<?php
header('Content-Type: text/html; charset=utf-8');
error_reporting(0);
$path="../../";
include("../../map.php");
include("../../secure.php");
include("../../scripts.php");
include("../../../deppo/tools/script/cpanel.php");
?>
<!DOCTYPE html>
<html lang="tr">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>Tab ve Ajax Örneği</title>
	<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet">
	<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css" rel="stylesheet">
	<link rel="stylesheet" type="text/css" href="<?php echo $weburl."/".$crmpath?>/assets/css/inmodal.css" />
</head>
<body>
	<div class="" style="padding:15px;">
		<div class="row">
			<!-- Mobilde hamburger menü butonu -->
			<div class="col-12 d-block d-md-none">
				<button class="hamburger-btn" onclick="toggleMenu()">
					<i class="fas fa-bars"></i>
				</button>
			</div>
			<!-- Üst Tab Butonları -->
			<div class="col-12">
				<ul class="nav nav-pills mb-3" id="pills-tab" role="tablist">
					<li class="nav-item" role="presentation">
						<a class="nav-link active" id="pills-tab-1" data-bs-toggle="pill" href="#pills-content-1" role="tab" aria-controls="pills-content-1" aria-selected="true"> Sub Domain(s)</a>
					</li>
					<li class="nav-item" role="presentation">
						<a class="nav-link" id="pills-tab-2" data-bs-toggle="pill" href="#pills-content-2" role="tab" aria-controls="pills-content-2" aria-selected="true"> CronJob(s)</a>
					</li>
					<li class="nav-item" role="presentation">
						<a class="nav-link" id="pills-tab-3" data-bs-toggle="pill" href="#pills-content-3" role="tab" aria-controls="pills-content-3" aria-selected="true"> Mysql(s)</a>
					</li>
					<li class="nav-item" role="presentation" style="float:right;">
						<select id="scron" class="form-control">
							<option value="--">
								-- CronJob Ortak Ayarlar --
							</option>
							<option minute="*" hour="*" day="*" month="*" weekday="*">
								Dakikada Bir Kez(* * * * *)
							</option>
							<option minute="*/5" hour="*" day="*" month="*" weekday="*">
								Beş Dakikada Bir Kez(*/5 * * * *)
							</option>
							<option minute="0,30" hour="*" day="*" month="*" weekday="*">
								Saatte İki Kez(0,30 * * * *)
							</option>
							<option minute="0" hour="*" day="*" month="*" weekday="*">
								Saatte Bir Kez(0 * * * *)
							</option>
							<option minute="0" hour="0,12" day="*" month="*" weekday="*">
								Günde İki Kez(0 0,12 * * *)
							</option>
							<option minute="0" hour="0" day="*" month="*" weekday="*">
								Günde Bir Kez(0 0 * * *)
							</option>
							<option minute="0" hour="0" day="*" month="*" weekday="0">
								Haftada Bir Kez(0 0 * * 0)
							</option>
							<option minute="0" hour="0" day="1,15" month="*" weekday="*">
								Ayın 1’inde ve 15’inde(0 0 1,15 * *)
							</option>
							<option minute="0" hour="0" day="1" month="*" weekday="*">
								Ayda Bir Kez(0 0 1 * *)
							</option>
							<option minute="0" hour="0" day="1" month="1" weekday="*">
								Yılda Bir Kez(0 0 1 1 *)
							</option>
						</select>
					</li>
				</ul>
			</div>
			<!-- İçerik alanı -->
			<div class="col-12">
				<div class="tab-content" id="pills-tabContent">

					<div class="tab-pane show active" id="pills-content-1" role="tabpanel" aria-labelledby="pills-tab-1">
						<form action="?ne=<?php echo $_GET["ne"];?>&islem=<?php echo $_GET["islem"];?>&durum=addsub" method="post">
							<table class="table table-no-more table-bordered table-striped mb-0">
								<tr class="addtr">
									<td><input name="nsubdomain" type="text" class="form-control" value="" Placeholder="Sub Domain"> </td>
									<td><input name="nfolder" type="text" class="form-control" value="" Placeholder="Folder"> </td>
									<td><button class="btn btn-warning mbtn" type="submit"><i class="fa fa-plus"></i><span class="ddn"> <?php echo $sdil[201]; //Ekle?></span></button> </td>
								</tr>
							</form>
							<?php
							$lsd = listsubdomain(tanim("cpanel","n1",0), tanim("cpanel","n2",0), tanim("cpanel","n3",0));
							foreach($lsd['cpanelresult']['data'] as $value) {
								?>
								<tr>
									<td><input name="subdomain" type="text" class="form-control" value="<?php echo $value['domain'];?>"></td>
									<td><input name="folder" type="text" class="form-control" value="<?php echo $value['basedir'];?>"></td>
									<td><a class="btn btn-danger mbtn btn-delete-row" href="?ne=<?php echo $_GET["ne"];?>&islem=<?php echo $_GET["islem"];?>&durum=delsub&subdomain=<?php echo $value['domain'];?>"><i class="fa fa-times "></i><span class="ddn"> <?php echo $sdil[204]; //Kaldir?></span></a></td>
								</tr>
							<?php }?>
						</table>
					</div>

					<div class="tab-pane" id="pills-content-2" role="tabpanel" aria-labelledby="pills-tab-2">
						<form action="?ne=<?php echo $_GET["ne"];?>&islem=<?php echo $_GET["islem"];?>&durum=addcron" method="post">
							<table class="table table-no-more table-bordered table-striped mb-0">
								<tr class="addtr">
									<td>
										<input name="command" list="jlist" id="command" type="text" class="form-control" value="" Placeholder="Command">
										<datalist id="jlist">
											<option value="<?php echo "wget ".$weburl."/cronjob";?> >/dev/null 2>&1"><?php echo "wget ".$weburl."/cronjob >/dev/null 2>&1";?></option>
											<option value="<?php echo "wget ".$weburl."/cronjob";?> >/dev/null 2>&1"><?php echo "wget ".$weburl."/cronjob?islem=birthday >/dev/null 2>&1";?></option>
											<option value="rm /home/<?php echo tanim("cpanel","n1",0);?>/cronjob.*">rm /home/<?php echo tanim("cpanel","n1",0);?>/cronjob.*</option>
										</td>
										<td class="w10"><input name="minute" id="minute" type="text" class="form-control" value="" Placeholder="Minute"> </td>
										<td class="w10"><input name="hour" id="hour" type="text" class="form-control" value="" Placeholder="Hour"> </td>
										<td class="w10"><input name="day" id="day" type="text" class="form-control" value="" Placeholder="Day"> </td>
										<td class="w10"><input name="month" id="month" type="text" class="form-control" value="" Placeholder="Month"> </td>
										<td class="w10"><input name="weekday" id="weekday" type="text" class="form-control" value="" Placeholder="Weekday"> </td>
										<td class="w10"><button class="btn btn-warning mbtn" type="submit"><i class="fa fa-plus"></i><span class="ddn"> <?php echo $sdil[201]; //Ekle?></span></button> </td>
									</tr>
								</form>
							</table>
							<?php
							$result=listcron(tanim("cpanel","n1",0), tanim("cpanel","n2",0), tanim("cpanel","n3",0));
							foreach($result['cpanelresult']['data'] as $value){
								if($value['command']<>""){
									?>
									<form action="?ne=<?php echo $_GET["ne"];?>&islem=<?php echo $_GET["islem"];?>&durum=editcron" method="post">
										<table class="table table-no-more table-bordered table-striped mb-0">
											<input name="linekey" type="hidden" class="form-control" value="<?php echo $value['linekey'];?>" Placeholder="Linekey">
											<tr>
												<td><input name="command" type="text" class="form-control" value='<?php echo $value['command'];?>' Placeholder="command"> </td>
												<td class="w10"><input name="minute" type="text" class="form-control" value="<?php echo $value['minute'];?>" Placeholder="minute"> </td>
												<td class="w10"><input name="hour" type="text" class="form-control" value="<?php echo $value['hour'];?>" Placeholder="hour"> </td>
												<td class="w10"><input name="day" type="text" class="form-control" value="<?php echo $value['day'];?>" Placeholder="Day"> </td>
												<td class="w10"><input name="month" type="text" class="form-control" value="<?php echo $value['month'];?>" Placeholder="month"> </td>
												<td class="w10"><input name="weekday" type="text" class="form-control" value="<?php echo $value['weekday'];?>" Placeholder="weekday"> </td>
												<td class="w10">
													<button class="btn btn-primary mbtn" type="submit"><i class="fa fa-refresh"></i><span class="ddn"> <?php echo $sdil[203]; //Güncelle?></span></button>
													<a class="btn btn-danger mbtn btn-delete-row" href="?ne=<?php echo $_GET["ne"];?>&islem=<?php echo $_GET["islem"];?>&durum=delcron&line=<?php echo $value['count'];?>"><i class="fa fa-times "></i><span class="ddn"> <?php echo $sdil[204]; //Kaldir?></span></a>
												</td>
											</tr>
										</table>
									</form>
								<?php }}?>
							</div>
						</div>
					</div>

					<div class="tab-pane" id="pills-content-3" role="tabpanel" aria-labelledby="pills-tab-3">
						<!-- MYSQL EKLEME FORMU -->
						<form action="?ne=<?php echo $_GET["ne"];?>&islem=<?php echo $_GET["islem"];?>&durum=addsql" method="post">
							<table class="table table-no-more table-bordered table-striped mb-0">
								<tr class="addtr">
									<td><input name="MysqlName" id="MysqlName" type="text" class="form-control" value="" placeholder="Mysql Adı"></td>
									<td class="w10"><input name="MysqlUser" id="MysqlUser" type="text" class="form-control" value="" placeholder="Mysql Kullanıcı"></td>
									<td class="w10"><input name="MysqlPass" id="MysqlPass" type="text" class="form-control" value="" placeholder="Mysql Şifre"></td>
									<td class="w10">
										<button class="btn btn-warning mbtn" type="submit">
											<i class="fa fa-plus"></i>
											<span class="ddn"><?php echo $sdil[201]; // Ekle ?></span>
										</button>
									</td>
								</tr>
							</table>
						</form>

						<?php
						// MYSQL VERİTABANI LİSTELEME
						$result = listmysql(tanim("cpanel", "n1", 0), tanim("cpanel", "n2", 0), tanim("cpanel", "n3", 0));
