Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
GLPI
glpi
Commits
f44f64c0
Commit
f44f64c0
authored
Jun 13, 2019
by
Johan Cwiklinski
Committed by
Johan Cwiklinski
Jun 17, 2019
Browse files
Rename TicketTemplate to ITILTemplate
Migrate database schema
parent
08470784
Changes
33
Expand all
Hide whitespace changes
Inline
Side-by-side
CHANGELOG.md
View file @
f44f64c0
...
...
@@ -34,6 +34,8 @@ The present file will list all changes made to the project; according to the
-
`DBMysql::isMySQLStrictMode()`
-
`getAllDatasFromTable`
renamed to
`getAllDataFromTable()`
-
Usage of
`$order`
parameter in
`getAllDataFromTable()`
(
`DbUtils::getAllDataFromTable()`
)
-
All
`TicketTemplate`
classes has been renamed to
`ITILTemplate`
-
`Ticket::getTicketTemplateToUse()`
renamed to
`Ticket::getITILTemplateToUse()`
#### Removed
...
...
front/
ticket
template.form.php
→
front/
itil
template.form.php
View file @
f44f64c0
...
...
@@ -32,5 +32,5 @@
include
(
'../inc/includes.php'
);
$dropdown
=
new
Ticket
Template
();
$dropdown
=
new
ITIL
Template
();
include
(
GLPI_ROOT
.
"/front/dropdown.common.form.php"
);
front/
ticket
template.php
→
front/
itil
template.php
View file @
f44f64c0
...
...
@@ -32,5 +32,5 @@
include
(
'../inc/includes.php'
);
$dropdown
=
new
Ticket
Template
();
$dropdown
=
new
ITIL
Template
();
include
(
GLPI_ROOT
.
"/front/dropdown.common.php"
);
front/
ticket
templatehiddenfield.form.php
→
front/
itil
templatehiddenfield.form.php
View file @
f44f64c0
...
...
@@ -34,15 +34,15 @@ use Glpi\Event;
include
(
'../inc/includes.php'
);
Session
::
checkRight
(
'
ticket
template'
,
UPDATE
);
Session
::
checkRight
(
'
itil
template'
,
UPDATE
);
$item
=
new
Ticket
TemplateHiddenField
();
$item
=
new
ITIL
TemplateHiddenField
();
if
(
isset
(
$_POST
[
"add"
]))
{
$item
->
check
(
-
1
,
UPDATE
,
$_POST
);
if
(
$item
->
add
(
$_POST
))
{
Event
::
log
(
$_POST
[
"
ticket
templates_id"
],
"
ticket
template"
,
4
,
"maintain"
,
Event
::
log
(
$_POST
[
"
itil
templates_id"
],
"
itil
template"
,
4
,
"maintain"
,
//TRANS: %s is the user login
sprintf
(
__
(
'%s adds hidden field'
),
$_SESSION
[
"glpiname"
]));
}
...
...
front/
ticket
templatemandatoryfield.form.php
→
front/
itil
templatemandatoryfield.form.php
View file @
f44f64c0
...
...
@@ -34,15 +34,15 @@ use Glpi\Event;
include
(
'../inc/includes.php'
);
Session
::
checkRight
(
'
ticket
template'
,
UPDATE
);
Session
::
checkRight
(
'
itil
template'
,
UPDATE
);
$item
=
new
Ticket
TemplateMandatoryField
();
$item
=
new
ITIL
TemplateMandatoryField
();
if
(
isset
(
$_POST
[
"add"
]))
{
$item
->
check
(
-
1
,
UPDATE
,
$_POST
);
if
(
$item
->
add
(
$_POST
))
{
Event
::
log
(
$_POST
[
"
ticket
templates_id"
],
"
ticket
template"
,
4
,
"maintain"
,
Event
::
log
(
$_POST
[
"
itil
templates_id"
],
"
itil
template"
,
4
,
"maintain"
,
//TRANS: %s is the user login
sprintf
(
__
(
'%s adds mandatory field'
),
$_SESSION
[
"glpiname"
]));
}
...
...
front/
ticket
templatepredefinedfield.form.php
→
front/
itil
templatepredefinedfield.form.php
View file @
f44f64c0
...
...
@@ -34,9 +34,9 @@ use Glpi\Event;
include
(
'../inc/includes.php'
);
Session
::
checkRight
(
'
ticket
template'
,
UPDATE
);
Session
::
checkRight
(
'
itil
template'
,
UPDATE
);
$item
=
new
Ticket
TemplatePredefinedField
();
$item
=
new
ITIL
TemplatePredefinedField
();
// Use masiveaction system to manage add value
if
(
isset
(
$_POST
[
"massiveaction"
]))
{
...
...
@@ -45,7 +45,7 @@ if (isset($_POST["massiveaction"])) {
$_POST
[
'items_tickets_id'
]
=
$_POST
[
'items_tickets_id'
]
.
"_"
.
$_POST
[
'add_items_id'
];
}
if
(
$item
->
add
(
$_POST
))
{
Event
::
log
(
$_POST
[
"
ticket
templates_id"
],
"
ticket
template"
,
4
,
"maintain"
,
Event
::
log
(
$_POST
[
"
itil
templates_id"
],
"
itil
template"
,
4
,
"maintain"
,
//TRANS: %s is the user login
sprintf
(
__
(
'%s adds predefined field'
),
$_SESSION
[
"glpiname"
]));
}
...
...
inc/api.class.php
View file @
f44f64c0
...
...
@@ -1241,7 +1241,7 @@ abstract class API extends CommonGLPI {
// filter with entity
if
(
$item
->
isEntityAssign
()
// some CommonDBChild classes may not have entities_id fields and isEntityAssign still return true (like
Ticket
TemplateMandatoryField)
// some CommonDBChild classes may not have entities_id fields and isEntityAssign still return true (like
ITIL
TemplateMandatoryField)
&&
array_key_exists
(
'entities_id'
,
$item
->
fields
))
{
$where
.
=
" AND ("
.
getEntitiesRestrictRequest
(
""
,
$itemtype
::
getTable
(),
...
...
inc/autoload.function.php
View file @
f44f64c0
...
...
@@ -268,6 +268,17 @@ function glpi_autoload($classname) {
return
false
;
}
//@since 9.5.0 -- WILL BE REMOVED IN FUTURE RELEASE
$deprecateds
=
[
'TicketTempate'
,
'TicketTemplateHiddenField'
,
'TicketTemplateMandatoryField'
,
'TicketTemplatePredefinedField'
];
if
(
in_array
(
$classname
,
$deprecateds
))
{
Toolbox
::
deprecated
(
"
$classname
has been dropped from GLPI."
);
}
if
(
$classname
===
'phpCAS'
&&
file_exists
(
stream_resolve_include_path
(
"CAS.php"
)))
{
include_once
(
'CAS.php'
);
...
...
inc/commonitilobject.class.php
View file @
f44f64c0
...
...
@@ -2530,9 +2530,9 @@ abstract class CommonITILObject extends CommonDBTM {
$mandatory
=
''
;
// For ticket templates : mandatories
if
((
$itemtype
==
'Ticket'
)
&&
isset
(
$options
[
'_
ticket
template'
]))
{
$mandatory
=
$options
[
'_
ticket
template'
]
->
getMandatoryMark
(
"_groups_id_"
.
$typename
);
if
(
$options
[
'_
ticket
template'
]
->
isMandatoryField
(
"_groups_id_"
.
$typename
)
&&
isset
(
$options
[
'_
itil
template'
]))
{
$mandatory
=
$options
[
'_
itil
template'
]
->
getMandatoryMark
(
"_groups_id_"
.
$typename
);
if
(
$options
[
'_
itil
template'
]
->
isMandatoryField
(
"_groups_id_"
.
$typename
)
&&
isset
(
$this
->
groups
[
$type
])
&&
(
count
(
$this
->
groups
[
$type
])
==
1
))
{
$candelete
=
false
;
}
...
...
@@ -2587,9 +2587,9 @@ abstract class CommonITILObject extends CommonDBTM {
$mandatory
=
''
;
// For ticket templates : mandatories
if
((
$itemtype
==
'Ticket'
)
&&
isset
(
$options
[
'_
ticket
template'
]))
{
$mandatory
=
$options
[
'_
ticket
template'
]
->
getMandatoryMark
(
"_suppliers_id_"
.
$typename
);
if
(
$options
[
'_
ticket
template'
]
->
isMandatoryField
(
"_suppliers_id_"
.
$typename
)
&&
isset
(
$options
[
'_
itil
template'
]))
{
$mandatory
=
$options
[
'_
itil
template'
]
->
getMandatoryMark
(
"_suppliers_id_"
.
$typename
);
if
(
$options
[
'_
itil
template'
]
->
isMandatoryField
(
"_suppliers_id_"
.
$typename
)
&&
isset
(
$this
->
suppliers
[
$type
])
&&
(
count
(
$this
->
suppliers
[
$type
])
==
1
))
{
$candelete
=
false
;
}
...
...
@@ -3642,9 +3642,9 @@ abstract class CommonITILObject extends CommonDBTM {
$mandatory
=
''
;
// For ticket templates : mandatories
if
((
$itemtype
==
'Ticket'
)
&&
isset
(
$options
[
'_
ticket
template'
]))
{
$mandatory
=
$options
[
'_
ticket
template'
]
->
getMandatoryMark
(
"_users_id_"
.
$typename
);
if
(
$options
[
'_
ticket
template'
]
->
isMandatoryField
(
"_users_id_"
.
$typename
)
&&
isset
(
$options
[
'_
itil
template'
]))
{
$mandatory
=
$options
[
'_
itil
template'
]
->
getMandatoryMark
(
"_users_id_"
.
$typename
);
if
(
$options
[
'_
itil
template'
]
->
isMandatoryField
(
"_users_id_"
.
$typename
)
&&
isset
(
$this
->
users
[
$type
])
&&
(
count
(
$this
->
users
[
$type
])
==
1
))
{
$candelete
=
false
;
}
...
...
@@ -3816,8 +3816,8 @@ abstract class CommonITILObject extends CommonDBTM {
echo
self
::
getActorIcon
(
'user'
,
$type
);
// For ticket templates : mandatories
if
((
$itemtype
==
'Ticket'
)
&&
isset
(
$options
[
'_
ticket
template'
]))
{
echo
$options
[
'_
ticket
template'
]
->
getMandatoryMark
(
"_users_id_"
.
$typename
);
&&
isset
(
$options
[
'_
itil
template'
]))
{
echo
$options
[
'_
itil
template'
]
->
getMandatoryMark
(
"_users_id_"
.
$typename
);
}
echo
" "
;
...
...
@@ -3980,8 +3980,8 @@ abstract class CommonITILObject extends CommonDBTM {
echo
self
::
getActorIcon
(
'supplier'
,
'assign'
);
// For ticket templates : mandatories
if
((
$itemtype
==
'Ticket'
)
&&
isset
(
$options
[
'_
ticket
template'
]))
{
echo
$options
[
'_
ticket
template'
]
->
getMandatoryMark
(
"_suppliers_id_assign"
);
&&
isset
(
$options
[
'_
itil
template'
]))
{
echo
$options
[
'_
itil
template'
]
->
getMandatoryMark
(
"_suppliers_id_assign"
);
}
echo
" "
;
...
...
@@ -4077,8 +4077,8 @@ abstract class CommonITILObject extends CommonDBTM {
'_users_id_assign'
,
'_groups_id_assign'
,
'_suppliers_id_assign'
]
as
$f
)
{
$is_hidden
[
$f
]
=
false
;
if
(
isset
(
$options
[
'_
ticket
template'
])
&&
$options
[
'_
ticket
template'
]
->
isHiddenField
(
$f
))
{
if
(
isset
(
$options
[
'_
itil
template'
])
&&
$options
[
'_
itil
template'
]
->
isHiddenField
(
$f
))
{
$is_hidden
[
$f
]
=
true
;
}
}
...
...
@@ -4184,8 +4184,8 @@ abstract class CommonITILObject extends CommonDBTM {
&&
!
$is_hidden
[
'_groups_id_requester'
])
{
echo
self
::
getActorIcon
(
'group'
,
CommonITILActor
::
REQUESTER
);
/// For ticket templates : mandatories
if
(
isset
(
$options
[
'_
ticket
template'
]))
{
echo
$options
[
'_
ticket
template'
]
->
getMandatoryMark
(
'_groups_id_requester'
);
if
(
isset
(
$options
[
'_
itil
template'
]))
{
echo
$options
[
'_
itil
template'
]
->
getMandatoryMark
(
'_groups_id_requester'
);
}
echo
" "
;
...
...
@@ -4278,8 +4278,8 @@ abstract class CommonITILObject extends CommonDBTM {
&&
!
$is_hidden
[
'_groups_id_observer'
])
{
echo
self
::
getActorIcon
(
'group'
,
CommonITILActor
::
OBSERVER
);
/// For ticket templates : mandatories
if
(
isset
(
$options
[
'_
ticket
template'
]))
{
echo
$options
[
'_
ticket
template'
]
->
getMandatoryMark
(
'_groups_id_observer'
);
if
(
isset
(
$options
[
'_
itil
template'
]))
{
echo
$options
[
'_
itil
template'
]
->
getMandatoryMark
(
'_groups_id_observer'
);
}
echo
" "
;
...
...
@@ -4390,8 +4390,8 @@ abstract class CommonITILObject extends CommonDBTM {
&&
$this
->
isAllowedStatus
(
CommonITILObject
::
INCOMING
,
CommonITILObject
::
ASSIGNED
))
{
echo
self
::
getActorIcon
(
'group'
,
CommonITILActor
::
ASSIGN
);
/// For ticket templates : mandatories
if
(
isset
(
$options
[
'_
ticket
template'
]))
{
echo
$options
[
'_
ticket
template'
]
->
getMandatoryMark
(
'_groups_id_assign'
);
if
(
isset
(
$options
[
'_
itil
template'
]))
{
echo
$options
[
'_
itil
template'
]
->
getMandatoryMark
(
'_groups_id_assign'
);
}
echo
" "
;
$rand
=
mt_rand
();
...
...
inc/document_item.class.php
View file @
f44f64c0
...
...
@@ -153,7 +153,7 @@ class Document_Item extends CommonDBRelation{
$ticket
=
new
Ticket
();
$ticket
->
getFromDB
(
$this
->
fields
[
'items_id'
]);
$tt
=
$ticket
->
get
Ticket
TemplateToUse
(
0
,
$ticket
->
fields
[
'type'
],
$tt
=
$ticket
->
get
ITIL
TemplateToUse
(
0
,
$ticket
->
fields
[
'type'
],
$ticket
->
fields
[
'itilcategories_id'
],
$ticket
->
fields
[
'entities_id'
]);
...
...
inc/entity.class.php
View file @
f44f64c0
...
...
@@ -103,7 +103,7 @@ class Entity extends CommonTreeDropdown {
'autoclose_delay'
,
'inquest_config'
,
'inquest_rate'
,
'inquest_delay'
,
'inquest_duration'
,
'inquest_URL'
,
'max_closedate'
,
'
ticket
templates_id'
,
'max_closedate'
,
'
itil
templates_id'
,
'suppliers_as_private'
],
// Configuration
'config'
...
...
@@ -903,7 +903,7 @@ class Entity extends CommonTreeDropdown {
$tab
[]
=
[
'id'
=>
'47'
,
'table'
=>
$this
->
getTable
(),
'field'
=>
'
ticket
templates_id'
,
// not a dropdown because of special value
'field'
=>
'
itil
templates_id'
,
// not a dropdown because of special value
'name'
=>
_n
(
'Ticket template'
,
'Ticket templates'
,
1
),
'massiveaction'
=>
false
,
'nosearch'
=>
true
,
...
...
@@ -2262,18 +2262,18 @@ class Entity extends CommonTreeDropdown {
$toadd
=
[
self
::
CONFIG_PARENT
=>
__
(
'Inheritance of the parent entity'
)];
}
$options
=
[
'value'
=>
$entity
->
fields
[
"
ticket
templates_id"
],
$options
=
[
'value'
=>
$entity
->
fields
[
"
itil
templates_id"
],
'entity'
=>
$ID
,
'toadd'
=>
$toadd
];
Ticket
Template
::
dropdown
(
$options
);
ITIL
Template
::
dropdown
(
$options
);
if
((
$entity
->
fields
[
"
ticket
templates_id"
]
==
self
::
CONFIG_PARENT
)
if
((
$entity
->
fields
[
"
itil
templates_id"
]
==
self
::
CONFIG_PARENT
)
&&
(
$ID
!=
0
))
{
echo
"<font class='green'> "
;
$tt
=
new
Ticket
Template
();
$tid
=
self
::
getUsedConfig
(
'
ticket
templates_id'
,
$ID
,
''
,
0
);
$tt
=
new
ITIL
Template
();
$tid
=
self
::
getUsedConfig
(
'
itil
templates_id'
,
$ID
,
''
,
0
);
if
(
!
$tid
)
{
echo
Dropdown
::
EMPTY_VALUE
;
}
else
if
(
$tt
->
getFromDB
(
$tid
))
{
...
...
@@ -2879,11 +2879,11 @@ class Entity extends CommonTreeDropdown {
}
return
Dropdown
::
getDropdownName
(
'glpi_entities'
,
$values
[
$field
]);
case
'
ticket
templates_id'
:
case
'
itil
templates_id'
:
if
(
$values
[
$field
]
==
self
::
CONFIG_PARENT
)
{
return
__
(
'Inheritance of the parent entity'
);
}
return
Dropdown
::
getDropdownName
(
'glpi_
ticket
templates'
,
$values
[
$field
]);
return
Dropdown
::
getDropdownName
(
'glpi_
itil
templates'
,
$values
[
$field
]);
case
'calendars_id'
:
switch
(
$values
[
$field
])
{
...
...
inc/item_ticket.class.php
View file @
f44f64c0
...
...
@@ -226,9 +226,9 @@ class Item_Ticket extends CommonDBRelation{
}
// Get ticket template
$tt
=
new
Ticket
Template
();
if
(
isset
(
$options
[
'_
ticket
template'
]))
{
$tt
=
$options
[
'_
ticket
template'
];
$tt
=
new
ITIL
Template
();
if
(
isset
(
$options
[
'_
itil
template'
]))
{
$tt
=
$options
[
'_
itil
template'
];
if
(
isset
(
$tt
->
fields
[
'id'
]))
{
$opt
[
'templates_id'
]
=
$tt
->
fields
[
'id'
];
}
...
...
inc/itilcategory.class.php
View file @
f44f64c0
...
...
@@ -87,11 +87,11 @@ class ITILCategory extends CommonTreeDropdown {
'label'
=>
__
(
'Visible for a change'
),
'type'
=>
'bool'
,
'list'
=>
true
],
[
'name'
=>
'
ticket
templates_id_demand'
,
[
'name'
=>
'
itil
templates_id_demand'
,
'label'
=>
__
(
'Template for a request'
),
'type'
=>
'dropdownValue'
,
'list'
=>
true
],
[
'name'
=>
'
ticket
templates_id_incident'
,
[
'name'
=>
'
itil
templates_id_incident'
,
'label'
=>
__
(
'Template for an incident'
),
'type'
=>
'dropdownValue'
,
'list'
=>
true
],
...
...
@@ -129,18 +129,18 @@ class ITILCategory extends CommonTreeDropdown {
$tab
[]
=
[
'id'
=>
'72'
,
'table'
=>
'glpi_
ticket
templates'
,
'table'
=>
'glpi_
itil
templates'
,
'field'
=>
'name'
,
'linkfield'
=>
'
ticket
templates_id_demand'
,
'linkfield'
=>
'
itil
templates_id_demand'
,
'name'
=>
__
(
'Template for a request'
),
'datatype'
=>
'dropdown'
];
$tab
[]
=
[
'id'
=>
'73'
,
'table'
=>
'glpi_
ticket
templates'
,
'table'
=>
'glpi_
itil
templates'
,
'field'
=>
'name'
,
'linkfield'
=>
'
ticket
templates_id_incident'
,
'linkfield'
=>
'
itil
templates_id_incident'
,
'name'
=>
__
(
'Template for an incident'
),
'datatype'
=>
'dropdown'
];
...
...
@@ -266,7 +266,7 @@ class ITILCategory extends CommonTreeDropdown {
if
(
Session
::
haveRight
(
self
::
$rightname
,
READ
))
{
switch
(
$item
->
getType
())
{
case
'
Ticket
Template'
:
case
'
ITIL
Template'
:
$ong
[
1
]
=
$this
->
getTypeName
(
Session
::
getPluralNumber
());
return
$ong
;
}
...
...
@@ -277,18 +277,18 @@ class ITILCategory extends CommonTreeDropdown {
static
function
displayTabContentForItem
(
CommonGLPI
$item
,
$tabnum
=
1
,
$withtemplate
=
0
)
{
if
(
$item
->
getType
()
==
'
Ticket
Template'
)
{
self
::
showFor
Ticket
Template
(
$item
,
$withtemplate
);
if
(
$item
->
getType
()
==
'
ITIL
Template'
)
{
self
::
showFor
ITIL
Template
(
$item
,
$withtemplate
);
}
return
parent
::
displayTabContentForItem
(
$item
,
$tabnum
,
$withtemplate
);
}
/**
* @param $tt
Ticket
Template object
* @param $tt
ITIL
Template object
* @param $withtemplate (default 0)
**/
static
function
showFor
Ticket
Template
(
Ticket
Template
$tt
,
$withtemplate
=
0
)
{
static
function
showFor
ITIL
Template
(
ITIL
Template
$tt
,
$withtemplate
=
0
)
{
global
$DB
,
$CFG_GLPI
;
$itilcategory
=
new
self
();
...
...
@@ -307,8 +307,8 @@ class ITILCategory extends CommonTreeDropdown {
'FROM'
=>
'glpi_itilcategories'
,
'WHERE'
=>
[
'OR'
=>
[
'
ticket
templates_id_incident'
=>
$ID
,
'
ticket
templates_id_demand'
=>
$ID
'
itil
templates_id_incident'
=>
$ID
,
'
itil
templates_id_demand'
=>
$ID
]
],
'ORDER'
=>
'name'
...
...
@@ -333,7 +333,7 @@ class ITILCategory extends CommonTreeDropdown {
echo
"<tr class='tab_bg_2'>"
;
$itilcategory
->
getFromDB
(
$data
[
'id'
]);
echo
"<td>"
.
$itilcategory
->
getLink
([
'comments'
=>
true
])
.
"</td>"
;
if
(
$data
[
'
ticket
templates_id_incident'
]
==
$ID
)
{
if
(
$data
[
'
itil
templates_id_incident'
]
==
$ID
)
{
echo
"<td class='center'>
<img src='"
.
$CFG_GLPI
[
"root_doc"
]
.
"/pics/ok.png' alt=
\"
"
.
__
(
'OK'
)
.
"
\"
width='14' height='14'>
...
...
@@ -342,7 +342,7 @@ class ITILCategory extends CommonTreeDropdown {
}
else
{
echo
"<td> </td>"
;
}
if
(
$data
[
'
ticket
templates_id_demand'
]
==
$ID
)
{
if
(
$data
[
'
itil
templates_id_demand'
]
==
$ID
)
{
echo
"<td class='center'>
<img src='"
.
$CFG_GLPI
[
"root_doc"
]
.
"/pics/ok.png' alt=
\"
"
.
__
(
'OK'
)
.
"
\"
width='14' height='14'>
...
...
inc/itiltemplate.class.php
0 → 100644
View file @
f44f64c0
This diff is collapsed.
Click to expand it.
inc/itiltemplatehiddenfield.class.php
0 → 100644
View file @
f44f64c0
<?php
/**
* ---------------------------------------------------------------------
* GLPI - Gestionnaire Libre de Parc Informatique
* Copyright (C) 2015-2018 Teclib' and contributors.
*
* http://glpi-project.org
*
* based on GLPI - Gestionnaire Libre de Parc Informatique
* Copyright (C) 2003-2014 by the INDEPNET Development Team.
*
* ---------------------------------------------------------------------
*
* LICENSE
*
* This file is part of GLPI.
*
* GLPI 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 2 of the License, or
* (at your option) any later version.
*
* GLPI 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
* along with GLPI. If not, see <http://www.gnu.org/licenses/>.
* ---------------------------------------------------------------------
*/
if
(
!
defined
(
'GLPI_ROOT'
))
{
die
(
"Sorry. You can't access this file directly"
);
}
/// Hidden fields for ticket template class
/// since version 0.83
class
ITILTemplateHiddenField
extends
CommonDBChild
{
// From CommonDBChild
static
public
$itemtype
=
'ITILTemplate'
;
static
public
$items_id
=
'itiltemplates_id'
;
public
$dohistory
=
true
;
/**
* @since 0.84
**/
function
getForbiddenStandardMassiveAction
()
{
$forbidden
=
parent
::
getForbiddenStandardMassiveAction
();
$forbidden
[]
=
'update'
;
return
$forbidden
;
}
static
function
getTypeName
(
$nb
=
0
)
{
return
_n
(
'Hidden field'
,
'Hidden fields'
,
$nb
);
}
/**
* @see CommonDBTM::getRawName()
*
* @since 0.85
**/
function
getRawName
()
{
$tt
=
new
ITILTemplate
();
$fields
=
$tt
->
getAllowedFieldsNames
(
true
);
if
(
isset
(
$fields
[
$this
->
fields
[
"num"
]]))
{
return
$fields
[
$this
->
fields
[
"num"
]];
}
return
''
;
}
function
getTabNameForItem
(
CommonGLPI
$item
,
$withtemplate
=
0
)
{
// can exists for template
if
((
$item
->
getType
()
==
'ITILTemplate'
)
&&
Session
::
haveRight
(
"itiltemplate"
,
READ
))
{
$nb
=
0
;
if
(
$_SESSION
[
'glpishow_count_on_tabs'
])
{
$nb
=
countElementsInTable
(
$this
->
getTable
(),
[
'itiltemplates_id'
=>
$item
->
getID
()]);
}
return
self
::
createTabEntry
(
self
::
getTypeName
(
Session
::
getPluralNumber
()),
$nb
);
}
return
''
;
}
static
function
displayTabContentForItem
(
CommonGLPI
$item
,
$tabnum
=
1
,
$withtemplate
=
0
)
{
self
::
showForITILTemplate
(
$item
,
$withtemplate
);
return
true
;
}
function
post_purgeItem
()
{
global
$DB
;
parent
::
post_purgeItem
();
$ticket
=
new
Ticket
();
$itemtype_id
=
$ticket
->
getSearchOptionIDByField
(
'field'
,
'itemtype'
,
'glpi_tickets'
);
$items_id_id
=
$ticket
->
getSearchOptionIDByField
(
'field'
,
'items_id'
,
'glpi_tickets'
);
// Try to delete itemtype -> delete items_id
if
(
$this
->
fields
[
'num'
]
==
$itemtype_id
)
{
$query
=
"SELECT `id`
FROM `"
.
$this
->
getTable
()
.
"`
WHERE `"
.
static
::
$items_id
.
"` = '"
.
$this
->
fields
[
'itiltemplates_id'
]
.
"'
AND `num` = '
$items_id_id
'"
;
if
(
$result
=
$DB
->
query
(
$query
))
{
if
(
$DB
->
numrows
(
$result
))
{
$a
=
new
self
();
$a
->
delete
([
'id'
=>
$DB
->
result
(
$result
,
0
,
0
)]);
}
}
}
}
/**
* Get hidden fields for a template
*
* @since 0.83
*
* @param $ID integer the template ID
* @param $withtypeandcategory boolean with type and category (false by default)
*
* @return an array of hidden fields
**/
function
getHiddenFields
(
$ID
,
$withtypeandcategory
=
false
)
{
global
$DB
;
$sql
=
"SELECT *
FROM `"
.
$this
->
getTable
()
.
"`
WHERE `"
.
static
::
$items_id
.
"` = '
$ID
'
ORDER BY `id`"
;
$result
=
$DB
->
query
(
$sql
);
$tt
=
new
ITILTemplate
();
$allowed_fields
=
$tt
->
getAllowedFields
(
$withtypeandcategory
);
$fields
=
[];
while
(
$rule
=
$DB
->
fetchAssoc
(
$result
))
{
if
(
isset
(
$allowed_fields
[
$rule
[
'num'
]]))
{
$fields
[
$allowed_fields
[
$rule
[
'num'
]]]
=
$rule
[
'num'
];
}
}
return
$fields
;
}
/**
* Return fields who doesn't need to be used for this part of template
*
* @since 9.2
*
* @return array the excluded fields (keys and values are equals)
*/
static
function
getExcludedFields
()
{
return
[
175
=>
175
,
// ticket's tasks (template)
];
}
/**
* Print the hidden fields
*
* @since 0.83
*
* @param $tt Ticket Template
* @param $withtemplate boolean Template or basic item (default 0)
*
* @return Nothing (call to classes members)
**/
static
function
showForITILTemplate
(
ITILTemplate
$tt
,
$withtemplate
=
0
)
{
global
$DB
;
$ID
=
$tt
->
fields
[
'id'
];
if
(
!
$tt
->
getFromDB
(
$ID
)
||
!
$tt
->
can
(
$ID
,
READ
))
{
return
false
;
}
$ttm
=
new
self
();
$used
=
$ttm
->
getHiddenFields
(
$ID
);
$canedit
=
$tt
->
canEdit
(
$ID
);
$fields
=
$tt
->
getAllowedFieldsNames
(
false
);
$fields
=
array_diff_key
(
$fields
,
self
::
getExcludedFields
());
$rand
=
mt_rand
();
$query
=
"SELECT `glpi_itiltemplatehiddenfields`.*
FROM `glpi_itiltemplatehiddenfields`
WHERE (`itiltemplates_id` = '
$ID
')"
;
if
(
$result
=
$DB
->
query
(
$query
))
{
$hiddenfields
=
[];
$used
=
[];
if
(
$numrows
=
$DB
->
numrows
(
$result
))
{
while
(
$data
=
$DB
->
fetchAssoc
(