<?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: teilnehmen.php,v 1.1 2004/02/06 21:22:09 nobse 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 $_GET, $db, $bcoosConfig, $xoopsUser;
$tid   = $_GET['id'];
$month = $_GET['month'];
$year  = $_GET['year'];

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

list($noeintrag) = $db->fetchRow($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->fetchRow($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>"._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/".$bcoosConfig['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/".$bcoosConfig['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->fetchRow($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/".$bcoosConfig['iconset']."pm.gif' border='0'></td>";
		echo "<td width='10%'><a href='".XOOPS_URL."/userinfo.php?uid=".$uid."'><img src='language/".$bcoosConfig['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 $_POST, $xoopsUser, $db, $bcoosConfig;
$tid  		= $_POST['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 $_POST, $xoopsUser, $db, $bcoosConfig;
$tid  		= $_POST['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($_POST['op']) ? $_POST['op'] : $_GET['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);
}
?>