<!-- Content Wrapper. Contains page content -->
  <div class="content-wrapper">
    <!-- Content Header (Page header) -->
   
    <!-- Main content -->
    <section class="content">
      <div class="row">
        <!-- left column -->
        
        <div class="col-md-12">
		
		  
          <!-- general form elements -->
          <div class="box box-primary">
		  
            <div class="box-header with-border">
              
			  <?php  if(!isset($update_rows)){ ?>
		<h3 class="box-title">Add New Deals </h3>
		  <?php }else{ ?>
		<h3 class="box-title">Edit Deals </h3>		  
      <?php } ?>
      </div>
      <!-- /.box-header -->
      <!-- form start -->
        <?php
        $mesg = $this->session->flashdata('success');
         if(isset($mesg)){  ?>
      <div class="alert alert-success">
        <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
        <?php echo $this->session->flashdata('success');?>
    </div>
		  <?php }
        $mesg2 = $this->session->flashdata('error');
         if(isset($mesg2)){  ?>
            <div class="alert alert-danger">
              <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
              <?php echo $this->session->flashdata('error');?>
          </div>
		  
          <?php } if(!isset($detail_rows)){ ?>
 <form role="form" method="post" action="<?php if(!isset($update_rows)){ echo base_url('admin/Add_deal/add_new');}else{ echo base_url('admin/Add_deal/newupdate'); } ?>" enctype="multipart/form-data">
              <div class="box-body">
			  <div class="col-md-4">
                <div class="form-group">
                  <label for="name">Name <span class="text-danger">*</span></label>
                  <input type="text" required  name="name" class="form-control" id="name" placeholder="Name" value="<?php
                  echo (isset($update_rows))? $update_rows[0]->name : ''; ?>">
                </div>
                <input type="hidden" name="rowid" value="<?php echo (isset($update_rows))? $rowID : ''; ?>" >
                <input type="text" name="slug" value="<?php echo (isset($update_rows))? $update_rows[0]->slug : ''; ?>" >

                
                
			  </div><!-- /.col-md-6 -->
        <div class="col-md-4">
          <div class="form-group">
                  <label for="Ptitle">Meta Main category Title (MAX Char 70)<span class="text-danger">*</span></label>
                  <input type="text" maxlength="70" required  class="form-control" name="title" id="Ptitle"
                         placeholder="Title" value="<?php echo (isset($update_rows))? $update_rows[0]->title : '';?>">
                </div>
        </div>
        <div class="col-md-4">
          <div class="form-group">
                  <label for="pdisc">Meta Main Category Disc (MAX Char 222) <span class="text-danger">*</span></label>
                  <input type="text" maxlength="222" required  class="form-control" name="dis" id="pdisc"
                         placeholder="Discription" value="<?php echo (isset($update_rows))? $update_rows[0]->dis : '';?>">
                </div>
        </div>
        <div class="col-md-12">
          <div class="form-group">
                  <label for="pdisc">Select Photo<span class="text-danger">*</span></label>
                  <input type="file" class="form-control" name="photo[]" id="" placeholder="Discription" >
                </div>
            <?php if(isset($update_rows)){ ?>
                <img src="<?php echo base_url('uploads/').$update_rows[0]->photo; ?>" width="70" height="70" class="img-thumbnail" alt="photo" />
            <?php } ?>
        </div>
        <div class="col-md-3">
          <div class="form-group">
            <label for="">Select Product For Deal</label>
              <select name="product_slug" required class="form-control" id="pro_ch">
                <option value="">-- Select Product --</option>
                <?php 
                    foreach ($product as $pro) {
                      
                 ?>
                <option <?php if(isset($update_rows)){ if($update_rows[0]->product_slug == $pro->slug){ echo "selected";} }?> value="<?php echo $pro->slug; ?>"><?php echo $pro->name; ?></option>
              <?php } ?>
              </select>
              <input type="hidden" value="<?php echo (isset($update_rows))? $update_rows[0]->price : '';?>" name="price" id="price">
          </div>
        </div>
        <div class="col-md-3">
          <div class="form-group">
            <label for="">Quantity for product</label>
              <input type="number" id="num" required min="1" value="<?php echo (isset($update_rows))? $update_rows[0]->qnt : '';?>" name="qnt" class="form-control" placeholder="Choose Quantity">
          </div>
        </div>
        <div class="col-md-3">
          <div class="form-group">
            <label for="">Total Amount</label>
              <input type="text" id="amount" required value="<?php echo (isset($update_rows))? $update_rows[0]->total_amount
                  : '';?>" name="total_amount"  class="form-control" placeholder="Total Price Show Here Auto">
          </div>
        </div>
        <!-- <div class="col-md-2">
          <div class="form-group">
            <label for="">Add Discount</label>
              <input type="text"  class="form-control" placeholder="Add Discount ">
          </div>
        </div> -->
        <div class="col-md-3">
          <div class="form-group">
            <label for="">Select Free Product For Deal</label>
              <select name="free_product" required class="form-control" id="">
                <option value="">-- Select Product --</option>
                <?php 
                    foreach ($product as $pro) {
                      
                 ?>
                <option <?php if(isset($update_rows)){ if($update_rows[0]->product_slug == $pro->slug){ echo "selected";} }?> value="<?php echo $pro->slug; ?>"><?php echo $pro->name; ?></option>
              <?php } ?>
              </select>
          </div>
        </div>
        <div class="clearfix"></div>
				
            <div class="box-footer">
                <input type="submit" class="btn btn-primary" name="btn-upload" value="<?php echo (isset($update_rows))? 'Update' : 'Submit';?>" />
              </div>
              
        </div>
            </form>
          <!-- /.box -->
		  
		  <?php }else{ ?>
		  <!-- / View User's Details -->
		
              <div class="box-body">
			  <div class="col-md-6">
          <table class="table table-responsive borderless">
          <tr>
            <th>Deal Name :</th>
            <td><?php echo ucfirst($detail_rows[0]->name); ?></td>
          </tr>
          <tr>
            <th>Title :</th>
            <td><?php echo ucfirst($detail_rows[0]->title); ?></td>
          </tr>
          <tr>
            <th>Discription :</th>
            <td><?php echo ucfirst($detail_rows[0]->dis); ?></td>
          </tr>

          </table>
            
            <div class="box-footer">
                <a href="<?php echo base_url('admin/Add_deal/update/').$detail_rows[0]->slug; ?>" class="btn btn-md btn-primary"><i class="fa fa-pencil-square-o" aria-hidden="true"></i> Edit </a>
                <a href="<?php echo base_url('admin/Add_deal/view');?>" class="btn btn-md btn-default"> Cancel </a>
              </div>

			  </div><!-- /.col-md-6 -->
				 <div class="col-md-6">
                <img class="img-responsive"  src="<?php echo  base_url('uploads/thumbs/').$detail_rows[0]->photo; ?>"  alt="">    
         </div>
          </div>


			<?php } ?>
		  
		  <div class="clearfix"></div>
        </div>
        
      </div>
      <!-- /.row -->
    </section>
    <!-- /.content -->
  </div>
  <!-- /.content-wrapper -->

<script>
  $('#Ptitle').keypress(function(){
        var cn = $('#Ptitle').val().length;
        if(cn == 70){
          alert('Limite End stop');
        }
    });
    $('#pdisc').keypress(function(){
        var cn = $('#pdisc').val().length;
        if(cn == 222){
          alert('Limite End stop');
        }
    });

    $('#pro_ch').change(function () {
        var val = $('#pro_ch').val();
        if(val != ''){
          $.ajax({
            url:"<?php echo base_url('admin/Add_deal/price'); ?>",
            method:"POST",
            data:{val:val},
            success:function(data){
              $('#price').val(data);
            }
          })
        }
    });
    $('#num').change(function () {
        var val = $('#num').val();
        var price = $('#price').val();
        var total = val*price;
        $('#amount').val(total);
    });
</script>
