<?php

include('../config/constant.php');
include('../includes/header.php');
include('../includes/navbar.php');
require_once '../config/db.php';
require_once '../config/database.class.php';
require_once '../config/functions.php';
$d = new database($db_config);



	?> 



<div class="container-fluid">
    <div class="card shadow mb-4">
    <div class="card-header py-3">
      <h5 class="m-0 font weight-bold text-primary">Product</h5></div>
     
          </div>
    
 	<div class="main">
			<main class="content">
				<div class="container-fluid p-0">
				           <div class="modal fade" id="subcatModal" tabindex="1" role="dialog" aria-labelledby="examplemodalLabel" aria-hidden="true">
          <div class="modal-dialog" role="document">
            <div class="modal-content">
              <div class="modal-header">
                <h5 class="modal-title" id="exampleModalLabel">Sub Category</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                  
                  <!--<span aria-hidden="true">&times;</span>-->
                </button>
              </div>
              <div class="modal-body">
                <form action="productedit.php" id="addSubcatForm" method="POST" onclick="editProduct(id);"enctype="multipart/form-data">
                  <div class="modal-body">
                    <div class="form-group">

                      <input type="hidden" name="id" id="id" class="form-control" placeholder="Enter Id">
                    </div>
                      <div class="form-group">
                      <label>Category</label>
                      <select class="form-control" id="catid" name="catid">
                          <i class="align-middle" data-feather="chevrons-down"></i>  
                                    <option data-feather="chevrons-down" value="">Select Category </option>
                                    <?php 
                   require_once '../config/db.php';
                   require_once '../config/database.class.php';
                   require_once '../config/functions.php';
                   $d = new database($db_config);?>
                   
                       
                     <?php 
                               $query = "SELECT * FROM category ";
                       $executeQuery = $d->selectQueryInArray($query);
                              
                              if($executeQuery )  {
                                // code...
                             
                            foreach ($executeQuery as $row)
                              {
                              ?>

<option value="<?php echo $row['id'];?>"><?php echo $row["category"];?></option>
<?php
}}
?>
          
                                   
                                </select>
                    </div>
                     <div class="form-group">
                      <label>Subcategory</label>
                      <input type="text" name="subcategory" id="subcategory" class="form-control" placeholder="Enter Subcategory">
                    </div>
                     <div class="form-group">
                      <label>Product</label>
                      <input type="text" name="product" id="product" class="form-control" placeholder="Enter Product">
                    </div>
                     <div class="form-group">
                      <label>Description</label>
                      <input type="text" name="description" id="editor" class="form-control" placeholder="Enter Description">
                    </div>
                  
                  </div>
                  <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                    <button type="submit" name="registerbtn" class="registerbtn btn-primary btn" >Save</button>
                  </div>
                </div></form>
              </div>
            </div>
          </div>
 
					<div class="mb-3">
						<h1 class="h3 d-inline align-middle">Forms</h1>
					
					</div> <form id="updateform" action="../product/update_product.php" method="POST">
 
   <button type="submit" name="registerbtn" class="registerbtn btn-primary btn"  style="float: right" >Update</button>
          
          <!--<button type="button"  style="float: right" class="btn btn-success" onclick="editSubhome(id);">
        <i class="align-middle" data-feather="edit"></i>Edit</button>-->
         
        <br/>
        <br/>
        <br/>
					<div class="row">
					     
						<div class="col-12 col-lg-8">
						       <?php
                                                $id = $_GET['id'];
                                                 $scat_string = str_replace(".","","$id");
                                              
                                                $query = "SELECT * FROM product where id = '$scat_string' ";
                                                 $executeQuery = $d->selectQueryInArray($query);
           
                                                   if($executeQuery )  { 
                                                   foreach ($executeQuery as $row)
                                                      {
                                                ?>
							<div class="card">
								<div class="card-header">
									<h5 class="card-title mb-0">Product</h5>
								</div>
							<div class="card-body">
									<input type="text" class="form-control" placeholder="Product" name="product" value="<?php echo $row["product"];?>">
								</div>
										
									
							</div>
						
	                 	<div class="card ">
								<div class="card-header">
									<h5 class="card-title mb-0">Code</h5>
								</div>
							<div class="card-body">
									<input type="text" class="form-control" placeholder="code" name="code" value="<?php echo $row["code"];?>">
								</div>
										
									
							</div>
							
	
		
							<div class="card">
								<div class="card-header">
									<h5 class="card-title mb-0">Description</h5>
								</div>
				
           
							
								<div class="card-body">
									<textarea class="form-control" rows="11" placeholder="Description" id="description" name="description" ><?php echo $row["description"];?></textarea>
								</div>
							</div>
		               <div class="card">
								<div class="card-header">
									<h5 class="card-title mb-0">Details</h5>
								</div>
				
           
							
								<div class="card-body">
								    <textarea id="your_summernote" name="detail"><?php echo $row["detail"];?></textarea>
									
								</div>
							</div>
							     <div class="card">
								<div class="card-header">
									<h5 class="card-title mb-0">Why Choose Us</h5>
								</div>
				
           
							
								<div class="card-body">
								    <textarea id="choose" name="choose"><?php echo $row["choose"];?></textarea>
									
								</div>
							</div>
			
			     <div class="card">
								<div class="card-header">
									<h5 class="card-title mb-0">Delievery Option</h5>
								</div>
				
           
							
								<div class="card-body">
								    <textarea id="delievery" name="delievery"><?php echo $row["delievery"];?></textarea>
									
								</div>
							</div>
			
                       <?php }} ?>
							
						</div>

						<div class="col-12 col-lg-4">
						  
						<div class="card">
								<div class="card-header">
									<h5 class="card-title mb-0">ID</h5>
								</div>
								<div class="card-body">
								    	<input type="text" class="form-control" name="id" placeholder="id" value="<?php echo $row["id"];?>">
									
					
								</div>
							</div>

							<div class="card">
								<div class="card-header">
									<h5 class="card-title mb-0">Category</h5>
								</div>
								<div class="card-body">
								   



									<select class="form-control" name="catid" id="catid">
									   
									  
									     <?php 
                               $query = "SELECT * FROM category ";
                       $executeQuery = $d->selectQueryInArray($query);
                              
                              if($executeQuery )  {
                                // code...
                             
                            foreach ($executeQuery as $row)
                              {
                              ?>
        <option value="<?php echo $row['id'];?>"><?php echo $row["category"];?></option>
          <?php }} ?>
        </select>

									<!--<select multiple class="form-control">
          <option>One</option>
          <option>Two</option>
          <option>Three</option>
          <option>Four</option>
        </select>-->
								</div>
								
							</div>
							   <!-- <div class="form-group">
                      <label>Subcategory</label>
                      <select class="form-control" id="subcategory" name="subcategory">
                                    
                                   </select>
                                   </div>-->
                     
							
							  <?php
                                                $id = $_GET['id'];
                                                 $scat_string = str_replace(".","","$id");
                                              
                                                $query = "SELECT * FROM product where id = '$scat_string' ";
                                                 $executeQuery = $d->selectQueryInArray($query);
           
                                                   if($executeQuery )  { 
                                                   foreach ($executeQuery as $row)
                                                      {
                                                ?>
							<div class="card">
								<div class="card-header">
									<h5 class="card-title mb-0">Subcategory</h5>
								</div>
								<div class="card-body">
								   
								 	<input type="text" class="form-control" name="subcategory" placeholder="Subcategory" value="<?php echo $row["subcategory"];?>">
									
					
								</div>
							</div>
										<div class="card">
								<div class="card-header">
									<h5 class="card-title mb-0">Price</h5>
								</div>
								<div class="card-body">
								    	<input type="text" class="form-control" name="price" placeholder="Price" value="<?php echo $row["price"];?>">
									
					
								</div>
							</div>
									<div class="card">
								<div class="card-header">
									<h5 class="card-title mb-0">Stock</h5>
								</div>
								<div class="card-body">
								    	<input type="text" class="form-control" name="stock" placeholder="Stock" value="<?php echo $row["stock"];?>">
									
					
								</div>
							</div>
							<div class="card">
								<div class="card-header">
									<h5 class="card-title mb-0">Unit</h5>
								</div>
								<div class="card-body">
								   



									<select class="form-control" name="unit" id="unit">
		 <option value="<?php echo $row["unit"];?>"><?php echo $row["unit"];?></option>							 
        <option value="Each">Each</option>
        <option value="Piece">Piece</option>
         <option value="Pair">Pair</option>
          <option value="Set">Set</option>
          
        </select>

					
								</div>
								
							</div>
								<div class="card">
								
							
								 	<div class="card-header">
                        <label for="image">Select image:</label>
                        </div>
                        	<div class="card-body">
                        <img  style="width:250px;"src="<?php echo $row["image1"];?>"  id="image1" name="image1">
                        
                        <input type="file" id="image1" name="image1" >
                      
                
							</div>
							    
							
							</div>

						<!--	<div class="card">
								<div class="card-header">
									<h5 class="card-title mb-0">Disabled</h5>
								</div>
								
								<div class="card-body">
									<div class="mb-3">
										<label class="form-label">Disabled input</label>
										<input type="text" class="form-control" placeholder="Disabled input" disabled>
									</div>
									<div class="mb-3">
										<label class="form-label">Disabled select menu</label>
										<select class="form-control" disabled>
            <option>Disabled select</option>
          </select>
									</div>
									<label class="form-check">
          <input class="form-check-input" type="checkbox" value="" disabled>
          <span class="form-check-label">
            Can't check this
          </span>
        </label>
								</div>
							</div>-->
							<?php }} ?>
						</div>
						
					</div>
					</form>

				</div>
			</main>

						</div>
            
 <?php
          include('../includes/footer.php');
        
          
          ?>
          
      <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.form/4.3.0/jquery.form.min.js" ></script>
            <script>
        
