Ejemplo n.º 1
0
 /**
  * Edit user
  */
 public function userAction()
 {
     $Profiles = new Application_Model_Profiles();
     $ProfilesMeta = new Application_Model_ProfilesMeta();
     $request = $this->getRequest();
     $profile_id = $request->getParam('id', null);
     $profile = $Profiles->getProfileByField('id', $profile_id);
     $this->view->sidebar_editprofile = $profile;
     // attach sidebar box
     Zend_Registry::get('hooks')->attach('hook_view_sidebar', 5, function () {
         echo Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer')->view->render('/_sidebar/editprofile.phtml');
     });
     $edit_user_form = new Application_Form_AdminUser();
     $this->view->edit_user_form = $edit_user_form;
     if ($request->isPost() && $profile_id && $edit_user_form->isValid($_POST)) {
         $elements = $edit_user_form->getElements();
         // standard db fields
         foreach ($elements as $element) {
             $element_id = $element->getId();
             // if column exists - save to main profiles table
             if (isset($profile->{$element_id})) {
                 $profile->{$element_id} = $element->getValue();
             }
         }
         // specific fields
         if ($edit_user_form->getValue('password1')) {
             $hash = new Application_Plugin_Phpass();
             $profile->password = $hash->HashPassword($edit_user_form->getValue('password1'));
         }
         $profile->relogin_request = 1;
         $profile->save();
         // notifications
         $bulk_notifications = array();
         foreach ($elements as $element) {
             $element_id = $element->getId();
             if (strstr($element_id, 'notification_email') !== false) {
                 $bulk_notifications[$element_id] = $element->getValue();
             }
         }
         $ProfilesMeta->metaUpdate('bulk_notifications', json_encode($bulk_notifications), $profile->id);
         // save all the rest to meta
         $elements = $edit_user_form->getElements();
         $system_elements = array('identifier', 'formsubmit', 'profile_privacy', 'default_privacy', 'screen_name', 'language', 'password1', 'password2', 'activationkey', 'is_hidden', 'csrf', 'role', 'name', 'email', 'id');
         // foreach meta elements
         foreach ($elements as $element) {
             $element_id = $element->getId();
             $element_value = $element->getValue();
             // skip system & readonly fields
             if (in_array($element_id, $system_elements)) {
                 continue;
             }
             // skip notifications
             if (strstr($element_id, 'notification_email') !== false) {
                 continue;
             }
             // custom date element?
             if ($element->helper == 'formDate') {
                 if ($element_value) {
                     $dateval = date("Y-m-d H:i:s", strtotime($element_value['day'] . '-' . $element_value['month'] . '-' . $element_value['year']));
                     $ProfilesMeta->metaUpdate($element_id, $dateval, $profile->id);
                 } else {
                     $ProfilesMeta->deleteProfilesMetaKey($profile->id, $element_id);
                 }
                 continue;
             }
             $ProfilesMeta->metaUpdate($element_id, $element_value, $profile->id);
         }
         Application_Plugin_Alerts::success($this->view->translate('User updated'));
         // flush url
         $this->redirect('admin/user/id/' . $profile_id);
     }
 }
 /**
  * Edit profile
  */
 public function editAction()
 {
     $Profiles = new Application_Model_Profiles();
     $this->buildMenu();
     $profile_form = new Application_Form_Profile();
     $this->view->profile_form = $profile_form;
     $request = $this->getRequest();
     if ($request->isPost() && $profile_form->isValid($_POST)) {
         Application_Plugin_Common::redirectOnDemoAccount();
         $profile = $Profiles->getProfileRow();
         // do not foreach this!
         $profile->screen_name = $profile_form->getValue('screen_name');
         $profile->profile_privacy = $profile_form->getValue('profile_privacy');
         $profile->save();
         $ProfilesMeta = new Application_Model_ProfilesMeta();
         $elements = $profile_form->getElements();
         $system_elements = array('identifier', 'formsubmit', 'profile_privacy', 'screen_name', 'csrf', 'name', 'email', 'id');
         // foreach meta elements
         foreach ($elements as $element) {
             $element_id = $element->getId();
             $element_value = $element->getValue();
             // skip system & readonly fields
             if (in_array($element_id, $system_elements)) {
                 continue;
             }
             // custom date element?
             if ($element->helper == 'formDate') {
                 if ($element_value) {
                     $dateval = date("Y-m-d H:i:s", strtotime($element_value['day'] . '-' . $element_value['month'] . '-' . $element_value['year']));
                     $ProfilesMeta->metaUpdate($element_id, $dateval, $profile->id);
                 } else {
                     $ProfilesMeta->deleteProfilesMetaKey($profile->id, $element_id);
                 }
                 continue;
             }
             $ProfilesMeta->metaUpdate($element_id, $element_value, $profile->id);
         }
         Application_Plugin_Alerts::success($this->view->translate('Profile updated'));
         // refresh user session
         Zend_Auth::getInstance()->getStorage()->write($Profiles->getProfileRowObject());
         // flush url
         $this->redirect('editprofile/edit');
     }
 }