.
@package archires
@author Nelly Mahu-Lasson, Xavier Caillaud
@copyright Copyright (c) 2016-2018 Archires plugin team
@license AGPL License 3.0 or (at your option) any later version
http://www.gnu.org/licenses/agpl-3.0-standalone.html
@link https://forge.glpi-project.org/projects/archires
@since version 2.2
--------------------------------------------------------------------------
*/
if (!defined('GLPI_ROOT')) {
die("Sorry. You can't access directly to this file");
}
class PluginArchiresStateColor extends CommonDBTM {
static $rightname = "plugin_archires";
function getFromDBbyState($state) {
global $DB;
$query = ['FROM' => $this->getTable(),
'WHERE' => ['states_id' => $state]];
if ($result = $DB->request($query)) {
if (count($result) != 1) {
return false;
}
$this->fields = $result->next();
if (is_array($this->fields) && count($this->fields)) {
return true;
}
}
return false;
}
function addStateColor($state,$color) {
global $DB;
if ($state != '-1') {
if ($this->getfromDBbyState($state)) {
$this->update(['id' => $this->fields['id'],
'color' => $color]);
} else {
$this->add(['states_id' => $state,
'color' => $color]);
}
} else {
$query = ['FROM' => 'glpi_states'];
$result = $DB->request($query);
$i = 0;
while ($i < count($result)) {
$row = $result->next();
$state_table = $row['id'];
if ($this->getfromDBbyState($state_table)) {
$this->update(['id' => $this->fields['id'],
'color' => $color]);
} else {
$this->add(['states_id' => $state_table,
'color' => $color]);
}
$i++;
}
}
}
function showConfigForm($canupdate=false) {
global $DB;
if ($canupdate) {
echo "
";
Html::closeForm();
}
$query = ['FROM' => $this->getTable(),
'ORDER' => ['states_id ASC']];
if ($result = $DB->request($query)) {
$number = count($result);
if ($number) {
echo "";
if ($canupdate) {
$rand = mt_rand();
Html::openMassiveActionsForm('mass'.__CLASS__.$rand);
$massiveactionparams = ['num_displayed' => $number,
'container' => 'mass'.__CLASS__.$rand];
Html::showMassiveActions($massiveactionparams);
}
echo "
";
echo "";
if ($canupdate) {
echo "| ";
Html::getCheckAllAsCheckbox('mass'.__CLASS__.$rand);
echo " | ";
}
echo "".__('Status')." | ";
echo "".__('Color', 'archires')." | | ";
echo "
";
while ($ligne = $result->next()) {
$ID = $ligne["id"];
echo "";
if ($canupdate) {
echo "| ";
Html::showMassiveActionCheckBox(__CLASS__, $ID);
echo " | ";
}
echo "".Dropdown::getDropdownName("glpi_states",$ligne["states_id"])." | ";
echo "".$ligne["color"]." | ";
echo "";
}
echo " |
";
if ($canupdate) {
$massiveactionparams['ontop'] = false;
Html::showMassiveActions($massiveactionparams);
}
echo "
";
Html::closeForm();
}
}
}
function dropdownState() {
global $DB;
$colors = [];
foreach ($DB->request("glpi_plugin_archires_statecolors") as $color) {
$colors[] = $color['states_id'];
}
$query = ['FROM' => 'glpi_states',
'WHERE' => ['NOT' => ['id' => [implode("','",$colors)]]],
'ORDER' => 'name'];
$result = $DB->request($query);
if (count($result)) {
$values = [1 => __('All statuses', 'archires')];
while ($data = $result->next()) {
$values[$data['id']] = $data["name"];
}
Dropdown::showFromArray('states_id', $values, ['width' => '80%',
'display_emptychoice' => true]);
}
}
function displayColorState($device) {
global $DB;
$graph = "";
$query_state = ['FROM' => $this->getTable(),
'WHERE' => ['states_id' => $device["states_id"]]];
$result_state = $DB->request($query_state);
$number_state = count($result_state);
if ($number_state && ($device["states_id"] > 0)) {
$row = $result_state->next();
$color_state = $row['color'];
$graph ="".Dropdown::getDropdownName("glpi_states",
$device["states_id"])
."";
} else if (!$number_state && ($device["states_id"] > 0)) {
$graph = Dropdown::getDropdownName("glpi_states",$device["states_id"]);
}
return $graph;
}
function getForbiddenStandardMassiveAction() {
$forbidden = parent::getForbiddenStandardMassiveAction();
$forbidden[] = 'update';
return $forbidden;
}
}