Completed
Branch feature/create_monthly_billing (30fb74)
by Laurent
02:14
created

modFlightLog::configureCss()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/* Copyright (C) 2003      Rodolphe Quiedeville <[email protected]>
3
 * Copyright (C) 2004-2015 Laurent Destailleur  <[email protected]>
4
 * Copyright (C) 2005-2016 Regis Houssin        <[email protected]>
5
 *
6
 * This program is free software; you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation; either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18
 */
19
20
/**
21
 *    \defgroup   mymodule     Module MyModule
22
 *  \brief      Example of a module descriptor.
23
 *                Such a file must be copied into htdocs/mymodule/core/modules directory.
24
 *  \file       htdocs/mymodule/core/modules/modMyModule.class.php
25
 *  \ingroup    mymodule
26
 *  \brief      Description and activation file for module MyModule
27
 */
28
include_once DOL_DOCUMENT_ROOT . '/core/modules/DolibarrModules.class.php';
29
30
31
/**
32
 *  Description and activation class for module MyModule
33
 */
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.1';
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
        // Array to add new pages in new tabs
164
        $this->tabs = [];
165
166
        if (!isset($conf->flightLog) || !isset($conf->flightLog->enabled)) {
167
            $conf->flightLog = new stdClass();
168
            $conf->flightLog->enabled = 0;
169
        }
170
171
        $this->boxes = [];
172
173
        $this->initDictionnaries();
174
        $this->initCronJobs();
175
        $this->initMenu();
176
        $this->initHooks();
177
        $this->initPermissions();
178
        $this->initExports();
179
180
        $this->activateTriggers();
181
        $this->initWorkflows();
182
    }
183
184
    /**
185
     *        Function called when module is enabled.
186
     *        The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database.
187
     *        It also creates data directories
188
     *
189
     * @param      string $options Options when enabling module ('', 'noboxes')
190
     *
191
     * @return     int                1 if OK, 0 if KO
192
     */
193
    public function init($options = '')
194
    {
195
        $sql = array();
196
197
        $this->_load_tables('/flightlog/sql/');
198
199
        return $this->_init($sql, $options);
200
    }
201
202
    /**
203
     * Function called when module is disabled.
204
     * Remove from database constants, boxes and permissions from Dolibarr database.
205
     * Data directories are not deleted
206
     *
207
     * @param      string $options Options when enabling module ('', 'noboxes')
208
     *
209
     * @return     int                1 if OK, 0 if KO
210
     */
211
    public function remove($options = '')
212
    {
213
        $sql = array();
214
215
        return $this->_remove($sql, $options);
216
    }
217
218
    /**
219
     * Init menu
220
     */
221
    private function initMenu()
