-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.php
174 lines (144 loc) · 5.04 KB
/
common.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
error_reporting(E_ALL);
ini_set('display_errors', '1');
date_default_timezone_set('Australia/Melbourne');
// Establish a connection to the database
function db_connect() {
// Local
if (strpos(curPageURL(), "localhost") > 0) {
if (!($db = mysql_connect("localhost", "root", ""))) {
report_error($db, "db_connect()", "mysql_connect()");
exit;
} else {
mysql_select_db("barham_realestate", $db);
return $db;
}
// Remote
} else {
if (!($db = mysql_connect("localhost", "barham_stephen", "1Chaille1"))) {
report_error($db, "db_connect()", "mysql_connect()");
die('Failed to connect to barham database!');
} else {
if (!mysql_select_db("barham_realestate", $db)) {
report_error($db, "db_connect()", "mysql_select_db()");
die('Failed to select barham_realestate database!');
} else {
return $db;
}
}
}
}
// This function gets the URL of the current page
function curPageURL() {
$pageURL = 'http';
if (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on") { $pageURL .= "s"; }
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
return $pageURL;
}
// This function just executes the passed in query
function execute($db, $Q, $location) {
if (!mysql_query($Q, $db)) {
report_error($db, $location." (common.execute.1)".$Q, $Q);
return(0);
} else {
return(1);
}
}
function rexecute($db, $Q, $location) {
if (!($res = mysql_query($Q, $db))) {
report_error($db, $location." (common.rexecute.1): ".$Q, $Q);
return(0);
} else if (mysql_num_rows($res) == 0) {
return(0);
} else if (mysql_num_rows($res) == 1) {
$row = mysql_fetch_row($res);
return($row[0]);
} else if (mysql_num_rows($res) > 1) {
report_error($db, $location." (common.rexecute.2)".$Q, $Q);
}
}
function arexecute($db, $Q, $location) {
$array = array();
if (!($res = mysql_query($Q, $db))) {
report_error($db, $location." (common.arexecute.1): ".$Q, $Q);
} else if (mysql_num_rows($res) > 0) {
while($row = mysql_fetch_row($res)) {
$array[] = $row[0];
}
}
return($array);
}
function aarexecute($db, $Q, $location) {
$array = array();
if (!($res = mysql_query($Q, $db))) {
report_error($db, $location." (common.aarexecute.1): ".$Q, $Q);
} else if (mysql_num_rows($res) > 0) {
while($row = mysql_fetch_array($res, MYSQL_NUM)) {
$array[] = $row;
}
}
return($array);
}
// This function reports an error
function report_error($db, $location, $Query) {
//print("alert('errno: ".mysql_errno($db)." error: ".mysql_error($db)."');");
if (mysql_errno($db) == 1062) {
$str = mysql_error($db);
if (strpos($str, "number") > 0 || strpos($str, "key 2") > 0) {
$estr = "ERROR(".$location."): There is already an entry in the database with that Account Number. Please try again.";
} else if (strpos($str, "phone") > 0 || strpos($str, "key 3") > 0) {
$estr = "ERROR(".$location."): There is already an entry in the database with that Phone Number. Please try again.";
} else if (strpos($str, "fax") > 0 || strpos($str, "key 4") > 0) {
$estr = "ERROR(".$location."): There is already an entry in the database with that Fax Number. Please try again.";
} else if (strpos($str, "del_street") > 0 || strpos($str, "key 5") > 0) {
$estr = "ERROR(".$location."): There is already an entry in the database with that Street & No. Please try again.";
} else if (strpos($str, "make") > 0) {
$estr = "ERROR(".$location."): There is already an entry in the database for Make with the same value. Please try again.";
} else if (strpos($str, "model") > 0) {
$estr = "ERROR(".$location."): There is already an entry in the database for Model with the same value. Please try again.";
} else if (strpos($str, "detail") > 0) {
$estr = "ERROR(".$location."): There is already an entry in the database for Detail with the same value. Please try again.";
} else {
$estr = "ERROR(".$location.") ".mysql_errno($db).": ".mysql_error($db);
}
} else {
$estr = "ERROR(".$location.") ".mysql_errno($db).": ".mysql_error($db);
}
$estr = rem_item($estr, "'");
//if ($Query != "-1") {
// print("alert('".$estr."');
// ");
//}
//print($Query);
// Don't try to email if we're on a local machine
if (strpos(curPageURL(), "localhost") == 0) {
mail("stephenlansell@gmail.com", "Nationwide Auto Parts Error", $estr." QUERY: ".$Query, "Nationwide Auto Parts");
} else {
print($location." ".$Query);
exit;
}
}
function serious_error($db, $location, $text) {
if (strpos(curPageURL(), "nationwideautoparts") != 0) {
$to = GetEnviro($db, 'error_email');
$to2 = GetEnviro($db, 'order_email');
mail($to, $location.$text, "Nationwide Autoparts");
mail($to2, $location.$text, "Nationwide Autoparts");
}
}
// This function removes the passed in character from the passed in string
function rem_item($str, $char) {
$newstr = "";
for ($i = 0; $i < strlen($str); $i++) {
if (($cchar = substr($str, $i, 1)) != $char) {
$newstr .= $cchar;
}
}
return $newstr;
}
?>