Jeu frise chronologique en xml

Description

Ceci est un jeu qui consiste a retrouver l'ordre chronologique des cartes proposées.
Pour l'exemple, il s'agit des présidents francais.
Mais n'importe quelle liste peut etre ajouter (les inventions, les rois de france, les chansons ...)

Ce jeu est en PHP et XML (dom xpath) et ne fait pas appel a une base de donnée.

Pour ajouter une nouvelle categorie il suffit de proceder comme suit
Par exemple si la categorie s'appelle "xxxxxx"

1) Il faut ajouter une image appelée livre_xxxxxx.jpg
(image sur laquelle on clique pour afficher la carte suivante)

2) il faut creer le fichier xml xxxxxx_init.xml
sur le modèle de celui fourni (presidents_init.xml)
avec les noeuds suivant
<jeu>
<frises>
</frises>
<cartes>
<carte id="année" label="nom court">
<image> image affichée> /image>
<nom> nom long </nom>
</carte>
liste des cartes (pas forcement ordonnées)
</cartes>
</jeu>

3) Il faut creer un répertoire xxxxxx dans lequel
vous déposerez toutes les images correspondantes a votre frise
Ces images sont affichés en 100 * 100, il est donc préférable
de mettre des images de cette taille environ

Source / Exemple :


<?php
session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
    <title> FRISES DU TEMPS </title>
	  
    <style>
        body    {background-color: #AFEEEE; background-image:url(fond_frise.jpg);}
        .title  {font-family: Arial; font-size: 20px; color: #3300ff}
    </style>
</head>

<body>
 <center>
  <h1> Frise du temps </h1>
 </center>

 <form name="frmFrise" action="" method="post"  >
    
 <?php 
	global $msgErr;
  $msgErr = "";
 
if (!empty($_POST)) {
  if (isset($_POST['sPseudo'])) {
  	if (!$_POST['pseudo'] == '') {
  	 	 if( preg_match('#^[a-z0-9_-]{3,16}$#i', $_POST['pseudo']) ) {	     // verif du pseudo saisie
  			$_SESSION['user_pseudo'] = $_POST['pseudo'];
  	 	}else {
   	 	  $msgErr = 'Pseudo non valide ';
  	 	}
  	}
  }
 	if (isset($_POST['cmd_New'])) {
		init_partie();
  } 
 	if (isset($_POST['sCateg'])) {
			if ($_SESSION['categ_frise'] != $_POST['sCateg']){
				$_SESSION['categ_frise'] = $_POST['sCateg'];
 	    	verif_partie_en_cours();
	    }	
  } 

 	if (isset($_POST['SelFr'])) {
	    $_SESSION['no_frise']=$_POST['SelFr'];
	}
 	if (isset($_POST['Cnext'])) {
 		if ($_SESSION['no_frise'] > 1) {
 	    $_SESSION['no_frise']--;
 	  }	
  } 
 	if (isset($_POST['Cprevious'])) {
 		// tester le maxi ?
 	    $_SESSION['no_frise']++;	
  } 
 
 	if (isset($_POST['cmdA'])) {
 		if ($_SESSION['no_carte'] > 0) {
 	    test_reponse('Avant');	
 	   } else {
 	   	$msgErr = 'selectionnez une carte ';
 	  }
  } 
 	if (isset($_POST['cmdP'])) {
 		if ($_SESSION['no_carte'] > 0) {
 	    test_reponse('Apres');	
 	   } else {
 	   	$msgErr = 'selectionnez une carte ';
 	  }
  } 
  if (isset($_POST['cmd_carte_x'])) {    	// _x car bouton image (retourne position x et y)
 	    sel_new_carte();	
  } 
} 

if (!isset($_SESSION['user_pseudo'])) {
	    test_pseudo();												// init du pseudo
}

	echo '<table border="0"> ';
	echo '  <tr> ';
	echo '    <td width="30%"> ';
    	
    	// affichage du pseudo
  echo '   Votre Pseudo : '.strtoupper($_SESSION['user_pseudo']);
     	 // selection de la categorie  
  echo '<br><br>';
  echo 'Categorie';
   echo ' <select name="sCateg" onchange="submit()">';   
  	  	 affListeCateg();	   
	echo '  </select> ';
 	echo '    </td> ';

if (!isset($_SESSION['no_carte'])) {
   	    verif_partie_en_cours();
}
	
	 // affichage de la table des scores	
	echo '    <td width="50%"> ';
	echo '    <table border="1"> ';
	echo '    <caption>  Tableau des scores </caption>';
	echo '      <tr> ';
	echo '        <th>  Categorie </th>';
	echo '        <th>  Nb cartes </th>';
	echo '        <th>  Nb trouvees </th>';
	echo '        <th>  Votre Scores </th>';
	echo '        <th>  Meilleur Scores </th>';
	echo '      </tr> ';
	echo '      <tr> ';
	 affich_scores();
 	echo ' 			</tr> 	';
	echo '    </table> ';
 	echo '    </td> ';
	
	 // affichage de la liste totale des scores	
	echo '  <td align="center"> ';
 	echo ' <A HREF="#" onClick="window.open(\'scores_frise.php\',\'Liste_des_scores\',\'toolbar=0, location=0, directories=0, status=0, scrollbars=0, resizable=1, copyhistory=0, menuBar=0, width=700, height=600\');return(false)">';
	echo ' <br> Voir les scores  </A> </td> ';
 	
	echo '  </tr> ';
	echo ' <tr> <td colspan="3"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <input type="submit" size="70" name="cmd_New" id="cmd_New" value="Nouvelle Partie"/>  </td> </tr>';
	
	echo '</table> ';
        echo '<br><br><br> ';
          
       
          
	 // affichage de la frise	
	 
	 echo ' <center>  ';
 	 echo ' <table border="0"> 
 	 				<tr>
 	          <th width="11%"> &nbsp; </th>
 	          <th width="11%"> &nbsp; </th>
 	          <th width="11%"> &nbsp; </th>
 	          <th >  <input type="submit" size="20" name="Cprevious" id="Cprevious" value="«"/> </th>  	
 	          <th width="11%"> &nbsp; </th>
 	          <th >  <input type="submit" size="20" name="Cnext" id="Cnext" value="»"/> </th>  	
  	        <th width="11%"> &nbsp; </th>
 	          <th width="11%"> &nbsp; </th>
 	          <th width="11%"> &nbsp; </th>
	         </tr>
	         <tr>   ';
 	 	    affich_frise();	
    echo ' </tr> 
					</table> ';
	    
 
 	 // affichage du message d'erreur eventuel	
           echo '<br> <br>';
           echo '<b> '.$msgErr.' </b>';
         echo '<br> <br>';
 
 	 // affichage du livre ou de la selection	
 	 		if ($_SESSION['no_carte'] == 0) { 
	       affich_livre();
	     } else {
					affich_carte();
			 }
    	?>

    <br>
    </form>
    
  </body>

</html>
     
          

  <?php 

function verif_partie_en_cours() {
//-----------------------------
	global $msgErr;
  $xmlfile = strtoupper($_SESSION['user_pseudo']).'_'.$_SESSION['categ_frise'].'.xml';
	if (file_exists($xmlfile)) {
		 // sauvegarde variable de session
  	$_SESSION['no_frise'] = 1; 
  	$_SESSION['no_carte'] = 0; 
	} else {
		init_partie();
	}
}		

function init_partie() {
//---------------------
		global $msgErr;
		
 // copie du modele xml pour le user 
   $xmlfileInit = $_SESSION['categ_frise'].'_init.xml';
   $xmlfile = strtoupper($_SESSION['user_pseudo']).'_'.$_SESSION['categ_frise'].'.xml';
  if (!copy($xmlfileInit, $xmlfile)) {
   echo "La copie du fichier xml :".$xmlfileInit." n'a pas réussi ...\n";
  }
  
  $dom = new DomDocument();
  $dom->load($xmlfile);
  $xpath = new DOMXPath($dom);

 $nbTot = $xpath->query('//cartes/carte')->length;

 // Choix de la premiere carte 
  $noChx = mt_rand(1,$nbTot);

// copie de la premiere carte dans la frise 
	$nodeCarte = $xpath->query('//cartes/carte['.$noChx.']')->item(0);    // recup carte
	$newfrise=$nodeCarte->cloneNode(true);																// clonage (copie)
	$nodeCarte->parentNode->removeChild($nodeCarte);											// suppression de la liste cartes
  $xpath->query('//frises')->item(0)->appendChild($newfrise);						// ajout dans la frise
  $dom->save($xmlfile);																									// sauvegarde fichier

 // sauvegarde variable de session
  $_SESSION['no_frise'] = 1; 
  $_SESSION['no_carte'] = 0; 
 
   maj_score('new',0);
}

function 	affich_frise(){
//---------------------
  $xmlfile = strtoupper($_SESSION['user_pseudo']).'_'.$_SESSION['categ_frise'].'.xml';
  $dom = new DomDocument();
  $dom->load($xmlfile);
  $xpath = new DOMXPath($dom);
  $nbTot = $xpath->query('//frises/carte')->length;

  $noChx = $_SESSION['no_frise'];

	// cartes precedentes    

	$i=$noChx-3;
	while($i < $noChx)  {
		if ($i >=1) {
			$nosuiv=$i;
			$noAff=$i;
  		$nomIDSuiv = $xpath->query('//frises/carte['.$nosuiv.']/@id')->item(0)->nodeValue;
			$nomCarteSuiv = $xpath->query('//frises/carte['.$nosuiv.']/nom')->item(0)->nodeValue;
			$nomImageSuiv = $xpath->query('//frises/carte['.$nosuiv.']/image')->item(0)->nodeValue;
  		echo '  <td valign="top"> <table><tr><th>'.$nomIDSuiv.'</th></tr><tr><td>	<img SRC="'.$_SESSION['categ_frise'].'/'.$nomImageSuiv.'"  border="0"  height="100" width="100" > </td></tr><tr><td> '.$nomCarteSuiv.'</td></tr></table> </td> ';
  	}else{
  		echo '<td> &nbsp; </td> ';
  	}
   	$i++;
	}

   // bouton preced
    echo ' 				 <td>  <input type="submit" size="50" name="cmdA" id="cmdA" value="AVANT"/> </td>  ';

	// carte en cours    
	$nomIDChoisie = $xpath->query('//frises/carte['.$noChx.']/@id')->item(0)->nodeValue;
  $nomCarteChoisie = $xpath->query('//frises/carte['.$noChx.']/nom')->item(0)->nodeValue;
  $nomImageChoisie = $xpath->query('//frises/carte['.$noChx.']/image')->item(0)->nodeValue;
 	echo ' <td valign="top"> <table><tr><th>'.$nomIDChoisie.'</th></tr><tr><td>	<img SRC="'.$_SESSION['categ_frise'].'/'.$nomImageChoisie.'"  border="0"  height="100" width="100" > </td></tr><tr><td> '.$nomCarteChoisie.'</td></tr></table> </td> ';

		  // bouton suiv
	 echo '    			 <td>  <input type="submit" size="50" name="cmdP" id="cmdP" value="APRES"/> </td>  	';

	// cartes suivantes    
		 
	$i=1;
	while(($noChx + $i <= $nbTot) and $i <=3) {
		$nosuiv=$noChx+$i;
		$noAff=$noChx+$i;
  	$nomIDSuiv = $xpath->query('//frises/carte['.$nosuiv.']/@id')->item(0)->nodeValue;
		$nomCarteSuiv = $xpath->query('//frises/carte['.$nosuiv.']/nom')->item(0)->nodeValue;
		$nomImageSuiv = $xpath->query('//frises/carte['.$nosuiv.']/image')->item(0)->nodeValue;
 		echo ' <td valign="top"> <table><tr><th>'.$nomIDSuiv.'</th></tr><tr><td>	<img SRC="'.$_SESSION['categ_frise'].'/'.$nomImageSuiv.'"  border="0"  height="100" width="100" > </td></tr><tr><td> '.$nomCarteSuiv.'</td></tr></table> </td> ';
   	$i++;
	}	    			
}

function 	affich_livre(){
//---------------------
	$msgInfos = 'Cliquez sur le livre pour choisir une nouvelle carte' ;    
	echo '<table border="0" width="70%">  
	        <tr> <td align="center"> <input border="0" height="100" width="100" src="livre_'.$_SESSION['categ_frise'].'.jpg" type=image name="cmd_carte" id="cmd_carte" align="middle" >   </td>  
	             <td align="center" width="60%">'.$msgInfos.'</td>
	        </tr>
	        <tr> <td> &nbsp; </td> <td> &nbsp; 	</td> 	</tr> 
				</table> ';
}

function  sel_new_carte(){
//---------------------
	global $msgErr;

  $xmlfile = strtoupper($_SESSION['user_pseudo']).'_'.$_SESSION['categ_frise'].'.xml';

 // Choix de la prochaine carte a trouver
 $dom = new DomDocument();
 $dom->load($xmlfile);
 $xpath = new DOMXPath($dom);

 $nbTot = $xpath->query('//cartes/carte')->length;
 if ($nbTot == 0) {
 	 $msgErr = 'Partie TERMINEE';
 } else {
 		$noChx = mt_rand(1,$nbTot);
  	$_SESSION['no_carte'] = $noChx; 
 }
}	

function 	affich_carte(){
//---------------------
  $xmlfile = strtoupper($_SESSION['user_pseudo']).'_'.$_SESSION['categ_frise'].'.xml';
  
  $dom = new DomDocument();
  $dom->load($xmlfile);
  $xpath = new DOMXPath($dom);
  $noChx = $_SESSION['no_carte'];
  $nomImageChoisie = $xpath->query('//cartes/carte['.$noChx.']/image')->item(0)->nodeValue;
  $nomCarteChoisie = $xpath->query('//cartes/carte['.$noChx.']/nom')->item(0)->nodeValue;

  $nbFrise = $xpath->query('//frises/carte')->length;
 	$nomIDInit = $xpath->query('//frises/carte[1]/@id')->item(0)->nodeValue;

	$msgAnnee='&nbsp;'; 
	if ($nbFrise == 1) {
		$msgInfos = 'Positionnez la carte dans la frise <br /> AVANT ou APRES &nbsp;&nbsp;'.$nomIDInit ;   
	} else {
		$msgInfos = 'Servez vous des boutons &nbsp;&nbsp; « &nbsp;&nbsp; et &nbsp;&nbsp;  »  <br /> pour vous positionnez dans la frise';    
		if ($nbFrise > 2) {
				$msgInfos = $msgInfos.' <br /> ou selectionner une annee';  
				$msgAnnee='<select name="SelFr" size="5" onchange="submit()">'; 
				$nodes = $xpath->query('//frises/carte');
				$pos=0;
				foreach ($nodes as $node) {
					$pos++;
					if ($pos == $_SESSION['no_frise']) {
						$msgAnnee=$msgAnnee.'<option value='.$pos.' selected >'.$node->getAttribute('id').'&nbsp;&nbsp;'.$node->getAttribute('label');
					} else {
						$msgAnnee=$msgAnnee.'<option value='.$pos.'>'.$node->getAttribute('id').'&nbsp;&nbsp;'.$node->getAttribute('label');
					}
        }
				$msgAnnee=$msgAnnee.'</select>';
    }
	}

	echo '<table border="0" width="80%">  
	        <tr> <td align="center"> <img SRC="'.$_SESSION['categ_frise'].'/'.$nomImageChoisie.'"   border="0"  height="100" width="100" >  </td> 
	             <td align="center" width="50%">'.$msgInfos.'</td> 
	             <td align="center" width="20%">'.$msgAnnee.'</td> 
	        </tr> 
	        <tr> <td align="center"> '.$nomCarteChoisie.'  	</td> <td colspan="2"> &nbsp; </td> 	</tr> 
				</table> ';
}

function  test_reponse($sReponse) {	
//------------------------------
	global $msgErr;
  $xmlfile = strtoupper($_SESSION['user_pseudo']).'_'.$_SESSION['categ_frise'].'.xml';
  $dom = new DomDocument();
  $dom->load($xmlfile);
  $xpath = new DOMXPath($dom);
 
  $noChx = $_SESSION['no_carte'];
  $noCen = $_SESSION['no_frise'];
  $nbMax = $xpath->query('//frises/carte')->length;

   //controle reponse
   // lecture carte a positionner
   // lecture frise centre, precedent et suivant
   // si AVANT lecture precedent
   //     - si date comprise entre précedent et centre : OK
   //     - sinon KO
   // sinon lecture suivant
   //     - si date comprise entre centre et suivant : OK
   //     - sinon KO

 	$nomIDCarte = $xpath->query('//cartes/carte['.$noChx.']/@id')->item(0)->nodeValue;
 	$nomCarte = $xpath->query('//cartes/carte['.$noChx.']/nom')->item(0)->nodeValue;
 	$nomIDCentre = $xpath->query('//frises/carte['.$noCen.']/@id')->item(0)->nodeValue;

  if ($sReponse =='Avant') {
	  	if ($noCen > 1) {
  			$noPrev = $noCen - 1;
 				$nomIDPrev = $xpath->query('//frises/carte['.$noPrev.']/@id')->item(0)->nodeValue;
      	$msgErr = 'Proposition : '.$nomCarte.' entre '.$nomIDPrev.' et '.$nomIDCentre;
  		}else {
  			$nomIDPrev = -100000000;												// valeur maxi arbitraire
      	$msgErr = 'Proposition : '.$nomCarte.' avant '.$nomIDCentre;
  		}
    	if (($nomIDCarte > $nomIDPrev) and ($nomIDCarte < $nomIDCentre)){ 
 	      $msgErr = $msgErr.'  Reponse CORRECTE';
 	       maj_score('maj',1);
 	  	} else {
 	      $msgErr = $msgErr.'  Reponse FAUSSE  ' ;
 	       maj_score('maj',0);
 	  	}
 	} else {
 		  if ($noCen < $nbMax) {
  			$noSuiv = $noCen + 1;
 				$nomIDSuiv = $xpath->query('//frises/carte['.$noSuiv.']/@id')->item(0)->nodeValue;
      	$msgErr = 'Proposition : '.$nomCarte.' entre '.$nomIDCentre.' et '.$nomIDSuiv;
  		}else {
  			$nomIDSuiv = +100000000;											// valeur maxi arbitraire
      	$msgErr = 'Proposition : '.$nomCarte.' apres '.$nomIDCentre;  			
  		}
    	if (($nomIDCarte > $nomIDCentre) and ($nomIDCarte < $nomIDSuiv)){ 
 	      $msgErr = $msgErr.'  Reponse CORRECTE';
 	       maj_score('maj',1);
 	  	} else {
 	      $msgErr = $msgErr.'  Reponse FAUSSE  ' ;
 	      maj_score('maj',0);
 	  	}
 	}
 	
 	// deplacement de la carte dans la frise

 	$nodeCarte = $xpath->query('//cartes/carte['.$noChx.']')->item(0);    // recup carte
	$newfrise=$nodeCarte->cloneNode(true);																// clonage (copie)
	$nodeCarte->parentNode->removeChild($nodeCarte);											// suppression de la liste cartes
																																				// positionnement dans la frise
	$nodes = $xpath->query('//frises/carte');
	$refNode = null;
	$pos=0;
	foreach ($nodes as $node) {
		$pos++;
    if ($node->getAttribute('id') > $nomIDCarte) {
    	if ($refNode == null) {
        $refNode = $node;
 				$_SESSION['no_frise'] = $pos;
       }
    }
	}
	if ($refNode != null) {
		$refNode->parentNode->insertBefore($newfrise, $refNode); 				// ajout dans la frise                                                                     
	} else {
    $xpath->query('//frises')->item(0)->appendChild($newfrise);			// ajout dans la frise (a la fin)
		$_SESSION['no_frise'] = $pos+1;
   }
  $dom->save($xmlfile);																							// sauvegarde fichier

 $_SESSION['no_carte'] = 0;
}

function 	 affich_scores(){
//-------------------------	
  $xmlscores = 'scores_frises.xml';
  $domSc = new DomDocument();
  $domSc->load($xmlscores);
  $xpath = new DOMXPath($domSc);
	$idJoueur=strtoupper($_SESSION['user_pseudo']);
	$nb_en_cours = $xpath->query('//jeux/'.$_SESSION['categ_frise'].'/joueur[@id="'.$idJoueur.'"]/en_cours/@nb_jeux')->item(0)->nodeValue;
	$nbok_en_cours = $xpath->query('//jeux/'.$_SESSION['categ_frise'].'/joueur[@id="'.$idJoueur.'"]/en_cours/@nb_ok')->item(0)->nodeValue;
	$score_en_cours = $xpath->query('//jeux/'.$_SESSION['categ_frise'].'/joueur[@id="'.$idJoueur.'"]/en_cours/@score')->item(0)->nodeValue;

  
  $nodes = $xpath->query('//jeux/'.$_SESSION['categ_frise'].'/joueur/meilleur');
  
  $max=0;
  $new_val=0;
  $nom_max = '';
	foreach ($nodes as $node) {
		$new_val = $node->getAttribute('score');
		if ($max < $new_val) {
			$max = $new_val;
			$nom_max = $node->parentNode->getAttribute('id');
		}
	}
  
	echo ' <td align="center">'.$_SESSION['categ_frise'].'</td> 
	       <td align="center"> '.$nb_en_cours.' </td> 
	       <td align="center"> '.$nbok_en_cours.' </td>  
         <td align="center"> '.$score_en_cours.' </td> 
	       <td align="center">  '.$max.' ('.$nom_max.') </td> ';
}

function maj_score($type,$points) {
//-------------------------------
	verif_existe_score();
	
	$xmlscores = 'scores_frises.xml';
  $domSc = new DomDocument();
  $domSc->load($xmlscores);
  $xpath = new DOMXPath($domSc);

	$idJoueur=strtoupper($_SESSION['user_pseudo']);
	$nb_en_cours = $xpath->query('//jeux/'.$_SESSION['categ_frise'].'/joueur[@id="'.$idJoueur.'"]/en_cours/@nb_jeux')->item(0)->nodeValue;
	$nbok_en_cours = $xpath->query('//jeux/'.$_SESSION['categ_frise'].'/joueur[@id="'.$idJoueur.'"]/en_cours/@nb_ok')->item(0)->nodeValue;
 
// calcul nouvelles valeurs
  if($type=='new') {
		$nb_en_cours = 0;  															
		$nbok_en_cours = 0;		
		$score_en_cours = 0 ;  
  } else {
		$nb_en_cours++;  																			// increment nombre de cartes jouées
		$nbok_en_cours = $nbok_en_cours + $points;						// mise a jour nbOK 
		/*  calcul score =  pourcentage (nb_ok/nb_jeux*100) * nb_ok  ex ((4/10*100)*10)= 160 
	                                                                 ex ((4/15*100)*15)= 106 */
		$score_en_cours = round((($nbok_en_cours / $nb_en_cours) *100) * $nbok_en_cours) ;  
	}

// reecriture des donnees
		$nodeEncours = $xpath->query('//jeux/'.$_SESSION['categ_frise'].'/joueur[@id="'.$idJoueur.'"]/en_cours');
		$nodeEncours->item(0)->setAttribute("nb_jeux", $nb_en_cours);
		$nodeEncours->item(0)->setAttribute("nb_ok", $nbok_en_cours);
		$nodeEncours->item(0)->setAttribute("score", $score_en_cours);

// verification si meilleur score depassé
		$meilleur_score = $xpath->query('//jeux/'.$_SESSION['categ_frise'].'/joueur[@id="'.$idJoueur.'"]/meilleur/@score')->item(0)->nodeValue;
		if($score_en_cours > $meilleur_score){
			$nodeMeilleur = $xpath->query('//jeux/'.$_SESSION['categ_frise'].'/joueur[@id="'.$idJoueur.'"]/meilleur');
			$nodeMeilleur->item(0)->setAttribute("nb_jeux", $nb_en_cours);
			$nodeMeilleur->item(0)->setAttribute("nb_ok", $nbok_en_cours);
			$nodeMeilleur->item(0)->setAttribute("score", $score_en_cours);
		}

// sauvegardes modif	
  $domSc->save($xmlscores);																							
	
}

function verif_existe_score() {
//--------------------------
	
	$xmlscores = 'scores_frises.xml';
  $domSc = new DomDocument();
  $domSc->load($xmlscores);
  $xpath = new DOMXPath($domSc);

	$idJoueur=strtoupper($_SESSION['user_pseudo']);
	
	
// verification si la categorie existe creation si n'existe pas
	$jeu = $xpath->query('//jeux/'.$_SESSION['categ_frise'])->length;
  if ($jeu == 0){
  	$nouveauJeu = $_SESSION['categ_frise'];
		$categ = $domSc->createElement($nouveauJeu);
  	$parent = $xpath->query('//jeux')->item(0);
		$parent->appendChild($categ);
  	$domSc->save($xmlscores);																							
	}

// verification si joueur existe
	$joueur = $xpath->query('//jeux/'.$_SESSION['categ_frise'].'/joueur[@id="'.$idJoueur.'"]')->length;
// Creation utilisateur ou lecture des scores en cours si l'utilisateur existe
  if ($joueur == 0){
  	// creation d'un node joueur suivant le modele
		$nodeModele = $xpath->query('//modeles/joueur')->item(0);    															// recup carte
		$newjoueur=$nodeModele->cloneNode(true);																									// clonage (copie)

		$nodeJeux = $xpath->query('//jeux/'.$_SESSION['categ_frise']);
		$nodeJeux->item(0)->appendChild($newjoueur); 	
		$nodeJoueur = $xpath->query('//jeux/'.$_SESSION['categ_frise'].'/joueur[@id="modele"]');
		$nodeJoueur->item(0)->setAttribute("id", $idJoueur);
  	$domSc->save($xmlscores);																							
  }
}

function test_pseudo(){
//---------------------

 	global $msgErr;
  if (!isset($_SESSION['user_pseudo'])) {
   	  if (isset($_SESSION['user_name']) and ($_SESSION['user_name'] <> "Visiteur")) {
	    		$pseudo_init=$_SESSION['user_name'];
   		} else {
	    		$pseudo_init='';
   		}
      echo 'Saisissez un pseudo';	
      echo ' <input type="text" maxLength="20" size="20" name="pseudo" id="pseudo" value="'.$pseudo_init.'" />';  
      echo '<input type="submit" size="30" name="sPseudo" id="sPseudo" value="Valider"/>';
      echo ' </form> <br />'.$msgErr.' </body> </html> ';
      exit();
  }

}

function affListeCateg() {
//--------------------------

// recherche de tous les xml de categorie  (au format categ_init.xml)
	$repert = getcwd();
 	$dir = scandir($repert);
  foreach ($dir as $f) {
  	$fich=$repert.'/'.$f;
    if(is_file($fich)) {
   	  if (substr($f, strlen($f)-9) == '_init.xml') {
 					$categs=explode("_", $f);
					$categ=$categs[0];
					if (isset($_SESSION['categ_frise'])) {
	       		if($categ == $_SESSION['categ_frise']){
	       			echo ' <option selected> '.$categ ;
       			} else {
 	      			echo ' <option> '.$categ ;
 	    			 }
 	     		}else{
       			echo ' <option selected> '.$categ ;
 	     			$_SESSION['categ_frise'] = $categ;
 	     		}
 	    }
		}
	}
}

 ?>

Codes Sources

A voir également

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.