Location: PHPKode > scripts > Yet Another Link Directory > yald2/suggest.php
<?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  *
******************************************************************************/

session_start();

require('inc/config.php');
require('inc/captcha/php-captcha.inc.php');
require('inc/functions.php');
require('inc/smarty/Smarty.class.php');

mysql_connect($mysql['host'],$mysql['username'],$mysql['password']);
mysql_select_db($mysql['db']);

$settings = getSettings();

$template = new Smarty();
$template->template_dir = $settings['template_dir'].'/'.$settings['default_template'].'/';

$compile_dir = $settings['template_c_dir'].'/';
$template->compile_dir = $compile_dir;
$template->compile_id = $settings['default_template'];

$captcha = new PhpCaptcha(null);

if(isset($_SESSION['yald_admin_logged_in'])){
	$is_administrator = true;
} else {
	$is_administrator = false;
}

$yald_head = '';

if(isset($_REQUEST['category']) && categoryExists($_REQUEST['category']) && $_REQUEST['category'] != '1'){
	$category = $_REQUEST['category'];
	$yald_body = '';

	if(isset($_POST['submitted'])){
		if(empty($_POST['security'])){
			if($settings['use_captcha']){
				$error = 'you must enter the text in the image';
			}
		} elseif(!$captcha->Validate($_POST['security'])){
			if($settings['use_captcha']){
				$error = 'the text you entered for the security image was incorrect';
			}
		} elseif(empty($_POST['title'])){
			$error = 'no title entered';
		} elseif(empty($_POST['url'])) {
			$error = 'no URL entered';
		} elseif(empty($_POST['description'])) {
			$error = 'no description entered';
		} elseif(empty($_POST['yourname'])){
			$error = 'you did not enter your name';
		} elseif(empty($_POST['youremail'])){
			$error = 'you did not enter your email';
		} elseif(linkUrlExists($_POST['url'])){
			$error = 'the URL entered already exists';
		} elseif(strlen($_POST['url'])>$settings['max_url_length']){
			$error = 'the URL you entered was more than'.$settings['max_url_length'].' characters';
		} elseif(strlen($_POST['description'])>$settings['max_description_length']){
			$error = 'the description must be under '.$settings['max_description_length'].' characters';
		} elseif(strlen($_POST['title'])>$settings['max_title_length']){
			$error = 'the title must be under '.$settings['max_title_length'].' characters';
		} elseif(!validateEmail($_POST['youremail'])){
			$error = 'your email is invalid';
		} elseif($settings['check_links']==true && !urlExists($_POST['url'])){
			$error = 'could not open the URL entered';
		}

		if(isset($error)){
			$template->assign('error',$error);
			if(!empty($_POST['title'])){
				$sticky_form['title'] = 'value="'.gpcStripSlashes($_POST['title']).'" ';
			} else {
				$sticky_form['title'] = '';
			}
			if(!empty($_POST['url'])){
				$sticky_form['url'] = 'value="'.gpcStripSlashes($_POST['url']).'" ';
			} else {
				$sticky_form['url'] = '';
			}
			if(!empty($_POST['description'])){
				$sticky_form['description'] = gpcStripSlashes($_POST['description']);
			} else {
				$sticky_form['description'] = '';
			}
			if(!empty($_POST['yourname'])){
				$sticky_form['yourname'] = 'value="'.gpcStripSlashes($_POST['yourname']).'" ';
			} else {
				$sticky_form['yourname'] = '';
			}
			if(!empty($_POST['youremail'])){
				$sticky_form['youremail'] = 'value="'.gpcStripSlashes($_POST['youremail']).'" ';
			} else {
				$sticky_form['youremail'] = '';
			}

			//assign sticky form variables to template
			$template->assign('title_value',$sticky_form['title']);
			$template->assign('url_value',$sticky_form['url']);
			$template->assign('description_value',$sticky_form['description']);
			$template->assign('yourname_value',$sticky_form['yourname']);
			$template->assign('youremail_value',$sticky_form['youremail']);

		} else {
			$query = 'INSERT INTO `'.$settings['links_table'].'` (`category` , `url` , `name` , `description`, `submit_name` , `submit_email`,`approved`,`date`)
			VALUES ("'.mysql_safe($category).'","'.mysql_safe($_POST['url']).'","'.mysql_safe($_POST['title']).'","'.mysql_safe($_POST['description']).'","'.mysql_safe($_POST['yourname']).'","'.mysql_safe($_POST['youremail']).'","false","'.time().'")';
			mysql_query($query);
			logEvent('u_add_link','0',$_POST['url']);
			$template->assign('success',true);
		}
	}


	$nav[] = array('name'=>'Top','url'=>$settings['index_file']);

	$categorypath = categoryPath($category);
	
	$nav = array_merge($nav,$categorypath);

	$categoryname = categoryName($category);
	$page_title = $categoryname;

	/*switch($settings['url_type']){
		case '1':
			$url = $settings['index_file'].'?viewcat='.$category;
			break;
		case '2':
			$url = $settings['mod_rewrite_url'].$category.'_'.cleanUrl($categoryname);
	}*/
	$url = rewriteUrl($category,$categoryname,categoryCleanedPath($category));

	$nav[] = array('name'=>htmlentities($categoryname),'url'=>$url);
	$nav[] = array('name'=>'Suggest link','url'=>'');

	if(isset($_POST['category_selects'])){
		$categorymenu = categoryMenu('1',$category);
		$template->assign('category_selects',$categorymenu);
	}

} else {
	$nav[] = array('name'=>'Top','url'=>$settings['index_file']);
	$nav[] = array('name'=>'Suggest link','url'=>'');

	$page_title = 'Suggest link';

	$categorymenu = categoryMenu('1');
	$template->assign('category_selects',$categorymenu);
}

$template->assign('use_captcha',$settings['use_captcha']);

$template->assign('title',htmlentities($page_title));
$template->assign('sitetitle',htmlentities($settings['site_title']));
if(!empty($category)){
	$template->assign('category_name',htmlentities($categoryname));
	$template->assign('category',$category);
}
$template->assign('nav_trail',$nav);
$template->assign('template_path',$settings['template_dir'].'/'.$settings['default_template']);

$template->assign('phpself',$_SERVER['PHP_SELF']);
$template->assign('yald_head',$yald_head);
$template->assign('is_administrator',$is_administrator);
$template->assign('home_url',$settings['home_link']);
$template->assign('description_length',$settings['max_description_length']);
$template->assign('display_admin_link',$settings['display_admin_link']);

$template->display('suggest.html');
?>
Return current item: Yet Another Link Directory