<?php
//v1.0.4 www.bcoos.net 2006/10 GPL
// www.bcoos.net 2006-09 1.0.2 GPL
//v1.2 www.exoops.info 2006/03 
// $Id: week.php,v 1.11 2004/02/06 21:22:09 nobse 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");
include(XOOPS_ROOT_PATH."/modules/ecal/cache/config.php");

$day = !empty($_POST['week']) ? $_POST['week'] : $_GET['week'];

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

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

$month = date("m", $usertimevent);
$year = date("Y", $usertimevent);

$lastweek = $week -1;
$nextweek = $week +1;

if ($beginn == 1) {
	if ($wochentag == "Monday") {
		$usertimevent = time() + ($useroffset*3600+86400);
	}
	$lastmonday = date("Y/m/d",strtotime ("last Monday +$week week",$usertimevent)); //Datum letzter Montag
	$lastmondaytime = strtotime("$lastmonday") ;
	$lastmonday1 = date("Y-m-d",strtotime ("last Monday +$week week",$usertimevent)); //Datum letzter Montag für Datenbankabfrage
	$nextmonday = date("Y-m-d",strtotime ("last Monday +$nextweek week",$usertimevent)); //Datum nächster Montag

$tag1[0] = _MON;
$tag1[1] = _TUE;
$tag1[2] = _WED;
$tag1[3] = _THU;
$tag1[4] = _FRI;
$tag1[5] = _SAT;
$tag1[6] = _SUN;
}else{
	if ($wochentag == "Sunday") {
		$usertimevent = time() + ($useroffset*3600+86400);
	}
	$lastmonday = date("Y/m/d",strtotime ("last Sunday +$week week",$usertimevent)); //Datum letzter Montag
	$lastmondaytime = strtotime("$lastmonday") ;
	$lastmonday1 = date("Y-m-d",strtotime ("last Sunday +$week week",$usertimevent)); //Datum letzter Montag für Datenbankabfrage
	$nextmonday = date("Y-m-d",strtotime ("last Sunday +$nextweek week",$usertimevent)); //Datum nächster Montag
	$nextmondaytime = strtotime("last Sunday +$nextweek week",$usertimevent);
$tag1[0] = _SUN;
$tag1[1] = _MON;
$tag1[2] = _TUE;
$tag1[3] = _WED;
$tag1[4] = _THU;
$tag1[5] = _FRI;
$tag1[6] = _SAT;
}



$query = $db->query("SELECT id, stamp, subject, username, privat, high FROM ".$db->prefix("ecal")." WHERE (stamp >= \"$lastmonday1 00:00:00\" and stamp <= \"$nextmonday 00:00:00\") AND valid = 'yes' ORDER BY stamp");

while($myrow = $db->fetchArray($query)) {
$jahr = substr($myrow['stamp'],0,4);
$monat = substr($myrow['stamp'],5,2);
$tag = substr($myrow['stamp'],8,2); 
$datum = $tag.".".$monat.".".$jahr; //Datum anpassen für ausgabeabfrage

	if ($xoopsUser) {
		if ($myrow["privat"] == 1 and $myrow["username"] == $xoopsUser->uname()) {
			if ($myrow['high'] == 1) {
			    $high = _CAL_TIPP;
			}else{
				$high = "";
			}
		$termin[$datum] .= "$high <a href='display.php?day=$tag&month=$monat&year=$jahr'>";
		$termin[$datum] .= "<img src='images/mini_calendar.gif' alt='"._CAL_TERMIN."'> ".$myrow['subject']."</a><br>";
			
		}
	}
	if($myrow["privat"] == 0) {
		if ($myrow['high'] == 1) {
			    $high = _CAL_TIPP;
			}else{
				$high = "";
		}
		$termin[$datum] .= "$high <a href='display.php?day=$tag&month=$monat&year=$jahr'>";
		$termin[$datum] .= "<img src='images/mini_calendar.gif' alt='"._CAL_TERMIN."'> ".$myrow['subject']."</a><br>";
		if ($myrow['high'] == 1) {
			    $high[$datum] = _CAL_TIPP;
			}else{
				$high[$datum] = "";
			}
	}
}
//news **************
if ($shownews == 1) {
	$result=$db->query("SELECT storyid, published, title FROM ".$db->prefix("stories")." WHERE published >= ".strtotime("$lastmonday1 00:00:00")." and published <= ".strtotime("$nextmonday 23:59:59")." and published <= ". time()."");
		while (list( $storyid, $published, $title) = $db->fetchRow($result)){
			$tagnews = date("d",$published);
			$monatnews = date("m",$published);
			$jahrnews = date("Y",$published);
			$datumnews = $tagnews.".".$monatnews.".".$jahrnews; //Datum anpassen für ausgabeabfrage
			$news[$datumnews] .= "<a href=".$bcoosConfig['xoops_url']."/modules/news/article.php?storyid=$storyid><img src='images/mini_news.gif' alt='"._CAL_NEWS."'> $title</a><br>";
		}
}

OpenTable();
define("_NAVPAGE","WEEK");
include ("include/nav.php");

    echo "<table border='0' width='100%' class='bg3'><tr>";
    echo "<td align='left'>";
    form_last_week($lastweek);
    echo "</td>";
    echo "<td align='center'><b>"._WEEKCAL."</b></td>";
    echo "<td align='right'>";
    form_next_week($nextweek);
    echo "</td></tr></table>";
    echo "<table width='100%' cellpadding='5'  CELLSPACING='1' border='0'  class='bg2'>";

for ($i=0; $i<=6;$i++){
	$wochentag = date("l", $lastmondaytime + 3600 * 24 * $i);
	$daycal = date("d.m.Y",strtotime ("+$i day",$lastmondaytime));
	$dayheute = date("d.m",strtotime ("+$i day",$lastmondaytime));
	$yy = $currentday.".".$currentmonth;
		if ($yy == $dayheute) {
	   		echo "<tr><td width='14%' bgcolor='$daycolor'><b>".$tag1[$i]."</b><br>".$daycal."<br><br><br><br></td><td class='bg3'>$termin[$daycal]$news[$daycal]</td></tr>";
		}elseif ($wochentag == "Saturday" or $wochentag == "Sunday"){
			echo "<tr><td width='14%' bgcolor='$weekcolor'><b>".$tag1[$i]."</b><br>".$daycal."<br><br><br><br></td><td class='bg3'>$termin[$daycal]$news[$daycal]</td></tr>";
		}else{
			echo "<tr><td width='14%' class='bg1'><b>".$tag1[$i]."</b><br>".$daycal."<br><br><br><br></td><td class='bg3'>$termin[$daycal]$news[$daycal]</td></tr>";
	    }
}
echo "</table>";

    echo "<table border='0' width='100%' class='bg3'><tr>";
    echo "<td align='left'>";
    form_last_week($lastweek);
    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_week($nextweek);
    echo "</td></tr></table>";	
CloseTable();
include(XOOPS_ROOT_PATH."/footer.php");
?>