222
    {
223
        $this->menus = array();
224
        $r = 0;
225
226
        $this->menu[$r] = array(
227
            'fk_menu' => 'fk_mainmenu=flightlog',
228
            'type' => self::MENU_TYPE_TOP,
229
            'titre' => 'Carnet de vols',
230
            'mainmenu' => 'flightlog',
231
            'leftmenu' => 'readFlight',
232
            'url' => '/flightlog/readFlights.php',
233
            'langs' => 'mylangfile',
234
            'position' => 100,
235
            'enabled' => '1',
236
            'perms' => '$user->rights->flightlog->vol->access',
237
            'target' => '',
238
            'user' => 0
239
        );
240
        $r++;
241
242
        $this->menu[$r] = array(
243
            'fk_menu' => 'fk_mainmenu=flightlog',
244
            'type' => self::MENU_TYPE_LEFT,
245
            'titre' => 'Ajouter un vol',
246
            'mainmenu' => 'flightlog',
247
            'leftmenu' => 'addFlight',
248
            'url' => '/flightlog/addFlight.php',
249
            'langs' => 'mylangfile',
250
            'position' => 101,
251
            'enabled' => '1',
252
            'perms' => '$user->rights->flightlog->vol->add',
253
            'target' => '',
254
            'user' => 2
255
        );
256
        $r++;
257
        $this->menu[$r] = array(
258
            'fk_menu' => 'fk_mainmenu=flightlog',
259
            'type' => self::MENU_TYPE_LEFT,
260
            'titre' => 'Visualisation',
261
            'mainmenu' => 'flightlog',
262
            'leftmenu' => 'showFlight',
263
            'url' => '/flightlog/readFlights.php',
264
            'langs' => 'mylangfile',
265
            'position' => 102,
266
            'enabled' => '1',
267
            'perms' => '1',
268
            'target' => '',
269
            'user' => 2
270
        );
271
        $this->menu[$r] = array(
272
            'fk_menu' => 'fk_mainmenu=flightlog',
273
            'type' => self::MENU_TYPE_LEFT,
274
            'titre' => 'Les vols',
275
            'mainmenu' => 'flightlog',
276
            'leftmenu' => 'flightlog',
277
            'url' => '/flightlog/list.php',
278
            'langs' => 'mylangfile',
279
            'position' => 105,
280
            'enabled' => '1',
281
            'perms' => '1',
282
            'target' => '',
283
            'user' => 2
284
        );
285
        $r++;
286
        $this->menu[$r] = array(
287
            'fk_menu' => 'fk_mainmenu=flightlog',
288
            'type' => self::MENU_TYPE_LEFT,
289
            'titre' => 'Gestion',
290
            'mainmenu' => 'flightlog',
291
            'leftmenu' => 'management',
292
            'url' => '',
293
            'langs' => 'mylangfile',
294
            'position' => 106,
295
            'enabled' => '1',
296
            'perms' => '$user->rights->flightlog->vol->status||$user->rights->flightlog->vol->detail',
297
            'target' => '',
298
            'user' => 2
299
        );
300
        $r++;
301
        $this->menu[$r] = array(
302
            'fk_menu' => 'fk_mainmenu=flightlog,fk_leftmenu=management',
303
            'type' => self::MENU_TYPE_LEFT,
304
            'titre' => 'Payement',
305
            'mainmenu' => 'flightlog',
306
            'leftmenu' => 'flightBilling',
307
            'url' => '/flightlog/listFact.php?view=1',
308
            'langs' => 'mylangfile',
309
            'position' => 107,
310
            'enabled' => '1',
311
            'perms' => '$user->rights->flightlog->vol->financial',
312
            'target' => '',
313
            'user' => 2
314
        );
315
        $r++;
316
        $this->menu[$r] = array(
317
            'fk_menu' => 'fk_mainmenu=flightlog,fk_leftmenu=management',
318
            'type' => self::MENU_TYPE_LEFT,
319
            'titre' => 'Aviabel',
320
            'mainmenu' => 'flightlog',
321
            'leftmenu' => 'flightAviabel',
322
            'url' => '/flightlog/listFact.php?view=2',
323
            'langs' => 'mylangfile',
324
            'position' => 108,
325
            'enabled' => '1',
326
            'perms' => '$user->rights->flightlog->vol->detail',
327
            'target' => '',
328
            'user' => 2
329
        );
330
        $r++;
331
        $this->menu[$r] = array(
332
            'fk_menu' => 'fk_mainmenu=flightlog,fk_leftmenu=management',
333
            'type' => self::MENU_TYPE_LEFT,
334
            'titre' => 'Facturation mensuelle',
335
            'mainmenu' => 'flightlog',
336
            'leftmenu' => 'monthlyBill',
337
            'url' => '/flightlog/generateMonthlyBilling.php',
338
            'langs' => 'mylangfile',
339
            'position' => 109,
340
            'enabled' => '1',
341
            'perms' => '$user->rights->flightlog->vol->financial',
342
            'target' => '',
343
            'user' => 2
344
        );
345
    }
346
347
    /**
348
     * Init permissions
349
     */
350
    private function initPermissions()
351
    {
352
        $this->rights = array();        // Permission array used by this module
353
        $r = 0;
354
355
        $this->rights[$r][0] = 9993;
356
        $this->rights[$r][1] = 'Permet d\'acceder au module des vols.';
357
        $this->rights[$r][3] = 0;
358
        $this->rights[$r][4] = 'vol';
359
        $this->rights[$r][5] = 'access';
360
        $r++;
361
362
        $this->rights[$r][0] = 9998;
363
        $this->rights[$r][1] = 'Enregistrer un nouveau vol.';
364
        $this->rights[$r][3] = 0;
365
        $this->rights[$r][4] = 'vol';
366
        $this->rights[$r][5] = 'add';
367
        $r++;
368
369
        $this->rights[$r][0] = 9997;
370
        $this->rights[$r][1] = 'Permet de facturer un vol.';
371
        $this->rights[$r][3] = 0;
372
        $this->rights[$r][4] = 'vol';
373
        $this->rights[$r][5] = 'status';
374
        $r++;
375
376
        $this->rights[$r][0] = 9996;
377
        $this->rights[$r][1] = 'Permet de supprimer un vol.';
378
        $this->rights[$r][3] = 0;
379
        $this->rights[$r][4] = 'vol';
380
        $this->rights[$r][5] = 'delete';
381
        $r++;
382
383
        $this->rights[$r][0] = 9995;
384
        $this->rights[$r][1] = 'Permet de modifier tous les vols.';
385
        $this->rights[$r][3] = 0;
386
        $this->rights[$r][4] = 'vol';
387
        $this->rights[$r][5] = 'edit';
388
        $r++;
389
390
        $this->rights[$r][0] = 9994;
391
        $this->rights[$r][1] = 'affiche les details de tous les ballons et de tous les pilotes.';
392
        $this->rights[$r][3] = 0;
393
        $this->rights[$r][4] = 'vol';
394
        $this->rights[$r][5] = 'detail';
395
        $r++;
396
397
        $this->rights[$r][0] = 9999;
398
        $this->rights[$r][1] = 'Gérer les aspects financier des vols';
399
        $this->rights[$r][3] = 0;
400
        $this->rights[$r][4] = 'vol';
401
        $this->rights[$r][5] = 'financial';
402
        $r++;
403
404
        $this->rights[$r][0] = 10000;
405
        $this->rights[$r][1] = 'Gérer des documents financiers';
406
        $this->rights[$r][3] = 0;
407
        $this->rights[$r][4] = 'vol';
408
        $this->rights[$r][5] = 'financialGenerateDocuments';
409
    }
