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