/**
  * Show cache statis for a current rule
  *
  * @param $target where to go
  **/
 function showCacheStatusByRule($target)
 {
     global $DB, $LANG;
     echo "<div class='center'>";
     echo "<table  class='tab_cadre_fixe'>";
     $rulecollection = RuleCollection::getClassByType($this->getType());
     $query = "SELECT *\n                FROM `" . $rulecollection->cache_table . "`,\n                     `glpi_rules`\n                WHERE `" . $rulecollection->cache_table . "`.`rules_id` = `glpi_rules`.`id`\n                      AND `" . $rulecollection->cache_table . "`.`rules_id` = '" . $this->fields["id"] . "'\n                ORDER BY `name`";
     $res_count = $DB->query($query);
     $this->showCacheRuleHeader();
     while ($datas = $DB->fetch_array($res_count)) {
         echo "<tr>";
         $this->showCacheRuleDetail($datas);
         echo "</tr>\n";
     }
     echo "</table><br><br>\n";
     echo "<a href='{$target}'>" . $LANG['rulesengine'][100] . "</a></div>";
 }
Exemple #2
0
 /**
  * Show cache statis for a current rule
  *
  * @param $target where to go
  **/
 function showCacheStatusByRule($target)
 {
     global $DB;
     echo "<div class='center'>";
     echo "<table  class='tab_cadre_fixe'>";
     $rulecollection = RuleCollection::getClassByType($this->getType());
     $query = "SELECT *\n                FROM `" . $rulecollection->cache_table . "`\n                WHERE `" . $rulecollection->cache_table . "`.`rules_id` = '" . $this->fields["id"] . "'";
     $res_count = $DB->query($query);
     $this->showCacheRuleHeader();
     while ($datas = $DB->fetch_assoc($res_count)) {
         echo "<tr>";
         $this->showCacheRuleDetail($datas);
         echo "</tr>\n";
     }
     echo "</table><br><br>\n";
     echo "<a href='{$target}'>" . __('Cache information') . "</a></div>";
 }
      $it    = explode("=",$arg);
      $it[0] = preg_replace('/^--/', '', $it[0]);

      //Replace the ° by = the find the good filter
      $it           = str_replace('°', '=', $it);
      $_GET[$it[0]] = $it[1];
   }
}

include ('../inc/includes.php');

// No debug mode
$_SESSION['glpi_use_mode'] == Session::NORMAL_MODE;

