<script type="text/javascript">




	
function change_status(brand_id,status){

	$(".loading_image").show();
	$.ajax({
	  url: "brandlist.php",
	  data: 'act=change_status&brand_id='+brand_id+'&status='+status,
	  success: function(msg){
          $("#status_msg").show();
          $("#status_msg").html("<div class='alert alert-success'><button data-dismiss='alert' class='close' type='button'>×</button>Status updated successfully...</div>");
          $("#status_msg_td").html(msg);
          hideMessage();
          if(status==0){
              $("#td_status_"+brand_id).html("<a href=\"javascript:void(0)\" onclick=\"change_status('"+brand_id+"','1')\" ><span class=\"badge badge-danger\">Inactive</span></a>");
          }else{
              $("#td_status_"+brand_id).html("<a href=\"javascript:void(0)\" onclick=\"change_status('"+brand_id+"','0')\" ><span class=\"badge badge-success\">Active</span></a>");
          }
      }
	});
}
</script>

<?php
$filename=basename($_SERVER['SCRIPT_FILENAME']);
$adminlogObj = new admin_log();

if($filename == 'brandlist.php')
{
    $module_id = $adminlogObj->getModuleId($filename);
}
?>

<div class="breadcrumb">
    <h1>Brands</h1>
    <ul>
        <li><a href="<?php echo SITE_URL.ADMIN_DIR ?>">Dashboard</a></li>
        <li>Brand list</li>
        
    </ul>
</div>
<div class="separator-breadcrumb border-top"></div>
<form action="" method="post" id="addFrm" name="addFrm">
    <div class="row">
        <div class="col-lg-12 col-md-12">
            <div class="card mb-5">
                <div class="card-body">
                    <div class="row row-xs">
                        
                        <div class="col-md-2 form-group mb-3">
                            <label for="brand_name">Status <span class="asterisk">*</span></label>
                            <select id="brand_name"  class="form-control" multiple name="brand_name[]">
                               <?php 
                               foreach ($allbrands  as $brand){
                                ?>
                                    <option value="<?php echo $brand->brand_id;?>">
                                        <?php echo $brand->brandName;?>
                                    </option>
                              <?php }
                               ?>
                            </select>
                        </div>
                        <div class="col-md-2 mt-3 mt-md-0"  id="div_brand_point">
                            <label for="brand_point">Assign points</label>
                            <input type="text" class="form-control" name="brand_point" id="brand_point"  />
                        </div>
                        <div class="col-md-2 mt-3 mt-md-0">
                            <label for="">&nbsp;</label>
                            <button type="submit" name="submit" class="btn btn-primary btn-block">Assign</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</form>
<form action="" method="post" id="searchFrm" name="searchFrm">
    <div class="row">
        <div class="col-lg-12 col-md-12">
            <div class="card mb-5">
                <div class="card-body">
                    <div class="row row-xs">
                        
                        <div class="col-md-2 mt-3 mt-md-0"  id="div_brandName">
                            <label for="brandName">Brand Name</label>
                            <input type="text" class="form-control" name="brandName" id="brandName"  />
                        </div>

                        <div class="col-md-2 mt-3 mt-md-0"  id="div_xcarestatus">
                            <label for="xcarestatus">Status</label>
                            <select class="form-control" id="xcarestatus" name="xcarestatus">
                                <option value="">Select Status</option>
                                <option value="active">Active</option>
                                <option value="inactive">Inactive</option>
                            </select>
                        </div>
                        <div class="col-md-2 mt-3 mt-md-0"  id="div_oneDollarPoints">
                            <label for="oneDollarPoints">Status</label>
                            <select class="form-control" id="oneDollarPoints" name="oneDollarPoints">
                                <option value="">Select Points</option>
                                <?php 
                                 foreach ($allPoints as $key => $value) {
                                     echo "<option value='".$value->oneDollarPoints."'>".$value->oneDollarPoints."</option>";
                                 }
                                ?>
                            </select>
                        </div>
                        <div class="col-md-2 mt-3 mt-md-0">
                            <label for="">&nbsp;</label>
                            <button type="submit" name="submit" class="btn btn-primary btn-block">Search</button>
                        </div>
                        <div class="col-md-2 mt-3 mt-md-0">
                            <label for="">&nbsp;</label>
                            <button type="reset" name="reset" class="btn btn-primary btn-block" onClick="window.location.reload()">Reset</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</form>

<!-- <div class="row mb-4">
  <div class="col-md-6">
        <select id="act" name="act" class="form-control maction">
          <option value="">Multiple action</option>              
          <option value="activate_all">Activate selected</option>
          <option value="inactivate_all">De-activate selected</option>
          <option value="delete_all">Delete selected</option>-->
        <!-- </select>
        <button type="button" class="btn btn-primary m-1" onclick="return validate_all();">Apply</button>
  </div>
  <div class="col-md-6 pull-right">
      <div class="button-group">
         <a href="brandadd.php" class="btn btn-dark m-1"><i class="i-Add-User"></i> Add New</a>
      </div>    
  </div>  
