Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2016
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.01 KB | None | 0 0
  1. <?php
  2. //================
  3. // Core
  4. //=================
  5. class Database{
  6. public static $host = 'localhost';
  7. public static $user = 'root';
  8. public static $password = '';
  9. public static $name = 'logistics';
  10. public static $connect;
  11. public static function Connect(){
  12. Database::$connect = mysqli_connect(Database::$host, Database::$user, Database::$password, Database::$name);
  13. }
  14. }
  15.  
  16. class Company{
  17. public static function Insert(){
  18. $prices = array($_POST['weightPrice'], $_POST['heightPrice']);
  19. $pricesList = implode(",", $prices);
  20. $command = "INSERT INTO companies (name, prices) VALUES ('".$_POST['name']."', '$pricesList')";
  21. mysqli_query(Database::$connect, $command);
  22. }
  23.  
  24. public static function Count(){
  25. $command = "SELECT * FROM companies";
  26. $array = mysqli_query(Database::$connect, $command);
  27. WHILE($row = mysqli_fetch_array($array)):
  28. $prices = $row['prices'];
  29. $pricesList = explode(",", $prices);
  30. //===================================================================
  31. // Price list explained: 0 - weight price | 1 - height price |
  32. //===================================================================
  33. $total = $pricesList[0] * Package::$weight + $pricesList[1] * Package::$height;
  34. include 'result.php';
  35. endwhile;
  36. }
  37.  
  38. public static function Message(){
  39. $clientIP = $_SERVER['REMOTE_ADDR'];
  40. $subject = "Klientas kreipiasi del siuntos - katalogas.no.";
  41. $message = "Jus gavote pasiulyma is zmogaus siuntai. Susisiekite numeriu ". $_POST['phone'] .", kad susitartumete.
  42. klientas taip pat nurode ir savo el paštą,". $_POST['email'];
  43. //mail($_POST['companyMail'], $subject, $message);
  44. echo 'Laiškas isšiųstas.';
  45. }
  46.  
  47. }
  48.  
  49. class Package{
  50. public static $height;
  51. public static $weight;
  52. public static function Description(){
  53. Package::$weight = $_POST['weight'];
  54. Package::$height = $_POST['height'];
  55. if(Package::$weight <= 0 || Package::$weight == ""){
  56. return Package::$weight = 1;
  57. }
  58. if(Package::$height <= 0 || Package::$height == ""){
  59. return Package::$height = 1;
  60. }
  61. }
  62. }
  63. class Output{
  64. public static $includes = array();
  65. public static function Add($path){
  66. Output::$includes[] = $path;
  67. }
  68. public static function Process(){
  69. foreach(Output::$includes as $path){
  70. include($path);
  71. }
  72. }
  73. }
  74.  
  75. //============================
  76. // Logic
  77. //============================
  78. if(isset($_POST['insert'])){
  79. Database::Connect();
  80. Company::Insert();
  81. }
  82. if(isset($_POST['count'])){
  83. Database::Connect();
  84. Package::Description();
  85. Company::Count();
  86.  
  87. }
  88. if(isset($_POST['request'])){
  89. Company::Message();
  90. }
  91.  
  92. Output::Process();
  93. ?>
  94.  
  95. <br><br><br>
  96. <h1>Insert</h1><br>
  97. <form action="main.php" method="POST">
  98. <input name="name" type="text" value="Test name"><br>
  99. Svorio kaina <input type="text" name="weightPrice" value="300"><br>
  100. Aukscio kaina<input type="text" name="heightPrice" value="200"><br>
  101. <input type="submit" name="insert" value="Insert">
  102. </form>
  103.  
  104. <br>
  105. <h1>Skaiciuokle</h1><br>
  106. <form action="main.php" method="POST">
  107. Svoris <input type="text" name="weight" value="20"><br>
  108. Aukstis <input type="text" name="height" value="10"><br>
  109. Miestas <select>
  110. <option name="Oslo">Oslas</option>
  111. <option name="Stavangeris">Stavangeris</option>
  112. <option name="Drammen">Dramenas</option>
  113. </select><Br>
  114. <input type="submit" name="count" value="Count!">
  115. </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement