363 lines
12 KiB
PHP
363 lines
12 KiB
PHP
<?php
|
|
|
|
class Project_notifications_module
|
|
{
|
|
private $ci;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->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 '<pre>'; 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 '<pre>'; 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 => <br>".$messageData['subject'];
|
|
$templates["log"][] = "MESSAGE => <br>".$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("<h1>LOG</h1>".implode("<br><br>",$templates["log"]));
|
|
//$this->ci->email->send();
|
|
|
|
//echo '<pre>'; print_r($templates["log"]); echo '</pre>'; die();
|
|
}
|
|
|
|
private function composeEmailMessage($data)
|
|
{
|
|
extract($data);
|
|
$rit = "";
|
|
$rit .= ' <p>Hello. Below you can find an updated log for the time recorded on the <b>'. $projectName .'</b> project. Please make sure the Upwork contract is synced accordingly.</p>';
|
|
$rit .= ' <p>These hours need to be logged into Upwork. Here are his log in details.</p>';
|
|
|
|
$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 .= ' <p>';
|
|
$rit .= ' <b>URL:</b> <a href="https://www.upwork.com">Click Here</a><br />';
|
|
$rit .= ' <b>Account:</b>'. $upworkAccount .'<br />';
|
|
$rit .= ' </p>';
|
|
|
|
$rit .= ' <p>Simply visit the contract named <a href="http://www.upwork.com/ab/workdiary/freelancer/#/'. $upworkContractId. '">'. $contractSubject .'</a> in Upwork then record the hours listed below. Make sure the total hours match (or exceed) the hours from our portal.</p>';
|
|
|
|
////////////
|
|
$ret = "";
|
|
$ret .= ' <table width="75%" cellpadding="5" align="center" style="margin-top: 10px;">';
|
|
|
|
$ret .= ' <thead>';
|
|
$ret .= ' <tr>';
|
|
$ret .= ' <th bgcolor="#000000"><font color="#FFFFFF">Task</font></th>';
|
|
$ret .= ' <th bgcolor="#000000"><font color="#FFFFFF">Hours</font></th>';
|
|
$ret .= ' <th bgcolor="#000000"><font color="#FFFFFF">Minutes</font></th>';
|
|
$ret .= ' <th bgcolor="#000000"><font color="#FFFFFF">Decimal</font></th>';
|
|
$ret .= ' </tr>';
|
|
$ret .= ' </thead>';
|
|
|
|
if ( isset($taskLists) && is_array($taskLists) )
|
|
{
|
|
$grandTotalTime = 0;
|
|
foreach ($taskLists as $taskList)
|
|
{
|
|
|
|
$ret .= '<tr>';
|
|
$ret .= ' <td bgcolor="#ffd700" colspan="4" align="center">';
|
|
$ret .= ' <font color="#000000">';
|
|
$ret .= ' <b>'. $taskList['DATE'] .'</b>';
|
|
$ret .= ' </font>';
|
|
$ret .= ' </td>';
|
|
$ret .= '</tr>';
|
|
|
|
$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 .= '<tr>';
|
|
$ret .= ' <td bgcolor="#808080"><font color="#FFFFFF">'. $task['NAME'] .'</font></td>';
|
|
$ret .= ' <td bgcolor="#808080"><font color="#FFFFFF">'. str_pad($hr, 2, "0", STR_PAD_LEFT) .'</font></td>';
|
|
$ret .= ' <td bgcolor="#808080"><font color="#FFFFFF">'. str_pad($min, 2, "0", STR_PAD_LEFT) .'</font></td>';
|
|
$ret .= ' <td bgcolor="#808080"><font color="#FFFFFF">'. number_format($hrDec,2,'.','') .'</font></td>';
|
|
$ret .= '</tr>';
|
|
}
|
|
|
|
$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 .= '<tr>';
|
|
$ret .= ' <td bgcolor="#ffd700" colspan="4" align="center"><font color="#000000"><b>Total Time: '. $taskExeTime .' Hours</b></font></td>';
|
|
$ret .= '</tr>';
|
|
|
|
$ret .= '<tr>';
|
|
$ret .= ' <td bgcolor="#000000" colspan="4" align="center" style="height: 5px;"></td>';
|
|
$ret .= '</tr>';
|
|
}
|
|
|
|
$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 .= '<tfoot style="padding-top: -5px;">';
|
|
$ret .= ' <tr>';
|
|
$ret .= ' <td bgcolor="#000000" colspan="4" align="center" valign="middle"><font color="#FFFFFF"><h1>Grand Total Time: '.$grandExeTime .' Hours</h1></font></td>';
|
|
$ret .= ' </tr>';
|
|
$ret .= '</tfoot>';
|
|
}
|
|
|
|
$ret .= ' </table> ';
|
|
|
|
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 = '<a href="https://www.upwork.com">Click Here</a>';
|
|
$upworkContractLink = '<a href="http://www.upwork.com/ab/workdiary/freelancer/#/'. $upworkContractId. '">'. $contractSubject .'</a>';
|
|
|
|
////////////
|
|
$ret = "";
|
|
$ret .= ' <table width="75%" cellpadding="5" align="center" style="margin-top: 10px;">';
|
|
|
|
$ret .= ' <thead>';
|
|
$ret .= ' <tr>';
|
|
$ret .= ' <th bgcolor="#000000"><font color="#FFFFFF">Task</font></th>';
|
|
$ret .= ' <th bgcolor="#000000"><font color="#FFFFFF">Hours</font></th>';
|
|
$ret .= ' <th bgcolor="#000000"><font color="#FFFFFF">Minutes</font></th>';
|
|
$ret .= ' <th bgcolor="#000000"><font color="#FFFFFF">Decimal</font></th>';
|
|
$ret .= ' </tr>';
|
|
$ret .= ' </thead>';
|
|
|
|
if ( isset($taskLists) && is_array($taskLists) )
|
|
{
|
|
$grandTotalTime = 0;
|
|
foreach ($taskLists as $taskList)
|
|
{
|
|
|
|
$ret .= '<tr>';
|
|
$ret .= ' <td bgcolor="#ffd700" colspan="4" align="center">';
|
|
$ret .= ' <font color="#000000">';
|
|
$ret .= ' <b>'. $taskList['DATE'] .'</b>';
|
|
$ret .= ' </font>';
|
|
$ret .= ' </td>';
|
|
$ret .= '</tr>';
|
|
|
|
$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 .= '<tr>';
|
|
$ret .= ' <td bgcolor="#808080"><font color="#FFFFFF">'. $task['NAME'] .'</font></td>';
|
|
$ret .= ' <td bgcolor="#808080"><font color="#FFFFFF">'. str_pad($hr, 2, "0", STR_PAD_LEFT) .'</font></td>';
|
|
$ret .= ' <td bgcolor="#808080"><font color="#FFFFFF">'. str_pad($min, 2, "0", STR_PAD_LEFT) .'</font></td>';
|
|
$ret .= ' <td bgcolor="#808080"><font color="#FFFFFF">'. number_format($hrDec,2,'.','') .'</font></td>';
|
|
$ret .= '</tr>';
|
|
}
|
|
|
|
$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 .= '<tr>';
|
|
$ret .= ' <td bgcolor="#ffd700" colspan="4" align="center"><font color="#000000"><b>Total Time: '. $taskExeTime .' Hours</b></font></td>';
|
|
$ret .= '</tr>';
|
|
|
|
$ret .= '<tr>';
|
|
$ret .= ' <td bgcolor="#000000" colspan="4" align="center" style="height: 5px;"></td>';
|
|
$ret .= '</tr>';
|
|
}
|
|
|
|
$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 .= '<tfoot style="padding-top: -5px;">';
|
|
$ret .= ' <tr>';
|
|
$ret .= ' <td bgcolor="#000000" colspan="4" align="center" valign="middle"><font color="#FFFFFF"><h1>Grand Total Time: '.$grandExeTime .' Hours</h1></font></td>';
|
|
$ret .= ' </tr>';
|
|
$ret .= '</tfoot>';
|
|
}
|
|
|
|
$ret .= ' </table> ';
|
|
///////
|
|
|
|
|
|
|
|
$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);
|
|
}
|
|
}
|