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