<?php
/**
 * @package		Ad Platform
 * @author		Uta Marian - Alexandru ( -uMarian- )
 * @license		http://codecanyon.net/licenses
 * @link		http://www.uta-marian.com
 * @version		Version 1.0
 */
 
require_once(dirname(__FILE__).'/../../config.php');
$prepare = new prepare;

$lang_id = $prepare->sanitize($_POST['lang_id'],'input');
$plugin_id = $prepare->sanitize($_POST['plugin_id'],'input');
$info_id = $prepare->sanitize($_POST['info_id'],'input');
$group_id = $prepare->sanitize($_POST['group_id'],'input');
$permalink_type = $prepare->sanitize($_POST['permalink_type'],'input');

if ( empty ( $permalink_type ) or ( $permalink_type == 'PERMALINK_TYPE' ) ) {
	$permalink_type = '1';
}

$lang_details = $db->Query("SELECT `lang_directory`, `lang_file` FROM ".DB_PREFIX."language WHERE `lang_id` =? LIMIT 1","i",$lang_id);

//REMOVE COOKIE
setcookie(COOKIE_LANGUAGE_DIR,"", time()-3600*24*5);
setcookie(COOKIE_LANGUAGE_FILE,"", time()-3600*24*5);
//END REMOVE COOKIE
					
setcookie(COOKIE_LANGUAGE_DIR,$lang_details[0]['lang_directory'], time()+3600*24, '/', COOKIE_DOMAIN);
setcookie(COOKIE_LANGUAGE_FILE,$lang_details[0]['lang_file'], time()+3600*24, '/', COOKIE_DOMAIN);

if ( $prepare->is_natural_no_zero($plugin_id) != '1' or $prepare->is_natural_no_zero($info_id) != '1' ) {
	echo ('<div id="mode">2</div><div id="request"></div>');
		} else {

//search for link into the database
if ( $group_id == 0 ) {
$lnk_ext = $db->Query("SELECT `permalink_url` FROM ".DB_PREFIX."permalinks WHERE `permalink_plugin_id` =? and `permalink_link_parent_id`=? and `permalink_lang_id` =? and `permalink_type`= ? LIMIT 1","iiii",$plugin_id,$info_id,$lang_id,$permalink_type);
	echo ('<div id="mode">1</div><div id="request">'.$lnk_ext[0]['permalink_url'].'</div>');
		} else {
$lnk_ext = $db->Query("SELECT `permalink_url` FROM ".DB_PREFIX."permalinks WHERE `permalink_plugin_id` =? and `permalink_link_id`=? and `permalink_lang_id` =? and `permalink_type`= ? LIMIT 1","iiii",$plugin_id,$group_id,$lang_id,$permalink_type);
	echo ('<div id="mode">1</div><div id="request">'.$lnk_ext[0]['permalink_url'].'</div>');		
					}
}
?>