| [ Index ] | PHP Cross Reference of Mambo 4.6.5 |
|
| [ Variables ] [ Functions ] [ Classes ] [ Constants ] [ Statistics ] | ||
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * @package Mambo 4 * @subpackage Categories 5 * @author Mambo Foundation Inc see README.php 6 * @copyright (C) 2000 - 2009 Mambo Foundation Inc. 7 * See COPYRIGHT.php for copyright notices and details. 8 * @license GNU/GPL Version 2, see LICENSE.php 9 * 10 * Redistributions of files must retain the above copyright notice. 11 * 12 * Mambo is free software; you can redistribute it and/or 13 * modify it under the terms of the GNU General Public License 14 * as published by the Free Software Foundation; version 2 of the License. 15 */ 16 17 /** ensure this file is being included by a parent file */ 18 defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' ); 19 20 require_once( $mainframe->getPath( 'admin_html' ) ); 21 require_once ($mosConfig_absolute_path.'/components/com_content/content.class.php'); 22 23 // get parameters from the URL or submitted form 24 $section = mosGetParam( $_REQUEST, 'section', 'content' ); 25 $cid = mosGetParam( $_REQUEST, 'cid', array(0) ); 26 if (!$cid) $id = mosGetParam( $_REQUEST, 'id', 0 ); 27 28 switch ($task) { 29 case 'new': 30 editCategory( 0, $section ); 31 break; 32 33 case 'edit': 34 editCategory( intval( $cid[0] ) ); 35 break; 36 37 case 'editA': 38 editCategory( intval( $id ) ); 39 break; 40 41 case 'moveselect': 42 moveCategorySelect( $option, $cid, $section ); 43 break; 44 45 case 'movesave': 46 moveCategorySave( $cid, $section ); 47 break; 48 49 case 'copyselect': 50 copyCategorySelect( $option, $cid, $section ); 51 break; 52 53 case 'copysave': 54 copyCategorySave( $cid, $section ); 55 break; 56 57 case 'go2menu': 58 case 'go2menuitem': 59 case 'menulink': 60 case 'save': 61 case 'apply': 62 saveCategory( $task ); 63 break; 64 65 case 'remove': 66 removeCategories( $section, $cid ); 67 break; 68 69 case 'publish': 70 publishCategories( $section, $id, $cid, 1 ); 71 break; 72 73 case 'unpublish': 74 publishCategories( $section, $id, $cid, 0 ); 75 break; 76 77 case 'cancel': 78 cancelCategory(); 79 break; 80 81 case 'orderup': 82 orderCategory( $cid[0], -1 ); 83 break; 84 85 case 'orderdown': 86 orderCategory( $cid[0], 1 ); 87 break; 88 89 case 'accesspublic': 90 accessMenu( $cid[0], 0, $section ); 91 break; 92 93 case 'accessregistered': 94 accessMenu( $cid[0], 1, $section ); 95 break; 96 97 case 'accessspecial': 98 accessMenu( $cid[0], 2, $section ); 99 break; 100 101 case 'saveorder': 102 saveOrder( $cid, $section ); 103 break; 104 105 default: 106 showCategories( $section, $option ); 107 break; 108 } 109 110 /** 111 * Compiles a list of categories for a section 112 * @param string The name of the category section 113 */ 114 function showCategories( $section, $option ) { 115 global $database, $mainframe, $mosConfig_list_limit, $mosConfig_absolute_path; 116 117 $sectionid = $mainframe->getUserStateFromRequest( "sectionid{$option}{$section}", 'sectionid', 0 ); 118 $limit = $mainframe->getUserStateFromRequest( "viewlistlimit", 'limit', $mosConfig_list_limit ); 119 $limitstart = $mainframe->getUserStateFromRequest( "view{$section}limitstart", 'limitstart', 0 ); 120 121 $section_name = ''; 122 $content_add = ''; 123 $content_join = ''; 124 $order = "\n ORDER BY c.ordering, c.name"; 125 if (intval( $section ) > 0) { 126 $table = 'content'; 127 128 // @RawSQLUse, trivial_implementation, SELECT 129 $query = "SELECT name FROM #__sections WHERE id='$section'"; 130 $database->setQuery( $query ); 131 $section_name = $database->loadResult(); 132 $section_name = 'Content: '. $section_name; 133 $where = "\n WHERE c.section='$section'"; 134 $type = 'content'; 135 } else if (strpos( $section, 'com_' ) === 0) { 136 $table = substr( $section, 4 ); 137 138 // @RawSQLUse, trivial_implementation, SELECT 139 $query = "SELECT name FROM #__components WHERE link='option=$section'"; 140 $database->setQuery( $query ); 141 $section_name = $database->loadResult(); 142 $where = "\n WHERE c.section='$section'"; 143 $type = 'other'; 144 // special handling for contact component 145 if ( $section == 'com_contact_details' ) { 146 $section_name = T_('Contact'); 147 } 148 $section_name = T_('Component: '). $section_name; 149 } else { 150 $table = $section; 151 $where = "\n WHERE c.section='$section'"; 152 $type = 'other'; 153 } 154 155 // get the total number of records 156 // @RawSQLUse, trivial_implementation, SELECT 157 $query = "SELECT count(*) FROM #__categories WHERE section='$section'"; 158 $database->setQuery( $query ); 159 $total = $database->loadResult(); 160 161 // allows for viweing of all content categories 162 if ( $section == 'content' ) { 163 $table = 'content'; 164 $content_add = "\n , z.title AS section_name"; 165 $content_join = "\n LEFT JOIN #__sections AS z ON z.id = c.section"; 166 //$where = "\n WHERE s1.catid = c.id"; 167 $where = "\n WHERE c.section NOT LIKE '%com_%'"; 168 $order = "\n ORDER BY c.section, c.ordering, c.name"; 169 $section_name = 'All Content'; 170 // get the total number of records 171 $database->setQuery( "SELECT count(*) FROM #__categories INNER JOIN #__sections AS s ON s.id = section" ); 172 $total = $database->loadResult(); 173 $type = 'content'; 174 } 175 176 // used by filter 177 if ( $sectionid > 0 ) { 178 $filter = "\n AND c.section = '$sectionid'"; 179 } else { 180 $filter = ''; 181 } 182 183 require_once ( $mosConfig_absolute_path . '/administrator/includes/pageNavigation.php' ); 184 $pageNav = new mosPageNav( $total, $limitstart, $limit ); 185 186 $query = "SELECT c.*, c.checked_out as checked_out_contact_category, g.name AS groupname, u.name AS editor," 187 . "COUNT(DISTINCT s2.checked_out) AS checked_out" 188 . $content_add 189 . "\n FROM #__categories AS c" 190 . "\n LEFT JOIN #__users AS u ON u.id = c.checked_out" 191 . "\n LEFT JOIN #__groups AS g ON g.id = c.access" 192 //. "\n LEFT JOIN #__$table AS s1 ON s1.catid = c.id" 193 . "\n LEFT JOIN #__$table AS s2 ON s2.catid = c.id AND s2.checked_out > 0" 194 . $content_join 195 . $where 196 . $filter 197 . "\n AND c.published != -2" 198 . "\n GROUP BY c.id" 199 . $order 200 . "\n LIMIT $pageNav->limitstart, $pageNav->limit" 201 ; 202 $database->setQuery( $query ); 203 $rows = $database->loadObjectList(); 204 if ($rows) { 205 foreach($rows as $row) { 206 $row->name = htmlspecialchars( str_replace( '&', '&', $row->name ) ); 207 $row->title = htmlspecialchars( str_replace( '&', '&', $row->title ) ); 208 } 209 } 210 if ($database->getErrorNum()) { 211 echo $database->stderr(); 212 return; 213 } 214 215 $count = count( $rows ); 216 // number of Active Items 217 for ( $i = 0; $i < $count; $i++ ) { 218 $query = "SELECT COUNT( a.id )" 219 . "\n FROM #__content AS a" 220 . "\n WHERE a.catid = ". $rows[$i]->id 221 . "\n AND a.state <> '-2'" 222 ; 223 $database->setQuery( $query ); 224 $active = $database->loadResult(); 225 $rows[$i]->active = $active; 226 } 227 // number of Trashed Items 228 for ( $i = 0; $i < $count; $i++ ) { 229 // @RawSQLUse, trivial_implementation, SELECT 230 $query = "SELECT COUNT( a.id )" 231 . "\n FROM #__content AS a" 232 . "\n WHERE a.catid = ". $rows[$i]->id 233 . "\n AND a.state = '-2'" 234 ; 235 $database->setQuery( $query ); 236 $trash = $database->loadResult(); 237 $rows[$i]->trash = $trash; 238 } 239 240 // get list of sections for dropdown filter 241 $javascript = 'onchange="document.adminForm.submit();"'; 242 $lists['sectionid'] = mosAdminMenus::SelectSection( 'sectionid', $sectionid, $javascript ); 243 244 categories_html::show( $rows, $section, $section_name, $pageNav, $lists, $type ); 245 } 246 247 /** 248 * Compiles information to add or edit a category 249 * @param string The name of the category section 250 * @param integer The unique id of the category to edit (0 if new) 251 * @param string The name of the current user 252 */ 253 function editCategory( $uid=0, $section='' ) { 254 global $database, $my; 255 256 $type = mosGetParam( $_REQUEST, 'type', '' ); 257 $redirect = mosGetParam( $_REQUEST, 'section', 'content' ); 258 259 $row = new mosCategory( $database ); 260 // load the row from the db table 261 $row->load( $uid ); 262 263 // fail if checked out not by 'me' 264 if ($row->checked_out && $row->checked_out <> $my->id) { 265 mosRedirect( 'index2.php?option=categories§ion='. $row->section, sprintf(T_('The category %s is currently being edited by another administrator'), $row->title) ); 266 } 267 268 if ($uid) { 269 // existing record 270 $row->checkout( $my->id ); 271 // code for Link Menu 272 if ( $row->section > 0 ) { 273 $query = "SELECT *" 274 . "\n FROM #__menu" 275 . "\n WHERE componentid = ". $row->id 276 . "\n AND ( type = 'content_archive_category' OR type = 'content_blog_category' OR type = 'content_category' )" 277 ; 278 $database->setQuery( $query ); 279 $menus = $database->loadObjectList(); 280 $count = count( $menus ); 281 for( $i = 0; $i < $count; $i++ ) { 282 switch ( $menus[$i]->type ) { 283 case 'content_category': 284 $menus[$i]->type = T_('Category Table'); 285 break; 286 287 case 'content_blog_category': 288 $menus[$i]->type = T_('Category Blog'); 289 break; 290 291 case 'content_archive_category': 292 $menus[$i]->type = T_('Category Blog Archive'); 293 break; 294 } 295 } 296 } else { 297 $menus = array(); 298 } 299 } else { 300 // new record 301 $row->section = $section; 302 $row->published = 1; 303 $menus = NULL; 304 } 305 306 // make order list 307 $order = array(); 308 // @RawSQLUse, trivial_implementation, SELECT 309 $database->setQuery( "SELECT COUNT(*) FROM #__categories WHERE section='$row->section'" ); 310 $max = intval( $database->loadResult() ) + 1; 311 312 for ($i=1; $i < $max; $i++) { 313 $order[] = mosHTML::makeOption( $i ); 314 } 315 316 // build the html select list for sections 317 if ( $section == 'content' ) { 318 // @RawSQLUse, trivial_implementation, SELECT 319 $query = "SELECT s.id AS value, s.title AS text" 320 . "\n FROM #__sections AS s" 321 . "\n ORDER BY s.ordering" 322 ; 323 $database->setQuery( $query ); 324 $sections = $database->loadObjectList(); 325 $lists['section'] = mosHTML::selectList( $sections, 'section', 'class="inputbox" size="1"', 'value', 'text' );; 326 } else { 327 if ( $type == 'other' ) { 328 $section_name = 'N/A'; 329 } else { 330 $temp = new mosSection( $database ); 331 $temp->load( $row->section ); 332 $section_name = $temp->name; 333 } 334 $lists['section'] = '<input type="hidden" name="section" value="'. $row->section .'" />'. $section_name; 335 } 336 337 // build the html select list for category types 338 $types[] = mosHTML::makeOption( '', T_('Select Type') ); 339 if ($row->section == 'com_contact_details') { 340 $types[] = mosHTML::makeOption( 'contact_category_table', T_('Contact Category Table') ); 341 } else 342 if ($row->section == 'com_newsfeeds') { 343 $types[] = mosHTML::makeOption( 'newsfeed_category_table', T_('News Feed Category Table') ); 344 } else 345 if ($row->section == 'com_weblinks') { 346 $types[] = mosHTML::makeOption( 'weblink_category_table', T_('Web Link Category Table') ); 347 } else { 348 $types[] = mosHTML::makeOption( 'content_category', T_('Content Category Table') ); 349 $types[] = mosHTML::makeOption( 'content_blog_category', T_('Content Category Blog') ); 350 $types[] = mosHTML::makeOption( 'content_archive_category', T_('Content Category Archive Blog') ); 351 } // if 352 $lists['link_type'] = mosHTML::selectList( $types, 'link_type', 'class="inputbox" size="1"', 'value', 'text' );; 353 354 // build the html select list for ordering 355 // @RawSQLUse, trivial_implementation, SELECT, CONCEPT 356 $query = "SELECT ordering AS value, title AS text" 357 . "\n FROM #__categories" 358 . "\n WHERE section = '$row->section'" 359 . "\n ORDER BY ordering" 360 ; 361 $lists['ordering'] = mosAdminMenus::SpecificOrdering( $row, $uid, $query ); 362 363 // build the select list for the image positions 364 $active = ( $row->image_position ? $row->image_position : 'left' ); 365 $lists['image_position'] = mosAdminMenus::Positions( 'image_position', $active, NULL, 0, 0 ); 366 // Imagelist 367 $lists['image'] = mosAdminMenus::Images( 'image', $row->image ); 368 // build the html select list for the group access 369 $lists['access'] = mosAdminMenus::Access( $row ); 370 // build the html radio buttons for published 371 $lists['published'] = mosHTML::yesnoRadioList( 'published', 'class="inputbox"', $row->published ); 372 // build the html select list for menu selection 373 $lists['menuselect'] = mosAdminMenus::MenuSelect( ); 374 375 categories_html::edit( $row, $lists, $redirect, $menus ); 376 } 377 378 /** 379 * Saves the catefory after an edit form submit 380 * @param string The name of the category section 381 */ 382 function saveCategory( $task ) { 383 global $database; 384 385 $menu = mosGetParam( $_POST, 'menu', 'mainmenu' ); 386 $menuid = mosGetParam( $_POST, 'menuid', 0 ); 387 $redirect = mosGetParam( $_POST, 'redirect', '' ); 388 $oldtitle = mosGetParam( $_POST, 'oldtitle', null ); 389 390 $row = new mosCategory( $database ); 391 if (!$row->bind( $_POST )) { 392 echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n"; 393 exit(); 394 } 395 if (!$row->check()) { 396 echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n"; 397 exit(); 398 } 399 400 if (!$row->store()) { 401 echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n"; 402 exit(); 403 } 404 $row->checkin(); 405 $row->updateOrder( "section='$row->section'" ); 406 407 if ( $oldtitle ) { 408 if ($oldtitle != $row->title) { 409 // @RawSQLUse, trivial_implementation, UPDATE 410 $database->setQuery( "UPDATE #__menu SET name='$row->title' WHERE name='$oldtitle' AND type='content_category'" ); 411 $database->query(); 412 } 413 } 414 415 // Update Section Count 416 if ($row->section != 'com_contact_details' && 417 $row->section != 'com_newsfeeds' && 418 $row->section != 'com_weblinks') { 419 // @RawSQLUse, trivial_implementation, UPDATE, CONCEPT 420 $query = "UPDATE #__sections SET count=count+1" 421 . "\n WHERE id = '$row->section'" 422 ; 423 $database->setQuery( $query ); 424 } 425 426 if (!$database->query()) { 427 echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n"; 428 exit(); 429 } 430 431 switch ( $task ) { 432 case 'go2menu': 433 mosRedirect( 'index2.php?option=com_menus&menutype='. $menu ); 434 break; 435 436 case 'go2menuitem': 437 mosRedirect( 'index2.php?option=com_menus&menutype='. $menu .'&task=edit&hidemainmenu=1&id='. $menuid ); 438 break; 439 440 case 'menulink': 441 menuLink( $row->id ); 442 break; 443 444 case 'apply': 445 $msg = T_('Changes to Category saved'); 446 mosRedirect( 'index2.php?option=com_categories§ion='. $redirect .'&task=editA&hidemainmenu=1&id='. $row->id, $msg ); 447 break; 448 449 case 'save': 450 default: 451 $msg = T_('Category saved'); 452 mosRedirect( 'index2.php?option=com_categories§ion='. $redirect, $msg ); 453 break; 454 } 455 } 456 457 /** 458 * Deletes one or more categories from the categories table 459 * @param string The name of the category section 460 * @param array An array of unique category id numbers 461 */ 462 function removeCategories( $section, $cid ) { 463 global $database; 464 465 if (count( $cid ) < 1) { 466 echo "<script> alert('".T_('Select a category to delete')."'); window.history.go(-1);</script>\n"; 467 exit; 468 } 469 470 $cids = implode( ',', $cid ); 471 472 //Get Section ID prior to removing Category, in order to update counts 473 //$database->setQuery( "SELECT section FROM #__categories WHERE id IN ($cids)" ); 474 //$secid = $database->loadResult(); 475 476 if (intval( $section ) > 0) { 477 $table = 'content'; 478 } else if (strpos( $section, 'com_' ) === 0) { 479 $table = substr( $section, 4 ); 480 } else { 481 $table = $section; 482 } 483 484 $query = "SELECT c.id, c.name, COUNT(s.catid) AS numcat" 485 . "\n FROM #__categories AS c" 486 . "\n LEFT JOIN #__$table AS s ON s.catid=c.id" 487 . "\n WHERE c.id IN ($cids)" 488 . "\n GROUP BY c.id" 489 ; 490 $database->setQuery( $query ); 491 492 if (!($rows = $database->loadObjectList())) { 493 echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n"; 494 } 495 496 $err = array(); 497 $cid = array(); 498 foreach ($rows as $row) { 499 if ($row->numcat == 0) { 500 $cid[] = $row->id; 501 } else { 502 $err[] = $row->name; 503 } 504 } 505 506 if (count( $cid )) { 507 $cids = implode( ',', $cid ); 508 // @RawSQLUse, trivial_implementation, DELETE 509 $database->setQuery( "DELETE FROM #__categories WHERE id IN ($cids)" ); 510 if (!$database->query()) { 511 echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n"; 512 } 513 } 514 515 if (count( $err )) { 516 $cids = implode( "\', \'", $err ); 517 $msg = 'Category(s): '. $cids .' cannot be removed as they contain records'; 518 mosRedirect( 'index2.php?option=com_categories§ion='. $section .'&mosmsg='. $msg ); 519 } 520 521 mosRedirect( 'index2.php?option=com_categories§ion='. $section ); 522 } 523 524 /** 525 * Publishes or Unpublishes one or more categories 526 * @param string The name of the category section 527 * @param integer A unique category id (passed from an edit form) 528 * @param array An array of unique category id numbers 529 * @param integer 0 if unpublishing, 1 if publishing 530 * @param string The name of the current user 531 */ 532 function publishCategories( $section, $categoryid=null, $cid=null, $publish=1 ) { 533 global $database, $my; 534 535 if (!is_array( $cid )) { 536 $cid = array(); 537 } 538 if ($categoryid) { 539 $cid[] = $categoryid; 540 } 541 542 if (count( $cid ) < 1) { 543 $action = $publish ? T_('publish') : T_('unpublish'); 544 echo "<script> alert('".sprintf(T_('Select a category to %s'), $action)."'); window.history.go(-1);</script>\n"; 545 exit; 546 } 547 548 $cids = implode( ',', $cid ); 549 550 $query = "UPDATE #__categories SET published='$publish'" 551 . "\nWHERE id IN ($cids) AND (checked_out=0 OR (checked_out='$my->id'))" 552 ; 553 $database->setQuery( $query ); 554 if (!$database->query()) { 555 echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n"; 556 exit(); 557 } 558 559 if (count( $cid ) == 1) { 560 $row = new mosCategory( $database ); 561 $row->checkin( $cid[0] ); 562 } 563 564 mosRedirect( 'index2.php?option=com_categories§ion='. $section ); 565 } 566 567 /** 568 * Cancels an edit operation 569 * @param string The name of the category section 570 * @param integer A unique category id 571 */ 572 function cancelCategory() { 573 global $database; 574 575 $redirect = mosGetParam( $_POST, 'redirect', '' ); 576 577 $row = new mosCategory( $database ); 578 $row->bind( $_POST ); 579 // sanitize 580 $row->id = intval($row->id); 581 $row->checkin(); 582 mosRedirect( 'index2.php?option=com_categories§ion='. $redirect ); 583 } 584 585 /** 586 * Moves the order of a record 587 * @param integer The increment to reorder by 588 */ 589 function orderCategory( $uid, $inc ) { 590 global $database; 591 592 $row = new mosCategory( $database ); 593 $row->load( $uid ); 594 $row->move( $inc, "section='$row->section'" ); 595 mosRedirect( 'index2.php?option=com_categories§ion='. $row->section ); 596 } 597 598 /** 599 * Form for moving item(s) to a specific menu 600 */ 601 function moveCategorySelect( $option, $cid, $sectionOld ) { 602 global $database; 603 604 $redirect = mosGetParam( $_POST, 'section', 'content' );; 605 606 if (!is_array( $cid ) || count( $cid ) < 1) { 607 echo "<script> alert('".T_('Select an item to move')."'); window.history.go(-1);</script>\n"; 608 exit; 609 } 610 611 ## query to list selected categories 612 $cids = implode( ',', $cid ); 613 // @RawSQLUse, trivial_implementation, SELECT 614 $query = "SELECT a.name, a.section FROM #__categories AS a WHERE a.id IN ( ". $cids ." )"; 615 $database->setQuery( $query ); 616 $items = $database->loadObjectList(); 617 618 ## query to list items from categories 619 // @RawSQLUse, trivial_implementation, SELECT 620 $query = "SELECT a.title FROM #__content AS a WHERE a.catid IN ( ". $cids ." ) ORDER BY a.catid, a.title"; 621 $database->setQuery( $query ); 622 $contents = $database->loadObjectList(); 623 624 ## query to choose section to move to 625 // @RawSQLUse, trivial_implementation, SELECT 626 $query = "SELECT a.name AS `text`, a.id AS `value` FROM #__sections AS a WHERE a.published = '1' ORDER BY a.name"; 627 $database->setQuery( $query ); 628 $sections = $database->loadObjectList(); 629 630 // build the html select list 631 $SectionList = mosHTML::selectList( $sections, 'sectionmove', 'class="inputbox" size="10"', 'value', 'text', null ); 632 633 categories_html::moveCategorySelect( $option, $cid, $SectionList, $items, $sectionOld, $contents, $redirect ); 634 } 635 636 637 /** 638 * Save the item(s) to the menu selected 639 */ 640 function moveCategorySave( $cid, $sectionOld ) { 641 global $database; 642 643 $sectionMove = mosGetParam( $_REQUEST, 'sectionmove', '' ); 644 645 $cids = implode( ',', $cid ); 646 $total = count( $cid ); 647 648 // @RawSQLUse, trivial_implementation, UPDATE 649 $query = "UPDATE #__categories SET section = '". $sectionMove ."' " 650 . "WHERE id IN ( ". $cids ." )" 651 ; 652 $database->setQuery( $query ); 653 if ( !$database->query() ) { 654 echo "<script> alert('". $database->getErrorMsg() ."'); window.history.go(-1); </script>\n"; 655 exit(); 656 } 657 // @RawSQLUse, trivial_implementation, UPDATE 658 $query = "UPDATE #__content SET sectionid = '". $sectionMove ."' " 659 . "WHERE catid IN ( ". $cids ." )" 660 ; 661 $database->setQuery( $query ); 662 if ( !$database->query() ) { 663 echo "<script> alert('". $database->getErrorMsg() ."'); window.history.go(-1); </script>\n"; 664 exit(); 665 } 666 $sectionNew = new mosSection ( $database ); 667 $sectionNew->load( $sectionMove ); 668 669 $msg = $total ." Categories moved to ". $sectionNew->name; 670 mosRedirect( 'index2.php?option=com_categories§ion='. $sectionOld .'&mosmsg='. $msg ); 671 } 672 673 /** 674 * Form for copying item(s) to a specific menu 675 */ 676 function copyCategorySelect( $option, $cid, $sectionOld ) { 677 global $database; 678 679 $redirect = mosGetParam( $_POST, 'section', 'content' );; 680 681 if (!is_array( $cid ) || count( $cid ) < 1) { 682 echo "<script> alert('".T_('Select an item to move')."'); window.history.go(-1);</script>\n"; 683 exit; 684 } 685 686 ## query to list selected categories 687 $cids = implode( ',', $cid ); 688 // @RawSQLUse, trivial_implementation, SELECT 689 $query = "SELECT a.name, a.section FROM #__categories AS a WHERE a.id IN ( ". $cids ." )"; 690 $database->setQuery( $query ); 691 $items = $database->loadObjectList(); 692 693 ## query to list items from categories 694 // @RawSQLUse, trivial_implementation, SELECT 695 $query = "SELECT a.title, a.id FROM #__content AS a WHERE a.catid IN ( ". $cids ." ) ORDER BY a.catid, a.title"; 696 $database->setQuery( $query ); 697 $contents = $database->loadObjectList(); 698 699 ## query to choose section to move to 700 // @RawSQLUse, trivial_implementation, SELECT 701 $query = "SELECT a.name AS `text`, a.id AS `value` FROM #__sections AS a WHERE a.published = '1' ORDER BY a.name"; 702 $database->setQuery( $query ); 703 $sections = $database->loadObjectList(); 704 705 // build the html select list 706 $SectionList = mosHTML::selectList( $sections, 'sectionmove', 'class="inputbox" size="10"', 'value', 'text', null ); 707 708 categories_html::copyCategorySelect( $option, $cid, $SectionList, $items, $sectionOld, $contents, $redirect ); 709 } 710 711 712 /** 713 * Save the item(s) to the menu selected 714 */ 715 function copyCategorySave( $cid, $sectionOld ) { 716 global $database; 717 718 $sectionMove = mosGetParam( $_REQUEST, 'sectionmove', '' ); 719 $contentid = mosGetParam( $_REQUEST, 'item', '' ); 720 $total = count( $contentid ); 721 722 $category = new mosCategory ( $database ); 723 foreach( $cid as $id ) { 724 $category->load( $id ); 725 $category->id = NULL; 726 $category->title = "Copy of ".$category->title; 727 $category->name = "Copy of ".$category->name; 728 $category->section = $sectionMove; 729 if (!$category->check()) { 730 echo "<script> alert('".$category->getError()."'); window.history.go(-1); </script>\n"; 731 exit(); 732 } 733 734 if (!$category->store()) { 735 echo "<script> alert('".$category->getError()."'); window.history.go(-1); </script>\n"; 736 exit(); 737 } 738 $category->checkin(); 739 // stores original catid 740 $newcatids[]["old"] = $id; 741 // pulls new catid 742 $newcatids[]["new"] = $category->id; 743 } 744 745 $content = new mosContent ( $database ); 746 foreach( $contentid as $id) { 747 $content->load( $id ); 748 $content->id = NULL; 749 $content->sectionid = $sectionMove; 750 $content->hits = 0; 751 foreach( $newcatids as $newcatid ) { 752 if ( $content->catid == $newcatid["old"] ) { 753 $content->catid = $newcatid["new"]; 754 } 755 } 756 if (!$content->check()) { 757 echo "<script> alert('".$content->getError()."'); window.history.go(-1); </script>\n"; 758 exit(); 759 } 760 761 if (!$content->store()) { 762 echo "<script> alert('".$content->getError()."'); window.history.go(-1); </script>\n"; 763 exit(); 764 } 765 $content->checkin(); 766 } 767 768 $sectionNew = new mosSection ( $database ); 769 $sectionNew->load( $sectionMove ); 770 771 $msg = sprintf(Tn_('%d Category copied to %s', '%d Categories copied to %s', $total), $total, $sectionNew->name); 772 mosRedirect( 'index2.php?option=com_categories§ion='. $sectionOld .'&mosmsg='. $msg ); 773 } 774 775 /** 776 * changes the access level of a record 777 * @param integer The increment to reorder by 778 */ 779 function accessMenu( $uid, $access, $section ) { 780 global $database; 781 782 $row = new mosCategory( $database ); 783 $row->load( $uid ); 784 $row->access = $access; 785 786 if ( !$row->check() ) { 787 return $row->getError(); 788 } 789 if ( !$row->store() ) { 790 return $row->getError(); 791 } 792 793 mosRedirect( 'index2.php?option=com_categories§ion='. $section ); 794 } 795 796 function menuLink( $id ) { 797 global $database; 798 799 $category = new mosCategory( $database ); 800 $category->bind( $_POST ); 801 $category->checkin(); 802 803 $redirect = mosGetParam( $_POST, 'redirect', '' ); 804 $menu = mosGetParam( $_POST, 'menuselect', '' ); 805 $name = mosGetParam( $_POST, 'link_name', '' ); 806 $sectionid = mosGetParam( $_POST, 'sectionid', '' ); 807 $type = mosGetParam( $_POST, 'link_type', '' ); 808 809 switch ( $type ) { 810 case 'content_category': 811 $link = 'index.php?option=com_content&task=category§ionid='. $sectionid .'&id='. $id; 812 $menutype = T_('Content Category Table'); 813 break; 814 815 case 'content_blog_category': 816 $link = 'index.php?option=com_content&task=blogcategory&id='. $id; 817 $menutype = T_('Content Category Blog'); 818 break; 819 820 case 'content_archive_category': 821 $link = 'index.php?option=com_content&task=archivecategory&id='. $id; 822 $menutype = T_('Content Category Blog Archive'); 823 break; 824 825 case 'contact_category_table': 826 $link = 'index.php?option=com_contact&catid='. $id; 827 $menutype = T_('Contact Category Table'); 828 break; 829 830 case 'newsfeed_category_table': 831 $link = 'index.php?option=com_newsfeeds&catid='. $id; 832 $menutype = T_('News Feed Category Table'); 833 break; 834 835 case 'weblink_category_table': 836 $link = 'index.php?option=com_weblinks&catid='. $id; 837 $menutype = T_('Web Link Category Table'); 838 break; 839 840 default:; 841 } 842 843 $row = new mosMenu( $database ); 844 $row->menutype = $menu; 845 $row->name = $name; 846 $row->type = $type; 847 $row->published = 1; 848 $row->componentid = $id; 849 $row->link = $link; 850 $row->ordering = 9999; 851 852 if (!$row->check()) { 853 echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n"; 854 exit(); 855 } 856 if (!$row->store()) { 857 echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n"; 858 exit(); 859 } 860 $row->checkin(); 861 $row->updateOrder( "menutype='". $menu ."'" ); 862 863 $msg = sprintf(T_('%s ( %s ) in menu: %s successfully created'),$name, $menutype,$menu); 864 mosRedirect( 'index2.php?option=com_categories§ion='. $redirect .'&task=editA&hidemainmenu=1&id='. $id, $msg ); 865 } 866 867 function saveOrder( &$cid, $section ) { 868 global $database; 869 $order = mosGetParam( $_POST, 'order', array(0) ); 870 $row = new mosCategory( $database ); 871 $sections = array(); 872 // update ordering values 873 foreach ($cid as $i=>$ciditem) { 874 $row->load( $ciditem ); 875 if ($row->ordering != $order[$i]) { 876 $row->ordering = $order[$i]; 877 if (!$row->store()) { 878 echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n"; 879 exit(); 880 } 881 // remember to updateOrder this group 882 $sections[$row->section] = $row->id; 883 } 884 } 885 // execute updateOrder for each group 886 foreach ($sections as $sectionid=>$rowid) { 887 $row->updateOrder("section='$sectionid'"); 888 } // foreach 889 $msg = T_('New ordering saved'); 890 mosRedirect( 'index2.php?option=com_categories§ion='. $section, $msg ); 891 } // saveOrder 892 893 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Wed Feb 8 00:05:01 2012 | Cross-referenced by PHPXref 0.7 |
| Mambo API: Mambo is Free software released under the GNU/General Public License, Version 2 |