<?php
/**
 * This file is part of
 * pragmaMx - Web Content Management System.
 * Copyright by pragmaMx Developer Team - http://www.pragmamx.org
 *
 * pragmaMx 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.
 *
 * this is a part of mxSchedule 
 *
 * $Version 1.0 $
 * $Author: Olaf Herfurth / TerraProject  http://www.tecmu.de $
 * $Date: 2010/009/01 $
 *
 */

defined('mxMainFileLoaded') or die('access denied');


$module_name = basename(dirname(__FILE__));

$target = PMX_HOME_URL . '/modules.php?name=' . $module_name ;
if (!MX_IS_ADMIN && (empty($_SERVER['HTTP_REFERER']) || strpos($_SERVER['HTTP_REFERER'], PMX_HOME_URL) === false)) {
    @header('HTTP/1.1 301 Moved Permanently');
    @header('Status: 301 Moved Permanently');
    @mxRedirect($target);
}

mxGetLangfile($module_name);
//include_once(PMX_SYSTEM_DIR . "/mxNewsFunctions.php");

global $prefix, $currentlang,$module_name, $bgcolor1, $bgcolor2, $bgcolor3, $WSCFG;


    $catid=$cat;
	$fwhere="";
	$eventpath="";
	if ($secid!=0) {
	   $eventpath=WS_getSectionTitle($secid);
	}

	if ($catid!=0) {
	   $tcat=ws_getCategory($catid);
	   $eventpath =WS_getSectionPath($tcat['secid'])."".WS_getCategoryPath($catid,-1);
	}

	// Links erzeugen
	$linkNewEvent="";
    switch($WSCFG['SET_USERGROUP']){
		case 0:
		$linkNewEvent="| <a href='modules.php?name=$module_name&amp;act=eventnew'>"._MYEVENTS_NEW."</a>";
		break;
		case 1:
		$linkNewEvent=(MX_IS_USER)?"| <a href='modules.php?name=$module_name&amp;act=eventnew'>"._MYEVENTS_NEW."</a>":"";
		break;
		case 3:
		$linkNewEvent=(MX_IS_ADMIN)?"| <a href='modules.php?name=$module_name&amp;act=eventnew'>"._MYEVENTS_NEW."</a>":"";
		break;
	}
    $linkMyEvents=(MX_IS_USER)?"| <a href='modules.php?name=$module_name&amp;act=myevents' rel='nofollow'>"._MYEVENTS."</a>":"";
	$linkAdmin=(MX_IS_ADMIN)?"| <a href='admin.php?op=$module_name' rel='nofollow'>"._ADMINISRATION."</a>"."":"";

	if ($secid>0 ) {
	   $fwhere.= "and event.secid=$secid ";
	   ws_isSection($secid);
	   $linkindex="| <a href='modules.php?name=$module_name' rel='nofollow'>"._EVENTS_INDEX."</a>"."";
	}
	if ($catid>0 ) {
	    ws_isCategory($catid);
	    $fwhere.= "and event.catid=$catid ";
	    $linkindex="| <a href='modules.php?name=$module_name' rel='nofollow'>"._EVENTS_INDEX."</a>"."";

	}
	
    // SQL-Abfrage

	$isuser=(!MX_IS_USER)?" and event.privat=0 ":"";
	
	  $fSecid="event.secid";
	  if ($secid>0) {
	      $fwhere.=" and event.secid=$secid ";
		  $fSecid="$secid";
		 } else {
	      $fwhere.="";
	  }


	$result = sql_query("select event.* from " . TABLE_EVENTS . " as event, ".TABLE_SECTIONS." as section where
	                   event.startdate >'".(time()-86400 )."' " .$isuser." ".$fwhere."  
					   and section.published=1 and section.secid=".$fSecid." 
					   and event.publish=1 order by event.startdate asc limit ".$WSCFG['SET_SERCHRESULTS']);

$logo = (file_exists('images/' . $site_logo)) ? '<p>' . mxCreateImage('images/' . $site_logo, $sitename) . '</p>' : '';
					   
$sitetitle=$mxConf['sitename'];		
$content ="";			   

	$content .= "<table width=\"100%\" >";
	$content .= "<thead>";
	$content .= "<tr border=\"0\"  bgcolor=\"$bgcolor2\">";
	if ($WSCFG['SET_FRONTPAGE_WEEK']==1) $content .= "<th align=\"left\" width=\"25\">"._WEEK."</th>";
	$content .= "<th align=\"center\" width=\"30%\">"._EVENTS_STARTDATE."</th>";
	$content .= "<th align=\"left\" width=\"16\"></th>";
	$content .= "<th align=\"left\" >"._TITLE."</th>";
	$content .= "</tr>";
	$content .= "</thead>";
$i=0;
while ($myevt = sql_fetch_assoc($result)) {

		//if (!is_array($evt)) die('access denied');
		
		extract ($myevt);
		$vTime2 = ws_langDate(time());
		//if (!$eid or ($privat && !MX_IS_USER)) mxErrorScreen(_PAGESNOTFOUND);
		/**
		 * sicherstellen, dass der Seitentitel keine Tags enthält und Sonderzeichen nicht zerstückelt werden
		 */
		$title = strip_tags(str_replace('&nbsp;', ' ', $title));
		
			  // Datum ausgeben
			  if ($enddate==$startdate) {
				$vDate=_WEEK." ".date("W",$startdate)."/".date("y",$startdate)." | ".ws_langDate($startdate)." ";
				} else {
				$vDate=_WEEK." ".date("W",$startdate)."/".date("y",$startdate)." | ".ws_langDate($startdate)." "._TO." ".ws_langDate($enddate);
			  }
			  switch ($ignoretime) {
				 case 0:
					$vTime="";			//keine Zeitangabe
					break;
				 case 1:
					$vTime=""._START." ".date("H:i",$starttime)." "._CLOCK;  //nur Startzeit
					break;
				 case 2:
					$vTime="".date("H:i",$starttime)." "._TO." ".date("H:M",$endtime)." "._CLOCK;
					break;
				 case 3:
					$vTime=""._END." ".date("H:i",$endtime)." "._CLOCK;
					break;
			  }
		
		
		// Zusammensetzen
	    $bgc=(intval($i/2)===($i/2))?$bgcolor1:$bgcolor3;
		$mysec=ws_getSection($myevt['secid']);
		
		$bgc=(trim($mysec['color']) !="")?trim($mysec['color']):$bgc;
		
        $content .= "<tr border=\"1\" bgcolor=\"$bgc\" >";
		if ($WSCFG['SET_FRONTPAGE_WEEK']==1) $content .= "<td>".ws_getWeekYear($myevt['startdate'])."</td>";
		$eEnddate=(ws_getDate($myevt['enddate'])==ws_getDate($myevt['startdate']))?"</td>":"&nbsp;"._TO." ".ws_getDate($myevt['enddate'])."</td>";
		$content .= "<td align=center >".ws_getDate($myevt['startdate']).$eEnddate; 
		
	    $content .= "<td align=\"lef\"t ><img src=\"".ws_getSectionIconName($myevt['secid']).
		          "\" height=\"10\" width=\"10\" title=\"".
				  WS_getSectionTitle($myevt['secid'])."".
				  WS_getCategoryTitle($myevt['catid'],-1)."\"/></td>";
		$content .= "<td align=\"left\" bgcolor=\"$bgc\" >".mxPrepareToDisplay($myevt['title'])." </a></td>";
		 
		$content .= "</tr>";
		$i++;
		
}		
		$content .="</table>";
		

echo '<?xml version="1.0"?>
		';
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=<?php echo _CHARSET ?>" />
  <meta http-equiv="content-language" content="<?php echo _DOC_LANGUAGE ?>" />
  <meta name="robots" content="NOINDEX, NOFOLLOW" />
  <link rel="stylesheet" type="text/css" href="layout/style/style.css.php?t=<?php echo MX_THEME ?>" />
  <link rel="stylesheet" type="text/css" href="themes/<?php echo MX_THEME ?>/style/style.css" />
  <link rel="stylesheet" type="text/css" href="layout/style/printpage.css" />
  <title><?php echo $sitename.' - '.$title ?></title>
</head>

<body class="printpage">
  <div id="p-page">
    <div id="p-head">
      <?php echo $logo ?>
      <h2><?php echo $sitetitle ?></h2>
    </div>
    <div id="p-main" class="content">
      <h3><?php echo _LISTPRINT ?>&nbsp;:&nbsp;<?php echo $eventpath ?></h3><hr />
    </div>

    <div id="p-main" class="content">
      <?php echo $content ?>
    </div>
    <div id="p-foot">
      
      <p><?php echo _COMESFROM ?> <?php echo $sitename ?><br />
      <?php echo PMX_HOME_URL ?></p>

      <p><?php echo _THEURL ?><br />
      <?php echo htmlspecialchars($target) ?></p>
    </div>
  </div>
</body>
</html>
