Start of the new user editor, some works, most things don't.

This commit is contained in:
dave 2010-08-08 09:09:49 +00:00
parent 7faf0fff45
commit ceb80636e1
8 changed files with 1908 additions and 307 deletions

1146
js/validate/jquery.validate.js vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@ -576,46 +576,61 @@ function user_judge_registration_status()
return "open"; return "open";
} }
$user_personal_fields_map = array( $user_fields_map = array(
/* Account -- Email requirement is set based on username, which
* is always required. Password is not required unless they type
* in the field, in which case the form validator kicks
* (checks pass1==pass2 and all that) */
// 'email' => array('email'),
/* Personal */
'salutation' => array('salutation'), 'salutation' => array('salutation'),
'name' => array('firstname','lastname'), 'name' => array('firstname','lastname'),
'email' => array('email'),
'sex' => array('sex'), 'sex' => array('sex'),
'phonehome' => array('phonehome'), 'phonehome' => array('phonehome'),
'phonework' => array('phonework'),
'phonecell' => array('phonecell'), 'phonecell' => array('phonecell'),
'fax' => array('fax'),
'org' => array('organization'),
'birthdate' => array('birthdate'), 'birthdate' => array('birthdate'),
'lang' => array('lang'), 'lang' => array('lang'),
'address' => array('address', 'address2', 'postalcode'), 'address' => array('address', 'address2', 'postalcode'),
'city' => array('city'), 'city' => array('city'),
'province' => array('province'), 'province' => array('province'),
'firstaid' => array('firstaid','cpr')); 'firstaid' => array('firstaid','cpr'),
/* Organization */
'org' => array('organization'),
'phonework' => array('phonework'),
'fax' => array('fax'),
);
function user_personal_fields($role) /* Return fields to show based on role. In the user editor, many
* fields are always shown and some have hard-coded requirements, but
* any in this list can be made optionally-required or not shown
* at all */
function user_fields_enabled($role)
{ {
global $config, $user_personal_fields_map; global $config, $user_fields_map;
$ret = array('firstname','lastname','email'); $ret = array('firstname','lastname');
$fields = $config["{$role}_personal_fields"]; $fields = $config["{$role}_personal_fields"];
if($fields != '') { if($fields != '') {
$fields = split(',', $fields); $fields = split(',', $fields);
foreach($fields as $f) { foreach($fields as $f) {
$ret = array_merge($ret, $user_personal_fields_map[$f]); $ret = array_merge($ret, $user_fields_map[$f]);
} }
} }
return $ret; return $ret;
} }
function user_personal_required_fields($role) /* Return required fields. Some fields are always shown and can be
* set to required. Some have hard-coded requirement status. This is only
* for the fields where the requirement can be configured. Not for ALL fields
* the user sees */
function user_fields_required($role)
{ {
global $config, $user_personal_fields_map; global $config, $user_fields_map;
$ret = array('firstname','lastname','email'); $ret = array('firstname','lastname','username');
$required = $config["{$role}_personal_required"]; $required = $config["{$role}_personal_required"];
if($required != '') { if($required != '') {
$fields = split(',', $required); $fields = split(',', $required);
foreach($fields as $f) { foreach($fields as $f) {
$ret = array_merge($ret, $user_personal_fields_map[$f]); $ret = array_merge($ret, $user_fields_map[$f]);
} }
} }
/* Filter some elements that are never required. /* Filter some elements that are never required.
@ -625,26 +640,6 @@ function user_personal_required_fields($role)
return $ret; return $ret;
} }
function user_personal_info_status(&$u)
{
$required = array();
foreach(array_keys($u['roles']) as $r) {
$required = array_merge($required,
user_personal_required_fields($r));
}
foreach($required as $r) {
$val = trim($u[$r]);
if(strlen($val) > 0) {
/* Ok */
} else {
return 'incomplete';
}
}
/* FIXME: somehow call the $role _status_update() function to update
* the individual [$role]['complete'] entry? */
return 'complete';
}
/* user_{$role}_login() is called with a full $u loaded */ /* user_{$role}_login() is called with a full $u loaded */

View File

