<?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 ) ) {
			//*** publisher_channels ***//
			$pc_user_id	=	$USER_ID;
			$pc_title	=	$prepare->sanitize($_POST['title'],'input');
			$pc_details	=	$prepare->sanitize($_POST['description'],'input');
			$pc_domain	=	$prepare->sanitize($_POST['domain'],'input');


			$insert = $db->NoQuery("INSERT INTO publisher_channels VALUES(NULL,?,?,?,?)","ssss",$pc_user_id,$pc_title,$pc_details,$pc_domain);
			if ( $insert ) {


			//*** publisher_channels_statistics ***//
			$pcs_channel_id		=	$db->LastID();
			$pcs_impressions	=	'0';
			$pcs_clicks			=	'0';
			$pcs_money			=	'0';

			$db->NoQuery("INSERT INTO publisher_channels_statistics VALUES(?,?,?,?)","ssss",$pcs_channel_id,$pcs_impressions,$pcs_clicks,$pcs_money);

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

				echo '<div id="mode">1</div><div id="message">'.$LANG["WBS_PUB_CHANNEL_CREATED"].'</div>';
			} else {
				echo '<div id="mode">2</div><div id="message">'.$LANG["WBS_PUB_CHANNEL_ERROR"].'</div>';
			}
		} else {
			$pc_id			=	$prepare->sanitize($_POST['id'],'input');
			$pc_user_id		=	$USER_ID;
			$pc_title		=	$prepare->sanitize($_POST['title'],'input');
			$pc_details		=	$prepare->sanitize($_POST['description'],'input');
			$pc_domain		=	$prepare->sanitize($_POST['domain'],'input');

				$update	=	$db->NoQuery("UPDATE publisher_channels SET pc_title=?, pc_details=?, pc_domain=? WHERE pc_id=? and pc_user_id=?","sssss",$pc_title,$pc_details,$pc_domain,$pc_id,$pc_user_id);



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

















?>