dolibarr 21.0.0-beta
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
40// Load translation files required by the page
41$langs->loadLangs(array('bookmarks', 'other'));
42
43
44// Get Parameters
45$id = GETPOSTINT("id");
46$action = GETPOST("action", "alpha");
47$title = (string) GETPOST("title", "alpha");
48$url = (string) GETPOST("url", "alpha");
49$urlsource = GETPOST("urlsource", "alpha");
50$target = GETPOST("target", "alpha");
51$userid = GETPOSTINT("userid");
52$position = GETPOSTINT("position");
53$backtopage = GETPOST('backtopage', 'alpha');
54
55
56// Initialize Objects
57$object = new Bookmark($db);
58if ($id > 0) {
59 $object->fetch($id);
60}
61
62// Security check
63restrictedArea($user, 'bookmark', $object);
64
65$permissiontoread = $user->hasRight('bookmark', 'lire');
66$permissiontoadd = $user->hasRight('bookmark', 'creer');
67$permissiontodelete = ($user->hasRight('bookmark', 'supprimer') || ($permissiontoadd && $object->fk_user == $user->id)); // Can always delete its own bookmark
68
69
70
71/*
72 * Actions
73 */
74
75if (($action == 'add' || $action == 'addproduct' || $action == 'update') && $permissiontoadd) {
76 if ($action == 'update') { // Test on permission already done
77 $invertedaction = 'edit';
78 } else {
79 $invertedaction = 'create';
80 }
81
82 $error = 0;
83
84 if (GETPOST('cancel', 'alpha')) {
85 if (empty($backtopage)) {
86 $backtopage = ($urlsource ? $urlsource : ((!empty($url) && !preg_match('/^http/i', $url)) ? $url : DOL_URL_ROOT.'/bookmarks/list.php'));
87 }
88 header("Location: ".$backtopage);
89 exit;
90 }
91
92 if ($action == 'update') { // Test on permission already done
93 $object->fetch(GETPOSTINT("id"));
94 }
95 // Check if null because user not admin can't set an user and send empty value here.
96 if (!empty($userid)) {
97 $object->fk_user = $userid;
98 }
99 $object->title = $title;
100 $object->url = $url;
101 $object->target = $target;
102 $object->position = $position;
103
104 if (!$title) {
105 $error++;
106 setEventMessages($langs->transnoentities("ErrorFieldRequired", $langs->trans("BookmarkTitle")), null, 'errors');
107 }
108
109 if (!$url) {
110 $error++;
111 setEventMessages($langs->transnoentities("ErrorFieldRequired", $langs->trans("UrlOrLink")), null, 'errors');
112 }
113
114 if (!$error) {
115 $object->favicon = 'none';
116
117 if ($action == 'update') { // Test on permission already done
118 $res = $object->update();
119 } else {
120 $res = $object->create();
121 }
122
123 if ($res > 0) {
124 if (empty($backtopage)) {
125 $backtopage = ($urlsource ? $urlsource : ((!empty($url) && !preg_match('/^http/i', $url)) ? $url : DOL_URL_ROOT.'/bookmarks/list.php'));
126 }
127 header("Location: ".$backtopage);
128 exit;
129 } else {
130 if ($object->errno == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
131 $langs->load("errors");
132 setEventMessages($langs->transnoentities("WarningBookmarkAlreadyExists"), null, 'warnings');
133 } else {
134 setEventMessages($object->error, $object->errors, 'errors');
135 }
136 $action = $invertedaction;
137 }
138 } else {
139 $action = $invertedaction;
140 }
141}
142
143
144
145/*
146 * View
147 */
148
149llxHeader('', '', '', '', 0, 0, '', '', '', 'mod-bookmarks page-card');
150
151$form = new Form($db);
152
153
154$head = array();
155$h = 1;
156
157$head[$h][0] = $_SERVER["PHP_SELF"].($object->id ? '?id='.$object->id : '');
158$head[$h][1] = $langs->trans("Bookmark");
159$head[$h][2] = 'card';
160$h++;
161
162$hselected = 'card';
163
164
165if ($action == 'create') {
166 /*
167 * Fact bookmark creation mode
168 */
169
170 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST" enctype="multipart/form-data">'."\n";
171 print '<input type="hidden" name="token" value="'.newToken().'">';
172 print '<input type="hidden" name="action" value="add">';
173 print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
174
175 print load_fiche_titre($langs->trans("NewBookmark"), '', 'bookmark');
176
177 print dol_get_fiche_head([], 'bookmark', '', 0, '');
178
179 print '<table class="border centpercent tableforfieldcreate">';
180
181 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>';
182 dol_set_focus('#titlebookmark');
183
184 // URL
185 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>';
186
187 // Target
188 print '<tr><td>'.$langs->trans("BehaviourOnClick").'</td><td>';
189 $liste = array(0=>$langs->trans("ReplaceWindow"), 1=>$langs->trans("OpenANewWindow"));
190 $defaulttarget = 1;
191 if ($url && !preg_match('/^http/i', $url)) {
192 $defaulttarget = 0;
193 }
194 print $form->selectarray('target', $liste, GETPOSTISSET('target') ? GETPOSTINT('target') : $defaulttarget, 0, 0, 0, '', 0, 0, 0, '', 'maxwidth300');
195 print '</td><td class="hideonsmartphone"><span class="opacitymedium">'.$langs->trans("ChooseIfANewWindowMustBeOpenedOnClickOnBookmark").'</span></td></tr>';
196
197 // Visibility / Owner
198 print '<tr><td>'.$langs->trans("Visibility").'</td><td>';
199 print img_picto('', 'user', 'class="pictofixedwidth"');
200 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');
201 print '</td><td class="hideonsmartphone"></td></tr>';
202
203 // Position
204 print '<tr><td>'.$langs->trans("Position").'</td><td>';
205 print '<input class="flat width50" name="position" value="'.(GETPOSTISSET("position") ? GETPOSTINT("position") : $object->position).'">';
206 print '</td><td class="hideonsmartphone"></td></tr>';
207
208 print '</table>';
209
210 print dol_get_fiche_end();
211
212 print $form->buttonsSaveCancel("CreateBookmark");
213
214 print '</form>';
215}
216
217
218if ($id > 0 && !preg_match('/^add/i', $action)) {
219 if ($action == 'edit') {
220 print '<form name="edit" method="POST" action="'.$_SERVER["PHP_SELF"].'" enctype="multipart/form-data">';
221 print '<input type="hidden" name="token" value="'.newToken().'">';
222 print '<input type="hidden" name="action" value="update">';
223 print '<input type="hidden" name="id" value="'.$object->id.'">';
224 print '<input type="hidden" name="urlsource" value="'.DOL_URL_ROOT.'/bookmarks/card.php?id='.$object->id.'">';
225 print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
226 }
227
228 print dol_get_fiche_head($head, $hselected, $langs->trans("Bookmark"), -1, 'bookmark');
229
230 $linkback = '<a href="'.DOL_URL_ROOT.'/bookmarks/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
231
232 dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', '', '', 0, '', '', 0);
233
234 print '<div class="fichecenter">';
235
236 print '<div class="underbanner clearboth"></div>';
237 print '<table class="border centpercent tableforfield">';
238
239 // Title
240 print '<tr><td class="titlefield">';
241 if ($action == 'edit') {
242 print '<span class="fieldrequired">';
243 }
244
245 print $langs->trans("BookmarkTitle");
246
247 if ($action == 'edit') {
248 print '</span>';
249 }
250
251 print '</td><td>';
252 if ($action == 'edit') {
253 print '<input class="flat minwidth250" name="title" value="'.(GETPOSTISSET("title") ? GETPOST("title", '', 2) : $object->title).'">';
254 } else {
255 print dol_escape_htmltag($object->title);
256 }
257 print '</td></tr>';
258
259 // URL
260 print '<tr><td>';
261 if ($action == 'edit') {
262 print '<span class="fieldrequired">';
263 }
264 print $langs->trans("UrlOrLink");
265 if ($action == 'edit') {
266 print '</span>';
267 }
268 print '</td><td class="wordbreak">';
269 if ($action == 'edit') {
270 print '<input class="flat minwidth500 quatrevingtpercent" name="url" value="'.(GETPOSTISSET("url") ? GETPOST("url") : $object->url).'">';
271 } else {
272 print '<a href="'.(preg_match('/^http/i', $object->url) ? $object->url : DOL_URL_ROOT.$object->url).'"'.($object->target ? ' target="_blank" rel="noopener noreferrer"' : '').'>';
273 print img_picto('', 'globe', 'class="paddingright"');
274 print $object->url;
275 print '</a>';
276 }
277 print '</td></tr>';
278
279 print '<tr><td>'.$langs->trans("BehaviourOnClick").'</td><td>';
280 if ($action == 'edit') {
281 $liste = array(1=>$langs->trans("OpenANewWindow"), 0=>$langs->trans("ReplaceWindow"));
282 print $form->selectarray('target', $liste, GETPOSTISSET("target") ? GETPOST("target") : $object->target);
283 } else {
284 if ($object->target == '0') {
285 print $langs->trans("ReplaceWindow");
286 }
287 if ($object->target == '1') {
288 print $langs->trans("OpenANewWindow");
289 }
290 }
291 print '</td></tr>';
292
293 // Visibility / owner
294 print '<tr><td>'.$langs->trans("Visibility").'</td><td>';
295 if ($action == 'edit' && $user->admin) {
296 print img_picto('', 'user', 'class="pictofixedwidth"');
297 print $form->select_dolusers(GETPOSTISSET('userid') ? GETPOSTINT('userid') : ($object->fk_user ? $object->fk_user : ''), 'userid', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth300 widthcentpercentminusx');
298 } else {
299 if ($object->fk_user > 0) {
300 $fuser = new User($db);
301 $fuser->fetch($object->fk_user);
302 print $fuser->getNomUrl(-1);
303 } else {
304 print '<span class="opacitymedium">'.$langs->trans("Everybody").'</span>';
305 }
306 }
307 print '</td></tr>';
308
309 // Position
310 print '<tr><td>'.$langs->trans("Position").'</td><td>';
311 if ($action == 'edit') {
312 print '<input class="flat" name="position" size="5" value="'.(GETPOSTISSET("position") ? GETPOSTINT("position") : $object->position).'">';
313 } else {
314 print $object->position;
315 }
316 print '</td></tr>';
317
318 // Date creation
319 print '<tr><td>'.$langs->trans("DateCreation").'</td><td>'.dol_print_date($object->datec, 'dayhour').'</td></tr>';
320
321 print '</table>';
322
323 print '</div>';
324
325 print dol_get_fiche_end();
326
327 if ($action == 'edit') {
328 print $form->buttonsSaveCancel();
329
330 print '</form>';
331 }
332
333
334 // Buttons
335
336 print '<div class="tabsAction">'."\n";
337
338 // Edit
339 if ($permissiontoadd && $action != 'edit') {
340 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=edit&token='.newToken().'">'.$langs->trans("Edit").'</a>'."\n";
341 }
342
343 // Remove
344 if ($permissiontodelete && $action != 'edit') {
345 print '<a class="butActionDelete" href="list.php?id='.$object->id.'&action=delete&token='.newToken().'">'.$langs->trans("Delete").'</a>'."\n";
346 }
347
348 print '</div>';
349}
350
351// End of page
352llxFooter();
353$db->close();
$id
Definition account.php:48
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
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:71
print $object position
Definition edit.php:204
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.