source: temp/test-xoops.ec-cube.net/html/banners.php @ 405

Revision 405, 17.8 KB checked in by root, 20 years ago (diff)
Line 
1<?php
2// $Id: banners.php,v 1.4 2005/08/03 12:39:11 onokazu Exp $
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
28include "mainfile.php";
29
30/********************************************/
31/* Function to let your client login to see */
32/* the stats                                */
33/********************************************/
34function clientlogin()
35{
36    global $xoopsDB, $xoopsLogger, $xoopsConfig;
37    include("header.php");
38    echo "<style type='text/css'>
39                body {background-color : #fcfcfc;color: #000000;font-weight: normal;font-size: 12px;font-family: Trebuchet MS,Verdana, Arial, Helvetica, sans-serif;margin-left: 0px;margin-top: 0px;margin-right: 0px;margin-bottom: 0px;}
40                .redirect {width: 70%;margin: 110px;text-align: center;padding: 15px;text-align:center;border: #e0e0e0 1px solid;color: #666666;background-color: #f6f6f6;text-align: center;}
41                .redirect a:link {color: #666666;text-decoration: none;font-weight: bold;}
42                .redirect a:visited {color: #666666;text-decoration: none;font-weight: bold;}
43                .redirect a:hover {color: #999999;text-decoration: underline;font-weight: bold;}
44                hr {height: 3px;border: 3px #E18A00 solid;filter : Alpha(Opacity=100,FinishOpacity=10,Style=2);width: 95%;}
45                font.bigtext { font-size: 16px; font-weight: bold; }
46        </style>
47
48    <form action='banners.php' method='post'>
49    <table width='100%' class='redirect'>
50    <tr><td colspan='2' align='center'>
51    <b>Advertising Statistics</b><hr /></td></tr>
52    <tr><td align='right'><b>Login: </b></td>
53        <td><input class='textbox' type='text' name='login' size='12' maxlength='10' /></td></tr>
54    <tr><td align='right'><b>Password: </b></td>
55        <td><input class='textbox' type='password' name='pass' size='12' maxlength='10' /></td></tr>
56    <tr><td align='center' colspan='2'><input type='hidden' name='op' value='Ok' />";
57    $token =& XoopsMultiTokenHandler::quickCreate('banner_Ok');
58    echo $token->getHtml();
59    echo "
60        <input type='submit' value='Login' /></td></tr>
61    <tr><td colspan='2' align='center'><hr />Please type your client information</td></tr>
62    </table></form>";
63    include "footer.php";
64}
65
66/*********************************************/
67/* Function to display the banners stats for */
68/* each client                               */
69/*********************************************/
70function bannerstats($login, $pass)
71{
72    global $xoopsDB, $xoopsConfig, $xoopsLogger;
73    if ($login == "" || $pass == "") {
74        redirect_header("banners.php",2);
75        exit();
76    }
77    $result = $xoopsDB->query(sprintf("SELECT cid, name, passwd FROM %s WHERE login=%s", $xoopsDB->prefix("bannerclient"), $xoopsDB->quoteString($login)));
78    list($cid, $name, $passwd) = $xoopsDB->fetchRow($result);
79        if ( $pass==$passwd ) {
80            include "header.php";
81            echo "<style type='text/css'>
82                         .b_td {color: #ffffff; background-color: #2F5376; padding: 3px; text-align: center;}
83                  </style>
84            <h4 style='text-align:center;'><b>Current Active Banners for $name</b><br /></h4>
85            <table width='100%' border='0'><tr>
86                <td class='b_td'><b>ID</b></td>
87                <td class='b_td'><b>Imp. Made</b></td>
88                <td class='b_td'><b>Imp. Total</b></td>
89                <td class='b_td'><b>Imp. Left</b></td>
90                <td class='b_td'><b>Clicks</b></td>
91                <td class='b_td'><b>% Clicks</b></td>
92                <td class='b_td'><b>Functions</b></td></tr>";
93            $result = $xoopsDB->query("select bid, imptotal, impmade, clicks, date from ".$xoopsDB->prefix("banner")." where cid=$cid");
94            while ( list($bid, $imptotal, $impmade, $clicks, $date) = $xoopsDB->fetchRow($result) ) {
95                if ( $impmade == 0 ) {
96                    $percent = 0;
97                } else {
98                    $percent = substr(100 * $clicks / $impmade, 0, 5);
99                }
100                if ( $imptotal == 0 ) {
101                    $left = "Unlimited";
102                } else {
103                    $left = $imptotal-$impmade;
104                }
105                $token =& XoopsMultiTokenHandler::quickCreate('banner_EmailStats');
106                echo "<tr><td align='center'>$bid</td>
107                <td align='center'>$impmade</td>
108                <td align='center'>$imptotal</td>
109                <td align='center'>$left</td>
110                <td align='center'>$clicks</td>
111                <td align='center'>$percent%</td>
112                <td align='center'><a href='banners.php?op=EmailStats&amp;login=$login&amp;pass=$pass&amp;cid=$cid&amp;bid=$bid&amp;".$token->getUrl()."'>E-mail Stats</a></td></tr>";
113            }
114            echo "</table><br /><br /><div>Following are your running Banners in ".htmlspecialchars($xoopsConfig['sitename'])." </div><br /><br />";
115            $result = $xoopsDB->query("select bid, imageurl, clickurl, htmlbanner, htmlcode from ".$xoopsDB->prefix("banner")." where cid=$cid");
116            while ( list($bid, $imageurl, $clickurl,$htmlbanner, $htmlcode) = $xoopsDB->fetchRow($result) ) {
117                $numrows = $xoopsDB->getRowsNum($result);
118                if ($numrows>1) {
119                    echo "<hr /><br />";
120                }
121                if (!empty($htmlbanner) && !empty($htmlcode)){
122                    echo $myts->displayTarea($htmlcode);
123                }else{
124                    if(strtolower(substr($imageurl,strrpos($imageurl,".")))==".swf") {
125                        echo "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/ swflash.cab#version=6,0,40,0\"; width=\"468\" height=\"60\">";
126                        echo "<param name=movie value=\"$imageurl\" />";
127                        echo "<param name=quality value='high' />";
128                        echo "<embed src=\"$imageurl\" quality='high' pluginspage=\"http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash\"; type=\"application/x-shockwave-flash\" width=\"468\" height=\"60\">";
129                        echo "</embed>";
130                        echo "</object>";
131                    } else {
132                        echo "<img src='$imageurl' border='1' alt='' />";
133                    }
134                }
135                $token =& XoopsMultiTokenHandler::quickCreate('banner_EmailStats');
136                echo"Banner ID: $bid<br />
137                Send <a href='banners.php?op=EmailStats&amp;login=$login&amp;cid=$cid&amp;bid=$bid&amp;pass=$pass&amp;".$token->getUrl()."'>E-Mail Stats</a> for this Banner<br />";
138                if (!$htmlbanner){
139                    $token =& XoopsMultiTokenHandler::quickCreate('banner_Change');
140                    $clickurl = htmlspecialchars($clickurl, ENT_QUOTES);
141                    echo "This Banner points to <a href='$clickurl'>this URL</a><br />
142                    <form action='banners.php' method='post'>
143                    Change URL: <input class='textbox' type='text' name='url' size='50' maxlength='200' value='$clickurl' />
144                    <input class='textbox' type='hidden' name='login' value='$login' />
145                    <input class='textbox' type='hidden' name='bid' value='$bid' />
146                    <input class='textbox' type='hidden' name='pass' value='$pass' />
147                    <input class='textbox' type='hidden' name='cid' value='$cid' />
148                    <input type='submit' name='op' value='Change' />";
149                    echo $token->getHtml();
150                    echo "</form>";
151                }
152            }
153
154            /* Finnished Banners */
155            echo "<br />";
156            if(!$result = $xoopsDB->query("select bid, impressions, clicks, datestart, dateend from ".$xoopsDB->prefix("bannerfinish")." where cid=$cid")){
157            echo "<h4 style='text-align:center;'>Banners Finished for $name</h4><br />
158            <table width='100%' border='0'><tr>
159            <td class='b_td'><b>ID</b></td>
160            <td class='b_td'><b>Impressions</b></td>
161            <td class='b_td'><b>Clicks</b></td>
162            <td class='b_td'><b>% Clicks</b></td>
163            <td class='b_td'><b>Start Date</b></td>
164            <td class='b_td'><b>End Date</b></td></tr>";
165            while ( list($bid, $impressions, $clicks, $datestart, $dateend) = $xoopsDB->fetchRow($result) ) {
166                $percent = substr(100 * $clicks / $impressions, 0, 5);
167                echo "<tr><td align='center'>$bid</td>
168                <td align='center'>$impressions</td>
169                <td align='center'>$clicks</td>
170                <td align='center'>$percent%</td>
171                <td align='center'>".formatTimestamp($datestart)."</td>
172                <td align='center'>".formatTimestamp($dateend)."</td></tr>";
173            }
174            echo "</table>";
175            }
176            include "footer.php";
177        } else {
178            redirect_header("banners.php",2);
179            exit();
180        }
181}
182
183/*********************************************/
184/* Function to let the client E-mail his     */
185/* banner Stats                              */
186/*********************************************/
187function EmailStats($login, $cid, $bid, $pass)
188{
189    global $xoopsDB, $xoopsConfig;
190    if ($login != "" && $pass != "") {
191        $cid = intval($cid);
192        $bid = intval($bid);
193        if ($result2 = $xoopsDB->query(sprintf("select name, email, passwd from %s where cid=%u AND login=%s", $xoopsDB->prefix("bannerclient"), $cid, $xoopsDB->quoteString($login)))) {
194            list($name, $email, $passwd) = $xoopsDB->fetchRow($result2);
195            if ($pass == $passwd) {
196                if ($email == "") {
197                    redirect_header("banners.php",3,"There isn't an email associated with client ".$name.".<br />Please contact the Administrator");
198                    exit();
199                } else {
200                    if ($result = $xoopsDB->query("select bid, imptotal, impmade, clicks, imageurl, clickurl, date from ".$xoopsDB->prefix("banner")." where bid=$bid and cid=$cid")) {
201                        list($bid, $imptotal, $impmade, $clicks, $imageurl, $clickurl, $date) = $xoopsDB->fetchRow($result);
202                        if ( $impmade == 0 ) {
203                            $percent = 0;
204                        } else {
205                            $percent = substr(100 * $clicks / $impmade, 0, 5);
206                        }
207                        if ( $imptotal == 0 ) {
208                            $left = "Unlimited";
209                            $imptotal = "Unlimited";
210                        } else {
211                            $left = $imptotal-$impmade;
212                        }
213                        $fecha = date("F jS Y, h:iA.");
214                        $subject = "Your Banner Statistics at ".$xoopsConfig['sitename'];
215                        $message = "Following are the complete stats for your advertising investment at ". $xoopsConfig['sitename']." :\n\n\nClient Name: $name\nBanner ID: $bid\nBanner Image: $imageurl\nBanner URL: $clickurl\n\nImpressions Purchased: $imptotal\nImpressions Made: $impmade\nImpressions Left: $left\nClicks Received: $clicks\nClicks Percent: $percent%\n\n\nReport Generated on: $fecha";
216                        $xoopsMailer =& getMailer();
217                        $xoopsMailer->useMail();
218                        $xoopsMailer->setToEmails($email);
219                        $xoopsMailer->setFromEmail($xoopsConfig['adminmail']);
220                        $xoopsMailer->setFromName($xoopsConfig['sitename']);
221                        $xoopsMailer->setSubject($subject);
222                        $xoopsMailer->setBody($message);
223                        $xoopsMailer->send();
224                        $token =& XoopsMultiTokenHandler::quickCreate('banner_Ok');
225                        redirect_header("banners.php?op=Ok&amp;login=$login&amp;pass=$pass&amp;".$token->getUrl(), 3, "Statistics for your banner has been sent to your email address.");
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/*********************************************/
240function change_banner_url_by_client($login, $pass, $cid, $bid, $url)
241{
242    global $xoopsDB;
243    if ($login != "" && $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($login));
247        if ($result = $xoopsDB->query($sql)) {
248            list($passwd) = $xoopsDB->fetchRow($result);
249            if ( $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                    $token =& XoopsMultiTokenHandler::quickCreate('banner_Ok');
253                    redirect_header("banners.php?op=Ok&amp;login=$login&amp;pass=$pass&amp;".$token->getUrl(), 3, "URL has been changed.");
254                    exit();
255                }
256            }
257        }
258    }
259    redirect_header("banners.php",2);
260    exit();
261}
262
263function clickbanner($bid)
264{
265    global $xoopsDB;
266    if (is_int($bid) && $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 = '';
278if (!empty($_POST['op'])) {
279  $op = $_POST['op'];
280} elseif (!empty($_GET['op'])) {
281  $op = $_GET['op'];
282}
283$myts =& MyTextSanitizer::getInstance();
284switch ( $op ) {
285case "click":
286    $bid = 0;
287    if (!empty($_GET['bid'])) {
288        $bid = intval($_GET['bid']);
289    }
290    clickbanner($bid);
291    break;
292case "login":
293    clientlogin();
294    break;
295case "Ok":
296    if (!XoopsMultiTokenHandler::quickValidate('banner_Ok')) {
297        redirect_header("banners.php");
298        exit();
299    }
300    $login = $pass = '';
301    if (!empty($_GET['login'])) {
302        $login = $myts->stripslashesGPC(trim($_GET['login']));
303    }
304    if (!empty($_GET['pass'])) {
305        $pass = $myts->stripslashesGPC(trim($_GET['pass']));
306    }
307    if (!empty($_POST['login'])) {
308        $login = $myts->stripslashesGPC(trim($_POST['login']));
309    }
310    if (!empty($_POST['pass'])) {
311        $pass = $myts->stripslashesGPC(trim($_POST['pass']));
312    }
313    bannerstats($login, $pass);
314    break;
315case "Change":
316    if (!XoopsMultiTokenHandler::quickValidate('banner_Change')) {
317        redirect_header("banners.php");
318        exit();
319    }
320    $login = $pass = $url = '';
321    $bid = $cid = 0;
322    if (!empty($_POST['login'])) {
323        $login = $myts->stripslashesGPC(trim($_POST['login']));
324    }
325    if (!empty($_POST['pass'])) {
326        $pass = $myts->stripslashesGPC(trim($_POST['pass']));
327    }
328    if (!empty($_POST['url'])) {
329        $url = $myts->stripslashesGPC(trim($_POST['url']));
330    }
331    if (!empty($_POST['bid'])) {
332        $bid = intval($_POST['bid']);
333    }
334    if (!empty($_POST['cid'])) {
335        $cid = intval($_POST['cid']);
336    }
337    change_banner_url_by_client($login, $pass, $cid, $bid, $url);
338    break;
339case "EmailStats":
340    if (!XoopsMultiTokenHandler::quickValidate('banner_EmailStats')) {
341        redirect_header("banners.php");
342        exit();
343    }
344    $login = $pass = '';
345    $bid = $cid = 0;
346    if (!empty($_GET['login'])) {
347        $login = $myts->stripslashesGPC(trim($_GET['login']));
348    }
349    if (!empty($_GET['pass'])) {
350        $pass = $myts->stripslashesGPC(trim($_GET['pass']));
351    }
352    if (!empty($_GET['bid'])) {
353        $bid = intval($_GET['bid']);
354    }
355    if (!empty($_GET['cid'])) {
356        $cid = intval($_GET['cid']);
357    }
358    EmailStats($login, $cid, $bid, $pass);
359    break;
360default:
361    clientlogin();
362    break;
363}
364
365?>
Note: See TracBrowser for help on using the repository browser.