<?php
// $Id: display.php,v 1.1 2004/07/11 10:27:50 Farsus Exp $
// ------------------------------------------------------------------------- //
//               E-Xoops: Content Management for the Masses                  //
//                       < http://www.e-xoops.com >                          //
// ------------------------------------------------------------------------- //
// Original Author: Nobse, Bama
// Author Website : http://www.e-xoops.de, http://service.bama-webdesign.de
// License Type   : GPL: See /manual/LICENSES/GPL.txt
// ------------------------------------------------------------------------- //
include("header.php");
include(XOOPS_ROOT_PATH."/header.php");

$month = !empty($HTTP_POST_VARS['month']) ? $HTTP_POST_VARS['month'] : $HTTP_GET_VARS['month'];
$year = !empty($HTTP_POST_VARS['year']) ? $HTTP_POST_VARS['year'] : $HTTP_GET_VARS['year'];
$day = !empty($HTTP_POST_VARS['day']) ? $HTTP_POST_VARS['day'] : $HTTP_GET_VARS['day'];
$katid = !empty($HTTP_POST_VARS['katid']) ? $HTTP_POST_VARS['katid'] : $HTTP_GET_VARS['katid'];
$month1 = !empty($HTTP_POST_VARS['month1']) ? $HTTP_POST_VARS['month1'] : $HTTP_GET_VARS['month1'];
$year1 = !empty($HTTP_POST_VARS['year1']) ? $HTTP_POST_VARS['year1'] : $HTTP_GET_VARS['year1'];
$day1 = !empty($HTTP_POST_VARS['day1']) ? $HTTP_POST_VARS['day1'] : $HTTP_GET_VARS['day1'];

if ($xoopsUser) {
	$useroffset = $xoopsUser->getVar("timezone_offset");
} else {
	$useroffset = $xoopsConfig['default_TZ'];
}

$usertimevent = (time() + (($useroffset - ($xoopsConfig['server_TZ'] - date('I'))) * 3600));
$currentday = date("j", $usertimevent);
$currentmonth = date("m", $usertimevent);
$currentyear = date("Y", $usertimevent);

$lastseconds = mktime(0,0,0,$month,$day,$year)-(24*60*60);
$lastday = date('j', $lastseconds);
$lastmonth = date('m', $lastseconds);
$lastyear = date('Y', $lastseconds);
$nextseconds = mktime(0,0,0,$month,$day,$year)+(24*60*60);
$nextday = date('j', $nextseconds);
$nextmonth = date('m', $nextseconds);
$nextyear = date('Y', $nextseconds);

if ($katid) {
    $abfrage =" stamp >= \"$year1-$month1-$day1 00:00:00\" AND cid=$katid AND valid ='yes'";
	$kat1 = $db->query("SELECT title, cid FROM ".$db->prefix("ecal_cat")." where cid=$katid");
	list($kattitle) = $db->fetch_row($kat1);
	
}else{
	$abfrage =" stamp >= \"$year-$month-$day 00:00:00\" AND stamp <= \"$year-$month-$day 23:59:59\" AND valid ='yes'";
}
OpenTable();
$temp_nextday = date("j",strtotime("+1 day",$usertimevent));
    if ( date('j m Y') == $day." ".$month." ".$year ){define("_NAVPAGE","TODAY");}
    if ( $day." ".$month." ".$year == $temp_nextday." ".$month." ".$year ){define("_NAVPAGE","TOMORROW");}

include ("include/nav.php");

		echo "<table border='0' width='100%' class='bg3'><tr>";
        echo "<td align='left'>";
        form_last_day($lastday, $lastmonth, $lastyear);
        echo "</td>";
		
		if ($katid) {
		    echo "<td align='center'><b>"._CAL_ALLKATEVENT.$kattitle."</b></td>";
			
		}else{
			echo "<td align='center'><b>$day ";
			echo getMonthName($month);
			echo " $year</b></td>";
		}
		echo "<td align='right'>";
        form_next_day($nextday, $nextmonth, $nextyear);
        echo "</td></tr></table>";
       	
		$query = $db->query("SELECT * FROM ".$db->prefix("ecal")." WHERE $abfrage ORDER BY stamp");
		$results=$db->num_rows($query);
		
		if (!$results ) {
			echo "<BR><CENTER><B>"._NOEVENTDAY."</B></CENTER><BR>";
		} else {

        while ($row = $db->fetch_array($query)){
						
			$nomuser = $row['username'];
 			$auteur = $db->query("SELECT uid FROM ".$db->prefix("users")." where uname='$nomuser'");
			list($uid) = $db->fetch_row($auteur);
			
			$kat = $db->query("SELECT title, cid FROM ".$db->prefix("ecal_cat")." where cid=".$row['cid']);
			$kategorie = $db->fetch_array($kat);
			
			$locat = $db->query("SELECT lid, location, email, url FROM ".$db->prefix("ecal_location")." where lid=".$row['locationid']);
			$location = $db->fetch_array($locat);
			
			$Calanddate = $row['stamp'];
			$Calanddate = strftime(_EVEDATESTRING,strtotime($Calanddate));
			$heurmin = strftime(_EVETIME,strtotime($Calanddate));
			$date = strftime(_EVEDATESHORT,strtotime($Calanddate));
			
			include ("include/displayform.php");			
		}
	}

				echo "<table border=0 width='100%' cellpadding='2' cellspacing='0'><tr class='bg3'>";
        echo "<td align='left'>";
        form_last_day($lastday, $lastmonth, $lastyear);
        echo "</td>";        
		if ($xoopsUser) {
			$group = $xoopsUser->groups();
    		}else{
			$group[] = 3;
		}
		$anno = explode("|", $anoevent);
		$is = array_intersect ($group, $anno);
		
		
		if (count($is) > 0) {
            echo "<td align='center'>";
            form_add_event($month, $year);
            echo "</td>";   
		} else {
            echo "<td>&nbsp;</td>";
		}
		echo "<td align='right'>";
        form_next_day($nextday, $nextmonth, $nextyear);
        echo "</td></tr></table>";
CloseTable();
include(XOOPS_ROOT_PATH."/footer.php");
?>