index.php 161 KB

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