Exemplo n.º 1
0
 public function savedepartments()
 {
     $auth = Zend_Auth::getInstance();
     if ($auth->hasIdentity()) {
         $loginUserId = $auth->getStorage()->read()->id;
         $loginuserRole = $auth->getStorage()->read()->emprole;
         $loginuserGroup = $auth->getStorage()->read()->group_id;
     }
     $appraisalquestionsmodel = new Default_Model_Appraisalquestions();
     $deptModel = new Default_Model_Departments();
     $msgarray = array();
     $errorflag = 'true';
     $bunit_id = $this->_request->getParam('bunit_id');
     $department_arr = $this->_request->getParam('department');
     $address_arr = $this->_request->getParam('address');
     if (!empty($department_arr)) {
         $departmentArr = array_count_values($department_arr);
         for ($i = 0; $i < sizeof($department_arr); $i++) {
             if ($department_arr[$i] == '') {
                 $msgarray['dept_name'][$i] = 'Please enter department.';
                 $errorflag = 'false';
             } else {
                 if (!preg_match('/^[a-zA-Z0-9.\\- ?]+$/', $department_arr[$i])) {
                     $msgarray['dept_name'][$i] = 'Please enter valid department.';
                     $errorflag = 'false';
                 } else {
                     if ($i > 0 && $departmentArr[$department_arr[$i]] > 1) {
                         $msgarray['dept_name'][$i] = 'Please enter different department.';
                         $errorflag = 'false';
                     } else {
                         $isDeptExist = $deptModel->checkDuplicateDeptName($department_arr[$i]);
                         if ($isDeptExist[0]['count'] > 0) {
                             $msgarray['dept_name'][$i] = ' Department name already exists.';
                             $msgarray['bunit_id'] = $bunit_id;
                             $errorflag = 'false';
                         }
                     }
                 }
             }
             if ($address_arr[$i] == '') {
                 $msgarray['address_name'][$i] = 'Please enter street address.';
                 $errorflag = 'false';
             }
         }
         $msgarray['deptsize'] = sizeof($department_arr);
     }
     if ($errorflag == 'true') {
         try {
             $menumodel = new Default_Model_Menu();
             $orgInfoModel = new Default_Model_Organisationinfo();
             $systempreferencemodel = new Default_Model_Sitepreference();
             $organisationData = $orgInfoModel->getOrganisationInfo();
             $sitePreferenceData = $systempreferencemodel->SitePreferanceData();
             $deptModel = new Default_Model_Departments();
             $actionflag = 1;
             $tableid = '';
             $where = '';
             $date = new Zend_Date();
             for ($i = 0; $i < sizeof($department_arr); $i++) {
                 if (strlen(trim($department_arr[$i])) > 3) {
                     $deptCode = strtoupper(substr(trim($department_arr[$i]), 0, 4));
                 } else {
                     $deptCode = strtoupper(trim($department_arr[$i]));
                 }
                 $data = array('deptname' => trim($department_arr[$i]), 'deptcode' => $deptCode, 'startdate' => NULL, 'country' => !empty($organisationData) ? $organisationData[0]['country'] : NULL, 'state' => !empty($organisationData) ? $organisationData[0]['state'] : NULL, 'city' => !empty($organisationData) ? $organisationData[0]['city'] : NULL, 'address1' => $address_arr[$i], 'timezone' => !empty($sitePreferenceData) ? $sitePreferenceData[0]['timezoneid'] : NULL, 'unitid' => $bunit_id, 'createdby' => $loginUserId, 'createddate' => $date->get('yyyy-MM-dd HH:mm:ss'), 'modifiedby' => $loginUserId, 'modifieddate' => $date->get('yyyy-MM-dd HH:mm:ss'));
                 $Id = $deptModel->SaveorUpdateDepartmentsUnits($data, $where);
                 $tableid = $Id;
                 $menuID = DEPARTMENTS;
                 $result = sapp_Global::logManager($menuID, $actionflag, $loginUserId, $tableid);
             }
             $wizard_model = new Default_Model_Wizard();
             $wizardData = $wizard_model->getWizardData();
             $wizardarray = array('departments' => 2, 'modifiedby' => $loginUserId, 'modifieddate' => gmdate("Y-m-d H:i:s"));
             if ($wizardData['site_config'] == 2 && $wizardData['org_details'] == 2 && $wizardData['servicerequest'] == 2) {
                 $wizardarray['iscomplete'] = 2;
             }
             $wizard_model->SaveorUpdateWizardData($wizardarray, '');
             $this->_helper->getHelper("FlashMessenger")->addMessage("Departments added successfully.");
             $this->_redirect('wizard/configureunitsanddepartments');
         } catch (Exception $e) {
             $msgarray['pa_category_id'] = "Something went wrong, please try again.";
             return $msgarray;
         }
     } else {
         return $msgarray;
     }
 }