Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //================
- // Core
- //=================
- class Database{
- public static $host = 'localhost';
- public static $user = 'root';
- public static $password = '';
- public static $name = 'logistics';
- public static $connect;
- public static function Connect(){
- Database::$connect = mysqli_connect(Database::$host, Database::$user, Database::$password, Database::$name);
- }
- }
- class Company{
- public static function Insert(){
- $prices = array($_POST['weightPrice'], $_POST['heightPrice']);
- $pricesList = implode(",", $prices);
- $command = "INSERT INTO companies (name, prices) VALUES ('".$_POST['name']."', '$pricesList')";
- mysqli_query(Database::$connect, $command);
- }
- public static function Count(){
- $command = "SELECT * FROM companies";
- $array = mysqli_query(Database::$connect, $command);
- WHILE($row = mysqli_fetch_array($array)):
- $prices = $row['prices'];
- $pricesList = explode(",", $prices);
- //===================================================================
- // Price list explained: 0 - weight price | 1 - height price |
- //===================================================================
- $total = $pricesList[0] * Package::$weight + $pricesList[1] * Package::$height;
- include 'result.php';
- endwhile;
- }
- public static function Message(){
- $clientIP = $_SERVER['REMOTE_ADDR'];
- $subject = "Klientas kreipiasi del siuntos - katalogas.no.";
- $message = "Jus gavote pasiulyma is zmogaus siuntai. Susisiekite numeriu ". $_POST['phone'] .", kad susitartumete.
- klientas taip pat nurode ir savo el paštą,". $_POST['email'];
- //mail($_POST['companyMail'], $subject, $message);
- echo 'Laiškas isšiųstas.';
- }
- }
- class Package{
- public static $height;
- public static $weight;
- public static function Description(){
- Package::$weight = $_POST['weight'];
- Package::$height = $_POST['height'];
- if(Package::$weight <= 0 || Package::$weight == ""){
- return Package::$weight = 1;
- }
- if(Package::$height <= 0 || Package::$height == ""){
- return Package::$height = 1;
- }
- }
- }
- class Output{
- public static $includes = array();
- public static function Add($path){
- Output::$includes[] = $path;
- }
- public static function Process(){
- foreach(Output::$includes as $path){
- include($path);
- }
- }
- }
- //============================
- // Logic
- //============================
- if(isset($_POST['insert'])){
- Database::Connect();
- Company::Insert();
- }
- if(isset($_POST['count'])){
- Database::Connect();
- Package::Description();
- Company::Count();
- }
- if(isset($_POST['request'])){
- Company::Message();
- }
- Output::Process();
- ?>
- <br><br><br>
- <h1>Insert</h1><br>
- <form action="main.php" method="POST">
- <input name="name" type="text" value="Test name"><br>
- Svorio kaina <input type="text" name="weightPrice" value="300"><br>
- Aukscio kaina<input type="text" name="heightPrice" value="200"><br>
- <input type="submit" name="insert" value="Insert">
- </form>
- <br>
- <h1>Skaiciuokle</h1><br>
- <form action="main.php" method="POST">
- Svoris <input type="text" name="weight" value="20"><br>
- Aukstis <input type="text" name="height" value="10"><br>
- Miestas <select>
- <option name="Oslo">Oslas</option>
- <option name="Stavangeris">Stavangeris</option>
- <option name="Drammen">Dramenas</option>
- </select><Br>
- <input type="submit" name="count" value="Count!">
- </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement