Location: PHPKode > projects > QuickTicket > quickticket/quickticket/qti_calendar.php
<?php

/*
 * PHP versions 4 and 5
 *
 * LICENSE: This source file is subject to version 3.0 of the PHP license
 * that is available through the world-wide-web at the following URI:
 * http://www.php.net/license. If you did not receive a copy of
 * the PHP License and are unable to obtain it through the web, please
 * send a note to hide@address.com so we can mail you a copy immediately.
 *
 * @category   Troubleticket
 * @package    QuickTicket
 * @author     Philippe Vandenberghe <hide@address.com>
 * @copyright  2008-2012 The PHP Group
 * @license    http://www.php.net/license  PHP License 3.0
 * @version    1.9.0.3 build:20081001
 * @link       http://www.qt-cute.org/doc/package/qti
 * @since      File available since Release 1.0.0
 * @deprecated File deprecated in Release 2.0.0
 *
 */

session_start();
require_once('bin/qti_init.php');
if ( !$oVIP->CanAccess('MUV',2,true) ) $oVIP->EndMessage('!',$L['R_member'],$_SESSION[QT]['skin_dir'],0);
$bShow = false;
if ( $_SESSION[QT]['show_calendar']=='V' ) $bShow = true;
if ( $_SESSION[QT]['show_calendar']=='U' && $oVIP->role!='V' ) $bShow = true;
if ( $_SESSION[QT]['show_calendar']=='M' && $oVIP->role=='M' ) $bShow = true;
if ( $oVIP->role=='A' ) $bShow = true;
if ( !$bShow ) $oVIP->EndMessage('!',$L['R_member'],$_SESSION[QT]['skin_dir'],0);

// ---------
// INITIALISE
// ---------

if ( !isset($_GET['s']) ) die('Missing section id...');
$s = intval($_GET['s']);
$v = 'firstpostdate';
if ( isset($_GET['v']) )
{
  if ( in_array($_GET['v'],array('firstpostdate','lastpostdate','wisheddate')) ) $v = $_GET['v'];
}
$intYear = intval(date('Y')); if ( isset($_GET['y']) ) $intYear = intval($_GET['y']);
$intMonth = intval(date('n')); if ( isset($_GET['m']) ) $intMonth = intval($_GET['m']);
$strOptions = '';

  // moderator settings
  if ( isset($_GET['Maction']) )
  {
    if ( $_GET['Maction']=='this' ) $_SESSION[QT]['cal_showall'] = false;
    if ( $_GET['Maction']=='all' ) $_SESSION[QT]['cal_showall'] = true;
    if ( $_GET['Maction']=='show_Z' ) $_SESSION[QT]['show_closed']=true;
    if ( $_GET['Maction']=='hide_Z' ) $_SESSION[QT]['show_closed']=false;
    if ( $_GET['Maction']=='hide_News' ) $_SESSION[QT]['cal_shownews'] = false;
    if ( $_GET['Maction']=='show_News' ) $_SESSION[QT]['cal_shownews'] = true;
  }
  if ( !$_SESSION[QT]['show_closed'] ) $strOptions .= 'status<>"Z" AND ';
  if ( !$_SESSION[QT]['cal_showall'] ) $strOptions .= 'forum='.$s.' AND ';
  if ( !$_SESSION[QT]['cal_shownews'] ) $strOptions .= 'type="T" AND ';

$dToday = mktime(0,0,0,date('n'),date('j'),date('Y'));

if ( $intYear>2037 ) die('Invalid year');
if ( $intYear<1970 ) die('Invalid year');
if ( $intMonth>12 ) die('Invalid month');
if ( $intMonth<1 ) die('Invalid month');

$oSEC = new cSection($s);

$oVIP->selfurl = 'qti_calendar.php';
$oVIP->selfname = $L['Section'].': '.$oSEC->name;

// --------
// HTML START
// --------

$arrCss = array('qti_calendar.css');
 
