/
modules.php
1419 lines (1239 loc) · 58.8 KB
/
modules.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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/* Copyright (C) 2003-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2003 Jean-Louis Bergamo <jlb@j1b.org>
* Copyright (C) 2004-2017 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
* Copyright (C) 2005-2017 Regis Houssin <regis.houssin@inodbox.com>
* Copyright (C) 2011-2023 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
* Copyright (C) 2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
* Copyright (C) 2018 Nicolas ZABOURI <info@inovea-conseil.com>
* Copyright (C) 2021-2023 Frédéric France <frederic.france@netlogic.fr>
* Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
*
* This program 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.
*
* This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
*/
/**
* \file htdocs/admin/modules.php
* \brief Page to activate/disable all modules
*/
if (!defined('CSRFCHECK_WITH_TOKEN') && (empty($_GET['action']) || $_GET['action'] != 'reset')) { // We force security except to disable modules so we can do it if a problem occurs on a module
define('CSRFCHECK_WITH_TOKEN', '1'); // Force use of CSRF protection with tokens even for GET
}
// Load Dolibarr environment
require '../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/geturl.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
require_once DOL_DOCUMENT_ROOT.'/admin/dolistore/class/dolistore.class.php';
// Load translation files required by the page
$langs->loadLangs(array("errors", "admin", "modulebuilder"));
// if we set another view list mode, we keep it (till we change one more time)
if (GETPOSTISSET('mode')) {
$mode = GETPOST('mode', 'alpha');
if ($mode == 'common' || $mode == 'commonkanban') {
dolibarr_set_const($db, "MAIN_MODULE_SETUP_ON_LIST_BY_DEFAULT", $mode, 'chaine', 0, '', $conf->entity);
}
} else {
$mode = (!getDolGlobalString('MAIN_MODULE_SETUP_ON_LIST_BY_DEFAULT') ? 'commonkanban' : $conf->global->MAIN_MODULE_SETUP_ON_LIST_BY_DEFAULT);
}
$action = GETPOST('action', 'aZ09');
$value = GETPOST('value', 'alpha');
$page_y = GETPOSTINT('page_y');
$search_keyword = GETPOST('search_keyword', 'alpha');
$search_status = GETPOST('search_status', 'alpha');
$search_nature = GETPOST('search_nature', 'alpha');
$search_version = GETPOST('search_version', 'alpha');
// For dolistore search
$options = array();
$options['per_page'] = 20;
$options['categorie'] = ((int) (GETPOSTINT('categorie') ? GETPOSTINT('categorie') : 0));
$options['start'] = ((int) (GETPOSTINT('start') ? GETPOSTINT('start') : 0));
$options['end'] = ((int) (GETPOSTINT('end') ? GETPOSTINT('end') : 0));
$options['search'] = GETPOST('search_keyword', 'alpha');
$dolistore = new Dolistore(false);
if (!$user->admin) {
accessforbidden();
}
$familyinfo = array(
'hr' => array('position' => '001', 'label' => $langs->trans("ModuleFamilyHr")),
'crm' => array('position' => '006', 'label' => $langs->trans("ModuleFamilyCrm")),
'srm' => array('position' => '007', 'label' => $langs->trans("ModuleFamilySrm")),
'financial' => array('position' => '009', 'label' => $langs->trans("ModuleFamilyFinancial")),
'products' => array('position' => '012', 'label' => $langs->trans("ModuleFamilyProducts")),
'projects' => array('position' => '015', 'label' => $langs->trans("ModuleFamilyProjects")),
'ecm' => array('position' => '018', 'label' => $langs->trans("ModuleFamilyECM")),
'technic' => array('position' => '021', 'label' => $langs->trans("ModuleFamilyTechnic")),
'portal' => array('position' => '040', 'label' => $langs->trans("ModuleFamilyPortal")),
'interface' => array('position' => '050', 'label' => $langs->trans("ModuleFamilyInterface")),
'base' => array('position' => '060', 'label' => $langs->trans("ModuleFamilyBase")),
'other' => array('position' => '100', 'label' => $langs->trans("ModuleFamilyOther")),
);
$param = '';
if (!GETPOST('buttonreset', 'alpha')) {
if ($search_keyword) {
$param .= '&search_keyword='.urlencode($search_keyword);
}
if ($search_status && $search_status != '-1') {
$param .= '&search_status='.urlencode($search_status);
}
if ($search_nature && $search_nature != '-1') {
$param .= '&search_nature='.urlencode($search_nature);
}
if ($search_version && $search_version != '-1') {
$param .= '&search_version='.urlencode($search_version);
}
}
$dirins = DOL_DOCUMENT_ROOT.'/custom';
$urldolibarrmodules = 'https://www.dolistore.com/';
// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
$hookmanager->initHooks(array('adminmodules', 'globaladmin'));
// Execution Time
$max_execution_time_for_deploy = (!getDolGlobalString('MODULE_UPLOAD_MAX_EXECUTION_TIME') ? 300 : $conf->global->MODULE_UPLOAD_MAX_EXECUTION_TIME); // 5mn if not defined
$max_time = @ini_get("max_execution_time");
if ($max_time && $max_time < $max_execution_time_for_deploy) {
dol_syslog("max_execution_time=".$max_time." is lower than max_execution_time_for_deploy=".$max_execution_time_for_deploy.". We try to increase it dynamically.");
@ini_set("max_execution_time", $max_execution_time_for_deploy); // This work only if safe mode is off. also web servers has timeout of 300
}
$dolibarrdataroot = preg_replace('/([\\/]+)$/i', '', DOL_DATA_ROOT);
$allowonlineinstall = true;
$allowfromweb = 1;
if (dol_is_file($dolibarrdataroot.'/installmodules.lock')) {
$allowonlineinstall = false;
}
/*
* Actions
*/
$formconfirm = '';
$parameters = array();
$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
if ($reshook < 0) {
setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
}
if (GETPOST('buttonreset', 'alpha')) {
$search_keyword = '';
$search_status = '';
$search_nature = '';
$search_version = '';
}
if ($action == 'install' && $allowonlineinstall) {
$error = 0;
// $original_file should match format module_modulename-x.y[.z].zip
$original_file = basename($_FILES["fileinstall"]["name"]);
$original_file = preg_replace('/\s*\(\d+\)\.zip$/i', '.zip', $original_file);
$newfile = $conf->admin->dir_temp.'/'.$original_file.'/'.$original_file;
if (!$original_file) {
$langs->load("Error");
setEventMessages($langs->trans("ErrorModuleFileRequired"), null, 'warnings');
$error++;
} else {
if (!$error && !preg_match('/\.zip$/i', $original_file)) {
$langs->load("errors");
setEventMessages($langs->trans("ErrorFileMustBeADolibarrPackage", $original_file), null, 'errors');
$error++;
}
if (!$error && !preg_match('/^(module[a-zA-Z0-9]*|theme)_.*\-([0-9][0-9\.]*)\.zip$/i', $original_file)) {
$langs->load("errors");
setEventMessages($langs->trans("ErrorFilenameDosNotMatchDolibarrPackageRules", $original_file, 'module_*-x.y*.zip'), null, 'errors');
$error++;
}
if (empty($_FILES['fileinstall']['tmp_name'])) {
$langs->load("errors");
setEventMessages($langs->trans("ErrorFileNotUploaded"), null, 'errors');
$error++;
}
}
if (!$error) {
if ($original_file) {
@dol_delete_dir_recursive($conf->admin->dir_temp.'/'.$original_file);
dol_mkdir($conf->admin->dir_temp.'/'.$original_file);
}
$tmpdir = preg_replace('/\.zip$/i', '', $original_file).'.dir';
if ($tmpdir) {
@dol_delete_dir_recursive($conf->admin->dir_temp.'/'.$tmpdir);
dol_mkdir($conf->admin->dir_temp.'/'.$tmpdir);
}
$result = dol_move_uploaded_file($_FILES['fileinstall']['tmp_name'], $newfile, 1, 0, $_FILES['fileinstall']['error']);
if ($result > 0) {
$result = dol_uncompress($newfile, $conf->admin->dir_temp.'/'.$tmpdir);
if (!empty($result['error'])) {
$langs->load("errors");
setEventMessages($langs->trans($result['error'], $original_file), null, 'errors');
$error++;
} else {
// Now we move the dir of the module
$modulename = preg_replace('/module_/', '', $original_file);
$modulename = preg_replace('/\-([0-9][0-9\.]*)\.zip$/i', '', $modulename);
// Search dir $modulename
$modulenamedir = $conf->admin->dir_temp.'/'.$tmpdir.'/'.$modulename; // Example ./mymodule
if (!dol_is_dir($modulenamedir)) {
$modulenamedir = $conf->admin->dir_temp.'/'.$tmpdir.'/htdocs/'.$modulename; // Example ./htdocs/mymodule
//var_dump($modulenamedir);
if (!dol_is_dir($modulenamedir)) {
setEventMessages($langs->trans("ErrorModuleFileSeemsToHaveAWrongFormat").'<br>'.$langs->trans("ErrorModuleFileSeemsToHaveAWrongFormat2", $modulename, 'htdocs/'.$modulename), null, 'errors');
$error++;
}
}
if (!$error) {
// TODO Make more test
}
dol_syslog("Uncompress of module file is a success.");
// We check if this is a metapackage
$modulenamearrays = array();
if (dol_is_file($modulenamedir.'/metapackage.conf')) {
// This is a meta package
$metafile = file_get_contents($modulenamedir.'/metapackage.conf');
$modulenamearrays = explode("\n", $metafile);
}
$modulenamearrays[$modulename] = $modulename;
//var_dump($modulenamearrays);exit;
// Lop on each package of the metapackage
foreach ($modulenamearrays as $modulenameval) {
if (strpos($modulenameval, '#') === 0) {
continue; // Discard comments
}
if (strpos($modulenameval, '//') === 0) {
continue; // Discard comments
}
if (!trim($modulenameval)) {
continue;
}
// Now we install the module
if (!$error) {
@dol_delete_dir_recursive($dirins.'/'.$modulenameval); // delete the target directory
$submodulenamedir = $conf->admin->dir_temp.'/'.$tmpdir.'/'.$modulenameval;
if (!dol_is_dir($submodulenamedir)) {
$submodulenamedir = $conf->admin->dir_temp.'/'.$tmpdir.'/htdocs/'.$modulenameval;
}
dol_syslog("We copy now directory ".$submodulenamedir." into target dir ".$dirins.'/'.$modulenameval);
$result = dolCopyDir($submodulenamedir, $dirins.'/'.$modulenameval, '0444', 1);
if ($result <= 0) {
dol_syslog('Failed to call dolCopyDir result='.$result." with param ".$submodulenamedir." and ".$dirins.'/'.$modulenameval, LOG_WARNING);
$langs->load("errors");
setEventMessages($langs->trans("ErrorFailToCopyDir", $submodulenamedir, $dirins.'/'.$modulenameval), null, 'errors');
$error++;
}
}
}
}
} else {
setEventMessages($langs->trans("ErrorFailToRenameFile", $_FILES['fileinstall']['tmp_name'], $newfile), null, 'errors');
$error++;
}
}
if (!$error) {
setEventMessages($langs->trans("SetupIsReadyForUse", DOL_URL_ROOT.'/admin/modules.php?mainmenu=home', $langs->transnoentitiesnoconv("Home").' - '.$langs->transnoentitiesnoconv("Setup").' - '.$langs->transnoentitiesnoconv("Modules")), null, 'warnings');
}
} elseif ($action == 'install' && !$allowonlineinstall) {
httponly_accessforbidden("You try to bypass the protection to disallow deployment of an external module. Hack attempt ?");
}
if ($action == 'set' && $user->admin) {
$checkOldValue = getDolGlobalInt('CHECKLASTVERSION_EXTERNALMODULE');
$csrfCheckOldValue = getDolGlobalInt('MAIN_SECURITY_CSRF_WITH_TOKEN');
$resarray = activateModule($value);
if ($checkOldValue != getDolGlobalInt('CHECKLASTVERSION_EXTERNALMODULE')) {
setEventMessage($langs->trans('WarningModuleHasChangedLastVersionCheckParameter', $value), 'warnings');
}
if ($csrfCheckOldValue != getDolGlobalInt('MAIN_SECURITY_CSRF_WITH_TOKEN')) {
setEventMessage($langs->trans('WarningModuleHasChangedSecurityCsrfParameter', $value), 'warnings');
}
dolibarr_set_const($db, "MAIN_IHM_PARAMS_REV", getDolGlobalInt('MAIN_IHM_PARAMS_REV') + 1, 'chaine', 0, '', $conf->entity);
if (!empty($resarray['errors'])) {
setEventMessages('', $resarray['errors'], 'errors');
} else {
//var_dump($resarray);exit;
if ($resarray['nbperms'] > 0) {
$tmpsql = "SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX."user WHERE admin <> 1";
$resqltmp = $db->query($tmpsql);
if ($resqltmp) {
$obj = $db->fetch_object($resqltmp);
//var_dump($obj->nb);exit;
if ($obj && $obj->nb > 1) {
$msg = $langs->trans('ModuleEnabledAdminMustCheckRights');
setEventMessages($msg, null, 'warnings');
}
} else {
dol_print_error($db);
}
}
}
header("Location: ".$_SERVER["PHP_SELF"]."?mode=".$mode.$param.($page_y ? '&page_y='.$page_y : ''));
exit;
} elseif ($action == 'reset' && $user->admin && GETPOST('confirm') == 'yes') {
$result = unActivateModule($value);
dolibarr_set_const($db, "MAIN_IHM_PARAMS_REV", getDolGlobalInt('MAIN_IHM_PARAMS_REV') + 1, 'chaine', 0, '', $conf->entity);
if ($result) {
setEventMessages($result, null, 'errors');
}
header("Location: ".$_SERVER["PHP_SELF"]."?mode=".$mode.$param.($page_y ? '&page_y='.$page_y : ''));
exit;
} elseif (getDolGlobalInt("MAIN_FEATURES_LEVEL") > 1 && $action == 'reload' && $user->admin && GETPOST('confirm') == 'yes') {
$result = unActivateModule($value, 0);
dolibarr_set_const($db, "MAIN_IHM_PARAMS_REV", (int) $conf->global->MAIN_IHM_PARAMS_REV + 1, 'chaine', 0, '', $conf->entity);
if ($result) {
setEventMessages($result, null, 'errors');
header("Location: ".$_SERVER["PHP_SELF"]."?mode=".$mode.$param.($page_y ? '&page_y='.$page_y : ''));
}
$resarray = activateModule($value, 0, 1);
dolibarr_set_const($db, "MAIN_IHM_PARAMS_REV", (int) $conf->global->MAIN_IHM_PARAMS_REV + 1, 'chaine', 0, '', $conf->entity);
if (!empty($resarray['errors'])) {
setEventMessages('', $resarray['errors'], 'errors');
} else {
if ($resarray['nbperms'] > 0) {
$tmpsql = "SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX."user WHERE admin <> 1";
$resqltmp = $db->query($tmpsql);
if ($resqltmp) {
$obj = $db->fetch_object($resqltmp);
if ($obj && $obj->nb > 1) {
$msg = $langs->trans('ModuleEnabledAdminMustCheckRights');
setEventMessages($msg, null, 'warnings');
}
} else {
dol_print_error($db);
}
}
}
header("Location: ".$_SERVER["PHP_SELF"]."?mode=".$mode.$param.($page_y ? '&page_y='.$page_y : ''));
exit;
}
/*
* View
*/
$form = new Form($db);
$morejs = array();
$morecss = array("/admin/dolistore/css/dolistore.css");
// Set dir where external modules are installed
if (!dol_is_dir($dirins)) {
dol_mkdir($dirins);
}
$dirins_ok = (dol_is_dir($dirins));
$help_url = 'EN:First_setup|FR:Premiers_paramétrages|ES:Primeras_configuraciones';
llxHeader('', $langs->trans("Setup"), $help_url, '', '', '', $morejs, $morecss, 0, 0);
// Search modules dirs
$modulesdir = dolGetModulesDirs();
$arrayofnatures = array(
'core' => array('label' => $langs->transnoentitiesnoconv("NativeModules")),
'external' => array('label' => $langs->transnoentitiesnoconv("External").' - ['.$langs->trans("AllPublishers").']')
);
$arrayofwarnings = array(); // Array of warning each module want to show when activated
$arrayofwarningsext = array(); // Array of warning each module want to show when we activate an external module
$filename = array();
$modules = array();
$orders = array();
$categ = array();
$publisherlogoarray = array();
$i = 0; // is a sequencer of modules found
$j = 0; // j is module number. Automatically affected if module number not defined.
$modNameLoaded = array();
foreach ($modulesdir as $dir) {
// Load modules attributes in arrays (name, numero, orders) from dir directory
//print $dir."\n<br>";
dol_syslog("Scan directory ".$dir." for module descriptor files (modXXX.class.php)");
$handle = @opendir($dir);
if (is_resource($handle)) {
while (($file = readdir($handle)) !== false) {
//print "$i ".$file."\n<br>";
if (is_readable($dir.$file) && substr($file, 0, 3) == 'mod' && substr($file, dol_strlen($file) - 10) == '.class.php') {
$modName = substr($file, 0, dol_strlen($file) - 10);
if ($modName) {
if (!empty($modNameLoaded[$modName])) { // In cache of already loaded modules ?
$mesg = "Error: Module ".$modName." was found twice: Into ".$modNameLoaded[$modName]." and ".$dir.". You probably have an old file on your disk.<br>";
setEventMessages($mesg, null, 'warnings');
dol_syslog($mesg, LOG_ERR);
continue;
}
try {
$res = include_once $dir.$file; // A class already exists in a different file will send a non catchable fatal error.
if (class_exists($modName)) {
$objMod = new $modName($db);
'@phan-var-force DolibarrModules $objMod';
$modNameLoaded[$modName] = $dir;
if (!$objMod->numero > 0 && $modName != 'modUser') {
dol_syslog('The module descriptor '.$modName.' must have a numero property', LOG_ERR);
}
$j = $objMod->numero;
$modulequalified = 1;
// We discard modules according to features level (PS: if module is activated we always show it)
$const_name = 'MAIN_MODULE_'.strtoupper(preg_replace('/^mod/i', '', get_class($objMod)));
if ($objMod->version == 'development' && (!getDolGlobalString($const_name) && (getDolGlobalInt('MAIN_FEATURES_LEVEL') < 2))) {
$modulequalified = 0;
}
if ($objMod->version == 'experimental' && (!getDolGlobalString($const_name) && (getDolGlobalInt('MAIN_FEATURES_LEVEL') < 1))) {
$modulequalified = 0;
}
if (preg_match('/deprecated/', $objMod->version) && (!getDolGlobalString($const_name) && (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 0))) {
$modulequalified = 0;
}
// We discard modules according to property ->hidden
if (!empty($objMod->hidden)) {
$modulequalified = 0;
}
if ($modulequalified > 0) {
$publisher = dol_escape_htmltag($objMod->getPublisher());
$external = ($objMod->isCoreOrExternalModule() == 'external');
if ($external) {
if ($publisher) {
// Check if there is a logo forpublisher
/* Do not show the company logo in combo. Make combo list dirty.
if (!empty($objMod->editor_squarred_logo)) {
$publisherlogoarray['external_'.$publisher] = img_picto('', $objMod->editor_squarred_logo, 'class="publisherlogoinline"');
}
$publisherlogo = empty($publisherlogoarray['external_'.$publisher]) ? '' : $publisherlogoarray['external_'.$publisher];
*/
$arrayofnatures['external_'.$publisher] = array('label' => $langs->trans("External").' - '.$publisher, 'data-html' => $langs->trans("External").' - <span class="opacitymedium inine-block valignmiddle">'.$publisher.'</span>');
} else {
$arrayofnatures['external_'] = array('label' => $langs->trans("External").' - ['.$langs->trans("UnknownPublishers").']');
}
}
ksort($arrayofnatures);
// Define array $categ with categ with at least one qualified module
$filename[$i] = $modName;
$modules[$modName] = $objMod;
// Gives the possibility to the module, to provide his own family info and position of this family
if (is_array($objMod->familyinfo) && !empty($objMod->familyinfo)) {
$familyinfo = array_merge($familyinfo, $objMod->familyinfo);
$familykey = key($objMod->familyinfo);
} else {
$familykey = $objMod->family;
}
'@phan-var-force string $familykey'; // if not, phan considers $familykey may be null
$moduleposition = ($objMod->module_position ? $objMod->module_position : '50');
if ($objMod->isCoreOrExternalModule() == 'external' && $moduleposition < 100000) {
// an external module should never return a value lower than '80'.
$moduleposition = '80'; // External modules at end by default
}
// Add list of warnings to show into arrayofwarnings and arrayofwarningsext
if (!empty($objMod->warnings_activation)) {
$arrayofwarnings[$modName] = $objMod->warnings_activation;
}
if (!empty($objMod->warnings_activation_ext)) {
$arrayofwarningsext[$modName] = $objMod->warnings_activation_ext;
}
$familyposition = (empty($familyinfo[$familykey]['position']) ? '0' : $familyinfo[$familykey]['position']);
$listOfOfficialModuleGroups = array('hr', 'technic', 'interface', 'technic', 'portal', 'financial', 'crm', 'base', 'products', 'srm', 'ecm', 'projects', 'other');
if ($external && !in_array($familykey, $listOfOfficialModuleGroups)) {
// If module is extern and into a custom group (not into an official predefined one), it must appear at end (custom groups should not be before official groups).
if (is_numeric($familyposition)) {
$familyposition = sprintf("%03d", (int) $familyposition + 100);
}
}
$orders[$i] = $familyposition."_".$familykey."_".$moduleposition."_".$j; // Sort by family, then by module position then number
// Set categ[$i]
$specialstring = 'unknown';
if ($objMod->version == 'development' || $objMod->version == 'experimental') {
$specialstring = 'expdev';
}
if (isset($categ[$specialstring])) {
$categ[$specialstring]++; // Array of all different modules categories
} else {
$categ[$specialstring] = 1;
}
$j++;
$i++;
} else {
dol_syslog("Module ".get_class($objMod)." not qualified");
}
} else {
print info_admin("admin/modules.php Warning bad descriptor file : ".$dir.$file." (Class ".$modName." not found into file)", 0, 0, '1', 'warning');
}
} catch (Exception $e) {
dol_syslog("Failed to load ".$dir.$file." ".$e->getMessage(), LOG_ERR);
}
}
}
}
closedir($handle);
} else {
dol_syslog("htdocs/admin/modules.php: Failed to open directory ".$dir.". See permission and open_basedir option.", LOG_WARNING);
}
}
if ($action == 'reset_confirm' && $user->admin) {
if (!empty($modules[$value])) {
$objMod = $modules[$value];
if (!empty($objMod->langfiles)) {
$langs->loadLangs($objMod->langfiles);
}
$form = new Form($db);
$formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?value='.$value.'&mode='.$mode.$param, $langs->trans('ConfirmUnactivation'), $langs->trans(GETPOST('confirm_message_code')), 'reset', '', 'no', 1);
}
}
if ($action == 'reload_confirm' && $user->admin) {
if (!empty($modules[$value])) {
$objMod = $modules[$value];
if (!empty($objMod->langfiles)) {
$langs->loadLangs($objMod->langfiles);
}
$form = new Form($db);
$formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?value='.$value.'&mode='.$mode.$param, $langs->trans('ConfirmReload'), $langs->trans(GETPOST('confirm_message_code')), 'reload', '', 'no', 1);
}
}
print $formconfirm;
asort($orders);
//var_dump($orders);
//var_dump($categ);
//var_dump($modules);
$nbofactivatedmodules = count($conf->modules);
$nbmodulesnotautoenabled = count($conf->modules);
if (in_array('fckeditor', $conf->modules)) {
$nbmodulesnotautoenabled--;
}
if (in_array('export', $conf->modules)) {
$nbmodulesnotautoenabled--;
}
if (in_array('import', $conf->modules)) {
$nbmodulesnotautoenabled--;
}
print load_fiche_titre($langs->trans("ModulesSetup"), '', 'title_setup');
// Start to show page
$deschelp = '';
if ($mode == 'common' || $mode == 'commonkanban') {
$desc = $langs->trans("ModulesDesc", '{picto}');
$desc .= ' '.$langs->trans("ModulesDesc2", '{picto2}');
$desc = str_replace('{picto}', img_picto('', 'switch_off', 'class="size15x"'), $desc);
$desc = str_replace('{picto2}', img_picto('', 'setup', 'class="size15x"'), $desc);
if ($nbmodulesnotautoenabled <= getDolGlobalInt('MAIN_MIN_NB_ENABLED_MODULE_FOR_WARNING', 1)) { // If only minimal initial modules enabled
$deschelp .= '<div class="info hideonsmartphone">'.$desc."<br></div>\n";
}
if (getDolGlobalString('MAIN_SETUP_MODULES_INFO')) { // Show a custom message
$deschelp .= '<div class="info">'.$langs->trans(getDolGlobalString('MAIN_SETUP_MODULES_INFO'))."<br></div>\n";
}
if ($deschelp) {
$deschelp .= '<br>';
}
}
if ($mode == 'marketplace') {
//$deschelp = '<div class="info hideonsmartphone">'.$langs->trans("ModulesMarketPlaceDesc")."<br></div><br>\n";
}
if ($mode == 'deploy') {
$deschelp = '<div class="info hideonsmartphone">'.$langs->trans("ModulesDeployDesc", $langs->transnoentitiesnoconv("AvailableModules"))."<br></div><br>\n";
}
if ($mode == 'develop') {
$deschelp = '<div class="info hideonsmartphone">'.$langs->trans("ModulesDevelopDesc")."<br></div><br>\n";
}
$head = modules_prepare_head($nbofactivatedmodules, count($modules), $nbmodulesnotautoenabled);
if ($mode == 'common' || $mode == 'commonkanban') {
dol_set_focus('#search_keyword');
print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
print '<input type="hidden" name="token" value="'.newToken().'">';
if (isset($optioncss) && $optioncss != '') {
print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
}
if (isset($sortfield) && $sortfield != '') {
print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
}
if (isset($sortorder) && $sortorder != '') {
print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
}
if (isset($page) && $page != '') {
print '<input type="hidden" name="page" value="'.$page.'">';
}
print '<input type="hidden" name="mode" value="'.$mode.'">';
print dol_get_fiche_head($head, 'modules', '', -1);
print $deschelp;
$moreforfilter = '<div class="valignmiddle">';
$moreforfilter .= '<div class="floatright right pagination paddingtop --module-list"><ul><li>';
$moreforfilter .= dolGetButtonTitle($langs->trans('CheckForModuleUpdate'), $langs->trans('CheckForModuleUpdate').'<br>'.$langs->trans('CheckForModuleUpdateHelp'), 'fa fa-sync', $_SERVER["PHP_SELF"].'?action=checklastversion&token='.newToken().'&mode='.$mode.$param, '', 1, array('morecss' => 'reposition'));
$moreforfilter .= dolGetButtonTitleSeparator();
$moreforfilter .= dolGetButtonTitle($langs->trans('ViewList'), '', 'fa fa-bars imgforviewmode', $_SERVER["PHP_SELF"].'?mode=common'.$param, '', ($mode == 'common' ? 2 : 1), array('morecss' => 'reposition'));
$moreforfilter .= dolGetButtonTitle($langs->trans('ViewKanban'), '', 'fa fa-th-list imgforviewmode', $_SERVER["PHP_SELF"].'?mode=commonkanban'.$param, '', ($mode == 'commonkanban' ? 2 : 1), array('morecss' => 'reposition'));
$moreforfilter .= '</li></ul></div>';
$moreforfilter .= '<div class="divfilteralone colorbacktimesheet float valignmiddle">';
$moreforfilter .= '<div class="divsearchfield paddingtop paddingbottom valignmiddle inline-block">';
$moreforfilter .= img_picto($langs->trans("Filter"), 'filter', 'class="paddingright opacityhigh hideonsmartphone"').'<input type="text" id="search_keyword" name="search_keyword" class="maxwidth125" value="'.dol_escape_htmltag($search_keyword).'" placeholder="'.dol_escape_htmltag($langs->trans('Keyword')).'">';
$moreforfilter .= '</div>';
$moreforfilter .= '<div class="divsearchfield paddingtop paddingbottom valignmiddle inline-block">';
$moreforfilter .= $form->selectarray('search_nature', $arrayofnatures, dol_escape_htmltag($search_nature), $langs->trans('Origin'), 0, 0, '', 0, 0, 0, '', 'maxwidth250', 1);
$moreforfilter .= '</div>';
if (getDolGlobalInt('MAIN_FEATURES_LEVEL')) {
$array_version = array('stable' => $langs->transnoentitiesnoconv("Stable"));
if (getDolGlobalInt('MAIN_FEATURES_LEVEL') < 0) {
$array_version['deprecated'] = $langs->trans("Deprecated");
}
if (getDolGlobalInt('MAIN_FEATURES_LEVEL') > 0) {
$array_version['experimental'] = $langs->trans("Experimental");
}
if (getDolGlobalInt('MAIN_FEATURES_LEVEL') > 1) {
$array_version['development'] = $langs->trans("Development");
}
$moreforfilter .= '<div class="divsearchfield paddingtop paddingbottom valignmiddle inline-block">';
$moreforfilter .= $form->selectarray('search_version', $array_version, $search_version, $langs->transnoentitiesnoconv('Version'), 0, 0, '', 0, 0, 0, '', 'maxwidth150', 1);
$moreforfilter .= '</div>';
}
$array_status = array('active' => $langs->transnoentitiesnoconv("Enabled"), 'disabled' => $langs->transnoentitiesnoconv("Disabled"));
$moreforfilter .= '<div class="divsearchfield paddingtop paddingbottom valignmiddle inline-block">';
$moreforfilter .= $form->selectarray('search_status', $array_status, $search_status, $langs->transnoentitiesnoconv('Status'), 0, 0, '', 0, 0, 0, '', 'maxwidth150', 1);
$moreforfilter .= '</div>';
$moreforfilter .= ' ';
$moreforfilter .= '<div class="divsearchfield valignmiddle inline-block">';
$moreforfilter .= '<input type="submit" name="buttonsubmit" class="button small nomarginleft" value="'.dol_escape_htmltag($langs->trans("Refresh")).'">';
if ($search_keyword || ($search_nature && $search_nature != '-1') || ($search_version && $search_version != '-1') || ($search_status && $search_status != '-1')) {
$moreforfilter .= ' ';
$moreforfilter .= '<input type="submit" name="buttonreset" class="buttonreset noborderbottom" value="'.dol_escape_htmltag($langs->trans("Reset")).'">';
}
$moreforfilter .= '</div>';
$moreforfilter .= '</div>';
$moreforfilter .= '</div>';
if (!empty($moreforfilter)) {
print $moreforfilter;
$parameters = array();
$reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook
print $hookmanager->resPrint;
}
$moreforfilter = '';
print '<div class="clearboth"></div><br>';
$object = new stdClass();
$parameters = array();
$reshook = $hookmanager->executeHooks('insertExtraHeader', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
if ($reshook < 0) {
setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
}
$disabled_modules = array();
if (!empty($_SESSION["disablemodules"])) {
$disabled_modules = explode(',', $_SESSION["disablemodules"]);
}
// Show list of modules
$oldfamily = '';
$foundoneexternalmodulewithupdate = 0;
$linenum = 0;
$atleastonequalified = 0;
$atleastoneforfamily = 0;
foreach ($orders as $key => $value) {
$linenum++;
$tab = explode('_', $value);
$familykey = $tab[1];
$module_position = $tab[2];
$modName = $filename[$key];
/** @var DolibarrModules $objMod */
$objMod = $modules[$modName];
//print $objMod->name." - ".$key." - ".$objMod->version."<br>";
if ($mode == 'expdev' && $objMod->version != 'development' && $objMod->version != 'experimental') {
continue; // Discard if not for current tab
}
if (!$objMod->getName()) {
dol_syslog("Error for module ".$key." - Property name of module looks empty", LOG_WARNING);
continue;
}
$modulenameshort = strtolower(preg_replace('/^mod/i', '', get_class($objMod)));
$const_name = 'MAIN_MODULE_'.strtoupper(preg_replace('/^mod/i', '', get_class($objMod)));
// Check filters
$modulename = $objMod->getName();
$moduletechnicalname = $objMod->name;
$moduledesc = $objMod->getDesc();
$moduledesclong = $objMod->getDescLong();
$moduleauthor = $objMod->getPublisher();
// We discard showing according to filters
if ($search_keyword) {
$qualified = 0;
if (preg_match('/'.preg_quote($search_keyword, '/').'/i', $modulename)
|| preg_match('/'.preg_quote($search_keyword, '/').'/i', $moduletechnicalname)
|| ($moduledesc && preg_match('/'.preg_quote($search_keyword, '/').'/i', $moduledesc))
|| ($moduledesclong && preg_match('/'.preg_quote($search_keyword, '/').'/i', $moduledesclong))
|| ($moduleauthor && preg_match('/'.preg_quote($search_keyword, '/').'/i', $moduleauthor))
) {
$qualified = 1;
}
if (!$qualified) {
continue;
}
}
if ($search_status) {
if ($search_status == 'active' && !getDolGlobalString($const_name)) {
continue;
}
if ($search_status == 'disabled' && getDolGlobalString($const_name)) {
continue;
}
}
if ($search_nature) {
if (preg_match('/^external/', $search_nature) && $objMod->isCoreOrExternalModule() != 'external') {
continue;
}
$reg = array();
if (preg_match('/^external_(.*)$/', $search_nature, $reg)) {
//print $reg[1].'-'.dol_escape_htmltag($objMod->getPublisher());
$publisher = dol_escape_htmltag($objMod->getPublisher());
if ($reg[1] && dol_escape_htmltag($reg[1]) != $publisher) {
continue;
}
if (!$reg[1] && !empty($publisher)) {
continue;
}
}
if ($search_nature == 'core' && $objMod->isCoreOrExternalModule() == 'external') {
continue;
}
}
if ($search_version) {
if (($objMod->version == 'development' || $objMod->version == 'experimental' || preg_match('/deprecated/', $objMod->version)) && $search_version == 'stable') {
continue;
}
if ($objMod->version != 'development' && ($search_version == 'development')) {
continue;
}
if ($objMod->version != 'experimental' && ($search_version == 'experimental')) {
continue;
}
if (!preg_match('/deprecated/', $objMod->version) && ($search_version == 'deprecated')) {
continue;
}
}
$atleastonequalified++;
// Load all language files of the qualified module
if (isset($objMod->langfiles) && is_array($objMod->langfiles)) {
foreach ($objMod->langfiles as $domain) {
$langs->load($domain);
}
}
// Print a separator if we change family
if ($familykey != $oldfamily) {
if ($oldfamily) {
print '</table></div><br>';
}
$familytext = empty($familyinfo[$familykey]['label']) ? $familykey : $familyinfo[$familykey]['label'];
print load_fiche_titre($familytext, '', '', 0, '', 'modulefamilygroup');
if ($mode == 'commonkanban') {
print '<div class="box-flex-container kanban">';
} else {
print '<div class="div-table-responsive">';
print '<table class="tagtable liste" summary="list_of_modules">'."\n";
}
$atleastoneforfamily = 0;
}
$atleastoneforfamily++;
if ($familykey != $oldfamily) {
$familytext = empty($familyinfo[$familykey]['label']) ? $familykey : $familyinfo[$familykey]['label'];
$oldfamily = $familykey;
}
// Version (with picto warning or not)
$version = $objMod->getVersion(0);
$versiontrans = '';
$warningstring = '';
if (preg_match('/development/i', $version)) {
$warningstring = $langs->trans("Development");
}
if (preg_match('/experimental/i', $version)) {
$warningstring = $langs->trans("Experimental");
}
if (preg_match('/deprecated/i', $version)) {
$warningstring = $langs->trans("Deprecated");
}
if ($objMod->isCoreOrExternalModule() == 'external' || preg_match('/development|experimental|deprecated/i', $version)) {
$versiontrans .= $objMod->getVersion(1);
}
if ($objMod->isCoreOrExternalModule() == 'external'
&& (
$action == 'checklastversion'
// This is a bad practice to activate a check on an external access during the building of the admin page. 1 external module can hang the application.
// Adding a cron job could be a good idea: see DolibarrModules::checkForUpdate()
|| getDolGlobalString('CHECKLASTVERSION_EXTERNALMODULE')
)
) {
$checkRes = $objMod->checkForUpdate();
if ($checkRes > 0) {
setEventMessage($objMod->getName().' : '.$versiontrans.' -> '.$objMod->lastVersion);
} elseif ($checkRes < 0) {
setEventMessage($objMod->getName().' '.$langs->trans('CheckVersionFail'), 'warnings');
}
}
// Define imginfo
$imginfo = "info";
if ($objMod->isCoreOrExternalModule() == 'external') {
$imginfo = "info_black";
}
$codeenabledisable = '';
$codetoconfig = '';
// Force disable of module disabled into session (for demo for example)
if (in_array($modulenameshort, $disabled_modules)) {
$objMod->disabled = true;
}
// Activate/Disable and Setup (2 columns)
if (getDolGlobalString($const_name)) { // If module is already activated
// Set $codeenabledisable
$disableSetup = 0;
if (!empty($arrayofwarnings[$modName])) {
$codeenabledisable .= '<!-- This module has a warning to show when we activate it (note: your country is '.$mysoc->country_code.') -->'."\n";
}
if (!empty($objMod->disabled)) {
$codeenabledisable .= $langs->trans("Disabled");
} elseif (!empty($objMod->always_enabled) || ((isModEnabled('multicompany') && $objMod->core_enabled) && ($user->entity || $conf->entity != 1))) {
// @phan-suppress-next-line PhanUndeclaredMethodCall
if (method_exists($objMod, 'alreadyUsed') && $objMod->alreadyUsed()) {
$codeenabledisable .= $langs->trans("Used");
} else {
$codeenabledisable .= img_picto($langs->trans("Required"), 'switch_on', '', false, 0, 0, '', 'opacitymedium valignmiddle');
//print $langs->trans("Required");
}
if (isModEnabled('multicompany') && $user->entity) {
$disableSetup++;
}
} else {
// @phan-suppress-next-line PhanUndeclaredMethodCall
if (!empty($objMod->warnings_unactivation[$mysoc->country_code]) && method_exists($objMod, 'alreadyUsed') && $objMod->alreadyUsed()) {
$codeenabledisable .= '<a class="reposition valignmiddle" href="'.$_SERVER["PHP_SELF"].'?id='.$objMod->numero.'&token='.newToken().'&module_position='.$module_position.'&action=reset_confirm&confirm_message_code='.urlencode($objMod->warnings_unactivation[$mysoc->country_code]).'&value='.$modName.'&mode='.$mode.$param.'">';
$codeenabledisable .= img_picto($langs->trans("Activated").($warningstring ? ' '.$warningstring : ''), 'switch_on');
$codeenabledisable .= '</a>';
if (getDolGlobalInt("MAIN_FEATURES_LEVEL") > 1) {
$codeenabledisable .= ' ';
$codeenabledisable .= '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?id='.$objMod->numero.'&token='.newToken().'&module_position='.$module_position.'&action=reload_confirm&value='.$modName.'&mode='.$mode.'&confirm=yes'.$param.'">';
$codeenabledisable .= img_picto($langs->trans("Reload"), 'refresh', 'class="opacitymedium"');
$codeenabledisable .= '</a>';
}
} else {
$codeenabledisable .= '<a class="reposition valignmiddle" href="'.$_SERVER["PHP_SELF"].'?id='.$objMod->numero.'&token='.newToken().'&module_position='.$module_position.'&action=reset&value='.$modName.'&mode='.$mode.'&confirm=yes'.$param.'">';
$codeenabledisable .= img_picto($langs->trans("Activated").($warningstring ? ' '.$warningstring : ''), 'switch_on');
$codeenabledisable .= '</a>';
if (getDolGlobalInt("MAIN_FEATURES_LEVEL") > 1) {
$codeenabledisable .= ' ';
$codeenabledisable .= '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?id='.$objMod->numero.'&token='.newToken().'&module_position='.$module_position.'&action=reload&value='.$modName.'&mode='.$mode.'&confirm=yes'.$param.'">';
$codeenabledisable .= img_picto($langs->trans("Reload"), 'refresh', 'class="opacitymedium"');
$codeenabledisable .= '</a>';
}
}
}
// Set $codetoconfig
if (!empty($objMod->config_page_url) && !$disableSetup) {
$backtourlparam = '';
if ($search_keyword != '') {
$backtourlparam .= ($backtourlparam ? '&' : '?').'search_keyword='.urlencode($search_keyword); // No urlencode here, done later
}
if ($search_nature > -1) {
$backtourlparam .= ($backtourlparam ? '&' : '?').'search_nature='.urlencode($search_nature); // No urlencode here, done later
}
if ($search_version > -1) {
$backtourlparam .= ($backtourlparam ? '&' : '?').'search_version='.urlencode($search_version); // No urlencode here, done later
}
if ($search_status > -1) {
$backtourlparam .= ($backtourlparam ? '&' : '?').'search_status='.urlencode($search_status); // No urlencode here, done later
}
$backtourl = $_SERVER["PHP_SELF"].$backtourlparam;
$regs = array();
if (is_array($objMod->config_page_url)) {
$i = 0;
foreach ($objMod->config_page_url as $page) {
$urlpage = $page;
if ($i++) {
$codetoconfig .= '<a href="'.$urlpage.'" title="'.$langs->trans($page).'">'.img_picto(ucfirst($page), "setup").'</a>';
// print '<a href="'.$page.'">'.ucfirst($page).'</a> ';
} else {
if (preg_match('/^([^@]+)@([^@]+)$/i', $urlpage, $regs)) {
$urltouse = dol_buildpath('/'.$regs[2].'/admin/'.$regs[1], 1);
$codetoconfig .= '<a href="'.$urltouse.(preg_match('/\?/', $urltouse) ? '&' : '?').'save_lastsearch_values=1&backtopage='.urlencode($backtourl).'" title="'.$langs->trans("Setup").'">'.img_picto($langs->trans("Setup"), "setup", 'style="padding-right: 6px"', false, 0, 0, '', 'fa-15').'</a>';
} else {
$urltouse = $urlpage;
$codetoconfig .= '<a href="'.$urltouse.(preg_match('/\?/', $urltouse) ? '&' : '?').'save_lastsearch_values=1&backtopage='.urlencode($backtourl).'" title="'.$langs->trans("Setup").'">'.img_picto($langs->trans("Setup"), "setup", 'style="padding-right: 6px"', false, 0, 0, '', 'fa-15').'</a>';
}
}
}
} elseif (preg_match('/^([^@]+)@([^@]+)$/i', (string) $objMod->config_page_url, $regs)) {
$codetoconfig .= '<a class="valignmiddle" href="'.dol_buildpath('/'.$regs[2].'/admin/'.$regs[1], 1).'?save_lastsearch_values=1&backtopage='.urlencode($backtourl).'" title="'.$langs->trans("Setup").'">'.img_picto($langs->trans("Setup"), "setup", 'style="padding-right: 6px"', false, 0, 0, '', 'fa-15').'</a>';
} else {
$codetoconfig .= '<a class="valignmiddle" href="'.((string) $objMod->config_page_url).'?save_lastsearch_values=1&backtopage='.urlencode($backtourl).'" title="'.$langs->trans("Setup").'">'.img_picto($langs->trans("Setup"), "setup", 'style="padding-right: 6px"', false, 0, 0, '', 'fa-15').'</a>';
}
} else {
$codetoconfig .= img_picto($langs->trans("NothingToSetup"), "setup", 'class="opacitytransp" style="padding-right: 6px"', false, 0, 0, '', 'fa-15');
}
} else { // Module not yet activated
// Set $codeenabledisable
if (!empty($objMod->always_enabled)) {
// A 'always_enabled' module should not never be disabled. If this happen, we keep a link to re-enable it.
$codeenabledisable .= '<!-- Message to show: an always_enabled module has been disabled -->'."\n";
$codeenabledisable .= '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?id='.$objMod->numero.'&token='.newToken().'&module_position='.$module_position.'&action=set&token='.newToken().'&value='.$modName.'&mode='.$mode.$param.'"';
$codeenabledisable .= '>';
$codeenabledisable .= img_picto($langs->trans("Disabled"), 'switch_off');
$codeenabledisable .= "</a>\n";
} elseif (!empty($objMod->disabled)) {
$codeenabledisable .= $langs->trans("Disabled");
} else {
// Module qualified for activation
$warningmessage = '';
if (!empty($arrayofwarnings[$modName])) {
$codeenabledisable .= '<!-- This module is a core module and it may have a warning to show when we activate it (note: your country is '.$mysoc->country_code.') -->'."\n";
foreach ($arrayofwarnings[$modName] as $keycountry => $cursorwarningmessage) {
if (preg_match('/^always/', $keycountry) || ($mysoc->country_code && preg_match('/^'.$mysoc->country_code.'/', $keycountry))) {
$warningmessage .= ($warningmessage ? "\n" : "").$langs->trans($cursorwarningmessage, $objMod->getName(), $mysoc->country_code);
}
}
}
if ($objMod->isCoreOrExternalModule() == 'external' && !empty($arrayofwarningsext)) {
$codeenabledisable .= '<!-- This module is an external module and it may have a warning to show (note: your country is '.$mysoc->country_code.') -->'."\n";
foreach ($arrayofwarningsext as $keymodule => $arrayofwarningsextbycountry) {
$keymodulelowercase = strtolower(preg_replace('/^mod/', '', $keymodule));
if (in_array($keymodulelowercase, $conf->modules)) { // If module that request warning is on
foreach ($arrayofwarningsextbycountry as $keycountry => $cursorwarningmessage) {
if (preg_match('/^always/', $keycountry) || ($mysoc->country_code && preg_match('/^'.$mysoc->country_code.'/', $keycountry))) {
$warningmessage .= ($warningmessage ? "\n" : "").$langs->trans($cursorwarningmessage, $objMod->getName(), $mysoc->country_code, $modules[$keymodule]->getName());
$warningmessage .= ($warningmessage ? "\n" : "").($warningmessage ? "\n" : "").$langs->trans("Module").' : '.$objMod->getName();
if (!empty($objMod->editor_name)) {
$warningmessage .= ($warningmessage ? "\n" : "").$langs->trans("Publisher").' : '.$objMod->editor_name;
}
if (!empty($objMod->editor_name)) {
$warningmessage .= ($warningmessage ? "\n" : "").$langs->trans("ModuleTriggeringThisWarning").' : '.$modules[$keymodule]->getName();