<?php
  require_once("../../session_check.php");
  require_once("../../../classes/main_classes.php");

  //OBJECTS
  $retrieveObj=new RETRIEVE();
  $rowcountObj=new ROWCOUNT();

  $null_mg_id=0;

  //get last inserted item
  $get_mg=$retrieveObj->retriever("miscellaneous_goods","*","miscellaneous_goods.user_id",$user_id,"miscellaneous_goods.mg_id","DESC","fetch");

  if($get_mg!="1020"){
    //check if there if a miscellaneous good that has no image
    $check_mgs=$retrieveObj->retriever("miscellaneous_good_images","*","miscellaneous_good_images.mg_id='".$get_mg->mg_id."' and mg_image_type","primary_image","fetch");

    if($check_mgs=="1020"){
      $null_mg_id=$get_mg->mg_id;
    }else{
       $null_mg_id=0;
    }
  }
    
?>

<h4 class="page-title">
  <span class="la la-cubes"></span>
  Miscellaneous goods
</h4>
<p><a href="#" class="bold" onclick="miscellaneous_goods_view()">Miscellaneous goods</a> <span class="fas fa-angle-right"></span> Add Miscellaneous good</p>
<div class="content-wrapper ">
    <div class="row">
        <div class="col-md-12">
          <div class="mx-auto card p-2">
            <p class="text-center lead">Miscellaneous good : <i>Information</i></p>
            <form id="add_miscellaneous_good_form" class="row">
              <div class="col-md-6">
                <div class="my-2">
                  <input class="form-control" type="text" name="mg_name" placeholder="Miscellaneous good name">
                </div>
              </div>
              <div class="col-md-6">
                <div class="my-2">
                  <input class="form-control" type="text" name="price" placeholder="Price">
                </div>
              </div>

              <div class="col-md-12 pt-3">
                <label for="mg_description">Description :</label>
                <textarea class="form-control" name="mg_description" id="mg_description"></textarea>
              </div>
              <div class="col-md-12">
                <div class="my-2" id="add_miscellaneous_good_response">
                  
                </div>

                <div class="my-2">
                  <input type="hidden" name="add_miscellaneous_good_note">
                  <button type="submit" class="btn btn-primary btn-block enter-btn" onclick="add_miscellaneous_good_basic_info()">Next</button>
                </div>
              </div>
            </form>
          </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    var editor = new Simditor({
      textarea: $('#mg_description')
      //optional options
    });

    
    var null_mg_id=<?php echo $null_mg_id ?>

    $(document).ready(function() {
      if(null_mg_id==0){
        
      }else{
        $("#main_section").load("includes_/miscellaneous_goods/add_miscellaneous_good_main_image.php",{
          mg_id:null_mg_id
        });
      }
      
    })
</script>
