Exemple #1
0
 /**
  * @param $options   array
  **/
 function displayActionSelectPattern($options = array())
 {
     $display = false;
     $param['value'] = '';
     if (isset($options['value'])) {
         $param['value'] = $options['value'];
     }
     switch ($options["action_type"]) {
         //If a regex value is used, then always display an autocompletiontextfield
         case "regex_result":
         case "append_regex_result":
             Html::autocompletionTextField($this, "value", $param);
             break;
         case 'fromuser':
         case 'fromitem':
             Dropdown::showYesNo("value", $param['value'], 0);
             $display = true;
             break;
         default:
             $actions = Rule::getActionsByType($options["sub_type"]);
             if (isset($actions[$options["field"]]['type'])) {
                 switch ($actions[$options["field"]]['type']) {
                     case "dropdown":
                         $table = $actions[$options["field"]]['table'];
                         $param['name'] = "value";
                         if (isset($actions[$options["field"]]['condition'])) {
                             $param['condition'] = $actions[$options["field"]]['condition'];
                         }
                         Dropdown::show(getItemTypeForTable($table), $param);
                         $display = true;
                         break;
                     case "dropdown_tickettype":
                         Ticket::dropdownType('value', $param);
                         $display = true;
                         break;
                     case "dropdown_assign":
                         $param['name'] = 'value';
                         $param['right'] = 'own_ticket';
                         User::dropdown($param);
                         $display = true;
                         break;
                     case "dropdown_users":
                         $param['name'] = 'value';
                         $param['right'] = 'all';
                         User::dropdown($param);
                         $display = true;
                         break;
                     case "dropdown_urgency":
                         $param['name'] = 'value';
                         Ticket::dropdownUrgency($param);
                         $display = true;
                         break;
                     case "dropdown_impact":
                         $param['name'] = 'value';
                         Ticket::dropdownImpact($param);
                         $display = true;
                         break;
                     case "dropdown_priority":
                         if ($_POST["action_type"] != 'compute') {
                             $param['name'] = 'value';
                             Ticket::dropdownPriority($param);
                         }
                         $display = true;
                         break;
                     case "dropdown_status":
                         $param['name'] = 'value';
                         Ticket::dropdownStatus($param);
                         $display = true;
                         break;
                     case "yesonly":
                         Dropdown::showYesNo("value", $param['value'], 0);
                         $display = true;
                         break;
                     case "yesno":
                         Dropdown::showYesNo("value", $param['value']);
                         $display = true;
                         break;
                     case "dropdown_management":
                         $param['name'] = 'value';
                         $param['management_restrict'] = 2;
                         $param['withtemplate'] = false;
                         Dropdown::showGlobalSwitch(0, $param);
                         $display = true;
                         break;
                     case "dropdown_users_validate":
                         $used = array();
                         if ($item = getItemForItemtype($options["sub_type"])) {
                             $rule_data = getAllDatasFromTable('glpi_ruleactions', "`action_type` = 'add_validation'\n                                                           AND `field` = 'users_id_validate'\n                                                           AND `" . $item->getRuleIdField() . "`\n                                                            = '" . $options[$item->getRuleIdField()] . "'");
                             foreach ($rule_data as $data) {
                                 $used[] = $data['value'];
                             }
                         }
                         $param['name'] = 'value';
                         $param['right'] = array('validate_incident', 'validate_request');
                         $param['used'] = $used;
                         User::dropdown($param);
                         $display = true;
                         break;
                     case "dropdown_groups_validate":
                         $used = array();
                         if ($item = getItemForItemtype($options["sub_type"])) {
                             $rule_data = getAllDatasFromTable('glpi_ruleactions', "`action_type` = 'add_validation'\n                                                           AND `field` = 'groups_id_validate'\n                                                           AND `" . $item->getRuleIdField() . "`\n                                                            = '" . $options[$item->getRuleIdField()] . "'");
                             foreach ($rule_data as $data) {
                                 $used[] = $data['value'];
                             }
                         }
                         $condition = "(SELECT count(`users_id`)\n                                    FROM `glpi_groups_users`\n                                    WHERE `groups_id` = `glpi_groups`.`id`)";
                         $param['name'] = 'value';
                         $param['condition'] = $condition;
                         $param['right'] = array('validate_incident', 'validate_request');
                         $param['used'] = $used;
                         Group::dropdown($param);
                         $display = true;
                         break;
                     case "dropdown_validation_percent":
                         $ticket = new Ticket();
                         echo $ticket->getValueToSelect('validation_percent', 'value', $param['value']);
                         $display = true;
                         break;
                     default:
                         if ($rule = getItemForItemtype($options["sub_type"])) {
                             $display = $rule->displayAdditionalRuleAction($actions[$options["field"]], $param['value']);
                         }
                         break;
                 }
             }
             if (!$display) {
                 Html::autocompletionTextField($this, "value", $param);
             }
     }
 }
