dolibarr/htdocs/core/boxes/box_bookmarks.php

165 lines
5 KiB
PHP
Raw Normal View History

2005-09-11 22:35:09 +00:00
<?php
/* Copyright (C) 2005-2017 Laurent Destailleur <eldy@users.sourceforge.net>
2015-01-25 00:20:58 +00:00
* Copyright (C) 2015 Frederic France <frederic.france@free.fr>
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
* 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
2011-07-31 23:24:38 +00:00
* along with this program. If not, see <http://www.gnu.org/licenses/>.
2005-09-11 22:35:09 +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
*/
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
{
2009-08-26 09:37:54 +00:00
var $boxcode="bookmarks";
var $boximg="object_bookmark";
var $boxlabel="BoxMyLastBookmarks";
2009-08-26 09:37:54 +00:00
var $depends = array("bookmark");
2005-09-11 22:35:09 +00:00
2018-08-22 08:51:55 +00:00
/**
* @var DoliDB Database handler.
*/
public $db;
2019-02-09 14:24:21 +00:00
var $param;
2009-08-26 09:37:54 +00:00
var $info_box_head = array();
var $info_box_contents = array();
2017-06-12 12:09:00 +00:00
/**
* Constructor
*
* @param DoliDB $db Database handler
* @param string $param More parameters
*/
function __construct($db, $param)
2017-06-12 12:09:00 +00:00
{
global $user;
$this->db=$db;
$this->hidden=! ($user->rights->bookmark->lire);
}
2009-08-26 09:37:54 +00:00
/**
2011-11-23 17:28:14 +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
*/
function loadBox($max = 5)
2009-08-26 09:37:54 +00:00
{
global $user, $langs, $db, $conf;
2009-08-26 09:37:54 +00:00
$langs->load("boxes");
2011-06-17 19:14:47 +00:00
2009-08-26 09:37:54 +00:00
$this->max=$max;
$this->info_box_head = array(
'text' => $langs->trans("BoxMyLastBookmarks", $max),
'sublink' => DOL_URL_ROOT.'/bookmarks/list.php',
);
if ($user->rights->bookmark->creer) {
2009-08-26 09:37:54 +00:00
$this->info_box_head['subpicto']='object_bookmark';
$this->info_box_head['subtext']=$langs->trans("BookmarksManagement");
}
else
{
$this->info_box_head['subpicto']='object_bookmark';
$this->info_box_head['subtext']=$langs->trans("ListOfBookmark");
}
if ($user->rights->bookmark->lire)
{
$sql = "SELECT b.title, b.url, b.target, b.favicon";
$sql.= " FROM ".MAIN_DB_PREFIX."bookmark as b";
$sql.= " WHERE fk_user = ".$user->id;
$sql.= " AND b.entity = ".$conf->entity;
$sql.= $db->order("position", "ASC");
2010-06-08 08:55:48 +00:00
$sql.= $db->plimit($max, 0);
2009-08-26 09:37:54 +00:00
$result = $db->query($sql);
if ($result)
{
$num = $db->num_rows($result);
2015-02-02 20:09:30 +00:00
$line = 0;
2009-08-26 09:37:54 +00:00
2015-02-02 20:09:30 +00:00
while ($line < $num) {
$objp = $db->fetch_object($result);
2015-02-02 20:09:30 +00:00
$this->info_box_contents[$line][0] = array(
2019-02-09 14:24:21 +00:00
'td' => 'class="left" width="16"',
'logo' => $this->boximg,
'url' => $objp->url,
'tooltip' => $objp->title,
'target' => $objp->target?'newtab':'',
);
2015-02-02 20:09:30 +00:00
$this->info_box_contents[$line][1] = array(
2017-03-10 10:22:27 +00:00
'td' => '',
'text' => $objp->title,
'url' => $objp->url,
'tooltip' => $objp->title,
'target' => $objp->target?'newtab':'',
);
2015-02-02 20:09:30 +00:00
$line++;
}
if ($num==0) {
$mytxt=$langs->trans("NoRecordedBookmarks");
if ($user->rights->bookmark->creer) $mytxt.=' '.$langs->trans("ClickToAdd");
2015-02-02 20:09:30 +00:00
$this->info_box_contents[$line][0] = array(
2019-02-09 14:24:21 +00:00
'td' => 'class="center" colspan="2"',
'tooltip' => $mytxt,
'url'=> DOL_URL_ROOT.'/bookmarks/list.php', 'text'=>$mytxt,
);
}
$db->free($result);
} else {
$this->info_box_contents[0][0] = array(
2017-03-10 10:22:27 +00:00
'td' => '',
'maxlength'=>500,
'text' => ($db->error().' sql='.$sql),
);
}
} else {
$this->info_box_contents[0][0] = array(
2019-02-09 14:24:21 +00:00
'td' => 'class="nohover opacitymedium left"',
'text' => $langs->trans("ReadPermissionNotAllowed")
);
}
}
2005-09-11 22:35:09 +00:00
2011-11-23 17:28:14 +00:00
/**
* Method to show box
*
* @param array $head Array with properties of box title
* @param array $contents Array with properties of box lines
2016-06-27 11:57:10 +00:00
* @param int $nooutput No print, only return string
2017-06-12 12:09:00 +00:00
* @return string
2011-11-23 17:28:14 +00:00
*/
function showBox($head = null, $contents = null, $nooutput = 0)
2016-06-27 11:57:10 +00:00
{
2017-06-12 12:09:00 +00:00
return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
2009-08-26 09:37:54 +00:00
}
2005-09-11 22:35:09 +00:00
}