dolibarr  16.0.5
list.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2005-2020 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 require '../main.inc.php';
25 require_once DOL_DOCUMENT_ROOT.'/bookmarks/class/bookmark.class.php';
26 
27 // Load translation files required by the page
28 $langs->loadLangs(array('bookmarks', 'admin'));
29 
30 $action = GETPOST('action', 'aZ09');
31 $massaction = GETPOST('massaction', 'alpha');
32 $show_files = GETPOST('show_files', 'int');
33 $confirm = GETPOST('confirm', 'alpha');
34 $toselect = GETPOST('toselect', 'array');
35 $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'bookmarklist'; // To manage different context of search
36 
37 // Security check
38 if (empty($user->rights->bookmark->lire)) {
39  restrictedArea($user, 'bookmarks');
40 }
41 $optioncss = GETPOST('optioncss', 'alpha');
42 
43 // Load variable for pagination
44 $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
45 $sortfield = GETPOST('sortfield', 'aZ09comma');
46 $sortorder = GETPOST('sortorder', 'aZ09comma');
47 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
48 if (empty($page) || $page == -1 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha') || (empty($toselect) && $massaction === '0')) {
49  $page = 0;
50 } // If $page is not defined, or '' or -1 or if we click on clear filters or if we select empty mass action
51 $offset = $limit * $page;
52 $pageprev = $page - 1;
53 $pagenext = $page + 1;
54 if (!$sortfield) {
55  $sortfield = 'position';
56 }
57 if (!$sortorder) {
58  $sortorder = 'ASC';
59 }
60 
61 $id = GETPOST("id", 'int');
62 
63 $object = new Bookmark($db);
64 
65 $permissiontoread = !empty($user->rights->bookmark->lire);
66 $permissiontoadd = !empty($user->rights->bookmark->creer);
67 $permissiontodelete = !empty($user->rights->bookmark->supprimer);
68 
69 
70 /*
71  * Actions
72  */
73 
74 if ($action == 'delete') {
75  $res = $object->remove($id);
76  if ($res > 0) {
77  header("Location: ".$_SERVER["PHP_SELF"]);
78  exit;
79  } else {
80  setEventMessages($object->error, $object->errors, 'errors');
81  }
82 }
83 
84 
85 /*
86  * View
87  */
88 
89 $form = new Form($db);
90 
91 $title = $langs->trans("ListOfBookmarks");
92 
93 llxHeader('', $title);
94 
95 $sql = "SELECT b.rowid, b.dateb, b.fk_user, b.url, b.target, b.title, b.favicon, b.position,";
96 $sql .= " u.login, u.lastname, u.firstname";
97 $sql .= " FROM ".MAIN_DB_PREFIX."bookmark as b LEFT JOIN ".MAIN_DB_PREFIX."user as u ON b.fk_user=u.rowid";
98 $sql .= " WHERE 1=1";
99 $sql .= " AND b.entity IN (".getEntity('bookmark').")";
100 if (!$user->admin) {
101  $sql .= " AND (b.fk_user = ".((int) $user->id)." OR b.fk_user is NULL OR b.fk_user = 0)";
102 }
103 
104 $sql .= $db->order($sortfield.", position", $sortorder);
105 
106 // Count total nb of records
107 $nbtotalofrecords = '';
108 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
109  $resql = $db->query($sql);
110  $nbtotalofrecords = $db->num_rows($resql);
111  if (($page * $limit) > $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0
112  $page = 0;
113  $offset = 0;
114  }
115 }
116 // if total of record found is smaller than limit, no need to do paging and to restart another select with limits set.
117 if (is_numeric($nbtotalofrecords) && $limit > $nbtotalofrecords) {
118  $num = $nbtotalofrecords;
119 } else {
120  $sql .= $db->plimit($limit + 1, $offset);
121 
122  $resql = $db->query($sql);
123  if (!$resql) {
124  dol_print_error($db);
125  exit;
126  }
127 
128  $num = $db->num_rows($resql);
129 }
130 
131 $param = "";
132 if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
133  $param .= '&contextpage='.urlencode($contextpage);
134 }
135 if ($limit > 0 && $limit != $conf->liste_limit) {
136  $param .= '&limit='.urlencode($limit);
137 }
138 if ($optioncss != '') {
139  $param = '&optioncss='.urlencode($optioncss);
140 }
141 
142 $moreforfilter = '';
143 
144 // List of mass actions available
145 $arrayofmassactions = array(
146  //'validate'=>img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("Validate"),
147  //'generate_doc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"),
148  //'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
149  //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
150 );
151 if ($permissiontodelete) {
152  $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
153 }
154 if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) {
155  $arrayofmassactions = array();
156 }
157 $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
158 
159 print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
160 if ($optioncss != '') {
161  print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
162 }
163 print '<input type="hidden" name="token" value="'.newToken().'">';
164 print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
165 print '<input type="hidden" name="action" value="list">';
166 print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
167 print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
168 print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
169 
170 $newcardbutton = '';
171 $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));
172 
173 print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'bookmark', 0, $newcardbutton, '', $limit, 0, 0, 1);
174 
175 print '<div class="div-table-responsive">';
176 print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
177 
178 print '<tr class="liste_titre">';
179 //print "<td>&nbsp;</td>";
180 print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "b.rowid", "", $param, 'align="left"', $sortfield, $sortorder);
181 print_liste_field_titre("Title", $_SERVER["PHP_SELF"], "b.title", "", $param, 'align="left"', $sortfield, $sortorder);
182 print_liste_field_titre("Link", $_SERVER["PHP_SELF"], "b.url", "", $param, 'align="left"', $sortfield, $sortorder);
183 print_liste_field_titre("Target", '', '', '', '', 'align="center"');
184 print_liste_field_titre("Visibility", $_SERVER["PHP_SELF"], "u.lastname", "", $param, 'align="center"', $sortfield, $sortorder);
185 print_liste_field_titre("Date", $_SERVER["PHP_SELF"], "b.dateb", "", $param, 'align="center"', $sortfield, $sortorder);
186 print_liste_field_titre("Position", $_SERVER["PHP_SELF"], "b.position", "", $param, 'class="right"', $sortfield, $sortorder);
188 print "</tr>\n";
189 
190 $cacheOfUsers = array();
191 
192 $i = 0;
193 while ($i < min($num, $limit)) {
194  $obj = $db->fetch_object($resql);
195 
196  $object->id = $obj->rowid;
197  $object->ref = $obj->rowid;
198 
199  print '<tr class="oddeven">';
200 
201  // Id
202  print '<td class="nowraponall">';
203  print $object->getNomUrl(1);
204  print '</td>';
205 
206  $linkintern = 0;
207  $title = $obj->title;
208  $link = $obj->url;
209  $canedit = $user->rights->bookmark->supprimer;
210  $candelete = $user->rights->bookmark->creer;
211 
212  // Title
213  print "<td>";
214  $linkintern = 1;
215  if ($linkintern) {
216  print '<a href="'.$obj->url.'">';
217  }
218  print $title;
219  if ($linkintern) {
220  print "</a>";
221  }
222  print "</td>\n";
223 
224  // Url
225  print '<td class="tdoverflowmax200">';
226  if (!$linkintern) {
227  print '<a href="'.$obj->url.'"'.($obj->target ? ' target="newlink" rel="noopener"' : '').'>';
228  }
229  print $link;
230  if (!$linkintern) {
231  print '</a>';
232  }
233  print "</td>\n";
234 
235  // Target
236  print '<td class="center">';
237  if ($obj->target == 0) {
238  print $langs->trans("BookmarkTargetReplaceWindowShort");
239  }
240  if ($obj->target == 1) {
241  print $langs->trans("BookmarkTargetNewWindowShort");
242  }
243  print "</td>\n";
244 
245  // Author
246  print '<td class="center">';
247  if ($obj->fk_user) {
248  if (empty($cacheOfUsers[$obj->fk_user])) {
249  $tmpuser = new User($db);
250  $tmpuser->fetch($obj->fk_user);
251  $cacheOfUsers[$obj->fk_user] = $tmpuser;
252  }
253  $tmpuser = $cacheOfUsers[$obj->fk_user];
254  print $tmpuser->getNomUrl(1);
255  } else {
256  print '<span class="opacitymedium">'.$langs->trans("Everybody").'</span>';
257  if (!$user->admin) {
258  $candelete = false;
259  $canedit = false;
260  }
261  }
262  print "</td>\n";
263 
264  // Date creation
265  print '<td class="center">'.dol_print_date($db->jdate($obj->dateb), 'day')."</td>";
266 
267  // Position
268  print '<td class="right">'.$obj->position."</td>";
269 
270  // Actions
271  print '<td class="nowraponall right">';
272  if ($canedit) {
273  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>";
274  }
275  if ($candelete) {
276  print '<a class="marginleftonly" href="'.$_SERVER["PHP_SELF"].'?action=delete&token='.newToken().'&id='.$obj->rowid.'">'.img_delete().'</a>';
277  }
278  print "</td>";
279  print "</tr>\n";
280  $i++;
281 }
282 print "</table>";
283 print '</div>';
284 
285 $db->free($resql);
286 
287 
288 // End of page
289 llxFooter();
290 $db->close();
restrictedArea
restrictedArea($user, $features, $objectid=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.
Definition: security.lib.php:234
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
Bookmark
Class to manage bookmarks.
Definition: bookmark.class.php:29
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4844
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
img_edit
img_edit($titlealt='default', $float=0, $other='')
Show logo editer/modifier fiche.
Definition: functions.lib.php:4389
img_picto
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Definition: functions.lib.php:3880
img_delete
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
Definition: functions.lib.php:4429
dolGetButtonTitle
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.
Definition: functions.lib.php:10605
print_barre_liste
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.
Definition: functions.lib.php:5257
newToken
newToken()
Return the value of token currently saved into session with name 'newtoken'.
Definition: functions.lib.php:10878
User
Class to manage Dolibarr users.
Definition: user.class.php:44
GETPOSTISSET
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
Definition: functions.lib.php:386
print_liste_field_titre
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
Definition: functions.lib.php:5026
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice') && $user->rights->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->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:742
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8137
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59