Beispiel #1
0
/**
* Shows a list of items for a menu
*/
function viewMenuItems($menutype, $option)
{
    global $database, $mainframe, $mosConfig_list_limit;
    $limit = $mainframe->getUserStateFromRequest("viewlistlimit", 'limit', $mosConfig_list_limit);
    $limitstart = $mainframe->getUserStateFromRequest("view{$option}limitstart{$menutype}", 'limitstart', 0);
    $levellimit = $mainframe->getUserStateFromRequest("view{$option}limit{$menutype}", 'levellimit', 10);
    $search = $mainframe->getUserStateFromRequest("search{$option}{$menutype}", 'search', '');
    $search = $database->getEscaped(trim(strtolower($search)));
    // select the records
    // note, since this is a tree we have to do the limits code-side
    if ($search) {
        $query = "SELECT m.id" . "\n FROM #__menu AS m" . "\n WHERE menutype='{$menutype}'" . "\n AND LOWER(m.name) LIKE '%" . strtolower($search) . "%'";
        $database->setQuery($query);
        $search_rows = $database->loadResultArray();
    }
    $query = "SELECT m.*, u.name AS editor, g.name AS groupname, c.publish_up, c.publish_down, com.name AS com_name" . "\n FROM #__menu AS m" . "\n LEFT JOIN #__users AS u ON u.id = m.checked_out" . "\n LEFT JOIN #__groups AS g ON g.id = m.access" . "\n LEFT JOIN #__content AS c ON c.id = m.componentid AND m.type='content_typed'" . "\n LEFT JOIN #__components AS com ON com.id = m.componentid AND m.type='components'" . "\n WHERE m.menutype='{$menutype}'" . "\n AND m.published != -2" . "\n ORDER BY parent,ordering";
    $database->setQuery($query);
    $rows = $database->loadObjectList();
    // establish the hierarchy of the menu
    $children = array();
    // first pass - collect children
    foreach ($rows as $v) {
        $pt = $v->parent;
        $list = @$children[$pt] ? $children[$pt] : array();
        array_push($list, $v);
        $children[$pt] = $list;
    }
    // second pass - get an indent list of the items
    $list = mosTreeRecurse(0, '', array(), $children, max(0, $levellimit - 1));
    // eventually only pick out the searched items.
    if ($search) {
        $list1 = array();
        foreach ($search_rows as $sid) {
            foreach ($list as $item) {
                if ($item->id == $sid) {
                    $list1[] = $item;
                }
            }
        }
        // replace full list with found items
        $list = $list1;
    }
    $total = count($list);
    require_once $GLOBALS['mosConfig_absolute_path'] . '/administrator/includes/pageNavigation.php';
    $pageNav = new mosPageNav($total, $limitstart, $limit);
    $levellist = mosHTML::integerSelectList(1, 20, 1, 'levellimit', 'size="1" onchange="document.adminForm.submit();"', $levellimit);
    // slice out elements based on limits
    $list = array_slice($list, $pageNav->limitstart, $pageNav->limit);
    $i = 0;
    foreach ($list as $mitem) {
        switch ($mitem->type) {
            case 'separator':
            case 'component_item_link':
                break;
            case 'content_item_link':
                $temp = split("&task=view&id=", $mitem->link);
                $mitem->link .= '&Itemid=' . $mainframe->getItemid($temp[1]);
                break;
            case 'url':
                if (eregi('index.php\\?', $mitem->link)) {
                    if (!eregi('Itemid=', $mitem->link)) {
                        $mitem->link .= '&Itemid=' . $mitem->id;
                    }
                }
                break;
            case 'content_typed':
            case 'content_item_link':
            default:
                $mitem->link .= '&Itemid=' . $mitem->id;
                break;
        }
        $list[$i]->link = $mitem->link;
        $i++;
    }
    $i = 0;
    foreach ($list as $row) {
        $name = RenameMenu($row->type, $row->com_name);
        $list[$i]->type = $name;
        $i++;
    }
    HTML_menusections::showMenusections($list, $pageNav, $search, $levellist, $menutype, $option);
}
Beispiel #2
0
function JLMSmultiselect($groups_arr = array(), $show_root = true, $course_id)
{
    global $my, $JLMS_DB;
    $JLMS_ACL =& JLMSFactory::getACL();
    $assigned_groups_only = $JLMS_ACL->CheckPermissions('advanced', 'assigned_groups_only');
    $members = "'0'";
    $groups_where_admin_manager = "'0'";
    if ($assigned_groups_only && $JLMS_ACL->_role_type > 1) {
        $groups_where_admin_manager = JLMS_ACL_HELPER::GetAssignedGroups($my->id, $course_id);
        $groups_where_admin_manager = implode(',', $groups_where_admin_manager);
    }
    if ($groups_where_admin_manager == '') {
        $groups_where_admin_manager = "'0'";
    }
    $where = "\n AND course_id = 0";
    if ($assigned_groups_only) {
        $where .= "\n AND id IN ({$groups_where_admin_manager})";
    }
    // get a list of the menu items
    // excluding the current menu item and its child elements
    $query = "SELECT id, ug_name as name, parent_id as parent" . "\n FROM #__lms_usergroups" . "\n WHERE 1" . $where . "\n ORDER BY ug_name, parent_id";
    $JLMS_DB->setQuery($query);
    $mitems = $JLMS_DB->loadObjectList();
    //echo $JLMS_DB->geterrormsg();
    // establish the hierarchy of the menu
    $children = array();
    if ($mitems) {
        // first pass - collect children
        foreach ($mitems as $v) {
            $pt = $v->parent;
            /** Joomla 1.6 compability { */
            $v->parent_id = $v->parent;
            $v->title = $v->name;
            /** } Joomla 1.6 compability*/
            $list = @$children[$pt] ? $children[$pt] : array();
            array_push($list, $v);
            $children[$pt] = $list;
        }
    }
    // second pass - get an indent list of the items
    $list = mosTreeRecurse(0, '', array(), $children, 20, 0, 0);
    //$javascript = ' onchange="javascript:view_fields(this,1);"';
    $javascript = '';
    // assemble menu items to the array
    $mitems = array();
    //	if ($show_root) {
    //		$mitems[] 	= mosHTML::makeOption( '0', 'Top' );
    //	}
    $query = "SELECT group_id, subgroup1_id FROM #__lms_users_in_global_groups WHERE user_id IN ( SELECT user_id FROM #__lms_users_in_groups WHERE course_id = {$course_id} )";
    $JLMS_DB->setQuery($query);
    $all_groups_in_course = $JLMS_DB->LoadObjectList();
    $rows = array();
    foreach ($list as $item) {
        $rows[] = mosHTML::makeOption($item->id, ($show_root ? '   ' : '') . $item->treename);
    }
    // assemble menu items to the array
    $select_list = '<select class="text_area" style="width: 272px;" size="12" multiple="multiple" name="groups[]" id="restricted_groups">';
    for ($i = 0; $i < count($rows); $i++) {
        $selected = '';
        for ($j = 0; $j < count($groups_arr); $j++) {
            if ($groups_arr[$j] == $rows[$i]->value) {
                $selected = 'selected="selected"';
                break;
            }
        }
        $flag = 0;
        for ($k = 0; $k < count($all_groups_in_course); $k++) {
            if ($rows[$i]->value == $all_groups_in_course[$k]->group_id || $rows[$i]->value == $all_groups_in_course[$k]->subgroup1_id) {
                $flag = 1;
                break;
            }
        }
        if ($flag == 0) {
            $style = 'style="color: grey"';
        } else {
            $style = '';
        }
        $select_list .= '<option value="' . $rows[$i]->value . '" ' . $selected . ' ' . $style . '>' . $rows[$i]->text . '</option>';
    }
    $select_list .= '</select>';
    //$output = mosHTML::selectList( $mitems, 'groups', 'class="text_area" size="12"'.(is_array($selected) ? ' multiple="multiple"' : '').' style="width: 272px;"'. $javascript, 'value', 'text', $selected );
    return $select_list;
}
 function GQP_parent($ex_id = 0, $selected = 0, $sb_name = 'parent', $show_root = true)
 {
     global $JLMS_DB;
     $id = '';
     if ($ex_id) {
         $id = "\n AND id != " . (int) $ex_id;
     }
     // get a list of the menu items
     // excluding the current menu item and its child elements
     $query = "SELECT id, c_category as name, parent" . "\n FROM #__lms_gqp_cats" . "\n WHERE 1" . $id . "\n ORDER BY parent, c_category";
     $JLMS_DB->setQuery($query);
     $mitems = $JLMS_DB->loadObjectList();
     // establish the hierarchy of the menu
     $children = array();
     if ($mitems) {
         // first pass - collect children
         foreach ($mitems as $v) {
             $pt = $v->parent;
             /** Joomla 1.6 compability { */
             $v->parent_id = $v->parent;
             $v->title = $v->name;
             /** } Joomla 1.6 compability*/
             $list = @$children[$pt] ? $children[$pt] : array();
             array_push($list, $v);
             $children[$pt] = $list;
         }
     }
     // second pass - get an indent list of the items
     $list = mosTreeRecurse(0, '', array(), $children, 20, 0, 0);
     $javascript = '';
     // onchange="javascript:view_fields(this,1);"';
     // assemble menu items to the array
     $mitems = array();
     if ($show_root) {
         $mitems[] = mosHTML::makeOption('0', 'Top');
     }
     foreach ($list as $item) {
         $mitems[] = mosHTML::makeOption($item->id, ($show_root ? '&nbsp;&nbsp;&nbsp;' : '') . $item->treename);
     }
     $output = mosHTML::selectList($mitems, $sb_name, 'class="text_area" size="12"' . (is_array($selected) ? ' multiple="multiple"' : '') . ' style="width: 272px;"' . $javascript, 'value', 'text', $selected);
     return $output;
 }
