public function receiveTicketMachine($message, $phone) { $dbOps = new DBOperations(); $con = new mysqli($dbOps->servername, $dbOps->username, $dbOps->password, $dbOps->dbname); //create the db connection $query = ""; if ($con->connect_error) { die("connection failed: " . $con->connect_error); } else { //Get the suitable serial_number for phone_number from ticket_machine table $queryGetEditer = "SELECT * FROM ticket_machine WHERE phone_number = {$phone}"; $result = $con->query($queryGetEditer); $editer = ""; while ($row = mysqli_fetch_array($result)) { $editer = $row['serial_number']; } //set the time zone to Colombo time date_default_timezone_set('Asia/Colombo'); $dt = new DateTime(); //create DateTime object $prepare = explode(" ", $message); // split the ticket machine into array //Example Code: supCode approvedKGs units suppliedKGs if (count($prepare) == 4) { if (is_numeric($prepare[1]) && is_numeric($prepare[2]) && is_numeric($prepare[3])) { //check the approvedKGs units suppliedKGs are integers if (!supplierCodeExists($prepare[0])) { //Example Code: supCode approvedKGs units suppliedKGs if (DBOperations::isSupCodeValid($prepare[0])) { //Check the supplier code valid or invalid $query = "INSERT INTO today_supply(supplier_code, date, approved_kgs, units, supplied_kgs, editer) VALUES ('" . $prepare[0] . "', '" . $dt->format('y-m-d') . "', '" . $prepare[1] . "', '" . $prepare[2] . "', '" . $prepare[3] . "', '" . $editer . "')"; $con->query($query); } else { //If the supplier code invalid then send error message Communication::sendMessage("Supplier code is invalid !", $phone); } } else { //If the supplier code exists then send error message Communication::sendMessage("Supplier code is already exists the system !", $phone); } } else { //reply again to the ticket machine Communication::sendMessage("Sent message is invalid.", $phone); } //Example Code: supCode approvedKGs suppliedKGs //Example Code: supCode approvedKGs units } else { if (count($prepare) == 3) { if (is_numeric($prepare[1]) && is_numeric($prepare[2])) { //check the integers as above if (!supplierCodeExists($prepare[0])) { if ($prepare[1] <= $prepare[2]) { //Example Code: supCode approvedKGs suppliedKGs if (DBOperations::isSupCodeValid($prepare[0])) { //Check the supplier code valid or invalid $query = "INSERT INTO today_supply(supplier_code, date, approved_kgs, supplied_kgs, editer) VALUES ('" . $prepare[0] . "', '" . $dt->format('y-m-d') . "', '" . $prepare[1] . "', '" . $prepare[2] . "', '" . $editer . "')"; $con->query($query); } else { //If the supplier code invalid then send error message Communication::sendMessage("Supplier code is invalid !", $phone); } } else { //Example Code: supCode approvedKGs units if (DBOperations::isSupCodeValid($prepare[0])) { //Check the supplier code valid or invalid $query = "INSERT INTO today_supply(supplier_code, date, approved_kgs, units, editer) VALUES ('" . $prepare[0] . "', '" . $dt->format('y-m-d') . "', '" . $prepare[1] . "', '" . $prepare[2] . "', '" . $editer . "')"; $con->query($query); } else { //If the supplier code invalid then send error message Communication::sendMessage("Supplier code is invalid !", $phone); } } } else { //If the supplier code exists then send error message Communication::sendMessage("Supplier code is already exists the system !", $phone); } } else { //reply again to the ticket machine Communication::sendMessage("Sent message is invalid.", $phone); } //Example Code: supCode approvedKGs } else { if (count($prepare) == 2) { if (is_numeric($prepare[1])) { if (!DBOperations::supplierCodeExists($prepare[0])) { //Example Code: supCode approvedKGs if (DBOperations::isSupCodeValid($prepare[0])) { //Check the supplier code valid or invalid $query = "INSERT INTO today_supply(supplier_code, date, approved_kgs, editer) VALUES ('" . $prepare[0] . "', '" . $dt->format('y-m-d') . "', '" . $prepare[1] . "', '" . $editer . "')"; $con->query($query); } else { //If the supplier code invalid then send error message Communication::sendMessage("Supplier code is invalid !", $phone); } } else { //If the supplier code exists then send error message Communication::sendMessage("Supplier code is already exists the system !", $phone); } } else { //reply again to the ticket machine Communication::sendMessage("Sent message is invalid.", $phone); } //Example Code: without above codes } else { //reply again to the ticket machine Communication::sendMessage("Sent message is invalid.", $phone); } } } } }
<?php include_once 'message/messageDB.php'; include_once 'message/communication.php'; // if(!empty($_POST['number'])){ // echo "number: ".$_POST['number']; // echo " sms: ".$_POST['send_message']; // } // if(!empty($_POST['received_message']) && $_POST['dbOps'] == "read message"){ // $filterMessage = DBOperations::filterMessageDetails($_POST['received_message']); // DBOperations::sendMessageDetails($filterMessage); // } if (!empty($_POST['number']) && !empty($_POST['send_message'])) { $mobileNumber = Communication::prepareNumber($_POST['number']); Communication::sendMessage($_POST['send_message'], $mobileNumber); } //DBOperations::receiveMessages("hgsr hjk", "94713535362"); //Supplier request message //DBOperations::displayMessageTable(); //DBOperations::receiveTicketMachine("0001 20", "94713535362"); //ticket machine message ?>
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button> <h4> <i class="icon fa fa-check"></i> Sorry!</h4> supplier allready exists , Please Try another one. </div>'; // $msg = " // <div class='alert alert-error'> // <button class='close' data-dismiss='alert'>×</button> // <strong>Sorry !</strong> email allready exists , Please Try another one // </div> // "; } else { if ($supplier->register($scode, $fname, $lname, $nic, $iCheck, $email, $address_1, $mobile, $estate, $estate_name, $reg_no, $size_of_estate, $estate_address, $bankn, $branch, $account, $bankacc, $editor)) { $message = "Thalapalakanada Tea factory, username: 0001 password: {$nic} http://tsms.x10host.com/page/"; if (!empty($mobile)) { $mobileNumber = Communication::prepareNumber($mobile); Communication::sendMessage($message, $mobileNumber); } echo ' <div class="row"> <div class="col-md-12"> <div class="box"> <div class="box-header"> <h3 class="box-title">Supplier Settings</h3> </div> <div class="box-body"> <p>Supplier Successfuly added to the database. Also You can change Supplier settings.</p> <a class="btn btn-app"> <i href="supplieredit.php" class="fa fa-edit"></i> Edit </a> <a href="suppliers.php" class="btn btn-app"> <i class="fa fa-user-plus"></i> Add Another