<?php
if (isset($_POST['id_delete'])) {
	if(settype($_POST['id_delete'], 'integer')) $id_delete = $_POST['id_delete'];
} else $id_delete = 0;

if ($id_delete){
	$sql = "SELECT iso FROM ".$module." WHERE id = :id ";
	
	$result = $conn->prepare($sql);
	$result->bindValue(':id', $id_delete, PDO::PARAM_INT);
	$result->execute();
	
	if ($result->rowCount()){
		$arr = $result->fetch();
		
		$sql = "DELETE FROM ".$module." WHERE id = :id ";
		$result = $conn->prepare($sql);
		$result->bindValue(':id', $id_delete, PDO::PARAM_INT);
		$result->execute();
		
		$sql_tmp = "SELECT id FROM ".$module." WHERE iso = :iso ";
		$result_tmp = $conn->prepare($sql_tmp);
		$result_tmp->bindValue(':iso', $arr['iso'], PDO::PARAM_STR);
		$result_tmp->execute();
		if (!$result_tmp->rowCount()){
			$sql_del = "DELETE FROM frontend_labels WHERE BINARY language = :language ";
			$result_del = $conn->prepare($sql_del);
			$result_del->bindValue(':language', $arr['iso'], PDO::PARAM_STR);
			$result_del->execute();
			$sql_del = "DELETE FROM settings_labels WHERE BINARY language = :language ";
			$result_del = $conn->prepare($sql_del);
			$result_del->bindValue(':language', $arr['iso'], PDO::PARAM_STR);
			$result_del->execute();
		}
		
	}
	$id_delete = 0;
}

if (isset($_POST['multi_delete']) && $_POST['multi_delete']){
	if (isset($_POST['c_check'])){
		foreach ($_POST['c_check'] AS $check_id => $value){
			$sql = "SELECT iso FROM ".$module." WHERE id = :id ";
			
			$result = $conn->prepare($sql);
			$result->bindValue(':id', $check_id, PDO::PARAM_INT);
			$result->execute();
			
			if ($result->rowCount()){
				$arr = $result->fetch();
				
				$sql = "DELETE FROM ".$module." WHERE id = :id ";
				$result = $conn->prepare($sql);
				$result->bindValue(':id', $check_id, PDO::PARAM_INT);
				$result->execute();
		
				$sql_tmp = "SELECT id FROM ".$module." WHERE iso = :iso ";
				$result_tmp = $conn->prepare($sql_tmp);
				$result_tmp->bindValue(':iso', $arr['iso'], PDO::PARAM_STR);
				$result_tmp->execute();
				if (!$result_tmp->rowCount()){
					$sql_del = "DELETE FROM frontend_labels WHERE BINARY language = :language ";
					$result_del = $conn->prepare($sql_del);
					$result_del->bindValue(':language', $arr['iso'], PDO::PARAM_STR);
					$result_del->execute();
					$sql_del = "DELETE FROM settings_labels WHERE BINARY language = :language ";
					$result_del = $conn->prepare($sql_del);
					$result_del->bindValue(':language', $arr['iso'], PDO::PARAM_STR);
					$result_del->execute();
				}
				
			}
		}
	}
}


print "
<input type='hidden' name='id_delete' value='".$id_delete."' />
<input type='hidden' name='multi_delete' value='0' />";