dolibarr  13.0.2
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 (!$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')) { $page = 0; } // If $page is not defined, or '' or -1 or if we click on clear filters or if we select empty mass action
49 $offset = $limit * $page;
50 $pageprev = $page - 1;
51 $pagenext = $page + 1;
52 if (!$sortfield) $sortfield = 'position';
53 if (!$sortorder) $sortorder = 'ASC';
54 
55 $id = GETPOST("id", 'int');
56 
57 $object = new Bookmark($db);
58 
59 $permissiontoread = $user->rights->bookmark->lire;
60 $permissiontoadd = $user->rights->bookmark->write;
61 $permissiontodelete = $user->rights->bookmark->delete;
62 
63 
64 /*
65  * Actions
66  */
67 
68 if ($action == 'delete')
69 {
70  $res = $object->remove($id);
71  if ($res > 0)
72  {
73  header("Location: ".$_SERVER["PHP_SELF"]);
74  exit;
75  } else {
76  setEventMessages($object->error, $object->errors, 'errors');
77  }
78 }
79 
80 
81 /*
82  * View
83  */
84 
85 $userstatic = new User($db);
86 
87 $title = $langs->trans("ListOfBookmarks");
88 
89 llxHeader('', $title);
90 
91 $sql = "SELECT b.rowid, b.dateb, b.fk_user, b.url, b.target, b.title, b.favicon, b.position,";
92 $sql .= " u.login, u.lastname, u.firstname";
93 $sql .= " FROM ".MAIN_DB_PREFIX."bookmark as b LEFT JOIN ".MAIN_DB_PREFIX."user as u ON b.fk_user=u.rowid";
94 $sql .= " WHERE 1=1";
95 $sql .= " AND b.entity IN (".getEntity('bookmark').")";
96 if (!$user->admin) $sql .= " AND (b.fk_user = ".$user->id." OR b.fk_user is NULL OR b.fk_user = 0)";
97 
98 $sql .= $db->order($sortfield.", position", $sortorder);
99 
100 // Count total nb of records
101 $nbtotalofrecords = '';
102 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
103 {
104  $resql = $db->query($sql);
105  $nbtotalofrecords = $db->num_rows($resql);
106  if (($page * $limit) > $nbtotalofrecords) // if total of record found is smaller than page * limit, goto and load page 0
107  {
108  $page = 0;
109  $offset = 0;
110  }
111 }
112 // if total of record found is smaller than limit, no need to do paging and to restart another select with limits set.
113 if (is_numeric($nbtotalofrecords) && $limit > $nbtotalofrecords)
114 {
115  $num = $nbtotalofrecords;
116 } else {
117  $sql .= $db->plimit($limit + 1, $offset);
118 
119  $resql = $db->query($sql);
120  if (!$resql)
121  {
122  dol_print_error($db);
123  exit;
124  }
125 
126  $num = $db->num_rows($resql);
127 }
128 
129 $param = "";
130 if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.urlencode($contextpage);
131 if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.urlencode($limit);
132 if ($optioncss != '') $param = '&optioncss='.urlencode($optioncss);
133 
134 $moreforfilter = '';
135 
136 // List of mass actions available
137 $arrayofmassactions = array(
138  //'validate'=>$langs->trans("Validate"),
139  //'generate_doc'=>$langs->trans("ReGeneratePDF"),
140  //'builddoc'=>$langs->trans("PDFMerge"),
141  //'presend'=>$langs->trans("SendByMail"),
142 );
143 if ($permissiontodelete) $arrayofmassactions['predelete'] = '<span class="fa fa-trash paddingrightonly"></span>'.$langs->trans("Delete");
144 if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) $arrayofmassactions = array();
145 $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
146 
147 print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
148 if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
149 print '<input type="hidden" name="token" value="'.newToken().'">';
150 print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
151 print '<input type="hidden" name="action" value="list">';
152 print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
153 print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
154 print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
155 
156 $newcardbutton = '';
157 $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));
158 
159 print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'bookmark', 0, $newcardbutton, '', $limit, 0, 0, 1);
160 
161 print '<div class="div-table-responsive">';
162 print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
163 
164 print "<tr class=\"liste_titre\">";
165 //print "<td>&nbsp;</td>";
166 print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "b.rowid", "", $param, 'align="left"', $sortfield, $sortorder);
167 print_liste_field_titre("Title", $_SERVER["PHP_SELF"], "b.title", "", $param, 'align="left"', $sortfield, $sortorder);
168 print_liste_field_titre("Link", $_SERVER["PHP_SELF"], "b.url", "", $param, 'align="left"', $sortfield, $sortorder);
169 print_liste_field_titre("Target", '', '', '', '', 'align="center"');
170 print_liste_field_titre("Owner", $_SERVER["PHP_SELF"], "u.lastname", "", $param, 'align="center"', $sortfield, $sortorder);
171 print_liste_field_titre("Date", $_SERVER["PHP_SELF"], "b.dateb", "", $param, 'align="center"', $sortfield, $sortorder);
172 print_liste_field_titre("Position", $_SERVER["PHP_SELF"], "b.position", "", $param, 'class="right"', $sortfield, $sortorder);
174 print "</tr>\n";
175 
176 $cacheOfUsers = array();
177 
178 $i = 0;
179 while ($i < min($num, $limit))
180 {
181  $obj = $db->fetch_object($resql);
182 
183  $object->id = $obj->rowid;
184  $object->ref = $obj->rowid;
185 
186  print '<tr class="oddeven">';
187 
188  // Id
189  print '<td class="left">';
190  print $object->getNomUrl(1);
191  print '</td>';
192 
193  $linkintern = 0;
194  $title = $obj->title;
195  $link = $obj->url;
196 
197  // Title
198  print "<td>";
199  $linkintern = 1;
200  if ($linkintern) print '<a href="'.$obj->url.'">';
201  print $title;
202  if ($linkintern) print "</a>";
203  print "</td>\n";
204 
205  // Url
206  print '<td class="tdoverflowmax200">';
207  if (!$linkintern) print '<a href="'.$obj->url.'"'.($obj->target ? ' target="newlink" rel="noopener"' : '').'>';
208  print $link;
209  if (!$linkintern) print '</a>';
210  print "</td>\n";
211 
212  // Target
213  print '<td class="center">';
214  if ($obj->target == 0) print $langs->trans("BookmarkTargetReplaceWindowShort");
215  if ($obj->target == 1) print $langs->trans("BookmarkTargetNewWindowShort");
216  print "</td>\n";
217 
218  // Author
219  print '<td class="center">';
220  if ($obj->fk_user)
221  {
222  if (empty($cacheOfUsers[$obj->fk_user])) {
223  $tmpuser = new User($db);
224  $tmpuser->fetch($obj->fk_user);
225  $cacheOfUsers[$obj->fk_user] = $tmpuser;
226  }
227  $tmpuser = $cacheOfUsers[$obj->fk_user];
228  print $tmpuser->getNomUrl(1);
229  } else {
230  print $langs->trans("Public");
231  }
232  print "</td>\n";
233 
234  // Date creation
235  print '<td class="center">'.dol_print_date($db->jdate($obj->dateb), 'day')."</td>";
236 
237  // Position
238  print '<td class="right">'.$obj->position."</td>";
239 
240  // Actions
241  print '<td class="nowrap right">';
242  if ($user->rights->bookmark->creer)
243  {
244  print '<a class="editfielda" href="'.DOL_URL_ROOT.'/bookmarks/card.php?action=edit&token='.newToken().'&id='.$obj->rowid.'&backtopage='.urlencode($_SERVER["PHP_SELF"]).'">'.img_edit()."</a>";
245  }
246  if ($user->rights->bookmark->supprimer)
247  {
248  print '<a class="marginleftonly" href="'.$_SERVER["PHP_SELF"].'?action=delete&token='.newToken().'&id='.$obj->rowid.'">'.img_delete().'</a>';
249  } else {
250  print "&nbsp;";
251  }
252  print "</td>";
253  print "</tr>\n";
254  $i++;
255 }
256 print "</table>";
257 print '</div>';
258 
259 $db->free($resql);
260 
261 
262 // End of page
263 llxFooter();
264 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
img_edit($titlealt= 'default', $float=0, $other= '')
Show logo editer/modifier fiche.
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.
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.
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.
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
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.
print
Draft customers invoices.
Definition: index.php:89
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1232
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
newToken()
Return the value of token currently saved into session with name &#39;newtoken&#39;.
llxFooter()
Empty footer.
Definition: wrapper.php:59
img_delete($titlealt= 'default', $other= 'class="pictodelete"', $morecss= '')
Show delete logo.
Class to manage bookmarks.