$(document).ready(function() {
	$('#catid').on('change', function() {
			var catid = this.value;
			$.ajax({
				url: "get_scat.php",
				type: "POST",
				data: {
					catid: catid
				},
				cache: false,
				success: function(dataResult){
					$("#subcategory").html(dataResult);
				}
			});
		
		
	});
});
</script>
          <script type="text/javascript">
            $(document).ready(function(){
              getAllProduct();
            });

           

 $(document).ready(function() {
// alert(id);
$('#updateform').modal('show');
$('#id').val(id);

$.ajax({
  type: "POST",
  data: 'id=' + id,
  url: '../product/get_product_by_id.php',
  success: function (response) {
    console.log(response)
    var json = $.parseJSON(response);

    $('#id').val(json[0].id);
    $('#catid').val(json[0].catid);
    $('#subcategory').val(json[0].subcategory);
    $('#product').val(json[0].product);
     $('#code').val(json[0].code);
    $('#stock').val(json[0].stock);
    $('#finish').val(json[0].finish);
    $('#unit').val(json[0].unit);
    $('#price').val(json[0].price);
    $('#title').val(json[0].title);
     $('#detail').val(json[0].detail);
    $('#description').val(json[0].description);
      $('#choose').val(json[0].choose);
        $('#delievery').val(json[0].delievery);
    $('#image1').attr("src",'https://brasshardwareindia.com/admin/uploads/'+json[0].image1); 
    $('#image2').attr("src",'https://brasshardwareindia.com/admin/uploads/'+json[0].image2); 
     
  }
});
}






</script>
           
 <script>
        ClassicEditor
            .create( document.querySelector( '#editor' ) )
            .catch( error => {
                console.error( error );
            } );
    </script>
<script src="https://cdn.tiny.cloud/1/no-api-key/tinymce/6/tinymce.min.js" referrerpolicy="origin"></script>

<script>
  tinymce.init({
    selector: 'textarea#editor',
    skin: 'bootstrap',
    plugins: 'lists, link, image, media',
    toolbar: 'h1 h2 bold italic strikethrough blockquote bullist numlist backcolor | link image media | removeformat help',
    menubar: false,
    });
</script>
<script>
  tinymce.init({
  selector: 'textarea#editor',
  plugins: 'lists, link, image, media',
  toolbar: 'h1 h2 bold italic strikethrough blockquote bullist numlist backcolor | link image media | removeformat help',
  menubar: false,
  setup: (editor) => {
      // Apply the focus effect
      editor.on("init", () => {
      editor.getContainer().style.transition = "border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out";
        });
      editor.on("focus", () => { (editor.getContainer().style.boxShadow = "0 0 0 .2rem rgba(0, 123, 255, .25)"),
      (editor.getContainer().style.borderColor = "#80bdff");
        });
      editor.on("blur", () => {
      (editor.getContainer().style.boxShadow = ""),
      (editor.getContainer().style.borderColor = "");
        });
      },
    });
</script>
<script>
  tinymce.init({
  selector: 'textarea#editor',
  skin: 'bootstrap', //The TinyMCE Bootstrap skin
  plugins: 'lists, link, image, media',
[¡K]//Omitted lines are identical to step 2                       
  });
</script>
<script>  new FroalaEditor('textarea#froala-editor')</script>


<!-- Summernote JS - CDN Link -->
    <script src="https://cdn.jsdelivr.net/npm/summernote@0.8.18/dist/summernote-lite.min.js"></script>
    <script>
        $(document).ready(function() {
            $("#your_summernote").summernote();
            $('.dropdown-toggle').dropdown();
        });
    </script>
    <!-- //Summernote JS - CDN Link -->
    <!-- Summernote JS - CDN Link -->
    <script src="https://cdn.jsdelivr.net/npm/summernote@0.8.18/dist/summernote-lite.min.js"></script>
    <script>
        $(document).ready(function() {
            $("#description").summernote();
            $('.dropdown-toggle').dropdown();
        });
    </script>
      <script>
        $(document).ready(function() {
            $("#choose").summernote();
            $('.dropdown-toggle').dropdown();
        });
    </script>
     <script>
        $(document).ready(function() {
            $("#delievery").summernote();
            $('.dropdown-toggle').dropdown();
        });
    </script>
    <!-- //Summernote JS - CDN Link -->