Simple PHP api for SnipeIT app. Not maintained anymore; check out BinStack instead: https://source.netsyms.com/Business/BinStack and https://netsyms.biz/binstack
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

updateitem.php 1.7KB

1234567891011121314151617181920212223242526272829303132
  1. <?php
  2. /**
  3. * Create/update an item.
  4. */
  5. require 'required.php';
  6. require 'dieifnotloggedin.php';
  7. $from = $_POST['from'];
  8. require 'readfrom.php';
  9. $id = $_POST['id'];
  10. if (is_empty($_POST['asset_tag']) && $from == 'assets') {
  11. sendError('Please fill in an asset tag.');
  12. }
  13. if (is_empty($id)) {
  14. // We need to create an item
  15. if ($from == 'assets') {
  16. $user_id = $database->select('users', 'id', ['username' => $_SESSION['user']])[0];
  17. $database->insert($from, ['name' => $_POST['name'], 'user_id' => $user_id, 'asset_tag' => $_POST['asset_tag'], 'rtd_location_id' => $_POST['location'], 'order_number' => $_POST['order_number'], 'status_id' => $_POST['status'], 'serial' => $_POST['serial'], 'model_id' => $_POST['model'], '#updated_at' => 'NOW()', '#created_at' => 'NOW()'/*, '_snipeit_hard_drive_secure__y_n_' => $_POST['hdd_secure']*/]);
  18. } else {
  19. $database->insert($from, ['name' => $_POST['name'], 'location_id' => $_POST['location'], 'qty' => $_POST['qty'], 'order_number' => $_POST['order_number'], '#updated_at' => 'NOW()', '#created_at' => 'NOW()']);
  20. }
  21. } else {
  22. // Update an existing item by id
  23. if ($from == 'assets') {
  24. $database->update($from, ['name' => $_POST['name'], 'asset_tag' => $_POST['asset_tag'], 'rtd_location_id' => $_POST['location'], 'order_number' => $_POST['order_number'], 'status_id' => $_POST['status'], 'serial' => $_POST['serial'], 'model_id' => $_POST['model'], '#updated_at' => 'NOW()'/*, '_snipeit_hard_drive_secure__y_n_' => $_POST['hdd_secure']*/], ['id' => $id]);
  25. } else {
  26. $database->update($from, ['name' => $_POST['name'], 'location_id' => $_POST['location'], 'qty' => $_POST['qty'], 'order_number' => $_POST['order_number'], '#updated_at' => 'NOW()'], ['id' => $id]);
  27. }
  28. }
  29. sendOK();