-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.php
138 lines (113 loc) · 4.29 KB
/
common.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
<?php
/* FLOTTE - Gestion de flotte.
Copyright (C) 2023 Thierry HUCHARD <thierryh@vivaldi.net>
This file is part of the FLOTTE.
FLOTTE is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your
option) any later version.
FLOTTE is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with sane; see the file COPYING.
If not, see <https://www.gnu.org/licenses/>.
*/
// Initialize the session
session_start();
// https://www.monsite.com/garage
// $BASE_PATH='/garage';
$BASE_PATH='';
$servername = "localhost";
$username = "myusername";
$password = "mypassword";
$dbname = "database";
// Check if the user is already logged in, if yes then redirect him to welcome page
if($_SERVER['SCRIPT_NAME'] != $BASE_PATH.'/login.php' && $_SERVER['SCRIPT_NAME'] != $BASE_PATH.'/admin.php' && (!isset($_SESSION["username"]) || $_SESSION["username"] == "")){
header("location: ".$BASE_PATH."/login.php");
exit;
}
else if($_SERVER['SCRIPT_NAME'] != $BASE_PATH.'/incident.php' &&
$_SERVER['SCRIPT_NAME'] != $BASE_PATH.'/incident_details.php' &&
$_SERVER['SCRIPT_NAME'] != $BASE_PATH.'/incident_form.php' &&
$_SERVER['SCRIPT_NAME'] != $BASE_PATH.'/capture.php' &&
isset($_SESSION["role"]) && $_SESSION["role"] != 0){
header('location: '.$BASE_PATH.'/incident.php');
exit;
}
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
function date_fr($date) {
$adate = date_parse_from_format('Y-m-d',$date);
$date2 = ($adate['day'] < 10 ? '0' : '').$adate['day'].'/'.($adate['month'] < 10 ? '0' : '').$adate['month'].'/'.$adate['year'];
return $date2;
}
function dateheure_fr($date) {
$adate = date_parse_from_format('Y-m-d H:i:s',$date);
$date2 = ($adate['day'] < 10 ? '0' : '').$adate['day'].'/'.($adate['month'] < 10 ? '0' : '').$adate['month'].'/'.$adate['year'].' à '.$adate['hour'].':'.$adate['minute'].':'.$adate['second'];
return $date2;
}
function datemoins2() {
$date = date('Y-m-d', strtotime('-2 month'));
$adate = date_parse_from_format('Y-m-d',$date);
$date2 = $adate['year'].'-'.($adate['month'] < 10 ? '0' : '').$adate['month'].'-'.($adate['day'] < 10 ? '0' : '').$adate['day'];
return $date2;
}
function dateplus2() {
$date = date('Y-m-d', strtotime('+2 month'));
$adate = date_parse_from_format('Y-m-d',$date);
$date2 = $adate['year'].'-'.($adate['month'] < 10 ? '0' : '').$adate['month'].'-'.($adate['day'] < 10 ? '0' : '').$adate['day'];
return $date2;
}
function datealerte($date, $label) {
$datec = date('Y-m-d');
if ($datec >= $date)
return '<label style="color: red;">'.$label.'</labe>';
else
return $label;
}
function list_options($con, $table, $val=-1) {
$sql = 'select id, nom from '. $table .' order by nom asc;';
$result = $con->query($sql);
if ($result->num_rows > 0) {
// output data of each row
echo '<option value=""';
if ($val == -1)
echo ' selected';
echo '>faire un choix ...</option>';
while($row = $result->fetch_assoc()) {
echo '<option value="'.$row['id'].'"';
if ($val == $row['id'])
echo ' selected';
echo '>'.$row['nom'].'</option>';
}
}
}
function list_plaque_options($con, $val=-1) {
$sql = 'select id, plaque from vehicule order by plaque asc;';
$result = $con->query($sql);
if ($result->num_rows > 0) {
// output data of each row
echo '<option value=""';
if ($val == -1)
echo ' selected';
echo '>faire un choix ...</option>';
while($row = $result->fetch_assoc()) {
echo '<option value="'.$row['id'].'"';
if ($val == $row['id'])
echo ' selected';
echo '>'.$row['plaque'].'</option>';
}
}
}
function get_value($val) {
if (isset($val))
return $val;
return '';
}
?>