diff --git a/htdocs/bookmark4u.class.php b/htdocs/bookmark4u.class.php new file mode 100644 index 00000000000..a80b25189e1 --- /dev/null +++ b/htdocs/bookmark4u.class.php @@ -0,0 +1,158 @@ + + * + * 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$ + * $Source$ + */ + +/*! \file htdocs/bookmark4u.class.php + \brief Fichier de la classe bookmark4u + \author Rodolphe Quiedeville + \version $Revision$ +*/ + +class Bookmark4u +{ + var $db; + + var $id; + + /** + * \brief Constructeur de la classe + * \param $DB handler accès base de données + * \param $id id de l'utilisateur (0 par défaut) + */ + function Bookmark4u($DB, $id=0) + { + + $this->db = $DB; + $this->id = $id; + + return 1; + } + + /** + * + * + */ + function get_bk4u_uid($user) + { + + $sql = "SELECT bk4u_uid FROM ".MAIN_DB_PREFIX."bookmark4u_login"; + $sql .= " WHERE fk_user =".$user->id; + + if ($this->db->query($sql)) + { + $num = $this->db->num_rows(); + + if ($num == 0) + { + $this->uid = 0; + return 0; + } + else + { + $row = $this->db->fetch_row(0); + + $this->uid = $row[0]; + return 0; + } + + $this->db->free(); + } + else + { + return 1; + } + } + /** + * + * + * + */ + + function get_bk4u_login() + { + + $sql = "SELECT user FROM bookmark4u.bk4u_passwd"; + $sql .= " WHERE uid =".$this->uid; + + if ($this->db->query($sql)) + { + $num = $this->db->num_rows(); + + if ($num == 0) + { + return 0; + } + else + { + $row = $this->db->fetch_row(0); + + $this->login = $row[0]; + return 0; + } + + $this->db->free(); + } + else + { + return 1; + } + } + + + + /** + * \brief Créé un compte + * \param user Objet du user + * + */ + function create_account_from_user($user) + { + // TODO rendre la base et la table générique + + $sql = "INSERT INTO bookmark4u.bk4u_passwd (user, passwd, name, email)"; + $sql .= " VALUES ('$user->login',password('$user->pass'),'$user->firstname $user->name','$user->email');"; + if ($this->db->query($sql)) + { + if ($this->db->affected_rows()) + { + $this->uid = $this->db->last_insert_id(); + + $sql = "INSERT INTO ".MAIN_DB_PREFIX."bookmark4u_login"; + $sql .= " (fk_user, bk4u_uid)"; + $sql .= " VALUES ($user->id, $this->uid)"; + + $this->db->query($sql); + + return 0; + } + else + { + dolibarr_syslog("Bookmark4u::Create_account_from_user INSERT 2"); + } + } + else + { + dolibarr_syslog("Bookmark4u::Create_account_from_user INSERT 1"); + print $sql; + } + + } +} +?> diff --git a/htdocs/user/addon.php b/htdocs/user/addon.php new file mode 100644 index 00000000000..b113c0c6039 --- /dev/null +++ b/htdocs/user/addon.php @@ -0,0 +1,151 @@ + + * + * 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$ + * $Source$ + */ + +require("./pre.inc.php"); +require_once DOL_DOCUMENT_ROOT."/bookmark4u.class.php"; + +$langs->load("users"); + +$form = new Form($db); + +if ($_GET["action"] == 'create_bk4u_login') +{ + $edituser = new User($db, $_GET["id"]); + $edituser->fetch($_GET["id"]); + + $bk4u = new Bookmark4u($db); + $bk4u->get_bk4u_uid($fuser); + $bk4u->create_account_from_user($edituser); + + Header("Location: addon.php?id=".$_GET["id"]); +} + +llxHeader("","Addon Utilisateur"); + + +/* ************************************************************************** */ +/* */ +/* Nouvel utilisateur */ +/* */ +/* ************************************************************************** */ + + +if ($_GET["id"]) +{ + $fuser = new User($db, $_GET["id"]); + $fuser->fetch(); + + $bk4u = new Bookmark4u($db); + $bk4u->get_bk4u_uid($fuser); + + + /* + * Affichage onglets + */ + + $h = 0; + + $head[$h][0] = DOL_URL_ROOT.'/user/fiche.php?id='.$fuser->id; + $head[$h][1] = $langs->trans("UserCard"); + if ($_GET["action"] != 'perms') { $hselected=$h; } + $h++; + + if ($user->admin) + { + $head[$h][0] = DOL_URL_ROOT.'/user/fiche.php?action=perms&id='.$fuser->id; + $head[$h][1] = $langs->trans("Permissions"); + $h++; + } + + $head[$h][0] = DOL_URL_ROOT.'/user/addon.php?id='.$fuser->id; + $head[$h][1] = $langs->trans("Addons"); + $hselected=$h; + + $h++; + + dolibarr_fiche_head($head, $hselected, $fuser->nom." ".$fuser->prenom); + + /* + * Fiche en mode visu + */ + + print '
| '.$langs->trans("LastName").' | '; + print ''.$fuser->nom.' | '; + print ''.$langs->trans("FirstName").' | '; + print ''.$fuser->prenom.' | '; + print "
| '.$langs->trans("Login").' | '; + print ''.$fuser->login.' | '; + print ''.$langs->trans("EMail").' | '; + print ''.$fuser->email.' | '; + print "
| '.$langs->trans("Login Boobkmark4u").' | '; + print ''; + + if ($bk4u->uid == 0) + { + print "Pas de login"; + } + else + { + $bk4u->get_bk4u_login(); + print $bk4u->login; + } + + print ' | '; + print ''; + print ' | '; + print " |