<?php
$page = 'Products_management';
?>
<!DOCTYPE html>
<html lang="en">

<head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>Admin</title>

    <!-- Bootstrap Core CSS -->
    <link href="<?php echo base_url(); ?>assets/backend/css/bootstrap.min.css" rel="stylesheet">

    <!-- Custom CSS -->
    <link href="<?php echo base_url(); ?>assets/backend/css/sb-admin.css" rel="stylesheet">

    <!-- Morris Charts CSS -->
    <link href="<?php echo base_url(); ?>assets/backend/css/plugins/morris.css" rel="stylesheet">
    <link href="<?php echo base_url(); ?>assets/backend/font-awesome-4.1.0/css/font-awesome.min.css" rel="stylesheet" type="text/css">
    <link href="<?php echo base_url();?>assets/backend/editor/css/font-awesome.min.css" rel="stylesheet" type="text/css">
	<link href="<?php echo base_url();?>assets/backend/editor/css/froala_editor.min.css" rel="stylesheet" type="text/css">
	
	<script>
	function display(check,id)
	{
	
		var ch = "#check"+id;
		var file = "p_file_"+id;
		var text = "text_"+id;
		var image = "image_"+id;
		var pimage = "pimage_"+id;
		if($(ch).is(':checked'))
		{
			document.getElementById(image).style.display = "none";
			//var image = "eimage_"+id;
			document.getElementById(pimage).style.display = "block";
			document.getElementById(file).removeAttribute('disabled');
			//document.getElementById('pd_image').setAttribute('required','true');
		}
		else
		{
			//var image = "image_"+id;
			//document.getElementById('text').value = image;
			document.getElementById(eimage).style.display = "none";
			document.getElementById(image).style.display = "block";
			document.getElementById(file).setAttribute('disabled','true');
		}
	}
		function show_image(input,id)
	{
		var image = "#pimage_"+id;
		if(input.files && input.files[0])
		{
			var reader = new FileReader();
			reader.onload = function(e)
			{
				var oimg = document.createElement('img');
				$(image)
						.attr('src',e.target.result);
			};
			reader.readAsDataURL(input.files[0]);
		}
	}
	</script>
	
	
	
</head>

