public function savequestionpopupAction()
 {
     $ajaxContext = $this->_helper->getHelper('AjaxContext');
     $ajaxContext->addActionContext('savequestionpopup', 'json')->initContext();
     $this->_helper->layout->disableLayout();
     $auth = Zend_Auth::getInstance();
     if ($auth->hasIdentity()) {
         $loginUserId = $auth->getStorage()->read()->id;
         $loginuserRole = $auth->getStorage()->read()->emprole;
         $loginuserGroup = $auth->getStorage()->read()->group_id;
     }
     $appraisalquestionsmodel = new Default_Model_Appraisalquestions();
     $result['result'] = '';
     $result['id'] = '';
     $result['question'] = '';
     $result['description'] = '';
     try {
         $categoryval = $this->_request->getParam('categoryval');
         $questionval = urldecode($this->_request->getParam('questionval'));
         $description = trim($this->_request->getParam('description'));
         $moduleflag = trim($this->_request->getParam('moduleflag'));
         $menumodel = new Default_Model_Menu();
         $actionflag = '';
         $tableid = '';
         $data = array('pa_category_id' => $categoryval, 'question' => $questionval, 'description' => $description != '' ? $description : NULL, 'module_flag' => $moduleflag, 'createdby_role' => $loginuserRole, 'createdby_group' => $loginuserGroup, 'createdby' => $loginUserId, 'modifiedby_role' => $loginuserRole, 'modifiedby_group' => $loginuserGroup, 'modifiedby' => $loginUserId, 'isactive' => 1, 'createddate' => gmdate("Y-m-d H:i:s"), 'modifieddate' => gmdate("Y-m-d H:i:s"));
         $where = '';
         $actionflag = 1;
         if ($questionval != '' && $categoryval != '' && $moduleflag != '' && preg_match('/^[a-zA-Z0-9.\\- ?\',\\/#@$&*()!]+$/', $questionval)) {
             $Id = $appraisalquestionsmodel->SaveorUpdateAppraisalQuestionData($data, $where);
             $menuidArr = $menumodel->getMenuObjID('/appraisalquestions');
             $menuID = $menuidArr[0]['id'];
             $logresult = sapp_Global::logManager($menuID, $actionflag, $loginUserId, $tableid);
             $result['msg'] = 'success';
             $result['id'] = $Id;
             $result['question'] = $questionval;
             $result['description'] = $description;
         } else {
             $result['msg'] = 'error';
             $result['id'] = '';
             $result['question'] = '';
             $result['description'] = '';
         }
     } catch (Exception $e) {
         $result['msg'] = $e->getMessage();
         $result['id'] = '';
         $result['question'] = '';
         $result['description'] = '';
     }
     $this->_helper->json($result);
 }
    public static function update_QsParmas_Allemps($questions, $categoryids = '')
    {
        $auth = Zend_Auth::getInstance();
        if ($auth->hasIdentity()) {
            $loginUserId = $auth->getStorage()->read()->id;
        }
        $appraisalQsModel = new Default_Model_Appraisalquestions();
        $appraisalCategoryModel = new Default_Model_Appraisalcategory();
        if ($questions != '') {
            $QsdataArr = array('isused' => 1, 'modifiedby' => $loginUserId, 'modifieddate' => gmdate("Y-m-d H:i:s"));
            $Qswhere = " id IN({$questions}) ";
            $QsId = $appraisalQsModel->SaveorUpdateAppraisalQuestionData($QsdataArr, $Qswhere);
        }
        if ($categoryids != '') {
            $CatdataArr = array('isused' => 1, 'modifiedby' => $loginUserId, 'modifieddate' => gmdate("Y-m-d H:i:s"));
            $Catwhere = " id IN({$categoryids}) ";
            $CatId = $appraisalCategoryModel->SaveorUpdateAppraisalCategoryData($CatdataArr, $Catwhere);
        }
        ?>
	    
	<?php 
    }
 /**
  * This action is used to edit the current available appraisal,where manager will manager his/her
  * employees as groups.
  */
 public function editAction()
 {
     $auth = Zend_Auth::getInstance();
     if ($auth->hasIdentity()) {
         $loginUserId = $auth->getStorage()->read()->id;
         $businessunit_id = $auth->getStorage()->read()->businessunit_id;
         $department_id = $auth->getStorage()->read()->department_id;
         $loginuserRole = $auth->getStorage()->read()->emprole;
         $loginuserGroup = $auth->getStorage()->read()->group_id;
     }
     $id = $this->getRequest()->getParam('id');
     try {
         if ($id != '') {
             //$id = sapp_Global::_decrypt($id);
             if (is_numeric($id) && $id > 0) {
                 $app_manager_model = new Default_Model_Appraisalmanager();
                 $appraisal_init_model = new Default_Model_Appraisalinit();
                 $appraisalQsModel = new Default_Model_Appraisalquestions();
                 $tablename = 'main_pa_questions_privileges';
                 $appraisal_data = $appraisal_init_model->getappdata_forview($id);
                 if ($appraisal_data['status'] == 1 && $appraisal_data['enable_step'] == 1) {
                     $appraisal_data['process_status'] = '';
                     if (!empty($appraisal_data)) {
                         if ($appraisal_data['initialize_status'] == 1) {
                             if ($appraisal_data['enable_step'] == 1) {
                                 $appraisal_data['process_status'] = 'Enabled to Managers';
                             }
                             if ($appraisal_data['enable_step'] == 2) {
                                 $appraisal_data['process_status'] = 'Enabled to Employees';
                             }
                         } else {
                             if ($appraisal_data['initialize_status'] == 2) {
                                 $appraisal_data['process_status'] = 'Initialize Later';
                             } else {
                                 $appraisal_data['process_status'] = 'In progress';
                             }
                         }
                     }
                     $EmpCountArr = $app_manager_model->getManagerGroupCount($id, $loginUserId);
                     if (!empty($EmpCountArr)) {
                         $appraisal_data['empcount'] = $EmpCountArr[0]['empcount'];
                     }
                     $manager_groups = $app_manager_model->getManagergroups($id, $loginUserId);
                     $questionsArr = $appraisalQsModel->getQuestionsByCategory($appraisal_data['category_id'], '');
                     $view = $this->getHelper('ViewRenderer')->view;
                     $view->previ_data = 'no';
                     $view->data = $appraisal_data;
                     $text = $view->render('appraisalinit/view.phtml');
                     $this->view->appraisal_id = $id;
                     $this->view->manager_id = $loginUserId;
                     $this->view->manager_groups = $manager_groups;
                     $this->view->appraisal_data = $appraisal_data;
                     $this->view->app_text = $text;
                     $this->view->questionsArr = $questionsArr;
                 } else {
                     $this->view->ermsg = 'nodata';
                 }
             } else {
                 $this->view->ermsg = 'nodata';
             }
         } else {
             $this->view->ermsg = 'nodata';
         }
     } catch (Exception $ex) {
         $this->view->ermsg = 'nodata';
     }
 }
 public function deleteAction()
 {
     $auth = Zend_Auth::getInstance();
     if ($auth->hasIdentity()) {
         $loginUserId = $auth->getStorage()->read()->id;
         $loginuserRole = $auth->getStorage()->read()->emprole;
         $loginuserGroup = $auth->getStorage()->read()->group_id;
     }
     $id = $this->_request->getParam('objid');
     $messages['message'] = '';
     $messages['msgtype'] = '';
     $count = 0;
     $actionflag = 3;
     if ($id) {
         $appraisalquestionsmodel = new Default_Model_Appraisalquestions();
         $menumodel = new Default_Model_Menu();
         $appraisalquestionsdata = $appraisalquestionsmodel->getAppraisalQuestionbyID($id);
         if ($appraisalquestionsdata[0]['isused'] == 0) {
             $data = array('isactive' => 0, 'modifieddate' => gmdate("Y-m-d H:i:s"), 'modifiedby_role' => $loginuserRole, 'modifiedby_group' => $loginuserGroup, 'modifiedby' => $loginUserId);
             $where = array('id=?' => $id);
             $Id = $appraisalquestionsmodel->SaveorUpdateAppraisalQuestionData($data, $where);
             if ($Id == 'update') {
                 $menuidArr = $menumodel->getMenuObjID('/appraisalquestions');
                 $menuID = $menuidArr[0]['id'];
                 $result = sapp_Global::logManager($menuID, $actionflag, $loginUserId, $id);
                 $configmail = sapp_Global::send_configuration_mail('Question', $appraisalquestionsdata[0]['question']);
                 $messages['message'] = 'Question deleted successfully.';
                 $messages['msgtype'] = 'success';
             } else {
                 $messages['message'] = 'Question cannot be deleted.';
                 $messages['msgtype'] = 'error';
             }
         } else {
             $messages['message'] = 'Question cannot be deleted as its using in appraisal process.';
             $messages['msgtype'] = 'error';
         }
     } else {
         $messages['message'] = 'Question cannot be deleted.';
         $messages['msgtype'] = 'error';
     }
     $this->_helper->json($messages);
 }
 public function deleteAction()
 {
     $auth = Zend_Auth::getInstance();
     if ($auth->hasIdentity()) {
         $loginUserId = $auth->getStorage()->read()->id;
     }
     $id = $this->_request->getParam('objid');
     $messages['message'] = '';
     $messages['msgtype'] = '';
     $count = 0;
     $actionflag = 3;
     if ($id) {
         $appraisalCategoryModel = new Default_Model_Appraisalcategory();
         $appCategorydata = $appraisalCategoryModel->getAppraisalCategoryDatabyID($id);
         if ($appCategorydata[0]['isused'] == 0) {
             $appQuestionModel = new Default_Model_Appraisalquestions();
             $appQuesData = $appQuestionModel->getAppraisalQuestionsByCategotyID($id);
             $d = array();
             foreach ($appQuesData as $key => $value) {
                 $d[] = $value['id'];
             }
             $d = implode(',', $d);
             if (sizeof($appQuesData) == 0) {
                 $data = array('isactive' => 0, 'modifiedby' => $loginUserId, 'modifieddate' => gmdate("Y-m-d H:i:s"));
                 $where = array('id=?' => $id);
                 $Id = $appraisalCategoryModel->SaveorUpdateAppraisalCategoryData($data, $where);
                 if ($Id == 'update') {
                     $menuID = APPRAISALCATEGORIES;
                     $result = sapp_Global::logManager($menuID, $actionflag, $loginUserId, $id);
                     /***
                     			** commented on 29-04-2015 by sapplica
                     			** need to integrate mail template
                     				$configmail = sapp_Global::send_configuration_mail('Category',$appCategorydata[0]['category_name']);	
                     			***/
                     $messages['message'] = 'Parameter deleted successfully.';
                     $messages['msgtype'] = 'success';
                 } else {
                     $messages['message'] = 'Parameter cannot be deleted.';
                     $messages['msgtype'] = 'error';
                 }
             } else {
                 $messages['message'] = 'Parameter cannot be deleted as there are active questions assigned to it.';
                 $messages['msgtype'] = 'error';
             }
             if (sizeof($appQuesData) > 0) {
                 $data = array('isactive' => 0, 'modifiedby' => $loginUserId, 'modifieddate' => gmdate("Y-m-d H:i:s"));
                 $where = array('id=?' => $id);
                 $Id = $appraisalCategoryModel->SaveorUpdateAppraisalCategoryData($data, $where);
                 $appQuestionModel->UpdateAppraisalQuestionData($d);
                 if ($Id == 'update') {
                     $menuID = APPRAISALCATEGORIES;
                     $result = sapp_Global::logManager($menuID, $actionflag, $loginUserId, $id);
                     /***
                     			 ** commented on 29-04-2015 by sapplica
                     			 ** need to integrate mail template
                     			 $configmail = sapp_Global::send_configuration_mail('Category',$appCategorydata[0]['category_name']);
                     			***/
                     $messages['message'] = 'Parameter deleted successfully.';
                     $messages['msgtype'] = 'success';
                 } else {
                     $messages['message'] = 'Parameter cannot be deleted.';
                     $messages['msgtype'] = 'error';
                 }
             }
         } else {
             $messages['message'] = 'Parameter cannot be deleted as it is being used in appraisal process.';
             $messages['msgtype'] = 'error';
         }
     } else {
         $messages['message'] = 'Parameter cannot be deleted.';
         $messages['msgtype'] = 'error';
     }
     $this->_helper->json($messages);
 }
 public function savequestions($hrWizardData)
 {
     $auth = Zend_Auth::getInstance();
     if ($auth->hasIdentity()) {
         $loginUserId = $auth->getStorage()->read()->id;
         $loginuserRole = $auth->getStorage()->read()->emprole;
         $loginuserGroup = $auth->getStorage()->read()->group_id;
     }
     $appraisalquestionsmodel = new Default_Model_Appraisalquestions();
     $msgarray = array();
     $errorflag = 'true';
     $categoryNameId = $this->_request->getParam('category_name_id');
     $questionarr = $this->_request->getParam('question');
     $descriptionarr = $this->_request->getParam('description');
     if (!empty($questionarr)) {
         for ($i = 0; $i < sizeof($questionarr); $i++) {
             if ($questionarr[$i] == '') {
                 $msgarray['question_name'][$i] = 'Please enter question.';
                 $errorflag = 'false';
             } else {
                 if (!preg_match('/^[a-zA-Z0-9.\\- ?\',\\/#@$&*()!]+$/', $questionarr[$i])) {
                     $msgarray['question_name'][$i] = 'Please enter valid holiday.';
                     $errorflag = 'false';
                 }
             }
             if ($categoryNameId == '') {
                 $msgarray['category_name_error'] = 'Please select category name.';
                 $errorflag = 'false';
             }
         }
         $msgarray['categoryerrorsize'] = sizeof($questionarr);
     }
     if ($errorflag == 'true') {
         try {
             $actionflag = 1;
             $tableid = '';
             $where = '';
             $date = new Zend_Date();
             for ($i = 0; $i < sizeof($questionarr); $i++) {
                 $data = array('pa_category_id' => $categoryNameId, 'question' => trim($questionarr[$i]), 'description' => $descriptionarr[$i] != '' ? trim($descriptionarr[$i]) : NULL, 'modifiedby' => $loginUserId, 'modifieddate' => gmdate("Y-m-d H:i:s"), 'modifiedby_role' => $loginuserRole, 'modifiedby_group' => $loginuserGroup, 'createdby_role' => $loginuserRole, 'createdby_group' => $loginuserGroup, 'createdby' => $loginUserId, 'module_flag' => 1, 'createddate' => gmdate("Y-m-d H:i:s"), 'isactive' => 1);
                 $Id = $appraisalquestionsmodel->SaveorUpdateAppraisalQuestionData($data, $where);
                 $tableid = $Id;
                 $menuID = APPRAISALQUESTIONS;
                 $result = sapp_Global::logManager($menuID, $actionflag, $loginUserId, $tableid);
             }
             $hrWizardModel = new Default_Model_Hrwizard();
             $hrwizardarray = array('perf_appraisal' => 2, 'modifiedby' => $loginUserId, 'modifieddate' => gmdate("Y-m-d H:i:s"));
             if ($hrWizardData['leavetypes'] == 2 && $hrWizardData['holidays'] == 2) {
                 $hrwizardarray['iscomplete'] = 2;
             }
             $hrWizardModel->SaveorUpdateHrWizardData($hrwizardarray, '');
             $this->_helper->getHelper("FlashMessenger")->addMessage("Questions added successfully.");
             $this->_redirect('hrwizard/configureperformanceappraisal');
         } catch (Exception $e) {
             $msgarray['category_name_error'] = "Something went wrong, please try again.";
             return $msgarray;
         }
     } else {
         return $msgarray;
     }
 }
 public function initialize($appraisalid, $initflag)
 {
     $auth = Zend_Auth::getInstance();
     if ($auth->hasIdentity()) {
         $loginUserId = $auth->getStorage()->read()->id;
         $loginuserRole = $auth->getStorage()->read()->emprole;
         $loginuserGroup = $auth->getStorage()->read()->group_id;
         $loginuserArr = array('loginuserid' => $loginUserId, 'loginuserrole' => $loginuserRole, 'loginusergroup' => $loginuserGroup);
         $loginUserEmpId = $auth->getStorage()->read()->employeeId;
         $loginUserfullname = $auth->getStorage()->read()->userfullname;
     }
     $appraisalQsModel = new Default_Model_Appraisalquestions();
     $appraisalQsTmpModel = new Default_Model_Appraisalqstemp();
     $app_init_model = new Default_Model_Appraisalinit();
     $appraisalPrivTempModel = new Default_Model_Appraisalqstemp();
     $appraisalPrivMainModel = new Default_Model_Appraisalqsmain();
     $appraisalempratingsmodel = new Default_Model_Appraisalemployeeratings();
     $app_manager_model = new Default_Model_Appraisalmanager();
     $usersmodel = new Default_Model_Users();
     $departmentsmodel = new Default_Model_Departments();
     $announcementsModel = new Default_Model_Announcements();
     $deptids = '';
     $questions = '';
     $title = 'Performance Appraisal';
     $description = 'Performance appraisal initialized';
     $trDb = Zend_Db_Table::getDefaultAdapter();
     $trDb->beginTransaction();
     try {
         $data = $app_init_model->getConfigData($appraisalid);
         $appraisaldata = $data[0];
         $qsdataArr = $appraisalPrivTempModel->getAppraisalQuestions($appraisalid);
         if (!empty($qsdataArr)) {
             foreach ($qsdataArr as $qs) {
                 $questions .= $qs['hr_qs'] . ',';
             }
             $questions = rtrim($questions, ',');
         }
         $questions = implode(',', array_keys(array_flip(explode(',', $questions))));
         $initdata = array('initialize_status' => 2, 'modifiedby' => $loginUserId, 'modifiedby_role' => $loginuserRole, 'modifiedby_group' => $loginuserGroup, 'modifieddate' => gmdate("Y-m-d H:i:s"));
         $initwhere = array('id=?' => $appraisalid);
         if ($initflag == 1) {
             $initdata['initialize_status'] = 1;
             $insertQstable = $appraisalQsModel->insertQsData($appraisalid, $loginuserArr);
             $updateTmptable = $appraisalPrivTempModel->updateQsTempData($appraisalid, $loginuserArr);
             $con = $app_init_model->SaveorUpdateAppraisalInitData($initdata, $initwhere);
             if ($appraisaldata['enable_step'] == 2) {
                 /**
                  * Start 
                  * Inserting or Updating employee ratings table when enabled to employees
                  * If record exists then updating else inserting
                  */
                 $employeeidArr = $appraisalPrivMainModel->getemployeeIDs($appraisalid);
                 if (!empty($employeeidArr)) {
                     foreach ($employeeidArr as $emp) {
                         $emprating_Arr = array('pa_initialization_id' => $appraisalid, 'employee_id' => $emp['employee_id'], 'line_manager_1' => $emp['line_manager_1'] != '' ? $emp['line_manager_1'] : NULL, 'line_manager_2' => $emp['line_manager_2'] != '' ? $emp['line_manager_2'] : NULL, 'line_manager_3' => $emp['line_manager_3'] != '' ? $emp['line_manager_3'] : NULL, 'line_manager_4' => $emp['line_manager_4'] != '' ? $emp['line_manager_4'] : NULL, 'line_manager_5' => $emp['line_manager_5'] != '' ? $emp['line_manager_5'] : NULL, 'modifiedby' => $loginUserId, 'modifiedby_role' => $loginuserRole, 'modifiedby_group' => $loginuserGroup, 'modifieddate' => gmdate("Y-m-d H:i:s"));
                         $employeeexistArr = $appraisalempratingsmodel->checkEmployeeExists($appraisalid, $emp['employee_id']);
                         if ($employeeexistArr[0]['empcount'] > 0) {
                             $qwhere = " employee_id = '" . $emp['employee_id'] . "' and pa_initialization_id='" . $appraisalid . "' and isactive=1";
                         } else {
                             $emprating_Arr['createdby'] = $loginUserId;
                             $emprating_Arr['createdby_role'] = $loginuserRole;
                             $emprating_Arr['createdby_group'] = $loginuserGroup;
                             $emprating_Arr['createddate'] = gmdate("Y-m-d H:i:s");
                             $qwhere = '';
                         }
                         $appraisalempratingsmodel->SaveorUpdateAppraisalSkillsData($emprating_Arr, $qwhere);
                         /**
                          * End
                          */
                     }
                 }
             }
             /*
              *   Logs Storing
              */
             if ($con == 'update') {
                 $actionflag = 2;
             } else {
                 $actionflag = 1;
             }
             $tableid = '';
             $menuID = INITIALIZE_APPRAISAL;
             $result = sapp_Global::logManager($menuID, $actionflag, $loginUserId, $tableid);
             /*
              *  Logs storing ends
              */
             /**
              * Sending mails to HR,Super Admin,Management,(managers OR employees) based on enable step.
              */
             $appraisalratingsmodel = new Default_Model_Appraisalratings();
             //to get initialization details using appraisal Id for Business Unit,Department,To Year
             $appraisal_details = $appraisalratingsmodel->getappdata($appraisalid);
             if (!empty($appraisal_details)) {
                 $businessUnit = $appraisal_details['businessunit_id'];
                 $department = $appraisal_details['deptid'];
                 $bunit = $appraisal_details['unitname'];
                 $dept = $appraisal_details['deptname'];
                 $to_year = $appraisal_details['to_year'];
                 $appraisalconfigmodel = new Default_Model_Appraisalconfig();
                 if ($department != '') {
                     $employeeDetailsArr = $appraisalconfigmodel->getUserDetailsByID($businessUnit, $department);
                 } else {
                     $employeeDetailsArr = $appraisalconfigmodel->getUserDetailsByID($businessUnit, '');
                 }
                 $dept_str = $dept == '' ? " " : "and department <b>{$dept}</b> ";
                 $emp_id_str = $loginuserRole == SUPERADMINROLE ? " " : "({$loginUserEmpId})";
                 //Preparing Employee array for Bcc
                 $empArr = array();
                 if (!empty($employeeDetailsArr)) {
                     $empArrList = '';
                     foreach ($employeeDetailsArr as $emp) {
                         array_push($empArr, $emp['emailaddress']);
                     }
                 }
                 $mail_str = $appraisaldata['enable_step'] == 1 ? 'to managers' : 'to employees';
                 $empmgrArr = array();
                 if ($appraisaldata['enable_step'] == 1) {
                     $getLine1ManagerId = $appraisalPrivMainModel->getLine1ManagerIdMain($appraisalid);
                     foreach ($getLine1ManagerId as $mgr) {
                         array_push($empmgrArr, $mgr['emailaddress']);
                     }
                 } else {
                     $empIdArr = array();
                     $empIdList = '';
                     $employeeidArr = $appraisalPrivMainModel->getemployeeIDs($appraisalid);
                     //fetching Employee Ids
                     if (!empty($employeeidArr)) {
                         foreach ($employeeidArr as $emp) {
                             array_push($empIdArr, $emp['employee_id']);
                         }
                         $empIdList = implode(',', $empIdArr);
                         //Preparing Employee Id List
                         $empDetailsArr = $app_manager_model->getUserDetailsByEmpID($empIdList);
                         //Fetching employee details
                         if (!empty($empDetailsArr)) {
                             foreach ($empDetailsArr as $emp) {
                                 array_push($empmgrArr, $emp['emailaddress']);
                                 //preparing Bcc array
                             }
                         }
                     }
                 }
                 $totalArr = array_merge($empArr, $empmgrArr);
                 //Sending mail to Super admin
                 $options['subject'] = APPLICATION_NAME . ': Performance Appraisal Initialization';
                 $options['header'] = 'Performance Appraisal Initialization : ' . $to_year;
                 $options['toEmail'] = SUPERADMIN_EMAIL;
                 $options['toName'] = 'Super Admin';
                 $options['bcc'] = $totalArr;
                 $options['message'] = "<div style='padding: 0; text-align: left; font-size:14px; font-family:Arial, Helvetica, sans-serif;'>\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t<span style='color:#3b3b3b;'>Hi,</span><br />\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t<div style='padding:20px 0 0 0;color:#3b3b3b;'>Performance appraisal has been initialized {$mail_str} for the year <b>{$to_year}</b> for business unit <b>{$bunit}</b>  {$dept_str} by " . $loginUserfullname . $emp_id_str . " </div>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t<div style='padding:20px 0 10px 0;'>Please <a href=" . BASE_URL . " target='_blank' style='color:#b3512f;'>click here</a> to login  to your <b>" . APPLICATION_NAME . "</b> account to check the details.</div>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t</div> ";
                 $mail_id = sapp_Global::_sendEmail($options);
             }
             if ($appraisaldata['enable_step'] == 2) {
                 $appImpleData = sapp_PerformanceHelper::check_per_implmentation($appraisaldata['businessunit_id'], $appraisaldata['department_id']);
             }
             sapp_PerformanceHelper::update_QsParmas_Allemps($questions, $appraisaldata['category_id']);
         } else {
             $app_init_model->SaveorUpdateAppraisalInitData($initdata, $initwhere);
         }
         $trDb->commit();
         if ($initflag == 1) {
             $this->_helper->getHelper("FlashMessenger")->addMessage(array("success" => 'Appraisal initialized successfully'));
         } else {
             $this->_helper->getHelper("FlashMessenger")->addMessage(array("success" => 'Appraisal configurations are saved to be initialized later'));
         }
         return 'success';
     } catch (Exception $e) {
         $trDb->rollBack();
         return 'error';
     }
 }
 public function initialize($appraisalid, $initflag)
 {
     $auth = Zend_Auth::getInstance();
     if ($auth->hasIdentity()) {
         $loginUserId = $auth->getStorage()->read()->id;
         $loginuserRole = $auth->getStorage()->read()->emprole;
         $loginuserGroup = $auth->getStorage()->read()->group_id;
         $loginuserArr = array('loginuserid' => $loginUserId, 'loginuserrole' => $loginuserRole, 'loginusergroup' => $loginuserGroup);
     }
     $appraisalQsModel = new Default_Model_Appraisalquestions();
     $appraisalQsTmpModel = new Default_Model_Appraisalqstemp();
     $app_init_model = new Default_Model_Appraisalinit();
     $appraisalPrivTempModel = new Default_Model_Appraisalqstemp();
     $appraisalPrivMainModel = new Default_Model_Appraisalqsmain();
     $appraisalempratingsmodel = new Default_Model_Appraisalemployeeratings();
     $usersmodel = new Default_Model_Users();
     $departmentsmodel = new Default_Model_Departments();
     $announcementsModel = new Default_Model_Announcements();
     $deptids = '';
     $questions = '';
     $title = 'Performance Appraisal';
     $description = 'Performance appraisal initialized';
     $trDb = Zend_Db_Table::getDefaultAdapter();
     $trDb->beginTransaction();
     try {
         $data = $app_init_model->getConfigData($appraisalid);
         $appraisaldata = $data[0];
         $qsdataArr = $appraisalPrivTempModel->getAppraisalQuestions($appraisalid);
         if (!empty($qsdataArr)) {
             foreach ($qsdataArr as $qs) {
                 $questions .= $qs['hr_qs'] . ',';
             }
             $questions = rtrim($questions, ',');
         }
         $questions = implode(',', array_keys(array_flip(explode(',', $questions))));
         $initdata = array('initialize_status' => 2, 'modifiedby' => $loginUserId, 'modifiedby_role' => $loginuserRole, 'modifiedby_group' => $loginuserGroup, 'modifieddate' => gmdate("Y-m-d H:i:s"));
         $initwhere = array('id=?' => $appraisalid);
         if ($initflag == 1) {
             $initdata['initialize_status'] = 1;
             $insertQstable = $appraisalQsModel->insertQsData($appraisalid, $loginuserArr);
             $updateTmptable = $appraisalPrivTempModel->updateQsTempData($appraisalid, $loginuserArr);
             $app_init_model->SaveorUpdateAppraisalInitData($initdata, $initwhere);
             /**
              * Sending mails to managers OR employees based on enable step.
              */
             if ($appraisaldata['enable_step'] == 1) {
                 /**
                  * Start 
                  * Sending Mails to Managers if enabled to managers
                  */
                 $getLine1ManagerId = $appraisalPrivMainModel->getLine1ManagerIdMain($appraisalid);
                 if (!empty($getLine1ManagerId)) {
                     foreach ($getLine1ManagerId as $val) {
                         $options['subject'] = APPLICATION_NAME . ': Appraisal process initiated';
                         $options['header'] = 'Performance Appraisal';
                         $options['toEmail'] = $val['emailaddress'];
                         $options['toName'] = $val['userfullname'];
                         $options['message'] = 'Dear ' . $val['userfullname'] . ', Appraisal process initiated';
                         $options['cron'] = 'yes';
                         //  sapp_Global::_sendEmail($options);
                     }
                 }
                 /**
                  * Mail to performance appraisal group
                  */
                 if (defined('PER_APPRAISAL_' . $appraisaldata['businessunit_id']) && $appraisaldata['businessunit_id'] != '') {
                     $options['subject'] = APPLICATION_NAME . ': Appraisal process initiated to managers.';
                     $options['header'] = 'Performance Appraisal';
                     $options['toEmail'] = constant('PER_APPRAISAL_' . $appraisaldata['businessunit_id']);
                     $options['toName'] = 'Performance Appraisal';
                     $options['message'] = 'Appraisal process initiated to managers.';
                     $options['cron'] = 'yes';
                     // sapp_Global::_sendEmail($options);
                 }
                 /**
                  * End
                  */
             } else {
                 /**
                  * Start 
                  * Inserting or Updating employee ratings table when enabled to employees
                  * If record exists then updating else inserting
                  */
                 $employeeidArr = $appraisalPrivMainModel->getemployeeIDs($appraisalid);
                 if (!empty($employeeidArr)) {
                     foreach ($employeeidArr as $emp) {
                         $emprating_Arr = array('pa_initialization_id' => $appraisalid, 'employee_id' => $emp['employee_id'], 'line_manager_1' => $emp['line_manager_1'] != '' ? $emp['line_manager_1'] : NULL, 'line_manager_2' => $emp['line_manager_2'] != '' ? $emp['line_manager_2'] : NULL, 'line_manager_3' => $emp['line_manager_3'] != '' ? $emp['line_manager_3'] : NULL, 'line_manager_4' => $emp['line_manager_4'] != '' ? $emp['line_manager_4'] : NULL, 'line_manager_5' => $emp['line_manager_5'] != '' ? $emp['line_manager_5'] : NULL, 'modifiedby' => $loginUserId, 'modifiedby_role' => $loginuserRole, 'modifiedby_group' => $loginuserGroup, 'modifieddate' => gmdate("Y-m-d H:i:s"));
                         $employeeexistArr = $appraisalempratingsmodel->checkEmployeeExists($appraisalid, $emp['employee_id']);
                         if ($employeeexistArr[0]['empcount'] > 0) {
                             $qwhere = " employee_id = '" . $emp['employee_id'] . "' and pa_initialization_id='" . $appraisalid . "' and isactive=1";
                         } else {
                             $emprating_Arr['createdby'] = $loginUserId;
                             $emprating_Arr['createdby_role'] = $loginuserRole;
                             $emprating_Arr['createdby_group'] = $loginuserGroup;
                             $emprating_Arr['createddate'] = gmdate("Y-m-d H:i:s");
                             $qwhere = '';
                         }
                         $appraisalempratingsmodel->SaveorUpdateAppraisalSkillsData($emprating_Arr, $qwhere);
                         /**
                          * End
                          */
                         /** Start
                          * Sending Mails to employees
                          */
                         $employeeDetailsArr = $usersmodel->getUserDetailsByID($emp['employee_id'], '');
                         if (!empty($employeeDetailsArr)) {
                             $options['subject'] = APPLICATION_NAME . ': Appraisal process initiated';
                             $options['header'] = 'Performance Appraisal';
                             $options['toEmail'] = $employeeDetailsArr[0]['emailaddress'];
                             $options['toName'] = $employeeDetailsArr[0]['userfullname'];
                             $options['message'] = 'Dear ' . $employeeDetailsArr[0]['userfullname'] . ', Appraisal process initiated';
                             $options['cron'] = 'yes';
                             // sapp_Global::_sendEmail($options);
                         }
                         /**
                          * End
                          */
                     }
                 }
                 /**
                  * Mail to performance appraisal group
                  */
                 if (defined('PER_APPRAISAL_' . $appraisaldata['businessunit_id']) && $appraisaldata['businessunit_id'] != '') {
                     $options['subject'] = APPLICATION_NAME . ': Appraisal process initiated to employees.';
                     $options['header'] = 'Performance Appraisal';
                     $options['toEmail'] = constant('PER_APPRAISAL_' . $appraisaldata['businessunit_id']);
                     $options['toName'] = 'Performance Appraisal';
                     $options['message'] = 'Appraisal process initiated to employees.';
                     $options['cron'] = 'yes';
                     //  sapp_Global::_sendEmail($options);
                 }
                 /**
                  * End
                  */
             }
             /**
              * End Sending Mails and updating emp ratings table
              */
             if ($appraisaldata['enable_step'] == 2) {
                 $appImpleData = sapp_PerformanceHelper::check_per_implmentation($appraisaldata['businessunit_id'], $appraisaldata['department_id']);
                 /** Start
                  * Announecements
                  */
                 if ($appImpleData['performance_app_flag'] == 1) {
                     $deptArr = $departmentsmodel->getAllDeptsForUnit($appraisaldata['businessunit_id']);
                     if (!empty($deptArr)) {
                         foreach ($deptArr as $dept) {
                             $deptids .= $dept['id'] . ',';
                         }
                         $deptids = rtrim($deptids, ',');
                     }
                 } else {
                     $deptids = $appraisaldata['department_id'];
                 }
                 /*	$announcement_arr = array(
                                               'businessunit_id' => $appraisaldata['businessunit_id']!=''?$appraisaldata['businessunit_id']:NULL,
                                               'department_id' => $deptids!=''?$deptids:NULL,
                                               'title' => $title,
                                               'description' => $description,
                                               'attachments' => NULL,
                                               'status' => 2,
                                               'isactive' => 1,
                 			'createdby' => $loginUserId,
                 						'createdby_role'=>$loginuserRole,
                 			'createdby_group'=>$loginuserGroup,
                                               'modifiedby' => $loginUserId,
                 						'modifiedby_role'=>$loginuserRole,
                 			'modifiedby_group'=>$loginuserGroup,
                 			'createddate'=>gmdate("Y-m-d H:i:s"),
                                               'modifieddate'=>gmdate("Y-m-d H:i:s")
                                   			);
                                   			
                                   	$Id = $announcementsModel->SaveorUpdateAnnouncementsData($announcement_arr, '');		*/
                 /**
                  * End
                  */
             }
             sapp_PerformanceHelper::update_QsParmas_Allemps($questions, $appraisaldata['category_id']);
         } else {
             $app_init_model->SaveorUpdateAppraisalInitData($initdata, $initwhere);
         }
         $trDb->commit();
         if ($initflag == 1) {
             $this->_helper->getHelper("FlashMessenger")->addMessage(array("success" => 'Appraisal initialized successfully'));
         } else {
             $this->_helper->getHelper("FlashMessenger")->addMessage(array("success" => 'Appraisal configurations are saved to be initialized later'));
         }
         return 'success';
     } catch (Exception $e) {
         $trDb->rollBack();
         return 'error';
     }
 }
 public function deleteAction()
 {
     $auth = Zend_Auth::getInstance();
     if ($auth->hasIdentity()) {
         $loginUserId = $auth->getStorage()->read()->id;
     }
     $id = $this->_request->getParam('objid');
     $messages['message'] = '';
     $messages['msgtype'] = '';
     $count = 0;
     $actionflag = 3;
     if ($id) {
         $appraisalCategoryModel = new Default_Model_Appraisalcategory();
         $menumodel = new Default_Model_Menu();
         $appCategorydata = $appraisalCategoryModel->getAppraisalCategoryDatabyID($id);
         if ($appCategorydata[0]['isused'] == 0) {
             $appQuestionModel = new Default_Model_Appraisalquestions();
             $appQuesData = $appQuestionModel->getAppraisalQuestionsByCategotyID($id);
             if (sizeof($appQuesData) == 0) {
                 $data = array('isactive' => 0, 'modifiedby' => $loginUserId, 'modifieddate' => gmdate("Y-m-d H:i:s"));
                 $where = array('id=?' => $id);
                 $Id = $appraisalCategoryModel->SaveorUpdateAppraisalCategoryData($data, $where);
                 if ($Id == 'update') {
                     $menuidArr = $menumodel->getMenuObjID('/appraisalcategory');
                     $menuID = $menuidArr[0]['id'];
                     $result = sapp_Global::logManager($menuID, $actionflag, $loginUserId, $id);
                     $configmail = sapp_Global::send_configuration_mail('Category', $appCategorydata[0]['category_name']);
                     $messages['message'] = 'Category deleted successfully.';
                     $messages['msgtype'] = 'success';
                 } else {
                     $messages['message'] = 'Category cannot be deleted.';
                     $messages['msgtype'] = 'error';
                 }
             } else {
                 $messages['message'] = 'Category cannot be deleted. Delete the questions under this category.';
                 $messages['msgtype'] = 'error';
             }
         } else {
             $messages['message'] = 'Category cannot be deleted as its using in appraisal process.';
             $messages['msgtype'] = 'error';
         }
     } else {
         $messages['message'] = 'Category cannot be deleted.';
         $messages['msgtype'] = 'error';
     }
     $this->_helper->json($messages);
 }