<?php
include_once 'clazz/Zincluder.php;';
session_start ();
$me = new Membre ( $_SESSION ['session_id'] );
$me->connect ( $_SESSION ['session_mdp'] );
if ($me->isAdminLevelLowerThan ( 15 )) {
	header ( 'Location:401.php' );
	exit ();
}
?>
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="css/adminStyle.css" />
<meta charset="utf-8" />
<title>La console d'admin</title>
</head>
<body>
	<script
		src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>

	<select id="commandSelector">
		<option value="get" selected="true">get</option>
		<option value="set">set</option>
		<option value="remove">remove</option>
		<option value="add">add</option>
		<option value="BDD">BDD</option>
	</select>

	<div id="setDiv">

		<form id="setFormObject">
			Objet<br /> <select class="classSelector" id="setClassSelector">
				<!-- Rempli en JS -->
			</select><br />
			<button id="selectFromObject">S&eacute;l&eacute;ctionner</button>
		</form>
		<!--  
		Pour enlever les vilains whitespace
		-->
		<form id="setChampsForm">
			Valeur<br /> <select id="setChamps">
				<!-- Rempli en JS -->
			</select> <select id="arrayOperation">
				<option value="add" selected="selected">add</option>
				<option value="set">set</option>
				<option value="remove">remove</option>
			</select> <input type="text" id="primitiveValueField" />
			<button id="selectComplexValue">S&eacute;l&eacute;ctionner</button>
		</form>

	</div>
	<button id="send">Envoyer la requ&ecirc;te</button>
	<br />
	<samp id="adminDialogAnswer">
		Hello !!!<br />
	</samp>




	<div class="fullscreen opaque">
		<div class="screen-vertical-centered">
			<form class="screen-horizontal-centered selectorForm">
				<!-- ID set en JS (bonjour la galère) -->

				<!-- Attributs remplis en JS -->
				<span>
					<input type="checkbox" />
					<h5>Nom du champ</h5>
					<select>
						<option value="ee">=</option>
						<option value="lt">&lt;</option>
						<option value="gt">&gt;</option>
						<option value="ge">&ge;</option>
						<option value="le">&le;</option>
						<option value="ne">&ne;</option>
					</select>
					<input type="text" />
					<button id="nomDuChampSelector">Selecteur</button>
				</span>

			</form>
		</div>
	</div>
	<script type="text/javascript">
		function done(){
			var objet = $(this).parent().data('object');//SetObjectSelector-projectSelector
			var selector = new Array();
			/*
			$(this).parent().children('div').each(function() {
				if($(this).children('input[type="checkbox"]').is(':selected')){
					var varName = $(this).parent().children('h5').text();
					var operator = $(this).parent().children('h5').text();
					
				}
			});
			*/
			$(this).parent().children('div').children('input[type="checkbox"]:selected').each(function() {
					var varName = $(this).parent().children('h5').text();
					var operator = $(this).parent().children('select').find(':selected').attr('value');
					var value;
					if($(this).parent().children('input[type="text"]').length)
						value = $(this).parent().children('input[type="text"]').val();
					else
						value = $(this).parent().children('button').data('selector');
					selector[varName] = operator+value;
				}
			});
			$('#'+objet).data('selector',JSON.stringify(selector));
		}

		function selector(object,clazz) {
			var newForm = $('<form></form>');
			newForm.data('object',object);
			switch(clazz){
			case 'membre':
				newForm.append(selectorNode('pseudo',true,false,false));
				newForm.append(selectorNode('password',true,false,false));
				newForm.append(selectorNode('adminLevel',true,false,true));
				newForm.append(selectorNode('dateCreation',true,false,true));
				newForm.append(selectorNode('requiredBanner',true,false,false));
				newForm.append(selectorNode('personnalMessage',true,false,false));
				break;
			case 'projet':
				newForm.append(selectorNode('name',true,false,false));
				newForm.append(selectorNode('dateCreation',true,false,true));
				newForm.append(selectorNode('owner',false,false,false));
				newForm.append(selectorNode('secondaryOwner',false,true,false));
				break;
			case 'version':
				newForm.append(selectorNode('name',true,false,false));
				newForm.append(selectorNode('sendDate',true,false,true));
				newForm.append(selectorNode('publicFiles',true,true,false));
				newForm.append(selectorNode('tags',true,true,false));
				newForm.append(selectorNode('project',false,false,false));
				newForm.append(selectorNode('language',true,false,false));
				break;
				
			}
			newForm.append('<br/>');
			newForm.append('<button id="selectorAbort">Annuler</button>')
			newForm.append('<button id="selectorDone">Termin&eacute;</button>');
			$('form.selectorForm').replaceWith(newForm);
		}
		function selectorNode(name,primitive,array,number){
			var span = $('<span></span>');
			span.append('<input type="checkbox" />')
			span.append('<h5>'+name+'</h5>')
			if(number)
				span.append('<select><option value="ee">=</option><option value="lt">&lt;</option><option value="gt">&gt;</option><option value="ge">&ge;</option><option value="le">&le;</option><option value="ne">&ne;</option></select>')
			else if(array)
				span.append('<select><option value="in">&isin;</option><option value="nn">&notin;</option></select>')
			else
				span.append('<select><option value="ee">=</option><option value="ne">&ne;</option></select>')
			if(primitive)
				span.append('<input type="text" />')
			else
				span.append('<button id="'+name+'Selector">Selecteur</button>')
		}
		
		function genClassesSelectors{
			$('select.classSelector')
			.append('<option value="membre">Membre</option>')
			.append('<option value="projet">Projet</option>')
			.append('<option value="version">Version</option>')
			.append('<option value="discussion">Discussion</option>')
			.append('<option value="message">Message</option>');
		}
		$(window).load(genClassesSelectors);
		
	</script>


</body>
</html>