12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. $infos = Document::addDocument($_FILES["document"], [
  14. "rang" => $_POST["rang"],
  15. "promo" => $_POST["promo"],
  16. "libelle" => $_POST["libelle"]
  17. ]);
  18. echo json_encode($infos);
  19. }
  20. function alter_document($documentid)
  21. {
  22. $doc = new Document($documentid);
  23. // We'll need to parse the PUT body to get our arguments
  24. $params = file_get_contents("php://input", "r");
  25. $putParams = array();
  26. while(preg_match("/&/", $params))
  27. {
  28. $param = strstr($params, "&", true);
  29. $params = substr(strstr($params, "&"), 1);
  30. $putParams[strstr($param, "=", true)] = substr(strstr($param, "="), 1);
  31. }
  32. // We need it one more time for the last argument
  33. $param = $params;
  34. $putParams[strstr($param, "=", true)] = substr(strstr($param, "="), 1);
  35. $doc->changePromo($putParams["promo"]);
  36. $doc->changeRank($putParams["rang"]);
  37. }
  38. function delete_document($fileid)
  39. {
  40. (new Document($fileid))->erase();
  41. }