<?php 
if($filter=="cari"){
	$file="ajax_client_current"; $div="icari"; $fislem="cdetail"; $clink="cc_clear";
}else{
	$file="ajax_client_service"; $div="ihizmet"; $fislem="sdetail"; $clink="cs_clear";
}
?>
<div class="mmb20" style="position:relative">
    <div style="float:right; margin-bottom:5px;">
        <div class="current_btn fr">
    <?php if($filter=="cari"){?>
        <button type="button" style="float:right; margin-left:10px;" class="btn btn-default" data-toggle="dropdown">
            <i class="fa fa-share-alt" style="font-size:20px;"></i>
        </button>
        <div class="dropdown-menu dropdown-menu-right" x-placement="top-end" style="">
            <a class="dropdown-item btn btn-default" id="print_<?php echo $filter?>" target="_blank" onclick="window.open('../print/print.php?ne=<?php echo $_GET["ne"]?>&id=<?php echo $_GET["id"]?>&ts1=<?php echo $_GET["ts1"];?>&ts2=<?php echo $_GET["ts2"];?>&durum=ucari')">
                <i class="fa fa-print"></i> <?php echo ctranslate("Yazdır")?>
            </a>
            <a class="dropdown-item btn btn-default" onclick="window.open('<?php echo $weburl?>/current/<?php echo $_GET["id"]?>')">
                <i class="fa fa-link"></i> <?php echo ctranslate("Link")?>
            </a>
            <a  class="dropdown-item btn btn-default" id="print_email_<?php echo $filter?>" onclick="AjaxGResult('../print/print.php?ne=<?php echo $_GET["ne"]?>&id=<?php echo $_GET["id"]?>&ts1=<?php echo $_GET["ts1"];?>&ts2=<?php echo $_GET["ts2"];?>&durum=ucari_mail','',''); alert('Gönderildi')">
                <i class="fa fa-envelope"></i> <?php echo ctranslate("E-Mail Gönder")?>
            </a>
            <a class="dropdown-item btn btn-default" id="xls_<?php echo $filter?>" onclick="window.open('../print/print.php?ne=<?php echo $_GET["ne"]?>&id=<?php echo $_GET["id"]?>&ts1=<?php echo $_GET["ts1"];?>&ts2=<?php echo $_GET["ts2"];?>&durum=ucari&op=xls')">
                <i class="fa fa-file-excel-o"></i> <?php echo ctranslate("xls export")?>
            </a>
        </div>
    <?php }?>
    <button type="button" class="btn btn-danger fr msa btn-all-clear" data-href="/clients/<?php echo $file?>.php?ne=<?php echo $_GET["ne"]?>&islem=<?php echo $_GET["islem"]?>&id=<?php echo $_GET["id"]?>&durum=<?php echo $clink?>" data-did="#i<?php echo $div?>" style="padding: 1px 6px; margin-left:10px;" title="Tüm hareketleri temizle">
        <i class="fa fa-eraser" aria-hidden="true" style="font-size:20px;"></i>
    </button>
    <!--<button type="button" class="btn btn-info fr" id="all_current_<?php echo $filter?>" style="padding: 1px 6px; margin-left:10px;" title="<?php echo date('Y-m-d', strtotime($yilbasi. ' -5 years'))?>">
        <?php echo date('Y-m-d', strtotime($yilbasi. ' +5 years'))?>
    </button>-->
    
    <button type="button" class="btn btn-warning mfrm fr cp" data-toggle="modal" data-title="<?php echo $rs["t1"]?>" data-width="90%" data-ajax="icari" data-target="#myModal" data-url="../../fonksiyon.php?islem=<?php echo $fislem?>&id=<?php echo $_GET["id"]?>">
        <i class="fa fa-plus" style="font-size:20px;"></i>
    </button>
    <div class="fr mmr10 mr10 filter_form" style="margin-top:-2px; display:none;">
        <form id="cfilter_<?php echo $filter?>">
            <input type="hidden" name="ne" value="<?php echo $_GET["ne"]?>">
            <input type="hidden" name="islem" value="<?php echo $_GET["islem"]?>">
            <input type="hidden" name="id" value="<?php echo $_GET["id"]?>">
            <input type="text" name="iq" id="iq" value="<?php if($_GET["q"]<>""){echo $_GET["q"];}?>" placeholder="<?php echo ctranslate("Kelime")?>">
            <select id="when_<?php echo $filter?>" class="">
                <option ts1="<?php echo date('Y-m-d', strtotime(date("Y-m-d"). ' -30 days'))?>">...</option>
                <option ts1="<?php echo date('Y-m-d', strtotime(date("Y-m-d"). ' -30 days'))?>"><?php echo ctranslate("Son 30 Gün")?></option>
                <option ts1="<?php echo date("Y-m-d")?>"><?php echo ctranslate("Bugün")?></option>
                <option ts1="<?php echo $haftabasi?>"><?php echo ctranslate("Bu Hafta")?></option>
                <option ts1="<?php echo $aybasi?>"><?php echo ctranslate("Bu Ay")?></option>
                <option ts1="<?php echo $yilbasi?>"><?php echo ctranslate("Bu Yıl")?></option>
                <option ts1="<?php echo date('Y-m-d', strtotime($yilbasi. ' -1 years'))?>"><?php echo date('Y', strtotime(date("Y"). ' -1 years'))?></option>
                <option ts1="<?php echo date('Y-m-d', strtotime($yilbasi. ' -2 years'))?>"><?php echo date('Y', strtotime(date("Y"). ' -2 years'))?></option>
                <option ts1="<?php echo date('Y-m-d', strtotime($yilbasi. ' -3 years'))?>"><?php echo date('Y', strtotime(date("Y"). ' -3 years'))?></option>
            </select>
            <input type="date" name="ts1" id="fts1_<?php echo $filter?>" value="<?php if($_GET["ts1"]<>""){echo $_GET["ts1"];}else{echo date('Y-m-d', strtotime(date("Y-m-d"). ' -30 days'));}?>">
            <input type="date" name="ts2" id="fts2_<?php echo $filter?>" value="<?php if($_GET["ts2"]<>""){echo $_GET["ts2"];}else{echo date("Y-m-d");}?>">
            <button type="button" id="submit_filter_btn_<?php echo $filter?>" class="btn btn-xs btn-warning">
                <i class="fa fa-filter" style="font-size:20px;"></i>
            </button>
        </form>
        <script>
            jQuery('#when_<?php echo $filter?>').on('change', function() {
                var w = jQuery("#when_<?php echo $filter?> option:selected").attr("ts1");
                jQuery('#fts1_<?php echo $filter?>').val(w);
                jQuery('#fts2_<?php echo $filter?>').val('<?php echo date("Y-m-d")?>');
            });
            jQuery('#fts1_<?php echo $filter?>').on('change', function() {
                jQuery('#fts2_<?php echo $filter?>').val('<?php echo date("Y-m-d")?>');
            });
            jQuery('#all_current_<?php echo $filter?>').on('click', function() {
                jQuery('#fts1_<?php echo $filter?>').val('<?php echo date('Y-m-d', strtotime($yilbasi. ' - 5 years '))?>');
                jQuery('#fts2_<?php echo $filter?>').val('<?php echo date('Y-m-d', strtotime($yilbasi. ' + 5 years '))?>');
            });
            jQuery('#submit_filter_btn_<?php echo $filter?>').click(function() {
                var fts1_<?php echo $filter?>=jQuery('#fts1_<?php echo $filter?>').val();
                var fts2_<?php echo $filter?>=jQuery('#fts2_<?php echo $filter?>').val();
				jQuery('#print_<?php echo $filter?>').attr('onclick', "window.open('/print/print.php?ne=<?php echo $_GET["ne"]?>&id=<?php echo $_GET["id"]?>&ts1='+fts1_<?php echo $filter?>+'&ts2='+fts2_<?php echo $filter?>+'&durum=ucari');");
				jQuery('#xls_<?php echo $filter?>').attr('onclick', "window.open('/print/print.php?ne=<?php echo $_GET["ne"]?>&id=<?php echo $_GET["id"]?>&ts1='+fts1_<?php echo $filter?>+'&ts2='+fts2_<?php echo $filter?>+'&durum=ucari&op=xls');");
              
                jQuery.ajax({
                    url: "../clients/<?php echo $file?>.php",
                    method: "GET",
                    data: jQuery('#cfilter_<?php echo $filter?>').serialize(),
                    beforeSend: function() {
                        jQuery('#<?php echo $div?>').html('<span class="text-info">Loading response...</span>');
                    },
                    success: function(data) {
                        jQuery('#<?php echo $div?>').fadeIn().html(data);
                    }
                });
            });
        </script>
    </div>
    <button type="button"  class="fr mmr10 mr10 btn btn-warning filter_btn" onclick="toggle('.filter_form');toggle('.filter_btn');">
        <i class="fa fa-filter" aria-hidden="true" style="font-size:20px;"></i>
    </button>
</div>
    </div>
 </div>