From c009ef1e3a2876d6172a1e8a6713598dce8e0c67 Mon Sep 17 00:00:00 2001 From: jacob Date: Mon, 27 Sep 2010 16:14:09 +0000 Subject: [PATCH] Added user_school.php, a form tab for user to select the school to which they belong. Updated user_edit.php to use it. --- user_edit.php | 9 +++- user_school.php | 140 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 148 insertions(+), 1 deletion(-) create mode 100644 user_school.php diff --git a/user_edit.php b/user_edit.php index 149f7cd..68f9a73 100644 --- a/user_edit.php +++ b/user_edit.php @@ -107,6 +107,13 @@ $tabs = array( 'fairinfo' => array( 'file' => 'user_roles.php', 'status_func' => false, ), + 'school' => array( + 'label' => 'School', + 'name' => 'Select School Information', + 'types' => array('teacher','student','principal','parent'), + 'file' => 'user_school.php', + 'status_func' => false + ) ); $u = user_load($edit_id); @@ -188,7 +195,7 @@ foreach($tabs as $k=>$t) { /* Get the status */ if(is_callable($t['status_func'])) { - $s = call_user_func($t['status_func'], $u); + $s = call_user_func($t['status_func'], &$u); $tabs[$k]['status'] = ($s == 'complete') ? 'complete' : 'incomplete'; } else { $tabs[$k]['status'] = 'incomplete'; diff --git a/user_school.php b/user_school.php new file mode 100644 index 0000000..17877a6 --- /dev/null +++ b/user_school.php @@ -0,0 +1,140 @@ + + Copyright (C) 2005 James Grant + Copyright (C) 2007 David Grant + + 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'); + +/* Ensure they're logged in as something, anything */ +user_auth_required(); + +$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']); + $query = "SELECT * FROM schools WHERE id = $school AND accesscode = '$code'"; + $data = mysql_fetch_assoc(mysql_query($query)); + if(is_array($data)){ + $query = "UPDATE users SET schools_id = $school WHERE id = $edit_id"; + if(mysql_query($query)){ + // we successfully updated the school for this user. Now send the info back to papulate the page + $schoolData = mysql_fetch_assoc(mysql_query("SELECT school, address, city, province_code, postalcode, phone FROM schools WHERE id='$school'")); + echo "schoolInfo = '" . implode("
", $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.") +); + +?> + +" . i18n("School Information") . ""; +$currentSchool = $u['schools_id']; +if($currentSchool != null){ + echo i18n("You are currently listed as a member of") . "
"; + echo '
'; + $schoolData = mysql_fetch_assoc(mysql_query("SELECT school, address, city, province_code, postalcode, phone FROM schools WHERE id='$currentSchool'")); + echo implode('
', $schoolData); + echo '
'; + echo '

' . $translations['if_incorrect'] . "

"; +}else{ + echo '
'; + echo '

' . $translations['not_associated'] . "

"; +} + +// draw the form elements for changing the school +echo "
"; +echo "" . i18n("School") . ": "; +echo ""; + +// build a select box for them to pick out a school +echo '"; +echo "
"; + +// and the rest of the form... +echo "" . i18n("Access Code") . ": "; +echo ""; +echo '
'; +echo "
"; +echo ''; +echo "
";