<?php

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

		if(!permission('access', 'drips')){
	        require admin_view("unauthorized");
	        exit();
	    }

	    if(route(2)){

	    	$drips = $db->from('drip_orders')
	    	->join('services', 'services.service_id = drip_orders.service_id')
	    	->leftjoin('users', 'users.user_id = drip_orders.user_id')
	    	->orderby('drip_id', 'DESC')
	    	->where('drip_status', route(2))
	    	->all();
	    	
			$tempDrips = [];
			foreach($drips as $drip) {
				if($drip["service_name"] != null) {
					$service_name = json_decode($drip["service_name"], true);
					$name = null;
					foreach($service_name as $details) {
						if($details["lang"] == 1) {
							$name = $details["name"];
						}
					}
					$drip["service_name"] = $name;
				}
				$tempDrips[] = $drip;
			}
			$drips = $tempDrips;
			$title = "Süreli Siparişler";
			$page_title = "Süreli Siparişler";

	    }else{

	    	$drips = $db->from('drip_orders')
	    	->join('services', 'services.service_id = drip_orders.service_id')
	    	->leftjoin('users', 'users.user_id = drip_orders.user_id')
	    	->orderby('drip_id', 'DESC')
	    	->all();

			$tempDrips = [];
			foreach($drips as $drip) {
				if($drip["service_name"] != null) {
					$service_name = json_decode($drip["service_name"], true);
					$name = null;
					foreach($service_name as $details) {
						if($details["lang"] == 1) {
							$name = $details["name"];
						}
					}
					$drip["service_name"] = $name;
				}
				$tempDrips[] = $drip;
			}
			$drips = $tempDrips;
			$title = "Süreli Siparişler";
			$page_title = "Süreli Siparişler";

	    }

		require admin_view('drips');

	}else{

		require controller("404");

	}

}else{

	require controller("404");
	
}