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

if ($id_active){
	$sql = "SELECT label, c_active FROM ".$module." WHERE id = :id ";
	$result = $conn->prepare($sql);
	$result->bindValue(':id', $id_active, PDO::PARAM_INT);
	$result->execute();
	$arr = $result->fetch();
	
	$sql = "UPDATE ".$module." SET c_active = :c_active WHERE BINARY label = :label";
	$result = $conn->prepare($sql);
	if ($arr['c_active'] == 1) $result->bindValue(':c_active', 0, PDO::PARAM_STR);
	else $result->bindValue(':c_active', 1, PDO::PARAM_STR);
	$result->bindValue(':label', $arr['label'], PDO::PARAM_STR);
	$result->execute();
	$id_active = 0;
}

if (isset($_POST['multi_activate']) && $_POST['multi_activate']){
	if (isset($_POST['c_check'])){
		foreach ($_POST['c_check'] AS $check_id => $value){
			$sql = "SELECT label FROM ".$module." WHERE id = :id ";
			$result = $conn->prepare($sql);
			$result->bindValue(':id', $check_id, PDO::PARAM_INT);
			$result->execute();
			$arr = $result->fetch();
			
			$sql = "UPDATE ".$module." SET c_active = '1' WHERE BINARY label = :label";
			$result = $conn->prepare($sql);
			$result->bindValue(':label', $arr['label'], PDO::PARAM_STR);
			$result->execute();
		}
	}
}

if (isset($_POST['multi_deactivate']) && $_POST['multi_deactivate']){
	if (isset($_POST['c_check'])){
		foreach ($_POST['c_check'] AS $check_id => $value){
			$sql = "SELECT label FROM ".$module." WHERE id = :id ";
			$result = $conn->prepare($sql);
			$result->bindValue(':id', $check_id, PDO::PARAM_INT);
			$result->execute();
			$arr = $result->fetch();
			
			$sql = "UPDATE ".$module." SET c_active = '0' WHERE BINARY label = :label";
			$result = $conn->prepare($sql);
			$result->bindValue(':label', $arr['label'], PDO::PARAM_STR);
			$result->execute();
		}
	}
}


print "
<input type='hidden' name='id_active' value='".$id_active."' />
<input type='hidden' name='multi_activate' value='0' />
<input type='hidden' name='multi_deactivate' value='0' />";
