| [ Index ] |
PHP Cross Reference of Joomla 1.5.26 DE |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * @version $Id: controller.php 19343 2010-11-03 18:12:02Z ian $ 4 * @package Joomla 5 * @subpackage Modules 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 $client = JRequest::getVar('client', 0, '', 'int'); 21 if ($client == 1) { 22 JSubMenuHelper::addEntry(JText::_('Site'), 'index.php?option=com_modules&client_id=0'); 23 JSubMenuHelper::addEntry(JText::_('Administrator'), 'index.php?option=com_modules&client=1', true ); 24 } else { 25 JSubMenuHelper::addEntry(JText::_('Site'), 'index.php?option=com_modules&client_id=0', true ); 26 JSubMenuHelper::addEntry(JText::_('Administrator'), 'index.php?option=com_modules&client=1'); 27 } 28 29 class ModulesController extends JController 30 { 31 /** 32 * Constructor 33 */ 34 function __construct( $config = array() ) 35 { 36 parent::__construct( $config ); 37 38 // Register Extra tasks 39 $this->registerTask( 'apply', 'save' ); 40 $this->registerTask( 'unpublish', 'publish' ); 41 $this->registerTask( 'orderup', 'reorder' ); 42 $this->registerTask( 'orderdown', 'reorder' ); 43 $this->registerTask( 'accesspublic', 'access' ); 44 $this->registerTask( 'accessregistered','access' ); 45 $this->registerTask( 'accessspecial', 'access' ); 46 } 47 48 /** 49 * Compiles a list of installed or defined modules 50 */ 51 function view() 52 { 53 global $mainframe; 54 55 // Initialize some variables 56 $db =& JFactory::getDBO(); 57 $client =& JApplicationHelper::getClientInfo(JRequest::getVar('client', '0', '', 'int')); 58 $option = 'com_modules'; 59 60 $filter_order = $mainframe->getUserStateFromRequest( $option.'filter_order', 'filter_order', 'm.position', 'cmd' ); 61 $filter_order_Dir = $mainframe->getUserStateFromRequest( $option.'filter_order_Dir', 'filter_order_Dir', '', 'word' ); 62 $filter_state = $mainframe->getUserStateFromRequest( $option.'filter_state', 'filter_state', '', 'word' ); 63 $filter_position = $mainframe->getUserStateFromRequest( $option.'filter_position', 'filter_position', '', 'cmd' ); 64 $filter_type = $mainframe->getUserStateFromRequest( $option.'filter_type', 'filter_type', '', 'cmd' ); 65 $filter_assigned = $mainframe->getUserStateFromRequest( $option.'filter_assigned', 'filter_assigned', '', 'cmd' ); 66 $search = $mainframe->getUserStateFromRequest( $option.'search', 'search', '', 'string' ); 67 if (strpos($search, '"') !== false) { 68 $search = str_replace(array('=', '<'), '', $search); 69 } 70 $search = JString::strtolower($search); 71 72 $limit = $mainframe->getUserStateFromRequest( 'global.list.limit', 'limit', $mainframe->getCfg('list_limit'), 'int' ); 73 $limitstart = $mainframe->getUserStateFromRequest( $option.'.limitstart', 'limitstart', 0, 'int' ); 74 75 $where[] = 'm.client_id = '.(int) $client->id; 76 77 $joins[] = 'LEFT JOIN #__users AS u ON u.id = m.checked_out'; 78 $joins[] = 'LEFT JOIN #__groups AS g ON g.id = m.access'; 79 $joins[] = 'LEFT JOIN #__modules_menu AS mm ON mm.moduleid = m.id'; 80 81 // used by filter 82 if ( $filter_assigned ) { 83 $joins[] = 'LEFT JOIN #__templates_menu AS t ON t.menuid = mm.menuid'; 84 $where[] = 't.template = '.$db->Quote($filter_assigned); 85 } 86 if ( $filter_position ) { 87 $where[] = 'm.position = '.$db->Quote($filter_position); 88 } 89 if ( $filter_type ) { 90 $where[] = 'm.module = '.$db->Quote($filter_type); 91 } 92 if ( $search ) { 93 $where[] = 'LOWER( m.title ) LIKE '.$db->Quote( '%'.$db->getEscaped( $search, true ).'%', false ); 94 } 95 if ( $filter_state ) { 96 if ( $filter_state == 'P' ) { 97 $where[] = 'm.published = 1'; 98 } else if ($filter_state == 'U' ) { 99 $where[] = 'm.published = 0'; 100 } 101 } 102 103 // sanitize $filter_order 104 if (!in_array($filter_order, array('m.title', 'm.published', 'm.ordering', 'groupname', 'm.position', 'pages', 'm.module', 'm.id'))) { 105 $filter_order = 'm.position'; 106 } 107 108 if (!in_array(strtoupper($filter_order_Dir), array('ASC', 'DESC', ''))) { 109 $filter_order_Dir = ''; 110 } 111 112 $where = ' WHERE ' . implode( ' AND ', $where ); 113 $join = ' ' . implode( ' ', $joins ); 114 if ($filter_order == 'm.ordering') { 115 $orderby = ' ORDER BY m.position, m.ordering '. $filter_order_Dir; 116 } else { 117 $orderby = ' ORDER BY '. $filter_order .' '. $filter_order_Dir .', m.ordering ASC'; 118 } 119 120 // get the total number of records 121 $query = 'SELECT COUNT(DISTINCT m.id)' 122 . ' FROM #__modules AS m' 123 . $join 124 . $where 125 ; 126 $db->setQuery( $query ); 127 $total = $db->loadResult(); 128 129 jimport('joomla.html.pagination'); 130 $pageNav = new JPagination( $total, $limitstart, $limit ); 131 132 $query = 'SELECT m.*, u.name AS editor, g.name AS groupname, MIN(mm.menuid) AS pages' 133 . ' FROM #__modules AS m' 134 . $join 135 . $where 136 . ' GROUP BY m.id' 137 . $orderby 138 ; 139 $db->setQuery( $query, $pageNav->limitstart, $pageNav->limit ); 140 $rows = $db->loadObjectList(); 141 if ($db->getErrorNum()) { 142 echo $db->stderr(); 143 return false; 144 } 145 146 // get list of Positions for dropdown filter 147 $query = 'SELECT m.position AS value, m.position AS text' 148 . ' FROM #__modules as m' 149 . ' WHERE m.client_id = '.(int) $client->id 150 . ' GROUP BY m.position' 151 . ' ORDER BY m.position' 152 ; 153 $positions[] = JHTML::_('select.option', '0', '- '. JText::_( 'Select Position' ) .' -' ); 154 $db->setQuery( $query ); 155 $positions = array_merge( $positions, $db->loadObjectList() ); 156 $lists['position'] = JHTML::_('select.genericlist', $positions, 'filter_position', 'class="inputbox" size="1" onchange="this.form.submit()"', 'value', 'text', "$filter_position" ); 157 158 // get list of Positions for dropdown filter 159 $query = 'SELECT module AS value, module AS text' 160 . ' FROM #__modules' 161 . ' WHERE client_id = '.(int) $client->id 162 . ' GROUP BY module' 163 . ' ORDER BY module' 164 ; 165 $db->setQuery( $query ); 166 $types[] = JHTML::_('select.option', '0', '- '. JText::_( 'Select Type' ) .' -' ); 167 $types = array_merge( $types, $db->loadObjectList() ); 168 $lists['type'] = JHTML::_('select.genericlist', $types, 'filter_type', 'class="inputbox" size="1" onchange="this.form.submit()"', 'value', 'text', "$filter_type" ); 169 170 // state filter 171 $lists['state'] = JHTML::_('grid.state', $filter_state ); 172 173 // template assignment filter 174 $query = 'SELECT DISTINCT(template) AS text, template AS value'. 175 ' FROM #__templates_menu' . 176 ' WHERE client_id = '.(int) $client->id; 177 $db->setQuery( $query ); 178 $assigned[] = JHTML::_('select.option', '0', '- '. JText::_( 'Select Template' ) .' -' ); 179 $assigned = array_merge( $assigned, $db->loadObjectList() ); 180 $lists['assigned'] = JHTML::_('select.genericlist', $assigned, 'filter_assigned', 'class="inputbox" size="1" onchange="this.form.submit()"', 'value', 'text', "$filter_assigned" ); 181 182 // table ordering 183 $lists['order_Dir'] = $filter_order_Dir; 184 $lists['order'] = $filter_order; 185 186 // search filter 187 $lists['search']= $search; 188 189 require_once( JApplicationHelper::getPath( 'admin_html' ) ); 190 HTML_modules::view( $rows, $client, $pageNav, $lists ); 191 } 192 193 /** 194 * Compiles information to add or edit a module 195 * @param string The current GET/POST option 196 * @param integer The unique id of the record to edit 197 */ 198 function copy() 199 { 200 // Check for request forgeries 201 JRequest::checkToken() or jexit( 'Invalid Token' ); 202 203 // Initialize some variables 204 $db =& JFactory::getDBO(); 205 $client =& JApplicationHelper::getClientInfo(JRequest::getVar('client', '0', '', 'int')); 206 $this->setRedirect( 'index.php?option=com_modules&client='.$client->id ); 207 208 $cid = JRequest::getVar( 'cid', array(), 'post', 'array' ); 209 $n = count( $cid ); 210 211 if ($n == 0) { 212 return JError::raiseWarning( 500, JText::_( 'No items selected' ) ); 213 } 214 215 $row =& JTable::getInstance('module'); 216 $tuples = array(); 217 218 foreach ($cid as $id) 219 { 220 // load the row from the db table 221 $row->load( (int) $id ); 222 $row->title = JText::sprintf( 'Copy of', $row->title ); 223 $row->id = 0; 224 $row->iscore = 0; 225 $row->published = 0; 226 227 if (!$row->check()) { 228 return JError::raiseWarning( 500, $row->getError() ); 229 } 230 if (!$row->store()) { 231 return JError::raiseWarning( 500, $row->getError() ); 232 } 233 $row->checkin(); 234 235 $row->reorder( 'position='.$db->Quote( $row->position ).' AND client_id='.(int) $client->id ); 236 237 $query = 'SELECT menuid' 238 . ' FROM #__modules_menu' 239 . ' WHERE moduleid = '.(int) $cid[0] 240 ; 241 $db->setQuery( $query ); 242 $rows = $db->loadResultArray(); 243 244 foreach ($rows as $menuid) { 245 $tuples[] = '('.(int) $row->id.','.(int) $menuid.')'; 246 } 247 } 248 249 if (!empty( $tuples )) 250 { 251 // Module-Menu Mapping: Do it in one query 252 $query = 'INSERT INTO #__modules_menu (moduleid,menuid) VALUES '.implode( ',', $tuples ); 253 $db->setQuery( $query ); 254 if (!$db->query()) { 255 return JError::raiseWarning( 500, $db->getError() ); 256 } 257 } 258 259 $msg = JText::sprintf( 'Items Copied', $n ); 260 $this->setRedirect( 'index.php?option=com_modules&client='. $client->id, $msg ); 261 } 262 263 /** 264 * Saves the module after an edit form submit 265 */ 266 function save() 267 { 268 // Check for request forgeries 269 JRequest::checkToken() or jexit( 'Invalid Token' ); 270 271 global $mainframe; 272 273 // Initialize some variables 274 $db =& JFactory::getDBO(); 275 $client =& JApplicationHelper::getClientInfo(JRequest::getVar('client', '0', '', 'int')); 276 $this->setRedirect( 'index.php?option=com_modules&client='.$client->id ); 277 278 $post = JRequest::get( 'post' ); 279 // fix up special html fields 280 $post['content'] = JRequest::getVar( 'content', '', 'post', 'string', JREQUEST_ALLOWRAW ); 281 $post['client_id'] = $client->id; 282 283 $row =& JTable::getInstance('module'); 284 285 if (!$row->bind( $post, 'selections' )) { 286 return JError::raiseWarning( 500, $row->getError() ); 287 } 288 289 if (!$row->check()) { 290 return JError::raiseWarning( 500, $row->getError() ); 291 } 292 293 // if new item, order last in appropriate group 294 if (!$row->id) { 295 $where = 'position='.$db->Quote( $row->position ).' AND client_id='.(int) $client->id ; 296 $row->ordering = $row->getNextOrder( $where ); 297 } 298 299 if (!$row->store()) { 300 return JError::raiseWarning( 500, $row->getError() ); 301 } 302 $row->checkin(); 303 304 $menus = JRequest::getVar( 'menus', '', 'post', 'word' ); 305 $selections = JRequest::getVar( 'selections', array(), 'post', 'array' ); 306 JArrayHelper::toInteger($selections); 307 308 // delete old module to menu item associations 309 $query = 'DELETE FROM #__modules_menu' 310 . ' WHERE moduleid = '.(int) $row->id 311 ; 312 $db->setQuery( $query ); 313 if (!$db->query()) { 314 return JError::raiseWarning( 500, $db->getError() ); 315 } 316 317 // check needed to stop a module being assigned to `All` 318 // and other menu items resulting in a module being displayed twice 319 if ( $menus == 'all' ) { 320 // assign new module to `all` menu item associations 321 $query = 'INSERT INTO #__modules_menu' 322 . ' SET moduleid = '.(int) $row->id.' , menuid = 0' 323 ; 324 $db->setQuery( $query ); 325 if (!$db->query()) { 326 return JError::raiseWarning( 500, $db->getError() ); 327 } 328 } 329 else 330 { 331 foreach ($selections as $menuid) 332 { 333 // this check for the blank spaces in the select box that have been added for cosmetic reasons 334 if ( (int) $menuid >= 0 ) { 335 // assign new module to menu item associations 336 $query = 'INSERT INTO #__modules_menu' 337 . ' SET moduleid = '.(int) $row->id .', menuid = '.(int) $menuid 338 ; 339 $db->setQuery( $query ); 340 if (!$db->query()) { 341 return JError::raiseWarning( 500, $db->getError() ); 342 } 343 } 344 } 345 } 346 347 // clean cache for all 3 front-end user groups (guest, reg, special) 348 $cache =& JFactory::getCache(); 349 $cache->remove($row->id . '0', $row->module); 350 $cache->remove($row->id . '1', $row->module); 351 $cache->remove($row->id . '2', $row->module); 352 // clean content cache because of loadposition plugin 353 $cache->clean( 'com_content' ); 354 355 $this->setMessage( JText::_( 'Item saved' ) ); 356 switch ($this->getTask()) 357 { 358 case 'apply': 359 $this->setRedirect( 'index.php?option=com_modules&client='. $client->id .'&task=edit&id='. $row->id ); 360 break; 361 } 362 } 363 364 /** 365 * Compiles information to add or edit a module 366 * @param string The current GET/POST option 367 * @param integer The unique id of the record to edit 368 */ 369 function edit( ) 370 { 371 // Initialize some variables 372 $db =& JFactory::getDBO(); 373 $user =& JFactory::getUser(); 374 375 $client =& JApplicationHelper::getClientInfo(JRequest::getVar('client', '0', '', 'int')); 376 $module = JRequest::getVar( 'module', '', '', 'cmd' ); 377 $id = JRequest::getVar( 'id', 0, 'method', 'int' ); 378 $cid = JRequest::getVar( 'cid', array( $id ), 'method', 'array' ); 379 JArrayHelper::toInteger($cid, array(0)); 380 381 $model = &$this->getModel('module'); 382 $model->setState( 'id', $cid[0] ); 383 $model->setState( 'clientId', $client->id ); 384 385 $lists = array(); 386 $row =& JTable::getInstance('module'); 387 // load the row from the db table 388 $row->load( (int) $cid[0] ); 389 // fail if checked out not by 'me' 390 if ($row->isCheckedOut( $user->get('id') )) { 391 $this->setRedirect( 'index.php?option=com_modules&client='.$client->id ); 392 return JError::raiseWarning( 500, JText::sprintf( 'DESCBEINGEDITTED', JText::_( 'The module' ), $row->title ) ); 393 } 394 395 $row->content = htmlspecialchars($row->content, ENT_COMPAT, 'UTF-8'); 396 397 if ( $cid[0] ) { 398 $row->checkout( $user->get('id') ); 399 } 400 // if a new record we must still prime the JTableModel object with a default 401 // position and the order; also add an extra item to the order list to 402 // place the 'new' record in last position if desired 403 if ($cid[0] == 0) { 404 $row->position = 'left'; 405 $row->showtitle = true; 406 $row->published = 1; 407 //$row->ordering = $l; 408 409 $row->module = $module; 410 } 411 412 if ($client->id == 1) 413 { 414 $where = 'client_id = 1'; 415 $lists['client_id'] = 1; 416 $path = 'mod1_xml'; 417 } 418 else 419 { 420 $where = 'client_id = 0'; 421 $lists['client_id'] = 0; 422 $path = 'mod0_xml'; 423 } 424 425 $query = 'SELECT position, ordering, showtitle, title' 426 . ' FROM #__modules' 427 . ' WHERE '. $where 428 . ' ORDER BY ordering' 429 ; 430 $db->setQuery( $query ); 431 $orders = $db->loadObjectList(); 432 if ($db->getErrorNum()) { 433 echo $db->stderr(); 434 return false; 435 } 436 437 $orders2 = array(); 438 439 $l = 0; 440 $r = 0; 441 for ($i=0, $n=count( $orders ); $i < $n; $i++) { 442 $ord = 0; 443 if (array_key_exists( $orders[$i]->position, $orders2 )) { 444 $ord =count( array_keys( $orders2[$orders[$i]->position] ) ) + 1; 445 } 446 447 $orders2[$orders[$i]->position][] = JHTML::_('select.option', $ord, $ord.'::'.addslashes( $orders[$i]->title ) ); 448 } 449 450 // get selected pages for $lists['selections'] 451 if ( $cid[0] ) { 452 $query = 'SELECT menuid AS value' 453 . ' FROM #__modules_menu' 454 . ' WHERE moduleid = '.(int) $row->id 455 ; 456 $db->setQuery( $query ); 457 $lookup = $db->loadObjectList(); 458 if (empty( $lookup )) { 459 $lookup = array( JHTML::_('select.option', '-1' ) ); 460 $row->pages = 'none'; 461 } elseif (count($lookup) == 1 && $lookup[0]->value == 0) { 462 $row->pages = 'all'; 463 } else { 464 $row->pages = null; 465 } 466 } else { 467 $lookup = array( JHTML::_('select.option', 0, JText::_( 'All' ) ) ); 468 $row->pages = 'all'; 469 } 470 471 if ( $row->access == 99 || $row->client_id == 1 || $lists['client_id'] ) { 472 $lists['access'] = 'Administrator'; 473 $lists['showtitle'] = 'N/A <input type="hidden" name="showtitle" value="1" />'; 474 $lists['selections'] = 'N/A'; 475 } else { 476 if ( $client->id == '1' ) { 477 $lists['access'] = 'N/A'; 478 $lists['selections'] = 'N/A'; 479 } else { 480 $lists['access'] = JHTML::_('list.accesslevel', $row ); 481 482 $selections = JHTML::_('menu.linkoptions'); 483 $lists['selections'] = JHTML::_('select.genericlist', $selections, 'selections[]', 'class="inputbox" size="15" multiple="multiple"', 'value', 'text', $lookup, 'selections' ); 484 } 485 $lists['showtitle'] = JHTML::_('select.booleanlist', 'showtitle', 'class="inputbox"', $row->showtitle ); 486 } 487 488 // build the html select list for published 489 $lists['published'] = JHTML::_('select.booleanlist', 'published', 'class="inputbox"', $row->published ); 490 491 $row->description = ''; 492 493 $lang =& JFactory::getLanguage(); 494 if ( $client->id != '1' ) { 495 $lang->load( trim($row->module), JPATH_SITE ); 496 } else { 497 $lang->load( trim($row->module) ); 498 } 499 500 // xml file for module 501 if ($row->module == 'custom') { 502 $xmlfile = JApplicationHelper::getPath( $path, 'mod_custom' ); 503 } else { 504 $xmlfile = JApplicationHelper::getPath( $path, $row->module ); 505 } 506 507 $data = JApplicationHelper::parseXMLInstallFile($xmlfile); 508 if ($data) 509 { 510 foreach($data as $key => $value) { 511 $row->$key = $value; 512 } 513 } 514 515 // get params definitions 516 $params = new JParameter( $row->params, $xmlfile, 'module' ); 517 518 require_once( JApplicationHelper::getPath( 'admin_html' ) ); 519 HTML_modules::edit( $model, $row, $orders2, $lists, $params, $client ); 520 } 521 522 /** 523 * Displays a list to select the creation of a new module 524 */ 525 function add() 526 { 527 global $mainframe; 528 529 // Initialize some variables 530 $modules = array(); 531 $client =& JApplicationHelper::getClientInfo(JRequest::getVar('client', '0', '', 'int')); 532 533 // path to search for modules 534 if ($client->id == '1') { 535 $path = JPATH_ADMINISTRATOR.DS.'modules'; 536 $langbase = JPATH_ADMINISTRATOR; 537 } else { 538 $path = JPATH_ROOT.DS.'modules'; 539 $langbase = JPATH_ROOT; 540 } 541 542 jimport('joomla.filesystem.folder'); 543 $dirs = JFolder::folders( $path ); 544 $lang =& JFactory::getLanguage(); 545 546 foreach ($dirs as $dir) 547 { 548 if (substr( $dir, 0, 4 ) == 'mod_') 549 { 550 $files = JFolder::files( $path.DS.$dir, '^([_A-Za-z0-9]*)\.xml$' ); 551 $module = new stdClass; 552 $module->file = $files[0]; 553 $module->module = str_replace( '.xml', '', $files[0] ); 554 $module->path = $path.DS.$dir; 555 $modules[] = $module; 556 557 $lang->load( $module->module, $langbase ); 558 } 559 } 560 561 require_once ( JPATH_COMPONENT.DS.'helpers'.DS.'xml.php' ); 562 ModulesHelperXML::parseXMLModuleFile( $modules, $client ); 563 564 $n = count($modules); 565 for ($i = 0; $i < $n; $i++) { 566 $modules[$i]->name = JText::_(stripslashes($modules[$i]->name)); 567 } 568 569 // sort array of objects alphabetically by name 570 JArrayHelper::sortObjects( $modules, 'name' ); 571 572 require_once( JApplicationHelper::getPath( 'admin_html' ) ); 573 HTML_modules::add( $modules, $client ); 574 } 575 576 /** 577 * Deletes one or more modules 578 * 579 * Also deletes associated entries in the #__module_menu table. 580 * @param array An array of unique category id numbers 581 */ 582 function remove() 583 { 584 global $mainframe; 585 586 // Check for request forgeries 587 JRequest::checkToken() or jexit( 'Invalid Token' ); 588 589 // Initialize some variables 590 $db =& JFactory::getDBO(); 591 $client =& JApplicationHelper::getClientInfo(JRequest::getVar('client', '0', '', 'int')); 592 $this->setRedirect( 'index.php?option=com_modules&client='.$client->id ); 593 594 $cid = JRequest::getVar( 'cid', array(), 'post', 'array' ); 595 JArrayHelper::toInteger( $cid ); 596 597 if (empty( $cid )) { 598 return JError::raiseWarning( 500, 'No items selected' ); 599 } 600 601 $cids = implode( ',', $cid ); 602 603 // pasamio: Disabled this as it breaks the uninstall ability! 604 /*$query = 'SELECT id, module, title, iscore, params' 605 . ' FROM #__modules WHERE id IN ('.$cids.')' 606 ; 607 $db->setQuery( $query ); 608 if (!($rows = $db->loadObjectList())) { 609 return JError::raiseError( 500, $db->getErrorMsg() ); 610 }*/ 611 612 // remove mappings first (lest we leave orphans) 613 $query = 'DELETE FROM #__modules_menu' 614 . ' WHERE moduleid IN ( '.$cids.' )' 615 ; 616 $db->setQuery( $query ); 617 if (!$db->query()) { 618 return JError::raiseError( 500, $db->getErrorMsg() ); 619 } 620 // remove module 621 $query = 'DELETE FROM #__modules' 622 . ' WHERE id IN ('.$cids.')' 623 ; 624 $db->setQuery( $query ); 625 if (!$db->query()) { 626 return JError::raiseError( 500, $db->getErrorMsg() ); 627 } 628 629 $this->setMessage( JText::sprintf( 'Items removed', count( $cid ) ) ); 630 } 631 632 /** 633 * Publishes or Unpublishes one or more modules 634 */ 635 function publish() 636 { 637 global $mainframe; 638 639 // Check for request forgeries 640 JRequest::checkToken() or jexit( 'Invalid Token' ); 641 642 // Initialize some variables 643 $db =& JFactory::getDBO(); 644 $user =& JFactory::getUser(); 645 $client =& JApplicationHelper::getClientInfo(JRequest::getVar('client', '0', '', 'int')); 646 $this->setRedirect( 'index.php?option=com_modules&client='.$client->id ); 647 648 $cache = & JFactory::getCache(); 649 $cache->clean( 'com_content' ); 650 651 $cid = JRequest::getVar( 'cid', array(), 'post', 'array' ); 652 JArrayHelper::toInteger($cid); 653 654 $task = $this->getTask(); 655 $publish = ($task == 'publish'); 656 657 if (empty( $cid )) { 658 return JError::raiseWarning( 500, 'No items selected' ); 659 } 660 661 $cids = implode( ',', $cid ); 662 663 $query = 'UPDATE #__modules' 664 . ' SET published = ' . intval( $publish ) 665 . ' WHERE id IN ( '.$cids.' )' 666 . ' AND ( checked_out = 0 OR ( checked_out = '.(int) $user->get('id').' ) )' 667 ; 668 $db->setQuery( $query ); 669 if (!$db->query()) { 670 return JError::raiseWarning( 500, $db->getErrorMsg() ); 671 } 672 673 if (count( $cid ) == 1) { 674 $row =& JTable::getInstance('module'); 675 $row->checkin( $cid[0] ); 676 } 677 } 678 679 /** 680 * Cancels an edit operation 681 */ 682 function cancel() 683 { 684 global $mainframe; 685 686 // Check for request forgeries 687 JRequest::checkToken() or jexit( 'Invalid Token' ); 688 689 // Initialize some variables 690 $db =& JFactory::getDBO(); 691 $client =& JApplicationHelper::getClientInfo(JRequest::getVar('client', '0', '', 'int')); 692 $this->setRedirect( 'index.php?option=com_modules&client='.$client->id ); 693 694 $row =& JTable::getInstance('module'); 695 // ignore array elements 696 $row->bind(JRequest::get('post'), 'selections params' ); 697 $row->checkin(); 698 } 699 700 /** 701 * Moves the order of a record 702 */ 703 function reorder() 704 { 705 global $mainframe; 706 707 // Check for request forgeries 708 JRequest::checkToken() or jexit( 'Invalid Token' ); 709 710 // Initialize some variables 711 $db =& JFactory::getDBO(); 712 $client =& JApplicationHelper::getClientInfo(JRequest::getVar('client', '0', '', 'int')); 713 $this->setRedirect( 'index.php?option=com_modules&client='.$client->id ); 714 715 $cid = JRequest::getVar( 'cid', array(), 'post', 'array' ); 716 JArrayHelper::toInteger($cid); 717 718 $task = $this->getTask(); 719 $inc = ($task == 'orderup' ? -1 : 1); 720 721 if (empty( $cid )) { 722 return JError::raiseWarning( 500, 'No items selected' ); 723 } 724 725 $row =& JTable::getInstance('module'); 726 $row->load( (int) $cid[0] ); 727 728 $row->move( $inc, 'position = '.$db->Quote( $row->position ).' AND client_id='.(int) $client->id ); 729 } 730 731 /** 732 * Changes the access level of a record 733 */ 734 function access() 735 { 736 global $mainframe; 737 738 // Check for request forgeries 739 JRequest::checkToken() or jexit( 'Invalid Token' ); 740 741 // Initialize some variables 742 $db =& JFactory::getDBO(); 743 $client =& JApplicationHelper::getClientInfo(JRequest::getVar('client', '0', '', 'int')); 744 $this->setRedirect( 'index.php?option=com_modules&client='.$client->id ); 745 746 $cid = JRequest::getVar( 'cid', array(), 'post', 'array' ); 747 JArrayHelper::toInteger($cid); 748 749 $task = JRequest::getCmd( 'task' ); 750 751 if (empty( $cid )) { 752 return JError::raiseWarning( 500, 'No items selected' ); 753 } 754 755 switch ( $task ) 756 { 757 case 'accesspublic': 758 $access = 0; 759 break; 760 761 case 'accessregistered': 762 $access = 1; 763 break; 764 765 case 'accessspecial': 766 $access = 2; 767 break; 768 } 769 770 $row =& JTable::getInstance('module'); 771 $row->load( (int) $cid[0] ); 772 $row->access = $access; 773 774 if ( !$row->check() ) { 775 JError::raiseWarning( 500, $row->getError() ); 776 } 777 if ( !$row->store() ) { 778 JError::raiseWarning( 500, $row->getError() ); 779 } 780 } 781 782 /** 783 * Saves the orders of the supplied list 784 */ 785 function saveOrder() 786 { 787 // Check for request forgeries 788 JRequest::checkToken() or jexit( 'Invalid Token' ); 789 790 // Initialize some variables 791 $db =& JFactory::getDBO(); 792 $client =& JApplicationHelper::getClientInfo(JRequest::getVar('client', '0', '', 'int')); 793 $this->setRedirect( 'index.php?option=com_modules&client='.$client->id ); 794 795 $cid = JRequest::getVar( 'cid', array(), 'post', 'array' ); 796 JArrayHelper::toInteger($cid); 797 798 if (empty( $cid )) { 799 return JError::raiseWarning( 500, 'No items selected' ); 800 } 801 802 $total = count( $cid ); 803 $row =& JTable::getInstance('module'); 804 $groupings = array(); 805 806 $order = JRequest::getVar( 'order', array(0), 'post', 'array' ); 807 JArrayHelper::toInteger($order); 808 809 // update ordering values 810 for ($i = 0; $i < $total; $i++) 811 { 812 $row->load( (int) $cid[$i] ); 813 // track postions 814 $groupings[] = $row->position; 815 816 if ($row->ordering != $order[$i]) 817 { 818 $row->ordering = $order[$i]; 819 if (!$row->store()) { 820 return JError::raiseWarning( 500, $db->getErrorMsg() ); 821 } 822 } 823 } 824 825 // execute updateOrder for each parent group 826 $groupings = array_unique( $groupings ); 827 foreach ($groupings as $group){ 828 $row->reorder('position = '.$db->Quote($group).' AND client_id = '.(int) $client->id); 829 } 830 831 $this->setMessage (JText::_( 'New ordering saved' )); 832 } 833 834 function preview() 835 { 836 $document =& JFactory::getDocument(); 837 $document->setTitle(JText::_('Module Preview')); 838 839 require_once( JApplicationHelper::getPath( 'admin_html' ) ); 840 HTML_modules::preview( ); 841 } 842 }
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 |