1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
//------------------------------------------------------------------------------ |
4
|
|
|
// |
5
|
|
|
// eTraxis - Records tracking web-based system |
6
|
|
|
// Copyright (C) 2005-2010 Artem Rodygin |
7
|
|
|
// |
8
|
|
|
// This program is free software: you can redistribute it and/or modify |
9
|
|
|
// it under the terms of the GNU General Public License as published by |
10
|
|
|
// the Free Software Foundation, either version 3 of the License, or |
11
|
|
|
// (at your option) any later version. |
12
|
|
|
// |
13
|
|
|
// This program is distributed in the hope that it will be useful, |
14
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
15
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16
|
|
|
// GNU General Public License for more details. |
17
|
|
|
// |
18
|
|
|
// You should have received a copy of the GNU General Public License |
19
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>. |
20
|
|
|
// |
21
|
|
|
//------------------------------------------------------------------------------ |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @package eTraxis |
25
|
|
|
* @ignore |
26
|
|
|
*/ |
27
|
|
|
|
28
|
|
|
/**#@+ |
29
|
|
|
* Dependency. |
30
|
|
|
*/ |
31
|
|
|
require_once('../engine/engine.php'); |
32
|
|
|
require_once('../dbo/accounts.php'); |
33
|
|
|
/**#@-*/ |
34
|
|
|
|
35
|
|
|
global $encodings; |
36
|
|
|
global $line_endings_names; |
37
|
|
|
global $line_endings_chars; |
38
|
|
|
|
39
|
|
|
init_page(LOAD_TAB); |
40
|
|
|
|
41
|
|
|
$error = NO_ERROR; |
42
|
|
|
|
43
|
|
|
// settings form is submitted |
44
|
|
|
|
45
|
|
|
if (try_request('submitted') == 'csvform') |
46
|
|
|
{ |
47
|
|
|
debug_write_log(DEBUG_NOTICE, 'Data are submitted.'); |
48
|
|
|
|
49
|
|
|
$delimiter = ustrcut($_REQUEST['delimiter'], 1); |
50
|
|
|
$encoding = ustr2int($_REQUEST['encoding'], 1, count($encodings)); |
51
|
|
|
$line_endings = ustr2int($_REQUEST['line_endings'], 1, count($line_endings_names)); |
52
|
|
|
|
53
|
|
|
if (ustrlen($delimiter) == 0 || |
54
|
|
|
ustrpos(CSV_DELIMITERS, $delimiter) === FALSE) |
55
|
|
|
{ |
56
|
|
|
$delimiter = chr(DEFAULT_DELIMITER); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
dal_query('accounts/csv.sql', |
60
|
|
|
$_SESSION[VAR_USERID], |
61
|
|
|
ord($delimiter), |
62
|
|
|
$encoding, |
63
|
|
|
$line_endings); |
64
|
|
|
|
65
|
|
|
exit; |
66
|
|
|
} |
67
|
|
|
else |
68
|
|
|
{ |
69
|
|
|
debug_write_log(DEBUG_NOTICE, 'Data are being requested.'); |
70
|
|
|
|
71
|
|
|
$delimiter = $_SESSION[VAR_DELIMITER]; |
72
|
|
|
$encoding = $_SESSION[VAR_ENCODING]; |
73
|
|
|
$line_endings = $_SESSION[VAR_LINE_ENDINGS]; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
// local JS functions |
77
|
|
|
|
78
|
|
|
$resTitle = get_js_resource(RES_SETTINGS_ID); |
79
|
|
|
$resError = get_js_resource(RES_ERROR_ID); |
80
|
|
|
$resMessage1 = get_js_resource(RES_ALERT_SUCCESSFULLY_SAVED_ID); |
81
|
|
|
$resMessage2 = get_js_resource(RES_ALERT_UNKNOWN_ERROR_ID); |
82
|
|
|
$resOK = get_js_resource(RES_OK_ID); |
83
|
|
|
|
84
|
|
|
$xml = <<<JQUERY |
85
|
|
|
<script> |
86
|
|
|
|
87
|
|
|
function csvSuccess () |
88
|
|
|
{ |
89
|
|
|
jqAlert("{$resTitle}", "{$resMessage1}", "{$resOK}"); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
function csvError () |
93
|
|
|
{ |
94
|
|
|
jqAlert("{$resError}", "{$resMessage2}", "{$resOK}"); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
</script> |
98
|
|
|
JQUERY; |
99
|
|
|
|
100
|
|
|
// generate contents |
101
|
|
|
|
102
|
|
|
$xml .= '<form name="csvform" action="csv.php" success="csvSuccess" error="csvError">' |
103
|
|
|
. '<group>' |
104
|
|
|
. '<control name="delimiter" required="' . get_html_resource(RES_REQUIRED3_ID) . '">' |
105
|
|
|
. '<label>' . get_html_resource(RES_CSV_DELIMITER_ID) . '</label>' |
106
|
|
|
. '<editbox maxlen="1">' . ustr2html($delimiter) . '</editbox>' |
107
|
|
|
. '</control>' |
108
|
|
|
. '<control name="encoding">' |
109
|
|
|
. '<label>' . get_html_resource(RES_CSV_ENCODING_ID) . '</label>' |
110
|
|
|
. '<combobox>'; |
111
|
|
|
|
112
|
|
|
foreach ($encodings as $i => $item) |
113
|
|
|
{ |
114
|
|
|
$xml .= ($encoding == $item |
115
|
|
|
? '<listitem value="' . $i . '" selected="true">' |
116
|
|
|
: '<listitem value="' . $i . '">') |
117
|
|
|
. ustr2html($item) |
118
|
|
|
. '</listitem>'; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
$xml .= '</combobox>' |
122
|
|
|
. '</control>' |
123
|
|
|
. '<control name="line_endings">' |
124
|
|
|
. '<label>' . get_html_resource(RES_CSV_LINE_ENDINGS_ID) . '</label>' |
125
|
|
|
. '<combobox>'; |
126
|
|
|
|
127
|
|
|
foreach ($line_endings_names as $i => $item) |
128
|
|
|
{ |
129
|
|
|
$xml .= ($line_endings == $line_endings_chars[$i] |
130
|
|
|
? '<listitem value="' . $i . '" selected="true">' |
131
|
|
|
: '<listitem value="' . $i . '">') |
132
|
|
|
. ustr2html($item) |
133
|
|
|
. '</listitem>'; |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
$xml .= '</combobox>' |
137
|
|
|
. '</control>' |
138
|
|
|
. '</group>' |
139
|
|
|
. '<button default="true">' . get_html_resource(RES_SAVE_ID) . '</button>' |
140
|
|
|
. '<note>' . get_html_resource(RES_ALERT_REQUIRED_ARE_EMPTY_ID) . '</note>' |
141
|
|
|
. '</form>'; |
142
|
|
|
|
143
|
|
|
echo(xml2html($xml)); |
144
|
|
|
|
145
|
|
|
?> |
|
|
|
|
146
|
|
|
|
Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.
A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.