<?php
$products = json_decode(GetArr("kayit"), true);
$users = json_decode(GetArr("uye","users"), true);
?>
<div class="inner-wrapper">
	<section role="main" class="content-body">
		<header class="page-header">
			<h2><?php echo $t25s[0];?> <?php echo ctranslate("İlişkileri")?></h2>
			
			<div class="right-wrapper text-right">
				<ol class="breadcrumbs">
					<li>
						<a href=".">
							<i class="fa fa-home"></i>
						</a>
					</li>
					<li><span>Crm +Plus</span></li>
					<li><span><?php echo $t25s[0];?> <?php echo ctranslate("İlişkileri")?></span></li>
				</ol>
				
				<a class="sidebar-right-toggle" data-open="sidebar-right"><i class="fa fa-chevron-left"></i></a>
			</div>
		</header>
		<div class="v3-row" id="process"></div>
		<div class="row">
			<div class="col">
				<section class="card">
					<header class="card-header v3-bg-info">
						<div class="card-actions" id="v-<?php echo $_GET['islem'];?>">
							<?php include("modules/public/filter.php");?>
							<a class="mb-1 mt-1 mr-1 btn btn-default" id="data-prev" href="<?php if($_GET["sayfa"]=="" or $_GET["sayfa"]==1){?>#<?php }else{?>?ne=<?php echo $_GET['ne'];?>&islem=<?php echo $_GET['islem'];?>&s2=<?php echo $_GET["s2"];?>&key=<?php echo $_GET["key"];?>&order=<?php echo $_GET["order"];?>&sayfa=<?php echo $ss-1;?><?php }?>" title="<?php echo $sdil[146]; //Önceki?>"><i class="fa fa-chevron-circle-left" aria-hidden="true"></i></a>
							<div class="mb-1 mt-1 mr-1 btn btn-default">
								<select onChange="self.location.href=this.options[this.selectedIndex].value;" class="form-control v3-input-xs" style="padding:0px; height: 19px;">
									<?php
										$rsay=$rcount/$slmt;
										for ($i = 0; $i <= $rsay; $i++) {$x=$i+1;
									?>
										<option value="?ne=<?php echo $_GET['ne'];?>&islem=<?php echo $_GET['islem'];?>&key=<?php echo $_GET["key"];?>&order=<?php echo $_GET["order"];?>&s2=<?php echo $_GET["s2"];?>&sayfa=<?php echo $x;?>" <?php if(($_GET["sayfa"]=="" and $x==1) or $_GET["sayfa"]==$x){?>selected<?php }?>><?php echo $x;?></option>
									<?php }?>
								</select>
							</div>
							<a class="mb-1 mt-1 mr-1 btn btn-default" id="data-next" href="<?php if($x >= $ss+1){?>?ne=<?php echo $_GET['ne'];?>&islem=<?php echo $_GET['islem'];?>&key=<?php echo $_GET["key"];?>&order=<?php echo $_GET["order"];?>&s2=<?php echo $_GET["s2"];?>&sayfa=<?php echo $ss+1;?><?php }else{?>#<?php }?>"  title="<?php echo $sdil[147]; //Sonraki?>"><i class="fa fa-chevron-circle-right" aria-hidden="true"></i></a>
							<a class="mb-1 mt-1 mr-1 btn btn-warning mfrm" data-toggle="modal" data-target="#myModal" data-url="modules/public/add.php?ne=uye&islem=relations" data-ref="?ne=uye&islem=relations" data-title="<?php echo $sdil[200]; //Yeni?> <?php echo ctranslate("İlişki")?>"><i class="fa fa-plus " aria-hidden="true"></i></a>
							<a class="mb-1 mt-1 mr-1 btn btn-warning exls"><i class="fas fa-file-excel" aria-hidden="true"></i></a>
							<?php if($MSA==1){?>
								<a class="mb-1 mt-1 mr-1 btn btn-default mfrm full" data-toggle="modal" data-target="#myModal" data-url="fonksiyon.php?ne=<?php echo $_GET["ne"]?>&islem=settings" href="#" title="<?php echo $sdil[35]; //Ayarlar?>"><i class="fa fa-ellipsis-v" aria-hidden="true"></i></a>
							<?php }?>
						</div>
						
						<h2 class="card-title mdn"><?php echo $t25s[0];?> <?php echo ctranslate("İlişkileri")?></h2>
					</header>
					<div class="card-body">
						<?php if($_GET["ts1"]=="" and $_GET["ts2"]==""){?>
							<div class="alert alert-warning">#<?php echo ctranslate("Son 30 Gün Listeniyor.")?></div>
						<?php }?>
						<table class="table table2excel">
							<thead>
								<tr class="mdn">
									<th class="w1" style="text-align:center;">ID</th>
									<th><?php echo ctranslate("Açıklama")?></th>
									<th class="w15"><?php echo ctranslate("Ürün/Hizmet")?></th>
									<th class="w12"><?php echo ctranslate("Yönetici(ler)")?></th>
									<th class="w12"><?php echo ctranslate("Müşteri")?></th>
									<?php $i=0; $fci="i"; $sqli=mysqli_query($conn, "select * from genel where ne='inputs' $linputs and (t2='All' or t2='".$_SESSION["lang"]."') and (n3='".$_GET["ne"]."' or n3='".$_GET["islem"]."') and n4<>'switch' and n13='list' and s1=0 $luye order by s10,id asc"); while($rsi=mysqli_fetch_assoc($sqli)){$i++;?>
										<th class="w8"><?php echo $rsi["n1"];?></th>
									<?php }?>
									<th class="w8"><?php echo ctranslate("Tarih")?></th>
									<th class="w5"><?php echo ctranslate("İşlemler")?></th>
								</tr>
							</thead>
							<tbody>
								<?php
								if($_GET["key"]<>""){
									$sorgu.="and (t1 like '%".$_GET["key"]."%' or n1 like '%".$_GET["key"]."%' or n17 like '%".$_GET["key"]."%')";
								}
								if($_GET["user"]<>""){
									$sorgu.="and (s1='".$_GET["user"]."' or s19='".$_GET["user"]."')";
								}
								$sql=mysqli_query($conn, "select * from t1 where ne='relations' $sorgu $luye order by id desc"); while($rs=mysqli_fetch_assoc($sql)){
									//if(($_GET["ts1"]=="" and $_GET["ts2"]=="" and $rs["ts1"] >= date('Y-m-d', strtotime(date("Y-m-d"). ' -30 days'))) or ($_GET["ts1"]<>"" and $_GET["ts2"]<>"") and ($rs["ts1"]>=$_GET["ts1"] and $rs["ts1"]<=$_GET["ts2"])){
										$jsi = json_decode($rs["n17"], true);
										if ($authority==0){
											$yetki=0;
										}else{
											$yetki=1;
										}
										?>
										<tr data-id="<?php echo $rs["id"];?>">
											<td class="mdn mfrm" data-toggle="modal" data-target="#myModal" data-url="modules/clients/client_relation_detail.php?islem=relations&id=<?php echo $rs["id"]?>" data-title="<?php echo $t25s[0];?> <?php echo ctranslate("İlişkileri")?>; <?php echo $rsc["t1"]?>"><?php echo i2a($rs["id"],6)?></td>
											<td class="cp mfrm mtar" data-toggle="modal" data-target="#myModal" data-url="modules/clients/client_relation_detail.php?islem=relations&id=<?php echo $rs["id"]?>" data-title="<?php echo $t25s[0];?> <?php echo ctranslate("İlişkileri")?>; <?php echo $rsc["t1"]?>"><?php if($mobile<>""){echo kisalt($rs["t1"],1);}else{echo $rs["t1"];}?> <?php if($rs["t5"]<>""){?><i class="emojies far fa-<?php echo $rs["t5"];?> v3-text-warning fs19 mfs19 fr mfr"></i><?php }?></td>
											<td class="mdn mw100">
												<?php
												$ps="";
												foreach($products as $key=>$value){
													$ps .=$value["id"]==$rs["s2"] ? "<span class='badge badge-info'>".$value["item"]."</span>" : '';
												}
												echo empty(rtrim($ps, ', ')) ? "..." : rtrim($ps, ', ');
												?>
											</td>
											<td class="mdn">
												<?php
													$s19s="";
													$s19s .= ($rs["s19"] == '0' || in_array('0', multivalues($rs["s19"]))) ? '<span class="badge badge-warning mr1 mmr1">Admin</span>' : '';
													foreach($users as $key=>$value){
														$s19s .= ($value["id"] == $rs["s19"] || in_array($value["id"], multivalues($rs["s19"]))) ? "<span class='badge badge-info mr1 mmr1'>".$value["item"]."</span>" : '';
													}
													echo empty(rtrim($s19s, ', ')) ? "..." : rtrim($s19s, ', ');
												?>
											</td>
											<td class="">
												<?php
													$us="";
													foreach($users as $key=>$value){
														$us .=$value["id"]==$rs["s1"] ? "<span class='badge badge-info'>".$value["item"]."</span>" : '';
													}
													echo empty(rtrim($us, ', ')) ? "..." : rtrim($us, ', ');
												?>
											</td>
											<?php $i=0; $fci="i"; $sqli=mysqli_query($conn, "select * from genel where ne='inputs' $linputs and (t2='All' or t2='".$_SESSION["lang"]."') and (n3='".$_GET["ne"]."' or n3='".$_GET["islem"]."') and n4<>'switch' and n13='list' and s1=0 $luye order by s10,id asc"); while($rsi=mysqli_fetch_assoc($sqli)){$i++;?>
												<td class="mdn"><?php if($rsi["n4"]=="input"){echo $jsi[$fci.$i];}else{echo $jsi[$fci.$i][0];}?></td>
											<?php }?>
											<td class=""><?php echo dtarih($rs["ts1"],"gg ka yyyy time")?></td>
											<td class="">
													<a style="cursor:pointer;" class="btn btn-warning mfrm" data-toggle="modal" data-target="#myModal" data-url="modules/clients/client_relation_detail.php?islem=relations&id=<?php echo $rs["id"]?>" data-title="<?php echo $t25s[0];?> <?php echo ctranslate("İlişkileri")?>; <?php echo $rsc["t1"]?>" href="#"><i class="fa fa-edit" aria-hidden="true"></i></a>
												<?php if ($yetki==0){?>
													<a style="cursor:pointer;" title="<?php echo $sdil[216]; //Yetkili Değilsiniz ??>" class="btn btn-danger btn-ban-row mmt5 mw100 mtac" href="#"><i class="fa fa-lock" aria-hidden="true"></i></a>
												<?php }else{ ?>
													<a style="cursor:pointer;" title="<?php echo $sdil[204]; //Sil?>" class="btn btn-danger btn-delete-row mmt5 mw100 mtac" data-href="?ne=<?php echo $_GET["ne"]?>&islem=<?php echo $_GET["islem"]?>&id=<?php echo $rs["id"]?>&durum=drelations"><i class="fa fa-times" aria-hidden="true"></i></a>
												<?php }?>
											</td>
										</tr>
									<?php }?>
								</tbody>					
							</table>
						</div>
					</section>
				</div>
			</div>
			<!-- end: page -->
		</section>
	</div>
	<aside id="sidebar-right" class="sidebar-right">
		<div class="nano">
			<div class="nano-content">
				<a href="#" class="mobile-close d-md-none">
					Collapse <i class="fa fa-chevron-right"></i>
				</a>
				<div class="sidebar-right-wrapper">
					...
				</div>
			</div>
		</div>
	</aside>
