<?php



	if($settings['service_list'] == "private"){

		if(!login_control()) {

			header('Location:'.site());

			exit();

		}

	}



	$title = "{SERVICES_PAGE_TITLE}";

	$page_content = $db->from('pages')->where('id', 1)->first();
	$seo = json_decode($page_content['page_seo'], true);

		$meta = [
			"title" => $seo['title'],
			"desc" 	=> $seo['desc'],
			"keyw" 	=> $seo['keyw']
		];


	$categories = $db->query("SELECT * FROM `categories` ORDER BY category_number ASC")->fetchAll(PDO::FETCH_ASSOC);

	$services_text = "";

	foreach($categories as $category) {



		$query = $db->from('services')

		->where('category_id', $category['category_id'])

		->where('service_status', 1)

		->orderby('service_number', 'ASC')

		->all();



		if($query) {

			$category_icon = $category["category_icon"];
			if(strlen($category_icon) > 0){
				$category_icon = '<i style="color:'.$category['category_icon_color'].'" class="'.$category_icon.'"></i> ';
			}
			$category_name = json_decode($category["category_name"], true);

			foreach($category_name as $details) {

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

					$category_name = $details["name"];

				}

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

					$category_name = $details["name"];

					break;

				}

			}

			$services_text .= '<tr class="text-center"><td id="tableTitle" colspan="7" style="background:#354052;font-weight:bold;color:#fff"> '.$category_icon.' '.$category_name.'</td></tr>';

			$services = $query;

			foreach($services as $service) {

				$service_name = json_decode($service["service_name"], true);

				foreach($service_name as $details) {

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

						$service_name = $details["name"];

					}

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

						$service_name = $details["name"];

						break;

					}

				}

				$service_desc = json_decode($service["service_desc"], true);

				foreach($service_desc as $details) {

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

						$service_desc = $details["name"];

					}

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

						$service_desc = $details["name"];

						break;

					}

				}

				$charge = offer($service);

				$services_text .= "

				<tr>

					<td class='text-center'>$service[service_id]</td>

					<td style='width:35%;'>$service_name</td>

					<td>{CURRENCY_SYMBOL}$charge</td>

					<td class='text-center' class='text-center'>$service[service_min]</td>

					<td class='text-center'>$service[service_max]</td>";

					if($settings['service_speed'] == 1):

					$services_text.="<td class='text-center'>".getservicetime($service['service_id'])."</td>";

					endif;

					$services_text.="<td class='text-center'><button style='background: #d4d4d4;border-color: #9a9a9a;' class='btn btn-primary btn-xs' data-toggle='collapse' id='desc_$service[service_id]' onclick='openDesc($service[service_id])' data-desc='".htmlspecialchars_decode($service_desc)."'>&#128065;</button></td>

				</tr>";

			}
			 /*
			 
			 
			 ^^^^^ Normal
			 
			 
			 
			 
			 
			 
			 
			 
			 */
			
			$services_text2 .= '<div class="text-center wellmo"><div id="tableTitle" colspan="7" style="background:#354052;font-weight:bold;color:#fff;padding:5px 3px;border-radius:4px;margin-bottom:4px;">'.$category_icon.' '.$category_name.'</div></div>';

			$services = $query;

			foreach($services as $service) {

				$service_name = json_decode($service["service_name"], true);

				foreach($service_name as $details) {

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

						$service_name = $details["name"];

					}

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

						$service_name = $details["name"];

						break;

					}

				}

				$service_desc = json_decode($service["service_desc"], true);

				foreach($service_desc as $details) {

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

						$service_desc = $details["name"];

					}

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

						$service_desc = $details["name"];

						break;

					}

				}

				$charge = offer($service);

				$services_text2 .= "

				<div class='well mo'>

					<div>ID: <span>$service[service_id]</span></div>

					<div>Servis: <span>$service_name</span></div>

					<div>Ücret: <span>".CURRENCY_SYMBOL.$charge."</span></div>

					<div>Minimum: <span>$service[service_min]</span></div>

					<div>Maksimum: <span>$service[service_max]</span></div>";

					if($settings['service_speed'] == 1):

					$services_text2.="<div>Ortalama Süre: <span>".getservicetime($service['service_id'])."</span></div>";

					endif;

					$services_text2.="<div>Açıklama: <span><button style='background: #d4d4d4;border-color: #9a9a9a;' class='btn btn-primary btn-xs' data-toggle='collapse' id='desc_$service[service_id]' onclick='openDesc($service[service_id])' data-desc='".htmlspecialchars_decode($service_desc)."'>&#128065;</button></span></div>

				</div>";

			}

		}

	}

	$services_text = replace($services_text);



	$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'];

						}elseif(@$data['visibility'] == 2){

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

						}



					}



				}



	require view("services");

	$output = ob_get_clean();

	$extra = [

		"{INTEGRATIONS}" => $integration,

		"{SERVICES_LIST}" => $services_text,
		
		"{SERVICES_LIST2}" => $services_text2,

	];

	echo replace($output, $extra);