forked from science-ation/science-ation
418 lines
14 KiB
PHP
418 lines
14 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');
|
|
|
|
/* Ensure they're logged in as something, anything */
|
|
user_auth_required();
|
|
|
|
$user_personal_fields = array(
|
|
'salutation' => array('name' => 'Salutation'),
|
|
'firstname' => array('name' => 'First Name'),
|
|
'lastname' => array('name' => 'Last Name'),
|
|
'address' => array('name' => 'Address 1'),
|
|
'address2' => array('name' => 'Address 2'),
|
|
'city' => array('name' => 'City'),
|
|
'lang' => array('name' => 'Preferred Language'),
|
|
'province' => array('name' => $config['provincestate']),
|
|
'organization' => array('name' => 'Organization'),
|
|
'sex' => array('name' => 'Gender'),
|
|
'firstaid' => array ('name' => 'First Aid Training',
|
|
'type' => 'yesno'),
|
|
'cpr' => array ('name' => 'CPR Training',
|
|
'type' => 'yesno'),
|
|
'phonehome' => array('name' => 'Phone (Home)',
|
|
'regexp' => '^[1-9][0-9]{2}-[1-9][0-9]{2}-[0-9]{4}( x[0-9]{1,5})?$',
|
|
'format' => '\'NNN-NNN-NNNN\' or \'NNN-NNN-NNNN xEXT\'',),
|
|
'phonecell' => array('name' => 'Phone (Cell)',
|
|
'regexp' => '^[1-9][0-9]{2}-[1-9][0-9]{2}-[0-9]{4}$',
|
|
'format' => '\'NNN-NNN-NNNN\'',),
|
|
'phonework' => array('name' => 'Phone (Work)',
|
|
'regexp' => '^[1-9][0-9]{2}-[1-9][0-9]{2}-[0-9]{4}( x[0-9]{1,5})?$',
|
|
'format' => '\'NNN-NNN-NNNN\' or \'NNN-NNN-NNNN xEXT\'',),
|
|
'fax' => array('name' => 'Fax',
|
|
'regexp' => '^[1-9][0-9]{2}-[1-9][0-9]{2}-[0-9]{4}$',
|
|
'format' => '\'NNN-NNN-NNNN\'',),
|
|
'postalcode' => array('name' => $config['postalzip'],
|
|
'regexp' => '^(([A-Za-z][0-9][A-Za-z]( )?[0-9][A-Za-z][0-9])|([0-9]{5}))$',
|
|
'format' => '\'ANA NAN\' or \'ANANAN\' or \'NNNNN\'',),
|
|
|
|
);
|
|
|
|
|
|
$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);
|
|
/* Load the fields the user can edit, and theones that are required */
|
|
$fields = array();
|
|
$required = array();
|
|
$errorfields = array();
|
|
foreach(array_keys($u['roles']) as $r) {
|
|
$fields = array_merge($fields,
|
|
user_personal_fields($r));
|
|
$required = array_merge($required,
|
|
user_personal_required_fields($r));
|
|
}
|
|
/* true/false strings for form validation */
|
|
$vreq = array();
|
|
|
|
switch($_GET['action']) {
|
|
case 'save':
|
|
$users_id = intval($_POST['users_id']);
|
|
/* Only admin can pass in a different users_id */
|
|
if($users_id != $_SESSION['users_id']) {
|
|
user_auth_required('admin');
|
|
}
|
|
$u = user_load($users_id);
|
|
|
|
$save = true;
|
|
/* Set values */
|
|
foreach($fields as $f) {
|
|
$u[$f] = stripslashes($_POST[$f]);
|
|
/* Allow the user to clear a field regardless of regex */
|
|
if($u[$f] == '') continue;
|
|
|
|
/* See if this field has a validate */
|
|
if(isset($user_personal_fields[$f]['regexp'])) {
|
|
/* Match the regex */
|
|
if(!ereg($user_personal_fields[$f]['regexp'], $u[$f])) {
|
|
/* Bad */
|
|
error_("Invalid format for $f expecting ({$user_personal_fields[$f]['format']})");
|
|
$save = false;
|
|
$errorfields[] = $f;
|
|
}
|
|
}
|
|
}
|
|
|
|
if(array_key_exists('committee', $u['roles'])) {
|
|
/* Trying to save a committee member eh? Well, we established above
|
|
* that we're allowed to be here, so go ahead and save it */
|
|
$u['displayemail'] = ($_POST['displayemail'] == 'yes') ? 'yes' : 'no';
|
|
$u['emailprivate'] = mysql_real_escape_string(stripslashes($_POST['emailprivate']));
|
|
|
|
if($_SESSION['superuser'] == 'yes') {
|
|
/* Check for a change in the access flags */
|
|
$access_admin = $_POST['access_admin'];
|
|
$access_config = $_POST['access_config'];
|
|
$access_super = $_POST['access_super'];
|
|
|
|
if($access_admin == 'yes' && !array_key_exists('admin', $u['roles'])) {
|
|
/* Admin added */
|
|
user_add_role($u, 'admin');
|
|
}
|
|
|
|
if($access_admin == 'no' && array_key_exists('admin', $u['roles'])) {
|
|
/* Admin removed */
|
|
user_remove_role($u, 'admin');
|
|
}
|
|
|
|
if($access_config == 'yes' && !array_key_exists('config', $u['roles'])) {
|
|
/* Config added */
|
|
user_add_role($u, 'config');
|
|
}
|
|
|
|
if($access_config == 'no' && array_key_exists('config', $u['roles'])) {
|
|
/* Config removed */
|
|
user_remove_role($u, 'config');
|
|
}
|
|
|
|
/* Update superuser */
|
|
if($u['superuser'] != $access_super) {
|
|
mysql_query("UPDATE accounts SET superuser='$s' WHERE id='{$u['accounts_id']}");
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
if($save == true) {
|
|
user_save($u);
|
|
happy_("%1 %2 successfully updated",array($u['firstname'],$u['lastname']));
|
|
}
|
|
|
|
//reload the user record because we dont know if we saved or didnt save above, we just want
|
|
//to know what the user looks like _now_
|
|
$u = user_load($users_id);
|
|
$newstatus=user_personal_info_status($u);
|
|
echo "<script type=\"text/javascript\">";
|
|
echo "personal_update_status('$newstatus');\n";
|
|
echo "</script>\n";
|
|
exit;
|
|
}
|
|
|
|
|
|
//send the header
|
|
display_messages();
|
|
echo "<h4>".i18n("Personal Information")."</h4>";
|
|
echo "<br/>";
|
|
|
|
$newstatus=user_personal_info_status($u);
|
|
?>
|
|
<script type="text/javascript">
|
|
function personal_save()
|
|
{
|
|
$("#debug").load("<?=$config['SFIABDIRECTORY']?>/user_personal.php?action=save", $("#personalform").serializeArray());
|
|
return false;
|
|
}
|
|
|
|
function personal_update_status(s) {
|
|
if(s!='complete') {
|
|
$("#personal_info_status").html('<?=error(i18n("Personal Information Incomplete"))?>');
|
|
}
|
|
else
|
|
$("#personal_info_status").html('<?=happy(i18n("Personal Information Complete"))?>');
|
|
}
|
|
|
|
//when we're ready, output the status
|
|
$(document).ready( function() { personal_update_status('<?=$newstatus?>');});
|
|
|
|
</script>
|
|
<?
|
|
echo "<div id=\"personal_info_status\"></div>";
|
|
|
|
if(count($u['roles']) > 1) {
|
|
$str='';
|
|
foreach(array_keys($u['roles']) as $r) {
|
|
$str.= (($str=='')?'':', ').i18n($roles[$r]['name']);
|
|
}
|
|
echo notice(i18n('This user has multiple roles, the fields shown below are a combination of every role. Some may not apply to some roles. This user has the following roles:').' '.$str);
|
|
}
|
|
|
|
function item(&$u, $label, $fname, $type='textbox')
|
|
{
|
|
global $required, $fields, $config;
|
|
global $vreq;
|
|
|
|
if(!in_array($fname, $fields)) {
|
|
$vreq[$fname] = 'false';
|
|
echo '<td></td><td></td>';
|
|
return;
|
|
}
|
|
|
|
/* vreq is true/false for the form validator */
|
|
if(in_array($fname, $required)) {
|
|
$vreq[$fname] = 'true';
|
|
$req = REQUIREDFIELD;
|
|
} else {
|
|
$vreq[$fname] = 'false';
|
|
$req = '';
|
|
}
|
|
|
|
$c = ($label == '') ? '' : ':';
|
|
echo "<td><label for=\"$fname\">$req".i18n($label)."$c</label></td>";
|
|
|
|
echo '<td>';
|
|
switch($type) {
|
|
case 'textbox':
|
|
echo "<input id=\"$fname\" name=\"$fname\" type=\"text\" value=\"{$u[$fname]}\">";
|
|
break;
|
|
|
|
case 'province':
|
|
emit_province_selector($fname, $u[$fname]);
|
|
break;
|
|
|
|
case 'yesno':
|
|
echo "<select name=\"$fname\">";
|
|
$sel = ($u[$fname]=='yes') ? 'selected="selected"' : '';
|
|
echo "<option value=\"yes\" $sel>".i18n("Yes")."</option>\n";
|
|
$sel = ($u[$fname]=='no') ? 'selected="selected"' : '';
|
|
echo "<option value=\"no\" $sel>".i18n("No")."</option>\n";
|
|
echo "</select>";
|
|
break;
|
|
case 'sex':
|
|
echo "<select name=\"$fname\">";
|
|
echo "<option value=\"\">".i18n("Choose")."</option>\n";
|
|
if($u['sex']=="male") $sel="selected=\"selected\""; else $sel="";
|
|
echo "<option value=\"male\" $sel>".i18n("Male")."</option>\n";
|
|
if($u['sex']=="female") $sel="selected=\"selected\""; else $sel="";
|
|
echo "<option value=\"female\" $sel>".i18n("Female")."</option>\n";
|
|
break;
|
|
|
|
case 'language':
|
|
echo "<select name=\"$fname\">";
|
|
echo "<option value=\"\">".i18n("Choose")."</option>\n";
|
|
foreach($config['languages'] AS $l=>$ln) {
|
|
if($u['lang']==$l) $sel="selected=\"selected\""; else $sel="";
|
|
echo "<option value=\"$l\" $sel>".i18n($ln)."</option>\n";
|
|
}
|
|
echo "</select>";
|
|
break;
|
|
}
|
|
echo '</td>';
|
|
|
|
}
|
|
/*
|
|
|
|
<tr><td style="text-align: right" colspan="2"><input type="submit" value="<?=i18n("Save")?>" /></td></tr>
|
|
|
|
<tr><td style="text-align: left" colspan="2"><b>Address</b'><hr /></td></tr>
|
|
|
|
*/
|
|
|
|
?>
|
|
<form class="editor" id="personalform">
|
|
|
|
<table width="90%">
|
|
<tr><td style="text-align: left" colspan="2"><b>Name</b'><hr /></td></tr>
|
|
<tr><?=item($u, 'Salutation', 'salutation')?></tr>
|
|
<tr><?=item($u, 'First Name', 'firstname')?></tr>
|
|
<tr><?=item($u, 'Last Name', 'lastname')?></tr>
|
|
<tr><td style="text-align: left" colspan="2"><b>Address</b><hr /></td></tr>
|
|
<tr><?=item($u, 'Address', 'address')?></tr>
|
|
<tr><?=item($u, '', 'address2')?></tr>
|
|
<tr><?=item($u, 'City', 'city')?></tr>
|
|
<tr><?=item($u, i18n($config['provincestate']), 'province', 'province')?></tr>
|
|
<tr><?=item($u, i18n($config['postalzip']), 'postalcode')?></tr>
|
|
<? /*<tr><td style="text-align: right" colspan="2"><input type="submit" value="<?=i18n("Save")?>" /></td></tr> */
|
|
?>
|
|
|
|
<tr><td style="text-align: left" colspan="2"><b>Phone</b'><hr /></td></tr>
|
|
<tr><?=item($u, 'Home Phone', 'phonehome')?></tr>
|
|
<tr><?=item($u, 'Cell', 'phonecell')?></tr>
|
|
<? /*<tr><td style="text-align: right" colspan="2"><input type="submit" value="<?=i18n("Save")?>" /></td></tr> */
|
|
?>
|
|
|
|
<tr><td style="text-align: left" colspan="2"><b>Other Information</b'><hr /></td></tr>
|
|
<tr><?=item($u, 'Preferred Language', 'lang', 'language')?></tr>
|
|
<tr><?=item($u, 'Gender', 'sex', 'sex')?></tr>
|
|
<tr><?=item($u, 'First Aid Training', 'firstaid', 'yesno')?></tr>
|
|
<tr><?=item($u, 'CPR Training', 'cpr', 'yesno')?></tr>
|
|
|
|
<? /*<tr><td style="text-align: right" colspan="2"><input type="submit" value="<?=i18n("Save")?>" /></td></tr> */
|
|
?>
|
|
|
|
<tr><td style="text-align: left" colspan="2"><b>Organization</b'><hr /></td></tr>
|
|
<tr><?=item($u, 'Organization Name', 'organization')?></tr>
|
|
<tr><?=item($u, 'Phone', 'phonework')?></tr>
|
|
<tr><?=item($u, 'Fax', 'fax')?></tr>
|
|
|
|
|
|
<?
|
|
|
|
echo "</table>";
|
|
|
|
|
|
/* Committee specific fields */
|
|
if(array_key_exists('committee', $u['roles']) && false ) {
|
|
echo "<table>";
|
|
|
|
echo "<tr><td>".i18n("Email (Private)").":</td><td><input size=\"25\" type=\"text\" name=\"emailprivate\" value=\"{$u['emailprivate']}\" /></td></tr>\n";
|
|
echo "<tr><td>".i18n("Display Emails").":</td><td>";
|
|
if($u['displayemail']=="no") $checked="checked=\"checked\""; else $checked="";
|
|
echo "<input type=\"radio\" name=\"displayemail\" value=\"no\" $checked />".i18n("No");
|
|
echo " ";
|
|
if($u['displayemail']=="yes") $checked="checked=\"checked\""; else $checked="";
|
|
echo "<input type=\"radio\" name=\"displayemail\" value=\"yes\" $checked />".i18n("Yes");
|
|
|
|
if($_SESSION['superuser'] == 'yes') {
|
|
/* If the user is a committee member, only print these fields
|
|
* if the editer has super access */
|
|
echo "<tr><td align=\"center\" colspan=\"2\"><hr /></td></tr>";
|
|
echo "<tr><td>".i18n("Access Controls").":</td><td>";
|
|
$ch = (array_key_exists('admin',$u['roles'])) ? 'checked="checked"' : '';
|
|
echo "<input type=\"checkbox\" name=\"access_admin\" value=\"yes\" $ch /> ".i18n("Administration")."<br />";
|
|
$ch = (array_key_exists('config',$u['roles'])) ? 'checked="checked"' : '';
|
|
echo "<input type=\"checkbox\" name=\"access_config\" value=\"yes\" $ch /> ".i18n("Configuration")."<br />";
|
|
$ch = ($u['superuser']=="yes") ? 'checked="checked"' : '';
|
|
echo "<input type=\"checkbox\" name=\"access_super\" value=\"yes\" $ch /> ".i18n("Superuser")."<br />";
|
|
echo "</td></tr>";
|
|
}
|
|
echo '</table>';
|
|
}
|
|
|
|
?>
|
|
|
|
<input type="submit" value="<?=i18n("Save Personal Information")?>" />
|
|
</form>
|
|
<br />
|
|
|
|
<script type="text/javascript">
|
|
/* This method from the form validator additional methods script, modified to not
|
|
* allow spaces or parentheses */
|
|
jQuery.validator.addMethod("phoneUS", function(phone_number, element) {
|
|
phone_number = phone_number.replace(/\s+/g, "");
|
|
return this.optional(element) || phone_number.length > 9 &&
|
|
phone_number.match(/^[2-9]\d{2}-[2-9]\d{2}-\d{4}$/);
|
|
}, "Please specify a valid phone number");
|
|
|
|
$().ready(function() {
|
|
$("#personalform").validate({
|
|
rules: {
|
|
firstname: { required: <?=$vreq['firstname']?> },
|
|
lastname: { required: <?=$vreq['lastname']?> },
|
|
address: { required: <?=$vreq['address']?> },
|
|
city: { required: <?=$vreq['city']?> },
|
|
province: { required: <?=$vreq['province']?> },
|
|
postalcode: { required: <?=$vreq['postalcode']?> },
|
|
phonehome: {
|
|
required: <?=$vreq['phonehome']?>,
|
|
phoneUS: true
|
|
},
|
|
phonecell: {
|
|
required: <?=$vreq['phonecell']?>,
|
|
phoneUS: true
|
|
},
|
|
lang: { required: <?=$vreq['lang']?> },
|
|
sex: { required: <?=$vreq['sex']?> },
|
|
firstaid: { required: <?=$vreq['firstaid']?> },
|
|
cpr: { required: <?=$vreq['cpr']?> }
|
|
},
|
|
messages: {
|
|
firstname: { required: "<?=i18n('Please enter your first (given) name')?>" },
|
|
lastname: { required: "<?=i18n('Please enter your last name')?>" },
|
|
address: { required: "<?=i18n('Please enter your street address')?>" },
|
|
city: { required: "<?=i18n('Please enter your city')?>" },
|
|
province: { required: "<?=i18n('Please enter your province')?>" },
|
|
postalcode: { required: "<?=i18n('Please enter your postal code')?>" },
|
|
phonehome: {
|
|
required: "<?=i18n('Please enter your home phone number')?>",
|
|
phoneUS: "<?=i18n('Please enter a valid phone number of the form (NNN-NNN-NNNN)')?>"
|
|
},
|
|
phonecell: {
|
|
required: "<?=i18n('Please enter your cell phone number')?>",
|
|
phoneUS: "<?=i18n('Please enter a valid phone number of the form (NNN-NNN-NNNN)')?>"
|
|
},
|
|
lang: { required: "<?=i18n('Please select your preferred language of communication')?>" },
|
|
sex: { required: "<?=i18n('Please select your gender')?>" },
|
|
firstaid: { required: "<?=i18n('Please select yes or no')?>" },
|
|
cpr: { required: "<?=i18n('Please select yes or no')?>" }
|
|
},
|
|
submitHandler: function() {
|
|
personal_save();
|
|
return false;
|
|
},
|
|
cancelHandler: function() {
|
|
personal_save();
|
|
return false;
|
|
}
|
|
});
|
|
});
|
|
</script>
|
|
|