index.php 99 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529
  1. <?php
  2. /* Copyright (C) 2004-2017 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2018 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 <http://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. /**
  22. * \file htdocs/modulebuilder/index.php
  23. * \brief Home page for module builder module
  24. */
  25. if (! defined('NOSCANPOSTFORINJECTION')) define('NOSCANPOSTFORINJECTION','1'); // Do not check anti SQL+XSS injection attack test
  26. require '../main.inc.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/lib/modulebuilder.lib.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/class/utils.class.php';
  33. // Load translation files required by the page
  34. $langs->loadLangs(array("admin", "modulebuilder", "other", "cron", "errors"));
  35. $action=GETPOST('action','aZ09');
  36. $confirm=GETPOST('confirm','alpha');
  37. $cancel=GETPOST('cancel','alpha');
  38. $module=GETPOST('module','alpha');
  39. $tab=GETPOST('tab','aZ09');
  40. $tabobj=GETPOST('tabobj','alpha');
  41. $propertykey=GETPOST('propertykey','alpha');
  42. if (empty($module)) $module='initmodule';
  43. if (empty($tab)) $tab='description';
  44. if (empty($tabobj)) $tabobj='newobjectifnoobj';
  45. $file=GETPOST('file','alpha');
  46. $modulename=dol_sanitizeFileName(GETPOST('modulename','alpha'));
  47. $objectname=dol_sanitizeFileName(GETPOST('objectname','alpha'));
  48. // Security check
  49. if (empty($conf->modulebuilder->enabled)) accessforbidden('ModuleBuilderNotAllowed');
  50. if (! $user->admin && empty($conf->global->MODULEBUILDER_FOREVERYONE)) accessforbidden('ModuleBuilderNotAllowed');
  51. // Dir for custom dirs
  52. $tmp=explode(',', $dolibarr_main_document_root_alt);
  53. $dirins = $tmp[0];
  54. $dirread = $dirins;
  55. $forceddirread = 0;
  56. $tmpdir = explode('@', $module);
  57. if (! empty($tmpdir[1]))
  58. {
  59. $module=$tmpdir[0];
  60. $dirread=$tmpdir[1];
  61. $forceddirread=1;
  62. }
  63. if (GETPOST('dirins','alpha'))
  64. {
  65. $dirread = $dirins = GETPOST('dirins','alpha');
  66. $forceddirread=1;
  67. }
  68. $FILEFLAG='modulebuilder.txt';
  69. $now=dol_now();
  70. $newmask = 0;
  71. if (empty($newmask) && ! empty($conf->global->MAIN_UMASK)) $newmask=$conf->global->MAIN_UMASK;
  72. if (empty($newmask)) // This should no happen
  73. {
  74. $newmask='0664';
  75. }
  76. /*
  77. * Actions
  78. */
  79. if ($dirins && $action == 'initmodule' && $modulename)
  80. {
  81. if (preg_match('/[^a-z0-9_]/i', $modulename))
  82. {
  83. $error++;
  84. setEventMessages($langs->trans("SpaceOrSpecialCharAreNotAllowed"), null, 'errors');
  85. }
  86. if (! $error)
  87. {
  88. $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
  89. $destdir = $dirins.'/'.strtolower($modulename);
  90. $arrayreplacement=array(
  91. 'mymodule'=>strtolower($modulename),
  92. 'MyModule'=>$modulename
  93. );
  94. $result = dolCopyDir($srcdir, $destdir, 0, 0, $arrayreplacement);
  95. //dol_mkdir($destfile);
  96. if ($result <= 0)
  97. {
  98. if ($result < 0)
  99. {
  100. $error++;
  101. $langs->load("errors");
  102. setEventMessages($langs->trans("ErrorFailToCopyDir", $srcdir, $destdir), null, 'errors');
  103. }
  104. else // $result == 0
  105. {
  106. setEventMessages($langs->trans("AllFilesDidAlreadyExist", $srcdir, $destdir), null, 'warnings');
  107. }
  108. }
  109. if (!empty($conf->global->MODULEBUILDER_USE_ABOUT))
  110. {
  111. dol_delete_file($destdir.'/admin/about.php');
  112. }
  113. if (!empty($conf->global->MODULEBUILDER_USE_DOCFOLDER))
  114. {
  115. dol_delete_dir($destdir.'/doc/');
  116. }
  117. // Delete some files related to object (because to previous dolCopyDir has copied everything)
  118. dol_delete_file($destdir.'/myobject_card.php');
  119. dol_delete_file($destdir.'/myobject_note.php');
  120. dol_delete_file($destdir.'/myobject_document.php');
  121. dol_delete_file($destdir.'/myobject_agenda.php');
  122. dol_delete_file($destdir.'/myobject_list.php');
  123. dol_delete_file($destdir.'/lib/mymodule_myobject.lib.php');
  124. dol_delete_file($destdir.'/test/phpunit/MyObjectTest.php');
  125. dol_delete_file($destdir.'/sql/llx_mymodule_myobject.sql');
  126. dol_delete_file($destdir.'/sql/llx_mymodule_myobject_extrafields.sql');
  127. dol_delete_file($destdir.'/sql/llx_mymodule_myobject.key.sql');
  128. dol_delete_file($destdir.'/scripts/myobject.php');
  129. dol_delete_file($destdir.'/img/object_myobject.png');
  130. dol_delete_file($destdir.'/class/myobject.class.php');
  131. dol_delete_file($destdir.'/class/api_mymodule.class.php');
  132. }
  133. // Edit PHP files
  134. if (! $error)
  135. {
  136. $listofphpfilestoedit = dol_dir_list($destdir, 'files', 1, '\.(php|MD|js|sql|txt|xml|lang)$', '', 'fullname', SORT_ASC, 0, 1);
  137. foreach($listofphpfilestoedit as $phpfileval)
  138. {
  139. //var_dump($phpfileval['fullname']);
  140. $arrayreplacement=array(
  141. 'mymodule'=>strtolower($modulename),
  142. 'MyModule'=>$modulename,
  143. 'MYMODULE'=>strtoupper($modulename),
  144. 'My module'=>$modulename,
  145. 'my module'=>$modulename,
  146. 'Mon module'=>$modulename,
  147. 'mon module'=>$modulename,
  148. 'htdocs/modulebuilder/template'=>strtolower($modulename),
  149. '---Put here your own copyright and developer email---'=>dol_print_date($now,'%Y').' '.$user->getFullName($langs).($user->email?' <'.$user->email.'>':'')
  150. );
  151. $result=dolReplaceInFile($phpfileval['fullname'], $arrayreplacement);
  152. //var_dump($result);
  153. if ($result < 0)
  154. {
  155. setEventMessages($langs->trans("ErrorFailToMakeReplacementInto", $phpfileval['fullname']), null, 'errors');
  156. }
  157. }
  158. if (!empty($conf->global->MODULEBUILDER_SPECIFIC_README))
  159. {
  160. dol_delete_file($destdir.'/README.md');
  161. file_put_contents($destdir.'/README.md', $conf->global->MODULEBUILDER_SPECIFIC_README);
  162. }
  163. }
  164. if (! $error)
  165. {
  166. setEventMessages('ModuleInitialized', null);
  167. $module=$modulename;
  168. $modulename = '';
  169. }
  170. }
  171. if ($dirins && $action == 'addlanguage' && !empty($module))
  172. {
  173. $newlangcode=GETPOST('newlangcode', 'aZ09');
  174. $srcfile = $dirins.'/'.strtolower($module).'/langs/en_US';
  175. $destfile = $dirins.'/'.strtolower($module).'/langs/'.$newlangcode;
  176. $result = dolCopyDir($srcfile, $destfile, 0, 0);
  177. }
  178. if ($dirins && $action == 'initobject' && $module && GETPOST('createtablearray','alpha'))
  179. {
  180. $tablename = GETPOST('initfromtablename','alpha');
  181. $_results = $db->DDLDescTable($tablename);
  182. if (empty($_results))
  183. {
  184. setEventMessages($langs->trans("ErrorTableNotFound", $tablename), null, 'errors');
  185. }
  186. else
  187. {
  188. /*public $fields=array(
  189. 'rowid' =>array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'index'=>1, 'position'=>1, 'comment'=>'Id'),
  190. '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'),
  191. 'entity' =>array('type'=>'integer', 'label'=>'Entity', 'enabled'=>1, 'visible'=>0, 'default'=>1, 'notnull'=>1, 'index'=>1, 'position'=>20),
  192. 'label' =>array('type'=>'varchar(255)', 'label'=>'Label', 'enabled'=>1, 'visible'=>1, 'position'=>30, 'searchall'=>1, 'css'=>'minwidth200', 'help'=>'Help text'),
  193. 'amount' =>array('type'=>'double(24,8)', 'label'=>'Amount', 'enabled'=>1, 'visible'=>1, 'default'=>'null', 'position'=>40, 'searchall'=>0, 'isameasure'=>1, 'help'=>'Help text'),
  194. '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'),
  195. 'description' =>array('type'=>'text', 'label'=>'Descrption', 'enabled'=>1, 'visible'=>0, 'position'=>60),
  196. 'note_public' =>array('type'=>'html', 'label'=>'NotePublic', 'enabled'=>1, 'visible'=>0, 'position'=>61),
  197. 'note_private' =>array('type'=>'html', 'label'=>'NotePrivate', 'enabled'=>1, 'visible'=>0, 'position'=>62),
  198. 'date_creation' =>array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>500),
  199. 'tms' =>array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>501),
  200. //'date_valid' =>array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-2, 'position'=>502),
  201. 'fk_user_creat' =>array('type'=>'integer', 'label'=>'UserAuthor', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>510),
  202. 'fk_user_modif' =>array('type'=>'integer', 'label'=>'UserModif', 'enabled'=>1, 'visible'=>-2, 'notnull'=>-1, 'position'=>511),
  203. //'fk_user_valid' =>array('type'=>'integer', 'label'=>'UserValidation', 'enabled'=>1, 'visible'=>-1, 'position'=>512),
  204. 'import_key' =>array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>1, 'visible'=>-2, 'notnull'=>-1, 'index'=>0, 'position'=>1000),
  205. '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')),
  206. );*/
  207. $string = 'public $fields=array('."\n";
  208. $string.="<br>";
  209. $i=10;
  210. while ($obj = $db->fetch_object($_results))
  211. {
  212. $fieldname = $obj->Field;
  213. $type = $obj->Type;
  214. if ($type == 'int(11)') $type='integer';
  215. $notnull = ($obj->Null == 'YES'?0:1);
  216. $label = preg_replace('/_/', ' ', ucfirst($fieldname));
  217. if ($fieldname == 'rowid') $label='ID';
  218. $string.= "'".$obj->Field."' =>array('type'=>'".$type."', 'label'=>'".$label."', 'enabled'=>1, 'visible'=>-2";
  219. if ($notnull) $string.= ", 'notnull'=>".$notnull;
  220. if ($fieldname == 'ref') $string.= ", 'showoncombobox'=>1";
  221. $string.= ", 'position'=>".$i."),\n";
  222. $string.="<br>";
  223. $i+=5;
  224. }
  225. $string.= ');'."\n";
  226. $string.="<br>";
  227. print $string;
  228. exit;
  229. }
  230. }
  231. if ($dirins && $action == 'initobject' && $module && $objectname)
  232. {
  233. if (preg_match('/[^a-z0-9_]/i', $objectname))
  234. {
  235. $error++;
  236. setEventMessages($langs->trans("SpaceOrSpecialCharAreNotAllowed"), null, 'errors');
  237. $tabobj='newobject';
  238. }
  239. $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
  240. $destdir = $dirins.'/'.strtolower($module);
  241. // The dir was not created by init
  242. dol_mkdir($destdir.'/class');
  243. dol_mkdir($destdir.'/img');
  244. dol_mkdir($destdir.'/lib');
  245. dol_mkdir($destdir.'/scripts');
  246. dol_mkdir($destdir.'/sql');
  247. dol_mkdir($destdir.'/test/phpunit');
  248. // Scan dir class to find if an object with same name already exists.
  249. if (! $error)
  250. {
  251. $dirlist=dol_dir_list($destdir.'/class','files',0,'\.txt$');
  252. $alreadyfound=false;
  253. foreach($dirlist as $key => $val)
  254. {
  255. $filefound=preg_replace('/\.txt$/','',$val['name']);
  256. if (strtolower($objectname) == strtolower($filefound) && $objectname != $filefound)
  257. {
  258. $alreadyfound=true;
  259. $error++;
  260. setEventMessages($langs->trans("AnObjectAlreadyExistWithThisNameAndDiffCase"), null, 'errors');
  261. break;
  262. }
  263. }
  264. }
  265. if (! $error)
  266. {
  267. // Copy some files
  268. $filetogenerate = array(
  269. 'myobject_card.php'=>strtolower($objectname).'_card.php',
  270. 'myobject_note.php'=>strtolower($objectname).'_note.php',
  271. 'myobject_document.php'=>strtolower($objectname).'_document.php',
  272. 'myobject_agenda.php'=>strtolower($objectname).'_agenda.php',
  273. 'myobject_list.php'=>strtolower($objectname).'_list.php',
  274. 'lib/mymodule_myobject.lib.php'=>'lib/'.strtolower($module).'_'.strtolower($objectname).'.lib.php',
  275. 'test/phpunit/MyObjectTest.php'=>'test/phpunit/'.$objectname.'Test.php',
  276. 'sql/llx_mymodule_myobject.sql'=>'sql/llx_'.strtolower($module).'_'.strtolower($objectname).'.sql',
  277. 'sql/llx_mymodule_myobject_extrafields.sql'=>'sql/llx_'.strtolower($module).'_'.strtolower($objectname).'_extrafields.sql',
  278. 'sql/llx_mymodule_myobject.key.sql'=>'sql/llx_'.strtolower($module).'_'.strtolower($objectname).'.key.sql',
  279. 'scripts/myobject.php'=>'scripts/'.strtolower($objectname).'.php',
  280. 'img/object_myobject.png'=>'img/object_'.strtolower($objectname).'.png',
  281. 'class/myobject.class.php'=>'class/'.strtolower($objectname).'.class.php',
  282. 'class/api_mymodule.class.php'=>'class/api_'.strtolower($module).'.class.php'
  283. );
  284. foreach($filetogenerate as $srcfile => $destfile)
  285. {
  286. $result = dol_copy($srcdir.'/'.$srcfile, $destdir.'/'.$destfile, $newmask, 0);
  287. if ($result <= 0)
  288. {
  289. if ($result < 0)
  290. {
  291. $error++;
  292. $langs->load("errors");
  293. setEventMessages($langs->trans("ErrorFailToCopyFile", $srcdir.'/'.$srcfile, $destdir.'/'.$destfile), null, 'errors');
  294. }
  295. else // $result == 0
  296. {
  297. setEventMessages($langs->trans("FileAlreadyExists", $destfile), null, 'warnings');
  298. }
  299. }
  300. }
  301. if (! $error)
  302. {
  303. // Scan for object class files
  304. $listofobject = dol_dir_list($destdir.'/class', 'files', 0, '\.class\.php$');
  305. $firstobjectname='';
  306. foreach($listofobject as $fileobj)
  307. {
  308. if (preg_match('/^api_/',$fileobj['name'])) continue;
  309. if (preg_match('/^actions_/',$fileobj['name'])) continue;
  310. $tmpcontent=file_get_contents($fileobj['fullname']);
  311. if (preg_match('/class\s+([^\s]*)\s+extends\s+CommonObject/ims',$tmpcontent,$reg))
  312. {
  313. $objectnameloop = $reg[1];
  314. if (empty($firstobjectname)) $firstobjectname = $objectnameloop;
  315. }
  316. // Regenerate left menu entry in descriptor for $objectname
  317. $stringtoadd="
  318. \t\t\$this->menu[\$r++]=array(
  319. 'fk_menu'=>'fk_mainmenu=mymodule', // '' 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
  320. 'type'=>'left', // This is a Left menu entry
  321. 'titre'=>'List MyObject',
  322. 'mainmenu'=>'mymodule',
  323. 'leftmenu'=>'mymodule_myobject',
  324. 'url'=>'/mymodule/myobject_list.php',
  325. 'langs'=>'mymodule@mymodule', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
  326. 'position'=>1100+\$r,
  327. 'enabled'=>'\$conf->mymodule->enabled', // 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.
  328. 'perms'=>'1', // Use 'perms'=>'\$user->rights->mymodule->level1->level2' if you want your menu with a permission rules
  329. 'target'=>'',
  330. 'user'=>2); // 0=Menu for internal users, 1=external users, 2=both
  331. \t\t\$this->menu[\$r++]=array(
  332. 'fk_menu'=>'fk_mainmenu=mymodule,fk_leftmenu=mymodule_myobject', // '' 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
  333. 'type'=>'left', // This is a Left menu entry
  334. 'titre'=>'New MyObject',
  335. 'mainmenu'=>'mymodule',
  336. 'leftmenu'=>'mymodule_myobject',
  337. 'url'=>'/mymodule/myobject_card.php?action=create',
  338. 'langs'=>'mymodule@mymodule', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
  339. 'position'=>1100+\$r,
  340. 'enabled'=>'\$conf->mymodule->enabled', // 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.
  341. 'perms'=>'1', // Use 'perms'=>'\$user->rights->mymodule->level1->level2' if you want your menu with a permission rules
  342. 'target'=>'',
  343. 'user'=>2); // 0=Menu for internal users, 1=external users, 2=both
  344. ";
  345. $stringtoadd = preg_replace('/MyObject/', $objectnameloop, $stringtoadd);
  346. $stringtoadd = preg_replace('/mymodule/', strtolower($module), $stringtoadd);
  347. $stringtoadd = preg_replace('/myobject/', strtolower($objectnameloop), $stringtoadd);
  348. $moduledescriptorfile=$destdir.'/core/modules/mod'.$module.'.class.php';
  349. // TODO Allow a replace with regex using dolReplaceRegexInFile
  350. // TODO Avoid duplicate addition
  351. dolReplaceInFile($moduledescriptorfile, array('END MODULEBUILDER LEFTMENU MYOBJECT */' => '*/'."\n".$stringtoadd."\n\t\t/* END MODULEBUILDER LEFTMENU MYOBJECT */"));
  352. // Add module descriptor to list of files to replace "MyObject' string with real name of object.
  353. $filetogenerate[]='core/modules/mod'.$module.'.class.php';
  354. // TODO
  355. }
  356. }
  357. }
  358. if (! $error)
  359. {
  360. // Edit PHP files
  361. foreach($filetogenerate as $destfile)
  362. {
  363. $phpfileval['fullname'] = $destdir.'/'.$destfile;
  364. //var_dump($phpfileval['fullname']);
  365. $arrayreplacement=array(
  366. 'mymodule'=>strtolower($module),
  367. 'MyModule'=>$module,
  368. 'MYMODULE'=>strtoupper($module),
  369. 'My module'=>$module,
  370. 'my module'=>$module,
  371. 'mon module'=>$module,
  372. 'Mon module'=>$module,
  373. 'htdocs/modulebuilder/template/'=>strtolower($modulename),
  374. 'myobject'=>strtolower($objectname),
  375. 'MyObject'=>$objectname,
  376. 'MYOBJECT'=>strtoupper($objectname)
  377. );
  378. $result=dolReplaceInFile($phpfileval['fullname'], $arrayreplacement);
  379. //var_dump($result);
  380. if ($result < 0)
  381. {
  382. setEventMessages($langs->trans("ErrorFailToMakeReplacementInto", $phpfileval['fullname']), null, 'errors');
  383. }
  384. }
  385. }
  386. if (! $error)
  387. {
  388. // Edit the class file to write properties
  389. $object=rebuildObjectClass($destdir, $module, $objectname, $newmask);
  390. if (is_numeric($object) && $object < 0) $error++;
  391. }
  392. if (! $error)
  393. {
  394. // Edit sql with new properties
  395. $result=rebuildObjectSql($destdir, $module, $objectname, $newmask, '', $object);
  396. if ($result < 0) $error++;
  397. }
  398. if (! $error)
  399. {
  400. setEventMessages($langs->trans('FilesForObjectInitialized', $objectname), null);
  401. }
  402. }
  403. if ($dirins && ($action == 'droptable' || $action == 'droptableextrafields') && !empty($module) && ! empty($tabobj))
  404. {
  405. $objectname = $tabobj;
  406. $arrayoftables=array();
  407. if ($action == 'droptable') $arrayoftables[] = MAIN_DB_PREFIX.strtolower($module).'_'.strtolower($tabobj);
  408. if ($action == 'droptableextrafields') $arrayoftables[] = MAIN_DB_PREFIX.strtolower($module).'_'.strtolower($tabobj).'_extrafields';
  409. foreach($arrayoftables as $tabletodrop)
  410. {
  411. $nb = -1;
  412. $sql="SELECT COUNT(*) as nb FROM ".$tabletodrop;
  413. $resql = $db->query($sql);
  414. if ($resql)
  415. {
  416. $obj = $db->fetch_object($resql);
  417. if ($obj)
  418. {
  419. $nb = $obj->nb;
  420. }
  421. }
  422. else
  423. {
  424. if ($db->lasterrno() == 'DB_ERROR_NOSUCHTABLE')
  425. {
  426. setEventMessages($langs->trans("TableDoesNotExists", $tabletodrop), null, 'warnings');
  427. }
  428. else
  429. {
  430. dol_print_error($db);
  431. }
  432. }
  433. if ($nb == 0)
  434. {
  435. $resql=$db->DDLDropTable($tabletodrop);
  436. //var_dump($resql);
  437. setEventMessages($langs->trans("TableDropped", $tabletodrop), null, 'mesgs');
  438. }
  439. elseif ($nb > 0)
  440. {
  441. setEventMessages($langs->trans("TableNotEmptyDropCanceled", $tabletodrop), null, 'warnings');
  442. }
  443. }
  444. }
  445. if ($dirins && $action == 'addproperty' && !empty($module) && ! empty($tabobj))
  446. {
  447. $error = 0;
  448. $objectname = $tabobj;
  449. $srcdir = $dirread.'/'.strtolower($module);
  450. $destdir = $dirins.'/'.strtolower($module);
  451. dol_mkdir($destdir);
  452. // We click on add property
  453. if (! GETPOST('regenerateclasssql') && ! GETPOST('regeneratemissing'))
  454. {
  455. if (! GETPOST('propname','aZ09'))
  456. {
  457. $error++;
  458. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Name")), null, 'errors');
  459. }
  460. if (! GETPOST('proplabel','alpha'))
  461. {
  462. $error++;
  463. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Label")), null, 'errors');
  464. }
  465. if (! GETPOST('proptype','alpha'))
  466. {
  467. $error++;
  468. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Type")), null, 'errors');
  469. }
  470. if (! $error)
  471. {
  472. $addfieldentry = array(
  473. 'name'=>GETPOST('propname','aZ09'),'label'=>GETPOST('proplabel','alpha'),'type'=>GETPOST('proptype','alpha'),
  474. 'arrayofkeyval'=>GETPOST('proparrayofkeyval','none'), // Example json string '{"0":"Draft","1":"Active","-1":"Cancel"}'
  475. 'visible'=>GETPOST('propvisible','int'),'enabled'=>GETPOST('propenabled','int'),
  476. 'position'=>GETPOST('propposition','int'),'notnull'=>GETPOST('propnotnull','int'),'index'=>GETPOST('propindex','int'),'searchall'=>GETPOST('propsearchall','int'),
  477. 'isameasure'=>GETPOST('propisameasure','int'), 'comment'=>GETPOST('propcomment','alpha'),'help'=>GETPOST('prophelp','alpha'));
  478. if (! empty($addfieldentry['arrayofkeyval']) && ! is_array($addfieldentry['arrayofkeyval']))
  479. {
  480. $addfieldentry['arrayofkeyval'] = dol_json_decode($addfieldentry['arrayofkeyval'], true);
  481. }
  482. }
  483. }
  484. if (GETPOST('regeneratemissing'))
  485. {
  486. setEventMessages($langs->trans("FeatureNotYetAvailable"), null, 'warnings');
  487. $error++;
  488. }
  489. // Edit the class file to write properties
  490. if (! $error)
  491. {
  492. $object=rebuildObjectClass($destdir, $module, $objectname, $newmask, $srcdir, $addfieldentry);
  493. if (is_numeric($result) && $result <= 0) $error++;
  494. }
  495. // Edit sql with new properties
  496. if (! $error)
  497. {
  498. $result=rebuildObjectSql($destdir, $module, $objectname, $newmask, $srcdir, $object);
  499. if ($result <= 0)
  500. {
  501. $error++;
  502. }
  503. }
  504. if (! $error)
  505. {
  506. setEventMessages($langs->trans('FilesForObjectUpdated', $objectname), null);
  507. clearstatcache(true);
  508. // Make a redirect to reload all data
  509. header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=objects&module='.$module.'&tabobj='.$objectname.'&nocache='.time());
  510. exit;
  511. }
  512. }
  513. if ($dirins && $action == 'confirm_deleteproperty' && $propertykey)
  514. {
  515. $objectname = $tabobj;
  516. $srcdir = $dirread.'/'.strtolower($module);
  517. $destdir = $dirins.'/'.strtolower($module);
  518. dol_mkdir($destdir);
  519. // Edit the class file to write properties
  520. if (! $error)
  521. {
  522. $object=rebuildObjectClass($destdir, $module, $objectname, $newmask, $srcdir, array(), $propertykey);
  523. if (is_numeric($object) && $object <= 0) $error++;
  524. }
  525. // Edit sql with new properties
  526. if (! $error)
  527. {
  528. $result=rebuildObjectSql($destdir, $module, $objectname, $newmask, $srcdir, $object);
  529. if ($result <= 0) $error++;
  530. }
  531. if (! $error)
  532. {
  533. setEventMessages($langs->trans('FilesForObjectUpdated', $objectname), null);
  534. clearstatcache(true);
  535. // Make a redirect to reload all data
  536. header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=objects&module='.$module.'&tabobj='.$objectname);
  537. exit;
  538. }
  539. }
  540. if ($dirins && $action == 'confirm_delete')
  541. {
  542. if (preg_match('/[^a-z0-9_]/i', $module))
  543. {
  544. $error++;
  545. setEventMessages($langs->trans("SpaceOrSpecialCharAreNotAllowed"), null, 'errors');
  546. }
  547. if (! $error)
  548. {
  549. $modulelowercase=strtolower($module);
  550. // Dir for module
  551. $dir = $dirins.'/'.$modulelowercase;
  552. $result = dol_delete_dir_recursive($dir);
  553. if ($result > 0)
  554. {
  555. setEventMessages($langs->trans("DirWasRemoved", $modulelowercase), null);
  556. }
  557. else
  558. {
  559. setEventMessages($langs->trans("PurgeNothingToDelete"), null, 'warnings');
  560. }
  561. }
  562. //header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?module=initmodule');
  563. //exit;
  564. $action = '';
  565. $module = 'deletemodule';
  566. }
  567. if ($dirins && $action == 'confirm_deleteobject' && $objectname)
  568. {
  569. if (preg_match('/[^a-z0-9_]/i', $objectname))
  570. {
  571. $error++;
  572. setEventMessages($langs->trans("SpaceOrSpecialCharAreNotAllowed"), null, 'errors');
  573. }
  574. if (! $error)
  575. {
  576. $modulelowercase=strtolower($module);
  577. $objectlowercase=strtolower($objectname);
  578. // Dir for module
  579. $dir = $dirins.'/'.$modulelowercase;
  580. // Delete some files
  581. $filetogenerate = array(
  582. 'myobject_card.php'=>strtolower($objectname).'_card.php',
  583. 'myobject_note.php'=>strtolower($objectname).'_note.php',
  584. 'myobject_document.php'=>strtolower($objectname).'_document.php',
  585. 'myobject_agenda.php'=>strtolower($objectname).'_agenda.php',
  586. 'myobject_list.php'=>strtolower($objectname).'_list.php',
  587. 'lib/mymodule.lib.php'=>'lib/'.strtolower($module).'.lib.php',
  588. 'lib/mymodule_myobject.lib.php'=>'lib/'.strtolower($module).'_'.strtolower($objectname).'.lib.php',
  589. 'test/phpunit/MyObjectTest.php'=>'test/phpunit/'.$objectname.'Test.php',
  590. 'sql/llx_mymodule_myobject.sql'=>'sql/llx_'.strtolower($module).'_'.strtolower($objectname).'.sql',
  591. 'sql/llx_mymodule_myobject_extrafields.sql'=>'sql/llx_'.strtolower($module).'_'.strtolower($objectname).'_extrafields.sql',
  592. 'sql/llx_mymodule_myobject.key.sql'=>'sql/llx_'.strtolower($module).'_'.strtolower($objectname).'.key.sql',
  593. 'scripts/myobject.php'=>'scripts/'.strtolower($objectname).'.php',
  594. 'img/object_myobject.png'=>'img/object_'.strtolower($objectname).'.png',
  595. 'class/myobject.class.php'=>'class/'.strtolower($objectname).'.class.php',
  596. 'class/api_myobject.class.php'=>'class/api_'.strtolower($module).'.class.php'
  597. );
  598. $resultko = 0;
  599. foreach($filetogenerate as $filetodelete)
  600. {
  601. $resulttmp = dol_delete_file($dir.'/'.$filetodelete, 0, 0, 1);
  602. if (! $resulttmp) $resultko++;
  603. }
  604. if ($resultko == 0)
  605. {
  606. setEventMessages($langs->trans("FilesDeleted"), null);
  607. }
  608. else
  609. {
  610. setEventMessages($langs->trans("ErrorSomeFilesCouldNotBeDeleted"), null, 'warnings');
  611. }
  612. }
  613. //header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?module=initmodule');
  614. //exit;
  615. $action = '';
  616. $tabobj = 'deleteobject';
  617. }
  618. if ($dirins && $action == 'generatepackage')
  619. {
  620. $modulelowercase=strtolower($module);
  621. // Dir for module
  622. $dir = $dirins.'/'.$modulelowercase;
  623. // Zip file to build
  624. $FILENAMEZIP='';
  625. // Load module
  626. dol_include_once($modulelowercase.'/core/modules/mod'.$module.'.class.php');
  627. $class='mod'.$module;
  628. if (class_exists($class))
  629. {
  630. try {
  631. $moduleobj = new $class($db);
  632. }
  633. catch(Exception $e)
  634. {
  635. $error++;
  636. dol_print_error($e->getMessage());
  637. }
  638. }
  639. else
  640. {
  641. $error++;
  642. $langs->load("errors");
  643. dol_print_error($langs->trans("ErrorFailedToLoadModuleDescriptorForXXX", $module));
  644. exit;
  645. }
  646. $arrayversion=explode('.',$moduleobj->version,3);
  647. if (count($arrayversion))
  648. {
  649. $FILENAMEZIP="module_".$modulelowercase.'-'.$arrayversion[0].'.'.$arrayversion[1].($arrayversion[2]?".".$arrayversion[2]:"").".zip";
  650. $dirofmodule = dol_buildpath($modulelowercase, 0).'/bin';
  651. $outputfilezip = $dirofmodule.'/'.$FILENAMEZIP;
  652. if ($dirofmodule)
  653. {
  654. if (! dol_is_dir($dirofmodule)) dol_mkdir($dirofmodule);
  655. $result = dol_compress_dir($dir, $outputfilezip, 'zip');
  656. }
  657. else
  658. {
  659. $result = -1;
  660. }
  661. if ($result > 0)
  662. {
  663. setEventMessages($langs->trans("ZipFileGeneratedInto", $outputfilezip), null);
  664. }
  665. else
  666. {
  667. $error++;
  668. $langs->load("errors");
  669. setEventMessages($langs->trans("ErrorFailToGenerateFile", $outputfilezip), null, 'errors');
  670. }
  671. }
  672. else
  673. {
  674. $error++;
  675. $langs->load("errors");
  676. setEventMessages($langs->trans("ErrorCheckVersionIsDefined"), null, 'errors');
  677. }
  678. }
  679. if ($dirins && $action == 'generatedoc')
  680. {
  681. $FILENAMEDOC=strtolower($module).'.html'; // TODO Use/text PDF
  682. $dirofmodule = dol_buildpath(strtolower($module), 0).'/doc';
  683. $outputfiledoc = $dirofmodule.'/'.$FILENAMEDOC;
  684. $util = new Utils($db);
  685. $result = $util->generateDoc($module);
  686. if ($result > 0)
  687. {
  688. setEventMessages($langs->trans("DocFileGeneratedInto", $outputfiledoc), null);
  689. }
  690. else
  691. {
  692. setEventMessages($util->error, $util->errors, 'errors');
  693. }
  694. }
  695. // Save file
  696. if ($action == 'savefile' && empty($cancel))
  697. {
  698. $relofcustom = basename($dirins);
  699. if ($relofcustom)
  700. {
  701. // Check that relative path ($file) start with name 'custom'
  702. if (! preg_match('/^'.$relofcustom.'/', $file)) $file=$relofcustom.'/'.$file;
  703. $pathoffile=dol_buildpath($file, 0);
  704. $pathoffilebackup=dol_buildpath($file.'.back', 0);
  705. // Save old version
  706. if (dol_is_file($pathoffile))
  707. {
  708. dol_copy($pathoffile, $pathoffilebackup, 0, 1);
  709. }
  710. $content = GETPOST('editfilecontent','none');
  711. // Save file on disk
  712. if ($content)
  713. {
  714. dol_delete_file($pathoffile);
  715. file_put_contents($pathoffile, $content);
  716. @chmod($pathoffile, octdec($newmask));
  717. setEventMessages($langs->trans("FileSaved"), null);
  718. }
  719. else
  720. {
  721. setEventMessages($langs->trans("ContentCantBeEmpty"), null, 'errors');
  722. //$action='editfile';
  723. $error++;
  724. }
  725. }
  726. }
  727. // Enable module
  728. if ($action == 'set' && $user->admin)
  729. {
  730. $param='';
  731. if ($module) $param.='&module='.$module;
  732. if ($tab) $param.='&tab='.$tab;
  733. if ($tabobj) $param.='&tabobj='.$tabobj;
  734. $value = GETPOST('value','alpha');
  735. $resarray = activateModule($value);
  736. if (! empty($resarray['errors'])) setEventMessages('', $resarray['errors'], 'errors');
  737. else
  738. {
  739. //var_dump($resarray);exit;
  740. if ($resarray['nbperms'] > 0)
  741. {
  742. $tmpsql="SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX."user WHERE admin <> 1";
  743. $resqltmp=$db->query($tmpsql);
  744. if ($resqltmp)
  745. {
  746. $obj=$db->fetch_object($resqltmp);
  747. //var_dump($obj->nb);exit;
  748. if ($obj && $obj->nb > 1)
  749. {
  750. $msg = $langs->trans('ModuleEnabledAdminMustCheckRights');
  751. setEventMessages($msg, null, 'warnings');
  752. }
  753. }
  754. else dol_print_error($db);
  755. }
  756. }
  757. header("Location: ".$_SERVER["PHP_SELF"]."?".$param);
  758. exit;
  759. }
  760. // Disable module
  761. if ($action == 'reset' && $user->admin)
  762. {
  763. $param='';
  764. if ($module) $param.='&module='.$module;
  765. if ($tab) $param.='&tab='.$tab;
  766. if ($tabobj) $param.='&tabobj='.$tabobj;
  767. $value = GETPOST('value','alpha');
  768. $result=unActivateModule($value);
  769. if ($result) setEventMessages($result, null, 'errors');
  770. header("Location: ".$_SERVER["PHP_SELF"]."?".$param);
  771. exit;
  772. }
  773. /*
  774. * View
  775. */
  776. $form = new Form($db);
  777. $formadmin = new FormAdmin($db);
  778. // Set dir where external modules are installed
  779. if (! dol_is_dir($dirins))
  780. {
  781. dol_mkdir($dirins);
  782. }
  783. $dirins_ok=(dol_is_dir($dirins));
  784. llxHeader('', $langs->trans("ModuleBuilder"), '', '', 0, 0,
  785. array(
  786. '/includes/ace/ace.js',
  787. '/includes/ace/ext-statusbar.js',
  788. '/includes/ace/ext-language_tools.js',
  789. //'/includes/ace/ext-chromevox.js'
  790. ), array());
  791. $text=$langs->trans("ModuleBuilder");
  792. print load_fiche_titre($text, '', 'title_setup');
  793. // Search modules to edit
  794. $listofmodules=array();
  795. $dirsincustom=dol_dir_list($dirread, 'directories');
  796. if (is_array($dirsincustom) && count($dirsincustom) > 0) {
  797. foreach ($dirsincustom as $dircustomcursor) {
  798. $fullname = $dircustomcursor['fullname'];
  799. if (dol_is_file($fullname . '/' . $FILEFLAG))
  800. {
  801. // Get real name of module (MyModule instead of mymodule)
  802. $dirtoscanrel = basename($fullname).'/core/modules/';
  803. $descriptorfiles = dol_dir_list(dirname($fullname).'/'.$dirtoscanrel, 'files', 0, 'mod.*\.class\.php$');
  804. if (empty($descriptorfiles)) // If descriptor not found into module dir, we look into main module dir.
  805. {
  806. $dirtoscanrel = 'core/modules/';
  807. $descriptorfiles = dol_dir_list($fullname.'/../'.$dirtoscanrel, 'files', 0, 'mod'.strtoupper(basename($fullname)).'\.class\.php$');
  808. }
  809. $modulenamewithcase = '';
  810. $moduledescriptorrelpath = '';
  811. $moduledescriptorfullpath = '';
  812. foreach ($descriptorfiles as $descriptorcursor) {
  813. $modulenamewithcase = preg_replace('/^mod/', '', $descriptorcursor['name']);
  814. $modulenamewithcase = preg_replace('/\.class\.php$/', '', $modulenamewithcase);
  815. $moduledescriptorrelpath = $dirtoscanrel.$descriptorcursor['name'];
  816. $moduledescriptorfullpath = $descriptorcursor['fullname'];
  817. //var_dump($descriptorcursor);
  818. }
  819. if ($modulenamewithcase)
  820. {
  821. $listofmodules[$dircustomcursor['name']] = array('modulenamewithcase'=>$modulenamewithcase, 'moduledescriptorrelpath'=> $moduledescriptorrelpath, 'moduledescriptorfullpath'=>$moduledescriptorfullpath);
  822. }
  823. //var_dump($listofmodules);
  824. }
  825. }
  826. }
  827. if ($forceddirread && empty($listofmodules))
  828. {
  829. $listofmodules[strtolower($module)] = array('modulenamewithcase'=>$module, 'moduledescriptorrelpath'=> 'notyetimplemented', 'moduledescriptorfullpath'=> 'notyetimplemented');
  830. }
  831. // Show description of content
  832. $newdircustom=$dirins;
  833. if (empty($newdircustom)) $newdircustom=img_warning();
  834. print $langs->trans("ModuleBuilderDesc", 'https://wiki.dolibarr.org/index.php/Module_development#Create_your_module').'<br>';
  835. print $langs->trans("ModuleBuilderDesc2", 'conf/conf.php', $newdircustom).'<br>';
  836. // If dirread was forced to somewhere else, by using URL
  837. // htdocs/modulebuilder/index.php?module=Inventory@/home/ldestailleur/git/dolibarr/htdocs/product
  838. if ($forceddirread) print $langs->trans("DirScanned").' : <strong>'.$dirread.'</strong><br>';
  839. $message='';
  840. if (! $dirins)
  841. {
  842. $message=info_admin($langs->trans("ConfFileMustContainCustom", DOL_DOCUMENT_ROOT.'/custom', DOL_DOCUMENT_ROOT));
  843. $allowfromweb=-1;
  844. }
  845. else
  846. {
  847. if ($dirins_ok)
  848. {
  849. if (! is_writable(dol_osencode($dirins)))
  850. {
  851. $langs->load("errors");
  852. $message=info_admin($langs->trans("ErrorFailedToWriteInDir",$dirins));
  853. $allowfromweb=0;
  854. }
  855. }
  856. else
  857. {
  858. $message=info_admin($langs->trans("NotExistsDirect",$dirins).$langs->trans("InfDirAlt").$langs->trans("InfDirExample"));
  859. $allowfromweb=0;
  860. }
  861. }
  862. if ($message)
  863. {
  864. print $message;
  865. }
  866. //print $langs->trans("ModuleBuilderDesc3", count($listofmodules), $FILEFLAG).'<br>';
  867. $infomodulesfound = '<div style="padding: 12px 9px 12px">'.$form->textwithpicto($langs->trans("ModuleBuilderDesc3", count($listofmodules)), $langs->trans("ModuleBuilderDesc4", $FILEFLAG)).'</div>';
  868. // Load module descriptor
  869. $error=0;
  870. $moduleobj = null;
  871. if (! empty($module) && $module != 'initmodule' && $module != 'deletemodule')
  872. {
  873. $modulelowercase=strtolower($module);
  874. // Load module
  875. $fullpathdirtodescriptor = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
  876. dol_include_once($fullpathdirtodescriptor);
  877. $class='mod'.$module;
  878. if (class_exists($class))
  879. {
  880. try {
  881. $moduleobj = new $class($db);
  882. }
  883. catch(Exception $e)
  884. {
  885. $error++;
  886. print $e->getMessage();
  887. }
  888. }
  889. else
  890. {
  891. if (empty($forceddirread)) $error++;
  892. $langs->load("errors");
  893. print img_warning('').' '.$langs->trans("ErrorFailedToLoadModuleDescriptorForXXX", $module).'<br>';
  894. }
  895. }
  896. print '<br>';
  897. // Tabs for all modules
  898. $head = array();
  899. $h=0;
  900. $head[$h][0] = $_SERVER["PHP_SELF"].'?module=initmodule';
  901. $head[$h][1] = $langs->trans("NewModule");
  902. $head[$h][2] = 'initmodule';
  903. $h++;
  904. foreach($listofmodules as $tmpmodule => $tmpmodulearray)
  905. {
  906. $head[$h][0] = $_SERVER["PHP_SELF"].'?module='.$tmpmodulearray['modulenamewithcase'].($forceddirread?'@'.$dirread:'');
  907. $head[$h][1] = $tmpmodulearray['modulenamewithcase'];
  908. $head[$h][2] = $tmpmodulearray['modulenamewithcase'];
  909. $h++;
  910. }
  911. $head[$h][0] = $_SERVER["PHP_SELF"].'?module=deletemodule';
  912. $head[$h][1] = $langs->trans("DangerZone");
  913. $head[$h][2] = 'deletemodule';
  914. $h++;
  915. dol_fiche_head($head, $module, $langs->trans("Modules"), -1, 'generic', 0, $infomodulesfound); // Modules
  916. if ($module == 'initmodule')
  917. {
  918. // New module
  919. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  920. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  921. print '<input type="hidden" name="action" value="initmodule">';
  922. print '<input type="hidden" name="module" value="initmodule">';
  923. print $langs->trans("EnterNameOfModuleDesc").'<br><br>';
  924. print '<input type="text" name="modulename" value="'.dol_escape_htmltag($modulename).'" placeholder="'.dol_escape_htmltag($langs->trans("ModuleKey")).'">';
  925. print '<input type="submit" class="button" name="create" value="'.dol_escape_htmltag($langs->trans("Create")).'"'.($dirins?'':' disabled="disabled"').'>';
  926. print '</form>';
  927. }
  928. elseif ($module == 'deletemodule')
  929. {
  930. print '<form name="delete">';
  931. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  932. print '<input type="hidden" name="action" value="confirm_delete">';
  933. print '<input type="hidden" name="module" value="deletemodule">';
  934. print $langs->trans("EnterNameOfModuleToDeleteDesc").'<br><br>';
  935. print '<input type="text" name="module" placeholder="'.dol_escape_htmltag($langs->trans("ModuleKey")).'" value="">';
  936. print '<input type="submit" class="buttonDelete" value="'.$langs->trans("Delete").'"'.($dirins?'':' disabled="disabled"').'>';
  937. print '</form>';
  938. }
  939. elseif (! empty($module))
  940. {
  941. // Tabs for module
  942. if (! $error)
  943. {
  944. $head2 = array();
  945. $h=0;
  946. $modulelowercase=strtolower($module);
  947. $const_name = 'MAIN_MODULE_'.strtoupper($module);
  948. $param='';
  949. if ($tab) $param.= '&tab='.$tab;
  950. if ($module) $param.='&module='.$module;
  951. if ($tabobj) $param.='&tabobj='.$tabobj;
  952. $urltomodulesetup='<a href="'.DOL_URL_ROOT.'/admin/modules.php?search_keyword='.urlencode($module).'">'.$langs->trans('Home').'-'.$langs->trans("Setup").'-'.$langs->trans("Modules").'</a>';
  953. $linktoenabledisable='';
  954. if (! empty($conf->global->$const_name)) // If module is already activated
  955. {
  956. $linktoenabledisable.='<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?id='.$moduleobj->numero.'&action=reset&value=mod' . $module . $param . '">';
  957. $linktoenabledisable.=img_picto($langs->trans("Activated"),'switch_on');
  958. $linktoenabledisable.='</a>';
  959. }
  960. else
  961. {
  962. $linktoenabledisable.='<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?id='.$moduleobj->numero.'&action=set&value=mod' . $module . $param . '">';
  963. $linktoenabledisable.=img_picto($langs->trans("Disabled"),'switch_off');
  964. $linktoenabledisable.="</a>\n";
  965. }
  966. if (! empty($conf->$modulelowercase->enabled))
  967. {
  968. $modulestatusinfo=img_warning().' '.$langs->trans("ModuleIsLive");
  969. }
  970. else
  971. {
  972. $modulestatusinfo=img_info('').' '.$langs->trans("ModuleIsNotActive", $urltomodulesetup);
  973. }
  974. $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=description&module='.$module.($forceddirread?'@'.$dirread:'');
  975. $head2[$h][1] = $langs->trans("Description");
  976. $head2[$h][2] = 'description';
  977. $h++;
  978. $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=specifications&module='.$module.($forceddirread?'@'.$dirread:'');
  979. $head2[$h][1] = $langs->trans("Specifications");
  980. $head2[$h][2] = 'specifications';
  981. $h++;
  982. $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=languages&module='.$module.($forceddirread?'@'.$dirread:'');
  983. $head2[$h][1] = $langs->trans("Languages");
  984. $head2[$h][2] = 'languages';
  985. $h++;
  986. $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=objects&module='.$module.($forceddirread?'@'.$dirread:'');
  987. $head2[$h][1] = $langs->trans("Objects");
  988. $head2[$h][2] = 'objects';
  989. $h++;
  990. $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=menus&module='.$module.($forceddirread?'@'.$dirread:'');
  991. $head2[$h][1] = $langs->trans("Menus");
  992. $head2[$h][2] = 'menus';
  993. $h++;
  994. $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=permissions&module='.$module.($forceddirread?'@'.$dirread:'');
  995. $head2[$h][1] = $langs->trans("Permissions");
  996. $head2[$h][2] = 'permissions';
  997. $h++;
  998. $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=hooks&module='.$module.($forceddirread?'@'.$dirread:'');
  999. $head2[$h][1] = $langs->trans("Hooks");
  1000. $head2[$h][2] = 'hooks';
  1001. $h++;
  1002. $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=triggers&module='.$module.($forceddirread?'@'.$dirread:'');
  1003. $head2[$h][1] = $langs->trans("Triggers");
  1004. $head2[$h][2] = 'triggers';
  1005. $h++;
  1006. $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=widgets&module='.$module.($forceddirread?'@'.$dirread:'');
  1007. $head2[$h][1] = $langs->trans("Widgets");
  1008. $head2[$h][2] = 'widgets';
  1009. $h++;
  1010. $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=cron&module='.$module.($forceddirread?'@'.$dirread:'');
  1011. $head2[$h][1] = $langs->trans("CronList");
  1012. $head2[$h][2] = 'cron';
  1013. $h++;
  1014. $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=buildpackage&module='.$module.($forceddirread?'@'.$dirread:'');
  1015. $head2[$h][1] = $langs->trans("BuildPackage");
  1016. $head2[$h][2] = 'buildpackage';
  1017. $h++;
  1018. // Link to enable / disable
  1019. print $modulestatusinfo;
  1020. print ' '.$linktoenabledisable;
  1021. print '<br>';
  1022. if (realpath($dirread.'/'.$modulelowercase) != $dirread.'/'.$modulelowercase)
  1023. {
  1024. print $langs->trans("RealPathOfModule").' : <strong>'.realpath($dirread.'/'.$modulelowercase).'</strong><br>';
  1025. }
  1026. print '<br>';
  1027. if ($tab == 'description')
  1028. {
  1029. $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
  1030. $pathtofilereadme = $modulelowercase.'/README.md';
  1031. $pathtochangelog = $modulelowercase.'/ChangeLog.md';
  1032. if ($action != 'editfile' || empty($file))
  1033. {
  1034. dol_fiche_head($head2, $tab, '', -1, ''); // Description - level 2
  1035. print $langs->trans("ModuleBuilderDesc".$tab).'<br><br>';
  1036. print '<span class="fa fa-file-o"></span> '.$langs->trans("DescriptorFile").' : <strong>'.$pathtofile.'</strong>';
  1037. print ' <a href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&module='.$module.($forceddirread?'@'.$dirread:'').'&action=editfile&format=php&file='.urlencode($pathtofile).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
  1038. print '<br>';
  1039. print '<span class="fa fa-file-o"></span> '.$langs->trans("ReadmeFile").' : <strong>'.$pathtofilereadme.'</strong>';
  1040. print ' <a href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&module='.$module.($forceddirread?'@'.$dirread:'').'&action=editfile&format=markdown&file='.urlencode($pathtofilereadme).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
  1041. print '<br>';
  1042. print '<span class="fa fa-file-o"></span> '.$langs->trans("ChangeLog").' : <strong>'.$pathtochangelog.'</strong>';
  1043. print ' <a href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&module='.$module.($forceddirread?'@'.$dirread:'').'&action=editfile&format=markdown&file='.urlencode($pathtochangelog).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
  1044. print '<br>';
  1045. print '<br>';
  1046. print '<br>';
  1047. print load_fiche_titre($langs->trans("DescriptorFile"));
  1048. if (! empty($moduleobj))
  1049. {
  1050. print '<div class="underbanner clearboth"></div>';
  1051. print '<div class="fichecenter">';
  1052. print '<table class="border centpercent">';
  1053. print '<tr class="liste_titre"><td class="titlefield">';
  1054. print $langs->trans("Parameter");
  1055. print '</td><td>';
  1056. print $langs->trans("Value");
  1057. print '</td></tr>';
  1058. print '<tr><td>';
  1059. print $langs->trans("Numero");
  1060. print '</td><td>';
  1061. print $moduleobj->numero;
  1062. print ' &nbsp; (<a href="'.DOL_URL_ROOT.'/admin/system/modules.php?mainmenu=home&leftmenu=admintools_info" target="_blank">'.$langs->trans("SeeIDsInUse").'</a>';
  1063. print ' - <a href="https://wiki.dolibarr.org/index.php/List_of_modules_id" target="_blank">'.$langs->trans("SeeReservedIDsRangeHere").'</a>)';
  1064. print '</td></tr>';
  1065. print '<tr><td>';
  1066. print $langs->trans("Name");
  1067. print '</td><td>';
  1068. print $moduleobj->getName();
  1069. print '</td></tr>';
  1070. print '<tr><td>';
  1071. print $langs->trans("Version");
  1072. print '</td><td>';
  1073. print $moduleobj->getVersion();
  1074. print '</td></tr>';
  1075. print '<tr><td>';
  1076. print $langs->trans("Family");
  1077. //print "<br>'crm','financial','hr','projects','products','ecm','technic','interface','other'";
  1078. print '</td><td>';
  1079. print $moduleobj->family;
  1080. print '</td></tr>';
  1081. print '<tr><td>';
  1082. print $langs->trans("EditorName");
  1083. print '</td><td>';
  1084. print $moduleobj->editor_name;
  1085. print '</td></tr>';
  1086. print '<tr><td>';
  1087. print $langs->trans("EditorUrl");
  1088. print '</td><td>';
  1089. print $moduleobj->editor_url;
  1090. print '</td></tr>';
  1091. print '<tr><td>';
  1092. print $langs->trans("Description");
  1093. print '</td><td>';
  1094. print $moduleobj->getDesc();
  1095. print '</td></tr>';
  1096. print '</table>';
  1097. print '<br><br>';
  1098. // Readme file
  1099. print load_fiche_titre($langs->trans("ReadmeFile"));
  1100. print '<div class="underbanner clearboth"></div>';
  1101. print '<div class="fichecenter">';
  1102. if (dol_is_file($dirread.'/'.$pathtofilereadme)) print $moduleobj->getDescLong();
  1103. else print $langs->trans("ErrorFileNotFound", $pathtofilereadme);
  1104. print '<br><br>';
  1105. // ChangeLog
  1106. print load_fiche_titre($langs->trans("ChangeLog"));
  1107. print '<div class="underbanner clearboth"></div>';
  1108. print '<div class="fichecenter">';
  1109. if (dol_is_file($dirread.'/'.$pathtochangelog)) print $moduleobj->getChangeLog();
  1110. else print $langs->trans("ErrorFileNotFound", $pathtochangelog);
  1111. print '</div>';
  1112. }
  1113. else
  1114. {
  1115. print $langs->trans("ErrorFailedToLoadModuleDescriptorForXXX", $module).'<br>';
  1116. }
  1117. dol_fiche_end();
  1118. }
  1119. else
  1120. {
  1121. $fullpathoffile=dol_buildpath($file, 0, 1); // Description - level 2
  1122. if ($fullpathoffile)
  1123. {
  1124. $content = file_get_contents($fullpathoffile);
  1125. }
  1126. // New module
  1127. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  1128. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  1129. print '<input type="hidden" name="action" value="savefile">';
  1130. print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
  1131. print '<input type="hidden" name="tab" value="'.$tab.'">';
  1132. print '<input type="hidden" name="module" value="'.$module.'">';
  1133. dol_fiche_head($head2, $tab, '', -1, '');
  1134. $doleditor=new DolEditor('editfilecontent', $content, '', '300', 'Full', 'In', true, false, 'ace', 0, '99%', '');
  1135. print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format','aZ09')?GETPOST('format','aZ09'):'html'));
  1136. dol_fiche_end();
  1137. print '<center>';
  1138. print '<input type="submit" class="button buttonforacesave" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
  1139. print ' &nbsp; ';
  1140. print '<input type="submit" class="button" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
  1141. print '</center>';
  1142. print '</form>';
  1143. }
  1144. }
  1145. else
  1146. {
  1147. dol_fiche_head($head2, $tab, '', -1, ''); // Level 2
  1148. }
  1149. if ($tab == 'specifications')
  1150. {
  1151. if ($action != 'editfile' || empty($file))
  1152. {
  1153. print $langs->trans("SpecDefDesc").'<br>';
  1154. print '<br>';
  1155. $specs=dol_dir_list(dol_buildpath($modulelowercase.'/doc', 0), 'files', 1, '(\.md|\.asciidoc)$', array('\/temp\/'));
  1156. foreach ($specs as $spec)
  1157. {
  1158. $pathtofile = $modulelowercase.'/doc/'.$spec['relativename'];
  1159. $format='asciidoc';
  1160. if (preg_match('/\.md$/i', $spec['name'])) $format='markdown';
  1161. print '<span class="fa fa-file-o"></span> '.$langs->trans("SpecificationFile").' : <strong>'.$pathtofile.'</strong>';
  1162. print ' <a href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&module='.$module.'&action=editfile&format='.$format.'&file='.urlencode($pathtofile).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
  1163. print '<br>';
  1164. }
  1165. }
  1166. else
  1167. {
  1168. // Use MD or asciidoc
  1169. //print $langs->trans("UseAsciiDocFormat").'<br>';
  1170. $fullpathoffile=dol_buildpath($file, 0);
  1171. $content = file_get_contents($fullpathoffile);
  1172. // New module
  1173. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  1174. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  1175. print '<input type="hidden" name="action" value="savefile">';
  1176. print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
  1177. print '<input type="hidden" name="tab" value="'.$tab.'">';
  1178. print '<input type="hidden" name="module" value="'.$module.'">';
  1179. $doleditor=new DolEditor('editfilecontent', $content, '', '300', 'Full', 'In', true, false, 'ace', 0, '99%');
  1180. print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format','aZ09')?GETPOST('format','aZ09'):'html'));
  1181. print '<br>';
  1182. print '<center>';
  1183. print '<input type="submit" class="button buttonforacesave" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
  1184. print ' &nbsp; ';
  1185. print '<input type="submit" class="button" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
  1186. print '</center>';
  1187. print '</form>';
  1188. }
  1189. }
  1190. if ($tab == 'languages')
  1191. {
  1192. if ($action != 'editfile' || empty($file))
  1193. {
  1194. print $langs->trans("LanguageDefDesc").'<br>';
  1195. print '<br>';
  1196. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  1197. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  1198. print '<input type="hidden" name="action" value="addlanguage">';
  1199. print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
  1200. print '<input type="hidden" name="tab" value="'.$tab.'">';
  1201. print '<input type="hidden" name="module" value="'.$module.'">';
  1202. print $formadmin->select_language($conf->global->MAIN_LANG_DEFAULT, 'newlangcode', 0, 0, 1, 0, 0, 'minwidth300', 1);
  1203. print '<input type="submit" name="addlanguage" class="button" value="'.dol_escape_htmltag($langs->trans("AddLanguageFile")).'"><br>';
  1204. print '</form>';
  1205. print '<br>';
  1206. print '<br>';
  1207. $langfiles=dol_dir_list(dol_buildpath($modulelowercase.'/langs', 0), 'files', 1, '\.lang$');
  1208. foreach ($langfiles as $langfile)
  1209. {
  1210. $pathtofile = $modulelowercase.'/langs/'.$langfile['relativename'];
  1211. print '<span class="fa fa-file-o"></span> '.$langs->trans("LanguageFile").' '.basename(dirname($pathtofile)).' : <strong>'.$pathtofile.'</strong>';
  1212. print ' <a href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&module='.$module.'&action=editfile&format='.$format.'&file='.urlencode($pathtofile).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
  1213. print '<br>';
  1214. }
  1215. }
  1216. else
  1217. {
  1218. // Edit text language file
  1219. //print $langs->trans("UseAsciiDocFormat").'<br>';
  1220. $fullpathoffile=dol_buildpath($file, 0);
  1221. $content = file_get_contents($fullpathoffile);
  1222. // New module
  1223. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  1224. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  1225. print '<input type="hidden" name="action" value="savefile">';
  1226. print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
  1227. print '<input type="hidden" name="tab" value="'.$tab.'">';
  1228. print '<input type="hidden" name="module" value="'.$module.'">';
  1229. $doleditor=new DolEditor('editfilecontent', $content, '', '300', 'Full', 'In', true, false, 'ace', 0, '99%');
  1230. print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format','aZ09')?GETPOST('format','aZ09'):'text'));
  1231. print '<br>';
  1232. print '<center>';
  1233. print '<input type="submit" class="button buttonforacesave" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
  1234. print ' &nbsp; ';
  1235. print '<input type="submit" class="button" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
  1236. print '</center>';
  1237. print '</form>';
  1238. }
  1239. }
  1240. if ($tab == 'objects')
  1241. {
  1242. $head3 = array();
  1243. $h=0;
  1244. // Dir for module
  1245. $dir = $dirread.'/'.$modulelowercase.'/class';
  1246. $head3[$h][0] = $_SERVER["PHP_SELF"].'?tab=objects&module='.$module.($forceddirread?'@'.$dirread:'').'&tabobj=newobject';
  1247. $head3[$h][1] = $langs->trans("NewObject");
  1248. $head3[$h][2] = 'newobject';
  1249. $h++;
  1250. // Scan for object class files
  1251. $listofobject = dol_dir_list($dir, 'files', 0, '\.class\.php$');
  1252. $firstobjectname='';
  1253. foreach($listofobject as $fileobj)
  1254. {
  1255. if (preg_match('/^api_/',$fileobj['name'])) continue;
  1256. if (preg_match('/^actions_/',$fileobj['name'])) continue;
  1257. $tmpcontent=file_get_contents($fileobj['fullname']);
  1258. if (preg_match('/class\s+([^\s]*)\s+extends\s+CommonObject/ims',$tmpcontent,$reg))
  1259. {
  1260. //$objectname = preg_replace('/\.txt$/', '', $fileobj['name']);
  1261. $objectname = $reg[1];
  1262. if (empty($firstobjectname)) $firstobjectname = $objectname;
  1263. $head3[$h][0] = $_SERVER["PHP_SELF"].'?tab=objects&module='.$module.($forceddirread?'@'.$dirread:'').'&tabobj='.$objectname;
  1264. $head3[$h][1] = $objectname;
  1265. $head3[$h][2] = $objectname;
  1266. $h++;
  1267. }
  1268. }
  1269. $head3[$h][0] = $_SERVER["PHP_SELF"].'?tab=objects&module='.$module.($forceddirread?'@'.$dirread:'').'&tabobj=deleteobject';
  1270. $head3[$h][1] = $langs->trans("DangerZone");
  1271. $head3[$h][2] = 'deleteobject';
  1272. $h++;
  1273. // 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.
  1274. if ($tabobj == 'newobjectifnoobj')
  1275. {
  1276. if ($firstobjectname) $tabobj=$firstobjectname;
  1277. else $tabobj = 'newobject';
  1278. }
  1279. dol_fiche_head($head3, $tabobj, '', -1, ''); // Level 3
  1280. if ($tabobj == 'newobject')
  1281. {
  1282. // New object tab
  1283. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  1284. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  1285. print '<input type="hidden" name="action" value="initobject">';
  1286. print '<input type="hidden" name="tab" value="objects">';
  1287. print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
  1288. print $langs->trans("EnterNameOfObjectDesc").'<br><br>';
  1289. print '<input type="text" name="objectname" value="'.dol_escape_htmltag(GETPOST('objectname','alpha')?GETPOST('objectname','alpha'):$modulename).'" placeholder="'.dol_escape_htmltag($langs->trans("ObjectKey")).'">';
  1290. print '<input type="submit" class="button" name="create" value="'.dol_escape_htmltag($langs->trans("Generate")).'"'.($dirins?'':' disabled="disabled"').'>';
  1291. print '<br>';
  1292. print '<br>';
  1293. print '<br>';
  1294. print $langs->trans("Or");
  1295. print '<br>';
  1296. print '<br>';
  1297. print '<br>';
  1298. //print '<input type="checkbox" name="initfromtablecheck"> ';
  1299. print $langs->trans("InitStructureFromExistingTable");
  1300. print '<input type="text" name="initfromtablename" value="" placeholder="'.$langs->trans("TableName").'">';
  1301. print '<input type="submit" class="button" name="createtablearray" value="'.dol_escape_htmltag($langs->trans("Generate")).'"'.($dirins?'':' disabled="disabled"').'>';
  1302. print '<br>';
  1303. print '</form>';
  1304. }
  1305. elseif ($tabobj == 'deleteobject')
  1306. {
  1307. // Delete object tab
  1308. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  1309. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  1310. print '<input type="hidden" name="action" value="confirm_deleteobject">';
  1311. print '<input type="hidden" name="tab" value="objects">';
  1312. print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
  1313. print $langs->trans("EnterNameOfObjectToDeleteDesc").'<br><br>';
  1314. print '<input type="text" name="objectname" value="'.dol_escape_htmltag($modulename).'" placeholder="'.dol_escape_htmltag($langs->trans("ObjectKey")).'">';
  1315. print '<input type="submit" class="buttonDelete" name="delete" value="'.dol_escape_htmltag($langs->trans("Delete")).'"'.($dirins?'':' disabled="disabled"').'>';
  1316. print '</form>';
  1317. }
  1318. else
  1319. { // tabobj = module
  1320. if ($action == 'deleteproperty')
  1321. {
  1322. $formconfirm = $form->formconfirm(
  1323. $_SERVER["PHP_SELF"].'?propertykey='.urlencode(GETPOST('propertykey','alpha')).'&objectname='.urlencode($objectname).'&tab='.urlencode($tab).'&module='.urlencode($module).'&tabobj='.urlencode($tabobj),
  1324. $langs->trans('Delete'), $langs->trans('ConfirmDeleteProperty', GETPOST('propertykey','alpha')), 'confirm_deleteproperty', '', 0, 1
  1325. );
  1326. // Print form confirm
  1327. print $formconfirm;
  1328. }
  1329. if ($action != 'editfile' || empty($file))
  1330. {
  1331. try {
  1332. //$pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
  1333. $pathtoclass = strtolower($module).'/class/'.strtolower($tabobj).'.class.php';
  1334. $pathtoapi = strtolower($module).'/class/api_'.strtolower($module).'.class.php';
  1335. $pathtoagenda = strtolower($module).'/'.strtolower($tabobj).'_agenda.php';
  1336. $pathtocard = strtolower($module).'/'.strtolower($tabobj).'_card.php';
  1337. $pathtodocument = strtolower($module).'/'.strtolower($tabobj).'_document.php';
  1338. $pathtolist = strtolower($module).'/'.strtolower($tabobj).'_list.php';
  1339. $pathtonote = strtolower($module).'/'.strtolower($tabobj).'_note.php';
  1340. $pathtophpunit = strtolower($module).'/test/phpunit/'.$tabobj.'Test.php';
  1341. $pathtosql = strtolower($module).'/sql/llx_'.strtolower($module).'_'.strtolower($tabobj).'.sql';
  1342. $pathtosqlextra = strtolower($module).'/sql/llx_'.strtolower($module).'_'.strtolower($tabobj).'_extrafields.sql';
  1343. $pathtosqlkey = strtolower($module).'/sql/llx_'.strtolower($module).'_'.strtolower($tabobj).'.key.sql';
  1344. $pathtolib = strtolower($module).'/lib/'.strtolower($tabobj).'.lib.php';
  1345. $pathtopicto = strtolower($module).'/img/object_'.strtolower($tabobj).'.png';
  1346. $pathtoscript = strtolower($module).'/scripts/'.strtolower($tabobj).'.php';
  1347. //var_dump($pathtolib);
  1348. $realpathtoclass = dol_buildpath($pathtoclass, 0, 2);
  1349. $realpathtoapi = dol_buildpath($pathtoapi, 0, 2);
  1350. $realpathtoagenda = dol_buildpath($pathtoagenda, 0, 2);
  1351. $realpathtocard = dol_buildpath($pathtocard, 0, 2);
  1352. $realpathtodocument = dol_buildpath($pathtodocument, 0, 2);
  1353. $realpathtolist = dol_buildpath($pathtolist, 0, 2);
  1354. $realpathtonote = dol_buildpath($pathtonote, 0, 2);
  1355. $realpathtophpunit = dol_buildpath($pathtophpunit, 0, 2);
  1356. $realpathtosql = dol_buildpath($pathtosql, 0, 2);
  1357. $realpathtosqlextra = dol_buildpath($pathtosqlextra, 0, 2);
  1358. $realpathtosqlkey = dol_buildpath($pathtosqlkey, 0, 2);
  1359. $realpathtolib = dol_buildpath($pathtolib, 0, 2);
  1360. $realpathtopicto = dol_buildpath($pathtopicto, 0, 2);
  1361. $realpathtoscript = dol_buildpath($pathtoscript, 0, 2);
  1362. print '<div class="fichehalfleft">';
  1363. print '<span class="fa fa-file-o"></span> '.$langs->trans("ClassFile").' : <strong>'.($realpathtoclass?'':'<strike>').$pathtoclass.($realpathtoclass?'':'</strike>').'</strong>';
  1364. print ' <a 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>';
  1365. print '<br>';
  1366. print '<span class="fa fa-file-o"></span> '.$langs->trans("ApiClassFile").' : <strong>'.($realpathtoapi?'':'<strike>').$pathtoapi.($realpathtoapi?'':'</strike>').'</strong>';
  1367. print ' <a 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>';
  1368. print ' &nbsp; <a href="'.DOL_URL_ROOT.'/api/index.php/explorer/" target="apiexplorer">'.$langs->trans("GoToApiExplorer").'</a>';
  1369. print '<br>';
  1370. print '<span class="fa fa-file-o"></span> '.$langs->trans("TestClassFile").' : <strong>'.($realpathtophpunit?'':'<strike>').$pathtophpunit.($realpathtophpunit?'':'</strike>').'</strong>';
  1371. print ' <a 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>';
  1372. print '<br>';
  1373. print '<br>';
  1374. print '<span class="fa fa-file-o"></span> '.$langs->trans("PageForLib").' : <strong>'.($realpathtolib?'':'<strike>').$pathtolib.($realpathtolib?'':'</strike>').'</strong>';
  1375. print ' <a 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>';
  1376. print '<br>';
  1377. print '<span class="fa fa-file-image-o"></span> '.$langs->trans("Image").' : <strong>'.($realpathtopicto?'':'<strike>').$pathtopicto.($realpathtopicto?'':'</strike>').'</strong>';
  1378. //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>';
  1379. print '<br>';
  1380. print '<br>';
  1381. print '<span class="fa fa-file-o"></span> '.$langs->trans("SqlFile").' : <strong>'.($realpathtosql?'':'<strike>').$pathtosql.($realpathtosql?'':'</strike>').'</strong>';
  1382. print ' <a 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>';
  1383. print ' &nbsp; <a href="'.$_SERVER["PHP_SELF"].'?tab='.$tab.'&tabobj='.$tabobj.'&module='.$module.($forceddirread?'@'.$dirread:'').'&action=droptable">'.$langs->trans("DropTableIfEmpty").'</a>';
  1384. //print ' &nbsp; <a href="'.$_SERVER["PHP_SELF"].'">'.$langs->trans("RunSql").'</a>';
  1385. print '<br>';
  1386. print '<span class="fa fa-file-o"></span> '.$langs->trans("SqlFileExtraFields").' : <strong>'.($realpathtosqlextra?'':'<strike>').$pathtosqlextra.($realpathtosqlextra?'':'</strike>').'</strong>';
  1387. print ' <a href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&tabobj='.$tabobj.'&module='.$module.($forceddirread?'@'.$dirread:'').'&action=editfile&file='.urlencode($pathtosqlextra).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
  1388. print ' &nbsp; <a href="'.$_SERVER["PHP_SELF"].'?tab='.$tab.'&tabobj='.$tabobj.'&module='.$module.($forceddirread?'@'.$dirread:'').'&action=droptableextrafields">'.$langs->trans("DropTableIfEmpty").'</a>';
  1389. //print ' &nbsp; <a href="'.$_SERVER["PHP_SELF"].'">'.$langs->trans("RunSql").'</a>';
  1390. print '<br>';
  1391. print '<span class="fa fa-file-o"></span> '.$langs->trans("SqlFileKey").' : <strong>'.($realpathtosqlkey?'':'<strike>').$pathtosqlkey.($realpathtosqlkey?'':'</strike>').'</strong>';
  1392. print ' <a 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>';
  1393. //print ' &nbsp; <a href="'.$_SERVER["PHP_SELF"].'">'.$langs->trans("RunSql").'</a>';
  1394. print '<br>';
  1395. print '<br>';
  1396. print '</div>';
  1397. $urloflist = dol_buildpath($pathtolist, 1);
  1398. $urlofcard = dol_buildpath($pathtocard, 1);
  1399. print '<div class="fichehalfleft">';
  1400. print '<span class="fa fa-file-o"></span> '.$langs->trans("PageForList").' : <strong><a href="'.$urloflist.'" target="_test">'.($realpathtosql?'':'<strike>').$pathtolist.($realpathtosql?'':'</strike>').'</a></strong>';
  1401. print ' <a 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>';
  1402. print '<br>';
  1403. 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>';
  1404. print ' <a 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>';
  1405. print '<br>';
  1406. print '<span class="fa fa-file-o"></span> '.$langs->trans("PageForAgendaTab").' : <strong>'.($realpathtoagenda?'':'<strike>').$pathtoagenda.($realpathtoagenda?'':'</strike>').'</strong>';
  1407. print ' <a 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>';
  1408. print '<br>';
  1409. print '<span class="fa fa-file-o"></span> '.$langs->trans("PageForDocumentTab").' : <strong>'.($realpathtodocument?'':'<strike>').$pathtodocument.($realpathtodocument?'':'</strike>').'</strong>';
  1410. print ' <a 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>';
  1411. print '<br>';
  1412. print '<span class="fa fa-file-o"></span> '.$langs->trans("PageForNoteTab").' : <strong>'.($realpathtonote?'':'<strike>').$pathtonote.($realpathtonote?'':'</strike>').'</strong>';
  1413. print ' <a 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>';
  1414. print '<br>';
  1415. print '<br>';
  1416. print '<span class="fa fa-file-o"></span> '.$langs->trans("ScriptFile").' : <strong>'.($realpathtoscript?'':'<strike>').$pathtoscript.($realpathtoscript?'':'</strike>').'</strong>';
  1417. 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>';
  1418. print '<br>';
  1419. print '<br>';
  1420. print '</div>';
  1421. print '<br><br><br>';
  1422. if(function_exists('opcache_invalidate')) opcache_invalidate($dirread.'/'.$pathtoclass,true); // remove the include cache hell !
  1423. if (empty($forceddirread))
  1424. {
  1425. $result = dol_include_once($pathtoclass);
  1426. }
  1427. else
  1428. {
  1429. $result = @include_once $dirread.'/'.$pathtoclass;
  1430. }
  1431. if (class_exists($tabobj))
  1432. {
  1433. try {
  1434. $tmpobjet = @new $tabobj($db);
  1435. }
  1436. catch(Exception $e)
  1437. {
  1438. dol_syslog('Failed to load Constructor of class: '.$e->getMessage(), LOG_WARNING);
  1439. }
  1440. }
  1441. if (! empty($tmpobjet))
  1442. {
  1443. $reflector = new ReflectionClass($tabobj);
  1444. $reflectorproperties = $reflector->getProperties(); // Can also use get_object_vars
  1445. $reflectorpropdefault = $reflector->getDefaultProperties(); // Can also use get_object_vars
  1446. //$propstat = $reflector->getStaticProperties();
  1447. //var_dump($reflectorpropdefault);
  1448. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  1449. print '<input class="button" type="submit" name="regenerateclasssql" value="'.$langs->trans("RegenerateClassAndSql").'">';
  1450. print '<input class="button" type="submit" name="regeneratemissing" value="'.$langs->trans("RegenerateMissingFiles").'">';
  1451. print '<br><br>';
  1452. print load_fiche_titre($langs->trans("Properties"), '', '');
  1453. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  1454. print '<input type="hidden" name="action" value="addproperty">';
  1455. print '<input type="hidden" name="tab" value="objects">';
  1456. print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module.($forceddirread?'@'.$dirread:'')).'">';
  1457. print '<input type="hidden" name="tabobj" value="'.dol_escape_htmltag($tabobj).'">';
  1458. print '<div class="div-table-responsive">';
  1459. print '<table class="noborder">';
  1460. print '<tr class="liste_titre">';
  1461. print '<th class="liste_titre">'.$langs->trans("Property");
  1462. print ' (<a class="" href="https://wiki.dolibarr.org/index.php/Language_and_development_rules#Table_and_fields_structures" target="_blank">'.$langs->trans("SeeExamples").'</a>)';
  1463. print '</th>';
  1464. print '<th>';
  1465. print $form->textwithpicto($langs->trans("Label"), $langs->trans("YouCanUseTranslationKey"));
  1466. print '</th>';
  1467. print '<th>'.$langs->trans("Type").'</td>';
  1468. print '<th>'.$form->textwithpicto($langs->trans("ArrayOfKeyValues"), $langs->trans("ArrayOfKeyValuesDesc")).'</th>';
  1469. print '<th class="center">'.$form->textwithpicto($langs->trans("NotNull"), $langs->trans("NotNullDesc")).'</th>';
  1470. print '<th class="center">'.$langs->trans("DefaultValue").'</th>';
  1471. print '<th class="center">'.$langs->trans("DatabaseIndex").'</th>';
  1472. print '<th class="right">'.$langs->trans("Position").'</th>';
  1473. print '<th class="center">'.$form->textwithpicto($langs->trans("Enabled"), $langs->trans("EnabledDesc")).'</th>';
  1474. print '<th class="center">'.$form->textwithpicto($langs->trans("Visible"), $langs->trans("VisibleDesc")).'</th>';
  1475. print '<th class="center">'.$form->textwithpicto($langs->trans("IsAMeasure"), $langs->trans("IsAMeasureDesc")).'</th>';
  1476. print '<th class="center">'.$form->textwithpicto($langs->trans("SearchAll"), $langs->trans("SearchAllDesc")).'</th>';
  1477. print '<th>'.$langs->trans("Comment").'</th>';
  1478. print '<th></th>';
  1479. print '</tr>';
  1480. // We must use $reflectorpropdefault['fields'] to get list of fields because $tmpobjet->fields may have been
  1481. // modified during the constructor and we want value into head of class before constructor is called.
  1482. //$properties = dol_sort_array($tmpobjet->fields, 'position');
  1483. $properties = dol_sort_array($reflectorpropdefault['fields'], 'position');
  1484. if (! empty($properties))
  1485. {
  1486. // Line to add a property
  1487. print '<tr>';
  1488. print '<td><input class="text maxwidth75" name="propname" value="'.dol_escape_htmltag(GETPOST('propname','alpha')).'"></td>';
  1489. print '<td><input class="text maxwidth75" name="proplabel" value="'.dol_escape_htmltag(GETPOST('proplabel','alpha')).'"></td>';
  1490. print '<td><input class="text maxwidth75" name="proptype" value="'.dol_escape_htmltag(GETPOST('proptype','alpha')).'"></td>';
  1491. print '<td><input class="text maxwidth75" name="proparrayofkeyval" value="'.dol_escape_htmltag(GETPOST('proparrayofkeyval','none')).'"></td>';
  1492. print '<td class="center"><input class="text" size="2" name="propnotnull" value="'.dol_escape_htmltag(GETPOST('propnotnull','alpha')).'"></td>';
  1493. print '<td><input class="text maxwidth50" name="propdefault" value="'.dol_escape_htmltag(GETPOST('propdefault','alpha')).'"></td>';
  1494. print '<td class="center"><input class="text" size="2" name="propindex" value="'.dol_escape_htmltag(GETPOST('propindex','alpha')).'"></td>';
  1495. print '<td class="right"><input class="text right" size="2" name="propposition" value="'.dol_escape_htmltag(GETPOST('propposition','alpha')).'"></td>';
  1496. print '<td class="center"><input class="text" size="2" name="propenabled" value="'.dol_escape_htmltag(GETPOST('propenabled','alpha')).'"></td>';
  1497. print '<td class="center"><input class="text" size="2" name="propvisible" value="'.dol_escape_htmltag(GETPOST('propvisible','alpha')).'"></td>';
  1498. print '<td class="center"><input class="text" size="2" name="propisameasure" value="'.dol_escape_htmltag(GETPOST('propisameasure','alpha')).'"></td>';
  1499. print '<td class="center"><input class="text" size="2" name="propsearchall" value="'.dol_escape_htmltag(GETPOST('propsearchall','alpha')).'"></td>';
  1500. print '<td><input class="text maxwidth100" name="propcomment" value="'.dol_escape_htmltag(GETPOST('propcomment','alpha')).'"></td>';
  1501. print '<td align="center">';
  1502. print '<input class="button" type="submit" name="add" value="'.$langs->trans("Add").'">';
  1503. print '</td></tr>';
  1504. foreach($properties as $propkey => $propval)
  1505. {
  1506. /* If from Reflection
  1507. if ($propval->class == $tabobj)
  1508. {
  1509. $propname=$propval->getName();
  1510. $comment=$propval->getDocComment();
  1511. $type=gettype($tmpobjet->$propname);
  1512. $default=$propdefault[$propname];
  1513. // Discard generic properties
  1514. if (in_array($propname, array('element', 'childtables', 'table_element', 'table_element_line', 'class_element_line', 'ismultientitymanaged'))) continue;
  1515. // Keep or not lines
  1516. if (in_array($propname, array('fk_element', 'lines'))) continue;
  1517. }*/
  1518. $propname=$propkey;
  1519. $proplabel=$propval['label'];
  1520. $proptype=$propval['type'];
  1521. $proparrayofkeyval=$propval['arrayofkeyval'];
  1522. $propnotnull=$propval['notnull'];
  1523. $propsearchall=$propval['searchall'];
  1524. $propdefault=$propval['default'];
  1525. $propindex=$propval['index'];
  1526. $propposition=$propval['position'];
  1527. $propenabled=$propval['enabled'];
  1528. $propvisible=$propval['visible'];
  1529. $propisameasure=$propval['isameasure'];
  1530. $propcomment=$propval['comment'];
  1531. print '<tr class="oddeven">';
  1532. print '<td>';
  1533. print $propname;
  1534. print '</td>';
  1535. print '<td>';
  1536. print $proplabel;
  1537. print '</td>';
  1538. print '<td>';
  1539. print $proptype;
  1540. print '</td>';
  1541. print '<td>';
  1542. if ($proparrayofkeyval)
  1543. {
  1544. print json_encode($proparrayofkeyval);
  1545. }
  1546. print '</td>';
  1547. print '<td class="center">';
  1548. print $propnotnull;
  1549. print '</td>';
  1550. print '<td>';
  1551. print $propdefault;
  1552. print '</td>';
  1553. print '<td class="center">';
  1554. print $propindex?'1':'';
  1555. print '</td>';
  1556. print '<td align="right">';
  1557. print $propposition;
  1558. print '</td>';
  1559. print '<td class="center">';
  1560. print $propenabled?$propenabled:'';
  1561. print '</td>';
  1562. print '<td class="center">';
  1563. print $propvisible?$propvisible:'';
  1564. print '</td>';
  1565. print '<td class="center">';
  1566. print $propisameasure?$propisameasure:'';
  1567. print '</td>';
  1568. print '<td class="center">';
  1569. print $propsearchall?'1':'';
  1570. print '</td>';
  1571. print '<td>';
  1572. print $propcomment;
  1573. print '</td>';
  1574. print '<td class="center">';
  1575. print '<a href="'.$_SERVER["PHP_SELF"].'?action=deleteproperty&propertykey='.urlencode($propname).'&tab='.urlencode($tab).'&module='.urlencode($module).'&tabobj='.urlencode($tabobj).'">'.img_delete().'</a>';
  1576. print '</td>';
  1577. print '</tr>';
  1578. }
  1579. }
  1580. else
  1581. {
  1582. 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>';
  1583. }
  1584. print '</table>';
  1585. print '</div>';
  1586. print '</form>';
  1587. }
  1588. else
  1589. {
  1590. print '<tr><td><span class="warning">'.$langs->trans('Failed to init the object with the new.').'</warning></td></tr>';
  1591. }
  1592. }
  1593. catch(Exception $e)
  1594. {
  1595. print $e->getMessage();
  1596. }
  1597. }
  1598. else
  1599. {
  1600. if (empty($forceddirread))
  1601. {
  1602. $fullpathoffile=dol_buildpath($file, 0);
  1603. }
  1604. else
  1605. {
  1606. $fullpathoffile=$dirread.'/'.$file;
  1607. }
  1608. $content = file_get_contents($fullpathoffile);
  1609. // New module
  1610. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  1611. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  1612. print '<input type="hidden" name="action" value="savefile">';
  1613. print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
  1614. print '<input type="hidden" name="tab" value="'.$tab.'">';
  1615. print '<input type="hidden" name="tabobj" value="'.dol_escape_htmltag($tabobj).'">';
  1616. print '<input type="hidden" name="module" value="'.$module.($forceddirread?'@'.$dirread:'').'">';
  1617. $doleditor=new DolEditor('editfilecontent', $content, '', '300', 'Full', 'In', true, false, 'ace', 0, '99%');
  1618. print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format','aZ09')?GETPOST('format','aZ09'):'html'));
  1619. print '<br>';
  1620. print '<center>';
  1621. print '<input type="submit" class="button buttonforacesave" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
  1622. print ' &nbsp; ';
  1623. print '<input type="submit" class="button" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
  1624. print '</center>';
  1625. print '</form>';
  1626. }
  1627. }
  1628. dol_fiche_end(); // Level 3
  1629. }
  1630. if ($tab == 'menus')
  1631. {
  1632. $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
  1633. //$menus = $moduleobj->;
  1634. if ($action != 'editfile' || empty($file))
  1635. {
  1636. print $langs->trans("MenusDefDesc", '<a href="'.DOL_URL_ROOT.'/admin/menus/index.php">'.$langs->trans('Menus').'</a>').'<br>';
  1637. print '<br>';
  1638. print '<span class="fa fa-file-o"></span> '.$langs->trans("DescriptorFile").' : <strong>'.$pathtofile.'</strong>';
  1639. print ' <a href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&module='.$module.'&action=editfile&format=php&file='.urlencode($pathtofile).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
  1640. print '<br>';
  1641. print '<br>';
  1642. print load_fiche_titre($langs->trans("ListOfMenusEntries"), '', '');
  1643. print 'TODO...';
  1644. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  1645. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  1646. print '<input type="hidden" name="action" value="addproperty">';
  1647. print '<input type="hidden" name="tab" value="objects">';
  1648. print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
  1649. print '<input type="hidden" name="tabobj" value="'.dol_escape_htmltag($tabobj).'">';
  1650. /*
  1651. print '<div class="div-table-responsive">';
  1652. print '<table class="noborder">';
  1653. print '<tr class="liste_titre">';
  1654. print_liste_field_titre("Menu",$_SERVER["PHP_SELF"],"","",$param,'',$sortfield,$sortorder);
  1655. print_liste_field_titre("CronTask",'','',"",$param,'',$sortfield,$sortorder);
  1656. print_liste_field_titre("CronFrequency",'',"","",$param,'',$sortfield,$sortorder);
  1657. print_liste_field_titre("StatusAtInstall",$_SERVER["PHP_SELF"],"","",$param,'',$sortfield,$sortorder);
  1658. print_liste_field_titre("Comment",$_SERVER["PHP_SELF"],"","",$param,'',$sortfield,$sortorder);
  1659. print "</tr>\n";
  1660. if (count($menus))
  1661. {
  1662. foreach ($cronjobs as $cron)
  1663. {
  1664. print '<tr class="oddeven">';
  1665. print '<td>';
  1666. print $cron['label'];
  1667. print '</td>';
  1668. print '<td>';
  1669. if ($cron['jobtype']=='method')
  1670. {
  1671. $text=$langs->trans("CronClass");
  1672. $texttoshow=$langs->trans('CronModule').': '.$module.'<br>';
  1673. $texttoshow.=$langs->trans('CronClass').': '. $cron['class'].'<br>';
  1674. $texttoshow.=$langs->trans('CronObject').': '. $cron['objectname'].'<br>';
  1675. $texttoshow.=$langs->trans('CronMethod').': '. $cron['method'];
  1676. $texttoshow.='<br>'.$langs->trans('CronArgs').': '. $cron['parameters'];
  1677. $texttoshow.='<br>'.$langs->trans('Comment').': '. $langs->trans($cron['comment']);
  1678. }
  1679. elseif ($cron['jobtype']=='command')
  1680. {
  1681. $text=$langs->trans('CronCommand');
  1682. $texttoshow=$langs->trans('CronCommand').': '.dol_trunc($cron['command']);
  1683. $texttoshow.='<br>'.$langs->trans('CronArgs').': '. $cron['parameters'];
  1684. $texttoshow.='<br>'.$langs->trans('Comment').': '. $langs->trans($cron['comment']);
  1685. }
  1686. print $form->textwithpicto($text, $texttoshow, 1);
  1687. print '</td>';
  1688. print '<td>';
  1689. if($cron['unitfrequency'] == "60") print $langs->trans('CronEach')." ".($cron['frequency'])." ".$langs->trans('Minutes');
  1690. if($cron['unitfrequency'] == "3600") print $langs->trans('CronEach')." ".($cron['frequency'])." ".$langs->trans('Hours');
  1691. if($cron['unitfrequency'] == "86400") print $langs->trans('CronEach')." ".($cron['frequency'])." ".$langs->trans('Days');
  1692. if($cron['unitfrequency'] == "604800") print $langs->trans('CronEach')." ".($cron['frequency'])." ".$langs->trans('Weeks');
  1693. print '</td>';
  1694. print '<td>';
  1695. print $cron['status'];
  1696. print '</td>';
  1697. print '<td>';
  1698. if (!empty($cron['comment'])) {print $cron['comment'];}
  1699. print '</td>';
  1700. print '</tr>';
  1701. }
  1702. }
  1703. else
  1704. {
  1705. print '<tr><td class="opacitymedium" colspan="5">'.$langs->trans("None").'</td></tr>';
  1706. }
  1707. print '</table>';
  1708. print '</div>';
  1709. print '</form>';
  1710. */
  1711. }
  1712. else
  1713. {
  1714. $fullpathoffile=dol_buildpath($file, 0);
  1715. $content = file_get_contents($fullpathoffile);
  1716. // New module
  1717. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  1718. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  1719. print '<input type="hidden" name="action" value="savefile">';
  1720. print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
  1721. print '<input type="hidden" name="tab" value="'.$tab.'">';
  1722. print '<input type="hidden" name="module" value="'.$module.'">';
  1723. $doleditor=new DolEditor('editfilecontent', $content, '', '300', 'Full', 'In', true, false, 'ace', 0, '99%');
  1724. print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format','aZ09')?GETPOST('format','aZ09'):'html'));
  1725. print '<br>';
  1726. print '<center>';
  1727. print '<input type="submit" class="button buttonforacesave" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
  1728. print ' &nbsp; ';
  1729. print '<input type="submit" class="button" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
  1730. print '</center>';
  1731. print '</form>';
  1732. }
  1733. }
  1734. if ($tab == 'permissions')
  1735. {
  1736. $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
  1737. //$perms = $moduleobj->;
  1738. if ($action != 'editfile' || empty($file))
  1739. {
  1740. print $langs->trans("PermissionsDefDesc", '<a href="'.DOL_URL_ROOT.'/admin/perms.php">'.$langs->trans('DefaultPermissions').'</a>').'<br>';
  1741. print '<br>';
  1742. print '<span class="fa fa-file-o"></span> '.$langs->trans("DescriptorFile").' : <strong>'.$pathtofile.'</strong>';
  1743. print ' <a href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&module='.$module.'&action=editfile&format=php&file='.urlencode($pathtofile).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
  1744. print '<br>';
  1745. print '<br>';
  1746. print load_fiche_titre($langs->trans("ListOfPermissionsDefined"), '', '');
  1747. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  1748. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  1749. print '<input type="hidden" name="action" value="addproperty">';
  1750. print '<input type="hidden" name="tab" value="objects">';
  1751. print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
  1752. print '<input type="hidden" name="tabobj" value="'.dol_escape_htmltag($tabobj).'">';
  1753. print 'TODO...';
  1754. /*
  1755. print '<div class="div-table-responsive">';
  1756. print '<table class="noborder">';
  1757. print '<tr class="liste_titre">';
  1758. print_liste_field_titre("CronLabel",$_SERVER["PHP_SELF"],"","",$param,'',$sortfield,$sortorder);
  1759. print_liste_field_titre("CronTask",'','',"",$param,'',$sortfield,$sortorder);
  1760. print_liste_field_titre("CronFrequency",'',"","",$param,'',$sortfield,$sortorder);
  1761. print_liste_field_titre("StatusAtInstall",$_SERVER["PHP_SELF"],"","",$param,'',$sortfield,$sortorder);
  1762. print_liste_field_titre("Comment",$_SERVER["PHP_SELF"],"","",$param,'',$sortfield,$sortorder);
  1763. print "</tr>\n";
  1764. if (count($cronjobs))
  1765. {
  1766. foreach ($cronjobs as $cron)
  1767. {
  1768. print '<tr class="oddeven">';
  1769. print '<td>';
  1770. print $cron['label'];
  1771. print '</td>';
  1772. print '<td>';
  1773. if ($cron['jobtype']=='method')
  1774. {
  1775. $text=$langs->trans("CronClass");
  1776. $texttoshow=$langs->trans('CronModule').': '.$module.'<br>';
  1777. $texttoshow.=$langs->trans('CronClass').': '. $cron['class'].'<br>';
  1778. $texttoshow.=$langs->trans('CronObject').': '. $cron['objectname'].'<br>';
  1779. $texttoshow.=$langs->trans('CronMethod').': '. $cron['method'];
  1780. $texttoshow.='<br>'.$langs->trans('CronArgs').': '. $cron['parameters'];
  1781. $texttoshow.='<br>'.$langs->trans('Comment').': '. $langs->trans($cron['comment']);
  1782. }
  1783. elseif ($cron['jobtype']=='command')
  1784. {
  1785. $text=$langs->trans('CronCommand');
  1786. $texttoshow=$langs->trans('CronCommand').': '.dol_trunc($cron['command']);
  1787. $texttoshow.='<br>'.$langs->trans('CronArgs').': '. $cron['parameters'];
  1788. $texttoshow.='<br>'.$langs->trans('Comment').': '. $langs->trans($cron['comment']);
  1789. }
  1790. print $form->textwithpicto($text, $texttoshow, 1);
  1791. print '</td>';
  1792. print '<td>';
  1793. if($cron['unitfrequency'] == "60") print $langs->trans('CronEach')." ".($cron['frequency'])." ".$langs->trans('Minutes');
  1794. if($cron['unitfrequency'] == "3600") print $langs->trans('CronEach')." ".($cron['frequency'])." ".$langs->trans('Hours');
  1795. if($cron['unitfrequency'] == "86400") print $langs->trans('CronEach')." ".($cron['frequency'])." ".$langs->trans('Days');
  1796. if($cron['unitfrequency'] == "604800") print $langs->trans('CronEach')." ".($cron['frequency'])." ".$langs->trans('Weeks');
  1797. print '</td>';
  1798. print '<td>';
  1799. print $cron['status'];
  1800. print '</td>';
  1801. print '<td>';
  1802. if (!empty($cron['comment'])) {print $cron['comment'];}
  1803. print '</td>';
  1804. print '</tr>';
  1805. }
  1806. }
  1807. else
  1808. {
  1809. print '<tr><td class="opacitymedium" colspan="5">'.$langs->trans("None").'</td></tr>';
  1810. }
  1811. print '</table>';
  1812. print '</div>';
  1813. print '</form>';
  1814. */
  1815. }
  1816. else
  1817. {
  1818. $fullpathoffile=dol_buildpath($file, 0);
  1819. $content = file_get_contents($fullpathoffile);
  1820. // New module
  1821. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  1822. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  1823. print '<input type="hidden" name="action" value="savefile">';
  1824. print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
  1825. print '<input type="hidden" name="tab" value="'.$tab.'">';
  1826. print '<input type="hidden" name="module" value="'.$module.'">';
  1827. $doleditor=new DolEditor('editfilecontent', $content, '', '300', 'Full', 'In', true, false, 'ace', 0, '99%');
  1828. print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format','aZ09')?GETPOST('format','aZ09'):'html'));
  1829. print '<br>';
  1830. print '<center>';
  1831. print '<input type="submit" class="button buttonforacesave" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
  1832. print ' &nbsp; ';
  1833. print '<input type="submit" class="button" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
  1834. print '</center>';
  1835. print '</form>';
  1836. }
  1837. }
  1838. if ($tab == 'hooks')
  1839. {
  1840. if ($action != 'editfile' || empty($file))
  1841. {
  1842. print $langs->trans("HooksDefDesc").'<br>';
  1843. print '<br>';
  1844. $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
  1845. print '<span class="fa fa-file-o"></span> '.$langs->trans("DescriptorFile").' : <strong>'.$pathtofile.'</strong>';
  1846. print ' <a href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&module='.$module.'&action=editfile&format=php&file='.urlencode($pathtofile).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
  1847. print '<br>';
  1848. $pathtohook = strtolower($module).'/class/actions_'.strtolower($module).'.class.php';
  1849. print '<span class="fa fa-file-o"></span> '.$langs->trans("HooksFile").' : <strong>'.$pathtohook.'</strong>';
  1850. print ' <a href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&module='.$module.'&action=editfile&format=php&file='.urlencode($pathtohook).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
  1851. print '<br>';
  1852. }
  1853. else
  1854. {
  1855. $fullpathoffile=dol_buildpath($file, 0);
  1856. $content = file_get_contents($fullpathoffile);
  1857. // New module
  1858. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  1859. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  1860. print '<input type="hidden" name="action" value="savefile">';
  1861. print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
  1862. print '<input type="hidden" name="tab" value="'.$tab.'">';
  1863. print '<input type="hidden" name="module" value="'.$module.'">';
  1864. $doleditor=new DolEditor('editfilecontent', $content, '', '300', 'Full', 'In', true, false, 'ace', 0, '99%');
  1865. print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format','aZ09')?GETPOST('format','aZ09'):'html'));
  1866. print '<br>';
  1867. print '<center>';
  1868. print '<input type="submit" class="button buttonforacesave" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
  1869. print ' &nbsp; ';
  1870. print '<input type="submit" class="button" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
  1871. print '</center>';
  1872. print '</form>';
  1873. }
  1874. }
  1875. if ($tab == 'triggers')
  1876. {
  1877. require_once DOL_DOCUMENT_ROOT.'/core/class/interfaces.class.php';
  1878. $interfaces = new Interfaces($db);
  1879. $triggers = $interfaces->getTriggersList(array('/'.strtolower($module).'/core/triggers'));
  1880. if ($action != 'editfile' || empty($file))
  1881. {
  1882. print $langs->trans("TriggerDefDesc").'<br>';
  1883. print '<br>';
  1884. if (! empty($triggers))
  1885. {
  1886. foreach ($triggers as $trigger)
  1887. {
  1888. $pathtofile = $trigger['relpath'];
  1889. print '<span class="fa fa-file-o"></span> '.$langs->trans("TriggersFile").' : <strong>'.$pathtofile.'</strong>';
  1890. print ' <a href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&module='.$module.'&action=editfile&format=php&file='.urlencode($pathtofile).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
  1891. print '<br>';
  1892. }
  1893. }
  1894. else
  1895. {
  1896. print $langs->trans("NoTrigger");
  1897. }
  1898. }
  1899. else
  1900. {
  1901. $fullpathoffile=dol_buildpath($file, 0);
  1902. $content = file_get_contents($fullpathoffile);
  1903. // New module
  1904. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  1905. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  1906. print '<input type="hidden" name="action" value="savefile">';
  1907. print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
  1908. print '<input type="hidden" name="tab" value="'.$tab.'">';
  1909. print '<input type="hidden" name="module" value="'.$module.'">';
  1910. $doleditor=new DolEditor('editfilecontent', $content, '', '300', 'Full', 'In', true, false, 'ace', 0, '99%');
  1911. print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format','aZ09')?GETPOST('format','aZ09'):'html'));
  1912. print '<br>';
  1913. print '<center>';
  1914. print '<input type="submit" class="button buttonforacesave" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
  1915. print ' &nbsp; ';
  1916. print '<input type="submit" class="button" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
  1917. print '</center>';
  1918. print '</form>';
  1919. }
  1920. }
  1921. if ($tab == 'widgets')
  1922. {
  1923. require_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
  1924. $widgets = ModeleBoxes::getWidgetsList(array('/'.strtolower($module).'/core/boxes'));
  1925. if ($action != 'editfile' || empty($file))
  1926. {
  1927. if (! empty($widget))
  1928. {
  1929. foreach ($widgets as $widget)
  1930. {
  1931. $pathtofile = $widget['relpath'];
  1932. print '<span class="fa fa-file-o"></span> '.$langs->trans("WidgetFile").' : <strong>'.$pathtofile.'</strong>';
  1933. print ' <a href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&module='.$module.'&action=editfile&format=php&file='.urlencode($pathtofile).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
  1934. print '<br>';
  1935. }
  1936. }
  1937. else
  1938. {
  1939. print $langs->trans("NoWidget");
  1940. }
  1941. }
  1942. else
  1943. {
  1944. $fullpathoffile=dol_buildpath($file, 0);
  1945. $content = file_get_contents($fullpathoffile);
  1946. // New module
  1947. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  1948. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  1949. print '<input type="hidden" name="action" value="savefile">';
  1950. print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
  1951. print '<input type="hidden" name="tab" value="'.$tab.'">';
  1952. print '<input type="hidden" name="module" value="'.$module.'">';
  1953. $doleditor=new DolEditor('editfilecontent', $content, '', '300', 'Full', 'In', true, false, 'ace', 0, '99%');
  1954. print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format','aZ09')?GETPOST('format','aZ09'):'html'));
  1955. print '<br>';
  1956. print '<center>';
  1957. print '<input type="submit" class="button buttonforacesave" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
  1958. print ' &nbsp; ';
  1959. print '<input type="submit" class="button" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
  1960. print '</center>';
  1961. print '</form>';
  1962. }
  1963. }
  1964. if ($tab == 'cron')
  1965. {
  1966. $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
  1967. $cronjobs = $moduleobj->cronjobs;
  1968. if ($action != 'editfile' || empty($file))
  1969. {
  1970. print $langs->trans("CronJobDefDesc", '<a href="'.DOL_URL_ROOT.'/cron/list.php?status=-2">'.$langs->transnoentities('CronList').'</a>').'<br>';
  1971. print '<br>';
  1972. print '<span class="fa fa-file-o"></span> '.$langs->trans("DescriptorFile").' : <strong>'.$pathtofile.'</strong>';
  1973. print ' <a href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&module='.$module.'&action=editfile&format=php&file='.urlencode($pathtofile).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
  1974. print '<br>';
  1975. print '<br>';
  1976. print load_fiche_titre($langs->trans("CronJobProfiles"), '', '');
  1977. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  1978. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  1979. print '<input type="hidden" name="action" value="addproperty">';
  1980. print '<input type="hidden" name="tab" value="objects">';
  1981. print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
  1982. print '<input type="hidden" name="tabobj" value="'.dol_escape_htmltag($tabobj).'">';
  1983. print '<div class="div-table-responsive">';
  1984. print '<table class="noborder">';
  1985. print '<tr class="liste_titre">';
  1986. print_liste_field_titre("CronLabel",$_SERVER["PHP_SELF"],"","",$param,'',$sortfield,$sortorder);
  1987. print_liste_field_titre("CronTask",'','',"",$param,'',$sortfield,$sortorder);
  1988. print_liste_field_titre("CronFrequency",'',"","",$param,'',$sortfield,$sortorder);
  1989. print_liste_field_titre("StatusAtInstall",$_SERVER["PHP_SELF"],"","",$param,'',$sortfield,$sortorder);
  1990. print_liste_field_titre("Comment",$_SERVER["PHP_SELF"],"","",$param,'',$sortfield,$sortorder);
  1991. print "</tr>\n";
  1992. if (count($cronjobs))
  1993. {
  1994. foreach ($cronjobs as $cron)
  1995. {
  1996. print '<tr class="oddeven">';
  1997. print '<td>';
  1998. print $cron['label'];
  1999. print '</td>';
  2000. print '<td>';
  2001. if ($cron['jobtype']=='method')
  2002. {
  2003. $text=$langs->trans("CronClass");
  2004. $texttoshow=$langs->trans('CronModule').': '.$module.'<br>';
  2005. $texttoshow.=$langs->trans('CronClass').': '. $cron['class'].'<br>';
  2006. $texttoshow.=$langs->trans('CronObject').': '. $cron['objectname'].'<br>';
  2007. $texttoshow.=$langs->trans('CronMethod').': '. $cron['method'];
  2008. $texttoshow.='<br>'.$langs->trans('CronArgs').': '. $cron['parameters'];
  2009. $texttoshow.='<br>'.$langs->trans('Comment').': '. $langs->trans($cron['comment']);
  2010. }
  2011. elseif ($cron['jobtype']=='command')
  2012. {
  2013. $text=$langs->trans('CronCommand');
  2014. $texttoshow=$langs->trans('CronCommand').': '.dol_trunc($cron['command']);
  2015. $texttoshow.='<br>'.$langs->trans('CronArgs').': '. $cron['parameters'];
  2016. $texttoshow.='<br>'.$langs->trans('Comment').': '. $langs->trans($cron['comment']);
  2017. }
  2018. print $form->textwithpicto($text, $texttoshow, 1);
  2019. print '</td>';
  2020. print '<td>';
  2021. if($cron['unitfrequency'] == "60") print $langs->trans('CronEach')." ".($cron['frequency'])." ".$langs->trans('Minutes');
  2022. if($cron['unitfrequency'] == "3600") print $langs->trans('CronEach')." ".($cron['frequency'])." ".$langs->trans('Hours');
  2023. if($cron['unitfrequency'] == "86400") print $langs->trans('CronEach')." ".($cron['frequency'])." ".$langs->trans('Days');
  2024. if($cron['unitfrequency'] == "604800") print $langs->trans('CronEach')." ".($cron['frequency'])." ".$langs->trans('Weeks');
  2025. print '</td>';
  2026. print '<td>';
  2027. print $cron['status'];
  2028. print '</td>';
  2029. print '<td>';
  2030. if (!empty($cron['comment'])) {print $cron['comment'];}
  2031. print '</td>';
  2032. print '</tr>';
  2033. }
  2034. }
  2035. else
  2036. {
  2037. print '<tr><td class="opacitymedium" colspan="5">'.$langs->trans("None").'</td></tr>';
  2038. }
  2039. print '</table>';
  2040. print '</div>';
  2041. print '</form>';
  2042. }
  2043. else
  2044. {
  2045. $fullpathoffile=dol_buildpath($file, 0);
  2046. $content = file_get_contents($fullpathoffile);
  2047. // New module
  2048. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  2049. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  2050. print '<input type="hidden" name="action" value="savefile">';
  2051. print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
  2052. print '<input type="hidden" name="tab" value="'.$tab.'">';
  2053. print '<input type="hidden" name="module" value="'.$module.'">';
  2054. $doleditor=new DolEditor('editfilecontent', $content, '', '300', 'Full', 'In', true, false, 'ace', 0, '99%');
  2055. print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format','aZ09')?GETPOST('format','aZ09'):'html'));
  2056. print '<br>';
  2057. print '<center>';
  2058. print '<input type="submit" class="button buttonforacesave" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
  2059. print ' &nbsp; ';
  2060. print '<input type="submit" class="button" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
  2061. print '</center>';
  2062. print '</form>';
  2063. }
  2064. }
  2065. if ($tab == 'buildpackage')
  2066. {
  2067. if (! class_exists('ZipArchive') && ! defined('ODTPHP_PATHTOPCLZIP'))
  2068. {
  2069. print img_warning().' '.$langs->trans("ErrNoZipEngine");
  2070. print '<br>';
  2071. }
  2072. $modulelowercase=strtolower($module);
  2073. // Zip file to build
  2074. $FILENAMEZIP='';
  2075. // Load module
  2076. $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
  2077. dol_include_once($pathtofile);
  2078. $class='mod'.$module;
  2079. if (class_exists($class))
  2080. {
  2081. try {
  2082. $moduleobj = new $class($db);
  2083. }
  2084. catch(Exception $e)
  2085. {
  2086. $error++;
  2087. dol_print_error($e->getMessage());
  2088. }
  2089. }
  2090. else
  2091. {
  2092. $error++;
  2093. $langs->load("errors");
  2094. dol_print_error($langs->trans("ErrorFailedToLoadModuleDescriptorForXXX", $module));
  2095. exit;
  2096. }
  2097. $arrayversion=explode('.',$moduleobj->version,3);
  2098. if (count($arrayversion))
  2099. {
  2100. $FILENAMEZIP="module_".$modulelowercase.'-'.$arrayversion[0].'.'.$arrayversion[1].($arrayversion[2]?".".$arrayversion[2]:"").".zip";
  2101. $outputfilezip = dol_buildpath($modulelowercase, 0).'/bin/'.$FILENAMEZIP;
  2102. $FILENAMEDOC=$modulelowercase.'.html';
  2103. $outputfiledoc = dol_buildpath($modulelowercase, 0).'/doc/'.$FILENAMEDOC;
  2104. $outputfiledocurl = dol_buildpath($modulelowercase, 1).'/doc/'.$FILENAMEDOC;
  2105. // TODO Use/test PDF
  2106. }
  2107. print '<br>';
  2108. print '<span class="fa fa-file-o"></span> '. $langs->trans("PathToModulePackage") . ' : ';
  2109. if (! dol_is_file($outputfilezip)) print '<strong>'.$langs->trans("FileNotYetGenerated").'</strong>';
  2110. else {
  2111. $relativepath = $modulelowercase.'/bin/'.$FILENAMEZIP;
  2112. print '<strong><a href="'.DOL_URL_ROOT.'/document.php?modulepart=packages&file='.urlencode($relativepath).'">'.$outputfilezip.'</a></strong>';
  2113. print ' ('.$langs->trans("GeneratedOn").' '.dol_print_date(dol_filemtime($outputfilezip), 'dayhour').')';
  2114. }
  2115. print '</strong><br>';
  2116. print '<br>';
  2117. print '<form name="generatepackage">';
  2118. print '<input type="hidden" name="action" value="generatepackage">';
  2119. print '<input type="hidden" name="tab" value="'.dol_escape_htmltag($tab).'">';
  2120. print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
  2121. print '<input type="submit" class="button" name="generatepackage" value="'.$langs->trans("BuildPackage").'">';
  2122. print '</form>';
  2123. print '<br><br><br>';
  2124. print '<span class="fa fa-file-o"></span> '. $langs->trans("PathToModuleDocumentation") . ' : ';
  2125. if (! dol_is_file($outputfiledoc)) print '<strong>'.$langs->trans("FileNotYetGenerated").'</strong>';
  2126. else {
  2127. print '<strong>';
  2128. print '<a href="'.$outputfiledocurl.'" target="_blank">';
  2129. print $outputfiledoc;
  2130. print '</a>';
  2131. print '</strong>';
  2132. print ' ('.$langs->trans("GeneratedOn").' '.dol_print_date(dol_filemtime($outputfiledoc), 'dayhour').')';
  2133. }
  2134. print '</strong><br>';
  2135. print '<br>';
  2136. print '<form name="generatedoc">';
  2137. print '<input type="hidden" name="action" value="generatedoc">';
  2138. print '<input type="hidden" name="tab" value="'.dol_escape_htmltag($tab).'">';
  2139. print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
  2140. print '<input type="submit" class="button" name="generatedoc" value="'.$langs->trans("BuildDocumentation").'">';
  2141. print '</form>';
  2142. }
  2143. if ($tab != 'description')
  2144. {
  2145. dol_fiche_end();
  2146. }
  2147. }
  2148. }
  2149. dol_fiche_end(); // End modules
  2150. // End of page
  2151. llxFooter();
  2152. $db->close();