dolibarr  9.0.0
box_bookmarks.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2005-2017 Laurent Destailleur <eldy@users.sourceforge.net>
3  * Copyright (C) 2015 Frederic France <frederic.france@free.fr>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
24 include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
25 
30 {
31  var $boxcode="bookmarks";
32  var $boximg="object_bookmark";
33  var $boxlabel="BoxMyLastBookmarks";
34  var $depends = array("bookmark");
35 
39  public $db;
40 
41  var $param;
42 
43  var $info_box_head = array();
44  var $info_box_contents = array();
45 
46 
53  function __construct($db,$param)
54  {
55  global $user;
56 
57  $this->db=$db;
58 
59  $this->hidden=! ($user->rights->bookmark->lire);
60  }
61 
68  function loadBox($max=5)
69  {
70  global $user, $langs, $db, $conf;
71  $langs->load("boxes");
72 
73  $this->max=$max;
74 
75  $this->info_box_head = array(
76  'text' => $langs->trans("BoxMyLastBookmarks",$max),
77  'sublink' => DOL_URL_ROOT.'/bookmarks/list.php',
78  );
79  if ($user->rights->bookmark->creer) {
80  $this->info_box_head['subpicto']='object_bookmark';
81  $this->info_box_head['subtext']=$langs->trans("BookmarksManagement");
82  }
83  else
84  {
85  $this->info_box_head['subpicto']='object_bookmark';
86  $this->info_box_head['subtext']=$langs->trans("ListOfBookmark");
87  }
88 
89  if ($user->rights->bookmark->lire)
90  {
91  $sql = "SELECT b.title, b.url, b.target, b.favicon";
92  $sql.= " FROM ".MAIN_DB_PREFIX."bookmark as b";
93  $sql.= " WHERE fk_user = ".$user->id;
94  $sql.= " AND b.entity = ".$conf->entity;
95  $sql.= $db->order("position","ASC");
96  $sql.= $db->plimit($max, 0);
97 
98  $result = $db->query($sql);
99  if ($result)
100  {
101  $num = $db->num_rows($result);
102 
103  $line = 0;
104 
105  while ($line < $num) {
106  $objp = $db->fetch_object($result);
107 
108  $this->info_box_contents[$line][0] = array(
109  'td' => 'align="left" width="16"',
110  'logo' => $this->boximg,
111  'url' => $objp->url,
112  'tooltip' => $objp->title,
113  'target' => $objp->target?'newtab':'',
114  );
115  $this->info_box_contents[$line][1] = array(
116  'td' => '',
117  'text' => $objp->title,
118  'url' => $objp->url,
119  'tooltip' => $objp->title,
120  'target' => $objp->target?'newtab':'',
121  );
122 
123  $line++;
124  }
125 
126  if ($num==0) {
127  $mytxt=$langs->trans("NoRecordedBookmarks");
128  if ($user->rights->bookmark->creer) $mytxt.=' '.$langs->trans("ClickToAdd");
129  $this->info_box_contents[$line][0] = array(
130  'td' => 'align="center" colspan="2"',
131  'tooltip' => $mytxt,
132  'url'=> DOL_URL_ROOT.'/bookmarks/list.php', 'text'=>$mytxt,
133  );
134  }
135 
136  $db->free($result);
137  } else {
138  $this->info_box_contents[0][0] = array(
139  'td' => '',
140  'maxlength'=>500,
141  'text' => ($db->error().' sql='.$sql),
142  );
143  }
144  } else {
145  $this->info_box_contents[0][0] = array(
146  'td' => 'align="left" class="nohover opacitymedium"',
147  'text' => $langs->trans("ReadPermissionNotAllowed")
148  );
149  }
150  }
151 
160  function showBox($head = null, $contents = null, $nooutput=0)
161  {
162  return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
163  }
164 }
165 
__construct($db, $param)
Constructor.
Class to manage the box to show bookmarks.
Class ModeleBoxes.
loadBox($max=5)
Load data for box to show them later.
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.