ruleaction.php 3.64 KB
Newer Older
moyooo's avatar
moyooo committed
1
<?php
2 3 4
/**
 * ---------------------------------------------------------------------
 * GLPI - Gestionnaire Libre de Parc Informatique
5
 * Copyright (C) 2015-2018 Teclib' and contributors.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
 *
 * 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/>.
 * ---------------------------------------------------------------------
moyooo's avatar
moyooo committed
31 32 33
 */

// Direct access to file
34
if (strpos($_SERVER['PHP_SELF'], "ruleaction.php")) {
35
   include ('../inc/includes.php');
remi's avatar
remi committed
36
   header("Content-Type: text/html; charset=UTF-8");
yllen's avatar
yllen committed
37
   Html::header_nocache();
yllen's avatar
yllen committed
38 39
} else if (!defined('GLPI_ROOT')) {
   die("Sorry. You can't access this file directly");
remi's avatar
remi committed
40
}
moyooo's avatar
moyooo committed
41

42
Session::checkLoginUser();
remi's avatar
remi committed
43 44

// Non define case
45
if (isset($_POST["sub_type"]) && class_exists($_POST["sub_type"])) {
remi's avatar
remi committed
46
   if (!isset($_POST["field"])) {
yllen's avatar
yllen committed
47
      $_POST["field"] = key(Rule::getActionsByType($_POST["sub_type"]));
remi's avatar
remi committed
48
   }
49 50 51 52 53 54
   if (!($item = getItemForItemtype($_POST["sub_type"]))) {
      exit();
   }
   if (!isset($_POST[$item->getRuleIdField()])) {
      exit();
   }
yllen's avatar
yllen committed
55

moyooo's avatar
moyooo committed
56 57 58 59 60
   // Existing action
   if ($_POST['ruleactions_id'] > 0) {
      $already_used = false;
   } else { // New action
      $ra           = getItemForItemtype($item->getRuleActionClass());
yllen's avatar
CS  
yllen committed
61 62
      $used         = $ra->getAlreadyUsedForRuleID($_POST[$item->getRuleIdField()],
                                                   $item->getType());
moyooo's avatar
moyooo committed
63 64 65 66 67 68 69 70 71
      $already_used = in_array($_POST["field"], $used);
   }

   echo "<table width='100%'><tr><td width='30%'>";

   $action_type = '';
   if (isset($_POST["action_type"])) {
      $action_type = $_POST["action_type"];
   }
remi's avatar
remi committed
72

73
   $randaction = RuleAction::dropdownActions(['subtype'     => $_POST["sub_type"],
moyooo's avatar
moyooo committed
74 75 76
                                                   'name'        => "action_type",
                                                   'field'       => $_POST["field"],
                                                   'value'       => $action_type,
77
                                                   'alreadyused' => $already_used]);
moyooo's avatar
moyooo committed
78 79

   echo "</td><td>";
moyooo's avatar
moyooo committed
80
   echo "<span id='action_type_span$randaction'>\n";
remi's avatar
remi committed
81 82
   echo "</span>\n";

83
   $paramsaction = ['action_type'                   => '__VALUE__',
yllen's avatar
CS  
yllen committed
84 85
                         'field'                         => $_POST["field"],
                         'sub_type'                      => $_POST["sub_type"],
86
                         $item->getForeignKeyField()     => $_POST[$item->getForeignKeyField()]];
yllen's avatar
CS  
yllen committed
87

88 89
   Ajax::updateItemOnSelectEvent("dropdown_action_type$randaction", "action_type_span$randaction",
                                 $CFG_GLPI["root_doc"]."/ajax/ruleactionvalue.php", $paramsaction);
yllen's avatar
yllen committed
90

moyooo's avatar
moyooo committed
91
   if (isset($_POST['value'])) {
92
      $paramsaction['value'] = $_POST['value'];
moyooo's avatar
moyooo committed
93 94
   }

95 96
   Ajax::updateItem("action_type_span$randaction", $CFG_GLPI["root_doc"]."/ajax/ruleactionvalue.php",
                    $paramsaction, "dropdown_action_type$randaction");
moyooo's avatar
moyooo committed
97
   echo "</td></tr></table>";
remi's avatar
remi committed
98
}