tiki-admin_integrator_rules.php 7.47 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 8 9 10
 *
 * Admin interface for rules management
 *
 */

require_once('tiki-setup.php');
require_once('lib/integrator/integrator.php');
zaufi's avatar
zaufi committed
11 12

// If Integrator is ON, check permissions...
13
if ($prefs['feature_integrator'] != 'y')
zaufi's avatar
zaufi committed
14
{
sylvieg's avatar
sylvieg committed
15
	$smarty->assign('msg', tra("This feature is disabled").": feature_integrator");
16
	$smarty->display("error.tpl");
sylvieg's avatar
sylvieg committed
17 18
	die;
}
19 20
if (($tiki_p_admin_integrator != 'y') && ($tiki_p_admin != 'y')) {
	$smarty->assign('errortype', 401);
21
    $smarty->assign('msg', tra("You do not have permission to use this feature"));
22
    $smarty->display("error.tpl");
23 24 25
    die;
}

26
// Setup local variables from request or set default values
zaufi's avatar
zaufi committed
27 28 29 30 31 32 33 34
$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;
35 36 37 38 39 40 41 42 43 44
$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';
45
$enabled     =  isset ($_REQUEST["enabled"])     ? ($_REQUEST["enabled"]   == 'on' ? 'y' : 'n')  : 'n';
46 47 48

if (!isset($_REQUEST["repID"]) || $repID <= 0)
{
49
    $smarty->assign('msg', tra("No repository"));
50
    $smarty->display("error.tpl");
51 52
    die;
}
53 54 55 56

// Create instance of integrator
$integrator = new TikiIntegrator($dbTiki);

zaufi's avatar
zaufi committed
57 58 59
// Check if copy button pressed
if (isset($_REQUEST["copy"]) && ($srcrep > 0))
    $integrator->copy_rules($srcrep, $repID);
60 61 62 63 64 65

// Check if 'save' button pressed ...
if (isset($_REQUEST["save"]))
{
    // ... and all mandatory paramaters r OK
    if (strlen($srch)  > 0)
zaufi's avatar
zaufi committed
66
        $integrator->add_replace_rule($repID, $ruleID, $ord, $srch, $repl,
67 68
                                      $type, $casesense, $rxmod, $enabled, 
                                      $description);
69 70
    else
    {
71
        $smarty->assign('msg', tra("Search is mandatory field"));
72
        $smarty->display("error.tpl");
73 74 75 76
        die;
    }
}
// Check if 'preview' button pressed ...
zaufi's avatar
zaufi committed
77
if (isset($_REQUEST["preview"]))
78 79 80
{
    // Prepeare rule data
    $rule = array();
81 82 83 84 85 86 87 88
    $rule["repID"]       = $repID;
    $rule["ruleID"]      = $ruleID;
    $rule["ord"]         = $ord;
    $rule["srch"]        = $srch;
    $rule["repl"]        = $repl;
    $rule["type"]        = $type;
    $rule["casesense"]   = $casesense;
    $rule["rxmod"]       = $rxmod;
89
    $rule["enabled"]     = $enabled;
90 91 92
    $rule["description"] = $description;

    // Reassign values in form
93 94 95 96 97 98 99
    $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"]);
100
    $smarty->assign('enabled',     $rule["enabled"]);
101 102 103 104 105 106 107 108 109
    $smarty->assign('description', $rule["description"]);

    // Have smth to show?
    if (($html != 'y' || $code != 'y'))
    {
        // 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);
110 111 112
        if ((substr($rep["path"], 0, 7) != 'http://')
         && (substr($rep["path"], 0, 8) != 'https://')
         && !file_exists($f))
113
        {
114
            $smarty->assign('msg', tra("File not found ").$f);
115
            $smarty->display("error.tpl");
116 117 118
            die;
        }
        // Get file content to string
zaufi's avatar
zaufi committed
119
        $data = @file_get_contents($f);
120
        if (isset($php_errormsg)) $data .= "ERROR: ".$php_errormsg;
zaufi's avatar
zaufi committed
121
        else
122
        {
zaufi's avatar
zaufi committed
123 124 125 126 127 128
            // Should we apply all configured rules or only current one?
            if ($all == 'y')
            {
                $rules = $integrator->list_rules($repID);
                if (is_array($rules))
                    foreach ($rules as $r)
129
                        if (($r["ruleID"] !== $ruleID) && $r["enabled"])
zaufi's avatar
zaufi committed
130 131
                            $data = $integrator->apply_rule($rep, $r, $data);
            }
132 133
            // Apply rule (make this rule 'enabled' :)
            $se = $rule["enabled"]; $rule["enabled"] = 'y';
zaufi's avatar
zaufi committed
134
            $data = $integrator->apply_rule($rep, $rule, $data);
135
            $rule["enabled"] = $se;
136
        }
137 138 139 140 141 142 143 144 145 146 147 148 149
        $smarty->assign_by_ref('preview_data', $data);
    }
}

// Whether some action requested?
if (isset($_REQUEST["action"]))
{
    switch ($_REQUEST["action"])
    {
    case 'edit':
        if ($ruleID != 0)
        {
            $rule = $integrator->get_rule($ruleID);
150 151 152 153 154 155 156
            $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"]);
157
            $smarty->assign('enabled',     $rule["enabled"]);
158 159 160 161
            $smarty->assign('description', $rule["description"]);
        }
        break;
    case 'rm':
mose's avatar
mose committed
162 163
        if ($ruleID != 0) {
					$area = "delintegratorrule";
164
					if ($prefs['feature_ticketlib2'] != 'y' or (isset($_POST['daconfirm']) and isset($_SESSION["ticket_$area"]))) {
mose's avatar
mose committed
165 166 167 168 169 170
						key_check($area);
						$integrator->remove_rule($ruleID);
					} else {
						key_get($area);
					}
				}
171 172
        break;
    default:
sylvieg's avatar
sylvieg committed
173
        $smarty->assign('msg', tra("Requested action in not supported on repository"));
174
        $smarty->display("error.tpl");
175 176 177 178 179 180
        die; break;
    }
}
// Get repository name
$r = $integrator->get_repository($repID);
$smarty->assign('name', $r["name"]);
zaufi's avatar
zaufi committed
181 182

// Reassign checkboxes
183 184 185
$smarty->assign('file', $file);
$smarty->assign('code', $code);
$smarty->assign('html', $html);
186
$smarty->assign('all',  $all);
187

zaufi's avatar
zaufi committed
188
// Fill list of rules
189 190 191 192
$rules = $integrator->list_rules($repID);
$smarty->assign_by_ref('rules', $rules);
$smarty->assign('repID', $repID);

zaufi's avatar
zaufi committed
193
// Fill list of possible source repositories
194
$allreps = $integrator->list_repositories(false);
zaufi's avatar
zaufi committed
195 196 197 198
$reps = array();
foreach($allreps as $rep) $reps[$rep["repID"]] = $rep["name"];
$smarty->assign_by_ref('reps', $reps);

199 200 201
// disallow robots to index page:
$smarty->assign('metatag_robots', 'NOINDEX, NOFOLLOW');

202 203
// Display the template
$smarty->assign('mid','tiki-admin_integrator_rules.tpl');
204
$smarty->display("tiki.tpl");