Files
@ f43d1a4680a9
Branch filter:
Location: hot67beta/administrator/components/com_sections/admin.sections.php
f43d1a4680a9
18.7 KiB
text/x-php
menubar 0 to 10
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 | <?php
/**
* @version $Id: admin.sections.php 10381 2008-06-01 03:35:53Z pasamio $
* @package Joomla
* @subpackage Sections
* @copyright Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
* @license GNU/GPL, see LICENSE.php
* Joomla! is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*/
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
require_once( JApplicationHelper::getPath( 'admin_html' ) );
// get parameters from the URL or submitted form
$scope = JRequest::getCmd( 'scope' );
$cid = JRequest::getVar( 'cid', array(0), '', 'array' );
JArrayHelper::toInteger($cid, array(0));
$task = JRequest::getCmd('task');
switch ($task)
{
case 'add' :
editSection(false );
break;
case 'edit':
editSection(true );
break;
case 'go2menu':
case 'go2menuitem':
case 'save':
case 'apply':
saveSection( $option, $scope, $task );
break;
case 'remove':
removeSections( $cid, $scope, $option );
break;
case 'copyselect':
copySectionSelect( $option, $cid, $scope );
break;
case 'copysave':
copySectionSave( $cid, $scope );
break;
case 'publish':
publishSections( $scope, $cid, 1, $option );
break;
case 'unpublish':
publishSections( $scope, $cid, 0, $option );
break;
case 'cancel':
cancelSection( $option, $scope );
break;
case 'orderup':
orderSection( $cid[0], -1, $option, $scope );
break;
case 'orderdown':
orderSection( $cid[0], 1, $option, $scope );
break;
case 'accesspublic':
accessMenu( $cid[0], 0, $option );
break;
case 'accessregistered':
accessMenu( $cid[0], 1, $option );
break;
case 'accessspecial':
accessMenu( $cid[0], 2, $option );
break;
case 'saveorder':
saveOrder( $cid );
break;
default:
showSections( $scope, $option );
break;
}
/**
* Compiles a list of categories for a section
* @param database A database connector object
* @param string The name of the category section
* @param string The name of the current user
*/
function showSections( $scope, $option )
{
global $mainframe;
$db =& JFactory::getDBO();
$user =& JFactory::getUser();
$filter_order = $mainframe->getUserStateFromRequest( $option.'.filter_order', 'filter_order', 's.ordering', 'cmd' );
$filter_order_Dir = $mainframe->getUserStateFromRequest( $option.'.filter_order_Dir', 'filter_order_Dir', '', 'word' );
$filter_state = $mainframe->getUserStateFromRequest( $option.'.filter_state', 'filter_state', '', 'word' );
$search = $mainframe->getUserStateFromRequest( $option.'.search', 'search', '', 'string' );
$search = JString::strtolower( $search );
$limit = $mainframe->getUserStateFromRequest( 'global.list.limit', 'limit', $mainframe->getCfg('list_limit'), 'int' );
$limitstart = $mainframe->getUserStateFromRequest( $option.'.limitstart', 'limitstart', 0, 'int' );
$where[] = 's.scope = '.$db->Quote($scope);
if ( $filter_state ) {
if ( $filter_state == 'P' ) {
$where[] = 's.published = 1';
} else if ($filter_state == 'U' ) {
$where[] = 's.published = 0';
}
}
if ($search) {
$where[] = 'LOWER(s.title) LIKE '.$db->Quote( '%'.$db->getEscaped( $search, true ).'%', false );
}
$where = ( count( $where ) ? ' WHERE ' . implode( ' AND ', $where ) : '' );
$orderby = ' ORDER BY '.$filter_order.' '. $filter_order_Dir .', s.ordering';
// get the total number of records
$query = 'SELECT COUNT(*)'
. ' FROM #__sections AS s'
. $where
;
$db->setQuery( $query );
$total = $db->loadResult();
jimport('joomla.html.pagination');
$pageNav = new JPagination( $total, $limitstart, $limit );
$query = 'SELECT s.*, g.name AS groupname, u.name AS editor'
. ' FROM #__sections AS s'
. ' LEFT JOIN #__content AS cc ON s.id = cc.sectionid'
. ' LEFT JOIN #__users AS u ON u.id = s.checked_out'
. ' LEFT JOIN #__groups AS g ON g.id = s.access'
. $where
. ' GROUP BY s.id'
. $orderby
;
$db->setQuery( $query, $pageNav->limitstart, $pageNav->limit );
$rows = $db->loadObjectList();
if ($db->getErrorNum()) {
echo $db->stderr();
return false;
}
$count = count( $rows );
// number of Active Categories
for ( $i = 0; $i < $count; $i++ ) {
$query = 'SELECT COUNT( a.id )'
. ' FROM #__categories AS a'
. ' WHERE a.section = '.$db->Quote($rows[$i]->id)
. ' AND a.published <> -2'
;
$db->setQuery( $query );
$active = $db->loadResult();
$rows[$i]->categories = $active;
}
// number of Active Items
for ( $i = 0; $i < $count; $i++ ) {
$query = 'SELECT COUNT( a.id )'
. ' FROM #__content AS a'
. ' WHERE a.sectionid = '.(int) $rows[$i]->id
. ' AND a.state <> -2'
;
$db->setQuery( $query );
$active = $db->loadResult();
$rows[$i]->active = $active;
}
// number of Trashed Items
for ( $i = 0; $i < $count; $i++ ) {
$query = 'SELECT COUNT( a.id )'
. ' FROM #__content AS a'
. ' WHERE a.sectionid = '.(int) $rows[$i]->id
. ' AND a.state = -2'
;
$db->setQuery( $query );
$trash = $db->loadResult();
$rows[$i]->trash = $trash;
}
// state filter
$lists['state'] = JHTML::_('grid.state', $filter_state );
// table ordering
$lists['order_Dir'] = $filter_order_Dir;
$lists['order'] = $filter_order;
// search filter
$lists['search']= $search;
sections_html::show( $rows, $scope, $user->get('id'), $pageNav, $option, $lists );
}
/**
* Compiles information to add or edit a section
* @param database A database connector object
* @param string The name of the category section
* @param integer The unique id of the category to edit (0 if new)
* @param string The name of the current user
*/
function editSection( $edit)
{
global $mainframe;
$db =& JFactory::getDBO();
$user =& JFactory::getUser();
$option = JRequest::getCmd( 'option');
$scope = JRequest::getCmd( 'scope' );
$cid = JRequest::getVar( 'cid', array(0), '', 'array' );
JArrayHelper::toInteger($cid, array(0));
$row =& JTable::getInstance('section');
// load the row from the db table
if ($edit)
$row->load( $cid[0] );
// fail if checked out not by 'me'
if ($row->isCheckedOut( $user->get('id') )) {
$msg = JText::sprintf( 'DESCBEINGEDITTED', JText::_( 'The section' ), $row->title );
$mainframe->redirect( 'index.php?option='. $option .'&scope='. $row->scope, $msg );
}
if ( $edit ) {
$row->checkout( $user->get('id') );
} else {
$row->scope = $scope;
$row->published = 1;
}
// build the html select list for ordering
$query = 'SELECT ordering AS value, title AS text'
. ' FROM #__sections'
. ' WHERE scope='.$db->Quote($row->scope).' ORDER BY ordering'
;
if($edit)
$lists['ordering'] = JHTML::_('list.specificordering', $row, $cid[0], $query );
else
$lists['ordering'] = JHTML::_('list.specificordering', $row, '', $query );
// build the select list for the image positions
$active = ( $row->image_position ? $row->image_position : 'left' );
$lists['image_position'] = JHTML::_('list.positions', 'image_position', $active, NULL, 0 );
// build the html select list for images
$lists['image'] = JHTML::_('list.images', 'image', $row->image );
// build the html select list for the group access
$lists['access'] = JHTML::_('list.accesslevel', $row );
// build the html radio buttons for published
$lists['published'] = JHTML::_('select.booleanlist', 'published', 'class="inputbox"', $row->published );
sections_html::edit( $row, $option, $lists );
}
/**
* Saves the catefory after an edit form submit
* @param database A database connector object
* @param string The name of the category section
*/
function saveSection( $option, $scope, $task )
{
global $mainframe;
// Check for request forgeries
JRequest::checkToken() or jexit( 'Invalid Token' );
$db =& JFactory::getDBO();
$menu = JRequest::getVar( 'menu', 'mainmenu', 'post', 'string' );
$menuid = JRequest::getVar( 'menuid', 0, 'post', 'int' );
$oldtitle = JRequest::getVar( 'oldtitle', '', '', 'post', 'string' );
$post = JRequest::get('post');
// fix up special html fields
$post['description'] = JRequest::getVar( 'description', '', 'post', 'string', JREQUEST_ALLOWRAW );
$row =& JTable::getInstance('section');
if (!$row->bind($post)) {
JError::raiseError(500, $row->getError() );
}
if (!$row->check()) {
JError::raiseError(500, $row->getError() );
}
if ( $oldtitle ) {
if ( $oldtitle <> $row->title ) {
$query = 'UPDATE #__menu'
. ' SET name = '.$db->Quote($row->title)
. ' WHERE name = '.$db->Quote($oldtitle)
. ' AND type = "content_section"'
;
$db->setQuery( $query );
$db->query();
}
}
// if new item order last in appropriate group
if (!$row->id) {
$row->ordering = $row->getNextOrder();
}
if (!$row->store()) {
JError::raiseError(500, $row->getError() );
}
$row->checkin();
switch ( $task )
{
case 'go2menu':
$mainframe->redirect( 'index.php?option=com_menus&menutype='. $menu );
break;
case 'go2menuitem':
$mainframe->redirect( 'index.php?option=com_menus&menutype='. $menu .'&task=edit&id='. $menuid );
break;
case 'apply':
$msg = JText::_( 'Changes to Section saved' );
$mainframe->redirect( 'index.php?option='. $option .'&scope='. $scope .'&task=edit&cid[]='. $row->id, $msg );
break;
case 'save':
default:
$msg = JText::_( 'Section saved' );
$mainframe->redirect( 'index.php?option='. $option .'&scope='. $scope, $msg );
break;
}
}
/**
* Deletes one or more categories from the categories table
* @param database A database connector object
* @param string The name of the category section
* @param array An array of unique category id numbers
*/
function removeSections( $cid, $scope, $option )
{
global $mainframe;
// Check for request forgeries
JRequest::checkToken() or jexit( 'Invalid Token' );
$db =& JFactory::getDBO();
if (count( $cid ) < 1) {
JError::raiseError(500, JText::_( 'Select a section to delete', true ) );
}
JArrayHelper::toInteger( $cid );
$cids = implode( ',', $cid );
$query = 'SELECT s.id, s.title, COUNT(c.id) AS numcat'
. ' FROM #__sections AS s'
. ' LEFT JOIN #__categories AS c ON c.section=s.id'
. ' WHERE s.id IN ( '.$cids.' )'
. ' GROUP BY s.id'
;
$db->setQuery( $query );
if (!($rows = $db->loadObjectList())) {
echo "<script> alert('".$db->getErrorMsg(true)."'); window.history.go(-1); </script>\n";
}
$name = array();
$err = array();
$cid = array();
foreach ($rows as $row) {
if ($row->numcat == 0) {
$cid[] = (int) $row->id;
$name[] = $row->title;
} else {
$err[] = $row->title;
}
}
if (count( $cid ))
{
$cids = implode( ',', $cid );
$query = 'DELETE FROM #__sections'
. ' WHERE id IN ( '.$cids.' )'
;
$db->setQuery( $query );
if (!$db->query()) {
echo "<script> alert('".$db->getErrorMsg(true)."'); window.history.go(-1); </script>\n";
}
}
if (count( $err ))
{
$cids = implode( ', ', $err );
$msg = JText::sprintf( 'DESCCANNOTBEREMOVED', $cids );
$mainframe->redirect( 'index.php?option='. $option .'&scope='. $scope, $msg );
}
$names = implode( ', ', $name );
$msg = JText::sprintf( 'Sections successfully deleted', $names );
$mainframe->redirect( 'index.php?option='. $option .'&scope='. $scope, $msg );
}
/**
* Publishes or Unpublishes one or more categories
* @param database A database connector object
* @param string The name of the category section
* @param integer A unique category id (passed from an edit form)
* @param array An array of unique category id numbers
* @param integer 0 if unpublishing, 1 if publishing
* @param string The name of the current user
*/
function publishSections( $scope, $cid=null, $publish=1, $option )
{
global $mainframe;
// Check for request forgeries
JRequest::checkToken() or jexit( 'Invalid Token' );
$db =& JFactory::getDBO();
$user =& JFactory::getUser();
JArrayHelper::toInteger($cid);
if ( count( $cid ) < 1 ) {
$action = $publish ? 'publish' : 'unpublish';
JError::raiseError(500, JText::_( 'Select a section to '.$action, true ) );
}
$cids = implode( ',', $cid );
$count = count( $cid );
$query = 'UPDATE #__sections'
. ' SET published = '.(int) $publish
. ' WHERE id IN ( '.$cids.' )'
. ' AND ( checked_out = 0 OR ( checked_out = '.(int) $user->get('id').' ) )'
;
$db->setQuery( $query );
if (!$db->query()) {
JError::raiseError(500, $db->getErrorMsg() );
}
if ( $count == 1 ) {
$row =& JTable::getInstance('section');
$row->checkin( $cid[0] );
}
// check if section linked to menu items if unpublishing
if ( $publish == 0 ) {
$query = 'SELECT id'
. ' FROM #__menu'
. ' WHERE type = "content_section"'
. ' AND componentid IN ( '.$cids.' )'
;
$db->setQuery( $query );
$menus = $db->loadObjectList();
if ($menus) {
foreach ($menus as $menu) {
$query = 'UPDATE #__menu'
. ' SET published = '.(int) $publish
. ' WHERE id = '.(int) $menu->id
;
$db->setQuery( $query );
$db->query();
}
}
}
$mainframe->redirect( 'index.php?option='. $option .'&scope='. $scope );
}
/**
* Cancels an edit operation
* @param database A database connector object
* @param string The name of the category section
* @param integer A unique category id
*/
function cancelSection( $option, $scope )
{
global $mainframe;
// Check for request forgeries
JRequest::checkToken() or jexit( 'Invalid Token' );
$db =& JFactory::getDBO();
$row =& JTable::getInstance('section');
$row->bind(JRequest::get('post'));
$row->checkin();
$mainframe->redirect( 'index.php?option='. $option .'&scope='. $scope );
}
/**
* Moves the order of a record
* @param integer The increment to reorder by
*/
function orderSection( $uid, $inc, $option, $scope )
{
global $mainframe;
// Check for request forgeries
JRequest::checkToken() or jexit( 'Invalid Token' );
$db =& JFactory::getDBO();
$row =& JTable::getInstance('section');
$row->load( $uid );
$row->move( $inc, 'scope = '.$db->Quote($row->scope) );
$mainframe->redirect( 'index.php?option='. $option .'&scope='. $scope );
}
/**
* Form for copying item(s) to a specific menu
*/
function copySectionSelect( $option, $cid, $section )
{
global $mainframe;
// Check for request forgeries
JRequest::checkToken() or jexit( 'Invalid Token' );
$db =& JFactory::getDBO();
JArrayHelper::toInteger($cid);
if ( count( $cid ) < 1) {
JError::raiseError(500, JText::_( 'Select an item to move', true ) );
}
## query to list selected categories
$cids = implode( ',', $cid );
$query = 'SELECT a.title, a.id'
. ' FROM #__categories AS a'
. ' WHERE a.section IN ( '.$cids.' )'
;
$db->setQuery( $query );
$categories = $db->loadObjectList();
## query to list items from categories
$query = 'SELECT a.title, a.id'
. ' FROM #__content AS a'
. ' WHERE a.sectionid IN ( '.$cids.' )'
. ' ORDER BY a.sectionid, a.catid, a.title'
;
$db->setQuery( $query );
$contents = $db->loadObjectList();
sections_html::copySectionSelect( $option, $cid, $categories, $contents, $section );
}
/**
* Save the item(s) to the menu selected
*/
function copySectionSave( $sectionid, $scope )
{
global $mainframe;
// Check for request forgeries
JRequest::checkToken() or jexit( 'Invalid Token' );
$db =& JFactory::getDBO();
$title = JRequest::getString( 'title' );
$contentid = JRequest::getVar( 'content' );
$categoryid = JRequest::getVar( 'category' );
JArrayHelper::toInteger($contentid);
JArrayHelper::toInteger($categoryid);
// copy section
$section =& JTable::getInstance('section');
foreach( $sectionid as $id ) {
$section->load( $id );
$section->id = NULL;
$section->title = $title;
$section->name = $title;
if ( !$section->check() ) {
copySectionSelect('com_sections', $sectionid, $scope );
JError::raiseWarning(500, $section->getError() );
return;
}
if ( !$section->store() ) {
JError::raiseError(500, $section->getError() );
}
$section->checkin();
$section->reorder( 'scope = '.$db->Quote($section->scope) );
// stores original catid
$newsectids[]["old"] = $id;
// pulls new catid
$newsectids[]["new"] = $section->id;
}
$sectionMove = $section->id;
// copy categories
$category =& JTable::getInstance('category');
foreach( $categoryid as $id ) {
$category->load( $id );
$category->id = NULL;
$category->section = $sectionMove;
foreach( $newsectids as $newsectid ) {
if ( $category->section == $newsectid["old"] ) {
$category->section = $newsectid["new"];
}
}
if (!$category->check()) {
JError::raiseError(500, $category->getError() );
}
if (!$category->store()) {
JError::raiseError(500, $category->getError() );
}
$category->checkin();
$category->reorder( 'section = '.$db->Quote($category->section) );
// stores original catid
$newcatids[]["old"] = $id;
// pulls new catid
$newcatids[]["new"] = $category->id;
}
$content =& JTable::getInstance('content');
foreach( $contentid as $id) {
$content->load( $id );
$content->id = NULL;
$content->hits = 0;
foreach( $newsectids as $newsectid ) {
if ( $content->sectionid == $newsectid["old"] ) {
$content->sectionid = $newsectid["new"];
}
}
foreach( $newcatids as $newcatid ) {
if ( $content->catid == $newcatid["old"] ) {
$content->catid = $newcatid["new"];
}
}
if (!$content->check()) {
JError::raiseError(500, $content->getError() );
}
if (!$content->store()) {
JError::raiseError(500, $content->getError() );
}
$content->checkin();
}
$sectionOld =& JTable::getInstance('section');
$sectionOld->load( $sectionMove );
$msg = JText::sprintf( 'DESCCATANDITEMSCOPIED', $sectionOld-> name, $title );
$mainframe->redirect( 'index.php?option=com_sections&scope=content', $msg );
}
/**
* changes the access level of a record
* @param integer The increment to reorder by
*/
function accessMenu( $uid, $access, $option )
{
global $mainframe;
// Check for request forgeries
JRequest::checkToken() or jexit( 'Invalid Token' );
$db =& JFactory::getDBO();
$row =& JTable::getInstance('section');
$row->load( $uid );
$row->access = $access;
if ( !$row->check() ) {
return $row->getError();
}
if ( !$row->store() ) {
return $row->getError();
}
$mainframe->redirect( 'index.php?option='. $option .'&scope='. $row->scope );
}
function saveOrder( &$cid )
{
global $mainframe;
// Check for request forgeries
JRequest::checkToken() or jexit( 'Invalid Token' );
$db =& JFactory::getDBO();
$row =& JTable::getInstance('section');
$total = count( $cid );
$order = JRequest::getVar( 'order', array(0), 'post', 'array' );
JArrayHelper::toInteger($order, array(0));
// update ordering values
for( $i=0; $i < $total; $i++ )
{
$row->load( (int) $cid[$i] );
if ($row->ordering != $order[$i]) {
$row->ordering = $order[$i];
if (!$row->store()) {
JError::raiseError(500, $db->getErrorMsg() );
}
}
}
$row->reorder( );
$msg = JText::_( 'New ordering saved' );
$mainframe->redirect( 'index.php?option=com_sections&scope=content', $msg );
}
|