public function save($employeeform)
 {
     $emproleStr = '';
     $roleArr = array();
     $empgroupStr = '';
     $auth = Zend_Auth::getInstance();
     if ($auth->hasIdentity()) {
         $loginUserId = $auth->getStorage()->read()->id;
     }
     $usersModel = new Default_Model_Usermanagement();
     $employeeModal = new Default_Model_Employee();
     $requimodel = new Default_Model_Requisition();
     $candidate_model = new Default_Model_Candidatedetails();
     $orgInfoModel = new Default_Model_Organisationinfo();
     $unitid = '';
     $deptid = '';
     $errorflag = 'true';
     $msgarray = array();
     $id = $this->_request->getParam('id');
     $businessunit_id = $this->_request->getParam('businessunit_id', null);
     $department_id = $this->_request->getParam('department_id', null);
     $reporting_manager = $this->_request->getParam('reporting_manager', null);
     $jobtitle_id = $this->_request->getParam('jobtitle_id', null);
     $position_id = $this->_request->getParam('position_id', null);
     $user_id = $this->_getParam('user_id', null);
     $prefix_id = $this->_getParam('prefix_id', null);
     $extension_number = $this->_getParam('extension_number', null);
     $office_number = $this->_request->getParam('office_number', null);
     $office_faxnumber = $this->_request->getParam('office_faxnumber', null);
     $date_of_joining = $this->_request->getParam('date_of_joining', null);
     $date_of_joining = sapp_Global::change_date($date_of_joining, 'database');
     $isvalidorgstartdate = $orgInfoModel->validateEmployeeJoiningDate($date_of_joining, $unitid, $deptid);
     if (!empty($isvalidorgstartdate)) {
         $msgarray['date_of_joining'] = 'Employee joining date should be greater than organization start date.';
         $errorflag = 'false';
     }
     if ($employeeform->isValid($this->_request->getPost()) && $errorflag == 'true') {
         $id = $this->_request->getParam('id');
         $emp_status_id = $this->_request->getParam('emp_status_id', null);
         $date_of_leaving = $this->_request->getParam('date_of_leaving', null);
         $date_of_leaving = sapp_Global::change_date($date_of_leaving, 'database');
         $years_exp = $this->_request->getParam('years_exp');
         //FOR USER table
         $employeeId = $this->_getParam('employeeId', null);
         $modeofentry = $this->_getParam('modeofentry', null);
         $firstname = trim($this->_getParam('firstname', null));
         $lastname = trim($this->_getParam('lastname', null));
         $userfullname = $firstname . ' ' . $lastname;
         $emprole = $this->_getParam('emprole', null);
         //roleid_group_id
         if ($emprole != "") {
             $roleArr = explode('_', $emprole);
             if (!empty($roleArr)) {
                 $emproleStr = $roleArr[0];
                 $empgroupStr = $roleArr[0];
             }
         }
         $emailaddress = $this->_getParam('emailaddress', null);
         //end of user table
         $date = new Zend_Date();
         $menumodel = new Default_Model_Menu();
         $empstatusarray = array(8, 9, 10);
         $actionflag = '';
         $tableid = '';
         $trDb = Zend_Db_Table::getDefaultAdapter();
         // starting transaction
         $trDb->beginTransaction();
         try {
             $emppassword = sapp_Global::generatePassword();
             $user_data = array('emprole' => $emproleStr, 'firstname' => $firstname != '' ? $firstname : NULL, 'lastname' => $lastname != '' ? $lastname : NULL, 'userfullname' => $userfullname, 'emailaddress' => $emailaddress, 'jobtitle_id' => $jobtitle_id, 'modifiedby' => $loginUserId, 'modifieddate' => gmdate("Y-m-d H:i:s"), 'emppassword' => md5($emppassword), 'employeeId' => $employeeId, 'modeofentry' => $id == '' ? $modeofentry : "", 'selecteddate' => $date_of_joining, 'candidatereferredby' => 0, 'userstatus' => 'old');
             if ($id != '') {
                 $where = array('user_id=?' => $user_id);
                 $actionflag = 2;
                 $user_where = "id = " . $user_id;
                 unset($user_data['candidatereferredby']);
                 unset($user_data['userstatus']);
                 unset($user_data['emppassword']);
                 unset($user_data['employeeId']);
                 unset($user_data['modeofentry']);
             } else {
                 $user_data['createdby'] = $loginUserId;
                 $user_data['createddate'] = gmdate("Y-m-d H:i:s");
                 $user_data['isactive'] = 1;
                 $where = '';
                 $actionflag = 1;
                 $user_where = '';
                 $identity_code_model = new Default_Model_Identitycodes();
                 $identity_codes = $identity_code_model->getIdentitycodesRecord();
                 $emp_identity_code = isset($identity_codes[0]) ? $identity_codes[0]['employee_code'] : "";
                 if ($emp_identity_code != '') {
                     $emp_id = $emp_identity_code . str_pad($usersModel->getMaxEmpId($emp_identity_code), 4, '0', STR_PAD_LEFT);
                 } else {
                     $emp_id = '';
                 }
                 $user_data['employeeId'] = $emp_id;
             }
             $user_status = $usersModel->SaveorUpdateUserData($user_data, $user_where);
             if ($id == '') {
                 $user_id = $user_status;
             }
             $data = array('user_id' => $user_id, 'reporting_manager' => $reporting_manager, 'emp_status_id' => $emp_status_id, 'businessunit_id' => $businessunit_id, 'department_id' => $department_id, 'jobtitle_id' => $jobtitle_id, 'position_id' => $position_id, 'prefix_id' => $prefix_id, 'extension_number' => $extension_number != '' ? $extension_number : NULL, 'office_number' => $office_number != '' ? $office_number : NULL, 'office_faxnumber' => $office_faxnumber != '' ? $office_faxnumber : NULL, 'date_of_joining' => $date_of_joining, 'date_of_leaving' => $date_of_leaving != '' ? $date_of_leaving : NULL, 'years_exp' => $years_exp == '' ? null : $years_exp, 'modifiedby' => $loginUserId, 'modifieddate' => gmdate("Y-m-d H:i:s"));
             if ($id == '') {
                 $data['createdby'] = $loginUserId;
                 $data['createddate'] = gmdate("Y-m-d H:i:s");
                 $data['isactive'] = 1;
             }
             $Id = $employeeModal->SaveorUpdateEmployeeData($data, $where);
             $statuswhere = array('id=?' => $user_id);
             if ($id != '') {
                 if (in_array($emp_status_id, $empstatusarray)) {
                     $isactivestatus = '';
                     if ($emp_status_id == 8) {
                         $isactivestatus = 2;
                     } else {
                         if ($emp_status_id == 9) {
                             $isactivestatus = 3;
                         } else {
                             if ($emp_status_id == 10) {
                                 $isactivestatus = 4;
                             }
                         }
                     }
                     $statusdata = array('isactive' => $isactivestatus);
                     $empstatusId = $usersModel->SaveorUpdateUserData($statusdata, $statuswhere);
                     $employeeModal->SaveorUpdateEmployeeData($statusdata, "user_id = " . $user_id);
                 } else {
                     $edata = $usersModel->getUserDataById($id);
                     $statusdata = array('isactive' => 1);
                     if ($edata['isactive'] != 0) {
                         if ($edata['emptemplock'] == 1) {
                             $statusdata = array('isactive' => 0);
                         }
                         $empstatusId = $usersModel->SaveorUpdateUserData($statusdata, $statuswhere);
                         $employeeModal->SaveorUpdateEmployeeData($statusdata, "user_id = " . $user_id);
                     }
                 }
             }
             if ($Id == 'update') {
                 $tableid = $id;
                 $this->_helper->getHelper("FlashMessenger")->addMessage(array("success" => "Employee details updated successfully."));
             } else {
                 //start of mailing
                 $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 of mailing
                 $tableid = $Id;
                 $this->_helper->getHelper("FlashMessenger")->addMessage(array("success" => "Employee details added successfully."));
             }
             $menuidArr = $menumodel->getMenuObjID('/employee');
             $menuID = $menuidArr[0]['id'];
             $result = sapp_Global::logManager($menuID, $actionflag, $loginUserId, $user_id);
             $trDb->commit();
             // Send email to employee when his details are edited by other user.
             $options['subject'] = APPLICATION_NAME . ': Employee details updated';
             $options['header'] = 'Employee details updated';
             $options['toEmail'] = $emailaddress;
             $options['toName'] = $userfullname;
             $options['message'] = 'Dear ' . $userfullname . ', your employee details are updated.';
             $options['cron'] = 'yes';
             if (!empty($id)) {
                 sapp_Global::_sendEmail($options);
             }
             $this->_redirect('myemployees/edit/id/' . $user_id);
         } catch (Exception $e) {
             $trDb->rollBack();
             $msgarray['employeeId'] = "Something went wrong, please try again later.";
             return $msgarray;
         }
     } else {
         $messages = $employeeform->getMessages();
         foreach ($messages as $key => $val) {
             foreach ($val as $key2 => $val2) {
                 $msgarray[$key] = $val2;
                 break;
             }
         }
         if (isset($jobtitle_id) && $jobtitle_id != 0 && $jobtitle_id != '') {
             $positionsmodel = new Default_Model_Positions();
             $positionlistArr = $positionsmodel->getPositionList($jobtitle_id);
             $employeeform->position_id->clearMultiOptions();
             $employeeform->position_id->addMultiOption('', 'Select Position');
             foreach ($positionlistArr as $positionlistRes) {
                 $employeeform->position_id->addMultiOption($positionlistRes['id'], utf8_encode($positionlistRes['positionname']));
             }
             if (isset($position_id) && $position_id != 0 && $position_id != '') {
                 $employeeform->setDefault('position_id', $position_id);
             }
         }
         return $msgarray;
     }
 }
 public function updateempdetails($employeeform)
 {
     $emproleStr = '';
     $roleArr = array();
     $auth = Zend_Auth::getInstance();
     if ($auth->hasIdentity()) {
         $loginUserId = $auth->getStorage()->read()->id;
     }
     $usersModel = new Default_Model_Usermanagement();
     $employeeModal = new Default_Model_Employee();
     $businessunit_id = $this->_request->getParam('businessunit_id', null);
     $department_id = $this->_request->getParam('department_id', null);
     $reporting_manager = $this->_request->getParam('reporting_manager', null);
     $jobtitle_id = $this->_request->getParam('jobtitle_id', null);
     $position_id = $this->_request->getParam('position_id', null);
     $user_id = $this->_getParam('user_id', null);
     $prefix_id = $this->_getParam('prefix_id', null);
     $extension_number = $this->_getParam('extension_number', null);
     if ($employeeform->isValid($this->_request->getPost())) {
         $id = $this->_request->getParam('id');
         $emp_status_id = $this->_request->getParam('emp_status_id', null);
         $date_of_joining = $this->_request->getParam('date_of_joining', null);
         $date_of_joining = sapp_Global::change_date($date_of_joining, 'database');
         $date_of_leaving = $this->_request->getParam('date_of_leaving', null);
         $date_of_leaving = sapp_Global::change_date($date_of_leaving, 'database');
         $years_exp = $this->_request->getParam('years_exp');
         //FOR USER table
         $employeeId = $this->_getParam('employeeId', null);
         $modeofentry = $this->_getParam('modeofentry', null);
         $hid_modeofentry = $this->_getParam('hid_modeofentry', null);
         $other_modeofentry = $this->_getParam('other_modeofentry', null);
         $userfullname = $this->_getParam('userfullname', null);
         $candidatereferredby = $this->_getParam('candidatereferredby', null);
         $rccandidatename = $this->_getParam('rccandidatename', null);
         $emprole = $this->_getParam('emprole', null);
         //roleid_group_id
         if ($emprole != "") {
             $roleArr = explode('_', $emprole);
             if (!empty($roleArr)) {
                 $emproleStr = $roleArr[0];
             }
         }
         $emailaddress = $this->_getParam('emailaddress', null);
         $tmp_name = $this->_request->getParam('tmp_emp_name', null);
         $act_inact = $this->_request->getParam("act_inact", null);
         //end of user table
         $date = new Zend_Date();
         $menumodel = new Default_Model_Menu();
         $empstatusarray = array(8, 9, 10);
         $actionflag = '';
         $tableid = '';
         if ($modeofentry == 'Direct' || $hid_modeofentry == 'Direct') {
             $candidate_key = 'userfullname';
             $candidate_value = $userfullname;
             $emp_name = $userfullname;
             $candidate_flag = 'no';
         } else {
             $candidate_key = 'rccandidatename';
             $candidate_value = $rccandidatename;
             $emp_name = $tmp_name;
             $candidate_flag = 'yes';
         }
         $trDb = Zend_Db_Table::getDefaultAdapter();
         // starting transaction
         $trDb->beginTransaction();
         try {
             $emppassword = sapp_Global::generatePassword();
             $user_data = array('emprole' => $emproleStr, $candidate_key => $candidate_value, 'emailaddress' => $emailaddress, 'modifiedby' => $loginUserId, 'modifieddate' => Zend_Registry::get('currentdate'), 'emppassword' => md5($emppassword), 'employeeId' => $employeeId, 'modeofentry' => $id == '' ? $modeofentry : "", 'selecteddate' => $date_of_joining, 'candidatereferredby' => $candidatereferredby, 'userstatus' => 'old', 'other_modeofentry' => $other_modeofentry);
             if ($id != '') {
                 $where = array('user_id=?' => $user_id);
                 $actionflag = 2;
                 $user_where = "id = " . $user_id;
                 unset($user_data['candidatereferredby']);
                 unset($user_data['userstatus']);
                 unset($user_data['emppassword']);
                 unset($user_data['employeeId']);
                 unset($user_data['modeofentry']);
                 unset($user_data['other_modeofentry']);
             } else {
                 $data['createdby'] = $loginUserId;
                 $data['createddate'] = gmdate("Y-m-d H:i:s");
                 $data['isactive'] = 1;
                 $user_data['createdby'] = $loginUserId;
                 $user_data['createddate'] = gmdate("Y-m-d H:i:s");
                 $user_data['isactive'] = 1;
                 if ($modeofentry != 'Direct') {
                     $user_data['userfullname'] = $emp_name;
                 }
                 $where = '';
                 $actionflag = 1;
                 $user_where = '';
             }
             $user_status = $usersModel->SaveorUpdateUserData($user_data, $user_where);
             if ($id == '') {
                 $user_id = $user_status;
             }
             $data = array('user_id' => $user_id, 'reporting_manager' => $reporting_manager, 'emp_status_id' => $emp_status_id, 'businessunit_id' => $businessunit_id, 'department_id' => $department_id, 'jobtitle_id' => $jobtitle_id, 'position_id' => $position_id, 'prefix_id' => $prefix_id, 'extension_number' => $extension_number, 'date_of_joining' => $date_of_joining, 'date_of_leaving' => $date_of_leaving != '' ? $date_of_leaving : NULL, 'years_exp' => $years_exp == '' ? null : $years_exp, 'modifiedby' => $loginUserId, 'modifieddate' => gmdate("Y-m-d H:i:s"));
             $Id = $employeeModal->SaveorUpdateEmployeeData($data, $where);
             $statuswhere = array('id=?' => $user_id);
             if (in_array($emp_status_id, $empstatusarray)) {
                 $isactivestatus = '';
                 if ($emp_status_id == 8) {
                     $isactivestatus = 2;
                 } else {
                     if ($emp_status_id == 9) {
                         $isactivestatus = 3;
                     } else {
                         if ($emp_status_id == 10) {
                             $isactivestatus = 4;
                         }
                     }
                 }
                 $statusdata = array('isactive' => $isactivestatus);
                 $empstatusId = $usersModel->SaveorUpdateUserData($statusdata, $statuswhere);
             } else {
                 $statusdata = array('isactive' => 1);
                 $empstatusId = $usersModel->SaveorUpdateUserData($statusdata, $statuswhere);
             }
             if ($Id == 'update') {
                 $tableid = $id;
                 $this->_helper->getHelper("FlashMessenger")->addMessage(array("success" => "Employee details updated successfully."));
             } else {
                 //start of mailing
                 $base_url = 'http://' . $this->getRequest()->getHttpHost() . $this->getRequest()->getBaseUrl();
                 $view = $this->getHelper('ViewRenderer')->view;
                 $this->view->emp_name = $emp_name;
                 $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 of mailing
                 $tableid = $Id;
                 $this->_helper->getHelper("FlashMessenger")->addMessage(array("success" => "Employee details added successfully."));
             }
             $menuidArr = $menumodel->getMenuObjID('/employee');
             $menuID = $menuidArr[0]['id'];
             $result = sapp_Global::logManager($menuID, $actionflag, $loginUserId, $tableid);
             $menuidArr = $menumodel->getMenuObjID('/usermanagement');
             $menuID_user = $menuidArr[0]['id'];
             $result = sapp_Global::logManager($menuID, $actionflag, $loginUserId, $user_id);
             if ($act_inact == 1) {
                 if ($user_data['isactive'] == 1) {
                     $act_str = array("Activated" => Zend_Registry::get('currentdate'));
                 } else {
                     $act_str = array("Inactivated" => Zend_Registry::get('currentdate'));
                 }
                 $result = sapp_Global::logManager($menuID_user, 4, $loginUserId, $user_id, '', $act_str);
             }
             $trDb->commit();
             $this->_redirect('employee/edit/id/' . $user_id);
         } catch (Exception $e) {
             $trDb->rollBack();
             $msgarray['employeeId'] = "Something went wrong,please try again later.";
             return $msgarray;
         }
     } else {
         $messages = $employeeform->getMessages();
         foreach ($messages as $key => $val) {
             foreach ($val as $key2 => $val2) {
                 $msgarray[$key] = $val2;
                 break;
             }
         }
         $usersModel = new Default_Model_Users();
         if (isset($businessunit_id) && $businessunit_id != 0 && $businessunit_id != '') {
             $departmentsmodel = new Default_Model_Departments();
             $departmentlistArr = $departmentsmodel->getDepartmentList($businessunit_id);
             $employeeform->department_id->clearMultiOptions();
             $employeeform->reporting_manager->clearMultiOptions();
             $employeeform->department_id->addMultiOption('', 'Select Department');
             foreach ($departmentlistArr as $departmentlistresult) {
                 $employeeform->department_id->addMultiOption($departmentlistresult['id'], utf8_encode($departmentlistresult['deptname']));
             }
             if (isset($department_id) && $department_id != 0 && $department_id != '') {
                 $employeeform->setDefault('department_id', $department_id);
             }
         }
         if (isset($department_id) && $department_id != 0 && $department_id != '') {
             $reportingManagerArr = $usersModel->getReportingManagerList($department_id, $user_id);
             $employeeform->reporting_manager->addMultiOption('', 'Select Reporting Manager');
             foreach ($reportingManagerArr as $reportingManagerresult) {
                 $employeeform->reporting_manager->addMultiOption($reportingManagerresult['id'], utf8_encode($reportingManagerresult['userfullname']));
             }
             if (isset($reporting_manager) && $reporting_manager != 0 && $reporting_manager != '') {
                 $employeeform->setDefault('reporting_manager', $reporting_manager);
             }
         }
         if (isset($jobtitle_id) && $jobtitle_id != 0 && $jobtitle_id != '') {
             $positionsmodel = new Default_Model_Positions();
             $positionlistArr = $positionsmodel->getPositionList($jobtitle_id);
             $employeeform->position_id->clearMultiOptions();
             $employeeform->position_id->addMultiOption('', 'Select Position');
             foreach ($positionlistArr as $positionlistRes) {
                 $employeeform->position_id->addMultiOption($positionlistRes['id'], utf8_encode($positionlistRes['positionname']));
             }
             if (isset($position_id) && $position_id != 0 && $position_id != '') {
                 $employeeform->setDefault('position_id', $position_id);
             }
         }
         return $msgarray;
     }
 }
