*** empty log message ***

svn path=/trunk/boinc/; revision=4618
This commit is contained in:
David Anderson 2004-11-21 18:56:30 +00:00
parent c448b0d443
commit 43a21e6efd
15 changed files with 111 additions and 166 deletions

View File

@ -19947,3 +19947,16 @@ David 20 Nov 2004
cs_prefs.C
win/
wingui_mainwindow.cpp
David 21 Nov 2004
- Change team-related PHP code so that it recomputes
"nusers" by doing a select count(*) when a user
quits or joins a team.
Also cleaned up skanky PHP code.
html/
inc/
team.inc
util.inc
user/
team*.php

View File

@ -114,22 +114,17 @@ function display_team_page($team, $offset, $sort_by) {
// requires that the team exist
function require_team($team) {
if (!$team) {
page_head("Error");
echo "Team does not exist.";
page_tail();
exit();
error_page("No such team.");
}
}
// requires that the user is logged in as the founder of
// the team trying to be edited
//
function require_founder_login($user, $team) {
require_team($team);
if ($user->id != $team->userid) {
page_head("Permission denied");
echo "Only a team's founder may edit a team.";
page_tail();
exit();
error_page("Only a team's founder may edit a team.");
}
}
@ -170,39 +165,15 @@ function show_team_row($team, $i) {
}
function user_join_team($team, $user) {
if ($user->teamid != 0) {
$query_team_other = sprintf(
"select * from team where id = %d",
$user->teamid
);
$result_team_other = mysql_query($query_team_other);
$first_team = mysql_fetch_object($result_team_other);
$first_nusers = $first_team->nusers;
$first_new_nusers = $first_nusers - 1;
if ($first_new_nusers > 0) {
$query_team_table_other = sprintf(
"update team set nusers = %d where id = %d",
$first_new_nusers,
$first_team->id
);
} else {
// no more users in this team: disband it.
$query_team_table_other = sprintf(
"delete from team where id = %d",
$first_team->id
);
}
$result_team_table_other = mysql_query($query_team_table_other);
$old_teamid = $user->teamid;
$res = mysql_query("update user set teamid=$team->id where id=$user->id");
if ($old_teamid != 0) {
$old_team = lookup_team($old_teamid);
team_update_nusers($old_team);
}
$query_user_table = sprintf(
"update user set teamid = %d where id = %d",
$team->id,
$user->id
);
$result_user_table = mysql_query($query_user_table);
$result_team_table = mysql_query("update team set nusers=nusers+1 where id = $team->id");
if ($result_user_table && $result_team_table) return true;
else return false;
team_update_nusers($team);
if ($res) return true;
return false;
}
function team_edit_form($team, $label, $url) {
@ -295,4 +266,17 @@ function team_inactive_ndays($team, $ndays) {
return false;
}
function team_update_nusers($team) {
$res = mysql_query("select count(*) as total from user where teamid=$team->id");
$comp = mysql_fetch_object($res);
if (!$comp) return;
$n = $comp->total;
if ($n > 0) {
mysql_query("update team set nusers=$n where id=$team->id");
} else {
echo "<br>Team is empty - deleting team.\n";
mysql_query("delete from team where id=$team->id");
}
}
?>

View File

@ -155,6 +155,13 @@ function profile_error_page($str) {
page_tail();
}
function error_page($msg) {
page_head("Unable to handle request");
echo $msg;
page_tail();
exit();
}
function date_str($x) {
if ($x == 0) return "---";
// return date("g:i A, l M j", $when);

View File

@ -32,7 +32,7 @@
$team_result = mysql_query("select * from team where id = $teamid");
$new_team = mysql_fetch_object($team_result);
mysql_free_result($team_result);
user_join_team($new_team,$user);
user_join_team($new_team, $user);
Header("Location: team_display.php?teamid=$teamid");
} else {
page_head("Error");

View File

@ -8,12 +8,7 @@
$user = get_logged_in_user();
$teamid = $_POST["teamid"];
$query = "select * from team where id = $teamid";
$result = mysql_query($query);
if ($result) {
$team = mysql_fetch_object($result);
mysql_free_result($result);
}
$team = lookup_team($teamid);
require_founder_login($user, $team);
$team_url = ereg_replace("\"", "'", $_POST["url"]);

View File

@ -8,14 +8,9 @@ require_once("../inc/team.inc");
$user = get_logged_in_user();
$teamid = $_GET["teamid"];
$query = "select * from team where id = $teamid";
$result = mysql_query($query);
if ($result) {
$team = mysql_fetch_object($result);
mysql_free_result($result);
}
$team = lookup_team($teamid);
require_founder_login($user, $team);
$team_name = ereg_replace("\"", "'", $team->name);
$team_name_html = ereg_replace("\"", "'", $team->name_html);
$team_url = ereg_replace("\"", "'", $team->url);

View File

@ -9,13 +9,7 @@ require_once("../inc/team.inc");
$user = get_logged_in_user();
$teamid = $_GET["teamid"];
$result = mysql_query("select * from team where id=$teamid");
if ($result) {
$team = mysql_fetch_object($result);
mysql_free_result($result);
}
$team = lookup_team($teamid);
require_founder_login($user, $team);
page_head("$team->name Email List");

View File

@ -14,18 +14,17 @@
page_head("Unable to add $user->name");
echo "You are already a member of $team->name.";
} else {
$success = user_join_team($team,$user);
$success = user_join_team($team, $user);
if ($success == true) {
page_head("Joined $team->name");
echo "You have joined
<a href=team_display.php?teamid=$team->id>$team->name</a>.
";
} else {
page_head("Error");
echo "Couldn't join team - please try later.\n";
error_page("Couldn't join team - please try later.");
}
}
page_tail();
page_tail();
?>

View File

@ -4,18 +4,12 @@ require_once("../inc/db.inc");
require_once("../inc/util.inc");
require_once("../inc/team.inc");
db_init();
$user = get_logged_in_user();
$id = $_GET["id"];
db_init();
$user = get_logged_in_user();
$teamid = $_GET["id"];
$query = "select * from team where id = $id";
$result = mysql_query($query);
if ($result) {
$team = mysql_fetch_object($result);
mysql_free_result($result);
}
$team = lookup_team($teamid);
$team_name = $team->name;
$team_id = $team->id;
page_head("Join $team_name");
echo " <p><b>Please note:</b>
<ul>
@ -24,7 +18,7 @@ $id = $_GET["id"];
</ul>
<hr>
<form method=post action=team_join_action.php>
<input type=hidden name=teamid value=$team_id>
<input type=hidden name=teamid value=$teamid>
<input type=submit value='Join team'>
</form>
";

View File

@ -32,9 +32,10 @@
}
echo "</ul>";
if ($too_many) {
echo "This is only a partial list of the possible teams you ";
echo "were searching for. You will need to narrow your search ";
echo "criteria to get more accurate results.<br>";
echo "
More than 100 teams match your search.
The first 100 are shown.<br>
";
}
}
echo "End of results<br>";

View File

@ -20,11 +20,11 @@ if ($team->userid != $user->id) {
}
echo "
<ul>
<li><a href=team_edit_form.php?teamid=$team->id>Edit team info</a>
<li><a href=team_remove_inactive_form.php?teamid=$team->id>Remove inactive members</a>
<li><a href=team_email_list.php?teamid=$team->id>View team email addresses</a>
</ul>
<ul>
<li><a href=team_edit_form.php?teamid=$team->id>Edit team info</a>
<li><a href=team_remove_inactive_form.php?teamid=$team->id>Remove inactive members</a>
<li><a href=team_email_list.php?teamid=$team->id>View team email addresses</a>
</ul>
";
page_tail();

View File

@ -6,25 +6,15 @@
db_init();
$user = get_logged_in_user();
$teamid = $_POST["id"];
$team = lookup_team($teamid);
if ($user->teamid == $team->id) {
$query_user_table = "update user set teamid = 0 where id = $user->id";
$result_user_table = mysql_query($query_user_table);
$query_team_table = "update team set nusers=nusers-1 where id=$team->id";
$result_team_table = mysql_query($query_team_table);
if ($result_user_table && $result_team_table) {
$team_name = $team->name;
page_head("Quit $team_name");
echo "<h2>Removed from team</h2>";
echo "You have been removed from <a href=team_display.php?teamid=$team->id>$team_name</a>";
} else {
page_head("Error");
echo "Couldn't quit team - please try later.\n";
}
mysql_query("update user set teamid=0 where id=$user->id");
team_update_nusers($team);
page_head("Quit $team->name");
echo "You have been removed from <a href=team_display.php?teamid=$team->id>$team->name</a>";
} else {
page_head("Unable to remove $user->name");
echo "$user->name is not a member of $team_name.\n";
page_head("Unable to quit team");
echo "Team doesn't exist, or you don't belong to it.\n";
}
page_tail();

View File

@ -8,31 +8,28 @@ db_init();
$user = get_logged_in_user(true);
$id = $user->teamid;
$result = mysql_query("select * from team where id=$id");
if ($result) {
$team = mysql_fetch_object($result);
mysql_free_result($result);
}
$team_name = $team->name;
$team_id = $team->id;
page_head("Quit $team_name");
echo "<h2>Quit $team_name</h2>";
echo "<table width=780>";
echo "<tr><td>";
echo "<p><b>Please note before quitting a team:</b>";
echo "<ul>";
echo "<li>If you quit a team, you may rejoin later, ";
echo "or join any other team you desire ";
echo "<li>Quitting a team does not affect your personal credit ";
echo "statistics in any way.";
echo "</ul>";
echo "</p>";
echo "<hr>";
echo "<form method=post action=team_quit_action.php>";
echo "<input type=hidden name=id value=$team_id>";
echo "<input type=submit value=\"Quit Team\">";
echo "</form>";
echo "</td></tr></table>";
page_tail();
$result = mysql_query("select * from team where id=$id");
if ($result) {
$team = mysql_fetch_object($result);
mysql_free_result($result);
}
$team_name = $team->name;
$team_id = $team->id;
page_head("Quit $team_name");
echo "
<b>Please note before quitting a team:</b>
<ul>
<li>If you quit a team, you may rejoin later,
or join any other team you desire
<li>Quitting a team does not affect your personal credit
statistics in any way.
</ul>
</p>
<form method=post action=team_quit_action.php>
<input type=hidden name=id value=$team_id>
<input type=submit value=\"Quit Team\">
</form>
";
page_tail();
} ?>

