Ejemplo n.º 1
0
 public function init()
 {
     $registry = Shineisp_Registry::getInstance();
     $auth = Zend_Auth::getInstance();
     if ($auth->hasIdentity()) {
         $logged_user = $auth->getIdentity();
     }
     // Set the custom decorator
     $this->addElementPrefixPath('Shineisp_Decorator', 'Shineisp/Decorator/', 'decorator');
     $translate = Shineisp_Registry::get('Zend_Translate');
     $this->addElement('text', 'firstname', array('filters' => array('StringTrim'), 'required' => true, 'label' => $translate->_('Firstname'), 'decorators' => array('Bootstrap'), 'class' => 'form-control'));
     $this->addElement('text', 'lastname', array('filters' => array('StringTrim'), 'required' => true, 'label' => $translate->_('Lastname'), 'decorators' => array('Bootstrap'), 'class' => 'form-control'));
     // Check if the user is an administrator, if not the select role object will become an hidden field
     if (AdminRoles::isAdministrator($logged_user['user_id'])) {
         $this->addElement('select', 'role_id', array('required' => true, 'label' => $translate->_('Role'), 'decorators' => array('Bootstrap'), 'class' => 'form-control'));
         $this->getElement('role_id')->setAllowEmpty(false)->setRegisterInArrayValidator(false)->setMultiOptions(AdminRoles::getList());
         $this->addElement('select', 'isp_id', array('required' => true, 'label' => $translate->_('Isp Company'), 'decorators' => array('Bootstrap'), 'class' => 'form-control'));
         $this->getElement('isp_id')->setAllowEmpty(false)->setRegisterInArrayValidator(false)->setMultiOptions(Isp::getList());
     } else {
         $this->addElement('hidden', 'role_id');
         $this->addElement('hidden', 'isp_id');
     }
     $this->addElement('text', 'email', array('filters' => array('StringTrim', 'StringToLower'), 'decorators' => array('Bootstrap'), 'validators' => array(array('validator' => 'EmailAddress')), 'required' => true, 'label' => $translate->_('Email'), 'class' => 'form-control'));
     $this->addElement('password', 'password', array('filters' => array('StringTrim'), 'decorators' => array('Bootstrap'), 'validators' => array(array('regex', false, '/^[a-zA-Z0-9\\-\\_\\.\\%\\!\\$]{6,20}$/')), 'label' => $translate->_('Password'), 'class' => 'form-control'));
     $this->addElement('hidden', 'user_id');
 }
Ejemplo n.º 2
0
 /**
  * processAction
  * Update the record previously selected
  * @return unknown_type
  */
 public function processAction()
 {
     $request = $this->getRequest();
     $user_id = $request->getParam('user_id');
     $adminbuttons = array();
     // Get our form and validate it
     $form = $this->getForm('/admin/profile/process');
     // Create the buttons in the edit form
     if (AdminRoles::isAdministrator($this->logged_user['user_id'])) {
         $this->view->buttons = array(array("url" => "#", "label" => $this->translator->translate('Save'), "params" => array('css' => null, 'id' => 'submit')), array("url" => "/admin/profile/list", "label" => $this->translator->translate('List'), "params" => array('css' => null, 'id' => 'submit')));
     } else {
         $this->view->buttons = array(array("url" => "#", "label" => $this->translator->translate('Save'), "params" => array('css' => null, 'id' => 'submit')));
     }
     // Check if the email already exists only when a new record is created
     if (empty($user_id)) {
         $form->getElement('email')->addValidator(new Shineisp_Validate_NoRecordExists('AdminUser', 'email'), true);
     }
     // Check if we have a POST request
     if (!$request->isPost()) {
         return $this->_helper->redirector('index');
     }
     if (!$form->isValid($request->getPost())) {
         // Invalid entries
         $this->view->form = $form;
         $this->view->title = $this->translator->translate("User Account");
         $this->view->description = $this->translator->translate("Some information must be checked again before saving them.");
         return $this->render('applicantform');
         // re-render the login form
     }
     // Save the data
     AdminUser::saveAll($request->getPost(), $request->getParam('user_id'));
     // Redirection
     if (AdminRoles::isAdministrator($this->logged_user['user_id'])) {
         return $this->_helper->redirector('list', 'profile', 'admin');
     } else {
         return $this->_helper->redirector('account', 'profile', 'admin');
     }
 }