From 33ad422c765089d21c206c38ef6fbddf4799f498 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 4 Sep 2008 17:35:29 +0000 Subject: [PATCH] Fix: Error management if bookmarks added twice --- htdocs/bookmarks/bookmark.class.php | 14 +++++++--- htdocs/bookmarks/fiche.php | 40 +++++++++++++++++++---------- 2 files changed, 36 insertions(+), 18 deletions(-) diff --git a/htdocs/bookmarks/bookmark.class.php b/htdocs/bookmarks/bookmark.class.php index e158926fba1..925764dc554 100644 --- a/htdocs/bookmarks/bookmark.class.php +++ b/htdocs/bookmarks/bookmark.class.php @@ -96,6 +96,8 @@ class Bookmark */ function create() { + $this->db->begin(); + $sql = "INSERT INTO ".MAIN_DB_PREFIX."bookmark (fk_user,dateb,url,target"; $sql.= " ,title,favicon"; if ($this->fk_soc) $sql.=",fk_soc"; @@ -109,22 +111,26 @@ class Bookmark if ($resql) { - $id = $this->db->last_insert_id (MAIN_DB_PREFIX."bookmark"); - + $id = $this->db->last_insert_id(MAIN_DB_PREFIX."bookmark"); if ($id > 0) { $this->id = $id; + $this->db->commit(); return $id; } else { - $this->error=$this->db->error(); + $this->error=$this->db->lasterror(); + $this->errno=$this->db->lasterrno(); + $this->db->rollback(); return -2; } } else { - dolibarr_print_error ($this->db); + $this->error=$this->db->lasterror(); + $this->errno=$this->db->lasterrno(); + $this->db->rollback(); return -1; } } diff --git a/htdocs/bookmarks/fiche.php b/htdocs/bookmarks/fiche.php index 58907b270c0..bba707007f4 100644 --- a/htdocs/bookmarks/fiche.php +++ b/htdocs/bookmarks/fiche.php @@ -1,6 +1,6 @@ - * Copyright (C) 2005 Laurent Destailleur + * Copyright (C) 2005-2008 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 @@ -15,17 +15,14 @@ * 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/fiche.php - \brief Page affichage/creation des bookmarks - \ingroup bookmark - \version $Revision$ -*/ + * \file htdocs/bookmarks/fiche.php + * \brief Page affichage/creation des bookmarks + * \ingroup bookmark + * \version $Id$ + */ require("./pre.inc.php"); @@ -55,7 +52,7 @@ if ($action == 'add') $societe=new Societe($db); $societe->fetch($_GET["socid"]); $bookmark->fk_soc=$societe->id; - $bookmark->url=DOL_URL_ROOT.'/comm/fiche.php?socid='.$societe->id; + $bookmark->url=DOL_URL_ROOT.'/soc.php?socid='.$societe->id; $bookmark->target='0'; $bookmark->title=$societe->nom; } @@ -71,18 +68,29 @@ if ($action == 'add') if (! $mesg) { - $bookmark->favicon='xxx'; + $bookmark->favicon='none'; $res=$bookmark->create(); if ($res > 0) { $urlsource=isset($_GET["urlsource"])?$_GET["urlsource"]:DOL_URL_ROOT.'/bookmarks/liste.php'; header("Location: ".$urlsource); + exit; } else { - $mesg='
'.$bookmark->error.'
'; - $action='create'; + if ($bookmark->errno == 'DB_ERROR_RECORD_ALREADY_EXISTS') + { + $langs->load("errors"); + $mesg='
'.$langs->trans("WarningBookmarkAlreadyExists").'
'; + } + else + { + $mesg='
'.$bookmark->error.'
'; + } + $action='create'; + $title=$bookmark->title; + $url=$bookmark->url; } } else @@ -106,6 +114,7 @@ if ($_GET["action"] == 'delete') if ($res > 0) { header("Location: ".$_SERVER["PHP_SELF"]); + exit; } else { @@ -114,6 +123,9 @@ if ($_GET["action"] == 'delete') } +/* + * View + */ llxHeader(); @@ -136,7 +148,7 @@ if ($action == 'create') print ''; print ''; - print ''; + print ''; print '
'.$langs->trans("BookmarkTitle").''.$langs->trans("SetHereATitleForLink").'
'.$langs->trans("UrlOrLink").''.$langs->trans("UseAnExternalHttpLinkOrRelativeDolibarrLink").'
'.$langs->trans("UrlOrLink").''.$langs->trans("UseAnExternalHttpLinkOrRelativeDolibarrLink").'
'.$langs->trans("BehaviourOnClick").''; $liste=array(1=>$langs->trans("OpenANewWindow"),0=>$langs->trans("ReplaceWindow")); $html->select_array('target',$liste,1);