-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpurchase_controller-Back.php
executable file
·237 lines (211 loc) · 6.5 KB
/
purchase_controller-Back.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
<?php
error_reporting(0);
//ini_set('display_errors', 1);
include_once 'include/global.inc.php';
require_once 'classes/signature-to-image.php';
//check to see that the form has been submitted
if($_SERVER['REQUEST_METHOD'] == 'POST') {
//retrieve the $_POST variables
$shop_id = $_REQUEST['txtshop'];
//$invoice = trim($_REQUEST['txtinvoice']);
$make = trim($_REQUEST['txtmake']);
$model = trim($_REQUEST['txtmodel']);
$imei = trim($_REQUEST['txtimei']);
$customername = trim($_REQUEST['txtcsname']);
$password = trim($_REQUEST['txtcpwd']);
$contact = trim($_REQUEST['txtcsno']);
$defects = trim($_REQUEST['txtdefects']);
$address = trim($_REQUEST['txtcaddress']);
$network = trim($_REQUEST['txtnetwork']);
$price = trim($_REQUEST['txtprice']);
$signature = trim($_REQUEST['txtcsig']);
$enteredby = trim($_REQUEST['txtrecby']);
$created_by = trim($_REQUEST['txtcreatedby']);
$shopname = $_REQUEST['txtshopname'];
$access = $_REQUEST['txtaccess'];
$checks = $_REQUEST['txtchecks'];
$other = $_REQUEST['txtother'];
$status = 'instock';
$dt = new DateTime("now", new DateTimeZone('Europe/London'));
$edate = $dt->format('Y-m-d H:i:s');
$shemail = "";
$invoice = $db->updateInvoiceNo('purchase');
// Converting Signatures to Image
if (!empty($signature)) {
//$img = sigJsonToImage($signature);
$img = sigJsonToImage($signature, array('imageSize'=>array(340, 105)));
$sigdate = new DateTime();
$sigtime = $sigdate->getTimestamp();
$csigname = preg_replace('/\s+/', '', $sigtime);
$signame = $csigname . "_S.png";
imagepng($img, "documents/".$signame);
}
$fname = $_FILES['txtfile']['name'];
//http://codular.com/php-file-uploads
if ((isset($fname)) && (!empty($fname))) {
//$name = $_FILES['txtfile']['name'];
$now = new DateTime();
$name = $now->getTimestamp();
$ext = pathinfo($fname, PATHINFO_EXTENSION);
//$ext = 'png';
$uname = preg_replace('/\s+/', '', $name);
$filename = $uname . "_I.png";
$path = "documents/".$filename;
$tmpFilename = $_FILES['txtfile']['tmp_name'] ;
imagepng(imagecreatefromstring(file_get_contents($tmpFilename)), $path, 9);
/*
if(!getimagesize($_FILES['txtfile']['tmp_name'])){
echo "Please ensure you are uploading an image!";
exit();
}
// Check filetype
//if($_FILES['txtfile']['type'] != 'IMAGE/image/PNG/png/JPG/jpg/JPEG/jpeg/GIF/gif/ICO/ico'){
//echo "Unsupported filetype uploaded!";
//exit();
//}
if(file_exists('documents/' . $filename)){
unlink($path);
if (move_uploaded_file($_FILES['txtfile']['tmp_name'], $path) === false){
echo "Error uploading image!";
exit();
}
} else {
if (move_uploaded_file($_FILES['txtfile']['tmp_name'], $path) === false){
echo "Error uploading image!";
exit();
}
}
*/
}
else {
$filename = $_REQUEST['userdbimage'];
}
//saving data to db
$data = array(
"shop_id" => "'$shop_id'",
"date_entered" => "'$edate'",
"invoice" => "'$invoice'",
"make" => "'$make'",
"model" => "'$model'",
"imei" => "'$imei'",
"customer_name" => "'$customername'",
"password" => "'$password'",
"contact_number" => "'$contact'",
"defects" => "'$defects'",
"address" => "'$address'",
"network" => "'$network'",
"price" => "'$price'",
"identification" => "'$filename'",
"signature" => "'$signature'",
"signimage" => "'$signame'",
"entered_by" => "'$enteredby'",
"status" => "'$status'",
"created_by" => "'$created_by'",
"created_at" => "'".date("Y-m-d H:i:s",time())."'"
);
//saving data to db
$id = $db->insert($data, 'purchase');
//Inserting phone accessories info to Misc table
if (isset($access)) {
$arrayacc = explode(',', $access);
foreach($arrayacc as $tag_name){
//modify below to add $id along with $tag_name
$accessval = $tag_name;
$accesstype = 'accessories';
$accessdata = array(
"itemid" => "'$id'",
"value" => "'$accessval'",
"type" => "'$accesstype'",
);
$ids = $db->insert($accessdata, 'misc');
}
}
//Inserting phone checklist info to Misc table
if (isset($checks)) {
$arraychk = explode(',', $checks);
foreach($arraychk as $checks_name){
//modify below to add $id along with $tag_name
$checksval = $checks_name;
$checkstype = 'check';
$checksdata = array(
"itemid" => "'$id'",
"value" => "'$checksval'",
"type" => "'$checkstype'",
);
$idc = $db->insert($checksdata, 'misc');
}
}
if (isset($other)) {
$othdata = array(
"itemid" => "'$id'",
"value" => "'$other'",
"type" => "'other'",
);
$ido = $db->insert($othdata, 'misc');
}
//For sending email to SuperAdmin
$sub = "New Phone $make-$model is purchased by $shopname";
$mess = "Dear Sir,\n Please see below specs of the phone purchased by $shopname on $edate.\n";
$mess = $mess."Customer Informaton: Customer Name : $customername; Contact: $contact, Address: $address.\n";
$mess = $mess."Phone Specifications: Make : $make; Model: $model IMEI: $imei.\n";
$mess = $mess."Network : $network; Defects: $defects Price: £ $price.\n";
$from = "From: fone-worlduk.com" . "\r\n";
//$to = "[email protected]";
$to = "[email protected]";
if (isset($to)) {
/*
//sendMail($to,$sub,$mess,$uname);
if (mail ($to, $sub, $mess, $from)) {
echo 1;
} else {
echo 0;
}
*/
require_once('classes/class.phpmailer.php');
include("classes/class.smtp.php");
$mail = new PHPMailer();
$mail->IsSMTP();
//$mail->Host = "relay-hosting.secureserver.net"; //"smtpout.secureserver.net"; // //"smtp.aol.com";
//$mail->SMTPSecure = 'tls';
//For Local
/*
$mail->SMTPDebug = 0;
$mail->SMTPAuth = true;
$mail->Host = "smtp.aol.com";
$mail->Port = 587;
*/
//For Production
$mail->SMTPDebug = 0;
$mail->SMTPAuth = false;
$mail->Host = "relay-hosting.secureserver.net";
//$mail->Port = 25;
$mail->Username = "[email protected]";
$mail->Password = "b7948456305m";
$from = "[email protected]";
//$mail->From = TO_EMAIL_ADDRESS;
//$mail->From = FROM_NAME;
$mail->SetFrom($from, 'fone-worlduk');
if (!empty($shemail)) {
$mail->AddReplyTo($shemail);
} else {
$mail->AddReplyTo("[email protected]");
}
//$address = $email;
$mail->AddAddress($to);
$mail->Subject = $sub;
$mail->Body = $mess;
/*
if(!$mail->Send()) {
echo 0;
} else {
echo 1;
}
*/
$mail->Send();
}
if (!empty($id))
echo $id;
else
echo 0;
}
?>