dolibarr  7.0.0-beta
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 
36  var $db;
37  var $param;
38 
39  var $info_box_head = array();
40  var $info_box_contents = array();
41 
42 
49  function __construct($db,$param)
50  {
51  global $user;
52 
53  $this->db=$db;
54 
55  $this->hidden=! ($user->rights->bookmark->lire);
56  }
57 
64  function loadBox($max=5)
65  {
66  global $user, $langs, $db, $conf;
67  $langs->load("boxes");
68 
69  $this->max=$max;
70 
71  $this->info_box_head = array(
72  'text' => $langs->trans("BoxMyLastBookmarks",$max),
73  'sublink' => DOL_URL_ROOT.'/bookmarks/list.php',
74  );
75  if ($user->rights->bookmark->creer) {
76  $this->info_box_head['subpicto']='object_bookmark';
77  $this->info_box_head['subtext']=$langs->trans("BookmarksManagement");
78  }
79  else
80  {
81  $this->info_box_head['subpicto']='object_bookmark';
82  $this->info_box_head['subtext']=$langs->trans("ListOfBookmark");
83  }
84 
85  if ($user->rights->bookmark->lire)
86  {
87  $sql = "SELECT b.title, b.url, b.target, b.favicon";
88  $sql.= " FROM ".MAIN_DB_PREFIX."bookmark as b";
89  $sql.= " WHERE fk_user = ".$user->id;
90  $sql.= " AND b.entity = ".$conf->entity;
91  $sql.= $db->order("position","ASC");
92  $sql.= $db->plimit($max, 0);
93 
94  $result = $db->query($sql);
95  if ($result)
96  {
97  $num = $db->num_rows($result);
98 
99  $line = 0;
100 
101  while ($line < $num) {
102  $objp = $db->fetch_object($result);
103 
104  $this->info_box_contents[$line][0] = array(
105  'td' => 'align="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->rights->bookmark->creer) $mytxt.=' '.$langs->trans("ClickToAdd");
125  $this->info_box_contents[$line][0] = array(
126  'td' => 'align="center" colspan="2"',
127  'tooltip' => $mytxt,
128  'url'=> DOL_URL_ROOT.'/bookmarks/list.php', 'text'=>$mytxt,
129  );
130  }
131 
132  $db->free($result);
133  } else {
134  $this->info_box_contents[0][0] = array(
135  'td' => '',
136  'maxlength'=>500,
137  'text' => ($db->error().' sql='.$sql),
138  );
139  }
140  } else {
141  $this->info_box_contents[0][0] = array(
142  'td' => 'align="left" class="nohover opacitymedium"',
143  'text' => $langs->trans("ReadPermissionNotAllowed")
144  );
145  }
146  }
147 
156  function showBox($head = null, $contents = null, $nooutput=0)
157  {
158  return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
159  }
160 
161 }
162 
__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.