Objet : devel-adl
Archives de la liste
- From: svn AT agendadulibre.org
- To: devel AT agendadulibre.org
- Subject: [Devel] r428 - branches/dui
- Date: Sun, 1 Mar 2009 18:38:38 +0100 (CET)
- List-archive: <http://agendadulibre.org/pipermail/devel>
- List-id: Developpement de l'Agenda du Libre <devel.agendadulibre.org>
Author: ldayot
Date: Sun Mar 1 18:38:37 2009
New Revision: 428
Log:
Changement de nom des scripts qui sont des classes d'objet.
Added:
branches/dui/class.bd.inc.php
branches/dui/class.session.inc.php
branches/dui/class.user.inc.php
Added: branches/dui/class.bd.inc.php
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ branches/dui/class.bd.inc.php Sun Mar 1 18:38:37 2009 (r428)
@@ -0,0 +1,118 @@
+<?php
+
+/* Copyright 2005
+ * - Mélanie Bats <melanie POINT bats CHEZ utbm POINT fr>
+ * - Thomas Petazzoni <thomas POINT petazzoni CHEZ enix POINT org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ *
+ * $Id: top.inc.php,v 1.51 2007/03/10 16:22:12 ldayot Exp $
+ */
+
+include("bd-private.inc.php");
+
+/*
+ * Perform a SQL query
+ *
+ * @param[in] The SQL query to be performed
+ */
+
+
+class db
+{
+ function db()
+ {
+ global $db_host;
+ global $db_user;
+ global $db_pass;
+ global $db_name;
+
+ if(@mysql_connect($db_host,$db_user,$db_pass)==FALSE)
+ {
+ echo "Probleme de connexion à la base de données sur
$db_host.\n";
+ return 0;
+ }
+
+ if(@mysql_select_db($db_name) == FALSE)
+ {
+ echo "Problème de selection de la base de données
$db_name sur $db_host.\n";
+ return 0;
+ }
+
+ mysql_query("set names 'utf8'");
+ }
+
+ function query ($query)
+ {
+ if( ($result = @mysql_query($query)) == FALSE)
+ {
+ echo "Problème dans la syntaxe de $query : " . mysql_error() .
"\n";
+ return 0;
+ }
+
+ return $result;
+ }
+
+ function insertid ()
+ {
+ return mysql_insert_id ();
+ }
+
+ function fetchObject ($result)
+ {
+ return mysql_fetch_object($result);
+ }
+
+ function fetchArray ($result)
+ {
+ return mysql_fetch_array($result);
+ }
+
+ function fetchRow ($result)
+ {
+ return mysql_fetch_row($result);
+ }
+
+ function freeResult ($result)
+ {
+ return mysql_free_result($result);
+ }
+
+ function numRows ($result)
+ {
+ return mysql_num_rows($result);
+ }
+
+ /**
+ * Converts the argument of an SQL request in a format accepted by MySQL.
+ *
+ * @param[in] value String or integer to use as argument
+ *
+ * @return The string to use in the request
+ */
+ function quote_smart($value)
+ {
+ if (get_magic_quotes_gpc())
+ $value = stripslashes($value);
+
+ if (!is_numeric($value))
+ $value = "'" . mysql_real_escape_string($value) . "'";
+
+ return $value;
+ }
+} // end class
+
+?>
Added: branches/dui/class.session.inc.php
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ branches/dui/class.session.inc.php Sun Mar 1 18:38:37 2009 (r428)
@@ -0,0 +1,100 @@
+<?php
+
+/* Copyright 2004
+ * - Mélanie Bats <melanie POINT bats CHEZ utbm POINT fr>
+ * - Thomas Petazzoni <thomas POINT petazzoni CHEZ enix POINT org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ *
+ * $Id: top.inc.php,v 1.51 2007/03/10 16:22:12 ldayot Exp $
+ */
+
+class session
+{
+ function session()
+ {
+ session_start();
+ }
+
+ function exists($variable)
+ {
+ if(!isset($_SESSION['$variable']) OR
+ !isset($_COOKIE[$variable]) OR
+ empty($_SESSION['$variable']) OR
+ $_COOKIE[$variable]!=md5($_SESSION['$variable']))
+ return FALSE;
+ else
+ return TRUE;
+ }
+
+ function value($variable)
+ {
+ return $_SESSION['$variable'];
+ }
+
+ function set($variable,$valeur)
+ {
+ setcookie($variable,md5($valeur),time()+(24*3600));
+ $_SESSION['$variable']=$valeur;
+ }
+
+ function destroy()
+ {
+ setcookie('login','');
+ session_unset();
+ session_destroy();
+ }
+}
+
+function user_find_login ($db, $userid)
+{
+ $sql = "SELECT login FROM users WHERE id=" . $db->quote_smart($userid);
+ $ret = $db->query ($sql);
+ if ($ret == FALSE)
+ {
+ error ("La requête <i>" . $sql . "</i> a échoué");
+ return -1;
+ }
+
+ $row = $db->fetchObject ($ret);
+
+ return $row->login;
+}
+
+/*
+ * Returns a positive ID if user identified, -1 otherwise
+ */
+function user_identify ($db, $login, $password)
+{
+ $sql = "SELECT id FROM users WHERE login=" . $db->quote_smart($login) . "
AND password=" . $db->quote_smart(md5($password));
+ $ret = $db->query ($sql);
+ if ($ret == FALSE)
+ {
+ error ("Erreur lors de la requête <i>" . $sql . "</i>");
+ return -1;
+ }
+
+ if ($db->numRows ($ret) != 1)
+ {
+ return -1;
+ }
+
+ $row = $db->fetchObject($ret);
+
+ return $row->id;
+}
+
+?>
Added: branches/dui/class.user.inc.php
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ branches/dui/class.user.inc.php Sun Mar 1 18:38:37 2009 (r428)
@@ -0,0 +1,137 @@
+<?php
+
+/* Copyright 2008
+ * - Thomas Petazzoni <thomas POINT petazzoni CHEZ enix POINT org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ */
+
+class user
+{
+ var $session;
+ var $db;
+
+ /*
+ * Returns a positive ID if user identified, -1 otherwise
+ */
+ function identify ($login, $password)
+ {
+ $sql =
+ "SELECT id FROM users WHERE login=" . $this->db->quote_smart($login) .
+ " AND password=" . $this->db->quote_smart(md5($password));
+ $ret = $this->db->query ($sql);
+ if ($ret == FALSE)
+ {
+ error ("Erreur lors de la requête <i>" . $sql . "</i>");
+ return -1;
+ }
+
+ if (mysql_num_rows ($ret) != 1)
+ {
+ return -1;
+ }
+
+ $row = mysql_fetch_object($ret);
+
+ return $row->id;
+ }
+
+ function get()
+ {
+ return $this->session->value("agenda_libre_id");
+ }
+
+ function get_login()
+ {
+ $sql = "select login from users where id=" .
$this->db->quote_smart($this->session->value("agenda_libre_id"));
+ $ret = $this->db->query($sql);
+ if ($ret == FALSE)
+ {
+ error("Erreur lors de la requête <i>" . $sql . "</i>");
+ return -1;
+ }
+
+ if (mysql_num_rows($ret) != 1)
+ return -1;
+
+ $row = mysql_fetch_object($ret);
+ return $row->login;
+ }
+
+ function get_name()
+ {
+ $sql = "select firstname, lastname from users where id=" .
$this->db->quote_smart($this->session->value("agenda_libre_id"));
+ $ret = $this->db->query($sql);
+ if ($ret == FALSE)
+ {
+ error("Erreur lors de la requête <i>" . $sql . "</i>");
+ return -1;
+ }
+
+ if (mysql_num_rows($ret) != 1)
+ return -1;
+
+ $row = mysql_fetch_object($ret);
+ return $row->firstname . " " . $row->lastname;
+ }
+
+ function disconnect()
+ {
+ $this->session->destroy();
+ }
+
+ function user($db)
+ {
+ $this->session = new session();
+ $this->db = $db;
+
+ if (! $this->session->exists("agenda_libre_id"))
+ {
+ if (! isset($_POST['__user_identify']))
+ {
+ put_header("Modération");
+
+ echo "<h2>Identification</h2>";
+ echo "<table align=\"center\">";
+ echo "<form method=\"post\">\n";
+ echo "<tr><td>Login:</td><td><input type=\"text\"
name=\"__user_login\" size=\"20\"/></td></tr>";
+ echo "<tr><td>Mot de passe:</td><td><input type=\"password\"
name=\"__user_password\" size=\"20\"/></td></tr>";
+ echo "<tr><td></td><td><input type=\"submit\"
name=\"__user_identify\" value=\"Identifier\"></td></tr>";
+ echo "</form>";
+ echo "</table>";
+
+ put_footer();
+ exit;
+ }
+ else
+ {
+ if (($ret = $this->identify ($_POST['__user_login'],
$_POST['__user_password'])) > 0)
+ {
+ $this->session->set("agenda_libre_id", $ret);
+ }
+ else
+ {
+ put_header("Modération");
+ echo "Mauvais login/pass";
+ put_footer();
+ exit;
+ }
+ }
+ }
+ }
+}
+
+?>
- [Devel] r428 - branches/dui, svn, 01/03/2009
Archives gérées par MHonArc 2.6.16.