Merge ssh://git@dev.euphorik.ch/cl7
[cl7.git] / php / connexion.php
index 1c78bb0..e35e7fa 100644 (file)
@@ -1,64 +1,72 @@
-<?php
-/*
- * Connexion à la base de donnée + résolutiondu participant.
- * Produit une variable globale nommée '$le_participant'.
- */
+<?php # coding: utf-8
 
-if (!file_exists("php/config_bd.php")) {
-   echo "Le fichier 'php/config_bd.php' n'existe pas, création en cours...\n";
-   if (!is_writable("."))
-   {
-     echo "Le dossier 'php' n'est pas accessible en écriture, veuillez changer les droits et recommencer.";
-     exit();
-   }
-   $f = fopen("php/config_bd.php", "w");
-   fwrite($f, '<?php # encoding:utf-8
-      # Parametres de connexion MySQL
-      $SQL_HOTE = "localhost";
-      $SQL_LOGIN = "";
-      $SQL_PASS = "";
-      $NOM_BASE = "corcelles_lan7";?>'
-   );
-   fclose($f);
-   echo "Le fichier a été créé, veuillez le compléter et recommencer.";
-   exit();
-}
+include_once("participant.php");
 
-include_once("config_bd.php");
-include_once("class_participant.php");
-
-$lien_mysql = mysql_connect($SQL_HOTE, $SQL_LOGIN, $SQL_PASS);
-if (!$lien_mysql || !mysql_select_db($NOM_BASE))
+/*
+ * Connexion à la base de données et création du participant courant.
+ */
+class Connexion
 {
-  echo "Connexion à la base de données impossible. Voir le fichier 'php/config_bd.php'";
-  exit();
-}
+   public $participant;
+   
+   funtion Connexion()
+   {
+      if (!file_exists("php/config_bd.php")) {
+         echo "Le fichier 'php/config_bd.php' n'existe pas, création en cours...\n";
+         if (!is_writable("."))
+         {
+           echo "Le dossier 'php' n'est pas accessible en écriture, veuillez changer les droits et recommencer.";
+           exit();
+         }
+         $f = fopen("php/config_bd.php", "w");
+         fwrite($f, '<?php # encoding:utf-8
+            # Parametres de connexion MySQL
+            $SQL_HOTE = "localhost";
+            $SQL_LOGIN = "";
+            $SQL_PASS = "";
+            $NOM_BASE = "corcelles_lan7";?>'
+         );
+         fclose($f);
+         echo "Le fichier a été créé, veuillez le compléter et recommencer.";
+         exit();
+      }
+      
+      include_once("config_bd.php");
+      
+      $lien_mysql = mysql_connect($SQL_HOTE, $SQL_LOGIN, $SQL_PASS);
+      if (!$lien_mysql || !mysql_select_db($NOM_BASE))
+      {
+        echo "Connexion à la base de données impossible. Voir le fichier 'php/config_bd.php'";
+        exit();
+      }
 
-mysql_set_charset("UTF8");
-mysql_query('SET AUTOCOMMIT=0');
+      mysql_set_charset("UTF8");
+      mysql_query('SET AUTOCOMMIT=0');
 
-if (isset($_POST['effacer_cookie'])) # le membre se délogue
-{
-   setcookie("COOKIE_INFO_PATICIPANT", "", time() - 100); # 'efface' le cookie membre
-   unset($HTTP_COOKIE_VARS["COOKIE_INFO_PATICIPANT"]);
-       unset($log);
-}
+      if (isset($_POST['effacer_cookie'])) # le membre se délogue
+      {
+         setcookie("COOKIE_INFO_PATICIPANT", "", time() - 100); # 'efface' le cookie membre
+         unset($HTTP_COOKIE_VARS["COOKIE_INFO_PATICIPANT"]);
+         unset($log);
+      }
 
-if (isset($_POST['log'])) # le membre se logue
-{              
-   $le_participant = new Participant($_POST['pseudo'], $_POST['password']);
-   if ($le_participant->valide)
-   {
-      setcookie ("COOKIE_INFO_PATICIPANT", $le_participant->info->id, time() + 31104000);              
+      if (isset($_POST['log'])) # le membre se logue
+      {                
+         $this->participant = new Participant($_POST['pseudo'], $_POST['password']);
+         if ($this->participant->valide)
+         {
+            setcookie ("COOKIE_INFO_PATICIPANT", $this->participant->info->id, time() + 31104000);             
+         }
+      }
+      else if (isset($HTTP_COOKIE_VARS["COOKIE_INFO_PATICIPANT"])) # le cookie existe deja chez le participant
+      {
+         $this->participant = new Participant($HTTP_COOKIE_VARS["COOKIE_INFO_PATICIPANT"]);
+      }
+      else
+      {
+         $this->participant = new Participant();
+      }
    }
 }
-else if (isset($HTTP_COOKIE_VARS["COOKIE_INFO_PATICIPANT"])) # le cookie existe deja chez le participant
-{
-   $le_participant = new Participant($HTTP_COOKIE_VARS["COOKIE_INFO_PATICIPANT"]);
-}
-else
-{
-       $le_participant = new Participant();
-}
 
 ?>
\ No newline at end of file