<?php
	$table = "pay_methods";

	$transfer_system = [
		"payeer" => [
			"payeer" => [
				"settings" => true,	//показывать настройки или нет
				"name" => "Payeer",	//название платежной системы
				"title" => "Payeer",
				"invest" => true,	//можно ли принимать платежи
				"payment" => true, 	//можно ли делать выплаты
			],
			"paykassa" => [
				"settings" => false,
				"name" => "PayKassa",
				"title" => "PayKassa",
				"invest" => true,
				"payment" => true,
			],
		],

		"yandexmoney" => [
			"yandexmoney" => [
				"settings" => true,
				"name" => "YandexMoney",
				"title" => "YandexMoney",
				"invest" => true,
				"payment" => true,
			],
			"payeer" => [
				"settings" => false,
				"name" => "Payeer",
				"title" => "Payeer",
				"invest" => false,
				"payment" => true,
			],
            "freekassa" => [
                "settings" => false,
                "name" => "freekassa",
                "title" => "freekassa",
                "invest" => true,
                "payment" => true,
            ],
            "casepay" => [
                "settings" => false,
                "name" => "Casepay",
                "title" => "Casepay",
                "invest" => true,
                "payment" => true,
            ],
		],

		"qiwi" => [
			"qiwi" => [
				"settings" => true,
				"name" => "Qiwi",
				"title" => "ручной",
				"invest" => true,
				"payment" => true,
			],
			"payeer" => [
				"settings" => false,
				"name" => "Payeer",
				"title" => "Payeer",
				"invest" => false,
				"payment" => true,
			],
			"hyiponline24" => [
				"settings" => true,
				"name" => "HyipOnline24",
				"title" => "HyipOnline24",
				"invest" => true,
				"payment" => true,
			],
            "freekassa" => [
                "settings" => false,
                "name" => "freekassa",
                "title" => "freekassa",
                "invest" => true,
                "payment" => true,
            ],
            "casepay" => [
                "settings" => false,
                "name" => "Casepay",
                "title" => "Casepay",
                "invest" => true,
                "payment" => true,
            ],
		],

		"perfectmoney" => [
			"perfectmoney" => [
				"settings" => true,	//показывать настройки или нет
				"name" => "PerfectMoney",	//название платежной системы
				"title" => "PerfectMoney",
				"invest" => true,	//можно ли принимать платежи
				"payment" => true, 	//можно ли делать выплаты
			],
			"paykassa" => [
				"settings" => false,
				"name" => "PayKassa",
				"title" => "PayKassa",
				"invest" => true,
				"payment" => true,
			],
		],

		"advcash" => [
			"advcash" => [
				"settings" => true,	//показывать настройки или нет
				"name" => "AdvCash",	//название платежной системы
				"title" => "AdvCash",
				"invest" => true,	//можно ли принимать платежи
				"payment" => true, 	//можно ли делать выплаты
			],
			"paykassa" => [
				"settings" => false,
				"name" => "PayKassa",
				"title" => "PayKassa",
				"invest" => true,
				"payment" => true,
			],
		],

		"card" => [
			"payeer" => [
				"settings" => false, 	//Выводить настройки или нет
				"name" => "Payeer",   	//Название отображаемой платежной системы (ОБЯЗАТЕЛЬНО ДОЛЖНО СОВПАДАТЬ С НАЗВАНИЕМ, ПОМИМО РЕГИСТРА), system_type
				"title" => "Payeer",	//название в винительном (кого, чего) падеже
				"invest" => true,
				"payment" => true,
			],
			"yandexmoney" => [
				"settings" => true,
				"name" => "YandexMoney",
				"title" => "Яндекс Деньги",
				"invest" => true,
				"payment" => false,
			],
			"freekassa" => [
				"settings" => false,
				"name" => "FreeKassa",
				"title" => "Free Kassa",
				"invest" => true,
				"payment" => true,
			],
			"paykassa" => [
				"settings" => false,
				"name" => "PayKassa",
				"title" => "PayKassa",
				"invest" => false,
				"payment" => true,
			],
			"card" => [
				"settings" => true,
				"name" => "Card (ручные)",
				"title" => "Card",
				"invest" => true,
				"payment" => true,
			],
            "casepay" => [
                "settings" => false,
                "name" => "Casepay",
                "title" => "Casepay",
                "invest" => true,
                "payment" => true,
            ],
		],

		"bitcoin" => [
			"block.io" => [
				"settings" => true, 	//Выводить настройки или нет
				"name" => "Block.io",   	//Название отображаемой платежной системы (ОБЯЗАТЕЛЬНО ДОЛЖНО СОВПАДАТЬ С НАЗВАНИЕМ, ПОМИМО РЕГИСТРА)
				"title" => "Block.io",
				"invest" => true,
				"payment" => true,
			],
			"manual" => [
				"settings" => true,
				"name" => "BitCoin",
				"title" => "BitCoin",
				"invest" => true,
				"payment" => true,
			],
			"paykassa" => [
				"settings" => false,
				"name" => "PayKassa",
				"title" => "PayKassa",
				"invest" => true,
				"payment" => true,
			],
		],

		"litecoin" => [
			"block.io" => [
				"settings" => true, 	//Выводить настройки или нет
				"name" => "Block.io",   	//Название отображаемой платежной системы (ОБЯЗАТЕЛЬНО ДОЛЖНО СОВПАДАТЬ С НАЗВАНИЕМ, ПОМИМО РЕГИСТРА)
				"title" => "Block.io",
				"invest" => true,
				"payment" => true,
			],
			"manual" => [
				"settings" => true,
				"name" => "LiteCoin",
				"title" => "LiteCoin",
				"invest" => true,
				"payment" => true,
			],
			"paykassa" => [
				"settings" => false,
				"name" => "PayKassa",
				"title" => "PayKassa",
				"invest" => true,
				"payment" => true,
			],
		],

		"dogecoin" => [
			"block.io" => [
				"settings" => true, 	//Выводить настройки или нет
				"name" => "Block.io",   	//Название отображаемой платежной системы (ОБЯЗАТЕЛЬНО ДОЛЖНО СОВПАДАТЬ С НАЗВАНИЕМ, ПОМИМО РЕГИСТРА)
				"title" => "Block.io",
				"invest" => true,
				"payment" => true,
			],
			"manual" => [
				"settings" => true,
				"name" => "DogeCoin",
				"title" => "DogeCoin",
				"invest" => true,
				"payment" => true,
			],
			"paykassa" => [
				"settings" => false,
				"name" => "PayKassa",
				"title" => "PayKassa",
				"invest" => true,
				"payment" => true,
			],
		],

		"ethereum" => [
			"manual" => [
				"settings" => true,
				"name" => "Ethereum",
				"title" => "Ethereum",
				"invest" => true,
				"payment" => true,
			],
			"paykassa" => [
				"settings" => false,
				"name" => "PayKassa",
				"title" => "PayKassa",
				"invest" => true,
				"payment" => true,
			],
		],

		"dash" => [
			"manual" => [
				"settings" => true,
				"name" => "Dash",
				"title" => "Dash",
				"invest" => true,
				"payment" => true,
			],
			"paykassa" => [
				"settings" => false,
				"name" => "PayKassa",
				"title" => "PayKassa",
				"invest" => true,
				"payment" => true,
			],
		],

        "bitcoincash" => [
            "manual" => [
                "settings" => true,
                "name" => "BitcoinCash",
                "title" => "BitcoinCash",
                "invest" => true,
                "payment" => true,
            ],
            "paykassa" => [
                "settings" => false,
                "name" => "PayKassa",
                "title" => "PayKassa",
                "invest" => true,
                "payment" => true,
            ],
        ],

        "zcash" => [
            "manual" => [
                "settings" => true,
                "name" => "Zcash",
                "title" => "Zcash",
                "invest" => true,
                "payment" => true,
            ],
            "paykassa" => [
                "settings" => false,
                "name" => "PayKassa",
                "title" => "PayKassa",
                "invest" => true,
                "payment" => true,
            ],
        ],

        "berty" => [
            "paykassa" => [
                "settings" => false,
                "name" => "PayKassa",
                "title" => "PayKassa",
                "invest" => true,
                "payment" => true,
            ],
        ],

        "monero" => [
            "manual" => [
                "settings" => true,
                "name" => "Monero",
                "title" => "Monero",
                "invest" => true,
                "payment" => true,
            ],
            "paykassa" => [
                "settings" => false,
                "name" => "PayKassa",
                "title" => "PayKassa",
                "invest" => true,
                "payment" => true,
            ],
        ],

        "ethereumclassic" => [
            "manual" => [
                "settings" => true,
                "name" => "EthereumClassic",
                "title" => "EthereumClassic",
                "invest" => true,
                "payment" => true,
            ],
            "paykassa" => [
                "settings" => false,
                "name" => "PayKassa",
                "title" => "PayKassa",
                "invest" => true,
                "payment" => true,
            ],
        ],

        "ripple" => [
            "manual" => [
                "settings" => true,
                "name" => "Ripple",
                "title" => "Ripple",
                "invest" => true,
                "payment" => true,
            ],
            "paykassa" => [
                "settings" => false,
                "name" => "PayKassa",
                "title" => "PayKassa",
                "invest" => true,
                "payment" => true,
            ],
        ],

        "neo" => [
            "manual" => [
                "settings" => true,
                "name" => "Neo",
                "title" => "Neo",
                "invest" => true,
                "payment" => true,
            ],
            "paykassa" => [
                "settings" => false,
                "name" => "PayKassa",
                "title" => "PayKassa",
                "invest" => true,
                "payment" => true,
            ],
        ],

        "gas" => [
            "manual" => [
                "settings" => true,
                "name" => "Gas",
                "title" => "Gas",
                "invest" => true,
                "payment" => true,
            ],
            "paykassa" => [
                "settings" => false,
                "name" => "PayKassa",
                "title" => "PayKassa",
                "invest" => true,
                "payment" => true,
            ],
        ],
	];

	if (!get("system")) {
		redirect('/adg.php?page=payment_system');
	}
    $system = strtolower(escape(get("system")));

	if (!DEMO) {
        while (is_post("update_settings")) {
            csrf_check_token();
			$type_payment = post("type_payment");

			$sql =  "UPDATE `payment_system` SET ";
			$sql .= "  `status` 		= ".escape_db(post("status"));
			$sql .= ", `type_invest` 	= ".escape_db(post("type_invest"));
			$sql .= ", `type_payment` 	= ".escape_db($type_payment);
			$sql .= ", `invest`			= ".escape_db(post("invest"));
			$sql .= ", `payment` 		= ".escape_db(post("payment"));
			$sql .= ", `currency` 		= ".escape_db(post('currency'));
			$sql .= ", `access` 		= ".escape_db(post('access'));
			$sql .= ", `access_pay` 	= ".escape_db(post('access_pay'));
			$sql .= " WHERE `name` 		= ".escape_db($system);

            $mysqli->query($sql);
            if ($type_payment === "'auto'") {
                $report = message_success("Данные сохранены. ВНИМАНИЕ! Вы установили автоматические выплаты, не забудьте настроить cron");
            } else {
                $report = message_success("Данные сохранены");
            }
            break;
        }

		//установка BTCPayMe нажатием одной кнопки
		while (is_post("install_content")) {
            csrf_check_token();

			//проверяем email админа на корректность
			if (!is_email($admin_email)) {
				$report = message_error('Ваш E-mail некорректен. Проверьте его в поле Настройки.');
			}

			//подключение класса
			require_once (ROOT.("/modules/btcpayme_api.class.php"));

			//создаем пользователя и аккаунт
			$bitcoin_cli = new BtcpaymeAPI(1,1);
			$data = $bitcoin_cli->api_get_account($admin_email, $site);

			//проверяем выходные данные
			if($data['error']) {
				$report = message_error($data['message']);
			} else {
				$pay_methods_data = [
					"btcpayme_shop_id" => $data['data']['sci_id'],
					"btcpayme_shop_password" => $data['data']['sci_password'],
					"btcpayme_api_id" => $data['data']['api_id'],
					"btcpayme_api_password" => $data['data']['api_password'],
					"bitcoin_address" => $data['data']['account_address']
				];

				foreach($pay_methods_data as $method => $item) {
					$sql = "UPDATE `pay_methods` SET `value` = ".escape_db($item);
					$sql .= " WHERE `name` = ".escape_db($method);

					if (!$mysqli->query($sql)) {
						$message = "Ошибка обновления поля {$method} в таблице pay_methods";
						$report = message_error($message);
						break;
					}
				}

                $report = message_success($data['message']);
            }
            break;
        }

		//установка PayKassa нажатием одной кнопки
		while (is_post("install_content_paykassa")) {
			//csrf_check_token();
			$report = adg_pay_methods_paykassa_signup();
			break;
		}

		while (is_post("update_transfer_system")) {
			csrf_check_token();
			if (post('idsn')) {
				$value = post('idsn');
				if (in_array($value, $transfer_system[$system])){
					$message = "Передано неверное значение в поле access";
					$report = message_error($message);
					break;
				}
				$sql = "UPDATE `payment_system` SET ";
				$sql .= " `access` = ".escape_db(trim($value));
				$sql .= " WHERE `name` = ".escape_db($system);
				if (!$mysqli->query($sql)) {
					$message = "Ошибка обновления поля access в таблице payment_system";
					$report = message_error($message);
					break;
				}
			}
			$message = "Поля обновлены";
			$report = message_success($message);
			break;
		}

		while (is_post("update_fields")) {
			if (isset($_POST['ids'][2]) && (int)$_POST['ids'][2] > 0) {
				$res = adg_create_file_to_payeer($_POST['ids'][2]);
				echo $res['message'];
			}
            foreach (post('ids') as $id => $value) {
                $sql = "UPDATE $table SET ";
                $sql .= " `value` = ".escape_db(trim($value));
                $sql .= " WHERE `id` = ".escape_db($id);
                if (!$mysqli->query($sql)) {
                    $row = get_row_by_id($table, $id);
                    $message = "Ошибка обновления поля ".$row['name'];
                    $report = message_error($message);
                    break 2;
                }
            }
            $message = "Поля обновлены";
            $report = message_success($message);
            break;
        }
	}

    $payment_system = get_row_by_field("payment_system", "name", $system);
    $status = $payment_system['status'];
    $type_payment = $payment_system['type_payment'];
    $type_invest = $payment_system['type_invest'];
	$invest = $payment_system['invest'];
	$payment = $payment_system['payment'];
	$payment = $payment_system['payment'];
	$system_currency = $payment_system['currency'];
	$access = $payment_system['access'];
	$access_pay = $payment_system['access_pay'];

	if (isset($transfer_system[$system])) {
		$settings_system = $transfer_system[$system];
		if (!$settings_system) {
			die("Ошибка! Не обнаружен платенжы метод");
		}
	}

	if (is_post('range_update')) {
	    unset($_POST['range_update']);
	    $report = message_success('Изменения сохранены');
	    $range_system = get('system');
	    $range_invest = json_encode(post('range_invest'));
	    $range_payment = json_encode(post('range_payment'));
	    $sql = 'UPDATE `payment_system` SET ';
	    $sql .= '  `range_invest` = '.escape_db($range_invest);
	    $sql .= ', `range_payment` = '.escape_db($range_payment);
	    $sql .= ' WHERE `name` = '.escape_db($range_system);
	    if (!$mysqli->query($sql)) {
	        log_write('ERROR /adg.php?page=pay_methods', 'Ошибка записи в базу данных', $sql);
	        $report = message_error('Ошибка записи в БД. Обратитесь в техподдержку');
        }
    }

