-
Notifications
You must be signed in to change notification settings - Fork 0
/
invoice_action.php
executable file
·174 lines (127 loc) · 6.3 KB
/
invoice_action.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
<?php
//print_r($_POST);
require_once('config.php');
$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());
header("Location: devices.php");
}
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")) {
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 ($_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());
header("Location: devices.php");
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "device")) {
if($_POST["invoice_id"]=="cits") {
$sql = sprintf("INSERT INTO invoices (`set`, `number`) VALUES (%s, %s)",
GetSQLValueString($_POST['new_set'], "text"),
GetSQLValueString($_POST['new_number'], "int"));
$result = mysql_query($sql, $db) or die(mysql_error());
//!!! Ja ir noradita jaunas PPR numurs, tad javeic parbaude, vai gadijuma jau tads neeksiste?
$last_invoice_inserted=mysql_insert_id();
$_SESSION['last_invoice_inserted']=$last_invoice_inserted;
}
else $last_invoice_inserted=$_POST['invoice_id'];
$sql = sprintf("INSERT INTO devices (`description`, `hostname`, `owner_id`, `invoice_id`,`id`) VALUES (%s, %s, %s, %s, %s)",
GetSQLValueString($_POST['description'], "text"),
GetSQLValueString($_POST['hostname'], "text"),
GetSQLValueString($_POST['owner_id'], "int"),
$last_invoice_inserted,
GetSQLValueString($_POST['id'], "text"));
$Result1 = mysql_query($sql, $db) or die(mysql_error());
if(isset($_SESSION['last_invoice_inserted']) and ($_SESSION['last_invoice_inserted']>0))
$location="invoices_edit.php";
else
$location="devices.php?device_inserted";
header("Location: ".$location);
}
/////////////////////****************************/////////////////////////////
// devices_edit.php UPDATE forma. (action=update, form=device
if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "device")) {
$sql="UPDATE `devices` SET `description`=".GetSQLValueString($_POST['description'],"text")." ,
`hostname`=".GetSQLValueString($_POST['hostname'], "text").",
`id`=".GetSQLValueString($_POST['id'], "text").",
`owner_id`=".GetSQLValueString($_POST['owner_id'], "int").",
`invoice_id`=".GetSQLValueString($_POST['invoice_id'], "int").
" WHERE `device_id` = ".GetSQLValueString($_POST['device_id'], "text")." LIMIT 1" ;
//echo $sql;
$Result1 = mysql_query($sql, $db) or die(mysql_error());
header("Location: devices_edit.php?device_id=".$_POST['device_id']);
}
/////////////////////****************************/////////////////////////////
// devices_edit.php UPDATE forma. (action=update, form=licenses_update
if ((isset($_POST["MM_device_update"])) && ($_POST["MM_device_update"] == "licenses")) {
//print_r($_POST);
//echo $_POST["license_1"];
$i=1;
if ($_POST['count']>0)
do {
$sql="UPDATE `licenses` SET `device_id`=".GetSQLValueString($_POST['device_id'],"int")." where ";
$sql.=" license_id= ".$_POST["license_".$i]." limit 1;" ;
//echo $sql;
//izpildam tikai tad, ja ir iezimets checkbox.
if ($_POST["license_".$i]>0)
$result = mysql_query($sql, $db) or die(mysql_error());
$i++;
} while ($i<=$_POST['count']) ;
header("Location: devices_edit.php?device_id=".$_POST['device_id']);
}
if ((isset($_POST["form"])) && ($_POST["form"] == "invoice_edit")) {
$sql="UPDATE `invoices` SET
`date`=".GetSQLValueString($_POST['date'],"text").",
`set`=".GetSQLValueString($_POST['set'],"text").",
`number`=".GetSQLValueString($_POST['number'],"int").",
`supplier_id`=".GetSQLValueString($_POST['supplier_id'],"int").",
`customer_id`=".GetSQLValueString($_POST['customer_id'],"int")."
where ";
$sql.=" invoice_id=".GetSQLValueString($_POST['invoice_id'],"int")." limit 1;" ;
//echo $sql;
$result = mysql_query($sql, $db) or die(mysql_error());
if (isset($_SESSION['last_invoice_inserted'])) {
unset($_SESSION['last_invoice_inserted']);
$location="devices.php";
}
else
$location=$_SERVER['HTTP_REFERER'];
//print_r($_SERVER);
header("Location: $location");
}
if (isset($_GET['delete']) && isset($_GET['invoice_id']))
{
$sql="delete from invoices where invoice_id=".intval($_GET['invoice_id'])." limit 1";
$result = mysql_query($sql, $db) or die(mysql_error());
header("Location: ".$_SERVER['HTTP_REFERER']);
}
?>