[ Index ] |
|
Code source de Joomla 1.0.13 |
1 <?php 2 /** 3 * @version $Id: admin.menumanager.php 5028 2006-09-13 18:45:52Z friesengeist $ 4 * @package Joomla 5 * @subpackage Menus 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 // ensure user has access to this function 19 if (!$acl->acl_check( 'administration', 'manage', 'users', $my->usertype, 'components', 'com_menumanager' )) { 20 mosRedirect( 'index2.php', _NOT_AUTH ); 21 } 22 23 require_once( $mainframe->getPath( 'admin_html' ) ); 24 25 $menu = stripslashes( strval( mosGetParam( $_GET, 'menu', '' ) ) ); 26 $type = stripslashes( strval( mosGetParam( $_POST, 'type', '' ) ) ); 27 $cid = mosGetParam( $_POST, 'cid', '' ); 28 if (isset( $cid[0] ) && get_magic_quotes_gpc()) { 29 $cid[0] = stripslashes( $cid[0] ); 30 } 31 32 switch ($task) { 33 case 'new': 34 editMenu( $option, '' ); 35 break; 36 37 case 'edit': 38 if ( !$menu ) { 39 $menu = $cid[0]; 40 } 41 editMenu( $option, $menu ); 42 break; 43 44 case 'savemenu': 45 saveMenu(); 46 break; 47 48 case 'deleteconfirm': 49 deleteconfirm( $option, $cid[0] ); 50 break; 51 52 case 'deletemenu': 53 deleteMenu( $option, $cid, $type ); 54 break; 55 56 case 'copyconfirm': 57 copyConfirm( $option, $cid[0] ); 58 break; 59 60 case 'copymenu': 61 copyMenu( $option, $cid, $type ); 62 break; 63 64 case 'cancel': 65 cancelMenu( $option ); 66 break; 67 68 default: 69 showMenu( $option ); 70 break; 71 } 72 73 74 /** 75 * Compiles a list of menumanager items 76 */ 77 function showMenu( $option ) { 78 global $database, $mainframe, $mosConfig_list_limit; 79 80 $limit = intval( $mainframe->getUserStateFromRequest( "viewlistlimit", 'limit', $mosConfig_list_limit ) ); 81 $limitstart = intval( $mainframe->getUserStateFromRequest( "view{". $option ."}limitstart", 'limitstart', 0 ) ); 82 83 $menuTypes = mosAdminMenus::menutypes(); 84 $total = count( $menuTypes ); 85 $i = 0; 86 foreach ( $menuTypes as $a ) { 87 $menus[$i]->type = $a; 88 89 // query to get number of modules for menutype 90 $query = "SELECT count( id )" 91 . "\n FROM #__modules" 92 . "\n WHERE module = 'mod_mainmenu'" 93 . "\n AND params LIKE '%" . $database->getEscaped( $a ) . "%'" 94 ; 95 $database->setQuery( $query ); 96 $modules = $database->loadResult(); 97 98 if ( !$modules ) { 99 $modules = '-'; 100 } 101 $menus[$i]->modules = $modules; 102 103 $i++; 104 } 105 106 // Query to get published menu item counts 107 $query = "SELECT a.menutype, count( a.menutype ) as num" 108 . "\n FROM #__menu AS a" 109 . "\n WHERE a.published = 1" 110 . "\n GROUP BY a.menutype" 111 . "\n ORDER BY a.menutype" 112 ; 113 $database->setQuery( $query ); 114 $published = $database->loadObjectList(); 115 116 // Query to get unpublished menu item counts 117 $query = "SELECT a.menutype, count( a.menutype ) as num" 118 . "\n FROM #__menu AS a" 119 . "\n WHERE a.published = 0" 120 . "\n GROUP BY a.menutype" 121 . "\n ORDER BY a.menutype" 122 ; 123 $database->setQuery( $query ); 124 $unpublished = $database->loadObjectList(); 125 126 // Query to get trash menu item counts 127 $query = "SELECT a.menutype, count( a.menutype ) as num" 128 . "\n FROM #__menu AS a" 129 . "\n WHERE a.published = -2" 130 . "\n GROUP BY a.menutype" 131 . "\n ORDER BY a.menutype" 132 ; 133 $database->setQuery( $query ); 134 $trash = $database->loadObjectList(); 135 136 for( $i = 0; $i < $total; $i++ ) { 137 // adds published count 138 foreach ( $published as $count ) { 139 if ( $menus[$i]->type == $count->menutype ) { 140 $menus[$i]->published = $count->num; 141 } 142 } 143 if ( @!$menus[$i]->published ) { 144 $menus[$i]->published = '-'; 145 } 146 // adds unpublished count 147 foreach ( $unpublished as $count ) { 148 if ( $menus[$i]->type == $count->menutype ) { 149 $menus[$i]->unpublished = $count->num; 150 } 151 } 152 if ( @!$menus[$i]->unpublished ) { 153 $menus[$i]->unpublished = '-'; 154 } 155 // adds trash count 156 foreach ( $trash as $count ) { 157 if ( $menus[$i]->type == $count->menutype ) { 158 $menus[$i]->trash = $count->num; 159 } 160 } 161 if ( @!$menus[$i]->trash ) { 162 $menus[$i]->trash = '-'; 163 } 164 } 165 166 require_once( $GLOBALS['mosConfig_absolute_path'] . '/administrator/includes/pageNavigation.php' ); 167 $pageNav = new mosPageNav( $total, $limitstart, $limit ); 168 169 HTML_menumanager::show( $option, $menus, $pageNav ); 170 } 171 172 173 /** 174 * Edits a mod_mainmenu module 175 * 176 * @param option options for the edit mode 177 * @param cid menu id 178 */ 179 function editMenu( $option, $menu ) { 180 global $database; 181 182 if( $menu ) { 183 $row->menutype = $menu; 184 } else { 185 $row = new mosModule( $database ); 186 // setting default values 187 $row->menutype = ''; 188 $row->iscore = 0; 189 $row->published = 0; 190 $row->position = 'left'; 191 $row->module = 'mod_mainmenu'; 192 } 193 194 HTML_menumanager::edit( $row, $option ); 195 } 196 197 /** 198 * Creates a new mod_mainmenu module, which makes the menu visible 199 * this is a workaround until a new dedicated table for menu management can be created 200 */ 201 function saveMenu() { 202 global $database; 203 204 $menutype = stripslashes( strval( mosGetParam( $_POST, 'menutype', '' ) ) ); 205 $old_menutype = stripslashes( strval( mosGetParam( $_POST, 'old_menutype', '' ) ) ); 206 $new = intval( mosGetParam( $_POST, 'new', 1 ) ); 207 208 // block to stop renaming of 'mainmenu' menutype 209 if ( $old_menutype == 'mainmenu' ) { 210 if ( $menutype != 'mainmenu' ) { 211 echo "<script> alert('You cannot rename the \'mainmenu\' Menu as this will disrupt the proper operation of Joomla'); window.history.go(-1); </script>\n"; 212 exit; 213 } 214 } 215 216 // check for ' in menu name 217 if (strstr($menutype, '\'')) { 218 echo "<script> alert('The menu name cannot contain a \''); window.history.go(-1); </script>\n"; 219 exit; 220 } 221 222 // check for unique menutype for new menus 223 $query = "SELECT params" 224 . "\n FROM #__modules" 225 . "\n WHERE module = 'mod_mainmenu'" 226 ; 227 $database->setQuery( $query ); 228 $menus = $database->loadResultArray(); 229 foreach ( $menus as $menu ) { 230 $params = mosParseParams( $menu ); 231 if ( $params->menutype == $menutype ) { 232 echo "<script> alert('A menu already exists with that name - you must enter a unique Menu Name'); window.history.go(-1); </script>\n"; 233 exit; 234 } 235 } 236 237 switch ( $new ) { 238 case 1: 239 // create a new module for the new menu 240 $row = new mosModule( $database ); 241 $row->bind( $_POST ); 242 243 $row->params = 'menutype='. $menutype; 244 245 // check then store data in db 246 if (!$row->check()) { 247 echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n"; 248 exit(); 249 } 250 if (!$row->store()) { 251 echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n"; 252 exit(); 253 } 254 255 $row->checkin(); 256 $row->updateOrder( "position=". $database->Quote( $row->position ) ); 257 258 // module assigned to show on All pages by default 259 // ToDO: Changed to become a Joomla! db-object 260 $query = "INSERT INTO #__modules_menu VALUES ( ".(int)$row->id.", 0 )"; 261 $database->setQuery( $query ); 262 if ( !$database->query() ) { 263 echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n"; 264 exit(); 265 } 266 267 $msg = 'New Menu created [ '. $menutype .' ]'; 268 break; 269 270 default: 271 // change menutype being of all mod_mainmenu modules calling old menutype 272 $query = "SELECT id" 273 . "\n FROM #__modules" 274 . "\n WHERE module = 'mod_mainmenu'" 275 . "\n AND params LIKE '%" . $database->getEscaped( $old_menutype ) . "%'" 276 ; 277 $database->setQuery( $query ); 278 $modules = $database->loadResultArray(); 279 280 foreach ( $modules as $module ) { 281 $row = new mosModule( $database ); 282 $row->load( $module ); 283 284 $save = 0; 285 $params = mosParseParams( $row->params ); 286 if ( $params->menutype == $old_menutype ) { 287 $params->menutype = $menutype; 288 $save = 1; 289 } 290 291 // save changes to module 'menutype' param 292 if ( $save ) { 293 $txt = array(); 294 foreach ( $params as $k=>$v) { 295 $txt[] = "$k=$v"; 296 } 297 $row->params = implode( "\n", $txt ); 298 299 // check then store data in db 300 if ( !$row->check() ) { 301 echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n"; 302 exit(); 303 } 304 if ( !$row->store() ) { 305 echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n"; 306 exit(); 307 } 308 309 $row->checkin(); 310 } 311 } 312 313 // change menutype of all menuitems using old menutype 314 if ( $menutype != $old_menutype ) { 315 $query = "UPDATE #__menu" 316 . "\n SET menutype = " . $database->Quote( $menutype ) 317 . "\n WHERE menutype = " . $database->Quote( $old_menutype ) 318 ; 319 $database->setQuery( $query ); 320 $database->query(); 321 } 322 323 $msg = 'Menu Items & Modules updated'; 324 break; 325 } 326 327 mosRedirect( 'index2.php?option=com_menumanager', $msg ); 328 } 329 330 /** 331 * Compiles a list of the items you have selected to permanently delte 332 */ 333 function deleteConfirm( $option, $type ) { 334 global $database; 335 336 if ( $type == 'mainmenu' ) { 337 echo "<script> alert('You cannot delete the \'mainmenu\' menu as it is core menu'); window.history.go(-1); </script>\n"; 338 exit(); 339 } 340 341 // list of menu items to delete 342 $query = "SELECT a.name, a.id" 343 . "\n FROM #__menu AS a" 344 . "\n WHERE a.menutype = " . $database->Quote( $type ) 345 . "\n ORDER BY a.name" 346 ; 347 $database->setQuery( $query ); 348 $items = $database->loadObjectList(); 349 350 // list of modules to delete 351 $query = "SELECT id" 352 . "\n FROM #__modules" 353 . "\n WHERE module = 'mod_mainmenu'" 354 . "\n AND params LIKE '%" . $database->getEscaped( $type ) . "%'" 355 ; 356 $database->setQuery( $query ); 357 $mods = $database->loadResultArray(); 358 359 foreach ( $mods as $module ) { 360 $row = new mosModule( $database ); 361 $row->load( $module ); 362 363 $params = mosParseParams( $row->params ); 364 if ( $params->menutype == $type ) { 365 $mid[] = $module; 366 } 367 } 368 369 mosArrayToInts( $mid ); 370 if (count( $mid )) { 371 $mids = 'id=' . implode( ' OR id=', $mid ); 372 $query = "SELECT id, title" 373 . "\n FROM #__modules" 374 . "\n WHERE ( $mids )" 375 ; 376 $database->setQuery( $query ); 377 $modules = $database->loadObjectList(); 378 } else { 379 $modules = null; 380 } 381 382 HTML_menumanager::showDelete( $option, $type, $items, $modules ); 383 } 384 385 /** 386 * Deletes menu items(s) you have selected 387 */ 388 function deleteMenu( $option, $cid, $type ) { 389 global $database; 390 391 if ( $type == 'mainmenu' ) { 392 echo "<script> alert('You cannot delete the \'mainmenu\' menu as it is core menu'); window.history.go(-1); </script>\n"; 393 exit(); 394 } 395 396 $mid = mosGetParam( $_POST, 'mids' ); 397 mosArrayToInts( $mid ); 398 if (count( $mid )) { 399 // delete menu items 400 $mids = 'id=' . implode( ' OR id=', $mid ); 401 $query = "DELETE FROM #__menu" 402 . "\n WHERE ( $mids )" 403 ; 404 $database->setQuery( $query ); 405 if ( !$database->query() ) { 406 echo "<script> alert('". $database->getErrorMsg() ."');</script>\n"; 407 exit; 408 } 409 } 410 411 mosArrayToInts( $cid ); 412 // checks whether any modules to delete 413 if (count( $cid )) { 414 // delete modules 415 $cids = 'id=' . implode( ' OR id=', $cid ); 416 $query = "DELETE FROM #__modules" 417 . "\n WHERE ( $cids )" 418 ; 419 $database->setQuery( $query ); 420 if ( !$database->query() ) { 421 echo "<script> alert('". $database->getErrorMsg() ."'); window.history.go(-1); </script>\n"; 422 exit; 423 } 424 // delete all module entires in jos_modules_menu 425 $cids = 'moduleid=' . implode( ' OR moduleid=', $cid ); 426 $query = "DELETE FROM #__modules_menu" 427 . "\n WHERE ( $cids )" 428 ; 429 $database->setQuery( $query ); 430 if ( !$database->query() ) { 431 echo "<script> alert('". $database->getErrorMsg() ."');</script>\n"; 432 exit; 433 } 434 435 // reorder modules after deletion 436 $mod = new mosModule( $database ); 437 $mod->ordering = 0; 438 $mod->updateOrder( "position='left'" ); 439 $mod->updateOrder( "position='right'" ); 440 } 441 442 // clean any existing cache files 443 mosCache::cleanCache( 'com_content' ); 444 445 $msg = 'Menu Deleted'; 446 mosRedirect( 'index2.php?option=' . $option, $msg ); 447 } 448 449 450 /** 451 * Compiles a list of the items you have selected to Copy 452 */ 453 function copyConfirm( $option, $type ) { 454 global $database; 455 456 // Content Items query 457 $query = "SELECT a.name, a.id" 458 . "\n FROM #__menu AS a" 459 . "\n WHERE a.menutype = " . $database->Quote( $type ) 460 . "\n ORDER BY a.name" 461 ; 462 $database->setQuery( $query ); 463 $items = $database->loadObjectList(); 464 465 HTML_menumanager::showCopy( $option, $type, $items ); 466 } 467 468 469 /** 470 * Copies a complete menu, all its items and creates a new module, using the name speified 471 */ 472 function copyMenu( $option, $cid, $type ) { 473 global $database; 474 475 $menu_name = stripslashes( strval( mosGetParam( $_POST, 'menu_name', 'New Menu' ) ) ); 476 $module_name = stripslashes( strval( mosGetParam( $_POST, 'module_name', 'New Module' ) ) ); 477 478 // check for unique menutype for new menu copy 479 $query = "SELECT params" 480 . "\n FROM #__modules" 481 . "\n WHERE module = 'mod_mainmenu'" 482 ; 483 $database->setQuery( $query ); 484 $menus = $database->loadResultArray(); 485 foreach ( $menus as $menu ) { 486 $params = mosParseParams( $menu ); 487 if ( $params->menutype == $menu_name ) { 488 echo "<script> alert('A menu already exists with that name - you must enter a unique Menu Name'); window.history.go(-1); </script>\n"; 489 exit; 490 } 491 } 492 493 // copy the menu items 494 $mids = josGetArrayInts( 'mids' ); 495 $total = count( $mids ); 496 $copy = new mosMenu( $database ); 497 $original = new mosMenu( $database ); 498 sort( $mids ); 499 $a_ids = array(); 500 501 foreach( $mids as $mid ) { 502 $original->load( $mid ); 503 $copy = $original; 504 $copy->id = NULL; 505 $copy->parent = $a_ids[$original->parent]; 506 $copy->menutype = $menu_name; 507 508 if ( !$copy->check() ) { 509 echo "<script> alert('".$copy->getError()."'); window.history.go(-1); </script>\n"; 510 exit(); 511 } 512 if ( !$copy->store() ) { 513 echo "<script> alert('".$copy->getError()."'); window.history.go(-1); </script>\n"; 514 exit(); 515 } 516 $a_ids[$original->id] = $copy->id; 517 } 518 519 // create the module copy 520 $row = new mosModule( $database ); 521 $row->load( 0 ); 522 $row->title = $module_name; 523 $row->iscore = 0; 524 $row->published = 1; 525 $row->position = 'left'; 526 $row->module = 'mod_mainmenu'; 527 $row->params = 'menutype='. $menu_name; 528 529 if (!$row->check()) { 530 echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n"; 531 exit(); 532 } 533 if (!$row->store()) { 534 echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n"; 535 exit(); 536 } 537 $row->checkin(); 538 $row->updateOrder( 'position=' . $database->Quote( $row->position ) ); 539 // module assigned to show on All pages by default 540 // ToDO: Changed to become a Joomla! db-object 541 $query = "INSERT INTO #__modules_menu VALUES ( " . (int) $row->id . ", 0 )"; 542 $database->setQuery( $query ); 543 if ( !$database->query() ) { 544 echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n"; 545 exit(); 546 } 547 548 // clean any existing cache files 549 mosCache::cleanCache( 'com_content' ); 550 551 $msg = 'Copy of Menu `'. $type .'` created, consisting of '. $total .' items'; 552 mosRedirect( 'index2.php?option=' . $option, $msg ); 553 } 554 555 /** 556 * Cancels an edit operation 557 * @param option options for the operation 558 */ 559 function cancelMenu( $option ) { 560 mosRedirect( 'index2.php?option=' . $option . '&task=view' ); 561 } 562 ?>
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 |
![]() |