Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require_once('./config.php');
- require_once ('./dbconn.php');
- require 'PHPExcel/Classes/PHPExcel/IOFactory.php';
- require_once('Stripe/init.php');
- \Stripe\Stripe::setApiKey("sk_test_4zljnNryTJFJMjYwHPRALTlW");
- try
- {
- $errText = '';
- $store_name = $_POST["storeName"];
- $sub = $_GET["sub"];
- $first_name = $_POST["firstName"];
- $last_name = $_POST["lastName"];
- $username = $_POST["username"];
- $password = $_POST["password"];
- $phone = $_POST["phone"];
- $sector = $_POST["store_sector"];
- $created_date = date('Y-m-d H:i:s');
- $pass_enc = string_encrypt_long($password);
- $store_name = str_replace("'", "''", $store_name);
- $first_name = str_replace("'", "''", $first_name);
- $last_name = str_replace("'", "''", $last_name);
- $sector = 'retail_food';
- // Email on Sign-Up
- $to = 'michael@easycount.io';
- // Subject
- $subject = 'EasyCount Finalised Sign-Up';
- // Message
- $message = '
- <html>
- <head>
- <title>EasyCount Finalised Sign-Up</title>
- </head>
- <body>
- <div style="background-color:#000000">
- <br>
- <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>
- <br>
- </div>
- <br>
- <p align="center"><font color="#27abea"><strong>New Finalised Sign-Up!</strong></font></p>
- <br>
- <p align="center"><font color="#27abea"><strong>Full Name: </strong></font>'.$first_name.'</p>
- <br>
- <p align="center"><font color="#27abea"><strong>Phone: </strong></font>'.$phone.'</p>
- <br>
- <p align="center"><font color="#27abea"><strong>Store: </strong></font>'.$store_name.'</p>
- <br>
- <p align="center"><font color="27abea"><strong>Email: </strong></font>'.$username.'</p>
- <br>
- <p align="center"><font color="27abea"><strong>Date of Creation: </strong></font>'.$created_date.'</p>
- <br>
- <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>
- <footer style = "background-color:#000000;">
- <br>
- <p align="center"><i><font color="white">Company: EasyCount.io</font></i></p>
- <p align="center"><i><font color="white">Contact Email: <a href="mailto:michael@easycount.io">michael@EasyCount.io</a>.</font></i></p>
- <p align="center"><i><font color="white">Contact Number: (+353) 01 9696509</font></i></p>
- <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>
- <p style="text-align:center;">
- <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">
- <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">
- <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">
- <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">
- <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">
- </p>
- <br>
- </footer>
- </body>
- </html>
- ';
- // Send HTML mail
- $headers[] = 'MIME-Version: 1.0';
- $headers[] = 'Content-type: text/html; charset=iso-8859-1';
- // Additional headers
- $headers[] = 'From: EasyCount <info@easycount.io>';
- // Mail
- mail($to, $subject, $message, implode("\r\n", $headers));
- // Email on Sign-Up Completion
- $toS = $username;
- // Subject
- $subjectS = 'EasyCount Welcome';
- // Message
- $messageS = '
- <html>
- <head>
- <title>Greetings from EasyCount!</title>
- </head>
- <body>
- <div style="padding-top:40px;padding-bottom:30px;padding-right:20px;padding-left:20px;margin:0 auto;margin:0 auto">
- <div style="background-color:#000000">
- <br>
- <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>
- <br>
- </div>
- <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>
- <br>
- <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>
- <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>
- <br>
- <p align="center" style="font-size: 13px; word-spacing: 0.8px;">To log in to the Web Platform, click the link below: </p>
- <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>
- <br>
- <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>
- <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>
- <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>
- <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>
- <br>
- <p align="center" style="font-size: 16px;">To learn more about our software, make sure you</p>
- <br>
- <table align="center">
- <tr>
- <td class="thsignup">
- <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>
- <br>
- <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>
- <br>
- <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>
- </td>
- </tr>
- </table>
- <br>
- <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>
- </div>
- </body>
- <footer style = "background-color:#000000;">
- <br>
- <p align="center"><i><font color="white">Company: EasyCount.io</font></i></p>
- <p align="center"><i><font color="white">Contact Email: <a href="mailto:michael@easycount.io">michael@EasyCount.io</a>.</font></i></p>
- <p align="center"><i><font color="white">Contact Number: (+353) 01 9696509</font></i></p>
- <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>
- <p style="text-align:center;">
- <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">
- <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">
- <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">
- <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">
- <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">
- </p>
- <br>
- </footer>
- </html>
- ';
- // Send HTML mail
- $headersS[] = 'MIME-Version: 1.0';
- $headersS[] = 'Content-type: text/html; charset=iso-8859-1';
- // Additional headers
- $headersS[] = 'From: EasyCount <info@easycount.io>';
- // Mail
- mail($toS, $subjectS, $messageS, implode("\r\n", $headersS));
- /*Validate Email
- $sql_email = "SELECT * FROM user_master WHERE username = '$username'";
- $used = mysqli_query($conn, $sql_email);
- if (mysqli_num_rows($used) > 0) {
- }*/
- //create store first & get last insert ID
- $query_stores = "insert into store_master (company_id, store_name, email, customer_id, store_sector) values ('1','$store_name','$username','8', 'retail_food')";
- $ret = f_insert_query($query_stores, $rows, $last_id);
- $store_id = $last_id;
- //create user for this store ID
- //echo 'Sub is: ' . $sub;
- //die();
- if ($sub == 'free')
- {
- $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)
- 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)";
- }
- else if ($sub == 'single')
- {
- $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)
- 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)";
- }
- else if ($sub == 'plus')
- {
- $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)
- 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)";
- }
- else
- {
- $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)
- 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)";
- }
- //echo $query;
- $ret = f_insert_query($query_users, $rows, $last_id);
- $user_id = $last_id;
- //redirect with login verification to page in new tab to upload products
- if ($rows >= 1)
- {
- //upload files
- if ($sector == 'retail_food')
- {
- $uploaddir = 'temp_files/';
- $uploadfile = $uploaddir . 'deli_sample1.xlsx';
- $exceldata = array();
- PHPExcel_Settings::setZipClass(PHPExcel_Settings::PCLZIP);
- $exceldata = array();
- try
- {
- $inputfiletype = PHPExcel_IOFactory::identify($uploadfile);
- $objReader = PHPExcel_IOFactory::createReader($inputfiletype);
- $objPHPExcel = $objReader->load($uploadfile);
- }
- catch(Exception $e)
- {
- die('Error loading file "'.pathinfo($inputfilename,PATHINFO_BASENAME).'": '.$e->getMessage());
- }
- // Get worksheet dimensions
- $sheet = $objPHPExcel->getSheet(0);
- $highestRow = $sheet->getHighestRow();
- $highestColumn = $sheet->getHighestColumn();
- // Loop through each row of the worksheet in turn
- for ($row = 2; $row <= $highestRow; $row++)
- {
- conn_start();
- // Read a row of data into an array
- $rowData = $sheet->rangeToArray('A' . $row . ':' . $highestColumn . $row, NULL, TRUE, FALSE);
- $product_name = $sheet->getCell('A'.$row)->getValue();
- $count_unit = $sheet->getCell('B'.$row)->getValue();
- $product_name = preg_replace('/[^A-Za-z0-9\. -]/', '', $product_name);
- $name = $product_name . ' (' . $count_unit . ')';
- $department = $sheet->getCell('C'.$row)->getValue();
- $unit_cost = $sheet->getCell('D'.$row)->getValue();
- if ($unit_cost == '')
- $unit_cost = 0;
- //check if size exists
- $querySize = "Select id from store_product_sizes where conversion_factor = '1' and store_id = $store_id";
- f_read_column('id', $querySize, $product_size_id);
- //If not, create product size 1
- if(intval($product_size_id) <= 0)
- {
- if($product_size > 1)
- $query = "Insert into store_product_sizes (conversion_factor,counting_unit,product_size,store_id) values ('1', 'Pcs', 'Case (1)','$store_id')";
- else
- $query = "Insert into store_product_sizes (conversion_factor,counting_unit,product_size,store_id) values ('1', 'Pcs', 'Each','$store_id')";
- $ret = f_insert_query($query, $rows, $last_id);
- }
- //Get Product Size 1
- $query = "Select id from store_product_sizes where conversion_factor = '1' and store_id = $store_id";
- f_read_column('id', $query, $product_size_id);
- //check if department exists
- $query = "Select id from store_departments where department_name = '$department' AND store_id = $store_id";
- f_read_column('id', $query, $department_id);
- if(intval($department_id) <= 0)
- {
- $query = "insert into store_departments (department_name,total_items,store_id) values ('$department', '0',$store_id)";
- $ret = f_insert_query($query, $rows, $last_id);
- }
- $query = "Select id from store_departments where department_name = '$department' AND store_id = $store_id";
- f_read_column('id', $query, $department_id);
- //check if product exists first
- $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}'";
- f_read_column('id', $query, $product_id);
- //echo $query;
- //die();
- // Inserts into database here
- if(intval($product_id) <= 0)
- {
- $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');";
- }
- else
- {
- $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";
- }
- $ret = f_insert_query($query, $rows, $last_id);
- $exceldata[] = $rowData[0];
- }
- //add locations
- $query = "insert into store_locations (location_name,total_items, store_id) SELECT location_name,'0',$store_id FROM sample_locations WHERE sector = 'retail_food'";
- $ret = f_insert_query($query, $rows, $last_id);
- //create audit
- $stock_date = date('Y-m-d');
- $query = "insert into stocktake_master (stock_date,store_id,user_id) values ('$stock_date',$store_id,$user_id)";
- // echo $query;
- //die();
- $ret = f_insert_query($query, $rows, $last_id);
- if ($rows >= 1)
- {
- $insert_stock_locations = "insert ignore into stocktake_locations (stocktake_id, store_locations_id) select $last_id, id from store_locations";
- f_update_query($insert_stock_locations, $rows);
- if($last_stock_id > 0)
- {
- $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)
- 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";
- $ret = f_update_query($query, $rows);
- $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";
- // echo $query_update_locations;
- //die();
- f_update_query($query_update_locations, $rows);
- }
- }
- }
- $customer = \Stripe\Customer::create(array(
- 'email' => $_POST['stripeEmail'],
- 'source' => $_POST['stripeToken'],
- ));
- $subscription = \Stripe\Subscription::create(array(
- 'customer' => $customer->id,
- 'items' => array(array('plan' => '2')),
- 'tax_percent' => 23.00,
- ));
- $user_name = $username;
- $user_pass = $password;
- if (validate_username_password($user_name, $user_pass, $errText))
- {
- //echo 'Are we entering here too?';
- $sessionTime = 0;
- if(isset($_POST['remember_me']) && !empty($_POST['remember_me'])){
- $sessionTime = time() + (60 * 60 * 24 * 30);
- }else{
- $sessionTime = 0;
- }
- $userCookie = false;
- $passCookie = false;
- $userCookie = setcookie('ti_user', $user_name, $sessionTime);
- $passCookie = setcookie('ti_pass', string_encrypt_long($user_pass), $sessionTime);
- ob_clean();
- echo '<script type="text/javascript"> window.open("https://easycount.io/platform/registration_landing.php", "_parent"); </script>';
- exit();
- }
- }
- else
- header("Location: https://easycount.io/platform/failed_registration.php");
- } catch(Exception $e)
- {
- header("Location: https://easycount.io/platform/failed_registration.php");
- error_log("unable to sign up customer:" . $_POST['stripeEmail'].
- ", error:" . $e->getMessage());
- }
- function validate_username_password($user_name, $user_pass, &$errText, $is_cookie = false)
- {
- $user_name = f_htmlspecialchars($user_name, ENT_QUOTES);
- $user_pass = f_htmlspecialchars($user_pass, ENT_QUOTES);
- $user_pass = $user_pass ;
- if ($is_cookie)
- $user_pass = $user_pass;
- else
- $user_pass = string_encrypt_long($user_pass);
- $query = "select * from user_master where username = '$user_name' and password = '$user_pass'";
- $retval = f_select_query($query, $datarows);
- if ($retval == 1 && count($datarows) > 0)
- {
- $status = strtoupper($datarows[0]->status);
- $auth_type = strtoupper($datarows[0]->auth_type);
- if($status != 'ACTIVE')
- {
- $errText .= '* Your account is not active. Please contact administrator.';
- return false;
- }
- if($auth_type == 'STORE-USER' || $auth_type == 'STORE-ADMIN')
- {
- $admin_id = $datarows[0]->admin_id;
- $query = "select status from user_master where id = $admin_id";
- f_read_column('status', $query, $status);
- $query = "select is_new from user_master where username = '$user_name'";
- //echo $query;
- //die();
- f_read_column('status', $query, $is_new);
- if($status != 'ACTIVE')
- {
- $errText .= '* Your Main Company Account is not active. Please contact your Company administrator.';
- return false;
- }
- }
- $_SESSION['user_name'] = $datarows[0]->username;
- $auth_type = strtoupper($datarows[0]->auth_type);
- $_SESSION['user_id'] = $datarows[0]->id;
- $_SESSION['user_full_name'] = $datarows[0]->first_name . " " . $datarows[0]->last_name ;
- $_SESSION['user_level'] = $datarows[0]->user_level;
- $_SESSION['status'] = $datarows[0]->status;
- $_SESSION['auth_type'] = $auth_type;
- $_SESSION['created_date'] = $datarows[0]->created_date;
- $_SESSION['is_new'] = $datarows[0]->is_new;
- $_SESSION['customer_id'] = $datarows[0]->customer_id;
- $_SESSION['store_name'] = $store_name;
- $_SESSION['store_sector'] = $sector;
- if($auth_type == 'COMPANY-ADMIN')
- {
- $_SESSION['store_id'] = 0;
- $user_id = intval($datarows[0]->id);
- $query_company_id = "select id from company_master where user_id = $user_id";
- f_read_column('id', $query_company_id, $company_id);
- $_SESSION['company_id'] = intval($company_id);
- $_SESSION['admin_id'] = $user_id;
- }
- if($auth_type == 'STORE-ADMIN')
- $_SESSION['admin_id'] = intval($datarows[0]->id);
- if($auth_type == 'STORE-USER' || $auth_type == 'STORE-ADMIN')
- $_SESSION['store_id'] = intval($datarows[0]->store_id);
- return true;
- }
- else
- {
- //send_db_error();
- header("Location: https://easycount.io/platform/failed_registration.php");
- //header( "Location: /platform/myaccount.php");
- echo '<meta http-equiv="refresh" content="15;URL=\'https://easycount.io/platform/registration.php\'">';
- //$errText .= '* Invalid Username / Password. Please enter correct login credentials.';
- // return false;
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement