<?php
if(isset($_REQUEST['side_banners']) && is_array($_REQUEST['side_banners']) && count($_REQUEST['side_banners'])) {
	$is_admin = intval($_REQUEST['is_admin']) == 1; 
	$side_banners = $_REQUEST['side_banners'];
	$domain_id = intval($_REQUEST['domain_id']);
	$path = $protocol . "www.cypruswebsites.com/";
	$q = "select * from domaincategories where catdom_id='$domain_id' and parent_id='0';";
	$r = @mysql_query($q);
	if($r && mysql_num_rows($r) == 1) {
		$row = mysql_fetch_assoc($r);
		$domain_id = intval($row['catdom_id']);
		$domainname = str_replace('www.', '', $row['domainname']);
		$addonname = trim($row['addonname']);
		$main_server = intval($row['hosting_server']) == 0;
		
	}
	else {
		die();
		$domain_id = 0;
	}
	
	$host = $_SERVER['HTTP_HOST'];
	if(str_replace('www.', '', $host) !== $domainname) {
		$host = $host . "/$addonname";
		$click_count_path = $_SERVER['HTTP_HOST'] . "/ageneral/";
	}
	else {
		$click_count_path = $_SERVER['HTTP_HOST'] . "/";
		if(!$main_server) {
			$path = $protocol . $host . "/";
		}
	}
	
	$click_count_path = $protocol . $click_count_path;
	
	
	$host = $protocol . $host . "/";
	
	$banners = array();
	
	
	//print_r($side_banners);
	
	foreach ($side_banners as $i=>$bc) {
		$tmp = explode("_", $bc);
		$module_id = intval($tmp[0]);
		$banner_code = trim($tmp[1]);
		$location = trim($tmp[2]);
		
		if($module_id > 0 && $banner_code != "" && $domain_id > 0) {
		
			ob_start();
			
			$q = "select * from banner where module_id='$module_id';";
			$r = @mysql_query($q);
			if($r && mysql_num_rows($r) > 0) {
				while ($row = mysql_fetch_assoc($r)) {
					$module_id = intval($row['module_id']);
					
					$imagefile = $path ."images/banners/".$row['banner'];
					if (!$is_admin && $domain_id > 0){
						mysql_query("UPDATE banner SET views=views+1 WHERE module_id='{$row['module_id']}'") or die (mysql_error());
						//because of overload problem the following line is commeneted out
						count_views('banner_stats_views', 'banner_id', $row['module_id'], $domain_id, '', 'right');
					}
					
					if($row["file_type"]=="application/x-shockwave-flash"){
						?>
						<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="https://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="<?php echo $row["width"];?>" height="<?php echo $row["height"];?>" hspace="0" vspace="0">
						<param name="movie" value="<?php echo $imagefile;?>">
						<param name="quality" value="high">
						<param name="menu" value="false">
						<param name="wmode" value="transparent">
						<embed src="<?php echo $imagefile;?>" width="<?php echo $row["width"];?>" height="<?php echo $row["height"];?>" hspace="0" vspace="0" quality="high" pluginspage="https://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"></embed>
						</object>
						<?php 
					}
					else {
						if($row["url"]<>"" && $row['show_website'] == 1){
							?>
							<a href="<?php echo $click_count_path;?>click_count.php?type=banner&id=<?php echo $row['module_id'];?>&domain_id=<?php echo $domain_id;?>&location=right" class="click-count" target="_blank" title="<?php echo $row["alt_en"];?>">
							<img src="<?php echo "$imagefile";?>" border="0" alt="<?php echo stripslashes($row["alt_en"]);?>">
							</a>
							<?php 
						}
						else {
							?>
							<img src="<?php echo "$imagefile";?>" border="0" alt="<?php echo stripslashes($row["alt_en"]);?>">
							<?php 
						}
					}
					
					if ($is_admin){
						$after1month = date("Y-m-d", strtotime("+3 months", time()));
						$qlf = "select * from left_content where module_id='$module_id' and catdom_id='$domain_id' and `type`='banner' and location='$location' and module_active='yes';";
						//echo '<div>' . $qlf . '</div>';
						$rlf = @mysql_query($qlf);
						if($rlf && mysql_num_rows($rlf) > 0) {
							$rowlf = mysql_fetch_assoc($rlf);
							echo "<br/>";
							if($rowlf["active_to"]<>"0000-00-00"){
								if($after1month>$rowlf["active_to"]){
									echo "<font color=#EE0000>";
									if(date("Y-m-d")>$rowlf["active_to"]){
										echo "<strong>EXPIRED!!</strong><br/>";
									}
								}
								elseif($after3months>$rowlf["active_to"]){
									echo "<font color=#0000EE>";
								}
								else {
									echo "<font color=#000000>";
								}
								echo "<strong>$rowlf[active_to]</strong>";
								echo "<br/>";
								echo "Inv.No:";
								echo $rowlf["invoice_no"];
								echo "</font>";
							}
							echo '<br/><a href="'. $protocol . $_SERVER['HTTP_HOST'].'/admin/banner.php?module_id='.$rowlf['module_id'].'" target="_blank">Edit</a>';
						}
					}
				}
			}
			
			$ban_content = ob_get_contents();
			ob_end_clean();
			
			$banners [] = array("banner_code" => $bc, "banner_content" => $ban_content);
			
		}
		
	}
	
	echo array2json($banners);
	
}
?>