tiki-admin_integrator_rules.php 6.98 KB
Newer Older
1 2
<?php
/**
3
 * $Id: /cvsroot/tikiwiki/tiki/tiki-admin_integrator_rules.php,v 1.26 2007-10-12 07:55:24 nyloth Exp $
4 5 6 7
 *
 * Admin interface for rules management
 *
 */
changi67's avatar
changi67 committed
8 9
require_once ('tiki-setup.php');
require_once ('lib/integrator/integrator.php');
zaufi's avatar
zaufi committed
10
// If Integrator is ON, check permissions...
changi67's avatar
changi67 committed
11 12 13 14
if ($prefs['feature_integrator'] != 'y') {
    $smarty->assign('msg', tra("This feature is disabled") . ": feature_integrator");
    $smarty->display("error.tpl");
    die;
sylvieg's avatar
sylvieg committed
15
}
16
if (($tiki_p_admin_integrator != 'y') && ($tiki_p_admin != 'y')) {
changi67's avatar
changi67 committed
17
    $smarty->assign('errortype', 401);
18
    $smarty->assign('msg', tra("You do not have permission to use this feature"));
19
    $smarty->display("error.tpl");
20 21
    die;
}
22
// Setup local variables from request or set default values
changi67's avatar
changi67 committed
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
$repID = (isset($_REQUEST["repID"]) && strlen($_REQUEST["repID"]) > 0) ? $_REQUEST["repID"] : 0;
$ruleID = (isset($_REQUEST["ruleID"]) && strlen($_REQUEST["ruleID"]) > 0) ? $_REQUEST["ruleID"] : 0;
$ord = (isset($_REQUEST["ord"]) && strlen($_REQUEST["ord"]) > 0) ? $_REQUEST["ord"] : 0;
$srcrep = (isset($_REQUEST["srcrep"]) && strlen($_REQUEST["srcrep"]) > 0) ? $_REQUEST["srcrep"] : 0;
$srch = isset($_REQUEST["srch"]) ? $_REQUEST["srch"] : '';
$repl = isset($_REQUEST["repl"]) ? $_REQUEST["repl"] : '';
$description = isset($_REQUEST["description"]) ? $_REQUEST["description"] : '';
$rxmod = isset($_REQUEST["rxmod"]) ? $_REQUEST["rxmod"] : '';
$file = isset($_REQUEST["file"]) ? $_REQUEST["file"] : '';
$type = isset($_REQUEST["type"]) ? ($_REQUEST["type"] == 'on' ? 'y' : 'n') : 'n';
$casesense = isset($_REQUEST["casesense"]) ? ($_REQUEST["casesense"] == 'on' ? 'y' : 'n') : 'n';
$code = isset($_REQUEST["code"]) ? ($_REQUEST["code"] == 'on' ? 'y' : 'n') : 'n';
$html = isset($_REQUEST["html"]) ? ($_REQUEST["html"] == 'on' ? 'y' : 'n') : 'n';
$all = isset($_REQUEST["all"]) ? ($_REQUEST["all"] == 'on' ? 'y' : 'n') : 'n';
$enabled = isset($_REQUEST["enabled"]) ? ($_REQUEST["enabled"] == 'on' ? 'y' : 'n') : 'n';
if (!isset($_REQUEST["repID"]) || $repID <= 0) {
39
    $smarty->assign('msg', tra("No repository"));
40
    $smarty->display("error.tpl");
41 42
    die;
}
43 44
// Create instance of integrator
$integrator = new TikiIntegrator($dbTiki);
zaufi's avatar
zaufi committed
45
// Check if copy button pressed
changi67's avatar
changi67 committed
46
if (isset($_REQUEST["copy"]) && ($srcrep > 0)) $integrator->copy_rules($srcrep, $repID);
47
// Check if 'save' button pressed ...
changi67's avatar
changi67 committed
48
if (isset($_REQUEST["save"])) {
49
    // ... and all mandatory paramaters r OK
changi67's avatar
changi67 committed
50 51
    if (strlen($srch) > 0) $integrator->add_replace_rule($repID, $ruleID, $ord, $srch, $repl, $type, $casesense, $rxmod, $enabled, $description);
    else {
52
        $smarty->assign('msg', tra("Search is mandatory field"));
53
        $smarty->display("error.tpl");
54 55 56 57
        die;
    }
}
// Check if 'preview' button pressed ...
changi67's avatar
changi67 committed
58
if (isset($_REQUEST["preview"])) {
59 60
    // Prepeare rule data
    $rule = array();
changi67's avatar
changi67 committed
61 62 63 64 65 66 67 68 69
    $rule["repID"] = $repID;
    $rule["ruleID"] = $ruleID;
    $rule["ord"] = $ord;
    $rule["srch"] = $srch;
    $rule["repl"] = $repl;
    $rule["type"] = $type;
    $rule["casesense"] = $casesense;
    $rule["rxmod"] = $rxmod;
    $rule["enabled"] = $enabled;
70 71
    $rule["description"] = $description;
    // Reassign values in form
changi67's avatar
changi67 committed
72 73 74 75 76 77 78 79
    $smarty->assign('ruleID', $rule["ruleID"]);
    $smarty->assign('ord', $rule["ord"]);
    $smarty->assign('srch', $rule["srch"]);
    $smarty->assign('repl', $rule["repl"]);
    $smarty->assign('type', $rule["type"]);
    $smarty->assign('casesense', $rule["casesense"]);
    $smarty->assign('rxmod', $rule["rxmod"]);
    $smarty->assign('enabled', $rule["enabled"]);
80 81
    $smarty->assign('description', $rule["description"]);
    // Have smth to show?
changi67's avatar
changi67 committed
82
    if (($html != 'y' || $code != 'y')) {
83 84 85 86
        // Get repository configuration data
        $rep = $integrator->get_repository($repID);
        // Check if file given and present at configured location
        $f = $integrator->get_rep_file($rep, $file);
changi67's avatar
changi67 committed
87 88
        if ((substr($rep["path"], 0, 7) != 'http://') && (substr($rep["path"], 0, 8) != 'https://') && !file_exists($f)) {
            $smarty->assign('msg', tra("File not found ") . $f);
89
            $smarty->display("error.tpl");
90 91 92
            die;
        }
        // Get file content to string
zaufi's avatar
zaufi committed
93
        $data = @file_get_contents($f);
changi67's avatar
changi67 committed
94 95
        if (isset($php_errormsg)) $data.= "ERROR: " . $php_errormsg;
        else {
zaufi's avatar
zaufi committed
96
            // Should we apply all configured rules or only current one?
changi67's avatar
changi67 committed
97
            if ($all == 'y') {
zaufi's avatar
zaufi committed
98
                $rules = $integrator->list_rules($repID);
changi67's avatar
changi67 committed
99
                if (is_array($rules)) foreach($rules as $r) if (($r["ruleID"] !== $ruleID) && $r["enabled"]) $data = $integrator->apply_rule($rep, $r, $data);
zaufi's avatar
zaufi committed
100
            }
101
            // Apply rule (make this rule 'enabled' :)
changi67's avatar
changi67 committed
102 103
            $se = $rule["enabled"];
            $rule["enabled"] = 'y';
zaufi's avatar
zaufi committed
104
            $data = $integrator->apply_rule($rep, $rule, $data);
105
            $rule["enabled"] = $se;
106
        }
107 108 109 110
        $smarty->assign_by_ref('preview_data', $data);
    }
}
// Whether some action requested?
changi67's avatar
changi67 committed
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
if (isset($_REQUEST["action"])) {
    switch ($_REQUEST["action"]) {
        case 'edit':
            if ($ruleID != 0) {
                $rule = $integrator->get_rule($ruleID);
                $smarty->assign('ruleID', $rule["ruleID"]);
                $smarty->assign('ord', $rule["ord"]);
                $smarty->assign('srch', $rule["srch"]);
                $smarty->assign('repl', $rule["repl"]);
                $smarty->assign('type', $rule["type"]);
                $smarty->assign('casesense', $rule["casesense"]);
                $smarty->assign('rxmod', $rule["rxmod"]);
                $smarty->assign('enabled', $rule["enabled"]);
                $smarty->assign('description', $rule["description"]);
            }
126
        break;
changi67's avatar
changi67 committed
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
        case 'rm':
            if ($ruleID != 0) {
                $area = "delintegratorrule";
                if ($prefs['feature_ticketlib2'] != 'y' or (isset($_POST['daconfirm']) and isset($_SESSION["ticket_$area"]))) {
                    key_check($area);
                    $integrator->remove_rule($ruleID);
                } else {
                    key_get($area);
                }
            }
        break;
        default:
            $smarty->assign('msg', tra("Requested action in not supported on repository"));
            $smarty->display("error.tpl");
            die;
142 143 144 145 146 147
        break;
    }
}
// Get repository name
$r = $integrator->get_repository($repID);
$smarty->assign('name', $r["name"]);
zaufi's avatar
zaufi committed
148
// Reassign checkboxes
149 150 151
$smarty->assign('file', $file);
$smarty->assign('code', $code);
$smarty->assign('html', $html);
changi67's avatar
changi67 committed
152
$smarty->assign('all', $all);
zaufi's avatar
zaufi committed
153
// Fill list of rules
154 155 156
$rules = $integrator->list_rules($repID);
$smarty->assign_by_ref('rules', $rules);
$smarty->assign('repID', $repID);
zaufi's avatar
zaufi committed
157
// Fill list of possible source repositories
158
$allreps = $integrator->list_repositories(false);
zaufi's avatar
zaufi committed
159 160 161
$reps = array();
foreach($allreps as $rep) $reps[$rep["repID"]] = $rep["name"];
$smarty->assign_by_ref('reps', $reps);
162 163
// disallow robots to index page:
$smarty->assign('metatag_robots', 'NOINDEX, NOFOLLOW');
164
// Display the template
changi67's avatar
changi67 committed
165
$smarty->assign('mid', 'tiki-admin_integrator_rules.tpl');
166
$smarty->display("tiki.tpl");