dolibarr  x.y.z
list.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2005-2022 Laurent Destailleur <eldy@users.sourceforge.net>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <https://www.gnu.org/licenses/>.
16  */
17 
24 // Load Dolibarr environment
25 require '../main.inc.php';
26 require_once DOL_DOCUMENT_ROOT.'/bookmarks/class/bookmark.class.php';
27 
28 // Load translation files required by the page
29 $langs->loadLangs(array('bookmarks', 'admin'));
30 
31 // Get Parameters
32 $action = GETPOST('action', 'aZ09');
33 $massaction = GETPOST('massaction', 'alpha');
34 $show_files = GETPOST('show_files', 'int');
35 $confirm = GETPOST('confirm', 'alpha');
36 $toselect = GETPOST('toselect', 'array');
37 $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'bookmarklist'; // To manage different context of search
38 $id = GETPOST("id", 'int');
39 $optioncss = GETPOST('optioncss', 'alpha');
40 
41 // Load variable for pagination
42 $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
43 $sortfield = GETPOST('sortfield', 'aZ09comma');
44 $sortorder = GETPOST('sortorder', 'aZ09comma');
45 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
46 if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
47  // If $page is not defined, or '' or -1 or if we click on clear filters
48  $page = 0;
49 }
50 $offset = $limit * $page;
51 $pageprev = $page - 1;
52 $pagenext = $page + 1;
53 if (!$sortfield) {
54  $sortfield = 'b.position';
55 }
56 if (!$sortorder) {
57  $sortorder = 'ASC';
58 }
59 
60 // Initialize Objects
61 $object = new Bookmark($db);
62 
63 // Security check
64 restrictedArea($user, 'bookmark');
65 
66 // Permissions
67 $permissiontoread = !empty($user->rights->bookmark->lire);
68 $permissiontoadd = !empty($user->rights->bookmark->creer);
69 $permissiontodelete = !empty($user->rights->bookmark->supprimer);
70 
71 
72 /*
73  * Actions
74  */
75 
76 if (GETPOST('cancel', 'alpha')) {
77  $action = 'list';
78  $massaction = '';
79 }
80 if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
81  $massaction = '';
82 }
83 
84 if ($action == 'delete') {
85  $res = $object->remove($id);
86  if ($res > 0) {
87  header("Location: ".$_SERVER["PHP_SELF"]);
88  exit;
89  } else {
90  setEventMessages($object->error, $object->errors, 'errors');
91  }
92 }
93 
94 
95 
96 /*
97  * View
98  */
99 
100 $form = new Form($db);
101 
102 $title = $langs->trans("Bookmarks");
103 
104 llxHeader('', $title);
105 
106 $sql = "SELECT b.rowid, b.dateb, b.fk_user, b.url, b.target, b.title, b.favicon, b.position,";
107 $sql .= " u.login, u.lastname, u.firstname";
108 
109 $sqlfields = $sql; // $sql fields to remove for count total
110 
111 $sql .= " FROM ".MAIN_DB_PREFIX."bookmark as b LEFT JOIN ".MAIN_DB_PREFIX."user as u ON b.fk_user=u.rowid";
112 $sql .= " WHERE 1=1";
113 $sql .= " AND b.entity IN (".getEntity('bookmark').")";
114 if (!$user->admin) {
115  $sql .= " AND (b.fk_user = ".((int) $user->id)." OR b.fk_user is NULL OR b.fk_user = 0)";
116 }
117 
118 // Count total nb of records
119 $nbtotalofrecords = '';
120 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
121  /* The fast and low memory method to get and count full list converts the sql into a sql count */
122  $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
123  $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
124  $resql = $db->query($sqlforcount);
125  if ($resql) {
126  $objforcount = $db->fetch_object($resql);
127  $nbtotalofrecords = $objforcount->nbtotalofrecords;
128  } else {
129  dol_print_error($db);
130  }
131 
132  if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
133  $page = 0;
134  $offset = 0;
135  }
136  $db->free($resql);
137 }
138 
139 // Complete request and execute it with limit
140 $sql .= $db->order($sortfield.", position", $sortorder);
141 if ($limit) {
142  $sql .= $db->plimit($limit + 1, $offset);
143 }
144 
145 $resql = $db->query($sql);
146 if (!$resql) {
147  dol_print_error($db);
148  exit;
149 }
150 
151 $num = $db->num_rows($resql);
152 
153 $param = '';
154 if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
155  $param .= '&contextpage='.urlencode($contextpage);
156 }
157 if ($limit > 0 && $limit != $conf->liste_limit) {
158  $param .= '&limit='.urlencode($limit);
159 }
160 if ($optioncss != '') {
161  $param .= '&optioncss='.urlencode($optioncss);
162 }
163 
164 $moreforfilter = '';
165 
166 // List of mass actions available
167 $arrayofmassactions = array(
168  //'validate'=>img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("Validate"),
169  //'generate_doc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"),
170  //'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
171  //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
172 );
173 if (!empty($permissiontodelete)) {
174  $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
175 }
176 if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) {
177  $arrayofmassactions = array();
178 }
179 $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
180 
181 print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
182 if ($optioncss != '') {
183  print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
184 }
185 print '<input type="hidden" name="token" value="'.newToken().'">';
186 print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
187 print '<input type="hidden" name="action" value="list">';
188 print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
189 print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
190 print '<input type="hidden" name="page" value="'.$page.'">';
191 print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
192 print '<input type="hidden" name="mode" value="'.$mode.'">';
193 
194 $newcardbutton = '';
195 $newcardbutton .= dolGetButtonTitle($langs->trans('New'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/bookmarks/card.php?action=create&backtopage='.urlencode(DOL_URL_ROOT.'/bookmarks/list.php'), '', !empty($user->rights->bookmark->creer));
196 
197 print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'bookmark', 0, $newcardbutton, '', $limit, 0, 0, 1);
198 
199 print '<div class="div-table-responsive">';
200 print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
201 
202 print '<tr class="liste_titre">';
203 //print "<td>&nbsp;</td>";
204 print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "b.rowid", "", $param, '', $sortfield, $sortorder);
205 print_liste_field_titre("Title", $_SERVER["PHP_SELF"], "b.title", "", $param, '', $sortfield, $sortorder);
206 print_liste_field_titre("Link", $_SERVER["PHP_SELF"], "b.url", "", $param, '', $sortfield, $sortorder);
207 print_liste_field_titre("Target", $_SERVER["PHP_SELF"], "b.target", "", $param, '', $sortfield, $sortorder, 'center ');
208 print_liste_field_titre("Visibility", $_SERVER["PHP_SELF"], "u.lastname", "", $param, '', $sortfield, $sortorder, 'center ');
209 print_liste_field_titre("DateCreation", $_SERVER["PHP_SELF"], "b.dateb", "", $param, '', $sortfield, $sortorder, 'center ');
210 print_liste_field_titre("Position", $_SERVER["PHP_SELF"], "b.position", "", $param, '', $sortfield, $sortorder, 'right ');
212 print "</tr>\n";
213 
214 $cacheOfUsers = array();
215 
216 $i = 0;
217 while ($i < min($num, $limit)) {
218  $obj = $db->fetch_object($resql);
219 
220  $object->id = $obj->rowid;
221  $object->ref = $obj->rowid;
222 
223  print '<tr class="oddeven">';
224 
225  // Id
226  print '<td class="nowraponall">';
227  print $object->getNomUrl(1);
228  print '</td>';
229 
230  $linkintern = 1;
231  if (preg_match('/^http/i', $obj->url)) {
232  $linkintern = 0;
233  }
234  $title = $obj->title;
235  $link = $obj->url;
236  $canedit = $user->rights->bookmark->supprimer;
237  $candelete = $user->rights->bookmark->creer;
238 
239  // Title
240  print '<td class="tdoverflowmax200" alt="'.dol_escape_htmltag($title).'">';
241  print dol_escape_htmltag($title);
242  print "</td>\n";
243 
244  // Url
245  print '<td class="tdoverflowmax200">';
246  if (empty($linkintern)) {
247  print img_picto('', 'url', 'class="pictofixedwidth"');
248  print '<a class="" href="'.$obj->url.'"'.($obj->target ? ' target="newlink" rel="noopener"' : '').'>';
249  } else {
250  //print img_picto('', 'rightarrow', 'class="pictofixedwidth"');
251  print '<a class="" href="'.$obj->url.'">';
252  }
253  print $link;
254  print '</a>';
255  print "</td>\n";
256 
257  // Target
258  print '<td class="center">';
259  if ($obj->target == 0) {
260  print $langs->trans("BookmarkTargetReplaceWindowShort");
261  }
262  if ($obj->target == 1) {
263  print $langs->trans("BookmarkTargetNewWindowShort");
264  }
265  print "</td>\n";
266 
267  // Author
268  print '<td class="center">';
269  if ($obj->fk_user) {
270  if (empty($cacheOfUsers[$obj->fk_user])) {
271  $tmpuser = new User($db);
272  $tmpuser->fetch($obj->fk_user);
273  $cacheOfUsers[$obj->fk_user] = $tmpuser;
274  }
275  $tmpuser = $cacheOfUsers[$obj->fk_user];
276  print $tmpuser->getNomUrl(1);
277  } else {
278  print '<span class="opacitymedium">'.$langs->trans("Everybody").'</span>';
279  if (!$user->admin) {
280  $candelete = false;
281  $canedit = false;
282  }
283  }
284  print "</td>\n";
285 
286  // Date creation
287  print '<td class="center" title="'.dol_escape_htmltag(dol_print_date($db->jdate($obj->dateb), 'dayhour')).'">'.dol_print_date($db->jdate($obj->dateb), 'day')."</td>";
288 
289  // Position
290  print '<td class="right">'.$obj->position."</td>";
291 
292  // Actions
293  print '<td class="nowraponall right">';
294  if ($canedit) {
295  print '<a class="editfielda marginleftonly" href="'.DOL_URL_ROOT.'/bookmarks/card.php?action=edit&token='.newToken().'&id='.$obj->rowid.'&backtopage='.urlencode($_SERVER["PHP_SELF"]).'">'.img_edit()."</a>";
296  }
297  if ($candelete) {
298  print '<a class="marginleftonly" href="'.$_SERVER["PHP_SELF"].'?action=delete&token='.newToken().'&id='.$obj->rowid.'">'.img_delete().'</a>';
299  }
300  print "</td>";
301  print "</tr>\n";
302  $i++;
303 }
304 print "</table>";
305 print '</div>';
306 
307 $db->free($resql);
308 
309 
310 // End of page
311 llxFooter();
312 $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.
Definition: user.class.php:45
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:745
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dolGetButtonTitle($label, $helpText='', $iconClass='fa fa-file', $url='', $id='', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
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)
newToken()
Return the value of token currently saved into session with name 'newtoken'.
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
print_barre_liste($titre, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $hideselectlimit=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
img_edit($titlealt='default', $float=0, $other='')
Show logo editer/modifier fiche.
$nbtotalofrecords
Count total nb of records.
Definition: list.php:329
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.