* @brief
*/
// Direct access to file
if (strpos($_SERVER['PHP_SELF'], "ruleaction.php")) {
    include '../inc/includes.php';
    header("Content-Type: text/html; charset=UTF-8");
    Html::header_nocache();
}
if (!defined('GLPI_ROOT')) {
    die("Can not acces directly to this file");
}
Session::checkLoginUser();
// Non define case
if (isset($_POST["sub_type"]) && class_exists($_POST["sub_type"])) {
    if (!isset($_POST["field"])) {
        $_POST["field"] = key(Rule::getActionsByType($_POST["sub_type"]));
    }
    if (!($item = getItemForItemtype($_POST["sub_type"]))) {
        exit;
    }
    if (!isset($_POST[$item->getRuleIdField()])) {
        exit;
    }
    // Existing action
    if ($_POST['ruleactions_id'] > 0) {
        $already_used = false;
    } else {
        // New action
        $ra = getItemForItemtype($item->getRuleActionClass());
        $used = $ra->getAlreadyUsedForRuleID($_POST[$item->getRuleIdField()], $item->getType());
        $already_used = in_array($_POST["field"], $used);
Exemple #3
0
 /**
  * @param $options   array
  **/
 function displayActionSelectPattern($options = array())
 {
     $display = false;
     switch ($_POST["action_type"]) {
         //If a regex value is used, then always display an autocompletiontextfield
         case "regex_result":
         case "append_regex_result":
             Html::autocompletionTextField($this, "value");
             break;
         case 'fromuser':
         case 'fromitem':
             Dropdown::showYesNo("value", 0, 0);
             $display = true;
             break;
         default:
             $actions = Rule::getActionsByType($options["sub_type"]);
             if (isset($actions[$options["field"]]['type'])) {
                 switch ($actions[$options["field"]]['type']) {
                     case "dropdown":
                         $table = $actions[$options["field"]]['table'];
                         $param = array('name' => "value");
                         if (isset($actions[$options["field"]]['condition'])) {
                             $param['condition'] = $actions[$options["field"]]['condition'];
                         }
                         Dropdown::show(getItemTypeForTable($table), $param);
                         $display = true;
                         break;
                     case "dropdown_tickettype":
                         Ticket::dropdownType('value');
                         $display = true;
                         break;
                     case "dropdown_assign":
                         User::dropdown(array('name' => 'value', 'right' => 'own_ticket'));
                         $display = true;
                         break;
                     case "dropdown_users":
                         User::dropdown(array('name' => 'value', 'right' => 'all'));
                         $display = true;
                         break;
                     case "dropdown_urgency":
                         Ticket::dropdownUrgency(array('name' => 'value'));
                         $display = true;
                         break;
                     case "dropdown_impact":
                         Ticket::dropdownImpact(array('name' => 'value'));
                         $display = true;
                         break;
                     case "dropdown_priority":
                         if ($_POST["action_type"] != 'compute') {
                             Ticket::dropdownPriority(array('name' => 'value'));
                         }
                         $display = true;
                         break;
                     case "dropdown_status":
                         Ticket::dropdownStatus(array('name' => "value"));
                         $display = true;
                         break;
                     case "yesonly":
                         Dropdown::showYesNo("value", 0, 0);
                         $display = true;
                         break;
                     case "yesno":
                         Dropdown::showYesNo("value");
                         $display = true;
                         break;
                     case "dropdown_management":
                         Dropdown::showGlobalSwitch(0, array('name' => 'value', 'management_restrict' => 2, 'withtemplate' => false));
                         $display = true;
                         break;
                     case "dropdown_users_validate":
                         User::dropdown(array('name' => "value", 'right' => array('validate_incident', 'validate_request')));
                         $display = true;
                         break;
                     default:
                         if ($rule = getItemForItemtype($options["sub_type"])) {
                             $display = $rule->displayAdditionalRuleAction($actions[$options["field"]]);
                         }
                         break;
                 }
             }
             if (!$display) {
                 Html::autocompletionTextField($this, "value");
             }
     }
 }