[ Index ]

PHP Cross Reference of Mambo 4.6.5

[ Variables ]     [ Functions ]     [ Classes ]     [ Constants ]     [ Statistics ]

title

Body

[close]

/administrator/components/com_banners/ -> admin.banners.php (source)

   1  <?php
   2  /**
   3  * @package Mambo
   4  * @subpackage Banners
   5  * @author Mambo Foundation Inc see README.php
   6  * @copyright (C) 2000 - 2009 Mambo Foundation Inc.
   7  * See COPYRIGHT.php for copyright notices and details.
   8  * @license GNU/GPL Version 2, see LICENSE.php
   9  *
  10  * Redistributions of files must retain the above copyright notice.
  11  *
  12  * Mambo is free software; you can redistribute it and/or
  13  * modify it under the terms of the GNU General Public License
  14  * as published by the Free Software Foundation; version 2 of the License.
  15  */
  16  
  17  /** ensure this file is being included by a parent file */
  18  defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );
  19  
  20  // ensure user has access to this function
  21  if (!($acl->acl_check( 'administration', 'edit', 'users', $my->usertype, 'components', 'all' )| $acl->acl_check( 'administration', 'edit', 'users', $my->usertype, 'components', 'com_banners' ))) {
  22      mosRedirect( 'index2.php', T_('You are not authorized to view this resource.') );
  23  }
  24  
  25  require_once( $mainframe->getPath( 'admin_html' ) );
  26  require_once( $mainframe->getPath( 'class' ) );
  27  
  28  $cid = mosGetParam( $_REQUEST, 'cid', array(0) );
  29  if (!is_array( $cid )) {
  30      $cid = array(0);
  31  }
  32  
  33  switch ($task) {
  34      case 'newclient':
  35          editBannerClient( 0, $option );
  36          break;
  37  
  38      case 'editclient':
  39          editBannerClient( $cid[0], $option );
  40          break;
  41  
  42      case 'editclientA':
  43          editBannerClient( $id, $option );
  44          break;
  45  
  46      case 'saveclient':
  47          saveBannerClient( $option );
  48          break;
  49  
  50      case 'removeclients':
  51          removeBannerClients( $cid, $option );
  52          break;
  53  
  54      case 'cancelclient':
  55          cancelEditClient( $option );
  56          break;
  57  
  58      case 'listclients':
  59          viewBannerClients( $option );
  60          break;
  61  
  62      // BANNER EVENTS
  63  
  64      case 'new':
  65          editBanner( null, $option );
  66          break;
  67  
  68      case 'cancel':
  69          cancelEditBanner();
  70          break;
  71  
  72      case 'save':
  73      case 'resethits':
  74          saveBanner( $task );
  75          break;
  76  
  77      case 'edit':
  78          editBanner( $cid[0], $option );
  79          break;
  80  
  81      case 'editA':
  82          editBanner( $id, $option );
  83          break;
  84  
  85      case 'remove':
  86          removeBanner( $cid );
  87          break;
  88  
  89      case 'publish':
  90          publishBanner( $cid,1 );
  91          break;
  92  
  93      case 'unpublish':
  94          publishBanner( $cid, 0 );
  95          break;
  96  
  97      default:
  98          viewBanners( $option );
  99          break;
 100  }
 101  
 102  function viewBanners( $option ) {
 103      global $database, $mainframe, $mosConfig_list_limit;
 104  
 105      $limit = $mainframe->getUserStateFromRequest( "viewlistlimit", 'limit', $mosConfig_list_limit );
 106      $limitstart = $mainframe->getUserStateFromRequest( "viewban{$option}limitstart", 'limitstart', 0 );
 107  
 108      // get the total number of records
 109      // @RawSQLUse, trivial_implementation, SELECT
 110      $database->setQuery( "SELECT count(*) FROM #__banner" );
 111      $total = $database->loadResult();
 112  
 113      require_once( $GLOBALS['mosConfig_absolute_path'] . '/administrator/includes/pageNavigation.php' );
 114      $pageNav = new mosPageNav( $total, $limitstart, $limit );
 115  
 116      $query = "SELECT b.*, u.name as editor FROM #__banner as b "
 117      . "\n LEFT JOIN #__users AS u ON u.id = b.checked_out"
 118      . "\nLIMIT $pageNav->limitstart,$pageNav->limit";
 119      $database->setQuery( $query );
 120  
 121      if(!$result = $database->query()) {
 122          echo $database->stderr();
 123          return;
 124      }
 125      $rows = $database->loadObjectList();
 126      HTML_banners::showBanners( $rows, $pageNav, $option );
 127  }
 128  
 129  function editBanner( $bannerid, $option ) {
 130      global $database, $my;
 131      $lists = array();
 132  
 133      $row = new mosBanner($database);
 134      $row->load( $bannerid );
 135  
 136    if ( $bannerid ){
 137      $row->checkout( $my->id );
 138    }
 139    
 140      // Build Client select list
 141      // @RawSQLUse, trivial_implementation, SELECT
 142      $sql    = "SELECT cid as value, name as text FROM #__bannerclient";
 143      $database->setQuery($sql);
 144      if (!$database->query()) {
 145          echo $database->stderr();
 146          return;
 147      }
 148  
 149      $clientlist[] = mosHTML::makeOption( '0', 'Select Client' );
 150      $clientlist = array_merge( $clientlist, $database->loadObjectList() );
 151      $lists['cid'] = mosHTML::selectList( $clientlist, 'cid', 'class="inputbox" size="1"','value', 'text', $row->cid);
 152  
 153      // Imagelist
 154      $javascript = 'onchange="changeDisplayImage();"';
 155      $directory = '/images/banners';
 156      $lists['imageurl'] = mosAdminMenus::Images( 'imageurl', $row->imageurl, $javascript, $directory );
 157  
 158  
 159      // make the select list for the image positions
 160      $yesno[] = mosHTML::makeOption( '0', T_('No') );
 161        $yesno[] = mosHTML::makeOption( '1', T_('Yes') );
 162    
 163        $lists['showBanner'] = mosHTML::selectList( $yesno, 'showBanner', 'class="inputbox" size="1"' , 'value', 'text', $row->showBanner );
 164  
 165      HTML_banners::bannerForm( $row, $lists, $option );
 166  }
 167  
 168  function saveBanner( $task ) {
 169      global $database;
 170      
 171      $row = new mosBanner($database);
 172  
 173      $msg = T_('Saved Banner info');
 174      if ( $task == 'resethits' ) {
 175          $row->clicks = 0;
 176          $msg = T_('Reset Banner clicks');
 177      }
 178      if (!$row->bind( $_POST )) {
 179          echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
 180          exit();
 181      }
 182      if (!$row->check()) {
 183          echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
 184          exit();
 185      }
 186      if (!$row->store()) {
 187          echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
 188          exit();
 189      }
 190      $row->checkin();
 191  
 192      mosRedirect( 'index2.php?option=com_banners', $msg );
 193  }
 194  
 195  function cancelEditBanner() {
 196      global $database;
 197      
 198      $row = new mosBanner($database);
 199      $row->bind( $_POST );
 200      $row->checkin();
 201      // sanitize
 202      $row->id = intval($row->id);
 203  
 204      mosRedirect( 'index2.php?option=com_banners' );
 205  }
 206  
 207  function publishBanner( $cid, $publish=1 ) {
 208      global $database, $my;
 209  
 210      if (!is_array( $cid ) || count( $cid ) < 1) {
 211          $action = $publish ? T_('publish') : T_('unpublish');
 212          echo "<script> alert('".sprintf(T_('Select an item to %s'), $action)."'); window.history.go(-1);</script>\n";
 213          exit;
 214      }
 215  
 216      $cids = implode( ',', $cid );
 217  
 218      $database->setQuery( "UPDATE #__banner SET showBanner='$publish'"
 219      . "\nWHERE bid IN ($cids) AND (checked_out=0 OR (checked_out='$my->id'))"
 220      );
 221      if (!$database->query()) {
 222          echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n";
 223          exit();
 224      }
 225  
 226      if (count( $cid ) == 1) {
 227          $row = new mosBanner( $database );
 228          $row->checkin( $cid[0] );
 229      }
 230      mosRedirect( 'index2.php?option=com_banners' );
 231  
 232  }
 233  
 234  function removeBanner( $cid ) {
 235      global $database;
 236      if (count( $cid )) {
 237          $cids = implode( ',', $cid );
 238          $database->setQuery( "DELETE FROM #__banner WHERE bid IN ($cids)" );
 239          if (!$database->query()) {
 240              echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n";
 241          }
 242      }
 243      mosRedirect( 'index2.php?option=com_banners' );
 244  }
 245  
 246  // ---------- BANNER CLIENTS ----------
 247  
 248  function viewBannerClients( $option ) {
 249      global $database, $mainframe, $mosConfig_list_limit;
 250  
 251      $limit = $mainframe->getUserStateFromRequest( "viewlistlimit", 'limit', $mosConfig_list_limit );
 252      $limitstart = $mainframe->getUserStateFromRequest( "viewcli{$option}limitstart", 'limitstart', 0 );
 253  
 254      // @RawSQLUse, trivial_implementation, SELECT
 255      // get the total number of records
 256      $database->setQuery( "SELECT count(*) FROM #__bannerclient" );
 257      $total = $database->loadResult();
 258  
 259      require_once( $GLOBALS['mosConfig_absolute_path'] . '/administrator/includes/pageNavigation.php' );
 260      $pageNav = new mosPageNav( $total, $limitstart, $limit );
 261  
 262      $sql = "SELECT a.*,    count(b.bid) AS bid, u.name AS editor"
 263      . "\n FROM #__bannerclient AS a"
 264      . "\n LEFT JOIN #__banner AS b ON a.cid = b.cid"
 265      . "\n LEFT JOIN #__users AS u ON u.id = a.checked_out"
 266      . "\n GROUP BY a.cid"
 267      . "\n LIMIT $pageNav->limitstart,$pageNav->limit";
 268      $database->setQuery($sql);
 269  
 270      if(!$result = $database->query()) {
 271          echo $database->stderr();
 272          return;
 273      }
 274      $rows = $database->loadObjectList();
 275  
 276      HTML_bannerClient::showClients( $rows, $pageNav, $option );
 277  }
 278  
 279  function editBannerClient( $clientid, $option ) {
 280      global $database, $my;
 281      
 282      $row = new mosBannerClient($database);
 283      $row->load($clientid);
 284  
 285      // fail if checked out not by 'me'
 286      if ($row->checked_out && $row->checked_out <> $my->id) {
 287          $msg = sprintf(T_('The client [ %s ] is currently being edited by another person.'), $row->name);
 288          mosRedirect( 'index2.php?option='. $option .'&task=listclients', $msg );
 289      }
 290  
 291      if ($clientid) {
 292          // do stuff for existing record
 293          $row->checkout( $my->id );
 294      } else {
 295          // do stuff for new record
 296          $row->published = 0;
 297          $row->approved = 0;
 298      }
 299  
 300      HTML_bannerClient::bannerClientForm( $row, $option );
 301  }
 302  
 303  function saveBannerClient( $option ) {
 304      global $database;
 305  
 306      $row = new mosBannerClient( $database );
 307      if (!$row->bind( $_POST )) {
 308          echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
 309          exit();
 310      }
 311      if (!$row->check()) {
 312          mosRedirect( "index2.php?option=$option&task=editclient&cid[]=$row->id", $row->getError() );
 313      }
 314  
 315      if (!$row->store()) {
 316          echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
 317          exit();
 318      }
 319      $row->checkin();
 320      
 321      mosRedirect( "index2.php?option=$option&task=listclients" );
 322  }
 323  
 324  function cancelEditClient( $option ) {
 325      global $database;
 326      $row = new mosBannerClient( $database );
 327      $row->bind( $_POST );
 328      // sanitize
 329      $row->id = intval($row->id);
 330      $row->checkin();
 331      mosRedirect( "index2.php?option=$option&task=listclients" );
 332  }
 333  
 334  function removeBannerClients( $cid, $option ) {
 335      global $database;
 336  
 337      for ($i = 0; $i < count($cid); $i++) {
 338          // @RawSQLUse, trivial_implementation, SELECT
 339          $query = "SELECT COUNT(bid) FROM #__banner WHERE cid='".$cid[$i]."'";
 340          $database->setQuery($query);
 341  
 342          if(($count = $database->loadResult()) == null) {
 343              echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n";
 344          }
 345  
 346          if ($count != 0) {
 347              mosRedirect( "index2.php?option=$option&task=listclients",
 348              T_("Cannot delete client at this time as they have a banner still running") );
 349          } else {
 350              // @RawSQLUse, trivial_implementation, DELETE
 351              $query="DELETE FROM #__bannerfinish WHERE `cid`='".$cid[$i]."'";
 352              $database->setQuery($query);
 353              $database->query();
 354  
 355              // @RawSQLUse, trivial_implementation, DELETE
 356              $query="DELETE FROM #__bannerclient WHERE `cid`='".$cid[$i]."'";
 357              $database->setQuery($query);
 358              $database->query();
 359          }
 360      }
 361      mosRedirect("index2.php?option=$option&task=listclients");
 362  }
 363  ?>