/**
  * 
  */
 public function assignservicerequestpopupAction()
 {
     $request_form = new Default_Form_Servicerequest();
     $id = $this->_getParam('id', null);
     $req_msg = "";
     try {
         if ($id != '') {
             $sd_req_model = new Default_Model_Servicerequests();
             $grid_type_arr = $sd_req_model->getGridtypearr();
             if (is_numeric($id) && $id > 0) {
                 $auth = Zend_Auth::getInstance();
                 if ($auth->hasIdentity()) {
                     $loginUserId = $auth->getStorage()->read()->id;
                     $loginuserRole = $auth->getStorage()->read()->emprole;
                     $loginuserGroup = $auth->getStorage()->read()->group_id;
                     $login_bu = $auth->getStorage()->read()->businessunit_id;
                     $login_dept = $auth->getStorage()->read()->department_id;
                 }
                 $data = $sd_req_model->getRequestById($id);
                 if (!empty($data)) {
                     $approver_level = "view";
                     if (($grid_type_arr[$grid_type] == 'rept_app' || $grid_type_arr[$grid_type] == 'approver') && $data['status'] == 'To management approve') {
                         $approver_level = $sd_req_model->getApproverLevel($loginUserId, $id);
                     }
                     $emp_model = new Default_Model_Employee();
                     $service_conf_model = new Default_Model_Servicedeskconf();
                     $other_approvers = $emp_model->get_Service_Executors($id);
                     foreach ($app_data as $key => $value) {
                         $app_names[$key] = $app_details[$value];
                     }
                     $conf_data = $service_conf_model->getServiceDeskConfbyID($data['service_desk_conf_id']);
                     $exec_data = $emp_model->getEmployeeDetails($conf_data[0]['request_recievers']);
                     $this->view->id = $id;
                     $this->view->data = $data;
                     $this->view->loginUserId = $loginUserId;
                     $this->view->other_approvers = $other_approvers;
                     $this->view->app_names = $app_names;
                     $this->view->exec_data = $exec_data;
                     if ($this->getRequest()->getPost()) {
                         $trDb = Zend_Db_Table::getDefaultAdapter();
                         // starting transaction
                         $trDb->beginTransaction();
                         try {
                             $req_id = $this->_getParam('hid_reqid', null);
                             $hid_status = $this->_getParam('hid_status', null);
                             $selexecutorid = trim($this->_getParam('executor_action', null));
                             $request_comments = trim($this->_getParam('request_comments', null));
                             $save_data = array('executor_id' => trim($selexecutorid), 'ticket_assigned_by' => trim($loginUserId), 'ticket_assigned_comments' => trim($request_comments), 'modifiedby' => $loginUserId, 'modifieddate' => gmdate("Y-m-d H:i:s"));
                             $req_msg['success'] = "Executor assigned to service request.";
                             $sd_result = "";
                             if ($data['status'] != 'Closed' && $data['status'] != 'Rejected') {
                                 $sd_result = $sd_req_model->SaveorUpdateRequestData($save_data, 'id = ' . $id);
                                 //email stuff ------------Start
                                 $sEmailData = $sd_req_model->getRequestDataForEmail($id);
                                 $sMailSubject = sprintf("%s - %s - %s - %s", $sEmailData['ticket_number'], $sEmailData['service_desk_name'], $sEmailData['service_request_name'], $sEmailData['status']);
                                 $smessage = "A new executor for this service request.";
                                 $summary_data = $sd_req_model->getDataSummary($id);
                                 $stoEmailAddress1 = $sd_req_model->getEmailAddress($selexecutorid);
                                 $stoEmailAddress2 = $sd_req_model->getEmailAddress($sEmailData['raised_by']);
                                 $stoEmailAddress3 = constant('ITSUPPORT_0');
                                 //$stoEmailAddress3 = $this->getSupportTeamEmailID($sEmailData['service_desk_conf_id']);
                                 $this->mail_helper_action($sMailSubject, $smessage, $summary_data, $stoEmailAddress1);
                                 $this->mail_helper_action($sMailSubject, $smessage, $summary_data, $stoEmailAddress2);
                                 $this->mail_helper_action($sMailSubject, $smessage, $summary_data, $stoEmailAddress3);
                                 //email stuff ------------End
                             }
                             //start of saving history
                             $reqh_model = new Default_Model_Requesthistory();
                             $reqh_data = array('request_id' => $id, 'description' => ucfirst($req_msg['success']), 'emp_id' => $loginUserId, 'emp_name' => ucfirst($auth->getStorage()->read()->userfullname), 'emp_profileimg' => $auth->getStorage()->read()->profileimg, 'createdby' => $loginUserId, 'modifiedby' => $loginUserId, 'comments' => trim($request_comments), 'isactive' => 1, 'createddate' => gmdate("Y-m-d H:i:s"), 'modifieddate' => gmdate("Y-m-d H:i:s"));
                             if ($sd_result == 'update') {
                                 $reqh_model->SaveorUpdateRhistory($reqh_data, '');
                                 //end of saving history
                                 //$this->send_req_mails($id);
                                 $req_msg['success'] = "Executor assigned to service request successfully.";
                             } else {
                                 $req_msg['error'] = "Some thing went wrong, please try again.";
                             }
                             $result = sapp_Global::logManager(SERVICEDESK, 2, $loginUserId, $id);
                             $trDb->commit();
                             $this->_helper->getHelper("FlashMessenger")->addMessage(array($req_msg));
                             $this->_redirect('servicerequests/index/t/' . sapp_Global::_encrypt($grid_type) . ($status_value != '' ? "/v/" . $status_value : ""));
                         } catch (Exception $ex) {
                             $trDb->rollBack();
                             $msgarray['executor_comments'] = "Something went wrong, please try again.";
                         }
                     }
                 } else {
                     $this->view->ermsg = 'norecord';
                 }
             } else {
                 $this->view->ermsg = 'norecord';
             }
         } else {
             $this->view->ermsg = 'norecord';
         }
     } catch (Exception $e) {
         $this->view->ermsg = 'nodata';
     }
     $this->view->action_name = $this->getRequest()->getActionName();
 }
 public function send_req_mails1($id)
 {
     $sd_req_model = new Default_Model_Servicerequests();
     $summary_data = $sd_req_model->getDataSummary($id);
     $cc_req_ids = $sd_req_model->getCC_mails($summary_data['service_desk_conf_id']);
     if ($summary_data['status'] == 'Open') {
         $total_ids = array($cc_req_ids['request_recievers'], $cc_req_ids['cc_mail_recievers'], $summary_data['createdby']);
     } else {
         if ($summary_data['status'] == 'Closed') {
             $total_ids = array($summary_data['executor_id'], $cc_req_ids['cc_mail_recievers'], $summary_data['createdby']);
         } else {
             if ($summary_data['status'] == 'To manager approve') {
                 $total_ids = array($summary_data['executor_id'], $cc_req_ids['cc_mail_recievers'], $summary_data['reporting_manager_id']);
             } else {
                 if (in_array($summary_data['status'], array('To management approve', 'Management approved', 'Management rejected'))) {
                     $total_ids = array($summary_data['executor_id'], $cc_req_ids['cc_mail_recievers'], $summary_data['approver_1'], $summary_data['approver_2'], $summary_data['approver_3']);
                 } else {
                     if ($summary_data['status'] == 'Manager approved' || $summary_data['status'] == 'Manager rejected') {
                         $total_ids = array($summary_data['executor_id'], $cc_req_ids['cc_mail_recievers'], $summary_data['reporting_manager_id']);
                     }
                 }
             }
         }
     }
     $total_ids = array_filter($total_ids);
     $total_ids = implode(',', $total_ids);
     $email_ids = $sd_req_model->getEmailIds($total_ids);
     $req_receivers = explode(',', $cc_req_ids['request_recievers']);
     $cc = array();
     if ($cc_req_ids['cc_mail_recievers'] != '') {
         $cc = explode(',', $cc_req_ids['cc_mail_recievers']);
     }
     $req_receivers[] = $summary_data['createdby'];
     $status = $summary_data['status'];
     $disp_arr = array('Closed' => 'Closed', 'Rejected' => 'Closed');
     $display_status = !in_array($status, $disp_arr) ? "Open" : "Closed";
     if (count($req_receivers) > 0) {
         foreach ($req_receivers as $rec) {
             $base_url = 'http://' . $this->getRequest()->getHttpHost() . $this->getRequest()->getBaseUrl();
             $view = $this->getHelper('ViewRenderer')->view;
             $this->view->base_url = $base_url;
             $this->view->type = "receivers";
             $this->view->data = $summary_data;
             $text = $view->render('mailtemplates/sdrequest.phtml');
             $options['subject'] = "New Online request: Status - " . $display_status;
             $options['header'] = 'Online request';
             $options['toEmail'] = isset($email_ids[$rec]) ? $email_ids[$rec] : "";
             $options['toName'] = '';
             $options['message'] = $text;
             $options['cron'] = 'yes';
             if ($options['toEmail'] != '') {
                 sapp_Global::_sendEmail($options);
             }
         }
     }
     if (count($cc) > 0) {
         foreach ($cc as $rec) {
             $base_url = 'http://' . $this->getRequest()->getHttpHost() . $this->getRequest()->getBaseUrl();
             $view = $this->getHelper('ViewRenderer')->view;
             $this->view->base_url = $base_url;
             $this->view->type = "receivers";
             $this->view->data = $summary_data;
             $text = $view->render('mailtemplates/sdrequest.phtml');
             $options['subject'] = "New Online request: Status - Open";
             $options['header'] = 'Online request';
             $options['toEmail'] = $email_ids[$rec];
             $options['toName'] = '';
             $options['message'] = $text;
             $options['cron'] = 'yes';
             if ($options['toEmail'] != '') {
                 sapp_Global::_sendEmail($options);
             }
         }
     }
 }