$strHeaderAddScript = '
<script type="text/javascript" src="bin/qt_jquery.js"></script>
<script type="text/javascript">
<!--
$(function() {
  $(".ajaxmouseover").mouseover(function() {
    $.post("qti_j_topic.php",
      {id:this.id,lang:"'.$_SESSION[QT]['language'].'"},
      function(data) { if ( data.length>0 ) document.getElementById("title_err").innerHTML=data; });
  });
});
-->
</script>
';

include('qti_p_header.php');

// Moderator actions
if ( $oVIP->role!='A' || $oVIP->role!='M' )
{
echo '<form method="get" action="qti_calendar.php" id="modaction">
<div class="div_modboard">
<span class="span_modboard">';
echo $L['Userrole'][$oVIP->role],':&nbsp;<input type="hidden" name="s" value="',$s,'"/>';
echo '<input type="hidden" name="v" value="',$v,'"/>
<input type="hidden" name="y" value="',$intYear,'"/>
<input type="hidden" name="m" value="',$intMonth,'"/>
<select name="Maction" class="small" onchange="document.getElementById(\'modaction\').submit();">
<option value="">',S,'</option>
<option value="show_Z"',($_SESSION[QT]['show_closed'] ? ' class="bold"' : ''),'>',$L['Topic_closed_show'],'</option>
<option value="hide_Z"',(!$_SESSION[QT]['show_closed'] ? ' class="bold"' : ''),'>',$L['Topic_closed_hide'],'</option>
<option value="0" disabled="disabled">-----------------</option>
<option value="show_News"',($_SESSION[QT]['cal_shownews'] ? ' class="bold"' : ''),'>',$L['Topic_news_show'],'</option>
<option value="hide_News"',(!$_SESSION[QT]['cal_shownews'] ? ' class="bold"' : ''),'>',$L['Topic_news_hide'],'</option>
<option value="0" disabled="disabled">-----------------</option>
<option value="all"',($_SESSION[QT]['cal_showall'] ? ' class="bold"' : ''),'>',$L['Topic_show_all'],'</option>
<option value="this"',(!$_SESSION[QT]['cal_showall'] ? ' class="bold"' : ''),'>',$L['Topic_show_this'],'</option>
</select>&nbsp;<input type="submit" name="Mok" class="small" value="',$L['Ok'],'" id="action_ok"/>
<script type="text/javascript">
<!--
document.getElementById("action_ok").style.visibility="hidden";
document.getElementById("action_ok").value="";
-->
</script>
</span></div>
</form>
';
}

