public function editAction()
 {
     $auth = Zend_Auth::getInstance();
     $role_datap = array();
     $empGroup = "";
     if ($auth->hasIdentity()) {
         $loginUserId = $auth->getStorage()->read()->id;
         $loginuserRole = $auth->getStorage()->read()->emprole;
         $loginuserGroup = $auth->getStorage()->read()->group_id;
         $loginuserUnitID = $auth->getStorage()->read()->businessunit_id;
         $loginuserDeptID = $auth->getStorage()->read()->department_id;
     }
     $id = (int) $this->getRequest()->getParam('id');
     $id = abs($id);
     if ($id == '') {
         $id = $loginUserId;
     }
     $callval = $this->getRequest()->getParam('call');
     if ($callval == 'ajaxcall') {
         $this->_helper->layout->disableLayout();
     }
     $employeeform = new Default_Form_Myteamemployee();
     try {
         if ($id != '' && is_numeric($id) && $id > 0 && $id != $loginUserId) {
             $employeeModal = new Default_Model_Employee();
             $usersModel = new Default_Model_Users();
             $employmentstatusModel = new Default_Model_Employmentstatus();
             $busineesUnitModel = new Default_Model_Businessunits();
             $deptModel = new Default_Model_Departments();
             $role_model = new Default_Model_Roles();
             $user_model = new Default_Model_Usermanagement();
             $candidate_model = new Default_Model_Candidatedetails();
             $jobtitlesModel = new Default_Model_Jobtitles();
             $positionsmodel = new Default_Model_Positions();
             $prefixModel = new Default_Model_Prefix();
             $data = array();
             $empDeptId = "";
             $empRoleId = "";
             $data = $employeeModal->getsingleEmployeeData($id);
             if ($data == 'norows') {
                 $this->view->rowexist = "norows";
             } else {
                 if (!empty($data)) {
                     $this->view->rowexist = "rows";
                     $employeeform->submit->setLabel('Update');
                     $data = $data[0];
                     /* Earlier code to fetch employee details */
                     $employeeData = $employeeModal->getsingleEmployeeData($id);
                     $roles_arr = $role_model->getRolesListByGroupID(EMPLOYEE_GROUP);
                     if (sizeof($roles_arr) > 0) {
                         $employeeform->emprole->addMultiOptions(array('' => 'Select Role') + $roles_arr);
                     }
                     $employmentStatusData = $employmentstatusModel->getempstatuslist();
                     if (sizeof($employmentStatusData) > 0) {
                         $employeeform->emp_status_id->addMultiOption('', 'Select Employment Status');
                         foreach ($employmentStatusData as $employmentStatusres) {
                             $employeeform->emp_status_id->addMultiOption($employmentStatusres['workcodename'], $employmentStatusres['statusname']);
                         }
                     }
                     $businessunitData = $busineesUnitModel->getDeparmentList();
                     if (sizeof($businessunitData) > 0) {
                         foreach ($businessunitData as $businessunitres) {
                             if ($businessunitres['id'] == $loginuserUnitID) {
                                 $employeeform->businessunit_id->addMultiOption($businessunitres['id'], $businessunitres['unitname']);
                             }
                         }
                     }
                     $departmentsData = $deptModel->getDepartmentList($data['businessunit_id']);
                     if (sizeof($departmentsData) > 0) {
                         foreach ($departmentsData as $departmentsres) {
                             if ($departmentsres['id'] == $loginuserDeptID) {
                                 $employeeform->department_id->addMultiOption($departmentsres['id'], $departmentsres['deptname']);
                             }
                         }
                     }
                     $jobtitleData = $jobtitlesModel->getJobTitleList();
                     if (sizeof($jobtitleData) > 0) {
                         $employeeform->jobtitle_id->addMultiOption('', 'Select Job Title');
                         foreach ($jobtitleData as $jobtitleres) {
                             $employeeform->jobtitle_id->addMultiOption($jobtitleres['id'], $jobtitleres['jobtitlename']);
                         }
                     }
                     $positionlistArr = $positionsmodel->getPositionList($data['jobtitle_id']);
                     if (sizeof($positionlistArr) > 0) {
                         $employeeform->position_id->addMultiOption('', 'Select Position');
                         foreach ($positionlistArr as $positionlistres) {
                             $employeeform->position_id->addMultiOption($positionlistres['id'], $positionlistres['positionname']);
                         }
                     }
                     $prefixData = $prefixModel->getPrefixList();
                     if (!empty($prefixData)) {
                         foreach ($prefixData as $prefixres) {
                             $employeeform->prefix_id->addMultiOption($prefixres['id'], $prefixres['prefix']);
                         }
                     }
                     $userData = $usersModel->getUserDetails($loginUserId);
                     if (count($userData) > 0) {
                         $employeeform->reporting_manager->addMultiOption($userData[0]['id'], $userData[0]['userfullname']);
                     }
                     $employeeform->populate($data);
                     $employeeform->setDefault('user_id', $data['user_id']);
                     $employeeform->setDefault('emp_status_id', $data['emp_status_id']);
                     $employeeform->setDefault('businessunit_id', $data['businessunit_id']);
                     $employeeform->setDefault('jobtitle_id', $data['jobtitle_id']);
                     $employeeform->setDefault('department_id', $data['department_id']);
                     $employeeform->setDefault('position_id', $data['position_id']);
                     $employeeform->setDefault('prefix_id', $data['prefix_id']);
                     $date_of_joining = sapp_Global::change_date($data['date_of_joining'], 'view');
                     $employeeform->date_of_joining->setValue($date_of_joining);
                     if ($data['date_of_leaving'] != '' && $data['date_of_leaving'] != '0000-00-00') {
                         $date_of_leaving = sapp_Global::change_date($data['date_of_leaving'], 'view');
                         $employeeform->date_of_leaving->setValue($date_of_leaving);
                     }
                     $role_data = $role_model->getRoleDataById($data['emprole']);
                     $employeeform->emprole->setValue($data['emprole'] . "_" . $role_data['group_id']);
                     $employeeform->setAttrib('action', DOMAIN . 'myemployees/edit/id/' . $id);
                     $this->view->id = $id;
                     $this->view->form = $employeeform;
                     $this->view->employeedata = !empty($employeeData) ? $employeeData[0] : "";
                     $this->view->messages = $this->_helper->flashMessenger->getMessages();
                     $this->view->data = $data;
                 }
             }
         } else {
             $this->view->rowexist = "norows";
         }
         if ($this->getRequest()->getPost()) {
             $result = $this->save($employeeform);
             $this->view->msgarray = $result;
             $employeeform->modeofentry->setValue($data['modeofentry']);
         }
     } catch (Exception $e) {
         $this->view->rowexist = "norows";
     }
 }
    public function save($processesform, $processdata)
    {
        $baseUrl = DOMAIN;
        $baseUrl = rtrim($baseUrl, '/');
        $auth = Zend_Auth::getInstance();
        if ($auth->hasIdentity()) {
            $loginUserId = $auth->getStorage()->read()->id;
            $loginuserRole = $auth->getStorage()->read()->emprole;
        }
        $usermodel = new Default_Model_Users();
        $hrem = 'true';
        $mngmntem = 'true';
        $agencyEmail = '';
        $lmanager1Email = '';
        $lmanager1Name = 'Manager';
        $agencysalutationName = 'Agency';
        $id = $this->getRequest()->getParam('id');
        $idData = $this->getRequest()->getParam('unitId');
        $idArr = array();
        $idArr = explode('-', $idData);
        $specimen_id = $idArr[0];
        $userflag = $idArr[1];
        $msgarray = array();
        if ($idArr[1] == 2) {
            $flag = 'cand';
            $person = 'candidate';
        } else {
            $flag = 'emp';
            $person = 'employee';
        }
        $processesmodel = new Default_Model_Processes();
        $empscreeningModel = new Default_Model_Empscreening();
        $statusFlag = '';
        $close = '';
        $controllername = 'processes';
        $errorflag = 'true';
        $BGStatus = '';
        $oldbgstatus = '';
        $mailsentflag = 0;
        if (!empty($processdata)) {
            $newStatus = $this->getRequest()->getParam('process_status');
            $previousstatus = $processdata[0]['process_status'];
            $agencyid = $processdata[0]['agencyid'];
            $checktype = $processdata[0]['checktypeid'];
            $processStatus = $processesmodel->getProcessStatus($specimen_id, $userflag, $agencyid, $checktype);
            if (!empty($processStatus) && sizeof($processStatus) > 0) {
                $oldstatus = $processStatus[0]['process_status'];
                $BGStatus = $processStatus[0]['bgcheck_status'];
                /* Check - Adding a record with same userid, agencyid and check type */
                $exists = 'false';
                for ($i = 0; $i < sizeof($processStatus); $i++) {
                    if (($processStatus[$i]['process_status'] == 'On hold' || $processStatus[$i]['process_status'] == 'In process') && $processStatus[$i]['process_status'] == $newStatus) {
                        $exists = 'true';
                    }
                }
                if ($newStatus == $previousstatus) {
                    $msgarray['StatusError'] = "Please change the status.";
                    $errorflag = "false";
                } else {
                    if ($BGStatus != 'Complete' && $exists == 'true') {
                        $msgarray['StatusError'] = "The " . $person . " is already assigned to the selected agency. Please re-assign the " . $person . " to another agency.";
                        $errorflag = "false";
                    }
                }
                /* END */
            }
        } else {
            $checktype = $this->_request->getParam('checktype');
            $radio_pocId = $this->_request->getParam('contactRadio');
            $agencyid = $this->_request->getParam('agencyids');
            $newStatus = 'In process';
            $agencyData = array();
            $agencyPOCData = array();
            if (empty($checktype) && $checktype == '') {
                $msgarray['checktype'] = "Please check atleast one screening type";
                $errorflag = "false";
            } else {
                if (empty($radio_pocId) || $radio_pocId == '') {
                    $msgarray['contactRadio'] = "Please select point of contact";
                    $errorflag = "false";
                }
            }
            if ($checktype) {
                $agencyArr = array();
                $agencyArr = $checktype;
                $agencyData = $empscreeningModel->getAgencyData($agencyArr, '', '');
            }
            if (!isset($agencyid) || $agencyid == '') {
                $agencyid = $this->getRequest()->getParam('defaultagencyid');
            }
            if (!isset($agencyid) || $agencyid == '') {
                $msgarray['agencyids'] = "Please select agency.";
                $errorflag = "false";
            }
            if ($agencyid) {
                $agencyPOCData = $empscreeningModel->getAgencyPOCData($agencyid);
            }
            $this->view->agencyData = $agencyData;
            $this->view->agencyPOCData = $agencyPOCData;
            /* Checking for configurations - screening type and agencies */
            $checktypeModal = new Default_Model_Bgscreeningtype();
            $agencymodel = new Default_Model_Agencylist();
            $typesData = $checktypeModal->fetchAll('isactive=1', 'type')->toArray();
            $agencyData = $agencymodel->fetchAll('isactive=1', 'agencyname')->toArray();
            for ($i = 0; $i < sizeof($agencyPOCData); $i++) {
                if ($agencyPOCData[$i]['id'] == $radio_pocId) {
                    $agencyEmail = $agencyPOCData[$i]['email'];
                    $agencyfname = $agencyPOCData[$i]['first_name'];
                    $agencylname = $agencyPOCData[$i]['last_name'];
                    $agencysalutationName = $agencyfname . ' ' . $agencylname;
                }
            }
            if (empty($typesData)) {
                $msgarray['checktype'] = 'Screening types are not configured yet.';
                $errorflag = 'false';
            }
            if (empty($agencyData)) {
                $msgarray['agencyids'] = 'Agencies are not added yet.';
                $errorflag = 'false';
            }
            $this->view->msgarray = $msgarray;
            /* */
            /* Check - Adding a record with same userid, agencyid and check type (for each check type ) */
            if (is_array($checktype) && $errorflag != "false") {
                for ($i = 0; $i < sizeof($checktype); $i++) {
                    $processStatus = array();
                    $processStatus = $processesmodel->getProcessStatus($specimen_id, $userflag, $agencyid, $checktype[$i]);
                    if (!empty($processStatus) && sizeof($processStatus > 0)) {
                        $exists = 'false';
                        for ($i = 0; $i < sizeof($processStatus); $i++) {
                            if ($processStatus[$i]['process_status'] == 'On hold' || $processStatus[$i]['process_status'] == 'In process') {
                                $exists = 'true';
                            }
                        }
                        $oldstatus = $processStatus[0]['process_status'];
                        $BGStatus = $processStatus[0]['bgcheck_status'];
                        if ($exists == 'true' && $BGStatus != 'Complete') {
                            $msgarray['StatusError'] = "The " . $person . " is already assigned to the selected agency. Please re-assign the " . $person . " to another agency.";
                            $errorflag = "false";
                        }
                    }
                    $oldbgstatusData = $processesmodel->getProcessStatus($specimen_id, $userflag, '', '');
                    if (!empty($oldbgstatusData)) {
                        $oldbgstatus = $oldbgstatusData[0]['bgcheck_status'];
                    } else {
                        $oldbgstatus = '';
                    }
                }
            }
            /* END */
        }
        if ($processesform->isValid($this->_request->getPost()) && $errorflag != 'false') {
            $date = new Zend_Date();
            $menumodel = new Default_Model_Menu();
            $actionflag = '';
            $tableid = '';
            /* 	A New process is created for a user whose background check status is in 'Complete' status. Then updating the bg status to 'In process' */
            if (($BGStatus == 'Complete' || $oldbgstatus == 'Complete' || $BGStatus == 'On hold' || $oldbgstatus == 'On hold') && $newStatus == 'In process') {
                $totalstatusData = array('bgcheck_status' => 'In process', 'modifiedby' => $loginUserId, 'modifieddate' => gmdate("Y-m-d H:i:s"));
                $totalstatusWhere = array('specimen_id=?' => $specimen_id, 'flag=?' => $userflag);
                $empscreeningModel->SaveorUpdateDetails($totalstatusData, $totalstatusWhere);
                /* Updating back ground check status to In process in employees/candidates status */
                if ($userflag == 1) {
                    $empData = array('backgroundchk_status' => 'In process', 'modifiedby' => $loginUserId, 'modifieddate' => gmdate("Y-m-d H:i:s"));
                    $empWhere = array('id=?' => $specimen_id);
                    $usermodel->addOrUpdateUserModel($empData, $empWhere);
                } else {
                    $candModel = new Default_Model_Candidatedetails();
                    $candData = array('backgroundchk_status' => 'In process', 'modifiedby' => $loginUserId, 'modifieddate' => gmdate("Y-m-d H:i:s"));
                    $candWhere = array('id=?' => $specimen_id);
                    $candModel->SaveorUpdateUserData($candData, $candWhere);
                }
                /* END */
                /* Mail to HRD, Line 1 and Line 2 managers that the background checks has been re-opened */
                if ($BGStatus != 'On hold' && $oldbgstatus != 'On hold') {
                    $empData = $empscreeningModel->getEmpPersonalData($specimen_id, $userflag);
                    if ($userflag == 1) {
                        $username = $empData[0]['name'];
                        $lmanager1Email = $empData[0]['rmanager_email'];
                        $lmanager1Name = $empData[0]['reporting_manager'];
                    } else {
                        $username = $empData[0]['candidate_name'];
                        $lmanager1Email = '';
                    }
                    $bid = '';
                    if (isset($empData[0]['businessid'])) {
                        $bid = $empData[0]['businessid'];
                    }
                    if (isset($lmanager1Email) && $lmanager1Email != '') {
                        $manager1 = array($lmanager1Email);
                    } else {
                        $manager1 = array();
                    }
                    if (isset($agencyEmail) && $agencyEmail != '') {
                        $agencyemail1 = array($agencyEmail);
                    } else {
                        $agencyemail1 = array();
                    }
                    if (defined('BG_CHECKS_MNGMNT_' . $bid) && $bid != '') {
                        $mngmntemailId = explode(",", constant('BG_CHECKS_MNGMNT_' . $bid));
                    } else {
                        $mngmntem = 'false';
                        $mngmntemailId = array();
                    }
                    if (defined('BG_CHECKS_HR_' . $bid) && $bid != '') {
                        $hremailId = explode(",", constant('BG_CHECKS_HR_' . $bid));
                    } else {
                        $hrem = 'false';
                        $hremailId = array();
                    }
                    $emailArr = array_merge($agencyemail1, $manager1, $mngmntemailId, $hremailId);
                    for ($i = 0; $i < sizeof($emailArr); $i++) {
                        $salutation = 'Dear Sir/Madam,';
                        if ($i == 0) {
                            $salutation = 'Dear ' . ucfirst($agencysalutationName) . ',';
                            $options['toName'] = ucfirst($agencysalutationName);
                        }
                        if ($i == 1) {
                            $salutation = 'Dear ' . ucfirst($lmanager1Name) . ',';
                            $options['toName'] = ucfirst($lmanager1Name);
                        }
                        if ($i == 2) {
                            $salutation = 'Dear Management,';
                            $options['toName'] = 'Management';
                        }
                        if ($i == 3) {
                            $salutation = 'Dear HR,';
                            $options['toName'] = 'HR';
                        }
                        $options['subject'] = APPLICATION_NAME . ' : Background checks re-opened';
                        $options['header'] = 'Background checks re-opened';
                        $options['toEmail'] = $emailArr[$i];
                        $createdbyName = $usermodel->getUserDetails($loginUserId);
                        if ($i == 0) {
                            $mailsentflag = 1;
                            $options['message'] = '<div>' . $salutation . '<div>The background check for ' . ucfirst($username) . '
													has been re-opened by ' . $createdbyName[0]['userfullname'] . '. </div>
													<div style="padding:20px 0 10px 0;">Please <a href="' . $baseUrl . '/index/popup" target="_blank" style="color:#b3512f;">click here</a> to login and check the details.</div>
												</div>';
                        } else {
                            $options['message'] = '<div>' . $salutation . '<div>The background check for ' . ucfirst($username) . '
													has been re-opened by ' . $createdbyName[0]['userfullname'] . '. </div>
													<div style="padding:20px 0 10px 0;">Please <a href="' . $baseUrl . '/index/popup" target="_blank" style="color:#b3512f;">click here</a> to login and check the details.</div>
												</div>';
                        }
                        $options['cron'] = 'yes';
                        sapp_Global::_sendEmail($options);
                    }
                }
                /* END */
            }
            /* END */
            $data = array('specimen_id' => $specimen_id, 'flag' => $userflag, 'bgagency_id' => $agencyid, 'modifiedby' => $loginUserId, 'modifieddate' => gmdate("Y-m-d H:i:s"));
            if ($id != '') {
                $data['process_status'] = $newStatus;
                $data['explanation'] = NULL;
                $where = array('id=?' => $id);
                $actionflag = 2;
            } else {
                $data['process_status'] = $newStatus;
                $data['bgagency_pocid'] = $radio_pocId;
                $data['createdby'] = $loginUserId;
                $data['createddate'] = gmdate("Y-m-d H:i:s");
                $data['isactive'] = 1;
                $where = '';
                $actionflag = 1;
                if ($newStatus == 'In process' && ($BGStatus != 'Complete' || $oldbgstatus != 'Complete' || $BGStatus != 'On hold' || $oldbgstatus != 'On hold') && $mailsentflag == 0) {
                    $empData = $empscreeningModel->getEmpPersonalData($specimen_id, $userflag);
                    $table = '';
                    if ($userflag == 1) {
                        $username = $empData[0]['name'];
                        $lmanager1Email = $empData[0]['rmanager_email'];
                        $lmanager1Name = $empData[0]['reporting_manager'];
                        $table = '<div>
											<table border="1" style="border-collapse:collapse;">
												<tr><td>Employee ID</td><td>' . $empData[0]['employee_id'] . '</td></tr>
												<tr><td>Employee Email</td><td>' . $empData[0]['email_id'] . '</td></tr>
												<tr><td>Employee Designation</td><td>' . $empData[0]['designation'] . '</td></tr>
											</table>
										</div>';
                    } else {
                        $username = $empData[0]['candidate_name'];
                        $lmanager1Email = '';
                        $table = '<div>Candidate Email : ' . $empData[0]['email'] . '</div>';
                    }
                    if ($agencysalutationName != '') {
                        $salutation = 'Dear ' . ucfirst($agencysalutationName) . ',';
                        $options['toName'] = ucfirst($agencysalutationName);
                    } else {
                        $salutation = 'Dear Sir/Madam,';
                        $options['toName'] = 'Agency';
                    }
                    $createdbyName = $usermodel->getUserDetails($loginUserId);
                    $options['subject'] = APPLICATION_NAME . ' : Background checks initiated';
                    $options['header'] = 'Background checks initiated';
                    $options['toEmail'] = $agencyEmail;
                    $options['message'] = '<div>' . $salutation . '<div>' . ucfirst($username) . ' has been sent for background checks by ' . ucfirst($createdbyName[0]['userfullname']) . '. Please find the details below.</div>' . $table . '
					                    
												<div style="padding:20px 0 10px 0;">Please <a href="' . $baseUrl . '/index/popup" target="_blank" style="color:#b3512f;">click here</a> to login and check the details.</div>
											</div>';
                    $options['cron'] = 'yes';
                    sapp_Global::_sendEmail($options);
                }
            }
            if (is_array($checktype)) {
                for ($i = 0; $i < sizeof($checktype); $i++) {
                    $data['bgcheck_type'] = $checktype[$i];
                    $detailId = $empscreeningModel->SaveorUpdateDetails($data, $where);
                }
            } else {
                $data['bgcheck_type'] = $checktype;
                $detailId = $empscreeningModel->SaveorUpdateDetails($data, $where);
            }
            /* If all the processes are in 'Complete' status, then updating the background check status to 'Complete' and sending mail to HR, reporting manager  */
            $checkAllprocesses = $processesmodel->getProcessStatus($specimen_id, $userflag);
            $completecount = 0;
            $onholdcount = 0;
            for ($i = 0; $i < sizeof($checkAllprocesses); $i++) {
                if ($checkAllprocesses[$i]['process_status'] == 'Complete') {
                    $completecount = $completecount + 1;
                }
            }
            if ($completecount == sizeof($checkAllprocesses)) {
                $totalstatusData = array('bgcheck_status' => 'Complete', 'modifiedby' => $loginUserId, 'modifieddate' => gmdate("Y-m-d H:i:s"));
                $totalstatusWhere = array('specimen_id=?' => $specimen_id, 'flag=?' => $userflag);
                $empscreeningModel->SaveorUpdateDetails($totalstatusData, $totalstatusWhere);
                /* Updating back ground check status to Completed in employees/candidates status */
                if ($userflag == 1) {
                    $usermodel = new Default_Model_Users();
                    $empData = array('backgroundchk_status' => 'Completed', 'modifiedby' => $loginUserId, 'modifieddate' => gmdate("Y-m-d H:i:s"));
                    $empWhere = array('id=?' => $specimen_id);
                    $usermodel->addOrUpdateUserModel($empData, $empWhere);
                } else {
                    $candModel = new Default_Model_Candidatedetails();
                    $candData = array('backgroundchk_status' => 'Completed', 'modifiedby' => $loginUserId, 'modifieddate' => gmdate("Y-m-d H:i:s"));
                    $candWhere = array('id=?' => $specimen_id);
                    $candModel->SaveorUpdateUserData($candData, $candWhere);
                }
                /* END */
                /* Mail to HRD, Line 1 and Line 2 managers */
                if ($newStatus == 'Complete') {
                    $empData = $empscreeningModel->getEmpPersonalData($specimen_id, $userflag);
                    if ($userflag == 1) {
                        $username = $empData[0]['name'];
                        $lmanager1Email = $empData[0]['rmanager_email'];
                        $lmanager1Name = $empData[0]['reporting_manager'];
                    } else {
                        $username = $empData[0]['name'];
                        $lmanager1Email = '';
                    }
                    $bid = '';
                    if (isset($empData[0]['businessid'])) {
                        $bid = $empData[0]['businessid'];
                    }
                    if (isset($lmanager1Email) && $lmanager1Email != '') {
                        $manager1 = array($lmanager1Email);
                    } else {
                        $manager1 = array();
                    }
                    if (defined('BG_CHECKS_MNGMNT_' . $bid) && $bid != '') {
                        $mngmntemailId = explode(",", constant('BG_CHECKS_MNGMNT_' . $bid));
                    } else {
                        $mngmntemailId = array();
                    }
                    if (defined('BG_CHECKS_HR_' . $bid) && $bid != '') {
                        $hremailId = explode(",", constant('BG_CHECKS_HR_' . $bid));
                    } else {
                        $hremailId = array();
                    }
                    $emailArr = array_merge($manager1, $mngmntemailId, $hremailId);
                    for ($i = 0; $i < sizeof($emailArr); $i++) {
                        $salutation = 'Dear Sir/Madam,';
                        if ($i == 0) {
                            $salutation = 'Dear ' . ucfirst($lmanager1Name) . ',';
                            $options['toName'] = ucfirst($lmanager1Name);
                        } else {
                            if ($i == 1) {
                                $salutation = 'Dear Management,';
                                $options['toName'] = 'Management';
                            } else {
                                $salutation = 'Dear HR,';
                                $options['toName'] = 'HR';
                            }
                        }
                        $options['subject'] = APPLICATION_NAME . ' : Background checks completed';
                        $options['header'] = 'Background checks completed';
                        $options['toEmail'] = $emailArr[$i];
                        $options['message'] = '<div>' . $salutation . '<div>The background check for ' . ucfirst($username) . '
													has been completed.</div>
													<div style="padding:20px 0 10px 0;">Please <a href="' . $baseUrl . '/index/popup" target="_blank" style="color:#b3512f;">click here</a> to login and check the details.</div>
												</div>';
                        $options['cron'] = 'yes';
                        sapp_Global::_sendEmail($options);
                    }
                }
                /* END */
            }
            /* End */
            /* If all the processes are in 'On hold' status, then updating the background check status to 'On hold' */
            for ($i = 0; $i < sizeof($checkAllprocesses); $i++) {
                if ($checkAllprocesses[$i]['process_status'] == 'On hold') {
                    $onholdcount = $onholdcount + 1;
                }
            }
            if ($onholdcount == sizeof($checkAllprocesses)) {
                $totalstatusData = array('bgcheck_status' => 'On hold', 'modifiedby' => $loginUserId, 'modifieddate' => gmdate("Y-m-d H:i:s"));
                $totalstatusWhere = array('specimen_id=?' => $specimen_id, 'flag=?' => $userflag);
                $empscreeningModel->SaveorUpdateDetails($totalstatusData, $totalstatusWhere);
                /* Updating back ground check status to Completed in employees/candidates status */
                if ($userflag == 1) {
                    $usermodel = new Default_Model_Users();
                    $empData = array('backgroundchk_status' => 'On hold', 'modifiedby' => $loginUserId, 'modifieddate' => gmdate("Y-m-d H:i:s"));
                    $empWhere = array('id=?' => $specimen_id);
                    $usermodel->addOrUpdateUserModel($empData, $empWhere);
                } else {
                    $candModel = new Default_Model_Candidatedetails();
                    $candData = array('backgroundchk_status' => 'On hold', 'modifiedby' => $loginUserId, 'modifieddate' => gmdate("Y-m-d H:i:s"));
                    $candWhere = array('id=?' => $specimen_id);
                    $candModel->SaveorUpdateUserData($candData, $candWhere);
                }
                /* END */
            }
            /* END */
            if ($detailId == 'update') {
                $tableid = $id;
                $this->view->eventact = 'updated';
            } else {
                $tableid = $detailId;
                $this->view->eventact = 'added';
            }
            $actionflag = 2;
            //Edit of the candidate or employee
            $menuidArr = $menumodel->getMenuObjID('/empscreening');
            $menuID = $menuidArr[0]['id'];
            $result = sapp_Global::logManager($menuID, $actionflag, $loginUserId, $specimen_id . '-' . $userflag);
            $close = 'close';
            $this->view->popup = $close;
        } else {
            $messages = $processesform->getMessages();
            foreach ($messages as $key => $val) {
                foreach ($val as $key2 => $val2) {
                    $msgarray[$key] = $val2;
                    break;
                }
                if (empty($checktypesData)) {
                    $msgarray['checktype'] = 'Screening types are not configured yet.';
                }
                if (empty($checkagencyData)) {
                    $msgarray['agencyids'] = 'Agencies are not added yet.';
                }
            }
            return $msgarray;
        }
        $this->view->statusFlag = $statusFlag;
    }
 public function viewprofileAction()
 {
     $id = '';
     $username = '';
     $email = '';
     $profileimage = '';
     $role = '';
     $auth = Zend_Auth::getInstance();
     if ($auth->hasIdentity()) {
         $auth = $auth->getStorage()->read();
         $id = $auth->id;
         $login_user_role = $auth->emprole;
         $username = $auth->userfullname;
         $email = $auth->emailaddress;
     }
     if ($id == SUPERADMIN) {
         $role = 'true';
     }
     $viewprofileform = new Default_Form_viewprofile();
     $usermodel = new Default_Model_Users();
     $getuserdetails = $usermodel->getUserDetails($id);
     $username = $getuserdetails[0]['userfullname'];
     $email = $getuserdetails[0]['emailaddress'];
     $profileimage = $getuserdetails[0]['profileimg'];
     $viewprofileform->populate($getuserdetails[0]);
     $this->view->id = $id;
     $this->view->username = $username;
     $this->view->email = $email;
     $this->view->profileimage = $profileimage;
     $this->view->login_user_role = $login_user_role;
     $this->view->role = $role;
     $this->view->form = $viewprofileform;
     $this->view->messages = $this->_helper->flashMessenger->getMessages();
     if ($this->getRequest()->getPost()) {
         $result = $this->saveProfileDetails($viewprofileform);
         $this->view->msgarray = $result;
     }
 }
    public function save($empscreeningform)
    {
        $baseUrl = BASE_URL;
        $baseUrl = rtrim($baseUrl, '/');
        $auth = Zend_Auth::getInstance();
        if ($auth->hasIdentity()) {
            $loginUserId = $auth->getStorage()->read()->id;
            $loginuserRole = $auth->getStorage()->read()->emprole;
        }
        $agencyEmail = '';
        $lmanager1Email = '';
        $lmanager1Name = 'Manager';
        $agencysalutationName = 'Agency';
        $empscreeningmodel = new Default_Model_Empscreening();
        $usermodel = new Default_Model_Users();
        $processesmodel = new Default_Model_Processes();
        $errorflag = "true";
        $id = $this->_request->getParam('id');
        $checktype = $this->_request->getParam('checktype');
        $radio_pocId = $this->_request->getParam('contactRadio');
        $agencyids = $this->_request->getParam('agencyids');
        $bgcheck_status = $this->_request->getParam('bgcheck_status');
        $employee = $this->_request->getParam('employee');
        $candid = $this->_request->getParam('candid');
        $empid = $this->getRequest()->getParam('empid');
        $specimenId = '';
        $empFlag = 1;
        $bgtypes = '';
        $BGStatus = '';
        $newStatus = 'In process';
        $inprocess = 'no';
        $options = array();
        if ($employee) {
            $empArr = explode('-', $employee);
            $empFlag = $empArr[0] == 'emp' ? 1 : 2;
            $specimenId = $empArr[1];
        }
        if (isset($candid)) {
            $empFlag = 2;
            $empArr[0] = 2;
            $specimenId = $candid;
        } else {
            if (isset($empid)) {
                $empFlag = 1;
                $empArr[0] = 1;
                $specimenId = $empid;
            }
        }
        if (empty($checktype)) {
            $msgarray['checktype'] = "Please check at least one screening type.";
            $errorflag = "false";
        }
        if (empty($radio_pocId) || $radio_pocId == '') {
            $msgarray['contactRadio'] = "Please select point of contact.";
            $errorflag = "false";
        }
        if (empty($employee)) {
            $msgarray['employee'] = "Please select employee.";
            $errorflag = "false";
        }
        if (!isset($agencyids) || $agencyids == '') {
            $agencyids = $this->getRequest()->getParam('defaultagencyid');
        }
        if (!isset($agencyids) || $agencyids == '') {
            $msgarray['agencyids'] = "Please select agency.";
            $errorflag = "false";
        }
        $checktypeModal = new Default_Model_Bgscreeningtype();
        $agencymodel = new Default_Model_Agencylist();
        $checktypesData = $checktypeModal->fetchAll('isactive=1', 'type')->toArray();
        $checkagencyData = $agencymodel->fetchAll('isactive=1', 'agencyname')->toArray();
        $employeeData = $empscreeningmodel->getEmployeesForScreening();
        $candidateData = $empscreeningmodel->getCandidatesForScreening();
        if (empty($checktypesData)) {
            $msgarray['checktype'] = 'Screening types are not configured yet.';
            $errorflag = 'false';
        }
        if (empty($checkagencyData)) {
            $msgarray['agencyids'] = 'Agencies are not added yet.';
            $errorflag = 'false';
        }
        if (empty($candidateData) && empty($employeeData)) {
            $msgarray['employee'] = 'Employees/candidates are not added yet.';
            $errorflag = 'false';
        }
        /* Check - Adding a record with same userid, agencyid and check type (for each check type ) */
        if (is_array($checktype) && $errorflag != "false") {
            for ($i = 0; $i < sizeof($checktype); $i++) {
                $processStatus = array();
                $processStatus = $processesmodel->getProcessStatus($specimenId, $empFlag, $agencyids, $checktype[$i]);
                if (!empty($processStatus) && sizeof($processStatus > 0)) {
                    $oldstatus = $processStatus[0]['process_status'];
                    $BGStatus = $processStatus[0]['bgcheck_status'];
                    if (($oldstatus == 'On hold' || $oldstatus == 'In process') && $newStatus == $oldstatus && $BGStatus != 'Complete') {
                        $msgarray['StatusError'] = "Already a record with the given data exists. Please insert a new record";
                        $errorflag = "false";
                    }
                }
            }
        }
        /* END */
        $agencyData = array();
        $agencyPOCData = array();
        $empData = array();
        $personalData = array();
        $addressData = array();
        $companyData = array();
        $empscreeningModel = new Default_Model_Empscreening();
        if (!empty($checktype)) {
            $agencyArr = array();
            $agencyArr = $checktype;
            $agencyData = $empscreeningModel->getAgencyData($agencyArr, '', '');
        }
        if ($agencyids) {
            $agencyPOCData = $empscreeningModel->getAgencyPOCData($agencyids);
        }
        if (isset($specimenId) && isset($empArr[0])) {
            $personalData = $empscreeningModel->getEmpPersonalData($specimenId, $empArr[0]);
            $addressData = $empscreeningModel->getEmpAddressData($specimenId, $empArr[0]);
            $companyData = $empscreeningModel->getEmpCompanyData($specimenId, $empArr[0]);
        }
        if (isset($id) && $id != '') {
            $idArr = array();
            $idArr = explode('-', $id);
            $specimenid = $idArr[0];
            $userflag = $idArr[1];
            $personalData = $empscreeningModel->getEmpPersonalData($specimenid, $userflag);
            $addressData = $empscreeningModel->getEmpAddressData($specimenid, $userflag);
            $companyData = $empscreeningModel->getEmpCompanyData($specimenid, $userflag);
            if (isset($personalData[0]['ustatus'])) {
                $processData = $this->processesGrid($id, $personalData[0]['ustatus']);
            } else {
                $processData = $this->processesGrid($id, '');
            }
            $this->view->dataArray = $processData;
        }
        $hrEmail = 'false';
        $mngmntEmail = 'false';
        if (isset($personalData[0]['businessid'])) {
            if (defined('BG_CHECKS_HR_' . $personalData[0]['businessid'])) {
                $hrEmail = constant('BG_CHECKS_HR_' . $personalData[0]['businessid']);
            }
            if (defined('BG_CHECKS_MNGMNT_' . $personalData[0]['businessid'])) {
                $mngmntEmail = constant('BG_CHECKS_MNGMNT_' . $personalData[0]['businessid']);
            }
        }
        $this->view->hrEmail = $hrEmail;
        $this->view->mngmntEmail = $mngmntEmail;
        $this->view->personalData = $personalData;
        $this->view->addressData = $addressData;
        $this->view->companyData = $companyData;
        $this->view->agencyData = $agencyData;
        $this->view->agencyPOCData = $agencyPOCData;
        if ($id != '') {
            $errorflag = 'true';
            if ($bgcheck_status == '0') {
                $msgarray['bgcheck_status'] = "Please select status";
                $errorflag = "false";
            }
        }
        if ($empscreeningform->isValid($this->_request->getPost()) && $errorflag != 'false') {
            $date = new Zend_Date();
            $actionflag = '';
            $tableid = '';
            if ($id == '') {
                /*	A New process is created for a user whose background check status is in 'Complete' status. Then updating the bg status to 'In process' */
                if ($BGStatus == 'Complete' && $newStatus == 'In process') {
                    $totalstatusData = array('bgcheck_status' => 'In process', 'modifiedby' => $loginUserId, 'modifieddate' => gmdate("Y-m-d H:i:s"));
                    $totalstatusWhere = array('specimen_id=?' => $specimenId, 'flag=?' => $empFlag);
                    $empscreeningModel->SaveorUpdateDetails($totalstatusData, $totalstatusWhere);
                }
                /* END */
                $data = array('specimen_id' => $specimenId, 'flag' => $empFlag, 'bgagency_id' => $agencyids, 'bgagency_pocid' => $radio_pocId, 'modifiedby' => $loginUserId, 'modifieddate' => gmdate("Y-m-d H:i:s"));
                $data['process_status'] = $newStatus;
                $data['createdby'] = $loginUserId;
                $data['createddate'] = gmdate("Y-m-d H:i:s");
                $data['isactive'] = 1;
                $where = '';
                $actionflag = 1;
                if (is_array($checktype)) {
                    for ($i = 0; $i < sizeof($checktype); $i++) {
                        $data['bgcheck_type'] = $checktype[$i];
                        $detailId = $empscreeningModel->SaveorUpdateDetails($data, $where);
                    }
                }
                /* Updating back ground check status to In process in employees/candidates status */
                if ($empFlag == 1) {
                    $empInsertionData = array('backgroundchk_status' => 'In process', 'modifiedby' => $loginUserId, 'modifieddate' => gmdate("Y-m-d H:i:s"));
                    $empWhere = array('id=?' => $specimenId);
                    $usermodel->addOrUpdateUserModel($empInsertionData, $empWhere, $specimenId);
                    $options['subject'] = APPLICATION_NAME . ' :: Employee Screening';
                } else {
                    $candModel = new Default_Model_Candidatedetails();
                    $candData = array('backgroundchk_status' => 'In process', 'modifiedby' => $loginUserId, 'modifieddate' => gmdate("Y-m-d H:i:s"));
                    $candWhere = array('id=?' => $specimenId);
                    $candModel->SaveorUpdateUserData($candData, $candWhere);
                    $options['subject'] = APPLICATION_NAME . ' :: Candidate Screening';
                }
                /* END */
                for ($i = 0; $i < sizeof($agencyPOCData); $i++) {
                    if ($agencyPOCData[$i]['id'] == $radio_pocId) {
                        $agencyEmail = $agencyPOCData[$i]['email'];
                        $agencyfname = $agencyPOCData[$i]['first_name'];
                        $agencylname = $agencyPOCData[$i]['last_name'];
                        $agencysalutationName = $agencyfname . ' ' . $agencylname;
                    }
                }
                $hremail = explode(",", HREMAIL);
                if ($empFlag == 1) {
                    $lmanager1Email = $personalData[0]['rmanager_email'];
                    $lmanager1Name = $personalData[0]['reporting_manager'];
                }
                $bid = '';
                if (isset($personalData[0]['businessid'])) {
                    $bid = $personalData[0]['businessid'];
                }
                if (isset($lmanager1Email) && $lmanager1Email != '') {
                    $manager1 = array($lmanager1Email);
                } else {
                    $manager1 = array();
                }
                if (isset($agencyEmail) && $agencyEmail != '') {
                    $agencyemail1 = array($agencyEmail);
                } else {
                    $agencyemail1 = array();
                }
                if (defined('BG_CHECKS_MNGMNT_' . $bid) && $bid != '') {
                    $mngmntemailId = explode(",", constant('BG_CHECKS_MNGMNT_' . $bid));
                } else {
                    $mngmntemailId = array();
                }
                if (defined('BG_CHECKS_HR_' . $bid) && $bid != '') {
                    $hremailId = explode(",", constant('BG_CHECKS_HR_' . $bid));
                } else {
                    $hremailId = array();
                }
                $emailArr = array_merge($manager1, $agencyemail1, $mngmntemailId, $hremailId);
                for ($i = 0; $i < sizeof($emailArr); $i++) {
                    $salutation = 'Dear Sir/Madam,';
                    if ($i == 0) {
                        $salutation = 'Dear ' . ucfirst($lmanager1Name) . ',';
                        $options['toName'] = ucfirst($lmanager1Name);
                    } else {
                        if ($i == 1) {
                            $salutation = 'Dear ' . ucfirst($agencysalutationName) . ',';
                            $options['toName'] = ucfirst($agencysalutationName);
                        } else {
                            if ($i == 2) {
                                $salutation = 'Dear Management,';
                                $options['toName'] = 'Management';
                            } else {
                                if ($i == 3) {
                                    $salutation = 'Dear HR,';
                                    $options['toName'] = 'HR';
                                }
                            }
                        }
                    }
                    $createdbyName = $usermodel->getUserDetails($loginUserId);
                    $options['subject'] = APPLICATION_NAME . ' : Background check initiated';
                    $options['header'] = 'Background check initiated';
                    $options['toEmail'] = $emailArr[$i];
                    $options['message'] = '<div>' . $salutation . '<div>' . ucfirst($personalData[0]['name']) . ' has been sent for background check by ' . ucfirst($createdbyName[0]['userfullname']) . '.';
                    if (!empty($personalData[0]['employee_id'])) {
                        $options['message'] .= ' Please find the details below.</div>
										<div>
											<table border="1" style="border-collapse:collapse;">
												<tr><td>Employee ID</td><td>' . $personalData[0]['employee_id'] . '</td></tr>
												<tr><td>Employee Email</td><td>' . $personalData[0]['email_id'] . '</td></tr>
												<tr><td>Employee Designation</td><td>' . $personalData[0]['designation'] . '</td></tr>
											</table>
										</div>';
                    }
                    $options['message'] .= '<div style="padding:20px 0 10px 0;">Please <a href="' . $baseUrl . '/index/popup" target="_blank" style="color:#b3512f;">click here</a> to login and check the details.</div>
											</div>';
                    $options['cron'] = 'yes';
                    $result = sapp_Global::_sendEmail($options);
                }
            }
            if ($id != '') {
                for ($i = 0; $i < sizeof($agencyPOCData); $i++) {
                    if ($agencyPOCData[$i]['id'] == $radio_pocId) {
                        $agencyEmail = $agencyPOCData[$i]['email'];
                        $agencyfname = $agencyPOCData[$i]['first_name'];
                        $agencylname = $agencyPOCData[$i]['last_name'];
                    }
                }
                $data = array('modifiedby' => $loginUserId, 'modifieddate' => gmdate("Y-m-d H:i:s"));
                $empArr = explode('-', $id);
                $specimenId = $empArr[0];
                $empFlag = $empArr[1];
                $checkstatuses = $empscreeningModel->checkbgstatus($specimenId, $empFlag, 'status');
                if (!empty($checkstatuses) && $checkstatuses[0]['bgcheck_status'] != $bgcheck_status) {
                    if ($bgcheck_status == 'Complete') {
                        $inprocess = 'no';
                        for ($i = 0; $i < sizeof($checkstatuses); $i++) {
                            if (($checkstatuses[$i]['process_status'] == 'In process' || $checkstatuses[$i]['process_status'] == 'On hold') && $checkstatuses[$i]['explanation'] == '' && $checkstatuses[$i]['bgcheck_status'] != 'Complete') {
                                $inprocess = 'yes';
                            }
                        }
                        if ($inprocess != 'yes') {
                            $data['bgcheck_status'] = $bgcheck_status;
                            $where = array('specimen_id=?' => $specimenId, 'flag=?' => $empFlag, 'isactive = 1');
                            $actionflag = 2;
                            $detailId = $empscreeningModel->SaveorUpdateDetails($data, $where);
                            /* Updating back ground check status to Completed in employees/candidates status */
                            if ($empFlag == 1) {
                                $usermodel = new Default_Model_Users();
                                $empinsertionData = array('backgroundchk_status' => 'Completed', 'modifiedby' => $loginUserId, 'modifieddate' => gmdate("Y-m-d H:i:s"));
                                $empWhere = array('id=?' => $specimenId);
                                $usermodel->addOrUpdateUserModel($empinsertionData, $empWhere, $specimenId);
                            } else {
                                $candModel = new Default_Model_Candidatedetails();
                                $candData = array('backgroundchk_status' => 'Completed', 'modifiedby' => $loginUserId, 'modifieddate' => gmdate("Y-m-d H:i:s"));
                                $candWhere = array('id=?' => $specimenId);
                                $candModel->SaveorUpdateUserData($candData, $candWhere);
                            }
                            /* END */
                            /* Mail to HRD, L1 and L2 managers*/
                            $hremail = explode(",", HREMAIL);
                            if ($empFlag == 1) {
                                $lmanager1Email = $personalData[0]['rmanager_email'];
                                $lmanager1Name = $personalData[0]['reporting_manager'];
                            }
                            if (isset($lmanager1Email) && $lmanager1Email != '') {
                                $manager1 = array($lmanager1Email);
                            } else {
                                $manager1 = array();
                            }
                            if (defined('BG_CHECKS_MNGMNT_' . $bid) && $bid != '') {
                                $mngmntemailId = explode(",", constant('BG_CHECKS_MNGMNT_' . $bid));
                            } else {
                                $mngmntemailId = array();
                            }
                            if (defined('BG_CHECKS_HR_' . $bid) && $bid != '') {
                                $hremailId = explode(",", constant('BG_CHECKS_HR_' . $bid));
                            } else {
                                $hremailId = array();
                            }
                            $emailArr = array_merge($manager1, $mngmntemailId, $hremailId);
                            for ($i = 0; $i < sizeof($emailArr); $i++) {
                                $salutation = 'Dear Sir/Madam,';
                                if ($i == 0) {
                                    $salutation = 'Dear ' . ucfirst($lmanager1Name) . ',';
                                    $options['toName'] = ucfirst($lmanager1Name);
                                }
                                if ($i == 1) {
                                    $salutation = 'Dear Management,';
                                    $options['toName'] = 'Management';
                                }
                                if ($i == 2) {
                                    $salutation = 'Dear HR,';
                                    $options['toName'] = 'HR';
                                }
                                $options['subject'] = APPLICATION_NAME . ' : Background check completed';
                                $options['header'] = 'Background check completed';
                                $options['toEmail'] = $emailArr[$i];
                                $options['message'] = '<div>' . $salutation . '<div>Background check for ' . ucfirst($personalData[0]['name']) . ' has been completed.';
                                if (!empty($personalData[0]['employee_id'])) {
                                    $options['message'] .= ' Please find the details below.</div>
										<div>
											<table border="1" style="border-collapse:collapse;">
												<tr><td>Employee ID</td><td>' . $personalData[0]['employee_id'] . '</td></tr>
												<tr><td>Employee Email</td><td>' . $personalData[0]['email_id'] . '</td></tr>
												<tr><td>Employee Designation</td><td>' . $personalData[0]['designation'] . '</td></tr>
											</table>
										</div>';
                                }
                                $options['message'] .= '<div style="padding:20px 0 10px 0;">Please <a href="' . $baseUrl . '/index/popup" target="_blank" style="color:#b3512f;">click here</a> to login and check the details.</div>
														</div>';
                                $options['cron'] = 'yes';
                                $result = sapp_Global::_sendEmail($options);
                            }
                            /* END */
                        }
                    } else {
                        $data['bgcheck_status'] = $bgcheck_status;
                        $where = array('specimen_id=?' => $specimenId, 'flag=?' => $empFlag, 'isactive = 1');
                        $actionflag = 2;
                        $detailId = $empscreeningModel->SaveorUpdateDetails($data, $where);
                        if ($empFlag == 1) {
                            $usermodel = new Default_Model_Users();
                            $empInsertionData = array('backgroundchk_status' => $bgcheck_status, 'modifiedby' => $loginUserId, 'modifieddate' => gmdate("Y-m-d H:i:s"));
                            $empWhere = array('id=?' => $specimenId);
                            $usermodel->addOrUpdateUserModel($empInsertionData, $empWhere, $specimenId);
                            $options['subject'] = APPLICATION_NAME . ' :: Employee Screening';
                        } else {
                            $candModel = new Default_Model_Candidatedetails();
                            $candData = array('backgroundchk_status' => $bgcheck_status, 'modifiedby' => $loginUserId, 'modifieddate' => gmdate("Y-m-d H:i:s"));
                            $candWhere = array('id=?' => $specimenId);
                            $candModel->SaveorUpdateUserData($candData, $candWhere);
                        }
                    }
                } else {
                    $inprocess = 'samebgstatus';
                }
            }
            if ($inprocess == 'yes' || $inprocess == 'samebgstatus') {
                $this->view->inprocess = $inprocess;
                $this->view->specimenId = $specimenId;
                $this->view->empFlag = $empFlag;
            } else {
                if ($detailId == 'update') {
                    $tableid = $id;
                } else {
                    $tableid = $detailId;
                }
                $menuID = EMPSCREENING;
                $result = sapp_Global::logManager($menuID, $actionflag, $loginUserId, $specimenId . '-' . $empFlag);
                if ($detailId == 'update') {
                    $this->_helper->getHelper("FlashMessenger")->addMessage(array("success" => "Background check process is updated successfully."));
                } else {
                    $this->_helper->getHelper("FlashMessenger")->addMessage(array("success" => "Background check process is added successfully."));
                }
                if ($empFlag == 2) {
                    $this->_redirect('empscreening/con/pQ==');
                } else {
                    $this->_redirect('empscreening/con/pA==');
                }
            }
        } else {
            $messages = $empscreeningform->getMessages();
            foreach ($messages as $key => $val) {
                foreach ($val as $key2 => $val2) {
                    $msgarray[$key] = $val2;
                    break;
                }
                if (empty($checktypesData)) {
                    $msgarray['checktype'] = 'Screening types are not configured yet.';
                }
                if (empty($checkagencyData)) {
                    $msgarray['agencyids'] = 'Agencies are not added yet.';
                }
                if (empty($candidateData) && empty($employeeData)) {
                    $msgarray['employee'] = 'Employees/candidates are not added yet.';
                    $errorflag = 'false';
                }
            }
            return $msgarray;
        }
        $this->view->lgnrole = $loginuserRole;
    }