<?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 ) ) {
			//*** advertisers_campaigns ***//
			$adv_campaign_user_id		=	$USER_ID;
			$adv_campaign_title			=	$prepare->sanitize($_POST['title'],'input');
			$adv_campaign_details		=	$prepare->sanitize($_POST['description'],'input');
			$adv_campaign_daily_budget	=	$prepare->sanitize($_POST['budget'],'input');
			$adv_campaign_daily_spent	=	'';
			$adv_campaign_status		=	$prepare->sanitize($_POST['status'],'input');




			$insert = $db->NoQuery("INSERT INTO advertisers_campaigns VALUES(NULL,?,?,?,?,?,?)","ssssss",$adv_campaign_user_id,$adv_campaign_title,$adv_campaign_details,$adv_campaign_daily_budget,$adv_campaign_daily_spent,$adv_campaign_status);
			if ( $insert ) {
				$adv_campaign_id	=	$db->LastID();


			//*** advertisers_campaigns_statistics ***//
			$acs_campaign_id	=	$adv_campaign_id;
			$acs_impressions	=	'0';
			$acs_clicks			=	'0';
			$acs_money_spent	=	'0';

			$db->NoQuery("INSERT INTO advertisers_campaigns_statistics VALUES(?,?,?,?)","ssss",$acs_campaign_id,$acs_impressions,$acs_clicks,$acs_money_spent);
			$db->NoQuery("update advertisers_profiles set adv_profile_campaigns=adv_profile_campaigns+1 where adv_profile_user_id=?","i",$USER_ID);
				echo '<div id="mode">1</div><div id="message">'.$LANG["WBS_CAMPAIGN_CREATED"].'</div>';
			} else {
				echo '<div id="mode">2</div><div id="message">'.$LANG["WBS_CAMPAIGN_ERROR"].'</div>';
			}
		} else {
			$adv_campaign_id			=	$prepare->sanitize($_POST['id'],'input');
			$adv_campaign_user_id		=	$USER_ID;
			$adv_campaign_title			=	$prepare->sanitize($_POST['title'],'input');
			$adv_campaign_details		=	$prepare->sanitize($_POST['description'],'input');
			$adv_campaign_daily_budget	=	$prepare->sanitize($_POST['budget'],'input');
			$adv_campaign_daily_spent	=	'';
			$adv_campaign_status		=	$prepare->sanitize($_POST['status'],'input');


				$update	=	$db->NoQuery("UPDATE advertisers_campaigns SET adv_campaign_title=?, adv_campaign_details=?, adv_campaign_daily_budget=?, adv_campaign_status=? WHERE adv_campaign_id=? and adv_campaign_user_id=?","ssssss",$adv_campaign_title,$adv_campaign_details,$adv_campaign_daily_budget,$adv_campaign_status,$adv_campaign_id,$adv_campaign_user_id);

				if ( $update ) {
					echo '<div id="mode">3</div><div id="message">'.$LANG["WBS_CAMPAIGN_UPDATED"].'</div>';
				} else {
					echo '<div id="mode">2</div><div id="message">'.$LANG["WBS_CAMPAIGN_ERROR"].'</div>';
				}
		}
}



if ( $t == 'campaign-status' ) {
	$mode	=	$prepare->sanitize($_POST['mode'],'input');

	if ( $mode == 'start' ) {
			$id	=	$prepare->sanitize($_POST['id'],'input');
			$db->NoQuery("update advertisers_campaigns set adv_campaign_status=? where adv_campaign_user_id=? and adv_campaign_id=?","iii",1,$USER_ID,$id);
	}

	if ( $mode == 'stop' ) {
			$id	=	$prepare->sanitize($_POST['id'],'input');
			$db->NoQuery("update advertisers_campaigns set adv_campaign_status=? where adv_campaign_user_id=? and adv_campaign_id=?","iii",3,$USER_ID,$id);
	}

	if ( $mode == 'pause' ) {
			$id	=	$prepare->sanitize($_POST['id'],'input');
			$db->NoQuery("update advertisers_campaigns set adv_campaign_status=? where adv_campaign_user_id=? and adv_campaign_id=?","iii",2,$USER_ID,$id);
	}


}
















?>