<?php

include("../include/config.php");

include("../include/functions.php"); 

include("../include/simpleimage.php");

  validate_admin();

if($_REQUEST['submitForm']=='yes'){ 

$zipcode=$_POST['zipcode'];
$zipcode=explode(',',$zipcode); // convert it into array
$zipcode=array_map('trim',$zipcode); // remove left and right spaces
$zipcode=preg_replace('/\s+/', '', $zipcode); //remove spaces between two character;
$zipcode=array_filter($zipcode); //remove empty array

$storeid=$_POST['storeid'];
$zone=$_POST['zone'];
$city=$_POST['city'];
$state=$_POST['state'];
$url=$_POST['url'];
$zonestatus=$_POST['zonestatus'];
$storestatus=$_POST['storestatus'];
$ziparea=$_POST['ziparea'];
$hike=$_POST['hike'];
$pickup=$_POST['pickup'];
$delivery=$_POST['delivery'];
$minimum=$_POST['minimum'];
$deliveryfee=$_POST['deliveryfee'];
$commission=$_POST['commission'];
$minimumorderfee=$_POST['minimumorderfee'];
$upsstatus=$_POST['upsstatus'];

$sectionname=$_POST['sectionname'];
$sectionname=implode(",",$sectionname);

$short_desc=$_POST['short_desc'];
$mini_desc=$_POST['mini_desc'];
$estd_delivery=$_POST['estd_delivery'];
$open_time=$_POST['open_time'];
$close_time=$_POST['close_time'];

$wholesalepartner=$_POST['wholesaledeliverypartner'];
$grocerypartner=$_POST['grocerydeliverypartner'];
$foodpartner=$_POST['fooddeliverypartner'];
$alcoholpartner=$_POST['alcoholdeliverypartner'];

$food_delivery_slots = ((isset($_POST['food_delivery_slots']) && $foodpartner == 'myvalue365') ? implode(',', $_POST['food_delivery_slots']) : '');

if($_REQUEST['id']!=''){
$obj->query("update tbl_store_zip set zip='$zipcode[0]',storeid='$storeid',zone='$zone',city='$city',state='$state',url='$url',zone_status='$zonestatus',store_status='$storestatus',zip_area='$ziparea',hike='$hike',pickup='$pickup',delivery='$delivery',minimum='$minimum',delivery_fee='$deliveryfee',commission='$commission',minimum_fee='$minimumorderfee',ups='$upsstatus',sectionid='$sectionname',short_description='$short_desc',mini_description='$mini_desc',estd_delivery='$estd_delivery',open_time='$open_time',close_time='$close_time',wholesale_delevery_partner='$wholesalepartner',grocery_delivery_partner='$grocerypartner',food_delivery_partner='$foodpartner',alocohol_delivery_partner ='$alcoholpartner', food_delivery_slots = '$food_delivery_slots' where id='".$_REQUEST['id']."'");
$_SESSION['sess_msg']='Record updated sucessfully';
}else{
for($x=0; $x < count($zipcode); $x++){
$obj->query("insert into tbl_store_zip set zip='$zipcode[$x]',storeid='$storeid',zone='$zone',city='$city',state='$state',url='$url',zone_status='$zonestatus',store_status='$storestatus',zip_area='$ziparea',hike='$hike',pickup='$pickup',delivery='$delivery',minimum='$minimum',delivery_fee='$deliveryfee',commission='$commission',minimum_fee='$minimumorderfee',ups='$upsstatus',sectionid='$sectionname',short_description='$short_desc',mini_description='$mini_desc',estd_delivery='$estd_delivery',open_time='$open_time',close_time='$close_time',wholesale_delevery_partner='$wholesalepartner',grocery_delivery_partner='$grocerypartner',food_delivery_partner='$foodpartner',alocohol_delivery_partner ='$alcoholpartner',food_delivery_slots ='$food_delivery_slots',status=1");
}
	$_SESSION['sess_msg']='Record added sucessfully';  
}
  	header("location:zip-list.php");
   	exit();
}

