2002-08-07 18:56:55 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
require_once("util.inc");
|
|
|
|
require_once("team.inc");
|
|
|
|
require_once("db.inc");
|
|
|
|
|
2002-12-04 19:14:00 +00:00
|
|
|
$authenticator = init_session();
|
2002-08-07 18:56:55 +00:00
|
|
|
db_init();
|
|
|
|
|
2002-12-04 19:14:00 +00:00
|
|
|
$user = get_user_from_auth($authenticator);
|
2002-08-12 20:16:55 +00:00
|
|
|
if (!$user) {
|
|
|
|
print_login_form();
|
2002-08-07 18:56:55 +00:00
|
|
|
} else {
|
2002-08-12 20:16:55 +00:00
|
|
|
if (!strlen($HTTP_POST_VARS["name"])) {
|
|
|
|
page_head("Error");
|
|
|
|
echo "You must specify a name for your team.";
|
|
|
|
} else {
|
|
|
|
$query = sprintf(
|
|
|
|
"insert into team (userid, name, name_lc, url, type, name_html, description, nusers) values(%d, '%s', '%s', '%s', %d, '%s', '%s', %d)",
|
2002-08-07 18:56:55 +00:00
|
|
|
$user->id,
|
2002-08-12 20:16:55 +00:00
|
|
|
$HTTP_POST_VARS["name"],
|
|
|
|
strtolower($HTTP_POST_VARS["name"]),
|
|
|
|
$HTTP_POST_VARS["url"],
|
|
|
|
$HTTP_POST_VARS["type"],
|
|
|
|
$HTTP_POST_VARS["name_html"],
|
|
|
|
$HTTP_POST_VARS["description"],
|
|
|
|
1
|
2002-08-07 18:56:55 +00:00
|
|
|
);
|
2003-01-03 21:55:05 +00:00
|
|
|
|
|
|
|
// TODO: the following logic is very confused
|
|
|
|
|
2002-08-12 20:16:55 +00:00
|
|
|
$result = mysql_query($query);
|
|
|
|
if ($result) {
|
|
|
|
$query_team = sprintf(
|
2003-01-03 21:55:05 +00:00
|
|
|
"select * from team where name = '%s'",
|
2002-08-12 20:16:55 +00:00
|
|
|
$HTTP_POST_VARS["name"]
|
2002-08-07 18:56:55 +00:00
|
|
|
);
|
2002-08-12 20:16:55 +00:00
|
|
|
$result_team = mysql_query($query_team);
|
|
|
|
$team = mysql_fetch_object($result_team);
|
|
|
|
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;
|
|
|
|
$query_team_table_other = sprintf(
|
|
|
|
"update team set nusers = %d where id = %d",
|
|
|
|
$first_new_nusers,
|
|
|
|
$first_team->id
|
|
|
|
);
|
|
|
|
$result_team_table_other = mysql_query($query_team_table_other);
|
|
|
|
}
|
|
|
|
$query_user_table = sprintf(
|
|
|
|
"update user set teamid = %d where id = %d",
|
|
|
|
$team->id,
|
|
|
|
$user->id
|
2002-08-07 18:56:55 +00:00
|
|
|
);
|
2002-08-12 20:16:55 +00:00
|
|
|
$result_user_table = mysql_query($query_user_table);
|
|
|
|
}
|
|
|
|
if ($result && $result_user_table) {
|
|
|
|
display_team_page($team);
|
|
|
|
} else {
|
|
|
|
page_head("Error");
|
|
|
|
echo "Couldn't create team - please try later.<br>\n";
|
|
|
|
echo "You may need to try a different team name.\n";
|
2002-11-11 19:40:22 +00:00
|
|
|
page_tail();
|
2002-08-07 18:56:55 +00:00
|
|
|
}
|
|
|
|
}
|
2002-08-12 20:16:55 +00:00
|
|
|
}
|
2002-08-07 18:56:55 +00:00
|
|
|
?>
|
|
|
|
|