<?php $__env->startSection('content'); ?> 
<style>
  .body
  {
    background-color:white;
  }
</style>

<script>
  function loadTehsil()
  {
      DistrictId=$("#District").val();
      $.ajax({
          type: "GET",
          url: "getTehsilNames",
          data:"districtid="+DistrictId,
          dataType: "json",
          success: function(result){
               $('#Tehsil').children().remove();         
               $('#Tehsil').append($('<option>').text(" तालुका ").attr('value', ""));
               $.each(result, function(id, value) {
                  $('#Tehsil').append($('<option>').text(value.TehsilName).attr('value', value.TehsilID));
               });
            }
       });
  }

  function getCityOrVillages()
  {
      var IsCity=-1;
      if(document.getElementById("City").checked==true)
      {
        IsCity=1;
      }
      else if(document.getElementById("Village").checked==true)
      {
        IsCity=0;
      }
      var CityId=$('#CorV').val();
      var TehsilId=$('#Tehsil').val();
      // Load Cities or villages from 
       $.ajax({
            type: "GET",
            url: "loadAvailableCitiesOrVillages",
            data:"IsCity="+IsCity+"&Tehsil="+TehsilId,
            dataType: "json",
            success: function(result){
              if(IsCity==1)
              {
                $('#CorV').children().remove();         
                $('#CorV').append($('<option>').text(" शहर ").attr('value', ""));
                $.each(result, function(id, value) {
                    $('#CorV').append($('<option>').text(value.CityName).attr('value', value.CityID));
                });
              }
              else if(IsCity==0)
              {
                $('#CorV').children().remove();         
                $('#CorV').append($('<option>').text(" गाव ").attr('value', ""));
                $.each(result, function(id, value) {
                    $('#CorV').append($('<option>').text(value.VillageName).attr('value', value.VillageID));
                });
              }
            }
          });
  }

  function loadPrabhag()
  {
    //alert("In Prabhag : ");
      var IsCity=-1;
      if(document.getElementById("City").checked==true)
      {
        IsCity=1;
      }
      else if(document.getElementById("Village").checked==true)
      {
        IsCity=0;
      }
      var CityId=$('#CorV').val();
      // Load Cities or villages from 
       $.ajax({
            type: "GET",
            url: "loadPrabhag",
            data:"IsCity="+IsCity+"&City_Village_Id="+CityId,
            dataType: "json",
            success: function(result){
                $('#PrabhagOrWard').children().remove();
                $('#PrabhagOrWard').append($('<option>').text(" प्रभाग ").attr('value', ""));
                $.each(result, function(id, value) {
                    $('#PrabhagOrWard').append($('<option>').text(value.PrabhagName).attr('value', value.PrabhagName));
                });
            }
          });
  }

  function loadBooth()
  {
      //alert("In Prabhag : ");
      var IsCity=-1;
      if(document.getElementById("City").checked==true)
      {
        IsCity=1;
      }
      else if(document.getElementById("Village").checked==true)
      {
        IsCity=0;
      }
      var CityId=$('#CorV').val();
      // Load Cities or villages from 
      $.ajax({
            type: "GET",
            url: "getBoothsNumbersById",
            data:"Village_Or_City_Id="+CityId,
            dataType: "json",
            success: function(result){
                $('#Booth').children().remove();         
                $('#Booth').append($('<option>').text(" बूथ ").attr('value', ""));
                $.each(result, function(id, value) {
                    $('#Booth').append($('<option>').text(value.BoothNumber).attr('value', value.BoothID));
              });
            }
       }); 
  }


  function loadVoters()
  {
      $("#loading").show();
      var CorV_ID=$("#CorV").val();
      var PrabhagOrWard="";
      var Booth=$("#Booth").val();
      var IsCity=-1;
      var SMS=-1;
      if(document.getElementById("SMS").checked==true)
      {
        SMS=1;
      }
      else
      {
        SMS=0;
      }
      if(document.getElementById("City").checked==true)
      {
        IsCity=1;
      }
      else if(document.getElementById("Village").checked==true)
      {
        IsCity=0;
      }
      if(IsCity==1 && (PrabhagOrWard=="" && Booth=="" ))
      {
        alert(" कृपया बूथ निवडा ");
      }
      else 
      {
        if (SMS==1) {
        $("#SelectALl").removeAttr("disabled");
        $("#SendSMS").removeAttr("disabled");
        }
        else {
          $("#SelectALl").attr("disabled", true);
          $("#SendSMS").attr("disabled", true);
        }
        var table = $('#SurnameTable').DataTable();
        table.destroy();
         $(".dataTables_processing").show();
         $('#SurnameTable').DataTable(
         {
             "responsive": true,
             "dataType": "json",
             "dom": 'Blfrtip',
             "lengthMenu": [[10, 25, 50,100, 500], [10, 25, 50,100, 500]],
                buttons: [
                  'csvHtml5'
                ],
             "sAjaxSource": "getVotersByAddress?CorV_ID="+CorV_ID+"&IsCity="+IsCity+"&PrabhagId=&BoothId="+Booth+"&SMS="+SMS,
             initComplete: function() { $('#loading').hide(); },
             "aoColumns": [
                { "mData": "SrNo" },
                { "mData": "Name" },
                { "mData": "MobileNumber"},
                { "mData": "WhatsAppNumber"},
                { "mData": "Address" },
                { "mData": "NewAddress" },
                { "mData": "EPICNumber" },
                { "mData": "BoothNumber" },
                { "mData": "VotingCenter" },
                { "mData": "View"}
               ],
            });
          $("#Img").hide();
         $(".dataTables_processing").hide();
      }
  }

  function selectAll()
  {
      $("#Img").show();
      if(document.getElementById("SMS").checked==true)
      {
        var i=0;
        var table = $('#SurnameTable').DataTable();
        if(document.getElementById("SelectALl").checked==true)
        {
          // Select All
         // alert(" Datatable Size : "+table.data().count());

          for (var i = 0; i < table.data().count(); i++) {
            if(document.getElementById("Voter_"+i))
            {
              document.getElementById("Voter_"+i).checked=true;
            }
          };
         $("#Img").hide();
        }
        else if(document.getElementById("SelectALl").checked==false)
        {
          // Unselect All
          for (var i = 0; i < table.data().count(); i++) {
            if(document.getElementById("Voter_"+i))
            {
              document.getElementById("Voter_"+i).checked=false;
            }
          };
           $("#Img").hide();
        }
      }
      else
      {

      }
  }

  function Unselect()
  {
    if(document.getElementById("SelectALl").checked==true)
    {
      document.getElementById("SelectALl").checked=false;
    }
  }

  function SendSMS()
  {
    var Voters=[];
    var table = $('#SurnameTable').DataTable();
    var Data="";
    var VoterArray=[];
        if(document.getElementById("SelectALl").checked==true)
        {
          var Table=0;var k=0;
          for (var i = 0; i < table.data().count(); i++) {
            if(document.getElementById("Voter_"+i))
            {
              // Write Data
              if(document.getElementById("Voter_"+i).checked==true)
              {
                Data+=$("#Voter_"+i).val()+",";
                VoterArray[k]=$("#Voter_"+i).val();
                k++;
                // Write JSON File 

              }
            } 
          }
          $("#SMSDialog").modal('show');;
          //alert(Data);
          //window.location.href = "send-sms";
          // Send Voter Data to Form
          /* $.ajax({
            type: "GET",
            url: "Send_SMS",
            data:"Voters="+VoterArray,
            dataType: "json",
            success: function(result){
              // Go to Page SMS Page
              window.location.assign("Send_SMS");

            }
          });
          */
        }
        else if(document.getElementById("SelectALl").checked==false)
        {
          // Unselect All
          for (var i = 0; i < table.data().count(); i++) {
            if(document.getElementById("Voter_"+i))
            {
                // Get Selected Items
               if(document.getElementById("Voter_"+i))
                {
                 // Write Data
                  if(document.getElementById("Voter_"+i).checked==true)
                  {
                    Data+=$("#Voter_"+i).val()+",";
                  }
                }
            }
          };
        
         }
  }
</script>

  <div class="qv rc sm sp" style="margin-top:3%;">
        <div class="qw">
            <?php if(Session::has('Name')): ?>   
              <span style="margin-left:70px;"> <strong> पत्त्यानुसार मतदार रिपोर्ट </strong> </span>
              <span style="margin-top:-7px;margin-left:55%;">Welcome, <?php echo e(Session::get('Name')); ?>

              <a href='Report-Dashboard' class='cg ts fx green' style="margin-left:80px;"> Go To Dashboard </a>
            <?php endif; ?>
        </div>
    </div>

  <div class="by amt" style="margin-top:-30px;" >
    <div class="gc">
      <div class="gz">
        <div class="ca qo anx ">
          <div class="qf b aml" style="width:223%;margin-left:-60px;">
            <div class="col-lg-12" style="margin-left:-10px;">
               <div class="col-lg-2">
                  <select id="District" name="District" onchange="loadTehsil()" class="form-control">
                    <option value=""> जिल्हा </option>
                    <?php foreach($Districts as $District): ?>

                       <?php if($SelectDistrict==$District->DistrictID ): ?>
                          <option value="<?php echo e($District->DistrictID); ?>" selected><?php echo e($District->DistrictName); ?></option>
                        <?php else: ?>
                         <option value="<?php echo e($District->DistrictID); ?>"><?php echo e($District->DistrictName); ?></option>
                         <?php endif; ?>
                    <?php endforeach; ?>
                  </select>
              </div>

              <div class="col-lg-2">
                  <select id="Tehsil" name="Tehsil" class="form-control">
                    <option value="">  तालुका </option>
                       <?php foreach($Tehsils as $Tehsil): ?>
                         <?php if($SelectedTehsil==$Tehsil->TehsilID ): ?>
                            <option value="<?php echo e($Tehsil->TehsilID); ?>" selected><?php echo e($Tehsil->TehsilName); ?></option>
                          <?php else: ?>
                            <option value="<?php echo e($Tehsil->TehsilID); ?>"><?php echo e($Tehsil->TehsilName); ?></option>
                          <?php endif; ?>
                       <?php endforeach; ?>
                  </select>
              </div>

              <div class="col-lg-2">
                 <div class="bv" data-example-id="" style="margin-top:5px;">
                    <?php if($IsCity==-1): ?>
                      <div class="ew ug ul">
                        <label>
                          <input type="radio" id="City" name="CityOrVillage" value="City" onclick="getCityOrVillages()">  
                          <span class="uh"></span>
                           शहर
                        </label>
                      </div>
                      <div class="ew ug ul">
                         <label>
                           <input type="radio" name="CityOrVillage" id="Village" value="Village" onclick="getCityOrVillages()"> 
                            <span class="uh"></span>
                              गाव
                           </label>
                      </div>
                    <?php elseif($IsCity==1): ?>
                      <div class="ew ug ul">
                        <label>
                          <input type="radio" id="City" name="CityOrVillage" value="City" onclick="getCityOrVillages()" checked>  
                          <span class="uh"></span>
                           शहर
                        </label>
                      </div>
                    <div class="ew ug ul">
                         <label>
                           <input type="radio" name="CityOrVillage" id="Village" value="Village" onclick="getCityOrVillages()"> 
                            <span class="uh"></span>
                              गाव
                           </label>
                    </div>
                    <?php elseif($IsCity==0): ?>
                      <div class="ew ug ul">
                        <label>
                          <input type="radio" id="City" name="CityOrVillage" value="City" onclick="getCityOrVillages()" >  
                          <span class="uh"></span>
                           शहर
                        </label>
                      </div>
                      <div class="ew ug ul">
                         <label>
                           <input type="radio" name="CityOrVillage" id="Village" value="Village" onclick="getCityOrVillages()" checked> 
                            <span class="uh"></span>
                              गाव
                           </label>
                      </div>
                    <?php endif; ?>
                  </div>
              </div>

              <div class="col-lg-2">
                  <select id="CorV" name="CorV" onchange="loadBooth();" class="form-control">
                    <option value=""> शहर / गाव </option>
                      <?php if($IsCity==1): ?>
                         <?php foreach($Cities_Villages as $City_Village): ?>
                           <?php if($SelectedCityOrVillage==$City_Village->CityID ): ?>
                              <option value="<?php echo e($City_Village->CityID); ?>" selected><?php echo e($City_Village->CityName); ?></option>
                            <?php else: ?>
                              <option value="<?php echo e($City_Village->CityID); ?>"><?php echo e($City_Village->CityName); ?></option>
                            <?php endif; ?>
                         <?php endforeach; ?>
                      <?php elseif($IsCity==0): ?>
                        <?php foreach($Cities_Villages as $City_Village): ?>
                           <?php if($SelectedCityOrVillage==$City_Village->VillageID ): ?>
                              <option value="<?php echo e($City_Village->VillageID); ?>" selected><?php echo e($City_Village->VillageName); ?></option>
                            <?php else: ?>
                              <option value="<?php echo e($City_Village->VillageID); ?>"><?php echo e($City_Village->VillageName); ?></option>
                            <?php endif; ?>
                         <?php endforeach; ?>
                      <?php endif; ?>
                  </select>
              </div>

           <!--   <div class="col-lg-2">
                  <select id="PrabhagOrWard" name="PrabhagOrWard"  class="form-control">
                    <option value=""> प्रभाग </option>
                     <?php foreach($Prabhags as $Prabhag): ?>
                        <option value="<?php echo e($Prabhag->PrabhagName); ?>"><?php echo e($Prabhag->PrabhagName); ?></option>
                      <?php endforeach; ?>
                  </select>
              </div>  -->

              <div class="col-lg-2">
                <strong></strong>
                  <select id="Booth" name="Booth" style="width:80%" class="form-control" >
                    <option value=""> बूथ </option>
                     <?php foreach($Booths as $Booth): ?>
                        <option value="<?php echo e($Booth->BoothID); ?>"><?php echo e($Booth->BoothNumber); ?></option>
                      <?php endforeach; ?>
                  </select>
              </div>
          </div>
          <p/><p/>
          <div class="col-lg-12" style="margin-top:2%;">
            <div class="col-lg-2">
              <input type="hidden" id="SMS" name="SMS" >  
            </div>
            <div class="col-lg-2">
              <button type="submit" onclick="loadVoters()" class="cg fp">
                <span > शोधा </span> 
              </button>
            </div>
          </div>
           <div class="row" style="margin-left:12px;">
              <div class="col-lg-12">
                <div class="col-lg-5"></div>
                <div class="col-lg-2"> <img src="<?php echo asset('theme/assets/images/loader7.gif'); ?>" id="loading" name="loading">  </div>
                <div class="col-lg-5"></div>                
              </div>
            </div>
            &nbsp;
          <div class="row" style="margin-left:12px;">
                <!-- Datatable  -->
                &nbsp;&nbsp;&nbsp;
                <!-- <button name='SendSMS' id='SendSMS' onclick="SendSMS()" class='cg fp'>Send SMS</button> -->
                <br/>&nbsp;&nbsp;&nbsp;
                <table id="SurnameTable" class="table table-hover" ><!-- table-hover -->
                  <thead>
                    <tr>
                    <!--  <th> <input type="checkbox" onclick="selectAll()" id="SelectALl" name="SelectALl" value="All"> </th> -->
                      <th> अ.क्र.</th>
                      <th> नाव </th>
                      <th> मोबाईल नंबर </th>
                      <th> व्हॉट्सअप नंबर </th>
                      <th> पत्ता </th>
                      <th> नवीन पत्ता </th>
                      <th> मतदान क्र.</th>
                      <th> बूथ नंबर </th>
                      <th> मतदान केंद्र </th>
                      <th> View </th>
                    </tr>
                  </thead>
                  <tbody>
                  </tbody>
                </table>
                <p/>
            </div>
          </div>
        </div>
      </div>
    </div>      
  </div>
</div>
</div>

<script>
   //$("#surnames").select2();
   $("#Img").hide();
   $("#CorV").select2();
  
   $("#District").select2();
   $("#Tehsil").select2();
   $("#Booth").select2();
   $("#Cast").select2();
   $("#SelectALl").attr("disabled", true);
   $("#SendSMS").attr("disabled", true);
   $("#loading").hide();
</script>
<script>
  $(document).ready(function() { 
    var table = $('#Final_Numbers').DataTable();
        table.destroy();
         $('#Final_Numbers').DataTable(
         {
             "responsive": true,
             "dataType": "json",
             "lengthMenu": [[10, 25, 50,100, 500], [10, 25, 50,100, 500]],
             "sAjaxSource": "getSMSMobileNumbers",
             initComplete: function() { $('#loading').hide(); },
             "aoColumns": [
                { "mData": "Name" },
                { "mData": "MobileNumber"}
               ]
            });
        });
</script>

<?php $__env->stopSection(); ?>
<?php echo $__env->make('admin.layouts.votermainview', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>