ci =& get_instance(); } public function executeNotification($id = "") { $this->ci->load->model('project_notifications/project_notifications_model'); $this->ci->load->model('project_notifications/project_notifications_email_templates_model'); $this->ci->load->config('email'); $templates = $this->ci->project_notifications_model->projectNotificationExecution($id); $execRecord = array(); foreach($templates["data"] as $template) { if($template['EMAIL_TEMPL_ID']!=='' && is_numeric($template['EMAIL_TEMPL_ID'])) { //echo '
'; print_r($this->ci->project_notifications_email_templates_model->get($template['EMAIL_TEMPL_ID'])); die(); $emailtemplate = $this->ci->project_notifications_email_templates_model->get($template['EMAIL_TEMPL_ID']); //echo ''; print_r($emailtemplate); die(); $messageData = $this->composeEmailMessageFromTemplate($template['EMAIL_TEMPL_ID'], $template['MESSAGE-DATA'], $emailtemplate); $this->ci->email->clear(true); if(trim($messageData['from_email'])!=='') { $this->ci->email->from($messageData['from_name'],$messageData['from_email']); } else { $this->ci->email->from($template['FROM_EMAIL'],$template['FROM_NAME']); } $this->ci->email->to($template['TO']); $this->ci->email->subject($messageData['subject']); $this->ci->email->message($messageData['message']); $templates["log"][] = "TO => ".$template['TO']; $templates["log"][] = "SUBJECT =>
".$messageData['subject']; $templates["log"][] = "MESSAGE =>
".$messageData['message']; if ($this->ci->email->send()) { log_activity('Email Sent To [Email: ' . $template['TO'] . ', Template: Project Notification]'); $execRecord[$template['NOTIFY_ID']]['NOTIFY_ID'] = $template['NOTIFY_ID']; $execRecord[$template['NOTIFY_ID']]['TIME'] = date("Y-m-d H:i:s"); } } else { //$message = $this->ci->load->view("email_templates/email", $template['MESSAGE-DATA'], TRUE); $message = $this->composeEmailMessage($template['MESSAGE-DATA']); $this->ci->email->clear(true); $this->ci->email->from($template['FROM_EMAIL'],$template['FROM_NAME']); $this->ci->email->to($template['TO']); $this->ci->email->subject($template['SUBJECT']); //$this->ci->email->message($template['MESSAGE']); $this->ci->email->message($message); $templates["log"][] = "TO => ".$template['TO']; if ($this->ci->email->send()) { log_activity('Email Sent To [Email: ' . $template['TO'] . ', Template: Project Notification]'); $execRecord[$template['NOTIFY_ID']]['NOTIFY_ID'] = $template['NOTIFY_ID']; $execRecord[$template['NOTIFY_ID']]['TIME'] = date("Y-m-d H:i:s"); } } } foreach($execRecord as $record) { $this->ci->db->insert(db_prefix() . 'project_notifications_log', [ 'notify_id' => $record['NOTIFY_ID'], 'triggertime' => $record['TIME'] ]); } $templates["log"][] = json_encode($execRecord); $this->ci->email->clear(true); $this->ci->email->from(get_option('smtp_email'),get_option('companyname')); $this->ci->email->to("soumya@sentientgeeks.com"); $this->ci->email->subject("BROMANAGERS LOG : ".date("Y-m-d H:i:s")); $this->ci->email->message("LOG
".implode("
",$templates["log"])); //$this->ci->email->send(); //echo ''; print_r($templates["log"]); echo ''; die(); } private function composeEmailMessage($data) { extract($data); $rit = ""; $rit .= 'Hello. Below you can find an updated log for the time recorded on the '. $projectName .' project. Please make sure the Upwork contract is synced accordingly.
'; $rit .= 'These hours need to be logged into Upwork. Here are his log in details.
'; $upworkAccount = NULL; $upworkContractId = NULL; if ((isset($contractCustomFields)) && (!empty($contractCustomFields)) && (is_array($contractCustomFields))) { foreach ($contractCustomFields as $contractCustomField) { if ($contractCustomField['slug'] == "contracts_upwork_account") { $upworkAccount = $contractCustomField['value']; } elseif ($contractCustomField['slug'] == "contracts_upwork_contract_id") { $upworkContractId = $contractCustomField['value']; } } } $rit .= ''; $rit .= ' URL: Click Here
'; $rit .= '
'; $rit .= ' Account:'. $upworkAccount .'
'; $rit .= 'Simply visit the contract named '. $contractSubject .' in Upwork then record the hours listed below. Make sure the total hours match (or exceed) the hours from our portal.
'; //////////// $ret = ""; $ret .= '
Task | '; $ret .= 'Hours | '; $ret .= 'Minutes | '; $ret .= 'Decimal | '; $ret .= '
---|---|---|---|
'; $ret .= ' '; $ret .= ' '. $taskList['DATE'] .''; $ret .= ' '; $ret .= ' | '; $ret .= '|||
'. $task['NAME'] .' | '; $ret .= ''. str_pad($hr, 2, "0", STR_PAD_LEFT) .' | '; $ret .= ''. str_pad($min, 2, "0", STR_PAD_LEFT) .' | '; $ret .= ''. number_format($hrDec,2,'.','') .' | '; $ret .= '
Total Time: '. $taskExeTime .' Hours | '; $ret .= '|||
'; $ret .= ' | |||
Grand Total Time: '.$grandExeTime .' Hours | ';
$ret .= '
Task | '; $ret .= 'Hours | '; $ret .= 'Minutes | '; $ret .= 'Decimal | '; $ret .= '
---|---|---|---|
'; $ret .= ' '; $ret .= ' '. $taskList['DATE'] .''; $ret .= ' '; $ret .= ' | '; $ret .= '|||
'. $task['NAME'] .' | '; $ret .= ''. str_pad($hr, 2, "0", STR_PAD_LEFT) .' | '; $ret .= ''. str_pad($min, 2, "0", STR_PAD_LEFT) .' | '; $ret .= ''. number_format($hrDec,2,'.','') .' | '; $ret .= '
Total Time: '. $taskExeTime .' Hours | '; $ret .= '|||
'; $ret .= ' | |||
Grand Total Time: '.$grandExeTime .' Hours | ';
$ret .= '