<?php
	$cat_id = $_GET['cat_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_sim  		= $_POST['pro_sim'];
		$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_memory  	= mysqli_real_escape_string($conn,$_POST['pro_memory']);
		$pro_promotion  	= mysqli_real_escape_string($conn,$_POST['pro_promotion']);
		$date1 = date('Y/m/d h:i:s a', time());
        if (isset($_FILES["file"])) {
            if ($_FILES["file"]["error"] > 0) {
                echo "Error: " . $_FILES["file"]["error"] . "<br>";
            } else {
                //===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
    mysqli_query($conn,"SET NAMES utf8");
    mysqli_query($conn,"insert into tbl_product values('',$catid,'$pro_title',$pro_status,'$pro_condition',$pro_price,'$url','$pro_net2G','$pro_net3G','$pro_net4G',$pro_sim,'$pro_warranty','$pro_dis_type','$pro_size','$pro_alert_type','$pro_wlan','$pro_camera','$pro_camera_feature','$pro_video','$pro_os','$pro_cpu','$pro_chipset','$pro_other','$date1',0,1,'$pro_memory','$pro_promotion')") or die(mysql_error());
    ?>
        <script type="text/javascript">
            window.location.href="?page=addnewphone&cat_id=2";
        </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;Phone</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">
                        <div class="col-lg-6" style="width:340px;">
                            <div class="form-group">
                                <label style="color:#3a3a3a;">Category</label>
                                <select class="form-control" name="category" required>
                                	<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)){
									?>
                                    <option value="<?php echo $row_p['cat_id'];?>"><?php echo $row_p['cat_title'];?></option>
                                    <?php } ?>
                                </select>
                            </div>
                            <div class="form-group">
                                <label style="color:#3a3a3a;"v>Phone Name</label>
                                <input class="form-control" placeholder="Phone Name" name="pro_title" required/>
                            </div>
                            <div class="form-group">
                                <label>Phone Status <b style="color:#F00;">(1 = New Arrival &nbsp;2 = Avaliable)</b></label>
                                <input id="new" class="form-control" placeholder="Phone Status" name="pro_status" required />
                            </div>
                            <div class="form-group">
                                <label>Condition</label>
                                <input class="form-control" placeholder="Condition" name="pro_condition" required />
                            </div>
                        </div>
                        <div class="col-lg-6" style="width:340px;">
                            <div class="form-group">
                                <label>Main Image</label>
                                <input type="file" name="file" required />
                            </div>
                            <div class="form-group">
                                <label style="color:#3a3a3a;"v>Phone Price</label>
                                <input id="price" class="form-control" placeholder="Phone Price" name="pro_price" required/>
                            </div>
                            <div class="form-group">
                                <label style="color:#3a3a3a;"v>Phone Sim</label>
                                <input id="sim" class="form-control" placeholder="Phone Sim" name="pro_sim"/>
                            </div>
                            <div class="form-group">
                                <label style="color:#3a3a3a;"v>Phone Warranty</label>
                                <input class="form-control" placeholder="Phone Warranty" name="pro_warranty" />
                            </div> 
                        </div>
                        <div class="col-lg-6" style="width:340px;">
                            <div class="form-group">
                                <label style="color:#3a3a3a;"v>Phone OS</label>
                                <input class="form-control" placeholder="Phone OS" name="pro_os"/>
                            </div>
                            <div class="form-group">
                                <label style="color:#3a3a3a;"v>Phone CPU</label>
                                <input class="form-control" placeholder="Phone CPU" name="pro_cpu"/>
                            </div>
                            <div class="form-group">
                                <label style="color:#3a3a3a;"v>Phone Chipset</label>
                                <input class="form-control" placeholder="Phone Chipset" name="pro_chipset"/>
                            </div>
                            <div class="form-group">
                                <label style="color:#3a3a3a;"v>Alert Type</label>
                                <input class="form-control" placeholder="Alert Typee" name="pro_alert_type"/>
                            </div>
                             
                        </div>
                        <div class="col-lg-6" style="width:46%;padding-top:15px; margin-right:10px;">
                        	<div class="form-group">
                                <label style="color:#3a3a3a;">Memory Size</label>
                                <textarea class="form-control" rows="1" name="pro_memory" placeholder="Memory Size"></textarea>
                            </div>
                            <div class="form-group">
                                <label style="color:#3a3a3a;">Display Type</label>
                                <textarea class="form-control" rows="2" name="pro_dis_type" placeholder="Display Type"></textarea>
                            </div>
                            <div class="form-group">
                                <label style="color:#3a3a3a;">Screen Size</label>
                                <textarea class="form-control" rows="2" name="pro_size" placeholder="Screen Size"></textarea>
                            </div>
                            <div class="form-group">
                                <label style="color:#3a3a3a;">WLAN</label>
                                <textarea class="form-control" rows="3" name="pro_wlan" placeholder="WLAN"></textarea>
                            </div>
                            <div class="form-group">
                                <label style="color:#3a3a3a;">Video</label>
                                <textarea class="form-control" rows="3" name="pro_video" placeholder="Video"></textarea>
                            </div>
                            <div class="form-group">
                                <label style="color:#3a3a3a;">Other</label>
                                <textarea class="form-control" rows="3" name="pro_other" placeholder="Other"></textarea>
                            </div>
                         </div>
                         <div class="col-lg-6" style="width:46%; padding-top:15px; padding-bottom:15px;">
                        	<div class="form-group">
                                <label style="color:#3a3a3a;">Promotion</label>
                                <textarea class="form-control" rows="1" name="pro_promotion" placeholder="Promotion"></textarea>
                            </div>
                            <div class="form-group">
                                <label style="color:#3a3a3a;">2G Network</label>
                                <textarea class="form-control" rows="2" name="pro_net2G" placeholder="2G Network"></textarea>
                            </div>
                            <div class="form-group">
                                <label style="color:#3a3a3a;">3G Network</label>
                                <textarea class="form-control" rows="2" name="pro_net3G" placeholder="3G Network"></textarea>
                            </div>
                            <div class="form-group">
                                <label style="color:#3a3a3a;">4G Network</label>
                                <textarea class="form-control" rows="2" name="pro_net4G" placeholder="4G Network"></textarea>
                            </div>
                            <div class="form-group">
                                <label style="color:#3a3a3a;">Camera</label>
                                <textarea class="form-control" rows="3" name="pro_camera" placeholder="Camera"></textarea>
                            </div>
                            <div class="form-group">
                                <label style="color:#3a3a3a;">Camera Feature</label>
                                <textarea class="form-control" rows="3" name="pro_camera_feature" placeholder="Camera Feature"></textarea>
                            </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;Save&nbsp;" title="Save"/>
                                 <a href="?page=addnewphone&cat_id=2">
                            <input type="button" name="addnew" class="btn btn-primary" value="&nbsp;Back&nbsp;" title="Back"/>
                            </a>
                            </div>
                         </div>  
                    </form>
                </div>
            </div>
       </div>
    </div>
</div>
<?php
	include('phone_data.php');
?>