3 * @version $Id: menu.php 1795 2009-04-24 09:29:31Z fishbone $
4 * @package Joomla.Framework
6 * @copyright Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
7 * @license 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.
16 defined( '_JEXEC' ) or die( 'Restricted access' );
19 * Utility class working with menu select lists
22 * @package Joomla.Framework
29 * Build the select list for Menu Ordering
31 function ordering( &$row, $id )
33 $db =& JFactory::getDBO();
37 $query = 'SELECT ordering AS value, name AS text'
39 . ' WHERE menutype = '.$db->Quote($row->menutype)
40 . ' AND parent = '.(int) $row->parent
41 . ' AND published != -2'
42 . ' ORDER BY ordering';
43 $order = JHTML::_('list.genericordering', $query );
44 $ordering = JHTML::_('select.genericlist', $order, 'ordering', 'class="inputbox" size="1"', 'value', 'text', intval( $row->ordering ) );
48 $ordering = '<input type="hidden" name="ordering" value="'. $row->ordering .'" />'. JText::_( 'DESCNEWITEMSLAST' );
54 * Build the multiple select list for Menu Links/Pages
56 function linkoptions( $all=false, $unassigned=false )
58 $db =& JFactory::getDBO();
60 // get a list of the menu items
61 $query = 'SELECT m.id, m.parent, m.name, m.menutype'
62 . ' FROM #__menu AS m'
63 . ' WHERE m.published = 1'
64 . ' ORDER BY m.menutype, m.parent, m.ordering'
66 $db->setQuery( $query );
67 $mitems = $db->loadObjectList();
68 $mitems_temp = $mitems;
70 // establish the hierarchy of the menu
72 // first pass - collect children
73 foreach ( $mitems as $v )
77 $list = @$children[$pt] ? $children[$pt] : array();
78 array_push( $list, $v );
79 $children[$pt] = $list;
81 // second pass - get an indent list of the items
82 $list = JHTMLMenu::TreeRecurse( intval( $mitems[0]->parent ), '', array(), $children, 9999, 0, 0 );
84 // Code that adds menu name to Display of Page(s)
85 $mitems_spacer = $mitems_temp[0]->menutype;
88 if ($all | $unassigned) {
89 $mitems[] = JHTML::_('select.option', '<OPTGROUP>', JText::_( 'Menus' ) );
92 $mitems[] = JHTML::_('select.option', 0, JText::_( 'All' ) );
95 $mitems[] = JHTML::_('select.option', -1, JText::_( 'Unassigned' ) );
98 $mitems[] = JHTML::_('select.option', '</OPTGROUP>' );
101 $lastMenuType = null;
103 foreach ($list as $list_a)
105 if ($list_a->menutype != $lastMenuType)
108 $mitems[] = JHTML::_('select.option', '</OPTGROUP>' );
110 $mitems[] = JHTML::_('select.option', '<OPTGROUP>', $list_a->menutype );
111 $lastMenuType = $list_a->menutype;
112 $tmpMenuType = $list_a->menutype;
115 $mitems[] = JHTML::_('select.option', $list_a->id, $list_a->treename );
117 if ($lastMenuType !== null) {
118 $mitems[] = JHTML::_('select.option', '</OPTGROUP>' );
124 function treerecurse( $id, $indent, $list, &$children, $maxlevel=9999, $level=0, $type=1 )
126 if (@$children[$id] && $level <= $maxlevel)
128 foreach ($children[$id] as $v)
133 $pre = '<sup>|_</sup> ';
134 $spacer = '. ';
137 $spacer = ' ';
140 if ( $v->parent == 0 ) {
143 $txt = $pre . $v->name;
147 $list[$id]->treename = "$indent$txt";
148 $list[$id]->children = count( @$children[$id] );
149 $list = JHTMLMenu::TreeRecurse( $id, $indent . $spacer, $list, $children, $maxlevel, $level+1, $type );