?>

<div id="page-wrapper">
	<div class="container-fluid">
		<div class="row">
			<div class="col-lg-12">
                <?php include(ROOT."/adg/pages/show_report.php"); ?>
				<div class="panel panel-primary">
					<div class="panel-heading">
						<h3 class="panel-title"><i class="fa fa-bar-chart-o"></i> <?php echo strtoupper($system); ?></h3>
					</div>

					<?php if (strtolower($system) === 'paykassa') { //костыльная проверка на данные PayKassa ?>
						<?php

						$pay_methods = get_list("pay_methods", " system_type = ".escape_db("PayKassa"));
						$checker = true;

						foreach($pay_methods as $item) {
							if(!$item['value'] || (int)strripos($item['value'], '*')) {
								$checker = false;
							}
						}

						if(!$checker) {
							?>
							<form action="" method="post" class="settings">
								<tr align="right">
									<td colspan="3" style="text-align:center;"><?php button_install('install_content_paykassa', 'btn btn-default', 'Установить'); ?></td>
								</tr>
							</form>
						<?php } else { ?>
							<tr align="right">
								<td colspan="3" style="text-align:center;"><?php button_install('', 'btn btn-success', 'Установлено'); ?></td>
							</tr>
						<?php } ?>
					<?php } else { ?>

						<?php if ($settings_system[$access]['settings'] || $settings_system[$access_pay]['settings']) { ?>
						<div class="panel-body">
							<div class="flot-chart">
								<div class="flot-chart-content" id="flot-line-chart">
									<div class="table-responsive">
										<table class="table table-bordered table-hover">
											<thead>
												<tr>
													<th>Параметр</th>
													<th>Текущее значение</th>
													<th>Новое значение</th>
												</tr>
											</thead>
											<tbody>


												<form action = "" method = "post" class = "settings">
													<input type="hidden" name="update_fields" value="1">
													<?php if ($settings_system[$access]['settings']) { ?>
														<tr>
															<td colspan="3"><b>Данные для пополнения</b></td>
														</tr>
														<?php
															$list = get_pay_methods_by_type(get("system"), "invest", $access);

															foreach ($list as $item) {
																if ((int)$item['show_admin'] === 0 || !$payment_system['access']) {
																	continue;
																}

														?>
																<tr>
																	<td><?php echo escape($item['title']);?></td>
																	<td><?php echo escape($item['value']);?></td>
																	<td>
																	<?php if ($item['system'] === 'Qiwi' && $item['name'] == 'qiwi_auto_invest') {?>
																		<select name = "ids[<?php echo $item['id']; ?>]" class = "form-control">
																			<option <?php if ($item['value'] === 'off') echo 'selected'; ?> value="off">Выключены</option>
																			<option <?php if ($item['value'] === 'on') echo 'selected'; ?>  value="on">Включены</option>
																		</select>
																	<?php } else { ?>
																		<input name = "ids[<?php echo $item['id']; ?>]" class = "form-control" value="<?php echo escape($item['value']);?>">
																	<?php } ?>
																	</td>
																</tr>
														<?php } ?>
													<?php } ?>

													<?php if ($settings_system[$access_pay]['settings']) { ?>
														<tr>
															<td colspan="3"><b>Данные для выплат</b></td>
														</tr>
														<?php
															$list = get_pay_methods_by_type(get("system"), "payment", $access_pay);
															foreach ($list as $item) {
																if ((int)$item['show_admin'] === 0 || !$payment_system['access']) {
																	continue;
																}
														?>
															<tr>
																<td><?php echo escape($item['title']); ?></td>
																<td style="width: 100px;">
																	<div style="width: 400px; overflow: auto;">
																		<?php echo escape($item['value']);?>
																	</div>
																</td>
																<td><input name = "ids[<?php echo $item['id']; ?>]" class = "form-control" value="<?php echo escape($item['value']);?>"></td>
															</tr>
														<?php } ?>
													<?php } ?>

													<tr align="right">
														<td colspan="3"><?php button_update(); ?></td>
													</tr>

												</form>
											</tbody>
										</table>
									</div>
								</div>
							</div>
						</div>
						<?php } ?>


						<div class="panel-body">
							<div class="flot-chart">
								<div class="flot-chart-content" id="flot-line-chart">
									<div>
										<form enctype="multipart/form-data" action = "" method = "POST">
											<!-- Сервисы приема и выплат -->
											<div class="col-md-6">
												<div class="col-md-12 bg-success" style="text-align:center;border-bottom: 1px solid #eee;margin-bottom: 20px;">
													<br>
													<label>СЕРВИС ПРИЕМА</label>
													<br><br>
												</div>
												<div class="col-md-12">
													<label>Принимать через </label>
													<select name="access" class="form-control" style="width: 100%;">
														<?php
															foreach ($settings_system as $key => $system) {
																if (!$system['invest']) {
																	continue;
																}
														?>
														<option <?php if (strtolower($key) == strtolower($access)) echo "selected"; ?> value="<?php echo strtolower(escape($key)); ?>">
															- <?php echo escape($system['name']); ?> -
														</option>
														<?php } ?>
													</select>
												</div>
											</div>
											<div class="col-md-6">
												<div class="col-md-12 bg-success" style="text-align:center;border-bottom: 1px solid #eee;margin-bottom: 20px;">
													<br>
													<label>СЕРВИС ВЫПЛАТ</label>
													<br><br>
												</div>
												<div class="col-md-12">
													<label>Выплачивать через </label>
													<select name="access_pay" class="form-control" style="width: 100%;">
														<?php foreach ($settings_system as $key => $system) {
                                                            if (!$system['payment']) {
                                                                continue;
                                                            } ?>
															<option <?php if (strtolower($key) == strtolower($access_pay)) echo "selected"; ?> value="<?php echo strtolower(escape($key)); ?>">
																- <?php echo escape($system['name']); ?> -
															</option>
														<?php } ?>
													</select>
												</div>
											</div>
											<!-- Сервисы приема и выплат -->
											<br><br><br><br><br><br><br><br><br>
											<div class="col-md-3">
												<div class="col-md-12 bg-success" style="text-align:center;border-bottom: 1px solid #eee;margin-bottom: 20px;">
													<br>
													<label>ПОПОЛНЕНИЯ</label>
													<br><br>
												</div>
												<div class="col-md-6">
													<label>Тип работы </label>
													<select name="type_invest" class="form-control" style="width: 100%;">
														<option <?php if ($type_invest === "manual") echo "selected"; ?> value="manual"> - Ручные - </option>
														<option <?php if ($type_invest === "instant") echo "selected"; ?> value="instant"> - Инстант - </option>
													</select>
												</div>
												<div class="col-md-6">
													<label>Статус работы </label>
													<select name="invest" class="form-control" style="width: 100%;">
														<option <?php if ($invest == 1) echo "selected"; ?> value="1"> - Включить - </option>
														<option <?php if ($invest == 0) echo "selected"; ?> value="0"> - Выключить - </option>
													</select>
												</div>
											</div>
											<div class="col-md-3">
												<div class="col-md-12 bg-success" style="text-align:center;border-bottom: 1px solid #eee;margin-bottom: 20px;">
													<br>
													<label>ВЫПЛАТЫ</label>
													<br><br>
												</div>
												<div class="col-md-6">
													<label>Тип работы </label>
													<select name="type_payment" class="form-control" style="width: 100%;">
														<option <?php if ($type_payment === "manual") echo "selected"; ?> value="manual"> - Ручные - </option>
														<option <?php if ($type_payment === "instant") echo "selected"; ?> value="instant"> - Инстант - </option>
														<option <?php if ($type_payment === "auto") echo "selected"; ?> value="auto"> - Автоматические - </option>
														<option <?php if ($type_payment === "confirmation") echo "selected"; ?> value="confirmation"> - По подтверждениям - </option>
													</select>
												</div>
												<div class="col-md-6">
													<label>Статус работы </label>
													<select name="payment" class="form-control" style="width: 100%;">
														<option <?php if ($payment == 1) echo "selected"; ?> value="1"> - Включить - </option>
														<option <?php if ($payment == 0) echo "selected"; ?> value="0"> - Выключить - </option>
													</select>
												</div>
											</div>
											<div class="col-md-3">
												<div class="col-md-12 bg-success" style="text-align:center;border-bottom: 1px solid #eee;margin-bottom: 20px;">
													<br>
													<label>НАСТРОЙКИ</label>
													<br><br>
												</div>
												<hr>
												<div class="col-md-12">
													<label>Статус работы </label>
													<select name="status" class="form-control" style="width: 100%;">
														<option <?php if ($status === "on") echo "selected"; ?> value="on"> - Включена - </option>
														<option <?php if ($status === "off") echo "selected"; ?> value="off"> - Выключена - </option>
													</select>
												</div>
											</div>
											<div class="col-md-3">
												<div class="col-md-12 bg-success" style="text-align:center;border-bottom: 1px solid #eee;margin-bottom: 20px;">
													<br>
													<label>ВАЛЮТА</label>
													<br><br>
												</div>
												<hr>
												<div class="col-md-12">
													<label></label>
													<select name="currency" class="form-control" style="width: 100%;">
														<?php foreach (get_list_currencies() as $cur) { ?>
															<option <?php if ($cur === $system_currency) echo "selected"; ?> value="<?php echo escape($cur); ?>"> - <?php echo escape($cur); ?> - </option>
														<?php } ?>
													</select>
												</div>
											</div>
											<div class="col-md-12">
												<label> </label><br>
												<input type="hidden" name="update_settings" value="1">
												<?php echo csrf_install(); ?>
												<button type="submit" name="update" class="btn" style="width:100%;">Обновить</button>
											</div>
										</form>

                                        <div class="clearfix"></div>
                                        <br><br>


                                        <form action="" method="post">

                                            <?php echo form_init(); ?>

                                            <div class="col-md-6">
                                                <div class="col-md-12 bg-success" style="text-align:center;border-bottom: 1px solid #eee;margin-bottom: 20px;">
                                                    <br>
                                                    <label>Интервал суммы пополнения</label>
                                                    <br><br>
                                                </div>
                                                <div class="col-md-2">
                                                    <label>Валюта</label>
                                                    <select name="currency" class="range_select form-control" style="width: 100%;" data-action="invest">
                                                        <?php $range_invest = json_decode(get_value('SELECT `range_invest` FROM `payment_system` WHERE `name` = '.escape_db(get('system'))), true);
                                                        foreach ($range_invest as $key => $item) { ?>
                                                            <option value="<?php echo escape($key); ?>" <?php if (strtolower($val) == strtolower($key)) { echo 'selected'; } ?>>
                                                                <?php echo escape($key); ?>
                                                            </option>
                                                        <?php } ?>
                                                    </select>
                                                </div>
                                                <?php foreach ($range_invest as $key => $item) { ?>
                                                    <div class="col-md-10 range_invest_input <?php echo escape($key); ?>" style="<?php if (count($range_invest) > 1 && $key != $val) { echo 'display: none;'; } ?>">
                                                        <div class="col-md-6">
                                                            <label>&nbsp;</label>
                                                            <div class="input-group" style="width: 100%;">
                                                                <span class="input-group-addon">MIN</span>
                                                                <input type="text" class="form-control" style="width: 100%;" name="<?php echo 'range_invest['.escape($key).'][min]'; ?>" value="<?php echo escape($item['min']); ?>">
                                                            </div>
                                                        </div>
                                                        <div class="col-md-6">
                                                            <label>&nbsp;</label>
                                                            <div class="input-group">
                                                                <span class="input-group-addon">MAX</span>
                                                                <input type="text" class="form-control" style="width: 100%;" name="<?php echo 'range_invest['.escape($key).'][max]'; ?>" value="<?php echo escape($item['max']); ?>">
                                                            </div>
                                                        </div>
                                                    </div>
                                                <?php } ?>
                                            </div>
                                            <div class="col-md-6">
                                                <div class="col-md-12 bg-success" style="text-align:center;border-bottom: 1px solid #eee;margin-bottom: 20px;">
                                                    <br>
                                                    <label>Интервал суммы выплаты</label>
                                                    <br><br>
                                                </div>
                                                <div class="col-md-2">
                                                    <label>Валюта</label>
                                                    <select name="currency" class="range_select form-control" style="width: 100%;" data-action="payment">
                                                        <?php $range_payment = json_decode(get_value('SELECT `range_payment` FROM `payment_system` WHERE `name` = '.escape_db(get('system'))), true);
                                                        foreach ($range_payment as $key => $item) { ?>
                                                            <option value="<?php echo escape($key); ?>" <?php if (strtolower($val) == strtolower($key)) { echo 'selected'; } ?>>
                                                                <?php echo escape($key); ?>
                                                            </option>
                                                        <?php } ?>
                                                    </select>
                                                </div>
                                                <?php foreach ($range_payment as $key => $item) { ?>
                                                    <div class="col-md-10 range_payment_input <?php echo escape($key); ?>" style="<?php if (count($range_payment) > 1 && $key != $val) { echo 'display: none;'; } ?>">
                                                        <div class="col-md-6">
                                                            <label>&nbsp;</label>
                                                            <div class="input-group" style="width: 100%;">
                                                                <span class="input-group-addon">MIN</span>
                                                                <input type="text" class="form-control" style="width: 100%;" name="<?php echo 'range_payment['.escape($key).'][min]'; ?>" value="<?php echo escape($item['min']); ?>">
                                                            </div>
                                                        </div>
                                                        <div class="col-md-6">
                                                            <label>&nbsp;</label>
                                                            <div class="input-group">
                                                                <span class="input-group-addon">MAX</span>
                                                                <input type="text" class="form-control" style="width: 100%;" name="<?php echo 'range_payment['.escape($key).'][max]'; ?>" value="<?php echo escape($item['max']); ?>">
                                                            </div>
                                                        </div>
                                                    </div>
                                                <?php } ?>
                                            </div>
                                            <div class="col-md-12">
                                                <br>
                                                <button type="submit" name="range_update" class="btn" style="width:100%;">Обновить</button>
                                            </div>
                                        </form>


                                        <br><br><br>

									</div>
								</div>
							</div>
						</div>
					<?php } ?>


                    <script>
                        $('.range_select').on('change', function () {
                            var val = $(this).val(),
                                action = $(this).data('action');
                            $('.range_' + action + '_input').hide();
                            $('.range_' + action + '_input.'+val).show();
                        })
                    </script>


				</div>

				<?php
					$white_list = ['Payeer', 'AdvCash', 'PayKassa', 'YandexMoney', 'Casepay'];
					foreach ($white_list as $item) {
						if (get('system') !== $item) {
							continue;
						}
				?>
                    <div class="row">
                        <div class="col-lg-12">
                            <label>Успешный ответ</label>
                            <div class="input-group">
                                <input type="text" class="form-control" id="success" value="<?php echo request_get_protocol().escape($site).'/pay/'.escape(strtolower($item)).'/success.php'; ?>">
                                <span class="input-group-btn">
                            <button class="btn btn-default btn-clipboard" data-clipboard-target="#success">Скопировать!</button>
                        </span>
                            </div><!-- /input-group -->
                        </div><!-- /.col-lg-6 -->
                    </div><!-- /.row -->
                    <br>
                    <div class="row">
                        <div class="col-lg-12">
                            <label>Неудачный ответ</label>
                            <div class="input-group">
                                <input type="text" class="form-control" id="fail" value="<?php echo request_get_protocol().escape($site).'/pay/'.escape(strtolower($item)).'/fail.php'; ?>">
                                <span class="input-group-btn">
                                    <button class="btn btn-default btn-clipboard" data-clipboard-target="#fail">Скопировать!</button>
                                </span>
                            </div><!-- /input-group -->
                        </div><!-- /.col-lg-6 -->
                    </div><!-- /.row -->
                    <br>
                    <div class="row">
                        <div class="col-lg-12">
                            <label>Обработчик</label>
                            <div class="input-group">
                                <input type="text" class="form-control" id="index" value="<?php echo request_get_protocol().escape($site).'/pay/'.escape(strtolower($item)).'/index.php'; ?>">
                                <span class="input-group-btn">
                                    <button class="btn btn-default btn-clipboard" data-clipboard-target="#index">Скопировать!</button>
                                </span>
                            </div><!-- /input-group -->
                        </div><!-- /.col-lg-6 -->
                    </div><!-- /.row -->
				<?php } ?>







				<br><br><br>
			</div>
		</div>
	</div>
</div>
<script src="/adg/style/js/clipboard.min.js"></script>
<script>
	new ClipboardJS(".btn-clipboard"); // Не забываем инициализировать библиотеку на нашей кнопке
</script>