<?php
	$cat_id = $_GET['cat_id'];
	$pro_id = $_GET['pro_id'];
?>
<?php
function getExtension($str) {
        $i = strrpos($str, ".");
        if (!$i) {
            return "";
        }

        $l = strlen($str) - $i;
        $ext = substr($str, $i + 1, $l);
        return $ext;
    }
    $upload_dir = "../images/products/";    
    if (isset($_POST['btsave'])) {
        
        $catid 			= $_POST['category'];
        $pro_title  	= mysqli_real_escape_string($conn,$_POST['pro_title']);
        $pro_status  	= $_POST['pro_status'];
		$pro_condition  = mysqli_real_escape_string($conn,$_POST['pro_condition']);	
		$pro_price  	= mysqli_real_escape_string($conn,$_POST['pro_price']);
		$pro_net2G  	= mysqli_real_escape_string($conn,$_POST['pro_net2G']);
		$pro_net3G  	= mysqli_real_escape_string($conn,$_POST['pro_net3G']);
		$pro_net4G  	= mysqli_real_escape_string($conn,$_POST['pro_net4G']);
		$pro_warranty   = mysqli_real_escape_string($conn,$_POST['pro_warranty']);
		$pro_dis_type   = mysqli_real_escape_string($conn,$_POST['pro_dis_type']);
		$pro_size  		= mysqli_real_escape_string($conn,$_POST['pro_size']);
		$pro_alert_type = mysqli_real_escape_string($conn,$_POST['pro_alert_type']);
		$pro_wlan  		= mysqli_real_escape_string($conn,$_POST['pro_wlan']);
		$pro_camera  	= mysqli_real_escape_string($conn,$_POST['pro_camera']);
		$pro_camera_feature  = mysqli_real_escape_string($conn,$_POST['pro_camera_feature']);
		$pro_video  	= mysqli_real_escape_string($conn,$_POST['pro_video']);
		$pro_os  		= mysqli_real_escape_string($conn,$_POST['pro_os']);
		$pro_cpu  		= mysqli_real_escape_string($conn,$_POST['pro_cpu']);
		$pro_chipset  	= mysqli_real_escape_string($conn,$_POST['pro_chipset']);
		$pro_other  	= mysqli_real_escape_string($conn,$_POST['pro_other']);
		$pro_promotion  	= mysqli_real_escape_string($conn,$_POST['pro_promotion']);
		$date1 = date('Y/m/d h:i:s a', time());
		
        if (file_exists($_FILES['file']['tmp_name'])){
			$check=mysqli_query($conn,"SELECT * FROM tbl_product WHERE pro_id=$pro_id");
					$url_row=mysqli_fetch_array($check);
						{unlink("../images/products/".$url_row['pro_img']);}
				//===function random name
				$image = $_FILES['file']['name'];
				$tempext = getExtension($image);
				$extfile = mt_rand() . "." . $tempext;
				//===function random name
				move_uploaded_file($_FILES["file"]["tmp_name"], $upload_dir . $extfile);
				//echo "Uploaded File :" . $_FILES["myfile"]["name"];
				$url=$extfile;		
		}
//======end upload file
    if($_FILES['file']['tmp_name'] !=NULL){
    mysqli_query($conn,"SET NAMES utf8");
    mysqli_query($conn,"update tbl_product set cat_id=$catid,pro_title='$pro_title',pro_status=$pro_status,pro_condition='$pro_condition',pro_price=$pro_price,pro_img='$url',pro_net2G='$pro_net2G',pro_net3G='$pro_net3G',pro_net4G='$pro_net4G',pro_warranty='$pro_warranty',pro_dis_type='$pro_dis_type',pro_size='$pro_size',pro_alert_type='$pro_alert_type',pro_wlan='$pro_wlan',pro_camera='$pro_camera',pro_camera_feature='$pro_camera_feature',pro_video='$pro_video',pro_os='$pro_os',pro_cpu='$pro_cpu',pro_chipset='$pro_chipset',pro_other='$pro_other',pro_date='$date1',pro_memory='s',pro_promotion='$pro_promotion' where pro_id = $pro_id") or die(mysql_error());
	}else{
		mysqli_query($conn,"SET NAMES utf8");
	mysqli_query($conn,"update tbl_product set cat_id=$catid,pro_title='$pro_title',pro_status=$pro_status,pro_condition='$pro_condition',pro_price=$pro_price,pro_net2G='$pro_net2G',pro_net3G='$pro_net3G',pro_net4G='$pro_net4G',pro_warranty='$pro_warranty',pro_dis_type='$pro_dis_type',pro_size='$pro_size',pro_alert_type='$pro_alert_type',pro_wlan='$pro_wlan',pro_camera='$pro_camera',pro_camera_feature='$pro_camera_feature',pro_video='$pro_video',pro_os='$pro_os',pro_cpu='$pro_cpu',pro_chipset='$pro_chipset',pro_other='$pro_other',pro_date='$date1',pro_memory='s',pro_promotion='$pro_promotion' where pro_id = $pro_id") or die(mysql_error());
	}
    ?>
        <script type="text/javascript">
            window.location.href="?page=addnewaccessory&cat_id=4";
        </script>
        <?php
    }   
