<?php
header('Content-Type:text/html;charset=utf-8');
$path="../../../";
include("cevir.php");
$path2="config/"; include("".$path."config/map.php");
include("fonksiyon".$ver.".php");
include("../inc.php");
include("mail/design.php");
date_default_timezone_set('Europe/Istanbul');
$start=date('H:i');$hf=date('H:i',strtotime('+50 minutes',strtotime($start)));$hl=date('H:i',strtotime('+70 minutes',strtotime($start)));
$gonderen=$firma;
function sfark($z){$z=strtotime($z);$f=time()-$z;return round($f/60);}
echo"<link rel='stylesheet' href='//cdn.crmplus.com.tr/css/watolye.css'/><script src='//kit.fontawesome.com/b1f22d74f8.js' crossorigin='anonymous'></script><ul class='v3-list-group'>";

switch($_GET["islem"]??''){
default:
echo"<li class='v3-list-group-item v3-list-group-item-warning'><i class='fas fa-ellipsis-v'></i> Accounting and Events Notification Module</li>";
$q=mysqli_query($conn,"select * from genel where (ne='not' or ne='senet' or ne='cek') order by id desc"); while($r=mysqli_fetch_assoc($q)){
	$s=strtotime($r["t4"]);$e=strtotime($r["t9"]);$t=strtotime(date('Y-m-d'));
	if(in_array($r["s3"],[0,1,2])&&$t>=$s&&$t<=$e){
		echo"<li class='v3-list-group-item v3-list-group-item-success'><i class='fas fa-paper-plane'></i> ".$r["t1"]." <i class='fas fa-chevron-right'></i> ".kisalt($r["n1"],50)."</li>";
		$konu=$r["t1"]." {".translate("Hatırlatma")."}";
		$mesaj=$design_top."<b>".$r["t1"]."</b><br>".$r["n1"]."<br>".dtarih($r["t9"],"gg ua yyyy")." ".$r["t2"]."<br><b>".$firma."</b> ".translate("olarak bizi ettiğiniz için teşekkür ederiz").$design_bottom;
		$ut5=explode(',',$r["t5"]);$sendto="";
		foreach($ut5 as $id){
			$id=trim($id);$m=mysqli_fetch_assoc(mysqli_query($conn,"select * from t5 where id=".$id));
			$_SESSION["Not_uID".$id]="gonderildi";
			if($id==0){
				if($module["bildirim_email"])emailgonder($fmail,$konu,$cc,$mesaj);
				if($module["bildirim_sms"])smsgonder($r["t1"],telefon($fgsm));
				if($module["bildirim_notification"])sNotification("e-Ajanda",$r["t1"],"Crm");
				$sendto.="{0} ".$fmail.", ";
			}else{
				$malici=base64_decode($m["t2"]);
				if($module["user_bildirim_email"])emailgonder($malici,$konu,$cc,$mesaj);
				if($module["user_bildirim_sms"])smsgonder($r["t1"],telefon($m["t4"]));
				if($module["user_bildirim_notification"])sNotification("e-Ajanda",$r["t1"],"Crm",$m["id"]);
				$sendto.="{".$id."} ".$malici.", ";
			}
		}
		echo"<li class='v3-list-group-item v3-list-group-item-info'><i class='fas fa-user'></i> ".$sendto."</li>";
	}
}

if($g5>0){
	echo"<li class='v3-list-group-item v3-list-group-item-warning'><i class='fas fa-ellipsis-v'></i> Services Notification Module</li>";
	$days=explode(',',$module["service_notification_periods"]);
	$users=mysqli_query($conn,"select * from t5 order by id desc"); while($u=mysqli_fetch_assoc($users)){
		$tbl="<table style='width:100%;font-size:12px;margin-top:15px;'><tr><td>".translate("Hizmet Detay")."</td><td>".translate("Tip")."</td><td>".translate("Başlangıç Tarihi")."</td><td>".translate("Bitiş Tarihi")."</td></tr>";
		$q2=mysqli_query($conn,"select * from t4 where ne='hizmet' and s1=".$u["id"]." order by t4 desc");$s=0; while($h=mysqli_fetch_assoc($q2)){
			$gun=(strtotime($h["t4"])-strtotime(date("Y-m-d")))/(60*60*24);
			if(in_array($gun,$days)){
				$s++;$tbl.="<tr><td>".$h["n1"]."</td><td>".$h["t1"]."</td><td>".dtarih($h["t3"],"gg ka yy")."</td><td>".dtarih($h["t4"],"gg ka yy")."</td></tr>";
			}
		}
		$tbl.="</table>";
		if($s){
			$konu=translate("Hizmet(ler) Ödeme Bildirimi");
			echo"<li class='v3-list-group-item v3-list-group-item-success'><i class='fas fa-paper-plane'></i> ".$u["t1"]." <i class='fas fa-chevron-right'></i> ".kisalt($konu,50)."</li>";
			$malici=base64_decode($u["t2"]);
			$mesaj=$design_top."<h3>".translate("Hatırlatma")."</h3>".translate("Sayın")." <b>".$u["t1"].";</b><br>".$konu."<br>".$tbl."<hr>".translate("end_service")."<br><br><b>".$firma."</b> ".translate("olarak bizi ettiğiniz için teşekkür ederiz").$design_bottom;
			if($module["user_bildirim_email"])emailgonder($malici,$konu,$cc,$mesaj);
			if($module["user_bildirim_sms"])smsgonder($konu,telefon($u["t4"]));
			if($module["user_bildirim_notification"])sNotification("Hizmet Bildirimi",$konu,"Crm",$u["id"]);
			$admin=$design_top."<h3>".translate("Hizmet Bildirimi")."</h3>".translate("Yöneticiye gönderildi:")." <b>".$malici."</b><br>".$tbl.$design_bottom;
			if($module["bildirim_email"])emailgonder($fmail,$konu,$cc,$admin);
			if($module["bildirim_sms"])smsgonder($konu,telefon($fgsm));
			if($module["bildirim_notification"])sNotification("Hatırlatma",$konu,"Crm");
		}
	}
}

if($e8>0){
	echo"<li class='v3-list-group-item v3-list-group-item-warning'><i class='fas fa-ellipsis-v'></i> Payment Notification Module</li>";
	$q3=mysqli_query($conn,"select * from t4 where ne='cari' and pb1>0 and t12<>'' order by t4 desc"); while($r=mysqli_fetch_assoc($q3)){
		$gun=tfark2(date('Y-m-d'),$r["t12"]);
		$ndate=strtotime($r["t12"]);
		if($gun>=-2&&$gun<=1){
			$konu=translate("Ödeme Bildirimi");
			$c=mysqli_fetch_assoc(mysqli_query($conn,"select * from t5 where id=".$r["s1"]));
			echo"<li class='v3-list-group-item v3-list-group-item-success'><i class='fas fa-paper-plane'></i> ".$c["t1"]." <i class='fas fa-chevron-right'></i> ".$konu."</li>";
			$malici=base64_decode($c["t2"]);
			$mesaj=$design_top."<h3>".translate("Hatırlatma")."</h3>".translate("Sayın")." <b>".$c["t1"].";</b><br><b>".wprice($r["pb1"])." ".$r["t6"]."</b> ".translate("tutarındaki bakiyeniz için ödeme hatırlatmasıdır.")."<hr>".translate("end_payment")."<br><b>".$firma."</b>".$design_bottom;
			if($module["user_bildirim_email"])emailgonder($malici,$konu,$cc,$mesaj);
			if($module["user_bildirim_sms"])smsgonder($konu,telefon($c["t4"]));
			if($module["user_bildirim_notification"])sNotification("Ödeme Bildirimi",$konu,"Crm",$c["id"]);
		}
	}
}
break;

case "basket":
echo"Basket Reminder Module<hr>";
$q=mysqli_query($conn,"select distinct s1 from eticaret where ne='sepet' and t5='sepet'"); while($s=mysqli_fetch_assoc($q)){
	$u=mysqli_fetch_assoc(mysqli_query($conn,"select * from t5 where id=".$s["s1"]));
	$dk=sfark($u["ts3"]);
	if($dk>=15&&$dk<=45){
		$konu=translate("Sepetinizde Bekleyen Ürün(ler) Var");
		$mesaj="<h2>".translate("Sepet Hatırlatma")."</h2><p>".translate("Sepetinizde unuttuğunuz ürünleri hatırlatmak isteriz.")."</p><hr><table style='width:100%;font-size:13px;'><tr><th>".translate("Ürün")."</th><th style='text-align:right'>".translate("Fiyat")."</th></tr>";
		$q2=mysqli_query($conn,"select * from eticaret where s1='".$u["id"]."' and ne='sepet' and t5='sepet'");
		$top=0;while($b=mysqli_fetch_assoc($q2)){$mesaj.="<tr><td>".kisalt($b["n1"],3)."</td><td style='text-align:right'>".$b["s2"]."X ".number_format($b["pb1"],2)." ".$kpb."</td></tr>";$top+=$b["pb1"]*$b["s2"];}
		$mesaj.="<tr><td colspan='2' style='text-align:right'><b>".translate("Genel Toplam").":</b> ".number_format($top,2)." ".$kpb."</td></tr><tr><td colspan='2' style='text-align:center'><a href='".$weburl."?eticaret/sepet' target='_blank' style='padding:10px;background:#961677;color:#fff;text-decoration:none;border-radius:2px;'>".translate("Siparişi Tamamla")."</a></td></tr></table>";
		$mesaj=$design_top.$mesaj.$design_bottom;
		emailgonder(v3d($u["t2"]),$konu,$cc,$mesaj,'order');
		$_SESSION["basket_".$u["id"]]=1;
	}}
	break;

	case "inday":
	echo"Daily Notification Module<hr>";
	$q=mysqli_query($conn,"select * from genel where ne='not' order by id desc"); while($r=mysqli_fetch_assoc($q)){
		$d=explode('-',$r["t4"]);
		if($d[2]==date('d')&&$d[1]==date('m')&&$d[0]==date('Y')&&$r["t2"]>$hf&&$r["t2"]<$hl){
			$konu=$cdil[48];$mesaj=$design_top."<h3>".$konu."</h3><b>".$r["t1"]."</b><br>".$r["n1"]."<br>".$r["ts2"]." ".$r["t2"].$design_bottom;
			if(in_array($module["bildirim"],[1,3]))emailgonder($mail,$konu,$cc,$mesaj);
			if(in_array($module["bildirim"],[2,3]))smsgonder($r["t1"],telefon($fgsm));
			sNotification($konu,$r["t1"],"Crm");
		}}
		break;
	}

	echo"</ul><center>$hf | $hl => Operation Successful</center>";
?>