Annotation of /mambo/branches/4.6/administrator/components/com_menus/admin.menus.php
Parent Directory
|
Revision Log
Revision 1711 - (view) (download)
| 1 : | elpie | 964 | <?php |
| 2 : | /** | ||
| 3 : | * @package Mambo | ||
| 4 : | * @subpackage Menus | ||
| 5 : | ocs_cms | 1396 | * @author Mambo Foundation Inc see README.php |
| 6 : | * @copyright Mambo Foundation Inc. | ||
| 7 : | * See COPYRIGHT.php for copyright notices and details. | ||
| 8 : | * @license GNU/GPL Version 2, see LICENSE.php | ||
| 9 : | * Mambo is free software; you can redistribute it and/or | ||
| 10 : | * modify it under the terms of the GNU General Public License | ||
| 11 : | * as published by the Free Software Foundation; version 2 of the License. | ||
| 12 : | */ | ||
| 13 : | elpie | 964 | |
| 14 : | /** ensure this file is being included by a parent file */ | ||
| 15 : | defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' ); | ||
| 16 : | |||
| 17 : | require_once( $mainframe->getPath( 'admin_html' ) ); | ||
| 18 : | |||
| 19 : | $id = intval( mosGetParam( $_GET, 'id', 0 ) ); | ||
| 20 : | $type = mosGetParam( $_REQUEST, 'type', false ); | ||
| 21 : | $menutype = mosGetParam( $_REQUEST, 'menutype', 'mainmenu' ); | ||
| 22 : | $task = mosGetParam( $_REQUEST, 'task', '' ); | ||
| 23 : | $access = mosGetParam( $_POST, 'access', '' ); | ||
| 24 : | $utaccess = mosGetParam( $_POST, 'utaccess', '' ); | ||
| 25 : | $ItemName = mosGetParam( $_POST, 'ItemName', '' ); | ||
| 26 : | $menu = mosGetParam( $_POST, 'menu', '' ); | ||
| 27 : | $cid = mosGetParam( $_POST, 'cid', array(0) ); | ||
| 28 : | |||
| 29 : | $path = $mosConfig_absolute_path .'/administrator/components/com_menus/'; | ||
| 30 : | |||
| 31 : | if (!is_array( $cid )) { | ||
| 32 : | $cid = array(0); | ||
| 33 : | } | ||
| 34 : | |||
| 35 : | |||
| 36 : | switch ($task) { | ||
| 37 : | case 'new': | ||
| 38 : | addMenuItem( $cid, $menutype, $option, $task ); | ||
| 39 : | break; | ||
| 40 : | |||
| 41 : | case 'edit': | ||
| 42 : | $cid[0] = ( $id ? $id : $cid[0] ); | ||
| 43 : | $menu = new mosMenu( $database ); | ||
| 44 : | if ( $cid[0] ) { | ||
| 45 : | $menu->load( $cid[0] ); | ||
| 46 : | } else { | ||
| 47 : | $menu->type = $type; | ||
| 48 : | } | ||
| 49 : | |||
| 50 : | if ( $menu->type ) { | ||
| 51 : | $type = $menu->type; | ||
| 52 : | require( $path . $menu->type .'/'. $menu->type .'.menu.php' ); | ||
| 53 : | } | ||
| 54 : | break; | ||
| 55 : | |||
| 56 : | case 'save': | ||
| 57 : | case 'apply': | ||
| 58 : | require( $path . $type .'/'. $type .'.menu.php' ); | ||
| 59 : | break; | ||
| 60 : | |||
| 61 : | case 'publish': | ||
| 62 : | case 'unpublish': | ||
| 63 : | if ($msg = publishMenuSection( $cid, ($task == 'publish') )) { | ||
| 64 : | // proceed no further if the menu item can't be published | ||
| 65 : | mosRedirect( 'index2.php?option=com_menus&menutype='. $menutype .'&mosmsg= '.$msg ); | ||
| 66 : | } else { | ||
| 67 : | mosRedirect( 'index2.php?option=com_menus&menutype='. $menutype ); | ||
| 68 : | } | ||
| 69 : | break; | ||
| 70 : | |||
| 71 : | case 'remove': | ||
| 72 : | if ($msg = TrashMenusection( $cid )) { | ||
| 73 : | mosRedirect( 'index2.php?option=com_menus&menutype='. $menutype .'&mosmsg= '.$msg ); | ||
| 74 : | } else { | ||
| 75 : | mosRedirect( 'index2.php?option=com_menus&menutype='. $menutype ); | ||
| 76 : | } | ||
| 77 : | break; | ||
| 78 : | |||
| 79 : | case 'cancel': | ||
| 80 : | cancelMenu( $option ); | ||
| 81 : | break; | ||
| 82 : | |||
| 83 : | case 'orderup': | ||
| 84 : | orderMenu( $cid[0], -1, $option ); | ||
| 85 : | break; | ||
| 86 : | |||
| 87 : | case 'orderdown': | ||
| 88 : | orderMenu( $cid[0], 1, $option ); | ||
| 89 : | break; | ||
| 90 : | |||
| 91 : | case 'accesspublic': | ||
| 92 : | accessMenu( $cid[0], 0, $option, $menutype ); | ||
| 93 : | break; | ||
| 94 : | |||
| 95 : | case 'accessregistered': | ||
| 96 : | accessMenu( $cid[0], 1, $option, $menutype ); | ||
| 97 : | break; | ||
| 98 : | |||
| 99 : | case 'accessspecial': | ||
| 100 : | accessMenu( $cid[0], 2, $option, $menutype ); | ||
| 101 : | break; | ||
| 102 : | |||
| 103 : | case 'movemenu': | ||
| 104 : | moveMenu( $option, $cid, $menutype ); | ||
| 105 : | break; | ||
| 106 : | |||
| 107 : | case 'movemenusave': | ||
| 108 : | moveMenuSave( $option, $cid, $menu, $menutype ); | ||
| 109 : | break; | ||
| 110 : | |||
| 111 : | case 'copymenu': | ||
| 112 : | copyMenu( $option, $cid, $menutype ); | ||
| 113 : | break; | ||
| 114 : | |||
| 115 : | case 'copymenusave': | ||
| 116 : | copyMenuSave( $option, $cid, $menu, $menutype ); | ||
| 117 : | break; | ||
| 118 : | |||
| 119 : | case 'cancelcopymenu': | ||
| 120 : | case 'cancelmovemenu': | ||
| 121 : | viewMenuItems( $menutype, $option ); | ||
| 122 : | break; | ||
| 123 : | |||
| 124 : | case 'saveorder': | ||
| 125 : | saveOrder( $cid, $menutype ); | ||
| 126 : | break; | ||
| 127 : | |||
| 128 : | default: | ||
| 129 : | $type = trim( mosGetParam( $_REQUEST, 'type', null ) ); | ||
| 130 : | if ($type) { | ||
| 131 : | // adding a new item - type selection form | ||
| 132 : | require( $path . $type .'/'. $type .'.menu.php' ); | ||
| 133 : | } else { | ||
| 134 : | viewMenuItems( $menutype, $option ); | ||
| 135 : | } | ||
| 136 : | break; | ||
| 137 : | } | ||
| 138 : | |||
| 139 : | /** | ||
| 140 : | * Shows a list of items for a menu | ||
| 141 : | */ | ||
| 142 : | function viewMenuItems( $menutype, $option ) { | ||
| 143 : | global $database, $mainframe, $mosConfig_list_limit; | ||
| 144 : | |||
| 145 : | $limit = $mainframe->getUserStateFromRequest( "viewlistlimit", 'limit', $mosConfig_list_limit ); | ||
| 146 : | $limitstart = $mainframe->getUserStateFromRequest( "view{$option}limitstart$menutype", 'limitstart', 0 ); | ||
| 147 : | $levellimit = $mainframe->getUserStateFromRequest( "view{$option}limit$menutype", 'levellimit', 10 ); | ||
| 148 : | $search = $mainframe->getUserStateFromRequest( "search{$option}$menutype", 'search', '' ); | ||
| 149 : | $search = $database->getEscaped( trim( strtolower( $search ) ) ); | ||
| 150 : | |||
| 151 : | // select the records | ||
| 152 : | // note, since this is a tree we have to do the limits code-side | ||
| 153 : | if ($search) { | ||
| 154 : | $query = "SELECT m.id" | ||
| 155 : | . "\n FROM #__menu AS m" | ||
| 156 : | //. "\n LEFT JOIN #__content AS c ON c.id = m.componentid AND type='content_typed'" | ||
| 157 : | . "\n WHERE menutype='$menutype'" | ||
| 158 : | . "\n AND LOWER(m.name) LIKE '%" . strtolower( $search ) . "%'" | ||
| 159 : | ; | ||
| 160 : | $database->setQuery( $query ); | ||
| 161 : | $search_rows = $database->loadResultArray(); | ||
| 162 : | } | ||
| 163 : | |||
| 164 : | $query = "SELECT m.*, u.name AS editor, g.name AS groupname, c.publish_up, c.publish_down, com.name AS com_name" | ||
| 165 : | . "\n FROM #__menu AS m" | ||
| 166 : | . "\n LEFT JOIN #__users AS u ON u.id = m.checked_out" | ||
| 167 : | . "\n LEFT JOIN #__groups AS g ON g.id = m.access" | ||
| 168 : | . "\n LEFT JOIN #__content AS c ON c.id = m.componentid AND m.type='content_typed'" | ||
| 169 : | . "\n LEFT JOIN #__components AS com ON com.id = m.componentid AND m.type='components'" | ||
| 170 : | . "\n WHERE m.menutype='$menutype'" | ||
| 171 : | . "\n AND m.published != -2" | ||
| 172 : | . "\n ORDER BY parent,ordering" | ||
| 173 : | ; | ||
| 174 : | $database->setQuery( $query ); | ||
| 175 : | $rows = $database->loadObjectList(); | ||
| 176 : | |||
| 177 : | // establish the hierarchy of the menu | ||
| 178 : | $children = array(); | ||
| 179 : | // first pass - collect children | ||
| 180 : | if ($rows) foreach ($rows as $v ) { | ||
| 181 : | $pt = $v->parent; | ||
| 182 : | $list = @$children[$pt] ? $children[$pt] : array(); | ||
| 183 : | array_push( $list, $v ); | ||
| 184 : | $children[$pt] = $list; | ||
| 185 : | } | ||
| 186 : | // second pass - get an indent list of the items | ||
| 187 : | $list = mosTreeRecurse( 0, '', array(), $children, max( 0, $levellimit-1 ) ); | ||
| 188 : | // eventually only pick out the searched items. | ||
| 189 : | if ($search) { | ||
| 190 : | $list1 = array(); | ||
| 191 : | |||
| 192 : | foreach ($search_rows as $sid ) { | ||
| 193 : | foreach ($list as $item) { | ||
| 194 : | if ($item->id == $sid) { | ||
| 195 : | $list1[] = $item; | ||
| 196 : | } | ||
| 197 : | } | ||
| 198 : | } | ||
| 199 : | // replace full list with found items | ||
| 200 : | $list = $list1; | ||
| 201 : | } | ||
| 202 : | |||
| 203 : | $total = count( $list ); | ||
| 204 : | |||
| 205 : | require_once( $GLOBALS['mosConfig_absolute_path'] . '/administrator/includes/pageNavigation.php' ); | ||
| 206 : | $pageNav = new mosPageNav( $total, $limitstart, $limit ); | ||
| 207 : | |||
| 208 : | $levellist = mosHTML::integerSelectList( 1, 20, 1, 'levellimit', 'size="1" onchange="document.adminForm.submit();"', $levellimit ); | ||
| 209 : | |||
| 210 : | // slice out elements based on limits | ||
| 211 : | $list = array_slice( $list, $pageNav->limitstart, $pageNav->limit ); | ||
| 212 : | |||
| 213 : | $i = 0; | ||
| 214 : | foreach ( $list as $mitem ) { | ||
| 215 : | $edit = ''; | ||
| 216 : | switch ( $mitem->type ) { | ||
| 217 : | case 'separator': | ||
| 218 : | case 'component_item_link': | ||
| 219 : | break; | ||
| 220 : | |||
| 221 : | case 'url': | ||
| 222 : | if ( eregi( 'index.php\?', $mitem->link ) ) { | ||
| 223 : | if ( !eregi( 'Itemid=', $mitem->link ) ) { | ||
| 224 : | $mitem->link .= '&Itemid='. $mitem->id; | ||
| 225 : | } | ||
| 226 : | } | ||
| 227 : | break; | ||
| 228 : | |||
| 229 : | case 'newsfeed_link': | ||
| 230 : | $edit = 'index2.php?option=com_newsfeeds&task=edit&hidemainmenu=1A&id=' . $mitem->componentid; | ||
| 231 : | $list[$i]->descrip = 'Edit this News Feed'; | ||
| 232 : | $mitem->link .= '&Itemid='. $mitem->id; | ||
| 233 : | break; | ||
| 234 : | |||
| 235 : | case 'contact_item_link': | ||
| 236 : | $edit = 'index2.php?option=com_contact&task=editA&hidemainmenu=1&id=' . $mitem->componentid; | ||
| 237 : | $list[$i]->descrip = 'Edit this Contact'; | ||
| 238 : | $mitem->link .= '&Itemid='. $mitem->id; | ||
| 239 : | break; | ||
| 240 : | |||
| 241 : | case 'content_item_link': | ||
| 242 : | $edit = 'index2.php?option=com_content&task=edit&hidemainmenu=1&id=' . $mitem->componentid; | ||
| 243 : | $list[$i]->descrip = 'Edit this Content'; | ||
| 244 : | break; | ||
| 245 : | |||
| 246 : | case 'content_typed': | ||
| 247 : | $edit = 'index2.php?option=com_typedcontent&task=edit&hidemainmenu=1&id='. $mitem->componentid; | ||
| 248 : | $list[$i]->descrip = 'Edit this Static Content'; | ||
| 249 : | break; | ||
| 250 : | |||
| 251 : | default: | ||
| 252 : | $mitem->link .= '&Itemid='. $mitem->id; | ||
| 253 : | break; | ||
| 254 : | } | ||
| 255 : | $list[$i]->link = $mitem->link; | ||
| 256 : | $list[$i]->edit = $edit; | ||
| 257 : | $i++; | ||
| 258 : | } | ||
| 259 : | |||
| 260 : | $i = 0; | ||
| 261 : | foreach ( $list as $row ) { | ||
| 262 : | // pulls name and description from menu type xml | ||
| 263 : | $row = ReadMenuXML( $row->type, $row->com_name ); | ||
| 264 : | $list[$i]->type = $row[0]; | ||
| 265 : | if (!isset($list[$i]->descrip)) $list[$i]->descrip = $row[1]; | ||
| 266 : | $i++; | ||
| 267 : | } | ||
| 268 : | |||
| 269 : | HTML_menusections::showMenusections( $list, $pageNav, $search, $levellist, $menutype, $option ); | ||
| 270 : | } | ||
| 271 : | |||
| 272 : | /** | ||
| 273 : | * Displays a selection list for menu item types | ||
| 274 : | */ | ||
| 275 : | function addMenuItem( &$cid, $menutype, $option, $task ) { | ||
| 276 : | global $mosConfig_absolute_path; | ||
| 277 : | |||
| 278 : | $types = array(); | ||
| 279 : | |||
| 280 : | // list of directories | ||
| 281 : | $dirs = mosReadDirectory( $mosConfig_absolute_path .'/administrator/components/com_menus' ); | ||
| 282 : | |||
| 283 : | // load files for menu types | ||
| 284 : | foreach ( $dirs as $dir ) { | ||
| 285 : | // needed within menu type .php files | ||
| 286 : | $type = $dir; | ||
| 287 : | $dir = $mosConfig_absolute_path .'/administrator/components/com_menus/'. $dir; | ||
| 288 : | if ( is_dir( $dir ) ) { | ||
| 289 : | $files = mosReadDirectory( $dir, ".\.menu\.php$" ); | ||
| 290 : | foreach ($files as $file) { | ||
| 291 : | require_once( "$dir/$file" ); | ||
| 292 : | // type of menu type | ||
| 293 : | $types[]->type = $type; | ||
| 294 : | } | ||
| 295 : | } | ||
| 296 : | } | ||
| 297 : | |||
| 298 : | $i = 0; | ||
| 299 : | foreach ( $types as $type ) { | ||
| 300 : | // pulls name and description from menu type xml | ||
| 301 : | $row = ReadMenuXML( $type->type ); | ||
| 302 : | $types[$i]->name = $row[0]; | ||
| 303 : | $types[$i]->descrip = $row[1]; | ||
| 304 : | $types[$i]->group = $row[2]; | ||
| 305 : | $i++; | ||
| 306 : | } | ||
| 307 : | |||
| 308 : | // sort array of objects alphabetically by name of menu type | ||
| 309 : | SortArrayObjects( $types, 'name', 1 ); | ||
| 310 : | |||
| 311 : | // split into Content | ||
| 312 : | $i = 0; | ||
| 313 : | foreach ( $types as $type ) { | ||
| 314 : | if ( strstr( $type->group, 'Content' ) ) { | ||
| 315 : | $types_content[] = $types[$i]; | ||
| 316 : | } | ||
| 317 : | $i++; | ||
| 318 : | } | ||
| 319 : | |||
| 320 : | // split into Links | ||
| 321 : | $i = 0; | ||
| 322 : | foreach ( $types as $type ) { | ||
| 323 : | if ( strstr( $type->group, 'Link' ) ) { | ||
| 324 : | $types_link[] = $types[$i]; | ||
| 325 : | } | ||
| 326 : | $i++; | ||
| 327 : | } | ||
| 328 : | |||
| 329 : | // split into Component | ||
| 330 : | $i = 0; | ||
| 331 : | foreach ( $types as $type ) { | ||
| 332 : | if ( strstr( $type->group, 'Component' ) ) { | ||
| 333 : | $types_component[] = $types[$i]; | ||
| 334 : | } | ||
| 335 : | $i++; | ||
| 336 : | } | ||
| 337 : | |||
| 338 : | // split into Other | ||
| 339 : | $i = 0; | ||
| 340 : | foreach ( $types as $type ) { | ||
| 341 : | if ( strstr( $type->group, 'Other' ) || !$type->group ) { | ||
| 342 : | $types_other[] = $types[$i]; | ||
| 343 : | } | ||
| 344 : | $i++; | ||
| 345 : | } | ||
| 346 : | |||
| 347 : | HTML_menusections::addMenuItem( $cid, $menutype, $option, $types_content, $types_component, $types_link, $types_other ); | ||
| 348 : | } | ||
| 349 : | |||
| 350 : | |||
| 351 : | /** | ||
| 352 : | * Generic function to save the menu | ||
| 353 : | */ | ||
| 354 : | function saveMenu( $option, $task='save' ) { | ||
| 355 : | global $database; | ||
| 356 : | |||
| 357 : | $params = mosGetParam( $_POST, 'params', '' ); | ||
| 358 : | if (is_array( $params )) { | ||
| 359 : | $txt = array(); | ||
| 360 : | foreach ($params as $k=>$v) { | ||
| 361 : | $txt[] = "$k=$v"; | ||
| 362 : | } | ||
| 363 : | $_POST['params'] = mosParameters::textareaHandling( $txt ); | ||
| 364 : | } | ||
| 365 : | |||
| 366 : | $row = new mosMenu( $database ); | ||
| 367 : | |||
| 368 : | if (!$row->bind( $_POST )) { | ||
| 369 : | echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n"; | ||
| 370 : | exit(); | ||
| 371 : | } | ||
| 372 : | |||
| 373 : | if (!$row->check()) { | ||
| 374 : | echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n"; | ||
| 375 : | exit(); | ||
| 376 : | } | ||
| 377 : | if (!$row->store()) { | ||
| 378 : | echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n"; | ||
| 379 : | exit(); | ||
| 380 : | } | ||
| 381 : | $row->checkin(); | ||
| 382 : | $row->updateOrder( "menutype='$row->menutype' AND parent='$row->parent'" ); | ||
| 383 : | |||
| 384 : | andphe | 1711 | $msg = T_('Menu item Saved'); |
| 385 : | elpie | 964 | switch ( $task ) { |
| 386 : | case 'apply': | ||
| 387 : | mosRedirect( 'index2.php?option='. $option .'&menutype='. $row->menutype .'&task=edit&id='. $row->id . '&hidemainmenu=1' , $msg ); | ||
| 388 : | break; | ||
| 389 : | |||
| 390 : | case 'save': | ||
| 391 : | default: | ||
| 392 : | mosRedirect( 'index2.php?option='. $option .'&menutype='. $row->menutype, $msg ); | ||
| 393 : | break; | ||
| 394 : | } | ||
| 395 : | } | ||
| 396 : | |||
| 397 : | /** | ||
| 398 : | * Publishes or Unpublishes one or more menu sections | ||
| 399 : | * @param database A database connector object | ||
| 400 : | * @param string The name of the category section | ||
| 401 : | * @param array An array of id numbers | ||
| 402 : | * @param integer 0 if unpublishing, 1 if publishing | ||
| 403 : | */ | ||
| 404 : | function publishMenuSection( $cid=null, $publish=1 ) { | ||
| 405 : | global $database, $mosConfig_absolute_path; | ||
| 406 : | |||
| 407 : | if (!is_array( $cid ) || count( $cid ) < 1) { | ||
| 408 : | $pub = $publish ? T_('publish') : T_('unpublish'); | ||
| 409 : | return sprintf(T_('Select an item to %s'), $pub); | ||
| 410 : | } | ||
| 411 : | |||
| 412 : | $menu = new mosMenu( $database ); | ||
| 413 : | foreach ($cid as $id) { | ||
| 414 : | $menu->load( $id ); | ||
| 415 : | $menu->published = $publish; | ||
| 416 : | |||
| 417 : | if (!$menu->check()) { | ||
| 418 : | return $menu->getError(); | ||
| 419 : | } | ||
| 420 : | if (!$menu->store()) { | ||
| 421 : | return $menu->getError(); | ||
| 422 : | } | ||
| 423 : | |||
| 424 : | if ($menu->type) { | ||
| 425 : | $database = &$database; | ||
| 426 : | $task = $publish ? 'publish' : 'unpublish'; | ||
| 427 : | require( $mosConfig_absolute_path . '/administrator/components/com_menus/' . $menu->type . '/' . $menu->type . '.menu.php' ); | ||
| 428 : | } | ||
| 429 : | } | ||
| 430 : | return null; | ||
| 431 : | } | ||
| 432 : | |||
| 433 : | /** | ||
| 434 : | * Trashes a menu record | ||
| 435 : | */ | ||
| 436 : | function TrashMenuSection( $cid=NULL ) { | ||
| 437 : | global $database; | ||
| 438 : | |||
| 439 : | $state = "-2"; | ||
| 440 : | //seperate contentids | ||
| 441 : | $cids = implode( ',', $cid ); | ||
| 442 : | $query = "UPDATE #__menu SET published = '". $state ."', ordering = '0'" | ||
| 443 : | . "\n WHERE id IN ( ". $cids ." )" | ||
| 444 : | ; | ||
| 445 : | $database->setQuery( $query ); | ||
| 446 : | if ( !$database->query() ) { | ||
| 447 : | echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n"; | ||
| 448 : | exit(); | ||
| 449 : | } | ||
| 450 : | |||
| 451 : | $total = count( $cid ); | ||
| 452 : | $msg = sprintf(Tn_("%d Item sent to the Trash", "%d Items sent to the Trash", $total), $total); | ||
| 453 : | return $msg; | ||
| 454 : | } | ||
| 455 : | |||
| 456 : | /** | ||
| 457 : | * Cancels an edit operation | ||
| 458 : | */ | ||
| 459 : | function cancelMenu( $option ) { | ||
| 460 : | global $database; | ||
| 461 : | |||
| 462 : | $menu = new mosMenu( $database ); | ||
| 463 : | $menu->bind( $_POST ); | ||
| 464 : | $menuid = mosGetParam( $_POST, 'menuid', 0 ); | ||
| 465 : | if ( $menuid ) { | ||
| 466 : | $menu->id = $menuid; | ||
| 467 : | } | ||
| 468 : | // sanitize | ||
| 469 : | $row->id = intval($row->id); | ||
| 470 : | $menu->checkin(); | ||
| 471 : | /* | ||
| 472 : | if ( $menu->type == 'content_typed' ) { | ||
| 473 : | $contentid = mosGetParam( $_POST, 'id', 0 ); | ||
| 474 : | $content = new mosContent( $database ); | ||
| 475 : | $content->load( $contentid ); | ||
| 476 : | $content->checkin(); | ||
| 477 : | } | ||
| 478 : | */ | ||
| 479 : | mosRedirect( 'index2.php?option='. $option .'&menutype='. $menu->menutype ); | ||
| 480 : | } | ||
| 481 : | |||
| 482 : | /** | ||
| 483 : | * Moves the order of a record | ||
| 484 : | * @param integer The increment to reorder by | ||
| 485 : | */ | ||
| 486 : | function orderMenu( $uid, $inc, $option ) { | ||
| 487 : | global $database; | ||
| 488 : | |||
| 489 : | $row = new mosMenu( $database ); | ||
| 490 : | $row->load( $uid ); | ||
| 491 : | $row->move( $inc, 'menutype="'. $row->menutype .'" AND parent="'. $row->parent .'"' ); | ||
| 492 : | |||
| 493 : | mosRedirect( 'index2.php?option='. $option .'&menutype='. $row->menutype ); | ||
| 494 : | } | ||
| 495 : | |||
| 496 : | |||
| 497 : | /** | ||
| 498 : | * changes the access level of a record | ||
| 499 : | * @param integer The increment to reorder by | ||
| 500 : | */ | ||
| 501 : | function accessMenu( $uid, $access, $option, $menutype ) { | ||
| 502 : | global $database; | ||
| 503 : | |||
| 504 : | $menu = new mosMenu( $database ); | ||
| 505 : | $menu->load( $uid ); | ||
| 506 : | $menu->access = $access; | ||
| 507 : | |||
| 508 : | if (!$menu->check()) { | ||
| 509 : | return $menu->getError(); | ||
| 510 : | } | ||
| 511 : | if (!$menu->store()) { | ||
| 512 : | return $menu->getError(); | ||
| 513 : | } | ||
| 514 : | |||
| 515 : | mosRedirect( 'index2.php?option='. $option .'&menutype='. $menutype ); | ||
| 516 : | } | ||
| 517 : | |||
| 518 : | /** | ||
| 519 : | * Form for moving item(s) to a specific menu | ||
| 520 : | */ | ||
| 521 : | function moveMenu( $option, $cid, $menutype ) { | ||
| 522 : | global $database; | ||
| 523 : | |||
| 524 : | if (!is_array( $cid ) || count( $cid ) < 1) { | ||
| 525 : | echo "<script> alert('".T_('Select an item to move')."'); window.history.go(-1);</script>\n"; | ||
| 526 : | exit; | ||
| 527 : | } | ||
| 528 : | |||
| 529 : | ## query to list selected menu items | ||
| 530 : | $cids = implode( ',', $cid ); | ||
| 531 : | $query = "SELECT a.name FROM #__menu AS a WHERE a.id IN ( ". $cids ." )"; | ||
| 532 : | $database->setQuery( $query ); | ||
| 533 : | $items = $database->loadObjectList(); | ||
| 534 : | |||
| 535 : | ## query to choose menu | ||
| 536 : | $query = "SELECT a.params FROM #__modules AS a WHERE a.module = 'mod_mainmenu' ORDER BY a.title"; | ||
| 537 : | $database->setQuery( $query ); | ||
| 538 : | $modules = $database->loadObjectList(); | ||
| 539 : | |||
| 540 : | foreach ( $modules as $module) { | ||
| 541 : | $pparser = new mosParameters($module->params); | ||
| 542 : | $params = $pparser->getParams(); | ||
| 543 : | // adds menutype to array | ||
| 544 : | $type = trim( @$params->menutype ); | ||
| 545 : | $menu[] = mosHTML::makeOption( $type, $type ); | ||
| 546 : | } | ||
| 547 : | // build the html select list | ||
| 548 : | $MenuList = mosHTML::selectList( $menu, 'menu', 'class="inputbox" size="10"', 'value', 'text', null ); | ||
| 549 : | |||
| 550 : | HTML_menusections::moveMenu( $option, $cid, $MenuList, $items, $menutype ); | ||
| 551 : | } | ||
| 552 : | |||
| 553 : | /** | ||
| 554 : | * Add all descendants to list of meni id's | ||
| 555 : | */ | ||
| 556 : | function addDescendants($id, &$cid) | ||
| 557 : | { | ||
| 558 : | global $database; | ||
| 559 : | |||
| 560 : | $database->setQuery("SELECT id FROM #__menu WHERE parent=$id"); | ||
| 561 : | $rows = $database->loadObjectList(); | ||
| 562 : | if ($database->getErrorNum()) { | ||
| 563 : | echo "<script> alert('". $database->getErrorMsg() ."'); window.history.go(-1); </script>\n"; | ||
| 564 : | exit(); | ||
| 565 : | } // if | ||
| 566 : | foreach ($rows as $row) { | ||
| 567 : | $found = false; | ||
| 568 : | foreach ($cid as $idx) | ||
| 569 : | if ($idx == $row->id) { | ||
| 570 : | $found = true; | ||
| 571 : | break; | ||
| 572 : | } // if | ||
| 573 : | if (!$found) $cid[] = $row->id; | ||
| 574 : | addDescendants($row->id, $cid); | ||
| 575 : | } // foreach | ||
| 576 : | } // addDescendants | ||
| 577 : | |||
| 578 : | /** | ||
| 579 : | * Save the item(s) to the menu selected | ||
| 580 : | */ | ||
| 581 : | function moveMenuSave( $option, $cid, $menu, $menutype ) { | ||
| 582 : | global $database, $my; | ||
| 583 : | |||
| 584 : | // add all decendants to the list | ||
| 585 : | foreach ($cid as $id) addDescendants($id, $cid); | ||
| 586 : | |||
| 587 : | $row = new mosMenu( $database ); | ||
| 588 : | $ordering = 1000000; | ||
| 589 : | $firstroot = 0; | ||
| 590 : | foreach ($cid as $id) { | ||
| 591 : | $row->load( $id ); | ||
| 592 : | |||
| 593 : | // is it moved together with his parent? | ||
| 594 : | $found = false; | ||
| 595 : | if ($row->parent != 0) | ||
| 596 : | foreach ($cid as $idx) | ||
| 597 : | if ($idx == $row->parent) { | ||
| 598 : | $found = true; | ||
| 599 : | break; | ||
| 600 : | } // if | ||
| 601 : | if (!$found) { | ||
| 602 : | $row->parent = 0; | ||
| 603 : | $row->ordering = $ordering++; | ||
| 604 : | if (!$firstroot) $firstroot = $row->id; | ||
| 605 : | } // if | ||
| 606 : | |||
| 607 : | $row->menutype = $menu; | ||
| 608 : | if ( !$row->store() ) { | ||
| 609 : | echo "<script> alert('". $database->getErrorMsg() ."'); window.history.go(-1); </script>\n"; | ||
| 610 : | exit(); | ||
| 611 : | } // if | ||
| 612 : | } // foreach | ||
| 613 : | |||
| 614 : | if ($firstroot) { | ||
| 615 : | $row->load( $firstroot ); | ||
| 616 : | $row->updateOrder( "menutype='". $row->menutype ."' AND parent='". $row->parent ."'" ); | ||
| 617 : | } // if | ||
| 618 : | |||
| 619 : | $msg = sprintf(Tn_('%d Menu Item moved to %s', '%d Menu Items moved to %s', count($cid)), count($cid), $menu); | ||
| 620 : | mosRedirect( 'index2.php?option='. $option .'&menutype='. $menutype .'&mosmsg='. $msg ); | ||
| 621 : | } // moveMenuSave | ||
| 622 : | |||
| 623 : | /** | ||
| 624 : | * Form for copying item(s) to a specific menu | ||
| 625 : | */ | ||
| 626 : | function copyMenu( $option, $cid, $menutype ) { | ||
| 627 : | global $database; | ||
| 628 : | |||
| 629 : | if (!is_array( $cid ) || count( $cid ) < 1) { | ||
| 630 : | echo "<script> alert('".T_('Select an item to move')."'); window.history.go(-1);</script>\n"; | ||
| 631 : | exit; | ||
| 632 : | } | ||
| 633 : | |||
| 634 : | ## query to list selected menu items | ||
| 635 : | $cids = implode( ',', $cid ); | ||
| 636 : | $query = "SELECT a.name FROM #__menu AS a WHERE a.id IN ( ". $cids ." )"; | ||
| 637 : | $database->setQuery( $query ); | ||
| 638 : | $items = $database->loadObjectList(); | ||
| 639 : | |||
| 640 : | $menuTypes = mosAdminMenus::menutypes(); | ||
| 641 : | |||
| 642 : | foreach ( $menuTypes as $menuType ) { | ||
| 643 : | $menu[] = mosHTML::makeOption( $menuType, $menuType ); | ||
| 644 : | } | ||
| 645 : | // build the html select list | ||
| 646 : | $MenuList = mosHTML::selectList( $menu, 'menu', 'class="inputbox" size="10"', 'value', 'text', null ); | ||
| 647 : | |||
| 648 : | HTML_menusections::copyMenu( $option, $cid, $MenuList, $items, $menutype ); | ||
| 649 : | } | ||
| 650 : | |||
| 651 : | /** | ||
| 652 : | * Save the item(s) to the menu selected | ||
| 653 : | */ | ||
| 654 : | function copyMenuSave( $option, $cid, $menu, $menutype ) { | ||
| 655 : | global $database; | ||
| 656 : | |||
| 657 : | $curr = new mosMenu( $database ); | ||
| 658 : | $cidref = array(); | ||
| 659 : | foreach( $cid as $id ) { | ||
| 660 : | $curr->load( $id ); | ||
| 661 : | $curr->id = NULL; | ||
| 662 : | if ( !$curr->store() ) { | ||
| 663 : | echo "<script> alert('".$curr->getError()."'); window.history.go(-1); </script>\n"; | ||
| 664 : | exit(); | ||
| 665 : | } | ||
| 666 : | $cidref[] = array($id, $curr->id); | ||
| 667 : | } | ||
| 668 : | foreach ( $cidref as $ref ) { | ||
| 669 : | andphe | 1366 | unset($curr); |
| 670 : | $curr = new mosMenu( $database ); | ||
| 671 : | elpie | 964 | $curr->load( $ref[1] ); |
| 672 : | if ($curr->parent!=0) { | ||
| 673 : | $found = false; | ||
| 674 : | foreach ( $cidref as $ref2 ) | ||
| 675 : | if ($curr->parent == $ref2[0]) { | ||
| 676 : | $curr->parent = $ref2[1]; | ||
| 677 : | $found = true; | ||
| 678 : | break; | ||
| 679 : | } // if | ||
| 680 : | if (!$found && $curr->menutype!=$menu) | ||
| 681 : | $curr->parent = 0; | ||
| 682 : | } // if | ||
| 683 : | $curr->menutype = $menu; | ||
| 684 : | $curr->ordering = '9999'; | ||
| 685 : | if ( !$curr->store() ) { | ||
| 686 : | echo "<script> alert('".$curr->getError()."'); window.history.go(-1); </script>\n"; | ||
| 687 : | exit(); | ||
| 688 : | } | ||
| 689 : | $curr->updateOrder( "menutype='". $curr->menutype ."' AND parent='". $curr->parent ."'" ); | ||
| 690 : | } // foreach | ||
| 691 : | $msg = sprintf(Tn_('%d Menu Item Copied to %s', '%d Menu Items Copied to %s', count($cid)), count($cid), $menu); | ||
| 692 : | mosRedirect( 'index2.php?option='. $option .'&menutype='. $menutype .'&mosmsg='. $msg ); | ||
| 693 : | } | ||
| 694 : | |||
| 695 : | function ReadMenuXML( $type, $component=-1 ) { | ||
| 696 : | global $mosConfig_absolute_path; | ||
| 697 : | |||
| 698 : | // xml file for module | ||
| 699 : | $xmlfile = $mosConfig_absolute_path .'/administrator/components/com_menus/'. $type .'/'. $type .'.xml'; | ||
| 700 : | $parser = new mosXMLDescription ($xmlfile); | ||
| 701 : | $name = $parser->getName('menu'); | ||
| 702 : | $descrip = $parser->getDescription('menu'); | ||
| 703 : | $group = $parser->getGroup('menu'); | ||
| 704 : | |||
| 705 : | if ( ( $component <> -1 ) && ( $name == 'Component') ) { | ||
| 706 : | andphe | 1711 | $name = T_($name) . ' - '. $component; |
| 707 : | elpie | 964 | } |
| 708 : | |||
| 709 : | $row[0] = $name; | ||
| 710 : | $row[1] = $descrip; | ||
| 711 : | $row[2] = $group; | ||
| 712 : | |||
| 713 : | return $row; | ||
| 714 : | } | ||
| 715 : | |||
| 716 : | function saveOrder( &$cid, $menutype ) { | ||
| 717 : | global $database; | ||
| 718 : | $order = mosGetParam( $_POST, 'order', array(0) ); | ||
| 719 : | $row = new mosMenu( $database ); | ||
| 720 : | $parents = array(); | ||
| 721 : | // update ordering values | ||
| 722 : | foreach ($cid as $i=>$ciditem) { | ||
| 723 : | $row->load( $ciditem ); | ||
| 724 : | if ($row->ordering != $order[$i]) { | ||
| 725 : | $row->ordering = $order[$i]; | ||
| 726 : | if (!$row->store()) { | ||
| 727 : | echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n"; | ||
| 728 : | exit(); | ||
| 729 : | } | ||
| 730 : | // remember to updateOrder this group | ||
| 731 : | $parents[$row->parent] = $row->id; | ||
| 732 : | } | ||
| 733 : | } | ||
| 734 : | // execute updateOrder for each group | ||
| 735 : | foreach ($parents as $parent=>$rowid) { | ||
| 736 : | $row->updateOrder("menutype = '$menutype' AND parent = '$parent' AND published >= 0"); | ||
| 737 : | } // foreach | ||
| 738 : | |||
| 739 : | $msg = T_('New ordering saved'); | ||
| 740 : | mosRedirect( 'index2.php?option=com_menus&menutype='. $menutype, $msg ); | ||
| 741 : | } // saveOrder | ||
| 742 : | |||
| 743 : | |||
| 744 : | ?> |
| ViewVC Help | |
| Powered by ViewVC 1.0.0 |
Web Hosting provided by Network Redux.

