/**
  * 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>";
 }
Example #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>";
 }
Example #3
0
 public function defineMethod($callable = [], $parameters)
 {
     $alias = $callable[0];
     $method = $callable[1];
     if (is_object($bind)) {
         $alias = get_class($alias);
         $Rule = RuleCollection::getRule($alias, true)->Instance = $bind;
     } else {
         $Rule = $this->getRule($alias, true);
     }
     foreach ($parameters as $key => $value) {
         if ($key[0] === ":") {
             $Rule->setParameter(ltrim($key, ':'), $method);
         } else {
             $Rule->setDependency($key, $value, $method);
         }
     }
     self::$rules[$alias] = $Rule;
 }
Example #4
0
      $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";
Example #5
0
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";
}
Example #6
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"]);
Example #8
0
 /**
  * @since version 0.85
  *
  * @see CommonDBTM::processMassiveActionsForOneItemtype()
  **/
 static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids)
 {
     global $DB;
     switch ($ma->getAction()) {
         case 'duplicate':
             $rulecollection = new RuleCollection();
             foreach ($ids as $id) {
                 if ($item->getFromDB($id)) {
                     if ($rulecollection->duplicateRule($id)) {
                         $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));
                 }
             }
             break;
         case 'export':
             if (count($ids)) {
                 $_SESSION['exportitems'] = $ids;
                 $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_OK);
                 $ma->setRedirect('rule.backup.php?action=download&itemtype=' . $item->getType());
             }
             break;
         case 'move_rule':
             $input = $ma->getInput();
             $collectionname = $input['rule_class_name'] . 'Collection';
             $rulecollection = new $collectionname();
             if ($rulecollection->canUpdate()) {
                 foreach ($ids as $id) {
                     if ($item->getFromDB($id)) {
                         if ($rulecollection->moveRule($id, $input['ranking'], $input['move_type'])) {
                             $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(), $ids, MassiveAction::ACTION_NORIGHT);
                 $ma->addMessage($item->getErrorMessage(ERROR_RIGHT));
             }
             break;
     }
     parent::processMassiveActionsForOneItemtype($ma, $item, $ids);
 }
Example #9
0
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();
}
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::checkSeveralRightsOr(array('rule_dictionnary_dropdown' => READ, 'rule_dictionnary_software' => READ));
Html::header(__('Administration'), $_SERVER['PHP_SELF'], "admin", "dictionnary", -1);
RuleCollection::titleBackup();
echo "<div class='center'><table class='tab_cadre'>";
echo "<tr><th colspan='4'>" . __('Dictionaries') . "</th></tr>";
echo "<tr class='tab_bg_1'><td class='top'><table class='tab_cadre'>";
echo "<tr><th>" . __('Global dictionary') . "</th></tr>";
if (Session::haveRight("rule_dictionnary_software", READ)) {
    echo "<tr class='tab_bg_1'><td class='center b'>";
    echo "<a href=\"ruledictionnarysoftware.php\">" . _n('Software', 'Software', 2) . "</a></td></tr>";
}
if (Session::haveRight("rule_dictionnary_dropdown", READ)) {
    echo "<tr class='tab_bg_1'><td class='center b'>";
    echo "<a href=\"ruledictionnarymanufacturer.php\">" . _n('Manufacturer', 'Manufacturers', 2) . "</a></td></tr>";
}
if (Session::haveRight("rule_dictionnary_printer", READ)) {
    echo "<tr class='tab_bg_1'><td class='center b'>";
    echo "<a href=\"ruledictionnaryprinter.php\">" . _n('Printer', 'Printers', 2) . "</a></td></tr>";
Example #11
0
 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']);
 }
 /**
  * Process all the rules collection
  *
  * @param input the input data used to check criterias
  * @param output the initial ouput array used to be manipulate by actions
  * @param params parameters for all internal functions
  * @param force_no_cache don't write rule's result into cache (for preview mode mainly)
  *
  * @return the output array updated by actions
  **/
 function processAllRules($input = array(), $output = array(), $params = array(), $force_no_cache = false)
 {
     //If cache enabled : try to get value from the cache
     $new_values = $this->checkDataInCache($input);
     if ($new_values != Rule::RULE_NOT_IN_CACHE) {
         $output["_rule_process"] = true;
         return array_merge($output, $new_values);
     }
     $output = parent::processAllRules($input, $output, $params);
     if (!$force_no_cache && isset($output["_ruleid"])) {
         $this->insertDataInCache($input, $output);
         unset($output["_ruleid"]);
     }
     return $output;
 }
Example #13
0
 /**
  * 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);
 }
 /**
  * @see RuleCollection::preProcessPreviewResults()
  **/
 function preProcessPreviewResults($output)
 {
     $output = parent::preProcessPreviewResults($output);
     return Ticket::showPreviewAssignAction($output);
 }
Example #15
0
/** @file
 * @brief
 * @since version 0.85
*/
include "../inc/includes.php";
Session::checkCentralAccess();
if (isset($_GET['action'])) {
    $action = $_GET['action'];
} else {
    if (isset($_POST['action'])) {
        $action = $_POST['action'];
    } else {
        $action = "import";
    }
}
$rulecollection = new RuleCollection();
$rulecollection->checkGlobal(READ);
if ($action != "export") {
    Html::header(Rule::getTypeName(Session::getPluralNumber()), $_SERVER['PHP_SELF'], "admin", "rule", -1);
}
switch ($action) {
    case "preview_import":
        $rulecollection->checkGlobal(CREATE);
        if (RuleCollection::previewImportRules()) {
            break;
        }
    case "import":
        $rulecollection->checkGlobal(CREATE);
        RuleCollection::displayImportRulesForm();
        break;
    case "export":