dolibarr 25.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-2025 Frédéric France <frederic.france@free.fr>
4 * Copyright (C) 2024-2026 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) // @phpstan-ignore constructor.unusedParameter
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("ListOfBookmarks");
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 // The widget shows the caller's own bookmarks plus the global ones
83 // (fk_user NULL or 0), the same filter the bookmarks list applies to
84 // a non-admin user — not the bookmarks of other users.
85 $sql .= " WHERE (fk_user = ".((int) $user->id)." OR fk_user IS NULL OR fk_user = 0)";
86 $sql .= " AND b.entity = ".((int) $conf->entity);
87 $sql .= $this->db->order("position", "ASC");
88 $sql .= $this->db->plimit($max, 0);
89
90 $result = $this->db->query($sql);
91 if ($result) {
92 $num = $this->db->num_rows($result);
93
94 $line = 0;
95
96 while ($line < $num) {
97 $objp = $this->db->fetch_object($result);
98
99 $this->info_box_contents[$line][0] = array(
100 'td' => 'class="left" width="16"',
101 'logo' => $this->boximg,
102 'url' => $objp->url,
103 'tooltip' => $objp->title,
104 'target' => $objp->target ? 'newtab' : '',
105 );
106 $this->info_box_contents[$line][1] = array(
107 'td' => '',
108 'text' => $objp->title,
109 'url' => $objp->url,
110 'tooltip' => $objp->title,
111 'target' => $objp->target ? 'newtab' : '',
112 );
113
114 $line++;
115 }
116
117 // if ($num == 0) {
118 // $mytxt = $langs->trans("NoRecordedBookmarks");
119 // if ($user->hasRight("bookmark", "creer")) {
120 // $mytxt .= ' '.$langs->trans("ClickToAdd");
121 // }
122 // $this->info_box_contents[$line][0] = array(
123 // 'td' => 'class="center" colspan="2"',
124 // 'tooltip' => $mytxt,
125 // 'url' => DOL_URL_ROOT.'/bookmarks/list.php', 'text' => $mytxt,
126 // );
127 // }
128
129 $this->db->free($result);
130 } else {
131 $this->info_box_contents[0][0] = array(
132 'td' => '',
133 'maxlength' => 500,
134 'text' => ($this->db->error().' sql='.$sql),
135 );
136 }
137 } else {
138 $this->info_box_contents[0][0] = array(
139 'td' => 'class="nohover left"',
140 'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>'
141 );
142 }
143 }
144
145
146
155 public function showBox($head = null, $contents = null, $nooutput = 0)
156 {
157 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
158 }
159}
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
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.