dolibarr 21.0.0-beta
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 MDW <mdeweerd@users.noreply.github.com>
6 * Copyright (C) 2024 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/files.lib.php';
40require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
41require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
42require_once DOL_DOCUMENT_ROOT.'/core/lib/modulebuilder.lib.php';
43require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
44require_once DOL_DOCUMENT_ROOT.'/core/class/utils.class.php';
45
58// Load translation files required by the page
59$langs->loadLangs(array("admin", "modulebuilder", "exports", "other", "cron", "errors"));
60
61// GET Parameters
62$action = GETPOST('action', 'aZ09');
63$confirm = GETPOST('confirm', 'alpha');
64$cancel = GETPOST('cancel', 'alpha');
65
66$sortfield = GETPOST('sortfield', 'alpha');
67$sortorder = GETPOST('sortorder', 'aZ09');
68
69$module = GETPOST('module', 'alpha');
70$tab = GETPOST('tab', 'aZ09');
71$tabobj = GETPOST('tabobj', 'alpha');
72$tabdic = GETPOST('tabdic', 'alpha');
73$propertykey = GETPOST('propertykey', 'alpha');
74if (empty($module)) {
75 $module = 'initmodule';
76}
77if (empty($tab)) {
78 $tab = 'description';
79}
80if (empty($tabobj)) {
81 $tabobj = 'newobjectifnoobj';
82}
83if (empty($tabdic)) {
84 $tabdic = 'newdicifnodic';
85}
86$file = GETPOST('file', 'alpha');
87$find = GETPOST('find', 'alpha');
88
89$modulename = dol_sanitizeFileName(GETPOST('modulename', 'alpha'));
90$objectname = dol_sanitizeFileName(GETPOST('objectname', 'alpha'));
91$dicname = dol_sanitizeFileName(GETPOST('dicname', 'alpha'));
92$editorname = GETPOST('editorname', 'alpha');
93$editorurl = GETPOST('editorurl', 'alpha');
94$version = GETPOST('version', 'alpha');
95$family = GETPOST('family', 'alpha');
96$picto = GETPOST('idpicto', 'alpha');
97$idmodule = GETPOST('idmodule', 'alpha');
98$format = ''; // Prevent undefined in css tab
99
100// Security check
101if (!isModEnabled('modulebuilder')) {
102 accessforbidden('Module ModuleBuilder not enabled');
103}
104if (!$user->hasRight("modulebuilder", "run")) {
105 accessforbidden('ModuleBuilderNotAllowed');
106}
107
108// Dir for custom dirs
109$tmp = explode(',', $dolibarr_main_document_root_alt);
110$dirins = $tmp[0];
111$dirread = $dirins;
112$forceddirread = 0;
113
114$tmpdir = explode('@', $module);
115if (!empty($tmpdir[1])) {
116 $module = $tmpdir[0];
117 $dirread = $tmpdir[1];
118 $forceddirread = 1;
119}
120if (GETPOST('dirins', 'alpha')) {
121 $dirread = $dirins = GETPOST('dirins', 'alpha');
122 $forceddirread = 1;
123}
124
125$FILEFLAG = 'modulebuilder.txt';
126
127$now = dol_now();
128$newmask = 0;
129if (empty($newmask) && getDolGlobalString('MAIN_UMASK')) {
130 $newmask = getDolGlobalString('MAIN_UMASK');
131}
132if (empty($newmask)) { // This should no happen
133 $newmask = '0664';
134}
135
136$result = restrictedArea($user, 'modulebuilder', 0);
137
138$error = 0;
139$param = '';
140
141$form = new Form($db);
142
143// Define $listofmodules
144$dirsrootforscan = array($dirread);
145
146// Add also the core modules into the list of modules to show/edit
147if ($dirread != DOL_DOCUMENT_ROOT && (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 2 || getDolGlobalString('MODULEBUILDER_ADD_DOCUMENT_ROOT'))) {
148 $dirsrootforscan[] = DOL_DOCUMENT_ROOT;
149}
150
151// Search modules to edit
152$textforlistofdirs = '<!-- Directory scanned -->'."\n";
153$listofmodules = array();
154'@phan-var-force array<string,array{modulenamewithcase:string,moduledescriptorrelpath:string,moduledescriptorfullpath:string,moduledescriptorrootpath,moduletype?:string}> $listofmodules';
155$i = 0;
156foreach ($dirsrootforscan as $tmpdirread) {
157 $moduletype = 'external';
158 if ($tmpdirread == DOL_DOCUMENT_ROOT) {
159 $moduletype = 'internal';
160 }
161
162 $dirsincustom = dol_dir_list($tmpdirread, 'directories');
163 if (is_array($dirsincustom) && count($dirsincustom) > 0) {
164 foreach ($dirsincustom as $dircustomcursor) {
165 $fullname = $dircustomcursor['fullname'];
166 if (dol_is_file($fullname.'/'.$FILEFLAG)) {
167 // Get real name of module (MyModule instead of mymodule)
168 $dirtoscanrel = basename($fullname).'/core/modules/';
169
170 $descriptorfiles = dol_dir_list(dirname($fullname).'/'.$dirtoscanrel, 'files', 0, 'mod.*\.class\.php$');
171 if (empty($descriptorfiles)) { // If descriptor not found into module dir, we look into main module dir.
172 $dirtoscanrel = 'core/modules/';
173 $descriptorfiles = dol_dir_list($fullname.'/../'.$dirtoscanrel, 'files', 0, 'mod'.strtoupper(basename($fullname)).'\.class\.php$');
174 }
175 $modulenamewithcase = '';
176 $moduledescriptorrelpath = '';
177 $moduledescriptorfullpath = '';
178
179 foreach ($descriptorfiles as $descriptorcursor) {
180 $modulenamewithcase = preg_replace('/^mod/', '', $descriptorcursor['name']);
181 $modulenamewithcase = preg_replace('/\.class\.php$/', '', $modulenamewithcase);
182 $moduledescriptorrelpath = $dirtoscanrel.$descriptorcursor['name'];
183 $moduledescriptorfullpath = $descriptorcursor['fullname'];
184 //var_dump($descriptorcursor);
185 }
186 if ($modulenamewithcase) {
187 $listofmodules[$dircustomcursor['name']] = array(
188 'modulenamewithcase' => $modulenamewithcase,
189 'moduledescriptorrelpath' => $moduledescriptorrelpath,
190 'moduledescriptorfullpath' => $moduledescriptorfullpath,
191 'moduledescriptorrootpath' => $tmpdirread,
192 'moduletype' => $moduletype
193 );
194 }
195 //var_dump($listofmodules);
196 }
197 }
198 }
199
200 if ($forceddirread && empty($listofmodules)) { // $forceddirread is 1 if we forced dir to read with dirins=... or with module=...@mydir
201 $listofmodules[strtolower($module)] = array(
202 'modulenamewithcase' => $module,
203 'moduledescriptorrelpath' => 'notyetimplemented',
204 'moduledescriptorfullpath' => 'notyetimplemented',
205 'moduledescriptorrootpath' => 'notyetimplemented',
206 );
207 }
208
209 // Show description of content
210 $newdircustom = $dirins;
211 if (empty($newdircustom)) {
212 $newdircustom = img_warning();
213 }
214 // If dirread was forced to somewhere else, by using URL
215 // htdocs/modulebuilder/index.php?module=Inventory@/home/ldestailleur/git/dolibarr/htdocs/product
216 if (empty($i)) {
217 $textforlistofdirs .= $langs->trans("DirScanned").' : ';
218 } else {
219 $textforlistofdirs .= ', ';
220 }
221 $textforlistofdirs .= '<strong class="wordbreakimp">'.$tmpdirread.'</strong>';
222 if ($tmpdirread == DOL_DOCUMENT_ROOT) {
223 if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 2) {
224 $textforlistofdirs .= $form->textwithpicto('', $langs->trans("ConstantIsOn", "MAIN_FEATURES_LEVEL"));
225 }
226 if (getDolGlobalString('MODULEBUILDER_ADD_DOCUMENT_ROOT')) {
227 $textforlistofdirs .= $form->textwithpicto('', $langs->trans("ConstantIsOn", "MODULEBUILDER_ADD_DOCUMENT_ROOT"));
228 }
229 }
230 $i++;
231}
232
239{
240 $error = error_get_last();
241 if ($error && ($error['type'] & (E_ERROR | E_PARSE | E_CORE_ERROR | E_COMPILE_ERROR | E_USER_ERROR))) {
242 // Handle the fatal error
243 echo "Fatal error occurred: {$error['message']} in {$error['file']} on line {$error['line']}";
244 // If a header was already send, we suppose it is the llx_Header() so we call the llxFooter()
245 if (headers_sent()) {
246 llxFooter();
247 }
248 }
249}
250register_shutdown_function("moduleBuilderShutdownFunction");
251
252
262function getLicenceHeader($user, $langs, $now)
263{
264 $licInfo = $user->getFullName($langs);
265 $emailTabs = str_repeat("\t", (int) (max(0, (31 - mb_strlen($licInfo)) / 4)));
266 $licInfo .= ($user->email ? $emailTabs.'<'.$user->email.'>' : '');
267 $licInfo = dol_print_date($now, '%Y')."\t\t".$licInfo;
268 return $licInfo;
269}
270
271/*
272 * Actions
273 */
274
275if ($dirins && $action == 'initmodule' && $modulename && $user->hasRight("modulebuilder", "run")) {
276 $modulename = ucfirst($modulename); // Force first letter in uppercase
277 $destdir = '/not_set/';
278
279 if (preg_match('/[^a-z0-9_]/i', $modulename)) {
280 $error++;
281 setEventMessages($langs->trans("SpaceOrSpecialCharAreNotAllowed"), null, 'errors');
282 }
283
284 if (!$error) {
285 $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
286 $destdir = $dirins.'/'.strtolower($modulename);
287
288 $arrayreplacement = array(
289 'mymodule' => strtolower($modulename),
290 'MyModule' => $modulename
291 );
292 $result = dolCopyDir($srcdir, $destdir, '0', 0, $arrayreplacement);
293 //dol_mkdir($destfile);
294 if ($result <= 0) {
295 if ($result < 0) {
296 $error++;
297 $langs->load("errors");
298 setEventMessages($langs->trans("ErrorFailToCopyDir", $srcdir, $destdir), null, 'errors');
299 } else {
300 // $result == 0
301 setEventMessages($langs->trans("AllFilesDidAlreadyExist", $srcdir, $destdir), null, 'warnings');
302 }
303 }
304
305 // Copy last 'html.formsetup.class.php' to backport folder
306 if (getDolGlobalInt('MODULEBUILDER_SUPPORT_COMPATIBILITY_V16')) {
307 $tryToCopyFromSetupClass = true;
308 $backportDest = $destdir .'/backport/v16/core/class';
309 $backportFileSrc = DOL_DOCUMENT_ROOT.'/core/class/html.formsetup.class.php';
310 $backportFileDest = $backportDest.'/html.formsetup.class.php';
311 $result = dol_mkdir($backportDest);
312
313 if ($result < 0) {
314 $error++;
315 $langs->load("errors");
316 setEventMessages($langs->trans("ErrorFailToCreateDir", $backportDest), null, 'errors');
317 $tryToCopyFromSetupClass = false;
318 }
319
320 if ($tryToCopyFromSetupClass) {
321 $result = dol_copy($backportFileSrc, $backportFileDest);
322 if ($result <= 0) {
323 if ($result < 0) {
324 $error++;
325 $langs->load("errors");
326 setEventMessages($langs->trans("ErrorFailToCopyFile", $backportFileSrc, $backportFileDest), null, 'errors');
327 } else {
328 setEventMessages($langs->trans("FileDidAlreadyExist", $backportFileDest), null, 'warnings');
329 }
330 }
331 }
332 }
333
334 if (getDolGlobalString('MODULEBUILDER_USE_ABOUT')) {
335 dol_delete_file($destdir.'/admin/about.php');
336 }
337
338 // Delete dir and files that can be generated in sub tabs later if we need them (we want a minimal module first)
339 dol_delete_dir_recursive($destdir.'/ajax');
340 dol_delete_dir_recursive($destdir.'/build/doxygen');
341 dol_delete_dir_recursive($destdir.'/core/modules/mailings');
342 dol_delete_dir_recursive($destdir.'/core/modules/'.strtolower($modulename));
343 dol_delete_dir_recursive($destdir.'/core/tpl');
344 dol_delete_dir_recursive($destdir.'/core/triggers');
345 dol_delete_dir_recursive($destdir.'/doc');
346 //dol_delete_dir_recursive($destdir.'/.tx');
347 dol_delete_dir_recursive($destdir.'/core/boxes');
348
349 dol_delete_file($destdir.'/admin/myobject_extrafields.php');
350
351 dol_delete_file($destdir.'/class/actions_'.strtolower($modulename).'.class.php');
352 dol_delete_file($destdir.'/class/api_'.strtolower($modulename).'.class.php');
353
354 dol_delete_file($destdir.'/css/'.strtolower($modulename).'.css.php');
355
356 dol_delete_file($destdir.'/js/'.strtolower($modulename).'.js.php');
357
358 dol_delete_file($destdir.'/scripts/'.strtolower($modulename).'.php');
359
360 dol_delete_file($destdir.'/sql/data.sql');
361 dol_delete_file($destdir.'/sql/update_x.x.x-y.y.y.sql');
362
363 // Delete some files related to Object (because the previous dolCopyDir has copied everything)
364 dol_delete_file($destdir.'/myobject_card.php');
365 dol_delete_file($destdir.'/myobject_contact.php');
366 dol_delete_file($destdir.'/myobject_note.php');
367 dol_delete_file($destdir.'/myobject_document.php');
368 dol_delete_file($destdir.'/myobject_agenda.php');
369 dol_delete_file($destdir.'/myobject_list.php');
370 dol_delete_file($destdir.'/lib/'.strtolower($modulename).'_myobject.lib.php');
371 dol_delete_file($destdir.'/test/phpunit/functional/'.$modulename.'FunctionalTest.php');
372 dol_delete_file($destdir.'/test/phpunit/MyObjectTest.php');
373 dol_delete_file($destdir.'/sql/llx_'.strtolower($modulename).'_myobject.sql');
374 dol_delete_file($destdir.'/sql/llx_'.strtolower($modulename).'_myobject_extrafields.sql');
375 dol_delete_file($destdir.'/sql/llx_'.strtolower($modulename).'_myobject.key.sql');
376 dol_delete_file($destdir.'/sql/llx_'.strtolower($modulename).'_myobject_extrafields.key.sql');
377 dol_delete_file($destdir.'/class/myobject.class.php');
378
379 dol_delete_dir($destdir.'/class', 1);
380 dol_delete_dir($destdir.'/css', 1);
381 dol_delete_dir($destdir.'/js', 1);
382 dol_delete_dir($destdir.'/scripts', 1);
383 dol_delete_dir($destdir.'/sql', 1);
384 dol_delete_dir($destdir.'/test/phpunit/functionnal', 1);
385 dol_delete_dir($destdir.'/test/phpunit', 1);
386 dol_delete_dir($destdir.'/test', 1);
387 }
388
389 // Edit PHP files
390 if (!$error) {
391 $listofphpfilestoedit = dol_dir_list($destdir, 'files', 1, '\.(php|MD|js|sql|txt|xml|lang)$', '', 'fullname', SORT_ASC, 0, 1);
392
393 $licInfo = getLicenceHeader($user, $langs, $now);
394 foreach ($listofphpfilestoedit as $phpfileval) {
395 //var_dump($phpfileval['fullname']);
396 $arrayreplacement = array(
397 'mymodule' => strtolower($modulename),
398 'MyModule' => $modulename,
399 'MYMODULE' => strtoupper($modulename),
400 'My module' => $modulename,
401 'my module' => $modulename,
402 'Mon module' => $modulename,
403 'mon module' => $modulename,
404 'htdocs/modulebuilder/template' => strtolower($modulename),
405 '---Put here your own copyright and developer email---' => $licInfo,
406 '---Replace with your own copyright and developer email---' => $licInfo,
407 'Editor name' => $editorname,
408 'https://www.example.com' => $editorurl,
409 '$this->version = \'1.0\'' => '$this->version = \''.$version.'\'',
410 '$this->picto = \'generic\';' => (empty($picto)) ? '$this->picto = \'generic\'' : '$this->picto = \''.$picto.'\';',
411 "modulefamily" => $family,
412 '500000' => $idmodule
413 );
414
415 if (getDolGlobalString('MODULEBUILDER_SPECIFIC_AUTHOR')) {
416 $arrayreplacement['---Replace with your own copyright and developer email---'] = dol_print_date($now, '%Y')."\t\t" . getDolGlobalString('MODULEBUILDER_SPECIFIC_AUTHOR');
417 }
418
419 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
420 $result = dolReplaceInFile($phpfileval['fullname'], $arrayreplacement);
421 //var_dump($result);
422 if ($result < 0) {
423 setEventMessages($langs->trans("ErrorFailToMakeReplacementInto", $phpfileval['fullname']), null, 'errors');
424 }
425 }
426
427 if (getDolGlobalString('MODULEBUILDER_SPECIFIC_README')) {
428 setEventMessages($langs->trans("ContentOfREADMECustomized"), null, 'warnings');
429 dol_delete_file($destdir.'/README.md');
430 file_put_contents($destdir.'/README.md', $conf->global->MODULEBUILDER_SPECIFIC_README);
431 }
432 // for create file to add properties
433 // file_put_contents($destdir.'/'.strtolower($modulename).'propertycard.php','');
434 // $srcFileCard = DOL_DOCUMENT_ROOT.'/modulebuilder/card.php';
435 // $destFileCard = $dirins.'/'.strtolower($modulename).'/template/card.php';
436 // dol_copy($srcFileCard, $destdir.'/'.strtolower($modulename).'propertycard.php', '0',1, $arrayreplacement);
437 }
438
439 if (!$error) {
440 setEventMessages($langs->trans('ModuleInitialized', $destdir), null);
441 $module = $modulename;
442
443 clearstatcache(true);
444 if (function_exists('opcache_invalidate')) {
445 opcache_reset(); // remove the include cache hell !
446 }
447
448 header("Location: ".$_SERVER["PHP_SELF"].'?module='.$modulename);
449 exit;
450 }
451}
452
453$destdir = '/not_set/'; // Initialize (for static analysis)
454$destfile = '/not_set/'; // Initialize (for static analysis)
455$srcfile = '/not_set/'; // Initialize (for static analysis)
456
457// init API, PHPUnit
458if ($dirins && in_array($action, array('initapi', 'initphpunit', 'initpagecontact', 'initpagedocument', 'initpagenote', 'initpageagenda')) && !empty($module) && $user->hasRight("modulebuilder", "run")) {
459 $modulename = ucfirst($module); // Force first letter in uppercase
460 $objectname = $tabobj;
461 $varnametoupdate = '';
462 $dirins = $listofmodules[strtolower($module)]['moduledescriptorrootpath'];
463 $destdir = $dirins.'/'.strtolower($module);
464
465 // Get list of existing objects
466 $objects = dolGetListOfObjectClasses($destdir);
467
468
469 if ($action == 'initapi') { // Test on permission already done
470 if (file_exists($dirins.'/'.strtolower($module).'/class/api_'.strtolower($module).'.class.php')) {
471 $result = dol_copy(DOL_DOCUMENT_ROOT.'/modulebuilder/template/class/api_mymodule.class.php', $dirins.'/'.strtolower($module).'/class/api_'.strtolower($module).'.class.php', '0', 1);
472 }
473 dol_mkdir($dirins.'/'.strtolower($module).'/class');
474 $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
475 $srcfile = $srcdir.'/class/api_mymodule.class.php';
476 $destfile = $dirins.'/'.strtolower($module).'/class/api_'.strtolower($module).'.class.php';
477 } elseif ($action == 'initphpunit') { // Test on permission already done
478 dol_mkdir($dirins.'/'.strtolower($module).'/test/phpunit');
479 $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
480 $srcfile = $srcdir.'/test/phpunit/MyObjectTest.php';
481 $destfile = $dirins.'/'.strtolower($module).'/test/phpunit/'.strtolower($objectname).'Test.php';
482 } elseif ($action == 'initpagecontact') { // Test on permission already done
483 dol_mkdir($dirins.'/'.strtolower($module));
484 $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
485 $srcfile = $srcdir.'/myobject_contact.php';
486 $destfile = $dirins.'/'.strtolower($module).'/'.strtolower($objectname).'_contact.php';
487 $varnametoupdate = 'showtabofpagecontact';
488 } elseif ($action == 'initpagedocument') { // Test on permission already done
489 dol_mkdir($dirins.'/'.strtolower($module));
490 $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
491 $srcfile = $srcdir.'/myobject_document.php';
492 $destfile = $dirins.'/'.strtolower($module).'/'.strtolower($objectname).'_document.php';
493 $varnametoupdate = 'showtabofpagedocument';
494 } elseif ($action == 'initpagenote') { // Test on permission already done
495 dol_mkdir($dirins.'/'.strtolower($module));
496 $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
497 $srcfile = $srcdir.'/myobject_note.php';
498 $destfile = $dirins.'/'.strtolower($module).'/'.strtolower($objectname).'_note.php';
499 $varnametoupdate = 'showtabofpagenote';
500 } elseif ($action == 'initpageagenda') { // Test on permission already done
501 dol_mkdir($dirins.'/'.strtolower($module));
502 $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
503 $srcfile = $srcdir.'/myobject_agenda.php';
504 $destfile = $dirins.'/'.strtolower($module).'/'.strtolower($objectname).'_agenda.php';
505 $varnametoupdate = 'showtabofpageagenda';
506 }
507
508 if (!file_exists($destfile)) {
509 $result = dol_copy($srcfile, $destfile, '0', 0);
510 }
511
512 if ($result > 0) {
513 //var_dump($phpfileval['fullname']);
514 $arrayreplacement = array(
515 'mymodule' => strtolower($modulename),
516 'MyModule' => $modulename,
517 'MYMODULE' => strtoupper($modulename),
518 'My module' => $modulename,
519 'my module' => $modulename,
520 'Mon module' => $modulename,
521 'mon module' => $modulename,
522 'htdocs/modulebuilder/template' => strtolower($modulename),
523 'myobject' => strtolower($objectname),
524 'MyObject' => $objectname,
525 'MYOBJECT' => strtoupper($objectname),
526
527 '---Replace with your own copyright and developer email---' => getLicenceHeader($user, $langs, $now)
528 );
529
530 if ($action == 'initapi') { // Test on permission already done
531 if (count($objects) >= 1) {
532 addObjectsToApiFile($srcfile, $destfile, $objects, $modulename);
533 }
534 } else {
535 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
536 dolReplaceInFile($destfile, $arrayreplacement);
537 }
538
539 if ($varnametoupdate) {
540 // Now we update the object file to set $$varnametoupdate to 1
541 $srcfile = $dirins.'/'.strtolower($module).'/lib/'.strtolower($module).'_'.strtolower($objectname).'.lib.php';
542 $arrayreplacement = array('/\$'.preg_quote($varnametoupdate, '/').' = 0;/' => '$'.$varnametoupdate.' = 1;');
543 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
544 dolReplaceInFile($srcfile, $arrayreplacement, '', '0', 0, 1);
545 }
546 } else {
547 $langs->load("errors");
548 setEventMessages($langs->trans('ErrorFailToCreateFile', $destfile), null, 'errors');
549 }
550}
551
552
553// init ExtraFields
554if ($dirins && $action == 'initsqlextrafields' && !empty($module) && $user->hasRight("modulebuilder", "run")) {
555 $modulename = ucfirst($module); // Force first letter in uppercase
556 $objectname = $tabobj;
557
558 dol_mkdir($dirins.'/'.strtolower($module).'/sql');
559 $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
560 $srcfile1 = $srcdir.'/sql/llx_mymodule_myobject_extrafields.sql';
561 $destfile1 = $dirins.'/'.strtolower($module).'/sql/llx_'.strtolower($module).'_'.strtolower($objectname).'_extrafields.sql';
562 $result1 = dol_copy($srcfile1, $destfile1, '0', 0);
563 $srcfile2 = $srcdir.'/sql/llx_mymodule_myobject_extrafields.key.sql';
564 $destfile2 = $dirins.'/'.strtolower($module).'/sql/llx_'.strtolower($module).'_'.strtolower($objectname).'_extrafields.key.sql';
565 $result2 = dol_copy($srcfile2, $destfile2, '0', 0);
566
567 if ($result1 > 0 && $result2 > 0) {
568 $modulename = ucfirst($module); // Force first letter in uppercase
569
570 //var_dump($phpfileval['fullname']);
571 $arrayreplacement = array(
572 'mymodule' => strtolower($modulename),
573 'MyModule' => $modulename,
574 'MYMODULE' => strtoupper($modulename),
575 'My module' => $modulename,
576 'my module' => $modulename,
577 'Mon module' => $modulename,
578 'mon module' => $modulename,
579 'htdocs/modulebuilder/template' => strtolower($modulename),
580 'My Object' => $objectname,
581 'MyObject' => $objectname,
582 'my object' => strtolower($objectname),
583 'myobject' => strtolower($objectname),
584 '---Replace with your own copyright and developer email---' => getLicenceHeader($user, $langs, $now)
585 );
586
587 dolReplaceInFile($destfile1, $arrayreplacement);
588 dolReplaceInFile($destfile2, $arrayreplacement);
589 } else {
590 $langs->load("errors");
591 if ($result1 <= 0) {
592 setEventMessages($langs->trans('ErrorFailToCreateFile', $destfile1), null, 'errors');
593 }
594 if ($result2 <= 0) {
595 setEventMessages($langs->trans('ErrorFailToCreateFile', $destfile2), null, 'errors');
596 }
597 }
598
599 // Now we update the object file to set $this->isextrafieldmanaged to 1
600 $srcfile = $dirins.'/'.strtolower($module).'/class/'.strtolower($objectname).'.class.php';
601 $arrayreplacement = array('/\$this->isextrafieldmanaged = 0;/' => '$this->isextrafieldmanaged = 1;');
602 dolReplaceInFile($srcfile, $arrayreplacement, '', '0', 0, 1);
603}
604
605
606// init Hook
607if ($dirins && $action == 'inithook' && !empty($module) && $user->hasRight("modulebuilder", "run")) {
608 dol_mkdir($dirins.'/'.strtolower($module).'/class');
609 $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
610 $srcfile = $srcdir.'/class/actions_mymodule.class.php';
611 $destfile = $dirins.'/'.strtolower($module).'/class/actions_'.strtolower($module).'.class.php';
612 $result = dol_copy($srcfile, $destfile, '0', 0);
613
614 if ($result > 0) {
615 $modulename = ucfirst($module); // Force first letter in uppercase
616
617 //var_dump($phpfileval['fullname']);
618 $arrayreplacement = array(
619 'mymodule' => strtolower($modulename),
620 'MyModule' => $modulename,
621 'MYMODULE' => strtoupper($modulename),
622 'My module' => $modulename,
623 'my module' => $modulename,
624 'Mon module' => $modulename,
625 'mon module' => $modulename,
626 'htdocs/modulebuilder/template' => strtolower($modulename),
627 '---Replace with your own copyright and developer email---' => getLicenceHeader($user, $langs, $now)
628 );
629
630 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
631 dolReplaceInFile($destfile, $arrayreplacement);
632 } else {
633 $langs->load("errors");
634 setEventMessages($langs->trans('ErrorFailToCreateFile', $destfile), null, 'errors');
635 }
636}
637
638
639// init Trigger
640if ($dirins && $action == 'inittrigger' && !empty($module) && $user->hasRight("modulebuilder", "run")) {
641 dol_mkdir($dirins.'/'.strtolower($module).'/core/triggers');
642 $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
643 $srcfile = $srcdir.'/core/triggers/interface_99_modMyModule_MyModuleTriggers.class.php';
644 $destfile = $dirins.'/'.strtolower($module).'/core/triggers/interface_99_mod'.$module.'_'.$module.'Triggers.class.php';
645 $result = dol_copy($srcfile, $destfile, '0', 0);
646
647 if ($result > 0) {
648 $modulename = ucfirst($module); // Force first letter in uppercase
649
650 //var_dump($phpfileval['fullname']);
651 $arrayreplacement = array(
652 'mymodule' => strtolower($modulename),
653 'MyModule' => $modulename,
654 'MYMODULE' => strtoupper($modulename),
655 'My module' => $modulename,
656 'my module' => $modulename,
657 'Mon module' => $modulename,
658 'mon module' => $modulename,
659 'htdocs/modulebuilder/template' => strtolower($modulename),
660 '---Replace with your own copyright and developer email---' => getLicenceHeader($user, $langs, $now)
661 );
662
663 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
664 dolReplaceInFile($destfile, $arrayreplacement);
665 } else {
666 $langs->load("errors");
667 setEventMessages($langs->trans('ErrorFailToCreateFile', $destfile), null, 'errors');
668 }
669}
670
671
672// init Widget
673if ($dirins && $action == 'initwidget' && !empty($module) && $user->hasRight("modulebuilder", "run")) {
674 dol_mkdir($dirins.'/'.strtolower($module).'/core/boxes');
675 $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
676 $srcfile = $srcdir.'/core/boxes/mymodulewidget1.php';
677 $destfile = $dirins.'/'.strtolower($module).'/core/boxes/'.strtolower($module).'widget1.php';
678 $result = dol_copy($srcfile, $destfile, '0', 0);
679
680 if ($result > 0) {
681 $modulename = ucfirst($module); // Force first letter in uppercase
682
683 //var_dump($phpfileval['fullname']);
684 $arrayreplacement = array(
685 'mymodule' => strtolower($modulename),
686 'MyModule' => $modulename,
687 'MYMODULE' => strtoupper($modulename),
688 'My module' => $modulename,
689 'my module' => $modulename,
690 'Mon module' => $modulename,
691 'mon module' => $modulename,
692 'htdocs/modulebuilder/template' => strtolower($modulename),
693 '---Replace with your own copyright and developer email---' => getLicenceHeader($user, $langs, $now)
694 );
695
696 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
697 dolReplaceInFile($destfile, $arrayreplacement);
698 } else {
699 $langs->load("errors");
700 setEventMessages($langs->trans('ErrorFailToCreateFile', $destfile), null, 'errors');
701 }
702}
703
704
705// init EmailSelector
706if ($dirins && $action == 'initemailing' && !empty($module) && $user->hasRight("modulebuilder", "run")) {
707 dol_mkdir($dirins.'/'.strtolower($module).'/core/modules/mailings');
708 $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
709 $srcfile = $srcdir.'/core/modules/mailings/mailing_mymodule_selector1.modules.php';
710 $destfile = $dirins.'/'.strtolower($module).'/core/modules/mailings/mailing_'.strtolower($module).'_selector1.modules.php';
711 $result = dol_copy($srcfile, $destfile, '0', 0);
712
713 if ($result > 0) {
714 $modulename = ucfirst($module); // Force first letter in uppercase
715
716 //var_dump($phpfileval['fullname']);
717 $arrayreplacement = array(
718 'mymodule' => strtolower($modulename),
719 'MyModule' => $modulename,
720 'MYMODULE' => strtoupper($modulename),
721 'My module' => $modulename,
722 'my module' => $modulename,
723 'Mon module' => $modulename,
724 'mon module' => $modulename,
725 'htdocs/modulebuilder/template' => strtolower($modulename),
726 '---Replace with your own copyright and developer email---' => getLicenceHeader($user, $langs, $now)
727 );
728
729 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
730 dolReplaceInFile($destfile, $arrayreplacement);
731 } else {
732 $langs->load("errors");
733 setEventMessages($langs->trans('ErrorFailToCreateFile', $destfile), null, 'errors');
734 }
735}
736
737
738// init CSS
739if ($dirins && $action == 'initcss' && !empty($module) && $user->hasRight("modulebuilder", "run")) {
740 dol_mkdir($dirins.'/'.strtolower($module).'/css');
741 $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
742 $srcfile = $srcdir.'/css/mymodule.css.php';
743 $destfile = $dirins.'/'.strtolower($module).'/css/'.strtolower($module).'.css.php';
744 $result = dol_copy($srcfile, $destfile, '0', 0);
745
746 if ($result > 0) {
747 $modulename = ucfirst($module); // Force first letter in uppercase
748
749 //var_dump($phpfileval['fullname']);
750 $arrayreplacement = array(
751 'mymodule' => strtolower($modulename),
752 'MyModule' => $modulename,
753 'MYMODULE' => strtoupper($modulename),
754 'My module' => $modulename,
755 'my module' => $modulename,
756 'Mon module' => $modulename,
757 'mon module' => $modulename,
758 'htdocs/modulebuilder/template' => strtolower($modulename),
759 '---Replace with your own copyright and developer email---' => getLicenceHeader($user, $langs, $now)
760 );
761
762 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
763 dolReplaceInFile($destfile, $arrayreplacement);
764
765 // Update descriptor file to uncomment file
766 $srcfile = $dirins.'/'.strtolower($module).'/core/modules/mod'.$module.'.class.php';
767 $arrayreplacement = array('/\/\/\s*\''.preg_quote('/'.strtolower($module).'/css/'.strtolower($module).'.css.php', '/').'\'/' => '\'/'.strtolower($module).'/css/'.strtolower($module).'.css.php\'');
768 dolReplaceInFile($srcfile, $arrayreplacement, '', '0', 0, 1);
769 } else {
770 $langs->load("errors");
771 setEventMessages($langs->trans('ErrorFailToCreateFile', $destfile), null, 'errors');
772 }
773}
774
775
776// init JS
777if ($dirins && $action == 'initjs' && !empty($module) && $user->hasRight("modulebuilder", "run")) {
778 dol_mkdir($dirins.'/'.strtolower($module).'/js');
779 $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
780 $srcfile = $srcdir.'/js/mymodule.js.php';
781 $destfile = $dirins.'/'.strtolower($module).'/js/'.strtolower($module).'.js.php';
782 $result = dol_copy($srcfile, $destfile, '0', 0);
783
784 if ($result > 0) {
785 $modulename = ucfirst($module); // Force first letter in uppercase
786
787 //var_dump($phpfileval['fullname']);
788 $arrayreplacement = array(
789 'mymodule' => strtolower($modulename),
790 'MyModule' => $modulename,
791 'MYMODULE' => strtoupper($modulename),
792 'My module' => $modulename,
793 'my module' => $modulename,
794 'Mon module' => $modulename,
795 'mon module' => $modulename,
796 'htdocs/modulebuilder/template' => strtolower($modulename),
797 '---Replace with your own copyright and developer email---' => getLicenceHeader($user, $langs, $now)
798 );
799
800 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
801 dolReplaceInFile($destfile, $arrayreplacement);
802
803 // Update descriptor file to uncomment file
804 $srcfile = $dirins.'/'.strtolower($module).'/core/modules/mod'.$module.'.class.php';
805 $arrayreplacement = array('/\/\/\s*\''.preg_quote('/'.strtolower($module).'/js/'.strtolower($module).'.js.php', '/').'\'/' => '\'/'.strtolower($module).'/js/'.strtolower($module).'.js.php\'');
806 dolReplaceInFile($srcfile, $arrayreplacement, '', '0', 0, 1);
807 } else {
808 $langs->load("errors");
809 setEventMessages($langs->trans('ErrorFailToCreateFile', $destfile), null, 'errors');
810 }
811}
812
813
814// init CLI
815if ($dirins && $action == 'initcli' && !empty($module) && $user->hasRight("modulebuilder", "run")) {
816 dol_mkdir($dirins.'/'.strtolower($module).'/scripts');
817 $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
818 $srcfile = $srcdir.'/scripts/mymodule.php';
819 $destfile = $dirins.'/'.strtolower($module).'/scripts/'.strtolower($module).'.php';
820 $result = dol_copy($srcfile, $destfile, '0', 0);
821
822 if ($result > 0) {
823 $modulename = ucfirst($module); // Force first letter in uppercase
824
825 //var_dump($phpfileval['fullname']);
826 $arrayreplacement = array(
827 'mymodule' => strtolower($modulename),
828 'MyModule' => $modulename,
829 'MYMODULE' => strtoupper($modulename),
830 'My module' => $modulename,
831 'my module' => $modulename,
832 'Mon module' => $modulename,
833 'mon module' => $modulename,
834 'htdocs/modulebuilder/template' => strtolower($modulename),
835 '__MYCOMPANY_NAME__' => $mysoc->name,
836 '__KEYWORDS__' => $modulename,
837 '__USER_FULLNAME__' => $user->getFullName($langs),
838 '__USER_EMAIL__' => $user->email,
839 '__YYYY-MM-DD__' => dol_print_date($now, 'dayrfc'),
840 '---Replace with your own copyright and developer email---' => getLicenceHeader($user, $langs, $now)
841 );
842
843 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
844 dolReplaceInFile($destfile, $arrayreplacement);
845 } else {
846 $langs->load("errors");
847 setEventMessages($langs->trans('ErrorFailToCreateFile', $destfile), null, 'errors');
848 }
849}
850
851
852$moduledescriptorfile = '/not_set/';
853
854// init Doc
855if ($dirins && $action == 'initdoc' && !empty($module) && $user->hasRight("modulebuilder", "run")) {
856 dol_mkdir($dirins.'/'.strtolower($module).'/doc');
857 $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
858 $srcfile = $srcdir.'/doc/Documentation.asciidoc';
859 $destfile = $dirins.'/'.strtolower($module).'/doc/Documentation.asciidoc';
860 $result = dol_copy($srcfile, $destfile, '0', 0);
861
862 if ($result > 0) {
863 $modulename = ucfirst($module); // Force first letter in uppercase
864 $modulelowercase = strtolower($module);
865
866 //var_dump($phpfileval['fullname']);
867 $arrayreplacement = array(
868 'mymodule' => strtolower($modulename),
869 'MyModule' => $modulename,
870 'MYMODULE' => strtoupper($modulename),
871 'My module' => $modulename,
872 'my module' => $modulename,
873 'Mon module' => $modulename,
874 'mon module' => $modulename,
875 'htdocs/modulebuilder/template' => strtolower($modulename),
876 '__MYCOMPANY_NAME__' => $mysoc->name,
877 '__KEYWORDS__' => $modulename,
878 '__USER_FULLNAME__' => $user->getFullName($langs),
879 '__USER_EMAIL__' => $user->email,
880 '__YYYY-MM-DD__' => dol_print_date($now, 'dayrfc'),
881 '---Replace with your own copyright and developer email---' => getLicenceHeader($user, $langs, $now)
882 );
883
884 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
885 dolReplaceInFile($destfile, $arrayreplacement);
886
887 // add table of properties
888 $dirins = $listofmodules[strtolower($module)]['moduledescriptorrootpath'];
889 $destdir = $dirins.'/'.strtolower($module);
890 $objects = dolGetListOfObjectClasses($destdir);
891 foreach ($objects as $path => $obj) {
892 writePropsInAsciiDoc($path, $obj, $destfile);
893 }
894
895 // add table of permissions
896 $moduledescriptorfile = $dirins.'/'.strtolower($module).'/core/modules/mod'.$module.'.class.php';
897 writePermsInAsciiDoc($moduledescriptorfile, $destfile);
898
899 // add api urls if file exist
900 if (file_exists($dirins.'/'.strtolower($module).'/class/api_'.strtolower($module).'.class.php')) {
901 $apiFile = $dirins.'/'.strtolower($module).'/class/api_'.strtolower($module).'.class.php';
902 writeApiUrlsInDoc($apiFile, $destfile);
903 }
904
905 // add ChangeLog in Doc
906 if (file_exists($dirins.'/'.strtolower($module).'/ChangeLog.md')) {
907 $changeLog = $dirins.'/'.strtolower($module).'/ChangeLog.md';
908 $string = file_get_contents($changeLog);
909
910 $replace = explode("\n", $string);
911 $strreplace = array();
912 foreach ($replace as $line) {
913 if ($line === '') {
914 continue;
915 }
916 if (strpos($line, '##') !== false) {
917 $strreplace[$line] = str_replace('##', '', $line);
918 } else {
919 $strreplace[$line] = $line;
920 }
921 }
922 $stringLog = implode("\n", $strreplace);
923 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
924 dolReplaceInFile($destfile, array('//include::ChangeLog.md[]' => '','__CHANGELOG__' => $stringLog));
925 }
926
927 // Delete old documentation files
928 $FILENAMEDOC = $modulelowercase.'.html';
929 $FILENAMEDOCPDF = $modulelowercase.'.pdf';
930 $outputfiledoc = dol_buildpath($modulelowercase, 0).'/doc/'.$FILENAMEDOC;
931 $outputfiledocurl = dol_buildpath($modulelowercase, 1).'/doc/'.$FILENAMEDOC;
932 $outputfiledocpdf = dol_buildpath($modulelowercase, 0).'/doc/'.$FILENAMEDOCPDF;
933 $outputfiledocurlpdf = dol_buildpath($modulelowercase, 1).'/doc/'.$FILENAMEDOCPDF;
934
935 dol_delete_file($outputfiledoc, 0, 0, 0, null, false, 0);
936 dol_delete_file($outputfiledocpdf, 0, 0, 0, null, false, 0);
937 } else {
938 $langs->load("errors");
939 setEventMessages($langs->trans('ErrorFailToCreateFile', $destfile), null, 'errors');
940 }
941}
942
943
944// add Language
945if ($dirins && $action == 'addlanguage' && !empty($module) && $user->hasRight("modulebuilder", "run")) {
946 $newlangcode = GETPOST('newlangcode', 'aZ09');
947
948 if ($newlangcode) {
949 $modulelowercase = strtolower($module);
950
951 // Dir for module
952 $diroflang = dol_buildpath($modulelowercase, 0);
953
954 if ($diroflang == $dolibarr_main_document_root.'/'.$modulelowercase) {
955 // This is not a custom module, we force diroflang to htdocs root
956 $diroflang = $dolibarr_main_document_root;
957
958 $srcfile = $diroflang.'/langs/en_US/'.$modulelowercase.'.lang';
959 $destfile = $diroflang.'/langs/'.$newlangcode.'/'.$modulelowercase.'.lang';
960
961 $result = dol_copy($srcfile, $destfile, '0', 0);
962 if ($result < 0) {
963 setEventMessages($langs->trans("ErrorFailToCopyFile", $srcfile, $destfile), null, 'errors');
964 }
965 } else {
966 $srcdir = $diroflang.'/langs/en_US';
967 $srcfile = $diroflang.'/langs/en_US/'.$modulelowercase.'.lang';
968 $destdir = $diroflang.'/langs/'.$newlangcode;
969
970 $arrayofreplacement = array();
971 if (!dol_is_dir($srcfile) || !dol_is_file($srcfile)) {
972 $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template/langs/en_US';
973 $arrayofreplacement = array('mymodule' => $modulelowercase);
974 }
975 $result = dolCopyDir($srcdir, $destdir, '0', 0, $arrayofreplacement);
976 }
977 } else {
978 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Language")), null, 'errors');
979 }
980}
981
982
983// Remove/delete File
984if ($dirins && $action == 'confirm_removefile' && !empty($module) && $user->hasRight("modulebuilder", "run")) {
985 $objectname = $tabobj;
986 $dirins = $listofmodules[strtolower($module)]['moduledescriptorrootpath'];
987 $destdir = $dirins.'/'.strtolower($module);
988
989 $relativefilename = dol_sanitizePathName(GETPOST('file', 'restricthtml'));
990
991 // Now we delete the file
992 if ($relativefilename) {
993 $dirnametodelete = dirname($relativefilename);
994 $filetodelete = $dirins.'/'.$relativefilename;
995 $dirtodelete = $dirins.'/'.$dirnametodelete;
996
997 // Get list of existing objects
998 $objects = dolGetListOfObjectClasses($destdir);
999
1000 $keyofobjecttodelete = array_search($objectname, $objects);
1001 if ($keyofobjecttodelete !== false) {
1002 unset($objects[$keyofobjecttodelete]);
1003 }
1004
1005 // Delete or modify the file
1006 if (strpos($relativefilename, 'api') !== false) {
1007 $file_api = $destdir.'/class/api_'.strtolower($module).'.class.php';
1008
1009 $removeFile = removeObjectFromApiFile($file_api, $objects, $objectname);
1010
1011 if (count($objects) == 0) {
1012 $result = dol_delete_file($filetodelete);
1013 }
1014
1015 if ($removeFile) {
1016 setEventMessages($langs->trans("ApiObjectDeleted"), null);
1017 }
1018 } else {
1019 $result = dol_delete_file($filetodelete);
1020 }
1021
1022 if (!$result) {
1023 setEventMessages($langs->trans("ErrorFailToDeleteFile", basename($filetodelete)), null, 'errors');
1024 } else {
1025 // If we delete a .sql file, we delete also the other .sql file
1026 if (preg_match('/\.sql$/', $relativefilename)) {
1027 if (preg_match('/\.key\.sql$/', $relativefilename)) {
1028 $relativefilename = preg_replace('/\.key\.sql$/', '.sql', $relativefilename);
1029 $filetodelete = $dirins.'/'.$relativefilename;
1030 $result = dol_delete_file($filetodelete);
1031 } elseif (preg_match('/\.sql$/', $relativefilename)) {
1032 $relativefilename = preg_replace('/\.sql$/', '.key.sql', $relativefilename);
1033 $filetodelete = $dirins.'/'.$relativefilename;
1034 $result = dol_delete_file($filetodelete);
1035 }
1036 }
1037
1038 if (dol_is_dir_empty($dirtodelete)) {
1039 dol_delete_dir($dirtodelete);
1040 }
1041
1042 // Update descriptor file to comment file
1043 if (in_array($tab, array('css', 'js'))) {
1044 $srcfile = $dirins.'/'.strtolower($module).'/core/modules/mod'.$module.'.class.php';
1045 $arrayreplacement = array('/^\s*\''.preg_quote('/'.$relativefilename, '/').'\',*/m' => ' // \'/'.$relativefilename.'\',');
1046 dolReplaceInFile($srcfile, $arrayreplacement, '', '0', 0, 1);
1047 }
1048
1049 if (preg_match('/_extrafields/', $relativefilename)) {
1050 // Now we update the object file to set $isextrafieldmanaged to 0
1051 $srcfile = $dirins.'/'.strtolower($module).'/class/'.strtolower($objectname).'.class.php';
1052 $arrayreplacement = array('/\$isextrafieldmanaged = 1;/' => '$isextrafieldmanaged = 0;');
1053 dolReplaceInFile($srcfile, $arrayreplacement, '', '0', 0, 1);
1054 }
1055
1056 // Now we update the lib file to set $showtabofpagexxx to 0
1057 $varnametoupdate = '';
1058 $reg = array();
1059 if (preg_match('/_([a-z]+)\.php$/', $relativefilename, $reg)) {
1060 $varnametoupdate = 'showtabofpage'.$reg[1];
1061 }
1062 if ($varnametoupdate) {
1063 $srcfile = $dirins.'/'.strtolower($module).'/lib/'.strtolower($module).'_'.strtolower($objectname).'.lib.php';
1064 $arrayreplacement = array('/\$'.preg_quote($varnametoupdate, '/').' = 1;/' => '$'.preg_quote($varnametoupdate, '/').' = 0;');
1065 dolReplaceInFile($srcfile, $arrayreplacement, '', '0', 0, 1);
1066 }
1067 }
1068 }
1069}
1070
1071// Init an object
1072if ($dirins && $action == 'initobject' && $module && $objectname && $user->hasRight("modulebuilder", "run")) {
1073 $warning = 0;
1074
1075 $objectname = ucfirst($objectname);
1076
1077 $dirins = $dirread = $listofmodules[strtolower($module)]['moduledescriptorrootpath'];
1078 $moduletype = $listofmodules[strtolower($module)]['moduletype'];
1079
1080 if (preg_match('/[^a-z0-9_]/i', $objectname)) {
1081 $error++;
1082 setEventMessages($langs->trans("SpaceOrSpecialCharAreNotAllowed"), null, 'errors');
1083 $tabobj = 'newobject';
1084 }
1085 if (class_exists($objectname)) {
1086 // TODO Add a more efficient detection. Scan disk ?
1087 $error++;
1088 setEventMessages($langs->trans("AnObjectWithThisClassNameAlreadyExists"), null, 'errors');
1089 $tabobj = 'newobject';
1090 }
1091
1092 $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
1093 $destdir = $dirins.'/'.strtolower($module);
1094
1095 // The dir was not created by init
1096 dol_mkdir($destdir.'/class');
1097 dol_mkdir($destdir.'/img');
1098 dol_mkdir($destdir.'/lib');
1099 dol_mkdir($destdir.'/scripts');
1100 dol_mkdir($destdir.'/sql');
1101 dol_mkdir($destdir.'/ajax');
1102
1103 // Scan dir class to find if an object with the same name already exists.
1104 if (!$error) {
1105 $dirlist = dol_dir_list($destdir.'/class', 'files', 0, '\.txt$');
1106 $alreadyfound = false;
1107 foreach ($dirlist as $key => $val) {
1108 $filefound = preg_replace('/\.txt$/', '', $val['name']);
1109 if (strtolower($objectname) == strtolower($filefound) && $objectname != $filefound) {
1110 $alreadyfound = true;
1111 $error++;
1112 setEventMessages($langs->trans("AnObjectAlreadyExistWithThisNameAndDiffCase"), null, 'errors');
1113 break;
1114 }
1115 }
1116 }
1117
1118 // If we must reuse an existing table for properties, define $stringforproperties
1119 // Generate class file from the table
1120 $stringforproperties = '';
1121 $tablename = GETPOST('initfromtablename', 'alpha');
1122 if ($tablename) {
1123 $_results = $db->DDLDescTable($tablename);
1124 if (empty($_results)) {
1125 $error++;
1126 $langs->load("errors");
1127 setEventMessages($langs->trans("ErrorTableNotFound", $tablename), null, 'errors');
1128 } else {
1156 /*public $fields=array(
1157 'rowid' => array('type' => 'integer', 'label' => 'TechnicalID', 'enabled' => 1, 'visible' => -2, 'notnull' => 1, 'index' => 1, 'position' => 1, 'comment' => 'Id'),
1158 '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'),
1159 'entity' => array('type' => 'integer', 'label' => 'Entity', 'enabled' => 1, 'visible' => 0, 'default' => 1, 'notnull' => 1, 'index' => 1, 'position' => 20),
1160 'label' => array('type' => 'varchar(255)', 'label' => 'Label', 'enabled' => 1, 'visible' => 1, 'position' => 30, 'searchall' => 1, 'css' => 'minwidth200', 'help' => 'Help text', 'alwayseditable' => '1'),
1161 'amount' => array('type' => 'double(24,8)', 'label' => 'Amount', 'enabled' => 1, 'visible' => 1, 'default' => 'null', 'position' => 40, 'searchall' => 0, 'isameasure' => 1, 'help' => 'Help text'),
1162 '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'),
1163 'description' => array('type' => 'text', 'label' => 'Descrption', 'enabled' => 1, 'visible' => 0, 'position' => 60),
1164 'note_public' => array('type' => 'html', 'label' => 'NotePublic', 'enabled' => 1, 'visible' => 0, 'position' => 61),
1165 'note_private' => array('type' => 'html', 'label' => 'NotePrivate', 'enabled' => 1, 'visible' => 0, 'position' => 62),
1166 'date_creation' => array('type' => 'datetime', 'label' => 'DateCreation', 'enabled' => 1, 'visible' => -2, 'notnull' => 1, 'position' => 500),
1167 'tms' => array('type' => 'timestamp', 'label' => 'DateModification', 'enabled' => 1, 'visible' => -2, 'notnull' => 1, 'position' => 501),
1168 //'date_valid' => array('type' => 'datetime', 'label' => 'DateCreation', 'enabled' => 1, 'visible' => -2, 'position' => 502),
1169 'fk_user_creat' => array('type' => 'integer', 'label' => 'UserAuthor', 'enabled' => 1, 'visible' => -2, 'notnull' => 1, 'position' => 510),
1170 'fk_user_modif' => array('type' => 'integer', 'label' => 'UserModif', 'enabled' => 1, 'visible' => -2, 'notnull' => -1, 'position' => 511),
1171 //'fk_user_valid' => array('type' => 'integer', 'label' => 'UserValidation', 'enabled' => 1, 'visible' => -1, 'position' => 512),
1172 'import_key' => array('type' => 'varchar(14)', 'label' => 'ImportId', 'enabled' => 1, 'visible' => -2, 'notnull' => -1, 'index' => 0, 'position' => 1000),
1173 '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')),
1174 );*/
1175
1176 $stringforproperties = '// BEGIN MODULEBUILDER PROPERTIES'."\n";
1177 $stringforproperties .= 'public $fields = array('."\n";
1178 $i = 10;
1179 while ($obj = $db->fetch_object($_results)) {
1180 // fieldname
1181 $fieldname = $obj->Field;
1182 // type
1183 $type = $obj->Type;
1184 if ($type == 'int(11)') {
1185 $type = 'integer';
1186 }
1187 if ($type == 'float') {
1188 $type = 'real';
1189 }
1190 if (strstr($type, 'tinyint')) {
1191 $type = 'integer';
1192 }
1193 if ($obj->Field == 'fk_soc') {
1194 $type = 'integer:Societe:societe/class/societe.class.php';
1195 }
1196 if (preg_match('/^fk_proj/', $obj->Field)) {
1197 $type = 'integer:Project:projet/class/project.class.php:1:fk_statut=1';
1198 }
1199 if (preg_match('/^fk_prod/', $obj->Field)) {
1200 $type = 'integer:Product:product/class/product.class.php:1';
1201 }
1202 if ($obj->Field == 'fk_warehouse') {
1203 $type = 'integer:Entrepot:product/stock/class/entrepot.class.php';
1204 }
1205 if (preg_match('/^(fk_user|fk_commercial)/', $obj->Field)) {
1206 $type = 'integer:User:user/class/user.class.php';
1207 }
1208
1209 // notnull
1210 $notnull = ($obj->Null == 'YES' ? 0 : 1);
1211 if ($fieldname == 'fk_user_modif') {
1212 $notnull = -1;
1213 }
1214 // label
1215 $label = preg_replace('/_/', '', ucfirst($fieldname));
1216 if ($fieldname == 'rowid') {
1217 $label = 'TechnicalID';
1218 }
1219 if ($fieldname == 'import_key') {
1220 $label = 'ImportId';
1221 }
1222 if ($fieldname == 'fk_soc') {
1223 $label = 'ThirdParty';
1224 }
1225 if ($fieldname == 'tms') {
1226 $label = 'DateModification';
1227 }
1228 if ($fieldname == 'datec') {
1229 $label = 'DateCreation';
1230 }
1231 if ($fieldname == 'date_valid') {
1232 $label = 'DateValidation';
1233 }
1234 if ($fieldname == 'datev') {
1235 $label = 'DateValidation';
1236 }
1237 if ($fieldname == 'note_private') {
1238 $label = 'NotePublic';
1239 }
1240 if ($fieldname == 'note_public') {
1241 $label = 'NotePrivate';
1242 }
1243 if ($fieldname == 'fk_user_creat') {
1244 $label = 'UserAuthor';
1245 }
1246 if ($fieldname == 'fk_user_modif') {
1247 $label = 'UserModif';
1248 }
1249 if ($fieldname == 'fk_user_valid') {
1250 $label = 'UserValidation';
1251 }
1252 // visible
1253 $visible = -1;
1254 if (in_array($fieldname, array('ref', 'label'))) {
1255 $visible = 1;
1256 }
1257 if ($fieldname == 'entity') {
1258 $visible = -2;
1259 }
1260 if ($fieldname == 'entity') {
1261 $visible = -2;
1262 }
1263 if ($fieldname == 'import_key') {
1264 $visible = -2;
1265 }
1266 if ($fieldname == 'fk_user_creat') {
1267 $visible = -2;
1268 }
1269 if ($fieldname == 'fk_user_modif') {
1270 $visible = -2;
1271 }
1272 if (in_array($fieldname, array('ref_ext', 'model_pdf', 'note_public', 'note_private'))) {
1273 $visible = 0;
1274 }
1275 // enabled
1276 $enabled = 1;
1277 // default
1278 $default = '';
1279 if ($fieldname == 'entity') {
1280 $default = 1;
1281 }
1282 // position
1283 $position = $i;
1284 if (in_array($fieldname, array('status', 'statut', 'fk_status', 'fk_statut'))) {
1285 $position = 500;
1286 }
1287 if ($fieldname == 'import_key') {
1288 $position = 900;
1289 }
1290 // $alwayseditable
1291 $alwayseditable=0;
1292 if ($fieldname == 'label') {
1293 $alwayseditable = 1;
1294 } else {
1295 $alwayseditable = 0;
1296 }
1297 // index
1298 $index = 0;
1299 if ($fieldname == 'entity') {
1300 $index = 1;
1301 }
1302 // css, cssview, csslist
1303 $css = '';
1304 $cssview = '';
1305 $csslist = '';
1306 if (preg_match('/^fk_/', $fieldname)) {
1307 $css = 'maxwidth500 widthcentpercentminusxx';
1308 }
1309 if ($fieldname == 'label') {
1310 $css = 'minwidth300';
1311 $cssview = 'wordbreak';
1312 }
1313 if (in_array($fieldname, array('note_public', 'note_private'))) {
1314 $cssview = 'wordbreak';
1315 }
1316 if (in_array($fieldname, array('ref', 'label')) || preg_match('/integer:/', $type)) {
1317 $csslist = 'tdoverflowmax150';
1318 }
1319
1320 // type
1321 if (isset($obj->Picto)) {
1322 $picto = $obj->Picto;
1323 }
1324 if ($obj->Field == 'fk_soc') {
1325 $picto = 'company';
1326 }
1327 if (preg_match('/^fk_proj/', $obj->Field)) {
1328 $picto = 'project';
1329 }
1330
1331 // Build the property string
1332 $stringforproperties .= "'".$obj->Field."' => array('type' => '".$type."', 'label' => '".$label."',";
1333 if ($default != '') {
1334 $stringforproperties .= " 'default' => ".$default.",";
1335 }
1336 $stringforproperties .= " 'enabled' => ".$enabled.",";
1337 $stringforproperties .= " 'visible' => ".$visible;
1338 if ($notnull) {
1339 $stringforproperties .= ", 'notnull' => ".$notnull;
1340 }
1341 if ($alwayseditable) {
1342 $stringforproperties .= ", 'alwayseditable' => 1";
1343 }
1344 if ($fieldname == 'ref' || $fieldname == 'code') {
1345 $stringforproperties .= ", 'showoncombobox' => 1";
1346 }
1347 $stringforproperties .= ", 'position' => ".$position;
1348 if ($index) {
1349 $stringforproperties .= ", 'index' => ".$index;
1350 }
1351 if ($picto) {
1352 $stringforproperties .= ", 'picto' => '".$picto."'";
1353 }
1354 if ($css) {
1355 $stringforproperties .= ", 'css' => '".$css."'";
1356 }
1357 if ($cssview) {
1358 $stringforproperties .= ", 'cssview' => '".$cssview."'";
1359 }
1360 if ($csslist) {
1361 $stringforproperties .= ", 'csslist' => '".$csslist."'";
1362 }
1363 $stringforproperties .= "),\n";
1364 $i += 5;
1365 }
1366 $stringforproperties .= ');'."\n";
1367 $stringforproperties .= '// END MODULEBUILDER PROPERTIES'."\n";
1368 }
1369 }
1370
1371 $filetogenerate = array(); // For static analysis
1372 if (!$error) {
1373 // Copy some files
1374 $filetogenerate = array(
1375 'myobject_card.php' => strtolower($objectname).'_card.php',
1376 'myobject_note.php' => strtolower($objectname).'_note.php',
1377 'myobject_contact.php' => strtolower($objectname).'_contact.php',
1378 'myobject_document.php' => strtolower($objectname).'_document.php',
1379 'myobject_agenda.php' => strtolower($objectname).'_agenda.php',
1380 'myobject_list.php' => strtolower($objectname).'_list.php',
1381 'admin/myobject_extrafields.php' => 'admin/'.strtolower($objectname).'_extrafields.php',
1382 'lib/mymodule_myobject.lib.php' => 'lib/'.strtolower($module).'_'.strtolower($objectname).'.lib.php',
1383 //'test/phpunit/MyObjectTest.php' => 'test/phpunit/'.strtolower($objectname).'Test.php',
1384 'sql/llx_mymodule_myobject.sql' => 'sql/llx_'.strtolower($module).'_'.strtolower($objectname).'.sql',
1385 'sql/llx_mymodule_myobject.key.sql' => 'sql/llx_'.strtolower($module).'_'.strtolower($objectname).'.key.sql',
1386 'sql/llx_mymodule_myobject_extrafields.sql' => 'sql/llx_'.strtolower($module).'_'.strtolower($objectname).'_extrafields.sql',
1387 'sql/llx_mymodule_myobject_extrafields.key.sql' => 'sql/llx_'.strtolower($module).'_'.strtolower($objectname).'_extrafields.key.sql',
1388 //'scripts/mymodule.php' => 'scripts/'.strtolower($objectname).'.php',
1389 'class/myobject.class.php' => 'class/'.strtolower($objectname).'.class.php',
1390 //'class/api_mymodule.class.php' => 'class/api_'.strtolower($module).'.class.php',
1391 'ajax/myobject.php' => 'ajax/'.strtolower($objectname).'.php',
1392 );
1393
1394 if (GETPOST('includerefgeneration', 'aZ09')) {
1395 dol_mkdir($destdir.'/core/modules/'.strtolower($module));
1396
1397 $filetogenerate += array(
1398 'core/modules/mymodule/mod_myobject_advanced.php' => 'core/modules/'.strtolower($module).'/mod_'.strtolower($objectname).'_advanced.php',
1399 'core/modules/mymodule/mod_myobject_standard.php' => 'core/modules/'.strtolower($module).'/mod_'.strtolower($objectname).'_standard.php',
1400 'core/modules/mymodule/modules_myobject.php' => 'core/modules/'.strtolower($module).'/modules_'.strtolower($objectname).'.php',
1401 );
1402 }
1403 if (GETPOST('includedocgeneration', 'aZ09')) {
1404 dol_mkdir($destdir.'/core/modules/'.strtolower($module));
1405 dol_mkdir($destdir.'/core/modules/'.strtolower($module).'/doc');
1406
1407 $filetogenerate += array(
1408 'core/modules/mymodule/doc/doc_generic_myobject_odt.modules.php' => 'core/modules/'.strtolower($module).'/doc/doc_generic_'.strtolower($objectname).'_odt.modules.php',
1409 'core/modules/mymodule/doc/pdf_standard_myobject.modules.php' => 'core/modules/'.strtolower($module).'/doc/pdf_standard_'.strtolower($objectname).'.modules.php'
1410 );
1411 }
1412 if (GETPOST('generatepermissions', 'aZ09')) {
1413 $firstobjectname = 'myobject';
1414 $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
1415 dol_include_once($pathtofile);
1416 $class = 'mod'.$module;
1417 $moduleobj = null;
1418 if (class_exists($class)) {
1419 try {
1420 $moduleobj = new $class($db);
1421 '@phan-var-force DolibarrModules $moduleobj';
1423 } catch (Exception $e) {
1424 $error++;
1425 dol_print_error($db, $e->getMessage());
1426 }
1427 }
1428 if (is_object($moduleobj)) {
1429 $rights = $moduleobj->rights;
1430 } else {
1431 $rights = [];
1432 }
1433 $moduledescriptorfile = $destdir.'/core/modules/mod'.$module.'.class.php';
1434 $checkComment = checkExistComment($moduledescriptorfile, 1);
1435 if ($checkComment < 0) {
1436 setEventMessages($langs->trans("WarningCommentNotFound", $langs->trans("Permissions"), "mod".$module."class.php"), null, 'warnings');
1437 } else {
1438 $generatePerms = reWriteAllPermissions($moduledescriptorfile, $rights, null, null, $objectname, $module, -2);
1439 if ($generatePerms < 0) {
1440 setEventMessages($langs->trans("WarningPermissionAlreadyExist", $langs->transnoentities($objectname)), null, 'warnings');
1441 }
1442 }
1443 }
1444
1445 if (!$error) {
1446 foreach ($filetogenerate as $srcfile => $destfile) {
1447 $result = dol_copy($srcdir.'/'.$srcfile, $destdir.'/'.$destfile, $newmask, 0);
1448 if ($result <= 0) {
1449 if ($result < 0) {
1450 $warning++;
1451 $langs->load("errors");
1452 setEventMessages($langs->trans("ErrorFailToCopyFile", $srcdir.'/'.$srcfile, $destdir.'/'.$destfile), null, 'errors');
1453 } else {
1454 // $result == 0
1455 setEventMessages($langs->trans("FileAlreadyExists", $destfile), null, 'warnings');
1456 }
1457 }
1458 $arrayreplacement = array(
1459 '/myobject\.class\.php/' => strtolower($objectname).'.class.php',
1460 '/myobject\.lib\.php/' => strtolower($objectname).'.lib.php',
1461 );
1462
1463 dolReplaceInFile($destdir.'/'.$destfile, $arrayreplacement, '', '0', 0, 1);
1464 }
1465 }
1466
1467 // Replace property section with $stringforproperties
1468 if (!$error && $stringforproperties) {
1469 //var_dump($stringforproperties);exit;
1470 $arrayreplacement = array(
1471 '/\/\/ BEGIN MODULEBUILDER PROPERTIES.*\/\/ END MODULEBUILDER PROPERTIES/ims' => $stringforproperties
1472 );
1473
1474 dolReplaceInFile($destdir.'/class/'.strtolower($objectname).'.class.php', $arrayreplacement, '', '0', 0, 1);
1475 }
1476
1477 // Edit the class 'class/'.strtolower($objectname).'.class.php'
1478 if (GETPOST('includerefgeneration', 'aZ09')) {
1479 // Replace 'visible' => 1, 'noteditable' => 0, 'default' => ''
1480 $arrayreplacement = array(
1481 '/\'visible\'s*=>s*1,\s*\'noteditable\'s*=>s*0,\s*\'default\'s*=>s*\'\'/' => "'visible' => 4, 'noteditable' => 1, 'default' => '(PROV)'"
1482 );
1483 //var_dump($arrayreplacement);exit;
1484 //var_dump($destdir.'/class/'.strtolower($objectname).'.class.php');exit;
1485 dolReplaceInFile($destdir.'/class/'.strtolower($objectname).'.class.php', $arrayreplacement, '', '0', 0, 1);
1486
1487 $arrayreplacement = array(
1488 '/\'models\' => 0,/' => '\'models\' => 1,'
1489 );
1490 dolReplaceInFile($destdir.'/core/modules/mod'.$module.'.class.php', $arrayreplacement, '', '0', 0, 1);
1491 }
1492
1493 // Edit the setup file and the card page
1494 if (GETPOST('includedocgeneration', 'aZ09')) {
1495 // Replace some var init into some files
1496 $arrayreplacement = array(
1497 '/\$includedocgeneration = 0;/' => '$includedocgeneration = 1;'
1498 );
1499 dolReplaceInFile($destdir.'/class/'.strtolower($objectname).'.class.php', $arrayreplacement, '', '0', 0, 1);
1500 dolReplaceInFile($destdir.'/'.strtolower($objectname).'_card.php', $arrayreplacement, '', '0', 0, 1);
1501
1502 $arrayreplacement = array(
1503 '/\'models\' => 0,/' => '\'models\' => 1,'
1504 );
1505
1506 dolReplaceInFile($destdir.'/core/modules/mod'.$module.'.class.php', $arrayreplacement, '', '0', 0, 1);
1507 }
1508
1509 // TODO Update entries '$myTmpObjects['MyObject'] = array('includerefgeneration' => 0, 'includedocgeneration' => 0);'
1510
1511
1512 // Scan for object class files
1513 $listofobject = dol_dir_list($destdir.'/class', 'files', 0, '\.class\.php$');
1514
1515 $firstobjectname = '';
1516 $stringtoadd = '';
1517 foreach ($listofobject as $fileobj) {
1518 if (preg_match('/^api_/', $fileobj['name'])) {
1519 continue;
1520 }
1521 if (preg_match('/^actions_/', $fileobj['name'])) {
1522 continue;
1523 }
1524
1525 $tmpcontent = file_get_contents($fileobj['fullname']);
1526 $reg = array();
1527 if (preg_match('/class\s+([^\s]*)\s+extends\s+CommonObject/ims', $tmpcontent, $reg)) {
1528 $objectnameloop = $reg[1];
1529 if (empty($firstobjectname)) {
1530 $firstobjectname = $objectnameloop;
1531 }
1532 }
1533
1534 // Regenerate left menu entry in descriptor for $objectname
1535 $stringtoadd = "
1536 \$this->menu[\$r++] = array(
1537 'fk_menu' => 'fk_mainmenu=mymodule',
1538 'type' => 'left',
1539 'titre' => 'MyObject',
1540 'prefix' => img_picto('', \$this->picto, 'class=\"paddingright pictofixedwidth valignmiddle\"'),
1541 'mainmenu' => 'mymodule',
1542 'leftmenu' => 'myobject',
1543 'url' => '/mymodule/myobject_list.php',
1544 'langs' => 'mymodule@mymodule',
1545 'position' => 1000 + \$r,
1546 'enabled' => 'isModEnabled(\"mymodule\")',
1547 'perms' => '".(GETPOST('generatepermissions') ? '$user->hasRight("mymodule", "myobject", "read")' : '1')."',
1548 'target' => '',
1549 'user' => 2,
1550 'object' => 'MyObject'
1551 );
1552 \$this->menu[\$r++] = array(
1553 'fk_menu' => 'fk_mainmenu=mymodule,fk_leftmenu=myobject',
1554 'type' => 'left',
1555 'titre' => 'List MyObject',
1556 'mainmenu' => 'mymodule',
1557 'leftmenu' => 'mymodule_myobject_list',
1558 'url' => '/mymodule/myobject_list.php',
1559 'langs' => 'mymodule@mymodule',
1560 'position' => 1000 + \$r,
1561 'enabled' => 'isModEnabled(\"mymodule\")',
1562 'perms' => '".(GETPOST('generatepermissions') ? '$user->hasRight("mymodule", "myobject", "read")' : '1')."',
1563 'target' => '',
1564 'user' => 2,
1565 'object' => 'MyObject'
1566 );
1567 \$this->menu[\$r++] = array(
1568 'fk_menu' => 'fk_mainmenu=mymodule,fk_leftmenu=myobject',
1569 'type' => 'left',
1570 'titre' => 'New MyObject',
1571 'mainmenu' => 'mymodule',
1572 'leftmenu' => 'mymodule_myobject_new',
1573 'url' => '/mymodule/myobject_card.php?action=create',
1574 'langs' => 'mymodule@mymodule',
1575 'position' => 1000 + \$r,
1576 'enabled' => 'isModEnabled(\"mymodule\")',
1577 'perms' => '".(GETPOST('generatepermissions') ? '$user->hasRight("mymodule", "myobject", "write")' : '1')."',
1578 'target' => '',
1579 'user' => 2,
1580 'object' => 'MyObject'
1581 );";
1582 $stringtoadd = preg_replace('/MyObject/', $objectname, $stringtoadd);
1583 $stringtoadd = preg_replace('/mymodule/', strtolower($module), $stringtoadd);
1584 $stringtoadd = preg_replace('/myobject/', strtolower($objectname), $stringtoadd);
1585
1586 $moduledescriptorfile = $destdir.'/core/modules/mod'.$module.'.class.php';
1587 }
1588 // TODO Allow a replace with regex using dolReplaceInFile with param arryreplacementisregex to 1
1589 // TODO Avoid duplicate addition
1590
1591 // load class and check if menu exist with same object name
1592 $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
1593 dol_include_once($pathtofile);
1594 $class = 'mod'.$module;
1595 $moduleobj = null;
1596 if (class_exists($class)) {
1597 try {
1598 $moduleobj = new $class($db);
1599 '@phan-var-force DolibarrModules $moduleobj';
1601 } catch (Exception $e) {
1602 $error++;
1603 dol_print_error($db, $e->getMessage());
1604 }
1605 }
1606 if (is_object($moduleobj)) {
1607 $menus = $moduleobj->menu;
1608 } else {
1609 $menus = array();
1610 }
1611 $counter = 0 ;
1612 foreach ($menus as $menu) {
1613 if ($menu['leftmenu'] == strtolower($objectname)) {
1614 $counter++;
1615 }
1616 }
1617 if (!$counter) {
1618 $checkComment = checkExistComment($moduledescriptorfile, 0);
1619 if ($checkComment < 0) {
1620 $warning++;
1621 setEventMessages($langs->trans("WarningCommentNotFound", $langs->trans("Menus"), basename($moduledescriptorfile)), null, 'warnings');
1622 } else {
1623 $arrayofreplacement = array('/* BEGIN MODULEBUILDER LEFTMENU MYOBJECT */' => '/* BEGIN MODULEBUILDER LEFTMENU '.strtoupper($objectname).' */'.$stringtoadd."\n\t\t".'/* END MODULEBUILDER LEFTMENU '.strtoupper($objectname).' */'."\n\t\t".'/* BEGIN MODULEBUILDER LEFTMENU MYOBJECT */');
1624 dolReplaceInFile($moduledescriptorfile, $arrayofreplacement);
1625 }
1626 }
1627 // Add module descriptor to list of files to replace "MyObject' string with real name of object.
1628 $filetogenerate[] = 'core/modules/mod'.$module.'.class.php';
1629 }
1630
1631 if (!$error) {
1632 // Edit PHP files to make replacement
1633 foreach ($filetogenerate as $destfile) {
1634 $phpfileval['fullname'] = $destdir.'/'.$destfile;
1635
1636 //var_dump($phpfileval['fullname']);
1637 $arrayreplacement = array(
1638 'mymodule' => strtolower($module),
1639 'MyModule' => $module,
1640 'MYMODULE' => strtoupper($module),
1641 'My module' => $module,
1642 'my module' => $module,
1643 'mon module' => $module,
1644 'Mon module' => $module,
1645 'htdocs/modulebuilder/template/' => strtolower($modulename),
1646 'myobject' => strtolower($objectname),
1647 'MyObject' => $objectname,
1648 //'MYOBJECT' => strtoupper($objectname),
1649 '---Replace with your own copyright and developer email---' => getLicenceHeader($user, $langs, $now)
1650 );
1651
1652 if (getDolGlobalString('MODULEBUILDER_SPECIFIC_AUTHOR')) {
1653 $arrayreplacement['---Replace with your own copyright and developer email---'] = dol_print_date($now, '%Y').' ' . getDolGlobalString('MODULEBUILDER_SPECIFIC_AUTHOR');
1654 }
1655
1656 $result = dolReplaceInFile($phpfileval['fullname'], $arrayreplacement);
1657 //var_dump($result);
1658 if ($result < 0) {
1659 setEventMessages($langs->trans("ErrorFailToMakeReplacementInto", $phpfileval['fullname']), null, 'errors');
1660 }
1661 }
1662 }
1663
1664 if (!$error) {
1665 // Edit the class file to write properties
1666 $object = rebuildObjectClass($destdir, $module, $objectname, $newmask);
1667
1668 if (is_numeric($object) && $object <= 0) {
1669 $pathoffiletoeditsrc = $destdir.'/class/'.strtolower($objectname).'.class.php';
1670 setEventMessages($langs->trans('ErrorFailToCreateFile', $pathoffiletoeditsrc), null, 'errors');
1671 $warning++;
1672 }
1673 // check if documentation was generate and add table of properties object
1674 $file = $destdir.'/class/'.strtolower($objectname).'.class.php';
1675 $destfile = $destdir.'/doc/Documentation.asciidoc';
1676
1677 if (file_exists($destfile)) {
1678 writePropsInAsciiDoc($file, $objectname, $destfile);
1679 }
1680 }
1681 if (!$error) {
1682 // Edit sql with new properties
1683 $result = rebuildObjectSql($destdir, $module, $objectname, $newmask, '', $object);
1684
1685 if ($result <= 0) {
1686 setEventMessages($langs->trans('ErrorFailToCreateFile', '.sql'), null);
1687 $error++;
1688 }
1689 }
1690
1691 if (!$error) {
1692 setEventMessages($langs->trans('FilesForObjectInitialized', $objectname), null);
1693 $tabobj = $objectname;
1694 } else {
1695 $tabobj = 'newobject';
1696 }
1697
1698 // check if module is enabled
1699 if (isModEnabled(strtolower($module))) {
1700 $result = unActivateModule(strtolower($module));
1701 dolibarr_set_const($db, "MAIN_IHM_PARAMS_REV", getDolGlobalInt('MAIN_IHM_PARAMS_REV') + 1, 'chaine', 0, '', $conf->entity);
1702 if ($result) {
1703 setEventMessages($result, null, 'errors');
1704 }
1705 setEventMessages($langs->trans('WarningModuleNeedRefresh', $langs->transnoentities($module)), null, 'warnings');
1706 header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=objects&module='.$module);
1707 exit;
1708 }
1709}
1710
1711// Add a dictionary
1712if ($dirins && $action == 'initdic' && $module && empty($cancel) && $user->hasRight("modulebuilder", "run")) {
1713 $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
1714 $destdir = $dirins.'/'.strtolower($module);
1715 $moduledescriptorfile = $dirins.'/'.strtolower($module).'/core/modules/mod'.$module.'.class.php';
1716
1717 if (!GETPOST('dicname')) {
1718 $error++;
1719 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Table")), null, 'errors');
1720 }
1721 if (!GETPOST('label')) {
1722 $error++;
1723 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Label")), null, 'errors');
1724 }
1725 if (!$error) {
1726 $newdicname = $dicname;
1727 if (!preg_match('/^c_/', $newdicname)) {
1728 $newdicname = 'c_'.$dicname;
1729 }
1730 dol_include_once($pathtofile);
1731 $class = 'mod'.$module;
1732
1733 if (class_exists($class)) {
1734 try {
1735 $moduleobj = new $class($db);
1736 '@phan-var-force DolibarrModules $moduleobj';
1738 } catch (Exception $e) {
1739 $error++;
1740 dol_print_error($db, $e->getMessage());
1741 }
1742 } else {
1743 $error++;
1744 $langs->load("errors");
1745 dol_print_error($db, $langs->trans("ErrorFailedToLoadModuleDescriptorForXXX", $module));
1746 exit;
1747 }
1748 $dictionaries = $moduleobj->dictionaries;
1749 $checkComment = checkExistComment($moduledescriptorfile, 2);
1750 if ($checkComment < 0) {
1751 setEventMessages($langs->trans("WarningCommentNotFound", $langs->trans("Dictionaries"), "mod".$module."class.php"), null, 'warnings');
1752 } else {
1753 createNewDictionnary($module, $moduledescriptorfile, $newdicname, $dictionaries);
1754 if (function_exists('opcache_invalidate')) {
1755 opcache_reset(); // remove the include cache hell !
1756 }
1757 clearstatcache(true);
1758 header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=dictionaries&module='.$module.($forceddirread ? '@'.$dirread : ''));
1759 exit;
1760 }
1761 }
1762}
1763
1764// Delete a SQL table
1765if ($dirins && ($action == 'droptable' || $action == 'droptableextrafields') && !empty($module) && !empty($tabobj) && $user->hasRight("modulebuilder", "run")) {
1766 $objectname = $tabobj;
1767
1768 $arrayoftables = array();
1769 if ($action == 'droptable') { // Test on permission already done
1770 $arrayoftables[] = MAIN_DB_PREFIX.strtolower($module).'_'.strtolower($tabobj);
1771 }
1772 if ($action == 'droptableextrafields') { // Test on permission already done
1773 $arrayoftables[] = MAIN_DB_PREFIX.strtolower($module).'_'.strtolower($tabobj).'_extrafields';
1774 }
1775
1776 foreach ($arrayoftables as $tabletodrop) {
1777 $nb = -1;
1778 $sql = "SELECT COUNT(*) as nb FROM ".$tabletodrop;
1779 $resql = $db->query($sql);
1780 if ($resql) {
1781 $obj = $db->fetch_object($resql);
1782 if ($obj) {
1783 $nb = $obj->nb;
1784 }
1785 } else {
1786 if ($db->lasterrno() == 'DB_ERROR_NOSUCHTABLE') {
1787 setEventMessages($langs->trans("TableDoesNotExists", $tabletodrop), null, 'warnings');
1788 } else {
1789 dol_print_error($db);
1790 }
1791 }
1792 if ($nb == 0) {
1793 $resql = $db->DDLDropTable($tabletodrop);
1794 //var_dump($resql);
1795 setEventMessages($langs->trans("TableDropped", $tabletodrop), null, 'mesgs');
1796 } elseif ($nb > 0) {
1797 setEventMessages($langs->trans("TableNotEmptyDropCanceled", $tabletodrop), null, 'warnings');
1798 }
1799 }
1800}
1801
1802if ($dirins && $action == 'addproperty' && empty($cancel) && !empty($module) && (!empty($tabobj) || !empty(GETPOST('obj'))) && $user->hasRight("modulebuilder", "run")) {
1803 $error = 0;
1804
1805 $objectname = (GETPOST('obj') ? GETPOST('obj') : $tabobj);
1806
1807 $dirins = $dirread = $listofmodules[strtolower($module)]['moduledescriptorrootpath'];
1808 $moduletype = $listofmodules[strtolower($module)]['moduletype'];
1809
1810 $srcdir = $dirread.'/'.strtolower($module);
1811 $destdir = $dirins.'/'.strtolower($module);
1812 dol_mkdir($destdir);
1813
1814 $objects = dolGetListOfObjectClasses($destdir);
1815 if (!in_array($objectname, array_values($objects))) {
1816 $error++;
1817 setEventMessages($langs->trans("ErrorObjectNotFound", $langs->transnoentities($objectname)), null, 'errors');
1818 }
1819
1820 $addfieldentry = array();
1821
1822 // We click on add property
1823 if (!GETPOST('regenerateclasssql') && !GETPOST('regeneratemissing')) {
1824 if (!GETPOST('propname', 'aZ09')) {
1825 $error++;
1826 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Name")), null, 'errors');
1827 }
1828 if (!GETPOST('proplabel', 'alpha')) {
1829 $error++;
1830 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Label")), null, 'errors');
1831 }
1832 if (!GETPOST('proptype', 'alpha')) {
1833 $error++;
1834 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Type")), null, 'errors');
1835 }
1836
1837
1838 if (!$error && !GETPOST('regenerateclasssql') && !GETPOST('regeneratemissing')) {
1839 $addfieldentry = array(
1840 'name' => GETPOST('propname', 'aZ09'),
1841 'label' => GETPOST('proplabel', 'alpha'),
1842 'type' => strtolower(GETPOST('proptype', 'alpha')),
1843 'arrayofkeyval' => GETPOST('proparrayofkeyval', 'alphawithlgt'), // Example json string '{"0":"Draft","1":"Active","-1":"Cancel"}'
1844 'visible' => GETPOST('propvisible', 'alphanohtml'),
1845 'enabled' => GETPOST('propenabled', 'alphanohtml'),
1846 'position' => GETPOSTINT('propposition'),
1847 'notnull' => GETPOSTINT('propnotnull'),
1848 'index' => GETPOSTINT('propindex'),
1849 'foreignkey' => GETPOST('propforeignkey', 'alpha'),
1850 'searchall' => GETPOSTINT('propsearchall'),
1851 'isameasure' => GETPOSTINT('propisameasure'),
1852 'comment' => GETPOST('propcomment', 'alpha'),
1853 'help' => GETPOST('prophelp', 'alpha'),
1854 'css' => GETPOST('propcss', 'alpha'), // Can be 'maxwidth500 widthcentpercentminusxx' for example
1855 'cssview' => GETPOST('propcssview', 'alpha'),
1856 'csslist' => GETPOST('propcsslist', 'alpha'),
1857 'default' => GETPOST('propdefault', 'restricthtml'),
1858 'noteditable' => GETPOSTINT('propnoteditable'),
1859 //'alwayseditable' => GETPOSTINT('propalwayseditable'),
1860 'validate' => GETPOSTINT('propvalidate')
1861 );
1862
1863 if (!empty($addfieldentry['arrayofkeyval']) && !is_array($addfieldentry['arrayofkeyval'])) {
1864 $tmpdecode = json_decode($addfieldentry['arrayofkeyval'], true);
1865 if ($tmpdecode) { // If string is already a json
1866 $addfieldentry['arrayofkeyval'] = $tmpdecode;
1867 } else { // If string is a list of lines with "key,value"
1868 $tmparray = dolExplodeIntoArray($addfieldentry['arrayofkeyval'], "\n", ",");
1869 $addfieldentry['arrayofkeyval'] = $tmparray;
1870 }
1871 }
1872 }
1873 }
1874
1875 /*if (GETPOST('regeneratemissing'))
1876 {
1877 setEventMessages($langs->trans("FeatureNotYetAvailable"), null, 'warnings');
1878 $error++;
1879 }*/
1880
1881 $moduletype = $listofmodules[strtolower($module)]['moduletype'];
1882
1883 // Edit the class file to write properties
1884 if (!$error) {
1885 $object = rebuildObjectClass($destdir, $module, $objectname, $newmask, $srcdir, $addfieldentry, $moduletype);
1886
1887 if (is_numeric($object) && $object <= 0) {
1888 $pathoffiletoeditsrc = $destdir.'/class/'.strtolower($objectname).'.class.php';
1889 setEventMessages($langs->trans('ErrorFailToCreateFile', $pathoffiletoeditsrc), null, 'errors');
1890 $error++;
1891 }
1892 }
1893
1894 // Edit sql with new properties
1895 if (!$error) {
1896 $result = rebuildObjectSql($destdir, $module, $objectname, $newmask, $srcdir, $object, $moduletype);
1897
1898 if ($result <= 0) {
1899 setEventMessages($langs->trans('ErrorFailToCreateFile', '.sql'), null, 'errors');
1900 $error++;
1901 }
1902 }
1903
1904 if (!$error) {
1905 clearstatcache(true);
1906
1907 setEventMessages($langs->trans('FilesForObjectUpdated', $objectname), null);
1908
1909 setEventMessages($langs->trans('WarningDatabaseIsNotUpdated'), null);
1910
1911 // Make a redirect to reload all data
1912 header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=objects&module='.$module.($forceddirread ? '@'.$dirread : '').'&tabobj='.$objectname.'&nocache='.time());
1913 exit;
1914 }
1915}
1916
1917if ($dirins && $action == 'confirm_deleteproperty' && $propertykey && $user->hasRight("modulebuilder", "run")) {
1918 $objectname = $tabobj;
1919
1920 $dirins = $dirread = $listofmodules[strtolower($module)]['moduledescriptorrootpath'];
1921 $moduletype = $listofmodules[strtolower($module)]['moduletype'];
1922
1923 $srcdir = $dirread.'/'.strtolower($module);
1924 $destdir = $dirins.'/'.strtolower($module);
1925 dol_mkdir($destdir);
1926
1927 // Edit the class file to write properties
1928 if (!$error) {
1929 $object = rebuildObjectClass($destdir, $module, $objectname, $newmask, $srcdir, array(), $propertykey);
1930
1931 if (is_numeric($object) && $object <= 0) {
1932 $pathoffiletoeditsrc = $destdir.'/class/'.strtolower($objectname).'.class.php';
1933 setEventMessages($langs->trans('ErrorFailToCreateFile', $pathoffiletoeditsrc), null, 'errors');
1934 $error++;
1935 }
1936 }
1937
1938 // Edit sql with new properties
1939 if (!$error) {
1940 $result = rebuildObjectSql($destdir, $module, $objectname, $newmask, $srcdir, $object);
1941
1942 if ($result <= 0) {
1943 setEventMessages($langs->trans('ErrorFailToCreateFile', '.sql'), null, 'errors');
1944 $error++;
1945 }
1946 }
1947
1948 if (!$error) {
1949 setEventMessages($langs->trans('FilesForObjectUpdated', $objectname), null);
1950
1951 clearstatcache(true);
1952
1953 // Make a redirect to reload all data
1954 header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=objects&module='.$module.($forceddirread ? '@'.$dirread : '').'&tabobj='.$objectname);
1955 exit;
1956 }
1957}
1958
1959if ($dirins && $action == 'confirm_deletemodule' && $user->hasRight("modulebuilder", "run")) {
1960 if (preg_match('/[^a-z0-9_]/i', $module)) {
1961 $error++;
1962 setEventMessages($langs->trans("SpaceOrSpecialCharAreNotAllowed"), null, 'errors');
1963 }
1964
1965 if (!$error) {
1966 $modulelowercase = strtolower($module);
1967
1968 // Dir for module
1969 $dir = $dirins.'/'.$modulelowercase;
1970
1971 $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
1972
1973 // Dir for module
1974 $dir = dol_buildpath($modulelowercase, 0);
1975
1976 // Zip file to build
1977 $FILENAMEZIP = '';
1978
1979 // Load module
1980 dol_include_once($pathtofile);
1981 $class = 'mod'.$module;
1982
1983 $moduleobj = null;
1984
1985 if (class_exists($class)) {
1986 try {
1987 $moduleobj = new $class($db);
1988 '@phan-var-force DolibarrModules $moduleobj';
1990 } catch (Exception $e) {
1991 $error++;
1992 dol_print_error($db, $e->getMessage());
1993 }
1994 } else {
1995 $error++;
1996 $langs->load("errors");
1997 setEventMessages($langs->trans("ErrorFailedToLoadModuleDescriptorForXXX", $module), null, 'warnings');
1998 }
1999
2000 if ($moduleobj) {
2001 $moduleobj->remove();
2002 }
2003
2004 $result = dol_delete_dir_recursive($dir);
2005
2006 if ($result > 0) {
2007 setEventMessages($langs->trans("DirWasRemoved", $modulelowercase), null);
2008
2009 clearstatcache(true);
2010 if (function_exists('opcache_invalidate')) {
2011 opcache_reset(); // remove the include cache hell !
2012 }
2013
2014 header("Location: ".$_SERVER["PHP_SELF"].'?module=deletemodule');
2015 exit;
2016 } else {
2017 setEventMessages($langs->trans("PurgeNothingToDelete"), null, 'warnings');
2018 }
2019 }
2020
2021 $action = '';
2022 $module = 'deletemodule';
2023}
2024
2025if ($dirins && $action == 'confirm_deleteobject' && $objectname && $user->hasRight("modulebuilder", "run")) {
2026 if (preg_match('/[^a-z0-9_]/i', $objectname)) {
2027 $error++;
2028 setEventMessages($langs->trans("SpaceOrSpecialCharAreNotAllowed"), null, 'errors');
2029 }
2030
2031 if (!$error) {
2032 $modulelowercase = strtolower($module);
2033 $objectlowercase = strtolower($objectname);
2034
2035 // Dir for module
2036 $dir = $dirins.'/'.$modulelowercase;
2037
2038 // Delete some files
2039 $filetodelete = array(
2040 'myobject_card.php' => strtolower($objectname).'_card.php',
2041 'myobject_note.php' => strtolower($objectname).'_note.php',
2042 'myobject_contact.php' => strtolower($objectname).'_contact.php',
2043 'myobject_document.php' => strtolower($objectname).'_document.php',
2044 'myobject_agenda.php' => strtolower($objectname).'_agenda.php',
2045 'myobject_list.php' => strtolower($objectname).'_list.php',
2046 'admin/myobject_extrafields.php' => 'admin/'.strtolower($objectname).'_extrafields.php',
2047 'lib/mymodule_myobject.lib.php' => 'lib/'.strtolower($module).'_'.strtolower($objectname).'.lib.php',
2048 'test/phpunit/MyObjectTest.php' => 'test/phpunit/'.strtolower($objectname).'Test.php',
2049 'sql/llx_mymodule_myobject.sql' => 'sql/llx_'.strtolower($module).'_'.strtolower($objectname).'.sql',
2050 'sql/llx_mymodule_myobject_extrafields.sql' => 'sql/llx_'.strtolower($module).'_'.strtolower($objectname).'_extrafields.sql',
2051 'sql/llx_mymodule_myobject.key.sql' => 'sql/llx_'.strtolower($module).'_'.strtolower($objectname).'.key.sql',
2052 'sql/llx_mymodule_myobject_extrafields.key.sql' => 'sql/llx_'.strtolower($module).'_'.strtolower($objectname).'_extrafields.key.sql',
2053 'scripts/myobject.php' => 'scripts/'.strtolower($objectname).'.php',
2054 'class/myobject.class.php' => 'class/'.strtolower($objectname).'.class.php',
2055 'class/api_myobject.class.php' => 'class/api_'.strtolower($module).'.class.php',
2056 'core/modules/mymodule/mod_myobject_advanced.php' => 'core/modules/'.strtolower($module).'/mod_'.strtolower($objectname).'_advanced.php',
2057 'core/modules/mymodule/mod_myobject_standard.php' => 'core/modules/'.strtolower($module).'/mod_'.strtolower($objectname).'_standard.php',
2058 'core/modules/mymodule/modules_myobject.php' => 'core/modules/'.strtolower($module).'/modules_'.strtolower($objectname).'.php',
2059 'core/modules/mymodule/doc/doc_generic_myobject_odt.modules.php' => 'core/modules/'.strtolower($module).'/doc/doc_generic_'.strtolower($objectname).'_odt.modules.php',
2060 'core/modules/mymodule/doc/pdf_standard_myobject.modules.php' => 'core/modules/'.strtolower($module).'/doc/pdf_standard_'.strtolower($objectname).'.modules.php'
2061 );
2062
2063 //menu for the object selected
2064 // load class and check if menu,permission,documentation exist for this object
2065 $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
2066 dol_include_once($pathtofile);
2067 $class = 'mod'.$module;
2068 $moduleobj = null;
2069 if (class_exists($class)) {
2070 try {
2071 $moduleobj = new $class($db);
2072 '@phan-var-force DolibarrModules $moduleobj';
2074 } catch (Exception $e) {
2075 $error++;
2076 dol_print_error($db, $e->getMessage());
2077 }
2078 } else {
2079 $error++;
2080 $langs->load("errors");
2081 dol_print_error($db, $langs->trans("ErrorFailedToLoadModuleDescriptorForXXX", $module));
2082 exit;
2083 }
2084 $moduledescriptorfile = $dirins.'/'.strtolower($module).'/core/modules/mod'.$module.'.class.php';
2085
2086 // delete menus linked to the object
2087 $menus = $moduleobj->menu;
2088 $rewriteMenu = checkExistComment($moduledescriptorfile, 0);
2089
2090 if ($rewriteMenu < 0) {
2091 setEventMessages($langs->trans("WarningCommentNotFound", $langs->trans("Menus"), "mod".$module."class.php"), null, 'warnings');
2092 } else {
2093 reWriteAllMenus($moduledescriptorfile, $menus, $objectname, null, -1);
2094 }
2095
2096 // regenerate permissions and delete them
2097 $permissions = $moduleobj->rights;
2098 $rewritePerms = checkExistComment($moduledescriptorfile, 1);
2099 if ($rewritePerms < 0) {
2100 setEventMessages($langs->trans("WarningCommentNotFound", $langs->trans("Permissions"), "mod".$module."class.php"), null, 'warnings');
2101 } else {
2102 reWriteAllPermissions($moduledescriptorfile, $permissions, null, null, $objectname, '', -1);
2103 }
2104 if ($rewritePerms && $rewriteMenu) {
2105 // check if documentation has been generated
2106 $file_doc = $dirins.'/'.strtolower($module).'/doc/Documentation.asciidoc';
2107 deletePropsAndPermsFromDoc($file_doc, $objectname);
2108
2109 clearstatcache(true);
2110 if (function_exists('opcache_invalidate')) {
2111 opcache_reset(); // remove the include cache hell !
2112 }
2113 $resultko = 0;
2114 foreach ($filetodelete as $tmpfiletodelete) {
2115 $resulttmp = dol_delete_file($dir.'/'.$tmpfiletodelete, 0, 0, 1);
2116 $resulttmp = dol_delete_file($dir.'/'.$tmpfiletodelete.'.back', 0, 0, 1);
2117 if (!$resulttmp) {
2118 $resultko++;
2119 }
2120 }
2121
2122 if ($resultko == 0) {
2123 setEventMessages($langs->trans("FilesDeleted"), null);
2124 } else {
2125 setEventMessages($langs->trans("ErrorSomeFilesCouldNotBeDeleted"), null, 'warnings');
2126 }
2127 }
2128 }
2129
2130 $action = '';
2131 if (! $error) {
2132 $tabobj = 'newobject';
2133 } else {
2134 $tabobj = 'deleteobject';
2135 }
2136
2137 // check if module is enabled
2138 if (isModEnabled(strtolower($module))) {
2139 $result = unActivateModule(strtolower($module));
2140 dolibarr_set_const($db, "MAIN_IHM_PARAMS_REV", getDolGlobalInt('MAIN_IHM_PARAMS_REV') + 1, 'chaine', 0, '', $conf->entity);
2141 if ($result) {
2142 setEventMessages($result, null, 'errors');
2143 }
2144 setEventMessages($langs->trans('WarningModuleNeedRefresh', $langs->transnoentities($module)), null, 'warnings');
2145 header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=objects&tabobj=deleteobject&module='.urlencode($module));
2146 exit;
2147 }
2148}
2149
2150if (($dirins && $action == 'confirm_deletedictionary' && $dicname) || ($dirins && $action == 'confirm_deletedictionary' && GETPOST('dictionnarykey')) && $user->hasRight("modulebuilder", "run")) {
2151 $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
2152 $destdir = $dirins.'/'.strtolower($module);
2153 $moduledescriptorfile = $dirins.'/'.strtolower($module).'/core/modules/mod'.$module.'.class.php';
2154
2155 if (preg_match('/[^a-z0-9_]/i', $dicname)) {
2156 $error++;
2157 setEventMessages($langs->trans("SpaceOrSpecialCharAreNotAllowed"), null, 'errors');
2158 }
2159
2160 if (!empty($dicname)) {
2161 $newdicname = $dicname;
2162 if (!preg_match('/^c_/', $newdicname)) {
2163 $newdicname = 'c_'.strtolower($dicname);
2164 }
2165 } else {
2166 $newdicname = null;
2167 }
2168
2169 dol_include_once($pathtofile);
2170 $class = 'mod'.$module;
2171
2172 if (class_exists($class)) {
2173 try {
2174 $moduleobj = new $class($db);
2175 '@phan-var-force DolibarrModules $moduleobj';
2177 } catch (Exception $e) {
2178 $error++;
2179 dol_print_error($db, $e->getMessage());
2180 }
2181 } else {
2182 $error++;
2183 $langs->load("errors");
2184 dol_print_error($db, $langs->trans("ErrorFailedToLoadModuleDescriptorForXXX", $module));
2185 exit;
2186 }
2187
2188 $dicts = $moduleobj->dictionaries;
2189 $checkComment = checkExistComment($moduledescriptorfile, 2);
2190 if ($checkComment < 0) {
2191 $error++;
2192 setEventMessages($langs->trans("WarningCommentNotFound", $langs->trans("Dictionaries"), "mod".$module."class.php"), null, 'warnings');
2193 }
2194
2195 if (!empty(GETPOST('dictionnarykey'))) {
2196 $newdicname = $dicts['tabname'][GETPOSTINT('dictionnarykey') - 1];
2197 }
2198
2199 // Lookup the table dicname
2200 $checkTable = false;
2201 if ($newdicname !== null) {
2202 $checkTable = $db->DDLDescTable(MAIN_DB_PREFIX.strtolower($newdicname));
2203 }
2204
2205 if (is_bool($checkTable) || $db->num_rows($checkTable) <= 0) { // @phpstan-ignore-line
2206 $error++;
2207 }
2208
2209 // search the key by name
2210 $keyToDelete = null;
2211 foreach ($dicts['tabname'] as $key => $table) {
2212 //var_dump($table." /////// ".$newdicname);exit;
2213 if (strtolower($table) === $newdicname) {
2214 $keyToDelete = $key;
2215 break;
2216 }
2217 }
2218 // delete all dicname's key values from the dictionary
2219 if ($keyToDelete !== null) {
2220 $keysToDelete = ['tabname', 'tablib', 'tabsql', 'tabsqlsort', 'tabfield', 'tabfieldvalue', 'tabfieldinsert', 'tabrowid', 'tabcond', 'tabhelp'];
2221 foreach ($keysToDelete as $key) {
2222 unset($dicts[$key][$keyToDelete]);
2223 }
2224 } else {
2225 $error++;
2226 setEventMessages($langs->trans("ErrorDictionaryNotFound", ucfirst($dicname)), null, 'errors');
2227 }
2228 if (!$error && $newdicname !== null) {
2229 // delete table
2230 $_results = $db->DDLDropTable(MAIN_DB_PREFIX.strtolower($newdicname));
2231 if ($_results < 0) {
2232 dol_print_error($db);
2233 $langs->load("errors");
2234 setEventMessages($langs->trans("ErrorTableNotFound", $newdicname), null, 'errors');
2235 }
2236 // rebuild file after update dictionaries
2237 $result = updateDictionaryInFile($module, $moduledescriptorfile, $dicts);
2238 if ($result > 0) {
2239 setEventMessages($langs->trans("DictionaryDeleted", ucfirst(substr($newdicname, 2))), null);
2240 }
2241 if (function_exists('opcache_invalidate')) {
2242 opcache_reset(); // remove the include cache hell !
2243 }
2244 clearstatcache(true);
2245 header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=dictionaries&module='.$module.($forceddirread ? '@'.$dirread : ''));
2246 exit;
2247 }
2248}
2249if ($dirins && $action == 'updatedictionary' && GETPOST('dictionnarykey') && $user->hasRight("modulebuilder", "run")) {
2250 $keydict = GETPOSTINT('dictionnarykey') - 1 ;
2251
2252 $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
2253 $destdir = $dirins.'/'.strtolower($module);
2254 $moduledescriptorfile = $dirins.'/'.strtolower($module).'/core/modules/mod'.$module.'.class.php';
2255 dol_include_once($pathtofile);
2256 $class = 'mod'.$module;
2257
2258 if (class_exists($class)) {
2259 try {
2260 $moduleobj = new $class($db);
2261 '@phan-var-force DolibarrModules $moduleobj';
2263 } catch (Exception $e) {
2264 $error++;
2265 dol_print_error($db, $e->getMessage());
2266 }
2267 } else {
2268 $error++;
2269 $langs->load("errors");
2270 dol_print_error($db, $langs->trans("ErrorFailedToLoadModuleDescriptorForXXX", $module));
2271 exit;
2272 }
2273
2274 $dicts = $moduleobj->dictionaries;
2275 if (!empty(GETPOST('tablib')) && GETPOST('tablib') !== $dicts['tablib'][$keydict]) {
2276 $dicts['tablib'][$keydict] = ucfirst(strtolower(GETPOST('tablib')));
2277 $checkComment = checkExistComment($moduledescriptorfile, 2);
2278 if ($checkComment < 0) {
2279 setEventMessages($langs->trans("WarningCommentNotFound", $langs->trans("Dictionaries"), "mod".$module."class.php"), null, 'warnings');
2280 } else {
2281 $updateDict = updateDictionaryInFile($module, $moduledescriptorfile, $dicts);
2282 if ($updateDict > 0) {
2283 setEventMessages($langs->trans("DictionaryNameUpdated", ucfirst(GETPOST('tablib'))), null);
2284 }
2285 if (function_exists('opcache_invalidate')) {
2286 opcache_reset(); // remove the include cache hell !
2287 }
2288 clearstatcache(true);
2289 header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=dictionaries&module='.$module.($forceddirread ? '@'.$dirread : ''));
2290 exit;
2291 }
2292 }
2293 //var_dump(GETPOST('tablib'));exit;
2294}
2295if ($dirins && $action == 'generatedoc' && $user->hasRight("modulebuilder", "run")) {
2296 $modulelowercase = strtolower($module);
2297
2298 // Dir for module
2299 $dirofmodule = dol_buildpath($modulelowercase, 0).'/doc';
2300
2301 $FILENAMEDOC = strtolower($module).'.html';
2302
2303 $util = new Utils($db);
2304 $result = $util->generateDoc($module);
2305
2306 if ($result > 0) {
2307 setEventMessages($langs->trans("DocFileGeneratedInto", $dirofmodule), null);
2308 } else {
2309 setEventMessages($util->error, $util->errors, 'errors');
2310 }
2311}
2312
2313if ($dirins && $action == 'generatepackage' && $user->hasRight("modulebuilder", "run")) {
2314 $modulelowercase = strtolower($module);
2315
2316 $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
2317
2318 // Dir for module
2319 $dir = dol_buildpath($modulelowercase, 0);
2320
2321 // Zip file to build
2322 $FILENAMEZIP = '';
2323
2324 // Load module
2325 dol_include_once($pathtofile);
2326 $class = 'mod'.$module;
2327
2328 if (class_exists($class)) {
2329 try {
2330 $moduleobj = new $class($db);
2331 '@phan-var-force DolibarrModules $moduleobj';
2333 } catch (Exception $e) {
2334 $error++;
2335 dol_print_error($db, $e->getMessage());
2336 }
2337 } else {
2338 $error++;
2339 $langs->load("errors");
2340 dol_print_error($db, $langs->trans("ErrorFailedToLoadModuleDescriptorForXXX", $module));
2341 exit;
2342 }
2343
2344 $arrayversion = explode('.', $moduleobj->version, 3);
2345 if (count($arrayversion)) {
2346 $FILENAMEZIP = "module_".$modulelowercase.'-'.$arrayversion[0].(empty($arrayversion[1]) ? '.0' : '.'.$arrayversion[1]).(empty($arrayversion[2]) ? '' : '.'.$arrayversion[2]).'.zip';
2347
2348 $dirofmodule = dol_buildpath($modulelowercase, 0).'/bin';
2349 $outputfilezip = $dirofmodule.'/'.$FILENAMEZIP;
2350 if ($dirofmodule) {
2351 if (!dol_is_dir($dirofmodule)) {
2352 dol_mkdir($dirofmodule);
2353 }
2354 // Note: We exclude /bin/ to not include the already generated zip
2355 $result = dol_compress_dir($dir, $outputfilezip, 'zip', '/\/bin\/|\.git|\.old|\.back|\.ssh/', $modulelowercase);
2356 } else {
2357 $result = -1;
2358 }
2359
2360 if ($result > 0) {
2361 setEventMessages($langs->trans("ZipFileGeneratedInto", $outputfilezip), null);
2362 } else {
2363 $error++;
2364 $langs->load("errors");
2365 setEventMessages($langs->trans("ErrorFailToGenerateFile", $outputfilezip), null, 'errors');
2366 }
2367 } else {
2368 $error++;
2369 $langs->load("errors");
2370 setEventMessages($langs->trans("ErrorCheckVersionIsDefined"), null, 'errors');
2371 }
2372}
2373
2374// Add permission
2375if ($dirins && $action == 'addright' && !empty($module) && empty($cancel) && $user->hasRight("modulebuilder", "run")) {
2376 $error = 0;
2377
2378 // load class and check if right exist
2379 $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
2380 dol_include_once($pathtofile);
2381 $class = 'mod'.$module;
2382 $moduleobj = null;
2383 if (class_exists($class)) {
2384 try {
2385 $moduleobj = new $class($db);
2386 '@phan-var-force DolibarrModules $moduleobj';
2388 } catch (Exception $e) {
2389 $error++;
2390 dol_print_error($db, $e->getMessage());
2391 }
2392 }
2393
2394 // verify information entered
2395 if (!GETPOST('label', 'alpha')) {
2396 $error++;
2397 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Label")), null, 'errors');
2398 }
2399 if (!GETPOST('permissionObj', 'alpha')) {
2400 $error++;
2401 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Rights")), null, 'errors');
2402 }
2403
2404 $id = GETPOST('id', 'alpha');
2405 $label = GETPOST('label', 'alpha');
2406 $objectForPerms = strtolower(GETPOST('permissionObj', 'alpha'));
2407 $crud = GETPOST('crud', 'alpha');
2408
2409 //check existing object permission
2410 $counter = 0;
2411 $permsForObject = array();
2412 if (is_object($moduleobj)) {
2413 $permissions = $moduleobj->rights;
2414 } else {
2415 $permissions = array();
2416 }
2417 $allObject = array();
2418
2419 $countPerms = count($permissions);
2420
2421 for ($i = 0; $i < $countPerms; $i++) {
2422 if ($permissions[$i][4] == $objectForPerms) {
2423 $counter++;
2424 if (count($permsForObject) < 3) {
2425 $permsForObject[] = $permissions[$i];
2426 }
2427 }
2428 $allObject[] = $permissions[$i][4];
2429 }
2430
2431 // check if label of object already exists
2432 $countPermsObj = count($permsForObject);
2433 for ($j = 0; $j < $countPermsObj; $j++) {
2434 if (in_array($crud, $permsForObject[$j])) {
2435 $error++;
2436 setEventMessages($langs->trans("ErrorExistingPermission", $langs->transnoentities($crud), $langs->transnoentities($objectForPerms)), null, 'errors');
2437 }
2438 }
2439
2440 $rightToAdd = array();
2441 if (!$error) {
2442 $key = $countPerms + 1;
2443 //prepare right to add
2444 $rightToAdd = array(
2445 0 => $id,
2446 1 => $label,
2447 4 => $objectForPerms,
2448 5 => $crud
2449 );
2450
2451 if (isModEnabled(strtolower($module))) {
2452 $result = unActivateModule(strtolower($module));
2453 dolibarr_set_const($db, "MAIN_IHM_PARAMS_REV", getDolGlobalInt('MAIN_IHM_PARAMS_REV') + 1, 'chaine', 0, '', $conf->entity);
2454 if ($result) {
2455 setEventMessages($result, null, 'errors');
2456 }
2457 setEventMessages($langs->trans('WarningModuleNeedRefresh', $langs->transnoentities($module)), null, 'warnings');
2458 }
2459 }
2460 $moduledescriptorfile = $dirins.'/'.strtolower($module).'/core/modules/mod'.$module.'.class.php';
2461 //rewriting all permissions after add a right
2462 $rewrite = checkExistComment($moduledescriptorfile, 1);
2463 if ($rewrite < 0) {
2464 setEventMessages($langs->trans("WarningCommentNotFound", $langs->trans("Permissions"), "mod".$module."class.php"), null, 'warnings');
2465 } else {
2466 reWriteAllPermissions($moduledescriptorfile, $permissions, $key, $rightToAdd, '', '', 1);
2467 setEventMessages($langs->trans('PermissionAddedSuccesfuly'), null);
2468
2469 clearstatcache(true);
2470 if (function_exists('opcache_invalidate')) {
2471 opcache_reset(); // remove the include cache hell !
2472 }
2473 header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=permissions&module='.$module);
2474 exit;
2475 }
2476}
2477
2478
2479// Update permission
2480if ($dirins && GETPOST('action') == 'update_right' && GETPOST('modifyright') && empty($cancel) && $user->hasRight("modulebuilder", "run")) {
2481 $error = 0;
2482 // load class and check if right exist
2483 $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
2484 dol_include_once($pathtofile);
2485 $class = 'mod'.$module;
2486 $moduleobj = null;
2487 if (class_exists($class)) {
2488 try {
2489 $moduleobj = new $class($db);
2490 '@phan-var-force DolibarrModules $moduleobj';
2492 } catch (Exception $e) {
2493 $error++;
2494 dol_print_error($db, $e->getMessage());
2495 }
2496 }
2497 // verify information entered
2498 if (!GETPOST('label', 'alpha')) {
2499 $error++;
2500 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Label")), null, 'errors');
2501 }
2502 if (!GETPOST('permissionObj', 'alpha')) {
2503 $error++;
2504 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Rights")), null, 'errors');
2505 }
2506
2507 $label = GETPOST('label', 'alpha');
2508 $objectForPerms = strtolower(GETPOST('permissionObj', 'alpha'));
2509 $crud = GETPOST('crud', 'alpha');
2510
2511
2512 if ($label == "Read objects of $module" && $crud != "read") {
2513 $crud = "read";
2514 // $label = "Read objects of $module";
2515 }
2516 if ($label == "Create/Update objects of $module" && $crud != "write") {
2517 $crud = "write";
2518 // $label = "Create/Update objects of $module";
2519 }
2520 if ($label == "Delete objects of $module" && $crud != "delete") {
2521 $crud = "delete";
2522 // $label = "Delete objects of $module";
2523 }
2524
2525 if (is_object($moduleobj)) {
2526 $permissions = $moduleobj->rights;
2527 } else {
2528 $permissions = [];
2529 }
2530 $key = GETPOSTINT('counter') - 1;
2531 //get permission want to delete from permissions array
2532 if (array_key_exists($key, $permissions)) {
2533 $x1 = $permissions[$key][1];
2534 $x2 = $permissions[$key][4];
2535 $x3 = $permissions[$key][5];
2536 } else {
2537 $x1 = null;
2538 $x2 = null;
2539 $x3 = null;
2540 }
2541 //check existing object permission
2542 $counter = 0;
2543 $permsForObject = array();
2544 // $permissions = $moduleobj->rights; // Already fetched above
2545 $firstRight = 0;
2546 $existRight = 0;
2547 $allObject = array();
2548
2549 $countPerms = count($permissions);
2550 for ($i = 0; $i < $countPerms; $i++) {
2551 if ($permissions[$i][4] == $objectForPerms) {
2552 $counter++;
2553 if (count($permsForObject) < 3) {
2554 $permsForObject[] = $permissions[$i];
2555 }
2556 }
2557 $allObject[] = $permissions[$i][4];
2558 }
2559
2560 if ($label != $x1 && $crud != $x3) {
2561 $countPermsObj = count($permsForObject);
2562 for ($j = 0; $j < $countPermsObj; $j++) {
2563 if (in_array($label, $permsForObject[$j])) {
2564 $error++;
2565 setEventMessages($langs->trans("ErrorExistingPermission", $langs->transnoentities($label), $langs->transnoentities($objectForPerms)), null, 'errors');
2566 }
2567 }
2568 }
2569
2570 if (!$error) {
2571 if (isModEnabled(strtolower($module))) {
2572 $result = unActivateModule(strtolower($module));
2573 dolibarr_set_const($db, "MAIN_IHM_PARAMS_REV", getDolGlobalInt('MAIN_IHM_PARAMS_REV') + 1, 'chaine', 0, '', $conf->entity);
2574 if ($result) {
2575 setEventMessages($result, null, 'errors');
2576 }
2577 setEventMessages($langs->trans('WarningModuleNeedRefresh', $langs->transnoentities($module)), null, 'warnings');
2578 }
2579
2580 $moduledescriptorfile = $dirins.'/'.strtolower($module).'/core/modules/mod'.$module.'.class.php';
2581 // rewriting all permissions after update permission needed
2582 $rewrite = checkExistComment($moduledescriptorfile, 1);
2583 if ($rewrite < 0) {
2584 setEventMessages($langs->trans("WarningCommentNotFound", $langs->trans("Permissions"), "mod".$module."class.php"), null, 'warnings');
2585 } else {
2586 $rightUpdated = null; // I not set at this point
2587 reWriteAllPermissions($moduledescriptorfile, $permissions, $key, $rightUpdated, '', '', 2);
2588 setEventMessages($langs->trans('PermissionUpdatedSuccesfuly'), null);
2589 clearstatcache(true);
2590 if (function_exists('opcache_invalidate')) {
2591 opcache_reset(); // remove the include cache hell !
2592 }
2593 header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=permissions&module='.$module);
2594 exit;
2595 }
2596 }
2597}
2598// Delete permission
2599if ($dirins && $action == 'confirm_deleteright' && !empty($module) && GETPOSTINT('permskey') && $user->hasRight("modulebuilder", "run")) {
2600 $error = 0;
2601 // load class and check if right exist
2602 $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
2603 dol_include_once($pathtofile);
2604 $class = 'mod'.$module;
2605 $moduleobj = null;
2606 if (class_exists($class)) {
2607 try {
2608 $moduleobj = new $class($db);
2609 '@phan-var-force DolibarrModules $moduleobj';
2611 } catch (Exception $e) {
2612 $error++;
2613 dol_print_error($db, $e->getMessage());
2614 }
2615 }
2616
2617 $permissions = $moduleobj->rights;
2618 $key = GETPOSTINT('permskey') - 1;
2619
2620 if (!$error) {
2621 // check if module is enabled
2622 if (isModEnabled(strtolower($module))) {
2623 $result = unActivateModule(strtolower($module));
2624 dolibarr_set_const($db, "MAIN_IHM_PARAMS_REV", getDolGlobalInt('MAIN_IHM_PARAMS_REV') + 1, 'chaine', 0, '', $conf->entity);
2625 if ($result) {
2626 setEventMessages($result, null, 'errors');
2627 }
2628 setEventMessages($langs->trans('WarningModuleNeedRefresh', $langs->transnoentities($module)), null, 'warnings');
2629 header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=permissions&module='.$module);
2630 exit;
2631 }
2632
2633 // rewriting all permissions
2634 $moduledescriptorfile = $dirins.'/'.strtolower($module).'/core/modules/mod'.$module.'.class.php';
2635 $rewrite = checkExistComment($moduledescriptorfile, 1);
2636 if ($rewrite < 0) {
2637 setEventMessages($langs->trans("WarningCommentNotFound", $langs->trans("Permissions"), "mod".$module."class.php"), null, 'warnings');
2638 } else {
2639 reWriteAllPermissions($moduledescriptorfile, $permissions, $key, null, '', '', 0);
2640 setEventMessages($langs->trans('PermissionDeletedSuccesfuly'), null);
2641
2642 clearstatcache(true);
2643 if (function_exists('opcache_invalidate')) {
2644 opcache_reset(); // remove the include cache hell !
2645 }
2646
2647 header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=permissions&module='.$module);
2648 exit;
2649 }
2650 }
2651}
2652// Save file
2653if ($action == 'savefile' && empty($cancel) && $user->hasRight("modulebuilder", "run")) {
2654 $relofcustom = basename($dirins);
2655
2656 if ($relofcustom) {
2657 // Check that relative path ($file) start with name 'custom'
2658 if (!preg_match('/^'.$relofcustom.'/', $file)) {
2659 $file = $relofcustom.'/'.$file;
2660 }
2661
2662 $pathoffile = dol_buildpath($file, 0);
2663 $pathoffilebackup = dol_buildpath($file.'.back', 0);
2664
2665 // Save old version
2666 if (dol_is_file($pathoffile)) {
2667 dol_copy($pathoffile, $pathoffilebackup, '0', 1);
2668 }
2669
2670 $check = 'restricthtml';
2671 $srclang = dol_mimetype($pathoffile, '', 3);
2672 if ($srclang == 'md') {
2673 $check = 'restricthtml';
2674 }
2675 if ($srclang == 'lang') {
2676 $check = 'restricthtml';
2677 }
2678 if ($srclang == 'php') {
2679 $check = 'none';
2680 }
2681
2682 $content = GETPOST('editfilecontent', $check);
2683
2684 // Save file on disk
2685 if ($content) {
2686 dol_delete_file($pathoffile);
2687 $result = file_put_contents($pathoffile, $content);
2688 if ($result) {
2689 dolChmod($pathoffile, $newmask);
2690
2691 setEventMessages($langs->trans("FileSaved"), null);
2692 } else {
2693 setEventMessages($langs->trans("ErrorFailedToSaveFile"), null, 'errors');
2694 }
2695 } else {
2696 setEventMessages($langs->trans("ContentCantBeEmpty"), null, 'errors');
2697 //$action='editfile';
2698 $error++;
2699 }
2700 }
2701}
2702
2703// Enable module
2704if ($action == 'set' && $user->admin && $user->hasRight("modulebuilder", "run")) {
2705 $param = '';
2706 if ($module) {
2707 $param .= '&module='.urlencode($module);
2708 }
2709 if ($tab) {
2710 $param .= '&tab='.urlencode($tab);
2711 }
2712 if ($tabobj) {
2713 $param .= '&tabobj='.urlencode($tabobj);
2714 }
2715
2716 $value = GETPOST('value', 'alpha');
2717 $resarray = activateModule($value);
2718 if (!empty($resarray['errors'])) {
2719 setEventMessages('', $resarray['errors'], 'errors');
2720 } else {
2721 //var_dump($resarray);exit;
2722 if ($resarray['nbperms'] > 0) {
2723 $tmpsql = "SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX."user WHERE admin <> 1";
2724 $resqltmp = $db->query($tmpsql);
2725 if ($resqltmp) {
2726 $obj = $db->fetch_object($resqltmp);
2727 //var_dump($obj->nb);exit;
2728 if ($obj && $obj->nb > 1) {
2729 $msg = $langs->trans('ModuleEnabledAdminMustCheckRights');
2730 setEventMessages($msg, null, 'warnings');
2731 }
2732 } else {
2733 dol_print_error($db);
2734 }
2735 }
2736 }
2737 header("Location: ".$_SERVER["PHP_SELF"]."?".$param);
2738 exit;
2739}
2740
2741// Disable module
2742if ($action == 'reset' && $user->admin && $user->hasRight("modulebuilder", "run")) {
2743 $param = '';
2744 if ($module) {
2745 $param .= '&module='.urlencode($module);
2746 }
2747 if ($tab) {
2748 $param .= '&tab='.urlencode($tab);
2749 }
2750 if ($tabobj) {
2751 $param .= '&tabobj='.urlencode($tabobj);
2752 }
2753
2754 $value = GETPOST('value', 'alpha');
2755 $result = unActivateModule($value);
2756 if ($result) {
2757 setEventMessages($result, null, 'errors');
2758 }
2759 header("Location: ".$_SERVER["PHP_SELF"]."?".$param);
2760 exit;
2761}
2762
2763// delete menu
2764if ($dirins && $action == 'confirm_deletemenu' && GETPOSTINT('menukey') && $user->hasRight("modulebuilder", "run")) {
2765 // check if module is enabled
2766 if (isModEnabled(strtolower($module))) {
2767 $result = unActivateModule(strtolower($module));
2768 dolibarr_set_const($db, "MAIN_IHM_PARAMS_REV", getDolGlobalInt('MAIN_IHM_PARAMS_REV') + 1, 'chaine', 0, '', $conf->entity);
2769 if ($result) {
2770 setEventMessages($result, null, 'errors');
2771 }
2772 setEventMessages($langs->trans('WarningModuleNeedRefresh', $langs->transnoentities($module)), null, 'warnings');
2773 header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=menus&module='.$module);
2774 exit;
2775 }
2776 // load class and check if menu exist
2777 $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
2778 dol_include_once($pathtofile);
2779 $class = 'mod'.$module;
2780 $moduleobj = null;
2781 if (class_exists($class)) {
2782 try {
2783 $moduleobj = new $class($db);
2784 '@phan-var-force DolibarrModules $moduleobj';
2786 } catch (Exception $e) {
2787 $error++;
2788 dol_print_error($db, $e->getMessage());
2789 }
2790 }
2791 // get all objects and convert value to lower case for compare
2792 $dir = $listofmodules[strtolower($module)]['moduledescriptorrootpath'];
2793 $destdir = $dir.'/'.strtolower($module);
2794 $objects = dolGetListOfObjectClasses($destdir);
2795 $result = array_map('strtolower', $objects);
2796
2797 $menus = $moduleobj->menu;
2798 $key = GETPOSTINT('menukey');
2799 $moduledescriptorfile = $dirins.'/'.strtolower($module).'/core/modules/mod'.$module.'.class.php';
2800
2801 $checkcomment = checkExistComment($moduledescriptorfile, 0);
2802 if ($checkcomment < 0) {
2803 setEventMessages($langs->trans("WarningCommentNotFound", $langs->trans("Menus"), "mod".$module."class.php"), null, 'warnings');
2804 } else {
2805 if ($menus[$key]['fk_menu'] === 'fk_mainmenu='.strtolower($module)) {
2806 if (in_array(strtolower($menus[$key]['leftmenu']), $result)) {
2807 reWriteAllMenus($moduledescriptorfile, $menus, $menus[$key]['leftmenu'], $key, -1);
2808 } else {
2809 reWriteAllMenus($moduledescriptorfile, $menus, null, $key, 0);
2810 }
2811 } else {
2812 reWriteAllMenus($moduledescriptorfile, $menus, null, $key, 0);
2813 }
2814
2815 clearstatcache(true);
2816 if (function_exists('opcache_invalidate')) {
2817 opcache_reset(); // remove the include cache hell !
2818 }
2819
2820 setEventMessages($langs->trans('MenuDeletedSuccessfuly'), null);
2821 header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=menus&module='.$module);
2822 exit;
2823 }
2824}
2825
2826// Add menu in module without initial object
2827if ($dirins && $action == 'addmenu' && empty($cancel) && $user->hasRight("modulebuilder", "run")) {
2828 // check if module is enabled
2829 if (isModEnabled(strtolower($module))) {
2830 $result = unActivateModule(strtolower($module));
2831 dolibarr_set_const($db, "MAIN_IHM_PARAMS_REV", getDolGlobalInt('MAIN_IHM_PARAMS_REV') + 1, 'chaine', 0, '', $conf->entity);
2832 if ($result) {
2833 setEventMessages($result, null, 'errors');
2834 }
2835 setEventMessages($langs->trans('WarningModuleNeedRefresh', $langs->transnoentities($module)), null, 'warnings');
2836 header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=menus&module='.$module);
2837 exit;
2838 }
2839 $error = 0;
2840
2841 // load class and check if right exist
2842 $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
2843 dol_include_once($pathtofile);
2844 $class = 'mod'.$module;
2845 $moduleobj = null;
2846 if (class_exists($class)) {
2847 try {
2848 $moduleobj = new $class($db);
2849 '@phan-var-force DolibarrModules $moduleobj';
2851 } catch (Exception $e) {
2852 $error++;
2853 dol_print_error($db, $e->getMessage());
2854 }
2855 }
2856 // get all menus
2857 $menus = $moduleobj->menu;
2858
2859 //verify fields required
2860 if (!GETPOST('type', 'alpha')) {
2861 $error++;
2862 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Type")), null, 'errors');
2863 }
2864 if (!GETPOST('titre', 'alpha')) {
2865 $error++;
2866 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Title")), null, 'errors');
2867 }
2868 if (!GETPOST('user', 'alpha')) {
2869 $error++;
2870 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("DetailUser")), null, 'errors');
2871 }
2872 if (!GETPOST('url', 'alpha')) {
2873 $error++;
2874 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Url")), null, 'errors');
2875 }
2876 if (!empty(GETPOST('target'))) {
2877 $targets = array('_blank','_self','_parent','_top','');
2878 if (!in_array(GETPOST('target'), $targets)) {
2879 $error++;
2880 setEventMessages($langs->trans("ErrorFieldValue", $langs->transnoentities("target")), null, 'errors');
2881 }
2882 }
2883
2884
2885 // check if title or url already exist in menus
2886
2887 foreach ($menus as $menu) {
2888 if (!empty(GETPOST('url')) && GETPOST('url') == $menu['url']) {
2889 $error++;
2890 setEventMessages($langs->trans("ErrorFieldExist", $langs->transnoentities("url")), null, 'errors');
2891 break;
2892 }
2893 if (strtolower(GETPOST('titre')) == strtolower($menu['titre'])) {
2894 $error++;
2895 setEventMessages($langs->trans("ErrorFieldExist", $langs->transnoentities("titre")), null, 'errors');
2896 break;
2897 }
2898 }
2899
2900 if (GETPOST('type', 'alpha') == 'left' && !empty(GETPOST('lefmenu', 'alpha'))) {
2901 if (!str_contains(GETPOST('leftmenu'), strtolower($module))) {
2902 $error++;
2903 setEventMessages($langs->trans("WarningFieldsMustContains", $langs->transnoentities("LeftmenuId")), null, 'errors');
2904 }
2905 }
2906 $dirins = $listofmodules[strtolower($module)]['moduledescriptorrootpath'];
2907 $destdir = $dirins.'/'.strtolower($module);
2908 $objects = dolGetListOfObjectClasses($destdir);
2909
2910 if (GETPOST('type', 'alpha') == 'left') {
2911 if (empty(GETPOST('leftmenu')) && count($objects) > 0) {
2912 $error++;
2913 setEventMessages($langs->trans("ErrorCoherenceMenu", $langs->transnoentities("LeftmenuId"), $langs->transnoentities("type")), null, 'errors');
2914 }
2915 }
2916 if (GETPOST('type', 'alpha') == 'top') {
2917 $error++;
2918 setEventMessages($langs->trans("ErrorTypeMenu", $langs->transnoentities("type")), null, 'errors');
2919 }
2920
2921 $moduledescriptorfile = $dirins.'/'.strtolower($module).'/core/modules/mod'.$module.'.class.php';
2922 if (!$error) {
2923 //stock forms in array
2924 $menuToAdd = array(
2925 'fk_menu' => GETPOST('fk_menu', 'alpha'),
2926 'type' => GETPOST('type', 'alpha'),
2927 'titre' => ucfirst(GETPOST('titre', 'alpha')),
2928 'prefix' => '',
2929 'mainmenu' => GETPOST('mainmenu', 'alpha'),
2930 'leftmenu' => GETPOST('leftmenu', 'alpha'),
2931 'url' => GETPOST('url', 'alpha'),
2932 'langs' => strtolower($module)."@".strtolower($module),
2933 'position' => '',
2934 'enabled' => GETPOST('enabled', 'alpha'),
2935 'perms' => '$user->hasRight("'.strtolower($module).'", "'.GETPOST('objects', 'alpha').'", "'.GETPOST('perms', 'alpha').'")',
2936 'target' => GETPOST('target', 'alpha'),
2937 'user' => GETPOSTINT('user'),
2938 );
2939
2940 if (GETPOST('type') == 'left') {
2941 unset($menuToAdd['prefix']);
2942 if (empty(GETPOST('fk_menu'))) {
2943 $menuToAdd['fk_menu'] = 'fk_mainmenu='.GETPOST('mainmenu', 'alpha');
2944 } else {
2945 $menuToAdd['fk_menu'] = 'fk_mainmenu='.GETPOST('mainmenu', 'alpha').',fk_leftmenu='.GETPOST('fk_menu');
2946 }
2947 }
2948 if (GETPOST('enabled') == '1') {
2949 $menuToAdd['enabled'] = 'isModEnabled("'.strtolower($module).'")';
2950 } else {
2951 $menuToAdd['enabled'] = "0";
2952 }
2953 if (empty(GETPOST('objects'))) {
2954 $menuToAdd['perms'] = '1';
2955 }
2956
2957 $checkcomment = checkExistComment($moduledescriptorfile, 0);
2958 if ($checkcomment < 0) {
2959 setEventMessages($langs->trans("WarningCommentNotFound", $langs->trans("Menus"), "mod".$module."class.php"), null, 'warnings');
2960 } else {
2961 // Write all menus
2962 $result = reWriteAllMenus($moduledescriptorfile, $menus, $menuToAdd, null, 1);
2963
2964 clearstatcache(true);
2965 if (function_exists('opcache_invalidate')) {
2966 opcache_reset();
2967 }
2968 /*if ($result < 0) {
2969 setEventMessages($langs->trans('ErrorMenuExistValue'), null, 'errors');
2970 header("Location: ".$_SERVER["PHP_SELF"].'?action=editmenu&token='.newToken().'&menukey='.urlencode($key+1).'&tab='.urlencode($tab).'&module='.urlencode($module).'&tabobj='.($key+1));
2971 exit;
2972 }*/
2973
2974 header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=menus&module='.$module);
2975 setEventMessages($langs->trans('MenuAddedSuccesfuly'), null);
2976 exit;
2977 }
2978 }
2979}
2980
2981// Modify a menu entry
2982if ($dirins && $action == "update_menu" && GETPOSTINT('menukey') && GETPOST('tabobj') && $user->hasRight("modulebuilder", "run")) {
2983 $objectname = GETPOST('tabobj');
2984 $dirins = $listofmodules[strtolower($module)]['moduledescriptorrootpath'];
2985 $destdir = $dirins.'/'.strtolower($module);
2986 $objects = dolGetListOfObjectClasses($destdir);
2987
2988 if (empty($cancel)) {
2989 if (isModEnabled(strtolower($module))) {
2990 $result = unActivateModule(strtolower($module));
2991 dolibarr_set_const($db, "MAIN_IHM_PARAMS_REV", getDolGlobalInt('MAIN_IHM_PARAMS_REV') + 1, 'chaine', 0, '', $conf->entity);
2992 if ($result) {
2993 setEventMessages($result, null, 'errors');
2994 }
2995 setEventMessages($langs->trans('WarningModuleNeedRefresh', $langs->transnoentities($module)), null, 'warnings');
2996 header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=menus&module='.$module);
2997 exit;
2998 }
2999 $error = 0;
3000 // for loading class and the menu wants to modify
3001 $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
3002 dol_include_once($pathtofile);
3003 $class = 'mod'.$module;
3004 $moduleobj = null;
3005 if (class_exists($class)) {
3006 try {
3007 $moduleobj = new $class($db);
3008 '@phan-var-force DolibarrModules $moduleobj';
3010 } catch (Exception $e) {
3011 $error++;
3012 dol_print_error($db, $e->getMessage());
3013 }
3014 }
3015 $menus = $moduleobj->menu;
3016 $key = GETPOSTINT('menukey') - 1;
3017
3018 $moduledescriptorfile = $dirins.'/'.strtolower($module).'/core/modules/mod'.$module.'.class.php';
3019 //stock forms in array
3020 $menuModify = array(
3021 'fk_menu' => GETPOST('fk_menu', 'alpha'),
3022 'type' => GETPOST('type', 'alpha'),
3023 'titre' => ucfirst(GETPOST('titre', 'alpha')),
3024 'prefix' => '',
3025 'mainmenu' => GETPOST('mainmenu', 'alpha'),
3026 'leftmenu' => $menus[$key]['leftmenu'],
3027 'url' => GETPOST('url', 'alpha'),
3028 'langs' => strtolower($module)."@".strtolower($module),
3029 'position' => '',
3030 'enabled' => GETPOST('enabled', 'alpha'),
3031 'perms' => GETPOST('perms', 'alpha'),
3032 'target' => GETPOST('target', 'alpha'),
3033 'user' => GETPOSTINT('user'),
3034 );
3035 if (!empty(GETPOST('fk_menu')) && GETPOST('fk_menu') != $menus[$key]['fk_menu']) {
3036 $menuModify['fk_menu'] = 'fk_mainmenu='.GETPOST('mainmenu').',fk_leftmenu='.GETPOST('fk_menu');
3037 } elseif (GETPOST('fk_menu') == $menus[$key]['fk_menu']) {
3038 $menuModify['fk_menu'] = $menus[$key]['fk_menu'];
3039 } else {
3040 $menuModify['fk_menu'] = 'fk_mainmenu='.GETPOST('mainmenu');
3041 }
3042 if ($menuModify['enabled'] === '') {
3043 $menuModify['enabled'] = '1';
3044 }
3045 if ($menuModify['perms'] === '') {
3046 $menuModify['perms'] = '1';
3047 }
3048
3049 if (GETPOST('type', 'alpha') == 'top') {
3050 $error++;
3051 setEventMessages($langs->trans("ErrorTypeMenu", $langs->transnoentities("type")), null, 'errors');
3052 }
3053
3054 if (!$error) {
3055 //update menu
3056 $checkComment = checkExistComment($moduledescriptorfile, 0);
3057
3058 if ($checkComment < 0) {
3059 setEventMessages($langs->trans("WarningCommentNotFound", $langs->trans("Menus"), "mod".$module."class.php"), null, 'warnings');
3060 } else {
3061 // Write all menus
3062 $result = reWriteAllMenus($moduledescriptorfile, $menus, $menuModify, $key, 2);
3063
3064 clearstatcache(true);
3065 if (function_exists('opcache_invalidate')) {
3066 opcache_reset();
3067 }
3068
3069 if ($result < 0) {
3070 setEventMessages($langs->trans('ErrorMenuExistValue'), null, 'errors');
3071 //var_dump($_SESSION);exit;
3072 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));
3073 exit;
3074 }
3075
3076 setEventMessages($langs->trans('MenuUpdatedSuccessfuly'), null);
3077 header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=menus&module='.$module);
3078 exit;
3079 }
3080 }
3081 } else {
3082 $_POST['type'] = ''; // TODO Use a var here and later
3083 $_POST['titre'] = '';
3084 $_POST['fk_menu'] = '';
3085 $_POST['leftmenu'] = '';
3086 $_POST['url'] = '';
3087 }
3088}
3089
3090// update properties description of module
3091if ($dirins && $action == "update_props_module" && !empty(GETPOST('keydescription', 'alpha')) && empty($cancel) && $user->hasRight("modulebuilder", "run")) {
3092 if (isModEnabled(strtolower($module))) {
3093 $result = unActivateModule(strtolower($module));
3094 dolibarr_set_const($db, "MAIN_IHM_PARAMS_REV", getDolGlobalInt('MAIN_IHM_PARAMS_REV') + 1, 'chaine', 0, '', $conf->entity);
3095 if ($result) {
3096 setEventMessages($result, null, 'errors');
3097 }
3098 setEventMessages($langs->trans('WarningModuleNeedRefresh', $langs->transnoentities($module)), null, 'warnings');
3099 header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=menus&module='.$module);
3100 exit;
3101 }
3102 $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
3103 $moduledescriptorfile = $dirins.'/'.strtolower($module).'/core/modules/mod'.$module.'.class.php';
3104 $modulelogfile = $dirins.'/'.strtolower($module).'/ChangeLog.md';
3105
3106 dol_include_once($pathtofile);
3107
3108 $class = 'mod'.$module;
3109 $moduleobj = null;
3110 if (class_exists($class)) {
3111 try {
3112 $moduleobj = new $class($db);
3113 '@phan-var-force DolibarrModules $moduleobj';
3115 } catch (Exception $e) {
3116 $error++;
3117 dol_print_error($db, $e->getMessage());
3118 }
3119 }
3120
3121 $keydescription = GETPOST('keydescription', 'alpha');
3122 switch ($keydescription) {
3123 case 'desc':
3124 $propertyToUpdate = 'description';
3125 break;
3126 case 'version':
3127 case 'family':
3128 case 'picto':
3129 case 'editor_name':
3130 case 'editor_url':
3131 $propertyToUpdate = $keydescription;
3132 break;
3133 default:
3134 $error = GETPOST('keydescription');
3135 break;
3136 }
3137
3138 if (isset($propertyToUpdate) && !empty(GETPOST('propsmodule'))) {
3139 $newValue = GETPOST('propsmodule');
3140 $lineToReplace = "\t\t\$this->$propertyToUpdate = ";
3141 $newLine = "\t\t\$this->$propertyToUpdate = '$newValue';\n";
3142
3143 //for change version in log file
3144 if ($propertyToUpdate === 'version') {
3145 dolReplaceInFile($modulelogfile, array("## ".$moduleobj->$propertyToUpdate => $newValue));
3146 }
3147
3148 $fileLines = file($moduledescriptorfile);
3149 foreach ($fileLines as &$line) {
3150 if (strpos($line, $lineToReplace) === 0) {
3151 dolReplaceInFile($moduledescriptorfile, array($line => $newLine));
3152 break;
3153 }
3154 }
3155
3156 clearstatcache(true);
3157 if (function_exists('opcache_invalidate')) {
3158 opcache_reset();
3159 }
3160 setEventMessages($langs->trans('PropertyModuleUpdated', $propertyToUpdate), null);
3161 header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=description&module='.$module);
3162 exit;
3163 }
3164}
3165
3166
3167/*
3168 * View
3169 */
3170
3171$form = new Form($db);
3172$formadmin = new FormAdmin($db);
3173
3174// Set dir where external modules are installed
3175if (!dol_is_dir($dirins)) {
3176 dol_mkdir($dirins);
3177}
3178$dirins_ok = (dol_is_dir($dirins));
3179
3180$help_url = '';
3181$morejs = array(
3182 '/includes/ace/src/ace.js',
3183 '/includes/ace/src/ext-statusbar.js',
3184 '/includes/ace/src/ext-language_tools.js',
3185 //'/includes/ace/src/ext-chromevox.js'
3186);
3187$morecss = array();
3188
3189llxHeader('', $langs->trans("ModuleBuilder"), $help_url, '', 0, 0, $morejs, $morecss, '', 'classforhorizontalscrolloftabs');
3190
3191
3192$text = $langs->trans("ModuleBuilder");
3193
3194print load_fiche_titre($text, '', 'title_setup');
3195
3196print '<span class="opacitymedium hideonsmartphone">'.$langs->trans("ModuleBuilderDesc", 'https://wiki.dolibarr.org/index.php/Module_development#Create_your_module').'</span>';
3197print '<br class="hideonsmartphone">';
3198
3199//print $textforlistofdirs;
3200//print '<br>';
3201
3202
3203
3204$message = '';
3205if (!$dirins) {
3206 $message = info_admin($langs->trans("ConfFileMustContainCustom", DOL_DOCUMENT_ROOT.'/custom', DOL_DOCUMENT_ROOT));
3207 $allowfromweb = -1;
3208} else {
3209 if ($dirins_ok) {
3210 if (!is_writable(dol_osencode($dirins))) {
3211 $langs->load("errors");
3212 $message = info_admin($langs->trans("ErrorFailedToWriteInDir", $dirins));
3213 $allowfromweb = 0;
3214 }
3215 } else {
3216 $message = info_admin($langs->trans("NotExistsDirect", $dirins).$langs->trans("InfDirAlt").$langs->trans("InfDirExample"));
3217 $allowfromweb = 0;
3218 }
3219}
3220if ($message) {
3221 print $message;
3222}
3223
3224//print $langs->trans("ModuleBuilderDesc3", count($listofmodules), $FILEFLAG).'<br>';
3225$infomodulesfound = '<div style="padding: 12px 9px 12px">'.$form->textwithpicto('', $langs->trans("ModuleBuilderDesc3", count($listofmodules)).'<br><br>'.$langs->trans("ModuleBuilderDesc4", $FILEFLAG).'<br>'.$textforlistofdirs).'</div>';
3226
3227
3228
3229$dolibarrdataroot = preg_replace('/([\\/]+)$/i', '', DOL_DATA_ROOT);
3230$allowonlineinstall = true;
3231if (dol_is_file($dolibarrdataroot.'/installmodules.lock')) {
3232 $allowonlineinstall = false;
3233}
3234if (empty($allowonlineinstall)) {
3235 if (getDolGlobalString('MAIN_MESSAGE_INSTALL_MODULES_DISABLED_CONTACT_US')) {
3236 // Show clean message
3237 $message = info_admin($langs->trans('InstallModuleFromWebHasBeenDisabledContactUs'));
3238 } else {
3239 // Show technical message
3240 $message = info_admin($langs->trans("InstallModuleFromWebHasBeenDisabledByFile", $dolibarrdataroot.'/installmodules.lock'), 0, 0, '1', 'warning');
3241 }
3242
3243 print $message;
3244
3245 llxFooter();
3246 exit(0);
3247}
3248
3249
3250// Load module descriptor
3251$error = 0;
3253
3254
3255if (!empty($module) && $module != 'initmodule' && $module != 'deletemodule') {
3256 $modulelowercase = strtolower($module);
3257 $loadclasserrormessage = '';
3258
3259 // Load module
3260 try {
3261 $fullpathdirtodescriptor = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
3262
3263 //throw(new Exception());
3264 dol_include_once($fullpathdirtodescriptor);
3265
3266 $class = 'mod'.$module;
3267 } catch (Throwable $e) { // This is called in PHP 7 only (includes Error and Exception)
3268 $loadclasserrormessage = $e->getMessage()."<br>\n";
3269 $loadclasserrormessage .= 'File: '.$e->getFile()."<br>\n";
3270 $loadclasserrormessage .= 'Line: '.$e->getLine()."<br>\n";
3271 }
3272
3273 $moduleobj = null;
3274 if (class_exists($class)) {
3275 try {
3276 $moduleobj = new $class($db);
3277 '@phan-var-force DolibarrModules $moduleobj';
3279 } catch (Exception $e) {
3280 $error++;
3281 print $e->getMessage();
3282 }
3283 } else {
3284 if (empty($forceddirread)) {
3285 $error++;
3286 }
3287 $langs->load("errors");
3288 print '<!-- ErrorFailedToLoadModuleDescriptorForXXX -->';
3289 print img_warning('').' '.$langs->trans("ErrorFailedToLoadModuleDescriptorForXXX", $module).'<br>';
3290 print $loadclasserrormessage;
3291 }
3292}
3293
3294print '<br>';
3295
3296
3297// Tabs for all modules
3298$head = array();
3299$h = 0;
3300
3301$head[$h][0] = $_SERVER["PHP_SELF"].'?module=initmodule';
3302$head[$h][1] = '<span class="valignmiddle text-plus-circle">'.$langs->trans("NewModule").'</span><span class="fa fa-plus-circle valignmiddle paddingleft"></span>';
3303$head[$h][2] = 'initmodule';
3304$h++;
3305
3306$linktoenabledisable = '';
3307
3308if (is_array($listofmodules) && count($listofmodules) > 0) {
3309 // Define $linktoenabledisable
3310 $modulelowercase = strtolower($module);
3311
3312 $param = '';
3313 if ($tab) {
3314 $param .= '&tab='.urlencode($tab);
3315 }
3316 if ($module) {
3317 $param .= '&module='.urlencode($module);
3318 }
3319 if ($tabobj) {
3320 $param .= '&tabobj='.urlencode($tabobj);
3321 }
3322
3323 $urltomodulesetup = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?search_keyword='.urlencode($module).'">'.$langs->trans('Home').'-'.$langs->trans("Setup").'-'.$langs->trans("Modules").'</a>';
3324
3325 // Define $linktoenabledisable to show after module title
3326 if (isModEnabled($modulelowercase)) { // If module is already activated
3327 $linktoenabledisable .= '<a class="reposition asetresetmodule valignmiddle" href="'.$_SERVER["PHP_SELF"].'?id='.$moduleobj->numero.'&action=reset&token='.newToken().'&value=mod'.$module.$param.'">';
3328 $linktoenabledisable .= img_picto($langs->trans("Activated"), 'switch_on', '', 0, 0, 0, '', '', 1);
3329 $linktoenabledisable .= '</a>';
3330
3331 $linktoenabledisable .= $form->textwithpicto('', $langs->trans("Warning").' : '.$langs->trans("ModuleIsLive"), -1, 'warning');
3332
3333 $objMod = $moduleobj;
3334 $backtourlparam = '';
3335 $backtourlparam .= ($backtourlparam ? '&' : '?').'module='.$module; // No urlencode here, done later
3336 if ($tab) {
3337 $backtourlparam .= ($backtourlparam ? '&' : '?').'tab='.$tab; // No urlencode here, done later
3338 }
3339 $backtourl = $_SERVER["PHP_SELF"].$backtourlparam;
3340
3341 $regs = array();
3342 if (is_array($objMod->config_page_url)) {
3343 $i = 0;
3344 foreach ($objMod->config_page_url as $page) {
3345 $urlpage = $page;
3346 if ($i++) {
3347 $linktoenabledisable .= ' <a href="'.$urlpage.'" title="'.$langs->trans($page).'">'.img_picto(ucfirst($page), "setup").'</a>';
3348 // print '<a href="'.$page.'">'.ucfirst($page).'</a>&nbsp;';
3349 } else {
3350 if (preg_match('/^([^@]+)@([^@]+)$/i', $urlpage, $regs)) {
3351 $urltouse = dol_buildpath('/'.$regs[2].'/admin/'.$regs[1], 1);
3352 $linktoenabledisable .= ' <a href="'.$urltouse.(preg_match('/\?/', $urltouse) ? '&' : '?').'save_lastsearch_values=1&backtopage='.urlencode($backtourl).'" title="'.$langs->trans("Setup").'">'.img_picto($langs->trans("Setup"), "setup", 'style="padding-right: 8px"').'</a>';
3353 } else {
3354 // Case standard admin page (not a page provided by the
3355 // module but a page provided by dolibarr)
3356 $urltouse = DOL_URL_ROOT.'/admin/'.$urlpage;
3357 $linktoenabledisable .= ' <a href="'.$urltouse.(preg_match('/\?/', $urltouse) ? '&' : '?').'save_lastsearch_values=1&backtopage='.urlencode($backtourl).'" title="'.$langs->trans("Setup").'">'.img_picto($langs->trans("Setup"), "setup", 'style="padding-right: 8px"').'</a>';
3358 }
3359 }
3360 }
3361 } elseif (preg_match('/^([^@]+)@([^@]+)$/i', $objMod->config_page_url, $regs)) {
3362 $linktoenabledisable .= ' &nbsp; <a 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"').'</a>';
3363 }
3364 } else {
3365 if (is_object($moduleobj)) {
3366 $linktoenabledisable .= '<a class="reposition asetresetmodule valignmiddle" href="'.$_SERVER["PHP_SELF"].'?id='.$moduleobj->numero.'&action=set&token='.newToken().'&value=mod'.$module.$param.'">';
3367 $linktoenabledisable .= img_picto($langs->trans("ModuleIsNotActive", $urltomodulesetup), 'switch_off', 'style="padding-right: 8px"', 0, 0, 0, '', 'classfortooltip', 1);
3368 $linktoenabledisable .= "</a>\n";
3369 }
3370 }
3371
3372 // Loop to show tab of each module
3373 foreach ($listofmodules as $tmpmodule => $tmpmodulearray) {
3374 $head[$h][0] = $_SERVER["PHP_SELF"].'?module='.$tmpmodulearray['modulenamewithcase'].($forceddirread ? '@'.$dirread : '');
3375 $head[$h][1] = $tmpmodulearray['modulenamewithcase'];
3376 $head[$h][2] = $tmpmodulearray['modulenamewithcase'];
3377
3378 if ($tmpmodulearray['modulenamewithcase'] == $module) {
3379 $head[$h][4] = '<span class="inline-block">'.$linktoenabledisable.'</span>';
3380 }
3381
3382 $h++;
3383 }
3384}
3385
3386$head[$h][0] = $_SERVER["PHP_SELF"].'?module=deletemodule';
3387$head[$h][1] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("DangerZone");
3388$head[$h][2] = 'deletemodule';
3389$h++;
3390
3391
3392print dol_get_fiche_head($head, $module, '', -1, '', 0, $infomodulesfound, '', 8); // Modules
3393
3394if ($module == 'initmodule') {
3395 // New module
3396 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
3397 print '<input type="hidden" name="token" value="'.newToken().'">';
3398 print '<input type="hidden" name="action" value="initmodule">';
3399 print '<input type="hidden" name="module" value="initmodule">';
3400
3401 //print '<span class="opacitymedium">'.$langs->trans("ModuleBuilderDesc2", 'conf/conf.php', $newdircustom).'</span><br>';
3402 print '<br>';
3403
3404 print '<div class="tagtable">';
3405
3406 print '<div class="tagtr"><div class="tagtd paddingright">';
3407 print '<span class="opacitymedium">'.$langs->trans("IdModule").'</span>';
3408 print '</div><div class="tagtd">';
3409 print '<input type="text" name="idmodule" class="width75" value="500000" placeholder="'.dol_escape_htmltag($langs->trans("IdModule")).'">';
3410 print '<span class="opacitymedium">';
3411 print ' &nbsp; (';
3412 print dolButtonToOpenUrlInDialogPopup('popup_modules_id', $langs->transnoentitiesnoconv("SeeIDsInUse"), $langs->transnoentitiesnoconv("SeeIDsInUse"), '/admin/system/modules.php?mainmenu=home&leftmenu=admintools_info', '', '');
3413 print ' - ';
3414 print '<a href="https://wiki.dolibarr.org/index.php/List_of_modules_id" target="_blank" rel="noopener noreferrer external">'.$langs->trans("SeeReservedIDsRangeHere").'</a>';
3415 print ')';
3416 print '</span>';
3417 print '</div></div>';
3418
3419 print '<div class="tagtr"><div class="tagtd paddingright">';
3420 print '<span class="opacitymedium fieldrequired">'.$langs->trans("ModuleName").'</span>';
3421 print '</div><div class="tagtd">';
3422 print '<input type="text" name="modulename" value="'.dol_escape_htmltag($modulename).'" autofocus>';
3423 print ' '.$form->textwithpicto('', $langs->trans("EnterNameOfModuleDesc"));
3424 print '</div></div>';
3425
3426 print '<div class="tagtr"><div class="tagtd paddingright">';
3427 print '<span class="opacitymedium">'.$langs->trans("Description").'</span>';
3428 print '</div><div class="tagtd">';
3429 print '<input type="text" name="description" value="" class="minwidth500"><br>';
3430 print '</div></div>';
3431
3432 print '<div class="tagtr"><div class="tagtd paddingright">';
3433 print '<span class="opacitymedium">'.$langs->trans("Version").'</span>';
3434 print '</div><div class="tagtd">';
3435 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")).'">';
3436 print '</div></div>';
3437
3438 print '<div class="tagtr"><div class="tagtd paddingright">';
3439 print '<span class="opacitymedium">'.$langs->trans("Family").'</span>';
3440 print '</div><div class="tagtd">';
3441 print '<select name="family" id="family" class="minwidth400">';
3442 $arrayoffamilies = array(
3443 'hr' => "ModuleFamilyHr",
3444 'crm' => "ModuleFamilyCrm",
3445 'srm' => "ModuleFamilySrm",
3446 'financial' => 'ModuleFamilyFinancial',
3447 'products' => 'ModuleFamilyProducts',
3448 'projects' => 'ModuleFamilyProjects',
3449 'ecm' => 'ModuleFamilyECM',
3450 'technic' => 'ModuleFamilyTechnic',
3451 'portal' => 'ModuleFamilyPortal',
3452 'interface' => 'ModuleFamilyInterface',
3453 'base' => 'ModuleFamilyBase',
3454 'other' => 'ModuleFamilyOther'
3455 );
3456 foreach ($arrayoffamilies as $key => $value) {
3457 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>';
3458 }
3459 print '</select>';
3460 print ajax_combobox("family");
3461 print '</div></div>';
3462
3463 print '<div class="tagtr"><div class="tagtd paddingright">';
3464 print '<span class="opacitymedium">'.$langs->trans("Picto").'</span>';
3465 print '</div><div class="tagtd">';
3466 print '<input type="text" name="idpicto" value="'.(GETPOSTISSET('idpicto') ? GETPOST('idpicto') : getDolGlobalString('MODULEBUILDER_DEFAULTPICTO', 'fa-file')).'" placeholder="'.dol_escape_htmltag($langs->trans("Picto")).'">';
3467 print $form->textwithpicto('', $langs->trans("Example").': fa-file, fa-globe, ... any font awesome code.<br>Advanced syntax is fa-fakey[_faprefix[_facolor[_fasize]]]');
3468 print '</div></div>';
3469
3470 print '<div class="tagtr"><div class="tagtd paddingright">';
3471 print '<span class="opacitymedium">'.$langs->trans("EditorName").'</span>';
3472 print '</div><div class="tagtd">';
3473 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")).'"><br>';
3474 print '</div></div>';
3475
3476 print '<div class="tagtr"><div class="tagtd paddingright">';
3477 print '<span class="opacitymedium">'.$langs->trans("EditorUrl").'</span>';
3478 print '</div><div class="tagtd">';
3479 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")).'"><br>';
3480 print '</div></div>';
3481
3482 print '<br><input type="submit" class="button" name="create" value="'.dol_escape_htmltag($langs->trans("Create")).'"'.($dirins ? '' : ' disabled="disabled"').'>';
3483 print '</form>';
3484} elseif ($module == 'deletemodule') {
3485 print '<!-- Form to init a module -->'."\n";
3486 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST" name="delete">';
3487 print '<input type="hidden" name="token" value="'.newToken().'">';
3488 print '<input type="hidden" name="action" value="confirm_deletemodule">';
3489 print '<input type="hidden" name="module" value="deletemodule">';
3490
3491 print $langs->trans("EnterNameOfModuleToDeleteDesc").'<br><br>';
3492
3493 print '<input type="text" name="module" placeholder="'.dol_escape_htmltag($langs->trans("ModuleKey")).'" value="" autofocus>';
3494 print '<input type="submit" class="button smallpaddingimp" value="'.$langs->trans("Delete").'"'.($dirins ? '' : ' disabled="disabled"').'>';
3495 print '</form>';
3496} elseif (!empty($module) && isset($modulelowercase)) {
3497 // Tabs for module
3498 if (!$error) {
3499 $dirread = $listofmodules[strtolower($module)]['moduledescriptorrootpath'];
3500 $destdir = $dirread.'/'.strtolower($module);
3501 $objects = dolGetListOfObjectClasses($destdir);
3502 $diroflang = dol_buildpath($modulelowercase, 0)."/langs";
3503 $countLangs = countItemsInDirectory($diroflang, 2);
3504 $countDictionaries = (!empty($moduleobj->dictionaries) ? count($moduleobj->dictionaries['tabname']) : 0);
3505 $countRights = count($moduleobj->rights);
3506 $countMenus = count($moduleobj->menu);
3507 $countTriggers = countItemsInDirectory(dol_buildpath($modulelowercase, 0)."/core/triggers");
3508 $countWidgets = countItemsInDirectory(dol_buildpath($modulelowercase, 0)."/core/boxes");
3509 $countEmailingSelectors = countItemsInDirectory(dol_buildpath($modulelowercase, 0)."/core/modules/mailings");
3510 $countCss = countItemsInDirectory(dol_buildpath($modulelowercase, 0)."/css");
3511 $countJs = countItemsInDirectory(dol_buildpath($modulelowercase, 0)."/js");
3512 $countCLI = countItemsInDirectory(dol_buildpath($modulelowercase, 0)."/scripts");
3513 $hasDoc = countItemsInDirectory(dol_buildpath($modulelowercase, 0)."/doc");
3514 //var_dump($moduleobj->dictionaries);exit;
3515 $head2 = array();
3516 $h = 0;
3517
3518 $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=description&module='.$module.($forceddirread ? '@'.$dirread : '');
3519 $head2[$h][1] = $langs->trans("Description");
3520 $head2[$h][2] = 'description';
3521 $h++;
3522
3523 $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=objects&module='.$module.($forceddirread ? '@'.$dirread : '');
3524 $head2[$h][1] = ((!is_array($objects) || count($objects) <= 0) ? $langs->trans("Objects") : $langs->trans("Objects").'<span class="marginleftonlyshort badge">'.count($objects)."</span>");
3525 $head2[$h][2] = 'objects';
3526 $h++;
3527
3528 $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=languages&module='.$module.($forceddirread ? '@'.$dirread : '');
3529 $head2[$h][1] = ($countLangs <= 0 ? $langs->trans("Languages") : $langs->trans("Languages").'<span class="marginleftonlyshort badge">'.$countLangs."</span>");
3530 $head2[$h][2] = 'languages';
3531 $h++;
3532
3533 $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=dictionaries&module='.$module.($forceddirread ? '@'.$dirread : '');
3534 $head2[$h][1] = ($countDictionaries == 0 ? $langs->trans("Dictionaries") : $langs->trans('Dictionaries').'<span class="marginleftonlyshort badge">'.$countDictionaries."</span>");
3535 $head2[$h][2] = 'dictionaries';
3536 $h++;
3537
3538 $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=permissions&module='.$module.($forceddirread ? '@'.$dirread : '');
3539 $head2[$h][1] = ($countRights <= 0 ? $langs->trans("Permissions") : $langs->trans("Permissions").'<span class="marginleftonlyshort badge">'.$countRights."</span>");
3540 $head2[$h][2] = 'permissions';
3541 $h++;
3542
3543 $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=tabs&module='.$module.($forceddirread ? '@'.$dirread : '');
3544 $head2[$h][1] = $langs->trans("Tabs");
3545 $head2[$h][2] = 'tabs';
3546 $h++;
3547
3548 $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=menus&module='.$module.($forceddirread ? '@'.$dirread : '');
3549 $head2[$h][1] = ($countMenus <= 0 ? $langs->trans("Menus") : $langs->trans("Menus").'<span class="marginleftonlyshort badge">'.$countMenus."</span>");
3550 $head2[$h][2] = 'menus';
3551 $h++;
3552
3553 $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=hooks&module='.$module.($forceddirread ? '@'.$dirread : '');
3554 $head2[$h][1] = $langs->trans("Hooks");
3555 $head2[$h][2] = 'hooks';
3556 $h++;
3557
3558 $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=triggers&module='.$module.($forceddirread ? '@'.$dirread : '');
3559 $head2[$h][1] = ($countTriggers <= 0 ? $langs->trans("Triggers") : $langs->trans("Triggers").'<span class="marginleftonlyshort badge">'.$countTriggers."</span>");
3560 $head2[$h][2] = 'triggers';
3561 $h++;
3562
3563 $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=widgets&module='.$module.($forceddirread ? '@'.$dirread : '');
3564 $head2[$h][1] = ($countWidgets <= 0 ? $langs->trans("Widgets") : $langs->trans("Widgets").'<span class="marginleftonlyshort badge">'.$countWidgets."</span>");
3565 $head2[$h][2] = 'widgets';
3566 $h++;
3567
3568 $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=emailings&module='.$module.($forceddirread ? '@'.$dirread : '');
3569 $head2[$h][1] = ($countEmailingSelectors <= 0 ? $langs->trans("EmailingSelectors") : $langs->trans("EmailingSelectors").'<span class="marginleftonlyshort badge">'.$countEmailingSelectors."</span>");
3570 $head2[$h][2] = 'emailings';
3571 $h++;
3572
3573 $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=exportimport&module='.$module.($forceddirread ? '@'.$dirread : '');
3574 $head2[$h][1] = $langs->trans("Export").'-'.$langs->trans("Import");
3575 $head2[$h][2] = 'exportimport';
3576 $h++;
3577
3578 $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=css&module='.$module.($forceddirread ? '@'.$dirread : '');
3579 $head2[$h][1] = ($countCss <= 0 ? $langs->trans("CSS") : $langs->trans("CSS")." (".$countCss.")");
3580 $head2[$h][2] = 'css';
3581 $h++;
3582
3583 $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=js&module='.$module.($forceddirread ? '@'.$dirread : '');
3584 $head2[$h][1] = ($countJs <= 0 ? $langs->trans("JS") : $langs->trans("JS").'<span class="marginleftonlyshort badge">'.$countJs."</span>");
3585 $head2[$h][2] = 'js';
3586 $h++;
3587
3588 $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=cli&module='.$module.($forceddirread ? '@'.$dirread : '');
3589 $head2[$h][1] = ($countCLI <= 0 ? $langs->trans("CLI") : $langs->trans("CLI").'<span class="marginleftonlyshort badge">'.$countCLI."</span>");
3590 $head2[$h][2] = 'cli';
3591 $h++;
3592
3593 $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=cron&module='.$module.($forceddirread ? '@'.$dirread : '');
3594 $head2[$h][1] = $langs->trans("CronList");
3595 $head2[$h][2] = 'cron';
3596 $h++;
3597
3598 $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=specifications&module='.$module.($forceddirread ? '@'.$dirread : '');
3599 $head2[$h][1] = ($hasDoc <= 0 ? $langs->trans("Documentation") : $langs->trans("Documentation").'<span class="paddingleft badge">'.$hasDoc."</span>");
3600 $head2[$h][2] = 'specifications';
3601 $h++;
3602
3603 $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=buildpackage&module='.$module.($forceddirread ? '@'.$dirread : '');
3604 $head2[$h][1] = $langs->trans("BuildPackage");
3605 $head2[$h][2] = 'buildpackage';
3606 $h++;
3607
3608 $MAXTABFOROBJECT = 15;
3609
3610 print '<!-- Section for a given module -->';
3611
3612 // Note module is inside $dirread
3613
3614 if ($tab == 'description') {
3615 print '<!-- tab=description -->'."\n";
3616 $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
3617 $pathtofilereadme = $modulelowercase.'/README.md';
3618 $pathtochangelog = $modulelowercase.'/ChangeLog.md';
3619
3620 $realpathofmodule = realpath($dirread.'/'.$modulelowercase);
3621
3622 if ($action != 'editfile' || empty($file)) {
3623 $morehtmlright = '';
3624 if ($realpathofmodule != $dirread.'/'.$modulelowercase) {
3625 $morehtmlright = '<div style="padding: 12px 9px 12px">'.$form->textwithpicto('', '<span class="opacitymedium">'.$langs->trans("RealPathOfModule").' :</span> <strong class="wordbreak">'.$realpathofmodule.'</strong>').'</div>';
3626 }
3627
3628 print dol_get_fiche_head($head2, $tab, '', -1, '', 0, $morehtmlright, '', $MAXTABFOROBJECT, 'formodulesuffix'); // Description - level 2
3629
3630 print '<span class="opacitymedium">'.$langs->trans("ModuleBuilderDesc".$tab).'</span>';
3631 print '<br><br>';
3632
3633 print '<table>';
3634
3635 print '<tr><td>';
3636 print '<span class="fa fa-file"></span> '.$langs->trans("DescriptorFile").' : <strong class="wordbreak">'.$pathtofile.'</strong>';
3637 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>';
3638 print '</td></tr>';
3639
3640 // List of setup pages
3641 $listofsetuppages = dol_dir_list($realpathofmodule.'/admin', 'files', 0, '\.php$');
3642 foreach ($listofsetuppages as $setuppage) {
3643 //var_dump($setuppage);
3644 print '<tr><td>';
3645 print '<span class="fa fa-file"></span> ';
3646 if ($setuppage['relativename'] == 'about.php') {
3647 print $langs->trans("AboutFile");
3648 } else {
3649 print $langs->trans("SetupFile");
3650 }
3651 print ' : ';
3652 print '<strong class="wordbreak bold"><a href="'.dol_buildpath($modulelowercase.'/admin/'.$setuppage['relativename'], 1).'" target="_test">'.$modulelowercase.'/admin/'.$setuppage['relativename'].'</a></strong>';
3653 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>';
3654 print '</td></tr>';
3655 }
3656
3657 print '<tr><td><span class="fa fa-file"></span> '.$langs->trans("ReadmeFile").' : <strong class="wordbreak">'.$pathtofilereadme.'</strong>';
3658 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>';
3659 print '</td></tr>';
3660
3661 print '<tr><td><span class="fa fa-file"></span> '.$langs->trans("ChangeLog").' : <strong class="wordbreak">'.$pathtochangelog.'</strong>';
3662 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>';
3663 print '</td></tr>';
3664
3665 print '</table>';
3666 print '<br>';
3667
3668 print load_fiche_titre($form->textwithpicto($langs->trans("DescriptorFile"), $langs->transnoentitiesnoconv("File").' '.$pathtofile), '', '');
3669
3670 if (is_object($moduleobj)) {
3671 print '<div class="underbanner clearboth"></div>';
3672 print '<div class="fichecenter">';
3673 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
3674 print '<input type="hidden" name="token" value="'.newToken().'">';
3675 print '<input type="hidden" name="action" value="update_props_module">';
3676 print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
3677 print '<input type="hidden" name="tab" value="'.dol_escape_htmltag($tab).'">';
3678 print '<input type="hidden" name="keydescription" value="'.dol_escape_htmltag(GETPOST('keydescription', 'alpha')).'">';
3679 print '<table class="border centpercent">';
3680 print '<tr class="liste_titre"><td class="titlefield">';
3681 print $langs->trans("Parameter");
3682 print '</td><td>';
3683 print $langs->trans("Value");
3684 print '</td></tr>';
3685
3686 print '<tr><td>';
3687 print $langs->trans("IdModule");
3688 print '</td><td>';
3689 print $moduleobj->numero;
3690 print '<span class="opacitymedium">';
3691 print ' &nbsp; (';
3692 print dolButtonToOpenUrlInDialogPopup('popup_modules_id', $langs->transnoentitiesnoconv("SeeIDsInUse"), $langs->transnoentitiesnoconv("SeeIDsInUse"), '/admin/system/modules.php?mainmenu=home&leftmenu=admintools_info', '', '');
3693 print ' - <a href="https://wiki.dolibarr.org/index.php/List_of_modules_id" target="_blank" rel="noopener noreferrer external">'.$langs->trans("SeeReservedIDsRangeHere").'</a>)';
3694 print '</span>';
3695 print '</td></tr>';
3696
3697 print '<tr><td>';
3698 print $langs->trans("ModuleName");
3699 print '</td><td>';
3700 print $moduleobj->getName();
3701 print '</td></tr>';
3702
3703 print '<tr><td>';
3704 print $langs->trans("Description");
3705 print '</td><td>';
3706 if ($action == 'edit_moduledescription' && GETPOST('keydescription', 'alpha') === 'desc') {
3707 print '<input class="minwidth500" name="propsmodule" value="'.dol_escape_htmltag($moduleobj->description).'">';
3708 print '<input class="reposition button smallpaddingimp" type="submit" name="modifydesc" value="'.$langs->trans("Modify").'"/>';
3709 print '<input class="reposition button button-cancel smallpaddingimp" type="submit" name="cancel" value="'.$langs->trans("Cancel").'"/>';
3710 } else {
3711 print $moduleobj->description;
3712 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>';
3713
3714 $moduledescritpionautotrans = $moduleobj->getDesc();
3715 if ($moduledescritpionautotrans != "Module".$moduleobj->name."Desc") {
3716 // $moduledescritpionautotrans has been found into a translation file
3717 print ' '.$form->textwithpicto('', $langs->trans("ModuleTranslatedIntoLangForKeyInto", "Module".$moduleobj->name."Desc", $moduledescritpionautotrans));
3718 } elseif ($moduledescritpionautotrans != "Module".$moduleobj->numero."Desc") {
3719 // $moduledescritpionautotrans has been found into a translation file
3720 print ' '.$form->textwithpicto('', $langs->trans("ModuleTranslatedIntoLangForKeyInto", "Module".$moduleobj->numero."Desc", $moduledescritpionautotrans));
3721 }
3722 }
3723 print '</td></tr>';
3724
3725 print '<tr><td>';
3726 print $langs->trans("Version");
3727 print '</td><td>';
3728 if ($action == 'edit_moduledescription' && GETPOST('keydescription', 'alpha') === 'version') {
3729 print '<input name="propsmodule" value="'.dol_escape_htmltag($moduleobj->getVersion()).'">';
3730 print '<input class="reposition button smallpaddingimp" type="submit" name="modifyversion" value="'.$langs->trans("Modify").'"/>';
3731 print '<input class="reposition button button-cancel smallpaddingimp" type="submit" name="cancel" value="'.$langs->trans("Cancel").'"/>';
3732 } else {
3733 print $moduleobj->getVersion();
3734 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>';
3735 }
3736 print '</td></tr>';
3737
3738 print '<tr><td>';
3739 print $langs->trans("Family");
3740 //print "<br>'crm','financial','hr','projects','products','ecm','technic','interface','other'";
3741 print '</td><td>';
3742 if ($action == 'edit_moduledescription' && GETPOST('keydescription', 'alpha') === 'family') {
3743 print '<select name="propsmodule" id="family" class="minwidth400">';
3744 $arrayoffamilies = array(
3745 'hr' => "ModuleFamilyHr",
3746 'crm' => "ModuleFamilyCrm",
3747 'srm' => "ModuleFamilySrm",
3748 'financial' => 'ModuleFamilyFinancial',
3749 'products' => 'ModuleFamilyProducts',
3750 'projects' => 'ModuleFamilyProjects',
3751 'ecm' => 'ModuleFamilyECM',
3752 'technic' => 'ModuleFamilyTechnic',
3753 'portal' => 'ModuleFamilyPortal',
3754 'interface' => 'ModuleFamilyInterface',
3755 'base' => 'ModuleFamilyBase',
3756 'other' => 'ModuleFamilyOther'
3757 );
3758 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>';
3759 foreach ($arrayoffamilies as $key => $value) {
3760 if ($key != $moduleobj->family) {
3761 print '<option value="'.$key.'" data-html="'.dol_escape_htmltag($langs->trans($value).' <span class="opacitymedium">- '.$key.'</span>').'">'.$langs->trans($value).'</option>';
3762 }
3763 }
3764 print '</select>';
3765 print '<input class="reposition button smallpaddingimp" type="submit" name="modifyfamily" value="'.$langs->trans("Modify").'"/>';
3766 print '<input class="reposition button button-cancel smallpaddingimp" type="submit" name="cancel" value="'.$langs->trans("Cancel").'"/>';
3767 } else {
3768 print $moduleobj->family;
3769 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>';
3770 }
3771 print '</td></tr>';
3772
3773 print '<tr><td>';
3774 print $langs->trans("Picto");
3775 print '</td><td>';
3776 if ($action == 'edit_modulepicto' && GETPOST('keydescription', 'alpha') === 'picto') {
3777 print '<input class="minwidth500" name="propsmodule" value="'.dol_escape_htmltag($moduleobj->picto).'">';
3778 print '<input class="reposition button smallpaddingimp" type="submit" name="modifypicto" value="'.$langs->trans("Modify").'"/>';
3779 print '<input class="reposition button button-cancel smallpaddingimp" type="submit" name="cancel" value="'.$langs->trans("Cancel").'"/>';
3780 } else {
3781 print $moduleobj->picto;
3782 print ' &nbsp; '.img_picto('', $moduleobj->picto, 'class="valignmiddle pictomodule paddingrightonly"');
3783 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>';
3784 }
3785 print '</td></tr>';
3786
3787 print '<tr><td>';
3788 print $langs->trans("EditorName");
3789 print '</td><td>';
3790 if ($action == 'edit_moduledescription' && GETPOST('keydescription', 'alpha') === 'editor_name') {
3791 print '<input name="propsmodule" value="'.dol_escape_htmltag($moduleobj->editor_name).'">';
3792 print '<input class="reposition button smallpaddingimp" type="submit" name="modifyname" value="'.$langs->trans("Modify").'"/>';
3793 print '<input class="reposition button button-cancel smallpaddingimp" type="submit" name="cancel" value="'.$langs->trans("Cancel").'"/>';
3794 } else {
3795 print $moduleobj->editor_name;
3796 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>';
3797 }
3798 print '</td></tr>';
3799
3800 print '<tr><td>';
3801 print $langs->trans("EditorUrl");
3802 print '</td><td>';
3803 if ($action == 'edit_moduledescription' && GETPOST('keydescription', 'alpha') === 'editor_url') {
3804 print '<input name="propsmodule" value="'.dol_escape_htmltag($moduleobj->editor_url).'">';
3805 print '<input class="reposition button smallpaddingimp" type="submit" name="modifyeditorurl" value="'.$langs->trans("Modify").'"/>';
3806 print '<input class="reposition button button-cancel smallpaddingimp" type="submit" name="cancel" value="'.$langs->trans("Cancel").'"/>';
3807 } else {
3808 if (!empty($moduleobj->editor_url)) {
3809 print '<a href="'.$moduleobj->editor_url.'" target="_blank" rel="noopener">'.$moduleobj->editor_url.' '.img_picto('', 'globe').'</a>';
3810 }
3811 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>';
3812 }
3813 print '</td></tr>';
3814
3815 print '</table>';
3816 print '</form>';
3817 } else {
3818 print $langs->trans("ErrorFailedToLoadModuleDescriptorForXXX", $module).'<br>';
3819 }
3820
3821 if (!empty($moduleobj)) {
3822 print '<br><br>';
3823
3824 // Readme file
3825 print load_fiche_titre($form->textwithpicto($langs->trans("ReadmeFile"), $langs->transnoentitiesnoconv("File").' '.$pathtofilereadme), '', '');
3826
3827 print '<!-- readme file -->';
3828 if (dol_is_file($dirread.'/'.$pathtofilereadme)) {
3829 print '<div class="underbanner clearboth"></div><div class="fichecenter">'.$moduleobj->getDescLong().'</div>';
3830 } else {
3831 print '<span class="opacitymedium">'.$langs->trans("ErrorFileNotFound", $pathtofilereadme).'</span>';
3832 }
3833
3834 print '<br><br>';
3835
3836 // ChangeLog
3837 print load_fiche_titre($form->textwithpicto($langs->trans("ChangeLog"), $langs->transnoentitiesnoconv("File").' '.$pathtochangelog), '', '');
3838
3839 print '<!-- changelog file -->';
3840 if (dol_is_file($dirread.'/'.$pathtochangelog)) {
3841 print '<div class="underbanner clearboth"></div><div class="fichecenter">'.$moduleobj->getChangeLog().'</div>';
3842 } else {
3843 print '<span class="opacitymedium">'.$langs->trans("ErrorFileNotFound", $pathtochangelog).'</span>';
3844 }
3845 }
3846
3847 print dol_get_fiche_end();
3848 } else { // Edit text file
3849 $fullpathoffile = dol_buildpath($file, 0, 1); // Description - level 2
3850
3851 if ($fullpathoffile) {
3852 $content = file_get_contents($fullpathoffile);
3853 }
3854
3855 // New module
3856 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
3857 print '<input type="hidden" name="token" value="'.newToken().'">';
3858 print '<input type="hidden" name="action" value="savefile">';
3859 print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
3860 print '<input type="hidden" name="tab" value="'.$tab.'">';
3861 print '<input type="hidden" name="module" value="'.$module.'">';
3862
3863 print dol_get_fiche_head($head2, $tab, '', -1, '', 0, '', '', 0, 'formodulesuffix');
3864
3865 $posCursor = (empty($find)) ? array() : array('find' => $find);
3866 $doleditor = new DolEditor('editfilecontent', $content, '', 300, 'Full', 'In', true, false, 'ace', 0, '99%', 0, $posCursor);
3867 print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ? GETPOST('format', 'aZ09') : 'html'));
3868
3869 print dol_get_fiche_end();
3870
3871 print '<center>';
3872 print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
3873 print ' &nbsp; ';
3874 print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
3875 print '</center>';
3876
3877 print '</form>';
3878 }
3879 } else {
3880 print dol_get_fiche_head($head2, $tab, '', -1, '', 0, '', '', $MAXTABFOROBJECT, 'formodulesuffix'); // Level 2
3881 }
3882
3883 if ($tab == 'languages') {
3884 print '<!-- tab=languages -->'."\n";
3885 if ($action != 'editfile' || empty($file)) {
3886 print '<span class="opacitymedium">'.$langs->trans("LanguageDefDesc").'</span><br>';
3887 print '<br>';
3888
3889
3890 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
3891 print '<input type="hidden" name="token" value="'.newToken().'">';
3892 print '<input type="hidden" name="action" value="addlanguage">';
3893 print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
3894 print '<input type="hidden" name="tab" value="'.$tab.'">';
3895 print '<input type="hidden" name="module" value="'.$module.'">';
3896 print $formadmin->select_language(getDolGlobalString('MAIN_LANG_DEFAULT'), 'newlangcode', 0, array(), 1, 0, 0, 'minwidth300', 1);
3897 print '<input type="submit" name="addlanguage" class="button smallpaddingimp" value="'.dol_escape_htmltag($langs->trans("AddLanguageFile")).'"><br>';
3898 print '</form>';
3899
3900 print '<br>';
3901 print '<br>';
3902
3903 $modulelowercase = strtolower($module);
3904
3905 // Dir for module
3906 $diroflang = dol_buildpath($modulelowercase, 0);
3907 $diroflang .= '/langs';
3908 $langfiles = dol_dir_list($diroflang, 'files', 1, '\.lang$');
3909
3910 if (!preg_match('/custom/', $dirread)) {
3911 // If this is not a module into custom
3912 $diroflang = $dirread;
3913 $diroflang .= '/langs';
3914 $langfiles = dol_dir_list($diroflang, 'files', 1, $modulelowercase.'\.lang$');
3915 }
3916
3917 print '<table class="none">';
3918 foreach ($langfiles as $langfile) {
3919 $pathtofile = $modulelowercase.'/langs/'.$langfile['relativename'];
3920 if (!preg_match('/custom/', $dirread)) { // If this is not a module into custom
3921 $pathtofile = 'langs/'.$langfile['relativename'];
3922 }
3923 print '<tr><td><span class="fa fa-file"></span> '.$langs->trans("LanguageFile").' '.basename(dirname($pathtofile)).' : <strong class="wordbreak">'.$pathtofile.'</strong>';
3924 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>';
3925 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>';
3926 print '</td>';
3927 }
3928 print '</table>';
3929 } else {
3930 // Edit text language file
3931
3932 //print $langs->trans("UseAsciiDocFormat").'<br>';
3933
3934 $fullpathoffile = dol_buildpath($file, 0);
3935
3936 $content = file_get_contents($fullpathoffile);
3937
3938 // New module
3939 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
3940 print '<input type="hidden" name="token" value="'.newToken().'">';
3941 print '<input type="hidden" name="action" value="savefile">';
3942 print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
3943 print '<input type="hidden" name="tab" value="'.$tab.'">';
3944 print '<input type="hidden" name="module" value="'.$module.'">';
3945
3946 $doleditor = new DolEditor('editfilecontent', $content, '', 300, 'Full', 'In', true, false, 'ace', 0, '99%');
3947 print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ? GETPOST('format', 'aZ09') : 'text'));
3948 print '<br>';
3949 print '<center>';
3950 print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
3951 print ' &nbsp; ';
3952 print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
3953 print '</center>';
3954
3955 print '</form>';
3956 }
3957 }
3958
3959 if ($tab == 'objects') {
3960 print '<!-- tab=objects -->'."\n";
3961 $head3 = array();
3962 $h = 0;
3963
3964 // Dir for module
3965 $dir = $dirread.'/'.$modulelowercase.'/class';
3966
3967 $head3[$h][0] = $_SERVER["PHP_SELF"].'?tab=objects&module='.$module.($forceddirread ? '@'.$dirread : '').'&tabobj=newobject';
3968 $head3[$h][1] = '<span class="valignmiddle text-plus-circle">'.$langs->trans("NewObjectInModulebuilder").'</span><span class="fa fa-plus-circle valignmiddle paddingleft"></span>';
3969 $head3[$h][2] = 'newobject';
3970 $h++;
3971
3972 // Scan for object class files
3973 $listofobject = dol_dir_list($dir, 'files', 0, '\.class\.php$');
3974
3975 $firstobjectname = '';
3976 foreach ($listofobject as $fileobj) {
3977 if (preg_match('/^api_/', $fileobj['name'])) {
3978 continue;
3979 }
3980 if (preg_match('/^actions_/', $fileobj['name'])) {
3981 continue;
3982 }
3983
3984 $tmpcontent = file_get_contents($fileobj['fullname']);
3985 if (preg_match('/class\s+([^\s]*)\s+extends\s+CommonObject/ims', $tmpcontent, $reg)) {
3986 //$objectname = preg_replace('/\.txt$/', '', $fileobj['name']);
3987 $objectname = $reg[1];
3988 if (empty($firstobjectname)) {
3989 $firstobjectname = $objectname;
3990 }
3991 $pictoname = 'generic';
3992 if (preg_match('/\$picto\s*=\s*["\']([^"\']+)["\']/', $tmpcontent, $reg)) {
3993 $pictoname = $reg[1];
3994 }
3995
3996 $head3[$h][0] = $_SERVER["PHP_SELF"].'?tab=objects&module='.$module.($forceddirread ? '@'.$dirread : '').'&tabobj='.$objectname;
3997 $head3[$h][1] = img_picto('', $pictoname, 'class="pictofixedwidth valignmiddle"').$objectname;
3998 $head3[$h][2] = $objectname;
3999 $h++;
4000 }
4001 }
4002
4003 if ($h > 1) {
4004 $head3[$h][0] = $_SERVER["PHP_SELF"].'?tab=objects&module='.$module.($forceddirread ? '@'.$dirread : '').'&tabobj=deleteobject';
4005 $head3[$h][1] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("DangerZone");
4006 $head3[$h][2] = 'deleteobject';
4007 $h++;
4008 }
4009
4010 // 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.
4011 if ($tabobj == 'newobjectifnoobj') {
4012 if ($firstobjectname) {
4013 $tabobj = $firstobjectname;
4014 } else {
4015 $tabobj = 'newobject';
4016 }
4017 }
4018
4019 print dol_get_fiche_head($head3, $tabobj, '', -1, '', 0, '', '', 0, 'forobjectsuffix'); // Level 3
4020
4021
4022 if ($tabobj == 'newobject') {
4023 // New object tab
4024 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
4025 print '<input type="hidden" name="token" value="'.newToken().'">';
4026 print '<input type="hidden" name="action" value="initobject">';
4027 print '<input type="hidden" name="tab" value="objects">';
4028 print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
4029
4030 print '<span class="opacitymedium">'.$langs->trans("EnterNameOfObjectDesc").'</span><br><br>';
4031
4032 print '<div class="tagtable">';
4033
4034 print '<div class="tagtr"><div class="tagtd">';
4035 print '<span class="opacitymedium">'.$langs->trans("ObjectKey").'</span> &nbsp; ';
4036 print '</div><div class="tagtd">';
4037 print '<input type="text" name="objectname" maxlength="64" value="'.dol_escape_htmltag(GETPOSTISSET('objectname') ? GETPOST('objectname', 'alpha') : $modulename).'" autofocus>';
4038 print $form->textwithpicto('', $langs->trans("Example").': MyObject, ACamelCaseName, ...');
4039 print '</div></div>';
4040
4041 print '<div class="tagtr"><div class="tagtd">';
4042 print '<span class="opacitymedium">'.$langs->trans("Picto").'</span> &nbsp; ';
4043 print '</div><div class="tagtd">';
4044 print '<input type="text" name="idpicto" value="fa-file" placeholder="'.dol_escape_htmltag($langs->trans("Picto")).'">';
4045 print $form->textwithpicto('', $langs->trans("Example").': fa-file, fa-globe, ... any font awesome code.<br>Advanced syntax is fa-fakey[_faprefix[_facolor[_fasize]]]');
4046 print '</div></div>';
4047
4048 print '<div class="tagtr"><div class="tagtd">';
4049 print '<span class="opacitymedium">'.$langs->trans("DefinePropertiesFromExistingTable").'</span> &nbsp; ';
4050 print '</div><div class="tagtd">';
4051 print '<input type="text" name="initfromtablename" value="'.GETPOST('initfromtablename').'" placeholder="'.$langs->trans("TableName").'">';
4052 print $form->textwithpicto('', $langs->trans("DefinePropertiesFromExistingTableDesc").'<br>'.$langs->trans("DefinePropertiesFromExistingTableDesc2"));
4053 print '</div></div>';
4054
4055 print '</div>';
4056
4057 print '<br>';
4058 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>';
4059 print '<input type="checkbox" name="includedocgeneration" id="includedocgeneration" value="includedocgeneration"> <label for="includedocgeneration">'.$form->textwithpicto($langs->trans("IncludeDocGeneration"), $langs->trans("IncludeDocGenerationHelp")).'</label><br>';
4060 print '<input type="checkbox" name="generatepermissions" id="generatepermissions" value="generatepermissions"> <label for="generatepermissions">'.$form->textwithpicto($langs->trans("GeneratePermissions"), $langs->trans("GeneratePermissionsHelp")).'</label><br>';
4061 print '<br>';
4062 print '<input type="submit" class="button small" name="create" value="'.dol_escape_htmltag($langs->trans("GenerateCode")).'"'.($dirins ? '' : ' disabled="disabled"').'>';
4063 print '<br>';
4064 print '<br>';
4065 /*
4066 print '<br>';
4067 print '<span class="opacitymedium">'.$langs->trans("or").'</span>';
4068 print '<br>';
4069 print '<br>';
4070 //print '<input type="checkbox" name="initfromtablecheck"> ';
4071 print $langs->trans("InitStructureFromExistingTable");
4072 print '<input type="text" name="initfromtablename" value="" placeholder="'.$langs->trans("TableName").'">';
4073 print '<input type="submit" class="button smallpaddingimp" name="createtablearray" value="'.dol_escape_htmltag($langs->trans("GenerateCode")).'"'.($dirins ? '' : ' disabled="disabled"').'>';
4074 print '<br>';
4075 */
4076
4077 print '</form>';
4078 } elseif ($tabobj == 'createproperty') {
4079 $attributesUnique = array(
4080 'proplabel' => $form->textwithpicto($langs->trans("Label"), $langs->trans("YouCanUseTranslationKey")),
4081 'propname' => $form->textwithpicto($langs->trans("Code"), $langs->trans("PropertyDesc"), 1, 'help', 'extracss', 0, 3, 'propertyhelp'),
4082 'proptype' => $form->textwithpicto($langs->trans("Type"), $langs->trans("TypeOfFieldsHelpIntro").'<br><br>'.$langs->trans("TypeOfFieldsHelp"), 1, 'help', 'extracss', 0, 3, 'typehelp'),
4083 'proparrayofkeyval' => $form->textwithpicto($langs->trans("ArrayOfKeyValues"), $langs->trans("ArrayOfKeyValuesDesc")),
4084 'propnotnull' => $form->textwithpicto($langs->trans("NotNull"), $langs->trans("NotNullDesc")),
4085 'propdefault' => $langs->trans("DefaultValue"),
4086 'propindex' => $langs->trans("DatabaseIndex"),
4087 'propforeignkey' => $form->textwithpicto($langs->trans("ForeignKey"), $langs->trans("ForeignKeyDesc"), 1, 'help', 'extracss', 0, 3, 'foreignkeyhelp'),
4088 'propposition' => $langs->trans("Position"),
4089 'propenabled' => $form->textwithpicto($langs->trans("Enabled"), $langs->trans("EnabledDesc"), 1, 'help', 'extracss', 0, 3, 'enabledhelp'),
4090 'propvisible' => $form->textwithpicto($langs->trans("Visibility"), $langs->trans("VisibleDesc").'<br><br>'.$langs->trans("ItCanBeAnExpression"), 1, 'help', 'extracss', 0, 3, 'visiblehelp'),
4091 'propnoteditable' => $langs->trans("NotEditable"),
4092 //'propalwayseditable' => $langs->trans("AlwaysEditable"),
4093 'propsearchall' => $form->textwithpicto($langs->trans("SearchAll"), $langs->trans("SearchAllDesc")),
4094 'propisameasure' => $form->textwithpicto($langs->trans("IsAMeasure"), $langs->trans("IsAMeasureDesc")),
4095 'propcss' => $langs->trans("CSSClass"),
4096 'propcssview' => $langs->trans("CSSViewClass"),
4097 'propcsslist' => $langs->trans("CSSListClass"),
4098 'prophelp' => $langs->trans("KeyForTooltip"),
4099 'propshowoncombobox' => $langs->trans("ShowOnCombobox"),
4100 //'propvalidate' => $form->textwithpicto($langs->trans("Validate"), $langs->trans("ValidateModBuilderDesc")),
4101 'propcomment' => $langs->trans("Comment"),
4102 );
4103 print '<form action="'.$_SERVER["PHP_SELF"].'?tab=objects&module='.urlencode($module).'&tabobj=createproperty&obj='.urlencode(GETPOST('obj')).'" method="POST">';
4104 print '<input type="hidden" name="token" value="'.newToken().'">';
4105 print '<input type="hidden" name="action" value="addproperty">';
4106 print '<input type="hidden" name="tab" value="objects">';
4107 print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
4108 print '<input type="hidden" name="obj" value="'.dol_escape_htmltag(GETPOST('obj')).'">';
4109
4110 print '<table class="border centpercent tableforfieldcreate">'."\n";
4111 $counter = 0;
4112 foreach ($attributesUnique as $key => $attribute) {
4113 if ($counter % 2 === 0) {
4114 print '<tr>';
4115 }
4116 if ($key == 'propname' || $key == 'proplabel') {
4117 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>';
4118 } elseif ($key == 'proptype') {
4119 print '<td class="titlefieldcreate fieldrequired">'.$attribute.'</td><td class="valuefieldcreate maxwidth50">';
4120 print '<input class="maxwidth200" id="'.$key.'" list="datalist'.$key.'" type="text" name="'.$key.'" value="'.dol_escape_htmltag(GETPOST($key, 'alpha')).'">';
4121 //print '<div id="suggestions"></div>';
4122 print '<datalist id="datalist'.$key.'">';
4123 print '<option>varchar(128)</option>';
4124 print '<option>email</option>';
4125 print '<option>phone</option>';
4126 print '<option>ip</option>';
4127 print '<option>url</option>';
4128 print '<option>password</option>';
4129 print '<option>text</option>';
4130 print '<option>html</option>';
4131 print '<option>date</option>';
4132 print '<option>datetime</option>';
4133 print '<option>integer</option>';
4134 print '<option>stars(5)</option>';
4135 print '<option>double(28,4)</option>';
4136 print '<option>real</option>';
4137 print '<option>integer:ClassName:RelativePath/To/ClassFile.class.php[:1[:FILTER]]</option>';
4138 // Combo with list of fields
4139 /*
4140 if (empty($formadmin)) {
4141 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
4142 $formadmin = new FormAdmin($db);
4143 }
4144 print $formadmin->selectTypeOfFields($key, GETPOST($key, 'alpha'));
4145 */
4146 print '</datalist>';
4147 print '</td>';
4148 //} elseif ($key == 'propvalidate') {
4149 // 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>';
4150 } elseif ($key == 'propvisible') {
4151 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>';
4152 } elseif ($key == 'propenabled') {
4153 //$default = "isModEnabled('".strtolower($module)."')";
4154 $default = 1;
4155 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>';
4156 } elseif ($key == 'proparrayofkeyval') {
4157 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>';
4158 } else {
4159 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>';
4160 }
4161 $counter++;
4162 if ($counter % 2 === 0) {
4163 print '</tr>';
4164 }
4165 }
4166 if ($counter % 2 !== 0) {
4167 while ($counter % 2 !== 0) {
4168 print '<td></td>';
4169 $counter++;
4170 }
4171 print '</tr>';
4172 }
4173 print '</table><br>'."\n";
4174 print '<div class="center">';
4175 print '<input type="submit" class="button button-save" name="add" value="' . dol_escape_htmltag($langs->trans('Create')) . '">';
4176 print '<input type="button" class="button button-cancel" name="cancel" value="' . dol_escape_htmltag($langs->trans('Cancel')) . '" onclick="goBack()">';
4177 print '</div>';
4178 print '</form>';
4179 // javascript
4180 print '<script>
4181 function goBack() {
4182 var url = "'.$_SERVER["PHP_SELF"].'?tab=objects&module='.urlencode($module).'";
4183 window.location.href = url;
4184 }
4185 $(document).ready(function() {
4186 $("#proplabel").on("keyup", function() {
4187 console.log("key up on label");
4188 s = cleanString($("#proplabel").val());
4189 $("#propname").val(s);
4190 });
4191
4192 function cleanString( stringtoclean )
4193 {
4194 // allow "a-z", "A-Z", "0-9" and "_"
4195 stringtoclean = stringtoclean.replace(/[^a-z0-9_]+/ig, "");
4196 stringtoclean = stringtoclean.toLowerCase();
4197 if (!isNaN(stringtoclean)) {
4198 return ""
4199 }
4200 while ( stringtoclean.length > 1 && !isNaN( stringtoclean.charAt(0)) ){
4201 stringtoclean = stringtoclean.substr(1)
4202 }
4203 if (stringtoclean.length > 28) {
4204 stringtoclean = stringtoclean.substring(0, 27);
4205 }
4206 return stringtoclean;
4207 }
4208
4209 });';
4210 print '</script>';
4211 } elseif ($tabobj == 'deleteobject') {
4212 // Delete object tab
4213 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
4214 print '<input type="hidden" name="token" value="'.newToken().'">';
4215 print '<input type="hidden" name="action" value="confirm_deleteobject">';
4216 print '<input type="hidden" name="tab" value="objects">';
4217 print '<input type="hidden" name="tabobj" value="deleteobject">';
4218 print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
4219
4220 print $langs->trans("EnterNameOfObjectToDeleteDesc").'<br><br>';
4221
4222 print '<input type="text" name="objectname" value="" placeholder="'.dol_escape_htmltag($langs->trans("ObjectKey")).'" autofocus>';
4223 print '<input type="submit" class="button smallpaddingimp" name="delete" value="'.dol_escape_htmltag($langs->trans("Delete")).'"'.($dirins ? '' : ' disabled="disabled"').'>';
4224 print '</form>';
4225 } else {
4226 // tabobj = module
4227 if ($action == 'deleteproperty') {
4228 $formconfirm = $form->formconfirm(
4229 $_SERVER["PHP_SELF"].'?propertykey='.urlencode(GETPOST('propertykey', 'alpha')).'&objectname='.urlencode($objectname).'&tab='.urlencode($tab).'&module='.urlencode($module).'&tabobj='.urlencode($tabobj),
4230 $langs->trans('Delete'),
4231 $langs->trans('ConfirmDeleteProperty', GETPOST('propertykey', 'alpha')),
4232 'confirm_deleteproperty',
4233 '',
4234 0,
4235 1
4236 );
4237
4238 // Print form confirm
4239 print $formconfirm;
4240 }
4241 if ($action != 'editfile' || empty($file)) {
4242 try {
4243 //$pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
4244
4245 $pathtoclass = strtolower($module).'/class/'.strtolower($tabobj).'.class.php';
4246 $pathtoapi = strtolower($module).'/class/api_'.strtolower($module).'.class.php';
4247 $pathtoagenda = strtolower($module).'/'.strtolower($tabobj).'_agenda.php';
4248 $pathtocard = strtolower($module).'/'.strtolower($tabobj).'_card.php';
4249 $pathtodocument = strtolower($module).'/'.strtolower($tabobj).'_document.php';
4250 $pathtolist = strtolower($module).'/'.strtolower($tabobj).'_list.php';
4251 $pathtonote = strtolower($module).'/'.strtolower($tabobj).'_note.php';
4252 $pathtocontact = strtolower($module).'/'.strtolower($tabobj).'_contact.php';
4253 $pathtophpunit = strtolower($module).'/test/phpunit/'.strtolower($tabobj).'Test.php';
4254
4255 // Try to load object class file
4256 clearstatcache(true);
4257 if (function_exists('opcache_invalidate')) {
4258 opcache_invalidate($dirread.'/'.$pathtoclass, true); // remove the include cache hell !
4259 }
4260
4261 if (empty($forceddirread) && empty($dirread)) {
4262 $result = dol_include_once($pathtoclass);
4263 $stringofinclude = "dol_include_once(".$pathtoclass.")";
4264 } else {
4265 $result = include_once $dirread.'/'.$pathtoclass;
4266 $stringofinclude = "@include_once ".$dirread.'/'.$pathtoclass;
4267 }
4268
4269 if (class_exists($tabobj)) {
4270 try {
4271 $tmpobject = @new $tabobj($db);
4272 } catch (Exception $e) {
4273 dol_syslog('Failed to load Constructor of class: '.$e->getMessage(), LOG_WARNING);
4274 }
4275 } else {
4276 print '<span class="warning">'.$langs->trans('Failed to find the class '.$tabobj.' despite the '.$stringofinclude).'</span><br><br>';
4277 }
4278
4279 // Define path for sql file
4280 $pathtosql = strtolower($module).'/sql/llx_'.strtolower($module).'_'.strtolower($tabobj).'-'.strtolower($module).'.sql';
4281 $result = dol_buildpath($pathtosql);
4282 if (! dol_is_file($result)) {
4283 $pathtosql = strtolower($module).'/sql/llx_'.strtolower($module).'_'.strtolower($tabobj).'.sql';
4284 $result = dol_buildpath($pathtosql);
4285 if (! dol_is_file($result)) {
4286 $pathtosql = 'install/mysql/tables/llx_'.strtolower($module).'_'.strtolower($tabobj).'-'.strtolower($module).'.sql';
4287 $result = dol_buildpath($pathtosql);
4288 if (! dol_is_file($result)) {
4289 $pathtosql = 'install/mysql/tables/llx_'.strtolower($module).'-'.strtolower($module).'.sql';
4290 $result = dol_buildpath($pathtosql);
4291 if (! dol_is_file($result)) {
4292 $pathtosql = 'install/mysql/tables/llx_'.strtolower($module).'.sql';
4293 $pathtosqlextra = 'install/mysql/tables/llx_'.strtolower($module).'_extrafields.sql';
4294 $result = dol_buildpath($pathtosql);
4295 } else {
4296 $pathtosqlextra = 'install/mysql/tables/llx_'.strtolower($module).'_extrafields-'.strtolower($module).'.sql';
4297 }
4298 } else {
4299 $pathtosqlextra = 'install/mysql/tables/llx_'.strtolower($module).'_'.strtolower($tabobj).'_extrafields-'.strtolower($module).'.sql';
4300 }
4301 } else {
4302 $pathtosqlextra = strtolower($module).'/sql/llx_'.strtolower($module).'_'.strtolower($tabobj).'_extrafields.sql';
4303 }
4304 } else {
4305 $pathtosqlextra = strtolower($module).'/sql/llx_'.strtolower($module).'_'.strtolower($tabobj).'_extrafields-'.strtolower($module).'.sql';
4306 }
4307 $pathtosqlroot = preg_replace('/\/llx_.*$/', '', $pathtosql);
4308
4309 $pathtosqlkey = preg_replace('/\.sql$/', '.key.sql', $pathtosql);
4310 $pathtosqlextrakey = preg_replace('/\.sql$/', '.key.sql', $pathtosqlextra);
4311
4312 $pathtolib = strtolower($module).'/lib/'.strtolower($module).'.lib.php';
4313 $pathtoobjlib = strtolower($module).'/lib/'.strtolower($module).'_'.strtolower($tabobj).'.lib.php';
4314
4315 $tmpobject = $tmpobject ?? null; // @phan-suppress-current-line PhanPluginDuplicateExpressionAssignmentOperation
4316 if (is_object($tmpobject) && property_exists($tmpobject, 'picto')) {
4317 $pathtopicto = $tmpobject->picto;
4318 $realpathtopicto = '';
4319 } else {
4320 $pathtopicto = strtolower($module).'/img/object_'.strtolower($tabobj).'.png';
4321 $realpathtopicto = $dirread.'/'.$pathtopicto;
4322 }
4323
4324 //var_dump($pathtoclass);
4325 //var_dump($dirread);
4326 $realpathtoclass = $dirread.'/'.$pathtoclass;
4327 $realpathtoapi = $dirread.'/'.$pathtoapi;
4328 $realpathtoagenda = $dirread.'/'.$pathtoagenda;
4329 $realpathtocard = $dirread.'/'.$pathtocard;
4330 $realpathtodocument = $dirread.'/'.$pathtodocument;
4331 $realpathtolist = $dirread.'/'.$pathtolist;
4332 $realpathtonote = $dirread.'/'.$pathtonote;
4333 $realpathtocontact = $dirread.'/'.$pathtocontact;
4334 $realpathtophpunit = $dirread.'/'.$pathtophpunit;
4335 $realpathtosql = $dirread.'/'.$pathtosql;
4336 $realpathtosqlextra = $dirread.'/'.$pathtosqlextra;
4337 $realpathtosqlkey = $dirread.'/'.$pathtosqlkey;
4338 $realpathtosqlextrakey = $dirread.'/'.$pathtosqlextrakey;
4339 $realpathtolib = $dirread.'/'.$pathtolib;
4340 $realpathtoobjlib = $dirread.'/'.$pathtoobjlib;
4341
4342 if (empty($realpathtoapi)) { // For compatibility with some old modules
4343 $pathtoapi = strtolower($module).'/class/api_'.strtolower($module).'s.class.php';
4344 $realpathtoapi = $dirread.'/'.$pathtoapi;
4345 }
4346
4347 $urloflist = dol_buildpath('/'.$pathtolist, 1);
4348 $urlofcard = dol_buildpath('/'.$pathtocard, 1);
4349
4350 $objs = array();
4351
4352 print '<!-- section for object -->';
4353 print '<div class="fichehalfleft smallxxx">';
4354 // Main DAO class file
4355 print '<span class="fa fa-file"></span> '.$langs->trans("ClassFile").' : <strong>'.(dol_is_file($realpathtoclass) ? '' : '<strike>').preg_replace('/^'.strtolower($module).'\//', '', $pathtoclass).(dol_is_file($realpathtoclass) ? '' : '</strike>').'</strong>';
4356 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>';
4357 print '<br>';
4358 // Image
4359 if ($realpathtopicto && dol_is_file($realpathtopicto)) {
4360 print '<span class="fa fa-file-image-o"></span> '.$langs->trans("Image").' : <strong>'.(dol_is_file($realpathtopicto) ? '' : '<strike>').preg_replace('/^'.strtolower($module).'\//', '', $pathtopicto).(dol_is_file($realpathtopicto) ? '' : '</strike>').'</strong>';
4361 //print ' <a href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&tabobj='.$tabobj.'&module='.$module.($forceddirread?'@'.$dirread:'').'&action=editfile&token='.newToken().'&format=php&file='.urlencode($pathtopicto).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
4362 print '<br>';
4363 } elseif (!empty($tmpobject)) {
4364 print '<span class="fa fa-file-image-o"></span> '.$langs->trans("Image").' : '.img_picto('', $tmpobject->picto, 'class="pictofixedwidth valignmiddle"').$tmpobject->picto;
4365 print '<br>';
4366 }
4367
4368 // API file
4369 print '<br>';
4370 print '<span class="fa fa-file"></span> '.$langs->trans("ApiClassFile").' : <strong class="wordbreak">'.(dol_is_file($realpathtoapi) ? '' : '<strike><span class="opacitymedium">').preg_replace('/^'.strtolower($module).'\//', '', $pathtoapi).(dol_is_file($realpathtoapi) ? '' : '</span></strike>').'</strong>';
4371 if (dol_is_file($realpathtoapi)) {
4372 $file = file_get_contents($realpathtoapi);
4373 if (preg_match('/var '.$tabobj.'\s+([^\s]*)\s/ims', $file, $objs)) {
4374 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>';
4375 print ' ';
4376 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>';
4377 print $form->textwithpicto('', $langs->trans("InfoForApiFile"), 1, 'warning');
4378 print ' &nbsp; ';
4379 // Comparing to null (phan considers $modulelowercase can be null here)
4380 if ($modulelowercase !== null && !isModEnabled($modulelowercase)) { // If module is not activated
4381 print '<a href="#" class="classfortooltip" target="apiexplorer" title="'.$langs->trans("ModuleMustBeEnabled", $module).'"><strike>'.$langs->trans("ApiExplorer").'</strike></a>';
4382 } else {
4383 print '<a href="'.DOL_URL_ROOT.'/api/index.php/explorer/" target="apiexplorer">'.$langs->trans("ApiExplorer").'</a>';
4384 }
4385 } else {
4386 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>';
4387 }
4388 } else {
4389 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>';
4390 }
4391 // PHPUnit
4392 print '<br>';
4393 print '<span class="fa fa-file"></span> '.$langs->trans("TestClassFile").' : <strong class="wordbreak">'.(dol_is_file($realpathtophpunit) ? '' : '<strike><span class="opacitymedium">').preg_replace('/^'.strtolower($module).'\//', '', $pathtophpunit).(dol_is_file($realpathtophpunit) ? '' : '</span></strike>').'</strong>';
4394 if (dol_is_file($realpathtophpunit)) {
4395 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>';
4396 print ' ';
4397 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>';
4398 } else {
4399 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>';
4400 }
4401 print '<br>';
4402
4403 print '<br>';
4404
4405 print '<span class="fa fa-file"></span> '.$langs->trans("PageForLib").' : <strong class="wordbreak">'.(dol_is_file($realpathtolib) ? '' : '<strike>').preg_replace('/^'.strtolower($module).'\//', '', $pathtolib).(dol_is_file($realpathtolib) ? '' : '</strike>').'</strong>';
4406 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>';
4407 print '<br>';
4408 print '<span class="fa fa-file"></span> '.$langs->trans("PageForObjLib").' : <strong class="wordbreak">'.(dol_is_file($realpathtoobjlib) ? '' : '<strike>').preg_replace('/^'.strtolower($module).'\//', '', $pathtoobjlib).(dol_is_file($realpathtoobjlib) ? '' : '</strike>').'</strong>';
4409 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>';
4410 print '<br>';
4411
4412 print '<br>';
4413 print '<span class="fa fa-file"></span> '.$langs->trans("SqlFile").' : <strong class="wordbreak">'.(dol_is_file($realpathtosql) ? '' : '<strike>').preg_replace('/^'.strtolower($module).'\//', '', $pathtosql).(dol_is_file($realpathtosql) ? '' : '</strike>').'</strong>';
4414 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>';
4415 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>';
4416 //print ' &nbsp; <a href="'.$_SERVER["PHP_SELF"].'">'.$langs->trans("RunSql").'</a>';
4417 print '<br>';
4418 print '<span class="fa fa-file"></span> '.$langs->trans("SqlFileKey").' : <strong class="wordbreak">'.(dol_is_file($realpathtosqlkey) ? '' : '<strike>').preg_replace('/^'.strtolower($module).'\//', '', $pathtosqlkey).(dol_is_file($realpathtosqlkey) ? '' : '</strike>').'</strong>';
4419 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>';
4420 //print ' &nbsp; <a href="'.$_SERVER["PHP_SELF"].'">'.$langs->trans("RunSql").'</a>';
4421 print '<br>';
4422 print '<span class="fa fa-file"></span> '.$langs->trans("SqlFileExtraFields").' : <strong class="wordbreak">'.(dol_is_file($realpathtosqlextra) ? '' : '<strike><span class="opacitymedium">').preg_replace('/^'.strtolower($module).'\//', '', $pathtosqlextra).(dol_is_file($realpathtosqlextra) && dol_is_file($realpathtosqlextrakey) ? '' : '</span></strike>').'</strong>';
4423 if (dol_is_file($realpathtosqlextra) && dol_is_file($realpathtosqlextrakey)) {
4424 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>';
4425 print ' ';
4426 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>';
4427 print ' &nbsp; ';
4428 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>';
4429 } else {
4430 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>';
4431 }
4432 //print ' &nbsp; <a href="'.$_SERVER["PHP_SELF"].'">'.$langs->trans("RunSql").'</a>';
4433 print '<br>';
4434 print '<span class="fa fa-file"></span> '.$langs->trans("SqlFileKeyExtraFields").' : <strong class="wordbreak">'.(dol_is_file($realpathtosqlextrakey) ? '' : '<strike><span class="opacitymedium">').preg_replace('/^'.strtolower($module).'\//', '', $pathtosqlextrakey).(dol_is_file($realpathtosqlextra) && dol_is_file($realpathtosqlextrakey) ? '' : '</span></strike>').'</strong>';
4435 if (dol_is_file($realpathtosqlextra) && dol_is_file($realpathtosqlextrakey)) {
4436 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>';
4437 print ' ';
4438 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>';
4439 } else {
4440 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>';
4441 }
4442 print '<br>';
4443 print '</div>';
4444
4445 print '<div class="fichehalfleft smallxxxx">';
4446 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('/^'.strtolower($module).'\//', '', $pathtolist).(dol_is_file($realpathtolist) ? '' : '</span></strike>').'</a></strong>';
4447 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>';
4448 print '<br>';
4449 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('/^'.strtolower($module).'\//', '', $pathtocard).(dol_is_file($realpathtocard) ? '' : '</strike>').'?action=create</a></strong>';
4450 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>';
4451 print '<br>';
4452 // Page contact
4453 print '<span class="fa fa-file"></span> '.$langs->trans("PageForContactTab").' : <strong class="wordbreak">'.(dol_is_file($realpathtocontact) ? '' : '<strike><span class="opacitymedium">').preg_replace('/^'.strtolower($module).'\//', '', $pathtocontact).(dol_is_file($realpathtocontact) ? '' : '</span></strike>').'</strong>';
4454 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>';
4455 if (dol_is_file($realpathtocontact)) {
4456 print ' ';
4457 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>';
4458 } else {
4459 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>';
4460 }
4461 print '<br>';
4462 // Page document
4463 print '<span class="fa fa-file"></span> '.$langs->trans("PageForDocumentTab").' : <strong class="wordbreak">'.(dol_is_file($realpathtodocument) ? '' : '<strike><span class="opacitymedium">').preg_replace('/^'.strtolower($module).'\//', '', $pathtodocument).(dol_is_file($realpathtodocument) ? '' : '</span></strike>').'</strong>';
4464 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>';
4465 if (dol_is_file($realpathtodocument)) {
4466 print ' ';
4467 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>';
4468 } else {
4469 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>';
4470 }
4471 print '<br>';
4472 // Page notes
4473 print '<span class="fa fa-file"></span> '.$langs->trans("PageForNoteTab").' : <strong class="wordbreak">'.(dol_is_file($realpathtonote) ? '' : '<strike><span class="opacitymedium">').preg_replace('/^'.strtolower($module).'\//', '', $pathtonote).(dol_is_file($realpathtonote) ? '' : '</span></strike>').'</strong>';
4474 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>';
4475 if (dol_is_file($realpathtonote)) {
4476 print ' ';
4477 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>';
4478 } else {
4479 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>';
4480 }
4481 print '<br>';
4482 // Page agenda
4483 print '<span class="fa fa-file"></span> '.$langs->trans("PageForAgendaTab").' : <strong class="wordbreak">'.(dol_is_file($realpathtoagenda) ? '' : '<strike><span class="opacitymedium">').preg_replace('/^'.strtolower($module).'\//', '', $pathtoagenda).(dol_is_file($realpathtoagenda) ? '' : '</span></strike>').'</strong>';
4484 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>';
4485 if (dol_is_file($realpathtoagenda)) {
4486 print ' ';
4487 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>';
4488 } else {
4489 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>';
4490 }
4491 print '<br>';
4492 print '<br>';
4493
4494 print '</div>';
4495
4496 print '<br><br><br>';
4497
4498 if (!empty($tmpobject)) {
4499 $reflector = new ReflectionClass($tabobj);
4500 $reflectorproperties = $reflector->getProperties(); // Can also use get_object_vars
4501 $reflectorpropdefault = $reflector->getDefaultProperties(); // Can also use get_object_vars
4502 //$propstat = $reflector->getStaticProperties();
4503 //var_dump($reflectorpropdefault);
4504
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="addproperty">';
4508 print '<input type="hidden" name="tab" value="objects">';
4509 print '<input type="hidden" name="page_y" value="">';
4510 print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module.($forceddirread ? '@'.$dirread : '')).'">';
4511 print '<input type="hidden" name="tabobj" value="'.dol_escape_htmltag($tabobj).'">';
4512
4513 print '<input class="button smallpaddingimp" type="submit" name="regenerateclasssql" value="'.$langs->trans("RegenerateClassAndSql").'">';
4514 print '<br><br class="clearboth">';
4515 print '<br class="clearboth">';
4516
4517 $mod = strtolower($module);
4518 $obj = strtolower($tabobj);
4519 $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));
4520 $nbOfProperties = count($reflectorpropdefault['fields']);
4521
4522 print_barre_liste($langs->trans("ObjectProperties"), 0, $_SERVER["PHP_SELF"], '', '', '', '', 0, $nbOfProperties, '', 0, $newproperty, 'margintoponly', 0, 0, 0, 1);
4523
4524 //var_dump($reflectorpropdefault);exit;
4525 print '<!-- Table with properties of object -->'."\n";
4526 print '<div class="div-table-responsive">';
4527 print '<table class="noborder small">';
4528 print '<tr class="liste_titre">';
4529 print '<th class="tdsticky tdstickygray">';
4530 $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>';
4531 print $form->textwithpicto($langs->trans("Code"), $htmltext, 1, 'help', 'extracss', 0, 3, 'propertyhelp');
4532 print '</th>';
4533 print '<th>';
4534 print $form->textwithpicto($langs->trans("Label"), $langs->trans("YouCanUseTranslationKey"));
4535 print '</th>';
4536 print '<th>'.$form->textwithpicto($langs->trans("Type"), $langs->trans("TypeOfFieldsHelpIntro").'<br><br>'.$langs->trans("TypeOfFieldsHelp"), 1, 'help', 'extracss', 0, 3, 'typehelp').'</th>';
4537 print '<th>'.$form->textwithpicto($langs->trans("ArrayOfKeyValues"), $langs->trans("ArrayOfKeyValuesDesc")).'</th>';
4538 print '<th class="center">'.$form->textwithpicto($langs->trans("NotNull"), $langs->trans("NotNullDesc")).'</th>';
4539 print '<th class="center">'.$langs->trans("DefaultValue").'</th>';
4540 print '<th class="center">'.$langs->trans("DatabaseIndex").'</th>';
4541 print '<th class="center">'.$form->textwithpicto($langs->trans("ForeignKey"), $langs->trans("ForeignKeyDesc"), 1, 'help', 'extracss', 0, 3, 'foreignkeyhelp').'</th>';
4542 print '<th class="right">'.$langs->trans("Position").'</th>';
4543 print '<th class="center">'.$form->textwithpicto($langs->trans("Enabled"), $langs->trans("EnabledDesc"), 1, 'help', 'extracss', 0, 3, 'enabledhelp').'</th>';
4544 print '<th class="center">'.$form->textwithpicto($langs->trans("Visibility"), $langs->trans("VisibleDesc").'<br><br>'.$langs->trans("ItCanBeAnExpression"), 1, 'help', 'extracss', 0, 3, 'visiblehelp').'</th>';
4545 print '<th class="center">'.$langs->trans("NotEditable").'</th>';
4546 //print '<th class="center">'.$langs->trans("AlwaysEditable").'</th>';
4547 print '<th class="center">'.$form->textwithpicto($langs->trans("SearchAll"), $langs->trans("SearchAllDesc")).'</th>';
4548 print '<th class="center">'.$form->textwithpicto($langs->trans("IsAMeasure"), $langs->trans("IsAMeasureDesc")).'</th>';
4549 print '<th class="center">'.$langs->trans("CSSClass").'</th>';
4550 print '<th class="center">'.$langs->trans("CSSViewClass").'</th>';
4551 print '<th class="center">'.$langs->trans("CSSListClass").'</th>';
4552 print '<th>'.$langs->trans("KeyForTooltip").'</th>';
4553 print '<th class="center">'.$langs->trans("ShowOnCombobox").'</th>';
4554 //print '<th class="center">'.$langs->trans("Disabled").'</th>';
4555 print '<th>'.$form->textwithpicto($langs->trans("Validate"), $langs->trans("ValidateModBuilderDesc")).'</th>';
4556 print '<th>'.$langs->trans("Comment").'</th>';
4557 print '<th class="tdstickyright tdstickyghostwhite"></th>';
4558 print '</tr>';
4559
4560 // We must use $reflectorpropdefault['fields'] to get list of fields because $tmpobject->fields may have been
4561 // modified during the constructor and we want value into head of class before constructor is called.
4562 //$properties = dol_sort_array($tmpobject->fields, 'position');
4563 $properties = dol_sort_array($reflectorpropdefault['fields'], 'position');
4564 if (!empty($properties)) {
4565 // List of existing properties
4566 foreach ($properties as $propkey => $propval) {
4567 /* If from Reflection
4568 if ($propval->class == $tabobj)
4569 {
4570 $propname=$propval->getName();
4571 $comment=$propval->getDocComment();
4572 $type=gettype($tmpobject->$propname);
4573 $default=$propdefault[$propname];
4574 // Discard generic properties
4575 if (in_array($propname, array('element', 'childtables', 'table_element', 'table_element_line', 'class_element_line', 'ismultientitymanaged'))) continue;
4576
4577 // Keep or not lines
4578 if (in_array($propname, array('fk_element', 'lines'))) continue;
4579 }*/
4580
4581 $propname = $propkey;
4582 $proplabel = $propval['label'];
4583 $proptype = $propval['type'];
4584 $proparrayofkeyval = !empty($propval['arrayofkeyval']) ? $propval['arrayofkeyval'] : '';
4585 $propnotnull = !empty($propval['notnull']) ? $propval['notnull'] : '0';
4586 $propdefault = !empty($propval['default']) ? $propval['default'] : '';
4587 $propindex = !empty($propval['index']) ? $propval['index'] : '';
4588 $propforeignkey = !empty($propval['foreignkey']) ? $propval['foreignkey'] : '';
4589 $propposition = $propval['position'];
4590 $propenabled = $propval['enabled'];
4591 $propvisible = $propval['visible'];
4592 $propnoteditable = !empty($propval['noteditable']) ? $propval['noteditable'] : 0;
4593 //$propalwayseditable = !empty($propval['alwayseditable'])?$propval['alwayseditable']:0;
4594 $propsearchall = !empty($propval['searchall']) ? $propval['searchall'] : 0;
4595 $propisameasure = !empty($propval['isameasure']) ? $propval['isameasure'] : 0;
4596 $propcss = !empty($propval['css']) ? $propval['css'] : '';
4597 $propcssview = !empty($propval['cssview']) ? $propval['cssview'] : '';
4598 $propcsslist = !empty($propval['csslist']) ? $propval['csslist'] : '';
4599 $prophelp = !empty($propval['help']) ? $propval['help'] : '';
4600 $propshowoncombobox = !empty($propval['showoncombobox']) ? $propval['showoncombobox'] : 0;
4601 //$propdisabled=$propval['disabled'];
4602 $propvalidate = !empty($propval['validate']) ? $propval['validate'] : 0;
4603 $propcomment = !empty($propval['comment']) ? $propval['comment'] : '';
4604
4605 print '<!-- line for object property -->'."\n";
4606 print '<tr class="oddeven">';
4607
4608 print '<td class="tdsticky tdstickygray">';
4609 print dol_escape_htmltag($propname);
4610 print '</td>';
4611 if ($action == 'editproperty' && $propname == $propertykey) {
4612 print '<td>';
4613 print '<input type="hidden" name="propname" value="'.dol_escape_htmltag($propname).'">';
4614 print '<input name="proplabel" class="maxwidth125" value="'.dol_escape_htmltag($proplabel).'">';
4615 print '</td>';
4616 print '<td class="tdoverflowmax150">';
4617 print '<input name="proptype" class="maxwidth125" value="'.dol_escape_htmltag($proptype).'"></input>';
4618 print '</td>';
4619 print '<td class="tdoverflowmax200">';
4620 print '<textarea name="proparrayofkeyval">';
4621 if (isset($proparrayofkeyval)) {
4622 if (is_array($proparrayofkeyval) || $proparrayofkeyval != '') {
4623 print dol_escape_htmltag(json_encode($proparrayofkeyval, JSON_UNESCAPED_UNICODE));
4624 }
4625 }
4626 print '</textarea>';
4627 print '</td>';
4628 print '<td>';
4629 print '<input class="center width50" name="propnotnull" value="'.dol_escape_htmltag($propnotnull).'">';
4630 print '</td>';
4631 print '<td>';
4632 print '<input class="maxwidth50" name="propdefault" value="'.dol_escape_htmltag($propdefault).'">';
4633 print '</td>';
4634 print '<td class="center">';
4635 print '<input class="center maxwidth50" name="propindex" value="'.dol_escape_htmltag($propindex).'">';
4636 print '</td>';
4637 print '<td>';
4638 print '<input class="center maxwidth100" name="propforeignkey" value="'.dol_escape_htmltag($propforeignkey).'">';
4639 print '</td>';
4640 print '<td>';
4641 print '<input class="right width50" name="propposition" value="'.dol_escape_htmltag($propposition).'">';
4642 print '</td>';
4643 print '<td>';
4644 print '<input class="center width75" name="propenabled" value="'.dol_escape_htmltag($propenabled).'">';
4645 print '</td>';
4646 print '<td>';
4647 print '<input class="center width75" name="propvisible" value="'.dol_escape_htmltag($propvisible).'">';
4648 print '</td>';
4649 print '<td>';
4650 print '<input class="center width50" name="propnoteditable" size="2" value="'.dol_escape_htmltag($propnoteditable).'">';
4651 print '</td>';
4652 /*print '<td>';
4653 print '<input class="center" name="propalwayseditable" size="2" value="'.dol_escape_htmltag($propalwayseditable).'">';
4654 print '</td>';*/
4655 print '<td>';
4656 print '<input class="center width50" name="propsearchall" value="'.dol_escape_htmltag($propsearchall).'">';
4657 print '</td>';
4658 print '<td>';
4659 print '<input class="center width50" name="propisameasure" value="'.dol_escape_htmltag($propisameasure).'">';
4660 print '</td>';
4661 print '<td>';
4662 print '<input class="center maxwidth50" name="propcss" value="'.dol_escape_htmltag($propcss).'">';
4663 print '</td>';
4664 print '<td>';
4665 print '<input class="center maxwidth50" name="propcssview" value="'.dol_escape_htmltag($propcssview).'">';
4666 print '</td>';
4667 print '<td>';
4668 print '<input class="center maxwidth50" name="propcsslist" value="'.dol_escape_htmltag($propcsslist).'">';
4669 print '</td>';
4670 print '<td>';
4671 print '<input class="maxwidth100" name="prophelp" value="'.dol_escape_htmltag($prophelp).'">';
4672 print '</td>';
4673 print '<td>';
4674 print '<input class="center maxwidth50" name="propshowoncombobox" value="'.dol_escape_htmltag($propshowoncombobox).'">';
4675 print '</td>';
4676 print '<td>';
4677 print '<input type="number" step="1" min="0" max="1" class="text maxwidth100" name="propvalidate" value="'.dol_escape_htmltag($propvalidate).'">';
4678 print '</td>';
4679 print '<td>';
4680 print '<input class="maxwidth100" name="propcomment" value="'.dol_escape_htmltag($propcomment).'">';
4681 print '</td>';
4682 print '<td class="center minwidth75 tdstickyright tdstickyghostwhite">';
4683 print '<input class="reposition button smallpaddingimp" type="submit" name="edit" value="'.$langs->trans("Save").'">';
4684 print '<input class="reposition button button-cancel smallpaddingimp" type="submit" name="cancel" value="'.$langs->trans("Cancel").'">';
4685 print '</td>';
4686 } else {
4687 print '<td class="tdoverflowmax200" title="'.dol_escape_htmltag($proplabel).'">';
4688 print dol_escape_htmltag($proplabel);
4689 print '</td>';
4690 print '<td class="tdoverflowmax200">';
4691 $pictoType = '';
4692 $matches = array();
4693 if (preg_match('/^varchar/', $proptype, $matches)) {
4694 $pictoType = 'varchar';
4695 } elseif (preg_match('/^integer:/', $proptype, $matches)) {
4696 $pictoType = 'link';
4697 } elseif (strpos($proptype, 'integer') === 0) {
4698 $pictoType = substr($proptype, 0, 3);
4699 } elseif (strpos($proptype, 'timestamp') === 0) {
4700 $pictoType = 'datetime';
4701 } elseif (strpos($proptype, 'real') === 0) {
4702 $pictoType = 'double';
4703 } elseif (strpos($proptype, 'stars') === 0) {
4704 $pictoType = 'stars';
4705 }
4706 print(!empty($pictoType) ? getPictoForType($pictoType) : getPictoForType($proptype)).'<span title="'.dol_escape_htmltag($proptype).'">'.dol_escape_htmltag($proptype).'</span>';
4707 print '</td>';
4708 print '<td class="tdoverflowmax200">';
4709 if ($proparrayofkeyval) {
4710 print '<span title="'.dol_escape_htmltag(json_encode($proparrayofkeyval, JSON_UNESCAPED_UNICODE)).'">';
4711 print dol_escape_htmltag(json_encode($proparrayofkeyval, JSON_UNESCAPED_UNICODE));
4712 print '</span>';
4713 }
4714 print '</td>';
4715 print '<td class="center">';
4716 print dol_escape_htmltag($propnotnull);
4717 print '</td>';
4718 print '<td>';
4719 print dol_escape_htmltag($propdefault);
4720 print '</td>';
4721 print '<td class="center">';
4722 print $propindex ? '1' : '';
4723 print '</td>';
4724 print '<td class="center">';
4725 print $propforeignkey ? dol_escape_htmltag($propforeignkey) : '';
4726 print '</td>';
4727 print '<td class="right">';
4728 print dol_escape_htmltag($propposition);
4729 print '</td>';
4730 print '<td class="center tdoverflowmax100" title="'.($propnoteditable ? dol_escape_htmltag($propnoteditable) : '').'">';
4731 print $propenabled ? dol_escape_htmltag($propenabled) : '';
4732 print '</td>';
4733 // Visibility
4734 print '<td class="center tdoverflowmax100" title="'.($propvisible ? dol_escape_htmltag($propvisible) : '0').'">';
4735 print $propvisible ? dol_escape_htmltag($propvisible) : '0';
4736 print '</td>';
4737 // Readonly
4738 print '<td class="center tdoverflowmax100" title="'.($propnoteditable ? dol_escape_htmltag($propnoteditable) : '').'">';
4739 print $propnoteditable ? dol_escape_htmltag($propnoteditable) : '';
4740 print '</td>';
4741 /*print '<td class="center">';
4742 print $propalwayseditable ? dol_escape_htmltag($propalwayseditable) : '';
4743 print '</td>';*/
4744 print '<td class="center">';
4745 print $propsearchall ? '1' : '';
4746 print '</td>';
4747 print '<td class="center">';
4748 print $propisameasure ? dol_escape_htmltag($propisameasure) : '';
4749 print '</td>';
4750 print '<td class="center tdoverflowmax100" title="'.($propcss ? dol_escape_htmltag($propcss) : '').'">';
4751 print $propcss ? dol_escape_htmltag($propcss) : '';
4752 print '</td>';
4753 print '<td class="center tdoverflowmax100" title="'.($propcssview ? dol_escape_htmltag($propcssview) : '').'">';
4754 print $propcssview ? dol_escape_htmltag($propcssview) : '';
4755 print '</td>';
4756 print '<td class="center tdoverflowmax100" title="'.($propcsslist ? dol_escape_htmltag($propcsslist) : '').'">';
4757 print $propcsslist ? dol_escape_htmltag($propcsslist) : '';
4758 print '</td>';
4759 // Key for tooltop
4760 print '<td class="tdoverflowmax150" title="'.($prophelp ? dol_escape_htmltag($prophelp) : '').'">';
4761 print $prophelp ? dol_escape_htmltag($prophelp) : '';
4762 print '</td>';
4763 print '<td class="center">';
4764 print $propshowoncombobox ? dol_escape_htmltag($propshowoncombobox) : '';
4765 print '</td>';
4766 /*print '<td class="center">';
4767 print $propdisabled?$propdisabled:'';
4768 print '</td>';*/
4769 print '<td class="center">';
4770 print $propvalidate ? dol_escape_htmltag($propvalidate) : '';
4771 print '</td>';
4772 print '<td class="tdoverflowmax200">';
4773 print '<span title="'.dol_escape_htmltag($propcomment).'">';
4774 print dol_escape_htmltag($propcomment);
4775 print '</span>';
4776 print '</td>';
4777 print '<td class="center minwidth75 tdstickyright tdstickyghostwhite">';
4778 if ($propname != 'rowid') {
4779 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>';
4780 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>';
4781 }
4782 print '</td>';
4783 }
4784 print '</tr>';
4785 }
4786 } else {
4787 if ($tab == 'specifications') {
4788 if ($action != 'editfile' || empty($file)) {
4789 print '<span class="opacitymedium">'.$langs->trans("SpecDefDesc").'</span><br>';
4790 print '<br>';
4791
4792 $specs = dol_dir_list(dol_buildpath($modulelowercase.'/doc', 0), 'files', 1, '(\.md|\.asciidoc)$', array('\/temp\/'));
4793
4794 foreach ($specs as $spec) {
4795 $pathtofile = $modulelowercase.'/doc/'.$spec['relativename'];
4796 $format = 'asciidoc';
4797 if (preg_match('/\.md$/i', $spec['name'])) {
4798 $format = 'markdown';
4799 }
4800 print '<span class="fa fa-file"></span> '.$langs->trans("SpecificationFile").' : <strong class="wordbreak">'.$pathtofile.'</strong>';
4801 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>';
4802 print '<br>';
4803 }
4804 } else {
4805 // Use MD or asciidoc
4806
4807 //print $langs->trans("UseAsciiDocFormat").'<br>';
4808
4809 $fullpathoffile = dol_buildpath($file, 0);
4810
4811 $content = file_get_contents($fullpathoffile);
4812
4813 // New module
4814 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
4815 print '<input type="hidden" name="token" value="'.newToken().'">';
4816 print '<input type="hidden" name="action" value="savefile">';
4817 print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
4818 print '<input type="hidden" name="tab" value="'.$tab.'">';
4819 print '<input type="hidden" name="module" value="'.$module.'">';
4820
4821 $doleditor = new DolEditor('editfilecontent', $content, '', 300, 'Full', 'In', true, false, 'ace', 0, '99%');
4822 print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ? GETPOST('format', 'aZ09') : 'html'));
4823 print '<br>';
4824 print '<center>';
4825 print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
4826 print ' &nbsp; ';
4827 print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
4828 print '</center>';
4829
4830 print '</form>';
4831 }
4832 }
4833 print '<tr><td><span class="warning">'.$langs->trans('Property %s not found in the class. The class was probably not generated by modulebuilder.', $field).'</warning></td></tr>';
4834 }
4835 print '</table>';
4836 print '</div>';
4837
4838 print '</form>';
4839 } else {
4840 print '<span class="warning">'.$langs->trans('Failed to init the object with the new %s (%s)', $tabobj, (string) $db).'</warning>';
4841 }
4842 } catch (Exception $e) {
4843 print 'ee';
4844 print $e->getMessage();
4845 print 'ff';
4846 }
4847 } else {
4848 if (empty($forceddirread)) {
4849 $fullpathoffile = dol_buildpath($file, 0);
4850 } else {
4851 $fullpathoffile = $dirread.'/'.$file;
4852 }
4853
4854 $content = file_get_contents($fullpathoffile);
4855
4856 // New module
4857 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
4858 print '<input type="hidden" name="token" value="'.newToken().'">';
4859 print '<input type="hidden" name="action" value="savefile">';
4860 print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
4861 print '<input type="hidden" name="tab" value="'.$tab.'">';
4862 print '<input type="hidden" name="tabobj" value="'.dol_escape_htmltag($tabobj).'">';
4863 print '<input type="hidden" name="module" value="'.$module.($forceddirread ? '@'.$dirread : '').'">';
4864
4865 $doleditor = new DolEditor('editfilecontent', $content, '', 300, 'Full', 'In', true, false, 'ace', 0, '99%');
4866 print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ? GETPOST('format', 'aZ09') : 'html'));
4867 print '<br>';
4868 print '<center>';
4869 print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
4870 print ' &nbsp; ';
4871 print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
4872 print '</center>';
4873
4874 print '</form>';
4875 }
4876 }
4877
4878 print dol_get_fiche_end(); // Level 3
4879 }
4880
4881 if ($tab == 'dictionaries') {
4882 print '<!-- tab=dictionaries -->'."\n";
4883 $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
4884
4885 $dicts = $moduleobj->dictionaries;
4886
4887 if ($action == 'deletedict') {
4888 $formconfirm = $form->formconfirm(
4889 $_SERVER["PHP_SELF"].'?dictionnarykey='.urlencode((string) (GETPOSTINT('dictionnarykey'))).'&tab='.urlencode((string) ($tab)).'&module='.urlencode((string) ($module)),
4890 $langs->trans('Delete'),
4891 $langs->trans('Confirm Delete Dictionnary', GETPOST('dictionnarykey', 'alpha')),
4892 'confirm_deletedictionary',
4893 '',
4894 0,
4895 1
4896 );
4897 print $formconfirm;
4898 }
4899
4900 if ($action != 'editfile' || empty($file)) {
4901 print '<span class="opacitymedium">';
4902 $htmlhelp = $langs->trans("DictionariesDefDescTooltip", '{s1}');
4903 $htmlhelp = str_replace('{s1}', '<a target="adminbis" class="nofocusvisible" href="'.DOL_URL_ROOT.'/admin/dict.php">'.$langs->trans('Setup').' - '.$langs->trans('Dictionaries').'</a>', $htmlhelp);
4904 print $form->textwithpicto($langs->trans("DictionariesDefDesc"), $htmlhelp, 1, 'help', '', 0, 2, 'helpondesc').'<br>';
4905 print '</span>';
4906 print '<br>';
4907
4908 print '<span class="fa fa-file"></span> '.$langs->trans("DescriptorFile").' : <strong class="wordbreak">'.$pathtofile.'</strong>';
4909 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>';
4910 print '<br>';
4911 if (is_array($dicts) && !empty($dicts)) {
4912 print '<span class="fa fa-file"></span> '.$langs->trans("LanguageFile").' :</span> ';
4913 print '<strong class="wordbreak">'.$dicts['langs'].'</strong>';
4914 print '<br>';
4915 }
4916 print '<br>';
4917
4918 $head3 = array();
4919 $h = 0;
4920
4921 // Dir for module
4922 //$dir = $dirread.'/'.$modulelowercase.'/class';
4923
4924 $head3[$h][0] = $_SERVER["PHP_SELF"].'?tab=dictionaries&module='.$module.($forceddirread ? '@'.$dirread : '').'&tabdic=newdictionary';
4925 $head3[$h][1] = '<span class="valignmiddle text-plus-circle">'.$langs->trans("NewDictionary").'</span><span class="fa fa-plus-circle valignmiddle paddingleft"></span>';
4926 $head3[$h][2] = 'newdictionary';
4927 $h++;
4928
4929 // Scan for object class files
4930 //$listofobject = dol_dir_list($dir, 'files', 0, '\.class\.php$');
4931
4932 $firstdicname = '';
4933 // if (!empty($dicts['tabname'])) {
4934 // foreach ($dicts['tabname'] as $key => $dic) {
4935 // $dicname = $dic;
4936 // $diclabel = $dicts['tablib'][$key];
4937
4938 // if (empty($firstdicname)) {
4939 // $firstdicname = $dicname;
4940 // }
4941
4942 // $head3[$h][0] = $_SERVER["PHP_SELF"].'?tab=dictionaries&module='.$module.($forceddirread ? '@'.$dirread : '').'&tabdic='.$dicname;
4943 // $head3[$h][1] = $diclabel;
4944 // $head3[$h][2] = $dicname;
4945 // $h++;
4946 // }
4947 // }
4948
4949 // if ($h > 1) {
4950 // $head3[$h][0] = $_SERVER["PHP_SELF"].'?tab=dictionaries&module='.$module.($forceddirread ? '@'.$dirread : '').'&tabdic=deletedictionary';
4951 // $head3[$h][1] = $langs->trans("DangerZone");
4952 // $head3[$h][2] = 'deletedictionary';
4953 // $h++;
4954 // }
4955
4956 // 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.
4957 // if ($tabdic == 'newdicifnodic') {
4958 // if ($firstdicname) {
4959 // $tabdic = $firstdicname;
4960 // } else {
4961 // $tabdic = 'newdictionary';
4962 // }
4963 // }
4964 //print dol_get_fiche_head($head3, $tabdic, '', -1, ''); // Level 3
4965
4966
4967 $newdict = dolGetButtonTitle($langs->trans('NewDictionary'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/modulebuilder/index.php?tab=dictionaries&module='.urlencode($module).'&tabdic=newdictionary');
4968 print_barre_liste($langs->trans("ListOfDictionariesEntries"), 0, $_SERVER["PHP_SELF"], '', '', '', '', 0, '', '', 0, $newdict, '', 0, 0, 0, 1);
4969
4970 if ($tabdic != 'newdictionary') {
4971 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
4972 print '<input type="hidden" name="token" value="'.newToken().'">';
4973 print '<input type="hidden" name="action" value="addDictionary">';
4974 print '<input type="hidden" name="tab" value="dictionaries">';
4975 print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
4976 print '<input type="hidden" name="tabdic" value="'.dol_escape_htmltag($tabdic).'">';
4977
4978 print '<div class="div-table-responsive">';
4979 print '<table class="noborder">';
4980
4981 print '<tr class="liste_titre">';
4982 print_liste_field_titre("#", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder, 'thsticky thstickygrey ');
4983 print_liste_field_titre("Table", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
4984 print_liste_field_titre("Label", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
4985 print_liste_field_titre("SQL", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
4986 print_liste_field_titre("SQLSort", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
4987 print_liste_field_titre("FieldsView", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
4988 print_liste_field_titre("FieldsEdit", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
4989 print_liste_field_titre("FieldsInsert", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
4990 print_liste_field_titre("Rowid", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
4991 print_liste_field_titre("Condition", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
4992 print_liste_field_titre("", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
4993 print "</tr>\n";
4994
4995 if (!empty($dicts) && is_array($dicts) && !empty($dicts['tabname']) && is_array($dicts['tabname'])) {
4996 $i = 0;
4997 $maxi = count($dicts['tabname']);
4998 while ($i < $maxi) {
4999 if ($action == 'editdict' && $i == GETPOSTINT('dictionnarykey') - 1) {
5000 print '<tr class="oddeven">';
5001 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
5002 print '<input type="hidden" name="token" value="'.newToken().'">';
5003 print '<input type="hidden" name="tab" value="dictionaries">';
5004 print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
5005 print '<input type="hidden" name="action" value="updatedictionary">';
5006 print '<input type="hidden" name="dictionnarykey" value="'.($i + 1).'">';
5007
5008 print '<td class="tdsticky tdstickygray">';
5009 print($i + 1);
5010 print '</td>';
5011
5012 print '<td>';
5013 print '<input type="text" name="tabname" value="'.$dicts['tabname'][$i].'" readonly class="tdstickygray">';
5014 print '</td>';
5015
5016 print '<td>';
5017 print '<input type="text" name="tablib" value="'.$dicts['tablib'][$i].'">';
5018 print '</td>';
5019
5020 print '<td>';
5021 print '<input type="text" name="tabsql" value="'.$dicts['tabsql'][$i].'" readonly class="tdstickygray">';
5022 print '</td>';
5023
5024 print '<td>';
5025 print '<select name="tabsqlsort">';
5026 print '<option value="'.dol_escape_htmltag($dicts['tabsqlsort'][$i]).'">'.$dicts['tabsqlsort'][$i].'</option>';
5027 print '</select>';
5028 print '</td>';
5029
5030 print '<td><select name="tabfield" >';
5031 print '<option value="'.dol_escape_htmltag($dicts['tabfield'][$i]).'">'.$dicts['tabfield'][$i].'</option>';
5032 print '</select></td>';
5033
5034 print '<td><select name="tabfieldvalue" >';
5035 print '<option value="'.dol_escape_htmltag($dicts['tabfieldvalue'][$i]).'">'.$dicts['tabfieldvalue'][$i].'</option>';
5036 print '</select></td>';
5037
5038 print '<td><select name="tabfieldinsert" >';
5039 print '<option value="'.dol_escape_htmltag($dicts['tabfieldinsert'][$i]).'">'.$dicts['tabfieldinsert'][$i].'</option>';
5040 print '</select></td>';
5041
5042 print '<td>';
5043 print '<input type="text" name="tabrowid" value="'.dol_escape_htmltag($dicts['tabrowid'][$i]).'" readonly class="tdstickygray">';
5044 print '</td>';
5045
5046 print '<td>';
5047 print '<input type="text" name="tabcond" value="'.dol_escape_htmltag((empty($dicts['tabcond'][$i]) ? 'disabled' : 'enabled')).'" readonly class="tdstickygray">';
5048 print '</td>';
5049
5050 print '<td class="center minwidth75 tdstickyright tdstickyghostwhite">';
5051 print '<input id ="updatedict" class="reposition button smallpaddingimp" type="submit" name="updatedict" value="'.$langs->trans("Modify").'"/>';
5052 print '<br>';
5053 print '<input class="reposition button button-cancel smallpaddingimp" type="submit" name="cancel" value="'.$langs->trans("Cancel").'"/>';
5054 print '</td>';
5055
5056 print '</form>';
5057 print '</tr>';
5058 } else {
5059 print '<tr class="oddeven">';
5060
5061 print '<td class="tdsticky tdstickygray">';
5062 print($i + 1);
5063 print '</td>';
5064
5065 print '<td>';
5066 print $dicts['tabname'][$i];
5067 print '</td>';
5068
5069 print '<td>';
5070 print $dicts['tablib'][$i];
5071 print '</td>';
5072
5073 print '<td>';
5074 print $dicts['tabsql'][$i];
5075 print '</td>';
5076
5077 print '<td>';
5078 print $dicts['tabsqlsort'][$i];
5079 print '</td>';
5080
5081 print '<td>';
5082 print $dicts['tabfield'][$i];
5083 print '</td>';
5084
5085 print '<td>';
5086 print $dicts['tabfieldvalue'][$i];
5087 print '</td>';
5088
5089 print '<td>';
5090 print $dicts['tabfieldinsert'][$i];
5091 print '</td>';
5092
5093 print '<td >';
5094 print $dicts['tabrowid'][$i];
5095 print '</td>';
5096
5097 print '<td >';
5098 print $dicts['tabcond'][$i];
5099 print '</td>';
5100
5101 print '<td class="center minwidth75 tdstickyright tdstickyghostwhite">';
5102 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>';
5103 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>';
5104 print '</td>';
5105
5106 print '</tr>';
5107 }
5108 $i++;
5109 }
5110 } else {
5111 print '<tr><td colspan="11"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
5112 }
5113
5114 print '</table>';
5115 print '</div>';
5116
5117 print '</form>';
5118 }
5119
5120 if ($tabdic == 'newdictionary') {
5121 // New dic tab
5122 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
5123 print '<input type="hidden" name="token" value="'.newToken().'">';
5124 print '<input type="hidden" name="action" value="initdic">';
5125 print '<input type="hidden" name="tab" value="dictionaries">';
5126 print '<input type="hidden" name="tabdic" value="'.$tabdic.'">';
5127
5128 print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
5129
5130 print '<span class="opacitymedium">'.$langs->trans("EnterNameOfDictionaryDesc").'</span><br><br>';
5131
5132 print dol_get_fiche_head();
5133 print '<table class="border centpercent">';
5134 print '<tbody>';
5135 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>';
5136 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>';
5137 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>';
5138 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>';
5139 print '<tr><td class="titlefieldcreate">'.$langs->trans("FieldsView").'</td><td><input type="text" name="field" value="'.dol_escape_htmltag(GETPOST('field', 'alpha')).'"></td></tr>';
5140 print '<tr><td class="titlefieldcreate">'.$langs->trans("FieldsEdit").'</td><td><input type="text" name="fieldvalue" value="'.dol_escape_htmltag(GETPOST('fieldvalue', 'alpha')).'"></td></tr>';
5141 print '<tr><td class="titlefieldcreate">'.$langs->trans("FieldsInsert").'</td><td><input type="text" name="fieldinsert" value="'.dol_escape_htmltag(GETPOST('fieldinsert', 'alpha')).'"></td></tr>';
5142 print '<tr><td class="titlefieldcreate">'.$langs->trans("Rowid").'</td><td><input type="text" name="rowid" value="'.dol_escape_htmltag(GETPOST('rowid', 'alpha')).'"></td></tr>';
5143 print '<tr></tr>';
5144 print '</tbody></table>';
5145 print '<input type="submit" class="button" name="create" value="'.dol_escape_htmltag($langs->trans("GenerateCode")).'"'.($dirins ? '' : ' disabled="disabled"').'>';
5146 print '<input id="cancel" type="submit" class="button" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
5147 print dol_get_fiche_end();
5148 print '</form>';
5149 print '<script>
5150 $(document).ready(function() {
5151 $("input[name=\'dicname\']").on("blur", function() {
5152 if ($(this).val().length > 0) {
5153 $("input[name=\'label\']").val($(this).val());
5154 $("input[name=\'sql\']").val("SELECT f.rowid as rowid, f.code, f.label, f.active FROM llx_c_" + $(this).val() + " as f");
5155 $("input[name=\'sqlsort\']").val("label ASC");
5156 $("input[name=\'field\']").val("code,label");
5157 $("input[name=\'fieldvalue\']").val("code,label");
5158 $("input[name=\'fieldinsert\']").val("code,label");
5159 $("input[name=\'rowid\']").val("rowid");
5160 } else {
5161 $("input[name=\'label\']").val("");
5162 $("input[name=\'sql\']").val("");
5163 $("input[name=\'sqlsort\']").val("");
5164 $("input[name=\'field\']").val("");
5165 $("input[name=\'fieldvalue\']").val("");
5166 $("input[name=\'fieldinsert\']").val("");
5167 $("input[name=\'rowid\']").val("");
5168 }
5169 });
5170 $("input[id=\'cancel\']").click(function() {
5171 window.history.back();
5172 });
5173 });
5174 </script>';
5175
5176 /*print '<br>';
5177 print '<br>';
5178 print '<br>';
5179 print '<span class="opacitymedium">'.$langs->trans("or").'</span>';
5180 print '<br>';
5181 print '<br>';
5182 //print '<input type="checkbox" name="initfromtablecheck"> ';
5183 print $langs->trans("InitStructureFromExistingTable");
5184 print '<input type="text" name="initfromtablename" value="" placeholder="'.$langs->trans("TableName").'">';
5185 print '<input type="submit" class="button smallpaddingimp" name="createtablearray" value="'.dol_escape_htmltag($langs->trans("GenerateCode")).'"'.($dirins ? '' : ' disabled="disabled"').'>';
5186 print '<br>';
5187 */
5188 } elseif ($tabdic == 'deletedictionary') {
5189 // Delete dic tab
5190 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
5191 print '<input type="hidden" name="token" value="'.newToken().'">';
5192 print '<input type="hidden" name="action" value="confirm_deletedictionary">';
5193 print '<input type="hidden" name="tab" value="dictionaries">';
5194 print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
5195
5196 print $langs->trans("EnterNameOfDictionnaryToDeleteDesc").'<br><br>';
5197
5198 print '<input type="text" name="dicname" value="'.dol_escape_htmltag($modulename).'" placeholder="'.dol_escape_htmltag($langs->trans("DicKey")).'">';
5199 print '<input type="submit" class="button smallpaddingimp" name="delete" value="'.dol_escape_htmltag($langs->trans("Delete")).'"'.($dirins ? '' : ' disabled="disabled"').'>';
5200 print '</form>';
5201 }
5202
5203 print dol_get_fiche_end();
5204 } else {
5205 $fullpathoffile = dol_buildpath($file, 0);
5206
5207 $content = file_get_contents($fullpathoffile);
5208
5209 // New module
5210 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
5211 print '<input type="hidden" name="token" value="'.newToken().'">';
5212 print '<input type="hidden" name="action" value="savefile">';
5213 print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
5214 print '<input type="hidden" name="tab" value="'.$tab.'">';
5215 print '<input type="hidden" name="module" value="'.$module.'">';
5216
5217 $posCursor = (empty($find)) ? array() : array('find' => $find);
5218 $doleditor = new DolEditor('editfilecontent', $content, '', 300, 'Full', 'In', true, false, 'ace', 0, '99%', 0, $posCursor);
5219 print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ? GETPOST('format', 'aZ09') : 'html'));
5220 print '<br>';
5221 print '<center>';
5222 print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
5223 print ' &nbsp; ';
5224 print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
5225 print '</center>';
5226
5227 print '</form>';
5228 }
5229 }
5230
5231 if ($tab == 'menus') {
5232 print '<!-- tab=menus -->'."\n";
5233 $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
5234 $dirins = $listofmodules[strtolower($module)]['moduledescriptorrootpath'];
5235 $destdir = $dirins.'/'.strtolower($module);
5236 $listofobject = dol_dir_list($destdir.'/class', 'files', 0, '\.class\.php$');
5237 $objects = dolGetListOfObjectClasses($destdir);
5238
5239 $leftmenus = array();
5240
5241 $menus = $moduleobj->menu;
5242
5243 $permissions = $moduleobj->rights;
5244 $crud = array('read' => 'CRUDRead', 'write' => 'CRUDCreateWrite', 'delete' => 'Delete');
5245
5246 //grouped permissions
5247 $groupedRights = array();
5248 foreach ($permissions as $right) {
5249 $key = $right[4];
5250 if (!isset($groupedRights[$key])) {
5251 $groupedRights[$key] = array();
5252 }
5253 $groupedRights[$key][] = $right;
5254 }
5255 $groupedRights_json = json_encode($groupedRights);
5256
5257 if ($action == 'deletemenu') {
5258 $formconfirms = $form->formconfirm(
5259 $_SERVER["PHP_SELF"].'?menukey='.urlencode((string) (GETPOSTINT('menukey'))).'&tab='.urlencode((string) ($tab)).'&module='.urlencode((string) ($module)),
5260 $langs->trans('Delete'),
5261 ($menus[GETPOST('menukey')]['fk_menu'] === 'fk_mainmenu='.strtolower($module) ? $langs->trans('Warning: you will delete all menus linked to this one.', GETPOSTINT('menukey')) : $langs->trans('Confirm Delete Menu', GETPOSTINT('menukey'))),
5262 'confirm_deletemenu',
5263 '',
5264 0,
5265 1
5266 );
5267 print $formconfirms;
5268 }
5269 if ($action != 'editfile' || empty($file)) {
5270 print '<span class="opacitymedium">';
5271 $htmlhelp = $langs->trans("MenusDefDescTooltip", '{s1}');
5272 $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);
5273 print $form->textwithpicto($langs->trans("MenusDefDesc"), $htmlhelp, 1, 'help', '', 0, 2, 'helpondesc').'<br>';
5274 print '</span>';
5275 print '<br>';
5276
5277 // Links to editable files
5278 print '<span class="fa fa-file"></span> '.$langs->trans("DescriptorFile").' : <strong class="wordbreak">'.$pathtofile.'</strong>';
5279 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>';
5280 print '<br>';
5281
5282 // Search all files of modules mentioned by menu
5283 $listODifferentUrlsInMenu = array();
5284 foreach ($menus as $obj) {
5285 if (preg_match('/^\/'.preg_quote(strtolower($module), '/').'\//', $obj['url']) && !empty($pathoffile)) {
5286 if (!empty($listODifferentUrlsInMenu[$pathoffile])) { // Test to avoid to show same file twice.
5287 continue;
5288 }
5289 $pathtofile = $obj['url'];
5290 $listODifferentUrlsInMenu[$pathoffile] = $pathtofile;
5291 print '<span class="fa fa-file"></span> '.$langs->trans("PageLinkedByAMenuEntry").' : <strong class="wordbreak">'.$pathtofile.'</strong>';
5292 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>';
5293 print '<br>';
5294 }
5295 }
5296
5297
5298 print '<br>';
5299 print load_fiche_titre($langs->trans("ListOfMenusEntries"), '', '');
5300
5301 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
5302 print '<input type="hidden" name="token" value="'.newToken().'">';
5303 print '<input type="hidden" name="action" value="addmenu">';
5304 print '<input type="hidden" name="tab" value="menus">';
5305 print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
5306 print '<input type="hidden" name="tabobj" value="'.dol_escape_htmltag($tabobj).'">';
5307
5308 print '<div class="div-table-responsive">';
5309 print '<table class="noborder small">';
5310
5311 $htmltextenabled = '<u>'.$langs->trans("Examples").':</u><br>';
5312 $htmltextenabled .= '1 <span class="opacitymedium">(module always enabled)</span><br>';
5313 $htmltextenabled .= '0 <span class="opacitymedium">(module always disabled)</span><br>';
5314 $htmltextenabled .= 'isModEnabled(\''.dol_escape_htmltag(strtolower($module)).'\') <span class="opacitymedium">(enabled when module is enabled)</span>';
5315 $htmltextperms = '<u>'.$langs->trans("Examples").':</u><br>';
5316 $htmltextperms .= '1 <span class="opacitymedium">(access always allowed)</span><br>';
5317 $htmltextperms .= '$user->hasright(\''.dol_escape_htmltag(strtolower($module)).'\', \'myobject\', \'read\') <span class="opacitymedium">(access allowed if user has permission module->object->read)</span>';
5318
5319 print '<tr class="liste_titre">';
5320 print_liste_field_titre("#", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder, 'center tdsticky tdstickygray ');
5321 print_liste_field_titre("Position", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
5322 print_liste_field_titre("Title", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder, 'center');
5323 print_liste_field_titre("LinkToParentMenu", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder, 'minwidth100 ');
5324 print_liste_field_titre("mainmenu", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
5325 print_liste_field_titre("leftmenu", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
5326 print_liste_field_titre("URL", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder, '', $langs->transnoentitiesnoconv('DetailUrl'));
5327 print_liste_field_titre("LanguageFile", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
5328 print_liste_field_titre("Position", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder, 'right ');
5329 print_liste_field_titre("Enabled", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder, 'center ', $langs->trans('DetailEnabled').'<br><br>'.$htmltextenabled);
5330 print_liste_field_titre("Rights", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder, '', $langs->trans('DetailRight').'<br><br>'.$htmltextperms);
5331 print_liste_field_titre("Target", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder, '', $langs->trans('DetailTarget'));
5332 print_liste_field_titre("MenuForUsers", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder, 'center minwidth100 ', $langs->trans('DetailUser'));
5333 print_liste_field_titre("", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder, 'center ', $langs->trans(''));
5334 print "</tr>\n";
5335
5336 $r = count($menus) + 1;
5337 // for adding menu on module
5338 print '<tr>';
5339 print '<td class="center tdsticky tdstickygray"><input type="hidden" readonly class="center maxwidth50" name="propenabled" value="#"></td>';
5340 print '<td class="center">';
5341 print '<select class="maxwidth50" name="type">';
5342 print '<option value="">'.$langs->trans("........").'</option><option value="'.dol_escape_htmltag("left").'">left</option><option value="'.dol_escape_htmltag("top").'">top</option>';
5343 print '</select></td>';
5344 print '<td class="left"><input type="text" class="left maxwidth100" name="titre" value="'.dol_escape_htmltag(GETPOST('titre', 'alpha')).'"></td>';
5345 print '<td class="left">';
5346 print '<select name="fk_menu">';
5347 print '<option value="">'.$langs->trans("........").'</option>';
5348 foreach ($menus as $obj) {
5349 if ($obj['type'] == 'left' && !empty($obj['leftmenu'])) {
5350 print "<option value=".strtolower($obj['leftmenu']).">".$obj['leftmenu']."</option>";
5351 }
5352 }
5353 print '</select>';
5354 print '</td>';
5355 print '<td class="left"><input type="text" class="left maxwidth50" name="mainmenu" value="'.(empty(GETPOST('mainmenu')) ? strtolower($module) : dol_escape_htmltag(GETPOST('mainmenu', 'alpha'))).'"></td>';
5356 print '<td class="center"><input id="leftmenu" type="text" class="left maxwidth50" name="leftmenu" value="'.dol_escape_htmltag(GETPOST('leftmenu', 'alpha')).'"></td>';
5357 // URL
5358 print '<td class="left"><input id="url" type="text" class="left maxwidth100" name="url" value="'.dol_escape_htmltag(GETPOST('url', 'alpha')).'"></td>';
5359 print '<td class="left"><input type="text" class="left maxwidth75" name="langs" value="'.strtolower($module).'@'.strtolower($module).'" readonly></td>';
5360 // Position
5361 print '<td class="center"><input type="text" class="center maxwidth50 tdstickygray" name="position" value="'.(1000 + $r).'" readonly></td>';
5362 // Enabled
5363 print '<td class="center">';
5364 print '<input type="enabled" class="maxwidth125" value="'.dol_escape_htmltag(GETPOSTISSET('enabled') ? GETPOST('enabled') : 'isModEnabled(\''.$module.'\')').'">';
5365 /*
5366 print '<select class="maxwidth" name="enabled">';
5367 print '<option value="1" selected>'.$langs->trans("Show").'</option>';
5368 print '<option value="0">'.$langs->trans("Hide").'</option>';
5369 print '</select>';
5370 */
5371 print '</td>';
5372 // Perms
5373 print '<td class="left">';
5374 print '<select class="maxwidth" name="objects" id="objects">';
5375 print '<option value=""></option>';
5376 if (is_array($objects)) {
5377 foreach ($objects as $value) {
5378 print '<option value="'.strtolower($value).'">'.dol_escape_htmltag(strtolower($value)).'</option>';
5379 }
5380 }
5381 print '</select>';
5382 print '<select class="maxwidth hideobject" name="perms" id="perms">';
5383 print '</select>';
5384 print '</td>';
5385 print '<td class="center"><input type="text" class="center maxwidth50" name="target" value="'.dol_escape_htmltag(GETPOST('target', 'alpha')).'"></td>';
5386 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>';
5387
5388 print '<td class="center minwidth75 tdstickyright tdstickyghostwhite">';
5389 print '<input type="submit" class="button" name="add" value="'.$langs->trans("Add").'">';
5390 print '</td>';
5391 print '</tr>';
5392 // end form for add menu
5393
5394 //var_dump($menus);
5395
5396 // Loop on each menu entry
5397 if (count($menus)) {
5398 $i = 0;
5399 foreach ($menus as $menu) {
5400 $i++;
5401 //for get parent in menu
5402 $string = dol_escape_htmltag($menu['fk_menu']);
5403 $value = substr($string, strpos($string, 'fk_leftmenu=') + strlen('fk_leftmenu='));
5404
5405 $propFk_menu = !empty($menu['fk_menu']) ? $menu['fk_menu'] : GETPOST('fk_menu');
5406 $propTitre = !empty($menu['titre']) ? $menu['titre'] : GETPOST('titre');
5407 $propMainmenu = !empty($menu['mainmenu']) ? $menu['mainmenu'] : GETPOST('mainmenu');
5408 $propLeftmenu = !empty($menu['leftmenu']) ? $menu['leftmenu'] : GETPOST('leftmenu');
5409 $propUrl = !empty($menu['url']) ? $menu['url'] : GETPOST('url', 'alpha');
5410 $propPerms = !empty($menu['perms']) ? $menu['perms'] : GETPOST('perms');
5411 $propUser = !empty($menu['user']) ? $menu['user'] : GETPOST('user');
5412 $propTarget = !empty($menu['target']) ? $menu['target'] : GETPOST('target');
5413 $propEnabled = !empty($menu['enabled']) ? $menu['enabled'] : GETPOST('enabled');
5414
5415 $objPerms = (empty($arguments[1]) ? '' : trim($arguments[1]));
5416 $valPerms = (empty($arguments[2]) ? '' : trim($arguments[2]));
5417
5418 //$tabobject = ''; // We can't know what is $tabobject in most cases
5419
5420 if ($action == 'editmenu' && GETPOSTINT('menukey') == $i) {
5421 //var_dump($propPerms);exit;
5422 print '<tr class="oddeven">';
5423 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
5424 print '<input type="hidden" name="token" value="'.newToken().'">';
5425 print '<input type="hidden" name="action" value="update_menu">';
5426 print '<input type="hidden" name="tab" value="menus">';
5427 print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
5428 print '<input type="hidden" name="menukey" value="'.$i.'"/>';
5429 //print '<input type="hidden" name="tabobject" value="'.dol_escape_htmltag($tabobject).'">';
5430 print '<td class="tdsticky tdstickygray">';
5431 print $i;
5432 print '</td>';
5433 // Position (top, left)
5434 print '<td class="center">
5435 <select class="center maxwidth50" name="type">
5436 <option value="'.dol_escape_htmltag($menu['type']).'">
5437 '.dol_escape_htmltag($menu['type']).'
5438 </option>';
5439 print '<option value="'.($menu['type'] == 'left' ? 'top' : 'left').'">';
5440 if ($menu['type'] == 'left') {
5441 print 'top';
5442 } else {
5443 print 'left';
5444 }
5445 print '</option></select></td>';
5446 // Title
5447 print '<td><input type="text" class="left maxwidth100" name="titre" value="'.dol_escape_htmltag($propTitre).'"></td>';
5448 // Parent menu
5449 print '<td>';
5450 /*print '<select name="fk_menu" class="left maxwidth">';
5451 print '<option value="'.dol_escape_htmltag($propFk_menu).'">'.dol_escape_htmltag($value).'</option>';
5452 foreach ($menus as $obj) {
5453 if ($obj['type'] == 'left' && $obj['leftmenu'] != $value && $obj['leftmenu'] != $menu['leftmenu']) {
5454 print "<option value=".strtolower($obj['leftmenu']).">".$obj['leftmenu']."</option>";
5455 }
5456 }
5457 print '</select>';*/
5458 print '<input type="text" name="fk_menu" class="maxwidth150" value="'.dol_escape_htmltag($propFk_menu).'">';
5459 print '</td>';
5460 print '<td><input type="text" class="left maxwidth50" name="mainmenu" value="'.dol_escape_htmltag($propMainmenu).'" readonly></td>';
5461 print '<td><input type="text" class="left maxwidth50" name="leftmenu" value="'.dol_escape_htmltag($propLeftmenu).'" readonly></td>';
5462 // URL
5463 print '<td><input type="text" class="left maxwidth250" name="url" value="'.dol_escape_htmltag($propUrl).'"></td>';
5464 print '<td><input type="text" class="left maxwidth50" name="langs" value="'.strtolower($module).'@'.strtolower($module).'" readonly></td>';
5465 // Position
5466 print '<td class="center"><input type="text" class="center maxwidth50 tdstickygray" name="position" value="'.($menu['position']).'" readonly></td>';
5467 // Enabled
5468 print '<td class="nowraponall">';
5469 print '<input type="text" class="maxwidth125" name="enabled" value="'.dol_escape_htmltag($propEnabled != '' ? $propEnabled : "isModEnabled('".dol_escape_htmltag($module)."')").'">';
5470 $htmltext = '<u>'.$langs->trans("Examples").':</u><br>';
5471 $htmltext .= '1 <span class="opacitymedium">(always enabled)</span><br>';
5472 $htmltext .= '0 <span class="opacitymedium">(always disabled)</span><br>';
5473 $htmltext .= 'isModEnabled(\''.dol_escape_htmltag($module).'\') <span class="opacitymedium">(enabled when module is enabled)</span><br>';
5474 print $form->textwithpicto('', $htmltext);
5475 /*
5476 print '<select class="maxwidth50" name="enabledselect">';
5477 print '<option value="1">1 (always enabled)</option>';
5478 print '<option value="0">0 (always disabled)</option>';
5479 print '<option value="isModEnabled(\''.dol_escape_htmltag($module).'\')" >isModEnabled(\''.dol_escape_htmltag($module).'\')</option>';
5480 print '</select>';
5481 */
5482 print '</td>';
5483 // Permissions
5484 print '<td class="nowraponall">';
5485 print '<input type="text" name="perms" value="'.dol_escape_htmltag($propPerms).'">';
5486 /*
5487 if (!empty($objPerms)) {
5488 print '<input type="hidden" name="objects" value="'.$objPerms.'" />';
5489 print '<select class="center maxwidth50" name="perms">';
5490 if (!empty($valPerms)) {
5491 print '<option selected value="'.dol_escape_htmltag($valPerms).'">'.dol_escape_htmltag($langs->trans($crud[$valPerms])).'</option>';
5492 foreach ($crud as $key => $val) {
5493 if ($valPerms != $key) {
5494 print '<option value="'.dol_escape_htmltag($key).'">'.dol_escape_htmltag($langs->trans($val)).'</option>';
5495 }
5496 }
5497 }
5498 print '</select>';
5499 } else {
5500 print '<select class="center maxwidth50" name="objects">';
5501 print '<option></option>';
5502 foreach ($objects as $obj) {
5503 print '<option value="'.dol_escape_htmltag(strtolower($obj)).'">'.dol_escape_htmltag($obj).'</option>';
5504 }
5505 print '</select>';
5506 print '<select class="center maxwidth50" name="perms">';
5507 foreach ($crud as $key => $val) {
5508 print '<option value="'.dol_escape_htmltag($key).'">'.dol_escape_htmltag($key).'</option>';
5509 }
5510 print '</select>';
5511 }*/
5512 print '</td>';
5513 // Target
5514 print '<td class="center"><input type="text" class="center maxwidth50" name="target" value="'.dol_escape_htmltag($propTarget).'"></td>';
5515 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>';
5516 print '<td class="center minwidth75 tdstickyright tdstickyghostwhite maxwidth75">';
5517 print '<input class="reposition button smallpaddingimp" type="submit" name="edit" value="'.$langs->trans("Modify").'">';
5518 print '<input class="reposition button button-cancel smallpaddingimp" type="submit" name="cancel" value="'.$langs->trans("Cancel").'">';
5519 print '</td>';
5520 print '</form>';
5521 print '</tr>';
5522 } else {
5523 print '<tr class="oddeven">';
5524
5525 print '<td class="tdsticky tdstickygray">';
5526 print $i;
5527 print '</td>';
5528
5529 print '<td class="center">';
5530 print dol_escape_htmltag($menu['type']);
5531 print '</td>';
5532
5533 // Title
5534 print '<td>';
5535 print dol_escape_htmltag($menu['titre']);
5536 print '</td>';
5537
5538 // Parent menu
5539 print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($menu['fk_menu']).'">';
5540 print dol_escape_htmltag($menu['fk_menu']);
5541 print '</td>';
5542
5543 print '<td>';
5544 print dol_escape_htmltag($menu['mainmenu']);
5545 print '</td>';
5546
5547 print '<td>';
5548 print dol_escape_htmltag($menu['leftmenu']);
5549 print '</td>';
5550
5551 print '<td class="tdoverflowmax250" title="'.dol_escape_htmltag($menu['url']).'">';
5552 print dol_escape_htmltag($menu['url']);
5553 print '</td>';
5554
5555 print '<td>';
5556 print dol_escape_htmltag($menu['langs']);
5557 print '</td>';
5558
5559 // Position
5560 print '<td class="center">';
5561 print dol_escape_htmltag((string) $menu['position']);
5562 print '</td>';
5563
5564 // Enabled
5565 print '<td class="tdoverflowmax200" title="'.dol_escape_htmltag($menu['enabled']).'">';
5566 print dol_escape_htmltag($menu['enabled']);
5567 print '</td>';
5568
5569 // Perms
5570 print '<td class="tdoverflowmax200" title="'.dol_escape_htmltag($menu['perms']).'">';
5571 print dol_escape_htmltag($langs->trans($menu['perms']));
5572 print '</td>';
5573
5574 // Target
5575 print '<td class="center tdoverflowmax200" title="'.dol_escape_htmltag($menu['target']).'">';
5576 print dol_escape_htmltag($menu['target']);
5577 print '</td>';
5578
5579 print '<td class="center">';
5580 if ($menu['user'] == 2) {
5581 print $langs->trans("AllMenus");
5582 } elseif ($menu['user'] == 0) {
5583 print $langs->trans('Internal');
5584 } elseif ($menu['user'] == 1) {
5585 print $langs->trans('External');
5586 } else {
5587 print $menu['user']; // should not happen
5588 }
5589 print '</td>';
5590 print '<td class="center minwidth75 tdstickyright tdstickyghostwhite">';
5591 if ($menu['titre'] != 'Module'.$module.'Name') {
5592 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>';
5593 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>';
5594 }
5595 print '</td>';
5596 }
5597 print '</tr>';
5598 }
5599 } else {
5600 print '<tr><td colspan="14"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
5601 }
5602
5603 print '</table>';
5604 print '</div>';
5605 print '</form>';
5606
5607
5608 print '<script>
5609 $(document).ready(function() {
5610 //for fill in auto url
5611 $("#leftmenu").on("input", function() {
5612 var inputLeftMenu = $("#leftmenu").val();
5613 if (inputLeftMenu !== \'\') {
5614 var url = \''.dol_escape_js(strtolower($module)).'\' + inputLeftMenu + \'.php\';
5615 $("#url").val(url);
5616 }else {
5617 $("#url").val("");
5618 }
5619 });
5620
5621 var groupedRights = ' . $groupedRights_json . ';
5622 var objectsSelect = $("select[id=\'objects\']");
5623 var permsSelect = $("select[id=\'perms\']");
5624
5625 objectsSelect.change(function() {
5626 var selectedObject = $(this).val();
5627
5628 permsSelect.empty();
5629
5630 var rights = groupedRights[selectedObject];
5631
5632 if (rights) {
5633 for (var i = 0; i < rights.length; i++) {
5634 var right = rights[i];
5635 var option = $("<option></option>").attr("value", right[5]).text(right[5]);
5636 permsSelect.append(option);
5637 }
5638 } else {
5639 var option = $("<option></option>").attr("value", "read").text("read");
5640 permsSelect.append(option);
5641 }
5642
5643 if (selectedObject !== "" && selectedObject !== null && rights) {
5644 permsSelect.show();
5645 } else {
5646 permsSelect.hide();
5647 }
5648 if (objectsSelect.val() === "" || objectsSelect.val() === null) {
5649 permsSelect.hide();
5650 }
5651 });
5652 });
5653 </script>';
5654
5655 // display permissions for each object
5656 } else {
5657 $fullpathoffile = dol_buildpath($file, 0);
5658
5659 $content = file_get_contents($fullpathoffile);
5660
5661 // New module
5662 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
5663 print '<input type="hidden" name="token" value="'.newToken().'">';
5664 print '<input type="hidden" name="action" value="savefile">';
5665 print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
5666 print '<input type="hidden" name="tab" value="'.$tab.'">';
5667 print '<input type="hidden" name="module" value="'.$module.'">';
5668
5669 $posCursor = (empty($find)) ? array() : array('find' => $find);
5670 $doleditor = new DolEditor('editfilecontent', $content, '', 300, 'Full', 'In', true, false, 'ace', 0, '99%', 0, $posCursor);
5671 print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ? GETPOST('format', 'aZ09') : 'html'));
5672 print '<br>';
5673 print '<center>';
5674 print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
5675 print ' &nbsp; ';
5676 print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
5677 print '</center>';
5678
5679 print '</form>';
5680 }
5681 }
5682
5683 if ($tab == 'permissions') {
5684 print '<!-- tab=permissions -->'."\n";
5685 $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
5686
5687 $perms = $moduleobj->rights;
5688
5689 // Get list of existing objects
5690 $dir = $dirread.'/'.$modulelowercase.'/class';
5691 $listofobject = dol_dir_list($dir, 'files', 0, '\.class\.php$');
5692 $objects = array('myobject');
5693 $reg = array();
5694 foreach ($listofobject as $fileobj) {
5695 $tmpcontent = file_get_contents($fileobj['fullname']);
5696 if (preg_match('/class\s+([^\s]*)\s+extends\s+CommonObject/ims', $tmpcontent, $reg)) {
5697 $objects[$fileobj['fullname']] = $reg[1];
5698 }
5699 }
5700
5701 // declared select list for actions and labels permissions
5702 $crud = array('read' => 'CRUDRead', 'write' => 'CRUDCreateWrite', 'delete' => 'Delete');
5703 $labels = array("Read objects of ".$module, "Create/Update objects of ".$module, "Delete objects of ".$module);
5704
5705 $action = GETPOST('action', 'alpha');
5706
5707 if ($action == 'deleteright') {
5708 $formconfirm = $form->formconfirm(
5709 $_SERVER["PHP_SELF"].'?permskey='.urlencode((string) (GETPOSTINT('permskey'))).'&tab='.urlencode((string) ($tab)).'&module='.urlencode((string) ($module)).'&tabobj='.urlencode((string) ($tabobj)),
5710 $langs->trans('Delete'),
5711 $langs->trans('Confirm Delete Right', GETPOST('permskey', 'alpha')),
5712 'confirm_deleteright',
5713 '',
5714 0,
5715 1
5716 );
5717 print $formconfirm;
5718 }
5719
5720 if ($action != 'editfile' || empty($file)) {
5721 print '<!-- Tab to manage permissions -->'."\n";
5722 print '<span class="opacitymedium">';
5723 $htmlhelp = $langs->trans("PermissionsDefDescTooltip", '{s1}');
5724 $htmlhelp = str_replace('{s1}', '<a target="adminbis" class="nofocusvisible" href="'.DOL_URL_ROOT.'/admin/perms.php">'.$langs->trans('DefaultRights').'</a>', $htmlhelp);
5725 print $form->textwithpicto($langs->trans("PermissionsDefDesc"), $htmlhelp, 1, 'help', '', 0, 2, 'helpondesc').'<br>';
5726 print '</span>';
5727 print '<br>';
5728
5729 print '<span class="fa fa-file"></span> '.$langs->trans("DescriptorFile").' : <strong class="wordbreak">'.$pathtofile.'</strong>';
5730 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>';
5731 print '<br>';
5732
5733 print '<br>';
5734 print load_fiche_titre($langs->trans("ListOfPermissionsDefined"), '', '');
5735
5736 print '<!-- form to add permissions -->'."\n";
5737 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
5738 print '<input type="hidden" name="token" value="'.newToken().'">';
5739 print '<input type="hidden" name="action" value="addright">';
5740 print '<input type="hidden" name="tab" value="permissions">';
5741 print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
5742 print '<input type="hidden" name="tabobj" value="'.dol_escape_htmltag($tabobj).'">';
5743
5744 print '<div class="div-table-responsive">';
5745 print '<table class="noborder">';
5746
5747 print '<tr class="liste_titre">';
5748 print_liste_field_titre("ID", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder, "center");
5749 print_liste_field_titre("Object", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder, "center");
5750 print_liste_field_titre("CRUD", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder, "center");
5751 print_liste_field_titre("Label", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder, "center");
5752 print_liste_field_titre("", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder, "center");
5753 print "</tr>\n";
5754
5755 //form for add new right
5756 print '<tr class="small">';
5757 print '<td><input type="hidden" readonly name="id" class="width75" value="0"></td>';
5758
5759 print '<td><select class="minwidth100" name="permissionObj" id="permissionObj">';
5760 print '<option value=""></option>';
5761 foreach ($objects as $obj) {
5762 if ($obj != 'myobject') {
5763 print '<option value="'.$obj.'">'.$obj.'</option>';
5764 }
5765 }
5766 print '</select></td>';
5767
5768 print '<td><select class="maxwidth75" name="crud" id="crud">';
5769 print '<option value=""></option>';
5770 foreach ($crud as $key => $val) {
5771 print '<option value="'.$key.'">'.$langs->trans($val).'</option>';
5772 }
5773 print '</td>';
5774
5775 print '<td >';
5776 print '<input type="text" name="label" id="label" class="minwidth200">';
5777 print '</td>';
5778
5779 print '<td class="center minwidth75 tdstickyright tdstickyghostwhite">';
5780 print '<input type="submit" class="button" name="add" value="'.$langs->trans("Add").'">';
5781 print '</td>';
5782 print '</tr>';
5783
5784 if (count($perms)) {
5785 $i = 0;
5786 foreach ($perms as $perm) {
5787 $i++;
5788
5789 // section for editing right
5790 if ($action == 'edit_right' && $perm[0] == GETPOSTINT('permskey')) {
5791 print '<tr class="oddeven">';
5792 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST" name="modifPerms">';
5793 print '<input type="hidden" name="token" value="'.newToken().'">';
5794 print '<input type="hidden" name="tab" value="permissions">';
5795 print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
5796 print '<input type="hidden" name="tabobj" value="'.dol_escape_htmltag($tabobj).'">';
5797 print '<input type="hidden" name="action" value="update_right">';
5798 print '<input type="hidden" name="counter" value="'.$i.'">';
5799
5800 print '<input type="hidden" name="permskey" value="'.$perm[0].'">';
5801
5802 print '<td class="tdsticky tdstickygray">';
5803 print '<input class="width75" type="text" readonly value="'.dol_escape_htmltag($perm[0]).'"/>';
5804 print '</td>';
5805
5806 print '<td>';
5807 print '<select name="crud">';
5808 print '<option value="'.dol_escape_htmltag($perm[5]).'">'.$langs->trans($perm[5]).'</option>';
5809 foreach ($crud as $i => $x) {
5810 if ($perm[5] != $i) {
5811 print '<option value="'.$i.'">'.$langs->trans(ucfirst($x)).'</option>';
5812 }
5813 }
5814 print '</select>';
5815 print '</td>';
5816
5817 print '<td><select name="permissionObj" >';
5818 print '<option value="'.dol_escape_htmltag($perm[4]).'">'.ucfirst($perm[4]).'</option>';
5819 print '</select></td>';
5820
5821 print '<td>';
5822 print '<input type="text" name="label" value="'.dol_escape_htmltag($perm[1]).'">';
5823 print '</td>';
5824
5825 print '<td class="center minwidth75 tdstickyright tdstickyghostwhite">';
5826 print '<input id ="modifyPerm" class="reposition button smallpaddingimp" type="submit" name="modifyright" value="'.$langs->trans("Modify").'"/>';
5827 print '<br>';
5828 print '<input class="reposition button button-cancel smallpaddingimp" type="submit" name="cancel" value="'.$langs->trans("Cancel").'"/>';
5829 print '</td>';
5830
5831 print '</form>';
5832 print '</tr>';
5833 } else {
5834 // $perm can be module->object->crud or module->crud
5835 print '<tr class="oddeven">';
5836
5837 print '<td>';
5838 print dol_escape_htmltag($perm[0]);
5839 print '</td>';
5840
5841 print '<td>';
5842 if (in_array($perm[5], array('lire', 'read', 'creer', 'write', 'effacer', 'delete'))) {
5843 print dol_escape_htmltag(ucfirst($perm[4]));
5844 } else {
5845 print ''; // No particular object
5846 }
5847 print '</td>';
5848
5849 print '<td>';
5850 if (in_array($perm[5], array('lire', 'read', 'creer', 'write', 'effacer', 'delete'))) {
5851 print ucfirst($langs->trans($perm[5]));
5852 } else {
5853 print ucfirst($langs->trans($perm[4]));
5854 }
5855 print '</td>';
5856
5857 print '<td>';
5858 print $langs->trans($perm[1]);
5859 print '</td>';
5860
5861 print '<td class="center minwidth75 tdstickyright tdstickyghostwhite">';
5862 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>';
5863 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>';
5864
5865 print '</td>';
5866
5867 print '</tr>';
5868 }
5869 }
5870 } else {
5871 print '<tr><td colspan="5"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
5872 }
5873
5874 print '</table>';
5875 print '</div>';
5876
5877 print '</form>';
5878 print '<script>
5879 function updateInputField() {
5880 value1 = $("#crud").val();
5881 value2 = $("#permissionObj").val();
5882
5883 // Vérifie si les deux sélections sont faites
5884 if (value1 && value2) {
5885 switch(value1.toLowerCase()){
5886 case "read":
5887 $("#label").val("Read "+value2+" object of '.ucfirst($module).'")
5888 break;
5889 case "write":
5890 $("#label").val("Create/Update "+value2+" object of '.ucfirst($module).'")
5891 break;
5892 case "delete":
5893 $("#label").val("Delete "+value2+" object of '.ucfirst($module).'")
5894 break;
5895 default:
5896 $("#label").val("")
5897 }
5898 }
5899 }
5900
5901 $("#crud, #permissionObj").change(function(){
5902 console.log("We change selection");
5903 updateInputField();
5904 });
5905
5906 </script>';
5907 } else {
5908 $fullpathoffile = dol_buildpath($file, 0);
5909
5910 $content = file_get_contents($fullpathoffile);
5911
5912 // New module
5913 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
5914 print '<input type="hidden" name="token" value="'.newToken().'">';
5915 print '<input type="hidden" name="action" value="savefile">';
5916 print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
5917 print '<input type="hidden" name="tab" value="'.$tab.'">';
5918 print '<input type="hidden" name="module" value="'.$module.'">';
5919
5920 $posCursor = (empty($find)) ? array() : array('find' => $find);
5921 $doleditor = new DolEditor('editfilecontent', $content, '', 300, 'Full', 'In', true, false, 'ace', 0, '99%', 0, $posCursor);
5922 print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ? GETPOST('format', 'aZ09') : 'html'));
5923 print '<br>';
5924 print '<center>';
5925 print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
5926 print ' &nbsp; ';
5927 print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
5928 print '</center>';
5929
5930 print '</form>';
5931 }
5932 }
5933
5934 if ($tab == 'hooks') {
5935 print '<!-- tab=hooks -->'."\n";
5936 if ($action != 'editfile' || empty($file)) {
5937 print '<span class="opacitymedium">'.$langs->trans("HooksDefDesc").'</span><br>';
5938 print '<br>';
5939
5940 print '<table>';
5941
5942 $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
5943 print '<tr><td>';
5944 print '<span class="fa fa-file"></span> '.$langs->trans("DescriptorFile").' : <strong class="wordbreak">'.$pathtofile.'</strong>';
5945 print '</td><td>';
5946 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>';
5947 print '</td></tr>';
5948
5949 print '<tr><td>';
5950 $pathtohook = strtolower($module).'/class/actions_'.strtolower($module).'.class.php';
5951 print '<span class="fa fa-file"></span> '.$langs->trans("HooksFile").' : ';
5952 if (dol_is_file($dirins.'/'.$pathtohook)) {
5953 print '<strong class="wordbreak">'.$pathtohook.'</strong>';
5954 print '</td>';
5955 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> ';
5956 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>';
5957 } else {
5958 print '<span class="opacitymedium">'.$langs->trans("FileNotYetGenerated").'</span>';
5959 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>';
5960 print '<td></td>';
5961 }
5962 print '</tr>';
5963 } else {
5964 $fullpathoffile = dol_buildpath($file, 0);
5965
5966 $content = file_get_contents($fullpathoffile);
5967
5968 // New module
5969 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
5970 print '<input type="hidden" name="token" value="'.newToken().'">';
5971 print '<input type="hidden" name="action" value="savefile">';
5972 print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
5973 print '<input type="hidden" name="tab" value="'.$tab.'">';
5974 print '<input type="hidden" name="module" value="'.$module.'">';
5975
5976 $posCursor = (empty($find)) ? array() : array('find' => $find);
5977 $doleditor = new DolEditor('editfilecontent', $content, '', 300, 'Full', 'In', true, false, 'ace', 0, '99%', 0, $posCursor);
5978 print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ? GETPOST('format', 'aZ09') : 'html'));
5979 print '<br>';
5980 print '<center>';
5981 print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
5982 print ' &nbsp; ';
5983 print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
5984 print '</center>';
5985
5986 print '</form>';
5987 }
5988 }
5989
5990 if ($tab == 'triggers') {
5991 print '<!-- tab=triggers -->'."\n";
5992 require_once DOL_DOCUMENT_ROOT.'/core/class/interfaces.class.php';
5993
5994 $interfaces = new Interfaces($db);
5995 $triggers = $interfaces->getTriggersList(array('/'.strtolower($module).'/core/triggers'));
5996
5997 if ($action != 'editfile' || empty($file)) {
5998 print '<span class="opacitymedium">'.$langs->trans("TriggerDefDesc").'</span><br>';
5999 print '<br>';
6000
6001 print '<table>';
6002
6003 $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
6004 print '<tr><td>';
6005 print '<span class="fa fa-file"></span> '.$langs->trans("DescriptorFile").' : <strong class="wordbreak">'.$pathtofile.'</strong>';
6006 print '</td><td>';
6007 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>';
6008 print '</td></tr>';
6009
6010 if (!empty($triggers)) {
6011 foreach ($triggers as $trigger) {
6012 $pathtofile = $trigger['relpath'];
6013
6014 print '<tr><td>';
6015 print '<span class="fa fa-file"></span> '.$langs->trans("TriggersFile").' : <strong class="wordbreak">'.$pathtofile.'</strong>';
6016 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>';
6017 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>';
6018 print '</tr>';
6019 }
6020 } else {
6021 print '<tr><td>';
6022 print '<span class="fa fa-file"></span> '.$langs->trans("TriggersFile");
6023 print ' : <span class="opacitymedium">'.$langs->trans("FileNotYetGenerated").'</span>';
6024 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>';
6025 print '<td></td>';
6026 print '</tr>';
6027 }
6028
6029 print '</table>';
6030 } else {
6031 $fullpathoffile = dol_buildpath($file, 0);
6032
6033 $content = file_get_contents($fullpathoffile);
6034
6035 // New module
6036 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
6037 print '<input type="hidden" name="token" value="'.newToken().'">';
6038 print '<input type="hidden" name="action" value="savefile">';
6039 print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
6040 print '<input type="hidden" name="tab" value="'.$tab.'">';
6041 print '<input type="hidden" name="module" value="'.$module.'">';
6042
6043 $posCursor = (empty($find)) ? array() : array('find' => $find);
6044 $doleditor = new DolEditor('editfilecontent', $content, '', 300, 'Full', 'In', true, false, 'ace', 0, '99%', 0, $posCursor);
6045 print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ? GETPOST('format', 'aZ09') : 'html'));
6046 print '<br>';
6047 print '<center>';
6048 print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
6049 print ' &nbsp; ';
6050 print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
6051 print '</center>';
6052
6053 print '</form>';
6054 }
6055 }
6056
6057 if ($tab == 'css') {
6058 print '<!-- tab=css -->'."\n";
6059 if ($action != 'editfile' || empty($file)) {
6060 print '<span class="opacitymedium">'.$langs->trans("CSSDesc").'</span><br>';
6061 print '<br>';
6062
6063 print '<table>';
6064
6065 print '<tr><td>';
6066 $pathtohook = strtolower($module).'/css/'.strtolower($module).'.css.php';
6067 print '<span class="fa fa-file"></span> '.$langs->trans("CSSFile").' : ';
6068 if (dol_is_file($dirins.'/'.$pathtohook)) {
6069 print '<strong class="wordbreak">'.$pathtohook.'</strong>';
6070 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>';
6071 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>';
6072 } else {
6073 print '<span class="opacitymedium">'.$langs->trans("FileNotYetGenerated").'</span>';
6074 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>';
6075 }
6076 print '</tr>';
6077 } else {
6078 $fullpathoffile = dol_buildpath($file, 0);
6079
6080 $content = file_get_contents($fullpathoffile);
6081
6082 // New module
6083 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
6084 print '<input type="hidden" name="token" value="'.newToken().'">';
6085 print '<input type="hidden" name="action" value="savefile">';
6086 print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
6087 print '<input type="hidden" name="tab" value="'.$tab.'">';
6088 print '<input type="hidden" name="module" value="'.$module.'">';
6089
6090 $doleditor = new DolEditor('editfilecontent', $content, '', 300, 'Full', 'In', true, false, 'ace', 0, '99%');
6091 print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ? GETPOST('format', 'aZ09') : 'html'));
6092 print '<br>';
6093 print '<center>';
6094 print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
6095 print ' &nbsp; ';
6096 print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
6097 print '</center>';
6098
6099 print '</form>';
6100 }
6101 }
6102
6103 if ($tab == 'js') {
6104 print '<!-- tab=js -->'."\n";
6105 if ($action != 'editfile' || empty($file)) {
6106 print '<span class="opacitymedium">'.$langs->trans("JSDesc").'</span><br>';
6107 print '<br>';
6108
6109 print '<table>';
6110
6111 print '<tr><td>';
6112 $pathtohook = strtolower($module).'/js/'.strtolower($module).'.js.php';
6113 print '<span class="fa fa-file"></span> '.$langs->trans("JSFile").' : ';
6114 if (dol_is_file($dirins.'/'.$pathtohook)) {
6115 print '<strong class="wordbreak">'.$pathtohook.'</strong>';
6116 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>';
6117 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>';
6118 } else {
6119 print '<span class="opacitymedium">'.$langs->trans("FileNotYetGenerated").'</span>';
6120 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>';
6121 }
6122 print '</tr>';
6123 } else {
6124 $fullpathoffile = dol_buildpath($file, 0);
6125
6126 $content = file_get_contents($fullpathoffile);
6127
6128 // New module
6129 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
6130 print '<input type="hidden" name="token" value="'.newToken().'">';
6131 print '<input type="hidden" name="action" value="savefile">';
6132 print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
6133 print '<input type="hidden" name="tab" value="'.$tab.'">';
6134 print '<input type="hidden" name="module" value="'.$module.'">';
6135
6136 $doleditor = new DolEditor('editfilecontent', $content, '', 300, 'Full', 'In', true, false, 'ace', 0, '99%');
6137 print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ? GETPOST('format', 'aZ09') : 'html'));
6138 print '<br>';
6139 print '<center>';
6140 print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
6141 print ' &nbsp; ';
6142 print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
6143 print '</center>';
6144
6145 print '</form>';
6146 }
6147 }
6148
6149 if ($tab == 'widgets') {
6150 print '<!-- tab=widgets -->'."\n";
6151 require_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
6152
6153 $widgets = ModeleBoxes::getWidgetsList(array('/'.strtolower($module).'/core/boxes'));
6154
6155 if ($action != 'editfile' || empty($file)) {
6156 print '<span class="opacitymedium">'.$langs->trans("WidgetDesc").'</span><br>';
6157 print '<br>';
6158
6159 print '<table>';
6160 if (!empty($widgets)) {
6161 foreach ($widgets as $widget) {
6162 $pathtofile = $widget['relpath'];
6163
6164 print '<tr><td><span class="fa fa-file"></span> '.$langs->trans("WidgetFile").' : <strong class="wordbreak">'.$pathtofile.'</strong>';
6165 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>';
6166 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>';
6167 print '</tr>';
6168 }
6169 } else {
6170 print '<tr><td><span class="fa fa-file"></span> '.$langs->trans("WidgetFile").' : <span class="opacitymedium">'.$langs->trans("NoWidget").'</span>';
6171 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>';
6172 print '</td></tr>';
6173 }
6174 print '</table>';
6175 } else {
6176 $fullpathoffile = dol_buildpath($file, 0);
6177
6178 $content = file_get_contents($fullpathoffile);
6179
6180 // New module
6181 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
6182 print '<input type="hidden" name="token" value="'.newToken().'">';
6183 print '<input type="hidden" name="action" value="savefile">';
6184 print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
6185 print '<input type="hidden" name="tab" value="'.$tab.'">';
6186 print '<input type="hidden" name="module" value="'.$module.'">';
6187
6188 $doleditor = new DolEditor('editfilecontent', $content, '', 300, 'Full', 'In', true, false, 'ace', 0, '99%');
6189 print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ? GETPOST('format', 'aZ09') : 'html'));
6190 print '<br>';
6191 print '<center>';
6192 print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
6193 print ' &nbsp; ';
6194 print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
6195 print '</center>';
6196
6197 print '</form>';
6198 }
6199 }
6200
6201 if ($tab == 'emailings') {
6202 print '<!-- tab=emailings -->'."\n";
6203 require_once DOL_DOCUMENT_ROOT.'/core/modules/mailings/modules_mailings.php';
6204
6205 $emailingselectors = MailingTargets::getEmailingSelectorsList(array('/'.strtolower($module).'/core/modules/mailings'));
6206
6207 if ($action != 'editfile' || empty($file)) {
6208 print '<span class="opacitymedium">'.$langs->trans("EmailingSelectorDesc").'</span><br>';
6209 print '<br>';
6210
6211 print '<table>';
6212 if (!empty($emailingselectors)) {
6213 foreach ($emailingselectors as $emailingselector) {
6214 $pathtofile = $emailingselector['relpath'];
6215
6216 print '<tr><td><span class="fa fa-file"></span> '.$langs->trans("EmailingSelectorFile").' : <strong class="wordbreak">'.$pathtofile.'</strong>';
6217 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>';
6218 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>';
6219 print '</tr>';
6220 }
6221 } else {
6222 print '<tr><td><span class="fa fa-file"></span> '.$langs->trans("EmailingSelectorFile").' : <span class="opacitymedium">'.$langs->trans("NoEmailingSelector").'</span>';
6223 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>';
6224 print '</td></tr>';
6225 }
6226 print '</table>';
6227 } else {
6228 $fullpathoffile = dol_buildpath($file, 0);
6229
6230 $content = file_get_contents($fullpathoffile);
6231
6232 // New module
6233 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
6234 print '<input type="hidden" name="token" value="'.newToken().'">';
6235 print '<input type="hidden" name="action" value="savefile">';
6236 print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
6237 print '<input type="hidden" name="tab" value="'.$tab.'">';
6238 print '<input type="hidden" name="module" value="'.$module.'">';
6239
6240 $doleditor = new DolEditor('editfilecontent', $content, '', 300, 'Full', 'In', true, false, 'ace', 0, '99%');
6241 print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ? GETPOST('format', 'aZ09') : 'html'));
6242 print '<br>';
6243 print '<center>';
6244 print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
6245 print ' &nbsp; ';
6246 print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
6247 print '</center>';
6248
6249 print '</form>';
6250 }
6251 }
6252
6253 if ($tab == 'exportimport') {
6254 print '<!-- tab=exportimport -->'."\n";
6255 $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
6256
6257 $exportlist = $moduleobj->export_label;
6258 $importlist = $moduleobj->import_label;
6259
6260 if ($action != 'editfile' || empty($file)) {
6261 print '<span class="opacitymedium">'.$langs->transnoentities('ImportExportProfiles').'</span><br>';
6262 print '<br>';
6263
6264 print '<span class="fa fa-file"></span> '.$langs->trans("DescriptorFile").' ('.$langs->trans("ExportsArea").') : <strong class="wordbreak">'.$pathtofile.'</strong>';
6265 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>';
6266 print '<br>';
6267 print '<span class="fa fa-file"></span> '.$langs->trans("DescriptorFile").' ('.$langs->trans("ImportArea").') : <strong class="wordbreak">'.$pathtofile.'</strong>';
6268 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>';
6269 print '<br>';
6270 } else {
6271 $fullpathoffile = dol_buildpath($file, 0);
6272
6273 $content = file_get_contents($fullpathoffile);
6274
6275 // New module
6276 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
6277 print '<input type="hidden" name="token" value="'.newToken().'">';
6278 print '<input type="hidden" name="action" value="savefile">';
6279 print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
6280 print '<input type="hidden" name="tab" value="'.$tab.'">';
6281 print '<input type="hidden" name="module" value="'.$module.'">';
6282
6283 $posCursor = (empty($find)) ? array() : array('find' => $find);
6284 $doleditor = new DolEditor('editfilecontent', $content, '', 300, 'Full', 'In', true, false, 'ace', 0, '99%', 0, $posCursor);
6285 print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ? GETPOST('format', 'aZ09') : 'html'));
6286 print '<br>';
6287 print '<center>';
6288 print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
6289 print ' &nbsp; ';
6290 print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
6291 print '</center>';
6292
6293 print '</form>';
6294 }
6295 }
6296
6297 if ($tab == 'cli') {
6298 print '<!-- tab=cli -->'."\n";
6299 $clifiles = array();
6300 $i = 0;
6301
6302 $dircli = array('/'.strtolower($module).'/scripts');
6303
6304 foreach ($dircli as $reldir) {
6305 $dir = dol_buildpath($reldir, 0);
6306 $newdir = dol_osencode($dir);
6307
6308 // Check if directory exists (we do not use dol_is_dir to avoid loading files.lib.php at each call)
6309 if (!is_dir($newdir)) {
6310 continue;
6311 }
6312
6313 $handle = opendir($newdir);
6314
6315 if (is_resource($handle)) {
6316 while (($tmpfile = readdir($handle)) !== false) {
6317 if (is_readable($newdir.'/'.$tmpfile) && preg_match('/^(.+)\.php/', $tmpfile, $reg)) {
6318 if (preg_match('/\.back$/', $tmpfile)) {
6319 continue;
6320 }
6321
6322 $clifiles[$i]['relpath'] = preg_replace('/^\//', '', $reldir).'/'.$tmpfile;
6323
6324 $i++;
6325 }
6326 }
6327 closedir($handle);
6328 }
6329 }
6330
6331 if ($action != 'editfile' || empty($file)) {
6332 print '<span class="opacitymedium">'.$langs->trans("CLIDesc").'</span><br>';
6333 print '<br>';
6334
6335 print '<table>';
6336 if (!empty($clifiles)) {
6337 foreach ($clifiles as $clifile) {
6338 $pathtofile = $clifile['relpath'];
6339
6340 print '<tr><td><span class="fa fa-file"></span> '.$langs->trans("CLIFile").' : <strong class="wordbreak">'.$pathtofile.'</strong>';
6341 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>';
6342 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>';
6343 print '</tr>';
6344 }
6345 } else {
6346 print '<tr><td><span class="fa fa-file"></span> '.$langs->trans("CLIFile").' : <span class="opacitymedium">'.$langs->trans("FileNotYetGenerated").'</span>';
6347 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>';
6348 print '</td></tr>';
6349 }
6350 print '</table>';
6351 } else {
6352 $fullpathoffile = dol_buildpath($file, 0);
6353
6354 $content = file_get_contents($fullpathoffile);
6355
6356 // New module
6357 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
6358 print '<input type="hidden" name="token" value="'.newToken().'">';
6359 print '<input type="hidden" name="action" value="savefile">';
6360 print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
6361 print '<input type="hidden" name="tab" value="'.$tab.'">';
6362 print '<input type="hidden" name="module" value="'.$module.'">';
6363
6364 $doleditor = new DolEditor('editfilecontent', $content, '', 300, 'Full', 'In', true, false, 'ace', 0, '99%');
6365 print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ? GETPOST('format', 'aZ09') : 'html'));
6366 print '<br>';
6367 print '<center>';
6368 print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
6369 print ' &nbsp; ';
6370 print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
6371 print '</center>';
6372
6373 print '</form>';
6374 }
6375 }
6376
6377 if ($tab == 'cron') {
6378 print '<!-- tab=cron -->'."\n";
6379 $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
6380
6381 $cronjobs = $moduleobj->cronjobs;
6382
6383 if ($action != 'editfile' || empty($file)) {
6384 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>';
6385 print '<br>';
6386
6387 print '<span class="fa fa-file"></span> '.$langs->trans("DescriptorFile").' : <strong class="wordbreak">'.$pathtofile.'</strong>';
6388 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>';
6389 print '<br>';
6390
6391 print '<br>';
6392 print load_fiche_titre($langs->trans("CronJobProfiles"), '', '');
6393
6394 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
6395 print '<input type="hidden" name="token" value="'.newToken().'">';
6396 print '<input type="hidden" name="action" value="addproperty">';
6397 print '<input type="hidden" name="tab" value="objects">';
6398 print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
6399 print '<input type="hidden" name="tabobj" value="'.dol_escape_htmltag($tabobj).'">';
6400
6401 print '<div class="div-table-responsive">';
6402 print '<table class="noborder">';
6403
6404 print '<tr class="liste_titre">';
6405 print_liste_field_titre("CronLabel", $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder);
6406 print_liste_field_titre("CronTask", '', '', "", $param, '', $sortfield, $sortorder);
6407 print_liste_field_titre("CronFrequency", '', "", "", $param, '', $sortfield, $sortorder);
6408 print_liste_field_titre("StatusAtInstall", $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder);
6409 print_liste_field_titre("Comment", $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder);
6410 print "</tr>\n";
6411
6412 if (count($cronjobs)) {
6413 foreach ($cronjobs as $cron) {
6414 print '<tr class="oddeven">';
6415
6416 print '<td>';
6417 print $cron['label'];
6418 print '</td>';
6419
6420 print '<td>';
6421 $texttoshow = null;
6422 if ($cron['jobtype'] == 'method') {
6423 $text = $langs->trans("CronClass");
6424 $texttoshow = $langs->trans('CronModule').': '.$module.'<br>';
6425 $texttoshow .= $langs->trans('CronClass').': '.$cron['class'].'<br>';
6426 $texttoshow .= $langs->trans('CronObject').': '.$cron['objectname'].'<br>';
6427 $texttoshow .= $langs->trans('CronMethod').': '.$cron['method'];
6428 $texttoshow .= '<br>'.$langs->trans('CronArgs').': '.$cron['parameters'];
6429 $texttoshow .= '<br>'.$langs->trans('Comment').': '.$langs->trans($cron['comment']);
6430 } elseif ($cron['jobtype'] == 'command') {
6431 $text = $langs->trans('CronCommand');
6432 $texttoshow = $langs->trans('CronCommand').': '.dol_trunc($cron['command']);
6433 $texttoshow .= '<br>'.$langs->trans('CronArgs').': '.$cron['parameters'];
6434 $texttoshow .= '<br>'.$langs->trans('Comment').': '.$langs->trans($cron['comment']);
6435 }
6436 print $form->textwithpicto($text, $texttoshow, 1);
6437 print '</td>';
6438
6439 print '<td>';
6440 if ($cron['unitfrequency'] == "60") {
6441 print $langs->trans('CronEach')." ".($cron['frequency'])." ".$langs->trans('Minutes');
6442 }
6443 if ($cron['unitfrequency'] == "3600") {
6444 print $langs->trans('CronEach')." ".($cron['frequency'])." ".$langs->trans('Hours');
6445 }
6446 if ($cron['unitfrequency'] == "86400") {
6447 print $langs->trans('CronEach')." ".($cron['frequency'])." ".$langs->trans('Days');
6448 }
6449 if ($cron['unitfrequency'] == "604800") {
6450 print $langs->trans('CronEach')." ".($cron['frequency'])." ".$langs->trans('Weeks');
6451 }
6452 print '</td>';
6453
6454 print '<td>';
6455 print $cron['status'];
6456 print '</td>';
6457
6458 print '<td>';
6459 if (!empty($cron['comment'])) {
6460 print $cron['comment'];
6461 }
6462 print '</td>';
6463
6464 print '</tr>';
6465 }
6466 } else {
6467 print '<tr><td colspan="5"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
6468 }
6469
6470 print '</table>';
6471 print '</div>';
6472
6473 print '</form>';
6474 } else {
6475 $fullpathoffile = dol_buildpath($file, 0);
6476
6477 $content = file_get_contents($fullpathoffile);
6478
6479 // New module
6480 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
6481 print '<input type="hidden" name="token" value="'.newToken().'">';
6482 print '<input type="hidden" name="action" value="savefile">';
6483 print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
6484 print '<input type="hidden" name="tab" value="'.$tab.'">';
6485 print '<input type="hidden" name="module" value="'.$module.'">';
6486
6487 $posCursor = (empty($find)) ? array() : array('find' => $find);
6488 $doleditor = new DolEditor('editfilecontent', $content, '', 300, 'Full', 'In', true, false, 'ace', 0, '99%', 0, $posCursor);
6489 print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ? GETPOST('format', 'aZ09') : 'html'));
6490 print '<br>';
6491 print '<center>';
6492 print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
6493 print ' &nbsp; ';
6494 print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
6495 print '</center>';
6496
6497 print '</form>';
6498 }
6499 }
6500
6501 if ($tab == 'specifications') {
6502 print '<!-- tab=specifications -->'."\n";
6503 $specs = dol_dir_list(dol_buildpath($modulelowercase.'/doc', 0), 'files', 1, '(\.md|\.asciidoc)$', array('\/temp\/'));
6504
6505 if ($action != 'editfile' || empty($file)) {
6506 print '<span class="opacitymedium">'.$langs->trans("SpecDefDesc").'</span><br>';
6507 print '<br>';
6508
6509 print '<table>';
6510 if (is_array($specs) && !empty($specs)) {
6511 foreach ($specs as $spec) {
6512 $pathtofile = $modulelowercase.'/doc/'.$spec['relativename'];
6513 $format = 'asciidoc';
6514 if (preg_match('/\.md$/i', $spec['name'])) {
6515 $format = 'markdown';
6516 }
6517 print '<tr><td>';
6518 print '<span class="fa fa-file"></span> '.$langs->trans("SpecificationFile").' : <strong class="wordbreak">'.$pathtofile.'</strong>';
6519 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>';
6520 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>';
6521 print '</tr>';
6522 }
6523 } else {
6524 print '<tr><td>';
6525 print '<span class="fa fa-file"></span> '.$langs->trans("SpecificationFile").' : <span class="opacitymedium">'.$langs->trans("FileNotYetGenerated").'</span>';
6526 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>';
6527 print '</tr>';
6528 }
6529 print '</table>';
6530 } else {
6531 // Use MD or asciidoc
6532
6533 //print $langs->trans("UseAsciiDocFormat").'<br>';
6534
6535 $fullpathoffile = dol_buildpath($file, 0);
6536
6537 $content = file_get_contents($fullpathoffile);
6538
6539 // New module
6540 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
6541 print '<input type="hidden" name="token" value="'.newToken().'">';
6542 print '<input type="hidden" name="action" value="savefile">';
6543 print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
6544 print '<input type="hidden" name="tab" value="'.$tab.'">';
6545 print '<input type="hidden" name="module" value="'.$module.'">';
6546
6547 $doleditor = new DolEditor('editfilecontent', $content, '', 300, 'Full', 'In', true, false, 'ace', 0, '99%');
6548 print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ? GETPOST('format', 'aZ09') : 'html'));
6549 print '<br>';
6550 print '<center>';
6551 print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
6552 print ' &nbsp; ';
6553 print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
6554 print '</center>';
6555
6556 print '</form>';
6557 }
6558
6559 print '<br><br><br>';
6560
6561 $FILENAMEDOC = $modulelowercase.'.html';
6562 $FILENAMEDOCPDF = $modulelowercase.'.pdf';
6563 $outputfiledoc = dol_buildpath($modulelowercase, 0).'/doc/'.$FILENAMEDOC;
6564 $outputfiledocurl = dol_buildpath($modulelowercase, 1).'/doc/'.$FILENAMEDOC;
6565 $outputfiledocrel = $modulelowercase.'/doc/'.$FILENAMEDOC;
6566 $outputfiledocpdf = dol_buildpath($modulelowercase, 0).'/doc/'.$FILENAMEDOCPDF;
6567 $outputfiledocurlpdf = dol_buildpath($modulelowercase, 1).'/doc/'.$FILENAMEDOCPDF;
6568 $outputfiledocrelpdf = $modulelowercase.'/doc/'.$FILENAMEDOCPDF;
6569
6570 // HTML
6571 print '<span class="fa fa-file"></span> '.$langs->trans("PathToModuleDocumentation", "HTML").' : ';
6572 if (!dol_is_file($outputfiledoc)) {
6573 print '<span class="opacitymedium">'.$langs->trans("FileNotYetGenerated").'</span>';
6574 } else {
6575 print '<strong>';
6576 print '<a href="'.$outputfiledocurl.'" target="_blank" rel="noopener noreferrer">';
6577 print $outputfiledoc;
6578 print '</a>';
6579 print '</strong>';
6580 print ' <span class="opacitymedium">('.$langs->trans("GeneratedOn").' '.dol_print_date(dol_filemtime($outputfiledoc), 'dayhour').')</span>';
6581 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>';
6582 }
6583 print '</strong><br>';
6584
6585 // PDF
6586 print '<span class="fa fa-file"></span> '.$langs->trans("PathToModuleDocumentation", "PDF").' : ';
6587 if (!dol_is_file($outputfiledocpdf)) {
6588 print '<span class="opacitymedium">'.$langs->trans("FileNotYetGenerated").'</span>';
6589 } else {
6590 print '<strong>';
6591 print '<a href="'.$outputfiledocurlpdf.'" target="_blank" rel="noopener noreferrer">';
6592 print $outputfiledocpdf;
6593 print '</a>';
6594 print '</strong>';
6595 print ' <span class="opacitymedium">('.$langs->trans("GeneratedOn").' '.dol_print_date(dol_filemtime($outputfiledocpdf), 'dayhour').')</span>';
6596 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>';
6597 }
6598 print '</strong><br>';
6599
6600 print '<br>';
6601
6602 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST" name="generatedoc">';
6603 print '<input type="hidden" name="token" value="'.newToken().'">';
6604 print '<input type="hidden" name="action" value="generatedoc">';
6605 print '<input type="hidden" name="tab" value="'.dol_escape_htmltag($tab).'">';
6606 print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
6607 print '<input type="submit" class="button" name="generatedoc" value="'.$langs->trans("BuildDocumentation").'"';
6608 if (!is_array($specs) || empty($specs)) {
6609 print ' disabled="disabled"';
6610 }
6611 print '>';
6612 print '</form>';
6613 }
6614
6615 if ($tab == 'buildpackage') {
6616 print '<!-- tab=buildpackage -->'."\n";
6617 print '<span class="opacitymedium">'.$langs->trans("BuildPackageDesc").'</span>';
6618 print '<br>';
6619
6620 if (!class_exists('ZipArchive') && !defined('ODTPHP_PATHTOPCLZIP')) {
6621 print img_warning().' '.$langs->trans("ErrNoZipEngine");
6622 print '<br>';
6623 }
6624
6625 $modulelowercase = strtolower($module);
6626
6627 // Zip file to build
6628 $FILENAMEZIP = '';
6629
6630 // Load module
6631 $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
6632 dol_include_once($pathtofile);
6633 $class = 'mod'.$module;
6634 $moduleobj = null;
6635 if (class_exists($class)) {
6636 try {
6637 $moduleobj = new $class($db);
6638 '@phan-var-force DolibarrModules $moduleobj';
6640 } catch (Exception $e) {
6641 $error++;
6642 dol_print_error($db, $e->getMessage());
6643 }
6644 }
6645 if ($moduleobj === null) {
6646 $error++;
6647 $langs->load("errors");
6648 dol_print_error($db, $langs->trans("ErrorFailedToLoadModuleDescriptorForXXX", $module));
6649 exit;
6650 }
6651
6652 $arrayversion = explode('.', $moduleobj->version, 3);
6653 if (count($arrayversion)) {
6654 $FILENAMEZIP = "module_".$modulelowercase.'-'.$arrayversion[0].(empty($arrayversion[1]) ? '.0' : '.'.$arrayversion[1]).(empty($arrayversion[2]) ? '' : ".".$arrayversion[2]).".zip";
6655 $outputfilezip = dol_buildpath($modulelowercase, 0).'/bin/'.$FILENAMEZIP;
6656 }
6657
6658 print '<br>';
6659
6660 print '<span class="fa fa-file"></span> '.$langs->trans("PathToModulePackage").' : ';
6661 if (!dol_is_file($outputfilezip)) {
6662 print '<span class="opacitymedium">'.$langs->trans("FileNotYetGenerated").'</span>';
6663 } else {
6664 $relativepath = $modulelowercase.'/bin/'.$FILENAMEZIP;
6665 print '<strong><a href="'.DOL_URL_ROOT.'/document.php?modulepart=packages&file='.urlencode($relativepath).'">'.$outputfilezip.'</a></strong>';
6666 print ' <span class="opacitymedium">('.$langs->trans("GeneratedOn").' '.dol_print_date(dol_filemtime($outputfilezip), 'dayhour').')</span>';
6667 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>';
6668 }
6669 print '</strong>';
6670
6671 print '<br>';
6672
6673 print '<br>';
6674
6675 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST" name="generatepackage">';
6676 print '<input type="hidden" name="token" value="'.newToken().'">';
6677 print '<input type="hidden" name="action" value="generatepackage">';
6678 print '<input type="hidden" name="tab" value="'.dol_escape_htmltag($tab).'">';
6679 print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
6680 print '<input type="submit" class="button" name="generatepackage" value="'.$langs->trans("BuildPackage").'">';
6681 print '</form>';
6682 }
6683
6684 if ($tab == 'tabs') {
6685 $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
6686
6687 $tabs = $moduleobj->tabs;
6688
6689 if ($action != 'editfile' || empty($file)) {
6690 print '<span class="opacitymedium">';
6691 $htmlhelp = $langs->trans("TabsDefDescTooltip", '{s1}');
6692 $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);
6693 print $form->textwithpicto($langs->trans("TabsDefDesc"), $htmlhelp, 1, 'help', '', 0, 2, 'helpondesc').'<br>';
6694 print '</span>';
6695 print '<br>';
6696
6697 print '<span class="fa fa-file"></span> '.$langs->trans("DescriptorFile").' : <strong>'.$pathtofile.'</strong>';
6698 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>';
6699 print '<br>';
6700
6701 print '<br>';
6702 print load_fiche_titre($langs->trans("ListOfTabsEntries"), '', '');
6703
6704 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
6705 print '<input type="hidden" name="token" value="'.newToken().'">';
6706 print '<input type="hidden" name="action" value="addproperty">';
6707 print '<input type="hidden" name="tab" value="objects">';
6708 print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
6709 print '<input type="hidden" name="tabobj" value="'.dol_escape_htmltag($tabobj).'">';
6710
6711 print '<div class="div-table-responsive">';
6712 print '<table class="noborder small">';
6713
6714 print '<tr class="liste_titre">';
6715 print_liste_field_titre("ObjectType", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
6716 print_liste_field_titre("Tab", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
6717 print_liste_field_titre("Title", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
6718 print_liste_field_titre("LangFile", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
6719 print_liste_field_titre("Condition", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
6720 print_liste_field_titre("Path", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
6721 print "</tr>\n";
6722
6723 if (count($tabs)) {
6724 foreach ($tabs as $tab) {
6725 $parts = explode(':', $tab['data']);
6726
6727 $objectType = $parts[0];
6728 $tabName = $parts[1];
6729 $tabTitle = isset($parts[2]) ? $parts[2] : '';
6730 $langFile = isset($parts[3]) ? $parts[3] : '';
6731 $condition = isset($parts[4]) ? $parts[4] : '';
6732 $path = isset($parts[5]) ? $parts[5] : '';
6733
6734 // If we want to remove the tab, then the format is 'objecttype:tabname:optionalcondition'
6735 // See: https://wiki.dolibarr.org/index.php?title=Tabs_system#To_remove_an_existing_tab
6736 if ($tabName[0] === '-') {
6737 $tabTitle = '';
6738 $condition = isset($parts[2]) ? $parts[2] : '';
6739 }
6740
6741 print '<tr class="oddeven">';
6742
6743 print '<td>';
6744 print dol_escape_htmltag($parts[0]);
6745 print '</td>';
6746
6747 print '<td>';
6748 if ($tabName[0] === "+") {
6749 print '<span class="badge badge-status4 badge-status">' . dol_escape_htmltag($tabName) . '</span>';
6750 } else {
6751 print '<span class="badge badge-status8 badge-status">' . dol_escape_htmltag($tabName) . '</span>';
6752 }
6753 print '</td>';
6754
6755 print '<td>';
6756 print dol_escape_htmltag($tabTitle);
6757 print '</td>';
6758
6759 print '<td>';
6760 print dol_escape_htmltag($langFile);
6761 print '</td>';
6762
6763 print '<td>';
6764 print dol_escape_htmltag($condition);
6765 print '</td>';
6766
6767 print '<td>';
6768 print dol_escape_htmltag($path);
6769 print '</td>';
6770
6771 print '</tr>';
6772 }
6773 } else {
6774 print '<tr><td colspan="5"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
6775 }
6776
6777 print '</table>';
6778 print '</div>';
6779
6780 print '</form>';
6781 } else {
6782 $fullpathoffile = dol_buildpath($file, 0);
6783
6784 $content = file_get_contents($fullpathoffile);
6785
6786 // New module
6787 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
6788 print '<input type="hidden" name="token" value="'.newToken().'">';
6789 print '<input type="hidden" name="action" value="savefile">';
6790 print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
6791 print '<input type="hidden" name="tab" value="'.$tab.'">';
6792 print '<input type="hidden" name="module" value="'.$module.'">';
6793
6794 $posCursor = (empty($find)) ? array() : array('find' => $find);
6795 $doleditor = new DolEditor('editfilecontent', $content, '', 300, 'Full', 'In', true, false, 'ace', 0, '99%', 0, $posCursor);
6796 print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ? GETPOST('format', 'aZ09') : 'html'));
6797 print '<br>';
6798 print '<center>';
6799 print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
6800 print ' &nbsp; ';
6801 print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
6802 print '</center>';
6803
6804 print '</form>';
6805 }
6806 }
6807
6808 if ($tab != 'description') {
6809 print dol_get_fiche_end();
6810 }
6811 }
6812}
6813
6814print dol_get_fiche_end(); // End modules
6815
6816
6817// End of page
6818llxFooter();
6819$db->close();
$id
Definition account.php:48
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
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).
unActivateModule($value, $requiredby=1)
Disable a module.
activateModule($value, $withdeps=1, $noconfverification=0)
Enable a module.
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve', $idforemptyvalue='-1', $morecss='')
Convert a html select field into an ajax combobox.
Definition ajax.lib.php:459
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:87
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:71
print $object position
Definition edit.php:204
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.
Class to manage utility methods.
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_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:63
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.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
dolExplodeIntoArray($string, $delimiter=';', $kv='=')
Split a string with 2 keys into key array.
print_barre_liste($title, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $selectlimitsuffix=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
dol_mimetype($file, $default='application/octet-stream', $mode=0)
Return MIME type of a file from its name with extension.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
dol_osencode($str)
Return a string encoded into OS filesystem encoding.
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.
dolButtonToOpenUrlInDialogPopup($name, $label, $buttonstring, $url, $disabled='', $morecss='classlink button bordertransp', $jsonopen='', $backtopagejsfields='', $accesskey='')
Return HTML code to output a button to open a dialog popup box.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
getPictoForType($key, $morecss='')
Return the picto for a data type.
dolChmod($filepath, $newmask='')
Change mod of a file.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
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'.
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='')
Show information in HTML for admin users or standard users.
img_edit($titlealt='default', $float=0, $other='')
Show logo edit/modify fiche.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_sanitizePathName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a path name.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
a disabled
treeview li table
No Email.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
$moduleobj
Definition index.php:3252
foreach( $dirsrootforscan as $tmpdirread) moduleBuilderShutdownFunction()
Add management to catch fatal errors - shutdown handler.
Definition index.php:238
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.
createNewDictionnary($modulename, $file, $namedic, $dictionnaires=null)
Create a new dictionary table.
countItemsInDirectory($path, $type=1)
count directories or files in modulebuilder folder
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.
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.
rebuildObjectClass($destdir, $module, $objectname, $newmask, $readdir='', $addfieldentry=array(), $delfieldentry='')
Regenerate files .class.php.
reWriteAllPermissions($file, $permissions, $key, $right, $objectname, $module, $action)
Rewriting all permissions after any actions.
checkExistComment($file, $number)
Function to check if comment BEGIN and END exists in modMyModule class.
addObjectsToApiFile($srcfile, $file, $objects, $modulename)
Add Object in ModuleApi File.
$conf db user
Active Directory does not allow anonymous connections.
Definition repair.php:153
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition repair.php:149
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:152
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
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.