/** * This public static function generates the view of the mailing statistics * and reports lists and graphs. * @param array $filters array of header filters * @param string $type type of reports(listing, graph & export file) * @param string $task * @param string $fileNameExport */ public static function mailingReports($filters, $type, $task, $fileNameExport) { $my = JFactory::getUser(); if (!empty($my->id)) { $ownedlists = jNews_Lists::getOwnedlists($my->id); } if (version_compare(JVERSION, '1.6.0', '>=')) { //j16 $usergid = JAccess::getGroupsByUser($my->id, false); $my->gid = $usergid[0]; } $gidAdmins = array(24, 25, 7, 8); $dateFormat = $filters['dateFormat']; $specialFormat = $filters['specialFormat']; $dateFormat4DateNumber = $filters['dateFormat4DateNumber']; $specialNo = $filters['specialNo']; $startdate = $filters['startdate']; $enddate = $filters['enddate']; $mainframe = JFactory::getApplication(); $db = JFactory::getDBO(); $sql = "SELECT FROM_UNIXTIME(N.sentdate {$specialFormat}) AS s_date," . "\t{$dateFormat4DateNumber} N.sentdate {$specialNo} AS DateNumber, " . "\tM.subject, N.html_sent, N.text_sent, N.html_read as html_views, " . "\tN.pending, N.failed, N.bounces, N.sent, " . "\tN.mailing_id as id" . " FROM #__jnews_mailings AS M" . " LEFT JOIN #__jnews_stats_global AS N ON N.mailing_id = M.id"; if (!$mainframe->isAdmin()) { if ($GLOBALS[JNEWS . 'enable_jsub']) { $sql .= " LEFT JOIN #__jnews_listmailings AS O ON O.mailing_id = M.id"; } if (!in_array($my->gid, $gidAdmins) && jnews::checkpermissions($my->gid)) { //come back here if (!empty($ownedlists)) { $sql .= " LEFT JOIN #__jnews_listmailings AS O ON O.mailing_id = M.id"; } } } $sql .= " WHERE N.sentdate BETWEEN {$startdate} AND {$enddate}"; if (!$mainframe->isAdmin() && !jnews::checkPermissions('admin')) { if ($GLOBALS[JNEWS . 'enable_jsub'] && !empty($ownedlists)) { $sql .= " AND O.list_id IN (" . implode($ownedlists, ',') . ")"; } if (!in_array($my->gid, $gidAdmins) && jnews::checkpermissions($my->gid)) { $sql .= " AND O.list_id IN (" . implode($ownedlists, ',') . ")"; } } $sql .= " GROUP BY M.id, DateNumber ORDER BY DateNumber "; $db->setQuery($sql); $results = $db->loadObjectList(); $mainPath = JNEWS_PATH_ADMIN_IMAGES2 . '16/'; ?> <div id="wizard" class=""></div> <?php if ($GLOBALS[JNEWS . 'level'] > 2) { ?> <div id="exportbtn" style="float:right;"> <a href="#" name="exportmailing" value="<?php echo _JNEWS_STATS_EXPORT; ?> " onclick="submitbutton('exportmailing')" > <img src="<?php echo $mainPath . 'export_statistics.png'; ?> "/> </a> </div> <br/> <br/> <?php if ($task == 'exportm') { //Go to a public static function to export the generated file outputReportGraph::mailingExport($results, $fileNameExport); } if ($type == 'graph') { //tallying totals $totalData = array(); $totalData['subject'] = ''; $totalData['html_sent'] = 0; $totalData['text_sent'] = 0; $totalData['html_views'] = 0; $totalData['pending'] = 0; // $totalData['failed'] = 0; // $totalData['bounces'] = 0; $totalData['sent'] = 0; $totalData['mailings'] = 0; if (!empty($results)) { foreach ($results as $row) { $totalData['html_sent'] += $row->html_sent; $totalData['text_sent'] += $row->text_sent; $totalData['html_views'] += $row->html_views; $totalData['pending'] += $row->pending; // $totalData['failed'] += $row->failed; // $totalData['bounces'] += $row->bounces; $totalData['sent'] += $row->sent; // $totalData['sent'] += $row->html_sent + $row->text_sent; //fixed $totalData['mailings']++; } //end4each } // Fix by Amod Begins //outputReportGraph::mailingGraph( $totalData ); outputReportGraph::mailingGraph($results); // Fix by Amod Ends } } if ($type == 'listing') { //call the public static function that wil display the reports in listing type outputReportGraph::mailingList($results, str_replace("'", "", $startdate), str_replace("'", "", $enddate)); } return true; }