<?php
/******************************************************************************
* This file is part of Yet Another Link Directory. *
* *
* Yet Another Link Directory 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, or *
* (at your option) any later version. *
* *
* Yet Another Link Directory is distributed in the hope that it will be *
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with Yet Another Link Directory; if not, write to the Free Software *
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
******************************************************************************/
require('../inc/config.php');
require('../inc/functions.php');
mysql_connect($mysql['host'],$mysql['username'],$mysql['password']);
mysql_select_db($mysql['db']);
$settings = getSettings();
session_start();
if(!isset($_SESSION['yald_admin_logged_in'])){
header('Location: login.php');
exit;
}
$template = file_get_contents('template.html');
$yald_body = '';
$yald_head = null;
if(isset($_POST['submitted']) && !empty($_REQUEST['cat']) && $_REQUEST['cat']!='1') {
if(empty($_POST['url'])){
$error = 'Error: you must enter a URL';
} elseif(empty($_POST['title'])){
$error = 'Error: you must enter a link title';
} elseif(empty($_POST['description'])){
$error = 'Error: you must enter a description';
} elseif(linkUrlExists($_POST['url'],$_POST['cat'])){
$error = 'Error: that URL already exists in the selected category';
} elseif(strlen($_POST['description'])>$settings['max_description_length']){
$error = 'Error: description must be under '.$settings['max_description_length'].' characters';
} elseif(strlen($_POST['url'])>$settings['max_url_length']){
$error = 'Error: URL must be under '.$settings['max_url_length'].' characters.';
} elseif(strlen($_POST['title'])>$settings['max_title_length']){
$error = 'Error: title must be under '.$settings['max_title_length'].' characters.';
}
if(!isset($error)){
$query = 'INSERT INTO `'.$settings['links_table'].'` (`category` , `url` , `name` , `description`, `approved`,`date`)
VALUES ("'.mysql_safe($_POST['cat']).'","'.mysql_safe($_POST['url']).'","'.mysql_safe($_POST['title']).'","'.mysql_safe($_POST['description']).'","true","'.time().'")';
mysql_query($query);
logEvent('add_link','0',$_POST['url']);
$error = 'Link successfully added into "'.categoryName($_POST['cat']).'"';
$_REQUEST['cat'] = '';
} else {
$yald_body .= '<div align="center"><div class="errorbox"><b>'.$error.'</b></div></div>';
}
}
if(empty($_REQUEST['cat']) || $_REQUEST['cat']=='1' || !categoryExists($_REQUEST['cat'])){
if(isset($error)){
$yald_body .= '<div align="center"><div class="errorbox"><b>'.$error.'</b></div></div>';
}
$yald_body .= '<b>Select a category to place the link in:</b><br /><br />';
$yald_body .= displayTree('1','newlink').'<br /><br />';
}
if(!empty($_POST['url'])){
$sticky_url = 'value="'.gpcStripSlashes($_POST['url']).'" ';
} else {
$sticky_url = '';
}
if(!empty($_POST['title'])){
$sticky_title = 'value="'.gpcStripSlashes($_POST['title']).'" ';
} else {
$sticky_title = '';
}
if(!empty($_POST['description'])){
$sticky_desc = gpcStripSlashes($_POST['description']);
} else {
$sticky_desc = '';
}
if(!empty($_REQUEST['cat']) && $_REQUEST['cat']!='1' && categoryExists($_REQUEST['cat'])){
$categoryname = categoryName($_REQUEST['cat']);
$yald_body .= <<<EOF
<strong>Add a link in {$categoryname}:</strong><br /><br />
<form action="{$_SERVER['PHP_SELF']}" method="post">
<table width="100%" border="0">
<tr>
<td width="11%">URL:</td>
<td width="89%"><input type="text" name="url" {$sticky_url}/></td>
</tr>
<tr>
<td>Title:</td>
<td><input type="text" name="title" {$sticky_title}/></td>
</tr>
<tr>
<td>Description:</td>
<td><textarea name="description" cols="30" rows="4">{$sticky_desc}</textarea>Max 255 chars.</td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="Submit" value="Submit Resource" />
<input name="Reset" type="reset" id="Reset" value="Reset" /><input type="hidden" name="cat" value="{$_REQUEST['cat']}" /><input type="hidden" name="submitted" value="1" /></td>
</tr>
</table>
EOF;
}
$template = admin_output('add_link');
print $template;
?>