-
Notifications
You must be signed in to change notification settings - Fork 39
/
watchtable.php
138 lines (118 loc) · 4.58 KB
/
watchtable.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<?php
// Purpose handling for the navigation elements on the watchtable-panel
// Author Lutz Brueckner <[email protected]>
// Copyright (c) 2000, 2001, 2002, 2003, 2004, 2005 by Lutz Brueckner,
// published under the terms of the GNU General Public Licence v.2,
// see file LICENCE for details
// do not overwrite $s_referer in script_start.inc.php
$no_session_referer = true;
require './inc/script_start.inc.php';
require './inc/array_functions.inc.php';
if ($s_connected) {
$dbhandle = db_connect()
or fb_error();
}
// handle the paging navigation
if (isset($_GET['go'])) {
switch ($_GET['go']) {
case 'start' :
$s_wt['start'] = 1;
break;
case 'prev' :
$s_wt['start'] -= $s_wt['rows'];
break;
case 'next' :
$s_wt['start'] += $s_wt['rows'];
break;
default :
$s_wt['start'] = $_GET['go'];
}
}
// ordering by the column headlines
elseif (isset($_GET['order'])) {
if ($s_wt['order'] == $_GET['order']) {
$s_wt['direction'] = ($s_wt['direction'] == 'ASC') ? 'DESC' : 'ASC';
} else {
$s_wt['order'] = $_GET['order'];
$s_wt['direction'] = 'ASC';
}
$s_wt['start'] = 1;
}
// editing of a dataset is requested
elseif (isset($_GET['edit'])) {
$s_edit_idx = ($s_edit_idx > 0) ? get_max_key($s_edit_where) + 1 : 1;
$target_panels = get_panel_array($s_referer);
$pname = 'dt_edit'.$s_edit_idx;
$instance = ($s_edit_idx > 1) ? "($s_edit_idx) " : '';
$ptitle = sprintf($dt_strings['EditFrom'], $instance, $s_wt['table']);
${$target_panels}[] = array($pname, $ptitle, 'open');
$pos = get_panel_index($$target_panels, $pname);
$$target_panels = array_moveto_top($$target_panels, $pos);
$s_edit_where[$s_edit_idx] = array('where' => get_request_data('edit', 'GET'),
'table' => $s_wt['table'], );
$s_fields = get_table_computed_sources($s_wt['table'], $s_fields);
$s_edit_values[$s_edit_idx] = init_edit_values($s_edit_where[$s_edit_idx], $s_fields[$s_wt['table']]);
}
// deleting of a dataset is requested
elseif (isset($_GET['del'])) {
$where = get_request_data('del', 'GET');
$quote = identifier_quote($s_login['dialect']);
$sql = 'DELETE FROM '.$quote.$s_wt['table'].$quote.' '.$where;
if ($s_cust['askdel'] == true) {
$s_delete_idx = ($s_delete_idx > 0) ? get_max_key($s_confirmations['row']) + 1 : 1;
$target_panels = get_panel_array($s_referer);
$pname = 'dt_delete'.$s_delete_idx;
$ptitle = 'Delete';
$ptitle .= ($s_delete_idx > 1) ? " ($s_delete_idx) " : ' ';
$ptitle .= 'from table '.$s_wt['table'];
${$target_panels}[] = array($pname, $ptitle, 'open');
$pos = get_panel_index($$target_panels, $pname);
$$target_panels = array_moveto_top($$target_panels, $pos);
$s_confirmations['row'][$s_delete_idx] =
array('msg' => sprintf($MESSAGES['CONFIRM_ROW_DELETE'], $s_wt['table'], $where),
'sql' => $sql, );
} else {
fbird_query($dbhandle, $sql)
or $fb_error = fbird_errmsg();
// cleanup the watchtable output buffer
$s_watch_buffer = '';
}
}
// cleanup the watchtable output buffer
if (isset($_GET['go']) || isset($_GET['order'])) {
$s_watch_buffer = '';
$s_cust['wt'][$s_login['database']] = array('table' => $s_wt['table'],
'start' => $s_wt['start'],
'order' => $s_wt['order'],
'dir' => $s_wt['direction'], );
set_customize_cookie($s_cust);
}
globalize_session_vars();
if (!empty($dbhandle)) {
fbird_close($dbhandle);
}
header('Location: '.url_session($s_referer));
exit;
//
// return the initial field values when editing a dataset
//
function init_edit_values($edit_where, $fields)
{
$values = array();
$quote = identifier_quote($GLOBALS['s_login']['dialect']);
$sql = 'SELECT * FROM '.$quote.$edit_where['table'].$quote.' '.$edit_where['where'];
$res = fbird_query($GLOBALS['dbhandle'], $sql) or fb_error();
if ($row = fbird_fetch_assoc($res, IBASE_TEXT)) {
fbird_free_result($res);
foreach ($fields as $field) {
if (isset($field['comp'])) {
$values[] = $field['csource'];
} else {
$values[] = $row[$field['name']];
}
}
} else {
$GLOBALS['fb_error'] = "Query didn't return a result: ".$sql;
}
return $values;
}