XOOPS 2.5.6  Final
 All Classes Namespaces Files Functions Variables Pages
banners.php
Go to the documentation of this file.
1 <?php
22 $xoopsOption['pagetype'] = 'banners';
23 include dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mainfile.php';
24 
25 /********************************************/
26 /* Function to let your client login to see */
27 /* the stats */
28 /********************************************/
29 function clientlogin()
30 {
32  include 'header.php';
33  $GLOBALS["xoTheme"]->addStylesheet(null, null, '
34  #login_window {
35  max-width: 480px;
36  margin: 1em auto;
37  background-color: #f8f8f8;
38  color: inherit;
39  border: 1px solid #000;
40  }
41  #login_window h2 {
42  margin: .5em;
43  padding: 130px 0 0;
44  background: url( images/password.png) no-repeat center top;
45  text-align: center;
46  }
47  .login_form .credentials {
48  margin: .5em 1em;
49  padding: 1em;
50  background-color: #ccc;
51  color: inherit;
52  }
53  .login_form .credentials label {
54  display: inline-block;
55  width: 33%;
56  margin: 1px;
57  }
58  .login_form .credentials input {
59  width: 50%;
60  margin: 1px;
61  padding: 1px;
62  border: 1px solid #000;
63  }
64  .login_form .credentials input:focus {
65  border: 1px solid #2266cc;
66  }
67  .login_form .actions {
68  padding: 1.5em .5em .5em;
69  text-align: center;
70  }
71  .login_info {
72  margin: .5em 1em;
73  text-align: center;
74  }
75  .content_title {
76  font-size: 1.2em;
77  }
78  ');
79  echo "<div id='login_window'>
80  <h2 class='content_title'>" . _BANNERS_LOGIN_TITLE . "</h2>
81  <form method='post' action='banners.php' class='login_form'>
82  <div class='credentials'>
83  <label for='login_form-login'>" . _BANNERS_LOGIN_LOGIN . "</label>
84  <input type='text' name='login' id='login_form-login' value='' /><br />
85  <label for='login_form-password'>" . _BANNERS_LOGIN_PASS . "</label>
86  <input type='password' name='pass' id='login_form-password' value='' /><br />
87  </div>
88  <div class='actions'><input type='hidden' name='op' value='Ok' /><button type='submit'>" . _BANNERS_LOGIN_OK . "</button></div>
89  <div class='login_info'>" . _BANNERS_LOGIN_INFO . "</div>" . $GLOBALS['xoopsSecurity']->getTokenHTML("BANNER_LOGIN") . "
90  </form></div>";
91  include $GLOBALS['xoops']->path('footer.php');
92 }
93 
94 /*********************************************/
95 /* Function to display the banners stats for */
96 /* each client */
97 /*********************************************/
98 function bannerstats()
99 {
101  if ($_SESSION['banner_login'] == "" || $_SESSION['banner_pass'] == "") {
102  redirect_header("banners.php", 2, _BANNERS_NO_LOGIN_DATA);
103  exit();
104  }
105  $result = $xoopsDB->query(sprintf("SELECT cid, name, passwd FROM %s WHERE login=%s", $xoopsDB->prefix("bannerclient"), $xoopsDB->quoteString($_SESSION['banner_login'])));
106  list ($cid, $name, $passwd) = $xoopsDB->fetchRow($result);
107  if ($_SESSION['banner_pass'] == $passwd) {
108  include $GLOBALS['xoops']->path('header.php');
109  $GLOBALS["xoTheme"]->addStylesheet(null, null, '
110  #bannerstats {}
111  #bannerstats td {
112  text-align: center;
113  }
114  ');
115 
116  echo "<div id='bannerstats'>
117  <h4 class='content_title'>" . sprintf(_BANNERS_TITLE, $name) . "</h4><hr />
118  <table summary=''>
119  <caption>" . sprintf(_BANNERS_TITLE, $name) . "</caption>
120  <thead><tr>
121  <td>ID</td>
122  <td>" . _BANNERS_IMP_MADE . "</td>
123  <td>" . _BANNERS_IMP_TOTAL . "</td>
124  <td>" . _BANNERS_IMP_LEFT . "</td>
125  <td>" . _BANNERS_CLICKS . "</td>
126  <td>" . _BANNERS_PER_CLICKS . "</td>
127  <td>" . _BANNERS_FUNCTIONS . "</td></tr></thead>
128  <tfoot><tr><td colspan='7'></td></tr></tfoot>";
129 
130  $result = $xoopsDB->query("SELECT bid, imptotal, impmade, clicks, date FROM " . $xoopsDB->prefix("banner") . " WHERE cid={$cid}");
131  $i = 0;
132  while (list ($bid, $imptotal, $impmade, $clicks, $date) = $xoopsDB->fetchRow($result)) {
133  if ($impmade == 0) {
134  $percent = 0;
135  } else {
136  $percent = substr(100 * $clicks / $impmade, 0, 5);
137  }
138  if ($imptotal == 0) {
139  $left = _BANNERS_UNLIMITED;
140  } else {
141  $left = $imptotal - $impmade;
142  }
143  $class = ($i % 2 == 0) ? 'even' : 'odd';
144  echo "<tbody><tr class='{$class}'>
145  <td>{$bid}</td>
146  <td>{$impmade}</td>
147  <td>{$imptotal}</td>
148  <td>{$left}</td>
149  <td>{$clicks}</td>
150  <td>{$percent}%</td>
151  <td><a href='banners.php?op=EmailStats&amp;cid={$cid}&amp;bid={$bid}' title='" . _BANNERS_STATS . "'>" . _BANNERS_STATS . "</a></td></tr></tbody>";
152  $i++;
153  }
154  echo "</table>
155  <br /><br />
156  <h4 class='content_title'>" . _BANNERS_FOW_IN . htmlspecialchars($xoopsConfig['sitename']) . "</h4><hr />";
157 
158  $result = $xoopsDB->query("SELECT bid, imageurl, clickurl, htmlbanner, htmlcode FROM " . $xoopsDB->prefix("banner") . " WHERE cid={$cid}");
159  while (list ($bid, $imageurl, $clickurl, $htmlbanner, $htmlcode) = $xoopsDB->fetchRow($result)) {
160  $numrows = $xoopsDB->getRowsNum($result);
161  if ($numrows > 1) {
162  echo "<br />";
163  }
164  if (!empty($htmlbanner) && !empty($htmlcode)) {
165  echo $myts->displayTarea($htmlcode);
166  } else {
167  if (strtolower(substr($imageurl, strrpos($imageurl, "."))) == ".swf") {
168  echo "<object type='application/x-shockwave-flash' width='468' height='60' data='{$imageurl}'>";
169  echo "<param name='movie' value='{$imageurl}' />";
170  echo "<param name='quality' value='high' />";
171  echo "</object>";
172  } else {
173  echo "<img src='{$imageurl}' alt='' />";
174  }
175  }
176  echo "<br /><strong>" . _BANNERS_ID . $bid . "</strong><br />" . sprintf(_BANNERS_SEND_STATS, 'banners.php?op=EmailStats&amp;cid=' . $cid . '&amp;bid=' . $bid) . "<br />";
177  if (!$htmlbanner) {
178  $clickurl = htmlspecialchars($clickurl, ENT_QUOTES);
179  echo sprintf(_BANNERS_POINTS, $clickurl) . "<br />
180  <form action='banners.php' method='post'>" . _BANNERS_URL . "
181  <input type='text' name='url' size='50' maxlength='200' value='{$clickurl}' />
182  <input type='hidden' name='bid' value='{$bid}' />
183  <input type='hidden' name='cid' value='{$cid}' />
184  <input type='submit' name='op' value='" . _BANNERS_CHANGE . "' />" . $GLOBALS['xoopsSecurity']->getTokenHTML("BANNER_EDIT") . "</form>";
185  }
186  }
187 
188  /* Finnished Banners */
189  echo "<br />";
190  if ($result = $xoopsDB->query("SELECT bid, impressions, clicks, datestart, dateend FROM " . $xoopsDB->prefix("bannerfinish") . " WHERE cid={$cid}")) {
191  echo "<h4 class='content_title'>" . sprintf(_BANNERS_FINISHED, $name) . "</h4><hr />
192  <table summary=''>
193  <caption>" . sprintf(_BANNERS_FINISHED, $name) . "</caption>
194  <thead><tr>
195  <td>ID</td>
196  <td>" . _BANNERS_IMP_MADE . "</td>
197  <td>" . _BANNERS_CLICKS . "</td>
198  <td>" . _BANNERS_PER_CLICKS . "</td>
199  <td>" . _BANNERS_STARTED . "</td>
200  <td>" . _BANNERS_ENDED . "</td></tr></thead>
201  <tfoot><tr><td colspan='6'></td></tr></tfoot>";
202 
203  $i = 0;
204  while (list ($bid, $impressions, $clicks, $datestart, $dateend) = $xoopsDB->fetchRow($result)) {
205  if ($impressions == 0) {
206  $percent = 0;
207  } else {
208  $percent = substr(100 * $clicks / $impressions, 0, 5);
209  }
210  $class = ($i % 2 == 0) ? 'even' : 'odd';
211  echo "<tbody><tr class='{$class}'>
212  <td>{$bid}</td>
213  <td>{$impressions}</td>
214  <td>{$clicks}</td>
215  <td>{$percent}%</td>
216  <td>" . formatTimestamp($datestart) . "</td>
217  <td>" . formatTimestamp($dateend) . "</td></tr></tbody>";
218  }
219  echo "</table></div>";
220  }
221  include $GLOBALS['xoops']->path('footer.php');
222  } else {
223  redirect_header("banners.php", 2);
224  exit();
225  }
226 }
227 
228 /*********************************************/
229 /* Function to let the client E-mail his */
230 /* banner Stats */
231 /*********************************************/
232 function EmailStats($cid, $bid)
233 {
234  global $xoopsDB, $xoopsConfig;
235  if ($_SESSION['banner_login'] != "" && $_SESSION['banner_pass'] != "") {
236  $cid = intval($cid);
237  $bid = intval($bid);
238  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'])))) {
239  list ($name, $email, $passwd) = $xoopsDB->fetchRow($result2);
240  if ($_SESSION['banner_pass'] == $passwd) {
241  if ($email == "") {
242  redirect_header("banners.php", 3, sprintf(_BANNERS_MAIL_ERROR, $name));
243  exit();
244  } else {
245  if ($result = $xoopsDB->query("SELECT bid, imptotal, impmade, clicks, imageurl, clickurl, date FROM " . $xoopsDB->prefix("banner") . " WHERE bid={$bid} AND cid={$cid}")) {
246  list ($bid, $imptotal, $impmade, $clicks, $imageurl, $clickurl, $date) = $xoopsDB->fetchRow($result);
247  if ($impmade == 0) {
248  $percent = 0;
249  } else {
250  $percent = substr(100 * $clicks / $impmade, 0, 5);
251  }
252  if ($imptotal == 0) {
253  $left = _BANNERS_UNLIMITED;
254  $imptotal = _BANNERS_UNLIMITED;
255  } else {
256  $left = $imptotal - $impmade;
257  }
258  $fecha = date("F jS Y, h:iA.");
259  $subject = sprintf(_BANNERS_MAIL_SUBJECT, $xoopsConfig['sitename']);
260  $message = sprintf(_BANNERS_MAIL_MESSAGE, $xoopsConfig['sitename'], $name, $bid, $imageurl, $clickurl, $imptotal, $impmade, $left, $clicks, $percent, $fecha);
261  $xoopsMailer = & xoops_getMailer();
262  $xoopsMailer->useMail();
263  $xoopsMailer->setToEmails($email);
264  $xoopsMailer->setFromEmail($xoopsConfig['adminmail']);
265  $xoopsMailer->setFromName($xoopsConfig['sitename']);
266  $xoopsMailer->setSubject($subject);
267  $xoopsMailer->setBody($message);
268  $xoopsMailer->send();
269  redirect_header("banners.php?op=Ok", 3, _BANNERS_MAIL_OK);
270  exit();
271  }
272  }
273  }
274  }
275  }
276  redirect_header("banners.php", 2);
277  exit();
278 }
279 
280 /*********************************************/
281 /* Function to let the client to change the */
282 /* url for his banner */
283 /*********************************************/
284 function change_banner_url_by_client($cid, $bid, $url)
285 {
286  global $xoopsDB;
287  if ($_SESSION['banner_login'] != "" && $_SESSION['banner_pass'] != "" && $url != "") {
288  $cid = intval($cid);
289  $bid = intval($bid);
290  $sql = sprintf("SELECT passwd FROM %s WHERE cid=%u AND login=%s", $xoopsDB->prefix("bannerclient"), $cid, $xoopsDB->quoteString($_SESSION['banner_login']));
291  if ($result = $xoopsDB->query($sql)) {
292  list ($passwd) = $xoopsDB->fetchRow($result);
293  if ($_SESSION['banner_pass'] == $passwd) {
294  $sql = sprintf("UPDATE %s SET clickurl=%s WHERE bid=%u AND cid=%u", $xoopsDB->prefix("banner"), $xoopsDB->quoteString($url), $bid, $cid);
295  if ($xoopsDB->query($sql)) {
296  redirect_header("banners.php?op=Ok", 3, _BANNERS_DBUPDATED);
297  exit();
298  }
299  }
300  }
301  }
302  redirect_header("banners.php", 2);
303  exit();
304 }
305 
306 function clickbanner($bid)
307 {
308  global $xoopsDB;
309  $bid = intval($bid);
310  if ($bid > 0) {
311  $bresult = $xoopsDB->query("SELECT clickurl FROM " . $xoopsDB->prefix("banner") . " WHERE bid={$bid}");
312  list ($clickurl) = $xoopsDB->fetchRow($bresult);
313  if ($clickurl) {
314  if ($GLOBALS['xoopsSecurity']->checkReferer()) {
315  $xoopsDB->queryF("UPDATE " . $xoopsDB->prefix("banner") . " SET clicks=clicks+1 WHERE bid=$bid");
316  header('Location: ' . $clickurl);
317  } else {
318  //No valid referer found so some javascript error or direct access found
319  echo _BANNERS_NO_REFERER;
320  }
321  exit();
322  }
323  }
324  redirect_header(XOOPS_URL, 3, _BANNERS_NO_ID);
325  exit();
326 }
327 
328 $op = '';
329 if (!empty($_POST['op'])) {
330  $op = $_POST['op'];
331 } else if (!empty($_GET['op'])) {
332  $op = $_GET['op'];
333 }
334 
336 switch ($op) {
337  case "click":
338  $bid = 0;
339  if (!empty($_GET['bid'])) {
340  $bid = intval($_GET['bid']);
341  }
342  clickbanner($bid);
343  break;
344  case "Ok":
345  if ($_SERVER['REQUEST_METHOD'] == 'POST') {
346  if (!$GLOBALS['xoopsSecurity']->check(true, false, "BANNER_LOGIN")) {
347  redirect_header("banners.php", 3, implode('<br />', $GLOBALS['xoopsSecurity']->getErrors()));
348  exit();
349  }
350 
351  $_SESSION['banner_login'] = $myts->stripslashesGPC(trim($_POST['login']));
352  $_SESSION['banner_pass'] = $myts->stripslashesGPC(trim($_POST['pass']));
353  }
354  bannerstats();
355  break;
356  case _BANNERS_CHANGE:
357  if (!$GLOBALS['xoopsSecurity']->check(true, false, "BANNER_EDIT")) {
358  redirect_header("banners.php", 3, implode('<br />', $GLOBALS['xoopsSecurity']->getErrors()));
359  exit();
360  }
361  $bid = $cid = 0;
362  if (!empty($_POST['url'])) {
363  $url = $myts->stripslashesGPC(trim($_POST['url']));
364  }
365  if (!empty($_POST['bid'])) {
366  $bid = intval($_POST['bid']);
367  }
368  if (!empty($_POST['cid'])) {
369  $cid = intval($_POST['cid']);
370  }
371  change_banner_url_by_client($cid, $bid, $url);
372  break;
373  case "EmailStats":
374  $bid = $cid = 0;
375  if (!empty($_GET['bid'])) {
376  $bid = intval($_GET['bid']);
377  }
378  if (!empty($_GET['cid'])) {
379  $cid = intval($_GET['cid']);
380  }
381  EmailStats($cid, $bid);
382  break;
383  case "login":
384  default:
385  clientlogin();
386  break;
387 }
388 
389 ?>