* @author Taiwen Jiang * @author DuGris aka L. Jen * @author Kris * @version $Id: banners.php 8066 2011-11-06 05:09:33Z beckmi $ */ $xoopsOption['pagetype'] = 'banners'; include dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mainfile.php'; /********************************************/ /* Function to let your client login to see */ /* the stats */ /********************************************/ function clientlogin() { global $xoopsDB, $xoopsLogger, $xoopsConfig; include 'header.php'; $GLOBALS["xoTheme"]->addStylesheet(null, null, ' #login_window { max-width: 480px; margin: 1em auto; background-color: #f8f8f8; color: inherit; border: 1px solid #000; } #login_window h2 { margin: .5em; padding: 130px 0 0; background: url( images/password.png) no-repeat center top; text-align: center; } .login_form .credentials { margin: .5em 1em; padding: 1em; background-color: #ccc; color: inherit; } .login_form .credentials label { display: inline-block; width: 33%; margin: 1px; } .login_form .credentials input { width: 50%; margin: 1px; padding: 1px; border: 1px solid #000; } .login_form .credentials input:focus { border: 1px solid #2266cc; } .login_form .actions { padding: 1.5em .5em .5em; text-align: center; } .login_info { margin: .5em 1em; text-align: center; } .content_title { font-size: 1.2em; } '); echo "

" . _BANNERS_LOGIN_TITLE . "

"; include $GLOBALS['xoops']->path('footer.php'); } /*********************************************/ /* Function to display the banners stats for */ /* each client */ /*********************************************/ function bannerstats() { global $xoopsDB, $xoopsConfig, $xoopsLogger, $myts ; if ($_SESSION['banner_login'] == "" || $_SESSION['banner_pass'] == "") { redirect_header("banners.php", 2, _BANNERS_NO_LOGIN_DATA); exit(); } $result = $xoopsDB->query(sprintf("SELECT cid, name, passwd FROM %s WHERE login=%s", $xoopsDB->prefix("bannerclient"), $xoopsDB->quoteString($_SESSION['banner_login']))); list ($cid, $name, $passwd) = $xoopsDB->fetchRow($result); if ($_SESSION['banner_pass'] == $passwd) { include $GLOBALS['xoops']->path('header.php'); $GLOBALS["xoTheme"]->addStylesheet(null, null, ' #bannerstats {} #bannerstats td { text-align: center; } '); echo "

" . sprintf(_BANNERS_TITLE, $name) . "


"; $result = $xoopsDB->query("SELECT bid, imptotal, impmade, clicks, date FROM " . $xoopsDB->prefix("banner") . " WHERE cid={$cid}"); $i = 0; while (list ($bid, $imptotal, $impmade, $clicks, $date) = $xoopsDB->fetchRow($result)) { if ($impmade == 0) { $percent = 0; } else { $percent = substr(100 * $clicks / $impmade, 0, 5); } if ($imptotal == 0) { $left = _BANNERS_UNLIMITED; } else { $left = $imptotal - $impmade; } $class = ($i % 2 == 0) ? 'even' : 'odd'; echo ""; $i++; } echo "
" . sprintf(_BANNERS_TITLE, $name) . "
ID " . _BANNERS_IMP_MADE . " " . _BANNERS_IMP_TOTAL . " " . _BANNERS_IMP_LEFT . " " . _BANNERS_CLICKS . " " . _BANNERS_PER_CLICKS . " " . _BANNERS_FUNCTIONS . "
{$bid} {$impmade} {$imptotal} {$left} {$clicks} {$percent}% " . _BANNERS_STATS . "


" . _BANNERS_FOW_IN . htmlspecialchars($xoopsConfig['sitename']) . "


