示例#1
0
function MB_editElement($menu_id, $mid)
{
    global $_CONF, $_TABLES, $_PLUGINS, $LANG_MB01, $LANG_MB_ADMIN, $LANG_MB_TYPES, $LANG_MB_GLTYPES, $LANG_MB_GLFUNCTION;
    $retval = '';
    $menu = menu::getInstance($menu_id);
    $menu_arr = array(array('url' => $_CONF['site_admin_url'] . '/menu.php?mode=menu&menu=' . $menu_id, 'text' => $LANG_MB01['return_to'] . $menu->name), array('url' => $_CONF['site_admin_url'] . '/menu.php', 'text' => $LANG_MB01['menu_list']));
    $retval .= COM_startBlock($LANG_MB01['menu_builder'] . ' :: ' . $LANG_MB01['edit_element'] . ' for ' . $menu->name, '', COM_getBlockTemplate('_admin_block', 'header'));
    $retval .= ADMIN_createMenu($menu_arr, $LANG_MB_ADMIN[5], $_CONF['layout_url'] . '/images/icons/menubuilder.png');
    // build types select
    if ($menu->menu_elements[$mid]->type == 1 && count($menu->menu_elements[$mid]->children) > 0) {
        $type_select = '<input type="hidden" name="menutype" id="menutype" value="1">';
        $type_select .= '<select id="menutyped" name="menutyped" disabled="disabled">' . LB;
    } else {
        $type_select = '<select id="menutype" name="menutype">' . LB;
    }
    while ($types = current($LANG_MB_TYPES)) {
        if (($menu->type == 2 || $menu->type == 4) && (key($LANG_MB_TYPES) == 1 || key($LANG_MB_TYPES) == 3)) {
            // skip it
        } else {
            $type_select .= '<option value="' . key($LANG_MB_TYPES) . '"';
            $type_select .= ($menu->menu_elements[$mid]->type == key($LANG_MB_TYPES) ? ' selected="selected"' : '') . '>' . $types . '</option>' . LB;
        }
        next($LANG_MB_TYPES);
    }
    $type_select .= '</select>' . LB;
    $glfunction_select = '<select id="glfunction" name="glfunction">' . LB;
    while ($glfunction = current($LANG_MB_GLFUNCTION)) {
        $glfunction_select .= '<option value="' . key($LANG_MB_GLFUNCTION) . '"';
        $glfunction_select .= ($menu->menu_elements[$mid]->subtype == key($LANG_MB_GLFUNCTION) ? ' selected="selected"' : '') . '>' . $glfunction . '</option>' . LB;
        next($LANG_MB_GLFUNCTION);
    }
    $glfunction_select .= '</select>' . LB;
    $gl_select = '<select id="gltype" name="gltype">' . LB;
    while ($gltype = current($LANG_MB_GLTYPES)) {
        $gl_select .= '<option value="' . key($LANG_MB_GLTYPES) . '"';
        $gl_select .= ($menu->menu_elements[$mid]->subtype == key($LANG_MB_GLTYPES) ? ' selected="selected"' : '') . '>' . $gltype . '</option>' . LB;
        next($LANG_MB_GLTYPES);
    }
    $gl_select .= '</select>' . LB;
    $plugin_select = '<select id="pluginname" name="pluginname">' . LB;
    $plugin_menus = _mbPLG_getMenuItems();
    ksort($plugin_menus);
    $found = 0;
    $num_plugins = count($plugin_menus);
    for ($i = 1; $i <= $num_plugins; $i++) {
        $plugin_select .= '<option value="' . key($plugin_menus) . '"';
        if ($menu->menu_elements[$mid]->subtype == key($plugin_menus)) {
            $plugin_select .= ' selected="selected"';
            $found++;
        }
        $plugin_select .= '>' . ucfirst(key($plugin_menus)) . '</option>' . LB;
        next($plugin_menus);
    }
    if ($found == 0) {
        $plugin_select .= '<option value="' . $menu->menu_elements[$mid]->subtype . '" selected="selected">' . $LANG_MB01['disabled_plugin'] . '</option>' . LB;
    }
    $plugin_select .= '</select>' . LB;
    $sp_select = '<select id="spname" name="spname">' . LB;
    if (in_array('staticpages', $_PLUGINS)) {
        $sql = "SELECT sp_id,sp_title,sp_label FROM {$_TABLES['staticpage']} WHERE sp_status = 1 ORDER BY sp_title";
        $result = DB_query($sql);
        while (list($sp_id, $sp_title, $sp_label) = DB_fetchArray($result)) {
            if (trim($sp_label) == '') {
                $label = $sp_title;
            } else {
                $label = $sp_label;
            }
            $sp_select .= '<option value="' . $sp_id . '"' . ($menu->menu_elements[$mid]->subtype == $sp_id ? ' selected="selected"' : '') . '>' . $label . '</option>' . LB;
        }
    }
    $sp_select .= '</select>' . LB;
    $topic_select = '<select id="topicname" name="topicname">' . LB;
    $sql = "SELECT tid,topic FROM {$_TABLES['topics']} ORDER BY topic";
    $result = DB_query($sql);
    while (list($tid, $topic) = DB_fetchArray($result)) {
        $topic_select .= '<option value="' . $tid . '"' . ($menu->menu_elements[$mid]->subtype == $tid ? ' selected="selected"' : '') . '>' . $topic . '</option>' . LB;
    }
    $topic_select .= '</select>' . LB;
    if ($menu->type == 2 || $menu->type == 4) {
        $parent_select = '<input type="hidden" name="pid" id="pid" value="0"/>' . $LANG_MB01['top_level'];
    } else {
        $parent_select = '<select id="pid" name="pid">' . LB;
        $parent_select .= '<option value="0">' . $LANG_MB01['top_level'] . '</option>' . LB;
        $result = DB_query("SELECT id,element_label FROM {$_TABLES['menu_elements']} WHERE menu_id='" . $menu_id . "' AND element_type=1");
        while ($row = DB_fetchArray($result)) {
            if ($row['id'] != $mid) {
                $parent_select .= '<option value="' . $row['id'] . '" ' . ($menu->menu_elements[$mid]->pid == $row['id'] ? 'selected="selected"' : '') . '>' . $row['element_label'] . '</option>' . LB;
            }
        }
        $parent_select .= '</select>' . LB;
    }
    // build group select
    $rootUser = DB_getItem($_TABLES['group_assignments'], 'ug_uid', 'ug_main_grp_id=1');
    $usergroups = SEC_getUserGroups($rootUser);
    $usergroups[$LANG_MB01['non-logged-in']] = 998;
    uksort($usergroups, "strnatcasecmp");
    $group_select = '<select id="group" name="group">' . LB;
    for ($i = 0; $i < count($usergroups); $i++) {
        $group_select .= '<option value="' . $usergroups[key($usergroups)] . '"';
        if ($menu->menu_elements[$mid]->group_id == $usergroups[key($usergroups)]) {
            $group_select .= ' selected="selected"';
        }
        $group_select .= '>' . ucfirst(key($usergroups)) . '</option>' . LB;
        next($usergroups);
    }
    $group_select .= '</select>' . LB;
    $target_select = '<select id="urltarget" name="urltarget">' . LB;
    $target_select .= '<option value=""' . ($menu->menu_elements[$mid]->target == "" ? ' selected="selected"' : '') . '>' . $LANG_MB01['same_window'] . '</option>' . LB;
    $target_select .= '<option value="_blank"' . ($menu->menu_elements[$mid]->target == "_blank" ? ' selected="selected"' : '') . '>' . $LANG_MB01['new_window'] . '</option>' . LB;
    $target_select .= '</select>' . LB;
    if ($menu->menu_elements[$mid]->active) {
        $active_selected = ' checked="checked"';
    } else {
        $active_selected = '';
    }
    $order_select = '<select id="menuorder" name="menuorder">' . LB;
    $order_select .= '<option value="0">' . $LANG_MB01['first_position'] . '</option>' . LB;
    $result = DB_query("SELECT id,element_label,element_order FROM {$_TABLES['menu_elements']} WHERE menu_id='" . $menu_id . "' AND pid=" . (int) $menu->menu_elements[$mid]->pid . " ORDER BY element_order ASC");
    $order = 10;
    while ($row = DB_fetchArray($result)) {
        if ($menu->menu_elements[$mid]->order != $order) {
            $label = strip_tags($row['element_label']);
            if (trim($label) == "") {
                $label = htmlspecialchars($row['element_label']);
            }
            $test_order = $order + 10;
            $order_select .= '<option value="' . $row['id'] . '"' . ($menu->menu_elements[$mid]->order == $test_order ? ' selected="selected"' : '') . '>' . $label . '</option>' . LB;
        }
        $order += 10;
    }
    $order_select .= '</select>' . LB;
    $T = new Template($_CONF['path_layout'] . 'admin/menu');
    $T->set_file('admin', 'editelement.thtml');
    $T->set_var(array('form_action' => $_CONF['site_admin_url'] . '/menu.php', 'birdseed' => '<a href="' . $_CONF['site_admin_url'] . '/menu.php">' . $LANG_MB01['menu_list'] . '</a> :: <a href="' . $_CONF['site_admin_url'] . '/menu.php?mode=menu&amp;menu=' . $menu_id . '">' . $menu->name . '</a> :: ' . $LANG_MB01['edit_element'], 'menulabel' => htmlspecialchars($menu->menu_elements[$mid]->label), 'menuorder' => $menu->menu_elements[$mid]->order, 'order_select' => $order_select, 'menuurl' => $menu->menu_elements[$mid]->url, 'phpfunction' => $menu->menu_elements[$mid]->subtype, 'type_select' => $type_select, 'gl_select' => $gl_select, 'plugin_select' => $plugin_select, 'sp_select' => $sp_select, 'topic_select' => $topic_select, 'glfunction_select' => $glfunction_select, 'parent_select' => $parent_select, 'group_select' => $group_select, 'target_select' => $target_select, 'active_selected' => $active_selected, 'menu' => $menu_id, 'mid' => $mid, 'mode' => 'saveedit'));
    $T->parse('output', 'admin');
    $retval .= $T->finish($T->get_var('output'));
    $retval .= COM_endBlock(COM_getBlockTemplate('_admin_block', 'footer'));
    return $retval;
}
示例#2
0
 function _parseElement()
 {
     global $_SP_CONF, $_USER, $_TABLES, $LANG01, $_CONF, $_GROUPS;
     $returnArray = array();
     $childArray = array();
     $item_array = array();
     if ($this->active != 1 && $this->id != 0) {
         return NULL;
     }
     if ($this->group_id == 998 && !COM_isAnonUser()) {
         return NULL;
     }
     if (isset($_REQUEST['topic'])) {
         $topic = COM_applyFilter($_REQUEST['topic']);
     } else {
         $topic = '';
     }
     if (COM_isAnonUser()) {
         $anon = 1;
     } else {
         $anon = 0;
     }
     $allowed = true;
     if ($this->group_id != 998 && $this->id != 0 && !SEC_inGroup($this->group_id)) {
         return NULL;
     }
     if ($this->group_id == 1 && !isset($_GROUPS['Root'])) {
         return NULL;
     }
     switch ($this->type) {
         case ET_SUB_MENU:
             $this->replace_macros();
             break;
         case ET_FUSION_ACTION:
             switch ($this->subtype) {
                 case 0:
                     // home
                     $this->url = $_CONF['site_url'] . '/';
                     break;
                 case 1:
                     // contribute
                     if ($anon && ($_CONF['loginrequired'] || $_CONF['submitloginrequired'])) {
                         return NULL;
                     }
                     if (empty($topic)) {
                         $this->url = $_CONF['site_url'] . '/submit.php?type=story';
                     } else {
                         $this->url = $_CONF['site_url'] . '/submit.php?type=story&amp;topic=' . $topic;
                     }
                     $label = $LANG01[71];
                     break;
                 case 2:
                     // directory
                     if ($anon && ($_CONF['loginrequired'] || $_CONF['directoryloginrequired'])) {
                         return NULL;
                     }
                     $this->url = $_CONF['site_url'] . '/directory.php';
                     if (!empty($topic)) {
                         $this->url = COM_buildUrl($this->url . '?topic=' . urlencode($topic));
                     }
                     break;
                 case 3:
                     // prefs
                     if ($anon && ($_CONF['loginrequired'] || $_CONF['profileloginrequired'])) {
                         return NULL;
                     }
                     $this->url = $_CONF['site_url'] . '/usersettings.php?mode=edit';
                     break;
                 case 4:
                     // search
                     if ($anon && ($_CONF['loginrequired'] || $_CONF['searchloginrequired'])) {
                         return NULL;
                     }
                     $this->url = $_CONF['site_url'] . '/search.php';
                     break;
                 case 5:
                     // stats
                     if (!SEC_hasRights('stats.view')) {
                         return NULL;
                     }
                     $this->url = $_CONF['site_url'] . '/stats.php';
                     break;
                 default:
                     // unknown?
                     $this->url = $_CONF['site_url'] . '/';
                     break;
             }
             break;
         case ET_FUSION_MENU:
             $this->url = '';
             switch ($this->subtype) {
                 case USER_MENU:
                     // if anonymous user - show login entry
                     if (COM_isAnonUser()) {
                         $this->label = $LANG01[58];
                         $this->url = $_CONF['site_url'] . '/users.php';
                         $this->target = '';
                         break;
                     }
                     // logged-in user see My Account entry
                     $item_array = getUserMenu();
                     $this->label = $LANG01[47];
                     break;
                 case ADMIN_MENU:
                     $this->url = $_CONF['site_admin_url'];
                     $item_array = getAdminMenu();
                     break;
                 case TOPIC_MENU:
                     $item_array = getTopicMenu();
                     break;
                 case STATICPAGE_MENU:
                     $item_array = array();
                     $order = '';
                     if (!empty($_SP_CONF['sort_menu_by'])) {
                         $order = ' ORDER BY ';
                         if ($_SP_CONF['sort_menu_by'] == 'date') {
                             $order .= 'sp_date DESC';
                         } else {
                             if ($_SP_CONF['sort_menu_by'] == 'label') {
                                 $order .= 'sp_label';
                             } else {
                                 if ($_SP_CONF['sort_menu_by'] == 'title') {
                                     $order .= 'sp_title';
                                 } else {
                                     // default to "sort by id"
                                     $order .= 'sp_id';
                                 }
                             }
                         }
                     }
                     $result = DB_query('SELECT sp_id, sp_label FROM ' . $_TABLES['staticpage'] . ' WHERE sp_onmenu = 1 AND sp_status = 1' . COM_getPermSql('AND') . $order);
                     $nrows = DB_numRows($result);
                     $menuitems = array();
                     for ($i = 0; $i < $nrows; $i++) {
                         $A = DB_fetchArray($result);
                         $url = COM_buildURL($_CONF['site_url'] . '/page.php?page=' . $A['sp_id']);
                         $label = $A['sp_label'];
                         $item_array[] = array('label' => $label, 'url' => $url);
                     }
                     break;
                 case PLUGIN_MENU:
                     $item_array = array();
                     $plugin_menu = PLG_getMenuItems();
                     if (count($plugin_menu) == 0) {
                         $this->access = 0;
                     } else {
                         for ($i = 1; $i <= count($plugin_menu); $i++) {
                             $url = current($plugin_menu);
                             $label = key($plugin_menu);
                             $item_array[] = array('label' => $label, 'url' => $url);
                             next($plugin_menu);
                         }
                     }
                     break;
                 case HEADER_MENU:
                 default:
             }
             break;
         case ET_PLUGIN:
             $plugin_menus = _mbPLG_getMenuItems();
             if (isset($plugin_menus[$this->subtype])) {
                 $this->url = $plugin_menus[$this->subtype];
             } else {
                 $this->access = 0;
                 $allowed = 0;
             }
             break;
         case ET_STATICPAGE:
             $this->url = COM_buildURL($_CONF['site_url'] . '/page.php?page=' . $this->subtype);
             break;
         case ET_URL:
             $this->replace_macros();
             break;
         case ET_PHP:
             $functionName = $this->subtype;
             if (function_exists($functionName)) {
                 $item_array = $functionName();
             }
             break;
         case ET_TOPIC:
             $this->url = $_CONF['site_url'] . '/index.php?topic=' . $this->subtype;
             break;
         default:
             break;
     }
     if ($this->id != 0 && $this->group_id == 998 && SEC_inGroup('Root')) {
         return NULL;
     }
     if ($allowed == 0 || $this->access == 0) {
         return NULL;
     }
     if ($this->type == ET_FUSION_MENU || $this->type == ET_PHP) {
         $childArray = $item_array;
     } else {
         if (!empty($this->children)) {
             $howmany = $this->getChildcount();
             if ($howmany > 0) {
                 $children = $this->getChildren();
                 foreach ($children as $child) {
                     $elementArray = $child->_parseElement();
                     if ($elementArray != NULL) {
                         $childArray[] = $elementArray;
                     }
                 }
             }
         } else {
             $childArray = NULL;
         }
     }
     $returnArray = array('label' => $this->label, 'url' => $this->url, 'target' => $this->target, 'children' => is_array($childArray) ? $childArray : NULL);
     return $returnArray;
 }