All mysql_-statments replaced by their corresponding mysqli_-statements
[cacert-devel.git] / pages / advertising / 0.php
1 <? /*
2 LibreSSL - CAcert web application
3 Copyright (C) 2004-2008 CAcert Inc.
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; version 2 of the License.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */ ?>
18 <?
19 $tdcols = 6;
20 if($_SESSION['profile']['adadmin'] == 2)
21 $tdcols++;
22
23 if(array_key_exists('approve',$_REQUEST) && intval($_REQUEST['approve']) > 0 && $_SESSION['profile']['adadmin'] >= 2)
24 {
25 $approve = intval($_REQUEST['approve']);
26 $query = "select * from `advertising` where `id`='$approve' and `expires`='0000-00-00 00:00:00'";
27 $res = mysqli_query($_SESSION['mconn'], $query);
28 if(mysqli_num_rows($res) > 0)
29 {
30 $row = mysqli_fetch_assoc($res);
31 $end = date("Y-m-d H:i:s", mktime(date("H"), date("i"), date("s"), date("m")+$row['months'], date("d"), date("Y")));
32 $query = "update `advertising` set `expires`='$end', `active`=1, `approvedby`='".$_SESSION['profile']['id']."' where `id`='$approve'";
33 mysqli_query($_SESSION['mconn'],$query);
34 echo "<p>The ad was approved and is now active.</p>\n";
35 }
36 }
37 if(array_key_exists('deactive',$_REQUEST) && intval($_REQUEST['deactive']) > 0 && $_SESSION['profile']['adadmin'] >= 2)
38 {
39 $deactive = intval($_REQUEST['deactive']);
40 $query = "select * from `advertising` where `id`='$deactive'";
41 $res = mysqli_query($_SESSION['mconn'], $query);
42 if(mysqli_num_rows($res) > 0)
43 {
44 $row = mysqli_fetch_assoc($res);
45 $end = date("Y-m-d H:i:s", mktime(date("H"), date("i"), date("s"), date("m")+$row['months'], date("d"), date("Y")));
46 $query = "update `advertising` set `active`=0 where `id`='$deactive'";
47 mysqli_query($_SESSION['mconn'], $query);
48 echo "<p>The ad was deactivated and is now inactive.</p>\n";
49 }
50 }
51
52 ?>
53 <table align="center" valign="middle" border="0" cellspacing="0" cellpadding="0" class="wrapper" width="500">
54 <tr>
55 <td colspan="<?=$tdcols?>" class="title"><?=_("View Advertising")?> <a href="advertising.php?id=<?=$id?>&showall=1"><?=_("Show All")?></a></td>
56 </tr>
57 <tr>
58 <td class="DataTD">ID</td>
59 <td class="DataTD">Link</td>
60 <td class="DataTD">Status</td>
61 <td class="DataTD">Expires</td>
62 <td class="DataTD">Edit</td>
63 <td class="DataTD">Disable</td>
64 <? if($_SESSION['profile']['adadmin'] == 2) { echo "\t<td class='DataTD'>Approve</td>\n"; }
65 ?> </tr>
66 <?
67 $query = "select *,UNIX_TIMESTAMP(`expires`)-UNIX_TIMESTAMP(NOW()) as `timeleft` from `advertising` where `replaced`=0 ";
68 if(!array_key_exists('showall',$_REQUEST) || $_REQUEST['showall'] != 1)
69 $query .= "and `active`=1 having `timeleft` > 0 ";
70 $query .= "order by `id` desc";
71
72 $res = mysqli_query($_SESSION['mconn'], $query);
73 while($row = mysqli_fetch_assoc($res))
74 {
75 if($row['expires'] == "0000-00-00 00:00:00")
76 $status = "Pending";
77 else if($row['active'] == 1 && $row['timeleft'] > 0)
78 $status = "Active";
79 else if($row['timeleft'] <= 0)
80 $status = "Expired";
81 else if($row['active'] != 1)
82 $status = "Disabled";
83 else
84 $status = "Unknown";
85 echo "<tr><td class='DataTD'>".$row['id']."</td><td class='DataTD'><a href='".$row['link']."' target='_new'>".$row['title']."</a></td>";
86 echo "<td class='DataTD'>$status</td><td class='DataTD'>".$row['expires']."</td><td class='DataTD'>Edit</td>";
87 echo "<td class='DataTD'>Disable</td>";
88 if($_SESSION['profile']['adadmin'] == 2)
89 {
90 if($status == "Pending" && $row['expires'] == "0000-00-00 00:00:00")
91 echo "<td class='DataTD'><a href='advertising.php?id=0&amp;approve=".$row['id']."'>Approve</a></td>";
92 else if($status == "Active")
93 echo "<td class='DataTD'><a href='advertising.php?id=0&amp;deactive=".$row['id']."'>De-Activate</a></td>";
94 else
95 echo "<td class='DataTD'>N/A</td>";
96 }
97 echo "</tr>\n";
98 }
99 ?>
100 </table>