forked from science-ation/science-ation
Updates to user_personal to use form validator
This commit is contained in:
parent
5112bc5ffb
commit
4ba55b274c
@ -111,8 +111,12 @@ form.editor table tr td {
|
||||
vertical-align: baseline;
|
||||
}
|
||||
|
||||
/* Enforce a minimum width, but let the table layout
|
||||
* expand to fit the width of the maximum label */
|
||||
form.editor table tr td:first-child {
|
||||
text-align: right;
|
||||
width: 20%;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
|
||||
|
@ -23,13 +23,13 @@
|
||||
*/
|
||||
?>
|
||||
<?
|
||||
require_once("common.inc.php");
|
||||
require_once("user.inc.php");
|
||||
require_once('common.inc.php');
|
||||
require_once('user.inc.php');
|
||||
|
||||
/* Ensure they're logged in as something, anything */
|
||||
user_auth_required();
|
||||
/* Ensure they're logged in as something, anything */
|
||||
user_auth_required();
|
||||
|
||||
$user_personal_fields = array(
|
||||
$user_personal_fields = array(
|
||||
'salutation' => array('name' => 'Salutation'),
|
||||
'firstname' => array('name' => 'First Name'),
|
||||
'lastname' => array('name' => 'Last Name'),
|
||||
@ -62,21 +62,14 @@
|
||||
|
||||
);
|
||||
|
||||
/* Sort out who we're editting */
|
||||
if($_POST['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
|
||||
* a committee member */
|
||||
$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($eid);
|
||||
$u = user_load($edit_id);
|
||||
/* Load the fields the user can edit, and theones that are required */
|
||||
$fields = array();
|
||||
$required = array();
|
||||
@ -87,6 +80,8 @@ if($eid != $_SESSION['users_id']) {
|
||||
$required = array_merge($required,
|
||||
user_personal_required_fields($r));
|
||||
}
|
||||
/* true/false strings for form validation */
|
||||
$vreq = array();
|
||||
|
||||
switch($_GET['action']) {
|
||||
case 'save':
|
||||
@ -172,19 +167,10 @@ case 'save':
|
||||
}
|
||||
|
||||
|
||||
|
||||
//send the header
|
||||
if($_SESSION['embed'] == true) {
|
||||
echo "<br/>";
|
||||
display_messages();
|
||||
echo "<h3>".i18n("Personal Information")."</h3>";
|
||||
echo "<br/>";
|
||||
} else {
|
||||
send_header("Personal Information for {$u['firstname']} {$u['lastname']}",
|
||||
array("Main" => "user_main.php")
|
||||
,"edit_profile"
|
||||
);
|
||||
}
|
||||
//send the header
|
||||
display_messages();
|
||||
echo "<h4>".i18n("Personal Information")."</h4>";
|
||||
echo "<br/>";
|
||||
|
||||
$newstatus=user_personal_info_status($u);
|
||||
?>
|
||||
@ -221,12 +207,23 @@ if(count($u['roles']) > 1) {
|
||||
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;
|
||||
}
|
||||
$req = in_array($fname, $required) ? REQUIREDFIELD : '';
|
||||
|
||||
/* 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>";
|
||||
|
||||
@ -274,42 +271,45 @@ function item(&$u, $label, $fname, $type='textbox')
|
||||
|
||||
<tr><td style="text-align: right" colspan="2"><input type="submit" value="<?=i18n("Save")?>" /></td></tr>
|
||||
|
||||
<tr><td style="text-align: left" colspan="2"><h4>Address</h4><hr /></td></tr>
|
||||
<tr><td style="text-align: left" colspan="2"><b>Address</b'><hr /></td></tr>
|
||||
|
||||
*/
|
||||
|
||||
?>
|
||||
<center>
|
||||
<form class="editor" name="personalform" id="personal_form">
|
||||
<input type="hidden" name="users_id" value="<?=$u['id']?>" />
|
||||
<table width="50%">
|
||||
<tr><td style="text-align: left" colspan="2"><h4>Name</h4><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><?=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"><h4>Phone</h4><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><?=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"><h4>Misc</h4><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><?=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: right" colspan="2"><input type="submit" value="<?=i18n("Save")?>" /></td></tr> */
|
||||
?>
|
||||
|
||||
<tr><td style="text-align: left" colspan="2"><h4>Organization</h4><hr /></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', 'firstaid')?></tr>
|
||||
<tr><?=item($u, 'Phone', 'phonework')?></tr>
|
||||
<tr><?=item($u, 'Fax', 'fax')?></tr>
|
||||
|
||||
|
||||
@ -317,8 +317,9 @@ function item(&$u, $label, $fname, $type='textbox')
|
||||
|
||||
echo "</table>";
|
||||
|
||||
|
||||
/* Committee specific fields */
|
||||
if(array_key_exists('committee', $u['roles'])) {
|
||||
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";
|
||||
@ -349,27 +350,58 @@ if(array_key_exists('committee', $u['roles'])) {
|
||||
|
||||
<input type="submit" value="<?=i18n("Save Personal Information")?>" />
|
||||
</form>
|
||||
</center>
|
||||
<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: true,
|
||||
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
|
||||
},
|
||||
lastname: {
|
||||
required: 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')?>",
|
||||
},
|
||||
lastnmae: {
|
||||
required: "<?=i18n('Please enter your last name')?>",
|
||||
}
|
||||
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();
|
||||
@ -380,11 +412,6 @@ $().ready(function() {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<?
|
||||
|
||||
if($_SESSION['embed'] != true) {
|
||||
send_footer();
|
||||
}
|
||||
|
||||
?>
|
||||
|
Loading…
x
Reference in New Issue
Block a user