function fetch_report_new($fileName = '', $type = '', $columns = array(), $items = array(), $reciever = array(), $temp_type = '', $user_id) { $htmlData = ''; $data['excel'] = $type; $data['columns'] = $columns; $data['items'] = $items; $data['fileName'] = $fileName; $testEmail = false; if ($type == 'excel') { $this->load->view('excelview', $data); } elseif ($type == 'pdf') { $htmlData = $this->load->view('pdfview_reports', $data, true); $this->load->helper('pdf'); tcpdf_write($htmlData, $fileName); } else { $htmlData = $this->load->view('pdfview_reports', $data, true); if (template_email_send($temp_type, $user_id, '', $reciever, $htmlData)) { $testEmail = true; } else { $testEmail = false; } if ($testEmail) { $this->data->html = "Email successfully sent."; $this->data->div_class = "success"; return "success"; } else { $this->data->html = "Unable to send email."; $this->data->div_class = "error"; return "error"; } } }
/** * Go through the automated reports and send the * recurring report if the schedule recursion falls into * this five minute interval */ function schedule() { // Set the 5 minute window $window_start = new DateTime(date("Y-m-d H:i:00")); $window_end = new DateTime(date("Y-m-d H:i:00", strtotime('+5 minutes'))); $schArrays = array('daily_reports', 'weekly_reports', 'monthly_reports', 'yearly_reports'); // Get ALL scheduled reports fitting this timeframe // could be very useful in implementing user timezones in the future /* daily */ $daily_reports = $this->db->query("select sr.*, srs.*\n\t\t\tfrom saved_reports sr\n\t\t\tleft join saved_reports_schedule srs on srs.saved_reports_id=sr.id\n\t\t\twhere \n\t\t\tdate_format(srs.report_datetime, '%k') = date_format(now(), '%k')\n\t\t\tand (\n\t\t\t\t\tdate_format(now(), '%i')-date_format(srs.report_datetime, '%i') >= 0\n\t\t\t\tand date_format(now(), '%i')-date_format(srs.report_datetime, '%i') < 5\n\t\t\t)\n\t\t\tand CURDATE() >= date(srs.report_datetime)\n\t\t\tand\n\t\t\treport_recursive_frequency = 1")->result_array(); //print_r($daily_reports); exit; /* weekly */ $weekly_reports = $this->db->query("select sr.*, srs.*\n\t\t\tfrom saved_reports sr\n\t\t\tleft join saved_reports_schedule srs on srs.saved_reports_id=sr.id\n\t\t\twhere date_format(srs.report_datetime, '%w') = date_format(now(), '%w')\n\t\t\tand date_format(srs.report_datetime, '%k') = date_format(now(), '%k')\n\t\t\tand (\n\t\t\t\t\tdate_format(now(), '%i')-date_format(srs.report_datetime, '%i') >= 0\n\t\t\t\tand date_format(now(), '%i')-date_format(srs.report_datetime, '%i') < 5\n\t\t\t)\n\t\t\tand CURDATE() >= date(srs.report_datetime)\n\t\t\tand report_recursive_frequency = 7")->result_array(); /* monthly */ $monthly_reports = $this->db->query("select sr.*, srs.*\n\t\t\tfrom saved_reports sr\n\t\t\tleft join saved_reports_schedule srs on srs.saved_reports_id=sr.id\n\t\t\twhere (\n\t\t\t\t date_format(srs.report_datetime, '%e') = date_format(now(), '%e')\n\t\t\t\tOR date_format(now(), '%e')-date_format(srs.report_datetime, '%e') < 0\n\t\t\t)\n\t\t\tand (\n\t\t\t\t\tdate_format(now(), '%i')-date_format(srs.report_datetime, '%i') >= 0\n\t\t\t\tand date_format(now(), '%i')-date_format(srs.report_datetime, '%i') < 5\n\t\t\t)\n\t\t\tand CURDATE() >= date(srs.report_datetime)\n\t\t\tand report_recursive_frequency = 31")->result_array(); /* yearly */ $yearly_reports = $this->db->query("select sr.*, srs.*\n\t\t\tfrom saved_reports sr\n\t\t\tleft join saved_reports_schedule srs on srs.saved_reports_id=sr.id\n\t\t\twhere (\n\t\t\t\t date_format(srs.report_datetime, '%e') = date_format(now(), '%e')\n\t\t\t\tOR date_format(now(), '%e')-date_format(srs.report_datetime, '%e') < 0\n\t\t\t)\n\t\t\tand date_format(srs.report_datetime, '%m') = date_format(now(), '%m')\n\t\t\tand (\n\t\t\t\t\tdate_format(now(), '%i')-date_format(srs.report_datetime, '%i') >= 0\n\t\t\t\tand date_format(now(), '%i')-date_format(srs.report_datetime, '%i') < 5\n\t\t\t)\n\t\t\tand CURDATE() >= date(srs.report_datetime)\n\t\t\tand report_recursive_frequency = 365")->result_array(); //none of the schedule arrays are populated - nothing to see here... if (empty($daily_reports) && empty($weekly_reports) && empty($monthly_reports) && empty($yearly_reports)) { return; } foreach ($schArrays as $arr) { $curSched = ${$arr}; for ($i = 0, $n = sizeof($curSched); $i < $n; $i++) { $report = $curSched[$i]; $report['report_schedule_date'] = $report['report_datetime']; $this->data->report_id = $report['id']; $this->prepareData($report); if (!empty($this->report_info->report_type)) { $this->report_info->set_filename(); $receivers = $report['email_addresses']; $template = 'general'; $html = $this->renderHtml(); $txt = $this->renderTxt(); if ($html) { $returnVal = template_email_send($template, $this->data->user_id, $this->report_info->file_name, $receivers, $html, $txt); } unset($html, $txt, $this->data, $this->report_info->store_id); } } } //end foreach }
/** * Email a report to emails entered into export modal form. * * @author unknown * @param string $imageName */ public function email($imageName = '') { $this->_response_type('json'); // Get the request info $this->data->report_where = json_decode(html_entity_decode($this->input->post('report_where')), true); $this->data->report_where['fromDate'] = isset($this->data->report_where['date_from']) ? $this->data->report_where['date_from'] : strtotime(date('Y-m-d 00:00:00')); $this->data->report_where['toDate'] = isset($this->data->report_where['date_to']) ? $this->data->report_where['date_to'] : strtotime(date('Y-m-d 23:59:59')); $this->data->report_where['time_frame'] = isset($this->data->report_where['time_frame']) ? $this->data->report_where['time_frame'] : '24'; $moreInfo = $this->Store->get_store_track($this->store_id); $this->data->merchant_logo = get_merchant_logo_url($moreInfo->brand_logo); $this->data->file_name = $this->input->post('file_name'); $this->data->title = $this->data->headerDate = ''; $this->data->time_frame = $this->data->report_where['time_frame']; $this->data->product_ids = isset($this->data->report_where['product_ids']) ? $this->data->report_where['product_ids'] : array(); $this->data->retailer = (int) $this->input->post('is_retailer'); $rptInfo = getTitleReporting($this->data->report_where, 'Y'); $this->data->reportType = $this->input->post('report_type'); switch ($this->data->reportType) { case 'productpricing': $this->data->title = $emailSubject = 'Price Over Time'; $this->data->headerDate = $rptInfo['date']; break; case 'dns_list': $this->data->title = $emailSubject = 'Do Not Sell List Report'; $this->data->headerDate = $rptInfo['date']; break; case 'pricingoverview': $emailSubject = 'Pricing Overview'; $this->data->title = 'Today\'s Pricing'; $this->data->headerDate = $rptInfo['date']; break; case 'marketviolator': $emailSubject = 'Violations Detail'; $this->data->title = $this->data->file_name; $this->data->headerDate = $rptInfo['date']; break; case 'violationoverview': $emailSubject = 'Violations Overview'; $this->data->title = $this->data->file_name; $this->data->headerDate = $rptInfo['date']; break; case 'violator': $emailSubject = 'Price Violator'; $this->data->title = $this->data->file_name; $this->data->headerDate = $rptInfo['date']; break; case 'whois': $emailSubject = $this->data->file_name; $this->data->title = $this->data->file_name; $this->data->headerDate = $rptInfo['date']; break; default: $emailSubject = 'Price Violations'; $this->data->title = $rptInfo['title']; if (!empty($this->data->report_where['group_id'])) { $group = $this->Product->getGroupByID($this->data->report_where['group_id']); if (!empty($group['name'])) { $this->data->title = $group['name']; } } $this->data->headerDate = 'Dates: ' . $rptInfo['date']; } if (isset($_POST['report_name'])) { $this->data->title = $this->input->post('report_name') . ' - ' . $this->data->title; } // Get the images used $graphData = $this->input->post('graph_data'); if ($imageName == '' and $graphData) { $imageName = $this->generateImage($graphData, $this->store_id); } $this->data->graph_image_name = empty($imageName) ? '' : $imageName; // Generate the content require_once APPPATH . 'libraries/mvexport.php'; $content = $this->input->post('export_content'); $this->mvexport = new mvexport($content); $this->data->report = $this->mvexport->getReport('.reportTable'); // Create the email $template = 'general'; $email_addresses = $this->input->post('email_addresses'); if (is_array($email_addresses)) { $receivers = implode(',', array_flip(array_flip($this->input->post('email_addresses')))); } else { $receivers = $email_addresses; } $htmlContent = $this->load->view('reports/_email', $this->data, TRUE); $textContent = $this->load->view('reports/_email_txt', $this->data, TRUE); $this->data = template_email_send($template, $this->user_id, $emailSubject, $receivers, $htmlContent, $textContent); }