New: Ajout gestion plus pointue des bookmarks:

Possibilit de mettre des bookmarks sur n'importe quelle page dolibarr mais aussi sur des pages externes.
This commit is contained in:
Laurent Destailleur 2005-08-15 15:44:44 +00:00
parent 39fdec8919
commit 850d26a897
12 changed files with 566 additions and 17 deletions

View File

@ -0,0 +1,182 @@
<?php
/* Copyright (C) 2005 Laurent Destailleur <eldy@users.sourceforge.net>
*
* 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;
}
}
}
?>

106
htdocs/bookmarks/fiche.php Normal file
View File

@ -0,0 +1,106 @@
<?php
/* Copyright (C) 2001-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2005 Laurent Destailleur <eldy@users.sourceforge.net>
*
* 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='<div class="error">'.$bookmark->error.'</div>';
}
}
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='<div class="error">'.$bookmark->error.'</div>';
}
}
llxHeader();
print_fiche_titre($langs->trans("Bookmarks"));
print 'En construction';
$db->close();
llxFooter('$Date$ - $Revision$');
?>

170
htdocs/bookmarks/liste.php Normal file
View File

@ -0,0 +1,170 @@
<?php
/* Copyright (C) 2005 Laurent Destailleur <eldy@users.sourceforge.net>
*
* 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='<div class="error">'.$bookmark->error.'</div>';
}
}
/*
* 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 "<table class=\"noborder\" width=\"100%\">";
print "<tr class=\"liste_titre\">";
//print "<td>&nbsp;</td>";
print_liste_field_titre($langs->trans("Id"),$_SERVER["PHP_SELF"],"bid","","",'align="left"',$sortfield);
print "<td>".$langs->trans("Title")."</td>";
print "<td>".$langs->trans("Link")."</td>";
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 "<td>&nbsp;</td>";
print "</tr>\n";
$var=True;
while ($i < $num)
{
$obj = $db->fetch_object($resql);
$var=!$var;
print "<tr $bc[$var]>";
// Id
print '<td align="left">';
print "<a href=\"fiche.php?id=".$obj->bid."\">".img_picto($langs->trans("ShowBookmark"),"bookmark").' '.$obj->bid."</a>";
print '</td>';
$lieninterne=0;
$title=dolibarr_trunc($obj->title,24);
$lien=dolibarr_trunc($obj->url,24);
// Title
print "<td>";
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 "<a href=\"".$obj->url."\">";
print $title;
if ($lieninterne) print "</a>";
print "</td>\n";
// Url
print "<td>";
if (! $lieninterne) print "<a href=\"".$obj->url."\">";
print $lien;
if (! $lieninterne) print "</a>";
print "</td>\n";
// Auteur
print "<td><a href='".DOL_URL_ROOT."/user/fiche.php?id=".$obj->fk_user."'>".img_object($langs->trans("ShowUser"),"user").' '.$obj->code."</a></td>\n";
// Date creation
print '<td align="center">'.dolibarr_print_date($obj->dateb) ."</td>";
// Actions
print "<td><a href=\"".$_SERVER["PHP_SELF"]."?action=delete&bid=$obj->bid\">".img_delete()."</a></td>\n";
print "</tr>\n";
$i++;
}
print "</table>";
$db->free($resql);
}
else
{
dolibarr_print_error($db);
}
$db->close();
llxFooter('$Date$ - $Revision$');
?>

View File

@ -0,0 +1,49 @@
<?php
/* Copyright (C) 2004 Laurent Destailleur <eldy@users.sourceforge.net>
*
* 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);
}
?>

View File

@ -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='<div class="error">'.$bookmark->error.'</div>';
}
}
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='<div class="error">'.$bookmark->error.'</div>';
}
}

View File

@ -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] = '<img border="0" src="'.DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/bookmark.png" alt="Bookmark" title="Bookmark">';
$head[$h][0] = DOL_URL_ROOT."/bookmarks/fiche.php?action=add&amp;socid=".$objsoc->id."&amp;urlsource=".$_SERVER["PHP_SELF"]."?socid=".$objsoc->id;
$head[$h][1] = img_picto($langs->trans("BookmarkThisPage"),'bookmark');
$head[$h][2] = 'image';
$h++;
}

View File

@ -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"));
}
/*

View File

@ -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).
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

View File

@ -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).
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

View File

@ -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"));

View File

@ -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);

View File

@ -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;