This repository has been archived by the owner on Sep 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
new_operation.php
158 lines (139 loc) · 6.56 KB
/
new_operation.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
<?php
/**
* Display a form to edit or add a new operation.
*
* PHP version 5
*
* Copyright © 2011 Mélissa Djebel
*
* This file is part of Galette (http://galette.tuxfamily.org).
*
* Plugin Pilote 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 Galette. If not, see <http://www.gnu.org/licenses/>.
*
* @category Plugins
* @package GalettePilote
*
* @author Mélissa Djebel <melissa.djebel@gmx.net>
* @copyright 2011 Mélissa Djebel
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
* @version 0.7
* @link http://galette.tuxfamily.org
* @since Available since 0.7
*/
define('GALETTE_BASE_PATH', '../../');
require_once GALETTE_BASE_PATH . 'includes/galette.inc.php';
if (!$login->isLogged() || !$login->isAdmin()) {
header('location: ' . GALETTE_BASE_PATH . 'index.php');
die();
}
// Import des classes de notre plugin
require_once '_config.inc.php';
$enregistrer = false;
$annuler = false;
if (array_key_exists('sauver', $_POST)) {
if (strlen($_POST['operation_id'] > 0)) {
$operation = new PiloteOperation(intval($_POST['operation_id']));
} else {
$operation = new PiloteOperation();
}
$operation->id_adherent = $_POST['adherent_id'];
$operation->access_exercice = $_POST['exercice'];
if ($operation->access_id == '') {
$operation->access_id = PiloteOperation::getNextAccessId(intval($operation->access_exercice));
}
list($j, $m, $a) = explode('/', $_POST['date_operation']);
$operation->date_operation = $a . '-' . $m . '-' . $j;
$operation->type_operation = $_POST['sel_type_operation'] == '-null-' ? $_POST['autre_type_operation'] : $_POST['sel_type_operation'];
$operation->libelle_operation = $_POST['libelle_operation'];
$operation->montant_operation = doubleval(str_replace(',', '.', $_POST['montant']));
if (strtolower($operation->type_operation) == 'vol') {
$operation->immatriculation = $_POST['immatriculation'];
$operation->duree_minute = intval($_POST['heures']) * 60 + intval($_POST['minutes']);
$operation->type_vol = $_POST['sel_type_vol'] == '-null-' ? $_POST['autre_type_vol'] : $_POST['sel_type_vol'];
$operation->aeroport_depart = $_POST['depart'];
$operation->aeroport_arrivee = $_POST['arrivee'];
$operation->instructeur = $_POST['instructeur'];
$operation->nb_atterrissages = intval($_POST['atterissage']);
$operation->nb_passagers = intval($_POST['nb_passagers']);
} else {
$operation->immatriculation = '*';
$operation->duree_minute = new Zend_Db_Expr('NULL');
$operation->type_vol = '';
$operation->aeroport_depart = '';
$operation->aeroport_arrivee = '';
$operation->instructeur = '';
$operation->nb_atterrissages = 0;
}
$operation->store();
$enregistrer = true;
if ($_POST['origine'] == 'compte_vol') {
$adherent = new Galette\Entity\Adherent(intval($operation->id_adherent));
header('Location: compte_vol.php?msg=ok&nb_lignes=20&compte_annee=' . $operation->access_exercice . '&login_adherent=' . $adherent->login);
} else if ($_POST['origine'] == 'liste_vols') {
$adherent = new Galette\Entity\Adherent(intval($operation->id_adherent));
header('Location: liste_vols.php?msg=ok&nb_lignes=20&compte_annee=' . $operation->access_exercice . '&login_adherent=' . $adherent->login);
}
}
if (array_key_exists('annuler', $_POST)) {
$annuler = true;
if ($_POST['origine'] == 'compte_vol') {
$adherent = new Galette\Entity\Adherent(intval($_POST['adherent_id']));
header('Location: compte_vol.php?msg=annule&nb_lignes=20&compte_annee=' . $_POST['exercice'] . '&login_adherent=' . $adherent->login);
} else if ($_POST['origine'] == 'liste_vols') {
$adherent = new Galette\Entity\Adherent(intval($_POST['adherent_id']));
header('Location: liste_vols.php?msg=annule&nb_lignes=20&compte_annee=' . $_POST['exercice'] . '&login_adherent=' . $adherent->login);
}
}
global $zdb;
$liste_type_operations = PiloteOperation::getTypesOperations();
$liste_type_vols = PiloteOperation::getTypesVols();
/**
* Récupération de l'opération si elle existe ou initialisation d'une nouvelle
*/
if (array_key_exists('operation_id', $_GET)) {
$operation = new PiloteOperation(intval($_GET['operation_id']));
$operation->duree_heure = floor($operation->duree_minute / 60);
$operation->duree_minute = $operation->duree_minute - $operation->duree_heure * 60;
$operation->date_operation_IHM = date('d/m/Y', strtotime($operation->date_operation));
$operation->montant_operation = number_format($operation->montant_operation, 2);
} else {
$operation = new PiloteOperation();
$operation->access_exercice = date('Y');
$operation->date_operation_IHM = date('d/m/Y');
$operation->aeroport_depart = PiloteParametre::getValeurParametre(PiloteParametre::PARAM_CODE_AEROCLUB);
$operation->aeroport_arrivee = PiloteParametre::getValeurParametre(PiloteParametre::PARAM_CODE_AEROCLUB);
$operation->nb_atterrissages = 1;
$operation->nb_passagers = 0;
$operation->duree_minute = 0;
$operation->duree_heure = 0;
}
$liste_adherents = PiloteOperation::getAdherentsActifs();
$login_adherent = '';
$tpl->assign('page_title', _T("NEW OPERATION.PAGE TITLE"));
//Set the path to the current plugin's templates,
//but backup main Galette's template path before
$orig_template_path = $tpl->template_dir;
$tpl->template_dir = 'templates/' . $preferences->pref_theme;
$tpl->assign('liste_adherents', $liste_adherents);
$tpl->assign('liste_type_operations', $liste_type_operations);
$tpl->assign('liste_avions', PiloteAvion::getTousAvionsReservables());
$tpl->assign('liste_type_vols', $liste_type_vols);
$tpl->assign('liste_instructeurs', PiloteInstructeur::getTousInstructeurs('nom', 'asc', 0, 9999));
$tpl->assign('require_calendar', true);
$tpl->assign('origine', $_GET['origine']);
$tpl->assign('login_adherent', $login_adherent);
$tpl->assign('operation', $operation);
$tpl->assign('enregistre', $enregistrer);
$tpl->assign('pas_enregistre', $annuler);
$content = $tpl->fetch('new_operation.tpl', PILOTE_SMARTY_PREFIX);
$tpl->assign('content', $content);
//Set path to main Galette's template
$tpl->template_dir = $orig_template_path;
$tpl->display('page.tpl', PILOTE_SMARTY_PREFIX);
?>