Beispiel #4
0
 /**
  * build the multiple select list for Menu Links/Pages
  */
 function MenuLinks(&$lookup, $all = NULL, $none = NULL, $unassigned = 1)
 {
     global $database;
     // get a list of the menu items
     $query = "SELECT m.*" . "\n FROM #__menu AS m" . "\n WHERE m.published = 1" . "\n ORDER BY m.menutype, m.parent, m.ordering";
     $database->setQuery($query);
     $mitems = $database->loadObjectList();
     $mitems_temp = $mitems;
     // establish the hierarchy of the menu
     $children = array();
     // first pass - collect children
     foreach ($mitems as $v) {
         $id = $v->id;
         $pt = $v->parent;
         $list = @$children[$pt] ? $children[$pt] : array();
         array_push($list, $v);
         $children[$pt] = $list;
     }
     // second pass - get an indent list of the items
     $list = mosTreeRecurse(intval($mitems[0]->parent), '', array(), $children, 20, 0, 0);
     // Code that adds menu name to Display of Page(s)
     $text_count = 0;
     $mitems_spacer = $mitems_temp[0]->menutype;
     foreach ($list as $list_a) {
         foreach ($mitems_temp as $mitems_a) {
             if ($mitems_a->id == $list_a->id) {
                 // Code that inserts the blank line that seperates different menus
                 if ($mitems_a->menutype != $mitems_spacer) {
                     $list_temp[] = mosHTML::makeOption(-999, '----');
                     $mitems_spacer = $mitems_a->menutype;
                 }
                 // do not display `url` menu item types that contain `index.php` and `Itemid`
                 if (!($mitems_a->type == 'url' && strpos($mitems_a->link, 'index.php') !== false && strpos($mitems_a->link, 'Itemid=') !== false)) {
                     $text = $mitems_a->menutype . ' | ' . $list_a->treename;
                     $list_temp[] = mosHTML::makeOption($list_a->id, $text);
                     if (strlen($text) > $text_count) {
                         $text_count = strlen($text);
                     }
                 }
             }
         }
     }
     $list = $list_temp;
     $mitems = array();
     if ($all) {
         // prepare an array with 'all' as the first item
         $mitems[] = mosHTML::makeOption(0, 'Todas');
         // adds space, in select box which is not saved
         $mitems[] = mosHTML::makeOption(-999, '----');
     }
     if ($none) {
         // prepare an array with 'all' as the first item
         $mitems[] = mosHTML::makeOption(-999, 'Nenhuma');
         // adds space, in select box which is not saved
         $mitems[] = mosHTML::makeOption(-999, '----');
     }
     if ($unassigned) {
         // prepare an array with 'all' as the first item
         $mitems[] = mosHTML::makeOption(99999999, 'Não atribuída');
         // adds space, in select box which is not saved
         $mitems[] = mosHTML::makeOption(-999, '----');
     }
     // append the rest of the menu items to the array
     foreach ($list as $item) {
         $mitems[] = mosHTML::makeOption($item->value, $item->text);
     }
     $pages = mosHTML::selectList($mitems, 'selections[]', 'class="inputbox" size="26" multiple="multiple"', 'value', 'text', $lookup);
     return $pages;
 }
