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 .= ' Account:'. $upworkAccount .'
'; $rit .= '

'; $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 .= ' '; $ret .= ' '; $ret .= ' '; $ret .= ' '; $ret .= ' '; $ret .= ' '; $ret .= ' '; $ret .= ' '; $ret .= ' '; if ( isset($taskLists) && is_array($taskLists) ) { $grandTotalTime = 0; foreach ($taskLists as $taskList) { $ret .= ''; $ret .= ' '; $ret .= ''; $totalTaskTime = 0; foreach ($taskList['DETAIL'] as $task) { $time = intval($task['TIME']); $totalTaskTime += $time; $mins = $time/60; $sec = $time%60; $hr = floor($mins/60); $hrDec = round($mins/60,2); $min = $mins%60; $exeTime = $hr.':'.str_pad($min, 2, "0", STR_PAD_LEFT); $ret .= ''; $ret .= ' '; $ret .= ' '; $ret .= ' '; $ret .= ' '; $ret .= ''; } $mins = floor($totalTaskTime/60); $sec = $time%60; $hr = floor($mins/60); $min = $mins%60; $taskExeTime = $hr.':'.str_pad($min, 2, "0", STR_PAD_LEFT); $grandTotalTime += $totalTaskTime; $ret .= ''; $ret .= ' '; $ret .= ''; $ret .= ''; $ret .= ' '; $ret .= ''; } $mins = round($grandTotalTime/60,2); $sec = $time%60; $hr = floor($mins/60); $min = $mins%60; $grandExeTime = $hr.':'.str_pad($min, 2, "0", STR_PAD_LEFT); $ret .= ''; $ret .= ' '; $ret .= ' '; $ret .= ' '; $ret .= ''; } $ret .= '
TaskHoursMinutesDecimal
'; $ret .= ' '; $ret .= ' '. $taskList['DATE'] .''; $ret .= ' '; $ret .= '
'. $task['NAME'] .''. str_pad($hr, 2, "0", STR_PAD_LEFT) .''. str_pad($min, 2, "0", STR_PAD_LEFT) .''. number_format($hrDec,2,'.','') .'
Total Time: '. $taskExeTime .' Hours

Grand Total Time: '.$grandExeTime .' Hours

'; return $rit.$ret; } private function composeEmailMessageFromTemplate($id,$data,$template) { extract($data); $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']; } } } $upworkLink = 'Click Here'; $upworkContractLink = ''. $contractSubject .''; //////////// $ret = ""; $ret .= ' '; $ret .= ' '; $ret .= ' '; $ret .= ' '; $ret .= ' '; $ret .= ' '; $ret .= ' '; $ret .= ' '; $ret .= ' '; if ( isset($taskLists) && is_array($taskLists) ) { $grandTotalTime = 0; foreach ($taskLists as $taskList) { $ret .= ''; $ret .= ' '; $ret .= ''; $totalTaskTime = 0; foreach ($taskList['DETAIL'] as $task) { $time = intval($task['TIME']); $totalTaskTime += $time; $mins = $time/60; $sec = $time%60; $hr = floor($mins/60); $hrDec = round($mins/60,2); $min = $mins%60; $exeTime = $hr.':'.str_pad($min, 2, "0", STR_PAD_LEFT); $ret .= ''; $ret .= ' '; $ret .= ' '; $ret .= ' '; $ret .= ' '; $ret .= ''; } $mins = floor($totalTaskTime/60); $sec = $time%60; $hr = floor($mins/60); $min = $mins%60; $taskExeTime = $hr.':'.str_pad($min, 2, "0", STR_PAD_LEFT); $grandTotalTime += $totalTaskTime; $ret .= ''; $ret .= ' '; $ret .= ''; $ret .= ''; $ret .= ' '; $ret .= ''; } $mins = round($grandTotalTime/60,2); $sec = $time%60; $hr = floor($mins/60); $min = $mins%60; $grandExeTime = $hr.':'.str_pad($min, 2, "0", STR_PAD_LEFT); $ret .= ''; $ret .= ' '; $ret .= ' '; $ret .= ' '; $ret .= ''; } $ret .= '
TaskHoursMinutesDecimal
'; $ret .= ' '; $ret .= ' '. $taskList['DATE'] .''; $ret .= ' '; $ret .= '
'. $task['NAME'] .''. str_pad($hr, 2, "0", STR_PAD_LEFT) .''. str_pad($min, 2, "0", STR_PAD_LEFT) .''. number_format($hrDec,2,'.','') .'
Total Time: '. $taskExeTime .' Hours

Grand Total Time: '.$grandExeTime .' Hours

'; /////// $message = $template->message; $subject = $template->subject; $project_name = $projectName; $upwork_link = $upworkLink; $upwork_account = $upworkAccount; $upwork_contract_link = $upworkContractLink; $report_body = $ret; $signature = "TEAM"; $date = date("m/d/Y"); $keys = array("{project_name}", "{upwork_link}", "{upwork_account}", "{upwork_contract_link}", "{report_body}", "{signature}", "{date}"); $values = array( $project_name, $upwork_link, $upwork_account, $upwork_contract_link, $report_body, $signature, $date); $formated_message = str_replace($keys, $values, $message); $formated_subject = str_replace($keys, $values, $subject); return array("message"=>$formated_message,"subject"=>$formated_subject, "from_name"=>$template->fromname, "from_email"=>fromemail); } }