410
411
    private function initCronJobs()
412
    {
413
        $this->cronjobs = array();
414
    }
415
416
    private function initDictionnaries()
417
    {
418
        $this->initFlightTypeDictionnary();
419
    }
420
421
    private function initFlightTypeDictionnary()
422
    {
423
        $this->dictionaries = array(
424
            'langs' => 'mylangfile@mymodule',
425
            'tabname' => array(MAIN_DB_PREFIX . "bbc_types"),
426
            'tablib' => array("Types de vols"),
427
            'tabsql' => array('SELECT f.idType, f.numero, f.nom, f.active FROM ' . MAIN_DB_PREFIX . 'bbc_types as f',),
428
            'tabsqlsort' => array("numero ASC"),
429
            'tabfield' => array("idType,numero,nom"),
430
            'tabfieldvalue' => array("numero,nom"),
431
            'tabfieldinsert' => array("numero,nom"),
432
            'tabrowid' => array("idType"),
433
            'tabcond' => array('$conf->flightlog->enabled'),
434
        );
435
    }
436
437
    /**
438
     * Init hooks
439
     */
440
    private function initHooks()
441
    {
442
        if (!isset($this->module_parts["hooks"])) {
443
            $this->module_parts["hooks"] = [];
444
        }
445
446
        $this->module_parts["hooks"][] = "searchform";
447
        $this->module_parts["hooks"][] = "showLinkToObjectBlock";
448
        $this->module_parts["hooks"][] = "criccar";
449
450
    }
451
452
    private function initConstants()
453
    {
454
        $this->const = array(
455
            0 => [
456
                'BBC_FLIGHT_LOG_TAUX_REMB_KM',
457
                'chaine',
458
                '0.25',
459
                'Taux remboursement des kilomètres au BBC',
460
                true,
461
                'current',
462
                true
463
            ],
464
            1 => [
465
                'BBC_FLIGHT_LOG_UNIT_PRICE_MISSION',
466
                'chaine',
467
                '35',
468
                'Unit price special mission',
469
                true,
470
                'current',
471
                true
472
            ],
473
        );
474
    }
475
476
    /**
477
     * Init exports
478
     */
479
    private function initExports()
480
    {
481
        $r = 0;
482
        $this->addFullFlightsExport($r);
483
    }
484
485
    /**
486
     * @param int $r
487
     */
488
    private function addFullFlightsExport($r)
