2005-09-11 22:35:09 +00:00
|
|
|
<?php
|
2017-12-02 00:13:32 +00:00
|
|
|
/* Copyright (C) 2005-2017 Laurent Destailleur <eldy@users.sourceforge.net>
|
2025-06-20 13:48:58 +00:00
|
|
|
* Copyright (C) 2015-2025 Frédéric France <frederic.france@free.fr>
|
2026-04-20 10:36:21 +00:00
|
|
|
* Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
|
2005-09-11 22:35:09 +00:00
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
2013-01-16 14:36:08 +00:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2005-09-11 22:35:09 +00:00
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2019-09-23 19:55:30 +00:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2005-09-11 22:35:09 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
2011-10-24 12:11:49 +00:00
|
|
|
* \file htdocs/core/boxes/box_bookmarks.php
|
2009-08-26 09:37:54 +00:00
|
|
|
* \ingroup bookmark
|
2010-07-21 11:57:52 +00:00
|
|
|
* \brief Module to generate box of bookmarks list
|
2009-08-26 09:37:54 +00:00
|
|
|
*/
|
2012-08-23 00:04:35 +00:00
|
|
|
include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
|
2005-09-11 22:35:09 +00:00
|
|
|
|
2012-01-26 12:49:15 +00:00
|
|
|
/**
|
|
|
|
|
* Class to manage the box to show bookmarks
|
|
|
|
|
*/
|
2012-01-28 16:22:02 +00:00
|
|
|
class box_bookmarks extends ModeleBoxes
|
|
|
|
|
{
|
2020-10-31 13:32:18 +00:00
|
|
|
public $boxcode = "bookmarks";
|
|
|
|
|
public $boximg = "bookmark";
|
|
|
|
|
public $boxlabel = "BoxMyLastBookmarks";
|
|
|
|
|
public $depends = array("bookmark");
|
2005-09-11 22:35:09 +00:00
|
|
|
|
2017-06-12 12:09:00 +00:00
|
|
|
/**
|
|
|
|
|
* Constructor
|
|
|
|
|
*
|
|
|
|
|
* @param DoliDB $db Database handler
|
|
|
|
|
* @param string $param More parameters
|
|
|
|
|
*/
|
2026-04-20 10:36:21 +00:00
|
|
|
public function __construct($db, $param) // @phpstan-ignore constructor.unusedParameter
|
2017-06-12 12:09:00 +00:00
|
|
|
{
|
2020-10-31 13:32:18 +00:00
|
|
|
global $user;
|
2017-06-12 12:09:00 +00:00
|
|
|
|
2020-10-31 13:32:18 +00:00
|
|
|
$this->db = $db;
|
2017-06-12 12:09:00 +00:00
|
|
|
|
2024-02-09 14:58:49 +00:00
|
|
|
$this->hidden = !$user->hasRight('bookmark', 'lire');
|
2024-10-14 09:56:59 +00:00
|
|
|
$this->urltoaddentry = DOL_URL_ROOT.'/bookmarks/card.php?action=create';
|
|
|
|
|
$this->msgNoRecords = 'NoRecordedBookmarks';
|
2017-06-12 12:09:00 +00:00
|
|
|
}
|
|
|
|
|
|
2009-08-26 09:37:54 +00:00
|
|
|
/**
|
2020-10-31 13:32:18 +00:00
|
|
|
* Load data for box to show them later
|
|
|
|
|
*
|
|
|
|
|
* @param int $max Maximum number of records to load
|
|
|
|
|
* @return void
|
2009-08-26 09:37:54 +00:00
|
|
|
*/
|
2019-02-27 23:15:32 +00:00
|
|
|
public function loadBox($max = 5)
|
2009-08-26 09:37:54 +00:00
|
|
|
{
|
2019-09-23 16:39:21 +00:00
|
|
|
global $user, $langs, $conf;
|
2009-08-26 09:37:54 +00:00
|
|
|
$langs->load("boxes");
|
2011-06-17 19:14:47 +00:00
|
|
|
|
2019-11-13 18:35:39 +00:00
|
|
|
$this->max = $max;
|
2009-08-26 09:37:54 +00:00
|
|
|
|
2015-01-21 00:06:04 +00:00
|
|
|
$this->info_box_head = array(
|
2020-10-31 13:32:18 +00:00
|
|
|
'text' => $langs->trans("BoxMyLastBookmarks", $max),
|
|
|
|
|
'sublink' => DOL_URL_ROOT.'/bookmarks/list.php',
|
|
|
|
|
);
|
2022-12-09 13:27:43 +00:00
|
|
|
if ($user->hasRight("bookmark", "creer")) {
|
2019-11-13 18:35:39 +00:00
|
|
|
$this->info_box_head['subpicto'] = 'bookmark';
|
|
|
|
|
$this->info_box_head['subtext'] = $langs->trans("BookmarksManagement");
|
2020-05-21 13:05:19 +00:00
|
|
|
} else {
|
2019-11-13 18:35:39 +00:00
|
|
|
$this->info_box_head['subpicto'] = 'bookmark';
|
2025-06-20 13:48:58 +00:00
|
|
|
$this->info_box_head['subtext'] = $langs->trans("ListOfBookmarks");
|
2009-08-26 09:37:54 +00:00
|
|
|
}
|
|
|
|
|
|
2023-10-11 17:32:04 +00:00
|
|
|
if ($user->hasRight('bookmark', 'lire')) {
|
2009-08-26 09:37:54 +00:00
|
|
|
$sql = "SELECT b.title, b.url, b.target, b.favicon";
|
2019-11-13 18:35:39 +00:00
|
|
|
$sql .= " FROM ".MAIN_DB_PREFIX."bookmark as b";
|
2021-03-30 15:53:25 +00:00
|
|
|
$sql .= " WHERE fk_user = ".((int) $user->id);
|
2026-07-20 13:26:30 +00:00
|
|
|
$sql .= " AND b.entity = ".((int) $conf->entity);
|
2019-11-13 18:35:39 +00:00
|
|
|
$sql .= $this->db->order("position", "ASC");
|
|
|
|
|
$sql .= $this->db->plimit($max, 0);
|
2009-08-26 09:37:54 +00:00
|
|
|
|
2019-09-23 16:39:21 +00:00
|
|
|
$result = $this->db->query($sql);
|
2021-02-23 21:03:23 +00:00
|
|
|
if ($result) {
|
2019-09-23 16:39:21 +00:00
|
|
|
$num = $this->db->num_rows($result);
|
2009-08-26 09:37:54 +00:00
|
|
|
|
2015-02-02 20:09:30 +00:00
|
|
|
$line = 0;
|
2009-08-26 09:37:54 +00:00
|
|
|
|
2020-10-31 13:32:18 +00:00
|
|
|
while ($line < $num) {
|
|
|
|
|
$objp = $this->db->fetch_object($result);
|
|
|
|
|
|
|
|
|
|
$this->info_box_contents[$line][0] = array(
|
|
|
|
|
'td' => 'class="left" width="16"',
|
|
|
|
|
'logo' => $this->boximg,
|
|
|
|
|
'url' => $objp->url,
|
|
|
|
|
'tooltip' => $objp->title,
|
|
|
|
|
'target' => $objp->target ? 'newtab' : '',
|
|
|
|
|
);
|
|
|
|
|
$this->info_box_contents[$line][1] = array(
|
|
|
|
|
'td' => '',
|
|
|
|
|
'text' => $objp->title,
|
|
|
|
|
'url' => $objp->url,
|
|
|
|
|
'tooltip' => $objp->title,
|
|
|
|
|
'target' => $objp->target ? 'newtab' : '',
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$line++;
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-14 09:56:59 +00:00
|
|
|
// if ($num == 0) {
|
|
|
|
|
// $mytxt = $langs->trans("NoRecordedBookmarks");
|
|
|
|
|
// if ($user->hasRight("bookmark", "creer")) {
|
|
|
|
|
// $mytxt .= ' '.$langs->trans("ClickToAdd");
|
|
|
|
|
// }
|
|
|
|
|
// $this->info_box_contents[$line][0] = array(
|
|
|
|
|
// 'td' => 'class="center" colspan="2"',
|
|
|
|
|
// 'tooltip' => $mytxt,
|
|
|
|
|
// 'url' => DOL_URL_ROOT.'/bookmarks/list.php', 'text' => $mytxt,
|
|
|
|
|
// );
|
|
|
|
|
// }
|
2020-10-31 13:32:18 +00:00
|
|
|
|
|
|
|
|
$this->db->free($result);
|
|
|
|
|
} else {
|
|
|
|
|
$this->info_box_contents[0][0] = array(
|
|
|
|
|
'td' => '',
|
2024-08-18 16:16:08 +00:00
|
|
|
'maxlength' => 500,
|
2020-10-31 13:32:18 +00:00
|
|
|
'text' => ($this->db->error().' sql='.$sql),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$this->info_box_contents[0][0] = array(
|
2023-12-05 14:21:26 +00:00
|
|
|
'td' => 'class="nohover left"',
|
|
|
|
|
'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>'
|
2020-10-31 13:32:18 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-28 10:09:35 +00:00
|
|
|
|
|
|
|
|
|
2020-10-31 13:32:18 +00:00
|
|
|
/**
|
2024-09-28 10:09:35 +00:00
|
|
|
* Method to show box. Called when the box needs to be displayed.
|
2020-10-31 13:32:18 +00:00
|
|
|
*
|
2024-09-28 10:09:35 +00:00
|
|
|
* @param ?array<array{text?:string,sublink?:string,subtext?:string,subpicto?:?string,picto?:string,nbcol?:int,limit?:int,subclass?:string,graph?:int<0,1>,target?:string}> $head Array with properties of box title
|
|
|
|
|
* @param ?array<array{tr?:string,td?:string,target?:string,text?:string,text2?:string,textnoformat?:string,tooltip?:string,logo?:string,url?:string,maxlength?:int,asis?:int<0,1>}> $contents Array with properties of box lines
|
2024-08-18 16:16:08 +00:00
|
|
|
* @param int<0,1> $nooutput No print, only return string
|
2024-09-28 10:09:35 +00:00
|
|
|
* @return string
|
2020-10-31 13:32:18 +00:00
|
|
|
*/
|
|
|
|
|
public function showBox($head = null, $contents = null, $nooutput = 0)
|
|
|
|
|
{
|
|
|
|
|
return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
|
|
|
|
|
}
|
2005-09-11 22:35:09 +00:00
|
|
|
}
|