Exemplo n.º 1
0
function sendreport($id, $clicks, $impression, $lastreport)
{
    global $adver_id, $totals, $subject;
    $mosConfig_absolute_path = JPATH_BASE;
    $database = JFactory::getDBO();
    $db = JFactory::getDBO();
    if (!class_exists('TableadagencyConfig')) {
        require_once $mosConfig_absolute_path . "/components/com_adagency/tables/adagencyconfig.php";
    }
    if (!class_exists('adagencyModeladagencyConfig')) {
        require_once $mosConfig_absolute_path . "/components/com_adagency/models/adagencyconfig.php";
    }
    if (!class_exists('TableadagencyAds')) {
        require_once $mosConfig_absolute_path . "/components/com_adagency/models/adagencyconfig.php";
    }
    $configs = new adagencyModeladagencyConfig();
    $configs = $configs->getConfigs();
    $sql = "SELECT u.name, u.email FROM #__users AS u \n\t\t\tLEFT JOIN #__ad_agency_advertis AS a\n\t\t\tON u.id = a.user_id\n\t\t\tWHERE u.id=" . $id . " AND u.block =0 AND a.approved = 'Y'";
    $database->setQuery($sql);
    $user = $database->loadObjectList();
    // If the user is disabled, don't send any emails
    if (!isset($user[0]->email)) {
        return false;
    }
    $database->setQuery("SELECT `aid`,`lastreport`,`weekreport`,`monthreport` FROM #__ad_agency_advertis WHERE `user_id`={$id}");
    $adver = $database->loadObjectList();
    $adver_id = $adver[0]->aid;
    $timesql = date("Y-m-d h-i-s");
    $database->setQuery("SELECT count(id) FROM #__ad_agency_campaign WHERE `aid`={$adver_id} AND `approved`='Y' AND `exp_notice`!=1 AND ((`type` = 'cpm' AND `quantity` >0) OR (`type` = 'pc' AND `quantity` >0) OR (`type` = 'fr' AND `validity` > '" . $timesql . "'))");
    $totals = $database->loadResult();
    $database->setQuery("SELECT `id`,`type`,`quantity`,`validity` FROM #__ad_agency_campaign WHERE `aid`={$adver_id} AND `approved`='Y' AND `exp_notice`!=1 AND ((`type` = 'cpm' AND `quantity` >0) OR (`type` = 'pc' AND `quantity` >0) OR (`type` = 'fr' AND `validity` > '" . $timesql . "'))");
    $campaigns = $database->loadObjectList();
    $name = $user[0]->name;
    $email = $user[0]->email;
    $subject = html_entity_decode($subject, ENT_QUOTES);
    $subject = $configs->sbrep;
    $message = $configs->bodyrep;
    $class_helper = new modAdAgencyZoneHelper();
    $time = '[' . $class_helper->formatime(date("Y-m-d", $lastreport)) . '] - [' . $class_helper->formatime(date("Y-m-d")) . ']';
    if ($totals == 1) {
        $idcmp = $campaigns[0]->id;
        // check if campaign has banners
        $sql = "SELECT count(campaign_id) FROM `#__ad_agency_campaign_banner` WHERE `campaign_id`=" . $idcmp;
        $db->setQuery($sql);
        $banners_count_current_campaign = $db->loadResult();
        if ($banners_count_current_campaign == 0) {
            return false;
        }
        // check if campaign has banners - end
        $database->setQuery("SELECT `name` FROM #__ad_agency_campaign WHERE `id`={$idcmp}");
        $cmptext = $database->loadResult();
        if (!$clicks[0]) {
            $clicks[0] = 0;
        }
        if (!$impression[0]) {
            $impression[0] = 0;
        }
        if ($clicks[0] == 0 && $impression[0] == 0) {
            return false;
        }
        $message = str_replace('{name}', $name, $message);
        $message = str_replace('{daterange}', $time, $message);
        $message = str_replace('{clicks}', $clicks[0], $message);
        $message = str_replace('{impressions}', $impression[0], $message);
        $message = str_replace('{used_for_more_campaigns}', ' ', $message);
        $message = str_replace('{campaign}', $cmptext, $message);
    } else {
        if ($totals > 1) {
            if (!$clicks[0]) {
                $clicks[0] = 0;
            }
            if (!$impression[0]) {
                $impression[0] = 0;
            }
            if ($clicks[0] == 0 && $impression[0] == 0) {
                $first_zero = true;
            } else {
                $first_zero = false;
            }
            $message = str_replace('{name}', $name, $message);
            $message = str_replace('{daterange}', $time, $message);
            $message = str_replace('{clicks}', $clicks[0], $message);
            $message = str_replace('{impressions}', $impression[0], $message);
            $cmp_id = 0;
            foreach ($campaigns as $cmps) {
                // check if campaign has banners
                $sql = "SELECT count(campaign_id) FROM `#__ad_agency_campaign_banner` WHERE `campaign_id`=" . $cmps->id;
                $db->setQuery($sql);
                $banners_count_current_campaign = $db->loadResult();
                if ($banners_count_current_campaign == 0) {
                    continue;
                }
                // check if campaign has banners - end
                $database->setQuery("SELECT `name` FROM #__ad_agency_campaign WHERE `approved`='Y' AND `id`={$cmps->id}");
                $cmptext[$cmp_id] = $database->loadObjectList();
                $cmp_id++;
            }
            $morecmp = '';
            $temp = $cmp_id - 1;
            $tmp = 1;
            while ($temp) {
                if (!$clicks[$tmp]) {
                    $clicks[$tmp] = 0;
                }
                if (!$impression[$tmp]) {
                    $impression[$tmp] = 0;
                }
                if ($clicks[$tmp] != 0 && $impression[$tmp] != 0) {
                    $morecmp .= "<br />Campaign Name: " . $cmptext[$tmp][0]->name . "<br /><br />";
                    $morecmp .= $clicks[$tmp] . " - Clicks total<br />";
                    $morecmp .= $impression[$tmp] . " - Impressions total<br />";
                }
                $tmp++;
                $temp--;
            }
            if ($first_zero == true && $morecmp == '') {
                return false;
            }
            $message = str_replace('{campaign}', $cmptext[0][0]->name, $message);
            $message = str_replace('{used_for_more_campaigns}', $morecmp, $message);
        }
    }
    $message = html_entity_decode($message, ENT_QUOTES);
    $newtime = time();
    if ($totals != 0) {
        if ($lastreport == $adver[0]->lastreport) {
            $database->setQuery("UPDATE #__ad_agency_advertis SET `lastreport`='{$newtime}' WHERE `user_id`={$id} ");
            $database->query();
        } else {
            if ($lastreport == $adver[0]->weekreport) {
                $database->setQuery("UPDATE #__ad_agency_advertis SET `weekreport`='{$newtime}' WHERE `user_id`={$id} ");
                $database->query();
            } else {
                if ($lastreport == $adver[0]->monthreport) {
                    $database->setQuery("UPDATE #__ad_agency_advertis SET `monthreport`='{$newtime}' WHERE `user_id`={$id} ");
                    $database->query();
                }
            }
        }
        $sql = "select `params` from #__ad_agency_settings";
        $db->setQuery($sql);
        $db->query();
        $email_params = $db->loadColumn();
        $email_params = @$email_params["0"];
        $email_params = unserialize($email_params);
        if ($email_params["send_report_to_advertiser"] == 1) {
            JFactory::getMailer()->sendMail($configs->fromemail, $configs->fromname, $email, $subject, $message, 1);
        }
    }
}
Exemplo n.º 2
0
<?php