if (isset($_GET["dictionnary"])) {
   $rulecollection = RuleCollection::getClassByType($_GET["dictionnary"]);
   if ($rulecollection) {
      if ($_GET["dictionnary"]=='RuleDictionnarySoftware' && isset($_GET["manufacturer"])) {
         $rulecollection->replayRulesOnExistingDB(0, 0, array(), $_GET["manufacturer"]);
      } else {
         $rulecollection->replayRulesOnExistingDB();
      }
   }

} else {
   echo "Usage : php -q -f compute_dictionnary.php dictionnary=<option>  [ manufacturer=ID ]\n";
   echo "Options values :\n";
   echo "RuleDictionnarySoftware : softwares\n";
   echo "RuleDictionnaryManufacturer : manufacturers\n";
   echo "RuleDictionnaryPrinter : printers\n";
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/>.
--------------------------------------------------------------------------
*/
/** @file
* @brief
*/
include '../inc/includes.php';
Session::checkCentralAccess();
if (isset($_GET["id"])) {
    $generic_rule = new Rule();
    $generic_rule->getFromDB($_GET["id"]);
    $generic_rule->checkGlobal(READ);
    $rulecollection = RuleCollection::getClassByType($generic_rule->fields["sub_type"]);
    include GLPI_ROOT . "/front/rule.common.form.php";
}
Exemple #5
0
 /**
  * @since version 0.83 (before addRule)
  *
  * @param $input array of values
  **/
 function executeAddRule($input)
 {
     $this->check($_POST["affectentity"], UPDATE);
     $collection = RuleCollection::getClassByType($_POST['sub_type']);
     $rule = $collection->getRuleClass($_POST['sub_type']);
     $ruleid = $rule->add($_POST);
     if ($ruleid) {
         //Add an action associated to the rule
         $ruleAction = new RuleAction();
         //Action is : affect computer to this entity
         $ruleAction->addActionByAttributes("assign", $ruleid, "entities_id", $_POST["affectentity"]);
         switch ($_POST['sub_type']) {
             case 'RuleRight':
                 if ($_POST["profiles_id"]) {
                     $ruleAction->addActionByAttributes("assign", $ruleid, "profiles_id", $_POST["profiles_id"]);
                 }
                 $ruleAction->addActionByAttributes("assign", $ruleid, "is_recursive", $_POST["is_recursive"]);
         }
     }
     Event::log($ruleid, "rules", 4, "setup", sprintf(__('%s adds the item'), $_SESSION["glpiname"]));
     Html::back();
 }
  @since     2010

  ------------------------------------------------------------------------
*/
if (!defined('GLPI_ROOT')) {
    include "../../../inc/includes.php";
}
$sub_type = 0;
if (isset($_POST["sub_type"])) {
    $sub_type = $_POST["sub_type"];
} else {
    if (isset($_GET["sub_type"])) {
        $sub_type = $_GET["sub_type"];
    }
}
$rulecollection = RuleCollection::getClassByType($sub_type);
if ($rulecollection->isRuleRecursive()) {
    $rulecollection->setEntity($_SESSION['glpiactive_entity']);
}
$rulecollection->checkGlobal(READ);
if (!strpos($_SERVER['PHP_SELF'], "popup")) {
    Html::header(__('Setup'), $_SERVER['PHP_SELF'], "config", "display");
}
// Need for RuleEngines
foreach ($_POST as $key => $val) {
    $_POST[$key] = stripslashes($_POST[$key]);
}
$input = $rulecollection->showRulesEnginePreviewCriteriasForm($_SERVER['PHP_SELF'], $_POST);
if (isset($_POST["test_all_rules"])) {
    //Unset values that must not be processed by the rule
    unset($_POST["sub_type"]);
along with GLPI; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
--------------------------------------------------------------------------
*/
// ----------------------------------------------------------------------
// Original Author of file: Walid Nouh
// Purpose of file:
// ----------------------------------------------------------------------
if (!defined('GLPI_ROOT')) {
    define('GLPI_ROOT', '..');
    include GLPI_ROOT . "/inc/includes.php";
}
if (!strpos($_SERVER['PHP_SELF'], "popup")) {
    commonHeader($LANG['rulesengine'][17], $_SERVER['PHP_SELF'], "admin", "dictionnary", "cache");
}
if (isset($_GET["sub_type"])) {
    echo "<br>";
    $rulecollection = RuleCollection::getClassByType($_GET["sub_type"]);
    if ($rulecollection->canView()) {
        if (!isset($_GET["rules_id"])) {
            $rulecollection->showCacheStatusForRuleType();
        } else {
            $rule = new $_GET["sub_type"]();
            $rule->getRuleWithCriteriasAndActions($_GET["rules_id"], 0, 0);
            $rule->showCacheStatusByRule($_SERVER["HTTP_REFERER"]);
        }
    }
}
if (!strpos($_SERVER['PHP_SELF'], "popup")) {
    commonFooter();
}
 function addRule($input)
 {
     global $LANG;
     $this->check($_POST["affectentity"], 'w');
     $collection = RuleCollection::getClassByType($_POST['sub_type']);
     $rule = $collection->getRuleClass($_POST['sub_type']);
     $ruleid = $rule->add($_POST);
     if ($ruleid) {
         //Add an action associated to the rule
         $ruleAction = new RuleAction();
         //Action is : affect computer to this entity
         $ruleAction->addActionByAttributes("assign", $ruleid, "entities_id", $_POST["affectentity"]);
         switch ($_POST['sub_type']) {
             case 'RuleRight':
                 if ($_POST["profiles_id"]) {
                     $ruleAction->addActionByAttributes("assign", $ruleid, "profiles_id", $_POST["profiles_id"]);
                 }
                 $ruleAction->addActionByAttributes("assign", $ruleid, "is_recursive", $_POST["is_recursive"]);
         }
     }
     Event::log($ruleid, "rules", 4, "setup", $_SESSION["glpiname"] . " " . $LANG['log'][22]);
     glpi_header($_SERVER['HTTP_REFERER']);
 }
 /**
  * Import a value in a dropdown table.
  *
  * This import a new dropdown if it doesn't exist - Play dictionnary if needed
  *
  * @param $value           string   Value of the new dropdown (need to be addslashes)
  * @param $entities_id     int      entity in case of specific dropdown (default -1)
  * @param $external_params array    (manufacturer) (need to be addslashes)
  * @param $comment                  (default '') (need to be addslashes)
  * @param $add                      if true, add it if not found. if false,
  *                                  just check if exists (true by default)
  *
  * @return integer : dropdown id.
  **/
 function importExternal($value, $entities_id = -1, $external_params = array(), $comment = "", $add = true)
 {
     $value = trim($value);
     if (strlen($value) == 0) {
         return 0;
     }
     $ruleinput = array("name" => stripslashes($value));
     $rulecollection = RuleCollection::getClassByType($this->getType(), true);
     foreach ($this->additional_fields_for_dictionnary as $field) {
         if (isset($external_params[$field])) {
             $ruleinput[$field] = $external_params[$field];
         } else {
             $ruleinput[$field] = '';
         }
     }
     /*
           switch ($this->getTable()) {
              case "glpi_computermodels" :
              case "glpi_monitormodels" :
              case "glpi_printermodels" :
              case "glpi_peripheralmodels" :
              case "glpi_phonemodels" :
              case "glpi_networkequipmentmodels" :
                 $ruleinput["manufacturer"] = $external_params["manufacturer"];
                 break;
           }*/
     $input["name"] = $value;
     $input["comment"] = $comment;
     $input["entities_id"] = $entities_id;
     if ($rulecollection) {
         $res_rule = $rulecollection->processAllRules(Toolbox::stripslashes_deep($ruleinput), array(), array());
         if (isset($res_rule["name"])) {
             $input["name"] = $res_rule["name"];
         }
     }
     return $add ? $this->import($input) : $this->findID($input);
 }