* Copyright (C) 2005-2009 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, see . */ /** * \file htdocs/bookmarks/fiche.php * \brief Page display/creation of bookmarks * \ingroup bookmark */ require("../main.inc.php"); require_once(DOL_DOCUMENT_ROOT."/bookmarks/class/bookmark.class.php"); $langs->load("other"); $action=isset($_GET["action"])?$_GET["action"]:$_POST["action"]; $title=isset($_GET["title"])?$_GET["title"]:$_POST["title"]; $url=isset($_GET["url"])?$_GET["url"]:$_POST["url"]; $target=isset($_GET["target"])?$_GET["target"]:$_POST["target"]; $userid=isset($_GET["userid"])?$_GET["userid"]:$_POST["userid"]; $position=isset($_GET["position"])?$_GET["position"]:$_POST["position"]; /* * Actions */ if ($action == 'add' || $action == 'addproduct' || $action == 'update') { if ($_POST["cancel"]) { $urlsource=(! empty($_REQUEST["urlsource"]))?$_REQUEST["urlsource"]:((! empty($url))?$url:DOL_URL_ROOT.'/bookmarks/liste.php'); header("Location: ".$urlsource); exit; } $mesg=''; $bookmark=new Bookmark($db); if ($action == 'update') $bookmark->fetch($_POST["id"]); $bookmark->fk_user=$userid; $bookmark->title=$title; $bookmark->url=$url; $bookmark->target=$target; $bookmark->position=$position; if (! $title) $mesg.=($mesg?'
':'').$langs->trans("ErrorFieldRequired",$langs->trans("BookmarkTitle")); if (! $url) $mesg.=($mesg?'
':'').$langs->trans("ErrorFieldRequired",$langs->trans("UrlOrLink")); if (! $mesg) { $bookmark->favicon='none'; if ($action == 'update') $res=$bookmark->update(); else $res=$bookmark->create(); if ($res > 0) { $urlsource=! empty($_REQUEST["urlsource"])?urldecode($_REQUEST["urlsource"]):DOL_URL_ROOT.'/bookmarks/liste.php'; header("Location: ".$urlsource); exit; } else { if ($bookmark->errno == 'DB_ERROR_RECORD_ALREADY_EXISTS') { $langs->load("errors"); $mesg='
'.$langs->trans("WarningBookmarkAlreadyExists").'
'; } else { $mesg='
'.$bookmark->error.'
'; } $action='create'; } } else { $mesg='
'.$mesg.'
'; $action='create'; } } 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"]); exit; } else { $mesg='
'.$bookmark->error.'
'; } } /* * View */ llxHeader(); $form=new Form($db); if ($action == 'create') { /* * Fact bookmark creation mode */ print '
'."\n"; print ''; print ''; print_fiche_titre($langs->trans("NewBookmark")); if ($mesg) print "$mesg
"; print ''; print ''; print ''; print ''; print ''; // Position print ''; print ''; print '
'.$langs->trans("BookmarkTitle").''.$langs->trans("SetHereATitleForLink").'
'.$langs->trans("UrlOrLink").''.$langs->trans("UseAnExternalHttpLinkOrRelativeDolibarrLink").'
'.$langs->trans("BehaviourOnClick").''; $liste=array(0=>$langs->trans("ReplaceWindow"),1=>$langs->trans("OpenANewWindow")); print $form->selectarray('target',$liste,1); print ''.$langs->trans("ChooseIfANewWindowMustBeOpenedOnClickOnBookmark").'
'.$langs->trans("Owner").''; $form->select_users(isset($_POST['userid'])?$_POST['userid']:$user->id,'userid',1); print ' 
'.$langs->trans("Position").''; print 'position).'">'; print '
'; print '   '; print ''; print '
'; print '
'; } if ($_GET["id"] > 0 && ! preg_match('/^add/i',$_GET["action"])) { /* * Fact bookmark mode or visually edition */ $bookmark=new Bookmark($db); $bookmark->fetch($_GET["id"]); dol_fiche_head($head, $hselected, $langs->trans("Bookmark"),0,'bookmark'); if ($_GET["action"] == 'edit') { print '
'; print ''; print ''; print ''; print ''; } print ''; print ''; print ''; print ''; print ''; print ''; // Position print ''; // Date creation print ''; if ($_GET["action"] == 'edit') print ''; print '
'.$langs->trans("Ref").''.$bookmark->ref.'
'.$langs->trans("BookmarkTitle").''; if ($_GET["action"] == 'edit') print 'title).'">'; else print $bookmark->title; print '
'.$langs->trans("UrlOrLink").''; if ($_GET["action"] == 'edit') print 'url).'">'; else print 'target?' target="_blank"':'').'>'.$bookmark->url.''; print '
'.$langs->trans("BehaviourOnClick").''; if ($_GET["action"] == 'edit') { $liste=array(1=>$langs->trans("OpenANewWindow"),0=>$langs->trans("ReplaceWindow")); print $form->selectarray('target',$liste,isset($_POST["target"])?$_POST["target"]:$bookmark->target); } else { if ($bookmark->target == 0) print $langs->trans("ReplaceWindow"); if ($bookmark->target == 1) print $langs->trans("OpenANewWindow"); } print '
'.$langs->trans("Owner").''; if ($_GET["action"] == 'edit' && $user->admin) { $form->select_users(isset($_POST['userid'])?$_POST['userid']:($bookmark->fk_user?$bookmark->fk_user:''),'userid',1); } else { if ($bookmark->fk_user) { $fuser=new User($db); $fuser->fetch($bookmark->fk_user); print $fuser->getNomUrl(1); } else { print $langs->trans("Public"); } } print '
'.$langs->trans("Position").''; if ($_GET["action"] == 'edit') print 'position).'">'; else print $bookmark->position; print '
'.$langs->trans("DateCreation").''.dol_print_date($bookmark->datec,'dayhour').'
   
'; if ($_GET["action"] == 'edit') print '
'; print "\n"; print "
\n"; // Edit if ($user->rights->bookmark->creer && $_GET["action"] != 'edit') { print " id."&action=edit\">".$langs->trans("Edit")."\n"; } // Remove if ($user->rights->bookmark->supprimer && $_GET["action"] != 'edit') { print " id."&action=delete\">".$langs->trans("Delete")."\n"; } print '
'; } $db->close(); llxFooter(); ?>