if($_REQUEST['id']!=''){
$sql=$obj->query("select *,s.storeid,z.zip,z.zip_area,z.city,z.status,z.sectionid from stores s inner join tbl_store_zip z on s.storeid=z.storeid where id=".$_REQUEST['id']);
$result=$obj->fetchNextObject($sql);
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<title><?php echo SITE_TITLE; ?></title>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<link href="css/admin.css" rel="stylesheet" type="text/css" />
</head>

<body>
<?php include("header.php") ?>
<br />
<div style="padding:1%">
<span style="float:left; padding-left:50px"><img src="images/arrow2.gif" width="21" height="21" hspace="10" align="absmiddle" /><strong style="font-size:14px; color:#555">Admin: Add Zipcode</strong> </span>
<span  style="float:right; padding-right:10px;">
<input type="button" name="add" value="View Zipcode List"  class="button" onclick="location.href='zip-list.php'" /></span>
</div><br />
<hr style="border:1px solid #ccc" />
<div style="background:#eee; padding:25px 30px">
<div style=" margin-left:50px; color:#555; font-size:18px;"><strong>Zipcode Details</strong></div><br /><br />
<form name="frm" method="POST" enctype="multipart/form-data" action="">
<input type="hidden" name="submitForm" value="yes" />
<input type="hidden" name="id" value="<?php echo $_REQUEST['id'];?>" />
<table width="100%" cellspacing="0" cellpadding="0">
<tr>
<td width="26%" align="right" class="paddBot11 paddRt14"><strong>Zip Code:</strong></td>
<td width="74%" align="left" class="paddBot11"><input name="zipcode" type="text" required size="36" value="<?php echo stripslashes($result->zip);?>" /> <?php if($_REQUEST['id']==''){ echo "* Add multiple zipcode with Comma and without any space eg. (60611,60612,60613)"; } ?></td>
</tr>
<tr>
<td align="right" class="paddBot11 paddRt14"><strong>Store Name:</strong></td>
<td align="left" class="paddBot11"><select name="storeid" required style="width:240px">
<option value="">Select Store...</option>
<?php $sql=$obj->query("select storename,storeid from stores where status=1 order by storename");
while($record=$obj->fetchNextObject($sql)){ ?>
<option value="<?php echo $record->storeid; ?>" <?php if($record->storeid==$result->storeid){ ?> selected="selected" <?php } ?>><?php echo ucwords(strtolower($record->storename)); ?></option>
<?php } ?>
</select></td>
</tr>
<tr>
<td align="right" class="paddBot11 paddRt14"><strong>Zone:</strong></td>
<td align="left" class="paddBot11"><input name="zone" type="text" required size="36" value="<?php if($result->zone){ echo stripslashes($result->zone); }else{ echo "2"; } ?>" /></td>
</tr>
<tr>

<td align="right" class="paddBot11 paddRt14"><strong>City:</strong></td>

<td align="left" class="paddBot11"><select name="city" required style="width:240px" required>

<option value="">Select City...</option>

<?php $sql=$obj->query("select city from tbl_city where status=1 order by city");

while($record=$obj->fetchNextObject($sql)){ ?>

<option value="<?php echo ucwords($record->city); ?>" <?php if(ucwords($record->city)==$result->city){ ?> selected="selected" <?php } ?>><?php echo ucwords(strtolower($record->city)); ?></option>

<?php } ?>

</select>

</tr>

<tr>

<td align="right" class="paddBot11 paddRt14"><strong>State:</strong></td>

<td align="left" class="paddBot11"><select name="state" required style="width:240px" required>

<option value="">Select State...</option>

<?php $sql=$obj->query("select distinct(state) from tbl_city where status=1 order by state");

while($record=$obj->fetchNextObject($sql)){ ?>

<option value="<?php echo strtoupper($record->state); ?>" <?php if(strtoupper($record->state)==strtoupper($result->state)){ ?> selected="selected" <?php } ?>><?php echo strtoupper($record->state); ?></option>

<?php } ?>

</select></td>

</tr>
<tr>
<td align="right" class="paddBot11 paddRt14"><strong>URL:</strong></td>
<td align="left" class="paddBot11"><input name="url" type="text" size="36" value="<?php echo stripslashes($result->url);?>" /></td>
</tr>
<tr>
<td align="right" class="paddBot11 paddRt14"><strong>Zone Status:</strong></td>
<td align="left" class="paddBot11"><input name="zonestatus" type="text" required size="36" value="<?php if($result->zone_status){ echo stripslashes($result->zone_status); }else{ echo "1"; } ?>" /></td>
</tr>
<tr>
<td align="right" class="paddBot11 paddRt14"><strong>Store Status:</strong></td>
<td align="left" class="paddBot11"><input name="storestatus" type="text" required size="36" value="<?php if($result->store_status){ echo stripslashes($result->store_status); }else{ echo "1"; } ?>" /></td>
</tr>
<tr>
<td align="right" class="paddBot11 paddRt14"><strong>Zip Area:</strong></td>
<td align="left" class="paddBot11"><select name="ziparea" required style="width:240px">
<option value="">Select Area...</option>
<option value="Local" <?php if($result->zip_area=='Local' || $result->zip_area=='local'){ ?> selected="selected"<?php } ?>>Local</option>
<option value="Suburb" <?php if($result->zip_area=='Subsurb' || $result->zip_area=='subsurb'){ ?> selected="selected"<?php } ?>>Suburb</option>
<option value="UPS" <?php if($result->zip_area=='UPS' || $result->zip_area=='ups'){ ?> selected="selected"<?php } ?>>UPS</option>
</select></td>
</tr>
<tr>
<td align="right" class="paddBot11 paddRt14"><strong>Price Hike ( % ):</strong></td>
<td align="left" class="paddBot11"><input name="hike" type="text" required size="36" value="<?php echo stripslashes($result->hike);?>" /></td>
</tr>
<tr>
<td align="right" class="paddBot11 paddRt14"><strong>Pickup:</strong></td>
<td align="left" class="paddBot11"><input name="pickup" type="text" required size="36" value="<?php if($result->pickup){ echo stripslashes($result->pickup); }else{ echo "1"; } ?>" /></td>
</tr>
<tr>
<td align="right" class="paddBot11 paddRt14"><strong>Delivery:</strong></td>
<td align="left" class="paddBot11"><input name="delivery" type="text" required size="36" value="<?php if($result->delivery){ echo stripslashes($result->delivery); }else{ echo "1"; } ?>" /></td>
</tr>
<tr>
<td align="right" class="paddBot11 paddRt14"><strong>Minimum:</strong></td>
<td align="left" class="paddBot11"><input name="minimum" type="text" required size="36" value="<?php if($result->minimum){ echo stripslashes($result->minimum); }else{ echo "10"; } ?>" /></td>
</tr>
<tr>
<td align="right" class="paddBot11 paddRt14"><strong>Delivery Fee:</strong></td>
<td align="left" class="paddBot11"><input name="deliveryfee" type="text" required size="36" value="<?php if($result->delivery_fee){ echo stripslashes($result->delivery_fee); }else{ echo "4.99"; } ?>" /></td>
</tr>
<tr>
<td align="right" class="paddBot11 paddRt14"><strong>Commission ( % ):</strong></td>
<td align="left" class="paddBot11"><input name="commission" type="text" required size="36" value="<?php echo stripslashes($result->commission);?>" /></td>
</tr>
<tr>
<td align="right" class="paddBot11 paddRt14"><strong>Minimum Order Fee:</strong></td>
<td align="left" class="paddBot11"><input name="minimumorderfee" type="text" required size="36" value="<?php if($result->minimum_fee){ echo stripslashes($result->minimum_fee); }else{ echo "2.99"; } ?>" /></td>
</tr>
<tr>
<td align="right" class="paddBot11 paddRt14"><strong>UPS Status:</strong></td>
<td align="left" class="paddBot11"><input name="upsstatus" type="text" required size="36" value="<?php if($result->ups){ echo stripslashes($result->ups); }else{ echo "0"; } ?>" /></td>
</tr>
<tr>
<td align="right" class="paddBot11 paddRt14"><strong> Section Name:</strong></td>
<td align="left" class="paddBot11">
<?php $sql=$obj->query("select id,section_name from tbl_section where status=1 order by section_name");
while($record=$obj->fetchNextObject($sql)){
	$sectionids=explode(',',$result->sectionid); 
?>	
<input type="checkbox" name="sectionname[]" value="<?php echo $record->id; ?>" <?php if(in_array($record->id, $sectionids)) { echo 'checked'; }?> /> <?php echo $record->section_name;?> 
<?php } ?>
</td>
</tr>
<tr>
<td align="right" class="paddBot11 paddRt14"><strong>Short Description:</strong></td>
<td align="left" class="paddBot11"><input name="short_desc" type="text" required size="36" value="<?php echo $result->short_description; ?>" /></td>
</tr>
<tr>
<td align="right" class="paddBot11 paddRt14"><strong>Mini Description:</strong></td>
<td align="left" class="paddBot11"><input name="mini_desc" type="text" required size="36" value="<?php echo $result->mini_description; ?>" /></td>
</tr>
<tr>
<td align="right" class="paddBot11 paddRt14"><strong>Estimated Delivery:</strong></td>
<td align="left" class="paddBot11"><input name="estd_delivery" type="text" required size="36" value="<?php echo $result->estd_delivery; ?>" /></td>
</tr>
<tr>
<td align="right" class="paddBot11 paddRt14"><strong>Opening Time:</strong></td>
<td align="left" class="paddBot11"><input name="open_time" type="text" required size="36" value="<?php echo $result->open_time; ?>" /> eg. 12:00:00</td>
</tr>
<tr>
<td align="right" class="paddBot11 paddRt14"><strong>Closing Time:</strong></td>
<td align="left" class="paddBot11"><input name="close_time" type="text" required size="36" value="<?php echo $result->close_time; ?>" /> eg. 12:00:00</td>
</tr>
<tr>
<td align="right" class="paddBot11 paddRt14"><strong>Wholesale Delivery Partner:</strong></td>
<td align="left" class="paddBot11"><select name="wholesaledeliverypartner" required style="width:240px">
<option value="">Select Delivery Partner...</option>
<option value="eatin" <?php if($result->wholesale_delevery_partner=='eatin'){ ?> selected="selected" <?php } ?>>Eatin</option>
<option value="myvalue365" <?php if($result->wholesale_delevery_partner=='myvalue365'){ ?> selected="selected" <?php } ?>>MyValue365</option>
<option value="oldjerusalem" <?php if($result->wholesale_delevery_partner=='oldjerusalem'){ ?> selected="selected" <?php } ?>>Old Jerusalem</option>
<option value="snap" <?php if($result->wholesale_delevery_partner=='snap'){ ?> selected="selected" <?php } ?>>Snap</option>
<option value="metrospeedy" <?php if($result->wholesale_delevery_partner=='metrospeedy'){ ?> selected="selected" <?php } ?>>Metro Speedy</option>

</select></td>
</tr>
<tr>
<td align="right" class="paddBot11 paddRt14"><strong>Grocery Delivery Partner:</strong></td>
<td align="left" class="paddBot11"><select name="grocerydeliverypartner" required style="width:240px">
<option value="">Select Delivery Partner...</option>
<option value="eatin" <?php if($result->grocery_delivery_partner=='eatin'){ ?> selected="selected" <?php } ?>>Eatin</option>
<option value="myvalue365" <?php if($result->grocery_delivery_partner=='myvalue365'){ ?> selected="selected" <?php } ?>>MyValue365</option>
<option value="oldjerusalem" <?php if($result->grocery_delivery_partner=='oldjerusalem'){ ?> selected="selected" <?php } ?>>Old Jerusalem</option>
<option value="snap" <?php if($result->grocery_delivery_partner=='snap'){ ?> selected="selected" <?php } ?>>Snap</option>
<option value="metrospeedy" <?php if($result->grocery_delivery_partner=='metrospeedy'){ ?> selected="selected" <?php } ?>>Metro Speedy</option>
</select></td>
</tr>
<tr>
<td align="right" class="paddBot11 paddRt14"><strong>Food Delivery Partner:</strong></td>
<td align="left" class="paddBot11"><select name="fooddeliverypartner" required style="width:240px" id="fooddeliverypartner">
<option value="">Select Delivery Partner...</option>
<option value="eatin" <?php if($result->food_delivery_partner=='eatin'){ ?> selected="selected" <?php } ?>>Eatin</option>
<option value="myvalue365" <?php if($result->food_delivery_partner=='myvalue365'){ ?> selected="selected" <?php } ?>>MyValue365</option>
<option value="oldjerusalem" <?php if($result->food_delivery_partner=='oldjerusalem'){ ?> selected="selected" <?php } ?>>Old Jerusalem</option>
<option value="snap" <?php if($result->food_delivery_partner=='snap'){ ?> selected="selected" <?php } ?>>Snap</option>
<option value="metrospeedy" <?php if($result->food_delivery_partner=='metrospeedy'){ ?> selected="selected" <?php } ?>>Metro Speedy</option>
</select></td>
</tr>

<?php 
    $display_slots = "display: none";
    if($result->food_delivery_partner=='myvalue365'){ 
      $display_slots = "display: table-cell";
		}	

$foodDeliverySlots = (!empty($result->food_delivery_slots) ? explode(',', $result->food_delivery_slots) : array());
		
$sqlSlot = $obj->query("select * from tbl_bookingslot");
?>
<tr>
	<td colspan=2 id="booking_slots" style="<?=$display_slots;?>" width="100%">
	<table width="100%">
<tr>
      <td align="right" class="paddBot11 paddRt14"><strong>Booking Slots:</strong></td>
      <td align="left" class="paddBot11">
<?php while($resultSlot = $obj->fetchNextObject($sqlSlot)){ ?>
	<input type="checkbox" name="food_delivery_slots[]" value="<?php echo $resultSlot->id; ?>" <?php if(in_array($resultSlot->id, $foodDeliverySlots)) { echo 'checked'; }?> /> <?php echo $resultSlot->bookingslot;?>  
<?php } ?>	
      </td>
</tr>
</table>
</td>
</tr>

<tr>
<td align="right" class="paddBot11 paddRt14"><strong>Alcohol Delivery Partner:</strong></td>
<td align="left" class="paddBot11"><select name="alcoholdeliverypartner" required style="width:240px">
<option value="">Select Delivery Partner...</option>
<option value="eatin" <?php if($result->alocohol_delivery_partner=='eatin'){ ?> selected="selected" <?php } ?>>Eatin</option>
<option value="myvalue365" <?php if($result->alocohol_delivery_partner=='myvalue365'){ ?> selected="selected" <?php } ?>>MyValue365</option>
<option value="oldjerusalem" <?php if($result->alocohol_delivery_partner=='oldjerusalem'){ ?> selected="selected" <?php } ?>>Old Jerusalem</option>
<option value="snap" <?php if($result->alocohol_delivery_partner=='snap'){ ?> selected="selected" <?php } ?>>Snap</option>
<option value="metrospeedy" <?php if($result->alocohol_delivery_partner=='metrospeedy'){ ?> selected="selected" <?php } ?>>Metro Speedy</option>
</select></td>
</tr>
<tr>
<td align="right" class="paddBot11 paddRt14">&nbsp;</td>
<td align="left" class="paddBot11">&nbsp;</td>
</tr>
<tr>
<td align="right" class="paddBot11 paddRt14"></td>
<td align="left" class="paddBot11"><input type="submit" name="submit" value="Submit"  class="submit" border="0"/></td>
</tr>								   
</table>
                                  
</form>
</div>

<script>
$(document).on("change","#fooddeliverypartner", function () {
	var cur_partner = $(this).val();
	if(cur_partner == 'myvalue365'){
		$("#booking_slots").show();
	}
	else{
		$("#booking_slots").hide();
	}
});
</script>

<?php include('footer.php'); ?>

</body>

</html>





