form = "linkform"; $pst->page = "links.php?create"; $pst->id = "admin_links"; require_once('auth.php'); // -------------------- $pst->save_preset(); require_once(e_HANDLER.'userclass_class.php'); require_once(e_HANDLER.'form_handler.php'); $rs = new form; $linkpost = new links; if (e_QUERY) { $tmp = explode('.', e_QUERY); $action = $tmp[0]; $sub_action = $tmp[1]; $id = $tmp[2]; unset($tmp); } foreach(array_keys($_POST) as $k) { if (preg_match("#(.*?)_delete_(\d+)(.*)#", $k, $matches)) { $delete = $matches[1]; $del_id = $matches[2]; } } if(isset($_POST['generate_sublinks']) && isset($_POST['sublink_type']) && $_POST['sublink_parent'] !="" ){ $subtype = $_POST['sublink_type']; $sublink = $linkpost->sublink_list($subtype); if(!is_object($sql2)){ $sql2 = new db; } $sql -> db_Select("links", "*", "link_id = '".$_POST['sublink_parent']."'"); $par = $sql-> db_Fetch(); extract($par); $sql -> db_Select($sublink['table'], "*", $sublink['query']); $count = 1; while($row = $sql-> db_Fetch()){ $subcat = $row[($sublink['fieldid'])]; $name = $row[($sublink['fieldname'])]; $subname = "submenu.$link_name.$name"; $suburl = str_replace("#",$subcat,$sublink['url']); $subicon = ($sublink['fieldicon']) ? $row[($sublink['fieldicon'])] : $link_button; $subdiz = ($sublink['fielddiz']) ? $row[($sublink['fielddiz'])] : $link_description; $subparent = $_POST['sublink_parent']; if($sql2->db_Insert("links", "0, '$subname', '$suburl', '$subdiz', '$subicon', '$link_category', '$count', '$subparent', '$link_open', '$link_class' ")){ $message .= LAN_CREATED. " ($name)
"; }else{ $message .= LAN_CREATED_FAILED. " ($name)
"; } $count++; } if($message){ $ns -> tablerender(LAN_CREATED, $message); } } if (isset($_POST['inc'])) { $qs = explode(".", $_POST['inc']); $linkid = $qs[0]; $link_order = $qs[1]; $sql->db_Update("links", "link_order=link_order+1 WHERE link_order='".($link_order-1)."'"); $sql->db_Update("links", "link_order=link_order-1 WHERE link_id='".$linkid."'"); } if (isset($_POST['dec'])) { $qs = explode(".", $_POST['dec']); $linkid = $qs[0]; $link_order = $qs[1]; $sql->db_Update("links", "link_order=link_order-1 WHERE link_order='".($link_order+1)."'"); $sql->db_Update("links", "link_order=link_order+1 WHERE link_id='".$linkid."'"); } if (isset($_POST['update'])) { foreach ($_POST['link_order'] as $loid) { $tmp = explode(".", $loid); $sql->db_Update("links", "link_order=".$tmp[1]." WHERE link_id=".$tmp[0]); } foreach ($_POST['link_class'] as $lckey => $lcid) { $sql->db_Update("links", "link_class='".$lcid."' WHERE link_id=".$lckey); } $e107cache->clear("sitelinks"); $linkpost->show_message(LAN_UPDATED); } if (isset($_POST['updateoptions'])) { $pref['linkpage_screentip'] = $_POST['linkpage_screentip']; $pref['sitelinks_expandsub'] = $_POST['sitelinks_expandsub']; save_prefs(); $linkpost->show_message(LCLAN_1); } if ($delete == 'main') { if($sql->db_Select("links", "link_id, link_name, link_order", "link_id='".$del_id."'")){ $row = $sql->db_Fetch(); $msg = $linkpost->delete_link($row); if($msg){ $e107cache->clear("sitelinks"); $linkpost->show_message($msg); } } } if (isset($_POST['add_link'])) { $linkpost->submit_link($sub_action, $_POST['link_id']); unset($id); } $linkArray = $linkpost->getLinks(); if ($action == 'create') { $linkpost->create_link($sub_action, $id); } if (!e_QUERY || $action == 'main') { $linkpost->show_existing_items(); } if ($action == 'opt') { $linkpost->show_pref_options(); } if($action == "sublinks"){ $linkpost->show_sublink_generator(); } require_once('footer.php'); exit; // End --------------------------------------------------------------------------------------------------------------------------------------------------------------------- class links { var $link_total; function getLinks() { global $sql; if($this->link_total = $sql->db_Select("links", "*", "ORDER BY link_order, link_id ASC", "nowhere")) { while($row = $sql->db_Fetch()) { $ret[$row['link_parent']][] = $row; } } return $ret; } function linkName($text) { if(substr($text, 0, 8) == "submenu.") { $tmp = explode(".",$text); return $tmp[2]; } else { return $text; } } function dropdown($curval="", $id=0, $indent=0) { global $linkArray; if(0 == $indent) {$ret = "\n";} foreach($linkArray[$id] as $l) { $s = ($l['link_id'] == $curval ? " selected='selected' " : "" ); $ret .= "\n"; if(array_key_exists($l['link_id'], $linkArray)) { $ret .= $this->dropdown($curval, $l['link_id'], $indent+1); } } return $ret; } function existing($id=0, $level=0) { global $linkArray; $ret = ""; foreach($linkArray[$id] as $l) { $s = ($l['link_parent'] == $curval ? " selected='selected' " : "" ); $ret .= $this->display_row($l, $level); if(array_key_exists($l['link_id'], $linkArray)) { $ret .= $this->existing($l['link_id'], $level+1); } } return $ret; } function show_existing_items() { global $sql, $rs, $ns, $tp, $linkArray; if (count($linkArray)) { $text = $rs->form_open("post", e_SELF, "myform_{$link_id}", "", ""); $text .= "
"; $text .= $this->existing(0); $text .= ""; $text .= "
".LCLAN_89." ".LCLAN_90." ".LAN_OPTIONS." ".LCLAN_95." ".LCLAN_91." ".LAN_ORDER."
"; $text .= $rs->form_close(); } else { $text .= "
".LCLAN_61."
"; } $ns->tablerender(LCLAN_8, $text); } function display_row($row2, $indent = FALSE) { global $sql, $rs, $ns, $tp, $linkArray; extract($row2); if(strpos($link_name, "submenu.") !== FALSE || $link_parent !=0){ if(substr($link_name,0,8) == "submenu."){ $tmp = explode(".",$link_name); $sublinkname = $tmp[2]; }else{ $sublinkname = $link_name; } $link_name = $sublinkname; } if ($indent) { $subimage = ""; $subspacer = ($indent > 1) ? " style='padding-left: ".(($indent - 1) * 16)."px'" : ""; $subindent = "".$subimage.""; } $text .= ""; $text .= $link_button ? " ": ""; $text .= " ".$subindent."
".$link_name."
"; $text .= ""; $text .= "".LINKLAN_10." "; $text .= "".ADMIN_EDIT_ICON." "; $text .= "toJS(LCLAN_58." [ $link_name ]")."') \" />"; $text .= ""; $text .= "".r_userclass("link_class[".$link_id."]", $link_class, "off", "public,guest,nobody,member,admin,classes").""; $text .= ""; $text .= ""; $text .= ""; $text .= ""; $text .= ""; $text .= ""; $text .= ""; $text .= ""; return $text; } function show_message($message) { global $ns; $ns->tablerender(LAN_UPDATE, "
".$message."
"); } function create_link($sub_action, $id) { global $sql, $rs, $ns, $pst; $preset = $pst->read_preset("admin_links"); extract($preset); if ($sub_action == "edit" && !$_POST['submit']) { if ($sql->db_Select("links", "*", "link_id='$id' ")) { $row = $sql->db_Fetch(); extract($row); } } if("sub" == $sub_action) { $link_parent = $id; } if(strpos($link_name, "submenu.") !== FALSE){ $tmp = explode(".",$link_name); $link_name = $tmp[2]; } $handle = opendir(e_IMAGE."icons"); while ($file = readdir($handle)) { if ($file != "." && $file != ".." && $file != "/" && $file != "CVS") { $iconlist[] = $file; } } closedir($handle); $text = "
"; $text .= "
".LINKLAN_2.":
".LCLAN_15.":
".LCLAN_16.":
".LCLAN_17.":
".LCLAN_18.":
".LCLAN_19.":
".LCLAN_12.": ".LCLAN_96." {SITELINKS=flat:[rendertype number]}
".LCLAN_25.":
(".LCLAN_26.")
".r_userclass("link_class", $link_class, "off", "public,guest,nobody,member,admin,classes")."
"; if ($id && $sub_action == "edit") { $text .= "\n"; } else { $text .= ""; } $text .= "
"; $ns->tablerender(LCLAN_29, $text); } function submit_link($sub_action, $id) { global $sql, $e107cache, $tp; if(!is_object($tp)) { $tp=new e_parse; } $_POST['link_name'] = $tp->toDB($_POST['link_name']); if($_POST['link_parent']){ $tmp = explode("|",$_POST['link_parent']); $link_name = $tp->toDB(("submenu.".$tmp[1].".".$_POST['link_name'])); $parent_id = intval($tmp[0]); }else{ $parent_id = 0; $link_name = $_POST['link_name']; } $link_url = $tp->toDB($_POST['link_url']); $link_description = $tp->toDB($_POST['link_description']); $link_button = $tp->toDB($_POST['link_button']); $link_t = $sql->db_Count("links", "(*)"); if ($id) { $sql->db_Update("links", "link_parent='$parent_id', link_name='$link_name', link_url='$link_url', link_description='$link_description', link_button= '$link_button', link_category='".$_POST['linkrender']."', link_open='".$_POST['linkopentype']."', link_class='".$_POST['link_class']."' WHERE link_id='$id'"); //rename all sublinks if($sql->db_Select("links", "*", "link_parent='{$id}'")) { $childList = $sql->db_getList(); foreach($childList as $c) { $old = explode(".", $c['link_name'], 3); $newname = "submenu.".$_POST['link_name'].".".$old[2]; $sql->db_Update("links", "link_name = '{$newname}' WHERE link_id = '{$c['link_id']}'"); } } $e107cache->clear("sitelinks"); $this->show_message(LCLAN_3); } else { $sql->db_Insert("links", "0, '$link_name', '$link_url', '$link_description', '$link_button', ".$_POST['linkrender'].", ".($link_t+1).", ".$parent_id.", ".$_POST['linkopentype'].", ".$_POST['link_class']); $e107cache->clear("sitelinks"); $this->show_message(LCLAN_2); } } function show_pref_options() { global $pref, $ns; $text = "
\n
".LCLAN_78."
".LCLAN_79."
". ($pref['linkpage_screentip'] ? "" : "")."
".LCLAN_80."
".LCLAN_81."
". ($pref['sitelinks_expandsub'] ? "" : "")."
"; $ns->tablerender(LCLAN_88, $text); } function delete_link($linkInfo) { global $sql; if ($sql->db_Select("links", "link_id", "link_order > '{$linkInfo['link_order']}'")){ $linkList = $sql->db_getList(); foreach($linkList as $l){ $sql->db_Update("links", "link_order = link_order -1 WHERE link_id = '{$l['link_id']}'"); } } if ($sql->db_Delete("links", "link_id='".$linkInfo['link_id']."'")){ // Update ophaned sublinks. $sql->db_Update("links", "link_name = SUBSTRING_INDEX(link_name, '.', -1) , link_parent = '0', link_class='255' WHERE link_parent= '".$linkInfo['link_id']."'"); return LCLAN_53." #".$linkInfo['link_id']." ".LCLAN_54."
"; }else{ return DELETED_FAILED; } } // -------------------------- Sub links generator -------------> function show_sublink_generator() { global $ns,$sql; $sublinks = $this->sublink_list(); $text = "
\n
".LINKLAN_6."
\n
".LINKLAN_7."
\n
"; $ns->tablerender("Sublinks Generator", $text); } function sublink_list($name=""){ global $sql,$PLUGINS_DIRECTORY; $sublink_type['news']['title'] = LINKLAN_8; // "News Categories"; $sublink_type['news']['table'] = "news_category"; $sublink_type['news']['query'] = "category_id !='-2' ORDER BY category_name ASC"; $sublink_type['news']['url'] = "news.php?cat.#"; $sublink_type['news']['fieldid'] = "category_id"; $sublink_type['news']['fieldname'] = "category_name"; $sublink_type['news']['fieldicon'] = "category_icon"; $sublink_type['downloads']['title'] = LINKLAN_9; //"Download Categories"; $sublink_type['downloads']['table'] = "download_category"; $sublink_type['downloads']['query'] = "download_category_parent ='0' ORDER BY download_category_name ASC"; $sublink_type['downloads']['url'] = "download.php?list.#"; $sublink_type['downloads']['fieldid'] = "download_category_id"; $sublink_type['downloads']['fieldname'] = "download_category_name"; $sublink_type['downloads']['fieldicon'] = "download_category_icon"; if ($sql -> db_Select("plugin", "plugin_path", "plugin_installflag = '1'")) { while ($row = $sql -> db_Fetch()) { $sublink_plugs[] = $row['plugin_path']; } } foreach ($sublink_plugs as $plugin_id) { if (is_readable(e_PLUGIN.$plugin_id.'/e_linkgen.php')) { require_once(e_PLUGIN.$plugin_id.'/e_linkgen.php'); } } if($name){ return $sublink_type[$name]; } return $sublink_type; } } function links_adminmenu() { global $action; if ($action == "") { $action = "main"; } $var['main']['text'] = LCLAN_62; $var['main']['link'] = e_SELF; $var['create']['text'] = LCLAN_63; $var['create']['link'] = e_SELF."?create"; $var['opt']['text'] = LAN_OPTIONS; $var['opt']['link'] = e_SELF."?opt"; $var['sub']['text'] = LINKLAN_4; $var['sub']['link'] = e_SELF."?sublinks"; show_admin_menu(LCLAN_68, $action, $var); } ?>