forked from kapooo/Electronics-Components-Inventory
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
246 lines (211 loc) · 6.18 KB
/
functions.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
<?php
/**
* Electronics Components Inventory - ECI
*
* Functions file
*
* NOTICE OF LICENSE
*
* This source file is subject to the Creative Commons
* Attribution-NonCommercial-ShareAlike 4.0 International License (CC BY-NC-SA 4.0)
* that is bundled with this package in the file LICENSE.
* It is also available through the world-wide-web at this URL:
* http://creativecommons.org/licenses/by-nc-sa/4.0/
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
*
* @copyright Copyright (c) 2015 Alessio Carpini (http://www.electronicsinv.com)
* @license http://creativecommons.org/licenses/by-nc-sa/4.0/ (CC BY-NC-SA 4.0)
*
*/
// Return subCategory array passing the Category ID
function sendSubCategory($idCategory)
{
// Include DB configuration
require 'config.ini.php';
$mysqli = mysqli_connect($server, $username, $password, $database) or die("Error:" . mysqli_error($link));
$query="select idSottoCategoriaProdotti, NomeSottoCategoria from SottoCategorieProdotti where CategorieProdotti_idCategorieProdotti = ".$idCategory." ";
$result=mysqli_query($mysqli, $query) or die("500 Internal Error");
// Array with the values (idSubCategory,NomeSottoCategoria)
$i=0;
$array = array();
while($i < $result->num_rows)
{
$row=$result->fetch_assoc();
$array[$row['idSottoCategoriaProdotti']] = $row['NomeSottoCategoria'];
$i++;
}
mysqli_close($mysqli);
return $array;
}
// Return Product Category array passing the subCategory ID
function sendProductCategory($idSubCategory)
{
require 'config.ini.php';
$mysqli = mysqli_connect($server, $username, $password, $database) or die("Error:" . mysqli_error($link));
// Query SQL
$query = "SELECT DISTINCT TipologiaProdotti.idTipologiaProdotti, TipologiaProdotti.TipologiaProdotto FROM SottoCategorieProdotti, TipologiaProdotti WHERE SottoCategorieProdotti.idSottoCategoriaProdotti = TipologiaProdotti.SottoCategorieProdotti_idSottoCategoriaProdotti AND SottoCategorieProdotti.idSottoCategoriaProdotti = ".$idSubCategory." ";
$result=mysqli_query($mysqli, $query) or die("500 Internal Error");
// Array with the values (idProductCategory, NameProductCategory)
$i=0;
$array = array();
while($i < $result->num_rows)
{
$row=$result->fetch_assoc();
$array[$row['idTipologiaProdotti']] = $row['TipologiaProdotto'];
$i++;
}
mysqli_close($mysqli);
return $array;
}
/* Check if Manufacturer Part No is present in DB
* Return:
* - true: if present
* - false: if absent
*/
function isManufacturerPartNoInDb($ManufacturerPartNo)
{
// Include DB configuration
require 'config.ini.php';
$mysqli = mysqli_connect($server, $username, $password, $database) or die("Error:" . mysqli_error($link));
$query="select COUNT(*) from Prodotti where ManufacturerPartNo ='" . $ManufacturerPartNo . "'";
$result=mysqli_query($mysqli, $query) or die("500 Internal Error");
$row=$result->fetch_assoc();
if($row['COUNT(*)'] != 0) // Manu Part No Already in DB
{
return true;
}
else
{
return false;
}
}
/* Check if Vendor Part No is present in DB
* Return:
* - true: if present
* - false: if absent
*/
function isVendorPartNoInDb($VendorPartNo)
{
require 'config.ini.php';
$mysqli = mysqli_connect($server, $username, $password, $database) or die("Error:" . mysqli_error($link));
$query="select COUNT(*) from Prodotti where VendorPartNo ='" . $VendorPartNo . "'";
$result=mysqli_query($mysqli, $query) or die("500 Internal Error");
$row=$result->fetch_assoc();
if($row['COUNT(*)'] != 0) // Manu Part No Already in DB
{
return true;
}
else
{
return false;
}
}
/* Check if ECI is installed or die
*
*
*
*/
function check_eci_db()
{
require 'config.ini.php';
if(empty($server) OR empty($username) OR empty($password) OR empty($database))
{
echo "Please EDIT config.ini.php in main directory";
exit();
}
else
{
$link = @mysqli_connect($server, $username, $password, $database);
// Can't connect to MySQL server
if (mysqli_connect_errno())
{
$error = mysqli_connect_errno();
switch ($error) {
case 2002:
echo "Can't connect to Database Server ".$server."<br>Check file config.ini.php";
break;
case 2003:
echo "Can't connect to Database Server ".$server."<br>Check file config.ini.php";
break;
case 1045:
echo "Username or Password NOT valid for Database ".$database." on ".$server."<br>Check file config.ini.php";
break;
case 1049:
echo "Database <b>".$database."</b> NOT exists! <br>Check file config.ini.php";
break;
default:
echo "Database Error: ".$error;
}
exit();
}
else
{
if (!mysqli_query($link, "SELECT version FROM Options"))
{
echo "Seems to be the FIRST time you use ECI.<br>Database ".$database." EXISTS<br><br>If you want to install ECI click here: <a href=\"install.php\"><b></b>INSTALL</a>";
mysqli_close($link);
exit();
}
}
}
}
/* Check if install.php file is present in directory
* Return true if it is present, false otherwise
*
*/
function check_install_file()
{
// Check if install.php is present in directory
if(file_exists ('install.php') )
{
return true;
}
else
{
return false;
}
}
function get_header()
{
require_once('pages/header.php');
}
function get_footer()
{
require_once('pages/footer.php');
}
function get_version()
{
require 'config.ini.php';
$mysqli = mysqli_connect($server, $username, $password, $database) or die("Error:" . mysqli_error($link));
$query = "SELECT version FROM Options";
$result = mysqli_query($mysqli, $query) or die("500 Internal Error");
$version=$result->fetch_assoc();
echo $version['version'];
}
function get_language($lang)
{
switch ($lang) {
case 'en':
$lang_file = 'languages/lang.en.php';
break;
case 'it':
$lang_file = 'languages/lang.it.php';
break;
case 'de':
$lang_file = 'languages/lang.de.php';
break;
case 'fr':
$lang_file = 'languages/lang.fr.php';
break;
case 'es':
$lang_file = 'languages/lang.es.php';
break;
default:
$lang_file = 'languages/lang.en.php';
}
return $lang_file;
}
?>