@ -47,7 +47,7 @@ function user_account_check_username($accounts_id, $username)
{ {
if(!account_valid_user($username)) return false; if(!account_valid_user($username)) return false;
$u = mysql_real_escape_string($u); $u = mysql_real_escape_string($username);
$q = mysql_query("SELECT id FROM accounts WHERE username='$u' AND deleted='no' AND id!=$accounts_id"); $q = mysql_query("SELECT id FROM accounts WHERE username='$u' AND deleted='no' AND id!=$accounts_id");
if(mysql_num_rows($q) != 0) return false; if(mysql_num_rows($q) != 0) return false;
@ -142,6 +142,14 @@ case 'save':
</script> </script>
<? <?
} }
/* Update the status */
$newstatus=user_account_status(null, $a);
?>
<script type="text/javascript">
user_update_tab_status('account','<?=$newstatus?>');
</script>
<?
exit; exit;
} }
@ -164,9 +172,10 @@ case 'save':
echo "drect to: {$_SESSION['request_uri']}";; echo "drect to: {$_SESSION['request_uri']}";;
} }
echo "<h4>".i18n("Account/Login Information")."</h4><br />";
?> ?>
<h4><?=i18n("Account/Login Information")?> - <span class="status_account"></span></h4>
<br />
<form class="editor" name="account" id="accountform"> <form class="editor" name="account" id="accountform">
<table width="90%"> <table width="90%">
<tr> <tr>
@ -266,7 +275,7 @@ $.validator.addMethod("checking",function(value, element) {
return username_checking; return username_checking;
}); });
$().ready(function() { $(document).ready(function() {
$("#accountform").validate({ $("#accountform").validate({
rules: { rules: {
email: { email: {
@ -321,6 +330,9 @@ $().ready(function() {
} }
}); });
user_update_tab_status('account');
<? if($_SESSION['password_expired'] == false) { ?> <? if($_SESSION['password_expired'] == false) { ?>
/* Code to disable the username box, only included if the password hasn't expired */ /* Code to disable the username box, only included if the password hasn't expired */
var username_link = $("#username_link").is(":checked"); var username_link = $("#username_link").is(":checked");

137
user_edit.inc.php Normal file
View File

@ -0,0 +1,137 @@
<?
/*
This file is part of the 'Science Fair In A Box' project
SFIAB Website: http://www.sfiab.ca
Copyright (C) 2010 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('account.inc.php');
function user_edit_item(&$u, $label, $fname, $type='textbox')
{
global $required, $fields, $config;
if(!in_array($fname, $fields)) {
echo '<td></td><td></td>';
return;
}
$req = in_array($fname, $required) ? REQUIREDFIELD : '';
$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>';
}
function user_account_status(&$u, $a = null)
{
if(is_array($u)) {
$a = account_load($u['accounts_id']);
}
if($a['username'] == '')
return 'incomplete';
return 'complete';
}
function user_personal_info_status(&$u)
{
$required = array();
foreach(array_keys($u['roles']) as $r) {
$required = array_merge($required, user_fields_required($r));
}
$our_fields = array('salutation', 'firstname','lastname','address',
'address2','city','province','postalcode',
'phonehome','phonecell','language','sex',
'firstaid','cpr');
$required = array_intersect($our_fields, $required);
foreach($required as $r) {
if(trim($u[$r]) == '') return 'incomplete';
}
/* FIXME: somehow call the $role _status_update() function to update
* the individual [$role]['complete'] entry? */
return 'complete';
}
function user_organization_status(&$u)
{
$required = array();
foreach(array_keys($u['roles']) as $r) {
$required = array_merge($required, user_fields_required($r));
}
$our_fields = array('organization', 'phonework','fax');
$required = array_intersect($our_fields, $required);
foreach($required as $r) {
if(trim($u[$r]) == '') return 'incomplete';
}
/* FIXME: somehow call the $role _status_update() function to update
* the individual [$role]['complete'] entry? */
return 'complete';
}
function user_roles_status(&$u)
{
return 'complete';
}
?>

279
user_edit.php Normal file
View File

@ -0,0 +1,279 @@
<?
/*
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>
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');
require_once('user_edit.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();
$tabs = array( 'fairinfo' => array(
'label' => 'Fair Information',
'types' => array('fair'),
'file' => 'fair_info.php',
),
'fairstatsgathering' => array(
'label' => 'Fair Stats Gathering',
'types' => array('fair'),
'file' => 'fair_stats_select.php',
),
'account' => array(
'label' => 'Account/Login',
'name' => 'Account/Login/Password',
'types' => array('student','judge','committee','volunteer','sponsor','fair'),
'file' => 'user_account.php',
'status_func' => 'user_account_status',
),
'personal' => array(
'label' => 'Personal',
'name' => 'Personal Information',
'types' => array('student','judge','committee','volunteer','sponsor','fair'),
'file' => 'user_personal.php',
'status_func' => 'user_personal_info_status',
),
'organization' => array(
'label' => 'Organization',
'name' => 'Organization Information',
'types' => array('judge','volunteer','sponsor'),
'file' => 'user_organization.php',
'status_func' => 'user_organization_status',
),
'roles' => array(
'label' => 'Roles',
'types' => array('student','judge','committee','volunteer','sponsor','fair'),
'file' => 'user_roles.php',
'status_func' => 'user_roles_status',
),
'judgeother' => array(
'label' => 'Judge Other',
'types' => array('judge'),
'file' => 'judge_other.php',
),
'judgeexpertise' => array(
'label' => 'Expertise',
'types' => array('judge'),
'file' => 'judge_expertise.php',
),
'judgeavailability' => array(
'label' => 'Time Avail.',
'types' => array('judge'),
'file' => 'judge_availability.php',
),
'judgesa' => array(
'label' => 'Special Awards',
'types' => array('judge'),
'file' => 'judge_special_awards.php',
),
'volunteerpos' => array(
'label' => 'Volunteer Positions',
'types' => array('volunteer'),
'file' => 'volunteer_position.php',
),
'fairstats' => array(
'label' => 'Fair Statistics and Information',
'types' => array('fair'),
'file' => 'fair_stats.php',
),
);
$u = user_load($edit_id);
$types = array_keys($u['roles']);
$selected = $_GET['tab'];
if(!array_key_exists($selected, $tabs)) {
if(in_array('fair', $types) )
$selected = 'fairinfo';
else
$selected = 'personal';
}
$fields = array();
$required = array();
foreach(array_keys($u['roles']) as $r) {
$fields = array_merge($fields, user_fields_enabled($r));
$required = array_merge($required, user_fields_required($r));
}
/* Disable some of the tabs */
if($config['judges_availability_enable'] != 'yes') $tabs['judgeavailability']['disabled'] = true;
$a = array_intersect(array('organization','phonework','fax'), $fields);
if(count($a) == 0) {
/* No organization stuff is enabled */
$tabs['organization']['disabled'] = true;
}
send_header(i18n("User Editor").": {$u['name']}");
/* Setup tabs */
echo '<div id="tabs">';
echo '<ul>';
/* Always show a registration summary */
echo '<li><a href="#user_summary">'.i18n('Registration Summary').'</a></li>';
$index = 1;
$selected_index = 0;
/* Show all other enabled tabs */
foreach($tabs as $k=>$t) {
/* Make sure the tab is enabled */
if($t['disabled'] == true) continue;
/* Make sure the user has the right type to see the tab */
$i = array_intersect($t['types'], $types);
if(count($i) == 0) {
/* Turn off the tab, so in future iterations of the tabs
* list we only ahve to check enabled */
$tabs[$k]['disabled'] = true;
continue;
}
$tabs[$k]['index'] = $index;
$tabs_key[$index] = $k;
if($k == $selected) $selected_index = $index;
$index++;
/* Show the tab */
$href = "{$t['file']}?id=$id";
echo "<li><a href=\"$href\"><span>".i18n($t['label'])."</span></a></li>";
}
?>
</ul>
<div id="user_summary">
<h4><?=i18n("Registration Summary")?></h4>
<br/>
<table border="0" cellpadding="2">
<?
foreach($tabs as $k=>$t) {
/* Enabled has been modified now for this user */
if($t['disabled'] == true) continue;
/* Get the status */
if(is_callable($t['status_func'])) {
$s = call_user_func($t['status_func'], $u);
$tabs[$k]['status'] = ($s == 'complete') ? 'complete' : 'incomplete';
} else {
$tabs[$k]['status'] = 'incomplete';
}
/* Link to switch to the tab */
$n = ($t['name'] != '') ? $t['name'] : $t['label'];
?>
<tr>
<td><a href="#" onclick="return linkto_click(<?=$t['index']?>);"><?=i18n($n)?></a></td>
<td><span class="status_<?=$k?>"></span></td>
</tr>
<?
}
?>
<tr><td colspan="2"><hr /></td></tr>
<tr> <td><?=i18n('Overall Status')?></td>
<td><span class="status_overall"></span></td>
</tr>
</table>
</div>
</div>
<script type="text/javascript">
var stat = new Array();
<?
/* An array of all tabs and current status for each one */
foreach($tabs as $k=>$t) {
/* Enabled has been modified now for this user */
if($t['disabled'] == true) continue;
if($t['index'] != 1) echo ", ";
echo "stat['$k'] = '{$t['status']}'\n";
}
?>
$(document).ready(function() {
$("#tabs").tabs({
// selected: <?=$selected_index?>
});
/* Update each tab for complete/incomplete */
for(var key in stat) {
user_update_tab_status(key);
}
});
function linkto_click(index)
{
$("#tabs").tabs('select', index);
return false;
}
function user_update_tab_status(tabkey,newstatus)
{
// var curr_tab = $("#tabs").tabs('option', 'selected');
if(!newstatus) {
/* Keep the status the same if not specified */
newstatus = stat[tabkey];
}
if(newstatus!='complete') {
$(".status_"+tabkey).html('<?=i18n("Incomplete")?>');
$(".status_"+tabkey).removeClass('happy');
$(".status_"+tabkey).addClass('error');
} else {
$(".status_"+tabkey).html('<?=i18n("Complete")?>');
$(".status_"+tabkey).removeClass('error');
$(".status_"+tabkey).addClass('happy');
}
stat[tabkey] = newstatus;
/* See if the user is overall complete, server-side this is done, but the
* server never sends back the overall result to the client, and doesn't need to
* because we can easily figure it out (assuming the complete/incomplete status
* of each tab doesn't get out of sync) */
var overall = 'complete';
for(var key in stat) {
if(stat[key] != 'complete') {
overall = 'incomplete';
}
}
if(overall!='complete') {
$(".status_overall").html('<?=i18n("Incomplete")?>');
$(".status_overall").removeClass('happy');
$(".status_overall").addClass('error');
} else {
$(".status_overall").html('<?=i18n("Complete")?>');
$(".status_overall").removeClass('error');
$(".status_overall").addClass('happy');
}
}
</script>
<?
send_footer();
?>

170
user_organization.php Normal file
View File

@ -0,0 +1,170 @@
<?
/*
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');
require_once('user_edit.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);
/* Load the fields the user can edit, and theones that are required */
$fields = array();
$required = array();
foreach(array_keys($u['roles']) as $r) {
$fields = array_merge($fields, user_fields_enabled($r));
$required = array_merge($required, user_fields_required($r));
}
/* Filter fields, only the ones we care about */
$our_fields = array('organization', 'phonework','fax');
$fields = array_intersect($our_fields, $fields);
$required = array_intersect($our_fields, $required);
switch($_GET['action']) {
case 'save':
$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;
}
if($save == true) {
user_save($u);
happy_("Organization information successfully updated");
}
//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($u['id']);
$newstatus=user_organization_status($u);
?>
<script type="text/javascript">
user_update_tab_status('organization','<?=$newstatus?>');
</script>
<?
exit;
}
//send the header
?>
<h4><?=i18n("Organization")?> - <span class="status_organization"></span></h4>
<br/>
<form class="editor" id="orgform">
<table width="90%">
<tr><td style="text-align: left" colspan="2"><b>Organization</b'><hr /></td></tr>
<tr><?=user_edit_item($u, 'Organization Name', 'organization')?></tr>
<tr><?=user_edit_item($u, 'Phone', 'phonework')?></tr>
<tr><?=user_edit_item($u, 'Fax', 'fax')?></tr>
</table>
<br />
<input type="submit" value="<?=i18n("Save Organization Information")?>" />
</form>
<br />
<?
function vreq($field)
{
global $required;
/* Return 'true' or 'false' as text for the
* validator plugin to use for the 'required' param */
if(in_array($field, $required)) return 'true';
return 'false';
}
?>
<script type="text/javascript">
function org_save()
{
$("#debug").load("<?=$config['SFIABDIRECTORY']?>/user_organization.php?action=save&users_id=<?=$edit_id?>", $("#orgform").serializeArray());
return false;
}
/* 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");
$(document).ready(function() {
$("#orgform").validate({
rules: {
organization: { required: <?=vreq('firstname')?> },
phonework: {
required: <?=vreq('phonework')?>,
phoneUS: true
},
fax: {
required: <?=vreq('fax')?>,
phoneUS: true
}
},
messages: {
organization: { required: "<?=i18n('Please enter your company\'s name')?>" },
phonehome: {
required: "<?=i18n('Please enter your work phone number')?>",
phoneUS: "<?=i18n('Please enter a valid phone number of the form (NNN-NNN-NNNN)')?>"
},
phonecell: {
required: "<?=i18n('Please enter your work fax number')?>",
phoneUS: "<?=i18n('Please enter a valid phone number of the form (NNN-NNN-NNNN)')?>"
}
},
submitHandler: function() {
org_save();
return false;
},
cancelHandler: function() {
org_save();
return false;
}
});
user_update_tab_status('organization');
});
</script>

View File

@ -25,44 +25,11 @@
<? <?
require_once('common.inc.php'); require_once('common.inc.php');
require_once('user.inc.php'); require_once('user.inc.php');
require_once('user_edit.inc.php');
/* Ensure they're logged in as something, anything */ /* Ensure they're logged in as something, anything */
user_auth_required(); 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']; $edit_id = isset($_GET['users_id']) ? intval($_GET['users_id']) : $_SESSION['users_id'];
if($edit_id != $_SESSION['users_id']) if($edit_id != $_SESSION['users_id'])
user_auth_required('admin'); user_auth_required('admin');
@ -71,46 +38,35 @@ else
$u = user_load($edit_id); $u = user_load($edit_id);
/* Load the fields the user can edit, and theones that are required */ /* Load the fields the user can edit, and theones that are required */
$fields = array(); $fields = array();
$required = array(); $required = array();
$errorfields = array(); foreach(array_keys($u['roles']) as $r) {
foreach(array_keys($u['roles']) as $r) {
$fields = array_merge($fields, $fields = array_merge($fields,
user_personal_fields($r)); user_fields_enabled($r));
$required = array_merge($required, $required = array_merge($required,
user_personal_required_fields($r)); user_fields_required($r));
} }
/* true/false strings for form validation */
$vreq = array(); /* Filter fields, only the ones we care about */
$our_fields = array('salutation', 'firstname','lastname','address',
'address2','city','province','postalcode',
'phonehome','phonecell','language','sex',
'firstaid','cpr');
$fields = array_intersect($our_fields, $fields);
$required = array_intersect($our_fields, $required);
switch($_GET['action']) { switch($_GET['action']) {
case 'save': 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; $save = true;
/* Set values */
/* Cleanup POST data */
foreach($fields as $f) { foreach($fields as $f) {
$u[$f] = stripslashes($_POST[$f]); $u[$f] = stripslashes($_POST[$f]);
/* Allow the user to clear a field regardless of regex */ /* Allow the user to clear a field */
if($u[$f] == '') continue; 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(0) {
if(array_key_exists('committee', $u['roles'])) { if(array_key_exists('committee', $u['roles'])) {
/* Trying to save a committee member eh? Well, we established above /* Trying to save a committee member eh? Well, we established above
* that we're allowed to be here, so go ahead and save it */ * that we're allowed to be here, so go ahead and save it */
@ -149,6 +105,7 @@ case 'save':
} }
} }
} }
}
if($save == true) { if($save == true) {
@ -158,165 +115,65 @@ case 'save':
//reload the user record because we dont know if we saved or didnt save above, we just want //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_ //to know what the user looks like _now_
$u = user_load($users_id); $u = user_load($u['id']);
/* Update the status */
$newstatus=user_personal_info_status($u); $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"> <script type="text/javascript">
function personal_save() user_update_tab_status('personal','<?=$newstatus?>');
{ </script>
$("#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>"; exit;
}
if(count($u['roles']) > 1) { if(count($u['roles']) > 1) {
$str=''; $str='';
foreach(array_keys($u['roles']) as $r) { foreach(array_keys($u['roles']) as $r) {
$str.= (($str=='')?'':', ').i18n($roles[$r]['name']); $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); // 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>
*/
?> ?>
<h4><?=i18n("Personal Information")?> - <span class="status_personal"></span></h4>
<br/>
<form class="editor" id="personalform"> <form class="editor" id="personalform">
<table width="90%"> <table width="90%">
<tr><td style="text-align: left" colspan="2"><b>Name</b'><hr /></td></tr> <tr><td style="text-align: left" colspan="2"><b>Name</b'><hr /></td></tr>
<tr><?=item($u, 'Salutation', 'salutation')?></tr> <tr><?=user_edit_item($u, 'Salutation', 'salutation')?></tr>
<tr><?=item($u, 'First Name', 'firstname')?></tr> <tr><?=user_edit_item($u, 'First Name', 'firstname')?></tr>
<tr><?=item($u, 'Last Name', 'lastname')?></tr> <tr><?=user_edit_item($u, 'Last Name', 'lastname')?></tr>
<tr><td style="text-align: left" colspan="2"><b>Address</b><hr /></td></tr> <tr><td style="text-align: left" colspan="2"><b>Address</b><hr /></td></tr>
<tr><?=item($u, 'Address', 'address')?></tr> <tr><?=user_edit_item($u, 'Address', 'address')?></tr>
<tr><?=item($u, '', 'address2')?></tr> <tr><?=user_edit_item($u, '', 'address2')?></tr>
<tr><?=item($u, 'City', 'city')?></tr> <tr><?=user_edit_item($u, 'City', 'city')?></tr>
<tr><?=item($u, i18n($config['provincestate']), 'province', 'province')?></tr> <tr><?=user_edit_item($u, i18n($config['provincestate']), 'province', 'province')?></tr>
<tr><?=item($u, i18n($config['postalzip']), 'postalcode')?></tr> <tr><?=user_edit_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: 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><td style="text-align: left" colspan="2"><b>Phone</b'><hr /></td></tr>
<tr><?=item($u, 'Home Phone', 'phonehome')?></tr> <tr><?=user_edit_item($u, 'Home Phone', 'phonehome')?></tr>
<tr><?=item($u, 'Cell', 'phonecell')?></tr> <tr><?=user_edit_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: 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><td style="text-align: left" colspan="2"><b>Other Information</b'><hr /></td></tr>
<tr><?=item($u, 'Preferred Language', 'lang', 'language')?></tr> <tr><?=user_edit_item($u, 'Preferred Language', 'lang', 'language')?></tr>
<tr><?=item($u, 'Gender', 'sex', 'sex')?></tr> <tr><?=user_edit_item($u, 'Gender', 'sex', 'sex')?></tr>
<tr><?=item($u, 'First Aid Training', 'firstaid', 'yesno')?></tr> <tr><?=user_edit_item($u, 'First Aid Training', 'firstaid', 'yesno')?></tr>
<tr><?=item($u, 'CPR Training', 'cpr', 'yesno')?></tr> <tr><?=user_edit_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>
</table>
<? <?
echo "</table>";
/* Committee specific fields */ /* Committee specific fields */
if(array_key_exists('committee', $u['roles']) && false ) { if(array_key_exists('committee', $u['roles']) && false ) {
@ -346,6 +203,15 @@ if(array_key_exists('committee', $u['roles']) && false ) {
echo '</table>'; echo '</table>';
} }
function vreq($field)
{
global $required;
/* Return 'true' or 'false' as text for the
* validator plugin to use for the 'required' param */
if(in_array($field, $required)) return 'true';
return 'false';
}
?> ?>
<input type="submit" value="<?=i18n("Save Personal Information")?>" /> <input type="submit" value="<?=i18n("Save Personal Information")?>" />
@ -353,6 +219,13 @@ if(array_key_exists('committee', $u['roles']) && false ) {
<br /> <br />
<script type="text/javascript"> <script type="text/javascript">
function personal_save()
{
$("#debug").load("<?=$config['SFIABDIRECTORY']?>/user_personal.php?action=save&users_id=<?=$edit_id?>", $("#personalform").serializeArray());
return false;
}
/* This method from the form validator additional methods script, modified to not /* This method from the form validator additional methods script, modified to not
* allow spaces or parentheses */ * allow spaces or parentheses */
jQuery.validator.addMethod("phoneUS", function(phone_number, element) { jQuery.validator.addMethod("phoneUS", function(phone_number, element) {
@ -361,27 +234,27 @@ jQuery.validator.addMethod("phoneUS", function(phone_number, element) {
phone_number.match(/^[2-9]\d{2}-[2-9]\d{2}-\d{4}$/); phone_number.match(/^[2-9]\d{2}-[2-9]\d{2}-\d{4}$/);
}, "Please specify a valid phone number"); }, "Please specify a valid phone number");
$().ready(function() { $(document).ready(function() {
$("#personalform").validate({ $("#personalform").validate({
rules: { rules: {
firstname: { required: <?=$vreq['firstname']?> }, firstname: { required: <?=vreq('firstname')?> },
lastname: { required: <?=$vreq['lastname']?> }, lastname: { required: <?=vreq('lastname')?> },
address: { required: <?=$vreq['address']?> }, address: { required: <?=vreq('address')?> },
city: { required: <?=$vreq['city']?> }, city: { required: <?=vreq('city')?> },
province: { required: <?=$vreq['province']?> }, province: { required: <?=vreq('province')?> },
postalcode: { required: <?=$vreq['postalcode']?> }, postalcode: { required: <?=vreq('postalcode')?> },
phonehome: { phonehome: {
required: <?=$vreq['phonehome']?>, required: <?=vreq('phonehome')?>,
phoneUS: true phoneUS: true
}, },
phonecell: { phonecell: {
required: <?=$vreq['phonecell']?>, required: <?=vreq('phonecell')?>,
phoneUS: true phoneUS: true
}, },
lang: { required: <?=$vreq['lang']?> }, lang: { required: <?=vreq('lang')?> },
sex: { required: <?=$vreq['sex']?> }, sex: { required: <?=vreq('sex')?> },
firstaid: { required: <?=$vreq['firstaid']?> }, firstaid: { required: <?=vreq('firstaid')?> },
cpr: { required: <?=$vreq['cpr']?> } cpr: { required: <?=vreq('cpr')?> }
}, },
messages: { messages: {
firstname: { required: "<?=i18n('Please enter your first (given) name')?>" }, firstname: { required: "<?=i18n('Please enter your first (given) name')?>" },
@ -407,11 +280,14 @@ $().ready(function() {
personal_save(); personal_save();
return false; return false;
}, },
cancelHandler: function() { invalidHandler: function() {
personal_save(); personal_save();
return false; return false;
} }
}); });
user_update_tab_status('personal');
}); });
</script> </script>

View File

@ -23,33 +23,24 @@
*/ */
?> ?>
<? <?
require_once("common.inc.php"); require_once('common.inc.php');
require_once("user.inc.php"); require_once('user.inc.php');
require_once('user_edit.inc.php');
if(!isset($_SESSION['users_id'])) { /* Ensure they're logged in as something, anything */
/* No user ID set, invalid session for editting roles */ user_auth_required();
echo "ERROR: session is invalid";
exit;
}
/* Sort out who we're editting */ $edit_id = isset($_GET['users_id']) ? intval($_GET['users_id']) : $_SESSION['users_id'];
if($_POST['users_id']) if($edit_id != $_SESSION['users_id'])
$eid = intval($_POST['users_id']); /* From a save form */
else if(array_key_exists('embed_edit_id', $_SESSION))
$eid = $_SESSION['embed_edit_id']; /* From the embedded editor */
else
$eid = $_SESSION['users_id']; /* Regular entry */
if($eid != $_SESSION['users_id']) {
/* Not editing ourself, we had better be
* someone with admin access */
user_auth_required('admin'); user_auth_required('admin');
} else
$u = user_load($eid); user_auth_required();
/* Validate the incoming role, make sure it is actually a role */ $u = user_load($edit_id);
$role = '';
if($_GET['action'] != '') { /* Validate the incoming role, make sure it is actually a role */
$role = '';
if($_GET['action'] != '') {
$role = $_GET['role']; $role = $_GET['role'];
if(!array_key_exists($role, $roles)) { if(!array_key_exists($role, $roles)) {
echo "ERROR: not an allowed role."; echo "ERROR: not an allowed role.";
@ -66,17 +57,14 @@ if($eid != $_SESSION['users_id']) {
echo "HALT: invalid role to manipulate for this user."; echo "HALT: invalid role to manipulate for this user.";
exit; exit;
} }
} }
switch($_GET['action']) { switch($_GET['action']) {
case 'delete': case 'delete':
//okay here we go, lets get rid of them completely, since this is what theyve asked for //okay here we go, lets get rid of them completely, since this is what theyve asked for
message_push(happy(i18n("Account successfully deleted. Goodbye"))); message_push(happy(i18n("Account successfully deleted. Goodbye")));
user_delete($u); user_delete($u);
if($_SESSION['embed'] == true) header('location: user_login.php?action=logout');
display_messages();
else
header('location: user_login.php?action=logout');
exit; exit;
case 'remove': case 'remove':
@ -111,31 +99,30 @@ case 'remove':
exit; exit;
} }
$u = user_load($u['id']);
if($_SESSION['embed'] == true) {
echo "<br/>";
display_messages();
echo "<h3>".i18n("Role and Account Management")."</h3>";
echo "<br/>";
} else {
send_header("Role and Account Management",
array("Main" => "user_main.php")
);
}
?> ?>
<h4><?=i18n("Roles")?> - <span class="status_roles"></span></h4>
<?
echo '<ul>';
echo '<li>'.i18n("An <b>Active Role</b> indicates you would like to participate in the %1 %2 as that role (Judge, Volunteer, etc.)",array($config['FAIRYEAR'],$config['fairname']));
echo '</li><li>'.i18n("A <b>Deactivated Role</b> indicates you cannot participate in the deactivated roles this year, but would like remain on the mailing lists for future years. You can activate your deactivated role at any time.");
echo '</li><li>'.i18n("The <b>Remove Role</b> button completely deletes the role from your account. You will not receive future emails for the removed role. This action cannot be undone.");
echo '</li><li>'.i18n("The <b>Delete Entire Account</b> button at the bottom of the page completely deletes your entire account. You will not receive any future email for any roles. It completely removes you from the system. This action cannot be undone.");
echo '</ul>';
?>
<script type="text/javascript"> <script type="text/javascript">
function activate(role) function activate(role)
{ {
$("#status_"+role).load("<?=$config['SFIABDIRECTORY']?>/user_activate.php?action=activate&role="+role,$('#activate_form').serializeArray()); $("#status_"+role).load("<?=$config['SFIABDIRECTORY']?>/user_roles.php?action=activate&users_id=<?=$u['id']?>&role="+role,$('#rolesform').serializeArray());
$("#activate_"+role).attr('disabled', 'disabled'); $("#activate_"+role).attr('disabled', 'disabled');
$("#deactivate_"+role).removeAttr('disabled'); $("#deactivate_"+role).removeAttr('disabled');
$("#remove_"+role).removeAttr('disabled'); $("#remove_"+role).removeAttr('disabled');
} }
function deactivate(role) function deactivate(role)
{ {
$("#status_"+role).load("<?=$config['SFIABDIRECTORY']?>/user_activate.php?action=deactivate&role="+role,$('#activate_form').serializeArray()); $("#status_"+role).load("<?=$config['SFIABDIRECTORY']?>/user_roles.php?action=deactivate&users_id=<?=$u['id']?>&role="+role,$('#rolesform').serializeArray());
$("#activate_"+role).removeAttr('disabled'); $("#activate_"+role).removeAttr('disabled');
$("#deactivate_"+role).attr('disabled', 'disabled'); $("#deactivate_"+role).attr('disabled', 'disabled');
$("#remove_"+role).attr('disabled', 'disabled'); $("#remove_"+role).attr('disabled', 'disabled');
@ -144,16 +131,22 @@ function remove(role)
{ {
var con = confirmClick("<?=i18n("Are you sure you want to remove this role from your account?\\nThis action cannot be undone.")?>"); var con = confirmClick("<?=i18n("Are you sure you want to remove this role from your account?\\nThis action cannot be undone.")?>");
if(con == true) { if(con == true) {
$("#status_"+role).load("<?=$config['SFIABDIRECTORY']?>/user_activate.php?action=remove&role="+role,$('#activate_form').serializeArray()); $("#status_"+role).load("<?=$config['SFIABDIRECTORY']?>/user_roles.php?action=remove&users_id=<?=$u['id']?>&role="+role,$('#rolesform').serializeArray());
$("#activate_"+role).attr('disabled', 'disabled'); $("#activate_"+role).attr('disabled', 'disabled');
$("#deactivate_"+role).attr('disabled', 'disabled'); $("#deactivate_"+role).attr('disabled', 'disabled');
$("#remove_"+role).attr('disabled', 'disabled'); $("#remove_"+role).attr('disabled', 'disabled');
} }
} }
$(document).ready(function() {
user_update_tab_status('roles');
});
</script> </script>
<form id="activate_form">
<input type="hidden" name="users_id" value="<?=$u['id']?>" /> <form id="rolesform">
<? <?
foreach(array_keys($u['roles']) as $r) { foreach(array_keys($u['roles']) as $r) {
@ -182,20 +175,13 @@ function remove(role)
<br /> <br />
<hr /> <hr />
<? <?
} }
echo "</form>";
echo '<ul>';
echo '<li>'.i18n("An <b>Active Role</b> indicates you would like to participate in the %1 %2 as that role (Judge, Volunteer, etc.)",array($config['FAIRYEAR'],$config['fairname']));
echo '</li><li>'.i18n("A <b>Deactivated Role</b> indicates you cannot participate in the deactivated roles this year, but would like remain on the mailing lists for future years. You can activate your deactivated role at any time.");
echo '</li><li>'.i18n("The <b>Remove Role</b> button completely deletes the role from your account. You will not receive future emails for the removed role. This action cannot be undone.");
echo '</li><li>'.i18n("The <b>Delete Entire Account</b> button below completely deletes your entire account. You will not receive any future email for any roles. It completely removes you from the system. This action cannot be undone.");
echo '</ul>';
echo "<form method=\"post\" action=\"{$config['SFIABDIRECTORY']}/user_activate.php?action=delete\">";
echo "<input type=\"hidden\" name=\"users_id\" value=\"{$u['id']}\" />";
echo "<input style=\"width: 300px;\" onclick=\"return confirmClick('".i18n("Are you sure you want to completely delete your account?\\nDoing so will remove you from our mailing list for future years and you will never hear from us again.\\nThis action cannot be undone.")."')\" type=\"submit\" value=\"".i18n("Delete Entire Account")."\">";
echo "</form>";
if($_SESSION['embed'] != true) send_footer();
?> ?>
</form>
<form method="post" action="<?=$config['SFIABDIRECTORY']?>/user_roles.php?action=delete&users_id=<?=$u['id']?>" >
<input style="width: 300px;" onclick="return confirmClick('<?=i18n("Are you sure you want to completely delete your account?\\nDoing so will remove you from our mailing list for future years and you will never hear from us again.\\nThis action cannot be undone.")?>');"
type="submit" value="<?=i18n("Delete Entire Account")?>">
</form>