<?php
require_once(dirname(__FILE__).'/../../config.php');
require_once(DIR_SYSTEM.'/users/class.session.user.php');

$USER_ID	=	$_SESSION[USER_SESSION]['0']['user_id'];

$t	=	$prepare->sanitize($_GET['t'],'input');

if ( $t == 'adm' ) {
$id	=	$prepare->sanitize($_POST['id'],'input');

if ( empty ( $id ) ) {//*** START INSERT ***//
	//*** publishers_ad_units ***//
	$pau_id				=	$prepare->sanitize($_POST['id'],'input');
	$pau_channel_id		=	$prepare->sanitize($_POST['channel'],'input');
	$pau_user_id		=	$USER_ID;
	$pau_language_id	=	'';
	$pau_name			=	$prepare->sanitize($_POST['ad_title'],'input');
	$pau_size			=	$prepare->sanitize($_POST['ad_size'],'input');
	$pau_size_type		=	$prepare->sanitize($_POST['ad_type'],'input');
	$pau_adult			=	'';

	$insert = $db->NoQuery("INSERT INTO publishers_ad_units VALUES(NULL,?,?,?,?,?,?,?)","sssssss",$pau_channel_id,$pau_user_id,$pau_language_id,$pau_name,$pau_size,$pau_size_type,$pau_adult);

	//*** publishers_ad_units_design ***//
if ( $insert ) {
	$paud_ad_unit_id	=	$db->LastID();
	$paud_title			=	$prepare->sanitize($_POST['title_color'],'input');
	$paud_link			=	$prepare->sanitize($_POST['link_color'],'input');
	$paud_text			=	$prepare->sanitize($_POST['text_color'],'input');
	$paud_background	=	$prepare->sanitize($_POST['background_color'],'input');
	$paud_border		=	$prepare->sanitize($_POST['border_color'],'input');

	$db->NoQuery("INSERT INTO publishers_ad_units_design VALUES(?,?,?,?,?,?)","ssssss",$paud_ad_unit_id,$paud_title,$paud_link,$paud_text,$paud_background,$paud_border);


	//*** publishers_ad_units_statistics ***//
	$paus_ad_id			=	$paud_ad_unit_id;
	$paus_impressions	=	'0';
	$paus_clicks		=	'0';
	$paus_money			=	'0';

	$db->NoQuery("INSERT INTO publishers_ad_units_statistics VALUES(?,?,?,?)","ssss",$paus_ad_id,$paus_impressions,$paus_clicks,$paus_money);

	//*** publishers_profiles ***//
	$db->NoQuery("update publishers_profiles set pub_profile_ads=pub_profile_ads+1 where pub_profile_user_id=?","i",$USER_ID);

		echo '<div id="mode">1</div><div id="message">'. $LANG["WBS_PUB_AD_CREATED"] .'</div><div id="pub_ad_id">'. $paud_ad_unit_id .'</div>';
	} else {
		echo '<div id="mode">2</div><div id="message">'. $LANG["WBS_PUB_AD_ERROR"] .'</div><div id="pub_ad_id">'. $paud_ad_unit_id .'</div>';
	}

} else {//*** END INSERT START UPDATE ***// 


	//*** publishers_ad_units ***//
	$pau_id				=	$prepare->sanitize($_POST['id'],'input');
	$pau_channel_id		=	$prepare->sanitize($_POST['channel'],'input');
	$pau_user_id		=	$USER_ID;
	$pau_language_id	=	'';
	$pau_name			=	$prepare->sanitize($_POST['ad_title'],'input');
	$pau_size			=	$prepare->sanitize($_POST['ad_size'],'input');
	$pau_size_type		=	$prepare->sanitize($_POST['ad_type'],'input');
	$pau_adult			=	'';

	$update	=	$db->NoQuery("UPDATE publishers_ad_units SET pau_channel_id=?, pau_language_id=?, pau_name=?, pau_adult=? WHERE pau_id=? and pau_user_id=?","ssssss",$pau_channel_id,$pau_language_id,$pau_name,$pau_adult,$pau_id,$pau_user_id);


if ( $update ) {
	//*** publishers_ad_units_design ***//
	$paud_ad_unit_id	=	$pau_id;
	$paud_title			=	$prepare->sanitize($_POST['title_color'],'input');
	$paud_link			=	$prepare->sanitize($_POST['link_color'],'input');
	$paud_text			=	$prepare->sanitize($_POST['text_color'],'input');
	$paud_background	=	$prepare->sanitize($_POST['background_color'],'input');
	$paud_border		=	$prepare->sanitize($_POST['border_color'],'input');


	$update	=	$db->NoQuery("UPDATE publishers_ad_units_design SET paud_title=?, paud_link=?, paud_text=?, paud_background=?, paud_border=? WHERE paud_ad_unit_id=?","ssssss",$paud_title,$paud_link,$paud_text,$paud_background,$paud_border,$paud_ad_unit_id);

	echo '<div id="mode">3</div><div id="message">'.$LANG["WBS_PUB_AD_UPDATED"].'</div><div id="pub_ad_id">'. $paud_ad_unit_id .'</div>';

} else { //** ERROR **//

	echo '<div id="mode">2</div><div id="message">'.$LANG["WBS_PUB_AD_ERROR"].'</div>';

}

}





}

















?>