dolibarr 21.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 Frédéric France <frederic.france@free.fr>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
28// Load Dolibarr environment
29require '../main.inc.php';
30require_once DOL_DOCUMENT_ROOT.'/bookmarks/class/bookmark.class.php';
31
32
33// Load translation files required by the page
34$langs->loadLangs(array('bookmarks', 'other'));
35
36
37// Get Parameters
38$id = GETPOSTINT("id");
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", "alpha");
44$userid = GETPOSTINT("userid");
45$position = GETPOSTINT("position");
46$backtopage = GETPOST('backtopage', 'alpha');
47
48
49// Initialize Objects
50$object = new Bookmark($db);
51if ($id > 0) {
52 $object->fetch($id);
53}
54
55// Security check
56restrictedArea($user, 'bookmark', $object);
57
58$permissiontoread = $user->hasRight('bookmark', 'lire');
59$permissiontoadd = $user->hasRight('bookmark', 'creer');
60$permissiontodelete = ($user->hasRight('bookmark', 'supprimer') || ($permissiontoadd && $object->fk_user == $user->id)); // Can always delete its own bookmark
61
62
63
64/*
65 * Actions
66 */
67
68if (($action == 'add' || $action == 'addproduct' || $action == 'update') && $permissiontoadd) {
69 if ($action == 'update') { // Test on permission already done
70 $invertedaction = 'edit';
71 } else {
72 $invertedaction = 'create';
73 }
74
75 $error = 0;
76
77 if (GETPOST('cancel', 'alpha')) {
78 if (empty($backtopage)) {
79 $backtopage = ($urlsource ? $urlsource : ((!empty($url) && !preg_match('/^http/i', $url)) ? $url : DOL_URL_ROOT.'/bookmarks/list.php'));
80 }
81 header("Location: ".$backtopage);
82 exit;
83 }
84
85 if ($action == 'update') { // Test on permission already done
86 $object->fetch(GETPOSTINT("id"));
87 }
88 // Check if null because user not admin can't set an user and send empty value here.
89 if (!empty($userid)) {
90 $object->fk_user = $userid;
91 }
92 $object->title = $title;
93 $object->url = $url;
94 $object->target = $target;
95 $object->position = $position;
96
97 if (!$title) {
98 $error++;
99 setEventMessages($langs->transnoentities("ErrorFieldRequired", $langs->trans("BookmarkTitle")), null, 'errors');
100 }
101
102 if (!$url) {
103 $error++;
104 setEventMessages($langs->transnoentities("ErrorFieldRequired", $langs->trans("UrlOrLink")), null, 'errors');
105 }
106
107 if (!$error) {
108 $object->favicon = 'none';
109
110 if ($action == 'update') { // Test on permission already done
111 $res = $object->update();
112 } else {
113 $res = $object->create();
114 }
115
116 if ($res > 0) {
117 if (empty($backtopage)) {
118 $backtopage = ($urlsource ? $urlsource : ((!empty($url) && !preg_match('/^http/i', $url)) ? $url : DOL_URL_ROOT.'/bookmarks/list.php'));
119 }
120 header("Location: ".$backtopage);
121 exit;
122 } else {
123 if ($object->errno == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
124 $langs->load("errors");
125 setEventMessages($langs->transnoentities("WarningBookmarkAlreadyExists"), null, 'warnings');
126 } else {
127 setEventMessages($object->error, $object->errors, 'errors');
128 }
129 $action = $invertedaction;
130 }
131 } else {
132 $action = $invertedaction;
133 }
134}
135
136
137
138/*
139 * View
140 */
141
142llxHeader('', '', '', '', 0, 0, '', '', '', 'mod-bookmarks page-card');
143
144$form = new Form($db);
145
146
147$head = array();
148$h = 1;
149
150$head[$h][0] = $_SERVER["PHP_SELF"].($object->id ? '?id='.$object->id : '');
151$head[$h][1] = $langs->trans("Bookmark");
152$head[$h][2] = 'card';
153$h++;
154
155$hselected = 'card';
156
157
158if ($action == 'create') {
159 /*
160 * Fact bookmark creation mode
161 */
162
163 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST" enctype="multipart/form-data">'."\n";
164 print '<input type="hidden" name="token" value="'.newToken().'">';
165 print '<input type="hidden" name="action" value="add">';
166 print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
167
168 print load_fiche_titre($langs->trans("NewBookmark"), '', 'bookmark');
169
170 print dol_get_fiche_head([], 'bookmark', '', 0, '');
171
172 print '<table class="border centpercent tableforfieldcreate">';
173
174 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>';
175 dol_set_focus('#titlebookmark');
176
177 // URL
178 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>';
179
180 // Target
181 print '<tr><td>'.$langs->trans("BehaviourOnClick").'</td><td>';
182 $liste = array(0=>$langs->trans("ReplaceWindow"), 1=>$langs->trans("OpenANewWindow"));
183 $defaulttarget = 1;
184 if ($url && !preg_match('/^http/i', $url)) {
185 $defaulttarget = 0;
186 }
187 print $form->selectarray('target', $liste, GETPOSTISSET('target') ? GETPOSTINT('target') : $defaulttarget, 0, 0, 0, '', 0, 0, 0, '', 'maxwidth300');
188 print '</td><td class="hideonsmartphone"><span class="opacitymedium">'.$langs->trans("ChooseIfANewWindowMustBeOpenedOnClickOnBookmark").'</span></td></tr>';
189
190 // Visibility / Owner
191 print '<tr><td>'.$langs->trans("Visibility").'</td><td>';
192 print img_picto('', 'user', 'class="pictofixedwidth"');
193 print $form->select_dolusers(GETPOSTISSET('userid') ? GETPOSTINT('userid') : $user->id, 'userid', 0, '', 0, ($user->admin ? '' : array($user->id)), '', 0, 0, 0, '', ($user->admin) ? 1 : 0, '', 'maxwidth300 widthcentpercentminusx');
194 print '</td><td class="hideonsmartphone"></td></tr>';
195
196 // Position
197 print '<tr><td>'.$langs->trans("Position").'</td><td>';
198 print '<input class="flat width50" name="position" value="'.(GETPOSTISSET("position") ? GETPOSTINT("position") : $object->position).'">';
199 print '</td><td class="hideonsmartphone"></td></tr>';
200
201 print '</table>';
202
203 print dol_get_fiche_end();
204
205 print $form->buttonsSaveCancel("CreateBookmark");
206
207 print '</form>';
208}
209
210
211if ($id > 0 && !preg_match('/^add/i', $action)) {
212 if ($action == 'edit') {
213 print '<form name="edit" method="POST" action="'.$_SERVER["PHP_SELF"].'" enctype="multipart/form-data">';
214 print '<input type="hidden" name="token" value="'.newToken().'">';
215 print '<input type="hidden" name="action" value="update">';
216 print '<input type="hidden" name="id" value="'.$object->id.'">';
217 print '<input type="hidden" name="urlsource" value="'.DOL_URL_ROOT.'/bookmarks/card.php?id='.$object->id.'">';
218 print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
219 }
220
221 print dol_get_fiche_head($head, $hselected, $langs->trans("Bookmark"), -1, 'bookmark');
222
223 $linkback = '<a href="'.DOL_URL_ROOT.'/bookmarks/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
224
225 dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', '', '', 0, '', '', 0);
226
227 print '<div class="fichecenter">';
228
229 print '<div class="underbanner clearboth"></div>';
230 print '<table class="border centpercent tableforfield">';
231
232 // Title
233 print '<tr><td class="titlefield">';
234 if ($action == 'edit') {
235 print '<span class="fieldrequired">';
236 }
237
238 print $langs->trans("BookmarkTitle");
239
240 if ($action == 'edit') {
241 print '</span>';
242 }
243
244 print '</td><td>';
245 if ($action == 'edit') {
246 print '<input class="flat minwidth250" name="title" value="'.(GETPOSTISSET("title") ? GETPOST("title", '', 2) : $object->title).'">';
247 } else {
248 print dol_escape_htmltag($object->title);
249 }
250 print '</td></tr>';
251
252 // URL
253 print '<tr><td>';
254 if ($action == 'edit') {
255 print '<span class="fieldrequired">';
256 }
257 print $langs->trans("UrlOrLink");
258 if ($action == 'edit') {
259 print '</span>';
260 }
261 print '</td><td class="wordbreak">';
262 if ($action == 'edit') {
263 print '<input class="flat minwidth500 quatrevingtpercent" name="url" value="'.(GETPOSTISSET("url") ? GETPOST("url") : $object->url).'">';
264 } else {
265 print '<a href="'.(preg_match('/^http/i', $object->url) ? $object->url : DOL_URL_ROOT.$object->url).'"'.($object->target ? ' target="_blank" rel="noopener noreferrer"' : '').'>';
266 print img_picto('', 'globe', 'class="paddingright"');
267 print $object->url;
268 print '</a>';
269 }
270 print '</td></tr>';
271
272 print '<tr><td>'.$langs->trans("BehaviourOnClick").'</td><td>';
273 if ($action == 'edit') {
274 $liste = array(1=>$langs->trans("OpenANewWindow"), 0=>$langs->trans("ReplaceWindow"));
275 print $form->selectarray('target', $liste, GETPOSTISSET("target") ? GETPOST("target") : $object->target);
276 } else {
277 if ($object->target == '0') {
278 print $langs->trans("ReplaceWindow");
279 }
280 if ($object->target == '1') {
281 print $langs->trans("OpenANewWindow");
282 }
283 }
284 print '</td></tr>';
285
286 // Visibility / owner
287 print '<tr><td>'.$langs->trans("Visibility").'</td><td>';
288 if ($action == 'edit' && $user->admin) {
289 print img_picto('', 'user', 'class="pictofixedwidth"');
290 print $form->select_dolusers(GETPOSTISSET('userid') ? GETPOSTINT('userid') : ($object->fk_user ? $object->fk_user : ''), 'userid', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth300 widthcentpercentminusx');
291 } else {
292 if ($object->fk_user > 0) {
293 $fuser = new User($db);
294 $fuser->fetch($object->fk_user);
295 print $fuser->getNomUrl(-1);
296 } else {
297 print '<span class="opacitymedium">'.$langs->trans("Everybody").'</span>';
298 }
299 }
300 print '</td></tr>';
301
302 // Position
303 print '<tr><td>'.$langs->trans("Position").'</td><td>';
304 if ($action == 'edit') {
305 print '<input class="flat" name="position" size="5" value="'.(GETPOSTISSET("position") ? GETPOSTINT("position") : $object->position).'">';
306 } else {
307 print $object->position;
308 }
309 print '</td></tr>';
310
311 // Date creation
312 print '<tr><td>'.$langs->trans("DateCreation").'</td><td>'.dol_print_date($object->datec, 'dayhour').'</td></tr>';
313
314 print '</table>';
315
316 print '</div>';
317
318 print dol_get_fiche_end();
319
320 if ($action == 'edit') {
321 print $form->buttonsSaveCancel();
322
323 print '</form>';
324 }
325
326
327 // Buttons
328
329 print '<div class="tabsAction">'."\n";
330
331 // Edit
332 if ($permissiontoadd && $action != 'edit') {
333 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=edit&token='.newToken().'">'.$langs->trans("Edit").'</a>'."\n";
334 }
335
336 // Remove
337 if ($permissiontodelete && $action != 'edit') {
338 print '<a class="butActionDelete" href="list.php?id='.$object->id.'&action=delete&token='.newToken().'">'.$langs->trans("Delete").'</a>'."\n";
339 }
340
341 print '</div>';
342}
343
344// End of page
345llxFooter();
346$db->close();
$id
Definition account.php:39
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
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:70
print $object position
Definition edit.php:195
Class to manage bookmarks.
Class to manage generation of HTML components Only common components must be here.
Class to manage Dolibarr users.
llxFooter()
Footer empty.
Definition document.php:107
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)
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)
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
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.