public function submitmanagerAction()
 {
     $auth = Zend_Auth::getInstance();
     if ($auth->hasIdentity()) {
         $loginUserId = $auth->getStorage()->read()->id;
         $loginuserRole = $auth->getStorage()->read()->emprole;
         $loginuserGroup = $auth->getStorage()->read()->group_id;
         $loginuserFullname = $auth->getStorage()->read()->userfullname;
         $loginuserEmail = $auth->getStorage()->read()->emailaddress;
         $loginUserEmpId = $auth->getStorage()->read()->employeeId;
     }
     $post_values = $this->getRequest()->getPost();
     $result = array('status' => 'fail', 'msg' => 'Something went wrong, please try again.');
     $questions = '';
     if (count($post_values) > 0) {
         $appraisal_id = $post_values['appraisal_id'];
         $manager_id = $post_values['manager_id'];
         if ($appraisal_id != '' && $manager_id != '') {
             $appraisal_id = sapp_Global::_decrypt($appraisal_id);
             $manager_id = sapp_Global::_decrypt($manager_id);
             $trDb = Zend_Db_Table::getDefaultAdapter();
             $trDb->beginTransaction();
             try {
                 $app_init_model = new Default_Model_Appraisalinit();
                 $appraisalPrivMainModel = new Default_Model_Appraisalqsmain();
                 $qsdataArr = $appraisalPrivMainModel->getAppraisalQuestionsMain($appraisal_id);
                 if (!empty($qsdataArr)) {
                     foreach ($qsdataArr as $qs) {
                         if (!empty($qs['manager_qs'])) {
                             $questions .= $qs['manager_qs'] . ',';
                         }
                     }
                     $questions = rtrim($questions, ',');
                 }
                 $questions = implode(',', array_keys(array_flip(explode(',', $questions))));
                 $submit_manager = $app_init_model->submitmanager($appraisal_id, $manager_id);
                 sapp_PerformanceHelper::update_QsParmas_Allemps($questions, '');
                 /*
                  *   Logs Storing
                  */
                 $actionflag = '';
                 $tableid = '';
                 $menuID = APPRAISAL_MANAGER;
                 $actionflag = 1;
                 sapp_Global::logManager($menuID, $actionflag, $loginUserId, $tableid);
                 /*
                  *  Logs storing ends
                  */
                 //to get initialization details using appraisal Id for Business Unit,Department,To Year
                 $appraisalratingsmodel = new Default_Model_Appraisalratings();
                 $appraisal_details = $appraisalratingsmodel->getappdata($appraisal_id);
                 if (!empty($appraisal_details)) {
                     $bunit = $appraisal_details['unitname'];
                     $dept = $appraisal_details['deptname'];
                     $to_year = $appraisal_details['to_year'];
                 }
                 /** Start
                  * Sending Mails to employees
                  */
                 $appraisalconfigmodel = new Default_Model_Appraisalconfig();
                 $app_manager_model = new Default_Model_Appraisalmanager();
                 $getBunit_dept = $app_manager_model->getBunitDept($appraisal_id);
                 if (!empty($getBunit_dept)) {
                     $unitID = $getBunit_dept['businessunit_id'];
                     $deptID = $getBunit_dept['department_id'];
                 }
                 $employeeDetailsArr = $appraisalconfigmodel->getUserDetailsByID($unitID, $deptID);
                 $dept_str = $dept == '' ? " " : "and <b>{$dept}</b> department";
                 $emp_id_str = $loginuserRole == SUPERADMINROLE ? " " : "({$loginUserEmpId})";
                 $empArr = array();
                 if (!empty($employeeDetailsArr)) {
                     $empArrList = '';
                     foreach ($employeeDetailsArr as $emp) {
                         array_push($empArr, $emp['emailaddress']);
                     }
                 }
                 // Sending mail to HR
                 $options['subject'] = APPLICATION_NAME . ': Manager Appraisal Submitted.';
                 $options['header'] = 'Performance Appraisal : Manager Appraisal ' . $to_year;
                 $options['toEmail'] = $loginuserEmail;
                 $options['bcc'] = $empArr;
                 $options['toEmail'] = $loginuserEmail;
                 $options['toName'] = $loginuserFullname;
                 $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;'> " . $loginuserFullname . $emp_id_str . " has submitted the Manager appraisal form for the year <b>{$to_year}</b> for <b>{$bunit}</b> business unit {$dept_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 and 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);
                 /**
                  * End
                  */
                 $trDb->commit();
                 $result['status'] = 'success';
                 $result['msg'] = "Submitted successfully";
                 $this->_helper->getHelper("FlashMessenger")->addMessage(array("success" => "Initialization Submitted successfully. "));
             } catch (Exception $e) {
                 $trDb->rollBack();
                 $result['status'] = 'error';
                 $result['msg'] = $e->getMessage();
             }
         }
     }
     $this->_helper->json($result);
 }
 public function editAction()
 {
     $auth = Zend_Auth::getInstance();
     if ($auth->hasIdentity()) {
         $loginUserId = $auth->getStorage()->read()->id;
     }
     try {
         $appEmpRatingsModel = new Default_Model_Appraisalemployeeratings();
         $app_rating_model = new Default_Model_Appraisalratings();
         $appEmpRatingsData = $appEmpRatingsModel->getSelfAppraisalDataByEmpID($loginUserId);
         if (sizeof($appEmpRatingsData) > 0 && $appEmpRatingsData[0]['employee_id'] == $loginUserId && $appEmpRatingsData[0]['status'] == 1 && $appEmpRatingsData[0]['appraisal_status'] == APP_PENDING_EMP) {
             // Check rating exist for appraisal.
             $checkRatingsExists = $app_rating_model->getAppraisalRatingsbyInitId($appEmpRatingsData[0]['pa_initialization_id']);
             // get all Categories Data based on category ids
             $categories_data = $appEmpRatingsModel->getAppCateDataByIDs($appEmpRatingsData[0]['category_id']);
             // get question previleges data of employee for that initialization
             $appEmpQuesPrivData = $appEmpRatingsModel->getAppEmpQuesPrivData($appEmpRatingsData[0]['pa_initialization_id'], $appEmpRatingsData[0]['employee_id']);
             // merging HR and Manager questions
             $ques_csv = '';
             if ($appEmpQuesPrivData[0]['hr_qs']) {
                 $ques_csv .= $appEmpQuesPrivData[0]['hr_qs'];
             }
             if ($appEmpQuesPrivData[0]['manager_qs']) {
                 if ($ques_csv) {
                     $ques_csv .= ',';
                 }
                 $ques_csv .= $appEmpQuesPrivData[0]['manager_qs'];
             }
             // get all questions data based on above question ids
             $questions_data = $appEmpRatingsModel->getAppQuesDataByIDs($ques_csv);
             // merging HR and Manager questions privileges
             $hr_ques_previs = array();
             $mgr_ques_previs = array();
             $ratingType = array();
             if ($appEmpQuesPrivData[0]['hr_group_qs_privileges']) {
                 $hr_ques_previs = json_decode($appEmpQuesPrivData[0]['hr_group_qs_privileges'], true);
             }
             if ($appEmpQuesPrivData[0]['manager_qs_privileges']) {
                 $mgr_ques_previs = json_decode($appEmpQuesPrivData[0]['manager_qs_privileges'], true);
             }
             $question_previs = $hr_ques_previs + $mgr_ques_previs;
             // Employee and Manager response
             $emp_response = array();
             $mgr_response = array();
             if ($appEmpRatingsData[0]['employee_response']) {
                 $emp_response = json_decode($appEmpRatingsData[0]['employee_response'], true);
             }
             if ($appEmpRatingsData[0]['manager_response']) {
                 $mgr_response = json_decode($appEmpRatingsData[0]['manager_response'], true);
             }
             // get rating details using configuration id
             $ratingsData = $appEmpRatingsModel->getAppRatingsDataByConfgId($appEmpRatingsData[0]['pa_configured_id'], $appEmpRatingsData[0]['pa_initialization_id']);
             if (count($ratingsData) > 0) {
                 $ratingType = $ratingsData[0]['rating_type'];
             }
             $ratingText = array();
             $ratingValues = array();
             foreach ($ratingsData as $rd) {
                 $ratingText[] = $rd['rating_text'];
                 $ratingValues[$rd['id']] = $rd['rating_value'];
             }
             // building managers names from Emp-Ques-Privileges data
             $managerIDs = array();
             $managerNames = array();
             $line_unique_arr = array_filter(array_unique(array(1 => $appEmpQuesPrivData[0]['line_manager_1'], 2 => $appEmpQuesPrivData[0]['line_manager_2'], 3 => $appEmpQuesPrivData[0]['line_manager_3'], 4 => $appEmpQuesPrivData[0]['line_manager_4'], 5 => $appEmpQuesPrivData[0]['line_manager_5'])), 'strlen');
             if (!empty($line_unique_arr)) {
                 for ($i = 1; $i <= count($line_unique_arr); $i++) {
                     $managerIDs[] = $line_unique_arr[$i];
                 }
                 $usersData = $appEmpRatingsModel->getUserNamesByIDs(implode($managerIDs, ','));
                 foreach ($managerIDs as $mi) {
                     foreach ($usersData as $ud) {
                         if ($ud['id'] == $mi) {
                             $managerNames[] = $ud['userfullname'];
                         }
                     }
                 }
             }
             $this->view->managerNames = $managerNames;
             $this->view->mgrLevels = $appEmpQuesPrivData[0]['manager_levels'];
             $this->view->appEmpRatingsData = $appEmpRatingsData;
             $this->view->categories_data = $categories_data;
             $this->view->questions_data = $questions_data;
             $this->view->question_previs = $question_previs;
             $this->view->ratingType = $ratingType;
             $this->view->ratingText = json_encode($ratingText);
             $this->view->ratingValues = $ratingValues;
             $this->view->emp_response = $emp_response;
             $this->view->mgr_response = $mgr_response;
             $this->view->check_ratings_exists = $checkRatingsExists;
         } else {
             $this->view->rowexist = "norows";
         }
     } catch (Exception $e) {
         $this->view->rowexist = "norows";
     }
 }
 public function save($appraisalratingsform)
 {
     $auth = Zend_Auth::getInstance();
     if ($auth->hasIdentity()) {
         $loginUserId = $auth->getStorage()->read()->id;
         $loginRole = $auth->getStorage()->read()->emprole;
         $loginGroup = $auth->getStorage()->read()->group_id;
         $businessUnit = $auth->getStorage()->read()->businessunit_id;
         $department = $auth->getStorage()->read()->department_id;
     }
     $appraisalratingsmodel = new Default_Model_Appraisalratings();
     $app_init_model = new Default_Model_Appraisalinit();
     if ($loginRole != SUPERADMINROLE && $loginGroup != MANAGEMENT_GROUP) {
         $businessUnit = $businessUnit;
         $department = $department;
     } else {
         $businessUnit = $this->_request->getParam('businessunit');
         $department = $this->_request->getParam('departmentid');
     }
     //$res = $appraisalratingsmodel->checkAccessAddratings($businessUnit,$department);
     $res = $app_init_model->check_per_implmentation($businessUnit, $department);
     $implementation = $res['performance_app_flag'];
     $rating_type = $res['appraisal_ratings'];
     $configured_id = $res['id'];
     $msgarray = array();
     $resultArr = array();
     $errorflag = "true";
     $id = $this->_request->getParam('id');
     $appraisalid = $this->_request->getParam('appraisalid');
     // $update_id = $this->_request->getParam('update_id');
     $appraisal_ratings = $rating_type == 1 ? 5 : 10;
     $db = Zend_Db_Table::getDefaultAdapter();
     $db->beginTransaction();
     $actionflag = '';
     try {
         if ($id != '') {
             for ($i = 0; $i < $appraisal_ratings; $i++) {
                 $rating_text = $this->_request->getParam('rating_text_' . ($i + 1));
                 $update_id = $this->_request->getParam('update_id_' . ($i + 1));
                 /* for Update record  */
                 $where = array('id=?' => $update_id);
                 $actionflag = 2;
                 $menumodel = new Default_Model_Menu();
                 $tableid = '';
                 $data = array('rating_text' => $rating_text, 'modifiedby_role' => $loginRole, 'modifiedby_group' => $loginGroup, 'modifiedby' => $loginUserId, 'modifieddate' => gmdate("Y-m-d H:i:s"));
                 //$where = 'isactive=1';
                 $Id = $appraisalratingsmodel->SaveorUpdateAppraisalRatingsData($data, $where);
             }
         } else {
             for ($i = 0; $i < $appraisal_ratings; $i++) {
                 $rating_text = $this->_request->getParam('rating_text_' . $i);
                 $menumodel = new Default_Model_Menu();
                 $tableid = '';
                 $data = array('pa_configured_id' => $configured_id, 'pa_initialization_id' => $appraisalid, 'rating_type' => $rating_type, 'rating_value' => $i + 1, 'rating_text' => $rating_text, 'createdby_role' => $loginRole, 'createdby_group' => $loginGroup, 'modifiedby_role' => $loginRole, 'modifiedby_group' => $loginGroup, 'modifiedby' => $loginUserId, 'modifieddate' => gmdate("Y-m-d H:i:s"), 'createdby' => $loginUserId, 'createddate' => gmdate("Y-m-d H:i:s"), 'isactive' => 1);
                 $where = '';
                 $actionflag = 1;
                 $Id = $appraisalratingsmodel->SaveorUpdateAppraisalRatingsData($data, $where);
             }
         }
         if ($Id == 'update') {
             $tableid = $id;
             $this->_helper->getHelper("FlashMessenger")->addMessage(array("success" => "Ratings updated successfully."));
         } else {
             $tableid = $Id;
             $this->_helper->getHelper("FlashMessenger")->addMessage(array("success" => "Ratings added successfully."));
         }
         $menuidArr = $menumodel->getMenuObjID('/appraisalratings');
         $menuID = $menuidArr[0]['id'];
         $result = sapp_Global::logManager($menuID, $actionflag, $loginUserId, $tableid);
         /** Start
          * Sending Mails to employees
          */
         $appraisalconfigmodel = new Default_Model_Appraisalconfig();
         if ($implementation == 0) {
             $employeeDetailsArr = $appraisalconfigmodel->getUserDetailsByID($businessUnit, $department);
         } else {
             $employeeDetailsArr = $appraisalconfigmodel->getUserDetailsByID($businessUnit, '');
         }
         $msg_add_update = $Id == 'update' ? "updated" : "added";
         //Sending mail to Super admin
         $options['subject'] = APPLICATION_NAME . ': Performance Appraisal Ratings ' . ucfirst($msg_add_update);
         $options['header'] = 'Performance Appraisal Configuration';
         $options['toEmail'] = SUPERADMIN_EMAIL;
         $options['toName'] = 'Super Admin';
         $options['message'] = 'Dear Super Admin, performance appraisal configuration ' . $msg_add_update;
         // $mail_id =  sapp_Global::_sendEmail($options);
         // Sending mail to others
         if (!empty($employeeDetailsArr)) {
             foreach ($employeeDetailsArr as $emp) {
                 $options['subject'] = APPLICATION_NAME . ': Performance Appraisal Settings Added.';
                 $options['header'] = 'Performance Appraisal Configuration';
                 $options['toEmail'] = $emp['emailaddress'];
                 $options['toName'] = $emp['userfullname'];
                 $options['message'] = 'Dear ' . $emp['userfullname'] . ', performance appraisal configuration ' . $msg_add_update;
                 //  $mail_id =  sapp_Global::_sendEmail($options);
             }
         }
         /**
          * End
          */
         $db->commit();
         $this->_redirect('appraisalratings');
         //throw new Exception("Some error message");
     } catch (Exception $e) {
         $db->rollBack();
         echo $e->getMessage();
         echo $e->getTraceAsString();
         return $msgarray;
     }
 }
 public function updatelinemanagerAction()
 {
     $this->_helper->layout->disableLayout();
     $ajaxContext = $this->_helper->getHelper('AjaxContext');
     $ajaxContext->addActionContext('updatelinemanager', 'json')->initContext();
     $auth = Zend_Auth::getInstance();
     if ($auth->hasIdentity()) {
         $loginUserId = $auth->getStorage()->read()->id;
         $loginuserRole = $auth->getStorage()->read()->emprole;
         $loginuserGroup = $auth->getStorage()->read()->group_id;
         $loginUserEmpId = $auth->getStorage()->read()->employeeId;
         $loginUserEmail = $auth->getStorage()->read()->emailaddress;
         $loginUsername = $auth->getStorage()->read()->userfullname;
         $loginUserprofileimg = $auth->getStorage()->read()->profileimg;
     }
     $appraisalPrivMainModel = new Default_Model_Appraisalqsmain();
     $appraisalempratingsmodel = new Default_Model_Appraisalemployeeratings();
     $result['result'] = 'success';
     $result['msg'] = '';
     $send_mails = false;
     $appraisalid = $this->_request->getParam('appraisalid');
     $employeeid = $this->_request->getParam('employeeid');
     $line_1_mgr = $this->_request->getParam('line_1_mgr');
     $line_2_mgr = $this->_request->getParam('line_2_mgr');
     $line_3_mgr = $this->_request->getParam('line_3_mgr');
     $line_4_mgr = $this->_request->getParam('line_4_mgr');
     $line_5_mgr = $this->_request->getParam('line_5_mgr');
     $levels = $this->_request->getParam('levels');
     //checking equality of manager levels for sending mails
     if ($appraisalid && $employeeid) {
         $appraisal_level_arr = $appraisalPrivMainModel->getAllManagerIds($appraisalid, $employeeid);
         $appraisal_level_arr = $appraisal_level_arr[0];
         $levels_pre = $appraisal_level_arr['manager_levels'];
         if ($levels_pre == $levels) {
             $preLine_1_mgr = $appraisal_level_arr['line_manager_1'];
             $preLine_2_mgr = $appraisal_level_arr['line_manager_2'];
             $preLine_3_mgr = $appraisal_level_arr['line_manager_3'];
             $preLine_4_mgr = $appraisal_level_arr['line_manager_4'];
             $preLine_5_mgr = $appraisal_level_arr['line_manager_5'];
             for ($i = 1; $i <= $levels_pre; $i++) {
                 $preLine_mgr = "preLine_" . $i . "_mgr";
                 $line_mgr = "line_" . $i . "_mgr";
                 if (${$line_mgr} != ${$preLine_mgr}) {
                     $send_mails = true;
                 }
             }
         } else {
             $send_mails = true;
         }
     }
     //end checking send mails to employees
     if ($appraisalid && $employeeid) {
         $trDb = Zend_Db_Table::getDefaultAdapter();
         $trDb->beginTransaction();
         try {
             $data = array('line_manager_1' => $line_1_mgr != '' ? $line_1_mgr : NULL, 'line_manager_2' => $line_2_mgr != '' ? $line_2_mgr : NULL, 'line_manager_3' => $line_3_mgr != '' ? $line_3_mgr : NULL, 'line_manager_4' => $line_4_mgr != '' ? $line_4_mgr : NULL, 'line_manager_5' => $line_5_mgr != '' ? $line_5_mgr : NULL, 'manager_levels' => is_numeric($levels) ? $levels : 1, 'modifiedby' => $loginUserId, 'modifiedby_role' => $loginuserRole, 'modifiedby_group' => $loginuserGroup, 'modifieddate' => gmdate("Y-m-d H:i:s"));
             $privilegeswhere = " employee_id = '" . $employeeid . "' and pa_initialization_id='" . $appraisalid . "' and module_flag=1 and isactive=1 ";
             $empratingswhere = " employee_id = '" . $employeeid . "' and pa_initialization_id='" . $appraisalid . "' and isactive=1 ";
             $appraisalPrivMainModel->SaveorUpdatePrivilegeData($data, $privilegeswhere);
             //remove the manager_levels as this column is not there in main_pa_employee_ratings table
             unset($data['manager_levels']);
             $appraisalempratingsmodel->SaveorUpdateAppraisalSkillsData($data, $empratingswhere);
             if ($send_mails == true) {
                 /** Start
                  * Sending Mails to employees
                  */
                 $emp_id_str = $loginuserRole == SUPERADMINROLE ? " " : "({$loginUserEmpId})";
                 //Preparing string with line manager ids
                 $mgrStr = '';
                 for ($i = 1; $i <= $levels; $i++) {
                     $mgr_str = 'line_' . $i . '_mgr';
                     //$line_1_mgr
                     if (is_numeric(${$mgr_str})) {
                         $mgrStr .= ${$mgr_str} . ',';
                     }
                 }
                 $mgrStr = rtrim($mgrStr, ",");
                 $appraisalratingsmodel = new Default_Model_Appraisalratings();
                 $appraisal_details = $appraisalratingsmodel->getappdata($appraisalid);
                 if (!empty($appraisal_details)) {
                     $to_year = $appraisal_details['to_year'];
                 }
                 $employeeDetailsArr = $appraisalPrivMainModel->getManagerDetailsByIds($employeeid, $mgrStr);
                 $mgr_array = array();
                 $mgr_array = explode(",", $mgrStr);
                 //Preparing Employee array for Bcc
                 $empArr = array();
                 if (!empty($employeeDetailsArr)) {
                     $empArrList = '';
                     $empUserIdArr = array();
                     $toEmailId = '';
                     $toEmailName = '';
                     foreach ($employeeDetailsArr as $emp) {
                         array_push($empArr, $emp['emailaddress']);
                         //preparing Bcc array
                         array_push($empUserIdArr, $emp['user_id']);
                         if ($emp['user_id'] == $employeeid) {
                             $toEmailId = $emp['emailaddress'];
                             $toEmailName = $emp['userfullname'];
                             $toEmpId = $emp['employeeId'];
                             array_pop($empArr);
                         }
                     }
                     $index = array_search($employeeid, $empUserIdArr);
                     unset($employeeDetailsArr[$index]);
                     $mail_str = '';
                     for ($j = 0; $j < sizeof($mgr_array); $j++) {
                         foreach ($employeeDetailsArr as $employee) {
                             if ($mgr_array[$j] == $employee['user_id']) {
                                 $profile_pic = $employee['profileimg'];
                                 $cnt = $j + 1;
                                 if ($profile_pic != '') {
                                     $src = DOMAIN . "public/uploads/profile/" . $profile_pic;
                                 } else {
                                     $src = MEDIA_PATH . "images/default-profile-pic.jpg";
                                 }
                                 $mail_str .= "<div style='padding:20px 0 0 0;color:#3b3b3b;'>Line {$cnt} Manager : " . $employee['userfullname'] . " <img src=" . $src . " onError=this.src=" . MEDIA_PATH . "images/default-profile-pic.jpg width='30px' height='30px' /></div>";
                             }
                         }
                     }
                 }
                 //pushing loginUserEmail to Bcc array
                 array_push($empArr, $loginUserEmail);
                 $options['subject'] = APPLICATION_NAME . ': Change in Line Managers';
                 $options['header'] = 'Performance Appraisal : ' . $to_year;
                 $options['bcc'] = $empArr;
                 $options['toEmail'] = $toEmailId;
                 $options['toName'] = $toEmailName;
                 $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;'>Line Managers for " . $toEmailName . "(" . $toEmpId . ") have been modified by " . $loginUsername . $emp_id_str . "</div>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t{$mail_str}\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 and 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);
                 /**
                  * End mails sending
                  */
             }
             $trDb->commit();
         } catch (Exception $e) {
             $trDb->rollBack();
             $result['result'] = 'error';
             $result['msg'] = $e->getMessage();
         }
     }
     $this->_helper->json($result);
 }
 public function getsearchedempcontentAction()
 {
     $errorMsg = "";
     $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;
     }
     $searchval = '';
     $searchstring = mysql_real_escape_string($this->_request->getParam('searchstring'));
     // $searchstring = $this->_request->getParam('searchstring');
     $view = $this->view;
     $model = new Default_Model_Appraisalmanager();
     $app_rating_model = new Default_Model_Appraisalratings();
     $ratingflag = 'false';
     $linemangerids = '';
     $managerprofileimgArr = array();
     if ($searchstring != '') {
         $searchval = " and es.userfullname like '%{$searchstring}%'";
     }
     //$emp_data = $model->getSearchEmpdata_managerapp($loginUserId,$searchval);
     $emp_data = $model->getEmpdata_managerapp($loginUserId, $searchval);
     if (!empty($emp_data)) {
         foreach ($emp_data as $key => $empval) {
             for ($i = 1; $i <= 5; $i++) {
                 if (isset($empval['line_rating_' . $i])) {
                     $linemangerids .= $empval['line_manager_' . $i] . ',';
                 }
             }
             if ($linemangerids) {
                 $linemangerids = rtrim($linemangerids, ',');
                 $managerprofileimgArr = $app_rating_model->getManagerProfileImg($linemangerids);
             }
             $emp_data[$key] = $emp_data[$key] + $managerprofileimgArr;
             $linemangerids = '';
             $managerprofileimgArr = array();
         }
     }
     $view->emp_data = $emp_data;
     $view->manager_id = $loginUserId;
     $view->error_msg = $errorMsg;
 }
 public function saveAction()
 {
     $auth = Zend_Auth::getInstance();
     $loginuserFullName = '';
     if ($auth->hasIdentity()) {
         $loginUserId = $auth->getStorage()->read()->id;
         $loginuserRole = $auth->getStorage()->read()->emprole;
         $loginuserGroup = $auth->getStorage()->read()->group_id;
         $loginuserProfileImg = $auth->getStorage()->read()->profileimg;
         $loginuserEmail = $auth->getStorage()->read()->emailaddress;
         $loginuserFullName = $auth->getStorage()->read()->userfullname;
         $loginUserEmpId = $auth->getStorage()->read()->employeeId;
     }
     try {
         $appEmpRatingsModel = new Default_Model_Appraisalemployeeratings();
         $app_init_model = new Default_Model_Appraisalinit();
         $id = $this->_request->getParam('id');
         $employee_id = $this->_request->getParam('employee_id');
         $initialization_id = $this->_request->getParam('initialization_id');
         $config_id = $this->_request->getParam('config_id');
         $flag = $this->_request->getParam('flag');
         $app_status = $this->_request->getParam('app_status');
         $mgr_levels = $this->_request->getParam('mgr_levels');
         $ratingsData = $appEmpRatingsModel->getAppRatingsDataByConfgId($config_id, $initialization_id);
         $ratingValues = array();
         foreach ($ratingsData as $rd) {
             $ratingValues[$rd['id']] = $rd['rating_value'];
         }
         $appData = array('modifiedby' => $loginUserId, 'modifiedby_role' => $loginuserRole, 'modifiedby_group' => $loginuserGroup, 'modifieddate' => gmdate("Y-m-d H:i:s"));
         $emp_rating_arr = $this->_request->getParam('emp_rating');
         $emp_comment_arr = $this->_request->getParam('emp_comment');
         $emp_response = array();
         if (sizeof($emp_rating_arr) > 0 || sizeof($emp_comment_arr) > 0) {
             foreach ($emp_rating_arr as $qid => $val) {
                 if (isset($emp_rating_arr[$qid])) {
                     $rating_id = array_search($emp_rating_arr[$qid], $ratingValues);
                 } else {
                     $rating_id = '';
                 }
                 $emp_response[$qid] = array('comment' => $emp_comment_arr[$qid], 'rating_id' => $rating_id);
             }
         }
         $appData['employee_response'] = json_encode($emp_response, true);
         $curent_level = array_search($app_status, $this->app_status_array);
         if ($flag == 'submit') {
             $appData['appraisal_status'] = $curent_level + 1;
             $history_desc = $this->app_history_disc_array[$curent_level];
             $appHistoryData = array('employee_id' => $employee_id, 'pa_initialization_id' => $initialization_id, 'description' => $history_desc, 'desc_emp_id' => $loginUserId, 'desc_emp_name' => $loginuserFullName, 'desc_emp_profileimg' => $loginuserProfileImg, 'createdby' => $loginUserId, 'createddate' => gmdate("Y-m-d H:i:s"), 'modifiedby' => $loginUserId, 'modifieddate' => gmdate("Y-m-d H:i:s"));
             $appHistoryModel = new Default_Model_Appraisalhistory();
             $result2 = $appHistoryModel->SaveorUpdateAppraisalHistoryData($appHistoryData);
             /* Update employee response column */
             $appraisaldata = $app_init_model->getConfigData($initialization_id);
             if ($appraisaldata[0]['employee_response'] == 1) {
                 $initdata = array('employee_response' => 2, 'modifiedby' => $loginUserId, 'modifiedby_role' => $loginuserRole, 'modifiedby_group' => $loginuserGroup, 'modifieddate' => gmdate("Y-m-d H:i:s"));
                 $initwhere = array('id=?' => $initialization_id);
                 $app_init_model->SaveorUpdateAppraisalInitData($initdata, $initwhere);
             }
             /*
              *   Logs Storing
              */
             $menumodel = new Default_Model_Menu();
             $actionflag = '';
             $tableid = '';
             $actionflag = 1;
             $menuidArr = $menumodel->getMenuObjID('/appraisalself');
             $menuID = $menuidArr[0]['id'];
             sapp_Global::logManager($menuID, $actionflag, $loginUserId, $tableid);
             /*
              *  Logs storing ends
              */
             /** Start
              * Sending Mails to employees
              */
             //to get initialization details using appraisal Id for Business Unit,Department,To Year
             $appraisalratingsmodel = new Default_Model_Appraisalratings();
             $appraisal_details = $appraisalratingsmodel->getappdata($initialization_id);
             if (!empty($appraisal_details)) {
                 $bunit = $appraisal_details['unitname'];
                 $dept = $appraisal_details['deptname'];
                 $to_year = $appraisal_details['to_year'];
             }
             $dept_str = $dept == '' ? " " : "and <b>{$dept}</b> department";
             $emp_id_str = $loginuserRole == SUPERADMINROLE ? " " : "({$loginUserEmpId})";
             $app_manager_model = new Default_Model_Appraisalmanager();
             $getLineManager = $app_manager_model->getLineMgr($initialization_id, $loginUserId);
             if (!empty($getLineManager)) {
                 $line_mgr = $getLineManager['line_manager_1'];
                 $employeeDetailsArr = $app_manager_model->getUserDetailsByEmpID($line_mgr);
                 $employeeDetailsArr = $employeeDetailsArr[0];
                 // Sending mail to Manager
                 if (!empty($employeeDetailsArr)) {
                     $options['subject'] = APPLICATION_NAME . ': Self Appraisal Submitted';
                     $options['header'] = "Performance Appraisal : {$to_year}";
                     $options['toEmail'] = $employeeDetailsArr['emailaddress'];
                     $options['toName'] = $employeeDetailsArr['userfullname'];
                     $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;'>Dear " . $employeeDetailsArr['userfullname'] . ",</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;'> " . $loginuserFullName . $emp_id_str . " has submitted appraisal form.</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 <b>" . APPLICATION_NAME . "</b>  and check the appraisal ratings and comments.</div>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t</div> ";
                     $mail_id = sapp_Global::_sendEmail($options);
                 }
             }
             //Sending mail to Employee
             $options['subject'] = APPLICATION_NAME . ': Performance Appraisal Submitted to Line1 manager';
             $options['header'] = "Performance Appraisal : {$to_year}";
             $options['toEmail'] = $loginuserEmail;
             $options['toName'] = $loginuserFullName;
             $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;'>Dear {$loginuserFullName},</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;'>Your appraisal form is submitted successfully to your Line1 Manager," . $employeeDetailsArr['userfullname'] . "(" . $employeeDetailsArr['employeeId'] . ") </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.</div>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t</div> ";
             $mail_id = sapp_Global::_sendEmail($options);
         }
         /**
          * End
          */
         $appWhere = array('id=?' => $id);
         $result1 = $appEmpRatingsModel->SaveorUpdateAppraisalSkillsData($appData, $appWhere);
         if ($result1) {
             $msg = 'saved';
         } else {
             $msg = 'err';
         }
     } catch (Exception $e) {
         //echo $e->getMessage();
         //echo $e->getTrace();
         //echo $e->getTraceAsString();
         $msg = "Something went wrong, please try again.";
     }
     $this->_helper->json(array('msg' => $msg));
 }
 public function ffinitialize($appInitId, $tableid, $enable_to, $check)
 {
     if ($tableid) {
         $auth = Zend_Auth::getInstance();
         if ($auth->hasIdentity()) {
             $loginUserId = $auth->getStorage()->read()->id;
             $loginuserRole = $auth->getStorage()->read()->emprole;
             $loginuserGroup = $auth->getStorage()->read()->group_id;
             $loginUserEmpId = $auth->getStorage()->read()->employeeId;
             $loginUserfullname = $auth->getStorage()->read()->userfullname;
         }
         $ffEmpRatingsModel = new Default_Model_Feedforwardemployeeratings();
         $feedforwardInitModel = new Default_Model_Feedforwardinit();
         $appraisalEmpsData = $feedforwardInitModel->getEmpsFromAppEmpRat($appInitId);
         $appEmpIDs = array();
         if (sizeof($appraisalEmpsData) > 0) {
             foreach ($appraisalEmpsData as $appE) {
                 $appEmpIDs[] = $appE['employee_id'];
                 $where = '';
                 $data = array('ff_initialization_id' => $tableid, 'question_ids' => $check != '' ? implode(',', $check) : NULL, 'manager_id' => $appE['line_manager_1'], 'employee_id' => $appE['employee_id'], 'ff_status' => 1, 'createdby' => $loginUserId, 'createdby_role' => $loginuserRole, 'createdby_group' => $loginuserGroup, 'createddate' => gmdate("Y-m-d H:i:s"));
                 $ffEmpRatingsModel->SaveorUpdateFFEmpRatingsData($data, $where);
             }
         }
         if (sizeof($appEmpIDs) > 0 && $enable_to == 1) {
             $appEmpIDsCsv = implode(',', $appEmpIDs);
             $allEmpsData = $feedforwardInitModel->getEmpsFromSummary($appEmpIDsCsv);
             if (sizeof($allEmpsData) > 0) {
                 foreach ($allEmpsData as $allE) {
                     $where1 = '';
                     $data1 = array('ff_initialization_id' => $tableid, 'question_ids' => $check != '' ? implode(',', $check) : NULL, 'manager_id' => $allE['reporting_manager'], 'employee_id' => $allE['user_id'], 'ff_status' => 1, 'createdby' => $loginUserId, 'createdby_role' => $loginuserRole, 'createdby_group' => $loginuserGroup, 'createddate' => gmdate("Y-m-d H:i:s"));
                     $ffEmpRatingsModel->SaveorUpdateFFEmpRatingsData($data1, $where1);
                 }
             }
         }
         $actionflag = 1;
         $tableid = '';
         $menuID = INITIALIZE_FEEDFORWARD;
         $result = sapp_Global::logManager($menuID, $actionflag, $loginUserId, $tableid);
         /** Start
          * Sending Mails to Super Admin,Management,HR
          */
         $appraisalratingsmodel = new Default_Model_Appraisalratings();
         $appraisalconfigmodel = new Default_Model_Appraisalconfig();
         //to get initialization details using appraisal Id for Business Unit,Department,To Year
         $appraisal_details = $appraisalratingsmodel->getappdata($appInitId);
         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'];
             $employeeDetailsArr = $appraisalconfigmodel->getUserDetailsByID($businessUnit, $department);
             if ($enable_to == 1) {
                 $empforFF = $feedforwardInitModel->getEmpIdforFF($businessUnit, $department);
             } else {
                 $empforFF = $feedforwardInitModel->getAppemployeeIDs($appInitId);
             }
             $ffEmpArr = array();
             $ffEmpList = '';
             if (!empty($empforFF)) {
                 foreach ($empforFF as $emp) {
                     array_push($ffEmpArr, $emp['employeeId']);
                 }
                 $ffEmpList = implode(',', $ffEmpArr);
             }
             $ffEmpEmailArr = array();
             $ffemployeeDetailsArr = $feedforwardInitModel->getUserDetailsByIds($ffEmpList);
             if (!empty($ffemployeeDetailsArr)) {
                 foreach ($ffemployeeDetailsArr as $empFF) {
                     array_push($ffEmpEmailArr, $empFF['emailaddress']);
                 }
             }
             $dept_str = $dept == '' ? " " : "and department <b>{$dept}</b> ";
             $emp_id_str = $loginuserRole == SUPERADMINROLE ? " " : "({$loginUserEmpId})";
             //Preparing Employee array for Bcc
             $empArr = array();
             $total_emp_arr = array();
             if (!empty($employeeDetailsArr)) {
                 $empArrList = '';
                 foreach ($employeeDetailsArr as $emp) {
                     array_push($empArr, $emp['emailaddress']);
                 }
             }
             $total_emp_arr = array_merge($empArr, $ffEmpEmailArr);
             //Sending mail to Super admin,HR,Management
             $options['subject'] = APPLICATION_NAME . ': Feedforward Initialization';
             $options['header'] = 'Feedforward Initialization : ' . $to_year;
             $options['toEmail'] = SUPERADMIN_EMAIL;
             $options['toName'] = 'Super Admin';
             $options['bcc'] = $total_emp_arr;
             $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<span style='color:#3b3b3b;'>Hi,</span><br />\n\t\t\t\t\t\t\t\t\t\t<div style='padding:20px 0 0 0;color:#3b3b3b;'>Feedforward process have been initialized 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<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 and check the details.</div>\n\t\t\t\t\t\t\t\t\t\t</div> ";
             //'Dear Super Admin, performance appraisal Initialized '.$mail_str;
             $mail_id = sapp_Global::_sendEmail($options);
         }
     }
 }
 public function savemngrorghierarchyAction()
 {
     $auth = Zend_Auth::getInstance();
     if ($auth->hasIdentity()) {
         $loginUserId = $auth->getStorage()->read()->id;
         $loginuserRole = $auth->getStorage()->read()->emprole;
         $loginuserGroup = $auth->getStorage()->read()->group_id;
     }
     $app_init_model = new Default_Model_Appraisalinit();
     $ques_temp_model = new Default_Model_Appraisalqstemp();
     $ques_org_model = new Default_Model_Appraisalqsmain();
     $app_rating_model = new Default_Model_Appraisalratings();
     // $init_id = $this->_getParam('init_id',null);
     $init_param = $this->_getParam('i', null);
     $init_id = sapp_Global::_decrypt($init_param);
     $init_data = $app_init_model->getConfigData($init_id);
     if (count($init_data) > 0) {
         $init_data = $init_data[0];
     }
     $this->view->init_id = $init_id;
     $this->view->init_data = $init_data;
     $this->view->msg_arr = array();
     $ratingsflag = 'false';
     $checkRatingsExists = $app_rating_model->getAppraisalRatingsbyInitId($init_id);
     if (!empty($checkRatingsExists)) {
         $ratingsflag = 'true';
     }
     $red_result = "";
     $type_arr = array('line' => 1, 'report' => 2);
     $trDb = Zend_Db_Table::getDefaultAdapter();
     //get manager ids as comma seperated string
     $manager_ids = $this->_getParam('mid', null);
     //break the manager ids into array
     $mngr_ids_array = explode(',', $manager_ids);
     $get_managers_data = array();
     $get_managers_data = $app_init_model->getManagers_report($init_id);
     $final_managers_data = array();
     //get the managers data and build an array with manager id as key
     if (isset($get_managers_data) && count($get_managers_data) > 0) {
         foreach ($get_managers_data as $data) {
             $mngr_id = isset($data['user_id']) ? $data['user_id'] : 0;
             $final_managers_data[$mngr_id] = $data;
         }
     }
     if (isset($mngr_ids_array) && count($mngr_ids_array) > 0) {
         $choose_option = 'report';
         foreach ($mngr_ids_array as $mngr) {
             $tot_ids = array();
             $context = 'add';
             $content = array();
             $content = $app_init_model->getdisplayacontentreportacc($init_id, $mngr);
             if ($context == 'add') {
                 $init_sdata = array('manager_level_type' => $type_arr[$choose_option]);
                 $app_result = array();
                 $app_result = $app_init_model->SaveorUpdateAppraisalInitData($init_sdata, " id = " . $init_id);
                 $qresult = '';
                 if ($app_result === 'update') {
                     if (count($content) > 0) {
                         foreach ($content as $cont) {
                             if (is_numeric($cont['user_id'])) {
                                 array_push($tot_ids, $cont['user_id']);
                             }
                         }
                     }
                     $line_str_arr = array();
                     $line_str_arr['line_manager_1'] = $mngr;
                     if (count($tot_ids) > 0) {
                         foreach ($tot_ids as $emp_id) {
                             $qdata = array('pa_initialization_id' => $init_id, 'manager_levels' => 1, 'employee_id' => $emp_id, 'module_flag' => 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"), 'isactive' => 1);
                             $qdata = array_merge($qdata, $line_str_arr);
                             if ($init_data['initialize_status'] == 1) {
                                 $qresult = $ques_org_model->SaveorUpdatePrivilegeData($qdata, '');
                             } else {
                                 $qresult = $ques_temp_model->SaveorUpdateData($qdata, '');
                             }
                         }
                     }
                 }
                 if ($qresult !== '' && $app_result !== '') {
                     $red_result = 'saved';
                 }
                 $message = "Appraisal process updated successfully";
             }
         }
         if ($red_result === 'saved') {
             $message = "Appraisal process updated successfully";
             $this->_helper->FlashMessenger()->setNamespace('conf_success')->addMessage($message);
             $this->_redirect('appraisalinit/confmanagers/i/' . sapp_Global::_encrypt($init_id));
         }
     }
     $this->view->ratingsflag = $ratingsflag;
     $this->render('configuremanagers');
 }
 public function save($appraisalratingsform)
 {
     $auth = Zend_Auth::getInstance();
     if ($auth->hasIdentity()) {
         $loginUserId = $auth->getStorage()->read()->id;
         $loginRole = $auth->getStorage()->read()->emprole;
         $loginGroup = $auth->getStorage()->read()->group_id;
         $businessUnit = $auth->getStorage()->read()->businessunit_id;
         $department = $auth->getStorage()->read()->department_id;
         $loginUserfullname = $auth->getStorage()->read()->userfullname;
         $loginUserEmpId = $auth->getStorage()->read()->employeeId;
     }
     $appraisalratingsmodel = new Default_Model_Appraisalratings();
     $app_init_model = new Default_Model_Appraisalinit();
     if ($loginRole != SUPERADMINROLE && $loginGroup != MANAGEMENT_GROUP) {
         $businessUnit = $businessUnit;
         $department = $department;
     } else {
         $businessUnit = $this->_request->getParam('businessunit');
         $department = $this->_request->getParam('departmentid');
     }
     $res = $app_init_model->checkAppraisalExists($businessUnit, $department);
     $implementation = isset($res[0]['performance_app_flag']) ? $res[0]['performance_app_flag'] : NULL;
     $rating_type = !empty($res[0]['appraisal_ratings']) ? $res[0]['appraisal_ratings'] : NULL;
     $configured_id = 0;
     $msgarray = array();
     $resultArr = array();
     $errorflag = "true";
     $id = $this->_request->getParam('id');
     $dept_id = $this->_request->getParam('departmentid');
     $implementation = is_numeric($dept_id) && $dept_id > 0 ? 0 : 1;
     $appraisal_ratings = $this->_request->getParam('appraisal_rating');
     $appraisalid = $this->_request->getParam('appraisalid');
     $db = Zend_Db_Table::getDefaultAdapter();
     $db->beginTransaction();
     $actionflag = '';
     try {
         if ($id != '') {
             for ($i = 0; $i < $appraisal_ratings; $i++) {
                 $rating_text = $this->_request->getParam('rating_text_' . ($i + 1));
                 $update_id = $this->_request->getParam('update_id_' . ($i + 1));
                 /* for Update record  */
                 $where = array('id=?' => $update_id);
                 $actionflag = 2;
                 $tableid = '';
                 $data = array('rating_text' => $rating_text, 'modifiedby_role' => $loginRole, 'modifiedby_group' => $loginGroup, 'modifiedby' => $loginUserId, 'modifieddate' => gmdate("Y-m-d H:i:s"));
                 $Id = $appraisalratingsmodel->SaveorUpdateAppraisalRatingsData($data, $where);
             }
         } else {
             for ($i = 0; $i < $appraisal_ratings; $i++) {
                 $rating_text = $this->_request->getParam('rating_text_' . $i);
                 $tableid = '';
                 $data = array('pa_configured_id' => $configured_id, 'pa_initialization_id' => $appraisalid, 'rating_type' => $rating_type, 'rating_value' => $i + 1, 'rating_text' => $rating_text, 'createdby_role' => $loginRole, 'createdby_group' => $loginGroup, 'modifiedby_role' => $loginRole, 'modifiedby_group' => $loginGroup, 'modifiedby' => $loginUserId, 'modifieddate' => gmdate("Y-m-d H:i:s"), 'createdby' => $loginUserId, 'createddate' => gmdate("Y-m-d H:i:s"), 'isactive' => 1);
                 $where = '';
                 $actionflag = 1;
                 $Id = $appraisalratingsmodel->SaveorUpdateAppraisalRatingsData($data, $where);
             }
         }
         if ($Id == 'update') {
             $tableid = $id;
             $this->_helper->getHelper("FlashMessenger")->addMessage(array("success" => "Ratings updated successfully."));
         } else {
             $tableid = $Id;
             $this->_helper->getHelper("FlashMessenger")->addMessage(array("success" => "Ratings added successfully."));
         }
         /*
          *   Logs Storing
          */
         $menuID = APPRAISALRATINGS;
         $result = sapp_Global::logManager($menuID, $actionflag, $loginUserId, $tableid);
         /*
          *  Logs storing ends
          */
         //to get initialization details using appraisal Id for Business Unit,Department,To Year
         $appraisal_details = $appraisalratingsmodel->getappdata($appraisalid);
         if (!empty($appraisal_details)) {
             $bunit = $appraisal_details['unitname'];
             $dept = $appraisal_details['deptname'];
             $to_year = $appraisal_details['to_year'];
         }
         /** Start
          * Sending Mails to employees
          */
         $appraisalconfigmodel = new Default_Model_Appraisalconfig();
         if ($implementation == 0) {
             $employeeDetailsArr = $appraisalconfigmodel->getUserDetailsByID($businessUnit, $department);
         } else {
             $employeeDetailsArr = $appraisalconfigmodel->getUserDetailsByID($businessUnit, '');
         }
         $msg_add_update = $Id == 'update' ? "updated" : "configured";
         $dept_str = $dept == '' ? " " : "and department <b>{$dept}</b> ";
         $emp_id_str = $loginRole == SUPERADMINROLE ? " " : "({$loginUserEmpId})";
         //Preparing Employee array for Bcc
         $empArr = array();
         if (!empty($employeeDetailsArr)) {
             $empArrList = '';
             foreach ($employeeDetailsArr as $emp) {
                 array_push($empArr, $emp['emailaddress']);
             }
         }
         //echo "<pre>";print_r($empArr);die();
         $options['subject'] = APPLICATION_NAME . ': Performance Appraisal Ratings ' . ucfirst($msg_add_update);
         $options['header'] = 'Performance Appraisal : Ratings';
         $options['bcc'] = $empArr;
         $options['toEmail'] = SUPERADMIN_EMAIL;
         $options['toName'] = 'Super Admin';
         $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<span style='color:#3b3b3b;'>Hi,</span><br />\n\t\t\t<div style='padding:20px 0 0 0;color:#3b3b3b;'>Performance appraisal ratings have been {$msg_add_update} 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<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.</div>\n\t\t\t</div> ";
         $mail_id = sapp_Global::_sendEmail($options);
         /**
          * End mails sending
          */
         $db->commit();
         $this->_redirect('appraisalratings');
     } catch (Exception $e) {
         $db->rollBack();
         echo $e->getMessage();
         echo $e->getTraceAsString();
         return $msgarray;
     }
 }
 public function assigngroupsAction()
 {
     $appraisalinitmodel = new Default_Model_Appraisalinit();
     $appraisalGroupsModel = new Default_Model_Appraisalgroups();
     $appraisalQsModel = new Default_Model_Appraisalquestions();
     $app_rating_model = new Default_Model_Appraisalratings();
     $init_param = $this->_getParam('i', null);
     $init_id = sapp_Global::_decrypt($init_param);
     $id = $init_id;
     $employeeIds = '';
     $groupIds = '';
     $options = '';
     $appraisalgroupName = '';
     $data['empcount'] = '';
     $groupflag = 'notassigned';
     $msgarray = array();
     $check_array = array();
     $questionsArr = array();
     $ratingsflag = 'false';
     $auth = Zend_Auth::getInstance();
     if ($auth->hasIdentity()) {
         $loginUserId = $auth->getStorage()->read()->id;
         $loginuserRole = $auth->getStorage()->read()->emprole;
         $loginuserGroup = $auth->getStorage()->read()->group_id;
     }
     try {
         if ($id) {
             if (is_numeric($id) && $id > 0) {
                 $checkRatingsExists = $app_rating_model->getAppraisalRatingsbyInitId($id);
                 if (!empty($checkRatingsExists)) {
                     $ratingsflag = 'true';
                 }
                 $data = $appraisalinitmodel->getConfigData($id);
                 //echo '<pre>';print_r($data);exit;
                 if (!empty($data) && $data[0]['status'] == 1) {
                     $data = $data[0];
                     if ($data['initialize_status'] == 1) {
                         $tablename = 'main_pa_questions_privileges';
                     } else {
                         $tablename = 'main_pa_questions_privileges_temp';
                     }
                     if ($data['group_settings'] != 0) {
                         if ($data['group_settings'] == 1) {
                             $questionPrivileges = $appraisalQsModel->gethrquestionprivileges($id, $tablename, '');
                             if ($data['category_id'] != '' && $data['category_id'] != 'null') {
                                 /*if($data['initialize_status'] == 1)
                                 			$questionsArr = $appraisalQsModel->getQuestionsByCategory($data['category_id'],$questionPrivileges['hr_qs']);
                                 		else*/
                                 $questionsArr = $appraisalQsModel->getQuestionsByCategory($data['category_id'], '');
                             }
                             //echo '<pre>';print_r($questionPrivileges);exit;
                             if (!empty($questionPrivileges)) {
                                 if (isset($questionPrivileges['hr_qs']) && isset($questionPrivileges['hr_group_qs_privileges'])) {
                                     if ($questionPrivileges['hr_qs'] != '' && $questionPrivileges['hr_group_qs_privileges'] != '') {
                                         $hr_qs_Arr = explode(',', $questionPrivileges['hr_qs']);
                                         $hr_qs_privileges = json_decode($questionPrivileges['hr_group_qs_privileges'], true);
                                         foreach ($hr_qs_privileges as $key => $val) {
                                             //$val = explode(',',substr($val, 1, -1));
                                             $check_array[$key] = $val;
                                         }
                                     }
                                 }
                             }
                             $this->view->questionsArr = $questionsArr;
                             $this->view->checkArr = $check_array;
                         } else {
                             $groupEmployeeCountArr = $appraisalQsModel->getGroupEmployeeCount($id, $tablename);
                             $EmpCountArr = $appraisalQsModel->getGroupCountDetails($id, $tablename);
                             if (!empty($EmpCountArr)) {
                                 $data['empcount'] = $EmpCountArr[0]['empcount'];
                             }
                             //echo '<pre>';print_r($groupEmployeeCountArr);exit;
                             $this->view->groupEmployeeCountArr = $groupEmployeeCountArr;
                         }
                         $this->view->msgarray = $msgarray;
                     }
                     if (sapp_Global::_checkprivileges(APPRAISALQUESTIONS, $loginuserGroup, $loginuserRole, 'edit') == 'Yes') {
                         $data['poppermission'] = 'yes';
                     }
                     $this->view->appraisalid = $id;
                     $this->view->encryptapprslid = $init_param;
                     $this->view->initializationdata = $data;
                     $this->view->ratingsflag = $ratingsflag;
                     if ($this->getRequest()->getPost()) {
                         $result = $this->savequestionPrivilegs($data);
                         $this->view->msgarray = $result;
                     }
                     $this->view->messages = $this->_helper->flashMessenger->getMessages();
                 } else {
                     $this->view->ermsg = 'norecord';
                 }
             } else {
                 $this->view->ermsg = 'norecord';
             }
         } else {
             $this->view->ermsg = 'norecord';
         }
     } catch (Exception $e) {
         $this->view->ermsg = 'nodata';
     }
 }