diff --git a/include/ajax.forms.php b/include/ajax.forms.php index ee95f722a439807fcbd8eb5d2c12e89d9d1f51cb..27fac6672d9c831a9ec8962f7121c043434b61ee 100644 --- a/include/ajax.forms.php +++ b/include/ajax.forms.php @@ -39,10 +39,10 @@ class DynamicFormsAjaxAPI extends AjaxController { function _getUserForms() { $static = new Form(array( 'name' => new TextboxField(array( - 'label'=>'Full Name', 'configuration'=>array('size'=>40)) + 'label'=>'Full Name', 'required'=>true, 'configuration'=>array('size'=>40)) ), 'email' => new TextboxField(array( - 'label'=>'Default Email', 'configuration'=>array( + 'label'=>'Default Email', 'required'=>true, 'configuration'=>array( 'validator'=>'email', 'size'=>40)) ), )); @@ -86,11 +86,10 @@ class DynamicFormsAjaxAPI extends AjaxController { } $data = $static->getClean(); - $user->first = $data['first']; - $user->last = $data['last']; + $user->name = $data['name']; $user->default_email->address = $data['email']; - $user->save(); $user->default_email->save(); + $user->save(); // Save custom data foreach ($custom_data as $cd) diff --git a/include/class.user.php b/include/class.user.php index b6bc367f3392e0cf069e3c85fafb7a5d59f86781..8a01c159c3e80fa1f3c39c5a4890b204b8f51903 100644 --- a/include/class.user.php +++ b/include/class.user.php @@ -112,6 +112,23 @@ class User extends UserModel { } return $data; } + + function save($refetch=false) { + // Drop commas and reorganize the name without them + $parts = array_map('trim', explode(',', $this->name)); + switch (count($parts)) { + case 2: + // Assume last, first --or-- last suff., first + $this->name = $parts[1].' '.$parts[0]; + // XXX: Consider last, first suff. + break; + case 3: + // Assume last, first, suffix, write 'first last suffix' + $this->name = $parts[1].' '.$parts[0].' '.$parts[2]; + break; + } + return parent::save($refetch); + } } User::_inspect(); @@ -146,7 +163,10 @@ class PersonsName { } function getLastFirst() { - return $this->parts['last'].', '.$this->parts['first']; + $name = $this->parts['last'].', '.$this->parts['first']; + if ($this->parts['suffix']) + $name .= ', '.$this->parts['suffix']; + return $name; } function __toString() { @@ -159,12 +179,6 @@ class PersonsName { static function splitName($name) { $results = array(); - // If there is a comma in the name, reverse the name - if (mb_strpos($name, ',' !== false)) { - list($last, $first) = explode(',', $name); - $name = $first.' '.$last; - } - $r = explode(' ', $name); $size = count($r); diff --git a/include/staff/templates/user-info.tmpl.php b/include/staff/templates/user-info.tmpl.php index b07e19561ab80ca066e756a488965affc529da2a..3cfb9d467d206c6ae2ba37c31a745fc744fd8e21 100644 --- a/include/staff/templates/user-info.tmpl.php +++ b/include/staff/templates/user-info.tmpl.php @@ -8,6 +8,7 @@ if (!data.length) { form.closest('.dialog').hide(); $('#overlay').hide(); + location.reload(); } else { form.closest('.dialog').empty().append(data); }