</section>
<?php
if($_GET["durum"]=="drelations"){
	$Rs = mysqli_query($conn, "delete from t1 where id=".$_GET["id"]);

}elseif($_GET["durum"]=="nrelations"){
	$ss19 = implode(',',$_POST["s19"]);
	if(!empty($ss19)){$ss19=$ss19;}else{$ss19="0";}
	if($_POST["s1"]=="0"){
		$sql5k=mysqli_query($conn, "select * from t5 where t4='".$_POST["ut4"]."'"); $rs5k=mysqli_fetch_assoc($sql5k);
		if(mysqli_num_rows($sql5k)==0 and $_POST["ut4"]<>""){
			$sqli5 = $conn->query("insert into t5(t1, t2, ne, s1, s4, s5, s19, t3, t4, t9, ts1) values ('".$_POST["ut1"]."', '".base64_encode($_POST["ut2"])."', 'uye', '0', '1', '0', '".$_SESSION["user_id"]."', '".base64_encode(generatePassword(8))."', '".$_POST["ut4"]."', '".$_POST["ts1"]."', now())");	
			$sql5=mysqli_query($conn, "select * from t5 order by id desc"); $rs5=mysqli_fetch_assoc($sql5);
		}else{
			$sql5=mysqli_query($conn, "select * from t5 where t4='".$_POST["ut4"]."'"); $rs5=mysqli_fetch_assoc($sql5);
		}
	}else{
		$sql5=mysqli_query($conn, "select * from t5 where id='".$_POST["s1"]."'"); $rs5=mysqli_fetch_assoc($sql5);
	}
	$iarr = array();
	foreach ($_POST as $key => $value){
		if(substr($key,0,1)=="i"){
			$iarr = $iarr + array( $key => $value);
		}
	}
	$rjsi = json_encode($iarr, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_NUMERIC_CHECK);
	$sql = $conn->query("insert into t1 (ne,t1,t4,s1,s19,n1,n17,ts1) values ('relations', '".$_POST["t1"]."', '".$_POST["t4"]."', '".$rs5["id"]."', '".$ss19."', '".addslashes(stripslashes($_POST["n1"]))."', '".addslashes(stripslashes($rjsi))."', now())");
	if($_POST["smail"]<>""){
		$mesaj	= "
		<h3>".$_POST["t1"]."</h3>
		<b>".translate("Sayın")." ".$rs5["t1"].";</b><br>".translate("iliski_text")."<hr>
		".$_POST["n1"]."
		";
		$malici	= base64_decode($rs5["t2"]);
		$konu		= $_POST["t1"];
		$path		=	"../";
		$mesaj	= $design_top.$mesaj.$design_bottom;
		emailgonder($malici,$konu,$cc,$mesaj);
	}
	$s1=$rs5["id"];
	$s1name=$rs5["t1"];
	$lt1=$_POST["t1"];
	echo location("?ne=".$_GET["ne"]."&islem=".$_GET["islem"]."&durum=ok",self,500,1);	
}
?>