<?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');
//  PMX SDK einbinden
include_once ('spaw'.DS.'spaw_control.class.php');
// Variablen definieren

function ws_showEvent($eid)
{
    global $prefix, $currentlang,$module_name, $bgcolor1, $bgcolor2, $bgcolor3, $WSCFG, $pagetitle;
	
	ws_isEvent($eid);
	$user=mxGetUserData();
	$conf=EventSetupConfig();
	
	$result = sql_query("select * from " . TABLE_EVENTS . " where eid=$eid  LIMIT 1 ");
	$evt=sql_fetch_assoc($result);	
	extract ($evt);
	//$config=unserialize($config);
	
	if (!$eid or ($privat==1 && !MX_IS_USER) or ($publish==0 && ($userid<>$user['uid']))) mxErrorScreen(_PAGESNOTFOUND);
	
	$userinfo=($publish==0 )?"<div class='warning'>"._INFO_USER_UNPUBLISHED."</div>":"";
	
	$picture=unserialize($pictures);
	$conf=unserialize($config);
	$cTitle=$title;
	
	// Variablen definieren
	$pagetitle=$title;
	$vTitle=$cTitle;
	$vDate="";
	$vTime="";
	$vContent="";
	$vZusatz="";
	$vInfo="";
	$vLinks="";
	$vPictures="";
	
	$vMyid=($parentid==0)?$eid:$parentid;
	// ABfragen
	  $uinfo = mxGetUserData();
	  $adminlinkedit=(ws_isAdmin())?"<a href='modules.php?name=$module_name&amp;act=eventedit&amp;eid=$vMyid&amp;ok=0' >"._EDIT."</a> |":"";
	  //MX_IS_ADMIN or 
	  //$uinfo= mxGetUserDataFromUid($userid);
	 $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 2:
		$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>"."":"";
	$linkindex="<a href='modules.php?name=$module_name' rel='nofollow'>"._EVENTS_INDEX."</a>"."";
	$adminlink="<p align=\"right\">[ $linkindex $linkNewEvent $adminlinkedit $linkMyEvents $linkAdmin ]</p>";

	  // Datum ausgeben
	  if ($enddate==$startdate) {
	    $vDate=_WEEK." ".ws_getWeekYear($startdate)." | ".ws_langDate($startdate)." "; //date("W",$startdate)."/".date("Y",$startdate)
		} else {
		$vDate=_WEEK." ".ws_getWeekYear($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 3:
		    $vTime=" | ".date("H:i",$starttime)." "._TO." ".date("H:i",$endtime)." "._CLOCK;
			break;
		 case 2:
		    $vTime=" | "._END." ".date("H:i",$endtime)." "._CLOCK;
			break;
	  }
	  $vContent .= mxPrepareToDisplay($text1);
	// Anmeldedatum
	   $vDeadline="";
	   if ($ignoredeadline>0){
	      switch ($ignoredeadline) {
		     case 1:
			    if (($WSCFG['SET_EVENT_INFO_DEADLINE'] > 0 ) and $deadline-($WSCFG['SET_EVENT_INFO_DEADLINE']*86400)< time() and ($deadline > time())) {// INFO
				    $vDeadline="<div class='important'>"._DEADLINE_UNTIL." <b>".ws_langDate($deadline)."</b></div>";
					} else {
				    $vDeadline=_DEADLINE." : ".ws_langDate($deadline)."";
				}
			    if ($deadline < time()) { // ende
				    $vDeadline=_DEADLINE_END." !!";
				}
			    break;
			 case 2:
			    $vDeadline=_DEADLINE_EVER;
			    break;
		  }
       }	
	   
    // Breadcrumb
	
	   $breadcrumb=WS_getSectionPath($secid)."-".WS_getCategoryPath($catid,-1);
	   
	// Links
	   if ($parentid >0 ) {
	      $seid=$parentid;
		  } else {
		  $seid=$eid;
	   }
	   $result1=sql_query("select eid,title,startdate,enddate from ".TABLE_EVENTS." where eid=$seid or parentid=$seid and enddate>".(time()-86400)." order by eid limit 0,".($WSCFG['DETAIL_BOUND_COUNT']+1));
	   $linkcount=sql_num_rows($result1);
	   if  ($linkcount>1) {
	      $vLinks ="<table class=\"list\" width=\"100%\"><tr><th class=\"title\" colspan=\"2\">"._DATE_LINKED."</th></tr>";
	      while (list($leid,$ltitle,$lstartdate,$lenddate)=sql_fetch_array($result1)) {
			  if ($enddate==$startdate) {
				$lDate=_WEEK."".ws_getWeekYear($lstartdate)."</td><td> <a href='modules.php?name=$module_name&amp;act=show&amp;eid=$leid'>  ".ws_langDate($lstartdate)."</a> ";
				} else {
				$lDate=_WEEK." ".ws_getWeekYear($lstartdate)."</td><td><a href='modules.php?name=$module_name&amp;act=show&amp;eid=$leid'>".ws_langDate($lstartdate)." "._TO." ".ws_langDate($lenddate)." </a>";
			  }
		    if ($leid!=$eid) {
			 $vLinks .="<tr><td width='50%'>$lDate</td></tr>"; 
			}
		  }
		  $vLinks .="</table>";
	   }
       $secpic=ws_getSectionIcon($secid);
	// Pictures
	  if (count($picture)>0 and $WSCFG['SET_MAXPICTURES']>0) {
	     $piccount=0;
	     $vPictures= "<hr /><p class=\"tiny\">"._CLICKFORFULLSIZE."</p>";
		 //$vPictures.= "<table class='table' ><tr>";
	    foreach ($picture as $key =>$value) {
		 $piccount++; 
		 if ($piccount> $WSCFG['SET_MAXPICTURES']) break;
		 if ($value!="") {
		   $etname=explode('.',$value);
		   $tname=$etname[count($etname)-2]."-thumb.".strtolower($etname[count($etname)-1]);
		   $cimg=mxCreateImage($tname,$vTitle);
		   $vPictures.= "<div style='padding:5px; 
		   							display:inline; 
									vertical-align: top;'>
									<a href='$value' rel=\"pretty".((count($picture)==1)?"":"[gal]")."\" title='".$vTitle."' >".$cimg."</a></div>";
		  }
		}
			$vPictures.= "<hr />";
	  }
	// ext Fields
	  $secconfig=ws_getSectionConfig($secid);
	  $secfield=$secconfig['FIELD'];
	  $vOrganizer="<table class='table'>";
	  foreach ($secfield as $key =>$i) {
	    $vextzusatz="";
		$vhon="";
		$vhend="";
		$vFlag=true;
	     if ($secfield[$key]['STATUS']>0 and trim($secfield[$key]['NAME'])!="" and trim($evt[$key])!="") {
		  switch ($key) {
		    case "maplink":
			case "text1":
			case "text2":
			case "text3":
			case "tax":
			case "vcontact":
			   $vFlag=false;
			   break;
			case "homepage":
			   if (substr($evt[$key],0,7)!="http://") $evt[$key]="http://".$evt[$key];
			   $vhon="<a href='".$evt[$key]."' target='_blank' rel='nofollow'>";
			   $vhend="</a>";
			   break;
			case "price":
			   $vextzusatz="Euro";
			   if ($tax==1) $vextzusatz.=" ("._SECTIONS_FIELD_TAX.")";
			   break;
		  }
		  if ($vFlag) $vOrganizer .="<tr valign='top'><td valign='top'><i>".$secfield[$key]['NAME']."</i></td><td valign='top'>:&nbsp;".$vhon.mxPrepareToDisplay($evt[$key]).$vhend." ".$vextzusatz."</td></tr>"; 
		 }
	  }
	  $vOrganizer .="<tr><td></td></tr></table>";
	  
	// Update counter
	
	    sql_query("update ".TABLE_EVENTS." set counter=counter+1 where eid=$eid");
		$vCounter=$counter;
		
	   $vInfo1 =($WSCFG['SET_DETAIL_USER']==1)?_PUBLISHEDON." ".date("d.m.Y",$dateedit)." "._FROM." <a href='modules.php?name=Userinfo&amp;uname=".$evt['uname']."' rel=\"nofollow\" >".$evt['uname']."</a>":"";
	   $vInfo2 =($WSCFG['SET_DETAIL_COUNTER']==1)?" - "._EVENTCOUNTER."$vCounter"._EVENTCOUNTER2:"";
	   $vInfo=$vInfo1."  ".$vInfo2."";
    
	//  Links 'ähnliche '
	   $vLinks3="";
	 if (!empty($keywords)) {
	   $vKeywords=explode(",",$keywords);
	   $xKeywords=implode(" ",$vKeywords);
	   $result1=sql_query("select eid,title,startdate,enddate from ".TABLE_EVENTS." where startdate>'".(time()-86400) ."' 
	                              and parentid='0' 
								  and publish='1' 
								  and secid<>$secid 
								  and match(title,keywords) AGAINST('$xKeywords' IN BOOLEAN MODE) order by startdate asc LIMIT 0,".$WSCFG['DETAIL_LINKS_COUNT']);
	   $linkcount1= sql_num_rows($result1);
	   if  ($linkcount1>0) {
	      
	      while (list($leid,$ltitle,$lstartdate,$lenddate)=sql_fetch_array($result1)) {
			  if ($leid!=$eid ) {
				  if ($lenddate==$lstartdate) {
					$lDate=_WEEK." ".ws_getWeekYear($lstartdate)." | ".ws_langDate($lstartdate)." ";
					} else {
					$lDate=_WEEK." ".ws_getWeekYear($lstartdate)." | ".ws_langDate($lstartdate)." "._TO." ".ws_langDate($lenddate);
				  }
				 $vLinks3 .="<tr><td width=\"50%\">$lDate</td><td><a href=\"modules.php?name=$module_name&amp;act=show&amp;eid=$leid\" title=\"$ltitle\" >$ltitle</a></td></tr>";
			  }
		  }
		  if (!empty($vLinks3)) $vLinks3 ="<table class=\"list\" width=\"100%\"><tr><th class=\"title\" colspan=\"2\">"._EVENTS_EXTLINKS."</th></tr>".$vLinks3 .="</table>";
	   }
	  }	
	  
	// Buttonleiste zusammensetzen
	  $img_join="";
	  $joinuser=0;
  if (isset($conf['JOIN_VIEW'])) {
	  switch ($conf['JOIN_VIEW']){
	     case 0:		//keiner
		      $joinuser=0;
		   break;
	     case 1:		//nur ich
		      $joinuser=(ws_isMyEventBool($eid))?1:MX_IS_ADMIN;
		   break;
	     case 2:		//user
		      $joinuser=(MX_IS_USER)?1:MX_IS_ADMIN;
		   break;
	     case 3:		//auch Gäste
		      $joinuser=1;
		   break;
	  }
		  $img_join=($conf['JOIN']==1)?"<a href='modules.php?name=$module_name&amp;act=join&amp;eid=$eid' title='"
		             ._PAGE_JOIN."' rel='nofollow'>".mxCreateImage("modules/" . $module_name . "/style/images/action/user_add.png",$module_name)."</a>":"";
	}  
	
	  $img_adduser=(MX_IS_USER and ($startdate>time()))?"<a href='modules.php?name=$module_name&amp;act=rememberme&amp;eid=$eid' title='"._DETAIL_REMINDER."' rel='nofollow'>".mxCreateImage("modules/" . $module_name . "/style/images/action/clock_play.png",$module_name)."</a>":"";
	  $img_comment=(!($vcontact==""))?"<a href='modules.php?name=$module_name&amp;act=sendcomment&amp;eid=$eid' title='"._DETAIL_SENDCOMMENT."' rel='nofollow'>".mxCreateImage("modules/" . $module_name . "/style/images/action/user_comment.png",$module_name)."</a>":"";
	
	  $img_bad=($WSCFG['SET_SHOW_BAD']==1)?"<a href='modules.php?name=$module_name&amp;act=sendadmin&amp;eid=$eid' title='"._DETAIL_SENDADMIN."' rel='nofollow'>".mxCreateImage("modules/" . $module_name . "/style/images/action/email_error.png",$module_name)."</a>":"";
	
	  $img_friend=($WSCFG['SET_SHOW_FRIEND']==1)?"<a href='modules.php?name=$module_name&amp;act=sendfriend&amp;eid=$eid' title='"._DETAIL_SENDAFRIEND."' rel='nofollow'>".mxCreateImage("modules/" . $module_name . "/style/images/action/email_to_friend.png",$module_name)."</a>":"";
	  
	  $img_print="<a href='modules.php?name=$module_name&amp;act=eventprint&amp;eid=$eid' title='"._DETAIL_PRINTER."' rel='nofollow' target='_blank'>".mxCreateImage("modules/" . $module_name . "/style/images/action/printer.png",$module_name)."</a>";
	
	  $buttonleiste=$img_join." ".$img_adduser." ".$img_comment." ".$img_friend." ".$img_bad." ".$img_print;
	// Seitenaufbau
	 
	  $pagetitle="".$vTitle;
	
	  include ("header.php");
	  ws_addCss();
	  ws_onClick();
	  ws_isHome();
	  echo "<div class=\"content\" align=\"right\">$adminlink</div>";
	  
		echo "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
					 <tr><td width=\"50\">$secpic</td>
					 <td align=\"left\" valign=\"middle\"><h2>".$vTitle."</h2></td></tr></table>";
		
		
	  
	  OpenTable();
          
		  if ($WSCFG['NAVIGATION']==1) echo $breadcrumb."<br /><br />";
		  if ($publish==1) {
		      echo "<table width='95%' class='table'><tr><td class=\"align-right\">$buttonleiste</td></tr></table>";
	      }
		  echo $userinfo;
		  //OpenTable2();
			echo "<table class=\"list\" width=\"100%\"><tr><th class=\"title \">$vDate  $vTime</th></tr></table>";
		  //CloseTable2();
		  echo "<div class='story-content'>$vContent<br /></div>";
		  echo "<div class='story-content'>$vDeadline<br /></div>";
			
		  echo "<br/>";
		  echo mxPrepareToDisplay($text2);
		  //echo "<br/>";
		  echo $vPictures;
		  echo "<br/><table cellspacing=\"2\" cellpadding=\"2\"><tr>";
			 if ($maplink==1 ) echo "<td><a href='".LinkToGoogleMap ($organizer,$zipcode,$adress,$city,$state)."' rel='nofollow' target='_blank' ><img src='".imgGoogleMap ($organizer,$zipcode,$adress,$city,$state)."' /></a></td>"; 
		  echo "<td>";
		  echo $vOrganizer; 
		  echo "</td>";
		  echo "</tr></table><br/>";
		  echo mxPrepareToDisplay($text3);
		  echo "<hr />";
		  echo "<div class='tiny'>$vInfo</div><br />";
		  if (!empty($vLinks) and $WSCFG['SET_DETAIL_BOUND']==1) {
//			OpenTable2();
//			  echo "<p class='title'>"._DATE_LINKED.":</p>".$vLinks."";
//			CloseTable2();
			  echo $vLinks;
			echo "<br />";
		  }
		  if (!empty($vLinks3) and $WSCFG['SET_DETAIL_LINKS']==1) {
			//OpenTable2();
			  //echo "<p class='title'>"._EVENTS_EXTLINKS.":</p>".$vLinks3."";
			  echo $vLinks3;
			//CloseTable2();
		  }
		  echo "<br/><br/>";
		  
		  echo "<br/><br/>";
		  goHomeIndex();
	  CloseTable();
	  include("footer.php");
	
}

function ws_sendAdmin($eid,$ok=0)
{
    global $prefix, $currentlang,$module_name, $bgcolor1, $bgcolor2, $bgcolor3, $WSCFG;
	  $ferror="";
	  ws_isEvent($eid);
	  if (isset($_POST['exit']))mxRedirect("modules.php?name=$module_name&amp;act=show&amp;eid=$eid");;
	  $rsc=(isset($_POST['rsc']))?intval($_POST['rsc']):0;
	  
	  if (($rsc==1) and !ws_IsCaptchaok()) $ferror= "<p class='warning'>"._ERR_CAPTCHA."</p>";
	  
	  if ($ok==1 and (empty($ferror))) {
	      ws_mail_eventbad ($eid);
		  mxRedirect("modules.php?name=$module_name",_PAGE_ADMINSEND_INFO4,3);
	  }
	  
	  $titelzeile=_PAGE_ADMINSEND;
	  $pagetitle=$titelzeile;
	
	  include ("header.php");
	  ws_addCss();
	  ws_isHome();
	  
	  $result=sql_query("select title,uname from ".TABLE_EVENTS." where eid='".$eid."' limit 1");
	  list($stitle,$suname)=sql_fetch_row($result);
		
		title($titelzeile);
	  
	  OpenTable();
	      echo $ferror;
		  echo "<br/><br/>";
		  echo _PAGE_ADMINSEND_INFO1;
		  echo "<br/><hr/><b>".$stitle."</b> "._FROM." ".$suname."<hr/><br/>";	  
		  echo _PAGE_ADMINSEND_INFO2;
		  echo "<br/><br/>";	  
		  echo _PAGE_ADMINSEND_INFO3;
		  echo "<br/><br/>";	  
		  
	adminFormOpen("modules.php?name=$module_name");	  
	  // Captcha 
	  $cactive=true;
	  switch ($WSCFG['SET_CAPTCHAUSER']) {
	     case 0: 
		   $cactive=false;
		   break;
		 case 1:
		   $cactive=(!MX_IS_ADMIN and !MX_IS_USER)?true:false;
		   break;
		 case 2:
		   $cactive=(!MX_IS_ADMIN)?true:false;
		   break;
	  }
	  
	    $strOK=($cactive)?"1":"0";
		
	   	echo '<input type="hidden" name="rsc" value="'.$strOK.'"/>';
	   	echo '<input type="hidden" name="act" value="sendadmin"/>';
	   	echo '<input type="hidden" name="eid" value="'.$eid.'"/>';
	   	echo '<input type="hidden" name="ok" value="1" />';
	   	
	    ws_addCaptcha($cactive);
		
		echo "<div class='align-center'><input type=\"submit\" name=\"GO\" value=\""._SEND."\"/>";
		echo "&nbsp;&nbsp;<input type=\"submit\" name=\"exit\" value=\""._CANCEL."\"/></div>";
		
	adminFormClose();	
	  echo "<p class=\"note align-center\">"._YOUR_IP." ".$_SERVER['REMOTE_ADDR']." "._YOUR_IP_SAVED."</p>";
	  CloseTable();
	  include("footer.php");
	
}

function ws_sendFriend($eid,$ok=0)
{
    global $prefix, $currentlang,$module_name, $bgcolor1, $bgcolor2, $bgcolor3, $WSCFG;
	  $ferror="";
	  ws_isEvent($eid);
	  
	  if (isset($_POST['exit']))mxRedirect("modules.php?name=$module_name&amp;act=show&amp;eid=$eid");;
	  $rsc=(isset($_POST['rsc']))?intval($_POST['rsc']):0;
	  $ok=(isset($_POST['ok']))?intval($_POST['ok']):0;
	  $sname=(isset($_POST['sname']))?trim($_POST['sname']):"";
	  $semail=(isset($_POST['semail']))?trim($_POST['semail']):"";
	  $eemail=(isset($_POST['eemail']))?trim($_POST['eemail']):"";
	  $ename=(isset($_POST['ename']))?trim($_POST['ename']):"";
	  $stext=(isset($_POST['stext']))?trim($_POST['stext']):"";
	  
	  if ($ok==1) { 
		  list($pppuser, $host)=explode("@", $semail);
			if (!(checkdnsrr( $host, "MX") or checkdnsrr($host,"A")))  $ferror .= _ERR_MAIL . "<br />";	 
		  list($pppuser, $host)=explode("@", $eemail);
			if (!(checkdnsrr( $host, "MX") or checkdnsrr($host,"A")))  $ferror .= _ERR_MAIL . "<br />";	 
	  }
	  if (($rsc==1) and !ws_IsCaptchaok()) $ferror= "<p class='warning'>"._ERR_CAPTCHA."</p>";
	  
	  if ($ok==1 and (empty($ferror))) {
	     ws_mail_sendfriend ($eid,$sname,$semail,$stext,$ename,$eemail,$ok);
		 mxRedirect("modules.php?name=$module_name&amp;act=show&amp;eid=$eid",_PAGE_FRIENDSEND_INFO3,3);
	  }
	  
	  $titelzeile=_PAGE_FRIENDSEND;
	  $pagetitle=$titelzeile;
	
	  include ("header.php");
	  ws_addCss();
	  ws_isHome();
	  
	  $result=sql_query("select title,uname from ".TABLE_EVENTS." where eid='".$eid."' limit 1");
	  list($stitle,$suname)=sql_fetch_row($result);
		
		title($titelzeile);
	  
	  OpenTable();
	      echo $ferror;
		  echo "<br/><br/>";
		  echo _PAGE_FRIENDSEND_INFO1;
		  echo "<br/><hr/><b>".$stitle."</b> "._FROM." ".$suname."<hr/><br/>";	  
		  echo _PAGE_FRIENDSEND_INFO2;
		  echo "<br/><br/>";	  
		  
	adminFormOpen("modules.php?name=$module_name");	  
	  // Captcha 
	  $cactive=true;
	  switch ($WSCFG['SET_CAPTCHAUSER']) {
	     case 0: 
		   $cactive=false;
		   break;
		 case 1:
		   $cactive=(!MX_IS_ADMIN and !MX_IS_USER)?true:false;
		   break;
		 case 2:
		   $cactive=(!MX_IS_ADMIN)?true:false;
		   break;
	  }
	  
	    $strOK=($cactive)?"1":"0";
		
		
	    $user=getGetUser();
      
	    $sname=($user['uname']=="") ?"":$user['uname'];
	    $semail=($user['email']=="") ?"":$user['email'];
		
		
		echo "<table class='table'>";
	    echo "<tr><td>"._FRIENDS_ENAME.'</td><td><input type="text" name="ename" value="'.$ename.'"/></td></tr>';
	    echo "<tr><td>"._FRIENDS_EEMAIL.'</td><td><input type="text" name="eemail" value="'.$eemail.'"/></td></tr>';
		echo "<tr><td>"._FRIENDS_STEXT.'</td><td></td></tr>';

		echo "<tr><td colspan='2'><textarea name=\"stext\" cols='80' rows='10'>".$stext."</textarea></td></tr>";
	    echo "<tr><td>"._FRIENDS_SNAME.'</td><td><input type="text" name="sname" value="'.$sname.'"/></td></tr>';
	    echo "<tr><td>"._FRIENDS_SEMAIL.'</td><td><input type="text" name="semail" value="'.$semail.'"/></td></tr>';
		
	   	echo '<input type="hidden" name="rsc" value="'.$strOK.'"/>';
	   	echo '<input type="hidden" name="act" value="sendfriend"/>';
	   	echo '<input type="hidden" name="eid" value="'.$eid.'"/>';
	   	echo '<input type="hidden" name="ok" value="1" />';
	    ws_addCaptcha($cactive);
		
		echo "<div class='align-center'><input type=\"submit\" name=\"GO\" value=\""._SEND."\"/>";
		echo "&nbsp;&nbsp;<input type=\"submit\" name=\"exit\" value=\""._CANCEL."\"/></div>";
		
	adminFormClose();	
	      echo "<p class=\"note align-center\">"._YOUR_IP." ".$_SERVER['REMOTE_ADDR']." "._YOUR_IP_SAVED."</p>";
	  CloseTable();
	  include("footer.php");
	
}

function ws_sendComment($eid,$ok=0)
{
    global $prefix, $currentlang,$module_name, $bgcolor1, $bgcolor2, $bgcolor3, $WSCFG;
	  $ferror="";
	  ws_isEvent($eid);
	  
	  if (isset($_POST['exit']))mxRedirect("modules.php?name=$module_name&amp;act=show&amp;eid=$eid");;
	  $rsc=(isset($_POST['rsc']))?intval($_POST['rsc']):0;
	  $ok=(isset($_POST['ok']))?intval($_POST['ok']):0;
	  $sname=(isset($_POST['sname']))?trim($_POST['sname']):"";
	  $semail=(isset($_POST['semail']))?trim($_POST['semail']):"";
	  $stext=(isset($_POST['stext']))?trim($_POST['stext']):"";
	  
	  if ($ok==1) { 
		  list($pppuser, $host)=explode("@", $semail);
			if (!(checkdnsrr( $host, "MX") or checkdnsrr($host,"A")))  $ferror .= _ERR_MAIL . "<br />";	 
	  }
	  if (($rsc==1) and !ws_IsCaptchaok()) $ferror= "<p class='warning'>"._ERR_CAPTCHA."</p>";
	  
	  if ($ok==1 and (empty($ferror))) {
	     ws_mail_sendcomment ($eid,$sname,$semail,$stext,$ok);
		 mxRedirect("modules.php?name=$module_name&amp;act=show&amp;eid=$eid",_PAGE_COMSEND_INFO3,3);
	  }
	  
	  $titelzeile=_PAGE_COMSEND;
	  $pagetitle=$titelzeile;
	
	  include ("header.php");
	  ws_addCss();
	  ws_isHome();
	  
	  $result=sql_query("select title,uname from ".TABLE_EVENTS." where eid='".$eid."' limit 1");
	  list($stitle,$suname)=sql_fetch_row($result);
		
		title($titelzeile);
	  
	  OpenTable();
	      echo $ferror;
		  echo "<br/><br/>";
		  echo _PAGE_COMSEND_INFO1;
		  echo "<br/><hr/><b>".$stitle."</b> "._FROM." ".$suname."<hr/><br/>";	  
		  echo _PAGE_COMSEND_INFO2;
		  echo "<br/><br/>";	  
		  
	adminFormOpen("modules.php?name=$module_name");	  
	  // Captcha 
	  $cactive=true;
	  switch ($WSCFG['SET_CAPTCHAUSER']) {
	     case 0: 
		   $cactive=false;
		   break;
		 case 1:
		   $cactive=(!MX_IS_ADMIN and !MX_IS_USER)?true:false;
		   break;
		 case 2:
		   $cactive=(!MX_IS_ADMIN)?true:false;
		   break;
	  }
	  
	    $strOK=($cactive)?"1":"0";
		
		
	    $user=getGetUser();
      
	    $sname=($user['uname']=="") ?"":$user['uname'];
	    $semail=($user['email']=="") ?"":$user['email'];
				
		echo _FRIENDS_STEXT.':<br />';

		echo "<textarea name=\"stext\" cols='80' rows='10'>".$stext."</textarea><br />";
		echo "<table>";
	    echo "<tr><td>"._FRIENDS_SNAME.'</td><td><input type="text" name="sname" value="'.$sname.'"/></td></tr>';
	    echo "<tr><td>"._FRIENDS_SEMAIL.'</td><td><input type="text" name="semail" value="'.$semail.'"/></td></tr>';
		echo "</table>";
		
	   	echo '<input type="hidden" name="rsc" value="'.$strOK.'"/>';
	   	echo '<input type="hidden" name="act" value="sendcomment"/>';
	   	echo '<input type="hidden" name="eid" value="'.$eid.'"/>';
	   	echo '<input type="hidden" name="ok" value="1" />';
	    ws_addCaptcha($cactive);
		
		echo "<div class='align-center'><input type=\"submit\" name=\"GO\" value=\""._SEND."\"/>";
		echo "&nbsp;&nbsp;<input type=\"submit\" name=\"exit\" value=\""._CANCEL."\"/></div>";
	    echo "<p class=\"note align-center\">"._YOUR_IP." ".$_SERVER['REMOTE_ADDR']." "._YOUR_IP_SAVED."</p>";
		
	adminFormClose();	
	  CloseTable();
	  include("footer.php");
	
}

function ws_rememberme($eid,$ok=0)
{
    global $prefix, $currentlang,$module_name, $bgcolor1, $bgcolor2, $bgcolor3, $WSCFG;
	  $ferror="";
	  ws_isEvent($eid);
	  
	  $user=mxGetUserData();
	  $sname=($user['uname']=="") ?"":$user['uname'];
	  $semail=($user['email']=="") ?"":$user['email'];
	  
	  
	  if (isset($_POST['exit']))mxRedirect("modules.php?name=$module_name&amp;act=show&amp;eid=$eid");;
	  $rsc=(isset($_POST['rsc']))?intval($_POST['rsc']):0;
	  
	  if (($rsc==1) and !ws_IsCaptchaok()) $ferror= "<p class='warning'>"._ERR_CAPTCHA."</p>";
	  
	  if ($ok==1 and (empty($ferror))) {
	      $result=sql_query("select parentid from ".TABLE_EVENTS." where eid='".$eid."' limit 1");
	      list($parentid)=sql_fetch_row($result);
		  if ($parentid==0) $parentid=$eid;
	      sql_query("insert ".TABLE_USER." set userid='".$user['uid']."', eid='$eid', reminder='1', parentid=$parentid");
		  
		  mxRedirect("modules.php?name=$module_name&amp;act=show&amp;eid=$eid",_PAGE_REMEMBERME_INFO4,3);
	  }
	  
	  $titelzeile=_PAGE_REMEMBERME;
	  $pagetitle=$titelzeile;
	
	  include ("header.php");
	  ws_addCss();
	  ws_isHome();
	  
	  $result=sql_query("select count(userid) from ".TABLE_USER." where eid='".$eid."' and userid='".$user['uid']."' and reminder='1'");
	  list($tcount)=sql_fetch_row($result);

	  $result=sql_query("select title,uname from ".TABLE_EVENTS." where eid='".$eid."' limit 1");
	  list($stitle,$suname)=sql_fetch_row($result);
		
	  title($titelzeile);
	  
	  OpenTable();
	  
	     if ($tcount==0) {
	      echo $ferror;
		  echo "<br/><br/>";
		  echo _PAGE_REMEMBERME_INFO1;
		  echo "<br/><hr/><b>".$stitle."</b> "._FROM." ".$suname."<hr/><br/>";	  
		  echo _PAGE_REMEMBERME_INFO2;
		  echo "<br/><br/>";	  
		  echo _PAGE_REMEMBERME_INFO3." ".mxPrepareToDisplay($semail);
		  echo "<br/><br/>";	  
		  
			adminFormOpen("modules.php?name=$module_name");	  
			  // Captcha 
			  $cactive=true;
			  switch ($WSCFG['SET_CAPTCHAUSER']) {
				 case 0: 
				   $cactive=false;
				   break;
				 case 1:
				   $cactive=(!MX_IS_ADMIN and !MX_IS_USER)?true:false;
				   break;
				 case 2:
				   $cactive=(!MX_IS_ADMIN)?true:false;
				   break;
			  }
			  
				$strOK=($cactive)?"1":"0";
			  
				echo '<input type="hidden" name="rsc" value="'.$strOK.'"/>';
				echo '<input type="hidden" name="act" value="rememberme"/>';
				echo '<input type="hidden" name="eid" value="'.$eid.'"/>';
				echo '<input type="hidden" name="ok" value="1" />';
				ws_addCaptcha($cactive);
				
				echo "<div class='align-center'><input type=\"submit\" name=\"GO\" value=\""._SAVE."\"/>";
				echo "&nbsp;&nbsp;<input type=\"submit\" name=\"exit\" value=\""._CANCEL."\"/></div>";
				
			adminFormClose();
	      echo "<p class=\"note align-center\">"._YOUR_IP." ".$_SERVER['REMOTE_ADDR']." "._YOUR_IP_SAVED."</p>";
		  } else {
		     echo "<p class='warning align-center'>"._PAGE_REMEMBERME_INFO5."</p><br /><br />";
	         ws_goHomeBACK();
		  }	

	  CloseTable();
	  
	  include("footer.php");
	
}

function ws_join($eid,$ok=0)
{
    global $prefix, $currentlang,$module_name, $bgcolor1, $bgcolor2, $bgcolor3, $WSCFG;
	  $ferror="";
	  ws_isEvent($eid);
	  
	  $user=mxGetUserData();
	  $sname=($user['uname']=="") ?"":$user['uname'];
	  $semail=($user['email']=="") ?"":$user['email'];
	  
	  $img_delete= mxCreateImage("modules/" . $module_name . "/style/images/action/cross.png",$module_name);
	  
	  if (isset($_POST['exit']))mxRedirect("modules.php?name=$module_name&amp;act=show&amp;eid=$eid");;
	  $rsc=(isset($_POST['rsc']))?intval($_POST['rsc']):0;
	  
	  if (($rsc==1) and !ws_IsCaptchaok()) $ferror= "<p class='warning'>"._ERR_CAPTCHA."</p>";
	  
	  if ($ok==1 and (empty($ferror))) {
	      $result=sql_query("select parentid from ".TABLE_EVENTS." where eid='".$eid."' limit 1");
	      list($parentid)=sql_fetch_row($result);
		  if ($parentid==0) $parentid=$eid;
	      sql_query("insert ".TABLE_USER." set userid='".$user['uid']."', eid='$eid', status='1', parentid=$parentid, text='".$_SERVER['REMOTE_ADDR']."'");
		  
		  mxRedirect("modules.php?name=$module_name&amp;act=show&amp;eid=$eid",_PAGE_JOIN_INFO4,3);
	  }
	  
	  $titelzeile=_PAGE_JOIN;
	  $pagetitle=$titelzeile;
	
	  include ("header.php");
	  ws_addCss();
	  ws_isHome();
	  
	  $result=sql_query("select count(userid) from ".TABLE_USER." where eid='".$eid."' and userid='".$user['uid']."' and status='1'");
	  list($tcount)=sql_fetch_row($result);

	  $result=sql_query("select title,uname,config,deadline,enddate,startdate,ignoredeadline from ".TABLE_EVENTS." where eid='".$eid."' limit 1");
	  list($stitle,$suname,$config,$deadline,$enddate,$startdate,$ignoredeadline)=sql_fetch_row($result);
	  $conf=unserialize($config);
	  $joindate=0;
	  
	 
	 switch ($ignoredeadline) {
	     case 0:		// Anmeldung immer möglich
		 case 2:
		    $joindate=($startdate>(time()-86400))?1:0;
		  break;
		 case 1:		// bis zum Anmeldeschluss
		    $joindate=($deadline>time())?1:0;
	      break; 
	 }
	  
	  title($titelzeile);
	  
	  OpenTable();
	   
	     if ($tcount==0 and MX_IS_USER and $joindate==1) {
			  echo $ferror;
			  echo "<br/><br/>";
			  echo _PAGE_JOIN_INFO1;
			  echo "<br/><hr/><b>".$stitle." </b> "._FROM." ".$suname."<hr/><br/>";	  
			  echo _PAGE_JOIN_INFO2;
			  echo "<br/><br/>";	  
		  
		  
			adminFormOpen("modules.php?name=$module_name");	  
			  // Captcha 
			  $cactive=true;
			  switch ($WSCFG['SET_CAPTCHAUSER']) {
				 case 0: 
				   $cactive=false;
				   break;
				 case 1:
				   $cactive=(!MX_IS_ADMIN and !MX_IS_USER)?true:false;
				   break;
				 case 2:
				   $cactive=(!MX_IS_ADMIN)?true:false;
				   break;
			  }
			  
				$strOK=($cactive)?"1":"0";
			  
				echo '<input type="hidden" name="rsc" value="'.$strOK.'"/>';
				echo '<input type="hidden" name="act" value="join"/>';
				echo '<input type="hidden" name="eid" value="'.$eid.'"/>';
				echo '<input type="hidden" name="ok" value="1" />';
				ws_addCaptcha($cactive);
				
				echo "<div class='align-center'><input type=\"submit\" name=\"GO\" value=\""._SAVE."\"/>";
				echo "&nbsp;&nbsp;<input type=\"submit\" name=\"exit\" value=\""._CANCEL."\"/></div><br /><br />";
				
			adminFormClose();
	      echo "<p class=\"note align-center\">"._YOUR_IP." ".$_SERVER['REMOTE_ADDR']." "._YOUR_IP_SAVED."</p><br /><br />";
		  
		  } else {
		  
		     if ($tcount>0)  {
			    echo "<p class='warning align-center'>"._PAGE_JOIN_INFO5."</p><br /><br />";
			 } 
			 if (!MX_IS_USER) { 
			    echo "<p class='highlight align-center'>"._PAGE_JOIN_INFO6."</p><br /><br />";
			 }
			 if ($joindate==0) {
			    echo "<p class='highlight align-center'>"._EVENT_JOIN_NONE."</p><br /><br />";
			 }
		}	

	  $joinuser=0;
	  switch ($conf['JOIN_VIEW']){
	     case 0:		//keiner
		      $joinuser=(MX_IS_ADMIN)?1:0;
		   break;
	     case 1:		//nur ich
		      $joinuser=(ws_isMyEventBool($eid))?1:MX_IS_ADMIN;
		   break;
	     case 2:		//user
		      $joinuser=(MX_IS_USER)?1:MX_IS_ADMIN;
		   break;
	     case 3:		//auch Gäste
		      $joinuser=1;
		   break;
	  }

      if ($joinuser==1) {
		// Teilnehmerliste
		$result=sql_query("select count(userid) from ".TABLE_USER." where eid='".$eid."' and status='1'");
        list($jCount)=sql_fetch_row($result);
		
		if ($jCount>0) {
		 echo "<p class='higlight align-center'>"._PAGE_JOIN_INFO3."</p>";
		 echo "<div class=\"box\" ><table width=\"100%\">";
		 echo "<tr><th>"._USERNAME."</th><th>"._REALNAME."</th><th>"._JOIN_DATE."</th>";
		 if (ws_isMyEventBool($eid)) echo "<th>"._ACTION."</th>";
		 echo "</tr>";
		 
		 $result=sql_query("select * from ".TABLE_USER." where eid='".$eid."' and status='1'");
		 while($mjoin=sql_fetch_assoc($result)) {
			$juser=mxGetUserDataFromUid($mjoin['userid']);
			echo "<tr><td><a href='modules.php?name=Userinfo&amp;uname=".$juser['uname']."'>".$juser['uname']."</a> </td><td> [".$juser['name']."]</td><td>".$mjoin['date']."</td>";
			if (ws_isMyEventBool($eid)) {
	           $img_ip= "<img src='modules/" . $module_name . "/style/images/action/zoom.png' title=\"".$mjoin['text']."\" />";
			   echo "<td width=\"40\"><a href='modules.php?name=$module_name&amp;act=joindelete&amp;eid=$eid&amp;uid=".$mjoin['userid']."' >$img_delete</a>$img_ip</td>";
			}
			echo "</tr>";
			unset($juser);
		 }
		 
		 echo "</table></div><br /><br />";
		 } else {
		   // keine Teilhemer
		 echo "<br /><br /><p class='note align-center'>"._PAGE_JOIN_INFO7."</p><br /><br />";
		   
		 }
	  }
      CloseTable();
	  OpenTable();
      echo "<p class=\"align-right\">[<a href='modules.php?name=$module_name&amp;act=show&amp;eid=$eid'>"._BACK."</a>]</p>";
	  
	  CloseTable();
	  
	  include("footer.php");
	
}

?>