-
Notifications
You must be signed in to change notification settings - Fork 0
/
addfollowed.php
222 lines (212 loc) · 7.73 KB
/
addfollowed.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
213
214
215
216
217
218
219
220
221
222
<?php
session_start();
if (!isset($_SESSION['login'], $_SESSION['idstaff']) ||
$_SESSION['login'] == 'admin') { // Get through login?
header('Location: login.php'); // sinon retour page login
exit();
}
if (isset($_COOKIE['lang'])) {
$lang = $_COOKIE['lang'];
} else {
// si aucune langue n'est déclaré, la langue par default est l'anglais
$lang = 'en';
}
// fichier de langue a importer
if ($lang=='fr') { // si la langue est 'fr' (français) on inclut le fichier (...)_fr_FR.php
include('i18n/fr_FR/addfollowed_fr_FR.php');
} elseif ($lang=='en') { // si la langue est 'en' (anglais) on inclut le fichier (...)_en_GB.php
include('i18n/en_UK/addfollowed_en_UK.php');
}
include "script/db.php";
include "script/form_func.php";
include "head.php";
$id_biname = array();
$lines = get_values(
'idSpecies, binomial_name',
'Species',
array('orderby' => 'binomial_name')
);
foreach ($lines as $line) {
$id_biname[$line['idSpecies']] = $line['binomial_name'];
}
$lines = get_values('idFacility, name', 'Facility', array('orderby' => 'name'));
$id_faname = array();
foreach ($lines as $line) {
$id_faname[$line['idFacility']] = $line['name'];
}
// If form info, fill database
if (isset($_POST['species'])) {
//Check values
$valid = true;
foreach (array('facility', 'species') as $intfld) {
if (!filter_var($_POST[$intfld], FILTER_VALIDATE_INT)) {
$valid = false;
}
}
foreach (array('gender', 'health') as $strfld) {
if (
!filter_var(
$_POST[$strfld],
FILTER_VALIDATE_REGEXP,
array('options' => array('regexp' => $filt_pattern))
)
) {
$valid = false;
}
}
if (
!filter_var(
$_POST['birth'],
FILTER_VALIDATE_REGEXP,
array('options' => array('regexp' => "/$dateregex/"))
)
) {
$valid = false;
}
if ($valid) {
$values = array(
'gender' => array(
'value' => $_POST['gender'], 'type' => PDO::PARAM_STR
),
'birth' => array(
'value' => $_POST['birth'], 'type' => PDO::PARAM_STR
),
'health' => array(
'value' => $_POST['health'], 'type' => PDO::PARAM_STR
),
'annotation' => array(
'value' => $_POST['annotation'], 'type' => PDO::PARAM_STR
),
'idFacility' => array(
'value' => $_POST['facility'], 'type' => PDO::PARAM_INT
),
'idSpecies' => array(
'value' => $_POST['species'], 'type' => PDO::PARAM_INT
),
);
$added_id = add_line('Followed', $values);
if ($added_id) {
add_line(
'FollowedEdition',
array(
'idStaff' => array(
'value' => $_SESSION['idstaff'], 'type' => PDO::PARAM_INT
),
'idFollowed' => array(
'value' => $added_id, 'type' => PDO::PARAM_INT
),
'type' => array(
'value' => 'addition', 'type' => PDO::PARAM_STR
)
)
);
if (isset($_POST['use_geoloc']) && $_POST['use_geoloc'] == 'on') {
$idmeasure = add_line(
'Measure',
array(
'idFollowed' => array(
'value' => $added_id, 'type' => PDO::PARAM_INT
),
'idStaff' => array(
'value' => $_SESSION['idstaff'],
'type' => PDO::PARAM_INT
)
)
);
$coords = explode(',', $_COOKIE['geoloc']);
add_line(
'Location',
array(
'latitude' => array(
'value' => (float) $coords[0],
'type' => PDO::PARAM_STR
),
'longitude' => array(
'value' => (float) $coords[1],
'type' => PDO::PARAM_STR
),
'idMeasure' => array(
'value' => $idmeasure, 'type' => PDO::PARAM_INT
)
)
);
}
}
}
}
head($title_head, $lang);
?>
<body>
<?php
include "nav.php";
if (isset($added_id, $valid) && $added_id && $valid) {
?>
<div class="alert alert-success" role="alert">
<a href='#' class='close' data-dismiss='alert' aria-label='close'>×</a>
<?php echo $alert_succes ?>
</div>
<?php
} elseif (isset($added_id) && !$added_id || isset($valid) && !$valid) {
?>
<div class="alert alert-danger" role="alert">
<a href='#' class='close' data-dismiss='alert' aria-label='close'>×</a>
<?php echo $alert_danger ?>
</div>
<?php
} ?>
<div class="container" style="background-image: url('data/pics/unordered/mada.jpg');">
<div class="add-form col-lg-5 col-md-5 col-sm-6 col-xs-12 col-lg-offset-6 col-md-offset-6 col-sm-offset-5">
<div class="formulaire">
<div class="middle">
<?php echo $title_form ?>
<?php echo $paragraph_form ?>
<form action="addfollowed.php" method="post">
<div class="form-group">
<select name="species" class="form-control">
<?php create_choice_list($id_biname); ?>
</select>
<select name='facility' class='form-control'>
<?php create_choice_list($id_faname, $defsel='1'); ?>
</select>
<label class="radio-inline"><input type="radio" name="gender" value="m"><?php echo $sex_m ?></label>
<label class="radio-inline"><input type="radio" name="gender" value="f"><?php echo $sex_f ?></label>
<label class="radio-inline"><input type="radio" name="gender" value="h"><?php echo $sex_h ?></label>
<label class="checkbox-inline">
<input type="checkbox" id="use_geoloc" name="use_geoloc" value="on"><?php echo $pos ?>
</label>
<br>
<input type="date" name="birth" class="form-control"
pattern="<?php echo $dateregex ?>"
placeholder="<?php echo $birth_date ?>">
<input type="text" name="health" class="form-control" placeholder="<?php echo $health ?>">
<textarea class="form-control" name="annotation" rows="4" cols="80"
placeholder="Commentaire sur L'individu"></textarea>
</div>
<button class="btn btn-success" id="submitbtn" type="submit" name="add_followed"><?php echo $save ?></button>
</form>
</div>
</div>
</div>
</div>
<?php include "footer.php" ?>
</body>
<script>
document.getElementById('use_geoloc').onclick = function()
{
if (this.checked)
{
document.getElementById('submitbtn').disabled = true;
navigator.geolocation.getCurrentPosition(coord2cookies);
document.getElementById('submitbtn').disabled = false;
}
else
{
document.getElementById('submitbtn').disabled = false;
}
}
function coord2cookies(position)
{
document.cookie = 'geoloc='+position.coords.latitude+','+position.coords.longitude;
}
</script>
</html>