Exemplo n.º 1
0
ossim_valid($directive_id, OSS_DIGIT, 'illegal:' . _("Directive ID"));
ossim_valid($file, OSS_ALPHA, OSS_DOT, OSS_SCORE, 'illegal:' . _("XML File"));
ossim_valid($engine_id, OSS_HEX, OSS_SCORE, 'illegal:' . _("Engine ID"));
ossim_valid($rule, OSS_DIGIT, '\\-', OSS_NULLABLE, 'illegal:' . _("Rule ID"));
ossim_valid($mode, OSS_ALPHA, OSS_NULLABLE, 'illegal:' . _("Mode"));
if (ossim_error()) {
    die(ossim_error());
}
$directive_editor = new Directive_editor($engine_id);
$filepath = file_exists($directive_editor->engine_path . "/" . $file) ? $directive_editor->engine_path . "/" . $file : $directive_editor->main_path . "/" . $file;
if (preg_match("/^\\d+-\\d+-\\d+\$/", $rule)) {
    if (GET('mode') == "delete") {
        $dom = $directive_editor->get_xml($filepath, "DOMXML");
        $direct = $directive_editor->getDirectiveFromXML($dom, $directive_id);
        $tab_rules = $direct->rules;
        $directive_editor->delrule($rule, &$tab_rules);
        if (!$directive_editor->save_xml($filepath, $dom, "DOMXML")) {
            echo "<!-- ERRORDELETE -->";
        }
    } elseif (GET('mode') == "copy") {
        $dom = $directive_editor->get_xml($filepath, "DOMXML");
        $direct = $directive_editor->getDirectiveFromXML($dom, $directive_id);
        $tab_rules = $direct->rules;
        list($id_dir, $id_rule, $id_father) = explode("-", $rule);
        $old_rule = $tab_rules[$id_rule];
        $new_rule = $old_rule->rule->cloneNode(true);
        // deep = true
        $new_rule->setAttribute("name", "Copy of " . $new_rule->getAttribute("name"));
        // Can not copy the root rule at same level => copy as a child (Button disabled for the moment)
        $parent = $old_rule->rule->parentNode;
        $parent->appendChild($new_rule);