<?php
	header('Content-Type: text/html; charset=utf-8');
	error_reporting(0);
	$path="../../";
	include("../../map.php");
	include("../../scripts.php");
	include("../../secure.php");
	session_start();  ob_start();
	if($_GET["tID"]>0){
		$_SESSION["tID"]=$_GET["tID"];
	}elseif($_GET["tID"]=="0"){
		$_SESSION["tID"]="";
		foreach ($_SESSION as $key => $value){
			if(substr($key,0,2)=="tm"){
				$_SESSION["tm_".$key] = "";
			}
		}
	}
	$tID=$_SESSION["tID"];
	$sqls=mysqli_query($conn, "select * from genel where ne='sablon' and id=".$tID.""); $rss=mysqli_fetch_assoc($sqls);
	if(mysqli_num_rows($sqls)>0){
		$mesajbox=$rss["n1"];
		$dmail=$rss["t10"];
		$mesajsub=$rss["t1"];
	}
	//findDirectoryPath("deppo")
?>
<!DOCTYPE html>
<html lang="en">
<style>
.v8-col200pxL-left {
    width: 223px;
    margin-left: -25px;
    float: left;
}
</style>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><?php echo $rs["t1"];?></title>
</head>
<body>
    <div class="qmodal">
        <div class="qmodal-content">
            <!-- Header with Action Buttons -->
            <div class="qmodal-header">
				<div class="header-title">
                    <nav aria-label="breadcrumb">
                        <ol class="breadcrumb">
                            <li class="breadcrumb-item"><a href="<?php echo $weburl?>" target="_blank"><i class="fa fa-home"></i></a></li>
                             <li class="breadcrumb-item"><a href="#"><?php echo ctranslate($t26);?></a></li>
                            <li class="breadcrumb-item active" aria-current="page"><?php echo $sdil[19]; //Toplu Eposta?></li>
                        </ol>
                    </nav>
                </div>
                <button type="button" id="openModalAndPost" class="btn btn-warning"><?php echo $sdil[112]; //Gönder?></button>
            </div>
			<form id="mform" method="post" target="modal2" action="../messages/ajax.php?ne=<?php echo $_GET["ne"];?>&islem=<?php echo $_GET["islem"];?>&durum=mail_sender" class="v3-row form" autocomplete="off">
            <!-- Left Tab Menu -->
            <div class="v8-columns">
					<div class="v8-col200pxL-left">
						<ul class="v8-side-tabs v8-js-tabs v8-same-height">
							<li class="current"><a href="#tab1" title=""><i class="fa fa-user"></i><span> Email Gönder</span></a></li>
							<li class="icon-tab with-margin"><a href="#" onclick="window.open('../upload/upload_all.php?ne=<?php echo $_GET["islem"]?>&file=excel', 'Upload', 'width=450,height=300')" title="xlsx import"><i class="fa fa-plus"></i> Excel</a></li>
							<?php if($_GET["xls"]<>""){?>
								<div style="clear:both;"></div>
								<li class="icon-tab with-margin"><a href="?ne=<?php echo $_GET["ne"];?>&islem=<?php echo $_GET["islem"];?>&xls=<?php echo $_GET["xls"];?>&durum=sliste" title="Xls Delete"><i class="fa fa-trash" aria-hidden="true" style="font-size:16px;"></i></a></li>
								<div style="clear:both;"></div>
								<li class="icon-tab with-margin"><a href="<?php echo findDirectoryPath("deppo")?>/deppo/excel/<?php echo $_GET["xls"];?>" title="Xls Download"><i class="fa fa-download" aria-hidden="true" style="font-size:16px;"></i></a></li>
							<?php }?>
							<li class="v3-btn v3-btn-warning w100" title="Taslaklar">
							<?php if($module["gtaslak"]=="1"){?>
								<select onChange="self.location.href=this.options[this.selectedIndex].value;" class="form-control">
										<option value="?ne=<?php echo $_GET['ne'];?>&islem=<?php echo $_GET['islem'];?>&tID=0"><?php echo translate("Taslaklar")?></option>
									<?php $sqlt=mysqli_query($conn, "select * from genel where ne='sablon' and t2='".$_GET["islem"]."' $ltemp order by id desc"); while($rst=mysqli_fetch_assoc($sqlt)){ ?>
										<option value="?ne=<?php echo $_GET['ne'];?>&islem=<?php echo $_GET['islem'];?>&tID=<?php echo $rst["id"];?>" <?php if($tID==$rst["id"]){?>selected<?php }?>><?php echo $rst["t1"];?></option>
									<?php }?>
										<option value="../public/templates.php?ne=mesajlar&islem=sablon">+ <?php echo translate("Yeni Ekle")?></option>
								</select>
							<?php }?>
							</li>
							<li class="v3-btn v3-btn-info w100" style="margin-top:5px" title="Gönderici">
								<select name="sender" class="form-control">
									<option value="0"><?php echo translate("Local Server")?></option>
									<?php $t=0; $sqlt=mysqli_query($conn, "select * from genel where ne='tanim' and t2='mailing' order by id asc"); while($rst=mysqli_fetch_assoc($sqlt)){$t++;?>
										<option value="../integration/Mailing/<?php echo $rst["n6"]?>/"><?php echo $rst["n6"]?></option>
									<?php }?>
								</select>
							</li>
						</ul>
					</div>
					<div class="v8-col200pxL-right">
						<div id="tab1" class="v8-tabs-content">
								<fieldset class="v3-col-md-4">
									<legend>Gönderen</b></legend>
									<input class="form-control" type="text" name="gonderen" value="<?php if($_SESSION["tmail_gonderen"]<>""){echo $_SESSION["tmail_gonderen"];}else{ echo $firma;};?>" placeholder="Gönderen">
								</fieldset>
								<fieldset class="v3-col-md-4">
									<legend>Gönderen Adres</b></legend>
									<select name="mgonderen" data-placeholder="Seçiniz" data-plugin-selecttwo="" class="form-control chosen-select" tabindex="8">
										<?php $sqlmg=mysqli_query($conn, "select * from genel where ne='tanim' and t2='email' order by id desc"); while($rsmg=mysqli_fetch_assoc($sqlmg)){ ?>
										<option value="<?php echo v3d($rsmg["n1"]);?>" <?php if(($dmail=="" and v3d($rsmg["n1"])==$mail) or v3d($rsmg["n1"])==$dmail){?>Selected<?php }?>><?php echo v3d($rsmg["n1"]);?></option>
										<?php }?>
									</select>
								</fieldset>
								<fieldset class="v3-col-md-4 <?php if($h4==0){echo "dn";}?>">
									<legend><?php echo $sdil[127]; //Grup Seç?></legend>
									<select name="s2" id="s2" class="form-control" tabindex="8" onchange="getCombo(this)">
										<option value="">...</option>
										<?php $sqlc=mysqli_query($conn, "select * from kategoriler where ne='kkategori' order by sira asc"); while($rsc=mysqli_fetch_assoc($sqlc)){ ?>
											<option value="<?php echo $rsc["Cat_ID"];?>"><?php echo $rsc["Cat_".$_SESSION["lang"].""];?></option>
										<?php }?>
										<?php
										$files = scandir(''.findDirectoryPath("deppo").'/excel/');  
										foreach ($files as $file){
											if(substr($file,0,5)==$_GET["islem"]){
										?>
										<option value="<?php echo $file;?>"><?php echo $file;?></option>
										<?php }}?>
									</select>
								</fieldset>
								<fieldset class="v3-col-md-8">
									<legend>Alıcı(lar)</b></legend>
									<select name="q[]" data-placeholder="Seçiniz" style="" multiple data-plugin-selecttwo="" class="form-control chosen-select" tabindex="8">
										<?php $sql5=mysqli_query($conn, "select * from t5 where t2<>'' $luye order by t1 asc"); while($rs5=mysqli_fetch_assoc($sql5)){ ?>
											<option value="<?php echo $rs5["id"];?>"><?php echo $rs5["t1"];?></option>
										<?php }?>
										<?php $sqlfm=mysqli_query($conn, "select * from genel where (ne='fmesaj' or ne='request') $luye"); while($rsfm=mysqli_fetch_assoc($sqlfm)){ $jsfi = json_decode($rsfm["n2"],true);?>
											<?php if($jsfi["Email"]<>""){?><option value="<?php echo $jsfi["Email"];?>"><?php echo $jsfi["Ad_Soyad"];?></option><?php }?>
										<?php }?>
									</select>
								</fieldset>
								<fieldset class="v3-col-md-4">
									<legend>Anahtar Kelime</b></legend>
									<input type="text" list="uniqueKeys" name="key" value="" placeholder="Anahtar kelime" class="form-control">
									<datalist id="uniqueKeys">
										<?php
										$uniqueKeys = [];
										$sql5 = mysqli_query($conn, "SELECT n4 FROM t5 WHERE t4<>'' $luye");
										while ($rs5 = mysqli_fetch_assoc($sql5)) {
											$keys = explode(',', $rs5["n4"]); // Veriyi virgüle göre ayır
											foreach ($keys as $key) {
												$trimmedKey = trim($key); // Boşlukları temizle
												if (!empty($trimmedKey) && !in_array($trimmedKey, $uniqueKeys)) {
													$uniqueKeys[] = $trimmedKey; // Tekrar etmeyenleri diziye ekle
													echo '<option value="' . htmlspecialchars($trimmedKey) . '"></option>';
												}
											}
										}
										?>
									</datalist>
								</fieldset>
								<fieldset class="v3-col-md-8">
									<legend>Konu</legend>
									<input type="text" name="konu" value="<?php echo $mesajsub;?>" placeholder="Konu" class="form-control">
								</fieldset>
								<fieldset class="v3-col-md-4">
									<legend>Süre</legend>
									<input type="text" name="msec" placeholder="Süre" value="3000" class="form-control">
									<p>*iki gönderi arasındaki zaman {ms}</p>
								</fieldset>
								<fieldset class="v3-col-md-12">
									<legend>Email <?php echo $sdil[207]; //Detay?></b></legend>
									<textarea name="mesaj" rows="3" class="form-control rte" id="rte" cols="20" placeholder="Email <?php echo $sdil[207]; //Detay?>"><?php echo $mesajbox;?></textarea>
									<br />
									<span style="font-size: 9pt">
										<a data-special="{AdSoyad}" class="v3-btn v3-btn-xs v3-btn-info mr5 addSpecial" title="Müşteri Ad Soyad">Ad Soyad</a> 
										<a data-special="{FirmaAdi}" class="v3-btn v3-btn-xs v3-btn-info mr5 addSpecial" title="Müşteri Firma Adı">Firma Adı</a> 
										<a data-special="{Unvan}" class="v3-btn v3-btn-xs v3-btn-info mr5 addSpecial" title="Müşteri Ünvan">Unvan</a> 
										<a data-special="{Telefon}" class="v3-btn v3-btn-xs v3-btn-info mr5 addSpecial" title="Müşteri Telefon">Telefon</a> 
										<a data-special="{Email}" class="v3-btn v3-btn-xs v3-btn-info mr5 addSpecial" title="Müşteri Email">Email</a> 
										<a data-special="{Sifre}" class="v3-btn v3-btn-xs v3-btn-info mr5 addSpecial" title="Müşteri Şifre">Şifre</a> 
										<a data-special="{firma}" class="v3-btn v3-btn-xs v3-btn-warning mr5 addSpecial" title="<?php echo $firma?>">firma</a> 
										<a data-special="{ftel}" class="v3-btn v3-btn-xs v3-btn-warning mr5 addSpecial" title="<?php echo $ftel?>">ftel</a> 
										<a data-special="{ftel2}" class="v3-btn v3-btn-xs v3-btn-warning mr5 addSpecial" title="<?php echo $ftel2?>">ftel2</a> 
										<a data-special="{fgsm}" class="v3-btn v3-btn-xs v3-btn-warning mr5 addSpecial" title="<?php echo $fgsm?>">fgsm</a> 
										<a data-special="{fweb}" class="v3-btn v3-btn-xs v3-btn-warning mr5 addSpecial" title="<?php echo $fweb?>">fweb</a> 
										<a data-special="{fadres}" class="v3-btn v3-btn-xs v3-btn-warning mr5 addSpecial" title="<?php echo $fadres?>">fadres</a> 
									</span>
									<script>
									  jQuery('a.addSpecial').click(function(e){
										e.preventDefault();
										CKEDITOR.instances.rte.insertHtml(jQuery(this).attr('data-special'));
									  })
									</script>
								</fieldset>
								<div style="clear:both;"></div>
								<div class="v3-col-md-12">
									<button id="send" class="button" type="submit" style="display:none;"><?php echo $sdil[112]; //Gönder?></button>
								</div>
							</form>
						</div>
							</div>
                 </div>
            </div>
</body>
<script src="../../assets/js/tabs.js"></script>
<?php echo $footer?>
<script>
jQuery(document).ready(function() {
	jQuery('select[name="sender"]').change(function() {
		var selectedValue = $(this).val();
		jQuery('#mform').attr('action', selectedValue);
	});
});
jQuery(document).on('click', '#openModalAndPost', function () {
  var form = jQuery('#mform');
  form.submit();
  jQuery('#myModal2').modal('show');
  jQuery('#myModal2').css('width','90%');
});
function getCombo(selectObject){
	var value = selectObject.value; 
	if(value.substr(value.length -4)=="xlsx"){
		jQuery('.v8-side-tabs').append('<li class="icon-tab with-margin"><a href="#" title="xlsx import"><i class="fa fa-plus" aria-hidden="true"></i> Excel</a></li>');
	}
}
jQuery(document).ready(function(){
	jQuery('#count').load('../../fonksiyon.php?islem=count&tbl=t5');
});
</script>
</html>