Beispiel #3
0
 public function sessiontourAction()
 {
     $auth = Zend_Auth::getInstance();
     if ($auth->hasIdentity()) {
         $loginUserId = $auth->getStorage()->read()->id;
     }
     $usermanagementModel = new Default_Model_Usermanagement();
     $status = $usermanagementModel->SaveorUpdateUserData(array('tourflag' => 1), "id=" . $loginUserId);
     if ($status == 'update') {
         $auth->getStorage()->read()->tourflag = 1;
     }
     $this->_helper->json($status);
 }
Beispiel #4
0
 public static function process_emp_excel($file_name)
 {
     require_once 'Classes/PHPExcel.php';
     require_once 'Classes/PHPExcel/IOFactory.php';
     $auth = Zend_Auth::getInstance();
     if ($auth->hasIdentity()) {
         $loginUserId = $auth->getStorage()->read()->id;
     }
     $emp_model = new Default_Model_Employee();
     $usersModel = new Default_Model_Usermanagement();
     $identity_code_model = new Default_Model_Identitycodes();
     $objReader = PHPExcel_IOFactory::createReaderForFile($file_name);
     $objPHPExcel = $objReader->load($file_name);
     //Read first sheet
     $sheet = $objPHPExcel->getSheet(0);
     // Get worksheet dimensions
     $sizeOfWorksheet = $sheet->getHighestDataRow();
     $highestColumn = $sheet->getHighestDataColumn();
     if ($sizeOfWorksheet > 1) {
         $arrReqHeaders = array('Prefix', 'First name', 'Last name', 'Role Type', 'Email', 'Business Unit', 'Department', 'Reporting manager', 'Job Title', 'Position', 'Employment Status', 'Date of joining', 'Date of leaving', 'Experience', 'Extension', 'Work telephone number', 'Fax');
         //Get first/header from excel
         $firstRow = $sheet->rangeToArray('A' . 1 . ':' . $highestColumn . 1, NULL, TRUE, TRUE);
         $arrGivenHeaders = $firstRow[0];
         $diffArray = array_diff_assoc($arrReqHeaders, $arrGivenHeaders);
         $prefix_arr = $emp_model->getPrefix_emp_excel();
         $roles_arr = $emp_model->getRoles_emp_excel();
         $bu_arr = $emp_model->getBU_emp_excel();
         $dep_arr = $emp_model->getDep_emp_excel();
         $job_arr = $emp_model->getJobs_emp_excel();
         $positions_arr = $emp_model->getPositions_emp_excel();
         $users_arr = $emp_model->getUsers_emp_excel();
         $emp_stat_arr = $emp_model->getEstat_emp_excel();
         $dol_emp_stat_arr = $emp_model->getDOLEstat_emp_excel();
         $mng_roles_arr = $emp_model->getMngRoles_emp_excel();
         $emps_arr = $emp_model->getEmps_emp_excel();
         $emails_arr = $emps_arr['email'];
         $emp_ids_arr = $emps_arr['ids'];
         $emp_depts_arr = $emp_model->getEmpsDeptWise();
         $dept_bu_arr = $emp_model->getDeptBUWise();
         $pos_jt_arr = $emp_model->getPosJTWise();
         $identity_codes = $identity_code_model->getIdentitycodesRecord();
         $emp_identity_code = isset($identity_codes[0]) ? $identity_codes[0]['employee_code'] : "";
         $trDb = Zend_Db_Table::getDefaultAdapter();
         // starting transaction
         $trDb->beginTransaction();
         try {
             //start of validations
             $ex_prefix_arr = array();
             //$ex_fullname_arr = array();
             $ex_firstname_arr = array();
             $ex_lastname_arr = array();
             $ex_role_arr = array();
             $ex_email_arr = array();
             $ex_bu_arr = array();
             $ex_dep_arr = array();
             $ex_rm_arr = array();
             $ex_jt_arr = array();
             $ex_pos_arr = array();
             $ex_es_arr = array();
             $ex_doj_arr = array();
             $ex_dol_arr = array();
             $ex_exp_arr = array();
             $ex_ext_arr = array();
             $ex_wn_arr = array();
             $ex_fax_arr = array();
             $tot_rec_cnt = 0;
             $err_msg = "";
             for ($i = 2; $i <= $sizeOfWorksheet; $i++) {
                 $rowData_org = $sheet->rangeToArray('A' . $i . ':' . $highestColumn . $i, NULL, TRUE, TRUE);
                 $rowData = $rowData_org[0];
                 $rowData_cpy = $rowData;
                 foreach ($rowData_cpy as $rkey => $rvalue) {
                     $rowData[$rkey] = trim($rvalue);
                 }
                 //start of mandatory checking
                 if (empty($rowData[0])) {
                     $err_msg = "Prefix cannot be empty at row " . $i . ".";
                     break;
                 }
                 /* if(empty($rowData[1]))
                    {
                        $err_msg = "Full Name cannot be empty at row ".$i.".";
                        break;
                    }*/
                 if (empty($rowData[1])) {
                     $err_msg = "First name cannot be empty at row " . $i . ".";
                     break;
                 }
                 if (empty($rowData[2])) {
                     $err_msg = "Last name cannot be empty at row " . $i . ".";
                     break;
                 }
                 if (empty($rowData[3])) {
                     $err_msg = "Role type cannot be empty at row " . $i . ".";
                     break;
                 }
                 if (empty($rowData[4])) {
                     $err_msg = "Email cannot be empty at row " . $i . ".";
                     break;
                 }
                 if (empty($rowData[7])) {
                     $err_msg = "Reporting manager cannot be empty at row " . $i . ".";
                     break;
                 }
                 if (empty($rowData[8])) {
                     $err_msg = "Job title cannot be empty at row " . $i . ".";
                     break;
                 }
                 if (empty($rowData[9])) {
                     $err_msg = "Position cannot be empty at row " . $i . ".";
                     break;
                 }
                 if (empty($rowData[10])) {
                     $err_msg = "Employment status cannot be empty at row " . $i . ".";
                     break;
                 }
                 if (empty($rowData[11])) {
                     $err_msg = "Date of joining cannot be empty at row " . $i . ".";
                     break;
                 }
                 if (!in_array($rowData[3], $mng_roles_arr) && empty($rowData[6])) {
                     $err_msg = "Department cannot be empty at row " . $i . ".";
                     break;
                 }
                 if (in_array($rowData[10], $dol_emp_stat_arr) && empty($rowData[12])) {
                     $err_msg = "Date of leaving cannot be empty at row " . $i . ".";
                     break;
                 }
                 if (!in_array($rowData[10], $dol_emp_stat_arr) && !empty($rowData[12]) && in_array($rowData[10], $emp_stat_arr)) {
                     $err_msg = "Date of leaving must be empty for '" . $rowData[10] . "' at row " . $i . ".";
                     break;
                 }
                 // end of mandatory checking
                 // start of pattern checking
                 if (!preg_match("/^(?=.*[a-zA-Z])([^ ][a-zA-Z0-9 ]*)\$/", trim($rowData[0])) && !empty($rowData[0])) {
                     $err_msg = "Prefix is not a valid format at row " . $i . ".";
                     break;
                 }
                 /* if (!preg_match("/^([a-zA-Z.]+ ?)+$/", $rowData[1])  && !empty($rowData[1]))
                    {
                        $err_msg = "Full Name is not a valid format at row ".$i.".";
                        break;
                    }*/
                 if (!preg_match("/^([a-zA-Z.]+ ?)+\$/", $rowData[1]) && !empty($rowData[1])) {
                     $err_msg = "First name is not a valid format at row " . $i . ".";
                     break;
                 }
                 if (!preg_match("/^([a-zA-Z.]+ ?)+\$/", $rowData[2]) && !empty($rowData[2])) {
                     $err_msg = "Last name is not a valid format at row " . $i . ".";
                     break;
                 }
                 if (!preg_match("/^[a-zA-Z]+?\$/", $rowData[3]) && !empty($rowData[3])) {
                     $err_msg = "Role type is not a valid format at row " . $i . ".";
                     break;
                 }
                 if (!preg_match("/^(?!.*\\.{2})[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\\.[a-zA-Z0-9-.]+\$/", $rowData[4]) && !empty($rowData[4])) {
                     $err_msg = "Email is not a valid format at row " . $i . ".";
                     break;
                 }
                 if (!preg_match("/^[a-zA-Z0-9\\&\\'\\.\\s]+\$/", $rowData[5]) && !empty($rowData[5])) {
                     $err_msg = "Business unit is not a valid format at row " . $i . ".";
                     break;
                 }
                 if (!preg_match("/^[a-zA-Z0-9\\&\\'\\.\\s]+\$/", $rowData[6]) && !empty($rowData[6])) {
                     $err_msg = "Department is not a valid format at row " . $i . ".";
                     break;
                 }
                 if (!preg_match("/^[a-zA-Z0-9\\&\\'\\.\\s]+\$/", $rowData[7]) && !empty($rowData[7])) {
                     $err_msg = "Reporting manager is not a valid format at row " . $i . ".";
                     break;
                 }
                 if (!preg_match("/^[a-zA-Z][a-zA-Z0-9\\s]*\$/", $rowData[8]) && !empty($rowData[8])) {
                     $err_msg = "Job title is not a valid format at row " . $i . ".";
                     break;
                 }
                 if (!preg_match("/^[a-zA-Z][a-zA-Z0-9\\-\\s]*\$/i", $rowData[9]) && !empty($rowData[9])) {
                     $err_msg = "Position is not a valid format at row " . $i . ".";
                     break;
                 }
                 if (!preg_match("/^(?=.*[a-zA-Z])([^ ][a-zA-Z0-9 ]*)\$/", $rowData[10]) && !empty($rowData[10])) {
                     $err_msg = "Employment status is not a valid format at row " . $i . ".";
                     break;
                 }
                 if (!empty($rowData[11])) {
                     try {
                         $test_doj = new DateTime($rowData[11]);
                     } catch (Exception $ex) {
                         return array('status' => 'error', 'msg' => "Date of joining is not a valid format at row " . $i . ".");
                     }
                 }
                 if (!empty($rowData[12])) {
                     try {
                         $test_dol = new DateTime($rowData[12]);
                     } catch (Exception $ex) {
                         return array('status' => 'error', 'msg' => "Date of leaving is not a valid format at row " . $i . ".");
                     }
                 }
                 if (!empty($rowData[12]) && $rowData[12] < $rowData[11]) {
                     $err_msg = "Date of leaving must be greater than date of joining at row " . $i . ".";
                     break;
                 }
                 if (!preg_match("/^[0-9]\\d{0,1}(\\.\\d*)?\$/", $rowData[13]) && !empty($rowData[13])) {
                     $err_msg = "Experience is not a valid format at row " . $i . ".";
                     break;
                 }
                 if (!preg_match("/^[0-9]+\$/", $rowData[14]) && !empty($rowData[14])) {
                     $err_msg = "Extension is not a valid format at row " . $i . ".";
                     break;
                 }
                 if (!preg_match("/^(?!0{10})[0-9\\+\\-\\)\\(]+\$/", $rowData[15]) && !empty($rowData[15])) {
                     $err_msg = "Work telephone number is not a valid format at row " . $i . ".";
                     break;
                 }
                 if (!preg_match("/^[0-9\\+\\-\\)\\(]+\$/", $rowData[16]) && !empty($rowData[16])) {
                     $err_msg = "Fax is not a valid format at row " . $i . ".";
                     break;
                 }
                 // end of pattern checking
                 // start of checking existence in the system.
                 if (!array_key_exists(strtolower($rowData[0]), $prefix_arr) && !empty($rowData[0])) {
                     $err_msg = "Unknown prefix at row " . $i . ".";
                     break;
                 }
                 if (!array_key_exists(strtolower($rowData[3]), $roles_arr) && !empty($rowData[3])) {
                     $err_msg = "Unknown role type at row " . $i . ".";
                     break;
                 }
                 if (!array_key_exists(strtolower($rowData[5]), $bu_arr) && !empty($rowData[5])) {
                     $err_msg = "Unknown business unit at row " . $i . ".";
                     break;
                 }
                 if (!array_key_exists(strtolower($rowData[6]), $dep_arr) && !empty($rowData[6])) {
                     $err_msg = "Unknown department at row " . $i . ".";
                     break;
                 }
                 if (in_array(strtolower($rowData[4]), $emails_arr) && !empty($rowData[4])) {
                     $err_msg = "Email already exists at row " . $i . ".";
                     break;
                 }
                 if (!in_array(strtolower($rowData[7]), $emp_ids_arr) && !empty($rowData[7])) {
                     $err_msg = "Unknown reporting manager at row " . $i . ".";
                     break;
                 }
                 if (!array_key_exists(strtolower($rowData[8]), $job_arr) && !empty($rowData[8])) {
                     $err_msg = "Unknown job title at row " . $i . ".";
                     break;
                 }
                 if (!array_key_exists(strtolower($rowData[9]), $positions_arr) && !empty($rowData[9])) {
                     $err_msg = "Unknown position at row " . $i . ".";
                     break;
                 }
                 if (!array_key_exists(strtolower($rowData[10]), $emp_stat_arr) && !empty($rowData[10])) {
                     $err_msg = "Unknown employment status at row " . $i . ".";
                     break;
                 }
                 // end of checking existence in the system.
                 if (!empty($rowData[6])) {
                     if (isset($emp_depts_arr[$dep_arr[strtolower($rowData[6])]]) && !in_array(strtolower($rowData[7]), $emp_depts_arr[$dep_arr[strtolower($rowData[6])]])) {
                         if (isset($emp_depts_arr[0]) && is_array($emp_depts_arr[0])) {
                             if (!in_array(strtolower($rowData[7]), $emp_depts_arr[0])) {
                                 $err_msg = "Reporting manager is not belongs to '" . $rowData[6] . "' department at row " . $i . ".";
                                 break;
                             }
                         }
                     }
                 } else {
                     if (isset($emp_depts_arr[0]) && is_array($emp_depts_arr[0])) {
                         if (!in_array(strtolower($rowData[7]), $emp_depts_arr[0])) {
                             $err_msg = "Reporting manager is not belongs to management group at row " . $i . ".";
                             break;
                         }
                     }
                 }
                 if (!empty($rowData[6])) {
                     if (isset($dept_bu_arr[0]) && is_array($dept_bu_arr[0])) {
                         if (in_array(strtolower($rowData[6]), $dept_bu_arr[0]) && !empty($rowData[5])) {
                             $err_msg = "Business unit not needed for this department '" . $rowData[6] . "' at row " . $i . ".";
                             break;
                         }
                         if (!in_array(strtolower($rowData[6]), $dept_bu_arr[0]) && empty($rowData[5])) {
                             $err_msg = "Business unit cannot be empty at row " . $i . ".";
                             break;
                         }
                     }
                     if (!empty($rowData[5])) {
                         if (isset($dept_bu_arr[$bu_arr[strtolower($rowData[5])]]) && !in_array(strtolower($rowData[6]), $dept_bu_arr[$bu_arr[strtolower($rowData[5])]]) && !empty($rowData[5])) {
                             $err_msg = "Department is not belongs to '" . $rowData[5] . "' business unit at row " . $i . ".";
                             break;
                         }
                     }
                 }
                 if (!empty($rowData[8]) && !empty($rowData[9])) {
                     if (isset($pos_jt_arr[$job_arr[strtolower($rowData[8])]]) && !in_array(strtolower($rowData[9]), $pos_jt_arr[$job_arr[strtolower($rowData[8])]]) && !empty($rowData[8])) {
                         $err_msg = "Position is not belongs to '" . $rowData[8] . "' job title at row " . $i . ".";
                         break;
                     }
                 }
             }
             //end of for loop
             if (!empty($err_msg)) {
                 return array('status' => 'error', 'msg' => $err_msg);
             }
             $err_msg = "";
             for ($i = 2; $i <= $sizeOfWorksheet; $i++) {
                 $rowData_org = $sheet->rangeToArray('A' . $i . ':' . $highestColumn . $i, NULL, TRUE, TRUE);
                 $rowData = $rowData_org[0];
                 $rowData_cpy = $rowData;
                 foreach ($rowData_cpy as $rkey => $rvalue) {
                     $rowData[$rkey] = trim($rvalue);
                 }
                 $ex_prefix_arr[] = $rowData[0];
                 //$ex_fullname_arr[] = $rowData[1];
                 $ex_firstname_arr[] = $rowData[1];
                 $ex_lastname_arr[] = $rowData[2];
                 $ex_role_arr[] = $rowData[3];
                 $ex_email_arr[$i] = $rowData[4];
                 $ex_bu_arr[] = $rowData[5];
                 $ex_dep_arr[] = $rowData[6];
                 $ex_rm_arr[] = $rowData[7];
                 $ex_jt_arr[] = $rowData[8];
                 $ex_pos_arr[] = $rowData[9];
                 $ex_es_arr[] = $rowData[10];
                 $ex_doj_arr[] = $rowData[11];
                 $ex_dol_arr[] = $rowData[12];
                 $ex_exp_arr[] = $rowData[13];
                 $ex_ext_arr[] = $rowData[14];
                 $ex_wn_arr[] = $rowData[15];
                 $ex_fax_arr[] = $rowData[16];
                 $tot_rec_cnt++;
             }
             foreach ($ex_email_arr as $key1 => $value1) {
                 $d = 0;
                 foreach ($ex_email_arr as $key2 => $value2) {
                     if ($key1 != $key2 && $value1 == $value2) {
                         $err_msg = "Duplicate email entry at row " . $key2 . ".";
                         $d++;
                         break;
                     }
                 }
                 if ($d > 0) {
                     break;
                 }
             }
             if (!empty($err_msg)) {
                 return array('status' => 'error', 'msg' => $err_msg);
             }
             //end of validations
             //start of saving
             if ($tot_rec_cnt > 0) {
                 for ($i = 2; $i <= $sizeOfWorksheet; $i++) {
                     $emp_id = $emp_identity_code . str_pad($usersModel->getMaxEmpId($emp_identity_code), 4, '0', STR_PAD_LEFT);
                     $rowData_org = $sheet->rangeToArray('A' . $i . ':' . $highestColumn . $i, NULL, TRUE, TRUE);
                     $rowData = $rowData_org[0];
                     $rowData_cpy = $rowData;
                     foreach ($rowData_cpy as $rkey => $rvalue) {
                         $rowData[$rkey] = trim($rvalue);
                     }
                     $emppassword = sapp_Global::generatePassword();
                     $date = new DateTime($rowData[11]);
                     $date_of_joining = $date->format('Y-m-d');
                     $date_of_leaving = "";
                     if ($rowData[12] != '') {
                         $ldate = new DateTime($rowData[12]);
                         $date_of_leaving = $ldate->format('Y-m-d');
                     }
                     $userfullname = $rowData[1] . ' ' . $rowData[2];
                     $user_data = array('emprole' => $roles_arr[strtolower($rowData[3])], 'userfullname' => $userfullname, 'firstname' => $rowData[1], 'lastname' => $rowData[2], 'emailaddress' => $rowData[4], 'jobtitle_id' => $job_arr[strtolower($rowData[8])], 'modifiedby' => $loginUserId, 'modifieddate' => gmdate("Y-m-d H:i:s"), 'emppassword' => md5($emppassword), 'employeeId' => $emp_id, 'modeofentry' => "Direct", 'selecteddate' => $date_of_joining, 'userstatus' => 'old');
                     $user_data['createdby'] = $loginUserId;
                     $user_data['createddate'] = gmdate("Y-m-d H:i:s");
                     $user_data['isactive'] = 1;
                     $user_id = $usersModel->SaveorUpdateUserData($user_data, '');
                     $data = array('user_id' => $user_id, 'reporting_manager' => $users_arr[strtolower($rowData[7])], 'emp_status_id' => $emp_stat_arr[strtolower($rowData[10])], 'businessunit_id' => !empty($rowData[4]) ? $bu_arr[strtolower($rowData[5])] : 0, 'department_id' => !empty($rowData[5]) ? $dep_arr[strtolower($rowData[6])] : null, 'jobtitle_id' => $job_arr[strtolower($rowData[8])], 'position_id' => $positions_arr[strtolower($rowData[9])], 'prefix_id' => $prefix_arr[strtolower($rowData[0])], 'extension_number' => $rowData[13] != '' ? $rowData[14] : NULL, 'office_number' => $rowData[14] != '' ? $rowData[15] : NULL, 'office_faxnumber' => $rowData[15] != '' ? $rowData[16] : NULL, 'date_of_joining' => $date_of_joining, 'date_of_leaving' => $date_of_leaving != '' ? $date_of_leaving : NULL, 'years_exp' => $rowData[13] == '' ? null : $rowData[13], 'modifiedby' => $loginUserId, 'modifieddate' => gmdate("Y-m-d H:i:s"));
                     $data['createdby'] = $loginUserId;
                     $data['createddate'] = gmdate("Y-m-d H:i:s");
                     $data['isactive'] = 1;
                     $emp_model->SaveorUpdateEmployeeData($data, '');
                     $text = "<div style='padding: 0; text-align: left; font-size:14px; font-family:Arial, Helvetica, sans-serif;'>\t\t\t\t\n\t<span style='color:#3b3b3b;'>Hello " . ucfirst($userfullname) . ",</span><br />\n\t\n\t<div style='padding:20px 0 0 0;color:#3b3b3b;'>You have been added to " . APPLICATION_NAME . ". The login credentials for your Sentrifugo account are:</div>\n\t\n\t<div style='padding:20px 0 0 0;color:#3b3b3b;'>Username: <strong>" . $emp_id . "</strong></div>\n\t<div style='padding:5px 0 0 0;color:#3b3b3b;'>Password: <strong>" . $emppassword . "</strong></div>\n\t\n\t<div style='padding:20px 0 10px 0;'>Please <a href='" . DOMAIN . "index/popup' target='_blank' style='color:#b3512f;'>click here</a> to login  to your Sentrifugo account.</div>\n\n</div>";
                     $options['subject'] = APPLICATION_NAME . ': Login Credentials';
                     $options['header'] = 'Greetings from Sentrifugo';
                     $options['toEmail'] = $rowData[4];
                     $options['toName'] = $userfullname;
                     $options['message'] = $text;
                     $options['cron'] = 'yes';
                     $result = sapp_Global::_sendEmail($options);
                 }
                 //end of for loop
                 $trDb->commit();
                 return array('status' => "success", 'msg' => 'Employees saved successfully.');
             } else {
                 return array('status' => 'error', 'msg' => "No records to save.");
             }
             //end of saving
         } catch (Exception $e) {
             $trDb->rollBack();
             return array('status' => 'error', 'msg' => "Something went wrong,please try again.");
         }
     } else {
         return array('status' => 'error', 'msg' => "No records to save.");
     }
 }
