Skip to content
Snippets Groups Projects
Commit 3b031e4f authored by user's avatar user
Browse files

Activite3

parent 76847c97
Branches
No related tags found
No related merge requests found
<?php
declare(strict_types=1);
class Auteur {
private String $lastName;
private String $firstName;
private DateTime $birthDate;
private array $citations;
public function __construct(string $lastName, String $firstName, DateTime $birthDate) {
$this->lastName = $lastName;
$this->firstName = $firstName;
$this->birthDate = $birthDate;
$this->citations = [];
}
public function getLastName(): String {
return $this->lastName;
}
public function getFirstName(): String {
return $this->firstName;
}
public function getBirthDate(): DateTime {
return $this->birthDate;
}
public function getCitations(): array {
return $this->citations;
}
public function addCitation(Citation $citation): void {
$this->citations[] = $citation;
}
}
\ No newline at end of file
<?php
declare(strict_types=1);
class Citation {
private String $content;
private Auteur $writer;
private DateTime $entryDate;
public function __construct (String $content, Auteur $auteur, DateTime $entryDate) {
$this-> content = $content;
$this->writer = $auteur;
$this->entryDate = $entryDate;
}
public function getContent(): String {
return $this->content;
}
public function getWriter(): Auteur {
return $this->writer;
}
public function getEntryDate(): DateTime {
return $this->entryDate;
}
}
\ No newline at end of file
<?php
declare(strict_types=1);
class Website {
private array $writers;
private array $citations;
public function __construct() {
$this->writers = [];
$this->citations = [];
}
public function addCitation(Citation $citation): void {
$this->citations[] = $citation;
$auteur = $citation->getWriter();
$auteur->addCitation($citation);
}
public function ajouterAuteur(Auteur $auteur): void {
$this->writers[] = $auteur;
}
public function getAuteurs(): array {
return $this->writers;
}
public function getCitations(): array {
return $this->citations;
}
}
\ No newline at end of file
<!DOCTYPE html>
<html lang="fr">
<head>
<title>ajout de citation </title>
<meta charset="UTF-8">
</head>
<body>
<main>
<article>
<header><h1>Formaire de création de citations</h1></header>
<form method="post" name="FrameCitation" action="viewCitation.php">
<table border="1" bgcolor="#ccccff" frame="above">
<tbody>
<tr>
<th><label for="login">Login</label></th>
<td><input name="login" maxlength="64" size="32"></td>
</tr>
<tr>
<th><label for="citation">Citation</label></th>
<td><textarea cols="128" rows="5" name="citation"></textarea></td>
</tr>
<tr>
<th><label for="auteur">Auteur</label></th>
<td><input name="auteur" maxlength="128" size="64"></td>
</tr>
<!-- Ajout de la ligne pour saisir la date de la citation -->
<tr>
<th><label for="date">Date de la citation</label></th>
<td><input name="date" type="date" value="<?php echo date('Y-m-d'); ?>"></td>
</tr>
<tr>
<td colspan="2" align="center">
<input name="Envoyer" value="Enregistrer la citation" type="submit">
<input name="Effacer" value="Annuler" type="reset">
</td>
</tr>
</tbody>
</table>
</form>
</article>
</main>
</body>
</html>
<?php
function getCurrentPageURL() {
$protocol = strpos(strtolower($_SERVER['SERVER_PROTOCOL']),'https') === false ? 'http' : 'https';
$host = $_SERVER['HTTP_HOST'];
$script = $_SERVER['SCRIPT_NAME'];
$params = $_SERVER['QUERY_STRING'];
$currentURL = $protocol . '://' . $host . $script;
if (!empty($params)) {
$currentURL .= '?' . $params;
}
return $currentURL;
}
$errorMessage = "";
$login = $citation = $auteur = $date = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$login = $_POST["login"];
$citation = $_POST["citation"];
$auteur = $_POST["auteur"];
$date = $_POST["date"];
// Vérifier si les champs obligatoires ne sont pas vides
if (empty($login) || empty($citation)) {
$errorMessage = "Les champs Login et Citation ne peuvent pas être vides.";
} else {
// Votre logique de traitement des données ici (enregistrement, validation, etc.)
}
}
?>
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<title>Ajout de Citation</title>
<style>
table {
border: 1px solid #ccccff;
width: 100%;
}
th, td {
padding: 8px;
text-align: left;
}
th {
background-color: #ccccff;
}
.error-message {
color: red;
}
</style>
</head>
<body>
<main>
<article>
<header><h1>Formulaire de création de citations</h1></header>
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST" && empty($errorMessage)) {
echo "<p>Citation enregistrée avec succès :</p>";
echo "<p><strong>Login:</strong> $login</p>";
echo "<p><strong>Citation:</strong> $citation</p>";
echo "<p><strong>Auteur:</strong> $auteur</p>";
echo "<p><strong>Date:</strong> $date</p>";
} else {
echo "<p class='error-message'>$errorMessage</p>";
}
?>
<form method="post" name="FrameCitation" action="<?php echo getCurrentPageURL(); ?>">
<table>
<tbody>
<tr>
<th><label for="login">Login</label></th>
<td><input name="login" maxlength="64" size="32" value="<?php echo htmlspecialchars($login); ?>"></td>
<td><?php echo ($errorMessage && empty($login)) ? "Le champ Login ne peut pas être vide." : ""; ?></td>
</tr>
<tr>
<th><label for="citation">Citation</label></th>
<td><textarea cols="128" rows="5" name="citation"><?php echo htmlspecialchars($citation); ?></textarea></td>
<td><?php echo ($errorMessage && empty($citation)) ? "Le champ Citation ne peut pas être vide." : ""; ?></td>
</tr>
<tr>
<th><label for="auteur">Auteur</label></th>
<td><input name="auteur" maxlength="128" size="64" value="<?php echo htmlspecialchars($auteur); ?>"></td>
<td></td>
</tr>
<tr>
<th><label for="date">Date</label></th>
<td><input name="date" type="date" value="<?php echo htmlspecialchars($date ? $date : date('Y-m-d')); ?>"></td>
<td></td>
</tr>
<tr>
<td colspan="3" align="center">
<input name="Envoyer" value="Enregistrer la citation" type="submit">
<input name="Effacer" value="Annuler" type="reset">
</td>
</tr>
</tbody>
</table>
</form>
</article>
</main>
</body>
</html>
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<title>Vue de la Citation</title>
</head>
<body>
<main>
<article>
<header><h1>Citation enregistrée</h1></header>
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$login = $_POST["login"];
$citation = $_POST["citation"];
$auteur = $_POST["auteur"];
$date = $_POST["date"];
echo "<p><strong>Login:</strong> $login</p>";
echo "<p><strong>Citation:</strong> $citation</p>";
echo "<p><strong>Auteur:</strong> $auteur</p>";
echo "<p><strong>Date:</strong> $date</p>";
} else {
echo "<p>Erreur lors de la soumission du formulaire.</p>";
}
?>
</article>
</main>
</body>
</html>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment