<?php

	$extra = null;

	if(login_control()) {

		$title = "{AUTO_PAGE_TITLE}";

		$categories = $db->query("SELECT * FROM `categories` INNER JOIN `services` ON services.category_id = categories.category_id WHERE services.service_auto = 1 AND services.service_comment = 0 GROUP BY services.category_id")->fetchAll(PDO::FETCH_ASSOC);

		$categories_text = "";

		foreach($categories as $category) {

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

			$default_lang = "";

			$control = false;

			foreach($category_name as $details) {

				if($details["lang"] == 1) {

					$default_lang = $details["name"];

				}

				if($details["lang"] == $lang) {

					$categories_text .= '<option value="'. $category["category_id"] .'">'. $details["name"] .'</option>';

					$control = true;

					break;

				}

			}

			if(!$control) {

				$categories_text .= '<option value="'. $category["category_id"] .'">'. $default_lang .'</option>';

			}

		}



		$integration = "";

		foreach($plugins as $plugin){



			if ($plugin['app_id'] !== 1 && $plugin['app_id'] !== 2 && $plugin['app_id'] !== 3 && $plugin['app_id'] !== 4 && $plugin['app_id'] !== 5) {



				@$data = json_decode($plugin['app_data'], true);



				if(@$data['visibility'] == 0){ // Tüm Sayfalar

					@$integration .= $data['code'];

				}elseif($data['visibility'] == 1){ // Giriş Yapanlar

					@$integration .= $data['code'];

				}



			}



		}



		require view("auto");



		$extra = [

			"{INTEGRATIONS}" => $integration,

			"{AUTO_FORM_CATEGORIES}" => $categories_text

		];

	} else {



		require controller("404");



	}

	

	$output = ob_get_clean();

	echo replace($output, $extra);