Beispiel #1
0
 /**
  * Function to create a new account.
  *
  * This function creates a new account, admin user for the account, admin user's profile and sets default values for
  * the admin user. It also sends mail to the user and the admin.
  * @param array $userData   array of account informatio.
  * @return int $accountId   id of the account created.
  */
 public function registerUser($userData)
 {
     $modelWep = new Model_Wep();
     $data = array();
     $data['email'] = $userData['email'];
     $data['first_name'] = $userData['first_name'];
     $data['last_name'] = $userData['last_name'];
     $data['account_identifier'] = $userData['account_identifier'];
     $data['user_name'] = $userData['user_name'];
     $data['password'] = $userData['password'];
     $data['org_name'] = trim($userData['org_name']);
     $data['org_address'] = $userData['org_address'];
     //Save Organisation Info
     $account['name'] = $data['org_name'];
     $account['address'] = $data['org_address'];
     $account['username'] = trim($data['account_identifier']);
     $account['uniqid'] = md5(date('Y-m-d H:i:s'));
     $accountId = $modelWep->insertRowsToTable('account', $account);
     //Save User Info
     $user['user_name'] = trim($data['user_name']);
     $user['password'] = md5($data['password']);
     $user['role_id'] = 1;
     $user['email'] = $data['email'];
     $user['account_id'] = $accountId;
     $user['status'] = 1;
     $user_id = $modelWep->insertRowsToTable('user', $user);
     //Save User Profile
     $admin['first_name'] = $data['first_name'];
     $admin['last_name'] = $data['last_name'];
     $admin['user_id'] = $user_id;
     $admin_id = $modelWep->insertRowsToTable('profile', $admin);
     //Create defaults
     $defaults = new Model_Defaults();
     $defaults->createDefaults($data, $accountId);
     //Send notification
     $notification = new Model_Notification();
     $notification->sendRegistrationNotifications($data);
     return $accountId;
 }
Beispiel #2
0
 /**
  * Function to register an organisation by Superadmin
  */
 public function registerAction()
 {
     $auth = Zend_Auth::getInstance();
     if ($auth->hasIdentity()) {
         $is_admin = false;
         $identity = $auth->getIdentity();
         if ($identity->role == "superadmin") {
             $this->view->blockManager()->disable('partial/primarymenu.phtml');
             $this->view->blockManager()->disable('partial/add-activity-menu.phtml');
             $this->view->blockManager()->disable('partial/usermgmtmenu.phtml');
             $this->view->blockManager()->disable('partial/published-list.phtml');
             $this->view->blockManager()->enable('partial/superadmin-menu.phtml');
             $this->view->blockManager()->enable('partial/dashboard.phtml');
             $is_admin = true;
         }
     }
     $defaultFieldsValues = new Iati_WEP_AccountDefaultFieldValues();
     $default['field_values'] = $defaultFieldsValues->getDefaultFields();
     $defaultFieldGroup = new Iati_WEP_AccountDisplayFieldGroup();
     $default['fields'] = $defaultFieldGroup->getProperties();
     $form = new Form_Wep_Accountregister();
     $form->add($default);
     if ($this->getRequest()->isPost()) {
         try {
             $data = $this->getRequest()->getPost();
             $model = new Model_Wep();
             if (!$form->isValid($data)) {
                 $form->populate($data);
             } else {
                 //Save Account Info
                 $account['name'] = $data['organisation_name'];
                 $account['address'] = $data['organisation_address'];
                 $account['username'] = $data['organisation_username'];
                 $account['uniqid'] = md5(date('Y-m-d H:i:s'));
                 $account_id = $model->insertRowsToTable('account', $account);
                 //Save User Info
                 $user['user_name'] = trim($data['organisation_username']) . "_admin";
                 $user['password'] = md5($data['password']);
                 $user['role_id'] = 1;
                 $user['email'] = $data['email'];
                 $user['account_id'] = $account_id;
                 $user['status'] = 1;
                 $user_id = $model->insertRowsToTable('user', $user);
                 //Save User Profile
                 $admin['first_name'] = $data['first_name'];
                 $admin['middle_name'] = $data['middle_name'];
                 $admin['last_name'] = $data['last_name'];
                 $admin['user_id'] = $user_id;
                 $admin_id = $model->insertRowsToTable('profile', $admin);
                 //Save Default Fields
                 $default = new Model_Defaults();
                 $default->createDefaults($data, $account_id);
                 $privilegeFields['resource'] = serialize($defaultKey);
                 $privilegeFields['owner_id'] = $account_id;
                 $privilegeFieldId = $model->insertRowsToTable('Privilege', $privilegeFields);
                 //Send notification
                 $data['user_name'] = $user['user_name'];
                 $notification = new Model_Notification();
                 $notification->sendRegistrationNotifications($data);
                 $this->_helper->FlashMessenger->addMessage(array('message' => "Account successfully registered."));
                 $this->_redirect('admin/list-organisation');
             }
         } catch (Exception $e) {
             print $e->getMessage();
         }
     }
     // Populate form with basic recommended default groups.
     $basic['default_fields'] = Iati_WEP_AccountDisplayFieldGroup::$defaults;
     $form->populate($basic);
     $this->view->form = $form;
     $this->view->blockManager()->disable('partial/primarymenu.phtml');
 }
Beispiel #3
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;
 }