Playing with user_personal.php

This commit is contained in:
dave 2010-08-08 09:09:38 +00:00
parent 57f7bd5212
commit 5112bc5ffb

View File

@ -191,7 +191,7 @@ $newstatus=user_personal_info_status($u);
<script type="text/javascript">
function personal_save()
{
$("#debug").load("<?=$config['SFIABDIRECTORY']?>/user_personal.php?action=save", $("#personal_form").serializeArray());
$("#debug").load("<?=$config['SFIABDIRECTORY']?>/user_personal.php?action=save", $("#personalform").serializeArray());
return false;
}
@ -218,126 +218,102 @@ if(count($u['roles']) > 1) {
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($user, $fname, $subtext='')
function item(&$u, $label, $fname, $type='textbox')
{
global $fields, $required;
global $errorfields;
global $user_personal_fields;
global $required, $fields, $config;
if(in_array($fname, $fields)) {
$text = i18n($user_personal_fields[$fname]['name']);
if(in_array($fname, $errorfields)) $style = 'style="color:red;"';
echo "<td><span $style>$text</span>: ";
if($subtext != '') echo '<br /><span style="font-size: 0.5em;">'.i18n($subtext).'</span>';
echo '</td><td>';
$req = in_array($fname, $required) ? REQUIREDFIELD : '';
switch($user_personal_fields[$fname]['type']) {
case 'yesno':
echo "<select name=\"$fname\">";
$sel = ($user[$fname]=='yes') ? 'selected="selected"' : '';
echo "<option value=\"yes\" $sel>".i18n("Yes")."</option>\n";
$sel = ($user[$fname]=='no') ? 'selected="selected"' : '';
echo "<option value=\"no\" $sel>".i18n("No")."</option>\n";
echo "</select> $req";
break;
default:
echo "<input onchange=\"fieldChanged()\" type=\"text\" name=\"$fname\" value=\"{$user[$fname]}\" />$req";
break;
}
echo '</td>';
} else {
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>';
}
/*
echo "<form name=\"personalform\" id=\"personal_form\">\n";
echo "<input type=\"hidden\" name=\"users_id\" value=\"{$u['id']}\" />";
echo "<table>\n";
<tr><td style="text-align: right" colspan="2"><input type="submit" value="<?=i18n("Save")?>" /></td></tr>
echo "<tr>\n";
item($u, 'firstname');
item($u, 'lastname');
echo "</tr>\n";
echo "<tr>\n";
item($u, 'salutation');
echo "<td></td><td></td>";
echo "</tr>\n";
echo "<tr>\n";
item($u, 'address');
item($u, 'city');
echo "</tr>\n";
echo "<tr>\n";
item($u, 'address2');
if(in_array('province', $fields)) {
echo '<td>'.i18n($config['provincestate']).': </td>';
echo '<td>';
emit_province_selector("province",$u['province'],"onchange=\"fieldChanged()\"");
if(in_array('province', $required)) echo REQUIREDFIELD;
echo '</td>';
} else {
echo '<td></td><td></td>';
}
echo "</tr>\n";
echo "<tr>\n";
item($u, 'postalcode');
echo "<td></td><td></td>";
echo "</tr>\n";
echo "<tr>";
item($u, 'phonehome');
item($u, 'phonecell');
echo "</tr>\n";
<tr><td style="text-align: left" colspan="2"><h4>Address</h4><hr /></td></tr>
echo "<tr>\n";
item($u, 'organization');
item($u, 'phonework');
echo "</tr>";
echo "<tr>\n";
item($u, 'fax');
if(in_array('sex', $fields)) {
echo '<td>'.i18n('Gender').': </td>';
echo '<td>';
echo "<select name=\"sex\">";
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";
echo "</select>";
if(in_array('sex', $required)) echo REQUIREDFIELD;
echo '</td>';
} else {
echo '<td></td><td></td>';
}
echo "</tr>";
*/
echo "<tr>\n";
item($u, 'firstaid');
item($u, 'cpr');
echo "</tr>";
echo "<tr>\n";
if(in_array('lang', $fields)) {
echo '<td>'.i18n('Preferred Lang').': </td>';
echo '<td>';
echo "<select name=\"lang\">";
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>";
if(in_array('lang', $required)) echo REQUIREDFIELD;
echo '</td>';
} else {
echo '<td></td><td></td>';
}
echo "<td></td><td></td>";
echo "</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>
<tr><?=item($u, 'Salutation', 'salutation')?></tr>
<tr><?=item($u, 'First Name', 'firstname')?></tr>
<tr><?=item($u, 'Last Name', 'lastname')?></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"><h4>Phone</h4><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"><h4>Misc</h4><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"><h4>Organization</h4><hr /></td></tr>
<tr><?=item($u, 'Organization Name', 'organization')?></tr>
<tr><?=item($u, 'Phone', 'firstaid')?></tr>
<tr><?=item($u, 'Fax', 'fax')?></tr>
echo "<tr><td colspan=\"4\"><hr /></td></tr>";
<?
echo "</table>";
@ -369,12 +345,43 @@ if(array_key_exists('committee', $u['roles'])) {
echo '</table>';
}
?>
<input type="submit" value="<?=i18n("Save Personal Information")?>" />
</form>
</center>
<br />
echo "<input type=\"submit\" onclick=\"personal_save();return false;\" value=\"".i18n("Save Personal Information")."\" />\n";
echo "</form>";
<script type="text/javascript">
$().ready(function() {
$("#personalform").validate({
rules: {
firstname: {
required: true,
},
lastname: {
required: true,
}
},
messages: {
firstname: {
required: "<?=i18n('Please enter your first (given) name')?>",
},
lastnmae: {
required: "<?=i18n('Please enter your last name')?>",
}
},
submitHandler: function() {
personal_save();
return false;
},
cancelHandler: function() {
personal_save();
return false;
}
});
echo "<br />";
<?
if($_SESSION['embed'] != true) {
send_footer();