grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026.
--------------------------------------------------------------------------
*/
/** @file
* @brief
*/
if (!defined('GLPI_ROOT')) {
die("Sorry. You can't access this file directly");
}
/**
* Bookmark class
**/
class Bookmark extends CommonDBTM {
// From CommonGLPI
public $taborientation = 'horizontal';
public $auto_message_on_action = false;
protected $displaylist = false;
static $rightname = 'bookmark_public';
const WIDTH = 750;
const SEARCH = 1; //SEARCH SYSTEM bookmark
const URI = 2;
/**
* @since version 0.84
*
* @return string
**/
function getForbiddenStandardMassiveAction() {
$forbidden = parent::getForbiddenStandardMassiveAction();
$forbidden[] = 'update';
return $forbidden;
}
/**
* @since version 0.85
*
* @see CommonDBTM::getSpecificMassiveActions()
**/
function getSpecificMassiveActions($checkitem=NULL) {
$actions[__CLASS__.MassiveAction::CLASS_ACTION_SEPARATOR.'move_bookmark'] = __('Move');
return $actions;
}
/**
* @since version 0.85
*
* @see CommonDBTM::showMassiveActionsSubForm()
**/
static function showMassiveActionsSubForm(MassiveAction $ma) {
global $CFG_GLPI;
switch ($ma->getAction()) {
case 'move_bookmark' :
$values = array('after' => __('After'),
'before' => __('Before'));
Dropdown::showFromArray('move_type', $values, array('width' => '20%'));
$param = array('name' => "bookmarks_id_ref",
'width' => '50%');
$param['condition'] = "(`is_private`='1' AND `users_id`='".Session::getLoginUserID()."') ";
$param['entity'] = -1;
Bookmark::dropdown($param);
echo "
\n";
echo Html::submit(_x('button', 'Move'), array('name' => 'massiveaction'))."";
return true;
}
return parent::showMassiveActionsSubForm($ma);
}
/**
* @since version 0.85
*
* @see CommonDBTM::processMassiveActionsForOneItemtype()
**/
static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item,
array $ids) {
global $DB;
switch ($ma->getAction()) {
case 'move_bookmark' :
$input = $ma->getInput();
if ($item->moveBookmark($ids, $input['bookmarks_id_ref'],
$input['move_type'])) {
$ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_OK);
} else {
$ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_KO);
}
return;
}
parent::processMassiveActionsForOneItemtype($ma, $item, $ids);
}
/**
* Special case: a private bookmark has entities_id==-1 => we cannot check it
* @see CommonDBTM::canCreateItem()
*
* @since version 0.85
**/
function canCreateItem() {
if (($this->fields['is_private'] == 1)
&& ($this->fields['users_id'] == Session::getLoginUserID())) {
return true;
}
return parent::canCreateItem();
}
/**
* Special case: a private bookmark has entities_id==-1 => we cannot check it
* @see CommonDBTM::canViewItem()
*
* @since version 0.85
**/
function canViewItem() {
if (($this->fields['is_private'] == 1)
&& ($this->fields['users_id'] == Session::getLoginUserID())) {
return true;
}
return parent::canViewItem();
}
function isNewItem() {
/// For tabs management : force isNewItem
return false;
}
function defineTabs($options=array()) {
$ong = array();
$this->addStandardTab(__CLASS__, $ong, $options);
$ong['no_all_tab'] = true;
return $ong;
}
function getTabNameForItem(CommonGLPI $item, $withtemplate=0) {
switch ($item->getType()) {
case __CLASS__:
$ong = array();
$ong[1] = __('Personal');
if (self::canView()) {
$ong[2] = __('Public');
}
return $ong;
}
return '';
}
static function displayTabContentForItem(CommonGLPI $item, $tabnum=1, $withtemplate=0) {
switch ($item->getType()) {
case __CLASS__ :
$is_private = 1;
if ($tabnum == 2) {
$is_private = 0;
}
$item->showBookmarkList($_GET['_target'], $is_private);
return true;
}
return false;
}
function prepareInputForAdd($input) {
if (!isset($input['url']) || !isset($input['type'])) {
return false;
}
$taburl = parse_url(rawurldecode($input['url']));
$index = strpos($taburl["path"], "plugins");
if (!$index) {
$index = strpos($taburl["path"], "front");
}
$input['path'] = Toolbox::substr($taburl["path"], $index,
Toolbox::strlen($taburl["path"]) - $index);
$query_tab = array();
if (isset($taburl["query"])) {
parse_str($taburl["query"], $query_tab);
}
$input['query'] = Toolbox::append_params($this->prepareQueryToStore($input['type'],
$query_tab, $input['itemtype']));
return $input;
}
function pre_updateInDB() {
// Set new user if initial user have been deleted
if (($this->fields['users_id'] == 0)
&& $uid=Session::getLoginUserID()) {
$this->input['users_id'] = $uid;
$this->fields['users_id'] = $uid;
$this->updates[] = "users_id";
}
}
function post_getEmpty() {
$this->fields["users_id"] = Session::getLoginUserID();
$this->fields["is_private"] = 1;
$this->fields["is_recursive"] = 0;
$this->fields["entities_id"] = $_SESSION["glpiactive_entity"];
}
function cleanDBonPurge() {
global $DB;
$query="DELETE
FROM `glpi_bookmarks_users`
WHERE `bookmarks_id` = '".$this->fields['id']."'";
$DB->query($query);
}
/**
* Print the bookmark form
*
* @param $ID integer ID of the item
* @param $options array
* - target for the Form
* - type bookmark type when adding a new bookmark
* - url when adding a new bookmark
* - itemtype when adding a new bookmark
**/
function showForm($ID, $options=array()) {
global $CFG_GLPI;
$ID = $this->fields['id'];
// Only an edit form : always check w right
if ($ID > 0) {
$this->check($ID, UPDATE);
} else {
$this->check(-1, CREATE);
}
echo '
';
echo "