error_reporting(E_ALL);
ini_set('display_errors', 1);
include_once('./includes/config.php');
include_once('./includes/functions.php');
// set trail
$trail = ' > Add Link';
$page = "Add link"; //title
include_once('./includes/header.php');
//Check if user is logged in - if not, display a friendly user message
if(!Authorize(0)) {
$message->Show($message->error['MSG']['LOGIN_REQUIRED'], $message->error['TITLE']['LOGIN_REQUIRED'], "error");
}
?>
if(isset($_POST['add_article']) && isset($_POST['title']) && isset($_POST['url']) && isset($_POST['spaw']) && isset($_POST['categories-edit'])) {
//Validate form
$error = ValidateForm($_POST['title'], $_POST['categories-edit'], $_POST['spaw'], $_POST['url']);
if(!CheckMaxChars($_POST['spaw'], MAX_CHAR_LINK_DESCRIPTION)) {
$error['set'] = true;
$error['spaw'] = "Please enter less than ".MAX_CHAR_LINK_DESCRIPTION." characters";
}
//If no errors
if($error['set'] == false) {
unset($_SESSION['errors']);
unset($_SESSION['values']);
$author = $user->data['user_id'];
$approved = (CheckModPermissions($_POST['categories-edit'])) ? 1 : 0;
if($approved == 1) $order = FindLastLink($_POST['categories-edit']); //Set the order of the link to last when newly added
else $order = 0;
//Check if article is added to database correctly
if(!AddLink($_POST['title'], $_POST['url'], $_POST['spaw'], $approved, $_POST['categories-edit'], $order)) $message->Show("An error occured while trying to upload a link");
else {
if($approved == 1) $message->Show("Your link has been submited.");
else $message->Show("Your link has been submited. It will need to be approved by an administrator before it is viewable by others");
}
}
else {
$_SESSION['errors'] = $error;
$_SESSION['values'] = $_POST;
//Escape quotes for proper display
$_SESSION['values']['title'] = stripslashes(htmlspecialchars($_SESSION['values']['title'], ENT_QUOTES));
$_SESSION['values']['spaw'] = stripslashes($_SESSION['values']['spaw']);
$_SESSION['values']['url'] = stripslashes(htmlspecialchars($_SESSION['values']['url'], ENT_QUOTES));
if(isset($_SESSION['errors'])) echo "
Looks like you missed something out. Please look over your link and correct any errors
";
DisplayArticleForm();
}
} else {
DisplayArticleForm();
}
?>
include_once(ROOT_FILES . "right.php"); ?>
include_once('./includes/footer.php');
//Display a form to add or update an article
function DisplayArticleForm($error=false) {
if(!isset($_SESSION['values'])) $url_value = "http://";
else $url_value = $_SESSION['values']['url'];
?>