2005-09-12 00:35:09 +02:00
|
|
|
<?php
|
2017-12-02 01:13:32 +01:00
|
|
|
/* Copyright (C) 2005-2017 Laurent Destailleur <eldy@users.sourceforge.net>
|
2015-01-25 01:20:58 +01:00
|
|
|
* Copyright (C) 2015 Frederic France <frederic.france@free.fr>
|
2005-09-12 00:35:09 +02: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 15:36:08 +01:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2005-09-12 00:35:09 +02: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 21:55:30 +02:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2005-09-12 00:35:09 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
2011-10-24 14:11:49 +02:00
|
|
|
* \file htdocs/core/boxes/box_bookmarks.php
|
2009-08-26 11:37:54 +02:00
|
|
|
* \ingroup bookmark
|
2010-07-21 13:57:52 +02:00
|
|
|
* \brief Module to generate box of bookmarks list
|
2009-08-26 11:37:54 +02:00
|
|
|
*/
|
2012-08-23 02:04:35 +02:00
|
|
|
include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
|
2005-09-12 00:35:09 +02:00
|
|
|
|
2012-01-26 13:49:15 +01:00
|
|
|
/**
|
|
|
|
|
* Class to manage the box to show bookmarks
|
|
|
|
|
*/
|
2012-01-28 17:22:02 +01:00
|
|
|
class box_bookmarks extends ModeleBoxes
|
|
|
|
|
{
|
2020-10-31 14:32:18 +01:00
|
|
|
public $boxcode = "bookmarks";
|
|
|
|
|
public $boximg = "bookmark";
|
|
|
|
|
public $boxlabel = "BoxMyLastBookmarks";
|
|
|
|
|
public $depends = array("bookmark");
|
2005-09-12 00:35:09 +02:00
|
|
|
|
2018-08-22 10:51:55 +02:00
|
|
|
/**
|
2020-10-31 14:32:18 +01:00
|
|
|
* @var DoliDB Database handler.
|
|
|
|
|
*/
|
|
|
|
|
public $db;
|
2019-02-09 15:24:21 +01:00
|
|
|
|
2020-10-31 14:32:18 +01:00
|
|
|
public $param;
|
2006-06-18 03:34:15 +02:00
|
|
|
|
2020-10-31 14:32:18 +01:00
|
|
|
public $info_box_head = array();
|
|
|
|
|
public $info_box_contents = array();
|
2009-08-26 11:37:54 +02:00
|
|
|
|
|
|
|
|
|
2017-06-12 14:09:00 +02:00
|
|
|
/**
|
|
|
|
|
* Constructor
|
|
|
|
|
*
|
|
|
|
|
* @param DoliDB $db Database handler
|
|
|
|
|
* @param string $param More parameters
|
|
|
|
|
*/
|
2019-02-28 00:15:32 +01:00
|
|
|
public function __construct($db, $param)
|
2017-06-12 14:09:00 +02:00
|
|
|
{
|
2020-10-31 14:32:18 +01:00
|
|
|
global $user;
|
2017-06-12 14:09:00 +02:00
|
|
|
|
2020-10-31 14:32:18 +01:00
|
|
|
$this->db = $db;
|
2017-06-12 14:09:00 +02:00
|
|
|
|
2020-10-31 14:32:18 +01:00
|
|
|
$this->hidden = !($user->rights->bookmark->lire);
|
2017-06-12 14:09:00 +02:00
|
|
|
}
|
|
|
|
|
|
2009-08-26 11:37:54 +02:00
|
|
|
/**
|
2020-10-31 14:32:18 +01:00
|
|
|
* Load data for box to show them later
|
|
|
|
|
*
|
|
|
|
|
* @param int $max Maximum number of records to load
|
|
|
|
|
* @return void
|
2009-08-26 11:37:54 +02:00
|
|
|
*/
|
2019-02-28 00:15:32 +01:00
|
|
|
public function loadBox($max = 5)
|
2009-08-26 11:37:54 +02:00
|
|
|
{
|
2019-09-23 18:39:21 +02:00
|
|
|
global $user, $langs, $conf;
|
2009-08-26 11:37:54 +02:00
|
|
|
$langs->load("boxes");
|
2011-06-17 21:14:47 +02:00
|
|
|
|
2019-11-13 19:35:39 +01:00
|
|
|
$this->max = $max;
|
2009-08-26 11:37:54 +02:00
|
|
|
|
2015-01-21 01:06:04 +01:00
|
|
|
$this->info_box_head = array(
|
2020-10-31 14:32:18 +01:00
|
|
|
'text' => $langs->trans("BoxMyLastBookmarks", $max),
|
|
|
|
|
'sublink' => DOL_URL_ROOT.'/bookmarks/list.php',
|
|
|
|
|
);
|
|
|
|
|
if ($user->rights->bookmark->creer) {
|
2019-11-13 19:35:39 +01:00
|
|
|
$this->info_box_head['subpicto'] = 'bookmark';
|
|
|
|
|
$this->info_box_head['subtext'] = $langs->trans("BookmarksManagement");
|
2020-05-21 15:05:19 +02:00
|
|
|
} else {
|
2019-11-13 19:35:39 +01:00
|
|
|
$this->info_box_head['subpicto'] = 'bookmark';
|
|
|
|
|
$this->info_box_head['subtext'] = $langs->trans("ListOfBookmark");
|
2009-08-26 11:37:54 +02:00
|
|
|
}
|
|
|
|
|
|
2021-02-23 22:03:23 +01:00
|
|
|
if ($user->rights->bookmark->lire) {
|
2009-08-26 11:37:54 +02:00
|
|
|
$sql = "SELECT b.title, b.url, b.target, b.favicon";
|
2019-11-13 19:35:39 +01:00
|
|
|
$sql .= " FROM ".MAIN_DB_PREFIX."bookmark as b";
|
2021-03-30 17:53:25 +02:00
|
|
|
$sql .= " WHERE fk_user = ".((int) $user->id);
|
2020-10-31 14:32:18 +01:00
|
|
|
$sql .= " AND b.entity = ".$conf->entity;
|
2019-11-13 19:35:39 +01:00
|
|
|
$sql .= $this->db->order("position", "ASC");
|
|
|
|
|
$sql .= $this->db->plimit($max, 0);
|
2009-08-26 11:37:54 +02:00
|
|
|
|
2019-09-23 18:39:21 +02:00
|
|
|
$result = $this->db->query($sql);
|
2021-02-23 22:03:23 +01:00
|
|
|
if ($result) {
|
2019-09-23 18:39:21 +02:00
|
|
|
$num = $this->db->num_rows($result);
|
2009-08-26 11:37:54 +02:00
|
|
|
|
2015-02-02 21:09:30 +01:00
|
|
|
$line = 0;
|
2009-08-26 11:37:54 +02:00
|
|
|
|
2020-10-31 14:32:18 +01: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++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($num == 0) {
|
|
|
|
|
$mytxt = $langs->trans("NoRecordedBookmarks");
|
2021-02-23 22:03:23 +01:00
|
|
|
if ($user->rights->bookmark->creer) {
|
|
|
|
|
$mytxt .= ' '.$langs->trans("ClickToAdd");
|
|
|
|
|
}
|
2020-10-31 14:32:18 +01:00
|
|
|
$this->info_box_contents[$line][0] = array(
|
|
|
|
|
'td' => 'class="center" colspan="2"',
|
|
|
|
|
'tooltip' => $mytxt,
|
|
|
|
|
'url'=> DOL_URL_ROOT.'/bookmarks/list.php', 'text'=>$mytxt,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->db->free($result);
|
|
|
|
|
} else {
|
|
|
|
|
$this->info_box_contents[0][0] = array(
|
|
|
|
|
'td' => '',
|
|
|
|
|
'maxlength'=>500,
|
|
|
|
|
'text' => ($this->db->error().' sql='.$sql),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$this->info_box_contents[0][0] = array(
|
|
|
|
|
'td' => 'class="nohover opacitymedium left"',
|
|
|
|
|
'text' => $langs->trans("ReadPermissionNotAllowed")
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Method to show box
|
|
|
|
|
*
|
|
|
|
|
* @param array $head Array with properties of box title
|
|
|
|
|
* @param array $contents Array with properties of box lines
|
|
|
|
|
* @param int $nooutput No print, only return string
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public function showBox($head = null, $contents = null, $nooutput = 0)
|
|
|
|
|
{
|
|
|
|
|
return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
|
|
|
|
|
}
|
2005-09-12 00:35:09 +02:00
|
|
|
}
|