index.php 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. <?php
  2. /* Copyright (C) 2001-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2017 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2010 Regis Houssin <regis.houssin@capnetworks.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file htdocs/modulebuilder/index.php
  21. * \brief Home page for module builder module
  22. */
  23. require '../main.inc.php';
  24. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  25. $langs->load("admin");
  26. $langs->load("modulebuilder");
  27. $langs->load("other");
  28. $action=GETPOST('action','alpha');
  29. $confirm=GETPOST('confirm','alpha');
  30. $module=GETPOST('module');
  31. if (empty($module)) $module='initmodule';
  32. if (empty($tab)) $tab='description';
  33. $modulename=dol_sanitizeFileName(GETPOST('modulename','alpha'));
  34. // Security check
  35. if (! $user->admin && empty($conf->global->MODULEBUILDER_FOREVERYONE)) accessforbidden('ModuleBuilderNotAllowed');
  36. // Dir for custom dirs
  37. $tmp=explode(',', $dolibarr_main_document_root_alt);
  38. $dircustom = $tmp[0];
  39. $FILEFLAG='modulebuilder.txt';
  40. /*
  41. * Actions
  42. */
  43. if ($dircustom && $action == 'initmodule' && $modulename)
  44. {
  45. $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
  46. $destdir = $dircustom.'/'.$modulename;
  47. $arrayreplacement=array(
  48. 'mymodule'=>strtolower($modulename),
  49. 'MyModule'=>$modulename
  50. );
  51. $result = dolCopyDir($srcdir, $destdir, 0, 0);
  52. //dol_mkdir($destfile);
  53. if ($result <= 0)
  54. {
  55. $error++;
  56. $langs->load("errors");
  57. setEventMessages($langs->trans("ErrorFailToCopyDir", $srcdir, $destdir), null, 'errors');
  58. }
  59. // Edit PHP files
  60. if (! $error)
  61. {
  62. $listofphpfilestoedit = dol_dir_list($destdir, 'files', 1, '\.php$', '', 'fullname', SORT_ASC, 0, 1);
  63. foreach($listofphpfilestoedit as $phpfileval)
  64. {
  65. var_dump($phpfileval['fullname']);
  66. $arrayreplacement=array(
  67. 'mymodule'=>strtolower($modulename),
  68. 'MyModule'=>$modulename,
  69. 'MYMODULE'=>strtoupper($modulename),
  70. 'My module'=>$modulename,
  71. 'htdocs/modulebuilder/template/'=>'',
  72. );
  73. $result=dolReplaceInFile($phpfileval['fullname'], $arrayreplacement);
  74. //var_dump($result);
  75. if ($result < 0)
  76. {
  77. setEventMessages($langs->trans("ErrorFailToMakeReplacementInto", $phpfileval['fullname']), null, 'errors');
  78. }
  79. }
  80. }
  81. if (! $error)
  82. {
  83. setEventMessages('ModuleInitialized', null);
  84. $module=$modulename;
  85. $modulename = '';
  86. }
  87. }
  88. /*
  89. * View
  90. */
  91. llxHeader("",$langs->trans("ModuleBuilder"),"");
  92. $text=$langs->trans("ModuleBuilder");
  93. print load_fiche_titre($text, '', 'title_setup');
  94. $listofmodules=array();
  95. /*
  96. if (!empty($conf->modulebuilder->enabled) && $mainmenu == 'modulebuilder') // Entry for Module builder
  97. {
  98. global $dolibarr_main_document_root_alt;
  99. if (! empty($dolibarr_main_document_root_alt) && is_array($dolibarr_main_document_root_alt))
  100. {
  101. foreach ($dolibarr_main_document_root_alt as $diralt)
  102. {*/
  103. $dirsincustom=dol_dir_list($dircustom, 'directories');
  104. if (is_array($dirsincustom) && count($dirsincustom) > 0)
  105. {
  106. foreach ($dirsincustom as $dircustomcursor)
  107. {
  108. $fullname = $dircustomcursor['fullname'];
  109. if (dol_is_file($fullname.'/'.$FILEFLAG))
  110. {
  111. $listofmodules[$dircustomcursor['name']]=$fullname;
  112. }
  113. }
  114. }
  115. /* }
  116. }
  117. else
  118. {
  119. $newmenu->add('', 'NoGeneratedModuleFound', 0, 0);
  120. }*/
  121. // Show description of content
  122. print $langs->trans("ModuleBuilderDesc").'<br>';
  123. print $langs->trans("ModuleBuilderDesc2", 'conf/conf.php', $dircustom).'<br>';
  124. print $langs->trans("ModuleBuilderDesc3", count($listofmodules), $FILEFLAG).'<br>';
  125. print '<br>';
  126. print '<br>';
  127. $head = array();
  128. $h=0;
  129. $head[$h][0] = $_SERVER["PHP_SELF"].'?module=initmodule';
  130. $head[$h][1] = $langs->trans("NewModule");
  131. $head[$h][2] = 'initmodule';
  132. $h++;
  133. foreach($listofmodules as $tmpmodule => $fullname)
  134. {
  135. $head[$h][0] = $_SERVER["PHP_SELF"].'?module='.$tmpmodule;
  136. $head[$h][1] = $tmpmodule;
  137. $head[$h][2] = $tmpmodule;
  138. $h++;
  139. }
  140. dol_fiche_head($head, $module, $langs->trans("Modules"), -1, 'generic');
  141. if ($module == 'initmodule')
  142. {
  143. // New module
  144. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  145. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  146. print '<input type="hidden" name="action" value="initmodule">';
  147. print '<input type="hidden" name="module" value="initmodule">';
  148. print $langs->trans("EnterNameOfModuleDesc").'<br><br>';
  149. print '<input type="text" name="modulename" value="'.dol_escape_htmltag($modulename).'" placeholder="'.dol_escape_htmltag($langs->trans("ModuleKey")).'">';
  150. print '<input type="submit" class="button" name="create" value="'.dol_escape_htmltag($langs->trans("Create")).'">';
  151. print '</form>';
  152. }
  153. elseif (! empty($module))
  154. {
  155. $error=0;
  156. // Load module
  157. dol_include_once($module.'/core/modules/mod'.ucfirst($module).'.class.php');
  158. $class='mod'.ucfirst($module);
  159. if (class_exists($class))
  160. {
  161. try {
  162. $moduleobj = new $class($db);
  163. }
  164. catch(Exception $e)
  165. {
  166. $error++;
  167. print $e->getMessage();
  168. }
  169. }
  170. else
  171. {
  172. $error++;
  173. $langs->load("errors");
  174. print img_warning('').' '.$langs->trans("ErrorFailedToLoadModuleDescriptorForXXX", $module);
  175. }
  176. // Button to delete module
  177. // Tabs for module
  178. if (! $error)
  179. {
  180. $head2 = array();
  181. $h=0;
  182. foreach($listofmodules as $tmpmodule => $fullname)
  183. {
  184. $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=description';
  185. $head2[$h][1] = $langs->trans("Description");
  186. $head2[$h][2] = 'description';
  187. $h++;
  188. $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=objects';
  189. $head2[$h][1] = $langs->trans("Objects");
  190. $head2[$h][2] = 'objects';
  191. $h++;
  192. $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab='.$tmpmodule;
  193. $head2[$h][1] = $langs->trans("Menus");
  194. $head2[$h][2] = 'menus';
  195. $h++;
  196. $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab='.$tmpmodule;
  197. $head2[$h][1] = $langs->trans("Permissions");
  198. $head2[$h][2] = 'permissions';
  199. $h++;
  200. $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab='.$tmpmodule;
  201. $head2[$h][1] = $langs->trans("Triggers");
  202. $head2[$h][2] = 'triggers';
  203. $h++;
  204. }
  205. dol_fiche_head($head2, $tab, '', -1, '');
  206. print $moduleobj->getDescLong();
  207. dol_fiche_end();
  208. }
  209. }
  210. dol_fiche_end();
  211. llxFooter();
  212. $db->close();