diff --git a/server_files/classes/Document.php b/server_files/classes/Document.php
index 020eeab..76622e9 100644
--- a/server_files/classes/Document.php
+++ b/server_files/classes/Document.php
@@ -270,6 +270,7 @@ class DocumentType
const SANITARY_PLUG = 2;
const SOLUTION = 3;
const SYNTHESIS = 4;
+ const SCHOLARSHIP = 5;
public static function getTranslatedName($type) {
switch ($type) {
@@ -279,6 +280,8 @@ class DocumentType
return "Autorisation de droit à l'image";
case self::SANITARY_PLUG:
return "Fiche sanitaire";
+ case self::SCHOLARSHIP:
+ return "Notification de bourse";
case self::SOLUTION:
return "Solution";
default:
@@ -294,6 +297,8 @@ class DocumentType
return "PHOTO_CONSENT";
case self::SANITARY_PLUG:
return "SANITARY_PLUG";
+ case self::SCHOLARSHIP:
+ return "SCHOLARSHIP";
case self::SOLUTION:
return "SOLUTION";
default:
@@ -309,6 +314,8 @@ class DocumentType
return self::PHOTO_CONSENT;
case "SANITARY_PLUG":
return self::SANITARY_PLUG;
+ case "SCHOLARSHIP":
+ return self::SCHOLARSHIP;
case "SOLUTION":
return self::SOLUTION;
default:
diff --git a/server_files/classes/Payment.php b/server_files/classes/Payment.php
index 7cb12bc..2847403 100644
--- a/server_files/classes/Payment.php
+++ b/server_files/classes/Payment.php
@@ -54,6 +54,16 @@ class Payment
return $this->amount;
}
+ /**
+ * @param mixed $amount
+ */
+ public function setAmount($amount)
+ {
+ global $DB;
+ $this->amount = $amount;
+ $DB->prepare("UPDATE `payments` SET `amount` = ? WHERE `id` = ?;")->execute([$amount, $this->id]);
+ }
+
/**
* @return int
*/
@@ -137,6 +147,6 @@ class Payment
{
global $DB;
$this->validation_status = $validation_status;
- $DB->prepare("UPDATE `payments` SET `$validation_status` = ? WHERE `id` = ?;")->execute([ValidationStatus::fromName($validation_status), $this->id]);
+ $DB->prepare("UPDATE `payments` SET `validation_status` = ? WHERE `id` = ?;")->execute([ValidationStatus::getName($validation_status), $this->id]);
}
}
\ No newline at end of file
diff --git a/server_files/classes/User.php b/server_files/classes/User.php
index d923409..64b3b8a 100644
--- a/server_files/classes/User.php
+++ b/server_files/classes/User.php
@@ -436,7 +436,9 @@ class User
$req = $DB->prepare("INSERT INTO `payments`(`user`, `tournament`, `amount`, `method`, `transaction_infos`, `validation_status`) VALUES (?, ?, ?, ?, ?, ?);");
$req->execute([$this->id, $tournament->getId(), 0, PaymentMethod::getName(PaymentMethod::NOT_PAID), "L'inscription n'est pas encore payée.", ValidationStatus::getName(ValidationStatus::NOT_READY)]);
- }
+
+ return $this->getPayment();
+ }
public function getOrganizedTournaments()
{
diff --git a/server_files/controllers/mon_compte.php b/server_files/controllers/mon_compte.php
index cc32d57..69ec017 100644
--- a/server_files/controllers/mon_compte.php
+++ b/server_files/controllers/mon_compte.php
@@ -3,8 +3,15 @@
if (!isset($_SESSION["user_id"]))
require_once "server_files/403.php";
-/** @var User $user */
+/**
+ * @var User $user
+ * @var Team $team
+ * @var Tournament $tournament
+ */
$user = $_SESSION["user"];
+$team = $_SESSION["team"];
+
+$tournament = Tournament::fromId($team->getTournamentId());
$has_error = false;
$error_message = null;
@@ -33,6 +40,18 @@ if (isset($_POST["update_password"])) {
}
}
+if (isset($_POST["send_document"])) {
+ $send_document = new SendDocument();
+ try {
+ $send_document->makeVerifications();
+ $send_document->sendDocument();
+ }
+ catch (AssertionError $e) {
+ $has_error = true;
+ $error_message = $e->getMessage();
+ }
+}
+
class MyAccount
{
public $email;
@@ -151,4 +170,46 @@ class NewPassword
}
}
+class SendDocument
+{
+ private $file;
+ private $type;
+
+ public function __construct()
+ {
+ $this->file = $_FILES["document"];
+ $this->type = strtoupper(htmlspecialchars($_POST["type"]));
+ }
+
+ public function makeVerifications()
+ {
+ global $LOCAL_PATH;
+
+ ensure($this->file["size"] <= 2e6, "Le fichier doit peser moins que 2 Mo.");
+ ensure(!$this->file["error"], "Une erreur est survenue.");
+ ensure(finfo_file(finfo_open(FILEINFO_MIME_TYPE), $this->file["tmp_name"]) == "application/pdf", "Le fichier doit être au format PDF.");
+ ensure(is_dir("$LOCAL_PATH/files") || mkdir("$LOCAL_PATH/files"), "Un problème est survenue dans l'envoi du fichier. Veuillez contacter l'administrateur du serveur.");
+ }
+
+ public function sendDocument()
+ {
+ global $LOCAL_PATH, $DB, $FINAL;
+
+ do
+ $id = genRandomPhrase(64);
+ while (file_exists("$LOCAL_PATH/files/$id"));
+
+ if (!rename($this->file["tmp_name"], "$LOCAL_PATH/files/$id"))
+ throw new AssertionError("Une erreur est survenue lors de l'envoi du fichier.");
+
+ $req = $DB->prepare("INSERT INTO `documents`(`file_id`, `user`, `team`, `tournament`, `type`)
+ VALUES (?, ?, ?, ?, ?);");
+ $req->execute([$id, $_SESSION["user_id"], $_SESSION["team"]->getId(), $_SESSION["team"]->isSelectedForFinal() ? $FINAL->getId() : $_SESSION["team"]->getTournamentId(), $this->type]);
+ }
+}
+
+$documents = $user->getAllDocuments($team->getTournamentId());
+if ($team->isSelectedForFinal())
+ $documents_final = $user->getAllDocuments($FINAL->getId());
+
require_once "server_files/views/mon_compte.php";
diff --git a/server_files/controllers/mon_equipe.php b/server_files/controllers/mon_equipe.php
index 453b829..45a5088 100644
--- a/server_files/controllers/mon_equipe.php
+++ b/server_files/controllers/mon_equipe.php
@@ -10,18 +10,6 @@ $tournaments = Tournament::getAllTournaments(false, true);
$has_error = false;
$error_message = null;
-if (isset($_POST["send_document"])) {
- $send_document = new SendDocument();
- try {
- $send_document->makeVerifications();
- $send_document->sendDocument();
- }
- catch (AssertionError $e) {
- $has_error = true;
- $error_message = $e->getMessage();
- }
-}
-
if (isset($_POST["team_edit"])) {
$my_team = new MyTeam($_POST);
try {
@@ -57,44 +45,6 @@ if (isset($_SESSION["user_id"]) && isset($_SESSION["team"]) && $_SESSION["team"]
else
require_once "server_files/403.php";
-class SendDocument
-{
- private $file;
- private $type;
-
- public function __construct()
- {
- $this->file = $_FILES["document"];
- $this->type = strtoupper(htmlspecialchars($_POST["type"]));
- }
-
- public function makeVerifications()
- {
- global $LOCAL_PATH;
-
- ensure($this->file["size"] <= 2e6, "Le fichier doit peser moins que 2 Mo.");
- ensure(!$this->file["error"], "Une erreur est survenue.");
- ensure(finfo_file(finfo_open(FILEINFO_MIME_TYPE), $this->file["tmp_name"]) == "application/pdf", "Le fichier doit être au format PDF.");
- ensure(is_dir("$LOCAL_PATH/files") || mkdir("$LOCAL_PATH/files"), "Un problème est survenue dans l'envoi du fichier. Veuillez contacter l'administrateur du serveur.");
- }
-
- public function sendDocument()
- {
- global $LOCAL_PATH, $DB, $FINAL;
-
- do
- $id = genRandomPhrase(64);
- while (file_exists("$LOCAL_PATH/files/$id"));
-
- if (!rename($this->file["tmp_name"], "$LOCAL_PATH/files/$id"))
- throw new AssertionError("Une erreur est survenue lors de l'envoi du fichier.");
-
- $req = $DB->prepare("INSERT INTO `documents`(`file_id`, `user`, `team`, `tournament`, `type`)
- VALUES (?, ?, ?, ?, ?);");
- $req->execute([$id, $_SESSION["user_id"], $_SESSION["team"]->getId(), $_SESSION["team"]->isSelectedForFinal() ? $FINAL->getId() : $_SESSION["team"]->getTournamentId(), $this->type]);
- }
-}
-
class MyTeam
{
public $name;
diff --git a/server_files/controllers/paiement.php b/server_files/controllers/paiement.php
index ae996db..6224f8f 100644
--- a/server_files/controllers/paiement.php
+++ b/server_files/controllers/paiement.php
@@ -13,4 +13,66 @@ $team = $_SESSION["team"];
$tournament = $team->getEffectiveTournament();
$payment = $user->getPayment();
+if (isset($_POST["pay"])) {
+ $pay = new Pay($_POST);
+ try {
+ $pay->makeVerifications();
+ $pay->submit();
+ }
+ catch (AssertionError $e) {
+ $has_error = true;
+ $error_message = $e->getMessage();
+ }
+}
+
+class Pay {
+ private $method;
+ private $infos;
+ private $scholarship;
+
+ public function __construct($data)
+ {
+ foreach ($data as $key => $value)
+ $this->$key = $value;
+
+ $this->method = PaymentMethod::fromName(strtoupper($this->method));
+
+ $this->scholarship = $_FILES["scholarship"];
+ }
+
+ public function makeVerifications()
+ {
+ global $payment;
+
+ ensure($payment->getValidationStatus() == ValidationStatus::NOT_READY, "Un paiement est déjà initié.");
+ ensure($this->method != PaymentMethod::NOT_PAID, "Vous n'avez pas payé.");
+ ensure($this->method == PaymentMethod::SCHOLARSHIP || ($this->infos != null && sizeof($this->infos) > 0), "Merci d'indiquer des informations pour retrouver votre paiement.");
+ ensure($this->method != PaymentMethod::SCHOLARSHIP || ($this->scholarship != null && !$this->scholarship["error"]), "Si vous êtes boursier, vous devez indiquer votre notifcation de bourse (une erreur est survenue).");
+ }
+
+ public function submit()
+ {
+ global $DB, $LOCAL_PATH, $payment, $tournament;
+
+ $payment->setMethod($this->method);
+ $payment->setAmount($this->method == PaymentMethod::SCHOLARSHIP ? 0 : $tournament->getPrice());
+ $payment->setValidationStatus(ValidationStatus::WAITING);
+ if ($this->method == PaymentMethod::SCHOLARSHIP) {
+ do
+ $id = genRandomPhrase(64);
+ while (file_exists("$LOCAL_PATH/files/$id"));
+
+ if (!rename($this->scholarship["tmp_name"], "$LOCAL_PATH/files/$id"))
+ throw new AssertionError("Une erreur est survenue lors de l'envoi du fichier.");
+
+ $req = $DB->prepare("INSERT INTO `documents`(`file_id`, `user`, `team`, `tournament`, `type`)
+ VALUES (?, ?, ?, ?, ?);");
+ $req->execute([$id, $_SESSION["user_id"], $_SESSION["team"]->getId(), $tournament->getId(), DocumentType::getName(DocumentType::SCHOLARSHIP)]);
+ $payment->setTransactionInfos($id);
+ }
+ else
+ $payment->setTransactionInfos($this->infos);
+ }
+}
+
require_once "server_files/views/paiement.php";
\ No newline at end of file
diff --git a/server_files/controllers/view_file.php b/server_files/controllers/view_file.php
index 14aa853..10d4fe4 100644
--- a/server_files/controllers/view_file.php
+++ b/server_files/controllers/view_file.php
@@ -63,6 +63,9 @@ if ($file !== null) {
case DocumentType::SANITARY_PLUG:
$name = "Fiche sanitaire";
break;
+ case DocumentType::SCHOLARSHIP:
+ $name = "Notification de bourse";
+ break;
}
$name .= " de $first_name $surname.pdf";
}
diff --git a/server_files/model.php b/server_files/model.php
index 344ba49..d4122d1 100644
--- a/server_files/model.php
+++ b/server_files/model.php
@@ -175,7 +175,7 @@ function printDocuments($documents)
$user = User::fromId($document->getUserId());
$surname = $user->getSurname();
$first_name = $user->getFirstName();
- $name = "Autorisation de droit à l'image";
+ $name = DocumentType::getTranslatedName($document->getType());
$version = $document->getVersion();
echo "$name de $first_name $surname (version $version) : Télécharger
\n";
}
diff --git a/server_files/views/mon_equipe.php b/server_files/views/mon_equipe.php
index 1546526..a66f0b7 100644
--- a/server_files/views/mon_equipe.php
+++ b/server_files/views/mon_equipe.php
@@ -127,7 +127,15 @@ require_once "header.php";