grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026. -------------------------------------------------------------------------- */ /** @file * @brief */ if (!defined('GLPI_ROOT')) { die("Sorry. You can't access this file directly"); } /** * Notepad class * * @since version 0.85 **/ class Notepad extends CommonDBChild { // From CommonDBChild static public $itemtype = 'itemtype'; static public $items_id = 'items_id'; public $dohistory = false; public $auto_message_on_action = false; // Link in message can't work' static public $logs_for_parent = true; static function getTypeName($nb=0) { //TRANS: Always plural return _n('Note', 'Notes', $nb); } function getLogTypeID() { return array($this->fields['itemtype'], $this->fields['items_id']); } function canCreateItem() { if (isset($this->fields['itemtype']) && ($item = getItemForItemtype($this->fields['itemtype']))) { return Session::haveRight($item::$rightname, UPDATENOTE); } return false; } function canUpdateItem() { if (isset($this->fields['itemtype']) && ($item = getItemForItemtype($this->fields['itemtype']))) { return Session::haveRight($item::$rightname, UPDATENOTE); } return false; } function prepareInputForAdd($input) { $input['users_id'] = Session::getLoginUserID(); $input['users_id_lastupdater'] = Session::getLoginUserID(); $input['date'] = $_SESSION['glpi_currenttime']; return $input; } function prepareInputForUpdate($input) { $input['users_id_lastupdater'] = Session::getLoginUserID(); return $input; } /** * @see CommonGLPI::getTabNameForItem() **/ function getTabNameForItem(CommonGLPI $item, $withtemplate=0) { if (Session::haveRight($item::$rightname, READNOTE)) { $nb = 0; if ($_SESSION['glpishow_count_on_tabs']) { $nb = self::countForItem($item); } return self::createTabEntry(self::getTypeName(Session::getPluralNumber()), $nb); } return false; } /** * @param $item CommonGLPI object * @param $tabnum (default 1) * @param $withtemplate (default 0) **/ static function displayTabContentForItem(CommonGLPI $item, $tabnum=1, $withtemplate=0) { static::showForItem($item); } /** * @param $item CommonDBTM object * * @return number **/ static function countForItem(CommonDBTM $item) { return countElementsInTable('glpi_notepads', "`itemtype` = '".$item->getType()."' AND `items_id` = '".$item->getID()."'"); } /** * @param $item CommonDBTM object **/ static function getAllForItem(CommonDBTM $item) { global $DB; $data = array(); $query = "SELECT `glpi_notepads`.*, `glpi_users`.`picture` FROM `glpi_notepads` LEFT JOIN `glpi_users` ON (`glpi_notepads`.`users_id_lastupdater` = `glpi_users`.`id`) WHERE `glpi_notepads`.`itemtype` = '".$item->getType()."' AND `glpi_notepads`.`items_id` = '".$item->getID()."' ORDER BY `date_mod` DESC"; foreach($DB->request($query) as $note) { $data[] = $note; } return $data; } /** * @since version 0.85 **/ static function getSearchOptionsToAdd() { $tab = array(); $tab['notepad'] = _n('Note', 'Notes', Session::getPluralNumber()); $tab[200]['table'] = 'glpi_notepads'; $tab[200]['field'] = 'content'; $tab[200]['name'] = _n('Note', 'Notes', Session::getPluralNumber()); $tab[200]['datatype'] = 'text'; $tab[200]['joinparams'] = array('jointype' => 'itemtype_item'); $tab[200]['forcegroupby'] = true; $tab[200]['splititems'] = true; $tab[200]['massiveaction'] = false; $tab[201]['table'] = 'glpi_notepads'; $tab[201]['field'] = 'date'; $tab[201]['name'] = __('Creation date'); $tab[201]['datatype'] = 'datetime'; $tab[201]['joinparams'] = array('jointype' => 'itemtype_item'); $tab[201]['forcegroupby'] = true; $tab[201]['massiveaction'] = false; $tab[202]['table'] = 'glpi_users'; $tab[202]['field'] = 'name'; $tab[202]['name'] = __('Writer'); $tab[202]['datatype'] = 'dropdown'; $tab[202]['forcegroupby'] = true; $tab[202]['massiveaction'] = false; $tab[202]['joinparams'] = array('beforejoin' => array('table' => 'glpi_notepads', 'joinparams' => array('jointype' => 'itemtype_item'))); $tab[203]['table'] = 'glpi_notepads'; $tab[203]['field'] = 'date_mod'; $tab[203]['name'] = __('Last update'); $tab[203]['datatype'] = 'datetime'; $tab[203]['joinparams'] = array('jointype' => 'itemtype_item'); $tab[203]['forcegroupby'] = true; $tab[203]['massiveaction'] = false; $tab[204]['table'] = 'glpi_users'; $tab[204]['field'] = 'name'; $tab[204]['linkfield'] = 'users_id_lastupdater'; $tab[204]['name'] = __('Last updater'); $tab[204]['datatype'] = 'dropdown'; $tab[204]['forcegroupby'] = true; $tab[204]['massiveaction'] = false; $tab[204]['joinparams'] = array('beforejoin' => array('table' => 'glpi_notepads', 'joinparams' => array('jointype' => 'itemtype_item'))); return $tab; } /** * Show notepads for an item * * @param $item CommonDBTM object * @param $withtemplate integer template or basic item (default '') **/ static function showForItem(CommonDBTM $item, $withtemplate='') { global $CFG_GLPI; if (!Session::haveRight($item::$rightname, READNOTE)) { return false; } $notes = static::getAllForItem($item); $rand = mt_rand(); $canedit = Session::haveRight($item::$rightname, UPDATENOTE); $showuserlink = 0; if (User::canView()) { $showuserlink = 1; } if ($canedit) { echo "
"; echo "
"; echo "
"; echo Html::hidden('itemtype', array('value' => $item->getType())); echo Html::hidden('items_id', array('value' => $item->getID())); echo "
"; echo "
"; echo ""; echo "
"; echo "
"; // box notecontent echo "

"; echo Html::submit(_x('button','Add'), array('name' => 'add')); echo "
"; Html::closeForm(); echo "
"; // boxnote } if (count($notes)) { foreach ($notes as $note) { $id = 'note'.$note['id'].$rand; $classtoadd = ''; if ($canedit) { $classtoadd = " pointer"; } echo "
"; echo "
"; echo "\"".__s('Picture')."\""; echo "
"; // boxnoteleft echo "
"; echo "
"; $username = NOT_AVAILABLE; if ($note['users_id_lastupdater']) { $username = getUserName($note['users_id_lastupdater'], $showuserlink); } $update = sprintf(__('Last update by %1$s on %2$s'), $username, Html::convDateTime($note['date_mod'])); $username = NOT_AVAILABLE; if ($note['users_id']) { $username = getUserName($note['users_id'], $showuserlink); } $create = sprintf(__('Create by %1$s on %2$s'), $username, Html::convDateTime($note['date'])); printf(__('%1$s / %2$s'), $update, $create); echo "
"; // floatright echo "
"; $content = nl2br($note['content']); if (empty($content)) $content = NOT_AVAILABLE; echo $content.'
'; // boxnotetext echo "
"; // boxnotecontent echo "
"; if ($canedit) { Html::showSimpleForm(Toolbox::getItemTypeFormURL('Notepad'), array('purge' => 'purge'), _x('button', 'Delete permanently'), array('id' => $note['id']), $CFG_GLPI["root_doc"]."/pics/delete.png", '', __('Confirm the final deletion?')); } echo "
"; // boxnoteright echo "
"; // boxnote if ($canedit) { echo "
"; echo ""; echo "
"; echo "
"; echo Html::hidden('id', array('value' => $note['id'])); echo ""; echo "
"; // boxnotecontent echo "

"; echo Html::submit(_x('button','Update'), array('name' => 'update')); echo "
"; // boxnoteright Html::closeForm(); echo "
"; // boxnote } } } return true; } } ?>