dolibarr 25.0.0-alpha
index.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2004-2023 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2018-2019 Nicolas ZABOURI <info@inovea-conseil.com>
4 * Copyright (C) 2023 Alexandre Janniaux <alexandre.janniaux@gmail.com>
5 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
6 * Copyright (C) 2024-2026 Frédéric France <frederic.france@free.fr>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 *
21 * You can also make a direct call the page with parameter like this:
22 * htdocs/modulebuilder/index.php?module=Inventory@/pathtodolibarr/htdocs/product
23 */
24
33if (!defined('NOSCANPOSTFORINJECTION')) {
34 define('NOSCANPOSTFORINJECTION', '1'); // Do not check anti SQL+XSS injection attack test
35}
36
37// Load Dolibarr environment
38require '../main.inc.php';
39require_once DOL_DOCUMENT_ROOT . '/core/lib/functions.lib.php';
40
52'
53@phan-var-force string $dolibarr_main_document_root
54@phan-var-force string $dolibarr_main_document_root_alt
55';
56require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
57require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
58require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
59require_once DOL_DOCUMENT_ROOT.'/core/lib/modulebuilder.lib.php';
60require_once DOL_DOCUMENT_ROOT.'/modulebuilder/class/NamingContractValidator.class.php';
61require_once DOL_DOCUMENT_ROOT.'/modulebuilder/class/RightsSyncService.class.php';
62require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
63require_once DOL_DOCUMENT_ROOT.'/core/class/utils.class.php';
64
65// Load translation files required by the page
66$langs->loadLangs(array("admin", "modulebuilder", "exports", "other", "cron", "uxdocumentation"));
67
68// GET Parameters
69$action = GETPOST('action', 'aZ09');
70$confirm = GETPOST('confirm', 'alpha');
71$cancel = GETPOST('cancel', 'alpha');
72
73$sortfield = GETPOST('sortfield', 'aZ09comma');
74$sortorder = GETPOST('sortorder', 'aZ09');
75
76$module = (string) GETPOST('module', 'alpha');
77$tab = (string) GETPOST('tab', 'aZ09');
78$tabobj = GETPOST('tabobj', 'alpha');
79$tabdic = GETPOST('tabdic', 'alpha');
80$propertykey = GETPOST('propertykey', 'alpha');
81if (empty($module)) {
82 $module = 'initmodule';
83}
84if (empty($tab)) {
85 $tab = 'description';
86}
87'@phan-var-force string $tab'; // Workaround 'empty()' bug of phan
88if (empty($tabobj)) {
89 $tabobj = 'newobjectifnoobj';
90}
91if (empty($tabdic)) {
92 $tabdic = 'newdicifnodic';
93}
94$file = GETPOST('file', 'alpha');
95$find = GETPOST('find', 'alpha');
96
97$modulename = dol_sanitizeFileName(GETPOST('modulename', 'alpha'));
98$objectname = dol_sanitizeFileName(GETPOST('objectname', 'alpha'));
99$dicname = dol_sanitizeFileName(GETPOST('dicname', 'alpha'));
100$editorname = (string) GETPOST('editorname', 'alpha');
101$editorurl = (string) GETPOST('editorurl', 'alpha');
102$version = (string) GETPOST('version', 'alpha');
103$family = (string) GETPOST('family', 'alpha');
104$picto = (string) GETPOST('idpicto', 'alpha');
105$idmodule = (string) GETPOST('idmodule', 'alpha');
106$format = ''; // Prevent undefined in css tab
107
108// Security check
109if (!isModEnabled('modulebuilder')) {
110 accessforbidden('Module ModuleBuilder not enabled');
111}
112if (!$user->hasRight("modulebuilder", "run")) { // after this test $user->hasRight("modulebuilder", "run") is always true, no need to check it more
113 accessforbidden('ModuleBuilderNotAllowed');
114}
115
116// Dir for custom dirs
117$tmp = explode(',', $dolibarr_main_document_root_alt);
118$dirins = $tmp[0];
119$dirread = $dirins;
120$forceddirread = 0;
121
122$tmpdir = explode('@', $module);
123if (!empty($tmpdir[1])) {
124 $module = $tmpdir[0];
125 $dirread = $tmpdir[1];
126 $forceddirread = 1;
127}
128if (GETPOST('dirins', 'alpha')) {
129 $dirread = $dirins = GETPOST('dirins', 'alpha');
130 $forceddirread = 1;
131}
132
133$FILEFLAG = 'modulebuilder.txt';
134
135$now = dol_now();
136$newmask = 0;
137if (empty($newmask) && getDolGlobalString('MAIN_UMASK')) {
138 $newmask = getDolGlobalString('MAIN_UMASK');
139}
140if (empty($newmask)) { // This should no happen
141 $newmask = '0664';
142}
143
144$result = restrictedArea($user, 'modulebuilder', 0);
145
146$error = 0;
147$param = '';
148
149$form = new Form($db);
150
151// Define $listofmodules
152$dirsrootforscan = array($dirread);
153
154// Add also the core modules into the list of modules to show/edit
155if ($dirread != DOL_DOCUMENT_ROOT && (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 2 || getDolGlobalString('MODULEBUILDER_ADD_DOCUMENT_ROOT'))) {
156 $dirsrootforscan[] = DOL_DOCUMENT_ROOT;
157}
158
159// Search modules to edit
160$textforlistofdirs = '<!-- Directory scanned -->'."\n";
161$listofmodules = array();
162'@phan-var-force array<string,array{modulenamewithcase:string,moduledescriptorrelpath:string,moduledescriptorfullpath:string,moduledescriptorrootpath,moduletype?:string}> $listofmodules';
163$i = 0;
164foreach ($dirsrootforscan as $tmpdirread) {
165 $moduletype = 'external';
166 if ($tmpdirread == DOL_DOCUMENT_ROOT) {
167 $moduletype = 'internal';
168 }
169
170 $dirsincustom = dol_dir_list($tmpdirread, 'directories');
171 if (is_array($dirsincustom) && count($dirsincustom) > 0) {
172 foreach ($dirsincustom as $dircustomcursor) {
173 $fullname = $dircustomcursor['fullname'];
174 if (dol_is_file($fullname.'/'.$FILEFLAG)) {
175 // Get real name of module (MyModule instead of mymodule)
176 $dirtoscanrel = basename($fullname).'/core/modules/';
177
178 $descriptorfiles = dol_dir_list(dirname($fullname).'/'.$dirtoscanrel, 'files', 0, 'mod.*\.class\.php$');
179 if (empty($descriptorfiles)) { // If descriptor not found into module dir, we look into main module dir.
180 $dirtoscanrel = 'core/modules/';
181 $descriptorfiles = dol_dir_list($fullname.'/../'.$dirtoscanrel, 'files', 0, 'mod'.dol_strtoupper(basename($fullname)).'\.class\.php$');
182 }
183 $modulenamewithcase = '';
184 $moduledescriptorrelpath = '';
185 $moduledescriptorfullpath = '';
186
187 foreach ($descriptorfiles as $descriptorcursor) {
188 $modulenamewithcase = preg_replace('/^mod/', '', $descriptorcursor['name']);
189 $modulenamewithcase = preg_replace('/\.class\.php$/', '', $modulenamewithcase);
190 $moduledescriptorrelpath = $dirtoscanrel.$descriptorcursor['name'];
191 $moduledescriptorfullpath = $descriptorcursor['fullname'];
192 //var_dump($descriptorcursor);
193 }
194 if ($modulenamewithcase) {
195 $listofmodules[$dircustomcursor['name']] = array(
196 'modulenamewithcase' => $modulenamewithcase,
197 'moduledescriptorrelpath' => $moduledescriptorrelpath,
198 'moduledescriptorfullpath' => $moduledescriptorfullpath,
199 'moduledescriptorrootpath' => $tmpdirread,
200 'moduletype' => $moduletype
201 );
202 }
203 //var_dump($listofmodules);
204 }
205 }
206 }
207
208 if ($forceddirread && empty($listofmodules)) { // $forceddirread is 1 if we forced dir to read with dirins=... or with module=...@mydir
209 $listofmodules[dol_strtolower($module)] = array(
210 'modulenamewithcase' => $module,
211 'moduledescriptorrelpath' => 'notyetimplemented',
212 'moduledescriptorfullpath' => 'notyetimplemented',
213 'moduledescriptorrootpath' => 'notyetimplemented',
214 );
215 }
216
217 // Show description of content
218 $newdircustom = $dirins;
219 if (empty($newdircustom)) {
220 $newdircustom = img_warning();
221 }
222 // If dirread was forced to somewhere else, by using URL
223 // htdocs/modulebuilder/index.php?module=Inventory@/home/ldestailleur/git/dolibarr/htdocs/product
224 if (empty($i)) {
225 $textforlistofdirs .= $langs->trans("DirScanned").' : ';
226 } else {
227 $textforlistofdirs .= ', ';
228 }
229 $textforlistofdirs .= '<strong class="wordbreakimp">'.$tmpdirread.'</strong>';
230 if ($tmpdirread == DOL_DOCUMENT_ROOT) {
231 if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 2) {
232 $textforlistofdirs .= $form->textwithpicto('', $langs->trans("ConstantIsOn", "MAIN_FEATURES_LEVEL"));
233 }
234 if (getDolGlobalString('MODULEBUILDER_ADD_DOCUMENT_ROOT')) {
235 $textforlistofdirs .= $form->textwithpicto('', $langs->trans("ConstantIsOn", "MODULEBUILDER_ADD_DOCUMENT_ROOT"));
236 }
237 }
238 $i++;
239}
240
247{
248 $error = error_get_last();
249 if ($error && ($error['type'] & (E_ERROR | E_PARSE | E_CORE_ERROR | E_COMPILE_ERROR | E_USER_ERROR))) {
250 // Handle the fatal error
251 echo "Fatal error occurred: {$error['message']} in {$error['file']} on line {$error['line']}";
252 // If a header was already send, we suppose it is the llx_Header() so we call the llxFooter()
253 if (headers_sent()) {
254 llxFooter();
255 }
256 }
257}
258register_shutdown_function("moduleBuilderShutdownFunction");
259
260
270function getLicenceHeader($user, $langs, $now)
271{
272 $licInfo = $user->getFullName($langs);
273 $emailTabs = str_repeat("\t", (int) (max(0, (31 - mb_strlen($licInfo)) / 4)));
274 $licInfo .= ($user->email ? $emailTabs.'<'.$user->email.'>' : '');
275 $licInfo = dol_print_date($now, '%Y')."\t\t".$licInfo;
276 return $licInfo;
277}
278
279
280/*
281 * Actions
282 */
283
291function modulebuilderValidateGeneratedFile(string $destfile, NamingContract $nc): void
292{
293 $content = file_get_contents($destfile);
294 if ($content === false) {
295 return;
296 }
297 $validator = new StrictNamingContractValidator();
298 $errors = $validator->validateContent($content, $destfile);
299 if (!empty($errors)) {
301 'ModuleBuilder NamingContract validation warning in ' . $destfile . ': '
302 . implode('; ', array_slice($errors, 0, 3)),
303 LOG_WARNING
304 );
305 $safeErrors = array_map('dol_escape_htmltag', array_slice($errors, 0, 5));
306 setEventMessages(implode('<br>', $safeErrors), null, 'warnings');
307 }
308}
309
316function modulebuilderSyncRights(RightsSyncCommand $cmd): SyncReport
317{
318 global $langs;
319
320 $service = new DescriptorRightsSyncService();
321 $report = $service->sync($cmd);
322
323 if ($report->hasWarnings()) {
324 $safe = array_map('dol_escape_htmltag', array_slice($report->warnings, 0, 5));
325 setEventMessages($langs->trans('ModuleBuilderPermissionsNormalized').'<br>'.implode('<br>', $safe), null, 'warnings');
326 }
327 if ($report->hasConflicts()) {
328 $safe = array_map('dol_escape_htmltag', array_slice($report->conflicts, 0, 5));
329 setEventMessages($langs->trans('ModuleBuilderPermissionsNotChanged').'<br>'.implode('<br>', $safe), null, 'errors');
330 }
331
332 return $report;
333}
334
335// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
336$hookmanager->initHooks(array('modulebuilder'));
337$hookobject = null;
338
339$parameters = array('module' => $module, 'tab' => $tab, 'tabobj' => $tabobj, 'dirins' => $dirins, 'dirread' => $dirread, 'listofmodules' => $listofmodules);
340$reshook = $hookmanager->executeHooks('doActions', $parameters, $hookobject, $action); // Note that $action may have been modified by hook
341if ($reshook < 0) {
342 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
343}
344if ($reshook > 0) {
345 // The action was fully managed by a hook, so native actions are skipped
346 $action = '';
347}
348
349if ($dirins && $action == 'initmodule' && $modulename) { // Test on permission already done
350 $modulename = dol_string_nounprintableascii(dol_string_unaccent(dol_ucwords($modulename))); // Force first letter in uppercase
351 $destdir = '/not_set/';
352 $ncModule = new NamingContract($modulename);
353
354 if (preg_match('/[^a-z0-9]/i', $modulename)) {
355 $error++;
356 setEventMessages($langs->trans("SpaceOrSpecialCharAreNotAllowed"), null, 'errors');
357 }
358
359 if (!$error) {
360 $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
361 $destdir = $dirins.'/'.dol_strtolower($modulename);
362
363 $arrayreplacement = [
364 'mymodule' => $ncModule->moduleNameLower,
365 'MyModule' => $ncModule->moduleNameCase,
366 ];
367 $result = dolCopyDir($srcdir, $destdir, '0', 0, $arrayreplacement);
368 //dol_mkdir($destfile);
369 if ($result <= 0) {
370 if ($result < 0) {
371 $error++;
372 $langs->load("errors");
373 setEventMessages($langs->trans("ErrorFailToCopyDir", $srcdir, $destdir), null, 'errors');
374 } else {
375 // $result == 0
376 setEventMessages($langs->trans("AllFilesDidAlreadyExist", $srcdir, $destdir), null, 'warnings');
377 }
378 }
379
380 // Copy last 'html.formsetup.class.php' to backport folder
381 if (getDolGlobalInt('MODULEBUILDER_SUPPORT_COMPATIBILITY_V16')) {
382 $tryToCopyFromSetupClass = true;
383 $backportDest = $destdir .'/backport/v16/core/class';
384 $backportFileSrc = DOL_DOCUMENT_ROOT.'/core/class/html.formsetup.class.php';
385 $backportFileDest = $backportDest.'/html.formsetup.class.php';
386 $result = dol_mkdir($backportDest);
387
388 if ($result < 0) {
389 $error++;
390 $langs->load("errors");
391 setEventMessages($langs->trans("ErrorFailToCreateDir", $backportDest), null, 'errors');
392 $tryToCopyFromSetupClass = false;
393 }
394
395 if ($tryToCopyFromSetupClass) {
396 $result = dol_copy($backportFileSrc, $backportFileDest);
397 if ($result <= 0) {
398 if ($result < 0) {
399 $error++;
400 $langs->load("errors");
401 setEventMessages($langs->trans("ErrorFailToCopyFile", $backportFileSrc, $backportFileDest), null, 'errors');
402 } else {
403 setEventMessages($langs->trans("FileDidAlreadyExist", $backportFileDest), null, 'warnings');
404 }
405 }
406 }
407 }
408
409 if (getDolGlobalString('MODULEBUILDER_USE_ABOUT')) {
410 dol_delete_file($destdir.'/admin/about.php');
411 }
412
413 // Delete dir and files that can be generated in sub tabs later if we need them (we want a minimal module first)
414 dol_delete_dir_recursive($destdir.'/ajax');
415 dol_delete_dir_recursive($destdir.'/build/doxygen');
416 dol_delete_dir_recursive($destdir.'/core/modules/mailings');
417 dol_delete_dir_recursive($destdir.'/core/modules/'.dol_strtolower($modulename));
418 dol_delete_dir_recursive($destdir.'/core/tpl');
419 dol_delete_dir_recursive($destdir.'/core/triggers');
420 dol_delete_dir_recursive($destdir.'/doc');
421 //dol_delete_dir_recursive($destdir.'/.tx');
422 dol_delete_dir_recursive($destdir.'/core/boxes');
423
424 dol_delete_file($destdir.'/admin/myobject_extrafields.php');
425
426 dol_delete_file($destdir.'/class/actions_'.dol_strtolower($modulename).'.class.php');
427 dol_delete_file($destdir.'/class/api_'.dol_strtolower($modulename).'.class.php');
428
429 dol_delete_file($destdir.'/css/'.dol_strtolower($modulename).'.css.php');
430
431 dol_delete_file($destdir.'/js/'.dol_strtolower($modulename).'.js.php');
432
433 dol_delete_file($destdir.'/scripts/'.dol_strtolower($modulename).'.php');
434
435 dol_delete_file($destdir.'/sql/data.sql');
436 dol_delete_file($destdir.'/sql/update_x.x.x-y.y.y.sql');
437
438 // Delete some files related to Object (because the previous dolCopyDir has copied everything)
439 dol_delete_file($destdir.'/myobject_card.php');
440 dol_delete_file($destdir.'/myobject_contact.php');
441 dol_delete_file($destdir.'/myobject_note.php');
442 dol_delete_file($destdir.'/myobject_document.php');
443 dol_delete_file($destdir.'/myobject_agenda.php');
444 dol_delete_file($destdir.'/myobject_list.php');
445 dol_delete_file($destdir.'/lib/'.dol_strtolower($modulename).'_myobject.lib.php');
446 dol_delete_file($destdir.'/test/phpunit/functional/'.$modulename.'FunctionalTest.php');
447 dol_delete_file($destdir.'/test/phpunit/MyObjectTest.php');
448 dol_delete_file($destdir.'/sql/llx_'.dol_strtolower($modulename).'_myobject.sql');
449 dol_delete_file($destdir.'/sql/llx_'.dol_strtolower($modulename).'_myobject_extrafields.sql');
450 dol_delete_file($destdir.'/sql/llx_'.dol_strtolower($modulename).'_myobject.key.sql');
451 dol_delete_file($destdir.'/sql/llx_'.dol_strtolower($modulename).'_myobject_extrafields.key.sql');
452 dol_delete_file($destdir.'/class/myobject.class.php');
453 dol_delete_file($destdir.'/class/myobjectstats.class.php');
454
455 dol_delete_dir($destdir.'/class', 1);
456 dol_delete_dir($destdir.'/css', 1);
457 dol_delete_dir($destdir.'/js', 1);
458 dol_delete_dir($destdir.'/scripts', 1);
459 dol_delete_dir($destdir.'/sql', 1);
460 dol_delete_dir($destdir.'/test/phpunit/functionnal', 1);
461 dol_delete_dir($destdir.'/test/phpunit', 1);
462 dol_delete_dir($destdir.'/test', 1);
463 }
464
465 // Edit PHP files
466 if (!$error) {
467 $listofphpfilestoedit = dol_dir_list($destdir, 'files', 1, '\.(php|MD|js|sql|txt|xml|lang)$', '', 'fullname', SORT_ASC, 0, 1);
468
469 $licInfo = getLicenceHeader($user, $langs, $now);
470 foreach ($listofphpfilestoedit as $phpfileval) {
471 //var_dump($phpfileval['fullname']);
472 $arrayreplacement = array_merge(
473 $ncModule->getSubstitutionMap(),
474 [
475 'htdocs/modulebuilder/template' => $ncModule->moduleNameLower,
476 '---Put here your own copyright and developer email---' => $licInfo,
477 '---Replace with your own copyright and developer email---' => $licInfo,
478 'Editor name' => $editorname,
479 'https://www.example.com' => $editorurl,
480 '$this->version = \'1.0\'' => '$this->version = \'' . $version . '\'',
481 '$this->picto = \'generic\';' => (empty($picto)) ? '$this->picto = \'generic\';' : '$this->picto = \'' . $picto . '\';',
482 'modulefamily' => $family,
483 // Key '500000' would be cast to int(500000) by PHP, then renumbered to 0 by
484 // array_merge -- causing str_replace to search for '0' instead of '500000'.
485 // Use a string key that matches the exact assignment line to avoid this.
486 '$this->numero = 500000' => '$this->numero = '.$idmodule,
487 ]
488 );
489
490 if (getDolGlobalString('MODULEBUILDER_SPECIFIC_AUTHOR')) {
491 $arrayreplacement['---Replace with your own copyright and developer email---'] = dol_print_date($now, '%Y')."\t\t" . getDolGlobalString('MODULEBUILDER_SPECIFIC_AUTHOR');
492 }
493
494 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
495 $result = dolReplaceInFile($phpfileval['fullname'], $arrayreplacement); // @phpstan-ignore-line
496 //var_dump($result);
497 if ($result < 0) {
498 $langs->load("errors");
499 setEventMessages($langs->trans("ErrorFailToMakeReplacementInto", $phpfileval['fullname']), null, 'errors');
500 }
501 }
502
503 if (getDolGlobalString('MODULEBUILDER_SPECIFIC_README')) {
504 setEventMessages($langs->trans("ContentOfREADMECustomized"), null, 'warnings');
505 dol_delete_file($destdir.'/README.md');
506 file_put_contents($destdir.'/README.md', getDolGlobalString("MODULEBUILDER_SPECIFIC_README"));
507 dolChmod($destdir.'/README.md');
508 }
509 // for create file to add properties
510 // file_put_contents($destdir.'/'.dol_strtolower($modulename).'propertycard.php','');
511 // $srcFileCard = DOL_DOCUMENT_ROOT.'/modulebuilder/card.php';
512 // $destFileCard = $dirins.'/'.dol_strtolower($modulename).'/template/card.php';
513 // dol_copy($srcFileCard, $destdir.'/'.dol_strtolower($modulename).'propertycard.php', '0',1, $arrayreplacement);
514 }
515
516 if (!$error) {
517 setEventMessages($langs->trans('ModuleInitialized', $destdir), null);
518 $module = $modulename;
519
520 clearstatcache(true);
521 if (function_exists('opcache_invalidate')) {
522 opcache_reset(); // remove the include cache hell !
523 }
524
525 header("Location: ".$_SERVER["PHP_SELF"].'?module='.$modulename);
526 exit;
527 }
528}
529
530$destdir = '/not_set/'; // Initialize (for static analysis)
531$destfile = '/not_set/'; // Initialize (for static analysis)
532$srcfile = '/not_set/'; // Initialize (for static analysis)
533
534// init API, PHPUnit
535if ($dirins && in_array($action, array('initapi', 'initphpunit', 'initpagecontact', 'initpagedocument', 'initpagenote', 'initpageagenda')) && !empty($module) /* && $user->hasRight("modulebuilder", "run") // already checked */) {
536 $modulename = dol_ucfirst($module); // Force first letter in uppercase
537 $objectname = $tabobj;
538 $varnametoupdate = '';
539 $accesspolicyfailed = false;
540 $dirins = $listofmodules[dol_strtolower($module)]['moduledescriptorrootpath'];
541 $destdir = $dirins.'/'.dol_strtolower($module);
542
543 // Get list of existing objects
544 $objects = dolGetListOfObjectClasses($destdir);
545
546
547 if ($action == 'initapi') { // Test on permission already done
548 if (file_exists($dirins.'/'.dol_strtolower($module).'/class/api_'.dol_strtolower($module).'.class.php')) {
549 $result = dol_copy(DOL_DOCUMENT_ROOT.'/modulebuilder/template/class/api_mymodule.class.php', $dirins.'/'.dol_strtolower($module).'/class/api_'.dol_strtolower($module).'.class.php', '0', 1);
550 }
551 dol_mkdir($dirins.'/'.dol_strtolower($module).'/class');
552 $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
553 $srcfile = $srcdir.'/class/api_mymodule.class.php';
554 $destfile = $dirins.'/'.dol_strtolower($module).'/class/api_'.dol_strtolower($module).'.class.php';
555 } elseif ($action == 'initphpunit') { // Test on permission already done
556 dol_mkdir($dirins.'/'.dol_strtolower($module).'/test/phpunit');
557 $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
558 $srcfile = $srcdir.'/test/phpunit/MyObjectTest.php';
559 $destfile = $dirins.'/'.dol_strtolower($module).'/test/phpunit/'.dol_strtolower($objectname).'Test.php';
560 } elseif ($action == 'initpagecontact') { // Test on permission already done
561 dol_mkdir($dirins.'/'.dol_strtolower($module));
562 $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
563 $srcfile = $srcdir.'/myobject_contact.php';
564 $destfile = $dirins.'/'.dol_strtolower($module).'/'.dol_strtolower($objectname).'_contact.php';
565 $varnametoupdate = 'showtabofpagecontact';
566 } elseif ($action == 'initpagedocument') { // Test on permission already done
567 dol_mkdir($dirins.'/'.dol_strtolower($module));
568 $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
569 $srcfile = $srcdir.'/myobject_document.php';
570 $destfile = $dirins.'/'.dol_strtolower($module).'/'.dol_strtolower($objectname).'_document.php';
571 $varnametoupdate = 'showtabofpagedocument';
572 } elseif ($action == 'initpagenote') { // Test on permission already done
573 dol_mkdir($dirins.'/'.dol_strtolower($module));
574 $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
575 $srcfile = $srcdir.'/myobject_note.php';
576 $destfile = $dirins.'/'.dol_strtolower($module).'/'.dol_strtolower($objectname).'_note.php';
577 $varnametoupdate = 'showtabofpagenote';
578 } elseif ($action == 'initpageagenda') { // Test on permission already done
579 dol_mkdir($dirins.'/'.dol_strtolower($module));
580 $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
581 $srcfile = $srcdir.'/myobject_agenda.php';
582 $destfile = $dirins.'/'.dol_strtolower($module).'/'.dol_strtolower($objectname).'_agenda.php';
583 $varnametoupdate = 'showtabofpageagenda';
584 }
585
586 if (!file_exists($destfile)) {
587 $result = dol_copy($srcfile, $destfile, '0', 0);
588 }
589
590 if ($result > 0) {
591 //var_dump($phpfileval['fullname']);
592 try {
593 $ncApiObj = new NamingContract($modulename, $objectname);
594 } catch (\InvalidArgumentException $e) {
595 $error++;
596 setEventMessages($langs->trans("SpaceOrSpecialCharAreNotAllowed"), null, 'errors');
597 $ncApiObj = null;
598 }
599
600 if (!$error && $ncApiObj !== null) {
601 $arrayreplacement = array_merge(
602 $ncApiObj->getSubstitutionMap(),
603 [
604 'htdocs/modulebuilder/template' => $ncApiObj->moduleNameLower,
605 '---Replace with your own copyright and developer email---' => getLicenceHeader($user, $langs, $now),
606 ]
607 );
608
609 if ($action == 'initapi') { // Test on permission already done
610 if (count($objects) >= 1) {
611 addObjectsToApiFile($srcfile, $destfile, $objects, $modulename);
612 }
613 // Fix PHPDoc header and class-declaration residuals left by addObjectsToApiFile.
614 // 'MYOBJECT' (uppercase) is excluded to preserve the /* BEGIN MODULEBUILDER API MYOBJECT */
615 // placeholder that addObjectsToApiFile keeps for future object additions.
616 $headerFix = $arrayreplacement;
617 unset($headerFix['MYOBJECT']);
618 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
619 dolReplaceInFile($destfile, $headerFix);
620 modulebuilderValidateGeneratedFile($destfile, $ncApiObj);
621 } else {
622 // A tab page must follow the access policy stored in the object class, and never keep the template markers
623 if ($varnametoupdate) {
624 $classfile = $destdir.'/class/'.dol_strtolower($objectname).'.class.php';
625 try {
626 $storedaccesspolicy = getModuleBuilderAccessPolicyFromClassFile($classfile);
627 if (applyModuleBuilderAccessPolicyToPage($destfile, $storedaccesspolicy) < 0) {
628 $accesspolicyfailed = true;
629 $langs->load("errors");
630 setEventMessages($langs->trans("ErrorFailToMakeReplacementInto", $destfile), null, 'errors');
631 }
632 } catch (\InvalidArgumentException $e) {
633 $accesspolicyfailed = true;
634 dol_syslog("modulebuilder: invalid access policy stored in ".$classfile.": ".$e->getMessage(), LOG_ERR);
635 setEventMessages($langs->trans("ErrorModuleBuilderInvalidStoredAccessPolicy", basename($classfile)), null, 'errors');
636 }
637 }
638 if ($accesspolicyfailed) {
639 $error++;
640 dol_delete_file($destfile);
641 } else {
642 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
643 dolReplaceInFile($destfile, $arrayreplacement);
644 modulebuilderValidateGeneratedFile($destfile, $ncApiObj);
645 }
646 }
647 }
648
649 if ($varnametoupdate && !$accesspolicyfailed) {
650 // Now we update the object file to set $$varnametoupdate to 1
651 $srcfile = $dirins.'/'.dol_strtolower($module).'/lib/'.dol_strtolower($module).'_'.dol_strtolower($objectname).'.lib.php';
652 $arrayreplacement = array('/\$'.preg_quote($varnametoupdate, '/').' = 0;/' => '$'.$varnametoupdate.' = 1;');
653 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
654 dolReplaceInFile($srcfile, $arrayreplacement, '', '0', 0, 1);
655 }
656 } else {
657 $langs->load("errors");
658 setEventMessages($langs->trans('ErrorFailToCreateFile', $destfile), null, 'errors');
659 }
660}
661
662
663// init ExtraFields
664if ($dirins && $action == 'initsqlextrafields' && !empty($module) /* && $user->hasRight("modulebuilder", "run") // already checked */) {
665 $modulename = dol_ucfirst($module); // Force first letter in uppercase
666 $objectname = $tabobj;
667
668 dol_mkdir($dirins.'/'.dol_strtolower($module).'/sql');
669 $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
670 $srcfile1 = $srcdir.'/sql/llx_mymodule_myobject_extrafields.sql';
671 $destfile1 = $dirins.'/'.dol_strtolower($module).'/sql/llx_'.dol_strtolower($module).'_'.dol_strtolower($objectname).'_extrafields.sql';
672 $result1 = dol_copy($srcfile1, $destfile1, '0', 0);
673 $srcfile2 = $srcdir.'/sql/llx_mymodule_myobject_extrafields.key.sql';
674 $destfile2 = $dirins.'/'.dol_strtolower($module).'/sql/llx_'.dol_strtolower($module).'_'.dol_strtolower($objectname).'_extrafields.key.sql';
675 $result2 = dol_copy($srcfile2, $destfile2, '0', 0);
676
677 if ($result1 > 0 && $result2 > 0) {
678 $modulename = dol_ucfirst($module); // Force first letter in uppercase
679
680 //var_dump($phpfileval['fullname']);
681 try {
682 $ncSqlObj = new NamingContract($modulename, $objectname);
683 } catch (\InvalidArgumentException $e) {
684 $error++;
685 setEventMessages($langs->trans("SpaceOrSpecialCharAreNotAllowed"), null, 'errors');
686 $ncSqlObj = null;
687 }
688
689 if (!$error && $ncSqlObj !== null) {
690 $arrayreplacement = array_merge(
691 $ncSqlObj->getSubstitutionMap(),
692 [
693 'htdocs/modulebuilder/template' => $ncSqlObj->moduleNameLower,
694 '---Replace with your own copyright and developer email---' => getLicenceHeader($user, $langs, $now),
695 ]
696 );
697
698 dolReplaceInFile($destfile1, $arrayreplacement);
699 dolReplaceInFile($destfile2, $arrayreplacement);
700 modulebuilderValidateGeneratedFile($destfile1, $ncSqlObj);
701 modulebuilderValidateGeneratedFile($destfile2, $ncSqlObj);
702 }
703 } else {
704 $langs->load("errors");
705 if ($result1 <= 0) {
706 setEventMessages($langs->trans('ErrorFailToCreateFile', $destfile1), null, 'errors');
707 }
708 if ($result2 <= 0) {
709 $langs->load("errors");
710 setEventMessages($langs->trans('ErrorFailToCreateFile', $destfile2), null, 'errors');
711 }
712 }
713
714 // Now we update the object file to set $this->isextrafieldmanaged to 1
715 $srcfile = $dirins.'/'.dol_strtolower($module).'/class/'.dol_strtolower($objectname).'.class.php';
716 $arrayreplacement = array('/\$this->isextrafieldmanaged = 0;/' => '$this->isextrafieldmanaged = 1;');
717 $arrayreplacement = array('/\$isextrafieldmanaged = 0;/' => '$isextrafieldmanaged = 1;');
718 dolReplaceInFile($srcfile, $arrayreplacement, '', '0', 0, 1);
719}
720
721
722// init Hook
723if ($dirins && $action == 'inithook' && !empty($module) /* && $user->hasRight("modulebuilder", "run") // already checked */) {
724 dol_mkdir($dirins.'/'.dol_strtolower($module).'/class');
725 $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
726 $srcfile = $srcdir.'/class/actions_mymodule.class.php';
727 $destfile = $dirins.'/'.dol_strtolower($module).'/class/actions_'.dol_strtolower($module).'.class.php';
728 $result = dol_copy($srcfile, $destfile, '0', 0);
729
730 if ($result > 0) {
731 $modulename = dol_ucfirst($module); // Force first letter in uppercase
732
733 //var_dump($phpfileval['fullname']);
734 $arrayreplacement = array(
735 'mymodule' => dol_strtolower($modulename),
736 'MyModule' => $modulename,
737 'MYMODULE' => dol_strtoupper($modulename),
738 'My module' => $modulename,
739 'my module' => $modulename,
740 'Mon module' => $modulename,
741 'mon module' => $modulename,
742 'htdocs/modulebuilder/template' => dol_strtolower($modulename),
743 '---Replace with your own copyright and developer email---' => getLicenceHeader($user, $langs, $now)
744 );
745
746 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
747 dolReplaceInFile($destfile, $arrayreplacement);
748 } else {
749 $langs->load("errors");
750 setEventMessages($langs->trans('ErrorFailToCreateFile', $destfile), null, 'errors');
751 }
752}
753
754
755// init Trigger
756if ($dirins && $action == 'inittrigger' && !empty($module) /* && $user->hasRight("modulebuilder", "run") // already checked */) {
757 dol_mkdir($dirins.'/'.dol_strtolower($module).'/core/triggers');
758 $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
759 $srcfile = $srcdir.'/core/triggers/interface_99_modMyModule_MyModuleTriggers.class.php';
760 $destfile = $dirins.'/'.dol_strtolower($module).'/core/triggers/interface_99_mod'.$module.'_'.$module.'Triggers.class.php';
761 $result = dol_copy($srcfile, $destfile, '0', 0);
762
763 if ($result > 0) {
764 $modulename = dol_ucfirst($module); // Force first letter in uppercase
765
766 //var_dump($phpfileval['fullname']);
767 $arrayreplacement = array(
768 'mymodule' => dol_strtolower($modulename),
769 'MyModule' => $modulename,
770 'MYMODULE' => dol_strtoupper($modulename),
771 'My module' => $modulename,
772 'my module' => $modulename,
773 'Mon module' => $modulename,
774 'mon module' => $modulename,
775 'htdocs/modulebuilder/template' => dol_strtolower($modulename),
776 '---Replace with your own copyright and developer email---' => getLicenceHeader($user, $langs, $now)
777 );
778
779 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
780 dolReplaceInFile($destfile, $arrayreplacement);
781 } else {
782 $langs->load("errors");
783 setEventMessages($langs->trans('ErrorFailToCreateFile', $destfile), null, 'errors');
784 }
785}
786
787
788// init Widget
789if ($dirins && $action == 'initwidget' && !empty($module) /* && $user->hasRight("modulebuilder", "run") // already checked */) {
790 dol_mkdir($dirins.'/'.dol_strtolower($module).'/core/boxes');
791 $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
792 $srcfile = $srcdir.'/core/boxes/mymodulewidget1.php';
793 $destfile = $dirins.'/'.dol_strtolower($module).'/core/boxes/'.dol_strtolower($module).'widget1.php';
794 $result = dol_copy($srcfile, $destfile, '0', 0);
795
796 if ($result > 0) {
797 $modulename = dol_ucfirst($module); // Force first letter in uppercase
798
799 //var_dump($phpfileval['fullname']);
800 $arrayreplacement = array(
801 'mymodule' => dol_strtolower($modulename),
802 'MyModule' => $modulename,
803 'MYMODULE' => dol_strtoupper($modulename),
804 'My module' => $modulename,
805 'my module' => $modulename,
806 'Mon module' => $modulename,
807 'mon module' => $modulename,
808 'htdocs/modulebuilder/template' => dol_strtolower($modulename),
809 '---Replace with your own copyright and developer email---' => getLicenceHeader($user, $langs, $now)
810 );
811
812 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
813 dolReplaceInFile($destfile, $arrayreplacement);
814 } else {
815 $langs->load("errors");
816 setEventMessages($langs->trans('ErrorFailToCreateFile', $destfile), null, 'errors');
817 }
818}
819
820
821// init EmailSelector
822if ($dirins && $action == 'initemailing' && !empty($module) /* && $user->hasRight("modulebuilder", "run") // already checked */) {
823 dol_mkdir($dirins.'/'.dol_strtolower($module).'/core/modules/mailings');
824 $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
825 $srcfile = $srcdir.'/core/modules/mailings/mailing_mymodule_selector1.modules.php';
826 $destfile = $dirins.'/'.dol_strtolower($module).'/core/modules/mailings/mailing_'.dol_strtolower($module).'_selector1.modules.php';
827 $result = dol_copy($srcfile, $destfile, '0', 0);
828
829 if ($result > 0) {
830 $modulename = dol_ucfirst($module); // Force first letter in uppercase
831
832 //var_dump($phpfileval['fullname']);
833 $arrayreplacement = array(
834 'mymodule' => dol_strtolower($modulename),
835 'MyModule' => $modulename,
836 'MYMODULE' => dol_strtoupper($modulename),
837 'My module' => $modulename,
838 'my module' => $modulename,
839 'Mon module' => $modulename,
840 'mon module' => $modulename,
841 'htdocs/modulebuilder/template' => dol_strtolower($modulename),
842 '---Replace with your own copyright and developer email---' => getLicenceHeader($user, $langs, $now)
843 );
844
845 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
846 dolReplaceInFile($destfile, $arrayreplacement);
847 } else {
848 $langs->load("errors");
849 setEventMessages($langs->trans('ErrorFailToCreateFile', $destfile), null, 'errors');
850 }
851}
852
853
854// init CSS
855if ($dirins && $action == 'initcss' && !empty($module) /* && $user->hasRight("modulebuilder", "run") // already checked */) {
856 dol_mkdir($dirins.'/'.dol_strtolower($module).'/css');
857 $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
858 $srcfile = $srcdir.'/css/mymodule.css.php';
859 $destfile = $dirins.'/'.dol_strtolower($module).'/css/'.dol_strtolower($module).'.css.php';
860 $result = dol_copy($srcfile, $destfile, '0', 0);
861
862 if ($result > 0) {
863 $modulename = dol_ucfirst($module); // Force first letter in uppercase
864
865 //var_dump($phpfileval['fullname']);
866 $arrayreplacement = array(
867 'mymodule' => dol_strtolower($modulename),
868 'MyModule' => $modulename,
869 'MYMODULE' => dol_strtoupper($modulename),
870 'My module' => $modulename,
871 'my module' => $modulename,
872 'Mon module' => $modulename,
873 'mon module' => $modulename,
874 'htdocs/modulebuilder/template' => dol_strtolower($modulename),
875 '---Replace with your own copyright and developer email---' => getLicenceHeader($user, $langs, $now)
876 );
877
878 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
879 dolReplaceInFile($destfile, $arrayreplacement);
880
881 // Update descriptor file to uncomment file
882 $srcfile = $dirins.'/'.dol_strtolower($module).'/core/modules/mod'.$module.'.class.php';
883 $arrayreplacement = array('/\/\/\s*\''.preg_quote('/'.dol_strtolower($module).'/css/'.dol_strtolower($module).'.css.php', '/').'\'/' => '\'/'.dol_strtolower($module).'/css/'.dol_strtolower($module).'.css.php\'');
884 dolReplaceInFile($srcfile, $arrayreplacement, '', '0', 0, 1);
885 } else {
886 $langs->load("errors");
887 setEventMessages($langs->trans('ErrorFailToCreateFile', $destfile), null, 'errors');
888 }
889}
890
891
892// init JS
893if ($dirins && $action == 'initjs' && !empty($module) /* && $user->hasRight("modulebuilder", "run") // already checked */) {
894 dol_mkdir($dirins.'/'.dol_strtolower($module).'/js');
895 $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
896 $srcfile = $srcdir.'/js/mymodule.js.php';
897 $destfile = $dirins.'/'.dol_strtolower($module).'/js/'.dol_strtolower($module).'.js.php';
898 $result = dol_copy($srcfile, $destfile, '0', 0);
899
900 if ($result > 0) {
901 $modulename = dol_ucfirst($module); // Force first letter in uppercase
902
903 //var_dump($phpfileval['fullname']);
904 $arrayreplacement = array(
905 'mymodule' => dol_strtolower($modulename),
906 'MyModule' => $modulename,
907 'MYMODULE' => dol_strtoupper($modulename),
908 'My module' => $modulename,
909 'my module' => $modulename,
910 'Mon module' => $modulename,
911 'mon module' => $modulename,
912 'htdocs/modulebuilder/template' => dol_strtolower($modulename),
913 '---Replace with your own copyright and developer email---' => getLicenceHeader($user, $langs, $now)
914 );
915
916 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
917 dolReplaceInFile($destfile, $arrayreplacement);
918
919 // Update descriptor file to uncomment file
920 $srcfile = $dirins.'/'.dol_strtolower($module).'/core/modules/mod'.$module.'.class.php';
921 $arrayreplacement = array('/\/\/\s*\''.preg_quote('/'.dol_strtolower($module).'/js/'.dol_strtolower($module).'.js.php', '/').'\'/' => '\'/'.dol_strtolower($module).'/js/'.dol_strtolower($module).'.js.php\'');
922 dolReplaceInFile($srcfile, $arrayreplacement, '', '0', 0, 1);
923 } else {
924 $langs->load("errors");
925 setEventMessages($langs->trans('ErrorFailToCreateFile', $destfile), null, 'errors');
926 }
927}
928
929
930// init CLI
931if ($dirins && $action == 'initcli' && !empty($module) /* && $user->hasRight("modulebuilder", "run") // already checked */) {
932 dol_mkdir($dirins.'/'.dol_strtolower($module).'/scripts');
933 $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
934 $srcfile = $srcdir.'/scripts/mymodule.php';
935 $destfile = $dirins.'/'.dol_strtolower($module).'/scripts/'.dol_strtolower($module).'.php';
936 $result = dol_copy($srcfile, $destfile, '0', 0);
937
938 if ($result > 0) {
939 $modulename = dol_ucfirst($module); // Force first letter in uppercase
940
941 //var_dump($phpfileval['fullname']);
942 $arrayreplacement = array(
943 'mymodule' => dol_strtolower($modulename),
944 'MyModule' => $modulename,
945 'MYMODULE' => dol_strtoupper($modulename),
946 'My module' => $modulename,
947 'my module' => $modulename,
948 'Mon module' => $modulename,
949 'mon module' => $modulename,
950 'htdocs/modulebuilder/template' => dol_strtolower($modulename),
951 '__MYCOMPANY_NAME__' => $mysoc->name,
952 '__KEYWORDS__' => $modulename,
953 '__USER_FULLNAME__' => $user->getFullName($langs),
954 '__USER_EMAIL__' => $user->email,
955 '__YYYY-MM-DD__' => dol_print_date($now, 'dayrfc'),
956 '---Replace with your own copyright and developer email---' => getLicenceHeader($user, $langs, $now)
957 );
958
959 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
960 dolReplaceInFile($destfile, $arrayreplacement);
961 } else {
962 $langs->load("errors");
963 setEventMessages($langs->trans('ErrorFailToCreateFile', $destfile), null, 'errors');
964 }
965}
966
967
968$moduledescriptorfile = '/not_set/';
969$modulelowercase = null;
970
971// init Doc
972if ($dirins && $action == 'initdoc' && !empty($module) /* && $user->hasRight("modulebuilder", "run") // already checked */) {
973 dol_mkdir($dirins.'/'.dol_strtolower($module).'/doc');
974 $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
975 $srcfile = $srcdir.'/doc/Documentation.asciidoc';
976 $destfile = $dirins.'/'.dol_strtolower($module).'/doc/Documentation.asciidoc';
977 $result = dol_copy($srcfile, $destfile, '0', 0);
978
979 if ($result > 0) {
980 $modulename = dol_ucfirst($module); // Force first letter in uppercase
981 $modulelowercase = dol_strtolower($module);
982
983 //var_dump($phpfileval['fullname']);
984 $arrayreplacement = array(
985 'mymodule' => dol_strtolower($modulename),
986 'MyModule' => $modulename,
987 'MYMODULE' => dol_strtoupper($modulename),
988 'My module' => $modulename,
989 'my module' => $modulename,
990 'Mon module' => $modulename,
991 'mon module' => $modulename,
992 'htdocs/modulebuilder/template' => dol_strtolower($modulename),
993 '__MYCOMPANY_NAME__' => $mysoc->name,
994 '__KEYWORDS__' => $modulename,
995 '__USER_FULLNAME__' => $user->getFullName($langs),
996 '__USER_EMAIL__' => $user->email,
997 '__YYYY-MM-DD__' => dol_print_date($now, 'dayrfc'),
998 '---Replace with your own copyright and developer email---' => getLicenceHeader($user, $langs, $now)
999 );
1000
1001 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
1002 dolReplaceInFile($destfile, $arrayreplacement);
1003
1004 // add table of properties
1005 $dirins = $listofmodules[dol_strtolower($module)]['moduledescriptorrootpath'];
1006 $destdir = $dirins.'/'.dol_strtolower($module);
1007 $objects = dolGetListOfObjectClasses($destdir);
1008 foreach ($objects as $path => $obj) {
1009 writePropsInAsciiDoc($path, $obj, $destfile);
1010 }
1011
1012 // add table of permissions
1013 $moduledescriptorfile = $dirins.'/'.dol_strtolower($module).'/core/modules/mod'.$module.'.class.php';
1014 writePermsInAsciiDoc($moduledescriptorfile, $destfile);
1015
1016 // add api urls if file exist
1017 if (file_exists($dirins.'/'.dol_strtolower($module).'/class/api_'.dol_strtolower($module).'.class.php')) {
1018 $apiFile = $dirins.'/'.dol_strtolower($module).'/class/api_'.dol_strtolower($module).'.class.php';
1019 writeApiUrlsInDoc($apiFile, $destfile);
1020 }
1021
1022 // add ChangeLog in Doc
1023 if (file_exists($dirins.'/'.dol_strtolower($module).'/ChangeLog.md')) {
1024 $changeLog = $dirins.'/'.dol_strtolower($module).'/ChangeLog.md';
1025 $string = file_get_contents($changeLog);
1026
1027 $replace = explode("\n", $string);
1028 $strreplace = array();
1029 foreach ($replace as $line) {
1030 if ($line === '') {
1031 continue;
1032 }
1033 if (strpos($line, '##') !== false) {
1034 $strreplace[$line] = str_replace('##', '', $line);
1035 } else {
1036 $strreplace[$line] = $line;
1037 }
1038 }
1039 $stringLog = implode("\n", $strreplace);
1040 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
1041 dolReplaceInFile($destfile, array('//include::ChangeLog.md[]' => '','__CHANGELOG__' => $stringLog));
1042 }
1043
1044 // Delete old documentation files
1045 $FILENAMEDOC = $modulelowercase.'.html';
1046 $FILENAMEDOCPDF = $modulelowercase.'.pdf';
1047 $outputfiledoc = dol_buildpath($modulelowercase, 0).'/doc/'.$FILENAMEDOC;
1048 $outputfiledocurl = dol_buildpath($modulelowercase, 1).'/doc/'.$FILENAMEDOC;
1049 $outputfiledocpdf = dol_buildpath($modulelowercase, 0).'/doc/'.$FILENAMEDOCPDF;
1050 $outputfiledocurlpdf = dol_buildpath($modulelowercase, 1).'/doc/'.$FILENAMEDOCPDF;
1051
1052 dol_delete_file($outputfiledoc, 0, 0, 0, null, false, 0);
1053 dol_delete_file($outputfiledocpdf, 0, 0, 0, null, false, 0);
1054 } else {
1055 $langs->load("errors");
1056 setEventMessages($langs->trans('ErrorFailToCreateFile', $destfile), null, 'errors');
1057 }
1058}
1059
1060
1061// add Language
1062if ($dirins && $action == 'addlanguage' && !empty($module) /* && $user->hasRight("modulebuilder", "run") // already checked */) {
1063 $newlangcode = GETPOST('newlangcode', 'aZ09');
1064
1065 if ($newlangcode) {
1066 $modulelowercase = dol_strtolower($module);
1067
1068 // Dir for module
1069 $diroflang = dol_buildpath($modulelowercase, 0);
1070
1071 if ($diroflang == $dolibarr_main_document_root.'/'.$modulelowercase) {
1072 // This is not a custom module, we force diroflang to htdocs root
1073 $diroflang = $dolibarr_main_document_root;
1074
1075 $srcfile = $diroflang.'/langs/en_US/'.$modulelowercase.'.lang';
1076 $destfile = $diroflang.'/langs/'.$newlangcode.'/'.$modulelowercase.'.lang';
1077
1078 $result = dol_copy($srcfile, $destfile, '0', 0);
1079 if ($result < 0) {
1080 $langs->load("errors");
1081 setEventMessages($langs->trans("ErrorFailToCopyFile", $srcfile, $destfile), null, 'errors');
1082 }
1083 } else {
1084 $srcdir = $diroflang.'/langs/en_US';
1085 $srcfile = $diroflang.'/langs/en_US/'.$modulelowercase.'.lang';
1086 $destdir = $diroflang.'/langs/'.$newlangcode;
1087
1088 $arrayofreplacement = array();
1089 if (!dol_is_dir($srcdir) || !dol_is_file($srcfile)) {
1090 $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template/langs/en_US';
1091 $arrayofreplacement = array('mymodule' => $modulelowercase);
1092 }
1093 $result = dolCopyDir($srcdir, $destdir, '0', 0, $arrayofreplacement);
1094 }
1095 } else {
1096 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Language")), null, 'errors');
1097 }
1098}
1099
1100
1101// Remove/delete File
1102if ($dirins && $action == 'confirm_removefile' && !empty($module) /* && $user->hasRight("modulebuilder", "run") // already checked */) {
1103 $objectname = $tabobj;
1104 $dirins = $listofmodules[dol_strtolower($module)]['moduledescriptorrootpath'];
1105 $destdir = $dirins.'/'.dol_strtolower($module);
1106
1107 $relativefilename = dol_sanitizePathName(GETPOST('file', 'restricthtml'));
1108
1109 // Now we delete the file
1110 if ($relativefilename) {
1111 $dirnametodelete = dirname($relativefilename);
1112 $filetodelete = $dirins.'/'.$relativefilename;
1113 $dirtodelete = $dirins.'/'.$dirnametodelete;
1114
1115 // Get list of existing objects
1116 $objects = dolGetListOfObjectClasses($destdir);
1117
1118 $keyofobjecttodelete = array_search($objectname, $objects);
1119 if ($keyofobjecttodelete !== false) {
1120 unset($objects[$keyofobjecttodelete]);
1121 }
1122
1123 // Delete or modify the file
1124 if (strpos($relativefilename, 'api') !== false) {
1125 $file_api = $destdir.'/class/api_'.dol_strtolower($module).'.class.php';
1126
1127 $removeFile = removeObjectFromApiFile($file_api, $objects, $objectname);
1128
1129 if (count($objects) == 0) {
1130 $result = dol_delete_file($filetodelete, 1);
1131 }
1132
1133 if ($removeFile) {
1134 setEventMessages($langs->trans("ApiObjectDeleted"), null);
1135 }
1136 } else {
1137 $result = dol_delete_file($filetodelete, 1);
1138 }
1139
1140 if (!$result) {
1141 $langs->load("errors");
1142 setEventMessages($langs->trans("ErrorFailToDeleteFile", basename($filetodelete)), null, 'errors');
1143 } else {
1144 // If we delete a .sql file, we delete also the other .sql file
1145 if (preg_match('/\.sql$/', $relativefilename)) {
1146 if (preg_match('/\.key\.sql$/', $relativefilename)) {
1147 $relativefilename = preg_replace('/\.key\.sql$/', '.sql', $relativefilename);
1148 $filetodelete = $dirins.'/'.$relativefilename;
1149 $result = dol_delete_file($filetodelete, 1);
1150 } elseif (preg_match('/\.sql$/', $relativefilename)) {
1151 $relativefilename = preg_replace('/\.sql$/', '.key.sql', $relativefilename);
1152 $filetodelete = $dirins.'/'.$relativefilename;
1153 $result = dol_delete_file($filetodelete, 1);
1154 }
1155 }
1156
1157 if (dol_is_dir_empty($dirtodelete)) {
1158 dol_delete_dir($dirtodelete);
1159 }
1160
1161 // Update descriptor file to comment file
1162 if (in_array($tab, array('css', 'js'))) {
1163 $srcfile = $dirins.'/'.dol_strtolower($module).'/core/modules/mod'.$module.'.class.php';
1164 $arrayreplacement = array('/^\s*\''.preg_quote('/'.$relativefilename, '/').'\',*/m' => ' // \'/'.$relativefilename.'\',');
1165 dolReplaceInFile($srcfile, $arrayreplacement, '', '0', 0, 1);
1166 }
1167
1168 if (preg_match('/_extrafields/', $relativefilename)) {
1169 // Now we update the object file to set $isextrafieldmanaged to 0
1170 $srcfile = $dirins.'/'.dol_strtolower($module).'/class/'.dol_strtolower($objectname).'.class.php';
1171 $arrayreplacement = array('/\$isextrafieldmanaged = 1;/' => '$isextrafieldmanaged = 0;');
1172 dolReplaceInFile($srcfile, $arrayreplacement, '', '0', 0, 1);
1173 }
1174
1175 // Now we update the lib file to set $showtabofpagexxx to 0
1176 $varnametoupdate = '';
1177 $reg = array();
1178 if (preg_match('/_([a-z]+)\.php$/', $relativefilename, $reg)) {
1179 $varnametoupdate = 'showtabofpage'.$reg[1];
1180 }
1181 if ($varnametoupdate) {
1182 $srcfile = $dirins.'/'.dol_strtolower($module).'/lib/'.dol_strtolower($module).'_'.dol_strtolower($objectname).'.lib.php';
1183 $arrayreplacement = array('/\$'.preg_quote($varnametoupdate, '/').' = 1;/' => '$'.preg_quote($varnametoupdate, '/').' = 0;');
1184 dolReplaceInFile($srcfile, $arrayreplacement, '', '0', 0, 1);
1185 }
1186 }
1187 }
1188}
1189
1190// Init an object
1191if ($dirins && $action == 'initobject' && $module && $objectname) { // Test on permission already done
1192 $warning = 0;
1193
1194 $objectname = dol_string_nounprintableascii(dol_string_unaccent(dol_ucwords($objectname))); // Force first letter in uppercase
1195
1196 $dirins = $dirread = $listofmodules[dol_strtolower($module)]['moduledescriptorrootpath'];
1197 $moduletype = $listofmodules[dol_strtolower($module)]['moduletype'];
1198
1199 if (preg_match('/[^a-z0-9]/i', $objectname)) {
1200 $error++;
1201 setEventMessages($langs->trans("SpaceOrSpecialCharAreNotAllowed"), null, 'errors');
1202 $tabobj = 'newobject';
1203 }
1204 if (class_exists($objectname)) {
1205 // TODO Add a more efficient detection. Scan disk ?
1206 $error++;
1207 setEventMessages($langs->trans("AnObjectWithThisClassNameAlreadyExists"), null, 'errors');
1208 $tabobj = 'newobject';
1209 }
1210
1211 try {
1212 $ncObj = new NamingContract($module, $objectname);
1213 } catch (\InvalidArgumentException $e) {
1214 $error++;
1215 setEventMessages($langs->trans("SpaceOrSpecialCharAreNotAllowed"), null, 'errors');
1216 $ncObj = null;
1217 }
1218
1219 $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
1220 $destdir = $dirins.'/'.dol_strtolower($module);
1221
1222 // Optional tabs and card actions selected by user, and detection of an already generated object (for idempotence warning)
1223 $enabledtabs = filterEnabledKeys(GETPOST('enabledtab', 'array'), getModuleBuilderObjectTabs());
1224 $enabledcardactions = filterEnabledKeys(GETPOST('enabledcardaction', 'array'), getModuleBuilderObjectCardActions());
1225 $objectalreadyexists = dol_is_file($destdir.'/class/'.dol_strtolower($objectname).'.class.php');
1226
1227 // Access policy of the object pages: an invalid policy rejects the whole generation, its predicates are never filtered
1228 $accesspolicy = null;
1229 $copiedfiles = array();
1230 $accesspolicyalternatives = array();
1231 for ($i = 0; $i < AccessPolicyConfig::MAX_ALTERNATIVES; $i++) {
1232 $accesspolicyalternatives[] = GETPOST('accesspolicy_'.$i, 'array:aZ09');
1233 }
1234 try {
1235 $accesspolicy = AccessPolicyConfig::fromAlternatives($accesspolicyalternatives, GETPOST('accesspolicymessage', 'alphanohtml'));
1236 } catch (\InvalidArgumentException $e) {
1237 $error++;
1238 dol_syslog("modulebuilder: invalid access policy for object ".$objectname.": ".$e->getMessage(), LOG_WARNING);
1239 setEventMessages($langs->trans("ErrorModuleBuilderInvalidAccessPolicy"), null, 'errors');
1240 $tabobj = 'newobject';
1241 }
1242 // All the pages of an object follow the policy stored in its class: on regeneration it overrides the form
1243 if (!$error && $objectalreadyexists) {
1244 $classfile = $destdir.'/class/'.dol_strtolower($objectname).'.class.php';
1245 try {
1246 $storedaccesspolicy = getModuleBuilderAccessPolicyFromClassFile($classfile);
1247 if ($accesspolicy !== null && ($storedaccesspolicy === null || $storedaccesspolicy->toJson() !== $accesspolicy->toJson())) {
1248 setEventMessages($langs->trans("WarningAccessPolicyOnRegeneration"), null, 'warnings');
1249 }
1250 $accesspolicy = $storedaccesspolicy;
1251 } catch (\InvalidArgumentException $e) {
1252 $error++;
1253 dol_syslog("modulebuilder: invalid access policy stored in ".$classfile.": ".$e->getMessage(), LOG_ERR);
1254 setEventMessages($langs->trans("ErrorModuleBuilderInvalidStoredAccessPolicy", basename($classfile)), null, 'errors');
1255 $tabobj = 'newobject';
1256 }
1257 }
1258
1259 // The dir was not created by init
1260 dol_mkdir($destdir.'/class');
1261 dol_mkdir($destdir.'/img');
1262 dol_mkdir($destdir.'/lib');
1263 dol_mkdir($destdir.'/scripts');
1264 dol_mkdir($destdir.'/sql');
1265 dol_mkdir($destdir.'/ajax');
1266 dol_mkdir($destdir.'/stats');
1267
1268 // Scan dir class to find if an object with the same name already exists.
1269 if (!$error) {
1270 $dirlist = dol_dir_list($destdir.'/class', 'files', 0, '\.txt$');
1271 $alreadyfound = false;
1272 foreach ($dirlist as $key => $val) {
1273 $filefound = preg_replace('/\.txt$/', '', $val['name']);
1274 if (dol_strtolower($objectname) == dol_strtolower($filefound) && $objectname != $filefound) {
1275 $alreadyfound = true;
1276 $error++;
1277 setEventMessages($langs->trans("AnObjectAlreadyExistWithThisNameAndDiffCase"), null, 'errors');
1278 break;
1279 }
1280 }
1281 }
1282
1283 // If we must reuse an existing table for properties, define $stringforproperties
1284 // Generate class file from the table
1285 $stringforproperties = '';
1286 $tablename = GETPOST('initfromtablename', 'alpha');
1287 if ($tablename) {
1288 $_results = $db->DDLDescTable($tablename);
1289 if (empty($_results)) {
1290 $error++;
1291 $langs->load("errors");
1292 setEventMessages($langs->trans("ErrorTableNotFound", $tablename), null, 'errors');
1293 } else {
1321 /*public $fields=array(
1322 'rowid' => array('type' => 'integer', 'label' => 'TechnicalID', 'enabled' => 1, 'visible' => -2, 'notnull' => 1, 'index' => 1, 'position' => 1, 'comment' => 'Id'),
1323 'ref' => array('type' => 'varchar(128)', 'label' => 'Ref', 'enabled' => 1, 'visible' => 1, 'notnull' => 1, 'showoncombobox' => 1, 'index' => 1, 'position' => 10, 'searchall' => 1, 'comment' => 'Reference of object'),
1324 'entity' => array('type' => 'integer', 'label' => 'Entity', 'enabled' => 1, 'visible' => 0, 'default' => 1, 'notnull' => 1, 'index' => 1, 'position' => 20),
1325 'label' => array('type' => 'varchar(255)', 'label' => 'Label', 'enabled' => 1, 'visible' => 1, 'position' => 30, 'searchall' => 1, 'css' => 'minwidth200', 'help' => 'Help text', 'alwayseditable' => '1'),
1326 'amount' => array('type' => 'double(24,8)', 'label' => 'Amount', 'enabled' => 1, 'visible' => 1, 'default' => 'null', 'position' => 40, 'searchall' => 0, 'isameasure' => 1, 'help' => 'Help text'),
1327 'fk_soc' => array('type' => 'integer:Societe:societe/class/societe.class.php', 'label' => 'ThirdParty', 'visible' => 1, 'enabled' => 1, 'position' => 50, 'notnull' => -1, 'index' => 1, 'searchall' => 1, 'help' => 'LinkToThirdparty'),
1328 'description' => array('type' => 'text', 'label' => 'Descrption', 'enabled' => 1, 'visible' => 0, 'position' => 60),
1329 'note_public' => array('type' => 'html', 'label' => 'NotePublic', 'enabled' => 1, 'visible' => 0, 'position' => 61),
1330 'note_private' => array('type' => 'html', 'label' => 'NotePrivate', 'enabled' => 1, 'visible' => 0, 'position' => 62),
1331 'date_creation' => array('type' => 'datetime', 'label' => 'DateCreation', 'enabled' => 1, 'visible' => -2, 'notnull' => 1, 'position' => 500),
1332 'tms' => array('type' => 'timestamp', 'label' => 'DateModification', 'enabled' => 1, 'visible' => -2, 'notnull' => 1, 'position' => 501),
1333 //'date_valid' => array('type' => 'datetime', 'label' => 'DateCreation', 'enabled' => 1, 'visible' => -2, 'position' => 502),
1334 'fk_user_creat' => array('type' => 'integer', 'label' => 'UserAuthor', 'enabled' => 1, 'visible' => -2, 'notnull' => 1, 'position' => 510),
1335 'fk_user_modif' => array('type' => 'integer', 'label' => 'UserModif', 'enabled' => 1, 'visible' => -2, 'notnull' => -1, 'position' => 511),
1336 //'fk_user_valid' => array('type' => 'integer', 'label' => 'UserValidation', 'enabled' => 1, 'visible' => -1, 'position' => 512),
1337 'import_key' => array('type' => 'varchar(14)', 'label' => 'ImportId', 'enabled' => 1, 'visible' => -2, 'notnull' => -1, 'index' => 0, 'position' => 1000),
1338 'status' => array('type' => 'integer', 'label' => 'Status', 'enabled' => 1, 'visible' => 1, 'notnull' => 1, 'default' => 0, 'index' => 1, 'position' => 1000, 'arrayofkeyval' => array(0 => 'Draft', 1 => 'Active', -1 => 'Cancel')),
1339 );*/
1340
1341 $stringforproperties = '// BEGIN MODULEBUILDER PROPERTIES'."\n";
1342 $stringforproperties .= 'public $fields = array('."\n";
1343 $i = 10;
1344 while ($obj = $db->fetch_object($_results)) {
1345 // fieldname
1346 $fieldname = $obj->Field;
1347 // type
1348 $type = $obj->Type;
1349 if ($type == 'int(11)') {
1350 $type = 'integer';
1351 } elseif ($type == 'float') {
1352 $type = 'real';
1353 } elseif (strstr($type, 'tinyint')) {
1354 $type = 'integer';
1355 } elseif (strstr($type, 'url')) {
1356 $type = 'varchar(255)';
1357 } elseif ($obj->Field == 'fk_soc') {
1358 $type = 'integer:Societe:societe/class/societe.class.php';
1359 } elseif (preg_match('/^fk_proj/', $obj->Field)) {
1360 $type = 'integer:Project:projet/class/project.class.php:1:fk_statut=1';
1361 } elseif (preg_match('/^fk_prod/', $obj->Field)) {
1362 $type = 'integer:Product:product/class/product.class.php:1';
1363 } elseif ($obj->Field == 'fk_warehouse') {
1364 $type = 'integer:Entrepot:product/stock/class/entrepot.class.php';
1365 } elseif (preg_match('/^(fk_user|fk_commercial)/', $obj->Field)) {
1366 $type = 'integer:User:user/class/user.class.php';
1367 }
1368
1369 // notnull
1370 $notnull = ($obj->Null == 'YES' ? 0 : 1);
1371 if ($fieldname == 'fk_user_modif') {
1372 $notnull = -1;
1373 }
1374 // label
1375 $label = preg_replace('/_/', '', dol_ucfirst($fieldname));
1376 if ($fieldname == 'rowid') {
1377 $label = 'TechnicalID';
1378 }
1379 if ($fieldname == 'import_key') {
1380 $label = 'ImportId';
1381 }
1382 if ($fieldname == 'fk_soc') {
1383 $label = 'ThirdParty';
1384 }
1385 if (in_array($fieldname, array('tms', 'date_modification'))) {
1386 $label = 'DateModification';
1387 }
1388 if (in_array($fieldname, array('datec', 'date_creation'))) {
1389 $label = 'DateCreation';
1390 }
1391 if ($fieldname == 'date_valid') {
1392 $label = 'DateValidation';
1393 }
1394 if ($fieldname == 'datev') {
1395 $label = 'DateValidation';
1396 }
1397 if ($fieldname == 'note_private') {
1398 $label = 'NotePublic';
1399 }
1400 if ($fieldname == 'note_public') {
1401 $label = 'NotePrivate';
1402 }
1403 if ($fieldname == 'fk_user_creat') {
1404 $label = 'UserAuthor';
1405 }
1406 if ($fieldname == 'fk_user_modif') {
1407 $label = 'UserModif';
1408 }
1409 if ($fieldname == 'fk_user_valid') {
1410 $label = 'UserValidation';
1411 }
1412 // visible
1413 $visible = -1;
1414 if (in_array($fieldname, array('ref', 'label'))) {
1415 $visible = 1;
1416 }
1417 if ($fieldname == 'entity') {
1418 $visible = -2;
1419 }
1420 if ($fieldname == 'entity') {
1421 $visible = -2;
1422 }
1423 if ($fieldname == 'import_key') {
1424 $visible = -2;
1425 }
1426 if ($fieldname == 'fk_user_creat') {
1427 $visible = -2;
1428 }
1429 if ($fieldname == 'fk_user_modif') {
1430 $visible = -2;
1431 }
1432 if (in_array($fieldname, array('ref_ext', 'model_pdf', 'note_public', 'note_private'))) {
1433 $visible = 0;
1434 }
1435 // enabled
1436 $enabled = 1;
1437 // default
1438 $default = '';
1439 if ($fieldname == 'entity') {
1440 $default = 1;
1441 }
1442 // position
1443 $position = $i;
1444 if (in_array($fieldname, array('status', 'statut', 'fk_status', 'fk_statut'))) {
1445 $position = 500;
1446 }
1447 if ($fieldname == 'import_key') {
1448 $position = 900;
1449 }
1450 // $alwayseditable
1451 $alwayseditable = 0;
1452 if ($fieldname == 'label') {
1453 $alwayseditable = 1;
1454 } else {
1455 $alwayseditable = 0;
1456 }
1457 // index
1458 $index = 0;
1459 if ($fieldname == 'entity') {
1460 $index = 1;
1461 }
1462 // css, cssview, csslist
1463 $css = '';
1464 $cssview = '';
1465 $csslist = '';
1466 if (preg_match('/^fk_/', $fieldname)) {
1467 $css = 'maxwidth500 widthcentpercentminusxx';
1468 }
1469 if ($fieldname == 'label') {
1470 $css = 'minwidth300';
1471 $cssview = 'wordbreak';
1472 }
1473 if (in_array($fieldname, array('note_public', 'note_private'))) {
1474 $cssview = 'wordbreak';
1475 }
1476 if (in_array($fieldname, array('ref', 'label')) || preg_match('/integer:/', $type)) {
1477 $csslist = 'tdoverflowmax150';
1478 }
1479
1480 // type
1481 $picto = '';
1482 if (isset($obj->Picto)) { // This should never exists
1483 $picto = $obj->Picto;
1484 }
1485 if (preg_match('/^fk_soc/', $obj->Field)) {
1486 $picto = 'company';
1487 } elseif (preg_match('/^fk_contact/', $obj->Field)) {
1488 $picto = 'contact';
1489 } elseif (preg_match('/^fk_bank/', $obj->Field)) {
1490 $picto = 'bank';
1491 } elseif (preg_match('/^fk_user/', $obj->Field)) {
1492 $picto = 'user';
1493 } elseif (preg_match('/^fk_warehouse/', $obj->Field)) {
1494 $picto = 'warehouse';
1495 } elseif (preg_match('/^fk_prod/', $obj->Field)) {
1496 $picto = 'product';
1497 } elseif (preg_match('/^fk_proj/', $obj->Field)) {
1498 $picto = 'project';
1499 } elseif (preg_match('/^fk_task/', $obj->Field)) {
1500 $picto = 'task';
1501 }
1502
1503 // lang
1504 $lang = $module.'@'.$module;
1505
1506 // Build the property string
1507 $stringforproperties .= "'".$obj->Field."' => array('type' => '".$type."', 'label' => '".$label."',";
1508 if ($default != '') {
1509 $stringforproperties .= " 'default' => ".$default.",";
1510 }
1511 $stringforproperties .= " 'enabled' => ".$enabled.",";
1512 $stringforproperties .= " 'visible' => ".$visible;
1513 if ($notnull) {
1514 $stringforproperties .= ", 'notnull' => ".$notnull;
1515 }
1516 if ($alwayseditable) {
1517 $stringforproperties .= ", 'alwayseditable' => 1";
1518 }
1519 if ($fieldname == 'ref' || $fieldname == 'code') {
1520 $stringforproperties .= ", 'showoncombobox' => 1";
1521 }
1522 $stringforproperties .= ", 'position' => ".$position;
1523 if ($index) {
1524 $stringforproperties .= ", 'index' => ".$index;
1525 }
1526 if ($picto) {
1527 $stringforproperties .= ", 'picto' => '".$picto."'";
1528 }
1529 if ($css) {
1530 $stringforproperties .= ", 'css' => '".$css."'";
1531 }
1532 if ($cssview) {
1533 $stringforproperties .= ", 'cssview' => '".$cssview."'";
1534 }
1535 if ($csslist) {
1536 $stringforproperties .= ", 'csslist' => '".$csslist."'";
1537 }
1538
1539 $stringforproperties .= ", 'lang' => '".$lang."'";
1540
1541 $stringforproperties .= "),\n";
1542 $i += 5;
1543 }
1544 $stringforproperties .= ');'."\n";
1545 $stringforproperties .= '// END MODULEBUILDER PROPERTIES'."\n";
1546 }
1547 }
1548
1549 // Hook to define the properties of the new object from another source than a table (a hook returning
1550 // resArray['fields'] with the same format than $fields replaces the properties of the template)
1551 if (!$error) {
1552 $parameters = array('module' => $module, 'objectname' => $objectname, 'dirins' => $dirins, 'initfromtablename' => $tablename);
1553 $reshook = $hookmanager->executeHooks('getFieldsForNewObject', $parameters, $hookobject, $action);
1554 if ($reshook < 0) {
1555 $error++;
1556 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
1557 $tabobj = 'newobject';
1558 } elseif ($reshook > 0 && !empty($hookmanager->resArray['fields']) && is_array($hookmanager->resArray['fields'])) {
1559 // Class file is reformatted later by rebuildObjectClass()
1560 $stringforproperties = '// BEGIN MODULEBUILDER PROPERTIES'."\n";
1561 $stringforproperties .= 'public $fields = '.var_export($hookmanager->resArray['fields'], true).';'."\n";
1562 $stringforproperties .= '// END MODULEBUILDER PROPERTIES'."\n";
1563 }
1564 }
1565
1566 $filetogenerate = array();
1567 if (!$error) {
1568 // Copy some files
1569 $filetogenerate = [];
1570 foreach ([
1571 'myobject_card.php',
1572 'myobject_note.php',
1573 'myobject_contact.php',
1574 'myobject_document.php',
1575 'myobject_agenda.php',
1576 'myobject_list.php',
1577 'admin/myobject_extrafields.php',
1578 'ajax/myobject.php',
1579 'lib/mymodule_myobject.lib.php',
1580 //'test/phpunit/MyObjectTest.php',
1581 'sql/llx_mymodule_myobject.sql',
1582 'sql/llx_mymodule_myobject.key.sql',
1583 'sql/llx_mymodule_myobject_extrafields.sql',
1584 'sql/llx_mymodule_myobject_extrafields.key.sql',
1585 //'scripts/mymodule.php',
1586 'class/myobject.class.php',
1587 'class/myobjectstats.class.php',
1588 //'class/api_mymodule.class.php',
1589 'stats/myobject_index.php',
1590 ] as $templateFile) {
1591 $filetogenerate[$templateFile] = $ncObj->applyToFilename($templateFile);
1592 }
1593
1594 // Exclude tab page files for tabs not selected by user
1595 foreach (getModuleBuilderObjectTabs() as $tabkey => $tabinfo) {
1596 if (!in_array($tabkey, $enabledtabs, true)) {
1597 unset($filetogenerate[$tabinfo['file']]);
1598 }
1599 }
1600
1601 if (GETPOST('includerefgeneration', 'aZ09')) {
1602 dol_mkdir($destdir.'/core/modules/'.dol_strtolower($module));
1603
1604 foreach ([
1605 'core/modules/mymodule/mod_myobject_advanced.php',
1606 'core/modules/mymodule/mod_myobject_standard.php',
1607 'core/modules/mymodule/modules_myobject.php',
1608 ] as $templateFile) {
1609 $filetogenerate[$templateFile] = $ncObj->applyToFilename($templateFile);
1610 }
1611 }
1612 if (GETPOST('includedocgeneration', 'aZ09')) {
1613 dol_mkdir($destdir.'/core/modules/'.dol_strtolower($module));
1614 dol_mkdir($destdir.'/core/modules/'.dol_strtolower($module).'/doc');
1615
1616 foreach ([
1617 'core/modules/mymodule/doc/doc_generic_myobject_odt.modules.php',
1618 'core/modules/mymodule/doc/pdf_standard_myobject.modules.php',
1619 ] as $templateFile) {
1620 $filetogenerate[$templateFile] = $ncObj->applyToFilename($templateFile);
1621 }
1622 }
1623 $class = null;
1624 if (GETPOST('generatepermissions', 'aZ09')) {
1625 $firstobjectname = 'myobject';
1626 $pathtofile = $listofmodules[dol_strtolower($module)]['moduledescriptorrelpath'];
1627 dol_include_once($pathtofile);
1628 $class = 'mod'.$module;
1629 $moduleobj = null;
1630 if (class_exists($class)) {
1631 try {
1632 $moduleobj = new $class($db);
1633 '@phan-var-force DolibarrModules $moduleobj';
1635 } catch (Exception $e) {
1636 $error++;
1637 dol_print_error($db, $e->getMessage());
1638 }
1639 }
1640 if (is_object($moduleobj)) {
1641 $rights = $moduleobj->rights;
1642 } else {
1643 $rights = [];
1644 }
1645 $moduledescriptorfile = $destdir.'/core/modules/mod'.$module.'.class.php';
1646 $checkComment = checkExistComment($moduledescriptorfile, 1);
1647 if ($checkComment < 0) {
1648 $langs->load("errors");
1649 setEventMessages($langs->trans("WarningCommentNotFound", $langs->trans("Permissions"), "mod".$module."class.php"), null, 'warnings');
1650 } else {
1651 $reportPerms = modulebuilderSyncRights(RightsSyncCommand::forObjectCreation($module, $moduledescriptorfile, is_array($rights) ? $rights : array(), $objectname));
1652 if ($reportPerms->skipped > 0) {
1653 $langs->load("errors");
1654 setEventMessages($langs->trans("WarningPermissionAlreadyExist", $langs->transnoentities($objectname)), null, 'warnings');
1655 }
1656 }
1657 }
1658
1659 if (!$error) {
1660 foreach ($filetogenerate as $srcfile => $destfile) {
1661 $result = dol_copy($srcdir.'/'.$srcfile, $destdir.'/'.$destfile, $newmask, 0);
1662 if ($result > 0) {
1663 $copiedfiles[$srcfile] = $destfile;
1664 }
1665 if ($result <= 0) {
1666 if ($result < 0) {
1667 $warning++;
1668 $langs->load("errors");
1669 setEventMessages($langs->trans("ErrorFailToCopyFile", $srcdir.'/'.$srcfile, $destdir.'/'.$destfile), null, 'errors');
1670 } else {
1671 // $result == 0
1672 setEventMessages($langs->trans("FileAlreadyExists", $destfile), null, 'warnings');
1673 }
1674 }
1675 $arrayreplacement = array(
1676 '/myobject\.class\.php/' => dol_strtolower($objectname).'.class.php',
1677 '/myobject\.lib\.php/' => dol_strtolower($objectname).'.lib.php',
1678 );
1679
1680 dolReplaceInFile($destdir.'/'.$destfile, $arrayreplacement, '', '0', 0, 1);
1681 }
1682 }
1683
1684 // Replace property section with $stringforproperties
1685 if (!$error && $stringforproperties) {
1686 //var_dump($stringforproperties);exit;
1687 $arrayreplacement = array(
1688 '/\/\/ BEGIN MODULEBUILDER PROPERTIES.*\/\/ END MODULEBUILDER PROPERTIES/ims' => $stringforproperties
1689 );
1690
1691 dolReplaceInFile($destdir.'/class/'.dol_strtolower($objectname).'.class.php', $arrayreplacement, '', '0', 0, 1);
1692 }
1693
1694 // Edit the class 'class/'.dol_strtolower($objectname).'.class.php'
1695 if (GETPOST('includerefgeneration', 'aZ09')) {
1696 // Replace 'visible' => 1, 'noteditable' => 0, 'default' => ''
1697 $arrayreplacement = array(
1698 '/\'visible\'s*=>s*1,\s*\'noteditable\'s*=>s*0,\s*\'default\'s*=>s*\'\'/' => "'visible' => 4, 'noteditable' => 1, 'default' => '(PROV)'"
1699 );
1700 //var_dump($arrayreplacement);exit;
1701 //var_dump($destdir.'/class/'.dol_strtolower($objectname).'.class.php');exit;
1702 dolReplaceInFile($destdir.'/class/'.dol_strtolower($objectname).'.class.php', $arrayreplacement, '', '0', 0, 1);
1703
1704 $arrayreplacement = array(
1705 '/\'models\' => 0,/' => '\'models\' => 1,'
1706 );
1707 dolReplaceInFile($destdir.'/core/modules/mod'.$module.'.class.php', $arrayreplacement, '', '0', 0, 1);
1708 }
1709
1710 // Edit the setup file and the card page
1711 if (GETPOST('includedocgeneration', 'aZ09')) {
1712 // Replace some var init into some files
1713 $arrayreplacement = array(
1714 '/\$includedocgeneration = 0;/' => '$includedocgeneration = 1;'
1715 );
1716 dolReplaceInFile($destdir.'/class/'.dol_strtolower($objectname).'.class.php', $arrayreplacement, '', '0', 0, 1);
1717 dolReplaceInFile($destdir.'/'.dol_strtolower($objectname).'_card.php', $arrayreplacement, '', '0', 0, 1);
1718
1719 $arrayreplacement = array(
1720 '/\'models\' => 0,/' => '\'models\' => 1,'
1721 );
1722
1723 dolReplaceInFile($destdir.'/core/modules/mod'.$module.'.class.php', $arrayreplacement, '', '0', 0, 1);
1724 }
1725
1726 // TODO Update entries '$myTmpObjects['MyObject'] = array('includerefgeneration' => 0, 'includedocgeneration' => 0);'
1727
1728
1729 // Scan for object class files
1730 $listofobject = dol_dir_list($destdir.'/class', 'files', 0, '\.class\.php$');
1731
1732 $firstobjectname = '';
1733 $stringtoadd = '';
1734 foreach ($listofobject as $fileobj) {
1735 if (preg_match('/^api_/', $fileobj['name'])) {
1736 continue;
1737 }
1738 if (preg_match('/^actions_/', $fileobj['name'])) {
1739 continue;
1740 }
1741
1742 $tmpcontent = file_get_contents($fileobj['fullname']);
1743 $reg = array();
1744 if (preg_match('/class\s+([^\s]*)\s+extends\s+CommonObject/ims', $tmpcontent, $reg)) {
1745 $objectnameloop = $reg[1];
1746 if (empty($firstobjectname)) {
1747 $firstobjectname = $objectnameloop;
1748 }
1749 }
1750
1751 // Regenerate left menu entry in descriptor for $objectname
1752 $stringtoadd = "
1753 \$this->menu[\$r++] = array(
1754 'fk_menu' => 'fk_mainmenu=mymodule',
1755 'type' => 'left',
1756 'titre' => 'MyObject',
1757 'prefix' => img_picto('', \$this->picto, 'class=\"paddingright pictofixedwidth valignmiddle\"'),
1758 'mainmenu' => 'mymodule',
1759 'leftmenu' => 'myobject',
1760 'url' => '/mymodule/myobject_list.php',
1761 'langs' => 'mymodule@mymodule',
1762 'position' => 1000 + \$r,
1763 'enabled' => 'isModEnabled(\"mymodule\")',
1764 'perms' => '".(GETPOST('generatepermissions') ? '$user->hasRight("mymodule", "myobject", "read")' : '1')."',
1765 'target' => '',
1766 'user' => 2,
1767 'object' => 'MyObject'
1768 );
1769 \$this->menu[\$r++] = array(
1770 'fk_menu' => 'fk_mainmenu=mymodule,fk_leftmenu=myobject',
1771 'type' => 'left',
1772 'titre' => 'List MyObject',
1773 'mainmenu' => 'mymodule',
1774 'leftmenu' => 'mymodule_myobject_list',
1775 'url' => '/mymodule/myobject_list.php',
1776 'langs' => 'mymodule@mymodule',
1777 'position' => 1000 + \$r,
1778 'enabled' => 'isModEnabled(\"mymodule\")',
1779 'perms' => '".(GETPOST('generatepermissions') ? '$user->hasRight("mymodule", "myobject", "read")' : '1')."',
1780 'target' => '',
1781 'user' => 2,
1782 'object' => 'MyObject'
1783 );
1784 \$this->menu[\$r++] = array(
1785 'fk_menu' => 'fk_mainmenu=mymodule,fk_leftmenu=myobject',
1786 'type' => 'left',
1787 'titre' => 'New MyObject',
1788 'mainmenu' => 'mymodule',
1789 'leftmenu' => 'mymodule_myobject_new',
1790 'url' => '/mymodule/myobject_card.php?action=create',
1791 'langs' => 'mymodule@mymodule',
1792 'position' => 1000 + \$r,
1793 'enabled' => 'isModEnabled(\"mymodule\")',
1794 'perms' => '".(GETPOST('generatepermissions') ? '$user->hasRight("mymodule", "myobject", "write")' : '1')."',
1795 'target' => '',
1796 'user' => 2,
1797 'object' => 'MyObject'
1798 );";
1799 $stringtoadd = $ncObj->applyTo($stringtoadd);
1800
1801 $moduledescriptorfile = $destdir.'/core/modules/mod'.$module.'.class.php';
1802 }
1803 // TODO Allow a replace with regex using dolReplaceInFile with param arryreplacementisregex to 1
1804 // TODO Avoid duplicate addition
1805
1806 // load class and check if menu exist with same object name
1807 $pathtofile = $listofmodules[dol_strtolower($module)]['moduledescriptorrelpath'];
1808 dol_include_once($pathtofile);
1809 $class = 'mod'.$module;
1810 $moduleobj = null;
1811 if (class_exists($class)) {
1812 try {
1813 $moduleobj = new $class($db);
1814 '@phan-var-force DolibarrModules $moduleobj';
1816 } catch (Exception $e) {
1817 $error++;
1818 dol_print_error($db, $e->getMessage());
1819 }
1820 }
1821 if (is_object($moduleobj)) {
1822 $menus = $moduleobj->menu;
1823 } else {
1824 $menus = array();
1825 }
1826 $counter = 0 ;
1827 foreach ($menus as $menu) {
1828 if ($menu['leftmenu'] == dol_strtolower($objectname)) {
1829 $counter++;
1830 }
1831 }
1832 if (!$counter) {
1833 $checkComment = checkExistComment($moduledescriptorfile, 0);
1834 if ($checkComment < 0) {
1835 $warning++;
1836 $langs->load("errors");
1837 setEventMessages($langs->trans("WarningCommentNotFound", $langs->trans("Menus"), basename($moduledescriptorfile)), null, 'warnings');
1838 } else {
1839 $arrayofreplacement = array(
1840 '/* BEGIN MODULEBUILDER LEFTMENU MYOBJECT */' => '/* BEGIN MODULEBUILDER LEFTMENU '.dol_strtoupper($objectname).' */'.$stringtoadd."\n\t\t".'/* END MODULEBUILDER LEFTMENU '.dol_strtoupper($objectname).' */'."\n\t\t".'/* BEGIN MODULEBUILDER LEFTMENU MYOBJECT */'
1841 );
1842 dolReplaceInFile($moduledescriptorfile, $arrayofreplacement);
1843 }
1844 }
1845 // Add module descriptor to list of files to replace "MyObject' string with real name of object.
1846 $filetogenerate[] = 'core/modules/mod'.$module.'.class.php';
1847 }
1848
1849 if (! $error && GETPOST('nogeneratelines', 'aZ09')) {
1850 $checkComment = checkExistComment($moduledescriptorfile, 0);
1851 if ($checkComment < 0) {
1852 $warning++;
1853 $langs->load("errors");
1854 setEventMessages($langs->trans("WarningCommentNotFound", $langs->trans("Menus"), basename($moduledescriptorfile)), null, 'warnings');
1855 } else {
1856 // File path
1857 $TFilePaths = [
1858 $destdir . '/class/' . dol_strtolower($objectname) . '.class.php',
1859 $destdir . '/class/api_' . dol_strtolower($module) . '.class.php',
1860 $destdir . '/' . dol_strtolower($objectname) . '_card.php'
1861 ];
1862
1863 // Pattern to remove everything between the tags
1865 foreach ($TFilePaths as $filePath) {
1866 // Skip files that were not generated (e.g. the API class when API generation is disabled);
1867 // a missing optional file must not abort the whole object generation.
1868 if (file_exists($filePath) && !removePatternFromFile($filePath, $pattern)) {
1869 $error++;
1870 }
1871 }
1872 }
1873 }
1874
1875 // Apply object tab selection on the generated lib file:
1876 // selected tabs -> hardcode the show flag to 1 (visible without extra config) ; unselected -> remove flag declaration and tab block
1877 if (!$error) {
1878 $libdestfile = $destdir.'/'.$ncObj->applyToFilename('lib/mymodule_myobject.lib.php');
1879 foreach (getModuleBuilderObjectTabs() as $tabkey => $tabinfo) {
1880 $marker = $tabinfo['marker'];
1881 if (in_array($tabkey, $enabledtabs, true)) {
1882 $arrayreplacement = array(
1883 '/\$'.$tabinfo['var'].' = getDolGlobalInt\‍([^;]*\‍);/' => '$'.$tabinfo['var'].' = 1;'
1884 );
1885 if (dolReplaceInFile($libdestfile, $arrayreplacement, '', '0', 0, 1) < 0) {
1886 $error++;
1887 dol_syslog("modulebuilder: failed to activate tab flag '".$tabkey."' in ".$libdestfile, LOG_ERR);
1888 }
1889 } else {
1890 if (!removePatternFromFile($libdestfile, '/\h*\/\/ BEGIN MODULEBUILDER TABFLAG '.$marker.'.*?\/\/ END MODULEBUILDER TABFLAG '.$marker.'\s*/s')
1891 || !removePatternFromFile($libdestfile, '/\h*\/\/ BEGIN MODULEBUILDER TAB '.$marker.'.*?\/\/ END MODULEBUILDER TAB '.$marker.'\s*/s')) {
1892 $error++;
1893 dol_syslog("modulebuilder: failed to purge tab '".$tabkey."' in ".$libdestfile, LOG_ERR);
1894 }
1895 }
1896 }
1897 $carddestfile = $destdir.'/'.$ncObj->applyToFilename('myobject_card.php');
1898
1899 // Agenda has an extra event widget on the card page: purge it too to avoid a dead link when the agenda tab is excluded
1900 if (!$error && !in_array('agenda', $enabledtabs, true)) {
1901 if (!removePatternFromFile($carddestfile, '/\h*\/\/ BEGIN MODULEBUILDER TAB AGENDA.*?\/\/ END MODULEBUILDER TAB AGENDA\s*/s')) {
1902 $error++;
1903 dol_syslog("modulebuilder: failed to purge agenda widget in ".$carddestfile, LOG_ERR);
1904 }
1905 }
1906
1907 // Apply card action selection on the generated card page:
1908 // unselected action -> purge every block it anchors ; selected action shipped commented out -> uncomment it
1909 if (!$error) {
1910 foreach (getModuleBuilderObjectCardActions() as $actionkey => $actioninfo) {
1911 if (!in_array($actionkey, $enabledcardactions, true)) {
1912 if (!removePatternFromFile($carddestfile, getModuleBuilderCardActionBlockPattern($actioninfo['marker']))) {
1913 $error++;
1914 dol_syslog("modulebuilder: failed to purge card action '".$actionkey."' in ".$carddestfile, LOG_ERR);
1915 }
1916 } elseif ($actioninfo['mode'] == 'activate') {
1917 foreach (getModuleBuilderCardActionUncommentPatterns($actioninfo['marker']) as $uncommentpattern) {
1918 if (!removePatternFromFile($carddestfile, $uncommentpattern)) {
1919 $error++;
1920 dol_syslog("modulebuilder: failed to activate card action '".$actionkey."' in ".$carddestfile, LOG_ERR);
1921 }
1922 }
1923 }
1924 }
1925 }
1926
1927 // Resolve the access policy block of the files copied by this run only: a file that already existed holds
1928 // substituted names and no marker any more
1929 if (!$error) {
1930 $accesspolicytargets = array_fill_keys(getModuleBuilderAccessPolicyPages(), 'page');
1931 $accesspolicytargets['class/myobject.class.php'] = 'class';
1932 foreach ($accesspolicytargets as $templatefile => $targettype) {
1933 if (!isset($copiedfiles[$templatefile])) {
1934 continue;
1935 }
1936 $targetfile = $destdir.'/'.$copiedfiles[$templatefile];
1937 $result = ($targettype == 'class') ? applyModuleBuilderAccessPolicyToClass($targetfile, $accesspolicy) : applyModuleBuilderAccessPolicyToPage($targetfile, $accesspolicy);
1938 if ($result < 0) {
1939 $error++;
1940 $langs->load("errors");
1941 setEventMessages($langs->trans("ErrorFailToMakeReplacementInto", $targetfile), null, 'errors');
1942 }
1943 }
1944 }
1945
1946 if ($objectalreadyexists) {
1947 setEventMessages($langs->trans("WarningTabSelectionOnRegeneration"), null, 'warnings');
1948 setEventMessages($langs->trans("WarningCardActionSelectionOnRegeneration"), null, 'warnings');
1949 }
1950 }
1951
1952 if (!$error) {
1953 // Edit PHP files to make replacement
1954 foreach ($filetogenerate as $destfile) {
1955 $phpfileval['fullname'] = $destdir.'/'.$destfile;
1956
1957 //var_dump($phpfileval['fullname']);
1958 $licenceValue = getDolGlobalString('MODULEBUILDER_SPECIFIC_AUTHOR')
1959 ? dol_print_date($now, '%Y') . ' ' . getDolGlobalString('MODULEBUILDER_SPECIFIC_AUTHOR')
1960 : getLicenceHeader($user, $langs, $now);
1961
1962 $arrayreplacement = array_merge(
1963 $ncObj->getSubstitutionMap(),
1964 [
1965 'htdocs/modulebuilder/template/' => $ncObj->moduleNameLower,
1966 '---Replace with your own copyright and developer email---' => $licenceValue,
1967 ]
1968 );
1969
1970 if (basename($phpfileval['fullname']) === 'mod'.$module.'.class.php') {
1971 // Module descriptor: substitute content but keep the persistent MODULEBUILDER markers intact
1972 $result = dolReplaceInFilePreservingModuleBuilderMarkers($phpfileval['fullname'], $arrayreplacement);
1973 } else {
1974 $result = dolReplaceInFile($phpfileval['fullname'], $arrayreplacement); // @phpstan-ignore-line
1975 }
1976 //var_dump($result);
1977 if ($result < 0) {
1978 $langs->load("errors");
1979 setEventMessages($langs->trans("ErrorFailToMakeReplacementInto", $phpfileval['fullname']), null, 'errors');
1980 } else {
1981 modulebuilderValidateGeneratedFile($phpfileval['fullname'], $ncObj);
1982 }
1983 }
1984 }
1985
1986 if (!$error && $ncObj !== null) {
1987 // Apply object name substitution to ALL PHP files in the module directory.
1988 // initmodule only substitutes the module name; files it creates (e.g. testmodindex.php,
1989 // lib/testmod.lib.php, admin/setup.php) still contain myobject/mymodule placeholders
1990 // that must be resolved when an object is first added.
1991 $licenceValueAll = getDolGlobalString('MODULEBUILDER_SPECIFIC_AUTHOR')
1992 ? dol_print_date($now, '%Y') . ' ' . getDolGlobalString('MODULEBUILDER_SPECIFIC_AUTHOR')
1993 : getLicenceHeader($user, $langs, $now);
1994 $moduleReplacementAll = array_merge(
1995 $ncObj->getSubstitutionMap(),
1996 [
1997 'htdocs/modulebuilder/template/' => $ncObj->moduleNameLower,
1998 '---Replace with your own copyright and developer email---' => $licenceValueAll,
1999 ]
2000 );
2001 $allModulePhpFiles = dol_dir_list($destdir, 'files', 1, '\.php$');
2002 // The module descriptor must NOT go through the blanket substitution: it keeps persistent
2003 // MYOBJECT/MYMODULE markers (TOPMENU/LEFTMENU) reused when generating subsequent objects, and its
2004 // own placeholders are already resolved by initmodule and the dedicated menu/permission blocks.
2005 $moduledescriptorbasename = 'mod'.$module.'.class.php';
2006 if (is_array($allModulePhpFiles) && !empty($allModulePhpFiles)) {
2007 foreach ($allModulePhpFiles as $phpFileval) {
2008 if (basename($phpFileval['fullname']) === $moduledescriptorbasename) {
2009 continue;
2010 }
2011 $result = dolReplaceInFile($phpFileval['fullname'], $moduleReplacementAll);
2012 if ($result < 0) {
2013 $langs->load("errors");
2014 setEventMessages($langs->trans("ErrorFailToMakeReplacementInto", $phpFileval['fullname']), null, 'warnings');
2015 }
2016 }
2017 }
2018 // Delete initmodule placeholder files superseded by initobject-generated files.
2019 $moduleLowerForPlaceholder = dol_strtolower($module);
2020 foreach ([
2021 $destdir . '/stats/myobject_index.php',
2022 $destdir . '/lib/' . $moduleLowerForPlaceholder . '_myobject.lib.php',
2023 ] as $placeholder) {
2024 if (file_exists($placeholder)) {
2025 dol_delete_file($placeholder);
2026 }
2027 }
2028 }
2029
2030 $object = null;
2031 if (!$error) {
2032 // Edit the class file to write properties
2033 $object = rebuildObjectClass($destdir, $module, $objectname, $newmask);
2034
2035 if (is_numeric($object) && $object <= 0) {
2036 $pathoffiletoeditsrc = $destdir.'/class/'.dol_strtolower($objectname).'.class.php';
2037 $langs->load("errors");
2038 setEventMessages($langs->trans('ErrorFailToCreateFile', $pathoffiletoeditsrc), null, 'errors');
2039 $warning++;
2040 }
2041 // check if documentation was generate and add table of properties object
2042 $file = $destdir.'/class/'.dol_strtolower($objectname).'.class.php';
2043 $destfile = $destdir.'/doc/Documentation.asciidoc';
2044
2045 if (file_exists($destfile)) {
2046 writePropsInAsciiDoc($file, $objectname, $destfile);
2047 }
2048 }
2049 if (!$error && $object !== null) {
2050 // Edit sql with new properties
2051 $result = rebuildObjectSql($destdir, $module, $objectname, $newmask, '', $object);
2052
2053 if ($result <= 0) {
2054 $langs->load("errors");
2055 setEventMessages($langs->trans('ErrorFailToCreateFile', '.sql'), null);
2056 $error++;
2057 }
2058 }
2059
2060 if (!$error) {
2061 setEventMessages($langs->trans('FilesForObjectInitialized', $objectname), null);
2062 $tabobj = $objectname;
2063 } else {
2064 $tabobj = 'newobject';
2065 }
2066
2067 // check if module is enabled
2069 $result = unActivateModule(dol_strtolower($module));
2070 dolibarr_set_const($db, "MAIN_IHM_PARAMS_REV", getDolGlobalInt('MAIN_IHM_PARAMS_REV') + 1, 'chaine', 0, '', $conf->entity);
2071 if ($result) {
2072 setEventMessages($result, null, 'errors');
2073 }
2074 $langs->load("errors");
2075 setEventMessages($langs->trans('WarningModuleNeedRefresh', $langs->transnoentities($module)), null, 'warnings');
2076 header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=objects&module='.$module);
2077 exit;
2078 }
2079}
2080
2081// Add a dictionary
2082if ($dirins && $action == 'initdic' && $module && empty($cancel) /* && $user->hasRight("modulebuilder", "run") // already checked */) {
2083 $pathtofile = $listofmodules[dol_strtolower($module)]['moduledescriptorrelpath'];
2084 $destdir = $dirins.'/'.dol_strtolower($module);
2085 $moduledescriptorfile = $dirins.'/'.dol_strtolower($module).'/core/modules/mod'.$module.'.class.php';
2086
2087 if (!GETPOST('dicname')) {
2088 $error++;
2089 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Table")), null, 'errors');
2090 }
2091 if (!GETPOST('label')) {
2092 $error++;
2093 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Label")), null, 'errors');
2094 }
2095 if (!$error) {
2096 $newdicname = $dicname;
2097 if (!preg_match('/^c_/', $newdicname)) {
2098 $newdicname = 'c_'.$dicname;
2099 }
2100 dol_include_once($pathtofile);
2101 $class = 'mod'.$module;
2102
2103 $moduleobj = null;
2104 if (class_exists($class)) {
2105 try {
2106 $moduleobj = new $class($db);
2107 '@phan-var-force DolibarrModules $moduleobj';
2109 } catch (Exception $e) {
2110 $error++;
2111 dol_print_error($db, $e->getMessage());
2112 }
2113 } else {
2114 $error++;
2115 }
2116 if ($moduleobj === null) {
2117 $langs->load("errors");
2118 dol_print_error($db, $langs->trans("ErrorFailedToLoadModuleDescriptorForXXX", $module));
2119 exit;
2120 }
2121 $dictionaries = $moduleobj->dictionaries;
2122 $checkComment = checkExistComment($moduledescriptorfile, 2);
2123 if ($checkComment < 0) {
2124 $langs->load("errors");
2125 setEventMessages($langs->trans("WarningCommentNotFound", $langs->trans("Dictionaries"), "mod".$module."class.php"), null, 'warnings');
2126 } else {
2127 createNewDictionnary($module, $moduledescriptorfile, $newdicname, $dictionaries);
2128 if (function_exists('opcache_invalidate')) {
2129 opcache_reset(); // remove the include cache hell !
2130 }
2131 clearstatcache(true);
2132 header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=dictionaries&module='.$module.($forceddirread ? '@'.$dirread : ''));
2133 exit;
2134 }
2135 }
2136}
2137
2138// Delete a SQL table
2139if ($dirins && ($action == 'droptable' || $action == 'droptableextrafields') && !empty($module) && !empty($tabobj) /* && $user->hasRight("modulebuilder", "run") // already checked */) {
2140 $objectname = $tabobj;
2141
2142 $arrayoftables = array();
2143 if ($action == 'droptable') { // Test on permission already done
2144 $arrayoftables[] = MAIN_DB_PREFIX.dol_strtolower($module).'_'.dol_strtolower($tabobj);
2145 }
2146 if ($action == 'droptableextrafields') { // Test on permission already done
2147 $arrayoftables[] = MAIN_DB_PREFIX.dol_strtolower($module).'_'.dol_strtolower($tabobj).'_extrafields';
2148 }
2149
2150 foreach ($arrayoftables as $tabletodrop) {
2151 $nb = -1;
2152 $sql = "SELECT COUNT(*) as nb FROM ".$tabletodrop;
2153 $resql = $db->query($sql);
2154 if ($resql) {
2155 $obj = $db->fetch_object($resql);
2156 if ($obj) {
2157 $nb = (int) $obj->nb;
2158 }
2159 } else {
2160 if ($db->lasterrno() == 'DB_ERROR_NOSUCHTABLE') {
2161 setEventMessages($langs->trans("TableDoesNotExists", $tabletodrop), null, 'warnings');
2162 } else {
2163 dol_print_error($db);
2164 }
2165 }
2166 if ($nb == 0) {
2167 $resql = $db->DDLDropTable($tabletodrop);
2168 //var_dump($resql);
2169 setEventMessages($langs->trans("TableDropped", $tabletodrop), null, 'mesgs');
2170 } elseif ($nb > 0) {
2171 setEventMessages($langs->trans("TableNotEmptyDropCanceled", $tabletodrop), null, 'warnings');
2172 }
2173 }
2174}
2175
2176if ($dirins && $action == 'addproperty' && empty($cancel) && !empty($module) && (!empty($tabobj) || !empty(GETPOST('obj'))) /* && $user->hasRight("modulebuilder", "run") // already checked */) {
2177 $error = 0;
2178
2179 $objectname = (GETPOST('obj') ? GETPOST('obj') : $tabobj);
2180
2181 $dirins = $dirread = $listofmodules[dol_strtolower($module)]['moduledescriptorrootpath'];
2182 $moduletype = $listofmodules[dol_strtolower($module)]['moduletype'];
2183
2184 $srcdir = $dirread.'/'.dol_strtolower($module);
2185 $destdir = $dirins.'/'.dol_strtolower($module);
2186 dol_mkdir($destdir);
2187
2188 $objects = dolGetListOfObjectClasses($destdir);
2189 if (!in_array($objectname, array_values($objects))) {
2190 $error++;
2191 $langs->load("errors");
2192 setEventMessages($langs->trans("ErrorObjectNotFound", $langs->transnoentities($objectname)), null, 'errors');
2193 }
2194
2195 $addfieldentry = array();
2196
2197 // We click on add property
2198 if (!GETPOST('regenerateclasssql') && !GETPOST('regeneratemissing')) {
2199 if (!GETPOST('propname', 'aZ09')) {
2200 $error++;
2201 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Name")), null, 'errors');
2202 }
2203 if (!GETPOST('proplabel', 'alpha')) {
2204 $error++;
2205 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Label")), null, 'errors');
2206 }
2207 if (!GETPOST('proptype', 'alpha')) {
2208 $error++;
2209 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Type")), null, 'errors');
2210 }
2211
2212
2213 if (!$error && !GETPOST('regenerateclasssql') && !GETPOST('regeneratemissing')) {
2214 // Preserve case for composite types such as 'integer:Societe:societe/class/societe.class.php:1:(...__SHARED_ENTITIES__...)'
2215 // because the colon-separated parts include PHP class names (case-sensitive) and __XXX__ substitution
2216 // tokens that are uppercase by convention. Only lowercase simple atomic types (#34602).
2217 $proptype = GETPOST('proptype', 'alpha');
2218 if (strpos($proptype, ':') === false && strpos($proptype, '_') === false) {
2219 $proptype = dol_strtolower($proptype);
2220 }
2221 $addfieldentry = array(
2222 'name' => GETPOST('propname', 'aZ09'),
2223 'label' => GETPOST('proplabel', 'alpha'),
2224 'type' => $proptype,
2225 'arrayofkeyval' => GETPOST('proparrayofkeyval', 'nohtml'), // Example json string '{"0":"Draft","1":"Active","-1":"Cancel"}'
2226 'visible' => GETPOST('propvisible', 'alphanohtml'),
2227 'enabled' => GETPOST('propenabled', 'alphanohtml'),
2228 'position' => GETPOSTINT('propposition'),
2229 'notnull' => GETPOSTINT('propnotnull'),
2230 'index' => GETPOSTINT('propindex'),
2231 'foreignkey' => GETPOST('propforeignkey', 'alpha'),
2232 'searchall' => GETPOSTINT('propsearchall'),
2233 'isameasure' => GETPOSTINT('propisameasure'),
2234 'showoncombobox' => GETPOSTINT('propshowoncombobox'),
2235 'comment' => GETPOST('propcomment', 'alpha'),
2236 'help' => GETPOST('prophelp', 'alpha'),
2237 'css' => GETPOST('propcss', 'alpha'), // Can be 'maxwidth500 widthcentpercentminusxx' for example
2238 'cssview' => GETPOST('propcssview', 'alpha'),
2239 'csslist' => GETPOST('propcsslist', 'alpha'),
2240 'default' => GETPOST('propdefault', 'restricthtml'),
2241 'noteditable' => GETPOSTINT('propnoteditable'),
2242 //'alwayseditable' => GETPOSTINT('propalwayseditable'),
2243 'validate' => GETPOSTINT('propvalidate')
2244 );
2245
2246 if (!empty($addfieldentry['arrayofkeyval']) && !is_array($addfieldentry['arrayofkeyval'])) {
2247 $tmpdecode = json_decode($addfieldentry['arrayofkeyval'], true);
2248 if ($tmpdecode) { // If string is already a json
2249 $addfieldentry['arrayofkeyval'] = $tmpdecode;
2250 } else { // If string is a list of lines with "key,value"
2251 $tmparray = dolExplodeIntoArray($addfieldentry['arrayofkeyval'], "\n", ",");
2252 $addfieldentry['arrayofkeyval'] = $tmparray;
2253 }
2254 }
2255 }
2256 }
2257
2258 /*if (GETPOST('regeneratemissing'))
2259 {
2260 setEventMessages($langs->trans("FeatureNotYetAvailable"), null, 'warnings');
2261 $error++;
2262 }*/
2263
2264 $moduletype = $listofmodules[dol_strtolower($module)]['moduletype'];
2265
2266 $object = null;
2267 // Edit the class file to write properties
2268 if (!$error) {
2269 $object = rebuildObjectClass($destdir, $module, $objectname, $newmask, $srcdir, $addfieldentry, $moduletype);
2270
2271 if (is_numeric($object) && $object <= 0) {
2272 $pathoffiletoeditsrc = $destdir.'/class/'.dol_strtolower($objectname).'.class.php';
2273 $langs->load("errors");
2274 setEventMessages($langs->trans('ErrorFailToCreateFile', $pathoffiletoeditsrc), null, 'errors');
2275 $error++;
2276 }
2277 }
2278
2279 // Edit sql with new properties
2280 if (!$error && $object !== null) {
2281 $result = rebuildObjectSql($destdir, $module, $objectname, $newmask, $srcdir, $object, $moduletype);
2282
2283 if ($result <= 0) {
2284 $langs->load("errors");
2285 setEventMessages($langs->trans('ErrorFailToCreateFile', '.sql'), null, 'errors');
2286 $error++;
2287 }
2288 }
2289
2290 if (!$error) {
2291 clearstatcache(true);
2292
2293 setEventMessages($langs->trans('FilesForObjectUpdated', $objectname), null);
2294
2295 setEventMessages($langs->trans('WarningDatabaseIsNotUpdated'), null);
2296
2297 // Make a redirect to reload all data
2298 header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=objects&module='.$module.($forceddirread ? '@'.$dirread : '').'&tabobj='.$objectname.'&nocache='.dol_now());
2299 exit;
2300 }
2301}
2302
2303if ($dirins && $action == 'confirm_deleteproperty' && $propertykey /* && $user->hasRight("modulebuilder", "run") // already checked */) {
2304 $objectname = $tabobj;
2305
2306 $dirins = $dirread = $listofmodules[dol_strtolower($module)]['moduledescriptorrootpath'];
2307 $moduletype = $listofmodules[dol_strtolower($module)]['moduletype'];
2308
2309 $srcdir = $dirread.'/'.dol_strtolower($module);
2310 $destdir = $dirins.'/'.dol_strtolower($module);
2311 dol_mkdir($destdir);
2312
2313 $object = null;
2314 // Edit the class file to write properties
2315 if (!$error) {
2316 $object = rebuildObjectClass($destdir, $module, $objectname, $newmask, $srcdir, array(), $propertykey);
2317
2318 if (is_numeric($object) && $object <= 0) {
2319 $pathoffiletoeditsrc = $destdir.'/class/'.dol_strtolower($objectname).'.class.php';
2320 $langs->load("errors");
2321 setEventMessages($langs->trans('ErrorFailToCreateFile', $pathoffiletoeditsrc), null, 'errors');
2322 $error++;
2323 }
2324 }
2325
2326 // Edit sql with new properties
2327 if (!$error && $object !== null) {
2328 $result = rebuildObjectSql($destdir, $module, $objectname, $newmask, $srcdir, $object);
2329
2330 if ($result <= 0) {
2331 $langs->load("errors");
2332 setEventMessages($langs->trans('ErrorFailToCreateFile', '.sql'), null, 'errors');
2333 $error++;
2334 }
2335 }
2336
2337 if (!$error) {
2338 setEventMessages($langs->trans('FilesForObjectUpdated', $objectname), null);
2339
2340 clearstatcache(true);
2341
2342 // Make a redirect to reload all data
2343 header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=objects&module='.$module.($forceddirread ? '@'.$dirread : '').'&tabobj='.$objectname);
2344 exit;
2345 }
2346}
2347
2348if ($dirins && $action == 'confirm_deletemodule' /* && $user->hasRight("modulebuilder", "run") // already checked */) {
2349 if (preg_match('/[^a-z0-9_]/i', $module)) {
2350 $error++;
2351 setEventMessages($langs->trans("SpaceOrSpecialCharAreNotAllowed"), null, 'errors');
2352 }
2353
2354 if (!$error) {
2355 $modulelowercase = dol_strtolower($module);
2356
2357 // Dir for module
2358 $dir = $dirins.'/'.$modulelowercase;
2359
2360 $pathtofile = $listofmodules[dol_strtolower($module)]['moduledescriptorrelpath'];
2361
2362 // Dir for module
2363 $dir = dol_buildpath($modulelowercase, 0);
2364
2365 // Zip file to build
2366 $FILENAMEZIP = '';
2367
2368 // Load module
2369 dol_include_once($pathtofile);
2370 $class = 'mod'.$module;
2371
2372 $moduleobj = null;
2373
2374 if (class_exists($class)) {
2375 try {
2376 $moduleobj = new $class($db);
2377 '@phan-var-force DolibarrModules $moduleobj';
2379 } catch (Exception $e) {
2380 $error++;
2381 dol_print_error($db, $e->getMessage());
2382 }
2383 } else {
2384 $error++;
2385 $langs->load("errors");
2386 setEventMessages($langs->trans("ErrorFailedToLoadModuleDescriptorForXXX", $module), null, 'warnings');
2387 }
2388
2389 if ($moduleobj) {
2390 $moduleobj->remove();
2391 }
2392
2393 $result = dol_delete_dir_recursive($dir);
2394
2395 if ($result > 0) {
2396 setEventMessages($langs->trans("DirWasRemoved", $modulelowercase), null);
2397
2398 clearstatcache(true);
2399 if (function_exists('opcache_invalidate')) {
2400 opcache_reset(); // remove the include cache hell !
2401 }
2402
2403 header("Location: ".$_SERVER["PHP_SELF"].'?module=deletemodule');
2404 exit;
2405 } else {
2406 setEventMessages($langs->trans("PurgeNothingToDelete"), null, 'warnings');
2407 }
2408 }
2409
2410 $action = '';
2411 $module = 'deletemodule';
2412}
2413
2414if ($dirins && $action == 'confirm_deleteobject' && $objectname /* && $user->hasRight("modulebuilder", "run") // already checked */) {
2415 if (preg_match('/[^a-z0-9_]/i', $objectname)) {
2416 $error++;
2417 setEventMessages($langs->trans("SpaceOrSpecialCharAreNotAllowed"), null, 'errors');
2418 }
2419
2420 if (!$error) {
2421 $modulelowercase = dol_strtolower($module);
2422 $objectlowercase = dol_strtolower($objectname);
2423
2424 // Dir for module
2425 $dir = $dirins.'/'.$modulelowercase;
2426
2427 // Delete some files
2428 try {
2429 $ncObjDel = new NamingContract($module, $objectname);
2430 } catch (\InvalidArgumentException $e) {
2431 $error++;
2432 setEventMessages($langs->trans("SpaceOrSpecialCharAreNotAllowed"), null, 'errors');
2433 $ncObjDel = null;
2434 }
2435 $filetodelete = [];
2436 if (!$error && $ncObjDel !== null) {
2437 foreach ([
2438 'myobject_card.php',
2439 'myobject_note.php',
2440 'myobject_contact.php',
2441 'myobject_document.php',
2442 'myobject_agenda.php',
2443 'myobject_list.php',
2444 'admin/myobject_extrafields.php',
2445 'lib/mymodule_myobject.lib.php',
2446 'sql/llx_mymodule_myobject.sql',
2447 'sql/llx_mymodule_myobject_extrafields.sql',
2448 'sql/llx_mymodule_myobject.key.sql',
2449 'sql/llx_mymodule_myobject_extrafields.key.sql',
2450 'scripts/myobject.php',
2451 'class/myobject.class.php',
2452 'class/myobjectstats.class.php',
2453 'core/modules/mymodule/mod_myobject_advanced.php',
2454 'core/modules/mymodule/mod_myobject_standard.php',
2455 'core/modules/mymodule/modules_myobject.php',
2456 'core/modules/mymodule/doc/doc_generic_myobject_odt.modules.php',
2457 'core/modules/mymodule/doc/pdf_standard_myobject.modules.php',
2458 'stats/myobject_index.php',
2459 ] as $templateFile) {
2460 $filetodelete[$templateFile] = $ncObjDel->applyToFilename($templateFile);
2461 }
2462 // Exceptions: target filenames differ from simple token substitution
2463 $filetodelete['ajax/myobject.lib.php'] = 'ajax/' . $ncObjDel->objectNameLower . '.php';
2464 $filetodelete['test/phpunit/MyObjectTest.php'] = 'test/phpunit/' . $ncObjDel->objectNameLower . 'Test.php';
2465 $filetodelete['class/api_myobject.class.php'] = 'class/api_' . $ncObjDel->moduleNameLower . '.class.php';
2466 }
2467
2468 //menu for the object selected
2469 // load class and check if menu,permission,documentation exist for this object
2470 $pathtofile = $listofmodules[dol_strtolower($module)]['moduledescriptorrelpath'];
2471 dol_include_once($pathtofile);
2472 $class = 'mod'.$module;
2473 $moduleobj = null;
2474 if (class_exists($class)) {
2475 try {
2476 $moduleobj = new $class($db);
2477 '@phan-var-force DolibarrModules $moduleobj';
2479 } catch (Exception $e) {
2480 $error++;
2481 dol_print_error($db, $e->getMessage());
2482 }
2483 } else {
2484 $error++;
2485 $langs->load("errors");
2486 dol_print_error($db, $langs->trans("ErrorFailedToLoadModuleDescriptorForXXX", $module));
2487 exit;
2488 }
2489 $moduledescriptorfile = $dirins.'/'.dol_strtolower($module).'/core/modules/mod'.$module.'.class.php';
2490
2491 // delete menus linked to the object
2492 $menus = $moduleobj->menu;
2493 $rewriteMenu = checkExistComment($moduledescriptorfile, 0);
2494
2495 if ($rewriteMenu < 0) {
2496 $langs->load("errors");
2497 setEventMessages($langs->trans("WarningCommentNotFound", $langs->trans("Menus"), "mod".$module."class.php"), null, 'warnings');
2498 } else {
2499 reWriteAllMenus($moduledescriptorfile, $menus, $objectname, null, -1);
2500 }
2501
2502 // regenerate permissions and delete them
2503 $permissions = $moduleobj->rights;
2504 $rewritePerms = checkExistComment($moduledescriptorfile, 1);
2505 if ($rewritePerms < 0) {
2506 $langs->load("errors");
2507 setEventMessages($langs->trans("WarningCommentNotFound", $langs->trans("Permissions"), "mod".$module."class.php"), null, 'warnings');
2508 } else {
2509 $reportPerms = modulebuilderSyncRights(RightsSyncCommand::forObjectDeletion($module, $moduledescriptorfile, is_array($permissions) ? $permissions : array(), $objectname));
2510 // A rights conflict deliberately does not cancel the object deletion below: the warning
2511 // already told the user the leftover rights need a manual cleanup.
2512 }
2513 if ($rewritePerms && $rewriteMenu) {
2514 // check if documentation has been generated
2515 $file_doc = $dirins.'/'.dol_strtolower($module).'/doc/Documentation.asciidoc';
2516 deletePropsAndPermsFromDoc($file_doc, $objectname);
2517
2518 clearstatcache(true);
2519 if (function_exists('opcache_invalidate')) {
2520 opcache_reset(); // remove the include cache hell !
2521 }
2522 $resultko = 0;
2523 foreach ($filetodelete as $tmpfiletodelete) {
2524 $resulttmp = dol_delete_file($dir.'/'.$tmpfiletodelete, 1, 0, 1);
2525 $resulttmp = dol_delete_file($dir.'/'.$tmpfiletodelete.'.back', 1, 0, 1);
2526 if (!$resulttmp) {
2527 $resultko++;
2528 }
2529 }
2530
2531 if ($resultko == 0) {
2532 setEventMessages($langs->trans("FilesDeleted"), null);
2533 } else {
2534 setEventMessages($langs->trans("ErrorSomeFilesCouldNotBeDeleted"), null, 'warnings');
2535 }
2536 }
2537 }
2538
2539 $action = '';
2540 if (! $error) {
2541 $tabobj = 'newobject';
2542 } else {
2543 $tabobj = 'deleteobject';
2544 }
2545
2546 // check if module is enabled
2548 $result = unActivateModule(dol_strtolower($module));
2549 dolibarr_set_const($db, "MAIN_IHM_PARAMS_REV", getDolGlobalInt('MAIN_IHM_PARAMS_REV') + 1, 'chaine', 0, '', $conf->entity);
2550 if ($result) {
2551 setEventMessages($result, null, 'errors');
2552 }
2553 $langs->load("errors");
2554 setEventMessages($langs->trans('WarningModuleNeedRefresh', $langs->transnoentities($module)), null, 'warnings');
2555 header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=objects&tabobj=deleteobject&module='.urlencode($module));
2556 exit;
2557 }
2558}
2559
2560if (($dirins && $action == 'confirm_deletedictionary' && $dicname) || ($dirins && $action == 'confirm_deletedictionary' && GETPOST('dictionnarykey')) /* && $user->hasRight("modulebuilder", "run") // already checked */) {
2561 $pathtofile = $listofmodules[dol_strtolower($module)]['moduledescriptorrelpath'];
2562 $destdir = $dirins.'/'.dol_strtolower($module);
2563 $moduledescriptorfile = $dirins.'/'.dol_strtolower($module).'/core/modules/mod'.$module.'.class.php';
2564
2565 if (preg_match('/[^a-z0-9_]/i', $dicname)) {
2566 $error++;
2567 setEventMessages($langs->trans("SpaceOrSpecialCharAreNotAllowed"), null, 'errors');
2568 }
2569
2570 if (!empty($dicname)) {
2571 $newdicname = $dicname;
2572 if (!preg_match('/^c_/', $newdicname)) {
2573 $newdicname = 'c_'.dol_strtolower($dicname);
2574 }
2575 } else {
2576 $newdicname = null;
2577 }
2578
2579 dol_include_once($pathtofile);
2580 $class = 'mod'.$module;
2581
2582 $moduleobj = null;
2583 if (class_exists($class)) {
2584 try {
2585 $moduleobj = new $class($db);
2586 '@phan-var-force DolibarrModules $moduleobj';
2588 } catch (Exception $e) {
2589 $error++;
2590 dol_print_error($db, $e->getMessage());
2591 }
2592 } else {
2593 $error++;
2594 }
2595 if ($moduleobj === null) {
2596 $langs->load("errors");
2597 dol_print_error($db, $langs->trans("ErrorFailedToLoadModuleDescriptorForXXX", $module));
2598 exit;
2599 }
2600
2601 $dicts = $moduleobj->dictionaries;
2602 $checkComment = checkExistComment($moduledescriptorfile, 2);
2603 if ($checkComment < 0) {
2604 $error++;
2605 $langs->load("errors");
2606 setEventMessages($langs->trans("WarningCommentNotFound", $langs->trans("Dictionaries"), "mod".$module."class.php"), null, 'warnings');
2607 }
2608
2609 if (!empty(GETPOST('dictionnarykey'))) {
2610 $newdicname = $dicts['tabname'][GETPOSTINT('dictionnarykey') - 1];
2611 }
2612
2613 // Lookup the table dicname
2614 $checkTable = false;
2615 if ($newdicname !== null) {
2616 $checkTable = $db->DDLDescTable(MAIN_DB_PREFIX.dol_strtolower($newdicname));
2617 }
2618
2619 if (is_bool($checkTable) || $db->num_rows($checkTable) <= 0) { // @phpstan-ignore-line
2620 $error++;
2621 }
2622
2623 // search the key by name
2624 $keyToDelete = null;
2625 foreach ($dicts['tabname'] as $key => $table) {
2626 //var_dump($table." /////// ".$newdicname);exit;
2627 if (dol_strtolower($table) === $newdicname) {
2628 $keyToDelete = $key;
2629 break;
2630 }
2631 }
2632 // delete all dicname's key values from the dictionary
2633 if ($keyToDelete !== null) {
2634 $keysToDelete = ['tabname', 'tablib', 'tabsql', 'tabsqlsort', 'tabfield', 'tabfieldvalue', 'tabfieldinsert', 'tabrowid', 'tabcond', 'tabhelp'];
2635 foreach ($keysToDelete as $key) {
2636 unset($dicts[$key][$keyToDelete]);
2637 }
2638 } else {
2639 $error++;
2640 $langs->load("errors");
2641 setEventMessages($langs->trans("ErrorDictionaryNotFound", dol_ucfirst($dicname)), null, 'errors');
2642 }
2643 if (!$error && $newdicname !== null) {
2644 // delete table
2645 $_results = $db->DDLDropTable(MAIN_DB_PREFIX.dol_strtolower($newdicname));
2646 if ($_results < 0) {
2647 dol_print_error($db);
2648 $langs->load("errors");
2649 setEventMessages($langs->trans("ErrorTableNotFound", $newdicname), null, 'errors');
2650 }
2651 // rebuild file after update dictionaries
2652 $result = updateDictionaryInFile($module, $moduledescriptorfile, $dicts);
2653 if ($result > 0) {
2654 setEventMessages($langs->trans("DictionaryDeleted", dol_ucfirst(dol_substr($newdicname, 2))), null);
2655 }
2656 if (function_exists('opcache_invalidate')) {
2657 opcache_reset(); // remove the include cache hell !
2658 }
2659 clearstatcache(true);
2660 header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=dictionaries&module='.$module.($forceddirread ? '@'.$dirread : ''));
2661 exit;
2662 }
2663}
2664if ($dirins && $action == 'updatedictionary' && GETPOST('dictionnarykey') /* && $user->hasRight("modulebuilder", "run") // already checked */) {
2665 $keydict = GETPOSTINT('dictionnarykey') - 1 ;
2666
2667 $pathtofile = $listofmodules[dol_strtolower($module)]['moduledescriptorrelpath'];
2668 $destdir = $dirins.'/'.dol_strtolower($module);
2669 $moduledescriptorfile = $dirins.'/'.dol_strtolower($module).'/core/modules/mod'.$module.'.class.php';
2670 dol_include_once($pathtofile);
2671 $class = 'mod'.$module;
2672
2673 $moduleobj = null;
2674 if (class_exists($class)) {
2675 try {
2676 $moduleobj = new $class($db);
2677 '@phan-var-force DolibarrModules $moduleobj';
2679 } catch (Exception $e) {
2680 $error++;
2681 dol_print_error($db, $e->getMessage());
2682 }
2683 } else {
2684 $error++;
2685 }
2686 if ($moduleobj === null) {
2687 $langs->load("errors");
2688 dol_print_error($db, $langs->trans("ErrorFailedToLoadModuleDescriptorForXXX", $module));
2689 exit;
2690 }
2691
2692 $dicts = $moduleobj->dictionaries;
2693 if (!empty(GETPOST('tablib')) && GETPOST('tablib') !== $dicts['tablib'][$keydict]) {
2694 $dicts['tablib'][$keydict] = dol_ucfirst(dol_strtolower(GETPOST('tablib')));
2695 $checkComment = checkExistComment($moduledescriptorfile, 2);
2696 if ($checkComment < 0) {
2697 $langs->load("errors");
2698 setEventMessages($langs->trans("WarningCommentNotFound", $langs->trans("Dictionaries"), "mod".$module."class.php"), null, 'warnings');
2699 } else {
2700 $updateDict = updateDictionaryInFile($module, $moduledescriptorfile, $dicts);
2701 if ($updateDict > 0) {
2702 setEventMessages($langs->trans("DictionaryNameUpdated", dol_ucfirst(GETPOST('tablib'))), null);
2703 }
2704 if (function_exists('opcache_invalidate')) {
2705 opcache_reset(); // remove the include cache hell !
2706 }
2707 clearstatcache(true);
2708 header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=dictionaries&module='.$module.($forceddirread ? '@'.$dirread : ''));
2709 exit;
2710 }
2711 }
2712 //var_dump(GETPOST('tablib'));exit;
2713}
2714if ($dirins && $action == 'generatedoc' /* && $user->hasRight("modulebuilder", "run") // already checked */) {
2715 $modulelowercase = dol_strtolower($module);
2716
2717 // Dir for module
2718 $dirofmodule = dol_buildpath($modulelowercase, 0).'/doc';
2719
2720 $FILENAMEDOC = dol_strtolower($module).'.html';
2721
2722 $util = new Utils($db);
2723 $result = $util->generateDoc($module);
2724
2725 if ($result > 0) {
2726 setEventMessages($langs->trans("DocFileGeneratedInto", $dirofmodule), null);
2727 } else {
2728 setEventMessages($util->error, $util->errors, 'errors');
2729 }
2730}
2731
2732if ($dirins && $action == 'generatepackage' /* && $user->hasRight("modulebuilder", "run") // already checked */) {
2733 $modulelowercase = dol_strtolower($module);
2734
2735 $pathtofile = $listofmodules[dol_strtolower($module)]['moduledescriptorrelpath'];
2736
2737 // Dir for module
2738 $dir = dol_buildpath($modulelowercase, 0);
2739
2740 // Zip file to build
2741 $FILENAMEZIP = '';
2742
2743 // Load module
2744 dol_include_once($pathtofile);
2745 $class = 'mod'.$module;
2746
2747 $moduleobj = null;
2748 if (class_exists($class)) {
2749 try {
2750 $moduleobj = new $class($db);
2751 '@phan-var-force DolibarrModules $moduleobj';
2753 } catch (Exception $e) {
2754 $error++;
2755 dol_print_error($db, $e->getMessage());
2756 }
2757 } else {
2758 $error++;
2759 }
2760 if ($moduleobj === null) {
2761 $langs->load("errors");
2762 dol_print_error($db, $langs->trans("ErrorFailedToLoadModuleDescriptorForXXX", $module));
2763 exit;
2764 }
2765
2766 $arrayversion = explode('.', $moduleobj->version, 3);
2767 if (count($arrayversion)) {
2768 $FILENAMEZIP = "module_".$modulelowercase.'-'.$arrayversion[0].(empty($arrayversion[1]) ? '.0' : '.'.$arrayversion[1]).(empty($arrayversion[2]) ? '' : '.'.$arrayversion[2]).'.zip';
2769
2770 $dirofmodule = dol_buildpath($modulelowercase, 0).'/bin';
2771 $outputfilezip = $dirofmodule.'/'.$FILENAMEZIP;
2772
2773 if (!dol_is_dir($dirofmodule)) {
2774 dol_mkdir($dirofmodule);
2775 }
2776 // Note: We exclude /bin/ to not include the already generated zip
2777 $result = dol_compress_dir($dir, $outputfilezip, 'zip', '/\/bin\/|\.git|\.old|\.back|\.ssh/', $modulelowercase);
2778
2779 if ($result > 0) {
2780 setEventMessages($langs->trans("ZipFileGeneratedInto", $outputfilezip), null);
2781 } else {
2782 $error++;
2783 $langs->load("errors");
2784 setEventMessages($langs->trans("ErrorFailToGenerateFile", $outputfilezip), null, 'errors');
2785 }
2786 } else {
2787 $error++;
2788 $langs->load("errors");
2789 setEventMessages($langs->trans("ErrorCheckVersionIsDefined"), null, 'errors');
2790 }
2791}
2792
2793// Add permission
2794if ($dirins && $action == 'addright' && !empty($module) && empty($cancel) /* && $user->hasRight("modulebuilder", "run") // already checked */) {
2795 $error = 0;
2796
2797 // load class and check if right exist
2798 $pathtofile = $listofmodules[dol_strtolower($module)]['moduledescriptorrelpath'];
2799 dol_include_once($pathtofile);
2800 $class = 'mod'.$module;
2801 $moduleobj = null;
2802 if (class_exists($class)) {
2803 try {
2804 $moduleobj = new $class($db);
2805 '@phan-var-force DolibarrModules $moduleobj';
2807 } catch (Exception $e) {
2808 $error++;
2809 dol_print_error($db, $e->getMessage());
2810 }
2811 }
2812
2813 // verify information entered
2814 if (!GETPOST('label', 'alpha')) {
2815 $error++;
2816 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Label")), null, 'errors');
2817 }
2818 if (!GETPOST('permissionObj', 'alpha')) {
2819 $error++;
2820 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Rights")), null, 'errors');
2821 }
2822
2823 $label = GETPOST('label', 'alpha');
2824 $objectForPerms = dol_strtolower(GETPOST('permissionObj', 'alpha'));
2825 $crud = GETPOST('crud', 'alpha');
2826
2827 //check existing object permission
2828 $counter = 0;
2829 $permsForObject = array();
2830 if (is_object($moduleobj)) {
2831 $permissions = $moduleobj->rights;
2832 } else {
2833 $permissions = array();
2834 }
2835 $allObject = array();
2836
2837 $countPerms = count($permissions);
2838
2839 for ($i = 0; $i < $countPerms; $i++) {
2840 if ($permissions[$i][4] == $objectForPerms) {
2841 $counter++;
2842 if (count($permsForObject) < 3) {
2843 $permsForObject[] = $permissions[$i];
2844 }
2845 }
2846 $allObject[] = $permissions[$i][4];
2847 }
2848
2849 // check if label of object already exists
2850 $countPermsObj = count($permsForObject);
2851 for ($j = 0; $j < $countPermsObj; $j++) {
2852 if (in_array($crud, $permsForObject[$j])) {
2853 $error++;
2854 $langs->load("errors");
2855 setEventMessages($langs->trans("ErrorExistingPermission", $langs->transnoentities($crud), $langs->transnoentities($objectForPerms)), null, 'errors');
2856 }
2857 }
2858
2859 if (!$error) {
2861 $result = unActivateModule(dol_strtolower($module));
2862 dolibarr_set_const($db, "MAIN_IHM_PARAMS_REV", getDolGlobalInt('MAIN_IHM_PARAMS_REV') + 1, 'chaine', 0, '', $conf->entity);
2863 if ($result) {
2864 setEventMessages($result, null, 'errors');
2865 }
2866 $langs->load("errors");
2867 setEventMessages($langs->trans('WarningModuleNeedRefresh', $langs->transnoentities($module)), null, 'warnings');
2868 }
2869
2870 $moduledescriptorfile = $dirins.'/'.dol_strtolower($module).'/core/modules/mod'.$module.'.class.php';
2871 // Rewriting all permissions section in the descriptor file
2872 $rewrite = checkExistComment($moduledescriptorfile, 1);
2873 if ($rewrite < 0) {
2874 $langs->load("errors");
2875 setEventMessages($langs->trans("WarningCommentNotFound", $langs->trans("Permissions"), "mod".$module."class.php"), null, 'warnings');
2876 } else {
2877 $reportPerms = modulebuilderSyncRights(RightsSyncCommand::forRightAddition($module, $moduledescriptorfile, $permissions, $objectForPerms, $label, $crud));
2878 if (!$reportPerms->hasConflicts()) {
2879 setEventMessages($langs->trans('PermissionAddedSuccesfuly'), null);
2880
2881 clearstatcache(true);
2882 if (function_exists('opcache_invalidate')) {
2883 opcache_reset(); // remove the include cache hell !
2884 }
2885 header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=permissions&module='.$module);
2886 exit;
2887 }
2888 }
2889 }
2890}
2891
2892
2893// Update permission
2894if ($dirins && GETPOST('action') == 'update_right' && GETPOST('modifyright') && empty($cancel) /* && $user->hasRight("modulebuilder", "run") // already checked */) {
2895 $error = 0;
2896 // load class and check if right exist
2897 $pathtofile = $listofmodules[dol_strtolower($module)]['moduledescriptorrelpath'];
2898 dol_include_once($pathtofile);
2899 $class = 'mod'.$module;
2900 $moduleobj = null;
2901 if (class_exists($class)) {
2902 try {
2903 $moduleobj = new $class($db);
2904 '@phan-var-force DolibarrModules $moduleobj';
2906 } catch (Exception $e) {
2907 $error++;
2908 dol_print_error($db, $e->getMessage());
2909 }
2910 }
2911 // verify information entered
2912 if (!GETPOST('label', 'alpha')) {
2913 $error++;
2914 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Label")), null, 'errors');
2915 }
2916 if (!GETPOST('permissionObj', 'alpha')) {
2917 $error++;
2918 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Rights")), null, 'errors');
2919 }
2920
2921 $label = GETPOST('label', 'alpha');
2922 $objectForPerms = dol_strtolower(GETPOST('permissionObj', 'alpha'));
2923 $crud = GETPOST('crud', 'alpha');
2924
2925
2926 if ($label == "Read objects of $module" && $crud != "read") {
2927 $crud = "read";
2928 // $label = "Read objects of $module";
2929 }
2930 if ($label == "Create/Update objects of $module" && $crud != "write") {
2931 $crud = "write";
2932 // $label = "Create/Update objects of $module";
2933 }
2934 if ($label == "Delete objects of $module" && $crud != "delete") {
2935 $crud = "delete";
2936 // $label = "Delete objects of $module";
2937 }
2938
2939 if (is_object($moduleobj)) {
2940 $permissions = $moduleobj->rights;
2941 } else {
2942 $permissions = [];
2943 }
2944 $key = GETPOSTINT('counter') - 1;
2945 //get permission want to delete from permissions array
2946 if (array_key_exists($key, $permissions)) {
2947 $x1 = $permissions[$key][1];
2948 $x2 = $permissions[$key][4];
2949 $x3 = $permissions[$key][5];
2950 } else {
2951 $x1 = null;
2952 $x2 = null;
2953 $x3 = null;
2954 }
2955 //check existing object permission
2956 $counter = 0;
2957 $permsForObject = array();
2958 // $permissions = $moduleobj->rights; // Already fetched above
2959 $firstRight = 0;
2960 $existRight = 0;
2961 $allObject = array();
2962
2963 $countPerms = count($permissions);
2964 for ($i = 0; $i < $countPerms; $i++) {
2965 if ($permissions[$i][4] == $objectForPerms) {
2966 $counter++;
2967 if (count($permsForObject) < 3) {
2968 $permsForObject[] = $permissions[$i];
2969 }
2970 }
2971 $allObject[] = $permissions[$i][4];
2972 }
2973
2974 if ($label != $x1 && $crud != $x3) {
2975 $countPermsObj = count($permsForObject);
2976 for ($j = 0; $j < $countPermsObj; $j++) {
2977 if (in_array($label, $permsForObject[$j])) {
2978 $error++;
2979 $langs->load("errors");
2980 setEventMessages($langs->trans("ErrorExistingPermission", $langs->transnoentities($label), $langs->transnoentities($objectForPerms)), null, 'errors');
2981 }
2982 }
2983 }
2984
2985 if (!$error) {
2987 $result = unActivateModule(dol_strtolower($module));
2988 dolibarr_set_const($db, "MAIN_IHM_PARAMS_REV", getDolGlobalInt('MAIN_IHM_PARAMS_REV') + 1, 'chaine', 0, '', $conf->entity);
2989 if ($result) {
2990 setEventMessages($result, null, 'errors');
2991 }
2992 $langs->load("errors");
2993 setEventMessages($langs->trans('WarningModuleNeedRefresh', $langs->transnoentities($module)), null, 'warnings');
2994 }
2995
2996 $moduledescriptorfile = $dirins.'/'.dol_strtolower($module).'/core/modules/mod'.$module.'.class.php';
2997 // rewriting all permissions after update permission needed
2998 $rewrite = checkExistComment($moduledescriptorfile, 1);
2999 if ($rewrite < 0) {
3000 $langs->load("errors");
3001 setEventMessages($langs->trans("WarningCommentNotFound", $langs->trans("Permissions"), "mod".$module."class.php"), null, 'warnings');
3002 } else {
3003 $reportPerms = modulebuilderSyncRights(RightsSyncCommand::forRightUpdate($module, $moduledescriptorfile, $permissions, $key, $objectForPerms, $label, $crud));
3004 if (!$reportPerms->hasConflicts()) {
3005 setEventMessages($langs->trans('PermissionUpdatedSuccesfuly'), null);
3006 clearstatcache(true);
3007 if (function_exists('opcache_invalidate')) {
3008 opcache_reset(); // remove the include cache hell !
3009 }
3010 header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=permissions&module='.$module);
3011 exit;
3012 }
3013 }
3014 }
3015}
3016// Delete permission
3017if ($dirins && $action == 'confirm_deleteright' && !empty($module) && GETPOSTINT('permskey') /* && $user->hasRight("modulebuilder", "run") // already checked */) {
3018 $error = 0;
3019 // load class and check if right exist
3020 $pathtofile = $listofmodules[dol_strtolower($module)]['moduledescriptorrelpath'];
3021 dol_include_once($pathtofile);
3022 $class = 'mod'.$module;
3023 $moduleobj = null;
3024 if (class_exists($class)) {
3025 try {
3026 $moduleobj = new $class($db);
3027 '@phan-var-force DolibarrModules $moduleobj';
3029 } catch (Exception $e) {
3030 $error++;
3031 dol_print_error($db, $e->getMessage());
3032 }
3033 }
3034
3035 $permissions = $moduleobj->rights;
3036 $key = GETPOSTINT('permskey') - 1;
3037
3038 if (!$error) {
3039 // check if module is enabled
3041 $result = unActivateModule(dol_strtolower($module));
3042 dolibarr_set_const($db, "MAIN_IHM_PARAMS_REV", getDolGlobalInt('MAIN_IHM_PARAMS_REV') + 1, 'chaine', 0, '', $conf->entity);
3043 if ($result) {
3044 setEventMessages($result, null, 'errors');
3045 }
3046 $langs->load("errors");
3047 setEventMessages($langs->trans('WarningModuleNeedRefresh', $langs->transnoentities($module)), null, 'warnings');
3048 header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=permissions&module='.$module);
3049 exit;
3050 }
3051
3052 // rewriting all permissions
3053 $moduledescriptorfile = $dirins.'/'.dol_strtolower($module).'/core/modules/mod'.$module.'.class.php';
3054 $rewrite = checkExistComment($moduledescriptorfile, 1);
3055 if ($rewrite < 0) {
3056 $langs->load("errors");
3057 setEventMessages($langs->trans("WarningCommentNotFound", $langs->trans("Permissions"), "mod".$module."class.php"), null, 'warnings');
3058 } else {
3059 $reportPerms = modulebuilderSyncRights(RightsSyncCommand::forRightDeletion($module, $moduledescriptorfile, $permissions, $key));
3060 if (!$reportPerms->hasConflicts()) {
3061 setEventMessages($langs->trans('PermissionDeletedSuccesfuly'), null);
3062
3063 clearstatcache(true);
3064 if (function_exists('opcache_invalidate')) {
3065 opcache_reset(); // remove the include cache hell !
3066 }
3067
3068 header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=permissions&module='.$module);
3069 exit;
3070 }
3071 }
3072 }
3073}
3074// Save file
3075if ($action == 'savefile' && empty($cancel) /* && $user->hasRight("modulebuilder", "run") // already checked */) {
3076 $relofcustom = basename($dirins);
3077
3078 if ($relofcustom) {
3079 // Check that relative path ($file) start with name 'custom'
3080 if (!preg_match('/^'.$relofcustom.'/', $file)) {
3081 $file = $relofcustom.'/'.$file;
3082 }
3083
3084 $pathoffile = dol_buildpath($file, 0);
3085 $pathoffilebackup = dol_buildpath($file.'.back', 0);
3086
3087 // Save old version
3088 if (dol_is_file($pathoffile)) {
3089 dol_copy($pathoffile, $pathoffilebackup, '0', 1);
3090 }
3091
3092 $check = 'restricthtml';
3093 $srclang = dol_mimetype($pathoffile, '', 3);
3094 if ($srclang == 'md') {
3095 $check = 'restricthtml';
3096 }
3097 if ($srclang == 'lang') {
3098 $check = 'restricthtml';
3099 }
3100 if ($srclang == 'php') {
3101 $check = 'none';
3102 }
3103
3104 $content = GETPOST('editfilecontent', $check);
3105
3106 // Save file on disk
3107 if ($content) {
3108 dol_delete_file($pathoffile);
3109 $result = file_put_contents($pathoffile, $content);
3110 if ($result) {
3111 dolChmod($pathoffile, $newmask);
3112
3113 setEventMessages($langs->trans("FileSaved"), null);
3114 } else {
3115 setEventMessages($langs->trans("ErrorFailedToSaveFile"), null, 'errors');
3116 }
3117 } else {
3118 setEventMessages($langs->trans("ContentCantBeEmpty"), null, 'errors');
3119 //$action='editfile';
3120 $error++;
3121 }
3122 }
3123}
3124
3125// Enable module
3126if ($action == 'set' && $user->admin /* && $user->hasRight("modulebuilder", "run") // already checked */) {
3127 $param = '';
3128 if ($module) {
3129 $param .= '&module='.urlencode($module);
3130 }
3131
3132 $param .= '&tab='.urlencode($tab);
3133 $param .= '&tabobj='.urlencode($tabobj);
3134
3135 $value = GETPOST('value', 'alpha');
3136 $resarray = activateModule($value, 1, 0);
3137 if (!empty($resarray['errors'])) {
3138 setEventMessages('', $resarray['errors'], 'errors');
3139 } else {
3140 //var_dump($resarray);exit;
3141 if ($resarray['nbperms'] > 0) {
3142 $tmpsql = "SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX."user WHERE admin <> 1";
3143 $resqltmp = $db->query($tmpsql);
3144 if ($resqltmp) {
3145 $obj = $db->fetch_object($resqltmp);
3146 //var_dump($obj->nb);exit;
3147 if ($obj && $obj->nb > 1) {
3148 $msg = $langs->trans('ModuleEnabledAdminMustCheckRights');
3149 setEventMessages($msg, null, 'warnings');
3150 }
3151 } else {
3152 dol_print_error($db);
3153 }
3154 }
3155 }
3156 header("Location: ".$_SERVER["PHP_SELF"]."?".$param);
3157 exit;
3158}
3159
3160// Disable module
3161if ($action == 'reset' && $user->admin /* && $user->hasRight("modulebuilder", "run") // already checked */) {
3162 $param = '';
3163 if ($module) {
3164 $param .= '&module='.urlencode($module);
3165 }
3166 $param .= '&tab='.urlencode($tab);
3167 $param .= '&tabobj='.urlencode($tabobj);
3168
3169 $value = GETPOST('value', 'alpha');
3170 $result = unActivateModule(dol_strtolower($value));
3171 if ($result) {
3172 setEventMessages($result, null, 'errors');
3173 }
3174 header("Location: ".$_SERVER["PHP_SELF"]."?".$param);
3175 exit;
3176}
3177
3178// Delete menu
3179if ($dirins && $action == 'confirm_deletemenu' && GETPOSTINT('menukey') /* && $user->hasRight("modulebuilder", "run") // already checked */) {
3180 // check if module is enabled
3182 $result = unActivateModule(dol_strtolower($module));
3183 dolibarr_set_const($db, "MAIN_IHM_PARAMS_REV", getDolGlobalInt('MAIN_IHM_PARAMS_REV') + 1, 'chaine', 0, '', $conf->entity);
3184 if ($result) {
3185 setEventMessages($result, null, 'errors');
3186 }
3187 $langs->load("errors");
3188 setEventMessages($langs->trans('WarningModuleNeedRefresh', $langs->transnoentities($module)), null, 'warnings');
3189 header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=menus&module='.$module);
3190 exit;
3191 }
3192 // load class and check if menu exist
3193 $pathtofile = $listofmodules[dol_strtolower($module)]['moduledescriptorrelpath'];
3194 dol_include_once($pathtofile);
3195 $class = 'mod'.$module;
3196 $moduleobj = null;
3197 if (class_exists($class)) {
3198 try {
3199 $moduleobj = new $class($db);
3200 '@phan-var-force DolibarrModules $moduleobj';
3202 } catch (Exception $e) {
3203 $error++;
3204 dol_print_error($db, $e->getMessage());
3205 }
3206 }
3207 // get all objects and convert value to lower case for compare
3208 $dir = $listofmodules[dol_strtolower($module)]['moduledescriptorrootpath'];
3209 $destdir = $dir.'/'.dol_strtolower($module);
3210 $objects = dolGetListOfObjectClasses($destdir);
3211 $result = array_map('dol_strtolower', $objects);
3212
3213 $menus = $moduleobj->menu;
3214 $key = GETPOSTINT('menukey');
3215 $moduledescriptorfile = $dirins.'/'.dol_strtolower($module).'/core/modules/mod'.$module.'.class.php';
3216
3217 $checkcomment = checkExistComment($moduledescriptorfile, 0);
3218 if ($checkcomment < 0) {
3219 $langs->load("errors");
3220 setEventMessages($langs->trans("WarningCommentNotFound", $langs->trans("Menus"), "mod".$module."class.php"), null, 'warnings');
3221 } else {
3222 if ($menus[$key]['fk_menu'] === 'fk_mainmenu='.dol_strtolower($module)) {
3223 if (in_array(dol_strtolower($menus[$key]['leftmenu']), $result)) {
3224 reWriteAllMenus($moduledescriptorfile, $menus, $menus[$key]['leftmenu'], $key, -1);
3225 } else {
3226 reWriteAllMenus($moduledescriptorfile, $menus, null, $key, 0);
3227 }
3228 } else {
3229 reWriteAllMenus($moduledescriptorfile, $menus, null, $key, 0);
3230 }
3231
3232 clearstatcache(true);
3233 if (function_exists('opcache_invalidate')) {
3234 opcache_reset(); // remove the include cache hell !
3235 }
3236
3237 setEventMessages($langs->trans('MenuDeletedSuccessfuly'), null);
3238 header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=menus&module='.$module);
3239 exit;
3240 }
3241}
3242
3243// Add menu in module without initial object
3244if ($dirins && $action == 'addmenu' && empty($cancel) /* && $user->hasRight("modulebuilder", "run") // already checked */) {
3245 // check if module is enabled
3247 $result = unActivateModule(dol_strtolower($module));
3248 dolibarr_set_const($db, "MAIN_IHM_PARAMS_REV", getDolGlobalInt('MAIN_IHM_PARAMS_REV') + 1, 'chaine', 0, '', $conf->entity);
3249 if ($result) {
3250 setEventMessages($result, null, 'errors');
3251 }
3252 $langs->load("errors");
3253 setEventMessages($langs->trans('WarningModuleNeedRefresh', $langs->transnoentities($module)), null, 'warnings');
3254 header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=menus&module='.$module);
3255 exit;
3256 }
3257 $error = 0;
3258
3259 // load class and check if right exist
3260 $pathtofile = $listofmodules[dol_strtolower($module)]['moduledescriptorrelpath'];
3261 dol_include_once($pathtofile);
3262 $class = 'mod'.$module;
3263 $moduleobj = null;
3264 if (class_exists($class)) {
3265 try {
3266 $moduleobj = new $class($db);
3267 '@phan-var-force DolibarrModules $moduleobj';
3269 } catch (Exception $e) {
3270 $error++;
3271 dol_print_error($db, $e->getMessage());
3272 }
3273 }
3274 // get all menus
3275 $menus = $moduleobj->menu;
3276
3277 //verify fields required
3278 if (!GETPOST('type', 'alpha')) {
3279 $error++;
3280 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Type")), null, 'errors');
3281 }
3282 if (!GETPOST('titre', 'alpha')) {
3283 $error++;
3284 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Title")), null, 'errors');
3285 }
3286 if (!GETPOST('user', 'alpha')) {
3287 $error++;
3288 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("DetailUser")), null, 'errors');
3289 }
3290 if (!GETPOST('url', 'alpha')) {
3291 $error++;
3292 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Url")), null, 'errors');
3293 }
3294 if (!empty(GETPOST('target'))) {
3295 $targets = array('_blank','_self','_parent','_top','');
3296 if (!in_array(GETPOST('target'), $targets)) {
3297 $error++;
3298 $langs->load("errors");
3299 setEventMessages($langs->trans("ErrorFieldValue", $langs->transnoentities("target")), null, 'errors');
3300 }
3301 }
3302
3303
3304 // check if title or url already exist in menus
3305
3306 foreach ($menus as $menu) {
3307 if (!empty(GETPOST('url')) && GETPOST('url') == $menu['url']) {
3308 $error++;
3309 $langs->load("errors");
3310 setEventMessages($langs->trans("ErrorFieldExist", $langs->transnoentities("url")), null, 'errors');
3311 break;
3312 }
3313 if (dol_strtolower(GETPOST('titre')) == dol_strtolower($menu['titre'])) {
3314 $error++;
3315 $langs->load("errors");
3316 setEventMessages($langs->trans("ErrorFieldExist", $langs->transnoentities("titre")), null, 'errors');
3317 break;
3318 }
3319 }
3320
3321 if (GETPOST('type', 'alpha') == 'left' && !empty(GETPOST('lefmenu', 'alpha'))) {
3322 if (!str_contains(GETPOST('leftmenu'), dol_strtolower($module))) {
3323 $error++;
3324 setEventMessages($langs->trans("WarningFieldsMustContains", $langs->transnoentities("LeftmenuId")), null, 'errors');
3325 }
3326 }
3327 $dirins = $listofmodules[dol_strtolower($module)]['moduledescriptorrootpath'];
3328 $destdir = $dirins.'/'.dol_strtolower($module);
3329 $objects = dolGetListOfObjectClasses($destdir);
3330
3331 if (GETPOST('type', 'alpha') == 'left') {
3332 if (empty(GETPOST('leftmenu')) && count($objects) > 0) {
3333 $error++;
3334 $langs->load("errors");
3335 setEventMessages($langs->trans("ErrorCoherenceMenu", $langs->transnoentities("LeftmenuId"), $langs->transnoentities("type")), null, 'errors');
3336 }
3337 }
3338 if (GETPOST('type', 'alpha') == 'top') {
3339 $error++;
3340 $langs->load("errors");
3341 setEventMessages($langs->trans("ErrorTypeMenu", $langs->transnoentities("type")), null, 'errors');
3342 }
3343
3344 $moduledescriptorfile = $dirins.'/'.dol_strtolower($module).'/core/modules/mod'.$module.'.class.php';
3345 if (!$error) {
3346 //stock forms in array
3347 $menuToAdd = array(
3348 'fk_menu' => GETPOST('fk_menu', 'alpha'),
3349 'type' => GETPOST('type', 'alpha'),
3350 'titre' => dol_ucfirst(GETPOST('titre', 'alpha')),
3351 'prefix' => '',
3352 'mainmenu' => GETPOST('mainmenu', 'alpha'),
3353 'leftmenu' => GETPOST('leftmenu', 'alpha'),
3354 'url' => GETPOST('url', 'alpha'),
3356 'position' => '',
3357 'enabled' => GETPOST('enabled', 'alpha'),
3358 'perms' => '$user->hasRight("'.dol_strtolower($module).'", "'.GETPOST('objects', 'alpha').'", "'.GETPOST('perms', 'alpha').'")',
3359 'target' => GETPOST('target', 'alpha'),
3360 'user' => GETPOSTINT('user'),
3361 );
3362
3363 if (GETPOST('type') == 'left') {
3364 unset($menuToAdd['prefix']);
3365 if (empty(GETPOST('fk_menu'))) {
3366 $menuToAdd['fk_menu'] = 'fk_mainmenu='.GETPOST('mainmenu', 'alpha');
3367 } else {
3368 $menuToAdd['fk_menu'] = 'fk_mainmenu='.GETPOST('mainmenu', 'alpha').',fk_leftmenu='.GETPOST('fk_menu');
3369 }
3370 }
3371 if (GETPOST('enabled') == '1') {
3372 $menuToAdd['enabled'] = 'isModEnabled("'.dol_strtolower($module).'")';
3373 } else {
3374 $menuToAdd['enabled'] = "0";
3375 }
3376 if (empty(GETPOST('objects'))) {
3377 $menuToAdd['perms'] = '1';
3378 }
3379
3380 $checkcomment = checkExistComment($moduledescriptorfile, 0);
3381 if ($checkcomment < 0) {
3382 $langs->load("errors");
3383 setEventMessages($langs->trans("WarningCommentNotFound", $langs->trans("Menus"), "mod".$module."class.php"), null, 'warnings');
3384 } else {
3385 // Write all menus
3386 $result = reWriteAllMenus($moduledescriptorfile, $menus, $menuToAdd, null, 1);
3387
3388 clearstatcache(true);
3389 if (function_exists('opcache_invalidate')) {
3390 opcache_reset();
3391 }
3392 /*if ($result < 0) {
3393 setEventMessages($langs->trans('ErrorMenuExistValue'), null, 'errors');
3394 header("Location: ".$_SERVER["PHP_SELF"].'?action=editmenu&token='.newToken().'&menukey='.urlencode($key+1).'&tab='.urlencode($tab).'&module='.urlencode($module).'&tabobj='.($key+1));
3395 exit;
3396 }*/
3397
3398 header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=menus&module='.$module);
3399 setEventMessages($langs->trans('MenuAddedSuccesfuly'), null);
3400 exit;
3401 }
3402 }
3403}
3404
3405// Modify a menu entry
3406if ($dirins && $action == "update_menu" && GETPOSTINT('menukey') && GETPOST('tabobj') /* && $user->hasRight("modulebuilder", "run") // already checked */) {
3407 $objectname = GETPOST('tabobj');
3408 $dirins = $listofmodules[dol_strtolower($module)]['moduledescriptorrootpath'];
3409 $destdir = $dirins.'/'.dol_strtolower($module);
3410 $objects = dolGetListOfObjectClasses($destdir);
3411
3412 if (empty($cancel)) {
3414 $result = unActivateModule(dol_strtolower($module));
3415 dolibarr_set_const($db, "MAIN_IHM_PARAMS_REV", getDolGlobalInt('MAIN_IHM_PARAMS_REV') + 1, 'chaine', 0, '', $conf->entity);
3416 if ($result) {
3417 setEventMessages($result, null, 'errors');
3418 }
3419 $langs->load("errors");
3420 setEventMessages($langs->trans('WarningModuleNeedRefresh', $langs->transnoentities($module)), null, 'warnings');
3421 header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=menus&module='.$module);
3422 exit;
3423 }
3424 $error = 0;
3425 // for loading class and the menu wants to modify
3426 $pathtofile = $listofmodules[dol_strtolower($module)]['moduledescriptorrelpath'];
3427 dol_include_once($pathtofile);
3428 $class = 'mod'.$module;
3429 $moduleobj = null;
3430 if (class_exists($class)) {
3431 try {
3432 $moduleobj = new $class($db);
3433 '@phan-var-force DolibarrModules $moduleobj';
3435 } catch (Exception $e) {
3436 $error++;
3437 dol_print_error($db, $e->getMessage());
3438 }
3439 }
3440 $menus = $moduleobj->menu;
3441 $key = GETPOSTINT('menukey') - 1;
3442
3443 $moduledescriptorfile = $dirins.'/'.dol_strtolower($module).'/core/modules/mod'.$module.'.class.php';
3444 //stock forms in array
3445 $menuModify = array(
3446 'fk_menu' => GETPOST('fk_menu', 'alpha'),
3447 'type' => GETPOST('type', 'alpha'),
3448 'titre' => dol_ucfirst(GETPOST('titre', 'alpha')),
3449 'prefix' => '',
3450 'mainmenu' => GETPOST('mainmenu', 'alpha'),
3451 'leftmenu' => $menus[$key]['leftmenu'],
3452 'url' => GETPOST('url', 'alpha'),
3454 'position' => '',
3455 'enabled' => GETPOST('enabled', 'alpha'),
3456 'perms' => GETPOST('perms', 'alpha'),
3457 'target' => GETPOST('target', 'alpha'),
3458 'user' => GETPOSTINT('user'),
3459 );
3460 if (!empty(GETPOST('fk_menu')) && GETPOST('fk_menu') != $menus[$key]['fk_menu']) {
3461 $menuModify['fk_menu'] = 'fk_mainmenu='.GETPOST('mainmenu').',fk_leftmenu='.GETPOST('fk_menu');
3462 } elseif (GETPOST('fk_menu') == $menus[$key]['fk_menu']) {
3463 $menuModify['fk_menu'] = $menus[$key]['fk_menu'];
3464 } else {
3465 $menuModify['fk_menu'] = 'fk_mainmenu='.GETPOST('mainmenu');
3466 }
3467 if ($menuModify['enabled'] === '') {
3468 $menuModify['enabled'] = '1';
3469 }
3470 if ($menuModify['perms'] === '') {
3471 $menuModify['perms'] = '1';
3472 }
3473
3474 if (GETPOST('type', 'alpha') == 'top') {
3475 $error++;
3476 $langs->load("errors");
3477 setEventMessages($langs->trans("ErrorTypeMenu", $langs->transnoentities("type")), null, 'errors');
3478 }
3479
3480 if (!$error) {
3481 //update menu
3482 $checkComment = checkExistComment($moduledescriptorfile, 0);
3483
3484 if ($checkComment < 0) {
3485 $langs->load("errors");
3486 setEventMessages($langs->trans("WarningCommentNotFound", $langs->trans("Menus"), "mod".$module."class.php"), null, 'warnings');
3487 } else {
3488 // Write all menus
3489 $result = reWriteAllMenus($moduledescriptorfile, $menus, $menuModify, $key, 2);
3490
3491 clearstatcache(true);
3492 if (function_exists('opcache_invalidate')) {
3493 opcache_reset();
3494 }
3495
3496 if ($result < 0) {
3497 $langs->load("errors");
3498 setEventMessages($langs->trans('ErrorMenuExistValue'), null, 'errors');
3499 //var_dump($_SESSION);exit;
3500 header("Location: ".$_SERVER["PHP_SELF"].'?action=editmenu&token='.newToken().'&menukey='.urlencode((string) ($key + 1)).'&tab='.urlencode((string) ($tab)).'&module='.urlencode((string) ($module)).'&tabobj='.($key + 1));
3501 exit;
3502 }
3503
3504 setEventMessages($langs->trans('MenuUpdatedSuccessfuly'), null);
3505 header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=menus&module='.$module);
3506 exit;
3507 }
3508 }
3509 } else {
3510 $_POST['type'] = ''; // TODO Use a var here and later
3511 $_POST['titre'] = '';
3512 $_POST['fk_menu'] = '';
3513 $_POST['leftmenu'] = '';
3514 $_POST['url'] = '';
3515 }
3516}
3517
3518// update properties description of module
3519if ($dirins && $action == "update_props_module" && !empty(GETPOST('keydescription', 'alpha')) && empty($cancel) /* && $user->hasRight("modulebuilder", "run") // already checked */) {
3521 $result = unActivateModule(dol_strtolower($module));
3522 dolibarr_set_const($db, "MAIN_IHM_PARAMS_REV", getDolGlobalInt('MAIN_IHM_PARAMS_REV') + 1, 'chaine', 0, '', $conf->entity);
3523 if ($result) {
3524 setEventMessages($result, null, 'errors');
3525 }
3526 $langs->load("errors");
3527 setEventMessages($langs->trans('WarningModuleNeedRefresh', $langs->transnoentities($module)), null, 'warnings');
3528 header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=menus&module='.$module);
3529 exit;
3530 }
3531 $pathtofile = $listofmodules[dol_strtolower($module)]['moduledescriptorrelpath'];
3532 $moduledescriptorfile = $dirins.'/'.dol_strtolower($module).'/core/modules/mod'.$module.'.class.php';
3533 $modulelogfile = $dirins.'/'.dol_strtolower($module).'/ChangeLog.md';
3534
3535 dol_include_once($pathtofile);
3536
3537 $class = 'mod'.$module;
3538 $moduleobj = null;
3539 if (class_exists($class)) {
3540 try {
3541 $moduleobj = new $class($db);
3542 '@phan-var-force DolibarrModules $moduleobj';
3544 } catch (Exception $e) {
3545 $error++;
3546 dol_print_error($db, $e->getMessage());
3547 }
3548 }
3549
3550 $keydescription = GETPOST('keydescription', 'alpha');
3551 switch ($keydescription) {
3552 case 'desc':
3553 $propertyToUpdate = 'description';
3554 break;
3555 case 'version':
3556 case 'family':
3557 case 'picto':
3558 case 'editor_name':
3559 case 'editor_url':
3560 $propertyToUpdate = $keydescription;
3561 break;
3562 default:
3563 $error = GETPOST('keydescription');
3564 break;
3565 }
3566
3567 if (isset($propertyToUpdate) && !empty(GETPOST('propsmodule'))) {
3568 $newValue = GETPOST('propsmodule');
3569 $patternToFindLine = '^\s*\$this->'.$propertyToUpdate.'\s*='; // Must be a regex string
3570 $newLine = "\t\t\$this->$propertyToUpdate = '$newValue';\n"; // Must a real string
3571
3572 $fileLines = file($moduledescriptorfile); // Get each line of file into an array
3573 $error = 0;
3574 $changedone = 0;
3575 foreach ($fileLines as &$line) {
3576 if (preg_match('/'.$patternToFindLine.'/', $line)) {
3577 $result = dolReplaceInFile($moduledescriptorfile, array($line => $newLine));
3578 if ($result > 0) {
3579 $changedone++;
3580 } elseif ($result <= -1) {
3581 $langs->load("errors");
3582 setEventMessages($langs->trans('ErrorFailToEditFile', $moduledescriptorfile), null, 'warnings');
3583 break;
3584 }
3585 break;
3586 }
3587 }
3588
3589 // To complete also the ChangeLogif we update the version
3590 if ($changedone && $propertyToUpdate === 'version') {
3591 dolReplaceInFile($modulelogfile, array("## ".$moduleobj->$propertyToUpdate => $newValue));
3592 }
3593
3594 clearstatcache(true);
3595 if (function_exists('opcache_invalidate')) {
3596 opcache_reset();
3597 }
3598 if ($changedone) {
3599 setEventMessages($langs->trans('PropertyModuleUpdated', $propertyToUpdate), null);
3600 } else {
3601 setEventMessages($langs->trans('NothingProcessed'), null, 'warnings');
3602 }
3603
3604 header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=description&module='.$module);
3605 exit;
3606 }
3607}
3608
3609
3610/*
3611 * View
3612 */
3613
3614$form = new Form($db);
3615$formadmin = new FormAdmin($db);
3616
3617// Set dir where external modules are installed
3618if (!dol_is_dir($dirins)) {
3619 dol_mkdir($dirins);
3620}
3621$dirins_ok = (dol_is_dir($dirins));
3622
3623$help_url = '';
3624$morejs = array(
3625 '/includes/ace/src/ace.js',
3626 '/includes/ace/src/ext-statusbar.js',
3627 '/includes/ace/src/ext-language_tools.js',
3628 //'/includes/ace/src/ext-chromevox.js'
3629);
3630$morecss = array();
3631
3632llxHeader('', $langs->trans("ModuleBuilder"), $help_url, '', 0, 0, $morejs, $morecss, '', 'classforhorizontalscrolloftabs');
3633
3634
3635$text = $langs->trans("ModuleBuilder");
3636
3637$morehtmlright = '<a href="'.DOL_URL_ROOT.'/admin/tools/ui/index.php" target="_blank" rel="noopener">'.img_picto('', 'book', 'class="pictofixedwidth"').$langs->trans("UxComponentsDoc").'</a>';
3638
3639print load_fiche_titre($text, $morehtmlright, 'title_setup');
3640
3641print '<div class="info hideonsmartphone">';
3642print $langs->trans("ModuleBuilderDesc", 'https://wiki.dolibarr.org/index.php/Module_development').'</span>';
3643print '</div>';
3644
3645
3646$message = '';
3647if (!$dirins) {
3648 $message = info_admin($langs->trans("ConfFileMustContainCustom", DOL_DOCUMENT_ROOT.'/custom', DOL_DOCUMENT_ROOT));
3649 $allowfromweb = -1;
3650} else {
3651 if ($dirins_ok) {
3652 if (!dol_is_writable($dirins)) {
3653 $langs->load("errors");
3654 $message = info_admin($langs->trans("ErrorFailedToWriteInDir", $dirins));
3655 $allowfromweb = 0;
3656 }
3657 } else {
3658 $message = info_admin($langs->trans("NotExistsDirect", $dirins).$langs->trans("InfDirAlt").$langs->trans("InfDirExample"));
3659 $allowfromweb = 0;
3660 }
3661}
3662if ($message) {
3663 print $message;
3664}
3665
3666//print $langs->trans("ModuleBuilderDesc3", count($listofmodules), $FILEFLAG).'<br>';
3667$infomodulesfound = '<div style="padding: 12px 9px 12px">'.$form->textwithpicto('', $langs->trans("ModuleBuilderDesc3", count($listofmodules)).'<br><br>'.$langs->trans("ModuleBuilderDesc4", $FILEFLAG).'<br>'.$textforlistofdirs).'</div>';
3668
3669
3670
3671$dolibarrdataroot = preg_replace('/([\\/]+)$/i', '', DOL_DATA_ROOT);
3672$allowonlineinstall = true;
3673if (dol_is_file($dolibarrdataroot.'/installmodules.lock')) {
3674 $allowonlineinstall = false;
3675}
3676if (empty($allowonlineinstall)) {
3677 if (getDolGlobalString('MAIN_MESSAGE_INSTALL_MODULES_DISABLED_CONTACT_US')) {
3678 // Show clean message
3679 $message = info_admin($langs->trans('InstallModuleFromWebHasBeenDisabledContactUs'));
3680 } else {
3681 // Show technical message
3682 $message = info_admin($langs->trans("InstallModuleFromWebHasBeenDisabledByFile", $dolibarrdataroot.'/installmodules.lock'), 0, 0, '1', 'warning');
3683 }
3684
3685 print $message;
3686
3687 llxFooter();
3688 exit(0);
3689}
3690
3691
3692// Load module descriptor
3693$error = 0;
3695
3696
3697if (!empty($module) && $module != 'initmodule' && $module != 'deletemodule') {
3698 $modulelowercase = dol_strtolower($module);
3699 $loadclasserrormessage = '';
3700
3701 $class = null;
3702 // Load module
3703 try {
3704 $fullpathdirtodescriptor = $listofmodules[dol_strtolower($module)]['moduledescriptorrelpath'];
3705
3706 //throw(new Exception());
3707 dol_include_once($fullpathdirtodescriptor);
3708
3709 $class = 'mod'.$module;
3710 } catch (Throwable $e) { // This is called in PHP 7 only (includes Error and Exception)
3711 $loadclasserrormessage = $e->getMessage()."<br>\n";
3712 $loadclasserrormessage .= 'File: '.$e->getFile()."<br>\n";
3713 $loadclasserrormessage .= 'Line: '.$e->getLine()."<br>\n";
3714 }
3715
3716 $moduleobj = null;
3717 if (class_exists($class)) {
3718 try {
3719 $moduleobj = new $class($db);
3720 '@phan-var-force DolibarrModules $moduleobj';
3722 } catch (Exception $e) {
3723 $error++;
3724 print $e->getMessage();
3725 }
3726 } else {
3727 if (empty($forceddirread)) {
3728 $error++;
3729 }
3730 $langs->load("errors");
3731 print '<!-- ErrorFailedToLoadModuleDescriptorForXXX -->';
3732 $langs->load("errors");
3733 print img_warning('').' '.$langs->trans("ErrorFailedToLoadModuleDescriptorForXXX", $module).'<br>';
3734 print $loadclasserrormessage;
3735 print '<br>';
3736 }
3737}
3738
3739
3740// Tabs for all modules
3741$head = array();
3742$h = 0;
3743
3744$head[$h][0] = $_SERVER["PHP_SELF"].'?module=initmodule';
3745$head[$h][1] = '<span class="valignmiddle text-plus-circle">'.$langs->trans("NewModule").'</span><span class="fa fa-plus-circle valignmiddle paddingleft"></span>';
3746$head[$h][2] = 'initmodule';
3747$h++;
3748
3749$linktoenabledisable = '';
3750
3751if (/* is_array($listofmodules) && */ count($listofmodules) > 0) {
3752 // Define $linktoenabledisable
3753 $modulelowercase = dol_strtolower($module);
3754
3755 $param = '';
3756 if ($module) {
3757 $param .= '&module='.urlencode($module);
3758 }
3759
3760 $param .= '&tab='.urlencode($tab);
3761 $param .= '&tabobj='.urlencode($tabobj);
3762
3763 $urltomodulesetup = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?search_keyword='.urlencode($module).'">'.$langs->trans('Home').'-'.$langs->trans("Setup").'-'.$langs->trans("Modules").'</a>';
3764
3765 // Define $linktoenabledisable to show after module title
3766 if (isModEnabled($modulelowercase)) { // If module is already activated
3767 $linktoenabledisable .= '<a class="reposition asetresetmodule valignmiddle" href="'.$_SERVER["PHP_SELF"].'?id='.$moduleobj->numero.'&action=reset&token='.newToken().'&value=mod'.$module.$param.'">';
3768 $linktoenabledisable .= img_picto($langs->trans("Warning").' : '.$langs->trans("ModuleIsLive"), 'switch_on', '', 0, 0, 0, '', 'warning valignmiddle', 1);
3769 $linktoenabledisable .= '</a>';
3770
3771 //$linktoenabledisable .= $form->textwithpicto('', $langs->trans("Warning").' : '.$langs->trans("ModuleIsLive"), -1, 'warning');
3772
3773 $objMod = $moduleobj;
3774 $backtourlparam = '';
3775 $backtourlparam .= ($backtourlparam ? '&' : '?').'module='.$module; // No urlencode here, done later
3776 $backtourlparam .= ($backtourlparam ? '&' : '?').'tab='.$tab; // No urlencode here, done later
3777 $backtourl = $_SERVER["PHP_SELF"].$backtourlparam;
3778
3779 $regs = array();
3780 if (is_array($objMod->config_page_url)) {
3781 $i = 0;
3782 foreach ($objMod->config_page_url as $page) {
3783 $urlpage = $page;
3784 if ($i++) {
3785 $linktoenabledisable .= ' <a class="valignmiddle" href="'.$urlpage.'" title="'.$langs->trans($page).'">'.img_picto(dol_ucfirst($page), "setup").'</a>';
3786 // print '<a href="'.$page.'">'.dol_ucfirst($page).'</a>&nbsp;';
3787 } else {
3788 if (preg_match('/^([^@]+)@([^@]+)$/i', $urlpage, $regs)) {
3789 $urltouse = dol_buildpath('/'.$regs[2].'/admin/'.$regs[1], 1);
3790 $linktoenabledisable .= ' <a class="valignmiddle" 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: 8px"', 0, 0, 0, '', '').'</a>';
3791 } else {
3792 // Case standard admin page (not a page provided by the
3793 // module but a page provided by dolibarr)
3794 $urltouse = DOL_URL_ROOT.'/admin/'.$urlpage;
3795 $linktoenabledisable .= ' <a class="valignmiddle" 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: 8px"', 0, 0, 0, '', '').'</a>';
3796 }
3797 }
3798 }
3799 } elseif (preg_match('/^([^@]+)@([^@]+)$/i', $objMod->config_page_url, $regs)) {
3800 $linktoenabledisable .= ' &nbsp; <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: 8px"', 0, 0, 0, '', '').'</a>';
3801 }
3802 } else {
3803 if (is_object($moduleobj)) {
3804 $linktoenabledisable .= '<a class="reposition asetresetmodule valignmiddle" href="'.$_SERVER["PHP_SELF"].'?id='.$moduleobj->numero.'&action=set&token='.newToken().'&value=mod'.$module.$param.'">';
3805 $linktoenabledisable .= img_picto($langs->trans("ModuleIsNotActive", $urltomodulesetup), 'switch_off', 'style="padding-right: 8px"', 0, 0, 0, '', 'classfortooltip valignmiddle', 1);
3806 $linktoenabledisable .= "</a>\n";
3807 }
3808 }
3809
3810 // Loop to show tab of each module
3811 foreach ($listofmodules as $tmpmodule => $tmpmodulearray) {
3812 $head[$h][0] = $_SERVER["PHP_SELF"].'?module='.$tmpmodulearray['modulenamewithcase'].($forceddirread ? '@'.$dirread : '');
3813 $head[$h][1] = $tmpmodulearray['modulenamewithcase'];
3814 $head[$h][2] = $tmpmodulearray['modulenamewithcase'];
3815
3816 if ($tmpmodulearray['modulenamewithcase'] == $module) {
3817 $head[$h][4] = '<span class="inline-block valignmiddle">'.$linktoenabledisable.'</span>';
3818 }
3819
3820 $h++;
3821 }
3822}
3823
3824$head[$h][0] = $_SERVER["PHP_SELF"].'?module=deletemodule';
3825$head[$h][1] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("DangerZone");
3826$head[$h][2] = 'deletemodule';
3827$h++;
3828
3829
3830print dol_get_fiche_head($head, $module, '', -1, '', 0, $infomodulesfound, '', 8); // Modules
3831
3832if ($module == 'initmodule') {
3833 // New module
3834 print '<!-- section init module -->'."\n";
3835 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
3836 print '<input type="hidden" name="token" value="'.newToken().'">';
3837 print '<input type="hidden" name="action" value="initmodule">';
3838 print '<input type="hidden" name="module" value="initmodule">';
3839
3840 //print '<span class="opacitymedium">'.$langs->trans("ModuleBuilderDesc2", 'conf/conf.php', $newdircustom).'</span><br>';
3841 print '<br>';
3842
3843 print '<div class="tagtable table-border">';
3844
3845 print '<div class="tagtr"><div class="tagtd paddingright">';
3846 print '<span class="opacitymedium">'.$langs->trans("IdModule").'</span>';
3847 print '</div><div class="tagtd">';
3848 print '<input type="number" min="100000" name="idmodule" class="width100" value="500000">';
3849 print '<span class="opacitymedium small">';
3850 print ' &nbsp; &nbsp; ';
3851 print dolButtonToOpenUrlInDialogPopup('popup_modules_id', $langs->transnoentitiesnoconv("SeeIDsInUse"), $langs->transnoentitiesnoconv("SeeIDsInUse"), '/admin/system/modules.php?mainmenu=home&leftmenu=admintools_info&hidetitle=1', '', '');
3852 print ' - ';
3853 print '<a href="https://wiki.dolibarr.org/index.php/List_of_modules_id" target="_blank" rel="noopener noreferrer external">'.$langs->trans("SeeReservedIDsRangeHere").'</a>';
3854 print '</span>';
3855 print '</div></div>';
3856
3857 print '<div class="tagtr"><div class="tagtd paddingright">';
3858 print '<span class="opacitymedium fieldrequired">'.$langs->trans("ModuleName").'</span>';
3859 print '</div><div class="tagtd">';
3860 print '<input type="text" name="modulename" value="'.dol_escape_htmltag($modulename).'" autofocus>';
3861 print ' '.$form->textwithpicto('', $langs->trans("EnterNameOfModuleDesc"));
3862 print '</div></div>';
3863
3864 print '<div class="tagtr"><div class="tagtd paddingright">';
3865 print '<span class="opacitymedium">'.$langs->trans("Description").'</span>';
3866 print '</div><div class="tagtd">';
3867 print '<input type="text" name="description" value="" class="minwidth500"><br>';
3868 print '</div></div>';
3869
3870 print '<div class="tagtr"><div class="tagtd paddingright">';
3871 print '<span class="opacitymedium">'.$langs->trans("Version").'</span>';
3872 print '</div><div class="tagtd">';
3873 print '<input type="text" name="version" class="width75" value="'.(GETPOSTISSET('version') ? GETPOST('version') : getDolGlobalString('MODULEBUILDER_SPECIFIC_VERSION', '1.0')).'" placeholder="'.dol_escape_htmltag($langs->trans("Version")).'">';
3874 print '</div></div>';
3875
3876 print '<div class="tagtr"><div class="tagtd paddingright">';
3877 print '<span class="opacitymedium">'.$langs->trans("Family").'</span>';
3878 print '</div><div class="tagtd">';
3879 print '<select name="family" id="family" class="minwidth400">';
3880 $arrayoffamilies = array(
3881 'hr' => "ModuleFamilyHr",
3882 'crm' => "ModuleFamilyCrm",
3883 'srm' => "ModuleFamilySrm",
3884 'financial' => 'ModuleFamilyFinancial',
3885 'products' => 'ModuleFamilyProducts',
3886 'projects' => 'ModuleFamilyProjects',
3887 'ecm' => 'ModuleFamilyECM',
3888 'technic' => 'ModuleFamilyTechnic',
3889 'portal' => 'ModuleFamilyPortal',
3890 'interface' => 'ModuleFamilyInterface',
3891 'base' => 'ModuleFamilyBase',
3892 'other' => 'ModuleFamilyOther'
3893 );
3894 foreach ($arrayoffamilies as $key => $value) {
3895 print '<option value="hr"'.($key == getDolGlobalString('MODULEBUILDER_SPECIFIC_FAMILY', 'other') ? ' selected="selected"' : '').' data-html="'.dol_escape_htmltag($langs->trans($value).' <span class="opacitymedium">- '.$key.'</span>').'">'.$langs->trans($value).'</option>';
3896 }
3897 print '</select>';
3898 print ajax_combobox("family");
3899 print '</div></div>';
3900
3901 print '<div class="tagtr"><div class="tagtd paddingright">';
3902 print '<span class="opacitymedium">'.$langs->trans("Picto").'</span>';
3903 print '</div><div class="tagtd">';
3904 print '<input type="text" name="idpicto" value="'.(GETPOSTISSET('idpicto') ? GETPOST('idpicto') : getDolGlobalString('MODULEBUILDER_DEFAULTPICTO', 'fa-file')).'" placeholder="'.dol_escape_htmltag($langs->trans("Picto")).'">';
3905 print $form->textwithpicto('', $langs->trans("Example").': fa-file, fa-globe, ... any font awesome code.<br>Advanced syntax is fa-fakey[_faprefix[_facolor[_fasize]]]');
3906
3907 print ' &nbsp; &nbsp; ';
3908
3909 print '<span class="opacitymedium small">';
3910 print dolButtonToOpenUrlInDialogPopup('popup_picto_id', $langs->transnoentitiesnoconv("DocIconsList"), $langs->transnoentitiesnoconv("DocIconsList"), '/admin/tools/ui/components/icons.php?hidenavmenu=1&displayMode=icon-only&mode=no-btn#img-picto-section-list', '', '');
3911 print '</span>';
3912
3913 print '</div></div>';
3914
3915 print '<div class="tagtr"><div class="tagtd paddingright">';
3916 print '<span class="opacitymedium">'.$langs->trans("EditorName").'</span>';
3917 print '</div><div class="tagtd">';
3918 print '<input type="text" name="editorname" value="'.(GETPOSTISSET('editorname') ? GETPOST('editorname') : getDolGlobalString('MODULEBUILDER_SPECIFIC_EDITOR_NAME', $mysoc->name)).'" placeholder="'.dol_escape_htmltag($langs->trans("EditorName")).'" spellcheck="false"><br>';
3919 print '</div></div>';
3920
3921 print '<div class="tagtr"><div class="tagtd paddingright">';
3922 print '<span class="opacitymedium">'.$langs->trans("EditorUrl").'</span>';
3923 print '</div><div class="tagtd">';
3924 print '<input type="text" name="editorurl" value="'.(GETPOSTISSET('editorurl') ? GETPOST('editorurl') : getDolGlobalString('MODULEBUILDER_SPECIFIC_EDITOR_URL', $mysoc->url)).'" placeholder="'.dol_escape_htmltag($langs->trans("EditorUrl")).'" spellcheck="false"><br>';
3925 print '</div></div>';
3926
3927 print '</div>'; // End div tagtable
3928
3929 print '<br><center>';
3930 print '<input type="submit" class="button" name="create" value="'.dol_escape_htmltag($langs->trans("Create")).'"'.($dirins ? '' : ' disabled="disabled"').'>';
3931 print '</center>';
3932 print '</form>';
3933} elseif ($module == 'deletemodule') {
3934 print '<!-- Form to init a module -->'."\n";
3935 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST" name="delete">';
3936 print '<input type="hidden" name="token" value="'.newToken().'">';
3937 print '<input type="hidden" name="action" value="confirm_deletemodule">';
3938 print '<input type="hidden" name="module" value="deletemodule">';
3939
3940 print $langs->trans("EnterNameOfModuleToDeleteDesc").'<br><br>';
3941
3942 print '<input type="text" name="module" placeholder="'.dol_escape_htmltag($langs->trans("ModuleKey")).'" value="" autofocus>';
3943 print '<input type="submit" class="button smallpaddingimp" value="'.$langs->trans("Delete").'"'.($dirins ? '' : ' disabled="disabled"').'>';
3944 print '</form>';
3945} elseif (!empty($module) && $modulelowercase !== null) {
3946 // Tabs for module
3947 if (!$error) {
3948 $dirread = $listofmodules[dol_strtolower($module)]['moduledescriptorrootpath'];
3949 $destdir = $dirread.'/'.dol_strtolower($module);
3950 $objects = dolGetListOfObjectClasses($destdir);
3951 $diroflang = dol_buildpath($modulelowercase, 0)."/langs";
3952 $countLangs = countItemsInDirectory($diroflang, 2);
3953 $countDictionaries = (!empty($moduleobj->dictionaries) ? count($moduleobj->dictionaries['tabname']) : 0);
3954 $countRights = count($moduleobj->rights);
3955 $countMenus = count($moduleobj->menu);
3956 $countTriggers = countItemsInDirectory(dol_buildpath($modulelowercase, 0)."/core/triggers");
3957 $countWidgets = countItemsInDirectory(dol_buildpath($modulelowercase, 0)."/core/boxes");
3958 $countEmailingSelectors = countItemsInDirectory(dol_buildpath($modulelowercase, 0)."/core/modules/mailings");
3959 $countCss = countItemsInDirectory(dol_buildpath($modulelowercase, 0)."/css");
3960 $countJs = countItemsInDirectory(dol_buildpath($modulelowercase, 0)."/js");
3961 $countCLI = countItemsInDirectory(dol_buildpath($modulelowercase, 0)."/scripts");
3962 $hasDoc = countItemsInDirectory(dol_buildpath($modulelowercase, 0)."/doc");
3963 //var_dump($moduleobj->dictionaries);exit;
3964 $head2 = array();
3965 $h = 0;
3966
3967 $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=description&module='.$module.($forceddirread ? '@'.$dirread : '');
3968 $head2[$h][1] = $langs->trans("Description");
3969 $head2[$h][2] = 'description';
3970 $h++;
3971
3972 $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=objects&module='.$module.($forceddirread ? '@'.$dirread : '');
3973 $head2[$h][1] = ((!is_array($objects) || count($objects) <= 0) ? $langs->trans("Objects") : $langs->trans("Objects").'<span class="marginleftonlyshort badge">'.count($objects)."</span>");
3974 $head2[$h][2] = 'objects';
3975 $h++;
3976
3977 $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=languages&module='.$module.($forceddirread ? '@'.$dirread : '');
3978 $head2[$h][1] = ($countLangs <= 0 ? $langs->trans("Languages") : $langs->trans("Languages").'<span class="marginleftonlyshort badge">'.$countLangs."</span>");
3979 $head2[$h][2] = 'languages';
3980 $h++;
3981
3982 $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=permissions&module='.$module.($forceddirread ? '@'.$dirread : '');
3983 $head2[$h][1] = ($countRights <= 0 ? $langs->trans("Permissions") : $langs->trans("Permissions").'<span class="marginleftonlyshort badge">'.$countRights."</span>");
3984 $head2[$h][2] = 'permissions';
3985 $h++;
3986
3987 $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=dictionaries&module='.$module.($forceddirread ? '@'.$dirread : '');
3988 $head2[$h][1] = ($countDictionaries == 0 ? $langs->trans("Dictionaries") : $langs->trans('Dictionaries').'<span class="marginleftonlyshort badge">'.$countDictionaries."</span>");
3989 $head2[$h][2] = 'dictionaries';
3990 $h++;
3991
3992 $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=tabs&module='.$module.($forceddirread ? '@'.$dirread : '');
3993 $head2[$h][1] = $langs->trans("Tabs");
3994 $head2[$h][2] = 'tabs';
3995 $h++;
3996
3997 $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=menus&module='.$module.($forceddirread ? '@'.$dirread : '');
3998 $head2[$h][1] = ($countMenus <= 0 ? $langs->trans("Menus") : $langs->trans("Menus").'<span class="marginleftonlyshort badge">'.$countMenus."</span>");
3999 $head2[$h][2] = 'menus';
4000 $h++;
4001
4002 $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=hooks&module='.$module.($forceddirread ? '@'.$dirread : '');
4003 $head2[$h][1] = $langs->trans("Hooks");
4004 $head2[$h][2] = 'hooks';
4005 $h++;
4006
4007 $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=triggers&module='.$module.($forceddirread ? '@'.$dirread : '');
4008 $head2[$h][1] = ($countTriggers <= 0 ? $langs->trans("Triggers") : $langs->trans("Triggers").'<span class="marginleftonlyshort badge">'.$countTriggers."</span>");
4009 $head2[$h][2] = 'triggers';
4010 $h++;
4011
4012 $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=widgets&module='.$module.($forceddirread ? '@'.$dirread : '');
4013 $head2[$h][1] = ($countWidgets <= 0 ? $langs->trans("Widgets") : $langs->trans("Widgets").'<span class="marginleftonlyshort badge">'.$countWidgets."</span>");
4014 $head2[$h][2] = 'widgets';
4015 $h++;
4016
4017 $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=emailings&module='.$module.($forceddirread ? '@'.$dirread : '');
4018 $head2[$h][1] = ($countEmailingSelectors <= 0 ? $langs->trans("EmailingSelectors") : $langs->trans("EmailingSelectors").'<span class="marginleftonlyshort badge">'.$countEmailingSelectors."</span>");
4019 $head2[$h][2] = 'emailings';
4020 $h++;
4021
4022 $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=exportimport&module='.$module.($forceddirread ? '@'.$dirread : '');
4023 $head2[$h][1] = $langs->trans("ImportExportProfiles");
4024 $head2[$h][2] = 'exportimport';
4025 $h++;
4026
4027 $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=css&module='.$module.($forceddirread ? '@'.$dirread : '');
4028 $head2[$h][1] = ($countCss <= 0 ? $langs->trans("CSS") : $langs->trans("CSS")." (".$countCss.")");
4029 $head2[$h][2] = 'css';
4030 $h++;
4031
4032 $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=js&module='.$module.($forceddirread ? '@'.$dirread : '');
4033 $head2[$h][1] = ($countJs <= 0 ? $langs->trans("JS") : $langs->trans("JS").'<span class="marginleftonlyshort badge">'.$countJs."</span>");
4034 $head2[$h][2] = 'js';
4035 $h++;
4036
4037 $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=cli&module='.$module.($forceddirread ? '@'.$dirread : '');
4038 $head2[$h][1] = ($countCLI <= 0 ? $langs->trans("CLI") : $langs->trans("CLI").'<span class="marginleftonlyshort badge">'.$countCLI."</span>");
4039 $head2[$h][2] = 'cli';
4040 $h++;
4041
4042 $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=cron&module='.$module.($forceddirread ? '@'.$dirread : '');
4043 $head2[$h][1] = $langs->trans("CronList");
4044 $head2[$h][2] = 'cron';
4045 $h++;
4046
4047 $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=specifications&module='.$module.($forceddirread ? '@'.$dirread : '');
4048 $head2[$h][1] = ($hasDoc <= 0 ? $langs->trans("Documentation") : $langs->trans("Documentation").'<span class="marginleftonlyshort badge">'.$hasDoc."</span>");
4049 $head2[$h][2] = 'specifications';
4050 $h++;
4051
4052 $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=buildpackage&module='.$module.($forceddirread ? '@'.$dirread : '');
4053 $head2[$h][1] = $langs->trans("BuildPackage");
4054 $head2[$h][2] = 'buildpackage';
4055 $h++;
4056
4057 $MAXTABFOROBJECT = 12;
4058
4059 print '<!-- Section for a given module -->';
4060
4061 // Note module is inside $dirread
4062
4063 if ($tab == 'description') {
4064 print '<!-- tab=description -->'."\n";
4065 $pathtofile = $listofmodules[dol_strtolower($module)]['moduledescriptorrelpath'];
4066 $pathtofilereadme = $modulelowercase.'/README.md';
4067 $pathtochangelog = $modulelowercase.'/ChangeLog.md';
4068 $pathtoindex = $modulelowercase.'/'.$modulelowercase.'index.php';
4069
4070 $realpathofmodule = realpath($dirread.'/'.$modulelowercase);
4071
4072 if ($action != 'editfile' || empty($file)) {
4073 $morehtmlright = '';
4074 if ($realpathofmodule != $dirread.'/'.$modulelowercase) {
4075 $morehtmlright = '<div style="padding: 12px 9px 12px">'.$form->textwithpicto('', '<span class="opacitymedium">'.$langs->trans("RealPathOfModule").' :</span> <strong class="wordbreak">'.$realpathofmodule.'</strong>').'</div>';
4076 }
4077
4078 print dol_get_fiche_head($head2, $tab, '', -1, '', 0, $morehtmlright, '', $MAXTABFOROBJECT, 'formodulesuffix'); // Description - level 2
4079
4080 print '<span class="opacitymedium">'.$langs->trans("ModuleBuilderDesc".$tab).'</span>';
4081 print '<br><br>';
4082
4083 print '<table>';
4084
4085 print '<tr><td>';
4086 print '<span class="fa fa-file"></span> '.$langs->trans("DescriptorFile").' : <strong class="wordbreak">'.$pathtofile.'</strong>';
4087 print '</td><td><a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&token='.newToken().'&format=php&file='.urlencode($pathtofile).'&find=DESCRIPTION_FLAG">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
4088 print '</td></tr>';
4089
4090 print '<tr><td><span class="fa fa-file"></span> '.$langs->trans("Index").' : <strong class="wordbreak">'.$pathtoindex.'</strong>';
4091 print '</td><td><a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&token='.newToken().'&format=php&file='.urlencode($pathtoindex).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
4092 print '</td></tr>';
4093
4094 // List of setup pages
4095 $listofsetuppages = dol_dir_list($realpathofmodule.'/admin', 'files', 0, '\.php$');
4096 foreach ($listofsetuppages as $setuppage) {
4097 // If this is a page for extrafields setup of an object
4098 $reg = array();
4099 if (preg_match('/^([a-z]+)_extrafields.php/', $setuppage['relativename'], $reg)) {
4100 // Check that object has $isextrafieldmanaged property set. If not, we should not show this file.
4101 $fileofclass = $realpathofmodule.'/class/'.$reg[1].'.class.php';
4102 if (is_readable($fileofclass) && !preg_match('/public\s+\$isextrafieldmanaged\s+=\s+1/', file_get_contents($fileofclass))) {
4103 continue;
4104 }
4105 }
4106
4107 //var_dump($setuppage);
4108 print '<tr><td>';
4109 print '<span class="fa fa-file"></span> ';
4110 if ($setuppage['relativename'] == 'about.php') {
4111 print $langs->trans("AboutFile");
4112 } else {
4113 print $langs->trans("SetupFile");
4114 }
4115 print ' : ';
4116 print '<strong class="wordbreak bold"><a href="'.dol_buildpath($modulelowercase.'/admin/'.$setuppage['relativename'], 1).'" target="_test">'.$modulelowercase.'/admin/'.$setuppage['relativename'].'</a></strong>';
4117 print '</td><td><a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&token='.newToken().'&format=php&file='.urlencode($modulelowercase.'/admin/'.$setuppage['relativename']).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
4118 print '</td></tr>';
4119 }
4120
4121 print '<tr><td><span class="fa fa-file"></span> '.$langs->trans("ReadmeFile").' : <strong class="wordbreak">'.$pathtofilereadme.'</strong>';
4122 print '</td><td><a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&token='.newToken().'&format=markdown&file='.urlencode($pathtofilereadme).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
4123 print '</td></tr>';
4124
4125 print '<tr><td><span class="fa fa-file"></span> '.$langs->trans("ChangeLog").' : <strong class="wordbreak">'.$pathtochangelog.'</strong>';
4126 print '</td><td><a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&token='.newToken().'&format=markdown&file='.urlencode($pathtochangelog).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
4127 print '</td></tr>';
4128
4129 print '</table>';
4130 print '<br>';
4131
4132 print load_fiche_titre($form->textwithpicto($langs->trans("DescriptorFile"), $langs->transnoentitiesnoconv("File").' '.$pathtofile), '', '');
4133
4134 if (is_object($moduleobj)) {
4135 print '<div class="underbanner clearboth"></div>';
4136 print '<div class="fichecenter">';
4137 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
4138 print '<input type="hidden" name="token" value="'.newToken().'">';
4139 print '<input type="hidden" name="action" value="update_props_module">';
4140 print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
4141 print '<input type="hidden" name="tab" value="'.dol_escape_htmltag($tab).'">';
4142 print '<input type="hidden" name="keydescription" value="'.dol_escape_htmltag(GETPOST('keydescription', 'alpha')).'">';
4143
4144 print '<div class="div-table-responsive-no-min">';
4145 print '<table class="border centpercent">';
4146 print '<tr class="liste_titre"><td class="titlefield">';
4147 print $langs->trans("Parameter");
4148 print '</td><td>';
4149 print $langs->trans("Value");
4150 print '</td></tr>';
4151
4152 print '<tr><td>';
4153 print $langs->trans("IdModule");
4154 print '</td><td>';
4155 print $moduleobj->numero;
4156 print '<span class="opacitymedium">';
4157 print ' &nbsp; (';
4158 print dolButtonToOpenUrlInDialogPopup('popup_modules_id', $langs->transnoentitiesnoconv("SeeIDsInUse"), $langs->transnoentitiesnoconv("SeeIDsInUse"), '/admin/system/modules.php?mainmenu=home&leftmenu=admintools_info', '', '');
4159 print ' - <a href="https://wiki.dolibarr.org/index.php/List_of_modules_id" target="_blank" rel="noopener noreferrer external">'.$langs->trans("SeeReservedIDsRangeHere").'</a>)';
4160 print '</span>';
4161 print '</td></tr>';
4162
4163 print '<tr><td>';
4164 print $langs->trans("ModuleName");
4165 print '</td><td>';
4166 print $moduleobj->getName();
4167 print '</td></tr>';
4168
4169 print '<tr><td>';
4170 print $langs->trans("Description");
4171 print '</td><td>';
4172 if ($action == 'edit_moduledescription' && GETPOST('keydescription', 'alpha') === 'desc') {
4173 print '<input class="minwidth500" name="propsmodule" value="'.dol_escape_htmltag($moduleobj->description).'" spellcheck="false">';
4174 print '<input class="reposition button smallpaddingimp" type="submit" name="modifydesc" value="'.$langs->trans("Modify").'"/>';
4175 print '<input class="reposition button button-cancel smallpaddingimp" type="submit" name="cancel" value="'.$langs->trans("Cancel").'"/>';
4176 } else {
4177 print $moduleobj->description;
4178 print '<a class="editfielda reposition marginleftonly marginrighttonly paddingright paddingleft" href="'.$_SERVER["PHP_SELF"].'?action=edit_moduledescription&token='.newToken().'&tab='.urlencode($tab).'&module='.urlencode($module).'&keydescription=desc">'.img_edit().'</a>';
4179
4180 $moduledescritpionautotrans = $moduleobj->getDesc();
4181 if ($moduledescritpionautotrans != "Module".$moduleobj->name."Desc") {
4182 // $moduledescritpionautotrans has been found into a translation file
4183 print ' '.$form->textwithpicto('', $langs->trans("ModuleTranslatedIntoLangForKeyInto", "Module".$moduleobj->name."Desc", $moduledescritpionautotrans));
4184 } elseif ($moduledescritpionautotrans != "Module".$moduleobj->numero."Desc") {
4185 // $moduledescritpionautotrans has been found into a translation file
4186 print ' '.$form->textwithpicto('', $langs->trans("ModuleTranslatedIntoLangForKeyInto", "Module".$moduleobj->numero."Desc", $moduledescritpionautotrans));
4187 }
4188 }
4189 print '</td></tr>';
4190
4191 print '<tr><td>';
4192 print $langs->trans("Version");
4193 print '</td><td>';
4194 if ($action == 'edit_moduledescription' && GETPOST('keydescription', 'alpha') === 'version') {
4195 print '<input name="propsmodule" value="'.dol_escape_htmltag($moduleobj->getVersion()).'">';
4196 print '<input class="reposition button smallpaddingimp" type="submit" name="modifyversion" value="'.$langs->trans("Modify").'"/>';
4197 print '<input class="reposition button button-cancel smallpaddingimp" type="submit" name="cancel" value="'.$langs->trans("Cancel").'"/>';
4198 } else {
4199 print $moduleobj->getVersion();
4200 print '<a class="editfielda reposition marginleftonly marginrighttonly paddingright paddingleft" href="'.$_SERVER["PHP_SELF"].'?action=edit_moduledescription&token='.newToken().'&tab='.urlencode($tab).'&module='.urlencode($module).'&keydescription=version">'.img_edit().'</a>';
4201 }
4202 print '</td></tr>';
4203
4204 print '<tr><td>';
4205 print $langs->trans("Family");
4206 //print "<br>'crm','financial','hr','projects','products','ecm','technic','interface','other'";
4207 print '</td><td>';
4208 if ($action == 'edit_moduledescription' && GETPOST('keydescription', 'alpha') === 'family') {
4209 print '<select name="propsmodule" id="family" class="minwidth400">';
4210 $arrayoffamilies = array(
4211 'hr' => "ModuleFamilyHr",
4212 'crm' => "ModuleFamilyCrm",
4213 'srm' => "ModuleFamilySrm",
4214 'financial' => 'ModuleFamilyFinancial',
4215 'products' => 'ModuleFamilyProducts',
4216 'projects' => 'ModuleFamilyProjects',
4217 'ecm' => 'ModuleFamilyECM',
4218 'technic' => 'ModuleFamilyTechnic',
4219 'portal' => 'ModuleFamilyPortal',
4220 'interface' => 'ModuleFamilyInterface',
4221 'base' => 'ModuleFamilyBase',
4222 'other' => 'ModuleFamilyOther'
4223 );
4224 print '<option value="'.$moduleobj->family.'" data-html="'.dol_escape_htmltag($langs->trans($arrayoffamilies[$moduleobj->family]).' <span class="opacitymedium">- '.$moduleobj->family.'</span>').'">'.$langs->trans($arrayoffamilies[$moduleobj->family]).'</option>';
4225 foreach ($arrayoffamilies as $key => $value) {
4226 if ($key != $moduleobj->family) {
4227 print '<option value="'.$key.'" data-html="'.dol_escape_htmltag($langs->trans($value).' <span class="opacitymedium">- '.$key.'</span>').'">'.$langs->trans($value).'</option>';
4228 }
4229 }
4230 print '</select>';
4231 print '<input class="reposition button smallpaddingimp" type="submit" name="modifyfamily" value="'.$langs->trans("Modify").'"/>';
4232 print '<input class="reposition button button-cancel smallpaddingimp" type="submit" name="cancel" value="'.$langs->trans("Cancel").'"/>';
4233 } else {
4234 print $moduleobj->family;
4235 print '<a class="editfielda reposition marginleftonly marginrighttonly paddingright paddingleft" href="'.$_SERVER["PHP_SELF"].'?action=edit_moduledescription&token='.newToken().'&tab='.urlencode($tab).'&module='.urlencode($module).'&keydescription=family">'.img_edit().'</a>';
4236 }
4237 print '</td></tr>';
4238
4239 print '<!-- picto of module -->'."\n";
4240 print '<tr><td>';
4241 print $langs->trans("Picto");
4242 print '</td><td>';
4243 if ($action == 'edit_modulepicto' && GETPOST('keydescription', 'alpha') === 'picto') {
4244 print '<input class="minwidth200 maxwidth500" name="propsmodule" value="'.dol_escape_htmltag($moduleobj->picto).'" spellcheck="false">';
4245
4246 print $form->textwithpicto('', $langs->trans("Example").': fa-file, fa-globe, ... any font awesome code.<br>Advanced syntax is fa-fakey[_faprefix[_facolor[_fasize]]] where faprefix can be far,far, facolor can be a text like \'red\' orvalue like \'#FF0000\' and fasize is CSS font size like \'1em\'');
4247
4248 print '<input class="reposition button smallpaddingimp" type="submit" name="modifypicto" value="'.$langs->trans("Modify").'"/>';
4249 print '<input class="reposition button button-cancel smallpaddingimp" type="submit" name="cancel" value="'.$langs->trans("Cancel").'"/>';
4250
4251 print ' &nbsp; &nbsp; ';
4252
4253 print '<span class="opacitymedium small">';
4254 print dolButtonToOpenUrlInDialogPopup('popup_picto_id', $langs->transnoentitiesnoconv("DocIconsList"), $langs->transnoentitiesnoconv("DocIconsList"), '/admin/tools/ui/components/icons.php?hidenavmenu=1&displayMode=icon-only&mode=no-btn#img-picto-section-list', '', '');
4255 print '</span>';
4256 } else {
4257 print $moduleobj->picto;
4258 print ' &nbsp; '.img_picto('', $moduleobj->picto, 'class="valignmiddle pictomodule paddingrightonly"');
4259 print '<a class="editfielda reposition marginleftonly marginrighttonly paddingright paddingleft" href="'.$_SERVER["PHP_SELF"].'?action=edit_modulepicto&token='.newToken().'&tab='.urlencode($tab).'&module='.urlencode($module).'&keydescription=picto">'.img_edit().'</a>';
4260 }
4261 print '</td></tr>';
4262
4263 print '<tr><td>';
4264 print $langs->trans("EditorName");
4265 print '</td><td>';
4266 if ($action == 'edit_moduledescription' && GETPOST('keydescription', 'alpha') === 'editor_name') {
4267 print '<input name="propsmodule" value="'.dol_escape_htmltag($moduleobj->editor_name).'" spellcheck="false">';
4268 print '<input class="reposition button smallpaddingimp" type="submit" name="modifyname" value="'.$langs->trans("Modify").'"/>';
4269 print '<input class="reposition button button-cancel smallpaddingimp" type="submit" name="cancel" value="'.$langs->trans("Cancel").'"/>';
4270 } else {
4271 print $moduleobj->editor_name;
4272 print '<a class="editfielda reposition marginleftonly marginrighttonly paddingright paddingleft" href="'.$_SERVER["PHP_SELF"].'?action=edit_moduledescription&token='.newToken().'&tab='.urlencode($tab).'&module='.urlencode($module).'&keydescription=editor_name">'.img_edit().'</a>';
4273 }
4274 print '</td></tr>';
4275
4276 print '<tr><td>';
4277 print $langs->trans("EditorUrl");
4278 print '</td><td>';
4279 if ($action == 'edit_moduledescription' && GETPOST('keydescription', 'alpha') === 'editor_url') {
4280 print '<input name="propsmodule" value="'.dol_escape_htmltag($moduleobj->editor_url).'" spellcheck="false">';
4281 print '<input class="reposition button smallpaddingimp" type="submit" name="modifyeditorurl" value="'.$langs->trans("Modify").'"/>';
4282 print '<input class="reposition button button-cancel smallpaddingimp" type="submit" name="cancel" value="'.$langs->trans("Cancel").'"/>';
4283 } else {
4284 if (!empty($moduleobj->editor_url)) {
4285 print '<a href="'.$moduleobj->editor_url.'" target="_blank" rel="noopener">'.$moduleobj->editor_url.' '.img_picto('', 'globe').'</a>';
4286 }
4287 print '<a class="editfielda reposition marginleftonly marginrighttonly paddingright paddingleft" href="'.$_SERVER["PHP_SELF"].'?action=edit_moduledescription&token='.newToken().'&tab='.urlencode($tab).'&module='.urlencode($module).'&keydescription=editor_url">'.img_edit().'</a>';
4288 }
4289 print '</td></tr>';
4290
4291 print '</table>';
4292 print '</div>';
4293 print '</form>';
4294 } else {
4295 $langs->load("errors");
4296 print $langs->trans("ErrorFailedToLoadModuleDescriptorForXXX", $module).'<br>';
4297 }
4298
4299 if (!empty($moduleobj)) {
4300 print '<br><br>';
4301
4302 // Readme file
4303 print load_fiche_titre($form->textwithpicto($langs->trans("ReadmeFile"), $langs->transnoentitiesnoconv("File").' '.$pathtofilereadme), '', '');
4304
4305 print '<!-- readme file -->';
4306 if (dol_is_file($dirread.'/'.$pathtofilereadme)) {
4307 print '<div class="underbanner clearboth"></div><div class="fichecenter">'.$moduleobj->getDescLong().'</div>';
4308 } else {
4309 $langs->load("errors");
4310 print '<span class="opacitymedium">'.$langs->trans("ErrorFileNotFound", $pathtofilereadme).'</span>';
4311 }
4312
4313 print '<br><br>';
4314
4315 // ChangeLog
4316 print load_fiche_titre($form->textwithpicto($langs->trans("ChangeLog"), $langs->transnoentitiesnoconv("File").' '.$pathtochangelog), '', '');
4317
4318 print '<!-- changelog file -->';
4319 if (dol_is_file($dirread.'/'.$pathtochangelog)) {
4320 print '<div class="underbanner clearboth"></div><div class="fichecenter">'.$moduleobj->getChangeLog().'</div>';
4321 } else {
4322 $langs->load("errors");
4323 print '<span class="opacitymedium">'.$langs->trans("ErrorFileNotFound", $pathtochangelog).'</span>';
4324 }
4325 }
4326
4327 print dol_get_fiche_end();
4328 } else { // Edit text file
4329 $fullpathoffile = dol_buildpath($file, 0, 1); // Description - level 2
4330
4331 $content = '';
4332 if ($fullpathoffile) {
4333 $content = file_get_contents($fullpathoffile);
4334 }
4335
4336 // New module
4337 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
4338 print '<input type="hidden" name="token" value="'.newToken().'">';
4339 print '<input type="hidden" name="action" value="savefile">';
4340 print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
4341 print '<input type="hidden" name="tab" value="'.$tab.'">';
4342 print '<input type="hidden" name="module" value="'.$module.'">';
4343
4344 print dol_get_fiche_head($head2, $tab, '', -1, '', 0, '', '', 0, 'formodulesuffix');
4345
4346 $posCursor = (empty($find)) ? array() : array('find' => $find);
4347 $doleditor = new DolEditor('editfilecontent', $content, '', 300, 'Full', 'In', true, false, 'ace', 0, '99%', 0, $posCursor);
4348 print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ? GETPOST('format', 'aZ09') : 'html'));
4349
4350 print dol_get_fiche_end();
4351
4352 print '<center>';
4353 print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
4354 print ' &nbsp; ';
4355 print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
4356 print '</center>';
4357
4358 print '</form>';
4359 }
4360 } else {
4361 print dol_get_fiche_head($head2, $tab, '', -1, '', 0, '', '', $MAXTABFOROBJECT, 'formodulesuffix'); // Level 2
4362 }
4363
4364 if ($tab == 'languages') {
4365 print '<!-- tab=languages -->'."\n";
4366 if ($action != 'editfile' || empty($file)) {
4367 print '<span class="opacitymedium">'.$langs->trans("LanguageDefDesc").'</span><br>';
4368 print '<br>';
4369
4370
4371 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
4372 print '<input type="hidden" name="token" value="'.newToken().'">';
4373 print '<input type="hidden" name="action" value="addlanguage">';
4374 print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
4375 print '<input type="hidden" name="tab" value="'.$tab.'">';
4376 print '<input type="hidden" name="module" value="'.$module.'">';
4377 print $formadmin->select_language(getDolGlobalString('MAIN_LANG_DEFAULT'), 'newlangcode', 0, array(), 1, 0, 0, 'minwidth300', 1);
4378 print '<input type="submit" name="addlanguage" class="button smallpaddingimp" value="'.dol_escape_htmltag($langs->trans("AddLanguageFile")).'"><br>';
4379 print '</form>';
4380
4381 print '<br>';
4382 print '<br>';
4383
4384 $modulelowercase = dol_strtolower($module);
4385
4386 // Dir for module
4387 $diroflang = dol_buildpath($modulelowercase, 0);
4388 $diroflang .= '/langs';
4389 $langfiles = dol_dir_list($diroflang, 'files', 1, '\.lang$');
4390
4391 if (!preg_match('/custom/', $dirread)) {
4392 // If this is not a module into custom
4393 $diroflang = $dirread;
4394 $diroflang .= '/langs';
4395 $langfiles = dol_dir_list($diroflang, 'files', 1, $modulelowercase.'\.lang$');
4396 }
4397
4398 print '<table class="none">';
4399 foreach ($langfiles as $langfile) {
4400 $pathtofile = $modulelowercase.'/langs/'.$langfile['relativename'];
4401 if (!preg_match('/custom/', $dirread)) { // If this is not a module into custom
4402 $pathtofile = 'langs/'.$langfile['relativename'];
4403 }
4404 print '<tr><td><span class="fa fa-file"></span> '.$langs->trans("LanguageFile").' '.basename(dirname($pathtofile)).' : <strong class="wordbreak">'.$pathtofile.'</strong>';
4405 print '</td><td><a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&token='.newToken().'&format=ini&file='.urlencode($pathtofile).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
4406 print '</td><td><a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=confirm_removefile&token='.newToken().'&file='.urlencode($pathtofile).'">'.img_picto($langs->trans("Delete"), 'delete').'</a>';
4407 print '</td>';
4408 }
4409 print '</table>';
4410 } else {
4411 // Edit text language file
4412
4413 //print $langs->trans("UseAsciiDocFormat").'<br>';
4414
4415 $fullpathoffile = dol_buildpath($file, 0);
4416
4417 $content = file_get_contents($fullpathoffile);
4418
4419 // New module
4420 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
4421 print '<input type="hidden" name="token" value="'.newToken().'">';
4422 print '<input type="hidden" name="action" value="savefile">';
4423 print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
4424 print '<input type="hidden" name="tab" value="'.$tab.'">';
4425 print '<input type="hidden" name="module" value="'.$module.'">';
4426
4427 $doleditor = new DolEditor('editfilecontent', $content, '', 300, 'Full', 'In', true, false, 'ace', 0, '99%');
4428 print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ? GETPOST('format', 'aZ09') : 'text'));
4429 print '<br>';
4430 print '<center>';
4431 print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
4432 print ' &nbsp; ';
4433 print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
4434 print '</center>';
4435
4436 print '</form>';
4437 }
4438 }
4439
4440 if ($tab == 'objects') {
4441 print '<!-- tab=objects -->'."\n";
4442 $head3 = array();
4443 $h = 0;
4444
4445 // Dir for module
4446 $dir = $dirread.'/'.$modulelowercase.'/class';
4447
4448 $head3[$h][0] = $_SERVER["PHP_SELF"].'?tab=objects&module='.$module.($forceddirread ? '@'.$dirread : '').'&tabobj=newobject';
4449 $head3[$h][1] = '<span class="valignmiddle text-plus-circle">'.$langs->trans("NewObjectInModulebuilder").'</span><span class="fa fa-plus-circle valignmiddle paddingleft"></span>';
4450 $head3[$h][2] = 'newobject';
4451 $h++;
4452
4453 // Scan for object class files
4454 $listofobject = dol_dir_list($dir, 'files', 0, '\.class\.php$');
4455
4456 $firstobjectname = '';
4457 foreach ($listofobject as $fileobj) {
4458 if (preg_match('/^api_/', $fileobj['name'])) {
4459 continue;
4460 }
4461 if (preg_match('/^actions_/', $fileobj['name'])) {
4462 continue;
4463 }
4464
4465 $tmpcontent = file_get_contents($fileobj['fullname']);
4466 if (preg_match('/class\s+([^\s]*)\s+extends\s+CommonObject/ims', $tmpcontent, $reg)) {
4467 //$objectname = preg_replace('/\.txt$/', '', $fileobj['name']);
4468 $objectname = $reg[1];
4469 if (empty($firstobjectname)) {
4470 $firstobjectname = $objectname;
4471 }
4472 $pictoname = 'generic';
4473 if (preg_match('/\$picto\s*=\s*["\']([^"\']+)["\']/', $tmpcontent, $reg)) {
4474 $pictoname = $reg[1];
4475 }
4476
4477 $head3[$h][0] = $_SERVER["PHP_SELF"].'?tab=objects&module='.$module.($forceddirread ? '@'.$dirread : '').'&tabobj='.$objectname;
4478 $head3[$h][1] = img_picto('', $pictoname, 'class="pictofixedwidth valignmiddle"').$objectname;
4479 $head3[$h][2] = $objectname;
4480 $h++;
4481 }
4482 }
4483
4484 if ($h > 1) {
4485 $head3[$h][0] = $_SERVER["PHP_SELF"].'?tab=objects&module='.$module.($forceddirread ? '@'.$dirread : '').'&tabobj=deleteobject';
4486 $head3[$h][1] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("DangerZone");
4487 $head3[$h][2] = 'deleteobject';
4488 $h++;
4489 }
4490
4491 // If tabobj was not defined, then we check if there is one obj. If yes, we force on it, if no, we will show tab to create new objects.
4492 if ($tabobj == 'newobjectifnoobj') {
4493 if ($firstobjectname) {
4494 $tabobj = $firstobjectname;
4495 } else {
4496 $tabobj = 'newobject';
4497 }
4498 }
4499
4500 print dol_get_fiche_head($head3, $tabobj, '', -1, '', 0, '', '', 0, 'forobjectsuffix'); // Level 3
4501
4502
4503 if ($tabobj == 'newobject') {
4504 // New object tab
4505 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
4506 print '<input type="hidden" name="token" value="'.newToken().'">';
4507 print '<input type="hidden" name="action" value="initobject">';
4508 print '<input type="hidden" name="tab" value="objects">';
4509 print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
4510
4511 // Tabs selected by default = all optional tabs; reflect posted state on redisplay
4512 $enabledtabsdefault = GETPOSTISSET('enabledtab') ? GETPOST('enabledtab', 'array') : array_keys(getModuleBuilderObjectTabs());
4513 // Not array_keys() here: an action shipped commented out in the template stays off by default
4514 $enabledcardactionsdefault = GETPOSTISSET('enabledcardaction') ? GETPOST('enabledcardaction', 'array') : getModuleBuilderDefaultEnabledKeys(getModuleBuilderObjectCardActions());
4515
4516 print '<span class="opacitymedium">'.$langs->trans("EnterNameOfObjectDesc").'</span><br><br>';
4517
4518 print '<div class="tagtable">';
4519
4520 print '<div class="tagtr"><div class="tagtd">';
4521 print '<span class="opacitymedium">'.$langs->trans("ObjectKey").'</span> &nbsp; ';
4522 print '</div><div class="tagtd">';
4523 print '<input type="text" name="objectname" maxlength="64" value="'.dol_escape_htmltag(GETPOSTISSET('objectname') ? GETPOST('objectname', 'alpha') : $modulename).'" required autofocus>';
4524 print $form->textwithpicto('', $langs->trans("Example").': MyObject, ACamelCaseName, ...');
4525 print '</div></div>';
4526
4527 print '<div class="tagtr"><div class="tagtd">';
4528 print '<span class="opacitymedium">'.$langs->trans("Picto").'</span> &nbsp; ';
4529 print '</div><div class="tagtd">';
4530 print '<input type="text" name="idpicto" value="fa-file" placeholder="'.dol_escape_htmltag($langs->trans("Picto")).'">';
4531
4532 print $form->textwithpicto('', $langs->trans("Example").': fa-file, fa-globe, ... any font awesome code.<br>Advanced syntax is fa-fakey[_faprefix[_facolor[_fasize]]] where faprefix can be far,far, facolor can be a text like \'red\' orvalue like \'#FF0000\' and fasize is CSS font size like \'1em\'');
4533
4534 print '<span class="opacitymedium small">';
4535 print ' &nbsp; &nbsp; ';
4536 print dolButtonToOpenUrlInDialogPopup('popup_picto_id', $langs->transnoentitiesnoconv("DocIconsList"), $langs->transnoentitiesnoconv("DocIconsList"), '/admin/tools/ui/components/icons.php?hidenavmenu=1&displayMode=icon-only&mode=no-btn#img-picto-section-list', '', '');
4537 print '</span>';
4538
4539 print '</div></div>';
4540
4541 print '<div class="tagtr"><div class="tagtd">';
4542 print '<span class="opacitymedium">'.$langs->trans("DefinePropertiesFromExistingTable").'</span> &nbsp; ';
4543 print '</div><div class="tagtd">';
4544 print '<input type="text" name="initfromtablename" value="'.GETPOST('initfromtablename').'" placeholder="'.$langs->trans("TableName").'">';
4545 print $form->textwithpicto('', $langs->trans("DefinePropertiesFromExistingTableDesc").'<br>'.$langs->trans("DefinePropertiesFromExistingTableDesc2"));
4546 print '</div></div>';
4547
4548 // Other lines of options (printed as div class="tagtr")
4549 $parameters = array('module' => $module, 'tabobj' => $tabobj);
4550 $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $hookobject, $action);
4551 if ($reshook < 0) {
4552 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
4553 }
4554 print $hookmanager->resPrint;
4555
4556 print '</div>';
4557
4558 print '<br>';
4559 print '<input type="checkbox" name="includerefgeneration" id="includerefgeneration" value="includerefgeneration"> <label class="margintoponly" for="includerefgeneration">'.$form->textwithpicto($langs->trans("IncludeRefGeneration"), $langs->trans("IncludeRefGenerationHelp")).'</label><br>';
4560 print '<input type="checkbox" name="includedocgeneration" id="includedocgeneration" value="includedocgeneration"> <label for="includedocgeneration">'.$form->textwithpicto($langs->trans("IncludeDocGeneration"), $langs->trans("IncludeDocGenerationHelp")).'</label><br>';
4561 print '<input type="checkbox" name="generatepermissions" id="generatepermissions" value="generatepermissions"> <label for="generatepermissions">'.$form->textwithpicto($langs->trans("GeneratePermissions"), $langs->trans("GeneratePermissionsHelp")).'</label><br>';
4562 print '<input type="checkbox" name="nogeneratelines" id="nogeneratelines" value="nogeneratelines"> <label for="nogeneratelines">'.$form->textwithpicto($langs->trans("NoGenerateLines"), $langs->trans("NoGenerateLinesHelp")).'</label><br>';
4563 print '<br><span class="opacitymedium">'.$form->textwithpicto($langs->trans("EnabledTabsForObject"), $langs->trans("EnabledTabsForObjectHelp")).'</span><br>';
4564 foreach (getModuleBuilderObjectTabs() as $tabkey => $tabinfo) {
4565 $checked = in_array($tabkey, $enabledtabsdefault, true) ? ' checked' : '';
4566 print '<input type="checkbox" name="enabledtab[]" id="enabledtab_'.$tabkey.'" value="'.dol_escape_htmltag($tabkey).'"'.$checked.'> ';
4567 print '<label for="enabledtab_'.$tabkey.'">'.dol_escape_htmltag($langs->trans($tabinfo['label'])).'</label> &nbsp; ';
4568 }
4569 print '<br>';
4570 print '<br><span class="opacitymedium">'.$form->textwithpicto($langs->trans("EnabledCardActionsForObject"), $langs->trans("EnabledCardActionsForObjectHelp")).'</span><br>';
4571 foreach (getModuleBuilderObjectCardActions() as $actionkey => $actioninfo) {
4572 $checked = in_array($actionkey, $enabledcardactionsdefault, true) ? ' checked' : '';
4573 print '<input type="checkbox" name="enabledcardaction[]" id="enabledcardaction_'.$actionkey.'" value="'.dol_escape_htmltag($actionkey).'"'.$checked.'> ';
4574 print '<label for="enabledcardaction_'.$actionkey.'">'.dol_escape_htmltag($langs->trans($actioninfo['label'])).'</label> &nbsp; ';
4575 }
4576 print '<br>';
4577 print '<br><span class="opacitymedium">'.$form->textwithpicto($langs->trans("AccessPolicyForObject"), $langs->trans("AccessPolicyForObjectHelp")).'</span><br>';
4578 for ($i = 0; $i < AccessPolicyConfig::MAX_ALTERNATIVES; $i++) {
4579 $accesspolicyselected = GETPOST('accesspolicy_'.$i, 'array:aZ09');
4580 print '<span class="opacitymedium">'.dol_escape_htmltag($langs->trans($i == 0 ? "AccessPolicyFirstAlternative" : "AccessPolicyOtherAlternative", $i + 1)).'</span> &nbsp; ';
4581 foreach (array_keys(PredicateRule::PREDICATES) as $predicatename) {
4582 $checked = in_array($predicatename, $accesspolicyselected, true) ? ' checked' : '';
4583 print '<span class="nowraponall"><input type="checkbox" name="accesspolicy_'.$i.'[]" id="accesspolicy_'.$i.'_'.$predicatename.'" value="'.dol_escape_htmltag($predicatename).'"'.$checked.'> ';
4584 print '<label for="accesspolicy_'.$i.'_'.$predicatename.'">'.dol_escape_htmltag($langs->trans("AccessPolicyPredicate".ucfirst($predicatename))).'</label></span> &nbsp; ';
4585 }
4586 print '<br>';
4587 }
4588 print '<span class="opacitymedium">'.$form->textwithpicto($langs->trans("AccessPolicyMessage"), $langs->trans("AccessPolicyMessageHelp")).'</span> &nbsp; ';
4589 print '<input type="text" name="accesspolicymessage" maxlength="'.AccessPolicyConfig::MAX_MESSAGE_LENGTH.'" value="'.dol_escape_htmltag(GETPOST('accesspolicymessage', 'alphanohtml')).'" placeholder="ErrorForbidden">';
4590 print '<br>';
4591 print '<br>';
4592 print '<input type="submit" class="button small" name="create" value="'.dol_escape_htmltag($langs->trans("GenerateCode")).'"'.($dirins ? '' : ' disabled="disabled"').'>';
4593 print '<br>';
4594 print '<br>';
4595 /*
4596 print '<br>';
4597 print '<span class="opacitymedium">'.$langs->trans("or").'</span>';
4598 print '<br>';
4599 print '<br>';
4600 //print '<input type="checkbox" name="initfromtablecheck"> ';
4601 print $langs->trans("InitStructureFromExistingTable");
4602 print '<input type="text" name="initfromtablename" value="" placeholder="'.$langs->trans("TableName").'">';
4603 print '<input type="submit" class="button smallpaddingimp" name="createtablearray" value="'.dol_escape_htmltag($langs->trans("GenerateCode")).'"'.($dirins ? '' : ' disabled="disabled"').'>';
4604 print '<br>';
4605 */
4606
4607 print '</form>';
4608 } elseif ($tabobj == 'createproperty') {
4609 $attributesUnique = array(
4610 'proplabel' => $form->textwithpicto($langs->trans("Label"), $langs->trans("YouCanUseTranslationKey")),
4611 'propname' => $form->textwithpicto($langs->trans("Code"), $langs->trans("PropertyDesc"), 1, 'help', 'extracss', 0, 3, 'propertyhelp'),
4612 'proptype' => $form->textwithpicto($langs->trans("Type"), $langs->trans("TypeOfFieldsHelpIntro").'<br><br>'.$langs->trans("TypeOfFieldsHelp"), 1, 'help', 'extracss', 0, 3, 'typehelp'),
4613 'proparrayofkeyval' => $form->textwithpicto($langs->trans("ArrayOfKeyValues"), $langs->trans("ArrayOfKeyValuesDesc")),
4614 'propnotnull' => $form->textwithpicto($langs->trans("NotNull"), $langs->trans("NotNullDesc")),
4615 'propdefault' => $langs->trans("DefaultValue"),
4616 'propindex' => $langs->trans("DatabaseIndex"),
4617 'propforeignkey' => $form->textwithpicto($langs->trans("ForeignKey"), $langs->trans("ForeignKeyDesc"), 1, 'help', 'extracss', 0, 3, 'foreignkeyhelp'),
4618 'propposition' => $langs->trans("Position"),
4619 'propenabled' => $form->textwithpicto($langs->trans("Enabled"), $langs->trans("EnabledDesc"), 1, 'help', 'extracss', 0, 3, 'enabledhelp'),
4620 'propvisible' => $form->textwithpicto($langs->trans("Visibility"), $langs->trans("VisibleDesc").'<br><br>'.$langs->trans("ItCanBeAnExpression"), 1, 'help', 'extracss', 0, 3, 'visiblehelp'),
4621 'propnoteditable' => $langs->trans("NotEditable"),
4622 //'propalwayseditable' => $langs->trans("AlwaysEditable"),
4623 'propsearchall' => $form->textwithpicto($langs->trans("SearchAll"), $langs->trans("SearchAllDesc")),
4624 'propisameasure' => $form->textwithpicto($langs->trans("IsAMeasure"), $langs->trans("IsAMeasureDesc")),
4625 'propcss' => $langs->trans("CSSClass"),
4626 'propcssview' => $langs->trans("CSSViewClass"),
4627 'propcsslist' => $langs->trans("CSSListClass"),
4628 'prophelp' => $langs->trans("KeyForTooltip"),
4629 'propshowoncombobox' => $langs->trans("ShowOnCombobox"),
4630 //'propvalidate' => $form->textwithpicto($langs->trans("Validate"), $langs->trans("ValidateModBuilderDesc")),
4631 'propcomment' => $langs->trans("Comment"),
4632 );
4633 print '<form action="'.$_SERVER["PHP_SELF"].'?tab=objects&module='.urlencode($module).'&tabobj=createproperty&obj='.urlencode(GETPOST('obj')).'" method="POST">';
4634 print '<input type="hidden" name="token" value="'.newToken().'">';
4635 print '<input type="hidden" name="action" value="addproperty">';
4636 print '<input type="hidden" name="tab" value="objects">';
4637 print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
4638 print '<input type="hidden" name="obj" value="'.dol_escape_htmltag(GETPOST('obj')).'">';
4639
4640 print '<table class="border centpercent tableforfieldcreate">'."\n";
4641 $counter = 0;
4642 foreach ($attributesUnique as $key => $attribute) {
4643 if ($counter % 2 === 0) {
4644 print '<tr>';
4645 }
4646 if ($key == 'propname' || $key == 'proplabel') {
4647 print '<td class="titlefieldcreate fieldrequired">'.$attribute.'</td><td class="valuefieldcreate maxwidth50"><input class="maxwidth200" id="'.$key.'" type="text" name="'.$key.'" value="'.dol_escape_htmltag(GETPOST($key, 'alpha')).'"></td>';
4648 } elseif ($key == 'proptype') {
4649 print '<td class="titlefieldcreate fieldrequired">'.$attribute.'</td><td class="valuefieldcreate maxwidth50">';
4650 print '<input class="maxwidth200" name="'.$key.'" id="'.$key.'" list="datalist'.$key.'" type="text" value="'.dol_escape_htmltag(GETPOST($key, 'alpha')).'">';
4651 //print '<div id="suggestions"></div>';
4652 print '<datalist id="datalist'.$key.'">';
4653 print '<option>varchar(128)</option>';
4654 print '<option>email</option>';
4655 print '<option>phone</option>';
4656 print '<option>ip</option>';
4657 print '<option>url</option>';
4658 print '<option>password</option>';
4659 print '<option>text</option>';
4660 print '<option>html</option>';
4661 print '<option>date</option>';
4662 print '<option>datetime</option>';
4663 print '<option>integer</option>';
4664 print '<option>stars(5)</option>';
4665 print '<option>double(28,4)</option>';
4666 print '<option>real</option>';
4667 print '<option>integer:ClassName:RelativePath/To/ClassFile.class.php[:1[:FILTER]]</option>';
4668 // Combo with list of fields
4669 /*
4670 if (empty($formadmin)) {
4671 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
4672 $formadmin = new FormAdmin($db);
4673 }
4674 print $formadmin->selectTypeOfFields($key, GETPOST($key, 'alpha'));
4675 */
4676 print '</datalist>';
4677 print '</td>';
4678 //} elseif ($key == 'propvalidate') {
4679 // print '<td class="titlefieldcreate">'.$attribute.'</td><td class="valuefieldcreate maxwidth50"><input type="number" step="1" min="0" max="1" class="text maxwidth100" value="'.dol_escape_htmltag(GETPOST($key, 'alpha')).'"></td>';
4680 } elseif ($key == 'propvisible') {
4681 print '<td class="titlefieldcreate">'.$attribute.'</td><td class="valuefieldcreate"><input class="maxwidth200" type="text" name="'.$key.'" value="'.dol_escape_htmltag(GETPOSTISSET($key) ? GETPOST($key, 'alpha') : "1").'"></td>';
4682 } elseif ($key == 'propenabled') {
4683 //$default = "isModEnabled('".dol_strtolower($module)."')";
4684 $default = 1;
4685 print '<td class="titlefieldcreate">'.$attribute.'</td><td class="valuefieldcreate"><input class="maxwidth200" type="text" name="'.$key.'" value="'.dol_escape_htmltag(GETPOSTISSET($key) ? GETPOST($key, 'alpha') : $default).'"></td>';
4686 } elseif ($key == 'proparrayofkeyval') {
4687 print '<td class="titlefieldcreate tdproparrayofkeyval">'.$attribute.'</td><td class="valuefieldcreate"><textarea class="maxwidth200" name="'.$key.'">'.dol_escape_htmltag(GETPOSTISSET($key) ? GETPOST($key, 'alpha') : "").'</textarea></td>';
4688 } else {
4689 print '<td class="titlefieldcreate">'.$attribute.'</td><td class="valuefieldcreate"><input class="maxwidth200" type="text" name="'.$key.'" value="'.dol_escape_htmltag(GETPOSTISSET($key) ? GETPOST($key, 'alpha') : '').'"></td>';
4690 }
4691 $counter++;
4692 if ($counter % 2 === 0) {
4693 print '</tr>';
4694 }
4695 }
4696 if ($counter % 2 !== 0) {
4697 while ($counter % 2 !== 0) {
4698 print '<td></td>';
4699 $counter++;
4700 }
4701 print '</tr>';
4702 }
4703 print '</table><br>'."\n";
4704 print '<div class="center">';
4705 print '<input type="submit" class="button button-save" name="add" value="' . dol_escape_htmltag($langs->trans('Create')) . '">';
4706 print '<input type="button" class="button button-cancel" name="cancel" value="' . dol_escape_htmltag($langs->trans('Cancel')) . '" onclick="goBack()">';
4707 print '</div>';
4708 print '</form>';
4709 // javascript
4710 print '<script>
4711 function goBack() {
4712 var url = "'.$_SERVER["PHP_SELF"].'?tab=objects&module='.urlencode($module).'";
4713 window.location.href = url;
4714 }
4715 $(document).ready(function() {
4716 $("#proplabel").on("keyup", function() {
4717 console.log("key up on label");
4718 s = cleanString($("#proplabel").val());
4719 $("#propname").val(s);
4720 });
4721
4722 function cleanString( stringtoclean )
4723 {
4724 // allow "a-z", "A-Z", "0-9" and "_"
4725 stringtoclean = stringtoclean.replace(/[^a-z0-9_]+/ig, "");
4726 stringtoclean = stringtoclean.toLowerCase();
4727 if (!isNaN(stringtoclean)) {
4728 return ""
4729 }
4730 while ( stringtoclean.length > 1 && !isNaN( stringtoclean.charAt(0)) ){
4731 stringtoclean = stringtoclean.dol_substr(1)
4732 }
4733 if (stringtoclean.length > 28) {
4734 stringtoclean = stringtoclean.substring(0, 27);
4735 }
4736 return stringtoclean;
4737 }
4738
4739 });';
4740 print '</script>';
4741 } elseif ($tabobj == 'deleteobject') {
4742 // Delete object tab
4743 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
4744 print '<input type="hidden" name="token" value="'.newToken().'">';
4745 print '<input type="hidden" name="action" value="confirm_deleteobject">';
4746 print '<input type="hidden" name="tab" value="objects">';
4747 print '<input type="hidden" name="tabobj" value="deleteobject">';
4748 print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
4749
4750 print $langs->trans("EnterNameOfObjectToDeleteDesc").'<br><br>';
4751
4752 print '<input type="text" class="valignmiddle" name="objectname" value="" placeholder="'.dol_escape_htmltag($langs->trans("ObjectKey")).'" autofocus>';
4753 print '<input type="submit" class="button smallpaddingimp" name="delete" value="'.dol_escape_htmltag($langs->trans("Delete")).'"'.($dirins ? '' : ' disabled="disabled"').'>';
4754 print '</form>';
4755 } else {
4756 // tabobj = module
4757 if ($action == 'deleteproperty') {
4758 $formconfirm = $form->formconfirm(
4759 $_SERVER["PHP_SELF"].'?propertykey='.urlencode(GETPOST('propertykey', 'alpha')).'&objectname='.urlencode($objectname).'&tab='.urlencode($tab).'&module='.urlencode($module).'&tabobj='.urlencode($tabobj),
4760 $langs->trans('Delete'),
4761 $langs->trans('ConfirmDeleteProperty', GETPOST('propertykey', 'alpha')),
4762 'confirm_deleteproperty',
4763 '',
4764 0,
4765 1
4766 );
4767
4768 // Print form confirm
4769 print $formconfirm;
4770 }
4771 if ($action != 'editfile' || empty($file)) {
4772 try {
4773 //$pathtofile = $listofmodules[dol_strtolower($module)]['moduledescriptorrelpath'];
4774
4775 $pathtoclass = dol_strtolower($module).'/class/'.dol_strtolower($tabobj).'.class.php';
4776 $pathtoapi = dol_strtolower($module).'/class/api_'.dol_strtolower($module).'.class.php';
4777 $pathtoagenda = dol_strtolower($module).'/'.dol_strtolower($tabobj).'_agenda.php';
4778 $pathtocard = dol_strtolower($module).'/'.dol_strtolower($tabobj).'_card.php';
4779 $pathtodocument = dol_strtolower($module).'/'.dol_strtolower($tabobj).'_document.php';
4780 $pathtolist = dol_strtolower($module).'/'.dol_strtolower($tabobj).'_list.php';
4781 $pathtonote = dol_strtolower($module).'/'.dol_strtolower($tabobj).'_note.php';
4782 $pathtocontact = dol_strtolower($module).'/'.dol_strtolower($tabobj).'_contact.php';
4783 $pathtophpunit = dol_strtolower($module).'/test/phpunit/'.dol_strtolower($tabobj).'Test.php';
4784
4785 // Try to load object class file
4786 clearstatcache(true);
4787 if (function_exists('opcache_invalidate')) {
4788 opcache_invalidate($dirread.'/'.$pathtoclass, true); // remove the include cache hell !
4789 }
4790
4791 if (empty($forceddirread) && empty($dirread)) {
4792 $result = dol_include_once($pathtoclass);
4793 $stringofinclude = "dol_include_once(".$pathtoclass.")";
4794 } else {
4795 $result = include_once $dirread.'/'.$pathtoclass;
4796 $stringofinclude = "@include_once ".$dirread.'/'.$pathtoclass;
4797 }
4798
4799 if (class_exists($tabobj)) {
4800 try {
4801 $tmpobject = @new $tabobj($db);
4802 } catch (Exception $e) {
4803 dol_syslog('Failed to load Constructor of class: '.$e->getMessage(), LOG_WARNING);
4804 }
4805 } else {
4806 print '<span class="warning">'.$langs->trans('Failed to find the class '.$tabobj.' despite the '.$stringofinclude).'</span><br><br>';
4807 }
4808
4809 // Define path for sql file
4810 $pathtosql = dol_strtolower($module).'/sql/llx_'.dol_strtolower($module).'_'.dol_strtolower($tabobj).'-'.dol_strtolower($module).'.sql';
4811 $result = dol_buildpath($pathtosql);
4812 if (! dol_is_file($result)) {
4813 $pathtosql = dol_strtolower($module).'/sql/llx_'.dol_strtolower($module).'_'.dol_strtolower($tabobj).'.sql';
4814 $result = dol_buildpath($pathtosql);
4815 if (! dol_is_file($result)) {
4816 $pathtosql = 'install/mysql/tables/llx_'.dol_strtolower($module).'_'.dol_strtolower($tabobj).'-'.dol_strtolower($module).'.sql';
4817 $result = dol_buildpath($pathtosql);
4818 if (! dol_is_file($result)) {
4819 $pathtosql = 'install/mysql/tables/llx_'.dol_strtolower($module).'-'.dol_strtolower($module).'.sql';
4820 $result = dol_buildpath($pathtosql);
4821 if (! dol_is_file($result)) {
4822 $pathtosql = 'install/mysql/tables/llx_'.dol_strtolower($module).'.sql';
4823 $pathtosqlextra = 'install/mysql/tables/llx_'.dol_strtolower($module).'_extrafields.sql';
4824 $result = dol_buildpath($pathtosql);
4825 } else {
4826 $pathtosqlextra = 'install/mysql/tables/llx_'.dol_strtolower($module).'_extrafields-'.dol_strtolower($module).'.sql';
4827 }
4828 } else {
4829 $pathtosqlextra = 'install/mysql/tables/llx_'.dol_strtolower($module).'_'.dol_strtolower($tabobj).'_extrafields-'.dol_strtolower($module).'.sql';
4830 }
4831 } else {
4832 $pathtosqlextra = dol_strtolower($module).'/sql/llx_'.dol_strtolower($module).'_'.dol_strtolower($tabobj).'_extrafields.sql';
4833 }
4834 } else {
4835 $pathtosqlextra = dol_strtolower($module).'/sql/llx_'.dol_strtolower($module).'_'.dol_strtolower($tabobj).'_extrafields-'.dol_strtolower($module).'.sql';
4836 }
4837 $pathtosqlroot = preg_replace('/\/llx_.*$/', '', $pathtosql);
4838
4839 $pathtosqlkey = preg_replace('/\.sql$/', '.key.sql', $pathtosql);
4840 $pathtosqlextrakey = preg_replace('/\.sql$/', '.key.sql', $pathtosqlextra);
4841
4842 $pathtolib = dol_strtolower($module).'/lib/'.dol_strtolower($module).'.lib.php';
4843 $pathtoobjlib = dol_strtolower($module).'/lib/'.dol_strtolower($module).'_'.dol_strtolower($tabobj).'.lib.php';
4844
4845 $tmpobject = $tmpobject ?? null; // @phan-suppress-current-line PhanPluginDuplicateExpressionAssignmentOperation
4846 if (is_object($tmpobject) && property_exists($tmpobject, 'picto')) {
4847 $pathtopicto = $tmpobject->picto;
4848 $realpathtopicto = '';
4849 } else {
4850 $pathtopicto = dol_strtolower($module).'/img/object_'.dol_strtolower($tabobj).'.png';
4851 $realpathtopicto = $dirread.'/'.$pathtopicto;
4852 }
4853
4854 //var_dump($pathtoclass);
4855 //var_dump($dirread);
4856 $realpathtoclass = $dirread.'/'.$pathtoclass;
4857 $realpathtoapi = $dirread.'/'.$pathtoapi;
4858 $realpathtoagenda = $dirread.'/'.$pathtoagenda;
4859 $realpathtocard = $dirread.'/'.$pathtocard;
4860 $realpathtodocument = $dirread.'/'.$pathtodocument;
4861 $realpathtolist = $dirread.'/'.$pathtolist;
4862 $realpathtonote = $dirread.'/'.$pathtonote;
4863 $realpathtocontact = $dirread.'/'.$pathtocontact;
4864 $realpathtophpunit = $dirread.'/'.$pathtophpunit;
4865 $realpathtosql = $dirread.'/'.$pathtosql;
4866 $realpathtosqlextra = $dirread.'/'.$pathtosqlextra;
4867 $realpathtosqlkey = $dirread.'/'.$pathtosqlkey;
4868 $realpathtosqlextrakey = $dirread.'/'.$pathtosqlextrakey;
4869 $realpathtolib = $dirread.'/'.$pathtolib;
4870 $realpathtoobjlib = $dirread.'/'.$pathtoobjlib;
4871
4872 if (empty($realpathtoapi)) { // For compatibility with some old modules
4873 $pathtoapi = dol_strtolower($module).'/class/api_'.dol_strtolower($module).'s.class.php';
4874 $realpathtoapi = $dirread.'/'.$pathtoapi;
4875 }
4876
4877 $urloflist = dol_buildpath('/'.$pathtolist, 1);
4878 $urlofcard = dol_buildpath('/'.$pathtocard, 1);
4879
4880 $objs = array();
4881
4882 // Image
4883 $htmltooltip = '';
4884 if ($realpathtopicto && dol_is_file($realpathtopicto)) {
4885 $htmltooltip .= '<span class="fa fa-file-image-o"></span> '.$langs->trans("Image").' : <strong>'.(dol_is_file($realpathtopicto) ? '' : '<strike>').preg_replace('/^'.dol_strtolower($module).'\//', '', $pathtopicto).(dol_is_file($realpathtopicto) ? '' : '</strike>').'</strong>';
4886 $htmltooltip .= '<br>';
4887 } elseif (!empty($tmpobject)) {
4888 $htmltooltip .= '<span class="fa fa-file-image-o"></span> '.$langs->trans("Image").' : '.img_picto('', $tmpobject->picto, 'class="pictofixedwidth valignmiddle"').$tmpobject->picto;
4889 $htmltooltip .= '<br>';
4890 }
4891 $htmltooltip .= '<span class="fa fa-file-image-o"></span> '.$langs->trans("IsExtraFieldManaged").' : '.yn(empty($tmpobject->isextrafieldmanaged) ? 0 : 1, 1, 2);
4892 $htmltooltip .= '<br>';
4893 $htmltooltip .= '<span class="fa fa-file-image-o"></span> '.$langs->trans("IsMultiEntityManaged").' : '.yn(empty($tmpobject->ismultientitymanaged) ? 0 : 1, 1, 2);
4894 $htmltooltip .= '<br>';
4895
4896 print '<!-- section for object -->';
4897 print '<div class="fichehalfleft smallxxx">';
4898 // Main DAO class file
4899 print '<span class="fa fa-file"></span> '.$langs->trans("ClassFile").' : <strong>'.(dol_is_file($realpathtoclass) ? '' : '<strike>').preg_replace('/^'.dol_strtolower($module).'\//', '', $pathtoclass).(dol_is_file($realpathtoclass) ? '' : '</strike>').'</strong>';
4900 print ' <a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&tabobj='.$tabobj.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&token='.newToken().'&format=php&file='.urlencode($pathtoclass).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
4901 print $form->textwithpicto('', $htmltooltip, 1, 'help', 'valignmiddle', 1);
4902 print '<br>';
4903
4904 // API file
4905 print '<br>';
4906 print '<span class="fa fa-file"></span> '.$langs->trans("ApiClassFile").' : <strong class="wordbreak">'.(dol_is_file($realpathtoapi) ? '' : '<strike><span class="opacitymedium">').preg_replace('/^'.dol_strtolower($module).'\//', '', $pathtoapi).(dol_is_file($realpathtoapi) ? '' : '</span></strike>').'</strong>';
4907 if (dol_is_file($realpathtoapi)) {
4908 $file = file_get_contents($realpathtoapi);
4909 if (preg_match('/var '.$tabobj.'\s+([^\s]*)\s/ims', $file, $objs)) {
4910 print ' <a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&tabobj='.$tabobj.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&token='.newToken().'&format=php&file='.urlencode($pathtoapi).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
4911 print ' ';
4912 print '<a class="reposition editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&tabobj='.$tabobj.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=confirm_removefile&token='.newToken().'&file='.urlencode($pathtoapi).'">'.img_picto($langs->trans("Delete"), 'delete').'</a>';
4913 print $form->textwithpicto('', $langs->trans("InfoForApiFile"), 1, 'warning');
4914 print ' &nbsp; ';
4915 // Comparing to null (phan considers $modulelowercase can be null here)
4916 if (!isModEnabled($modulelowercase)) { // If module is not activated
4917 print '<a href="#" class="classfortooltip" target="apiexplorer" title="'.$langs->trans("ModuleMustBeEnabled", $module).'"><strike>'.$langs->trans("ApiExplorer").'</strike></a>';
4918 } else {
4919 print '<a href="'.DOL_URL_ROOT.'/api/index.php/explorer/" target="apiexplorer">'.$langs->trans("ApiExplorer").'</a>';
4920 }
4921 } else {
4922 print '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&tabobj='.$tabobj.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=initapi&token='.newToken().'&format=php&file='.urlencode($pathtoapi).'">'.img_picto($langs->trans('AddAPIsForThisObject'), 'generate', 'class="paddingleft"').'</a>';
4923 }
4924 } else {
4925 print '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&tabobj='.$tabobj.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=initapi&token='.newToken().'&format=php&file='.urlencode($pathtoapi).'">'.img_picto('Generate', 'generate', 'class="paddingleft"').'</a>';
4926 }
4927 // PHPUnit
4928 print '<br>';
4929 print '<span class="fa fa-file"></span> '.$langs->trans("TestClassFile").' : <strong class="wordbreak">'.(dol_is_file($realpathtophpunit) ? '' : '<strike><span class="opacitymedium">').preg_replace('/^'.dol_strtolower($module).'\//', '', $pathtophpunit).(dol_is_file($realpathtophpunit) ? '' : '</span></strike>').'</strong>';
4930 if (dol_is_file($realpathtophpunit)) {
4931 print ' <a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&tabobj='.$tabobj.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&token='.newToken().'&format=php&file='.urlencode($pathtophpunit).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
4932 print ' ';
4933 print '<a class="reposition editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&tabobj='.$tabobj.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=confirm_removefile&token='.newToken().'&file='.urlencode($pathtophpunit).'">'.img_picto($langs->trans("Delete"), 'delete').'</a>';
4934 } else {
4935 print '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&tabobj='.$tabobj.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=initphpunit&token='.newToken().'&format=php&file='.urlencode($pathtophpunit).'">'.img_picto('Generate', 'generate', 'class="paddingleft"').'</a>';
4936 }
4937 print '<br>';
4938
4939 print '<br>';
4940
4941 print '<span class="fa fa-file"></span> '.$langs->trans("PageForLib").' : <strong class="wordbreak">'.(dol_is_file($realpathtolib) ? '' : '<strike>').preg_replace('/^'.dol_strtolower($module).'\//', '', $pathtolib).(dol_is_file($realpathtolib) ? '' : '</strike>').'</strong>';
4942 print ' <a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&tabobj='.$tabobj.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&token='.newToken().'&format=php&file='.urlencode($pathtolib).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
4943 print '<br>';
4944 print '<span class="fa fa-file"></span> '.$langs->trans("PageForObjLib").' : <strong class="wordbreak">'.(dol_is_file($realpathtoobjlib) ? '' : '<strike>').preg_replace('/^'.dol_strtolower($module).'\//', '', $pathtoobjlib).(dol_is_file($realpathtoobjlib) ? '' : '</strike>').'</strong>';
4945 print ' <a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&tabobj='.$tabobj.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&token='.newToken().'&format=php&file='.urlencode($pathtoobjlib).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
4946 print '<br>';
4947
4948 print '<br>';
4949 print '<span class="fa fa-file"></span> '.$langs->trans("SqlFile").' : <strong class="wordbreak">'.(dol_is_file($realpathtosql) ? '' : '<strike>').preg_replace('/^'.dol_strtolower($module).'\//', '', $pathtosql).(dol_is_file($realpathtosql) ? '' : '</strike>').'</strong>';
4950 print ' <a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&tabobj='.$tabobj.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&token='.newToken().'&format=sql&file='.urlencode($pathtosql).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
4951 print ' &nbsp; <a class="reposition" href="'.$_SERVER["PHP_SELF"].'?tab='.urlencode($tab).'&tabobj='.$tabobj.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=droptable&token='.newToken().'">'.$langs->trans("DropTableIfEmpty").'</a>';
4952 //print ' &nbsp; <a href="'.$_SERVER["PHP_SELF"].'">'.$langs->trans("RunSql").'</a>';
4953 print '<br>';
4954 print '<span class="fa fa-file"></span> '.$langs->trans("SqlFileKey").' : <strong class="wordbreak">'.(dol_is_file($realpathtosqlkey) ? '' : '<strike>').preg_replace('/^'.dol_strtolower($module).'\//', '', $pathtosqlkey).(dol_is_file($realpathtosqlkey) ? '' : '</strike>').'</strong>';
4955 print ' <a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&tabobj='.$tabobj.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&token='.newToken().'&format=sql&file='.urlencode($pathtosqlkey).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
4956 //print ' &nbsp; <a href="'.$_SERVER["PHP_SELF"].'">'.$langs->trans("RunSql").'</a>';
4957 print '<br>';
4958 if (!empty($tmpobject->isextrafieldmanaged)) {
4959 print '<span class="fa fa-file"></span> '.$langs->trans("SqlFileExtraFields").' : <strong class="wordbreak">'.(dol_is_file($realpathtosqlextra) ? '' : '<strike><span class="opacitymedium">').preg_replace('/^'.dol_strtolower($module).'\//', '', $pathtosqlextra).(dol_is_file($realpathtosqlextra) && dol_is_file($realpathtosqlextrakey) ? '' : '</span></strike>').'</strong>';
4960 if (dol_is_file($realpathtosqlextra) && dol_is_file($realpathtosqlextrakey)) {
4961 print ' <a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&tabobj='.$tabobj.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&token='.newToken().'&file='.urlencode($pathtosqlextra).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
4962 print ' ';
4963 print '<a class="reposition editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&tabobj='.$tabobj.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=confirm_removefile&token='.newToken().'&file='.urlencode($pathtosqlextra).'">'.img_picto($langs->trans("Delete"), 'delete').'</a>';
4964 print ' &nbsp; ';
4965 print '<a class="reposition editfielda" href="'.$_SERVER["PHP_SELF"].'?tab='.urlencode($tab).'&tabobj='.$tabobj.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=droptableextrafields&token='.newToken().'">'.$langs->trans("DropTableIfEmpty").'</a>';
4966 } else {
4967 print '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&tabobj='.$tabobj.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=initsqlextrafields&token='.newToken().'&format=sql&file='.urlencode($pathtosqlextra).'">'.img_picto('Generate', 'generate', 'class="paddingleft"').'</a>';
4968 }
4969
4970 //print ' &nbsp; <a href="'.$_SERVER["PHP_SELF"].'">'.$langs->trans("RunSql").'</a>';
4971 print '<br>';
4972 print '<span class="fa fa-file"></span> '.$langs->trans("SqlFileKeyExtraFields").' : <strong class="wordbreak">'.(dol_is_file($realpathtosqlextrakey) ? '' : '<strike><span class="opacitymedium">').preg_replace('/^'.dol_strtolower($module).'\//', '', $pathtosqlextrakey).(dol_is_file($realpathtosqlextra) && dol_is_file($realpathtosqlextrakey) ? '' : '</span></strike>').'</strong>';
4973 if (dol_is_file($realpathtosqlextra) && dol_is_file($realpathtosqlextrakey)) {
4974 print ' <a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&tabobj='.$tabobj.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&token='.newToken().'&format=sql&file='.urlencode($pathtosqlextrakey).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
4975 print ' ';
4976 print '<a class="reposition editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&tabobj='.$tabobj.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=confirm_removefile&token='.newToken().'&file='.urlencode($pathtosqlextrakey).'">'.img_picto($langs->trans("Delete"), 'delete').'</a>';
4977 } else {
4978 print '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&tabobj='.$tabobj.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=initsqlextrafields&token='.newToken().'&format=sql&file='.urlencode($pathtosqlextra).'">'.img_picto('Generate', 'generate', 'class="paddingleft"').'</a>';
4979 }
4980 print '<br>';
4981 }
4982 print '</div>';
4983
4984 print '<div class="fichehalfleft smallxxxx">';
4985 print '<span class="fa fa-file"></span> '.$langs->trans("PageForList").' : <strong class="wordbreak"><a href="'.$urloflist.'" target="_test">'.(dol_is_file($realpathtolist) ? '' : '<strike><span class="opacitymedium">').preg_replace('/^'.dol_strtolower($module).'\//', '', $pathtolist).(dol_is_file($realpathtolist) ? '' : '</span></strike>').'</a></strong>';
4986 print ' <a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&tabobj='.$tabobj.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&token='.newToken().'&format=php&file='.urlencode($pathtolist).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
4987 print '<br>';
4988 print '<span class="fa fa-file"></span> '.$langs->trans("PageForCreateEditView").' : <strong class="wordbreak"><a href="'.$urlofcard.'?action=create" target="_test">'.(dol_is_file($realpathtocard) ? '' : '<strike>').preg_replace('/^'.dol_strtolower($module).'\//', '', $pathtocard).(dol_is_file($realpathtocard) ? '' : '</strike>').'?action=create</a></strong>';
4989 print ' <a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&tabobj='.$tabobj.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&token='.newToken().'&format=php&file='.urlencode($pathtocard).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
4990 print '<br>';
4991 // Page contact
4992 print '<span class="fa fa-file"></span> '.$langs->trans("PageForContactTab").' : <strong class="wordbreak">'.(dol_is_file($realpathtocontact) ? '' : '<strike><span class="opacitymedium">').preg_replace('/^'.dol_strtolower($module).'\//', '', $pathtocontact).(dol_is_file($realpathtocontact) ? '' : '</span></strike>').'</strong>';
4993 print ' <a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&tabobj='.$tabobj.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&token='.newToken().'&format=php&file='.urlencode($pathtocontact).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
4994 if (dol_is_file($realpathtocontact)) {
4995 print ' ';
4996 print '<a class="reposition editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&tabobj='.$tabobj.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=confirm_removefile&token='.newToken().'&file='.urlencode($pathtocontact).'">'.img_picto($langs->trans("Delete"), 'delete').'</a>';
4997 } else {
4998 print '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&tabobj='.$tabobj.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=initpagecontact&token='.newToken().'&format=php&file='.urlencode($pathtocontact).'">'.img_picto('Generate', 'generate', 'class="paddingleft"').'</a>';
4999 }
5000 print '<br>';
5001 // Page document
5002 print '<span class="fa fa-file"></span> '.$langs->trans("PageForDocumentTab").' : <strong class="wordbreak">'.(dol_is_file($realpathtodocument) ? '' : '<strike><span class="opacitymedium">').preg_replace('/^'.dol_strtolower($module).'\//', '', $pathtodocument).(dol_is_file($realpathtodocument) ? '' : '</span></strike>').'</strong>';
5003 print ' <a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&tabobj='.$tabobj.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&token='.newToken().'&format=php&file='.urlencode($pathtodocument).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
5004 if (dol_is_file($realpathtodocument)) {
5005 print ' ';
5006 print '<a class="reposition editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&tabobj='.$tabobj.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=confirm_removefile&token='.newToken().'&file='.urlencode($pathtodocument).'">'.img_picto($langs->trans("Delete"), 'delete').'</a>';
5007 } else {
5008 print '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&tabobj='.$tabobj.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=initpagedocument&token='.newToken().'&format=php&file='.urlencode($pathtocontact).'">'.img_picto('Generate', 'generate', 'class="paddingleft"').'</a>';
5009 }
5010 print '<br>';
5011 // Page notes
5012 print '<span class="fa fa-file"></span> '.$langs->trans("PageForNoteTab").' : <strong class="wordbreak">'.(dol_is_file($realpathtonote) ? '' : '<strike><span class="opacitymedium">').preg_replace('/^'.dol_strtolower($module).'\//', '', $pathtonote).(dol_is_file($realpathtonote) ? '' : '</span></strike>').'</strong>';
5013 print ' <a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&tabobj='.$tabobj.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&token='.newToken().'&format=php&file='.urlencode($pathtonote).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
5014 if (dol_is_file($realpathtonote)) {
5015 print ' ';
5016 print '<a class="reposition editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&tabobj='.$tabobj.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=confirm_removefile&token='.newToken().'&file='.urlencode($pathtonote).'">'.img_picto($langs->trans("Delete"), 'delete').'</a>';
5017 } else {
5018 print '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&tabobj='.$tabobj.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=initpagenote&token='.newToken().'&format=php&file='.urlencode($pathtocontact).'">'.img_picto('Generate', 'generate', 'class="paddingleft"').'</a>';
5019 }
5020 print '<br>';
5021 // Page agenda
5022 print '<span class="fa fa-file"></span> '.$langs->trans("PageForAgendaTab").' : <strong class="wordbreak">'.(dol_is_file($realpathtoagenda) ? '' : '<strike><span class="opacitymedium">').preg_replace('/^'.dol_strtolower($module).'\//', '', $pathtoagenda).(dol_is_file($realpathtoagenda) ? '' : '</span></strike>').'</strong>';
5023 print ' <a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&tabobj='.$tabobj.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&format=php&token='.newToken().'&file='.urlencode($pathtoagenda).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
5024 if (dol_is_file($realpathtoagenda)) {
5025 print ' ';
5026 print '<a class="reposition editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&tabobj='.$tabobj.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=confirm_removefile&token='.newToken().'&file='.urlencode($pathtoagenda).'">'.img_picto($langs->trans("Delete"), 'delete').'</a>';
5027 } else {
5028 print '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&tabobj='.$tabobj.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=initpageagenda&token='.newToken().'&format=php&file='.urlencode($pathtocontact).'">'.img_picto('Generate', 'generate', 'class="paddingleft"').'</a>';
5029 }
5030 print '<br>';
5031 print '<br>';
5032
5033 print '</div>';
5034
5035 print '<br><br><br>';
5036
5037 if (!empty($tmpobject)) {
5038 $reflector = new ReflectionClass($tabobj);
5039 $reflectorproperties = $reflector->getProperties(); // Can also use get_object_vars
5040 $reflectorpropdefault = $reflector->getDefaultProperties(); // Can also use get_object_vars
5041 //$propstat = $reflector->getStaticProperties();
5042 //var_dump($reflectorpropdefault);
5043
5044 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
5045 print '<input type="hidden" name="token" value="'.newToken().'">';
5046 print '<input type="hidden" name="action" value="addproperty">';
5047 print '<input type="hidden" name="tab" value="objects">';
5048 print '<input type="hidden" name="page_y" value="">';
5049 print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module.($forceddirread ? '@'.$dirread : '')).'">';
5050 print '<input type="hidden" name="tabobj" value="'.dol_escape_htmltag($tabobj).'">';
5051
5052 print '<input class="button smallpaddingimp" type="submit" name="regenerateclasssql" value="'.$langs->trans("RegenerateClassAndSql").'">';
5053
5054 $parameters = array('module' => $module, 'tabobj' => $tabobj, 'dirread' => $dirread);
5055 $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $tmpobject, $action);
5056 if ($reshook < 0) {
5057 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
5058 }
5059 print $hookmanager->resPrint;
5060
5061 print '<br><br class="clearboth">';
5062 print '<br class="clearboth">';
5063
5064 $mod = dol_strtolower($module);
5065 $obj = dol_strtolower($tabobj);
5066 $newproperty = dolGetButtonTitle($langs->trans('NewProperty'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/modulebuilder/index.php?tab=objects&module='.urlencode($module).'&tabobj=createproperty&obj='.urlencode($tabobj));
5067 $nbOfProperties = count($reflectorpropdefault['fields']);
5068
5069 print_barre_liste($langs->trans("ObjectProperties"), 0, $_SERVER["PHP_SELF"], '', '', '', '', 0, $nbOfProperties, '', 0, $newproperty, 'margintoponly', 0, 0, 0, 1);
5070
5071 //var_dump($reflectorpropdefault);exit;
5072 print '<!-- Table with properties of object -->'."\n";
5073 print '<div class="div-table-responsive">';
5074 print '<table class="noborder small">';
5075 print '<tr class="liste_titre">';
5076 if (!empty($conf->main_checkbox_left_column)) {
5077 print '<th class="tdstickyright tdstickyghostwhite"></th>';
5078 }
5079 print '<th class="tdsticky tdstickygray">';
5080 $htmltext = $langs->trans("PropertyDesc").'<br><br><a class="" href="https://wiki.dolibarr.org/index.php/Language_and_development_rules#Table_and_fields_structures" target="_blank" rel="noopener noreferrer external">'.$langs->trans("SeeExamples").'</a>';
5081 print $form->textwithpicto($langs->trans("Code"), $htmltext, 1, 'help', 'extracss', 0, 3, 'propertyhelp');
5082 print '</th>';
5083 print '<th>';
5084 print $form->textwithpicto($langs->trans("Label"), $langs->trans("YouCanUseTranslationKey"));
5085 print '</th>';
5086 print '<th>'.$form->textwithpicto($langs->trans("Type"), $langs->trans("TypeOfFieldsHelpIntro").'<br><br>'.$langs->trans("TypeOfFieldsHelp"), 1, 'help', 'extracss', 0, 3, 'typehelp').'</th>';
5087 print '<th>'.$form->textwithpicto($langs->trans("ArrayOfKeyValues"), $langs->trans("ArrayOfKeyValuesDesc")).'</th>';
5088 print '<th class="center">'.$form->textwithpicto($langs->trans("NotNull"), $langs->trans("NotNullDesc")).'</th>';
5089 print '<th class="center">'.$langs->trans("DefaultValue").'</th>';
5090 print '<th class="center">'.$langs->trans("DatabaseIndex").'</th>';
5091 print '<th class="center">'.$form->textwithpicto($langs->trans("ForeignKey"), $langs->trans("ForeignKeyDesc"), 1, 'help', 'extracss', 0, 3, 'foreignkeyhelp').'</th>';
5092 print '<th class="right">'.$langs->trans("Position").'</th>';
5093 print '<th class="center">'.$form->textwithpicto($langs->trans("Enabled"), $langs->trans("EnabledDesc"), 1, 'help', 'extracss', 0, 3, 'enabledhelp').'</th>';
5094 print '<th class="center">'.$form->textwithpicto($langs->trans("Visibility"), $langs->trans("VisibleDesc").'<br><br>'.$langs->trans("ItCanBeAnExpression"), 1, 'help', 'extracss', 0, 3, 'visiblehelp').'</th>';
5095 print '<th class="center">'.$langs->trans("NotEditable").'</th>';
5096 //print '<th class="center">'.$langs->trans("AlwaysEditable").'</th>';
5097 print '<th class="center">'.$form->textwithpicto($langs->trans("SearchAll"), $langs->trans("SearchAllDesc")).'</th>';
5098 print '<th class="center">'.$form->textwithpicto($langs->trans("IsAMeasure"), $langs->trans("IsAMeasureDesc")).'</th>';
5099 print '<th class="center">'.$langs->trans("CSSClass").'</th>';
5100 print '<th class="center">'.$langs->trans("CSSViewClass").'</th>';
5101 print '<th class="center">'.$langs->trans("CSSListClass").'</th>';
5102 print '<th>'.$langs->trans("KeyForTooltip").'</th>';
5103 print '<th class="center">'.$langs->trans("ShowOnCombobox").'</th>';
5104 //print '<th class="center">'.$langs->trans("Disabled").'</th>';
5105 print '<th>'.$form->textwithpicto($langs->trans("Validate"), $langs->trans("ValidateModBuilderDesc")).'</th>';
5106 print '<th>'.$langs->trans("Comment").'</th>';
5107 if (empty($conf->main_checkbox_left_column)) {
5108 print '<th class="tdstickyright tdstickyghostwhite"></th>';
5109 }
5110 print '</tr>';
5111
5112 // We must use $reflectorpropdefault['fields'] to get list of fields because $tmpobject->fields may have been
5113 // modified during the constructor and we want value into head of class before constructor is called.
5114 //$properties = dol_sort_array($tmpobject->fields, 'position');
5115 $properties = dol_sort_array($reflectorpropdefault['fields'], 'position');
5116 if (!empty($properties)) {
5117 // List of existing properties
5118 foreach ($properties as $propkey => $propval) {
5119 /* If from Reflection
5120 if ($propval->class == $tabobj)
5121 {
5122 $propname=$propval->getName();
5123 $comment=$propval->getDocComment();
5124 $type=gettype($tmpobject->$propname);
5125 $default=$propdefault[$propname];
5126 // Discard generic properties
5127 if (in_array($propname, array('element', 'childtables', 'table_element', 'table_element_line', 'class_element_line', 'ismultientitymanaged'))) continue;
5128
5129 // Keep or not lines
5130 if (in_array($propname, array('fk_element', 'lines'))) continue;
5131 }*/
5132
5133 $propname = $propkey;
5134 $proplabel = $propval['label'];
5135 $proptype = $propval['type'];
5136 $proparrayofkeyval = !empty($propval['arrayofkeyval']) ? $propval['arrayofkeyval'] : '';
5137 $propnotnull = !empty($propval['notnull']) ? $propval['notnull'] : '0';
5138 $propdefault = !empty($propval['default']) ? $propval['default'] : '';
5139 $propindex = !empty($propval['index']) ? $propval['index'] : '';
5140 $propforeignkey = !empty($propval['foreignkey']) ? $propval['foreignkey'] : '';
5141 $propposition = $propval['position'];
5142 $propenabled = $propval['enabled'];
5143 $propvisible = $propval['visible'];
5144 $propnoteditable = !empty($propval['noteditable']) ? $propval['noteditable'] : 0;
5145 //$propalwayseditable = !empty($propval['alwayseditable'])?$propval['alwayseditable']:0;
5146 $propsearchall = !empty($propval['searchall']) ? $propval['searchall'] : 0;
5147 $propisameasure = !empty($propval['isameasure']) ? $propval['isameasure'] : 0;
5148 $propcss = !empty($propval['css']) ? $propval['css'] : '';
5149 $propcssview = !empty($propval['cssview']) ? $propval['cssview'] : '';
5150 $propcsslist = !empty($propval['csslist']) ? $propval['csslist'] : '';
5151 $prophelp = !empty($propval['help']) ? $propval['help'] : '';
5152 $propshowoncombobox = !empty($propval['showoncombobox']) ? $propval['showoncombobox'] : 0;
5153 //$propdisabled=$propval['disabled'];
5154 $propvalidate = !empty($propval['validate']) ? $propval['validate'] : 0;
5155 $propcomment = !empty($propval['comment']) ? $propval['comment'] : '';
5156
5157 print '<!-- line for object property -->'."\n";
5158 print '<tr class="oddeven">';
5159
5160 if (!empty($conf->main_checkbox_left_column)) {
5161 if ($action == 'editproperty' && $propname == $propertykey) {
5162 print '<td class="center minwidth75 tdstickyright tdstickyghostwhite">';
5163 print '<input class="reposition button smallpaddingimp" type="submit" name="edit" value="'.$langs->trans("Save").'">';
5164 print '<input class="reposition button button-cancel smallpaddingimp" type="submit" name="cancel" value="'.$langs->trans("Cancel").'">';
5165 print '</td>';
5166 } else {
5167 print '<td class="center minwidth75 tdstickyright tdstickyghostwhite">';
5168 if ($propname != 'rowid') {
5169 print '<a class="editfielda reposition marginleftonly marginrighttonly paddingright paddingleft" href="'.$_SERVER["PHP_SELF"].'?action=editproperty&token='.newToken().'&propertykey='.urlencode($propname).'&tab='.urlencode($tab).'&module='.urlencode($module).'&tabobj='.urlencode($tabobj).'">'.img_edit().'</a>';
5170 print '<a class="reposition marginleftonly marginrighttonly paddingright paddingleft" href="'.$_SERVER["PHP_SELF"].'?action=deleteproperty&token='.newToken().'&propertykey='.urlencode($propname).'&tab='.urlencode($tab).'&module='.urlencode($module).'&tabobj='.urlencode($tabobj).'">'.img_delete().'</a>';
5171 }
5172 print '</td>';
5173 }
5174 }
5175 print '<td class="tdsticky tdstickygray">';
5176 print dol_escape_htmltag($propname);
5177 print '</td>';
5178 if ($action == 'editproperty' && $propname == $propertykey) {
5179 print '<td>';
5180 print '<input type="hidden" name="propname" value="'.dol_escape_htmltag($propname).'">';
5181 print '<input name="proplabel" class="maxwidth125" value="'.dol_escape_htmltag($proplabel).'">';
5182 print '</td>';
5183 print '<td class="tdoverflowmax150">';
5184 print '<input name="proptype" id="proptype" class="maxwidth125" value="'.dol_escape_htmltag($proptype).'" list="datalistproptype"></input>';
5185 // Use the samedatalist than for create
5186 print '<datalist id="datalistproptype">';
5187 print '<option>varchar(128)</option>';
5188 print '<option>email</option>';
5189 print '<option>phone</option>';
5190 print '<option>ip</option>';
5191 print '<option>url</option>';
5192 print '<option>password</option>';
5193 print '<option>text</option>';
5194 print '<option>html</option>';
5195 print '<option>date</option>';
5196 print '<option>datetime</option>';
5197 print '<option>integer</option>';
5198 print '<option>stars(5)</option>';
5199 print '<option>double(28,4)</option>';
5200 print '<option>real</option>';
5201 print '<option>integer:ClassName:RelativePath/To/ClassFile.class.php[:1[:FILTER]]</option>';
5202 // Combo with list of fields
5203 /*
5204 if (empty($formadmin)) {
5205 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
5206 $formadmin = new FormAdmin($db);
5207 }
5208 print $formadmin->selectTypeOfFields($key, GETPOST($key, 'alpha'));
5209 */
5210 print '</datalist>';
5211
5212 print '</td>';
5213 print '<td class="tdoverflowmax200">';
5214 print '<textarea name="proparrayofkeyval">';
5215 if (is_array($proparrayofkeyval) || $proparrayofkeyval != '') {
5216 print dol_escape_htmltag(json_encode($proparrayofkeyval, JSON_UNESCAPED_UNICODE));
5217 }
5218 print '</textarea>';
5219 print '</td>';
5220 print '<td>';
5221 print '<input class="center width50" name="propnotnull" value="'.dol_escape_htmltag($propnotnull).'">';
5222 print '</td>';
5223 print '<td>';
5224 print '<input class="maxwidth50" name="propdefault" value="'.dol_escape_htmltag($propdefault).'">';
5225 print '</td>';
5226 print '<td class="center">';
5227 print '<input class="center maxwidth50" name="propindex" value="'.dol_escape_htmltag($propindex).'">';
5228 print '</td>';
5229 print '<td>';
5230 print '<input class="center maxwidth100" name="propforeignkey" value="'.dol_escape_htmltag($propforeignkey).'">';
5231 print '</td>';
5232 print '<td>';
5233 print '<input class="right width50" name="propposition" value="'.dol_escape_htmltag($propposition).'">';
5234 print '</td>';
5235 print '<td>';
5236 print '<input class="center width75" name="propenabled" value="'.dol_escape_htmltag($propenabled).'">';
5237 print '</td>';
5238 print '<td>';
5239 print '<input class="center width75" name="propvisible" value="'.dol_escape_htmltag($propvisible).'">';
5240 print '</td>';
5241 print '<td>';
5242 print '<input class="center width50" name="propnoteditable" size="2" value="'.dol_escape_htmltag($propnoteditable).'">';
5243 print '</td>';
5244 /*print '<td>';
5245 print '<input class="center" name="propalwayseditable" size="2" value="'.dol_escape_htmltag($propalwayseditable).'">';
5246 print '</td>';*/
5247 print '<td>';
5248 print '<input class="center width50" name="propsearchall" value="'.dol_escape_htmltag($propsearchall).'">';
5249 print '</td>';
5250 print '<td>';
5251 print '<input class="center width50" name="propisameasure" value="'.dol_escape_htmltag($propisameasure).'">';
5252 print '</td>';
5253 print '<td>';
5254 print '<input class="center maxwidth50" name="propcss" value="'.dol_escape_htmltag($propcss).'">';
5255 print '</td>';
5256 print '<td>';
5257 print '<input class="center maxwidth50" name="propcssview" value="'.dol_escape_htmltag($propcssview).'">';
5258 print '</td>';
5259 print '<td>';
5260 print '<input class="center maxwidth50" name="propcsslist" value="'.dol_escape_htmltag($propcsslist).'">';
5261 print '</td>';
5262 print '<td>';
5263 print '<input class="maxwidth100" name="prophelp" value="'.dol_escape_htmltag($prophelp).'">';
5264 print '</td>';
5265 print '<td>';
5266 print '<input class="center maxwidth50" name="propshowoncombobox" value="'.dol_escape_htmltag($propshowoncombobox).'">';
5267 print '</td>';
5268 print '<td>';
5269 print '<input type="number" step="1" min="0" max="1" class="text maxwidth100" name="propvalidate" value="'.dol_escape_htmltag($propvalidate).'">';
5270 print '</td>';
5271 print '<td>';
5272 print '<input class="maxwidth100" name="propcomment" value="'.dol_escape_htmltag($propcomment).'">';
5273 print '</td>';
5274 if (empty($conf->main_checkbox_left_column)) {
5275 print '<td class="center minwidth75 tdstickyright tdstickyghostwhite">';
5276 print '<input class="reposition button smallpaddingimp" type="submit" name="edit" value="'.$langs->trans("Save").'">';
5277 print '<input class="reposition button button-cancel smallpaddingimp" type="submit" name="cancel" value="'.$langs->trans("Cancel").'">';
5278 print '</td>';
5279 }
5280 } else {
5281 print '<td class="tdoverflowmax200" title="'.dol_escape_htmltag($proplabel).'">';
5282 print dol_escape_htmltag($proplabel);
5283 print '</td>';
5284 print '<td class="tdoverflowmax200">';
5285 $pictoType = '';
5286 $matches = array();
5287 if (preg_match('/^varchar/', $proptype, $matches)) {
5288 $pictoType = 'varchar';
5289 } elseif (preg_match('/^integer:/', $proptype, $matches)) {
5290 $pictoType = 'link';
5291 } elseif (strpos($proptype, 'integer') === 0) {
5292 $pictoType = dol_substr($proptype, 0, 3);
5293 } elseif (strpos($proptype, 'timestamp') === 0) {
5294 $pictoType = 'datetime';
5295 } elseif (strpos($proptype, 'real') === 0) {
5296 $pictoType = 'double';
5297 } elseif (strpos($proptype, 'stars') === 0) {
5298 $pictoType = 'stars';
5299 }
5300 print(!empty($pictoType) ? getPictoForType($pictoType) : getPictoForType($proptype)).'<span title="'.dol_escape_htmltag($proptype).'">'.dol_escape_htmltag($proptype).'</span>';
5301 print '</td>';
5302 print '<td class="tdoverflowmax200">';
5303 if ($proparrayofkeyval) {
5304 print '<span title="'.dol_escape_htmltag(json_encode($proparrayofkeyval, JSON_UNESCAPED_UNICODE)).'">';
5305 print dol_escape_htmltag(json_encode($proparrayofkeyval, JSON_UNESCAPED_UNICODE));
5306 print '</span>';
5307 }
5308 print '</td>';
5309 print '<td class="center">';
5310 print dol_escape_htmltag($propnotnull);
5311 print '</td>';
5312 print '<td>';
5313 print dol_escape_htmltag($propdefault);
5314 print '</td>';
5315 print '<td class="center">';
5316 print $propindex ? '1' : '';
5317 print '</td>';
5318 print '<td class="center">';
5319 print $propforeignkey ? dol_escape_htmltag($propforeignkey) : '';
5320 print '</td>';
5321 print '<td class="right">';
5322 print dol_escape_htmltag($propposition);
5323 print '</td>';
5324 print '<td class="center tdoverflowmax100" title="'.($propnoteditable ? dol_escape_htmltag($propnoteditable) : '').'">';
5325 print $propenabled ? dol_escape_htmltag($propenabled) : '';
5326 print '</td>';
5327 // Visibility
5328 print '<td class="center tdoverflowmax100" title="'.($propvisible ? dol_escape_htmltag($propvisible) : '0').'">';
5329 print $propvisible ? dol_escape_htmltag($propvisible) : '0';
5330 print '</td>';
5331 // Readonly
5332 print '<td class="center tdoverflowmax100" title="'.($propnoteditable ? dol_escape_htmltag($propnoteditable) : '').'">';
5333 print $propnoteditable ? dol_escape_htmltag($propnoteditable) : '';
5334 print '</td>';
5335 /*print '<td class="center">';
5336 print $propalwayseditable ? dol_escape_htmltag($propalwayseditable) : '';
5337 print '</td>';*/
5338 print '<td class="center">';
5339 print $propsearchall ? '1' : '';
5340 print '</td>';
5341 print '<td class="center">';
5342 print $propisameasure ? dol_escape_htmltag($propisameasure) : '';
5343 print '</td>';
5344 print '<td class="center tdoverflowmax100" title="'.($propcss ? dol_escape_htmltag($propcss) : '').'">';
5345 print $propcss ? dol_escape_htmltag($propcss) : '';
5346 print '</td>';
5347 print '<td class="center tdoverflowmax100" title="'.($propcssview ? dol_escape_htmltag($propcssview) : '').'">';
5348 print $propcssview ? dol_escape_htmltag($propcssview) : '';
5349 print '</td>';
5350 print '<td class="center tdoverflowmax100" title="'.($propcsslist ? dol_escape_htmltag($propcsslist) : '').'">';
5351 print $propcsslist ? dol_escape_htmltag($propcsslist) : '';
5352 print '</td>';
5353 // Key for tooltop
5354 print '<td class="tdoverflowmax150" title="'.($prophelp ? dol_escape_htmltag($prophelp) : '').'">';
5355 print $prophelp ? dol_escape_htmltag($prophelp) : '';
5356 print '</td>';
5357 print '<td class="center">';
5358 print $propshowoncombobox ? dol_escape_htmltag($propshowoncombobox) : '';
5359 print '</td>';
5360 /*print '<td class="center">';
5361 print $propdisabled?$propdisabled:'';
5362 print '</td>';*/
5363 print '<td class="center">';
5364 print $propvalidate ? dol_escape_htmltag($propvalidate) : '';
5365 print '</td>';
5366 print '<td class="tdoverflowmax200">';
5367 print '<span title="'.dol_escape_htmltag($propcomment).'">';
5368 print dol_escape_htmltag($propcomment);
5369 print '</span>';
5370 print '</td>';
5371 if (empty($conf->main_checkbox_left_column)) {
5372 print '<td class="center minwidth75 tdstickyright tdstickyghostwhite">';
5373 if ($propname != 'rowid') {
5374 print '<a class="editfielda reposition marginleftonly marginrighttonly paddingright paddingleft" href="'.$_SERVER["PHP_SELF"].'?action=editproperty&token='.newToken().'&propertykey='.urlencode($propname).'&tab='.urlencode($tab).'&module='.urlencode($module).'&tabobj='.urlencode($tabobj).'">'.img_edit().'</a>';
5375 print '<a class="reposition marginleftonly marginrighttonly paddingright paddingleft" href="'.$_SERVER["PHP_SELF"].'?action=deleteproperty&token='.newToken().'&propertykey='.urlencode($propname).'&tab='.urlencode($tab).'&module='.urlencode($module).'&tabobj='.urlencode($tabobj).'">'.img_delete().'</a>';
5376 }
5377 print '</td>';
5378 }
5379 }
5380 print '</tr>';
5381 }
5382 } else {
5383 if ($tab == 'specifications') {
5384 if ($action != 'editfile' || empty($file)) {
5385 print '<span class="opacitymedium">'.$langs->trans("SpecDefDesc").'</span><br>';
5386 print '<br>';
5387
5388 $specs = dol_dir_list(dol_buildpath($modulelowercase.'/doc', 0), 'files', 1, '(\.md|\.asciidoc)$', array('\/temp\/'));
5389
5390 foreach ($specs as $spec) {
5391 $pathtofile = $modulelowercase.'/doc/'.$spec['relativename'];
5392 $format = 'asciidoc';
5393 if (preg_match('/\.md$/i', $spec['name'])) {
5394 $format = 'markdown';
5395 }
5396 print '<span class="fa fa-file"></span> '.$langs->trans("SpecificationFile").' : <strong class="wordbreak">'.$pathtofile.'</strong>';
5397 print ' <a href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&token='.newToken().'&format='.$format.'&file='.urlencode($pathtofile).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
5398 print '<br>';
5399 }
5400 } else {
5401 // Use MD or asciidoc
5402
5403 //print $langs->trans("UseAsciiDocFormat").'<br>';
5404
5405 $fullpathoffile = dol_buildpath($file, 0);
5406
5407 $content = file_get_contents($fullpathoffile);
5408
5409 // New module
5410 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
5411 print '<input type="hidden" name="token" value="'.newToken().'">';
5412 print '<input type="hidden" name="action" value="savefile">';
5413 print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
5414 print '<input type="hidden" name="tab" value="'.$tab.'">';
5415 print '<input type="hidden" name="module" value="'.$module.'">';
5416
5417 $doleditor = new DolEditor('editfilecontent', $content, '', 300, 'Full', 'In', true, false, 'ace', 0, '99%');
5418 print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ? GETPOST('format', 'aZ09') : 'html'));
5419 print '<br>';
5420 print '<center>';
5421 print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
5422 print ' &nbsp; ';
5423 print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
5424 print '</center>';
5425
5426 print '</form>';
5427 }
5428 }
5429 $langs->load("errors");
5430 print '<tr><td><span class="warning">'.$langs->trans('ErrorModuleBuilderNoFieldProperty').'</warning></td></tr>';
5431 }
5432 print '</table>';
5433 print '</div>';
5434
5435 print '</form>';
5436 } else {
5437 $langs->load("errors");
5438 print '<span class="warning">'.$langs->trans('ErrorModuleBuilderFailedToInit', $tabobj, (string) $db).'</warning>';
5439 }
5440 } catch (Exception $e) {
5441 print 'ee';
5442 print $e->getMessage();
5443 print 'ff';
5444 }
5445 } else {
5446 if (empty($forceddirread)) {
5447 $fullpathoffile = dol_buildpath($file, 0);
5448 } else {
5449 $fullpathoffile = $dirread.'/'.$file;
5450 }
5451
5452 $content = file_get_contents($fullpathoffile);
5453
5454 // New module
5455 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
5456 print '<input type="hidden" name="token" value="'.newToken().'">';
5457 print '<input type="hidden" name="action" value="savefile">';
5458 print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
5459 print '<input type="hidden" name="tab" value="'.$tab.'">';
5460 print '<input type="hidden" name="tabobj" value="'.dol_escape_htmltag($tabobj).'">';
5461 print '<input type="hidden" name="module" value="'.$module.($forceddirread ? '@'.$dirread : '').'">';
5462
5463 $doleditor = new DolEditor('editfilecontent', $content, '', 300, 'Full', 'In', true, false, 'ace', 0, '99%');
5464 print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ? GETPOST('format', 'aZ09') : 'html'));
5465 print '<br>';
5466 print '<center>';
5467 print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
5468 print ' &nbsp; ';
5469 print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
5470 print '</center>';
5471
5472 print '</form>';
5473 }
5474 }
5475
5476 print dol_get_fiche_end(); // Level 3
5477 }
5478
5479 if ($tab == 'dictionaries') {
5480 print '<!-- tab=dictionaries -->'."\n";
5481 $pathtofile = $listofmodules[dol_strtolower($module)]['moduledescriptorrelpath'];
5482
5483 $dicts = $moduleobj->dictionaries;
5484
5485 if ($action == 'deletedict') {
5486 $formconfirm = $form->formconfirm(
5487 $_SERVER["PHP_SELF"].'?dictionnarykey='.urlencode((string) (GETPOSTINT('dictionnarykey'))).'&tab='.urlencode((string) ($tab)).'&module='.urlencode((string) ($module)),
5488 $langs->trans('Delete'),
5489 $langs->trans('Confirm Delete Dictionnary', GETPOST('dictionnarykey', 'alpha')),
5490 'confirm_deletedictionary',
5491 '',
5492 0,
5493 1
5494 );
5495 print $formconfirm;
5496 }
5497
5498 if ($action != 'editfile' || empty($file)) {
5499 print '<span class="opacitymedium">';
5500 $htmlhelp = $langs->trans("DictionariesDefDescTooltip", '{s1}');
5501 $htmlhelp = str_replace('{s1}', '<a target="adminbis" class="nofocusvisible" href="'.DOL_URL_ROOT.'/admin/dict.php">'.$langs->trans('Setup').' - '.$langs->trans('Dictionaries').'</a>', $htmlhelp);
5502 print $form->textwithpicto($langs->trans("DictionariesDefDesc"), $htmlhelp, 1, 'help', '', 0, 2, 'helpondesc').'<br>';
5503 print '</span>';
5504 print '<br>';
5505
5506 print '<span class="fa fa-file"></span> '.$langs->trans("DescriptorFile").' : <strong class="wordbreak">'.$pathtofile.'</strong>';
5507 print ' <a class="editfielda paddingleft paddingright" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&token='.newToken().'&format=php&file='.urlencode($pathtofile).'&find=DICTIONARIES">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
5508 print '<br>';
5509 if (is_array($dicts) && !empty($dicts)) {
5510 print '<span class="fa fa-file"></span> '.$langs->trans("LanguageFile").' :</span> ';
5511 print '<strong class="wordbreak">'.$dicts['langs'].'</strong>';
5512 print '<br>';
5513 }
5514 print '<br>';
5515
5516 $head3 = array();
5517 $h = 0;
5518
5519 // Dir for module
5520 //$dir = $dirread.'/'.$modulelowercase.'/class';
5521
5522 $head3[$h][0] = $_SERVER["PHP_SELF"].'?tab=dictionaries&module='.$module.($forceddirread ? '@'.$dirread : '').'&tabdic=newdictionary';
5523 $head3[$h][1] = '<span class="valignmiddle text-plus-circle">'.$langs->trans("NewDictionary").'</span><span class="fa fa-plus-circle valignmiddle paddingleft"></span>';
5524 $head3[$h][2] = 'newdictionary';
5525 $h++;
5526
5527 // Scan for object class files
5528 //$listofobject = dol_dir_list($dir, 'files', 0, '\.class\.php$');
5529
5530 $firstdicname = '';
5531 // if (!empty($dicts['tabname'])) {
5532 // foreach ($dicts['tabname'] as $key => $dic) {
5533 // $dicname = $dic;
5534 // $diclabel = $dicts['tablib'][$key];
5535
5536 // if (empty($firstdicname)) {
5537 // $firstdicname = $dicname;
5538 // }
5539
5540 // $head3[$h][0] = $_SERVER["PHP_SELF"].'?tab=dictionaries&module='.$module.($forceddirread ? '@'.$dirread : '').'&tabdic='.$dicname;
5541 // $head3[$h][1] = $diclabel;
5542 // $head3[$h][2] = $dicname;
5543 // $h++;
5544 // }
5545 // }
5546
5547 // if ($h > 1) {
5548 // $head3[$h][0] = $_SERVER["PHP_SELF"].'?tab=dictionaries&module='.$module.($forceddirread ? '@'.$dirread : '').'&tabdic=deletedictionary';
5549 // $head3[$h][1] = $langs->trans("DangerZone");
5550 // $head3[$h][2] = 'deletedictionary';
5551 // $h++;
5552 // }
5553
5554 // If tabobj was not defined, then we check if there is one obj. If yes, we force on it, if no, we will show tab to create new objects.
5555 // if ($tabdic == 'newdicifnodic') {
5556 // if ($firstdicname) {
5557 // $tabdic = $firstdicname;
5558 // } else {
5559 // $tabdic = 'newdictionary';
5560 // }
5561 // }
5562 //print dol_get_fiche_head($head3, $tabdic, '', -1, ''); // Level 3
5563
5564
5565 $newdict = dolGetButtonTitle($langs->trans('NewDictionary'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/modulebuilder/index.php?tab=dictionaries&module='.urlencode($module).'&tabdic=newdictionary');
5566 print_barre_liste($langs->trans("ListOfDictionariesEntries"), 0, $_SERVER["PHP_SELF"], '', '', '', '', 0, '', '', 0, $newdict, '', 0, 0, 0, 1);
5567
5568 if ($tabdic != 'newdictionary') {
5569 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
5570 print '<input type="hidden" name="token" value="'.newToken().'">';
5571 print '<input type="hidden" name="action" value="addDictionary">';
5572 print '<input type="hidden" name="tab" value="dictionaries">';
5573 print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
5574 print '<input type="hidden" name="tabdic" value="'.dol_escape_htmltag($tabdic).'">';
5575
5576 print '<div class="div-table-responsive">';
5577 print '<table class="noborder">';
5578
5579 print '<tr class="liste_titre">';
5580 print_liste_field_titre("#", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder, 'thsticky thstickygrey ');
5581 print_liste_field_titre("Table", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
5582 print_liste_field_titre("Label", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
5583 print_liste_field_titre("SQL", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
5584 print_liste_field_titre("SQLSort", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
5585 print_liste_field_titre("FieldsView", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
5586 print_liste_field_titre("FieldsEdit", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
5587 print_liste_field_titre("FieldsInsert", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
5588 print_liste_field_titre("Rowid", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
5589 print_liste_field_titre("Condition", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
5590 print_liste_field_titre("", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
5591 print "</tr>\n";
5592
5593 if (!empty($dicts) && is_array($dicts) && !empty($dicts['tabname']) && is_array($dicts['tabname'])) {
5594 $i = 0;
5595 $maxi = count($dicts['tabname']);
5596 while ($i < $maxi) {
5597 if ($action == 'editdict' && $i == GETPOSTINT('dictionnarykey') - 1) {
5598 print '<tr class="oddeven">';
5599 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
5600 print '<input type="hidden" name="token" value="'.newToken().'">';
5601 print '<input type="hidden" name="tab" value="dictionaries">';
5602 print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
5603 print '<input type="hidden" name="action" value="updatedictionary">';
5604 print '<input type="hidden" name="dictionnarykey" value="'.($i + 1).'">';
5605
5606 print '<td class="tdsticky tdstickygray">';
5607 print($i + 1);
5608 print '</td>';
5609
5610 print '<td>';
5611 print '<input type="text" name="tabname" value="'.$dicts['tabname'][$i].'" readonly class="tdstickygray">';
5612 print '</td>';
5613
5614 print '<td>';
5615 print '<input type="text" name="tablib" value="'.$dicts['tablib'][$i].'">';
5616 print '</td>';
5617
5618 print '<td>';
5619 print '<input type="text" name="tabsql" value="'.$dicts['tabsql'][$i].'" readonly class="tdstickygray">';
5620 print '</td>';
5621
5622 print '<td>';
5623 print '<select name="tabsqlsort">';
5624 print '<option value="'.dol_escape_htmltag($dicts['tabsqlsort'][$i]).'">'.$dicts['tabsqlsort'][$i].'</option>';
5625 print '</select>';
5626 print '</td>';
5627
5628 print '<td><select name="tabfield" >';
5629 print '<option value="'.dol_escape_htmltag($dicts['tabfield'][$i]).'">'.$dicts['tabfield'][$i].'</option>';
5630 print '</select></td>';
5631
5632 print '<td><select name="tabfieldvalue" >';
5633 print '<option value="'.dol_escape_htmltag($dicts['tabfieldvalue'][$i]).'">'.$dicts['tabfieldvalue'][$i].'</option>';
5634 print '</select></td>';
5635
5636 print '<td><select name="tabfieldinsert" >';
5637 print '<option value="'.dol_escape_htmltag($dicts['tabfieldinsert'][$i]).'">'.$dicts['tabfieldinsert'][$i].'</option>';
5638 print '</select></td>';
5639
5640 print '<td>';
5641 print '<input type="text" name="tabrowid" value="'.dol_escape_htmltag($dicts['tabrowid'][$i]).'" readonly class="tdstickygray">';
5642 print '</td>';
5643
5644 print '<td>';
5645 print '<input type="text" name="tabcond" value="'.dol_escape_htmltag((empty($dicts['tabcond'][$i]) ? 'disabled' : 'enabled')).'" readonly class="tdstickygray">';
5646 print '</td>';
5647
5648 print '<td class="center minwidth75 tdstickyright tdstickyghostwhite">';
5649 print '<input id ="updatedict" class="reposition button smallpaddingimp" type="submit" name="updatedict" value="'.$langs->trans("Modify").'"/>';
5650 print '<br>';
5651 print '<input class="reposition button button-cancel smallpaddingimp" type="submit" name="cancel" value="'.$langs->trans("Cancel").'"/>';
5652 print '</td>';
5653
5654 print '</form>';
5655 print '</tr>';
5656 } else {
5657 print '<tr class="oddeven">';
5658
5659 print '<td class="tdsticky tdstickygray">';
5660 print($i + 1);
5661 print '</td>';
5662
5663 print '<td>';
5664 print $dicts['tabname'][$i];
5665 print '</td>';
5666
5667 print '<td>';
5668 print $dicts['tablib'][$i];
5669 print '</td>';
5670
5671 print '<td>';
5672 print $dicts['tabsql'][$i];
5673 print '</td>';
5674
5675 print '<td>';
5676 print $dicts['tabsqlsort'][$i];
5677 print '</td>';
5678
5679 print '<td>';
5680 print $dicts['tabfield'][$i];
5681 print '</td>';
5682
5683 print '<td>';
5684 print $dicts['tabfieldvalue'][$i];
5685 print '</td>';
5686
5687 print '<td>';
5688 print $dicts['tabfieldinsert'][$i];
5689 print '</td>';
5690
5691 print '<td >';
5692 print $dicts['tabrowid'][$i];
5693 print '</td>';
5694
5695 print '<td >';
5696 print $dicts['tabcond'][$i];
5697 print '</td>';
5698
5699 print '<td class="center minwidth75 tdstickyright tdstickyghostwhite">';
5700 print '<a class="editfielda reposition marginleftonly marginrighttonly paddingright paddingleft" href="'.$_SERVER["PHP_SELF"].'?action=editdict&token='.newToken().'&dictionnarykey='.urlencode((string) ($i + 1)).'&tab='.urlencode((string) ($tab)).'&module='.urlencode((string) ($module)).'">'.img_edit().'</a>';
5701 print '<a class="marginleftonly marginrighttonly paddingright paddingleft" href="'.$_SERVER["PHP_SELF"].'?action=deletedict&token='.newToken().'&dictionnarykey='.urlencode((string) ($i + 1)).'&tab='.urlencode((string) ($tab)).'&module='.urlencode((string) ($module)).'">'.img_delete().'</a>';
5702 print '</td>';
5703
5704 print '</tr>';
5705 }
5706 $i++;
5707 }
5708 } else {
5709 print '<tr><td colspan="11"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
5710 }
5711
5712 print '</table>';
5713 print '</div>';
5714
5715 print '</form>';
5716 }
5717
5718 if ($tabdic == 'newdictionary') {
5719 // New dic tab
5720 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
5721 print '<input type="hidden" name="token" value="'.newToken().'">';
5722 print '<input type="hidden" name="action" value="initdic">';
5723 print '<input type="hidden" name="tab" value="dictionaries">';
5724 print '<input type="hidden" name="tabdic" value="'.$tabdic.'">';
5725
5726 print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
5727
5728 print '<span class="opacitymedium">'.$langs->trans("EnterNameOfDictionaryDesc").'</span><br><br>';
5729
5730 print dol_get_fiche_head();
5731 print '<table class="border centpercent">';
5732 print '<tbody>';
5733 print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans("Table").'</td><td><input type="text" name="dicname" maxlength="64" value="'.dol_escape_htmltag(GETPOST('dicname', 'alpha') ? GETPOST('dicname', 'alpha') : $modulename).'" placeholder="'.dol_escape_htmltag($langs->trans("DicKey")).'" autofocus></td>';
5734 print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans("Label").'</td><td><input type="text" name="label" value="'.dol_escape_htmltag(GETPOST('label', 'alpha')).'"></td></tr>';
5735 print '<tr><td class="titlefieldcreate">'.$langs->trans("SQL").'</td><td><input type="text" style="width:50%;" name="sql" value="'.dol_escape_htmltag(GETPOST('sql', 'alpha')).'"></td></tr>';
5736 print '<tr><td class="titlefieldcreate">'.$langs->trans("SQLSort").'</td><td><input type="text" name="sqlsort" value="'.dol_escape_htmltag(GETPOST('sqlsort', 'alpha')).'" readonly></td></tr>';
5737 print '<tr><td class="titlefieldcreate">'.$langs->trans("FieldsView").'</td><td><input type="text" name="field" value="'.dol_escape_htmltag(GETPOST('field', 'alpha')).'"></td></tr>';
5738 print '<tr><td class="titlefieldcreate">'.$langs->trans("FieldsEdit").'</td><td><input type="text" name="fieldvalue" value="'.dol_escape_htmltag(GETPOST('fieldvalue', 'alpha')).'"></td></tr>';
5739 print '<tr><td class="titlefieldcreate">'.$langs->trans("FieldsInsert").'</td><td><input type="text" name="fieldinsert" value="'.dol_escape_htmltag(GETPOST('fieldinsert', 'alpha')).'"></td></tr>';
5740 print '<tr><td class="titlefieldcreate">'.$langs->trans("Rowid").'</td><td><input type="text" name="rowid" value="'.dol_escape_htmltag(GETPOST('rowid', 'alpha')).'"></td></tr>';
5741 print '<tr></tr>';
5742 print '</tbody></table>';
5743 print '<input type="submit" class="button" name="create" value="'.dol_escape_htmltag($langs->trans("GenerateCode")).'"'.($dirins ? '' : ' disabled="disabled"').'>';
5744 print '<input id="cancel" type="submit" class="button" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
5745 print dol_get_fiche_end();
5746 print '</form>';
5747 print '<script>
5748 $(document).ready(function() {
5749 $("input[name=\'dicname\']").on("blur", function() {
5750 if ($(this).val().length > 0) {
5751 $("input[name=\'label\']").val($(this).val());
5752 $("input[name=\'sql\']").val("SELECT f.rowid as rowid, f.code, f.label, f.active FROM llx_c_" + $(this).val() + " as f");
5753 $("input[name=\'sqlsort\']").val("label ASC");
5754 $("input[name=\'field\']").val("code,label");
5755 $("input[name=\'fieldvalue\']").val("code,label");
5756 $("input[name=\'fieldinsert\']").val("code,label");
5757 $("input[name=\'rowid\']").val("rowid");
5758 } else {
5759 $("input[name=\'label\']").val("");
5760 $("input[name=\'sql\']").val("");
5761 $("input[name=\'sqlsort\']").val("");
5762 $("input[name=\'field\']").val("");
5763 $("input[name=\'fieldvalue\']").val("");
5764 $("input[name=\'fieldinsert\']").val("");
5765 $("input[name=\'rowid\']").val("");
5766 }
5767 });
5768 $("input[id=\'cancel\']").click(function() {
5769 window.history.back();
5770 });
5771 });
5772 </script>';
5773
5774 /*print '<br>';
5775 print '<br>';
5776 print '<br>';
5777 print '<span class="opacitymedium">'.$langs->trans("or").'</span>';
5778 print '<br>';
5779 print '<br>';
5780 //print '<input type="checkbox" name="initfromtablecheck"> ';
5781 print $langs->trans("InitStructureFromExistingTable");
5782 print '<input type="text" name="initfromtablename" value="" placeholder="'.$langs->trans("TableName").'">';
5783 print '<input type="submit" class="button smallpaddingimp" name="createtablearray" value="'.dol_escape_htmltag($langs->trans("GenerateCode")).'"'.($dirins ? '' : ' disabled="disabled"').'>';
5784 print '<br>';
5785 */
5786 } elseif ($tabdic == 'deletedictionary') {
5787 // Delete dic tab
5788 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
5789 print '<input type="hidden" name="token" value="'.newToken().'">';
5790 print '<input type="hidden" name="action" value="confirm_deletedictionary">';
5791 print '<input type="hidden" name="tab" value="dictionaries">';
5792 print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
5793
5794 print $langs->trans("EnterNameOfDictionnaryToDeleteDesc").'<br><br>';
5795
5796 print '<input type="text" name="dicname" value="'.dol_escape_htmltag($modulename).'" placeholder="'.dol_escape_htmltag($langs->trans("DicKey")).'">';
5797 print '<input type="submit" class="button smallpaddingimp" name="delete" value="'.dol_escape_htmltag($langs->trans("Delete")).'"'.($dirins ? '' : ' disabled="disabled"').'>';
5798 print '</form>';
5799 }
5800
5801 print dol_get_fiche_end();
5802 } else {
5803 $fullpathoffile = dol_buildpath($file, 0);
5804
5805 $content = file_get_contents($fullpathoffile);
5806
5807 // New module
5808 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
5809 print '<input type="hidden" name="token" value="'.newToken().'">';
5810 print '<input type="hidden" name="action" value="savefile">';
5811 print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
5812 print '<input type="hidden" name="tab" value="'.$tab.'">';
5813 print '<input type="hidden" name="module" value="'.$module.'">';
5814
5815 $posCursor = (empty($find)) ? array() : array('find' => $find);
5816 $doleditor = new DolEditor('editfilecontent', $content, '', 300, 'Full', 'In', true, false, 'ace', 0, '99%', 0, $posCursor);
5817 print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ? GETPOST('format', 'aZ09') : 'html'));
5818 print '<br>';
5819 print '<center>';
5820 print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
5821 print ' &nbsp; ';
5822 print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
5823 print '</center>';
5824
5825 print '</form>';
5826 }
5827 }
5828
5829 if ($tab == 'menus') {
5830 print '<!-- tab=menus -->'."\n";
5831 $pathtofile = $listofmodules[dol_strtolower($module)]['moduledescriptorrelpath'];
5832 $dirins = $listofmodules[dol_strtolower($module)]['moduledescriptorrootpath'];
5833 $destdir = $dirins.'/'.dol_strtolower($module);
5834 $listofobject = dol_dir_list($destdir.'/class', 'files', 0, '\.class\.php$');
5835 $objects = dolGetListOfObjectClasses($destdir);
5836
5837 $leftmenus = array();
5838
5839 $menus = $moduleobj->menu;
5840
5841 $permissions = $moduleobj->rights;
5842 $crud = array('read' => 'CRUDRead', 'write' => 'CRUDCreateWrite', 'delete' => 'Delete');
5843
5844 //grouped permissions
5845 $groupedRights = array();
5846 foreach ($permissions as $right) {
5847 $key = $right[4];
5848 if (!isset($groupedRights[$key])) {
5849 $groupedRights[$key] = array();
5850 }
5851 $groupedRights[$key][] = $right;
5852 }
5853 $groupedRights_json = json_encode($groupedRights);
5854
5855 if ($action == 'deletemenu') {
5856 $formconfirms = $form->formconfirm(
5857 $_SERVER["PHP_SELF"].'?menukey='.urlencode((string) (GETPOSTINT('menukey'))).'&tab='.urlencode((string) ($tab)).'&module='.urlencode((string) ($module)),
5858 $langs->trans('Delete'),
5859 ($menus[GETPOST('menukey')]['fk_menu'] === 'fk_mainmenu='.dol_strtolower($module) ? $langs->trans('Warning: you will delete all menus linked to this one.', GETPOSTINT('menukey')) : $langs->trans('Confirm Delete Menu', GETPOSTINT('menukey'))),
5860 'confirm_deletemenu',
5861 '',
5862 0,
5863 1
5864 );
5865 print $formconfirms;
5866 }
5867 if ($action != 'editfile' || empty($file)) {
5868 print '<span class="opacitymedium">';
5869 $htmlhelp = $langs->trans("MenusDefDescTooltip", '{s1}');
5870 $htmlhelp = str_replace('{s1}', '<a target="adminbis" class="nofocusvisible" href="'.DOL_URL_ROOT.'/admin/menus/index.php">'.$langs->trans('Setup').' - '.$langs->trans('Menus').'</a>', $htmlhelp);
5871 print $form->textwithpicto($langs->trans("MenusDefDesc"), $htmlhelp, 1, 'help', '', 0, 2, 'helpondesc').'<br>';
5872 print '</span>';
5873 print '<br>';
5874
5875 // Links to editable files
5876 print '<span class="fa fa-file"></span> '.$langs->trans("DescriptorFile").' : <strong class="wordbreak">'.$pathtofile.'</strong>';
5877 print ' <a class="editfielda paddingleft paddingright" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&token='.newToken().'&format=php&file='.urlencode($pathtofile).'&find=TOPMENU">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
5878 print '<br>';
5879
5880 // Search all files of modules mentioned by menu
5881 $listODifferentUrlsInMenu = array();
5882 foreach ($menus as $obj) {
5883 if (preg_match('/^\/'.preg_quote(dol_strtolower($module), '/').'\//', $obj['url']) && !empty($pathoffile)) {
5884 if (!empty($listODifferentUrlsInMenu[$pathoffile])) { // Test to avoid to show same file twice.
5885 continue;
5886 }
5887 $pathtofile = $obj['url'];
5888 $listODifferentUrlsInMenu[$pathoffile] = $pathtofile;
5889 print '<span class="fa fa-file"></span> '.$langs->trans("PageLinkedByAMenuEntry").' : <strong class="wordbreak">'.$pathtofile.'</strong>';
5890 print ' <a class="editfielda paddingleft paddingright" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&token='.newToken().'&format=php&file='.urlencode($pathtofile).'&find=TOPMENU">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
5891 print '<br>';
5892 }
5893 }
5894
5895
5896 print '<br>';
5897 print load_fiche_titre($langs->trans("ListOfMenusEntries"), '', '');
5898
5899 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
5900 print '<input type="hidden" name="token" value="'.newToken().'">';
5901 print '<input type="hidden" name="action" value="addmenu">';
5902 print '<input type="hidden" name="tab" value="menus">';
5903 print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
5904 print '<input type="hidden" name="tabobj" value="'.dol_escape_htmltag($tabobj).'">';
5905
5906 print '<div class="div-table-responsive">';
5907 print '<table class="noborder small">';
5908
5909 $htmltextenabled = '<u>'.$langs->trans("Examples").':</u><br>';
5910 $htmltextenabled .= '1 <span class="opacitymedium">(module always enabled)</span><br>';
5911 $htmltextenabled .= '0 <span class="opacitymedium">(module always disabled)</span><br>';
5912 $htmltextenabled .= 'isModEnabled(\''.dol_escape_htmltag(dol_strtolower($module)).'\') <span class="opacitymedium">(enabled when module is enabled)</span>';
5913 $htmltextperms = '<u>'.$langs->trans("Examples").':</u><br>';
5914 $htmltextperms .= '1 <span class="opacitymedium">(access always allowed)</span><br>';
5915 $htmltextperms .= '$user->hasright(\''.dol_escape_htmltag(dol_strtolower($module)).'\', \'myobject\', \'read\') <span class="opacitymedium">(access allowed if user has permission module->object->read)</span>';
5916
5917 print '<tr class="liste_titre">';
5918 print_liste_field_titre("#", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder, 'center tdsticky tdstickygray ');
5919 print_liste_field_titre("Position", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
5920 print_liste_field_titre("Title", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder, 'center');
5921 print_liste_field_titre("LinkToParentMenu", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder, 'minwidth100 ');
5922 print_liste_field_titre("mainmenu", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
5923 print_liste_field_titre("leftmenu", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
5924 print_liste_field_titre("URL", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder, '', $langs->transnoentitiesnoconv('DetailUrl'));
5925 print_liste_field_titre("LanguageFile", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
5926 print_liste_field_titre("Position", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder, 'right ');
5927 print_liste_field_titre("Enabled", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder, 'center ', $langs->trans('DetailEnabled').'<br><br>'.$htmltextenabled);
5928 print_liste_field_titre("Rights", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder, '', $langs->trans('DetailRight').'<br><br>'.$htmltextperms);
5929 print_liste_field_titre("Target", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder, '', $langs->trans('DetailTarget'));
5930 print_liste_field_titre("MenuForUsers", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder, 'center minwidth100 ', $langs->trans('DetailUser'));
5931 print_liste_field_titre("", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder, 'center ', $langs->trans(''));
5932 print "</tr>\n";
5933
5934 $r = count($menus) + 1;
5935 // for adding menu on module
5936 print '<tr>';
5937 print '<td class="center tdsticky tdstickygray"><input type="hidden" readonly class="center maxwidth50" name="propenabled" value="#"></td>';
5938 print '<td class="center">';
5939 print '<select class="maxwidth50" name="type">';
5940 print '<option value="">'.$langs->trans("........").'</option><option value="'.dol_escape_htmltag("left").'">left</option><option value="'.dol_escape_htmltag("top").'">top</option>';
5941 print '</select></td>';
5942 print '<td class="left"><input type="text" class="left maxwidth100" name="titre" value="'.dol_escape_htmltag(GETPOST('titre', 'alpha')).'"></td>';
5943 print '<td class="left">';
5944 print '<select name="fk_menu">';
5945 print '<option value="">'.$langs->trans("........").'</option>';
5946 foreach ($menus as $obj) {
5947 if ($obj['type'] == 'left' && !empty($obj['leftmenu'])) {
5948 print "<option value=".dol_strtolower($obj['leftmenu']).">".$obj['leftmenu']."</option>";
5949 }
5950 }
5951 print '</select>';
5952 print '</td>';
5953 print '<td class="left"><input type="text" class="left maxwidth50" name="mainmenu" value="'.(empty(GETPOST('mainmenu')) ? dol_strtolower($module) : dol_escape_htmltag(GETPOST('mainmenu', 'alpha'))).'"></td>';
5954 print '<td class="center"><input id="leftmenu" type="text" class="left maxwidth50" name="leftmenu" value="'.dol_escape_htmltag(GETPOST('leftmenu', 'alpha')).'"></td>';
5955 // URL
5956 print '<td class="left"><input id="url" type="text" class="left maxwidth100" name="url" value="'.dol_escape_htmltag(GETPOST('url', 'alpha')).'"></td>';
5957 print '<td class="left"><input type="text" class="left maxwidth75" name="langs" value="'.dol_strtolower($module).'@'.dol_strtolower($module).'" readonly></td>';
5958 // Position
5959 print '<td class="center"><input type="text" class="center maxwidth50 tdstickygray" name="position" value="'.(1000 + $r).'" readonly></td>';
5960 // Enabled
5961 print '<td class="center">';
5962 print '<input type="enabled" class="maxwidth125" value="'.dol_escape_htmltag(GETPOSTISSET('enabled') ? GETPOST('enabled') : 'isModEnabled(\''.$module.'\')').'">';
5963 /*
5964 print '<select class="maxwidth" name="enabled">';
5965 print '<option value="1" selected>'.$langs->trans("Show").'</option>';
5966 print '<option value="0">'.$langs->trans("Hide").'</option>';
5967 print '</select>';
5968 */
5969 print '</td>';
5970 // Perms
5971 print '<td class="left">';
5972 print '<select class="maxwidth" name="objects" id="objects">';
5973 print '<option value=""></option>';
5974 if (is_array($objects)) {
5975 foreach ($objects as $value) {
5976 print '<option value="'.dol_strtolower($value).'">'.dol_escape_htmltag(dol_strtolower($value)).'</option>';
5977 }
5978 }
5979 print '</select>';
5980 print '<select class="maxwidth hideobject" name="perms" id="perms">';
5981 print '</select>';
5982 print '</td>';
5983 print '<td class="center"><input type="text" class="center maxwidth50" name="target" value="'.dol_escape_htmltag(GETPOST('target', 'alpha')).'"></td>';
5984 print '<td class="center"><select class="maxwidth10" name="user"><option value="2">'.$langs->trans("AllMenus").'</option><option value="0">'.$langs->trans("Internal").'</option><option value="1">'.$langs->trans("External").'</option></select></td>';
5985
5986 print '<td class="center minwidth75 tdstickyright tdstickyghostwhite">';
5987 print '<input type="submit" class="button" name="add" value="'.$langs->trans("Add").'">';
5988 print '</td>';
5989 print '</tr>';
5990 // end form for add menu
5991
5992 //var_dump($menus);
5993
5994 // Loop on each menu entry
5995 if (count($menus)) {
5996 $i = 0;
5997 foreach ($menus as $menu) {
5998 $i++;
5999 //for get parent in menu
6000 $string = dol_escape_htmltag($menu['fk_menu']);
6001 $value = dol_substr($string, strpos($string, 'fk_leftmenu=') + dol_strlen('fk_leftmenu='));
6002
6003 $propFk_menu = !empty($menu['fk_menu']) ? $menu['fk_menu'] : GETPOST('fk_menu');
6004 $propTitre = !empty($menu['titre']) ? $menu['titre'] : GETPOST('titre');
6005 $propMainmenu = !empty($menu['mainmenu']) ? $menu['mainmenu'] : GETPOST('mainmenu');
6006 $propLeftmenu = !empty($menu['leftmenu']) ? $menu['leftmenu'] : GETPOST('leftmenu');
6007 $propUrl = !empty($menu['url']) ? $menu['url'] : GETPOST('url', 'alpha');
6008 $propPerms = !empty($menu['perms']) ? $menu['perms'] : GETPOST('perms');
6009 $propUser = !empty($menu['user']) ? $menu['user'] : GETPOST('user');
6010 $propTarget = !empty($menu['target']) ? $menu['target'] : GETPOST('target');
6011 $propEnabled = !empty($menu['enabled']) ? $menu['enabled'] : GETPOST('enabled');
6012
6013 $objPerms = (empty($arguments[1]) ? '' : trim($arguments[1]));
6014 $valPerms = (empty($arguments[2]) ? '' : trim($arguments[2]));
6015
6016 //$tabobject = ''; // We can't know what is $tabobject in most cases
6017
6018 if ($action == 'editmenu' && GETPOSTINT('menukey') == $i) {
6019 //var_dump($propPerms);exit;
6020 print '<tr class="oddeven">';
6021 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
6022 print '<input type="hidden" name="token" value="'.newToken().'">';
6023 print '<input type="hidden" name="action" value="update_menu">';
6024 print '<input type="hidden" name="tab" value="menus">';
6025 print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
6026 print '<input type="hidden" name="menukey" value="'.$i.'"/>';
6027 //print '<input type="hidden" name="tabobject" value="'.dol_escape_htmltag($tabobject).'">';
6028 print '<td class="tdsticky tdstickygray">';
6029 print $i;
6030 print '</td>';
6031 // Position (top, left)
6032 print '<td class="center">
6033 <select class="center maxwidth50" name="type">
6034 <option value="'.dol_escape_htmltag($menu['type']).'">
6035 '.dol_escape_htmltag($menu['type']).'
6036 </option>';
6037 print '<option value="'.($menu['type'] == 'left' ? 'top' : 'left').'">';
6038 if ($menu['type'] == 'left') {
6039 print 'top';
6040 } else {
6041 print 'left';
6042 }
6043 print '</option></select></td>';
6044 // Title
6045 print '<td><input type="text" class="left maxwidth100" name="titre" value="'.dol_escape_htmltag($propTitre).'"></td>';
6046 // Parent menu
6047 print '<td>';
6048 /*print '<select name="fk_menu" class="left maxwidth">';
6049 print '<option value="'.dol_escape_htmltag($propFk_menu).'">'.dol_escape_htmltag($value).'</option>';
6050 foreach ($menus as $obj) {
6051 if ($obj['type'] == 'left' && $obj['leftmenu'] != $value && $obj['leftmenu'] != $menu['leftmenu']) {
6052 print "<option value=".dol_strtolower($obj['leftmenu']).">".$obj['leftmenu']."</option>";
6053 }
6054 }
6055 print '</select>';*/
6056 print '<input type="text" name="fk_menu" class="maxwidth150" value="'.dol_escape_htmltag($propFk_menu).'">';
6057 print '</td>';
6058 print '<td><input type="text" class="left maxwidth50" name="mainmenu" value="'.dol_escape_htmltag($propMainmenu).'" readonly></td>';
6059 print '<td><input type="text" class="left maxwidth50" name="leftmenu" value="'.dol_escape_htmltag($propLeftmenu).'" readonly></td>';
6060 // URL
6061 print '<td><input type="text" class="left maxwidth250" name="url" value="'.dol_escape_htmltag($propUrl).'"></td>';
6062 print '<td><input type="text" class="left maxwidth50" name="langs" value="'.dol_strtolower($module).'@'.dol_strtolower($module).'" readonly></td>';
6063 // Position
6064 print '<td class="center"><input type="text" class="center maxwidth50 tdstickygray" name="position" value="'.($menu['position']).'" readonly></td>';
6065 // Enabled
6066 print '<td class="nowraponall">';
6067 print '<input type="text" class="maxwidth125" name="enabled" value="'.dol_escape_htmltag($propEnabled != '' ? $propEnabled : "isModEnabled('".dol_escape_htmltag($module)."')").'">';
6068 $htmltext = '<u>'.$langs->trans("Examples").':</u><br>';
6069 $htmltext .= '1 <span class="opacitymedium">(always enabled)</span><br>';
6070 $htmltext .= '0 <span class="opacitymedium">(always disabled)</span><br>';
6071 $htmltext .= 'isModEnabled(\''.dol_escape_htmltag($module).'\') <span class="opacitymedium">(enabled when module is enabled)</span><br>';
6072 print $form->textwithpicto('', $htmltext);
6073 /*
6074 print '<select class="maxwidth50" name="enabledselect">';
6075 print '<option value="1">1 (always enabled)</option>';
6076 print '<option value="0">0 (always disabled)</option>';
6077 print '<option value="isModEnabled(\''.dol_escape_htmltag($module).'\')" >isModEnabled(\''.dol_escape_htmltag($module).'\')</option>';
6078 print '</select>';
6079 */
6080 print '</td>';
6081 // Permissions
6082 print '<td class="nowraponall">';
6083 print '<input type="text" name="perms" value="'.dol_escape_htmltag($propPerms).'">';
6084 /*
6085 if (!empty($objPerms)) {
6086 print '<input type="hidden" name="objects" value="'.$objPerms.'" />';
6087 print '<select class="center maxwidth50" name="perms">';
6088 if (!empty($valPerms)) {
6089 print '<option selected value="'.dol_escape_htmltag($valPerms).'">'.dol_escape_htmltag($langs->trans($crud[$valPerms])).'</option>';
6090 foreach ($crud as $key => $val) {
6091 if ($valPerms != $key) {
6092 print '<option value="'.dol_escape_htmltag($key).'">'.dol_escape_htmltag($langs->trans($val)).'</option>';
6093 }
6094 }
6095 }
6096 print '</select>';
6097 } else {
6098 print '<select class="center maxwidth50" name="objects">';
6099 print '<option></option>';
6100 foreach ($objects as $obj) {
6101 print '<option value="'.dol_escape_htmltag(dol_strtolower($obj)).'">'.dol_escape_htmltag($obj).'</option>';
6102 }
6103 print '</select>';
6104 print '<select class="center maxwidth50" name="perms">';
6105 foreach ($crud as $key => $val) {
6106 print '<option value="'.dol_escape_htmltag($key).'">'.dol_escape_htmltag($key).'</option>';
6107 }
6108 print '</select>';
6109 }*/
6110 print '</td>';
6111 // Target
6112 print '<td class="center"><input type="text" class="center maxwidth50" name="target" value="'.dol_escape_htmltag($propTarget).'"></td>';
6113 print '<td class="center"><select class="center maxwidth10" name="user"><option value="2">'.$langs->trans("AllMenus").'</option><option value="0">'.$langs->trans("Internal").'</option><option value="1">'.$langs->trans("External").'</option></select></td>';
6114 print '<td class="center minwidth75 tdstickyright tdstickyghostwhite maxwidth75">';
6115 print '<input class="reposition button smallpaddingimp" type="submit" name="edit" value="'.$langs->trans("Modify").'">';
6116 print '<input class="reposition button button-cancel smallpaddingimp" type="submit" name="cancel" value="'.$langs->trans("Cancel").'">';
6117 print '</td>';
6118 print '</form>';
6119 print '</tr>';
6120 } else {
6121 print '<tr class="oddeven">';
6122
6123 print '<td class="tdsticky tdstickygray">';
6124 print $i;
6125 print '</td>';
6126
6127 print '<td class="center">';
6128 print dol_escape_htmltag($menu['type']);
6129 print '</td>';
6130
6131 // Title
6132 print '<td>';
6133 print dol_escape_htmltag($menu['titre']);
6134 print '</td>';
6135
6136 // Parent menu
6137 print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($menu['fk_menu']).'">';
6138 print dol_escape_htmltag($menu['fk_menu']);
6139 print '</td>';
6140
6141 print '<td>';
6142 print dol_escape_htmltag($menu['mainmenu']);
6143 print '</td>';
6144
6145 print '<td>';
6146 print dol_escape_htmltag($menu['leftmenu']);
6147 print '</td>';
6148
6149 print '<td class="tdoverflowmax250" title="'.dol_escape_htmltag($menu['url']).'">';
6150 print dol_escape_htmltag($menu['url']);
6151 print '</td>';
6152
6153 print '<td>';
6154 print dol_escape_htmltag($menu['langs']);
6155 print '</td>';
6156
6157 // Position
6158 print '<td class="center">';
6159 print dol_escape_htmltag((string) $menu['position']);
6160 print '</td>';
6161
6162 // Enabled
6163 print '<td class="tdoverflowmax200" title="'.dol_escape_htmltag($menu['enabled']).'">';
6164 print dol_escape_htmltag($menu['enabled']);
6165 print '</td>';
6166
6167 // Perms
6168 print '<td class="tdoverflowmax200" title="'.dol_escape_htmltag($menu['perms']).'">';
6169 print dol_escape_htmltag($langs->trans($menu['perms']));
6170 print '</td>';
6171
6172 // Target
6173 print '<td class="center tdoverflowmax200" title="'.dol_escape_htmltag($menu['target']).'">';
6174 print dol_escape_htmltag($menu['target']);
6175 print '</td>';
6176
6177 print '<td class="center">';
6178 if ($menu['user'] == 2) {
6179 print $langs->trans("AllMenus");
6180 } elseif ($menu['user'] == 0) {
6181 print $langs->trans('Internal');
6182 } elseif ($menu['user'] == 1) {
6183 print $langs->trans('External');
6184 } else {
6185 print $menu['user']; // should not happen
6186 }
6187 print '</td>';
6188 print '<td class="center minwidth75 tdstickyright tdstickyghostwhite">';
6189 if ($menu['titre'] != 'Module'.$module.'Name') {
6190 print '<a class="editfielda reposition marginleftonly marginrighttonly paddingright paddingleft" href="'.$_SERVER["PHP_SELF"].'?action=editmenu&token='.newToken().'&menukey='.urlencode((string) ($i)).'&tab='.urlencode((string) ($tab)).'&module='.urlencode((string) ($module)).'&tabobj='.urlencode((string) ($tabobj)).'">'.img_edit().'</a>';
6191 print '<a class="deletefielda reposition marginleftonly marginrighttonly paddingright paddingleft" href="'.$_SERVER["PHP_SELF"].'?action=deletemenu&token='.newToken().'&menukey='.urlencode((string) ($i - 1)).'&tab='.urlencode((string) ($tab)).'&module='.urlencode((string) ($module)).'">'.img_delete().'</a>';
6192 }
6193 print '</td>';
6194 }
6195 print '</tr>';
6196 }
6197 } else {
6198 print '<tr><td colspan="14"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
6199 }
6200
6201 print '</table>';
6202 print '</div>';
6203 print '</form>';
6204
6205
6206 print '<script>
6207 $(document).ready(function() {
6208 //for fill in auto url
6209 $("#leftmenu").on("input", function() {
6210 var inputLeftMenu = $("#leftmenu").val();
6211 if (inputLeftMenu !== \'\') {
6212 var url = \''.dol_escape_js(dol_strtolower($module)).'\' + inputLeftMenu + \'.php\';
6213 $("#url").val(url);
6214 }else {
6215 $("#url").val("");
6216 }
6217 });
6218
6219 var groupedRights = ' . $groupedRights_json . ';
6220 var objectsSelect = $("select[id=\'objects\']");
6221 var permsSelect = $("select[id=\'perms\']");
6222
6223 objectsSelect.change(function() {
6224 var selectedObject = $(this).val();
6225
6226 permsSelect.empty();
6227
6228 var rights = groupedRights[selectedObject];
6229
6230 if (rights) {
6231 for (var i = 0; i < rights.length; i++) {
6232 var right = rights[i];
6233 var option = $("<option></option>").attr("value", right[5]).text(right[5]);
6234 permsSelect.append(option);
6235 }
6236 } else {
6237 var option = $("<option></option>").attr("value", "read").text("read");
6238 permsSelect.append(option);
6239 }
6240
6241 if (selectedObject !== "" && selectedObject !== null && rights) {
6242 permsSelect.show();
6243 } else {
6244 permsSelect.hide();
6245 }
6246 if (objectsSelect.val() === "" || objectsSelect.val() === null) {
6247 permsSelect.hide();
6248 }
6249 });
6250 });
6251 </script>';
6252
6253 // display permissions for each object
6254 } else {
6255 $fullpathoffile = dol_buildpath($file, 0);
6256
6257 $content = file_get_contents($fullpathoffile);
6258
6259 // New module
6260 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
6261 print '<input type="hidden" name="token" value="'.newToken().'">';
6262 print '<input type="hidden" name="action" value="savefile">';
6263 print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
6264 print '<input type="hidden" name="tab" value="'.$tab.'">';
6265 print '<input type="hidden" name="module" value="'.$module.'">';
6266
6267 $posCursor = (empty($find)) ? array() : array('find' => $find);
6268 $doleditor = new DolEditor('editfilecontent', $content, '', 300, 'Full', 'In', true, false, 'ace', 0, '99%', 0, $posCursor);
6269 print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ? GETPOST('format', 'aZ09') : 'html'));
6270 print '<br>';
6271 print '<center>';
6272 print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
6273 print ' &nbsp; ';
6274 print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
6275 print '</center>';
6276
6277 print '</form>';
6278 }
6279 }
6280
6281 if ($tab == 'permissions') {
6282 print '<!-- tab=permissions -->'."\n";
6283 $pathtofile = $listofmodules[dol_strtolower($module)]['moduledescriptorrelpath'];
6284
6285 $perms = $moduleobj->rights;
6286
6287 // Get list of existing objects
6288 $dir = $dirread.'/'.$modulelowercase.'/class';
6289 $listofobject = dol_dir_list($dir, 'files', 0, '\.class\.php$');
6290 $objects = array('myobject');
6291 $reg = array();
6292 foreach ($listofobject as $fileobj) {
6293 $tmpcontent = file_get_contents($fileobj['fullname']);
6294 if (preg_match('/class\s+([^\s]*)\s+extends\s+CommonObject/ims', $tmpcontent, $reg)) {
6295 $objects[$fileobj['fullname']] = $reg[1];
6296 }
6297 }
6298
6299 // declared select list for actions and labels permissions
6300 $crud = array('read' => 'CRUDRead', 'write' => 'CRUDCreateWrite', 'delete' => 'Delete');
6301 $labels = array("Read objects of ".$module, "Create/Update objects of ".$module, "Delete objects of ".$module);
6302
6303 $action = GETPOST('action', 'alpha');
6304
6305 if ($action == 'deleteright') {
6306 $formconfirm = $form->formconfirm(
6307 $_SERVER["PHP_SELF"].'?permskey='.urlencode((string) (GETPOSTINT('permskey'))).'&tab='.urlencode((string) ($tab)).'&module='.urlencode((string) ($module)).'&tabobj='.urlencode((string) ($tabobj)),
6308 $langs->trans('Delete'),
6309 $langs->trans('Confirm Delete Right', GETPOST('permskey', 'alpha')),
6310 'confirm_deleteright',
6311 '',
6312 0,
6313 1
6314 );
6315 print $formconfirm;
6316 }
6317
6318 if ($action != 'editfile' || empty($file)) {
6319 print '<!-- Tab to manage permissions -->'."\n";
6320 print '<span class="opacitymedium">';
6321 $htmlhelp = $langs->trans("PermissionsDefDescTooltip");
6322 //$htmlhelp = $langs->trans("PermissionsDefDescTooltip", '{s1}');
6323 //$htmlhelp = str_replace('{s1}', '<a target="adminbis" class="nofocusvisible" href="'.DOL_URL_ROOT.'/admin/perms.php">'.$langs->trans('DefaultRights').'</a>', $htmlhelp);
6324 print $form->textwithpicto($langs->trans("PermissionsDefDesc"), $htmlhelp, 1, 'help', '', 0, 2, 'helpondesc').'<br>';
6325 print '</span>';
6326 print '<br>';
6327
6328 print '<span class="fa fa-file"></span> '.$langs->trans("DescriptorFile").' : <strong class="wordbreak">'.$pathtofile.'</strong>';
6329 print ' <a class="editfielda paddingleft paddingright" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&token='.newToken().'&format=php&file='.urlencode($pathtofile).'&find=PERMISSIONS">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
6330 print '<br>';
6331
6332 print '<br>';
6333 print load_fiche_titre($langs->trans("ListOfPermissionsDefined"), '', '');
6334
6335 print '<!-- form to add permissions -->'."\n";
6336 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
6337 print '<input type="hidden" name="token" value="'.newToken().'">';
6338 print '<input type="hidden" name="action" value="addright">';
6339 print '<input type="hidden" name="tab" value="permissions">';
6340 print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
6341 print '<input type="hidden" name="tabobj" value="'.dol_escape_htmltag($tabobj).'">';
6342
6343 print '<div class="div-table-responsive">';
6344 print '<table class="noborder">';
6345
6346 print '<tr class="liste_titre">';
6347 print_liste_field_titre("ID", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder, "center");
6348 print_liste_field_titre("Object", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder, "center");
6349 print_liste_field_titre("CRUD", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder, "center");
6350 print_liste_field_titre("Label", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder, "center");
6351 print_liste_field_titre("", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder, "center");
6352 print "</tr>\n";
6353
6354 //form for add new right
6355 print '<tr class="small">';
6356 print '<td><input type="hidden" readonly name="id" class="width75" value="0"></td>';
6357
6358 print '<td><select class="minwidth100" name="permissionObj" id="permissionObj">';
6359 print '<option value=""></option>';
6360 foreach ($objects as $obj) {
6361 if ($obj != 'myobject') {
6362 print '<option value="'.$obj.'">'.$obj.'</option>';
6363 }
6364 }
6365 print '</select></td>';
6366
6367 print '<td><select class="maxwidth75" name="crud" id="crud">';
6368 print '<option value=""></option>';
6369 foreach ($crud as $key => $val) {
6370 print '<option value="'.$key.'">'.$langs->trans($val).'</option>';
6371 }
6372 print '</td>';
6373
6374 print '<td >';
6375 print '<input type="text" name="label" id="label" class="minwidth200">';
6376 print '</td>';
6377
6378 print '<td class="center minwidth75 tdstickyright tdstickyghostwhite">';
6379 print '<input type="submit" class="button" name="add" value="'.$langs->trans("Add").'">';
6380 print '</td>';
6381 print '</tr>';
6382
6383 if (count($perms)) {
6384 $i = 0;
6385 foreach ($perms as $perm) {
6386 $i++;
6387
6388 // section for editing right
6389 if ($action == 'edit_right' && $perm[0] == GETPOSTINT('permskey')) {
6390 print '<tr class="oddeven">';
6391 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST" name="modifPerms">';
6392 print '<input type="hidden" name="token" value="'.newToken().'">';
6393 print '<input type="hidden" name="tab" value="permissions">';
6394 print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
6395 print '<input type="hidden" name="tabobj" value="'.dol_escape_htmltag($tabobj).'">';
6396 print '<input type="hidden" name="action" value="update_right">';
6397 print '<input type="hidden" name="counter" value="'.$i.'">';
6398
6399 print '<input type="hidden" name="permskey" value="'.$perm[0].'">';
6400
6401 print '<td class="tdsticky tdstickygray">';
6402 print '<input class="width75" type="text" readonly value="'.dol_escape_htmltag($perm[0]).'"/>';
6403 print '</td>';
6404
6405 print '<td>';
6406 print '<select name="crud">';
6407 print '<option value="'.dol_escape_htmltag($perm[5]).'">'.$langs->trans($perm[5]).'</option>';
6408 foreach ($crud as $i => $x) {
6409 if ($perm[5] != $i) {
6410 print '<option value="'.$i.'">'.$langs->trans(dol_ucfirst($x)).'</option>';
6411 }
6412 }
6413 print '</select>';
6414 print '</td>';
6415
6416 print '<td><select name="permissionObj" >';
6417 print '<option value="'.dol_escape_htmltag($perm[4]).'">'.dol_ucfirst($perm[4]).'</option>';
6418 print '</select></td>';
6419
6420 print '<td>';
6421 print '<input type="text" name="label" value="'.dol_escape_htmltag($perm[1]).'">';
6422 print '</td>';
6423
6424 print '<td class="center minwidth75 tdstickyright tdstickyghostwhite">';
6425 print '<input id ="modifyPerm" class="reposition button smallpaddingimp" type="submit" name="modifyright" value="'.$langs->trans("Modify").'"/>';
6426 print '<br>';
6427 print '<input class="reposition button button-cancel smallpaddingimp" type="submit" name="cancel" value="'.$langs->trans("Cancel").'"/>';
6428 print '</td>';
6429
6430 print '</form>';
6431 print '</tr>';
6432 } else {
6433 // $perm can be module->object->crud or module->crud
6434 print '<tr class="oddeven">';
6435
6436 print '<td>';
6437 print dol_escape_htmltag($perm[0]);
6438 print '</td>';
6439
6440 print '<td>';
6441 if (in_array($perm[5], array('lire', 'read', 'creer', 'write', 'effacer', 'delete'))) {
6442 print dol_escape_htmltag(dol_ucfirst($perm[4]));
6443 } else {
6444 print ''; // No particular object
6445 }
6446 print '</td>';
6447
6448 print '<td>';
6449 if (in_array($perm[5], array('lire', 'read', 'creer', 'write', 'effacer', 'delete'))) {
6450 print dol_ucfirst($langs->trans($perm[5]));
6451 } else {
6452 print dol_ucfirst($langs->trans($perm[4]));
6453 }
6454 print '</td>';
6455
6456 print '<td>';
6457 print $langs->trans($perm[1]);
6458 print '</td>';
6459
6460 print '<td class="center minwidth75 tdstickyright tdstickyghostwhite">';
6461 print '<a class="editfielda reposition marginleftonly marginrighttonly paddingright paddingleft" href="'.$_SERVER["PHP_SELF"].'?action=edit_right&token='.newToken().'&permskey='.urlencode($perm[0]).'&tab='.urlencode($tab).'&module='.urlencode($module).'&tabobj='.urlencode($tabobj).'">'.img_edit().'</a>';
6462 print '<a class="marginleftonly marginrighttonly paddingright paddingleft" href="'.$_SERVER["PHP_SELF"].'?action=deleteright&token='.newToken().'&permskey='.urlencode((string) ($i)).'&tab='.urlencode((string) ($tab)).'&module='.urlencode((string) ($module)).'&tabobj='.urlencode((string) ($tabobj)).'">'.img_delete().'</a>';
6463
6464 print '</td>';
6465
6466 print '</tr>';
6467 }
6468 }
6469 } else {
6470 print '<tr><td colspan="5"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
6471 }
6472
6473 print '</table>';
6474 print '</div>';
6475
6476 print '</form>';
6477 print '<script>
6478 function updateInputField() {
6479 value1 = $("#crud").val();
6480 value2 = $("#permissionObj").val();
6481
6482 // Check if both selections are made
6483 if (value1 && value2) {
6484 switch(value1.toLowerCase()){
6485 case "read":
6486 $("#label").val("Read "+value2+" object of '.dol_ucfirst($module).'")
6487 break;
6488 case "write":
6489 $("#label").val("Create/Update "+value2+" object of '.dol_ucfirst($module).'")
6490 break;
6491 case "delete":
6492 $("#label").val("Delete "+value2+" object of '.dol_ucfirst($module).'")
6493 break;
6494 default:
6495 $("#label").val("")
6496 }
6497 }
6498 }
6499
6500 $("#crud, #permissionObj").change(function(){
6501 console.log("We change selection");
6502 updateInputField();
6503 });
6504
6505 </script>';
6506 } else {
6507 $fullpathoffile = dol_buildpath($file, 0);
6508
6509 $content = file_get_contents($fullpathoffile);
6510
6511 // New module
6512 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
6513 print '<input type="hidden" name="token" value="'.newToken().'">';
6514 print '<input type="hidden" name="action" value="savefile">';
6515 print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
6516 print '<input type="hidden" name="tab" value="'.$tab.'">';
6517 print '<input type="hidden" name="module" value="'.$module.'">';
6518
6519 $posCursor = (empty($find)) ? array() : array('find' => $find);
6520 $doleditor = new DolEditor('editfilecontent', $content, '', 300, 'Full', 'In', true, false, 'ace', 0, '99%', 0, $posCursor);
6521 print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ? GETPOST('format', 'aZ09') : 'html'));
6522 print '<br>';
6523 print '<center>';
6524 print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
6525 print ' &nbsp; ';
6526 print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
6527 print '</center>';
6528
6529 print '</form>';
6530 }
6531 }
6532
6533 if ($tab == 'hooks') {
6534 print '<!-- tab=hooks -->'."\n";
6535 if ($action != 'editfile' || empty($file)) {
6536 print '<span class="opacitymedium">'.$langs->trans("HooksDefDesc").'</span><br>';
6537 print '<br>';
6538
6539 print '<table>';
6540
6541 $pathtofile = $listofmodules[dol_strtolower($module)]['moduledescriptorrelpath'];
6542 print '<tr><td>';
6543 print '<span class="fa fa-file"></span> '.$langs->trans("DescriptorFile").' : <strong class="wordbreak">'.$pathtofile.'</strong>';
6544 print '</td><td>';
6545 print '<a class="editfielda paddingleft paddingright" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&token='.newToken().'&format=php&file='.urlencode($pathtofile).'&find=HOOKSCONTEXTS">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
6546 print '</td></tr>';
6547
6548 print '<tr><td>';
6549 $pathtohook = dol_strtolower($module).'/class/actions_'.dol_strtolower($module).'.class.php';
6550 print '<span class="fa fa-file"></span> '.$langs->trans("HooksFile").' : ';
6551 if (dol_is_file($dirins.'/'.$pathtohook)) {
6552 print '<strong class="wordbreak">'.$pathtohook.'</strong>';
6553 print '</td>';
6554 print '<td><a class="editfielda paddingleft paddingright" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&token='.newToken().'&format=php&file='.urlencode($pathtohook).'">'.img_picto($langs->trans("Edit"), 'edit').'</a> ';
6555 print '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=confirm_removefile&token='.newToken().'&file='.urlencode($pathtohook).'">'.img_picto($langs->trans("Delete"), 'delete').'</a></td>';
6556 } else {
6557 print '<span class="opacitymedium">'.$langs->trans("FileNotYetGenerated").'</span>';
6558 print '<a href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=inithook&token='.newToken().'&format=php&file='.urlencode($pathtohook).'">'.img_picto('Generate', 'generate', 'class="paddingleft"').'</td>';
6559 print '<td></td>';
6560 }
6561 print '</tr>';
6562 } else {
6563 $fullpathoffile = dol_buildpath($file, 0);
6564
6565 $content = file_get_contents($fullpathoffile);
6566
6567 // New module
6568 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
6569 print '<input type="hidden" name="token" value="'.newToken().'">';
6570 print '<input type="hidden" name="action" value="savefile">';
6571 print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
6572 print '<input type="hidden" name="tab" value="'.$tab.'">';
6573 print '<input type="hidden" name="module" value="'.$module.'">';
6574
6575 $posCursor = (empty($find)) ? array() : array('find' => $find);
6576 $doleditor = new DolEditor('editfilecontent', $content, '', 300, 'Full', 'In', true, false, 'ace', 0, '99%', 0, $posCursor);
6577 print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ? GETPOST('format', 'aZ09') : 'html'));
6578 print '<br>';
6579 print '<center>';
6580 print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
6581 print ' &nbsp; ';
6582 print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
6583 print '</center>';
6584
6585 print '</form>';
6586 }
6587 }
6588
6589 if ($tab == 'triggers') {
6590 print '<!-- tab=triggers -->'."\n";
6591 require_once DOL_DOCUMENT_ROOT.'/core/class/interfaces.class.php';
6592
6593 $interfaces = new Interfaces($db);
6594 $triggers = $interfaces->getTriggersList(array('/'.dol_strtolower($module).'/core/triggers'));
6595
6596 if ($action != 'editfile' || empty($file)) {
6597 print '<span class="opacitymedium">'.$langs->trans("TriggerDefDesc").'</span><br>';
6598 print '<br>';
6599
6600 print '<table>';
6601
6602 $pathtofile = $listofmodules[dol_strtolower($module)]['moduledescriptorrelpath'];
6603 print '<tr><td>';
6604 print '<span class="fa fa-file"></span> '.$langs->trans("DescriptorFile").' : <strong class="wordbreak">'.$pathtofile.'</strong>';
6605 print '</td><td>';
6606 print '<a class="editfielda paddingleft paddingright" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&token='.newToken().'&format=php&file='.urlencode($pathtofile).'&find=module_parts">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
6607 print '</td></tr>';
6608
6609 if (!empty($triggers)) {
6610 foreach ($triggers as $trigger) {
6611 $pathtofile = $trigger['relpath'];
6612
6613 print '<tr><td>';
6614 print '<span class="fa fa-file"></span> '.$langs->trans("TriggersFile").' : <strong class="wordbreak">'.$pathtofile.'</strong>';
6615 print '</td><td><a class="editfielda paddingleft paddingright" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&token='.newToken().'&format=php&file='.urlencode($pathtofile).'">'.img_picto($langs->trans("Edit"), 'edit').'</a></td>';
6616 print '<td><a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=confirm_removefile&token='.newToken().'&file='.urlencode($pathtofile).'">'.img_picto($langs->trans("Delete"), 'delete').'</a></td>';
6617 print '</tr>';
6618 }
6619 } else {
6620 print '<tr><td>';
6621 print '<span class="fa fa-file"></span> '.$langs->trans("TriggersFile");
6622 print ' : <span class="opacitymedium">'.$langs->trans("FileNotYetGenerated").'</span>';
6623 print '<a href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=inittrigger&token='.newToken().'&format=php">'.img_picto('Generate', 'generate', 'class="paddingleft"').'</a></td>';
6624 print '<td></td>';
6625 print '</tr>';
6626 }
6627
6628 print '</table>';
6629 } else {
6630 $fullpathoffile = dol_buildpath($file, 0);
6631
6632 $content = file_get_contents($fullpathoffile);
6633
6634 // New module
6635 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
6636 print '<input type="hidden" name="token" value="'.newToken().'">';
6637 print '<input type="hidden" name="action" value="savefile">';
6638 print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
6639 print '<input type="hidden" name="tab" value="'.$tab.'">';
6640 print '<input type="hidden" name="module" value="'.$module.'">';
6641
6642 $posCursor = (empty($find)) ? array() : array('find' => $find);
6643 $doleditor = new DolEditor('editfilecontent', $content, '', 300, 'Full', 'In', true, false, 'ace', 0, '99%', 0, $posCursor);
6644 print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ? GETPOST('format', 'aZ09') : 'html'));
6645 print '<br>';
6646 print '<center>';
6647 print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
6648 print ' &nbsp; ';
6649 print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
6650 print '</center>';
6651
6652 print '</form>';
6653 }
6654 }
6655
6656 if ($tab == 'css') {
6657 print '<!-- tab=css -->'."\n";
6658 if ($action != 'editfile' || empty($file)) {
6659 print '<span class="opacitymedium">'.$langs->trans("CSSDesc").'</span><br>';
6660 print '<br>';
6661
6662 print '<table>';
6663
6664 print '<tr><td>';
6665 $pathtohook = dol_strtolower($module).'/css/'.dol_strtolower($module).'.css.php';
6666 print '<span class="fa fa-file"></span> '.$langs->trans("CSSFile").' : ';
6667 if (dol_is_file($dirins.'/'.$pathtohook)) {
6668 print '<strong class="wordbreak">'.$pathtohook.'</strong>';
6669 print '</td><td><a class="editfielda paddingleft paddingright" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&token='.newToken().'&format=php&file='.urlencode($pathtohook).'">'.img_picto($langs->trans("Edit"), 'edit').'</a></td>';
6670 print '</td><td><a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=confirm_removefile&token='.newToken().'&format='.$format.'&file='.urlencode($pathtohook).'">'.img_picto($langs->trans("Delete"), 'delete').'</a></td>';
6671 } else {
6672 print '<span class="opacitymedium">'.$langs->trans("FileNotYetGenerated").'</span>';
6673 print '</td><td><a href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=initcss&token='.newToken().'&format=php&file='.urlencode($pathtohook).'">'.img_picto('Generate', 'generate', 'class="paddingleft"').'</a></td>';
6674 }
6675 print '</tr>';
6676 } else {
6677 $fullpathoffile = dol_buildpath($file, 0);
6678
6679 $content = file_get_contents($fullpathoffile);
6680
6681 // New module
6682 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
6683 print '<input type="hidden" name="token" value="'.newToken().'">';
6684 print '<input type="hidden" name="action" value="savefile">';
6685 print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
6686 print '<input type="hidden" name="tab" value="'.$tab.'">';
6687 print '<input type="hidden" name="module" value="'.$module.'">';
6688
6689 $doleditor = new DolEditor('editfilecontent', $content, '', 300, 'Full', 'In', true, false, 'ace', 0, '99%');
6690 print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ? GETPOST('format', 'aZ09') : 'html'));
6691 print '<br>';
6692 print '<center>';
6693 print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
6694 print ' &nbsp; ';
6695 print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
6696 print '</center>';
6697
6698 print '</form>';
6699 }
6700 }
6701
6702 if ($tab == 'js') {
6703 print '<!-- tab=js -->'."\n";
6704 if ($action != 'editfile' || empty($file)) {
6705 print '<span class="opacitymedium">'.$langs->trans("JSDesc").'</span><br>';
6706 print '<br>';
6707
6708 print '<table>';
6709
6710 print '<tr><td>';
6711 $pathtohook = dol_strtolower($module).'/js/'.dol_strtolower($module).'.js.php';
6712 print '<span class="fa fa-file"></span> '.$langs->trans("JSFile").' : ';
6713 if (dol_is_file($dirins.'/'.$pathtohook)) {
6714 print '<strong class="wordbreak">'.$pathtohook.'</strong>';
6715 print '</td><td><a class="editfielda paddingleft paddingright" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&token='.newToken().'&format=php&file='.urlencode($pathtohook).'">'.img_picto($langs->trans("Edit"), 'edit').'</a></td>';
6716 print '</td><td><a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=confirm_removefile&token='.newToken().'&file='.urlencode($pathtohook).'">'.img_picto($langs->trans("Delete"), 'delete').'</a></td>';
6717 } else {
6718 print '<span class="opacitymedium">'.$langs->trans("FileNotYetGenerated").'</span>';
6719 print '</td><td><a href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=initjs&token='.newToken().'&format=php&file='.urlencode($pathtohook).'">'.img_picto('Generate', 'generate', 'class="paddingleft"').'</a></td>';
6720 }
6721 print '</tr>';
6722 } else {
6723 $fullpathoffile = dol_buildpath($file, 0);
6724
6725 $content = file_get_contents($fullpathoffile);
6726
6727 // New module
6728 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
6729 print '<input type="hidden" name="token" value="'.newToken().'">';
6730 print '<input type="hidden" name="action" value="savefile">';
6731 print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
6732 print '<input type="hidden" name="tab" value="'.$tab.'">';
6733 print '<input type="hidden" name="module" value="'.$module.'">';
6734
6735 $doleditor = new DolEditor('editfilecontent', $content, '', 300, 'Full', 'In', true, false, 'ace', 0, '99%');
6736 print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ? GETPOST('format', 'aZ09') : 'html'));
6737 print '<br>';
6738 print '<center>';
6739 print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
6740 print ' &nbsp; ';
6741 print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
6742 print '</center>';
6743
6744 print '</form>';
6745 }
6746 }
6747
6748 if ($tab == 'widgets') {
6749 print '<!-- tab=widgets -->'."\n";
6750 require_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
6751
6752 $widgets = ModeleBoxes::getWidgetsList(array('/'.dol_strtolower($module).'/core/boxes'));
6753
6754 if ($action != 'editfile' || empty($file)) {
6755 print '<span class="opacitymedium">'.$langs->trans("WidgetDesc").'</span><br>';
6756 print '<br>';
6757
6758 print '<table>';
6759 if (!empty($widgets)) {
6760 foreach ($widgets as $widget) {
6761 $pathtofile = $widget['relpath'];
6762
6763 print '<tr><td><span class="fa fa-file"></span> '.$langs->trans("WidgetFile").' : <strong class="wordbreak">'.$pathtofile.'</strong>';
6764 print '</td><td><a class="editfielda paddingleft paddingright" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&token='.newToken().'&format=php&file='.urlencode($pathtofile).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
6765 print '</td><td><a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=confirm_removefile&token='.newToken().'&file='.urlencode($pathtofile).'">'.img_picto($langs->trans("Delete"), 'delete').'</a></td>';
6766 print '</tr>';
6767 }
6768 } else {
6769 print '<tr><td><span class="fa fa-file"></span> '.$langs->trans("WidgetFile").' : <span class="opacitymedium">'.$langs->trans("NoWidget").'</span>';
6770 print '</td><td><a href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=initwidget&token='.newToken().'&format=php">'.img_picto('Generate', 'generate', 'class="paddingleft"').'</a>';
6771 print '</td></tr>';
6772 }
6773 print '</table>';
6774 } else {
6775 $fullpathoffile = dol_buildpath($file, 0);
6776
6777 $content = file_get_contents($fullpathoffile);
6778
6779 // New module
6780 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
6781 print '<input type="hidden" name="token" value="'.newToken().'">';
6782 print '<input type="hidden" name="action" value="savefile">';
6783 print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
6784 print '<input type="hidden" name="tab" value="'.$tab.'">';
6785 print '<input type="hidden" name="module" value="'.$module.'">';
6786
6787 $doleditor = new DolEditor('editfilecontent', $content, '', 300, 'Full', 'In', true, false, 'ace', 0, '99%');
6788 print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ? GETPOST('format', 'aZ09') : 'html'));
6789 print '<br>';
6790 print '<center>';
6791 print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
6792 print ' &nbsp; ';
6793 print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
6794 print '</center>';
6795
6796 print '</form>';
6797 }
6798 }
6799
6800 if ($tab == 'emailings') {
6801 print '<!-- tab=emailings -->'."\n";
6802 require_once DOL_DOCUMENT_ROOT.'/core/modules/mailings/modules_mailings.php';
6803
6804 $emailingselectors = MailingTargets::getEmailingSelectorsList(array('/'.dol_strtolower($module).'/core/modules/mailings'));
6805
6806 if ($action != 'editfile' || empty($file)) {
6807 print '<span class="opacitymedium">'.$langs->trans("EmailingSelectorDesc").'</span><br>';
6808 print '<br>';
6809
6810 print '<table>';
6811 if (!empty($emailingselectors)) {
6812 foreach ($emailingselectors as $emailingselector) {
6813 $pathtofile = $emailingselector['relpath'];
6814
6815 print '<tr><td><span class="fa fa-file"></span> '.$langs->trans("EmailingSelectorFile").' : <strong class="wordbreak">'.$pathtofile.'</strong>';
6816 print '</td><td><a class="editfielda paddingleft paddingright" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&token='.newToken().'&format=php&file='.urlencode($pathtofile).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
6817 print '</td><td><a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=confirm_removefile&token='.newToken().'&file='.urlencode($pathtofile).'">'.img_picto($langs->trans("Delete"), 'delete').'</a></td>';
6818 print '</tr>';
6819 }
6820 } else {
6821 print '<tr><td><span class="fa fa-file"></span> '.$langs->trans("EmailingSelectorFile").' : <span class="opacitymedium">'.$langs->trans("NoEmailingSelector").'</span>';
6822 print '</td><td><a href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=initemailing&token='.newToken().'&format=php">'.img_picto('Generate', 'generate', 'class="paddingleft"').'</a>';
6823 print '</td></tr>';
6824 }
6825 print '</table>';
6826 } else {
6827 $fullpathoffile = dol_buildpath($file, 0);
6828
6829 $content = file_get_contents($fullpathoffile);
6830
6831 // New module
6832 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
6833 print '<input type="hidden" name="token" value="'.newToken().'">';
6834 print '<input type="hidden" name="action" value="savefile">';
6835 print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
6836 print '<input type="hidden" name="tab" value="'.$tab.'">';
6837 print '<input type="hidden" name="module" value="'.$module.'">';
6838
6839 $doleditor = new DolEditor('editfilecontent', $content, '', 300, 'Full', 'In', true, false, 'ace', 0, '99%');
6840 print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ? GETPOST('format', 'aZ09') : 'html'));
6841 print '<br>';
6842 print '<center>';
6843 print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
6844 print ' &nbsp; ';
6845 print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
6846 print '</center>';
6847
6848 print '</form>';
6849 }
6850 }
6851
6852 if ($tab == 'exportimport') {
6853 print '<!-- tab=exportimport -->'."\n";
6854 $pathtofile = $listofmodules[dol_strtolower($module)]['moduledescriptorrelpath'];
6855
6856 $exportlist = $moduleobj->export_label;
6857 $importlist = $moduleobj->import_label;
6858
6859 if ($action != 'editfile' || empty($file)) {
6860 print '<span class="opacitymedium">'.$langs->transnoentities('ImportExportProfiles').'</span><br>';
6861 print '<br>';
6862
6863 print '<span class="fa fa-file"></span> '.$langs->trans("DescriptorFile").' ('.$langs->trans("ExportsArea").') : <strong class="wordbreak">'.$pathtofile.'</strong>';
6864 print ' <a class="editfielda paddingleft paddingright" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&token='.newToken().'&format=php&file='.urlencode($pathtofile).'&find=EXPORT">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
6865 print '<br>';
6866 print '<span class="fa fa-file"></span> '.$langs->trans("DescriptorFile").' ('.$langs->trans("ImportArea").') : <strong class="wordbreak">'.$pathtofile.'</strong>';
6867 print ' <a class="editfielda paddingleft paddingright" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&token='.newToken().'&format=php&file='.urlencode($pathtofile).'&find=IMPORT">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
6868 print '<br>';
6869 } else {
6870 $fullpathoffile = dol_buildpath($file, 0);
6871
6872 $content = file_get_contents($fullpathoffile);
6873
6874 // New module
6875 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
6876 print '<input type="hidden" name="token" value="'.newToken().'">';
6877 print '<input type="hidden" name="action" value="savefile">';
6878 print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
6879 print '<input type="hidden" name="tab" value="'.$tab.'">';
6880 print '<input type="hidden" name="module" value="'.$module.'">';
6881
6882 $posCursor = (empty($find)) ? array() : array('find' => $find);
6883 $doleditor = new DolEditor('editfilecontent', $content, '', 300, 'Full', 'In', true, false, 'ace', 0, '99%', 0, $posCursor);
6884 print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ? GETPOST('format', 'aZ09') : 'html'));
6885 print '<br>';
6886 print '<center>';
6887 print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
6888 print ' &nbsp; ';
6889 print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
6890 print '</center>';
6891
6892 print '</form>';
6893 }
6894 }
6895
6896 if ($tab == 'cli') {
6897 print '<!-- tab=cli -->'."\n";
6898 $clifiles = array();
6899 $i = 0;
6900
6901 $dircli = array('/'.dol_strtolower($module).'/scripts');
6902
6903 foreach ($dircli as $reldir) {
6904 $dir = dol_buildpath($reldir, 0);
6905 $newdir = dol_osencode($dir);
6906
6907 // Check if directory exists (we do not use dol_is_dir to avoid loading files.lib.php at each call)
6908 if (!dol_is_dir($newdir)) {
6909 continue;
6910 }
6911
6912 $handle = opendir($newdir);
6913
6914 if (is_resource($handle)) {
6915 while (($tmpfile = readdir($handle)) !== false) {
6916 if (is_readable($newdir.'/'.$tmpfile) && preg_match('/^(.+)\.php/', $tmpfile, $reg)) {
6917 if (preg_match('/\.back$/', $tmpfile)) {
6918 continue;
6919 }
6920
6921 $clifiles[$i]['relpath'] = preg_replace('/^\//', '', $reldir).'/'.$tmpfile;
6922
6923 $i++;
6924 }
6925 }
6926 closedir($handle);
6927 }
6928 }
6929
6930 if ($action != 'editfile' || empty($file)) {
6931 print '<span class="opacitymedium">'.$langs->trans("CLIDesc").'</span><br>';
6932 print '<br>';
6933
6934 print '<table>';
6935 if (!empty($clifiles)) {
6936 foreach ($clifiles as $clifile) {
6937 $pathtofile = $clifile['relpath'];
6938
6939 print '<tr><td><span class="fa fa-file"></span> '.$langs->trans("CLIFile").' : <strong class="wordbreak">'.$pathtofile.'</strong>';
6940 print '</td><td><a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&token='.newToken().'&format=php&file='.urlencode($pathtofile).'">'.img_picto($langs->trans("Edit"), 'edit').'</a></td>';
6941 print '<td><a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=confirm_removefile&token='.newToken().'&file='.urlencode($pathtofile).'">'.img_picto($langs->trans("Delete"), 'delete').'</a></td>';
6942 print '</tr>';
6943 }
6944 } else {
6945 print '<tr><td><span class="fa fa-file"></span> '.$langs->trans("CLIFile").' : <span class="opacitymedium">'.$langs->trans("FileNotYetGenerated").'</span>';
6946 print '</td><td><a href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=initcli&token='.newToken().'&format=php">'.img_picto('Generate', 'generate', 'class="paddingleft"').'</a>';
6947 print '</td></tr>';
6948 }
6949 print '</table>';
6950 } else {
6951 $fullpathoffile = dol_buildpath($file, 0);
6952
6953 $content = file_get_contents($fullpathoffile);
6954
6955 // New module
6956 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
6957 print '<input type="hidden" name="token" value="'.newToken().'">';
6958 print '<input type="hidden" name="action" value="savefile">';
6959 print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
6960 print '<input type="hidden" name="tab" value="'.$tab.'">';
6961 print '<input type="hidden" name="module" value="'.$module.'">';
6962
6963 $doleditor = new DolEditor('editfilecontent', $content, '', 300, 'Full', 'In', true, false, 'ace', 0, '99%');
6964 print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ? GETPOST('format', 'aZ09') : 'html'));
6965 print '<br>';
6966 print '<center>';
6967 print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
6968 print ' &nbsp; ';
6969 print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
6970 print '</center>';
6971
6972 print '</form>';
6973 }
6974 }
6975
6976 if ($tab == 'cron') {
6977 print '<!-- tab=cron -->'."\n";
6978 $pathtofile = $listofmodules[dol_strtolower($module)]['moduledescriptorrelpath'];
6979
6980 $cronjobs = $moduleobj->cronjobs;
6981
6982 if ($action != 'editfile' || empty($file)) {
6983 print '<span class="opacitymedium">'.str_replace('{s1}', '<a target="adminbis" class="nofocusvisible" href="'.DOL_URL_ROOT.'/cron/list.php">'.$langs->transnoentities('CronList').'</a>', $langs->trans("CronJobDefDesc", '{s1}')).'</span><br>';
6984 print '<br>';
6985
6986 print '<span class="fa fa-file"></span> '.$langs->trans("DescriptorFile").' : <strong class="wordbreak">'.$pathtofile.'</strong>';
6987 print ' <a class="editfielda paddingleft paddingright" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&token='.newToken().'&format=php&file='.urlencode($pathtofile).'&find=CRON">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
6988 print '<br>';
6989
6990 print '<br>';
6991 print load_fiche_titre($langs->trans("CronJobProfiles"), '', '');
6992
6993 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
6994 print '<input type="hidden" name="token" value="'.newToken().'">';
6995 print '<input type="hidden" name="action" value="addproperty">';
6996 print '<input type="hidden" name="tab" value="objects">';
6997 print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
6998 print '<input type="hidden" name="tabobj" value="'.dol_escape_htmltag($tabobj).'">';
6999
7000 print '<div class="div-table-responsive">';
7001 print '<table class="noborder">';
7002
7003 print '<tr class="liste_titre">';
7004 print_liste_field_titre("CronLabel", $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder);
7005 print_liste_field_titre("CronTask", '', '', "", $param, '', $sortfield, $sortorder);
7006 print_liste_field_titre("CronFrequency", '', "", "", $param, '', $sortfield, $sortorder);
7007 print_liste_field_titre("StatusAtInstall", $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder);
7008 print_liste_field_titre("Comment", $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder);
7009 print "</tr>\n";
7010
7011 if (count($cronjobs)) {
7012 foreach ($cronjobs as $cron) {
7013 print '<tr class="oddeven">';
7014
7015 print '<td>';
7016 print $cron['label'];
7017 print '</td>';
7018
7019 print '<td>';
7020 $texttoshow = '';
7021 if ($cron['jobtype'] == 'method') {
7022 $text = $langs->trans("CronClass");
7023 $texttoshow = $langs->trans('CronModule').': '.$module.'<br>';
7024 $texttoshow .= $langs->trans('CronClass').': '.$cron['class'].'<br>';
7025 $texttoshow .= $langs->trans('CronObject').': '.$cron['objectname'].'<br>';
7026 $texttoshow .= $langs->trans('CronMethod').': '.$cron['method'];
7027 $texttoshow .= '<br>'.$langs->trans('CronArgs').': '.$cron['parameters'];
7028 $texttoshow .= '<br>'.$langs->trans('Comment').': '.$langs->trans($cron['comment']);
7029 } elseif ($cron['jobtype'] == 'command') {
7030 $text = $langs->trans('CronCommand');
7031 $texttoshow = $langs->trans('CronCommand').': '.dol_trunc($cron['command']);
7032 $texttoshow .= '<br>'.$langs->trans('CronArgs').': '.$cron['parameters'];
7033 $texttoshow .= '<br>'.$langs->trans('Comment').': '.$langs->trans($cron['comment']);
7034 }
7035 print $form->textwithpicto($text, $texttoshow, 1);
7036 print '</td>';
7037
7038 print '<td>';
7039 if ($cron['unitfrequency'] == "60") {
7040 print $langs->trans('CronEach')." ".($cron['frequency'])." ".$langs->trans('Minutes');
7041 }
7042 if ($cron['unitfrequency'] == "3600") {
7043 print $langs->trans('CronEach')." ".($cron['frequency'])." ".$langs->trans('Hours');
7044 }
7045 if ($cron['unitfrequency'] == "86400") {
7046 print $langs->trans('CronEach')." ".($cron['frequency'])." ".$langs->trans('Days');
7047 }
7048 if ($cron['unitfrequency'] == "604800") {
7049 print $langs->trans('CronEach')." ".($cron['frequency'])." ".$langs->trans('Weeks');
7050 }
7051 print '</td>';
7052
7053 print '<td>';
7054 print $cron['status'];
7055 print '</td>';
7056
7057 print '<td>';
7058 if (!empty($cron['comment'])) {
7059 print $cron['comment'];
7060 }
7061 print '</td>';
7062
7063 print '</tr>';
7064 }
7065 } else {
7066 print '<tr><td colspan="5"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
7067 }
7068
7069 print '</table>';
7070 print '</div>';
7071
7072 print '</form>';
7073 } else {
7074 $fullpathoffile = dol_buildpath($file, 0);
7075
7076 $content = file_get_contents($fullpathoffile);
7077
7078 // New module
7079 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
7080 print '<input type="hidden" name="token" value="'.newToken().'">';
7081 print '<input type="hidden" name="action" value="savefile">';
7082 print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
7083 print '<input type="hidden" name="tab" value="'.$tab.'">';
7084 print '<input type="hidden" name="module" value="'.$module.'">';
7085
7086 $posCursor = (empty($find)) ? array() : array('find' => $find);
7087 $doleditor = new DolEditor('editfilecontent', $content, '', 300, 'Full', 'In', true, false, 'ace', 0, '99%', 0, $posCursor);
7088 print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ? GETPOST('format', 'aZ09') : 'html'));
7089 print '<br>';
7090 print '<center>';
7091 print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
7092 print ' &nbsp; ';
7093 print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
7094 print '</center>';
7095
7096 print '</form>';
7097 }
7098 }
7099
7100 if ($tab == 'specifications') {
7101 print '<!-- tab=specifications -->'."\n";
7102 $specs = dol_dir_list(dol_buildpath($modulelowercase.'/doc', 0), 'files', 1, '(\.md|\.asciidoc)$', array('\/temp\/'));
7103
7104 if ($action != 'editfile' || empty($file)) {
7105 print '<span class="opacitymedium">'.$langs->trans("SpecDefDesc").'</span><br>';
7106 print '<br>';
7107
7108 print '<table>';
7109 if (is_array($specs) && !empty($specs)) {
7110 foreach ($specs as $spec) {
7111 $pathtofile = $modulelowercase.'/doc/'.$spec['relativename'];
7112 $format = 'asciidoc';
7113 if (preg_match('/\.md$/i', $spec['name'])) {
7114 $format = 'markdown';
7115 }
7116 print '<tr><td>';
7117 print '<span class="fa fa-file"></span> '.$langs->trans("SpecificationFile").' : <strong class="wordbreak">'.$pathtofile.'</strong>';
7118 print '</td><td><a class="editfielda paddingleft paddingright" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&token='.newToken().'&format='.$format.'&file='.urlencode($pathtofile).'">'.img_picto($langs->trans("Edit"), 'edit').'</a></td>';
7119 print '<td><a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=confirm_removefile&token='.newToken().'&format='.$format.'&file='.urlencode($pathtofile).'">'.img_picto($langs->trans("Delete"), 'delete').'</a></td>';
7120 print '</tr>';
7121 }
7122 } else {
7123 print '<tr><td>';
7124 print '<span class="fa fa-file"></span> '.$langs->trans("SpecificationFile").' : <span class="opacitymedium">'.$langs->trans("FileNotYetGenerated").'</span>';
7125 print '</td><td><a href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=initdoc&token='.newToken().'&format=php">'.img_picto('Generate', 'generate', 'class="paddingleft"').'</a></td>';
7126 print '</tr>';
7127 }
7128 print '</table>';
7129 } else {
7130 // Use MD or asciidoc
7131
7132 //print $langs->trans("UseAsciiDocFormat").'<br>';
7133
7134 $fullpathoffile = dol_buildpath($file, 0);
7135
7136 $content = file_get_contents($fullpathoffile);
7137
7138 // New module
7139 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
7140 print '<input type="hidden" name="token" value="'.newToken().'">';
7141 print '<input type="hidden" name="action" value="savefile">';
7142 print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
7143 print '<input type="hidden" name="tab" value="'.$tab.'">';
7144 print '<input type="hidden" name="module" value="'.$module.'">';
7145
7146 $doleditor = new DolEditor('editfilecontent', $content, '', 300, 'Full', 'In', true, false, 'ace', 0, '99%');
7147 print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ? GETPOST('format', 'aZ09') : 'html'));
7148 print '<br>';
7149 print '<center>';
7150 print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
7151 print ' &nbsp; ';
7152 print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
7153 print '</center>';
7154
7155 print '</form>';
7156 }
7157
7158 print '<br><br><br>';
7159
7160 $FILENAMEDOC = $modulelowercase.'.html';
7161 $FILENAMEDOCPDF = $modulelowercase.'.pdf';
7162 $outputfiledoc = dol_buildpath($modulelowercase, 0).'/doc/'.$FILENAMEDOC;
7163 $outputfiledocurl = dol_buildpath($modulelowercase, 1).'/doc/'.$FILENAMEDOC;
7164 $outputfiledocrel = $modulelowercase.'/doc/'.$FILENAMEDOC;
7165 $outputfiledocpdf = dol_buildpath($modulelowercase, 0).'/doc/'.$FILENAMEDOCPDF;
7166 $outputfiledocurlpdf = dol_buildpath($modulelowercase, 1).'/doc/'.$FILENAMEDOCPDF;
7167 $outputfiledocrelpdf = $modulelowercase.'/doc/'.$FILENAMEDOCPDF;
7168
7169 // HTML
7170 print '<span class="fa fa-file"></span> '.$langs->trans("PathToModuleDocumentation", "HTML").' : ';
7171 if (!dol_is_file($outputfiledoc)) {
7172 print '<span class="opacitymedium">'.$langs->trans("FileNotYetGenerated").'</span>';
7173 } else {
7174 print '<strong>';
7175 print '<a href="'.$outputfiledocurl.'" target="_blank" rel="noopener noreferrer">';
7176 print $outputfiledoc;
7177 print '</a>';
7178 print '</strong>';
7179 print ' <span class="opacitymedium">('.$langs->trans("GeneratedOn").' '.dol_print_date(dol_filemtime($outputfiledoc), 'dayhour').')</span>';
7180 print ' <a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=confirm_removefile&token='.newToken().'&format='.$format.'&file='.urlencode($outputfiledocrel).'">'.img_picto($langs->trans("Delete"), 'delete').'</a>';
7181 }
7182 print '</strong><br>';
7183
7184 // PDF
7185 print '<span class="fa fa-file"></span> '.$langs->trans("PathToModuleDocumentation", "PDF").' : ';
7186 if (!dol_is_file($outputfiledocpdf)) {
7187 print '<span class="opacitymedium">'.$langs->trans("FileNotYetGenerated").'</span>';
7188 } else {
7189 print '<strong>';
7190 print '<a href="'.$outputfiledocurlpdf.'" target="_blank" rel="noopener noreferrer">';
7191 print $outputfiledocpdf;
7192 print '</a>';
7193 print '</strong>';
7194 print ' <span class="opacitymedium">('.$langs->trans("GeneratedOn").' '.dol_print_date(dol_filemtime($outputfiledocpdf), 'dayhour').')</span>';
7195 print ' <a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=confirm_removefile&token='.newToken().'&format='.$format.'&file='.urlencode($outputfiledocrelpdf).'">'.img_picto($langs->trans("Delete"), 'delete').'</a>';
7196 }
7197 print '</strong><br>';
7198
7199 print '<br>';
7200
7201 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST" name="generatedoc">';
7202 print '<input type="hidden" name="token" value="'.newToken().'">';
7203 print '<input type="hidden" name="action" value="generatedoc">';
7204 print '<input type="hidden" name="tab" value="'.dol_escape_htmltag($tab).'">';
7205 print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
7206 print '<input type="submit" class="button" name="generatedoc" value="'.$langs->trans("BuildDocumentation").'"';
7207 if (!is_array($specs) || empty($specs)) {
7208 print ' disabled="disabled"';
7209 }
7210 print '>';
7211 print '</form>';
7212 }
7213
7214 if ($tab == 'buildpackage') {
7215 print '<!-- tab=buildpackage -->'."\n";
7216 print '<span class="opacitymedium">'.$langs->trans("BuildPackageDesc").'</span>';
7217 print '<br>';
7218
7219 if (!class_exists('ZipArchive') && !defined('ODTPHP_PATHTOPCLZIP')) {
7220 $langs->load("errors");
7221 print img_warning().' '.$langs->trans("ErrNoZipEngine");
7222 print '<br>';
7223 }
7224
7225 $modulelowercase = dol_strtolower($module);
7226
7227 // Zip file to build
7228 $FILENAMEZIP = '';
7229
7230 // Load module
7231 $pathtofile = $listofmodules[dol_strtolower($module)]['moduledescriptorrelpath'];
7232 dol_include_once($pathtofile);
7233 $class = 'mod'.$module;
7234 $moduleobj = null;
7235 if (class_exists($class)) {
7236 try {
7237 $moduleobj = new $class($db);
7238 '@phan-var-force DolibarrModules $moduleobj';
7240 } catch (Exception $e) {
7241 $error++;
7242 dol_print_error($db, $e->getMessage());
7243 }
7244 }
7245 if ($moduleobj === null) {
7246 $error++;
7247 $langs->load("errors");
7248 dol_print_error($db, $langs->trans("ErrorFailedToLoadModuleDescriptorForXXX", $module));
7249 exit;
7250 }
7251
7252 $outputfilezip = null;
7253 $arrayversion = explode('.', $moduleobj->version, 3);
7254 if (count($arrayversion)) {
7255 $FILENAMEZIP = "module_".$modulelowercase.'-'.$arrayversion[0].(empty($arrayversion[1]) ? '.0' : '.'.$arrayversion[1]).(empty($arrayversion[2]) ? '' : ".".$arrayversion[2]).".zip";
7256 $outputfilezip = dol_buildpath($modulelowercase, 0).'/bin/'.$FILENAMEZIP;
7257 }
7258
7259 print '<br>';
7260
7261 print '<span class="fa fa-file"></span> '.$langs->trans("PathToModulePackage").' : ';
7262 if ($outputfilezip === null || !dol_is_file($outputfilezip)) {
7263 print '<span class="opacitymedium">'.$langs->trans("FileNotYetGenerated").'</span>';
7264 } else {
7265 $relativepath = $modulelowercase.'/bin/'.$FILENAMEZIP;
7266 print '<strong><a href="'.DOL_URL_ROOT.'/document.php?modulepart=packages&file='.urlencode($relativepath).'">'.$outputfilezip.'</a></strong>';
7267 print ' <span class="opacitymedium">('.$langs->trans("GeneratedOn").' '.dol_print_date(dol_filemtime($outputfilezip), 'dayhour').')</span>';
7268 print ' <a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=confirm_removefile&token='.newToken().'&file='.urlencode($relativepath).'">'.img_picto($langs->trans("Delete"), 'delete').'</a>';
7269 }
7270 print '</strong>';
7271
7272 print '<br>';
7273
7274 print '<br>';
7275
7276 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST" name="generatepackage">';
7277 print '<input type="hidden" name="token" value="'.newToken().'">';
7278 print '<input type="hidden" name="action" value="generatepackage">';
7279 print '<input type="hidden" name="tab" value="'.dol_escape_htmltag($tab).'">';
7280 print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
7281 print '<input type="submit" class="button" name="generatepackage" value="'.$langs->trans("BuildPackage").'">';
7282 print '</form>';
7283 }
7284
7285 if ($tab == 'tabs') {
7286 $pathtofile = $listofmodules[dol_strtolower($module)]['moduledescriptorrelpath'];
7287
7288 $tabs = $moduleobj->tabs;
7289
7290 if ($action != 'editfile' || empty($file)) {
7291 print '<span class="opacitymedium">';
7292 $htmlhelp = $langs->trans("TabsDefDescTooltip", '{s1}');
7293 $htmlhelp = str_replace('{s1}', '<a target="adminbis" class="nofocusvisible" href="'.DOL_URL_ROOT.'/admin/menus/index.php">'.$langs->trans('Setup').' - '.$langs->trans('Tabs').'</a>', $htmlhelp);
7294 print $form->textwithpicto($langs->trans("TabsDefDesc"), $htmlhelp, 1, 'help', '', 0, 2, 'helpondesc').'<br>';
7295 print '</span>';
7296 print '<br>';
7297
7298 print '<span class="fa fa-file"></span> '.$langs->trans("DescriptorFile").' : <strong>'.$pathtofile.'</strong>';
7299 print ' <a class="editfielda paddingleft paddingright" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&format=php&file='.urlencode($pathtofile).'&find=TABS">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
7300 print '<br>';
7301
7302 print '<br>';
7303 print load_fiche_titre($langs->trans("ListOfTabsEntries"), '', '');
7304
7305 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
7306 print '<input type="hidden" name="token" value="'.newToken().'">';
7307 print '<input type="hidden" name="action" value="addproperty">';
7308 print '<input type="hidden" name="tab" value="objects">';
7309 print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
7310 print '<input type="hidden" name="tabobj" value="'.dol_escape_htmltag($tabobj).'">';
7311
7312 print '<div class="div-table-responsive">';
7313 print '<table class="noborder small">';
7314
7315 print '<tr class="liste_titre">';
7316 print_liste_field_titre("ObjectType", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
7317 print_liste_field_titre("Tab", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
7318 print_liste_field_titre("Title", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
7319 print_liste_field_titre("LangFile", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
7320 print_liste_field_titre("Condition", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
7321 print_liste_field_titre("Path", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
7322 print "</tr>\n";
7323
7324 if (count($tabs)) {
7325 foreach ($tabs as $tab) {
7326 $parts = explode(':', $tab['data']);
7327
7328 $objectType = $parts[0];
7329 $tabName = $parts[1];
7330 $tabTitle = isset($parts[2]) ? $parts[2] : '';
7331 $langFile = isset($parts[3]) ? $parts[3] : '';
7332 $condition = isset($parts[4]) ? $parts[4] : '';
7333 $path = isset($parts[5]) ? $parts[5] : '';
7334
7335 // If we want to remove the tab, then the format is 'objecttype:tabname:optionalcondition'
7336 // See: https://wiki.dolibarr.org/index.php?title=Tabs_system#To_remove_an_existing_tab
7337 if ($tabName[0] === '-') {
7338 $tabTitle = '';
7339 $condition = isset($parts[2]) ? $parts[2] : '';
7340 }
7341
7342 print '<tr class="oddeven">';
7343
7344 print '<td>';
7345 print dol_escape_htmltag($parts[0]);
7346 print '</td>';
7347
7348 print '<td>';
7349 if ($tabName[0] === "+") {
7350 print '<span class="badge badge-status4 badge-status">' . dol_escape_htmltag($tabName) . '</span>';
7351 } else {
7352 print '<span class="badge badge-status8 badge-status">' . dol_escape_htmltag($tabName) . '</span>';
7353 }
7354 print '</td>';
7355
7356 print '<td>';
7357 print dol_escape_htmltag($tabTitle);
7358 print '</td>';
7359
7360 print '<td>';
7361 print dol_escape_htmltag($langFile);
7362 print '</td>';
7363
7364 print '<td>';
7365 print dol_escape_htmltag($condition);
7366 print '</td>';
7367
7368 print '<td>';
7369 print dol_escape_htmltag($path);
7370 print '</td>';
7371
7372 print '</tr>';
7373 }
7374 } else {
7375 print '<tr><td colspan="5"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
7376 }
7377
7378 print '</table>';
7379 print '</div>';
7380
7381 print '</form>';
7382 } else {
7383 $fullpathoffile = dol_buildpath($file, 0);
7384
7385 $content = file_get_contents($fullpathoffile);
7386
7387 // New module
7388 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
7389 print '<input type="hidden" name="token" value="'.newToken().'">';
7390 print '<input type="hidden" name="action" value="savefile">';
7391 print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
7392 print '<input type="hidden" name="tab" value="'.$tab.'">';
7393 print '<input type="hidden" name="module" value="'.$module.'">';
7394
7395 $posCursor = (empty($find)) ? array() : array('find' => $find);
7396 $doleditor = new DolEditor('editfilecontent', $content, '', 300, 'Full', 'In', true, false, 'ace', 0, '99%', 0, $posCursor);
7397 print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ? GETPOST('format', 'aZ09') : 'html'));
7398 print '<br>';
7399 print '<center>';
7400 print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
7401 print ' &nbsp; ';
7402 print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
7403 print '</center>';
7404
7405 print '</form>';
7406 }
7407 }
7408
7409 if ($tab != 'description') {
7410 print dol_get_fiche_end();
7411 }
7412 }
7413}
7414
7415print dol_get_fiche_end(); // End modules
7416
7417
7418// End of page
7419llxFooter();
7420$db->close();
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
$propal type
'integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortfield]]]',...
Definition propal.php:281
dolibarr_set_const($db, $name, $value, $type='chaine', $visible=0, $note='', $entity=1)
Insert a parameter (key,value) into database (delete old key then insert it again).
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve', $idforemptyvalue='-1', $morecss='', $placeholder='')
Convert a html select field into an ajax combobox.
Definition ajax.lib.php:488
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
print $object position
Definition edit.php:206
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
static fromAlternatives(array $alternatives, string $message='')
Build a policy from the editor of ModuleBuilder: the predicates of an alternative are combined with A...
Syncs rights straight into the mod<Module>.class.php descriptor file.
Class to manage a WYSIWYG editor.
Class to generate html code for admin pages.
Class to manage generation of HTML components Only common components must be here.
Class to manage triggers.
static getEmailingSelectorsList($forcedir=null)
Return list of widget.
static getWidgetsList($forcedirwidget=null)
Return list of widget.
Immutable value object holding all case variants of a module/object pair.
const PREDICATES
PHP rendered for each predicate.
Immutable request describing one permissions sync to perform on a module descriptor.
static forObjectDeletion(string $module, string $descriptorFile, array $permissions, string $objectName)
Drop every right attached to an object being deleted.
static forRightDeletion(string $module, string $descriptorFile, array $permissions, int $rightKey)
Remove one right, addressed by its index in the rights array.
static forRightUpdate(string $module, string $descriptorFile, array $permissions, int $rightKey, string $objectName, string $label, string $crud)
Replace one right, addressed by its index in the rights array.
static forRightAddition(string $module, string $descriptorFile, array $permissions, string $objectName, string $label, string $crud)
Append one right to the descriptor.
static forObjectCreation(string $module, string $descriptorFile, array $permissions, string $objectName)
Declare the three CRUD rights of a newly generated object.
Strict implementation — reports any residual myobject/mymodule token as a warning.
Immutable outcome of a permissions sync run.
Class to manage utility methods.
if(! $sortfield) if(! $sortorder) $module
Definition list.php:193
global $mysoc
removePatternFromFile(string $filePath, string $pattern)
Removes content from a file that matches a given pattern.
dol_filemtime($pathoffile)
Return time of a file.
dol_copy($srcfile, $destfile, $newmask='0', $overwriteifexists=1, $testvirus=0, $indexdatabase=0)
Copy a file to another file.
dol_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null, $allowdotdot=false, $indexdatabase=1, $nolog=0)
Remove a file or several files with a mask.
dol_is_writable($folderorfile)
Test if directory or filename is writable.
dol_delete_dir($dir, $nophperrors=0)
Remove a directory (not recursive, so content must be empty).
dol_delete_dir_recursive($dir, $count=0, $nophperrors=0, $onlysub=0, &$countdeleted=0, $indexdatabase=1, $nolog=0, $level=0)
Remove a directory $dir and its subdirectories (or only files and subdirectories)
dolCopyDir($srcfile, $destfile, $newmask, $overwriteifexists, $arrayreplacement=null, $excludesubdir=0, $excludefileext=null, $excludearchivefiles=0)
Copy a dir to another dir.
dol_is_file($pathoffile)
Return if path is a file.
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
Definition files.lib.php:66
dol_is_dir($folder)
Test if filename is a directory.
dolReplaceInFile($srcfile, $arrayreplacement, $destfile='', $newmask='0', $indexdatabase=0, $arrayreplacementisregex=0)
Make replacement of strings into a file.
dol_is_dir_empty($dir)
Return if path is empty.
dol_now($mode='gmt')
Return date for now.
dolExplodeIntoArray($string, $delimiter=';', $kv='=')
Split a string with 2 keys into key array.
dol_ucfirst($string, $encoding="UTF-8")
Convert first character of the first word of a string to upper.
dol_strtolower($string, $encoding="UTF-8")
Convert a string to lower.
dol_mimetype($file, $default='application/octet-stream', $mode=0)
Return MIME type of a file from its name with extension.
dol_strlen($string, $stringencoding='UTF-8', $binarycount=0)
Make a strlen call.
dol_osencode($str)
Return a string encoded into OS filesystem encoding.
dol_sanitizePathName($str, $newstr='_', $unaccent=0, $allowdash=0)
Clean a string to use it as a path name.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
dolChmod($filepath, $newmask='')
Change mod of a file.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by the value of a given key, which produces ascending (default) or descending out...
if(!function_exists( 'dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
dol_string_unaccent($str)
Clean a string from all accent characters to be used as ref, login or by dol_sanitizeFileName.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
dol_strtoupper($string, $encoding="UTF-8")
Convert a string to upper.
dol_substr($string, $start, $length=null, $stringencoding='', $trunconbytes=0)
Make a substring.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_string_nounprintableascii($str, $removetabcrlf=1)
Clean a string from all non printable ASCII chars (0x00-0x1F and 0x7F).
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '...' if string larger than length.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
dol_ucwords($string, $encoding="UTF-8")
Convert first character of all the words of a string to upper.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
print_liste_field_titre($name, $file="", $field="", $begin="", $param="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
Definition html.lib.php:542
dolButtonToOpenUrlInDialogPopup($name, $label, $buttonstring, $url, $disabled='', $morecss='classlink button bordertransp', $jsonopen='', $jsonclose='', $accesskey='')
Return HTML code to output a button to open a dialog popup box.
Definition html.lib.php:437
dolGetButtonTitle($label, $helpText='', $iconClass='fa fa-file', $url='', $id='', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition html.lib.php:740
getPictoForType($key, $morecss='')
Return the picto for a data type.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='', $textonpictotooltip='', $cssfordropdown='info_admin')
Show information in HTML for admin users or standard users.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Definition html.lib.php:183
$moduleobj
Definition index.php:3694
getLicenceHeader($user, $langs, $now)
Produce copyright replacement string for user.
Definition index.php:270
modulebuilderValidateGeneratedFile(string $destfile, NamingContract $nc)
Post-generation validation – logs and displays a warning if residual myobject/mymodule tokens remain.
Definition index.php:291
foreach( $dirsrootforscan as $tmpdirread) moduleBuilderShutdownFunction()
Add management to catch fatal errors - shutdown handler.
Definition index.php:246
getModuleBuilderDefaultEnabledKeys($map)
Return the keys enabled by default in a ModuleBuilder generation map.
updateDictionaryInFile($module, $file, $dicts)
Updates a dictionary in a module descriptor file.
deletePropsAndPermsFromDoc($file, $objectname)
Delete property and permissions from documentation ascii file if we delete an object.
applyModuleBuilderAccessPolicyToPage(string $file, ?AccessPolicyConfig $policy)
Apply an access policy to a generated object page.
applyModuleBuilderAccessPolicyToClass(string $file, ?AccessPolicyConfig $policy)
Store an access policy in the generated object class.
getModuleBuilderCardActionUncommentPatterns($marker)
Build the regular expressions removing the comment fence of a card action generated in 'activate' mod...
getModuleBuilderAccessPolicyFromClassFile(string $file)
Load the access policy stored in a generated object class by renderModuleBuilderAccessPolicyProperty(...
createNewDictionnary($modulename, $file, $namedic, $dictionnaires=null)
Create a new dictionary table.
filterEnabledKeys($requested, $map)
Filter a list of requested keys against a known map of generable elements.
countItemsInDirectory($path, $type=1)
count directories or files in modulebuilder folder
getModuleBuilderCardActionBlockPattern($marker)
Build the regular expression matching every block of a card action in the object card template.
writePermsInAsciiDoc($file, $destfile)
Write all permissions of each object in AsciiDoc format.
reWriteAllMenus($file, $menus, $menuWantTo, $key, $action)
rebuildObjectSql($destdir, $module, $objectname, $newmask, $readdir='', $object=null, $moduletype='external')
Save data into a memory area shared by all users, all sessions on server.
writeApiUrlsInDoc($file_api, $file_doc)
Generate Urls and add them to documentation module.
dolGetListOfObjectClasses($destdir)
Get list of existing objects from a directory.
getModuleBuilderLinesBlockPattern()
Return the regular expression matching a block of object lines code in the templates,...
writePropsInAsciiDoc($file, $objectname, $destfile)
Write all properties of the object in AsciiDoc format.
removeObjectFromApiFile($file, $objects, $objectname)
Remove Object variables and methods from API_Module File.
getModuleBuilderObjectCardActions()
Return the map of optional action buttons that can be generated on the card page of a ModuleBuilder o...
getModuleBuilderAccessPolicyPages()
Return the object pages whose read access is driven by the access policy defined in ModuleBuilder.
dolReplaceInFilePreservingModuleBuilderMarkers($file, $arrayreplacement)
Apply substitutions to a module descriptor file while preserving the MODULEBUILDER comment markers.
rebuildObjectClass($destdir, $module, $objectname, $newmask, $readdir='', $addfieldentry=array(), $delfieldentry='')
Regenerate files .class.php.
checkExistComment($file, $number)
Function to check if comment BEGIN and END exists in modMyModule class.
getModuleBuilderObjectTabs()
Return the map of optional tabs that can be generated for a ModuleBuilder object.
addObjectsToApiFile($srcfile, $file, $objects, $modulename)
Add Object in ModuleApi File.
$conf db user
Active Directory does not allow anonymous connections.
Definition repair.php:166
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:165
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $nodie=0, $mode='')
Check permissions of a user to show a page and an object.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.
treeview li table
No Email.
a disabled