[ Index ] |
|
Code source de Joomla 1.0.13 |
1 <?php 2 /** 3 * @version $Id: admin.categories.php 5876 2006-11-29 00:21:35Z facedancer $ 4 * @package Joomla 5 * @subpackage Categories 6 * @copyright Copyright (C) 2005 Open Source Matters. All rights reserved. 7 * @license http://www.gnu.org/copyleft/gpl.html 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( '_VALID_MOS' ) or die( 'Restricted access' ); 17 18 require_once( $mainframe->getPath( 'admin_html' ) ); 19 20 define( 'COM_IMAGE_BASE', $mosConfig_absolute_path . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'stories' ); 21 22 // get parameters from the URL or submitted form 23 $section = stripslashes( strval( mosGetParam( $_REQUEST, 'section', 'content' ) ) ); 24 25 $cid = josGetArrayInts( 'cid' ); 26 27 switch ($task) { 28 case 'new': 29 editCategory( 0, $section ); 30 break; 31 32 case 'edit': 33 editCategory( intval( $cid[0] ) ); 34 break; 35 36 case 'editA': 37 editCategory( intval( $id ) ); 38 break; 39 40 case 'moveselect': 41 moveCategorySelect( $option, $cid, $section ); 42 break; 43 44 case 'movesave': 45 moveCategorySave( $cid, $section ); 46 break; 47 48 case 'copyselect': 49 copyCategorySelect( $option, $cid, $section ); 50 break; 51 52 case 'copysave': 53 copyCategorySave( $cid, $section ); 54 break; 55 56 case 'go2menu': 57 case 'go2menuitem': 58 case 'menulink': 59 case 'save': 60 case 'apply': 61 saveCategory( $task ); 62 break; 63 64 case 'remove': 65 removeCategories( $section, $cid ); 66 break; 67 68 case 'publish': 69 publishCategories( $section, $id, $cid, 1 ); 70 break; 71 72 case 'unpublish': 73 publishCategories( $section, $id, $cid, 0 ); 74 break; 75 76 case 'cancel': 77 cancelCategory(); 78 break; 79 80 case 'orderup': 81 orderCategory( intval( $cid[0] ), -1 ); 82 break; 83 84 case 'orderdown': 85 orderCategory( intval( $cid[0] ), 1 ); 86 break; 87 88 case 'accesspublic': 89 accessMenu( intval( $cid[0] ), 0, $section ); 90 break; 91 92 case 'accessregistered': 93 accessMenu( intval( $cid[0] ), 1, $section ); 94 break; 95 96 case 'accessspecial': 97 accessMenu( intval( $cid[0] ), 2, $section ); 98 break; 99 100 case 'saveorder': 101 saveOrder( $cid, $section ); 102 break; 103 104 default: 105 showCategories( $section, $option ); 106 break; 107 } 108 109 /** 110 * Compiles a list of categories for a section 111 * @param string The name of the category section 112 */ 113 function showCategories( $section, $option ) { 114 global $database, $mainframe, $mosConfig_list_limit, $mosConfig_absolute_path, $mosConfig_dbprefix; 115 116 $sectionid = intval( $mainframe->getUserStateFromRequest( "sectionid{$option}{$section}", 'sectionid', 0 ) ); 117 $limit = intval( $mainframe->getUserStateFromRequest( "viewlistlimit", 'limit', $mosConfig_list_limit ) ); 118 $limitstart = intval( $mainframe->getUserStateFromRequest( "view{$section}limitstart", 'limitstart', 0 ) ); 119 120 $section_name = ''; 121 $content_add = ''; 122 $content_join = ''; 123 $order = "\n ORDER BY c.ordering, c.name"; 124 if (intval( $section ) > 0) { 125 $table = 'content'; 126 127 $query = "SELECT name" 128 . "\n FROM #__sections" 129 . "\n WHERE id = " . (int) $section 130 ; 131 $database->setQuery( $query ); 132 $section_name = $database->loadResult(); 133 $section_name = 'Content: '. $section_name; 134 $where = "\n WHERE c.section = " . $database->Quote( $section ); 135 $type = 'content'; 136 } else if (strpos( $section, 'com_' ) === 0) { 137 $table = substr( $section, 4 ); 138 139 $query = "SELECT name" 140 . "\n FROM #__components" 141 . "\n WHERE link = 'option=" . $database->getEscaped( $section ) . "'" 142 ; 143 $database->setQuery( $query ); 144 $section_name = $database->loadResult(); 145 $where = "\n WHERE c.section = " . $database->Quote( $section ); 146 $type = 'other'; 147 // special handling for contact component 148 if ( $section == 'com_contact_details' ) { 149 $section_name = 'Contact'; 150 } 151 $section_name = 'Component: '. $section_name; 152 } else { 153 $table = $section; 154 $where = "\n WHERE c.section = " . $database->Quote( $section ); 155 $type = 'other'; 156 } 157 158 // get the total number of records 159 $query = "SELECT COUNT(*)" 160 . "\n FROM #__categories" 161 . "\n WHERE section = " . $database->Quote( $section ) 162 ; 163 $database->setQuery( $query ); 164 $total = $database->loadResult(); 165 166 // allows for viweing of all content categories 167 if ( $section == 'content' ) { 168 $table = 'content'; 169 $content_add = "\n , z.title AS section_name"; 170 $content_join = "\n LEFT JOIN #__sections AS z ON z.id = c.section"; 171 //$where = "\n WHERE s1.catid = c.id"; 172 $where = "\n WHERE c.section NOT LIKE '%com_%'"; 173 $order = "\n ORDER BY c.section, c.ordering, c.name"; 174 $section_name = 'All Content'; 175 // get the total number of records 176 $query = "SELECT COUNT(*)" 177 . "\n FROM #__categories" 178 . "\n INNER JOIN #__sections AS s ON s.id = section"; 179 if ( $sectionid > 0 ) { 180 $query .= "\n WHERE section = " . $database->Quote( $sectionid ); 181 } 182 $database->setQuery( $query ); 183 $total = $database->loadResult(); 184 $type = 'content'; 185 } 186 187 // used by filter 188 if ( $sectionid > 0 ) { 189 $filter = "\n AND c.section = " . $database->Quote( $sectionid ); 190 } else { 191 $filter = ''; 192 } 193 194 require_once ( $mosConfig_absolute_path . '/administrator/includes/pageNavigation.php' ); 195 $pageNav = new mosPageNav( $total, $limitstart, $limit ); 196 197 $tablesAllowed = $database->getTableList(); 198 if (!in_array( $mosConfig_dbprefix . $table, $tablesAllowed )) { 199 $table = 'content'; 200 } 201 $query = "SELECT c.*, c.checked_out as checked_out_contact_category, g.name AS groupname, u.name AS editor," 202 . "COUNT( DISTINCT s2.checked_out ) AS checked_out" 203 . $content_add 204 . "\n FROM #__categories AS c" 205 . "\n LEFT JOIN #__users AS u ON u.id = c.checked_out" 206 . "\n LEFT JOIN #__groups AS g ON g.id = c.access" 207 . "\n LEFT JOIN `#__$table` AS s2 ON s2.catid = c.id AND s2.checked_out > 0" 208 . $content_join 209 . $where 210 . $filter 211 . "\n AND c.published != -2" 212 . "\n GROUP BY c.id" 213 . $order 214 ; 215 $database->setQuery( $query, $pageNav->limitstart, $pageNav->limit ); 216 $rows = $database->loadObjectList(); 217 if ($database->getErrorNum()) { 218 echo $database->stderr(); 219 return; 220 } 221 222 $count = count( $rows ); 223 // number of Active Items 224 for ( $i = 0; $i < $count; $i++ ) { 225 $query = "SELECT COUNT( a.id )" 226 . "\n FROM #__content AS a" 227 . "\n WHERE a.catid = " . (int) $rows[$i]->id 228 . "\n AND a.state != -2" 229 ; 230 $database->setQuery( $query ); 231 $active = $database->loadResult(); 232 $rows[$i]->active = $active; 233 } 234 // number of Trashed Items 235 for ( $i = 0; $i < $count; $i++ ) { 236 $query = "SELECT COUNT( a.id )" 237 . "\n FROM #__content AS a" 238 . "\n WHERE a.catid = " . (int) $rows[$i]->id 239 . "\n AND a.state = -2" 240 ; 241 $database->setQuery( $query ); 242 $trash = $database->loadResult(); 243 $rows[$i]->trash = $trash; 244 } 245 246 // get list of sections for dropdown filter 247 $javascript = 'onchange="document.adminForm.submit();"'; 248 $lists['sectionid'] = mosAdminMenus::SelectSection( 'sectionid', $sectionid, $javascript ); 249 250 categories_html::show( $rows, $section, $section_name, $pageNav, $lists, $type ); 251 } 252 253 /** 254 * Compiles information to add or edit a category 255 * @param string The name of the category section 256 * @param integer The unique id of the category to edit (0 if new) 257 * @param string The name of the current user 258 */ 259 function editCategory( $uid=0, $section='' ) { 260 global $database, $my, $mainframe; 261 262 $type = strval( mosGetParam( $_REQUEST, 'type', '' ) ); 263 $redirect = strval( mosGetParam( $_REQUEST, 'section', 'content' ) ); 264 265 // check for existance of any sections 266 $query = "SELECT COUNT( id )" 267 . "\n FROM #__sections" 268 . "\n WHERE scope = 'content'" 269 ; 270 $database->setQuery( $query ); 271 $sections = $database->loadResult(); 272 if (!$sections && $type != 'other') { 273 echo "<script> alert('You need to have at least one Section before you can create a Category'); window.history.go(-1); </script>\n"; 274 exit(); 275 } 276 277 $row = new mosCategory( $database ); 278 // load the row from the db table 279 $row->load( (int)$uid ); 280 281 // fail if checked out not by 'me' 282 if ($row->checked_out && $row->checked_out != $my->id) { 283 mosRedirect( 'index2.php?option=categories§ion='. $row->section, 'The category '. $row->title .' is currently being edited by another administrator' ); 284 } 285 286 $lists['links'] = 0; 287 $menus = NULL; 288 $selected_folders = NULL; 289 if ( $uid ) { 290 // existing record 291 $row->checkout( $my->id ); 292 293 // code for Link Menu 294 switch ( $row->section ) { 295 case 'com_weblinks': 296 $and = "\n AND type = 'weblink_category_table'"; 297 $link = 'Table - Weblink Category'; 298 break; 299 300 case 'com_newsfeeds': 301 $and = "\n AND type = 'newsfeed_category_table'"; 302 $link = 'Table - Newsfeeds Category'; 303 break; 304 305 case 'com_contact_details': 306 $and = "\n AND type = 'contact_category_table'"; 307 $link = 'Table - Contacts Category'; 308 break; 309 310 default: 311 $and = ''; 312 $link = ''; 313 break; 314 } 315 316 // content 317 if ( $row->section > 0 ) { 318 $query = "SELECT *" 319 . "\n FROM #__menu" 320 . "\n WHERE componentid = " . (int) $row->id 321 . "\n AND ( type = 'content_archive_category' OR type = 'content_blog_category' OR type = 'content_category' )" 322 ; 323 $database->setQuery( $query ); 324 $menus = $database->loadObjectList(); 325 326 $count = count( $menus ); 327 for( $i = 0; $i < $count; $i++ ) { 328 switch ( $menus[$i]->type ) { 329 case 'content_category': 330 $menus[$i]->type = 'Table - Content Category'; 331 break; 332 333 case 'content_blog_category': 334 $menus[$i]->type = 'Blog - Content Category'; 335 break; 336 337 case 'content_archive_category': 338 $menus[$i]->type = 'Blog - Content Category Archive'; 339 break; 340 } 341 } 342 $lists['links'] = 1; 343 344 // handling for MOSImage directories 345 if ( trim( $row->params ) ) { 346 // get params definitions 347 $params = new mosParameters( $row->params, $mainframe->getPath( 'com_xml', 'com_categories' ), 'component' ); 348 $temps = $params->get( 'imagefolders', '' ); 349 350 $temps = explode( ',', $temps ); 351 foreach( $temps as $temp ) { 352 $selected_folders[] = mosHTML::makeOption( $temp, $temp ); 353 } 354 } else { 355 $selected_folders[] = mosHTML::makeOption( '*2*' ); 356 } 357 } else { 358 $query = "SELECT *" 359 . "\n FROM #__menu" 360 . "\n WHERE componentid = " . (int) $row->id 361 . $and 362 ; 363 $database->setQuery( $query ); 364 $menus = $database->loadObjectList(); 365 366 $count = count( $menus ); 367 for( $i = 0; $i < $count; $i++ ) { 368 $menus[$i]->type = $link; 369 } 370 $lists['links'] = 1; 371 } 372 } else { 373 // new record 374 $row->section = $section; 375 $row->published = 1; 376 $menus = NULL; 377 378 // handling for MOSImage directories 379 if ( $row->section == 'content' ) { 380 $selected_folders[] = mosHTML::makeOption( '*2*' ); 381 } 382 } 383 384 // make order list 385 $order = array(); 386 $query = "SELECT COUNT(*)" 387 . "\n FROM #__categories" 388 . "\n WHERE section = " . $database->Quote( $row->section ) 389 ; 390 $database->setQuery( $query ); 391 $max = intval( $database->loadResult() ) + 1; 392 393 for ($i=1; $i < $max; $i++) { 394 $order[] = mosHTML::makeOption( $i ); 395 } 396 397 // build the html select list for sections 398 if ( $section == 'content' ) { 399 $query = "SELECT s.id AS value, s.title AS text" 400 . "\n FROM #__sections AS s" 401 . "\n ORDER BY s.ordering" 402 ; 403 $database->setQuery( $query ); 404 $sections = $database->loadObjectList(); 405 $lists['section'] = mosHTML::selectList( $sections, 'section', 'class="inputbox" size="1"', 'value', 'text' );; 406 } else { 407 if ( $type == 'other' ) { 408 $section_name = 'N/A'; 409 } else { 410 $temp = new mosSection( $database ); 411 $temp->load( $row->section ); 412 $section_name = $temp->name; 413 } 414 $lists['section'] = '<input type="hidden" name="section" value="'. $row->section .'" />'. $section_name; 415 } 416 417 // build the html select list for category types 418 $types[] = mosHTML::makeOption( '', 'Select Type' ); 419 if ($row->section == 'com_contact_details') { 420 $types[] = mosHTML::makeOption( 'contact_category_table', 'Contact Category Table' ); 421 } else 422 if ($row->section == 'com_newsfeeds') { 423 $types[] = mosHTML::makeOption( 'newsfeed_category_table', 'Newsfeed Category Table' ); 424 } else 425 if ($row->section == 'com_weblinks') { 426 $types[] = mosHTML::makeOption( 'weblink_category_table', 'Weblink Category Table' ); 427 } else { 428 $types[] = mosHTML::makeOption( 'content_category', 'Content Category Table' ); 429 $types[] = mosHTML::makeOption( 'content_blog_category', 'Content Category Blog' ); 430 $types[] = mosHTML::makeOption( 'content_archive_category', 'Content Category Archive Blog' ); 431 } // if 432 $lists['link_type'] = mosHTML::selectList( $types, 'link_type', 'class="inputbox" size="1"', 'value', 'text' ); 433 434 // build the html select list for ordering 435 $query = "SELECT ordering AS value, title AS text" 436 . "\n FROM #__categories" 437 . "\n WHERE section = " . $database->Quote( $row->section ) 438 . "\n ORDER BY ordering" 439 ; 440 $lists['ordering'] = stripslashes( mosAdminMenus::SpecificOrdering( $row, $uid, $query )); 441 442 // build the select list for the image positions 443 $active = ( $row->image_position ? $row->image_position : 'left' ); 444 $lists['image_position'] = mosAdminMenus::Positions( 'image_position', $active, NULL, 0, 0 ); 445 // Imagelist 446 $lists['image'] = mosAdminMenus::Images( 'image', $row->image ); 447 // build the html select list for the group access 448 $lists['access'] = mosAdminMenus::Access( $row ); 449 // build the html radio buttons for published 450 $lists['published'] = mosHTML::yesnoRadioList( 'published', 'class="inputbox"', $row->published ); 451 // build the html select list for menu selection 452 $lists['menuselect'] = mosAdminMenus::MenuSelect( ); 453 454 // handling for MOSImage directories 455 if ( $row->section > 0 || $row->section == 'content' ) { 456 // list of folders in images/stories/ 457 $imgFiles = recursive_listdir( COM_IMAGE_BASE ); 458 $len = strlen( COM_IMAGE_BASE ); 459 460 $folders[] = mosHTML::makeOption( '*2*', 'Use Section settings' ); 461 $folders[] = mosHTML::makeOption( '*#*', '---------------------' ); 462 $folders[] = mosHTML::makeOption( '*1*', 'All' ); 463 $folders[] = mosHTML::makeOption( '*0*', 'None' ); 464 $folders[] = mosHTML::makeOption( '*#*', '---------------------' ); 465 $folders[] = mosHTML::makeOption( '/' ); 466 foreach ($imgFiles as $file) { 467 $folders[] = mosHTML::makeOption( substr( $file, $len ) ); 468 } 469 470 $lists['folders'] = mosHTML::selectList( $folders, 'folders[]', 'class="inputbox" size="17" multiple="multiple"', 'value', 'text', $selected_folders ); 471 } 472 473 categories_html::edit( $row, $lists, $redirect, $menus ); 474 } 475 476 /** 477 * Saves the catefory after an edit form submit 478 * @param string The name of the category section 479 */ 480 function saveCategory( $task ) { 481 global $database; 482 483 $menu = strval( mosGetParam( $_POST, 'menu', 'mainmenu' ) ); 484 $menuid = intval( mosGetParam( $_POST, 'menuid', 0 ) ); 485 $redirect = strval( mosGetParam( $_POST, 'redirect', '' ) ); 486 $oldtitle = stripslashes( strval( mosGetParam( $_POST, 'oldtitle', null ) ) ); 487 488 $row = new mosCategory( $database ); 489 if (!$row->bind( $_POST, 'folders' )) { 490 echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n"; 491 exit(); 492 } 493 $row->title = addslashes( $row->title ); 494 $row->name = addslashes( $row->name ); 495 496 // handling for MOSImage directories 497 if ( $row->section > 0 ) { 498 $folders = mosGetParam( $_POST, 'folders', array() ); 499 $folders = implode( ',', $folders ); 500 501 if ( strpos( $folders, '*2*' ) !== false ) { 502 $folders = '*2*'; 503 } else if ( strpos( $folders, '*1*' ) !== false ) { 504 $folders = '*1*'; 505 } else if ( strpos( $folders, '*0*' ) !== false ) { 506 $folders = '*0*'; 507 } else if ( strpos( $folders, ',*#*' ) !== false ) { 508 $folders = str_replace( ',*#*', '', $folders ); 509 } else if ( strpos( $folders, '*#*,' ) !== false ) { 510 $folders = str_replace( '*#*,', '', $folders ); 511 } else if ( strpos( $folders, '*#*' ) !== false ) { 512 $folders = str_replace( '*#*', '', $folders ); 513 } 514 515 $row->params = 'imagefolders='. $folders; 516 } 517 518 if (!$row->check()) { 519 echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n"; 520 exit(); 521 } 522 523 if (!$row->store()) { 524 echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n"; 525 exit(); 526 } 527 528 $row->checkin(); 529 $row->updateOrder( "section = " . $database->Quote( $row->section ) ); 530 531 if ( $oldtitle ) { 532 if ($oldtitle != $row->title) { 533 $query = "UPDATE #__menu" 534 . "\n SET name = " . $database->Quote( $row->title ) 535 . "\n WHERE name = " . $database->Quote( $oldtitle ) 536 . "\n AND type = 'content_category'" 537 ; 538 $database->setQuery( $query ); 539 $database->query(); 540 } 541 } 542 543 // Update Section Count 544 if ($row->section != 'com_contact_details' && 545 $row->section != 'com_newsfeeds' && 546 $row->section != 'com_weblinks') { 547 $query = "UPDATE #__sections SET count=count+1" 548 . "\n WHERE id = " . $database->Quote( $row->section ) 549 ; 550 $database->setQuery( $query ); 551 } 552 if (!$database->query()) { 553 echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n"; 554 exit(); 555 } 556 557 if ($redirect == 'content') { 558 // clean any existing cache files 559 mosCache::cleanCache( 'com_content' ); 560 } 561 562 switch ( $task ) { 563 case 'go2menu': 564 mosRedirect( 'index2.php?option=com_menus&menutype='. $menu ); 565 break; 566 567 case 'go2menuitem': 568 mosRedirect( 'index2.php?option=com_menus&menutype='. $menu .'&task=edit&hidemainmenu=1&id='. $menuid ); 569 break; 570 571 case 'menulink': 572 menuLink( $row->id ); 573 break; 574 575 case 'apply': 576 $msg = 'Changes to Category saved'; 577 mosRedirect( 'index2.php?option=com_categories§ion='. $redirect .'&task=editA&hidemainmenu=1&id='. $row->id, $msg ); 578 break; 579 580 case 'save': 581 default: 582 $msg = 'Category saved'; 583 mosRedirect( 'index2.php?option=com_categories§ion='. $redirect, $msg ); 584 break; 585 } 586 } 587 588 /** 589 * Deletes one or more categories from the categories table 590 * @param string The name of the category section 591 * @param array An array of unique category id numbers 592 */ 593 function removeCategories( $section, $cid ) { 594 global $database, $mosConfig_dbprefix; 595 596 if (count( $cid ) < 1) { 597 echo "<script> alert('Select a category to delete'); window.history.go(-1);</script>\n"; 598 exit; 599 } 600 601 if (intval( $section ) > 0) { 602 $table = 'content'; 603 } else if (strpos( $section, 'com_' ) === 0) { 604 $table = substr( $section, 4 ); 605 } else { 606 $table = $section; 607 } 608 609 $tablesAllowed = $database->getTableList(); 610 if (!in_array( $mosConfig_dbprefix . $table, $tablesAllowed )) { 611 $table = 'content'; 612 } 613 mosArrayToInts( $cid ); 614 $cids = 'c.id=' . implode( ' OR c.id=', $cid ); 615 $query = "SELECT c.id, c.name, COUNT( s.catid ) AS numcat" 616 . "\n FROM #__categories AS c" 617 . "\n LEFT JOIN `#__$table` AS s ON s.catid = c.id" 618 . "\n WHERE ( $cids )" 619 . "\n GROUP BY c.id" 620 ; 621 $database->setQuery( $query ); 622 623 if (!($rows = $database->loadObjectList())) { 624 echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n"; 625 } 626 627 $err = array(); 628 $cid = array(); 629 foreach ($rows as $row) { 630 if ($row->numcat == 0) { 631 $cid[] = $row->id; 632 } else { 633 $err[] = $row->name; 634 } 635 } 636 637 if (count( $cid )) { 638 mosArrayToInts( $cid ); 639 $cids = 'id=' . implode( ' OR id=', $cid ); 640 $query = "DELETE FROM #__categories" 641 . "\n WHERE ( $cids )" 642 ; 643 $database->setQuery( $query ); 644 if (!$database->query()) { 645 echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n"; 646 } 647 } 648 649 if ($section == 'content') { 650 // clean any existing cache files 651 mosCache::cleanCache( 'com_content' ); 652 } 653 654 if (count( $err )) { 655 $cids = implode( "\', \'", $err ); 656 $msg = 'Category(s): '. $cids .' cannot be removed as they contain records'; 657 mosRedirect( 'index2.php?option=com_categories§ion='. $section .'&mosmsg='. $msg ); 658 } 659 660 mosRedirect( 'index2.php?option=com_categories§ion='. $section ); 661 } 662 663 /** 664 * Publishes or Unpublishes one or more categories 665 * @param string The name of the category section 666 * @param integer A unique category id (passed from an edit form) 667 * @param array An array of unique category id numbers 668 * @param integer 0 if unpublishing, 1 if publishing 669 * @param string The name of the current user 670 */ 671 function publishCategories( $section, $categoryid=null, $cid=null, $publish=1 ) { 672 global $database, $my; 673 674 if (!is_array( $cid )) { 675 $cid = array(); 676 } 677 if ($categoryid) { 678 $cid[] = $categoryid; 679 } 680 681 if (count( $cid ) < 1) { 682 $action = $publish ? 'publish' : 'unpublish'; 683 echo "<script> alert('Select a category to $action'); window.history.go(-1);</script>\n"; 684 exit; 685 } 686 687 mosArrayToInts( $cid ); 688 $cids = 'id=' . implode( ' OR id=', $cid ); 689 690 $query = "UPDATE #__categories" 691 . "\n SET published = " . (int) $publish 692 . "\n WHERE ( $cids )" 693 . "\n AND ( checked_out = 0 OR ( checked_out = " . (int) $my->id . " ) )" 694 ; 695 $database->setQuery( $query ); 696 if (!$database->query()) { 697 echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n"; 698 exit(); 699 } 700 701 if (count( $cid ) == 1) { 702 $row = new mosCategory( $database ); 703 $row->checkin( $cid[0] ); 704 } 705 706 if ($section == 'content') { 707 // clean any existing cache files 708 mosCache::cleanCache( 'com_content' ); 709 } 710 711 mosRedirect( 'index2.php?option=com_categories§ion='. $section ); 712 } 713 714 /** 715 * Cancels an edit operation 716 * @param string The name of the category section 717 * @param integer A unique category id 718 */ 719 function cancelCategory() { 720 global $database; 721 722 $redirect = strval( mosGetParam( $_POST, 'redirect', '' ) ); 723 724 $row = new mosCategory( $database ); 725 $row->bind( $_POST ); 726 $row->checkin(); 727 728 mosRedirect( 'index2.php?option=com_categories§ion='. $redirect ); 729 } 730 731 /** 732 * Moves the order of a record 733 * @param integer The increment to reorder by 734 */ 735 function orderCategory( $uid, $inc ) { 736 global $database; 737 738 $row = new mosCategory( $database ); 739 $row->load( (int)$uid ); 740 $row->move( $inc, "section = " . $database->Quote( $row->section ) ); 741 742 // clean any existing cache files 743 mosCache::cleanCache( 'com_content' ); 744 745 mosRedirect( 'index2.php?option=com_categories§ion='. $row->section ); 746 } 747 748 /** 749 * Form for moving item(s) to a specific menu 750 */ 751 function moveCategorySelect( $option, $cid, $sectionOld ) { 752 global $database; 753 754 $redirect = mosGetParam( $_POST, 'section', 'content' );; 755 756 if (!is_array( $cid ) || count( $cid ) < 1) { 757 echo "<script> alert('Select an item to move'); window.history.go(-1);</script>\n"; 758 exit; 759 } 760 761 ## query to list selected categories 762 mosArrayToInts( $cid ); 763 $cids = 'a.id=' . implode( ' OR a.id=', $cid ); 764 $query = "SELECT a.name, a.section" 765 . "\n FROM #__categories AS a" 766 . "\n WHERE ( $cids )" 767 ; 768 $database->setQuery( $query ); 769 $items = $database->loadObjectList(); 770 771 ## query to list items from categories 772 // mosArrayToInts( $cid ); // Just done a few lines earlier 773 $cids = 'a.catid=' . implode( ' OR a.catid=', $cid ); 774 $query = "SELECT a.title" 775 . "\n FROM #__content AS a" 776 . "\n WHERE ( $cids )" 777 . "\n ORDER BY a.catid, a.title" 778 ; 779 $database->setQuery( $query ); 780 $contents = $database->loadObjectList(); 781 782 ## query to choose section to move to 783 $query = "SELECT a.name AS text, a.id AS value" 784 . "\n FROM #__sections AS a" 785 . "\n WHERE a.published = 1" 786 . "\n ORDER BY a.name" 787 ; 788 $database->setQuery( $query ); 789 $sections = $database->loadObjectList(); 790 791 // build the html select list 792 $SectionList = mosHTML::selectList( $sections, 'sectionmove', 'class="inputbox" size="10"', 'value', 'text', null ); 793 794 categories_html::moveCategorySelect( $option, $cid, $SectionList, $items, $sectionOld, $contents, $redirect ); 795 } 796 797 798 /** 799 * Save the item(s) to the menu selected 800 */ 801 function moveCategorySave( $cid, $sectionOld ) { 802 global $database; 803 804 if (!is_array( $cid ) || count( $cid ) < 1) { 805 echo "<script> alert('Select an item to move'); window.history.go(-1);</script>\n"; 806 exit; 807 } 808 809 $sectionMove = intval( mosGetParam( $_REQUEST, 'sectionmove', '' ) ); 810 if ( !$sectionMove ) { 811 mosRedirect( 'index.php?option=com_categories&mosmsg=An error has occurred' ); 812 } 813 814 $total = count( $cid ); 815 816 mosArrayToInts( $cid ); 817 $cids = 'id=' . implode( ' OR id=', $cid ); 818 $query = "UPDATE #__categories" 819 . "\n SET section = " . $sectionMove 820 . "\n WHERE ( $cids )" 821 ; 822 $database->setQuery( $query ); 823 if ( !$database->query() ) { 824 echo "<script> alert('". $database->getErrorMsg() ."'); window.history.go(-1); </script>\n"; 825 exit(); 826 } 827 // mosArrayToInts( $cid ); // Just done a few lines earlier 828 $cids = 'catid=' . implode( ' OR catid=', $cid ); 829 $query = "UPDATE #__content" 830 . "\n SET sectionid = " . $sectionMove 831 . "\n WHERE ( $cids )" 832 ; 833 $database->setQuery( $query ); 834 if ( !$database->query() ) { 835 echo "<script> alert('". $database->getErrorMsg() ."'); window.history.go(-1); </script>\n"; 836 exit(); 837 } 838 $sectionNew = new mosSection ( $database ); 839 $sectionNew->load( $sectionMove ); 840 841 if ($sectionOld == 'content') { 842 // clean any existing cache files 843 mosCache::cleanCache( 'com_content' ); 844 } 845 846 $msg = ( (count($cid) - 1) ? 'Categories' : 'Category' ) .' moved to '. $sectionNew->name; 847 mosRedirect( 'index2.php?option=com_categories§ion='. $sectionOld .'&mosmsg='. $msg ); 848 } 849 850 /** 851 * Form for copying item(s) to a specific menu 852 */ 853 function copyCategorySelect( $option, $cid, $sectionOld ) { 854 global $database; 855 856 $redirect = mosGetParam( $_POST, 'section', 'content' );; 857 858 if (!is_array( $cid ) || count( $cid ) < 1) { 859 echo "<script> alert('Select an item to move'); window.history.go(-1);</script>\n"; 860 exit; 861 } 862 863 ## query to list selected categories 864 mosArrayToInts( $cid ); 865 $cids = 'a.id=' . implode( ' OR a.id=', $cid ); 866 $query = "SELECT a.name, a.section" 867 . "\n FROM #__categories AS a" 868 . "\n WHERE ( $cids )" 869 ; 870 $database->setQuery( $query ); 871 $items = $database->loadObjectList(); 872 873 ## query to list items from categories 874 // mosArrayToInts( $cid ); // Just done a few lines earlier 875 $cids = 'a.catid=' . implode( ' OR a.catid=', $cid ); 876 $query = "SELECT a.title, a.id" 877 . "\n FROM #__content AS a" 878 . "\n WHERE ( $cids )" 879 . "\n ORDER BY a.catid, a.title" 880 ; 881 $database->setQuery( $query ); 882 $contents = $database->loadObjectList(); 883 884 ## query to choose section to move to 885 $query = "SELECT a.name AS `text`, a.id AS `value`" 886 . "\n FROM #__sections AS a" 887 . "\n WHERE a.published = 1" 888 . "\n ORDER BY a.name" 889 ; 890 $database->setQuery( $query ); 891 $sections = $database->loadObjectList(); 892 893 // build the html select list 894 $SectionList = mosHTML::selectList( $sections, 'sectionmove', 'class="inputbox" size="10"', 'value', 'text', null ); 895 896 categories_html::copyCategorySelect( $option, $cid, $SectionList, $items, $sectionOld, $contents, $redirect ); 897 } 898 899 900 /** 901 * Save the item(s) to the menu selected 902 */ 903 function copyCategorySave( $cid, $sectionOld ) { 904 global $database; 905 906 $sectionMove = intval( mosGetParam( $_REQUEST, 'sectionmove', '' ) ); 907 if ( !$sectionMove ) { 908 mosRedirect( 'index.php?option=com_categories&mosmsg=An error has occurred' ); 909 } 910 911 $contentid = josGetArrayInts( 'item', $_REQUEST ); 912 $total = count( $contentid ); 913 914 $category = new mosCategory ( $database ); 915 foreach( $cid as $id ) { 916 $category->load( (int)$id ); 917 $category->id = NULL; 918 $category->title = 'Copy of '. $category->title; 919 $category->name = 'Copy of '. $category->name; 920 $category->section = $sectionMove; 921 if (!$category->check()) { 922 echo "<script> alert('".$category->getError()."'); window.history.go(-1); </script>\n"; 923 exit(); 924 } 925 926 if (!$category->store()) { 927 echo "<script> alert('".$category->getError()."'); window.history.go(-1); </script>\n"; 928 exit(); 929 } 930 $category->checkin(); 931 // stores original catid 932 $newcatids[]["old"] = $id; 933 // pulls new catid 934 $newcatids[]["new"] = $category->id; 935 } 936 937 $content = new mosContent ( $database ); 938 foreach( $contentid as $id) { 939 $content->load( (int)$id ); 940 $content->id = NULL; 941 $content->sectionid = $sectionMove; 942 $content->hits = 0; 943 foreach( $newcatids as $newcatid ) { 944 if ( $content->catid == $newcatid['old'] ) { 945 $content->catid = $newcatid['new']; 946 } 947 } 948 if (!$content->check()) { 949 echo "<script> alert('".$content->getError()."'); window.history.go(-1); </script>\n"; 950 exit(); 951 } 952 953 if (!$content->store()) { 954 echo "<script> alert('".$content->getError()."'); window.history.go(-1); </script>\n"; 955 exit(); 956 } 957 $content->checkin(); 958 } 959 960 $sectionNew = new mosSection ( $database ); 961 $sectionNew->load( $sectionMove ); 962 963 if ($sectionOld == 'content') { 964 // clean any existing cache files 965 mosCache::cleanCache( 'com_content' ); 966 } 967 968 $msg = ( (count($cid) - 1) ? 'Categories' : 'Category' ) .' copied to '. $sectionNew->name; 969 mosRedirect( 'index2.php?option=com_categories§ion='. $sectionOld .'&mosmsg='. $msg ); 970 } 971 972 /** 973 * changes the access level of a record 974 * @param integer The increment to reorder by 975 */ 976 function accessMenu( $uid, $access, $section ) { 977 global $database; 978 979 $row = new mosCategory( $database ); 980 $row->load( (int)$uid ); 981 $row->access = $access; 982 983 if ( !$row->check() ) { 984 return $row->getError(); 985 } 986 if ( !$row->store() ) { 987 return $row->getError(); 988 } 989 990 if ($section == 'content') { 991 // clean any existing cache files 992 mosCache::cleanCache( 'com_content' ); 993 } 994 995 mosRedirect( 'index2.php?option=com_categories§ion='. $section ); 996 } 997 998 function menuLink( $id ) { 999 global $database; 1000 1001 $category = new mosCategory( $database ); 1002 $category->bind( $_POST ); 1003 $category->checkin(); 1004 1005 $redirect = strval( mosGetParam( $_POST, 'redirect', '' ) ); 1006 $menu = stripslashes( strval( mosGetParam( $_POST, 'menuselect', '' ) ) ); 1007 $name = strval( mosGetParam( $_POST, 'link_name', '' ) ); 1008 $sectionid = mosGetParam( $_POST, 'sectionid', '' ); 1009 $type = strval( mosGetParam( $_POST, 'link_type', '' ) ); 1010 1011 $name = stripslashes( ampReplace($name) ); 1012 1013 switch ( $type ) { 1014 case 'content_category': 1015 $link = 'index.php?option=com_content&task=category§ionid='. $sectionid .'&id='. $id; 1016 $menutype = 'Content Category Table'; 1017 break; 1018 1019 case 'content_blog_category': 1020 $link = 'index.php?option=com_content&task=blogcategory&id='. $id; 1021 $menutype = 'Content Category Blog'; 1022 break; 1023 1024 case 'content_archive_category': 1025 $link = 'index.php?option=com_content&task=archivecategory&id='. $id; 1026 $menutype = 'Content Category Blog Archive'; 1027 break; 1028 1029 case 'contact_category_table': 1030 $link = 'index.php?option=com_contact&catid='. $id; 1031 $menutype = 'Contact Category Table'; 1032 break; 1033 1034 case 'newsfeed_category_table': 1035 $link = 'index.php?option=com_newsfeeds&catid='. $id; 1036 $menutype = 'Newsfeed Category Table'; 1037 break; 1038 1039 case 'weblink_category_table': 1040 $link = 'index.php?option=com_weblinks&catid='. $id; 1041 $menutype = 'Weblink Category Table'; 1042 break; 1043 } 1044 1045 $row = new mosMenu( $database ); 1046 $row->menutype = $menu; 1047 $row->name = $name; 1048 $row->type = $type; 1049 $row->published = 1; 1050 $row->componentid = $id; 1051 $row->link = $link; 1052 $row->ordering = 9999; 1053 1054 if ( $type == 'content_blog_category' ) { 1055 $row->params = 'categoryid='. $id; 1056 } 1057 1058 if (!$row->check()) { 1059 echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n"; 1060 exit(); 1061 } 1062 if (!$row->store()) { 1063 echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n"; 1064 exit(); 1065 } 1066 $row->checkin(); 1067 $row->updateOrder( "menutype = " . $database->Quote( $menu ) ); 1068 1069 if ($redirect == 'content') { 1070 // clean any existing cache files 1071 mosCache::cleanCache( 'com_content' ); 1072 } 1073 1074 $msg = $name .' ( '. $menutype .' ) in menu: '. $menu .' successfully created'; 1075 mosRedirect( 'index2.php?option=com_categories§ion='. $redirect .'&task=editA&hidemainmenu=1&id='. $id, $msg ); 1076 } 1077 1078 function saveOrder( &$cid, $section ) { 1079 global $database; 1080 1081 $total = count( $cid ); 1082 $order = josGetArrayInts( 'order' ); 1083 1084 $row = new mosCategory( $database ); 1085 $conditions = array(); 1086 1087 // update ordering values 1088 for( $i=0; $i < $total; $i++ ) { 1089 $row->load( (int) $cid[$i] ); 1090 if ($row->ordering != $order[$i]) { 1091 $row->ordering = $order[$i]; 1092 if (!$row->store()) { 1093 echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n"; 1094 exit(); 1095 } // if 1096 // remember to updateOrder this group 1097 $condition = "section=" . $database->Quote( $row->section ); 1098 $found = false; 1099 foreach ( $conditions as $cond ) 1100 if ($cond[1]==$condition) { 1101 $found = true; 1102 break; 1103 } // if 1104 if (!$found) 1105 { 1106 $conditions[] = array( $row->id, $condition); 1107 } 1108 1109 } // if 1110 } // for 1111 1112 // execute updateOrder for each group 1113 foreach ( $conditions as $cond ) { 1114 $row->load( $cond[0] ); 1115 $row->updateOrder( $cond[1] ); 1116 } // foreach 1117 1118 if ($section == 'content') { 1119 // clean any existing cache files 1120 mosCache::cleanCache( 'com_content' ); 1121 } 1122 1123 $msg = 'New ordering saved'; 1124 mosRedirect( 'index2.php?option=com_categories§ion='. $section, $msg ); 1125 } // saveOrder 1126 1127 function recursive_listdir( $base ) { 1128 static $filelist = array(); 1129 static $dirlist = array(); 1130 1131 if(is_dir($base)) { 1132 $dh = opendir($base); 1133 while (false !== ($dir = readdir($dh))) { 1134 if ($dir !== '.' && $dir !== '..' && is_dir($base .'/'. $dir) && strtolower($dir) !== 'cvs' && strtolower($dir) !== '.svn') { 1135 $subbase = $base .'/'. $dir; 1136 $dirlist[] = $subbase; 1137 $subdirlist = recursive_listdir($subbase); 1138 } 1139 } 1140 closedir($dh); 1141 } 1142 return $dirlist; 1143 } 1144 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Wed Nov 21 14:43:32 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |