dolibarr  16.0.5
card.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2001-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2005-2015 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2014 Marcos GarcĂ­a <marcosgdf@gmail.com>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <https://www.gnu.org/licenses/>.
18  */
19 
27 require '../main.inc.php';
28 require_once DOL_DOCUMENT_ROOT.'/bookmarks/class/bookmark.class.php';
29 
30 // Load translation files required by the page
31 $langs->loadLangs(array('bookmarks', 'other'));
32 
33 // Security check
34 if (empty($user->rights->bookmark->lire)) {
35  restrictedArea($user, 'bookmarks');
36 }
37 
38 $id = GETPOST("id", 'int');
39 $action = GETPOST("action", "alpha");
40 $title = (string) GETPOST("title", "alpha");
41 $url = (string) GETPOST("url", "alpha");
42 $urlsource = GETPOST("urlsource", "alpha");
43 $target = GETPOST("target", "int");
44 $userid = GETPOST("userid", "int");
45 $position = GETPOST("position", "int");
46 $backtopage = GETPOST('backtopage', 'alpha');
47 
48 $object = new Bookmark($db);
49 if ($id > 0) {
50  $object->fetch($id);
51 }
52 
53 
54 /*
55  * Actions
56  */
57 
58 if ($action == 'add' || $action == 'addproduct' || $action == 'update') {
59  if ($action == 'update') {
60  $invertedaction = 'edit';
61  } else {
62  $invertedaction = 'create';
63  }
64 
65  $error = 0;
66 
67  if (GETPOST('cancel', 'alpha')) {
68  if (empty($backtopage)) {
69  $backtopage = ($urlsource ? $urlsource : ((!empty($url) && !preg_match('/^http/i', $url)) ? $url : DOL_URL_ROOT.'/bookmarks/list.php'));
70  }
71  header("Location: ".$backtopage);
72  exit;
73  }
74 
75  if ($action == 'update') {
76  $object->fetch(GETPOST("id", 'int'));
77  }
78  // Check if null because user not admin can't set an user and send empty value here.
79  if (!empty($userid)) {
80  $object->fk_user = $userid;
81  }
82  $object->title = $title;
83  $object->url = $url;
84  $object->target = $target;
85  $object->position = $position;
86 
87  if (!$title) {
88  $error++;
89  setEventMessages($langs->transnoentities("ErrorFieldRequired", $langs->trans("BookmarkTitle")), null, 'errors');
90  }
91 
92  if (!$url) {
93  $error++;
94  setEventMessages($langs->transnoentities("ErrorFieldRequired", $langs->trans("UrlOrLink")), null, 'errors');
95  }
96 
97  if (!$error) {
98  $object->favicon = 'none';
99 
100  if ($action == 'update') {
101  $res = $object->update();
102  } else {
103  $res = $object->create();
104  }
105 
106  if ($res > 0) {
107  if (empty($backtopage)) {
108  $backtopage = ($urlsource ? $urlsource : ((!empty($url) && !preg_match('/^http/i', $url)) ? $url : DOL_URL_ROOT.'/bookmarks/list.php'));
109  }
110  header("Location: ".$backtopage);
111  exit;
112  } else {
113  if ($object->errno == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
114  $langs->load("errors");
115  setEventMessages($langs->transnoentities("WarningBookmarkAlreadyExists"), null, 'warnings');
116  } else {
117  setEventMessages($object->error, $object->errors, 'errors');
118  }
119  $action = $invertedaction;
120  }
121  } else {
122  $action = $invertedaction;
123  }
124 }
125 
126 
127 /*
128  * View
129  */
130 
131 llxHeader();
132 
133 $form = new Form($db);
134 
135 
136 $head = array();
137 $h = 1;
138 
139 $head[$h][0] = $_SERVER["PHP_SELF"].($object->id ? '?id='.$object->id : '');
140 $head[$h][1] = $langs->trans("Bookmark");
141 $head[$h][2] = 'card';
142 $h++;
143 
144 $hselected = 'card';
145 
146 
147 if ($action == 'create') {
148  /*
149  * Fact bookmark creation mode
150  */
151 
152  print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST" enctype="multipart/form-data">'."\n";
153  print '<input type="hidden" name="token" value="'.newToken().'">';
154  print '<input type="hidden" name="action" value="add">';
155  print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
156 
157  print load_fiche_titre($langs->trans("NewBookmark"), '', 'bookmark');
158 
159  print dol_get_fiche_head(null, 'bookmark', '', 0, '');
160 
161  print '<table class="border centpercent tableforfieldcreate">';
162 
163  print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans("BookmarkTitle").'</td><td><input id="titlebookmark" class="flat minwidth250" name="title" value="'.dol_escape_htmltag($title).'"></td><td class="hideonsmartphone"><span class="opacitymedium">'.$langs->trans("SetHereATitleForLink").'</span></td></tr>';
164  dol_set_focus('#titlebookmark');
165 
166  // Url
167  print '<tr><td class="fieldrequired">'.$langs->trans("UrlOrLink").'</td><td><input class="flat quatrevingtpercent minwidth500" name="url" value="'.dol_escape_htmltag($url).'"></td><td class="hideonsmartphone"><span class="opacitymedium">'.$langs->trans("UseAnExternalHttpLinkOrRelativeDolibarrLink").'</span></td></tr>';
168 
169  // Target
170  print '<tr><td>'.$langs->trans("BehaviourOnClick").'</td><td>';
171  $liste = array(0=>$langs->trans("ReplaceWindow"), 1=>$langs->trans("OpenANewWindow"));
172  $defaulttarget = 1;
173  if ($url && !preg_match('/^http/i', $url)) {
174  $defaulttarget = 0;
175  }
176  print $form->selectarray('target', $liste, GETPOSTISSET('target') ? GETPOST('target', 'int') : $defaulttarget, 0, 0, 0, '', 0, 0, 0, '', 'maxwidth300');
177  print '</td><td class="hideonsmartphone"><span class="opacitymedium">'.$langs->trans("ChooseIfANewWindowMustBeOpenedOnClickOnBookmark").'</span></td></tr>';
178 
179  // Owner
180  print '<tr><td>'.$langs->trans("Visibility").'</td><td>';
181  print img_picto('', 'user').' '.$form->select_dolusers(GETPOSTISSET('userid') ? GETPOST('userid', 'int') : $user->id, 'userid', 0, '', 0, ($user->admin ? '' : array($user->id)), '', 0, 0, 0, '', ($user->admin) ? 1 : 0, '', 'maxwidth300 widthcentpercentminusx');
182  print '</td><td class="hideonsmartphone"></td></tr>';
183 
184  // Position
185  print '<tr><td>'.$langs->trans("Position").'</td><td>';
186  print '<input class="flat width50" name="position" value="'.(GETPOSTISSET("position") ? GETPOST("position", 'int') : $object->position).'">';
187  print '</td><td class="hideonsmartphone"></td></tr>';
188 
189  print '</table>';
190 
191  print dol_get_fiche_end();
192 
193  print $form->buttonsSaveCancel("CreateBookmark");
194 
195  print '</form>';
196 }
197 
198 
199 if ($id > 0 && !preg_match('/^add/i', $action)) {
200  if ($action == 'edit') {
201  print '<form name="edit" method="POST" action="'.$_SERVER["PHP_SELF"].'" enctype="multipart/form-data">';
202  print '<input type="hidden" name="token" value="'.newToken().'">';
203  print '<input type="hidden" name="action" value="update">';
204  print '<input type="hidden" name="id" value="'.$object->id.'">';
205  print '<input type="hidden" name="urlsource" value="'.DOL_URL_ROOT.'/bookmarks/card.php?id='.$object->id.'">';
206  print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
207  }
208 
209  print dol_get_fiche_head($head, $hselected, $langs->trans("Bookmark"), -1, 'bookmark');
210 
211  $linkback = '<a href="'.DOL_URL_ROOT.'/bookmarks/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
212 
213  dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', '', '', 0, '', '', 0);
214 
215  print '<div class="fichecenter">';
216 
217  print '<div class="underbanner clearboth"></div>';
218  print '<table class="border centpercent tableforfield">';
219 
220  print '<tr><td class="titlefield">';
221  if ($action == 'edit') {
222  print '<span class="fieldrequired">';
223  }
224 
225  print $langs->trans("BookmarkTitle");
226 
227  if ($action == 'edit') {
228  print '</span>';
229  }
230 
231  print '</td><td>';
232  if ($action == 'edit') {
233  print '<input class="flat minwidth250" name="title" value="'.(GETPOSTISSET("title") ? GETPOST("title", '', 2) : $object->title).'">';
234  } else {
235  print dol_escape_htmltag($object->title);
236  }
237  print '</td></tr>';
238 
239  print '<tr><td>';
240  if ($action == 'edit') {
241  print '<span class="fieldrequired">';
242  }
243  print $langs->trans("UrlOrLink");
244  if ($action == 'edit') {
245  print '</span>';
246  }
247  print '</td><td>';
248  if ($action == 'edit') {
249  print '<input class="flat minwidth500 quatrevingtpercent" name="url" value="'.(GETPOSTISSET("url") ? GETPOST("url") : $object->url).'">';
250  } else {
251  print '<a href="'.(preg_match('/^http/i', $object->url) ? $object->url : DOL_URL_ROOT.$object->url).'"'.($object->target ? ' target="_blank" rel="noopener noreferrer"' : '').'>';
252  print img_picto('', 'globe', 'class="paddingright"');
253  print $object->url;
254  print '</a>';
255  }
256  print '</td></tr>';
257 
258  print '<tr><td>'.$langs->trans("BehaviourOnClick").'</td><td>';
259  if ($action == 'edit') {
260  $liste = array(1=>$langs->trans("OpenANewWindow"), 0=>$langs->trans("ReplaceWindow"));
261  print $form->selectarray('target', $liste, GETPOSTISSET("target") ? GETPOST("target") : $object->target);
262  } else {
263  if ($object->target == 0) {
264  print $langs->trans("ReplaceWindow");
265  }
266  if ($object->target == 1) {
267  print $langs->trans("OpenANewWindow");
268  }
269  }
270  print '</td></tr>';
271 
272  print '<tr><td>'.$langs->trans("Visibility").'</td><td>';
273  if ($action == 'edit' && $user->admin) {
274  print img_picto('', 'user').' '.$form->select_dolusers(GETPOSTISSET('userid') ? GETPOST('userid', 'int') : ($object->fk_user ? $object->fk_user : ''), 'userid', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth300');
275  } else {
276  if ($object->fk_user > 0) {
277  $fuser = new User($db);
278  $fuser->fetch($object->fk_user);
279  print $fuser->getNomUrl(1);
280  } else {
281  print '<span class="opacitymedium">'.$langs->trans("Everybody").'</span>';
282  }
283  }
284  print '</td></tr>';
285 
286  // Position
287  print '<tr><td>'.$langs->trans("Position").'</td><td>';
288  if ($action == 'edit') {
289  print '<input class="flat" name="position" size="5" value="'.(GETPOSTISSET("position") ? GETPOST("position", 'int') : $object->position).'">';
290  } else {
291  print $object->position;
292  }
293  print '</td></tr>';
294 
295  // Date creation
296  print '<tr><td>'.$langs->trans("DateCreation").'</td><td>'.dol_print_date($object->datec, 'dayhour').'</td></tr>';
297 
298  print '</table>';
299 
300  print '</div>';
301 
302  print dol_get_fiche_end();
303 
304  if ($action == 'edit') {
305  print $form->buttonsSaveCancel();
306 
307  print '</form>';
308  }
309 
310 
311  // Buttons
312 
313  print "<div class=\"tabsAction\">\n";
314 
315  // Edit
316  if ($user->rights->bookmark->creer && $action != 'edit') {
317  print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=edit&token='.newToken().'">'.$langs->trans("Edit").'</a>'."\n";
318  }
319 
320  // Remove
321  if ($user->rights->bookmark->supprimer && $action != 'edit') {
322  print '<a class="butActionDelete" href="list.php?bid='.$object->id.'&action=delete&token='.newToken().'">'.$langs->trans("Delete").'</a>'."\n";
323  }
324 
325  print '</div>';
326 }
327 
328 // End of page
329 llxFooter();
330 $db->close();
dol_escape_htmltag
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
Definition: functions.lib.php:1468
restrictedArea
restrictedArea($user, $features, $objectid=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.
Definition: security.lib.php:234
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
Bookmark
Class to manage bookmarks.
Definition: bookmark.class.php:29
load_fiche_titre
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Definition: functions.lib.php:5204
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
dol_banner_tab
dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='rowid', $fieldref='ref', $morehtmlref='', $moreparam='', $nodbprefix=0, $morehtmlleft='', $morehtmlstatus='', $onlybanner=0, $morehtmlright='')
Show tab footer of a card.
Definition: functions.lib.php:2046
dol_print_date
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
Definition: functions.lib.php:2514
img_picto
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Definition: functions.lib.php:3880
dol_get_fiche_head
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
Definition: functions.lib.php:1822
newToken
newToken()
Return the value of token currently saved into session with name 'newtoken'.
Definition: functions.lib.php:10878
dol_get_fiche_end
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition: functions.lib.php:2018
User
Class to manage Dolibarr users.
Definition: user.class.php:44
GETPOSTISSET
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
Definition: functions.lib.php:386
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
dol_set_focus
dol_set_focus($selector)
Set focus onto field with selector (similar behaviour of 'autofocus' HTML5 tag)
Definition: functions.lib.php:9379
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8137
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59