<?php
/************************************************************************/
/* Maximus CMS: Web Portal System                                       */
/* ==============================                                       */
/*                                                                      */
/* Copyright (c) 2002 - 2006                                            */
/* http://www.php-maximus.fr                                            */
/* dev@php-maximus.org                                                  */
/*                                                                      */
/* This program is free software. You can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 2 of the License.       */
/************************************************************************/
/* Based on PHP-NUKE: Web Portal System                                 */
/************************************************************************/

	$result = $db->sql_query("SELECT url from ".TABLE_LINKS_LINKS." where url='$url'");
	$numrows = $db->sql_numrows($result);
	if ($numrows>0) {
		incoh();
		menu(1);
		br('1');
		Max_OpenTable();
		echo "<center><b>"._LINKALREADYEXT."</b><br /><br />"
		.""._GOBACK."";
		Max_CloseTable();
		incof();
	} else {
		if(defined('USER_ALLOW')) {
			$user2 = base64_decode($user);
			$user2 = addslashes($user2);
			$cookie = explode(":", $user2);
			cookiedecode($user);
			$submitter = $cookie[1];
		}
		// Check if Title exist
		if ($title=="") {
			incoh();
			menu(1);
			br('1');
			Max_OpenTable();
			echo "<center><b>"._LINKNOTITLE."</b><br /><br />"
			.""._GOBACK."";
			Max_CloseTable();
			incof();
		}
		// Check if URL exist
		if ($url=="") {
			incoh();
			menu(1);
			br('1');
			Max_OpenTable();
			echo "<center><b>"._LINKNOURL."</b><br /><br />"
			.""._GOBACK."";
			Max_CloseTable();
			incof();
		}
		// Check if Description exist
		if ($description=="") {
			incoh();
			menu(1);
			br('1');
			Max_OpenTable();
			echo "<center><b>"._LINKNODESC."</b><br /><br />"
			.""._GOBACK."";
			Max_CloseTable();
			incof();
		}
		$cat = explode("-", $cat);
		if ($cat[1]=="") {
			$cat[1] = 0;
		}
		$title = stripslashes(check_html(FixQuotes($title, "nohtml")));
		$url = stripslashes(check_html($url, "nohtml"));
		$description = stripslashes(check_html(FixQuotes($description), "html"));
		$auth_name = stripslashes(check_html($auth_name, "nohtml"));
		$email = stripslashes(check_html($email, "nohtml"));
		$cat[0] = $db->XMFnum($cat[0]);
		$cat[1] = $db->XMFnum($cat[1]);
		$num_new = $db->sql_numrows($db->sql_query("SELECT * FROM ".TABLE_LINKS_NEWLINK." WHERE title='$title' OR url='$url' OR description='$description'"));
		if ($num_new == 0) {
			$db->sql_query("insert into ".TABLE_LINKS_NEWLINK." values (NULL, '$cat[0]', '$cat[1]', '".addslashes($title)."', '".addslashes($url)."', '".addslashes($description)."', '".addslashes($auth_name)."', '".addslashes($email)."', '".addslashes($submitter)."')");
		}
		incoh();
		menu(1);
		br('1');
		Max_OpenTable();
		echo "<center><b>"._LINKRECEIVED."</b><br />";
		if ($email != "") {
			echo _EMAILWHENADD;
		} else {
			echo _CHECKFORIT;
		}
		Max_CloseTable();
		incof();
	}
