<?php
///////////////////////////////////////////////////////////////////////////////////////////
///Script PHP/MYSQL of management of classifieds ads developed by Script PAG
///Script PAG all rights reserved. Use under license. http://www.script-pag.com
///////////////////////////////////////////////////////////////////////////////////////////

############################################################

require_once __DIR__.'/includes/all_fns.php';

///////////////////////////////////
//Validation add ad
//////////////////////////////////

if(!empty($_POST['id_ad']) && $_POST['action'] == 1)
{
	$id_ad = (int) $_POST['id_ad'];

	if($id_ad > 0)
	{
		$cookie_name = 'cook'. $id_ad;
		setcookie($cookie_name, 'Script_PAG'. $id_ad, time()+(365 * 24 * 60 * 60), '/');
		$_COOKIE[$cookie_name] = 'Script_PAG'. $id_ad;
	}
}

///////////////////////////////////
//Validation delete ad
//////////////////////////////////

if(!empty($_POST['id_ad']) && $_POST['action'] == 2)
{
	$id_ad = (int) $_POST['id_ad'];
	
	if($id_ad > 0)
	{
		$cookie_name = 'cook'. $id_ad;
		setcookie($cookie_name, '', time() - 3600, '/');
		unset($_COOKIE[$cookie_name]);
	}
}

///////////////////////////////////
//Get number of ads
//////////////////////////////////

$_SESSION['nb_ad_selection'] = get_selected_number();
$total = $_SESSION['nb_ad_selection'];

$limit_page = 0;
$start_ads = 1;
$end_ads = $total;

///////////////////////////////////
//Inclusion des fonctions html
//////////////////////////////////


if($_SESSION['nb_ad_selection'] > 0)
$search_array = $_COOKIE;

if($_SESSION['nb_ad_selection'] < 1) {
	$search_array = array();
	$text = $language['page_no_selected'];
}

///////////////////////////////////
//Variables of search engine
//////////////////////////////////

$type = 0;
$type_search = 6;
$listing_search = 4;
$count_adv = 0;

///////////////////////////////////
//Variables of elements
//////////////////////////////////

$index = 0;
$account = 0;

///////////////////////////////////
//Title and meta 
//////////////////////////////////

$title = $language['title_page_selected'];
$description = $language['description_page_selected'];
$words = $language['keywords_page_selected'];
$title_listing_infos = $language['info_page_selected'];

///////////////////////////////////
//Display view
//////////////////////////////////

pool::execute('beforestart');

$view = array();
$view[] = 'template/tpl_search_results.php';

if(!isset($_POST['is_ajax'])) require_once __DIR__.'/template/tpl_layout.php';
else require_once __DIR__.'/template/tpl_search_results.php';