-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
executable file
·423 lines (319 loc) · 13.2 KB
/
index.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
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
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
<?php require_once('config.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form2")) {
$insertSQL = sprintf("INSERT INTO invoices (`date`, `set`, `number`, supplier_id, customer_id) VALUES (%s, %s, %s, %s, %s)",
GetSQLValueString($_POST['date'], "text"),
GetSQLValueString($_POST['set'], "text"),
GetSQLValueString($_POST['number'], "text"),
GetSQLValueString($_POST['supplier_id'], "int"),
GetSQLValueString($_POST['customer_id'], "int"));
$Result1 = mysql_query($insertSQL, $db) or die(mysql_error());
$insertGoTo = "index.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
if ((isset($_GET['invoice_id'])) && ($_GET['invoice_id'] != "")) {
$deleteSQL = sprintf("DELETE FROM invoices WHERE invoice_id=%s",
GetSQLValueString($_GET['invoice_id'], "int"));
$Result1 = mysql_query($deleteSQL, $db) or die(mysql_error());
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form4")) {
//print_r($_POST);
for ($i=1; $i<=$_POST['software_menu_counter'];$i++) {
$insertSQL = sprintf("INSERT INTO licenses (invoice_id, software_id) VALUES (%s, %s)",
@GetSQLValueString($_POST['invoice_id'], "int"),
@GetSQLValueString($_POST['software_id_'.$i], "int"));
//echo "<br />";
//
if (isset($_POST['license_count_'.$i]) && ($_POST['license_count_'.$i]>0))
do {
//echo $_POST['license_count_'.$i]."<br />";
$Result1 = mysql_query($insertSQL, $db) or die(mysql_error());
$_POST['license_count_'.$i]--;
} while ($_POST['license_count_'.$i] > 0) ;
}
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form3")) {
$insertSQL = sprintf("INSERT INTO party (party_id, name, type) VALUES (%s, %s, %s)",
GetSQLValueString($_POST['party_id'], "int"),
GetSQLValueString($_POST['name'], "text"),
GetSQLValueString($_POST['type'], "int"));
$Result1 = mysql_query($insertSQL, $db) or die(mysql_error());
}
$maxRows_Recordset1 = 10;
$pageNum_Recordset1 = 0;
if (isset($_GET['pageNum_Recordset1'])) {
$pageNum_Recordset1 = $_GET['pageNum_Recordset1'];
}
$startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1;
$query_Recordset1 = "SELECT * FROM invoices ORDER BY invoice_id ASC";
$query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1);
$Recordset1 = mysql_query($query_limit_Recordset1, $db) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
if (isset($_GET['totalRows_Recordset1'])) {
$totalRows_Recordset1 = $_GET['totalRows_Recordset1'];
} else {
$all_Recordset1 = mysql_query($query_Recordset1);
$totalRows_Recordset1 = mysql_num_rows($all_Recordset1);
}
$totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1;
$query_party_suppliers = "SELECT name, party_id FROM party WHERE type=2 order by name asc";
$party_suppliers = mysql_query($query_party_suppliers, $db) or die(mysql_error());
$row_party_suppliers = mysql_fetch_assoc($party_suppliers);
$totalRows_party_suppliers = mysql_num_rows($party_suppliers);
$query_party_customers = "SELECT name, party_id FROM party WHERE type=1";
$party_customers = mysql_query($query_party_customers, $db) or die(mysql_error());
$row_party_customers = mysql_fetch_assoc($party_customers);
$totalRows_party_customers = mysql_num_rows($party_customers);
$query_party_type = "SELECT * FROM party_type";
$party_type = mysql_query($query_party_type, $db) or die(mysql_error());
$row_party_type = mysql_fetch_assoc($party_type);
$totalRows_party_type = mysql_num_rows($party_type);
$query_invoices = "SELECT * FROM invoices order by `set`, `number`";
$invoices = mysql_query($query_invoices, $db) or die(mysql_error());
$row_invoices = mysql_fetch_assoc($invoices);
$totalRows_invoices = mysql_num_rows($invoices);
$query_licenses = "SELECT l.license_id, s.name as sname, lt.name as ltype, i.number, i.set, i.date from licenses l
left join software s on l.software_id=s.software_id
left join license_type lt on s.license_type=lt.license_type_id
join invoices i where i.invoice_id=l.invoice_id
";
$licenses = mysql_query($query_licenses, $db) or die(mysql_error());
$totalRows_licenses = mysql_num_rows($licenses);
$sql = "SELECT i.invoice_id, i.date, i.set, i.number, cus.name as customer, sup.name as supplier from invoices i
left join party cus on i.customer_id=cus.party_id
left join party sup on i.supplier_id=sup.party_id";
$result_invoices_all = mysql_query($sql, $db) or die(mysql_error());
function software_menu() {
global $db;
$query_software = "SELECT s.software_id, s.name as software_name, t.name as license_type FROM software s left join license_type t on s.license_type=t.license_type_id order by software_name ASC";
$software = mysql_query($query_software, $db) or die(mysql_error());
$row_software = mysql_fetch_assoc($software);
$totalRows_software = mysql_num_rows($software);
$html = "<select name='software_id_'>";
do {
$html.="<option value='".$row_software['software_id']."' >".$row_software['software_name']." - ".$row_software['license_type']."</option>";
} while ($row_software = mysql_fetch_assoc($software));
$html.=" </select>";
return $html;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript">
<!--
var counter = 0;
function init() {
document.getElementById('moreFields').onclick = moreFields;
moreFields();
}
function moreFields() {
counter++;
software_menu_counter=document.getElementById('software_menu_counter');
software_menu_counter.value=counter;
var newFields = document.getElementById('readroot').cloneNode(true);
newFields.id = '';
newFields.style.display = 'block';
var newField = newFields.childNodes;
for (var i=0;i<newField.length;i++) {
var theName = newField[i].name
if (theName)
newField[i].name = theName + counter;
}
var insertHere = document.getElementById('writeroot');
insertHere.parentNode.insertBefore(newFields,insertHere);
}
// -->
</script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>LIC - Invoices</title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body onload="init()">
<? include("menu.php");?>
<form action="<?php echo $editFormAction; ?>" method="post" name="form2" id="form2">
<table align="center">
<tr valign="baseline">
<td nowrap="nowrap" align="right">Date:</td>
<td><input type="text" name="date" value="" size="32" class="datepicker" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Set:</td>
<td><input type="text" name="set" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Number:</td>
<td><input type="text" name="number" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Supplier_id:</td>
<td><select name="supplier_id">
<option value="0">-- Izvēlieties --- </option>
<?php
do {
?>
<option value="<?php echo $row_party_suppliers['party_id']?>" ><?php echo $row_party_suppliers['name']?></option>
<?php
} while ($row_party_suppliers = mysql_fetch_assoc($party_suppliers));
?>
</select>
</td>
</tr>
<tr> </tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Customer_id:</td>
<td><select name="customer_id">
<?php
$query_party_customers = "SELECT name, party_id FROM party WHERE type=1";
$party_customers = mysql_query($query_party_customers, $db) or die(mysql_error());
$row_party_customers = mysql_fetch_assoc($party_customers);
$totalRows_party_customers = mysql_num_rows($party_customers);
do {
?>
<option value="<?php echo $row_party_customers['party_id']?>" ><?php echo $row_party_customers['name']?></option>
<?php
} while ($row_party_customers = mysql_fetch_assoc($party_customers));
?>
</select>
</td>
</tr>
<tr> </tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right"> </td>
<td><input type="submit" value="Insert record" /></td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="form2" />
</form>
<div id="readroot" style="display: none"> <?=software_menu();?> <input id="license_count_" type="text" name="license_count_" value="1" />
<input type="button" value=" - " onclick="this.parentNode.parentNode.removeChild(this.parentNode);" />
</div>
<form method="post" style="background-color: #CCC; padding:10px; width: 900px;">
<strong>Forma, ar kuru pievienot programmatūru kādai no pavadzīmēm</strong><br />
<select name="invoice_id">
<?php
do {
?>
<option value="<?php echo $row_invoices['invoice_id']?>" ><?=$row_invoices['set']." ".$row_invoices['number'];?></option>
<?php
} while ($row_invoices = mysql_fetch_assoc($invoices));
?>
</select>
<span id="writeroot"></span>
<input type="button" id="moreFields" value=" + " /> <br /><input type="submit" value="Add licenses" />
<input type="hidden" name="software_menu_counter" id="software_menu_counter" value=0 />
<input type="hidden" name="MM_insert" value="form4" />
</form>
<p>Pavadzīmju saraksts:</p>
<table border="0" bgcolor="#CCCCCC" cellspacing="1" cellpadding="1">
<? while ($row=mysql_fetch_assoc($result_invoices_all)) {;
if (@$th==0) {
echo "<tr>";
foreach($row as $key => $val ) { echo "<td bgcolor=\"#FFFFFF\"> $key </td>\n\r"; }
echo"<td>action</td></tr>";
}
$th=1;
echo "<tr>" ;
foreach($row as $val) { echo "<td bgcolor=\"#FFFFFF\"> $val; </td> "; }
echo "<td bgcolor=\"#FFFFFF\">
<a href='invoice.php?id=".$row['invoice_id']."'>Open</a>
<a href='invoices_edit.php?invoice_id=".$row['invoice_id']."'>Edit</a>
".'<a href="invoice_action.php?delete&invoice_id='.$row['invoice_id'].'" onclick="javascript:return confirm(\'Vai tiešām vēlies dzēst?\')">Delete</a></td> </tr>'; }
?>
</table>
FORMas laukus pievienot
<form action="<?php echo $editFormAction; ?>" method="post" name="form3" id="form3">
<table align="center">
<tr valign="baseline">
<td nowrap="nowrap" align="right">Party_id:</td>
<td><input type="text" name="party_id" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Name:</td>
<td><input type="text" name="name" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Type:</td>
<td><select name="type">
<?php
do {
?>
<option value="<?php echo $row_party_type['party_type_id']?>" ><?php echo $row_party_type['name']?></option>
<?php
} while ($row_party_type = mysql_fetch_assoc($party_type));
?>
</select>
</td>
</tr>
<tr> </tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right"> </td>
<td><input type="submit" value="Insert record" /></td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="form3" />
</form>
<p> </p>
<table border="0" cellpadding="1" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td>name</td>
<td>party_id</td>
</tr>
<?php do { ?>
<tr>
<td bgcolor="#FFFFFF"><?php echo $row_party_suppliers['name']; ?></td>
<td bgcolor="#FFFFFF"><?php echo $row_party_suppliers['party_id']; ?></td>
</tr>
<?php } while ($row_party_suppliers = mysql_fetch_assoc($party_suppliers)); ?>
</table>
<br />
<table border="1">
<? while ($row44=mysql_fetch_assoc($licenses)) {;
echo "<tr>" ; foreach($row44 as $key => $val) { echo "<td> $val; </td> "; }
echo "</tr>"; }
?>
</table>
</body>
</html>
<?php
mysql_free_result($Recordset1);
mysql_free_result($party_suppliers);
mysql_free_result($party_customers);
mysql_free_result($party_type);
mysql_free_result($invoices);
@mysql_free_result($software);
?>