"; $result = $xoopsDB->query("SELECT bid, imageurl, clickurl, htmlbanner, htmlcode FROM " . $xoopsDB->prefix("banner") . " WHERE cid={$cid}"); while (list ($bid, $imageurl, $clickurl, $htmlbanner, $htmlcode) = $xoopsDB->fetchRow($result)) { $numrows = $xoopsDB->getRowsNum($result); if ($numrows > 1) { echo "
"; } if (!empty($htmlbanner) && !empty($htmlcode)) { echo $myts->displayTarea($htmlcode); } else { if (strtolower(substr($imageurl, strrpos($imageurl, "."))) == ".swf") { echo ""; echo ""; echo ""; echo ""; } else { echo ""; } } echo "
" . _BANNERS_ID . $bid . "
" . sprintf(_BANNERS_SEND_STATS, 'banners.php?op=EmailStats&cid=' . $cid . '&bid=' . $bid) . "
"; if (!$htmlbanner) { $clickurl = htmlspecialchars($clickurl, ENT_QUOTES); echo sprintf(_BANNERS_POINTS, $clickurl) . "
" . _BANNERS_URL . " " . $GLOBALS['xoopsSecurity']->getTokenHTML("BANNER_EDIT") . "
"; } } /* Finnished Banners */ echo "
"; if ($result = $xoopsDB->query("SELECT bid, impressions, clicks, datestart, dateend FROM " . $xoopsDB->prefix("bannerfinish") . " WHERE cid={$cid}")) { echo "

" . sprintf(_BANNERS_FINISHED, $name) . "