489
    {
490
        $this->export_code[$r] = $this->rights_class . '_' . $r;
491
        $this->export_label[$r] = 'Flights export';
492
        $this->export_enabled[$r] = '1';
493
        $this->export_permission[$r] = array(array("flightlog", "vol", "detail"));
494
        $this->export_fields_array[$r] = array(
495
            "flight.idBBC_vols" => "Identifiant",
496
            "flight.date" => "Date",
497
            "flight.lieuD" => "Lieu décollage ",
498
            "flight.lieuA" => "Lieu atterissage",
499
            "flight.heureD" => "Heure décollage",
500
            "flight.heureA" => "Heure atterissage",
501
            "flight.BBC_ballons_idBBC_ballons" => "Identifiant ballon",
502
            "flight.nbrPax" => "# pax",
503
            "flight.remarque" => "Remarque",
504
            "flight.incidents" => "Incidents",
505
            "flight.fk_type" => "Identifiant type",
506
            "flight.fk_pilot" => "Identifiant pilote",
507
            "flight.fk_organisateur" => "Identifiant organisateur",
508
            "flight.is_facture" => "Facture Oui/Non",
509
            "flight.kilometers" => "# Km",
510
            "flight.cost" => "Cout",
511
            "flight.fk_receiver" => "Identifiant receveur d'argent",
512
            "flight.justif_kilometers" => "Justificatif kilomètres",
513
            "balloon.immat" => "Immat.",
514
            "pilot.login" => "Pilote",
515
            "flightType.nom" => "Type de vol",
516
            "organisator.login" => "Organisateur",
517
            "receiver.login" => "Percepteur",
518
        );
519
520
        $this->export_TypeFields_array[$r] = [
521
            "flight.date" => "Date",
522
            "flight.lieuD" => "Text",
523
            "flight.lieuA" => "Text",
524
            "flight.heureD" => "Text",
525
            "flight.heureA" => "Text",
526
            "flight.BBC_ballons_idBBC_ballons" => implode(":", ["List", "bbc_ballons", "immat", "rowid"]),
527
            "flight.nbrPax" => "Numeric",
528
            "flight.remarque" => "Text",
529
            "flight.incidents" => "Text",
530
            "flight.fk_type" => implode(":", ["List", "bbc_types", "nom", "idType"]),
531
            "flight.fk_pilot" => implode(":", ["List", "user", "login", "rowid"]),
532
            "flight.fk_organisateur" => implode(":", ["List", "user", "login", "rowid"]),
533
            "flight.is_facture" => "Boolean",
534
            "flight.kilometers" => "Numeric",
535
            "flight.cost" => "Numeric",
536
            "flight.fk_receiver" => implode(":", ["List", "user", "login", "rowid"]),
537
            "flight.justif_kilometers" => "Text",
538
        ];
539
540
        $this->export_entities_array[$r] = array(
541
            "flight.idBBC_vols" => "Flight",
542
            "flight.date" => "Flight",
543
            "flight.lieuD" => "Flight",
544
            "flight.lieuA" => "Flight",
545
            "flight.heureD" => "Flight",
546
            "flight.heureA" => "Flight",
547
            "flight.BBC_ballons_idBBC_ballons" => "Flight",
548
            "flight.nbrPax" => "Flight",
549
            "flight.remarque" => "Flight",
550
            "flight.incidents" => "Flight",
551
            "flight.fk_type" => "Flight",
552
            "flight.fk_pilot" => "Flight",
553
            "flight.fk_organisateur" => "Flight",
554
            "flight.is_facture" => "Flight",
555
            "flight.kilometers" => "Flight",
556
            "flight.cost" => "Flight",
557
            "flight.fk_receiver" => "Flight",
558
            "flight.justif_kilometers" => "Flight",
559
            "balloon.immat" => "Balloon",
560
            "pilot.login" => "Pilot",
561
            "flightType.nom" => "FlightType",
562
            "organisator.login" => "Organisator",
563
            "receiver.login" => "Percepteur",
564
        );
565
        $this->export_sql_start[$r] = 'SELECT DISTINCT ';
566
        $this->export_sql_end[$r] = ' FROM ' . MAIN_DB_PREFIX . 'bbc_vols as flight';
567
        $this->export_sql_end[$r] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'bbc_ballons as balloon on (flight.BBC_ballons_idBBC_ballons = balloon.rowid)';
568
        $this->export_sql_end[$r] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'bbc_types as flightType on (flight.fk_type = flightType.idType)';
569
        $this->export_sql_end[$r] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'user as pilot on (flight.fk_pilot = pilot.rowid)';
570
        $this->export_sql_end[$r] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'user as organisator on (flight.fk_organisateur = organisator.rowid)';
571
        $this->export_sql_end[$r] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'user as receiver on (flight.fk_receiver = receiver.rowid)';
572
        $this->export_sql_end[$r] .= ' WHERE 1 = 1';
573
    }
574
575
    /**
576
     * Activate triggers for this module
577
     */
578
    private function activateTriggers()
579
    {
580
        $this->module_parts['triggers'] = 1;
581
    }
582
583
    /**
584
     * Initialize all workflows
585
     */
586
    private function initWorkflows()
587
    {
588
        $this->module_parts['workflow'] = [
589
            "WORKFLOW_BBC_FLIGHTLOG_SEND_MAIL_ON_INCIDENT" => [
590
                'family' => 'create',
591
                'position' => 10,
592
                'enabled' => '1',
593
                'picto' => 'order'
594
            ],
595
        ];
596
    }
597
598
    /**
599
     * Add stylesheets
600
     */
601
    private function configureCss()
602
    {
603
        $this->module_parts['css'] = [
604
            '/flightlog/css/flightlog.css',
605
        ];
606
    }
607
608
}
609
610