Beispiel #5
0
 public function changeRM($oldRM, $newRM, $status, $ishead)
 {
     $auth = Zend_Auth::getInstance();
     if ($auth->hasIdentity()) {
         $loginUserId = $auth->getStorage()->read()->id;
     }
     $db = Zend_Db_Table::getDefaultAdapter();
     $db->beginTransaction();
     $oldRMData = $this->getsingleEmployeeData($oldRM);
     try {
         if ($status == 'active') {
             $data = array('isactive' => 1, 'emptemplock' => 0, 'modifieddate' => gmdate("Y-m-d H:i:s"), 'modifiedby' => $loginUserId);
             $Query1 = "UPDATE main_employees SET isactive = 1, modifieddate = '" . gmdate("Y-m-d H:i:s") . "', modifiedby = " . $loginUserId . " WHERE user_id=" . $oldRM . " ;";
             $db->query($Query1);
         } else {
             if ($status == 'inactive') {
                 $data = array('isactive' => 0, 'emptemplock' => 1, 'modifieddate' => gmdate("Y-m-d H:i:s"), 'modifiedby' => $loginUserId);
             }
         }
         $where = "id = " . $oldRM;
         $user_model = new Default_Model_Usermanagement();
         $result = $user_model->SaveorUpdateUserData($data, $where);
         if ($status == 'inactive') {
             $empQuery1 = "UPDATE main_employees SET reporting_manager = " . $newRM . ", modifieddate = '" . gmdate("Y-m-d H:i:s") . "', modifiedby = " . $loginUserId . " WHERE reporting_manager=" . $oldRM . " and isactive = 1 AND user_id <> " . $newRM . ";";
             $empQuery2 = "UPDATE main_employees SET reporting_manager = " . $oldRMData[0]['reporting_manager'] . ", modifieddate = '" . gmdate("Y-m-d H:i:s") . "', modifiedby = " . $loginUserId . " WHERE reporting_manager=" . $oldRM . " and isactive = 1 AND user_id = " . $newRM . ";";
             if ($ishead == '1') {
                 $orgQuery1 = "UPDATE main_employees SET is_orghead = 0,isactive = 0, reporting_manager= " . $newRM . ", modifieddate = '" . gmdate("Y-m-d H:i:s") . "', modifiedby = " . $loginUserId . " WHERE user_id=" . $oldRM . " ;";
                 $db->query($orgQuery1);
                 $orgQuery2 = "UPDATE main_employees SET is_orghead = 1,reporting_manager= 0, modifieddate = '" . gmdate("Y-m-d H:i:s") . "', modifiedby = " . $loginUserId . " WHERE user_id=" . $newRM . " ;";
                 $db->query($orgQuery2);
             }
             $db->query($empQuery1);
             $db->query($empQuery2);
         }
         $db->commit();
         return 'success';
     } catch (Exception $e) {
         return 'failed';
         $db->rollBack();
     }
 }
 public function addemppopupAction()
 {
     $flag = 'true';
     $controllername = 'employee';
     $msgarray = array();
     $emptyFlag = 0;
     Zend_Layout::getMvcInstance()->setLayoutPath(APPLICATION_PATH . "/layouts/scripts/popup/");
     $auth = Zend_Auth::getInstance();
     if ($auth->hasIdentity()) {
         $loginUserId = $auth->getStorage()->read()->id;
     }
     $deptidforhead = $this->_getParam('deptidforhead', null);
     $report_opt = array();
     $emp_form = new Default_Form_employee();
     $user_model = new Default_Model_Usermanagement();
     $role_model = new Default_Model_Roles();
     $prefixModel = new Default_Model_Prefix();
     $identity_code_model = new Default_Model_Identitycodes();
     $jobtitlesModel = new Default_Model_Jobtitles();
     $deptModel = new Default_Model_Departments();
     $positionsmodel = new Default_Model_Positions();
     $employeeModal = new Default_Model_Employee();
     $usersModel2 = new Default_Model_Users();
     $employmentstatusModel = new Default_Model_Employmentstatus();
     $emp_form->setAction(BASE_URL . 'employee/addemppopup/deptidforhead/' . $deptidforhead);
     $emp_form->removeElement('department_id');
     $emp_form->removeElement('modeofentry');
     $identity_codes = $identity_code_model->getIdentitycodesRecord();
     $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';
     }
     $emp_form->employeeId->setValue($emp_id);
     $role_data = $role_model->getRolesList_Dept();
     $emp_form->emprole->addMultiOptions(array('' => 'Select Role') + $role_data);
     if (empty($role_data)) {
         $msgarray['emprole'] = 'Roles are not configured yet.';
         $flag = 'false';
     }
     $prefixData = $prefixModel->getPrefixList();
     $emp_form->prefix_id->addMultiOption('', 'Select Prefix');
     if (!empty($prefixData)) {
         foreach ($prefixData as $prefixres) {
             $emp_form->prefix_id->addMultiOption($prefixres['id'], $prefixres['prefix']);
         }
     } else {
         $msgarray['prefix_id'] = 'Prefixes are not configured yet.';
         //$flag = 'false';
     }
     $jobtitleData = $jobtitlesModel->getJobTitleList();
     if (!empty($jobtitleData)) {
         foreach ($jobtitleData as $jobtitleres) {
             $emp_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.';
         //$flag = 'false';
     }
     if (isset($_POST['jobtitle_id']) && $_POST['jobtitle_id'] != '') {
         $positionlistArr = $positionsmodel->getPositionList($_POST['jobtitle_id']);
         if (sizeof($positionlistArr) > 0) {
             $emp_form->position_id->addMultiOption('', 'Select Position');
             foreach ($positionlistArr as $positionlistres) {
                 $emp_form->position_id->addMultiOption($positionlistres['id'], $positionlistres['positionname']);
             }
         }
     }
     $employmentStatusData = $employmentstatusModel->getempstatusActivelist();
     $emp_form->emp_status_id->addMultiOption('', 'Select Employment Status');
     if (!empty($employmentStatusData)) {
         foreach ($employmentStatusData as $employmentStatusres) {
             $emp_form->emp_status_id->addMultiOption($employmentStatusres['workcodename'], $employmentStatusres['statusname']);
         }
     } else {
         $msgarray['emp_status_id'] = 'Employment status is not configured yet.';
         $emptyFlag++;
     }
     $reportingManagerData = $usersModel2->getReportingManagerList_employees('', '', MANAGEMENT_GROUP);
     if (!empty($reportingManagerData)) {
         $report_opt = $reportingManagerData;
         if (isset($_POST['reporting_manager']) && $_POST['reporting_manager'] != '') {
             $emp_form->setDefault('reporting_manager', $_POST['reporting_manager']);
         }
     } else {
         $msgarray['reporting_manager'] = 'Reporting managers are not added yet.';
         $flag = 'false';
     }
     if ($this->getRequest()->getPost()) {
         if ($emp_form->isValid($this->_request->getPost()) && $flag == 'true') {
             $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');
             $date_of_leaving = $this->_request->getParam('date_of_leaving', null);
             $date_of_leaving = sapp_Global::change_date($date_of_leaving, 'database');
             $employeeId = $this->_getParam('employeeId', null);
             $emprole = $this->_getParam('emprole', null);
             $reporting_manager = $this->_getParam('reporting_manager', null);
             $emailaddress = $this->_getParam('emailaddress', null);
             $emppassword = sapp_Global::generatePassword();
             $firstname = trim($this->_getParam('firstname', null));
             $lastname = trim($this->_getParam('lastname', null));
             $userfullname = $firstname . ' ' . $lastname;
             //$userfullname = trim($this->_request->getParam('userfullname',null));
             $prefix_id = $this->_getParam('prefix_id', null);
             $user_id = $this->_getParam('user_id', null);
             $emp_status_id = $this->_getParam('emp_status_id', null);
             $user_data = array('emprole' => $emprole, 'firstname' => $firstname != '' ? $firstname : NULL, 'lastname' => $lastname != '' ? $lastname : NULL, 'userfullname' => $userfullname, 'emailaddress' => $emailaddress, 'jobtitle_id' => $jobtitle_id, 'modifiedby' => $loginUserId, 'modifieddate' => gmdate("Y-m-d H:i:s"), 'emppassword' => md5($emppassword), 'employeeId' => $employeeId, 'modeofentry' => 'Direct', 'selecteddate' => $date_of_joining, 'userstatus' => 'old');
             $emp_data = array('user_id' => $user_id, 'jobtitle_id' => $jobtitle_id, 'position_id' => $position_id, 'prefix_id' => $prefix_id, 'department_id' => $deptidforhead, 'reporting_manager' => $reporting_manager, 'date_of_joining' => $date_of_joining, 'date_of_leaving' => $date_of_leaving != '' ? $date_of_leaving : NULL, 'emp_status_id' => $emp_status_id, 'modifiedby' => $loginUserId, 'modifieddate' => gmdate("Y-m-d H:i:s"));
             $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;
             $employeeModal->SaveorUpdateEmployeeData($emp_data, '');
             //end of saving into employee table.
             $tableid = $user_id;
             $actionflag = 1;
             $menuID = ORGANISATIONINFO;
             try {
                 $result = sapp_Global::logManager($menuID, $actionflag, $loginUserId, $tableid);
             } catch (Exception $e) {
             }
             $managementUsersData = $deptModel->getDeptHeads();
             $opt = '';
             foreach ($managementUsersData as $record) {
                 $opt .= sapp_Global::selectOptionBuilder($record['id'], $record['userfullname']);
             }
             $this->view->managementUsersData = $opt;
             /* Send Mail to the user */
             $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 */
             $this->view->eventact = 'added';
             $close = 'close';
             $this->view->popup = $close;
         } else {
             $messages = $emp_form->getMessages();
             foreach ($messages as $key => $val) {
                 foreach ($val as $key2 => $val2) {
                     $msgarray[$key] = $val2;
                     break;
                 }
             }
             $this->view->msgarray = $msgarray;
         }
     }
     $this->view->msgarray = $msgarray;
     $this->view->report_opt = $report_opt;
     $this->view->controllername = $controllername;
     $this->view->emp_form = $emp_form;
 }
 public function addorgheadAction()
 {
     Zend_Layout::getMvcInstance()->setLayoutPath(APPLICATION_PATH . "/layouts/scripts/popup/");
     $auth = Zend_Auth::getInstance();
     if ($auth->hasIdentity()) {
         $loginUserId = $auth->getStorage()->read()->id;
         $loginuserRole = $auth->getStorage()->read()->emprole;
         $loginuserGroup = $auth->getStorage()->read()->group_id;
     }
     $org_id = $this->_request->getParam('orgid', null);
     $msgarray = array();
     $prevorgheadId = '';
     $posted_prevorghead_rm = '';
     try {
         $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();
         $form = new Default_Form_Organisationhead();
         $form->setAttrib('action', BASE_URL . 'organisationinfo/addorghead/orgid/' . $org_id);
         $identity_codes = $identity_code_model->getIdentitycodesRecord();
         $role_data = $role_model->getRolesList_orginfo();
         $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($role_data)) {
             $msgarray['emprole'] = 'Roles are not added 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.';
         }
         $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']);
                 }
             }
         }
         if (isset($_POST['prevorghead_rm']) && $_POST['prevorghead_rm'] != '') {
             $posted_prevorghead_rm = $_POST['prevorghead_rm'];
         }
         $orgheadsData = $employeeModal->getEmployeesForOrgHead();
         $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)) {
                 $prevorgheadId = $user_data->id;
             } else {
                 $form->removeElement('prevorghead_rm');
             }
         } else {
             $form->removeElement('prevorghead_rm');
         }
         if ($this->getRequest()->getPost()) {
             if ($form->isValid($this->_request->getPost()) && $flag != 'false') {
                 $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_head', null), 'database');
                 $employeeId = $this->_request->getParam('employeeId', null);
                 $emprole = $this->_request->getParam('emprole', null);
                 $emailaddress = $this->_request->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 = trim($this->_request->getParam('orghead',null));
                 $userfullname = $first_name . ' ' . $last_name;
                 $prefix_id = $this->_request->getParam('prefix_id', null);
                 $user_id = $this->_request->getParam('user_id', null);
                 $prevorghead_rm = $this->_request->getParam('prevorghead_rm', null);
                 $prevheadid = $this->_request->getParam('prevheadid', null);
                 $user_data = array('emprole' => $emprole, 'firstname' => $first_name, 'lastname' => $last_name, 'userfullname' => $userfullname, 'emailaddress' => $emailaddress, 'jobtitle_id' => $jobtitle_id, 'emppassword' => md5($emppassword), 'employeeId' => $employeeId, 'selecteddate' => $date_of_joining, 'userstatus' => 'old', 'modeofentry' => 'Direct', 'createdby' => $loginUserId, 'createddate' => gmdate("Y-m-d H:i:s"), 'modifiedby' => $loginUserId, 'modifieddate' => gmdate("Y-m-d H:i:s"), 'isactive' => 1);
                 $emp_data = array('jobtitle_id' => $jobtitle_id, 'position_id' => $position_id, 'prefix_id' => $prefix_id, 'reporting_manager' => 0, 'date_of_joining' => $date_of_joining, 'createdby' => $loginUserId, 'createddate' => gmdate("Y-m-d H:i:s"), 'modifiedby' => $loginUserId, 'modifieddate' => gmdate("Y-m-d H:i:s"), 'isactive' => 1, 'is_orghead' => 1);
                 $org_data = array('modifiedby' => $loginUserId, 'modifieddate' => gmdate("Y-m-d H:i:s"));
                 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;
                 $db = Zend_Db_Table::getDefaultAdapter();
                 $db->beginTransaction();
                 try {
                     $user_id = $user_model->SaveorUpdateUserData($user_data, '');
                     $emp_data['user_id'] = $user_id;
                     $employeeModal->SaveorUpdateEmployeeData($emp_data, '');
                     if (isset($prevheadid) && $prevheadid != '') {
                         $org_data['orghead'] = $user_id;
                         $orgwhere = array('id=?' => $org_id);
                         $orgInfoModel->SaveorUpdateData($org_data, $orgwhere);
                         $orgInfoModel->changeOrgHead($prevheadid, $user_id, $prevorghead_rm);
                         $this->sendmailstoemployees($prevheadid, $user_id);
                     }
                     $tableid = $user_id;
                     $actionflag = 1;
                     $menuID = EMPLOYEE;
                     try {
                         $result = sapp_Global::logManager($menuID, $actionflag, $loginUserId, $tableid);
                     } catch (Exception $e) {
                         echo $e->getMessage();
                     }
                     $close = 'close';
                     $this->view->popup = $close;
                     $this->view->eventact = 'added';
                     $db->commit();
                 } catch (Exception $e) {
                     $db->rollBack();
                 }
             } else {
                 $messages = $form->getMessages();
                 foreach ($messages as $key => $val) {
                     foreach ($val as $key2 => $val2) {
                         $msgarray[$key] = $val2;
                         break;
                     }
                 }
             }
         }
         $this->view->prevorgheadId = $prevorgheadId;
         $this->view->form = $form;
         $this->view->msgarray = $msgarray;
         $this->view->orgheadsData = $orgheadsData;
         $this->view->posted_prevorghead_rm = $posted_prevorghead_rm;
     } catch (Exception $e) {
         echo $e->getMessage();
         die;
     }
 }
 /**
  * This action is used to delete roles and their child data.
  * @parameters
  * @param objid    =   id of role.
  * 
  * @return String    success/failure message 
  */
 public function deleteAction()
 {
     $auth = Zend_Auth::getInstance();
     if ($auth->hasIdentity()) {
         $loginUserId = $auth->getStorage()->read()->id;
     }
     $baseUrl = $this->generateBaseurl();
     $id = $this->_request->getParam('objid');
     $messages['message'] = '';
     $actionflag = 3;
     $agencyuser = '******';
     $Id = '';
     if ($id) {
         $user_model = new Default_Model_Usermanagement();
         $menumodel = new Default_Model_Menu();
         $agencylistmodel = new Default_Model_Agencylist();
         $agencyroles = $agencylistmodel->getagencyrole();
         $userData = $user_model->getUserDataById($id);
         $user_role = $userData['emprole'];
         foreach ($agencyroles as $agrole) {
             if ($agrole['id'] == $user_role) {
                 $agencyuser = '******';
             }
         }
         $data = array('isactive' => 0, 'modifiedby' => $loginUserId, 'modifieddate' => gmdate("Y-m-d H:i:s"));
         $where = array('id=?' => $id);
         $Id = $user_model->SaveorUpdateUserData($data, $where);
         if ($agencyuser == 'yes') {
             $agencyData = $user_model->getAgencyData($id);
             $user_model->deleteAllagencydetails($agencyData['agencyid'], $loginUserId);
             $emailids = $agencylistmodel->getAllHRManagementEMails();
             $this->sendEMails($agencyData, 'inactivated');
         }
         if ($Id == 'update') {
             $objidArr = $menumodel->getMenuObjID('/roles');
             $objID = $objidArr[0]['id'];
             $result = sapp_Global::logManager($objID, $actionflag, $loginUserId, $id);
             $messages['message'] = 'User deleted successfully';
             $messages['msgtype'] = 'success';
         } else {
             $messages['message'] = 'User cannot be deleted';
             $messages['msgtype'] = 'error';
         }
     } else {
         $messages['message'] = 'User cannot be deleted';
         $messages['msgtype'] = 'error';
     }
     $this->_helper->json($messages);
 }