"; $i = 0; while (list ($bid, $impressions, $clicks, $datestart, $dateend) = $xoopsDB->fetchRow($result)) { if ($impressions == 0) { $percent = 0; } else { $percent = substr(100 * $clicks / $impressions, 0, 5); } $class = ($i % 2 == 0) ? 'even' : 'odd'; echo ""; } echo "
" . sprintf(_BANNERS_FINISHED, $name) . "
ID " . _BANNERS_IMP_MADE . " " . _BANNERS_CLICKS . " " . _BANNERS_PER_CLICKS . " " . _BANNERS_STARTED . " " . _BANNERS_ENDED . "
{$bid} {$impressions} {$clicks} {$percent}% " . formatTimestamp($datestart) . " " . formatTimestamp($dateend) . "
"; } include $GLOBALS['xoops']->path('footer.php'); } else { redirect_header("banners.php", 2); exit(); } } /*********************************************/ /* Function to let the client E-mail his */ /* banner Stats */ /*********************************************/ function EmailStats($cid, $bid) { global $xoopsDB, $xoopsConfig; if ($_SESSION['banner_login'] != "" && $_SESSION['banner_pass'] != "") { $cid = intval($cid); $bid = intval($bid); if ($result2 = $xoopsDB->query(sprintf("SELECT name, email, passwd FROM %s WHERE cid=%u AND login=%s", $xoopsDB->prefix("bannerclient"), $cid, $xoopsDB->quoteString($_SESSION['banner_login'])))) { list ($name, $email, $passwd) = $xoopsDB->fetchRow($result2); if ($_SESSION['banner_pass'] == $passwd) { if ($email == "") { redirect_header("banners.php", 3, sprintf(_BANNERS_MAIL_ERROR, $name)); exit(); } else { if ($result = $xoopsDB->query("SELECT bid, imptotal, impmade, clicks, imageurl, clickurl, date FROM " . $xoopsDB->prefix("banner") . " WHERE bid={$bid} AND cid={$cid}")) { list ($bid, $imptotal, $impmade, $clicks, $imageurl, $clickurl, $date) = $xoopsDB->fetchRow($result); if ($impmade == 0) { $percent = 0; } else { $percent = substr(100 * $clicks / $impmade, 0, 5); } if ($imptotal == 0) { $left = _BANNERS_UNLIMITED; $imptotal = _BANNERS_UNLIMITED; } else { $left = $imptotal - $impmade; } $fecha = date("F jS Y, h:iA."); $subject = sprintf(_BANNERS_MAIL_SUBJECT, $xoopsConfig['sitename']); $message = sprintf(_BANNERS_MAIL_MESSAGE, $xoopsConfig['sitename'], $name, $bid, $imageurl, $clickurl, $imptotal, $impmade, $left, $clicks, $percent, $fecha); $xoopsMailer = & xoops_getMailer(); $xoopsMailer->useMail(); $xoopsMailer->setToEmails($email); $xoopsMailer->setFromEmail($xoopsConfig['adminmail']); $xoopsMailer->setFromName($xoopsConfig['sitename']); $xoopsMailer->setSubject($subject); $xoopsMailer->setBody($message); $xoopsMailer->send(); redirect_header("banners.php?op=Ok", 3, _BANNERS_MAIL_OK); exit(); } } } } } redirect_header("banners.php", 2); exit(); } /*********************************************/ /* Function to let the client to change the */ /* url for his banner */ /*********************************************/ function change_banner_url_by_client($cid, $bid, $url) { global $xoopsDB; if ($_SESSION['banner_login'] != "" && $_SESSION['banner_pass'] != "" && $url != "") { $cid = intval($cid); $bid = intval($bid); $sql = sprintf("SELECT passwd FROM %s WHERE cid=%u AND login=%s", $xoopsDB->prefix("bannerclient"), $cid, $xoopsDB->quoteString($_SESSION['banner_login'])); if ($result = $xoopsDB->query($sql)) { list ($passwd) = $xoopsDB->fetchRow($result); if ($_SESSION['banner_pass'] == $passwd) { $sql = sprintf("UPDATE %s SET clickurl=%s WHERE bid=%u AND cid=%u", $xoopsDB->prefix("banner"), $xoopsDB->quoteString($url), $bid, $cid); if ($xoopsDB->query($sql)) { redirect_header("banners.php?op=Ok", 3, _BANNERS_DBUPDATED); exit(); } } } } redirect_header("banners.php", 2); exit(); } function clickbanner($bid) { global $xoopsDB; $bid = intval($bid); if ($bid > 0) { $bresult = $xoopsDB->query("SELECT clickurl FROM " . $xoopsDB->prefix("banner") . " WHERE bid={$bid}"); list ($clickurl) = $xoopsDB->fetchRow($bresult); if ($clickurl) { if ($GLOBALS['xoopsSecurity']->checkReferer()) { $xoopsDB->queryF("UPDATE " . $xoopsDB->prefix("banner") . " SET clicks=clicks+1 WHERE bid=$bid"); header('Location: ' . $clickurl); } else { //No valid referer found so some javascript error or direct access found echo _BANNERS_NO_REFERER; } exit(); } } redirect_header(XOOPS_URL, 3, _BANNERS_NO_ID); exit(); } $op = ''; if (!empty($_POST['op'])) { $op = $_POST['op']; } else if (!empty($_GET['op'])) { $op = $_GET['op']; } $myts =& MyTextSanitizer::getInstance(); switch ($op) { case "click": $bid = 0; if (!empty($_GET['bid'])) { $bid = intval($_GET['bid']); } clickbanner($bid); break; case "Ok": if ($_SERVER['REQUEST_METHOD'] == 'POST') { if (!$GLOBALS['xoopsSecurity']->check(true, false, "BANNER_LOGIN")) { redirect_header("banners.php", 3, implode('
', $GLOBALS['xoopsSecurity']->getErrors())); exit(); } $_SESSION['banner_login'] = $myts->stripslashesGPC(trim($_POST['login'])); $_SESSION['banner_pass'] = $myts->stripslashesGPC(trim($_POST['pass'])); } bannerstats(); break; case _BANNERS_CHANGE: if (!$GLOBALS['xoopsSecurity']->check(true, false, "BANNER_EDIT")) { redirect_header("banners.php", 3, implode('
', $GLOBALS['xoopsSecurity']->getErrors())); exit(); } $bid = $cid = 0; if (!empty($_POST['url'])) { $url = $myts->stripslashesGPC(trim($_POST['url'])); } if (!empty($_POST['bid'])) { $bid = intval($_POST['bid']); } if (!empty($_POST['cid'])) { $cid = intval($_POST['cid']); } change_banner_url_by_client($cid, $bid, $url); break; case "EmailStats": $bid = $cid = 0; if (!empty($_GET['bid'])) { $bid = intval($_GET['bid']); } if (!empty($_GET['cid'])) { $cid = intval($_GET['cid']); } EmailStats($cid, $bid); break; case "login": default: clientlogin(); break; } ?>