View File

@ -7,48 +7,32 @@
db_init();
$user = get_logged_in_user();
$query = sprintf(
"select * from team where id = %d",
$_POST["id"]
);
$result = mysql_query($query);
if ($result) {
$team = mysql_fetch_object($result);
mysql_free_result($result);
$teamid = $_POST["id"];
$team = lookup_team($teamid);
if (!team) {
error_page("No such team");
}
require_founder_login($user, $team);
page_head("Removing users from $team->name");
$nmembers = 0;
$ndel = 0;
for ($i=0; $i<$_POST["ninactive_users"]; $i++) {
if ($_POST["remove_$i"] != 0) {
$query = sprintf(
"select * from user where id = %d",
$_POST["remove_$i"]
);
$result = mysql_query($query);
$user = mysql_fetch_object($result);
$userid = $_POST["remove_$i"];
$user = lookup_user_id($userid);
if ($user->teamid != $team->id) {
echo "<br>$user->name is not a member of $team->name";
} else {
$query_user_table = sprintf(
"update user set teamid = 0 where id = %d",
$_POST["remove_$i"]
);
$nmembers++;
$result_user_table = mysql_query($query_user_table);
$query = "update user set teamid=0 where id=$userid";
$result_user_table = mysql_query($query);
echo "<br>$user->name has been removed";
$ndel++;
}
}
}
$new_nusers = $team->nusers - $nmembers;
if ($new_nusers > 0) {
$query = "update team set nusers = $new_nusers where id = $team->id";
} else {
$query = "delete from team where id = $team->id";
echo "<p><b>The team has been disbanded because there are no more members.</b>";
if ($ndel) {
team_update_nusers($team);
}
$result = mysql_query($query);
page_tail();

View File

@ -7,22 +7,14 @@
db_init();
$user = get_logged_in_user();
$teamid = $_GET["teamid"];
$result = mysql_query("select * from team where id = $teamid");
if ($result) {
$team = mysql_fetch_object($result);
mysql_free_result($result);
}
$team = lookup_team($teamid);
require_founder_login($user, $team);
$team_name = $team->name;
$team_id = $team->id;
$nusers = $team->nusers;
page_head("Remove Members from $team_name");
page_head("Remove Members from $team->name");
echo "
<h2>Remove members from $team_name</h2>
Removing a member will subtract their credit from team totals
<form method=post action=team_remove_inactive_action.php>
<input type=hidden name=id value=$team_id>
<input type=hidden name=id value=$team->id>
";
start_table();
echo "<tr>
@ -33,7 +25,7 @@
</tr>
";
$result = mysql_query("select * from user where teamid = $team_id");
$result = mysql_query("select * from user where teamid = $team->id");
$ninactive_users = 0;
while ($user = mysql_fetch_object($result)) {