<?php
/*
= upcoming events view =

© Copyright 2009-2012  LuxSoft - www.LuxSoft.eu

This file is part of the LuxCal Web Calendar.

The LuxCal Web Calendar 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 3 of the License, or (at your option) any later version.

The LuxCal Web Calendar 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 the LuxCal 
Web Calendar. If not, see <http://www.gnu.org/licenses/>.
*/

function showGrid(&$events,$date) {
	global $privs, $set, $xx;
	foreach ($events as $evt) {
		$mayEdit = ($privs > 2 or ($privs == 2 and $evt['uid'] == $_SESSION['uid'])) ? true : false;
		echo "<table><tr><td class=\"lMarginUp\">";
		echo ($evt['sti'] == "" and $evt['eti'] == "") ? $xx['vws_all_day'] : ITtoDT($evt['sti']);
		echo ($evt['eti']) ? " - ".ITtoDT($evt['eti']).'</td>' : '</td>';
		if ($set['eventColor']) {
			$eColor = ($evt['cco'] ? 'color:'.$evt['cco'].';' : '').($evt['cbg'] ? 'background-color:'.$evt['cbg'].';' : '');
		} else {
			$eColor = $evt['uco'] ? 'background-color:'.$evt['uco'].';' : '';
		}
		$eStyle = $eColor ? ' style="'.$eColor.'"' : '';
		$check = '';
		if ($evt['ch1']) { $check .= strpos($evt['chk'], $date.'a') ? $evt['mk1'].' ' : '<span class="checkme">&#9744;</span>'; }
		if ($evt['ch2']) { $check .= strpos($evt['chk'], $date.'b') ? $evt['mk2'].' ' : '<span class="checkme">&#9744;</span>'; }
		if ($check) {
			$attrib = $mayEdit ? "class=\"point\" onclick=\"checkE(".$evt['eid'].",'".$date."');\" title=\"".$xx['vws_check_marks']."\"" : '';
			$check = '<span '.$attrib.">".$check.'</span> ';
		}
		if ($set['details4All'] or $mayEdit) {
			echo '<td><h6>'.$check."<span class=\"point\"".$eStyle." onclick=\"editE(".$evt['eid'].",'".$date."');\">".$evt['tit']."</span></h6>\n";
			if ($evt['ven']) { echo $xx['vws_venue'].": ".$evt['ven']."<br>\n"; }
			if ($evt['des']) { echo $evt['des']."<br>\n"; }
		} else {
			echo '<td><h6>'.$check."<span".$eStyle.">".$evt['tit']."</span></h6>\n";
		}
		if ($set['showCatName']) { echo $xx['evt_category'].": ".$evt['cnm']."<br>\n"; }
		if ($set['showAdEd']) {
			echo $xx['vws_added'].': '.IDtoDD($evt['ada']).' ('.$evt['una'].")<br>\n";;
			if ($evt['mda'] and $evt['edr']) { echo $xx['vws_edited'].': '.IDtoDD($evt['mda']).' ('.$evt['edr'].")<br>\n";; }
		}
		echo "</td></tr></table>\n";
	}
}

//sanity check
if (!defined('LCC')) { exit('not permitted ('.substr(basename(__FILE__),0,-4).')'); } //lounch via script only

//initialize
$cD = $_SESSION['cD'];
$eTime = mktime(0,0,0,substr($cD,5,2),substr($cD,8,2),substr($cD,0,4)) + (($set['lookaheadDays']-1) * 86400); //Unix time of end date
$eDate = date("Y-m-d", $eTime);

retrieve($cD,$eDate,'uc');

//display header
echo "<div class=\"headUp noprint noprintx\">\n";
if (!$mobile) {
	echo '<button class="floatR" onclick="printNice(\'noprintx\');">'.$xx['vws_print_all']."</button>\n";
	echo '<span class="floatR">&nbsp;&nbsp;</span>'."\n";
	echo '<button class="floatR" onclick="printNice(\'noprint\');">'.$xx['vws_print_today']."</button>\n";
}
echo '<h5>',makeD($cD,2)," - ",makeD($eDate,2),'</h5>'."\n<br>\n";
echo "</div>\n";

//display upcoming events
echo '<div id="scrollBox"'.($mobile ? '' : ' class="scrollBoxUp"').">\n";
echo '<div class="eventBg">'."\n";
if ($evtList) {
	foreach($evtList as $date => &$events) {
		if ($date > $cD) { echo "<div class=\"noprint\">\n"; $nopSet = true; }
		echo "<br><h6>".makeD($date,6)."</h6>\n";
		showGrid($events,$date);
		if ($date > $cD) { echo "</div>\n"; $nopSet = true; }
	}
} else {
	echo $xx['none']."\n";
}
echo "</div>\n</div>\n";
?>
