<?php
##############################################################################################
# #
# groups.php #
# * ------------------- #
# * begin : Saturday, February 11, 2006 #
# * copyright : (C) 2004-2008 CompWebChess2 Development Team #
# * support : http://www.compwebchess.com/cms/index.php #
# * VERSION: : $Id: groups.php,v 2.2dev 2008/11/14 17:59:31 nelson8317 Exp $ #
# #
##############################################################################################
# This program 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 2 of the License, or (at your option) any later version. #
# #
# This program is distributed in the hope that it will be useful, but #
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS #
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License along with this #
# program; if not, write to: #
# #
# Free Software Foundation, Inc., #
# 59 Temple Place, Suite 330, #
# Boston, MA 02111-1307 USA #
##############################################################################################
$root = dirname(__FILE__);
session_start();
/* load settings */
require_once './includes/config.inc.php';
/* Language selection */
require_once "./includes/common.inc.php";
require_once "includes/languageselection.inc.php";
/* load external functions for setting up new game */
require_once './includes/chessutils.inc.php';
require_once './includes/chessconstants.inc.php';
require_once './includes/chessdb.inc.php';
require_once './includes/gui.inc.php';
/* allow WebChess to be run on PHP systems < 4.1.0, using old http vars */
fixOldPHPVersions();
/* if this page is accessed directly (ie: without going through login), */
/* player is logged off by default */
if (!isset($_SESSION['playerID']))
$_SESSION['playerID'] = -1;
//if ($_COOKIE["cookie_language"] != $_SESSION['pref_language'])
//
/* connect to database */
require_once './includes/connectdb.inc.php';
/* check session status */
require_once './includes/sessioncheck.inc.php';
/* set default playing mode to different PCs (as opposed to both players sharing a PC) */
$_SESSION['isSharedPC'] = false;
/* check if loading game */
if (isset($_POST['gameID']))
$_SESSION['gameID'] = $_POST['gameID'];
/* debug flag */
define ("DEBUG", 0);
require_once "./includes/groups_functions.inc.php";
if ($CFG_ENABLE_CHAT && isset($_POST['chat_msg'])){
if ($_POST[chat_msg] != "")
mysql_query("insert into chat_club (fromID,msg,group_id,hora) VALUES ('".$_SESSION[playerID]."','".$_POST[chat_msg]."','".$_POST[group_id]."', NOW())");
}
$action = (!empty($_POST['action'])) ? $_POST['action'] : $_GET['action'];
$id = (!empty($_POST['id'])) ? $_POST['id'] : $_GET['id'];
$pl = mysql_query("SELECT * FROM players WHERE playerID='".$_SESSION['playerID']."'");
$me = mysql_fetch_array($pl);
$firstName = $me['nick'];
?>
<!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=utf-8" />
<title><?=$CFG_SITE_NAME?> - <?=_("groups")?></title>
<link rel="stylesheet"
href="themes/<?=$_SESSION["pref_colortheme"]?>/styles.css"
type="text/css" />
<script>
function MessagePlayer(playerID)
{
var where="sendmessage.php?<?=$ssname?>=<?=$ssid?>&to="+playerID;
var height=320;
var width=470;
var left=(screen.availWidth/2)-(width/2);
var top=(screen.availHeight/2)-(height/2)-100;
window.open(where,"","height="+height+",width="+width+",left="+left+",top="+top);
}
</script>
<script language="javascript" type="text/javascript"> function clearAllText(thefield){ if (thefield.defaultValue==thefield.value) thefield.value = "" } </script>
<style>
TABLE {
font-size: 12;
font-family: verdana;
}
</style>
</head>
<body bgcolor=white text=black>
<?php include("./themes/".$_SESSION["pref_colortheme"]."/header.php");?>
<table width='98%' class='TABLE' align='center'>
<tr>
<th align='center' class='THTOP'><?=_("clubsmenu")?></th>
</tr>
<tr>
<td align=center class='TD'><a href="groups.php"><?=_("My Club")?></a> |
<a href="groups.php?action=new"><?=_("Create a Club")?></a> |
<a href="groups.php?action=list"><?=_("Join a Club")?></a> |
<a href="clubs_help.php"><?=_("Clubs Help")?></a></td>
</tr>
</table>
<br />
<?php
////////////////////////////////////// SWITCH START ////////////////////////////////////////////////////////////////////
switch($action) {
default:
$h = get_group($me['playerID']);
?>
<table width='98%' class='TABLE' align='center'>
<?php
if ($h == false)
{
?>
<tr>
<td align=center class='TD'><?=_("You are not yet a member of a club. Why not create or join one?")?>
<br />
<?=_("For more info on Clubs, see below")?>:</td>
</tr>
<tr>
<td class='TD'>
<div class="helptext"><?= sprintf(_("<p>Clubs are a way for people with common interests to get together, exchange ideas, and of course, to play chess!</p>
<p>Players can be one of two things in the Clubs Feature:<br />Club Member or Club President.</p>
<p>Club members join a Club so that the Club President can create tournaments and give the Club its character and overall emphasis.
<ol>Club Presidents have several powers and responsibilities:
<li>Ability to Create Clubs.</li>
<li>Approve prospective Club Members to be members of their Club.</li>
<li>Delete Club Members.</li>
<li>Create Club Tournaments.</li>
</ol>
Clubs can never be deleted, so if you create a Club, make certain it is one that you want to lead for a long time. Also, please note that ONLY the first Club you create can be used for your Club Tournaments.</p>
<p>Players can only belong to more than one Club at a time.
Club Presidents can never leave their Club. They can, however,
create an unlimited number of Clubs for others to join.<br />
<u>Here is an example of how Clubs might Work:</u></p>
<p>Let us create a fictitious Club, one called, for the purposes of this example.</p>
<p>Nelson decides to create a Club Tournament. In his %s Club, he has 5 members:</p>
<p>Player 1, Player 2, Player3, Player4, and Player5.</p>
<p>He then goes to the Tournaments feature and creates his Tournament. When setting up his tournament, he will select in the Access section the choice, \"My Club\". The new Tournament is then created.</p>"), $CFG_SITE_NAME) ?>
</div>
</td>
<?php
} else {
?>
<tr>
<td align=center class='TD'><?php
$num = 0;
while (list($key,$val) = each($h))
{
echo '<br />'._("teamleader").' ';
echo ($val['creator'] == $me['playerID']) ? ('<strong>'._("Club President").'</strong>'): _('in');
echo _("of the Club") . '<a href="groups.php?action=view&id='.$val['group_id'].'">'.$val['title'].'</a><br />';
$num++;
$toid = $val['group_id'];
} // while
if ($num == 1)
{
?>
<meta http-equiv="refresh"
content="0;url=groups.php?action=view&id=<?=$toid?>" />
</td>
<?php
}
}
?>
</tr>
</table>
<?php
break; // case default
case 'new':
$query = "SELECT count(*) as anz FROM groups WHERE creator = '".$me['playerID']."'";
$c1 = mysql_query($query);
$c = mysql_fetch_array($c1);
$c = $c['anz'];
/*if ($c >= 1 && !in_array($me['playerID'], $ag_leiter))
{
echo "You have already created a team.";
exit;
}*/
?>
<table bgcolor='$bgcolor6' border='0' style='width: 98%' align='center'>
<tr>
<td align='center'>
<form action="groups.php" method="post"><input type="hidden"
name="action" value="create" /> <strong><?= _("Name of Club") ?>: </strong> <br />
<input type="text" name="title" /><br />
<br />
<strong><?= _("Club Description") ?>:</strong> <br />
<textarea name="text" rows="7" cols="30"></textarea><br />
<br />
<strong><?= _("Club Type") ?>:<strong> <br />
<select name="ag">
<option value="0"><?= _("Tournament Club") ?></option>
<option value="1"><?= _("Second Club (only choose this if you already created a club!)") ?></option>
</select><br />
<br />
<input type="submit" /></form>
</td>
</tr>
</table>
<?php
break; // case new
case 'create':
if (is_creator($me['id']))
{
echo _("This Club has already been created.");
exit;
}
if (empty($_POST['title']))
{
echo _("Please enter a Club name.");
exit;
}
if (empty($_POST['text']))
{
echo _("A description for your Club must be entered.");
exit;
}
$title = db_input($_POST['title']);
$text = db_input($_POST['text']);
$ag = $_POST['ag'];
$time = time();
$query = "INSERT INTO groups (group_id, title, text, creator, time, ag) VALUES (NULL, '$title', '$text', '".$me['playerID']."', '$time', '$ag')";
if (mysql_query($query))
{
$gid = mysql_insert_id();
$query = "INSERT INTO group_members VALUES ('".$me['playerID']."', '$gid', '$time')";
if (mysql_query($query))
{
echo _("Your Club has been created successfully!");
}
else
{
echo mysql_error()."<br />".$query;
}
}
else
{
echo mysql_error()."<br />".$query;
}
break; // case create
case 'list':
?>
<table width='98%' class='TABLE' align='center'>
<tr>
<th align='center'><strong><?= _("Club") ?></strong></th>
<th align='center'><strong><?= _("Club President") ?></strong></th>
<th align='center'><strong><?= _("Members") ?></strong></th>
</tr>
<?php
$g1 = mysql_query("SELECT g.*, p.nick FROM groups g
LEFT JOIN players p on p.playerID = g.creator");
echo mysql_error();
while($g = mysql_fetch_array($g1))
{
$c = getcount("group_members", "WHERE group_id = '".$g['group_id']."' AND joined > 0");
$title = db_output($g['title']);
$text = db_output($g['text']);
echo "<tr>";
echo "<td class='TD' align=center>";
echo '<a href="groups.php?action=view&id='.$g['group_id'].'"><strong>'.$title.'</strong></a><br />'.$text.'</td>';
echo "<td class='TD' align=center>";
echo '<a href="stats_user.php?cod='.$g['creator'].'">'.$g['nick'].'</a>';
echo "<td class='TD' align=center>";
echo ''.$c.'</td>';
echo '</tr>';
}
echo '</table>';
break; // case list
case 'view':
$g1 = mysql_query("SELECT g.*, p.nick FROM groups g
LEFT JOIN players p on p.playerID = g.creator
WHERE g.group_id = '$id'");
echo mysql_error();
$g = mysql_fetch_array($g1);
$c = getcount("group_members", "WHERE group_id = '$id' AND joined > 0");
$title = db_output($g['title']);
$text = db_output($g['text']);
?>
<center><font size="+1">
<table width='98%' class='TABLE' align='center'>
<tr>
<th colspan="2" class='THTOP'><?= sprintf(_("Welcome to the $s clubs page!."), $title);?></th>
</tr>
<tr rowspan='3'>
<td align="center" class='TD'><?=show_avatar_club($row[group_id]);?></td>
<td align="center" class='TD'>
<table width="100%" class='STATUSTABLE'>
<tr>
<td align="center"><strong><?= sprintf(_("This Club currently has %d members."), $c);?></strong><br />
<hr>
</td>
</tr>
<tr>
<td>
<table width="100%" class='STATUSTABLE'>
<tr>
<td align='center'><?= _("Club President") ?>:<a
href="quick_stats.php?cod=<?= $g['creator']?>"><?= $g['nick']?></a><br />
<br />
<hr />
</td>
</tr>
</table>
<?= $text?></td>
</tr>
</table>
<br />
<table width='98%' class='TABLE' align='center'>
<tr>
<th align='center' colspan='5' class='THTOP'><?= _("Club Members") ?></th>
</tr>
<tr>
<th align='center'><strong><?= _("Name") ?></strong></th>
<th align='center'><strong><?= _("Send PM") ?></strong></th>
<th align='center'><strong><?= _("Rating") ?></strong></th>
<th align='center'><strong><?= _("Date Joined") ?></strong></th>
<th align='center'><strong><?= _("Action") ?></strong></th>
</tr>
<?php
$p1 = mysql_query("SELECT p.*, g.joined FROM players p
LEFT JOIN group_members g
ON g.playerID = p.playerID
WHERE g.group_id = '$id'
AND g.joined > 0
ORDER BY g.joined ASC");
echo mysql_error();
while($p = mysql_fetch_array($p1)) {
echo "<tr><td class='TD' align='center'>";
echo '<a href="stats_user.php?cod='.$p['playerID'].'">'.$p['nick'].'</a></td>';
echo "<td class='TD' align='center'>";
$msg = mysql_query("SELECT * FROM players WHERE playerID='".$p['playerID']."'");
$sendmsg = mysql_fetch_array($msg);
$msgid = $sendmsg['playerID'];
if (can_chat($_SESSION['playerID'],$p['playerID'])){
echo '<a href=javascript:MessagePlayer('.$p['playerID'].')>Message</a>';
}
else {
echo _("Ignore Feature Enabled");
}
echo "</td><td class='TD' align='center'>";
echo ''.$p['rating'].'</td>';
echo "<td class='TD' align='center'>";
echo ''.date("d.m.y", $p['joined']).'</td>';
echo "<td class='TD' align='center'>";
if (is_groupcreator($id, $me['playerID']) && $p['playerID'] != $me['playerID'])
{
echo '<a href="groups.php?action=kick&id='.$p['playerID'].'&group='.$id.'">' . _("Delete from Club") . '</a>';
$c = getcount("groups", "WHERE creator = '".$me['playerID']."' AND group_id != '$id'");
}
else
{
echo ' ';
}
echo '</td></tr>';
}
echo '</table>';
echo '<br />';
if (is_groupcreator($id, $me['playerID']))
{
?>
</form>
</font>
<br />
<br />
<center><strong><?= _("You are the President of this Club.") ?></strong></center>
<?php
$w = getcount("group_members", "WHERE group_id = '$id' AND joined = 0");
if ($w > 0)
{
?>
<br />
<br />
<table width='98%' class='TABLE' align='center'>
<tr>
<th align='center' class='THTOP' colspan='3'><?= sprintf(_("There are %d pending members wishing to join your Club."), $w) ?></th>
</tr>
<tr>
<th align='center'><strong><?= _("Name") ?></strong></th>
<th align='center'><strong><?= _("Rating") ?></strong></th>
<th align='center'><strong><?= _("Options") ?></strong></th>
</tr>
<?php
$s1 = mysql_query("SELECT p.* FROM players p
LEFT JOIN group_members g
ON g.playerID = p.playerID
WHERE g.group_id = '$id'
AND joined = 0");
echo mysql_error();
while ($s = mysql_fetch_array($s1))
{
echo "<tr>";
echo "<td class='TD' align=center>";
echo '<a href="stats_user.php?cod='.$s['playerID'].'">'.$s['nick'].'</a></td>';
echo "<td class='TD' align=center>";
echo ''.$s['rating'].'</td>';
echo "<td class='TD' align=center>";
echo '<a href="groups.php?action=response&id='.$s['playerID'].'&group='.$id.'&feedback=1">'._("accept").'</a> | ';
echo '<a href="groups.php?action=kick&id='.$s['playerID'].'&group='.$id.'&feedback=0">'._("reject").'</a></td></tr>';
}
echo "</table>";
}
}
else {
$h = get_group($me['playerID']);
echo _("If you not already a member of this Club,<br />Click the link below if you wish to Join.<br /><br />");
echo '<a href="groups.php?action=join&id='.$id.'"><strong>' . _("Click here to join this Club.") . '<br /><br /></strong></a>';
if ($id == $h[0]['group_id'])
{
echo _("If you see your name in the Members Roster above,<br /> you are a full member of this Club. If you do not see your name there,<br /> you are a Pending Member, and still must be approved to join.") . '<br /><br />';
echo '<a href="groups.php?action=leave&id='.$id.'">' . _("Click here to leave this Club.") . '</a>';
}
/*else
{
echo 'You are already on a team or applying for membership; Sorry, but you can join only one team at a time.';
}*/
} //creator
break; // case view
case 'join':
$h = get_group($me['playerID']);
/*if ($h != false)
{
echo 'You are already in the Club '.$h['title'].' and cannot join more than one Club at a time.';
exit;
}*/
if (mysql_query("INSERT INTO group_members VALUES ('".$me['playerID']."', '$id', 0)"))
{
// Mail an den Gruppenleiter
$g = get_groupdata($id);
$tq = mysql_query("SELECT nick FROM players WHERE playerID = '".$g['creator']."'");
$toer = mysql_fetch_array($tq);
/*$tomail = $toer['user_email'];
$toname = $g['nick'];
$totitle = 'Application to Join Club';
$text = 'Hello '.$toname.',
You are receiving this email because '.$me['nick'].' would like to join your Club, \''.$g['title'].'\'.
Please go to the Clubs link at The Chess Knights to either accept or reject this member application.';
$header = 'From: ' . $CFG_MAILADDRESS . "\nReturn-Path: " . $CFG_MAILADDRESS . "\n";
mail($tomail, $totitle, $text,$header);
echo "Your request to join was sent to the Club President.<br /> You will be informed of his decision via E-Mail or Private Message.";
}
else { echo mysql_error();*/ }
break; // case join
case 'response':
$group = $_GET['group'];
$feedback = $_GET['feedback'];
$time = time();
if (empty($id))
{
echo _("No player selected.") . ' G544';
exit;
}
if (empty($group))
{
echo _("No Club selected.") . ' G550';
exit;
}
if (empty($feedback))
{
echo _("No reply selected.") . ' G556';
exit;
}
if (!is_groupcreator($group, $me['playerID']))
{
echo _("You are not the leader of this Club.") . ' G562';
exit;
}
// Mail an den Gruppenleiter
$g = get_groupdata($group);
$tq = mysql_query("SELECT nick FROM players WHERE playerID = '$id'");
$toer = mysql_fetch_array($tq);
/*$tomail = $toer['user_email'];
$toname = $toer['nick'];
$totitle = 'Application to Join Club';*/
if ($feedback == 1)
{
$query = "UPDATE group_members SET joined = '$time' WHERE group_id = '$group' AND playerID = '$id'";
$text = sprintf(_("Hello %s\n, your application to join the Club %s has been approved"), $toname, $g['title']);
}
else
{
$query = "DELETE FROM group_members WHERE group_id = '$group' AND playerID = '$id'";
$text = sprintf(_("Hello %s,\nyour application to join the Club %s has not been approved. You now have the option to join another Club or to Create you own."), $toname, $g['title']);
}
if (mysql_query($query))
{
$totitle = _("Your response to applicant");
$header = 'From: ' . $CFG_MAILADDRESS . "\nReturn-Path: " . $CFG_MAILADDRESS . "\n";
mail($tomail, $totitle, $text,$header);
echo " <font color=$textcolor1>" . sprintf(_("Please send applicant %s a Private Message regarding your decision."), $toname) . "</font>";
}
else { echo mysql_error(); }
break; // case repsonse
case 'leave':
$g = $_GET['id'];
if (empty($g))
{
echo _("error");
exit;
}
mysql_query("DELETE FROM group_members WHERE playerID = '".$me['playerID']."' AND group_id = '$g'");
echo _("You have successfully left this Club.");
break; // case leave
case 'kick':
$g = $_GET['group'];
if (!is_groupcreator($g, $me['playerID']))
{
echo _("Error: Off Limits G628");
exit;
}
if (empty($g))
{
echo _("Error: Group missing G634");
exit;
}
if (empty($id))
{
echo _("Error: ID missing G640");
exit;
}
mysql_query("DELETE FROM group_members WHERE playerID = '$id' AND group_id = '$g'");
echo mysql_error();
echo _("Player has been successfully deleted.");
break; // case kick
case 'move':
$g = $_GET['group'];
$to = $_GET['to'];
if (!is_groupcreator($g, $me['playerID']))
{
echo "Player has been successfully deleted.";
exit;
}
if (empty($g))
{
echo "Error.";
exit;
}
if (empty($id))
{
echo "Error.";
exit;
}
$usersd = mysql_query("SELECT * FROM players WHERE playerID='$id'");
$he = mysql_fetch_array($usersd);
?>
<table width='98%' class='TABLE' align='center'>
<tr>
<th>Move Member to Another Club</th>
</tr>
<tr>
<td class='TD' align='center'><?php
if (empty($to)) {
?> <?= _("Move Member")?>: <strong><?=$he['nick']?></strong> <br />
<br />
<form action="move_clubuser.php" method="get"><input
type="hidden" name="action" value="move" /><input type="hidden"
name="id" value="<?=$id?>" /><input type="hidden" name="group"
value="<?=$g?>" /> Choose Club: <select name="to">
<?php
$q1 = mysql_query("SELECT * FROM groups WHERE creator = '".$me['playerID']."'");
while ($q = mysql_fetch_array($q1))
{
echo '<option value="'.$q['group_id'].'">'.$q['title'].'</option>';
}
}
else
{
mysql_query("UPDATE group_members SET group_id = '$to' WHERE group_id = '$g' AND playerID = '$id'");
echo _("moveuser3");
}
?>
</select> <br />
<br />
<?php if (empty($to)) { ?><input type="submit" /><?php } ?></form>
</td>
</tr>
</table>
<?php
break; // case move
} // case
?>
<form name="logout" action="mainmenu.php" method="post"><input
type="hidden" name="ToDo" value="Logout" /></form>
</font>
<br />
</td>
</tr>
</table>
</td>
<?php
include "./themes/".$_SESSION["pref_colortheme"]."/footer.php";?>
</body>
</html>