From 850d26a8972beb7d6d27702050095dba59237881 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 15 Aug 2005 15:44:44 +0000 Subject: [PATCH] =?UTF-8?q?New:=20Ajout=20gestion=20plus=20pointue=20des?= =?UTF-8?q?=20bookmarks:=20Possibilit=E9=20de=20mettre=20des=20bookmarks?= =?UTF-8?q?=20sur=20n'importe=20quelle=20page=20dolibarr=20mais=20aussi=20?= =?UTF-8?q?sur=20des=20pages=20externes.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- htdocs/bookmarks/bookmark.class.php | 182 ++++++++++++++++++++++ htdocs/bookmarks/fiche.php | 106 +++++++++++++ htdocs/bookmarks/liste.php | 170 ++++++++++++++++++++ htdocs/bookmarks/pre.inc.php | 49 ++++++ htdocs/comm/bookmark.php | 36 ++++- htdocs/comm/fiche.php | 4 +- htdocs/includes/menus/barre_left/eldy.php | 9 +- htdocs/langs/en_US/other.lang | 7 +- htdocs/langs/fr_FR/other.lang | 7 +- htdocs/pre.inc.php | 3 +- mysql/migration/1.1.0-2.0.0.sql | 2 + mysql/tables/llx_bookmark.sql | 8 +- 12 files changed, 566 insertions(+), 17 deletions(-) create mode 100644 htdocs/bookmarks/bookmark.class.php create mode 100644 htdocs/bookmarks/fiche.php create mode 100644 htdocs/bookmarks/liste.php create mode 100644 htdocs/bookmarks/pre.inc.php diff --git a/htdocs/bookmarks/bookmark.class.php b/htdocs/bookmarks/bookmark.class.php new file mode 100644 index 00000000000..a928fe2516e --- /dev/null +++ b/htdocs/bookmarks/bookmark.class.php @@ -0,0 +1,182 @@ + + * + * 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/bookmarks/bookmark.class.php + \ingroup bookmark + \brief Fichier de la classe des bookmark + \version $Revision$ +*/ + + +/** + \class Bookmark + \brief Classe permettant la gestion des bookmarks +*/ + +class Bookmark +{ + var $db; + + var $id; + var $fk_user; + var $datec; + var $url; + var $target; + var $title; + var $favicon; + + /** + * \brief Constructeur + * \param db Handler d'accès base de données + * \param id Id du bookmark + */ + function Bookmark($db, $id=-1) + { + $this->db = $db; + $this->id = $id; + } + + /** + * \brief Charge le bookmark + * \param id Id du bookmark à charger + */ + function fetch($id) + { + $sql = "SELECT rowid, fk_user, ".$this->db->pdate("dateb").", url, target,"; + $sql.= " title, favicon"; + $sql.= " FROM ".MAIN_DB_PREFIX."bookmark"; + $sql.= " WHERE rowid = ".$id; + + $resql = $this->db->query ($sql); + + if ($resql) + { + $obj = $this->db->fetch_object($resql); + + $this->id = $obj->rowid; + $this->fk_user = $obj->fk_user; + $this->datec = $obj->datec; + $this->url = $obj->url; + $this->target = $obj->target; + $this->title = stripslashes($obj->title); + $this->favicon = $obj->favicon; + + $this->db->free($resql); + return $this->id; + } + else + { + dolibarr_print_error ($this->db); + return -1; + } + } + + /** + * \brief Insere bookmark en base + * \param int <0 si ko, rowid si ok + */ + function create() + { + $sql = "INSERT INTO ".MAIN_DB_PREFIX."bookmark (fk_user,dateb,url,target"; + $sql.= " ,title,favicon"; + if ($this->fk_soc) $sql.=",fk_soc"; + $sql.= ")"; + $sql.= " VALUES ('".$this->fk_user."', sysdate(),"; + $sql.= " '".$this->url."', '".$this->target."',"; + $sql.= " '".addslashes($this->title)."', '".$this->favicon."'"; + if ($this->fk_soc) $sql.=",".$this->fk_soc; + $sql.= ")"; + $resql = $this->db->query ($sql); + + if ($resql) + { + $id = $this->db->last_insert_id (MAIN_DB_PREFIX."bookmark"); + + if ($id > 0) + { + $this->id = $id; + return $id; + } + else + { + $this->error=$this->db->error(); + return -2; + } + } + else + { + dolibarr_print_error ($this->db); + return -1; + } + } + + /** + * \brief Mise à jour du bookmark + * \return int <0 si ko, >0 si ok + */ + function update() + { + $sql = "UPDATE ".MAIN_DB_PREFIX."bookmark"; + $sql.= " SET fk_user = '".$this->fk_user."'"; + $sql.= " ,dateb = '".$this->datec."'"; + $sql.= " ,url = '".$this->url."'"; + $sql.= " ,target = '".$this->target."'"; + $sql.= " ,title = '".$this->title."'"; + $sql.= " ,favicon = '".$this->favicon."'"; + $sql.= " WHERE rowid = ".$this->id; + + if ($this->db->query ($sql)) + { + return 1; + } + else + { + $this->error=$this->db->error(); + return -1; + } + } + + /** + * \brief Supprime le bookmark + * \param id Id bookmark à supprimer + * \return int <0 si ko, >0 si ok + */ + function remove($id) + { + $sql = "DELETE FROM ".MAIN_DB_PREFIX."bookmark"; + $sql .= " WHERE rowid = ".$id; + + $resql=$this->db->query ($sql); + if ($resql) + { + return 1; + } + else + { + $this->error=$this->db->error(); + return -1; + } + + } + +} +?> diff --git a/htdocs/bookmarks/fiche.php b/htdocs/bookmarks/fiche.php new file mode 100644 index 00000000000..9d26c0eeba2 --- /dev/null +++ b/htdocs/bookmarks/fiche.php @@ -0,0 +1,106 @@ + + * Copyright (C) 2005 Laurent Destailleur + * + * 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/comm/bookmark.php + \brief Page affichage des bookmarks + \version $Revision$ +*/ + + +require("./pre.inc.php"); +require_once(DOL_DOCUMENT_ROOT."/bookmarks/bookmark.class.php"); + + +/* + * Actions + */ + +if ($_GET["action"] == 'add') +{ + $bookmark=new Bookmark($db); + $bookmark->fk_user=$user->id; + if ($_GET["socid"]) // Lien vers fiche comm société + { + require_once(DOL_DOCUMENT_ROOT."/societe.class.php"); + $societe=new Societe($db); + $societe->fetch($_GET["socid"]); + $bookmark->fk_soc=$societe->id; + $bookmark->url=DOL_URL_ROOT.'/comm/fiche.php?socidp='.$societe->id; + $bookmark->target=''; + $bookmark->title=$societe->nom; + } + else + { + $bookmark->url=$_GET["url"]; + $bookmark->target=$_GET["target"]; + $bookmark->title=$_GET["title"]; + } + $bookmark->favicon='xxx'; + + $res=$bookmark->create(); + if ($res > 0) + { + $urlsource=isset($_GET["urlsource"])?$_GET["urlsource"]:$_SERVER["PHP_SELF"]; + header("Location: ".$urlsource); + } + else + { + $mesg='
'.$bookmark->error.'
'; + } +} + +if ($_GET["action"] == 'delete') +{ + $bookmark=new Bookmark($db); + $bookmark->id=$_GET["bid"]; + $bookmark->url=$user->id; + $bookmark->target=$user->id; + $bookmark->title='xxx'; + $bookmark->favicon='xxx'; + + $res=$bookmark->remove(); + if ($res > 0) + { + header("Location: ".$_SERVER["PHP_SELF"]); + } + else + { + $mesg='
'.$bookmark->error.'
'; + } +} + + + +llxHeader(); + +print_fiche_titre($langs->trans("Bookmarks")); + + +print 'En construction'; + + +$db->close(); + +llxFooter('$Date$ - $Revision$'); +?> diff --git a/htdocs/bookmarks/liste.php b/htdocs/bookmarks/liste.php new file mode 100644 index 00000000000..26c124b28b6 --- /dev/null +++ b/htdocs/bookmarks/liste.php @@ -0,0 +1,170 @@ + + * + * 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/bookmarks/liste.php + \brief Page affichage des bookmarks + \version $Revision$ +*/ + +require("./pre.inc.php"); +require_once(DOL_DOCUMENT_ROOT."/bookmarks/bookmark.class.php"); + + +$page=$_GET["page"]; +$sortorder=$_GET["sortorder"]; +$sortfield=$_GET["sortfield"]; +if (! $sortorder) $sortorder="DESC"; +if (! $sortfield) $sortfield="bid"; + +if ($page == -1) { $page = 0 ; } +$limit = 26; +$offset = $limit * $page ; +$pageprev = $page - 1; +$pagenext = $page + 1; + + +/* + * Actions + */ + +if ($_GET["action"] == 'delete') +{ + $bookmark=new Bookmark($db); + $res=$bookmark->remove($_GET["bid"]); + if ($res > 0) + { + header("Location: ".$_SERVER["PHP_SELF"]); + } + else + { + $mesg='
'.$bookmark->error.'
'; + } +} + + +/* + * Affichage liste + */ + +llxHeader(); + +print_fiche_titre($langs->trans("Bookmarks")); + +if ($mesg) print $mesg; + +$sql = "SELECT b.fk_soc as idp, ".$db->pdate("b.dateb")." as dateb, b.rowid as bid, b.fk_user, b.url, b.target, b.title, b.favicon,"; +$sql.= " u.name, u.firstname, u.code"; +$sql.= " FROM ".MAIN_DB_PREFIX."bookmark as b, ".MAIN_DB_PREFIX."user as u"; +$sql.= " WHERE b.fk_user=u.rowid"; +if (! $user->admin) $sql.= " AND b.fk_user = ".$user->id; +$sql.= " ORDER BY $sortfield $sortorder " . $db->plimit( $limit, $offset); + +$resql=$db->query($sql); +if ($resql) +{ + $num = $db->num_rows($resql); + $i = 0; + + print ""; + + print ""; + //print ""; + print_liste_field_titre($langs->trans("Id"),$_SERVER["PHP_SELF"],"bid","","",'align="left"',$sortfield); + print ""; + print ""; + print_liste_field_titre($langs->trans("Author"),$_SERVER["PHP_SELF"],"u.name","","","",$sortfield); + print_liste_field_titre($langs->trans("Date"),$_SERVER["PHP_SELF"],"b.dateb","","",'align="center"',$sortfield); + print ""; + print "\n"; + + $var=True; + while ($i < $num) + { + $obj = $db->fetch_object($resql); + + $var=!$var; + print ""; + + // Id + print ''; + + $lieninterne=0; + $title=dolibarr_trunc($obj->title,24); + $lien=dolibarr_trunc($obj->url,24); + + // Title + print "\n"; + + // Url + print "\n"; + + // Auteur + print "\n"; + + // Date creation + print '"; + + // Actions + print "\n"; + + print "\n"; + $i++; + } + print "
 ".$langs->trans("Title")."".$langs->trans("Link")." 
'; + print "bid."\">".img_picto($langs->trans("ShowBookmark"),"bookmark").' '.$obj->bid.""; + print '"; + if ($obj->idp) + { + // Lien interne societe + $lieninterne=1; + $lien="Dolibarr"; + if (! $obj->title) + { + // Pour compatibilite avec anciens bookmarks + require_once(DOL_DOCUMENT_ROOT."/societe.class.php"); + $societe=new Societe($db); + $societe->fetch($obj->idp); + $obj->title=$societe->nom; + } + $title=img_object($langs->trans("ShowCompany"),"company").' '.$obj->title; + } + if ($lieninterne) print "url."\">"; + print $title; + if ($lieninterne) print ""; + print ""; + if (! $lieninterne) print "url."\">"; + print $lien; + if (! $lieninterne) print ""; + print "".img_object($langs->trans("ShowUser"),"user").' '.$obj->code."'.dolibarr_print_date($obj->dateb) ."bid\">".img_delete()."
"; + $db->free($resql); +} +else +{ + dolibarr_print_error($db); +} + + +$db->close(); + +llxFooter('$Date$ - $Revision$'); +?> diff --git a/htdocs/bookmarks/pre.inc.php b/htdocs/bookmarks/pre.inc.php new file mode 100644 index 00000000000..cb251141e56 --- /dev/null +++ b/htdocs/bookmarks/pre.inc.php @@ -0,0 +1,49 @@ + + * + * 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/bookmarks/pre.inc.php + \ingroup bookmark + \brief Fichier de gestion du menu gauche des bookmarks + \version $Revision$ +*/ + +require("../main.inc.php"); + + +function llxHeader($head = "", $title = "") +{ + global $user, $conf, $langs; + $langs->load("other"); + + top_menu($head, $title); + + $menu = new Menu(); + + // Bookmarks + $menu->add(DOL_URL_ROOT."/bookmarks/liste.php", $langs->trans("Bookmarks")); + $menu->add_submenu(DOL_URL_ROOT."/bookmarks/fiche.php?action=create", $langs->trans("NewBookmark")); + $menu->add_submenu(DOL_URL_ROOT."/bookmarks/liste.php", $langs->trans("List")); + + left_menu($menu->liste); +} +?> diff --git a/htdocs/comm/bookmark.php b/htdocs/comm/bookmark.php index 96c07aca802..23ce2fabb13 100644 --- a/htdocs/comm/bookmark.php +++ b/htdocs/comm/bookmark.php @@ -50,18 +50,42 @@ $pagenext = $page + 1; if ($_GET["action"] == 'add') { - $sql = "INSERT INTO ".MAIN_DB_PREFIX."bookmark (fk_soc, dateb, fk_user) VALUES ($socidp, now(),'". $user->login ."');"; - if (! $db->query($sql) ) + $bookmark=new Bookmark($db); + $bookmark->fk_user=$user->id; + $bookmark->url=$user->id; + $bookmark->target=$user->id; + $bookmark->title='xxx'; + $bookmark->favicon='xxx'; + + $res=$bookmark->create(); + if ($res > 0) { - print $db->error(); + header("Location: ".$_SERVER["PHP_SELF"]); + } + else + { + $mesg='
'.$bookmark->error.'
'; } } if ($_GET["action"] == 'delete') { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."bookmark WHERE rowid=".$_GET["bid"]; - if (! $user->admin) $sql .= " AND fk_user = ". $user->id; - $result = $db->query($sql); + $bookmark=new Bookmark($db); + $bookmark->id=$_GET["bid"]; + $bookmark->url=$user->id; + $bookmark->target=$user->id; + $bookmark->title='xxx'; + $bookmark->favicon='xxx'; + + $res=$bookmark->remove(); + if ($res > 0) + { + header("Location: ".$_SERVER["PHP_SELF"]); + } + else + { + $mesg='
'.$bookmark->error.'
'; + } } diff --git a/htdocs/comm/fiche.php b/htdocs/comm/fiche.php index e09dd44eba0..313981cc482 100644 --- a/htdocs/comm/fiche.php +++ b/htdocs/comm/fiche.php @@ -195,8 +195,8 @@ if ($_socid > 0) if ($user->societe_id == 0) { - $head[$h][0] = DOL_URL_ROOT."/comm/index.php?socidp=$objsoc->id&action=add_bookmark"; - $head[$h][1] = 'Bookmark'; + $head[$h][0] = DOL_URL_ROOT."/bookmarks/fiche.php?action=add&socid=".$objsoc->id."&urlsource=".$_SERVER["PHP_SELF"]."?socid=".$objsoc->id; + $head[$h][1] = img_picto($langs->trans("BookmarkThisPage"),'bookmark'); $head[$h][2] = 'image'; $h++; } diff --git a/htdocs/includes/menus/barre_left/eldy.php b/htdocs/includes/menus/barre_left/eldy.php index d6fcd0ad1ab..83af2e7be4c 100644 --- a/htdocs/includes/menus/barre_left/eldy.php +++ b/htdocs/includes/menus/barre_left/eldy.php @@ -508,8 +508,8 @@ class MenuLeft { $langs->load("admin"); $langs->load("mails"); - $newmenu->add(DOL_URL_ROOT."/comm/mailing/index.php?leftmenu=mailing", $langs->trans("EMailings"),0,$user->rights->mailing->lire); - $newmenu->add_submenu(DOL_URL_ROOT."/comm/mailing/fiche.php?leftmenu=mailing&action=create", $langs->trans("NewMailing"),1,$user->rights->mailing->creer); + $newmenu->add(DOL_URL_ROOT."/comm/mailing/index.php?leftmenu=mailing", $langs->trans("EMailings"), 0, $user->rights->mailing->lire); + $newmenu->add_submenu(DOL_URL_ROOT."/comm/mailing/fiche.php?leftmenu=mailing&action=create", $langs->trans("NewMailing"), 1, $user->rights->mailing->creer); } if ($conf->projet->enabled) @@ -519,7 +519,10 @@ class MenuLeft { $newmenu->add_submenu(DOL_URL_ROOT."/comm/clients.php?leftmenu=projects", $langs->trans("NewProject"), 1, $user->rights->projet->creer); } - $newmenu->add_submenu(DOL_URL_ROOT."/comm/bookmark.php?leftmenu=bookmarks", $langs->trans("Bookmarks"), 0, 1); + $langs->load("other"); + $newmenu->add_submenu(DOL_URL_ROOT."/bookmarks/liste.php?leftmenu=bookmarks", $langs->trans("Bookmarks"), 0, 1); + $newmenu->add_submenu(DOL_URL_ROOT."/bookmarks/fiche.php?action=create", $langs->trans("NewBookmark")); + $newmenu->add_submenu(DOL_URL_ROOT."/bookmarks/liste.php", $langs->trans("List")); } /* diff --git a/htdocs/langs/en_US/other.lang b/htdocs/langs/en_US/other.lang index 202be16733b..624b5e7d849 100644 --- a/htdocs/langs/en_US/other.lang +++ b/htdocs/langs/en_US/other.lang @@ -20,4 +20,9 @@ AttachANewFile=Attach a new file/document LinkedObject=Linked object NbOfActiveNotifications=Number of notifications WarningInstallDirExists=Warning, install directory (%s) still exists. This is a serious security hole. You should removed it as soon as possible. -WarningUntilDirRemoved=This warning will keep active while directory is present (Shown only for admin users). \ No newline at end of file +WarningUntilDirRemoved=This warning will keep active while directory is present (Shown only for admin users). +Bookmark=Bookmark +Bookmarks=Bookmarks +NewBookmark=New bookmark +ShowBookmark=Show bookmark +BookmarkThisPage=Bookmark this page \ No newline at end of file diff --git a/htdocs/langs/fr_FR/other.lang b/htdocs/langs/fr_FR/other.lang index f185cdbf343..38bc817a4cc 100644 --- a/htdocs/langs/fr_FR/other.lang +++ b/htdocs/langs/fr_FR/other.lang @@ -20,4 +20,9 @@ AttachANewFile=Ajouter un nouveau fichier/document LinkedObject=Objet lié NbOfActiveNotifications=Nombre de notifications WarningInstallDirExists=Attention, le répertoire install (%s) existe toujours. Une fois l'install terminée, sa présence n'est plus nécessaire et représente une faille sérieuse de sécurité. Vous devriez l'effacer dès que possible. -WarningUntilDirRemoved=Cette alerte restera active tant que le répertoire existera (alerte visible pour les utilisateurs admin uniquement). \ No newline at end of file +WarningUntilDirRemoved=Cette alerte restera active tant que le répertoire existera (alerte visible pour les utilisateurs admin uniquement). +Bookmark=Marque page +Bookmarks=Marque pages +NewBookmark=Nouveau marque page +ShowBookmark=Afficher marque page +BookmarkThisPage=Marquer cette page dans ces favoris \ No newline at end of file diff --git a/htdocs/pre.inc.php b/htdocs/pre.inc.php index a283756b7ff..4cd8e832dc6 100644 --- a/htdocs/pre.inc.php +++ b/htdocs/pre.inc.php @@ -132,7 +132,7 @@ function llxHeader($head = "") { $menu->add(DOL_URL_ROOT."/expedition/index.php", $langs->trans("Sendings")); } - if ($user->rights->mailing->lire) + if ($conf->mailing->enabled && $user->rights->mailing->lire) { $langs->load("mails"); $menu->add(DOL_URL_ROOT."/comm/mailing/index.php",$langs->trans("EMailings")); @@ -171,6 +171,7 @@ function llxHeader($head = "") { $menu->add(DOL_URL_ROOT."/postnuke/articles/index.php", "Editorial"); } + $menu->add(DOL_URL_ROOT."/bookmarks/liste.php", $langs->trans("Bookmarks")); $langs->load("users"); $menu->add(DOL_URL_ROOT."/user/home.php", $langs->trans("MenuUsersAndGroups")); diff --git a/mysql/migration/1.1.0-2.0.0.sql b/mysql/migration/1.1.0-2.0.0.sql index ff34c8d7170..34d69fab4a8 100644 --- a/mysql/migration/1.1.0-2.0.0.sql +++ b/mysql/migration/1.1.0-2.0.0.sql @@ -1633,6 +1633,8 @@ update llx_const set name='MAIN_EMAIL_FROM' where name='MAIN_MAIL_FROM'; alter table llx_bookmark add url varchar(128); alter table llx_bookmark add target varchar(16); +alter table llx_bookmark add title varchar(64); +alter table llx_bookmark add favicon varchar(24); diff --git a/mysql/tables/llx_bookmark.sql b/mysql/tables/llx_bookmark.sql index 6496047639c..eb54ecea747 100644 --- a/mysql/tables/llx_bookmark.sql +++ b/mysql/tables/llx_bookmark.sql @@ -22,8 +22,10 @@ create table llx_bookmark ( rowid integer AUTO_INCREMENT PRIMARY KEY, fk_soc integer, - fk_user integer, + fk_user integer NOT NULL, dateb datetime, - url varchar(128), - target varchar(16) + url varchar(128) NOT NULL, + target varchar(16), + title varchar(64), + favicon varchar(24) )type=innodb;