[ Index ]

PHP Cross Reference of Joomla 1.5.26 DE

title

Body

[close]

/administrator/components/com_banners/controllers/ -> client.php (source)

   1  <?php
   2  /**
   3   * @version        $Id: client.php 19343 2010-11-03 18:12:02Z ian $
   4   * @package        Joomla
   5   * @subpackage    Banners
   6   * @copyright    Copyright (C) 2005 - 2010 Open Source Matters. All rights reserved.
   7   * @license        GNU/GPL, see LICENSE.php
   8   * Joomla! is free software. This version may have been modified pursuant
   9   * to the GNU General Public License, and as distributed it includes or
  10   * is derivative of works licensed under the GNU General Public License or
  11   * other free or open source software licenses.
  12   * See COPYRIGHT.php for copyright notices and details.
  13   */
  14  
  15  // no direct access
  16  defined( '_JEXEC' ) or die( 'Restricted access' );
  17  
  18  jimport( 'joomla.application.component.controller' );
  19  
  20  /**
  21   * @package        Joomla
  22   * @subpackage    Banners
  23   */
  24  class BannerControllerClient extends JController
  25  {
  26      /**
  27       * Constructor
  28       */
  29  	function __construct( $config = array() )
  30      {
  31          parent::__construct( $config );
  32          // Register Extra tasks
  33          $this->registerTask( 'add',        'edit' );
  34          $this->registerTask( 'apply',    'save' );
  35      }
  36  
  37  	function display()
  38      {
  39          global $mainframe;
  40  
  41          $db        =& JFactory::getDBO();
  42          $user    =& JFactory::getUser();
  43          $context            = 'com_banners.bannerclient.list.';
  44          $filter_order        = $mainframe->getUserStateFromRequest( $context.'filter_order',        'filter_order',        'a.name',    'cmd' );
  45          $filter_order_Dir    = $mainframe->getUserStateFromRequest( $context.'filter_order_Dir',    'filter_order_Dir',    '',            'word' );
  46          $search                = $mainframe->getUserStateFromRequest( $context.'search',            'search',            '',            'string' );
  47          if (strpos($search, '"') !== false) {
  48              $search = str_replace(array('=', '<'), '', $search);
  49          }
  50          $search = JString::strtolower($search);
  51  
  52          $limit        = $mainframe->getUserStateFromRequest( 'global.list.limit',        'limit',        $mainframe->getCfg('list_limit'), 'int' );
  53          $limitstart    = $mainframe->getUserStateFromRequest( $context.'limitstart',    'limitstart',    0, 'int' );
  54  
  55          $where = array();
  56  
  57          if ($search) {
  58              $where[] = 'LOWER(a.name) LIKE '.$db->Quote( '%'.$db->getEscaped( $search, true ).'%', false );
  59          }
  60  
  61          $where        = ( count( $where ) ? ' WHERE ' . implode( ' AND ', $where ) : '' );
  62  
  63          if (!in_array($filter_order, array('a.name', 'a.contact', 'bid', 'a.cid'))) {
  64              $filter_order = 'a.name';
  65          }
  66  
  67          if (!in_array(strtoupper($filter_order_Dir), array('ASC', 'DESC'))) {
  68              $filter_order_Dir = '';
  69          }
  70  
  71          $orderby = ' ORDER BY '. $filter_order .' '. $filter_order_Dir .', a.cid';
  72  
  73          // get the total number of records
  74          $query = 'SELECT a.*, count(b.bid) AS nbanners, u.name AS editor'
  75          . ' FROM #__bannerclient AS a'
  76          . ' LEFT JOIN #__banner AS b ON a.cid = b.cid'
  77          . ' LEFT JOIN #__users AS u ON u.id = a.checked_out'
  78          . $where
  79          . ' GROUP BY a.cid'
  80          . $orderby
  81          ;
  82  
  83          $db->setQuery( $query );
  84          $db->query();
  85          $total = $db->getNumRows();
  86  
  87          jimport('joomla.html.pagination');
  88          $pageNav = new JPagination( $total, $limitstart, $limit );
  89  
  90          $db->setQuery( $query, $pageNav->limitstart, $pageNav->limit );
  91          $rows = $db->loadObjectList();
  92  
  93          // table ordering
  94          $lists['order_Dir']    = $filter_order_Dir;
  95          $lists['order']        = $filter_order;
  96  
  97          // search filter
  98          $lists['search']= $search;
  99  
 100          require_once(JPATH_COMPONENT.DS.'views'.DS.'client.php');
 101          BannersViewClients::clients( $rows, $pageNav, $lists );
 102      }
 103  
 104      /**
 105       * Edit a banner client record
 106       */
 107  	function edit()
 108      {
 109          // Initialize variables
 110          $db        =& JFactory::getDBO();
 111          $user    =& JFactory::getUser();
 112  
 113          $userId    = $user->get ( 'id' );
 114  
 115          if ($this->_task == 'edit') {
 116              $cid    = JRequest::getVar('cid', array(0), 'method', 'array');
 117          } else {
 118              $cid    = array( 0 );
 119          }
 120  
 121          $row =& JTable::getInstance('bannerclient', 'Table');
 122          $row->load( (int) $cid[0] );
 123  
 124          // fail if checked out not by 'me'
 125          if ($row->isCheckedOut( $userId )) {
 126              $this->setRedirect( 'index.php?option=com_banners&c=client' );
 127              return JError::raiseWarning( JText::sprintf( 'WARNEDITEDBYPERSON', $row->name ) );
 128          }
 129  
 130          if ($row->cid) {
 131              // do stuff for existing record
 132              $row->checkout( $userId );
 133          } else {
 134              // do stuff for new record
 135              $row->published = 0;
 136              $row->approved = 0;
 137          }
 138  
 139          require_once(JPATH_COMPONENT.DS.'views'.DS.'client.php');
 140          BannersViewClients::client( $row );
 141      }
 142  
 143  	function save()
 144      {
 145          // Check for request forgeries
 146          JRequest::checkToken() or jexit( 'Invalid Token' );
 147  
 148          $this->setRedirect( 'index.php?option=com_banners&c=client' );
 149  
 150          // Initialize variables
 151          $db        =& JFactory::getDBO();
 152          $table    =& JTable::getInstance('bannerclient', 'Table');
 153  
 154          if (!$table->bind( JRequest::get( 'post' ) )) {
 155              return JError::raiseWarning( 500, $table->getError() );
 156          }
 157          if (!$table->check()) {
 158              return JError::raiseWarning( 500, $table->getError() );
 159          }
 160          if (!$table->store()) {
 161              return JError::raiseWarning( 500, $table->getError() );
 162          }
 163          $table->checkin();
 164  
 165          switch (JRequest::getCmd( 'task' ))
 166          {
 167              case 'apply':
 168                  $this->setRedirect( 'index.php?option=com_banners&c=client&task=edit&cid[]='. $table->cid );
 169                  break;
 170          }
 171  
 172          $this->setMessage( JText::_( 'Item Saved' ) );
 173      }
 174  
 175  	function cancel()
 176      {
 177          // Check for request forgeries
 178          JRequest::checkToken() or jexit( 'Invalid Token' );
 179  
 180          $this->setRedirect( 'index.php?option=com_banners&c=client' );
 181  
 182          // Initialize variables
 183          $db            =& JFactory::getDBO();
 184          $table        =& JTable::getInstance('bannerclient', 'Table');
 185          $table->cid    = JRequest::getVar( 'cid', 0, 'post', 'int' );
 186          $table->checkin();
 187      }
 188  
 189  	function remove()
 190      {
 191          // Check for request forgeries
 192          JRequest::checkToken() or jexit( 'Invalid Token' );
 193  
 194          $this->setRedirect( 'index.php?option=com_banners&c=client' );
 195  
 196          // Initialize variables
 197          $db        =& JFactory::getDBO();
 198          $cid    = JRequest::getVar( 'cid', array(0), 'post', 'array' );
 199          $table    =& JTable::getInstance('bannerclient', 'Table');
 200          $n        = count( $cid );
 201  
 202          for ($i = 0; $i < $n; $i++)
 203          {
 204              $query = 'SELECT COUNT( bid )'
 205              . ' FROM #__banner'
 206              . ' WHERE cid = '. (int) $cid[$i]
 207              ;
 208              $db->setQuery($query);
 209              $count = $db->loadResult();
 210              if ($count === null) {
 211                  return JError::raiseWarning( 500, $db->getErrorMsg() );
 212              }
 213              else if ($count > 0) {
 214                  return JError::raiseWarning( 500, JText::_( 'WARNCANNOTDELCLIENTBANNER' ) );
 215              }
 216              else {
 217                  if (!$table->delete( (int) $cid[$i] )) {
 218                      return JError::raiseWarning( 500, $table->getError() );
 219                  }
 220              }
 221          }
 222  
 223          $this->setMessage( JText::sprintf( 'Items removed', $n ) );
 224      }
 225  }


Generated: Wed Mar 28 15:54:07 2012 Cross-referenced by PHPXref 0.7.1