/** * get the current time * @param int $delay * @param int $offset */ public static function getNow($delay = 0, $offset = false, $specificTime = null) { $timeOffset = jnews::calculateOffset(JNEWS_TIME_OFFSET); //we calculate the offset depending on the version of joomla $nowTime = !empty($specificTime) ? $specificTime : time(); $nowTime = $nowTime + $timeOffset + $delay * 60; if ($offset) { $nowTime = $nowTime - date('Z'); } return $nowTime; // - date('Z'); }
function statistics($listId, $listType, $mailingId, $message, $task, $action) { //From Specified fieldset $sDate = JRequest::getVar('startdate'); $eDate = JRequest::getVar('enddate'); if ($task == 'cpanel') { jNews_Tools::redirect('index.php?option=' . JNEWS_OPTION); } //Predefined fieldset $currentInterval = JRequest::getVar('rptinterval'); $currentRange = JRequest::getVar('rptrange'); if (empty($currentRange)) { $currentRange = 'this-month'; } if (empty($currentInterval)) { $currentInterval = 'weekly'; } if ($sDate == '0000-00-00' && $eDate == '0000-00-00') { $sDate = 0; $eDate = 0; } if (!empty($sDate) && !empty($eDate)) { if ($sDate != '0000-00-00' && $eDate != '0000-00-00') { $sDate = strtotime($sDate); $sDate = $sDate - jnews::calculateOffset(JNEWS_TIME_OFFSET) + date('Z'); $eDate = strtotime($eDate); $eDate = $eDate - jnews::calculateOffset(JNEWS_TIME_OFFSET) + date('Z'); } elseif ($sDate != '0000-00-00' && $eDate == '0000-00-00') { $sDate = strtotime($sDate); $sDate = $sDate - jnews::calculateOffset(JNEWS_TIME_OFFSET) + date('Z'); $eDate = time(); // - JNEWS_TIME_OFFSET * 3600 ; } elseif ($sDate == '0000-00-00' && $eDate != '0000-00-00') { echo jnews::printM('warning', _JNEWS_REPORT_WARN_MESSAGE); $sDate = 0; $eDate = 0; } } else { //Set the correct startDateTime and endDateTime //Set also the correct intervals appropriate for each range //current datetime base on the website setting configuration $currDate = $eDate = time(); // - JNEWS_TIME_OFFSET * 3600 ; switch ($currentRange) { case 'today': //today $sDate = mktime(0, 0, 0, date('m'), date('d'), date('Y')); $eDate = mktime(23, 59, 59, date('m'), date('d'), date('Y')); $currentInterval = 'daily'; break; case 'yesterday': //yesterday $sDate = mktime(0, 0, 0, date('m'), date('d') - 1, date('Y')); $eDate = mktime(23, 59, 59, date('m'), date('d') - 1, date('Y')); $currentInterval = 'daily'; break; case 'this-week': //this week $sDate = mktime(0, 0, 0, date('n'), date('j'), date('Y')) - (date('N') - 1) * 3600 * 24; //if selected intervals is monthly or yearly if ($currentInterval == 'monthly' || $currentInterval == 'yearly') { $currentInterval = 'weekly'; } break; case 'last-week': //last week..start of the week is Monday at 00:00:00 and will end on Sunday at 23:59:59: $sDate = mktime(0, 0, 0, date('n'), date('j') - 6, date('Y')) - date('N') * 3600 * 24; $eDate = mktime(23, 59, 59, date('n'), date('j'), date('Y')) - date('N') * 3600 * 24; //if selected intervals is monthly or yearly if ($currentInterval == 'monthly' || $currentInterval == 'yearly') { $currentInterval = 'weekly'; } break; case 'last-2-weeks': //last 2 weeks $sDate = mktime(0, 0, 0, date('n'), date('j') - 13, date('Y')) - date('N') * 3600 * 24; $eDate = mktime(23, 59, 59, date('n'), date('j'), date('Y')) - date('N') * 3600 * 24; //if selected intervals is monthly or yearly if ($currentInterval == 'monthly' || $currentInterval == 'yearly') { $currentInterval = 'weekly'; } break; case 'last-month': //last month..starts at the first day to the last day $sDate = strtotime(date('m') - 1 . '/01/' . date('Y'), $currDate); $eDate = $sDate + 30 * 24 * 3600; //mktime(23, 59, 59, date('m')); if ($currentInterval == 'yearly') { $currentInterval = 'weekly'; } break; case 'this-year': //this year..starts $sDate = strtotime('01/01/' . date('Y'), $currDate); break; case 'last-year': //last year...starts jan 1 and ends dec 31 $sDate = mktime(0, 0, 0, 1, 1, date('Y') - 1); $eDate = mktime(23, 59, 59, 12, 31, date('Y') - 1); break; case '2-years-ago': //2 Years ago if ($currentInterval == 'yearly') { //if the interval is yearly $sDate = mktime(0, 0, 0, 1, 1, date('Y') - 2); //starts jan 1 } else { $eDate = mktime(23, 59, 59, 12, 31, date('Y') - 2); //ends dec 31 $sDate = mktime(0, 0, 0, 1, 1, date('Y') - 2); //starts jan 1 } break; case '3-years-ago': //3 Years ago if ($currentInterval == 'yearly') { //if the interval is yearly $sDate = mktime(0, 0, 0, 1, 1, date('Y') - 3); //starts jan 1 } else { $eDate = mktime(23, 59, 59, 12, 31, date('Y') - 3); //ends dec 31 $sDate = mktime(0, 0, 0, 1, 1, date('Y') - 3); //starts jan 1 } break; case 'this-month': //this month //this month default: $sDate = strtotime(date('m') . '/01/' . date('Y'), $currDate); if ($currentInterval == 'yearly') { $currentInterval = 'weekly'; } break; } } //Still need to double check if there's really values on the start and end date if (!empty($sDate) && !empty($eDate)) { //Title header $doc = JFactory::getDocument(); $css = '.icon-48-statistics_header { background-image:url(' . JNEWS_PATH_ADMIN_IMAGES2 . 'header/statistics.png)}'; $doc->addStyleDeclaration($css, $type = 'text/css'); $img = 'statistics_header.png'; $message = ''; $start = date('F j, Y', jnews::getNow(0, true, $sDate)); $end = date('F j, Y', jnews::getNow(0, true, $eDate)); if ($currentRange == 'today' || $currentRange == 'yesterday') { $title = _JNEWS_REPORT_HEADER . ': ' . $start; $fileNameExport = $start; } else { $title = _JNEWS_REPORT_HEADER . ': ' . $start . ' ' . _JNEWS_REPORT_HEADER_TO . ' ' . $end; $fileNameExport = $start . ' ' . _JNEWS_REPORT_HEADER_TO . ' ' . $end; } backHTML::_header($title, $img, $message, $task, $action); } $dateFormat = 'FROM_UNIXTIME('; switch ($currentInterval) { case 'yearly': //yearly $specialFormat = ',\'%Y\''; $dateFormat4DateNumber = 'FROM_UNIXTIME('; //.$columnModif.', \'' .substr($special, 10).'\'))'; $specialNo = ',\'%Y\')'; break; case 'weekly': //weekly $specialFormat = ',\'%M %d, %Y\''; $dateFormat4DateNumber = 'WEEK(' . $dateFormat; $dateFormat4DateNumber = 'WEEK(FROM_UNIXTIME('; //'dtfrmtweek%Y-%m-%d'; // WEEK(DATE_FORMAT(cdate, '%Y-%m-%d')) $specialNo = ',\'%Y-%m-%d\'))'; break; case 'daily': //daily $specialFormat = ',\'%M %d, %Y\''; $dateFormat4DateNumber = 'FROM_UNIXTIME('; //'dateformat%Y%m%d'; $specialNo = ',\'%Y%m%d\')'; break; case 'monthly': //monthly //monthly default: $specialFormat = ',\'%M, %Y\''; $dateFormat4DateNumber = 'FROM_UNIXTIME('; //'dateformat%Y%m%d'; $specialNo = ',\'%Y%m\')'; break; } $queryfilters = array(); $queryfilters['enddate'] = '\'' . $eDate . '\''; $queryfilters['startdate'] = '\'' . $sDate . '\''; $queryfilters['dateFormat'] = $dateFormat; $queryfilters['specialFormat'] = $specialFormat; $queryfilters['dateFormat4DateNumber'] = $dateFormat4DateNumber; $queryfilters['specialNo'] = $specialNo; $queryfilters['mailingId'] = $mailingId; $queryfilters['task'] = $task; //go to class.stats to display the view of stats require_once JNEWSPATH_CLASS . 'class.statistics.php'; outputReportGraph::initIncludes(); echo '<form action="index.php" method="post" name="adminForm" id="adminForm">'; if ($task == 'graph') { $results = array(); $results['subject'] = JRequest::getVar('subject', ''); $results['html_sent'] = JRequest::getVar('html_sent', '0'); $results['text_sent'] = JRequest::getVar('text_sent', '0'); $results['html_views'] = JRequest::getVar('html_views', '0'); $results['html_unread'] = JRequest::getVar('html_unread', '0'); $results['pending'] = JRequest::getVar('pending', '0'); // $results['failed'] = JRequest::getVar( 'failed', '0' ); // $results['bounces'] = JRequest::getVar( 'bounces', '0' ); $results['sent'] = JRequest::getVar('sent', '0'); // $results['sent'] = intval( $results['html_sent'] + $results['text_sent'] ); //fixed $results['id'] = JRequest::getVar('id'); $queryfilters['startdate'] = '\'' . JRequest::getInt('startdate') . '\''; $queryfilters['enddate'] = '\'' . JRequest::getVar('enddate') . '\''; outputReportGraph::mailingSpecificGraph($results, $queryfilters); } else { outputReportGraph::headerFilter($currentInterval); if (empty($fileNameExport)) { $fileNameExport = null; } outputReportGraph::tabReports($queryfilters, $task, $fileNameExport); } echo '</form>'; return true; }
/** public static function that will save mailing * @param int $mailingId - mailing id * @param int $listId - list id */ public static function saveMailing(&$mailingId, $listId) { $total = 0; $list = jNews_Lists::getOneList($listId); // $allow_html = jNews_Tools::allow_html(); $xf = new jNews_Config(); $db = JFactory::getDBO(); // check list type $mailingtype = JRequest::getVar('listype', 0); if (empty($mailingtype)) { $mySess = JFactory::getSession(); $listType = $mySess->set('listype', '', 'LType'); } else { $listType = $mailingtype; } $senddate = JRequest::getVar('senddate', 0); $task = JRequest::getVar('task', ''); if ($task == 'saveSend') { $senddate = time(); } $subject = JRequest::getVar('subject', '', 'request', 'string'); // $content = JRequest::getVar('content', '', 'request','string', JREQUEST_ALLOWRAW); $content = JRequest::getVar('jnewsContent', '', 'request', 'string', JREQUEST_ALLOWRAW); $alt_content = JRequest::getVar('altbody', '', JREQUEST_ALLOWRAW); $published = JRequest::getVar('published', 0); $visible = JRequest::getVar('visible', 1); $html = JRequest::getVar('html_mailings', 1); $new_list = JRequest::getVar('new_list', 0); $fromname = JRequest::getVar('fromname', ''); $fromemail = JRequest::getVar('fromemail', ''); $frombounce = JRequest::getVar('frombounce', ''); $userid = JRequest::getVar('userid', 0); $delay = JRequest::getVar('delay', 0); $acc_level = JRequest::getVar('acc_level', $list->acc_id); $issue_nb = JRequest::getVar('issue_nb', 1); if ($mailingtype == 7) { $issue_nb = 1; } $attachments = JRequest::getVar('attachments', ''); $follow_up = JRequest::getVar('follow_up', 0); $cat_id = JRequest::getVar('cat_id', ''); $delay_max = JRequest::getVar('delay_max', 7); $delay_min = JRequest::getVar('delay_min', 0); $notify_id = JRequest::getVar('notify_id', 0); $next_date = JRequest::getVar('next_date', 0); $start_date = JRequest::getVar('start_date', 0); $smart_date = JRequest::getVar('smart_date', 0); $listIdA = JRequest::getVar('aca_mailing_addto', array()); //clean up $cat_id if (!empty($cat_id)) { $cat_idA = explode(',', $cat_id); if (count($cat_idA) > 1) { //remove the all category $newcat_idA = array(); foreach ($cat_idA as $oneCat_id) { if ($oneCat_id != '0:0') { $newcat_idA[] = $oneCat_id; } } $cat_id = trim(implode(',', $newcat_idA), ','); } } $createdate = time(); //get the default template $template = jNews_Templates::loadOneTemplate('*', '', 'template_id', 'DESC', true); $template_id = JRequest::getVar('template_id', $template->template_id); // change start_date type from string to int if (!empty($senddate) and $task != 'saveSend') { $senddate = strtotime($senddate); $senddate = $senddate - jnews::calculateOffset(JNEWS_TIME_OFFSET) + date('Z'); if ($senddate <= time()) { $senddate = 0; } } elseif (!empty($senddate) && $task == 'saveSend') { //not used any more $senddate = $senddate; } else { $senddate = 0; } if (!empty($start_date)) { $start_date = strtotime($start_date); $start_date = $start_date - jnews::calculateOffset(JNEWS_TIME_OFFSET) + date('Z'); } if (!empty($next_date)) { $next_date = strtotime($next_date); $next_date = $next_date - jnews::calculateOffset(JNEWS_TIME_OFFSET) + date('Z'); } if (!empty($create_date)) { $create_date = strtotime($create_date); $create_date = $create_date - jnews::calculateOffset(JNEWS_TIME_OFFSET) + date('Z'); } $delay = $delay * 24 * 60; $attach = ''; if (!empty($attachments)) { foreach ($attachments as $attachment) { $attach .= $attachment . "\n"; } } if (!empty($_FILES['file_0']['name'])) { $otherAttachs = jNews_Mailing::uploadFiles(); if (!empty($otherAttachs)) { foreach ($otherAttachs as $otherAttach) { $attach .= '/' . $otherAttach . "\n"; } } } $images = JRequest::getVar('images', ''); if (empty($alt_content)) { $alt_content = jNews_ProcessMail::htmlToText($content); } else { $alt_content = "<pre>" . $alt_content . "</pre>"; } if ($listType == 2) { // auto-repsonders $senddate = time() + $delay * 60; } else { if ($senddate > time()) { $published = 2; } } if ($GLOBALS[JNEWS . 'show_subscriptionlink']) { if (substr_count($content, '{tag:subscriptions}') < 1) { $content .= "<br/> {tag:subscriptions} <br/>"; } if (strlen($alt_content) > 10 and substr_count($alt_content, '{tag:subscriptions}') < 1) { $alt_content .= "\r\n {tag:subscriptions} \r\n"; } } if ($GLOBALS[JNEWS . 'show_unsubscribelink']) { if (substr_count($content, '{tag:unsubscribe}') < 1) { $content .= "<br/> {tag:unsubscribe} <br/>"; } if (strlen($alt_content) > 10 and substr_count($alt_content, '{tag:unsubscribe}') < 1) { $alt_content .= "\r\n {tag:unsubscribe}\r\n"; } } // save to cross table if (!empty($listIdA) && !empty($listIdA)) { $myLIst2Add = array(); foreach ($listIdA as $listid => $values) { if ($values == 1) { $myLIst2Add[$listid] = true; } } } else { // we dont have any list selected return false; } //in saving in case there are still old tag format we will replace with new //we replce the oldtags to new tags $mailing = new stdClass(); $mailing->htmlcontent = jNews_Mailing::replaceOldTagsToNew($content); $mailing->textonly = jNews_Mailing::replaceOldTagsToNew($alt_content); if ($new_list != 0) { //NEW MAILING //information to be inserted $mailing->list_id = $listId; $mailing->mailing_type = $mailingtype; $mailing->senddate = $senddate; $mailing->subject = $subject; $mailing->htmlcontent = $content; $mailing->textonly = $alt_content; $mailing->attachments = $attach; $mailing->images = $images; $mailing->published = $published; $mailing->visible = $visible; $mailing->fromname = $fromname; $mailing->fromemail = $fromemail; $mailing->frombounce = $frombounce; $mailing->html = $html; $mailing->delay = $delay; $mailing->issue_nb = $issue_nb; $mailing->acc_level = $acc_level; $mailing->createdate = $createdate; $mailing->follow_up = $follow_up; if (empty($mailing->follow_up)) { $mailing->follow_up = 0; } $mailing->cat_id = $cat_id; $mailing->delay_max = $delay_max; $mailing->delay_min = $delay_min; $mailing->notify_id = $notify_id; $mailing->next_date = $next_date; $mailing->start_date = $start_date; $mailing->smart_date = $smart_date; $mailing->mailing_type = $mailingtype; $mailing->list_id = $listId; $mailing->author_id = $userid; $mailing->template_id = $template_id; //insert the mailing data $mailingId = jNews_Mailing::insertMailingData($mailing); $db->setQuery('SELECT LAST_INSERT_ID()'); $mailingId = $db->loadResult(); $xf->plus('totalmailing0', 1); $xf->plus('act_totalmailing0', 1); $xf->plus('totalmailing' . $listType, 1); $xf->plus('act_totalmailing' . $listType, 1); if ($listType == 7) { jNews_Queue::addSNinQueue($mailingId, $delay_min, $start_date, $mailing->next_date); } //modified for smartnewsletter added next_date jNews_Mailing::saveMailingList($mailingId, array_keys($myLIst2Add), $senddate, $listType, $published, (bool) $new_list); //if we have an auto-responder we need to make sure the new auto-responders get added to all current subscribed users if ($published && $mailingtype == 2) { //add the this auto-responders to all users //select all user subscribe to this autoresponder $query = "SELECT L.`subscriber_id`, L.`subdate`+" . $delay . ", " . $mailingId . ", 2, 1 FROM `#__jnews_listssubscribers` AS L "; $query .= " WHERE L.`list_id` =" . $listId; $query2 = "INSERT IGNORE `#__jnews_queue` ( `subscriber_id`, `send_date`, `mailing_id`, `type`, `priority` ) " . $query; $db->setQuery($query2); $db->query(); } } else { //update mailing $query = 'SELECT `send_date`,`published`,`delay` FROM `#__jnews_mailings` WHERE `id` =' . $mailingId; $db->setQuery($query); $mailingInfoO = $db->loadObject(); $queueSendDateUpdate = $mailingInfoO->send_date != $senddate ? true : false; $queuePublishUpdate = $mailingInfoO->published != $published ? true : false; $queueDelayUpdate = $mailingInfoO->delay != $delay ? $delay - $mailingInfoO->delay : 0; $query = "UPDATE `#__jnews_mailings` SET " . " `subject` = '" . addslashes($subject) . "', " . " `htmlcontent` = '" . addslashes($content) . "', " . " `textonly` = '" . addslashes($alt_content) . "', " . " `attachments` = '" . $attach . "', " . " `images` = '" . $images . "', " . " `published` = '" . $published . "', " . " `html` = " . $html . " , " . " `visible` = " . $visible . " , " . " `fromname` = '" . $fromname . "', " . " `fromemail` = '" . $fromemail . "', " . " `frombounce` = '" . $frombounce . "', " . " `author_id` = '" . $userid . "' , " . " `delay` = " . $delay . ", " . " `acc_level` = '" . $acc_level . "', " . " `send_date` = '" . $senddate . "', " . " `follow_up` = " . $follow_up . ", " . " `cat_id` = '" . $cat_id . "', " . " `delay_max` = " . (int) $delay_max . ", " . " `delay_min` = " . (int) $delay_min . ", " . " `notify_id` = " . (int) $notify_id . ", " . " `next_date` = " . (int) $next_date . ", " . " `template_id` = " . (int) $template_id . ", " . " `start_date` = " . (int) $start_date . ", " . " `smart_date` = " . (int) $smart_date . " " . " WHERE `id` =" . $mailingId; $db->setQuery($query); $db->query(); jNews_Mailing::saveMailingList($mailingId, array_keys($myLIst2Add), $senddate, $listType, $published, (bool) $new_list, $queueSendDateUpdate, $queuePublishUpdate, $queueDelayUpdate); if ($published && $mailingtype == 2) { $query_check = "SELECT `qid` FROM `#__jnews_queue` WHERE `type` = '8' AND `mailing_id` = '{$mailingId}'"; $db->setQuery($query_check); $additionInfo = $db->loadObjectList(); if (is_array($additionInfo) && !empty($additionInfo)) { $query_update = "UPDATE `#__jnews_queue` SET `type` = '2' WHERE mailing_id = {$mailingId}"; $db->setQuery($query_update); $db->query(); } } } return true; }