.
* ---------------------------------------------------------------------
*/
if (!defined('GLPI_ROOT')) {
die("Sorry. You can't access this file directly");
}
/**
* ITILSolution Class
**/
class ITILSolution extends CommonDBChild {
// From CommonDBTM
public $dohistory = true;
private $item = null;
static public $itemtype = 'itemtype'; // Class name or field name (start with itemtype) for link to Parent
static public $items_id = 'items_id'; // Field name
public static function getNameField() {
return 'id';
}
static function getTypeName($nb = 0) {
return _n('Solution', 'Solutions', $nb);
}
function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) {
if ($item->isNewItem()) {
return;
}
if ($item->maySolve()) {
$nb = 0;
$title = self::getTypeName(Session::getPluralNumber());
if ($_SESSION['glpishow_count_on_tabs']) {
$nb = self::countFor($item->getType(), $item->getID());
}
return self::createTabEntry($title, $nb);
}
}
static function canView() {
return Session::haveRight('ticket', READ)
|| Session::haveRight('change', READ)
|| Session::haveRight('problem', READ);
}
public static function canUpdate() {
//always true, will rely on ITILSolution::canUpdateItem
return true;
}
public function canUpdateItem() {
return $this->item->maySolve();
}
public static function canCreate() {
//always true, will rely on ITILSolution::canCreateItem
return true;
}
public function canCreateItem() {
$item = new $this->fields['itemtype'];
$item->getFromDB($this->fields['items_id']);
return $item->canSolve();
}
function canEdit($ID) {
return $this->item->maySolve();
}
function post_getFromDB() {
$this->item = new $this->fields['itemtype'];
$this->item->getFromDB($this->fields['items_id']);
}
/**
* Print the phone form
*
* @param $ID integer ID of the item
* @param $options array
* - item: CommonITILObject instance
* - kb_id_toload: load new item content from KB entry
*
* @return boolean item found
**/
function showForm($ID, $options = []) {
global $CFG_GLPI;
if ($this->isNewItem()) {
$this->getEmpty();
}
if (!isset($options['item']) && isset($options['parent'])) {
//when we came from aja/viewsubitem.php
$options['item'] = $options['parent'];
}
$options['formoptions'] = ($options['formoptions'] ?? '') . ' data-track-changes=true';
$item = $options['item'];
$this->item = $item;
$item->check($item->getID(), READ);
if ($item instanceof Ticket && $this->isNewItem()) {
$ti = new Ticket_Ticket();
$open_child = $ti->countOpenChildren($item->getID());
if ($open_child > 0) {
echo "
" . __('Warning: non closed children tickets depends on current ticket. Are you sure you want to close it?') . "
";
}
}
$canedit = $item->maySolve();
if (isset($options['kb_id_toload']) && $options['kb_id_toload'] > 0) {
$kb = new KnowbaseItem();
if ($kb->getFromDB($options['kb_id_toload'])) {
$this->fields['content'] = $kb->getField('answer');
}
}
// Alert if validation waiting
$validationtype = $item->getType().'Validation';
if (method_exists($validationtype, 'alertValidation') && $this->isNewItem()) {
$validationtype::alertValidation($item, 'solution');
}
if (!isset($options['noform'])) {
$this->showFormHeader($options);
}
$show_template = $canedit;
$rand_template = mt_rand();
$rand_text = $rand_type = 0;
if ($canedit) {
$rand_text = mt_rand();
$rand_type = mt_rand();
}
if ($show_template) {
echo "