// MAIN CALENDAR

  $dCurrentDate = mktime(0,0,0,$intMonth,1,$intYear);
  $dMainDate = $dCurrentDate;
  $dFirstDay = mktime(0,0,0,$intMonth,1,$intYear);
  if ( date('l',$dFirstDay)!='Monday' )
  {
    $dFirstDay = strtotime('-1 week',$dFirstDay);
    $dFirstMonday = strtotime('next monday',$dFirstDay);
    // correction for php 4.2
    // find last monday
    for ($i=date('j',$dFirstDay);$i<32;$i++)
    {
      $dI = mktime(0,0,0,date('n',$dFirstDay),$i,date('Y',$dFirstDay));
      if ( !$dI )
      {
      if ( date('N',$dI)==1 ) $dFirstMonday = $dI;
      }
    }
    $dFirstDay = $dFirstMonday;
  }
  $intShiftWeek = intval(date('W',$dFirstDay)); if ( $intShiftWeek>53 ) $intShiftWeek==1;

  // LIST OF TOPICS PER DAY IN THIS FORUM

  $arrTopics = array();
  $intCountTopics = 0;
  $arrCountTopics = array();

  switch(substr($oDB->type,0,5))
  {
  case 'mysql': $strQ = 'SELECT id,type,status,SUBSTRING('.$v.',7,2) as eventday FROM '.TABTOPIC.' WHERE '.$strOptions.' LEFT('.$v.',6)="'.($intYear*100+$intMonth).'"'; break;
  case 'mssql': $strQ = 'SELECT id,type,status,SUBSTRING('.$v.',7,2) as eventday FROM '.TABTOPIC.' WHERE '.$strOptions.' LEFT('.$v.',6)="'.($intYear*100+$intMonth).'"'; break;
  case 'pg':    $strQ = 'SELECT id,type,status,SUBSTRING('.$v.',7,2) as eventday FROM '.TABTOPIC.' WHERE '.$strOptions.' SUBSTRING('.$v.',1,6)="'.($intYear*100+$intMonth).'"'; break;
  case 'ibase': $strQ = 'SELECT id,type,status,SUBSTR('.$v.' FROM 7 FOR 2) as eventday FROM '.TABTOPIC.' WHERE '.$strOptions.' SUBSTRING('.$v.' FORM 1 FOR 6)="'.($intYear*100+$intMonth).'"'; break;
  case 'sqlit': $strQ = 'SELECT id,type,status,SUBSTR('.$v.',7,2) as eventday FROM '.TABTOPIC.' WHERE '.$strOptions.' SUBSTR('.$v.',1,6)="'.($intYear*100+$intMonth).'"'; break;
  case 'acces': $strQ = 'SELECT id,type,status,MID('.$v.',7,2) as eventday FROM '.TABTOPIC.' WHERE '.$strOptions.' LEFT('.$v.',6)="'.($intYear*100+$intMonth).'"'; break;
  case 'db2':   $strQ = 'SELECT id,type,status,SUBSTR('.$v.',7,2) as eventday FROM '.TABTOPIC.' WHERE '.$strOptions.' SUBSTR('.$v.',1,6)="'.($intYear*100+$intMonth).'"'; break;
  case 'ifx':   $strQ = 'SELECT id,type,status,SUBSTRING('.$v.',7,2) as eventday FROM '.TABTOPIC.' WHERE '.$strOptions.' SUBSTRING('.$v.',1,6)="'.($intYear*100+$intMonth).'"'; break;
  case 'oci':   $strQ = 'SELECT id,type,status,SUBSTR('.$v.',7,2) as eventday FROM '.TABTOPIC.' WHERE '.$strOptions.' SUBSTR('.$v.',1,6)="'.($intYear*100+$intMonth).'"'; break;
  default: die('Unknown db type '.$oDB->type);
  }

  $oDB->Query($strQ);
  while($row=$oDB->Getrow())
  {
    if ( !empty($row['eventday']) )
    {
      $intDay = intval($row['eventday']);
      if ( !empty($intDay) )
      {
      $arrTopics[$intDay][]=$row;
      $intCountTopics++;
      if ( !isset($arrCountTopics[$row['status']]) ) { $arrCountTopics[$row['status']]=1; } else { $arrCountTopics[$row['status']]++; }
      }
    }
  }

// DISPLAY MAIN CALENDAR

