document.php 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. require_once(dirname(__DIR__) . "/models/document.class.php");
  3. require_once(dirname(__DIR__) . "/models/promo.class.php");
  4. function document()
  5. {
  6. set("title", "Documents");
  7. set("data", Document::getAll());
  8. set("promos", Promo::getAll());
  9. return html("list.html.php", "layout.html.php");
  10. }
  11. function add_document()
  12. {
  13. $filePath = Document::addDocument($_FILES["document"], [
  14. "rang" => $_POST["rang"],
  15. "promo" => $_POST["promo"],
  16. "libelle" => $_POST["libelle"]
  17. ]);
  18. json_encode(array(
  19. "path" => $filePath
  20. ));
  21. }
  22. function alter_document($documentid)
  23. {
  24. $doc = new Document($documentid);
  25. // We'll need to parse the PUT body to get our arguments
  26. $params = file_get_contents("php://input", "r");
  27. $putParams = array();
  28. while(preg_match("/&/", $params))
  29. {
  30. $param = strstr($params, "&", true);
  31. $params = substr(strstr($params, "&"), 1);
  32. $putParams[strstr($param, "=", true)] = substr(strstr($param, "="), 1);
  33. }
  34. // We need it one more time for the last argument
  35. $param = $params;
  36. $putParams[strstr($param, "=", true)] = substr(strstr($param, "="), 1);
  37. $doc->changePromo($putParams["promo"]);
  38. $doc->changeRank($putParams["rang"]);
  39. }
  40. function delete_document($fileid)
  41. {
  42. (new Document($fileid))->erase();
  43. }