-
Notifications
You must be signed in to change notification settings - Fork 1
/
orderViewer.php
180 lines (160 loc) · 5.53 KB
/
orderViewer.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
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
<?php
include_once "check.php";
include_once "./template/functions.php";
include_once "./template/config.php";
include_once "globals.php";
if (!isAdmin()) { exit; }
$tableExists = existsOrdersTable();
?>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<html>
<head>
<title>Order Viewer</title>
<?php
$self = $_SERVER['PHP_SELF'];
$orderName = getEscGet('orderName');
$deleteOrder = getEscGet('deleteOrder');
$unreadOrder = getEscGet('unreadOrder');
$fname = null;
if (!empty($unreadOrder) || !empty($deleteOrder)) {
$dir = './orders';
$fname = $dir.'/'.$orderName;
}
if (!empty($fname)) {
if (!empty($unreadOrder)) {
if ($tableExists) { execSQL("UPDATE orders SET fresh = 1 WHERE strFilename = '".$fname."';", false); }
unset( $orderName, $unreadOrder );
} else if (!empty($deleteOrder)) {
if (isFile($fname)) { unlink($fname); }
if ($tableExists) { execSQL("DELETE FROM orders WHERE strFilename = '".$fname."';", false); }
unset( $orderName, $deleteOrder );
}
}
?>
<link rel="stylesheet" type="text/css" href="class.css" />
<?php if (empty($orderName)) { ?>
<script type="text/javascript" src="./template/js/jquery.min.js"></script>
<script type="text/javascript">
function cursorBusy() {
$('body').css('cursor', 'wait');
$('td').css('cursor', 'wait');
}
function readOrder(orderName) {
if (orderName == null || orderName == '') { return; }
cursorBusy();
window.location.href='<?php echo $self; ?>?orderName=' + orderName;
}
function unReadOrder(orderName) {
if (orderName == null || orderName == '') { return; }
cursorBusy();
window.location.href='<?php echo $self; ?>?unreadOrder=1&orderName=' + orderName;
}
function dletOrder(orderName) {
if (orderName == null || orderName == '') { return; }
var frage = unescape("Delete order '" + orderName + "'?");
var answer = confirm(frage);
if (!answer) { return; }
cursorBusy();
window.location.href='<?php echo $self; ?>?deleteOrder=1&orderName=' + orderName;
}
</script>
<?php } else { ?>
<script type="text/javascript">
function selectText(obj) {
if (document.selection) {
var range = document.body.createTextRange();
range.moveToElementText(obj);
range.select();
} else if (window.getSelection) {
var range = document.createRange();
range.selectNode(obj);
window.getSelection().addRange(range);
}
}
</script>
<?php } ?>
</head>
<body style='padding:10px 0px; margin:0px;'>
<?php if (empty($orderName)) { ?>
<table id="orders" class="film" style="width:95%; padding:0px; z-index:1;">
<tr><th class="righto">#</th><th style="padding-left:10px !important;">User</th><th class="righto">Date</th><th></th><th></th></tr>
<?php readOrders(); ?>
</table>
<?php } ?>
<?php if (!empty($orderName)) {
$tableExists = $GLOBALS['tableExists'];
echo "\r\n<b>".$orderName."</b>\r\n";
$dir = './orders';
$fname = $dir.'/'.$orderName;
$size = filesize($fname);
if ($size > 0) {
$file = fopen($fname, 'r');
$content = fread($file, $size);
fclose($file);
echo "<hr style='background:#69C; border:0px; height:2px; width:300%;' />\r\n";
echo "<pre onclick='selectText(this);'>\r\n";
if ($size > 0) { echo encodeString($content); }
echo "</pre>\r\n";
}
if ($tableExists) { execSQL("UPDATE orders SET fresh = 0 WHERE strFilename = '".$fname."';", false); }
} ?>
</body>
</html>
<?php
/* FUNCTIONS */
function readOrders() {
$tableExists = $GLOBALS['tableExists'];
$freshs = array();
if ($tableExists) {
$res = querySQL("SELECT strFilename, fresh FROM orders ORDER BY strFilename;");
foreach($res as $row) {
$fname = $row['strFilename'];
$fresh = $row['fresh'];
$freshs[$fname] = $fresh;
}
}
$ver = array();
$dir = './orders';
$d = dir($dir);
while (false !== ($entry = $d->read())) {
$entry = trim($entry);
if (empty($entry) || $entry == '.' || $entry == '..') { continue; }
$ver[] = $entry;
}
$d->close();
unset($d);
arsort($ver); //rsort($ver);
$counter = 0;
foreach($ver as $entry) {
$fname = $dir.'/'.$entry;
$fresh = isset($freshs[$fname]) ? $freshs[$fname] : 0;
if (!isFile($fname)) { continue; }
$size = filesize($fname);
if ($size > 0) {
postOrder($counter+1, $entry, $fname, $fresh);
$counter++;
}
}
if (empty($counter)) {
echo "\t\t\t".'<tr>';
echo '<td colspan="5">No orders found!</td>';
echo '</tr>';
echo "\r\n";
}
}
function postOrder($c, $name, $fname, $fresh) {
$elem = explode('_', $name);
$date = strtotime($elem[0]);
$date = date('d.m.Y H:i', filectime($fname));
$user = str_replace('.order', '', $elem[1]);
$style = $fresh ? ' font-weight:bold;' : '';
echo "\t\t\t".'<tr'.$style.'>';
echo '<td onclick="readOrder(\''.$name.'\'); return false;" style="cursor:pointer;'.$style.'" class="righto">'.$c.'</td>';
echo '<td onclick="readOrder(\''.$name.'\'); return false;" style="cursor:pointer;'.$style.' padding-left:10px !important;">'.$user.'</td>';
echo '<td onclick="readOrder(\''.$name.'\'); return false;" style="cursor:pointer;'.$style.'" class="righto">'.$date.'</td>';
echo '<td onclick="unReadOrder(\''.$name.'\'); return false;" style="cursor:pointer;'.$style.' max-width:35px;" class="righto"><img src="./img/apply.png" style="height:16px; width:16px;" title="set unread"></td>';
echo '<td onclick="dletOrder(\''.$name.'\'); return false;" style="cursor:pointer;'.$style.' max-width:35px;" class="righto"><img src="./img/del.png" style="height:16px; width:16px;" title="delete"></td>';
echo '</tr>';
echo "\r\n";
}
?>