XCL Web Application Platform 2.5.0
The XoopsCube Legacy Project
Loading...
Searching...
No Matches
banners.php
1<?php
13
14include 'mainfile.php';
23function clientlogin()
24{
25 global $xoopsDB, $xoopsLogger, $xoopsConfig;
26 include('header.php');
27 echo "<style>
28 .redirect {width: 70%;margin: 110px;text-align: center;padding: 15px;text-align:center;text-align: center;}
29 .redirect a:link {text-decoration: none;font-weight: bold;}
30 .redirect a:visited {text-decoration: none;font-weight: bold;}
31 .redirect a:hover {text-decoration: underline;font-weight: bold;}
32 </style>
33
34 <form action='banners.php' method='post'>
35 <article>
36 <header>
37 <div class='headings'>
38 <h3>Advertising Statistics</h3>
39 <p>Please type your client information</p>
40 </div>
41 </header>
42 <label>Login
43 <input class='textbox' type='text' name='login' size='12' maxlength='10'>
44 </label>
45 <label>Password
46 <input class='textbox' type='password' name='pass' size='12' maxlength='10'>
47 </label>
48 <input type='hidden' name='op' value='Ok'>";
49 $token =& XoopsMultiTokenHandler::quickCreate('banner_Ok');
50 echo $token->getHtml();
51 echo "
52 <footer><input type='submit' value='Login'></footer>
53 </article></form>";
54 include 'footer.php';
55}
56
57/*********************************************/
58/* Function to display the banners stats for */
59/* each client */
60/*********************************************/
61function bannerstats($login, $pass)
62{
63 global $xoopsDB, $xoopsConfig, $xoopsLogger;
64 if ('' == $login || '' == $pass) {
65 redirect_header('banners.php', 2);
66 exit();
67 }
68
69 // Sanitize Textarea HTML
70 $myts =& MyTextSanitizer::getInstance();
71
72 $result = $xoopsDB->query(sprintf('SELECT cid, name, passwd FROM %s WHERE login=%s', $xoopsDB->prefix('bannerclient'), $xoopsDB->quoteString($login)));
73 list($cid, $name, $passwd) = $xoopsDB->fetchRow($result);
74 if ($pass==$passwd) {
75 include 'header.php';
76 echo "
77 <h4>Current Active Banners for $name</h4>
78 <table>
79 <thead>
80 <tr class='list_center'>
81 <th class='list_id'>ID</th>
82 <th class='list_center'>Imp. Made</th>
83 <th class='b_td'>Imp. Total</th>
84 <th class='b_td'><b>Imp. Left</th>
85 <th class='b_td'><b>Clicks</th>
86 <th class='b_td'><b>% Clicks</th>
87 <th class='list-action'>Action</th>
88 </tr></thead>";
89 $result = $xoopsDB->query('select bid, imptotal, impmade, clicks, date from ' . $xoopsDB->prefix('banner') . " where cid=$cid");
90 while (list($bid, $imptotal, $impmade, $clicks, $date) = $xoopsDB->fetchRow($result)) {
91 if (0 == $impmade) {
92 $percent = 0;
93 } else {
94 $percent = substr(100 * $clicks / $impmade, 0, 5);
95 }
96 if (0 == $imptotal) {
97 $left = 'Unlimited';
98 } else {
99 $left = $imptotal-$impmade;
100 }
101 $token =& XoopsMultiTokenHandler::quickCreate('banner_EmailStats');
102 echo "<tr class='list_center'>
103 <td>$bid</td>
104 <td>$impmade</td>
105 <td>$imptotal</td>
106 <td>$left</td>
107 <td>$clicks</td>
108 <td>$percent%</td>
109 <td><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>
110 </tr>";
111 }
112 echo '</table>'
113 .'<hr><div>Following are your running Banners in ' . htmlspecialchars($xoopsConfig['sitename']) . ' </div>';
114
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>';
120 }
121 if (!empty($htmlbanner) && !empty($htmlcode)) {
122 // Sanitize Textarea HTML
123 $bannerHtml = $myts->displayTarea( $htmlcode );
124 echo "<pre><code>".$bannerHtml."</code></pre>";
125
126 } else {
127 if ('.swf' == strtolower(substr($imageurl, strrpos($imageurl, '.')))) {
128 echo '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="https://download.macromedia.com/pub/shockwave/cabs/flash/ swflash.cab#version=6,0,40,0"; width="468" height="60">';
129 echo "<param name=movie value=\"$imageurl\" />";
130 echo "<param name=quality value='high' />";
131 echo "<embed src=\"$imageurl\" quality='high' pluginspage=\"https://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash\"; type=\"application/x-shockwave-flash\" width=\"468\" height=\"60\">";
132 echo '</embed>';
133 echo '</object>';
134 } else {
135 echo "<img src='$imageurl' border='1' alt=''>";
136 }
137 }
138 $token =& XoopsMultiTokenHandler::quickCreate('banner_EmailStats');
139 echo"Banner ID: $bid<br>
140 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>";
141 if (!$htmlbanner) {
142 $token =& XoopsMultiTokenHandler::quickCreate('banner_Change');
143 $clickurl = htmlspecialchars($clickurl, ENT_QUOTES);
144 echo "This Banner points to <a href='$clickurl'>this URL</a><br>
145 <form action='banners.php' method='post'>
146 Change URL: <input class='textbox' type='text' name='url' size='50' maxlength='200' value='$clickurl'>
147 <input class='textbox' type='hidden' name='login' value='$login'>
148 <input class='textbox' type='hidden' name='bid' value='$bid'>
149 <input class='textbox' type='hidden' name='pass' value='$pass'>
150 <input class='textbox' type='hidden' name='cid' value='$cid'>
151 <input type='submit' name='op' value='Change'>";
152 echo $token->getHtml();
153 echo '</form>';
154 }
155 }
156
157 /* Finnished Banners */
158 echo '<br>';
159 if (!$result = $xoopsDB->query('select bid, impressions, clicks, datestart, dateend from ' . $xoopsDB->prefix('bannerfinish') . " where cid=$cid")) {
160 echo "<h4 style='text-align:center;'>Banners Finished for $name</h4><br>
161 <table><tr>
162 <td>ID</td>
163 <td>Impressions</td>
164 <td>Clicks</td>
165 <td>% Clicks</td>
166 <td>Start Date</td>
167 <td>End Date</td></tr>";
168 while (list($bid, $impressions, $clicks, $datestart, $dateend) = $xoopsDB->fetchRow($result)) {
169 $percent = substr(100 * $clicks / $impressions, 0, 5);
170 echo "<tr>
171 <td>$bid</td>
172 <td>$impressions</td>
173 <td>$clicks</td>
174 <td>$percent%</td>
175 <td>".formatTimestamp($datestart)."</td>
176 <td>".formatTimestamp($dateend) . '</td></tr>';
177 }
178 echo '</table>';
179 }
180 include 'footer.php';
181 } else {
182 redirect_header('banners.php', 2);
183 exit();
184 }
185}
186
187/*********************************************/
188/* Function to let the client E-mail his */
189/* banner Stats */
190/*********************************************/
191function EmailStats($login, $cid, $bid, $pass)
192{
193 global $xoopsDB, $xoopsConfig;
194 if ('' != $login && '' != $pass) {
195 $cid = (int)$cid;
196 $bid = (int)$bid;
197 if ($result2 = $xoopsDB->query(sprintf('select name, email, passwd from %s where cid=%u AND login=%s', $xoopsDB->prefix('bannerclient'), $cid, $xoopsDB->quoteString($login)))) {
198 list($name, $email, $passwd) = $xoopsDB->fetchRow($result2);
199 if ($pass == $passwd) {
200 if ('' == $email) {
201 redirect_header('banners.php', 2, "There isn't an email associated with client " . $name . '.<br>Please contact the Administrator');
202 exit();
203 } else {
204 if ($result = $xoopsDB->query('select bid, imptotal, impmade, clicks, imageurl, clickurl, date from ' . $xoopsDB->prefix('banner') . " where bid=$bid and cid=$cid")) {
205 list($bid, $imptotal, $impmade, $clicks, $imageurl, $clickurl, $date) = $xoopsDB->fetchRow($result);
206 if (0 == $impmade) {
207 $percent = 0;
208 } else {
209 $percent = substr(100 * $clicks / $impmade, 0, 5);
210 }
211 if (0 == $imptotal) {
212 $left = 'Unlimited';
213 $imptotal = 'Unlimited';
214 } else {
215 $left = $imptotal-$impmade;
216 }
217 $fecha = date('F jS Y, h:iA.');
218 $subject = 'Your Banner Statistics at ' . $xoopsConfig['sitename'];
219 $message = 'Following are the complete stats for your advertising investment at '
220 . $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";
221 $xoopsMailer =& getMailer();
222 $xoopsMailer->useMail();
223 $xoopsMailer->setToEmails($email);
224 $xoopsMailer->setFromEmail($xoopsConfig['adminmail']);
225 $xoopsMailer->setFromName($xoopsConfig['sitename']);
226 $xoopsMailer->setSubject($subject);
227 $xoopsMailer->setBody($message);
228 $xoopsMailer->send();
229 $token =& XoopsMultiTokenHandler::quickCreate('banner_Ok');
230 redirect_header("banners.php?op=Ok&amp;login=$login&amp;pass=$pass&amp;".$token->getUrl(), 2, 'Statistics for your banner has been sent to your email address.');
231 exit();
232 }
233 }
234 }
235 }
236 }
237 redirect_header('banners.php', 2);
238 exit();
239}
240
241/*********************************************/
242/* Function to let the client change the */
243/* url for his banner */
244/*********************************************/
245function change_banner_url_by_client($login, $pass, $cid, $bid, $url)
246{
247 global $xoopsDB;
248 if ('' != $login && '' != $pass && '' != $url) {
249 $cid = (int)$cid;
250 $bid = (int)$bid;
251 $sql = sprintf('select passwd from %s where cid=%u and login=%s', $xoopsDB->prefix('bannerclient'), $cid, $xoopsDB->quoteString($login));
252 if ($result = $xoopsDB->query($sql)) {
253 list($passwd) = $xoopsDB->fetchRow($result);
254 if ($pass == $passwd) {
255 $sql = sprintf('update %s set clickurl=%s where bid=%u AND cid=%u', $xoopsDB->prefix('banner'), $xoopsDB->quoteString($url), $bid, $cid);
256 if ($xoopsDB->query($sql)) {
257 $token =& XoopsMultiTokenHandler::quickCreate('banner_Ok');
258 redirect_header("banners.php?op=Ok&amp;login=$login&amp;pass=$pass&amp;".$token->getUrl(), 2, 'URL has been changed.');
259 exit();
260 }
261 }
262 }
263 }
264 redirect_header('banners.php', 2);
265 exit();
266}
267
268function clickbanner($bid)
269{
270 global $xoopsDB;
271 if (is_int($bid) && $bid > 0) {
272 if (xoops_refcheck()) {
273 if ($bresult = $xoopsDB->query('select clickurl from ' . $xoopsDB->prefix('banner') . " where bid=$bid")) {
274 list($clickurl) = $xoopsDB->fetchRow($bresult);
275 $xoopsDB->queryF('update ' . $xoopsDB->prefix('banner') . " set clicks=clicks+1 where bid=$bid");
276 header('Location: '.$clickurl);
277 }
278 }
279 }
280 exit();
281}
282
283$op = '';
284if (!empty($_POST['op'])) {
285 $op = $_POST['op'];
286} elseif (!empty($_GET['op'])) {
287 $op = $_GET['op'];
288}
289
291
292switch ($op) {
293 case 'click':
294 $bid = 0;
295 if (!empty($_GET['bid'])) {
296 $bid = (int)$_GET['bid'];
297 }
298 clickbanner($bid);
299 break;
300 case 'login':
301 clientlogin();
302 break;
303 case 'Ok':
304 if (!XoopsMultiTokenHandler::quickValidate('banner_Ok')) {
305 redirect_header('banners.php');
306 exit();
307 }
308 $login = $pass = '';
309 if (!empty($_GET['login'])) {
310 $login = $myts->stripslashesGPC(trim($_GET['login']));
311 }
312 if (!empty($_GET['pass'])) {
313 $pass = $myts->stripslashesGPC(trim($_GET['pass']));
314 }
315 if (!empty($_POST['login'])) {
316 $login = $myts->stripslashesGPC(trim($_POST['login']));
317 }
318 if (!empty($_POST['pass'])) {
319 $pass = $myts->stripslashesGPC(trim($_POST['pass']));
320 }
321 bannerstats($login, $pass);
322 break;
323 case 'Change':
324 if (!XoopsMultiTokenHandler::quickValidate('banner_Change')) {
325 redirect_header('banners.php');
326 exit();
327 }
328 $login = $pass = $url = '';
329 $bid = $cid = 0;
330 if (!empty($_POST['login'])) {
331 $login = $myts->stripslashesGPC(trim($_POST['login']));
332 }
333 if (!empty($_POST['pass'])) {
334 $pass = $myts->stripslashesGPC(trim($_POST['pass']));
335 }
336 if (!empty($_POST['url'])) {
337 $url = $myts->stripslashesGPC(trim($_POST['url']));
338 }
339 if (!empty($_POST['bid'])) {
340 $bid = (int)$_POST['bid'];
341 }
342 if (!empty($_POST['cid'])) {
343 $cid = (int)$_POST['cid'];
344 }
345 change_banner_url_by_client($login, $pass, $cid, $bid, $url);
346 break;
347 case 'EmailStats':
348 if (!XoopsMultiTokenHandler::quickValidate('banner_EmailStats')) {
349 redirect_header('banners.php');
350 exit();
351 }
352 $login = $pass = '';
353 $bid = $cid = 0;
354 if (!empty($_GET['login'])) {
355 $login = $myts->stripslashesGPC(trim($_GET['login']));
356 }
357 if (!empty($_GET['pass'])) {
358 $pass = $myts->stripslashesGPC(trim($_GET['pass']));
359 }
360 if (!empty($_GET['bid'])) {
361 $bid = (int)$_GET['bid'];
362 }
363 if (!empty($_GET['cid'])) {
364 $cid = (int)$_GET['cid'];
365 }
366 EmailStats($login, $cid, $bid, $pass);
367 break;
368 default:
369 clientlogin();
370 break;
371}
static quickValidate($name, $clearIfValid=true)
Definition token.php:401
static & quickCreate($name, $timeout=XOOPS_TOKEN_TIMEOUT)
Definition token.php:385