index.php 203 KB

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