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