예제 #1
0
 /**
  * validate help item sef_url within the help_version
  * @return bool
  */
 public function validate()
 {
     global $db;
     // check for an sef url field.  If it exists make sure it's valid and not a duplicate
     //this needs to check for SEF URLS being turned on also: TODO
     if (property_exists($this, 'sef_url') && !in_array('sef_url', $this->do_not_validate)) {
         if (empty($this->sef_url)) {
             $this->makeSefUrl();
         }
         $this->validates['is_valid_sef_name']['sef_url'] = array();
         $this->validates['uniqueness_of']['sef_url'] = array();
     }
     // safeguard again loc data not being pass via forms...sometimes this happens when you're in a router
     // mapped view and src hasn't been passed in via link to the form
     if (isset($this->id) && empty($this->location_data)) {
         $loc = $db->selectValue($this->tablename, 'location_data', 'id=' . $this->id);
         if (!empty($loc)) {
             $this->location_data = $loc;
         }
     }
     // run the validation as defined in the datatypes
     if (!isset($this->validates)) {
         return true;
     }
     $messages = array();
     $post = empty($_POST) ? array() : $_POST;
     foreach ($this->validates as $validation => $field) {
         foreach ($field as $key => $value) {
             $fieldname = is_numeric($key) ? $value : $key;
             $opts = is_numeric($key) ? array() : $value;
             $sql = "`" . $fieldname . "`='" . $this->{$fieldname} . " AND help_version_id='" . $this->help_version_id . "'";
             if (!empty($this->id)) {
                 $sql .= ' AND id != ' . $this->id;
             }
             $ret = $db->countObjects($this->tablename, $sql);
             if ($ret > 0) {
                 $ret = array_key_exists('message', $opts) ? $opts['message'] : ucwords($fieldname) . ' "' . $this->{$fieldname} . '" is already in use.';
             } else {
                 $ret = true;
             }
             if (!is_bool($ret)) {
                 $messages[] = $ret;
                 expValidator::setErrorField($fieldname);
                 unset($post[$fieldname]);
             }
         }
     }
     if (count($messages) >= 1) {
         expValidator::failAndReturnToForm($messages, $post);
     }
 }
예제 #2
0
 public function update_userpassword()
 {
     if (empty($this->params['id'])) {
         expValidator::failAndReturnToForm(gt('You must specify the user whose password you want to change'), $this->params);
     }
     if (empty($this->params['new_password1'])) {
         expValidator::setErrorField('new_password1');
         expValidator::failAndReturnToForm(gt('You must specify a new password for this user.'), $this->params);
     }
     if (empty($this->params['new_password2'])) {
         expValidator::setErrorField('new_password2');
         expValidator::failAndReturnToForm(gt('You must confirm the password.'), $this->params);
     }
     $u = new user($this->params['id']);
     $ret = $u->setPassword($this->params['new_password1'], $this->params['new_password2']);
     if (is_string($ret)) {
         expValidator::setErrorField('new_password1');
         $this->params['new_password1'] = '';
         $this->params['new_password2'] = '';
         expValidator::failAndReturnToForm($ret, $this->params);
     } else {
         $u->save(true);
     }
     flash('message', gt('Password reset for user') . ' ' . $u->username);
     expHistory::back();
 }