<?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[20]; //Toplu Sms?></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=sms_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> Sms</span></a></li>
							<li class="v3-btn v3-btn-warning w100">
							<?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-warning w100 tal">
								<label>Test Mode</label>
								<input type="checkbox" name="test" value="true">
							</li>
						</ul>
					</div>
					<div class="v8-col200pxL-right">
						<div id="tab1" class="v8-tabs-content" style="min-height: 734px;">
								<?php if($_GET["durum"]=="ok"){?>
									<div class="alert alert-success">
										<?php echo $sdil[212]; //islem Basariyla Gerçeklestirilmistir !?>
									</div>
								<?php }?>
								<fieldset class="v3-col-md-4" style="">
									<legend>Kontor Bakiye</legend>
									<b>
										<div class="digi" style="font-family:arial; font-size:50px; color:#ff3300; text-align:center; margin-top:-20px"><?php echo smsbakiye();?> <?php if($ussms<>""){?><span style="opacity: 0.2; color:gray;"><?php echo smsbakiye()-$ussms?></span><?php }?></div>
									</b>
								</fieldset>
								<fieldset class="v3-col-md-4" style="">
									<legend>Orginatör</legend>
									<b>
										<div class="digi" style="font-family:arial; font-size:50px; color:#ff3300; text-align:center; margin-top:-20px"><?php echo tanim("sms","n3",0);?></div>
									</b>
								</fieldset>
								<fieldset class="v3-col-md-4 <?php if($h4==0){echo "dn";}?>">
									<legend>Alıcı Grubu (Kayıtlı)</legend>
									<select name="s2" data-placeholder="Seçiniz" class="form-control chosen-select" data-plugin-selecttwo="" tabindex="8">
											<option value="0">Lütfen Seçiniz</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 }?>
									</select>
								</fieldset>
								
								<fieldset class="v3-col-md-8">
									<legend>Alıcı</b></legend>
									<select name="q[]" data-placeholder="Seçiniz" style="" multiple data-plugin-selecttwo="" class="form-control chosen-select" tabindex="8">
											<option value="">Lütfen Seçiniz</option>
										<?php $sql5=mysqli_query($conn, "select * from t5 where t4<>'' $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["Telefon"]<>""){?><option value="<?php echo $jsfi["Telefon"];?>"><?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-12" style="height:120px !important;">
									<legend>Sms Detay (<span id="smsx"></span>)</legend>
									<textarea name="mesaj" rows="3" id="sms1" class="smsx form-control" cols="20" placeholder="Sms İçeriği" style="height:80px; margin-top: -10px;"><?php echo $mesajbox;?></textarea>
								</fieldset>
								<div class="v3-col-md-10" style="font-size: 9pt">
									<a onclick="addTextTag('sms1',' {AdSoyad} '); return false" class="v3-btn v3-btn-xs v3-btn-info mr5 " title="Müşteri Ad Soyad">{AdSoyad}</a> 
									<a onclick="addTextTag('sms1',' {FirmaAdi} '); return false" class="v3-btn v3-btn-xs v3-btn-info mr5 " title="Müşteri Firma Adı">{FirmaAdi}</a> 
									<a onclick="addTextTag('sms1',' {Unvan} '); return false" class="v3-btn v3-btn-xs v3-btn-info mr5 " title="Müşteri Unvan">{Unvan}</a> 
									<a onclick="addTextTag('sms1',' {Telefon} '); return false" class="v3-btn v3-btn-xs v3-btn-info mr5 " title="Müşteri Telefon">{Telefon}</a> 
									<a onclick="addTextTag('sms1',' {Email} '); return false" class="v3-btn v3-btn-xs v3-btn-info mr5 " title="Müşteri Email">{Email}</a> 
									<a onclick="addTextTag('sms1',' {Sifre} '); return false" class="v3-btn v3-btn-xs v3-btn-info mr5 " title="Müşteri Şifre">{Sifre}</a> 
									<a onclick="addTextTag('sms1',' {firma} '); return false" class="v3-btn v3-btn-xs v3-btn-warning mr5 " title="<?php echo $firma?>">{firma}</a> 
									<a onclick="addTextTag('sms1',' {ftel} '); return false" class="v3-btn v3-btn-xs v3-btn-warning mr5 " title="<?php echo $ftel?>">{ftel}</a> 
									<a onclick="addTextTag('sms1',' {ftel2} '); return false" class="v3-btn v3-btn-xs v3-btn-warning mr5 " title="<?php echo $ftel2?>">{ftel2}</a> 
									<a onclick="addTextTag('sms1',' {fgsm} '); return false" class="v3-btn v3-btn-xs v3-btn-warning mr5 " title="<?php echo $fgsm?>">{fgsm}</a> 
									<a onclick="addTextTag('sms1',' {fweb} '); return false" class="v3-btn v3-btn-xs v3-btn-warning mr5 " title="<?php echo $fweb?>">{fweb}</a> 
									<a onclick="addTextTag('sms1',' {fadres} '); return false" class="v3-btn v3-btn-xs v3-btn-warning mr5 " title="<?php echo $fadres?>">{fadres}</a> 
								</div>
								<div class="v3-col-md-2" style="text-align:right;">
									<button class="button" type="submit" style="display:none"><i class="fa fa-paper-plane-o" aria-hidden="true"></i> Gönder</button>
								</div>
							</form>
						</div>							
								</div>
							</div>
						</div>
					</div>
				</div>
			</form>
                 </div>
            </div>
</body>
<script src="../../assets/js/tabs.js"></script>
<?php echo $footer?>
<script type="text/javascript">
	jQuery(document).on('click', '#openModalAndPost', function () {
		var form = jQuery('#mform');
		form.submit();
		jQuery('#myModal2').modal('show');
		jQuery('#myModal2').css('width','90%');
	});
	function addTextTag(id,text) {
		document.getElementById(id).value += text;
	}
</script>
</html>