2010-06-14 18:30:39 +00:00
|
|
|
<?php
|
|
|
|
require_once('common.inc.php');
|
|
|
|
require_once('user.inc.php');
|
2010-06-15 16:57:50 +00:00
|
|
|
if($_SESSION['schoolid'] && $_SESSION['schoolaccesscode'] && $conference['type'] == 'scienceolympics'){
|
2010-06-14 18:30:39 +00:00
|
|
|
switch($_GET['action']){
|
|
|
|
case 'saveNew':
|
|
|
|
$teamName = mysql_real_escape_string($_POST['teamname']);
|
2010-06-16 17:45:13 +00:00
|
|
|
$query = 'INSERT INTO so_teams (schools_id, conferences_id, name) VALUES (' . $_SESSION['schoolid'] . ', ' . $conference['id'] . ', "' . $teamName . '")';
|
2010-06-14 18:30:39 +00:00
|
|
|
$success = mysql_query($query);
|
|
|
|
draw_page();
|
|
|
|
break;
|
|
|
|
case 'save':
|
|
|
|
$success = false;
|
|
|
|
$teamId = mysql_real_escape_string($_POST['teamId']);
|
|
|
|
$teamName = mysql_real_escape_string($_POST['teamname']);
|
|
|
|
// a quick check to make sure the team being updated does indeed belong
|
|
|
|
// to this school
|
|
|
|
$query = 'SELECT COUNT(*) AS tally FROM so_teams WHERE schools_id=' . $_SESSION['schoolid'] . ' AND id=' . $teamId;
|
|
|
|
$testResults = mysql_fetch_array(mysql_query($query));
|
|
|
|
if($testResults['tally'] == 1){
|
|
|
|
// ok, the team belongs to the school that this session belongs to. We can
|
|
|
|
// can go ahead and save the changes.
|
|
|
|
$query = 'UPDATE so_teams SET name="' . $teamName . '" ';
|
|
|
|
$query .= 'WHERE schools_id=' . $_SESSION['schoolid'] . ' ';
|
|
|
|
$query .= 'AND id=' . $teamId;
|
|
|
|
$success = mysql_query($query);
|
|
|
|
}
|
|
|
|
if($success){
|
2010-06-15 16:57:50 +00:00
|
|
|
happy_("Team successfully updated");
|
2010-06-14 18:30:39 +00:00
|
|
|
echo("<script type=\"text/javascript\">newname = '$teamName';</script>");
|
|
|
|
}else{
|
2010-06-15 16:57:50 +00:00
|
|
|
error_("Unable to update record");
|
2010-06-14 18:30:39 +00:00
|
|
|
echo("<script type=\"text/javascript\">newname = null;</script>");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'delete':
|
|
|
|
$success = false;
|
|
|
|
$teamId = mysql_real_escape_string($_POST['teamId']);
|
|
|
|
$teamName = mysql_real_escape_string($_POST['teamname']);
|
|
|
|
// a quick check to make sure the team being updated does indeed belong
|
|
|
|
// to this school
|
|
|
|
$query = 'SELECT COUNT(*) AS tally FROM so_teams WHERE schools_id=' . $_SESSION['schoolid'] . ' AND id=' . $teamId;
|
|
|
|
$testResults = mysql_fetch_array(mysql_query($query));
|
|
|
|
if($testResults['tally'] == 1){
|
|
|
|
// ok, the team belongs to the school that this session belongs to. We can
|
|
|
|
// can go ahead and save the changes.
|
|
|
|
$query = 'DELETE FROM so_teams ';
|
|
|
|
$query .= 'WHERE schools_id=' . $_SESSION['schoolid'] . ' ';
|
|
|
|
$query .= 'AND id=' . $teamId;
|
|
|
|
if(mysql_query($query)){
|
|
|
|
$success = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if($success){
|
2010-06-15 16:57:50 +00:00
|
|
|
happy_("Team successfully deleted");
|
2010-06-14 18:30:39 +00:00
|
|
|
echo("<script type=\"text/javascript\">deleteId = '$teamId';</script>");
|
|
|
|
}else{
|
2010-06-15 16:57:50 +00:00
|
|
|
error_("Unable to delete record");
|
2010-06-14 18:30:39 +00:00
|
|
|
echo("<script type=\"text/javascript\">deleteId = null;</script>");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
draw_page();
|
|
|
|
}
|
|
|
|
}else{
|
2010-06-15 16:57:50 +00:00
|
|
|
header('Location: schoolaccess.php');
|
2010-06-14 18:30:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function draw_page(){
|
2010-06-16 15:16:25 +00:00
|
|
|
global $conference;
|
2010-06-14 18:30:39 +00:00
|
|
|
$title = i18n("Manage Teams");
|
2010-06-16 17:50:12 +00:00
|
|
|
send_header($title, array("School Home" => "schoolaccess.php"));
|
2010-06-14 18:30:39 +00:00
|
|
|
?>
|
|
|
|
<script type="text/javascript">
|
|
|
|
$(document).ready(function() {
|
|
|
|
$('#teamaccordion').accordion();
|
|
|
|
$('#teamaccordion').css('visibility', 'visible');
|
|
|
|
});
|
|
|
|
|
|
|
|
function delete_team(teamId){
|
|
|
|
var data = $("#editTeam_" + teamId).serializeArray();
|
2010-06-15 18:14:01 +00:00
|
|
|
$("#debug").load("schoolteams.php?action=delete", data, function(){
|
2010-06-14 18:30:39 +00:00
|
|
|
$('#teamHeader_' + teamId).remove();
|
|
|
|
$('#team_' + teamId).remove();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function saveData(teamId){
|
|
|
|
var data = $("#editTeam_" + teamId).serializeArray();
|
|
|
|
|
2010-06-16 15:16:25 +00:00
|
|
|
$("#debug").load("schoolteams.php?action=save", data, function(){
|
2010-06-14 18:30:39 +00:00
|
|
|
if(newname != undefined){
|
|
|
|
newname = '<span class="ui-icon ui-icon-triangle-1-e"></span><a href="#" tabindex="-1">' + newname + '</a>';
|
|
|
|
$('#teamHeader_' + teamId).html(newname);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
<?php
|
|
|
|
echo '<div id="teamaccordion" style="width:40em; visibility:hidden;">';
|
2010-06-16 15:16:25 +00:00
|
|
|
$teamList = mysql_query("SELECT * FROM so_teams WHERE schools_id = " . $_SESSION['schoolid'] . " AND conferences_id = " . $conference['id']);
|
|
|
|
while($teamList && $team = mysql_fetch_array($teamList)){
|
2010-06-14 18:30:39 +00:00
|
|
|
echo '<h3 id="teamHeader_' . $team['id'] . '"><a href="#">' . $team['name'] . "</a></h3>\n";
|
|
|
|
echo '<div id="team_' . $team['id'] . '">' . "\n";
|
|
|
|
echo '<form id="editTeam_' . $team['id'] . '" onsubmit="return false;">';
|
|
|
|
echo i18n('name') . ': <input type="text" name="teamname" value="' . $team['name'] . '"></input>';
|
|
|
|
echo '<div style="height:1em;"></div>';
|
|
|
|
echo "<button onclick=\"saveData('" . $team['id'] . "');\">" . i18n('Save') . '</button>';
|
2010-06-23 15:52:27 +00:00
|
|
|
$record = mysql_fetch_array(mysql_query("SELECT count(*) AS regCount FROM schedule_registrations WHERE so_teams_id = " . $team['id']));
|
|
|
|
if($record['regCount'] == 0){
|
|
|
|
echo "<button onclick=\"delete_team('" . $team['id'] . "');\">" . i18n('Delete') . '</button>';
|
|
|
|
}else{
|
|
|
|
echo '<div style="font-size: 80%">';
|
|
|
|
echo '<a href="schoolschedule.php" style="color:#666">';
|
|
|
|
if($record['regCount'] > 1){
|
|
|
|
echo i18n("This team is currently registered for %1 events and can not be deleted.", array($record['regCount']));
|
|
|
|
}else{
|
|
|
|
echo i18n("This team is currently registered for an event and can not be deleted.");
|
|
|
|
}
|
|
|
|
echo '</a></div>';
|
|
|
|
}
|
2010-06-14 18:30:39 +00:00
|
|
|
echo "<input type=\"hidden\" name=\"teamId\" value=\"" . $team['id'] . "\"></input>";
|
|
|
|
echo '</form>';
|
|
|
|
echo "</div>";
|
|
|
|
}
|
|
|
|
echo '<h3><a href="#">' . i18n("New Team") . '</a></h3>';
|
|
|
|
echo '<div id="newTeam">';
|
2010-06-15 18:14:01 +00:00
|
|
|
echo '<form method="POST" action="schoolteams.php?action=saveNew">';
|
2010-06-14 18:30:39 +00:00
|
|
|
echo '<label>' . i18n('Name') . '</label><input type="text" style="width:100%" name="teamname"></input>' . "\n";
|
|
|
|
echo '<div style="height:1em;"></div>';
|
|
|
|
echo '<input type="submit" value="' . i18n("Save") . '"></input>';
|
|
|
|
echo '</form>';
|
|
|
|
echo "</div>\n";
|
|
|
|
echo '</div>';
|
|
|
|
send_footer();
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|