diff --git a/user_personal.php b/user_personal.php index b158fd07..76656207 100644 --- a/user_personal.php +++ b/user_personal.php @@ -33,6 +33,37 @@ exit; } + $user_personal_fields = array( + 'firstname' => array('name' => 'First Name'), + 'lastname' => array('name' => 'Last Name'), + 'email' => array('name' => 'Email Address'), + 'username' => array('name' => 'Username'), + 'password' => array('name' => 'Password'), + 'address' => array('name' => 'Address 1'), + 'address2' => array('name' => 'Address 2'), + 'city' => array('name' => 'City'), + 'province' => array('name' => 'Province'), + 'organization' => array('name' => 'Organization'), + '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' => 'Postal Code', + 'regexp' => '^(([A-Z][0-9][A-Z] [0-9][A-Z][0-9])|([0-9]{5}))$', + 'format' => '\'ANA NAN\' or \'NNNNN\'',), + +); + + + /* See if there is an edit request */ $eid = intval($_GET['edit']); @@ -53,6 +84,7 @@ /* Load the fields the user can edit, and theones that are required */ $fields = array(); $required = array(); + $errorfields = array(); foreach($u['types'] as $t) { $fields = array_merge($fields, user_personal_fields($t)); @@ -68,9 +100,24 @@ if($_POST['action']=="save") { + $save = true; /* Set values */ foreach($fields as $f) { - $u[$f] = mysql_escape_string(stripslashes($_POST[$f])); + $u[$f] = stripslashes($_POST[$f]); + } + + foreach($u as $f=>$v) { + if($v == '') 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'], $v)) { + /* Bad */ + $save = false; + $errorfields[] = $f; + } + } } if(!array_key_exists('username', $u) || $u['username'] == '') { @@ -97,7 +144,10 @@ $q=mysql_query("SELECT id FROM users WHERE email='$em' AND id!='{$u['id']}'"); if(mysql_num_rows($q) > 0) { $notice = 'email_exists'; - } else { + $save = false; + } + + if($save == true) { user_save($u); if($_SESSION['last_page'] == 'committee_management') { header("location: {$config['SFIABDIRECTORY']}/admin/committees.php"); @@ -138,7 +188,14 @@ break; } -if($eid == false) { + foreach($errorfields as $f) { + echo error(i18n('\'%1\' must use the format: %2', + array(i18n($user_personal_fields[$f]['name']), + $user_personal_fields[$f]['format']))); + } + if(count($errorfields)) { + echo error(i18n('Information will not be saved until the above errors are corrected')); + } else if ($eid == false) { //output the current status $newstatus=user_personal_info_status($u); if($newstatus!='complete') @@ -155,12 +212,16 @@ if(count($u['types']) > 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:').' '.$roles); } -function item($user, $text, $fname, $subtext='') +function item($user, $fname, $subtext='') { global $fields, $required; + global $errorfields; + global $user_personal_fields; if(in_array($fname, $fields)) { - echo '
'; echo " | |
'.i18n('Province').': | '; echo ''; @@ -209,20 +270,20 @@ item($u, "Address 2", 'address2'); } echo " |
"; echo " | |
'; echo " |