<body>
    <div id="wrapper">
        <!-- Navigation -->
        <?php
		include "include/header.php";
		?>     
        <div id="page-wrapper">
            <div class="container-fluid">
                <!-- Page Heading -->
                <div class="row">
                    <div class="col-lg-12">
                        <h1 class="page-header">
                           Update Product 
                            <small>Details</small>
                        </h1>
                        <ol class="breadcrumb">
                            <li>
                                <i class="fa fa-dashboard"></i>  <a href="<?php echo base_url();?>app/home">Dashboard</a>
                            </li>
                            <li class="active">
                                <i class="fa fa-file"></i> Update Product
                            </li>
                        </ol>                        
                    </div>
                </div>                
                <!-- /.row -->
                <?php
				foreach($productid as $row)
				$p_id = $row->p_id;
				?>
				<div class="row">
                    <form role="form" action="<?php echo base_url(); ?>update/up_product/<?php echo $p_id; ?>" method="post" enctype="multipart/form-data">
                    <div class="col-lg-6">                                              
                            <div class="form-group">							
                                <label>Product Category</label>
								<!--<input type="text" class="form-control" name="pc_name" value="<?php echo $c_row->pc_name;?>" readonly="">-->
                                <select class="form-control" name="pc_id">
									<?php foreach($products as $c_row): ?>
									<option <?php if($c_row->pc_id == $row->pc_id) {echo "selected='selected'";} ?> value="<?php echo $c_row->pc_id; ?>"><?php echo $c_row->pc_name; ?></option>
									<?php endforeach; ?>
								</select>
                            </div>
							<div class="form-group">
                                <label>Product Name</label>
                                <input class="form-control" name="p_name" value="<?php echo $row->p_name; ?>" readonly="">
                            </div>							                                                                    
                    </div>
					<div class="col-lg-6">
						<div class="form-group">
                                <label>Product Image</label><br>
                                <!--<input type="file" class="form-control" name="p_img" onchange="display_image(this,'#image');" required="">-->
								<img id="image_<?php echo $row->p_id;?>" src="<?php echo base_url();?>assets/uploads/gallery/<?php echo $row->p_name.'_'.$row->p_id.'.jpg'?>" alt="" style="border:1px solid #ccc; width:250px; height: 150px;">
								<img id="pimage_<?php echo $row->p_id;?>" src="<?php echo base_url();?>assets/backend/a-great-ship.jpg" alt="" style="display:none; height: 150px; width: 250px;">
                            </div>    
						 <div class="form-group">                            
                                <label>Uploaded Image</label><br>
                                <!--<img src="<?php echo base_url(); ?>assets/uploads/gallery/<?php echo $row->p_name.'_'.$row->p_id.'.jpg'; ?>" id="image" width="320" height="180">-->								
								<input type="file" class="form-control form-control" id="p_file_<?php echo $row->p_id;?>" name="p_file"
								onChange="show_image(this,'<?php echo $row->p_id;?>');" required disabled >
								<input type="checkbox" id="check<?php echo $row->p_id;?>" name="check" onClick="display(this,'<?php echo $row->p_id;?>')">Change Image								
                        </div>
					</div>
                    <div class="col-lg-12">							
                            <div class="form-group">                            
                                <label>Page Information</label>
                                <textarea class="form-control" id="edit" name="p_description"><?php echo $row->p_description;?></textarea>
                            </div>
                    <input type="submit" class="btn btn-primary" value="Update">
                    <a href="<?php echo base_url(); ?>app/product_manage" class="btn btn-default">Cancel</a>
                    </div>
                    </form>
                </div>
            </div>
            <!-- /.container-fluid -->

        </div>
        <!-- /#page-wrapper -->

    </div>
    <!-- /#wrapper -->

    <!-- jQuery Version 1.11.0 -->
    <script src="<?php echo base_url(); ?>assets/backend/js/jquery-1.11.0.js"></script>

    <!-- Bootstrap Core JavaScript -->
    <script src="<?php echo base_url(); ?>assets/backend/js/bootstrap.min.js"></script>

    <!-- Morris Charts JavaScript -->
    <script src="<?php echo base_url(); ?>assets/backend/js/plugins/morris/raphael.min.js"></script>
    <script src="<?php echo base_url(); ?>assets/backend/js/plugins/morris/morris.min.js"></script>
    <script src="<?php echo base_url(); ?>assets/backend/js/plugins/morris/morris-data.js"></script>
<script src="<?php echo base_url(); ?>assets/backend/js/plugins/morris/raphael.min.js"></script>
    <script src="<?php echo base_url(); ?>assets/backend/js/plugins/morris/morris.min.js"></script>
    <script src="<?php echo base_url(); ?>assets/backend/js/plugins/morris/morris-data.js"></script>
	<script src="<?php echo base_url(); ?>assets/backend/editor/js/libs/jquery-1.11.1.min.js"></script>
  <script src="<?php echo base_url(); ?>assets/backend/editor/js/froala_editor.min.js"></script>
  
  <script src="<?php echo base_url(); ?>assets/backend/editor/js/plugins/tables.min.js"></script>
  <script src="<?php echo base_url(); ?>assets/backend/editor/js/plugins/lists.min.js"></script>
  <script src="<?php echo base_url(); ?>assets/backend/editor/js/plugins/colors.min.js"></script>
  <script src="<?php echo base_url(); ?>assets/backend/editor/js/plugins/font_family.min.js"></script>
  <script src="<?php echo base_url(); ?>assets/backend/editor/js/plugins/font_size.min.js"></script>
  <script src="<?php echo base_url(); ?>assets/backend/editor/js/plugins/block_styles.min.js"></script>
  <script src="<?php echo base_url(); ?>assets/backend/editor/js/plugins/media_manager.min.js"></script>
  <script src="<?php echo base_url(); ?>assets/backend/editor/js/plugins/video.min.js"></script>

  <script>
    $(document).ready(function(){

    $('#edit').editable({inlineMode: false, height:200, imageUploadURL: '<?php echo base_url(); ?>app/upload_image',  imageErrorCallback: function (data) {
    
    console.log(data);
}
});
  });
	
	  function display_image(input,image)
	{
		if(input.files && input.files[0])
		{
			//document.getElementById("d_image").style.display="block";
            var reader = new FileReader();
			reader.onload = function(e)
			{
				var oimg = document.createElement('img');
				$(image)
						.attr('src',e.target.result);
			};
			reader.readAsDataURL(input.files[0]);
		}
	}
  </script>
</body>

</html>
