[ Index ]
 

Code source de GeekLog 1.4.1

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

/public_html/calendar/ -> index.php (source)

   1  <?php
   2  
   3  /* Reminder: always indent with 4 spaces (no tabs). */
   4  // +---------------------------------------------------------------------------+
   5  // | Calendar Plugin 1.0                                                       |
   6  // +---------------------------------------------------------------------------+
   7  // | index.php                                                                 |
   8  // |                                                                           |
   9  // | Geeklog calendar plugin                                                   |
  10  // +---------------------------------------------------------------------------+
  11  // | Copyright (C) 2000-2006 by the following authors:                         |
  12  // |                                                                           |
  13  // | Authors: Tony Bibbs        - tony AT tonybibbs DOT com                    |
  14  // |          Mark Limburg      - mlimburg AT users DOT sourceforge DOT net    |
  15  // |          Jason Whittenburg - jwhitten AT securitygeeks DOT com            |
  16  // |          Dirk Haun         - dirk AT haun-online DOT de                   |
  17  // +---------------------------------------------------------------------------+
  18  // |                                                                           |
  19  // | This program is free software; you can redistribute it and/or             |
  20  // | modify it under the terms of the GNU General Public License               |
  21  // | as published by the Free Software Foundation; either version 2            |
  22  // | of the License, or (at your option) any later version.                    |
  23  // |                                                                           |
  24  // | This program is distributed in the hope that it will be useful,           |
  25  // | but WITHOUT ANY WARRANTY; without even the implied warranty of            |
  26  // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             |
  27  // | GNU General Public License for more details.                              |
  28  // |                                                                           |
  29  // | You should have received a copy of the GNU General Public License         |
  30  // | along with this program; if not, write to the Free Software Foundation,   |
  31  // | Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.           |
  32  // |                                                                           |
  33  // +---------------------------------------------------------------------------+
  34  //
  35  // $Id: index.php,v 1.18 2006/09/04 07:40:33 dhaun Exp $
  36  
  37  require_once  ('../lib-common.php');
  38  require_once ($_CONF['path_system'] . 'classes/calendar.class.php');
  39  
  40  $display = '';
  41  
  42  if (empty ($_USER['username']) &&
  43      (($_CONF['loginrequired'] == 1) || ($_CA_CONF['calendarloginrequired'] == 1))) {
  44      $display .= COM_siteHeader('');
  45      $display .= COM_startBlock ($LANG_LOGIN[1], '',
  46                                  COM_getBlockTemplate ('_msg_block', 'header'));
  47      $login = new Template($_CONF['path_layout'] . 'submit');
  48      $login->set_file (array ('login'=>'submitloginrequired.thtml'));
  49      $login->set_var ('login_message', $LANG_LOGIN[2]);
  50      $login->set_var ('site_url', $_CONF['site_url']);   
  51      $login->set_var ('site_admin_url', $_CONF['site_admin_url']);   
  52      $login->set_var ('layout_url', $_CONF['layout_url']);   
  53      $login->set_var ('lang_login', $LANG_LOGIN[3]);
  54      $login->set_var ('lang_newuser', $LANG_LOGIN[4]);
  55      $login->parse ('output', 'login');
  56      $display .= $login->finish ($login->get_var('output'));
  57      $display .= COM_endBlock (COM_getBlockTemplate ('_msg_block', 'footer'));
  58      $display .= COM_siteFooter();
  59      echo $display;
  60      exit;
  61  }
  62  
  63  function getDayViewData($result, $cur_time = '')
  64  {
  65      $max = 0;
  66  
  67      // If no date/time passed used current timestamp
  68      if (empty($cur_time)) {
  69          $cur_time = time();
  70      }
  71  
  72      // Initialize array
  73      $hourcols = array();
  74      for ($i = 0; $i <= 23; $i++) {
  75          $hourcols[$i] = 0;
  76      }
  77  
  78      // Get data and increment counters
  79      $thedata = array();
  80      $nrows = DB_numRows($result);
  81  
  82      $alldaydata = array ();
  83      for ($i = 1; $i <= $nrows; $i++) {
  84          $A = DB_fetchArray($result);
  85          if ($A['allday'] == 1 OR (($A['datestart'] < date('Y-m-d',$cur_time)) AND ($A['dateend'] > date('Y-m-d',$cur_time)))) {
  86              // This is an all day event
  87              $alldaydata[$i] = $A;
  88          } else {
  89              // This is an event with start/end times
  90              if ($A['datestart'] < date('Y-m-d', $cur_time) AND $A['dateend'] >= date('Y-m-d', $cur_time)) {
  91                  $starthour = '00';
  92              } else {
  93                  $starthour = date('G', strtotime($A['datestart'] . ' ' . $A['timestart']));
  94              }
  95              $endhour = date('G', strtotime($A['dateend'] . ' ' . $A['timeend']));
  96              if (date('i', strtotime($A['dateend'] . ' ' . $A['timeend'])) == '00') {
  97                  $endhour = $endhour - 1; 
  98              }
  99              $hourcols[$starthour] = $hourcols[$starthour] + 1;
 100              if ($hourcols[$starthour] > $max) {
 101                  $max = $hourcols[$starthour];
 102              }
 103              $thedata[$i] = $A;
 104          }
 105      }
 106  
 107      return array($hourcols, $thedata, $max, $alldaydata);
 108  }
 109  
 110  function setCalendarLanguage (&$aCalendar)
 111  {
 112      global $_CONF, $LANG_WEEK, $LANG_MONTH;
 113  
 114      $lang_days = array ('sunday'    => $LANG_WEEK[1],
 115                          'monday'    => $LANG_WEEK[2],
 116                          'tuesday'   => $LANG_WEEK[3],
 117                          'wednesday' => $LANG_WEEK[4],
 118                          'thursday'  => $LANG_WEEK[5],
 119                          'friday'    => $LANG_WEEK[6],
 120                          'saturday'  => $LANG_WEEK[7]);
 121  
 122      $lang_months = array ('january'   => $LANG_MONTH[1],
 123                            'february'  => $LANG_MONTH[2],
 124                            'march'     => $LANG_MONTH[3],
 125                            'april'     => $LANG_MONTH[4],
 126                            'may'       => $LANG_MONTH[5],
 127                            'june'      => $LANG_MONTH[6],
 128                            'july'      => $LANG_MONTH[7],
 129                            'august'    => $LANG_MONTH[8],
 130                            'september' => $LANG_MONTH[9],
 131                            'october'   => $LANG_MONTH[10],
 132                            'november'  => $LANG_MONTH[11],
 133                            'december'  => $LANG_MONTH[12]);
 134  
 135      $aCalendar->setLanguage ($lang_days, $lang_months, $_CONF['week_start']);
 136  }
 137  
 138  /**                     
 139  * Returns an abbreviated day's name 
 140  *                       
 141  * @param    int     $day    1 = Sunday, 2 = Monday, ...
 142  * @return   string          abbreviated day's name (3 characters)
 143  *
 144  *
 145  */
 146  function shortDaysName ($day)
 147  {
 148      global $LANG_WEEK;
 149  
 150      return MBYTE_substr ($LANG_WEEK[$day], 0, 2);
 151  }
 152  
 153  function makeDaysHeadline ()
 154  {
 155      global $_CONF;
 156  
 157      $retval = '<tr><th>';
 158      if ($_CONF['week_start'] == 'Mon') {
 159          $retval .= shortDaysName (2) . '</th><th>'
 160                  . shortDaysName (3) . '</th><th>'
 161                  . shortDaysName (4) . '</th><th>'
 162                  . shortDaysName (5) . '</th><th>'
 163                  . shortDaysName (6) . '</th><th>'
 164                  . shortDaysName (7) . '</th><th>'
 165                  . shortDaysName (1) . '</th></tr>';
 166      } else {
 167          $retval .= shortDaysName (1) . '</th><th>'
 168                  . shortDaysName (2) . '</th><th>'
 169                  . shortDaysName (3) . '</th><th>'
 170                  . shortDaysName (4) . '</th><th>'
 171                  . shortDaysName (5) . '</th><th>'
 172                  . shortDaysName (6) . '</th><th>'
 173                  . shortDaysName (7) . '</th></tr>';
 174      }
 175  
 176      return $retval;
 177  }
 178  
 179  /**
 180  * Add the 'mode=' parameter to a URL
 181  *
 182  * @param    string  $mode   the mode ('personal' or empty string)
 183  * @param    boolean $more   whether there are more parameters in the URL or not
 184  * @param    string          'mode' parameter for the URL or an empty string
 185  *
 186  */
 187  function addMode ($mode, $more = true)
 188  {
 189      $retval = '';
 190  
 191      if (!empty ($mode)) {
 192          $retval .= 'mode=' . $mode;
 193          if ($more) {
 194              $retval .= '&amp;';
 195          }
 196      }
 197  
 198      return $retval;
 199  }
 200  
 201  /**
 202  * Return link to "delete event" image
 203  *
 204  * Note: Personal events can be deleted if the current user is the owner of the
 205  *       calendar and has _read_ access to them.
 206  *
 207  * @param    string  $mode   'personal' for personal events
 208  * @param    array   $A      event permissions and id
 209  * @return   string          link or empty string
 210  *
 211  */
 212  function getDeleteImageLink ($mode, $A)
 213  {
 214      global $_CONF, $LANG_CAL_ADMIN, $LANG_CAL_2, $_IMAGE_TYPE;
 215  
 216      $retval = '';
 217  
 218      if ($mode == 'personal') {
 219          if (SEC_hasAccess ($A['owner_id'], $A['group_id'], $A['perm_owner'],
 220                  $A['perm_group'], $A['perm_members'], $A['perm_anon']) > 0) {
 221  
 222              $retval = '<a href="' . $_CONF['site_url']
 223                      . '/calendar/event.php?action=deleteevent&amp;eid='
 224                      . $A['eid'] . '"><img src="' . $_CONF['site_url']
 225                      . '/calendar/images/delete_event.' . $_IMAGE_TYPE
 226                      . '" border="0" alt="' . $LANG_CAL_2[30] . '" title="'
 227                      . $LANG_CAL_2[30] . '"></a>';
 228          }
 229      } else if (SEC_hasRights ('calendar.edit')) {
 230          if (SEC_hasAccess ($A['owner_id'], $A['group_id'], $A['perm_owner'],
 231                  $A['perm_group'], $A['perm_members'], $A['perm_anon']) == 3) {
 232  
 233              $retval = '<a href="' . $_CONF['site_admin_url']
 234                      . '/plugins/calendar/index.php?mode=' . $LANG_CAL_ADMIN[22]
 235                      . '&amp;eid=' . $A['eid'] . '"><img src="'
 236                      . $_CONF['site_url']
 237                      . '/calendar/images/delete_event.' . $_IMAGE_TYPE
 238                      . '" border="0" alt="' . $LANG_CAL_2[30] . '" title="'
 239                      . $LANG_CAL_2[30] . '"></a>';
 240          }
 241      }
 242  
 243      return $retval;
 244  }
 245  
 246  /**
 247  * Gets a small, text-only version of a calendar
 248  *
 249  * @param    int     $m  Month to display
 250  * @param    int     $y  Year to display
 251  * @return   string      HTML for small calendar
 252  *
 253  */
 254  function getSmallCalendar ($m, $y, $mode = '')
 255  {
 256      global $_CONF;
 257  
 258      $retval = '';
 259      $mycal = new Calendar ();
 260      setCalendarLanguage ($mycal);
 261      $mycal->setCalendarMatrix ($m, $y);
 262  
 263      if (!empty ($mode)) {
 264          $mode = '&amp;mode=' . $mode;
 265      }
 266  
 267      $retval .= '<table class="smallcal">' . LB 
 268              . '<tr class="smallcal-headline"><td align="center" colspan="7">'
 269              . '<a href="' . $_CONF['site_url'] . '/calendar/index.php?month='
 270              . $m . '&amp;year=' . $y . $mode . '">' . $mycal->getMonthName ($m)
 271              . '</a></td></tr>' . makeDaysHeadline () . LB;
 272  
 273      for ($i = 1; $i <= 6; $i++) {
 274          if ($i % 2 == 0) {
 275              $tr = '<tr class="smallcal-week-even">' . LB;
 276          } else {
 277              $tr = '<tr class="smallcal-week-odd">' . LB;
 278          }
 279          $tr_sent = false;
 280          for ($j = 1; $j <= 7; $j++) {
 281              $curday = $mycal->getDayData ($i, $j);
 282              if (!$tr_sent) {
 283                  if (empty ($curday)) {
 284                      $retval .= '<tr class="smallcal-week-empty">' . LB;
 285                  } else {
 286                      $retval .= $tr;
 287                  }
 288                  $tr_sent = true;
 289              }
 290              $retval .= '<td align="right"';
 291              if (!empty ($curday)) {
 292                  if ($j % 2 == 0) {
 293                      $retval .= ' class="smallcal-day-even">' . LB;
 294                  } else {
 295                      $retval .= ' class="smallcal-day-odd">' . LB;
 296                  }
 297                  $retval .= $curday->daynumber;
 298              } else {
 299                  $retval .= ' class="smallcal-day-empty">&nbsp;';
 300              }
 301              $retval .= '</td>' . LB;
 302          }
 303          $retval .= '</tr>' . LB;
 304      }
 305  
 306      $retval .= '</table>' . LB;
 307      
 308      return $retval;
 309  }
 310  
 311  /**
 312  * Builds Quick Add form
 313  *
 314  */
 315  function getQuickAdd($tpl, $month, $day, $year)
 316  {
 317      global $_CA_CONF, $LANG_CAL_2;
 318  
 319      $tpl->set_var ('month_options', COM_getMonthFormOptions ($month));
 320      $tpl->set_var ('day_options', COM_getDayFormOptions ($day));
 321      $tpl->set_var ('year_options', COM_getYearFormOptions ($year));
 322  
 323      $cur_hour = date ('H', time ());
 324      if ($cur_hour >= 12) {
 325          $ampm = 'pm';
 326      } else {
 327          $ampm = 'am';
 328      }
 329      $cur_hour_24 = $cur_hour % 24;
 330      if ($cur_hour > 12) {
 331          $cur_hour = $cur_hour - 12;
 332      } else if ($cur_hour == 0) {
 333          $cur_hour = 12;
 334      }
 335      if (isset ($_CA_CONF['hour_mode']) && ($_CA_CONF['hour_mode'] == 24)) {
 336          $tpl->set_var ('hour_mode', 24);
 337          $tpl->set_var ('hour_options',
 338                         COM_getHourFormOptions ($cur_hour_24, 24));
 339      } else {
 340          $tpl->set_var ('hour_mode', 12);
 341          $tpl->set_var ('hour_options', COM_getHourFormOptions ($cur_hour));
 342      }
 343      $tpl->set_var ('startampm_selection',
 344                     COM_getAmPmFormSelection ('start_ampm', $ampm));
 345      $cur_min = intval (date ('i') / 15) * 15;
 346      $tpl->set_var ('minute_options', COM_getMinuteFormOptions ($cur_min, 15));
 347  
 348      $tpl->set_var ('lang_event', $LANG_CAL_2[32]);
 349      $tpl->set_var ('lang_date', $LANG_CAL_2[33]);
 350      $tpl->set_var ('lang_time', $LANG_CAL_2[34]);
 351      $tpl->set_var ('lang_add', $LANG_CAL_2[31]);
 352      $tpl->set_var ('lang_quickadd', $LANG_CAL_2[35]);
 353      $tpl->set_var ('lang_submit', $LANG_CAL_2[36]);
 354      $tpl->parse ('quickadd_form', 'quickadd', true);
 355  
 356      return $tpl;
 357  }
 358  
 359  /** 
 360  * Returns timestamp for the prior sunday of a given day
 361  *
 362  */
 363  function getPriorSunday($month, $day, $year) 
 364  {
 365      $thestamp = mktime(0, 0, 0, $month, $day, $year);
 366      $newday = $day - date('w', $thestamp);
 367      $newstamp = mktime(0,0,0,$month,$newday,$year);
 368      $newday = date('j',$newstamp);
 369      $newmonth = date('n', $newstamp);
 370      $newyear = date('Y',$newstamp);
 371  
 372      return array($newmonth, $newday, $newyear);
 373  }
 374  
 375  $mode = '';
 376  if (isset ($_REQUEST['mode'])) {
 377      $mode = COM_applyFilter ($_REQUEST['mode']);
 378  }
 379  
 380  if ($mode != 'personal' && $mode != 'quickadd') {
 381      $mode = '';
 382  }
 383  
 384  if ($mode == 'personal') {
 385      $display .= COM_siteHeader ('menu', $LANG_CAL_1[42]);
 386  } else {
 387      $display .= COM_siteHeader ('menu', $LANG_CAL_1[41]);
 388  }
 389  
 390  // Set mode back to master if user refreshes screen after their session expires
 391  if (($mode == 'personal') && (!isset ($_USER['uid']) || ($_USER['uid'] <= 1))) {
 392      $mode = '';
 393  }
 394  
 395  if ($mode == 'personal' AND $_CA_CONF['personalcalendars'] == 0) {
 396      // User is trying to use the personal calendar feature even though it isn't
 397      // turned on.
 398      $display .= $LANG_CAL_2[37];
 399      $display .= COM_siteFooter();
 400      echo $display;
 401      exit;
 402  }
 403  
 404  // after this point, we can safely assume that if $mode == 'personal',
 405  // the current user is actually allowed to use this personal calendar
 406  
 407  $msg = 0;
 408  if (isset ($_REQUEST['msg'])) {
 409      $msg = COM_applyFilter ($_REQUEST['msg'], true);
 410  }
 411  if ($msg > 0) {
 412      $display .= COM_showMessage ($msg, 'calendar');
 413  }
 414  
 415  $view = '';
 416  if (isset ($_REQUEST['view'])) {
 417      $view = COM_applyFilter ($_REQUEST['view']);
 418  }
 419  
 420  if (!in_array ($view, array ('month', 'week', 'day', 'addentry', 'savepersonal'))) {
 421      $view = '';
 422  }
 423  
 424  $year = 0;
 425  if (isset ($_REQUEST['year'])) {
 426      $year = COM_applyFilter ($_REQUEST['year'], true);
 427  }
 428  $month = 0;
 429  if (isset ($_REQUEST['month'])) {
 430      $month = COM_applyFilter ($_REQUEST['month'], true);
 431  }
 432  $day = 0;
 433  if (isset ($_REQUEST['day'])) {
 434      $day = COM_applyFilter ($_REQUEST['day'], true);
 435  }
 436  
 437  // Create new calendar object
 438  $cal = new Calendar();
 439  
 440  if ($view == 'week' AND (empty($month) AND empty($day) AND empty($year))) {
 441      list($month, $day, $year) = getPriorSunday(date('m', time()), date('j', time()), date('Y', time()));
 442  } else {
 443      // Get current month
 444      $currentmonth = date('m', time());
 445      if (empty($month)) {
 446          $month = $currentmonth;
 447      }
 448  
 449      // Get current year
 450      $currentyear = date('Y', time());
 451      if (empty($year)) {
 452          $year = $currentyear;
 453      }
 454  
 455      // Get current day
 456      $currentday =  date('j', time());
 457      if (empty($day)) {
 458          $day = $currentday;
 459      }
 460  }
 461  
 462  // Get previous month and year
 463  $prevmonth = $month - 1;
 464  if ($prevmonth == 0) {
 465      $prevmonth = 12;
 466      $prevyear = $year - 1;
 467  } else {
 468      $prevyear = $year;
 469  }
 470  
 471  // Get next month and year
 472  $nextmonth = $month + 1;
 473  if ($nextmonth == 13) {
 474      $nextmonth = 1;
 475      $nextyear = $year + 1;
 476  } else {
 477      $nextyear = $year;
 478  }
 479  
 480  setCalendarLanguage ($cal);
 481  
 482  // Build calendar matrix
 483  $cal->setCalendarMatrix ($month, $year);
 484  
 485  switch ($view) {
 486  case 'day':
 487      $cal_templates = new Template($_CONF['path'] . '/plugins/calendar/templates/dayview');
 488      $cal_templates->set_file(array('column'=>'column.thtml',
 489                                     'event'=>'singleevent.thtml',
 490                                     'dayview'=>'dayview.thtml',
 491                                     'quickadd'=>'quickaddform.thtml'));
 492      $cal_templates->set_var ('site_url', $_CONF['site_url']);
 493      $cal_templates->set_var ('site_admin_url', $_CONF['site_admin_url']);
 494      $cal_templates->set_var ('layout_url', $_CONF['layout_url']);
 495      $cal_templates->set_var('mode', $mode);
 496      $cal_templates->set_var('lang_day', $LANG_CAL_2[39]);
 497      $cal_templates->set_var('lang_week', $LANG_CAL_2[40]);
 498      $cal_templates->set_var('lang_month', $LANG_CAL_2[41]);
 499      list($wmonth, $wday, $wyear) = getPriorSunday($month, $day, $year);
 500      $cal_templates->set_var('wmonth', $wmonth);
 501      $cal_templates->set_var('wday', $wday);
 502      $cal_templates->set_var('wyear', $wyear);
 503      $cal_templates->set_var('month',$month);
 504      $cal_templates->set_var('day', $day);
 505      $cal_templates->set_var('year',$year);
 506      $prevstamp = mktime(0, 0, 0,$month, $day - 1, $year);
 507      $nextstamp = mktime(0, 0, 0,$month, $day + 1, $year);
 508      $cal_templates->set_var('prevmonth', strftime('%m',$prevstamp));
 509      $cal_templates->set_var('prevday', strftime('%d',$prevstamp));
 510      $cal_templates->set_var('prevyear', strftime('%Y',$prevstamp));
 511      $cal_templates->set_var('nextmonth', strftime('%m',$nextstamp));
 512      $cal_templates->set_var('nextday', strftime('%d',$nextstamp));
 513      $cal_templates->set_var('nextyear', strftime('%Y',$nextstamp));
 514  
 515      $cal_templates->set_var('currentday', strftime('%A, %x',mktime(0, 0, 0,$month, $day, $year)));
 516      if ($mode == 'personal') {
 517          $cal_templates->set_var('calendar_title', '[' . $LANG_CAL_2[28] . ' ' . COM_getDisplayName());
 518          $cal_templates->set_var('calendar_toggle', '|&nbsp;<a href="'
 519                                 . $_CONF['site_url'] . "/calendar/index.php?view=day&amp;month=$month&amp;day=$day&amp;year=$year\">" . $LANG_CAL_2[11] . '</a>]');
 520      } else {
 521          $cal_templates->set_var('calendar_title', '[' . $_CONF['site_name'] . ' ' . $LANG_CAL_2[29]);
 522          if (!empty($_USER['uid']) AND $_CA_CONF['personalcalendars'] == 1) {
 523              $cal_templates->set_var('calendar_toggle', '|&nbsp;<a href="'
 524                                     . $_CONF['site_url'] . "/calendar/index.php?mode=personal&amp;view=day&amp;month=$month&amp;day=$day&amp;year=$year\">" . $LANG_CAL_2[12] . '</a>]');
 525          } else {
 526              $cal_templates->set_var('calendar_toggle', ']');
 527          }
 528      }
 529      $thedate = COM_getUserDateTimeFormat(mktime(0,0,0,$month,$day,$year));
 530      $cal_templates->set_var('week_num',strftime('%V',$thedate[1]));
 531      if ($mode == 'personal') {
 532          $calsql = "SELECT eid,title,datestart,dateend,timestart,timeend,allday,owner_id,group_id,perm_owner,perm_group,perm_members,perm_anon FROM {$_TABLES['personal_events']} "
 533                  . "WHERE (uid = {$_USER['uid']}) "
 534                  . "AND ((allday=1 AND datestart = \"$year-$month-$day\") "
 535                  . "OR (datestart >= \"$year-$month-$day 00:00:00\" AND datestart <= \"$year-$month-$day 23:59:59\") "
 536                  . "OR (dateend >= \"$year-$month-$day 00:00:00\" AND dateend <= \"$year-$month-$day 23:59:59\") "
 537                  . "OR (\"$year-$month-$day\" BETWEEN datestart AND dateend)) "
 538                  . "ORDER BY datestart,timestart";
 539      } else {
 540          $calsql = "SELECT eid,title,datestart,dateend,timestart,timeend,allday,owner_id,group_id,perm_owner,perm_group,perm_members,perm_anon FROM {$_TABLES['events']} WHERE ((allday=1 "
 541                  . "AND datestart = \"$year-$month-$day\") "
 542                  . "OR (datestart >= \"$year-$month-$day 00:00:00\" AND datestart <= \"$year-$month-$day 23:59:59\") "
 543                  . "OR (dateend >= \"$year-$month-$day 00:00:00\" AND dateend <= \"$year-$month-$day 23:59:59\") "
 544                  . "OR (\"$year-$month-$day\" BETWEEN datestart AND dateend))" . COM_getPermSql ('AND')
 545                  . " ORDER BY datestart,timestart";
 546      }
 547      $result = DB_query($calsql);
 548      $nrows = DB_numRows($result);
 549      list($hourcols, $thedata, $max, $alldaydata) = getDayViewData($result);
 550  
 551      // Get all day events
 552      if (count ($alldaydata) > 0) {
 553          for ($i = 1; $i <= count ($alldaydata); $i++) {
 554              $A = current($alldaydata);
 555              $cal_templates->set_var ('delete_imagelink',
 556                                       getDeleteImageLink ($mode, $A));
 557              $cal_templates->set_var('event_time', $LANG_CAL_2[26]);
 558              $cal_templates->set_var('eid', $A['eid']);
 559              $cal_templates->set_var('event_title',stripslashes($A['title']));
 560              if ($i < count($alldaydata)) {
 561                  $cal_templates->set_var('br', '<br>');
 562              } else {
 563                  $cal_templates->set_var('br', '');
 564              }
 565              $cal_templates->parse('allday_events','event', true); 
 566              next($alldaydata);
 567          }
 568      } else {
 569          $cal_templates->set_var('allday_events','&nbsp;');
 570      }
 571  
 572      //$cal_templates->set_var('first_colspan', $maxcols);
 573      //$cal_templates->set_var('title_colspan', $maxcols + 1);
 574      for ($i = 0; $i <= 23; $i++) {
 575          $numevents = $hourcols[$i];
 576          if ($numevents > 0) {
 577              // $colsleft = $maxcols;
 578              $cal_templates->set_var ('layout_url', $_CONF['path'] . 'plugins/calendar/templates/');
 579              for ($j = 1; $j <= $numevents; $j++) {
 580                  $A = current ($thedata);
 581                  $cal_templates->set_var ('event_time',
 582                      strftime ($_CONF['timeonly'], strtotime ($A['datestart']
 583                              . ' ' . $A['timestart'])) . '-'
 584                      . strftime ($_CONF['timeonly'], strtotime ($A['dateend']
 585                              . ' ' . $A['timeend'])));
 586                  $cal_templates->set_var ('delete_imagelink',
 587                                           getDeleteImageLink ($mode, $A));
 588                  $cal_templates->set_var('eid', $A['eid']);
 589                  $cal_templates->set_var('event_title', stripslashes($A['title']));
 590                  if ($j < $numevents) {
 591                      $cal_templates->set_var('br', '<br>');
 592                  } else {
 593                      $cal_templates->set_var('br', '');
 594                  }
 595                  $cal_templates->parse ('event_entry', 'event',
 596                                         ($j == 1) ? false : true);
 597                  // $colsleft = $colsleft - 1;
 598                  next($thedata);
 599              }
 600          } else {
 601              $cal_templates->set_var('event_entry','&nbsp;');
 602          }
 603          $cal_templates->set_var ($i . '_hour',
 604                  strftime ($_CONF['timeonly'], mktime ($i, 0)));
 605          $cal_templates->parse ($i . '_cols', 'column', true);
 606      }
 607  
 608      if ($mode == 'personal') {
 609          $cal_templates = getQuickAdd($cal_templates, $month, $day, $year);
 610      } else {
 611          $cal_templates->set_var('quickadd_form','');
 612      }
 613      $display .= $cal_templates->parse('output', 'dayview');
 614      $display .= COM_siteFooter();
 615      break;
 616  
 617  case 'week':
 618      $cal_templates = new Template($_CONF['path'] . '/plugins/calendar/templates');
 619      $cal_templates->set_file(array('week'=>'weekview/weekview.thtml',
 620                                     'events'=>'weekview/events.thtml',
 621                                     'quickadd'=>'dayview/quickaddform.thtml'));
 622      $cal_templates->set_var ('site_url', $_CONF['site_url']);
 623      $cal_templates->set_var ('site_admin_url', $_CONF['site_admin_url']);
 624      $cal_templates->set_var ('layout_url', $_CONF['layout_url']);
 625      $cal_templates->set_var('mode', $mode);
 626      $cal_templates->set_var('lang_week', $LANG_CAL_2[27]);
 627      if ($mode == 'personal') {
 628          $cal_templates->set_var('calendar_title', '[' . $LANG_CAL_2[28] . ' ' . COM_getDisplayName());
 629          $cal_templates->set_var('calendar_toggle', '|&nbsp;<a href="' . $_CONF['site_url']
 630                                                   . "/calendar/index.php?view=week&amp;month=$month&amp;day=$day&amp;year=$year\">"
 631                                                   . $LANG_CAL_2[11] . '</a>]');
 632      } else {
 633          $cal_templates->set_var('calendar_title', '[' . $_CONF['site_name'] . ' ' . $LANG_CAL_2[29]);
 634          if (!empty($_USER['uid']) AND $_CA_CONF['personalcalendars'] == 1) {
 635              $cal_templates->set_var('calendar_toggle', '|&nbsp;<a href="' . $_CONF['site_url']
 636                                                       . "/calendar/index.php?mode=personal&amp;view=week&amp;month=$month&amp;day=$day&amp;year=$year\">"
 637                                                       . $LANG_CAL_2[12] . '</a>]');
 638          } else {
 639              $cal_templates->set_var('calendar_toggle', ']');
 640          }
 641      }
 642      if ($mode == 'personal') {
 643          $cal_templates = getQuickAdd($cal_templates, $month, $day, $year);
 644      } else {
 645          $cal_templates->set_var('quickadd_form','');
 646      }
 647      // Get data for previous week
 648      $prevstamp = mktime(0,0,0,$month,$day-7,$year);
 649      $nextstamp = mktime(0,0,0,$month,$day+7,$year);
 650      $cal_templates->set_var('prevmonth',strftime('%m',$prevstamp));
 651      $cal_templates->set_var('prevday',date('j',$prevstamp));
 652      $cal_templates->set_var('prevyear',strftime('%Y',$prevstamp));
 653      $cal_templates->set_var('nextmonth',strftime('%m',$nextstamp));
 654      $cal_templates->set_var('nextday',date('j',$nextstamp));
 655      $cal_templates->set_var('nextyear',strftime('%Y',$nextstamp));
 656      $cal_templates->set_var ('lang_day', $LANG_CAL_2[39]);
 657      $cal_templates->set_var ('lang_week', $LANG_CAL_2[40]);
 658      $cal_templates->set_var ('lang_month', $LANG_CAL_2[41]);
 659      if ($_CONF['week_start'] == 'Mon') {
 660          $time_day1 = mktime (0, 0, 0, $month, $day + 1, $year);
 661          $time_day7 = mktime (0, 0, 0, $month, $day + 7, $year);
 662          $start_mname = strftime ('%B', $time_day1);
 663          $eday = strftime ('%e', $time_day7);
 664          $end_mname = strftime ('%B', $time_day7);
 665          $end_ynum = strftime ('%Y', $time_day7);
 666          $date_range = $start_mname . ' ' . strftime ('%e', $time_day1);
 667      } else {
 668          $start_mname = strftime ('%B', mktime (0, 0, 0, $month, $day, $year));
 669          $time_day6 = mktime (0, 0, 0, $month, $day + 6, $year);
 670          $eday = strftime ('%e', $time_day6);
 671          $end_mname = strftime ('%B', $time_day6);
 672          $end_ynum = strftime ('%Y', $time_day6);
 673          $date_range = $start_mname . ' ' . $day;
 674      }
 675      if ($year <> $end_ynum) {
 676          $date_range .= ', ' . $year . ' - ';
 677      } else {
 678          $date_range .= ' - ';
 679      }
 680      if ($start_mname <> $end_mname) {
 681          $date_range .= $end_mname . ' ' . $eday . ', ' . $end_ynum;
 682      } else {
 683          $date_range .= $eday . ', ' . $end_ynum;
 684      }
 685      $cal_templates->set_var('date_range', $date_range);
 686      if ($_CONF['week_start'] == 'Mon') {
 687          $thedate = COM_getUserDateTimeFormat (mktime (0, 0, 0, $month, $day + 1,$year));
 688      } else {
 689          $thedate = COM_getUserDateTimeFormat (mktime (0, 0, 0, $month, $day, $year));
 690      }
 691      $cal_templates->set_var('week_num',$thedate[1]);
 692      for ($i = 1; $i <= 7; $i++) {
 693          if ($_CONF['week_start'] == 'Mon') {
 694              $dayname = (date ('w', $thedate[1]) == 0)
 695                       ? $cal->getDayName (7)
 696                       : $cal->getDayName (date ('w', $thedate[1]));
 697          } else {
 698              $dayname = $cal->getDayName (date ('w', $thedate[1]) + 1);
 699          }
 700          $monthnum = date('m', $thedate[1]);
 701          $daynum = date('d', $thedate[1]);
 702          $yearnum = date('Y', $thedate[1]);
 703          if ($yearnum . '-' . $monthnum . '-' . $daynum == date('Y-m-d',time())) {
 704              $cal_templates->set_var('class'.$i,'weekview-curday');
 705          } else {
 706              $cal_templates->set_var('class'.$i,'weekview-offday');
 707          }
 708          $monthname = $cal->getMonthName($monthnum);
 709          $cal_templates->set_var ('day' . $i, $dayname . ', <a href="'
 710              . $_CONF['site_url'] . '/calendar/index.php?' . addMode ($mode)
 711              . 'view=day&amp;day=' . $daynum . '&amp;month=' . $monthnum
 712              . '&amp;year=' . $yearnum . '">' . strftime ('%x', $thedate[1])
 713              . '</a>');
 714          if ($mode == 'personal') {
 715              $add_str =  $LANG_CAL_2[8];
 716          } else {
 717              $add_str =  $LANG_CAL_2[42];
 718          }    
 719          
 720          $cal_templates->set_var ('langlink_addevent' . $i, '<a href="'
 721              . $_CONF['site_url'] . '/submit.php?type=calendar&amp;'
 722              . addMode ($mode) . 'day=' . $daynum . '&amp;month=' . $monthnum
 723              . '&amp;year=' . $yearnum . '">' . $add_str . '</a>');
 724          if ($mode == 'personal') {
 725              $calsql = "SELECT eid,title,datestart,dateend,timestart,timeend,allday,owner_id,group_id,perm_owner,perm_group,perm_members,perm_anon FROM {$_TABLES['personal_events']} WHERE (uid = {$_USER['uid']}) AND ((allday=1 AND datestart = \"$yearnum-$monthnum-$daynum\") OR (datestart >= \"$yearnum-$monthnum-$daynum 00:00:00\" AND datestart <= \"$yearnum-$monthnum-$daynum 23:59:59\") OR (dateend >= \"$yearnum-$monthnum-$daynum 00:00:00\" AND dateend <= \"$yearnum-$monthnum-$daynum 23:59:59\") OR (\"$yearnum-$monthnum-$daynum\" BETWEEN datestart AND dateend)) ORDER BY datestart,timestart";
 726          } else {
 727              $calsql = "SELECT eid,title,datestart,dateend,timestart,timeend,allday,owner_id,group_id,perm_owner,perm_group,perm_members,perm_anon FROM {$_TABLES['events']} WHERE ((allday=1 AND datestart = \"$yearnum-$monthnum-$daynum\") OR (datestart >= \"$yearnum-$monthnum-$daynum 00:00:00\" AND datestart <= \"$yearnum-$monthnum-$daynum 23:59:59\") OR (dateend >= \"$yearnum-$monthnum-$daynum 00:00:00\" AND dateend <= \"$yearnum-$monthnum-$daynum 23:59:59\") OR (\"$yearnum-$monthnum-$daynum\" BETWEEN datestart AND dateend))" . COM_getPermSql ('AND') . " ORDER BY datestart,timestart";
 728          }
 729          $result = DB_query($calsql);
 730          $nrows = DB_numRows($result);
 731          for ($j = 1; $j <= $nrows; $j++) {
 732              $A = DB_fetchArray($result);
 733              if ($A['allday'] == 1) {
 734                  $cal_templates->set_var('event_starttime', $LANG_CAL_2[26]);
 735                  $cal_templates->set_var('event_endtime','');
 736              } else {
 737                  $startstamp = strtotime($A['datestart'] . ' ' . $A['timestart']);
 738                  $endstamp = strtotime($A['dateend'] . ' ' . $A['timeend']);
 739                  $startday = date('d',$startstamp);
 740                  $startmonth = date('n',$startstamp);
 741                  $endday = date('d', $endstamp);
 742                  $endmonth = date('n',$endstamp);
 743                  if (($startmonth == $monthnum && $daynum > $startday) OR ($startmonth <> $monthnum)) {
 744                      $starttime = date('n/j g:i a',$startstamp);
 745                  } else { 
 746                      $starttime = date('g:i a', $startstamp); 
 747                  }
 748                  if (($endmonth == $monthnum && $daynum < $endday) OR ($endmonth <> $monthnum)) {
 749                      $endtime = date('n/j g:i a', $endstamp);
 750                  } else { 
 751                      $endtime = date('g:i a', $endstamp); 
 752                  }
 753                  $cal_templates->set_var('event_starttime', $starttime);
 754                  $cal_templates->set_var('event_endtime', ' - ' . $endtime);
 755              }
 756              $cal_templates->set_var ('event_title_and_link', '<a href="'
 757                  . $_CONF['site_url'] . '/calendar/event.php?' . addMode ($mode)
 758                  . 'eid=' . $A['eid'] . '">' . stripslashes($A['title'])
 759                  . '</a>');
 760              // Provide delete event link if user has access
 761              $cal_templates->set_var ('delete_imagelink',
 762                                       getDeleteImageLink ($mode, $A));
 763              $cal_templates->parse ('events_day' . $i, 'events', true);
 764          }
 765          if ($nrows == 0) {
 766              $cal_templates->set_var('event_starttime','&nbsp;');
 767              $cal_templates->set_var('event_endtime','');
 768              $cal_templates->set_var('event_title_and_link','');
 769              $cal_templates->set_var('delete_imagelink','');
 770              $cal_templates->parse('events_day'.$i,'events',true);
 771          }
 772          // Go to next day
 773          $thedate = COM_getUserDateTimeFormat(mktime(0,0,0,$monthnum, $daynum + 1, $yearnum));
 774      }
 775  
 776      $display .= $cal_templates->parse('output','week');
 777      $display .= COM_siteFooter();
 778      break;
 779      
 780  case 'addentry':
 781      $display .= plugin_submit_calendar($mode);
 782      break;
 783  case 'savepersonal':
 784      $display = plugin_savesubmission_calendar($_POST);
 785      break;
 786  
 787  default: // month view
 788  // Load templates
 789  
 790  $cal_templates = new Template($_CONF['path'] . '/plugins/calendar/templates');
 791  $cal_templates->set_file (array (
 792          'calendar'    => 'calendar.thtml',
 793          'week'        => 'calendarweek.thtml',
 794          'day'         => 'calendarday.thtml',
 795          'event'       => 'calendarevent.thtml',
 796          'mastercal'   => 'mastercalendaroption.thtml',
 797          'personalcal' => 'personalcalendaroption.thtml',
 798          'addevent'    => 'addeventoption.thtml'
 799          ));
 800  
 801  $cal_templates->set_var ('site_url', $_CONF['site_url']);
 802  $cal_templates->set_var ('site_admin_url', $_CONF['site_admin_url']);
 803  $cal_templates->set_var ('layout_url', $_CONF['layout_url']);
 804  $cal_templates->set_var ('mode', $mode);
 805  if ($mode == 'personal') {
 806      $cal_templates->set_var ('start_block', COM_startBlock ($LANG_CAL_2[12]));
 807      $cal_templates->set_var ('end_block', COM_endBlock ());
 808  } else {
 809      $cal_templates->set_var ('start_block', COM_startBlock ($LANG_CAL_2[11]));
 810      $cal_templates->set_var ('end_block', COM_endBlock ());
 811  }
 812  
 813  $smallcal_prev = getSmallCalendar ($prevmonth, $prevyear, $mode);
 814  $cal_templates->set_var ('previous_months_calendar', $smallcal_prev);
 815  $cal_templates->set_var ('previous_months_cal',
 816                           '<font size="-2">' . LB . $smallcal_prev . '</font>');
 817  
 818  $smallcal_next = getSmallCalendar ($nextmonth, $nextyear, $mode);
 819  $cal_templates->set_var ('next_months_calendar', $smallcal_next);
 820  $cal_templates->set_var ('next_months_cal',
 821                           '<font size="-2">' . LB . $smallcal_next . '</font>');
 822  
 823  $cal_templates->set_var('cal_prevmo_num', $prevmonth);
 824  $cal_templates->set_var('cal_prevyr_num', $prevyear);
 825  $cal_templates->set_var('cal_month_and_year', $cal->getMonthName($month) . ' ' . $year);
 826  $cal_templates->set_var('cal_nextmo_num', $nextmonth);
 827  $cal_templates->set_var('cal_nextyr_num', $nextyear);
 828  
 829  if ($_CONF['week_start'] == 'Mon') {
 830      $cal_templates->set_var('lang_sunday', $LANG_WEEK[2]);
 831      $cal_templates->set_var('lang_monday', $LANG_WEEK[3]);
 832      $cal_templates->set_var('lang_tuesday', $LANG_WEEK[4]);
 833      $cal_templates->set_var('lang_wednesday', $LANG_WEEK[5]);
 834      $cal_templates->set_var('lang_thursday', $LANG_WEEK[6]);
 835      $cal_templates->set_var('lang_friday', $LANG_WEEK[7]);
 836      $cal_templates->set_var('lang_saturday', $LANG_WEEK[1]);
 837  } else {
 838      $cal_templates->set_var('lang_sunday', $LANG_WEEK[1]);
 839      $cal_templates->set_var('lang_monday', $LANG_WEEK[2]);
 840      $cal_templates->set_var('lang_tuesday', $LANG_WEEK[3]);
 841      $cal_templates->set_var('lang_wednesday', $LANG_WEEK[4]);
 842      $cal_templates->set_var('lang_thursday', $LANG_WEEK[5]);
 843      $cal_templates->set_var('lang_friday', $LANG_WEEK[6]);
 844      $cal_templates->set_var('lang_saturday', $LANG_WEEK[7]);
 845  }
 846  
 847  $cal_templates->set_var('lang_january', $LANG_MONTH[1]);
 848  if ($month == 1) $cal_templates->set_var('selected_jan','selected="selected"');
 849  $cal_templates->set_var('lang_february', $LANG_MONTH[2]);
 850  if ($month == 2) $cal_templates->set_var('selected_feb','selected="selected"');
 851  $cal_templates->set_var('lang_march', $LANG_MONTH[3]);
 852  if ($month == 3) $cal_templates->set_var('selected_mar','selected="selected"');
 853  $cal_templates->set_var('lang_april', $LANG_MONTH[4]);
 854  if ($month == 4) $cal_templates->set_var('selected_apr','selected="selected"');
 855  $cal_templates->set_var('lang_may', $LANG_MONTH[5]);
 856  if ($month == 5) $cal_templates->set_var('selected_may','selected="selected"');
 857  $cal_templates->set_var('lang_june', $LANG_MONTH[6]);
 858  if ($month == 6) $cal_templates->set_var('selected_jun','selected="selected"');
 859  $cal_templates->set_var('lang_july', $LANG_MONTH[7]);
 860  if ($month == 7) $cal_templates->set_var('selected_jul','selected="selected"');
 861  $cal_templates->set_var('lang_august', $LANG_MONTH[8]);
 862  if ($month == 8) $cal_templates->set_var('selected_aug','selected="selected"');
 863  $cal_templates->set_var('lang_september', $LANG_MONTH[9]);
 864  if ($month == 9) $cal_templates->set_var('selected_sep','selected="selected"');
 865  $cal_templates->set_var('lang_october', $LANG_MONTH[10]);
 866  if ($month == 10) $cal_templates->set_var('selected_oct','selected="selected"');
 867  $cal_templates->set_var('lang_november', $LANG_MONTH[11]);
 868  if ($month == 11) $cal_templates->set_var('selected_nov','selected="selected"');
 869  $cal_templates->set_var('lang_december', $LANG_MONTH[12]);
 870  if ($month == 12) $cal_templates->set_var('selected_dec','selected="selected"');
 871  
 872  $cal_templates->set_var('lang_day', $LANG_CAL_2[39]);
 873  $cal_templates->set_var('lang_week', $LANG_CAL_2[40]);
 874  $cal_templates->set_var('lang_month', $LANG_CAL_2[41]);
 875  
 876  if ($mode == 'personal') {
 877      $cal_templates->set_var ('calendar_title',
 878                               $LANG_CAL_2[28] . ' ' . COM_getDisplayName());
 879  } else {
 880      $cal_templates->set_var ('calendar_title',
 881                               $_CONF['site_name'] . ' ' . $LANG_CAL_2[29]);
 882  }
 883  
 884  $yroptions = '';
 885  for ($y = $currentyear - 5; $y <= $currentyear + 5; $y++) {
 886      $yroptions .= '<option value="' . $y . '"';
 887      if ($y == $year) {
 888          $yroptions .= ' selected="selected"';
 889      }
 890      $yroptions .= '>' . $y . '</option>'.LB;
 891  }
 892  $cal_templates->set_var('year_options', $yroptions);
 893  
 894  for ($i = 1; $i <= 6; $i++) {
 895      $wday = '';
 896      for ($j = 1; $j <= 7; $j++) {
 897          $curday = $cal->getDayData($i, $j);
 898          if (!empty($curday)) {
 899              // Cache first actual day of the week to build week view link
 900              if (empty($wday)) {
 901                  $wday = $curday->daynumber;
 902              }
 903              if (($currentyear > $year) OR
 904                  ($currentmonth > $month && $currentyear == $year) OR
 905                  ($currentmonth == $month && $currentday > $curday->daynumber && $currentyear == $year)) {
 906                  $cal_templates->set_var('cal_day_style', 'cal-oldday'); 
 907              } else {
 908                  if ($currentyear == $year && $currentmonth == $month && $currentday == $curday->daynumber) {
 909                      $cal_templates->set_var('cal_day_style','cal-today');
 910                  } else {
 911                      $cal_templates->set_var('cal_day_style', 'cal-futureday');
 912                  }
 913              }
 914  
 915              if (strlen($curday->daynumber) == 1) {
 916                  $curday->daynumber = '0' . $curday->daynumber;
 917              }
 918  
 919              $cal_templates->set_var ('cal_day_anchortags', '<a href="'
 920                  . $_CONF['site_url'] . '/calendar/index.php?view=day&amp;'
 921                  . addMode ($mode) . 'day=' . $curday->daynumber. '&amp;month='
 922                  . $month . '&amp;year=' . $year . '" class="cal-date">'
 923                  . $curday->daynumber. '</a><hr>');
 924  
 925              if (strlen($month) == 1) {
 926                  $month = '0' . $month;
 927              }
 928  
 929              if ($mode == 'personal') {
 930                  $calsql_tbl = $_TABLES['personal_events'];
 931                  $calsql_filt = "AND (uid = {$_USER['uid']})";
 932              } else {
 933                  $calsql_tbl = $_TABLES['events'];
 934                  $calsql_filt = COM_getPermSql ('AND');
 935              }
 936              
 937              $calsql = "SELECT eid,title,datestart,dateend,timestart,timeend,allday,owner_id,group_id,perm_owner,perm_group,perm_members,perm_anon FROM $calsql_tbl WHERE "
 938                      . "((datestart >= \"$year-$month-$curday->daynumber 00:00:00\" "
 939                      . "AND datestart <= \"$year-$month-$curday->daynumber 23:59:59\") "
 940                      . "OR (dateend >= \"$year-$month-$curday->daynumber 00:00:00\" "
 941                      . "AND dateend <= \"$year-$month-$curday->daynumber 23:59:59\") "
 942                      . "OR (\"$year-$month-$curday->daynumber\" BETWEEN datestart AND dateend))"
 943                      . $calsql_filt . " ORDER BY datestart,timestart";
 944  
 945              $query2 = DB_query($calsql);
 946              $q2_numrows = DB_numRows($query2);
 947  
 948              if ($q2_numrows > 0) {
 949                  $entries = '';
 950                  for ($z = 1; $z <= $q2_numrows; $z++) {
 951                      $results = DB_fetchArray ($query2);
 952                      if ($results['title']) {
 953                          $cal_templates->set_var ('cal_day_entries', '');
 954                          $entries .= '<a href="' . $_CONF['site_url']
 955                              . '/calendar/event.php?' . addMode ($mode)
 956                              . 'eid=' . $results['eid'] . '" class="cal-event">'
 957                              . stripslashes ($results['title']) . '</a><hr>';
 958                      }
 959                  }
 960                  for ($z = $z; $z <= 4; $z++) {
 961                      $entries .= '<br>';
 962                  }
 963  
 964                  $cal_templates->set_var('event_anchortags', $entries);
 965  
 966              } else {
 967                  if ($q2_numrows < 4) {
 968                      for ($t=0; $t < (4 - $q2_numrows); $t++) {
 969                          $cal_templates->set_var('cal_day_entries','<br><br><br><br>');
 970                      }
 971                  }
 972              }
 973  
 974              $cal_templates->parse('cal_day_entries', 'event', true);
 975              $cal_templates->set_var('event_anchortags','');
 976          } else {
 977              if ($i > 1) {
 978                  // Close out calendar if needed
 979                  for ($k = $j; $k <= 7; $k++) {
 980                      $cal_templates->set_var('cal_day_style','cal-nullday');
 981                      $cal_templates->set_var('cal_day_anchortags', '');
 982                      $cal_templates->set_var('cal_day_entries','&nbsp;');
 983                      if ($k < 7) $cal_templates->parse('cal_days', 'day', true);
 984                  }
 985                  // for looping to stop...we are done now
 986                  $i = 7;
 987                  $j = 8;
 988              } else {
 989                  // Print empty box for any days in the first week that occur
 990                  // before the first day
 991                  $cal_templates->set_var('cal_day_style','cal-nullday');
 992                  $cal_templates->set_var('cal_day_anchortags', '');
 993                  $cal_templates->set_var('cal_day_entries','&nbsp;');
 994              }
 995          }
 996          $cal_templates->parse('cal_days','day',true);
 997      }
 998      list($wmonth, $wday, $wyear) = getPriorSunday($month, $wday, $year);
 999      $cal_templates->set_var('wmonth', $wmonth);
1000      $cal_templates->set_var('wday', $wday);
1001      $cal_templates->set_var('wyear', $wyear);
1002      $cal_templates->parse('cal_week', 'week',true);
1003      $cal_templates->set_var('cal_days','');
1004  
1005      // check if we need to render the following week at all
1006      if ($i < 6) {
1007          $data = $cal->getDayData ($i + 1, 1);
1008          if (empty ($data)) {
1009              break;     
1010          }
1011      }
1012  }
1013  
1014  if ($mode == 'personal') {
1015      $cal_templates->set_var('lang_mastercal', $LANG_CAL_2[25] . $LANG_CAL_2[11]);
1016      $cal_templates->parse('master_calendar_option','mastercal',true); 
1017  } else {
1018      if (isset ($_USER['uid']) && ($_USER['uid'] > 1) &&
1019              ($_CA_CONF['personalcalendars'] == 1)) {
1020          $cal_templates->set_var('lang_mycalendar', $LANG_CAL_2[12]);
1021          $cal_templates->parse('personal_calendar_option','personalcal',true); 
1022      } else {
1023          $cal_templates->set_var('personal_calendar_option','&nbsp;');
1024      }
1025  }
1026  
1027  
1028  $cal_templates->set_var('lang_cal_curmo', $LANG_MONTH[$currentmonth + 0]);
1029  $cal_templates->set_var('cal_curmo_num', $currentmonth);
1030  $cal_templates->set_var('cal_curyr_num', $currentyear);
1031  $cal_templates->set_var('lang_cal_displaymo', $LANG_MONTH[$month + 0]);
1032  $cal_templates->set_var('cal_displaymo_num', $month);
1033  $cal_templates->set_var('cal_displayyr_num', $year);
1034  if ($mode == 'personal') {
1035      $cal_templates->set_var('lang_addevent', $LANG_CAL_2[8]);
1036      $cal_templates->set_var('addevent_formurl', '/calendar/index.php');
1037  } else {
1038      $cal_templates->set_var('lang_addevent', $LANG_CAL_2[42]);
1039      $cal_templates->set_var('addevent_formurl', '/submit.php?type=calendar');   
1040  }
1041  $cal_templates->parse('add_event_option','addevent',true);
1042  $cal_templates->parse('output','calendar');
1043  $display .= $cal_templates->finish($cal_templates->get_var('output'));
1044  
1045  $display .= COM_siteFooter();
1046  break;
1047  
1048  } // end switch    
1049  
1050  echo $display;
1051  
1052  ?>


Généré le : Wed Nov 21 12:27:40 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics