public function init() { $this->setMethod('post'); $this->setAttrib('id', 'formid'); $this->setAttrib('name', 'systempreference'); $id = new Zend_Form_Element_Hidden('id'); $dateformatid = new Zend_Form_Element_Select('dateformatid'); $dateformatid->setAttrib('class', 'selectoption'); $dateformatid->setRegisterInArrayValidator(false); $dateformatid->setRequired(true); $dateformatid->addValidator('NotEmpty', false, array('messages' => 'Please select date format.')); $timeformatid = new Zend_Form_Element_Select('timeformatid'); $timeformatid->setAttrib('class', 'selectoption'); $timeformatid->setRegisterInArrayValidator(false); $timeformatid->setRequired(true); $timeformatid->addValidator('NotEmpty', false, array('messages' => 'Please select time format.')); $timezoneid = new Zend_Form_Element_Select('timezoneid'); $timezoneid->setAttrib('class', 'selectoption'); $timezoneid->setRegisterInArrayValidator(false); $timezoneid->setRequired(true); $timezoneid->addValidator('NotEmpty', false, array('messages' => 'Please select time zone preference.')); $timezoneid->addMultiOption('', 'Select Time zone'); $timezoneModal = new Default_Model_Timezone(); $timezoneData = $timezoneModal->fetchAll('isactive=1', 'timezone')->toArray(); foreach ($timezoneData as $data) { $timezoneid->addMultiOption($data['id'], $data['timezone'] . ' [' . $data['timezone_abbr'] . ']'); } $currencyid = new Zend_Form_Element_Select('currencyid'); $currencyid->setAttrib('class', 'selectoption'); $currencyid->setRegisterInArrayValidator(false); $currencyid->setRequired(true); $currencyid->addValidator('NotEmpty', false, array('messages' => 'Please select currency.')); $passwordid = new Zend_Form_Element_Select('passwordid'); $passwordid->setAttrib('class', 'selectoption'); $passwordid->setAttrib('onchange', 'displayPasswordDesc(this)'); $passwordid->setRegisterInArrayValidator(false); $passwordid->setRequired(true); $passwordid->addValidator('NotEmpty', false, array('messages' => 'Please select default password.')); $description = new Zend_Form_Element_Textarea('description'); $description->setAttrib('rows', 10); $description->setAttrib('cols', 50); $description->setAttrib('maxlength', '200'); $submit = new Zend_Form_Element_Submit('submit'); $submit->setAttrib('id', 'submitbutton'); $submit->setLabel('Save'); $this->addElements(array($timezoneid, $id, $dateformatid, $timeformatid, $currencyid, $passwordid, $description, $submit)); $this->setElementDecorators(array('ViewHelper')); }
public function configuresiteAction() { $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(); $msgarray = array(); $wizardpreferenceform = new Default_Form_wizardpreference(); $dateformatidmodel = new Default_Model_Dateformat(); $timeformatidmodel = new Default_Model_Timeformat(); $currencyidmodel = new Default_Model_Currency(); $systempreferencemodel = new Default_Model_Sitepreference(); $orginfomodel = new Default_Model_Organisationinfo(); $identitycodesmodel = new Default_Model_Identitycodes(); $employmentstatusmodel = new Default_Model_Employmentstatus(); $statesmodel = new Default_Model_States(); $citiesmodel = new Default_Model_Cities(); $date_formats_arr = array(); $time_formats_arr = array(); $passworddataArr = array(); $currencynameArr = array(); $countryId = ''; $stateId = ''; $cityId = ''; $new_stateId = ''; $new_cityId = ''; $empstatusids = ''; $timezonemodel = new Default_Model_Timezone(); $wizard_model = new Default_Model_Wizard(); $wizardData = $wizard_model->getWizardData(); /* START * Queries to check whether the configuration are already set. * If set then prepopulate the fields */ $sitepreferencedata = $systempreferencemodel->SitePreferanceData(); $orginfodata = $orginfomodel->getOrganisationInfo(); $empstatusdata = $employmentstatusmodel->getEmploymentStatuslist(); $identitycodedata = $identitycodesmodel->getIdentitycodesRecord(); /* * END - Checking configuration is set or not. */ $allTimezoneData = $timezonemodel->fetchAll('isactive=1', 'timezone')->toArray(); 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'); } try { if (!empty($orginfodata)) { $countryId = isset($orginfodata[0]['country']) ? $orginfodata[0]['country'] : ""; $stateId = isset($orginfodata[0]['state']) ? $orginfodata[0]['state'] : ""; $cityId = isset($orginfodata[0]['city']) ? $orginfodata[0]['city'] : ""; $wizardpreferenceform->organisationid->setValue($orginfodata[0]['id']); } else { if (isset($wizardData['country']) && $wizardData['country'] != 'null') { $countryId = $wizardData['country']; } if (isset($wizardData['state']) && $wizardData['state'] != 'null') { $stateId = $wizardData['state']; } if (isset($wizardData['city']) && $wizardData['city'] != 'null') { $cityId = $wizardData['city']; } } if (count($_POST) > 0) { $countryId = isset($_POST['perm_country']) ? $_POST['perm_country'] : ""; $stateId = isset($_POST['perm_state']) ? $_POST['perm_state'] : ""; $cityId = isset($_POST['perm_city']) ? $_POST['perm_city'] : ""; } $date_formats_arr = $dateformatidmodel->getAllDateFormats(); $time_formats_arr = $timeformatidmodel->fetchAll()->toArray(); $defaultempstatusdata = $employmentstatusmodel->getCompleteStatuslist(); $wizardpreferenceform->passwordid->addMultiOption('', 'Select Password Preference'); $passworddataArr = $systempreferencemodel->getPasswordData(); foreach ($passworddataArr as $passwordres) { $wizardpreferenceform->passwordid->addMultiOption($passwordres['id'], utf8_encode($passwordres['passwordtype'])); } if (sizeof($allTimezoneData) > 0) { foreach ($allTimezoneData as $timezoneidres) { $wizardpreferenceform->timezoneid->addMultiOption($timezoneidres['id'], utf8_encode($timezoneidres['timezone'] . ' [' . $timezoneidres['timezone_abbr'] . ']')); } } else { $msgarray['timezoneid'] = 'Time Zone is not configured yet.'; } if (sizeof($defaultempstatusdata) > 0) { foreach ($defaultempstatusdata as $empstatusres) { $wizardpreferenceform->workcodename->addMultiOption($empstatusres['id'], utf8_encode($empstatusres['employemnt_status'])); } } /* Start * To prepopulate the form if already configured */ if (!empty($sitepreferencedata)) { if (isset($sitepreferencedata[0]['dateformatid'])) { $wizardpreferenceform->setDefault('dateformatid', $sitepreferencedata[0]['dateformatid']); } if (isset($sitepreferencedata[0]['timeformatid'])) { $wizardpreferenceform->setDefault('timeformatid', $sitepreferencedata[0]['timeformatid']); } if (isset($sitepreferencedata[0]['timezoneid'])) { $wizardpreferenceform->setDefault('timezoneid', $sitepreferencedata[0]['timezoneid']); } if (isset($sitepreferencedata[0]['passwordid'])) { $wizardpreferenceform->setDefault('passwordid', $sitepreferencedata[0]['passwordid']); } if (isset($sitepreferencedata[0]['currencyid'])) { $wizardpreferenceform->currencyid->setValue($sitepreferencedata[0]['currencyid']); $currencynameArr = $currencyidmodel->getCurrencyDataByID($sitepreferencedata[0]['currencyid']); } if (!empty($currencynameArr)) { $wizardpreferenceform->currencyname->setValue($currencynameArr[0]['currencyname']); $wizardpreferenceform->currencycode->setValue($currencynameArr[0]['currencycode']); } } if ($countryId != '') { $wizardpreferenceform->setDefault('perm_country', $countryId); $statesData = $statesmodel->getStatesList((int) $countryId); if (!empty($statesData)) { foreach ($statesData as $res) { if ($stateId == $res['id']) { $new_stateId = $res['id'] . '!@#' . utf8_encode($res['state_name']); } $wizardpreferenceform->perm_state->addMultiOption($res['id'] . '!@#' . utf8_encode($res['state_name']), utf8_encode($res['state_name'])); } if (count($_POST) == 0) { $stateId = $new_stateId; } } } if ($stateId != '') { $wizardpreferenceform->setDefault('perm_state', $stateId); $citiesData = $citiesmodel->getCitiesList((int) $stateId); foreach ($citiesData as $res) { if ($cityId == $res['id']) { $new_cityId = $res['id'] . '!@#' . utf8_encode($res['city_name']); } $wizardpreferenceform->perm_city->addMultiOption($res['id'] . '!@#' . utf8_encode($res['city_name']), utf8_encode($res['city_name'])); } if (count($_POST) == 0) { $cityId = $new_cityId; } } if ($cityId != '') { $wizardpreferenceform->setDefault('perm_city', $cityId); } if (!empty($identitycodedata)) { $wizardpreferenceform->empcodeid->setValue($identitycodedata[0]['id']); $wizardpreferenceform->employee_code->setValue($identitycodedata[0]['employee_code']); } if (sizeof($empstatusdata) > 0) { foreach ($empstatusdata as $empstats) { $empstatusids .= $empstats['workcodename'] . ','; } $empstatusids = rtrim($empstatusids, ','); } /* * End - Prepopulating data */ $wizardpreferenceform->setAttrib('action', DOMAIN . 'wizard/configuresite'); $this->view->msgarray = $msgarray; } catch (Exception $e) { $this->view->nodata = "nodata"; } $this->view->form = $wizardpreferenceform; $this->view->date_formats_arr = $date_formats_arr; $this->view->time_formats_arr = $time_formats_arr; $this->view->passworddata = $passworddataArr; $this->view->empstatusids = $empstatusids; if ($this->getRequest()->getPost()) { $result = $this->savesitepreference($wizardpreferenceform, $wizardData); $this->view->msgarray = $result; } $this->view->popConfigPermission = $popConfigPermission; $this->view->wizarddata = $wizardData; $this->view->messages = $this->_helper->flashMessenger->getMessages(); }
public function editAction() { $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(); $msgarray = array(); $id = $this->getRequest()->getParam('id'); $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(); $date_formats_arr = array(); $time_formats_arr = array(); $passworddataArr = array(); $timezonemodel = new Default_Model_Timezone(); $allTimezoneData = $timezonemodel->fetchAll('isactive=1', 'timezone')->toArray(); 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'); } if ($id && $id > 0 && is_numeric($id)) { try { $data = $systempreferencemodel->getsingleSystemPreferanceData($id); $date_formats_arr = $dateformatidmodel->getAllDateFormats(); $time_formats_arr = $timeformatidmodel->fetchAll()->toArray(); $currencyidmodeldata = $currencyidmodel->getCurrencyList(); $systempreferenceform->currencyid->addMultiOption('', 'Select Currency'); if (sizeof($currencyidmodeldata) > 0) { foreach ($currencyidmodeldata as $currencyidres) { $systempreferenceform->currencyid->addMultiOption($currencyidres['id'], utf8_encode($currencyidres['currencytext'])); } } $systempreferenceform->passwordid->addMultiOption('', 'Select Password Preference'); $passworddataArr = $systempreferencemodel->getPasswordData(); 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->populate($data); $systempreferenceform->setDefault('dateformatid', $data['dateformatid']); $systempreferenceform->setDefault('timeformatid', $data['timeformatid']); $systempreferenceform->setDefault('currencyid', $data['currencyid']); $systempreferenceform->setDefault('passwordid', $data['passwordid']); $systempreferenceform->setAttrib('action', DOMAIN . 'sitepreference/edit/id/' . $id); $this->view->msgarray = $msgarray; } catch (Exception $e) { $this->view->nodata = "nodata"; } } else { $this->view->nodata = "nodata"; } $this->view->form = $systempreferenceform; $this->view->date_formats_arr = $date_formats_arr; $this->view->time_formats_arr = $time_formats_arr; $this->view->passworddata = $passworddataArr; if ($this->getRequest()->getPost()) { $result = $this->save($systempreferenceform); $this->view->msgarray = $result; } $this->view->popConfigPermission = $popConfigPermission; }
public function editpopupAction() { Zend_Layout::getMvcInstance()->setLayoutPath(APPLICATION_PATH . "/layouts/scripts/popup/"); $orgInfoModel = new Default_Model_Organisationinfo(); $getorgData = $orgInfoModel->getorgrecords(); $deptModel = new Default_Model_Departments(); if (!empty($getorgData)) { $orgdata = ''; $auth = Zend_Auth::getInstance(); if ($auth->hasIdentity()) { $loginUserId = $auth->getStorage()->read()->id; } $msgarray = array(); $flag = 'true'; $bunitid = $this->getRequest()->getParam('unitId'); $id = intVal($this->getRequest()->getParam('id')); $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(); $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(); $deptModel = new Default_Model_Departments(); $deptform = new Default_Form_departments(); $deptform->setAction(BASE_URL . 'departments/editpopup/id/' . $id . '/unitId/' . $bunitid); $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']; } $address = $getorgData[0]['address1']; //department head data $managementUsersData = $deptModel->getDepartmenttHead(''); foreach ($managementUsersData as $mgmtdata) { $deptform->depthead->addMultiOption($mgmtdata['user_id'], $mgmtdata['userfullname']); } 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); } $close = ''; $controllername = 'departments'; $deptData = array(); if ($id) { $data = $deptModel->getSingleDepartmentData($id); if (!empty($data)) { $deptform->populate($data); $deptform->submit->setLabel('Update'); $st_date = sapp_Global::change_date($data['startdate'], 'view'); $deptform->setDefault('start_date', $st_date); $deptform->setDefault('start_date', $st_date); $deptform->state->clearMultiOptions(); $deptform->city->clearMultiOptions(); $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 != '') { $statesmodel = new Default_Model_States(); $statesData = $statesmodel->getBasicStatesList($countryId); foreach ($statesData as $res) { $deptform->state->addMultiOption($res['state_id_org'], utf8_encode($res['state'])); } } if ($stateId != '') { $citiesmodel = new Default_Model_Cities(); $citiesData = $citiesmodel->getBasicCitiesList($stateId); foreach ($citiesData as $res) { $deptform->city->addMultiOption($res['city_org_id'], utf8_encode($res['city'])); } } $deptform->setDefault('country', $countryId); $deptform->setDefault('state', $stateId); $deptform->setDefault('city', $cityId); $this->view->ermsg = ''; $this->view->datarr = $data; } else { $this->view->ermsg = 'nodata'; } } $bname = $deptModel->getbusinessunitname($bunitid); $this->view->bunitname = $bname; $this->view->deptData = sizeof($deptData); $this->view->form = $deptform; $this->view->unitid = $bunitid; $this->view->controllername = $controllername; 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($allTimezoneData)) { $msgarray['timezone'] = 'Time zones are not configured yet.'; $flag = 'false'; } $this->view->msgarray = $msgarray; if ($this->getRequest()->getPost()) { if ($deptform->isValid($this->_request->getPost()) && $flag == 'true') { $deptname = $this->_request->getParam('deptname'); $deptcode = $this->_request->getParam('deptcode'); $description = $this->_request->getParam('description'); $start_date = $this->_request->getParam('start_date', null); $start_date = sapp_Global::change_date($start_date, 'database'); $country = $this->_request->getParam('country'); $state = intval($this->_request->getParam('state')); $city = intval($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'); if (!isset($unitid) || $unitid == '') { $unitid = $bunitid; } $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); if ($Id == 'update') { $this->view->eventact = 'updated'; $tableid = $id; } else { $this->view->eventact = 'added'; $tableid = $Id; } $menuID = DEPARTMENTS; $result = sapp_Global::logManager($menuID, $actionflag, $loginUserId, $tableid); Zend_Layout::getMvcInstance()->setLayoutPath(APPLICATION_PATH . "/layouts/scripts/popup/"); $close = 'close'; $this->view->popup = $close; $this->view->controllername = $controllername; } 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($allTimezoneData)) { $msgarray['timezone'] = 'Time zones are not configured yet.'; } } $this->view->msgarray = $msgarray; } } } else { $orgdata = 'noorgdata'; $this->view->orgdata = $orgdata; } }
public function addpopupAction() { Zend_Layout::getMvcInstance()->setLayoutPath(APPLICATION_PATH . "/layouts/scripts/popup/"); $auth = Zend_Auth::getInstance(); if ($auth->hasIdentity()) { $loginUserId = $auth->getStorage()->read()->id; } $id = $this->getRequest()->getParam('id'); $controllername = 'timezone'; $timezoneform = new Default_Form_timezone(); $timezonemodel = new Default_Model_Timezone(); $timezoneform->setAction(BASE_URL . 'timezone/addpopup'); if ($this->getRequest()->getPost()) { if ($timezoneform->isValid($this->_request->getPost())) { $id = $this->_request->getParam('id'); $timezones = $this->_request->getParam('timezone'); $description = $this->_request->getParam('description'); $date = new Zend_Date(); $actionflag = ''; $tableid = ''; if (is_array($timezones)) { $timezonesStr = implode(",", $timezones); } else { $timezonesStr = ''; } $count = count($timezones); $Id = $timezonemodel->savetimezonedetails($timezonesStr, $description, $loginUserId); $where = ''; $actionflag = 1; $tableid = $Id; $menuID = TIMEZONE; for ($i = 0; $i < $count; $i++) { $result = sapp_Global::logManager($menuID, $actionflag, $loginUserId, $tableid); $tableid = $tableid + 1; } $timezonesData = $timezonemodel->fetchAll('isactive = 1', 'timezone')->toArray(); $opt = ''; foreach ($timezonesData as $record) { $opt .= sapp_Global::selectOptionBuilder($record['id'], $record['timezone'] . ' [' . $record['timezone_abbr'] . ']'); } $this->view->timezonesData = $opt; $this->view->eventact = 'added'; $close = 'close'; $this->view->popup = $close; } else { $messages = $timezoneform->getMessages(); foreach ($messages as $key => $val) { foreach ($val as $key2 => $val2) { $msgarray[$key] = $val2; break; } } $this->view->msgarray = $msgarray; } } $this->view->controllername = $controllername; $this->view->form = $timezoneform; $this->view->ermsg = ''; }
public function init() { $this->setMethod('post'); $this->setAttrib('action', BASE_URL . 'businessunits/edit'); $this->setAttrib('id', 'formid'); $this->setAttrib('name', 'businessunits'); $id = new Zend_Form_Element_Hidden('id'); $unitname = new Zend_Form_Element_Text('unitname'); $unitname->setAttrib('maxLength', 50); $unitname->addFilter(new Zend_Filter_StringTrim()); $unitname->setRequired(true); $unitname->addValidator('NotEmpty', false, array('messages' => 'Please enter name.')); $unitname->addValidator("regex", true, array('pattern' => '/^(?![0-9]{4})[a-zA-Z0-9.\\- ?]+$/', 'messages' => array('regexNotMatch' => 'Please enter valid name.'))); $unitname->addValidator(new Zend_Validate_Db_NoRecordExists(array('table' => 'main_businessunits', 'field' => 'unitname', 'exclude' => 'id!="' . Zend_Controller_Front::getInstance()->getRequest()->getParam('id') . '" and isactive=1'))); $unitname->getValidator('Db_NoRecordExists')->setMessage('Name already exists.'); $unitcode = new Zend_Form_Element_Text('unitcode'); $unitcode->addFilter(new Zend_Filter_StringTrim()); $unitcode->setRequired(true); $unitcode->setAttrib("maxlength", 4); $unitcode->addValidator('NotEmpty', false, array('messages' => 'Please enter code.')); $unitcode->addValidators(array(array('StringLength', false, array('min' => 2, 'max' => 4, 'messages' => array(Zend_Validate_StringLength::TOO_LONG => 'Code must contain at most %max% characters.', Zend_Validate_StringLength::TOO_SHORT => 'Code must contain at least %min% characters.'))))); $unitcode->addValidators(array(array('validator' => 'Regex', 'breakChainOnFailure' => true, 'options' => array('pattern' => '/^[a-zA-Z0-9\\&\'\\.\\s]+$/', 'messages' => array(Zend_Validate_Regex::NOT_MATCH => 'Please enter valid code.'))))); $unitcode->addValidator(new Zend_Validate_Db_NoRecordExists(array('table' => 'main_businessunits', 'field' => 'unitcode', 'exclude' => 'id!="' . Zend_Controller_Front::getInstance()->getRequest()->getParam('id') . '" and isactive=1'))); $unitcode->getValidator('Db_NoRecordExists')->setMessage('Code already exists.'); $description = new Zend_Form_Element_Textarea('description'); $description->setAttrib('rows', 10); $description->setAttrib('cols', 50); $start_date = new ZendX_JQuery_Form_Element_DatePicker('start_date'); $start_date->setAttrib('readonly', 'true'); $start_date->setAttrib('onfocus', 'this.blur()'); $start_date->setOptions(array('class' => 'brdr_none')); $country = new Zend_Form_Element_Select('country'); $country->setLabel('country'); $country->setRequired(true); $country->addValidator('NotEmpty', false, array('messages' => 'Please select country.')); $country->setAttrib('onchange', 'displayParticularState_normal(this,"state","state","city")'); $countryModal = new Default_Model_Countries(); $countriesData = $countryModal->fetchAll('isactive=1', 'country'); $country->addMultiOption('', 'Select country'); foreach ($countriesData->toArray() as $data) { $country->addMultiOption($data['country_id_org'], $data['country']); } $country->setRegisterInArrayValidator(false); $state = new Zend_Form_Element_Select('state'); $state->setAttrib('onchange', 'displayParticularCity_normal(this,"city","city","")'); $state->setRegisterInArrayValidator(false); $state->addMultiOption('', 'Select State'); $state->setRequired(true); $state->addValidator('NotEmpty', false, array('messages' => 'Please select state.')); $city = new Zend_Form_Element_Select('city'); $city->setAttrib('class', 'selectoption'); $city->setAttrib('onchange', 'displayCityCode(this)'); $city->setRegisterInArrayValidator(false); $city->addMultiOption('', 'Select City'); $city->setRequired(true); $city->addValidator('NotEmpty', false, array('messages' => 'Please select city.')); $address1 = new Zend_Form_Element_Textarea('address1'); $address1->setAttrib('rows', 10); $address1->setAttrib('cols', 50); $address1->setRequired(true); $address1->addValidator('NotEmpty', false, array('messages' => 'Please enter street address.')); $address2 = new Zend_Form_Element_Textarea('address2'); $address2->setAttrib('rows', 10); $address2->setAttrib('cols', 50); $address3 = new Zend_Form_Element_Textarea('address3'); $address3->setAttrib('rows', 10); $address3->setAttrib('cols', 50); $timezone = new Zend_Form_Element_Select('timezone'); $timezone->setLabel('timezone'); $timezone->setRequired(true); $timezone->addValidator('NotEmpty', false, array('messages' => 'Please select time zone.')); $timezoneModel = new Default_Model_Timezone(); $timezonedata = $timezoneModel->fetchAll('isactive=1', 'timezone'); $timezone->addMultiOption('', 'Select Time zone'); foreach ($timezonedata->toArray() as $data) { $timezone->addMultiOption($data['id'], $data['timezone'] . ' [' . $data['timezone_abbr'] . ']'); } $timezone->setRegisterInArrayValidator(false); $unithead = new Zend_Form_Element_Text('unithead'); $unithead->setLabel('timezone'); $unithead->setAttrib('maxlength', '50'); $unithead->addValidator("regex", true, array('pattern' => '/^[a-zA-Z.\\- ?]+$/', 'messages' => array('regexNotMatch' => 'Please enter valid name.'))); $submit = new Zend_Form_Element_Submit('submit'); $submit->setAttrib('id', 'submitbutton'); $submit->setLabel('Save'); $this->addElements(array($id, $unitname, $unitcode, $description, $start_date, $country, $state, $city, $address1, $address2, $address3, $timezone, $unithead, $submit)); $this->setElementDecorators(array('ViewHelper')); $this->setElementDecorators(array('UiWidgetElement'), array('start_date')); }
public function editAction() { $orgInfoModel = new Default_Model_Organisationinfo(); $getorgData = $orgInfoModel->getorgrecords(); $popConfigPermission = 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'); } $msgarray = array(); $flag = 'true'; $id = $this->getRequest()->getParam('id'); $callval = $this->getRequest()->getParam('call'); if ($callval == 'ajaxcall') { $this->_helper->layout->disableLayout(); } $countriesModel = new Default_Model_Countries(); $statesmodel = new Default_Model_States(); $citiesmodel = new Default_Model_Cities(); $timezonemodel = new Default_Model_Timezone(); $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(); $businessunitsform = new Default_Form_businessunits(); $businessunitsmodel = new Default_Model_Businessunits(); $orgInfoModel = new Default_Model_Organisationinfo(); $deptModel = new Default_Model_Departments(); $deptform = new Default_Form_departments(); $deptData = array(); $msgarray = array(); $businessunitsform->setAttrib('action', DOMAIN . 'businessunits/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']; } $address = $getorgData[0]['address1']; if (isset($country) && $country != 0 && $country != '') { $businessunitsform->setDefault('country', $country); $statesData = $statesmodel->getBasicStatesList($country); foreach ($statesData as $res) { $businessunitsform->state->addMultiOption($res['state_id_org'], utf8_encode($res['state'])); } if (isset($state) && $state != 0 && $state != '') { $businessunitsform->setDefault('state', $state); } } if (isset($state) && $state != 0 && $state != '') { $citiesData = $citiesmodel->getBasicCitiesList($state); foreach ($citiesData as $res) { $businessunitsform->city->addMultiOption($res['city_org_id'], utf8_encode($res['city'])); } if (isset($city) && $city != 0 && $city != '') { $businessunitsform->setDefault('city', $city); } } if (isset($address) && $address != '') { $businessunitsform->address1->setValue($address); } if (is_numeric($id) && $id > 0) { $data = $businessunitsmodel->getSingleUnitData($id); if (!empty($data)) { $businessunitsform->setAttrib('action', DOMAIN . 'businessunits/edit/id/' . $id); $businessunitsform->populate($data); $businessunitsform->submit->setLabel('Update'); $st_date = sapp_Global::change_date($data["startdate"], 'view'); $businessunitsform->setDefault('start_date', $st_date); $businessunitsform->state->clearMultiOptions(); $businessunitsform->city->clearMultiOptions(); $businessunitsform->state->addMultiOption('', utf8_encode("Select State")); $businessunitsform->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) { $businessunitsform->state->addMultiOption($res['state_id_org'], utf8_encode($res['state'])); } $businessunitsform->setDefault('country', $countryId); $businessunitsform->setDefault('state', $stateId); } if ($stateId != '') { $citiesData = $citiesmodel->getBasicCitiesList($stateId); foreach ($citiesData as $res) { $businessunitsform->city->addMultiOption($res['city_org_id'], utf8_encode($res['city'])); } $businessunitsform->setDefault('city', $cityId); } $deptData = $deptModel->getAllDeptsForUnit($id); $this->view->ermsg = ''; $this->view->datarr = $data; } else { $this->view->ermsg = 'nodata'; } } else { if ($id != '') { $this->view->ermsg = 'nodata'; } } $deptaddpermission = sapp_Global::_checkprivileges(DEPARTMENTS, $loginuserGroup, $loginuserRole, 'add'); $this->view->deptaddpermission = $deptaddpermission; $this->view->dataArray = $this->departmentGrid($id); $this->view->deptData = sizeof($deptData); $this->view->form = $businessunitsform; $this->view->unitid = $id; if (!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($allTimezoneData)) { $msgarray['timezone'] = 'Time zones are not configured yet.'; $flag = 'false'; } $start_date = $this->_request->getParam('start_date'); $start_date = sapp_Global::change_date($start_date, 'database'); $this->view->msgarray = $msgarray; if ($this->getRequest()->getPost()) { if ($businessunitsform->isValid($this->_request->getPost()) && $flag == 'true') { $unitname = $this->_request->getParam('unitname'); $unitcode = $this->_request->getParam('unitcode'); $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'); $timezone = $this->_request->getParam('timezone'); $unithead = $this->_request->getParam('unithead'); $unitcodeExistance = $businessunitsmodel->checkUnitCodeDuplicates($unitcode, $id); if (!$unitcodeExistance) { $date = new Zend_Date(); $menumodel = new Default_Model_Menu(); $actionflag = ''; $tableid = ''; $data = array('unitname' => trim($unitname), 'unitcode' => trim($unitcode), '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), 'unithead' => trim($unithead), 'modifiedby' => $loginUserId, 'modifieddate' => gmdate("Y-m-d H:i:s")); if ($id != '') { $where = array('id=?' => $id); $actionflag = 2; } else { $data['createdby'] = $loginUserId; $data['createddate'] = gmdate("Y-m-d H:i:s"); $data['isactive'] = 1; $where = ''; $actionflag = 1; } $Id = $businessunitsmodel->SaveorUpdateBusinessUnits($data, $where); if ($Id == 'update') { $tableid = $id; $this->_helper->getHelper("FlashMessenger")->addMessage("Business unit updated successfully."); } else { $tableid = $Id; $this->_helper->getHelper("FlashMessenger")->addMessage("Business unit added successfully."); } $menuidArr = $menumodel->getMenuObjID('/businessunits'); $menuID = $menuidArr[0]['id']; $result = sapp_Global::logManager($menuID, $actionflag, $loginUserId, $tableid); $this->_redirect('businessunits'); } else { $msgarray['message'] = 'A Business Unit, with the given code, already exists.'; $msgarray['msgtype'] = 'error'; $this->view->messages = $msgarray; } } else { $messages = $businessunitsform->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($allTimezoneData)) { $msgarray['timezone'] = 'Time zones are not configured yet.'; } } $this->view->msgarray = $msgarray; } } } else { $orgdata = 'noorgdata'; $this->view->orgdata = $orgdata; } $this->view->popConfigPermission = $popConfigPermission; }
public function init() { $this->setMethod('post'); $this->setAttrib('id', 'formid'); $this->setAttrib('name', 'systempreference'); $id = new Zend_Form_Element_Hidden('id'); $currencyid = new Zend_Form_Element_Hidden('currencyid'); $organisationid = new Zend_Form_Element_Hidden('organisationid'); $empcodeid = new Zend_Form_Element_Hidden('empcodeid'); $dateformatid = new Zend_Form_Element_Select('dateformatid'); $dateformatid->setAttrib('class', 'selectoption'); $dateformatid->setRegisterInArrayValidator(false); $dateformatid->setRequired(true); $dateformatid->addValidator('NotEmpty', false, array('messages' => 'Please select date format.')); $timeformatid = new Zend_Form_Element_Select('timeformatid'); $timeformatid->setAttrib('class', 'selectoption'); $timeformatid->setRegisterInArrayValidator(false); $timeformatid->setRequired(true); $timeformatid->addValidator('NotEmpty', false, array('messages' => 'Please select time format.')); $timezoneid = new Zend_Form_Element_Select('timezoneid'); $timezoneid->setAttrib('class', 'selectoption'); $timezoneid->setRegisterInArrayValidator(false); $timezoneid->setRequired(true); $timezoneid->addValidator('NotEmpty', false, array('messages' => 'Please select time zone preference.')); $timezoneid->addMultiOption('', 'Select Time zone'); $timezoneModal = new Default_Model_Timezone(); $timezoneData = $timezoneModal->fetchAll('isactive=1', 'timezone')->toArray(); foreach ($timezoneData as $data) { $timezoneid->addMultiOption($data['id'], $data['timezone'] . ' [' . $data['timezone_abbr'] . ']'); } $currencyname = new Zend_Form_Element_Text('currencyname'); $currencyname->setAttrib('maxLength', 50); $currencyname->addFilter(new Zend_Filter_StringTrim()); $currencyname->setRequired(true); $currencyname->addValidator('NotEmpty', false, array('messages' => 'Please enter currency.')); $currencyname->addValidator("regex", true, array('pattern' => '/^[a-zA-Z][a-zA-Z0-9\\s]*$/', 'messages' => array('regexNotMatch' => 'Please enter valid currency.'))); $currencyname->addValidator(new Zend_Validate_Db_NoRecordExists(array('table' => 'main_currency', 'field' => 'currencyname', 'exclude' => 'id!="' . Zend_Controller_Front::getInstance()->getRequest()->getParam('currencyid') . '" and isactive=1'))); $currencyname->getValidator('Db_NoRecordExists')->setMessage('Currency already exists.'); $currencycode = new Zend_Form_Element_Text('currencycode'); $currencycode->setAttrib('maxLength', 20); $currencycode->addFilter(new Zend_Filter_StringTrim()); $currencycode->setRequired(true); $currencycode->addValidator('NotEmpty', false, array('messages' => 'Please enter currency code.')); $currencycode->addValidator("regex", true, array('pattern' => '/^[a-zA-Z][a-zA-Z0-9]*$/', 'messages' => array('regexNotMatch' => 'Please enter valid currency code.'))); $currencycode->addValidator(new Zend_Validate_Db_NoRecordExists(array('table' => 'main_currency', 'field' => 'currencycode', 'exclude' => 'id!="' . Zend_Controller_Front::getInstance()->getRequest()->getParam('currencyid') . '" and isactive=1'))); $currencycode->getValidator('Db_NoRecordExists')->setMessage('Currency code already exists.'); $passwordid = new Zend_Form_Element_Select('passwordid'); $passwordid->setAttrib('class', 'selectoption'); $passwordid->setAttrib('onchange', 'displayPasswordDesc(this)'); $passwordid->setRegisterInArrayValidator(false); $passwordid->setRequired(true); $passwordid->addValidator('NotEmpty', false, array('messages' => 'Please select default password.')); $perm_country = new Zend_Form_Element_Select('perm_country'); $perm_country->setAttrib('onchange', 'displayParticularState(this,"","perm_state","")'); $perm_country->setRegisterInArrayValidator(false); $countriesModel = new Default_Model_Countries(); $countrieslistArr = $countriesModel->getTotalCountriesList('addcountry'); if (sizeof($countrieslistArr) > 0) { $perm_country->addMultiOption('', 'Select Country'); foreach ($countrieslistArr as $countrieslistres) { $perm_country->addMultiOption($countrieslistres['id'], utf8_encode($countrieslistres['country_name'])); } } $perm_country->setRequired(true); $perm_country->addValidator('NotEmpty', false, array('messages' => 'Please select country.')); $perm_state = new Zend_Form_Element_Select('perm_state'); $perm_state->setAttrib('onchange', 'displayParticularCity(this,"","perm_city","")'); $perm_state->setRegisterInArrayValidator(false); $perm_state->addMultiOption('', 'Select State'); $perm_state->setRequired(true); $perm_state->addValidator('NotEmpty', false, array('messages' => 'Please select state.')); $perm_city = new Zend_Form_Element_Select('perm_city'); $perm_city->setRegisterInArrayValidator(false); $perm_city->addMultiOption('', 'Select City'); $perm_city->setRequired(true); $perm_city->addValidator('NotEmpty', false, array('messages' => 'Please select city.')); $workcodename = new Zend_Form_Element_Multiselect('workcodename'); $workcodename->setRegisterInArrayValidator(false); $workcodename->setRequired(true); $workcodename->addValidator('NotEmpty', false, array('messages' => 'Please select employment status.')); $empCode = new Zend_Form_Element_Text('employee_code'); $empCode->addFilter(new Zend_Filter_StringTrim()); $empCode->setAttrib('maxLength', 5); $empCode->setRequired(true); $empCode->addValidator('NotEmpty', false, array('messages' => 'Please enter employee code.')); $empCode->addValidators(array(array('StringLength', false, array('min' => 1, 'max' => 5, 'messages' => array(Zend_Validate_StringLength::TOO_LONG => 'Employee code must contain at most %max% characters.', Zend_Validate_StringLength::TOO_SHORT => 'Employee code must contain at least %min% characters.'))))); $empCode->addValidators(array(array('validator' => 'Regex', 'breakChainOnFailure' => true, 'options' => array('pattern' => '/^[A-Za-z][a-zA-Z@\\-]*$/', 'messages' => array(Zend_Validate_Regex::NOT_MATCH => 'Please enter valid employee code.'))))); $submit = new Zend_Form_Element_Submit('submit'); $submit->setAttrib('id', 'submitbutton'); $submit->setLabel('Save'); $this->addElements(array($timezoneid, $id, $currencyid, $organisationid, $empcodeid, $dateformatid, $timeformatid, $currencycode, $currencyname, $passwordid, $perm_country, $perm_state, $perm_city, $workcodename, $empCode, $submit)); $this->setElementDecorators(array('ViewHelper')); }