<?
$page = "links.php";
include "manager_header.php";

if(isset($_POST['task'])) { $task = $_POST['task']; } else { $task = "main"; }

// SET VARS
$result = "";









if($task == "links_save") {

//PROCESS LINKS
$total_links = $_POST['total_links'];
$links_title = "";
$links_url = "";
for($l=0;$l<($total_links+1);$l++) {
$var1 = "link_title_$l";
$var2 = "link_url_$l";
$link_title = str_replace("'", "&#39;", str_replace("<!>", "", $_POST[$var1]));
$link_url = str_replace("'", "", str_replace("<!>", "", $_POST[$var2]));
if(str_replace(" ", "", $link_title) == "") { $link_title = $link_url; }
if(str_replace(" ", "", str_replace("http://", "", $link_url)) != "") {
 if($l != 0) { $links_title .= "<!>"; $links_url .= "<!>"; }
$links_title .= "$link_title";
$links_url .= "$link_url";
}}

mysql_query("UPDATE bhost_weblogs SET links_url='$links_url', links_title='$links_title' WHERE w_id='$weblog_info[w_id]'");
$weblog_info = mysql_fetch_assoc(mysql_query("SELECT * FROM bhost_weblogs WHERE w_id='$weblog_info[w_id]'"));
$result = "<img src='../images/saved_icon.gif' border='0' class='success'> <font class='success'>$links6</font><br><br>";
$task = "main";
}



















if($task == "main") {
echo $head;

echo "
$links1
";

// CHECK IF LINK TAGS ARE MISSING FROM TEMPLATE
// IF THEY ARE, SHOW THIS WARNING

if(stristr($weblog_info[template], "&lt;Link&gt;") === false) {
echo "
<br><br>
$links5
";
}

echo "
<br><br>
$result
<table cellpadding='3' cellspacing='0'>
<tr>
<td>$links2</td>
<td>$links3</td>
</tr>
<form action='links.php' name='linkform' method='POST'>
";
$total_links = 0;
$count = 0;
if($weblog_info[links_url] != "") {
$links_url = explode("<!>", trim($weblog_info[links_url]));
$links_title = explode("<!>", trim($weblog_info[links_title]));
for($l=0;$l<count($links_url);$l++) {
$count++;
echo "<tr><td style='padding-right: 4px;'><input type='text' class='text' name='link_title_$l' value='$links_title[$l]'></td><td><input type='text' class='text' name='link_url_$l' value='$links_url[$l]' size='45'></td></tr>";
$total_links++;
}
}
echo "
<tr><td style='padding-right: 4px;'><input type='text' class='text' name='link_title_$total_links' value=''></td><td NOWRAP><input type='text' class='text' name='link_url_$total_links' value='http://' size='45'> "; tip2("54", "55"); echo "</td></tr>
<tr><td colspan='2'>&nbsp;</td></tr>
<tr><td><input type='submit' class='button' value='$links4'></td></tr>
<input type='hidden' name='task' value='links_save'>
<input type='hidden' name='total_links' value='$total_links'>
</form>
</table>
";

echo $foot;
}
?>