1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* List rules on a table OR view
|
5
|
*
|
6
|
* $Id: rules.php,v 1.25 2005/10/18 03:45:16 chriskl Exp $
|
7
|
*/
|
8
|
|
9
|
// Include application functions
|
10
|
include_once('./libraries/lib.inc.php');
|
11
|
|
12
|
$action = (isset($_REQUEST['action'])) ? $_REQUEST['action'] : '';
|
13
|
$PHP_SELF = $_SERVER['PHP_SELF'];
|
14
|
|
15
|
/**
|
16
|
* Confirm and then actually create a rule
|
17
|
*/
|
18
|
function createRule($confirm, $msg = '') {
|
19
|
global $PHP_SELF, $data, $data, $misc;
|
20
|
global $lang;
|
21
|
|
22
|
if (!isset($_POST['name'])) $_POST['name'] = '';
|
23
|
if (!isset($_POST['event'])) $_POST['event'] = '';
|
24
|
if (!isset($_POST['where'])) $_POST['where'] = '';
|
25
|
if (!isset($_POST['type'])) $_POST['type'] = 'SOMETHING';
|
26
|
if (!isset($_POST['raction'])) $_POST['raction'] = '';
|
27
|
|
28
|
if ($confirm) {
|
29
|
$misc->printTrail($_REQUEST['subject']);
|
30
|
$misc->printTitle($lang['strcreaterule'],'pg.rule.create');
|
31
|
$misc->printMsg($msg);
|
32
|
|
33
|
echo "<form action=\"$PHP_SELF\" method=\"post\">\n";
|
34
|
echo "<table>\n";
|
35
|
echo "<tr><th class=\"data left required\">{$lang['strname']}</th>\n";
|
36
|
echo "<td class=\"data1\"><input name=\"name\" size=\"16\" maxlength=\"{$data->_maxNameLen}\" value=\"",
|
37
|
htmlspecialchars($_POST['name']), "\" /></td></tr>\n";
|
38
|
echo "<tr><th class=\"data left required\">{$lang['strevent']}</th>\n";
|
39
|
echo "<td class=\"data1\"><select name=\"event\">\n";
|
40
|
foreach ($data->rule_events as $v) {
|
41
|
echo "<option value=\"{$v}\"", ($v == $_POST['event']) ? ' selected="selected"' : '',
|
42
|
">{$v}</option>\n";
|
43
|
}
|
44
|
echo "</select></td></tr>\n";
|
45
|
echo "<tr><th class=\"data left\">{$lang['strwhere']}</th>\n";
|
46
|
echo "<td class=\"data1\"><input name=\"where\" size=\"32\" value=\"",
|
47
|
htmlspecialchars($_POST['where']), "\" /></td></tr>\n";
|
48
|
echo "<tr><th class=\"data left\">{$lang['strinstead']}</th>\n";
|
49
|
echo "<td class=\"data1\">";
|
50
|
echo "<input type=\"checkbox\" name=\"instead\" ", (isset($_POST['instead'])) ? ' checked="checked"' : '', " />\n";
|
51
|
echo "</td></tr>\n";
|
52
|
echo "<tr><th class=\"data left required\">{$lang['straction']}</th>\n";
|
53
|
echo "<td class=\"data1\">";
|
54
|
echo "<input type=\"radio\" name=\"type\" value=\"NOTHING\"", ($_POST['type'] == 'NOTHING') ? ' checked="checked"' : '', " /> NOTHING<br />\n";
|
55
|
echo "<input type=\"radio\" name=\"type\" value=\"SOMETHING\"", ($_POST['type'] == 'SOMETHING') ? ' checked="checked"' : '', " />\n";
|
56
|
echo "(<input name=\"raction\" size=\"32\" value=\"",
|
57
|
htmlspecialchars($_POST['raction']), "\" />)</td></tr>\n";
|
58
|
echo "</table>\n";
|
59
|
|
60
|
echo "<input type=\"hidden\" name=\"action\" value=\"save_create_rule\" />\n";
|
61
|
echo "<input type=\"hidden\" name=\"subject\" value=\"", htmlspecialchars($_REQUEST['subject']), "\" />\n";
|
62
|
echo "<input type=\"hidden\" name=\"", htmlspecialchars($_REQUEST['subject']),
|
63
|
"\" value=\"", htmlspecialchars($_REQUEST[$_REQUEST['subject']]), "\" />\n";
|
64
|
echo $misc->form;
|
65
|
echo "<p><input type=\"submit\" name=\"ok\" value=\"{$lang['strcreate']}\" />\n";
|
66
|
echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n";
|
67
|
echo "</form>\n";
|
68
|
|
69
|
}
|
70
|
else {
|
71
|
if (trim($_POST['name']) == '')
|
72
|
createRule(true, $lang['strruleneedsname']);
|
73
|
else {
|
74
|
$status = $data->createRule($_POST['name'],
|
75
|
$_POST['event'], $_POST[$_POST['subject']], $_POST['where'],
|
76
|
isset($_POST['instead']), $_POST['type'], $_POST['raction']);
|
77
|
if ($status == 0)
|
78
|
doDefault($lang['strrulecreated']);
|
79
|
else
|
80
|
createRule(true, $lang['strrulecreatedbad']);
|
81
|
}
|
82
|
}
|
83
|
}
|
84
|
|
85
|
/**
|
86
|
* Show confirmation of drop and perform actual drop
|
87
|
*/
|
88
|
function doDrop($confirm) {
|
89
|
global $data, $misc;
|
90
|
global $PHP_SELF, $lang;
|
91
|
|
92
|
if ($confirm) {
|
93
|
$misc->printTrail($_REQUEST['subject']);
|
94
|
$misc->printTitle($lang['strdrop'],'pg.rule.drop');
|
95
|
|
96
|
echo "<p>", sprintf($lang['strconfdroprule'], $misc->printVal($_REQUEST['rule']),
|
97
|
$misc->printVal($_REQUEST[$_REQUEST['reltype']])), "</p>\n";
|
98
|
|
99
|
echo "<form action=\"$PHP_SELF\" method=\"post\">\n";
|
100
|
echo "<input type=\"hidden\" name=\"action\" value=\"drop\" />\n";
|
101
|
echo "<input type=\"hidden\" name=\"subject\" value=\"", htmlspecialchars($_REQUEST['reltype']), "\" />\n";
|
102
|
echo "<input type=\"hidden\" name=\"", htmlspecialchars($_REQUEST['reltype']),
|
103
|
"\" value=\"", htmlspecialchars($_REQUEST[$_REQUEST['reltype']]), "\" />\n";
|
104
|
echo "<input type=\"hidden\" name=\"rule\" value=\"", htmlspecialchars($_REQUEST['rule']), "\" />\n";
|
105
|
echo $misc->form;
|
106
|
// Show cascade drop option if supportd
|
107
|
if ($data->hasDropBehavior()) {
|
108
|
echo "<p><input type=\"checkbox\" name=\"cascade\" /> {$lang['strcascade']}</p>\n";
|
109
|
}
|
110
|
echo "<input type=\"submit\" name=\"yes\" value=\"{$lang['stryes']}\" />\n";
|
111
|
echo "<input type=\"submit\" name=\"no\" value=\"{$lang['strno']}\" />\n";
|
112
|
echo "</form>\n";
|
113
|
}
|
114
|
else {
|
115
|
$status = $data->dropRule($_POST['rule'], $_POST[$_POST['subject']], isset($_POST['cascade']));
|
116
|
if ($status == 0)
|
117
|
doDefault($lang['strruledropped']);
|
118
|
else
|
119
|
doDefault($lang['strruledroppedbad']);
|
120
|
}
|
121
|
|
122
|
}
|
123
|
|
124
|
/**
|
125
|
* List all the rules on the table
|
126
|
*/
|
127
|
function doDefault($msg = '') {
|
128
|
global $data, $misc;
|
129
|
global $PHP_SELF;
|
130
|
global $lang;
|
131
|
|
132
|
$misc->printTrail($_REQUEST['subject']);
|
133
|
$misc->printTabs($_REQUEST['subject'], 'rules');
|
134
|
$misc->printMsg($msg);
|
135
|
|
136
|
$rules = $data->getRules($_REQUEST[$_REQUEST['subject']]);
|
137
|
|
138
|
$columns = array(
|
139
|
'rule' => array(
|
140
|
'title' => $lang['strname'],
|
141
|
'field' => 'rulename',
|
142
|
),
|
143
|
'definition' => array(
|
144
|
'title' => $lang['strdefinition'],
|
145
|
'field' => 'definition',
|
146
|
),
|
147
|
'actions' => array(
|
148
|
'title' => $lang['stractions'],
|
149
|
),
|
150
|
);
|
151
|
|
152
|
$subject = urlencode($_REQUEST['subject']);
|
153
|
$object = urlencode($_REQUEST[$_REQUEST['subject']]);
|
154
|
|
155
|
$actions = array(
|
156
|
'drop' => array(
|
157
|
'title' => $lang['strdrop'],
|
158
|
'url' => "{$PHP_SELF}?action=confirm_drop&{$misc->href}&reltype={$subject}&{$subject}={$object}&subject=rule&",
|
159
|
'vars' => array('rule' => 'rulename'),
|
160
|
),
|
161
|
);
|
162
|
|
163
|
$misc->printTable($rules, $columns, $actions, $lang['strnorules']);
|
164
|
|
165
|
echo "<p><a class=\"navlink\" href=\"{$PHP_SELF}?action=create_rule&{$misc->href}&{$subject}={$object}&subject={$subject}\">{$lang['strcreaterule']}</a></p>\n";
|
166
|
}
|
167
|
|
168
|
// Different header if we're view rules or table rules
|
169
|
$misc->printHeader($_REQUEST[$_REQUEST['subject']] . ' - ' . $lang['strrules']);
|
170
|
$misc->printBody();
|
171
|
|
172
|
switch ($action) {
|
173
|
case 'create_rule':
|
174
|
createRule(true);
|
175
|
break;
|
176
|
case 'save_create_rule':
|
177
|
if (isset($_POST['cancel'])) doDefault();
|
178
|
else createRule(false);
|
179
|
break;
|
180
|
case 'drop':
|
181
|
if (isset($_POST['yes'])) doDrop(false);
|
182
|
else doDefault();
|
183
|
break;
|
184
|
case 'confirm_drop':
|
185
|
doDrop(true);
|
186
|
break;
|
187
|
default:
|
188
|
doDefault();
|
189
|
break;
|
190
|
}
|
191
|
|
192
|
$misc->printFooter();
|
193
|
|
194
|
?>
|