<? include_once("../includes/main.inc.php");

$page_id = $_REQUEST['page_id'];
$country_id = '1';

if(is_post_back()) {

                    $qs= explode("-", $unique );
			        $qs1 =$qs[0];
					$qs2 =$qs[1]; 

	if($page_id!='') {		 

		$sql = "update `tbl_banner` set alt_tags='".addslashes($alt_tags)."' where id = $page_id ";
		db_query($sql);

		########### Update Image sv_image ################

		if($_FILES['slider']['name']!='')

		{

			if(strlen($sv_image) && file_exists(UP_FILES_FS1_PATH."/banner/thumb/".$sv_image)){

				@unlink(UP_FILES_FS1_PATH."/banner/thumb/".$sv_image);

			}

			$sv_image_1 = md5(uniqid(rand(), true)).'.'.file_ext($_FILES[slider]['name']);

			copy($_FILES['slider']['tmp_name'], UP_FILES_FS1_PATH."/banner/thumb/".$sv_image_1) or die("Image is not uploaded");

			copy($_FILES['slider']['tmp_name'], UP_FILES_FS1_PATH."/banner/original/".$sv_image_1) or die("Image is not uploaded");

			$n_width=120; // Fix the width of the thumb nail images

			$n_height=90; // Fix the height of the thumb nail imaage

			$tsrc=UP_FILES_FS1_PATH."/banner/thumb/".$sv_image_1;

			$add=UP_FILES_FS1_PATH."/banner/original/".$sv_image_1; // Path where thumb nail image will be stored

			//echo $tsrc;

			if (!($_FILES[slider][type] =="image/pjpeg" OR $_FILES[slider][type]=="image/jpeg" OR $_FILES[slider][type]=="image/png")){echo "Your uploaded file must be of JPG or GIF or PNG. Other file types are not allowed<BR>";

			exit;}

				///////// starting of JPG thumb nail creation//////////

			if($_FILES[slider][type]=="image/pjpeg" OR $_FILES[slider][type]=="image/jpeg")

			{

				$im=ImageCreateFromJPEG($add);

				$width=ImageSx($im); // Original picture width is stored

				$height=ImageSy($im); // Original picture height is stored

				$newimage=imagecreatetruecolor($n_width,$n_height);

				imageCopyResized($newimage,$im,0,0,0,0,$n_width,$n_height,$width,$height);

				ImageJpeg($newimage,$tsrc);

				chmod("$tsrc",0777);

			}

			else{

				$im=ImageCreateFromPNG($add);

				$width=ImageSx($im); // Original picture width is stored

				$height=ImageSy($im); // Original picture height is stored

				$newimage=imagecreatetruecolor($n_width,$n_height);

				imageCopyResized($newimage,$im,0,0,0,0,$n_width,$n_height,$width,$height);

				ImagePng($newimage,$tsrc);

				chmod("$tsrc",0777);

			}

			db_query("update tbl_banner set banner_img='".$sv_image_1."' where id = $page_id ");
		}
       
		set_session_msg("Banner Images updated successfully.");	
	} else{	

		########### Uploading Image Insert Bases ################
		if($_FILES['slider']['name']!='')

		{

			if(strlen($sv_image) && file_exists(UP_FILES_FS1_PATH."/banner/thumb/".$sv_image)){

			@unlink(UP_FILES_FS1_PATH."/banner/thumb/".$sv_image);

			}

			$sv_image_1 = md5(uniqid(rand(), true)).'.'.file_ext($_FILES[slider]['name']);

			copy($_FILES['slider']['tmp_name'], UP_FILES_FS1_PATH."/banner/thumb/".$sv_image_1) or die("Image is not uploaded");

			copy($_FILES['slider']['tmp_name'], UP_FILES_FS1_PATH."/banner/original/".$sv_image_1) or die("Image is not uploaded");

			$n_width=120; // Fix the width of the thumb nail images

			$n_height=90; // Fix the height of the thumb nail imaage

			$tsrc=UP_FILES_FS1_PATH."/banner/thumb/".$sv_image_1;

			$add=UP_FILES_FS1_PATH."/banner/original/".$sv_image_1; // Path where thumb nail image will be stored

			//echo $tsrc;

			if (!($_FILES[slider][type] =="image/pjpeg" OR $_FILES[slider][type]=="image/jpeg" OR $_FILES[slider][type]=="image/png")){echo "Your uploaded file must be of JPG or GIF or PNG. Other file types are not allowed<BR>";

			exit;}

			/// starting of JPG thumb nail creation///

			if($_FILES[slider][type]=="image/pjpeg" OR $_FILES[slider][type]=="image/jpeg")

			{

				$im=ImageCreateFromJPEG($add);

				$width=ImageSx($im); // Original picture width is stored

				$height=ImageSy($im); // Original picture height is stored

				$newimage=imagecreatetruecolor($n_width,$n_height);

				imageCopyResized($newimage,$im,0,0,0,0,$n_width,$n_height,$width,$height);

				ImageJpeg($newimage,$tsrc);

				chmod("$tsrc",0777);

			}

			else{

				$im=ImageCreateFromPNG($add);

				$width=ImageSx($im); // Original picture width is stored

				$height=ImageSy($im); // Original picture height is stored

				$newimage=imagecreatetruecolor($n_width,$n_height);

				imageCopyResized($newimage,$im,0,0,0,0,$n_width,$n_height,$width,$height);

				ImagePng($newimage,$tsrc);

				chmod("$tsrc",0777);

			}
		}
		

        $sql = "insert into `tbl_banner` set banner_img='".addslashes($sv_image_1)."', status='".addslashes($status)."', service_id='".addslashes($qs1)."', service_name='".addslashes($qs2)."', alt_tags='".addslashes($alt_tags)."'";
        db_query($sql);
        
        set_session_msg("New Banner added successfully.");

	}

	header("Location: banner.php?start=$start");
	exit;
}

$page_id = $_REQUEST['page_id'];

if($page_id!='') {
	$sql = "select * from `tbl_banner` where id = '$page_id'";
	$result = db_query($sql);
	if ($line_raw = mysql_fetch_array($result)) {

	@extract($line_raw);

	}
}
?>

<link href="styles.css" rel="stylesheet" type="text/css">

<? include("top.inc.php");?>

<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td id="pageHead"><div id="txtPageHead">
Add/Edit Banner Images.</div></td>
</tr>
</table>

<table width="80%" align="left">
<tr><td>

<form method="post" action="" enctype="multipart/form-data" name="form1" id="form1" onSubmit="return validate(this);">
<table width="80%" align="center" border=0 cellpadding="0"  cellspacing="0" class="text">

<tr>
<td  colspan="2"height="30"  align="right"><a href="banner.php?start=<?=$start?>" class="redcolor"><strong>Back To Banner List</strong></a></td>
</tr>    
<tr><td height="15"><div align="center"><span class="msg"><?=display_sess_msg();?></span></div><br /></td></tr>  

<?php  $pcqry = mysql_query("select country_id,country_name from `tbl_country` where parent_childs='0' ");	?>
<tr>
<td class="lables"><b>Parent Name</b></td>
<td class="feildstxt"><select name="parent_childs" id="parent_childs">
<option value="0" <?php if($parent_childs=='0'){ echo 'selected="selected"'; } ?>>Slect Parent Name</option>
<?php while($parentData = mysql_fetch_assoc($pcqry)){ ?>  
<option value="<?php echo $parentData['country_id']; ?>" <?php if($parentData['country_id']==$parent_childs){ echo 'selected="selected"'; } ?>><?php echo $parentData['country_name']; ?></option>      
<?php } ?>    
</select></td>
</tr>

<tr><td>&nbsp;</td></tr>

<tr>
<td class="lables"><b>Services ( Childs Name )</b></td>
<td class="feildstxt">
<select name="unique" id="unique" style="width:164px;">
<option value="">Select Services Name</option>    
</select>
</td>
</tr>

<tr><td>&nbsp;</td></tr>

<tr>
<td class="lables"><b>Status</b></td>
<td class="feildstxt"><select name="status" id="status">
<option value="1" <?php if($status=='1'){ echo 'selected="selected"'; } ?>>Active</option>
<option value="0" <?php if($status=='0'){ echo 'selected="selected"'; } ?>>InActive</option>          
</select></td>
</tr>

<tr><td>&nbsp;</td></tr>

<tr><td class="lables" colspan="2"><hr/></td> </tr>

<tr><td>&nbsp;</td></tr>
       
<tr>
<td class="lables"><b>Banner Image</b></td>
<td class="feildstxt"><input type="file" name="slider" id="slider"  /></td>
</tr>

<tr><td>&nbsp;</td></tr>

<tr>
<td class="lables"><b>Banner Alt Tags</b></td>
<td class="feildstxt">
<textarea style="width:200px;" name="alt_tags" id="alt_tags"  ><?=stripslashes($alt_tags)?></textarea>
</td>
</tr>  

<tr><td>&nbsp;</td></tr>

<tr>
<td align="left" class="lables">&nbsp;</td>
<td align="left" class="feildstxt"><input class="button" type="submit" name="submit" value="Add"></td>
</tr>

<tr><td height="25">&nbsp;</td></tr>
</table>
</form>
</td></tr></table>   
    
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$('#parent_childs').on('change',function(){
	var PID = $(this).val();
	/*alert(PID) */
	if(PID){
		$.ajax({
			type:'POST',
			url:'<?php echo SITE_WS_PATH; ?>/admin/ajaxData.php',
			data:'parent_childs='+PID,
			success:function(html){
				$('#unique').html(html);
			}
		}); 
	}else{
		$('#submenu').html('<option value="">Select State Services</option>');
	 
	}
});
});
</script> 
<? include("bottom.inc.php");?>