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

function teiladd() {
global $HTTP_GET_VARS, $db, $xoopsConfig, $xoopsUser;
$tid   = $HTTP_GET_VARS['id'];
$month = $HTTP_GET_VARS['month'];
$year  = $HTTP_GET_VARS['year'];

$query = $db->query("SELECT * FROM ".$db->prefix("ecal")." WHERE id = $tid");
$row = $db->fetch_array($query);
$datum  = strftime(_EVEDATESHORT,strtotime($row['stamp']));

list($noeintrag) = $db->fetch_row($db->query("SELECT COUNT(*) FROM ".$db->prefix("ecal_teiln")." WHERE uid = ".$xoopsUser->getvar("uid")." and tid = $tid"));
$result = $db->query("SELECT uid, uname FROM ".$db->prefix("ecal_teiln")." WHERE tid = $tid ");
list($anzahl) = $db->fetch_row($db->query("SELECT COUNT(*) FROM ".$db->prefix("ecal_teiln")." WHERE tid = $tid"));
 
include(XOOPS_ROOT_PATH."/header.php");
OpenTable();
include ("include/nav.php");

echo "<table width='100%' class='bg2' border='0'><tr>";
echo "<td width='40%'><b>"._CAL_DATE."</b>".$datum."</a></td>";
echo "<td width='60%'><b>"._CAL_TITLE."</b> ".$row['subject']."</td></tr></table>";

echo "<table width='100%' class='bg3' border='0'><tr><td width='50%'>";

//linke tabelle
echo "<table width='100%' class='bg3' border='0'>";
echo "<form name='teiln' method='post' action='teilnehmen.php'>";
echo "<tr><td><center>"._CAL_TEILNAHME."</center></td></tr>";
echo "<input type='hidden' name='tid' value='$tid'>";
if ($noeintrag == 0) {
	echo "<input type='hidden' name='op' value='teilsave'>";
	echo "<tr><td><center><input type='image' src='".XOOPS_URL."/modules/ecal/language/".$xoopsConfig['language']."/images/icon_teiln_save.gif'></center></td></tr>";
} else {
	echo "<input type='hidden' name='op' value='teildel'>";
	echo "<tr><td><center><input type='image' src='".XOOPS_URL."/modules/ecal/language/".$xoopsConfig['language']."/images/icon_teiln_delete.gif'></center></td></tr>";
}

echo "</form><tr><td>";
echo "<center>";
form_ret_ecal($month,$year);
echo "</center></td></tr></table>";

//*************
echo "</td><td width='50%'>";
//rechte tabelle
echo "<table width='100%' class='bg3' border='0'>";
if ($anzahl != 0) {
	echo "<tr><td>"._CAL_ANZAHL_TEILN.$anzahl."</td><td></td><td></td></tr>";
	while (list($uid, $uname) = $db->fetch_row($result)){
		echo "<tr><td width='80%'>".$uname."</td>";
		echo "<td width='10%'><a href='".XOOPS_URL."/modules/messages/pmlite.php?send=1&to_userid=".$uid."'><img src='".XOOPS_URL."/images/icons/pm.gif' border='0'></td>";
		echo "<td width='10%'><a href='".XOOPS_URL."/userinfo.php?uid=".$uid."'><img src='language/".$xoopsConfig['language']."/images/icon_profile.gif' border='0' width='59' height='18' ALT='".$uname."'></a></td></tr>";
		
	}
} else {
	echo "<tr><td>"._CAL_NO_TEILN."</td></tr>";
}

echo "</table>";
//****************
echo "</td></tr></table>";

CloseTable();
include(XOOPS_ROOT_PATH."/footer.php");
}
//*******************************************************+
function teilsave() {
global $HTTP_POST_VARS, $xoopsUser, $db, $xoopsConfig;
$tid  		= $HTTP_POST_VARS['tid'];
$userid = $xoopsUser->getvar("uid");
$uname = $xoopsUser->getvar("uname");

$newid = $db->genId($db->prefix('ecal_teiln')."_id_seq");
$temp = $db->query("INSERT INTO ".$db->prefix("ecal_teiln")." SET id=$newid, tid=$tid, uid = $userid, uname = '$uname' ");
	
redirect_header("index.php",1,_CAL_TEILN_ADD);
}

//*******************************************************+
function teildel() {
global $HTTP_POST_VARS, $xoopsUser, $db, $xoopsConfig;
$tid  		= $HTTP_POST_VARS['tid'];
$userid = $xoopsUser->getvar("uid");
$uname = $xoopsUser->getvar("uname");

//$newid = $db->genId($db->prefix('ecal_teiln')."_id_seq");
$temp = $db->query("DELETE FROM ".$db->prefix("ecal_teiln")." WHERE tid=$tid AND uid = $userid");
	
redirect_header("index.php",1,_CAL_TEILN_DEL);
}

//*************************************+
$op = !empty($HTTP_POST_VARS['op']) ? $HTTP_POST_VARS['op'] : $HTTP_GET_VARS['op'];
if ($xoopsUser) {
    
	switch ($op) {
	case "teilsave":
		teilsave();
		break;
	case "teiladd":
		teiladd();
		break;
	case "teildel":
		teildel();
		break;
	default:
		redirect_header("index.php");
		break;
	}
} else {
redirect_header("../../user.php",1,_NOACTION);
}
?>