commit 1bf7fbee0ef1ee318e242b904e6e7ff993451f0d Author: kris@sentientgeeks.com Date: Mon Feb 8 14:49:42 2021 +0530 initial Commit diff --git a/controllers/Project_notifications.php b/controllers/Project_notifications.php new file mode 100644 index 0000000..7a1e361 --- /dev/null +++ b/controllers/Project_notifications.php @@ -0,0 +1,176 @@ +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 + +} \ No newline at end of file diff --git a/controllers/index.html b/controllers/index.html new file mode 100644 index 0000000..b702fbc --- /dev/null +++ b/controllers/index.html @@ -0,0 +1,11 @@ + + + + 403 Forbidden + + + +

Directory access is forbidden.

+ + + diff --git a/libraries/Project_notifications_module.php b/libraries/Project_notifications_module.php new file mode 100644 index 0000000..959211c --- /dev/null +++ b/libraries/Project_notifications_module.php @@ -0,0 +1,362 @@ +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); + } +} diff --git a/models/Project_notifications_model.php b/models/Project_notifications_model.php new file mode 100644 index 0000000..04195a9 --- /dev/null +++ b/models/Project_notifications_model.php @@ -0,0 +1,352 @@ +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); + } + +} diff --git a/models/index.html b/models/index.html new file mode 100644 index 0000000..b702fbc --- /dev/null +++ b/models/index.html @@ -0,0 +1,11 @@ + + + + 403 Forbidden + + + +

Directory access is forbidden.

+ + + diff --git a/project_notifications.php b/project_notifications.php new file mode 100644 index 0000000..767fc4e --- /dev/null +++ b/project_notifications.php @@ -0,0 +1,69 @@ +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, + ]); + } +} \ No newline at end of file diff --git a/views/email_templates/email.php b/views/email_templates/email.php new file mode 100644 index 0000000..49016d8 --- /dev/null +++ b/views/email_templates/email.php @@ -0,0 +1,129 @@ +

Hello. Below you can find an updated log for the time recorded on the project. Please make sure the Upwork contract is synced accordingly.

+ +

These hours need to be logged into Upwork. Here are his log in details.

+ + + + + + + + + + + + + + + + + + + + + + +

+ URL: Click Here
+ Account:
+

+ +

Simply visit the contract named in Upwork then record the hours listed below. Make sure the total hours match (or exceed) the hours from our portal.

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
TaskHoursMinutesDecimal
+ + + +
Total Time: Hours

Grand Total Time: Hours

diff --git a/views/index.html b/views/index.html new file mode 100644 index 0000000..b702fbc --- /dev/null +++ b/views/index.html @@ -0,0 +1,11 @@ + + + + 403 Forbidden + + + +

Directory access is forbidden.

+ + + diff --git a/views/project_notifications.php b/views/project_notifications.php new file mode 100644 index 0000000..7a5ccc7 --- /dev/null +++ b/views/project_notifications.php @@ -0,0 +1,56 @@ + + +
+
+
+
+
+
+

+
+ +
+
+ + +
+
+
+
+
+
+ + + + \ No newline at end of file diff --git a/views/tables/list.php b/views/tables/list.php new file mode 100644 index 0000000..7760f26 --- /dev/null +++ b/views/tables/list.php @@ -0,0 +1,45 @@ +' . $_data . ''; + + $_data .= '
'; + + $_data .= ' ' . _l('edit') . ''; + + if (has_permission('notification', '', 'delete')) { + $_data .= ' | ' . _l('delete') . ''; + } + + $_data .= ' | ' . _l('pn_execute') . ''; + + $_data .= '
'; + } + $row[] = $_data; + } + $row['DT_RowClass'] = 'has-row-options'; + $output['aaData'][] = $row; + +} \ No newline at end of file