echo '
<table class="ta_hidden" cellspacing="0" style="width:700px"><tr class="tr_hidden" style="vertical-align:middle">
<td>
<h2>';
if ( date('n',$dCurrentDate)>1 ) echo '<a href="',$oVIP->selfurl,'?s=',$s,'&amp;v=',$v,'&amp;y=',$intYear,'&amp;m='.(date('n',$dCurrentDate)-1).'">&lt;</a> ';
echo $L['dateMMM'][date('n',$dCurrentDate)];
if ( date('n',$dCurrentDate)<12 ) echo ' <a href="',$oVIP->selfurl,'?s=',$s,'&amp;v=',$v,'&amp;y=',$intYear,'&amp;m='.(date('n',$dCurrentDate)+1).'">&gt;</a>';
echo '</h2>
</td>
<td style="text-align:right;">
<form class="small" method="get" action="',$oVIP->selfurl,'">
<input type="hidden" name="s" id="s" value="',$s,'"/>
<input type="hidden" name="v" id="v" value="',$v,'"/>
<input type="hidden" name="y" id="y" value="',$intYear,'"/>
',$L['Display_at'],' <select class="small" name="v">
<option value="firstpostdate"',($v=='firstpostdate' ? QSEL : ''),'>',$L['First_message'],'</option>
<option value="lastpostdate"',($v=='lastpostdate' ? QSEL : ''),'>',$L['Last_message'],'</option>
<option value="wisheddate"',($v=='wisheddate' ? QSEL : ''),'>',$L['Wisheddate'],'</option>
</select>
',$L['Month'],' <select class="small" name="m">
';
for ($i=1;$i<13;$i++)
{
echo '<option',($i==date('n') ? ' class="bold" ' : ''),' value="',$i,'"',($i==$intMonth ? QSEL : ''),'>',$L['dateMMM'][$i],'</option>';
}
echo '</select> ';
echo '<select class="small" name="y">';
for ($i=$intYear-1;$i<$intYear+2;$i++)
{
echo '<option value="',$i,'"',($i==$intYear ? QSEL : ''),'>',$i,'</option>';
}
echo '</select> <input class="small" type="submit" name="submit" id="submit" value="',$L['Ok'],'"/></td>',N;
echo '</form></td>';
echo '</tr></table>';

echo '<table class="ta ta_s" cellspacing="0" style="width:700px">';
echo '<tr class="tr_t">';
echo '<th class="th_week th_date_first">&nbsp;</th>';
for ($i=1;$i<8;$i++)
{
  echo '<th class="th_date',($i==7 ? ' th_date_last' : ''),'" style="width:95px">',$L['dateDDD'][$i],'</th>';
}
echo '</tr>';

  $iShift=0;
  for ($intWeek=0;$intWeek<6;$intWeek++)
  {
    echo '<tr class="tr_t">';
    echo '<td class="td_week">',$intShiftWeek,'</td>'; $intShiftWeek++;
    for ($intDay=1;$intDay<8;$intDay++)
    {
      $d = strtotime("+$iShift days",$dFirstDay); $iShift++;
      $intShiftYear = date('Y',$d);
      $intShiftMonth = date('n',$d);
      $intShiftDay = date('j',$d);

      // date number
      if ( date('n',$dCurrentDate)==date('n',$d) )
      {
        echo '<td class="td_date"',(date('z',$dToday)==date('z',$d) ? ' id="zone_today"' : ''),'>';
        echo '<p class="p_datenumber">',$intShiftDay,'</p><p class="p_dateicon">&nbsp;';
        // date info topic
        if ( isset($arrTopics[$intShiftDay]) )
        {
          $intTopics = 0;
          Foreach ($arrTopics[$intShiftDay] as $intKey => $arrValues)
          {
            $intTopics++;
            $oTopic = new cTopic($arrValues);
              // icon
              if ( strtolower($oTopic->type)=='a' )
              {
                $strTicon = $_SESSION[QT]['skin_dir'].'/ico_topic_a_0.gif';
                $strTname = $L['Ico_topic_a_0'];
              }
              else
              {
                if ( isset($_SESSION['qtiTstatus'][$oTopic->status]['statusname']) )
                {
                $strTicon = $_SESSION[QT]['skin_dir'].'/'.$_SESSION['qtiTstatus'][$oTopic->status]['icon'];
                $strTname = $_SESSION['qtiTstatus'][$oTopic->status]['statusname'];
                }
                else
                {
                $strTicon = 'admin/ico_status.gif';
                $strTname = 'unknown status';
                }
              }
            if ( $intTopics>=12 )
            {
              echo '...';
              break;
            }
            else
            {
              echo '<a class="ajaxmouseover" id="t',$oTopic->id,'" href="qti_topic.php?s=',$s,'&amp;t=',$oTopic->id,'">',AsImg($strTicon,'T',$strTname,'ico ico_t'),'</a> ';
            }
          }
        }
      }
      else
      {
        echo '<td class="td_date_out">';
        echo '<p class="p_datenumber">',$intShiftDay,'</p><p class="p_dateicon">&nbsp;';
      }
      echo '</p></td>';
    }
    echo '</tr>';
    if ( $intShiftMonth>$intMonth && $intShiftYear==$intYear ) break;
  }

echo '</table>';

// NEXT MONTH

  $intMonth++;
  if ( $intMonth>12) { $intMonth=1; $intYear++; }
  if ( $intYear>2037 ) die('Invalid year');

  $dCurrentDate = mktime(0,0,0,$intMonth,1,$intYear);
  $dFirstDay = mktime(0,0,0,$intMonth,1,$intYear);
  if ( date('l',$dFirstDay)!='Monday' )
  {
    $dFirstDay = strtotime('-1 week',$dFirstDay);
    $dFirstMonday = strtotime('next monday',$dFirstDay);
    // correction for php 4.2
    // find last monday
    for ($i=date('j',$dFirstDay);$i<32;$i++)
    {
      $dI = mktime(0,0,0,date('n',$dFirstDay),$i,date('Y',$dFirstDay));
      if ( !$dI )
      {
      if ( date('N',$dI)==1 ) $dFirstMonday = $dI;
      }
    }
    $dFirstDay = $dFirstMonday;
  }

  // LIST OF TOPICS PER DAY IN THIS FORUM

  $arrTopics = array();
  $intCountTopicsN=0;

  switch(substr($oDB->type,0,5))
  {
  case 'mysql': $strQ = 'SELECT SUBSTRING('.$v.',7,2) as eventday FROM '.TABTOPIC.' WHERE '.$strOptions.' LEFT('.$v.',6)="'.($intYear*100+$intMonth).'"'; break;
  case 'mssql': $strQ = 'SELECT SUBSTRING('.$v.',7,2) as eventday FROM '.TABTOPIC.' WHERE '.$strOptions.' LEFT('.$v.',6)="'.($intYear*100+$intMonth).'"'; break;
  case 'pg':    $strQ = 'SELECT SUBSTRING('.$v.',7,2) as eventday FROM '.TABTOPIC.' WHERE '.$strOptions.' SUBSTRING('.$v.',1,6)="'.($intYear*100+$intMonth).'"'; break;
  case 'ibase': $strQ = 'SELECT SUBSTR('.$v.' FROM 7 FOR 2) as eventday FROM '.TABTOPIC.' WHERE '.$strOptions.' SUBSTRING('.$v.' FORM 1 FOR 6)="'.($intYear*100+$intMonth).'"'; break;
  case 'sqlit': $strQ = 'SELECT SUBSTR('.$v.',7,2) as eventday FROM '.TABTOPIC.' WHERE '.$strOptions.' SUBSTR('.$v.',1,6)="'.($intYear*100+$intMonth).'"'; break;
  case 'acces': $strQ = 'SELECT MID('.$v.',7,2) as eventday FROM '.TABTOPIC.' WHERE '.$strOptions.' LEFT('.$v.',6)="'.($intYear*100+$intMonth).'"'; break;
  case 'db2':   $strQ = 'SELECT SUBSTR('.$v.',7,2) as eventday FROM '.TABTOPIC.' WHERE '.$strOptions.' SUBSTR('.$v.',1,6)="'.($intYear*100+$intMonth).'"'; break;
  case 'ifx':   $strQ = 'SELECT SUBSTRING('.$v.',7,2) as eventday FROM '.TABTOPIC.' WHERE '.$strOptions.' SUBSTRING('.$v.',1,6)="'.($intYear*100+$intMonth).'"'; break;
  case 'oci':   $strQ = 'SELECT SUBSTR('.$v.',7,2) as eventday FROM '.TABTOPIC.' WHERE '.$strOptions.' SUBSTR('.$v.',1,6)="'.($intYear*100+$intMonth).'"'; break;
  default: die('Unknown db type '.$oDB->type);
  }

  $oDB->Query($strQ);
  while($row=$oDB->Getrow())
  {
    // count topic per date
    if ( !empty($row['eventday']) )
    {
      $intDay = intval($row['eventday']);
      if ( !empty($intDay) )
      {
      if ( !isset($arrTopics[$intDay]) ) $arrTopics[$intDay]=0;
      $arrTopics[$intDay]++;
      $intCountTopicsN++;
      }
    }
  }

