· 7 years ago · Oct 23, 2018, 08:44 AM
1<?php
2 require_once('./config.php');
3 require_once ('./dbconn.php');
4 require 'PHPExcel/Classes/PHPExcel/IOFactory.php';
5 require_once('Stripe/init.php');
6
7 \Stripe\Stripe::setApiKey("sk_test_4zljnNryTJFJMjYwHPRALTlW");
8
9 try
10{
11 $errText = '';
12
13 $store_name = $_POST["storeName"];
14 $sub = $_GET["sub"];
15 $first_name = $_POST["firstName"];
16 $last_name = $_POST["lastName"];
17 $username = $_POST["username"];
18 $password = $_POST["password"];
19 $phone = $_POST["phone"];
20 $sector = $_POST["store_sector"];
21 $created_date = date('Y-m-d H:i:s');
22 $pass_enc = string_encrypt_long($password);
23
24 $store_name = str_replace("'", "''", $store_name);
25 $first_name = str_replace("'", "''", $first_name);
26 $last_name = str_replace("'", "''", $last_name);
27 $sector = 'retail_food';
28 // Email on Sign-Up
29 $to = 'michael@easycount.io';
30
31 // Subject
32 $subject = 'EasyCount Finalised Sign-Up';
33
34 // Message
35 $message = '
36 <html>
37 <head>
38 <title>EasyCount Finalised Sign-Up</title>
39 </head>
40 <body>
41 <div style="background-color:#000000">
42 <br>
43 <p style="text-align:center; background-color:#000000;"><img src="https://drive.google.com/uc?export=view&id=1FY943SsjxAOfdffdqdbvVbhDN0jnSFOR" alt="Logo" width="280" height="72"></p>
44 <br>
45 </div>
46 <br>
47 <p align="center"><font color="#27abea"><strong>New Finalised Sign-Up!</strong></font></p>
48 <br>
49 <p align="center"><font color="#27abea"><strong>Full Name: </strong></font>'.$first_name.'</p>
50 <br>
51 <p align="center"><font color="#27abea"><strong>Phone: </strong></font>'.$phone.'</p>
52 <br>
53 <p align="center"><font color="#27abea"><strong>Store: </strong></font>'.$store_name.'</p>
54 <br>
55 <p align="center"><font color="27abea"><strong>Email: </strong></font>'.$username.'</p>
56 <br>
57 <p align="center"><font color="27abea"><strong>Date of Creation: </strong></font>'.$created_date.'</p>
58 <br>
59 <p align="center">The above details relate to a fully completed sign-up process. Remember, Trials are set to expire within a month of creation.</p>
60 <footer style = "background-color:#000000;">
61 <br>
62 <p align="center"><i><font color="white">Company: EasyCount.io</font></i></p>
63 <p align="center"><i><font color="white">Contact Email: <a href="mailto:michael@easycount.io">michael@EasyCount.io</a>.</font></i></p>
64 <p align="center"><i><font color="white">Contact Number: (+353) 01 9696509</font></i></p>
65 <p align="center"><i><font color="white">If you would prefer not to receive emails from us in the future, please click <a href="mailto:michael@easycount.io?subject=Email Unsubscribe &body=Please remove me from your mailing list, thank you.">here</a> to unsubscribe.</font></i></p>
66 <p style="text-align:center;">
67 <a href="https://www.facebook.com/easycountio/" style="text-decoration: none;"><img src="https://drive.google.com/uc?export=view&id=1JytSv5lsKpNVikKFCPM7JCw7cKhN4qPC" alt="Facebook" width="48" height="48">
68 <a href="https://twitter.com/Easycount_io" style="text-decoration: none;"><img src="https://drive.google.com/uc?export=view&id=1hYiqoA77N8MCWxPhE1luIRE7a6HruoCG" alt="Twitter" width="48" height="48">
69 <a href="https://www.linkedin.com/company/easycount.io/" style="text-decoration: none;"><img src="https://drive.google.com/uc?export=view&id=1Uo9-ks8YQJYuJqJ0wDSZrpN-54CdsQ_m" alt="LinkedIn" width="48" height="48">
70 <a href="https://www.instagram.com/easycount.io/" style="text-decoration: none;"><img src="https://drive.google.com/uc?export=view&id=1xz6pU7akYPtL2k73B3lfqnzp4uJXLKcX" alt="Instagram" width="48" height="48">
71 <a href="https://www.youtube.com/channel/UC1QVRLNdg0Dy0mwK9t_dSaA" style="text-decoration: none;"><img src="https://drive.google.com/uc?export=view&id=17RbkBWC577ZouMq29jq7vdfgTHyvFfyn" alt="YouTube" width="48" height="48">
72 </p>
73 <br>
74 </footer>
75 </body>
76 </html>
77 ';
78
79 // Send HTML mail
80 $headers[] = 'MIME-Version: 1.0';
81 $headers[] = 'Content-type: text/html; charset=iso-8859-1';
82
83 // Additional headers
84 $headers[] = 'From: EasyCount <info@easycount.io>';
85
86 // Mail
87 mail($to, $subject, $message, implode("\r\n", $headers));
88
89 // Email on Sign-Up Completion
90 $toS = $username;
91
92 // Subject
93 $subjectS = 'EasyCount Welcome';
94
95 // Message
96 $messageS = '
97 <html>
98 <head>
99 <title>Greetings from EasyCount!</title>
100 </head>
101 <body>
102 <div style="padding-top:40px;padding-bottom:30px;padding-right:20px;padding-left:20px;margin:0 auto;margin:0 auto">
103 <div style="background-color:#000000">
104 <br>
105 <p style="text-align:center; background-color:#000000;"><img src="https://drive.google.com/uc?export=view&id=1FY943SsjxAOfdffdqdbvVbhDN0jnSFOR" alt="Logo" width="280" height="72"></p>
106 <br>
107 </div>
108 <p align="center" style="font-size: 20px; word-spacing: 0.8px;"><strong><font color="#27abea">Thank you for signing up to EasyCount!</font></strong></p>
109 <br>
110 <p align="center" style="font-size: 13px; word-spacing: 0.8px;">Just a quick reminder for yourself, your <strong><font color="#27abea">Username</font></strong> is: '.$username.'</p>
111 <p align="center" style="font-size: 13px; word-spacing: 0.8px;">If you ever forget your password, you may reset it on the login screen or by sending an email to michael@easycount.io and I shall assist you where possible.</p>
112 <br>
113 <p align="center" style="font-size: 13px; word-spacing: 0.8px;">To log in to the Web Platform, click the link below: </p>
114 <p align="center" style="font-size: 13px; word-spacing: 0.8px;"><strong><font color="#27abea">Web Platform Login:</font></strong><a href="https://easycount.io/platform/login.php" target="_blank"> Logon</a></p>
115 <br>
116 <p align="center" style="font-size: 13px; word-spacing: 0.8px;">Be sure to download our Mobile App, available on the Google Play Store & the iOS App Store (Apple).</p>
117 <p align="center" style="font-size: 13px; word-spacing: 0.8px;">This is the tool that you will be doing your counts with, which you then sync to the Web Platform you just signed up to!</p>
118 <p align="center" style="font-size: 13px; word-spacing: 0.8px;"><a href="https://play.google.com/store/apps/details?id=io.easycount.app&hl=en" target="_blank"> Google Play Store</a></p>
119 <p align="center" style="font-size: 13px; word-spacing: 0.8px;"><a href="https://itunes.apple.com/gb/app/easycount/id1351279895?mt=8" target="_blank"> iOS App Store </a></p>
120 <br>
121 <p align="center" style="font-size: 16px;">To learn more about our software, make sure you</p>
122 <br>
123 <table align="center">
124 <tr>
125 <td class="thsignup">
126 <i class="fa fa-car"></i><a style="border-radius: 15px; padding: 10px; text-align: center; background-color: #27abea; display: block; color: #ffffff;font-size: 14px;text-decoration: none;" href="https://easycount.io/help-centre/" target="_blank"> Visit our Help Centre </a>
127 <br>
128 <i class="fa fa-car"></i><a style="border-radius: 15px; padding: 10px; text-align: center; background-color: #27abea; display: block; color: #ffffff;font-size: 14px;text-decoration: none;" href="https://easycount.io/contact-us/" target="_blank"> Contact our Team </a>
129 <br>
130 <i class="fa fa-car"></i><a style="border-radius: 15px; padding: 10px; text-align: center; background-color: #27abea; display: block; color: #ffffff;font-size: 14px;text-decoration: none;" href="https://www.facebook.com/easycountio/" target="_blank"> Follow us on Social Media </a>
131 </td>
132 </tr>
133 </table>
134 <br>
135 <p align="center"style="font-size: 13px; word-spacing: 0.8px;"><strong>If you ever need technical help or general support with EasyCount, be sure to contact us through email or by phone.<strong></p>
136 </div>
137 </body>
138 <footer style = "background-color:#000000;">
139 <br>
140 <p align="center"><i><font color="white">Company: EasyCount.io</font></i></p>
141 <p align="center"><i><font color="white">Contact Email: <a href="mailto:michael@easycount.io">michael@EasyCount.io</a>.</font></i></p>
142 <p align="center"><i><font color="white">Contact Number: (+353) 01 9696509</font></i></p>
143 <p align="center"><i><font color="white">If you would prefer not to receive emails from us in the future, please click <a href="mailto:michael@easycount.io?subject=Email Unsubscribe &body=Please remove me from your mailing list, thank you.">here</a> to unsubscribe.</font></i></p>
144 <p style="text-align:center;">
145 <a href="https://www.facebook.com/easycountio/" style="text-decoration: none;"><img src="https://drive.google.com/uc?export=view&id=1JytSv5lsKpNVikKFCPM7JCw7cKhN4qPC" alt="Facebook" width="48" height="48">
146 <a href="https://twitter.com/Easycount_io" style="text-decoration: none;"><img src="https://drive.google.com/uc?export=view&id=1hYiqoA77N8MCWxPhE1luIRE7a6HruoCG" alt="Twitter" width="48" height="48">
147 <a href="https://www.linkedin.com/company/easycount.io/" style="text-decoration: none;"><img src="https://drive.google.com/uc?export=view&id=1Uo9-ks8YQJYuJqJ0wDSZrpN-54CdsQ_m" alt="LinkedIn" width="48" height="48">
148 <a href="https://www.instagram.com/easycount.io/" style="text-decoration: none;"><img src="https://drive.google.com/uc?export=view&id=1xz6pU7akYPtL2k73B3lfqnzp4uJXLKcX" alt="Instagram" width="48" height="48">
149 <a href="https://www.youtube.com/channel/UC1QVRLNdg0Dy0mwK9t_dSaA" style="text-decoration: none;"><img src="https://drive.google.com/uc?export=view&id=17RbkBWC577ZouMq29jq7vdfgTHyvFfyn" alt="YouTube" width="48" height="48">
150 </p>
151 <br>
152 </footer>
153 </html>
154 ';
155
156 // Send HTML mail
157 $headersS[] = 'MIME-Version: 1.0';
158 $headersS[] = 'Content-type: text/html; charset=iso-8859-1';
159
160 // Additional headers
161 $headersS[] = 'From: EasyCount <info@easycount.io>';
162
163 // Mail
164 mail($toS, $subjectS, $messageS, implode("\r\n", $headersS));
165
166/*Validate Email
167$sql_email = "SELECT * FROM user_master WHERE username = '$username'";
168$used = mysqli_query($conn, $sql_email);
169
170if (mysqli_num_rows($used) > 0) {
171
172}*/
173
174 //create store first & get last insert ID
175 $query_stores = "insert into store_master (company_id, store_name, email, customer_id, store_sector) values ('1','$store_name','$username','8', 'retail_food')";
176 $ret = f_insert_query($query_stores, $rows, $last_id);
177 $store_id = $last_id;
178 //create user for this store ID
179 //echo 'Sub is: ' . $sub;
180 //die();
181 if ($sub == 'free')
182 {
183 $query_users = "insert into user_master (first_name, last_name, auth_type, username, password, email_id, phone, status, admin_id, is_app_user, store_id, created_date, is_new, customer_id, is_trial, subscription_end)
184 values ('$first_name','$last_name', 'STORE-FREE', '$username', '$pass_enc','$username', '$phone', 'ACTIVE','34','1','$last_id', '$created_date', '1', '8', '1', NOW()+INTERVAL 21 DAY)";
185 }
186 else if ($sub == 'single')
187 {
188 $query_users = "insert into user_master (first_name, last_name, auth_type, username, password, email_id, phone, status, admin_id, is_app_user, store_id, created_date, is_new, customer_id, is_trial, subscription_end)
189 values ('$first_name','$last_name', 'STORE-SINGLE', '$username', '$pass_enc','$username', '$phone', 'ACTIVE','34','1','$last_id', '$created_date', '1', '8', '1', NOW()+INTERVAL 21 DAY)";
190 }
191 else if ($sub == 'plus')
192 {
193 $query_users = "insert into user_master (first_name, last_name, auth_type, username, password, email_id, phone, status, admin_id, is_app_user, store_id, created_date, is_new, customer_id, is_trial, subscription_end)
194 values ('$first_name','$last_name', 'STORE-USER', '$username', '$pass_enc','$username', '$phone', 'ACTIVE','34','1','$last_id', '$created_date', '1', '8', '1', NOW()+INTERVAL 21 DAY)";
195 }
196 else
197 {
198 $query_users = "insert into user_master (first_name, last_name, auth_type, username, password, email_id, phone, status, admin_id, is_app_user, store_id, created_date, is_new, customer_id, is_trial, subscription_end)
199 values ('$first_name','$last_name', 'STORE-USER', '$username', '$pass_enc','$username', '$phone', 'ACTIVE','34','1','$last_id', '$created_date', '1', '8', '1', NOW()+INTERVAL 21 DAY)";
200 }
201 //echo $query;
202
203
204 $ret = f_insert_query($query_users, $rows, $last_id);
205 $user_id = $last_id;
206
207 //redirect with login verification to page in new tab to upload products
208 if ($rows >= 1)
209 {
210 //upload files
211 if ($sector == 'retail_food')
212 {
213 $uploaddir = 'temp_files/';
214 $uploadfile = $uploaddir . 'deli_sample1.xlsx';
215
216 $exceldata = array();
217
218 PHPExcel_Settings::setZipClass(PHPExcel_Settings::PCLZIP);
219 $exceldata = array();
220 try
221 {
222 $inputfiletype = PHPExcel_IOFactory::identify($uploadfile);
223 $objReader = PHPExcel_IOFactory::createReader($inputfiletype);
224 $objPHPExcel = $objReader->load($uploadfile);
225 }
226
227 catch(Exception $e)
228 {
229 die('Error loading file "'.pathinfo($inputfilename,PATHINFO_BASENAME).'": '.$e->getMessage());
230 }
231
232 // Get worksheet dimensions
233 $sheet = $objPHPExcel->getSheet(0);
234 $highestRow = $sheet->getHighestRow();
235 $highestColumn = $sheet->getHighestColumn();
236
237 // Loop through each row of the worksheet in turn
238 for ($row = 2; $row <= $highestRow; $row++)
239 {
240 conn_start();
241 // Read a row of data into an array
242 $rowData = $sheet->rangeToArray('A' . $row . ':' . $highestColumn . $row, NULL, TRUE, FALSE);
243 $product_name = $sheet->getCell('A'.$row)->getValue();
244 $count_unit = $sheet->getCell('B'.$row)->getValue();
245
246 $product_name = preg_replace('/[^A-Za-z0-9\. -]/', '', $product_name);
247
248 $name = $product_name . ' (' . $count_unit . ')';
249 $department = $sheet->getCell('C'.$row)->getValue();
250 $unit_cost = $sheet->getCell('D'.$row)->getValue();
251
252 if ($unit_cost == '')
253 $unit_cost = 0;
254 //check if size exists
255 $querySize = "Select id from store_product_sizes where conversion_factor = '1' and store_id = $store_id";
256 f_read_column('id', $querySize, $product_size_id);
257
258 //If not, create product size 1
259 if(intval($product_size_id) <= 0)
260 {
261 if($product_size > 1)
262 $query = "Insert into store_product_sizes (conversion_factor,counting_unit,product_size,store_id) values ('1', 'Pcs', 'Case (1)','$store_id')";
263 else
264 $query = "Insert into store_product_sizes (conversion_factor,counting_unit,product_size,store_id) values ('1', 'Pcs', 'Each','$store_id')";
265 $ret = f_insert_query($query, $rows, $last_id);
266 }
267
268 //Get Product Size 1
269 $query = "Select id from store_product_sizes where conversion_factor = '1' and store_id = $store_id";
270 f_read_column('id', $query, $product_size_id);
271
272 //check if department exists
273 $query = "Select id from store_departments where department_name = '$department' AND store_id = $store_id";
274 f_read_column('id', $query, $department_id);
275
276 if(intval($department_id) <= 0)
277 {
278 $query = "insert into store_departments (department_name,total_items,store_id) values ('$department', '0',$store_id)";
279 $ret = f_insert_query($query, $rows, $last_id);
280
281 }
282
283 $query = "Select id from store_departments where department_name = '$department' AND store_id = $store_id";
284 f_read_column('id', $query, $department_id);
285
286 //check if product exists first
287 $query = "Select id from product_master where product_name LIKE '$name' AND store_id = $store_id AND department_id = $department_id AND product_cost LIKE '{$unit_cost}'";
288 f_read_column('id', $query, $product_id);
289 //echo $query;
290 //die();
291 // Inserts into database here
292 if(intval($product_id) <= 0)
293 {
294 $query = "INSERT INTO product_master(product_name, department_id,product_size_id, product_cost, store_id) VALUES('$name', '$department_id', '$product_size_id','$unit_cost','$store_id');";
295 }
296 else
297 {
298 $query = "UPDATE product_master set product_name = '$name', department_id = '$department_id', product_size_id = $product_size_id, product_cost = '$unit_cost', product_selling_price = 0 where id = product_id; $product_id";
299 }
300
301 $ret = f_insert_query($query, $rows, $last_id);
302 $exceldata[] = $rowData[0];
303
304 }
305
306 //add locations
307 $query = "insert into store_locations (location_name,total_items, store_id) SELECT location_name,'0',$store_id FROM sample_locations WHERE sector = 'retail_food'";
308 $ret = f_insert_query($query, $rows, $last_id);
309
310 //create audit
311 $stock_date = date('Y-m-d');
312 $query = "insert into stocktake_master (stock_date,store_id,user_id) values ('$stock_date',$store_id,$user_id)";
313 // echo $query;
314 //die();
315 $ret = f_insert_query($query, $rows, $last_id);
316
317 if ($rows >= 1)
318 {
319 $insert_stock_locations = "insert ignore into stocktake_locations (stocktake_id, store_locations_id) select $last_id, id from store_locations";
320
321 f_update_query($insert_stock_locations, $rows);
322
323 if($last_stock_id > 0)
324 {
325 $query = "insert ignore into stocktake_details (stocktake_id,product_id,department_id,product_size_id,full_cost,unit_of_measure,unit_cost,location_id,orientation,shelf_number,position_number,quantity,total_packed_items,is_damaged,is_expired, store_locations_id)
326 select $last_id , product_id,department_id,product_size_id,full_cost,unit_of_measure,unit_cost,location_id,orientation,shelf_number,position_number,0,total_packed_items,is_damaged,is_expired, store_locations_id from stocktake_details where stocktake_id = $last_stock_id";
327 $ret = f_update_query($query, $rows);
328
329
330 $query_update_locations = "update stocktake_details, stocktake_locations set stocktake_details.location_id = stocktake_locations.id where stocktake_details.stocktake_id = $last_id and stocktake_locations.stocktake_id = $last_id and stocktake_locations.store_locations_id = stocktake_details.store_locations_id";
331 // echo $query_update_locations;
332 //die();
333 f_update_query($query_update_locations, $rows);
334
335 }
336 }
337
338 }
339
340 $customer = \Stripe\Customer::create(array(
341 'email' => $_POST['stripeEmail'],
342 'source' => $_POST['stripeToken'],
343 ));
344
345 $subscription = \Stripe\Subscription::create(array(
346 'customer' => $customer->id,
347 'items' => array(array('plan' => '2')),
348 'tax_percent' => 23.00,
349 ));
350
351 $user_name = $username;
352 $user_pass = $password;
353
354 if (validate_username_password($user_name, $user_pass, $errText))
355 {
356 //echo 'Are we entering here too?';
357
358 $sessionTime = 0;
359 if(isset($_POST['remember_me']) && !empty($_POST['remember_me'])){
360 $sessionTime = time() + (60 * 60 * 24 * 30);
361 }else{
362 $sessionTime = 0;
363 }
364
365 $userCookie = false;
366 $passCookie = false;
367
368 $userCookie = setcookie('ti_user', $user_name, $sessionTime);
369 $passCookie = setcookie('ti_pass', string_encrypt_long($user_pass), $sessionTime);
370
371 ob_clean();
372 echo '<script type="text/javascript"> window.open("https://easycount.io/platform/registration_landing.php", "_parent"); </script>';
373 exit();
374 }
375 }
376 else
377 header("Location: https://easycount.io/platform/failed_registration.php");
378
379} catch(Exception $e)
380 {
381 header("Location: https://easycount.io/platform/failed_registration.php");
382 error_log("unable to sign up customer:" . $_POST['stripeEmail'].
383 ", error:" . $e->getMessage());
384 }
385
386
387
388function validate_username_password($user_name, $user_pass, &$errText, $is_cookie = false)
389{
390
391 $user_name = f_htmlspecialchars($user_name, ENT_QUOTES);
392 $user_pass = f_htmlspecialchars($user_pass, ENT_QUOTES);
393 $user_pass = $user_pass ;
394 if ($is_cookie)
395 $user_pass = $user_pass;
396 else
397 $user_pass = string_encrypt_long($user_pass);
398
399 $query = "select * from user_master where username = '$user_name' and password = '$user_pass'";
400
401 $retval = f_select_query($query, $datarows);
402
403 if ($retval == 1 && count($datarows) > 0)
404 {
405 $status = strtoupper($datarows[0]->status);
406 $auth_type = strtoupper($datarows[0]->auth_type);
407
408 if($status != 'ACTIVE')
409 {
410 $errText .= '* Your account is not active. Please contact administrator.';
411 return false;
412 }
413
414 if($auth_type == 'STORE-USER' || $auth_type == 'STORE-ADMIN')
415 {
416 $admin_id = $datarows[0]->admin_id;
417 $query = "select status from user_master where id = $admin_id";
418 f_read_column('status', $query, $status);
419
420 $query = "select is_new from user_master where username = '$user_name'";
421 //echo $query;
422 //die();
423 f_read_column('status', $query, $is_new);
424
425 if($status != 'ACTIVE')
426 {
427 $errText .= '* Your Main Company Account is not active. Please contact your Company administrator.';
428 return false;
429 }
430 }
431
432 $_SESSION['user_name'] = $datarows[0]->username;
433 $auth_type = strtoupper($datarows[0]->auth_type);
434 $_SESSION['user_id'] = $datarows[0]->id;
435 $_SESSION['user_full_name'] = $datarows[0]->first_name . " " . $datarows[0]->last_name ;
436 $_SESSION['user_level'] = $datarows[0]->user_level;
437 $_SESSION['status'] = $datarows[0]->status;
438 $_SESSION['auth_type'] = $auth_type;
439 $_SESSION['created_date'] = $datarows[0]->created_date;
440 $_SESSION['is_new'] = $datarows[0]->is_new;
441 $_SESSION['customer_id'] = $datarows[0]->customer_id;
442 $_SESSION['store_name'] = $store_name;
443 $_SESSION['store_sector'] = $sector;
444
445
446 if($auth_type == 'COMPANY-ADMIN')
447 {
448 $_SESSION['store_id'] = 0;
449 $user_id = intval($datarows[0]->id);
450 $query_company_id = "select id from company_master where user_id = $user_id";
451 f_read_column('id', $query_company_id, $company_id);
452 $_SESSION['company_id'] = intval($company_id);
453 $_SESSION['admin_id'] = $user_id;
454
455
456 }
457 if($auth_type == 'STORE-ADMIN')
458 $_SESSION['admin_id'] = intval($datarows[0]->id);
459
460 if($auth_type == 'STORE-USER' || $auth_type == 'STORE-ADMIN')
461 $_SESSION['store_id'] = intval($datarows[0]->store_id);
462
463
464 return true;
465 }
466 else
467 {
468 //send_db_error();
469 header("Location: https://easycount.io/platform/failed_registration.php");
470 //header( "Location: /platform/myaccount.php");
471 echo '<meta http-equiv="refresh" content="15;URL=\'https://easycount.io/platform/registration.php\'">';
472 //$errText .= '* Invalid Username / Password. Please enter correct login credentials.';
473 // return false;
474 }
475
476
477}
478
479?>