/**
 * @copyright   (C) 2010 iJoomla, Inc. - All rights reserved.
 * @license  GNU General Public License, version 2 (http://www.gnu.org/licenses/gpl-2.0.html) * @author  iJoomla.com webmaster@ijoomla.com
 * @url   http://www.ijoomla.com/licensing/
 * the PHP code portions are distributed under the GPL license. If not otherwise stated, all images, manuals, cascading style sheets, and included JavaScript  *are NOT GPL, and are released under the IJOOMLA Proprietary Use License v1.0 
 * More info at http://www.ijoomla.com/licensing/
*/
// no direct access
defined('_JEXEC') or die('Restricted access');
// Include the helper functions only once
if (!defined('DS')) {
    define('DS', DIRECTORY_SEPARATOR);
}
require_once dirname(__FILE__) . DS . 'helper.php';
$doc = JFactory::getDocument();
$doc->addScript(JURI::root() . "modules/mod_ijoomla_adagency_zone/includes/helper.js");
$real_ip = iJoomlaGetRealIpAddrModule();
$blacklist = getIPBlocklist();
if (in_array($real_ip, $blacklist)) {
    return "";
}
// Get data from helper class
$helper = new modAdAgencyZoneHelper();
$zone_output = $helper->getParams($module);
$module_id = $module->id;
// Run default template script for output
require JModuleHelper::getLayoutPath('mod_ijoomla_adagency_zone');