// Eval links
if (isset($_GET['managelinks'])) {
// Managing links
if ($_POST['newlink_name'] != "Link Display (Do not use plus signs (+))" && $_POST['newlink_name'] != "") {
$joined_nlink = $_POST['newlink_name']."+".$_POST['newlink_link'];
$cml_res = mysql_query("SELECT * FROM `prefs` WHERE `field` LIKE 'mainlink_top%'");
mysql_query("INSERT INTO `prefs` (`field`,`value`) VALUES ('mainlink_top{$num}','{$joined_nlink}')");
}
$stor_array_keys = array();
$stor_array_vals = array();
$stor_array_dels = array("dels");
foreach($_POST as $key => $value) { // sadly, this is the easiest way to do this.
$basetype = substr($key,13); // We're now left with the type, ie "name"
$base = substr($key,0,13); // returns something like "mainlink_top1"
if($basetype == "del") {
if ($value == "on") {
mysql_query("DELETE FROM `prefs` WHERE `field`='{$base}'");
array_push($stor_array_dels,$base);
}
}
else {
if($basetype == "link") { #VALS#
if(array_search($base,$stor_array_dels) == FALSE) { // check of this base is already in the deleted links
array_push($stor_array_vals,$value);
}
}
elseif($basetype == "name") { #KEYS#
if(array_search($base,$stor_array_dels) == FALSE) {
array_push($stor_array_keys,$value);
}
}
else {
}
}
}
$links = array_combine($stor_array_keys,$stor_array_vals); // Whoo, it's now like, even more fun.
mysql_query("DELETE FROM `prefs` WHERE `field` LIKE 'mainlink_top%'"); // We're replacing them all.
$numlinks = 1;
foreach ($links as $key => $value) {
$combined = $key."+".$value;
// Whee, back to original format, lets insert it so we can be done with this.
mysql_query("INSERT INTO `prefs` (`field`,`value`) VALUES ('mainlink_top{$numlinks}','{$combined}');") or die(mysql_error());
$numlinks++;
}
echo "Homepage main links have been successfully updated
";
}