| [ Index ] |
PHP Cross Reference of Joomla 1.5.26 DE |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * @version $Id: banner.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 BannerControllerBanner 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 $this->registerTask( 'resethits', 'save' ); 36 $this->registerTask( 'unpublish', 'publish' ); 37 } 38 39 /** 40 * Display the list of banners 41 */ 42 function display() 43 { 44 global $mainframe; 45 46 $db =& JFactory::getDBO(); 47 48 $context = 'com_banners.banner.list.'; 49 $filter_order = $mainframe->getUserStateFromRequest( $context.'filter_order', 'filter_order', 'cc.title', 'cmd' ); 50 $filter_order_Dir = $mainframe->getUserStateFromRequest( $context.'filter_order_Dir', 'filter_order_Dir', '', 'word' ); 51 $filter_catid = $mainframe->getUserStateFromRequest( $context.'filter_catid', 'filter_catid', '', 'int' ); 52 $filter_state = $mainframe->getUserStateFromRequest( $context.'filter_state', 'filter_state', '', 'word' ); 53 $search = $mainframe->getUserStateFromRequest( $context.'search', 'search', '', 'string' ); 54 if (strpos($search, '"') !== false) { 55 $search = str_replace(array('=', '<'), '', $search); 56 } 57 $search = JString::strtolower($search); 58 59 $limit = $mainframe->getUserStateFromRequest( 'global.list.limit', 'limit', $mainframe->getCfg('list_limit'), 'int' ); 60 $limitstart = $mainframe->getUserStateFromRequest( $context.'limitstart', 'limitstart', 0, 'int' ); 61 62 $where = array(); 63 64 if ( $filter_state ) 65 { 66 if ( $filter_state == 'P' ) { 67 $where[] = 'b.showBanner = 1'; 68 } 69 else if ($filter_state == 'U' ) { 70 $where[] = 'b.showBanner = 0'; 71 } 72 } 73 if ($filter_catid) { 74 $where[] = 'cc.id = ' . (int) $filter_catid; 75 } 76 if ($search) { 77 $where[] = 'LOWER(b.name) LIKE '.$db->Quote( '%'.$db->getEscaped( $search, true ).'%', false ); 78 } 79 80 $where = count( $where ) ? ' WHERE ' . implode( ' AND ', $where ) : ''; 81 82 // sanitize $filter_order 83 if (!in_array($filter_order, array('b.name', 'c.name', 'cc.title', 'b.showBanner', 'b.ordering', 'b.Sticky', 'b.impmade', 'b.clicks', 'b.bid'))) { 84 $filter_order = 'cc.title'; 85 } 86 87 if (!in_array(strtoupper($filter_order_Dir), array('ASC', 'DESC'))) { 88 $filter_order_Dir = ''; 89 } 90 91 $orderby = ' ORDER BY '. $filter_order .' '. $filter_order_Dir .', b.ordering'; 92 93 // get the total number of records 94 $query = 'SELECT COUNT(*)' 95 . ' FROM #__banner AS b' 96 . ' LEFT JOIN #__categories AS cc ON cc.id = b.catid' 97 . $where 98 ; 99 $db->setQuery( $query ); 100 $total = $db->loadResult(); 101 102 jimport('joomla.html.pagination'); 103 $pageNav = new JPagination( $total, $limitstart, $limit ); 104 105 $query = 'SELECT b.*, c.name AS client_name, cc.title AS category_name, u.name AS editor' 106 . ' FROM #__banner AS b' 107 . ' INNER JOIN #__bannerclient AS c ON c.cid = b.cid' 108 . ' LEFT JOIN #__categories AS cc ON cc.id = b.catid' 109 . ' LEFT JOIN #__users AS u ON u.id = b.checked_out' 110 . $where 111 . $orderby 112 ; 113 $db->setQuery( $query, $pageNav->limitstart, $pageNav->limit ); 114 $rows = $db->loadObjectList(); 115 116 // build list of categories 117 $javascript = 'onchange="document.adminForm.submit();"'; 118 $lists['catid'] = JHTML::_('list.category', 'filter_catid', 'com_banner', (int) $filter_catid, $javascript ); 119 120 // state filter 121 $lists['state'] = JHTML::_('grid.state', $filter_state ); 122 123 // table ordering 124 $lists['order_Dir'] = $filter_order_Dir; 125 $lists['order'] = $filter_order; 126 127 // search filter 128 $lists['search']= $search; 129 130 require_once(JPATH_COMPONENT.DS.'views'.DS.'banner.php'); 131 BannersViewBanner::banners( $rows, $pageNav, $lists ); 132 } 133 134 function edit() 135 { 136 $db =& JFactory::getDBO(); 137 $user =& JFactory::getUser(); 138 139 if ($this->_task == 'edit') { 140 $cid = JRequest::getVar('cid', array(0), 'method', 'array'); 141 $cid = array((int) $cid[0]); 142 } else { 143 $cid = array( 0 ); 144 } 145 146 $option = JRequest::getCmd('option'); 147 148 $lists = array(); 149 150 $row =& JTable::getInstance('banner', 'Table'); 151 $row->load( $cid[0] ); 152 153 if ($cid[0]) { 154 $row->checkout( $user->get('id') ); 155 } else { 156 $row->showBanner = 1; 157 } 158 159 // Build Client select list 160 $sql = 'SELECT cid, name' 161 . ' FROM #__bannerclient' 162 ; 163 $db->setQuery($sql); 164 if (!$db->query()) 165 { 166 $this->setRedirect( 'index.php?option=com_banners' ); 167 return JError::raiseWarning( 500, $db->getErrorMsg() ); 168 } 169 170 $banner_params = new JParameter( $row->params ); 171 $lists['width'] = $banner_params->get( 'width'); 172 $lists['height'] = $banner_params->get( 'height'); 173 174 $clientlist[] = JHTML::_('select.option', '0', JText::_( 'Select Client' ), 'cid', 'name' ); 175 $clientlist = array_merge( $clientlist, $db->loadObjectList() ); 176 $lists['cid'] = JHTML::_('select.genericlist', $clientlist, 'cid', 'class="inputbox" size="1"','cid', 'name', $row->cid ); 177 178 // Imagelist 179 $javascript = 'onchange="changeDisplayImage();"'; 180 $directory = '/images/banners'; 181 $lists['imageurl'] = JHTML::_('list.images', 'imageurl', $row->imageurl, $javascript, $directory, "bmp|gif|jpg|png|swf" ); 182 183 // build list of categories 184 $lists['catid'] = JHTML::_('list.category', 'catid', 'com_banner', intval( $row->catid ) ); 185 186 // sticky 187 $lists['sticky'] = JHTML::_('select.booleanlist', 'sticky', 'class="inputbox"', $row->sticky ); 188 189 // published 190 $lists['showBanner'] = JHTML::_('select.booleanlist', 'showBanner', '', $row->showBanner ); 191 192 require_once(JPATH_COMPONENT.DS.'views'.DS.'banner.php'); 193 BannersViewBanner::banner( $row, $lists ); 194 } 195 196 /** 197 * Save method 198 */ 199 function save() 200 { 201 global $mainframe; 202 203 // Check for request forgeries 204 JRequest::checkToken() or jexit( 'Invalid Token' ); 205 206 $this->setRedirect( 'index.php?option=com_banners' ); 207 208 // Initialize variables 209 $db =& JFactory::getDBO(); 210 211 $post = JRequest::get( 'post' ); 212 // fix up special html fields 213 $post['custombannercode'] = JRequest::getVar( 'custombannercode', '', 'post', 'string', JREQUEST_ALLOWRAW ); 214 215 $row =& JTable::getInstance('banner', 'Table'); 216 217 // Save params temp fix 218 $temp1 = array(); 219 $temp2 = array(); 220 $temp1['width'] = (int) $post['width']; 221 $temp1['height'] = (int) $post['height']; 222 foreach ($temp1 as $k => $v) 223 { 224 if ( $k && strlen($v) ) 225 { 226 $temp2[] = $k.'='.$v; 227 } 228 } 229 $row->params = implode( "\n", $temp2 ); 230 231 if (!$row->bind( $post )) { 232 return JError::raiseWarning( 500, $row->getError() ); 233 } 234 235 // Resets clicks when `Reset Clicks` button is used instead of `Save` button 236 $task = JRequest::getCmd( 'task' ); 237 if ( $task == 'resethits' ) 238 { 239 $row->clicks = 0; 240 $msg = JText::_( 'Reset Banner clicks' ); 241 } 242 243 // Sets impressions to unlimited when `unlimited` checkbox ticked 244 $unlimited = JRequest::getBool('unlimited'); 245 if ($unlimited) { 246 $row->imptotal = 0; 247 } 248 249 if (!$row->check()) { 250 return JError::raiseWarning( 500, $row->getError() ); 251 } 252 253 // if new item order last in appropriate group 254 if (!$row->bid) 255 { 256 $where = 'catid = '.(int) $row->catid; 257 $row->ordering = $row->getNextOrder( $where ); 258 } 259 260 if (!$row->store()) { 261 return JError::raiseWarning( 500, $row->getError() ); 262 } 263 $row->checkin(); 264 265 switch ($task) 266 { 267 case 'apply': 268 $link = 'index.php?option=com_banners&task=edit&cid[]='. $row->bid ; 269 break; 270 271 case 'save': 272 default: 273 $link = 'index.php?option=com_banners'; 274 break; 275 } 276 277 $this->setRedirect( $link, JText::_( 'Item Saved' ) ); 278 } 279 280 function cancel() 281 { 282 // Check for request forgeries 283 JRequest::checkToken() or jexit( 'Invalid Token' ); 284 285 $this->setRedirect( 'index.php?option=com_banners' ); 286 287 // Initialize variables 288 $db =& JFactory::getDBO(); 289 $post = JRequest::get( 'post' ); 290 $row =& JTable::getInstance('banner', 'Table'); 291 $row->bind( $post ); 292 $row->checkin(); 293 } 294 295 /** 296 * Copies one or more banners 297 */ 298 function copy() 299 { 300 // Check for request forgeries 301 JRequest::checkToken() or jexit( 'Invalid Token' ); 302 303 $this->setRedirect( 'index.php?option=com_banners' ); 304 305 $cid = JRequest::getVar( 'cid', null, 'post', 'array' ); 306 $db =& JFactory::getDBO(); 307 $table =& JTable::getInstance('banner', 'Table'); 308 $user = &JFactory::getUser(); 309 $n = count( $cid ); 310 311 if ($n > 0) 312 { 313 foreach ($cid as $id) 314 { 315 if ($table->load( (int)$id )) 316 { 317 $table->bid = 0; 318 $table->name = 'Copy of ' . $table->name; 319 $table->impmade = 0; 320 $table->clicks = 0; 321 $table->showBanner = 0; 322 $table->date = $db->getNullDate(); 323 324 if (!$table->store()) { 325 return JError::raiseWarning( $table->getError() ); 326 } 327 } 328 else { 329 return JError::raiseWarning( 500, $table->getError() ); 330 } 331 } 332 } 333 else { 334 return JError::raiseWarning( 500, JText::_( 'No items selected' ) ); 335 } 336 $this->setMessage( JText::sprintf( 'Items copied', $n ) ); 337 } 338 339 function publish() 340 { 341 // Check for request forgeries 342 JRequest::checkToken() or jexit( 'Invalid Token' ); 343 344 $this->setRedirect( 'index.php?option=com_banners' ); 345 346 // Initialize variables 347 $db =& JFactory::getDBO(); 348 $user =& JFactory::getUser(); 349 $cid = JRequest::getVar( 'cid', array(), 'post', 'array' ); 350 $task = JRequest::getCmd( 'task' ); 351 $publish = ($task == 'publish'); 352 $n = count( $cid ); 353 354 if (empty( $cid )) { 355 return JError::raiseWarning( 500, JText::_( 'No items selected' ) ); 356 } 357 358 JArrayHelper::toInteger( $cid ); 359 $cids = implode( ',', $cid ); 360 361 $query = 'UPDATE #__banner' 362 . ' SET showBanner = ' . (int) $publish 363 . ' WHERE bid IN ( '. $cids.' )' 364 . ' AND ( checked_out = 0 OR ( checked_out = ' .(int) $user->get('id'). ' ) )' 365 ; 366 $db->setQuery( $query ); 367 if (!$db->query()) { 368 return JError::raiseWarning( 500, $db->getError() ); 369 } 370 $this->setMessage( JText::sprintf( $publish ? 'Items published' : 'Items unpublished', $n ) ); 371 } 372 373 function remove() 374 { 375 // Check for request forgeries 376 JRequest::checkToken() or jexit( 'Invalid Token' ); 377 378 $this->setRedirect( 'index.php?option=com_banners' ); 379 380 // Initialize variables 381 $db =& JFactory::getDBO(); 382 $cid = JRequest::getVar( 'cid', array(), 'post', 'array' ); 383 $n = count( $cid ); 384 JArrayHelper::toInteger( $cid ); 385 386 if ($n) 387 { 388 $query = 'DELETE FROM #__banner' 389 . ' WHERE bid = ' . implode( ' OR bid = ', $cid ) 390 ; 391 $db->setQuery( $query ); 392 if (!$db->query()) { 393 JError::raiseWarning( 500, $db->getError() ); 394 } 395 } 396 397 $this->setMessage( JText::sprintf( 'Items removed', $n ) ); 398 } 399 400 /** 401 * Save the new order given by user 402 */ 403 function saveOrder() 404 { 405 // Check for request forgeries 406 JRequest::checkToken() or jexit( 'Invalid Token' ); 407 408 $this->setRedirect( 'index.php?option=com_banners' ); 409 410 // Initialize variables 411 $db =& JFactory::getDBO(); 412 $cid = JRequest::getVar( 'cid', array(), 'post', 'array' ); 413 $order = JRequest::getVar( 'order', array(), 'post', 'array' ); 414 $row =& JTable::getInstance('banner', 'Table'); 415 $total = count( $cid ); 416 $conditions = array(); 417 418 if (empty( $cid )) { 419 return JError::raiseWarning( 500, JText::_( 'No items selected' ) ); 420 } 421 422 // update ordering values 423 for ($i = 0; $i < $total; $i++) 424 { 425 $row->load( (int) $cid[$i] ); 426 if ($row->ordering != $order[$i]) 427 { 428 $row->ordering = $order[$i]; 429 if (!$row->store()) { 430 return JError::raiseError( 500, $db->getErrorMsg() ); 431 } 432 // remember to reorder this category 433 $condition = 'catid = '.(int) $row->catid; 434 $found = false; 435 foreach ($conditions as $cond) { 436 if ($cond[1] == $condition) 437 { 438 $found = true; 439 break; 440 } 441 } 442 if (!$found) { 443 $conditions[] = array ( $row->bid, $condition ); 444 } 445 } 446 } 447 448 // execute reorder for each category 449 foreach ($conditions as $cond) 450 { 451 $row->load( $cond[0] ); 452 $row->reorder( $cond[1] ); 453 } 454 455 // Clear the component's cache 456 $cache =& JFactory::getCache('com_banners'); 457 $cache->clean(); 458 459 $this->setMessage( JText::_('New ordering saved') ); 460 } 461 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Wed Mar 28 15:54:07 2012 | Cross-referenced by PHPXref 0.7.1 |