Advertisement
Guest User

Untitled

a guest
Feb 6th, 2018
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.40 KB | None | 0 0
  1. <?php
  2. date_default_timezone_set('Europe/Kiev');
  3. header('Content-Type: text/html; charset=utf-8');
  4. header('Access-Control-Allow-Origin: *');
  5. header('Access-Control-Allow-Methods: POST, GET');
  6.  
  7. $servername = "localhost";
  8. $username = "id956225_id956225_ssergey931";
  9. $password = "fuckerspace";
  10. $dbname = "id956225_dbmigration";
  11.  
  12. // Create connection
  13. $conn = new mysqli($servername, $username, $password, $dbname);
  14. // Check connection
  15. if ($conn->connect_error) {
  16.     die("Connection failed: " . $conn->connect_error);
  17. }
  18.  
  19. // $conn->close();
  20. ?>
  21.  
  22. <?php
  23. if (!empty($_POST))
  24. {
  25.  
  26.     if (!empty($_POST['isNewOrder'])) {
  27.         $firstName = $_POST['firstName'];
  28.         $lastName = $_POST['lastName'];
  29.         $phone = $_POST['phoneNumber'];
  30.         $deviceType = $_POST['DeviceType'];
  31.         $deviceName = $_POST['productName'];
  32.         $deviceTypeIndex = $_POST['DeviceTypeIndex'];
  33.         $breaking = $_POST['issue'];
  34.         $notes = $_POST['notes'];
  35.         $performedRepairs = $_POST['performedRepairs'];
  36.         $orderStatus = $_POST['orderStatus'];
  37.  
  38.         $query = "INSERT INTO mainbase (Date_of_Issue, FirstNameC, LastNameC, Nphone, Type_device, Name_Device, Breaking, Notes, Performed_repairs, Order_status, Warranty_start, Warranty_end, Date_design, Price) VALUES (now(), '$firstName', '$lastName', '$phone', '$deviceType', '$deviceName', '$breaking', '$notes', '$performedRepairs', '$orderStatus', now(), NOW()+INTERVAL 1 DAY, now(), '0')";
  39.        
  40.         if (mysqli_query($conn, $query)) {
  41.             echo "New order created successfully\n";
  42.  
  43.             $query = $conn->query("SELECT Number_order FROM mainbase ORDER BY Number_order DESC LIMIT 1");
  44.             while($data = $query->fetch_assoc()) {
  45.                 $orderNumber = $data["Number_order"];
  46.                 echo "The last order number is: " . $data["Number_order"]. "\n";
  47.             }
  48.  
  49.             $comp = $_POST['comp'];
  50.             $charger = $comp['charger'];
  51.             $battery = $comp['battery'];
  52.             $bag = $comp['bag'];
  53.             $cable = $comp['cable'];
  54.             $flashDrive = $comp['flashDrive'];
  55.             $simCard = $comp['simCard'];
  56.             $caps = $comp['caps'];
  57.             $appearance = $_POST['appearance'];
  58.             $workflowNotes = $_POST['workflowNotes'];
  59.             $seal = $_POST['seal'];
  60.  
  61.             $query = "INSERT INTO komplekt (ID_Zakaz, Charger, Battery, Bag, Cable, FlashDrive, SimCard, Caps, Appearance, WorkflowNotes, Seal) VALUES ('$orderNumber', '$charger', '$battery', '$bag', '$cable', '$flashDrive', '$simCard', '$caps', '$appearance', '$workflowNotes', '$seal')";
  62.             if (mysqli_query($conn, $query)) {
  63.                 echo "Complectation info is added too\n";
  64.             } else {
  65.                 echo "Error: " . $query . "<br>" . mysqli_error($conn);
  66.             }
  67.         } else {
  68.             echo "Error: " . $query . "<br>" . mysqli_error($conn);
  69.         }
  70.     }
  71.     if (!empty($_POST['isEditOrder'])) {
  72.         $issue = $_POST['issue'];
  73.         $dateOfissue = $_POST['date'];
  74.         $dateDesign = $_POST['dateDesign'];
  75.         $firstName = $_POST['firstName'];
  76.         $lastName = $_POST['lastName'];
  77.         $phoneNumber = $_POST['phoneNumber'];
  78.         $deviceName = $_POST['productName'];
  79.         $deviceType = $_POST['DeviceType'];
  80.         $notes = $_POST['notes'];
  81.         $orderNumber = $_POST['orderNumber'];
  82.         $orderStatus = $_POST['orderStatus'];
  83.         $performedRepairs = $_POST['performedRepairs'];
  84.         $warrantyStart = $_POST['warrantyStart'];
  85.         $warrantyEnd = $_POST['warrantyEnd'];
  86.         $price = $_POST['price'];
  87.         $seal = $_POST['seal'];
  88.         $appearance = $_POST['appearance'];
  89.         $workflowNotes = $_POST['workflowNotes'];
  90.         $comp = $_POST['comp'];
  91.  
  92.         $query = "UPDATE mainbase SET Breaking='$issue', Date_of_Issue='$dateOfissue', FirstNameC='$firstName', LastNameC='$lastName', Nphone='$phoneNumber', Type_device='$deviceType', Name_device='$deviceName', notes='$notes', Performed_repairs='$performedRepairs', Order_status='$orderStatus', Warranty_start='$warrantyStart', Warranty_end='$warrantyEnd', Date_design='$dateDesign', Price='$price' WHERE Number_order='$orderNumber'";
  93.         if (mysqli_query($conn, $query)) {
  94.             echo "The record was updated successfully";
  95.         } else {
  96.             echo "Error: " . $query . "<br>" . mysqli_error($conn);
  97.         }
  98.  
  99.     }
  100.     if (!empty($_POST['getdata'])) {
  101.         $arrsum = array();
  102.         $data_comp = array();
  103.         $data_orders = array();
  104.         $data_types = array();
  105.         $data_users = array();
  106.  
  107.         $query = $conn->query("SELECT * FROM komplekt");
  108.         while($data = $query->fetch_assoc()) {
  109.             $data_comp[$data["ID_Zakaz"]] = $data;
  110.         }
  111.         $query = $conn->query("SELECT * FROM mainbase ORDER BY Number_order DESC");
  112.         while($data = $query->fetch_assoc()) {
  113.             $data_orders[] = $data;
  114.         }
  115.         $query = $conn->query("SELECT * FROM type");
  116.         while($data = $query->fetch_assoc()) {
  117.             $data_types[] = $data;
  118.         }
  119.         $query = $conn->query("SELECT * FROM users");
  120.         while($data = $query->fetch_assoc()) {
  121.             $data_users[] = $data;
  122.         }
  123.         $arrsum[] = $data_comp;
  124.         $arrsum[] = $data_orders;
  125.         $arrsum[] = $data_types;
  126.         $arrsum[] = $data_users;
  127.         echo json_encode($arrsum);
  128.     }
  129. }
  130.  
  131.  
  132.  
  133. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement