public function editAction()
 {
     $orgInfoModel = new Default_Model_Organisationinfo();
     $getorgData = $orgInfoModel->getorgrecords();
     $sitepreferencemodel = new Default_Model_Sitepreference();
     $activerecordArr = $sitepreferencemodel->getActiveRecord();
     $timezoneid = !empty($activerecordArr[0]['timezoneid']) ? $activerecordArr[0]['timezoneid'] : '';
     $popConfigPermission = array();
     $organisationHead = array();
     if (!empty($getorgData)) {
         $orgdata = '';
         $auth = Zend_Auth::getInstance();
         if ($auth->hasIdentity()) {
             $loginUserId = $auth->getStorage()->read()->id;
             $loginUserRole = $auth->getStorage()->read()->emprole;
             $loginUserGroup = $auth->getStorage()->read()->group_id;
         }
         if (sapp_Global::_checkprivileges(TIMEZONE, $loginUserGroup, $loginUserRole, 'add') == 'Yes') {
             array_push($popConfigPermission, 'timezone');
         }
         if (sapp_Global::_checkprivileges(COUNTRIES, $loginUserGroup, $loginUserRole, 'add') == 'Yes') {
             array_push($popConfigPermission, 'country');
         }
         if (sapp_Global::_checkprivileges(STATES, $loginUserGroup, $loginUserRole, 'add') == 'Yes') {
             array_push($popConfigPermission, 'state');
         }
         if (sapp_Global::_checkprivileges(CITIES, $loginUserGroup, $loginUserRole, 'add') == 'Yes') {
             array_push($popConfigPermission, 'city');
         }
         if (sapp_Global::_checkprivileges(EMPLOYEE, $loginUserGroup, $loginUserRole, 'add') == 'Yes') {
             array_push($popConfigPermission, 'employee');
         }
         $msgarray = array();
         $flag = 'true';
         $id = $this->getRequest()->getParam('id');
         $callval = $this->getRequest()->getParam('call');
         $deptModel = new Default_Model_Departments();
         $deptform = new Default_Form_departments();
         $statesmodel = new Default_Model_States();
         $citiesmodel = new Default_Model_Cities();
         $countriesModel = new Default_Model_Countries();
         $statesmodel = new Default_Model_States();
         $citiesmodel = new Default_Model_Cities();
         $timezonemodel = new Default_Model_Timezone();
         $businessunitsmodel = new Default_Model_Businessunits();
         $orgInfoModel = new Default_Model_Organisationinfo();
         $employeeModal = new Default_Model_Employee();
         $allTimezoneData = $timezonemodel->fetchAll('isactive=1', 'timezone')->toArray();
         $allCountriesData = $countriesModel->fetchAll('isactive=1', 'country')->toArray();
         $allStatesData = $statesmodel->fetchAll('isactive=1', 'state')->toArray();
         $allCitiesData = $citiesmodel->fetchAll('isactive=1', 'city')->toArray();
         $allBusinessunitsData = $businessunitsmodel->fetchAll('isactive=1', 'unitname')->toArray();
         $deptData = array();
         $deptform->setAttrib('action', BASE_URL . 'departments/edit');
         $country = $getorgData[0]['country'];
         if (isset($_POST['country'])) {
             $country = $_POST['country'];
         }
         $state = $getorgData[0]['state'];
         if (isset($_POST['state'])) {
             $state = $_POST['state'];
         }
         $city = $getorgData[0]['city'];
         if (isset($_POST['city'])) {
             $city = $_POST['city'];
         }
         $deptform->setDefault('timezone', $timezoneid);
         $address = $getorgData[0]['address1'];
         $organisationHead = $employeeModal->getCurrentOrgHead();
         if (isset($country) && $country != 0 && $country != '') {
             $deptform->setDefault('country', $country);
             $statesData = $statesmodel->getBasicStatesList($country);
             foreach ($statesData as $res) {
                 $deptform->state->addMultiOption($res['state_id_org'], utf8_encode($res['state']));
             }
             if (isset($state) && $state != 0 && $state != '') {
                 $deptform->setDefault('state', $state);
             }
         }
         if (isset($state) && $state != 0 && $state != '') {
             $citiesData = $citiesmodel->getBasicCitiesList($state);
             foreach ($citiesData as $res) {
                 $deptform->city->addMultiOption($res['city_org_id'], utf8_encode($res['city']));
             }
             if (isset($city) && $city != 0 && $city != '') {
                 $deptform->setDefault('city', $city);
             }
         }
         if (isset($address) && $address != '') {
             $deptform->address1->setValue($address);
         }
         if (is_numeric($id) && $id > 0) {
             $data = $deptModel->getSingleDepartmentData($id);
             if (!empty($data)) {
                 $deptform->setAttrib('action', BASE_URL . 'departments/edit/id/' . $id);
                 $managementUsersData = $deptModel->getDepartmenttHead($data['depthead']);
                 foreach ($managementUsersData as $mgmtdata) {
                     $deptform->depthead->addMultiOption($mgmtdata['user_id'], $mgmtdata['userfullname']);
                 }
                 $deptform->populate($data);
                 $deptform->setDefault('depthead', $data['depthead']);
                 $deptform->submit->setLabel('Update');
                 $deptform->state->clearMultiOptions();
                 $deptform->city->clearMultiOptions();
                 $deptform->state->addMultiOption('', utf8_encode("Select State"));
                 $deptform->city->addMultiOption('', utf8_encode("Select City"));
                 $countryId = $data['country'];
                 if (isset($_POST['country'])) {
                     $countryId = $_POST['country'];
                 }
                 $stateId = $data['state'];
                 if (isset($_POST['state'])) {
                     $stateId = $_POST['state'];
                 }
                 $cityId = $data['city'];
                 if (isset($_POST['city'])) {
                     $cityId = $_POST['city'];
                 }
                 if ($countryId != '') {
                     $statesData = $statesmodel->getBasicStatesList($countryId);
                     foreach ($statesData as $res) {
                         $deptform->state->addMultiOption($res['state_id_org'], utf8_encode($res['state']));
                     }
                     $deptform->setDefault('country', $countryId);
                     $deptform->setDefault('state', $stateId);
                 }
                 if ($stateId != '') {
                     $citiesData = $citiesmodel->getBasicCitiesList($stateId);
                     foreach ($citiesData as $res) {
                         $deptform->city->addMultiOption($res['city_org_id'], utf8_encode($res['city']));
                     }
                     $deptform->setDefault('city', $cityId);
                 }
                 if ($data["startdate"] != '') {
                     $st_date = sapp_Global::change_date($data["startdate"], 'view');
                     $deptform->setDefault('start_date', $st_date);
                 }
                 $this->view->ermsg = '';
                 $this->view->datarr = $data;
             } else {
                 $this->view->ermsg = 'nodata';
             }
         } else {
             if ($id != '') {
                 $this->view->ermsg = 'nodata';
             } else {
                 $managementUsersData = $deptModel->getDepartmenttHead('');
                 foreach ($managementUsersData as $mgmtdata) {
                     $deptform->depthead->addMultiOption($mgmtdata['user_id'], $mgmtdata['userfullname']);
                 }
             }
         }
         $this->view->deptData = sizeof($deptData);
         $this->view->form = $deptform;
         if (!empty($allBusinessunitsData) && !empty($allCountriesData) && !empty($allStatesData) && !empty($allCitiesData) && !empty($allTimezoneData)) {
             $this->view->configuremsg = '';
         } else {
             $this->view->configuremsg = 'notconfigurable';
         }
         if (empty($allCountriesData)) {
             $msgarray['country'] = 'Countries are not configured yet.';
             $flag = 'false';
         }
         if (empty($allStatesData)) {
             $msgarray['state'] = 'States are not configured yet.';
             $flag = 'false';
         }
         if (empty($allCitiesData)) {
             $msgarray['city'] = 'Cities are not configured yet.';
             $flag = 'false';
         }
         if (empty($allBusinessunitsData)) {
             $msgarray['unitid'] = 'Business units are not added yet.';
             $flag = 'false';
         }
         if (empty($allTimezoneData)) {
             $msgarray['timezone'] = 'Time zones are not configured yet.';
             $flag = 'false';
         }
         $this->view->msgarray = $msgarray;
         if ($this->getRequest()->getPost()) {
             $deptname = trim($this->_request->getParam('deptname'));
             $unitid = $this->_request->getParam('unitid');
             if ($deptname != '' && $unitid != '') {
                 if (!preg_match('/^[a-zA-Z.\\- ?]+$/', $deptname)) {
                     $msgarray['deptname'] = "Please enter valid department name.";
                     $flag = 'false';
                 } else {
                     $checkExists = $deptModel->checkExistance($deptname, $unitid, $id);
                     if ($checkExists != 0) {
                         $msgarray['deptname'] = "Department name already exists.";
                         $flag = 'false';
                     }
                 }
             } else {
                 $flag = 'false';
             }
             $start_date = $this->_request->getParam('start_date', null);
             $start_date = sapp_Global::change_date($start_date, 'database');
             if ($deptform->isValid($this->_request->getPost()) && $flag == 'true') {
                 $deptname = $this->_request->getParam('deptname');
                 $deptcode = $this->_request->getParam('deptcode');
                 $description = $this->_request->getParam('description');
                 $country = $this->_request->getParam('country');
                 $state = intval($this->_request->getParam('state'));
                 $city = $this->_request->getParam('city');
                 $address1 = $this->_request->getParam('address1');
                 $address2 = $this->_request->getParam('address2');
                 $address3 = $this->_request->getParam('address3');
                 $unitid = $this->_request->getParam('unitid');
                 $timezone = $this->_request->getParam('timezone');
                 $depthead = $this->_request->getParam('depthead');
                 $deptcodeExistance = $deptModel->checkCodeDuplicates($deptcode, $id);
                 if (!$deptcodeExistance) {
                     $date = new Zend_Date();
                     $actionflag = '';
                     $tableid = '';
                     $data = array('deptname' => trim($deptname), 'deptcode' => trim($deptcode), 'description' => trim($description), 'startdate' => $start_date != '' ? $start_date : NULL, 'country' => trim($country), 'state' => trim($state), 'city' => trim($city), 'address1' => trim($address1), 'address2' => trim($address2), 'address3' => trim($address3), 'timezone' => trim($timezone), 'unitid' => $unitid, 'depthead' => trim($depthead), 'modifiedby' => $loginUserId, 'modifieddate' => $date->get('yyyy-MM-dd HH:mm:ss'));
                     if ($id != '') {
                         $where = array('id=?' => $id);
                         $actionflag = 2;
                     } else {
                         $data['createdby'] = $loginUserId;
                         $data['createddate'] = $date->get('yyyy-MM-dd HH:mm:ss');
                         $data['isactive'] = 1;
                         $where = '';
                         $actionflag = 1;
                     }
                     $Id = $deptModel->SaveorUpdateDepartmentsUnits($data, $where);
                     /* Updating business unit and department for org head*/
                     $emp_data = array('businessunit_id' => $unitid, 'modifiedby' => $loginUserId, 'modifieddate' => gmdate("Y-m-d H:i:s"));
                     $emp_where = array('user_id=?' => $depthead);
                     if ($Id == 'update') {
                         $tableid = $id;
                         $emp_data['department_id'] = $id;
                         $this->_helper->getHelper("FlashMessenger")->addMessage("Department updated successfully.");
                     } else {
                         $tableid = $Id;
                         $emp_data['department_id'] = $Id;
                         $this->_helper->getHelper("FlashMessenger")->addMessage("Department added successfully.");
                     }
                     $employeeModal->SaveorUpdateEmployeeData($emp_data, $emp_where);
                     $menuID = DEPARTMENTS;
                     $result = sapp_Global::logManager($menuID, $actionflag, $loginUserId, $tableid);
                     $this->_redirect('departments');
                 } else {
                     $msgarray['message'] = 'A Department, with the given code, already exists.';
                     $msgarray['msgtype'] = 'error';
                     $this->view->messages = $msgarray;
                 }
             } else {
                 $messages = $deptform->getMessages();
                 foreach ($messages as $key => $val) {
                     foreach ($val as $key2 => $val2) {
                         $msgarray[$key] = $val2;
                         break;
                     }
                     if (empty($allCountriesData)) {
                         $msgarray['country'] = 'Countries are not configured yet.';
                     }
                     if (empty($allStatesData)) {
                         $msgarray['state'] = 'States are not configured yet.';
                     }
                     if (empty($allCitiesData)) {
                         $msgarray['city'] = 'Cities are not configured yet.';
                     }
                     if (empty($allBusinessunitsData)) {
                         $msgarray['unitid'] = 'Business units are not added yet.';
                     }
                     if (empty($allTimezoneData)) {
                         $msgarray['timezone'] = 'Time zones are not configured yet.';
                     }
                 }
                 $this->view->msgarray = $msgarray;
             }
         }
     } else {
         $orgdata = 'noorgdata';
         $this->view->orgdata = $orgdata;
     }
     $this->view->popConfigPermission = $popConfigPermission;
     $this->view->organisationHead = $organisationHead;
 }
 public function addAction()
 {
     $auth = Zend_Auth::getInstance();
     if ($auth->hasIdentity()) {
         $loginUserId = $auth->getStorage()->read()->id;
         $loginuserRole = $auth->getStorage()->read()->emprole;
         $loginuserGroup = $auth->getStorage()->read()->group_id;
     }
     $popConfigPermission = array();
     if (sapp_Global::_checkprivileges(CURRENCY, $loginuserGroup, $loginuserRole, 'add') == 'Yes') {
         array_push($popConfigPermission, 'currency');
     }
     if (sapp_Global::_checkprivileges(TIMEZONE, $loginuserGroup, $loginuserRole, 'add') == 'Yes') {
         array_push($popConfigPermission, 'timezone');
     }
     $callval = $this->getRequest()->getParam('call');
     if ($callval == 'ajaxcall') {
         $this->_helper->layout->disableLayout();
     }
     $systempreferenceform = new Default_Form_systempreference();
     $dateformatidmodel = new Default_Model_Dateformat();
     $timeformatidmodel = new Default_Model_Timeformat();
     $currencyidmodel = new Default_Model_Currency();
     $systempreferencemodel = new Default_Model_Sitepreference();
     $activerecordArr = $systempreferencemodel->getActiveRecord();
     $msgarray = array();
     $timezonemodel = new Default_Model_Timezone();
     $allTimezoneData = $timezonemodel->fetchAll('isactive=1', 'timezone')->toArray();
     $date_formats_arr = $dateformatidmodel->getAllDateFormats();
     $time_formats_arr = $timeformatidmodel->fetchAll()->toArray();
     if (sizeof($date_formats_arr) > 0) {
         $this->view->date_formats_arr = $date_formats_arr;
     } else {
         $msgarray['dateformatid'] = 'Date Formats are not configured yet';
     }
     if (sizeof($time_formats_arr) > 0) {
         $this->view->time_formats_arr = $time_formats_arr;
     } else {
         $msgarray['timeformatid'] = 'Time Formats are not configured yet';
     }
     $currencyidmodeldata = $currencyidmodel->getCurrencyList();
     $systempreferenceform->currencyid->addMultiOption('', 'Select Currency');
     if (sizeof($currencyidmodeldata) > 0) {
         foreach ($currencyidmodeldata as $currencyidres) {
             $systempreferenceform->currencyid->addMultiOption($currencyidres['id'], utf8_encode($currencyidres['currency']));
         }
     } else {
         $msgarray['currencyid'] = 'Currency is not configured yet';
     }
     $passworddataArr = $systempreferencemodel->getPasswordData();
     $systempreferenceform->passwordid->addMultiOption('', 'Select Password Preference');
     foreach ($passworddataArr as $passwordres) {
         $systempreferenceform->passwordid->addMultiOption($passwordres['id'], utf8_encode($passwordres['passwordtype']));
     }
     if (sizeof($allTimezoneData) > 0) {
         foreach ($allTimezoneData as $timezoneidres) {
             $systempreferenceform->timezoneid->addMultiOption($timezoneidres['id'], utf8_encode($timezoneidres['timezone'] . ' [' . $timezoneidres['timezone_abbr'] . ']'));
         }
     } else {
         $msgarray['timezoneid'] = 'Time Zone is not configured yet.';
     }
     $systempreferenceform->setAttrib('action', DOMAIN . 'sitepreference/add');
     $this->view->form = $systempreferenceform;
     $this->view->passworddata = $passworddataArr;
     $this->view->msgarray = $msgarray;
     $this->view->popConfigPermission = $popConfigPermission;
     if (count($activerecordArr) > 0) {
         $this->view->nodata = "nodata";
     }
     if ($this->getRequest()->getPost()) {
         $result = $this->save($systempreferenceform);
         $this->view->msgarray = $result;
     }
 }
Esempio n. 3
0
 /**
  * This function is used to write site constants to a php file.
  */
 public static function generateSiteConstants()
 {
     $filename = Zend_Registry::get('siteconstant_file_path');
     $site_model = new Default_Model_Sitepreference();
     $site_data = $site_model->getActiveRecord();
     if (!empty($site_data)) {
         $site_data = $site_data[0];
         $utc = new DateTimeZone('UTC');
         $dt = new DateTime('now', $utc);
         $current_tz = new DateTimeZone($site_data['tz_value']);
         $tzoffset = $current_tz->getOffset($dt);
         $offset = self::formatOffset($tzoffset);
         $site_content = "<?php\n           defined('DATEFORMAT_PHP') || define('DATEFORMAT_PHP','" . $site_data['date_format'] . "');\n           defined('DATEFORMAT_MYSQL') || define('DATEFORMAT_MYSQL','" . $site_data['mysql_dateformat'] . "');\n           defined('DATEFORMAT_JS') || define('DATEFORMAT_JS','" . $site_data['js_dateformat'] . "');\n           defined('DATE_DESCRIPTION') || define('DATE_DESCRIPTION','" . $site_data['date_description'] . "');\n           defined('TIME_FORMAT') || define('TIME_FORMAT','" . $site_data['time_format'] . "');   \n           defined('TIMEZONE_OFFSET') || define('TIMEZONE_OFFSET','" . $offset . "');   \n           defined('CURRENCY_FORMAT') || define('CURRENCY_FORMAT','" . $site_data['currency'] . "');\n           defined('PASSWORD_FORMAT') || define('PASSWORD_FORMAT','" . $site_data['passwordtype'] . "');\n        ?>";
         try {
             $handle = fopen($filename, "w+");
             fwrite($handle, trim($site_content));
             fclose($handle);
         } catch (Exception $e) {
         }
     }
 }