| [ 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 Menus 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 // ensure user has access to this function 21 if (!$acl->acl_check( 'administration', 'manage', 'users', $my->usertype, 'components', 'com_menumanager' )) { 22 mosRedirect( 'index2.php', T_('You are not authorized to view this resource.') ); 23 } 24 25 require_once( $mainframe->getPath( 'admin_html' ) ); 26 27 $menu = mosGetParam( $_GET, 'menu', '' ); 28 $task = mosGetParam( $_REQUEST, 'task', array(0) ); 29 $type = mosGetParam( $_POST, 'type', '' ); 30 $cid = mosGetParam( $_POST, 'cid', '' ); 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 ); 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 = $mainframe->getUserStateFromRequest( "viewlistlimit", 'limit', $mosConfig_list_limit ); 81 $limitstart = $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 '%$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 // @RawSQLUse, trivial_implementation, SELECT 108 $query = "SELECT a.menutype, count( a.menutype ) as num" 109 . "\n FROM #__menu AS a" 110 . "\n WHERE a.published = 1" 111 . "\n GROUP BY a.menutype" 112 . "\n ORDER BY a.menutype" 113 ; 114 $database->setQuery( $query ); 115 $published = $database->loadObjectList(); 116 117 // Query to get unpublished menu item counts 118 // @RawSQLUse, trivial_implementation, SELECT 119 $query = "SELECT a.menutype, count( a.menutype ) as num" 120 . "\n FROM #__menu AS a" 121 . "\n WHERE a.published = 0" 122 . "\n GROUP BY a.menutype" 123 . "\n ORDER BY a.menutype" 124 ; 125 $database->setQuery( $query ); 126 $unpublished = $database->loadObjectList(); 127 if (!$unpublished) $unpublished = array(); 128 129 // Query to get trash menu item counts 130 // @RawSQLUse, trivial_implementation, SELECT 131 $query = "SELECT a.menutype, count( a.menutype ) as num" 132 . "\n FROM #__menu AS a" 133 . "\n WHERE a.published = -2" 134 . "\n GROUP BY a.menutype" 135 . "\n ORDER BY a.menutype" 136 ; 137 $database->setQuery( $query ); 138 $trash = $database->loadObjectList(); 139 if (!$trash) $trash = array(); 140 141 for( $i = 0; $i < $total; $i++ ) { 142 // adds published count 143 foreach ( $published as $count ) { 144 if ( $menus[$i]->type == $count->menutype ) { 145 $menus[$i]->published = $count->num; 146 } 147 } 148 if ( @!$menus[$i]->published ) { 149 $menus[$i]->published = '-'; 150 } 151 // adds unpublished count 152 foreach ( $unpublished as $count ) { 153 if ( $menus[$i]->type == $count->menutype ) { 154 $menus[$i]->unpublished = $count->num; 155 } 156 } 157 if ( @!$menus[$i]->unpublished ) { 158 $menus[$i]->unpublished = '-'; 159 } 160 // adds trash count 161 foreach ( $trash as $count ) { 162 if ( $menus[$i]->type == $count->menutype ) { 163 $menus[$i]->trash = $count->num; 164 } 165 } 166 if ( @!$menus[$i]->trash ) { 167 $menus[$i]->trash = '-'; 168 } 169 } 170 171 require_once( $GLOBALS['mosConfig_absolute_path'] . '/administrator/includes/pageNavigation.php' ); 172 $pageNav = new mosPageNav( $total, $limitstart, $limit ); 173 174 HTML_menumanager::show( $option, $menus, $pageNav ); 175 } 176 177 178 /** 179 * Edits a mod_mainmenu module 180 * 181 * @param option options for the edit mode 182 * @param cid menu id 183 */ 184 function editMenu( $option, $menu ) { 185 global $database; 186 187 if( $menu ) { 188 $row->menutype = $menu; 189 } else { 190 $row = new mosModule( $database ); 191 // setting default values 192 $row->menutype = ''; 193 $row->iscore = 0; 194 $row->published = 0; 195 $row->position = 'left'; 196 $row->module = 'mod_mainmenu'; 197 } 198 199 HTML_menumanager::edit( $row, $option ); 200 } 201 202 /** 203 * Creates a new mod_mainmenu module, which makes the menu visible 204 * this is a workaround until a new dedicated table for menu management can be created 205 */ 206 function saveMenu() { 207 global $database; 208 209 $menutype = mosGetParam( $_POST, 'menutype', '' ); 210 $old_menutype = mosGetParam( $_POST, 'old_menutype', '' ); 211 $new = mosGetParam( $_POST, 'new', 1 ); 212 213 // block to stop renaming of 'mainmenu' menutype 214 if ( $old_menutype == 'mainmenu' ) { 215 if ( $menutype <> 'mainmenu' ) { 216 echo "<script> alert('".T_('You cannot rename the "mainmenu" Menu as this will disrupt the proper operation of Mambo')."'); window.history.go(-1); </script>\n"; 217 exit; 218 } 219 } 220 221 // check for unique menutype for new menus 222 // @RawSQLUse, trivial_implementation, SELECT 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 $pparser = new mosParameters($menu); 231 $params = $pparser->getParams(); 232 if ( $params->menutype == $menutype ) { 233 echo "<script> alert('".T_('A menu already exists with that name - you must enter a unique Menu Name')."'); window.history.go(-1); </script>\n"; 234 exit; 235 } 236 } 237 238 switch ( $new ) { 239 case 1: 240 // create a new module for the new menu 241 $row = new mosModule( $database ); 242 $row->bind( $_POST ); 243 244 $row->params = 'menutype='. $menutype; 245 246 // check then store data in db 247 if (!$row->check()) { 248 echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n"; 249 exit(); 250 } 251 if (!$row->store()) { 252 echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n"; 253 exit(); 254 } 255 256 $row->checkin(); 257 $row->updateOrder( "position='". $row->position ."'" ); 258 259 // module assigned to show on All pages by default 260 // ToDO: Changed to become a mambo db-object 261 // @RawSQLUse, trivial_implementation, INSERT 262 $query = "INSERT INTO #__modules_menu VALUES ( $row->id, 0 )"; 263 $database->setQuery( $query ); 264 if ( !$database->query() ) { 265 echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n"; 266 exit(); 267 } 268 269 $msg = sprintf(T_('New Menu created [ %s ]'), $menutype); 270 break; 271 272 default: 273 // change menutype being of all mod_mainmenu modules calling old menutype 274 $query = "SELECT id" 275 . "\n FROM #__modules" 276 . "\n WHERE module = 'mod_mainmenu'" 277 . "\n AND params LIKE '%$old_menutype%'" 278 ; 279 $database->setQuery( $query ); 280 $modules = $database->loadResultArray(); 281 282 foreach ( $modules as $module ) { 283 $row = new mosModule( $database ); 284 $row->load( $module ); 285 286 $save = 0; 287 $pparser = new mosParameters($row->params); 288 $params = $pparser->getParams(); 289 if ( $params->menutype == $old_menutype ) { 290 $params->menutype = $menutype; 291 $save = 1; 292 } 293 294 // save changes to module 'menutype' param 295 if ( $save ) { 296 $txt = array(); 297 foreach ( $params as $k=>$v) { 298 $txt[] = "$k=$v"; 299 } 300 $row->params = implode( "\n", $txt ); 301 302 // check then store data in db 303 if ( !$row->check() ) { 304 echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n"; 305 exit(); 306 } 307 if ( !$row->store() ) { 308 echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n"; 309 exit(); 310 } 311 312 $row->checkin(); 313 } 314 } 315 316 // change menutype of all menuitems using old menutype 317 if ( $menutype <> $old_menutype ) { 318 // @RawSQLUse, trivial_implementation, UPDATE 319 $query = "UPDATE #__menu SET menutype = '$menutype' WHERE menutype = '$old_menutype'"; 320 $database->setQuery( $query ); 321 $database->query(); 322 } 323 324 $msg = T_('Menu Items & Modules updated'); 325 break; 326 } 327 328 mosRedirect( 'index2.php?option=com_menumanager', $msg ); 329 } 330 331 /** 332 * Compiles a list of the items you have selected to permanently delte 333 */ 334 function deleteConfirm( $option, $types ) { 335 global $database; 336 337 if ( in_array('mainmenu', $types )) { 338 $types = array_diff($types, array('mainmenu')); 339 echo "<script> alert('".T_('You cannot delete the "mainmenu" menu as it is a core menu')."'); </script>\n"; 340 } 341 342 $menus = implode("','",$types); 343 // list of menu items to delete 344 // @RawSQLUse, trivial_implementation, SELECT 345 $query = "SELECT a.name, a.id" 346 . "\n FROM #__menu AS a" 347 . "\n WHERE ( a.menutype IN ( '$menus' ) )" 348 . "\n ORDER BY a.name" 349 ; 350 $database->setQuery( $query ); 351 $items = $database->loadObjectList(); 352 353 foreach ($types as $type) { 354 // list of modules to delete 355 $query = "SELECT id" 356 . "\n FROM #__modules" 357 . "\n WHERE module = 'mod_mainmenu'" 358 . "\n AND params LIKE '%$type%'" 359 ; 360 $database->setQuery( $query ); 361 $mods = $database->loadResultArray(); 362 foreach ( $mods as $module ) { 363 $row = new mosModule( $database ); 364 $row->load( $module ); 365 $pparser = new mosParameters($row->params); 366 $params = $pparser->getParams(); 367 if ( $params->menutype == $type ) { 368 $mid[] = $module; 369 } 370 } 371 } 372 373 @$mids = implode( ',', $mid ); 374 // @RawSQLUse, trivial_implementation, SELECT 375 $query = "SELECT id, title" 376 . "\n FROM #__modules" 377 . "\n WHERE id IN ( $mids )" 378 ; 379 $database->setQuery( $query ); 380 @$modules = $database->loadObjectList(); 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('".T_('You cannot delete the "mainmenu" menu as it is a core menu')."'); window.history.go(-1); </script>\n"; 393 exit(); 394 } 395 396 397 $mids = mosGetParam( $_POST, 'mids', 0 ); 398 if ( is_array( $mids ) ) { 399 $mids = implode( ',', $mids ); 400 } 401 // delete menu items 402 // @RawSQLUse, trivial_implementation, DELETE 403 $query = "DELETE FROM #__menu" 404 . "\n WHERE ( id IN ( $mids ) )" 405 ; 406 $database->setQuery( $query ); 407 if ( !$database->query() ) { 408 echo "<script> alert('". $database->getErrorMsg() ."');</script>\n"; 409 exit; 410 } 411 412 if ( is_array( $cid ) ) { 413 $cids = implode( ',', $cid ); 414 } else { 415 $cids = $cid; 416 } 417 418 // checks whether any modules to delete 419 if ( $cids ) { 420 // delete modules 421 // @RawSQLUse, trivial_implementation, DELETE 422 $database->setQuery( "DELETE FROM #__modules WHERE id IN ( $cids )" ); 423 if ( !$database->query() ) { 424 echo "<script> alert('". $database->getErrorMsg() ."'); window.history.go(-1); </script>\n"; 425 exit; 426 } 427 // delete all module entires in mos_modules_menu 428 // @RawSQLUse, trivial_implementation, DELETE 429 $database->setQuery( "DELETE FROM #__modules_menu WHERE moduleid IN ( ". $cids ." )" ); 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 $msg = 'Menu Deleted'; 443 mosRedirect( 'index2.php?option=' . $option, $msg ); 444 } 445 446 447 /** 448 * Compiles a list of the items you have selected to Copy 449 */ 450 function copyConfirm( $option, $type ) { 451 global $database; 452 453 // Content Items query 454 // @RawSQLUse, trivial_implementation, SELECT 455 $query = "SELECT a.name, a.id" 456 . "\n FROM #__menu AS a" 457 . "\n WHERE ( a.menutype IN ( '". $type ."' ) )" 458 . "\n ORDER BY a.name" 459 ; 460 $database->setQuery( $query ); 461 $items = $database->loadObjectList(); 462 463 HTML_menumanager::showCopy( $option, $type, $items ); 464 } 465 466 467 /** 468 * Copies a complete menu, all its items and creates a new module, using the name speified 469 */ 470 function copyMenu( $option, $cid, $type ) { 471 global $database; 472 473 $menu_name = mosGetParam( $_POST, 'menu_name', 'New Menu' ); 474 $module_name = mosGetParam( $_POST, 'module_name', 'New Module' ); 475 476 // check for unique menutype for new menu copy 477 // @RawSQLUse, trivial_implementation, SELECT 478 $query = "SELECT params" 479 . "\n FROM #__modules" 480 . "\n WHERE module = 'mod_mainmenu'" 481 ; 482 $database->setQuery( $query ); 483 $menus = $database->loadResultArray(); 484 foreach ( $menus as $menu ) { 485 $pparser = new mosParameters($menu); 486 $params = $pparser->getParams(); 487 if ( $params->menutype == $menu_name ) { 488 echo "<script> alert('".T_('A menu with that name already exists - 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 = mosGetParam( $_POST, '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='". $row->position ."'" ); 539 // module assigned to show on All pages by default 540 // ToDO: Changed to become a mambo db-object 541 // @RawSQLUse, trivial_implementation, INSERT 542 $query = "INSERT INTO #__modules_menu VALUES ( $row->id, 0 )"; 543 $database->setQuery( $query ); 544 if ( !$database->query() ) { 545 echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n"; 546 exit(); 547 } 548 549 $msg = sprintf(Tn_('Copy of Menu `%s` created, consisting of %d item', 'Copy of Menu `%s` created, consisting of %d items', $total), $type, $total); 550 mosRedirect( 'index2.php?option=' . $option, $msg ); 551 } 552 553 /** 554 * Cancels an edit operation 555 * @param option options for the operation 556 */ 557 function cancelMenu( $option ) { 558 mosRedirect( 'index2.php?option=' . $option . '&task=view' ); 559 } 560 ?>
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 |