dolibarr 25.0.0-alpha
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-2025 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('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 // Check if null because user not admin can't set an user and send empty value here.
97 if (!empty($userid)) {
98 $object->fk_user = $userid;
99 }
100 $object->title = $title;
101 $object->url = $url;
102 $object->target = $target;
103 $object->position = $position;
104
105 if (!$title) {
106 $error++;
107 setEventMessages($langs->transnoentities("ErrorFieldRequired", $langs->trans("BookmarkTitle")), null, 'errors');
108 }
109
110 if (!$url) {
111 $error++;
112 setEventMessages($langs->transnoentities("ErrorFieldRequired", $langs->trans("UrlOrLink")), null, 'errors');
113 }
114
115 if (!$error) {
116 $object->favicon = 'none';
117
118 if ($action == 'update') { // Test on permission already done
119 $res = $object->update();
120 } else {
121 $res = $object->create();
122 }
123
124 if ($res > 0) {
125 if (empty($backtopage)) {
126 $backtopage = ($urlsource ? $urlsource : ((!empty($url) && !preg_match('/^http/i', $url)) ? $url : DOL_URL_ROOT.'/bookmarks/list.php'));
127 }
128 header("Location: ".$backtopage);
129 exit;
130 } else {
131 if ($object->errno == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
132 $langs->load("errors");
133 setEventMessages($langs->transnoentities("WarningBookmarkAlreadyExists"), null, 'warnings');
134 } else {
135 setEventMessages($object->error, $object->errors, 'errors');
136 }
137 $action = $invertedaction;
138 }
139 } else {
140 $action = $invertedaction;
141 }
142}
143
144
145
146/*
147 * View
148 */
149
150llxHeader('', '', '', '', 0, 0, '', '', '', 'mod-bookmarks page-card');
151
152$form = new Form($db);
153
154
155$head = array();
156$h = 1;
157
158$head[$h][0] = $_SERVER["PHP_SELF"].($object->id ? '?id='.$object->id : '');
159$head[$h][1] = $langs->trans("Bookmark");
160$head[$h][2] = 'card';
161$h++;
162
163$hselected = 'card';
164
165
166if ($action == 'create') {
167 /*
168 * Fact bookmark creation mode
169 */
170
171 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST" enctype="multipart/form-data">'."\n";
172 print '<input type="hidden" name="token" value="'.newToken().'">';
173 print '<input type="hidden" name="action" value="add">';
174 print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
175
176 print load_fiche_titre($langs->trans("NewBookmark"), '', 'bookmark');
177
178 print dol_get_fiche_head([], 'bookmark', '', 0, '');
179
180 print '<table class="border centpercent tableforfieldcreate">';
181
182 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>';
183 dol_set_focus('#titlebookmark');
184
185 // URL
186 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>';
187
188 // Target
189 print '<tr><td>'.$langs->trans("BehaviourOnClick").'</td><td>';
190 $liste = array(0 => $langs->trans("ReplaceWindow"), 1 => $langs->trans("OpenANewWindow"));
191 $defaulttarget = 1;
192 if ($url && !preg_match('/^http/i', $url)) {
193 $defaulttarget = 0;
194 }
195 print $form->selectarray('target', $liste, GETPOSTISSET('target') ? GETPOSTINT('target') : $defaulttarget, 0, 0, 0, '', 0, 0, 0, '', 'maxwidth300');
196 print '</td><td class="hideonsmartphone"><span class="opacitymedium">'.$langs->trans("ChooseIfANewWindowMustBeOpenedOnClickOnBookmark").'</span></td></tr>';
197
198 // Visibility / Owner
199 print '<tr><td>'.$langs->trans("Visibility").'</td><td>';
200 print img_picto('', 'user', 'class="pictofixedwidth"');
201 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');
202 print '</td><td class="hideonsmartphone"></td></tr>';
203
204 // Position
205 print '<tr><td>'.$langs->trans("Position").'</td><td>';
206 print '<input class="flat width50" name="position" value="'.(GETPOSTISSET("position") ? GETPOSTINT("position") : $object->position).'">';
207 print '</td><td class="hideonsmartphone"></td></tr>';
208
209 print '</table>';
210
211 print dol_get_fiche_end();
212
213 print $form->buttonsSaveCancel("CreateBookmark");
214
215 print '</form>';
216}
217
218
219if ($id > 0 && !preg_match('/^add/i', $action)) {
220 if ($action == 'edit') {
221 print '<form name="edit" method="POST" action="'.$_SERVER["PHP_SELF"].'" enctype="multipart/form-data">';
222 print '<input type="hidden" name="token" value="'.newToken().'">';
223 print '<input type="hidden" name="action" value="update">';
224 print '<input type="hidden" name="id" value="'.$object->id.'">';
225 print '<input type="hidden" name="urlsource" value="'.DOL_URL_ROOT.'/bookmarks/card.php?id='.$object->id.'">';
226 print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
227 }
228
229 print dol_get_fiche_head($head, $hselected, $langs->trans("Bookmark"), -1, $object->picto);
230
231 $linkback = '<a href="'.DOL_URL_ROOT.'/bookmarks/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
232
233 dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', '', '', 0, '', '', 0);
234
235 print '<div class="fichecenter">';
236
237 print '<div class="underbanner clearboth"></div>';
238 print '<table class="border centpercent tableforfield">';
239
240 // Title
241 print '<tr><td class="titlefield">';
242 if ($action == 'edit') {
243 print '<span class="fieldrequired">';
244 }
245
246 print $langs->trans("BookmarkTitle");
247
248 if ($action == 'edit') {
249 print '</span>';
250 }
251
252 print '</td><td>';
253 if ($action == 'edit') {
254 print '<input class="flat minwidth250" name="title" value="'.(GETPOSTISSET("title") ? GETPOST("title", 'alphanohtml', 2) : $object->title).'">';
255 } else {
256 print dol_escape_htmltag($object->title);
257 }
258 print '</td></tr>';
259
260 // URL
261 print '<tr><td>';
262 if ($action == 'edit') {
263 print '<span class="fieldrequired">';
264 }
265 print $langs->trans("UrlOrLink");
266 if ($action == 'edit') {
267 print '</span>';
268 }
269 print '</td><td class="wordbreak">';
270 if ($action == 'edit') {
271 print '<input class="flat minwidth500 quatrevingtpercent" name="url" value="'.(GETPOSTISSET("url") ? GETPOST("url") : $object->url).'">';
272 } else {
273 print '<a href="'.(preg_match('/^http/i', $object->url) ? $object->url : DOL_URL_ROOT.$object->url).'"'.($object->target ? ' target="_blank" rel="noopener noreferrer"' : '').'>';
274 print img_picto('', 'globe', 'class="paddingright"');
275 print $object->url;
276 print '</a>';
277 }
278 print '</td></tr>';
279
280 print '<tr><td>'.$langs->trans("BehaviourOnClick").'</td><td>';
281 if ($action == 'edit') {
282 $liste = array(1 => $langs->trans("OpenANewWindow"), 0 => $langs->trans("ReplaceWindow"));
283 print $form->selectarray('target', $liste, GETPOSTISSET("target") ? GETPOST("target") : $object->target);
284 } else {
285 if ($object->target == '0') {
286 print $langs->trans("ReplaceWindow");
287 }
288 if ($object->target == '1') {
289 print $langs->trans("OpenANewWindow");
290 }
291 }
292 print '</td></tr>';
293
294 // Visibility / owner
295 print '<tr><td>'.$langs->trans("Visibility").'</td><td>';
296 if ($action == 'edit' && $user->admin) {
297 print img_picto('', 'user', 'class="pictofixedwidth"');
298 print $form->select_dolusers(GETPOSTISSET('userid') ? GETPOSTINT('userid') : ($object->fk_user ? $object->fk_user : ''), 'userid', 1, null, 0, '', '', '0', 0, 0, '', 0, '', 'maxwidth300 widthcentpercentminusx');
299 } else {
300 if ($object->fk_user > 0) {
301 $fuser = new User($db);
302 $fuser->fetch($object->fk_user);
303 print $fuser->getNomUrl(-1);
304 } else {
305 print '<span class="opacitymedium">'.$langs->trans("Everybody").'</span>';
306 }
307 }
308 print '</td></tr>';
309
310 // Position
311 print '<tr><td>'.$langs->trans("Position").'</td><td>';
312 if ($action == 'edit') {
313 print '<input class="flat" name="position" size="5" value="'.(GETPOSTISSET("position") ? GETPOSTINT("position") : $object->position).'">';
314 } else {
315 print $object->position;
316 }
317 print '</td></tr>';
318
319 // Date creation
320 print '<tr><td>'.$langs->trans("DateCreation").'</td><td>'.dol_print_date($object->datec, 'dayhour').'</td></tr>';
321
322 print '</table>';
323
324 print '</div>';
325
326 print dol_get_fiche_end();
327
328 if ($action == 'edit') {
329 print $form->buttonsSaveCancel();
330
331 print '</form>';
332 }
333
334
335 // Buttons
336
337 print '<div class="tabsAction">'."\n";
338
339 // Edit
340 if ($permissiontoadd && $action != 'edit') {
341 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=edit&token='.newToken().'">'.$langs->trans("Edit").'</a>'."\n";
342 }
343
344 // Remove
345 if ($permissiontodelete && $action != 'edit') {
346 print dolGetButtonAction($langs->trans("Delete"), $langs->trans("Delete"), 'delete', 'list.php?id='.$object->id.'&action=delete&token='.newToken(), '', true, array('attr' => array('class' => 'reposition')))."\n";
347 }
348
349 print '</div>';
350}
351
352// End of page
353llxFooter();
354$db->close();
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
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.
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, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
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.
Definition html.lib.php:540
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition html.lib.php:738
dol_set_focus($selector)
Set focus onto field with selector (similar behaviour of 'autofocus' HTML5 tag)
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Definition html.lib.php:181
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $nodie=0, $mode='')
Check permissions of a user to show a page and an object.