Print_r($result);
						if (!empty($result['cpanelresult']['data'])) {
							foreach ($result['cpanelresult']['data'] as $index => $value) {
								if (!empty($value['db'])) {
									?>
									<form action="?ne=<?php echo $_GET["ne"];?>&islem=<?php echo $_GET["islem"];?>&durum=editsql" method="post">
										<input type="hidden" name="linekey" value="<?php echo $value['linekey'] ?? $index; ?>">
										<table class="table table-no-more table-bordered table-striped mb-0">
											<tr>
												<td><input name="MysqlName" type="text" class="form-control" value="<?php echo htmlspecialchars($value['db']); ?>" placeholder="Mysql Adı"></td>
												<td class="w10"><input name="MysqlUser" type="text" class="form-control" value="<?php echo htmlspecialchars($value['user'] ?? ''); ?>" placeholder="Mysql Kullanıcı"></td>
												<td class="w10"><input name="MysqlPass" type="text" class="form-control" value="" placeholder="Mysql Şifre (Güncellemek için giriniz)"></td>
												<td class="w10">
													<button class="btn btn-primary mbtn" type="submit">
														<i class="fa fa-refresh"></i>
														<span class="ddn"><?php echo $sdil[203]; // Güncelle ?></span>
													</button>
													<a class="btn btn-danger mbtn btn-delete-row" href="?ne=<?php echo $_GET["ne"];?>&islem=<?php echo $_GET["islem"];?>&durum=delsql&line=<?php echo $index; ?>">
														<i class="fa fa-times"></i>
														<span class="ddn"><?php echo $sdil[204]; // Kaldır ?></span>
													</a>
												</td>
											</tr>
										</table>
									</form>
									<?php
								}
							}
						} else {
							echo "<p>Hiçbir MySQL veritabanı bulunamadı.</p>";
						}
						?>

							</div>
						</div>
					</div>
				</div>
			</div>
			<!-- Bootstrap JS -->
			<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js"></script>
			<script>
				jQuery(document).on('change','#scron',function(e){
					var hour = jQuery('option:selected', this).attr('hour');
					var day = jQuery('option:selected', this).attr('day');
					var minute = jQuery('option:selected', this).attr('minute');
					var month = jQuery('option:selected', this).attr('month');
					var weekday = jQuery('option:selected', this).attr('weekday');
					jQuery('#hour').val(hour);
					jQuery('#day').val(day);
					jQuery('#minute').val(minute);
					jQuery('#month').val(month);
					jQuery('#weekday').val(weekday);
				});
			</script>
			<?php
			if($_GET["durum"]=="addsub"){
				echo $_POST["nsubdomain"];
				$csub = createsubdomain(tanim("cpanel","n1",0), tanim("cpanel","n2",0), tanim("cpanel","n3",0), $_POST["nsubdomain"], $_POST["nfolder"]);
				if($csub=="İşlem Başarılı"){
					$sdomain="".$_POST["nsubdomain"].".".$_SERVER['SERVER_NAME']."";
		//$sql = $conn->query("insert into genel(t2,ne,n1,n2,n3,n4,s10) VALUES ('domain', 'tanim', '".v3e($sdomain)."', '', '', '', '0')");
					echo location("?ne=".$_GET["ne"]."&islem=".$_GET["islem"]."&durum=ok",self,1000,1);
				}else{
					echo location("?ne=".$_GET["ne"]."&islem=".$_GET["islem"]."&durum=err&err=".$csub."",self,1000,1);
				}

			}elseif($_GET["durum"]=="delsub"){
				$dsub = delsubdomain(tanim("cpanel","n1",0), tanim("cpanel","n2",0), tanim("cpanel","n3",0), $_GET["subdomain"]);
				if($dsub=="İşlem Başarılı"){
					echo location("?ne=".$_GET["ne"]."&islem=".$_GET["islem"]."&durum=ok",self,1000,1);
				}else{
					echo location("?ne=".$_GET["ne"]."&islem=".$_GET["islem"]."&durum=err&err=".$dsub."",self,1000,1);
				}

			}elseif($_GET["durum"]=="addcron"){
				$acron = addcron(tanim("cpanel","n1",0), tanim("cpanel","n2",0), tanim("cpanel","n3",0),$_POST["command"],$_POST["minute"],$_POST["hour"],$_POST["day"],$_POST["month"],$_POST["weekday"]);
				if($acron=="İşlem Başarılı"){
					echo location("?ne=".$_GET["ne"]."&islem=".$_GET["islem"]."&durum=ok#&pills-tab-2",self,1000,1);
				}else{
					echo location("?ne=".$_GET["ne"]."&islem=".$_GET["islem"]."&durum=err&err=".$acron."#&pills-tab-2",self,1000,1);
				}

			}elseif($_GET["durum"]=="editcron"){
				$ecron = editcron(tanim("cpanel","n1",0), tanim("cpanel","n2",0), tanim("cpanel","n3",0),$_POST["command"],$_POST["linekey"],$_POST["minute"],$_POST["hour"],$_POST["day"],$_POST["month"],$_POST["weekday"]);
				if($ecron=="İşlem Başarılı"){
					echo location("?ne=".$_GET["ne"]."&islem=".$_GET["islem"]."&durum=ok#&pills-tab-2",self,1000,1);
				}else{
					echo location("?ne=".$_GET["ne"]."&islem=".$_GET["islem"]."&durum=err&err=".$ecron."#&pills-tab-2",self,1000,1);
				}
				
			}elseif($_GET["durum"]=="delcron"){
				$dcron = delcron(tanim("cpanel","n1",0), tanim("cpanel","n2",0), tanim("cpanel","n3",0),$_GET["line"]);
				if($dcron=="İşlem Başarılı"){
					echo location("?ne=".$_GET["ne"]."&islem=".$_GET["islem"]."&durum=ok#&pills-tab-2",self,1000,1);
				}else{
					echo location("?ne=".$_GET["ne"]."&islem=".$_GET["islem"]."&durum=err&err=".$dcron."#&pills-tab-2",self,1000,1);
				}
			}
			?>
		</body>
		</html>