mirror of
				https://gitlab.com/animath/si/plateforme.git
				synced 2025-11-04 09:42:10 +01:00 
			
		
		
		
	Support des lettres de motivation
This commit is contained in:
		@@ -271,6 +271,7 @@ class DocumentType
 | 
			
		||||
	const SOLUTION = 3;
 | 
			
		||||
	const SYNTHESIS = 4;
 | 
			
		||||
	const SCHOLARSHIP = 5;
 | 
			
		||||
	const MOTIVATION_LETTER = 6;
 | 
			
		||||
 | 
			
		||||
	public static function getTranslatedName($type) {
 | 
			
		||||
		switch ($type) {
 | 
			
		||||
@@ -282,6 +283,8 @@ class DocumentType
 | 
			
		||||
				return "Fiche sanitaire";
 | 
			
		||||
            case self::SCHOLARSHIP:
 | 
			
		||||
                return "Notification de bourse";
 | 
			
		||||
			case self::MOTIVATION_LETTER:
 | 
			
		||||
				return "Lettre de motivation";
 | 
			
		||||
			case self::SOLUTION:
 | 
			
		||||
				return "Solution";
 | 
			
		||||
			default:
 | 
			
		||||
@@ -299,6 +302,8 @@ class DocumentType
 | 
			
		||||
				return "SANITARY_PLUG";
 | 
			
		||||
            case self::SCHOLARSHIP:
 | 
			
		||||
                return "SCHOLARSHIP";
 | 
			
		||||
			case self::MOTIVATION_LETTER:
 | 
			
		||||
				return "MOTIVATION_LETTER";
 | 
			
		||||
			case self::SOLUTION:
 | 
			
		||||
				return "SOLUTION";
 | 
			
		||||
			default:
 | 
			
		||||
@@ -316,6 +321,8 @@ class DocumentType
 | 
			
		||||
				return self::SANITARY_PLUG;
 | 
			
		||||
            case "SCHOLARSHIP":
 | 
			
		||||
                return self::SCHOLARSHIP;
 | 
			
		||||
			case "MOTIVATION_LETTER":
 | 
			
		||||
				return self::MOTIVATION_LETTER;
 | 
			
		||||
			case "SOLUTION":
 | 
			
		||||
				return self::SOLUTION;
 | 
			
		||||
			default:
 | 
			
		||||
 
 | 
			
		||||
@@ -435,6 +435,17 @@ class User
 | 
			
		||||
		while (($data = $req->fetch()) !== false)
 | 
			
		||||
			$docs[] = Document::fromData($data);
 | 
			
		||||
 | 
			
		||||
		if ($this->team_id > 0) {
 | 
			
		||||
			$req = $DB->query("SELECT * FROM `documents` AS `t1` "
 | 
			
		||||
				. "INNER JOIN (SELECT `user`, `type`, `tournament`, MAX(`uploaded_at`) AS `last_upload`, COUNT(`team`) AS `version` FROM `documents` GROUP BY `tournament`, `type`, `user`) `t2` "
 | 
			
		||||
				. "ON `t1`.`user` = `t2`.`user` AND `t1`.`type` = `t2`.`type` AND `t1`.`tournament` = `t2`.`tournament` "
 | 
			
		||||
				. "WHERE `t1`.`uploaded_at` = `t2`.`last_upload` AND `t1`.`tournament` = $tournament_id AND `t1`.`team` = $this->team_id "
 | 
			
		||||
				. "AND `t1`.`type` = 'MOTIVATION_LETTER';");
 | 
			
		||||
 | 
			
		||||
			while (($data = $req->fetch()) !== false)
 | 
			
		||||
				$docs[] = Document::fromData($data);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		return $docs;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -205,7 +205,8 @@ class SendDocument
 | 
			
		||||
 | 
			
		||||
        $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]);
 | 
			
		||||
        $req->execute([$id, $this->type == DocumentType::getName(DocumentType::MOTIVATION_LETTER) ? -1 : $_SESSION["user_id"], $_SESSION["team"]->getId(),
 | 
			
		||||
			$_SESSION["team"]->isSelectedForFinal() ? $FINAL->getId() : $_SESSION["team"]->getTournamentId(), $this->type]);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -48,11 +48,11 @@ if ($file !== null) {
 | 
			
		||||
		$user = User::fromId($file->getUserId());
 | 
			
		||||
		$type = $file->getType();
 | 
			
		||||
 | 
			
		||||
		if (($_SESSION["role"] == Role::PARTICIPANT || $_SESSION["role"] == Role::ENCADRANT) && $user->getId() != $_SESSION["user_id"])
 | 
			
		||||
			require_once "server_files/403.php";
 | 
			
		||||
		if (($_SESSION["role"] == Role::PARTICIPANT || $_SESSION["role"] == Role::ENCADRANT)) {
 | 
			
		||||
			if ($type != DocumentType::MOTIVATION_LETTER && $user->getId() != $_SESSION["user_id"] || $file->getTeamId() != $team->getId())
 | 
			
		||||
				require_once "server_files/403.php";
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		$surname = $user->getSurname();
 | 
			
		||||
		$first_name = $user->getFirstName();
 | 
			
		||||
		switch ($type) {
 | 
			
		||||
			case DocumentType::PARENTAL_CONSENT:
 | 
			
		||||
				$name = "Autorisation parentale";
 | 
			
		||||
@@ -67,7 +67,13 @@ if ($file !== null) {
 | 
			
		||||
                $name = "Notification de bourse";
 | 
			
		||||
                break;
 | 
			
		||||
		}
 | 
			
		||||
		$name .= " de $first_name $surname.pdf";
 | 
			
		||||
		if ($type == DocumentType::MOTIVATION_LETTER)
 | 
			
		||||
			$name = "Lettre de motivation de l'équipe $trigram.pdf";
 | 
			
		||||
		else {
 | 
			
		||||
			$surname = $user->getSurname();
 | 
			
		||||
			$first_name = $user->getFirstName();
 | 
			
		||||
			$name .= " de $first_name $surname.pdf";
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
else
 | 
			
		||||
 
 | 
			
		||||
@@ -136,6 +136,7 @@ function canValidate(Team $team, Tournament $tournament)
 | 
			
		||||
		$d = $req->fetch();
 | 
			
		||||
		$can_validate &= $d["version"] > 0;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	for ($i = 1; $i <= 6; ++$i) {
 | 
			
		||||
		if ($team->getParticipants()[$i] === NULL)
 | 
			
		||||
			continue;
 | 
			
		||||
@@ -159,6 +160,11 @@ function canValidate(Team $team, Tournament $tournament)
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	$req = $DB->prepare("SELECT COUNT(*) AS `version` FROM `documents` WHERE `team` = ? AND `tournament` = ? AND `type` = ?;");
 | 
			
		||||
	$req->execute([$team->getId(), $tournament->getId(), "MOTIVATION_LETTER"]);
 | 
			
		||||
	$d = $req->fetch();
 | 
			
		||||
	$can_validate &= $d["version"] > 0;
 | 
			
		||||
 | 
			
		||||
	return $can_validate;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -172,12 +178,20 @@ function printDocuments($documents)
 | 
			
		||||
	echo "<div class=\"alert alert-info\">\n";
 | 
			
		||||
	foreach ($documents as $document) {
 | 
			
		||||
		$file_id = $document->getFileId();
 | 
			
		||||
		$user = User::fromId($document->getUserId());
 | 
			
		||||
		$surname = $user->getSurname();
 | 
			
		||||
		$first_name = $user->getFirstName();
 | 
			
		||||
		$name = DocumentType::getTranslatedName($document->getType());
 | 
			
		||||
		$version = $document->getVersion();
 | 
			
		||||
		echo "$name de $first_name $surname (version $version) : <a href=\"/file/$file_id\"><strong>Télécharger</strong></a><br />\n";
 | 
			
		||||
		if ($document->getType() == DocumentType::MOTIVATION_LETTER) {
 | 
			
		||||
			$team = Team::fromId($document->getTeamId());
 | 
			
		||||
			echo "Lettre de motivation de l'équipe " . $team->getTrigram();
 | 
			
		||||
		}
 | 
			
		||||
		else {
 | 
			
		||||
			$user = User::fromId($document->getUserId());
 | 
			
		||||
			$surname = $user->getSurname();
 | 
			
		||||
			$first_name = $user->getFirstName();
 | 
			
		||||
			echo "$name de $first_name $surname";
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		echo " (version $version) : <a href=\"/file/$file_id\"><strong>Télécharger</strong></a><br />\n";
 | 
			
		||||
	}
 | 
			
		||||
	echo "</div>\n";
 | 
			
		||||
}
 | 
			
		||||
@@ -228,6 +242,12 @@ function getZipFile($document_type, $tournament_id, $team_id = -1)
 | 
			
		||||
					case DocumentType::PHOTO_CONSENT:
 | 
			
		||||
						$name = "Autorisation de droit à l'image de " . $user->getFirstName() . " " . $user->getSurname() . ".pdf";
 | 
			
		||||
						break;
 | 
			
		||||
					case DocumentType::SCHOLARSHIP:
 | 
			
		||||
						$name = "Notification de bourse de " . $user->getFirstName() . " " . $user->getSurname()  . ".pdf";
 | 
			
		||||
						break;
 | 
			
		||||
					case DocumentType::MOTIVATION_LETTER:
 | 
			
		||||
						$name = "Lettre de motivation de l'équipe " . $team->getTrigram() . ".pdf";
 | 
			
		||||
						break;
 | 
			
		||||
					default:
 | 
			
		||||
						$name = "Fiche sanitaire de " . $user->getFirstName() . " " . $user->getSurname() . ".pdf";
 | 
			
		||||
						break;
 | 
			
		||||
 
 | 
			
		||||
@@ -227,6 +227,7 @@ if (!$has_error && (isset($my_account) || isset($new_password))) {
 | 
			
		||||
                        <?php } ?>
 | 
			
		||||
                        <option value="photo_consent">Autorisation de droit à l'image</option>
 | 
			
		||||
                        <option value="sanitary_plug">Fiche sanitaire</option>
 | 
			
		||||
                        <option value="motivation_letter">Lettre de motivation (pour toute l'équipe)</option>
 | 
			
		||||
                    </select>
 | 
			
		||||
                </div>
 | 
			
		||||
            </div>
 | 
			
		||||
 
 | 
			
		||||
@@ -115,7 +115,7 @@ require_once "header.php";
 | 
			
		||||
            <div class="alert alert-warning">
 | 
			
		||||
                Pour demander à valider votre équipe, vous devez avoir au moins un encadrant, quatre participants,
 | 
			
		||||
                choisi un problème et soumis une autorisation de droit à l'image, une fiche sanitaire et une autorisation
 | 
			
		||||
                parentale (si besoin) par participant.
 | 
			
		||||
                parentale (si besoin) par participant, ainsi qu'une lettre de motivation à transmettre aux organisateurs.
 | 
			
		||||
            </div>
 | 
			
		||||
		<?php } ?>
 | 
			
		||||
	<?php }
 | 
			
		||||
 
 | 
			
		||||
@@ -23,7 +23,7 @@ if ($payment->getValidationStatus() == ValidationStatus::NOT_READY) { ?>
 | 
			
		||||
    <div class="alert alert-info">
 | 
			
		||||
        <form method="POST" enctype="multipart/form-data">
 | 
			
		||||
            <label for="method"><strong>Mode de paiement :</strong></label>
 | 
			
		||||
            <select class="custom-select" id="method" name="method">
 | 
			
		||||
            <select class="custom-select" id="method" name="method" onchange="displayInfos()">
 | 
			
		||||
                <?php
 | 
			
		||||
                for ($method = PaymentMethod::NOT_PAID; $method <= PaymentMethod::SCHOLARSHIP; ++$method) {
 | 
			
		||||
                    if ($method == PaymentMethod::CASH || $method == PaymentMethod::BANK_CHECK)
 | 
			
		||||
@@ -32,13 +32,39 @@ if ($payment->getValidationStatus() == ValidationStatus::NOT_READY) { ?>
 | 
			
		||||
                    <option value="<?= strtolower(PaymentMethod::getName($method)) ?>"><?= PaymentMethod::getTranslatedName($method) ?></option>
 | 
			
		||||
                <?php } ?>
 | 
			
		||||
            </select>
 | 
			
		||||
            <label for="infos"><strong>Informations sur le paiement :</strong></label>
 | 
			
		||||
            <label id="infos_label" for="infos"><strong>Informations sur le paiement :</strong></label>
 | 
			
		||||
            <textarea class="form-control" name="infos" id="infos"></textarea>
 | 
			
		||||
            <label for="scholarship"><strong>Notification de bourse :</strong></label>
 | 
			
		||||
            <label id="scholarship_label" for="scholarship"><strong>Notification de bourse :</strong></label>
 | 
			
		||||
            <input type="file" class="form-control" name="scholarship" id="scholarship" />
 | 
			
		||||
            <input class="btn btn-primary btn-block" type="submit" name="pay" value="Envoyer" />
 | 
			
		||||
        </form>
 | 
			
		||||
    </div>
 | 
			
		||||
 | 
			
		||||
    <script>
 | 
			
		||||
        function displayInfos() {
 | 
			
		||||
            console.log("value = " + document.getElementById("method").value);
 | 
			
		||||
            switch (document.getElementById("method").value) {
 | 
			
		||||
                case "scholarship":
 | 
			
		||||
                    document.getElementById("scholarship_label").style.display = "block";
 | 
			
		||||
                    document.getElementById("scholarship").style.display = "block";
 | 
			
		||||
                    document.getElementById("scholarship").require = "true";
 | 
			
		||||
                    document.getElementById("infos_label").style.display = "none";
 | 
			
		||||
                    document.getElementById("infos").style.display = "none";
 | 
			
		||||
                    document.getElementById("infos").require = "false";
 | 
			
		||||
                    break;
 | 
			
		||||
                default:
 | 
			
		||||
                    document.getElementById("scholarship_label").style.display = "none";
 | 
			
		||||
                    document.getElementById("scholarship").style.display = "none";
 | 
			
		||||
                    document.getElementById("scholarship").require = "false";
 | 
			
		||||
                    document.getElementById("infos_label").style.display = "block";
 | 
			
		||||
                    document.getElementById("infos").style.display = "block";
 | 
			
		||||
                    document.getElementById("infos").require = "true";
 | 
			
		||||
                    break;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        displayInfos();
 | 
			
		||||
    </script>
 | 
			
		||||
<?php } else {
 | 
			
		||||
    if ($payment->getValidationStatus() == ValidationStatus::WAITING) { ?>
 | 
			
		||||
        <div class="alert alert-warning">
 | 
			
		||||
@@ -62,6 +88,7 @@ if ($payment->getValidationStatus() == ValidationStatus::NOT_READY) { ?>
 | 
			
		||||
            <strong>Informations sur le paiement :</strong> <?= $payment->getTransactionInfos() ?><br />
 | 
			
		||||
        <?php } ?>
 | 
			
		||||
    </div>
 | 
			
		||||
 | 
			
		||||
<?php }
 | 
			
		||||
 | 
			
		||||
require_once "footer.php";
 | 
			
		||||
		Reference in New Issue
	
	Block a user