form = "core-links-edit-form";
$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');
require_once(e_HANDLER."message_handler.php");
require_once (e_HANDLER."ren_help.php");
$rs = new form();
$linkpost = new links();
$emessage = &eMessage::getInstance();
$action = '';
if(e_QUERY)
{
$tmp = explode('.', e_QUERY);
$action = $tmp[0];
$sub_action = varset($tmp[1], '');
$id = varset($tmp[2], '');
unset($tmp);
}
define("URL_SEPARATOR", 'X'); // Used in names of 'inc' and 'dec' fields
$incdec_action = '';
foreach(array_keys($_POST) as $k)
{
if(preg_match("#(.*?)_delete_(\d+)(.*)#", $k, $matches))
{
$delete = $matches[1];
$del_id = $matches[2];
} elseif(!$incdec_action && (preg_match("#^(inc|dec)".URL_SEPARATOR."(\d+)".URL_SEPARATOR."(\d+)_[x|y]#", $k, $matches)))
{
$incdec_action = $matches[1];
$linkid = intval($matches[2]);
$link_order = intval($matches[3]);
}
}
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 = $name; // eliminate old embedded hierarchy from names. (e.g. 'submenu.TopName.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})[!br!]";
$emessage->add(LAN_CREATED." ({$name})", E_MESSAGE_SUCCESS);
} else
{
$message .= LAN_CREATED_FAILED." ({$name})[!br!]";
$emessage->add(LAN_CREATED_FAILED." ({$name})", E_MESSAGE_ERROR);
}
$count++;
}
if($message)
{
sitelinks_adminlog('01', $message); // 'Sublinks generated'
}
}
if($incdec_action == 'inc')
{
$sql->db_Update("links", "link_order=link_order+1 WHERE link_order='".intval($link_order - 1)."'");
$sql->db_Update("links", "link_order=link_order-1 WHERE link_id='".intval($linkid)."'");
sitelinks_adminlog('02', 'Id: '.$linkid);
}
elseif($incdec_action == 'dec')
{
$sql->db_Update("links", "link_order=link_order-1 WHERE link_order='".intval($link_order + 1)."'");
$sql->db_Update("links", "link_order=link_order+1 WHERE link_id='".intval($linkid)."'");
sitelinks_adminlog('03', 'Id: '.$linkid);
}
if(isset($_POST['update']))
{
foreach($_POST['link_order'] as $loid)
{
$tmp = explode(".", $loid);
$sql->db_Update("links", "link_order=".intval($tmp[1])." WHERE link_id=".intval($tmp[0]));
}
foreach($_POST['link_class'] as $lckey => $lcid)
{
$sql->db_Update("links", "link_class='".$lcid."' WHERE link_id=".intval($lckey));
}
$e107cache->clear("sitelinks");
$emessage->add(LAN_UPDATED, E_MESSAGE_SUCCESS);
sitelinks_adminlog('04', '');
}
if(isset($_POST['updateoptions']))
{
$changed = FALSE;
foreach(array('linkpage_screentip', 'sitelinks_expandsub') as $opt)
{
$temp = intval($_POST[$opt]);
if($temp != $pref[$opt])
{
$pref[$opt] = $temp;
$changed = TRUE;
}
}
if($changed)
{
save_prefs();
$e107cache->clear("sitelinks");
sitelinks_adminlog('05', $pref['linkpage_screentip'].','.$pref['sitelinks_expandsub']);
$emessage->add(LCLAN_1, E_MESSAGE_SUCCESS);
}
else
{
// Nothing changed
$emessage->add(LINKLAN_11);
}
}
if($delete == 'main')
{
if($sql->db_Select("links", "link_id, link_name, link_order, link_parent", "link_id=".intval($del_id)))
{
$row = $sql->db_Fetch();
$linkpost->delete_link($row); // Admin logging in class routine
}
}
if(isset($_POST['add_link']))
{
$linkpost->submit_link($sub_action, $_POST['link_id']);
unset($id);
}
$linkArray = $linkpost->getLinks();
switch ($action) {
case 'create':
$linkpost->create_link($sub_action, $id);
break;
case 'debug':
$linkpost->show_existing_items(TRUE);
break;
case 'opt':
$linkpost->show_pref_options();
break;
case 'sublinks':
$linkpost->show_sublink_generator();
break;
case 'savepreset':
case 'clr_preset':
default: //handles preset urls as well
$action = 'main';
$sub_action = $id = '';
$linkpost->show_existing_items();
break;
}
require_once ('footer.php');
exit();
// End ---------------------------------------------------------------------------------------------------------------------------------------------------------------------
class links
{
var $link_total;
var $aIdOptPrep, $aIdOptData, $aIdOptTest;
var $debug_dis = FALSE;
function getLinks()
{
global $sql;
if($this->link_total = $sql->db_Select("links", "*", "ORDER BY link_category,link_order, link_id ASC", "nowhere"))
{
while($row = $sql->db_Fetch())
{
$ret[$row['link_parent']][] = $row;
}
}
return $ret;
}
function linkName($text)
{
// This function is ONLY needed for link databases that have been upgraded from
// before 0.7+ -- all new link collections make use of link_parent instead
// of hierarchy embedded in the link_name. (Unfortunately, the upgraded
// data still includes embedded coding.)
if(substr($text, 0, 8) == "submenu.") // for backwards compatibility only.
{
$tmp = explode(".", $text);
switch(count($tmp))
{
case 3: // submenu.parent.node
$tmp = $tmp[2];
break;
case 5: // submenu.parent.midlev.child.node
$tmp = $tmp[4];
break;
case 2: // submenu.parent (invalid?)
default:
$parentLen = strlen($tmp[1]);
$tmp = substr($text, 8 + $parentLen + 1); // Skip submenu.parent.
}
return $tmp;
}
else
{
return $text;
}
}
function dropdown($curval = "", $lid = 0, $indent = 0)
{ // Drop-down list using on the parent_id. :)
global $linkArray, $id, $sub_action;
if(0 == $indent)
{
$ret = "\n";
}
foreach($linkArray[$lid] as $l)
{
$s = ($l['link_id'] == $curval ? " selected='selected' " : "");
$thename = $this->linkName($l['link_name']);
// prevent making self the parent.
if($l['link_id'] == $id)
{
$thename = "(".$thename.")";
}
if($sub_action == "sub")
{
$thelink = ($l['link_id'] != $lid) ? $l['link_id'] : $l['link_parent'];
}
else
{
$thelink = ($l['link_id'] != $id) ? $l['link_id'] : $l['link_parent'];
}
$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($dbg_display = FALSE)
{
global $sql, $rs, $e107, $tp, $linkArray, $emessage;
$this->debug_dis = $dbg_display;
if(count($linkArray))
{
$this->prepIdOpts(); // Prepare the options list for all links
$text = $rs->form_open("post", e_SELF, "myform_{$link_id}", "", "");
$text .= "
";
$text .= $rs->form_close();
}
else
{
$text .= "".LCLAN_61."
";
}
$e107->ns->tablerender(LCLAN_8, $emessage->render().$text);
}
function prepIdOpts()
{
for($a = 1; $a <= $this->link_total; $a++)
{
$sTxt = "".$a;
$this->aIdOptData[] = array('val' => '|||.'.$a, 'txt' => $sTxt); // Later, ||| becomes Id
$this->aIdOptTest[] = $sTxt;
}
$this->aIdOptPrep = $this->prepOpts($this->aIdOptData);
}
function display_row($row2, $indent = FALSE)
{
global $sql, $rs, $tp, $linkArray, $previous_cat;
extract($row2);
if($link_category > 1 && $link_category != $previous_cat)
{
$text .= "