XOOPS 2.5.6  Final
 All Classes Namespaces Files Functions Variables Pages
main.php
Go to the documentation of this file.
1 <?php
2 // $Id: main.php 8645 2012-01-06 16:03:18Z mageg $
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 // Check users rights
29 if ( !is_object($xoopsUser) || !is_object($xoopsModule) || !$xoopsUser->isAdmin($xoopsModule->mid()) ) exit( _NOPERM );
30 // Check is active
31 if ( !xoops_getModuleOption('active_banners', 'system') ) redirect_header( 'admin.php', 2, _AM_SYSTEM_NOTACTIVE );
32 // Parameters
33 $nb_aff = xoops_getModuleOption('banners_pager', 'system');
34 // Classes
35 $banner_Handler =& xoops_getModuleHandler( 'banner', 'system' );
36 $banner_finish_Handler =& xoops_getModuleHandler( 'bannerfinish', 'system' );
37 $banner_client_Handler =& xoops_getModuleHandler( 'bannerclient', 'system' );
38 // Get Action type
39 $op = system_CleanVars ( $_REQUEST, 'op', 'default', 'string' );
40 // Define template
41 $xoopsOption['template_main'] = 'system_banners.html';
42 // Call header
44 // Define Stylesheet
45 $xoTheme->addStylesheet( XOOPS_URL . '/modules/system/css/admin.css');
46 $xoTheme->addStylesheet( XOOPS_URL . '/modules/system/css/ui/' . xoops_getModuleOption('jquery_theme', 'system') . '/ui.all.css');
47 // Define scripts
48 $xoTheme->addScript('browse.php?Frameworks/jquery/jquery.js');
49 $xoTheme->addScript('browse.php?Frameworks/jquery/plugins/jquery.ui.js');
50 $xoTheme->addScript('browse.php?Frameworks/jquery/plugins/jquery.tablesorter.js');
51 $xoTheme->addScript('modules/system/js/admin.js');
52 // Define Breadcrumb and tips
53 $xoBreadCrumb->addLink( _AM_SYSTEM_BANNERS_NAV_MANAGER, system_adminVersion('banners', 'adminpath') );
54 switch ( $op ) {
55  // Banners
56  case 'banner_save': // Save banner
57  if ( !$GLOBALS["xoopsSecurity"]->check() ) {
58  redirect_header("admin.php?fct=banners", 3, implode(",", $GLOBALS["xoopsSecurity"]->getErrors()));
59  }
60  $bid = system_CleanVars($_POST, 'bid', 0, 'int' );
61  if ( $bid > 0 ) {
62  $obj =& $banner_Handler->get( $bid );
63  } else {
64  $obj =& $banner_Handler->create();
65  $obj->setVar("date", time());
66  }
67  $obj->setVars( $_POST );
68  $verif_htmlbanner = system_CleanVars($_POST, 'htmlbanner', 0, 'int');
69  $obj->setVar("htmlbanner", $verif_htmlbanner);
70 
71  if ($banner_Handler->insert($obj)) {
72  redirect_header("admin.php?fct=banners", 2, _AM_SYSTEM_BANNERS_DBUPDATED);
73  }
74  xoops_error( $obj->getHtmlErrors() );
75  $form =& $obj->getForm(false);
76  $form->display();
77  break;
78 
79  case 'banner_edit': // Edit banner
81  $xoBreadCrumb->addHelp( system_adminVersion('banners', 'help') . '#banner_edit' );
83  $xoBreadCrumb->render();
84 
85  $bid = system_CleanVars($_REQUEST, 'bid', 0, 'int' );
86  if ( $bid > 0 ) {
87  $obj = $banner_Handler->get( $bid );
88  $form = $obj->getForm();
89  $form->display();
90  } else {
91  redirect_header('admin.php?fct=banners', 1, _AM_SYSTEM_DBERROR);
92  }
93  break;
94 
95  case 'banner_delete': // Delete banner
97  $xoBreadCrumb->addHelp( system_adminVersion('banners', 'help') . '#banner_delete' );
98  $xoBreadCrumb->render();
99 
100  $bid = system_CleanVars($_REQUEST, 'bid', 0, 'int' );
101  if ( $bid > 0 ) {
102  $obj =& $banner_Handler->get( $bid );
103  if (isset($_POST["ok"]) && $_POST["ok"] == 1) {
104  if ( !$GLOBALS["xoopsSecurity"]->check() ) {
105  redirect_header("admin.php?fct=banners", 3, implode(",", $GLOBALS["xoopsSecurity"]->getErrors()));
106  }
107  if ($banner_Handler->delete($obj)) {
108  redirect_header("admin.php?fct=banners", 3, _AM_SYSTEM_BANNERS_DELEBNR);
109  } else {
110  xoops_error( $obj->getHtmlErrors() );
111  }
112  } else {
113  xoops_confirm( array("ok" => 1, "bid" => $bid, "op" => "banner_delete"), 'admin.php?fct=banners', sprintf(_AM_SYSTEM_BANNERS_SUREDELE));
114  }
115  } else {
116  redirect_header('admin.php?fct=banners', 1, _AM_SYSTEM_DBERROR);
117  }
118  break;
119 
120  case 'banner_finish_delete': // Delete finish banner
122  $xoBreadCrumb->addHelp( system_adminVersion('banners', 'help') . '#banner_finish_delete' );
123  $xoBreadCrumb->render();
124 
125  $bid = system_CleanVars($_REQUEST, 'bid', 0, 'int' );
126  if ( $bid > 0 ) {
127  $obj =& $banner_finish_Handler->get( $bid );
128  if (isset($_POST["ok"]) && $_POST["ok"] == 1)
129  {
130  if ( !$GLOBALS["xoopsSecurity"]->check() ) {
131  redirect_header("admin.php?fct=banners", 3, implode(",", $GLOBALS["xoopsSecurity"]->getErrors()));
132  }
133  if ($banner_finish_Handler->delete( $obj )) {
134  redirect_header("admin.php?fct=banners", 3, _AM_SYSTEM_BANNERS_DBUPDATED);
135  } else {
136  xoops_error( $obj->getHtmlErrors() );
137  }
138  } else {
139  xoops_confirm( array("ok" => 1, "bid" => $bid, "op" => "banner_finish_delete"), 'admin.php?fct=banners', sprintf(_AM_SYSTEM_BANNERS_SUREDELE));
140  }
141  } else {
142  redirect_header('admin.php?fct=banners', 1, _AM_SYSTEM_DBERROR);
143  }
144  break;
145 
146  // Clients
147  case 'banner_client_save': // Save client
148  if ( !$GLOBALS["xoopsSecurity"]->check() ) {
149  redirect_header("admin.php?fct=banners", 3, implode(",", $GLOBALS["xoopsSecurity"]->getErrors()));
150  }
151  $cid = system_CleanVars($_REQUEST, 'cid', 0, 'int' );
152  if ( $cid > 0 ) {
153  $obj =& $banner_client_Handler->get( $cid );
154  } else {
155  $obj =& $banner_client_Handler->create();
156  }
157  $obj->setVars( $_POST );
158 
159  if ($banner_client_Handler->insert( $obj )) {
160  redirect_header("admin.php?fct=banners", 2, _AM_SYSTEM_BANNERS_DBUPDATED);
161  }
162 
163  xoops_error( $obj->getHtmlErrors() );
164  $form =& $obj->getForm(false);
165  $form->display();
166  break;
167 
168  case 'banner_client_edit': // Edit client
170  $xoBreadCrumb->addHelp( system_adminVersion('banners', 'help') . '#banner_client_edit' );
172  $xoBreadCrumb->render();
173 
174  $cid = system_CleanVars($_REQUEST, 'cid', 0, 'int' );
175  if ( $cid > 0 ) {
176  $obj = $banner_client_Handler->get( $cid );
177  $form = $obj->getForm();
178  $xoopsTpl->assign('form', $form->render());
179  } else {
180  redirect_header('admin.php?fct=banners', 1, _AM_SYSTEM_DBERROR);
181  }
182  break;
183 
184  case 'banner_client_delete': // Delete Client
186  $xoBreadCrumb->addHelp( system_adminVersion('banners', 'help') . '#banner_client_delete' );
187  $xoBreadCrumb->render();
188 
189  $cid = system_CleanVars($_REQUEST, 'cid', 0, 'int' );
190  if ( $cid > 0 ) {
191  $obj =& $banner_client_Handler->get( $cid );
192  if (isset($_POST["ok"]) && $_POST["ok"] == 1) {
193  if ( !$GLOBALS["xoopsSecurity"]->check() ) {
194  redirect_header("admin.php?fct=banners", 3, implode(",", $GLOBALS["xoopsSecurity"]->getErrors()));
195  }
196  if ($banner_client_Handler->delete($obj)) {
197  // Delete client banners
198  $banner_Handler->deleteAll(new Criteria('cid', $cid));
199  $banner_finish_Handler->deleteAll(new Criteria('cid', $cid));
200 
201  redirect_header("admin.php?fct=banners", 3, _AM_SYSTEM_BANNERS_DBUPDATED);
202  } else {
203  xoops_error( $obj->getHtmlErrors() );
204  }
205  } else {
206  xoops_confirm(array("ok" => 1, "cid" => $cid, "op" => "banner_client_delete"), 'admin.php?fct=banners', _AM_SYSTEM_BANNERS_SUREDELBNR);
207  }
208  } else {
209  redirect_header('admin.php?fct=banners', 1, _AM_SYSTEM_DBERROR);
210  }
211  break;
212 
213  case 'new_banner': // Form: New Banner
215  $xoBreadCrumb->addHelp( system_adminVersion('banners', 'help') . '#new_banner' );
217  $xoBreadCrumb->render();
218  $obj =& $banner_Handler->create();
219  $form = $obj->getForm();
220  $xoopsTpl->assign('form', $form->render());
221  break;
222 
223  case 'new_client': // Form: New Client
225  $xoBreadCrumb->addHelp( system_adminVersion('banners', 'help') . '#new_client' );
227  $xoBreadCrumb->render();
228  $obj =& $banner_client_Handler->create();
229  $form = $obj->getForm();
230  $xoopsTpl->assign('form', $form->render());
231  break;
232 
233  default:
234  $xoBreadCrumb->addHelp( system_adminVersion('banners', 'help') );
236  $xoBreadCrumb->render();
237 
238  // Get start pager
239  $start = system_CleanVars ( $_REQUEST, 'start', 0, 'int' );
240  $startF = system_CleanVars ( $_REQUEST, 'startF', 0, 'int' );
241  $startC = system_CleanVars ( $_REQUEST, 'startC', 0, 'int' );
242  // Display Banners
243  // Criteria
244  $criteria = new CriteriaCompo();
245  $criteria->setSort("date");
246  $criteria->setOrder("DESC");
247  $criteria->setStart($start);
248  $criteria->setLimit($nb_aff);
249 
250  $banner_count = $banner_Handler->getCount($criteria);
251  $banner_arr = $banner_Handler->getall($criteria);
252 
253  $xoopsTpl->assign( 'banner_count', $banner_count );
254 
255  if ( $banner_count > 0 )
256  {
257  foreach (array_keys($banner_arr) as $i)
258  {
259  $bid = $banner_arr[$i]->getVar("bid");
260  $imptotal = $banner_arr[$i]->getVar("imptotal");
261  $impmade = $banner_arr[$i]->getVar("impmade");
262  $imageurl = $banner_arr[$i]->getVar("imageurl");
263  $clicks = $banner_arr[$i]->getVar("clicks");
264  $htmlbanner =$banner_arr[$i]->getVar("htmlbanner");
265  $htmlcode = $banner_arr[$i]->getVar("htmlcode");
266  $name_client = $banner_client_Handler->get($banner_arr[$i]->getVar("cid"));
267  if ( is_object($name_client) )
268  $name = $name_client->getVar("name");
269 
270  if ( $impmade == 0 ) {
271  $percent = 0;
272  } else {
273  $percent = substr(100 * $clicks / $impmade, 0, 5);
274  }
275  if ( $imptotal == 0 ) {
276  $left = ""._AM_SYSTEM_BANNERS_UNLIMIT."";
277  } else {
278  $left = $imptotal-$impmade;
279  }
280 
281  //Img
282  $img = '';
283  if ($htmlbanner) {
284  $img .= html_entity_decode($htmlcode);
285  } else {
286 
287  if(strtolower(substr($imageurl,strrpos($imageurl,".")))==".swf") {
288  $img .= "<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\">";
289  $img .= "<param name=movie value=\"$imageurl\">";
290  $img .= "<param name=quality value=high>";
291  $img .= "<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\">";
292  $img .= "</embed>";
293  $img .= "</object>";
294  } else {
295  $img .= "<img src='".$imageurl."' alt='' />";
296  }
297  }
298 
299  $banner['bid'] = $bid;
300  $banner['impmade'] = $impmade;
301  $banner['clicks'] = $clicks;
302  $banner['left'] = $left;
303  $banner['percent'] = $percent;
304  $banner['imageurl'] = $img;
305  $banner['name'] = $name;
306  $banner['edit_delete'] = '<img class="cursorpointer" onclick="display_dialog('.$bid.', true, false, \'slide\', \'slide\', 200, 520);" src="images/icons/view.png" alt="'._AM_SYSTEM_BANNERS_VIEW.'" title="'._AM_SYSTEM_BANNERS_VIEW.'" /><a href="admin.php?fct=banners&amp;op=banner_edit&amp;bid='.$bid.'"><img src="./images/icons/edit.png" border="0" alt="'._AM_SYSTEM_BANNERS_EDIT.'" title="'._AM_SYSTEM_BANNERS_EDIT.'"></a><a href="admin.php?fct=banners&amp;op=banner_delete&amp;bid='.$bid.'"><img src="./images/icons/delete.png" border="0" alt="'._AM_SYSTEM_BANNERS_DELETE.'" title="'._AM_SYSTEM_BANNERS_DELETE.'"></a>';
307 
308  $xoopsTpl->append_by_ref( 'banner', $banner );
309  $xoopsTpl->append_by_ref( 'popup_banner', $banner );
310  unset( $banner );
311  }
312  }
313  // Display Page Navigation
314  if ($banner_count > $nb_aff) {
315  $nav = new XoopsPageNav($banner_count, $nb_aff, $start, 'start', 'fct=banners&amp;startF=' . $startF . '&amp;startC=' . $startC);
316  $xoopsTpl->assign('nav_menu_banner', $nav->renderNav(4));
317  }
318  // Display Finished Banners
319  // Criteria
320  $criteria = new CriteriaCompo();
321  $criteria->setSort("bid");
322  $criteria->setOrder("DESC");
323  $criteria->setStart($startF);
324  $criteria->setLimit($nb_aff);
325 
326  $banner_finish_count = $banner_finish_Handler->getCount($criteria);
327  $banner_finish_arr = $banner_finish_Handler->getall($criteria);
328 
329  $xoopsTpl->assign( 'banner_finish_count', $banner_finish_count );
330 
331  if ( $banner_finish_count > 0 )
332  {
333  foreach (array_keys($banner_finish_arr) as $i)
334  {
335  $bid = $banner_finish_arr[$i]->getVar("bid");
336  //$imageurl = $banner_arr[$i]->getVar("imageurl");
337  $impressions = $banner_finish_arr[$i]->getVar("impressions");
338  $clicks = $banner_finish_arr[$i]->getVar("clicks");
339  if ($impressions != 0){
340  $percent = substr(100 * $clicks / $impressions, 0, 5);
341  }
342 
343  $banner_finish['bid'] = $bid;
344  $banner_finish['impressions'] = $impressions;
345  $banner_finish['clicks'] = $clicks;
346  $banner_finish['left'] = $left;
347  $banner_finish['percent'] = $percent;
348  $banner_finish['datestart'] = formatTimestamp($banner_finish_arr[$i]->getVar("datestart"),"m");
349  $banner_finish['dateend'] = formatTimestamp($banner_finish_arr[$i]->getVar("dateend"),"m");
350  $name_client = $banner_client_Handler->get($banner_finish_arr[$i]->getVar("cid"));
351  $banner_finish['name'] = $name_client->getVar("name");
352  $banner_finish['edit_delete'] = '<img class="cursorpointer" onclick="display_dialog('.$bid.'000, true, true, \'slide\', \'slide\', 200, 520);" src="images/icons/view.png" alt="'._AM_SYSTEM_BANNERS_VIEW.'" title="'._AM_SYSTEM_BANNERS_VIEW.'" /><a href="admin.php?fct=banners&amp;op=banner_finish_delete&amp;bid='.$bid.'"><img src="./images/icons/delete.png" border="0" alt="'._AM_SYSTEM_BANNERS_DELETE.'" title="'._AM_SYSTEM_BANNERS_DELETE.'"></a>';
353 
354  $xoopsTpl->append_by_ref( 'banner_finish', $banner_finish );
355  unset( $banner_finish );
356  }
357  }
358  // Display Page Navigation
359  if ($banner_finish_count > $nb_aff) {
360  $nav = new XoopsPageNav($banner_count, $nb_aff, $startF, 'startF', 'fct=banners&amp;start=' . $start . '&amp;startC=' . $startC);
361  $xoopsTpl->assign('nav_menu_bannerF', $nav->renderNav(4));
362  }
363  // Display client
364  $criteria = new CriteriaCompo();
365  $criteria->setSort("cid");
366  $criteria->setOrder("DESC");
367  $criteria->setStart($startC);
368  $criteria->setLimit($nb_aff);
369 
370  $banner_client_count = $banner_client_Handler->getCount($criteria);
371  $banner_client_arr = $banner_client_Handler->getall($criteria);
372 
373  $xoopsTpl->assign( 'banner_client_count', $banner_client_count );
374 
375  if ( $banner_client_count > 0 )
376  {
377  foreach (array_keys($banner_client_arr) as $i)
378  {
379  $cid = $banner_client_arr[$i]->getVar("cid");
380 
381  $criteria = new CriteriaCompo();
382  $criteria->add(new Criteria('cid', $cid, '='));
383  $banner_active = $banner_Handler->getCount($criteria);
384  $banner_client['cid'] = $cid;
385  $banner_client['banner_active'] = $banner_active;
386  $banner_client['name'] = $banner_client_arr[$i]->getVar("name");
387  $banner_client['contact'] = $banner_client_arr[$i]->getVar("contact");
388  $banner_client['email'] = $banner_client_arr[$i]->getVar("email");
389  $banner_client['edit_delete'] = '<a href="admin.php?fct=banners&amp;op=banner_client_edit&amp;cid='.$cid.'"><img src="./images/icons/edit.png" border="0" alt="'._AM_SYSTEM_BANNERS_EDIT.'" title="'._AM_SYSTEM_BANNERS_EDIT.'"></a><a href="admin.php?fct=banners&amp;op=banner_client_delete&amp;cid='.$cid.'"><img src="./images/icons/delete.png" border="0" alt="'._AM_SYSTEM_BANNERS_DELETE.'" title="'._AM_SYSTEM_BANNERS_DELETE.'"></a>';
390 
391  $xoopsTpl->append_by_ref( 'banner_client', $banner_client );
392  unset( $banner_client );
393  }
394  }
395  // Display Page Navigation
396  if ($banner_client_count > $nb_aff) {
397  $nav = new XoopsPageNav($banner_count, $nb_aff, $startC, 'startC', 'fct=banners&amp;start=' . $start . '&amp;startF=' . $startF);
398  $xoopsTpl->assign('nav_menu_client', $nav->renderNav(4));
399  }
400  break;
401 }
403 
404 ?>