Skip to content
GitLab
Menu
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
87f1cae8
Commit
87f1cae8
authored
Oct 30, 2017
by
Johan Cwiklinski
Browse files
Add specific massive action for OS related update; fixes #3049
parent
a2ae7483
Changes
3
Hide whitespace changes
Inline
Side-by-side
ajax/dropdownMassiveActionOs.php
0 → 100644
View file @
87f1cae8
<?php
/**
* ---------------------------------------------------------------------
* GLPI - Gestionnaire Libre de Parc Informatique
* Copyright (C) 2015-2017 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/>.
* ---------------------------------------------------------------------
*/
include
(
'../inc/includes.php'
);
header
(
"Content-Type: text/html; charset=UTF-8"
);
Html
::
header_nocache
();
Session
::
checkCentralAccess
();
if
(
!
isset
(
$_POST
[
"itemtype"
])
||
!
(
$item
=
getItemForItemtype
(
$_POST
[
'itemtype'
])))
{
exit
();
}
$item
::
dropdown
();
echo
"<br/><input type='submit' name='update' value=
\"
"
.
_sx
(
'button'
,
'Update'
)
.
"
\"
class='submit'>"
;
inc/computer.class.php
View file @
87f1cae8
...
...
@@ -571,6 +571,7 @@ class Computer extends CommonDBTM {
$actions
=
parent
::
getSpecificMassiveActions
(
$checkitem
);
if
(
$isadmin
)
{
$actions
[
'Item_OperatingSystem'
.
MassiveAction
::
CLASS_ACTION_SEPARATOR
.
'update'
]
=
OperatingSystem
::
getTypeName
();
$actions
[
'Computer_Item'
.
MassiveAction
::
CLASS_ACTION_SEPARATOR
.
'add'
]
=
_x
(
'button'
,
'Connect'
);
$actions
[
'Computer_SoftwareVersion'
.
MassiveAction
::
CLASS_ACTION_SEPARATOR
.
'add'
]
=
_x
(
'button'
,
'Install'
);
MassiveAction
::
getAddTransferList
(
$actions
);
...
...
inc/item_operatingsystem.class.php
View file @
87f1cae8
...
...
@@ -420,6 +420,7 @@ class Item_OperatingSystem extends CommonDBRelation {
'field'
=>
'name'
,
'name'
=>
__
(
'Name'
),
'datatype'
=>
'dropdown'
,
'massiveaction'
=>
false
,
'joinparams'
=>
[
'beforejoin'
=>
[
'table'
=>
'glpi_items_operatingsystems'
,
...
...
@@ -437,6 +438,7 @@ class Item_OperatingSystem extends CommonDBRelation {
'field'
=>
'name'
,
'name'
=>
__
(
'Version'
),
'datatype'
=>
'dropdown'
,
'massiveaction'
=>
false
,
'joinparams'
=>
[
'beforejoin'
=>
[
'table'
=>
'glpi_items_operatingsystems'
,
...
...
@@ -454,6 +456,7 @@ class Item_OperatingSystem extends CommonDBRelation {
'field'
=>
'name'
,
'name'
=>
__
(
'Service pack'
),
'datatype'
=>
'dropdown'
,
'massiveaction'
=>
false
,
'joinparams'
=>
[
'beforejoin'
=>
[
'table'
=>
'glpi_items_operatingsystems'
,
...
...
@@ -471,6 +474,7 @@ class Item_OperatingSystem extends CommonDBRelation {
'field'
=>
'license_number'
,
'name'
=>
__
(
'Serial number'
),
'datatype'
=>
'string'
,
'massiveaction'
=>
false
,
'joinparams'
=>
[
'jointype'
=>
'itemtype_item'
,
'specific_itemtype'
=>
$itemtype
...
...
@@ -483,6 +487,7 @@ class Item_OperatingSystem extends CommonDBRelation {
'field'
=>
'license_id'
,
'name'
=>
__
(
'Product ID'
),
'datatype'
=>
'string'
,
'massiveaction'
=>
false
,
'joinparams'
=>
[
'jointype'
=>
'itemtype_item'
,
'specific_itemtype'
=>
$itemtype
...
...
@@ -495,6 +500,7 @@ class Item_OperatingSystem extends CommonDBRelation {
'field'
=>
'name'
,
'name'
=>
__
(
'Architecture'
),
'datatype'
=>
'dropdown'
,
'massiveaction'
=>
false
,
'joinparams'
=>
[
'beforejoin'
=>
[
'table'
=>
'glpi_items_operatingsystems'
,
...
...
@@ -512,6 +518,7 @@ class Item_OperatingSystem extends CommonDBRelation {
'field'
=>
'name'
,
'name'
=>
_n
(
'Kernel'
,
'Kernels'
,
1
),
'datatype'
=>
'dropdown'
,
'massiveaction'
=>
false
,
'joinparams'
=>
[
'beforejoin'
=>
[
'table'
=>
'glpi_operatingsystemkernelversions'
,
...
...
@@ -534,6 +541,7 @@ class Item_OperatingSystem extends CommonDBRelation {
'field'
=>
'name'
,
'name'
=>
_n
(
'Kernel version'
,
'Kernel versions'
,
1
),
'datatype'
=>
'dropdown'
,
'massiveaction'
=>
false
,
'joinparams'
=>
[
'beforejoin'
=>
[
'table'
=>
'glpi_items_operatingsystems'
,
...
...
@@ -551,6 +559,7 @@ class Item_OperatingSystem extends CommonDBRelation {
'field'
=>
'name'
,
'name'
=>
__
(
'Edition'
),
'datatype'
=>
'dropdown'
,
'massiveaction'
=>
false
,
'joinparams'
=>
[
'beforejoin'
=>
[
'table'
=>
'glpi_items_operatingsystems'
,
...
...
@@ -564,4 +573,106 @@ class Item_OperatingSystem extends CommonDBRelation {
return
$tab
;
}
static
function
getRelationMassiveActionsSpecificities
()
{
global
$CFG_GLPI
;
$specificities
=
parent
::
getRelationMassiveActionsSpecificities
();
$specificities
[
'itemtypes'
]
=
[
'Computer'
,
'Monitor'
,
'NetworkEquipment'
,
'Peripheral'
,
'Phone'
,
'Printer'
];
return
$specificities
;
}
static
function
showMassiveActionsSubForm
(
MassiveAction
$ma
)
{
switch
(
$ma
->
getAction
())
{
case
'update'
:
static
::
showFormMassiveUpdate
(
$ma
);
return
true
;
}
return
parent
::
showMassiveActionsSubForm
(
$ma
);
}
static
function
showFormMassiveUpdate
(
$ma
)
{
global
$CFG_GLPI
;
$rand
=
mt_rand
();
Dropdown
::
showFromArray
(
'os_field'
,
[
'OperatingSystem'
=>
__
(
'Name'
),
'OperatingSystemVersion'
=>
__
(
'Version'
),
'OperatingSystemArchitecture'
=>
__
(
'Architecture'
),
'OperatingSystemKernel'
=>
__
(
'Kernel'
),
'OperatingSystemKernelVersion'
=>
__
(
'Kernel version'
),
'OperatingSystemEdition'
=>
__
(
'Edition'
)
],
[
'display_emptychoice'
=>
true
,
'rand'
=>
$rand
]
);
Ajax
::
updateItemOnSelectEvent
(
"dropdown_os_field
$rand
"
,
"results_os_field
$rand
"
,
$CFG_GLPI
[
"root_doc"
]
.
"/ajax/dropdownMassiveActionOs.php"
,
[
'itemtype'
=>
'__VALUE__'
,
'rand'
=>
$rand
]
);
echo
"<span id='results_os_field
$rand
'></span>
\n
"
;
}
static
function
processMassiveActionsForOneItemtype
(
MassiveAction
$ma
,
CommonDBTM
$item
,
array
$ids
)
{
switch
(
$ma
->
getAction
())
{
case
'update'
:
$input
=
$ma
->
getInput
();
unset
(
$input
[
'update'
]);
unset
(
$input
[
'os_field'
]);
$ios
=
new
Item_OperatingSystem
();
foreach
(
$ids
as
$id
)
{
if
(
$item
->
getFromDB
(
$id
))
{
if
(
$item
->
can
(
$id
,
UPDATE
,
$input
))
{
$exists
=
$ios
->
getFromDBByCrit
([
'itemtype'
=>
$item
->
getType
(),
'items_id'
=>
$item
->
getID
()
]);
$ok
=
false
;
if
(
$exists
)
{
$ok
=
$ios
->
update
([
'id'
=>
$ios
->
getID
()]
+
$input
);
}
else
{
$ok
=
$ios
->
add
([
'itemtype'
=>
$item
->
getType
(),
'items_id'
=>
$item
->
getID
()]
+
$input
);
}
if
(
$ok
!=
false
)
{
$ma
->
itemDone
(
$item
->
getType
(),
$id
,
MassiveAction
::
ACTION_OK
);
}
else
{
$ma
->
itemDone
(
$item
->
getType
(),
$id
,
MassiveAction
::
ACTION_KO
);
$ma
->
addMessage
(
$item
->
getErrorMessage
(
ERROR_ON_ACTION
));
}
}
else
{
$ma
->
itemDone
(
$item
->
getType
(),
$id
,
MassiveAction
::
ACTION_KO
);
$ma
->
addMessage
(
$item
->
getErrorMessage
(
ERROR_NOT_FOUND
));
}
}
else
{
$ma
->
itemDone
(
$item
->
getType
(),
$id
,
MassiveAction
::
ACTION_KO
);
$ma
->
addMessage
(
$item
->
getErrorMessage
(
ERROR_NOT_FOUND
));
}
}
break
;
}
parent
::
processMassiveActionsForOneItemtype
(
$ma
,
$item
,
$ids
);
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment