| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222 | <?php//Regarde si il y a un cookie avec le nom de la session à charger ou l'info en POSTif(isset($_POST['salon'])){	//Création du cookie	setcookie('salon', $_POST['salon'], time() + 60 * 60 * 24, '/', '', false, true);	//Recharge la page	header('Location: ./');	exit;} else if(!isset($_COOKIE['salon'])){	require 'start.php';	exit;}//Activation de la sessionif(!isset($_COOKIE['common-sess'])){	//Création du cookie de session commun	setcookie('common-sess', $_COOKIE['salon'], time() + 60 * 60 * 24, '/', '', false, true);	//Recharge la page	header('Location: ./');	exit;} else if($_COOKIE['common-sess'] != $_COOKIE['salon']){	//Changement de la valeur de la session	setcookie('common-sess', $_COOKIE['salon'], time() + 60 * 60 * 24, '/', '', false, true);	//Recharge la page	header('Location: ./');	exit;}//Lancement sessionsession_name('common-sess');session_start();//Valeur message$type = '';$value = '';//Param Getif(isset($_GET['quit'])){	setcookie('salon', '', 0, '/', '', false, true);	header('Location: ./');	exit;}if(isset($_GET['type']) && isset($_GET['value'])){	$type = $_GET['type'];	$value = $_GET['value'];}//Setup session si besoinsif(!( isset($_SESSION['user']) && isset($_SESSION['roll']) )){	$_SESSION['user'] = [];	$_SESSION['roll'] = [];}//Traitement formulaireif(isset($_POST['roll'])){	//Regarde si l'utilisateur est nouveau	$name = '';	if(isset($_POST['name']) && trim($_POST['name']) != ''){		$name = $_POST['name'];		if(!isset($_SESSION['user'][$name])){			$_SESSION['user'][$name] = $name;		}	} else if(isset($_POST['save-name'])){		$name = $_POST['save-name'];	} else {		$type = 'err';		$value = 'Aucun lanceur';	}	//Si il y a un bien un utilisateur	if($name != ''){		//Tirage		$roll = mt_rand(1, $_POST['roll']);		//Affichage		if(isset($_POST['hide'])){			header('Location: ./?type&value=' . urlencode('Resultat : ' . $roll . ' / ' . $_POST['roll']));			exit;		}		$_SESSION['roll'][] = [			'name' => $name,			'roll' => $roll,			'dice' => $_POST['roll']		];	}}//Page webrequire 'header.php';?><style type="text/css">	.center{		text-align: center;	}	.float_message {    	position: absolute;    	width: 800px;    	top: 120px;    	right: 80px;    	z-index: 100;    	box-shadow:  12px 12px 2px 1px rgba(0, 0, 255, .2);    	margin:  0 0 0 0;    	height: 60px;    	cursor:  pointer;	}</style><div style="position: absolute; top: 40px; left: 80px; cursor: pointer;">	<i id="quit" class="material-icons tooltipped" data-position="right" data-tooltip="Changer de salon" style="font-size: 4em">arrow_back</i></div><div style="position: absolute; top: 40px; right: 80px; cursor: pointer;">	<i id="reload" class="material-icons tooltipped" data-position="bottom" data-tooltip="Recharger la page" style="font-size: 4em">refresh</i></div><div style="position: absolute; top: 40px; right: 160px; cursor: pointer;">	<i id="reset" class="material-icons tooltipped" data-position="left" data-tooltip="Reset les lancer" style="font-size: 4em">settings_backup_restore</i></div><main class="container">	<div class="row">		<div class="col s12 center">			<h1><b>JdR Roll</b></h1>		</div>	</div>	<form id="form" method="POST" action="./">		<div class="row">			<div class="col m6 s12">				<div class="row">		        	<div class="input-field col s12">		          		<input id="name" type="text" name="name">		          		<label for="name">Nom du lanceur</label>		        	</div>		      	</div>		    </div>		    <div class="col m6 s12">				<div class="row">		        	<div class="input-field col s12">		          		<select id="save-name" name="save-name">		      				<option value="" disabled selected>Selectionnez un lanceur</option>		      				<?php		      				foreach ($_SESSION['user'] as $val) {		      					?>		      					<option><?= $val ?>		      					<?php		      				}		      				?>		    			</select>		    			<label>Lanceur enregistré</label>		        	</div>		      	</div>		    </div>		</div>		<div class="row">			<div class="col m6 s12">				<div class="row">		        	<div class="input-field col s12">		      			<select name="roll">		      				<option selected>100</option>		      				<?php		      				for($i = 90; $i > 0; $i -= 10){		      					?>		      					<option><?= $i ?></option>		      					<?php		      				}		      				?>		    			</select>		    			<label>Valeur</label>		    		</div>		    	</div>		    </div>		    <div class="col m4 s12 center" style="margin-top: 2em">		    	<label>        			<input type="checkbox" name="hide">        			<span>Cacher le resultat</span>      			</label>		    </div>		</div>		<div class="row center">			<div class="col s12">				<button id="valid" type="button" class="waves-effect waves-light btn" style="margin-top: 1em"><i class="material-icons right">check</i>Valider</button>			</div>		</div>	</form>	<div class="row">		<div class="col s12 center">			<h3><i>Historique</i></h3>		</div>	</div>	<div class="row">		<div class="col s12">			<table class="responsive-table">				<thead>					<tr>						<td><b>Lanceur</b></td>						<td><b>Valeur</b></td>						<td><b>Dé</b></td>					</tr>				</thead>				<tbody id="tbody">					<?php					$roll = array_reverse($_SESSION['roll']);					foreach ($roll as $val) {						?>						<tr>							<td><?= $val['name'] ?></td>							<td><?= $val['roll'] ?></td>							<td><?= $val['dice'] ?></td>						</tr>						<?php					}					?>				</tbody>			</table>		</div>	</div></main><input type="hidden" id="msg" data-type="<?= $type ?>" value="<?= $value ?>"><?phprequire 'footer.php';
 |