1 | <?php |
||
34 | class modFlightLog extends DolibarrModules |
||
35 | { |
||
36 | const MENU_TYPE_LEFT = 'left'; |
||
37 | const MENU_TYPE_TOP = 'top'; |
||
38 | |||
39 | /** |
||
40 | * @var array Indexed list of export IDs |
||
41 | * |
||
42 | */ |
||
43 | public $export_code = array(); |
||
44 | |||
45 | /** |
||
46 | * @var array Indexed list of export names |
||
47 | * |
||
48 | */ |
||
49 | public $export_label = array(); |
||
50 | |||
51 | /** |
||
52 | * @var array Indexed list of export enabling conditions |
||
53 | * |
||
54 | */ |
||
55 | public $export_enabled = array(); |
||
56 | |||
57 | /** |
||
58 | * @var array Indexed list of export required permissions |
||
59 | * |
||
60 | */ |
||
61 | public $export_permission = array(); |
||
62 | |||
63 | /** |
||
64 | * @var array Indexed list of export fields |
||
65 | * |
||
66 | */ |
||
67 | public $export_fields_array = array(); |
||
68 | |||
69 | /** |
||
70 | * @var array Indexed list of export entities |
||
71 | * |
||
72 | */ |
||
73 | public $export_entities_array = array(); |
||
74 | |||
75 | /** |
||
76 | * @var array Indexed list of export SQL queries start |
||
77 | * |
||
78 | */ |
||
79 | public $export_sql_start = array(); |
||
80 | |||
81 | /** |
||
82 | * @var array Indexed list of export SQL queries end |
||
83 | * |
||
84 | */ |
||
85 | public $export_sql_end = array(); |
||
86 | |||
87 | /** |
||
88 | * @var array |
||
89 | */ |
||
90 | public $export_TypeFields_array = []; |
||
91 | |||
92 | /** |
||
93 | * @var array |
||
94 | */ |
||
95 | public $menus; |
||
96 | |||
97 | /** |
||
98 | * @var array |
||
99 | */ |
||
100 | public $tabs; |
||
101 | |||
102 | /** |
||
103 | * @var array |
||
104 | */ |
||
105 | public $dictionaries; |
||
106 | |||
107 | /** |
||
108 | * Constructor. Define names, constants, directories, boxes, permissions |
||
109 | * |
||
110 | * @param DoliDB $db Database handler |
||
111 | */ |
||
112 | public function __construct($db) |
||
113 | { |
||
114 | parent::__construct($db); |
||
115 | |||
116 | global $conf; |
||
117 | |||
118 | // Id for module (must be unique). |
||
119 | $this->numero = 500000; |
||
120 | // Key text used to identify module (for permissions, menus, etc...) |
||
121 | $this->rights_class = 'flightlog'; |
||
122 | |||
123 | $this->family = "Belgian Balloon Club"; |
||
124 | $this->module_position = 500; |
||
125 | $this->name = preg_replace('/^mod/i', '', get_class($this)); |
||
126 | // Module description, used if translation string 'ModuleXXXDesc' not found (where XXX is value of numeric property 'numero' of module) |
||
127 | $this->description = "Pilots flight log"; |
||
128 | $this->descriptionlong = "Manage flights and flight types for the Belgian Balloon Club"; |
||
129 | $this->editor_name = 'De Coninck Laurent'; |
||
130 | $this->editor_url = 'http://www.dolibarr.org'; |
||
131 | |||
132 | // Possible values for version are: 'development', 'experimental', 'dolibarr', 'dolibarr_deprecated' or a version string like 'x.y.z' |
||
133 | $this->version = '1.3'; |
||
134 | // Key used in llx_const table to save module status enabled/disabled (where MYMODULE is value of property name of module in uppercase) |
||
135 | $this->const_name = 'MAIN_MODULE_' . strtoupper($this->name); |
||
136 | // Name of image file used for this module. |
||
137 | // If file is in theme/yourtheme/img directory under name object_pictovalue.png, use this->picto='pictovalue' |
||
138 | // If file is in module/img directory under name object_pictovalue.png, use this->picto='pictovalue@module' |
||
139 | $this->picto = 'flight@flightlog'; |
||
140 | |||
141 | $this->configureCss(); |
||
142 | |||
143 | // Data directories to create when module is enabled. |
||
144 | $this->dirs = array(); |
||
145 | |||
146 | // Config pages. Put here list of php page, stored into mymodule/admin directory, to use to setup module. |
||
147 | $this->config_page_url = [ |
||
148 | "vol.php@flightlog", |
||
149 | ]; |
||
150 | |||
151 | // Dependencies |
||
152 | $this->hidden = false; |
||
153 | $this->depends = array('modFlightBalloon'); |
||
154 | $this->requiredby = array(); |
||
155 | $this->conflictwith = array(); |
||
156 | $this->phpmin = array(5, 5); |
||
157 | $this->need_dolibarr_version = array(4, 0); |
||
158 | $this->langfiles = array("mymodule@flightlog"); |
||
159 | |||
160 | // Constants |
||
161 | $this->initConstants(); |
||
162 | |||
163 | if (!isset($conf->flightLog) || !isset($conf->flightLog->enabled)) { |
||
164 | $conf->flightLog = new stdClass(); |
||
165 | $conf->flightLog->enabled = 0; |
||
166 | } |
||
167 | |||
168 | $this->boxes = []; |
||
169 | |||
170 | $this->initTabs(); |
||
171 | $this->initDictionnaries(); |
||
172 | $this->initCronJobs(); |
||
173 | $this->initMenu(); |
||
174 | $this->initHooks(); |
||
175 | $this->initPermissions(); |
||
176 | $this->initExports(); |
||
177 | |||
178 | $this->activateTriggers(); |
||
179 | $this->initWorkflows(); |
||
180 | } |
||
181 | |||
182 | /** |
||
183 | * Function called when module is enabled. |
||
184 | * The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database. |
||
185 | * It also creates data directories |
||
186 | * |
||
187 | * @param string $options Options when enabling module ('', 'noboxes') |
||
188 | * |
||
189 | * @return int 1 if OK, 0 if KO |
||
190 | */ |
||
191 | public function init($options = '') |
||
192 | { |
||
193 | $sql = array(); |
||
194 | |||
195 | $this->_load_tables('/flightlog/sql/'); |
||
196 | |||
197 | return $this->_init($sql, $options); |
||
198 | } |
||
199 | |||
200 | /** |
||
201 | * Function called when module is disabled. |
||
202 | * Remove from database constants, boxes and permissions from Dolibarr database. |
||
203 | * Data directories are not deleted |
||
204 | * |
||
205 | * @param string $options Options when enabling module ('', 'noboxes') |
||
206 | * |
||
207 | * @return int 1 if OK, 0 if KO |
||
208 | */ |
||
209 | public function remove($options = '') |
||
210 | { |
||
211 | $sql = array(); |
||
212 | |||
213 | return $this->_remove($sql, $options); |
||
214 | } |
||
215 | |||
216 | /** |
||
217 | * Init menu |
||
218 | */ |
||
219 | private function initMenu() |
||
220 | { |
||
221 | $this->menus = array(); |
||
222 | $r = 0; |
||
223 | |||
224 | $this->menu[$r] = array( |
||
225 | 'fk_menu' => 'fk_mainmenu=flightlog', |
||
226 | 'type' => self::MENU_TYPE_TOP, |
||
227 | 'titre' => 'Carnet de vols', |
||
228 | 'mainmenu' => 'flightlog', |
||
229 | 'leftmenu' => 'readFlight', |
||
230 | 'url' => '/flightlog/readFlights.php', |
||
231 | 'langs' => 'mylangfile', |
||
232 | 'position' => 100, |
||
233 | 'enabled' => '1', |
||
234 | 'perms' => '$user->rights->flightlog->vol->access', |
||
235 | 'target' => '', |
||
236 | 'user' => 0 |
||
237 | ); |
||
238 | $r++; |
||
239 | |||
240 | $this->menu[$r] = array( |
||
241 | 'fk_menu' => 'fk_mainmenu=flightlog', |
||
242 | 'type' => self::MENU_TYPE_LEFT, |
||
243 | 'titre' => 'Ajouter un vol', |
||
244 | 'mainmenu' => 'flightlog', |
||
245 | 'leftmenu' => 'addFlight', |
||
246 | 'url' => '/flightlog/addFlight.php', |
||
247 | 'langs' => 'mylangfile', |
||
248 | 'position' => 101, |
||
249 | 'enabled' => '1', |
||
250 | 'perms' => '$user->rights->flightlog->vol->add', |
||
251 | 'target' => '', |
||
252 | 'user' => 2 |
||
253 | ); |
||
254 | $r++; |
||
255 | $this->menu[$r] = array( |
||
256 | 'fk_menu' => 'fk_mainmenu=flightlog', |
||
257 | 'type' => self::MENU_TYPE_LEFT, |
||
258 | 'titre' => 'Visualisation', |
||
259 | 'mainmenu' => 'flightlog', |
||
260 | 'leftmenu' => 'showFlight', |
||
261 | 'url' => '/flightlog/readFlights.php', |
||
262 | 'langs' => 'mylangfile', |
||
263 | 'position' => 102, |
||
264 | 'enabled' => '1', |
||
265 | 'perms' => '1', |
||
266 | 'target' => '', |
||
267 | 'user' => 2 |
||
268 | ); |
||
269 | $this->menu[$r] = array( |
||
270 | 'fk_menu' => 'fk_mainmenu=flightlog', |
||
271 | 'type' => self::MENU_TYPE_LEFT, |
||
272 | 'titre' => 'Les vols', |
||
273 | 'mainmenu' => 'flightlog', |
||
274 | 'leftmenu' => 'flightlog', |
||
275 | 'url' => '/flightlog/list.php', |
||
276 | 'langs' => 'mylangfile', |
||
277 | 'position' => 105, |
||
278 | 'enabled' => '1', |
||
279 | 'perms' => '1', |
||
280 | 'target' => '', |
||
281 | 'user' => 2 |
||
282 | ); |
||
283 | $r++; |
||
284 | $this->menu[$r] = array( |
||
285 | 'fk_menu' => 'fk_mainmenu=flightlog', |
||
286 | 'type' => self::MENU_TYPE_LEFT, |
||
287 | 'titre' => 'Gestion', |
||
288 | 'mainmenu' => 'flightlog', |
||
289 | 'leftmenu' => 'management', |
||
290 | 'url' => '', |
||
291 | 'langs' => 'mylangfile', |
||
292 | 'position' => 106, |
||
293 | 'enabled' => '1', |
||
294 | 'perms' => '$user->rights->flightlog->vol->status||$user->rights->flightlog->vol->detail', |
||
295 | 'target' => '', |
||
296 | 'user' => 2 |
||
297 | ); |
||
298 | $r++; |
||
299 | $this->menu[$r] = array( |
||
300 | 'fk_menu' => 'fk_mainmenu=flightlog,fk_leftmenu=management', |
||
301 | 'type' => self::MENU_TYPE_LEFT, |
||
302 | 'titre' => 'Payement', |
||
303 | 'mainmenu' => 'flightlog', |
||
304 | 'leftmenu' => 'flightBilling', |
||
305 | 'url' => '/flightlog/listFact.php?view=1', |
||
306 | 'langs' => 'mylangfile', |
||
307 | 'position' => 107, |
||
308 | 'enabled' => '1', |
||
309 | 'perms' => '$user->rights->flightlog->vol->financial', |
||
310 | 'target' => '', |
||
311 | 'user' => 2 |
||
312 | ); |
||
313 | $r++; |
||
314 | $this->menu[$r] = array( |
||
315 | 'fk_menu' => 'fk_mainmenu=flightlog,fk_leftmenu=management', |
||
316 | 'type' => self::MENU_TYPE_LEFT, |
||
317 | 'titre' => 'Aviabel', |
||
318 | 'mainmenu' => 'flightlog', |
||
319 | 'leftmenu' => 'flightAviabel', |
||
320 | 'url' => '/flightlog/listFact.php?view=2', |
||
321 | 'langs' => 'mylangfile', |
||
322 | 'position' => 108, |
||
323 | 'enabled' => '1', |
||
324 | 'perms' => '$user->rights->flightlog->vol->detail', |
||
325 | 'target' => '', |
||
326 | 'user' => 2 |
||
327 | ); |
||
328 | $r++; |
||
329 | $this->menu[$r] = array( |
||
330 | 'fk_menu' => 'fk_mainmenu=flightlog,fk_leftmenu=management', |
||
331 | 'type' => self::MENU_TYPE_LEFT, |
||
332 | 'titre' => 'Facturation mensuelle', |
||
333 | 'mainmenu' => 'flightlog', |
||
334 | 'leftmenu' => 'monthlyBill', |
||
335 | 'url' => '/flightlog/generateMonthlyBilling.php', |
||
336 | 'langs' => 'mylangfile', |
||
337 | 'position' => 109, |
||
338 | 'enabled' => '1', |
||
339 | 'perms' => '$user->rights->flightlog->vol->financial', |
||
340 | 'target' => '', |
||
341 | 'user' => 2 |
||
342 | ); |
||
343 | } |
||
344 | |||
345 | /** |
||
346 | * Init permissions |
||
347 | */ |
||
348 | private function initPermissions() |
||
349 | { |
||
350 | $this->rights = array(); // Permission array used by this module |
||
351 | $r = 0; |
||
352 | |||
353 | $this->rights[$r][0] = 9993; |
||
354 | $this->rights[$r][1] = 'Permet d\'acceder au module des vols.'; |
||
355 | $this->rights[$r][3] = 0; |
||
356 | $this->rights[$r][4] = 'vol'; |
||
357 | $this->rights[$r][5] = 'access'; |
||
358 | $r++; |
||
359 | |||
360 | $this->rights[$r][0] = 9998; |
||
361 | $this->rights[$r][1] = 'Enregistrer un nouveau vol.'; |
||
362 | $this->rights[$r][3] = 0; |
||
363 | $this->rights[$r][4] = 'vol'; |
||
364 | $this->rights[$r][5] = 'add'; |
||
365 | $r++; |
||
366 | |||
367 | $this->rights[$r][0] = 9997; |
||
368 | $this->rights[$r][1] = 'Permet de facturer un vol.'; |
||
369 | $this->rights[$r][3] = 0; |
||
370 | $this->rights[$r][4] = 'vol'; |
||
371 | $this->rights[$r][5] = 'status'; |
||
372 | $r++; |
||
373 | |||
374 | $this->rights[$r][0] = 9996; |
||
375 | $this->rights[$r][1] = 'Permet de supprimer un vol.'; |
||
376 | $this->rights[$r][3] = 0; |
||
377 | $this->rights[$r][4] = 'vol'; |
||
378 | $this->rights[$r][5] = 'delete'; |
||
379 | $r++; |
||
380 | |||
381 | $this->rights[$r][0] = 9995; |
||
382 | $this->rights[$r][1] = 'Permet de modifier tous les vols.'; |
||
383 | $this->rights[$r][3] = 0; |
||
384 | $this->rights[$r][4] = 'vol'; |
||
385 | $this->rights[$r][5] = 'edit'; |
||
386 | $r++; |
||
387 | |||
388 | $this->rights[$r][0] = 9994; |
||
389 | $this->rights[$r][1] = 'affiche les details de tous les ballons et de tous les pilotes.'; |
||
390 | $this->rights[$r][3] = 0; |
||
391 | $this->rights[$r][4] = 'vol'; |
||
392 | $this->rights[$r][5] = 'detail'; |
||
393 | $r++; |
||
394 | |||
395 | $this->rights[$r][0] = 9999; |
||
396 | $this->rights[$r][1] = 'Gérer les aspects financier des vols'; |
||
397 | $this->rights[$r][3] = 0; |
||
398 | $this->rights[$r][4] = 'vol'; |
||
399 | $this->rights[$r][5] = 'financial'; |
||
400 | $r++; |
||
401 | |||
402 | $this->rights[$r][0] = 10000; |
||
403 | $this->rights[$r][1] = 'Gérer des documents financiers'; |
||
404 | $this->rights[$r][3] = 0; |
||
405 | $this->rights[$r][4] = 'vol'; |
||
406 | $this->rights[$r][5] = 'financialGenerateDocuments'; |
||
407 | } |
||
408 | |||
409 | private function initCronJobs() |
||
410 | { |
||
411 | $this->cronjobs = [ |
||
412 | 0=>array('label'=>'bbcMonthlyFlightsBill', 'jobtype'=>'method', 'class'=>'flightlog/core/cron/BbcMonthlyFlightsBillCron.php', 'objectname'=>'BbcMonthlyFlightsBillCron', 'method'=>'run', 'parameters'=>'', 'comment'=>'Generate month bill.', 'frequency'=>1, 'unitfrequency'=>2592000), |
||
413 | ]; |
||
414 | } |
||
415 | |||
416 | private function initDictionnaries() |
||
420 | |||
421 | private function initFlightTypeDictionnary() |
||
436 | |||
437 | /** |
||
438 | * Init hooks |
||
439 | */ |
||
440 | private function initHooks() |
||
451 | |||
452 | private function initConstants() |
||
475 | |||
476 | /** |
||
477 | * Init exports |
||
478 | */ |
||
479 | private function initExports() |
||
484 | |||
485 | /** |
||
486 | * @param int $r |
||
487 | */ |
||
488 | private function addFullFlightsExport($r) |
||
574 | |||
575 | /** |
||
576 | * Activate triggers for this module |
||
577 | */ |
||
578 | private function activateTriggers() |
||
582 | |||
583 | /** |
||
584 | * Initialize all workflows |
||
585 | */ |
||
586 | private function initWorkflows() |
||
597 | |||
598 | /** |
||
599 | * Add stylesheets |
||
600 | */ |
||
601 | private function configureCss() |
||
607 | |||
608 | /** |
||
609 | * Init tabs to inject in other modules. |
||
610 | */ |
||
611 | private function initTabs() |
||
612 | { |
||
613 | $this->tabs = []; |
||
618 | |||
619 | } |
||
620 | |||
621 |