[ Index ]
 

Code source de Joomla 1.0.13

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

/administrator/components/com_menus/ -> admin.menus.php (source)

   1  <?php
   2  /**
   3  * @version $Id: admin.menus.php 5047 2006-09-14 13:49:01Z 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  require_once( $mainframe->getPath( 'admin_html' ) );
  19  
  20  $path         = $mosConfig_absolute_path .'/administrator/components/com_menus/';
  21  
  22  $menutype     = stripslashes( strval( mosGetParam( $_REQUEST, 'menutype', 'mainmenu' ) ) );
  23  $type         = stripslashes( strval( mosGetParam( $_REQUEST, 'type', false ) ) );
  24  $menu         = stripslashes( strval( mosGetParam( $_POST, 'menu', '' ) ) );
  25  
  26  $cid         = josGetArrayInts( 'cid' );
  27  
  28  switch ($task) {
  29      case 'new':
  30          addMenuItem( $cid, $menutype, $option, $task );
  31          break;
  32  
  33      case 'edit':
  34          $cid[0]    = ( $id ? $id : intval( $cid[0] ) );
  35          $menu = new mosMenu( $database );
  36          if ( $cid[0] ) {
  37              $menu->load( $cid[0]  );
  38          } else {
  39              $menu->type = $type;
  40          }
  41  
  42          if ( $menu->type ) {
  43              $type = $menu->type;
  44              require_once( $path . $menu->type .'/'. $menu->type .'.menu.php' );
  45          }
  46          break;
  47  
  48      case 'save':
  49      case 'apply':    
  50          // clean any existing cache files
  51          mosCache::cleanCache( 'com_content' );
  52          require_once( $path . $type .'/'. $type .'.menu.php' );
  53          break;
  54  
  55      case 'publish':
  56      case 'unpublish':
  57          publishMenuSection( $cid, ($task == 'publish'), $menutype );
  58          break;
  59  
  60      case 'remove':
  61          TrashMenusection( $cid, $menutype );
  62          break;
  63  
  64      case 'cancel':
  65          cancelMenu( $option );
  66          break;
  67  
  68      case 'orderup':
  69          orderMenu( intval( $cid[0] ), -1, $option );
  70          break;
  71  
  72      case 'orderdown':
  73          orderMenu( intval( $cid[0] ), 1, $option );
  74          break;
  75  
  76      case 'accesspublic':
  77          accessMenu( intval( $cid[0] ), 0, $option, $menutype );
  78          break;
  79  
  80      case 'accessregistered':
  81          accessMenu( intval( $cid[0] ), 1, $option, $menutype );
  82          break;
  83  
  84      case 'accessspecial':
  85          accessMenu( intval( $cid[0] ), 2, $option, $menutype );
  86          break;
  87  
  88      case 'movemenu':
  89          moveMenu( $option, $cid, $menutype );
  90          break;
  91  
  92      case 'movemenusave':
  93          moveMenuSave( $option, $cid, $menu, $menutype );
  94          break;
  95  
  96      case 'copymenu':
  97          copyMenu( $option, $cid, $menutype );
  98          break;
  99  
 100      case 'copymenusave':
 101          copyMenuSave( $option, $cid, $menu, $menutype );
 102          break;
 103  
 104      case 'cancelcopymenu':
 105      case 'cancelmovemenu':
 106          viewMenuItems( $menutype, $option );
 107          break;
 108  
 109      case 'saveorder':
 110          saveOrder( $cid, $menutype );
 111          break;
 112  
 113      default:
 114          $type = stripslashes( strval( mosGetParam( $_REQUEST, 'type' ) ) );
 115          if ($type) {
 116              // adding a new item - type selection form
 117              require_once( $path . $type .'/'. $type .'.menu.php' );
 118          } else {
 119              viewMenuItems( $menutype, $option );
 120          }
 121          break;
 122  }
 123  
 124  /**
 125  * Shows a list of items for a menu
 126  */
 127  function viewMenuItems( $menutype, $option ) {
 128      global $database, $mainframe, $mosConfig_list_limit;
 129  
 130      $limit         = intval( $mainframe->getUserStateFromRequest( "viewlistlimit", 'limit', $mosConfig_list_limit ) );
 131      $limitstart = intval( $mainframe->getUserStateFromRequest( "view{$option}limitstart$menutype", 'limitstart', 0 ) );
 132      $levellimit = intval( $mainframe->getUserStateFromRequest( "view{$option}limit$menutype", 'levellimit', 10 ) );
 133      $search     = $mainframe->getUserStateFromRequest( "search{$option}$menutype", 'search', '' );
 134      if (get_magic_quotes_gpc()) {
 135          $search    = stripslashes( $search );
 136      }
 137  
 138      // select the records
 139      // note, since this is a tree we have to do the limits code-side
 140      if ($search) {
 141          $query = "SELECT m.id"
 142          . "\n FROM #__menu AS m"
 143          //. "\n LEFT JOIN #__content AS c ON c.id = m.componentid AND type='content_typed'"
 144          . "\n WHERE menutype = " . $database->Quote( $menutype )
 145          . "\n AND LOWER( m.name ) LIKE '%" . $database->getEscaped( trim( strtolower( $search ) ) ) . "%'"
 146          ;
 147          $database->setQuery( $query );
 148          $search_rows = $database->loadResultArray();
 149      }
 150  
 151      $query = "SELECT m.*, u.name AS editor, g.name AS groupname, c.publish_up, c.publish_down, com.name AS com_name"
 152      . "\n FROM #__menu AS m"
 153      . "\n LEFT JOIN #__users AS u ON u.id = m.checked_out"
 154      . "\n LEFT JOIN #__groups AS g ON g.id = m.access"
 155      . "\n LEFT JOIN #__content AS c ON c.id = m.componentid AND m.type = 'content_typed'"
 156      . "\n LEFT JOIN #__components AS com ON com.id = m.componentid AND m.type = 'components'"
 157      . "\n WHERE m.menutype = " . $database->Quote( $menutype )
 158      . "\n AND m.published != -2"
 159      . "\n ORDER BY parent, ordering"
 160      ;
 161      $database->setQuery( $query );
 162      $rows = $database->loadObjectList();
 163  
 164      // establish the hierarchy of the menu
 165      $children = array();
 166      // first pass - collect children
 167      foreach ($rows as $v ) {
 168          $pt = $v->parent;
 169          $list = @$children[$pt] ? $children[$pt] : array();
 170          array_push( $list, $v );
 171          $children[$pt] = $list;
 172      }
 173      // second pass - get an indent list of the items
 174      $list = mosTreeRecurse( 0, '', array(), $children, max( 0, $levellimit-1 ) );
 175      // eventually only pick out the searched items.
 176      if ($search) {
 177          $list1 = array();
 178  
 179          foreach ($search_rows as $sid ) {
 180              foreach ($list as $item) {
 181                  if ($item->id == $sid) {
 182                      $list1[] = $item;
 183                  }
 184              }
 185          }
 186          // replace full list with found items
 187          $list = $list1;
 188      }
 189  
 190      $total = count( $list );
 191  
 192      require_once( $GLOBALS['mosConfig_absolute_path'] . '/administrator/includes/pageNavigation.php' );
 193      $pageNav = new mosPageNav( $total, $limitstart, $limit  );
 194  
 195      $levellist = mosHTML::integerSelectList( 1, 20, 1, 'levellimit', 'size="1" onchange="document.adminForm.submit();"', $levellimit );
 196  
 197      // slice out elements based on limits
 198      $list = array_slice( $list, $pageNav->limitstart, $pageNav->limit );
 199  
 200      $i = 0;
 201      foreach ( $list as $mitem ) {
 202          $edit = '';
 203          switch ( $mitem->type ) {
 204              case 'separator':
 205              case 'component_item_link':
 206                  break;
 207  
 208              case 'url':
 209                  if ( eregi( 'index.php\?', $mitem->link ) ) {
 210                      if ( !eregi( 'Itemid=', $mitem->link ) ) {
 211                          $mitem->link .= '&Itemid='. $mitem->id;
 212                      }
 213                  }
 214                  break;
 215  
 216              case 'newsfeed_link':
 217                  $edit = 'index2.php?option=com_newsfeeds&task=edit&hidemainmenu=1A&id=' . $mitem->componentid;
 218                  $list[$i]->descrip     = 'Edit this Newsfeed';
 219                  $mitem->link .= '&Itemid='. $mitem->id;
 220                  break;
 221  
 222              case 'contact_item_link':
 223                  $edit = 'index2.php?option=com_contact&task=editA&hidemainmenu=1&id=' . $mitem->componentid;
 224                  $list[$i]->descrip     = 'Edit this Contact';
 225                  $mitem->link .= '&Itemid='. $mitem->id;
 226                  break;
 227  
 228              case 'content_item_link':
 229                  $edit = 'index2.php?option=com_content&task=edit&hidemainmenu=1&id=' . $mitem->componentid;
 230                  $list[$i]->descrip     = 'Edit this Content';
 231                  break;
 232  
 233              case 'content_typed':
 234                  $edit = 'index2.php?option=com_typedcontent&task=edit&hidemainmenu=1&id='. $mitem->componentid;
 235                  $list[$i]->descrip     = 'Edit this Static Content';
 236                  break;
 237  
 238              default:
 239                  $mitem->link .= '&Itemid='. $mitem->id;
 240                  break;
 241          }
 242          $list[$i]->link = $mitem->link;
 243          $list[$i]->edit = $edit;
 244          $i++;
 245      }
 246  
 247      $i = 0;
 248      foreach ( $list as $row ) {
 249          // pulls name and description from menu type xml
 250          $row = ReadMenuXML( $row->type, $row->com_name );
 251          $list[$i]->type     = $row[0];
 252          if (!isset($list[$i]->descrip)) $list[$i]->descrip = $row[1];
 253          $i++;
 254      }
 255  
 256      HTML_menusections::showMenusections( $list, $pageNav, $search, $levellist, $menutype, $option );
 257  }
 258  
 259  /**
 260  * Displays a selection list for menu item types
 261  */
 262  function addMenuItem( &$cid, $menutype, $option, $task ) {
 263      global $mosConfig_absolute_path;
 264  
 265      $types     = array();
 266  
 267      // list of directories
 268      $dirs     = mosReadDirectory( $mosConfig_absolute_path .'/administrator/components/com_menus' );
 269  
 270      // load files for menu types
 271      foreach ( $dirs as $dir ) {
 272          // needed within menu type .php files
 273          $type     = $dir;
 274          $dir     = $mosConfig_absolute_path .'/administrator/components/com_menus/'. $dir;
 275          if ( is_dir( $dir ) ) {
 276              $files = mosReadDirectory( $dir, ".\.menu\.php$" );
 277              foreach ($files as $file) {
 278                  require_once( "$dir/$file" );
 279                  // type of menu type
 280                  $types[]->type = $type;
 281              }
 282          }
 283      }
 284  
 285      $i = 0;
 286      foreach ( $types as $type ) {
 287          // pulls name and description from menu type xml
 288          $row = ReadMenuXML( $type->type );
 289          $types[$i]->name     = $row[0];
 290          $types[$i]->descrip = $row[1];
 291          $types[$i]->group     = $row[2];
 292          $i++;
 293      }
 294  
 295      // sort array of objects alphabetically by name of menu type
 296      SortArrayObjects( $types, 'name', 1 );
 297  
 298      // split into Content
 299      $i = 0;
 300      foreach ( $types as $type ) {
 301          if ( strstr( $type->group, 'Content' ) ) {
 302              $types_content[] = $types[$i];
 303          }
 304          $i++;
 305      }
 306  
 307      // split into Links
 308      $i = 0;
 309      foreach ( $types as $type ) {
 310          if ( strstr( $type->group, 'Link' ) ) {
 311              $types_link[] = $types[$i];
 312          }
 313          $i++;
 314      }
 315  
 316      // split into Component
 317      $i = 0;
 318      foreach ( $types as $type ) {
 319          if ( strstr( $type->group, 'Component' ) ) {
 320              $types_component[] = $types[$i];
 321          }
 322          $i++;
 323      }
 324  
 325      // split into Other
 326      $i = 0;
 327      foreach ( $types as $type ) {
 328          if ( strstr( $type->group, 'Other' ) || !$type->group ) {
 329              $types_other[] = $types[$i];
 330          }
 331          $i++;
 332      }
 333  
 334      // split into Submit
 335      $i = 0;
 336      foreach ( $types as $type ) {
 337          if ( strstr( $type->group, 'Submit' ) || !$type->group ) {
 338              $types_submit[] = $types[$i];
 339          }
 340          $i++;
 341      }
 342  
 343      HTML_menusections::addMenuItem( $cid, $menutype, $option, $types_content, $types_component, $types_link, $types_other, $types_submit );
 344  }
 345  
 346  
 347  /**
 348  * Generic function to save the menu
 349  */
 350  function saveMenu( $option, $task='save' ) {
 351      global $database;
 352  
 353      $params = mosGetParam( $_POST, 'params', '' );
 354      if (is_array( $params )) {
 355          $txt = array();
 356          foreach ($params as $k=>$v) {
 357              $txt[] = "$k=$v";
 358          }
 359          $_POST['params'] = mosParameters::textareaHandling( $txt );
 360      }
 361  
 362      $row = new mosMenu( $database );
 363  
 364      if (!$row->bind( $_POST )) {
 365          echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
 366          exit();
 367      }
 368  
 369      $row->name = ampReplace( $row->name );
 370      
 371      if (!$row->check()) {
 372          echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
 373          exit();
 374      }
 375      if (!$row->store()) {
 376          echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
 377          exit();
 378      }
 379      $row->checkin();
 380      $row->updateOrder( 'menutype = ' . $database->Quote( $row->menutype ) . ' AND parent = ' . (int) $row->parent );
 381  
 382      $msg = 'Menu item Saved';
 383      switch ( $task ) {
 384          case 'apply':
 385              mosRedirect( 'index2.php?option='. $option .'&menutype='. $row->menutype .'&task=edit&id='. $row->id . '&hidemainmenu=1' , $msg );
 386              break;
 387  
 388          case 'save':
 389          default:
 390              mosRedirect( 'index2.php?option='. $option .'&menutype='. $row->menutype, $msg );
 391              break;
 392      }
 393  }
 394  
 395  /**
 396  * Publishes or Unpublishes one or more menu sections
 397  * @param database A database connector object
 398  * @param string The name of the category section
 399  * @param array An array of id numbers
 400  * @param integer 0 if unpublishing, 1 if publishing
 401  */
 402  function publishMenuSection( $cid=null, $publish=1, $menutype ) {
 403      global $database, $mosConfig_absolute_path;
 404  
 405      if (!is_array( $cid ) || count( $cid ) < 1) {
 406          return 'Select an item to ' . ($publish ? 'publish' : 'unpublish');
 407      }
 408  
 409      $menu = new mosMenu( $database );
 410      foreach ($cid as $id) {
 411          $menu->load( $id );
 412          $menu->published = $publish;
 413  
 414          if (!$menu->check()) {
 415              return $menu->getError();
 416          }
 417          if (!$menu->store()) {
 418              return $menu->getError();
 419          }
 420  
 421          if ($menu->type) {
 422              $database = &$database;
 423              $task = $publish ? 'publish' : 'unpublish';
 424              // $type value is used in *.menu.php
 425              $type = $menu->type;
 426              require_once( $mosConfig_absolute_path . '/administrator/components/com_menus/' . $type . '/' . $type . '.menu.php' );
 427          }
 428      }
 429      
 430      // clean any existing cache files
 431      mosCache::cleanCache( 'com_content' );
 432  
 433      mosRedirect( 'index2.php?option=com_menus&menutype='. $menutype );
 434  }
 435  
 436  /**
 437  * Trashes a menu record
 438  */
 439  function TrashMenuSection( $cid=NULL, $menutype='mainmenu' ) {
 440      global $database;
 441      
 442      $nullDate    = $database->getNullDate();
 443      $state        = -2;
 444      
 445      $query = "SELECT *"
 446      . "\n FROM #__menu"
 447      . "\n WHERE menutype = " . $database->Quote( $menutype )
 448      . "\n AND published != " . (int) $state
 449      . "\n ORDER BY menutype, parent, ordering"
 450      ;
 451      $database->setQuery( $query );
 452      $mitems = $database->loadObjectList();    
 453      
 454      // determine if selected item has an child items
 455      $children = array();
 456      foreach ( $cid as $id ) {
 457          foreach ( $mitems as $item ) {
 458              if ( $item->parent == $id ) {
 459                  $children[] = $item->id;
 460              }        
 461          }
 462      }    
 463      $list     = josMenuChildrenRecurse( $mitems, $children, $children );
 464      $list     = array_merge( $cid, $list );
 465  
 466      mosArrayToInts( $list );
 467      $ids = 'id=' . implode( ' OR id=', $list );
 468      
 469      $query = "UPDATE #__menu"
 470      . "\n SET published = " . (int) $state . ", ordering = 0, checked_out = 0, checked_out_time = " . $database->Quote( $nullDate )
 471      . "\n WHERE ( $ids )"
 472      ;
 473      $database->setQuery( $query );
 474      if ( !$database->query() ) {
 475          echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n";
 476          exit();
 477      }
 478  
 479      $total = count( $cid );
 480      
 481      // clean any existing cache files
 482      mosCache::cleanCache( 'com_content' );
 483  
 484      $msg = $total .' Item(s) sent to the Trash';    
 485      mosRedirect( 'index2.php?option=com_menus&menutype='. $menutype, $msg );
 486  }
 487  
 488  /**
 489  * Cancels an edit operation
 490  */
 491  function cancelMenu( $option ) {
 492      global $database;
 493  
 494      $menu = new mosMenu( $database );
 495      $menu->bind( $_POST );
 496      $menuid = intval( mosGetParam( $_POST, 'menuid', 0 ) );
 497      if ( $menuid ) {
 498          $menu->id = $menuid;
 499      }
 500      $menu->checkin();
 501  
 502      mosRedirect( 'index2.php?option='. $option .'&menutype='. $menu->menutype );
 503  }
 504  
 505  /**
 506  * Moves the order of a record
 507  * @param integer The increment to reorder by
 508  */
 509  function orderMenu( $uid, $inc, $option ) {
 510      global $database;
 511  
 512      $row = new mosMenu( $database );
 513      $row->load( $uid );
 514      $row->move( $inc, "menutype = " . $database->Quote( $row->menutype ) . " AND parent = " . (int) $row->parent );
 515      
 516      // clean any existing cache files
 517      mosCache::cleanCache( 'com_content' );
 518  
 519      mosRedirect( 'index2.php?option='. $option .'&menutype='. $row->menutype );
 520  }
 521  
 522  
 523  /**
 524  * changes the access level of a record
 525  * @param integer The increment to reorder by
 526  */
 527  function accessMenu( $uid, $access, $option, $menutype ) {
 528      global $database;
 529  
 530      $menu = new mosMenu( $database );
 531      $menu->load( $uid );
 532      $menu->access = $access;
 533  
 534      if (!$menu->check()) {
 535          return $menu->getError();
 536      }
 537      if (!$menu->store()) {
 538          return $menu->getError();
 539      }
 540      
 541      // clean any existing cache files
 542      mosCache::cleanCache( 'com_content' );
 543  
 544      mosRedirect( 'index2.php?option='. $option .'&menutype='. $menutype );
 545  }
 546  
 547  /**
 548  * Form for moving item(s) to a specific menu
 549  */
 550  function moveMenu( $option, $cid, $menutype ) {
 551      global $database;
 552  
 553      if (!is_array( $cid ) || count( $cid ) < 1) {
 554          echo "<script> alert('Select an item to move'); window.history.go(-1);</script>\n";
 555          exit;
 556      }
 557  
 558      ## query to list selected menu items
 559      mosArrayToInts( $cid );
 560      $cids = 'a.id=' . implode( ' OR a.id=', $cid );
 561      $query = "SELECT a.name"
 562      . "\n FROM #__menu AS a"
 563      . "\n WHERE ( $cids )"
 564      ;
 565      $database->setQuery( $query );
 566      $items = $database->loadObjectList();
 567  
 568      ## query to choose menu
 569      $query = "SELECT a.params"
 570      . "\n FROM #__modules AS a"
 571      . "\n WHERE a.module = 'mod_mainmenu'"
 572      . "\n ORDER BY a.title"
 573      ;
 574      $database->setQuery( $query );
 575      $modules = $database->loadObjectList();
 576  
 577      foreach ( $modules as $module) {
 578          $params = mosParseParams( $module->params );
 579          // adds menutype to array
 580          $type = trim( @$params->menutype );
 581          $menu[] = mosHTML::makeOption( $type, $type );
 582      }
 583      // build the html select list
 584      $MenuList = mosHTML::selectList( $menu, 'menu', 'class="inputbox" size="10"', 'value', 'text', null );
 585  
 586      HTML_menusections::moveMenu( $option, $cid, $MenuList, $items, $menutype );
 587  }
 588  
 589  /**
 590  * Add all descendants to list of meni id's
 591  */
 592  function addDescendants($id, &$cid) {
 593      global $database;
 594  
 595      $query = "SELECT id"
 596      . "\n FROM #__menu"
 597      . "\n WHERE parent = " . (int) $id
 598      ;
 599      $database->setQuery( $query );
 600      $rows = $database->loadObjectList();
 601      if ($database->getErrorNum()) {
 602          echo "<script> alert('". $database->getErrorMsg() ."'); window.history.go(-1); </script>\n";
 603          exit();
 604      } // if
 605      foreach ($rows as $row) {
 606          $found = false;
 607          foreach ($cid as $idx)
 608              if ($idx == $row->id) {
 609                  $found = true;
 610                  break;
 611              } // if
 612          if (!$found) $cid[] = $row->id;
 613          addDescendants($row->id, $cid);
 614      } // foreach
 615  } // addDescendants
 616  
 617  /**
 618  * Save the item(s) to the menu selected
 619  */
 620  function moveMenuSave( $option, $cid, $menu, $menutype ) {
 621      global $database;
 622  
 623      // add all decendants to the list
 624      foreach ($cid as $id) addDescendants($id, $cid);
 625  
 626      $row         = new mosMenu( $database );
 627      $ordering     = 1000000;
 628      $firstroot     = 0;
 629      foreach ($cid as $id) {
 630          $row->load( $id );
 631  
 632          // is it moved together with his parent?
 633          $found = false;
 634          if ($row->parent != 0)
 635              foreach ($cid as $idx)
 636                  if ($idx == $row->parent) {
 637                      $found = true;
 638                      break;
 639                  } // if
 640          if (!$found) {
 641              $row->parent = 0;
 642              $row->ordering = $ordering++;
 643              if (!$firstroot) $firstroot = $row->id;
 644          } // if
 645  
 646          $row->menutype = $menu;
 647          if ( !$row->store() ) {
 648              echo "<script> alert('". $database->getErrorMsg() ."'); window.history.go(-1); </script>\n";
 649              exit();
 650          } // if
 651      } // foreach
 652  
 653      if ($firstroot) {
 654          $row->load( $firstroot );
 655          $row->updateOrder( 'menutype = ' . $database->Quote( $row->menutype ) . ' AND parent = ' . (int) $row->parent );
 656      } // if
 657  
 658      // clean any existing cache files
 659      mosCache::cleanCache( 'com_content' );
 660      
 661      $msg = count($cid) .' Menu Items moved to '. $menu;
 662      mosRedirect( 'index2.php?option='. $option .'&menutype='. $menutype .'&mosmsg='. $msg );
 663  } // moveMenuSave
 664  
 665  /**
 666  * Form for copying item(s) to a specific menu
 667  */
 668  function copyMenu( $option, $cid, $menutype ) {
 669      global $database;
 670  
 671      if (!is_array( $cid ) || count( $cid ) < 1) {
 672          echo "<script> alert('Select an item to move'); window.history.go(-1);</script>\n";
 673          exit;
 674      }
 675  
 676      ## query to list selected menu items
 677      mosArrayToInts( $cid );
 678      $cids = 'a.id=' . implode( ' OR a.id=', $cid );
 679      $query = "SELECT a.name"
 680      . "\n FROM #__menu AS a"
 681      . "\n WHERE ( $cids )"
 682      ;
 683      $database->setQuery( $query );
 684      $items = $database->loadObjectList();
 685  
 686      $menuTypes     = mosAdminMenus::menutypes();
 687  
 688      foreach ( $menuTypes as $menuType ) {
 689          $menu[] = mosHTML::makeOption( $menuType, $menuType );
 690      }
 691      // build the html select list
 692      $MenuList = mosHTML::selectList( $menu, 'menu', 'class="inputbox" size="10"', 'value', 'text', null );
 693  
 694      HTML_menusections::copyMenu( $option, $cid, $MenuList, $items, $menutype );
 695  }
 696  
 697  /**
 698  * Save the item(s) to the menu selected
 699  */
 700  function copyMenuSave( $option, $cid, $menu, $menutype ) {
 701      global $database;
 702  
 703      $curr = new mosMenu( $database );
 704      $cidref = array();
 705      foreach( $cid as $id ) {
 706          $curr->load( $id );
 707          $curr->id = NULL;
 708          if ( !$curr->store() ) {
 709              echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
 710              exit();
 711          }
 712          $cidref[] = array($id, $curr->id);
 713      }
 714      foreach ( $cidref as $ref ) {
 715          $curr->load( $ref[1] );
 716          if ($curr->parent!=0) {
 717              $found = false;
 718              foreach ( $cidref as $ref2 )
 719                  if ($curr->parent == $ref2[0]) {
 720                      $curr->parent = $ref2[1];
 721                      $found = true;
 722                      break;
 723                  } // if
 724              if (!$found && $curr->menutype!=$menu)
 725                  $curr->parent = 0;
 726          } // if
 727          $curr->menutype = $menu;
 728          $curr->ordering = '9999';
 729          if ( !$curr->store() ) {
 730              echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
 731              exit();
 732          }
 733          $curr->updateOrder( 'menutype = ' . $database->Quote( $curr->menutype ) . ' AND parent = ' . (int) $curr->parent );
 734      } // foreach
 735      
 736      // clean any existing cache files
 737      mosCache::cleanCache( 'com_content' );
 738  
 739      $msg = count( $cid ) .' Menu Items Copied to '. $menu;
 740      mosRedirect( 'index2.php?option='. $option .'&menutype='. $menutype .'&mosmsg='. $msg );
 741  }
 742  
 743  function ReadMenuXML( $type, $component=-1 ) {
 744      global $mosConfig_absolute_path;
 745  
 746      // XML library
 747      require_once ( $mosConfig_absolute_path . '/includes/domit/xml_domit_lite_include.php' );
 748      // xml file for module
 749      $xmlfile = $mosConfig_absolute_path .'/administrator/components/com_menus/'. $type .'/'. $type .'.xml';
 750      $xmlDoc = new DOMIT_Lite_Document();
 751      $xmlDoc->resolveErrors( true );
 752  
 753      if ($xmlDoc->loadXML( $xmlfile, false, true )) {
 754          $root = &$xmlDoc->documentElement;
 755  
 756          if ( $root->getTagName() == 'mosinstall' && ( $root->getAttribute( 'type' ) == 'component' || $root->getAttribute( 'type' ) == 'menu' ) ) {
 757              // Menu Type Name
 758              $element     = &$root->getElementsByPath( 'name', 1 );
 759              $name         = $element ? trim( $element->getText() ) : '';
 760              // Menu Type Description
 761              $element     = &$root->getElementsByPath( 'description', 1 );
 762              $descrip     = $element ? trim( $element->getText() ) : '';
 763              // Menu Type Group
 764              $element     = &$root->getElementsByPath( 'group', 1 );
 765              $group         = $element ? trim( $element->getText() ) : '';
 766          }
 767      }
 768  
 769      if ( ( $component != -1 ) && ( $name == 'Component') ) {
 770              $name .= ' - '. $component;
 771      }
 772  
 773      $row[0]    = $name;
 774      $row[1] = $descrip;
 775      $row[2] = $group;
 776  
 777      return $row;
 778  }
 779  
 780  function saveOrder( &$cid, $menutype ) {
 781      global $database;
 782  
 783      $total        = count( $cid );
 784      $order         = josGetArrayInts( 'order' );
 785      
 786      $row        = new mosMenu( $database );
 787      $conditions = array();
 788  
 789      // update ordering values
 790      for( $i=0; $i < $total; $i++ ) {
 791          $row->load( (int) $cid[$i] );
 792          if ($row->ordering != $order[$i]) {
 793              $row->ordering = $order[$i];
 794              if (!$row->store()) {
 795                  echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n";
 796                  exit();
 797              }
 798              // remember to updateOrder this group
 799              $condition = "menutype = " . $database->Quote( $menutype ) . " AND parent = " . (int) $row->parent . " AND published >= 0";
 800              $found = false;
 801              foreach ( $conditions as $cond )
 802                  if ($cond[1]==$condition) {
 803                      $found = true;
 804                      break;
 805                  } 
 806              if (!$found) $conditions[] = array($row->id, $condition);
 807          } 
 808      } 
 809  
 810      // execute updateOrder for each group
 811      foreach ( $conditions as $cond ) {
 812          $row->load( $cond[0] );
 813          $row->updateOrder( $cond[1] );
 814      } 
 815      
 816      // clean any existing cache files
 817      mosCache::cleanCache( 'com_content' );
 818  
 819      $msg     = 'New ordering saved';
 820      mosRedirect( 'index2.php?option=com_menus&menutype='. $menutype, $msg );
 821  } 
 822  
 823  /**
 824  * Returns list of child items for a given set of ids from menu items supplied
 825  *
 826  */
 827  function josMenuChildrenRecurse( $mitems, $parents, $list, $maxlevel=20, $level=0 ) {
 828      // check to reduce recursive processing
 829      if ( $level <= $maxlevel && count( $parents ) ) {
 830          $children = array();
 831          foreach ( $parents as $id ) {            
 832              foreach ( $mitems as $item ) {
 833                  if ( $item->parent == $id ) {
 834                      $children[] = $item->id;
 835                  }        
 836              }
 837          }    
 838          
 839          // check to reduce recursive processing
 840          if ( count( $children ) ) {
 841              $list = josMenuChildrenRecurse( $mitems, $children, $list, $maxlevel, $level+1 );
 842              
 843              $list = array_merge( $list, $children );
 844          }
 845      }
 846      
 847      return $list;
 848  }
 849  ?>


Généré le : Wed Nov 21 14:43:32 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics