UserAuth->getData(); if ($user['type'] != 'admin') { $this->_noType = true; $this->actions = array('edit' => 'doEdit', 'cancel' => 'doBack', 'update' => 'doUpdate',); $DBObj->id = intval($user['id']); } parent::DB_Grid($Doc, $DBObj); if (count($this->DBObj->getTypes()) < 2 ){ $this->functionalFields[] = 'type'; } } function _bindFormFields($form) { $form = parent::_bindFormFields($form); $rePas = false; $elements = $form->getElements(); foreach ($elements as $key => $elem) { switch ($elem->getName()) { case 'type': $form->removeElement('type'); if (!$this->_noType) { $type = Form::createElement('select', 'type', 'Type', $this->DBObj->getTypes() ); $type->setValue($this->DBObj->getData('type')); $form->insertElementBefore($type, $elements[$key + 1]->getName()) ; } break; case 'email': $form->addRule('email', 'Email address is required', 'required'); $form->addRule('email', 'Email address is required', 'required', null, 'client'); $form->addRule('email', 'Wrong email address', 'email'); $form->addRule('email', 'Wrong email address', 'email', null, 'client'); break; case 'password': $form->removeElement('password'); $password = array(); $password[] =& Form::createElement('password', 'password', null, array('size' => 30, 'autocomplete' => 'off')); $password[] =& Form::createElement('static', 'password_static', '', ''); $form->addGroup($password, 'password', 'Password', null, false); $re_password = array(); $re_password[] =& Form::createElement('password', 're_password', null, array('size' => 30, 'autocomplete' => 'off')); $re_password[] =& Form::createElement('static', 're_password_static', '', ''); $form->addGroup($re_password, 're_password', 'Confirm Password', null, false); unset($re_password, $password); break; default: $form->addRule($elem->getName(), ucwords($elem->getName()).' is required', 'required'); $form->addRule($elem->getName(), ucwords($elem->getName()).' is required', 'required', null, 'client'); break; } } $form->updateElementAttr(array('login', 'email', 'name'), 'size="30"'); $form->addFormRule(array(&$this, 'validForm')); $form->setConstants(array('password' => '', 're_password' => '' )); return $form; } function validForm($fields) { $error_bool = false; $error = array(); if (!$this->DBObj->isLoginUnique($fields['login'])){ $error_bool = true; $error = array_merge($error, array('login' => 'The login must be unique')); } if ($fields['password'] != $fields['re_password']) { $error_bool = true; $error = array_merge($error, array('password' => 'Password and Confirm password entries do not match')); } if ($error_bool == false) { return true; } else { return $error; } } function _getNewForm() { $form = parent::_getNewForm(); $form->addGroupRule('password', array( 'password' => array( array('Password is required', 'required'), array('Password is required', 'required', null, 'client'), ), )); $form->addGroupRule('re_password', array( 're_password' => array( array('Confirm password is required', 'required'), array('Confirm password is required', 'required', null, 'client'), ), )); $form->setDefaults(array('type' => 'sub_admin')); return $form; } function _getEditForm() { $form = parent::_getEditForm(); $pass = $form->getElement('password'); $pasEls = $pass->getElements(); $pasEls[1]->setValue('
Leave blank to use current'); $re_pass = $form->getElement('re_password'); $re_pasEls = $re_pass->getElements(); $re_pasEls[1]->setValue('
Leave blank to use current'); return $form; } function _doListBind(&$DB_List) { $DB_List->bind(); $DB_List->removeCol('password'); $DB_List->removeCol('email'); return true; } function doDelete() { if ($this->DBObj->delete()){ Session::setData(CURR_PAGE, 'msg', $this->DBObj->itemName.' deleted'); }else { Session::setData(CURR_PAGE, 'error', 'Cannot delete last '.$this->DBObj->itemName); } $this->doBack(); } } ?>