* Copyright (C) 2005-2015 Laurent Destailleur * Copyright (C) 2014 Marcos GarcĂ­a * * 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 3 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/card.php * \brief Page display/creation of bookmarks * \ingroup bookmark */ require '../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/bookmarks/class/bookmark.class.php'; // Load translation files required by the page $langs->loadLangs(array('bookmarks', 'other')); // Security check if (! $user->rights->bookmark->lire) { restrictedArea($user, 'bookmarks'); } $id=GETPOST("id",'int'); $action=GETPOST("action","alpha"); $title=GETPOST("title","alpha"); $url=GETPOST("url","alpha"); $urlsource=GETPOST("urlsource","alpha"); $target=GETPOST("target","alpha"); $userid=GETPOST("userid","int"); $position=GETPOST("position","int"); $backtopage=GETPOST('backtopage','alpha'); $object=new Bookmark($db); /* * Actions */ if ($action == 'add' || $action == 'addproduct' || $action == 'update') { if ($action == 'update') { $invertedaction = 'edit'; } else { $invertedaction = 'create'; } $error = 0; if (GETPOST('cancel','alpha')) { if (empty($backtopage)) $backtopage=($urlsource?$urlsource:((! empty($url) && ! preg_match('/^http/i', $url))?$url:DOL_URL_ROOT.'/bookmarks/list.php')); header("Location: ".$backtopage); exit; } if ($action == 'update') $object->fetch(GETPOST("id",'int')); // Check if null because user not admin can't set an user and send empty value here. if(!empty($userid)) $object->fk_user=$userid; $object->title=$title; $object->url=$url; $object->target=$target; $object->position=$position; if (! $title) { $error++; setEventMessages($langs->transnoentities("ErrorFieldRequired",$langs->trans("BookmarkTitle")), null, 'errors'); } if (! $url) { $error++; setEventMessages($langs->transnoentities("ErrorFieldRequired",$langs->trans("UrlOrLink")), null, 'errors'); } if (! $error) { $object->favicon='none'; if ($action == 'update') $res=$object->update(); else $res=$object->create(); if ($res > 0) { if (empty($backtopage)) $backtopage=($urlsource?$urlsource:((! empty($url) && ! preg_match('/^http/i', $url))?$url:DOL_URL_ROOT.'/bookmarks/list.php')); header("Location: ".$backtopage); exit; } else { if ($object->errno == 'DB_ERROR_RECORD_ALREADY_EXISTS') { $langs->load("errors"); setEventMessages($langs->transnoentities("WarningBookmarkAlreadyExists"), null, 'warnings'); } else { setEventMessages($object->error, $object->errors, 'errors'); } $action = $invertedaction; } } else { $action = $invertedaction; } } /* * View */ llxHeader(); $form=new Form($db); $head = array(); $h=1; $head[$h][0] = $_SERVER["PHP_SELF"].($object->id?'id='.$object->id:''); $head[$h][1] = $langs->trans("Card"); $head[$h][2] = 'card'; $h++; $hselected='card'; if ($action == 'create') { /* * Fact bookmark creation mode */ print '
'."\n"; print ''; print ''; print load_fiche_titre($langs->trans("NewBookmark")); dol_fiche_head($head, $hselected, $langs->trans("Bookmark"), 0, 'bookmark'); print ''; print ''; dol_set_focus('#titlebookmark'); // Url print ''; // Target print ''; // Owner print ''; // Position 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").''; print $form->select_dolusers(isset($_POST['userid'])?$_POST['userid']:$user->id, 'userid', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth300'); print ' 
'.$langs->trans("Position").''; print 'position).'">'; print ' 
'; dol_fiche_end(); print '
'; print '   '; print ''; print '
'; print '
'; } if ($id > 0 && ! preg_match('/^add/i',$action)) { /* * Fact bookmark mode or visually edition */ $object->fetch($id); $hselected = 'card'; $head = array( array( '', $langs->trans('Card'), 'card' ) ); if ($action == 'edit') { print '
'; print ''; print ''; print ''; print ''; print ''; } dol_fiche_head($head, $hselected, $langs->trans("Bookmark"), -1, 'bookmark'); $linkback = ''.$langs->trans("BackToList").''; dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', '', '', 0, '', '', 0); print '
'; print '
'; print ''; print ''; print ''; print ''; print ''; // Position print ''; // Date creation print ''; print '
'; if ($action == 'edit') { print ''; } print $langs->trans("BookmarkTitle"); if ($action == 'edit') { print ''; } print ''; if ($action == 'edit') print 'title).'">'; else print $object->title; print '
'; if ($action == 'edit') { print ''; } print $langs->trans("UrlOrLink"); if ($action == 'edit') { print ''; } print ''; if ($action == 'edit') print 'url).'">'; else print 'target?' target="_blank"':'').'>'.$object->url.''; print '
'.$langs->trans("BehaviourOnClick").''; if ($action == 'edit') { $liste=array(1=>$langs->trans("OpenANewWindow"),0=>$langs->trans("ReplaceWindow")); print $form->selectarray('target',$liste,isset($_POST["target"])?$_POST["target"]:$object->target); } else { if ($object->target == 0) print $langs->trans("ReplaceWindow"); if ($object->target == 1) print $langs->trans("OpenANewWindow"); } print '
'.$langs->trans("Owner").''; if ($action == 'edit' && $user->admin) { print $form->select_dolusers(isset($_POST['userid'])?$_POST['userid']:($object->fk_user?$object->fk_user:''), 'userid', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth300'); } else { if ($object->fk_user) { $fuser=new User($db); $fuser->fetch($object->fk_user); print $fuser->getNomUrl(1); } else { print $langs->trans("Public"); } } print '
'.$langs->trans("Position").''; if ($action == 'edit') print 'position).'">'; else print $object->position; print '
'.$langs->trans("DateCreation").''.dol_print_date($object->datec,'dayhour').'
'; print '
'; dol_fiche_end(); if ($action == 'edit') { print '
   
'; print '
'; } // Buttons print "
\n"; // Edit if ($user->rights->bookmark->creer && $action != 'edit') { print " id."&action=edit\">".$langs->trans("Edit")."\n"; } // Remove if ($user->rights->bookmark->supprimer && $action != 'edit') { print " id."&action=delete\">".$langs->trans("Delete")."\n"; } print '
'; } llxFooter(); $db->close();