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-2024 Frédéric France <frederic.france@free.fr>
4 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
25include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
26
31{
32 public $boxcode = "bookmarks";
33 public $boximg = "bookmark";
34 public $boxlabel = "BoxMyLastBookmarks";
35 public $depends = array("bookmark");
36
43 public function __construct($db, $param)
44 {
45 global $user;
46
47 $this->db = $db;
48
49 $this->hidden = !$user->hasRight('bookmark', 'lire');
50 $this->urltoaddentry = DOL_URL_ROOT.'/bookmarks/card.php?action=create';
51 $this->msgNoRecords = 'NoRecordedBookmarks';
52 }
53
60 public function loadBox($max = 5)
61 {
62 global $user, $langs, $conf;
63 $langs->load("boxes");
64
65 $this->max = $max;
66
67 $this->info_box_head = array(
68 'text' => $langs->trans("BoxMyLastBookmarks", $max),
69 'sublink' => DOL_URL_ROOT.'/bookmarks/list.php',
70 );
71 if ($user->hasRight("bookmark", "creer")) {
72 $this->info_box_head['subpicto'] = 'bookmark';
73 $this->info_box_head['subtext'] = $langs->trans("BookmarksManagement");
74 } else {
75 $this->info_box_head['subpicto'] = 'bookmark';
76 $this->info_box_head['subtext'] = $langs->trans("ListOfBookmark");
77 }
78
79 if ($user->hasRight('bookmark', 'lire')) {
80 $sql = "SELECT b.title, b.url, b.target, b.favicon";
81 $sql .= " FROM ".MAIN_DB_PREFIX."bookmark as b";
82 $sql .= " WHERE fk_user = ".((int) $user->id);
83 $sql .= " AND b.entity = ".$conf->entity;
84 $sql .= $this->db->order("position", "ASC");
85 $sql .= $this->db->plimit($max, 0);
86
87 $result = $this->db->query($sql);
88 if ($result) {
89 $num = $this->db->num_rows($result);
90
91 $line = 0;
92
93 while ($line < $num) {
94 $objp = $this->db->fetch_object($result);
95
96 $this->info_box_contents[$line][0] = array(
97 'td' => 'class="left" width="16"',
98 'logo' => $this->boximg,
99 'url' => $objp->url,
100 'tooltip' => $objp->title,
101 'target' => $objp->target ? 'newtab' : '',
102 );
103 $this->info_box_contents[$line][1] = array(
104 'td' => '',
105 'text' => $objp->title,
106 'url' => $objp->url,
107 'tooltip' => $objp->title,
108 'target' => $objp->target ? 'newtab' : '',
109 );
110
111 $line++;
112 }
113
114 // if ($num == 0) {
115 // $mytxt = $langs->trans("NoRecordedBookmarks");
116 // if ($user->hasRight("bookmark", "creer")) {
117 // $mytxt .= ' '.$langs->trans("ClickToAdd");
118 // }
119 // $this->info_box_contents[$line][0] = array(
120 // 'td' => 'class="center" colspan="2"',
121 // 'tooltip' => $mytxt,
122 // 'url' => DOL_URL_ROOT.'/bookmarks/list.php', 'text' => $mytxt,
123 // );
124 // }
125
126 $this->db->free($result);
127 } else {
128 $this->info_box_contents[0][0] = array(
129 'td' => '',
130 'maxlength' => 500,
131 'text' => ($this->db->error().' sql='.$sql),
132 );
133 }
134 } else {
135 $this->info_box_contents[0][0] = array(
136 'td' => 'class="nohover left"',
137 'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>'
138 );
139 }
140 }
141
142
143
152 public function showBox($head = null, $contents = null, $nooutput = 0)
153 {
154 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
155 }
156}
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.