ADD support des inscriptions terminées
[cl7.git] / php / connexion.php
1 <?php
2 /*
3 * Connexion à la base de donnée + résolutiondu participant.
4 * Produit une variable globale nommée '$le_participant'.
5 */
6
7 if (!file_exists("php/config_bd.php")) {
8 echo "Le fichier 'php/config_bd.php' n'existe pas, création en cours...\n";
9 if (!is_writable("."))
10 {
11 echo "Le dossier 'php' n'est pas accessible en écriture, veuillez changer les droits et recommencer.";
12 exit();
13 }
14 $f = fopen("php/config_bd.php", "w");
15 fwrite($f, '<?php # encoding:utf-8
16 # Parametres de connexion MySQL
17 $SQL_HOTE = "localhost";
18 $SQL_LOGIN = "";
19 $SQL_PASS = "";
20 $NOM_BASE = "corcelles_lan7";?>'
21 );
22 fclose($f);
23 echo "Le fichier a été créé, veuillez le compléter et recommencer.";
24 exit();
25 }
26
27 include_once("config_bd.php");
28 include_once("class_participant.php");
29
30 $lien_mysql = mysql_connect($SQL_HOTE, $SQL_LOGIN, $SQL_PASS);
31 if (!$lien_mysql || !mysql_select_db($NOM_BASE))
32 {
33 echo "Connexion à la base de données impossible. Voir le fichier 'php/config_bd.php'";
34 exit();
35 }
36
37 mysql_set_charset("UTF8");
38 mysql_query('SET AUTOCOMMIT=0');
39
40 if (isset($_POST['effacer_cookie'])) # le membre se délogue
41 {
42 setcookie("COOKIE_INFO_PATICIPANT", "", time() - 100); # 'efface' le cookie membre
43 unset($HTTP_COOKIE_VARS["COOKIE_INFO_PATICIPANT"]);
44 unset($log);
45 }
46
47 if (isset($_POST['log'])) # le membre se logue
48 {
49 $le_participant = new Participant($_POST['pseudo'], $_POST['password']);
50 if ($le_participant->valide)
51 {
52 setcookie ("COOKIE_INFO_PATICIPANT", $le_participant->info->id, time() + 31104000);
53 }
54 }
55 else if (isset($HTTP_COOKIE_VARS["COOKIE_INFO_PATICIPANT"])) # le cookie existe deja chez le participant
56 {
57 $le_participant = new Participant($HTTP_COOKIE_VARS["COOKIE_INFO_PATICIPANT"]);
58 }
59 else
60 {
61 $le_participant = new Participant();
62 }
63
64 ?>