<?php
include_once 'clazz/Membre.class.php';
include_once 'includes/bdd.php';

$me = new Membre();
$me->connect();

if($me->getAdminLevel()<15){
	echo 'Your admin level is too low (15 or more required)';
	exit;
}elseif(!isset($_GET['action'])){
	echo 'Please set an action in the URL (GET method ,name:"action")';
	exit;
}

switch ($_GET['action']){

case 'set_discutionVisibility' :
	if(!isset($_POST['discutionVisibility'])){
		echo 'You must give a discution visibility (POST method,name:"discutionVisibility")';
		exit;
	}
	if(!isset($_POST['discutionID'])){
		echo 'You must give a discution ID (POST method,name:"discutionID")';
		exit;
	}
	$discutionVisibility = $_POST['discutionVisibility'];
	$discutionID = $_POST['discutionID'];
	if ($discutionVisibility !== 'p' and preg_match ( "#^a[0-9]+$#",$discutionVisibility ) != 1 and preg_match ( '#^x([0-9]+;)*([0-9]+)?$#', $discutionVisibility ) != 1 ){
		echo 'Your discution visibility is not well-formed : it should have been formed like ("p" or "x31;41;59;26;53" or "a42")';
		exit;
	}
	
	$req = $GLOBALS['bdd']->prepare('UPDATE discussions SET autorized=? WHERE ID=?');
	$req->execute(array($discutionVisibility,$discution));
		
		
		
		
		
		
		
		exit;




default :
	echo 'Unknown action : '+$_GET['action'];
	exit;
	
}	