-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdbshow.inc.php
More file actions
301 lines (251 loc) · 8.85 KB
/
dbshow.inc.php
File metadata and controls
301 lines (251 loc) · 8.85 KB
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
<? if (!defined('IN_ENGINE')) {die('forbidden');}
include('functions_showitem.php');
function fmtcheckbox($outfmt,$iid) {
global $askc_del1;
$ou='';
switch ($outfmt) {
case 'webpage':
$ou.='<tr>'.'<td>';
break;
case 'webpage_list':
$ou.='<td>';
break;
}
$ou.='<input type="checkbox" name="'.'selitem[]'.'" value="'.$iid.'" />';
# $ou.=' '.'ID'.':'.$iid;
$ou.=' '.'<a href="'.'dbshowitem.php?action=edit&id='.$iid.'">'.'ID'.':'.$iid.'</a>';
if (auth_user('DEL1')) {
$ou.=' '.'<a href="'.'dbshow.php?action=edit&del='.$iid.'"';
if ($askc_del1) {$ou.=' onclick="javascript:return confirm(\''.'Are you sure?'.'\');" ';}
$ou.='>'.'Del'.'</a>';
}
if (auth_user('EDIT')) {
$ou.=' '.'<a href="'.'dbadd.php?action=edit&id='.$iid.'">'.'Edit'.'</a>';
}
if ($starr && auth_user('STAR1')) {
$ou.=' '.'<a href="'.'dbshow.php?action=edit&fav='.$iid.'">'.'Fav'.'</a>';
}
switch ($outfmt) {
case 'webpage':
$ou.='</td>'.'</tr>';
break;
case 'webpage_list':
$ou.='</td>';
break;
}
return $ou;
}
function shwctrlbuttons() {
global $mobi,$starr;
# include('functions_js_checkbox.inc.php');
echo
<script language="JavaScript" type="text/javascript">
<!--
drawSelItmButtons();
// if (window.innerWidth<400) {document.writeln("<br />");}
// -->
</script>
';
if (auth_user('DELM')) {
echo '<input type="submit" name="cdel" value="';
if ($mobi) {echo 'Del';} else {echo 'Delete';}
echo '" /> ';
}
if ($starr && auth_user('STARM')) {
echo '<input type="submit" name="cstar" value="'.'Fav+'.'" /> ';
echo '<input type="submit" name="cunstar" value="'.'Fav-'.'" /> ';
}
}
# $action=strtolower(trim($_REQUEST['action'])); # Action (View, Edit) # Commented out because it's defined before to include this file
$outfmt=strtolower(trim($_REQUEST['out'])); # Output format (webpage, webpage_list, raw, txt, html, xml, json, csv)
$outwhr=strtolower(trim($_REQUEST['put'])); # Where to put the output (browser, dload)
if (!$action) {$action='view';} # Set default action
if (($action=='view' && $functen['view']!=1) || ($action=='edit' && $functen['edit']!=1) || ($action=='export' && $functen['export']!=1)) {fdisabled(); die();}
if ($action=='export' && !auth_user('EXPORT')) {authdenied(); die();}
if ($action=='export' || $outfmt=='raw') {$reslim=false;} else {$reslim=$reslimdef;}
if (!$outfmt) {
if ($action=='edit') {
$outfmt='webpage_list';
} else {
$outfmt='webpage';
}
} # Set default output format
if ($outwhr!='dload' || $outfmt=='webpage' || $action=='edit') {$outwhr='browser';} # Set default for Where to put the output / Download not allowed for webpage format and edit
if ($action=='export' && $outfmt!='txt' && $outfmt!='html' && $outfmt!='xml' && $outfmt!='json') {$outfmt='csv';} # Set allowed formats and default format to export data
if ($action=='export' && $outwhr!='browser') {$outwhr='dload';} # Set default destination to export data
if ($outfmt=='raw') {$outfmt='txt';} # You may want to use "raw" for testing purposes only. Set this line as a comment to prevent raw output of the table in the database, or comment it out to allow it
if (!$pag) {$pag=$_GET['pag'];}
if (!$pag || $pag<1) {$pag=1;}
if (!$itmppag) {$itmppag=$_GET['itmppag'];}
if (!preg_match("/^[0-9]+$/i",$itmppag)) {$itmppag=$itmppagdef;} # Prevents MySQL injection
if (!$itmppag || $itmppag<1 || $itmppag>=$itmppagdef) {$itmppag=$itmppagdef;}
# $itmppag=3; # Force items per page
$_frm=$pag*$itmppag-$itmppag;
# $pagurl=$edge_main_url.'dbshow.php';
$pagurl=$_REQUEST['PHP_SELF'];
# Deletion
$del=checkint($_GET['del']);
if ($del) {
if (auth_user('DEL1')) {
$qdb="DELETE FROM `".$db_table1_name."` WHERE `id`=".$del.";";
$dbo=dbx_query($dbx,$dbxcon,$qdb,$db_name);
# echo 'Entry deleted';
} else {authdenied();}
}
# Star/Unstar
if ($starr) {
$fav=checkint($_GET['fav']);
if ($fav) {
if (auth_user('STAR1')) {
$qdb="SELECT `starr` FROM `".$db_table1_name."` WHERE `id`=".$fav.";";
# echo "<br />".'*** 1: ['.$qdb.']'."<br />";
$dbo=dbx_query($dbx,$dbxcon,$qdb,$db_name);
$row=dbx_fetch_array($dbx,$dbo);
if ($row['starr']==0) {$xinv=1;} else {$xinv=0;}
$qdb="UPDATE `".$db_table1_name."` SET `starr`=".$xinv." WHERE `id`=".$fav.";";
$dbo=dbx_query($dbx,$dbxcon,$qdb,$db_name);
# echo 'Entry starred';
} else {authdenied();}
}
}
$selitem=$_REQUEST['selitem'];
if ($selitem && (auth_user('DELM') || ($starr && auth_user('STARM')))) {
for ($icnt=0; $icnt<count($selitem); $icnt++) {
$selitem[$icnt]=floor($selitem[$icnt]);
# Mass Deletion
if (auth_user('DELM') && $_POST['cdel']!='') {
$qdb="DELETE FROM `".$db_table1_name."` WHERE id=".$selitem[$icnt].";";
$dbo=dbx_query($dbx,$dbxcon,$qdb,$db_name);
# echo 'Mass deletion performed';
}
if ($starr && auth_user('STARM')) {
# Mass Star
if ($_POST['cstar']!='') {
$qdb="UPDATE `".$db_table1_name."` SET `starr`=".'1'." WHERE `id`=".$selitem[$icnt].";";
$dbo=dbx_query($dbx,$dbxcon,$qdb,$db_name);
# echo 'Mass deletion performed';
}
# Mass Unstar
if ($_POST['cunstar']!='') {
$qdb="UPDATE `".$db_table1_name."` SET `starr`=".'0'." WHERE `id`=".$selitem[$icnt].";";
$dbo=dbx_query($dbx,$dbxcon,$qdb,$db_name);
# echo 'Mass deletion performed';
}
}
}
}
if ($outwhr=='browser' && ($outfmt=='webpage' || $outfmt=='webpage_list')) {
include('dbsearch_form.inc.php'); echo "<br />\n";
}
# Set default file name and extension
switch ($outfmt) {
default:
case 'txt':
case 'raw':
$fout='data.txt';
break;
case 'html':
$fout='data.html';
break;
case 'csv':
$fout='data.csv';
break;
case 'xml':
$fout='data.xml';
break;
case 'json':
$fout='data.json';
break;
}
# Allowed fields (as set in the configuration file)
$usrfld='id,';
reset($dbdat);
while ($l_1=each($dbdat)) {
list ($l_1a,$l_1b) = str_getcsv($l_1['value'],'|');
if ($l_1b>'0' && substr($l_1['key'],0,2)!='xx') {$usrfld.=$l_1['key'].',';}
}
$usrfld.='dat';
$qusrch='';
include('getdatasearch_1_form.inc.php');
$qusrt='';
if ($q && strlen($q)<$srchqminlen && ($outfmt=='webpage' || $outfmt=='webpage_list')) {echo 'You need to provide at least '.$srchqminlen.' characters to search into the database'."<br /><br />\n";}
if ($outfmt!='raw') {
$qdbs1=$usrfld;
} else {
$qdbs1='*';
}
if ($starr) {
if ($starrbl==1) {
$qusrt.=' ORDER BY `starr` DESC';
if ($defsrt) {$qusrt.=', '.$defsrt;}
} elseif ($starrbl==2) {
$qusrt.=' ORDER BY `starr` ASC';
if ($defsrt) {$qusrt.=', '.$defsrt;}
}
} else {
if ($defsrt) {$qusrt.=' ORDER BY '.$defsrt;}
}
$qcnt='SELECT COUNT(*) AS c'." FROM `".$db_table1_name."`".$qusrch;
$qdb='SELECT '.$qdbs1." FROM `".$db_table1_name."`".$qusrch;
$qdb.=$qusrt;
if ($reslim) {$qdb.=" LIMIT ".$_frm.",".$itmppag;}
$qdb.=';';
# echo "<br />".'['.$qdb.']'."<br />";
$dbo=dbx_query($dbx,$dbxcon,$qdb,$db_name);
# $dbn=dbx_num_rows($dbx,$dbo);
if ($dbo) {
$fwhandle='';
if ($outwhr=='dload') {
include('savehdr.inc.php'); // Ask user where to save the file
// if (!$fwhandle=fopen($fout,'w')) {echo "Can't open file for output."; die();} // Save a file locally
} else {
# echo "<br />".'['.$qcnt.']'."<br />";
$qnum=dbx_query($dbx,$dbxcon,$qcnt,$db_name);
$qnrn=dbx_fetch_array($dbx,$qnum); $qnr=$qnrn['c'];
# echo "<br />".'['.$qnr.']'."<br />";
if ($outwhr=='browser' && $outfmt!='webpage' && $outfmt!='webpage_list') {
echo '<code><xmp>';
}
if ($outwhr=='browser' && ($outfmt=='webpage' || $outfmt=='webpage_list')) {
if ($qnr!=1) {$wxsp='entries';} else {$wxsp='entry';}; echo $qnr.' '.$wxsp.' '.'found'."<br />";
# if ($dbn!=1) {$wxsp='entries';} else {$wxsp='entry';}; echo $dbn.' '.$wxsp.' '.'listed'."<br />";
echo "<br />\n";
}
if ($reslim) {
prpagnum($pag,$itmppag,$qnr,$pagurl,'?out='.$outfmt.'&put='.$outwhr.'&itmppag='.$itmppag.'&');
echo "<br /><br />";
}
}
$showeft=$showef; # Show/Hide empty field as requested in the configuration. If an output format doesn't allow it, you can override it here
if ($action=='edit') {$useminimitems=true;} else {$useminimitems=false;}
if ($action=='edit') {$shwctrls=true;} else {$shwctrls=false;}
if ($shwctrls && auth_user('DELM,STARM','|')) {
include('functions_js_checkbox.inc.php');
echo '<form name="console" id="console" action="'.$_REQUEST['PHP_SELF'].'" method="post">';
shwctrlbuttons();
}
include('dbshow_header.inc.php');
$cp=0;
while ($dbey=dbx_fetch_array($dbx,$dbo)) {
$cp++;
include('dbshow_body.inc.php');
}
include('dbshow_footer.inc.php');
if ($shwctrls && auth_user('DELM,STARM','|')) {
shwctrlbuttons();
echo '</form>';
}
if ($outwhr=='dload') {
// fclose($fwhandle);
} else {
if ($outwhr=='browser' && $outfmt!='webpage' && $outfmt!='webpage_list') {
echo '</xmp></code>';
}
if ($reslim) {
echo "<br /><br />";
prpagnum($pag,$itmppag,$qnr,$pagurl,'?out='.$outfmt.'&put='.$outwhr.'&itmppag='.$itmppag.'&');
}
}
}
if ($action=='edit' && $functen['remove']==1 && auth_user('DELA')) {echo "<br /><br />".'<a href="dbremove.php">Remove all entries from the database</a>';}
?>