dolibarr  17.0.4
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 <https://www.gnu.org/licenses/>.
17  */
18 
24 include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
25 
30 {
31  public $boxcode = "bookmarks";
32  public $boximg = "bookmark";
33  public $boxlabel = "BoxMyLastBookmarks";
34  public $depends = array("bookmark");
35 
39  public $db;
40 
41  public $param;
42 
43  public $info_box_head = array();
44  public $info_box_contents = array();
45 
46 
53  public function __construct($db, $param)
54  {
55  global $user;
56 
57  $this->db = $db;
58 
59  $this->hidden = empty($user->rights->bookmark->lire);
60  }
61 
68  public function loadBox($max = 5)
69  {
70  global $user, $langs, $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->hasRight("bookmark", "creer")) {
80  $this->info_box_head['subpicto'] = 'bookmark';
81  $this->info_box_head['subtext'] = $langs->trans("BookmarksManagement");
82  } else {
83  $this->info_box_head['subpicto'] = 'bookmark';
84  $this->info_box_head['subtext'] = $langs->trans("ListOfBookmark");
85  }
86 
87  if ($user->rights->bookmark->lire) {
88  $sql = "SELECT b.title, b.url, b.target, b.favicon";
89  $sql .= " FROM ".MAIN_DB_PREFIX."bookmark as b";
90  $sql .= " WHERE fk_user = ".((int) $user->id);
91  $sql .= " AND b.entity = ".$conf->entity;
92  $sql .= $this->db->order("position", "ASC");
93  $sql .= $this->db->plimit($max, 0);
94 
95  $result = $this->db->query($sql);
96  if ($result) {
97  $num = $this->db->num_rows($result);
98 
99  $line = 0;
100 
101  while ($line < $num) {
102  $objp = $this->db->fetch_object($result);
103 
104  $this->info_box_contents[$line][0] = array(
105  'td' => 'class="left" width="16"',
106  'logo' => $this->boximg,
107  'url' => $objp->url,
108  'tooltip' => $objp->title,
109  'target' => $objp->target ? 'newtab' : '',
110  );
111  $this->info_box_contents[$line][1] = array(
112  'td' => '',
113  'text' => $objp->title,
114  'url' => $objp->url,
115  'tooltip' => $objp->title,
116  'target' => $objp->target ? 'newtab' : '',
117  );
118 
119  $line++;
120  }
121 
122  if ($num == 0) {
123  $mytxt = $langs->trans("NoRecordedBookmarks");
124  if ($user->hasRight("bookmark", "creer")) {
125  $mytxt .= ' '.$langs->trans("ClickToAdd");
126  }
127  $this->info_box_contents[$line][0] = array(
128  'td' => 'class="center" colspan="2"',
129  'tooltip' => $mytxt,
130  'url'=> DOL_URL_ROOT.'/bookmarks/list.php', 'text'=>$mytxt,
131  );
132  }
133 
134  $this->db->free($result);
135  } else {
136  $this->info_box_contents[0][0] = array(
137  'td' => '',
138  'maxlength'=>500,
139  'text' => ($this->db->error().' sql='.$sql),
140  );
141  }
142  } else {
143  $this->info_box_contents[0][0] = array(
144  'td' => 'class="nohover opacitymedium left"',
145  'text' => $langs->trans("ReadPermissionNotAllowed")
146  );
147  }
148  }
149 
158  public function showBox($head = null, $contents = null, $nooutput = 0)
159  {
160  return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
161  }
162 }
Class ModeleBoxes.
Class to manage the box to show bookmarks.
loadBox($max=5)
Load data for box to show them later.
__construct($db, $param)
Constructor.
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
$conf db
API class for accounts.
Definition: inc.php:41