dolibarr 22.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-2022 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2014 Marcos García <marcosgdf@gmail.com>
5 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
6 * Copyright (C) 2025 MDW <mdeweerd@users.noreply.github.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
29// Load Dolibarr environment
30require '../main.inc.php';
31require_once DOL_DOCUMENT_ROOT.'/bookmarks/class/bookmark.class.php';
32
41// Load translation files required by the page
42$langs->loadLangs(array('bookmarks', 'other'));
43
44
45// Get Parameters
46$id = GETPOSTINT("id");
47$action = GETPOST("action", "alpha");
48$title = (string) GETPOST("title", "alpha");
49$url = (string) GETPOST("url", "alpha");
50$urlsource = GETPOST("urlsource", "alpha");
51$target = GETPOST("target", "alpha");
52$userid = GETPOSTINT("userid");
53$position = GETPOSTINT("position");
54$backtopage = GETPOST('backtopage', 'alpha');
55
56
57// Initialize Objects
58$object = new Bookmark($db);
59if ($id > 0) {
60 $object->fetch($id);
61}
62
63// Security check
64restrictedArea($user, 'bookmark', $object);
65
66$permissiontoread = $user->hasRight('bookmark', 'lire');
67$permissiontoadd = $user->hasRight('bookmark', 'creer');
68$permissiontodelete = ($user->hasRight('bookmark', 'supprimer') || ($permissiontoadd && $object->fk_user == $user->id)); // Can always delete its own bookmark
69
70
71
72/*
73 * Actions
74 */
75
76if (($action == 'add' || $action == 'addproduct' || $action == 'update') && $permissiontoadd) {
77 if ($action == 'update') { // Test on permission already done
78 $invertedaction = 'edit';
79 } else {
80 $invertedaction = 'create';
81 }
82
83 $error = 0;
84
85 if (GETPOST('cancel', 'alpha')) {
86 if (empty($backtopage)) {
87 $backtopage = ($urlsource ? $urlsource : ((!empty($url) && !preg_match('/^http/i', $url)) ? $url : DOL_URL_ROOT.'/bookmarks/list.php'));
88 }
89 header("Location: ".$backtopage);
90 exit;
91 }
92
93 if ($action == 'update') { // Test on permission already done
94 $object->fetch(GETPOSTINT("id"));
95 }
96 if (!empty($user->admin)) {
97 // Only an admin can choose the owner of a bookmark (the form offers no choice to the other users)
98 if (!empty($userid)) {
99 $object->fk_user = $userid;
100 }
101 } elseif ($action != 'update') {
102 // A user that is not admin creates bookmarks for himself only, whatever is posted. On update, the owner is not changed.
103 $object->fk_user = $user->id;
104 }
105 $object->title = $title;
106 $object->url = $url;
107 $object->target = $target;
108 $object->position = $position;
109
110 if (!$title) {
111 $error++;
112 setEventMessages($langs->transnoentities("ErrorFieldRequired", $langs->trans("BookmarkTitle")), null, 'errors');
113 }
114
115 if (!$url) {
116 $error++;
117 setEventMessages($langs->transnoentities("ErrorFieldRequired", $langs->trans("UrlOrLink")), null, 'errors');
118 }
119
120 if (dol_strlen($title) > 64) { // Size of the field title in database
121 $error++;
122 $langs->load("errors");
123 setEventMessages($langs->transnoentities("ErrorFieldTooLong", $langs->transnoentitiesnoconv("BookmarkTitle")), null, 'errors');
124 }
125
126 if (!$error) {
127 $object->favicon = 'none';
128
129 if ($action == 'update') { // Test on permission already done
130 $res = $object->update();
131 } else {
132 $res = $object->create();
133 }
134
135 if ($res > 0) {
136 if (empty($backtopage)) {
137 $backtopage = ($urlsource ? $urlsource : ((!empty($url) && !preg_match('/^http/i', $url)) ? $url : DOL_URL_ROOT.'/bookmarks/list.php'));
138 }
139 header("Location: ".$backtopage);
140 exit;
141 } else {
142 if ($object->errno == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
143 $langs->load("errors");
144 setEventMessages($langs->transnoentities("WarningBookmarkAlreadyExists"), null, 'warnings');
145 } else {
146 setEventMessages($object->error, $object->errors, 'errors');
147 }
148 $action = $invertedaction;
149 }
150 } else {
151 $action = $invertedaction;
152 }
153}
154
155
156
157/*
158 * View
159 */
160
161llxHeader('', '', '', '', 0, 0, '', '', '', 'mod-bookmarks page-card');
162
163$form = new Form($db);
164
165
166$head = array();
167$h = 1;
168
169$head[$h][0] = $_SERVER["PHP_SELF"].($object->id ? '?id='.$object->id : '');
170$head[$h][1] = $langs->trans("Bookmark");
171$head[$h][2] = 'card';
172$h++;
173
174$hselected = 'card';
175
176
177if ($action == 'create') {
178 /*
179 * Fact bookmark creation mode
180 */
181
182 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST" enctype="multipart/form-data">'."\n";
183 print '<input type="hidden" name="token" value="'.newToken().'">';
184 print '<input type="hidden" name="action" value="add">';
185 print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
186
187 print load_fiche_titre($langs->trans("NewBookmark"), '', 'bookmark');
188
189 print dol_get_fiche_head([], 'bookmark', '', 0, '');
190
191 print '<table class="border centpercent tableforfieldcreate">';
192
193 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>';
194 dol_set_focus('#titlebookmark');
195
196 // URL
197 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>';
198
199 // Target
200 print '<tr><td>'.$langs->trans("BehaviourOnClick").'</td><td>';
201 $liste = array(0 => $langs->trans("ReplaceWindow"), 1 => $langs->trans("OpenANewWindow"));
202 $defaulttarget = 1;
203 if ($url && !preg_match('/^http/i', $url)) {
204 $defaulttarget = 0;
205 }
206 print $form->selectarray('target', $liste, GETPOSTISSET('target') ? GETPOSTINT('target') : $defaulttarget, 0, 0, 0, '', 0, 0, 0, '', 'maxwidth300');
207 print '</td><td class="hideonsmartphone"><span class="opacitymedium">'.$langs->trans("ChooseIfANewWindowMustBeOpenedOnClickOnBookmark").'</span></td></tr>';
208
209 // Visibility / Owner
210 print '<tr><td>'.$langs->trans("Visibility").'</td><td>';
211 print img_picto('', 'user', 'class="pictofixedwidth"');
212 print $form->select_dolusers(GETPOSTISSET('userid') ? GETPOSTINT('userid') : $user->id, 'userid', 0, null, 0, ($user->admin ? '' : array($user->id)), '', '0', 0, 0, '', ($user->admin) ? 1 : 0, '', 'maxwidth300 widthcentpercentminusx');
213 print '</td><td class="hideonsmartphone"></td></tr>';
214
215 // Position
216 print '<tr><td>'.$langs->trans("Position").'</td><td>';
217 print '<input class="flat width50" name="position" value="'.(GETPOSTISSET("position") ? GETPOSTINT("position") : $object->position).'">';
218 print '</td><td class="hideonsmartphone"></td></tr>';
219
220 print '</table>';
221
222 print dol_get_fiche_end();
223
224 print $form->buttonsSaveCancel("CreateBookmark");
225
226 print '</form>';
227}
228
229
230if ($id > 0 && !preg_match('/^add/i', $action)) {
231 if ($action == 'edit') {
232 print '<form name="edit" method="POST" action="'.$_SERVER["PHP_SELF"].'" enctype="multipart/form-data">';
233 print '<input type="hidden" name="token" value="'.newToken().'">';
234 print '<input type="hidden" name="action" value="update">';
235 print '<input type="hidden" name="id" value="'.$object->id.'">';
236 print '<input type="hidden" name="urlsource" value="'.DOL_URL_ROOT.'/bookmarks/card.php?id='.$object->id.'">';
237 print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
238 }
239
240 print dol_get_fiche_head($head, $hselected, $langs->trans("Bookmark"), -1, 'bookmark');
241
242 $linkback = '<a href="'.DOL_URL_ROOT.'/bookmarks/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
243
244 dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', '', '', 0, '', '', 0);
245
246 print '<div class="fichecenter">';
247
248 print '<div class="underbanner clearboth"></div>';
249 print '<table class="border centpercent tableforfield">';
250
251 // Title
252 print '<tr><td class="titlefield">';
253 if ($action == 'edit') {
254 print '<span class="fieldrequired">';
255 }
256
257 print $langs->trans("BookmarkTitle");
258
259 if ($action == 'edit') {
260 print '</span>';
261 }
262
263 print '</td><td>';
264 if ($action == 'edit') {
265 print '<input class="flat minwidth250" name="title" value="'.(GETPOSTISSET("title") ? GETPOST("title", '', 2) : $object->title).'">';
266 } else {
267 print dol_escape_htmltag($object->title);
268 }
269 print '</td></tr>';
270
271 // URL
272 print '<tr><td>';
273 if ($action == 'edit') {
274 print '<span class="fieldrequired">';
275 }
276 print $langs->trans("UrlOrLink");
277 if ($action == 'edit') {
278 print '</span>';
279 }
280 print '</td><td class="wordbreak">';
281 if ($action == 'edit') {
282 print '<input class="flat minwidth500 quatrevingtpercent" name="url" value="'.(GETPOSTISSET("url") ? GETPOST("url") : $object->url).'">';
283 } else {
284 print '<a href="'.(preg_match('/^http/i', $object->url) ? $object->url : DOL_URL_ROOT.$object->url).'"'.($object->target ? ' target="_blank" rel="noopener noreferrer"' : '').'>';
285 print img_picto('', 'globe', 'class="paddingright"');
286 print $object->url;
287 print '</a>';
288 }
289 print '</td></tr>';
290
291 print '<tr><td>'.$langs->trans("BehaviourOnClick").'</td><td>';
292 if ($action == 'edit') {
293 $liste = array(1 => $langs->trans("OpenANewWindow"), 0 => $langs->trans("ReplaceWindow"));
294 print $form->selectarray('target', $liste, GETPOSTISSET("target") ? GETPOST("target") : $object->target);
295 } else {
296 if ($object->target == '0') {
297 print $langs->trans("ReplaceWindow");
298 }
299 if ($object->target == '1') {
300 print $langs->trans("OpenANewWindow");
301 }
302 }
303 print '</td></tr>';
304
305 // Visibility / owner
306 print '<tr><td>'.$langs->trans("Visibility").'</td><td>';
307 if ($action == 'edit' && $user->admin) {
308 print img_picto('', 'user', 'class="pictofixedwidth"');
309 print $form->select_dolusers(GETPOSTISSET('userid') ? GETPOSTINT('userid') : ($object->fk_user ? $object->fk_user : ''), 'userid', 1, null, 0, '', '', '0', 0, 0, '', 0, '', 'maxwidth300 widthcentpercentminusx');
310 } else {
311 if ($object->fk_user > 0) {
312 $fuser = new User($db);
313 $fuser->fetch($object->fk_user);
314 print $fuser->getNomUrl(-1);
315 } else {
316 print '<span class="opacitymedium">'.$langs->trans("Everybody").'</span>';
317 }
318 }
319 print '</td></tr>';
320
321 // Position
322 print '<tr><td>'.$langs->trans("Position").'</td><td>';
323 if ($action == 'edit') {
324 print '<input class="flat" name="position" size="5" value="'.(GETPOSTISSET("position") ? GETPOSTINT("position") : $object->position).'">';
325 } else {
326 print $object->position;
327 }
328 print '</td></tr>';
329
330 // Date creation
331 print '<tr><td>'.$langs->trans("DateCreation").'</td><td>'.dol_print_date($object->datec, 'dayhour').'</td></tr>';
332
333 print '</table>';
334
335 print '</div>';
336
337 print dol_get_fiche_end();
338
339 if ($action == 'edit') {
340 print $form->buttonsSaveCancel();
341
342 print '</form>';
343 }
344
345
346 // Buttons
347
348 print '<div class="tabsAction">'."\n";
349
350 // Edit
351 if ($permissiontoadd && $action != 'edit') {
352 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=edit&token='.newToken().'">'.$langs->trans("Edit").'</a>'."\n";
353 }
354
355 // Remove
356 if ($permissiontodelete && $action != 'edit') {
357 print '<a class="butActionDelete" href="list.php?id='.$object->id.'&action=delete&token='.newToken().'">'.$langs->trans("Delete").'</a>'."\n";
358 }
359
360 print '</div>';
361}
362
363// End of page
364llxFooter();
365$db->close();
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:48
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:67
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
print $object position
Definition edit.php:206
Class to manage bookmarks.
Class to manage generation of HTML components Only common components must be here.
Class to manage Dolibarr users.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_set_focus($selector)
Set focus onto field with selector (similar behaviour of 'autofocus' HTML5 tag)
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
restrictedArea(User $user, $features, $object=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.