<?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 '<br /><b>';
myecho($title);
echo '</b>';
/*
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>';
*/
$key1=get('n1');
/*
echo('<form action="index.php" method="get">');
echo('<div id="reportdef" style="display:none;"><input name="odb_script" type="hidden" value="xrcal"></input>');
echo('<input name="odb_search" type="hidden" value="'.$search.'" />');
echo('<input name="odb_date" type="hidden" value="'.get('date').'" />');
echo('<input name="odb_days" type="hidden" value="'.get('days').'" />');
echo('<input name="odb_title" type="hidden" value="'.$title.'" />');
echo '<div class="supergroup">';
echo '<table>';
echo '<tr>';
//-----------------------------------------------------
echo '<td class="label">';
myecho('Resource');
echo '</td>';
//-----------------------------------------------------
echo '<td class="input">';
$show_name='n1';
$show_value=$key1;
$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>');
flush();
*/
$minute_width=0.2;
$today = mktime(0,0,0,date("m"),date("d"),date("Y"));
$days_to_show=0+get('days');
if($days_to_show==0)
$days_to_show=7;
if(get('quickdate'))
{
$quickdate=get('quickdate');
$quickdate=substr($quickdate,6,4).substr($quickdate,3,2).substr($quickdate,0,2);
$date=round((-$today + mktime(0,0,0,substr($quickdate,4,2),substr($quickdate,6,2),substr($quickdate,0,4)))/3600/24,0);
}
elseif(get('date'))
{
$date=get('date');
$quickdate=date('Ymd',mktime(0,0,0,date("m"),date("d")+$date,date("Y")));
}
else
{
$date=0;
$quickdate=date('Ymd');
}
$date_shift=0+$date;
if($date_shift==0)
if(date('w',$today)==0)
$date_shift=-6;
else
$date_shift=-date('w',$today)+1;
$date_shift=0;
$starting_date=date('Ymd',mktime(0,0,0,date("m"),date("d")+$date_shift,date("Y")));
$ending_date=date('Ymd',mktime(0,0,0,date("m"),date("d")+$date_shift+$days_to_show,date("Y")));
$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();
$resource_array=array();
if(count($group_array))
{
reset($group_array);
while(list($tmp_group,$record_array)=each($group_array))
{
//searching for the first important field
$first_important_variable_name='';
$second_important_variable_name='';
$third_important_variable_name='';
$variable_array2=load_config($tmp_group);
reset($variable_array2);
while(list($variable_name,$variable_description)=each($variable_array2))
{
if($variable_description['hl']==1 and $first_important_variable_name=='' and $variable_name!=$key1)
{
$first_important_variable_name=$variable_name;
}
elseif($variable_description['hl']==1 and $second_important_variable_name=='' and $variable_name!=$key1)
{
$second_important_variable_name=$variable_name;
}
elseif($variable_description['hl']==1 and $variable_name!=$key1)
{
$third_important_variable_name=$variable_name;
break;
}
}
//searching for dates
foreach($record_array as $line )
{
if($key1=='')
$key1=$first_important_variable_name;
for($dd=$date_shift;$dd<$date_shift+$days_to_show;$dd++)
{
$current_date=date('Ymd',mktime(0,0,0,date("m"),date("d")+$dd,date("Y")));
$pos_tmp=strpos($line,$current_date);
while($pos_tmp)
{
//getting field name
$dpos=$pos_tmp;
$spos=strrpos(substr($line,0,$dpos),'$');
$kpos=strrpos(substr($line,0,$dpos),'=');
$key=substr($line,$spos+1,$kpos-$spos-1);
if(read($line,$key.' OK'))
$color='#888;';
//elseif(strpos($line,'OK'))
// $color='#888;';
else
$color='#080;';
$tooltip=myecho($tmp_group,'RETURN');
if($key!='sysComment' and $key!='sysModInfo' and $key!='sysModDate' and $key!='sysValidFrom')
{
//echo $starting_date.' '.$current_date.' '.$ending_date.' '.read($line,$first_important_variable_name).'<br>';
$resource=read($line,$key1);
$resource_array[$resource]['Resource Title']=read($line,$key1);
$resource_array[$resource]['Resource Type']=$key1;
//showing on calendar
$next_ii=count($calendar_array[$resource][$current_date]);
$calendar_array[$resource][$current_date][$next_ii]['line']=$line;
$calendar_array[$resource][$current_date][$next_ii]['key']=$key;
$calendar_array[$resource][$current_date][$next_ii]['color']=$color;
$calendar_array[$resource][$current_date][$next_ii]['Tooltip']=$tooltip;
$calendar_array[$resource][$current_date][$next_ii]['Link']='index.php?odb_search=sysId%3d'.read($line,'sysId');
$calendar_array[$resource][$current_date][$next_ii]['First']=read($line,$first_important_variable_name);
$calendar_array[$resource][$current_date][$next_ii]['Subject']='';
$calendar_array[$resource][$current_date][$next_ii]['Subject'].='<b>'.read($line,$first_important_variable_name);
if(read($line,$first_important_variable_name)=='Verspätung' and read($line,'Verspatung')==1)
$calendar_array[$resource][$current_date][$next_ii]['Subject'].= ': '.read($line,'Verspatung').' Tag';
if(read($line,$first_important_variable_name)=='Verspätung' and read($line,'Verspatung')>1)
$calendar_array[$resource][$current_date][$next_ii]['Subject'].= ': '.read($line,'Verspatung').' Tage';
$calendar_array[$resource][$current_date][$next_ii]['Subject'].='</b>';
if(read($line,$second_important_variable_name))
{
$calendar_array[$resource][$current_date][$next_ii]['Subject'].=' <br />'.read($line,$second_important_variable_name);
}
if(read($line,$third_important_variable_name))
{
$calendar_array[$resource][$current_date][$next_ii]['Subject'].=' <br />'.read($line,$third_important_variable_name);
}
$tmp_key=$key;
//$tmp_key=str_replace('Lieferdatum','WE',$tmp_key);
//$tmp_key=str_replace('Druckunterlagen','DU',$tmp_key);
//$tmp_key=str_replace('DU Versand bis','DU Versand',$tmp_key);
$calendar_array[$resource][$current_date][$next_ii]['Subject'].=' <br />'.myecho($tmp_key,'RETURN');
//echo ' '.trim(str_replace($current_date,'',read($line,$key)));
}
$pos_tmp=strpos($line,$current_date,$pos_tmp+8);
}
}
}
}
}
//~ echo '<pre>';
//~ print_r($calendar_array);
//~ echo '</pre>';
$key_link='odb_days='.$days_to_show.'&n1='.$key1.'&n2='.$key2.'&n3='.$key3.'&n4='.$key4.'&n5='.$key5.'&n6='.$key6.'&n7='.$key7.'&'.'&n8='.$key8.'&'.'&n9='.$key9.'&'.'&n10='.$key10.'&';
?>
<span class="noprint" style="margin-left:10px;">
<a href="index.php?odb_script=<?php echo $script; ?>&odb_search=<?php echo $search; ?>&<?php echo $key_link; ?>odb_date=<?php echo ($date_shift-$days_to_show); ?>&popup=<?php echo $popup; ?>"><<</a> |
<a href="index.php?odb_script=<?php echo $script; ?>&odb_search=<?php echo $search; ?>&<?php echo $key_link; ?>odb_date=<?php echo ($date_shift+$days_to_show); ?>&popup=<?php echo $popup; ?>">>></a>
</span>
<br />
<?php
//header
/*
echo '<tr>';
echo '<td> </td>';
for($dd=$date_shift;$dd<$date_shift+$days_to_show;$dd++)
echo '<td class="cal_weekday cal_weekday'.date('w',mktime(0,0,0,date("m"),date("d")+$dd,date("Y"))).'">'.myecho($weekday_array[date('w',mktime(0,0,0,date("m"),date("d")+$dd,date("Y")))],'RETURN').'</td>';
echo '</tr>';
echo '<tr>';
echo '<td> </td>';
for($dd=$date_shift;$dd<$date_shift+$days_to_show;$dd++)
if($dd==0)
echo '<td class="cal_dayheader" style="background-color:#dfd;">'.date('d',mktime(0,0,0,date("m"),date("d")+$dd,date("Y"))).'</td>';
else
echo '<td class="cal_dayheader">'.date('d',mktime(0,0,0,date("m"),date("d")+$dd,date("Y"))).'</td>';
echo '</tr>';
echo '<tr>';
echo '<td> </td>';
for($dd=$date_shift;$dd<$date_shift+$days_to_show;$dd++)
echo '<td class="cal_fulldate">'.date('d.m.Y',mktime(0,0,0,date("m"),date("d")+$dd,date("Y"))).'</td>';
echo '</tr>';
*/
$color=0;
//for each day
for($dd=$date_shift;$dd<$date_shift+$days_to_show;$dd++)
{
echo '<br /><b>';
echo myecho($weekday_array[date('w',mktime(0,0,0,date("m"),date("d")+$dd,date("Y")))],'RETURN').' '.date('d.m.Y',mktime(0,0,0,date("m"),date("d")+$dd,date("Y")));
echo '</b><br />';
echo '<ol>';
//for each resource
ksort($resource_array);
reset($resource_array);
foreach($resource_array as $cc => $tmp_val)
{
if($resource_array[$cc]['Resource Title'] or count($calendar_array[$cc]))
{
$color=1-$color;
$ticket_array=$calendar_array[$cc][date('Ymd',mktime(0,0,0,date("m"),date("d")+$dd,date("Y")))];
if(sizeof($ticket_array))
{
echo '<li>';
//echo ' '.date('d.m.Y',mktime(0,0,0,date("m"),date("d")+$dd,date("Y"))).'<br />';
for($tt=0;$tt<sizeof($ticket_array);$tt++)
{
$line=$calendar_array[$cc][date('Ymd',mktime(0,0,0,date("m"),date("d")+$dd,date("Y")))][$tt]['line'];
$key=$calendar_array[$cc][date('Ymd',mktime(0,0,0,date("m"),date("d")+$dd,date("Y")))][$tt]['key'];
echo '<a title="'.$ticket_array[$tt]['Description'].'" href="'.$ticket_array[$tt]['Link'].'">'.' '.$resource_array[$cc]['Resource Title'].'.</a> '.str_replace(' CRLF','',$ticket_array[$tt]['Subject']).'<br />';
}
echo '</li>';
}
}
}
echo '</ol>';
}
?>