Skip to content

Commit

Permalink
ajout de l'enregistrement de site
Browse files Browse the repository at this point in the history
  • Loading branch information
Natouille04 committed Oct 9, 2024
1 parent 100b1f2 commit 751c100
Show file tree
Hide file tree
Showing 5 changed files with 153 additions and 25 deletions.
1 change: 1 addition & 0 deletions .idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

82 changes: 78 additions & 4 deletions assets/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ h1, img {
margin: 0;
}

h2 {
text-align: center;
}

#titre {
display: flex;

Expand All @@ -38,22 +42,23 @@ main {
width: 100%;

display: flex;
justify-content: center;
flex-direction: column;
align-items: center;
}

.projects-list {
.projects-list, .registered-sites {
width: 95%;
height: 100%;

margin: 25px;

display: flex;
flex-wrap: wrap;
justify-content: space-between;
justify-content: center;
}

.project {
width: 20%;
width: 15%;
height: 20vh;

min-width: 150px;
Expand Down Expand Up @@ -85,4 +90,73 @@ main {

.button {
background-color: ;
}

hr {
width: 80%;
}

.site {
width: 15%;
height: 13vh;

min-width: 150px;
min-height: 100px;

display: flex;
flex-direction: column;
justify-content: center;

margin: 25px;

background-color: #3b3b3b;

text-align: center;

border: solid 2px white;
border-radius: 15px;
}

.site h2 {
margin: 20px;
}

.form-hr {
width: 40%;
}

form {
width: 100%;

display: flex;
flex-direction: column;
align-items: center;
}

form input {
width: 30%;
height: 5vh;

margin: 5px 0px;
}

form input[type="text"] {
color: white;
background-color: #1f1f1f;

outline : none;

border: none;
border-bottom: solid white 1px;
}

form input[type=submit] {
width: 15%;

font-size: 1em;

border: none;
border-radius: 5px;

margin: 25px 0px 10px 0px;
}
3 changes: 3 additions & 0 deletions assets/data/data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[

]
91 changes: 71 additions & 20 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,91 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="assets/css/style.css" rel="stylesheet">

<link rel="icon" type="image/x-icon" href="assets/img/favicon.ico">

<title>Project.PHP</title>
</head>

<body>
<header>
<?php echo "<div id='titre'><h1>Projects.</h1><img src='assets/img/PHP-logo.svg.png' alt='logo php' class='logo-php'></div>" ?>
<header>
<?php echo "<div id='titre'><h1>Projects.</h1><img src='assets/img/PHP-logo.svg.png' alt='logo php' class='logo-php'></div>" ?>
<p>Bienvenue sur Projects.php</p>
<a href="project">Mes Projet PHP</a>
</header>

<p>Bienvenue sur Projects.php</p>
<main>

<a href="project">Mes Projet PHP</a>
<div class="projects-list">
<?php
$scandir = scandir("project");
foreach ($scandir as $fichier) {
if ($fichier !== '.' && $fichier !== '..' && is_dir("project/$fichier")) {
echo "<div class='project'>";
echo "<div><h2>$fichier</h2></div>";
echo "<div class='button'><a href='project/$fichier'>Acceder</a></div>";
echo "</div>";
}
}
?>
</div>

</header>
<hr>

<main>
<div class="projects-list">
<h2>Sites enregistrés</h2>

<?php
$scandir = scandir("project");
foreach ($scandir as $fichier) {
if ($fichier !== '.' && $fichier !== '..' && is_dir("project/$fichier")) {
echo "<div class='project'>";
echo "<div><h2>$fichier</h2></div>";
echo "<div class='button'><a href='project/$fichier'>Acceder</a></div>";
<div class="registered-sites">
<?php
$jsonFile = 'assets/data/data.json';
if (file_exists($jsonFile)) {
$jsonData = file_get_contents($jsonFile);
$data = json_decode($jsonData, true);
if (!empty($data)) {
foreach ($data as $site) {
echo "<div class='site'>";
echo "<h2>" . htmlspecialchars($site['name']) . "</h2>";
echo "<a href='" . htmlspecialchars($site['url']) . "'>" . htmlspecialchars($site['url']) . "</a>";
echo "</div>";
}
} else {
echo "<p>Aucun site enregistré.</p>";
}
?>
} else {
echo "<p>Le fichier de données n'existe pas.</p>";
}
?>
</div>

<hr class="form-hr">

<form action="" method="POST">
<h2>Ajouté un site</h2>
<input type="text" name="name" placeholder="Nom" required>
<input type="text" name="url" placeholder="URL" required>
<input type="submit" value="Ajouté">
</form>

<hr class="form-hr">

</div>
</main>
</main>

<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$name = $_POST['name'];
$url = $_POST['url'];
$formData = array(
'name' => $name,
'url' => $url
);
if (file_exists($jsonFile)) {
$jsonData = file_get_contents($jsonFile);
$data = json_decode($jsonData, true);
} else {
$data = array();
}
$data[] = $formData;
$newJsonData = json_encode($data, JSON_PRETTY_PRINT);
file_put_contents($jsonFile, $newJsonData);
}
?>
</body>

</html>
</html>

0 comments on commit 751c100

Please sign in to comment.