Location: PHPKode > projects > OpenBizMap > obm2007.1/mydata/script/tmp_cal.txt
<?php
/*
OpenDataBag - Data Web Interface
Copyright (C) 2004 Nawara

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/

// Calendar config ---------------------------------------------

$title=get('title');
if(!$title)
  $title=$mm2;
if(!$title)
  $title=$mm1;
if(!$title)
  $title='Calendar';

echo '<h2>';
myecho($title);
echo '</h2>';

echo '<a class="noprint" style="margin-left:10px;" href="#" onclick="document.getElementById(\'reportdef\').style.display=\'block\'; this.style.display=\'none\';">';
  myecho('Show definition');
echo '</a>';

echo('<form action="index.php" method="get">');
echo('<div id="reportdef" style="display:none;"><input name="odb_script" type="hidden" value="cal"></input>');
echo('<input name="odb_search" type="hidden" value="'.$search.'" />');
echo('<input name="odb_date" type="hidden" value="'.get('date').'" />');
echo('<input name="odb_title" type="hidden" value="'.$title.'" />');


$key2=get('n2');
$key3=get('n3');
$key4=get('n4');
$key5=get('n5');
$key6=get('n6');
$key7=get('n7');

echo '<div class="supergroup">';
  echo '<table>';
  echo '<tr>';
    //-----------------------------------------------------
    echo '<td class="label">';
    echo '</td>';

    echo '<td class="label">';
      myecho('Date Field');
    echo '</td>';

    echo '<td class="label">';
      myecho('Subject');
    echo '</td>';

    echo '<td class="label">';
      myecho('Description');
    echo '</td>';

    echo '<td class="label">';
      myecho('Red Filter');
    echo '</td>';

    echo '<td class="label">';
      myecho('Gray Filter');
    echo '</td>';

    echo '<td class="label">';
      myecho('Green Filter');
    echo '</td>';

    echo '<td class="label">';
    echo '</td>';

  echo '</tr>';
  echo '<tr>';
    //-----------------------------------------------------
    echo '<td class="label">';
      echo '1';
    echo '</td>';

    echo '<td class="input">';
      $show_name='n2';
      $show_value=$key2;
      $variable_name='ALLWORDS';
      echo('<input class="fld_" name="'.$show_name.'" id="'.$show_name.'" type="text" title="'.$show_value.'" onkeydown1="new AutoSuggestControl(this, \''.$variable_name.'\', new RemoteStateSuggestions());" value="'.$show_value.'"/>');
    echo '</td>';

    echo '<td class="input">';
      $show_name='n3';
      $show_value=$key3;
      $variable_name='ALLWORDS';
      echo('<input class="fld_" name="'.$show_name.'" id="'.$show_name.'" type="text" title="'.$show_value.'" onkeydown1="new AutoSuggestControl(this, \''.$variable_name.'\', new RemoteStateSuggestions());" value="'.$show_value.'"/>');
    echo '</td>';

    echo '<td class="input">';
      $show_name='n4';
      $show_value=$key4;
      $variable_name='ALLWORDS';
      echo('<input class="fld_" name="'.$show_name.'" id="'.$show_name.'" type="text" title="'.$show_value.'" onkeydown1="new AutoSuggestControl(this, \''.$variable_name.'\', new RemoteStateSuggestions());" value="'.$show_value.'"/>');
    echo '</td>';

    echo '<td class="input">';
      $show_name='n5';
      $show_value=$key5;
      $variable_name='ALLWORDS';
      echo('<input class="fld_" name="'.$show_name.'" id="'.$show_name.'" type="text" title="'.$show_value.'" onkeydown1="new AutoSuggestControl(this, \''.$variable_name.'\', new RemoteStateSuggestions());" value="'.$show_value.'"/>');
    echo '</td>';

    echo '<td class="input">';
      $show_name='n6';
      $show_value=$key6;
      $variable_name='ALLWORDS';
      echo('<input class="fld_" name="'.$show_name.'" id="'.$show_name.'" type="text" title="'.$show_value.'" onkeydown1="new AutoSuggestControl(this, \''.$variable_name.'\', new RemoteStateSuggestions());" value="'.$show_value.'"/>');
    echo '</td>';

    echo '<td class="input">';
      $show_name='n7';
      $show_value=$key7;
      $variable_name='ALLWORDS';
      echo('<input class="fld_" name="'.$show_name.'" id="'.$show_name.'" type="text" title="'.$show_value.'" onkeydown1="new AutoSuggestControl(this, \''.$variable_name.'\', new RemoteStateSuggestions());" value="'.$show_value.'"/>');
    echo '</td>';

    echo '<td>';
      echo('<input type="submit" class="submit" value="'.myecho('Show','RETURN').'" />');
    echo '</td>';

  echo '</tr>';
  echo '</table>';
  echo '<a style="margin-left:10px;" href="index.php?odb_sys=structure" target="_blank">';
    myecho('Show all available fields');
  echo '</a>';
echo '</div>';

echo('</div></form>');

flush();

$minute_width=0.2;
$today = mktime(0,0,0,date("m"),date("d"),date("Y"));
$days_to_show=28;

$weekday_array[0]='Sunday';
$weekday_array[1]='Monday';
$weekday_array[2]='Tuesday';
$weekday_array[3]='Wednesday';
$weekday_array[4]='Thursday';
$weekday_array[5]='Friday';
$weekday_array[6]='Saturday';

$calendar_array=array();
$full_day_array=array();
$day_array=array();

$date_shift=0+get('date')-date('w',mktime(0,0,0,date("m"),date("d")+get('date'),date("Y")));
$starting_date=date('Ymd',mktime(0,0,0,date("m"),date("d")+$date_shift-6,date("Y")));
$ending_date=date('Ymd',mktime(0,0,0,date("m"),date("d")+$date_shift+$days_to_show-6-1,date("Y")));


if(sizeof($group_array))
{
  $starting_time=mktime(0,0,0,substr($starting_date,4,2),substr($starting_date,6,2),substr($starting_date,0,4));
  $dd_shift=ceil(($starting_time-time())/3600/24);
  for($dd=$dd_shift;$dd<$dd_shift+$days_to_show;$dd++)
  {
    if(isset($day_array[date('d.m.Y',mktime(0,0,0,date("m"),date("d")+$dd,date("Y")))]))
      $full_day_array[$dd]=$day_array[date('d.m.Y',mktime(0,0,0,date("m"),date("d")+$dd,date("Y")))];
    elseif(isset($day_array[date('w',mktime(0,0,0,date("m"),date("d")+$dd,date("Y")))]))
      $full_day_array[$dd]=$day_array[date('w',mktime(0,0,0,date("m"),date("d")+$dd,date("Y")))];
  }

  //filling calendar
  $cal_resource_name=1;
  reset($group_array);
  while(list($tmp_group,$record_array)=each($group_array))
  {
    foreach($record_array as $line )
    {
      $key2_array=explode('[',str_replace(']','',$key2));

      reset($key2_array);
      foreach($key2_array as $key2)
      {
        $cal_start_date=substr(read($line,$key2),0,8);

      if($cal_start_date>=$starting_date and $cal_start_date<=$ending_date)
      {
          if(count($key2_array)>1)
            $cal_title=myecho($key2,'RETURN').' '.read($line,$key3);
          else
        $cal_title=read($line,$key3);
        $cal_title=str_replace('<br>',"\n",$cal_title);
        $cal_title=str_replace('<br />',"\n",$cal_title);
        $cal_title=str_replace('<br/>',"\n",$cal_title);
        $cal_title=trim($cal_title);
        $cal_title=str_replace("\n",'<br />',$cal_title);
        if(strlen(trim(strip_tags($cal_title)))==0)
          $cal_title='No title';

        $cal_description=read($line,$key4);

        if($key5 and strpos($line,$key5)) $cal_color='#f00';
        if($key6 and strpos($line,$key6)) $cal_color='#888';
        if($key7 and strpos($line,$key7)) $cal_color='#050';

        $cnt=sizeof($calendar_array[$cal_start_date]);

        $calendar_array[$cal_start_date][$cnt]['tooltip']=$cal_description;
        $calendar_array[$cal_start_date][$cnt]['title']=$cal_title;
        $calendar_array[$cal_start_date][$cnt]['link']=$tmp_group.' sysId='.read($line,'sysId');
        $calendar_array[$cal_start_date][$cnt]['color']=$cal_color;
        }
      }
    }
  }
}


$key_link='n2='.$key2.'&amp;n3='.$key3.'&amp;n4='.$key4.'&amp;n5='.$key5.'&amp;n6='.$key6.'&amp;n7='.$key7.'&amp;';
?>

<span class="noprint" style="margin-left:10px;">
<a href="index.php?odb_script=<?php echo $script; ?>&amp;odb_search=<?php echo $search; ?>&amp;<?php echo $key_link; ?>odb_date=<?php echo $date_shift-$days_to_show; ?>"><?php myecho('Show previous %1 days',$days_to_show); ?></a> |
<a href="index.php?odb_script=<?php echo $script; ?>&amp;odb_search=<?php echo $search; ?>&amp;<?php echo $key_link; ?>odb_date=<?php echo $date_shift+$days_to_show; ?>"><?php myecho('Show next %1 days',$days_to_show); ?></a>
</span>

<br />
<br />

<table class="cal_">
<?php
  //header

    echo '<tr>';
    for($ii=1;$ii<8;$ii++)
      echo '<td class="cal_weekday cal_weekday'.($ii%7).'" style="border: #888 1px solid; font-size:18px; padding:5px;">'.myecho($weekday_array[($ii%7)],'RETURN').'</td>';
    echo '</tr>';

    for($dd=$date_shift;$dd<$date_shift+$days_to_show;$dd+=7)
    {
      {
        echo '<tr>';
        for($ee=$dd-6;$ee<$dd+1;$ee++)
        {
          if(date('m',mktime(0,0,0,date("m"),date("d")+$ee,date("Y")))%2==0)
            echo '<td style="border: #888 1px solid; background-color:#fff;">';
          else
            echo '<td style="border: #888 1px solid; background-color:#eee;">';

            if($ee==0)
              echo '<div style="color:#0a0; margin:10px;">';
            else
              echo '<div style="color:#888; margin:10px;">';
            myecho(date('F',mktime(0,0,0,date("m"),date("d")+$ee,date("Y")))).'<br />';
            echo '<div style="font-size:30px;">'.date('d',mktime(0,0,0,date("m"),date("d")+$ee,date("Y"))).'</div>';
            echo '</div>';

                $ticket_array=$calendar_array[date('Ymd',mktime(0,0,0,date("m"),date("d")+$ee,date("Y")))];

                echo '<ol style="margin:3px; padding-left:3px; list-style-position: inside;">';
                for($tt=0;$tt<sizeof($ticket_array);$tt++)
                {
                  $day_start=$full_day_array[$ee]['start'];

                  if(!$full_day_array[$ee]['isopen'])
                    $day_start=$ticket_array[$tt]['start'];

                  $start=$minute_width*($ticket_array[$tt]['start']-$day_start);
                  $duration=$minute_width*$ticket_array[$tt]['duration'];
                  $title=$ticket_array[$tt]['title'];
                  $tooltip=$ticket_array[$tt]['tooltip'];
                  $color=$ticket_array[$tt]['color'];
                  echo '<li style=""><a style="color:'.$color.'" title="'.$tooltip.'" href="index.php?odb_search='.$ticket_array[$tt]['link'].'">';
                    echo $title;
                  echo '</a></li>';
                }
                echo '</ol>';


            echo '</td>';

        }
        echo '</tr>';

      }

    }


?>
</table>
Return current item: OpenBizMap