<?php

	if(login_control()) {

		$title = "{DRIPS_PAGE_TITLE}";

		$query = $db->prepare("SELECT * FROM `drip_orders` INNER JOIN `services` ON services.service_id = drip_orders.service_id WHERE drip_orders.user_id = ? ORDER BY drip_id DESC");

		$query->execute([session("user_id")]);

		$drips = $query->fetchAll(PDO::FETCH_ASSOC);

		$drips_text = "";

		foreach($drips as $drip) {

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

			foreach($service_name as $details) {

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

					$name = $details["name"];

				}

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

					$name = $details["name"];

					break;

				}

			}

			$status = '<span class="badge badge-success">{DRIP_STATUS_COMPLETED}</span>';

			if($drip["drip_status"] == 1) {

				$status = '<span class="badge badge-warning">{DRIP_STATUS_PROCESSING}</span>';

			} elseif($drip["drip_status"] == 2) {

				$status = '<span class="badge badge-danger">{DRIP_STATUS_CANCELED}</span>';

			}

			$drips_text .= "<tr><td>$drip[drip_id]</td><td>$name</td><td>$drip[drip_link]</td><td>{CURRENCY_SYMBOL}$drip[drip_amount]</td><td>$drip[drip_quantity]</td><td>$drip[drip_completed]/$drip[drip_runs]</td><td>$drip[drip_interval]</td><td>".date("d.m.y H:i:s", $drip["drip_last_action"])."</td><td>$status</td></tr>";

		}

		$drips_text = replace($drips_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){

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

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

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

				}



			}



		}



		require view("drips");

		$output = ob_get_clean();

		$extra = [

			"{INTEGRATIONS}" => $integration,

			"{DRIPS_LIST}" => $drips_text

		];

		echo replace($output, $extra);

	} else {

		require controller("404");

	}