From 4ba55b274cdd0ba0ba107fb1e8233423b426ec68 Mon Sep 17 00:00:00 2001 From: dave Date: Sun, 8 Aug 2010 09:09:46 +0000 Subject: [PATCH] Updates to user_personal to use form validator --- tableeditor.css | 4 ++ user_personal.php | 157 +++++++++++++++++++++++++++------------------- 2 files changed, 96 insertions(+), 65 deletions(-) diff --git a/tableeditor.css b/tableeditor.css index 06285be9..d41bd0dd 100644 --- a/tableeditor.css +++ b/tableeditor.css @@ -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; } diff --git a/user_personal.php b/user_personal.php index b79fad25..683c09b2 100644 --- a/user_personal.php +++ b/user_personal.php @@ -23,13 +23,13 @@ */ ?> 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 "
"; - display_messages(); - echo "

".i18n("Personal Information")."

"; - echo "
"; - } else { - send_header("Personal Information for {$u['firstname']} {$u['lastname']}", - array("Main" => "user_main.php") - ,"edit_profile" - ); - } +//send the header +display_messages(); +echo "

".i18n("Personal Information")."

"; +echo "
"; $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 ''; 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 ""; @@ -274,42 +271,45 @@ function item(&$u, $label, $fname, $type='textbox') " /> -

Address


+Address
*/ ?> -
-
- - - + + +

Name


+ + - - + + */ +?> - + - + */ +?> - + - + */ +?> - + - + @@ -317,8 +317,9 @@ function item(&$u, $label, $fname, $type='textbox') echo "
Name
Address
" />
" />

Phone


Phone
" />
" />

Misc


Other Information
" />
" />

Organization


Organization
"; + /* Committee specific fields */ -if(array_key_exists('committee', $u['roles'])) { +if(array_key_exists('committee', $u['roles']) && false ) { echo ""; echo "\n"; @@ -349,27 +350,58 @@ if(array_key_exists('committee', $u['roles'])) { " /> -
-
".i18n("Email (Private)").":