// DISPLAY SUBDATA

echo '<table class="ta_hidden" cellspacing="0"><tr class="tr_hidden">';
echo '<td style="width:220px">';

  // DISPLAY NEXT MONTH

  echo '<h2>'.$L['dateMMM'][date('n',$dCurrentDate)].'</h2>';
  echo '<table class="ta ta_s" cellspacing="0" style="width:200px">';
  echo '<tr class="tr_t">';
  for ($intDay=1;$intDay<8;$intDay++)
  {
  echo '<th class="th_date_next">',$L['dateD'][$intDay],'</th>';
  }
  echo '</tr>';

    $iShift=0;
    for ($intWeek=0;$intWeek<6;$intWeek++)
    {
      echo '<tr class="tr_t">';
      for ($intDay=1;$intDay<8;$intDay++)
      {
        $d = strtotime("+$iShift days",$dFirstDay); $iShift++;
        $intShiftYear = date('Y',$d);
        $intShiftMonth = date('n',$d);
        $intShiftDay = date('j',$d);
        // date number
        if ( date('n',$dCurrentDate)==date('n',$d) )
        {
          echo '<td class="td_date_next"',(date('z',$dToday)==date('z',$d) ? ' id="zone_today"' : ''),'>';
          if ( !empty($arrTopics[$intShiftDay]) )
          {
            echo '<a class="a_date_next" href="qti_calendar.php?s=',$s,'&amp;y=',$intYear,'&amp;m=',$intMonth,'">',$intShiftDay,'</a> ';
          }
          else
          {
            echo $intShiftDay;
          }
        }
        else
        {
          echo '<td class="td_date_out_next">';
          echo $intShiftDay;
        }
        echo '</td>';
      }
      echo '</tr>';
      if ( $intShiftMonth>$intMonth && $intShiftYear==$intYear ) break;
    }

  echo '</table>';

echo '</td>';
echo '<td style="width:220px">';

  // DISPLAY STATS

  echo '<h2>',$L['Statistics'],'</h2>';
  echo '<br/>';
  echo '<p class="preview_section"><b>',$L['dateMMM'][date('n',$dMainDate)],'</b></p>';
  foreach ( $arrCountTopics as $strKey => $intValue)
  {
  echo '<p class="preview_section">',$intValue,' ',$_SESSION['qtiTstatus'][$strKey]['name'],'</p>';
  }
  echo '<p class="preview_section">',$L['Total'],': ',$intCountTopics,' ',$L['Topics'],'</p>';
  echo '<br/>';
  echo '<p class="preview_section"><b>',$L['dateMMM'][date('n',$dCurrentDate)],'</b></p>';
  echo '<p class="preview_section">',$L['Total'],': ',$intCountTopicsN,' ',$L['Topics'],'</p>';

echo '</td>';
echo '<td style="width:220px">';

  // DISPLAY Preview

  echo '<h2>',$L['Preview'],'</h2>';
  echo '<script type="text/javascript"></script><noscript>Your browser does not support JavaScript</noscript>';
  echo '<div style="width:250px" id="title_err"></div>';

echo '</td>';
echo '<td>&nbsp;</td>';
echo '</tr></table>';

// HTML END

include('qti_p_footer.php');

?>
Return current item: QuickTicket