/
triggers.php
108 lines (88 loc) · 3.26 KB
/
triggers.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
/**
* List triggers on a table
*
* $Id: triggers.php,v 1.2 2003/02/07 17:34:35 xzilla Exp $
*/
// Include application functions
include_once('libraries/lib.inc.php');
$action = (isset($_REQUEST['action'])) ? $_REQUEST['action'] : '';
$PHP_SELF = $_SERVER['PHP_SELF'];
/**
* Show confirmation of drop and perform actual drop
*/
function doDrop($confirm) {
global $localData, $misc;
global $PHP_SELF, $strDrop, $strConfDropTrigger, $strTriggerDropped, $strTriggerDroppedBad, $strYes, $strNo;
if ($confirm) {
echo "<h2>", htmlspecialchars($_REQUEST['database']), ": Tables: ",
htmlspecialchars($_REQUEST['table']), ": " , htmlspecialchars($_REQUEST['trigger']), ": {$strDrop}</h2>\n";
echo "<p>", sprintf($strConfDropTrigger, htmlspecialchars($_REQUEST['trigger']),
htmlspecialchars($_REQUEST['table'])), "</p>\n";
echo "<form action=\"$PHP_SELF\" method=\"post\">\n";
echo "<input type=\"hidden\" name=\"action\" value=\"drop\">\n";
echo "<input type=\"hidden\" name=\"table\" value=\"", htmlspecialchars($_REQUEST['table']), "\">\n";
echo "<input type=\"hidden\" name=\"trigger\" value=\"", htmlspecialchars($_REQUEST['trigger']), "\">\n";
echo $misc->form;
echo "<input type=\"submit\" name=\"choice\" value=\"{$strYes}\"> <input type=\"submit\" name=\"choice\" value=\"{$strNo}\">\n";
echo "</form>\n";
}
else {
$status = $localData->dropTrigger($_POST['trigger'], $_POST['table']);
if ($status == 0)
doDefault($strTriggerDropped);
else
doDefault($strTriggerDroppedBad);
}
}
/**
* List all the triggers on the table
*/
function doDefault($msg = '') {
global $data, $localData, $misc;
global $PHP_SELF;
global $strTriggers, $strName, $strActions, $strNoTriggers, $strCreateTrigger, $strDrop;
$misc->printTableNav();
echo "<h2>", htmlspecialchars($_REQUEST['database']), ": ", htmlspecialchars($_REQUEST['table']), ": {$strTriggers}</h2>\n";
$misc->printMsg($msg);
$triggers = &$localData->getTriggers($_REQUEST['table']);
if ($triggers->recordCount() > 0) {
echo "<table>\n";
echo "<tr><th class=\"data\">{$strName}</th><th class=\"data\">{$strActions}</th>\n";
$i = 0;
while (!$triggers->EOF) {
$id = ( ($i % 2 ) == 0 ? '1' : '2' );
echo "<tr><td class=\"data{$id}\">", htmlspecialchars( $triggers->f[$data->tgFields['tgname']]), "</td>";
echo "<td class=\"data{$id}\">";
echo "<a href=\"$PHP_SELF?action=confirm_drop&{$misc->href}&trigger=", htmlspecialchars( $triggers->f[$data->tgFields['tgname']]),
"&table=", htmlspecialchars($_REQUEST['table']), "\">{$strDrop}</td></tr>\n";
$triggers->moveNext();
$i++;
}
echo "</table>\n";
}
else
echo "<p>{$strNoTriggers}</p>\n";
//echo "<p><a class=\"navlink\" href=\"$PHP_SELF?action=create&{$misc->href}&table=", htmlspecialchars($_REQUEST['table']), "\">{$strCreateTrigger}</a></p>\n";
}
$misc->printHeader($strTables . ' - ' . $_REQUEST['table'] . ' - ' . $strTriggers);
switch ($action) {
case 'save_create':
doSaveCreate();
break;
case 'create':
doCreate();
break;
case 'drop':
if ($_POST['choice'] == $strYes) doDrop(false);
else doDefault();
break;
case 'confirm_drop':
doDrop(true);
break;
default:
doDefault();
break;
}
$misc->printFooter();
?>