-
Notifications
You must be signed in to change notification settings - Fork 0
/
upload.php
212 lines (186 loc) · 6.5 KB
/
upload.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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
<?php session_start();
require "admin/config.php";
require "functions.php";
if(!isset($_SESSION["visitor"]) && !isset($_SESSION["admin"]))
{
header("Location: login.php");
}
else if(isset($_SESSION["visitor"]))
{
header("Location: index.php");
}
$conection = conection_to_database($db_config);
if(!$conection)
{
header("Location: error.php");
}
$error = "";
$error_in_debe = "";
$name_error = "";
$months = array("Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octumbre", "Noviembre", "Diciembre");
if($_SERVER["REQUEST_METHOD"] == "POST")
{
// Array que contiene los meses que debe o no debe
$mes_contenedor_pago = array();
$mes_contenedor_debe = array();
// Creo array
for($i = 0; $i < 12; $i++)
{
for($x = 0; $x < 12; $x++)
{
$mes_contenedor_pago[2013 + $i][$months[$x]] = -1;
}
}
for($i = 0; $i < 12; $i++)
{
for($x = 0; $x < 12; $x++)
{
$mes_contenedor_debe[2013 + $i][$months[$x] . "Debe"] = -1;
}
}
// Fill the array
for($i = 0; $i < 12; $i++)
{
$mes_contenedor_pago[2021][$months[$i]] = isset($_POST[$months[$i]]) ? 1 : -1;
}
for($i = 0; $i < 12; $i++)
{
$mes_contenedor_debe[2021][$months[$i] . "Debe"] = isset($_POST[$months[$i] . "Debe"]) ? 0 : -1;
}
$pago = serialize($mes_contenedor_pago);
$debe = serialize($mes_contenedor_debe);
// Pongo un error si debe y no debe al mismo tiempo
for($i = 0; $i < 12; $i++)
{
if($mes_contenedor_pago[2021][$months[$i]] == 1 && $mes_contenedor_debe[2021][$months[$i] . "Debe"] == 0) // Means that the two checkbox are checked
{
$error .= "- Debe y pagó el mismo mes: " . $months[$i] . "<br>";
}
}
// Pongo un error si el name esta vacio
if(empty($_POST["name"]))
{
$error .= "- El nombre no puede estar vacio <br>";
}
// Pongo un error si alguna fecha no esta completa
if(empty($_POST["ingreso_year"]) || empty($_POST["ingreso_month"]) || empty($_POST["ingreso_day"]) || empty($_POST["birth_year"]) || empty($_POST["birth_month"]) || empty($_POST["birth_day"]))
{
$error .= "- Fechas de ingreso y nacimiento tienen que esta completas <br>";
}
// Checkear si ya existe el numero de socio
$statement = $conection->prepare("SELECT * FROM socios WHERE socio_number = :socio_number");
$statement->execute(array("socio_number" => clean_string($_POST["socio"])));
$result = $statement->fetchAll();
if(!empty($result))
{
$error .= "- Numero de socio (" . clean_string($_POST["socio"]) . ") en uso <br>" ;
}
// Añadir Socio si no hay problema
if(empty($error))
{
$orden_number = clean_string($_POST["orden"]);
$socio_number = clean_string($_POST["socio"]);
$name = clean_string($_POST["name"]);
$postal = clean_string($_POST["postal"]);
$ingreso = clean_string($_POST["ingreso_year"]) . "/" . clean_string($_POST["ingreso_month"]) . "/" . clean_string($_POST["ingreso_day"]);
$baja = clean_string($_POST["baja_year"]) . "/" . clean_string($_POST["baja_month"]) . "/" . clean_string($_POST["baja_day"]);
$mail = clean_string($_POST["mail"]);
$cellphone = clean_string($_POST["cellphone"]);
$dni = clean_string($_POST["dni"]);
$birthday = clean_string($_POST["birth_year"]) . "/" . clean_string($_POST["birth_month"]) . "/" . clean_string($_POST["birth_day"]);
$nationality = clean_string($_POST["nationality"]);
$activity = clean_string($_POST["activity"]);
if(!empty($_FILES["torrent_data"]["name"]))
{
$photo = file_get_contents($_FILES["torrent_data"]["tmp_name"]);
$photo_type = $_FILES["torrent_data"]["type"];
$statement = $conection->prepare("INSERT INTO socios
values(
null,
:orden_number,
:socio_number,
:name,
:postal_code,
:ingreso,
:baja,
:email,
:cellphone,
:DNI,
:birth,
:nationality,
:activity,
:pagados,
:debidos,
:photo,
:photo_type
)"
);
$statement->execute(
array(
"orden_number" => $orden_number,
"socio_number" => $socio_number,
"name" => $name,
"postal_code" => $postal,
"ingreso" => $ingreso,
"baja" => $baja,
"email" => $mail,
"cellphone" => $cellphone,
"DNI" => $dni,
"birth" => $birthday,
"nationality" => $nationality,
"activity" => $activity,
"pagados" => $pago,
"debidos" => $debe,
"photo" => $photo,
"photo_type" => $photo_type
)
);
header("Location: index.php");
}
else
{
$statement = $conection->prepare("INSERT INTO socios
values(
null,
:orden_number,
:socio_number,
:name,
:postal_code,
:ingreso,
:baja,
:email,
:cellphone,
:DNI,
:birth,
:nationality,
:activity,
:pagados,
:debidos,
null,
null
)"
);
$statement->execute(
array(
"orden_number" => $orden_number,
"socio_number" => $socio_number,
"name" => $name,
"postal_code" => $postal,
"ingreso" => $ingreso,
"baja" => $baja,
"email" => $mail,
"cellphone" => $cellphone,
"DNI" => $dni,
"birth" => $birthday,
"nationality" => $nationality,
"activity" => $activity,
"pagados" => $pago,
"debidos" => $debe
)
);
header("Location: index.php");
}
}
}
require "view/upload.view.php";
?>