/**
 * Generates an HTML select list from a tree based query list
 * @param array Source array with id and parent fields
 * @param array The id of the current list item
 * @param array Target array.  May be an empty array.
 * @param array An array of objects
 * @param string The value of the HTML name attribute
 * @param string Additional HTML attributes for the <select> tag
 * @param string The name of the object variable for the option value
 * @param string The name of the object variable for the option text
 * @param mixed The key that is selected
 * @returns string HTML for the select list
 */
function html_treeSelectList(&$src_list, $src_id, $tgt_list, $tag_name, $tag_attribs, $key, $text, $selected)
{
    // establish the hierarchy of the menu
    $children = array();
    // first pass - collect children
    foreach ($src_list as $v) {
        $pt = $v->parent;
        $list = @$children[$pt] ? $children[$pt] : array();
        array_push($list, $v);
        $children[$pt] = $list;
    }
    // second pass - get an indent list of the items
    $ilist = mosTreeRecurse(0, '', array(), $children);
    // assemble menu items to the array
    $this_treename = '';
    foreach ($ilist as $item) {
        if ($this_treename) {
            if ($item->id != $src_id && strpos($item->treename, $this_treename) === false) {
                $tgt_list[] = html_makeOption($item->id, $item->treename);
            }
        } else {
            if ($item->id != $src_id) {
                $tgt_list[] = html_makeOption($item->id, $item->treename);
            } else {
                $this_treename = "{$item->treename}/";
            }
        }
    }
    // build the html select list
    return html_selectList($tgt_list, $tag_name, $tag_attribs, $key, $text, $selected);
}
Beispiel #6
0
 /**
  * build the multiple select list for Menu Links/Pages
  */
 function MenuLinks(&$lookup, $all = NULL, $none = NULL)
 {
     global $database;
     // get a list of the menu items
     $database->setQuery("SELECT m.*" . "\n FROM #__menu m" . "\n WHERE type != 'separator'" . "\n AND link NOT LIKE '%tp:/%'" . "\n AND published = '1'" . "\n ORDER BY menutype, parent, ordering");
     $mitems = $database->loadObjectList();
     $mitems_temp = $mitems;
     // establish the hierarchy of the menu
     $children = array();
     // first pass - collect children
     foreach ($mitems as $v) {
         $id = $v->id;
         $pt = $v->parent;
         $list = @$children[$pt] ? $children[$pt] : array();
         array_push($list, $v);
         $children[$pt] = $list;
     }
     // second pass - get an indent list of the items
     $list = mosTreeRecurse(intval($mitems[0]->parent), '', array(), $children, 9999, 0, 0);
     // Code that adds menu name to Display of Page(s)
     $text_count = "0";
     $mitems_spacer = $mitems_temp[0]->menutype;
     foreach ($list as $list_a) {
         foreach ($mitems_temp as $mitems_a) {
             if ($mitems_a->id == $list_a->id) {
                 // Code that inserts the blank line that seperates different menus
                 if ($mitems_a->menutype != $mitems_spacer) {
                     $list_temp[] = mosHTML::makeOption(-999, '----');
                     $mitems_spacer = $mitems_a->menutype;
                 }
                 $text = $mitems_a->menutype . " | " . $list_a->treename;
                 $list_temp[] = mosHTML::makeOption($list_a->id, $text);
                 if (strlen($text) > $text_count) {
                     $text_count = strlen($text);
                 }
             }
         }
     }
     $list = $list_temp;
     $mitems = array();
     if ($all) {
         // prepare an array with 'all' as the first item
         $mitems[] = mosHTML::makeOption(0, T_('All'));
         // adds space, in select box which is not saved
         $mitems[] = mosHTML::makeOption(-999, '----');
     }
     if ($none) {
         // prepare an array with 'all' as the first item
         $mitems[] = mosHTML::makeOption(-998, T_('None'));
         // adds space, in select box which is not saved
         $mitems[] = mosHTML::makeOption(-999, '----');
     }
     // append the rest of the menu items to the array
     foreach ($list as $item) {
         $mitems[] = mosHTML::makeOption($item->value, $item->text);
     }
     if ($lookup == NULL) {
         $lookup = '-998';
     }
     $pages = mosHTML::selectList($mitems, 'selections[]', 'class="inputbox" size="26" multiple="multiple"', 'value', 'text', $lookup);
     return $pages;
 }