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
|
2011-08-01 01:24:38 +02:00
|
|
|
* along with this program. If not, see <http://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
|
|
|
|
|
{
|
2009-08-26 11:37:54 +02:00
|
|
|
var $boxcode="bookmarks";
|
|
|
|
|
var $boximg="object_bookmark";
|
2013-01-15 17:06:53 +01:00
|
|
|
var $boxlabel="BoxMyLastBookmarks";
|
2009-08-26 11:37:54 +02:00
|
|
|
var $depends = array("bookmark");
|
2005-09-12 00:35:09 +02:00
|
|
|
|
2006-06-18 03:34:15 +02:00
|
|
|
var $db;
|
|
|
|
|
var $param;
|
|
|
|
|
|
2009-08-26 11:37:54 +02:00
|
|
|
var $info_box_head = array();
|
|
|
|
|
var $info_box_contents = array();
|
|
|
|
|
|
|
|
|
|
|
2017-06-12 14:09:00 +02:00
|
|
|
/**
|
|
|
|
|
* Constructor
|
|
|
|
|
*
|
|
|
|
|
* @param DoliDB $db Database handler
|
|
|
|
|
* @param string $param More parameters
|
|
|
|
|
*/
|
|
|
|
|
function __construct($db,$param)
|
|
|
|
|
{
|
|
|
|
|
global $user;
|
|
|
|
|
|
|
|
|
|
$this->db=$db;
|
|
|
|
|
|
|
|
|
|
$this->hidden=! ($user->rights->bookmark->lire);
|
|
|
|
|
}
|
|
|
|
|
|
2009-08-26 11:37:54 +02:00
|
|
|
/**
|
2011-11-23 18:28:14 +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
|
|
|
*/
|
|
|
|
|
function loadBox($max=5)
|
|
|
|
|
{
|
2013-12-10 11:33:27 +01:00
|
|
|
global $user, $langs, $db, $conf;
|
2009-08-26 11:37:54 +02:00
|
|
|
$langs->load("boxes");
|
2011-06-17 21:14:47 +02:00
|
|
|
|
2009-08-26 11:37:54 +02:00
|
|
|
$this->max=$max;
|
|
|
|
|
|
2015-01-21 01:06:04 +01:00
|
|
|
$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 11:37:54 +02: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;
|
2013-12-10 11:33:27 +01:00
|
|
|
$sql.= " AND b.entity = ".$conf->entity;
|
2010-06-08 10:55:48 +02:00
|
|
|
$sql.= $db->order("position","ASC");
|
|
|
|
|
$sql.= $db->plimit($max, 0);
|
2009-08-26 11:37:54 +02:00
|
|
|
|
|
|
|
|
$result = $db->query($sql);
|
|
|
|
|
if ($result)
|
|
|
|
|
{
|
|
|
|
|
$num = $db->num_rows($result);
|
|
|
|
|
|
2015-02-02 21:09:30 +01:00
|
|
|
$line = 0;
|
2009-08-26 11:37:54 +02:00
|
|
|
|
2015-02-02 21:09:30 +01:00
|
|
|
while ($line < $num) {
|
2015-01-21 01:06:04 +01:00
|
|
|
$objp = $db->fetch_object($result);
|
|
|
|
|
|
2015-02-02 21:09:30 +01:00
|
|
|
$this->info_box_contents[$line][0] = array(
|
2015-01-21 01:06:04 +01:00
|
|
|
'td' => 'align="left" width="16"',
|
|
|
|
|
'logo' => $this->boximg,
|
|
|
|
|
'url' => $objp->url,
|
|
|
|
|
'tooltip' => $objp->title,
|
|
|
|
|
'target' => $objp->target?'newtab':'',
|
|
|
|
|
);
|
2015-02-02 21:09:30 +01:00
|
|
|
$this->info_box_contents[$line][1] = array(
|
2017-03-10 11:22:27 +01:00
|
|
|
'td' => '',
|
2015-01-21 01:06:04 +01:00
|
|
|
'text' => $objp->title,
|
|
|
|
|
'url' => $objp->url,
|
|
|
|
|
'tooltip' => $objp->title,
|
|
|
|
|
'target' => $objp->target?'newtab':'',
|
|
|
|
|
);
|
|
|
|
|
|
2015-02-02 21:09:30 +01:00
|
|
|
$line++;
|
2015-01-21 01:06:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($num==0) {
|
|
|
|
|
$mytxt=$langs->trans("NoRecordedBookmarks");
|
|
|
|
|
if ($user->rights->bookmark->creer) $mytxt.=' '.$langs->trans("ClickToAdd");
|
2015-02-02 21:09:30 +01:00
|
|
|
$this->info_box_contents[$line][0] = array(
|
2015-01-21 01:06:04 +01:00
|
|
|
'td' => 'align="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 11:22:27 +01:00
|
|
|
'td' => '',
|
2015-01-21 01:06:04 +01:00
|
|
|
'maxlength'=>500,
|
|
|
|
|
'text' => ($db->error().' sql='.$sql),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$this->info_box_contents[0][0] = array(
|
2017-06-10 00:05:47 +02:00
|
|
|
'td' => 'align="left" class="nohover opacitymedium"',
|
|
|
|
|
'text' => $langs->trans("ReadPermissionNotAllowed")
|
2015-01-21 01:06:04 +01:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
2005-09-12 00:35:09 +02:00
|
|
|
|
2011-11-23 18:28:14 +01: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 13:57:10 +02:00
|
|
|
* @param int $nooutput No print, only return string
|
2017-06-12 14:09:00 +02:00
|
|
|
* @return string
|
2011-11-23 18:28:14 +01:00
|
|
|
*/
|
2016-06-27 13:57:10 +02:00
|
|
|
function showBox($head = null, $contents = null, $nooutput=0)
|
|
|
|
|
{
|
2017-06-12 14:09:00 +02:00
|
|
|
return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
|
2009-08-26 11:37:54 +02:00
|
|
|
}
|
2005-09-12 00:35:09 +02:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|