<? include "top.php"; ?>
<!DOCTYPE html>
<html>
   <head>
      <?php include('include/head.php'); ?>
      <title>Add Channel</title>
      <link rel="stylesheet" type="text/css" href="https://sarmac.b-cdn.net/plugins/datatables/media/css/jquery.dataTables.css">
      <link rel="stylesheet" type="text/css" href="https://sarmac.b-cdn.net/plugins/datatables/media/css/dataTables.bootstrap4.css">
      <link rel="stylesheet" type="text/css" href="https://sarmac.b-cdn.net/plugins/datatables/media/css/responsive.dataTables.css">
      <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/sweetalert2@9"></script>
   </head>
   <body>
      <?php include('include/header.php');?>
      <?
         $custid=$_REQUEST['custid'];
         $query=f(q("SELECT * FROM `adduser`WHERE  is_cable=1 AND id='$custid'"));
         $prc=floatval($query['price'])*(0);
         $total=floatval($query['price'])+floatval($prc);
         ?>
      <?php include('include/sidebar.php'); 
         ?>
      <div class="main-container">
         <div class="pd-ltr-20 customscroll customscroll-10-p height-100-p xs-pd-20-10">
            <div class="min-height-200px">
               <div class="page-header">
                  <div class="row">
                     <div class="col-md-6 col-sm-12">
                        <div class="title">
                           <h4>Add Channel</h4>
                        </div>
                        <nav aria-label="breadcrumb" role="navigation">
                           <ol class="breadcrumb">
                              <li class="breadcrumb-item"><a href="index.php">Home</a></li>
                              <li class="breadcrumb-item active" aria-current="page">Add Channel</li>
                           </ol>
                        </nav>
                     </div>
                     <div class="col-md-6 col-sm-12 text-right">
                     </div>
                  </div>
               </div>
               <!-- Default Basic Forms Start -->
               <div class="pd-20 bg-white border-radius-4 box-shadow mb-30">
                  <small style="color: red;"><?=$msg?></small>
                  <div class="clearfix" style="min-height: 30px;"></div>
                  <div class="form-group row">
                     <div class="col-md-12">
                        <b>User Details</b><br>
                        <?=$query['name']?><br>
                        <b>Cust Code:</b> <?=$query['custid']?><br>
                        <b>Address:</b> <?=$query['address']?><br>
                        <b>Phone :</b> <?=$query['phone']?><br>
                        <b>Package Name :</b> <?=$query['pay_ch']?><br>
                        <b>Current Amount: &#8377;<?=$total?></b>
                     </div>
                  </div>
                  <div class="form-group row">
                     <div class="col-md-4" style="overflow-y: scroll;height: 300px;">
                        <form method="POST">
                           <input type="hidden" name="rowid" id="rowid" value="<?=$query['id']?>">
                           <input type="hidden" id="name1" value="0" name="yt">
                           <input type="hidden" id="name2" value="0" name="ytt">
                           <input type="hidden" id="name3" value="0" name="ytss">
                           <input type="hidden" name="packle" id="pacl" value="">
                           <input type="hidden" name="packleid" id="pacid" value="">
                           <label>Cable Package</label><br>
                           <hr>
                           <?
                              $getpack=mysqli_query($con,"SELECT * FROM tbl_pack WHERE ptype='2'");
                              while($arr=mysqli_fetch_array($getpack)){
                              ?>
                           <input type="checkbox" name="packs[]" packname="<?=$arr['pname']?>" price="<?=$arr['prc']?>" data="<?=$arr['pnochannel']?>" value="<?=$arr['pid']?>" class="cpack pac" onclick="cpacklength(); cadd(); ttlc(); cpval(); ncf();"> <?=$arr['pname']?>&nbsp;(&#8377; <?=$arr['prc']?>)<br>
                           <?}?>
                     </div>
                     <div class="col-md-4" style="overflow-y: scroll;height: 300px;">
                     <label>Broadcaster Package</label><br><hr>
                     <?
                        $getpack=mysqli_query($con,"SELECT * FROM tbl_pack WHERE ptype='3'");
                        while($arr=mysqli_fetch_array($getpack)){
                        ?>
                     <input type="checkbox" name="bpacks[]" packname="<?=$arr['pname']?>" price="<?=$arr['prc']?>" data="<?=$arr['pnochannel']?>" value="<?=$arr['pid']?>" class="packs pac" onclick="packlength(); ttlc(); pval(); ncf();"> <?=$arr['pname']?>&nbsp;(&#8377; <?=$arr['prc']?>)<br>
                     <?}?>
                     </div>
                     <div class="col-md-4" style="overflow-y: scroll;height: 300px;">
                     <label>Ala Carte Channels</label><br><hr>
                     <?
                        $getpack=mysqli_query($con,"SELECT * FROM tbl_pack WHERE ptype='4'");
                        while($arr=mysqli_fetch_array($getpack)){
                        ?>
                     <input type="checkbox" name="alacarte[]" class="pack pac" packname="<?=$arr['pname']?>" price="<?=$arr['prc']?>" data="<?=$arr['pnochannel']?>" value="<?=$arr['pid']?>" onclick="arelength(); ttlc(); ncf();alc();"> <?=$arr['pname']?>&nbsp;(&#8377; <?=$arr['prc']?>)<br>
                     <?}?>
                     </div>
                  </div>
                  <div class="col-md-6">
                  <p>Number Of Cable Package : <b id="noop"></b></p>
                  <p>Number Of Broadcaster Package : <b id="bop"></b></p>
                  <p>Number Of Ala Carte Channel : <b id="acc"></b></p>
                  <p>Total Number Of channel : <b id="tot"></b></p>
                  <p>NCF : <b id="ncc"></b></p>
                  <input type="hidden" name="nc" id="ncff" value="0">
                  <p>Cable Package Total : <b id="cpcid">0</b></p>
                  <p>Broadcaster Package Total : <b id="pcid"></b></p>
                  <p>Ala Carte Total : <b id="alc"></b></p>
                  <input type="hidden" name="accc" id="aocl" value="0">
                  <input type="hidden" name="pcc" id="ptid" value="">
                  <input type="hidden" name="pccd" id="cptid" value="">
                  <p>Total Amount : <b id="tott"></b></p>
                  <input type="hidden" name="ptot" id="ptotal" value="">
                  <hr>
                  <button type="button" class="btn btn-warning" onclick="reg_validation();"><i class="fa fa-eye"></i> Change Now</button>
                  </div>
                  </form>
                  <div class="collapse collapse-box" id="basic-form1" >
                  </div>
               </div>
            </div>
            <?php include('include/footer.php'); ?>
         </div>
      </div>
      <?php include('include/script.php'); ?>
      <script src="src/plugins/datatables/media/js/jquery.dataTables.min.js"></script>
      <script src="src/plugins/datatables/media/js/dataTables.bootstrap4.js"></script>
      <script src="src/plugins/datatables/media/js/dataTables.responsive.js"></script>
      <script src="src/plugins/datatables/media/js/responsive.bootstrap4.js"></script>
      <!-- buttons for Export datatable -->
      <script src="src/plugins/datatables/media/js/button/dataTables.buttons.js"></script>
      <script src="src/plugins/datatables/media/js/button/buttons.bootstrap4.js"></script>
      <script src="src/plugins/datatables/media/js/button/buttons.print.js"></script>
      <script src="src/plugins/datatables/media/js/button/buttons.html5.js"></script>
      <script src="src/plugins/datatables/media/js/button/buttons.flash.js"></script>
      <script src="src/plugins/datatables/media/js/button/pdfmake.min.js"></script>
      <script src="src/plugins/datatables/media/js/button/vfs_fonts.js"></script>
      <script>
         $('document').ready(function(){
            $('.data-table').DataTable({
               scrollCollapse: true,
               autoWidth: false,
               responsive: true,
               columnDefs: [{
                  targets: "datatable-nosort",
                  orderable: false,
               }],
               "lengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]],
               "language": {
                  "info": "_START_-_END_ of _TOTAL_ entries",
                  searchPlaceholder: "Search"
               },
            });
            $('.data-table-export').DataTable({
               scrollCollapse: true,
               autoWidth: false,
               responsive: true,
               columnDefs: [{
                  targets: "datatable-nosort",
                  orderable: false,
               }],
               "lengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]],
               "language": {
                  "info": "_START_-_END_ of _TOTAL_ entries",
                  searchPlaceholder: "Search"
               },
               dom: 'Bfrtip',
               buttons: [
               'copy', 'csv', 'pdf', 'print'
               ]
            });
            var table = $('.select-row').DataTable();
            $('.select-row tbody').on('click', 'tr', function () {
               if ($(this).hasClass('selected')) {
                  $(this).removeClass('selected');
               }
               else {
                  table.$('tr.selected').removeClass('selected');
                  $(this).addClass('selected');
               }
            });
            var multipletable = $('.multiple-select-row').DataTable();
            $('.multiple-select-row tbody').on('click', 'tr', function () {
               $(this).toggleClass('selected');
            });
         });
      </script>

<script type="text/javascript">
  $('.payg').hide();
  var ax;
  function cpacklength(){
  var pkcs = $('input.cpack:checked').length;
   $('#noop').html(pkcs);
   add();
   //ncf();
  }
  function packlength(){
  var pks = $('input.packs:checked').length;
   $('#bop').html(pks);
   add();
   //ncf();
  }
  function arelength(){
  var pkss = $('input.pack:checked').length;
   $('#acc').html(pkss);
   badd();
   //ncf();
   //$('#id').val(pkss);
  }
  function ttlc()
  {
   var w=parseFloat($('#name2').val());
   var x=parseFloat($('#name1').val());
   var y=parseFloat($('#name3').val());
// alert(w+'&&'+x);   
   var z= parseFloat(w)+parseFloat(x)+parseFloat(y);
   $('#tot').html(z);
  }
 function add(){
    var arr=[];
     $('input.packs:checked').each(function(){
      arr.push($(this).attr('data'));
    });
    //var arr = ["20.0","40.1","80.2","400.3"],
    sum = 0;
$.each(arr,function(){sum+=parseFloat(this) || 0; });

$('#name1').val(sum);
// alert(sum);
   }
    function cadd(){
    var arr=[];
     $('input.cpack:checked').each(function(){
      arr.push($(this).attr('data'));
    });
    //var arr = ["20.0","40.1","80.2","400.3"],
    sum = 0;
$.each(arr,function(){sum+=parseFloat(this) || 0; });

$('#name3').val(sum);
// alert(sum);
   }
     // var ax=arr;
     function badd(){
     var ar=[];
     $('input.pack:checked').each(function(){
      ar.push($(this).attr('data'));
    });
     sums = 0;
$.each(ar,function(){sums+=parseFloat(this) || 0; });

$('#name2').val(sums);
//ncf();
// alert(sums);
}
function pval()
{
  var arr=[];
  $('input.packs:checked').each(function(){
      arr.push($(this).attr('price'));
    });
    //var arr = ["20.0","40.1","80.2","400.3"],
    sum = 0;
$.each(arr,function(){sum+=parseFloat(this) || 0; });
$('#ptid').val(sum);
$('#pcid').html(sum);
//ncf();
// alert(sum);
}
function cpval()
{
  var arr=[];
  $('input.cpack:checked').each(function(){
      arr.push($(this).attr('price'));
    });
    //var arr = ["20.0","40.1","80.2","400.3"],
    sum = 0;
$.each(arr,function(){sum+=parseFloat(this) || 0; });
$('#cptid').val(sum);
$('#cpcid').html(sum);
//ncf();
// alert(sum);
}
function ncf()
{
   var ii=parseFloat($('#tot').html());
   // alert(ii);
   var pric=parseFloat($('#pcid').html());
   var prise=parseFloat($('#cpcid').html());
   if(prise<0 || price=='NaN')
   {
    prise=0;
   }
   var price=parseFloat(pric)+parseFloat(prise);
   // alert(price);
   // alert(prise);
   var mrp=price;
   var jj=price;
  // alert(ii);
  // $ii=count($pr);
    if(ii>100){
    var g=ii-100;
      // alert(g);
    var o=0;
    for(j=1;j<=g;j++)
    {
    //echo $i."<br>";
    if(j%25==0)
    {
        o=o+1;
    }
    var p=j%25;
    }
    if(o==0)
    {
        price=price+25;
        mrp=mrp+25; 
    }
    else if(o!=0)
    {
        o=o*25;
        price=price+o;
        mrp=mrp+o;
        if(p!=0)
        {
            price=price+25;
             mrp=mrp+25;
        }
    }

   var u=price-jj;
   
  
   $('#ncc').html(u);
   $('#ncff').val(u);
}
total();
}
function total()
  {
   var a=parseFloat($('#ncff').val());
   //alert(a);
   if(a=='')
   {
    a=0;
   }
   var b=parseFloat($('#pcid').html());
   var d=parseFloat($('#aocl').val());
   var e=parseFloat($('#cpcid').html());
   //alert(d);
   //alert(a+'&&'+b);   
   var c= parseFloat(a)+parseFloat(b)+parseFloat(d)+parseFloat(e);
   c=parseFloat(c).toFixed(2);
   $('#tott').html(c);
   $('#ptotal').val(c);
   // alert(c);
  }
// alert(ax);
function alc(){
 
    var arr=[];
  $('input.pack:checked').each(function(){
      arr.push($(this).attr('price'));
    });
    //var arr = ["20.0","40.1","80.2","400.3"],
    sum = 0;
$.each(arr,function(){sum+=parseFloat(this) || 0; }); 
//alert(sum);
$('#alc').html(sum);
$('#aocl').val(sum);
  total();
}
$('.pac').click(function(){
   var arr=[];
  $('input.pac:checked').each(function(){
      arr.push($(this).attr('packname'));
    });
    //var arr = ["20.0","40.1","80.2","400.3"],
    var package='';
   var pkg=arr.length;
  for (var i = 0; i < pkg; i++) {
    package= arr[i]+','+package;
   // alert(arr[i]);
  }//alert(package);
  package = package.replace(/,+$/,'');
  $('#pacl').val(package);
  //alert(package);
});
$('.pac').click(function(){
   var ay=[];
  $('input.pac:checked').each(function(){
      ay.push($(this).attr('value'));
    });
    //var arr = ["20.0","40.1","80.2","400.3"],
    var package='';
   var pkg=ay.length;
  for (var i = 0; i < pkg; i++) {
    package= ay[i]+','+package;
   // alert(arr[i]);
  }//alert(package);
  package = package.replace(/,+$/,'');
  $('#pacid').val(package);
  // alert(package);
});

  function reg_validation()
      {
       var mode='packchange_insert';
       var ptotal=$("#ptotal").val();
       var pacl=$("#pacl").val();
       var rowid=$("#rowid").val();
       var ncff=$("#ncff").val();
       var pacid=$("#pacid").val();
       // alert(ncff);

      jQuery.post('packchange_check.php',
          {
            "mode":mode,
            "ptotal":ptotal,
            "pacl":pacl,
            "rowid":rowid,
            "ncff":ncff,
            "pacid":pacid
          },
    function (data)
    { 
      if(data.trim()=='Saved')
      {
        // alert(data);
        alert('Your package has been saved');
        $('.payg').show();
       window.location.reload();
      }else{
        alert('Something Went Wrong');
      }
    });
      
          }
</script>
   </body>
</html>

