Ejemplo n.º 1
0
    public function configAction()
    {
        $table = new Application_Model_DbTable_Config();
        $rowset = $table->fetchAll();

        $config = array();
        foreach ($rowset as $row) {
            $config[$row->code] = $row->value;
        }

        $form = new Application_Form_Config();
        $form->populate($config);

        $request = $this->getRequest();

        if ($request->isPost() && $form->isValid($request->getPost())) {
            $values = $form->getValues();

            $table->update(
                array('value' => $values['can_vote']),
                $table->getAdapter()->quoteInto('code = "can_vote"')
            );

            $table->update(
                array('value' => $values['can_enter']),
                $table->getAdapter()->quoteInto('code = "can_enter"')
            );

            return $this->_redirect('/admin/config?msg=config-saved');
        }

        $this->view->form = $form;
    }
Ejemplo n.º 2
0
 public function configAction()
 {
     $configForm = new Application_Form_Config();
     $configForm->setAction($this->_helper->url->url());
     $languageSelect = $configForm->getElement('language');
     $languageSelect->setMultiOptions($this->_helper->language->getLanguages(false));
     $loggedUser = $this->_helper->session->getCurrentUser();
     $isSuperAdminLogged = $loggedUser->getRoleId() === Tools_Security_Acl::ROLE_SUPERADMIN;
     $this->view->isSuperAdmin = $isSuperAdminLogged;
     if ($this->getRequest()->isPost()) {
         if (!$isSuperAdminLogged) {
             $configForm->removeElement('suLogin');
             $configForm->removeElement('suPassword');
             $configForm->removeElement('canonicalScheme');
             $configForm->removeElement('recapthaPublicKey');
             $configForm->removeElement('recapthaPrivateKey');
         } else {
             //initializing current superadmin user
             $userTable = new Application_Model_DbTable_User();
             $userMapper = Application_Model_Mappers_UserMapper::getInstance();
         }
         if ($configForm->isValid($this->getRequest()->getParams())) {
             //proccessing language changing
             $selectedLang = $languageSelect->getValue();
             if ($selectedLang != $this->_helper->language->getCurrentLanguage()) {
                 $this->_helper->language->setLanguage($selectedLang);
                 $languageSelect->setMultiOptions($this->_helper->language->getLanguages(false));
             }
             if ($isSuperAdminLogged) {
                 $newPass = $configForm->getElement('suPassword')->getValue();
                 $newLogin = $configForm->getElement('suLogin')->getValue();
                 $adminDataModified = false;
                 // checking if there is new su password
                 if (!empty($newPass) && md5($newPass) !== $loggedUser->getPassword()) {
                     $loggedUser->setPassword($newPass);
                     $adminDataModified = true;
                 }
                 // checking if su email has been changed
                 if ($newLogin != $loggedUser->getEmail()) {
                     $usersWithSuchEmail = $userTable->fetchAll($userTable->getAdapter()->quoteInto('email = ?', $newLogin));
                     if (!$usersWithSuchEmail->count()) {
                         $loggedUser->setEmail($newLogin);
                         $adminDataModified = true;
                     }
                 }
                 if ($adminDataModified === true) {
                     if (!$userMapper->save($loggedUser)) {
                         unset($newLogin);
                     }
                 }
             }
             //$showMemberOnlyPages = intval($configForm->getElement('memPagesInMenu')->getValue());
             //proccessing form to db
             $config = $configForm->getValues();
             if (isset($newLogin)) {
                 $config['adminEmail'] = $newLogin;
             }
             if ($config['smtpPassword'] === null && null === $this->getRequest()->getParam('smtpPassword', null)) {
                 unset($config['smtpPassword']);
             }
             if ($config['inlineEditor'] !== $this->_helper->config->getConfig('inlineEditor')) {
                 $this->_helper->cache->clean(false, false, array('Widgets_AbstractContent'));
             }
             $this->_configMapper->save($config);
             $this->_helper->flashMessenger->addMessage('Setting saved');
         } else {
             if ($configForm->proccessErrors()) {
                 $this->_helper->flashMessenger->addMessage('Some fields are wrong');
             }
         }
         if (false !== ($actions = $this->_request->getParam('actions', false))) {
             $removeActions = array();
             foreach ($actions as $action) {
                 if (isset($action['delete']) && $action['delete'] === "true") {
                     array_push($removeActions, $action['id']);
                     continue;
                 }
                 Application_Model_Mappers_EmailTriggersMapper::getInstance()->save($action);
             }
             if (!empty($removeActions)) {
                 Application_Model_Mappers_EmailTriggersMapper::getInstance()->delete($removeActions);
             }
         }
     } else {
         // loading config from db
         $currentConfig = $this->_configMapper->getConfig();
         if (!isset($currentConfig['language'])) {
             $currentConfig['language'] = $this->_helper->language->getCurrentLanguage();
         }
         if (is_array($currentConfig) && !empty($currentConfig)) {
             $configForm->setOptions($currentConfig);
         }
     }
     if ($isSuperAdminLogged) {
         $suadmin = Application_Model_Mappers_UserMapper::getInstance()->findByRole(Tools_Security_Acl::ROLE_SUPERADMIN);
         $suadminEmail = $suadmin->getEmail();
         $suPassword = $suadmin->getPassword();
         $configForm->getElement('suLogin')->setValue($suadminEmail);
         $configForm->getElement('suPassword')->setValue($suPassword);
     }
     $this->view->messages = $this->_helper->flashMessenger->getMessages();
     $this->view->configForm = $configForm;
 }