/application/modules/geocontexter/controllers/UserEditController.php
PHP | 226 lines | 154 code | 39 blank | 33 comment | 24 complexity | 7fc4707041ad1cc7e09b9a4a154362b4 MD5 | raw file
- <?php
- /**
- * GeoContexter
- * @link http://code.google.com/p/geocontexter/
- * @package GeoContexter
- */
- /**
- * user edit
- *
- * @package GeoContexter
- * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
- * @author Armand Turpel <geocontexter@gmail.com>
- * @version $Rev: 828 $ / $LastChangedDate: 2011-02-27 10:30:28 +0100 (Sun, 27 Feb 2011) $ / $Author: armand.turpel $
- */
- class Geocontexter_UserEditController extends Mozend_Controller_Action_AbstractAdmin
- {
- public function preDispatch()
- {
- // set view. we keep the index view instead of add
- //
- $this->_helper->viewRenderer->setScriptAction('index');
- $this->view->partialData['active_page'] = 'edit';
- $this->view->timezone_identifiers = DateTimeZone::listIdentifiers();
- $this->view->error = array();
- $this->view->user_result = array();
- $languages = new Geocontexter_Model_LanguagesGet;
- $params = array('enable' => 'true');
- $lang_result = $languages->get( $params );
- if($lang_result instanceof Mozend_ModelError)
- {
- return $this->error( $lang_result->getErrorString(), __file__, __line__ );
- }
- else
- {
- $this->view->languages = $lang_result;
- }
- }
- public function indexAction()
- {
- $this->view->id_user = $this->id_user =$this->request->getParam('id_user');
- if((null === $this->id_user) || (0 == $this->id_user))
- {
- $this->id_user = 0;
- $this->view->headTitle('Edit user', 'PREPEND');
- }
- else
- {
- // get current context
- //
- $user = new Geocontexter_Model_UserGet;
- $params = array('id_user' => $this->id_user);
- $result = $user->get( $params );
- if($result instanceof Mozend_ModelError)
- {
- return $this->error( $result->getErrorString(), __file__, __line__ );
- }
- else
- {
- $this->view->headTitle('Edit user ' . $result['user_forename'] . ' ' . $result['user_lastname'], 'PREPEND');
- $this->view->user_result = $result;
- }
- }
- }
- /**
- * add new group action
- */
- public function updateAction()
- {
- // check on cancel action
- //
- $cancel = $this->request->getPost('cancel');
- if($cancel !== null)
- {
- $this->_redirect($this->view->adminAreaToken .
- '/geocontexter/user/index');
- }
- $params = array();
- $this->view->error = array();
- $this->view->id_user = $this->id_user = $this->request->getPost('id_user');
- $this->view->user_result['user_login'] = $this->request->getPost('user_login');
- $this->view->user_result['id_status'] =
- $params['id_status'] = $this->request->getPost('id_status');
- $this->view->user_result['id_group'] =
- $params['id_group'] = $this->request->getPost('id_group');
- $this->view->user_result['user_lastname'] =
- $params['user_lastname'] = $this->request->getPost('user_lastname');
- $this->view->user_result['user_forename'] =
- $params['user_forename'] = $this->request->getPost('user_forename');
- $this->view->user_result['user_lang'] =
- $params['lang'] = $this->request->getPost('user_lang');
- $this->view->user_result['user_email'] =
- $params['user_email'] = $this->request->getPost('user_email');
- $this->view->user_result['user_url'] =
- $params['user_url'] = $this->request->getPost('user_url');
- $this->view->user_result['user_timezone'] =
- $params['user_timezone'] = $this->request->getPost('user_timezone');
- $this->view->user_result['user_description'] =
- $params['description'] = $this->request->getPost('user_description');
- $user_password = $this->request->getPost('user_password');
- $user_password2 = $this->request->getPost('user_password2');
- if(!empty($user_password))
- {
- if($user_password != $user_password2)
- {
- $this->view->error[] = 'Both user password must be equal';
- }
- else
- {
- $params['user_password'] = md5($user_password);
- }
- }
- // if status is trash then check if there is no related project
- //
- if($params['id_status'] == 0)
- {
- $user_related_content_check = new Geocontexter_Model_UserRelatedContentCheck;
- $result = $user_related_content_check->check( $this->id_user );
- if($result instanceof Mozend_ModelError)
- {
- return $this->error( $result->getErrorString(), __file__, __line__ );
- }
- else if(count($result) > 0)
- {
- $message = 'Couldnt move this user to trash. There are some records related to this user.';
- $this->view->error[] = $message;
- $this->view->headTitle($message, 'PREPEND');
- return;
- }
- }
- // basic check if user dosent modify its own status
- // or modify other administrators account
- //
- if(false === $this->_check( $params ))
- {
- $this->view->error[] = 'Unexpected error';
- }
- if(empty($params['user_lastname']))
- {
- $this->view->error[] = 'User lastname is empty';
- }
- if(empty($params['user_forename']))
- {
- $this->view->error[] = 'User forename is empty';
- }
- if(empty($params['user_email']))
- {
- $this->view->error[] = 'User email is empty';
- }
- if(count($this->view->error) > 0)
- {
- $this->view->headTitle('Error: User data failure', 'PREPEND');
- return;
- }
- $user = new Geocontexter_Model_UserUpdate;
- // add item attribute
- //
- $result = $user->update( array('id_user' => $this->id_user,
- 'data' => $params ));
- if($result instanceof Mozend_ModelError)
- {
- return $this->error( $result->getErrorString(), __file__, __line__ );
- }
- else
- {
- $this->_redirect($this->view->adminAreaToken .
- '/geocontexter/user/index');
- }
- }
- private function _check( $params )
- {
- $identity = $this->request->getParam('identity');
- // cannot modify ouwn account status
- //
- if(($params['id_status'] < 200) &&
- ($identity->id_user == $params['id_user']))
- {
- return false;
- }
- // cannot modify account of user of the same or higher rights group
- //
- if(($identity->id_group > 0) && ($identity->id_group >= $params['id_group']))
- {
- return false;
- }
- return true;
- }
- }