dolibarr 21.0.0-alpha
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
24include_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
42 public function __construct($db, $param)
43 {
44 global $user;
45
46 $this->db = $db;
47
48 $this->hidden = !$user->hasRight('bookmark', 'lire');
49 }
50
57 public function loadBox($max = 5)
58 {
59 global $user, $langs, $conf;
60 $langs->load("boxes");
61
62 $this->max = $max;
63
64 $this->info_box_head = array(
65 'text' => $langs->trans("BoxMyLastBookmarks", $max),
66 'sublink' => DOL_URL_ROOT.'/bookmarks/list.php',
67 );
68 if ($user->hasRight("bookmark", "creer")) {
69 $this->info_box_head['subpicto'] = 'bookmark';
70 $this->info_box_head['subtext'] = $langs->trans("BookmarksManagement");
71 } else {
72 $this->info_box_head['subpicto'] = 'bookmark';
73 $this->info_box_head['subtext'] = $langs->trans("ListOfBookmark");
74 }
75
76 if ($user->hasRight('bookmark', 'lire')) {
77 $sql = "SELECT b.title, b.url, b.target, b.favicon";
78 $sql .= " FROM ".MAIN_DB_PREFIX."bookmark as b";
79 $sql .= " WHERE fk_user = ".((int) $user->id);
80 $sql .= " AND b.entity = ".$conf->entity;
81 $sql .= $this->db->order("position", "ASC");
82 $sql .= $this->db->plimit($max, 0);
83
84 $result = $this->db->query($sql);
85 if ($result) {
86 $num = $this->db->num_rows($result);
87
88 $line = 0;
89
90 while ($line < $num) {
91 $objp = $this->db->fetch_object($result);
92
93 $this->info_box_contents[$line][0] = array(
94 'td' => 'class="left" width="16"',
95 'logo' => $this->boximg,
96 'url' => $objp->url,
97 'tooltip' => $objp->title,
98 'target' => $objp->target ? 'newtab' : '',
99 );
100 $this->info_box_contents[$line][1] = array(
101 'td' => '',
102 'text' => $objp->title,
103 'url' => $objp->url,
104 'tooltip' => $objp->title,
105 'target' => $objp->target ? 'newtab' : '',
106 );
107
108 $line++;
109 }
110
111 if ($num == 0) {
112 $mytxt = $langs->trans("NoRecordedBookmarks");
113 if ($user->hasRight("bookmark", "creer")) {
114 $mytxt .= ' '.$langs->trans("ClickToAdd");
115 }
116 $this->info_box_contents[$line][0] = array(
117 'td' => 'class="center" colspan="2"',
118 'tooltip' => $mytxt,
119 'url'=> DOL_URL_ROOT.'/bookmarks/list.php', 'text'=>$mytxt,
120 );
121 }
122
123 $this->db->free($result);
124 } else {
125 $this->info_box_contents[0][0] = array(
126 'td' => '',
127 'maxlength'=>500,
128 'text' => ($this->db->error().' sql='.$sql),
129 );
130 }
131 } else {
132 $this->info_box_contents[0][0] = array(
133 'td' => 'class="nohover left"',
134 'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>'
135 );
136 }
137 }
138
147 public function showBox($head = null, $contents = null, $nooutput = 0)
148 {
149 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
150 }
151}
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.