/
defdep-up.php
executable file
·197 lines (173 loc) · 5.28 KB
/
defdep-up.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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
<?
#This program is copyright by Andre Coetzee email: ac@main.me
#and is licensed under the GPL v3
#
#
#
#
#Please add yourself to: http://www.accounting-123.com
#Developers, Software Vendors, Support, Accountants, Users
#
#
#The full software license can be found here:
#http://www.accounting-123.com/a.php?a=153/GPLv3
#
#
#
#
#
#
#
#
#
#
#
##
# compinfo-view.php :: View & edit company info
##
# get settings
require ("settings.php");
if (isset ($_POST["key"])) {
switch ($_POST["key"]) {
case "confirm":
$OUTPUT = confirm ($_POST);
break;
case "write":
$OUTPUT = write ($_POST);
break;
default:
if(isset($_GET['file'])){
$OUTPUT =confirm2($_GET['file']);
}else{
$OUTPUT = show ();
}
}
} else {
if(isset($_GET['file'])){
$OUTPUT =confirm2($_GET['file']);
}else{
$OUTPUT = show ();
}
}
# display output
require ("template.php");
# print Info from db
function show ()
{
# start table, etc
$show =
"<h3>Upload accounts file</h3>
<table cellpadding='".TMPL_tblCellPadding."' cellspacing='".TMPL_tblCellSpacing."'>
<form ENCTYPE='multipart/form-data' action='".SELF."' method=post>
<input type=hidden name=key value=confirm>
<tr><th>Field</th><th>Value</th></tr>
<tr class='bg-even'><td>Accounts File</td><td><input type=file size=20 name=accfile></td></tr>
<tr><td colspan=2 align=right><input type=submit value='Confirm »'></td></tr>
</form>
</table>";
return $show;
}
function confirm ($_POST)
{
# get $_FILES global var for uploaded files
global $_FILES;
# get vars
foreach ($_POST as $key => $value) {
$$key = $value;
}
# deal with logo image
if (empty ($_FILES["accfile"])) {
return "<li class=err> Please select a file to upload from your hard drive.";
}
if (is_uploaded_file ($_FILES["accfile"]["tmp_name"])) {
// open the file
$file = file($_FILES["accfile"]["tmp_name"]);
// Layout
$analyze = "<center><h3>File analysis</h3>
<form action='".SELF."' method=post name=form>
<input type=hidden name=key value=write>
<table border=0 cellpadding='".TMPL_tblCellPadding."' cellspacing='".TMPL_tblCellSpacing."' width=300>
<tr class='bg-even'><td>Department name</td><td><input type=text name=depname value='unknown' size=30></td></tr>
<tr><th>Account number</th><th>Account name</th></tr>";
foreach($file as $key => $value){
$info = explode(",", $value);
if(count($info) < 3){
$analyze .= "<tr class='bg-even'><td colspan=2 align=center>$info[0]</td></tr>";
}else{
foreach($info as $key2 => $infos){
$info[$key2] = str_replace("\"", "", $info[$key2]);
}
$analyze .= "<tr class='bg-odd'><td><input type=hidden name=accnum[] value='$info[1]'>$info[1]</td><td><input type=hidden name=accname[] value='$info[2]'>$info[2]</td></tr>";
}
}
$analyze .= "<tr><td><br></td></tr>
<tr><td><input type=button value='« Cancel' onClick='javascript:history.back();'></td><td align=right><input type=submit value='Confirm »'></td></tr>
</table></form>";
}
return $analyze;
}
function confirm2($filename)
{
$filename = "../".$filename;
# check if folder exist
if(!file_exists ($filename)){
return "<li> File does not exist.";
}
# check if folder is a folder
if(is_dir($filename)){
return "<li>SElected file is a directory.";
}
$file = file($filename);
// Layout
$analyze = "<center><h3>File analysis</h3>
<table border=0 cellpadding='".TMPL_tblCellPadding."' cellspacing='".TMPL_tblCellSpacing."' width=300>
<tr><th>Account number</th><th>Account name</th></tr>";
foreach($file as $key => $value){
$info = explode(",", $value);
if(count($info) < 3){
$analyze .= "<tr class='bg-even'><td colspan=2 align=center>$info[0]</td></tr>";
}else{
foreach($info as $key2 => $infos){
$info[$key2] = str_replace("\"", "", $info[$key2]);
}
$analyze .= "<tr class='bg-odd'><td>$info[1]</td><td>$info[2]</td></tr>";
}
}
$analyze .= "</table>";
return $analyze;
}
function write ($_POST)
{
# get vars
foreach ($_POST as $key => $value) {
$$key = $value;
}
# validate input
require_lib("validate");
$v = new validate ();
$v->isOk ($depname, "string", 1, 255, "Invalid department name.");
// default department
core_connect();
$sql = "INSERT INTO defdep(depname) VALUES('$depname')";
$Rs = db_exec($sql) or die("Unable to add DefDept");
# get next ordnum
$depid = pglib_lastid ("defdep", "depid");
foreach($accnum as $key => $value){
list($topacc, $accnum) = explode("/", $value);
$sql = "INSERT INTO defacc(depid, topacc, accnum, accname) VALUES('$depid', '$topacc', '$accnum', '$accname[$key]')";
$Rs = db_exec($sql) or die("Unable to add Defacc's");
}
# display errors, if any
if ($v->isError ()) {
$confirm = "";
$errors = $v->getErrors();
foreach ($errors as $e) {
$confirm .= "<li class=err>".$e["msg"];
}
$confirmCust .= "<p><input type=button onClick='JavaScript:history.back();' value='« Correct submission'>";
return $confirm;
}
$write = "<li> Inserted";
return $write;
}
?>