home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / CMS / xoops-2.0.18.1.exe / xoops-2.0.18.1 / htdocs / banners.php < prev    next >
Encoding:
PHP Script  |  2008-01-28  |  16.0 KB  |  337 lines

  1. <?php
  2. // $Id: banners.php 1280 2008-01-28 07:53:42Z phppp $
  3. //  ------------------------------------------------------------------------ //
  4. //                XOOPS - PHP Content Management System                      //
  5. //                    Copyright (c) 2000 XOOPS.org                           //
  6. //                       <http://www.xoops.org/>                             //
  7. //  ------------------------------------------------------------------------ //
  8. //  This program is free software; you can redistribute it and/or modify     //
  9. //  it under the terms of the GNU General Public License as published by     //
  10. //  the Free Software Foundation; either version 2 of the License, or        //
  11. //  (at your option) any later version.                                      //
  12. //                                                                           //
  13. //  You may not change or alter any portion of this comment or credits       //
  14. //  of supporting developers from this source code or any supporting         //
  15. //  source code which is considered copyrighted (c) material of the          //
  16. //  original comment or credit authors.                                      //
  17. //                                                                           //
  18. //  This program is distributed in the hope that it will be useful,          //
  19. //  but WITHOUT ANY WARRANTY; without even the implied warranty of           //
  20. //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
  21. //  GNU General Public License for more details.                             //
  22. //                                                                           //
  23. //  You should have received a copy of the GNU General Public License        //
  24. //  along with this program; if not, write to the Free Software              //
  25. //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
  26. //  ------------------------------------------------------------------------ //
  27.  
  28. $xoopsOption['pagetype'] = "banners";
  29.  
  30. include "mainfile.php";
  31.  
  32. /********************************************/
  33. /* Function to let your client login to see */
  34. /* the stats                                */
  35. /********************************************/
  36. function clientlogin()
  37. {
  38.     global $xoopsDB, $xoopsLogger, $xoopsConfig;
  39.     include("header.php");
  40.     echo "<div id='login_window'>
  41.           <h2 class='content_title'>"._BANNERS_LOGIN_TITLE."</h2>
  42.           <form method='post' action='banners.php' class='login_form'>
  43.           <div class='credentials'>
  44.           <label for='login_form-login'>"._BANNERS_LOGIN_LOGIN."</label>
  45.           <input type='text' name='login' id='login_form-login' value='' /><br />
  46.           <label for='login_form-password'>"._BANNERS_LOGIN_PASS."</label>
  47.           <input type='password' name='pass' id='login_form-password' value='' /><br />
  48.           </div>
  49.           <div class='actions'><input type='hidden' name='op' value='Ok' /><button type='submit'>"._BANNERS_LOGIN_OK."</button></div>
  50.           <div class='login_info'>"._BANNERS_LOGIN_INFO."</div>".
  51.           $GLOBALS['xoopsSecurity']->getTokenHTML("BANNER_LOGIN")."
  52.           </form></div>";
  53.     include "footer.php";
  54. }
  55.  
  56. /*********************************************/
  57. /* Function to display the banners stats for */
  58. /* each client                               */
  59. /*********************************************/
  60. function bannerstats()
  61. {
  62.     global $xoopsDB, $xoopsConfig, $xoopsLogger;
  63.     if ($_SESSION['banner_login'] == "" || $_SESSION['banner_pass'] == "") {
  64.         redirect_header("banners.php", 2, 'No login data detected');
  65.         exit();
  66.     }
  67.     $result = $xoopsDB->query(sprintf("SELECT cid, name, passwd FROM %s WHERE login=%s", $xoopsDB->prefix("bannerclient"), $xoopsDB->quoteString($_SESSION['banner_login'])));
  68.     list($cid, $name, $passwd) = $xoopsDB->fetchRow($result);
  69.         if ( $_SESSION['banner_pass'] == $passwd ) {
  70.             include "header.php";
  71.  
  72.             echo "<div id='bannerstats'>
  73.                   <h4 class='content_title'>".sprintf( _BANNERS_TITLE , $name )."</h4><hr />
  74.                   <table summary=''>
  75.                   <caption>".sprintf( _BANNERS_TITLE , $name )."</caption>
  76.                   <thead><tr>
  77.                   <td>ID</td>
  78.                   <td>"._BANNERS_IMP_MADE."</td>
  79.                   <td>"._BANNERS_IMP_TOTAL."</td>
  80.                   <td>"._BANNERS_IMP_LEFT."</td>
  81.                   <td>"._BANNERS_CLICKS."</td>
  82.                   <td>"._BANNERS_PER_CLICKS."</td>
  83.                   <td>"._BANNERS_FUNCTIONS."</td></tr></thead>
  84.                   <tfoot><tr><td colspan='7'></td></tr></tfoot>";
  85.  
  86.             $result = $xoopsDB->query("select bid, imptotal, impmade, clicks, date from ".$xoopsDB->prefix("banner")." where cid=$cid");
  87.             $i = 0;
  88.             while ( list($bid, $imptotal, $impmade, $clicks, $date) = $xoopsDB->fetchRow($result) ) {
  89.                 if ( $impmade == 0 ) {
  90.                     $percent = 0;
  91.                 } else {
  92.                     $percent = substr(100 * $clicks / $impmade, 0, 5);
  93.                 }
  94.                 if ( $imptotal == 0 ) {
  95.                     $left = _BANNERS_UNLIMITED;
  96.                 } else {
  97.                     $left = $imptotal-$impmade;
  98.                 }
  99.                 $class = ($i % 2 == 0) ? 'even' : 'odd';
  100.                 echo "<tbody><tr class='$class'>
  101.                       <td>$bid</td>
  102.                       <td>$impmade</td>
  103.                       <td>$imptotal</td>
  104.                       <td>$left</td>
  105.                       <td>$clicks</td>
  106.                       <td>$percent%</td>
  107.                       <td><a href='banners.php?op=EmailStats&cid=$cid&bid=$bid' title='" . _BANNERS_STATS . "'>" . _BANNERS_STATS . "</a></td></tr></tbody>";
  108.                 $i++;
  109.             }
  110.             echo "</table>
  111.                   <br /><br />
  112.                   <h4 class='content_title'>". _BANNERS_FOW_IN . htmlspecialchars( $xoopsConfig['sitename'] ). "</h4><hr />";
  113.  
  114.             $result = $xoopsDB->query("select bid, imageurl, clickurl, htmlbanner, htmlcode from ".$xoopsDB->prefix("banner")." where cid=$cid");
  115.             while ( list($bid, $imageurl, $clickurl,$htmlbanner, $htmlcode) = $xoopsDB->fetchRow($result) ) {
  116.                 $numrows = $xoopsDB->getRowsNum($result);
  117.                 if ($numrows>1) {
  118.                     echo "<br />";
  119.                 }
  120.                 if (!empty($htmlbanner) && !empty($htmlcode)){
  121.                     echo $myts->displayTarea($htmlcode);
  122.                 }else{
  123.                     if(strtolower(substr($imageurl,strrpos($imageurl,".")))==".swf") {
  124.                         echo "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0\" width=\"468\" height=\"60\">";
  125.                         echo "<param name=movie value=\"$imageurl\" />";
  126.                         echo "<param name=quality value='high' />";
  127.                         echo "<embed src=\"$imageurl\" quality='high' pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" width=\"468\" height=\"60\">";
  128.                         echo "</embed>";
  129.                         echo "</object>";
  130.                     } else {
  131.                         echo "<img src='$imageurl' alt='' />";
  132.                     }
  133.                 }
  134.                 echo "<br /><strong>" . _BANNERS_ID . $bid . "</strong><br />" .
  135.                 sprintf(_BANNERS_SEND_STATS, 'banners.php?op=EmailStats&cid='.$cid.'&bid='.$bid) . "<br />";
  136.                 if (!$htmlbanner){
  137.                     $clickurl = htmlspecialchars($clickurl, ENT_QUOTES);
  138.                     echo sprintf(_BANNERS_POINTS, $clickurl) . "<br />
  139.                     <form action='banners.php' method='post'>". _BANNERS_URL . "
  140.                     <input type='text' name='url' size='50' maxlength='200' value='$clickurl' />
  141.                     <input type='hidden' name='bid' value='$bid' />
  142.                     <input type='hidden' name='cid' value='$cid' />
  143.                     <input type='submit' name='op' value='". _BANNERS_CHANGE ."' />" .
  144.                     $GLOBALS['xoopsSecurity']->getTokenHTML("BANNER_EDIT") . "</form>";
  145.                 }
  146.             }
  147.  
  148.             /* Finnished Banners */
  149.             echo "<br />";
  150.             if($result = $xoopsDB->query("select bid, impressions, clicks, datestart, dateend from ".$xoopsDB->prefix("bannerfinish")." where cid=$cid")){
  151.                 echo "<h4 class='content_title'>" . sprintf(_BANNERS_FINISHED, $name) . "</h4><hr />
  152.                       <table summary=''>
  153.                       <caption>" . sprintf(_BANNERS_FINISHED, $name) . "</caption>
  154.                       <thead><tr>
  155.                       <td>ID</td>
  156.                       <td>"._BANNERS_IMP_MADE."</td>
  157.                       <td>"._BANNERS_CLICKS."</td>
  158.                       <td>"._BANNERS_PER_CLICKS."</td>
  159.                       <td>"._BANNERS_STARTED."</td>
  160.                       <td>"._BANNERS_ENDED."</td></tr></thead>
  161.                       <tfoot><tr><td colspan='6'></td></tr></tfoot>";
  162.  
  163.                 $i=0;
  164.                 while ( list($bid, $impressions, $clicks, $datestart, $dateend) = $xoopsDB->fetchRow($result) ) {
  165.                     $percent = substr(100 * $clicks / $impressions, 0, 5);
  166.                     $class = ($i % 2 == 0) ? 'even' : 'odd';
  167.                     echo "<tbody><tr class='$class'>
  168.                           <td>$bid</td>
  169.                           <td>$impressions</td>
  170.                           <td>$clicks</td>
  171.                           <td>$percent%</td>
  172.                           <td>".formatTimestamp($datestart)."</td>
  173.                           <td>".formatTimestamp($dateend)."</td></tr></tbody>";
  174.                 }
  175.                 echo "</table></div>";
  176.             }
  177.             include "footer.php";
  178.         } else {
  179.             redirect_header("banners.php",2);
  180.             exit();
  181.         }
  182. }
  183.  
  184. /*********************************************/
  185. /* Function to let the client E-mail his     */
  186. /* banner Stats                              */
  187. /*********************************************/
  188. function EmailStats($cid, $bid)
  189. {
  190.     global $xoopsDB, $xoopsConfig;
  191.     if ($_SESSION['banner_login'] != "" && $_SESSION['banner_pass'] != "") {
  192.         $cid = intval($cid);
  193.         $bid = intval($bid);
  194.         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'])))) {
  195.             list($name, $email, $passwd) = $xoopsDB->fetchRow($result2);
  196.             if ($_SESSION['banner_pass'] == $passwd) {
  197.                 if ($email == "") {
  198.                     redirect_header("banners.php", 3, sprintf( _BANNERS_MAIL_ERROR, $name) );
  199.                     exit();
  200.                 } else {
  201.                     if ($result = $xoopsDB->query("select bid, imptotal, impmade, clicks, imageurl, clickurl, date from ".$xoopsDB->prefix("banner")." where bid=$bid and cid=$cid")) {
  202.                         list($bid, $imptotal, $impmade, $clicks, $imageurl, $clickurl, $date) = $xoopsDB->fetchRow($result);
  203.                         if ( $impmade == 0 ) {
  204.                             $percent = 0;
  205.                         } else {
  206.                             $percent = substr(100 * $clicks / $impmade, 0, 5);
  207.                         }
  208.                         if ( $imptotal == 0 ) {
  209.                             $left = _BANNERS_UNLIMITED;
  210.                             $imptotal = _BANNERS_UNLIMITED;
  211.                         } else {
  212.                             $left = $imptotal-$impmade;
  213.                         }
  214.                         $fecha = date("F jS Y, h:iA.");
  215.                         $subject = sprintf(_BANNERS_MAIL_SUBJECT , $xoopsConfig['sitename'] );
  216.                         $message = sprintf(_BANNERS_MAIL_MESSAGE , $xoopsConfig['sitename'], $name, $bid, $imageurl, $clickurl, $imptotal, $impmade, $left, $clicks, $percent, $fecha);
  217.                         $xoopsMailer =& getMailer();
  218.                         $xoopsMailer->useMail();
  219.                         $xoopsMailer->setToEmails($email);
  220.                         $xoopsMailer->setFromEmail($xoopsConfig['adminmail']);
  221.                         $xoopsMailer->setFromName($xoopsConfig['sitename']);
  222.                         $xoopsMailer->setSubject($subject);
  223.                         $xoopsMailer->setBody($message);
  224.                         $xoopsMailer->send();
  225.                         redirect_header("banners.php?op=Ok", 3, _BANNERS_MAIL_OK);
  226.                         exit();
  227.                     }
  228.                 }
  229.             }
  230.         }
  231.     }
  232.     redirect_header("banners.php",2);
  233.     exit();
  234. }
  235.  
  236. /*********************************************/
  237. /* Function to let the client to change the  */
  238. /* url for his banner                        */
  239. /*********************************************/
  240. function change_banner_url_by_client($cid, $bid, $url)
  241. {
  242.     global $xoopsDB;
  243.     if ($_SESSION['banner_login'] != "" && $_SESSION['banner_pass'] != "" && $url != "") {
  244.         $cid = intval($cid);
  245.         $bid = intval($bid);
  246.         $sql = sprintf("select passwd from %s where cid=%u and login=%s", $xoopsDB->prefix("bannerclient"), $cid, $xoopsDB->quoteString($_SESSION['banner_login']));
  247.         if ($result = $xoopsDB->query($sql)) {
  248.             list($passwd) = $xoopsDB->fetchRow($result);
  249.             if ( $_SESSION['banner_pass'] == $passwd ) {
  250.                 $sql = sprintf("update %s set clickurl=%s where bid=%u AND cid=%u", $xoopsDB->prefix("banner"), $xoopsDB->quoteString($url), $bid, $cid);
  251.                 if ($xoopsDB->query($sql)) {
  252.                     redirect_header("banners.php?op=Ok", 3, "URL has been changed.");
  253.                     exit();
  254.                 }
  255.             }
  256.         }
  257.     }
  258.     redirect_header("banners.php",2);
  259.     exit();
  260. }
  261.  
  262. function clickbanner($bid)
  263. {
  264.     global $xoopsDB;
  265.     $bid = intval($bid);
  266.     if ($bid > 0) {
  267.         if (xoops_refcheck()) {
  268.             if ($bresult = $xoopsDB->query("select clickurl from ".$xoopsDB->prefix("banner")." where bid=$bid")) {
  269.                 list($clickurl) = $xoopsDB->fetchRow($bresult);
  270.                 $xoopsDB->queryF("update ".$xoopsDB->prefix("banner")." set clicks=clicks+1 where bid=$bid");
  271.                 header ('Location: '.$clickurl);
  272.             }
  273.         }
  274.     }
  275.     exit();
  276. }
  277. $op = '';
  278. if (!empty($_POST['op'])) {
  279.   $op = $_POST['op'];
  280. } elseif (!empty($_GET['op'])) {
  281.   $op = $_GET['op'];
  282. }
  283. $myts =& MyTextSanitizer::getInstance();
  284. switch ( $op ) {
  285. case "click":
  286.     $bid = 0;
  287.     if (!empty($_GET['bid'])) {
  288.         $bid = intval($_GET['bid']);
  289.     }
  290.     clickbanner($bid);
  291.     break;
  292. case "Ok":
  293.     if ( $_SERVER['REQUEST_METHOD'] == 'POST' ) {
  294.         if ( !$GLOBALS['xoopsSecurity']->check(true, false, "BANNER_LOGIN") ) {
  295.             redirect_header("banners.php", 3, implode('<br />', $GLOBALS['xoopsSecurity']->getErrors()));
  296.             exit();
  297.         }
  298.  
  299.         $_SESSION['banner_login'] = $myts->stripslashesGPC(trim($_POST['login']));
  300.         $_SESSION['banner_pass'] = $myts->stripslashesGPC(trim($_POST['pass']));
  301.     }
  302.     bannerstats();
  303.     break;
  304. case _BANNERS_CHANGE:
  305.     if (!$GLOBALS['xoopsSecurity']->check(true, false, "BANNER_EDIT")) {
  306.         redirect_header("banners.php", 3, implode('<br />', $GLOBALS['xoopsSecurity']->getErrors()));
  307.         exit();
  308.     }
  309.     $bid = $cid = 0;
  310.     if (!empty($_POST['url'])) {
  311.         $url = $myts->stripslashesGPC(trim($_POST['url']));
  312.     }
  313.     if (!empty($_POST['bid'])) {
  314.         $bid = intval($_POST['bid']);
  315.     }
  316.     if (!empty($_POST['cid'])) {
  317.         $cid = intval($_POST['cid']);
  318.     }
  319.     change_banner_url_by_client($cid, $bid, $url);
  320.     break;
  321. case "EmailStats":
  322.     $bid = $cid = 0;
  323.     if (!empty($_GET['bid'])) {
  324.         $bid = intval($_GET['bid']);
  325.     }
  326.     if (!empty($_GET['cid'])) {
  327.         $cid = intval($_GET['cid']);
  328.     }
  329.     EmailStats($cid, $bid);
  330.     break;
  331. case "login":
  332. default:
  333.     clientlogin();
  334.     break;
  335. }
  336.  
  337. ?>