This repository has been archived by the owner on Mar 26, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ajoutPersonne.php
116 lines (109 loc) · 3.36 KB
/
ajoutPersonne.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
<?php
/**
* Empêcher création de deux mec du même nom
* protéger première requête
*/
$title = "Ajout d'une Personne" ;
include 'includes/header.php' ;
if(!isset($_POST['nom']) && !isset($_POST['prenom'])){
include 'includes/Formulaires/ajoutKarateka.php';
} else {
$erreur = verifier_arguments(['nom','prenom']);
if( isset($_POST['is_karateka']) ){
$erreur.= verifier_arguments(['poids','taille','ceinture']);
if($_POST['ceinture'] == 'black'){
$erreur.= verifier_arguments(['dans']);
} else {
$_POST['dans'] == 0;
}
if ( isset($_FILES['photo']) ) {
//vérification de la photo
$fichier = basename($_FILES['photo']['name']);
$taille_maxi = 100000;
$taille = filesize($_FILES['photo']['tmp_name']);
$extensions = array('.png', '.gif', '.jpg', '.jpeg');
$extension = strrchr($_FILES['photo']['name'], '.');
//Début des vérifications de sécurité...
if(!in_array($extension, $extensions)) //Si l'extension n'est pas dans le tableau
{
$erreur .= 'Vous devez uploader un fichier de type png, gif, jpg.<br />';
}
if($taille>$taille_maxi)
{
$erreur .= 'Le fichier est trop gros... <br />';
}
} else {
$erreur .= 'Photo obligatoire <br />';
}
} elseif ( isset($_POST['is_dirigeant']) ) {
$erreur .= verifier_arguments(['email','tel']) ;
} else {
$erreur .= 'Une Personne ne peut pas être ni dirigeante ni Karatéka';
}
if($erreur){
echo $erreur;
include 'includes/Formulaires/ajoutKarateka.php';
} else {
echo "insertion d'une personne...";
$vConnect = Connect();
$request = 'INSERT INTO person (firstname, lastname)
VALUES (\''.$_POST['prenom'].'\', \''.$_POST['nom'].'\')
RETURNING id;' ;
if( !($result = pg_query($vConnect, $request)) ) {
echo pg_last_error() ;
exit();
}
$id_personne = pg_fetch_array($result, null, PGSQL_ASSOC);
$id_personne = $id_personne['id'];
echo "ok ! <br />" ;
if ( isset($_POST['is_dirigeant']) ) {
echo "insertion d'un dirigeant... ";
$array = [
'id' => $id_personne,
'mail' => $_POST['email'],
'phone' => $_POST['tel']
] ;
if ( !pg_insert( $vConnect, 'leader', $array) ) {
echo pg_last_error();
exit();
}
echo "ok ! <br />" ;
}
if ( isset($_POST['is_karateka']) ) {
echo "insertion d'un karateka...";
//On formate le nom du fichier ici...
$fichier = strtr($fichier,
'ÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÒÓÔÕÖÙÚÛÜÝàáâãäåçèéêëìíîïðòóôõöùúûüýÿ',
'AAAAAACEEEEIIIIOOOOOUUUUYaaaaaaceeeeiiiioooooouuuuyy');
$fichier = preg_replace('/([^.a-z0-9]+)/i', '-', $fichier);
$emplacement = 'photo_karateka/'.time().$fichier;
if(move_uploaded_file($_FILES['photo']['tmp_name'], $emplacement))
{
echo 'Upload effectué avec succès !';
} else //Sinon (la fonction renvoie FALSE).
{
echo 'Echec de l\'upload !';
exit();
}
$array = [
'id' => $id_personne,
'urlphoto' => $emplacement,
'weight' => $_POST['poids'],
'height' => $_POST['taille'],
'belt' => $_POST['ceinture'],
'dans' => $_POST['dans']
] ;
if(isset($_POST['is_teacher'])){
$array['teacher'] = true;
} else {
$array['teacher'] = false;
}
if ( !pg_insert( $vConnect, 'karateka', $array) ) {
echo pg_last_error();
exit();
}
echo "ok ! <br />" ;
}
pg_close($vConnect);
}
}