initial Commit
This commit is contained in:
commit
1bf7fbee0e
176
controllers/Project_notifications.php
Normal file
176
controllers/Project_notifications.php
Normal file
@ -0,0 +1,176 @@
|
|||||||
|
<?php
|
||||||
|
defined('BASEPATH') or exit('No direct script access allowed');
|
||||||
|
|
||||||
|
class Project_notifications extends AdminController
|
||||||
|
{
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
|
||||||
|
$this->load->model('project_notifications_model');
|
||||||
|
$this->load->model('project_notifications_email_templates_model');
|
||||||
|
$this->load->model('contract_types_model');
|
||||||
|
$this->load->model('projects_model');
|
||||||
|
$this->load->helper('url');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
close_setup_menu();
|
||||||
|
|
||||||
|
if (!has_permission('project_notifications', '', 'view')) {
|
||||||
|
access_denied('project_notifications');
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->input->is_ajax_request()) {
|
||||||
|
$this->app->get_table_data(module_views_path('project_notifications', 'tables/list'));
|
||||||
|
}
|
||||||
|
|
||||||
|
$data['title'] = _l('pn_title');
|
||||||
|
|
||||||
|
$this->load->view('project_notifications', $data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function configure($id="")
|
||||||
|
{
|
||||||
|
if (!has_permission('project_notifications', '', 'view')) {
|
||||||
|
access_denied('project_notifications');
|
||||||
|
}
|
||||||
|
|
||||||
|
$data['contractTypes'] = $this->contract_types_model->get();
|
||||||
|
$data['projectData'] = $this->project_notifications_model->getProjectDataForConfigurations();
|
||||||
|
$data['pan'] = $this->project_notifications_model->get($id);
|
||||||
|
$data['id'] = $id;
|
||||||
|
$data['title'] = _l('pn_configure_title');
|
||||||
|
$data['templates'] = $this->project_notifications_email_templates_model->get();
|
||||||
|
|
||||||
|
$this->load->view('configure', $data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function configuration($id="")
|
||||||
|
{
|
||||||
|
if (trim($id)!=='') {
|
||||||
|
|
||||||
|
if (!has_permission('project_notifications', '', 'edit')) {
|
||||||
|
access_denied('project_notifications');
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
if (!has_permission('project_notifications', '', 'add')) {
|
||||||
|
access_denied('project_notifications');
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->input->post()) {
|
||||||
|
|
||||||
|
$post = $this->input->post();
|
||||||
|
|
||||||
|
$data['triggertime'] = $post['triggertime'];
|
||||||
|
$data['triggerday'] = $post['triggerday'];
|
||||||
|
$data['emails'] = $post['emails'];
|
||||||
|
$data['choice_type'] = $post['choice_type'];
|
||||||
|
$data['contract_type'] = $post['contract_type'];
|
||||||
|
$data['projects'] = $post['projects'];
|
||||||
|
$data['dataset'] = (isset($post['prev_week']) && $post['prev_week']=='Y')?'PREV-WEEK':'SO-FAR';
|
||||||
|
$data['info_to_send'] = '';
|
||||||
|
$data['email_template'] = $post['email_template'];
|
||||||
|
|
||||||
|
if (trim($id)!=='') {
|
||||||
|
$data['id'] = $id;
|
||||||
|
}
|
||||||
|
|
||||||
|
$success = $this->project_notifications_model->upsert($data);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
redirect('project_notifications');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function delete($id)
|
||||||
|
{
|
||||||
|
$success = $this->project_notifications_model->delete($id);
|
||||||
|
|
||||||
|
redirect('project_notifications');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function execute($id)
|
||||||
|
{
|
||||||
|
execute_project_notification($id);
|
||||||
|
redirect('project_notifications');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function email_templates()
|
||||||
|
{
|
||||||
|
close_setup_menu();
|
||||||
|
|
||||||
|
if (!has_permission('project_notifications', '', 'view')) {
|
||||||
|
access_denied('project_notifications');
|
||||||
|
}
|
||||||
|
|
||||||
|
$data['title'] = _l('pn_email_template_title');
|
||||||
|
$data['tickets'] = $this->project_notifications_email_templates_model->get();
|
||||||
|
|
||||||
|
$this->load->view('email_templates', $data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function email_template($id="")
|
||||||
|
{
|
||||||
|
close_setup_menu();
|
||||||
|
|
||||||
|
if (!has_permission('project_notifications', '', 'view')) {
|
||||||
|
access_denied('project_notifications');
|
||||||
|
}
|
||||||
|
|
||||||
|
$data['template'] = $this->project_notifications_email_templates_model->get($id);
|
||||||
|
$data['title'] = $data['template']->name;
|
||||||
|
$data['id'] = $id;
|
||||||
|
$data['available_merge_fields'] = $this->project_notifications_email_templates_model->available_merge_fields();
|
||||||
|
|
||||||
|
$this->load->view('template', $data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function upsertemailtemplate($id="")
|
||||||
|
{
|
||||||
|
if (trim($id)!=='') {
|
||||||
|
if (!has_permission('project_notifications', '', 'edit')) {
|
||||||
|
access_denied('project_notifications');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (!has_permission('project_notifications', '', 'add')) {
|
||||||
|
access_denied('project_notifications');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->input->post()) {
|
||||||
|
$post = $this->input->post();
|
||||||
|
|
||||||
|
$data['type'] = $post['type'];
|
||||||
|
$data['slug'] = $post['slug'];
|
||||||
|
$data['language'] = $post['language'];
|
||||||
|
$data['name'] = $post['name'];
|
||||||
|
$data['subject'] = $post['subject'];
|
||||||
|
$data['message'] = $post['message'];
|
||||||
|
$data['fromname'] = $post['fromname'];
|
||||||
|
$data['fromemail'] = $post['fromemail'];
|
||||||
|
$data['plaintext'] = $post['plaintext'];
|
||||||
|
$data['active'] = $post['active'];
|
||||||
|
$data['order'] = $post['order'];
|
||||||
|
|
||||||
|
if (trim($id)!=='') {
|
||||||
|
$data['id'] = $id;
|
||||||
|
}
|
||||||
|
|
||||||
|
$success = $this->project_notifications_email_templates_model->upsert($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
redirect('project_notifications/email_templates');
|
||||||
|
}
|
||||||
|
|
||||||
|
// proivate utilities
|
||||||
|
|
||||||
|
// This should not be in the controller and we should be using CI Active Record.
|
||||||
|
// moved to model
|
||||||
|
|
||||||
|
}
|
11
controllers/index.html
Normal file
11
controllers/index.html
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>403 Forbidden</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<p>Directory access is forbidden.</p>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
362
libraries/Project_notifications_module.php
Normal file
362
libraries/Project_notifications_module.php
Normal file
@ -0,0 +1,362 @@
|
|||||||
|
<?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);
|
||||||
|
}
|
||||||
|
}
|
352
models/Project_notifications_model.php
Normal file
352
models/Project_notifications_model.php
Normal file
@ -0,0 +1,352 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
defined('BASEPATH') or exit('No direct script access allowed');
|
||||||
|
|
||||||
|
class Project_notifications_model extends App_Model
|
||||||
|
{
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get($id = '',$returnArray=false)
|
||||||
|
{
|
||||||
|
if (is_numeric($id)) {
|
||||||
|
$this->db->where('id', $id);
|
||||||
|
if($returnArray===true)
|
||||||
|
{
|
||||||
|
return $this->db->get(db_prefix() . 'project_notifications')->result_array();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return $this->db->get(db_prefix() . 'project_notifications')->row();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->db->get(db_prefix() . 'project_notifications')->result_array();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function upsert($data)
|
||||||
|
{
|
||||||
|
if (isset($data['id']) && trim($data['id']) !== '' && is_numeric($data['id'])) {
|
||||||
|
|
||||||
|
$this->db->where('id', $data['id']);
|
||||||
|
$this->db->update(db_prefix() . 'project_notifications', [
|
||||||
|
'triggertime' => $data['triggertime'],
|
||||||
|
'triggerday' => $data['triggerday'],
|
||||||
|
'emails' => $data['emails'],
|
||||||
|
'choice_type' => $data['choice_type'],
|
||||||
|
'contract_type' => $data['contract_type'],
|
||||||
|
'projects' => $data['projects'],
|
||||||
|
'dataset' => $data['dataset'],
|
||||||
|
'info_to_send' => $data['info_to_send'],
|
||||||
|
'email_template' => $data['email_template']
|
||||||
|
]);
|
||||||
|
|
||||||
|
if ($this->db->affected_rows() > 0) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
$this->db->insert(db_prefix() . 'project_notifications', [
|
||||||
|
'triggertime' => $data['triggertime'],
|
||||||
|
'triggerday' => $data['triggerday'],
|
||||||
|
'emails' => $data['emails'],
|
||||||
|
'choice_type' => $data['choice_type'],
|
||||||
|
'contract_type' => $data['contract_type'],
|
||||||
|
'projects' => $data['projects'],
|
||||||
|
'dataset' => $data['dataset'],
|
||||||
|
'info_to_send' => $data['info_to_send'],
|
||||||
|
'email_template' => $data['email_template']
|
||||||
|
]);
|
||||||
|
|
||||||
|
$insert_id = $this->db->insert_id();
|
||||||
|
|
||||||
|
if ($insert_id) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function delete($id)
|
||||||
|
{
|
||||||
|
$this->db->where('id', $id);
|
||||||
|
$this->db->delete(db_prefix().'project_notifications');
|
||||||
|
|
||||||
|
if ($this->db->affected_rows() > 0) {
|
||||||
|
|
||||||
|
log_activity('Project Activity Configuration Deleted [ID: ' . $id . ']'); // What is suerveyId?
|
||||||
|
return true;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function getProjectDataForConfigurations()
|
||||||
|
{
|
||||||
|
$this->db->select( db_prefix() . "projects.*, " . db_prefix() . "contracts_types.id AS contract_type_id", FALSE);
|
||||||
|
$this->db->from( db_prefix() . "projects");
|
||||||
|
$this->db->join(db_prefix() . "contracts ", db_prefix() . "projects.id = " . db_prefix() . "contracts.project_id",'left');
|
||||||
|
$this->db->join(db_prefix() . "contracts_types ", db_prefix() . "contracts_types.id = " . db_prefix() . "contracts.contract_type",'left');
|
||||||
|
$this->db->order_by( db_prefix() . "projects.name", "asc");
|
||||||
|
|
||||||
|
$data = $this->db->get()->result_array();
|
||||||
|
|
||||||
|
$ret = array();
|
||||||
|
foreach($data as $d)
|
||||||
|
{
|
||||||
|
$cId = ($d['contract_type_id']=='')?0:$d['contract_type_id'];
|
||||||
|
$ret[$cId][] = $d;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function projectNotificationExecution($id = "")
|
||||||
|
{
|
||||||
|
$emailTemplates = array();
|
||||||
|
|
||||||
|
$log = array();
|
||||||
|
|
||||||
|
if($id!=='')
|
||||||
|
{
|
||||||
|
$notifications = $this->get($id, true);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$notifications = $this->get();
|
||||||
|
}
|
||||||
|
|
||||||
|
$log[] = "size(notifications) => ".sizeof($notifications);
|
||||||
|
|
||||||
|
$templateCounter = 0;
|
||||||
|
|
||||||
|
foreach ($notifications as $notification)
|
||||||
|
{
|
||||||
|
$execTime = date("U", strtotime(date("Y-m-d").' '.$notification['triggertime'].':00'));
|
||||||
|
|
||||||
|
$log[] = "id => ".$id;
|
||||||
|
$log[] = "triggertime => ".date("Y-m-d").' '.$notification['triggertime'].':00';
|
||||||
|
$log[] = "now => ".date("Y-m-d H:i:s");
|
||||||
|
$log[] = "execTime => ".$execTime;
|
||||||
|
|
||||||
|
$this->db->select();
|
||||||
|
$this->db->from(db_prefix() . "project_notifications_log");
|
||||||
|
$this->db->where("notify_id", $notification['id']);
|
||||||
|
$this->db->order_by(db_prefix()."project_notifications_log.id", "desc");
|
||||||
|
$this->db->limit(1);
|
||||||
|
|
||||||
|
$dataLog = $this->db->get()->row();
|
||||||
|
|
||||||
|
$log[] = "dataLog => ".json_encode((array)$dataLog);
|
||||||
|
|
||||||
|
$lastTrigger = date('2000-01-01 00:00:00');
|
||||||
|
if(isset($dataLog) && $dataLog->triggertime !=='')
|
||||||
|
{
|
||||||
|
$lastTrigger = $dataLog->triggertime;
|
||||||
|
}
|
||||||
|
|
||||||
|
$log[] = "lastTrigger => ".$lastTrigger;
|
||||||
|
|
||||||
|
$checktoRun = false;
|
||||||
|
|
||||||
|
if( strtoupper($notification['triggerday']) === strtoupper(date('D')) || strtoupper($notification['triggerday']) === 'EVERYDAY' )
|
||||||
|
{
|
||||||
|
$checktoRun = true;
|
||||||
|
$log[] = "check 1 (triggerday==today) => (strtoupper(".$notification['triggerday'].") === strtoupper(".date('D')."))";
|
||||||
|
$log[] = "check 2 (triggerday==EVERYDAY) => (strtoupper(".$notification['triggerday'].") === EVERYDAY )";
|
||||||
|
}
|
||||||
|
|
||||||
|
if($checktoRun === true && intval($execTime) <= intval(date("U", strtotime(date("Y-m-d H:i:s") ) ) ) )
|
||||||
|
{
|
||||||
|
$checktoRun = true;
|
||||||
|
$log[] = "check 3 (execTime<=NOW) => intval(".$execTime.") <= intval(".date("U", strtotime(date("Y-m-d H:i:s") ) )." )";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$checktoRun = false;
|
||||||
|
$log[] = "check 3 (execTime<=NOW) => intval(".$execTime.") <= intval(".date("U", strtotime(date("Y-m-d H:i:s") ) )." ) -- FAILS";
|
||||||
|
}
|
||||||
|
|
||||||
|
if($checktoRun === true && intval(date("U", strtotime($lastTrigger))) < intval($execTime))
|
||||||
|
{
|
||||||
|
$checktoRun = true;
|
||||||
|
$log[] = "check 4 (lastTrigger < execTime) => intval(".date("U", strtotime($lastTrigger)).") < intval(".$execTime.") )";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$checktoRun = false;
|
||||||
|
$log[] = "check 4 (lastTrigger < execTime) => intval(".date("U", strtotime($lastTrigger)).") < intval(".$execTime.") ) -- FAILS";
|
||||||
|
}
|
||||||
|
|
||||||
|
if( $checktoRun === true || trim($id) !== "" )
|
||||||
|
{
|
||||||
|
$this->db->from(db_prefix() . "taskstimers");
|
||||||
|
$this->db->join(db_prefix() . "tasks ", db_prefix() . "tasks.id = " . db_prefix() . "taskstimers.task_id");
|
||||||
|
$this->db->where(db_prefix() . "tasks.rel_type","project");
|
||||||
|
$this->db->join(db_prefix() . "projects ", db_prefix() . "projects.id = " . db_prefix() . "tasks.rel_id");
|
||||||
|
|
||||||
|
if ($notification['choice_type'] == 'CONTRACT')
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
$this->db->select("IFNULL(project_id,-1)");
|
||||||
|
$this->db->from(db_prefix() . "contracts");
|
||||||
|
$this->db->where("contract_type", $notification['contract_type']);
|
||||||
|
|
||||||
|
$contract_sub_query = $this->db->get_compiled_select();
|
||||||
|
*/
|
||||||
|
|
||||||
|
$this->db->select(db_prefix() . "contracts.id as contractId");
|
||||||
|
$this->db->select(db_prefix() . "contracts.subject as contractSubject");
|
||||||
|
|
||||||
|
//$this->db->where(db_prefix() . "projects.id IN( $contract_sub_query )");
|
||||||
|
$this->db->join(db_prefix() . "contracts ", db_prefix() . "contracts.project_id = " . db_prefix() . "projects.id");
|
||||||
|
}
|
||||||
|
|
||||||
|
if($notification['choice_type']=='SPECIFIC')
|
||||||
|
{
|
||||||
|
$this->db->where(db_prefix() . "projects.id", $notification['projects']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(strtoupper(date('D'))=="MON")
|
||||||
|
{
|
||||||
|
$lastMonday = strtotime(date("Y-m-d 00:00:00"));
|
||||||
|
$previousMonday = strtotime("last monday", $lastMonday);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$lastMonday = strtotime("last monday");
|
||||||
|
$previousMonday = strtotime("last monday", $lastMonday);
|
||||||
|
}
|
||||||
|
|
||||||
|
if($notification['dataset']=='PREV-WEEK')
|
||||||
|
{
|
||||||
|
$this->db->where(db_prefix() . "taskstimers.start_time >= ", date('U', $previousMonday));
|
||||||
|
$this->db->where(db_prefix() . "taskstimers.end_time < ", date('U', $lastMonday));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$this->db->where(db_prefix() . "taskstimers.start_time >= ", date('U', $lastMonday));
|
||||||
|
}
|
||||||
|
|
||||||
|
//$this->db->group_by(db_prefix() . "projects.id");
|
||||||
|
//$this->db->select("SUM(".db_prefix() . "taskstimers.end_time-".db_prefix() . "taskstimers.start_time) AS exeTime, ".db_prefix() . "projects.name AS projectName");
|
||||||
|
|
||||||
|
$this->db->select(db_prefix() . "taskstimers.*,
|
||||||
|
(".db_prefix() . "taskstimers.end_time-".db_prefix() . "taskstimers.start_time) AS exeTime,
|
||||||
|
".db_prefix() . "tasks.name AS taskName,
|
||||||
|
".db_prefix() . "projects.name AS projectName,
|
||||||
|
".db_prefix() . "projects.id AS projectId");
|
||||||
|
|
||||||
|
$this->db->order_by( db_prefix() . "taskstimers.start_time", "asc");
|
||||||
|
|
||||||
|
$query = $this->db->get();
|
||||||
|
|
||||||
|
if ($query->num_rows() > 0) {
|
||||||
|
|
||||||
|
$sqldata = $query->result_array();
|
||||||
|
|
||||||
|
$log[] = "sqldata => ".json_encode($sqldata);
|
||||||
|
|
||||||
|
$recipientEmails = array();
|
||||||
|
|
||||||
|
$data = array();
|
||||||
|
|
||||||
|
$counter = 0;
|
||||||
|
foreach($sqldata as $record)
|
||||||
|
{
|
||||||
|
$data[$record["projectId"]]['NAME'] = $record["projectName"];
|
||||||
|
|
||||||
|
$date = date("Ymd", $record["start_time"] ) ;
|
||||||
|
|
||||||
|
$data[$record["projectId"]]['TASK'][$date]['DATE'] = date("m/d/Y", $record["start_time"] ) ;
|
||||||
|
$data[$record["projectId"]]['TASK'][$date]['DETAIL'][$counter]['NAME'] = $record["taskName"];
|
||||||
|
$data[$record["projectId"]]['TASK'][$date]['DETAIL'][$counter]['TIME'] = $record["exeTime"];
|
||||||
|
|
||||||
|
if ((isset($record["contractId"])) && (!empty($record["contractId"]))) {
|
||||||
|
|
||||||
|
$data[$record["projectId"]]['CONTRACTID'] = $record["contractId"];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((isset($record["contractSubject"])) && (!empty($record["contractSubject"]))) {
|
||||||
|
|
||||||
|
$data[$record["projectId"]]['CONTRACTSUBJECT'] = $record["contractSubject"];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*$time = $record['exeTime'];
|
||||||
|
|
||||||
|
$mins = floor($time/60);
|
||||||
|
$sec = $time%60;
|
||||||
|
|
||||||
|
$hr = floor($mins/60);
|
||||||
|
$min = $mins%60;
|
||||||
|
|
||||||
|
$exeTime = $hr.':'.str_pad($min, 2, "0", STR_PAD_LEFT).':'.str_pad($sec, 2, "0", STR_PAD_LEFT);
|
||||||
|
|
||||||
|
$data[$record["projectId"]]['TASK'][$date]['DETAIL'][$counter]['FORMAT_TIME'] = $exeTime; */
|
||||||
|
}
|
||||||
|
|
||||||
|
$recepients = explode(',',$notification['emails']);
|
||||||
|
|
||||||
|
foreach($recepients as $recepient)
|
||||||
|
{
|
||||||
|
$recipientEmails[] = $recepient;
|
||||||
|
foreach($data as $projectId => $projectData)
|
||||||
|
{
|
||||||
|
$emailTemplates[$templateCounter]['EMAIL_TEMPL_ID'] = $notification['email_template'];
|
||||||
|
$emailTemplates[$templateCounter]['NOTIFY_ID'] = $notification['id'];
|
||||||
|
$emailTemplates[$templateCounter]['TO'] = $recepient;
|
||||||
|
$emailTemplates[$templateCounter]['FROM_EMAIL'] = get_option('smtp_email');
|
||||||
|
$emailTemplates[$templateCounter]['FROM_NAME'] = get_option('companyname');
|
||||||
|
$emailTemplates[$templateCounter]['SUBJECT'] = "Time Log For ".$projectData['NAME']." Project As Of ".date("m/d/Y").". ";
|
||||||
|
|
||||||
|
$templateData['projectName'] = $projectData['NAME'];
|
||||||
|
$templateData['taskLists'] = $projectData['TASK'];
|
||||||
|
$templateData['upworkUserName'] = "Nothing";
|
||||||
|
$templateData['contractSubject'] = $projectData['CONTRACTSUBJECT'];
|
||||||
|
|
||||||
|
if ($notification['choice_type'] == 'CONTRACT') {
|
||||||
|
|
||||||
|
$this->db->select(db_prefix() . "customfields.name");
|
||||||
|
$this->db->select(db_prefix() . "customfields.slug");
|
||||||
|
$this->db->select(db_prefix() . "customfieldsvalues.value");
|
||||||
|
$this->db->from(db_prefix() . "customfieldsvalues");
|
||||||
|
$this->db->where(db_prefix() . "customfields.fieldto", 'contracts');
|
||||||
|
$this->db->where(db_prefix() . "customfieldsvalues.relid", $projectData['CONTRACTID']);
|
||||||
|
$this->db->join(db_prefix() . "customfields", db_prefix() . "customfieldsvalues.fieldid = ".db_prefix() . "customfields.id");
|
||||||
|
|
||||||
|
$get_contracts_custom_fields = $this->db->get();
|
||||||
|
|
||||||
|
if ($get_contracts_custom_fields->num_rows() > 0) {
|
||||||
|
|
||||||
|
$templateData['contractCustomFields'] = $get_contracts_custom_fields->result_array();
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
$templateData['contractCustomFields'] = FALSE;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$emailTemplates[$templateCounter]['MESSAGE-DATA'] = $templateData;
|
||||||
|
//$emailTemplates[$templateCounter]['MESSAGE'] = $this->load->view("email_templates/email", $templateData, TRUE);
|
||||||
|
$templateCounter++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return array("data"=>$emailTemplates,"log"=>$log);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
11
models/index.html
Normal file
11
models/index.html
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>403 Forbidden</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<p>Directory access is forbidden.</p>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
69
project_notifications.php
Normal file
69
project_notifications.php
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
<?php
|
||||||
|
defined('BASEPATH') or exit('No direct script access allowed');
|
||||||
|
|
||||||
|
/*
|
||||||
|
Module Name: Project Notifications
|
||||||
|
Description: This module will allow you to create automated notifications for projects that have had activity.
|
||||||
|
Version: 1.0.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
define('PROJECT_NOTIFICATIONS_MODULE_NAME', 'project_notifications');
|
||||||
|
|
||||||
|
hooks()->add_action('after_cron_run', 'execute_project_notification');
|
||||||
|
hooks()->add_action('admin_init', 'project_notifications_module_init_menu_items');
|
||||||
|
hooks()->add_action('admin_init', 'project_notifications_permissions');
|
||||||
|
|
||||||
|
function execute_project_notification($id = "")
|
||||||
|
{
|
||||||
|
$CI = &get_instance();
|
||||||
|
$CI->load->library(PROJECT_NOTIFICATIONS_MODULE_NAME . '/' . 'project_notifications_module');
|
||||||
|
$CI->project_notifications_module->executeNotification($id);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function project_notifications_permissions()
|
||||||
|
{
|
||||||
|
$capabilities = [];
|
||||||
|
|
||||||
|
$capabilities['capabilities'] = [
|
||||||
|
'view' => _l('permission_view') . '(' . _l('permission_global') . ')',
|
||||||
|
'create' => _l('permission_create'),
|
||||||
|
'create_template' => _l('permission_create'),
|
||||||
|
'edit' => _l('permission_edit'),
|
||||||
|
'delete' => _l('permission_delete'),
|
||||||
|
];
|
||||||
|
|
||||||
|
register_staff_capabilities('project_notifications', $capabilities, _l('pn_title'));
|
||||||
|
}
|
||||||
|
|
||||||
|
register_activation_hook(PROJECT_NOTIFICATIONS_MODULE_NAME, 'project_notifications_module_activation_hook');
|
||||||
|
|
||||||
|
function project_notifications_module_activation_hook()
|
||||||
|
{
|
||||||
|
$CI = &get_instance();
|
||||||
|
|
||||||
|
require_once(__DIR__ . '/install.php');
|
||||||
|
}
|
||||||
|
|
||||||
|
register_language_files(PROJECT_NOTIFICATIONS_MODULE_NAME, [PROJECT_NOTIFICATIONS_MODULE_NAME]);
|
||||||
|
|
||||||
|
function project_notifications_module_init_menu_items()
|
||||||
|
{
|
||||||
|
$CI = &get_instance();
|
||||||
|
|
||||||
|
$CI->app->add_quick_actions_link([
|
||||||
|
'name' => _l('pn_title'),
|
||||||
|
'url' => 'project_notifications/notify',
|
||||||
|
'permission' => 'project_notifications',
|
||||||
|
'position' => 56,
|
||||||
|
]);
|
||||||
|
|
||||||
|
if (has_permission('pa_notify', '', 'view')) {
|
||||||
|
$CI->app_menu->add_sidebar_children_item('utilities', [
|
||||||
|
'slug' => 'project-notifications',
|
||||||
|
'name' => _l('pn_title'),
|
||||||
|
'href' => admin_url('project_notifications'),
|
||||||
|
'position' => 24,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
129
views/email_templates/email.php
Normal file
129
views/email_templates/email.php
Normal file
@ -0,0 +1,129 @@
|
|||||||
|
<p>Hello. Below you can find an updated log for the time recorded on the <b><?php echo $projectName; ?></b> project. Please make sure the Upwork contract is synced accordingly.</p>
|
||||||
|
|
||||||
|
<p>These hours need to be logged into Upwork. Here are his log in details.</p>
|
||||||
|
|
||||||
|
<?php $upworkAccount = NULL; ?>
|
||||||
|
<?php $upworkContractId = NULL; ?>
|
||||||
|
|
||||||
|
<?php if ((isset($contractCustomFields)) && (!empty($contractCustomFields)) && (is_array($contractCustomFields))): ?>
|
||||||
|
|
||||||
|
<?php foreach ($contractCustomFields as $contractCustomField): ?>
|
||||||
|
|
||||||
|
<?php if ($contractCustomField['slug'] == "contracts_upwork_account"): ?>
|
||||||
|
|
||||||
|
<?php $upworkAccount = $contractCustomField['value']; ?>
|
||||||
|
|
||||||
|
<?php elseif ($contractCustomField['slug'] == "contracts_upwork_contract_id"): ?>
|
||||||
|
|
||||||
|
<?php $upworkContractId = $contractCustomField['value']; ?>
|
||||||
|
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<?php endforeach; ?>
|
||||||
|
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<b>URL:</b> <a href="https://www.upwork.com">Click Here</a><br />
|
||||||
|
<b>Account:</b> <?php echo $upworkAccount; ?><br />
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>Simply visit the contract named <a href="http://www.upwork.com/ab/workdiary/freelancer/#/<?php echo $upworkContractId; ?>"><?php echo $contractSubject; ?></a> in Upwork then record the hours listed below. Make sure the total hours match (or exceed) the hours from our portal.</p>
|
||||||
|
|
||||||
|
<table width="75%" cellpadding="5" align="center" style="margin-top: 10px;">
|
||||||
|
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th bgcolor="#000000"><font color="#FFFFFF">Task</font></th>
|
||||||
|
<th bgcolor="#000000"><font color="#FFFFFF">Hours</font></th>
|
||||||
|
<th bgcolor="#000000"><font color="#FFFFFF">Minutes</font></th>
|
||||||
|
<th bgcolor="#000000"><font color="#FFFFFF">Decimal</font></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
|
||||||
|
<?php
|
||||||
|
if ( isset($taskLists) && is_array($taskLists) )
|
||||||
|
{
|
||||||
|
$grandTotalTime = 0;
|
||||||
|
foreach ($taskLists as $taskList)
|
||||||
|
{
|
||||||
|
?>
|
||||||
|
<tr>
|
||||||
|
<td bgcolor="#ffd700" colspan="4" align="center">
|
||||||
|
<font color="#000000">
|
||||||
|
<b><?php echo $taskList['DATE']; ?></b>
|
||||||
|
</font>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<?php
|
||||||
|
$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);
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td bgcolor="#808080"><font color="#FFFFFF"><?php echo $task['NAME']; ?></font></td>
|
||||||
|
<td bgcolor="#808080"><font color="#FFFFFF"><?php echo str_pad($hr, 2, "0", STR_PAD_LEFT); ?></font></td>
|
||||||
|
<td bgcolor="#808080"><font color="#FFFFFF"><?php echo str_pad($min, 2, "0", STR_PAD_LEFT); ?></font></td>
|
||||||
|
<td bgcolor="#808080"><font color="#FFFFFF"><?php echo number_format($hrDec,2,'.',''); ?></font></td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
|
||||||
|
$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;
|
||||||
|
?>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td bgcolor="#ffd700" colspan="4" align="center"><font color="#000000"><b>Total Time: <?php echo $taskExeTime; ?> Hours</b></font></td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td bgcolor="#000000" colspan="4" align="center" style="height: 5px;"></td>
|
||||||
|
</tr>
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
|
||||||
|
$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);
|
||||||
|
|
||||||
|
?>
|
||||||
|
<tfoot style="padding-top: -5px;">
|
||||||
|
<tr>
|
||||||
|
<td bgcolor="#000000" colspan="4" align="center" valign="middle"><font color="#FFFFFF"><h1>Grand Total Time: <?php echo $grandExeTime; ?> Hours</h1></font></td>
|
||||||
|
</tr>
|
||||||
|
</tfoot>
|
||||||
|
<?php
|
||||||
|
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</table>
|
11
views/index.html
Normal file
11
views/index.html
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>403 Forbidden</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<p>Directory access is forbidden.</p>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
56
views/project_notifications.php
Normal file
56
views/project_notifications.php
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
<?php defined('BASEPATH') or exit('No direct script access allowed'); ?>
|
||||||
|
<?php init_head(); ?>
|
||||||
|
<div id="wrapper">
|
||||||
|
<div class="content">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-12">
|
||||||
|
<div class="panel_s">
|
||||||
|
<div class="panel-body">
|
||||||
|
<h4 class="no-margin"><?php echo $title; ?></h4>
|
||||||
|
<hr class="hr-panel-heading" />
|
||||||
|
<div class="row _buttons">
|
||||||
|
<div class="col-md-12">
|
||||||
|
<?php
|
||||||
|
if(has_permission('project_notifications','','create')){
|
||||||
|
?>
|
||||||
|
<a href="#" onclick="new_task(<?php echo "'".admin_url('project_notifications/configure')."'"; ?>); return false;" class="btn btn-info pull-left new"><?php echo _l('pa_new_notifier'); ?></a>
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
<?php
|
||||||
|
if(has_permission('project_notifications','','create_template')){
|
||||||
|
?>
|
||||||
|
<a href="<?php echo admin_url('project_notifications/email_templates'); ?>" class="btn btn-info pull-right new"><?php echo _l('pa_email_template'); ?></a>
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<hr class="hr-panel-heading hr-10" />
|
||||||
|
<div class="clearfix"></div>
|
||||||
|
|
||||||
|
<?php
|
||||||
|
render_datatable(array(
|
||||||
|
_l('id'),
|
||||||
|
_l('pa_trigger_time_h'),
|
||||||
|
_l('pa_trigger_day_h'),
|
||||||
|
_l('pa_emails_h'),
|
||||||
|
_l('pa_task_choice_type_h'),
|
||||||
|
_l('pa_projects_h'),
|
||||||
|
_l('pa_dataset_h'),
|
||||||
|
),'project-activity');
|
||||||
|
?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php init_tail(); ?>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
<script>
|
||||||
|
$(function(){
|
||||||
|
initDataTable('.table-project-activity', window.location.href);
|
||||||
|
});
|
||||||
|
</script>
|
45
views/tables/list.php
Normal file
45
views/tables/list.php
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
<?php
|
||||||
|
defined('BASEPATH') or exit('No direct script access allowed');
|
||||||
|
$aColumns = [
|
||||||
|
'id',
|
||||||
|
'triggertime',
|
||||||
|
'triggerday',
|
||||||
|
'emails',
|
||||||
|
'(CASE WHEN choice_type="CONTRACT" THEN "Project with Contract Type" ELSE "Specific Project" END)',
|
||||||
|
'(CASE WHEN choice_type="CONTRACT" THEN (SELECT name FROM ' . db_prefix() . 'contracts_types WHERE ' . db_prefix() . 'contracts_types.id = ' . db_prefix() . 'project_notifications.contract_type) ELSE (SELECT name FROM ' . db_prefix() . 'projects WHERE ' . db_prefix() . 'projects.id = ' . db_prefix() . 'project_notifications.projects) END)',
|
||||||
|
'(CASE WHEN dataset="SO-FAR" THEN "Send Details So Far" ELSE "Send Details For Previous Week" END)',
|
||||||
|
];
|
||||||
|
$sIndexColumn = 'id';
|
||||||
|
$sTable = db_prefix() . 'project_notifications';
|
||||||
|
$result = data_tables_init($aColumns, $sIndexColumn, $sTable, [], [], []);
|
||||||
|
|
||||||
|
$output = $result['output'];
|
||||||
|
$rResult = $result['rResult'];
|
||||||
|
|
||||||
|
foreach ($rResult as $aRow) {
|
||||||
|
|
||||||
|
$row = [];
|
||||||
|
for ($i = 0; $i < count($aColumns); $i++) {
|
||||||
|
$_data = $aRow[$aColumns[$i]];
|
||||||
|
|
||||||
|
if ($aColumns[$i] == 'triggertime') {
|
||||||
|
$_data = '<a href="#" onclick="new_task(\''.admin_url('project_notifications/configure/'.$aRow['id']).'\'); return false;">' . $_data . '</a>';
|
||||||
|
|
||||||
|
$_data .= '<div class="row-options">';
|
||||||
|
|
||||||
|
$_data .= ' <a href="#" onclick="new_task(\''.admin_url('project_notifications/configure/'.$aRow['id']).'\'); return false;">' . _l('edit') . '</a>';
|
||||||
|
|
||||||
|
if (has_permission('notification', '', 'delete')) {
|
||||||
|
$_data .= ' | <a href="' . admin_url('project_notifications/delete/' . $aRow['id']) . '" class="text-danger _delete">' . _l('delete') . '</a>';
|
||||||
|
}
|
||||||
|
|
||||||
|
$_data .= ' | <a href="' . admin_url('project_notifications/execute/' . $aRow['id']) . '">' . _l('pn_execute') . '</a>';
|
||||||
|
|
||||||
|
$_data .= '</div>';
|
||||||
|
}
|
||||||
|
$row[] = $_data;
|
||||||
|
}
|
||||||
|
$row['DT_RowClass'] = 'has-row-options';
|
||||||
|
$output['aaData'][] = $row;
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user