Beispiel #1
0
 public static function _getAdapter($adapter, $options)
 {
     if (empty($adapter) || empty($options) || !is_array($options)) {
         return false;
     }
     if (!in_array($adapter, array('ldap', 'db', 'email'))) {
         return false;
     }
     if (!array_key_exists('username', $options) || !array_key_exists('user_password', $options)) {
         return false;
     }
     $username = $options['username'];
     $password = $options['user_password'];
     switch ($adapter) {
         case 'ldap':
             $auth = new Zend_Auth_Adapter_Ldap($options['ldap'], $username, $password);
             break;
         case 'db':
             $password = md5($password);
             $auth = new Zend_Auth_Adapter_DbTable($options['db'], 'main_users', 'employeeId', 'emppassword');
             $auth->setIdentity($username)->setCredential($password);
             break;
         case 'email':
             $password = md5($password);
             $auth = new Zend_Auth_Adapter_DbTable($options['db'], 'main_users', 'emailaddress', 'emppassword');
             $auth->setIdentity($username)->setCredential($password);
             break;
     }
     //To create organization image session
     $orgInfoModel = new Default_Model_Organisationinfo();
     $getorgData = $orgInfoModel->getorgrecords();
     if (!empty($getorgData)) {
         $id = $getorgData[0]['id'];
         $data = $orgInfoModel->getOrganisationData($id);
         $organizationImg = new Zend_Session_Namespace('organizationinfo');
         if (!empty($data['org_image'])) {
             $organizationImg->orgimg = $data['org_image'];
         }
     }
     return $auth;
 }
 public function viewAction_27092013()
 {
     $auth = Zend_Auth::getInstance();
     if ($auth->hasIdentity()) {
         $loginUserId = $auth->getStorage()->read()->id;
     }
     $id = $this->getRequest()->getParam('userid');
     $callval = $this->getRequest()->getParam('call');
     if ($callval == 'ajaxcall') {
         $this->_helper->layout->disableLayout();
     }
     $objName = 'empcommunicationdetails';
     $empcommdetailsform = new Default_Form_empcommunicationdetails();
     $empcommdetailsform->removeElement("submit");
     $elements = $empcommdetailsform->getElements();
     if (count($elements) > 0) {
         foreach ($elements as $key => $element) {
             if ($key != "Cancel" && $key != "Edit" && $key != "Delete" && $key != "Attachments") {
                 $element->setAttrib("disabled", "disabled");
             }
         }
     }
     try {
         if ($id) {
             $employeeModal = new Default_Model_Employee();
             $isrowexist = $employeeModal->getsingleEmployeeData($id);
             if ($isrowexist == 'norows') {
                 $this->view->rowexist = "norows";
             } else {
                 $this->view->rowexist = "rows";
             }
             $empdata = $employeeModal->getActiveEmployeeData($id);
             if (!empty($empdata)) {
                 //TO get the Employee  profile information....
                 $usersModel = new Default_Model_Users();
                 $employeeData = $usersModel->getUserDetailsByIDandFlag($id);
                 $empcommdetailsModal = new Default_Model_Empcommunicationdetails();
                 $usersModel = new Default_Model_Users();
                 $countriesModel = new Default_Model_Countries();
                 $statesmodel = new Default_Model_States();
                 $citiesmodel = new Default_Model_Cities();
                 $orgInfoModel = new Default_Model_Organisationinfo();
                 $msgarray = array();
                 $orgid = 1;
                 $orgdata = $orgInfoModel->getOrganisationData($orgid);
                 $countryId = $orgdata['country'];
                 $stateId = $orgdata['state'];
                 $cityId = $orgdata['city'];
                 if ($countryId != '') {
                     $countryData = $countriesModel->getActiveCountryName($countryId);
                     $orgdata['country'] = $countryData[0]['country'];
                 }
                 if ($stateId != '') {
                     $stateData = $statesmodel->getStateNameData($stateId);
                     $orgdata['state'] = $stateData[0]['state'];
                 }
                 if ($cityId != '') {
                     $citiesData = $citiesmodel->getCitiesNameData($cityId);
                     $orgdata['city'] = $citiesData[0]['city'];
                 }
                 $countrieslistArr = $countriesModel->getActiveCountriesList();
                 if (sizeof($countrieslistArr) > 0) {
                     $empcommdetailsform->perm_country->addMultiOption('', 'Select Country');
                     $empcommdetailsform->current_country->addMultiOption('', 'Select Country');
                     foreach ($countrieslistArr as $countrieslistres) {
                         $empcommdetailsform->perm_country->addMultiOption($countrieslistres['country_id_org'], $countrieslistres['country']);
                         $empcommdetailsform->current_country->addMultiOption($countrieslistres['country_id_org'], $countrieslistres['country']);
                     }
                 } else {
                     $msgarray['perm_country'] = 'Countries are not configured yet.';
                     $msgarray['current_country'] = 'Countries are not configured yet.';
                 }
                 $data = $empcommdetailsModal->getsingleEmpCommDetailsData($id);
                 if (!empty($data)) {
                     $statePermlistArr = $statesmodel->getStatesList($data[0]['perm_country']);
                     if (sizeof($statePermlistArr) > 0) {
                         $empcommdetailsform->perm_state->addMultiOption('', 'Select State');
                         foreach ($statePermlistArr as $statelistres) {
                             $empcommdetailsform->perm_state->addMultiOption($statelistres['id'] . '!@#' . $statelistres['state_name'], $statelistres['state_name']);
                         }
                     }
                     $cityPermlistArr = $citiesmodel->getCitiesList($data[0]['perm_state']);
                     if (sizeof($cityPermlistArr) > 0) {
                         $empcommdetailsform->perm_city->addMultiOption('', 'Select City');
                         foreach ($cityPermlistArr as $cityPermlistres) {
                             $empcommdetailsform->perm_city->addMultiOption($cityPermlistres['id'] . '!@#' . $cityPermlistres['city_name'], $cityPermlistres['city_name']);
                         }
                     }
                     if ($data[0]['current_country'] != '' && $data[0]['current_state'] != '') {
                         $statecurrlistArr = $statesmodel->getStatesList($data[0]['current_country']);
                         if (sizeof($statecurrlistArr) > 0) {
                             $empcommdetailsform->current_state->addMultiOption('', 'Select State');
                             foreach ($statecurrlistArr as $statecurrlistres) {
                                 $empcommdetailsform->current_state->addMultiOption($statecurrlistres['id'] . '!@#' . $statecurrlistres['state_name'], $statecurrlistres['state_name']);
                             }
                         }
                         $currstateNameArr = $statesmodel->getStateName($data[0]['current_state']);
                     }
                     if ($data[0]['current_country'] != '' && $data[0]['current_state'] != '' && $data[0]['current_city'] != '') {
                         $cityCurrlistArr = $citiesmodel->getCitiesList($data[0]['current_state']);
                         if (sizeof($cityCurrlistArr) > 0) {
                             $empcommdetailsform->current_city->addMultiOption('', 'Select State');
                             foreach ($cityCurrlistArr as $cityCurrlistres) {
                                 $empcommdetailsform->current_city->addMultiOption($cityCurrlistres['id'] . '!@#' . $cityCurrlistres['city_name'], $cityCurrlistres['city_name']);
                             }
                         }
                         $currcityNameArr = $citiesmodel->getCityName($data[0]['current_city']);
                     }
                     $permstateNameArr = $statesmodel->getStateName($data[0]['perm_state']);
                     $permcityNameArr = $citiesmodel->getCityName($data[0]['perm_city']);
                     $empcommdetailsform->populate($data[0]);
                     $empcommdetailsform->setDefault('perm_country', $data[0]['perm_country']);
                     $empcommdetailsform->setDefault('perm_state', $permstateNameArr[0]['id'] . '!@#' . $permstateNameArr[0]['statename']);
                     $empcommdetailsform->setDefault('perm_city', $permcityNameArr[0]['id'] . '!@#' . $permcityNameArr[0]['cityname']);
                     if ($data[0]['current_country'] != '') {
                         $empcommdetailsform->setDefault('current_country', $data[0]['current_country']);
                     }
                     if ($data[0]['current_state'] != '') {
                         $empcommdetailsform->setDefault('current_state', $currstateNameArr[0]['id'] . '!@#' . $currstateNameArr[0]['statename']);
                     }
                     if ($data[0]['current_city'] != '') {
                         $empcommdetailsform->setDefault('current_city', $currcityNameArr[0]['id'] . '!@#' . $currcityNameArr[0]['cityname']);
                     }
                 }
                 $this->view->controllername = $objName;
                 $this->view->data = $data;
                 $this->view->dataArray = $orgdata;
                 $this->view->id = $id;
                 $this->view->employeedata = $employeeData[0];
                 $this->view->form = $empcommdetailsform;
             }
             $this->view->empdata = $empdata;
         }
     } catch (Exception $e) {
         $this->view->rowexist = "norows";
     }
 }
 public function edit_oldAction()
 {
     $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();
     $empid = '';
     $orgheadsData = array();
     $oldOrgHead = '';
     $new_stateId = '';
     $actionpage = '';
     if (sapp_Global::_checkprivileges(PREFIX, $loginuserGroup, $loginuserRole, 'add') == 'Yes') {
         array_push($popConfigPermission, 'prefix');
     }
     if (sapp_Global::_checkprivileges(IDENTITYCODES, $loginuserGroup, $loginuserRole, 'edit') == 'Yes') {
         array_push($popConfigPermission, 'identitycodes');
     }
     if (sapp_Global::_checkprivileges(JOBTITLES, $loginuserGroup, $loginuserRole, 'add') == 'Yes') {
         array_push($popConfigPermission, 'jobtitles');
     }
     if (sapp_Global::_checkprivileges(POSITIONS, $loginuserGroup, $loginuserRole, 'add') == 'Yes') {
         array_push($popConfigPermission, 'position');
     }
     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, 'edit') == 'Yes') {
         array_push($popConfigPermission, 'employee');
     }
     $msgarray = array();
     $new_stateId = '';
     $new_cityId = '';
     $id = $this->getRequest()->getParam('id');
     $form = new Default_Form_Organisationinfo();
     $user_model = new Default_Model_Usermanagement();
     $orgInfoModel = new Default_Model_Organisationinfo();
     $countriesModel = new Default_Model_Countries();
     $statesmodel = new Default_Model_States();
     $citiesmodel = new Default_Model_Cities();
     $role_model = new Default_Model_Roles();
     $prefixModel = new Default_Model_Prefix();
     $identity_code_model = new Default_Model_Identitycodes();
     $jobtitlesModel = new Default_Model_Jobtitles();
     $employeeModal = new Default_Model_Employee();
     $positionsmodel = new Default_Model_Positions();
     $identity_codes = $identity_code_model->getIdentitycodesRecord();
     $role_data = $role_model->getRolesList_orginfo();
     $allCountriesData = $countriesModel->fetchAll('isactive=1', 'country')->toArray();
     $allStatesData = $statesmodel->fetchAll('isactive=1', 'state')->toArray();
     $allCitiesData = $citiesmodel->fetchAll('isactive=1', 'city')->toArray();
     $flag = 'true';
     $emp_identity_code = isset($identity_codes[0]) ? $identity_codes[0]['employee_code'] : "";
     if ($emp_identity_code != '') {
         $emp_id = $emp_identity_code . str_pad($user_model->getMaxEmpId($emp_identity_code), 4, '0', STR_PAD_LEFT);
     } else {
         $emp_id = '';
         $msgarray['employeeId'] = 'Identity codes are not configured yet.';
         $flag = 'false';
     }
     $form->employeeId->setValue($emp_id);
     $form->emprole->addMultiOptions(array('' => 'Select Role') + $role_data);
     if (empty($allCountriesData)) {
         $msgarray['country'] = 'Countries are not configured yet.';
         $flag = 'false';
     }
     if (empty($role_data)) {
         $msgarray['emprole'] = 'Roles are not added 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';
     }
     $prefixData = $prefixModel->getPrefixList();
     $form->prefix_id->addMultiOption('', 'Select Prefix');
     if (!empty($prefixData)) {
         foreach ($prefixData as $prefixres) {
             $form->prefix_id->addMultiOption($prefixres['id'], $prefixres['prefix']);
         }
     } else {
         $msgarray['prefix_id'] = 'Prefixes are not configured yet.';
     }
     $jobtitleData = $jobtitlesModel->getJobTitleList();
     if (!empty($jobtitleData)) {
         foreach ($jobtitleData as $jobtitleres) {
             $form->jobtitle_id->addMultiOption($jobtitleres['id'], $jobtitleres['jobtitlename']);
         }
     } else {
         $msgarray['jobtitle_id'] = 'Job titles are not configured yet.';
         $msgarray['position_id'] = 'Positions are not configured yet.';
     }
     $orgheadsData = $employeeModal->getEmployeesForOrgHead();
     $currentOrgHead = $employeeModal->getCurrentOrgHead();
     if (!empty($currentOrgHead)) {
         $oldOrgHead = $currentOrgHead[0]['user_id'];
     }
     if ($id) {
         $form->submit->setLabel('Update');
         try {
             $data = $orgInfoModel->getOrganisationData($id);
             $form->setAttrib('action', BASE_URL . 'organisationinfo/edit/id/' . $id);
             $data['org_startdate'] = sapp_Global::change_date($data['org_startdate'], 'view');
             $form->populate($data);
             $countryId = $data['country'];
             $stateId = $data['state'];
             $cityId = $data['city'];
             $actionpage = 'edit';
             if (count($_POST) > 0) {
                 $countryId = isset($_POST['country']) ? $_POST['country'] : "";
                 $stateId = isset($_POST['state']) ? $_POST['state'] : "";
                 $cityId = isset($_POST['city']) ? $_POST['city'] : "";
             }
             if ($countryId != '') {
                 $statesData = $statesmodel->getBasicStatesList((int) $countryId);
                 foreach ($statesData as $res) {
                     if ($stateId == $res['state_id_org']) {
                         $new_stateId = $res['state_id_org'] . '!@#' . utf8_encode($res['state']);
                     }
                     $form->state->addMultiOption($res['state_id_org'] . '!@#' . utf8_encode($res['state']), utf8_encode($res['state']));
                 }
                 if (count($_POST) == 0) {
                     $stateId = $new_stateId;
                 }
             }
             if ($stateId != '') {
                 $citiesData = $citiesmodel->getBasicCitiesList((int) $stateId);
                 foreach ($citiesData as $res) {
                     if ($cityId == $res['city_org_id']) {
                         $new_cityId = $res['city_org_id'] . '!@#' . utf8_encode($res['city']);
                     }
                     $form->city->addMultiOption($res['city_org_id'] . '!@#' . utf8_encode($res['city']), utf8_encode($res['city']));
                 }
                 if (count($_POST) == 0) {
                     $cityId = $new_cityId;
                 }
             }
             $emp_data = $employeeModal->fetchRow("is_orghead = 1");
             if (!empty($emp_data)) {
                 $user_data = $user_model->fetchRow("id = " . $emp_data->user_id);
                 if (!empty($user_data)) {
                     $form->setDefault('firstname_orghead', $user_data->firstname);
                     $form->setDefault('lastname_orghead', $user_data->lastname);
                     $form->setDefault('employeeId', $user_data->employeeId);
                     $form->setDefault('emprole', $user_data->emprole);
                     $form->setDefault('emailaddress', $user_data->emailaddress);
                     $form->setDefault('jobtitle_id', $user_data->jobtitle_id);
                     $form->setDefault('prefix_id', $emp_data->prefix_id);
                     $form->setDefault('date_of_joining', sapp_Global::change_date($emp_data->date_of_joining, 'view'));
                     $jobtitle_id = $emp_data->jobtitle_id;
                     if (isset($_POST['jobtitle_id'])) {
                         $jobtitle_id = $_POST['jobtitle_id'];
                     }
                     $form->position_id->addMultiOption('', 'Select a Position');
                     if ($jobtitle_id != '') {
                         $positionlistArr = $positionsmodel->getPositionList($jobtitle_id);
                         if (sizeof($positionlistArr) > 0) {
                             foreach ($positionlistArr as $positionlistres) {
                                 $form->position_id->addMultiOption($positionlistres['id'], $positionlistres['positionname']);
                             }
                         }
                     }
                     $form->setDefault('position_id', $emp_data->position_id);
                     $form->setDefault('orghead', $user_data->id);
                 }
                 $empid = $emp_data->user_id;
             } else {
                 $form->setDefault('orghead', '');
             }
             if (empty($orgheadsData)) {
                 $msgarray['orghead'] = 'Management employees are not added yet.';
             }
             $form->setDefault('country', $countryId);
             $form->setDefault('state', $stateId);
             $form->setDefault('city', $cityId);
             $this->view->domainValue = $data['domain'];
             $this->view->org_image = $data['org_image'];
             $this->view->ermsg = '';
             $this->view->datarr = $data;
             $this->view->user_id = $empid;
             $this->view->orgheadsData = $orgheadsData;
         } catch (Exception $e) {
             $this->view->ermsg = 'nodata';
         }
     } else {
         $actionpage = 'add';
         $activeOrgs = $orgInfoModel->getorgrecords();
         if (empty($activeOrgs)) {
             $form->setAttrib('action', BASE_URL . 'organisationinfo/edit');
             $country = $this->_request->getParam('country');
             $state = intVal($this->_request->getParam('state'));
             $city = intVal($this->_request->getParam('city'));
             if (isset($country) && $country != 0 && $country != '') {
                 $statesData = $statesmodel->getBasicStatesList($country);
                 foreach ($statesData as $res) {
                     $form->state->addMultiOption($res['state_id_org'] . '!@#' . utf8_encode($res['state']), utf8_encode($res['state']));
                 }
                 if (isset($state) && $state != 0 && $state != '') {
                     $form->setDefault('state', $state);
                 }
             }
             if (isset($state) && $state != 0 && $state != '') {
                 $citiesData = $citiesmodel->getBasicCitiesList($state);
                 foreach ($citiesData as $res) {
                     $form->city->addMultiOption($res['city_org_id'] . '!@#' . utf8_encode($res['city']), utf8_encode($res['city']));
                 }
                 if (isset($city) && $city != 0 && $city != '') {
                     $form->setDefault('city', $city);
                 }
             }
             $this->view->ermsg = '';
         } else {
             $this->view->ermsg = 'cannotadd';
         }
         $form->position_id->addMultiOption('', 'Select a Position');
         if (isset($_POST['jobtitle_id']) && $_POST['jobtitle_id'] != '') {
             $jobtitle_id = $_POST['jobtitle_id'];
             $positionlistArr = $positionsmodel->getPositionList($jobtitle_id);
             if (sizeof($positionlistArr) > 0) {
                 foreach ($positionlistArr as $positionlistres) {
                     $form->position_id->addMultiOption($positionlistres['id'], $positionlistres['positionname']);
                 }
             }
         }
         $emp_data = $employeeModal->fetchRow("is_orghead = 1");
         if (!empty($emp_data)) {
             $user_data = $user_model->fetchRow("id = " . $emp_data->user_id);
             if (!empty($user_data)) {
                 $form->setDefault('employeeId', $user_data->employeeId);
                 $form->setDefault('emprole', $user_data->emprole);
                 $form->setDefault('emailaddress', $user_data->emailaddress);
                 $form->setDefault('jobtitle_id', $user_data->jobtitle_id);
                 $form->setDefault('prefix_id', $emp_data->prefix_id);
                 $form->setDefault('date_of_joining', sapp_Global::change_date($emp_data->date_of_joining, 'view'));
                 $jobtitle_id = $emp_data->jobtitle_id;
                 if (isset($_POST['jobtitle_id'])) {
                     $jobtitle_id = $_POST['jobtitle_id'];
                 }
                 $form->position_id->addMultiOption('', 'Select a Position');
                 if ($jobtitle_id != '') {
                     $positionlistArr = $positionsmodel->getPositionList($jobtitle_id);
                     if (sizeof($positionlistArr) > 0) {
                         foreach ($positionlistArr as $positionlistres) {
                             $form->position_id->addMultiOption($positionlistres['id'], $positionlistres['positionname']);
                         }
                     }
                 }
                 $form->setDefault('position_id', $emp_data->position_id);
                 $form->setDefault('orghead', $user_data->id);
             }
             $empid = $emp_data->user_id;
         } else {
             $form->setDefault('orghead', '');
         }
         if (empty($orgheadsData)) {
             $msgarray['orghead'] = 'Management employees are not added yet.';
         }
         $this->view->user_id = $empid;
         $this->view->orgheadsData = $orgheadsData;
     }
     $this->view->form = $form;
     $this->view->currentOrgHead = $currentOrgHead;
     $this->view->actionpage = $actionpage;
     if (!empty($allCountriesData) && !empty($allStatesData) && !empty($allCitiesData)) {
         $this->view->configuremsg = '';
     } else {
         $this->view->configuremsg = 'notconfigurable';
     }
     if (isset($_POST['prevorgheadrm'])) {
         $prevorgheadrm = $this->_request->getParam('prevorgheadrm');
     } else {
         $prevorgheadrm = '';
     }
     $this->view->prevorgheadrmval = $prevorgheadrm;
     if (isset($_POST['rmflag'])) {
         $rmflag = $this->_request->getParam('rmflag');
     } else {
         $rmflag = '0';
     }
     $this->view->rmflag = $rmflag;
     if ($this->getRequest()->getPost()) {
         $imagerror = $this->_request->getParam('imgerr');
         $imagepath = $this->_request->getParam('org_image_value');
         $imgerrmsg = $this->_request->getParam('imgerrmsg');
         $pphnumber = $this->_request->getParam('phonenumber');
         $sphnumber = $this->_request->getParam('secondaryphone');
         $org_startdate = sapp_Global::change_date($this->_request->getParam('org_startdate'), 'database');
         $flag = 'true';
         if (isset($imagepath) && $imagepath != '') {
             $imageArr = explode('.', $imagepath);
             if (sizeof($imageArr) > 1) {
                 $imagename = $imageArr[0];
                 $imageext = $imageArr[1];
                 $extArr = array('gif', 'jpg', 'jpeg', 'png');
                 if (!in_array($imageext, $extArr)) {
                     $msgarray['org_image_value'] = 'Please upload an appropriate image file.';
                     $flag = 'false';
                 }
             } else {
                 $msgarray['org_image_value'] = 'Please upload an appropriate image file.';
                 $flag = 'false';
             }
         }
         if ($imagerror == 'error') {
             if ($imgerrmsg != '' && $imgerrmsg != 'undefined') {
                 $msgarray['org_image_value'] = $imgerrmsg;
             } else {
                 $msgarray['org_image_value'] = 'Please upload an appropriate image file.';
             }
             $flag = 'false';
         }
         if ($pphnumber == $sphnumber && $sphnumber != '' && $pphnumber != '') {
             $msgarray['secondaryphone'] = 'Please enter different phone number.';
             $flag = 'false';
         }
         if ($form->isValid($this->_request->getPost()) && $flag != 'false') {
             $domain = $this->_request->getParam('domain');
             $domain = implode(',', $domain);
             $prevorgheadrm = $this->_request->getParam('prevorgheadrm');
             $actionflag = '';
             $date = new Zend_Date();
             $newOrgHead = $this->_request->getParam('orghead');
             if ($newOrgHead != '') {
                 $neworgHeadData = $employeeModal->getsingleEmployeeData($newOrgHead);
             }
             if (!empty($neworgHeadData)) {
                 $headfullname = $neworgHeadData[0]['userfullname'];
             } else {
                 $headfullname = '';
             }
             $data = array('organisationname' => trim($this->_request->getParam('organisationname')), 'domain' => trim($domain), 'website' => trim($this->_request->getParam('website')), 'org_image' => $imagepath, 'orgdescription' => trim($this->_request->getParam('orgdescription')), 'totalemployees' => trim($this->_request->getParam('totalemployees')), 'org_startdate' => $org_startdate != '' ? $org_startdate : NULL, 'phonenumber' => trim($this->_request->getParam('phonenumber')), 'secondaryphone' => trim($this->_request->getParam('secondaryphone')), 'faxnumber' => trim($this->_request->getParam('faxnumber')), 'country' => trim((int) $this->_request->getParam('country')), 'state' => trim(intval($this->_request->getParam('state'))), 'city' => trim(intval($this->_request->getParam('city'))), 'address1' => trim($this->_request->getParam('address1')), 'address2' => trim($this->_request->getParam('address2')), 'address3' => trim($this->_request->getParam('address3')), 'description' => trim($this->_request->getParam('description')), 'orghead' => trim($this->_request->getParam('orghead')), 'designation' => trim($this->_request->getParam('jobtitle_id', null)), 'modifiedby' => $loginUserId, 'modifieddate' => gmdate("Y-m-d H:i:s"));
             $db = Zend_Db_Table::getDefaultAdapter();
             $db->beginTransaction();
             try {
                 if ($oldOrgHead != $newOrgHead && $oldOrgHead != '' && $newOrgHead != '' && $prevorgheadrm) {
                     $orgInfoModel->changeOrgHead($oldOrgHead, $newOrgHead, $prevorgheadrm);
                 }
                 $path = IMAGE_UPLOAD_PATH;
                 $imagepath = $this->_request->getParam('org_image_value');
                 $filecopy = 'success';
                 if ($imagepath != '') {
                     $filecopy = 'error';
                     if (file_exists(USER_PREVIEW_UPLOAD_PATH . '//' . $imagepath)) {
                         try {
                             if (copy(USER_PREVIEW_UPLOAD_PATH . '//' . $imagepath, $path . '//' . $imagepath)) {
                                 $filecopy = 'success';
                             }
                             unlink(USER_PREVIEW_UPLOAD_PATH . '//' . $imagepath);
                         } catch (Exception $e) {
                             echo $msgarray['org_image_value'] = $e->getMessage();
                             exit;
                         }
                     }
                 }
                 $where = array('id=?' => $id);
                 if ($imagepath == '') {
                     unset($data['org_image']);
                 } else {
                     if ($filecopy == 'error') {
                         unset($data['org_image']);
                     }
                 }
                 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 = $orgInfoModel->SaveorUpdateData($data, $where);
                 $jobtitle_id = $this->_request->getParam('jobtitle_id', null);
                 $position_id = $this->_request->getParam('position_id', null);
                 $date_of_joining = sapp_Global::change_date($this->_request->getParam('date_of_joining', null), 'database');
                 $employeeId = $this->_getParam('employeeId', null);
                 $emprole = $this->_getParam('emprole', null);
                 $emailaddress = $this->_getParam('emailaddress', null);
                 $emppassword = sapp_Global::generatePassword();
                 $first_name = trim($this->_request->getParam('firstname_orghead', null));
                 $last_name = trim($this->_request->getParam('lastname_orghead', null));
                 $userfullname = $first_name . ' ' . $last_name;
                 //$userfullname = $headfullname;
                 $prefix_id = $this->_getParam('prefix_id', null);
                 $user_id = $this->_getParam('user_id', null);
                 $user_data = array('emprole' => $emprole, 'firstname' => $first_name, 'lastname' => $last_name, 'userfullname' => $userfullname, 'emailaddress' => $emailaddress, 'jobtitle_id' => $jobtitle_id, 'modifiedby' => $loginUserId, 'modifieddate' => gmdate("Y-m-d H:i:s"), 'emppassword' => md5($emppassword), 'employeeId' => $employeeId, 'selecteddate' => $date_of_joining, 'userstatus' => 'old', 'modeofentry' => 'Direct');
                 $emp_data = array('user_id' => $newOrgHead, 'jobtitle_id' => $jobtitle_id, 'position_id' => $position_id, 'prefix_id' => $prefix_id, 'reporting_manager' => 0, 'date_of_joining' => $date_of_joining, 'modifiedby' => $loginUserId, 'modifieddate' => gmdate("Y-m-d H:i:s"));
                 if ($Id == 'update') {
                     $tableid = $id;
                     unset($user_data['emppassword']);
                     unset($user_data['modeofentry']);
                     unset($user_data['userstatus']);
                     if ($newOrgHead != '') {
                         $user_st = $user_model->SaveorUpdateUserData($user_data, " id = " . $newOrgHead);
                         $employeeModal->SaveorUpdateEmployeeData($emp_data, " user_id = " . $newOrgHead);
                     } else {
                         $user_data['userstatus'] = 'old';
                         $user_data['emppassword'] = md5($emppassword);
                         $user_data['createdby'] = $loginUserId;
                         $user_data['createddate'] = gmdate("Y-m-d H:i:s");
                         $user_data['isactive'] = 1;
                         if ($emp_identity_code != '') {
                             $emp_id = $emp_identity_code . str_pad($user_model->getMaxEmpId($emp_identity_code), 4, '0', STR_PAD_LEFT);
                         } else {
                             $emp_id = '';
                         }
                         $user_data['employeeId'] = $emp_id;
                         $user_id = $user_model->SaveorUpdateUserData($user_data, '');
                         $emp_data['user_id'] = $newOrgHead;
                         $emp_data['createdby'] = $loginUserId;
                         $emp_data['createddate'] = gmdate("Y-m-d H:i:s");
                         $emp_data['isactive'] = 1;
                         $emp_data['is_orghead'] = 1;
                         $employeeModal->SaveorUpdateEmployeeData($emp_data, '');
                     }
                     if ($filecopy == 'success') {
                         $this->_helper->getHelper("FlashMessenger")->addMessage("Organization information updated successfully.");
                     } else {
                         $this->_helper->getHelper("FlashMessenger")->addMessage("Organization information updated successfully but failed to upload the logo.");
                     }
                 } else {
                     //start of saving into employee table
                     $user_data['createdby'] = $loginUserId;
                     $user_data['createddate'] = gmdate("Y-m-d H:i:s");
                     $user_data['isactive'] = 1;
                     if ($emp_identity_code != '') {
                         $emp_id = $emp_identity_code . str_pad($user_model->getMaxEmpId($emp_identity_code), 4, '0', STR_PAD_LEFT);
                     } else {
                         $emp_id = '';
                     }
                     $user_data['employeeId'] = $emp_id;
                     $user_id = $user_model->SaveorUpdateUserData($user_data, '');
                     $emp_data['user_id'] = $user_id;
                     $emp_data['createdby'] = $loginUserId;
                     $emp_data['createddate'] = gmdate("Y-m-d H:i:s");
                     $emp_data['isactive'] = 1;
                     $emp_data['is_orghead'] = 1;
                     $employeeModal->SaveorUpdateEmployeeData($emp_data, '');
                     $tableid = $Id;
                     if ($filecopy == 'success') {
                         $this->_helper->getHelper("FlashMessenger")->addMessage("Organization information saved successfully.");
                     } else {
                         $this->_helper->getHelper("FlashMessenger")->addMessage("Organization information saved successfully but failed to upload the logo.");
                     }
                 }
                 $menuID = ORGANISATIONINFO;
                 try {
                     if ($Id != '' && $Id != 'update') {
                         $result = sapp_Global::logManager($menuID, $actionflag, $loginUserId, $Id);
                     } else {
                         $result = sapp_Global::logManager($menuID, $actionflag, $loginUserId, $id);
                     }
                 } catch (Exception $e) {
                     echo $e->getMessage();
                 }
                 /* Send Mail to the user */
                 if ($Id != 'update') {
                     $base_url = 'http://' . $this->getRequest()->getHttpHost() . $this->getRequest()->getBaseUrl();
                     $view = $this->getHelper('ViewRenderer')->view;
                     $this->view->emp_name = $userfullname;
                     $this->view->password = $emppassword;
                     $this->view->emp_id = $employeeId;
                     $this->view->base_url = $base_url;
                     $text = $view->render('mailtemplates/newpassword.phtml');
                     $options['subject'] = APPLICATION_NAME . ': login credentials';
                     $options['header'] = 'Greetings from Sentrifugo';
                     $options['toEmail'] = $emailaddress;
                     $options['toName'] = $this->view->emp_name;
                     $options['message'] = $text;
                     $result = sapp_Global::_sendEmail($options);
                 }
                 /* END */
                 $db->commit();
                 $this->_redirect('organisationinfo');
             } catch (Exception $e) {
                 $db->rollBack();
                 return 'failed';
             }
         } else {
             $messages = $form->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 (isset($this->msgarray['domain'])) {
                 $this->view->msMsg = 'multiselecterror';
             }
         }
     }
     $this->view->msgarray = $msgarray;
     $this->view->popConfigPermission = $popConfigPermission;
 }
 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();
     $new_stateId = '';
     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();
     $new_stateId = '';
     $new_cityId = '';
     $id = $this->getRequest()->getParam('id');
     $form = new Default_Form_Organisationinfo();
     $orgInfoModel = new Default_Model_Organisationinfo();
     $countriesModel = new Default_Model_Countries();
     $statesmodel = new Default_Model_States();
     $citiesmodel = new Default_Model_Cities();
     $wizard_model = new Default_Model_Wizard();
     $allCountriesData = $countriesModel->fetchAll('isactive=1', 'country')->toArray();
     $allStatesData = $statesmodel->fetchAll('isactive=1', 'state')->toArray();
     $allCitiesData = $citiesmodel->fetchAll('isactive=1', 'city')->toArray();
     $flag = 'true';
     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 ($id) {
         $form->submit->setLabel('Update');
         try {
             $data = $orgInfoModel->getOrganisationData($id);
             $form->setAttrib('action', DOMAIN . 'organisationinfo/edit/id/' . $id);
             $data['org_startdate'] = sapp_Global::change_date($data['org_startdate'], 'view');
             $form->populate($data);
             $countryId = $data['country'];
             $stateId = $data['state'];
             $cityId = $data['city'];
             $actionpage = 'edit';
             if (count($_POST) > 0) {
                 $countryId = isset($_POST['country']) ? $_POST['country'] : "";
                 $stateId = isset($_POST['state']) ? $_POST['state'] : "";
                 $cityId = isset($_POST['city']) ? $_POST['city'] : "";
             }
             if ($countryId != '') {
                 $statesData = $statesmodel->getBasicStatesList((int) $countryId);
                 foreach ($statesData as $res) {
                     if ($stateId == $res['state_id_org']) {
                         $new_stateId = $res['state_id_org'] . '!@#' . utf8_encode($res['state']);
                     }
                     $form->state->addMultiOption($res['state_id_org'] . '!@#' . utf8_encode($res['state']), utf8_encode($res['state']));
                 }
                 if (count($_POST) == 0) {
                     $stateId = $new_stateId;
                 }
             }
             if ($stateId != '') {
                 $citiesData = $citiesmodel->getBasicCitiesList((int) $stateId);
                 foreach ($citiesData as $res) {
                     if ($cityId == $res['city_org_id']) {
                         $new_cityId = $res['city_org_id'] . '!@#' . utf8_encode($res['city']);
                     }
                     $form->city->addMultiOption($res['city_org_id'] . '!@#' . utf8_encode($res['city']), utf8_encode($res['city']));
                 }
                 if (count($_POST) == 0) {
                     $cityId = $new_cityId;
                 }
             }
             $form->setDefault('country', $countryId);
             $form->setDefault('state', $stateId);
             $form->setDefault('city', $cityId);
             $this->view->domainValue = $data['domain'];
             $this->view->org_image = $data['org_image'];
             $this->view->ermsg = '';
             $this->view->datarr = $data;
         } catch (Exception $e) {
             $this->view->ermsg = 'nodata';
         }
     } else {
         $wizardData = $wizard_model->getWizardData();
         sapp_Global::buildlocations($form, $wizardData);
     }
     $this->view->form = $form;
     if (!empty($allCountriesData) && !empty($allStatesData) && !empty($allCitiesData)) {
         $this->view->configuremsg = '';
     } else {
         $this->view->configuremsg = 'notconfigurable';
     }
     $this->view->msgarray = $msgarray;
     if ($this->getRequest()->getPost()) {
         $result = $this->saveorginfo($form, $loginUserId);
         $this->view->msgarray = $result;
         if (isset($this->msgarray['domain'])) {
             $this->view->msMsg = 'multiselecterror';
         }
     }
     $this->view->popConfigPermission = $popConfigPermission;
 }