dolibarr  13.0.2
index.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2004-2019 Laurent Destailleur <eldy@users.sourceforge.net>
3  * Copyright (C) 2018-2019 Nicolas ZABOURI <info@inovea-conseil.com>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <https://www.gnu.org/licenses/>.
17  *
18  * You can also make a direct call the page with parameter like this:
19  * htdocs/modulebuilder/index.php?module=Inventory@/pathtodolibarr/htdocs/product
20  */
21 
30 if (!defined('NOSCANPOSTFORINJECTION')) define('NOSCANPOSTFORINJECTION', '1'); // Do not check anti SQL+XSS injection attack test
31 
32 require '../main.inc.php';
33 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
34 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
35 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
36 require_once DOL_DOCUMENT_ROOT.'/core/lib/modulebuilder.lib.php';
37 require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
38 require_once DOL_DOCUMENT_ROOT.'/core/class/utils.class.php';
39 
40 // Load translation files required by the page
41 $langs->loadLangs(array("admin", "modulebuilder", "other", "cron", "errors"));
42 
43 $action = GETPOST('action', 'aZ09');
44 $confirm = GETPOST('confirm', 'alpha');
45 $cancel = GETPOST('cancel', 'alpha');
46 
47 $module = GETPOST('module', 'alpha');
48 $tab = GETPOST('tab', 'aZ09');
49 $tabobj = GETPOST('tabobj', 'alpha');
50 $propertykey = GETPOST('propertykey', 'alpha');
51 if (empty($module)) $module = 'initmodule';
52 if (empty($tab)) $tab = 'description';
53 if (empty($tabobj)) $tabobj = 'newobjectifnoobj';
54 $file = GETPOST('file', 'alpha');
55 
56 $modulename = dol_sanitizeFileName(GETPOST('modulename', 'alpha'));
57 $objectname = dol_sanitizeFileName(GETPOST('objectname', 'alpha'));
58 
59 // Security check
60 if (empty($conf->modulebuilder->enabled)) accessforbidden();
61 if (!$user->admin && empty($conf->global->MODULEBUILDER_FOREVERYONE)) accessforbidden($langs->trans('ModuleBuilderNotAllowed'));
62 
63 
64 // Dir for custom dirs
65 $tmp = explode(',', $dolibarr_main_document_root_alt);
66 $dirins = $tmp[0];
67 $dirread = $dirins;
68 $forceddirread = 0;
69 
70 $tmpdir = explode('@', $module);
71 if (!empty($tmpdir[1]))
72 {
73  $module = $tmpdir[0];
74  $dirread = $tmpdir[1];
75  $forceddirread = 1;
76 }
77 if (GETPOST('dirins', 'alpha'))
78 {
79  $dirread = $dirins = GETPOST('dirins', 'alpha');
80  $forceddirread = 1;
81 }
82 
83 $FILEFLAG = 'modulebuilder.txt';
84 
85 $now = dol_now();
86 $newmask = 0;
87 if (empty($newmask) && !empty($conf->global->MAIN_UMASK)) $newmask = $conf->global->MAIN_UMASK;
88 if (empty($newmask)) // This should no happen
89 {
90  $newmask = '0664';
91 }
92 
93 $result = restrictedArea($user, 'modulebuilder', null);
94 
95 $error = 0;
96 
97 $form = new Form($db);
98 
99 // Define $listofmodules
100 $dirsrootforscan = array($dirread);
101 // Add also the core modules into the list of modules to show/edit
102 if ($dirread != DOL_DOCUMENT_ROOT && ($conf->global->MAIN_FEATURES_LEVEL >= 2 || !empty($conf->global->MODULEBUILDER_ADD_DOCUMENT_ROOT))) { $dirsrootforscan[] = DOL_DOCUMENT_ROOT; }
103 
104 // Search modules to edit
105 $textforlistofdirs = '<!-- Directory scanned -->'."\n";
106 $listofmodules = array();
107 $i = 0;
108 foreach ($dirsrootforscan as $dirread)
109 {
110  $moduletype = 'external';
111  if ($dirread == DOL_DOCUMENT_ROOT) {
112  $moduletype = 'internal';
113  }
114 
115  $dirsincustom = dol_dir_list($dirread, 'directories');
116  if (is_array($dirsincustom) && count($dirsincustom) > 0) {
117  foreach ($dirsincustom as $dircustomcursor) {
118  $fullname = $dircustomcursor['fullname'];
119  if (dol_is_file($fullname.'/'.$FILEFLAG))
120  {
121  // Get real name of module (MyModule instead of mymodule)
122  $dirtoscanrel = basename($fullname).'/core/modules/';
123 
124  $descriptorfiles = dol_dir_list(dirname($fullname).'/'.$dirtoscanrel, 'files', 0, 'mod.*\.class\.php$');
125  if (empty($descriptorfiles)) // If descriptor not found into module dir, we look into main module dir.
126  {
127  $dirtoscanrel = 'core/modules/';
128  $descriptorfiles = dol_dir_list($fullname.'/../'.$dirtoscanrel, 'files', 0, 'mod'.strtoupper(basename($fullname)).'\.class\.php$');
129  }
130  $modulenamewithcase = '';
131  $moduledescriptorrelpath = '';
132  $moduledescriptorfullpath = '';
133 
134  foreach ($descriptorfiles as $descriptorcursor) {
135  $modulenamewithcase = preg_replace('/^mod/', '', $descriptorcursor['name']);
136  $modulenamewithcase = preg_replace('/\.class\.php$/', '', $modulenamewithcase);
137  $moduledescriptorrelpath = $dirtoscanrel.$descriptorcursor['name'];
138  $moduledescriptorfullpath = $descriptorcursor['fullname'];
139  //var_dump($descriptorcursor);
140  }
141  if ($modulenamewithcase)
142  {
143  $listofmodules[$dircustomcursor['name']] = array(
144  'modulenamewithcase'=>$modulenamewithcase,
145  'moduledescriptorrelpath'=> $moduledescriptorrelpath,
146  'moduledescriptorfullpath'=>$moduledescriptorfullpath,
147  'moduledescriptorrootpath'=>$dirread,
148  'moduletype'=>$moduletype
149  );
150  }
151  //var_dump($listofmodules);
152  }
153  }
154  }
155 
156  if ($forceddirread && empty($listofmodules)) // $forceddirread is 1 if we forced dir to read with dirins=... or with module=...@mydir
157  {
158  $listofmodules[strtolower($module)] = array(
159  'modulenamewithcase'=>$module,
160  'moduledescriptorrelpath'=> 'notyetimplemented',
161  'moduledescriptorfullpath'=> 'notyetimplemented',
162  'moduledescriptorrootpath'=> 'notyetimplemented',
163  );
164  }
165 
166  // Show description of content
167  $newdircustom = $dirins;
168  if (empty($newdircustom)) $newdircustom = img_warning();
169  // If dirread was forced to somewhere else, by using URL
170  // htdocs/modulebuilder/index.php?module=Inventory@/home/ldestailleur/git/dolibarr/htdocs/product
171  if (empty($i)) $textforlistofdirs .= $langs->trans("DirScanned").' : ';
172  else $textforlistofdirs .= ', ';
173  $textforlistofdirs .= '<strong class="wordbreakimp">'.$dirread.'</strong>';
174  if ($dirread == DOL_DOCUMENT_ROOT) {
175  if ($conf->global->MAIN_FEATURES_LEVEL >= 2) $textforlistofdirs .= $form->textwithpicto('', $langs->trans("ConstantIsOn", "MAIN_FEATURES_LEVEL"));
176  if (!empty($conf->global->MODULEBUILDER_ADD_DOCUMENT_ROOT)) $textforlistofdirs .= $form->textwithpicto('', $langs->trans("ConstantIsOn", "MODULEBUILDER_ADD_DOCUMENT_ROOT"));
177  }
178  $i++;
179 }
180 
181 
182 /*
183  * Actions
184  */
185 
186 if ($dirins && $action == 'initmodule' && $modulename)
187 {
188  $modulename = ucfirst($modulename); // Force first letter in uppercase
189 
190  if (preg_match('/[^a-z0-9_]/i', $modulename))
191  {
192  $error++;
193  setEventMessages($langs->trans("SpaceOrSpecialCharAreNotAllowed"), null, 'errors');
194  }
195 
196  if (!$error)
197  {
198  $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
199  $destdir = $dirins.'/'.strtolower($modulename);
200 
201  $arrayreplacement = array(
202  'mymodule'=>strtolower($modulename),
203  'MyModule'=>$modulename
204  );
205 
206  $result = dolCopyDir($srcdir, $destdir, 0, 0, $arrayreplacement);
207  //dol_mkdir($destfile);
208  if ($result <= 0)
209  {
210  if ($result < 0)
211  {
212  $error++;
213  $langs->load("errors");
214  setEventMessages($langs->trans("ErrorFailToCopyDir", $srcdir, $destdir), null, 'errors');
215  } else {
216  // $result == 0
217  setEventMessages($langs->trans("AllFilesDidAlreadyExist", $srcdir, $destdir), null, 'warnings');
218  }
219  }
220 
221  if (!empty($conf->global->MODULEBUILDER_USE_ABOUT))
222  {
223  dol_delete_file($destdir.'/admin/about.php');
224  }
225 
226  // Delete dir and files that can be generated in sub tabs later if we need them (we want a minimal module first)
227  dol_delete_dir_recursive($destdir.'/build/doxygen');
228  dol_delete_dir_recursive($destdir.'/core/modules/mailings');
229  dol_delete_dir_recursive($destdir.'/core/modules/'.strtolower($modulename).'');
230  dol_delete_dir_recursive($destdir.'/core/tpl');
231  dol_delete_dir_recursive($destdir.'/core/triggers');
232  dol_delete_dir_recursive($destdir.'/doc');
233  dol_delete_dir_recursive($destdir.'/.tx');
234  dol_delete_dir_recursive($destdir.'/core/boxes');
235 
236  dol_delete_file($destdir.'/admin/myobject_extrafields.php');
237 
238  dol_delete_file($destdir.'/sql/data.sql');
239  dol_delete_file($destdir.'/sql/update_x.x.x-y.y.y.sql');
240 
241  dol_delete_file($destdir.'/class/actions_'.strtolower($modulename).'.class.php');
242  dol_delete_file($destdir.'/class/api_'.strtolower($modulename).'.class.php');
243 
244  dol_delete_file($destdir.'/css/'.strtolower($modulename).'.css.php');
245 
246  dol_delete_file($destdir.'/js/'.strtolower($modulename).'.js.php');
247 
248  dol_delete_file($destdir.'/scripts/'.strtolower($modulename).'.php');
249 
250  dol_delete_file($destdir.'/test/phpunit/MyModuleFunctionnalTest.php');
251 
252  // Delete some files related to Object (because the previous dolCopyDir has copied everything)
253  dol_delete_file($destdir.'/myobject_card.php');
254  dol_delete_file($destdir.'/myobject_note.php');
255  dol_delete_file($destdir.'/myobject_document.php');
256  dol_delete_file($destdir.'/myobject_agenda.php');
257  dol_delete_file($destdir.'/myobject_list.php');
258  dol_delete_file($destdir.'/lib/'.strtolower($modulename).'_myobject.lib.php');
259  dol_delete_file($destdir.'/test/phpunit/MyObjectTest.php');
260  dol_delete_file($destdir.'/sql/llx_'.strtolower($modulename).'_myobject.sql');
261  dol_delete_file($destdir.'/sql/llx_'.strtolower($modulename).'_myobject_extrafields.sql');
262  dol_delete_file($destdir.'/sql/llx_'.strtolower($modulename).'_myobject.key.sql');
263  dol_delete_file($destdir.'/sql/llx_'.strtolower($modulename).'_myobject_extrafields.key.sql');
264  dol_delete_file($destdir.'/img/object_myobject.png');
265  dol_delete_file($destdir.'/class/myobject.class.php');
266 
267  dol_delete_dir($destdir.'/class', 1);
268  dol_delete_dir($destdir.'/sql', 1);
269  dol_delete_dir($destdir.'/scripts', 1);
270  dol_delete_dir($destdir.'/js', 1);
271  dol_delete_dir($destdir.'/css', 1);
272  dol_delete_dir($destdir.'/test/phpunit', 1);
273  dol_delete_dir($destdir.'/test', 1);
274  }
275 
276  // Edit PHP files
277  if (!$error)
278  {
279  $listofphpfilestoedit = dol_dir_list($destdir, 'files', 1, '\.(php|MD|js|sql|txt|xml|lang)$', '', 'fullname', SORT_ASC, 0, 1);
280  foreach ($listofphpfilestoedit as $phpfileval)
281  {
282  //var_dump($phpfileval['fullname']);
283  $arrayreplacement = array(
284  'mymodule'=>strtolower($modulename),
285  'MyModule'=>$modulename,
286  'MYMODULE'=>strtoupper($modulename),
287  'My module'=>$modulename,
288  'my module'=>$modulename,
289  'Mon module'=>$modulename,
290  'mon module'=>$modulename,
291  'htdocs/modulebuilder/template'=>strtolower($modulename),
292  '---Put here your own copyright and developer email---'=>dol_print_date($now, '%Y').' '.$user->getFullName($langs).($user->email ? ' <'.$user->email.'>' : '')
293  );
294 
295  if ($conf->global->MAIN_FEATURES_LEVEL >= 2) {
296  if (!empty($conf->global->MODULEBUILDER_SPECIFIC_EDITOR_NAME)) $arrayreplacement['Editor name'] = $conf->global->MODULEBUILDER_SPECIFIC_EDITOR_NAME;
297  if (!empty($conf->global->MODULEBUILDER_SPECIFIC_EDITOR_URL)) $arrayreplacement['https://www.example.com'] = $conf->global->MODULEBUILDER_SPECIFIC_EDITOR_URL;
298  if (!empty($conf->global->MODULEBUILDER_SPECIFIC_AUTHOR)) $arrayreplacement['---Put here your own copyright and developer email---'] = dol_print_date($now, '%Y').' '.$conf->global->MODULEBUILDER_SPECIFIC_AUTHOR;
299  if (!empty($conf->global->MODULEBUILDER_SPECIFIC_VERSION)) $arrayreplacement['1.0'] = $conf->global->MODULEBUILDER_SPECIFIC_VERSION;
300  if (!empty($conf->global->MODULEBUILDER_SPECIFIC_FAMILY)) $arrayreplacement['other'] = $conf->global->MODULEBUILDER_SPECIFIC_FAMILY;
301  }
302 
303  $result = dolReplaceInFile($phpfileval['fullname'], $arrayreplacement);
304  //var_dump($result);
305  if ($result < 0)
306  {
307  setEventMessages($langs->trans("ErrorFailToMakeReplacementInto", $phpfileval['fullname']), null, 'errors');
308  }
309  }
310 
311  if (!empty($conf->global->MODULEBUILDER_SPECIFIC_README))
312  {
313  setEventMessages($langs->trans("ContentOfREADMECustomized"), null, 'warnings');
314  dol_delete_file($destdir.'/README.md');
315  file_put_contents($destdir.'/README.md', $conf->global->MODULEBUILDER_SPECIFIC_README);
316  }
317  }
318 
319  if (!$error)
320  {
321  setEventMessages('ModuleInitialized', null);
322  $module = $modulename;
323  $modulename = '';
324  }
325 }
326 
327 if ($dirins && $action == 'initapi' && !empty($module))
328 {
329  $modulename = ucfirst($module); // Force first letter in uppercase
330  $objectname = $tabobj;
331 
332  dol_mkdir($dirins.'/'.strtolower($module).'/class');
333  $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
334  $srcfile = $srcdir.'/class/api_mymodule.class.php';
335  $destfile = $dirins.'/'.strtolower($module).'/class/api_'.strtolower($module).'.class.php';
336  //var_dump($srcfile);var_dump($destfile);
337  $result = dol_copy($srcfile, $destfile, 0, 0);
338 
339  if ($result > 0)
340  {
341  //var_dump($phpfileval['fullname']);
342  $arrayreplacement = array(
343  'mymodule'=>strtolower($modulename),
344  'MyModule'=>$modulename,
345  'MYMODULE'=>strtoupper($modulename),
346  'My module'=>$modulename,
347  'my module'=>$modulename,
348  'Mon module'=>$modulename,
349  'mon module'=>$modulename,
350  'htdocs/modulebuilder/template'=>strtolower($modulename),
351  'myobject'=>strtolower($objectname),
352  'MyObject'=>$objectname,
353  'MYOBJECT'=>strtoupper($objectname),
354  '---Put here your own copyright and developer email---'=>dol_print_date($now, '%Y').' '.$user->getFullName($langs).($user->email ? ' <'.$user->email.'>' : '')
355  );
356 
357  dolReplaceInFile($destfile, $arrayreplacement);
358  } else {
359  $langs->load("errors");
360  setEventMessages($langs->trans('ErrorFailToCreateFile', $destfile), null, 'errors');
361  }
362 }
363 if ($dirins && $action == 'initphpunit' && !empty($module))
364 {
365  $modulename = ucfirst($module); // Force first letter in uppercase
366  $objectname = $tabobj;
367 
368  dol_mkdir($dirins.'/'.strtolower($module).'/class');
369  $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
370  $srcfile = $srcdir.'/test/phpunit/MyObjectTest.php';
371  $destfile = $dirins.'/'.strtolower($module).'/test/phpunit/'.strtolower($objectname).'Test.php';
372  $result = dol_copy($srcfile, $destfile, 0, 0);
373 
374  if ($result > 0)
375  {
376  //var_dump($phpfileval['fullname']);
377  $arrayreplacement = array(
378  'mymodule'=>strtolower($modulename),
379  'MyModule'=>$modulename,
380  'MYMODULE'=>strtoupper($modulename),
381  'My module'=>$modulename,
382  'my module'=>$modulename,
383  'Mon module'=>$modulename,
384  'mon module'=>$modulename,
385  'htdocs/modulebuilder/template'=>strtolower($modulename),
386  'myobject'=>strtolower($objectname),
387  'MyObject'=>$objectname,
388  'MYOBJECT'=>strtoupper($objectname),
389  '---Put here your own copyright and developer email---'=>dol_print_date($now, '%Y').' '.$user->getFullName($langs).($user->email ? ' <'.$user->email.'>' : '')
390  );
391 
392  dolReplaceInFile($destfile, $arrayreplacement);
393  } else {
394  $langs->load("errors");
395  setEventMessages($langs->trans('ErrorFailToCreateFile', $destfile), null, 'errors');
396  }
397 }
398 if ($dirins && $action == 'initsqlextrafields' && !empty($module)) {
399  $modulename = ucfirst($module); // Force first letter in uppercase
400  $objectname = $tabobj;
401 
402  dol_mkdir($dirins.'/'.strtolower($module).'/sql');
403  $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
404  $srcfile1 = $srcdir.'/sql/llx_mymodule_myobject_extrafields.sql';
405  $destfile1 = $dirins.'/'.strtolower($module).'/sql/llx_'.strtolower($module).'_'.strtolower($objectname).'_extrafields.sql';
406  //var_dump($srcfile);var_dump($destfile);
407  $result1 = dol_copy($srcfile1, $destfile1, 0, 0);
408  $srcfile2 = $srcdir.'/sql/llx_mymodule_myobject_extrafields.key.sql';
409  $destfile2 = $dirins.'/'.strtolower($module).'/sql/llx_'.strtolower($module).'_'.strtolower($objectname).'_extrafields.key.sql';
410  //var_dump($srcfile);var_dump($destfile);
411  $result2 = dol_copy($srcfile2, $destfile2, 0, 0);
412 
413  if ($result1 > 0 && $result2 > 0)
414  {
415  $modulename = ucfirst($module); // Force first letter in uppercase
416 
417  //var_dump($phpfileval['fullname']);
418  $arrayreplacement = array(
419  'mymodule'=>strtolower($modulename),
420  'MyModule'=>$modulename,
421  'MYMODULE'=>strtoupper($modulename),
422  'My module'=>$modulename,
423  'my module'=>$modulename,
424  'Mon module'=>$modulename,
425  'mon module'=>$modulename,
426  'htdocs/modulebuilder/template'=>strtolower($modulename),
427  'My Object'=>$objectname,
428  'MyObject'=>$objectname,
429  'my object'=>strtolower($objectname),
430  'myobject'=>strtolower($objectname),
431  '---Put here your own copyright and developer email---'=>dol_print_date($now, '%Y').' '.$user->getFullName($langs).($user->email ? ' <'.$user->email.'>' : '')
432  );
433 
434  dolReplaceInFile($destfile1, $arrayreplacement);
435  dolReplaceInFile($destfile2, $arrayreplacement);
436  } else {
437  $langs->load("errors");
438  setEventMessages($langs->trans('ErrorFailToCreateFile', ''), null, 'errors');
439  }
440  // TODO Enable in class the property $isextrafieldmanaged = 1
441 }
442 if ($dirins && $action == 'inithook' && !empty($module))
443 {
444  dol_mkdir($dirins.'/'.strtolower($module).'/class');
445  $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
446  $srcfile = $srcdir.'/class/actions_mymodule.class.php';
447  $destfile = $dirins.'/'.strtolower($module).'/class/actions_'.strtolower($module).'.class.php';
448  //var_dump($srcfile);var_dump($destfile);
449  $result = dol_copy($srcfile, $destfile, 0, 0);
450 
451  if ($result > 0)
452  {
453  $modulename = ucfirst($module); // Force first letter in uppercase
454 
455  //var_dump($phpfileval['fullname']);
456  $arrayreplacement = array(
457  'mymodule'=>strtolower($modulename),
458  'MyModule'=>$modulename,
459  'MYMODULE'=>strtoupper($modulename),
460  'My module'=>$modulename,
461  'my module'=>$modulename,
462  'Mon module'=>$modulename,
463  'mon module'=>$modulename,
464  'htdocs/modulebuilder/template'=>strtolower($modulename),
465  '---Put here your own copyright and developer email---'=>dol_print_date($now, '%Y').' '.$user->getFullName($langs).($user->email ? ' <'.$user->email.'>' : '')
466  );
467 
468  dolReplaceInFile($destfile, $arrayreplacement);
469  } else {
470  $langs->load("errors");
471  setEventMessages($langs->trans('ErrorFailToCreateFile', $destfile), null, 'errors');
472  }
473 }
474 if ($dirins && $action == 'inittrigger' && !empty($module))
475 {
476  dol_mkdir($dirins.'/'.strtolower($module).'/core/triggers');
477  $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
478  $srcfile = $srcdir.'/core/triggers/interface_99_modMyModule_MyModuleTriggers.class.php';
479  $destfile = $dirins.'/'.strtolower($module).'/core/triggers/interface_99_mod'.$module.'_'.$module.'Triggers.class.php';
480  //var_dump($srcfile);var_dump($destfile);
481  $result = dol_copy($srcfile, $destfile, 0, 0);
482 
483  if ($result > 0)
484  {
485  $modulename = ucfirst($module); // Force first letter in uppercase
486 
487  //var_dump($phpfileval['fullname']);
488  $arrayreplacement = array(
489  'mymodule'=>strtolower($modulename),
490  'MyModule'=>$modulename,
491  'MYMODULE'=>strtoupper($modulename),
492  'My module'=>$modulename,
493  'my module'=>$modulename,
494  'Mon module'=>$modulename,
495  'mon module'=>$modulename,
496  'htdocs/modulebuilder/template'=>strtolower($modulename),
497  '---Put here your own copyright and developer email---'=>dol_print_date($now, '%Y').' '.$user->getFullName($langs).($user->email ? ' <'.$user->email.'>' : '')
498  );
499 
500  dolReplaceInFile($destfile, $arrayreplacement);
501  } else {
502  $langs->load("errors");
503  setEventMessages($langs->trans('ErrorFailToCreateFile', $destfile), null, 'errors');
504  }
505 }
506 if ($dirins && $action == 'initwidget' && !empty($module))
507 {
508  dol_mkdir($dirins.'/'.strtolower($module).'/core/boxes');
509  $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
510  $srcfile = $srcdir.'/core/boxes/mymodulewidget1.php';
511  $destfile = $dirins.'/'.strtolower($module).'/core/boxes/'.strtolower($module).'widget1.php';
512  //var_dump($srcfile);var_dump($destfile);
513  $result = dol_copy($srcfile, $destfile, 0, 0);
514 
515  if ($result > 0) {
516  $modulename = ucfirst($module); // Force first letter in uppercase
517 
518  //var_dump($phpfileval['fullname']);
519  $arrayreplacement = array(
520  'mymodule'=>strtolower($modulename),
521  'MyModule'=>$modulename,
522  'MYMODULE'=>strtoupper($modulename),
523  'My module'=>$modulename,
524  'my module'=>$modulename,
525  'Mon module'=>$modulename,
526  'mon module'=>$modulename,
527  'htdocs/modulebuilder/template'=>strtolower($modulename),
528  '---Put here your own copyright and developer email---'=>dol_print_date($now, '%Y').' '.$user->getFullName($langs).($user->email ? ' <'.$user->email.'>' : '')
529  );
530 
531  dolReplaceInFile($destfile, $arrayreplacement);
532  } else {
533  $langs->load("errors");
534  setEventMessages($langs->trans('ErrorFailToCreateFile', $destfile), null, 'errors');
535  }
536 }
537 if ($dirins && $action == 'initcss' && !empty($module))
538 {
539  dol_mkdir($dirins.'/'.strtolower($module).'/css');
540  $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
541  $srcfile = $srcdir.'/css/mymodule.css.php';
542  $destfile = $dirins.'/'.strtolower($module).'/css/'.strtolower($module).'.css.php';
543  //var_dump($srcfile);var_dump($destfile);
544  $result = dol_copy($srcfile, $destfile, 0, 0);
545 
546  if ($result > 0)
547  {
548  $modulename = ucfirst($module); // Force first letter in uppercase
549 
550  //var_dump($phpfileval['fullname']);
551  $arrayreplacement = array(
552  'mymodule'=>strtolower($modulename),
553  'MyModule'=>$modulename,
554  'MYMODULE'=>strtoupper($modulename),
555  'My module'=>$modulename,
556  'my module'=>$modulename,
557  'Mon module'=>$modulename,
558  'mon module'=>$modulename,
559  'htdocs/modulebuilder/template'=>strtolower($modulename),
560  '---Put here your own copyright and developer email---'=>dol_print_date($now, '%Y').' '.$user->getFullName($langs).($user->email ? ' <'.$user->email.'>' : ''),
561  );
562 
563  dolReplaceInFile($destfile, $arrayreplacement);
564 
565  // Update descriptor file to uncomment file
566  $srcfile = $dirins.'/'.strtolower($module).'/core/modules/mod'.$module.'.class.php';
567  $arrayreplacement = array('/\/\/\s*\''.preg_quote('/'.strtolower($module).'/css/'.strtolower($module).'.css.php', '/').'\'/' => '\'/'.strtolower($module).'/css/'.strtolower($module).'.css.php\'');
568  dolReplaceInFile($srcfile, $arrayreplacement, '', 0, 0, 1);
569  } else {
570  $langs->load("errors");
571  setEventMessages($langs->trans('ErrorFailToCreateFile', $destfile), null, 'errors');
572  }
573 }
574 
575 if ($dirins && $action == 'initjs' && !empty($module))
576 {
577  dol_mkdir($dirins.'/'.strtolower($module).'/js');
578  $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
579  $srcfile = $srcdir.'/js/mymodule.js.php';
580  $destfile = $dirins.'/'.strtolower($module).'/js/'.strtolower($module).'.js.php';
581  //var_dump($srcfile);var_dump($destfile);
582  $result = dol_copy($srcfile, $destfile, 0, 0);
583 
584  if ($result > 0)
585  {
586  $modulename = ucfirst($module); // Force first letter in uppercase
587 
588  //var_dump($phpfileval['fullname']);
589  $arrayreplacement = array(
590  'mymodule'=>strtolower($modulename),
591  'MyModule'=>$modulename,
592  'MYMODULE'=>strtoupper($modulename),
593  'My module'=>$modulename,
594  'my module'=>$modulename,
595  'Mon module'=>$modulename,
596  'mon module'=>$modulename,
597  'htdocs/modulebuilder/template'=>strtolower($modulename),
598  '---Put here your own copyright and developer email---'=>dol_print_date($now, '%Y').' '.$user->getFullName($langs).($user->email ? ' <'.$user->email.'>' : '')
599  );
600 
601  dolReplaceInFile($destfile, $arrayreplacement);
602 
603  // Update descriptor file to uncomment file
604  $srcfile = $dirins.'/'.strtolower($module).'/core/modules/mod'.$module.'.class.php';
605  $arrayreplacement = array('/\/\/\s*\''.preg_quote('/'.strtolower($module).'/js/'.strtolower($module).'.js.php', '/').'\'/' => '\'/'.strtolower($module).'/js/'.strtolower($module).'.js.php\'');
606  dolReplaceInFile($srcfile, $arrayreplacement, '', 0, 0, 1);
607  } else {
608  $langs->load("errors");
609  setEventMessages($langs->trans('ErrorFailToCreateFile', $destfile), null, 'errors');
610  }
611 }
612 if ($dirins && $action == 'initcli' && !empty($module))
613 {
614  dol_mkdir($dirins.'/'.strtolower($module).'/scripts');
615  $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
616  $srcfile = $srcdir.'/scripts/mymodule.php';
617  $destfile = $dirins.'/'.strtolower($module).'/scripts/'.strtolower($module).'.php';
618  //var_dump($srcfile);var_dump($destfile);
619  $result = dol_copy($srcfile, $destfile, 0, 0);
620 
621  if ($result > 0)
622  {
623  $modulename = ucfirst($module); // Force first letter in uppercase
624 
625  //var_dump($phpfileval['fullname']);
626  $arrayreplacement = array(
627  'mymodule'=>strtolower($modulename),
628  'MyModule'=>$modulename,
629  'MYMODULE'=>strtoupper($modulename),
630  'My module'=>$modulename,
631  'my module'=>$modulename,
632  'Mon module'=>$modulename,
633  'mon module'=>$modulename,
634  'htdocs/modulebuilder/template'=>strtolower($modulename),
635  '__MYCOMPANY_NAME__'=>$mysoc->name,
636  '__KEYWORDS__'=>$modulename,
637  '__USER_FULLNAME__'=>$user->getFullName($langs),
638  '__USER_EMAIL__'=>$user->email,
639  '__YYYY-MM-DD__'=>dol_print_date($now, 'dayrfc'),
640  '---Put here your own copyright and developer email---'=>dol_print_date($now, 'dayrfc').' '.$user->getFullName($langs).($user->email ? ' <'.$user->email.'>' : '')
641  );
642 
643  dolReplaceInFile($destfile, $arrayreplacement);
644  } else {
645  $langs->load("errors");
646  setEventMessages($langs->trans('ErrorFailToCreateFile', $destfile), null, 'errors');
647  }
648 }
649 if ($dirins && $action == 'initdoc' && !empty($module)) {
650  dol_mkdir($dirins.'/'.strtolower($module).'/doc');
651  $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
652  $srcfile = $srcdir.'/doc/Documentation.asciidoc';
653  $destfile = $dirins.'/'.strtolower($module).'/doc/Documentation.asciidoc';
654  //var_dump($srcfile);var_dump($destfile);
655  $result = dol_copy($srcfile, $destfile, 0, 0);
656 
657  if ($result > 0) {
658  $modulename = ucfirst($module); // Force first letter in uppercase
659  $modulelowercase = strtolower($module);
660 
661  //var_dump($phpfileval['fullname']);
662  $arrayreplacement = array(
663  'mymodule'=>strtolower($modulename),
664  'MyModule'=>$modulename,
665  'MYMODULE'=>strtoupper($modulename),
666  'My module'=>$modulename,
667  'my module'=>$modulename,
668  'Mon module'=>$modulename,
669  'mon module'=>$modulename,
670  'htdocs/modulebuilder/template'=>strtolower($modulename),
671  '__MYCOMPANY_NAME__'=>$mysoc->name,
672  '__KEYWORDS__'=>$modulename,
673  '__USER_FULLNAME__'=>$user->getFullName($langs),
674  '__USER_EMAIL__'=>$user->email,
675  '__YYYY-MM-DD__'=>dol_print_date($now, 'dayrfc'),
676  '---Put here your own copyright and developer email---'=>dol_print_date($now, 'dayrfc').' '.$user->getFullName($langs).($user->email ? ' <'.$user->email.'>' : '')
677  );
678 
679  dolReplaceInFile($destfile, $arrayreplacement);
680 
681  // Delete old documentation files
682  $FILENAMEDOC = $modulelowercase.'.html';
683  $FILENAMEDOCPDF = $modulelowercase.'.pdf';
684  $outputfiledoc = dol_buildpath($modulelowercase, 0).'/doc/'.$FILENAMEDOC;
685  $outputfiledocurl = dol_buildpath($modulelowercase, 1).'/doc/'.$FILENAMEDOC;
686  $outputfiledocpdf = dol_buildpath($modulelowercase, 0).'/doc/'.$FILENAMEDOCPDF;
687  $outputfiledocurlpdf = dol_buildpath($modulelowercase, 1).'/doc/'.$FILENAMEDOCPDF;
688 
689  dol_delete_file($outputfiledoc, 0, 0, 0, null, false, 0);
690  dol_delete_file($outputfiledocpdf, 0, 0, 0, null, false, 0);
691  } else {
692  $langs->load("errors");
693  setEventMessages($langs->trans('ErrorFailToCreateFile', $destfile), null, 'errors');
694  }
695 }
696 
697 if ($dirins && $action == 'addlanguage' && !empty($module))
698 {
699  $newlangcode = GETPOST('newlangcode', 'aZ09');
700  $srcfile = $dirins.'/'.strtolower($module).'/langs/en_US';
701  $destfile = $dirins.'/'.strtolower($module).'/langs/'.$newlangcode;
702  $result = dolCopyDir($srcfile, $destfile, 0, 0);
703 }
704 
705 if ($dirins && $action == 'confirm_removefile' && !empty($module))
706 {
707  $relativefilename = dol_sanitizePathName(GETPOST('file', 'none'));
708  if ($relativefilename)
709  {
710  $dirnametodelete = dirname($relativefilename);
711  $filetodelete = $dirins.'/'.$relativefilename;
712  $dirtodelete = $dirins.'/'.$dirnametodelete;
713 
714  $result = dol_delete_file($filetodelete);
715  if (!$result) {
716  setEventMessages($langs->trans("ErrorFailToDeleteFile", basename($filetodelete)), null, 'errors');
717  } else {
718  if (dol_is_dir_empty($dirtodelete)) dol_delete_dir($dirtodelete);
719 
720  // Update descriptor file to comment file
721  if (in_array($tab, array('css', 'js')))
722  {
723  $srcfile = $dirins.'/'.strtolower($module).'/core/modules/mod'.$module.'.class.php';
724  $arrayreplacement = array('/^\s*\''.preg_quote('/'.$relativefilename, '/').'\',*/m'=>' // \'/'.$relativefilename.'\',');
725  dolReplaceInFile($srcfile, $arrayreplacement, '', 0, 0, 1);
726  }
727  }
728  }
729 }
730 
731 // Build the $fields array from SQL table (initfromtablename)
732 if ($dirins && $action == 'initobject' && $module && GETPOST('createtablearray', 'alpha'))
733 {
734  $tablename = GETPOST('initfromtablename', 'alpha');
735  $_results = $db->DDLDescTable($tablename);
736  if (empty($_results))
737  {
738  setEventMessages($langs->trans("ErrorTableNotFound", $tablename), null, 'errors');
739  } else {
760  /*public $fields=array(
761  'rowid' =>array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'index'=>1, 'position'=>1, 'comment'=>'Id'),
762  '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'),
763  'entity' =>array('type'=>'integer', 'label'=>'Entity', 'enabled'=>1, 'visible'=>0, 'default'=>1, 'notnull'=>1, 'index'=>1, 'position'=>20),
764  'label' =>array('type'=>'varchar(255)', 'label'=>'Label', 'enabled'=>1, 'visible'=>1, 'position'=>30, 'searchall'=>1, 'css'=>'minwidth200', 'help'=>'Help text'),
765  'amount' =>array('type'=>'double(24,8)', 'label'=>'Amount', 'enabled'=>1, 'visible'=>1, 'default'=>'null', 'position'=>40, 'searchall'=>0, 'isameasure'=>1, 'help'=>'Help text'),
766  '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'=>'LinkToThirparty'),
767  'description' =>array('type'=>'text', 'label'=>'Descrption', 'enabled'=>1, 'visible'=>0, 'position'=>60),
768  'note_public' =>array('type'=>'html', 'label'=>'NotePublic', 'enabled'=>1, 'visible'=>0, 'position'=>61),
769  'note_private' =>array('type'=>'html', 'label'=>'NotePrivate', 'enabled'=>1, 'visible'=>0, 'position'=>62),
770  'date_creation' =>array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>500),
771  'tms' =>array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>501),
772  //'date_valid' =>array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-2, 'position'=>502),
773  'fk_user_creat' =>array('type'=>'integer', 'label'=>'UserAuthor', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>510),
774  'fk_user_modif' =>array('type'=>'integer', 'label'=>'UserModif', 'enabled'=>1, 'visible'=>-2, 'notnull'=>-1, 'position'=>511),
775  //'fk_user_valid' =>array('type'=>'integer', 'label'=>'UserValidation', 'enabled'=>1, 'visible'=>-1, 'position'=>512),
776  'import_key' =>array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>1, 'visible'=>-2, 'notnull'=>-1, 'index'=>0, 'position'=>1000),
777  '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')),
778  );*/
779 
780  $string = 'public $fields=array('."\n";
781  $string .= "<br>";
782  $i = 10;
783  while ($obj = $db->fetch_object($_results))
784  {
785  // fieldname
786  $fieldname = $obj->Field;
787  // type
788  $type = $obj->Type;
789  if ($type == 'int(11)') $type = 'integer';
790  if ($type == 'float') $type = 'real';
791  if (strstr($type, 'tinyint')) $type = 'integer';
792  if ($obj->Field == 'fk_soc') $type = 'integer:Societe:societe/class/societe.class.php';
793  if (preg_match('/^fk_proj/', $obj->Field)) $type = 'integer:Project:projet/class/project.class.php:1:fk_statut=1';
794  if (preg_match('/^fk_prod/', $obj->Field)) $type = 'integer:Product:product/class/product.class.php:1';
795  if ($obj->Field == 'fk_warehouse') $type = 'integer:Entrepot:product/stock/class/entrepot.class.php';
796  if (preg_match('/^(fk_user|fk_commercial)/', $obj->Field)) $type = 'integer:User:user/class/user.class.php';
797 
798  // notnull
799  $notnull = ($obj->Null == 'YES' ? 0 : 1);
800  if ($fieldname == 'fk_user_modif') $notnull = -1;
801  // label
802  $label = preg_replace('/_/', '', ucfirst($fieldname));
803  if ($fieldname == 'rowid') $label = 'TechnicalID';
804  if ($fieldname == 'import_key') $label = 'ImportId';
805  if ($fieldname == 'fk_soc') $label = 'ThirdParty';
806  if ($fieldname == 'tms') $label = 'DateModification';
807  if ($fieldname == 'datec') $label = 'DateCreation';
808  if ($fieldname == 'date_valid') $label = 'DateValidation';
809  if ($fieldname == 'datev') $label = 'DateValidation';
810  if ($fieldname == 'note_private') $label = 'NotePublic';
811  if ($fieldname == 'note_public') $label = 'NotePrivate';
812  if ($fieldname == 'fk_user_creat') $label = 'UserAuthor';
813  if ($fieldname == 'fk_user_modif') $label = 'UserModif';
814  if ($fieldname == 'fk_user_valid') $label = 'UserValidation';
815  // visible
816  $visible = -1;
817  if ($fieldname == 'entity') $visible = -2;
818  if ($fieldname == 'import_key') $visible = -2;
819  if ($fieldname == 'fk_user_creat') $visible = -2;
820  if ($fieldname == 'fk_user_modif') $visible = -2;
821  if (in_array($fieldname, array('ref_ext', 'model_pdf', 'note_public', 'note_private'))) $visible = 0;
822  // enabled
823  $enabled = 1;
824  // default
825  $default = '';
826  if ($fieldname == 'entity') $default = 1;
827  // position
828  $position = $i;
829  if (in_array($fieldname, array('status', 'statut', 'fk_status', 'fk_statut'))) $position = 500;
830  if ($fieldname == 'import_key') $position = 900;
831  // index
832  $index = 0;
833  if ($fieldname == 'entity') $index = 1;
834 
835  $string .= "'".$obj->Field."' =>array('type'=>'".$type."', 'label'=>'".$label."',";
836  if ($default != '') $string .= " 'default'=>".$default.",";
837  $string .= " 'enabled'=>".$enabled.",";
838  $string .= " 'visible'=>".$visible;
839  if ($notnull) $string .= ", 'notnull'=>".$notnull;
840  if ($fieldname == 'ref') $string .= ", 'showoncombobox'=>1";
841  $string .= ", 'position'=>".$position;
842  if ($index) $string .= ", 'index'=>".$index;
843  $string .= "),\n";
844  $string .= "<br>";
845  $i += 5;
846  }
847  $string .= ');'."\n";
848  $string .= "<br>";
849  print $string;
850  exit;
851  }
852 }
853 
854 if ($dirins && $action == 'initobject' && $module && $objectname)
855 {
856  $objectname = ucfirst($objectname);
857 
858  $dirins = $dirread = $listofmodules[strtolower($module)]['moduledescriptorrootpath'];
859  $moduletype = $listofmodules[strtolower($module)]['moduletype'];
860 
861  if (preg_match('/[^a-z0-9_]/i', $objectname))
862  {
863  $error++;
864  setEventMessages($langs->trans("SpaceOrSpecialCharAreNotAllowed"), null, 'errors');
865  $tabobj = 'newobject';
866  }
867  if (class_exists($objectname)) {
868  // TODO Add a more efficient detection. Scan disk ?
869  $error++;
870  setEventMessages($langs->trans("AnObjectWithThisClassNameAlreadyExists"), null, 'errors');
871  $tabobj = 'newobject';
872  }
873 
874  $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
875  $destdir = $dirins.'/'.strtolower($module);
876 
877  // The dir was not created by init
878  dol_mkdir($destdir.'/class');
879  dol_mkdir($destdir.'/img');
880  dol_mkdir($destdir.'/lib');
881  dol_mkdir($destdir.'/scripts');
882  dol_mkdir($destdir.'/sql');
883 
884  // Scan dir class to find if an object with same name already exists.
885  if (!$error)
886  {
887  $dirlist = dol_dir_list($destdir.'/class', 'files', 0, '\.txt$');
888  $alreadyfound = false;
889  foreach ($dirlist as $key => $val)
890  {
891  $filefound = preg_replace('/\.txt$/', '', $val['name']);
892  if (strtolower($objectname) == strtolower($filefound) && $objectname != $filefound)
893  {
894  $alreadyfound = true;
895  $error++;
896  setEventMessages($langs->trans("AnObjectAlreadyExistWithThisNameAndDiffCase"), null, 'errors');
897  break;
898  }
899  }
900  }
901 
902  if (!$error)
903  {
904  // Copy some files
905  $filetogenerate = array(
906  'myobject_card.php'=>strtolower($objectname).'_card.php',
907  'myobject_note.php'=>strtolower($objectname).'_note.php',
908  'myobject_contact.php'=>strtolower($objectname).'_contact.php',
909  'myobject_document.php'=>strtolower($objectname).'_document.php',
910  'myobject_agenda.php'=>strtolower($objectname).'_agenda.php',
911  'myobject_list.php'=>strtolower($objectname).'_list.php',
912  'admin/myobject_extrafields.php'=>'admin/'.strtolower($objectname).'_extrafields.php',
913  'lib/mymodule_myobject.lib.php'=>'lib/'.strtolower($module).'_'.strtolower($objectname).'.lib.php',
914  //'test/phpunit/MyObjectTest.php'=>'test/phpunit/'.strtolower($objectname).'Test.php',
915  'sql/llx_mymodule_myobject.sql'=>'sql/llx_'.strtolower($module).'_'.strtolower($objectname).'.sql',
916  'sql/llx_mymodule_myobject.key.sql'=>'sql/llx_'.strtolower($module).'_'.strtolower($objectname).'.key.sql',
917  'sql/llx_mymodule_myobject_extrafields.sql'=>'sql/llx_'.strtolower($module).'_'.strtolower($objectname).'_extrafields.sql',
918  'sql/llx_mymodule_myobject_extrafields.key.sql'=>'sql/llx_'.strtolower($module).'_'.strtolower($objectname).'_extrafields.key.sql',
919  //'scripts/mymodule.php'=>'scripts/'.strtolower($objectname).'.php',
920  'img/object_myobject.png'=>'img/object_'.strtolower($objectname).'.png',
921  'class/myobject.class.php'=>'class/'.strtolower($objectname).'.class.php',
922  //'class/api_mymodule.class.php'=>'class/api_'.strtolower($module).'.class.php',
923  );
924 
925  if (GETPOST('includerefgeneration', 'aZ09'))
926  {
927  dol_mkdir($destdir.'/core/modules/'.strtolower($module));
928 
929  $filetogenerate += array(
930  'core/modules/mymodule/mod_myobject_advanced.php'=>'core/modules/'.strtolower($module).'/mod_'.strtolower($objectname).'_advanced.php',
931  'core/modules/mymodule/mod_myobject_standard.php'=>'core/modules/'.strtolower($module).'/mod_'.strtolower($objectname).'_standard.php',
932  'core/modules/mymodule/modules_myobject.php'=>'core/modules/'.strtolower($module).'/modules_'.strtolower($objectname).'.php',
933  );
934  }
935  if (GETPOST('includedocgeneration', 'aZ09'))
936  {
937  dol_mkdir($destdir.'/core/modules/'.strtolower($module));
938  dol_mkdir($destdir.'/core/modules/'.strtolower($module).'/doc');
939 
940  $filetogenerate += array(
941  'core/modules/mymodule/doc/doc_generic_myobject_odt.modules.php'=>'core/modules/'.strtolower($module).'/doc/doc_generic_'.strtolower($objectname).'_odt.modules.php',
942  'core/modules/mymodule/doc/pdf_standard_myobject.modules.php'=>'core/modules/'.strtolower($module).'/doc/pdf_standard_'.strtolower($objectname).'.modules.php'
943  );
944  }
945 
946  foreach ($filetogenerate as $srcfile => $destfile)
947  {
948  $result = dol_copy($srcdir.'/'.$srcfile, $destdir.'/'.$destfile, $newmask, 0);
949  if ($result <= 0)
950  {
951  if ($result < 0)
952  {
953  $error++;
954  $langs->load("errors");
955  setEventMessages($langs->trans("ErrorFailToCopyFile", $srcdir.'/'.$srcfile, $destdir.'/'.$destfile), null, 'errors');
956  } else {
957  // $result == 0
958  setEventMessages($langs->trans("FileAlreadyExists", $destfile), null, 'warnings');
959  }
960  }
961  }
962 
963  // Edit the class 'class/'.strtolower($objectname).'.class.php'
964  if (GETPOST('includerefgeneration', 'aZ09')) {
965  // Replace 'visible'=>1, 'noteditable'=>0, 'default'=>''
966  $arrayreplacement = array(
967  '/\'visible\'=>1,\s*\'noteditable\'=>0,\s*\'default\'=>\'\'/' => "'visible'=>4, 'noteditable'=>1, 'default'=>'(PROV)'"
968  );
969  //var_dump($arrayreplacement);exit;
970  //var_dump($destdir.'/class/'.strtolower($objectname).'.class.php');exit;
971  dolReplaceInFile($destdir.'/class/'.strtolower($objectname).'.class.php', $arrayreplacement, '', 0, 0, 1);
972 
973  $arrayreplacement = array(
974  '/\'models\' => 0,/' => '\'models\' => 1,'
975  );
976  dolReplaceInFile($destdir.'/core/modules/mod'.$module.'.class.php', $arrayreplacement, '', 0, 0, 1);
977  }
978 
979  // Edit the setup file and the card page
980  if (GETPOST('includedocgeneration', 'aZ09')) {
981  // Replace some var init into some files
982  $arrayreplacement = array(
983  '/\$includedocgeneration = 0;/' => '$includedocgeneration = 1;'
984  );
985  dolReplaceInFile($destdir.'/class/'.strtolower($objectname).'.class.php', $arrayreplacement, '', 0, 0, 1);
986  dolReplaceInFile($destdir.'/'.strtolower($objectname).'_card.php', $arrayreplacement, '', 0, 0, 1);
987 
988  $arrayreplacement = array(
989  '/\'models\' => 0,/' => '\'models\' => 1,'
990  );
991 
992  dolReplaceInFile($destdir.'/core/modules/mod'.$module.'.class.php', $arrayreplacement, '', 0, 0, 1);
993  }
994 
995  // TODO Update entries '$myTmpObjects['MyObject']=array('includerefgeneration'=>0, 'includedocgeneration'=>0);'
996 
997 
998  // Scan for object class files
999  $listofobject = dol_dir_list($destdir.'/class', 'files', 0, '\.class\.php$');
1000 
1001  $firstobjectname = '';
1002  foreach ($listofobject as $fileobj)
1003  {
1004  if (preg_match('/^api_/', $fileobj['name'])) continue;
1005  if (preg_match('/^actions_/', $fileobj['name'])) continue;
1006 
1007  $tmpcontent = file_get_contents($fileobj['fullname']);
1008  $reg = array();
1009  if (preg_match('/class\s+([^\s]*)\s+extends\s+CommonObject/ims', $tmpcontent, $reg))
1010  {
1011  $objectnameloop = $reg[1];
1012  if (empty($firstobjectname)) $firstobjectname = $objectnameloop;
1013  }
1014 
1015  // Regenerate left menu entry in descriptor for $objectname
1016  $stringtoadd = "
1017  \$this->menu[\$r++]=array(
1018  // '' if this is a top menu. For left menu, use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode
1019  'fk_menu'=>'fk_mainmenu=mymodule',
1020  // This is a Left menu entry
1021  'type'=>'left',
1022  'titre'=>'List MyObject',
1023  'mainmenu'=>'mymodule',
1024  'leftmenu'=>'mymodule_myobject',
1025  'url'=>'/mymodule/myobject_list.php',
1026  // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
1027  'langs'=>'mymodule@mymodule',
1028  'position'=>1100+\$r,
1029  // Define condition to show or hide menu entry. Use '\$conf->mymodule->enabled' if entry must be visible if module is enabled. Use '\$leftmenu==\'system\'' to show if leftmenu system is selected.
1030  'enabled'=>'\$conf->mymodule->enabled',
1031  // Use 'perms'=>'\$user->rights->mymodule->level1->level2' if you want your menu with a permission rules
1032  'perms'=>'1',
1033  'target'=>'',
1034  // 0=Menu for internal users, 1=external users, 2=both
1035  'user'=>2,
1036  );
1037  \$this->menu[\$r++]=array(
1038  // '' if this is a top menu. For left menu, use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode
1039  'fk_menu'=>'fk_mainmenu=mymodule,fk_leftmenu=mymodule_myobject',
1040  // This is a Left menu entry
1041  'type'=>'left',
1042  'titre'=>'New MyObject',
1043  'mainmenu'=>'mymodule',
1044  'leftmenu'=>'mymodule_myobject',
1045  'url'=>'/mymodule/myobject_card.php?action=create',
1046  // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
1047  'langs'=>'mymodule@mymodule',
1048  'position'=>1100+\$r,
1049  // Define condition to show or hide menu entry. Use '\$conf->mymodule->enabled' if entry must be visible if module is enabled. Use '\$leftmenu==\'system\'' to show if leftmenu system is selected.
1050  'enabled'=>'\$conf->mymodule->enabled',
1051  // Use 'perms'=>'\$user->rights->mymodule->level1->level2' if you want your menu with a permission rules
1052  'perms'=>'1',
1053  'target'=>'',
1054  // 0=Menu for internal users, 1=external users, 2=both
1055  'user'=>2
1056  );\n";
1057  $stringtoadd = preg_replace('/MyObject/', $objectnameloop, $stringtoadd);
1058  $stringtoadd = preg_replace('/mymodule/', strtolower($module), $stringtoadd);
1059  $stringtoadd = preg_replace('/myobject/', strtolower($objectnameloop), $stringtoadd);
1060 
1061  $moduledescriptorfile = $destdir.'/core/modules/mod'.$module.'.class.php';
1062 
1063  // TODO Allow a replace with regex using dolReplaceInFile with param arryreplacementisregex to 1
1064  // TODO Avoid duplicate addition
1065 
1066  dolReplaceInFile($moduledescriptorfile, array('END MODULEBUILDER LEFTMENU MYOBJECT */' => '*/'."\n".$stringtoadd."\n\t\t/* END MODULEBUILDER LEFTMENU MYOBJECT */"));
1067 
1068  // Add module descriptor to list of files to replace "MyObject' string with real name of object.
1069  $filetogenerate[] = 'core/modules/mod'.$module.'.class.php';
1070  }
1071  }
1072 
1073  if (!$error)
1074  {
1075  // Edit PHP files to make replacement
1076  foreach ($filetogenerate as $destfile)
1077  {
1078  $phpfileval['fullname'] = $destdir.'/'.$destfile;
1079 
1080  //var_dump($phpfileval['fullname']);
1081  $arrayreplacement = array(
1082  'mymodule'=>strtolower($module),
1083  'MyModule'=>$module,
1084  'MYMODULE'=>strtoupper($module),
1085  'My module'=>$module,
1086  'my module'=>$module,
1087  'mon module'=>$module,
1088  'Mon module'=>$module,
1089  'htdocs/modulebuilder/template/'=>strtolower($modulename),
1090  'myobject'=>strtolower($objectname),
1091  'MyObject'=>$objectname,
1092  'MYOBJECT'=>strtoupper($objectname)
1093  );
1094 
1095  $result = dolReplaceInFile($phpfileval['fullname'], $arrayreplacement);
1096  //var_dump($result);
1097  if ($result < 0)
1098  {
1099  setEventMessages($langs->trans("ErrorFailToMakeReplacementInto", $phpfileval['fullname']), null, 'errors');
1100  }
1101  }
1102  }
1103 
1104  if (!$error)
1105  {
1106  // Edit the class file to write properties
1107  $object = rebuildObjectClass($destdir, $module, $objectname, $newmask);
1108  if (is_numeric($object) && $object < 0) $error++;
1109  }
1110  if (!$error)
1111  {
1112  // Edit sql with new properties
1113  $result = rebuildObjectSql($destdir, $module, $objectname, $newmask, '', $object);
1114  if ($result < 0) $error++;
1115  }
1116 
1117  if (!$error)
1118  {
1119  setEventMessages($langs->trans('FilesForObjectInitialized', $objectname), null);
1120  $tabobj = $objectname;
1121  }
1122 }
1123 
1124 if ($dirins && ($action == 'droptable' || $action == 'droptableextrafields') && !empty($module) && !empty($tabobj))
1125 {
1126  $objectname = $tabobj;
1127 
1128  $arrayoftables = array();
1129  if ($action == 'droptable') $arrayoftables[] = MAIN_DB_PREFIX.strtolower($module).'_'.strtolower($tabobj);
1130  if ($action == 'droptableextrafields') $arrayoftables[] = MAIN_DB_PREFIX.strtolower($module).'_'.strtolower($tabobj).'_extrafields';
1131 
1132  foreach ($arrayoftables as $tabletodrop)
1133  {
1134  $nb = -1;
1135  $sql = "SELECT COUNT(*) as nb FROM ".$tabletodrop;
1136  $resql = $db->query($sql);
1137  if ($resql)
1138  {
1139  $obj = $db->fetch_object($resql);
1140  if ($obj)
1141  {
1142  $nb = $obj->nb;
1143  }
1144  } else {
1145  if ($db->lasterrno() == 'DB_ERROR_NOSUCHTABLE')
1146  {
1147  setEventMessages($langs->trans("TableDoesNotExists", $tabletodrop), null, 'warnings');
1148  } else {
1149  dol_print_error($db);
1150  }
1151  }
1152  if ($nb == 0)
1153  {
1154  $resql = $db->DDLDropTable($tabletodrop);
1155  //var_dump($resql);
1156  setEventMessages($langs->trans("TableDropped", $tabletodrop), null, 'mesgs');
1157  } elseif ($nb > 0)
1158  {
1159  setEventMessages($langs->trans("TableNotEmptyDropCanceled", $tabletodrop), null, 'warnings');
1160  }
1161  }
1162 }
1163 
1164 if ($dirins && $action == 'addproperty' && !empty($module) && !empty($tabobj))
1165 {
1166  $error = 0;
1167 
1168  $objectname = $tabobj;
1169 
1170  $dirins = $dirread = $listofmodules[strtolower($module)]['moduledescriptorrootpath'];
1171  $moduletype = $listofmodules[strtolower($module)]['moduletype'];
1172 
1173  $srcdir = $dirread.'/'.strtolower($module);
1174  $destdir = $dirins.'/'.strtolower($module);
1175  dol_mkdir($destdir);
1176 
1177  // We click on add property
1178  if (!GETPOST('regenerateclasssql') && !GETPOST('regeneratemissing'))
1179  {
1180  if (!GETPOST('propname', 'aZ09'))
1181  {
1182  $error++;
1183  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Name")), null, 'errors');
1184  }
1185  if (!GETPOST('proplabel', 'alpha'))
1186  {
1187  $error++;
1188  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Label")), null, 'errors');
1189  }
1190  if (!GETPOST('proptype', 'alpha'))
1191  {
1192  $error++;
1193  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Type")), null, 'errors');
1194  }
1195 
1196  if (!$error)
1197  {
1198  $addfieldentry = array(
1199  'name'=>GETPOST('propname', 'aZ09'), 'label'=>GETPOST('proplabel', 'alpha'), 'type'=>GETPOST('proptype', 'alpha'),
1200  'arrayofkeyval'=>GETPOST('proparrayofkeyval', 'restricthtml'), // Example json string '{"0":"Draft","1":"Active","-1":"Cancel"}'
1201  'visible'=>GETPOST('propvisible', 'int'), 'enabled'=>GETPOST('propenabled', 'int'),
1202  'position'=>GETPOST('propposition', 'int'), 'notnull'=>GETPOST('propnotnull', 'int'), 'index'=>GETPOST('propindex', 'int'), 'searchall'=>GETPOST('propsearchall', 'int'),
1203  'isameasure'=>GETPOST('propisameasure', 'int'), 'comment'=>GETPOST('propcomment', 'alpha'), 'help'=>GETPOST('prophelp', 'alpha')
1204  );
1205 
1206  if (!empty($addfieldentry['arrayofkeyval']) && !is_array($addfieldentry['arrayofkeyval']))
1207  {
1208  $addfieldentry['arrayofkeyval'] = json_decode($addfieldentry['arrayofkeyval'], true);
1209  }
1210  }
1211  }
1212 
1213  /*if (GETPOST('regeneratemissing'))
1214  {
1215  setEventMessages($langs->trans("FeatureNotYetAvailable"), null, 'warnings');
1216  $error++;
1217  }*/
1218 
1219  // Edit the class file to write properties
1220  if (!$error)
1221  {
1222  $moduletype = 'external';
1223 
1224  $object = rebuildObjectClass($destdir, $module, $objectname, $newmask, $srcdir, $addfieldentry, $moduletype);
1225  if (is_numeric($object) && $object <= 0)
1226  {
1227  $error++;
1228  }
1229  }
1230 
1231  // Edit sql with new properties
1232  if (!$error)
1233  {
1234  $moduletype = 'external';
1235 
1236  $result = rebuildObjectSql($destdir, $module, $objectname, $newmask, $srcdir, $object, $moduletype);
1237  if ($result <= 0)
1238  {
1239  $error++;
1240  }
1241  }
1242 
1243  if (!$error)
1244  {
1245  setEventMessages($langs->trans('FilesForObjectUpdated', $objectname), null);
1246 
1247  clearstatcache(true);
1248 
1249  // Make a redirect to reload all data
1250  header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=objects&module='.$module.($forceddirread ? '@'.$dirread : '').'&tabobj='.$objectname.'&nocache='.time());
1251 
1252  exit;
1253  }
1254 }
1255 
1256 if ($dirins && $action == 'confirm_deleteproperty' && $propertykey)
1257 {
1258  $objectname = $tabobj;
1259 
1260  $srcdir = $dirread.'/'.strtolower($module);
1261  $destdir = $dirins.'/'.strtolower($module);
1262  dol_mkdir($destdir);
1263 
1264  // Edit the class file to write properties
1265  if (!$error)
1266  {
1267  $object = rebuildObjectClass($destdir, $module, $objectname, $newmask, $srcdir, array(), $propertykey);
1268  if (is_numeric($object) && $object <= 0) $error++;
1269  }
1270 
1271  // Edit sql with new properties
1272  if (!$error)
1273  {
1274  $result = rebuildObjectSql($destdir, $module, $objectname, $newmask, $srcdir, $object);
1275  if ($result <= 0) $error++;
1276  }
1277 
1278  if (!$error)
1279  {
1280  setEventMessages($langs->trans('FilesForObjectUpdated', $objectname), null);
1281 
1282  clearstatcache(true);
1283 
1284  // Make a redirect to reload all data
1285  header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=objects&module='.$module.($forceddirread ? '@'.$dirread : '').'&tabobj='.$objectname);
1286 
1287  exit;
1288  }
1289 }
1290 
1291 if ($dirins && $action == 'confirm_deletemodule')
1292 {
1293  if (preg_match('/[^a-z0-9_]/i', $module))
1294  {
1295  $error++;
1296  setEventMessages($langs->trans("SpaceOrSpecialCharAreNotAllowed"), null, 'errors');
1297  }
1298 
1299  if (!$error)
1300  {
1301  $modulelowercase = strtolower($module);
1302 
1303  // Dir for module
1304  $dir = $dirins.'/'.$modulelowercase;
1305 
1306  $result = dol_delete_dir_recursive($dir);
1307 
1308  if ($result > 0)
1309  {
1310  setEventMessages($langs->trans("DirWasRemoved", $modulelowercase), null);
1311  } else {
1312  setEventMessages($langs->trans("PurgeNothingToDelete"), null, 'warnings');
1313  }
1314  }
1315 
1316  $action = '';
1317  $module = 'deletemodule';
1318 }
1319 
1320 if ($dirins && $action == 'confirm_deleteobject' && $objectname)
1321 {
1322  if (preg_match('/[^a-z0-9_]/i', $objectname))
1323  {
1324  $error++;
1325  setEventMessages($langs->trans("SpaceOrSpecialCharAreNotAllowed"), null, 'errors');
1326  }
1327 
1328  if (!$error)
1329  {
1330  $modulelowercase = strtolower($module);
1331  $objectlowercase = strtolower($objectname);
1332 
1333  // Dir for module
1334  $dir = $dirins.'/'.$modulelowercase;
1335 
1336  // Delete some files
1337  $filetodelete = array(
1338  'myobject_card.php'=>strtolower($objectname).'_card.php',
1339  'myobject_note.php'=>strtolower($objectname).'_note.php',
1340  'myobject_contact.php'=>strtolower($objectname).'_contact.php',
1341  'myobject_document.php'=>strtolower($objectname).'_document.php',
1342  'myobject_agenda.php'=>strtolower($objectname).'_agenda.php',
1343  'myobject_list.php'=>strtolower($objectname).'_list.php',
1344  'admin/myobject_extrafields.php'=>'admin/'.strtolower($objectname).'_extrafields.php',
1345  'lib/mymodule_myobject.lib.php'=>'lib/'.strtolower($module).'_'.strtolower($objectname).'.lib.php',
1346  'test/phpunit/MyObjectTest.php'=>'test/phpunit/'.strtolower($objectname).'Test.php',
1347  'sql/llx_mymodule_myobject.sql'=>'sql/llx_'.strtolower($module).'_'.strtolower($objectname).'.sql',
1348  'sql/llx_mymodule_myobject_extrafields.sql'=>'sql/llx_'.strtolower($module).'_'.strtolower($objectname).'_extrafields.sql',
1349  'sql/llx_mymodule_myobject.key.sql'=>'sql/llx_'.strtolower($module).'_'.strtolower($objectname).'.key.sql',
1350  'sql/llx_mymodule_myobject_extrafields.key.sql'=>'sql/llx_'.strtolower($module).'_'.strtolower($objectname).'_extrafields.key.sql',
1351  'scripts/myobject.php'=>'scripts/'.strtolower($objectname).'.php',
1352  'img/object_myobject.png'=>'img/object_'.strtolower($objectname).'.png',
1353  'class/myobject.class.php'=>'class/'.strtolower($objectname).'.class.php',
1354  'class/api_myobject.class.php'=>'class/api_'.strtolower($module).'.class.php',
1355  'core/modules/mymodule/mod_myobject_advanced.php'=>'core/modules/'.strtolower($module).'/mod_'.strtolower($objectname).'_advanced.php',
1356  'core/modules/mymodule/mod_myobject_standard.php'=>'core/modules/'.strtolower($module).'/mod_'.strtolower($objectname).'_standard.php',
1357  'core/modules/mymodule/modules_myobject.php'=>'core/modules/'.strtolower($module).'/modules_'.strtolower($objectname).'.php',
1358  'core/modules/mymodule/doc/doc_generic_myobject_odt.modules.php'=>'core/modules/'.strtolower($module).'/doc/doc_generic_'.strtolower($objectname).'_odt.modules.php',
1359  'core/modules/mymodule/doc/pdf_standard_myobject.modules.php'=>'core/modules/'.strtolower($module).'/doc/pdf_standard_'.strtolower($objectname).'.modules.php'
1360  );
1361 
1362  $resultko = 0;
1363  foreach ($filetodelete as $filetodelete)
1364  {
1365  $resulttmp = dol_delete_file($dir.'/'.$filetodelete, 0, 0, 1);
1366  $resulttmp = dol_delete_file($dir.'/'.$filetodelete.'.back', 0, 0, 1);
1367  if (!$resulttmp) $resultko++;
1368  }
1369 
1370  if ($resultko == 0)
1371  {
1372  setEventMessages($langs->trans("FilesDeleted"), null);
1373  } else {
1374  setEventMessages($langs->trans("ErrorSomeFilesCouldNotBeDeleted"), null, 'warnings');
1375  }
1376  }
1377 
1378  $action = '';
1379  $tabobj = 'deleteobject';
1380 }
1381 
1382 
1383 if ($dirins && $action == 'generatepackage')
1384 {
1385  $modulelowercase = strtolower($module);
1386 
1387  // Dir for module
1388  $dir = $dirins.'/'.$modulelowercase;
1389  // Zip file to build
1390  $FILENAMEZIP = '';
1391 
1392  // Load module
1393  dol_include_once($modulelowercase.'/core/modules/mod'.$module.'.class.php');
1394  $class = 'mod'.$module;
1395 
1396  if (class_exists($class))
1397  {
1398  try {
1399  $moduleobj = new $class($db);
1400  } catch (Exception $e)
1401  {
1402  $error++;
1403  dol_print_error($e->getMessage());
1404  }
1405  } else {
1406  $error++;
1407  $langs->load("errors");
1408  dol_print_error($langs->trans("ErrorFailedToLoadModuleDescriptorForXXX", $module));
1409  exit;
1410  }
1411 
1412  $arrayversion = explode('.', $moduleobj->version, 3);
1413  if (count($arrayversion))
1414  {
1415  $FILENAMEZIP = "module_".$modulelowercase.'-'.$arrayversion[0].'.'.$arrayversion[1].($arrayversion[2] ? ".".$arrayversion[2] : "").".zip";
1416 
1417  $dirofmodule = dol_buildpath($modulelowercase, 0).'/bin';
1418  $outputfilezip = $dirofmodule.'/'.$FILENAMEZIP;
1419  if ($dirofmodule)
1420  {
1421  if (!dol_is_dir($dirofmodule)) dol_mkdir($dirofmodule);
1422  $result = dol_compress_dir($dir, $outputfilezip, 'zip', '', $modulelowercase);
1423  } else {
1424  $result = -1;
1425  }
1426 
1427  if ($result > 0)
1428  {
1429  setEventMessages($langs->trans("ZipFileGeneratedInto", $outputfilezip), null);
1430  } else {
1431  $error++;
1432  $langs->load("errors");
1433  setEventMessages($langs->trans("ErrorFailToGenerateFile", $outputfilezip), null, 'errors');
1434  }
1435  } else {
1436  $error++;
1437  $langs->load("errors");
1438  setEventMessages($langs->trans("ErrorCheckVersionIsDefined"), null, 'errors');
1439  }
1440 }
1441 
1442 if ($dirins && $action == 'generatedoc')
1443 {
1444  $FILENAMEDOC = strtolower($module).'.html';
1445  $dirofmodule = dol_buildpath(strtolower($module), 0).'/doc';
1446 
1447  $util = new Utils($db);
1448  $result = $util->generateDoc($module);
1449 
1450  if ($result > 0)
1451  {
1452  setEventMessages($langs->trans("DocFileGeneratedInto", $dirofmodule), null);
1453  } else {
1454  setEventMessages($util->error, $util->errors, 'errors');
1455  }
1456 }
1457 
1458 
1459 // Save file
1460 if ($action == 'savefile' && empty($cancel))
1461 {
1462  $relofcustom = basename($dirins);
1463 
1464  if ($relofcustom)
1465  {
1466  // Check that relative path ($file) start with name 'custom'
1467  if (!preg_match('/^'.$relofcustom.'/', $file)) $file = $relofcustom.'/'.$file;
1468 
1469  $pathoffile = dol_buildpath($file, 0);
1470  $pathoffilebackup = dol_buildpath($file.'.back', 0);
1471 
1472  // Save old version
1473  if (dol_is_file($pathoffile))
1474  {
1475  dol_copy($pathoffile, $pathoffilebackup, 0, 1);
1476  }
1477 
1478  $check = 'restricthtml';
1479  $srclang = dol_mimetype($pathoffile, '', 3);
1480  if ($srclang == 'md') $check = 'restricthtml';
1481  if ($srclang == 'lang') $check = 'restricthtml';
1482  if ($srclang == 'php') $check = 'none';
1483 
1484  $content = GETPOST('editfilecontent', $check);
1485 
1486  // Save file on disk
1487  if ($content)
1488  {
1489  dol_delete_file($pathoffile);
1490  $result = file_put_contents($pathoffile, $content);
1491  if ($result)
1492  {
1493  @chmod($pathoffile, octdec($newmask));
1494 
1495  setEventMessages($langs->trans("FileSaved"), null);
1496  } else {
1497  setEventMessages($langs->trans("ErrorFailedToSaveFile"), null, 'errors');
1498  }
1499  } else {
1500  setEventMessages($langs->trans("ContentCantBeEmpty"), null, 'errors');
1501  //$action='editfile';
1502  $error++;
1503  }
1504  }
1505 }
1506 
1507 // Enable module
1508 if ($action == 'set' && $user->admin)
1509 {
1510  $param = '';
1511  if ($module) $param .= '&module='.urlencode($module);
1512  if ($tab) $param .= '&tab='.urlencode($tab);
1513  if ($tabobj) $param .= '&tabobj='.urlencode($tabobj);
1514 
1515  $value = GETPOST('value', 'alpha');
1516  $resarray = activateModule($value);
1517  if (!empty($resarray['errors'])) setEventMessages('', $resarray['errors'], 'errors');
1518  else {
1519  //var_dump($resarray);exit;
1520  if ($resarray['nbperms'] > 0)
1521  {
1522  $tmpsql = "SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX."user WHERE admin <> 1";
1523  $resqltmp = $db->query($tmpsql);
1524  if ($resqltmp)
1525  {
1526  $obj = $db->fetch_object($resqltmp);
1527  //var_dump($obj->nb);exit;
1528  if ($obj && $obj->nb > 1)
1529  {
1530  $msg = $langs->trans('ModuleEnabledAdminMustCheckRights');
1531  setEventMessages($msg, null, 'warnings');
1532  }
1533  } else dol_print_error($db);
1534  }
1535  }
1536  header("Location: ".$_SERVER["PHP_SELF"]."?".$param);
1537  exit;
1538 }
1539 
1540 // Disable module
1541 if ($action == 'reset' && $user->admin)
1542 {
1543  $param = '';
1544  if ($module) $param .= '&module='.urlencode($module);
1545  if ($tab) $param .= '&tab='.urlencode($tab);
1546  if ($tabobj) $param .= '&tabobj='.urlencode($tabobj);
1547 
1548  $value = GETPOST('value', 'alpha');
1549  $result = unActivateModule($value);
1550  if ($result) setEventMessages($result, null, 'errors');
1551  header("Location: ".$_SERVER["PHP_SELF"]."?".$param);
1552  exit;
1553 }
1554 
1555 
1556 
1557 /*
1558  * View
1559  */
1560 
1561 $form = new Form($db);
1562 $formadmin = new FormAdmin($db);
1563 
1564 // Set dir where external modules are installed
1565 if (!dol_is_dir($dirins))
1566 {
1567  dol_mkdir($dirins);
1568 }
1569 $dirins_ok = (dol_is_dir($dirins));
1570 
1571 llxHeader('', $langs->trans("ModuleBuilder"), '', '', 0, 0,
1572  array(
1573  '/includes/ace/src/ace.js',
1574  '/includes/ace/src/ext-statusbar.js',
1575  '/includes/ace/src/ext-language_tools.js',
1576  //'/includes/ace/src/ext-chromevox.js'
1577  ), array(), '', 'classforhorizontalscrolloftabs');
1578 
1579 
1580 $text = $langs->trans("ModuleBuilder");
1581 
1582 print load_fiche_titre($text, '', 'title_setup');
1583 
1584 print '<span class="opacitymedium hideonsmartphone">'.$langs->trans("ModuleBuilderDesc", 'https://wiki.dolibarr.org/index.php/Module_development#Create_your_module').'</span><br>';
1585 
1586 print $textforlistofdirs;
1587 print '<br>';
1588 //var_dump($listofmodules);
1589 
1590 
1591 $message = '';
1592 if (!$dirins)
1593 {
1594  $message = info_admin($langs->trans("ConfFileMustContainCustom", DOL_DOCUMENT_ROOT.'/custom', DOL_DOCUMENT_ROOT));
1595  $allowfromweb = -1;
1596 } else {
1597  if ($dirins_ok)
1598  {
1599  if (!is_writable(dol_osencode($dirins)))
1600  {
1601  $langs->load("errors");
1602  $message = info_admin($langs->trans("ErrorFailedToWriteInDir", $dirins));
1603  $allowfromweb = 0;
1604  }
1605  } else {
1606  $message = info_admin($langs->trans("NotExistsDirect", $dirins).$langs->trans("InfDirAlt").$langs->trans("InfDirExample"));
1607  $allowfromweb = 0;
1608  }
1609 }
1610 if ($message)
1611 {
1612  print $message;
1613 }
1614 
1615 //print $langs->trans("ModuleBuilderDesc3", count($listofmodules), $FILEFLAG).'<br>';
1616 $infomodulesfound = '<div style="padding: 12px 9px 12px">'.$form->textwithpicto('<span class="opacitymedium">'.$langs->trans("ModuleBuilderDesc3", count($listofmodules)).'</span>', $langs->trans("ModuleBuilderDesc4", $FILEFLAG)).'</div>';
1617 
1618 
1619 // Load module descriptor
1620 $error = 0;
1621 $moduleobj = null;
1622 
1623 
1624 if (!empty($module) && $module != 'initmodule' && $module != 'deletemodule')
1625 {
1626  $modulelowercase = strtolower($module);
1627  $loadclasserrormessage = '';
1628 
1629  // Load module
1630  try {
1631  $fullpathdirtodescriptor = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
1632 
1633  //throw(new Exception());
1634  dol_include_once($fullpathdirtodescriptor);
1635 
1636  $class = 'mod'.$module;
1637  } catch (Throwable $e) { // This is called in PHP 7 only. Never called with PHP 5.6
1638  $loadclasserrormessage = $e->getMessage()."<br>\n";
1639  $loadclasserrormessage .= 'File: '.$e->getFile()."<br>\n";
1640  $loadclasserrormessage .= 'Line: '.$e->getLine()."<br>\n";
1641  }
1642 
1643  if (class_exists($class))
1644  {
1645  try {
1646  $moduleobj = new $class($db);
1647  } catch (Exception $e) {
1648  $error++;
1649  print $e->getMessage();
1650  }
1651  } else {
1652  if (empty($forceddirread)) $error++;
1653  $langs->load("errors");
1654  print img_warning('').' '.$langs->trans("ErrorFailedToLoadModuleDescriptorForXXX", $module).'<br>';
1655  print $loadclasserrormessage;
1656  }
1657 }
1658 
1659 print '<br>';
1660 
1661 
1662 // Tabs for all modules
1663 $head = array();
1664 $h = 0;
1665 
1666 $head[$h][0] = $_SERVER["PHP_SELF"].'?module=initmodule';
1667 $head[$h][1] = '<span class="valignmiddle text-plus-circle">'.$langs->trans("NewModule").'</span><span class="fa fa-plus-circle valignmiddle paddingleft"></span>';
1668 $head[$h][2] = 'initmodule';
1669 $h++;
1670 
1671 $linktoenabledisable = '';
1672 $modulestatusinfo = '';
1673 
1674 if (is_array($listofmodules) && count($listofmodules) > 0) {
1675  // Define $linktoenabledisable and $modulestatusinfo
1676  $modulelowercase = strtolower($module);
1677  $const_name = 'MAIN_MODULE_'.strtoupper($module);
1678 
1679  $param = '';
1680  if ($tab) $param .= '&tab='.urlencode($tab);
1681  if ($module) $param .= '&module='.urlencode($module);
1682  if ($tabobj) $param .= '&tabobj='.urlencode($tabobj);
1683 
1684  $urltomodulesetup = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?search_keyword='.urlencode($module).'">'.$langs->trans('Home').'-'.$langs->trans("Setup").'-'.$langs->trans("Modules").'</a>';
1685  if (!empty($conf->global->$const_name)) // If module is already activated
1686  {
1687  $linktoenabledisable .= '<a class="reposition asetresetmodule valignmiddle" href="'.$_SERVER["PHP_SELF"].'?id='.$moduleobj->numero.'&action=reset&value=mod'.$module.$param.'">';
1688  $linktoenabledisable .= img_picto($langs->trans("Activated"), 'switch_on', '', false, 0, 0, '', '', 1);
1689  $linktoenabledisable .= '</a>';
1690 
1691  $objMod = $moduleobj;
1692  $backtourlparam = '';
1693  $backtourlparam .= ($backtourlparam ? '&' : '?').'module='.$module; // No urlencode here, done later
1694  if ($tab) $backtourlparam .= ($backtourlparam ? '&' : '?').'tab='.$tab; // No urlencode here, done later
1695  $backtourl = $_SERVER["PHP_SELF"].$backtourlparam;
1696 
1697  $regs = array();
1698  if (is_array($objMod->config_page_url))
1699  {
1700  $i = 0;
1701  foreach ($objMod->config_page_url as $page)
1702  {
1703  $urlpage = $page;
1704  if ($i++)
1705  {
1706  $linktoenabledisable .= ' <a href="'.$urlpage.'" title="'.$langs->trans($page).'">'.img_picto(ucfirst($page), "setup").'</a>';
1707  // print '<a href="'.$page.'">'.ucfirst($page).'</a>&nbsp;';
1708  } else {
1709  if (preg_match('/^([^@]+)@([^@]+)$/i', $urlpage, $regs))
1710  {
1711  $urltouse = dol_buildpath('/'.$regs[2].'/admin/'.$regs[1], 1);
1712  $linktoenabledisable .= ' &nbsp; <a href="'.$urltouse.(preg_match('/\?/', $urltouse) ? '&' : '?').'save_lastsearch_values=1&backtopage='.urlencode($backtourl).'" title="'.$langs->trans("Setup").'">'.img_picto($langs->trans("Setup"), "setup", 'style="padding-right: 6px"').'</a>';
1713  } else {
1714  $urltouse = $urlpage;
1715  $linktoenabledisable .= ' &nbsp; <a href="'.$urltouse.(preg_match('/\?/', $urltouse) ? '&' : '?').'save_lastsearch_values=1&backtopage='.urlencode($backtourl).'" title="'.$langs->trans("Setup").'">'.img_picto($langs->trans("Setup"), "setup", 'style="padding-right: 6px"').'</a>';
1716  }
1717  }
1718  }
1719  } elseif (preg_match('/^([^@]+)@([^@]+)$/i', $objMod->config_page_url, $regs)) {
1720  $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: 6px"').'</a>';
1721  }
1722  } else {
1723  $linktoenabledisable .= '<a class="reposition asetresetmodule valignmiddle" href="'.$_SERVER["PHP_SELF"].'?id='.$moduleobj->numero.'&action=set&token='.newToken().'&value=mod'.$module.$param.'">';
1724  $linktoenabledisable .= img_picto($langs->trans("ModuleIsNotActive", $urltomodulesetup), 'switch_off', '', false, 0, 0, '', 'classfortooltip', 1);
1725  $linktoenabledisable .= "</a>\n";
1726  }
1727 
1728  if (!empty($conf->$modulelowercase->enabled))
1729  {
1730  $modulestatusinfo = $form->textwithpicto('', $langs->trans("Warning").' : '.$langs->trans("ModuleIsLive"), -1, 'warning');
1731  }
1732 
1733  // Loop to show tab of each module
1734  foreach ($listofmodules as $tmpmodule => $tmpmodulearray)
1735  {
1736  $head[$h][0] = $_SERVER["PHP_SELF"].'?module='.$tmpmodulearray['modulenamewithcase'].($forceddirread ? '@'.$dirread : '');
1737  $head[$h][1] = $tmpmodulearray['modulenamewithcase'];
1738  $head[$h][2] = $tmpmodulearray['modulenamewithcase'];
1739 
1740  /*if ($tmpmodule == $modulelowercase) {
1741  $head[$h][1] .= ' '.$modulestatusinfo;
1742  $head[$h][1] .= ' '.$linktoenabledisable;
1743  }*/
1744 
1745  $h++;
1746  }
1747 }
1748 
1749 $head[$h][0] = $_SERVER["PHP_SELF"].'?module=deletemodule';
1750 $head[$h][1] = $langs->trans("DangerZone");
1751 $head[$h][2] = 'deletemodule';
1752 $h++;
1753 
1754 print dol_get_fiche_head($head, $module, '', -1, '', 0, $infomodulesfound, '', 8); // Modules
1755 
1756 if ($module == 'initmodule')
1757 {
1758  // New module
1759  print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
1760  print '<input type="hidden" name="token" value="'.newToken().'">';
1761  print '<input type="hidden" name="action" value="initmodule">';
1762  print '<input type="hidden" name="module" value="initmodule">';
1763 
1764  //print '<span class="opacitymedium">'.$langs->trans("ModuleBuilderDesc2", 'conf/conf.php', $newdircustom).'</span><br>';
1765  print $langs->trans("EnterNameOfModuleDesc").'<br>';
1766  print '<br>';
1767 
1768  print '<input type="text" name="modulename" value="'.dol_escape_htmltag($modulename).'" placeholder="'.dol_escape_htmltag($langs->trans("ModuleKey")).'"><br>';
1769 
1770  print '<br><input type="submit" class="button" name="create" value="'.dol_escape_htmltag($langs->trans("Create")).'"'.($dirins ? '' : ' disabled="disabled"').'>';
1771  print '</form>';
1772 } elseif ($module == 'deletemodule') {
1773  print '<!-- Form to init a module -->'."\n";
1774  print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST" name="delete">';
1775  print '<input type="hidden" name="token" value="'.newToken().'">';
1776  print '<input type="hidden" name="action" value="confirm_deletemodule">';
1777  print '<input type="hidden" name="module" value="deletemodule">';
1778 
1779  print $langs->trans("EnterNameOfModuleToDeleteDesc").'<br><br>';
1780 
1781  print '<input type="text" name="module" placeholder="'.dol_escape_htmltag($langs->trans("ModuleKey")).'" value="">';
1782  print '<input type="submit" class="button smallpaddingimp" value="'.$langs->trans("Delete").'"'.($dirins ? '' : ' disabled="disabled"').'>';
1783  print '</form>';
1784 } elseif (!empty($module)) {
1785  // Tabs for module
1786  if (!$error)
1787  {
1788  $dirread = $listofmodules[strtolower($module)]['moduledescriptorrootpath'];
1789 
1790  $head2 = array();
1791  $h = 0;
1792 
1793  $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=description&module='.$module.($forceddirread ? '@'.$dirread : '');
1794  $head2[$h][1] = $langs->trans("Description");
1795  $head2[$h][2] = 'description';
1796  $h++;
1797 
1798  $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=languages&module='.$module.($forceddirread ? '@'.$dirread : '');
1799  $head2[$h][1] = $langs->trans("Languages");
1800  $head2[$h][2] = 'languages';
1801  $h++;
1802 
1803  $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=dictionaries&module='.$module.($forceddirread ? '@'.$dirread : '');
1804  $head2[$h][1] = $langs->trans("Dictionaries");
1805  $head2[$h][2] = 'dictionaries';
1806  $h++;
1807 
1808  $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=objects&module='.$module.($forceddirread ? '@'.$dirread : '');
1809  $head2[$h][1] = $langs->trans("Objects");
1810  $head2[$h][2] = 'objects';
1811  $h++;
1812 
1813  $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=permissions&module='.$module.($forceddirread ? '@'.$dirread : '');
1814  $head2[$h][1] = $langs->trans("Permissions");
1815  $head2[$h][2] = 'permissions';
1816  $h++;
1817 
1818  $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=menus&module='.$module.($forceddirread ? '@'.$dirread : '');
1819  $head2[$h][1] = $langs->trans("Menus");
1820  $head2[$h][2] = 'menus';
1821  $h++;
1822 
1823  $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=hooks&module='.$module.($forceddirread ? '@'.$dirread : '');
1824  $head2[$h][1] = $langs->trans("Hooks");
1825  $head2[$h][2] = 'hooks';
1826  $h++;
1827 
1828  $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=triggers&module='.$module.($forceddirread ? '@'.$dirread : '');
1829  $head2[$h][1] = $langs->trans("Triggers");
1830  $head2[$h][2] = 'triggers';
1831  $h++;
1832 
1833  $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=widgets&module='.$module.($forceddirread ? '@'.$dirread : '');
1834  $head2[$h][1] = $langs->trans("Widgets");
1835  $head2[$h][2] = 'widgets';
1836  $h++;
1837 
1838  $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=css&module='.$module.($forceddirread ? '@'.$dirread : '');
1839  $head2[$h][1] = $langs->trans("CSS");
1840  $head2[$h][2] = 'css';
1841  $h++;
1842 
1843  $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=js&module='.$module.($forceddirread ? '@'.$dirread : '');
1844  $head2[$h][1] = $langs->trans("JS");
1845  $head2[$h][2] = 'js';
1846  $h++;
1847 
1848  $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=cli&module='.$module.($forceddirread ? '@'.$dirread : '');
1849  $head2[$h][1] = $langs->trans("CLI");
1850  $head2[$h][2] = 'cli';
1851  $h++;
1852 
1853  $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=cron&module='.$module.($forceddirread ? '@'.$dirread : '');
1854  $head2[$h][1] = $langs->trans("CronList");
1855  $head2[$h][2] = 'cron';
1856  $h++;
1857 
1858  $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=specifications&module='.$module.($forceddirread ? '@'.$dirread : '');
1859  $head2[$h][1] = $langs->trans("Documentation");
1860  $head2[$h][2] = 'specifications';
1861  $h++;
1862 
1863  $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=buildpackage&module='.$module.($forceddirread ? '@'.$dirread : '');
1864  $head2[$h][1] = $langs->trans("BuildPackage");
1865  $head2[$h][2] = 'buildpackage';
1866  $h++;
1867 
1868  // Link to enable / disable
1869  print '<div class="center">'.$modulestatusinfo;
1870  print ' '.$linktoenabledisable.'</div>';
1871 
1872  print '<br>';
1873 
1874  // Note module is inside $dirread
1875 
1876  if ($tab == 'description')
1877  {
1878  $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
1879  $pathtofilereadme = $modulelowercase.'/README.md';
1880  $pathtochangelog = $modulelowercase.'/ChangeLog.md';
1881 
1882  if ($action != 'editfile' || empty($file))
1883  {
1884  print dol_get_fiche_head($head2, $tab, '', -1, '', 0, '', '', 0, 'formodulesuffix'); // Description - level 2
1885 
1886  print '<span class="opacitymedium">'.$langs->trans("ModuleBuilderDesc".$tab).'</span>';
1887  $infoonmodulepath = '';
1888  if (realpath($dirread.'/'.$modulelowercase) != $dirread.'/'.$modulelowercase)
1889  {
1890  $infoonmodulepath = '<span class="opacitymedium">'.$langs->trans("RealPathOfModule").' :</span> <strong>'.realpath($dirread.'/'.$modulelowercase).'</strong><br>';
1891  print ' '.$infoonmodulepath;
1892  }
1893  print '<br>';
1894 
1895  print '<table>';
1896 
1897  print '<tr><td>';
1898  print '<span class="fa fa-file-o"></span> '.$langs->trans("DescriptorFile").' : <strong>'.$pathtofile.'</strong>';
1899  print '</td><td><a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&format=php&file='.urlencode($pathtofile).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
1900  print '</td></tr>';
1901 
1902  print '<tr><td><span class="fa fa-file-o"></span> '.$langs->trans("ReadmeFile").' : <strong>'.$pathtofilereadme.'</strong>';
1903  print '</td><td><a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&format=markdown&file='.urlencode($pathtofilereadme).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
1904  print '</td></tr>';
1905 
1906  print '<tr><td><span class="fa fa-file-o"></span> '.$langs->trans("ChangeLog").' : <strong>'.$pathtochangelog.'</strong>';
1907  print '</td><td><a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&format=markdown&file='.urlencode($pathtochangelog).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
1908  print '</td></tr>';
1909 
1910  print '</table>';
1911  print '<br>';
1912 
1913  print load_fiche_titre($langs->trans("DescriptorFile"), '', '');
1914 
1915  if (!empty($moduleobj))
1916  {
1917  print '<div class="underbanner clearboth"></div>';
1918  print '<div class="fichecenter">';
1919 
1920  print '<table class="border centpercent">';
1921  print '<tr class="liste_titre"><td class="titlefield">';
1922  print $langs->trans("Parameter");
1923  print '</td><td>';
1924  print $langs->trans("Value");
1925  print '</td></tr>';
1926 
1927  print '<tr><td>';
1928  print $langs->trans("Numero");
1929  print '</td><td>';
1930  print $moduleobj->numero;
1931  print ' &nbsp; (<a href="'.DOL_URL_ROOT.'/admin/system/modules.php?mainmenu=home&leftmenu=admintools_info" target="_blank">'.$langs->trans("SeeIDsInUse").'</a>';
1932  print ' - <a href="https://wiki.dolibarr.org/index.php/List_of_modules_id" target="_blank">'.$langs->trans("SeeReservedIDsRangeHere").'</a>)';
1933  print '</td></tr>';
1934 
1935  print '<tr><td>';
1936  print $langs->trans("Name");
1937  print '</td><td>';
1938  print $moduleobj->getName();
1939  print '</td></tr>';
1940 
1941  print '<tr><td>';
1942  print $langs->trans("Version");
1943  print '</td><td>';
1944  print $moduleobj->getVersion();
1945  print '</td></tr>';
1946 
1947  print '<tr><td>';
1948  print $langs->trans("Family");
1949  //print "<br>'crm','financial','hr','projects','products','ecm','technic','interface','other'";
1950  print '</td><td>';
1951  print $moduleobj->family;
1952  print '</td></tr>';
1953 
1954  print '<tr><td>';
1955  print $langs->trans("EditorName");
1956  print '</td><td>';
1957  print $moduleobj->editor_name;
1958  print '</td></tr>';
1959 
1960  print '<tr><td>';
1961  print $langs->trans("EditorUrl");
1962  print '</td><td>';
1963  print $moduleobj->editor_url;
1964  print '</td></tr>';
1965 
1966  print '<tr><td>';
1967  print $langs->trans("Description");
1968  print '</td><td>';
1969  print $moduleobj->getDesc();
1970  print '</td></tr>';
1971 
1972  print '</table>';
1973  } else {
1974  print $langs->trans("ErrorFailedToLoadModuleDescriptorForXXX", $module).'<br>';
1975  }
1976 
1977  if (!empty($moduleobj))
1978  {
1979  print '<br><br>';
1980 
1981  // Readme file
1982  print load_fiche_titre($langs->trans("ReadmeFile"), '', '');
1983 
1984  print '<!-- readme file -->';
1985  if (dol_is_file($dirread.'/'.$pathtofilereadme)) print '<div class="underbanner clearboth"></div><div class="fichecenter">'.$moduleobj->getDescLong().'</div>';
1986  else print '<span class="opacitymedium">'.$langs->trans("ErrorFileNotFound", $pathtofilereadme).'</span>';
1987 
1988  print '<br><br>';
1989 
1990  // ChangeLog
1991  print load_fiche_titre($langs->trans("ChangeLog"), '', '');
1992 
1993  print '<!-- changelog file -->';
1994  if (dol_is_file($dirread.'/'.$pathtochangelog)) print '<div class="underbanner clearboth"></div><div class="fichecenter">'.$moduleobj->getChangeLog().'</div>';
1995  else print '<span class="opacitymedium">'.$langs->trans("ErrorFileNotFound", $pathtochangelog).'</span>';
1996  }
1997 
1998  print dol_get_fiche_end();
1999  } else { // Edit text file
2000  $fullpathoffile = dol_buildpath($file, 0, 1); // Description - level 2
2001 
2002  if ($fullpathoffile)
2003  {
2004  $content = file_get_contents($fullpathoffile);
2005  }
2006 
2007  // New module
2008  print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
2009  print '<input type="hidden" name="token" value="'.newToken().'">';
2010  print '<input type="hidden" name="action" value="savefile">';
2011  print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
2012  print '<input type="hidden" name="tab" value="'.$tab.'">';
2013  print '<input type="hidden" name="module" value="'.$module.'">';
2014 
2015  print dol_get_fiche_head($head2, $tab, '', -1, '', 0, '', '', 0, 'formodulesuffix');
2016 
2017  $doleditor = new DolEditor('editfilecontent', $content, '', '300', 'Full', 'In', true, false, 'ace', 0, '99%', '');
2018  print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ?GETPOST('format', 'aZ09') : 'html'));
2019 
2020  print dol_get_fiche_end();
2021 
2022  print '<center>';
2023  print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
2024  print ' &nbsp; ';
2025  print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
2026  print '</center>';
2027 
2028  print '</form>';
2029  }
2030  } else {
2031  print dol_get_fiche_head($head2, $tab, '', -1, '', 0, '', '', 0, 'formodulesuffix'); // Level 2
2032  }
2033 
2034  if ($tab == 'languages')
2035  {
2036  if ($action != 'editfile' || empty($file))
2037  {
2038  print '<span class="opacitymedium">'.$langs->trans("LanguageDefDesc").'</span><br>';
2039  print '<br>';
2040 
2041 
2042  print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
2043  print '<input type="hidden" name="token" value="'.newToken().'">';
2044  print '<input type="hidden" name="action" value="addlanguage">';
2045  print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
2046  print '<input type="hidden" name="tab" value="'.$tab.'">';
2047  print '<input type="hidden" name="module" value="'.$module.'">';
2048  print $formadmin->select_language($conf->global->MAIN_LANG_DEFAULT, 'newlangcode', 0, 0, 1, 0, 0, 'minwidth300', 1);
2049  print '<input type="submit" name="addlanguage" class="button" value="'.dol_escape_htmltag($langs->trans("AddLanguageFile")).'"><br>';
2050  print '</form>';
2051 
2052  print '<br>';
2053  print '<br>';
2054 
2055  $langfiles = dol_dir_list(dol_buildpath($modulelowercase.'/langs', 0), 'files', 1, '\.lang$');
2056 
2057  print '<table class="none">';
2058  foreach ($langfiles as $langfile)
2059  {
2060  $pathtofile = $modulelowercase.'/langs/'.$langfile['relativename'];
2061  print '<tr><td><span class="fa fa-file-o"></span> '.$langs->trans("LanguageFile").' '.basename(dirname($pathtofile)).' : <strong>'.$pathtofile.'</strong>';
2062  print '</td><td><a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&format=txt&file='.urlencode($pathtofile).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
2063  print '</td><td><a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=confirm_removefile&file='.urlencode($pathtofile).'">'.img_picto($langs->trans("Delete"), 'delete').'</a>';
2064  print '</td>';
2065  }
2066  print '</table>';
2067  } else {
2068  // Edit text language file
2069 
2070  //print $langs->trans("UseAsciiDocFormat").'<br>';
2071 
2072  $fullpathoffile = dol_buildpath($file, 0);
2073 
2074  $content = file_get_contents($fullpathoffile);
2075 
2076  // New module
2077  print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
2078  print '<input type="hidden" name="token" value="'.newToken().'">';
2079  print '<input type="hidden" name="action" value="savefile">';
2080  print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
2081  print '<input type="hidden" name="tab" value="'.$tab.'">';
2082  print '<input type="hidden" name="module" value="'.$module.'">';
2083 
2084  $doleditor = new DolEditor('editfilecontent', $content, '', '300', 'Full', 'In', true, false, 'ace', 0, '99%');
2085  print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ?GETPOST('format', 'aZ09') : 'text'));
2086  print '<br>';
2087  print '<center>';
2088  print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
2089  print ' &nbsp; ';
2090  print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
2091  print '</center>';
2092 
2093  print '</form>';
2094  }
2095  }
2096 
2097  if ($tab == 'dictionaries')
2098  {
2099  $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
2100 
2101  $dicts = $moduleobj->dictionaries;
2102 
2103  if ($action != 'editfile' || empty($file))
2104  {
2105  print '<span class="opacitymedium">';
2106  $htmlhelp = $langs->trans("DictionariesDefDescTooltip", '<a href="'.DOL_URL_ROOT.'/admin/dict.php">'.$langs->trans('Setup').' - '.$langs->trans('Dictionaries').'</a>');
2107  print $form->textwithpicto($langs->trans("DictionariesDefDesc"), $htmlhelp, 1, 'help', '', 0, 2, 'helpondesc').'<br>';
2108  print '</span>';
2109  print '<br>';
2110 
2111  print '<span class="fa fa-file-o"></span> '.$langs->trans("DescriptorFile").' : <strong>'.$pathtofile.'</strong>';
2112  print ' <a class="editfielda paddingleft paddingright" href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&format=php&file='.urlencode($pathtofile).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
2113  print '<br>';
2114  if (is_array($dicts) && !empty($dicts)) {
2115  print '<span class="fa fa-file-o"></span> '.$langs->trans("LanguageFile").' :</span> ';
2116  print '<strong>'.$dicts['langs'].'</strong>';
2117  print '<br>';
2118  }
2119 
2120  print load_fiche_titre($langs->trans("ListOfDictionariesEntries"), '', '');
2121 
2122  print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
2123  print '<input type="hidden" name="token" value="'.newToken().'">';
2124  print '<input type="hidden" name="action" value="addproperty">';
2125  print '<input type="hidden" name="tab" value="objects">';
2126  print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
2127  print '<input type="hidden" name="tabobj" value="'.dol_escape_htmltag($tabobj).'">';
2128 
2129  print '<div class="div-table-responsive">';
2130  print '<table class="noborder">';
2131 
2132  print '<tr class="liste_titre">';
2133  print_liste_field_titre("#", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
2134  print_liste_field_titre("Table", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
2135  print_liste_field_titre("Label", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
2136  print_liste_field_titre("SQL", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
2137  print_liste_field_titre("SQLSort", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
2138  print_liste_field_titre("FieldsView", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
2139  print_liste_field_titre("FieldsEdit", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
2140  print_liste_field_titre("FieldsInsert", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
2141  print_liste_field_titre("Rowid", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
2142  print_liste_field_titre("Condition", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
2143  print "</tr>\n";
2144 
2145  if (is_array($dicts) && is_array($dicts['tabname']))
2146  {
2147  $i = 0;
2148  $maxi = count($dicts['tabname']);
2149  while ($i < $maxi)
2150  {
2151  print '<tr class="oddeven">';
2152 
2153  print '<td>';
2154  print ($i + 1);
2155  print '</td>';
2156 
2157  print '<td>';
2158  print $dicts['tabname'][$i];
2159  print '</td>';
2160 
2161  print '<td>';
2162  print $dicts['tablib'][$i];
2163  print '</td>';
2164 
2165  print '<td>';
2166  print $dicts['tabsql'][$i];
2167  print '</td>';
2168 
2169  print '<td>';
2170  print $dicts['tabsqlsort'][$i];
2171  print '</td>';
2172 
2173  print '<td>';
2174  print $dicts['tabfield'][$i];
2175  print '</td>';
2176 
2177  print '<td>';
2178  print $dicts['tabfieldvalue'][$i];
2179  print '</td>';
2180 
2181  print '<td>';
2182  print $dicts['tabfieldinsert'][$i];
2183  print '</td>';
2184 
2185  print '<td class="right">';
2186  print $dicts['tabrowid'][$i];
2187  print '</td>';
2188 
2189  print '<td class="right">';
2190  print $dicts['tabcond'][$i];
2191  print '</td>';
2192 
2193  print '</tr>';
2194  $i++;
2195  }
2196  } else {
2197  print '<tr><td class="opacitymedium" colspan="5">'.$langs->trans("None").'</td></tr>';
2198  }
2199 
2200  print '</table>';
2201  print '</div>';
2202 
2203  print '</form>';
2204  } else {
2205  $fullpathoffile = dol_buildpath($file, 0);
2206 
2207  $content = file_get_contents($fullpathoffile);
2208 
2209  // New module
2210  print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
2211  print '<input type="hidden" name="token" value="'.newToken().'">';
2212  print '<input type="hidden" name="action" value="savefile">';
2213  print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
2214  print '<input type="hidden" name="tab" value="'.$tab.'">';
2215  print '<input type="hidden" name="module" value="'.$module.'">';
2216 
2217  $doleditor = new DolEditor('editfilecontent', $content, '', '300', 'Full', 'In', true, false, 'ace', 0, '99%');
2218  print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ?GETPOST('format', 'aZ09') : 'html'));
2219  print '<br>';
2220  print '<center>';
2221  print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
2222  print ' &nbsp; ';
2223  print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
2224  print '</center>';
2225 
2226  print '</form>';
2227  }
2228  }
2229 
2230  if ($tab == 'objects')
2231  {
2232  $head3 = array();
2233  $h = 0;
2234 
2235  // Dir for module
2236  $dir = $dirread.'/'.$modulelowercase.'/class';
2237 
2238  $head3[$h][0] = $_SERVER["PHP_SELF"].'?tab=objects&module='.$module.($forceddirread ? '@'.$dirread : '').'&tabobj=newobject';
2239  $head3[$h][1] = '<span class="valignmiddle text-plus-circle">'.$langs->trans("NewObjectInModulebuilder").'</span><span class="fa fa-plus-circle valignmiddle paddingleft"></span>';
2240  $head3[$h][2] = 'newobject';
2241  $h++;
2242 
2243  // Scan for object class files
2244  $listofobject = dol_dir_list($dir, 'files', 0, '\.class\.php$');
2245 
2246  $firstobjectname = '';
2247  foreach ($listofobject as $fileobj)
2248  {
2249  if (preg_match('/^api_/', $fileobj['name'])) continue;
2250  if (preg_match('/^actions_/', $fileobj['name'])) continue;
2251 
2252  $tmpcontent = file_get_contents($fileobj['fullname']);
2253  if (preg_match('/class\s+([^\s]*)\s+extends\s+CommonObject/ims', $tmpcontent, $reg))
2254  {
2255  //$objectname = preg_replace('/\.txt$/', '', $fileobj['name']);
2256  $objectname = $reg[1];
2257  if (empty($firstobjectname)) $firstobjectname = $objectname;
2258 
2259  $head3[$h][0] = $_SERVER["PHP_SELF"].'?tab=objects&module='.$module.($forceddirread ? '@'.$dirread : '').'&tabobj='.$objectname;
2260  $head3[$h][1] = $objectname;
2261  $head3[$h][2] = $objectname;
2262  $h++;
2263  }
2264  }
2265 
2266  $head3[$h][0] = $_SERVER["PHP_SELF"].'?tab=objects&module='.$module.($forceddirread ? '@'.$dirread : '').'&tabobj=deleteobject';
2267  $head3[$h][1] = $langs->trans("DangerZone");
2268  $head3[$h][2] = 'deleteobject';
2269  $h++;
2270 
2271  // 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.
2272  if ($tabobj == 'newobjectifnoobj')
2273  {
2274  if ($firstobjectname) $tabobj = $firstobjectname;
2275  else $tabobj = 'newobject';
2276  }
2277 
2278  print dol_get_fiche_head($head3, $tabobj, '', -1, ''); // Level 3
2279 
2280  if ($tabobj == 'newobject')
2281  {
2282  // New object tab
2283  print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
2284  print '<input type="hidden" name="token" value="'.newToken().'">';
2285  print '<input type="hidden" name="action" value="initobject">';
2286  print '<input type="hidden" name="tab" value="objects">';
2287  print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
2288 
2289  print '<span class="opacitymedium">'.$langs->trans("EnterNameOfObjectDesc").'</span><br><br>';
2290 
2291  print '<input type="text" name="objectname" maxlength="64" value="'.dol_escape_htmltag(GETPOST('objectname', 'alpha') ? GETPOST('objectname', 'alpha') : $modulename).'" placeholder="'.dol_escape_htmltag($langs->trans("ObjectKey")).'"><br>';
2292  print '<input type="checkbox" name="includerefgeneration" value="includerefgeneration"> '.$form->textwithpicto($langs->trans("IncludeRefGeneration"), $langs->trans("IncludeRefGenerationHelp")).'<br>';
2293  print '<input type="checkbox" name="includedocgeneration" value="includedocgeneration"> '.$form->textwithpicto($langs->trans("IncludeDocGeneration"), $langs->trans("IncludeDocGenerationHelp")).'<br>';
2294  print '<input type="submit" class="button" name="create" value="'.dol_escape_htmltag($langs->trans("Generate")).'"'.($dirins ? '' : ' disabled="disabled"').'>';
2295  print '<br>';
2296  print '<br>';
2297  print '<br>';
2298  print $langs->trans("or");
2299  print '<br>';
2300  print '<br>';
2301  //print '<input type="checkbox" name="initfromtablecheck"> ';
2302  print $langs->trans("InitStructureFromExistingTable");
2303  print '<input type="text" name="initfromtablename" value="" placeholder="'.$langs->trans("TableName").'">';
2304  print '<input type="submit" class="button" name="createtablearray" value="'.dol_escape_htmltag($langs->trans("Generate")).'"'.($dirins ? '' : ' disabled="disabled"').'>';
2305  print '<br>';
2306 
2307  print '</form>';
2308  } elseif ($tabobj == 'deleteobject') {
2309  // Delete object tab
2310  print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
2311  print '<input type="hidden" name="token" value="'.newToken().'">';
2312  print '<input type="hidden" name="action" value="confirm_deleteobject">';
2313  print '<input type="hidden" name="tab" value="objects">';
2314  print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
2315 
2316  print $langs->trans("EnterNameOfObjectToDeleteDesc").'<br><br>';
2317 
2318  print '<input type="text" name="objectname" value="'.dol_escape_htmltag($modulename).'" placeholder="'.dol_escape_htmltag($langs->trans("ObjectKey")).'">';
2319  print '<input type="submit" class="button smallpaddingimp" name="delete" value="'.dol_escape_htmltag($langs->trans("Delete")).'"'.($dirins ? '' : ' disabled="disabled"').'>';
2320  print '</form>';
2321  } else {
2322  // tabobj = module
2323  if ($action == 'deleteproperty')
2324  {
2325  $formconfirm = $form->formconfirm(
2326  $_SERVER["PHP_SELF"].'?propertykey='.urlencode(GETPOST('propertykey', 'alpha')).'&objectname='.urlencode($objectname).'&tab='.urlencode($tab).'&module='.urlencode($module).'&tabobj='.urlencode($tabobj),
2327  $langs->trans('Delete'), $langs->trans('ConfirmDeleteProperty', GETPOST('propertykey', 'alpha')), 'confirm_deleteproperty', '', 0, 1
2328  );
2329 
2330  // Print form confirm
2331  print $formconfirm;
2332  }
2333 
2334  if ($action != 'editfile' || empty($file))
2335  {
2336  try {
2337  //$pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
2338 
2339  $pathtoclass = strtolower($module).'/class/'.strtolower($tabobj).'.class.php';
2340  $pathtoapi = strtolower($module).'/class/api_'.strtolower($module).'.class.php';
2341  $pathtoagenda = strtolower($module).'/'.strtolower($tabobj).'_agenda.php';
2342  $pathtocard = strtolower($module).'/'.strtolower($tabobj).'_card.php';
2343  $pathtodocument = strtolower($module).'/'.strtolower($tabobj).'_document.php';
2344  $pathtolist = strtolower($module).'/'.strtolower($tabobj).'_list.php';
2345  $pathtonote = strtolower($module).'/'.strtolower($tabobj).'_note.php';
2346  $pathtocontact = strtolower($module).'/'.strtolower($tabobj).'_contact.php';
2347  $pathtophpunit = strtolower($module).'/test/phpunit/'.strtolower($tabobj).'Test.php';
2348  $pathtosql = strtolower($module).'/sql/llx_'.strtolower($module).'_'.strtolower($tabobj).'.sql';
2349  $pathtosqlextra = strtolower($module).'/sql/llx_'.strtolower($module).'_'.strtolower($tabobj).'_extrafields.sql';
2350  $pathtosqlkey = strtolower($module).'/sql/llx_'.strtolower($module).'_'.strtolower($tabobj).'.key.sql';
2351  $pathtosqlextrakey = strtolower($module).'/sql/llx_'.strtolower($module).'_'.strtolower($tabobj).'_extrafields.key.sql';
2352  $pathtolib = strtolower($module).'/lib/'.strtolower($module).'.lib.php';
2353  $pathtoobjlib = strtolower($module).'/lib/'.strtolower($module).'_'.strtolower($tabobj).'.lib.php';
2354  $pathtopicto = strtolower($module).'/img/object_'.strtolower($tabobj).'.png';
2355  $pathtoscript = strtolower($module).'/scripts/'.strtolower($tabobj).'.php';
2356 
2357  //var_dump($pathtoclass); var_dump($dirread);
2358  $realpathtoclass = $dirread.'/'.$pathtoclass;
2359  $realpathtoapi = $dirread.'/'.$pathtoapi;
2360  $realpathtoagenda = $dirread.'/'.$pathtoagenda;
2361  $realpathtocard = $dirread.'/'.$pathtocard;
2362  $realpathtodocument = $dirread.'/'.$pathtodocument;
2363  $realpathtolist = $dirread.'/'.$pathtolist;
2364  $realpathtonote = $dirread.'/'.$pathtonote;
2365  $realpathtocontact = $dirread.'/'.$pathtocontact;
2366  $realpathtophpunit = $dirread.'/'.$pathtophpunit;
2367  $realpathtosql = $dirread.'/'.$pathtosql;
2368  $realpathtosqlextra = $dirread.'/'.$pathtosqlextra;
2369  $realpathtosqlkey = $dirread.'/'.$pathtosqlkey;
2370  $realpathtosqlextrakey = $dirread.'/'.$pathtosqlextrakey;
2371  $realpathtolib = $dirread.'/'.$pathtolib;
2372  $realpathtoobjlib = $dirread.'/'.$pathtoobjlib;
2373  $realpathtopicto = $dirread.'/'.$pathtopicto;
2374  $realpathtoscript = $dirread.'/'.$pathtoscript;
2375 
2376  if (empty($realpathtoapi)) // For compatibility with some old modules
2377  {
2378  $pathtoapi = strtolower($module).'/class/api_'.strtolower($module).'s.class.php';
2379  $realpathtoapi = $dirread.'/'.$pathtoapi;
2380  }
2381  $urloflist = $dirread.'/'.$pathtolist;
2382  $urlofcard = $dirread.'/'.$pathtocard;
2383 
2384  print '<div class="fichehalfleft">';
2385  print '<span class="fa fa-file-o"></span> '.$langs->trans("ClassFile").' : <strong>'.($realpathtoclass ? '' : '<strike>').$pathtoclass.($realpathtoclass ? '' : '</strike>').'</strong>';
2386  print ' <a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&tabobj='.$tabobj.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&format=php&file='.urlencode($pathtoclass).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
2387  print '<br>';
2388  print '<span class="fa fa-file-o"></span> '.$langs->trans("ApiClassFile").' : <strong>'.($realpathtoapi ? '' : '<strike>').$pathtoapi.($realpathtoapi ? '' : '</strike>').'</strong>';
2389  if (dol_is_file($realpathtoapi)) {
2390  print ' <a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&tabobj='.$tabobj.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&format=php&file='.urlencode($pathtoapi).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
2391  print ' ';
2392  print '<a class="reposition editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&tabobj='.$tabobj.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=confirm_removefile&file='.urlencode($pathtoapi).'">'.img_picto($langs->trans("Delete"), 'delete').'</a>';
2393  print ' &nbsp; ';
2394  if (empty($conf->global->$const_name)) // If module is not activated
2395  {
2396  print '<a href="#" class="classfortooltip" target="apiexplorer" title="'.$langs->trans("ModuleMustBeEnabled", $module).'"><strike>'.$langs->trans("GoToApiExplorer").'</strike></a>';
2397  } else {
2398  print '<a href="'.DOL_URL_ROOT.'/api/index.php/explorer/" target="apiexplorer">'.$langs->trans("GoToApiExplorer").'</a>';
2399  }
2400  } else {
2401  //print '<span class="opacitymedium">'.$langs->trans("FileNotYetGenerated").'</span> ';
2402  print '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&tabobj='.$tabobj.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=initapi&format=php&file='.urlencode($pathtoapi).'"><input type="button" class="button smallpaddingimp" value="'.$langs->trans("Generate").'"></a>';
2403  }
2404  // PHPUnit
2405  print '<br>';
2406  print '<span class="fa fa-file-o"></span> '.$langs->trans("TestClassFile").' : <strong>'.($realpathtophpunit ? '' : '<strike>').$pathtophpunit.($realpathtophpunit ? '' : '</strike>').'</strong>';
2407  if (dol_is_file($realpathtophpunit)) {
2408  print ' <a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&tabobj='.$tabobj.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&format=php&file='.urlencode($pathtophpunit).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
2409  print ' ';
2410  print '<a class="reposition editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&tabobj='.$tabobj.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=confirm_removefile&file='.urlencode($pathtophpunit).'">'.img_picto($langs->trans("Delete"), 'delete').'</a>';
2411  } else {
2412  //print '<span class="opacitymedium">'.$langs->trans("FileNotYetGenerated").'</span> ';
2413  print '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&tabobj='.$tabobj.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=initphpunit&format=php&file='.urlencode($pathtophpunit).'"><input type="button" class="button smallpaddingimp" value="'.$langs->trans("Generate").'"></a>';
2414  }
2415  print '<br>';
2416 
2417  print '<br>';
2418 
2419  print '<span class="fa fa-file-o"></span> '.$langs->trans("PageForLib").' : <strong>'.($realpathtolib ? '' : '<strike>').$pathtolib.($realpathtolib ? '' : '</strike>').'</strong>';
2420  print ' <a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&tabobj='.$tabobj.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&format=php&file='.urlencode($pathtolib).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
2421  print '<br>';
2422  print '<span class="fa fa-file-o"></span> '.$langs->trans("PageForObjLib").' : <strong>'.($realpathtoobjlib ? '' : '<strike>').$pathtoobjlib.($realpathtoobjlib ? '' : '</strike>').'</strong>';
2423  print ' <a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&tabobj='.$tabobj.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&format=php&file='.urlencode($pathtoobjlib).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
2424  print '<br>';
2425  print '<span class="fa fa-file-image-o"></span> '.$langs->trans("Image").' : <strong>'.($realpathtopicto ? '' : '<strike>').$pathtopicto.($realpathtopicto ? '' : '</strike>').'</strong>';
2426  //print ' <a href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&tabobj='.$tabobj.'&module='.$module.($forceddirread?'@'.$dirread:'').'&action=editfile&format=php&file='.urlencode($pathtopicto).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
2427  print '<br>';
2428 
2429  print '<br>';
2430  print '<span class="fa fa-file-o"></span> '.$langs->trans("SqlFile").' : <strong>'.($realpathtosql ? '' : '<strike>').$pathtosql.($realpathtosql ? '' : '</strike>').'</strong>';
2431  print ' <a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&tabobj='.$tabobj.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&format=sql&file='.urlencode($pathtosql).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
2432  print ' &nbsp; <a class="reposition" href="'.$_SERVER["PHP_SELF"].'?tab='.$tab.'&tabobj='.$tabobj.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=droptable">'.$langs->trans("DropTableIfEmpty").'</a>';
2433  //print ' &nbsp; <a href="'.$_SERVER["PHP_SELF"].'">'.$langs->trans("RunSql").'</a>';
2434  print '<br>';
2435  print '<span class="fa fa-file-o"></span> '.$langs->trans("SqlFileKey").' : <strong>'.($realpathtosqlkey ? '' : '<strike>').$pathtosqlkey.($realpathtosqlkey ? '' : '</strike>').'</strong>';
2436  print ' <a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&tabobj='.$tabobj.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&format=sql&file='.urlencode($pathtosqlkey).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
2437  //print ' &nbsp; <a href="'.$_SERVER["PHP_SELF"].'">'.$langs->trans("RunSql").'</a>';
2438  print '<br>';
2439  print '<span class="fa fa-file-o"></span> '.$langs->trans("SqlFileExtraFields").' : <strong>'.($realpathtosqlextra ? '' : '<strike>').$pathtosqlextra.($realpathtosqlextra ? '' : '</strike>').'</strong>';
2440  if (dol_is_file($realpathtosqlextra) && dol_is_file($realpathtosqlextrakey)) {
2441  print ' <a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&tabobj='.$tabobj.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&file='.urlencode($pathtosqlextra).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
2442  print ' ';
2443  print '<a class="reposition editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&tabobj='.$tabobj.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=confirm_removefile&file='.urlencode($pathtosqlextra).'">'.img_picto($langs->trans("Delete"), 'delete').'</a>';
2444  print ' &nbsp; ';
2445  print '<a class="reposition editfielda" href="'.$_SERVER["PHP_SELF"].'?tab='.$tab.'&tabobj='.$tabobj.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=droptableextrafields">'.$langs->trans("DropTableIfEmpty").'</a>';
2446  } else {
2447  print '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&tabobj='.$tabobj.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=initsqlextrafields&format=sql&file='.urlencode($pathtosqlextra).'"><input type="button" class="button smallpaddingimp" value="'.$langs->trans("Generate").'"></a>';
2448  }
2449  //print ' &nbsp; <a href="'.$_SERVER["PHP_SELF"].'">'.$langs->trans("RunSql").'</a>';
2450  print '<br>';
2451  print '<span class="fa fa-file-o"></span> '.$langs->trans("SqlFileKeyExtraFields").' : <strong>'.($realpathtosqlextrakey ? '' : '<strike>').$pathtosqlextrakey.($realpathtosqlextrakey ? '' : '</strike>').'</strong>';
2452  if (dol_is_file($realpathtosqlextra) && dol_is_file($realpathtosqlextrakey)) {
2453  print ' <a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&tabobj='.$tabobj.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&format=sql&file='.urlencode($pathtosqlextrakey).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
2454  print ' ';
2455  print '<a class="reposition editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&tabobj='.$tabobj.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=confirm_removefile&file='.urlencode($pathtosqlextrakey).'">'.img_picto($langs->trans("Delete"), 'delete').'</a>';
2456  } else {
2457  print '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&tabobj='.$tabobj.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=initsqlextrafields&format=sql&file='.urlencode($pathtosqlextra).'"><input type="button" class="button smallpaddingimp" value="'.$langs->trans("Generate").'"></a>';
2458  }
2459  //print ' &nbsp; <a href="'.$_SERVER["PHP_SELF"].'">'.$langs->trans("RunSql").'</a>';
2460  print '<br>';
2461 
2462  print '<br>';
2463  print '</div>';
2464 
2465  print '<div class="fichehalfleft">';
2466  print '<span class="fa fa-file-o"></span> '.$langs->trans("PageForList").' : <strong><a href="'.$urloflist.'" target="_test">'.($realpathtolist ? '' : '<strike>').$pathtolist.($realpathtolist ? '' : '</strike>').'</a></strong>';
2467  print ' <a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&tabobj='.$tabobj.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&format=php&file='.urlencode($pathtolist).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
2468  print '<br>';
2469  print '<span class="fa fa-file-o"></span> '.$langs->trans("PageForCreateEditView").' : <strong><a href="'.$urlofcard.'?action=create" target="_test">'.($realpathtocard ? '' : '<strike>').$pathtocard.($realpathtocard ? '' : '</strike>').'?action=create</a></strong>';
2470  print ' <a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&tabobj='.$tabobj.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&format=php&file='.urlencode($pathtocard).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
2471  print '<br>';
2472  print '<span class="fa fa-file-o"></span> '.$langs->trans("PageForContactTab").' : <strong>'.($realpathtocontact ? '' : '<strike>').$pathtocontact.($realpathtocontact ? '' : '</strike>').'</strong>';
2473  print ' <a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&tabobj='.$tabobj.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&format=php&file='.urlencode($pathtocontact).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
2474  if (dol_is_file($realpathtocontact)) {
2475  print ' ';
2476  print '<a class="reposition editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&tabobj='.$tabobj.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=confirm_removefile&file='.urlencode($pathtocontact).'">'.img_picto($langs->trans("Delete"), 'delete').'</a>';
2477  }
2478  print '<br>';
2479  print '<span class="fa fa-file-o"></span> '.$langs->trans("PageForDocumentTab").' : <strong>'.($realpathtodocument ? '' : '<strike>').$pathtodocument.($realpathtodocument ? '' : '</strike>').'</strong>';
2480  print ' <a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&tabobj='.$tabobj.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&format=php&file='.urlencode($pathtodocument).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
2481  if (dol_is_file($realpathtodocument)) {
2482  print ' ';
2483  print '<a class="reposition editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&tabobj='.$tabobj.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=confirm_removefile&file='.urlencode($pathtodocument).'">'.img_picto($langs->trans("Delete"), 'delete').'</a>';
2484  }
2485  print '<br>';
2486  print '<span class="fa fa-file-o"></span> '.$langs->trans("PageForNoteTab").' : <strong>'.($realpathtonote ? '' : '<strike>').$pathtonote.($realpathtonote ? '' : '</strike>').'</strong>';
2487  print ' <a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&tabobj='.$tabobj.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&format=php&file='.urlencode($pathtonote).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
2488  if (dol_is_file($realpathtonote)) {
2489  print ' ';
2490  print '<a class="reposition editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&tabobj='.$tabobj.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=confirm_removefile&file='.urlencode($pathtonote).'">'.img_picto($langs->trans("Delete"), 'delete').'</a>';
2491  }
2492  print '<br>';
2493  print '<span class="fa fa-file-o"></span> '.$langs->trans("PageForAgendaTab").' : <strong>'.($realpathtoagenda ? '' : '<strike>').$pathtoagenda.($realpathtoagenda ? '' : '</strike>').'</strong>';
2494  print ' <a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&tabobj='.$tabobj.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&format=php&file='.urlencode($pathtoagenda).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
2495  if (dol_is_file($realpathtoagenda)) {
2496  print ' ';
2497  print '<a class="reposition editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&tabobj='.$tabobj.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=confirm_removefile&file='.urlencode($pathtoagenda).'">'.img_picto($langs->trans("Delete"), 'delete').'</a>';
2498  }
2499  print '<br>';
2500 
2501  /* This is already on Tab CLI
2502  print '<br>';
2503  print '<span class="fa fa-file-o"></span> '.$langs->trans("ScriptFile").' : <strong>'.($realpathtoscript?'':'<strike>').$pathtoscript.($realpathtoscript?'':'</strike>').'</strong>';
2504  print ' <a href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&tabobj='.$tabobj.'&module='.$module.($forceddirread?'@'.$dirread:'').'&action=editfile&format=php&file='.urlencode($pathtoscript).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
2505  print '<br>';*/
2506 
2507  print '<br>';
2508 
2509  print '</div>';
2510 
2511  print '<br><br><br>';
2512 
2513  if (function_exists('opcache_invalidate')) opcache_invalidate($dirread.'/'.$pathtoclass, true); // remove the include cache hell !
2514 
2515  if (empty($forceddirread) && empty($dirread))
2516  {
2517  $result = dol_include_once($pathtoclass);
2518  } else {
2519  $result = @include_once $dirread.'/'.$pathtoclass;
2520  }
2521  if (class_exists($tabobj))
2522  {
2523  try {
2524  $tmpobjet = @new $tabobj($db);
2525  } catch (Exception $e)
2526  {
2527  dol_syslog('Failed to load Constructor of class: '.$e->getMessage(), LOG_WARNING);
2528  }
2529  }
2530 
2531  if (!empty($tmpobjet))
2532  {
2533  $reflector = new ReflectionClass($tabobj);
2534  $reflectorproperties = $reflector->getProperties(); // Can also use get_object_vars
2535  $reflectorpropdefault = $reflector->getDefaultProperties(); // Can also use get_object_vars
2536  //$propstat = $reflector->getStaticProperties();
2537  //var_dump($reflectorpropdefault);
2538 
2539  print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
2540  print '<input type="hidden" name="token" value="'.newToken().'">';
2541  print '<input type="hidden" name="action" value="addproperty">';
2542  print '<input type="hidden" name="tab" value="objects">';
2543  print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module.($forceddirread ? '@'.$dirread : '')).'">';
2544  print '<input type="hidden" name="tabobj" value="'.dol_escape_htmltag($tabobj).'">';
2545 
2546  print '<input class="button smallpaddingimp" type="submit" name="regenerateclasssql" value="'.$langs->trans("RegenerateClassAndSql").'">';
2547  print '<br><br>';
2548 
2549  print load_fiche_titre($langs->trans("ObjectProperties"), '', '');
2550 
2551  print '<!-- Table with properties of object -->'."\n";
2552  print '<div class="div-table-responsive">';
2553  print '<table class="noborder">';
2554  print '<tr class="liste_titre">';
2555  print '<th>'.$langs->trans("Property");
2556  print ' (<a class="" href="https://wiki.dolibarr.org/index.php/Language_and_development_rules#Table_and_fields_structures" target="_blank">'.$langs->trans("SeeExamples").'</a>)';
2557  print '</th>';
2558  print '<th>';
2559  print $form->textwithpicto($langs->trans("Label"), $langs->trans("YouCanUseTranslationKey"));
2560  print '</th>';
2561  print '<th>'.$form->textwithpicto($langs->trans("Type"), $langs->trans("TypeOfFieldsHelp")).'</th>';
2562  print '<th>'.$form->textwithpicto($langs->trans("ArrayOfKeyValues"), $langs->trans("ArrayOfKeyValuesDesc")).'</th>';
2563  print '<th class="center">'.$form->textwithpicto($langs->trans("NotNull"), $langs->trans("NotNullDesc")).'</th>';
2564  print '<th class="center">'.$langs->trans("DefaultValue").'</th>';
2565  print '<th class="center">'.$langs->trans("DatabaseIndex").'</th>';
2566  print '<th class="center">'.$langs->trans("ForeignKey").'</th>';
2567  print '<th class="right">'.$langs->trans("Position").'</th>';
2568  print '<th class="center">'.$form->textwithpicto($langs->trans("Enabled"), $langs->trans("EnabledDesc")).'</th>';
2569  print '<th class="center">'.$form->textwithpicto($langs->trans("Visible"), $langs->trans("VisibleDesc")).'</th>';
2570  print '<th class="center">'.$langs->trans("NotEditable").'</th>';
2571  print '<th class="center">'.$form->textwithpicto($langs->trans("SearchAll"), $langs->trans("SearchAllDesc")).'</th>';
2572  print '<th class="center">'.$form->textwithpicto($langs->trans("IsAMeasure"), $langs->trans("IsAMeasureDesc")).'</th>';
2573  print '<th class="center">'.$langs->trans("CSSClass").'</th>';
2574  print '<th class="center">'.$langs->trans("CSSViewClass").'</th>';
2575  print '<th class="center">'.$langs->trans("KeyForTooltip").'</th>';
2576  print '<th class="center">'.$langs->trans("ShowOnCombobox").'</th>';
2577  //print '<th class="center">'.$langs->trans("Disabled").'</th>';
2578  print '<th>'.$langs->trans("Comment").'</th>';
2579  print '<th></th>';
2580  print '</tr>';
2581 
2582  // We must use $reflectorpropdefault['fields'] to get list of fields because $tmpobjet->fields may have been
2583  // modified during the constructor and we want value into head of class before constructor is called.
2584  //$properties = dol_sort_array($tmpobjet->fields, 'position');
2585  $properties = dol_sort_array($reflectorpropdefault['fields'], 'position');
2586 
2587  if (!empty($properties))
2588  {
2589  // Line to add a property
2590  print '<tr>';
2591  print '<td><input class="text maxwidth75" name="propname" value="'.dol_escape_htmltag(GETPOST('propname', 'alpha')).'"></td>';
2592  print '<td><input class="text maxwidth75" name="proplabel" value="'.dol_escape_htmltag(GETPOST('proplabel', 'alpha')).'"></td>';
2593  print '<td><input class="text maxwidth75" name="proptype" value="'.dol_escape_htmltag(GETPOST('proptype', 'alpha')).'"></td>';
2594  print '<td><input class="text maxwidth75" name="proparrayofkeyval" value="'.dol_escape_htmltag(GETPOST('proparrayofkeyval', 'restricthtml')).'"></td>';
2595  print '<td class="center"><input class="text" size="2" name="propnotnull" value="'.dol_escape_htmltag(GETPOST('propnotnull', 'alpha')).'"></td>';
2596  print '<td><input class="text maxwidth50" name="propdefault" value="'.dol_escape_htmltag(GETPOST('propdefault', 'alpha')).'"></td>';
2597  print '<td class="center"><input class="text" size="2" name="propindex" value="'.dol_escape_htmltag(GETPOST('propindex', 'alpha')).'"></td>';
2598  print '<td class="center"><input class="text" size="2" name="propforeignkey" value="'.dol_escape_htmltag(GETPOST('propforeignkey', 'alpha')).'"></td>';
2599  print '<td class="right"><input class="text right" size="2" name="propposition" value="'.dol_escape_htmltag(GETPOST('propposition', 'alpha')).'"></td>';
2600  print '<td class="center"><input class="text" size="2" name="propenabled" value="'.dol_escape_htmltag(GETPOST('propenabled', 'alpha')).'"></td>';
2601  print '<td class="center"><input class="text" size="2" name="propvisible" value="'.dol_escape_htmltag(GETPOST('propvisible', 'alpha')).'"></td>';
2602  print '<td class="center"><input class="text" size="2" name="propnoteditable" value="'.dol_escape_htmltag(GETPOST('propnoteditable', 'alpha')).'"></td>';
2603  print '<td class="center"><input class="text" size="2" name="propsearchall" value="'.dol_escape_htmltag(GETPOST('propsearchall', 'alpha')).'"></td>';
2604  print '<td class="center"><input class="text" size="2" name="propisameasure" value="'.dol_escape_htmltag(GETPOST('propisameasure', 'alpha')).'"></td>';
2605  print '<td class="center"><input class="text" size="2" name="propcss" value="'.dol_escape_htmltag(GETPOST('propcss', 'alpha')).'"></td>';
2606  print '<td class="center"><input class="text" size="2" name="propcssview" value="'.dol_escape_htmltag(GETPOST('propcssview', 'alpha')).'"></td>';
2607  print '<td class="center"><input class="text" size="2" name="prophelp" value="'.dol_escape_htmltag(GETPOST('prophelp', 'alpha')).'"></td>';
2608  print '<td class="center"><input class="text" size="2" name="propshowoncombobox" value="'.dol_escape_htmltag(GETPOST('propshowoncombobox', 'alpha')).'"></td>';
2609  //print '<td class="center"><input class="text" size="2" name="propdisabled" value="'.dol_escape_htmltag(GETPOST('propdisabled', 'alpha')).'"></td>';
2610  print '<td><input class="text maxwidth100" name="propcomment" value="'.dol_escape_htmltag(GETPOST('propcomment', 'alpha')).'"></td>';
2611  print '<td class="center">';
2612  print '<input class="button" type="submit" name="add" value="'.$langs->trans("Add").'">';
2613  print '</td></tr>';
2614 
2615  // List of existing properties
2616  foreach ($properties as $propkey => $propval)
2617  {
2618  /* If from Reflection
2619  if ($propval->class == $tabobj)
2620  {
2621  $propname=$propval->getName();
2622  $comment=$propval->getDocComment();
2623  $type=gettype($tmpobjet->$propname);
2624  $default=$propdefault[$propname];
2625  // Discard generic properties
2626  if (in_array($propname, array('element', 'childtables', 'table_element', 'table_element_line', 'class_element_line', 'ismultientitymanaged'))) continue;
2627 
2628  // Keep or not lines
2629  if (in_array($propname, array('fk_element', 'lines'))) continue;
2630  }*/
2631 
2632  $propname = $propkey;
2633  $proplabel = $propval['label'];
2634  $proptype = $propval['type'];
2635  $proparrayofkeyval = $propval['arrayofkeyval'];
2636  $propnotnull = $propval['notnull'];
2637  $propdefault = $propval['default'];
2638  $propindex = $propval['index'];
2639  $propforeignkey = $propval['foreignkey'];
2640  $propposition = $propval['position'];
2641  $propenabled = $propval['enabled'];
2642  $propvisible = $propval['visible'];
2643  $propnoteditable = $propval['noteditable'];
2644  $propsearchall = $propval['searchall'];
2645  $propisameasure = $propval['isameasure'];
2646  $propcss = $propval['css'];
2647  $propcssview = $propval['cssview'];
2648  $prophelp = $propval['help'];
2649  $propshowoncombobox = $propval['showoncombobox'];
2650  //$propdisabled=$propval['disabled'];
2651  $propcomment = $propval['comment'];
2652 
2653  print '<tr class="oddeven">';
2654 
2655  print '<td>';
2656  print dol_escape_htmltag($propname);
2657  print '</td>';
2658  print '<td>';
2659  print dol_escape_htmltag($proplabel);
2660  print '</td>';
2661  print '<td class="tdoverflowmax200">';
2662  print '<span title="'.dol_escape_htmltag($proptype).'">'.dol_escape_htmltag($proptype).'</span>';
2663  print '</td>';
2664  print '<td class="tdoverflowmax200">';
2665  if ($proparrayofkeyval) {
2666  print '<span title="'.dol_escape_htmltag(json_encode($proparrayofkeyval)).'">';
2667  print dol_escape_htmltag(json_encode($proparrayofkeyval));
2668  print '</span>';
2669  }
2670  print '</td>';
2671  print '<td class="center">';
2672  print dol_escape_htmltag($propnotnull);
2673  print '</td>';
2674  print '<td>';
2675  print dol_escape_htmltag($propdefault);
2676  print '</td>';
2677  print '<td class="center">';
2678  print $propindex ? '1' : '';
2679  print '</td>';
2680  print '<td class="center">';
2681  print $propforeignkey ? dol_escape_htmltag($propforeignkey) : '';
2682  print '</td>';
2683  print '<td class="right">';
2684  print dol_escape_htmltag($propposition);
2685  print '</td>';
2686  print '<td class="center">';
2687  print $propenabled ? dol_escape_htmltag($propenabled) : '';
2688  print '</td>';
2689  print '<td class="center">';
2690  print $propvisible ? dol_escape_htmltag($propvisible) : '0';
2691  print '</td>';
2692  print '<td class="center">';
2693  print $propnoteditable ? dol_escape_htmltag($propnoteditable) : '';
2694  print '</td>';
2695  print '<td class="center">';
2696  print $propsearchall ? '1' : '';
2697  print '</td>';
2698  print '<td class="center">';
2699  print $propisameasure ? dol_escape_htmltag($propisameasure) : '';
2700  print '</td>';
2701  print '<td class="center">';
2702  print $propcss ? dol_escape_htmltag($propcss) : '';
2703  print '</td>';
2704  print '<td class="center">';
2705  print $propcssview ? dol_escape_htmltag($propcssview) : '';
2706  print '</td>';
2707  print '<td class="tdoverflowmax200">';
2708  print $prophelp ? dol_escape_htmltag($prophelp) : '';
2709  print '</td>';
2710  print '<td class="center">';
2711  print $propshowoncombobox ? dol_escape_htmltag($propshowoncombobox) : '';
2712  print '</td>';
2713  /*print '<td class="center">';
2714  print $propdisabled?$propdisabled:'';
2715  print '</td>';*/
2716  print '<td class="tdoverflowmax200">';
2717  print '<span title="'.dol_escape_htmltag($propcomment).'">';
2718  print dol_escape_htmltag($propcomment);
2719  print '</span>';
2720  print '</td>';
2721  print '<td class="center">';
2722  if ($propname != 'rowid')
2723  {
2724  print '<a href="'.$_SERVER["PHP_SELF"].'?action=deleteproperty&token='.newToken().'&propertykey='.urlencode($propname).'&tab='.urlencode($tab).'&module='.urlencode($module).'&tabobj='.urlencode($tabobj).'">'.img_delete().'</a>';
2725  }
2726  print '</td>';
2727 
2728  print '</tr>';
2729  }
2730  } else {
2731  if ($tab == 'specifications')
2732  {
2733  if ($action != 'editfile' || empty($file))
2734  {
2735  print '<span class="opacitymedium">'.$langs->trans("SpecDefDesc").'</span><br>';
2736  print '<br>';
2737 
2738  $specs = dol_dir_list(dol_buildpath($modulelowercase.'/doc', 0), 'files', 1, '(\.md|\.asciidoc)$', array('\/temp\/'));
2739 
2740  foreach ($specs as $spec)
2741  {
2742  $pathtofile = $modulelowercase.'/doc/'.$spec['relativename'];
2743  $format = 'asciidoc';
2744  if (preg_match('/\.md$/i', $spec['name'])) $format = 'markdown';
2745  print '<span class="fa fa-file-o"></span> '.$langs->trans("SpecificationFile").' : <strong>'.$pathtofile.'</strong>';
2746  print ' <a href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&format='.$format.'&file='.urlencode($pathtofile).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
2747  print '<br>';
2748  }
2749  } else {
2750  // Use MD or asciidoc
2751 
2752  //print $langs->trans("UseAsciiDocFormat").'<br>';
2753 
2754  $fullpathoffile = dol_buildpath($file, 0);
2755 
2756  $content = file_get_contents($fullpathoffile);
2757 
2758  // New module
2759  print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
2760  print '<input type="hidden" name="token" value="'.newToken().'">';
2761  print '<input type="hidden" name="action" value="savefile">';
2762  print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
2763  print '<input type="hidden" name="tab" value="'.$tab.'">';
2764  print '<input type="hidden" name="module" value="'.$module.'">';
2765 
2766  $doleditor = new DolEditor('editfilecontent', $content, '', '300', 'Full', 'In', true, false, 'ace', 0, '99%');
2767  print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ?GETPOST('format', 'aZ09') : 'html'));
2768  print '<br>';
2769  print '<center>';
2770  print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
2771  print ' &nbsp; ';
2772  print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
2773  print '</center>';
2774 
2775  print '</form>';
2776  }
2777  }
2778  print '<tr><td><span class="warning">'.$langs->trans('Property $field not found into the class. The class was probably not generated by modulebuilder.').'</warning></td></tr>';
2779  }
2780  print '</table>';
2781  print '</div>';
2782 
2783  print '</form>';
2784  } else {
2785  print '<tr><td><span class="warning">'.$langs->trans('Failed to init the object with the new.').'</warning></td></tr>';
2786  }
2787  } catch (Exception $e)
2788  {
2789  print $e->getMessage();
2790  }
2791  } else {
2792  if (empty($forceddirread))
2793  {
2794  $fullpathoffile = dol_buildpath($file, 0);
2795  } else {
2796  $fullpathoffile = $dirread.'/'.$file;
2797  }
2798 
2799  $content = file_get_contents($fullpathoffile);
2800 
2801  // New module
2802  print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
2803  print '<input type="hidden" name="token" value="'.newToken().'">';
2804  print '<input type="hidden" name="action" value="savefile">';
2805  print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
2806  print '<input type="hidden" name="tab" value="'.$tab.'">';
2807  print '<input type="hidden" name="tabobj" value="'.dol_escape_htmltag($tabobj).'">';
2808  print '<input type="hidden" name="module" value="'.$module.($forceddirread ? '@'.$dirread : '').'">';
2809 
2810  $doleditor = new DolEditor('editfilecontent', $content, '', '300', 'Full', 'In', true, false, 'ace', 0, '99%');
2811  print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ?GETPOST('format', 'aZ09') : 'html'));
2812  print '<br>';
2813  print '<center>';
2814  print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
2815  print ' &nbsp; ';
2816  print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
2817  print '</center>';
2818 
2819  print '</form>';
2820  }
2821  }
2822 
2823  print dol_get_fiche_end(); // Level 3
2824  }
2825 
2826  if ($tab == 'menus')
2827  {
2828  $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
2829 
2830  $menus = $moduleobj->menu;
2831 
2832  if ($action != 'editfile' || empty($file))
2833  {
2834  print '<span class="opacitymedium">';
2835  $htmlhelp = $langs->trans("MenusDefDescTooltip", '<a href="'.DOL_URL_ROOT.'/admin/menus/index.php">'.$langs->trans('Setup').' - '.$langs->trans('Menus').'</a>');
2836  print $form->textwithpicto($langs->trans("MenusDefDesc"), $htmlhelp, 1, 'help', '', 0, 2, 'helpondesc').'<br>';
2837  print '</span>';
2838  print '<br>';
2839 
2840  print '<span class="fa fa-file-o"></span> '.$langs->trans("DescriptorFile").' : <strong>'.$pathtofile.'</strong>';
2841  print ' <a class="editfielda paddingleft paddingright" href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&format=php&file='.urlencode($pathtofile).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
2842  print '<br>';
2843 
2844  print '<br>';
2845  print load_fiche_titre($langs->trans("ListOfMenusEntries"), '', '');
2846 
2847  print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
2848  print '<input type="hidden" name="token" value="'.newToken().'">';
2849  print '<input type="hidden" name="action" value="addproperty">';
2850  print '<input type="hidden" name="tab" value="objects">';
2851  print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
2852  print '<input type="hidden" name="tabobj" value="'.dol_escape_htmltag($tabobj).'">';
2853 
2854  print '<div class="div-table-responsive">';
2855  print '<table class="noborder">';
2856 
2857  print '<tr class="liste_titre">';
2858  print_liste_field_titre("Type", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
2859  print_liste_field_titre("fk_menu", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
2860  print_liste_field_titre("Title", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
2861  print_liste_field_titre("mainmenu", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
2862  print_liste_field_titre("leftmenu", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
2863  print_liste_field_titre("URL", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
2864  print_liste_field_titre("LanguageFile", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
2865  print_liste_field_titre("Position", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
2866  print_liste_field_titre("Enabled", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
2867  print_liste_field_titre("Permission", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
2868  print_liste_field_titre("Target", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
2869  print_liste_field_titre("UserType", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder, 'right ');
2870  print "</tr>\n";
2871 
2872  if (count($menus))
2873  {
2874  foreach ($menus as $menu)
2875  {
2876  print '<tr class="oddeven">';
2877 
2878  print '<td>';
2879  print $menu['type'];
2880  print '</td>';
2881 
2882  print '<td>';
2883  print $menu['fk_menu'];
2884  print '</td>';
2885 
2886  print '<td>';
2887  print $menu['titre'];
2888  print '</td>';
2889 
2890  print '<td>';
2891  print $menu['mainmenu'];
2892  print '</td>';
2893 
2894  print '<td>';
2895  print $menu['leftmenu'];
2896  print '</td>';
2897 
2898  print '<td>';
2899  print $menu['url'];
2900  print '</td>';
2901 
2902  print '<td>';
2903  print $menu['langs'];
2904  print '</td>';
2905 
2906  print '<td>';
2907  print $menu['position'];
2908  print '</td>';
2909 
2910  print '<td>';
2911  print $menu['enabled'];
2912  print '</td>';
2913 
2914  print '<td>';
2915  print $menu['perms'];
2916  print '</td>';
2917 
2918  print '<td>';
2919  print $menu['target'];
2920  print '</td>';
2921 
2922  print '<td class="right">';
2923  print $menu['user'];
2924  print '</td>';
2925 
2926  print '</tr>';
2927  }
2928  } else {
2929  print '<tr><td class="opacitymedium" colspan="5">'.$langs->trans("None").'</td></tr>';
2930  }
2931 
2932  print '</table>';
2933  print '</div>';
2934 
2935  print '</form>';
2936  } else {
2937  $fullpathoffile = dol_buildpath($file, 0);
2938 
2939  $content = file_get_contents($fullpathoffile);
2940 
2941  // New module
2942  print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
2943  print '<input type="hidden" name="token" value="'.newToken().'">';
2944  print '<input type="hidden" name="action" value="savefile">';
2945  print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
2946  print '<input type="hidden" name="tab" value="'.$tab.'">';
2947  print '<input type="hidden" name="module" value="'.$module.'">';
2948 
2949  $doleditor = new DolEditor('editfilecontent', $content, '', '300', 'Full', 'In', true, false, 'ace', 0, '99%');
2950  print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ?GETPOST('format', 'aZ09') : 'html'));
2951  print '<br>';
2952  print '<center>';
2953  print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
2954  print ' &nbsp; ';
2955  print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
2956  print '</center>';
2957 
2958  print '</form>';
2959  }
2960  }
2961 
2962  if ($tab == 'permissions')
2963  {
2964  $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
2965 
2966  $perms = $moduleobj->rights;
2967 
2968  if ($action != 'editfile' || empty($file))
2969  {
2970  print '<span class="opacitymedium">';
2971  $htmlhelp = $langs->trans("PermissionsDefDescTooltip", '<a href="'.DOL_URL_ROOT.'/admin/perms.php">'.$langs->trans('DefaultPermissions').'</a>');
2972  print $form->textwithpicto($langs->trans("PermissionsDefDesc"), $htmlhelp, 1, 'help', '', 0, 2, 'helpondesc').'<br>';
2973  print '</span>';
2974  print '<br>';
2975 
2976  print '<span class="fa fa-file-o"></span> '.$langs->trans("DescriptorFile").' : <strong>'.$pathtofile.'</strong>';
2977  print ' <a class="editfielda paddingleft paddingright" href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&format=php&file='.urlencode($pathtofile).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
2978  print '<br>';
2979 
2980  print '<br>';
2981  print load_fiche_titre($langs->trans("ListOfPermissionsDefined"), '', '');
2982 
2983  print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
2984  print '<input type="hidden" name="token" value="'.newToken().'">';
2985  print '<input type="hidden" name="action" value="addproperty">';
2986  print '<input type="hidden" name="tab" value="objects">';
2987  print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
2988  print '<input type="hidden" name="tabobj" value="'.dol_escape_htmltag($tabobj).'">';
2989 
2990  print '<div class="div-table-responsive">';
2991  print '<table class="noborder">';
2992 
2993  print '<tr class="liste_titre">';
2994  print_liste_field_titre("ID", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
2995  print_liste_field_titre("Label", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
2996  print_liste_field_titre("Permission", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
2997  print_liste_field_titre("", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
2998  print "</tr>\n";
2999 
3000  if (count($perms))
3001  {
3002  foreach ($perms as $perm)
3003  {
3004  print '<tr class="oddeven">';
3005 
3006  print '<td>';
3007  print $perm[0];
3008  print '</td>';
3009 
3010  print '<td>';
3011  print $perm[1];
3012  print '</td>';
3013 
3014  print '<td>';
3015  print $perm[4];
3016  print '</td>';
3017 
3018  print '<td>';
3019  print $perm[5];
3020  print '</td>';
3021 
3022  print '</tr>';
3023  }
3024  } else {
3025  print '<tr><td class="opacitymedium" colspan="4">'.$langs->trans("None").'</td></tr>';
3026  }
3027 
3028  print '</table>';
3029  print '</div>';
3030 
3031  print '</form>';
3032  } else {
3033  $fullpathoffile = dol_buildpath($file, 0);
3034 
3035  $content = file_get_contents($fullpathoffile);
3036 
3037  // New module
3038  print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
3039  print '<input type="hidden" name="token" value="'.newToken().'">';
3040  print '<input type="hidden" name="action" value="savefile">';
3041  print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
3042  print '<input type="hidden" name="tab" value="'.$tab.'">';
3043  print '<input type="hidden" name="module" value="'.$module.'">';
3044 
3045  $doleditor = new DolEditor('editfilecontent', $content, '', '300', 'Full', 'In', true, false, 'ace', 0, '99%');
3046  print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ?GETPOST('format', 'aZ09') : 'html'));
3047  print '<br>';
3048  print '<center>';
3049  print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
3050  print ' &nbsp; ';
3051  print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
3052  print '</center>';
3053 
3054  print '</form>';
3055  }
3056  }
3057 
3058  if ($tab == 'hooks')
3059  {
3060  if ($action != 'editfile' || empty($file))
3061  {
3062  print '<span class="opacitymedium">'.$langs->trans("HooksDefDesc").'</span><br>';
3063  print '<br>';
3064 
3065  print '<table>';
3066 
3067  $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
3068  print '<tr><td>';
3069  print '<span class="fa fa-file-o"></span> '.$langs->trans("DescriptorFile").' : <strong class="">'.$pathtofile.'</strong>';
3070  print '</td><td>';
3071  print '<a class="editfielda paddingleft paddingright" href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&format=php&file='.urlencode($pathtofile).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
3072  print '</td></tr>';
3073 
3074  print '<tr><td>';
3075  $pathtohook = strtolower($module).'/class/actions_'.strtolower($module).'.class.php';
3076  print '<span class="fa fa-file-o"></span> '.$langs->trans("HooksFile").' : ';
3077  if (dol_is_file($dirins.'/'.$pathtohook))
3078  {
3079  print '<strong>'.$pathtohook.'</strong>';
3080  print '</td>';
3081  print '<td><a class="editfielda paddingleft paddingright" href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&format=php&file='.urlencode($pathtohook).'">'.img_picto($langs->trans("Edit"), 'edit').'</a> ';
3082  print '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=confirm_removefile&format='.$format.'&file='.urlencode($pathtohook).'">'.img_picto($langs->trans("Delete"), 'delete').'</a></td>';
3083  } else {
3084  print '<span class="opacitymedium">'.$langs->trans("FileNotYetGenerated").'</span>';
3085  print '<a href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=inithook&format=php&file='.urlencode($pathtohook).'"><input type="button" class="button smallpaddingimp" value="'.$langs->trans("Generate").'"></a></td>';
3086  print '<td></td>';
3087  }
3088  print '</tr>';
3089  } else {
3090  $fullpathoffile = dol_buildpath($file, 0);
3091 
3092  $content = file_get_contents($fullpathoffile);
3093 
3094  // New module
3095  print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
3096  print '<input type="hidden" name="token" value="'.newToken().'">';
3097  print '<input type="hidden" name="action" value="savefile">';
3098  print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
3099  print '<input type="hidden" name="tab" value="'.$tab.'">';
3100  print '<input type="hidden" name="module" value="'.$module.'">';
3101 
3102  $doleditor = new DolEditor('editfilecontent', $content, '', '300', 'Full', 'In', true, false, 'ace', 0, '99%');
3103  print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ?GETPOST('format', 'aZ09') : 'html'));
3104  print '<br>';
3105  print '<center>';
3106  print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
3107  print ' &nbsp; ';
3108  print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
3109  print '</center>';
3110 
3111  print '</form>';
3112  }
3113  }
3114 
3115  if ($tab == 'triggers')
3116  {
3117  require_once DOL_DOCUMENT_ROOT.'/core/class/interfaces.class.php';
3118 
3119  $interfaces = new Interfaces($db);
3120  $triggers = $interfaces->getTriggersList(array('/'.strtolower($module).'/core/triggers'));
3121 
3122  if ($action != 'editfile' || empty($file))
3123  {
3124  print '<span class="opacitymedium">'.$langs->trans("TriggerDefDesc").'</span><br>';
3125  print '<br>';
3126 
3127  print '<table>';
3128 
3129  $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
3130  print '<tr><td>';
3131  print '<span class="fa fa-file-o"></span> '.$langs->trans("DescriptorFile").' : <strong class="">'.$pathtofile.'</strong>';
3132  print '</td><td>';
3133  print '<a class="editfielda paddingleft paddingright" href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&format=php&file='.urlencode($pathtofile).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
3134  print '</td></tr>';
3135 
3136  if (!empty($triggers))
3137  {
3138  foreach ($triggers as $trigger)
3139  {
3140  $pathtofile = $trigger['relpath'];
3141 
3142  print '<tr><td>';
3143  print '<span class="fa fa-file-o"></span> '.$langs->trans("TriggersFile").' : <strong>'.$pathtofile.'</strong>';
3144  print '</td><td><a class="editfielda paddingleft paddingright" href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&format=php&file='.urlencode($pathtofile).'">'.img_picto($langs->trans("Edit"), 'edit').'</a></td>';
3145  print '<td><a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=confirm_removefile&format='.$format.'&file='.urlencode($pathtofile).'">'.img_picto($langs->trans("Delete"), 'delete').'</a></td>';
3146  print '</tr>';
3147  }
3148  } else {
3149  print '<tr><td>';
3150  print '<span class="fa fa-file-o"></span> '.$langs->trans("NoTrigger");
3151  print '<a href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=inittrigger&format=php"><input type="button" class="button smallpaddingimp" value="'.$langs->trans("Generate").'"></a></td>';
3152  print '<td></td>';
3153  print '</tr>';
3154  }
3155 
3156  print '</table>';
3157  } else {
3158  $fullpathoffile = dol_buildpath($file, 0);
3159 
3160  $content = file_get_contents($fullpathoffile);
3161 
3162  // New module
3163  print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
3164  print '<input type="hidden" name="token" value="'.newToken().'">';
3165  print '<input type="hidden" name="action" value="savefile">';
3166  print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
3167  print '<input type="hidden" name="tab" value="'.$tab.'">';
3168  print '<input type="hidden" name="module" value="'.$module.'">';
3169 
3170  $doleditor = new DolEditor('editfilecontent', $content, '', '300', 'Full', 'In', true, false, 'ace', 0, '99%');
3171  print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ?GETPOST('format', 'aZ09') : 'html'));
3172  print '<br>';
3173  print '<center>';
3174  print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
3175  print ' &nbsp; ';
3176  print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
3177  print '</center>';
3178 
3179  print '</form>';
3180  }
3181  }
3182 
3183  if ($tab == 'css')
3184  {
3185  if ($action != 'editfile' || empty($file))
3186  {
3187  print '<span class="opacitymedium">'.$langs->trans("CSSDesc").'</span><br>';
3188  print '<br>';
3189 
3190  print '<table>';
3191 
3192  print '<tr><td>';
3193  $pathtohook = strtolower($module).'/css/'.strtolower($module).'.css.php';
3194  print '<span class="fa fa-file-o"></span> '.$langs->trans("CSSFile").' : ';
3195  if (dol_is_file($dirins.'/'.$pathtohook))
3196  {
3197  print '<strong>'.$pathtohook.'</strong>';
3198  print '</td><td><a class="editfielda paddingleft paddingright" href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&format=php&file='.urlencode($pathtohook).'">'.img_picto($langs->trans("Edit"), 'edit').'</a></td>';
3199  print '</td><td><a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=confirm_removefile&format='.$format.'&file='.urlencode($pathtohook).'">'.img_picto($langs->trans("Delete"), 'delete').'</a></td>';
3200  } else {
3201  print '<span class="opacitymedium">'.$langs->trans("FileNotYetGenerated").'</span>';
3202  print '</td><td><a href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=initcss&format=php&file='.urlencode($pathtohook).'"><input type="button" class="button smallpaddingimp" value="'.$langs->trans("Generate").'"></a></td>';
3203  }
3204  print '</tr>';
3205  } else {
3206  $fullpathoffile = dol_buildpath($file, 0);
3207 
3208  $content = file_get_contents($fullpathoffile);
3209 
3210  // New module
3211  print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
3212  print '<input type="hidden" name="token" value="'.newToken().'">';
3213  print '<input type="hidden" name="action" value="savefile">';
3214  print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
3215  print '<input type="hidden" name="tab" value="'.$tab.'">';
3216  print '<input type="hidden" name="module" value="'.$module.'">';
3217 
3218  $doleditor = new DolEditor('editfilecontent', $content, '', '300', 'Full', 'In', true, false, 'ace', 0, '99%');
3219  print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ?GETPOST('format', 'aZ09') : 'html'));
3220  print '<br>';
3221  print '<center>';
3222  print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
3223  print ' &nbsp; ';
3224  print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
3225  print '</center>';
3226 
3227  print '</form>';
3228  }
3229  }
3230 
3231  if ($tab == 'js')
3232  {
3233  if ($action != 'editfile' || empty($file))
3234  {
3235  print '<span class="opacitymedium">'.$langs->trans("JSDesc").'</span><br>';
3236  print '<br>';
3237 
3238  print '<table>';
3239 
3240  print '<tr><td>';
3241  $pathtohook = strtolower($module).'/js/'.strtolower($module).'.js.php';
3242  print '<span class="fa fa-file-o"></span> '.$langs->trans("JSFile").' : ';
3243  if (dol_is_file($dirins.'/'.$pathtohook))
3244  {
3245  print '<strong>'.$pathtohook.'</strong>';
3246  print '</td><td><a class="editfielda paddingleft paddingright" href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&format=php&file='.urlencode($pathtohook).'">'.img_picto($langs->trans("Edit"), 'edit').'</a></td>';
3247  print '</td><td><a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=confirm_removefile&format='.$format.'&file='.urlencode($pathtohook).'">'.img_picto($langs->trans("Delete"), 'delete').'</a></td>';
3248  } else {
3249  print '<span class="opacitymedium">'.$langs->trans("FileNotYetGenerated").'</span>';
3250  print '</td><td><a href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=initjs&format=php&file='.urlencode($pathtohook).'"><input type="button" class="button smallpaddingimp" value="'.$langs->trans("Generate").'"></a></td>';
3251  }
3252  print '</tr>';
3253  } else {
3254  $fullpathoffile = dol_buildpath($file, 0);
3255 
3256  $content = file_get_contents($fullpathoffile);
3257 
3258  // New module
3259  print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
3260  print '<input type="hidden" name="token" value="'.newToken().'">';
3261  print '<input type="hidden" name="action" value="savefile">';
3262  print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
3263  print '<input type="hidden" name="tab" value="'.$tab.'">';
3264  print '<input type="hidden" name="module" value="'.$module.'">';
3265 
3266  $doleditor = new DolEditor('editfilecontent', $content, '', '300', 'Full', 'In', true, false, 'ace', 0, '99%');
3267  print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ?GETPOST('format', 'aZ09') : 'html'));
3268  print '<br>';
3269  print '<center>';
3270  print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
3271  print ' &nbsp; ';
3272  print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
3273  print '</center>';
3274 
3275  print '</form>';
3276  }
3277  }
3278 
3279  if ($tab == 'widgets')
3280  {
3281  require_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
3282 
3283  $widgets = ModeleBoxes::getWidgetsList(array('/'.strtolower($module).'/core/boxes'));
3284 
3285  if ($action != 'editfile' || empty($file))
3286  {
3287  print '<span class="opacitymedium">'.$langs->trans("WidgetDesc").'</span><br>';
3288  print '<br>';
3289 
3290  print '<table>';
3291  if (!empty($widgets))
3292  {
3293  foreach ($widgets as $widget)
3294  {
3295  $pathtofile = $widget['relpath'];
3296 
3297  print '<tr><td><span class="fa fa-file-o"></span> '.$langs->trans("WidgetFile").' : <strong>'.$pathtofile.'</strong>';
3298  print '</td><td><a class="editfielda paddingleft paddingright" href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&format=php&file='.urlencode($pathtofile).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
3299  print '</td><td><a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=confirm_removefile&format='.$format.'&file='.urlencode($pathtofile).'">'.img_picto($langs->trans("Delete"), 'delete').'</a></td>';
3300  print '</tr>';
3301  }
3302  } else {
3303  print '<tr><td><span class="fa fa-file-o"></span> '.$langs->trans("NoWidget");
3304  print '</td><td><a href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=initwidget&format=php"><input type="button" class="button smallpaddingimp" value="'.$langs->trans("Generate").'"></a>';
3305  print '</td></tr>';
3306  }
3307  print '</table>';
3308  } else {
3309  $fullpathoffile = dol_buildpath($file, 0);
3310 
3311  $content = file_get_contents($fullpathoffile);
3312 
3313  // New module
3314  print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
3315  print '<input type="hidden" name="token" value="'.newToken().'">';
3316  print '<input type="hidden" name="action" value="savefile">';
3317  print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
3318  print '<input type="hidden" name="tab" value="'.$tab.'">';
3319  print '<input type="hidden" name="module" value="'.$module.'">';
3320 
3321  $doleditor = new DolEditor('editfilecontent', $content, '', '300', 'Full', 'In', true, false, 'ace', 0, '99%');
3322  print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ?GETPOST('format', 'aZ09') : 'html'));
3323  print '<br>';
3324  print '<center>';
3325  print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
3326  print ' &nbsp; ';
3327  print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
3328  print '</center>';
3329 
3330  print '</form>';
3331  }
3332  }
3333 
3334  if ($tab == 'cli')
3335  {
3336  $clifiles = array();
3337  $i = 0;
3338 
3339  $dircli = array('/'.strtolower($module).'/scripts');
3340 
3341  foreach ($dircli as $reldir)
3342  {
3343  $dir = dol_buildpath($reldir, 0);
3344  $newdir = dol_osencode($dir);
3345 
3346  // Check if directory exists (we do not use dol_is_dir to avoid loading files.lib.php at each call)
3347  if (!is_dir($newdir)) continue;
3348 
3349  $handle = opendir($newdir);
3350  if (is_resource($handle))
3351  {
3352  while (($tmpfile = readdir($handle)) !== false)
3353  {
3354  if (is_readable($newdir.'/'.$file) && preg_match('/^(.+)\.php/', $tmpfile, $reg))
3355  {
3356  if (preg_match('/\.back$/', $tmpfile)) continue;
3357 
3358  $clifiles[$i]['relpath'] = preg_replace('/^\//', '', $reldir).'/'.$tmpfile;
3359 
3360  $i++;
3361  }
3362  }
3363  closedir($handle);
3364  }
3365  }
3366 
3367  if ($action != 'editfile' || empty($file))
3368  {
3369  print '<span class="opacitymedium">'.$langs->trans("CLIDesc").'</span><br>';
3370  print '<br>';
3371 
3372  print '<table>';
3373  if (!empty($clifiles))
3374  {
3375  foreach ($clifiles as $clifile)
3376  {
3377  $pathtofile = $clifile['relpath'];
3378 
3379  print '<tr><td><span class="fa fa-file-o"></span> '.$langs->trans("CLIFile").' : <strong>'.$pathtofile.'</strong>';
3380  print '</td><td><a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&format=php&file='.urlencode($pathtofile).'">'.img_picto($langs->trans("Edit"), 'edit').'</a></td>';
3381  print '<td><a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=confirm_removefile&format='.$format.'&file='.urlencode($pathtofile).'">'.img_picto($langs->trans("Delete"), 'delete').'</a></td>';
3382  print '</tr>';
3383  }
3384  } else {
3385  print '<tr><td><span class="fa fa-file-o"></span> '.$langs->trans("NoCLIFile");
3386  print '</td><td><a href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=initcli&format=php"><input type="button" class="button smallpaddingimp" value="'.$langs->trans("Generate").'"></a>';
3387  print '</td></tr>';
3388  }
3389  print '</table>';
3390  } else {
3391  $fullpathoffile = dol_buildpath($file, 0);
3392 
3393  $content = file_get_contents($fullpathoffile);
3394 
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="savefile">';
3399  print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
3400  print '<input type="hidden" name="tab" value="'.$tab.'">';
3401  print '<input type="hidden" name="module" value="'.$module.'">';
3402 
3403  $doleditor = new DolEditor('editfilecontent', $content, '', '300', 'Full', 'In', true, false, 'ace', 0, '99%');
3404  print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ?GETPOST('format', 'aZ09') : 'html'));
3405  print '<br>';
3406  print '<center>';
3407  print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
3408  print ' &nbsp; ';
3409  print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
3410  print '</center>';
3411 
3412  print '</form>';
3413  }
3414  }
3415 
3416  if ($tab == 'cron')
3417  {
3418  $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
3419 
3420  $cronjobs = $moduleobj->cronjobs;
3421 
3422  if ($action != 'editfile' || empty($file))
3423  {
3424  print '<span class="opacitymedium">'.str_replace('{s1}', '<a href="'.DOL_URL_ROOT.'/cron/list.php">'.$langs->transnoentities('CronList').'</a>', $langs->trans("CronJobDefDesc", '{s1}')).'</span><br>';
3425  print '<br>';
3426 
3427  print '<span class="fa fa-file-o"></span> '.$langs->trans("DescriptorFile").' : <strong>'.$pathtofile.'</strong>';
3428  print ' <a class="editfielda paddingleft paddingright" href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&format=php&file='.urlencode($pathtofile).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
3429  print '<br>';
3430 
3431  print '<br>';
3432  print load_fiche_titre($langs->trans("CronJobProfiles"), '', '');
3433 
3434  print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
3435  print '<input type="hidden" name="token" value="'.newToken().'">';
3436  print '<input type="hidden" name="action" value="addproperty">';
3437  print '<input type="hidden" name="tab" value="objects">';
3438  print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
3439  print '<input type="hidden" name="tabobj" value="'.dol_escape_htmltag($tabobj).'">';
3440 
3441  print '<div class="div-table-responsive">';
3442  print '<table class="noborder">';
3443 
3444  print '<tr class="liste_titre">';
3445  print_liste_field_titre("CronLabel", $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder);
3446  print_liste_field_titre("CronTask", '', '', "", $param, '', $sortfield, $sortorder);
3447  print_liste_field_titre("CronFrequency", '', "", "", $param, '', $sortfield, $sortorder);
3448  print_liste_field_titre("StatusAtInstall", $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder);
3449  print_liste_field_titre("Comment", $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder);
3450  print "</tr>\n";
3451 
3452  if (count($cronjobs))
3453  {
3454  foreach ($cronjobs as $cron)
3455  {
3456  print '<tr class="oddeven">';
3457 
3458  print '<td>';
3459  print $cron['label'];
3460  print '</td>';
3461 
3462  print '<td>';
3463  if ($cron['jobtype'] == 'method')
3464  {
3465  $text = $langs->trans("CronClass");
3466  $texttoshow = $langs->trans('CronModule').': '.$module.'<br>';
3467  $texttoshow .= $langs->trans('CronClass').': '.$cron['class'].'<br>';
3468  $texttoshow .= $langs->trans('CronObject').': '.$cron['objectname'].'<br>';
3469  $texttoshow .= $langs->trans('CronMethod').': '.$cron['method'];
3470  $texttoshow .= '<br>'.$langs->trans('CronArgs').': '.$cron['parameters'];
3471  $texttoshow .= '<br>'.$langs->trans('Comment').': '.$langs->trans($cron['comment']);
3472  } elseif ($cron['jobtype'] == 'command')
3473  {
3474  $text = $langs->trans('CronCommand');
3475  $texttoshow = $langs->trans('CronCommand').': '.dol_trunc($cron['command']);
3476  $texttoshow .= '<br>'.$langs->trans('CronArgs').': '.$cron['parameters'];
3477  $texttoshow .= '<br>'.$langs->trans('Comment').': '.$langs->trans($cron['comment']);
3478  }
3479  print $form->textwithpicto($text, $texttoshow, 1);
3480  print '</td>';
3481 
3482  print '<td>';
3483  if ($cron['unitfrequency'] == "60") print $langs->trans('CronEach')." ".($cron['frequency'])." ".$langs->trans('Minutes');
3484  if ($cron['unitfrequency'] == "3600") print $langs->trans('CronEach')." ".($cron['frequency'])." ".$langs->trans('Hours');
3485  if ($cron['unitfrequency'] == "86400") print $langs->trans('CronEach')." ".($cron['frequency'])." ".$langs->trans('Days');
3486  if ($cron['unitfrequency'] == "604800") print $langs->trans('CronEach')." ".($cron['frequency'])." ".$langs->trans('Weeks');
3487  print '</td>';
3488 
3489  print '<td>';
3490  print $cron['status'];
3491  print '</td>';
3492 
3493  print '<td>';
3494  if (!empty($cron['comment'])) {print $cron['comment']; }
3495  print '</td>';
3496 
3497  print '</tr>';
3498  }
3499  } else {
3500  print '<tr><td class="opacitymedium" colspan="5">'.$langs->trans("None").'</td></tr>';
3501  }
3502 
3503  print '</table>';
3504  print '</div>';
3505 
3506  print '</form>';
3507  } else {
3508  $fullpathoffile = dol_buildpath($file, 0);
3509 
3510  $content = file_get_contents($fullpathoffile);
3511 
3512  // New module
3513  print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
3514  print '<input type="hidden" name="token" value="'.newToken().'">';
3515  print '<input type="hidden" name="action" value="savefile">';
3516  print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
3517  print '<input type="hidden" name="tab" value="'.$tab.'">';
3518  print '<input type="hidden" name="module" value="'.$module.'">';
3519 
3520  $doleditor = new DolEditor('editfilecontent', $content, '', '300', 'Full', 'In', true, false, 'ace', 0, '99%');
3521  print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ?GETPOST('format', 'aZ09') : 'html'));
3522  print '<br>';
3523  print '<center>';
3524  print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
3525  print ' &nbsp; ';
3526  print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
3527  print '</center>';
3528 
3529  print '</form>';
3530  }
3531  }
3532 
3533  if ($tab == 'specifications')
3534  {
3535  $specs = dol_dir_list(dol_buildpath($modulelowercase.'/doc', 0), 'files', 1, '(\.md|\.asciidoc)$', array('\/temp\/'));
3536 
3537  if ($action != 'editfile' || empty($file))
3538  {
3539  print '<span class="opacitymedium">'.$langs->trans("SpecDefDesc").'</span><br>';
3540  print '<br>';
3541 
3542  print '<table>';
3543  if (is_array($specs) && !empty($specs))
3544  {
3545  foreach ($specs as $spec)
3546  {
3547  $pathtofile = $modulelowercase.'/doc/'.$spec['relativename'];
3548  $format = 'asciidoc';
3549  if (preg_match('/\.md$/i', $spec['name'])) $format = 'markdown';
3550  print '<tr><td>';
3551  print '<span class="fa fa-file-o"></span> '.$langs->trans("SpecificationFile").' : <strong>'.$pathtofile.'</strong>';
3552  print '</td><td><a class="editfielda paddingleft paddingright" href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&format='.$format.'&file='.urlencode($pathtofile).'">'.img_picto($langs->trans("Edit"), 'edit').'</a></td>';
3553  print '<td><a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=confirm_removefile&format='.$format.'&file='.urlencode($pathtofile).'">'.img_picto($langs->trans("Delete"), 'delete').'</a></td>';
3554  print '</tr>';
3555  }
3556  } else {
3557  print '<tr><td>';
3558  print '<span class="fa fa-file-o"></span> '.$langs->trans("FileNotYetGenerated");
3559  print '</td><td><a href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=initdoc&format=php"><input type="button" class="button smallpaddingimp" value="'.$langs->trans("Generate").'"></a></td>';
3560  print '</tr>';
3561  }
3562  print '</table>';
3563  } else {
3564  // Use MD or asciidoc
3565 
3566  //print $langs->trans("UseAsciiDocFormat").'<br>';
3567 
3568  $fullpathoffile = dol_buildpath($file, 0);
3569 
3570  $content = file_get_contents($fullpathoffile);
3571 
3572  // New module
3573  print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
3574  print '<input type="hidden" name="token" value="'.newToken().'">';
3575  print '<input type="hidden" name="action" value="savefile">';
3576  print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
3577  print '<input type="hidden" name="tab" value="'.$tab.'">';
3578  print '<input type="hidden" name="module" value="'.$module.'">';
3579 
3580  $doleditor = new DolEditor('editfilecontent', $content, '', '300', 'Full', 'In', true, false, 'ace', 0, '99%');
3581  print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ?GETPOST('format', 'aZ09') : 'html'));
3582  print '<br>';
3583  print '<center>';
3584  print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
3585  print ' &nbsp; ';
3586  print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
3587  print '</center>';
3588 
3589  print '</form>';
3590  }
3591 
3592  print '<br><br><br>';
3593 
3594  $FILENAMEDOC = $modulelowercase.'.html';
3595  $FILENAMEDOCPDF = $modulelowercase.'.pdf';
3596  $outputfiledoc = dol_buildpath($modulelowercase, 0).'/doc/'.$FILENAMEDOC;
3597  $outputfiledocurl = dol_buildpath($modulelowercase, 1).'/doc/'.$FILENAMEDOC;
3598  $outputfiledocpdf = dol_buildpath($modulelowercase, 0).'/doc/'.$FILENAMEDOCPDF;
3599  $outputfiledocurlpdf = dol_buildpath($modulelowercase, 1).'/doc/'.$FILENAMEDOCPDF;
3600 
3601  // HTML
3602  print '<span class="fa fa-file-o"></span> '.$langs->trans("PathToModuleDocumentation", "HTML").' : ';
3603  if (!dol_is_file($outputfiledoc)) print '<span class="opacitymedium">'.$langs->trans("FileNotYetGenerated").'</span>';
3604  else {
3605  print '<strong>';
3606  print '<a href="'.$outputfiledocurl.'" target="_blank">';
3607  print $outputfiledoc;
3608  print '</a>';
3609  print '</strong>';
3610  print ' ('.$langs->trans("GeneratedOn").' '.dol_print_date(dol_filemtime($outputfiledoc), 'dayhour').')';
3611  }
3612  print '</strong><br>';
3613 
3614  // PDF
3615  print '<span class="fa fa-file-o"></span> '.$langs->trans("PathToModuleDocumentation", "PDF").' : ';
3616  if (!dol_is_file($outputfiledocpdf)) print '<span class="opacitymedium">'.$langs->trans("FileNotYetGenerated").'</span>';
3617  else {
3618  print '<strong>';
3619  print '<a href="'.$outputfiledocurlpdf.'" target="_blank">';
3620  print $outputfiledocpdf;
3621  print '</a>';
3622  print '</strong>';
3623  print ' ('.$langs->trans("GeneratedOn").' '.dol_print_date(dol_filemtime($outputfiledocpdf), 'dayhour').')';
3624  }
3625  print '</strong><br>';
3626 
3627  print '<br>';
3628 
3629  print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST" name="generatedoc">';
3630  print '<input type="hidden" name="token" value="'.newToken().'">';
3631  print '<input type="hidden" name="action" value="generatedoc">';
3632  print '<input type="hidden" name="tab" value="'.dol_escape_htmltag($tab).'">';
3633  print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
3634  print '<input type="submit" class="button" name="generatedoc" value="'.$langs->trans("BuildDocumentation").'"';
3635  if (!is_array($specs) || empty($specs)) print ' disabled="disabled"';
3636  print '>';
3637  print '</form>';
3638  }
3639 
3640  if ($tab == 'buildpackage')
3641  {
3642  print '<span class="opacitymedium">'.$langs->trans("BuildPackageDesc").'</span>';
3643  print '<br>';
3644 
3645  if (!class_exists('ZipArchive') && !defined('ODTPHP_PATHTOPCLZIP'))
3646  {
3647  print img_warning().' '.$langs->trans("ErrNoZipEngine");
3648  print '<br>';
3649  }
3650 
3651  $modulelowercase = strtolower($module);
3652 
3653  // Zip file to build
3654  $FILENAMEZIP = '';
3655 
3656  // Load module
3657  $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
3658  dol_include_once($pathtofile);
3659  $class = 'mod'.$module;
3660 
3661  if (class_exists($class))
3662  {
3663  try {
3664  $moduleobj = new $class($db);
3665  } catch (Exception $e) {
3666  $error++;
3667  dol_print_error($e->getMessage());
3668  }
3669  } else {
3670  $error++;
3671  $langs->load("errors");
3672  dol_print_error($langs->trans("ErrorFailedToLoadModuleDescriptorForXXX", $module));
3673  exit;
3674  }
3675 
3676  $arrayversion = explode('.', $moduleobj->version, 3);
3677  if (count($arrayversion))
3678  {
3679  $FILENAMEZIP = "module_".$modulelowercase.'-'.$arrayversion[0].'.'.$arrayversion[1].($arrayversion[2] ? ".".$arrayversion[2] : "").".zip";
3680  $outputfilezip = dol_buildpath($modulelowercase, 0).'/bin/'.$FILENAMEZIP;
3681  }
3682 
3683  print '<br>';
3684 
3685  print '<span class="fa fa-file-o"></span> '.$langs->trans("PathToModulePackage").' : ';
3686  if (!dol_is_file($outputfilezip)) print '<span class="opacitymedium">'.$langs->trans("FileNotYetGenerated").'</span>';
3687  else {
3688  $relativepath = $modulelowercase.'/bin/'.$FILENAMEZIP;
3689  print '<strong><a href="'.DOL_URL_ROOT.'/document.php?modulepart=packages&file='.urlencode($relativepath).'">'.$outputfilezip.'</a></strong>';
3690  print ' ('.$langs->trans("GeneratedOn").' '.dol_print_date(dol_filemtime($outputfilezip), 'dayhour').')';
3691  }
3692  print '</strong><br>';
3693 
3694  print '<br>';
3695 
3696  print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST" name="generatepackage">';
3697  print '<input type="hidden" name="token" value="'.newToken().'">';
3698  print '<input type="hidden" name="action" value="generatepackage">';
3699  print '<input type="hidden" name="tab" value="'.dol_escape_htmltag($tab).'">';
3700  print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
3701  print '<input type="submit" class="button" name="generatepackage" value="'.$langs->trans("BuildPackage").'">';
3702  print '</form>';
3703  }
3704 
3705  if ($tab != 'description')
3706  {
3707  print dol_get_fiche_end();
3708  }
3709  }
3710 }
3711 
3712 print dol_get_fiche_end(); // End modules
3713 
3714 // End of page
3715 llxFooter();
3716 $db->close();
if(!function_exists('dol_getprefix')) dol_include_once($relpath, $classname= '')
Make an include_once using default root and alternate root if it fails.
dol_osencode($str)
Return a string encoded into OS filesystem encoding.
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Class to manage utility methods.
Definition: utils.class.php:28
dol_copy($srcfile, $destfile, $newmask=0, $overwriteifexists=1)
Copy a file to another file.
Definition: files.lib.php:663
dolCopyDir($srcfile, $destfile, $newmask, $overwriteifexists, $arrayreplacement=null, $excludesubdir=0)
Copy a dir to another dir.
Definition: files.lib.php:720
dol_sanitizePathName($str, $newstr= '_', $unaccent=1)
Clean a string to use it as a path name.
unActivateModule($value, $requiredby=1)
Disable a module.
Definition: admin.lib.php:1100
dol_now($mode= 'auto')
Return date for now.
static getWidgetsList($forcedirwidget=null)
Return list of widget.
dol_is_dir($folder)
Test if filename is a directory.
Definition: files.lib.php:432
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
img_warning($titlealt= 'default', $moreatt= '', $morecss= 'pictowarning')
Show warning logo.
Class to generate html code for admin pages.
llxHeader()
Empty header.
Definition: wrapper.php:45
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
Class to manage generation of HTML components Only common components must be here.
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
dol_mimetype($file, $default= 'application/octet-stream', $mode=0)
Return mime type of a file.
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt= '', $morecss= '', $marginleftonlyshort=2)
Show picto whatever it&#39;s its name (generic function)
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
dol_delete_dir_recursive($dir, $count=0, $nophperrors=0, $onlysub=0, &$countdeleted=0)
Remove a directory $dir and its subdirectories (or only files and subdirectories) ...
Definition: files.lib.php:1286
dol_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null, $allowdotdot=false, $indexdatabase=1)
Remove a file or several files with a mask.
Definition: files.lib.php:1144
restrictedArea($user, $features, $objectid=0, $tableandshare= '', $feature2= '', $dbt_keyfield= 'fk_soc', $dbt_select= 'rowid', $isdraft=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 Calling this function terminate execution ...
dol_sanitizeFileName($str, $newstr= '_', $unaccent=1)
Clean a string to use it as a file name.
dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0)
Scan a directory and return a list of files/directories.
Definition: files.lib.php:60
dol_is_file($pathoffile)
Return if path is a file.
Definition: files.lib.php:457
print $_SERVER["PHP_SELF"]
Edit parameters.
dolReplaceInFile($srcfile, $arrayreplacement, $destfile= '', $newmask=0, $indexdatabase=0, $arrayreplacementisregex=0)
Make replacement of strings into a file.
Definition: files.lib.php:585
dol_sort_array(&$array, $index, $order= 'asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by second index function, which produces ascending (default) or descending output...
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
print
Draft customers invoices.
Definition: index.php:89
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_filemtime($pathoffile)
Return time of a file.
Definition: files.lib.php:567
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1232
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
newToken()
Return the value of token currently saved into session with name &#39;newtoken&#39;.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
activateModule($value, $withdeps=1)
Enable a module.
Definition: admin.lib.php:971
Class to manage a WYSIWYG editor.
dol_trunc($string, $size=40, $trunc= 'right', $stringencoding= 'UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding &#39;...&#39; if string larger than length.
dol_delete_dir($dir, $nophperrors=0)
Remove a directory (not recursive, so content must be empty).
Definition: files.lib.php:1262
llxFooter()
Empty footer.
Definition: wrapper.php:59
img_delete($titlealt= 'default', $other= 'class="pictodelete"', $morecss= '')
Show delete logo.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin= '1', $morecss= '', $textfordropdown= '')
Show information for admin users or standard users.
Class to manage triggers.
dol_mkdir($dir, $dataroot= '', $newmask=null)
Creation of a directory (this can create recursive subdir)
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $keepmoretags= '', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields...
dol_is_dir_empty($dir)
Return if path is empty.
Definition: files.lib.php:445