1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. require_once(dirname(__DIR__)."/models/promo.class.php");
  3. function promo()
  4. {
  5. set("title", "Promotions");
  6. set("data", Promo::getAll());
  7. return html("list.html.php", "layout.html.php");
  8. }
  9. function add_promo()
  10. {
  11. Promo::addPromo([
  12. "id" => $_POST["id"],
  13. "libelle" => $_POST["libelle"]
  14. ]);
  15. }
  16. function alter_promo($promoid)
  17. {
  18. $promo = new Promo($promoid);
  19. // We'll need to parse the PUT body to get our arguments
  20. $params = file_get_contents("php://input", "r");
  21. $putParams = array();
  22. while(preg_match("/&/", $params))
  23. {
  24. $param = strstr($params, "&", true);
  25. $params = substr(strstr($params, "&"), 1);
  26. $putParams[strstr($param, "=", true)] = substr(strstr($param, "="), 1);
  27. }
  28. // We need it one more time for the last argument
  29. $param = $params;
  30. $putParams[strstr($param, "=", true)] = substr(strstr($param, "="), 1);
  31. $promo->setLibelle($putParams["libelle"]);
  32. $promo->write();
  33. }
  34. function delete_promo($promoid)
  35. {
  36. (new Promo($promoid))->erase();
  37. }