forked from science-ation/science-ation
135 lines
4.6 KiB
PHP
135 lines
4.6 KiB
PHP
<?
|
|
/*
|
|
This file is part of the 'Science Fair In A Box' project
|
|
SFIAB Website: http://www.sfiab.ca
|
|
|
|
Copyright (C) 2005 Sci-Tech Ontario Inc <info@scitechontario.org>
|
|
Copyright (C) 2005 James Grant <james@lightbox.org>
|
|
Copyright (C) 2007 David Grant <dave@lightbox.org>
|
|
|
|
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, version 2.
|
|
|
|
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; see the file COPYING. If not, write to
|
|
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
Boston, MA 02111-1307, USA.
|
|
*/
|
|
|
|
require_once('common.inc.php');
|
|
require_once('user.inc.php');
|
|
|
|
$edit_id = isset($_GET['users_id']) ? intval($_GET['users_id']) : $_SESSION['users_id'];
|
|
|
|
if($edit_id != $_SESSION['users_id'])
|
|
user_auth_required('admin');
|
|
else
|
|
user_auth_required();
|
|
|
|
$u = user_load($edit_id);
|
|
|
|
if(array_key_exists('action', $_POST)){
|
|
switch($_POST['action']){
|
|
case 'submit_code':
|
|
$code = mysql_real_escape_string($_POST['code']);
|
|
$school = mysql_real_escape_string($_POST['school']);
|
|
if(user_set_school($u, $school, $code)){
|
|
$schoolData = mysql_fetch_assoc(mysql_query("SELECT school, address, city, province_code, postalcode, phone FROM schools WHERE id='$school'"));
|
|
echo "schoolInfo = '" . implode("<br/>", $schoolData) . "';";
|
|
}
|
|
break;
|
|
default:
|
|
// invalid action
|
|
break;
|
|
}
|
|
exit;
|
|
}
|
|
|
|
$translations = array(
|
|
'if_incorrect' => i18n("If this is incorrect, please select the correct school and enter its access code in the fields below."),
|
|
'incorrect' => i18n("That does not appear to be the correct access code. Please select the school and enter its access code in the fields below."),
|
|
'not_associated' => i18n("You are not currently associated with any school. Please select the school and enter its access code in the fields below.")
|
|
);
|
|
|
|
?>
|
|
<script type="text/javascript">
|
|
function submitSchoolCode(){
|
|
$.post('user_school.php',
|
|
{
|
|
'action' : 'submit_code',
|
|
'code' : $('#accessCode').val(),
|
|
'school' : $('#schoolId').val(),
|
|
'uid' : <?=$edit_id;?>
|
|
},
|
|
function(response){
|
|
var schoolInfo = null;
|
|
eval(response);
|
|
if(schoolInfo != null){
|
|
$('#infobox').html(schoolInfo);
|
|
$('#infobox').css({'border':'solid', 'border-width':'1px'});
|
|
$('#instructions').html("<?=$translations['if_incorrect'];?>");
|
|
}else{
|
|
$('#instructions').html("<?=$translations['incorrect'];?>");
|
|
}
|
|
|
|
}
|
|
);
|
|
}
|
|
</script>
|
|
<?php
|
|
|
|
// draw the info area
|
|
echo "<h4>" . i18n("School Information") . "</h4>";
|
|
$currentSchool = $u['schools_id'];
|
|
if($currentSchool){
|
|
$q=mysql_query("SELECT * FROM schools WHERE id='$currentSchool' AND conferences_id='{$conference['id']}'");
|
|
if(!mysql_num_rows($q)) {
|
|
echo "Your current school selection is invalid. Please select your school";
|
|
$currentSchool=null;
|
|
}
|
|
}
|
|
if($currentSchool){
|
|
echo i18n("You are currently listed as a member of") . "<br/>";
|
|
echo '<div id="infobox" style="margin:10px;padding:5px;border:solid;border-width:1px;font-weight:bold">';
|
|
$schoolData = mysql_fetch_assoc(mysql_query("SELECT school, address, city, province_code, postalcode, phone FROM schools WHERE id='$currentSchool'"));
|
|
echo implode('<br/>', $schoolData);
|
|
echo '</div>';
|
|
echo '<p id="instructions">' . $translations['if_incorrect'] . "</p>";
|
|
}else{
|
|
echo '<div id="infobox" style="margin:10px;padding:5px;border:none;border-width:1px;font-weight:bold"></div>';
|
|
echo '<p id="instructions">' . $translations['not_associated'] . "</p>";
|
|
}
|
|
|
|
// draw the form elements for changing the school
|
|
echo "<table><tr><td>";
|
|
echo i18n("School").":";
|
|
echo "</td><td>";
|
|
|
|
// build a select box for them to pick out a school
|
|
echo '<select id="schoolId">';
|
|
echo "<option value=\"\">".i18n("Choose a school")."</option>\n";
|
|
$schoolList = get_schools($conference['id']);
|
|
foreach($schoolList as $id => $school){
|
|
if($school == $schoolData['school']){
|
|
$sel= "selected=\"selected\"";
|
|
}else{
|
|
$sel= "";
|
|
}
|
|
echo "<option $sel value=\"$id\">$school</option>";
|
|
}
|
|
echo "</select>";
|
|
echo "</td></tr>";
|
|
echo "<tr><td>";
|
|
echo i18n("Access Code") . ":";
|
|
echo "</td><td>";
|
|
echo '<input type="text" id="accessCode"></input><br/>';
|
|
echo "</td></tr><tr><td colspan = 2>";
|
|
echo '<button onClick = "submitSchoolCode()">' . i18n("Submit") . '</button>';
|
|
echo "</td></tr></table>";
|