/** * The default action * * Displays the admin dashboard * * @return void */ public function indexAction() { $notes = new Model_Note(); $this->view->notes = $notes->getUsersNotes(); $content = new Model_Page(); $this->view->pages = $content->getCurrentUsersPages('create_date DESC', 5); $user = new Model_User(); $identity = $user->getCurrentUser(); $form = new Admin_Form_User(); $form->onlyIndexIndexActionElements(); $form->setAction($this->baseUrl . '/admin/user/update-my-account'); $firstName = $form->getElement('first_name'); $firstName->setValue($identity->first_name); $lastName = $form->getElement('last_name'); $lastName->setValue($identity->last_name); $email = $form->getElement('email'); $email->setValue($identity->email); $submit = $form->getElement('submitAdminUserForm'); $submit->setLabel($this->view->getTranslation('Update My Account')); $displayGroup = $form->getDisplayGroup('adminUserGroup'); $displayGroup->setLegend($this->view->getTranslation('My Account'))->setAttrib('class', 'formColumn'); $this->view->form = $form; }
public function saveAction() { $messages = array(); $isValidEmail = true; $session = new Zend_Session_Namespace('data'); $form = new Admin_Form_User(); $table = new Tri_Db_Table('user'); $data = $this->_getAllParams(); if ($data['email'] && (!isset($data['id']) || !$data['id'])) { $row = $table->fetchRow(array('email = ?' => $data['email'])); if ($row) { $isValidEmail = false; $messages[] = 'Email existing'; } } if (!isset($data['id']) || !$data['id']) { $form->getElement('password')->setAllowEmpty(false); } if ($form->isValid($data) && $isValidEmail) { if (!$form->image->receive()) { $messages[] = 'Image fail'; } $data = $form->getValues(); if (!$form->image->getValue()) { unset($data['image']); } if (!$data['password']) { unset($data['password']); } if (isset($data['id']) && $data['id'] && Zend_Auth::getInstance()->hasIdentity()) { $row = $table->find($data['id'])->current(); $row->setFromArray($data); $id = $row->save(); } else { unset($data['id']); $row = $table->createRow($data); $id = $row->save(); $session->attempt = 0; $data['password'] = $this->_getParam('password'); $this->view->data = $data; $mail = new Zend_Mail(APP_CHARSET); $mail->setBodyHtml($this->view->render('user/welcome.phtml')); $mail->setSubject($this->view->translate('Welcome')); $mail->addTo($data['email'], $data['name']); $mail->send(); $result = $this->login($data['email'], $data['password']); if ($result->isValid()) { if ($session->url) { $this->_helper->_flashMessenger->addMessage('Success'); $url = $session->url; $session->url = null; $this->_redirect($url); } } } $this->_helper->_flashMessenger->addMessage('Success'); $identity = Zend_Auth::getInstance()->getIdentity(); if ($identity->id == $id) { $this->_redirect('user/edit'); } if ($identity->role == 'institution') { $this->_redirect('user'); } $this->_redirect('dashboard'); } $messages[] = 'Error'; $this->view->messages = $messages; $this->view->form = $form; $this->render('form'); }
public function addAction() { $request = $this->getRequest(); $form = new Admin_Form_User(); $options = $request->getPost(); if ($request->isPost()) { /*---- email validation ----*/ $form->getElement('email')->addValidators(array(array('Db_NoRecordExists', false, array('table' => 'user', 'field' => 'email', 'messages' => 'Email already exists, Please choose another email address.')))); /*-------------------------*/ if ($form->isValid($options)) { $model = new Application_Model_User(); $options['dob'] = $options['year'] . "-" . $options['month'] . "-" . $options['day']; $options['status'] = 'active'; $options['password'] = md5($options['password']); $options['preferredLanguage'] = 'English'; //$options['userLevelId'] =$options['userLevelId']; //$model->setOptions($options); // $id=$model->save(); /*--------- Upload image START -------------------------*/ $upload = new Zend_File_Transfer_Adapter_Http(); if ($upload->isValid('image')) { $upload->setDestination("media/picture/profile/"); try { $upload->receive('image'); } catch (Zend_File_Transfer_Exception $e) { $msg = $e->getMessage(); } $upload->setOptions(array('useByteString' => false)); $file_name = $upload->getFileName('image'); $cardImageTypeArr = explode(".", $file_name); $ext = strtolower($cardImageTypeArr[count($cardImageTypeArr) - 1]); $target_file_name = "profile_" . $id . ".{$ext}"; $targetPath = 'media/picture/profile/' . $target_file_name; $filterFileRename = new Zend_Filter_File_Rename(array('target' => $targetPath, 'overwrite' => true)); $filterFileRename->filter($file_name); $options['image'] = $target_file_name; /*--- Generate Thumbnail ---*/ $thumb = Base_Image_PhpThumbFactory::create($targetPath); $thumb->resize(100, 100); $thumb->save($targetPath = 'media/picture/profile/thumb_' . $target_file_name); $model->setOptions($options); $model->setId($id); $id = $model->save(); } /*--------- Upload image END -------------------------*/ //$options['dob'] = $options['year']."-".$options['month']."-".$options['day']; //$model->setOptions($options); //$model->save(); $user = new Application_Model_User($options); $user_id = $user->save(); if ($user_id > 0) { /*---- default permission settings ----*/ $user->setDefaultPermissions($user_id); $user->setDefaultJournal($user_id); } $this->view->msg = "'User has been inserted successfully!"; $form->reset(); } else { $form->reset(); $form->populate($options); } } $this->view->form = $form; }
/** * Add action * * Add a new user * * @return void */ public function createAction() { $form = new Admin_Form_User(); $elmUserName = $form->getElement('name'); $elmUserName->addValidators(array(array('UsernameExistsNot', true))); $form->onlyCreateActionElements(); $u = new Model_User(); $form->setModel($u); if ($form->validatePost()) { $password = $form->getValue('password'); $userName = $form->getValue('name'); $result = $form->create(array('password' => md5($password))); if ($result) { $this->_redirect('admin/user/open/username/' . $userName); } } $this->view->breadcrumbs['Create User'] = $this->baseUrl . '/admin/user/create'; $form->setAction($this->baseUrl . '/admin/user/create'); $this->view->form = $form; $this->view->toolbarLinks['Add to my bookmarks'] = $this->baseUrl . '/admin/index/bookmark/url/admin_user_create'; }