?> 
<script type="text/javascript">
$(document).ready(function() {
    $("#new, #price, #sim").keydown(function (e) {
        // Allow: backspace, delete, tab, escape, enter and .
        if ($.inArray(e.keyCode, [46, 8, 9, 27, 13, 110, 190]) !== -1 ||
             // Allow: Ctrl+A
            (e.keyCode == 65 && e.ctrlKey === true) || 
             // Allow: home, end, left, right, down, up
            (e.keyCode >= 35 && e.keyCode <= 40)) {
                 // let it happen, don't do anything
                 return;
        }
        // Ensure that it is a number and stop the keypress
        if ((e.shiftKey || (e.keyCode < 48 || e.keyCode > 57)) && (e.keyCode < 96 || e.keyCode > 105)) {
            e.preventDefault();
        }
    });
});
</script>
<div class="row">
    <div class="col-lg-12" style="margin-top:-41px;margin-bottom:-13px;">
        <h1 class="page-header" style="font-size:19px; color:#09F;"><i class="fa fa-user fa-fw"></i>&nbsp;Camera</h1>
    </div>
    <!-- /.col-lg-12 -->
</div>
<!-- Row -->
<div class="row">
    <div class="col-lg-12">
        <div class="panel panel-default" style="width:100%;">
            <div class="panel-body">
                <div class="row">
                    <form method="post" enctype="multipart/form-data">
                    	<?php
							mysqli_query($conn,'SET NAMES utf8');
							$sql_p=mysqli_query($conn,"SELECT * FROM tbl_product where pro_id = $pro_id"); 
							while($row5=mysqli_fetch_array($sql_p)){
						?>
                        <div class="col-lg-6" style="width:340px;margin-bottom:5px;">
                            <div class="form-group">
                                <label style="color:#3a3a3a;">Category</label>
                                <select class="form-control" name="category">
                                	<option value="">Category</option>
                                	<?php
										mysqli_query($conn,'SET NAMES utf8');
										$select2=mysqli_query($conn,"SELECT * FROM tbl_category where pr_id = $cat_id"); 
										while($row_p=mysqli_fetch_array($select2)){
											if($row_p['cat_id']== $row5['cat_id'])
														$select="selected";
													else
														$select="";
									?>
                                    <option value="<?php echo $row_p['cat_id'];?>" <?php echo $select;?>><?php echo $row_p['cat_title'];?></option>
                                    <?php } ?>
                                </select>
                            </div>
                            <div class="form-group">
                                <label style="color:#3a3a3a;"v>Name</label>
                                <input class="form-control" placeholder="Name" name="pro_title" value="<?php echo $row5['pro_title'];?>"/>
                            </div>
                            <div class="form-group">
                                <label>Status <b style="color:#F00;">(1 = New Arrival &nbsp;2 = Avaliable)</b></label>
                                <input id="new" class="form-control" placeholder="Status" name="pro_status" value="<?php echo $row5['pro_status'];?>"/>
                            </div>
                            <div class="form-group">
                                <label>Main Image</label>
                                <img src="../images/products/<?php echo $row5['pro_img'];?>" width="50" style="border:1px solid #F00; float:right; max-height:80px;"/><input type="file" name="file" />
                            </div>
                            <div class="form-group">
                                <label>For Brand</label>
                                <input class="form-control" placeholder="Condition" name="pro_condition" value="<?php echo $row5['pro_condition'];?>" />
                            </div>
                            <div class="form-group" style="margin-top:-4px;">
                                <label style="color:#3a3a3a;"v>Price</label>
                                <input id="price" class="form-control" placeholder="Price" name="pro_price" value="<?php echo $row5['pro_price'];?>" />   
                        	</div>
                            <div class="form-group">
                                <label>Model</label>
                                <input class="form-control" placeholder="Model" name="pro_net2G" value="<?php echo $row5['pro_net2G'];?>"/>
                            </div>
                            <div class="form-group">
                                <label>Promotion</label>
                                <input class="form-control" placeholder="Promotion" name="pro_promotion" value="<?php echo $row5['pro_promotion'];?>"/>
                            </div>
                            <div class="form-group" style="margin-top:-25px; min-width:308px;">
                                <label></label><br/>
                                <input type="submit" name="btsave" class="btn btn-success" value="&nbsp;Update&nbsp;" title="Update"/>
                                 <a href="?page=addnewaccessory&cat_id=4">
                            <input type="button" name="addnew" class="btn btn-primary" value="&nbsp;Back&nbsp;" title="Back"/>
                            </a>
                            </div>
                        </div>
                        <div class="col-lg-6" style="width:340px;">
                            <div class="form-group" style="margin-top:-4px;">
                                <label style="color:#3a3a3a;"v>Quantity</label>
                                <input class="form-control" placeholder="Quantity" name="pro_net3G" value="<?php echo $row5['pro_net3G'];?>"/>
                            </div> 
                            <div class="form-group" style="margin-top:-4px;">
                                <label style="color:#3a3a3a;"v>Material</label>
                                <input class="form-control" placeholder="Material" name="pro_net4G" value="<?php echo $row5['pro_net4G'];?>"/>
                            </div>
                            <div class="form-group" style="margin-top:-4px;">
                                <label style="color:#3a3a3a;"v>Color</label>
                                <input class="form-control" placeholder="Color" name="pro_warranty" value="<?php echo $row5['pro_warranty'];?>"/>
                            </div> 
                            <div class="form-group" style="margin-top:-4px;">
                                <label style="color:#3a3a3a;"v>Battery Type</label>
                                <input class="form-control" placeholder="Battery Type" name="pro_alert_type" value="<?php echo $row5['pro_alert_type'];?>"/>
                            </div> 
                            <div class="form-group" style="margin-top:-4px;">
                                <label style="color:#3a3a3a;"v>Voltage</label>
                                <input class="form-control" placeholder="Voltage" name="pro_wlan" value="<?php echo $row5['pro_wlan'];?>"/>
                            </div>
                            <div class="form-group" style="margin-top:-4px;">
                                <label style="color:#3a3a3a;"v>Capacity Range</label>
                                <input class="form-control" placeholder="Capacity Range" name="pro_camera" value="<?php echo $row5['pro_camera'];?>"/>
                            </div>
                              
                        </div>
                        <div class="col-lg-6" style="width:340px;">
                        	<div class="form-group" style="margin-top:-4px;">
                                <label style="color:#3a3a3a;"v>Nominal Capacity</label>
                                <input class="form-control" placeholder="Nominal Capacity" name="pro_camera_feature" value="<?php echo $row5['pro_camera_feature'];?>"/>
                            </div>
                            <div class="form-group" style="margin-top:-4px;">
                                <label style="color:#3a3a3a;"v>Battery Actual Capacity</label>
                                <input class="form-control" placeholder="Battery Actual Capacity" name="pro_video" value="<?php echo $row5['pro_video'];?>"/>
                            </div>
                            <div class="form-group" style="margin-top:-4px;">
                                <label style="color:#3a3a3a;"v>Input</label>
                                <input class="form-control" placeholder="Input" name="pro_os" value="<?php echo $row5['pro_os'];?>"/>
                            </div>
                            <div class="form-group" style="margin-top:-4px;">
                                <label style="color:#3a3a3a;"v>Output</label>
                                <input class="form-control" placeholder="Output" name="pro_cpu" value="<?php echo $row5['pro_cpu'];?>"/>
                            </div>
                            <div class="form-group" style="margin-top:-4px;">
                                <label style="color:#3a3a3a;"v>Charging Time</label>
                                <input class="form-control" placeholder="Charging Time" name="pro_chipset" value="<?php echo $row5['pro_chipset'];?>"/>
                            </div>
                            <div class="form-group" style="margin-top:-4px;">
                                <label style="color:#3a3a3a;"v>Compatible Type</label>
                                <input class="form-control" placeholder="Compatible Type" name="pro_size" value="<?php echo $row5['pro_size'];?>"/>
                            </div>
                        </div>
                        <div class="col-lg-6" style="width:680px; float:left">
                        	<div class="form-group" style="margin-top:10px;">
                                <label style="color:#3a3a3a;">Compatible Models</label>
                                <textarea class="form-control" rows="5" name="pro_dis_type" placeholder="Compatible Models"><?php echo $row5['pro_dis_type'];?></textarea>
                            </div>
                            <div class="form-group" style="margin-bottom:30px;">
                                <label style="color:#3a3a3a;">Other</label>
                                <textarea class="form-control" rows="5" name="pro_other" placeholder="Other"><?php echo $row5['pro_other'];?></textarea>
                            </div>
                            
                       </div>
                       <?php } ?> 
                    </form>
                </div>
            </div>
       </div>
    </div>
</div>
<?php
	include('accessory_data.php');
?>