Пример #1
0
 public function settingsAction()
 {
     if (Simplified_Model_Simplified::isSimplified()) {
         $this->_redirect('simplified/default/settings');
     }
     $identity = Zend_Auth::getInstance()->getIdentity();
     $model = new Model_Wep();
     $modelRegistryInfo = new Model_RegistryInfo();
     $defaultFieldsValues = $model->getDefaults('default_field_values', 'account_id', $identity->account_id);
     $default['field_values'] = $defaultFieldsValues->getDefaultFields();
     $defaultFieldGroup = $model->getDefaults('default_field_groups', 'account_id', $identity->account_id);
     $default['fields'] = $defaultFieldGroup->getProperties();
     $form = new Form_Wep_EditDefaults();
     $form->edit($default);
     $registryInfoData = $modelRegistryInfo->getOrgRegistryInfo($identity->account_id);
     if ($registryInfoData) {
         $form->populate($registryInfoData->toArray());
     }
     if ($_POST) {
         try {
             $data = $this->getRequest()->getPost();
             if (!$form->isValid($data)) {
                 $this->_helper->FlashMessenger->addMessage(array('error' => "You have some error in your data"));
                 $form->populate($data);
             } else {
                 //Trim
                 $data['default_reporting_org'] = trim($data['default_reporting_org']);
                 $data['reporting_org_ref'] = trim($data['reporting_org_ref']);
                 //Get default fields values for reporting org
                 $defaultFieldsValues = $model->getDefaults('default_field_values', 'account_id', $identity->account_id);
                 $defaults = $defaultFieldsValues->getDefaultFields();
                 $reportingOrgOld['@ref'] = $defaults['reporting_org_ref'];
                 $reportingOrgOld['@type'] = $defaults['reporting_org_type'];
                 $reportingOrgOld['@xml_lang'] = $defaults['reporting_org_lang'];
                 $reportingOrgOld['text'] = $defaults['reporting_org'];
                 $reportingOrgOld = serialize($reportingOrgOld);
                 //Get values from settings form
                 $reportingOrgNew['@ref'] = $data['reporting_org_ref'];
                 $reportingOrgNew['@type'] = $data['reporting_org_type'];
                 $reportingOrgNew['@xml_lang'] = $data['reporting_org_lang'];
                 $reportingOrgNew['text'] = $data['default_reporting_org'];
                 $reportingOrgNew = serialize($reportingOrgNew);
                 //Update Publishing Info
                 $modelRegistryInfo->updateRegistryInfoFromData($data);
                 //Update Default Values
                 $defaults = new Model_Defaults();
                 $defaults->updateDefaults($data);
                 if (isset($_GET['btn'])) {
                     $save = $_GET['btn'];
                 }
                 //If reporting org change
                 if ($reportingOrgNew != $reportingOrgOld) {
                     if ($save == "ok") {
                         $model->updateIatiIdentifiers($data['reporting_org_ref']);
                         $model->settingsChange();
                         //Check push_to_registry for activity
                         $modelPublished = new Model_Published();
                         $activityPublish = $modelPublished->isPushedToRegistry($identity->account_id);
                         if ($activityPublish) {
                             $this->pushToRegistry('Published');
                         }
                         //Check push_to_registry for organisation data
                         $modelOrganisationPublished = new Model_OrganisationPublished();
                         $organisationPublish = $modelOrganisationPublished->isPushedToRegistry($identity->account_id);
                         if ($organisationPublish) {
                             $this->pushToRegistry('OrganisationPublished');
                         }
                     }
                 }
                 $this->_helper->FlashMessenger->addMessage(array('message' => "Settings successfully updated."));
                 if ($identity->role == 'superadmin') {
                     $this->_redirect('admin/dashboard');
                 } else {
                     if ($identity->role == 'admin') {
                         $this->_redirect('wep/dashboard');
                     }
                 }
             }
         } catch (Exception $e) {
             print $e;
         }
     }
     $this->view->blockManager()->enable('partial/dashboard.phtml');
     $this->view->form = $form;
 }