</div> -->
<div class="widget-body">
    <div class="portlet-body">
                        
    <?php echo (isset($successMsg) && $successMsg!='') ? "<div class='alert alert-success'><button data-dismiss='alert' class='close' type='button'>×</button>".base64_decode($successMsg)."</div>" : '' ; ?>
    <?php echo (isset($failedMsg) && $failedMsg!='') ? "<div class='alert alert-danger'><button data-dismiss='alert' class='close' type='button'>×</button>".base64_decode($failedMsg)."</div>" : '' ?>
   
    <div id="status_msg" style="display: none;"><div class="alert alert-success"><button data-dismiss='alert' class='close' type='button'>×</button>&nbsp;</div></div>
    <div id="alert_msg" style="display: none;"><div class="alert alert-danger"><button data-dismiss='alert' class='close' type='button'>×</button>&nbsp;</div></div>

    </div>
</div>



<div class="row mb-4">
    <div class="col-md-12 mb-4">
        <div class="card text-left">

            <div class="card-body">
                <div class="table-responsive">
                  <form id="listFrm" name="listFrm" action="" method="post">       
                    <input type="hidden" id="action" name="action" value="">
                    <table id="list" class="display table table-striped table-bordered" style="width:100%">
                        <thead>
                            <tr>
                                <th>Name</th>
                                <th>Image</th>
                                <th>Status</th>
                                <th>XcareStatus</th>
                                <th>Points</th>
                                <th>Price</th>
                                <th>Dates</th>
                                <th>Status</th>
                            </tr>
                        </thead>
                    </table>
                  </form>
                </div>
            </div>
        </div>
    </div>
</div>
<script src="./assets/js/jquery.multiselect.js"></script>
<link rel="stylesheet" href="./assets/styles/css/jquery.multiselect.css">
<link href="./assets/styles/css/select2.min.css" rel="stylesheet" />
<script src="./assets/js/select2.min.js"></script>
<link rel="stylesheet" href="./assets/styles/css/jquery.toast.css">
<script src="./assets/js/jquery.toast.js"></script>
<script type="application/javascript">
   $('#brand_name').multiselect({
            columns: 1,
            placeholder: 'Select brand',
            search: true,
            //selectAll: true
    });
 
   $(document).ready(function() {
        $('#list').DataTable({ 
            "ajax": "brandlist.php?act=load",
            "processing": true,
            "serverSide": true,
            "pageLength": 25,
                "aaSorting": [],
                "aoColumnDefs": [
                    { 'bSortable': false, 'aTargets': [0,6,7] }
                ],
            language: {
                "processing" : "<div class='loader-bubble loader-bubble-primary m-5'></div>",
                "sEmptyTable" :  "No records found."
            }
            
        });
        $("#searchFrm").on( "submit", function(e) {
            e.preventDefault();
            
            var brandName = $("#brandName").val();
            var xcarestatus = $("#xcarestatus").val();
            var xcarestatus = $("#oneDollarPoints").val();

            $('#list').DataTable().destroy();
            $('#list').DataTable( { 
                "ajax": "brandlist.php?act=load&brandName="+brandName+"&xcarestatus="+xcarestatus+"&oneDollarPoints="+oneDollarPoints,
                "processing": true,
                "serverSide": true,
                "pageLength": 25,
                    "aaSorting": [],
                    "aoColumnDefs": [
                        { 'bSortable': false, 'aTargets': [0,6,7] }
                    ],
                language: {
                    "processing" : "<div class='loader-bubble loader-bubble-primary m-5'></div>",
                    "sEmptyTable" :  "No records found."
                }
                
            } );

        });

        $("#addFrm").on( "submit", function(e) {
            e.preventDefault();
            var brandIds = $("#brand_name").val();
            var brand_points = $("#brand_point").val();
            console.log(brandIds);
            $.ajax({      
                url: "brandlist.php",
                data: { 
                    act:"assign",
                    brandIds:brandIds,brand_points:brand_points
                },
                method: 'POST',
                success: function(data){
                    $(".loader-bubble").hide();
                    $.toast({
                            heading: '</em>',
                            text: 'Assign successfully...',
                            position: 'top-right',
                            stack: false,
                            showHideTransition: 'slide',
                            icon: 'success'
                    });
                    $('#list').DataTable().destroy();
                    $('#list').DataTable({ 
                        "ajax": "brandlist.php?act=load",
                        "processing": true,
                        "serverSide": true,
                        "pageLength": 25,
                            "aaSorting": [],
                            "aoColumnDefs": [
                                { 'bSortable': false, 'aTargets': [0,6,7] }
                            ],
                        language: {
                            "processing" : "<div class='loader-bubble loader-bubble-primary m-5'></div>",
                            "sEmptyTable" :  "No records found."
                        }
                        
                    });
                }
            });

        });
    });
</script>