-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnew.php
executable file
·144 lines (114 loc) · 4.26 KB
/
new.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<?php
require 'inc/Autoloader.php';
if (empty(Session::getInstance()->read('id'))) {
Session::getInstance()->setFlash('danger', 'Vous devez être connecté');
App::redirect('signin.php');
}
if (!empty($_POST) && !empty($_FILES)) {
$db = App::getDatabase();
$errors = [];
if (!empty($_POST['title']) && !empty($_POST['description']) && !empty($_FILES['img'])) {
$Auth = new Auth;
$session_id = Session::getInstance()->read('id');
$name_file = $_FILES['img']['name'];
$name_extension = strrchr($name_file, ".");
$extensions_autorisation = array('.png', '.PNG', '.jpg', '.JPG', '.jpeg', '.JPEG');
$file_tmp_name = $_FILES['img']['tmp_name'];
$file_dest = 'uploads/' . $name_file;
$date = date("Y-m-d H:i:s");
if($Auth->insertNewAnnounceData($db,$date,$session_id,$name_extension,$extensions_autorisation,$file_dest,$file_tmp_name)){
Session::getInstance()->setFlash('success', 'L\'Annonce a été crée avec succés');
App::redirect('my.php');
}
else {
$errors['img'] = "Pour l'image seuls les extensions PNG , JPG ou JPG sont autorisées";
}
} else {
$errors[] = "Tous les champs doivent être remplis";
}
}
?>
<?php include 'layouts/login_header.html';?>
<title>Nouvel Appel | We-Share</title>
<style>
html,body {
height: 100%;
}
body {
display: flex;
align-items: center;
padding-top: 40px;
padding-bottom: 40px;
background-color: #f5f5f5;
}
img{ width: 200px; height: 200px;}
.form-signin-signup {
width: 100%;
max-width: 55%;
padding: 15px;
margin: auto;
}
.form-signin-signup .form-control {
position: relative;
box-sizing: border-box;
height: auto;
padding: 10px;
font-size: 16px;
}
.form-signin-signup .form-select {
position: relative;
box-sizing: border-box;
height: auto;
padding: 10px;
font-size: 16px;
}
.form-signin-signup .form-control:focus {
z-index: 2;
}
.form-signin-signup input[type="text"] {
margin-bottom: 10px;
border-radius: 5px;
}
.form-signin-signup input[type="email"] {
margin-bottom: 10px;
border-radius: 5px;
}
.form-signin-signup input[type="file"] {
margin-bottom: 10px;
border-radius: 5px;
}
textarea {
margin-bottom: 10px;
border-radius: 5px;
}
.form-signin-signup button{
max-width: 40%;
}
</style>
</head>
<body class="text-center">
<main class="form-signin-signup">
<form action="" method="POST" enctype="multipart/form-data">
<img class="mb-4 rounded-circle" src="assets/images/We-Share-logo.png" alt="" width="72" height="57">
<h1 class="h3 mb-3 fw-normal">Nouvel Appel</h1>
<!-- errors controle -->
<?php if (!empty($errors)): ?>
<div class="alert alert-danger">
<p>Votre nouvelle annonce a connu des problèmes lors de la création :</p>
<?php foreach ($errors as $error): ?>
<div><?=$error;?></div>
<?php endforeach;?>
</div>
<?php endif;?>
<label for="inputEmail" class="visually-hidden">Choisissez un titre convenable</label>
<input type="text" id="inputEmail" name="title" class="form-control" placeholder="Choisissez un titre convenable" required autofocus>
<label class="form-label visually-hidden" for="customFile">Choisissez une image pour votre annonce</label>
<input type="file" class="form-control" name ="img" id="customFile" placeholder="Choisissez une image pour votre annonce" required/>
<label for="InputDiscription" class="form-label visually-hidden">Choisissez une description convenable</label>
<textarea type="text" name ="description" class="form-control" id="InputDiscription" placeholder="Choisissez une description convenable" rows="6" cols="50" required></textarea>
<button class="w-100 btn btn-lg btn-primary" type="submit">Ajouter</button>
<p class="mt-5 mb-3 text-muted">© We Share 2021</p>
</form>
</main>
</body>
</html>