<?php

require "mp-content/init.php";
$response = new \stdClass();


if (isset($_GET["action"]) && get("action") != null) {
	$action = get("action");

	if ($action == "login") {


		if (!login_control()) {
			$posts = [
				"username" => true,
				"password" => true
			];
			$error = false;
			foreach ($posts as $post => $required) {
				if ($required) {
					if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
						$$post = filter($_POST[$post]);
					} else {
						$error = true;
						break;
					}
				} else {
					if (isset($_POST[$post])) {
						$$post = filter($_POST[$post]);
					} else {
						$error = true;
						break;
					}
				}
			}
			if (!$error) {
				$do = true;
				$dcq = $db->from('integrations')->where('app_id', 1)->first();
				$recaptcha = json_decode($dcq['app_data'], true);
				if ($recaptcha["login_page"]) {
					if (isset($_POST["g-recaptcha-response"]) && $_POST["g-recaptcha-response"] != null) {
						$captcha = $_POST['g-recaptcha-response'];
						$control = json_decode(file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=" . $recaptcha["secret_key"] . "&response=" . $captcha . "&remoteip=" . $_SERVER['REMOTE_ADDR']));
						if ($control->success != true) {
							$do = false;
						}
					} else {
						$do = false;
					}
				}
				if ($do) {
					$query = $db->prepare("SELECT * FROM users WHERE user_username = ?");
					$query->execute(array(
						$username
					));
					if ($query->rowCount()) {
						$user = $query->fetch(PDO::FETCH_ASSOC);
						if (password_verify($password, $user["user_password"])) {
							if ($user["user_status"] != 0) {
								$ip = $_SERVER['REMOTE_ADDR'];
								insert_log($db, $user["user_id"], $ip, "Giriş yapıldı.");
								session("login", true);
								session("user_id", $user["user_id"]);
								session("user_permissions", $user["user_perms"]);

								if (isset($_POST['benihatirla'])) {
									if ($_POST['benihatirla'] == 'on') {

										$oturumveri = array('username' => $username, 'password' => $password);
										cookie('oturum', base64_encode(json_encode($oturumveri)));
									}
								}

								$response->reload = true;
							} else {
								$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
							}
						} else {
							$response->error = "{LOGIN_MESSAGE_WRONG_PASSWORD}";
						}
					} else {
						$response->error = "{LOGIN_MESSAGE_WRONG_USERNAME}";
					}
				} else {
					$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
				}
			} else {
				$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "skypeverify") {
		if (login_control()) {
			$provider = $db->from('settings')->where('id', 1)->first();
			$code = rand(111111, 999999);
			$userguncel = $db->update('users')->where('user_id', $user_id)
				->set(array(
					'user_verify_code' => $code
				));
			$skype = filter($_POST['skype_onay']);
			if (send_sms("1", $provider['sms_provider'], $skype, $code)) {

				$html = '<form id="sms_onay" onsubmit="return false;" data-reset="0">
				<input type="text" name="sms_kod" class="form-control" name=""placeholder="Telefonunuza gelen doğrulama kodu">
				<button type="submit" class="btn btn-success">Kodu Gönder</button>
			</form>';
				$response->verify = $html;
			} else {
				$response->error = "Doğrulama Kodu Gönderilemedi!";
			}
		}
	} elseif ($action == "sms_onay") {
		if (login_control()) {
			$kod = $user['user_verify_code'];
			$gelen = filter($_POST['sms_kod']);
			if ($kod == $gelen) {
				$durum = json_decode($user['user_verify'], true);
				$durum['skype'] = 1;
				$durum = json_encode($durum);

				$userguncel = $db->update('users')->where('user_id', $user_id)
					->set(array(
						'user_verify' => $durum,
						'user_verify_code' => ""
					));
				$response->reload = true;
			} else {
				$response->error = "Doğrulama Kodu Yanlış!";
			}
		}
	} elseif ($action == "mailverify") {
		if (login_control()) {
			$code = rand(111111, 999999);
			$userguncel = $db->update('users')->where('user_id', $user_id)
				->set(array(
					'user_verify_code' => $code
				));
			$mail = filter($_POST['mail_onay']);
			$sendmail = send_email($user["user_email"], $user["user_first_name"], "Email Onaylama", "Mail Adresinizi Onaylamak İçin Gerekli Kod: " . $code);
			if ($sendmail == "Parola sıfırlama bağlantınız, mail adresinize gönderilmiştir.") {
				$html = '<form id="mail_onay" onsubmit="return false;" data-reset="0">
						<input type="text" name="mail_kod" class="form-control" name=""placeholder="Mailinize gelen doğrulama kodu">
						<button type="submit" class="btn btn-success">Kodu Gönder</button>
						</form>';
				$response->verify = $html;
			} else {
				$response->error = "Sistem hatası nedeniyle şifre sıfırlama maili gönderilemedi.";
			}
		}
	} elseif ($action == 'mail_onay') {
		if (login_control()) {
			$kod = $user['user_verify_code'];
			$gelen = filter($_POST['mail_kod']);
			if ($kod == $gelen) {
				$durum = json_decode($user['user_verify'], true);
				$durum['email'] = 1;
				$durum = json_encode($durum);

				$userguncel = $db->update('users')->where('user_id', $user_id)
					->set(array(
						'user_verify' => $durum,
						'user_verify_code' => ""
					));
				$response->reload = true;
			} else {
				$response->error = "Doğrulama Kodu Yanlış!";
			}
		}
	} elseif ($action == "register") {
		if (!login_control()) {
			$posts = [
				"email" => true,
				"username" => true,
				"password" => true,
				"re_password" => true,
				"first_name" => true,
				"last_name" => true,
				"skype" => false
			];
			$error = false;
			foreach ($posts as $post => $required) {
				if ($required) {
					if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
						$$post = filter($_POST[$post]);
					} else {
						$error = true;
						break;
					}
				} else {
					if (isset($_POST[$post])) {
						$$post = filter($_POST[$post]);
					} else {
						$error = true;
						break;
					}
				}
			}
			if (!$error) {
				$do = true;
				$dcq = $db->from('integrations')->where('app_id', 1)->first();
				$recaptcha = json_decode($dcq['app_data'], true);
				if ($recaptcha["register_page"]) {
					if (isset($_POST["g-recaptcha-response"]) && $_POST["g-recaptcha-response"] != null) {
						$captcha = $_POST['g-recaptcha-response'];
						$control = json_decode(file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=" . $recaptcha["secret_key"] . "&response=" . $captcha . "&remoteip=" . $_SERVER['REMOTE_ADDR']));
						if ($control->success != true) {
							$do = false;
						}
					} else {
						$do = false;
					}
				}
				if ($do) {
					if (strlen($username) <= 40) {
						if ($password == $re_password) {
							$query = $db->prepare("SELECT * FROM users WHERE user_email = ?");
							$query->execute(array(
								$email
							));
							if (!$query->rowCount()) {
								$query = $db->prepare("SELECT * FROM users WHERE user_username = ?");
								$query->execute(array(
									$username
								));
								if (!$query->rowCount()) {
									$query = $db->prepare("SELECT * FROM users WHERE user_skype = ?");
									$query->execute(array(
										$skype
									));
									if ($skype == "" || !$query->rowCount()) {
										$key = "";
										do {
											$key = md5(rand(0, 99999) . rand(0, 99999) . rand(0, 99999) . rand(0, 99999));
											$query = $db->prepare("SELECT * FROM users WHERE user_key = ?");
											$query->execute([$key]);
										} while ($query->rowCount());
										$password = password_hash($password, PASSWORD_DEFAULT);
										$verify = json_encode(array("email" => 0, "skype" => 0));
										$now = time();
										$query = $db->prepare("INSERT INTO users SET user_email = ?, user_username = ?, user_password = ?, user_first_name = ?, user_last_name = ?, user_skype = ?, user_key = ?, user_verify=?, user_perms = ?, reg_date = $now, last_date = $now");
										$insert_user = $query->execute([$email, strtolower($username), $password, $first_name, $last_name, ($skype != "" ? $skype : null), $key, $verify, 0]);
										if ($insert_user) {

											$user_id = $db->lastInsertId();



											$ip = $_SERVER['REMOTE_ADDR'];
											insert_log($db, $user_id, $ip, "Kayıt olundu.");

											if (REFERENCE_STATUS) {
												if (session("r")) {
													$query = $db->prepare("SELECT * FROM `users` WHERE user_id = ?");
													$query->execute([session("r")]);
													if ($query->rowCount()) {
														$query = $db->prepare("INSERT INTO `user_references` SET user_id = ?, reference_user_id = ?");
														$insert_reference = $query->execute([$user_id, session("r")]);
													}
													unset($_SESSION["r"]);
												}
											}


											if (PLUGIN_GIFTBALANCE_STATUS) {

												$addbalance = $db->update('users')->where('user_id', $user_id)
													->set(array(
														'user_balance' => PLUGIN_GIFTBALANCE_AMOUNT
													));
											}

											session("login", true);
											session("user_id", $user_id);
											$response->reload = true;

											if ($settings['discord_notify_url']) {
												discord_api(2, "```##Yeni Üye Kaydı##```\n**• Kullanıcı Adı:** " . $username . "\n**• Kayıt Tarihi:** " . date('d.m.Y H:i:s'));
											}
										} else {
											$response->error = "{MESSAGE_TECHNICAL_ERROR}";
										}
									} else {
										$response->error = "{REGISTER_MESSAGE_TAKEN_SKYPE}";
									}
								} else {
									$response->error = "{REGISTER_MESSAGE_TAKEN_USERNAME}";
								}
							} else {
								$response->error = "{REGISTER_MESSAGE_TAKEN_EMAIL}";
							}
						} else {
							$response->error = "{REGISTER_MESSAGE_PASSWORD_DONT_MATCH}";
						}
					} else {
						$response->error = "{REGISTER_MESSAGE_TOO_LONG_USERNAME}";
					}
				} else {
					$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
				}
			} else {
				$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "update_password") {
		if (login_control()) {
			$posts = [
				"password" => true,
				"new_password" => true,
				"re_new_password" => true
			];
			$error = false;
			foreach ($posts as $post => $required) {
				if ($required) {
					if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
						$$post = filter($_POST[$post]);
					} else {
						$error = true;
						break;
					}
				} else {
					if (isset($_POST[$post])) {
						$$post = filter($_POST[$post]);
					} else {
						$error = true;
						break;
					}
				}
			}
			if (!$error) {
				if (password_verify($password, $user["user_password"])) {
					if ($new_password == $re_new_password) {
						$password = password_hash($new_password, PASSWORD_DEFAULT);
						$query = $db->prepare("UPDATE `users` SET user_password = ? WHERE user_id = ?");
						$update_password = $query->execute([$password, $user["user_id"]]);
						if ($update_password) {
							$ip = $_SERVER['REMOTE_ADDR'];
							insert_log($db, $user["user_id"], $ip, "Parola değiştirildi.");
							$response->success = "{UPDATE_PASSWORD_MESSAGE_SUCCESS}";
						} else {
							$response->error = "{TECHNICAL_FAILURE}";
						}
					} else {
						$response->error = "{UPDATE_PASSWORD_MESSAGE_DONT_MATCH}";
					}
				} else {
					$response->error = "{UPDATE_PASSWORD_MESSAGE_WRONG_PASSWORD}";
				}
			} else {
				$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "new_key") {
		if (login_control()) {
			$key = "";
			do {
				$key = md5(rand(0, 99999) . rand(0, 99999) . rand(0, 99999) . rand(0, 99999));
				$query = $db->prepare("SELECT * FROM users WHERE user_key = ?");
				$query->execute([$key]);
			} while ($query->rowCount());
			$query = $db->prepare("UPDATE `users` SET user_key = ? WHERE user_id = ?");
			$update_key = $query->execute([$key, $user["user_id"]]);
			if ($update_key) {
				$ip = $_SERVER['REMOTE_ADDR'];
				insert_log($db, $user["user_id"], $ip, "API key değiştirildi.");
				$response->edit = true;
				$response->type = "value";
				$response->item = "#key";
				$response->text = $key;
			} else {
				$response->error = "{TECHNICAL_FAILURE}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "customer_cancel_order") {
		if (login_control()) {

			$id = htmlspecialchars($_POST['id']);

			$order = $db->from('orders')
				->join('services', 'services.service_id = orders.service_id')
				->where('orders.order_id', $id)
				->first();

			if ($order) {

				if ($order['cancel_button'] == 1) {

					$tasks = $db->from('tasks')
						->where('user_id', session('user_id'))
						->where('order_id', $id)
						->where('task_type', 2)
						->first();

					if ($tasks) {

						if ($tasks['task_status'] == 0) {

							$response->error = "Bu sipariş için zaten iptal işlemi başlatmışsınız, bir yöneticinin onay vermesini bekleyiniz.";
						} else {

							$newTask = $db->insert('tasks')
								->set(array(
									'order_id' => $id,
									'user_id' => session('user_id'),
									'task_type' => 2,
									'task_status' => 0
								));

							if ($newTask) {
								$response->reload = true;
							} else {
								$response->error = "İşleminiz gerçekleştirilemedi, daha sonra tekrar deneyiniz.";
							}
						}
					} else {

						$newTask = $db->insert('tasks')
							->set(array(
								'order_id' => $id,
								'user_id' => session('user_id'),
								'task_type' => 2,
								'task_status' => 0
							));

						if ($newTask) {
							$response->reload = true;
						} else {
							$response->error = "İşleminiz gerçekleştirilemedi, daha sonra tekrar deneyiniz.";
						}
					}
				} else {

					$response->error = "Bu sipariş için iptal butonu aktif değil.";
				}
			} else {

				$response->error = "İşleminiz gerçekleştirilemedi, daha sonra tekrar deneyiniz.";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "refill_order") {
		if (login_control()) {

			$id = htmlspecialchars($_POST['id']);

			$order = $db->from('orders')
				->join('services', 'services.service_id = orders.service_id')
				->where('orders.order_id', $id)
				->first();

			if ($order) {

				if ($order['refill_button'] == 1) {

					$tasks = $db->from('tasks')
						->where('user_id', session('user_id'))
						->where('order_id', $id)
						->where('task_type', 1)
						->first();

					if ($tasks) {

						if ($tasks['task_status'] == 0) {

							$response->error = "Bu sipariş için zaten telafi işlemi başlatmışsınız.";
						} else {

							if ($order['refill_type'] == 2) {

								$siparis = $db->from('orders')->where('order_id', $order['order_id'])->first();
								$apiss = $db->from('apis')->where('api_id', $siparis['api_id'])->first();

								if ($apiss) {

									$sendApi = create_refill($apiss['api_url'], $apiss['api_key'], $order['api_order_id']);

									if ($sendApi) {

										$newTask = $db->insert('tasks')
											->set(array(
												'order_id' => $id,
												'user_id' => session('user_id'),
												'task_type' => 1,
												'task_status' => 0
											));

										if ($newTask) {
											$response->success = "Refill isteğiniz sağlayıcıya iletilmiştir.";
										} else {
											$response->error = "İşleminiz gerçekleştirilemedi, daha sonra tekrar deneyiniz.";
										}
									} else {

										$response->error = "Refill isteğiniz sağlayıcıya iletilemedi.";
									}
								} else {

									$response->error = "Refill isteğiniz gerçekleştirilemedi.";
								}
							} else {

								$newTask = $db->insert('tasks')
									->set(array(
										'order_id' => $id,
										'user_id' => session('user_id'),
										'task_type' => 1,
										'task_status' => 0
									));

								if ($newTask) {
									$response->success = "Refill isteğiniz sağlayıcıya iletilmiştir.";
								} else {
									$response->error = "İşleminiz gerçekleştirilemedi, daha sonra tekrar deneyiniz.";
								}
							}
						}
					} else {

						if ($order['refill_type'] == 2) {

							$siparis = $db->from('orders')->where('order_id', $order['order_id'])->first();
							$apiss = $db->from('apis')->where('api_id', $siparis['api_id'])->first();

							if ($apiss) {

								$sendApi = create_refill($apiss['api_url'], $apiss['api_key'], $order['api_order_id']);

								if ($sendApi) {

									$newTask = $db->insert('tasks')
										->set(array(
											'order_id' => $id,
											'user_id' => session('user_id'),
											'task_type' => 1,
											'task_status' => 0
										));

									if ($newTask) {
										$response->success = "Refill isteğiniz sağlayıcıya iletilmiştir.";
									} else {
										$response->error = "İşleminiz gerçekleştirilemedi, daha sonra tekrar deneyiniz.";
									}
								} else {

									$response->error = "Refill isteğiniz sağlayıcıya iletilemedi.";
								}
							} else {

								$response->error = "Refill isteğiniz gerçekleştirilemedi.";
							}
						} else {

							$newTask = $db->insert('tasks')
								->set(array(
									'order_id' => $id,
									'user_id' => session('user_id'),
									'task_type' => 1,
									'task_status' => 0
								));

							if ($newTask) {
								$response->success = "Refill isteğiniz sağlayıcıya iletilmiştir.";
							} else {
								$response->error = "İşleminiz gerçekleştirilemedi, daha sonra tekrar deneyiniz.";
							}
						}
					}
				} else {

					$response->error = "Bu sipariş için iptal butonu aktif değil.";
				}
			} else {

				$response->error = "İşleminiz gerçekleştirilemedi, daha sonra tekrar deneyiniz.";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "get_services") {
		if (isset($_POST["categories"])) {
			$categories = post("categories");
			$extracted_services = [];
			$extraSql = "service_auto = 0";
			if (strstr($_SERVER["HTTP_REFERER"], "auto")) {
				$extraSql = "service_auto = 1";
			}
			foreach ($categories as $category) {
				$query = $db->prepare("SELECT * FROM `services` WHERE category_id = ? AND service_status = 1 AND $extraSql ORDER BY service_number ASC, service_number DESC");
				$query->execute([
					$category
				]);
				if ($query->rowCount()) {
					$services = $query->fetchAll(PDO::FETCH_ASSOC);
					foreach ($services as $service) {
						$service_name = json_decode($service["service_name"], true);
						$service_desc = json_decode($service["service_desc"], true);
						$name = null;
						$desc = null;
						foreach ($service_name as $details) {
							if ($details["lang"] == 1) {
								$name = $details["name"];
							}
							if ($details["lang"] == $lang) {
								$name = $details["name"];
								break;
							}
						}
						foreach ($service_desc as $details) {
							if ($details["lang"] == 1) {
								$desc = $details["name"];
							}
							if ($details["lang"] == $lang) {
								$desc = $details["name"];
								break;
							}
						}
						$extracted_services[$category][] = [
							"id" => $service["service_id"],
							"name" => $name . " -- " . CURRENCY_SYMBOL . offer($service),
							"desc" => htmlspecialchars_decode($desc),
							"charge" => offer($service),
							"min" => $service["service_min"],
							"max" => $service["service_max"],
							"auto" => $service["service_auto"],
							"drip" => $service["service_drip"],
							"package" => $service["service_package"],
							"comment" => $service["service_comment"]
						];
					}
				}
			}
			$response->services = json_encode($extracted_services);
			$response->status = true;
		} else {
			$response->status = false;
		}
	} elseif ($action == "calculate") {
		if (login_control()) {
			$posts = [
				"charge" => true,
				"quantity" => true,
				"package" => true,
				"runs" => false
			];
			$error = false;
			foreach ($posts as $post => $required) {
				if ($required) {
					if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
						$$post = filter($_POST[$post]);
					} else {
						$error = true;
						break;
					}
				} else {
					if (isset($_POST[$post])) {
						$$post = filter($_POST[$post]);
					} else {
						$error = true;
						break;
					}
				}
			}
			if (!$error) {
				if ($runs != null) {
					$response->total_quantity = $quantity * $runs;
					if ($package == 1) {
						$response->amount = CURRENCY_SYMBOL . ($charge * $runs);
					} else {
						$response->amount = CURRENCY_SYMBOL . ((($charge / 1000) * $quantity) * $runs);
					}
				} else {
					if ($package == 1) {
						$response->amount = CURRENCY_SYMBOL . $charge;
					} else {
						$response->amount = CURRENCY_SYMBOL . (($charge / 1000) * $quantity);
					}
				}
				$response->status = true;
			} else {
				$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "new_order") {
		if (login_control()) {
			$posts = [
				"service" => true,
				"link" => true,
				"quantity" => true,
				"comments" => false,
				"runs" => false,
				"interval" => false
			];
			$error = false;
			foreach ($posts as $post => $required) {
				if ($required) {
					if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
						$$post = filter($_POST[$post]);
					} else {
						$error = true;
						break;
					}
				} else {
					if (isset($_POST[$post])) {
						$$post = filter($_POST[$post]);
					} else {
						$error = true;
						break;
					}
				}
			}
			if (!$error) {
				$query = $db->prepare("SELECT * FROM `services` WHERE service_id = ? AND service_status = 1 AND service_auto = 0");
				$query->execute([$service]);
				if ($query->rowCount()) {
					$service = $query->fetch(PDO::FETCH_ASSOC);
					if ($service["service_comment"] == 1) {
						if ($comments != null) {
							$count = count(explode("\n", $comments));
							$quantity = $count;
						}
					}
					if (is_numeric($quantity) && $quantity >= $service["service_min"] && $quantity <= $service["service_max"]) {
						$charge = offer($service);
						if ($service["service_drip"] == 1 && $runs != null && $interval != null && $runs > 1 && $interval >= 0 && $interval <= 30 && $interval % 5 == 0 && is_numeric($interval) && is_numeric($runs)) {
							$amount = (($charge / 1000) * $quantity) * $runs;
							if ($service["service_package"] == 1) {
								$amount = $charge * $runs;
								$quantity = 1;
							}
							if ($user["user_balance"] >= $amount) {
								$order = add_order($service, session("user_id"), $link, $quantity, $amount, $comments, $runs, $interval);

								if ($order) {
									$ip = $_SERVER['REMOTE_ADDR'];
									insert_log($db, $user["user_id"], $ip, "Süreli sipariş verildi.");
									$new_balance = $user["user_balance"] - $amount;
									$query = $db->prepare("UPDATE `users` SET user_balance = ? WHERE user_id = ?");
									$update_user = $query->execute([$new_balance, session("user_id")]);
									$response->success = "Siparişiniz Oluşturuldu - Sipariş Ücreti: " . $amount . " - Güncel Bakiye: " . $new_balance;
									$response->balance = $new_balance;
									if ($settings['discord_notify_url']) {
										discord_api(2, "```##Yeni Sipariş##```\n**• Sipariş Ücreti:** " . $amount . "\n**• Sipariş Veren Müşteri:** " . $user["user_username"] . "\n**• Sipariş URL:** " . $link . "\n**• Sipariş Miktarı:** " . $quantity . "\n**• Servis Tipi:** Süreli Sipariş\n**• Sipariş Tarihi:** " . date('d.m.Y H:i:s'));
									}
								} else {
									$ip = $_SERVER['REMOTE_ADDR'];
									insert_log($db, $user["user_id"], $ip, "Süreli sipariş verildi.");
									$new_balance = $user["user_balance"] - $amount;
									$query = $db->prepare("UPDATE `users` SET user_balance = ? WHERE user_id = ?");
									$update_user = $query->execute([$new_balance, session("user_id")]);
									$response->success = "Siparişiniz Oluşturuldu - Sipariş Ücreti: " . $amount . " - Güncel Bakiye: " . $new_balance;
									$response->balance = $new_balance;
									if ($settings['discord_notify_url']) {
										discord_api(2, "```##Yeni Sipariş##```\n**• Sipariş Ücreti:** " . $amount . "\n**• Sipariş Veren Müşteri:** " . $user["user_username"] . "\n**• Sipariş URL:** " . $link . "\n**• Sipariş Miktarı:** " . $quantity . "\n**• Servis Tipi:** Süreli Sipariş\n**• Sipariş Tarihi:** " . date('d.m.Y H:i:s'));
									}
								}
							} else {
								$response->error = "{INSUFFICIENT_BALANCE}";
							}
						} else {
							$amount = (($charge / 1000) * $quantity);
							if ($service["service_package"] == 1) {
								$amount = $charge;
								$quantity = 1;
							}
							if ($user["user_balance"] >= $amount) {
								$order = add_order($service, session("user_id"), $link, $quantity, $amount, $comments);


								if ($order) {
									$ip = $_SERVER['REMOTE_ADDR'];
									insert_log($db, $user["user_id"], $ip, "Sipariş verildi. <a href='/admin/orders?search=" . $order . "&search_type=id'>İncele</a> Ücret: $amount" . CURRENCY_SYMBOL);
									$new_balance = $user["user_balance"] - $amount;
									$query = $db->prepare("UPDATE `users` SET user_balance = ? WHERE user_id = ?");
									$update_user = $query->execute([$new_balance, session("user_id")]);
									$response->success = "Siparişiniz Oluşturuldu - Sipariş Ücreti: " . $amount . " - Güncel Bakiye: " . $new_balance;
									$response->balance = $new_balance;
									if ($settings['discord_notify_url']) {
										discord_api(2, "```##Yeni Sipariş##```\n**• Sipariş Ücreti:** " . $amount . "\n**• Sipariş Veren Müşteri:** " . $user["user_username"] . "\n**• Sipariş URL:** " . $link . "\n**• Sipariş Miktarı:** " . $quantity . "\n**• Servis Tipi:** Normal Sipariş\n**• Sipariş Tarihi:** " . date('d.m.Y H:i:s'));
									}
								} else {

									$ip = $_SERVER['REMOTE_ADDR'];
									insert_log($db, $user["user_id"], $ip, "Sipariş verildi. <a href='/admin/orders?search=" . $order . "&search_type=id'>İncele</a> Ücret: $amount" . CURRENCY_SYMBOL);
									$new_balance = $user["user_balance"] - $amount;
									$query = $db->prepare("UPDATE `users` SET user_balance = ? WHERE user_id = ?");
									$update_user = $query->execute([$new_balance, session("user_id")]);
									$response->success = "Siparişiniz Oluşturuldu - Sipariş Ücreti: " . $amount . " - Güncel Bakiye: " . $new_balance;
									$response->balance = $new_balance;
									if ($settings['discord_notify_url']) {
										discord_api(2, "```##Yeni Sipariş##```\n**• Sipariş Ücreti:** " . $amount . "\n**• Sipariş Veren Müşteri:** " . $user["user_username"] . "\n**• Sipariş URL:** " . $link . "\n**• Sipariş Miktarı:** " . $quantity . "\n**• Servis Tipi:** Normal Sipariş\n**• Sipariş Tarihi:** " . date('d.m.Y H:i:s'));
									}
								}
							} else {
								$response->error = "{INSUFFICIENT_BALANCE}";
							}
						}
					} else {
						$response->error = "{ORDER_MESSAGE_QUANTITY}";
					}
				} else {
					$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
				}
			} else {
				$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "child_order") {
		if (login_control()) {
			$posts = [
				"domain" => true,
				"currency" => true,
				"username" => true,
				"password" => true
			];
			$error = false;
			foreach ($posts as $post => $required) {
				if ($required) {
					if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
						$$post = filter($_POST[$post]);
					} else {
						$error = true;
						break;
					}
				} else {
					if (isset($_POST[$post])) {
						$$post = filter($_POST[$post]);
					} else {
						$error = true;
						break;
					}
				}
			}
			if (!$error) {

				if (checkdnsrr($domain, 'ANY')) {

					if ($user['user_balance'] >= $cp->price) {

						$order = NewChildPanel($user['user_id'], $domain, $username, $password, $currency);


						if ($order) {

							$response->reload = true;
						} else {
							$response->error = "Bir hata oluştu lütfen daha sonra tekrar deneyiniz.";
						}
					} else {
						$response->error = "Bakiyeniz yetersiz.";
					}
				} else {
					$response->error = "Lütfen geçerli ve kayıt edilmiş bir domain adresi giriniz.";
				}
			} else {
				$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "auto_order") {
		if (login_control()) {
			$posts = [
				"service" => true,
				"link" => true,
				"quantity" => true,
				"limit" => false,
				"expiration" => false
			];
			$error = false;
			foreach ($posts as $post => $required) {
				if ($required) {
					if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
						$$post = filter($_POST[$post]);
					} else {
						$error = true;
						break;
					}
				} else {
					if (isset($_POST[$post])) {
						$$post = filter($_POST[$post]);
					} else {
						$error = true;
						break;
					}
				}
			}
			if (!$error) {
				$query = $db->prepare("SELECT * FROM `services` WHERE service_id = ?");
				$query->execute([$service]);
				if ($query->rowCount()) {
					$service = $query->fetch(PDO::FETCH_ASSOC);
					if ($service["service_auto"]) {
						if (is_numeric($quantity) && $quantity >= $service["service_min"] && $quantity <= $service["service_max"]) {
							if ($expiration != null) {
								$expiration = strtotime($expiration);
							}
							if ($limit == null || (is_numeric($limit) && $limit > 0)) {

								$qweasfqwr			= ProxyOtoSiparis($link);

								if ($qweasfqwr) {

									$photoCount		=  $qweasfqwr['data']['user']["edge_owner_to_timeline_media"]["count"];
									$photos    		=  $qweasfqwr['data']['user']["edge_owner_to_timeline_media"]["edges"];

									if ($photos) {

										$types = $photos[0]['node']['__typename'];
										$photoids = $photos[0]['node']['shortcode'];
									} else {

										$types = null;
										$photoids = null;
									}
								} else {

									$photoCount		= null;
									$photoids    		=  null;
								}

								$insert_auto = $db->insert('auto_orders')
									->set(array(
										'user_id' => session('user_id'),
										'service_id' => $service['service_id'],
										'last_post' => $photoids,
										'auto_date' => time(),
										'auto_link' => $link,
										'auto_quantity' => $quantity,
										'auto_limit' => ($limit == null) ? null : $limit,
										'auto_expiration' => $expiration
									));

								if ($insert_auto) {
									$ip = $_SERVER['REMOTE_ADDR'];
									insert_log($db, $user["user_id"], $ip, "Otomatik sipariş oluşturuldu.");
									$response->success = "{AUTO_MESSAGE_SUCCESS}";
								} else {
									$response->error = "{TECHNICAL_FAILURE}";
								}
							}
						} else {
							$response->error = "{ORDER_MESSAGE_QUANTITY}";
						}
					} else {
						$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
					}
				} else {
					$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
				}
			} else {
				$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "stop_auto") {
		if (login_control()) {
			$posts = [
				"id" => true
			];
			$error = false;
			foreach ($posts as $post => $required) {
				if ($required) {
					if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
						$$post = filter($_POST[$post]);
					} else {
						$error = true;
						break;
					}
				} else {
					if (isset($_POST[$post])) {
						$$post = filter($_POST[$post]);
					} else {
						$error = true;
						break;
					}
				}
			}
			if (!$error) {
				$query = $db->prepare("SELECT * FROM `auto_orders` WHERE auto_id = ? AND user_id = ? AND auto_status = 1");
				$query->execute([$id, session("user_id")]);
				if ($query->rowCount()) {
					$query = $db->prepare("UPDATE `auto_orders` SET auto_status = 2 WHERE auto_id = ?");
					$update_auto = $query->execute([$id]);
					if ($update_auto) {
						$ip = $_SERVER['REMOTE_ADDR'];
						insert_log($db, $user["user_id"], $ip, "Otomatik sipariş durduruldu.");
						$response->success = "{AUTO_UPDATE_SUCCESS_MESSAGE}";
						$response->content_status = '<span class="badge badge-danger">{AUTO_STATUS_CANCELED}</span>';
						$response->content_edit = "-";
					} else {
						$response->error = "{TECHNICAL_FAILURE}";
					}
				} else {
					$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
				}
			} else {
				$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "create_ticket") {
		if (login_control()) {
			$posts = [
				"title" => true,
				"message" => true
			];
			$error = false;
			foreach ($posts as $post => $required) {
				if ($required) {
					if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
						$$post = filter($_POST[$post]);
					} else {
						$error = true;
						break;
					}
				} else {
					if (isset($_POST[$post])) {
						$$post = filter($_POST[$post]);
					} else {
						$error = true;
						break;
					}
				}
			}
			if (!$error) {
				$db->beginTransaction();

				$userQuery = $db->from('users')->where('user_id', session('user_id'))->first();
				if ($userQuery) {

					if (TICKET_LIMIT != 0) {

						$userTickets = $db->from('tickets')->where('user_id', session('user_id'))->where('ticket_status', 1)->all();

						if (count($userTickets) > TICKET_LIMIT) {
							$response->error = "Maksimum talep sınırına ulaştınız, lütfen aktif taleplerinizin sonuçlanmasını bekleyiniz.";
						} else {

							$insert_ticket = $db->insert('tickets')
								->set(array(
									'user_id' => session('user_id'),
									'ticket_title' => $title
								));

							$ticket_id = $db->lastInsertId();
							$time = time();

							$insert_message = $db->insert('ticket_messages')
								->set(array(
									'ticket_id' => $ticket_id,
									'message_author' => 1,
									'message_text' => $message,
									'message_time' => $time
								));

							if ($insert_ticket && $insert_message) {

								$ip = $_SERVER['REMOTE_ADDR'];
								insert_log($db, $user["user_id"], $ip, "Destek talebi oluşturuldu. <a href='/admin/support/$ticket_id'>Oku</a>");
								$db->commit();
								$response->reload = true;
								if ($settings['discord_notify_url']) {
									discord_api(2, "```##Yeni Destek Talebi##```\n**• Talep Başlığı:** " . $title . "\n**• Talebi Oluşturan Müşteri:**" . $user["user_username"] . "\n**• Talep Tarihi:** " . date('d.m.Y H:i:s'));
								}

								$Notifyemail 		= 	$settings['admin_iletisim'];
								$Notifyphone 		= 	$settings['admin_phone'];
								$Notifyname 		= 	"Sn. Site Yetkilisi";
								$Notifysubject 		= 	"Yeni Destek Talebi";
								$Notifymessage 		= 	$title . ", başlığında yeni destek talebiniz mevcut.";

								if ($NotifySettings['failed'] == 2) {

									send_email($Notifyemail, $Notifyname, $Notifysubject, $Notifymessage);
								} elseif ($NotifySettings['failed'] == 3) {

									send_sms(1, $settings['sms_provider'], $Notifyphone, $Notifymessage);
								} elseif ($NotifySettings['failed'] == 4) {

									send_email($Notifyemail, $Notifyname, $Notifysubject, $Notifymessage);
									send_sms(1, $settings['sms_provider'], $Notifyphone, $Notifymessage);
								}
							} else {

								$db->rollBack();
								$response->error = "{TECHNICAL_FAILURE}";
							}
						}
					} else {

						$insert_ticket = $db->insert('tickets')
							->set(array(
								'user_id' => session('user_id'),
								'ticket_title' => $title,
								'ticket_ans' => 1
							));

						$ticket_id = $db->lastInsertId();
						$time = time();

						$insert_message = $db->insert('ticket_messages')
							->set(array(
								'ticket_id' => $ticket_id,
								'message_author' => 1,
								'message_text' => $message,
								'message_time' => $time
							));

						if ($insert_ticket && $insert_message) {

							$ip = $_SERVER['REMOTE_ADDR'];
							insert_log($db, $user["user_id"], $ip, "Destek talebi oluşturuldu. <a href='/admin/support/$ticket_id'>Oku</a>");
							$db->commit();
							$response->reload = true;
							if ($settings['discord_notify_url']) {
								discord_api(2, "```##Yeni Destek Talebi##```\n**• Talep Başlığı:** " . $title . "\n**• Talebi Oluşturan Müşteri:**" . $user["user_username"] . "\n**• Talep Tarihi:** " . date('d.m.Y H:i:s'));
							}
						} else {

							$db->rollBack();
							$response->error = "{TECHNICAL_FAILURE}";
						}
					}
				}
			} else {

				$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
			}
		} else {

			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "send_message") {
		if (login_control()) {
			$posts = [
				"id" => true,
				"message" => true
			];
			$error = false;
			foreach ($posts as $post => $required) {
				if ($required) {
					if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
						$$post = filter($_POST[$post]);
					} else {
						$error = true;
						break;
					}
				} else {
					if (isset($_POST[$post])) {
						$$post = filter($_POST[$post]);
					} else {
						$error = true;
						break;
					}
				}
			}
			if (!$error) {
				$query = $db->prepare("SELECT * FROM `tickets` WHERE ticket_id = ? AND user_id = ? AND ticket_status = 1");
				$query->execute([$id, session("user_id")]);
				$query2 = $db->prepare("UPDATE tickets SET ticket_ans = 1 WHERE ticket_id = ?");
				$query2->execute([$id]);
				if ($query->rowCount()) {
					$time = time();
					$query = $db->prepare("INSERT INTO `ticket_messages` SET ticket_id = ?, message_text = ?, message_time = ?, message_author = 1");
					$insert_message = $query->execute([$id, $message, $time]);
					if ($insert_message) {

						$query = $db->prepare("UPDATE tickets SET ticket_read = 0 WHERE ticket_id = ? AND user_id = ?");
						$query->execute([$id, session("user_id")]);


						$ip = $_SERVER['REMOTE_ADDR'];
						insert_log($db, $user["user_id"], $ip, "Destek talebine mesaj gönderildi.");
						$response->reload = true;
						if ($settings['discord_notify_url']) {
							discord_api(2, "```#" . $id . " Numaralı Destek Talebine Yeni Cevap Gönderildi```\n**• İşlem Tarihi:** " . date('d.m.Y H:i:s'));
						}
					} else {
						$response->error = "{TECHNICAL_FAILURE}";
					}
				} else {
					$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
				}
			} else {
				$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "forgot_password") {
		if (!login_control()) {
			$posts = [
				"username" => true
			];
			$error = false;
			foreach ($posts as $post => $required) {
				if ($required) {
					if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
						$$post = filter($_POST[$post]);
					} else {
						$error = true;
						break;
					}
				} else {
					if (isset($_POST[$post])) {
						$$post = filter($_POST[$post]);
					} else {
						$error = true;
						break;
					}
				}
			}
			if (!$error) {
				$do = true;
				if ($do) {
					$query = $db->prepare("SELECT * FROM `users` WHERE user_username = ?");
					$query->execute([$username]);
					if ($query->rowCount()) {
						$user = $query->fetch(PDO::FETCH_ASSOC);
						$smtp = $db->query("SELECT * FROM `smtp_settings` WHERE id = 1")->fetch(PDO::FETCH_ASSOC);
						$secure = "tls";
						if ($smtp["smtp_ssl"]) {
							$secure = "ssl";
						}
						$opt = [
							"host" => $smtp["smtp_host"],
							"email" => $smtp["smtp_email"],
							"password" => $smtp["smtp_password"],
							"port" => $smtp["smtp_port"],
							"title" => TITLE,
							"subject" => "Reset Password",
							"secure" => $secure
						];
						$key = "";
						do {
							$key = md5($user["user_password"] . $user["user_email"] . time() . rand(0, 99999)) . md5($user["user_id"] . $user["user_key"] . time() . rand(0, 99999));
							$query = $db->prepare("SELECT * FROM `reset_password_requests` WHERE request_hash = ?");
							$query->execute([$key]);
						} while ($query->rowCount());
						$update_requests = $db->query("UPDATE `reset_password_requests` SET request_status = 0 WHERE user_id = $user[user_id]");
						$query = $db->prepare("INSERT INTO `reset_password_requests` SET user_id = ?, request_hash = ?, request_expiration = ?");
						$insert_request = $query->execute([$user["user_id"], $key, time() + 86400]);
						if ($insert_request) {

							$sendmail = send_email($user["user_email"], $user["user_first_name"], "Parola Sıfırlama İsteği", "Şifre Sıfırlama Bağlantınız: " . site($siteLinks['reset']['url'] . "/{$key}"));
							$paneltitle = $settings['site_title'];
							$sendsms  = send_sms(1, $settings['sms_provider'], $user["user_skype"], " $paneltitle Şifre Sıfırlama Bağlantınız: " . site($siteLinks['reset']['url'] . "/{$key}"));

							if ($sendmail) {
								$ip = $_SERVER['REMOTE_ADDR'];
								insert_log($db, $user["user_id"], $ip, "Parola sıfırlama isteği oluşturuldu.");
								$response->success = "Mail ve Telefon Numarınıza Şifre Sıfırlama Bağlantınız Gönderilmiştir.";
							} else {
								$response->error = $sendmail;
							}
						} else {
							$response->error = "{TECHNICAL_FAILURE}";
						}
						$user = null;
					} else {
						$response->error = "{FORGOT_MESSAGE_NOT_FOUND}";
					}
				} else {
					$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
				}
			} else {
				$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "reset_password") {
		if (!login_control()) {
			$posts = [
				"password" => true,
				"re_password" => true,
				"hash" => true
			];
			$error = false;
			foreach ($posts as $post => $required) {
				if ($required) {
					if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
						$$post = filter($_POST[$post]);
					} else {
						$error = true;
						break;
					}
				} else {
					if (isset($_POST[$post])) {
						$$post = filter($_POST[$post]);
					} else {
						$error = true;
						break;
					}
				}
			}
			if (!$error) {

				if ($password == $re_password) {

					if ($hash) {

						$query = $db->from('reset_password_requests')
							->where('request_hash', $hash)
							->where('request_status', 1)
							->first();

						if ($query) {

							$request = $query;
							$password = password_hash($password, PASSWORD_DEFAULT);

							$update_password = $db->update('users')->where('user_id', $request['user_id'])
								->set(array('user_password' => $password));

							$update_request = $db->update('reset_password_requests')->where('request_id', $request['request_id'])
								->set(array('request_status' => 0));

							if ($update_password && $update_request) {
								$ip = $_SERVER['REMOTE_ADDR'];
								insert_log($db, $request['user_id'], $ip, "Parola sıfırlandı.");

								$response->success = "{RESET_PASSWORD_SUCCESS}";
								$response->redirect = true;
								$response->location = site();
								$response->delay = 3000;
							} else {
								$response->error = "{TECHNICAL_FAILURE}";
							}
						} else {
							$response->error = "{MESSAGE_WRONG_REQUEST}";
						}
					} else {
						$response->error = "<h3>☺</h3>";
					}
				} else {
					$response->error = "{REGISTER_MESSAGE_PASSWORD_DONT_MATCH}";
				}
			} else {
				$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "add_funds") {
		/*echo 2312141;
		exit;*/
		if (login_control()) {
			$posts = [
				"amount" => true,
				"phone" => true
			];
			$error = false;
			foreach ($posts as $post => $required) {
				if ($required) {
					if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
						$$post = filter($_POST[$post]);
					} else {
						$error = true;
						break;
					}
				} else {
					if (isset($_POST[$post])) {
						$$post = filter($_POST[$post]);
					} else {
						$error = true;
						break;
					}
				}
			}
			if (!$error) {
				if (intval($amount)) {
					if ($amount >= MINIMUM_PAYMENT) {
						$payment = new Payment($db);
						$p = null;
						if (PAYMENT_METHOD == 1) {
							$p = $payment->PayTR($user, $amount, $phone);
						} elseif (PAYMENT_METHOD == 2) {
							$p = $payment->Buypayer($user, $amount);
						} elseif (PAYMENT_METHOD == 3) {
							$p = $payment->Paywant($user, $amount);
						} else {
							$response->error = "{MESSAGE_PAYMENT_CLOSED}";
						}
						if ($p) {

							if ($p["status"]) {

								$ip = $_SERVER['REMOTE_ADDR'];
								insert_log($db, $user["user_id"], $ip, "Bakiye ekleme işlemi yapıldı.");
								$response->location = $p["location"];
								$response->newtab = true;
								$response->redirect = true;
								if ($settings['discord_notify_url']) {
									discord_api(2, "```##Bakiye Ekleme İşlemi##```\n**• Talep Edilen Tutar:** " . $amount . "\n**• Talebi Oluşturan Müşteri:**" . $user["user_username"] . "\n**• Talep Tarihi:** " . date('d.m.Y H:i:s'));
								}
							} else {

								$response->error = $p["message"];
							}
						}
					} else {
						$response->error = "{ADD_FUNDS_MESSAGE_LEAST}";
					}
				} else {
					$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
				}
			} else {
				$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "add_bank_funds") {
		if (login_control()) {
			$posts = [
				"bank_account" => true,
				"amount" => true
			];
			$error = false;
			foreach ($posts as $post => $required) {
				if ($required) {
					if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
						$$post = filter($_POST[$post]);
					} else {
						$error = true;
						break;
					}
				} else {
					if (isset($_POST[$post])) {
						$$post = filter($_POST[$post]);
					} else {
						$error = true;
						break;
					}
				}
			}
			if (!$error) {
				if (intval($amount)) {
					if ($amount >= 1) {

						$query = $db->insert('bank_deposits')->set(array(
							'user' => $user["user_id"],
							'bank' => $bank_account,
							'amount' => $amount,
							'status' => 0
						));

						if ($query) {
							$ip = $_SERVER['REMOTE_ADDR'];
							insert_log($db, $user["user_id"], $ip, "Ödeme bildirimi yapıldı.");
							$response->success = "Ödeme bildirimi yapıldı.";
							if ($settings['discord_notify_url']) {
								discord_api(2, "```##Banka Ödeme Bildirimi##```\n**• Talep Edilen Tutar:** " . $amount . "\n**• Talebi Oluşturan Müşteri:**" . $user["user_username"] . "\n**• Talep Tarihi:** " . date('d.m.Y H:i:s'));
							}

							$Notifyemail 		= 	$settings['admin_iletisim'];
							$Notifyphone 		= 	$settings['admin_phone'];
							$Notifyname 		= 	"Sn. Site Yetkilisi";
							$Notifysubject 		= 	"Banka Ödeme Bildirimi";
							$Notifymessage 		= 	"##Banka Ödeme Bildirimi## • Talep Edilen Tutar: " . $amount . " • Talebi Oluşturan Müşteri: " . $user["user_username"] . " • Talep Tarihi: " . date('d.m.Y H:i:s');

							if ($NotifySettings['bank'] == 2) {

								send_email($Notifyemail, $Notifyname, $Notifysubject, $Notifymessage);
							} elseif ($NotifySettings['bank'] == 3) {

								send_sms(1, $settings['sms_provider'], $Notifyphone, $Notifymessage);
							} elseif ($NotifySettings['bank'] == 4) {

								send_email($Notifyemail, $Notifyname, $Notifysubject, $Notifymessage);
								send_sms(1, $settings['sms_provider'], $Notifyphone, $Notifymessage);
							}
						} else {
							$response->error = "{ADD_FUNDS_MESSAGE_LEAST}";
						}
					} else {
						$response->error = "{ADD_FUNDS_MESSAGE_LEAST}";
					}
				} else {
					$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
				}
			} else {
				$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "get_details") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {
				$posts = [
					"start_date" => true,
					"end_date" => true
				];
				$error = false;
				foreach ($posts as $post => $required) {
					if ($required) {
						if (isset($_GET[$post]) && filter($_GET[$post]) != null) {
							$$post = filter($_GET[$post]);
						} else {
							$error = true;
							break;
						}
					} else {
						if (isset($_GET[$post])) {
							$$post = filter($_GET[$post]);
						} else {
							$error = true;
							break;
						}
					}
				}
				if (!$error) {
					$time_start = strtotime(str_replace("/", "-", $start_date) . " 00:00:00");
					$time_end = strtotime(str_replace("/", "-", $end_date) . " 23:59:59");
					if ($time_end > $time_start) {
						$query = $db->prepare("SELECT * FROM `orders` WHERE (order_status = 'Completed' OR order_status = 'Partial') AND order_date BETWEEN ? AND ?");
						$query->execute([$time_start, $time_end]);
						if ($query->rowCount()) {
							$orders = $query->fetchAll(PDO::FETCH_ASSOC);
							$tempOrders = [];
							$sums = [];
							$sums[] = ["Toplamlar"];
							foreach ($orders as $order) {
								$amount = $order["order_amount"];
								$api_amount = ($order["api_order_amount"] != null) ? $order["api_order_amount"] : 0;
								$api_currency = ($order["api_order_currency"] != null) ? $order["api_order_currency"] : "TRY";
								$date = date("d.m.Y H:i:s", $order["order_date"]);
								$order = [
									"date" => $date,
									"currency" => CURRENCY_CODE,
									"amount" => $amount,
									"api_currency" => $api_currency,
									"api_amount" => $api_amount,
									"net" => (CURRENCY_CODE == $api_currency) ? $amount - $api_amount : "Para birimi uyuşmuyor!"
								];
								if (array_key_exists($api_currency, $sums)) {
									$sums[$api_currency][2] += $amount;
									$sums[$api_currency][4] += $api_amount;
									if (CURRENCY_CODE == $api_currency) {
										$sums[$api_currency][5] += ($amount - $api_amount);
									}
								} else {
									$sums[$api_currency] = [
										"",
										CURRENCY_CODE,
										$amount,
										$api_currency,
										$api_amount,
										(CURRENCY_CODE == $api_currency) ? ($amount - $api_amount) : "Para birimi uyuşmuyor!"
									];
								}
								$tempOrders[] = $order;
							}
							$orders = array_merge([["Tarih", "Para Birimi", "Tutar", "API Para Birimi", "API Tutar", "Net Kazanç"]], $tempOrders);
							$orders = array_merge($orders, $sums, [["Sipariş Sayısı: " . $query->rowCount()]]);
							$filename = "report-" . time() . ".csv";
							$delimiter = ";";
							$f = fopen('php://memory', 'w');
							foreach ($orders as $line) {
								fputcsv($f, $line, $delimiter);
							}
							fseek($f, 0);
							header('Content-Type: application/csv; charset=utf-8');
							header('Content-Disposition: attachment; filename="' . $filename . '";');
							fpassthru($f);
							exit;
						} else {
							$response->log = "Belirtilen tarih aralığında sipariş bulunamadı.";
						}
					} else {
						$response->error = "Hatalı tarih aralığı!";
					}
				} else {
					$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "get_earnings") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {
				$posts = [
					"start_date" => true,
					"end_date" => true
				];
				$error = false;
				foreach ($posts as $post => $required) {
					if ($required) {
						if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
							$$post = filter($_POST[$post]);
						} else {
							$error = true;
							break;
						}
					} else {
						if (isset($_POST[$post])) {
							$$post = filter($_POST[$post]);
						} else {
							$error = true;
							break;
						}
					}
				}
				if (!$error) {
					$time_start = strtotime(str_replace("/", "-", $start_date) . " 00:00:00");
					$time_end = strtotime(str_replace("/", "-", $end_date) . " 23:59:59");
					if ($time_end > $time_start) {
						$query = $db->prepare("SELECT * FROM `orders` WHERE (order_status = 'Completed' OR order_status = 'Partial') AND order_date BETWEEN ? AND ?");
						$query->execute([$time_start, $time_end]);
						if ($query->rowCount()) {
							if ($time_end - $time_start <= 86400) {
								$diff = $time_end - $time_start;
								$interval = 7200;
								$times = ceil($diff / $interval);
								$orders = $query->fetchAll(PDO::FETCH_ASSOC);
								$tempOrders = [];
								for ($i = 0; $i < $times; $i++) {
									$start = $time_start + ($i * $interval);
									$end = $start + ($interval - 1);
									if ($end > $time_end) {
										$end = $time_end;
									}
									$sdate = date("H:i", $start);
									$date = date("H:i", $end);
									$tempOrders[$sdate . " - " . $date] = 0;
									foreach ($orders as $order) {
										if ($order["order_date"] >= $start && $order["order_date"] <= $end) {
											if ($order["api_order_currency"] == null) {
												$order["api_order_currency"] = "TRY";
											}
											if (CURRENCY_CODE == $order["api_order_currency"]) {
												if ($order["api_order_amount"] == null) {
													$order["api_order_amount"] = 0;
												}
												$amount = $order["order_amount"] - $order["api_order_amount"];
												if ($order["order_status"] == "Partial") {
													$amount = ($order["order_amount"] - ($order["order_amount"] / $order["order_quantity"]) * $order["order_remains"]) - $order["api_order_amount"];
												}
												$tempOrders[$sdate . " - " . $date] += $amount;
											}
										}
									}
								}
								$response->labels = array_keys($tempOrders);
								$response->datas = array_values($tempOrders);
								$response->success = true;
							} elseif ($time_end - $time_start <= 604800) {
								$diff = $time_end - $time_start;
								$interval = 75600;
								$times = ceil($diff / $interval);
								$orders = $query->fetchAll(PDO::FETCH_ASSOC);
								$tempOrders = [];
								for ($i = 0; $i < $times; $i++) {
									$start = $time_start + ($i * $interval);
									$end = $start + ($interval - 1);
									if ($end > $time_end) {
										$end = $time_end;
									}
									$sdate = date("d.m.y H:i", $start);
									$date = date("d.m.y H:i", $end);
									$tempOrders[$sdate . " - " . $date] = 0;
									foreach ($orders as $order) {
										if ($order["order_date"] >= $start && $order["order_date"] <= $end) {
											if ($order["api_order_currency"] == null) {
												$order["api_order_currency"] = "TRY";
											}
											if (CURRENCY_CODE == $order["api_order_currency"]) {
												if ($order["api_order_amount"] == null) {
													$order["api_order_amount"] = 0;
												}
												$amount = $order["order_amount"] - $order["api_order_amount"];
												if ($order["order_status"] == "Partial") {
													$amount = ($order["order_amount"] - ($order["order_amount"] / $order["order_quantity"]) * $order["order_remains"]) - $order["api_order_amount"];
												}
												$tempOrders[$sdate . " - " . $date] += $amount;
											}
										}
									}
								}
								$response->labels = array_keys($tempOrders);
								$response->datas = array_values($tempOrders);
								$response->success = true;
							} elseif ($time_end - $time_start <= 2592000) {
								$diff = $time_end - $time_start;
								$interval = 240000;
								$times = ceil($diff / $interval);
								$orders = $query->fetchAll(PDO::FETCH_ASSOC);
								$tempOrders = [];
								for ($i = 0; $i < $times; $i++) {
									$start = $time_start + ($i * $interval);
									$end = $start + ($interval - 1);
									if ($end > $time_end) {
										$end = $time_end;
									}
									$sdate = date("d.m.y", $start);
									$date = date("d.m.y", $end);
									$tempOrders[$sdate . " - " . $date] = 0;
									foreach ($orders as $order) {
										if ($order["order_date"] >= $start && $order["order_date"] <= $end) {
											if ($order["api_order_currency"] == null) {
												$order["api_order_currency"] = "TRY";
											}
											if (CURRENCY_CODE == $order["api_order_currency"]) {
												if ($order["api_order_amount"] == null) {
													$order["api_order_amount"] = 0;
												}
												$amount = $order["order_amount"] - $order["api_order_amount"];
												if ($order["order_status"] == "Partial") {
													$amount = ($order["order_amount"] - ($order["order_amount"] / $order["order_quantity"]) * $order["order_remains"]) - $order["api_order_amount"];
												}
												$tempOrders[$sdate . " - " . $date] += $amount;
											}
										}
									}
								}
								$response->labels = array_keys($tempOrders);
								$response->datas = array_values($tempOrders);
								$response->success = true;
							} elseif ($time_end - $time_start <= 7776000) {
								$diff = $time_end - $time_start;
								$interval = 518400;
								$times = ceil($diff / $interval);
								$orders = $query->fetchAll(PDO::FETCH_ASSOC);
								$tempOrders = [];
								for ($i = 0; $i < $times; $i++) {
									$start = $time_start + ($i * $interval);
									$end = $start + ($interval - 1);
									if ($end > $time_end) {
										$end = $time_end;
									}
									$sdate = date("d.m.y", $start);
									$date = date("d.m.y", $end);
									$tempOrders[$sdate . " - " . $date] = 0;
									foreach ($orders as $order) {
										if ($order["order_date"] >= $start && $order["order_date"] <= $end) {
											if ($order["api_order_currency"] == null) {
												$order["api_order_currency"] = "TRY";
											}
											if (CURRENCY_CODE == $order["api_order_currency"]) {
												if ($order["api_order_amount"] == null) {
													$order["api_order_amount"] = 0;
												}
												$amount = $order["order_amount"] - $order["api_order_amount"];
												if ($order["order_status"] == "Partial") {
													$amount = ($order["order_amount"] - ($order["order_amount"] / $order["order_quantity"]) * $order["order_remains"]) - $order["api_order_amount"];
												}
												$tempOrders[$sdate . " - " . $date] += $amount;
											}
										}
									}
								}
								$response->labels = array_keys($tempOrders);
								$response->datas = array_values($tempOrders);
								$response->success = true;
							} else {
								$response->log = "En fazla 90 günlük grafik gösterilebilir.";
							}
						} else {
							$response->log = "Belirtilen tarih aralığında sipariş bulunamadı.";
						}
					} else {
						$response->error = "Hatalı tarih aralığı!";
					}
				} else {
					$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "update_ticket") {
		if (login_control()) {
			if ($user["user_authority"] > 0) {

				if (!permission('access', 'edit')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					$posts = [
						"id" => true,
						"type" => true,
						"status" => true
					];
					$error = false;
					foreach ($posts as $post => $required) {
						if ($required) {
							if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						} else {
							if (isset($_POST[$post])) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						}
					}
					if (!$error) {

						if ($type == 1) {

							$query = $db->from('tickets')->where('ticket_id', $id)->first();

							if ($query) {

								if ($query['ticket_status'] == 1) {

									$update = $db->update('tickets')->where('ticket_id', $id)
										->set(array(
											'ticket_status' => 0
										));

									if ($update) {
										$response->reload = true;
									} else {
										$response->error = "Sistem hatası oluştu, daha sonra tekrar deneyiniz.";
									}
								} elseif ($query['ticket_status'] == 0) {

									$update = $db->update('tickets')->where('ticket_id', $id)
										->set(array(
											'ticket_status' => 1
										));

									if ($update) {
										$response->reload = true;
									} else {
										$response->error = "Sistem hatası oluştu, daha sonra tekrar deneyiniz.";
									}
								} else {

									$response->error = "Bu destek talebi kapatılmış, durumu değiştirilemez.";
								}
							} else {

								$response->error = "Sistem hatası oluştu, daha sonra tekrar deneyiniz.";
							}
						} elseif ($type == 2) {

							$query = $db->from('tickets')->where('ticket_id', $id)->first();

							if ($query) {

								$update = $db->update('tickets')->where('ticket_id', $id)
									->set(array(
										'ticket_status' => 2
									));

								if ($update) {
									$response->reload = true;
								} else {
									$response->error = "Sistem hatası oluştu, daha sonra tekrar deneyiniz.";
								}
							} else {

								$response->error = "Sistem hatası oluştu, daha sonra tekrar deneyiniz.";
							}
						}
					} else {
						$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
					}
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "Update_NotifySettings") {
		if (login_control()) {
			if ($user["user_authority"] > 0) {

				if (!permission('access', 'edit')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					$posts = [
						"neworder_notify" => true,
						"online_notify" => true,
						"bank_notify" => true,
						"failedorder_notify" => true,
						"newsupport_notify" => true
					];
					$error = false;
					foreach ($posts as $post => $required) {
						if ($required) {
							if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						} else {
							if (isset($_POST[$post])) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						}
					}
					if (!$error) {

						$arr = [
							"bank" => $bank_notify,
							"online" => $online_notify,
							'failed' => $failedorder_notify,
							'support' => $newsupport_notify,
							'order' => $neworder_notify
						];

						$update = $db->update('settings')->where('id', 1)
							->set(array(
								'notify_settings' => json_encode($arr)
							));

						if ($update) {
							$response->success = "Bilgiler başarıyla güncellendi.";
						} else {
							$response->error = "Sistem hatası nedeniyle işleminiz gerçekleştirilemedi.";
						}
					} else {
						$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
					}
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "delete_ticket") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'delete')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					$posts = [
						"id" => true
					];
					$error = false;
					foreach ($posts as $post => $required) {
						if ($required) {
							if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						} else {
							if (isset($_POST[$post])) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						}
					}
					if (!$error) {
						$query = $db->prepare("DELETE FROM `tickets` WHERE ticket_id = ?");
						$delete_ticket = $query->execute([$id]);
						if ($delete_ticket) {
							$query = $db->prepare("DELETE FROM `ticket_messages` WHERE ticket_id = ?");
							$delete_ticket = $query->execute([$id]);
							$response->reload = true;
						} else {
							$response->error = "Sistem hatası oluştu!";
						}
					} else {
						$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
					}
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "admin_send_message") {
		if (login_control()) {
			if ($user["user_authority"] > 0) {

				if (!permission('access', 'support')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					$id = $_POST['id'];
					$message = htmlspecialchars($_POST['message']);

					$error = false;
					if (!$error) {
						$query = $db->prepare("SELECT * FROM `tickets` WHERE ticket_id = ? AND ticket_status = 1");
						$query->execute([$id]);
						$query2 = $db->prepare("UPDATE tickets SET ticket_ans = 2 WHERE ticket_id = ?");
						$query2->execute([$id]);
						$query3 = $db->prepare("UPDATE tickets SET client_read = 0 WHERE ticket_id = ?");
						$query3->execute([$id]);
						if ($query->rowCount()) {
							$time = time();
							$insert_message = $db->insert('ticket_messages')
								->set(array(
									'ticket_id' => $id,
									'message_text' => $message,
									'message_time' => $time,
									'message_author' => 0
								));
							if ($insert_message) {
								$response->reload = true;
							} else {
								$response->error = "Sistem hatası oluştu!";
							}
						} else {
							$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
						}
					} else {
						$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
					}
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "delete_user") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'delete')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					$posts = [
						"id" => true
					];
					$error = false;
					foreach ($posts as $post => $required) {
						if ($required) {
							if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						} else {
							if (isset($_POST[$post])) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						}
					}
					if (!$error) {
						$query = $db->prepare("DELETE FROM `users` WHERE user_id = ?");
						$delete_user = $query->execute([$id]);
						if ($delete_user) {
							$response->reload = true;
						} else {
							$response->error = "Sistem hatası oluştu!";
						}
					} else {
						$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
					}
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "update_user") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'edit')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					$posts = [
						"id" => false,
						"username" => false,
						"email" => true,
						"first_name" => true,
						"last_name" => true,
						"skype" => true,
						"authority" => true,
						"password" => false
					];
					$error = false;
					foreach ($posts as $post => $required) {
						if ($required) {
							if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						} else {
							if (isset($_POST[$post])) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						}
					}
					if (!$error) {
						$query = $db->prepare("SELECT * FROM users WHERE user_email = ? AND user_id != ?");
						$query->execute(array(
							$email, $id
						));
						if (!$query->rowCount()) {
							$query = $db->prepare("SELECT * FROM users WHERE user_username = ? AND user_id != ?");
							$query->execute(array(
								$username, $id
							));
							if (!$query->rowCount()) {
								$query = $db->prepare("SELECT * FROM users WHERE user_skype = ? AND user_id != ?");
								$query->execute(array(
									$skype, $id
								));
								if ($skype == "" || !$query->rowCount()) {
									if ($authority >= 0 && $authority <= 2) {
										$status = 1;
										if (isset($_POST["status"])) {
											$status = 0;
										}

										@$perms = json_encode($_POST['access']);

										if ($password != null) {

											$password = password_hash($password, PASSWORD_DEFAULT);

											$update_user = $db->update('users')
												->where('user_id', $id)
												->set(array(
													'user_email' => $email,
													'user_username' => $username,
													'user_first_name' => $first_name,
													'user_last_name' => $last_name,
													'user_skype' => $skype,
													'user_authority' => $authority,
													'user_perms' => $perms,
													'user_password' => $password
												));
										} else {

											$update_user = $db->update('users')
												->where('user_id', $id)
												->set(array(
													'user_email' => $email,
													'user_username' => $username,
													'user_first_name' => $first_name,
													'user_last_name' => $last_name,
													'user_skype' => $skype,
													'user_authority' => $authority,
													'user_perms' => $perms
												));
										}


										if ($update_user) {
											$response->success = "Kullanıcı güncellendi.";
										} else {
											$response->error = "Sistem hatası oluştu!";
										}
									} else {
										$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
									}
								} else {
									$response->error = "Skype adresi kullanılıyor.";
								}
							} else {
								$response->error = "Kullanıcı adı kullanılıyor.";
							}
						} else {
							$response->error = "E-posta adresi kullanılıyor.";
						}
					} else {
						$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
					}
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "update_offers") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {
				$posts = [
					"id" => true
				];
				$error = false;
				foreach ($posts as $post => $required) {
					if ($required) {
						if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
							$$post = filter($_POST[$post]);
						} else {
							$error = true;
							break;
						}
					} else {
						if (isset($_POST[$post])) {
							$$post = filter($_POST[$post]);
						} else {
							$error = true;
							break;
						}
					}
				}
				if (!$error) {
					foreach ($_POST["service"] as $key => $val) {
						$key = filter($key);
						$val = filter($val);
						if ($val == null) {
							$query = $db->prepare("DELETE FROM `special_offers` WHERE user_id = ? AND service_id = ?");
							$delete_offer = $query->execute([$id, $key]);
							if (!$delete_offer) {
								$response->error = "Sistem hatası oluştu.";
								break;
							}
						} else {
							$val = str_replace(",", ".", $val);
							if (is_numeric($val)) {
								$query = $db->prepare("SELECT * FROM `special_offers` WHERE user_id = ? AND service_id = ?");
								$query->execute([$id, $key]);
								if ($query->rowCount()) {
									$query = $db->prepare("UPDATE `special_offers` SET offer_charge = ? WHERE user_id = ? AND service_id = ?");
									$update_offer = $query->execute([$val, $id, $key]);
									if (!$update_offer) {
										$response->error = "Sistem hatası oluştu.";
										break;
									}
								} else {
									$query = $db->prepare("INSERT INTO `special_offers` SET offer_charge = ?, user_id = ?, service_id = ?");
									$insert_offer = $query->execute([$val, $id, $key]);
									if (!$insert_offer) {
										$response->error = "Sistem hatası oluştu.";
										break;
									}
								}
							}
						}
					}
					if (!isset($response->error)) {
						$response->success = "İşlemler tamamlandı.";
					}
				} else {
					$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "update_ordering") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'edit')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					$posts = [
						"type" => true
					];
					$error = false;
					foreach ($posts as $post => $required) {
						if ($required) {
							if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						} else {
							if (isset($_POST[$post])) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						}
					}
					if (!$error) {
						if ($type == "categories") {
							$i = 1;
							foreach ($_POST["ordering"] as $category) {
								$category = filter($category);
								$query = $db->prepare("UPDATE `categories` SET category_number = ? WHERE category_id = ?");
								$query->execute([$i, $category]);
								$i++;
							}
							$response->success = 'Sıralama güncellendi.';
						} elseif ($type == "services") {
							$i = 1;
							foreach ($_POST["ordering"] as $service) {
								$service = filter($service);
								$query = $db->prepare("UPDATE `services` SET service_number = ? WHERE service_id = ?");
								$query->execute([$i, $service]);
								$i++;
							}
							$response->success = 'Sıralama güncellendi.';
						} else {
							$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
						}
					} else {
						$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
					}
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "update_menu_ordering") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'edit')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					$posts = [
						"type" => true
					];
					$error = false;
					foreach ($posts as $post => $required) {
						if ($required) {
							if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						} else {
							if (isset($_POST[$post])) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						}
					}
					if (!$error) {
						if ($type == "public") {
							$i = 1;
							foreach ($_POST["ordering"] as $category) {
								$category = filter($category);
								$query = $db->prepare("UPDATE `menus` SET menu_line = ? WHERE menu_id = ?");
								$query->execute([$i, $category]);
								$i++;
							}
						} elseif ($type == "private") {
							$i = 1;
							foreach ($_POST["ordering"] as $service) {
								$service = filter($service);
								$query = $db->prepare("UPDATE `menus` SET menu_line = ? WHERE menu_id = ?");
								$query->execute([$i, $service]);
								$i++;
							}
						} else {
							$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
						}
					} else {
						$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
					}
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "update_category") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'edit')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					$posts = [
						"id" => true,
						"category_icon" => true,
						"category_icon_color" => true,
					];
					$error = false;
					foreach ($posts as $post => $required) {
						if ($required) {
							if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						} else {
							if (isset($_POST[$post])) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						}
					}
					if (!$error) {
						$name = [];
						foreach ($_POST["name"] as $key => $val) {
							$key = filter($key);
							$val = filter($val);
							if ($val != null) {
								$name[] = [
									"lang" => intval($key),
									"name" => $val
								];
							}
						}
						$name = json_encode($name);
						$query = $db->prepare("UPDATE `categories` SET category_icon_color=?,category_icon= ?, category_name = ? WHERE category_id = ?");
						$update_category = $query->execute([$category_icon_color, $category_icon, $name, $id]);
						if ($update_category) {
							$response->success = "Kategori Güncellendi";
						} else {
							$response->error = "Sistem hatası oluştu.";
						}
					} else {
						$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
					}
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "add_category") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'edit')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					$posts = [
						"category_icon" => true,
						"category_icon_color" => true
					];
					$error = false;
					foreach ($posts as $post => $required) {

						if (isset($_POST[$post])) {
							$$post = filter($_POST[$post]);
						} else {
							$error = true;
							break;
						}
					}
					$name = [];
					foreach ($_POST["name"] as $key => $val) {
						$key = filter($key);
						$val = filter($val);
						if ($val != null) {
							$name[] = [
								"lang" => intval($key),
								"name" => $val
							];
						}
					}
					if (!empty($name)) {
						$name = json_encode($name);
					} else {
						$name = null;
					}
					$query = $db->prepare("INSERT INTO `categories` SET category_icon_color = ?,category_icon = ?, category_name = ?");
					$insert_category = $query->execute([$category_icon_color, $category_icon, $name]);
					if ($insert_category) {
						$response->success = "Kategori Eklendi";
					} else {
						$response->error = "Sistem hatası oluştu.";
					}
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "change_status_category") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'edit')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					$posts = [
						"id" => true
					];

					$error = false;
					foreach ($posts as $post => $required) {
						if ($required) {
							if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						} else {
							if (isset($_POST[$post])) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						}
					}

					if (!$error) {
						$query = $db->from('categories')->where('category_id', $id)->first();

						if ($query) {

							if ($query['category_status'] == 1) {

								$update = $db->update('categories')->where('category_id', $id)
									->set(array(
										'category_status' => 0
									));

								if ($update) {
									$response->reload = true;
								} else {
									$response->error = "Sistem hatası oluştu.";
								}
							} else {

								$update = $db->update('categories')->where('category_id', $id)
									->set(array(
										'category_status' => 1
									));

								if ($update) {
									$response->reload = true;
								} else {
									$response->error = "Sistem hatası oluştu.";
								}
							}
						} else {
							$response->error = "Sistem hatası oluştu!";
						}
					} else {

						$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
					}
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "delete_category") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'delete')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					$posts = [
						"id" => true
					];
					$error = false;
					foreach ($posts as $post => $required) {
						if ($required) {
							if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						} else {
							if (isset($_POST[$post])) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						}
					}
					if (!$error) {
						$query = $db->prepare("DELETE FROM `categories` WHERE category_id = ?");
						$delete_category = $query->execute([$id]);
						if ($delete_category) {
							$response->reload = true;
						} else {
							$response->error = "Sistem hatası oluştu!";
						}
					} else {
						$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
					}
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "delete_menu") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'delete')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					$posts = [
						"id" => true
					];
					$error = false;
					foreach ($posts as $post => $required) {
						if ($required) {
							if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						} else {
							if (isset($_POST[$post])) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						}
					}
					if (!$error) {
						$query = $db->prepare("DELETE FROM `menus` WHERE menu_id = ?");
						$delete_category = $query->execute([$id]);
						if ($delete_category) {
							$response->reload = true;
						} else {
							$response->error = "Sistem hatası oluştu!";
						}
					} else {
						$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
					}
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "delete_bankdeposit") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'delete')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					$posts = [
						"id" => true
					];
					$error = false;
					foreach ($posts as $post => $required) {
						if ($required) {
							if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						} else {
							if (isset($_POST[$post])) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						}
					}
					if (!$error) {
						$query = $db->delete('bank_deposits')->where('id', $id)->done();
						if ($query) {
							$response->reload = true;
						} else {
							$response->error = "Sistem hatası oluştu!";
						}
					} else {
						$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
					}
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "onay_bankdeposit") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'edit')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					$posts = [
						"id" => true
					];
					$error = false;
					foreach ($posts as $post => $required) {
						if ($required) {
							if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						} else {
							if (isset($_POST[$post])) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						}
					}
					if (!$error) {
						$depositquery = $db->from('bank_deposits')->where('id', $id)->first();

						$query = $db->update('bank_deposits')->where('id', $id)
							->set(array(
								'status' => 1
							));

						$userquery = $db->from('users')
							->where('user_id', $depositquery['user'])
							->first();

						$yenibakiye = $userquery['user_balance'] + $depositquery['amount'];

						$updatebalance = $db->update('users')->where('user_id', $depositquery['user'])
							->set(array(
								'user_balance' => $yenibakiye
							));

						if ($query && $updatebalance) {
							$response->reload = true;
						} else {
							$response->error = "Sistem hatası oluştu!";
						}
					} else {
						$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
					}
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "update_settings") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'edit')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					$posts = [
						"title" => true,
						"logo" => true,
						"favo" => true,
						"desc" => true,
						"keyw" => true,
						"admins" => true,
						"currency_code" => false,
						"currency_symbol" => false,
						"payment_method" => true,
						"minimum_payment" => true,
						"api" => true,
						"reference_status" => true,
						"reference_share" => true,
						"admin_phone" => true,
						"contact_detail" => false,
						"header_code" => false,
						"footer_code" => false,
						"sms_provider" => true

					];
					$error = false;
					foreach ($posts as $post => $required) {
						if ($required) {
							if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						} else {
							if (isset($_POST[$post])) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						}
					}
					if (!$error) {
						$currency["currency_code"] = $currency_code;
						$currency["currency_symbol"] = $currency_symbol;
						$currency = json_encode($currency);
						$update_settings = $db->update('settings')->where('id', 1)
							->set(array(
								'site_title' => $title,
								'site_logo' => $logo,
								'site_desc' => $desc,
								'site_keyw' => $keyw,
								'admin_iletisim' => $admins,
								'site_currency' => $currency,
								'payment_method' => $payment_method,
								'minimum_payment' => $minimum_payment,
								'api_status' => $api,
								'reference_status' => $reference_status,
								'reference_share' => $reference_share,
								'sms_provider' => $sms_provider,
								'admin_phone' => $admin_phone,
								'header_code' => $header_code,
								'footer_code' => $footer_code,
								'contact_detail' => $contact_detail
							));

						if ($update_settings) {
							$response->success = "Ayarlar güncellendi.";
						} else {
							$response->error = "Sistem hatası oluştu!";
						}
					} else {
						$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
					}
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "update_smtp") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'edit')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					$posts = [
						"email" => true,
						"password" => true,
						"host" => true,
						"port" => true,
						"ssl" => true
					];
					$error = false;
					foreach ($posts as $post => $required) {
						if ($required) {
							if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						} else {
							if (isset($_POST[$post])) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						}
					}
					if (!$error) {
						$query = $db->prepare("UPDATE `smtp_settings` SET smtp_email = ?, smtp_password = ?, smtp_host = ?, smtp_port = ?, smtp_ssl = ?");
						$update_smtp = $query->execute([$email, $password, $host, $port, $ssl]);
						if ($update_smtp) {
							$response->success = "SMTP ayarları güncellendi.";
						} else {
							$response->error = "Sistem hatası oluştu!";
						}
					} else {
						$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
					}
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "update_sms") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'edit')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					$posts = [
						"username" => true,
						"password" => true,
						"sms_title" => true,
						"id" => true
					];
					$error = false;
					foreach ($_POST as $key => $value) {
						$$key = $value;
					}
					if (!$error) {

						$query = $db->update('sms_settings')
							->where('id', $id)
							->set(array(
								'username' => $username,
								'password' => $password,
								'sms_title' => $sms_title
							));

						if ($query) {
							$response->success = "SMS ayarları güncellendi.";
						} else {
							$response->error = "Sistem hatası oluştu!";
						}
					} else {
						$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
					}
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "send_sms") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'edit')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					$posts = [
						"numbers" => true,
						"message" => true
					];
					$error = false;
					foreach ($posts as $post => $required) {
						if ($required) {
							if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						} else {
							if (isset($_POST[$post])) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						}
					}
					if (!$error) {

						$provider = $db->from('settings')->where('id', 1)->first();

						if ($provider['sms_provider'] == 0) {
							$response->error = "SMS Modülü kapalı.";
						} else {
							$response->log = send_sms("1", $provider['sms_provider'], $numbers, $message);
						}
					} else {
						$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
					}
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "sendemail") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'edit')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					$posts = [
						"numbers" => true,
						"message" => true,
						"baslik" => true,
					];
					$error = false;
					foreach ($posts as $post => $required) {
						if ($required) {
							if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						} else {
							if (isset($_POST[$post])) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						}
					}
					if (!$error) {


						$explode = explode(PHP_EOL, $numbers);
						foreach ($explode as $mailadres) {

							$sendmail = send_email($mailadres, $user["user_first_name"], $baslik, $message);
						}
						$response->log = "Başarıyla Gönderildi";
					} else {
						$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
					}
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "add_language") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'edit')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					$posts = [
						"name" => true,
						"code" => true
					];
					$error = false;
					foreach ($posts as $post => $required) {
						if ($required) {
							if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						} else {
							if (isset($_POST[$post])) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						}
					}
					if (!$error) {
						$query = $db->prepare("INSERT INTO `langs` SET lang_name = ?, lang_code = ?");
						$insert_language = $query->execute([$name, $code]);
						if ($insert_language) {
							$response->success = "Dil eklendi.";
						} else {
							$response->error = "Sistem hatası oluştu!";
						}
					} else {
						$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
					}
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "update_language") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'edit')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					$posts = [
						"id" => true,
						"name" => true,
						"code" => true
					];
					$error = false;
					foreach ($posts as $post => $required) {
						if ($required) {
							if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						} else {
							if (isset($_POST[$post])) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						}
					}
					if (!$error) {
						$query = $db->prepare("UPDATE `langs` SET lang_name = ?, lang_code = ? WHERE lang_id = ?");
						$update_language = $query->execute([$name, $code, $id]);
						if ($update_language) {
							$response->success = "Dil güncellendi.";
						} else {
							$response->error = "Sistem hatası oluştu!";
						}
					} else {
						$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
					}
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "delete_language") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'delete')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {


					$posts = [
						"id" => true
					];
					$error = false;
					foreach ($posts as $post => $required) {
						if ($required) {
							if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						} else {
							if (isset($_POST[$post])) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						}
					}
					if (!$error) {
						$db->beginTransaction();
						$query = $db->prepare("DELETE FROM `langs` WHERE lang_id = ?");
						$delete_language = $query->execute([$id]);
						$query = $db->prepare("DELETE FROM `translations` WHERE lang_id = ?");
						$delete_translations = $query->execute([$id]);
						if ($delete_language && $delete_translations) {
							$db->commit();
							$response->reload = true;
						} else {
							$db->rollBack();
							$response->error = "Sistem hatası oluştu!";
						}
					} else {
						$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
					}
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "get_translations") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {
				$posts = [
					"id" => false
				];
				$error = false;
				foreach ($posts as $post => $required) {
					if ($required) {
						if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
							$$post = filter($_POST[$post]);
						} else {
							$error = true;
							break;
						}
					} else {
						if (isset($_POST[$post])) {
							$$post = filter($_POST[$post]);
						} else {
							$error = true;
							break;
						}
					}
				}
				if (!$error) {
					$query = $db->prepare("SELECT A.*, B.translation_text FROM `translation_codes` AS A LEFT JOIN `translations` AS B ON B.code_id = A.code_id and (B.lang_id = ? OR B.lang_id = null)");
					$query->execute([$id]);
					$translations = $query->fetchAll(PDO::FETCH_ASSOC);
					$tempTranslataions = [];
					foreach ($translations as $translation) {
						$tempTranslataions[$translation["code_id"]] = ($translation["translation_text"] != null) ? $translation["translation_text"] : "%" . $translation["code_text"] . "%";
					}
					$response->translations = $tempTranslataions;
				} else {
					$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "update_translations") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'edit')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					$posts = [
						"id" => true
					];
					$error = false;
					foreach ($posts as $post => $required) {
						if ($required) {
							if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						} else {
							if (isset($_POST[$post])) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						}
					}
					if (!$error) {
						foreach ($_POST["code"] as $key => $val) {
							$key = filter($key);
							$val = filter($val, false);
							$query = $db->prepare("SELECT * FROM `translations` WHERE code_id = ? AND lang_id = ?");
							$query->execute([$key, $id]);
							if ($query->rowCount()) {
								$query = $db->prepare("UPDATE `translations` SET translation_text = ? WHERE code_id = ? AND lang_id = ?");
								$update_translation = $query->execute([(($val != "") ? $val : null), $key, $id]);
								if (!$update_translation) {
									$response->error = "Sistem hatası oluştu.";
									break;
								}
							} else {
								if ($val != "") {
									$query = $db->prepare("INSERT INTO `translations` SET translation_text = ?, code_id = ?, lang_id = ?");
									$insert_translation = $query->execute([$val, $key, $id]);
									if (!$insert_translation) {
										$response->error = "Sistem hatası oluştu.";
										break;
									}
								}
							}
						}
						if (!isset($response->error)) {
							$response->success = "İşlemler tamamlandı.";
						}
					} else {
						$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
					}
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "change_lang") {
		$posts = [
			"id" => true
		];
		$error = false;
		foreach ($posts as $post => $required) {
			if ($required) {
				if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
					$$post = filter($_POST[$post]);
				} else {
					$error = true;
					break;
				}
			} else {
				if (isset($_POST[$post])) {
					$$post = filter($_POST[$post]);
				} else {
					$error = true;
					break;
				}
			}
		}
		if (!$error) {
			$query = $db->prepare("SELECT * FROM langs WHERE lang_id = ?");
			$query->execute([$id]);
			if ($query->rowCount() > 0) {
				$lang = $query->fetch(PDO::FETCH_ASSOC);
				$lang = $lang["lang_id"];
				session("language", $lang);
				$response->reload = true;
			}
		} else {
			$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
		}
	} elseif ($action == "add_announcement") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'edit')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					$content = [];
					foreach ($_POST["content"] as $key => $val) {
						$key = filter($key);
						$val = filter($val, false);
						if ($val != null) {
							$content[] = [
								"lang" => intval($key),
								"content" => $val
							];
						}
					}
					if (!empty($content)) {
						$content = json_encode($content);
						$code = strtoupper(uniqid("MOONPANEL_FIELDS_"));
						$query = $db->prepare("INSERT INTO `announcements` SET `announcement_area` = ?, announcement_content = ?");
						$insert_announcement = $query->execute([$code, $content]);
						if ($insert_announcement) {
							$response->alert = "Duyuru eklendi. Duyuru kodu:<br />&#123;" . $code . "&#125;";
						} else {
							$response->error = "Sistem hatası oluştu.";
						}
					} else {
						$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
					}
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "add_duyuru") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'edit')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					$posts = [
						"duyuru_title" => true,
						"duyuru_icon" => true,
						"duyuru_daire_color" => true,
						"duyuru_icon_color" => true,
						"duyuru_content" => true
					];

					$error = false;
					foreach ($posts as $post => $required) {
						if ($required) {
							if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						} else {
							if (isset($_POST[$post])) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						}
					}

					if (!$error) {

						$query = $db->insert('duyuru')->set(array(
							'duyuru_title' => $duyuru_title,
							'duyuru_icon' => $duyuru_icon,
							'duyuru_daire_color' => $duyuru_daire_color,
							'duyuru_icon_color' => $duyuru_icon_color,
							'duyuru_content' => $duyuru_content
						));

						if ($query) {
							$response->alert = "Duyuru eklendi.";
						} else {
							$response->error = "Sistem hatası oluştu.";
						}
					} else {
						$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
					}
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "add_blog") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'edit')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					$posts = [
						"blog_title" => true,
						"blog_url" => true,
						"blog_content" => true
					];

					$error = false;
					foreach ($posts as $post => $required) {
						if ($required) {
							if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						} else {
							if (isset($_POST[$post])) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						}
					}

					if (!$error) {

						$blogs = $db->from('blog')->where('blog_title', $blog_title)->first();

						if ($blogs) {

							$response->error = "Bu blog başlığı zaten mevcut, lütfen değiştiriniz.";
						} else {

							$blog_url = permalink($blog_url);

							$blogUrlQuery = $db->from('blog')->where('blog_url', $blog_url)->first();

							if (!$blogUrlQuery) {

								$query = $db->insert('blog')
									->set(array(
										'blog_title' => $blog_title,
										'blog_url' => $blog_url,
										'blog_content' => $blog_content,
										'blog_seotitle' => filter($_POST['blog_seotitle']),
										'blog_seodesc' => filter($_POST['blog_seodesc']),
										'blog_seokeyw' => filter($_POST['blog_seokeyw'])
									));

								if ($query) {
									$response->success = "Blog eklendi.";
								} else {
									$response->error = "Sistem hatası oluştu.";
								}
							} else {

								$response->error = "Bu blog urlsi sistemde zaten mevcut, lütfen değiştiriniz.";
							}
						}
					} else {
						$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
					}
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "add_bankaccount") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'edit')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					$posts = [
						"account_title" => true,
						"account_name" => true,
						"account_iban" => true,
						"account_number" => true,
						"account_branch" => true
					];

					$error = false;
					foreach ($posts as $post => $required) {
						if ($required) {
							if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						} else {
							if (isset($_POST[$post])) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						}
					}
					if (!$error) {

						$addAccount = $db->insert('bank_accounts')
							->set(array(
								'account_title' => $account_title,
								'account_name' => $account_name,
								'account_iban' => $account_iban,
								'account_number' => $account_number,
								'account_branch' => $account_branch
							));

						if ($addAccount) {
							$response->success = "Banka Hesabı Eklendi";
						} else {
							$response->error = "Sistem hatası oluştu.";
						}
					} else {
						$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
					}
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "update_links") {

		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'edit')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					$links = json_decode(json_encode($_POST['links']), true);

					if (!$links['account']['url'] || !$links['add-funds']['url'] || !$links['child']['url'] || !$links['auto']['url'] || !$links['autos']['url'] || !$links['blog']['url'] || !$links['contact']['url'] || !$links['drips']['url'] || !$links['faq']['url'] || !$links['forgot']['url'] || !$links['orders']['url'] || !$links['reff']['url'] || !$links['register']['url'] || !$links['reset']['url'] || !$links['services']['url'] || !$links['terms']['url'] || !$links['tickets']['url'] || !$links['page']['url']) {

						$response->error = "Boş veya hatalı veri mevcut, lütfen tüm alanları doldurunuz.";
					} else {

						$last = [

							"links" => [
								"account" => [
									"url" => permalink($links['account']['url'])
								],
								"page" => [
									"url" => permalink($links['page']['url'])
								],
								"add-funds" => [
									"url" => permalink($links['add-funds']['url'])
								],
								"auto" => [
									"url" => permalink($links['auto']['url'])
								],
								"autos" => [
									"url" => permalink($links['autos']['url'])
								],
								"blog" => [
									"url" => permalink($links['blog']['url']),
									"status" => $links['blog']['status']
								],
								"contact" => [
									"url" => permalink($links['contact']['url']),
									"status" => $links['contact']['status']
								],
								"child" => [
									"url" => permalink($links['child']['url'])
								],
								"drips" => [
									"url" => permalink($links['drips']['url'])
								],
								"faq" => [
									"url" => permalink($links['faq']['url']),
									"status" => $links['faq']['status']
								],
								"forgot" => [
									"url" => permalink($links['forgot']['url'])
								],
								"orders" => [
									"url" => permalink($links['orders']['url'])
								],
								"reff" => [
									"url" => permalink($links['reff']['url']),
									"status" => $links['reff']['status']
								],
								"register" => [
									"url" => permalink($links['register']['url'])
								],
								"login" => [
									"url" => "/",
								],
								"reset" => [
									"url" => permalink($links['reset']['url'])
								],
								"services" => [
									"url" => permalink($links['services']['url']),
									"status" => $links['services']['status']
								],
								"terms" => [
									"url" => permalink($links['terms']['url']),
									"status" => $links['terms']['status']
								],
								"tickets" => [
									"url" => permalink($links['tickets']['url'])
								],
							]

						];

						$update = $db->update('settings')->where('id', 1)
							->set(array(
								'site_links' => json_encode($last)
							));

						if ($update) {
							$response->success = "Bilgiler güncellendi.";
						} else {
							$response->error = "Sistem hatası oluştu.";
						}
					}
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "edit_bankaccount") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'edit')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					$posts = [
						"id" => true,
						"account_title" => true,
						"account_name" => true,
						"account_iban" => true,
						"account_number" => true,
						"account_branch" => true
					];

					$error = false;
					foreach ($posts as $post => $required) {
						if ($required) {
							if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						} else {
							if (isset($_POST[$post])) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						}
					}
					if (!$error) {

						$addAccount = $db->update('bank_accounts')
							->where('id', $id)
							->set(array(
								'account_title' => $account_title,
								'account_name' => $account_name,
								'account_iban' => $account_iban,
								'account_number' => $account_number,
								'account_branch' => $account_branch
							));

						if ($addAccount) {
							$response->success = "Banka Hesabı Güncellendi";
						} else {
							$response->error = "Sistem hatası oluştu.";
						}
					} else {
						$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
					}
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "update_announcement") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'edit')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {
					$posts = [
						"id" => true
					];
					$error = false;
					foreach ($posts as $post => $required) {
						if ($required) {
							if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						} else {
							if (isset($_POST[$post])) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						}
					}
					if (!$error) {
						$content = [];
						foreach ($_POST["content"] as $key => $val) {
							$key = filter($key);
							$val = filter($val, false);
							$content[] = [
								"lang" => intval($key),
								"content" => $val
							];
						}
						if (!empty($content)) {
							$content = json_encode($content);
							$query = $db->prepare("UPDATE `announcements` SET announcement_content = ? WHERE announcement_id = ?");
							$update_announcement = $query->execute([$content, $id]);
							if ($update_announcement) {
								$response->success = "Duyuru güncellendi.";
							} else {
								$response->error = "Sistem hatası oluştu.";
							}
						} else {
							$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
						}
					} else {
						$response->error = "{MESSAGE_WRONG_REQUEST}";
					}
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "delete_announcement") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'delete')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					$posts = [
						"id" => true
					];
					$error = false;
					foreach ($posts as $post => $required) {
						if ($required) {
							if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						} else {
							if (isset($_POST[$post])) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						}
					}
					if (!$error) {
						$query = $db->prepare("DELETE FROM `announcements` WHERE announcement_id = ?");
						$delete_announcement = $query->execute([$id]);
						if ($delete_announcement) {
							$response->reload = true;
						} else {
							$response->error = "Sistem hatası oluştu!";
						}
					} else {
						$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
					}
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "get_api_services") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {
				$posts = [
					"api" => true
				];
				$error = false;
				foreach ($posts as $post => $required) {
					if ($required) {
						if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
							$$post = filter($_POST[$post]);
						} else {
							$error = true;
							break;
						}
					} else {
						if (isset($_POST[$post])) {
							$$post = filter($_POST[$post]);
						} else {
							$error = true;
							break;
						}
					}
				}
				if (!$error) {
					$query = $db->prepare("SELECT * FROM `apis` WHERE api_id = ?");
					$query->execute([$api]);
					if ($query->rowCount()) {
						$api = $query->fetch(PDO::FETCH_ASSOC);
						$services = services($api["api_url"], $api["api_key"]);
						$html = '<option value="0">Seçilmedi</option>';
						if (!empty($services)) {
							foreach ($services as $service) {
								$html .= '<option value="' . $service["service"] . '" data-min="' . $service["min"] . '" data-max="' . $service["max"] . '" data-price="' . $service["rate"] . '">' . $service['service'] . ' -- ' . $service["name"] . ' -- ' . $service["rate"] . '</option>';
							}
							$response->edit = true;
							$response->type = "html";
							$response->item = "#service_list";
							$response->text = $html;
							$response->log = "Servisler güncellendi.";
						} else {
							$response->error = "Hata oluştu";
						}
					} else {
						$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
					}
				} else {
					$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "add_service") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'edit')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					$posts = [
						"type" => true,
						"auto_type" => false,
						"api" => false,
						"api_service" => false,
						"category" => true,
						"charge" => true,
						"cron_charge" => true,
						"min" => true,
						"service_fixed_price" => true,
						"max" => true,
						"drip" => true,
						"cancel_button" => true,
						"refill_button" => true,
						"refill_type" => true,
						"refill_day" => false,
						"refill_bekleme" => false
					];
					$error = false;
					foreach ($posts as $post => $required) {
						if ($required) {
							if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						} else {
							if (isset($_POST[$post])) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						}
					}

					if ($_POST['refill_button'] == 1) {
						if ($_POST['refill_type'] == 1) {
							if (empty($_POST['refill_day']) || empty($_POST['refill_bekleme'])) {
								$error = true;
							}
						}
					}


					if (!$error) {

						$nameS = Emoji::Encode($_POST['service_name']);
						$name = '[{"lang":1,"name":"' . $nameS . '"}]';
						$desc = '[{"lang":1,"name":"&amp;lt;strong&amp;gt;Dikkat Etmeniz Gerekenler:&amp;lt;/strong&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;★ Profiliniz gizli olmamalıdır.&amp;lt;br&amp;gt;★ Bir sipariş devam ederken ikinci siparişi girmemelisiniz.&amp;lt;br&amp;gt;★ Yoğunluğa bağlı olarak siparişlerin başlama ve yüklenme süreleri değişebilir.&amp;lt;br&amp;gt;"}]';

						if ($name != null) {
							$do_action = true;
							$service_auto = 0;
							$service_package = 0;
							$service_comment = 0;
							if ($type == 4) {
								$service_auto = 1;
								$drip = 0;
								$cancel_button = 0;
								$refill_button = 0;
								if (!$auto_type == 1 || !$auto_type == 2) {
									$do_action = false;
								}
							}
							if ($type == 3) {
								$service_comment = 1;
								$auto_type = 0;
								$drip = 0;
							}
							if ($type == 2) {
								$service_package = 1;
								$auto_type = 0;
								$min = 1;
								$max = 1;
							}
							if ($type == 1) {
								$auto_type = 0;
							}
							if ($do_action) {
								if ($min > 0 && $max > 0) {
									if ($api == 0) {
										$api_service = 0;
									} else {

										$query = $db->prepare("SELECT * FROM `apis` WHERE api_id = ?");
										$query->execute([$api]);

										if (!$query->rowCount()) {
											$do_action = false;
										}
									}
									if ($do_action) {

										if ($api_service != 0) {

											$apiQuery = $db->from('apis')->where('api_id', $api)->first();
											$apiQueryServices = services($apiQuery["api_url"], $apiQuery["api_key"]);
											$apiQueryBalance = api_balance($apiQuery["api_url"], $apiQuery["api_key"]);
											$apitype = 2;

											if ($apiQueryServices) {

												foreach ($apiQueryServices as $a => $row) {

													if ($row['service'] == $api_service) {

														$apiServiceDetail['min'] = $row['min'];
														$apiServiceDetail['max'] = $row['max'];
														$apiServiceDetail['rate'] = $row['rate'];
														$apiServiceDetail['currency'] = $apiQueryBalance['currency'];
														$apiServiceDetail = json_encode($apiServiceDetail);
													}
												}
											} else {

												$apiServiceDetail = null;
												$apitype = 0;
											}
										} else {

											$apiServiceDetail = null;
											$apitype = 0;
										}


										$query = $db->prepare("SELECT * FROM `categories` WHERE category_id = ?");
										$query->execute([$category]);
										if ($query->rowCount()) {
											$cronmax = array();
											if (isset($_POST['min_max_1'])) {
												$cronmax['min'] = 1;
											} else {
												$cronmax['min'] = 0;
											}
											if (isset($_POST['min_max_2'])) {
												$cronmax['max'] = 1;
											} else {
												$cronmax['max'] = 0;
											}
											$_service_auto_status = 0;
											if (isset($_POST['service_auto_status'])) {
												$_service_auto_status = $_POST['service_auto_status'];
											} else {
												$_service_auto_status = 0;
											}
											$cronmax = json_encode($cronmax);
											$query = $db->insert('services')
												->set(array(
													'service_auto_status' => $_service_auto_status,
													'category_id' => $category,
													'api_type' => $apitype,
													'api_id' => (($api != 0) ? $api : null),
													'api_Service' => (($api_service != 0) ? $api_service : null),
													'api_detail' => (($api_service != 0) ? $apiServiceDetail : null),
													'service_name' => $name,
													'service_charge' => round($charge, 5),
													'service_min' => $min,
													'service_fixed_price' => $service_fixed_price,
													'service_max' => $max,
													'service_auto' => $service_auto,
													'service_type' => (($service_auto == 1) ? $auto_type : null),
													'service_drip' => $drip,
													'service_package' => $service_package,
													'service_comment' => $service_comment,
													'cron_price_rate' => $cron_charge,
													'service_min_max' => $cronmax,
													'cancel_button' => $cancel_button,
													'refill_button' => $refill_button,
													'service_desc' => $desc,
													'refill_type' => $refill_type,
													'refill_day' => $refill_day,
													"refill_bekleme" => $refill_bekleme
												));

											if ($query) {
												$response->success = "Servis eklendi";
											} else {
												$response->error = "Sistem hatası oluştu!";
											}
										} else {
											$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
										}
									} else {
										$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
									}
								} else {
									$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
								}
							} else {
								$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
							}
						} else {
							$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
						}
					} else {
						$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
					}
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "update_service") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'edit')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					$posts = [
						"id" => true,
						"type" => true,
						"auto_type" => false,
						"api" => false,
						"api_service" => false,
						"category" => true,
						"charge" => true,
						"cron_charge" => true,
						"min" => true,
						"max" => true,
						"service_fixed_price" => true,
						"drip" => true,
						"cancel_button" => true,
						"refill_button" => true,
						"refill_type" => true,
						"refill_day" => false,
						"refill_bekleme" => false
					];
					$error = false;
					foreach ($posts as $post => $required) {

						if ($required) {
							if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						} else {
							if (isset($_POST[$post])) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						}
					}
					if (!$error) {
						$encodaname = Emoji::Encode($_POST['service_name']);
						$name = '[{"lang":1,"name":"' . $encodaname . '"}]';

						if ($name != null) {
							$do_action = true;
							$service_auto = 0;
							$service_package = 0;
							$service_comment = 0;
							if ($type == 4) {
								$service_auto = 1;
								$drip = 0;
								$cancel_button = 0;
								$refill_button = 0;
								if (!$auto_type == 1 || !$auto_type == 2) {
									$do_action = false;
								}
							}
							if ($type == 3) {
								$service_comment = 1;
								$auto_type = 0;
								$drip = 0;
							}
							if ($type == 2) {
								$service_package = 1;
								$auto_type = 0;
								$min = 1;
								$max = 1;
							}
							if ($type == 1) {
								$auto_type = 0;
							}
							if ($do_action) {
								if ($min > 0 && $max > 0) {
									if ($api == 0) {
										$api_service = 0;
									} else {
										$query = $db->prepare("SELECT * FROM `apis` WHERE api_id = ?");
										$query->execute([$api]);
										if (!$query->rowCount()) {
											$do_action = false;
										}
									}
									if ($do_action) {

										if ($api_service != 0) {

											$apiQuery = $db->from('apis')->where('api_id', $api)->first();
											$apiQueryServices = services($apiQuery["api_url"], $apiQuery["api_key"]);
											$apiQueryBalance = api_balance($apiQuery["api_url"], $apiQuery["api_key"]);
											$apitype = 2;

											if ($apiQueryServices) {
												foreach ($apiQueryServices as $a => $row) {
													if ($row['service'] == $api_service) {
														$apiServiceDetail['max'] = $row['max'];
														$apiServiceDetail['min'] = $row['min'];
														$apiServiceDetail['rate'] = $row['rate'];
														$apiServiceDetail['currency'] = $apiQueryBalance['currency'];
														$apiServiceDetail = json_encode($apiServiceDetail);
													}
												}
											} else {

												$apiServiceDetail = null;
												$apitype = 0;
											}
										} else {

											$apiServiceDetail = null;
											$apitype = 0;
										}

										$query = $db->prepare("SELECT * FROM `categories` WHERE category_id = ?");
										$query->execute([$category]);
										if ($query->rowCount()) {
											$cronmax = array();
											if (isset($_POST['min_max_1'])) {
												$cronmax['min'] = 1;
											} else {
												$cronmax['min'] = 0;
											}
											if (isset($_POST['min_max_2'])) {
												$cronmax['max'] = 1;
											} else {
												$cronmax['max'] = 0;
											}
											$_service_auto_status = 0;
											if (isset($_POST['service_auto_status'])) {
												$_service_auto_status = $_POST['service_auto_status'];
											} else {
												$_service_auto_status = 0;
											}	
											$cronmax = json_encode($cronmax);
											$update_service = $db->update('services')
												->where('service_id', $id)
												->set(array(
													'service_auto_status' => $_service_auto_status,
													'category_id' => $category,
													'api_type' => $apitype,
													'api_id' => (($api != 0) ? $api : null),
													'api_Service' => (($api_service != 0) ? $api_service : null),
													'api_detail' => (($api_service != 0) ? $apiServiceDetail : null),
													'service_name' => $name,
													'service_charge' => round($charge, 5),
													'service_min' => $min,
													'service_fixed_price' => $service_fixed_price,
													'service_max' => $max,
													'service_auto' => $service_auto,
													'service_type' => (($service_auto == 1) ? $auto_type : null),
													'service_drip' => $drip,
													'service_package' => $service_package,
													'service_comment' => $service_comment,
													'cron_price_rate' => $cron_charge,
													'service_min_max' => $cronmax,
													'cancel_button' => $cancel_button,
													'refill_button' => $refill_button,
													'refill_type' => $refill_type,
													'refill_day' => $refill_day,
													'refill_bekleme' => $refill_bekleme
												));

											if ($update_service) {
												$response->reload = true;
											} else {
												$response->error = "Sistem hatası oluştu!";
											}
										} else {
											$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
										}
									} else {
										$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
									}
								} else {
									$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
								}
							} else {
								$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
							}
						} else {
							$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
						}
					} else {
						$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
					}
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "delete_service") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'delete')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					$posts = [
						"id" => true
					];
					$error = false;
					foreach ($posts as $post => $required) {
						if ($required) {
							if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						} else {
							if (isset($_POST[$post])) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						}
					}
					if (!$error) {
						$query = $db->prepare("DELETE FROM `services` WHERE service_id = ?");
						$delete_service = $query->execute([$id]);
						if ($delete_service) {
							$response->reload = true;
						} else {
							$response->error = "Sistem hatası oluştu!";
						}
					} else {
						$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
					}
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "delete_service_indirim") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'delete')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					$posts = [
						"id" => true
					];
					$error = false;
					foreach ($posts as $post => $required) {
						if ($required) {
							if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						} else {
							if (isset($_POST[$post])) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						}
					}
					if (!$error) {
						$query = $db->prepare("DELETE FROM `special_offers` WHERE service_id = ?");
						$delete_service = $query->execute([$id]);
						if ($delete_service) {
							$response->reload = true;
						} else {
							$response->error = "Sistem hatası oluştu!";
						}
					} else {
						$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
					}
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "delete_service_indirim_uye") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'delete')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					$posts = [
						"id" => true
					];
					$error = false;
					foreach ($posts as $post => $required) {
						if ($required) {
							if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						} else {
							if (isset($_POST[$post])) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						}
					}
					if (!$error) {
						$query = $db->prepare("DELETE FROM `special_offers` WHERE user_id = ?");
						$delete_service = $query->execute([$id]);
						if ($delete_service) {
							$response->reload = true;
						} else {
							$response->error = "Sistem hatası oluştu!";
						}
					} else {
						$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
					}
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "delete_service_discount") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'delete')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					$posts = [
						"id" => true
					];
					$error = false;
					foreach ($posts as $post => $required) {
						if ($required) {
							if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						} else {
							if (isset($_POST[$post])) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						}
					}
					if (!$error) {

						$query = $db->delete('special_offers')->where('service_id', $id)->done();

						if ($query) {
							$response->success = "Servise ait tüm indirimler silindi.";
						} else {
							$response->error = "Silinecek veri bulunamadı veya sistem hatası oluştu, daha sonra tekrar deneyiniz.";
						}
					} else {
						$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
					}
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "add_api") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'edit')) {
					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					$posts = [
						"url" => true,
						"key" => true
					];
					$error = false;
					foreach ($posts as $post => $required) {
						if ($required) {
							if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						} else {
							if (isset($_POST[$post])) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						}
					}
					if (!$error) {
						$query = $db->prepare("INSERT INTO `apis` SET api_key = ?, api_url = ?");
						$insert_api = $query->execute([$key, $url]);
						if ($insert_api) {
							$response->success = "API eklendi";
						} else {
							$response->error = "Sistem hatası oluştu.";
						}
					} else {
						$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
					}
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "update_api") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'edit')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					$posts = [
						"id" => true,
						"url" => true,
						"key" => true
					];
					$error = false;
					foreach ($posts as $post => $required) {
						if ($required) {
							if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						} else {
							if (isset($_POST[$post])) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						}
					}
					if (!$error) {
						$query = $db->prepare("UPDATE `apis` SET api_key = ?, api_url = ? WHERE api_id = ?");
						$update_api = $query->execute([$key, $url, $id]);
						if ($update_api) {
							$response->success = "API güncellendi";
						} else {
							$response->error = "Sistem hatası oluştu.";
						}
					} else {
						$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
					}
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "delete_api") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'delete')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					$posts = [
						"id" => true
					];
					$error = false;
					foreach ($posts as $post => $required) {
						if ($required) {
							if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						} else {
							if (isset($_POST[$post])) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						}
					}
					if (!$error) {
						$query = $db->prepare("DELETE FROM `apis` WHERE api_id = ?");
						$delete_api = $query->execute([$id]);
						if ($delete_api) {
							$response->reload = true;
						} else {
							$response->error = "Sistem hatası oluştu!";
						}
					} else {
						$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
					}
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "update_order_status") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {


				if (!permission('access', 'edit')) {
					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					$posts = [
						"id" => true,
						"remains" => true,
						"status" => true
					];
					$error = false;
					foreach ($posts as $post => $required) {
						if ($required) {
							if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						} else {
							if (isset($_POST[$post])) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						}
					}

					if (!$error) {

						if ($status == "Completed") {

							$remains = 0;

							$updateOrder = $db->update('orders')
								->where('order_id', $id)
								->set(array(
									'order_remains' => $remains,
									'order_status' => $status,
									'update_date' => time(),
									'is_failed' => 0
								));


							if ($updateOrder) {
								$response->reload = true;
							} else {
								$response->error = "Sistem hatası oluştu!";
							}
						} elseif ($status == "Partial") {

							$proccess = partial_order($id, $remains);

							if ($proccess) {

								$response->reload = true;
							} else {

								$response->error = "İşleminiz gerçekleştirilemedi, daha sonra tekrar deneyiniz.";
							}
						} elseif ($status == "Canceled") {

							$proccess = cancel_order($id);
							if ($proccess) {

								$response->reload = true;
							} else {

								$response->error = "İşleminiz gerçekleştirilemedi, daha sonra tekrar deneyiniz.";
							}
						} else {

							$updateOrder = $db->update('orders')
								->where('order_id', $id)
								->set(array(
									'api_id' => NULL,
									'api_order_id' => NULL,
									'api_order_amount' => NULL,
									'api_order_currency' => NULL,
									'order_remains' => $remains,
									'order_status' => $status,
									'update_date' => time(),
									'is_failed' => 0
								));


							if ($updateOrder) {
								$response->reload = true;
							} else {
								$response->error = "Sistem hatası oluştu!";
							}
						}
					} else {
						$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
					}
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "update_order_count") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'edit')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					$posts = [
						"id" => true,
						"count" => true
					];
					$error = false;
					foreach ($posts as $post => $required) {
						if ($required) {
							if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						} else {
							if (isset($_POST[$post])) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						}
					}
					if (!$error) {

						$order = $db->from('orders')->where('order_id', $id)->first();

						if ($order) {

							$updateOrder = $db->update('orders')
								->where('order_id', $id)
								->set(array(
									'order_start_count' => $count
								));

							if ($updateOrder) {
								$response->success = "Sipariş başlangıç sayısı başarıyla güncellendi.";
							} else {
								$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
							}
						} else {

							$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
						}
					} else {
						$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
					}
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "task_deny") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'edit')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					$posts = [
						"id" => true,
						"type" => true
					];
					$error = false;
					foreach ($posts as $post => $required) {
						if ($required) {
							if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						} else {
							if (isset($_POST[$post])) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						}
					}
					if (!$error) {

						$task = $db->from('tasks')->where('task_id', $id)->first();

						if ($task) {

							if ($task['task_status'] == 2) {

								$response->error = "Bu işlem zaten reddedilmiş.";
							} else {

								$updateTask = $db->update('tasks')
									->where('task_id', $id)
									->set(array(
										'task_status' => 2,
										'task_updatedate' => date("Y-m-d H:i:s"),
									));

								if ($updateTask) {
									$response->reload = true;
								} else {
									$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
								}
							}
						} else {

							$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
						}
					} else {
						$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
					}
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "task_confirm") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'edit')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					$posts = [
						"id" => true,
						"type" => true
					];
					$error = false;
					foreach ($posts as $post => $required) {
						if ($required) {
							if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						} else {
							if (isset($_POST[$post])) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						}
					}
					if (!$error) {

						$task = $db->from('tasks')->where('task_id', $id)->first();

						if ($task) {

							if ($task['task_status'] == 1) {

								$response->error = "Bu işlem zaten onaylanmış.";
							} else {

								if ($type == 2) {

									$updateTask = $db->update('tasks')
										->where('task_id', $id)
										->set(array(
											'task_status' => 1,
											'task_updatedate' => date("Y-m-d H:i:s"),
										));

									$cancel_order = cancel_order($task['order_id']);

									if ($updateTask && $cancel_order) {
										$response->reload = true;
									} else {
										$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
									}
								} else {

									$updateTask = $db->update('tasks')
										->where('task_id', $id)
										->set(array(
											'task_status' => 1,
											'task_updatedate' => date("Y-m-d H:i:s")
										));

									if ($updateTask) {
										$response->reload = true;
									} else {
										$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
									}
								}
							}
						} else {

							$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
						}
					} else {
						$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
					}
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "get_order") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'orders')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					$posts = [
						"id" => true
					];
					$error = false;
					foreach ($posts as $post => $required) {
						if ($required) {
							if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						} else {
							if (isset($_POST[$post])) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						}
					}
					if (!$error) {
						$query = $db->prepare("SELECT O.*, S.service_name, U.user_username FROM `orders` AS O LEFT JOIN `services` AS S ON S.service_id = O.service_id LEFT JOIN `users` AS U ON U.user_id = O.user_id WHERE order_id = ?");
						$query->execute([$id]);
						if ($query->rowCount()) {
							$status_list = [
								"completed" => "Completed",
								"canceled" => "Canceled",
								"partial" => "Partial",
								"pending" => "Pending",
								"inprogress" => "In progress",
								"processing" => "Processing"
							];
							$order = $query->fetch(PDO::FETCH_ASSOC);
							$key = array_search($order["order_status"], $status_list);
							if ($key !== false) {
								$order["order_status"] = "{ORDERS_STATUS_" . str_replace(" ", "", strtoupper($status_list[$key])) . "}";
							}
							if ($order["service_name"] != null) {
								$service_name = json_decode($order["service_name"], true);
								$name = null;
								foreach ($service_name as $details) {
									if ($details["lang"] == 1) {
										$name = $details["name"];
									}
								}
								$order["service_name"] = $name;
							} else {
								$order["service_name"] = "Silinmiş";
							}
							if ($order["user_username"] == null) {
								$order["user_username"] = "Silinmiş";
							}
							$title = "Sipariş Görüntüle (" . $order['order_id'] . ")";
							$html = '
									<div class="form-group">
										<div class="input-group">
											<span class="input-group-addon"><b>Servis</b></span>
											<input type="text" value="[#' . $order["service_id"] . '] ' . $order["service_name"] . '" class="form-control" readonly="">
										</div>
									</div>
									<div class="row">
										<div class="form-group col-md-6">
											<div class="input-group">
												<span class="input-group-addon"><b>Oluşturulma Tarihi</b></span>
												<input type="text" value="' . str_date(date("y-m-d H:i:s", $order["order_date"])) . '" class="form-control" readonly="">
											</div>
										</div>
										<div class="form-group col-md-6">
											<div class="input-group">
												<span class="input-group-addon"><b>Son Güncellenme Tarihi</b></span>
												<input type="text" value="' . str_date(date("y-m-d H:i:s", $order["update_date"])) . '" class="form-control" readonly="">
											</div>
										</div>
									</div>';
							if ($order['is_failed'] == 1) :
								$html .= '<div class="form-group">
											<div class="input-group">
												<span class="input-group-addon"><b>Sağlayıcıdan Gelen Bilgi</b></span>
												<textarea class="form-control" readonly="">' . $order["order_detail"] . '</textarea>
											</div>
										</div>';
							endif;
							if ($order['api_order_id'] != null) :
								$html .= '
										<div class="row">
											<div class="form-group col-md-6">
												<div class="input-group">
													<span class="input-group-addon"><b>API Sipariş ID</b></span>
													<input type="text" value="' . $order["api_order_id"] . '" class="form-control" readonly="">
												</div>
											</div>
											<div class="form-group col-md-6">
												<div class="input-group">
													<span class="input-group-addon"><b>API Sipariş Tutarı</b></span>
													<input type="text" value="' . $order["api_order_currency"] . " " . $order["api_order_amount"] . '" class="form-control" readonly="">
												</div>
											</div>
										</div>
										<div class="form-group">
											<div class="input-group">
												<span class="input-group-addon"><b>Sağlayıcıdan Gelen Bilgi</b></span>
												<textarea class="form-control" readonly="">' . $order["order_detail"] . '</textarea>
											</div>
										</div>';
							endif;

							if ($order['order_comments'] != null) :
								$html .= '
										
										<div class="form-group">
											<div class="input-group">
												<span class="input-group-addon"><b>Sipariş Yorumları</b></span>
												<textarea class="form-control" rows="5" readonly="">' . $order["order_comments"] . '</textarea>
											</div>
										</div>';
							endif;



							$response->title = $title;
							$response->order = $html;
						} else {
							$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
						}
					} else {
						$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
					}
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "get_update") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'orders')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					$title = "Yazılım Güncellemesi (Dikkat!)";
					$html = '<center><b>Bu uyarıyı okumadan lütfen güncelleme yapmayınız!</b></center></br>
						<p>Güncelleme işlemini başlatmadan önce site dosyalarınızın ve veritabanınızın yedeğini almayı unutmayınız. Güncelleme sırasında yaşanabilecek olası problemler sebebiyle veri kaybı yaşayabilirsiniz bu sebepten ötürü yedek almadan lütfen güncelleme işlemi başlatmayınız.<br></p>
						<ul>
							<li>Güncellemeyi başlat tuşuna tıkladıktan sonra lütfen sayfayı yenilemeyiniz.</li>
							<li>Güncelleme tamamlanınca başarılı mesajı alacaksınız, başarılı mesajı alana kadar sayfayı veya pencereyi kapatmayınız.</li>
							<li>Tam Veritabanı yedeği almadan bu işlemi başlatmayınız.</li>
							<li>Tam Dosya yedeği almadan bu işlemi başlatmayınız.</li>
							<li>Eğer güncelleme sırasında bir hata alırsanız ve siteniz doğru şekilde çalışmazsa aldığınız yedeği sitenize geri kurup, manuel güncelleme için bir yetkiliye ulaşınız.</li>
						</ul>
						<button class="btn btn-default btn-block" onclick="updateScript()">Uyarıyı Okudum ve Anladım, Güncellemeyi Başlat</button>
						';
					$response->title = $title;
					$response->order = $html;
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "add_bonus_form") {

		if (session('login')) {

			if (!permission('access', 'edit')) {

				$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
			} else {

				$posts = [
					"bonus_method" => true,
					"bonus_amount" => true,
					"bonus_from" => true
				];

				$error = false;
				foreach ($posts as $post => $required) {
					if ($required) {
						if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
							$$post = filter($_POST[$post]);
						} else {
							$error = true;
							break;
						}
					} else {
						if (isset($_POST[$post])) {
							$$post = filter($_POST[$post]);
						} else {
							$error = true;
							break;
						}
					}
				}

				if (!$error) {

					$insert = $db->insert('payment_bonus')
						->set(array(
							'bonus_method' => $bonus_method,
							'bonus_from' => $bonus_from,
							'bonus_amount' => $bonus_amount
						));

					if ($insert) {
						$response->success = "Ödeme bonusu başarıyla eklendi.";
					} else {
						$response->error = "Sistem hatası oluştu, daha sonra tekrar deneyiniz.";
					}
				} else {

					$response->error = "{MESSAGE_WRONG_REQUEST}s";
				}
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "delete_bonus") {

		if (session('login')) {

			if (!permission('access', 'delete')) {

				$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
			} else {

				$posts = [
					"id" => true
				];

				$error = false;
				foreach ($posts as $post => $required) {
					if ($required) {
						if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
							$$post = filter($_POST[$post]);
						} else {
							$error = true;
							break;
						}
					} else {
						if (isset($_POST[$post])) {
							$$post = filter($_POST[$post]);
						} else {
							$error = true;
							break;
						}
					}
				}

				if (!$error) {

					$bonus = $db->from('payment_bonus')->where('bonus_id', $id)->first();

					if ($bonus) {

						$delete = $db->delete('payment_bonus')->where('bonus_id', $id)->done();

						if ($delete) {
							$response->reload = true;
						} else {
							$response->error = "Sistem hatası nedeniyle işleminiz gerçekleştirilemedi.";
						}
					} else {
						$response->error = "Silinmek istenen veri, veritabanında bulunamadı.";
					}
				} else {

					$response->error = "{MESSAGE_WRONG_REQUEST}s";
				}
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "add_bonus") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'bonuses')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					$methods = $db->from('payment_methods')->all();

					$title = "Yeni Bonus Oluştur";
					$html = '
						<form id="add_bonus_form" onsubmit="return false;" data-reset="1">
							<div class="form-group">
								<div class="input-group">
									<span class="input-group-addon"><b>Ödeme Methodu</b></span>
									<select class="form-control" name="bonus_method">';
					foreach ($methods as $row) :
						if ($row['method_id'] != 7) :
							$html .= '<option value="' . $row['method_id'] . '">' . $row['method_title'] . '</option>';
						endif;
					endforeach;
					$html .= '</select>
								</div>
							</div>
							<div class="form-group">
								<div class="input-group">
									<span class="input-group-addon"><b>Bonus Tutarı (%)</b></span>
									<input type="double" min="1" name="bonus_amount" class="form-control">
								</div>
							</div>
							<div class="form-group">
								<div class="input-group">
									<span class="input-group-addon"><b>İtibaren (TL)</b></span>
									<input type="double" min="1" name="bonus_from" class="form-control">
								</div>
							</div>
							<div class="form-group">
								<button type="submit" class="btn btn-default">Oluştur</button>
							</div>
						</form>
						';
					$response->title = $title;
					$response->order = $html;
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "add_menu_form") {

		if (session('login')) {

			if (!permission('access', 'edit')) {

				$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
			} else {

				$posts = [
					"page" => true,
					"menu_type" => true,
					"title" => true,
					"menu_icon" => true
				];

				$error = false;
				foreach ($posts as $post => $required) {
					if ($required) {
						if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
							$$post = filter($_POST[$post]);
						} else {
							$error = true;
							break;
						}
					} else {
						if (isset($_POST[$post])) {
							$$post = filter($_POST[$post]);
						} else {
							$error = true;
							break;
						}
					}
				}

				if (!$error) {

					$menu_icon = $_POST['menu_icon'];

					if ($page == "none") {

						$link = $_POST['custom_link'];

						if ($link) {
							$error = false;
						}
					} else {


						if ($page == "1") {
							$link = "../";
							$error = false;
						} elseif ($page == "2") {
							$link = "auto";
							$error = false;
						} elseif ($page == "3") {
							$link = 'orders';
							$error = false;
						} elseif ($page == "4") {
							$link = 'services';
							$error = false;
						} elseif ($page == "5") {
							$link = 'add-funds';
							$error = false;
						} elseif ($page == "6") {
							$link = 'tickets';
							$error = false;
						} elseif ($page == "7") {
							$link = 'reff';
							$error = false;
						} elseif ($page == "8") {
							$link = "/api";
							$error = false;
						} elseif ($page == "9") {
							$link = 'drips';
							$error = false;
						} elseif ($page == "10") {
							$link = 'autos';
							$error = false;
						} elseif ($page == "11") {
							$link = 'login';
							$error = false;
						} elseif ($page == "12") {
							$link = 'register';
							$error = false;
						} elseif ($page == "14") {
							$link = 'child';
							$error = false;
						}


						if (!$error) {

							$insert = $db->insert('menus')
								->set(array(
									'menu_type' => $menu_type,
									'menu_lock' => 0,
									'menu_link' => $link,
									'menu_title' => $title,
									'menu_icon' => $menu_icon
								));

							if ($insert) {
								$response->reload = true;
							} else {
								$response->error = "İşleminiz gerçekleştirilemedi.";
							}
						} else {

							$response->error = "İşleminiz gerçekleştirilemedi.";
						}
					}
				} else {

					$response->error = "{MESSAGE_WRONG_REQUEST}s";
				}
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "add_menu") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'menus')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					$pages = $db->from('pages')->all();

					$title = "Yeni Menü Oluştur";
					$html = '
						<form id="add_menu_form" onsubmit="return false;" data-reset="1">
							<div class="alert alert-success alert-dismissible text-center" role="alert">
							Bu form ile sayfalarınıza özel menü oluşturabilirsiniz.
							</div>
							
							<div class="form-group 1">
								<div class="input-group">
									<span class="input-group-addon"><b>Menü Tipi</b></span>
									<select class="form-control" name="menu_type">
										<option value="1">Giriş Yapanlar</option>
										<option value="2">Giriş Yapmayanlar</option>
									</select>
								</div>
							</div>
							
							<div class="form-group 2">
								<div class="input-group">
									<span class="input-group-addon"><b>Bağlantılı Sayfa</b></span>
									<select class="form-control" name="page">
    									<option value="none">-- Seçilmedi --</option>
    									<option style="font-weight: bold;background: #bb1b40;color: white;font-size: 17px;" value="1">Yeni Sipariş</option>
    									<option style="font-weight: bold;background: #bb1b40;color: white;font-size: 17px;" value="2">Abonelik</option>
    									<option style="font-weight: bold;background: #bb1b40;color: white;font-size: 17px;" value="3">Siparişler</option>
    									<option style="font-weight: bold;background: #bb1b40;color: white;font-size: 17px;" value="4">Fiyat Listesi</option>
    									<option style="font-weight: bold;background: #bb1b40;color: white;font-size: 17px;" value="5">Bakiye Ekle</option>
    									<option style="font-weight: bold;background: #bb1b40;color: white;font-size: 17px;" value="6">Destek</option>
    									<option style="font-weight: bold;background: #bb1b40;color: white;font-size: 17px;" value="7">Referans</option>
    									<option style="font-weight: bold;background: #bb1b40;color: white;font-size: 17px;" value="8">API</option>
    									<option style="font-weight: bold;background: #bb1b40;color: white;font-size: 17px;" value="9">Süreli Siparişler</option>
    									<option style="font-weight: bold;background: #bb1b40;color: white;font-size: 17px;" value="14">Child Panel</option>
    									<option style="font-weight: bold;background: #bb1b40;color: white;font-size: 17px;" value="10">Abonelikler</option>
    									<option style="font-weight: bold;background: #7d7dff;color: white;font-size: 17px;" value="11">Giriş Yap</option>
    									<option style="font-weight: bold;background: #7d7dff;color: white;font-size: 17px;" value="12">Kayıt Ol</option>
    									<option style="font-weight: bold;background: #7d7dff;color: white;font-size: 17px;" value="13">Fiyat Listesi</option>
									</select>
								</div>
							</div>
							
							<div class="form-group 3">
								<div class="input-group">
									<span class="input-group-addon"><b>İkon</b></span>
									<input type="text" name="menu_icon" placeholder="fas fa-user" class="form-control">
									<a href="https://fontawesome.com/icons?m=free" target="_blank" style="position: absolute;right: 10px;top: 20%;z-index: 999;">İkonlar</a>
								</div>
							</div>
							
							<div class="form-group 4">
								<div class="input-group">
									<span class="input-group-addon"><b>Başlık</b></span>
									<input type="text" name="title" class="form-control">
								</div>
							</div>
							
							<div class="form-group 5">
								<button type="submit" class="btn btn-default">Oluştur</button>
							</div>
							
						</form>
						';
					$response->title = $title;
					$response->order = $html;
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "get_service") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'services')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					$error = false;

					if (!$error) {

						$categories = $db->from('categories')->orderby('category_number', 'ASC')->all();
						$apis = $db->from('apis')->orderby('api_id', 'ASC')->all();

						$tempCategories = [];
						foreach ($categories as $category) {
							$category_name = json_decode($category["category_name"], true);
							$name = null;
							foreach ($category_name as $details) {
								if ($details["lang"] == 1) {
									$name = $details["name"];
								}
							}
							$category["category_name"] = $name;
							$tempCategories[] = $category;
						}
						$categories = $tempCategories;

						$title = "Yeni Servis Oluştur";
						$html  = '<form id="add_service" onsubmit="return false;" data-reset="1">
										<div class="form-group">
											<div class="input-group">
												<span class="input-group-addon"><b>Servis Adı</b></span>
												<input type="text" name="service_name" class="form-control">
											</div>
										</div>
										<div class="form-group">
											<div class="input-group">
												<span class="input-group-addon"><b>Servis Kategorisi</b></span>
												<select name="category" class="form-control">';
						foreach ($categories as $category) :
							$html .= '<option value="' . $category["category_id"] . '">' . $category["category_name"] . '</option>';
						endforeach;
						$html .= '</select>
												</div>
											</div>
											<div class="box">
												<div class="form-group">
													<div class="input-group">
														<span class="input-group-addon"><b>Servis Tipi</b></span>
														<select id="service_type" name="type" onchange="change_type()" class="form-control form-control-sm">
															<option value="1">Normal</option>
															<option value="2">Paket</option>
															<option value="3">Özel Yorum</option>
															<option value="4">Abonelik</option>
														</select>
													</div>
												</div>
												<div id="service_auto" class="form-group hide">
													<div class="input-group">
														<span class="input-group-addon"><b>Abonelik Tipi</b></span>
														<select name="auto_type" class="form-control">
															<option value="1">Instagram İzlenme</option>
															<option value="2">Instagram Beğeni</option>
														</select>
													</div>
												</div>
												<hr>
												<div class="form-group">
													<div class="input-group">
														<span class="input-group-addon"><b>Servis Sağlayıcı</b></span>
														<select id="service-api" name="api" onchange="change_api();$(this).click()" class="form-control form-control-sm mb-2">
															<option value="0">Manuel Servis (Sağlayıcı Seçilmedi)</option>';
						foreach ($apis as $api) :
							$html .= '<option value="' . $api["api_id"] . '">' . $api["api_url"] . '</option>';
						endforeach; // onchange="sabit_fiyat_guncelle()"
						$html .= '</select>
													</div>
												</div>
											
												<div class="form-group api_service_list_area" style="display:none">
													<div class="input-group">
														<span class="input-group-addon"><b>API Servisi</b></span>
														<select id="service_list" name="api_service" onchange="change_api_service()" class="form-control form-control-sm mb-2">
															<option value="0">Seçilmedi</option>
														</select>
													</div>
												</div>
											</div>
											<div class="row">
											<div class="col-md-4">
											<div class="form-group">
												<div class="input-group">
													<span class="input-group-addon"><b>Servis Fiyatı (1000 Adet)</b></span>
													<input type="text" name="charge" id="service_price" class="form-control" required>
												</div>
											</div>
											</div>										
											<div class="col-md-4">
											<div class="form-group">
												<div class="input-group">
													<span class="input-group-addon"><b>Otomatik Fiyat Yüzdesi</b></span>
													<input type="number" min="0" name="cron_charge" value="0" id="cron_price_rate" class="form-control" required>
												</div>
											</div>
											</div>
											<div class="col-md-4">
											<div class="form-group">
												<div class="input-group">
													<span class="input-group-addon"><b>Sabit Kar (TL)</b></span>
													<input type="double" min="0" name="service_fixed_price"  placeholder="0" id="service_fixed_price" class="form-control" required>
												</div>
											</div>
											</div>
											</div>
											<div class="row" id="service_quantity">
												<div class="col-md-6">
													<div class="form-group">
														<div class="input-group">
															<span class="input-group-addon"><b>Minimum Sipariş <input type="checkbox" checked name="min_max_1"></b></span>
															<input type="number" name="min" id="service_min" class="form-control" required>
														</div>
													</div>
												</div>
												<div class="col-md-6">
													<div class="form-group">
														<div class="input-group">
															<span class="input-group-addon"><b>Maksimum Sipariş <input type="checkbox" checked name="min_max_2"></b></span>
															<input type="number" name="max" id="service_max" class="form-control" required>
														</div>
													</div>
												</div>
											</div>
																						
											<hr>
											<div class="row" id="service_buttons">
												<div class="col-md-12">
													<div class="form-group">
														<div class="input-group">
															<span class="input-group-addon"><b>İptal Tuşu</b></span>
															<select name="cancel_button" class="form-control">
																<option value="0" selected>Pasif</option>
																<option value="1">Aktif</option>
															</select>
														</div>
													</div>
												</div>
											</div>
											<div class="row" id="service_buttons">
												<div class="col-md-6">
													<div class="form-group">
														<div class="input-group">
															<span class="input-group-addon"><b>Telafi Tuşu</b></span>
															<select name="refill_button" class="form-control refill_toggle">
																<option value="0" selected>Pasif</option>
																<option value="1">Aktif</option>
															</select>
														</div>
													</div>
												</div>
												<div class="col-md-6 refill_type_area" style="display:none">
													<div class="form-group">
														<div class="input-group">
															<span class="input-group-addon"><b>Telafi Tipi</b></span>
															<select name="refill_type" class="form-control refiltype_toggle">
																<option value="1" selected>Manuel</option>
																<option value="2">Otomatik (Sadece Perfect Panelde API ile Çalışır)</option>
															</select>
														</div>
													</div>
												</div>
											</div>
											<div class="row refill_options_area" style="display:none">
												<div class="col-md-6">
													<div class="form-group">
														<div class="input-group">
															<span class="input-group-addon"><b>Refill Maksimum Gün (Lifetime ise 0 yazınız)</b></span>
															<input type="number" name="refill_day" class="form-control">
														</div>
													</div>
												</div>
												<div class="col-md-6">
													<div class="form-group">
														<div class="input-group">
															<span class="input-group-addon"><b>Refill Bekleme Saati</b></span>
															<input type="number" name="refill_bekleme" class="form-control">
														</div>
														<small>Refill butonunun gösterim aralığı (saat cinsinden)</small>
													</div>
												</div>
											</div>
											<div class="row aktif_pasif_area" style="display:none">
												<div class="col-md-12">
													<div class="form-group">
														<div class="input-group">
															<span class="input-group-addon"><b>Aktif/Pasif Api Sistemi</b></span>
															<select name="service_auto_status" class="form-control">
																<option value="0">Manuel</option>
																<option value="1">Sağlayıcıda durum değişirse otomatik değiştir</option>
																<option value="2">Sağlayıcıda durum değişirse uyar</option>
																<option value="3" selected>Sağlayıcıda durum değişirse uyar ve değiştir</option>
															</select>
														</div>
													</div>
												</div>
											</div>

											<div class="form-group" id="service_drip">
												<div class="input-group">
													<span class="input-group-addon"><b>Süreli Sipariş</b></span>
													<select name="drip" class="form-control">
														<option value="0">Hayır</option>
														<option value="1">Evet</option>
													</select>
												</div>
											</div>
											<div class="form-group">
												<button type="submit" class="btn btn-success"><span class="text">Yeni Servisi Oluştur</span></button>
											</div>
										</form>
										<script>

											function change_type() {
												var type = $("#service_type").val();
												if(type == 1) {
													$("#service_quantity").removeClass("hide");
													$("#service_drip").removeClass("hide");
													$("#service_auto").addClass("hide");
													$("#service_buttons").removeClass("hide");
												} else if(type == 2) {
													$("#service_quantity").addClass("hide");
													$("#service_min, #service_max").val("1");
													$("#service_drip").removeClass("hide");
													$("#service_auto").addClass("hide");
													$("#service_buttons").removeClass("hide");
												} else if(type == 3) {
													$("#service_quantity").removeClass("hide");
													$("#service_drip").addClass("hide");
													$("select[name=drip]").val("0");
													$("#service_auto").addClass("hide");
													$("#service_buttons").removeClass("hide");
												} else if(type == 4) {
													$("#service_quantity").removeClass("hide");
													$("#service_drip").addClass("hide");
													$("select[name=drip]").val("0");
													$("#service_auto").removeClass("hide");
													$("#service_buttons").addClass("hide");

												}
											}
											function change_api() {
												var api = $("#service-api").val();
												if(api != "0") {
													post("get_api_services", {api:api});
												}
											}
											function change_api_service() {
												var type = $("#service_type").val();
												var selected = $("#service_list").find("option:selected");
												if($("#autoUpdate").is(":checked")) {
													if(type != 2) {
														$("#service_min").val(selected.data("min"));
														$("#service_max").val(selected.data("max"));
													}
													var price = selected.data("price");


													$("#service_price").val(price);
												}
											}
										</script>';
						$response->title = $title;
						$response->order = $html;
					} else {
						$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
					}
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "edit_service") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'services')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					$posts = [
						"id" => true
					];

					$error = false;

					foreach ($posts as $post => $required) {
						if ($required) {
							if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						} else {
							if (isset($_POST[$post])) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						}
					}

					$service = $db->from('services')->where('service_id', $id)->first();

					if ($service) {
						$error = false;
					} else {
						$error = true;
					}

					if (!$error) {

						$categories = $db->from('categories')->orderby('category_number', 'ASC')->all();
						$apis = $db->from('apis')->orderby('api_id', 'ASC')->all();

						$tempCategories = [];
						foreach ($categories as $category) {
							$category_name = json_decode($category["category_name"], true);
							$name = null;
							foreach ($category_name as $details) {
								if ($details["lang"] == 1) {
									$name = $details["name"];
								}
							}
							$category["category_name"] = $name;
							$tempCategories[] = $category;
						}
						$categories = $tempCategories;

						$type = 1;
						if ($service["service_package"]) {
							$type = 2;
						} elseif ($service["service_comment"]) {
							$type = 3;
						} elseif ($service["service_auto"]) {
							$type = 4;
						}

						$name = json_decode($service['service_name'], true);
						$minmax = json_decode($service['service_min_max'], true);
						$title = "Servis Düzenle  <a class='close' data-dismiss='modal'>×</a>";
						$html  = '<form id="update_service" onsubmit="return false;" data-reset="0">
										<div class="form-group">
											<div class="input-group">
												<span class="input-group-addon"><b>Servis Adı</b></span>
												<input type="text" name="service_name" class="form-control" value="' . $name[0]['name'] . '">
											</div>
										</div>
										<div class="form-group">
											<div class="input-group">
												<span class="input-group-addon"><b>Servis Kategorisi</b></span>
												<select name="category" class="form-control">';
						foreach ($categories as $category) :
							$html .= '<option value="' . $category["category_id"] . '" ';
							if ($service['category_id'] == $category['category_id']) : $html .= 'selected';
							endif;
							$html .= '>' . $category["category_name"] . '</option>';
						endforeach;
						$html .= '</select>
												</div>
											</div>
											<div class="box">
												<div class="form-group">
													<div class="input-group">
														<span class="input-group-addon"><b>Servis Tipi</b></span>
														<select id="service_type" name="type" onchange="change_type()" class="form-control form-control-sm">
															<option value="1"';
						($type == 1) ? $html .= "selected" : null;
						$html .= '>Normal</option>
															<option value="2"';
						($type == 2) ? $html .= "selected" : null;
						$html .= '>Paket</option>
															<option value="3"';
						($type == 3) ? $html .= "selected" : null;
						$html .= '>Özel Yorum</option>
															<option value="4"';
						($type == 4) ? $html .= "selected" : null;
						$html .= '>Abonelik</option>
														</select>
													</div>
												</div>
												<div id="service_auto" class="form-group hide">
													<div class="input-group">
														<span class="input-group-addon"><b>Abonelik Tipi</b></span>
														<select name="auto_type" class="form-control">
															<option value="1"';
						($service["service_type"] == 1) ? $html .= "selected" : null;
						$html .= '>Instagram İzlenme</option>
															<option value="2"';
						($service["service_type"] == 2) ? $html .= "selected" : null;
						$html .= '>Instagram Beğeni</option>
														</select>
													</div>
												</div>
												<hr>
												<div class="form-group">
													<div class="input-group">
														<span class="input-group-addon"><b>Servis Sağlayıcı</b></span>
														<select id="service-api" name="api" onchange="change_api()" class="form-control form-control-sm mb-2">
															<option value="0">Manuel Servis (Sağlayıcı Seçilmedi)</option>';
						foreach ($apis as $api) :
							$html .= '<option value="' . $api["api_id"] . '" ';
							($api['api_id'] == $service['api_id']) ? $html .= "selected" : null;
							$html .= '>' . $api["api_url"] . '</option>';
						endforeach; //onchange="sabit_fiyat_guncelle()"
						$html .= '</select>
													</div>
												</div>
											
												<div class="form-group api_service_list_area" style="'. (($service["api_id"] == 0) ? 'display:none' : NULL) .'">
													<div class="input-group">
														<span class="input-group-addon"><b>API Servisi</b></span>
														<select id="service_list" name="api_service" onchange="change_api_service()" class="form-control form-control-sm mb-2">
															<option value="0">Seçilmedi</option>
														</select>
													</div>
												</div>
											</div>

											<div class="row">
											<div class="col-md-4">
											<div class="form-group">
												<div class="input-group">
													<span class="input-group-addon"><b>Servis Fiyatı (1000 Adet)</b></span>
													<input type="text" name="charge" id="service_price"  value="' . $service['service_charge'] . '" class="form-control" required>
												</div>
											</div>
											</div>										
											<div class="col-md-4">
											<div class="form-group">
												<div class="input-group">
													<span class="input-group-addon"><b>Otomatik Fiyat Yüzdesi</b></span>
													<input type="number" min="0" name="cron_charge" id="cron_price_rate" value="' . $service['cron_price_rate'] . '" class="form-control" required>
												</div>
											</div>
											</div>
											<div class="col-md-4">
											<div class="form-group">
												<div class="input-group">
													<span class="input-group-addon"><b>Sabit Kar (TL)</b></span>
													<input type="double" min="0" name="service_fixed_price"  placeholder="0" id="service_fixed_price"  value="' . $service['service_fixed_price'] . '" class="form-control" required>
												</div>
											</div>
											</div>
											</div>
											<div class="row" id="service_quantity">
												<div class="col-md-6">
													<div class="form-group">
														<div class="input-group">
															<span class="input-group-addon"><b>Minimum Sipariş  <input type="checkbox" name="min_max_1"';
						($minmax['min'] == 1) ? $html .= " checked" : null;
						$html .= '></b></span>
															<input type="number" name="min" id="service_min" value="' . $service['service_min'] . '" class="form-control" required>
														</div>
													</div>
												</div>
												<div class="col-md-6">
													<div class="form-group">
														<div class="input-group">
															<span class="input-group-addon"><b>Maksimum Sipariş  <input type="checkbox" name="min_max_2"';
						($minmax['max'] == 1) ? $html .= " checked" : null;
						$html .= '></b></span>
															<input type="number" name="max" id="service_max" value="' . $service['service_max'] . '" class="form-control" required>
														</div>
													</div>
												</div>
											</div>
											<hr>
											<div class="row" id="service_buttons">
												<div class="col-md-12">
													<div class="form-group">
														<div class="input-group">
															<span class="input-group-addon"><b>İptal Tuşu</b></span>
															<select name="cancel_button" class="form-control">
																<option value="0"';
						($service["cancel_button"] == 0) ? $html .= " selected" : null;
						$html .= '>Pasif</option>
																											<option value="1"';
						($service["cancel_button"] == 1) ? $html .= " selected" : null;
						$html .= '>Aktif</option>
															</select>
														</div>
													</div>
												</div>
												<div class="col-md-6">
													<div class="form-group">
														<div class="input-group">
															<span class="input-group-addon"><b>Telafi Tuşu</b></span>
															<select name="refill_button" class="form-control refill_toggle ">
																<option value="0"';
						($service["refill_button"] == 0) ? $html .= " selected" : null;
						$html .= '>Pasif</option>
																										<option value="1"';
						($service["refill_button"] == 1) ? $html .= " selected" : null;
						$html .= '>Aktif</option>
															</select>
														</div>
													</div>
												</div>
												<div class="col-md-6 refill_type_area" style="'. (($service["refill_button"] == 0) ? 'display:none' : NULL) .'">
													<div class="form-group">
														<div class="input-group">  
															<span class="input-group-addon"><b>Telafi Tipi</b></span>
															<select name="refill_type" class="form-control refiltype_toggle">
																<option value="1"';
						($service["refill_type"] == 1) ? $html .= " selected" : null;
						$html .= '>Manuel</option>
																											<option value="2"';
						($service["refill_type"] == 2) ? $html .= " selected" : null;
						$html .= '>Otomatik (Sadece Perfect Panelde API ile Çalışır)</option>
															</select>
														</div>
													</div>
												</div>
											</div>
											<div class="row refill_options_area" style="'. (($service["refill_button"] == 0 || $service['refill_type'] == 2) ? 'display:none' : NULL) .'" >
												<div class="col-md-6">
													<div class="form-group">
														<div class="input-group">
															<span class="input-group-addon"><b>Refill Maksimum Gün (Lifetime ise 0 yazınız)</b></span>
															<input type="number" name="refill_day" value="' . $service["refill_day"] . '" class="form-control">
														</div>
													</div>
												</div>
												<div class="col-md-6">
													<div class="form-group">
														<div class="input-group">
															<span class="input-group-addon"><b>Refill Bekleme Saati</b></span>
															<input type="number" name="refill_bekleme" value="' . $service["refill_bekleme"] . '" class="form-control">
														</div>
														<small>Refill butonunun gösterim aralığı (saat cinsinden)</small>
													</div>
												</div>
											</div>

											<div class="row aktif_pasif_area" style="'. (($service["api_id"] == 0) ? 'display:none' : NULL) .'">
												<div class="col-md-12">
													<div class="form-group">
														<div class="input-group">
															<span class="input-group-addon"><b>Aktif/Pasif Api Sistemi</b></span>
															<select name="service_auto_status" class="form-control">
																<option value="0" '.($service['service_auto_status'] == 0 ? 'selected' : NULL).'>Manuel</option>
																<option value="1" '.($service['service_auto_status'] == 1 ? 'selected' : NULL).'>Sağlayıcıda durum değişirse otomatik değiştir</option>
																<option value="2" '.($service['service_auto_status'] == 2 ? 'selected' : NULL).'>Sağlayıcıda durum değişirse uyar</option>
																<option value="3" '.($service['service_auto_status'] == 3 ? 'selected' : NULL).'>Sağlayıcıda durum değişirse uyar ve değiştir</option>
															</select>
														</div>
													</div>
												</div>
											</div>

											<div class="form-group" id="service_drip">
												<div class="input-group">
													<span class="input-group-addon"><b>Süreli Sipariş</b></span>
													<select name="drip" class="form-control">
														<option value="0"';
						($service["service_drip"] == 0) ? $html .= "selected" : null;
						$html .= '>Hayır</option>
																							<option value="1"';
						($service["service_drip"] == 1) ? $html .= "selected" : null;



						$html .= '>Evet</option>
</select>
</div>
</div>';
						$html .= '<input type="text" name="id" value="' . $service["service_id"] . '" style="display:none;">';
						$html .= '
<div class="form-group">
    <button type="submit" class="btn btn-default"><span class="text">Servisi Güncelle</span></button>
</div>
</form>
<script>
    change_api();
    change_type();
    $(function () {
        var selectedId = "';

						if (isset($service["api_service"]) && $service["api_service"] != null) {
							$html .= '' . $service["api_service"] . '"';
						} else {
							$html .= '"';
						}
						$html .= ';
        var selectedApı = "';

						if (isset($service["api_id"]) && $service["api_id"] != null) {
							$html .= '' . $service["api_id"] . '';
						}
						$html .= '";
        $("#service_list").bind("DOMSubtreeModified", function () {
            if (selectedApı != 0 && (selectedApı == $("#service-api").val())) {
                $("#service_list").val(selectedId);
            }
        });
    });

    function change_type() {
        var type = $("#service_type").val();
        if (type == 1) {
            $("#service_quantity").removeClass("hide");
            $("#service_drip").removeClass("hide");
            $("#service_auto").addClass("hide");
            $("#service_buttons").removeClass("hide");
        } else if (type == 2) {
            $("#service_quantity").addClass("hide");
            $("#service_min, #service_max").val("1");
            $("#service_drip").removeClass("hide");
            $("#service_auto").addClass("hide");
            $("#service_buttons").removeClass("hide");
        } else if (type == 3) {
            $("#service_quantity").removeClass("hide");
            $("#service_drip").addClass("hide");
            $("select[name=drip]").val("0");
            $("#service_auto").addClass("hide");
            $("#service_buttons").removeClass("hide");
        } else if (type == 4) {
            $("#service_quantity").removeClass("hide");
            $("#service_drip").addClass("hide");
            $("select[name=drip]").val("0");
            $("#service_auto").removeClass("hide");
            $("#service_buttons").addClass("hide");

        }
    }

    function change_api() {
        var api = $("#service-api").val();
        if (api != "0") {
            post("get_api_services", {api: api});
        }
    }

    function change_api_service() {
        var type = $("#service_type").val();
        var selected = $("#service_list").find("option:selected");
        if ($("#autoUpdate").is(":checked")) {
            if (type != 2) {
                $("#service_min").val(selected.data("min"));
                $("#service_max").val(selected.data("max"));
            }
            var price = selected.data("price");
    

            console.log(price);
            $("#service_price").val(price);
        }
    }
</script>';


						$response->title = $title;
						$response->order = $html;
					} else {
						$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
					}
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "add_payment_proccess") {
		if (login_control()) {
			$posts = [
				"user" => true,
				"amount" => true,
				"extras" => true,
				"type" => true
			];
			$error = false;
			foreach ($posts as $post => $required) {
				if ($required) {
					if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
						$$post = filter($_POST[$post]);
					} else {
						$error = true;
						break;
					}
				} else {
					if (isset($_POST[$post])) {
						$$post = filter($_POST[$post]);
					} else {
						$error = true;
						break;
					}
				}
			}
			if (!$error) {

				$userQ = $db->from('users')->where('user_username', $user)->first();

				if ($userQ) {

					if ($type == "add") {

						$newbalance = $userQ['user_balance'] + $amount;
						$eskibakiye = $userQ['user_balance'];
						$yenibakiye = $newbalance;

						$addbalance = $db->update('users')
							->where('user_id', $userQ['user_id'])
							->set(array(
								'user_balance' => $newbalance
							));

						if ($addbalance) {

							$insertorder = $db->insert('deposits')
								->set(array(
									'user_id' => $userQ['user_id'],
									'order_id' => 000,
									'deposit_date' => time(),
									'deposit_method' => 158,
									'deposit_extras' => $extras,
									'deposit_amount' => $amount,
									'deposit_status' => 1,
									'eskib' => $eskibakiye,
									'yenib' => $yenibakiye
								));

							$response->reload = true;
						} else {
							$response->error = "Sistem hatası oluştu.";
						}
					} elseif ($type == "decrease") {

						$newbalance = $userQ['user_balance'] - $amount;
						$eskibakiye = $userQ['user_balance'];
						$yenibakiye = $newbalance;

						if ($newbalance < 0) {

							$repsonse->error = "Bakiye eksiltmek istediğiniz kullanıcının bakiyesi: " . $userQ['user_balance'] . " tutarındadır. Lütfen bulunan bakiye içerisinde eksiltme yapınız.";
						} else {

							$updatebalance = $db->update('users')->where('user_username', $user)
								->set(array(
									'user_balance' => $newbalance
								));

							if ($updatebalance) {

								$insertorder = $db->insert('deposits')
									->set(array(
										'user_id' => $userQ['user_id'],
										'order_id' => 000,
										'deposit_date' => time(),
										'deposit_method' => 159,
										'deposit_extras' => $extras,
										'deposit_amount' => $amount,
										'deposit_status' => 1,
										'eskib' => $eskibakiye,
										'yenib' => $yenibakiye
									));

								$response->reload = true;
							} else {
								$response->error = "Sistem hatası oluştu.";
							}
						}
					}
				} else {

					$response->error = "Belirtilen kullanıcı adına ait hesap bulunamadı.";
				}
			} else {
				$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "add_payment") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'edit')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {
					$title = "Ödeme Ekle/Çıkar";
					$html = '<form id="add_payment_proccess" onsubmit="return false;" data-reset="1">
									<div class="form-group">
										<div class="input-group">
											<span class="input-group-addon"><b>Kullanıcı Adı</b></span>
											<input type="text" name="user" class="form-control">
										</div>
									</div>
									<div class="form-group">
										<div class="input-group">
											<span class="input-group-addon"><b>Tutar</b></span>
											<input type="double" min="1" name="amount" class="form-control">
										</div>
									</div>
									<div class="form-group">
										<div class="input-group">
											<span class="input-group-addon"><b>Not</b></span>
											<input type="text" name="extras" class="form-control">
										</div>
									</div>
									<div class="form-group">
										<div class="input-group">
											<span class="input-group-addon"><b>İşlem Tipi</b></span>
											<select name="type" class="form-control">
												<option value="add">Ekle</option>
												<option value="decrease">Çıkar</option>
											</select>
										</div>
									</div>
									<div class="form-group">
										<button type="submit" class="btn btn-success">Onayla</button>
									</div>
								<form>';
					$response->title = $title;
					$response->order = $html;
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "get_newsupport") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'edit')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {
					$title = "Yeni Talep Oluştur";
					$html = '<form id="add_new_ticket" onsubmit="return false;" data-reset="1">
									<div class="form-group">
										<div class="input-group">
											<span class="input-group-addon"><b>Kullanıcı Adı</b></span>
											<input type="text" name="user" class="form-control">
										</div>
									</div>
									<div class="form-group">
										<div class="input-group">
											<span class="input-group-addon"><b>Başlık</b></span>
											<input type="text" name="title" class="form-control">
										</div>
									</div>
									<div class="form-group">
										<div class="input-group">
											<span class="input-group-addon"><b>Mesaj</b></span>
											<textarea name="message" rows="6" class="form-control"></textarea>
										</div>
									</div>
									<div class="form-group">
										<button type="submit" class="btn btn-success">Oluştur</button>
									</div>
								<form>';
					$response->title = $title;
					$response->order = $html;
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "add_new_ticket") {
		if (login_control()) {
			$posts = [
				"user" => true,
				"title" => true,
				"message" => true
			];
			$error = false;
			foreach ($posts as $post => $required) {
				if ($required) {
					if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
						$$post = filter($_POST[$post]);
					} else {
						$error = true;
						break;
					}
				} else {
					if (isset($_POST[$post])) {
						$$post = filter($_POST[$post]);
					} else {
						$error = true;
						break;
					}
				}
			}
			if (!$error) {

				$userQ = $db->from('users')->where('user_username', $user)->first();

				if ($userQ) {

					$addticket = $db->insert('tickets')
						->set(array(
							'ticket_title' => $title,
							'user_id' => $userQ['user_id']
						));

					if ($addticket) {

						$ticketQuery = $db->from('tickets')->where('user_id', $userQ['user_id'])->orderby('ticket_date', 'DESC')->first();

						if ($ticketQuery) {

							$addmessage = $db->insert('ticket_messages')
								->set(array(
									'message_author' => 2,
									'ticket_id' => $ticketQuery['ticket_id'],
									'message_text' => $message,
									'message_time' => time()
								));

							if ($addmessage) {
								$response->success = "Destek talebi oluşturuldu.";
							} else {
								$response->error = "Destek talebi oluşturuldu fakat mesaj gönderilemedi.";
							}
						} else {

							$response->error = "Destek talebi oluşturuldu fakat mesaj gönderilemedi.";
						}
					} else {

						$response->error = "Sistem hatası oluştu.";
					}
				} else {

					$response->error = "Belirtilen kullanıcı adına ait hesap bulunamadı.";
				}
			} else {
				$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "get_account") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'accounts')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					$posts = [
						"id" => true
					];
					$error = false;
					foreach ($posts as $post => $required) {
						if ($required) {
							if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						} else {
							if (isset($_POST[$post])) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						}
					}
					if (!$error) {

						$query = $db->from('bank_accounts')->where('id', $id)->first();

						if ($query) {
							$title = "Banka Hesabı Düzenle";
							$html = '
									<form id="edit_bankaccount" onsubmit="return false;" data-reset="0">
										<div class="form-group">
											<div class="input-group">
												<span class="input-group-addon"><b>Banka İsmi</b></span>
												<input type="text" name="account_title" class="form-control" value="' . $query['account_title'] . '">
											</div>
										</div>
										<div class="form-group">
											<div class="input-group">
												<span class="input-group-addon"><b>İsim Soyisim</b></span>
												<input type="text" name="account_name" class="form-control" value="' . $query['account_name'] . '">
											</div>
										</div>
										<div class="form-group">
											<div class="input-group">
												<span class="input-group-addon"><b>IBAN</b></span>
												<input type="text" name="account_iban" class="form-control" value="' . $query['account_iban'] . '">
											</div>
										</div>
										<div class="form-group">
											<div class="input-group">
												<span class="input-group-addon"><b>Hesap NO</b></span>
												<input type="text" name="account_number" class="form-control" value="' . $query['account_number'] . '">
											</div>
										</div>
										<div class="form-group">
											<div class="input-group">
												<span class="input-group-addon"><b>Şube Kodu</b></span>
												<input type="text" name="account_branch" class="form-control" value="' . $query['account_branch'] . '">
											</div>
										</div>
										<input type="text" name="id" class="form-control" style="display:none;" value="' . $query['id'] . '">
										<div class="form-group">
											<button type="submit" class="btn btn-success">Güncelle</button>
										</div>
									<form>
								';
							$response->title = $title;
							$response->order = $html;
						} else {
							$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
						}
					} else {
						$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
					}
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "get_user") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'users')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					$posts = [
						"id" => true
					];
					$error = false;
					foreach ($posts as $post => $required) {
						if ($required) {
							if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						} else {
							if (isset($_POST[$post])) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						}
					}

					if (!$error) {

						$query = $db->from('users')->where('user_id', $id)->first();
						$permissions = json_decode($query['user_perms'], true);

						if ($query) {
							$title = "Üye Düzenle (" . $query['user_id'] . ")";
							$html = '
									<form id="update_user" onsubmit="return false;" data-reset="0">
										<div class="form-group">
											<div class="input-group">
												<span class="input-group-addon"><b>Kullanıcı Adı</b></span>
												<input type="text" name="username" class="form-control" value="' . $query['user_username'] . '">
											</div>
										</div>
										<div class="form-group">
											<div class="input-group">
												<span class="input-group-addon"><b>EMail Adresi</b></span>
												<input type="text" name="email" class="form-control" value="' . $query['user_email'] . '">
											</div>
										</div>
										<div class="form-group">
											<div class="input-group">
												<span class="input-group-addon"><b>Şifre</b></span>
												<input type="text" name="password" class="form-control"">
											</div>
											<small>Parolayı değiştirmek istemiyorsanız boş bırakınız.</small>
										</div>
										<div class="form-group">
											<div class="input-group">
												<span class="input-group-addon"><b>Bakiye</b></span>
												<input type="text" name="balance" class="form-control" value="' . $query['user_balance'] . '" readonly="">
											</div>
										</div>
										<div class="form-group">
											<div class="input-group">
												<span class="input-group-addon"><b>API Key</b></span>
												<input type="text" name="balance" class="form-control" value="' . $query['user_key'] . '" readonly="">
											</div>
										</div>
										<div class="row">
											<div class="form-group col-md-6">
												<div class="input-group">
													<span class="input-group-addon"><b>İsim</b></span>
													<input type="text" name="first_name" class="form-control" value="' . $query['user_first_name'] . '">
												</div>
											</div>
											<div class="form-group col-md-6">
												<div class="input-group">
													<span class="input-group-addon"><b>Soyisim</b></span>
													<input type="text" name="last_name" class="form-control" value="' . $query['user_last_name'] . '">
												</div>
											</div>
										</div>
										<div class="form-group">
											<div class="input-group">
												<span class="input-group-addon"><b>Telefon</b></span>
												<input type="text" name="skype" class="form-control" value="' . $query['user_skype'] . '">
											</div>
										</div>
										<div class="form-group">
											<div class="input-group">
												<span class="input-group-addon"><b>Yetki</b></span>
												<select name="authority" class="form-control form-control-sm">';
							if ($query["user_authority"] == 2) :
								$html .= '<option value="0">Yetki Yok</option>
													<option value="2" selected>Yönetici</option>';
							else :
								$html .= '<option value="0" selected>Yetki Yok</option>
													<option value="2">Yönetici</option>';
							endif;
							$html .= '</select>
											</div>
										</div>';
							if ($_SESSION['user_id'] == $query['user_id']) :
								$html .= '
											<div class="form-group">
												<label style="width:100%;"><b>Kullanıcı İzinleri</b></label>';
								foreach ($perms as $perm => $value) :
									$html .= '<div class="checkbox-inline">
													<input type="checkbox" class="access" name="access[access][' . $perm . ']" ';
									if (isset($permissions['access'][$perm]) && $permissions['access'][$perm] == 1) : $html .= ' checked ';
									endif;
									$html .= 'value="1"> ' . $value['title'] . '
												</div>';
								endforeach;
								$html .= '</div>';
							elseif (permission('access', 'root')) :
								$html .= '
											<div class="form-group">
												<label style="width:100%;"><b>Kullanıcı İzinleri</b></label>';
								foreach ($perms as $perm => $value) :
									$html .= '<div class="checkbox-inline">
													<input type="checkbox" class="access" name="access[access][' . $perm . ']" ';
									if (isset($permissions['access'][$perm]) && $permissions['access'][$perm] == 1) : $html .= ' checked ';
									endif;
									$html .= 'value="1"> ' . $value['title'] . '
												</div>';
								endforeach;
								$html .= '</div>';
							else :
								$html .= '
											<div class="form-group">
												<label style="width:100%;"><b>Kullanıcı İzinleri</b></label>';
								foreach ($perms as $perm => $value) :
									$html .= '<div class="checkbox-inline">
													<input type="checkbox" class="access" onclick="return false;" name="access[access][' . $perm . ']" ';
									if (isset($permissions['access'][$perm]) && $permissions['access'][$perm] == 1) : $html .= ' checked ';
									endif;
									$html .= 'value="1"> ' . $value['title'] . '
												</div>';
								endforeach;
								$html .= '</div>';
							endif;
							$html .= '<input type="text" name="id" class="form-control" style="display:none;" value="' . $query['user_id'] . '">
										<div class="form-group">
											<button type="submit" class="btn btn-success">Güncelle</button>
										</div>
									<form>
								';
							$response->title = $title;
							$response->order = $html;
						} else {
							$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
						}
					} else {
						$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
					}
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "get_userpromotions") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'users')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					$posts = [
						"id" => true
					];
					$error = false;
					foreach ($posts as $post => $required) {
						if ($required) {
							if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						} else {
							if (isset($_POST[$post])) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						}
					}

					if (!$error) {

						$query = $db->from('users')->where('user_id', $id)->first();
						$offers = $db->query("SELECT * FROM `special_offers` WHERE user_id = $query[user_id]")->fetchAll(PDO::FETCH_ASSOC);
						$offers_temp = [];
						foreach ($offers as $offer) {
							$offers_temp[$offer["service_id"]] = $offer["offer_charge"];
						}
						$offers = $offers_temp;
						$tempServices = [];
						$categories = $db->query("SELECT * FROM `categories` ORDER BY category_number ASC, category_id DESC");
						foreach ($categories as $category) {
							$services = $db->query("SELECT * FROM `services` WHERE category_id = '$category[category_id]' ORDER BY service_number ASC, service_id DESC");
							foreach ($services as $service) {
								$service_name = json_decode($service["service_name"], true);
								$name = null;
								foreach ($service_name as $details) {
									if ($details["lang"] == 1) {
										$name = $details["name"];
									}
								}
								$service["service_name"] = $name;
								$tempServices[] = $service;
							}
						}

						$services = $tempServices;

						if ($query) {
							$title = "Üyeye Özel Fiyatlandırma (" . $query['user_id'] . ")";
							$html = '<form id="update_offers" onsubmit="return false;" data-reset="0">
											<input type="hidden" name="id" value="' . $query["user_id"] . '" />
											<table class="table table-bordered">
												<thead>
													<tr>
														<th>Servis</th>
														<th>Özel Fiyat</th>
													</tr>
												</thead>
												<tbody>';
							foreach ($services as $service) :
								$json = json_decode($service['api_detail'], true);
								$html .= '<tr>
															<td>' . $service["service_name"] . ' <span style="background:#dc123c;color:white;font-weight:bold;padding:3px;border-radius:3px;margin-right:5px;"> Satış : ' . CURRENCY_SYMBOL . $service["service_charge"] . ' </span> <span style="background:#309e03;color:white;font-weight:bold;padding:3px;border-radius:3px;"> Alış : ' . $json["rate"] . '</span></td>
															<td><input type="text" name="service[' . $service["service_id"] . ']" class="form-control" value="';
								array_key_exists($service["service_id"], $offers) ? $html .= '' . $offers[$service["service_id"]] . '' : null;
								$html .= '"/></td>
														</tr>';
							endforeach;
							$html .= '</tbody>
											</table>
											<button type="submit" class="btn btn-success">Güncelle</button>
											
											<a href="#" onclick="uye_toplu_indirim_sil(' . $query['user_id'] . ')" class="btn btn-warning">Hepsini Sil</a>
									</form>';

							$response->title = $title;
							$response->order = $html;
						} else {
							$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
						}
					} else {
						$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
					}
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "get_moonpanelpro") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'root')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					$error = false;

					if (!$error) {

						$title = "MoonPanel PRO";
						$html = '<iframe src="' . admin_url('pro') . '" style="width:100%;height: 600px;border:none;overflow:hidden;"></iframe>';
						$response->title = $title;
						$response->order = $html;
					} else {
						$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
					}
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "get_userlogs") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'users')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					$posts = [
						"id" => true
					];
					$error = false;
					foreach ($posts as $post => $required) {
						if ($required) {
							if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						} else {
							if (isset($_POST[$post])) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						}
					}

					if (!$error) {

						$query = $db->from('users')->where('user_id', $id)->first();
						$logs = $db->from('user_logs')->where('user_id', $query['user_id'])->orderby('log_id', 'DESC')->all();

						if ($query) {
							$title = "Üye Logları (" . $query['user_id'] . ")";
							$html = '<table id="ordertable" class="table table-bordered">
											<thead>
												<tr>
													<th>Tarih</th>
													<th>IP</th>
													<th>Açıklama</th>
												</tr>
											</thead>
											<tbody>';
							foreach ($logs as $log) :
								$html .= '<tr>
														<td>' . date("d.m.y H:i:s", $log["log_time"]) . '</td>
														<td>' . $log["log_ip"] . '</td>
														<td>' . $log["log_content"] . '</td>
													</tr>';
							endforeach;
							$html .= '</tbody>
										</table>
										<script>$("#ordertable").DataTable({"order": [[ 0, "desc" ]]});</script>';
							$response->title = $title;
							$response->order = $html;
						} else {
							$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
						}
					} else {
						$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
					}
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "user_block") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'edit')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					$posts = [
						"id" => true
					];
					$error = false;
					foreach ($posts as $post => $required) {
						if ($required) {
							if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						} else {
							if (isset($_POST[$post])) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						}
					}

					if (!$error) {

						$query = $db->from('users')->where('user_id', $id)->first();

						if ($query) {

							if ($query['user_status'] == 1) {

								$update = $db->update('users')
									->where('user_id', $query['user_id'])
									->set(array(
										'user_status' => 0
									));

								if ($update) {
									$response->reload = true;
								} else {
									$response->error = "İşlem başarısız, daha sonra tekrar deneyiniz.";
								}
							} elseif ($query['user_status'] == 0) {

								$update = $db->update('users')
									->where('user_id', $query['user_id'])
									->set(array(
										'user_status' => 1
									));

								if ($update) {
									$response->reload = true;
								} else {
									$response->error = "İşlem başarısız, daha sonra tekrar deneyiniz.";
								}
							}
						} else {
							$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
						}
					} else {
						$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
					}
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "get_servicedescription") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'services')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					$posts = [
						"id" => true
					];
					$error = false;
					foreach ($posts as $post => $required) {
						if ($required) {
							if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						} else {
							if (isset($_POST[$post])) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						}
					}
					if (!$error) {

						$service = $db->from('services')->where('service_id', $id)->first();
						$desc = json_decode($service['service_desc'], true);

						if ($desc != null) {
							$desc = htmlspecialchars_decode($desc[0]['name']);
						} else {
							$desc = null;
						}

						if ($service) {
							$title = "Servis Açıklaması Düzenle";
							$html = '
									<form id="update_servicedesc" onsubmit="return false;" data-reset="0">
										<div class="form-group">
											<div class="input-group">
												<span class="input-group-addon"><b>Servis Açıklaması</b></span>
												<textarea type="text" id="editor" name="service_desc" col="6" rows="5" class="form-control">' . $desc . '</textarea>
											</div>
										</div>
										<input type="text" name="id" class="form-control" style="display:none;" value="' . $service['service_id'] . '">
										<div class="form-group">
											<button type="submit" class="btn btn-success">Güncelle</button>
										</div>
									<form>
									<script>
										function MinHeightPlugin(editor) {
										  this.editor = editor;
										}

										MinHeightPlugin.prototype.init = function() {
										  this.editor.ui.view.editable.extendTemplate({
										    attributes: {
										      style: {
										        minHeight: "300px"
										      }
										    }
										  });
										};

										ClassicEditor.builtinPlugins.push(MinHeightPlugin);
										ClassicEditor.create( document.querySelector("#editor"),{
											language: "tr"
										}).then(editor => {
											console.log( editor );
										}).catch(error => {
											console.error( error );
										});
									</script>
								';
							$response->title = $title;
							$response->order = $html;
						} else {
							$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
						}
					} else {
						$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
					}
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "update_servicedesc") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'edit')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					$posts = [
						"id" => true,
						"service_desc" => true
					];
					$error = false;
					foreach ($posts as $post => $required) {
						if ($required) {
							if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						} else {
							if (isset($_POST[$post])) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						}
					}
					if (!$error) {

						$service = $db->from('services')->where('service_id', $id)->first();

						if ($service) {

							$htmldesc = htmlspecialchars($service_desc);
							$encode = Emoji::Encode($htmldesc);
							$desc = '[{"lang":1,"name":"' . $encode . '"}]';

							$update = $db->update('services')->where('service_id', $id)
								->set(array(
									'service_desc' => $desc
								));

							if ($update) {
								$response->success = "Servis açıklaması başarıyla güncellendi.";
							} else {
								$response->error = "Servis açıklaması güncellenemedi, daha sonra tekrar deneyiniz.";
							}
						} else {
							$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
						}
					} else {
						$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
					}
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "update_servicestatus") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'edit')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					$posts = [
						"id" => true,
						"type" => true
					];
					$error = false;
					foreach ($posts as $post => $required) {
						if ($required) {
							if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						} else {
							if (isset($_POST[$post])) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						}
					}
					if (!$error) {

						$service = $db->from('services')->where('service_id', $id)->first();

						if ($service) {

							if ($type == "off") {

								if ($service['service_status'] == 0) {

									$response->error = "Bu servis zaten pasif durumda, tekrardan pasifleştirilemez.";
								} else {

									$update = $db->update('services')->where('service_id', $id)
										->set(array(
											'api_type' => 3,
											'service_status' => 0
										));

									if ($update) {

										$response->success = "Servis başarıyla pasifleştirilmiştir.";
									}
								}
							} elseif ($type == "on") {

								if ($service['service_status'] == 1) {

									$response->error = "Bu servis zaten aktif durumda, tekrardan aktifleştirilemez.";
								} else {

									$update = $db->update('services')->where('service_id', $id)
										->set(array(
											'api_type' => 2,
											'service_status' => 1
										));

									if ($update) {

										$response->success = "Servis başarıyla aktifleştirilmiştir.";
									}
								}
							} else {

								$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
							}
						} else {
							$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
						}
					} else {
						$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
					}
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "get_payment") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'payments')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					$posts = [
						"id" => true
					];

					$error = false;

					foreach ($posts as $post => $required) {
						if ($required) {
							if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						} else {
							if (isset($_POST[$post])) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						}
					}

					if ($id == 1) {

						$method = $db->from('payment_methods')->where('method_id', $id)->first();

						if ($method) {

							$data = json_decode($method['method_details'], true);

							$title = "PayTR Ayarları";
							$html = '	
										<form id="update_method" onsubmit="return false;" data-reset="0">
											<div class="form-group">
												<div class="input-group">
													<span class="input-group-addon"><b>Görünür İsim</b></span>
													<input type="text" name="data[name]" class="form-control form-control-sm" value="' . $data["name"] . '" />
												</div>
											</div>
											<div class="form-group">
												<div class="input-group">
													<span class="input-group-addon"><b>Durum</b></span>
													<select class="form-control" name="data[status]">
														<option value="1" ';
							($data["status"] == 1) ? $html .= "selected" : null;
							$html .= '>Aktif</option>
														<option value="0" ';
							($data["status"] == 0) ? $html .= "selected" : null;
							$html .= '>Pasif</option>
													</select>
												</div>
											</div>
											<hr>
											<div class="form-group">
												<div class="input-group">
													<span class="input-group-addon"><b>MID</b></span>
													<input type="text" name="data[mid]" class="form-control form-control-sm" value="' . $data["mid"] . '" />
												</div>
											</div>
											<div class="form-group">
												<div class="input-group">
													<span class="input-group-addon"><b>KEY</b></span>
													<input type="text" name="data[key]" class="form-control form-control-sm" value="' . $data["key"] . '" />
												</div>
											</div>
											<div class="form-group">
												<div class="input-group">
													<span class="input-group-addon"><b>SALT</b></span>
													<input type="text" name="data[salt]" class="form-control form-control-sm" value="' . $data["salt"] . '" />
												</div>
											</div>
											<hr>
											<div class="form-group">
												<div class="input-group">
													<span class="input-group-addon"><b>Komisyon (%)</b></span>
													<input type="text" name="data[comission]" class="form-control form-control-sm" value="' . $data["comission"] . '" />
												</div>
											</div>
											<div class="form-group">
												<div class="input-group">
													<span class="input-group-addon"><b>Minimum Ödeme</b></span>
													<input type="number" name="data[min]" min="0" class="form-control form-control-sm" value="' . $data["min"] . '" />
												</div>
											</div>
											<div class="form-group">
												<div class="input-group">
													<span class="input-group-addon"><b>Maksimum Ödeme</b></span>
													<input type="number" name="data[max]" min="0" class="form-control form-control-sm" value="' . $data["max"] . '" />
												</div>
											</div>
											<hr>
											<div class="form-group">
												<label><b>PayTR CallBack (Geri Dönüş) Adresi:</b> <code>' . site('notify/paytr') . '</code></label>
											</div>
											<input type="hidden" name="id" value="' . $method['method_id'] . '" />
											<div class="form-group">
												<button type="submit" class="btn btn-success">Güncelle</button>
											</div>
										<form>
								';
							$response->title = $title;
							$response->order = $html;
						} else {

							$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
						}
					} elseif ($id == 3) {

						$method = $db->from('payment_methods')->where('method_id', $id)->first();

						if ($method) {

							$data = json_decode($method['method_details'], true);

							$title = "Paywant Ayarları";
							$html = '
										<form id="update_method" onsubmit="return false;" data-reset="0">
											<div class="form-group">
												<div class="input-group">
													<span class="input-group-addon"><b>Görünür İsim</b></span>
													<input type="text" name="data[name]" class="form-control form-control-sm" value="' . $data["name"] . '" />
												</div>
											</div>
											<div class="form-group">
												<div class="input-group">
													<span class="input-group-addon"><b>Durum</b></span>
													<select class="form-control" name="data[status]">
														<option value="1" ';
							($data["status"] == 1) ? $html .= "selected" : null;
							$html .= '>Aktif</option>
														<option value="0" ';
							($data["status"] == 0) ? $html .= "selected" : null;
							$html .= '>Pasif</option>
													</select>
												</div>
											</div>
											<hr>
											<div class="form-group">
												<div class="input-group">
													<span class="input-group-addon"><b>Key</b></span>
													<input type="text" name="data[key]" class="form-control form-control-sm" value="' . $data["key"] . '" />
												</div>
											</div>
											<div class="form-group">
												<div class="input-group">
													<span class="input-group-addon"><b>Secret</b></span>
													<input type="text" name="data[secret]" class="form-control form-control-sm" value="' . $data["secret"] . '" />
												</div>
											</div>
											<hr>
											<div class="form-group">
												<div class="input-group">
													<span class="input-group-addon"><b>Komisyon (%)</b></span>
													<input type="text" name="data[comission]" class="form-control form-control-sm" value="' . $data["comission"] . '" />
												</div>
											</div>
											<div class="form-group">
												<div class="input-group">
													<span class="input-group-addon"><b>Minimum Ödeme</b></span>
													<input type="number" name="data[min]" min="0" class="form-control form-control-sm" value="' . $data["min"] . '" />
												</div>
											</div>
											<div class="form-group">
												<div class="input-group">
													<span class="input-group-addon"><b>Maksimum Ödeme</b></span>
													<input type="number" name="data[max]" min="0" class="form-control form-control-sm" value="' . $data["max"] . '" />
												</div>
											</div>
											<hr>
											<div class="form-group">
												<label><b>Paywant CallBack (Geri Dönüş) Adresi:</b> <code>' . site('notify/paywant') . '</code></label>
											</div>
											<input type="hidden" name="id" value="' . $method['method_id'] . '" />
											<div class="form-group">
												<button type="submit" class="btn btn-success">Güncelle</button>
											</div>
										<form>
								';
							$response->title = $title;
							$response->order = $html;
						} else {

							$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
						}
					} elseif ($id == 99) {

						$method = $db->from('payment_methods')->where('method_id', $id)->first();

						if ($method) {

							$data = json_decode($method['method_details'], true);

							$title = "PayHesap Ayarları";
							$html = '
										<form id="update_method" onsubmit="return false;" data-reset="0">
											<div class="form-group">
												<div class="input-group">
													<span class="input-group-addon"><b>Görünür İsim</b></span>
													<input type="text" name="data[name]" class="form-control form-control-sm" value="' . $data["name"] . '" />
												</div>
											</div>
											<div class="form-group">
												<div class="input-group">
													<span class="input-group-addon"><b>Durum</b></span>
													<select class="form-control" name="data[status]">
														<option value="1" ';
															($data["status"] == 1) ? $html .= "selected" : null;
															$html .= '>Aktif</option>
																						<option value="0" ';
															($data["status"] == 0) ? $html .= "selected" : null;
															$html .= '>Pasif</option>
													</select>
												</div>
											</div>
											<hr>
											<div class="form-group">
												<div class="input-group">
													<span class="input-group-addon"><b>Key</b></span>
													<input type="text" name="data[key]" class="form-control form-control-sm" value="' . $data["key"] . '" />
												</div>
											</div>
											<hr>
											<div class="form-group">
												<div class="input-group">
													<span class="input-group-addon"><b>Komisyon (%)</b></span>
													<input type="text" name="data[comission]" class="form-control form-control-sm" value="' . $data["comission"] . '" />
												</div>
											</div>
											<div class="form-group">
												<div class="input-group">
													<span class="input-group-addon"><b>Minimum Ödeme</b></span>
													<input type="number" name="data[min]" min="0" class="form-control form-control-sm" value="' . $data["min"] . '" />
												</div>
											</div>
											<div class="form-group">
												<div class="input-group">
													<span class="input-group-addon"><b>Maksimum Ödeme</b></span>
													<input type="number" name="data[max]" min="0" class="form-control form-control-sm" value="' . $data["max"] . '" />
												</div>
											</div>
											<hr>
											<div class="form-group">
												<label><b>PayHesap CallBack (Geri Dönüş) Adresi:</b> <code>' . site('notify/payhesap') . '</code></label>
											</div>
											<input type="hidden" name="id" value="' . $method['method_id'] . '" />
											<div class="form-group">
												<button type="submit" class="btn btn-success">Güncelle</button>
											</div>
										<form>
								';
							$response->title = $title;
							$response->order = $html;
						} else {

							$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
						}
					} elseif ($id == 4) {

						$method = $db->from('payment_methods')->where('method_id', $id)->first();

						if ($method) {

							$data = json_decode($method['method_details'], true);

							$title = "Shopier Ayarları";
							$html = '
										<form id="update_method" onsubmit="return false;" data-reset="0">
											<div class="form-group">
												<div class="input-group">
													<span class="input-group-addon"><b>Görünür İsim</b></span>
													<input type="text" name="data[name]" class="form-control form-control-sm" value="' . $data["name"] . '" />
												</div>
											</div>
											<div class="form-group">
												<div class="input-group">
													<span class="input-group-addon"><b>Durum</b></span>
													<select class="form-control" name="data[status]">
														<option value="1" ';
							($data["status"] == 1) ? $html .= "selected" : null;
							$html .= '>Aktif</option>
														<option value="0" ';
							($data["status"] == 0) ? $html .= "selected" : null;
							$html .= '>Pasif</option>
													</select>
												</div>
											</div>
											<hr>
											<div class="form-group">
												<div class="input-group">
													<span class="input-group-addon"><b>API Key</b></span>
													<input type="text" name="data[key]" class="form-control form-control-sm" value="' . $data["key"] . '" />
												</div>
											</div>
											<div class="form-group">
												<div class="input-group">
													<span class="input-group-addon"><b>API Secret</b></span>
													<input type="text" name="data[secret]" class="form-control form-control-sm" value="' . $data["secret"] . '" />
												</div>
											</div>
											<div class="form-group">
												<div class="input-group">
													<span class="input-group-addon"><b>Geri Dönüş</b></span>
													<select class="form-control" name="data[callbackurl]">
														<option value="1" ';
							($data["callbackurl"] == 1) ? $html .= "selected" : null;
							$html .= '>Geri Dönüş URL 1</option>
														<option value="2" ';
							($data["callbackurl"] == 2) ? $html .= "selected" : null;
							$html .= '>Geri Dönüş URL 2</option>
														<option value="3" ';
							($data["callbackurl"] == 3) ? $html .= "selected" : null;
							$html .= '>Geri Dönüş URL 3</option>
														<option value="4" ';
							($data["callbackurl"] == 4) ? $html .= "selected" : null;
							$html .= '>Geri Dönüş URL 4</option>
														<option value="5" ';
							($data["callbackurl"] == 5) ? $html .= "selected" : null;
							$html .= '>Geri Dönüş URL 5</option>
													</select>
												</div>
											</div>
											<hr>
											<div class="form-group">
												<div class="input-group">
													<span class="input-group-addon"><b>İşlem Ücreti (0.49TL)</b></span>
													<select class="form-control" name="data[fee]">
														<option value="1" ';
							($data["fee"] == 1) ? $html .= "selected" : null;
							$html .= '>Yansıt</option>
														<option value="0" ';
							($data["fee"] == 0) ? $html .= "selected" : null;
							$html .= '>Yansıtma</option>
													</select>
												</div>
											</div>
											<div class="form-group">
												<div class="input-group">
													<span class="input-group-addon"><b>Komisyon (%)</b></span>
													<input type="text" name="data[comission]" class="form-control form-control-sm" value="' . $data["comission"] . '" />
												</div>
											</div>
											<hr>
											<div class="form-group">
												<div class="input-group">
													<span class="input-group-addon"><b>Minimum Ödeme</b></span>
													<input type="number" name="data[min]" min="0" class="form-control form-control-sm" value="' . $data["min"] . '" />
												</div>
											</div>
											<div class="form-group">
												<div class="input-group">
													<span class="input-group-addon"><b>Maksimum Ödeme</b></span>
													<input type="number" name="data[max]" min="0" class="form-control form-control-sm" value="' . $data["max"] . '" />
												</div>
											</div>
											<hr>
											<div class="form-group">
												<label><b>Shopier CallBack (Geri Dönüş) Adresi:</b> <code>' . site('notify/shopier') . '</code></label>
											</div>
											<input type="hidden" name="id" value="' . $method['method_id'] . '" />
											<div class="form-group">
												<button type="submit" class="btn btn-success">Güncelle</button>
											</div>
										<form>
								';
							$response->title = $title;
							$response->order = $html;
						} else {

							$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
						}
					} elseif ($id == 5) {

						$method = $db->from('payment_methods')->where('method_id', $id)->first();

						if ($method) {

							$data = json_decode($method['method_details'], true);

							$title = "WeePay Ayarları";
							$html = '
										<form id="update_method" onsubmit="return false;" data-reset="0">
											<div class="form-group">
												<div class="input-group">
													<span class="input-group-addon"><b>Görünür İsim</b></span>
													<input type="text" name="data[name]" class="form-control form-control-sm" value="' . $data["name"] . '" />
												</div>
											</div>
											<div class="form-group">
												<div class="input-group">
													<span class="input-group-addon"><b>Durum</b></span>
													<select class="form-control" name="data[status]">
														<option value="1" ';
							($data["status"] == 1) ? $html .= "selected" : null;
							$html .= '>Aktif</option>
														<option value="0" ';
							($data["status"] == 0) ? $html .= "selected" : null;
							$html .= '>Pasif</option>
													</select>
												</div>
											</div>
											<hr>
											<div class="form-group">
												<div class="input-group">
													<span class="input-group-addon"><b>Key</b></span>
													<input type="text" name="data[key]" class="form-control form-control-sm" value="' . $data["key"] . '" />
												</div>
											</div>
											<div class="form-group">
												<div class="input-group">
													<span class="input-group-addon"><b>Secret</b></span>
													<input type="text" name="data[secret]" class="form-control form-control-sm" value="' . $data["secret"] . '" />
												</div>
											</div>
											<hr>
											<div class="form-group">
												<div class="input-group">
													<span class="input-group-addon"><b>Komisyon (%)</b></span>
													<input type="text" name="data[comission]" class="form-control form-control-sm" value="' . $data["comission"] . '" />
												</div>
											</div>
											<div class="form-group">
												<div class="input-group">
													<span class="input-group-addon"><b>Minimum Ödeme</b></span>
													<input type="number" name="data[min]" min="0" class="form-control form-control-sm" value="' . $data["min"] . '" />
												</div>
											</div>
											<div class="form-group">
												<div class="input-group">
													<span class="input-group-addon"><b>Maksimum Ödeme</b></span>
													<input type="number" name="data[max]" min="0" class="form-control form-control-sm" value="' . $data["max"] . '" />
												</div>
											</div>
											<hr>
											<div class="form-group">
												<label><b>WeePay CallBack (Geri Dönüş) Adresi:</b> <code>' . site('notify/shoplemo') . '</code></label>
											</div>
											<input type="hidden" name="id" value="' . $method['method_id'] . '" />
											<div class="form-group">
												<button type="submit" class="btn btn-success">Güncelle</button>
											</div>
										<form>
								';
							$response->title = $title;
							$response->order = $html;
						} else {

							$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
						}
					} elseif ($id == 6) {

						$method = $db->from('payment_methods')->where('method_id', $id)->first();

						if ($method) {

							$data = json_decode($method['method_details'], true);

							$title = "PayTR Havale/EFT Ayarları";
							$html = '	
										<form id="update_method" onsubmit="return false;" data-reset="0">
											<div class="form-group">
												<div class="input-group">
													<span class="input-group-addon"><b>Görünür İsim</b></span>
													<input type="text" name="data[name]" class="form-control form-control-sm" value="' . $data["name"] . '" />
												</div>
											</div>
											<div class="form-group">
												<div class="input-group">
													<span class="input-group-addon"><b>Durum</b></span>
													<select class="form-control" name="data[status]">
														<option value="1" ';
							($data["status"] == 1) ? $html .= "selected" : null;
							$html .= '>Aktif</option>
														<option value="0" ';
							($data["status"] == 0) ? $html .= "selected" : null;
							$html .= '>Pasif</option>
													</select>
												</div>
											</div>
											<hr>
											<div class="form-group">
												<div class="input-group">
													<span class="input-group-addon"><b>MID</b></span>
													<input type="text" name="data[mid]" class="form-control form-control-sm" value="' . $data["mid"] . '" />
												</div>
											</div>
											<div class="form-group">
												<div class="input-group">
													<span class="input-group-addon"><b>KEY</b></span>
													<input type="text" name="data[key]" class="form-control form-control-sm" value="' . $data["key"] . '" />
												</div>
											</div>
											<div class="form-group">
												<div class="input-group">
													<span class="input-group-addon"><b>SALT</b></span>
													<input type="text" name="data[salt]" class="form-control form-control-sm" value="' . $data["salt"] . '" />
												</div>
											</div>
											<hr>
											<div class="form-group">
												<div class="input-group">
													<span class="input-group-addon"><b>Komisyon (%)</b></span>
													<input type="text" name="data[comission]" class="form-control form-control-sm" value="' . $data["comission"] . '" />
												</div>
											</div>
											<div class="form-group">
												<div class="input-group">
													<span class="input-group-addon"><b>Minimum Ödeme</b></span>
													<input type="number" name="data[min]" min="0" class="form-control form-control-sm" value="' . $data["min"] . '" />
												</div>
											</div>
											<div class="form-group">
												<div class="input-group">
													<span class="input-group-addon"><b>Maksimum Ödeme</b></span>
													<input type="number" name="data[max]" min="0" class="form-control form-control-sm" value="' . $data["max"] . '" />
												</div>
											</div>
											<hr>
											<div class="form-group">
												<label><b>PayTR CallBack (Geri Dönüş) Adresi:</b> <code>' . site('notify/paytr') . '</code></label>
											</div>
											<input type="hidden" name="id" value="' . $method['method_id'] . '" />
											<div class="form-group">
												<button type="submit" class="btn btn-success">Güncelle</button>
											</div>
										<form>
								';
							$response->title = $title;
							$response->order = $html;
						} else {

							$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
						}
					} elseif ($id == 7) {

						$method = $db->from('payment_methods')->where('method_id', $id)->first();

						if ($method) {

							$data = json_decode($method['method_details'], true);

							$title = "Banka Havale/EFT Ayarları";
							$html = '	
										<form id="update_method" onsubmit="return false;" data-reset="0">
											<div class="form-group">
												<div class="input-group">
													<span class="input-group-addon"><b>Görünür İsim</b></span>
													<input type="text" name="data[name]" class="form-control form-control-sm" value="' . $data["name"] . '" />
												</div>
											</div>
											<div class="form-group">
												<div class="input-group">
													<span class="input-group-addon"><b>Durum</b></span>
													<select class="form-control" name="data[status]">
														<option value="1" ';
							($data["status"] == 1) ? $html .= "selected" : null;
							$html .= '>Aktif</option>
														<option value="0" ';
							($data["status"] == 0) ? $html .= "selected" : null;
							$html .= '>Pasif</option>
													</select>
												</div>
											</div>
											<hr>
											<div class="form-group">
												<div class="input-group">
													<span class="input-group-addon"><b>Minimum Ödeme</b></span>
													<input type="number" name="data[min]" min="0" class="form-control form-control-sm" value="' . $data["min"] . '" />
												</div>
											</div>
											<div class="form-group">
												<div class="input-group">
													<span class="input-group-addon"><b>Maksimum Ödeme</b></span>
													<input type="number" name="data[max]" min="0" class="form-control form-control-sm" value="' . $data["max"] . '" />
												</div>
											</div>
											<input type="hidden" name="id" value="' . $method['method_id'] . '" />
											<div class="form-group">
												<button type="submit" class="btn btn-success">Güncelle</button>
											</div>
										<form>
								';
							$response->title = $title;
							$response->order = $html;
						} else {

							$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
						}
					} elseif ($id == 8) {

						$method = $db->from('payment_methods')->where('method_id', $id)->first();

						if ($method) {

							$data = json_decode($method['method_details'], true);

							$title = "Papara Ayarları";
							$html = '
										<form id="update_method" onsubmit="return false;" data-reset="0">
											<div class="form-group">
												<div class="input-group">
													<span class="input-group-addon"><b>Görünür İsim</b></span>
													<input type="text" name="data[name]" class="form-control form-control-sm" value="' . htmlspecialchars($data["name"]) . '" />
												</div>
											</div>
											<div class="form-group">
												<div class="input-group">
													<span class="input-group-addon"><b>Durum</b></span>
													<select class="form-control" name="data[status]">
														<option value="1" ';
							($data["status"] == 1) ? $html .= "selected" : null;
							$html .= '>Aktif</option>
														<option value="0" ';
							($data["status"] == 0) ? $html .= "selected" : null;
							$html .= '>Pasif</option>
													</select>
												</div>
											</div>
											<hr>
											<div class="form-group">
												<div class="input-group">
													<span class="input-group-addon"><b>Papara Numarası</b></span>
													<input type="text" name="data[number]" class="form-control form-control-sm" value="' . htmlspecialchars($data["number"]) . '" />
												</div>
											</div>
											<div class="form-group">
												<div class="input-group">
													<span class="input-group-addon"><b>Papara Ön Eki</b></span>
													<input type="text" name="data[prefix]" class="form-control form-control-sm" value="' . htmlspecialchars($data["prefix"]) . '" />
												</div>
											</div>
											<div class="form-group">
												<div class="input-group">
													<span class="input-group-addon"><b>Papara IMAP Sunucu</b></span>
													<input type="text" name="data[imap_server]" class="form-control form-control-sm" value="' . htmlspecialchars($data["imap_server"]) . '" />
												</div>
											</div>
											<div class="form-group">
												<div class="input-group">
													<span class="input-group-addon"><b>Papara IMAP Kullanıcı</b></span>
													<input type="text" name="data[imap_user]" class="form-control form-control-sm" value="' . htmlspecialchars($data["imap_user"]) . '" />
												</div>
											</div>
											<div class="form-group">
												<div class="input-group">
													<span class="input-group-addon"><b>Papara IMAP Parolası</b></span>
													<input type="text" name="data[imap_password]" class="form-control form-control-sm" value="' . htmlspecialchars($data["imap_password"]) . '" />
												</div>
											</div>
											<hr>
											<div class="form-group">
												<div class="input-group">
													<span class="input-group-addon"><b>Komisyon (%)</b></span>
													<input type="text" name="data[comission]" class="form-control form-control-sm" value="' . $data["comission"] . '" />
												</div>
											</div>
											<hr>
											<div class="form-group">
												<div class="input-group">
													<span class="input-group-addon"><b>Minimum Ödeme</b></span>
													<input type="number" name="data[min]" min="0" class="form-control form-control-sm" value="' . $data["min"] . '" />
												</div>
											</div>
											<div class="form-group">
												<div class="input-group">
													<span class="input-group-addon"><b>Maksimum Ödeme</b></span>
													<input type="number" name="data[max]" min="0" class="form-control form-control-sm" value="' . $data["max"] . '" />
												</div>
											</div>
											<hr>
											<input type="hidden" name="id" value="' . $method['method_id'] . '" />
											<div class="form-group">
												<button type="submit" class="btn btn-success">Güncelle</button>
											</div>
										<form>
								';
							$response->title = $title;
							$response->order = $html;
						} else {

							$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
						}
					} else {
						$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
					}
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "get_captcha") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'integrations')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					$posts = [
						"id" => true
					];

					$error = false;

					foreach ($posts as $post => $required) {
						if ($required) {
							if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						} else {
							if (isset($_POST[$post])) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						}
					}

					$recaptcha = $db->from('recaptcha_settings')->where('id', $id)->first();

					if ($recaptcha) {

						$title = "reCaptcha Modül Ayarları";
						$html = '	
								<form id="update_recaptcha" onsubmit="return false;" data-reset="0">
									<div class="form-group">
										<div class="input-group">
											<span class="input-group-addon"><b>Site Key</b></span>
											<input type="text" name="site_key" class="form-control form-control-sm" value="' . $recaptcha["site_key"] . '" />
										</div>
									</div>
									<div class="form-group">
										<div class="input-group">
											<span class="input-group-addon"><b>Secret Key</b></span>
											<input type="text" name="secret_key" class="form-control form-control-sm" value="' . $recaptcha["secret_key"] . '" />
										</div>
									</div>
									<div class="form-group">
										<div class="input-group">
											<span class="input-group-addon"><b>Kayıt sayfası reCAPTCHA</b></span>
											<select name="register_page" class="form-control form-control-sm">
												<option value="0"';
						if ($recaptcha["register_page"] == 0) {
							$html .= 'selected';
						}
						$html .= '>Kapalı</option>
												<option value="1"';
						if ($recaptcha["register_page"] == 1) {
							$html .= 'selected';
						}
						$html .= '>Açık</option>
											</select>
										</div>
									</div>
									<div class="form-group">
										<div class="input-group">
											<span class="input-group-addon"><b>Giriş sayfası reCAPTCHA</b></span>
											<select name="login_page" class="form-control form-control-sm">
												<option value="0"';
						if ($recaptcha["login_page"] == 1) {
							$html .= 'selected';
						}
						$html .= '>Kapalı</option>
												<option value="1"';
						if ($recaptcha["login_page"] == 1) {
							$html .= 'selected';
						}
						$html .= '>Açık</option>
											</select>
										</div>
									</div>
									<div class="form-group text-right">
										<button type="submit" class="btn btn-success">Güncelle</button>
									</div>
								</form>';

						$response->title = $title;
						$response->order = $html;
					} else {

						$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
					}
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "get_integration") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'integrations')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					$posts = [
						"id" => true
					];

					$error = false;

					foreach ($posts as $post => $required) {
						if ($required) {
							if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						} else {
							if (isset($_POST[$post])) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						}
					}

					$query = $db->from('integrations')->where('app_id', $id)->first();

					if ($query) {

						$detail = json_decode($query['app_detail'], true);
						$appdata = json_decode($query['app_data'], true);

						$title = $query['app_title'] . " Entegrasyon Ayarları";
						$html = '<form id="update_integration" onsubmit="return false;" data-reset="0">';
						foreach ($detail['inputs'] as $row) :
							$html .= '<div class="form-group">
										<div class="input-group">
											<span class="input-group-addon"><b>' . $row['title'] . '</b></span>';
							if ($row['type'] == "text") :
								$html .= '
											<input type="text" name="app_data[' . $row['name'] . ']" class="form-control form-control-sm" value="' . $appdata[$row["name"]] . '" />';
							elseif ($row['type'] == "password") :
								$html .= '<input type="password" name="app_data[' . $row['name'] . ']" class="form-control form-control-sm" value="' . $appdata[$row["name"]] . '" />';
							elseif ($row['type'] == "textarea") :
								$html .= '<textarea name="app_data[' . $row['name'] . ']" class="form-control form-control-sm" rows="7">' . $appdata[$row["name"]] . '</textarea>';
							elseif ($row['type'] == "select") :
								$html .= '<select name="app_data[' . $row['name'] . ']" class="form-control">';
								foreach ($row['options'] as $data) :
									$html .= '<option value="' . $data['value'] . '"';
									if ($appdata[$row["name"]] == $data['value']) {
										$html .= ' selected';
									}
									$html .= '>' . $data['title'] . '</option>';
								endforeach;
								$html .= '</select>';
							endif;
							$html .= '</div>
									</div>';
						endforeach;
						$html .= '
									<input type="hidden" name="app_id" value="' . $query['app_id'] . '">
									<div class="form-group text-right">
										<button type="submit" class="btn btn-success">Güncelle</button>
									</div>
								</form>';

						$response->title = $title;
						$response->order = $html;
					} else {

						$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
					}
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "get_plugin") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'plugins')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					$posts = [
						"id" => true
					];

					$error = false;

					foreach ($posts as $post => $required) {
						if ($required) {
							if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						} else {
							if (isset($_POST[$post])) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						}
					}

					$query = $db->from('plugins')->where('plugin_id', $id)->first();

					if ($query) {

						$title = $query['plugin_title'] . " Eklenti Ayarları";

						if ($id == 1) {

							$data = json_decode($query['plugin_data'], true);
							$html = '<form id="update_plugin" onsubmit="return false;" data-reset="0">
											<div class="form-group">
												<div class="input-group">
													<span class="input-group-addon"><b>Verilecek Bakiye</b></span>
													<input type="text" name="data[gift_amount]" class="form-control" value="' . $data['gift_amount'] . '">
												</div>
												<small>Sadece sayı yazınız, virgül yerine nokta kullanınız.</small>
											</div>
											<input type="hidden" name="id" value="' . $query['plugin_id'] . '">
											<div class="form-group text-right">
												<button type="submit" class="btn btn-success">Güncelle</button>
											</div>
										 </form>';
						} elseif ($id == 2) {

							$html = '<b>Bu eklentiye ait düzenlenebilir ayar bulunmamaktadır.</b>';
						} elseif ($id == 3) {

							$data = json_decode($query['plugin_data'], true);
							$html = '<form id="update_plugin" onsubmit="return false;" data-reset="0">
											<div class="form-group">
												<div class="input-group">
													<span class="input-group-addon"><b>Referans Kazanç Oranı</b></span>
													<input type="text" name="data[reference_share]" class="form-control" value="' . $data['reference_share'] . '">
												</div>
												<small>Sadece sayı yazınız, virgül yerine nokta kullanınız.</small>
											</div>
											<input type="hidden" name="id" value="' . $query['plugin_id'] . '">
											<div class="form-group text-right">
												<button type="submit" class="btn btn-success">Güncelle</button>
											</div>
										 </form>';
						}

						$response->title = $title;
						$response->order = $html;
					} else {

						$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
					}
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "update_plugin") {
		if (login_control()) {

			if ($user["user_authority"] == 2) {

				if (!permission('access', 'edit')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					$id = $_POST['id'];
					$data = json_encode($_POST['data']);

					if (!$id || !$data) {
						$error = true;
					} else {
						$error = false;
					}

					if (!$error) {

						$update = $db->update('plugins')->where('plugin_id', $id)
							->set(array(
								'plugin_data' => $data
							));

						if ($update) {
							$response->success = "Entegrasyon ayarları güncellendi.";
						} else {
							$response->error = "Sistem hatası oluştu.";
						}
					} else {
						$response->error = "Eksik veya hatalı alanlar mevcut.";
					}
				}
			} else {

				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {

			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "update_integration") {
		if (login_control()) {

			if ($user["user_authority"] == 2) {

				if (!permission('access', 'edit')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					$id = $_POST['app_id'];
					$data = json_encode($_POST['app_data']);

					if (!$id || !$data) {
						$error = true;
					} else {
						$error = false;
					}

					if (!$error) {

						$update = $db->update('integrations')->where('app_id', $id)
							->set(array(
								'app_data' => $data
							));

						if ($update) {
							$response->success = "Entegrasyon ayarları güncellendi.";
						} else {
							$response->error = "Sistem hatası oluştu.";
						}
					} else {
						$response->error = "Eksik veya hatalı alanlar mevcut.";
					}
				}
			} else {

				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {

			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "get_discord") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'integrations')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					$posts = [
						"id" => true
					];

					$error = false;

					foreach ($posts as $post => $required) {
						if ($required) {
							if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						} else {
							if (isset($_POST[$post])) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						}
					}

					$ayar = $db->from('settings')->where('id', $id)->first();

					if ($ayar) {

						$title = "Discord Modül Ayarları";
						$html = '	
								<form id="update_discord" onsubmit="return false;" data-reset="0">
									<div class="form-group">
										<div class="input-group">
											<span class="input-group-addon"><b>Üye Aksiyon Bildirimleri</b></span>
											<input type="text" name="discord_notify_url" placeholder="https://discordapp.com/api/webhooks/000000000000000000000/dNZIKChoheDqVWVs1rW6Mi19SaoqGTubGH-zt6keS7kXIspFV7e3vMg7a_FH40R19kaE" class="form-control form-control-sm" value="' . $ayar["discord_notify_url"] . '" />
										</div>
										<small>Bu alan üyelerinizin yaptığı aksiyonları bildirir.</small>
									</div>
									<div class="form-group">
										<div class="input-group">
											<span class="input-group-addon"><b>API Bildirimleri</b></span>
											<input type="text" name="discord_apiNotify_url" placeholder="https://discordapp.com/api/webhooks/000000000000000000000/dNZIKChoheDqVWVs1rW6Mi19SaoqGTubGH-zt6keS7kXIspFV7e3vMg7a_FH40R19kaE" class="form-control form-control-sm" value="' . $ayar["discord_apiNotify_url"] . '" />
										</div>
										<small>Bu alan API Güncellemelerini bildirir.</small>
									</div>
									<div class="form-group text-right">
										<button type="submit" class="btn btn-success">Güncelle</button>
									</div>
								</form>
							';

						$response->title = $title;
						$response->order = $html;
					} else {

						$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
					}
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "get_sendsms") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'users')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					$posts = [
						"id" => true
					];

					$error = false;

					foreach ($posts as $post => $required) {
						if ($required) {
							if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						} else {
							if (isset($_POST[$post])) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						}
					}

					if ($id == "send") {
						$title = "Toplu SMS Gönder";
						$html = '
								<form id="send_sms" onsubmit="return false;" data-reset="0">
									<div class="form-group">
										<label>Numaralar(her satıra bir tane)</label>
										<textarea name="numbers" rows="8" class="form-control form-control-sm"></textarea>
									</div>
									<div class="form-group">
										<label>Mesaj</label>
										<textarea name="message" rows="8" class="form-control form-control-sm"></textarea>
									</div>
									<div class="form-group text-right">
										<button type="submit" class="btn btn-success">Gönder</button>
									</div>
								</form>';
						$response->title = $title;
						$response->order = $html;
					} elseif ($id == "numbers") {

						$numbers = $db->query("SELECT user_skype FROM `users` WHERE user_skype != ''")->fetchAll(PDO::FETCH_ASSOC);
						$email = $db->prepare("SELECT user_email FROM users");
						$email->execute();
						$email = $email->fetchALL();
						$tempNumbers = "";
						$emailler = "";
						foreach ($email as $mail) {
							$emailler .= $mail['user_email'] . "\n";
						}
						foreach ($numbers as $number) {
							$tempNumbers .= $number["user_skype"] . "\n";
						}
						$numbers = trim($tempNumbers, "\n");
						$emailler = trim($emailler, "\n");

						$title = "Üye Bilgileri";
						$html = '<textarea rows="15" class="form-control" style="margin-bottom:20px;">' . $numbers . '</textarea>';
						$html .= '<textarea rows="15" class="form-control" style="margin-bottom:20px;">' . $emailler . '</textarea>';
						$response->title = $title;
						$response->order = $html;
					} else {

						$response->error = "{MESSAGE_WRONG_REQUEST}";
					}
				}
			} else {

				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {

			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "get_sendemail") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'users')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					$posts = [
						"id" => true
					];

					$error = false;

					foreach ($posts as $post => $required) {
						if ($required) {
							if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						} else {
							if (isset($_POST[$post])) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						}
					}

					if ($id == "send") {
						$title = "Toplu Mail Gönder";
						$html = '
								<form id="sendemail" onsubmit="return false;" data-reset="0">
									<div class="form-group">
										<label>Emailler(her satıra bir tane)</label>
										<textarea name="numbers" rows="8" class="form-control form-control-sm"></textarea>
									</div>
									<div class="form-group">
										<label>Email Başlığı</label>
										<input name="baslik" rows="8" class="form-control form-control-sm"></input>
									</div>
									<div class="form-group">
										<label>Mesaj</label>
										<textarea name="message" rows="8" class="form-control form-control-sm"></textarea>
									</div>
									<div class="form-group text-right">
										<button type="submit" class="btn btn-success">Gönder</button>
									</div>
								</form>';
						$response->title = $title;
						$response->order = $html;
					} elseif ($id == "numbers") {

						$numbers = $db->query("SELECT user_skype FROM `users` WHERE user_skype != ''")->fetchAll(PDO::FETCH_ASSOC);
						$tempNumbers = "";
						foreach ($numbers as $number) {
							$tempNumbers .= $number["user_skype"] . "\n";
						}
						$numbers = trim($tempNumbers, "\n");
						$title = "Üye Bilgileri";
						$html = '<textarea rows="15" class="form-control" style="margin-bottom:20px;">' . $numbers . '</textarea>';

						$response->title = $title;
						$response->order = $html;
					} else {

						$response->error = "{MESSAGE_WRONG_REQUEST}";
					}
				}
			} else {

				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {

			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "update_guard_settings") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				$posts = [
					"guard_status" => true
				];

				$error = false;

				foreach ($posts as $post => $required) {
					if ($required) {
						if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
							$$post = filter($_POST[$post]);
						} else {
							$error = true;
							break;
						}
					} else {
						if (isset($_POST[$post])) {
							$$post = filter($_POST[$post]);
						} else {
							$error = true;
							break;
						}
					}
				}

				if (!$error) {

					$array = [
						"guard_status" => $guard_status
					];

					$posts = json_encode($array);

					$update = $db->update('settings')
						->where('id', 1)
						->set(array(
							'guard_settings' => $posts
						));

					if ($update) {
						$response->success = "Guard ayarları başarıyla güncelleştirildi.";
					} else {
						$response->error = "Bilgiler güncelleştirilemedi, daha sonra tekrar deneyiniz.";
					}
				} else {

					$response->error = "Boş veya hatalı alanlar mevcut.";
				}
			} else {

				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {

			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "update_cron_settings") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				$posts = [
					"cron_min_change" => true,
					"cron_max_change" => true,
					"cron_status_change" => true,
					"cron_price_change" => true,
					"cron_price_rate" => true
				];

				$error = false;

				foreach ($posts as $post => $required) {
					if ($required) {
						if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
							$$post = filter($_POST[$post]);
						} else {
							$error = true;
							break;
						}
					} else {
						if (isset($_POST[$post])) {
							$$post = filter($_POST[$post]);
						} else {
							$error = true;
							break;
						}
					}
				}

				if (!$error) {

					$array = [
						"cron_min" => $cron_min_change,
						"cron_max" => $cron_max_change,
						"cron_status" => $cron_status_change,
						"cron_price" => $cron_price_change,
						"cron_price_rate" => $cron_price_rate
					];

					$posts = json_encode($array);

					$update = $db->update('settings')
						->where('id', 1)
						->set(array(
							'cron_settings' => $posts
						));

					if ($update) {
						$response->success = "CRON ayarları başarıyla güncelleştirildi.";
					} else {
						$response->error = "Bilgiler güncelleştirilemedi, daha sonra tekrar deneyiniz.";
					}
				} else {

					$response->error = "Boş veya hatalı alanlar mevcut.";
				}
			} else {

				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {

			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "get_usersms") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'users')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					$posts = [
						"id" => true
					];

					$error = false;

					foreach ($posts as $post => $required) {
						if ($required) {
							if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						} else {
							if (isset($_POST[$post])) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						}
					}

					$user = $db->from('users')->where('user_id', $id)->first();

					if ($user) {
						$title = "SMS Gönder";
						$html = '
								<form id="send_sms" onsubmit="return false;" data-reset="0">
									<div class="form-group">
										<label>Numaralar(her satıra bir tane)</label>
										<input type="text" name="numbers" class="form-control" value="' . $user['user_skype'] . '" readonly>
									</div>
									<div class="form-group">
										<label>Mesaj</label>
										<textarea name="message" rows="8" class="form-control form-control-sm"></textarea>
									</div>
									<div class="form-group text-right">
										<button type="submit" class="btn btn-success">Gönder</button>
									</div>
								</form>';
						$response->title = $title;
						$response->order = $html;
					} else {

						$response->error = "{MESSAGE_WRONG_REQUEST}";
					}
				}
			} else {

				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {

			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "api_service_add") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'edit')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					$services     	= $_POST["servicesList"];
					$provider_id  	= $_POST["provider"];
					$percent    	= $_POST["percent"];
					$provider 		= $db->from('apis')->where('api_id', $provider_id)->first();
					$cat 			= intval(@$_POST["category"]);
					$apiServices 	= services($provider["api_url"], $provider["api_key"]);
					$balance 		= api_balance($provider["api_url"], $provider["api_key"]);

					if (count($services)) {

						foreach ($services as $service => $price) {

							foreach ($apiServices as $apiService) {

								if ($service == $apiService['service'] && $service != 0) {

									$detail['min'] 		= $apiService['min'];
									$detail['max']		= $apiService['max'];
									$detail['rate']		= $apiService['rate'];
									$detail['currency']	= $balance['currency'];
									$package 			= serviceTypeGetList($apiService['type']);
									$encodename 		= Emoji::Encode($apiService['name']);
									$name2 				= '[{"lang":1,"name":"' . $encodename . '"}]';

									$desc = '[{"lang":1,"name":"&amp;lt;strong&amp;gt;Dikkat Etmeniz Gerekenler:&amp;lt;/strong&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;★ Profiliniz gizli olmamalıdır.&amp;lt;br&amp;gt;★ Bir sipariş devam ederken ikinci siparişi girmemelisiniz.&amp;lt;br&amp;gt;★ Yoğunluğa bağlı olarak siparişlerin başlama ve yüklenme süreleri değişebilir.&amp;lt;br&amp;gt;"}]';

									if ($package == 11) {

										$insert = $db->insert('services')
											->set(array(
												'category_id' => $cat,
												'api_id' => $provider_id,
												'api_service' => $service,
												'api_detail' => json_encode($detail),
												'service_number' => 1,
												'api_type' => 2,
												'service_status' => 1,
												'service_name' => $name2,
												'service_charge' => round($price, 5),
												'service_min' => $apiService['min'],
												'service_max' => $apiService['max'],
												'cron_price_rate' => $percent,
												'service_min_max' => '{"min":1,"max":1}',
												'service_auto' => 0,
												'service_drip' => 0,
												'service_package' => 1,
												'service_comment' => 0,
												'service_desc' => $desc
											));
									} else {
                                        
                                        
                                        if(isset($_POST['providersync'])) {
                                            if ($_POST['providersync'] == "on") {
                                                $sync = [
                                                    "min" => 1,
                                                    "max" => 1
                                                ];
                                            } else {
                                                $sync = [
                                                    "min" => 0,
                                                    "max" => 0
                                                ];
                                            }
                                        } else {
                                            $sync = [
                                                "min" => 0,
                                                "max" => 0
                                            ];
                                        }

										if ($_POST['sabit']) {
											$fixedprice = $_POST['sabit'];
										} else {
											$fixedprice = "0";
										}

										if ($_POST['percent']) {
											$per = $_POST['percent'];
										} else {
											$per = "0";
										}

										$insert = $db->insert('services')
											->set(array(
												'category_id' => $cat,
												'api_id' => $provider_id,
												'api_service' => $service,
												'api_detail' => json_encode($detail),
												'service_number' => 1,
												'api_type' => 2,
												'service_status' => 1,
												'service_name' => $name2,
												'service_charge' => round($price, 5),
												'service_min' => $apiService['min'],
												'service_max' => $apiService['max'],
												'service_min_max' => json_encode($per),
												'service_fixed_price' => $fixedprice,
												'cron_price_rate' => $per,
												'service_auto' => 0,
												'service_drip' => 0,
												'service_package' => 0,
												'service_comment' => 0,
												'service_desc' => $desc
											));
									}
								}
							}
						}

						$response->success = "Servisler başarıyla eklendi.";
					} else {

						$response->error = "İşlem başarısız, daha sonra tekrar deneyiniz.";
					}
				}
			} else {

				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {

			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "get_apiservice") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'edit')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					$providers = $db->from('apis')->all();
					$categories = $db->from('categories')->all();

					$tempCategories = [];
					foreach ($categories as $cat) {
						$category_name = json_decode($cat["category_name"], true);
						$name = null;
						foreach ($category_name as $details) {
							if ($details["lang"] == 1) {
								$name = $details["name"];
							}
						}
						$cat["category_name"] = $name;
						$tempCategories[] = $cat;
					}
					$categories = $tempCategories;

					if ($user) {

						$title = "API ile Toplu Servis Ekle";
						$html = '
								<form id="api_service_add" onsubmit="return false;" data-reset="0">
									<div id="step-one">
										<div class="alert alert-info">Toplu servis çekme hizmeti sadece normal servisleri çekmektedir, otomatik izlenme ve benzeri servisler çekilmez.</div> 
										<div class="form-group">
											<div class="input-group">
												<span class="input-group-addon">Servis Sağlayıcı</span>
												<select class="form-control" name="provider" id="provider">
													<option value="0">Servis sağlayıcı seçiniz...</option>';
						foreach ($providers as $provider) :
							$html .= '<option value="' . $provider["api_id"] . '">' . $provider["api_url"] . '</option>';
						endforeach;
						$html .= '</select>
											</div>
										</div>
										<div class="form-group">
											<div class="input-group">
												<span class="input-group-addon">Kategori Seçiniz</span>
												<select class="form-control" name="cat" id="cat">
													<option value="0">Kategori Seçiniz...</option>';
						foreach ($categories as $cat) :
							$html .= '<option value="' . $cat["category_id"] . '">' . $cat["category_name"] . '</option>';
						endforeach;
						$html .= '</select>
											</div>
										</div>
									</div>
									<div id="step-two">
									</div>
									<div id="step-three">
									</div>

									<div class="form-group text-right">
										<button type="button" class="btn btn-success" id="nextStep" data-step="first">Devam Et</button>
										<button type="submit" class="btn btn-primary" id="submitStep">Servisleri ekle</button>
									</div>
								</form>
								<script>
            						$("#submitStep").hide();
            						$("#nextStep").click(function(){

						              	var now_step = $(this).attr("data-step");
						              	var provider = $("#provider").val();
						              	var category = $("#cat").val();
              							$("#step-two").hide();

                						if( now_step == "first" ){

                  							if( provider == 0 ){
                  								iziToast.show({
													title: "Hata",
													message: "Lütfen servis sağlayıcısını seçin",
													timeout: delay,
													position: "center"
												});
                  							}else if( category == 0 ){
                  								iziToast.show({
													title: "Hata",
													message: "Lütfen kategori seçin",
													timeout: delay,
													position: "center"
												});
                  							}else{
							                    $("#step-one").hide();
							                    $("#step-two").show();
							                    $.post("../request/get_apiservice_list", {provider:provider,category:category}, function(data){
							                      $("#step-two").html(data);
							                    });
							                    $("#nextStep").attr("data-step","second");
                  							}

                						}else if( now_step == "second" ){

                    						var array     = [];
					                       	$(\'[class^="selectServices-"]\').each(function () {
					                            var id    = $(this).val();
					                            var check = $(this).prop("checked");
					                            var provider  =  $(this).attr("data-provider");
					                              if( check == true ){
					                                var params = {};
					                                params["id"]            = id;
					                                params["category"]      = $(this).attr("data-category");
					                                array.push(params);
					                              }
					                       	});
					                       	var count = array.length;
					                     	if( count ){
					                       		$.post("../request/get_apiservice_last", {provider:provider,services:array }, function(data){
					                         		$("#step-three").html(data);
					                       		});
					                       		$("#nextStep").hide();
					                       		$("#submitStep").show();
					                     	}else{
					                       		$("#nextStep").attr("data-step","second");
					                       		$("#step-one").hide();
					                       		$("#step-two").show();
					                       		$("#nextStep").show();
					                       		$("#submitStep").hide();
					                       		iziToast.show({
													title: "Hata",
													message: "Lütfen en az 1 servis seçiniz.",
													timeout: delay,
													position: "center"
												});
                     						}
                						}
            						});
          						</script>';

						$response->title = $title;
						$response->order = $html;
					} else {

						$response->error = "{MESSAGE_WRONG_REQUEST}";
					}
				}
			} else {

				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {

			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "get_apiservice_list") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				$posts = [
					"provider" => true,
					"category" => true
				];

				$error = false;

				foreach ($posts as $post => $required) {
					if ($required) {
						if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
							$$post = filter($_POST[$post]);
						} else {
							$error = true;
							break;
						}
					} else {
						if (isset($_POST[$post])) {
							$$post = filter($_POST[$post]);
						} else {
							$error = true;
							break;
						}
					}
				}

				$providerQuery = $db->from('apis')->where('api_id', $provider)->first();

				if ($providerQuery) {

					$services = services($providerQuery["api_url"], $providerQuery["api_key"]);

					if ($services) {

						$grouped = array_group_by($services, 'category');

						$html = '
							<div class="services-import__body">
								<div class="services-import__list-wrap">
									<div class="services-import__scroll-wrap">';
							foreach ($grouped as $row) :
								$provider++;
								$html .= '
									<span>
										<div class="services-import__category">
											<div class="services-import__category-title">
												<label style="margin-bottom:0;"><input type="checkbox" data-id="' . $provider . '" id="checkAll-' . $provider . '">' . $row[0]['category'] . '</label>
                                                <input type="hidden" name="category" value="' . $category . '">
											</div>
                            			</div>
                             			<div class="services-import__packages">
	                                		<ul>';
							for ($i = 0; $i < count($row); $i++) :
								$html .= '<li>
	                                				<label>
	                                					<input data-service="' . $row[$i]['name'] . '" data-provider="' . $providerQuery["api_id"] . '"  data-category="' . $provider . '"  class="selectServices-' . $provider . '" type="checkbox" value="' . $row[$i]['service'] . '" name="services[]">' . $row[$i]['service'] . ' - ' . $row[$i]['name'] . '
	                                					<span class="services-import__packages-price">' . $row[$i]['rate'] . '</span>
	                                				</label>
	                                			</li>';
							endfor;
							$html .= '</ul>
                                		</div>
                                	</span>';
						endforeach;
						$html .= '</div>
                            </div>
                            <script>
					            $(\'[id^="checkAll-"]\').click(function () {

					                var id = $(this).attr("data-id");
					                if ( $(this).prop("checked") == true ) {

					                   $(".selectServices-"+id).not(this).prop("checked", true);
					                }else{

					                   $(".selectServices-"+id).not(this).prop("checked", false);

					                }

					            });
				            </script>';

						echo $html;
					} else {

						$response->error = "{MESSAGE_WRONG_REQUEST}";
					}
				} else {

					$response->error = "{MESSAGE_WRONG_REQUEST}";
				}
			}
		} else {

			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "get_apiservice_last") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				$provider 		= $_POST['provider'];
				$providerQuery 	= $db->from('apis')->where('api_id', $provider)->first();
				$apiServices 	= services($providerQuery["api_url"], $providerQuery["api_key"]);

				if ($providerQuery) {

					$services = json_decode(json_encode($_POST["services"]), true);

					if ($services) {

						$grouped = array_group_by($services, 'category');


						$html = '
							<div class="services-import__body">
								<div class="services-import__list-wrap services-import__list-active">

				                   	<div class="services-import__step3-field">
				                   		<div class="row">
				                   			<div class="col-md-6">
					                   			<div class="panel panel-default">
					                   				<div class="panel-body">
					                      				<div class="services-import__placeholder-title" style="margin-bottom:5px;"><b>Yüzde (%)</b></div>
					                      				<input type="number" class="form-control" placeholder="0" id="raise-percent" name="percent" value="">
					                      			</div>
					                      		</div>
					                      		<div class="form-group">
													<div class="input-group">
														<span class="input-group-addon"><input type="checkbox" class="custom-control-input"></span>
														<input style="font-weight: 700;" type="text" class="form-control" readonly="" name="providersync" value="Sağlayıcı Senkronizasyonu">
													</div>
												</div>
					                      	</div>
				                   			<div class="col-md-6">
					                   			<div class="panel panel-default">
					                   				<div class="panel-body">
					                      				<div class="services-import__placeholder-title" style="margin-bottom:5px;"><b>Sabit Kar</b></div>
					                      				<input type="double" class="form-control" placeholder="0" id="raise-fixed" name="sabit" value="">
					                      			</div>
					                      		</div>
					                      		<div class="services-import__step3-actions" style="margin:20px 0;"><span class="btn btn-default" style="width:100%;">Hesaplamaları sıfırla</span></div>
					                      	</div>
				                      	</div>
				                   	</div>
									<div class="services-import__scroll-wrap">';

						$category_id  = 0;
						$c = 0;
						foreach ($grouped as $category) :
							foreach ($apiServices as $key => $value) :
								if ($category[$category_id]['id'] == $value['service']) :
									$categoryName = $value['category'];
								endif;
							endforeach;
							$category_id = $category_id++;
							$c++;
							$html .= '
				                    <span class="providerCategory" id="providerCategory-' . $c . '">
			                           	<div class="services-import__category">
			                              	<div class="services-import__category-title"><label style="margin-bottom:0;">' . $categoryName . '</label></div>
			                           	</div>
			                           	<div class="services-import__packages">
                              			<ul>';

							for ($i = 0; $i < count($category); $i++) :
								foreach ($apiServices as $apiService) :
									if ($apiService['service'] == $category[$i]['id']) :

										$html .= '<li id="providerService-' . $apiService['service'] . '">
                                         <label>
                                            ' . $apiService['service'] . ' - ' . $apiService['name'] . '
                                            <span class="services-import__packages-price-edit" >
                                               <div class="services-import__packages-price-lock" data-category="' . $c . '"  data-id="servicedelete-' . $apiService['service'] . '" data-service="' . $apiService['service'] . '">
                                                 <span class="fa fa-trash"></span>
                                               </div>
                                               <input id="servicePriceCal' . $apiService['service'] . '" type="text" class="services-import__price" data-rate="' . $apiService['rate'] . '" data-service="' . $apiService['service'] . '" name="servicesList[' . $apiService['service'] . ']" value="' . $apiService['rate'] . '">
                                               <span class="services-import__provider-price">' . $apiService['rate'] . '</span>
                                            </span>
                                         </label>
                                      </li>';
									endif;
								endforeach;
							endfor;
							$html .=  '</ul>
                           </div>
                        </span>';
						endforeach;
						$html .= '</div></div></div><script>
          function formatCurrency(total) {
              var neg = false;
              if(total < 0) {
                  neg = true;
                  total = Math.abs(total);
              }
              return parseFloat(total, 10).toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, "$1,").toString();
          }
          function sum(input){
           if (toString.call(input) !== "[object Array]")
              return false;

                      var total =  0;
                      for(var i=0;i<input.length;i++)
                        {
                          if(isNaN(input[i])){
                          continue;
                           }
                      total += Number(input[i]);
                   }
             return total;
            }
          function chargeService(){
            var add_fixed       = $("#raise-fixed").val();
            var add_percent     = $("#raise-percent").val();
            $(".services-import__price").each(function(){
              if( $(this).attr("readonly") != "readonly" ){
                var rate        = $(this).attr("data-rate");
                var service     = $(this).attr("data-service");
                var total = sum([rate,(rate*add_percent/100),add_fixed]);
                $("#servicePriceCal"+service).val(total);

              }
            });
          }
            $(\'[data-id^="servicedelete-"]\').click(function(){
              var id        = $(this).attr("data-service");
              var category  = $(this).attr("data-category");
              $("li#providerService-"+id).remove();
                if( $("#providerCategory-"+category+" > .services-import__packages > ul > li").length == 0 ){
                  $("#providerCategory-"+category).remove();
                }
            });
            $(\'[data-id^="servicelock-"]\').click(function(){
              var service_id  = $(this).attr("data-service");
              var lock        = $(this).find("span").attr("class");
              if( lock == "fa fa-unlock" ){
                $(this).find("span").removeClass("fa fa-unlock");
                $(this).find("span").addClass("fa fa-lock");
                $(\'[data-service="\'+service_id+\'"]\').attr("readonly",true);
              } else{
                $(this).find("span").removeClass("fa fa-lock");
                $(this).find("span").addClass("fa fa-unlock");
                $(\'[data-service="\'+service_id+\'"]\').attr("readonly",false);
              }
            });

            $(".services-import__step3-actions").click(function(){
              var add_fixed       = $("#raise-fixed").val("");
              var add_percent     = $("#raise-percent").val("");
              $(".services-import__price").each(function(){
                if( $(this).attr("readonly") != "readonly" ){
                  var rate        = $(this).attr("data-rate");
                  var service     = $(this).attr("data-service");
                    $("#servicePriceCal"+service).val(rate);
                }
              });
            });

            $("#raise-fixed").on("keyup", function(){
              chargeService();
            });

            $("#raise-percent").on("keyup", function(){
              chargeService();
            });

          </script>';



						echo $html;
					} else {

						$response->error = "{MESSAGE_WRONG_REQUEST}";
					}
				} else {

					$response->error = "{MESSAGE_WRONG_REQUEST}";
				}
			}
		} else {

			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "edit_provider") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				$posts = [
					"id" => true
				];

				$error = false;

				foreach ($posts as $post => $required) {
					if ($required) {
						if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
							$$post = filter($_POST[$post]);
						} else {
							$error = true;
							break;
						}
					} else {
						if (isset($_POST[$post])) {
							$$post = filter($_POST[$post]);
						} else {
							$error = true;
							break;
						}
					}
				}

				$api = $db->from('apis')->where('api_id', $id)->first();

				if ($api) {


					$title = $api['api_id'] . " numaralı Servis Sağlayıcı düzenleniyor.";
					$html = '<form id="update_api" onsubmit="return false;" data-reset="0">
					            	<input type="hidden" name="id" value="' . $api['api_id'] . '" >
								<div class="form-group">
									<div class="input-group">
										<span class="input-group-addon"><b>API URL</b></span>
										<input type="text" name="url" class="form-control" value="' . $api['api_url'] . '" required>
									</div>
								</div>
								<div class="form-group">
									<div class="input-group">
										<span class="input-group-addon"><b>API KEY</b></span>
										<input type="text" name="key" class="form-control" value="' . $api['api_key'] . '" required>
									</div>
								</div>
								<div class="form-group text-right">
									<button type="button" class="btn btn-default" data-dismiss="modal">Vazgeç</button>
									<button type="submit" class="btn btn-success">Bilgileri Güncelle</button>
								</div>
						</form>';

					$response->title = $title;
					$response->order = $html;
				} else {

					$response->error = "{MESSAGE_WRONG_REQUEST}";
				}
			}
		} else {

			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "get_sms") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'integrations')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					$posts = [
						"id" => true
					];

					$error = false;

					foreach ($posts as $post => $required) {
						if ($required) {
							if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						} else {
							if (isset($_POST[$post])) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						}
					}

					if ($id == 1) {

						$sms = $db->from('sms_settings')->where('id', $id)->first();

						if ($sms) {

							$title = "BizimSMS Modül Ayarları";
							$html = '	
										<form id="update_sms" onsubmit="return false;" data-reset="0">
											<div class="form-group">
												<div class="input-group">
													<span class="input-group-addon"><b>Kullanıcı Adı</b></span>
													<input type="text" name="username" class="form-control form-control-sm" value="' . $sms["username"] . '" />
												</div>
											</div>
											<div class="form-group">
												<div class="input-group">
													<span class="input-group-addon"><b>Parola</b></span>
													<input type="password" name="password" class="form-control form-control-sm" value="' . $sms["password"] . '" />
												</div>
											</div>
											<div class="form-group">
												<div class="input-group">
													<span class="input-group-addon"><b>SMS Başlık</b></span>
													<input type="text" name="sms_title" class="form-control form-control-sm" value="' . $sms["sms_title"] . '" />
												</div>
											</div>
											<input type="text" name="id" value="' . $sms["id"] . '" style="display:none;">
											<div class="form-group text-right">
												<button type="submit" class="btn btn-success">Güncelle</button>
											</div>
										</form>
								';
							$response->title = $title;
							$response->order = $html;
						} else {

							$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
						}
					} elseif ($id == 2) {

						$sms = $db->from('sms_settings')->where('id', $id)->first();

						if ($sms) {

							$title = "İletiMerkezi Modül Ayarları";
							$html = '	
										<form id="update_sms" onsubmit="return false;" data-reset="0">
											<div class="form-group">
												<div class="input-group">
													<span class="input-group-addon"><b>Kullanıcı Adı</b></span>
													<input type="text" name="username" class="form-control form-control-sm" value="' . $sms["username"] . '" />
												</div>
											</div>
											<div class="form-group">
												<div class="input-group">
													<span class="input-group-addon"><b>Parola</b></span>
													<input type="password" name="password" class="form-control form-control-sm" value="' . $sms["password"] . '" />
												</div>
											</div>
											<div class="form-group">
												<div class="input-group">
													<span class="input-group-addon"><b>SMS Başlık</b></span>
													<input type="text" name="sms_title" class="form-control form-control-sm" value="' . $sms["sms_title"] . '" />
												</div>
											</div>
											<input type="text" name="id" value="' . $sms["id"] . '" style="display:none;">
											<div class="form-group text-right">
												<button type="submit" class="btn btn-success">Güncelle</button>
											</div>
										</form>
								';
							$response->title = $title;
							$response->order = $html;
						} else {

							$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
						}
					} elseif ($id == 3) {

						$sms = $db->from('sms_settings')->where('id', $id)->first();

						if ($sms) {

							$title = "NetGSM Modül Ayarları";
							$html = '
										<form id="update_sms" onsubmit="return false;" data-reset="0">
											<div class="form-group">
												<div class="input-group">
													<span class="input-group-addon"><b>Kullanıcı Adı</b></span>
													<input type="text" name="username" class="form-control form-control-sm" value="' . $sms["username"] . '" />
												</div>
											</div>
											<div class="form-group">
												<div class="input-group">
													<span class="input-group-addon"><b>Parola</b></span>
													<input type="password" name="password" class="form-control form-control-sm" value="' . $sms["password"] . '" />
												</div>
											</div>
											<div class="form-group">
												<div class="input-group">
													<span class="input-group-addon"><b>SMS Başlık</b></span>
													<input type="text" name="sms_title" class="form-control form-control-sm" value="' . $sms["sms_title"] . '" />
												</div>
											</div>
											<input type="text" name="id" value="' . $sms["id"] . '" style="display:none;">
											<div class="form-group text-right">
												<button type="submit" class="btn btn-success">Güncelle</button>
											</div>
										</form>
								';
							$response->title = $title;
							$response->order = $html;
						} else {

							$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
						}
					} else {

						$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
					}
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "get_duyuru") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'announcements')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					$posts = [
						"id" => true
					];
					$error = false;
					foreach ($posts as $post => $required) {
						if ($required) {
							if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						} else {
							if (isset($_POST[$post])) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						}
					}
					if (!$error) {

						$query = $db->from('duyuru')->where('id', $id)->first();

						if ($query) {
							$title = "Duyuru Düzenle";
							$html = '
									<form id="update_duyuru" onsubmit="return false;" data-reset="0">
										<input type="hidden" name="id" value="' . $query["id"] . '" />

										<div class="form-group">
											<label><b>Duyuru:</b></label>
											<textarea name="duyuru_content" class="form-control">' . $query['duyuru_content'] . '</textarea>
										</div>

										<div class="form-group text-right">
											<button type="submit" style="width:100%" class="modal-button">Güncelle</button>
										</div>
									</form>
									<script>$(".summernote").summernote({height: 300});</script>
								';
							$response->order = $html;
						} else {
							$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
						}
					} else {
						$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
					}
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "get_category") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'services')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					$posts = [
						"id" => true
					];
					$error = false;
					foreach ($posts as $post => $required) {
						if ($required) {
							if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						} else {
							if (isset($_POST[$post])) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						}
					}
					if (!$error) {

						$category = $db->from('categories')->where('category_id', $id)->first();

						if ($category) {

							$category_name = json_decode($category["category_name"], true);
							$languages = [];

							foreach ($category_name as $details) {

								$languages[$details["lang"]] = $details["name"];
							}
							$title = "Kategori Düzenle";
							$html = '
									<form id="update_category" onsubmit="return false;" data-reset="0">
										<input type="hidden" name="id" value="' . $category["category_id"] . '" />
										<div class="form-group">';
							foreach ($langs as $lang) :
								$html .= '<label>Kategori adı (' . $lang["lang_code"] . ')</label>
														<input type="text" id="lang_' . $lang["lang_id"] . '" name="name[' . $lang["lang_id"] . ']" class="form-control" value="';
								if (array_key_exists($lang["lang_id"], $languages)) {
									$html .= '' . $languages[$lang["lang_id"]] . '';
								}
								$html .= '" />';
							endforeach;
							$html .= '</div>

			

										<div class="form-group">
											<label>Kategori ICON</label>
											<div class="input-group iconpicker-container">
												<input name="category_icon" class="form-control icp icp-auto-duzenle iconpicker-element iconpicker-input" value="' . $category["category_icon"] . '" type="text">
												<span class="input-group-addon"></span>
											</div>
										</div>
										<div class="form-group">
											<label>ICON Rengi</label>
											<input name="category_icon_color" class="form-control" id="myPickerId" value="' . $category["category_icon_color"] . '" type="text">
                                            <script>
                                            var myPicker = new JSColor("#myPickerId");

											</script>
										</div>
										
										<div class="form-group text-right">
											<button type="submit" class="modal-button">Güncelle</button>
										</div>
									</form>';
							$response->order = $html;
							$response->title = $category_name[0]['name'];
						} else {
							$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
						}
					} else {
						$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
					}
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "get_ticket") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'support')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					$posts = [
						"id" => true
					];
					$error = false;
					foreach ($posts as $post => $required) {
						if ($required) {
							if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						} else {
							if (isset($_POST[$post])) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						}
					}
					if (!$error) {

						$ticket = $db->query("SELECT * FROM `tickets` INNER JOIN `users` ON users.user_id = tickets.user_id WHERE tickets.ticket_id = '$id'")->fetch(PDO::FETCH_ASSOC);

						if ($ticket) {

							switch ($ticket["ticket_status"]) {

								case '1':
									$ticket["ticket_status"] = "Açık";
									$ticketstatus = 1;
									break;

								case '2':
									$ticket["ticket_status"] = "Kilitli";
									$ticketstatus = 2;
									break;

								case '0':
									$ticket["ticket_status"] = "Kapalı";
									$ticketstatus = 0;
									break;
							}

							$messages = $db->query("SELECT * FROM ticket_messages WHERE ticket_id = '$id' ORDER BY message_id ASC")->fetchAll(PDO::FETCH_ASSOC);
							$update = $db->update('tickets')->where('ticket_id', $id)->set(array('ticket_read' => 1));
							$title = "Destek Talebi Görüntüle";
							$html = '<div class="panel-heading">
											<div class="input-group">
												<input type="text" class="form-control" value="[#' . $ticket["ticket_id"] . '] - ' . $ticket["ticket_title"] . '" readonly="">
												<div class="input-group-btn">
													<button class="btn btn-default" onclick="update_ticket(' . $id . ', 2)">Destek Talebini Kilitle</button>
													<button class="btn btn-primary" onclick="update_ticket(' . $id . ', 1)">Destek Talebini Kapat/Aç</button>
												</div>
											</div>
											<div class="row" style="margin-top:10px;">
												<div class="col-lg-4">
													<div class="input-group">
														<span class="input-group-addon"><b>Kullanıcı Adı</b></span>
														<input type="text" class="form-control" value="' . $ticket["user_username"] . '" readonly="">
													</div>
												</div>
												<div class="col-lg-4">
													<div class="input-group">
														<span class="input-group-addon"><b>Talep Tarihi</b></span>
														<input type="text" class="form-control" value="' . str_date($ticket["ticket_date"]) . '" readonly="">
													</div>
												</div>
												<div class="col-lg-4">
													<div class="input-group">
														<span class="input-group-addon"><b>Durum</b></span>
														<input type="text" class="form-control" value="' . $ticket["ticket_status"] . '" readonly="">
													</div>
												</div>
											</div>
										</div>
										<div id="chat-messages" class="panel-body">
											<div class="row">';
							foreach ($messages as $message) :
								if ($message["message_author"] == 1) :
									$html .= '<div class="col-xs-11">
													<p class="pull-right" style="width:100%;text-align:left;"><small>' . date("d.m.Y H:i:s", $message["message_time"]) . '</small></p>
													<div class="well well-sm chat-message pull-left" data-toggle="tooltip" data-placement="bottom" title="' . date("d.m.Y H:i:s", $message["message_time"]) . '">' . $message["message_text"] . '</div>
												</div>';
								else :
									$html .= '<div class="col-xs-11 col-xs-offset-1">

													<p class="pull-right" style="width:100%;text-align:right;"><small>' . date("d.m.Y H:i:s", $message["message_time"]) . '</small></p>
													<div class="well well-sm chat-message pull-right" data-toggle="tooltip" data-placement="bottom" title="' . date("d.m.Y H:i:s", $message["message_time"]) . '">' . $message["message_text"] . '</div>
												</div>';
								endif;
							endforeach;
							$html .= '</div>
										</div>

										<div class="panel-footer">';
							if ($ticketstatus == 2) :
								$html .= '<div class="alert alert-danger" role="alert">Bu destek talebi kilitlenmiş, artık cevaplanamaz.</div>';
							elseif ($ticketstatus == 1) :
								$html .= '<form id="admin_send_message" onsubmit="return false;">
												<input type="hidden" name="id" value="' . $id . '" />
												<div class="input-group">
													<input class="form-control" name="message" placeholder="Cevabınızı yazın..">
													<span class="input-group-btn">
														<button class="btn btn-warning"><i class="fa fa-send"></i></button>
													</span>
												</div>
											</form>';
							elseif ($ticketstatus == 0) :
								$html .= '<div class="alert alert-danger" role="alert">Bu destek talebi kapatılmış, işlem yapmak için talebi açınız.</div>
											</div>';
							endif;

							$response->order = $html;
						} else {

							$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
						}
					} else {

						$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
					}
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "get_alltickets") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				$error = false;

				if (!permission('access', 'support')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					if (!$error) {

						$tickets = $db->from('tickets')
							->join('users', 'users.user_id = tickets.user_id')
							->orderby('ticket_read', 'ASC')
							->orderby('ticket_id', 'DESC')
							->all();

						if ($tickets) {

							$html = '<ul class="list-group" style="overflow: hidden;overflow-y: scroll;height: 670px;margin: 0;">';
							foreach ($tickets as $ticket) :
								if ($ticket['ticket_status'] == 1) :
									$html .= '<button class="ticket-button" href="javascript:;" onclick="openticket(' . $ticket['ticket_id'] . ')">
										<li class="list-group-item" data-toggle="tooltip" data-placement="bottom" title="Oluşturulma Tarihi: ' . str_date($ticket["ticket_date"]) . '">';
									if ($ticket['ticket_status'] == 2) :
										$html .= '<i class="fa fa-lock text-danger" data-toggle="tooltip" data-placement="left" title="Kilitli"></i>';
									else :
										if ($ticket['ticket_read'] == 0) :
											$html .= '<i class="fa fa-times-circle text-danger" data-toggle="tooltip" data-placement="top" title="Okunmamış"></i>';
										else :
											$html .= '<i class="fa fa-check-circle text-success" data-toggle="tooltip" data-placement="top" title="Okunmuş"></i>';
										endif;
									endif;
									if ($ticket['ticket_read'] == 0) :
										$html .= '<b>#' . $ticket["ticket_id"] . ' - ' . $ticket["ticket_title"] . '</b>';
									else :
										$html .= '#' . $ticket["ticket_id"] . ' - ' . $ticket["ticket_title"] . '';
									endif;
									$html .= '</li>
									</button>';
								elseif ($ticket['ticket_status'] == 0) :
									$html .= '<button class="ticket-button" href="javascript:;" onclick="openticket(' . $ticket['ticket_id'] . ')">
										<li class="list-group-item" data-toggle="tooltip" data-placement="bottom" title="Oluşturulma Tarihi: ' . str_date($ticket["ticket_date"]) . '">';
									if ($ticket['ticket_status'] == 2) :
										$html .= '<i class="fa fa-lock text-danger" data-toggle="tooltip" data-placement="left" title="Kilitli"></i>';
									else :
										if ($ticket['ticket_read'] == 0) :
											$html .= '<i class="fa fa-times-circle text-danger" data-toggle="tooltip" data-placement="top" title="Okunmamış"></i>';
										else :
											$html .= '<i class="fa fa-check-circle text-success" data-toggle="tooltip" data-placement="top" title="Okunmuş"></i>';
										endif;
									endif;
									if ($ticket['ticket_read'] == 0) :
										$html .= '<b>#' . $ticket["ticket_id"] . ' - ' . $ticket["ticket_title"] . '</b>';
									else :
										$html .= '#' . $ticket["ticket_id"] . ' - ' . $ticket["ticket_title"] . '';
									endif;
									$html .= '</li>
									</button>';
								endif;
							endforeach;
							$html . '</ul>';

							$response->order = $html;
						} else {

							$html = '<div style="width:100%;padding-top:20px;" class="text-center"><b>Talep Bulunamadı</b></div>';
							$response->order = $html;
						}
					} else {

						$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
					}
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "update_duyuru") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'edit')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					$posts = [
						"id" => true,
						"duyuru_title" => true,
						"duyuru_icon" => true,
						"duyuru_icon_color" => true,
						"duyuru_daire_color" => true,
						"duyuru_content" => false
					];
					$error = false;
					foreach ($posts as $post => $required) {
						if ($required) {
							if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						} else {
							if (isset($_POST[$post])) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						}
					}
					if (!$error) {

						$query = $db->update('duyuru')->where('id', $id)
							->set(array(
								'duyuru_title' => $duyuru_title,
								'duyuru_icon' => $duyuru_icon,
								'duyuru_icon_color' => $duyuru_icon_color,
								'duyuru_daire_color' => $duyuru_daire_color,
								'duyuru_content' => $duyuru_content
							));

						if ($query) {
							$response->success = "Duyuru güncellendi.";
						} else {
							$response->error = "Sistem hatası oluştu.";
						}
					} else {
						$response->error = "{MESSAGE_WRONG_REQUEST}";
					}
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "update_blog") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'edit')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					$posts = [
						"id" => true,
						"blog_title" => true,
						"blog_url" => true,
						"blog_content" => false
					];
					$error = false;
					foreach ($posts as $post => $required) {
						if ($required) {
							if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						} else {
							if (isset($_POST[$post])) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						}
					}
					if (!$error) {

						$currentblogs = $db->from('blog')->where('blog_title', $blog_title)->first();

						if ($currentblogs) {

							$blog_url = permalink($blog_url);
							$blogs = $db->from('blog')->where('blog_url', $blog_url)->first();

							if ($blogs) {
								$response->error = "Blog URL zaten mevcut, lütfen blog başlığınızı yenileyiniz.";
							} else {

								$query = $db->update('blog')->where('id', $id)
									->set(array(
										'blog_title' => $blog_title,
										'blog_url' => $blog_url,
										'blog_content' => $blog_content,
										'blog_seotitle' => filter($_POST['blog_seotitle']),
										'blog_seodesc' => filter($_POST['blog_seodesc']),
										'blog_seokeyw' => filter($_POST['blog_seokeyw'])
									));

								if ($query) {
									$response->success = "Blog güncellendi.";
								} else {
									$response->error = "Sistem hatası oluştu.";
								}
							}
						} else {

							$blog_url = permalink($blog_title);
							$query = $db->update('blog')->where('id', $id)
								->set(array(
									'blog_title' => $blog_title,
									'blog_url' => $blog_url,
									'blog_content' => $blog_content,
									'blog_seotitle' => filter($_POST['blog_seotitle']),
									'blog_seodesc' => filter($_POST['blog_seodesc']),
									'blog_seokeyw' => filter($_POST['blog_seokeyw'])
								));

							if ($query) {
								$response->success = "Blog güncellendi.";
							} else {
								$response->error = "Sistem hatası oluştu.";
							}
						}
					} else {
						$response->error = "{MESSAGE_WRONG_REQUEST}";
					}
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "update_page") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'edit')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					$posts = [
						"id" => true,
						"page_title" => true,
						"page_content" => false
					];
					$error = false;
					foreach ($posts as $post => $required) {
						if ($required) {
							if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						} else {
							if (isset($_POST[$post])) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						}
					}
					if (!$error) {

						if ($_POST['page_url']) {
							$page_url = permalink($_POST['page_url']);
						} else {
							$page_url = "";
						}

						if (@!$_POST['page_visibility']) {
							$_POST['page_visibility'] = 1;
						}

						$query = $db->update('pages')->where('id', $id)
							->set(array(
								'page_visibility' => $_POST['page_visibility'],
								'page_title' => $page_title,
								'page_seo' => json_encode($_POST['seo']),
								'page_url' => $page_url,
								'page_content' => $page_content,
								'page_date' => date('Y-m-d h:m:s')
							));

						if ($query) {
							$response->success = "Sayfa güncellendi.";
						} else {
							$response->error = "Sistem hatası oluştu.";
						}
					} else {
						$response->error = "{MESSAGE_WRONG_REQUEST}";
					}
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "add_page") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'edit')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					$posts = [
						"page_title" => true,
						"page_content" => false
					];
					$error = false;
					foreach ($posts as $post => $required) {
						if ($required) {
							if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						} else {
							if (isset($_POST[$post])) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						}
					}
					if (!$error) {

						if ($_POST['page_url']) {
							$page_url = permalink($_POST['page_url']);
						} else {
							$page_url = permalink($_POST['page_title']);
						}

						$query = $db->insert('pages')
							->set(array(
								'page_visibility' => $_POST['page_visibility'],
								'page_title' => $page_title,
								'page_seo' => json_encode($_POST['seo']),
								'page_url' => $page_url,
								'page_content' => $page_content,
								'page_lock' => 0,
								'page_date' => date('Y-m-d h:m:s')
							));

						if ($query) {
							$response->success = "Sayfa oluşturuldu.";
						} else {
							$response->error = "Sistem hatası oluştu.";
						}
					} else {
						$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
					}
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "delete_order") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'delete')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					$posts = [
						"id" => true
					];
					$error = false;
					foreach ($posts as $post => $required) {
						if ($required) {
							if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						} else {
							if (isset($_POST[$post])) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						}
					}
					if (!$error) {
						$query = $db->prepare("DELETE FROM `orders` WHERE order_id = ?");
						$delete_order = $query->execute([$id]);
						if ($delete_order) {
							$response->reload = true;
						} else {
							$response->error = "Sistem hatası oluştu!";
						}
					} else {
						$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
					}
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "update_auto_status") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'edit')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					$posts = [
						"id" => true,
						"status" => true
					];
					$error = false;
					foreach ($posts as $post => $required) {
						if ($required) {
							if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						} else {
							if (isset($_POST[$post])) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						}
					}
					if (!$error) {
						$query = $db->prepare("UPDATE `auto_orders` SET auto_status = ? WHERE auto_id = ?");
						$update_order = $query->execute([$status, $id]);
						if ($update_order) {
							$response->reload = true;
						} else {
							$response->error = "Sistem hatası oluştu!";
						}
					} else {
						$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
					}
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "delete_auto") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'delete')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					$posts = [
						"id" => true
					];
					$error = false;
					foreach ($posts as $post => $required) {
						if ($required) {
							if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						} else {
							if (isset($_POST[$post])) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						}
					}
					if (!$error) {
						$query = $db->prepare("DELETE FROM `auto_orders` WHERE auto_id = ?");
						$delete_auto = $query->execute([$id]);
						if ($delete_auto) {
							$response->reload = true;
						} else {
							$response->error = "Sistem hatası oluştu!";
						}
					} else {
						$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
					}
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "delete_account") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'delete')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					$posts = [
						"id" => true
					];
					$error = false;
					foreach ($posts as $post => $required) {
						if ($required) {
							if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						} else {
							if (isset($_POST[$post])) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						}
					}
					if (!$error) {

						$query = $db->delete('bank_accounts')->where('id', $id)->done();
						if ($query) {
							$response->reload = true;
						} else {
							$response->error = "Sistem hatası oluştu!";
						}
					} else {
						$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
					}
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "delete_duyuru") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'delete')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					$posts = [
						"id" => true
					];
					$error = false;
					foreach ($posts as $post => $required) {
						if ($required) {
							if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						} else {
							if (isset($_POST[$post])) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						}
					}
					if (!$error) {

						$query = $db->delete('duyuru')->where('id', $id)->done();
						if ($query) {
							$response->reload = true;
						} else {
							$response->error = "Sistem hatası oluştu!";
						}
					} else {
						$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
					}
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "delete_blog") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'delete')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					$posts = [
						"id" => true
					];
					$error = false;
					foreach ($posts as $post => $required) {
						if ($required) {
							if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						} else {
							if (isset($_POST[$post])) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						}
					}
					if (!$error) {

						$query = $db->delete('blog')->where('id', $id)->done();
						if ($query) {
							$response->reload = true;
						} else {
							$response->error = "Sistem hatası oluştu!";
						}
					} else {
						$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
					}
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "delete_sayfa") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'delete')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					$posts = [
						"id" => true
					];
					$error = false;
					foreach ($posts as $post => $required) {
						if ($required) {
							if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						} else {
							if (isset($_POST[$post])) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						}
					}
					if (!$error) {

						$query = $db->delete('pages')->where('id', $id)->done();
						if ($query) {
							$response->reload = true;
						} else {
							$response->error = "Sistem hatası oluştu!";
						}
					} else {
						$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
					}
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "update_drip_status") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'edit')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					$posts = [
						"id" => true,
						"status" => true
					];
					$error = false;
					foreach ($posts as $post => $required) {
						if ($required) {
							if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						} else {
							if (isset($_POST[$post])) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						}
					}
					if (!$error) {
						$query = $db->prepare("SELECT * FROM `drip_orders` WHERE drip_id = ?");
						$query->execute([$id]);
						if ($query->rowCount()) {
							$drip = $query->fetch(PDO::FETCH_ASSOC);
							if ($status == 2) {
								$query = $db->prepare("SELECT * FROM `users` WHERE user_id = ?");
								$query->execute([$drip["user_id"]]);
								if ($query->rowCount() && $drip["drip_return"] == 0) {
									$u = $query->fetch(PDO::FETCH_ASSOC);
									$remains = $drip["drip_runs"] - $drip["drip_completed"];
									$remainAmount = ($drip["drip_amount"] / $drip["drip_runs"]) * $remains;
									$db->beginTransaction();
									$query = $db->prepare("UPDATE `drip_orders` SET drip_status = ?, drip_return = 1 WHERE drip_id = ?");
									$update_order = $query->execute([$status, $id]);
									$balance = $u["user_balance"] + $remainAmount;
									$query = $db->prepare("UPDATE `users` SET user_balance = ? WHERE user_id = ?");
									$update_user = $query->execute([$balance, $drip["user_id"]]);
									if ($update_order && $update_user) {
										$db->commit();
										$response->success = "Süreli sipariş güncellendi.";
									} else {
										$db->rollBack();
										$response->error = "Sistem hatası oluştu!";
									}
								} else {
									$query = $db->prepare("UPDATE `drip_orders` SET drip_status = ?, drip_return = 1 WHERE drip_id = ?");
									$update_order = $query->execute([$status, $id]);
									if ($update_order) {
										$response->success = "Süreli sipariş güncellendi.";
									} else {
										$response->error = "Sistem hatası oluştu!";
									}
								}
							} else {
								$query = $db->prepare("UPDATE `drip_orders` SET drip_status = ? WHERE drip_id = ?");
								$update_order = $query->execute([$status, $id]);
								if ($update_order) {
									$response->success = "Süreli sipariş güncellendi.";
								} else {
									$response->error = "Sistem hatası oluştu!";
								}
							}
						} else {
							$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
						}
					} else {
						$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
					}
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "delete_drip") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'delete')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					$posts = [
						"id" => true
					];
					$error = false;
					foreach ($posts as $post => $required) {
						if ($required) {
							if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						} else {
							if (isset($_POST[$post])) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						}
					}
					if (!$error) {
						$query = $db->prepare("DELETE FROM `drip_orders` WHERE drip_id = ?");
						$delete_drip = $query->execute([$id]);
						if ($delete_drip) {
							$response->reload = true;
						} else {
							$response->error = "Sistem hatası oluştu!";
						}
					} else {
						$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
					}
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "delete_child") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'root')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					$posts = [
						"id" => true
					];
					$error = false;
					foreach ($posts as $post => $required) {
						if ($required) {
							if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						} else {
							if (isset($_POST[$post])) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						}
					}
					if (!$error) {
						$query = $db->prepare("DELETE FROM `child_panels` WHERE id = ?");
						$delete_drip = $query->execute([$id]);
						if ($delete_drip) {
							$response->reload = true;
						} else {
							$response->error = "Sistem hatası oluştu!";
						}
					} else {
						$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
					}
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "delete_proxy") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'delete')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					$posts = [
						"id" => true
					];
					$error = false;
					foreach ($posts as $post => $required) {
						if ($required) {
							if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						} else {
							if (isset($_POST[$post])) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						}
					}
					if (!$error) {

						$query = $db->prepare("DELETE FROM `proxy` WHERE proxy_id = ?");
						$delete_drip = $query->execute([$id]);
						if ($delete_drip) {
							$response->reload = true;
						} else {
							$response->error = "Sistem hatası oluştu!";
						}
					} else {
						$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
					}
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "proxy_check") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'root')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					$posts = [
						"id" => true
					];
					$error = false;
					foreach ($posts as $post => $required) {
						if ($required) {
							if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						} else {
							if (isset($_POST[$post])) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						}
					}
					if (!$error) {

						$kontrol = ProxyKontrol($id);

						if ($kontrol) {

							$response->success = "Proxy sorunsuz bir şekilde çalışmakta.";
						} else {

							$response->error = "Proxy çalışmıyor, pasifleştirildi.";

							$update = $db->update('proxy')->where('proxy_id', $id)
								->set(array(
									'proxy_status' => 0
								));
						}
					} else {
						$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
					}
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "cancel_order") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'edit')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					$posts = [
						"id" => true
					];
					$error = false;
					foreach ($posts as $post => $required) {
						if ($required) {
							if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						} else {
							if (isset($_POST[$post])) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						}
					}
					if (!$error) {
						$order = $db->query("SELECT * FROM `orders` WHERE order_id = '$id'")->fetch(PDO::FETCH_ASSOC);
						if ($order) {
							$u = $db->query("SELECT * FROM `users` WHERE user_id = '$order[user_id]'")->fetch(PDO::FETCH_ASSOC);
							if ($u) {
								$db->beginTransaction();
								$query = $db->prepare("UPDATE `orders` SET order_status = ?, is_failed = 0, order_return = 1 WHERE order_id = ?");
								$cancel_order = $query->execute(['Canceled', $id]);
								$balance = $u["user_balance"] + $order["order_amount"];
								$query = $db->prepare("UPDATE `users` SET user_balance = ? WHERE user_id = ?");
								$update_user = $query->execute([$balance, $order["user_id"]]);
								if ($cancel_order && $update_user) {
									$db->commit();
									$response->reload = true;
								} else {
									$db->rollBack();
									$response->error = "Sistem hatası oluştu!";
								}
							} else {
								$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
							}
						} else {
							$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
						}
					} else {
						$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
					}
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "order_multiple_cancel") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'edit')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					@$id = $_POST['id'];

					if ($id) {

						foreach ($id as $row) {

							$order = $db->from('orders')->where('order_id', $row)->first();
							if ($order) {

								$user = $db->from('users')->where('user_id', $order['user_id'])->first();
								if ($user) {

									$cancel_order = $db->update('orders')->where('order_id', $row)
										->set(array(
											'order_status' => "Canceled",
											'is_failed' => 0,
											'order_return' => 1,
											'order_amount' => 0
										));

									$balance = $user['user_balance'] + $order['order_amount'];
									user_spent("cikar", $user['user_username'], $order['order_amount']);

									$update_user = $db->update('users')->where('user_id', $user['user_id'])
										->set(array(
											'user_balance' => $balance
										));

									$success = true;
								}
							} else {
								$success = false;
							}
						}

						if ($success) {
							$response->reload = true;
						} else {
							$response->error = "Sistem hatası oluştu!";
						}
					} else {
						$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
					}
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "service_multiple_on") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'edit')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					@$id = $_POST['id'];

					if ($id) {

						foreach ($id as $row) {

							$service = $db->from('services')->where('service_id', $row)->first();
							if ($service) {

								if ($service['service_status'] == 0) {

									$update = $db->update('services')->where('service_id', $row)
										->set(array(
											'service_status' => 1
										));

									$success = true;
								}
							} else {
								$success = false;
							}
						}

						if ($success) {
							$response->reload = true;
						} else {
							$response->error = "Sistem hatası oluştu!";
						}
					} else {
						$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
					}
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "service_multiple_off") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'edit')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					@$id = $_POST['id'];

					if ($id) {

						foreach ($id as $row) {

							$service = $db->from('services')->where('service_id', $row)->first();
							if ($service) {

								if ($service['service_status'] == 1) {

									$update = $db->update('services')->where('service_id', $row)
										->set(array(
											'service_status' => 0
										));

									$success = true;
								}
							} else {
								$success = false;
							}
						}

						if ($success) {
							$response->reload = true;
						} else {
							$response->error = "Sistem hatası oluştu!";
						}
					} else {
						$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
					}
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "service_multiple_delete") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'delete')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					@$id = $_POST['id'];

					if ($id) {

						foreach ($id as $row) {

							$service = $db->from('services')->where('service_id', $row)->first();
							if ($service) {

								$query = $db->delete('services')->where('service_id', $service['service_id'])->done();
								$success = true;
							} else {
								$success = false;
							}
						}

						if ($success) {
							$response->reload = true;
						} else {
							$response->error = "Sistem hatası oluştu!";
						}
					} else {
						$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
					}
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "automation_multiple_delete") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'delete')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					@$id = $_POST['id'];

					if ($id) {

						foreach ($id as $row) {

							$service = $db->from('auto_report')->where('report_id', $row)->first();
							if ($service) {

								$query = $db->delete('auto_report')->where('report_id', $service['report_id'])->done();
								$success = true;
							} else {
								$success = false;
							}
						}

						if ($success) {
							$response->reload = true;
						} else {
							$response->error = "Sistem hatası oluştu!";
						}
					} else {
						$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
					}
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "crons_multiple_delete") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'delete')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					@$id = $_POST['id'];

					if ($id) {

						foreach ($id as $row) {

							$crons = $db->from('crons_report')->where('crons_id', $row)->first();
							if ($crons) {

								$query = $db->delete('crons_report')->where('crons_id', $crons['crons_id'])->done();
								$success = true;
							} else {
								$success = false;
							}
						}

						if ($success) {
							$response->reload = true;
						} else {
							$response->error = "Sistem hatası oluştu!";
						}
					} else {
						$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
					}
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "provider_multiple_delete") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'delete')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					@$id = $_POST['id'];

					if ($id) {

						foreach ($id as $row) {

							$service = $db->from('api_report')->where('report_id', $row)->first();
							if ($service) {

								$query = $db->delete('api_report')->where('report_id', $service['report_id'])->done();
								$success = true;
							} else {
								$success = false;
							}
						}

						if ($success) {
							$response->reload = true;
						} else {
							$response->error = "Sistem hatası oluştu!";
						}
					} else {
						$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
					}
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "log_multiple_delete") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'delete')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					@$id = $_POST['id'];

					if ($id) {

						foreach ($id as $row) {

							$service = $db->from('user_logs')->where('log_id', $row)->first();
							if ($service) {

								$query = $db->delete('user_logs')->where('log_id', $service['log_id'])->done();
								$success = true;
							} else {
								$success = false;
							}
						}

						if ($success) {
							$response->reload = true;
						} else {
							$response->error = "Sistem hatası oluştu!";
						}
					} else {
						$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
					}
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "send_order") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'edit')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					$posts = [
						"id" => true
					];
					$error = false;
					foreach ($posts as $post => $required) {
						if ($required) {
							if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						} else {
							if (isset($_POST[$post])) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						}
					}
					if (!$error) {

						$order = $db->from('orders')->where('order_id', $id)->first();

						if ($order) {

							$service = $db->from('services')->where('service_id', $order['service_id'])->first();

							if ($service) {

								$api = $db->from('apis')->where('api_id', $service['api_id'])->first();

								if ($api) {

									$order = send_order_default($api["api_url"], $api["api_key"], $service["api_service"], $order["order_link"], $order["order_quantity"], true);
									$orderdetail = json_encode($order, true);

									if ($order->error) {

										$response->error = $order->error;
									} else {

										$update_order = $db->update('orders')->where('order_id', $id)
											->set(array(
												'api_id' => $api['api_id'],
												'api_order_id' => $order->order,
												'is_failed' => 0,
												'order_detail' => $orderdetail
											));

										if ($update_order) {

											$response->reload = true;
										} else {

											$response->error = "Sistem hatası oluştu!";
										}
									}
								} else {
									$response->error = "API bulunamadı.";
								}
							} else {
								$response->error = "Servis bulunamadı.";
							}
						} else {
							$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
						}
					} else {
						$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
					}
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "update_method") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'edit')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					$posts = [
						"id" => true
					];
					$error = false;
					foreach ($posts as $post => $required) {
						if ($required) {
							if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						} else {
							if (isset($_POST[$post])) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						}
					}
					if (!$error) {
						$details = json_encode($_POST["data"]);
						$query = $db->prepare("UPDATE `payment_methods` SET method_details = ? WHERE method_id = ?");
						$update_method = $query->execute([$details, $id]);
						if ($update_method) {
							$response->success = "Yöntem güncellendi";
						} else {
							$response->error = "Sistem hatası oluştu!";
						}
					} else {
						$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
					}
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "update_file") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'edit')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					$posts = [
						"file" => true
					];
					$error = false;
					foreach ($posts as $post => $required) {
						if ($required) {
							if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						} else {
							if (isset($_POST[$post])) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						}
					}
					if (!$error) {

						$filedir = dir . "/mp-content/view/" . $_POST['theme'] . "/" . $file . ".php";

						if (file_exists($filedir)) {
							if (isset($_POST["content"])) {
								$content = filter($_POST["content"], false);
								if (file_put_contents($filedir, $content)) {
									$response->success = "Dosya kaydedildi";
								} else {
									$response->error = "Sistem hatası oluştu!";
								}
							} else {
								$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
							}
						} else {
							$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
						}
					} else {
						$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
					}
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "update_content") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'edit')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					$posts = [
						"id" => true
					];
					$error = false;
					foreach ($posts as $post => $required) {
						if ($required) {
							if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						} else {
							if (isset($_POST[$post])) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						}
					}
					if (!$error) {
						if ($id == "faq") {
							$content = [];
							foreach ($_POST["content"] as $key => $val) {
								$key = filter($key);
								$val = filter($val, false);
								if ($val != null) {
									$content[] = [
										"lang" => intval($key),
										"content" => $val
									];
								}
							}
							$content = json_encode($content);
							$query = $db->prepare("UPDATE `contents` SET faq_content = ? WHERE id = 1");
							$update_content = $query->execute([$content]);
							if ($update_content) {
								$response->success = "İçerik Güncellendi";
							} else {
								$response->error = "Sistem hatası oluştu.";
							}
						} elseif ($id == "terms") {
							$content = [];
							foreach ($_POST["content"] as $key => $val) {
								$key = filter($key);
								$val = filter($val, false);
								if ($val != null) {
									$content[] = [
										"lang" => intval($key),
										"content" => $val
									];
								}
							}
							$content = json_encode($content);
							$query = $db->prepare("UPDATE `contents` SET terms_content = ? WHERE id = 1");
							$update_content = $query->execute([$content]);
							if ($update_content) {
								$response->success = "İçerik Güncellendi";
							} else {
								$response->error = "Sistem hatası oluştu.";
							}
						} else {
							$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
						}
					} else {
						$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
					}
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "get_report") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {
				$orders = $db->query("SELECT * FROM `orders` WHERE order_status = 'Completed' OR order_status = 'Partial' ORDER BY order_id DESC")->fetchAll(PDO::FETCH_ASSOC);
				if ($orders) {
					$tempOrders = [];
					$sums = [];
					$sums[] = ["Toplamlar"];
					foreach ($orders as $order) {
						$amount = $order["order_amount"];
						$api_amount = ($order["api_order_amount"] != null) ? $order["api_order_amount"] : 0;
						$api_currency = ($order["api_order_currency"] != null) ? $order["api_order_currency"] : "TRY";
						$date = date("d.m.Y H:i:s", $order["order_date"]);
						$order = [
							"date" => $date,
							"currency" => CURRENCY_CODE,
							"amount" => $amount,
							"api_currency" => $api_currency,
							"api_amount" => $api_amount,
							"net" => (CURRENCY_CODE == $api_currency) ? $amount - $api_amount : "Para birimi uyuşmuyor!"
						];
						if (array_key_exists($api_currency, $sums)) {
							$sums[$api_currency][2] += $amount;
							$sums[$api_currency][4] += $api_amount;
							if (CURRENCY_CODE == $api_currency) {
								$sums[$api_currency][5] += ($amount - $api_amount);
							}
						} else {
							$sums[$api_currency] = [
								"",
								CURRENCY_CODE,
								$amount,
								$api_currency,
								$api_amount,
								(CURRENCY_CODE == $api_currency) ? ($amount - $api_amount) : "Para birimi uyuşmuyor!"
							];
						}
						$tempOrders[] = $order;
					}
					$orders = array_merge([["Tarih", "Para Birimi", "Tutar", "API Para Birimi", "API Tutar", "Net Kazanç"]], $tempOrders);
					$orders = array_merge($orders, $sums);
					$filename = "report-" . time() . ".csv";
					$delimiter = ";";
					$f = fopen('php://memory', 'w');
					foreach ($orders as $line) {
						fputcsv($f, $line, $delimiter);
					}
					fseek($f, 0);
					header('Content-Type: application/csv; charset=utf-8');
					header('Content-Disposition: attachment; filename="' . $filename . '";');
					fpassthru($f);
					exit;
				} else {
					$response->error = "Sipariş yok.";
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "admin_add_funds") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'edit')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					$posts = [
						"username" => true,
						"amount" => true
					];
					$error = false;
					foreach ($posts as $post => $required) {
						if ($required) {
							if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						} else {
							if (isset($_POST[$post])) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						}
					}
					if (!$error) {
						$query = $db->prepare("SELECT * FROM `users` WHERE user_username = ?");
						$query->execute([$username]);
						if ($query->rowCount()) {
							$u = $query->fetch(PDO::FETCH_ASSOC);
							$query = $db->prepare("UPDATE `users` SET user_balance = ? WHERE user_id = ?");
							$update_user = $query->execute([$u["user_balance"] + $amount, $u["user_id"]]);
							if ($update_user) {
								$response->success = "Üyeye bakiye eklendi";
							} else {
								$response->error = "Sistem hatası oluştu!";
							}
						} else {
							$response->error = "Üye bulunamadı.";
						}
					} else {
						$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
					}
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "update_recaptcha") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'edit')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					$posts = [
						"site_key" => true,
						"secret_key" => true,
						"login_page" => true,
						"register_page" => true
					];
					$error = false;
					foreach ($_POST as $key => $value) {
						$$key = $value;
					}
					if (!$error) {
						$query = $db->prepare("UPDATE recaptcha_settings SET site_key = ?, secret_key = ?, login_page = ?, register_page = ? WHERE id = 1");
						$update_recaptcha = $query->execute([$site_key, $secret_key, $login_page, $register_page]);
						if ($update_recaptcha) {
							$response->success = "Ayarlar güncellendi";
						} else {
							$response->error = "Sistem hatası oluştu!";
						}
					} else {
						$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
					}
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "update_discord") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'edit')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					$posts = [
						"discord_apiNotify_url" => true,
						"discord_notify_url" => true
					];
					$error = false;
					foreach ($_POST as $key => $value) {
						$$key = $value;
					}
					if (!$error) {
						$query = $db->prepare("UPDATE settings SET discord_apiNotify_url = ?, discord_notify_url = ? WHERE id = 1");
						$update_recaptcha = $query->execute([$discord_apiNotify_url, $discord_notify_url]);
						if ($update_recaptcha) {
							$response->success = "Modül Ayarları Güncellendi";
						} else {
							$response->error = "Sistem hatası oluştu!";
						}
					} else {
						$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
					}
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "update_script") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'root')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					$downloadFile = file_download($licenseUpdates['updates'][0]['url']);

					if ($downloadFile == "OK") {

						$zip = new ZipArchive;
						$res = $zip->open(dir . '/update.zip');

						if ($res === TRUE) {

							$zip->extractTo(dir);
							$zip->close();
							$response->success = "Güncelleme başarıyla tamamlandı.";
						} else {
							$response->error = "Güncelleme dosyası çıkartılamadı, lütfen daha sonra tekrar deneyiniz.";
						}
					} else {
						$response->error = "Güncelleme dosyası indirilemedi, daha sonra tekrar deneyiniz.";
					}
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "theme_change") {
		if (login_control()) {
			if ($user["user_authority"] == 2) {

				if (!permission('access', 'edit')) {

					$response->error = "Bu işlemi gerçekleştirmek için izniniz bulunmuyor.";
				} else {

					$posts = [
						"id" => false
					];
					$error = false;
					foreach ($posts as $post => $required) {
						if ($required) {
							if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						} else {
							if (isset($_POST[$post])) {
								$$post = filter($_POST[$post]);
							} else {
								$error = true;
								break;
							}
						}
					}
					if (!$error) {
						$query = $db->prepare("UPDATE settings SET site_theme = ? WHERE id = 1");
						$update_recaptcha = $query->execute([$id]);
						if ($update_recaptcha) {
							$response->success = "Tema güncellendi";
						} else {
							$response->error = "Sistem hatası oluştu!";
						}
					} else {
						$response->error = "{MESSAGE_NULL_OR_WRONG_VALUE}";
					}
				}
			} else {
				$response->error = "{MESSAGE_WRONG_REQUEST}";
			}
		} else {
			$response->error = "{MESSAGE_WRONG_REQUEST}";
		}
	} elseif ($action == "api_request") {
		$posts = [
			"key" => true,
			"action" => true
		];

		if ($_GET['key'] && $_GET['action']) {
			$response->error = "Missing parameters.";
			$error = true;
		} else {
			$error = false;
		}

		foreach ($posts as $post => $required) {
			if ($required) {
				if (isset($_POST[$post]) && filter($_POST[$post]) != null) {
					$$post = filter($_POST[$post]);
				} else {
					$error = true;
					break;
				}
			} else {
				if (isset($_POST[$post])) {
					$$post = filter($_POST[$post]);
				} else {
					$error = true;
					break;
				}
			}
		}
		if (API_STATUS == 1) {

			if (!$error) {

				$user = $db->from('users')->where('user_key', $key)->first();

				if ($user) {

					if ($action == "services") {

						$services = $db->from('services')
							->join('categories', 'categories.category_id = services.category_id')
							->where('services.service_status', 1)
							->all();

						$servicesTempArray = [];
						foreach ($services as $service) {
							$category_name = json_decode($service["category_name"], true);
							foreach ($category_name as $details) {
								if ($details["lang"] == 1) {
									$service["category_name"] = $details["name"];
								}
								if ($details["lang"] == $lang) {
									$service["category_name"] = $details["name"];
									break;
								}
							}
							$service_name = json_decode($service["service_name"], true);
							foreach ($service_name as $details) {
								if ($details["lang"] == 1) {
									$service["service_name"] = $details["name"];
								}
								if ($details["lang"] == $lang) {
									$service["service_name"] = $details["name"];
									break;
								}
							}
							$type = "Default";
							if ($service["service_package"]) {
								$type = "Package";
							} elseif ($service["service_comment"]) {
								$type = "Custom Comments";
							} elseif ($service["service_auto"]) {
								$type = "Subscriptions";
							}
							$servicesTempArrayTwo = [];
							$servicesTempArrayTwo["service"] = $service["service_id"];
							$servicesTempArrayTwo["name"] = $service["service_name"];
							$servicesTempArrayTwo["type"] = $type;
							$servicesTempArrayTwo["category"] = $service["category_name"];
							$servicesTempArrayTwo["rate"] = $charge = offer($service, $user["user_id"]);
							$servicesTempArrayTwo["min"] = $service["service_min"];
							$servicesTempArrayTwo["max"] = $service["service_max"];
							$services2[] = $servicesTempArrayTwo;
						}
						$response = $services2;
					} elseif ($action == "add") {

						if (post("service") && post("service") != null) {

							$service = post("service");
							$query = $db->prepare("SELECT * FROM `services` WHERE service_id = ? AND service_status = 1");
							$query->execute([$service]);

							if ($query->rowCount()) {

								$service = $query->fetch(PDO::FETCH_ASSOC);

								if (post("username") && post("username") != null) {

									$username = post("username");

									if (post("quantity") && post("quantity") != null) {

										$limit = null;
										$expiry = null;

										if (post("limit") && post("limit") != null) {
											$limit = post("limit");
										}
										if (post("expiry") && post("expiry") != null) {
											$expiry = post("expiry");
										}

										if (is_numeric($quantity) && $quantity >= $service["service_min"] && $quantity <= $service["service_max"]) {
											if ($expiry != null) {
												$expiry = strtotime($expiry);
											}
											if (!is_numeric($limit) && $limit < 1) {
												$limit = null;
											}
											$query = $db->prepare("INSERT INTO `auto_orders` SET user_id = ?, service_id = ?, last_post = ?, auto_date = ?, auto_link = ?, auto_quantity = ?, auto_limit = ?, auto_expiration = ?");
											$insert_auto = $query->execute([$user["user_id"], $service["service_id"], null, time(), $username, $quantity, ($limit == null) ? null : $limit, ($expiry == null) ? null : $expiry]);
											if ($insert_auto) {
												$response->order = $db->lastInsertId();
											} else {
												$response->error = "Due to a technical glitch, you can not order now";
											}
										} else {
											$response->error = "Order quantity can be minimum $service[service_min], maximum $service[service_max]";
										}
									}
								} elseif (post("link") && post("link") != null) {
									$link = post("link");
									$charge = offer($service, $user["user_id"]);
									if (post("comments") && post("comments") != null) {
										$comments = post("comments");
										$count = count(explode("\n", $comments));
										$quantity = $count;
										if ($quantity >= $service["service_min"] && $quantity <= $service["service_max"]) {
											$amount = (($charge / 1000) * $quantity);
											if ($user["user_balance"] >= $amount) {
												$order = add_order($service, $user["user_id"], $link, $quantity, $amount, $comments);
												if ($order) {
													$new_balance = $user["user_balance"] - $amount;
													$query = $db->prepare("UPDATE `users` SET user_balance = ? WHERE user_id = ?");
													$update_user = $query->execute([$new_balance, $user["user_id"]]);
													$response->order = $order;
												} else {
													$response->error = "Due to a technical glitch, you can not order now";
												}
											} else {
												$response->error = "Not enough funds on balance";
											}
										} else {
											$response->error = "Order quantity can be minimum $service[service_min], maximum $service[service_max]";
										}
									} else {
										if ($service["service_package"] == 1) {
											$amount = $charge;
											if ($user["user_balance"] >= $amount) {
												$order = add_order($service, $user["user_id"], $link, 1, $amount);
												if ($order) {
													$new_balance = $user["user_balance"] - $amount;
													$query = $db->prepare("UPDATE `users` SET user_balance = ? WHERE user_id = ?");
													$update_user = $query->execute([$new_balance, $user["user_id"]]);
													$response->order = $order;
												} else {
													$response->error = "Due to a technical glitch, you can not order now";
												}
											} else {
												$response->error = "Not enough funds on balance";
											}
										} else {
											$quantity = post("quantity");
											if ($service["service_package"] == 1) {
												$quantity = 1;
											}
											if (is_numeric($quantity) && $quantity >= $service["service_min"] && $quantity <= $service["service_max"]) {
												$runs = null;
												$interval = null;
												if (post("runs") && post("runs") != null && is_numeric(post("runs")) && post("runs") > 0) {
													$runs = post("runs");
												}
												if (post("interval") && post("interval") != null && is_numeric(post("interval")) && post("interval") % 5 == 0 && post("interval") >= 0 && post("interval") <= 30) {
													$interval = post("interval");
												}
												if ($runs != null && $interval != null) {
													$amount = (($charge / 1000) * $quantity) * $runs;
													if ($service["service_package"] == 1) {
														$amount = $charge * $runs;
														$quantity = 1;
													}
													if ($user["user_balance"] >= $amount) {
														$order = add_order($service, $user["user_id"], $link, $quantity, $amount, null, $runs, $interval);
														if ($order) {
															$new_balance = $user["user_balance"] - $amount;
															$query = $db->prepare("UPDATE `users` SET user_balance = ? WHERE user_id = ?");
															$update_user = $query->execute([$new_balance, $user["user_id"]]);
															$response->order = $order;
														} else {
															$response->error = "Due to a technical glitch, you can not order now";
														}
													} else {
														$response->error = "Not enough funds on balance";
													}
												} else {
													$amount = (($charge / 1000) * $quantity);
													if ($service["service_package"] == 1) {
														$amount = $charge;
														$quantity = 1;
													}
													if ($user["user_balance"] >= $amount) {
														$order = add_order($service, $user["user_id"], $link, $quantity, $amount);
														if ($order) {
															$new_balance = $user["user_balance"] - $amount;
															$query = $db->prepare("UPDATE `users` SET user_balance = ? WHERE user_id = ?");
															$update_user = $query->execute([$new_balance, $user["user_id"]]);
															$response->order = $order;
														} else {
															$response->error = "Due to a technical glitch, you can not order now";
														}
													} else {
														$response->error = "Not enough funds on balance";
													}
												}
											} else {
												$response->error = "Order quantity can be minimum $service[service_min], maximum $service[service_max]";
											}
										}
									}
								} else {
									$response->error = "Bad link";
								}
							} else {
								$response->error = "Incorrect service ID";
							}
						} else {
							$response->error = "Incorrect service ID";
						}
					} elseif ($action == "status") {
						$id = null;
						if (isset($_POST["order"]) && filter($_POST["order"]) != null) {
							$id = filter($_POST["order"]);
						} elseif (isset($_POST["orders"]) && filter($_POST["orders"]) != null) {
							$orders = filter($_POST["orders"]);
							$ids = explode(",", $orders);
							$id2 = [];
							foreach ($ids as $id) {
								$id2[] = filter($id);
							}
							$id = $id2;
						}
						if ($id) {
							if (is_array($id)) {
								$ordersTempArray = [];
								foreach ($id as $i) {
									$query = $db->prepare("SELECT * FROM `orders` WHERE order_id = ? AND user_id = ?");
									$query->execute([$i, $user["user_id"]]);
									if ($query->rowCount()) {
										$order = $query->fetch(PDO::FETCH_ASSOC);
										$ordersTempArray[$i]["charge"] = $order["order_amount"];
										$ordersTempArray[$i]["start_count"] = $order["order_start_count"];
										$ordersTempArray[$i]["status"] = $order["order_status"];
										$ordersTempArray[$i]["remains"] = $order["order_remains"];
										$ordersTempArray[$i]["currency"] = CURRENCY_CODE;
									} else {
										$ordersTempArray["$i"]["error"] = "Incorrect order ID";
									}
								}
								$response = $ordersTempArray;
							} else {
								$orderTempArray = [];
								$query = $db->prepare("SELECT * FROM `orders` WHERE order_id = ? AND user_id = ?");
								$query->execute([$id, $user["user_id"]]);
								if ($query->rowCount()) {
									$order = $query->fetch(PDO::FETCH_ASSOC);
									$orderTempArray["charge"] = $order["order_amount"];
									$orderTempArray["start_count"] = $order["order_start_count"];
									$orderTempArray["status"] = $order["order_status"];
									$orderTempArray["remains"] = $order["order_remains"];
									$orderTempArray["currency"] = CURRENCY_CODE;
								} else {
									$orderTempArray["error"] = "Incorrect order ID";
								}
								$response = $orderTempArray;
							}
						}
					} elseif ($action == "balance") {
						$balance = [];
						$balance["balance"] = $user["user_balance"];
						$balance["currency"] = CURRENCY_CODE;
						$response = $balance;
					} else {
						$response->error = "Incorrect request";
					}
				} else {
					$response->error = "Incorrect API key!";
				}
			} else {
				$response->error = "Missing parameters.";
			}
		} else {
			$response->error = "API System Disabled";
		}
	} else {
		$response->error = "{MESSAGE_WRONG_REQUEST}";
	}
} else {
	$response->error = "{MESSAGE_WRONG_REQUEST}";
}


if(json_encode($response) != "{}"){
	echo replace(json_encode($response));
}


