index.php 204 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440
  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. $moduletype = $listofmodules[strtolower($module)]['moduletype'];
  1335. // Edit the class file to write properties
  1336. if (!$error) {
  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. $result = rebuildObjectSql($destdir, $module, $objectname, $newmask, $srcdir, $object, $moduletype);
  1345. if ($result <= 0) {
  1346. $error++;
  1347. }
  1348. }
  1349. if (!$error) {
  1350. clearstatcache(true);
  1351. setEventMessages($langs->trans('FilesForObjectUpdated', $objectname), null);
  1352. setEventMessages($langs->trans('WarningDatabaseIsNotUpdated'), null);
  1353. // Make a redirect to reload all data
  1354. header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=objects&module='.$module.($forceddirread ? '@'.$dirread : '').'&tabobj='.$objectname.'&nocache='.time());
  1355. exit;
  1356. }
  1357. }
  1358. if ($dirins && $action == 'confirm_deleteproperty' && $propertykey) {
  1359. $objectname = $tabobj;
  1360. $dirins = $dirread = $listofmodules[strtolower($module)]['moduledescriptorrootpath'];
  1361. $moduletype = $listofmodules[strtolower($module)]['moduletype'];
  1362. $srcdir = $dirread.'/'.strtolower($module);
  1363. $destdir = $dirins.'/'.strtolower($module);
  1364. dol_mkdir($destdir);
  1365. // Edit the class file to write properties
  1366. if (!$error) {
  1367. $object = rebuildObjectClass($destdir, $module, $objectname, $newmask, $srcdir, array(), $propertykey);
  1368. if (is_numeric($object) && $object <= 0) {
  1369. $error++;
  1370. }
  1371. }
  1372. // Edit sql with new properties
  1373. if (!$error) {
  1374. $result = rebuildObjectSql($destdir, $module, $objectname, $newmask, $srcdir, $object);
  1375. if ($result <= 0) {
  1376. $error++;
  1377. }
  1378. }
  1379. if (!$error) {
  1380. setEventMessages($langs->trans('FilesForObjectUpdated', $objectname), null);
  1381. clearstatcache(true);
  1382. // Make a redirect to reload all data
  1383. header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=objects&module='.$module.($forceddirread ? '@'.$dirread : '').'&tabobj='.$objectname);
  1384. exit;
  1385. }
  1386. }
  1387. if ($dirins && $action == 'confirm_deletemodule') {
  1388. if (preg_match('/[^a-z0-9_]/i', $module)) {
  1389. $error++;
  1390. setEventMessages($langs->trans("SpaceOrSpecialCharAreNotAllowed"), null, 'errors');
  1391. }
  1392. if (!$error) {
  1393. $modulelowercase = strtolower($module);
  1394. // Dir for module
  1395. $dir = $dirins.'/'.$modulelowercase;
  1396. $result = dol_delete_dir_recursive($dir);
  1397. if ($result > 0) {
  1398. setEventMessages($langs->trans("DirWasRemoved", $modulelowercase), null);
  1399. clearstatcache(true);
  1400. if (function_exists('opcache_invalidate')) {
  1401. opcache_reset(); // remove the include cache hell !
  1402. }
  1403. header("Location: ".$_SERVER["PHP_SELF"].'?module=deletemodule');
  1404. exit;
  1405. } else {
  1406. setEventMessages($langs->trans("PurgeNothingToDelete"), null, 'warnings');
  1407. }
  1408. }
  1409. $action = '';
  1410. $module = 'deletemodule';
  1411. }
  1412. if ($dirins && $action == 'confirm_deleteobject' && $objectname) {
  1413. if (preg_match('/[^a-z0-9_]/i', $objectname)) {
  1414. $error++;
  1415. setEventMessages($langs->trans("SpaceOrSpecialCharAreNotAllowed"), null, 'errors');
  1416. }
  1417. if (!$error) {
  1418. $modulelowercase = strtolower($module);
  1419. $objectlowercase = strtolower($objectname);
  1420. // Dir for module
  1421. $dir = $dirins.'/'.$modulelowercase;
  1422. // Delete some files
  1423. $filetodelete = array(
  1424. 'myobject_card.php'=>strtolower($objectname).'_card.php',
  1425. 'myobject_note.php'=>strtolower($objectname).'_note.php',
  1426. 'myobject_contact.php'=>strtolower($objectname).'_contact.php',
  1427. 'myobject_document.php'=>strtolower($objectname).'_document.php',
  1428. 'myobject_agenda.php'=>strtolower($objectname).'_agenda.php',
  1429. 'myobject_list.php'=>strtolower($objectname).'_list.php',
  1430. 'admin/myobject_extrafields.php'=>'admin/'.strtolower($objectname).'_extrafields.php',
  1431. 'lib/mymodule_myobject.lib.php'=>'lib/'.strtolower($module).'_'.strtolower($objectname).'.lib.php',
  1432. 'test/phpunit/MyObjectTest.php'=>'test/phpunit/'.strtolower($objectname).'Test.php',
  1433. 'sql/llx_mymodule_myobject.sql'=>'sql/llx_'.strtolower($module).'_'.strtolower($objectname).'.sql',
  1434. 'sql/llx_mymodule_myobject_extrafields.sql'=>'sql/llx_'.strtolower($module).'_'.strtolower($objectname).'_extrafields.sql',
  1435. 'sql/llx_mymodule_myobject.key.sql'=>'sql/llx_'.strtolower($module).'_'.strtolower($objectname).'.key.sql',
  1436. 'sql/llx_mymodule_myobject_extrafields.key.sql'=>'sql/llx_'.strtolower($module).'_'.strtolower($objectname).'_extrafields.key.sql',
  1437. 'scripts/myobject.php'=>'scripts/'.strtolower($objectname).'.php',
  1438. 'img/object_myobject.png'=>'img/object_'.strtolower($objectname).'.png',
  1439. 'class/myobject.class.php'=>'class/'.strtolower($objectname).'.class.php',
  1440. 'class/api_myobject.class.php'=>'class/api_'.strtolower($module).'.class.php',
  1441. 'core/modules/mymodule/mod_myobject_advanced.php'=>'core/modules/'.strtolower($module).'/mod_'.strtolower($objectname).'_advanced.php',
  1442. 'core/modules/mymodule/mod_myobject_standard.php'=>'core/modules/'.strtolower($module).'/mod_'.strtolower($objectname).'_standard.php',
  1443. 'core/modules/mymodule/modules_myobject.php'=>'core/modules/'.strtolower($module).'/modules_'.strtolower($objectname).'.php',
  1444. 'core/modules/mymodule/doc/doc_generic_myobject_odt.modules.php'=>'core/modules/'.strtolower($module).'/doc/doc_generic_'.strtolower($objectname).'_odt.modules.php',
  1445. 'core/modules/mymodule/doc/pdf_standard_myobject.modules.php'=>'core/modules/'.strtolower($module).'/doc/pdf_standard_'.strtolower($objectname).'.modules.php'
  1446. );
  1447. $resultko = 0;
  1448. foreach ($filetodelete as $filetodelete) {
  1449. $resulttmp = dol_delete_file($dir.'/'.$filetodelete, 0, 0, 1);
  1450. $resulttmp = dol_delete_file($dir.'/'.$filetodelete.'.back', 0, 0, 1);
  1451. if (!$resulttmp) {
  1452. $resultko++;
  1453. }
  1454. }
  1455. if ($resultko == 0) {
  1456. setEventMessages($langs->trans("FilesDeleted"), null);
  1457. } else {
  1458. setEventMessages($langs->trans("ErrorSomeFilesCouldNotBeDeleted"), null, 'warnings');
  1459. }
  1460. }
  1461. $action = '';
  1462. $tabobj = 'deleteobject';
  1463. }
  1464. if ($dirins && $action == 'generatedoc') {
  1465. $modulelowercase = strtolower($module);
  1466. // Dir for module
  1467. $dirofmodule = dol_buildpath($modulelowercase, 0).'/doc';
  1468. $FILENAMEDOC = strtolower($module).'.html';
  1469. $util = new Utils($db);
  1470. $result = $util->generateDoc($module);
  1471. if ($result > 0) {
  1472. setEventMessages($langs->trans("DocFileGeneratedInto", $dirofmodule), null);
  1473. } else {
  1474. setEventMessages($util->error, $util->errors, 'errors');
  1475. }
  1476. }
  1477. if ($dirins && $action == 'generatepackage') {
  1478. $modulelowercase = strtolower($module);
  1479. $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
  1480. // Dir for module
  1481. $dir = dol_buildpath($modulelowercase, 0);
  1482. // Zip file to build
  1483. $FILENAMEZIP = '';
  1484. // Load module
  1485. dol_include_once($pathtofile);
  1486. $class = 'mod'.$module;
  1487. if (class_exists($class)) {
  1488. try {
  1489. $moduleobj = new $class($db);
  1490. } catch (Exception $e) {
  1491. $error++;
  1492. dol_print_error($db, $e->getMessage());
  1493. }
  1494. } else {
  1495. $error++;
  1496. $langs->load("errors");
  1497. dol_print_error($db, $langs->trans("ErrorFailedToLoadModuleDescriptorForXXX", $module));
  1498. exit;
  1499. }
  1500. $arrayversion = explode('.', $moduleobj->version, 3);
  1501. if (count($arrayversion)) {
  1502. $FILENAMEZIP = "module_".$modulelowercase.'-'.$arrayversion[0].(empty($arrayversion[1]) ? '.0' : '.'.$arrayversion[1]).($arrayversion[2] ? '.'.$arrayversion[2] : '').'.zip';
  1503. $dirofmodule = dol_buildpath($modulelowercase, 0).'/bin';
  1504. $outputfilezip = $dirofmodule.'/'.$FILENAMEZIP;
  1505. if ($dirofmodule) {
  1506. if (!dol_is_dir($dirofmodule)) {
  1507. dol_mkdir($dirofmodule);
  1508. }
  1509. // Note: We exclude /bin/ to not include the already generated zip
  1510. $result = dol_compress_dir($dir, $outputfilezip, 'zip', '/\/bin\//', $modulelowercase);
  1511. } else {
  1512. $result = -1;
  1513. }
  1514. if ($result > 0) {
  1515. setEventMessages($langs->trans("ZipFileGeneratedInto", $outputfilezip), null);
  1516. } else {
  1517. $error++;
  1518. $langs->load("errors");
  1519. setEventMessages($langs->trans("ErrorFailToGenerateFile", $outputfilezip), null, 'errors');
  1520. }
  1521. } else {
  1522. $error++;
  1523. $langs->load("errors");
  1524. setEventMessages($langs->trans("ErrorCheckVersionIsDefined"), null, 'errors');
  1525. }
  1526. }
  1527. // Save file
  1528. if ($action == 'savefile' && empty($cancel)) {
  1529. $relofcustom = basename($dirins);
  1530. if ($relofcustom) {
  1531. // Check that relative path ($file) start with name 'custom'
  1532. if (!preg_match('/^'.$relofcustom.'/', $file)) {
  1533. $file = $relofcustom.'/'.$file;
  1534. }
  1535. $pathoffile = dol_buildpath($file, 0);
  1536. $pathoffilebackup = dol_buildpath($file.'.back', 0);
  1537. // Save old version
  1538. if (dol_is_file($pathoffile)) {
  1539. dol_copy($pathoffile, $pathoffilebackup, 0, 1);
  1540. }
  1541. $check = 'restricthtml';
  1542. $srclang = dol_mimetype($pathoffile, '', 3);
  1543. if ($srclang == 'md') {
  1544. $check = 'restricthtml';
  1545. }
  1546. if ($srclang == 'lang') {
  1547. $check = 'restricthtml';
  1548. }
  1549. if ($srclang == 'php') {
  1550. $check = 'none';
  1551. }
  1552. $content = GETPOST('editfilecontent', $check);
  1553. // Save file on disk
  1554. if ($content) {
  1555. dol_delete_file($pathoffile);
  1556. $result = file_put_contents($pathoffile, $content);
  1557. if ($result) {
  1558. @chmod($pathoffile, octdec($newmask));
  1559. setEventMessages($langs->trans("FileSaved"), null);
  1560. } else {
  1561. setEventMessages($langs->trans("ErrorFailedToSaveFile"), null, 'errors');
  1562. }
  1563. } else {
  1564. setEventMessages($langs->trans("ContentCantBeEmpty"), null, 'errors');
  1565. //$action='editfile';
  1566. $error++;
  1567. }
  1568. }
  1569. }
  1570. // Enable module
  1571. if ($action == 'set' && $user->admin) {
  1572. $param = '';
  1573. if ($module) {
  1574. $param .= '&module='.urlencode($module);
  1575. }
  1576. if ($tab) {
  1577. $param .= '&tab='.urlencode($tab);
  1578. }
  1579. if ($tabobj) {
  1580. $param .= '&tabobj='.urlencode($tabobj);
  1581. }
  1582. $value = GETPOST('value', 'alpha');
  1583. $resarray = activateModule($value);
  1584. if (!empty($resarray['errors'])) {
  1585. setEventMessages('', $resarray['errors'], 'errors');
  1586. } else {
  1587. //var_dump($resarray);exit;
  1588. if ($resarray['nbperms'] > 0) {
  1589. $tmpsql = "SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX."user WHERE admin <> 1";
  1590. $resqltmp = $db->query($tmpsql);
  1591. if ($resqltmp) {
  1592. $obj = $db->fetch_object($resqltmp);
  1593. //var_dump($obj->nb);exit;
  1594. if ($obj && $obj->nb > 1) {
  1595. $msg = $langs->trans('ModuleEnabledAdminMustCheckRights');
  1596. setEventMessages($msg, null, 'warnings');
  1597. }
  1598. } else {
  1599. dol_print_error($db);
  1600. }
  1601. }
  1602. }
  1603. header("Location: ".$_SERVER["PHP_SELF"]."?".$param);
  1604. exit;
  1605. }
  1606. // Disable module
  1607. if ($action == 'reset' && $user->admin) {
  1608. $param = '';
  1609. if ($module) {
  1610. $param .= '&module='.urlencode($module);
  1611. }
  1612. if ($tab) {
  1613. $param .= '&tab='.urlencode($tab);
  1614. }
  1615. if ($tabobj) {
  1616. $param .= '&tabobj='.urlencode($tabobj);
  1617. }
  1618. $value = GETPOST('value', 'alpha');
  1619. $result = unActivateModule($value);
  1620. if ($result) {
  1621. setEventMessages($result, null, 'errors');
  1622. }
  1623. header("Location: ".$_SERVER["PHP_SELF"]."?".$param);
  1624. exit;
  1625. }
  1626. /*
  1627. * View
  1628. */
  1629. $form = new Form($db);
  1630. $formadmin = new FormAdmin($db);
  1631. // Set dir where external modules are installed
  1632. if (!dol_is_dir($dirins)) {
  1633. dol_mkdir($dirins);
  1634. }
  1635. $dirins_ok = (dol_is_dir($dirins));
  1636. $help_url = '';
  1637. $morejs = array(
  1638. '/includes/ace/src/ace.js',
  1639. '/includes/ace/src/ext-statusbar.js',
  1640. '/includes/ace/src/ext-language_tools.js',
  1641. //'/includes/ace/src/ext-chromevox.js'
  1642. );
  1643. $morecss = array();
  1644. llxHeader('', $langs->trans("ModuleBuilder"), $help_url, '', 0, 0, $morejs, $morecss, '', 'classforhorizontalscrolloftabs');
  1645. $text = $langs->trans("ModuleBuilder");
  1646. print load_fiche_titre($text, '', 'title_setup');
  1647. print '<span class="opacitymedium hideonsmartphone">'.$langs->trans("ModuleBuilderDesc", 'https://wiki.dolibarr.org/index.php/Module_development#Create_your_module').'</span>';
  1648. print '<br class="hideonsmartphone">';
  1649. //print $textforlistofdirs;
  1650. //print '<br>';
  1651. //var_dump($listofmodules);
  1652. $message = '';
  1653. if (!$dirins) {
  1654. $message = info_admin($langs->trans("ConfFileMustContainCustom", DOL_DOCUMENT_ROOT.'/custom', DOL_DOCUMENT_ROOT));
  1655. $allowfromweb = -1;
  1656. } else {
  1657. if ($dirins_ok) {
  1658. if (!is_writable(dol_osencode($dirins))) {
  1659. $langs->load("errors");
  1660. $message = info_admin($langs->trans("ErrorFailedToWriteInDir", $dirins));
  1661. $allowfromweb = 0;
  1662. }
  1663. } else {
  1664. $message = info_admin($langs->trans("NotExistsDirect", $dirins).$langs->trans("InfDirAlt").$langs->trans("InfDirExample"));
  1665. $allowfromweb = 0;
  1666. }
  1667. }
  1668. if ($message) {
  1669. print $message;
  1670. }
  1671. //print $langs->trans("ModuleBuilderDesc3", count($listofmodules), $FILEFLAG).'<br>';
  1672. $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>';
  1673. // Load module descriptor
  1674. $error = 0;
  1675. $moduleobj = null;
  1676. if (!empty($module) && $module != 'initmodule' && $module != 'deletemodule') {
  1677. $modulelowercase = strtolower($module);
  1678. $loadclasserrormessage = '';
  1679. // Load module
  1680. try {
  1681. $fullpathdirtodescriptor = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
  1682. //throw(new Exception());
  1683. dol_include_once($fullpathdirtodescriptor);
  1684. $class = 'mod'.$module;
  1685. } catch (Throwable $e) { // This is called in PHP 7 only. Never called with PHP 5.6
  1686. $loadclasserrormessage = $e->getMessage()."<br>\n";
  1687. $loadclasserrormessage .= 'File: '.$e->getFile()."<br>\n";
  1688. $loadclasserrormessage .= 'Line: '.$e->getLine()."<br>\n";
  1689. } catch (Exception $e) {
  1690. $loadclasserrormessage = $e->getMessage()."<br>\n";
  1691. $loadclasserrormessage .= 'File: '.$e->getFile()."<br>\n";
  1692. $loadclasserrormessage .= 'Line: '.$e->getLine()."<br>\n";
  1693. }
  1694. if (class_exists($class)) {
  1695. try {
  1696. $moduleobj = new $class($db);
  1697. } catch (Exception $e) {
  1698. $error++;
  1699. print $e->getMessage();
  1700. }
  1701. } else {
  1702. if (empty($forceddirread)) {
  1703. $error++;
  1704. }
  1705. $langs->load("errors");
  1706. print '<!-- ErrorFailedToLoadModuleDescriptorForXXX -->';
  1707. print img_warning('').' '.$langs->trans("ErrorFailedToLoadModuleDescriptorForXXX", $module).'<br>';
  1708. print $loadclasserrormessage;
  1709. }
  1710. }
  1711. print '<br>';
  1712. // Tabs for all modules
  1713. $head = array();
  1714. $h = 0;
  1715. $head[$h][0] = $_SERVER["PHP_SELF"].'?module=initmodule';
  1716. $head[$h][1] = '<span class="valignmiddle text-plus-circle">'.$langs->trans("NewModule").'</span><span class="fa fa-plus-circle valignmiddle paddingleft"></span>';
  1717. $head[$h][2] = 'initmodule';
  1718. $h++;
  1719. $linktoenabledisable = '';
  1720. if (is_array($listofmodules) && count($listofmodules) > 0) {
  1721. // Define $linktoenabledisable
  1722. $modulelowercase = strtolower($module);
  1723. $const_name = 'MAIN_MODULE_'.strtoupper($module);
  1724. $param = '';
  1725. if ($tab) {
  1726. $param .= '&tab='.urlencode($tab);
  1727. }
  1728. if ($module) {
  1729. $param .= '&module='.urlencode($module);
  1730. }
  1731. if ($tabobj) {
  1732. $param .= '&tabobj='.urlencode($tabobj);
  1733. }
  1734. $urltomodulesetup = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?search_keyword='.urlencode($module).'">'.$langs->trans('Home').'-'.$langs->trans("Setup").'-'.$langs->trans("Modules").'</a>';
  1735. if (!empty($conf->global->$const_name)) { // If module is already activated
  1736. $linktoenabledisable .= '<a class="reposition asetresetmodule valignmiddle" href="'.$_SERVER["PHP_SELF"].'?id='.$moduleobj->numero.'&action=reset&value=mod'.$module.$param.'">';
  1737. $linktoenabledisable .= img_picto($langs->trans("Activated"), 'switch_on', '', false, 0, 0, '', '', 1);
  1738. $linktoenabledisable .= '</a>';
  1739. $linktoenabledisable .= $form->textwithpicto('', $langs->trans("Warning").' : '.$langs->trans("ModuleIsLive"), -1, 'warning');
  1740. $objMod = $moduleobj;
  1741. $backtourlparam = '';
  1742. $backtourlparam .= ($backtourlparam ? '&' : '?').'module='.$module; // No urlencode here, done later
  1743. if ($tab) {
  1744. $backtourlparam .= ($backtourlparam ? '&' : '?').'tab='.$tab; // No urlencode here, done later
  1745. }
  1746. $backtourl = $_SERVER["PHP_SELF"].$backtourlparam;
  1747. $regs = array();
  1748. if (is_array($objMod->config_page_url)) {
  1749. $i = 0;
  1750. foreach ($objMod->config_page_url as $page) {
  1751. $urlpage = $page;
  1752. if ($i++) {
  1753. $linktoenabledisable .= ' <a href="'.$urlpage.'" title="'.$langs->trans($page).'">'.img_picto(ucfirst($page), "setup").'</a>';
  1754. // print '<a href="'.$page.'">'.ucfirst($page).'</a>&nbsp;';
  1755. } else {
  1756. if (preg_match('/^([^@]+)@([^@]+)$/i', $urlpage, $regs)) {
  1757. $urltouse = dol_buildpath('/'.$regs[2].'/admin/'.$regs[1], 1);
  1758. $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>';
  1759. } else {
  1760. // Case standard admin page (not a page provided by the
  1761. // module but a page provided by dolibarr)
  1762. $urltouse = DOL_URL_ROOT.'/admin/'.$urlpage;
  1763. $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>';
  1764. }
  1765. }
  1766. }
  1767. } elseif (preg_match('/^([^@]+)@([^@]+)$/i', $objMod->config_page_url, $regs)) {
  1768. $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>';
  1769. }
  1770. } else {
  1771. if (!empty($moduleobj)) {
  1772. $linktoenabledisable .= '<a class="reposition asetresetmodule valignmiddle" href="'.$_SERVER["PHP_SELF"].'?id='.$moduleobj->numero.'&action=set&token='.newToken().'&value=mod'.$module.$param.'">';
  1773. $linktoenabledisable .= img_picto($langs->trans("ModuleIsNotActive", $urltomodulesetup), 'switch_off', 'style="padding-right: 8px"', false, 0, 0, '', 'classfortooltip', 1);
  1774. $linktoenabledisable .= "</a>\n";
  1775. }
  1776. }
  1777. // Loop to show tab of each module
  1778. foreach ($listofmodules as $tmpmodule => $tmpmodulearray) {
  1779. $head[$h][0] = $_SERVER["PHP_SELF"].'?module='.$tmpmodulearray['modulenamewithcase'].($forceddirread ? '@'.$dirread : '');
  1780. $head[$h][1] = $tmpmodulearray['modulenamewithcase'];
  1781. $head[$h][2] = $tmpmodulearray['modulenamewithcase'];
  1782. if ($tmpmodulearray['modulenamewithcase'] == $module) {
  1783. $head[$h][4] = '<span class="inline-block">'.$linktoenabledisable.'</span>';
  1784. }
  1785. $h++;
  1786. }
  1787. }
  1788. $head[$h][0] = $_SERVER["PHP_SELF"].'?module=deletemodule';
  1789. $head[$h][1] = $langs->trans("DangerZone");
  1790. $head[$h][2] = 'deletemodule';
  1791. $h++;
  1792. print dol_get_fiche_head($head, $module, '', -1, '', 0, $infomodulesfound, '', 8); // Modules
  1793. if ($module == 'initmodule') {
  1794. // New module
  1795. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  1796. print '<input type="hidden" name="token" value="'.newToken().'">';
  1797. print '<input type="hidden" name="action" value="initmodule">';
  1798. print '<input type="hidden" name="module" value="initmodule">';
  1799. //print '<span class="opacitymedium">'.$langs->trans("ModuleBuilderDesc2", 'conf/conf.php', $newdircustom).'</span><br>';
  1800. print $langs->trans("EnterNameOfModuleDesc").'<br>';
  1801. print '<br>';
  1802. print '<input type="text" name="modulename" value="'.dol_escape_htmltag($modulename).'" placeholder="'.dol_escape_htmltag($langs->trans("ModuleKey")).'"><br>';
  1803. print '<br><input type="submit" class="button" name="create" value="'.dol_escape_htmltag($langs->trans("Create")).'"'.($dirins ? '' : ' disabled="disabled"').'>';
  1804. print '</form>';
  1805. } elseif ($module == 'deletemodule') {
  1806. print '<!-- Form to init a module -->'."\n";
  1807. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST" name="delete">';
  1808. print '<input type="hidden" name="token" value="'.newToken().'">';
  1809. print '<input type="hidden" name="action" value="confirm_deletemodule">';
  1810. print '<input type="hidden" name="module" value="deletemodule">';
  1811. print $langs->trans("EnterNameOfModuleToDeleteDesc").'<br><br>';
  1812. print '<input type="text" name="module" placeholder="'.dol_escape_htmltag($langs->trans("ModuleKey")).'" value="">';
  1813. print '<input type="submit" class="button smallpaddingimp" value="'.$langs->trans("Delete").'"'.($dirins ? '' : ' disabled="disabled"').'>';
  1814. print '</form>';
  1815. } elseif (!empty($module)) {
  1816. // Tabs for module
  1817. if (!$error) {
  1818. $dirread = $listofmodules[strtolower($module)]['moduledescriptorrootpath'];
  1819. $head2 = array();
  1820. $h = 0;
  1821. $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=description&module='.$module.($forceddirread ? '@'.$dirread : '');
  1822. $head2[$h][1] = $langs->trans("Description");
  1823. $head2[$h][2] = 'description';
  1824. $h++;
  1825. $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=objects&module='.$module.($forceddirread ? '@'.$dirread : '');
  1826. $head2[$h][1] = $langs->trans("Objects");
  1827. $head2[$h][2] = 'objects';
  1828. $h++;
  1829. $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=languages&module='.$module.($forceddirread ? '@'.$dirread : '');
  1830. $head2[$h][1] = $langs->trans("Languages");
  1831. $head2[$h][2] = 'languages';
  1832. $h++;
  1833. $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=dictionaries&module='.$module.($forceddirread ? '@'.$dirread : '');
  1834. $head2[$h][1] = $langs->trans("Dictionaries");
  1835. $head2[$h][2] = 'dictionaries';
  1836. $h++;
  1837. $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=permissions&module='.$module.($forceddirread ? '@'.$dirread : '');
  1838. $head2[$h][1] = $langs->trans("Permissions");
  1839. $head2[$h][2] = 'permissions';
  1840. $h++;
  1841. $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=tabs&module='.$module.($forceddirread ? '@'.$dirread : '');
  1842. $head2[$h][1] = $langs->trans("Tabs");
  1843. $head2[$h][2] = 'tabs';
  1844. $h++;
  1845. $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=menus&module='.$module.($forceddirread ? '@'.$dirread : '');
  1846. $head2[$h][1] = $langs->trans("Menus");
  1847. $head2[$h][2] = 'menus';
  1848. $h++;
  1849. $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=hooks&module='.$module.($forceddirread ? '@'.$dirread : '');
  1850. $head2[$h][1] = $langs->trans("Hooks");
  1851. $head2[$h][2] = 'hooks';
  1852. $h++;
  1853. $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=triggers&module='.$module.($forceddirread ? '@'.$dirread : '');
  1854. $head2[$h][1] = $langs->trans("Triggers");
  1855. $head2[$h][2] = 'triggers';
  1856. $h++;
  1857. $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=widgets&module='.$module.($forceddirread ? '@'.$dirread : '');
  1858. $head2[$h][1] = $langs->trans("Widgets");
  1859. $head2[$h][2] = 'widgets';
  1860. $h++;
  1861. $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=exportimport&module='.$module.($forceddirread ? '@'.$dirread : '');
  1862. $head2[$h][1] = $langs->trans("Export").'-'.$langs->trans("Import");
  1863. $head2[$h][2] = 'exportimport';
  1864. $h++;
  1865. $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=css&module='.$module.($forceddirread ? '@'.$dirread : '');
  1866. $head2[$h][1] = $langs->trans("CSS");
  1867. $head2[$h][2] = 'css';
  1868. $h++;
  1869. $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=js&module='.$module.($forceddirread ? '@'.$dirread : '');
  1870. $head2[$h][1] = $langs->trans("JS");
  1871. $head2[$h][2] = 'js';
  1872. $h++;
  1873. $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=cli&module='.$module.($forceddirread ? '@'.$dirread : '');
  1874. $head2[$h][1] = $langs->trans("CLI");
  1875. $head2[$h][2] = 'cli';
  1876. $h++;
  1877. $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=cron&module='.$module.($forceddirread ? '@'.$dirread : '');
  1878. $head2[$h][1] = $langs->trans("CronList");
  1879. $head2[$h][2] = 'cron';
  1880. $h++;
  1881. $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=specifications&module='.$module.($forceddirread ? '@'.$dirread : '');
  1882. $head2[$h][1] = $langs->trans("Documentation");
  1883. $head2[$h][2] = 'specifications';
  1884. $h++;
  1885. $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=buildpackage&module='.$module.($forceddirread ? '@'.$dirread : '');
  1886. $head2[$h][1] = $langs->trans("BuildPackage");
  1887. $head2[$h][2] = 'buildpackage';
  1888. $h++;
  1889. print '<!-- Section for a given module -->';
  1890. // Note module is inside $dirread
  1891. if ($tab == 'description') {
  1892. print '<!-- tab=description -->'."\n";
  1893. $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
  1894. $pathtofilereadme = $modulelowercase.'/README.md';
  1895. $pathtochangelog = $modulelowercase.'/ChangeLog.md';
  1896. if ($action != 'editfile' || empty($file)) {
  1897. print dol_get_fiche_head($head2, $tab, '', -1, '', 0, '', '', 0, 'formodulesuffix'); // Description - level 2
  1898. print '<span class="opacitymedium">'.$langs->trans("ModuleBuilderDesc".$tab).'</span>';
  1899. $infoonmodulepath = '';
  1900. if (realpath($dirread.'/'.$modulelowercase) != $dirread.'/'.$modulelowercase) {
  1901. $infoonmodulepath = '<span class="opacitymedium">'.$langs->trans("RealPathOfModule").' :</span> <strong class="wordbreak">'.realpath($dirread.'/'.$modulelowercase).'</strong><br>';
  1902. print ' '.$infoonmodulepath;
  1903. }
  1904. print '<br>';
  1905. print '<table>';
  1906. print '<tr><td>';
  1907. print '<span class="fa fa-file-o"></span> '.$langs->trans("DescriptorFile").' : <strong class="wordbreak">'.$pathtofile.'</strong>';
  1908. 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>';
  1909. print '</td></tr>';
  1910. print '<tr><td><span class="fa fa-file-o"></span> '.$langs->trans("ReadmeFile").' : <strong class="wordbreak">'.$pathtofilereadme.'</strong>';
  1911. 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>';
  1912. print '</td></tr>';
  1913. print '<tr><td><span class="fa fa-file-o"></span> '.$langs->trans("ChangeLog").' : <strong class="wordbreak">'.$pathtochangelog.'</strong>';
  1914. 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>';
  1915. print '</td></tr>';
  1916. print '</table>';
  1917. print '<br>';
  1918. print load_fiche_titre($langs->trans("DescriptorFile"), '', '');
  1919. if (!empty($moduleobj)) {
  1920. print '<div class="underbanner clearboth"></div>';
  1921. print '<div class="fichecenter">';
  1922. print '<table class="border centpercent">';
  1923. print '<tr class="liste_titre"><td class="titlefield">';
  1924. print $langs->trans("Parameter");
  1925. print '</td><td>';
  1926. print $langs->trans("Value");
  1927. print '</td></tr>';
  1928. print '<tr><td>';
  1929. print $langs->trans("Numero");
  1930. print '</td><td>';
  1931. print $moduleobj->numero;
  1932. 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>';
  1933. print ' - <a href="https://wiki.dolibarr.org/index.php/List_of_modules_id" target="_blank" rel="noopener noreferrer external">'.$langs->trans("SeeReservedIDsRangeHere").'</a>)';
  1934. print '</td></tr>';
  1935. print '<tr><td>';
  1936. print $langs->trans("Name");
  1937. print '</td><td>';
  1938. print $moduleobj->getName();
  1939. print '</td></tr>';
  1940. print '<tr><td>';
  1941. print $langs->trans("Version");
  1942. print '</td><td>';
  1943. print $moduleobj->getVersion();
  1944. print '</td></tr>';
  1945. print '<tr><td>';
  1946. print $langs->trans("Family");
  1947. //print "<br>'crm','financial','hr','projects','products','ecm','technic','interface','other'";
  1948. print '</td><td>';
  1949. print $moduleobj->family;
  1950. print '</td></tr>';
  1951. print '<tr><td>';
  1952. print $langs->trans("EditorName");
  1953. print '</td><td>';
  1954. print $moduleobj->editor_name;
  1955. print '</td></tr>';
  1956. print '<tr><td>';
  1957. print $langs->trans("EditorUrl");
  1958. print '</td><td>';
  1959. if (!empty($moduleobj->editor_url)) {
  1960. print '<a href="'.$moduleobj->editor_url.'" class="_blank" rel="noopener">'.$moduleobj->editor_url.' '.img_picto('', 'globe').'</a>';
  1961. }
  1962. print '</td></tr>';
  1963. print '<tr><td>';
  1964. print $langs->trans("Picto");
  1965. print '</td><td>';
  1966. print $moduleobj->picto;
  1967. print ' &nbsp; '.img_picto('', $moduleobj->picto, 'class="valignmiddle pictomodule paddingrightonly"');
  1968. print '</td></tr>';
  1969. print '<tr><td>';
  1970. print $langs->trans("Description");
  1971. print '</td><td>';
  1972. print $moduleobj->getDesc();
  1973. print '</td></tr>';
  1974. print '</table>';
  1975. } else {
  1976. print $langs->trans("ErrorFailedToLoadModuleDescriptorForXXX", $module).'<br>';
  1977. }
  1978. if (!empty($moduleobj)) {
  1979. print '<br><br>';
  1980. // Readme file
  1981. print load_fiche_titre($langs->trans("ReadmeFile"), '', '');
  1982. print '<!-- readme file -->';
  1983. if (dol_is_file($dirread.'/'.$pathtofilereadme)) {
  1984. print '<div class="underbanner clearboth"></div><div class="fichecenter">'.$moduleobj->getDescLong().'</div>';
  1985. } else {
  1986. print '<span class="opacitymedium">'.$langs->trans("ErrorFileNotFound", $pathtofilereadme).'</span>';
  1987. }
  1988. print '<br><br>';
  1989. // ChangeLog
  1990. print load_fiche_titre($langs->trans("ChangeLog"), '', '');
  1991. print '<!-- changelog file -->';
  1992. if (dol_is_file($dirread.'/'.$pathtochangelog)) {
  1993. print '<div class="underbanner clearboth"></div><div class="fichecenter">'.$moduleobj->getChangeLog().'</div>';
  1994. } else {
  1995. print '<span class="opacitymedium">'.$langs->trans("ErrorFileNotFound", $pathtochangelog).'</span>';
  1996. }
  1997. }
  1998. print dol_get_fiche_end();
  1999. } else { // Edit text file
  2000. $fullpathoffile = dol_buildpath($file, 0, 1); // Description - level 2
  2001. if ($fullpathoffile) {
  2002. $content = file_get_contents($fullpathoffile);
  2003. }
  2004. // New module
  2005. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  2006. print '<input type="hidden" name="token" value="'.newToken().'">';
  2007. print '<input type="hidden" name="action" value="savefile">';
  2008. print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
  2009. print '<input type="hidden" name="tab" value="'.$tab.'">';
  2010. print '<input type="hidden" name="module" value="'.$module.'">';
  2011. print dol_get_fiche_head($head2, $tab, '', -1, '', 0, '', '', 0, 'formodulesuffix');
  2012. $doleditor = new DolEditor('editfilecontent', $content, '', '300', 'Full', 'In', true, false, 'ace', 0, '99%', '');
  2013. print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ?GETPOST('format', 'aZ09') : 'html'));
  2014. print dol_get_fiche_end();
  2015. print '<center>';
  2016. print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
  2017. print ' &nbsp; ';
  2018. print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
  2019. print '</center>';
  2020. print '</form>';
  2021. }
  2022. } else {
  2023. print dol_get_fiche_head($head2, $tab, '', -1, '', 0, '', '', 0, 'formodulesuffix'); // Level 2
  2024. }
  2025. if ($tab == 'languages') {
  2026. print '<!-- tab=languages -->'."\n";
  2027. if ($action != 'editfile' || empty($file)) {
  2028. print '<span class="opacitymedium">'.$langs->trans("LanguageDefDesc").'</span><br>';
  2029. print '<br>';
  2030. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  2031. print '<input type="hidden" name="token" value="'.newToken().'">';
  2032. print '<input type="hidden" name="action" value="addlanguage">';
  2033. print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
  2034. print '<input type="hidden" name="tab" value="'.$tab.'">';
  2035. print '<input type="hidden" name="module" value="'.$module.'">';
  2036. print $formadmin->select_language($conf->global->MAIN_LANG_DEFAULT, 'newlangcode', 0, 0, 1, 0, 0, 'minwidth300', 1);
  2037. print '<input type="submit" name="addlanguage" class="button smallpaddingimp" value="'.dol_escape_htmltag($langs->trans("AddLanguageFile")).'"><br>';
  2038. print '</form>';
  2039. print '<br>';
  2040. print '<br>';
  2041. $modulelowercase = strtolower($module);
  2042. // Dir for module
  2043. $diroflang = dol_buildpath($modulelowercase, 0);
  2044. $diroflang .= '/langs';
  2045. $langfiles = dol_dir_list($diroflang, 'files', 1, '\.lang$');
  2046. if (!preg_match('/custom/', $dirread)) {
  2047. // If this is not a module into custom
  2048. $diroflang = $dirread;
  2049. $diroflang .= '/langs';
  2050. $langfiles = dol_dir_list($diroflang, 'files', 1, $modulelowercase.'\.lang$');
  2051. }
  2052. print '<table class="none">';
  2053. foreach ($langfiles as $langfile) {
  2054. $pathtofile = $modulelowercase.'/langs/'.$langfile['relativename'];
  2055. if (!preg_match('/custom/', $dirread)) { // If this is not a module into custom
  2056. $pathtofile = 'langs/'.$langfile['relativename'];
  2057. }
  2058. print '<tr><td><span class="fa fa-file-o"></span> '.$langs->trans("LanguageFile").' '.basename(dirname($pathtofile)).' : <strong class="wordbreak">'.$pathtofile.'</strong>';
  2059. 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>';
  2060. 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>';
  2061. print '</td>';
  2062. }
  2063. print '</table>';
  2064. } else {
  2065. // Edit text language file
  2066. //print $langs->trans("UseAsciiDocFormat").'<br>';
  2067. $fullpathoffile = dol_buildpath($file, 0);
  2068. $content = file_get_contents($fullpathoffile);
  2069. // New module
  2070. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  2071. print '<input type="hidden" name="token" value="'.newToken().'">';
  2072. print '<input type="hidden" name="action" value="savefile">';
  2073. print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
  2074. print '<input type="hidden" name="tab" value="'.$tab.'">';
  2075. print '<input type="hidden" name="module" value="'.$module.'">';
  2076. $doleditor = new DolEditor('editfilecontent', $content, '', '300', 'Full', 'In', true, false, 'ace', 0, '99%');
  2077. print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ?GETPOST('format', 'aZ09') : 'text'));
  2078. print '<br>';
  2079. print '<center>';
  2080. print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
  2081. print ' &nbsp; ';
  2082. print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
  2083. print '</center>';
  2084. print '</form>';
  2085. }
  2086. }
  2087. if ($tab == 'objects') {
  2088. print '<!-- tab=objects -->'."\n";
  2089. $head3 = array();
  2090. $h = 0;
  2091. // Dir for module
  2092. $dir = $dirread.'/'.$modulelowercase.'/class';
  2093. $head3[$h][0] = $_SERVER["PHP_SELF"].'?tab=objects&module='.$module.($forceddirread ? '@'.$dirread : '').'&tabobj=newobject';
  2094. $head3[$h][1] = '<span class="valignmiddle text-plus-circle">'.$langs->trans("NewObjectInModulebuilder").'</span><span class="fa fa-plus-circle valignmiddle paddingleft"></span>';
  2095. $head3[$h][2] = 'newobject';
  2096. $h++;
  2097. // Scan for object class files
  2098. $listofobject = dol_dir_list($dir, 'files', 0, '\.class\.php$');
  2099. $firstobjectname = '';
  2100. foreach ($listofobject as $fileobj) {
  2101. if (preg_match('/^api_/', $fileobj['name'])) {
  2102. continue;
  2103. }
  2104. if (preg_match('/^actions_/', $fileobj['name'])) {
  2105. continue;
  2106. }
  2107. $tmpcontent = file_get_contents($fileobj['fullname']);
  2108. if (preg_match('/class\s+([^\s]*)\s+extends\s+CommonObject/ims', $tmpcontent, $reg)) {
  2109. //$objectname = preg_replace('/\.txt$/', '', $fileobj['name']);
  2110. $objectname = $reg[1];
  2111. if (empty($firstobjectname)) {
  2112. $firstobjectname = $objectname;
  2113. }
  2114. $head3[$h][0] = $_SERVER["PHP_SELF"].'?tab=objects&module='.$module.($forceddirread ? '@'.$dirread : '').'&tabobj='.$objectname;
  2115. $head3[$h][1] = $objectname;
  2116. $head3[$h][2] = $objectname;
  2117. $h++;
  2118. }
  2119. }
  2120. if ($h > 1) {
  2121. $head3[$h][0] = $_SERVER["PHP_SELF"].'?tab=objects&module='.$module.($forceddirread ? '@'.$dirread : '').'&tabobj=deleteobject';
  2122. $head3[$h][1] = $langs->trans("DangerZone");
  2123. $head3[$h][2] = 'deleteobject';
  2124. $h++;
  2125. }
  2126. // 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.
  2127. if ($tabobj == 'newobjectifnoobj') {
  2128. if ($firstobjectname) {
  2129. $tabobj = $firstobjectname;
  2130. } else {
  2131. $tabobj = 'newobject';
  2132. }
  2133. }
  2134. print dol_get_fiche_head($head3, $tabobj, '', -1, ''); // Level 3
  2135. if ($tabobj == 'newobject') {
  2136. // New object tab
  2137. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  2138. print '<input type="hidden" name="token" value="'.newToken().'">';
  2139. print '<input type="hidden" name="action" value="initobject">';
  2140. print '<input type="hidden" name="tab" value="objects">';
  2141. print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
  2142. print '<span class="opacitymedium">'.$langs->trans("EnterNameOfObjectDesc").'</span><br><br>';
  2143. 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>';
  2144. print '<input type="checkbox" name="includerefgeneration" id="includerefgeneration" value="includerefgeneration"> <label for="includerefgeneration">'.$form->textwithpicto($langs->trans("IncludeRefGeneration"), $langs->trans("IncludeRefGenerationHelp")).'</label><br>';
  2145. print '<input type="checkbox" name="includedocgeneration" id="includedocgeneration" value="includedocgeneration"> <label for="includedocgeneration">'.$form->textwithpicto($langs->trans("IncludeDocGeneration"), $langs->trans("IncludeDocGenerationHelp")).'</label><br>';
  2146. print '<input type="submit" class="button smallpaddingimp" name="create" value="'.dol_escape_htmltag($langs->trans("Generate")).'"'.($dirins ? '' : ' disabled="disabled"').'>';
  2147. print '<br>';
  2148. print '<br>';
  2149. print '<br>';
  2150. print '<span class="opacitymedium">'.$langs->trans("or").'</span>';
  2151. print '<br>';
  2152. print '<br>';
  2153. //print '<input type="checkbox" name="initfromtablecheck"> ';
  2154. print $langs->trans("InitStructureFromExistingTable");
  2155. print '<input type="text" name="initfromtablename" value="" placeholder="'.$langs->trans("TableName").'">';
  2156. print '<input type="submit" class="button smallpaddingimp" name="createtablearray" value="'.dol_escape_htmltag($langs->trans("Generate")).'"'.($dirins ? '' : ' disabled="disabled"').'>';
  2157. print '<br>';
  2158. print '</form>';
  2159. } elseif ($tabobj == 'deleteobject') {
  2160. // Delete object tab
  2161. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  2162. print '<input type="hidden" name="token" value="'.newToken().'">';
  2163. print '<input type="hidden" name="action" value="confirm_deleteobject">';
  2164. print '<input type="hidden" name="tab" value="objects">';
  2165. print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
  2166. print $langs->trans("EnterNameOfObjectToDeleteDesc").'<br><br>';
  2167. print '<input type="text" name="objectname" value="'.dol_escape_htmltag($modulename).'" placeholder="'.dol_escape_htmltag($langs->trans("ObjectKey")).'">';
  2168. print '<input type="submit" class="button smallpaddingimp" name="delete" value="'.dol_escape_htmltag($langs->trans("Delete")).'"'.($dirins ? '' : ' disabled="disabled"').'>';
  2169. print '</form>';
  2170. } else {
  2171. // tabobj = module
  2172. if ($action == 'deleteproperty') {
  2173. $formconfirm = $form->formconfirm(
  2174. $_SERVER["PHP_SELF"].'?propertykey='.urlencode(GETPOST('propertykey', 'alpha')).'&objectname='.urlencode($objectname).'&tab='.urlencode($tab).'&module='.urlencode($module).'&tabobj='.urlencode($tabobj),
  2175. $langs->trans('Delete'),
  2176. $langs->trans('ConfirmDeleteProperty', GETPOST('propertykey', 'alpha')),
  2177. 'confirm_deleteproperty',
  2178. '',
  2179. 0,
  2180. 1
  2181. );
  2182. // Print form confirm
  2183. print $formconfirm;
  2184. }
  2185. if ($action != 'editfile' || empty($file)) {
  2186. try {
  2187. //$pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
  2188. $pathtoclass = strtolower($module).'/class/'.strtolower($tabobj).'.class.php';
  2189. $pathtoapi = strtolower($module).'/class/api_'.strtolower($module).'.class.php';
  2190. $pathtoagenda = strtolower($module).'/'.strtolower($tabobj).'_agenda.php';
  2191. $pathtocard = strtolower($module).'/'.strtolower($tabobj).'_card.php';
  2192. $pathtodocument = strtolower($module).'/'.strtolower($tabobj).'_document.php';
  2193. $pathtolist = strtolower($module).'/'.strtolower($tabobj).'_list.php';
  2194. $pathtonote = strtolower($module).'/'.strtolower($tabobj).'_note.php';
  2195. $pathtocontact = strtolower($module).'/'.strtolower($tabobj).'_contact.php';
  2196. $pathtophpunit = strtolower($module).'/test/phpunit/'.strtolower($tabobj).'Test.php';
  2197. // Try to load object class file
  2198. clearstatcache(true);
  2199. if (function_exists('opcache_invalidate')) {
  2200. opcache_invalidate($dirread.'/'.$pathtoclass, true); // remove the include cache hell !
  2201. }
  2202. if (empty($forceddirread) && empty($dirread)) {
  2203. $result = dol_include_once($pathtoclass);
  2204. $stringofinclude = "dol_include_once(".$pathtoclass.")";
  2205. } else {
  2206. $result = @include_once $dirread.'/'.$pathtoclass;
  2207. $stringofinclude = "@include_once ".$dirread.'/'.$pathtoclass;
  2208. }
  2209. if (class_exists($tabobj)) {
  2210. try {
  2211. $tmpobjet = @new $tabobj($db);
  2212. } catch (Exception $e) {
  2213. dol_syslog('Failed to load Constructor of class: '.$e->getMessage(), LOG_WARNING);
  2214. }
  2215. } else {
  2216. print '<span class="warning">'.$langs->trans('Failed to find the class '.$tabobj.' despite the '.$stringofinclude).'</span><br><br>';
  2217. }
  2218. // Define path for sql file
  2219. $pathtosql = strtolower($module).'/sql/llx_'.strtolower($module).'_'.strtolower($tabobj).'-'.strtolower($module).'.sql';
  2220. $result = dol_buildpath($pathtosql);
  2221. if (! dol_is_file($result)) {
  2222. $pathtosql = strtolower($module).'/sql/llx_'.strtolower($module).'_'.strtolower($tabobj).'.sql';
  2223. $result = dol_buildpath($pathtosql);
  2224. if (! dol_is_file($result)) {
  2225. $pathtosql = 'install/mysql/tables/llx_'.strtolower($module).'_'.strtolower($tabobj).'-'.strtolower($module).'.sql';
  2226. $result = dol_buildpath($pathtosql);
  2227. if (! dol_is_file($result)) {
  2228. $pathtosql = 'install/mysql/tables/llx_'.strtolower($module).'-'.strtolower($module).'.sql';
  2229. $result = dol_buildpath($pathtosql);
  2230. if (! dol_is_file($result)) {
  2231. $pathtosql = 'install/mysql/tables/llx_'.strtolower($module).'.sql';
  2232. $pathtosqlextra = 'install/mysql/tables/llx_'.strtolower($module).'_extrafields.sql';
  2233. $result = dol_buildpath($pathtosql);
  2234. } else {
  2235. $pathtosqlextra = 'install/mysql/tables/llx_'.strtolower($module).'_extrafields-'.strtolower($module).'.sql';
  2236. }
  2237. } else {
  2238. $pathtosqlextra = 'install/mysql/tables/llx_'.strtolower($module).'_'.strtolower($tabobj).'_extrafields-'.strtolower($module).'.sql';
  2239. }
  2240. } else {
  2241. $pathtosqlextra = strtolower($module).'/sql/llx_'.strtolower($module).'_'.strtolower($tabobj).'_extrafields.sql';
  2242. }
  2243. } else {
  2244. $pathtosqlextra = strtolower($module).'/sql/llx_'.strtolower($module).'_'.strtolower($tabobj).'_extrafields-'.strtolower($module).'.sql';
  2245. }
  2246. $pathtosqlroot = preg_replace('/\/llx_.*$/', '', $pathtosql);
  2247. $pathtosqlkey = preg_replace('/\.sql$/', '.key.sql', $pathtosql);
  2248. $pathtosqlextrakey = preg_replace('/\.sql$/', '.key.sql', $pathtosqlextra);
  2249. $pathtolib = strtolower($module).'/lib/'.strtolower($module).'.lib.php';
  2250. $pathtoobjlib = strtolower($module).'/lib/'.strtolower($module).'_'.strtolower($tabobj).'.lib.php';
  2251. $pathtopicto = strtolower($module).'/img/object_'.strtolower($tabobj).'.png';
  2252. //var_dump($pathtoclass);
  2253. //var_dump($dirread);
  2254. $realpathtoclass = $dirread.'/'.$pathtoclass;
  2255. $realpathtoapi = $dirread.'/'.$pathtoapi;
  2256. $realpathtoagenda = $dirread.'/'.$pathtoagenda;
  2257. $realpathtocard = $dirread.'/'.$pathtocard;
  2258. $realpathtodocument = $dirread.'/'.$pathtodocument;
  2259. $realpathtolist = $dirread.'/'.$pathtolist;
  2260. $realpathtonote = $dirread.'/'.$pathtonote;
  2261. $realpathtocontact = $dirread.'/'.$pathtocontact;
  2262. $realpathtophpunit = $dirread.'/'.$pathtophpunit;
  2263. $realpathtosql = $dirread.'/'.$pathtosql;
  2264. $realpathtosqlextra = $dirread.'/'.$pathtosqlextra;
  2265. $realpathtosqlkey = $dirread.'/'.$pathtosqlkey;
  2266. $realpathtosqlextrakey = $dirread.'/'.$pathtosqlextrakey;
  2267. $realpathtolib = $dirread.'/'.$pathtolib;
  2268. $realpathtoobjlib = $dirread.'/'.$pathtoobjlib;
  2269. $realpathtopicto = $dirread.'/'.$pathtopicto;
  2270. if (empty($realpathtoapi)) { // For compatibility with some old modules
  2271. $pathtoapi = strtolower($module).'/class/api_'.strtolower($module).'s.class.php';
  2272. $realpathtoapi = $dirread.'/'.$pathtoapi;
  2273. }
  2274. $urloflist = dol_buildpath('/'.$pathtolist, 1);
  2275. $urlofcard = dol_buildpath('/'.$pathtocard, 1);
  2276. print '<div class="fichehalfleft smallxxx">';
  2277. // Main DAO class file
  2278. 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>';
  2279. 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>';
  2280. // API file
  2281. print '<br>';
  2282. 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>';
  2283. if (dol_is_file($realpathtoapi)) {
  2284. 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>';
  2285. print ' ';
  2286. 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>';
  2287. print ' &nbsp; ';
  2288. if (empty($conf->global->$const_name)) { // If module is not activated
  2289. print '<a href="#" class="classfortooltip" target="apiexplorer" title="'.$langs->trans("ModuleMustBeEnabled", $module).'"><strike>'.$langs->trans("GoToApiExplorer").'</strike></a>';
  2290. } else {
  2291. print '<a href="'.DOL_URL_ROOT.'/api/index.php/explorer/" target="apiexplorer">'.$langs->trans("GoToApiExplorer").'</a>';
  2292. }
  2293. } else {
  2294. 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>';
  2295. }
  2296. // PHPUnit
  2297. print '<br>';
  2298. 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>';
  2299. if (dol_is_file($realpathtophpunit)) {
  2300. 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>';
  2301. print ' ';
  2302. 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>';
  2303. } else {
  2304. 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>';
  2305. }
  2306. print '<br>';
  2307. print '<br>';
  2308. 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>';
  2309. 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>';
  2310. print '<br>';
  2311. 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>';
  2312. 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>';
  2313. print '<br>';
  2314. 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>';
  2315. //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>';
  2316. print '<br>';
  2317. print '<br>';
  2318. 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>';
  2319. 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>';
  2320. 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>';
  2321. //print ' &nbsp; <a href="'.$_SERVER["PHP_SELF"].'">'.$langs->trans("RunSql").'</a>';
  2322. print '<br>';
  2323. 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>';
  2324. 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>';
  2325. //print ' &nbsp; <a href="'.$_SERVER["PHP_SELF"].'">'.$langs->trans("RunSql").'</a>';
  2326. print '<br>';
  2327. 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>';
  2328. if (dol_is_file($realpathtosqlextra) && dol_is_file($realpathtosqlextrakey)) {
  2329. 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>';
  2330. print ' ';
  2331. 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>';
  2332. print ' &nbsp; ';
  2333. 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>';
  2334. } else {
  2335. 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>';
  2336. }
  2337. //print ' &nbsp; <a href="'.$_SERVER["PHP_SELF"].'">'.$langs->trans("RunSql").'</a>';
  2338. print '<br>';
  2339. 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>';
  2340. if (dol_is_file($realpathtosqlextra) && dol_is_file($realpathtosqlextrakey)) {
  2341. 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>';
  2342. print ' ';
  2343. 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>';
  2344. } else {
  2345. 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>';
  2346. }
  2347. print '<br>';
  2348. print '</div>';
  2349. print '<div class="fichehalfleft smallxxxx">';
  2350. 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>';
  2351. 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>';
  2352. print '<br>';
  2353. 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>';
  2354. 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>';
  2355. print '<br>';
  2356. // Page contact
  2357. 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>';
  2358. 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>';
  2359. if (dol_is_file($realpathtocontact)) {
  2360. print ' ';
  2361. 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>';
  2362. } else {
  2363. 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>';
  2364. }
  2365. print '<br>';
  2366. // Page document
  2367. 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>';
  2368. 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>';
  2369. if (dol_is_file($realpathtodocument)) {
  2370. print ' ';
  2371. 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>';
  2372. } else {
  2373. 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>';
  2374. }
  2375. print '<br>';
  2376. // Page notes
  2377. 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>';
  2378. 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>';
  2379. if (dol_is_file($realpathtonote)) {
  2380. print ' ';
  2381. 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>';
  2382. } else {
  2383. 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>';
  2384. }
  2385. print '<br>';
  2386. // Page agenda
  2387. 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>';
  2388. 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>';
  2389. if (dol_is_file($realpathtoagenda)) {
  2390. print ' ';
  2391. 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>';
  2392. } else {
  2393. 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>';
  2394. }
  2395. print '<br>';
  2396. print '<br>';
  2397. print '</div>';
  2398. print '<br><br><br>';
  2399. if (!empty($tmpobjet)) {
  2400. $reflector = new ReflectionClass($tabobj);
  2401. $reflectorproperties = $reflector->getProperties(); // Can also use get_object_vars
  2402. $reflectorpropdefault = $reflector->getDefaultProperties(); // Can also use get_object_vars
  2403. //$propstat = $reflector->getStaticProperties();
  2404. //var_dump($reflectorpropdefault);
  2405. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  2406. print '<input type="hidden" name="token" value="'.newToken().'">';
  2407. print '<input type="hidden" name="action" value="addproperty">';
  2408. print '<input type="hidden" name="tab" value="objects">';
  2409. print '<input type="hidden" name="page_y" value="">';
  2410. print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module.($forceddirread ? '@'.$dirread : '')).'">';
  2411. print '<input type="hidden" name="tabobj" value="'.dol_escape_htmltag($tabobj).'">';
  2412. print '<input class="button smallpaddingimp" type="submit" name="regenerateclasssql" value="'.$langs->trans("RegenerateClassAndSql").'">';
  2413. print '<br><br>';
  2414. print load_fiche_titre($langs->trans("ObjectProperties"), '', '');
  2415. print '<!-- Table with properties of object -->'."\n";
  2416. print '<div class="div-table-responsive">';
  2417. print '<table class="noborder small">';
  2418. print '<tr class="liste_titre">';
  2419. print '<th class="none">'.$langs->trans("Property");
  2420. 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>)';
  2421. print '</th>';
  2422. print '<th>';
  2423. print $form->textwithpicto($langs->trans("Label"), $langs->trans("YouCanUseTranslationKey"));
  2424. print '</th>';
  2425. print '<th>'.$form->textwithpicto($langs->trans("Type"), $langs->trans("TypeOfFieldsHelp")).'</th>';
  2426. print '<th>'.$form->textwithpicto($langs->trans("ArrayOfKeyValues"), $langs->trans("ArrayOfKeyValuesDesc")).'</th>';
  2427. print '<th class="center">'.$form->textwithpicto($langs->trans("NotNull"), $langs->trans("NotNullDesc")).'</th>';
  2428. print '<th class="center">'.$langs->trans("DefaultValue").'</th>';
  2429. print '<th class="center">'.$langs->trans("DatabaseIndex").'</th>';
  2430. print '<th class="center">'.$langs->trans("ForeignKey").'</th>';
  2431. print '<th class="right">'.$langs->trans("Position").'</th>';
  2432. print '<th class="center">'.$form->textwithpicto($langs->trans("Enabled"), $langs->trans("EnabledDesc")).'</th>';
  2433. print '<th class="center">'.$form->textwithpicto($langs->trans("Visible"), $langs->trans("VisibleDesc")).'</th>';
  2434. print '<th class="center">'.$langs->trans("NotEditable").'</th>';
  2435. print '<th class="center">'.$form->textwithpicto($langs->trans("SearchAll"), $langs->trans("SearchAllDesc")).'</th>';
  2436. print '<th class="center">'.$form->textwithpicto($langs->trans("IsAMeasure"), $langs->trans("IsAMeasureDesc")).'</th>';
  2437. print '<th class="center">'.$langs->trans("CSSClass").'</th>';
  2438. print '<th class="center">'.$langs->trans("CSSViewClass").'</th>';
  2439. print '<th class="center">'.$langs->trans("CSSListClass").'</th>';
  2440. print '<th>'.$langs->trans("KeyForTooltip").'</th>';
  2441. print '<th class="center">'.$langs->trans("ShowOnCombobox").'</th>';
  2442. //print '<th class="center">'.$langs->trans("Disabled").'</th>';
  2443. print '<th>'.$form->textwithpicto($langs->trans("Validate"), $langs->trans("ValidateModBuilderDesc")).'</th>';
  2444. print '<th>'.$langs->trans("Comment").'</th>';
  2445. print '<th class="none"></th>';
  2446. print '</tr>';
  2447. // We must use $reflectorpropdefault['fields'] to get list of fields because $tmpobjet->fields may have been
  2448. // modified during the constructor and we want value into head of class before constructor is called.
  2449. //$properties = dol_sort_array($tmpobjet->fields, 'position');
  2450. $properties = dol_sort_array($reflectorpropdefault['fields'], 'position');
  2451. if (!empty($properties)) {
  2452. // Line to add a property
  2453. print '<tr>';
  2454. print '<td class="none"><input type="text" class="maxwidth75" name="propname" value="'.dol_escape_htmltag(GETPOST('propname', 'alpha')).'"></td>';
  2455. print '<td><input type="text" class="maxwidth75" name="proplabel" value="'.dol_escape_htmltag(GETPOST('proplabel', 'alpha')).'"></td>';
  2456. print '<td><input type="text" class="maxwidth75" name="proptype" value="'.dol_escape_htmltag(GETPOST('proptype', 'alpha')).'"></td>';
  2457. print '<td><input type="text" class="maxwidth75" name="proparrayofkeyval" value="'.dol_escape_htmltag(GETPOST('proparrayofkeyval', 'restricthtml')).'"></td>';
  2458. print '<td class="center"><input type="text" class="center maxwidth50" name="propnotnull" value="'.dol_escape_htmltag(GETPOST('propnotnull', 'alpha')).'"></td>';
  2459. print '<td><input type="text" class="center maxwidth50" name="propdefault" value="'.dol_escape_htmltag(GETPOST('propdefault', 'alpha')).'"></td>';
  2460. print '<td class="center"><input type="text" class="center maxwidth50" name="propindex" value="'.dol_escape_htmltag(GETPOST('propindex', 'alpha')).'"></td>';
  2461. print '<td class="center"><input type="text" class="maxwidth100" name="propforeignkey" value="'.dol_escape_htmltag(GETPOST('propforeignkey', 'alpha')).'"></td>';
  2462. print '<td class="right"><input type="text" class="right" size="2" name="propposition" value="'.dol_escape_htmltag(GETPOST('propposition', 'alpha')).'"></td>';
  2463. print '<td class="center"><input type="text" class="center maxwidth50" name="propenabled" value="'.dol_escape_htmltag(GETPOST('propenabled', 'alpha')).'"></td>';
  2464. print '<td class="center"><input type="text" class="center maxwidth50" name="propvisible" value="'.dol_escape_htmltag(GETPOST('propvisible', 'alpha')).'"></td>';
  2465. print '<td class="center"><input type="text" class="center maxwidth50" name="propnoteditable" value="'.dol_escape_htmltag(GETPOST('propnoteditable', 'alpha')).'"></td>';
  2466. print '<td class="center"><input type="text" class="center maxwidth50" name="propsearchall" value="'.dol_escape_htmltag(GETPOST('propsearchall', 'alpha')).'"></td>';
  2467. print '<td class="center"><input type="text" class="center maxwidth50" name="propisameasure" value="'.dol_escape_htmltag(GETPOST('propisameasure', 'alpha')).'"></td>';
  2468. print '<td class="center"><input type="text" class="maxwidth50" name="propcss" value="'.dol_escape_htmltag(GETPOST('propcss', 'alpha')).'"></td>';
  2469. print '<td class="center"><input type="text" class="maxwidth50" name="propcssview" value="'.dol_escape_htmltag(GETPOST('propcssview', 'alpha')).'"></td>';
  2470. print '<td class="center"><input type="text" class="maxwidth50" name="propcsslist" value="'.dol_escape_htmltag(GETPOST('propcsslist', 'alpha')).'"></td>';
  2471. print '<td><input type="text" size="2" name="prophelp" value="'.dol_escape_htmltag(GETPOST('prophelp', 'alpha')).'"></td>';
  2472. print '<td class="center"><input type="text" class="center maxwidth50" name="propshowoncombobox" value="'.dol_escape_htmltag(GETPOST('propshowoncombobox', 'alpha')).'"></td>';
  2473. //print '<td class="center"><input type="text" size="2" name="propdisabled" value="'.dol_escape_htmltag(GETPOST('propdisabled', 'alpha')).'"></td>';
  2474. print '<td><input type="number" step="1" min="0" max="1" class="text maxwidth100" name="propvalidate" value="'.dol_escape_htmltag(GETPOST('propvalidate', 'alpha')).'"></td>';
  2475. print '<td><input class="text maxwidth100" name="propcomment" value="'.dol_escape_htmltag(GETPOST('propcomment', 'alpha')).'"></td>';
  2476. print '<td class="center tdstickyright tdstickyghostwhite">';
  2477. print '<input type="submit" class="button" name="add" value="'.$langs->trans("Add").'">';
  2478. print '</td></tr>';
  2479. // List of existing properties
  2480. foreach ($properties as $propkey => $propval) {
  2481. /* If from Reflection
  2482. if ($propval->class == $tabobj)
  2483. {
  2484. $propname=$propval->getName();
  2485. $comment=$propval->getDocComment();
  2486. $type=gettype($tmpobjet->$propname);
  2487. $default=$propdefault[$propname];
  2488. // Discard generic properties
  2489. if (in_array($propname, array('element', 'childtables', 'table_element', 'table_element_line', 'class_element_line', 'ismultientitymanaged'))) continue;
  2490. // Keep or not lines
  2491. if (in_array($propname, array('fk_element', 'lines'))) continue;
  2492. }*/
  2493. $propname = $propkey;
  2494. $proplabel = $propval['label'];
  2495. $proptype = $propval['type'];
  2496. $proparrayofkeyval = !empty($propval['arrayofkeyval'])?$propval['arrayofkeyval']:'';
  2497. $propnotnull = $propval['notnull'];
  2498. $propdefault = !empty($propval['default'])?$propval['default']:'';
  2499. $propindex = !empty($propval['index'])?$propval['index']:'';
  2500. $propforeignkey = !empty($propval['foreignkey'])?$propval['foreignkey']:'';
  2501. $propposition = $propval['position'];
  2502. $propenabled = $propval['enabled'];
  2503. $propvisible = $propval['visible'];
  2504. $propnoteditable = !empty($propval['noteditable'])?$propval['noteditable']:0;
  2505. $propsearchall = !empty($propval['searchall'])?$propval['searchall']:0;
  2506. $propisameasure = !empty($propval['isameasure'])?$propval['isameasure']:0;
  2507. $propcss = !empty($propval['css'])?$propval['css']:'';
  2508. $propcssview = !empty($propval['cssview'])?$propval['cssview']:'';
  2509. $propcsslist = !empty($propval['csslist'])?$propval['csslist']:'';
  2510. $prophelp = !empty($propval['help'])?$propval['help']:'';
  2511. $propshowoncombobox = !empty($propval['showoncombobox'])?$propval['showoncombobox']:0;
  2512. //$propdisabled=$propval['disabled'];
  2513. $propvalidate = !empty($propval['validate'])?$propval['validate']:0;
  2514. $propcomment = !empty($propval['comment'])?$propval['comment']:'';
  2515. print '<tr class="oddeven">';
  2516. print '<td class="tdsticky tdstickygray">';
  2517. print dol_escape_htmltag($propname);
  2518. print '</td>';
  2519. print '<td>';
  2520. print dol_escape_htmltag($proplabel);
  2521. print '</td>';
  2522. if ($action == 'editproperty' && $propname == $propertykey) {
  2523. print '<td class="tdoverflowmax200">';
  2524. print '<input type="hidden" name="propname" value="'.dol_escape_htmltag($propname).'">';
  2525. print '<input type="hidden" name="proplabel" value="'.dol_escape_htmltag($proplabel).'">';
  2526. print '<input name="proptype" value="'.dol_escape_htmltag($proptype).'"></input>';
  2527. print '</td>';
  2528. print '<td class="tdoverflowmax200">';
  2529. print '<input name="proparrayofkeyval" value="';
  2530. if (isset($proparrayofkeyval)) {
  2531. print dol_escape_htmltag(json_encode($proparrayofkeyval, JSON_UNESCAPED_UNICODE));
  2532. }
  2533. print '">';
  2534. print '</input>';
  2535. print '</td>';
  2536. print '<td>';
  2537. print '<input class="center width50" name="propnotnull" value="'.dol_escape_htmltag($propnotnull).'">';
  2538. print '</td>';
  2539. print '<td>';
  2540. print '<input class="maxwidth50" name="propdefault" value="'.dol_escape_htmltag($propdefault).'">';
  2541. print '</td>';
  2542. print '<td class="center">';
  2543. print '<input class="center maxwidth50" name="propindex" value="'.dol_escape_htmltag($propindex).'">';
  2544. print '</td>';
  2545. print '<td>';
  2546. print '<input class="center" name="propforeignkey" value="'.dol_escape_htmltag($propforeignkey).'">';
  2547. print '</td>';
  2548. print '<td>';
  2549. print '<input class="right width50" name="propposition" value="'.dol_escape_htmltag($propposition).'">';
  2550. print '</td>';
  2551. print '<td>';
  2552. print '<input class="center" name="propenabled" size="2" value="'.dol_escape_htmltag($propenabled).'">';
  2553. print '</td>';
  2554. print '<td>';
  2555. print '<input class="center" name="propvisible" size="2" value="'.dol_escape_htmltag($propvisible).'">';
  2556. print '</td>';
  2557. print '<td>';
  2558. print '<input class="center" name="propnoteditable" size="2" value="'.dol_escape_htmltag($propnoteditable).'">';
  2559. print '</td>';
  2560. print '<td>';
  2561. print '<input class="center" name="propsearchall" size="2" value="'.dol_escape_htmltag($propsearchall).'">';
  2562. print '</td>';
  2563. print '<td>';
  2564. print '<input class="center" name="propisameasure" size="2" value="'.dol_escape_htmltag($propisameasure).'">';
  2565. print '</td>';
  2566. print '<td>';
  2567. print '<input class="center maxwidth50" name="propcss" value="'.dol_escape_htmltag($propcss).'">';
  2568. print '</td>';
  2569. print '<td>';
  2570. print '<input class="center maxwidth50" name="propcssview" value="'.dol_escape_htmltag($propcssview).'">';
  2571. print '</td>';
  2572. print '<td>';
  2573. print '<input class="center maxwidth50" name="propcsslist" value="'.dol_escape_htmltag($propcsslist).'">';
  2574. print '</td>';
  2575. print '<td>';
  2576. print '<input class="maxwidth100" name="prophelp" value="'.dol_escape_htmltag($prophelp).'">';
  2577. print '</td>';
  2578. print '<td>';
  2579. print '<input class="center maxwidth50" name="propshowoncombobox" value="'.dol_escape_htmltag($propshowoncombobox).'">';
  2580. print '</td>';
  2581. print '<td>';
  2582. print '<input type="number" step="1" min="0" max="1" class="text maxwidth100" name="propvalidate" value="'.dol_escape_htmltag($propvalidate).'">';
  2583. print '</td>';
  2584. print '<td>';
  2585. print '<input class="maxwidth100" name="propcomment" value="'.dol_escape_htmltag($propcomment).'">';
  2586. print '</td>';
  2587. print '<td class="center tdstickyright tdstickyghostwhite">';
  2588. print '<input class="reposition button smallpaddingimp" type="submit" name="edit" value="'.$langs->trans("Save").'">';
  2589. print '<input class="reposition button button-cancel smallpaddingimp" type="submit" name="cancel" value="'.$langs->trans("Cancel").'">';
  2590. print '</td>';
  2591. } else {
  2592. print '<td class="tdoverflowmax200">';
  2593. print '<span title="'.dol_escape_htmltag($proptype).'">'.dol_escape_htmltag($proptype).'</span>';
  2594. print '</td>';
  2595. print '<td class="tdoverflowmax200">';
  2596. if ($proparrayofkeyval) {
  2597. print '<span title="'.dol_escape_htmltag(json_encode($proparrayofkeyval, JSON_UNESCAPED_UNICODE)).'">';
  2598. print dol_escape_htmltag(json_encode($proparrayofkeyval, JSON_UNESCAPED_UNICODE));
  2599. print '</span>';
  2600. }
  2601. print '</td>';
  2602. print '<td class="center">';
  2603. print dol_escape_htmltag($propnotnull);
  2604. print '</td>';
  2605. print '<td>';
  2606. print dol_escape_htmltag($propdefault);
  2607. print '</td>';
  2608. print '<td class="center">';
  2609. print $propindex ? '1' : '';
  2610. print '</td>';
  2611. print '<td class="center">';
  2612. print $propforeignkey ? dol_escape_htmltag($propforeignkey) : '';
  2613. print '</td>';
  2614. print '<td class="right">';
  2615. print dol_escape_htmltag($propposition);
  2616. print '</td>';
  2617. print '<td class="center">';
  2618. print $propenabled ? dol_escape_htmltag($propenabled) : '';
  2619. print '</td>';
  2620. print '<td class="center">';
  2621. print $propvisible ? dol_escape_htmltag($propvisible) : '0';
  2622. print '</td>';
  2623. print '<td class="center">';
  2624. print $propnoteditable ? dol_escape_htmltag($propnoteditable) : '';
  2625. print '</td>';
  2626. print '<td class="center">';
  2627. print $propsearchall ? '1' : '';
  2628. print '</td>';
  2629. print '<td class="center">';
  2630. print $propisameasure ? dol_escape_htmltag($propisameasure) : '';
  2631. print '</td>';
  2632. print '<td class="center">';
  2633. print $propcss ? dol_escape_htmltag($propcss) : '';
  2634. print '</td>';
  2635. print '<td class="center">';
  2636. print $propcssview ? dol_escape_htmltag($propcssview) : '';
  2637. print '</td>';
  2638. print '<td class="center">';
  2639. print $propcsslist ? dol_escape_htmltag($propcsslist) : '';
  2640. print '</td>';
  2641. print '<td class="tdoverflowmax200">';
  2642. print $prophelp ? dol_escape_htmltag($prophelp) : '';
  2643. print '</td>';
  2644. print '<td class="center">';
  2645. print $propshowoncombobox ? dol_escape_htmltag($propshowoncombobox) : '';
  2646. print '</td>';
  2647. /*print '<td class="center">';
  2648. print $propdisabled?$propdisabled:'';
  2649. print '</td>';*/
  2650. print '<td class="center">';
  2651. print $propvalidate ? dol_escape_htmltag($propvalidate) : '';
  2652. print '</td>';
  2653. print '<td class="tdoverflowmax200">';
  2654. print '<span title="'.dol_escape_htmltag($propcomment).'">';
  2655. print dol_escape_htmltag($propcomment);
  2656. print '</span>';
  2657. print '</td>';
  2658. print '<td class="center tdstickyright tdstickyghostwhite">';
  2659. if ($propname != 'rowid') {
  2660. 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>';
  2661. 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>';
  2662. }
  2663. print '</td>';
  2664. }
  2665. print '</tr>';
  2666. }
  2667. } else {
  2668. if ($tab == 'specifications') {
  2669. if ($action != 'editfile' || empty($file)) {
  2670. print '<span class="opacitymedium">'.$langs->trans("SpecDefDesc").'</span><br>';
  2671. print '<br>';
  2672. $specs = dol_dir_list(dol_buildpath($modulelowercase.'/doc', 0), 'files', 1, '(\.md|\.asciidoc)$', array('\/temp\/'));
  2673. foreach ($specs as $spec) {
  2674. $pathtofile = $modulelowercase.'/doc/'.$spec['relativename'];
  2675. $format = 'asciidoc';
  2676. if (preg_match('/\.md$/i', $spec['name'])) {
  2677. $format = 'markdown';
  2678. }
  2679. print '<span class="fa fa-file-o"></span> '.$langs->trans("SpecificationFile").' : <strong class="wordbreak">'.$pathtofile.'</strong>';
  2680. 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>';
  2681. print '<br>';
  2682. }
  2683. } else {
  2684. // Use MD or asciidoc
  2685. //print $langs->trans("UseAsciiDocFormat").'<br>';
  2686. $fullpathoffile = dol_buildpath($file, 0);
  2687. $content = file_get_contents($fullpathoffile);
  2688. // New module
  2689. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  2690. print '<input type="hidden" name="token" value="'.newToken().'">';
  2691. print '<input type="hidden" name="action" value="savefile">';
  2692. print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
  2693. print '<input type="hidden" name="tab" value="'.$tab.'">';
  2694. print '<input type="hidden" name="module" value="'.$module.'">';
  2695. $doleditor = new DolEditor('editfilecontent', $content, '', '300', 'Full', 'In', true, false, 'ace', 0, '99%');
  2696. print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ?GETPOST('format', 'aZ09') : 'html'));
  2697. print '<br>';
  2698. print '<center>';
  2699. print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
  2700. print ' &nbsp; ';
  2701. print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
  2702. print '</center>';
  2703. print '</form>';
  2704. }
  2705. }
  2706. 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>';
  2707. }
  2708. print '</table>';
  2709. print '</div>';
  2710. print '</form>';
  2711. } else {
  2712. print '<span class="warning">'.$langs->trans('Failed to init the object with the new '.$tabobj.'($db)').'</warning>';
  2713. }
  2714. } catch (Exception $e) {
  2715. print $e->getMessage();
  2716. }
  2717. } else {
  2718. if (empty($forceddirread)) {
  2719. $fullpathoffile = dol_buildpath($file, 0);
  2720. } else {
  2721. $fullpathoffile = $dirread.'/'.$file;
  2722. }
  2723. $content = file_get_contents($fullpathoffile);
  2724. // New module
  2725. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  2726. print '<input type="hidden" name="token" value="'.newToken().'">';
  2727. print '<input type="hidden" name="action" value="savefile">';
  2728. print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
  2729. print '<input type="hidden" name="tab" value="'.$tab.'">';
  2730. print '<input type="hidden" name="tabobj" value="'.dol_escape_htmltag($tabobj).'">';
  2731. print '<input type="hidden" name="module" value="'.$module.($forceddirread ? '@'.$dirread : '').'">';
  2732. $doleditor = new DolEditor('editfilecontent', $content, '', '300', 'Full', 'In', true, false, 'ace', 0, '99%');
  2733. print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ?GETPOST('format', 'aZ09') : 'html'));
  2734. print '<br>';
  2735. print '<center>';
  2736. print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
  2737. print ' &nbsp; ';
  2738. print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
  2739. print '</center>';
  2740. print '</form>';
  2741. }
  2742. }
  2743. print dol_get_fiche_end(); // Level 3
  2744. }
  2745. if ($tab == 'dictionaries') {
  2746. print '<!-- tab=dictionaries -->'."\n";
  2747. $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
  2748. $dicts = $moduleobj->dictionaries;
  2749. if ($action != 'editfile' || empty($file)) {
  2750. print '<span class="opacitymedium">';
  2751. $htmlhelp = $langs->trans("DictionariesDefDescTooltip", '{s1}');
  2752. $htmlhelp = str_replace('{s1}', '<a target="adminbis" class="nofocusvisible" href="'.DOL_URL_ROOT.'/admin/dict.php">'.$langs->trans('Setup').' - '.$langs->trans('Dictionaries').'</a>', $htmlhelp);
  2753. print $form->textwithpicto($langs->trans("DictionariesDefDesc"), $htmlhelp, 1, 'help', '', 0, 2, 'helpondesc').'<br>';
  2754. print '</span>';
  2755. print '<br>';
  2756. print '<span class="fa fa-file-o"></span> '.$langs->trans("DescriptorFile").' : <strong class="wordbreak">'.$pathtofile.'</strong>';
  2757. 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>';
  2758. print '<br>';
  2759. if (is_array($dicts) && !empty($dicts)) {
  2760. print '<span class="fa fa-file-o"></span> '.$langs->trans("LanguageFile").' :</span> ';
  2761. print '<strong class="wordbreak">'.$dicts['langs'].'</strong>';
  2762. print '<br>';
  2763. }
  2764. print '<!-- tab=objects -->'."\n";
  2765. $head3 = array();
  2766. $h = 0;
  2767. // Dir for module
  2768. //$dir = $dirread.'/'.$modulelowercase.'/class';
  2769. $head3[$h][0] = $_SERVER["PHP_SELF"].'?tab=dictionaries&module='.$module.($forceddirread ? '@'.$dirread : '').'&tabdic=newdictionary';
  2770. $head3[$h][1] = '<span class="valignmiddle text-plus-circle">'.$langs->trans("NewDictionary").'</span><span class="fa fa-plus-circle valignmiddle paddingleft"></span>';
  2771. $head3[$h][2] = 'newdictionary';
  2772. $h++;
  2773. // Scan for object class files
  2774. //$listofobject = dol_dir_list($dir, 'files', 0, '\.class\.php$');
  2775. $firstdicname = '';
  2776. foreach ($dicts['tabname'] as $key => $dic) {
  2777. $dicname = $dic;
  2778. $diclabel = $dicts['tablib'][$key];
  2779. if (empty($firstdicname)) {
  2780. $firstdicname = $dicname;
  2781. }
  2782. $head3[$h][0] = $_SERVER["PHP_SELF"].'?tab=dictionaries&module='.$module.($forceddirread ? '@'.$dirread : '').'&tabdic='.$dicname;
  2783. $head3[$h][1] = $diclabel;
  2784. $head3[$h][2] = $dicname;
  2785. $h++;
  2786. }
  2787. if ($h > 1) {
  2788. $head3[$h][0] = $_SERVER["PHP_SELF"].'?tab=dictionaries&module='.$module.($forceddirread ? '@'.$dirread : '').'&tabdic=deletedictionary';
  2789. $head3[$h][1] = $langs->trans("DangerZone");
  2790. $head3[$h][2] = 'deletedictionary';
  2791. $h++;
  2792. }
  2793. // 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.
  2794. if ($tabdic == 'newdicifnodic') {
  2795. if ($firstdicname) {
  2796. $tabdic = $firstdicname;
  2797. } else {
  2798. $tabdic = 'newdictionary';
  2799. }
  2800. }
  2801. print load_fiche_titre($langs->trans("ListOfDictionariesEntries"), '', '');
  2802. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  2803. print '<input type="hidden" name="token" value="'.newToken().'">';
  2804. print '<input type="hidden" name="action" value="addproperty">';
  2805. print '<input type="hidden" name="tab" value="dictionaries">';
  2806. print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
  2807. print '<input type="hidden" name="tabdic" value="'.dol_escape_htmltag($tabdic).'">';
  2808. print '<div class="div-table-responsive">';
  2809. print '<table class="noborder">';
  2810. print '<tr class="liste_titre">';
  2811. print_liste_field_titre("#", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder, 'thsticky thstickygrey ');
  2812. print_liste_field_titre("Table", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
  2813. print_liste_field_titre("Label", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
  2814. print_liste_field_titre("SQL", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
  2815. print_liste_field_titre("SQLSort", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
  2816. print_liste_field_titre("FieldsView", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
  2817. print_liste_field_titre("FieldsEdit", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
  2818. print_liste_field_titre("FieldsInsert", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
  2819. print_liste_field_titre("Rowid", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
  2820. print_liste_field_titre("Condition", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
  2821. print "</tr>\n";
  2822. if (!empty($dicts) && is_array($dicts) && !empty($dicts['tabname']) && is_array($dicts['tabname'])) {
  2823. $i = 0;
  2824. $maxi = count($dicts['tabname']);
  2825. while ($i < $maxi) {
  2826. print '<tr class="oddeven">';
  2827. print '<td class="tdsticky tdstickygray">';
  2828. print ($i + 1);
  2829. print '</td>';
  2830. print '<td>';
  2831. print $dicts['tabname'][$i];
  2832. print '</td>';
  2833. print '<td>';
  2834. print $dicts['tablib'][$i];
  2835. print '</td>';
  2836. print '<td>';
  2837. print $dicts['tabsql'][$i];
  2838. print '</td>';
  2839. print '<td>';
  2840. print $dicts['tabsqlsort'][$i];
  2841. print '</td>';
  2842. print '<td>';
  2843. print $dicts['tabfield'][$i];
  2844. print '</td>';
  2845. print '<td>';
  2846. print $dicts['tabfieldvalue'][$i];
  2847. print '</td>';
  2848. print '<td>';
  2849. print $dicts['tabfieldinsert'][$i];
  2850. print '</td>';
  2851. print '<td class="right">';
  2852. print $dicts['tabrowid'][$i];
  2853. print '</td>';
  2854. print '<td class="right">';
  2855. print $dicts['tabcond'][$i];
  2856. print '</td>';
  2857. print '</tr>';
  2858. $i++;
  2859. }
  2860. } else {
  2861. print '<tr><td colspan="10"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
  2862. }
  2863. print '</table>';
  2864. print '</div>';
  2865. print '</form>';
  2866. print dol_get_fiche_head($head3, $tabdic, '', -1, ''); // Level 3
  2867. if ($tabdic == 'newdictionary') {
  2868. // New dic tab
  2869. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  2870. print '<input type="hidden" name="token" value="'.newToken().'">';
  2871. print '<input type="hidden" name="action" value="initdic">';
  2872. print '<input type="hidden" name="tab" value="dictionaries">';
  2873. print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
  2874. print '<span class="opacitymedium">'.$langs->trans("EnterNameOfDictionaryDesc").'</span><br><br>';
  2875. 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>';
  2876. //print '<input type="checkbox" name="includerefgeneration" id="includerefgeneration" value="includerefgeneration"> <label for="includerefgeneration">'.$form->textwithpicto($langs->trans("IncludeRefGeneration"), $langs->trans("IncludeRefGenerationHelp")).'</label><br>';
  2877. //print '<input type="checkbox" name="includedocgeneration" id="includedocgeneration" value="includedocgeneration"> <label for="includedocgeneration">'.$form->textwithpicto($langs->trans("IncludeDocGeneration"), $langs->trans("IncludeDocGenerationHelp")).'</label><br>';
  2878. print '<input type="submit" class="button smallpaddingimp" name="create" value="'.dol_escape_htmltag($langs->trans("Generate")).'"'.($dirins ? '' : ' disabled="disabled"').'>';
  2879. /*print '<br>';
  2880. print '<br>';
  2881. print '<br>';
  2882. print '<span class="opacitymedium">'.$langs->trans("or").'</span>';
  2883. print '<br>';
  2884. print '<br>';
  2885. //print '<input type="checkbox" name="initfromtablecheck"> ';
  2886. print $langs->trans("InitStructureFromExistingTable");
  2887. print '<input type="text" name="initfromtablename" value="" placeholder="'.$langs->trans("TableName").'">';
  2888. print '<input type="submit" class="button smallpaddingimp" name="createtablearray" value="'.dol_escape_htmltag($langs->trans("Generate")).'"'.($dirins ? '' : ' disabled="disabled"').'>';
  2889. print '<br>';
  2890. */
  2891. print '</form>';
  2892. } elseif ($tabdic == 'deletedictionary') {
  2893. // Delete dic tab
  2894. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  2895. print '<input type="hidden" name="token" value="'.newToken().'">';
  2896. print '<input type="hidden" name="action" value="confirm_deleteobject">';
  2897. print '<input type="hidden" name="tab" value="dictionaries">';
  2898. print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
  2899. print $langs->trans("EnterNameOfObjectToDeleteDesc").'<br><br>';
  2900. print '<input type="text" name="objectname" value="'.dol_escape_htmltag($modulename).'" placeholder="'.dol_escape_htmltag($langs->trans("ObjectKey")).'">';
  2901. print '<input type="submit" class="button smallpaddingimp" name="delete" value="'.dol_escape_htmltag($langs->trans("Delete")).'"'.($dirins ? '' : ' disabled="disabled"').'>';
  2902. print '</form>';
  2903. } else {
  2904. print $langs->trans("FeatureNotYetAvailable");
  2905. }
  2906. print dol_get_fiche_end();
  2907. } else {
  2908. $fullpathoffile = dol_buildpath($file, 0);
  2909. $content = file_get_contents($fullpathoffile);
  2910. // New module
  2911. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  2912. print '<input type="hidden" name="token" value="'.newToken().'">';
  2913. print '<input type="hidden" name="action" value="savefile">';
  2914. print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
  2915. print '<input type="hidden" name="tab" value="'.$tab.'">';
  2916. print '<input type="hidden" name="module" value="'.$module.'">';
  2917. $doleditor = new DolEditor('editfilecontent', $content, '', '300', 'Full', 'In', true, false, 'ace', 0, '99%');
  2918. print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ?GETPOST('format', 'aZ09') : 'html'));
  2919. print '<br>';
  2920. print '<center>';
  2921. print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
  2922. print ' &nbsp; ';
  2923. print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
  2924. print '</center>';
  2925. print '</form>';
  2926. }
  2927. }
  2928. if ($tab == 'menus') {
  2929. print '<!-- tab=menus -->'."\n";
  2930. $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
  2931. $menus = $moduleobj->menu;
  2932. if ($action != 'editfile' || empty($file)) {
  2933. print '<span class="opacitymedium">';
  2934. $htmlhelp = $langs->trans("MenusDefDescTooltip", '{s1}');
  2935. $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);
  2936. print $form->textwithpicto($langs->trans("MenusDefDesc"), $htmlhelp, 1, 'help', '', 0, 2, 'helpondesc').'<br>';
  2937. print '</span>';
  2938. print '<br>';
  2939. print '<span class="fa fa-file-o"></span> '.$langs->trans("DescriptorFile").' : <strong class="wordbreak">'.$pathtofile.'</strong>';
  2940. 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>';
  2941. print '<br>';
  2942. print '<br>';
  2943. print load_fiche_titre($langs->trans("ListOfMenusEntries"), '', '');
  2944. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  2945. print '<input type="hidden" name="token" value="'.newToken().'">';
  2946. print '<input type="hidden" name="action" value="addproperty">';
  2947. print '<input type="hidden" name="tab" value="objects">';
  2948. print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
  2949. print '<input type="hidden" name="tabobj" value="'.dol_escape_htmltag($tabobj).'">';
  2950. print '<div class="div-table-responsive">';
  2951. print '<table class="noborder small">';
  2952. print '<tr class="liste_titre">';
  2953. print_liste_field_titre("#", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder, 'thsticky ');
  2954. print_liste_field_titre("Type", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
  2955. print_liste_field_titre("LinkToParentMenu", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
  2956. print_liste_field_titre("Title", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
  2957. print_liste_field_titre("mainmenu", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
  2958. print_liste_field_titre("leftmenu", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
  2959. print_liste_field_titre("RelativeURL", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
  2960. print_liste_field_titre("LanguageFile", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
  2961. print_liste_field_titre("Position", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder, 'right ');
  2962. print_liste_field_titre("Enabled", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder, 'center ');
  2963. print_liste_field_titre("Permission", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
  2964. print_liste_field_titre("Target", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
  2965. print_liste_field_titre("UserType", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder, 'right ');
  2966. print "</tr>\n";
  2967. if (count($menus)) {
  2968. $i = 0;
  2969. foreach ($menus as $menu) {
  2970. $i++;
  2971. print '<tr class="oddeven">';
  2972. print '<td class="tdsticky tdstickygray">';
  2973. print $i;
  2974. print '</td>';
  2975. print '<td>';
  2976. print dol_escape_htmltag($menu['type']);
  2977. print '</td>';
  2978. print '<td>';
  2979. print dol_escape_htmltag($menu['fk_menu']);
  2980. print '</td>';
  2981. print '<td>';
  2982. print dol_escape_htmltag($menu['titre']);
  2983. print '</td>';
  2984. print '<td>';
  2985. print dol_escape_htmltag($menu['mainmenu']);
  2986. print '</td>';
  2987. print '<td>';
  2988. print dol_escape_htmltag($menu['leftmenu']);
  2989. print '</td>';
  2990. print '<td class="tdoverflowmax300" title="'.dol_escape_htmltag($menu['url']).'">';
  2991. print dol_escape_htmltag($menu['url']);
  2992. print '</td>';
  2993. print '<td>';
  2994. print dol_escape_htmltag($menu['langs']);
  2995. print '</td>';
  2996. print '<td class="right">';
  2997. print dol_escape_htmltag($menu['position']);
  2998. print '</td>';
  2999. print '<td class="center tdoverflowmax200" title="'.dol_escape_htmltag($menu['enabled']).'">';
  3000. print dol_escape_htmltag($menu['enabled']);
  3001. print '</td>';
  3002. print '<td class="center tdoverflowmax200" title="'.dol_escape_htmltag($menu['perms']).'">';
  3003. print dol_escape_htmltag($menu['perms']);
  3004. print '</td>';
  3005. print '<td>';
  3006. print dol_escape_htmltag($menu['target']);
  3007. print '</td>';
  3008. print '<td class="right">';
  3009. print dol_escape_htmltag($menu['user']);
  3010. print '</td>';
  3011. print '</tr>';
  3012. }
  3013. } else {
  3014. print '<tr><td colspan="5"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
  3015. }
  3016. print '</table>';
  3017. print '</div>';
  3018. print '</form>';
  3019. } else {
  3020. $fullpathoffile = dol_buildpath($file, 0);
  3021. $content = file_get_contents($fullpathoffile);
  3022. // New module
  3023. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  3024. print '<input type="hidden" name="token" value="'.newToken().'">';
  3025. print '<input type="hidden" name="action" value="savefile">';
  3026. print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
  3027. print '<input type="hidden" name="tab" value="'.$tab.'">';
  3028. print '<input type="hidden" name="module" value="'.$module.'">';
  3029. $doleditor = new DolEditor('editfilecontent', $content, '', '300', 'Full', 'In', true, false, 'ace', 0, '99%');
  3030. print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ?GETPOST('format', 'aZ09') : 'html'));
  3031. print '<br>';
  3032. print '<center>';
  3033. print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
  3034. print ' &nbsp; ';
  3035. print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
  3036. print '</center>';
  3037. print '</form>';
  3038. }
  3039. }
  3040. if ($tab == 'permissions') {
  3041. print '<!-- tab=permissions -->'."\n";
  3042. $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
  3043. $perms = $moduleobj->rights;
  3044. if ($action != 'editfile' || empty($file)) {
  3045. print '<span class="opacitymedium">';
  3046. $htmlhelp = $langs->trans("PermissionsDefDescTooltip", '{s1}');
  3047. $htmlhelp = str_replace('{s1}', '<a target="adminbis" class="nofocusvisible" href="'.DOL_URL_ROOT.'/admin/perms.php">'.$langs->trans('DefaultRights').'</a>', $htmlhelp);
  3048. print $form->textwithpicto($langs->trans("PermissionsDefDesc"), $htmlhelp, 1, 'help', '', 0, 2, 'helpondesc').'<br>';
  3049. print '</span>';
  3050. print '<br>';
  3051. print '<span class="fa fa-file-o"></span> '.$langs->trans("DescriptorFile").' : <strong class="wordbreak">'.$pathtofile.'</strong>';
  3052. 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>';
  3053. print '<br>';
  3054. print '<br>';
  3055. print load_fiche_titre($langs->trans("ListOfPermissionsDefined"), '', '');
  3056. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  3057. print '<input type="hidden" name="token" value="'.newToken().'">';
  3058. print '<input type="hidden" name="action" value="addproperty">';
  3059. print '<input type="hidden" name="tab" value="objects">';
  3060. print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
  3061. print '<input type="hidden" name="tabobj" value="'.dol_escape_htmltag($tabobj).'">';
  3062. print '<div class="div-table-responsive">';
  3063. print '<table class="noborder">';
  3064. print '<tr class="liste_titre">';
  3065. print_liste_field_titre("ID", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
  3066. print_liste_field_titre("Label", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
  3067. print_liste_field_titre("Permission", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
  3068. print_liste_field_titre("", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
  3069. print "</tr>\n";
  3070. if (count($perms)) {
  3071. foreach ($perms as $perm) {
  3072. print '<tr class="oddeven">';
  3073. print '<td>';
  3074. print $perm[0];
  3075. print '</td>';
  3076. print '<td>';
  3077. print $langs->trans($perm[1]);
  3078. print '</td>';
  3079. print '<td>';
  3080. print $perm[4];
  3081. print '</td>';
  3082. print '<td>';
  3083. print $perm[5];
  3084. print '</td>';
  3085. print '</tr>';
  3086. }
  3087. } else {
  3088. print '<tr><td colspan="4"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
  3089. }
  3090. print '</table>';
  3091. print '</div>';
  3092. print '</form>';
  3093. } else {
  3094. $fullpathoffile = dol_buildpath($file, 0);
  3095. $content = file_get_contents($fullpathoffile);
  3096. // New module
  3097. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  3098. print '<input type="hidden" name="token" value="'.newToken().'">';
  3099. print '<input type="hidden" name="action" value="savefile">';
  3100. print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
  3101. print '<input type="hidden" name="tab" value="'.$tab.'">';
  3102. print '<input type="hidden" name="module" value="'.$module.'">';
  3103. $doleditor = new DolEditor('editfilecontent', $content, '', '300', 'Full', 'In', true, false, 'ace', 0, '99%');
  3104. print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ?GETPOST('format', 'aZ09') : 'html'));
  3105. print '<br>';
  3106. print '<center>';
  3107. print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
  3108. print ' &nbsp; ';
  3109. print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
  3110. print '</center>';
  3111. print '</form>';
  3112. }
  3113. }
  3114. if ($tab == 'hooks') {
  3115. print '<!-- tab=hooks -->'."\n";
  3116. if ($action != 'editfile' || empty($file)) {
  3117. print '<span class="opacitymedium">'.$langs->trans("HooksDefDesc").'</span><br>';
  3118. print '<br>';
  3119. print '<table>';
  3120. $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
  3121. print '<tr><td>';
  3122. print '<span class="fa fa-file-o"></span> '.$langs->trans("DescriptorFile").' : <strong class="wordbreak">'.$pathtofile.'</strong>';
  3123. print '</td><td>';
  3124. 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>';
  3125. print '</td></tr>';
  3126. print '<tr><td>';
  3127. $pathtohook = strtolower($module).'/class/actions_'.strtolower($module).'.class.php';
  3128. print '<span class="fa fa-file-o"></span> '.$langs->trans("HooksFile").' : ';
  3129. if (dol_is_file($dirins.'/'.$pathtohook)) {
  3130. print '<strong class="wordbreak">'.$pathtohook.'</strong>';
  3131. print '</td>';
  3132. 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> ';
  3133. 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>';
  3134. } else {
  3135. print '<span class="opacitymedium">'.$langs->trans("FileNotYetGenerated").'</span>';
  3136. 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>';
  3137. print '<td></td>';
  3138. }
  3139. print '</tr>';
  3140. } else {
  3141. $fullpathoffile = dol_buildpath($file, 0);
  3142. $content = file_get_contents($fullpathoffile);
  3143. // New module
  3144. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  3145. print '<input type="hidden" name="token" value="'.newToken().'">';
  3146. print '<input type="hidden" name="action" value="savefile">';
  3147. print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
  3148. print '<input type="hidden" name="tab" value="'.$tab.'">';
  3149. print '<input type="hidden" name="module" value="'.$module.'">';
  3150. $doleditor = new DolEditor('editfilecontent', $content, '', '300', 'Full', 'In', true, false, 'ace', 0, '99%');
  3151. print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ?GETPOST('format', 'aZ09') : 'html'));
  3152. print '<br>';
  3153. print '<center>';
  3154. print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
  3155. print ' &nbsp; ';
  3156. print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
  3157. print '</center>';
  3158. print '</form>';
  3159. }
  3160. }
  3161. if ($tab == 'triggers') {
  3162. print '<!-- tab=triggers -->'."\n";
  3163. require_once DOL_DOCUMENT_ROOT.'/core/class/interfaces.class.php';
  3164. $interfaces = new Interfaces($db);
  3165. $triggers = $interfaces->getTriggersList(array('/'.strtolower($module).'/core/triggers'));
  3166. if ($action != 'editfile' || empty($file)) {
  3167. print '<span class="opacitymedium">'.$langs->trans("TriggerDefDesc").'</span><br>';
  3168. print '<br>';
  3169. print '<table>';
  3170. $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
  3171. print '<tr><td>';
  3172. print '<span class="fa fa-file-o"></span> '.$langs->trans("DescriptorFile").' : <strong class="wordbreak">'.$pathtofile.'</strong>';
  3173. print '</td><td>';
  3174. 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>';
  3175. print '</td></tr>';
  3176. if (!empty($triggers)) {
  3177. foreach ($triggers as $trigger) {
  3178. $pathtofile = $trigger['relpath'];
  3179. print '<tr><td>';
  3180. print '<span class="fa fa-file-o"></span> '.$langs->trans("TriggersFile").' : <strong class="wordbreak">'.$pathtofile.'</strong>';
  3181. 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>';
  3182. 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>';
  3183. print '</tr>';
  3184. }
  3185. } else {
  3186. print '<tr><td>';
  3187. print '<span class="fa fa-file-o"></span> '.$langs->trans("TriggersFile");
  3188. print ' : <span class="opacitymedium">'.$langs->trans("FileNotYetGenerated").'</span>';
  3189. print '<a href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=inittrigger&format=php">'.img_picto('Generate', 'generate', 'class="paddingleft"').'</a></td>';
  3190. print '<td></td>';
  3191. print '</tr>';
  3192. }
  3193. print '</table>';
  3194. } else {
  3195. $fullpathoffile = dol_buildpath($file, 0);
  3196. $content = file_get_contents($fullpathoffile);
  3197. // New module
  3198. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  3199. print '<input type="hidden" name="token" value="'.newToken().'">';
  3200. print '<input type="hidden" name="action" value="savefile">';
  3201. print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
  3202. print '<input type="hidden" name="tab" value="'.$tab.'">';
  3203. print '<input type="hidden" name="module" value="'.$module.'">';
  3204. $doleditor = new DolEditor('editfilecontent', $content, '', '300', 'Full', 'In', true, false, 'ace', 0, '99%');
  3205. print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ?GETPOST('format', 'aZ09') : 'html'));
  3206. print '<br>';
  3207. print '<center>';
  3208. print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
  3209. print ' &nbsp; ';
  3210. print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
  3211. print '</center>';
  3212. print '</form>';
  3213. }
  3214. }
  3215. if ($tab == 'css') {
  3216. print '<!-- tab=css -->'."\n";
  3217. if ($action != 'editfile' || empty($file)) {
  3218. print '<span class="opacitymedium">'.$langs->trans("CSSDesc").'</span><br>';
  3219. print '<br>';
  3220. print '<table>';
  3221. print '<tr><td>';
  3222. $pathtohook = strtolower($module).'/css/'.strtolower($module).'.css.php';
  3223. print '<span class="fa fa-file-o"></span> '.$langs->trans("CSSFile").' : ';
  3224. if (dol_is_file($dirins.'/'.$pathtohook)) {
  3225. print '<strong class="wordbreak">'.$pathtohook.'</strong>';
  3226. 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>';
  3227. 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>';
  3228. } else {
  3229. print '<span class="opacitymedium">'.$langs->trans("FileNotYetGenerated").'</span>';
  3230. 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>';
  3231. }
  3232. print '</tr>';
  3233. } else {
  3234. $fullpathoffile = dol_buildpath($file, 0);
  3235. $content = file_get_contents($fullpathoffile);
  3236. // New module
  3237. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  3238. print '<input type="hidden" name="token" value="'.newToken().'">';
  3239. print '<input type="hidden" name="action" value="savefile">';
  3240. print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
  3241. print '<input type="hidden" name="tab" value="'.$tab.'">';
  3242. print '<input type="hidden" name="module" value="'.$module.'">';
  3243. $doleditor = new DolEditor('editfilecontent', $content, '', '300', 'Full', 'In', true, false, 'ace', 0, '99%');
  3244. print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ?GETPOST('format', 'aZ09') : 'html'));
  3245. print '<br>';
  3246. print '<center>';
  3247. print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
  3248. print ' &nbsp; ';
  3249. print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
  3250. print '</center>';
  3251. print '</form>';
  3252. }
  3253. }
  3254. if ($tab == 'js') {
  3255. print '<!-- tab=js -->'."\n";
  3256. if ($action != 'editfile' || empty($file)) {
  3257. print '<span class="opacitymedium">'.$langs->trans("JSDesc").'</span><br>';
  3258. print '<br>';
  3259. print '<table>';
  3260. print '<tr><td>';
  3261. $pathtohook = strtolower($module).'/js/'.strtolower($module).'.js.php';
  3262. print '<span class="fa fa-file-o"></span> '.$langs->trans("JSFile").' : ';
  3263. if (dol_is_file($dirins.'/'.$pathtohook)) {
  3264. print '<strong class="wordbreak">'.$pathtohook.'</strong>';
  3265. 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>';
  3266. 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>';
  3267. } else {
  3268. print '<span class="opacitymedium">'.$langs->trans("FileNotYetGenerated").'</span>';
  3269. 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>';
  3270. }
  3271. print '</tr>';
  3272. } else {
  3273. $fullpathoffile = dol_buildpath($file, 0);
  3274. $content = file_get_contents($fullpathoffile);
  3275. // New module
  3276. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  3277. print '<input type="hidden" name="token" value="'.newToken().'">';
  3278. print '<input type="hidden" name="action" value="savefile">';
  3279. print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
  3280. print '<input type="hidden" name="tab" value="'.$tab.'">';
  3281. print '<input type="hidden" name="module" value="'.$module.'">';
  3282. $doleditor = new DolEditor('editfilecontent', $content, '', '300', 'Full', 'In', true, false, 'ace', 0, '99%');
  3283. print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ?GETPOST('format', 'aZ09') : 'html'));
  3284. print '<br>';
  3285. print '<center>';
  3286. print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
  3287. print ' &nbsp; ';
  3288. print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
  3289. print '</center>';
  3290. print '</form>';
  3291. }
  3292. }
  3293. if ($tab == 'widgets') {
  3294. print '<!-- tab=widgets -->'."\n";
  3295. require_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
  3296. $widgets = ModeleBoxes::getWidgetsList(array('/'.strtolower($module).'/core/boxes'));
  3297. if ($action != 'editfile' || empty($file)) {
  3298. print '<span class="opacitymedium">'.$langs->trans("WidgetDesc").'</span><br>';
  3299. print '<br>';
  3300. print '<table>';
  3301. if (!empty($widgets)) {
  3302. foreach ($widgets as $widget) {
  3303. $pathtofile = $widget['relpath'];
  3304. print '<tr><td><span class="fa fa-file-o"></span> '.$langs->trans("WidgetFile").' : <strong class="wordbreak">'.$pathtofile.'</strong>';
  3305. 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>';
  3306. 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>';
  3307. print '</tr>';
  3308. }
  3309. } else {
  3310. print '<tr><td><span class="fa fa-file-o"></span> '.$langs->trans("WidgetFile").' : <span class="opacitymedium">'.$langs->trans("NoWidget").'</span>';
  3311. 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>';
  3312. print '</td></tr>';
  3313. }
  3314. print '</table>';
  3315. } else {
  3316. $fullpathoffile = dol_buildpath($file, 0);
  3317. $content = file_get_contents($fullpathoffile);
  3318. // New module
  3319. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  3320. print '<input type="hidden" name="token" value="'.newToken().'">';
  3321. print '<input type="hidden" name="action" value="savefile">';
  3322. print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
  3323. print '<input type="hidden" name="tab" value="'.$tab.'">';
  3324. print '<input type="hidden" name="module" value="'.$module.'">';
  3325. $doleditor = new DolEditor('editfilecontent', $content, '', '300', 'Full', 'In', true, false, 'ace', 0, '99%');
  3326. print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ?GETPOST('format', 'aZ09') : 'html'));
  3327. print '<br>';
  3328. print '<center>';
  3329. print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
  3330. print ' &nbsp; ';
  3331. print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
  3332. print '</center>';
  3333. print '</form>';
  3334. }
  3335. }
  3336. if ($tab == 'exportimport') {
  3337. print '<!-- tab=exportimport -->'."\n";
  3338. $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
  3339. $exportlist = $moduleobj->export_label;
  3340. $importlist = $moduleobj->import_label;
  3341. if ($action != 'editfile' || empty($file)) {
  3342. print '<span class="opacitymedium">'.$langs->transnoentities('ImportExportProfiles').'</span><br>';
  3343. print '<br>';
  3344. print '<span class="fa fa-file-o"></span> '.$langs->trans("DescriptorFile").' : <strong class="wordbreak">'.$pathtofile.'</strong>';
  3345. 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>';
  3346. print '<br>';
  3347. } else {
  3348. $fullpathoffile = dol_buildpath($file, 0);
  3349. $content = file_get_contents($fullpathoffile);
  3350. // New module
  3351. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  3352. print '<input type="hidden" name="token" value="'.newToken().'">';
  3353. print '<input type="hidden" name="action" value="savefile">';
  3354. print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
  3355. print '<input type="hidden" name="tab" value="'.$tab.'">';
  3356. print '<input type="hidden" name="module" value="'.$module.'">';
  3357. $doleditor = new DolEditor('editfilecontent', $content, '', '300', 'Full', 'In', true, false, 'ace', 0, '99%');
  3358. print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ?GETPOST('format', 'aZ09') : 'html'));
  3359. print '<br>';
  3360. print '<center>';
  3361. print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
  3362. print ' &nbsp; ';
  3363. print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
  3364. print '</center>';
  3365. print '</form>';
  3366. }
  3367. }
  3368. if ($tab == 'cli') {
  3369. print '<!-- tab=cli -->'."\n";
  3370. $clifiles = array();
  3371. $i = 0;
  3372. $dircli = array('/'.strtolower($module).'/scripts');
  3373. foreach ($dircli as $reldir) {
  3374. $dir = dol_buildpath($reldir, 0);
  3375. $newdir = dol_osencode($dir);
  3376. // Check if directory exists (we do not use dol_is_dir to avoid loading files.lib.php at each call)
  3377. if (!is_dir($newdir)) {
  3378. continue;
  3379. }
  3380. $handle = opendir($newdir);
  3381. if (is_resource($handle)) {
  3382. while (($tmpfile = readdir($handle)) !== false) {
  3383. if (is_readable($newdir.'/'.$file) && preg_match('/^(.+)\.php/', $tmpfile, $reg)) {
  3384. if (preg_match('/\.back$/', $tmpfile)) {
  3385. continue;
  3386. }
  3387. $clifiles[$i]['relpath'] = preg_replace('/^\//', '', $reldir).'/'.$tmpfile;
  3388. $i++;
  3389. }
  3390. }
  3391. closedir($handle);
  3392. }
  3393. }
  3394. if ($action != 'editfile' || empty($file)) {
  3395. print '<span class="opacitymedium">'.$langs->trans("CLIDesc").'</span><br>';
  3396. print '<br>';
  3397. print '<table>';
  3398. if (!empty($clifiles)) {
  3399. foreach ($clifiles as $clifile) {
  3400. $pathtofile = $clifile['relpath'];
  3401. print '<tr><td><span class="fa fa-file-o"></span> '.$langs->trans("CLIFile").' : <strong class="wordbreak">'.$pathtofile.'</strong>';
  3402. 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>';
  3403. 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>';
  3404. print '</tr>';
  3405. }
  3406. } else {
  3407. print '<tr><td><span class="fa fa-file-o"></span> '.$langs->trans("CLIFile").' : <span class="opacitymedium">'.$langs->trans("FileNotYetGenerated"); '</span>';
  3408. 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>';
  3409. print '</td></tr>';
  3410. }
  3411. print '</table>';
  3412. } else {
  3413. $fullpathoffile = dol_buildpath($file, 0);
  3414. $content = file_get_contents($fullpathoffile);
  3415. // New module
  3416. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  3417. print '<input type="hidden" name="token" value="'.newToken().'">';
  3418. print '<input type="hidden" name="action" value="savefile">';
  3419. print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
  3420. print '<input type="hidden" name="tab" value="'.$tab.'">';
  3421. print '<input type="hidden" name="module" value="'.$module.'">';
  3422. $doleditor = new DolEditor('editfilecontent', $content, '', '300', 'Full', 'In', true, false, 'ace', 0, '99%');
  3423. print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ?GETPOST('format', 'aZ09') : 'html'));
  3424. print '<br>';
  3425. print '<center>';
  3426. print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
  3427. print ' &nbsp; ';
  3428. print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
  3429. print '</center>';
  3430. print '</form>';
  3431. }
  3432. }
  3433. if ($tab == 'cron') {
  3434. print '<!-- tab=cron -->'."\n";
  3435. $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
  3436. $cronjobs = $moduleobj->cronjobs;
  3437. if ($action != 'editfile' || empty($file)) {
  3438. 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>';
  3439. print '<br>';
  3440. print '<span class="fa fa-file-o"></span> '.$langs->trans("DescriptorFile").' : <strong class="wordbreak">'.$pathtofile.'</strong>';
  3441. 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>';
  3442. print '<br>';
  3443. print '<br>';
  3444. print load_fiche_titre($langs->trans("CronJobProfiles"), '', '');
  3445. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  3446. print '<input type="hidden" name="token" value="'.newToken().'">';
  3447. print '<input type="hidden" name="action" value="addproperty">';
  3448. print '<input type="hidden" name="tab" value="objects">';
  3449. print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
  3450. print '<input type="hidden" name="tabobj" value="'.dol_escape_htmltag($tabobj).'">';
  3451. print '<div class="div-table-responsive">';
  3452. print '<table class="noborder">';
  3453. print '<tr class="liste_titre">';
  3454. print_liste_field_titre("CronLabel", $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder);
  3455. print_liste_field_titre("CronTask", '', '', "", $param, '', $sortfield, $sortorder);
  3456. print_liste_field_titre("CronFrequency", '', "", "", $param, '', $sortfield, $sortorder);
  3457. print_liste_field_titre("StatusAtInstall", $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder);
  3458. print_liste_field_titre("Comment", $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder);
  3459. print "</tr>\n";
  3460. if (count($cronjobs)) {
  3461. foreach ($cronjobs as $cron) {
  3462. print '<tr class="oddeven">';
  3463. print '<td>';
  3464. print $cron['label'];
  3465. print '</td>';
  3466. print '<td>';
  3467. if ($cron['jobtype'] == 'method') {
  3468. $text = $langs->trans("CronClass");
  3469. $texttoshow = $langs->trans('CronModule').': '.$module.'<br>';
  3470. $texttoshow .= $langs->trans('CronClass').': '.$cron['class'].'<br>';
  3471. $texttoshow .= $langs->trans('CronObject').': '.$cron['objectname'].'<br>';
  3472. $texttoshow .= $langs->trans('CronMethod').': '.$cron['method'];
  3473. $texttoshow .= '<br>'.$langs->trans('CronArgs').': '.$cron['parameters'];
  3474. $texttoshow .= '<br>'.$langs->trans('Comment').': '.$langs->trans($cron['comment']);
  3475. } elseif ($cron['jobtype'] == 'command') {
  3476. $text = $langs->trans('CronCommand');
  3477. $texttoshow = $langs->trans('CronCommand').': '.dol_trunc($cron['command']);
  3478. $texttoshow .= '<br>'.$langs->trans('CronArgs').': '.$cron['parameters'];
  3479. $texttoshow .= '<br>'.$langs->trans('Comment').': '.$langs->trans($cron['comment']);
  3480. }
  3481. print $form->textwithpicto($text, $texttoshow, 1);
  3482. print '</td>';
  3483. print '<td>';
  3484. if ($cron['unitfrequency'] == "60") {
  3485. print $langs->trans('CronEach')." ".($cron['frequency'])." ".$langs->trans('Minutes');
  3486. }
  3487. if ($cron['unitfrequency'] == "3600") {
  3488. print $langs->trans('CronEach')." ".($cron['frequency'])." ".$langs->trans('Hours');
  3489. }
  3490. if ($cron['unitfrequency'] == "86400") {
  3491. print $langs->trans('CronEach')." ".($cron['frequency'])." ".$langs->trans('Days');
  3492. }
  3493. if ($cron['unitfrequency'] == "604800") {
  3494. print $langs->trans('CronEach')." ".($cron['frequency'])." ".$langs->trans('Weeks');
  3495. }
  3496. print '</td>';
  3497. print '<td>';
  3498. print $cron['status'];
  3499. print '</td>';
  3500. print '<td>';
  3501. if (!empty($cron['comment'])) {
  3502. print $cron['comment'];
  3503. }
  3504. print '</td>';
  3505. print '</tr>';
  3506. }
  3507. } else {
  3508. print '<tr><td colspan="5"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
  3509. }
  3510. print '</table>';
  3511. print '</div>';
  3512. print '</form>';
  3513. } else {
  3514. $fullpathoffile = dol_buildpath($file, 0);
  3515. $content = file_get_contents($fullpathoffile);
  3516. // New module
  3517. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  3518. print '<input type="hidden" name="token" value="'.newToken().'">';
  3519. print '<input type="hidden" name="action" value="savefile">';
  3520. print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
  3521. print '<input type="hidden" name="tab" value="'.$tab.'">';
  3522. print '<input type="hidden" name="module" value="'.$module.'">';
  3523. $doleditor = new DolEditor('editfilecontent', $content, '', '300', 'Full', 'In', true, false, 'ace', 0, '99%');
  3524. print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ?GETPOST('format', 'aZ09') : 'html'));
  3525. print '<br>';
  3526. print '<center>';
  3527. print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
  3528. print ' &nbsp; ';
  3529. print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
  3530. print '</center>';
  3531. print '</form>';
  3532. }
  3533. }
  3534. if ($tab == 'specifications') {
  3535. print '<!-- tab=specifications -->'."\n";
  3536. $specs = dol_dir_list(dol_buildpath($modulelowercase.'/doc', 0), 'files', 1, '(\.md|\.asciidoc)$', array('\/temp\/'));
  3537. if ($action != 'editfile' || empty($file)) {
  3538. print '<span class="opacitymedium">'.$langs->trans("SpecDefDesc").'</span><br>';
  3539. print '<br>';
  3540. print '<table>';
  3541. if (is_array($specs) && !empty($specs)) {
  3542. foreach ($specs as $spec) {
  3543. $pathtofile = $modulelowercase.'/doc/'.$spec['relativename'];
  3544. $format = 'asciidoc';
  3545. if (preg_match('/\.md$/i', $spec['name'])) {
  3546. $format = 'markdown';
  3547. }
  3548. print '<tr><td>';
  3549. print '<span class="fa fa-file-o"></span> '.$langs->trans("SpecificationFile").' : <strong class="wordbreak">'.$pathtofile.'</strong>';
  3550. 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>';
  3551. 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>';
  3552. print '</tr>';
  3553. }
  3554. } else {
  3555. print '<tr><td>';
  3556. print '<span class="fa fa-file-o"></span> '.$langs->trans("SpecificationFile").' : <span class="opacitymedium">'.$langs->trans("FileNotYetGenerated").'</span>';
  3557. 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>';
  3558. print '</tr>';
  3559. }
  3560. print '</table>';
  3561. } else {
  3562. // Use MD or asciidoc
  3563. //print $langs->trans("UseAsciiDocFormat").'<br>';
  3564. $fullpathoffile = dol_buildpath($file, 0);
  3565. $content = file_get_contents($fullpathoffile);
  3566. // New module
  3567. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  3568. print '<input type="hidden" name="token" value="'.newToken().'">';
  3569. print '<input type="hidden" name="action" value="savefile">';
  3570. print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
  3571. print '<input type="hidden" name="tab" value="'.$tab.'">';
  3572. print '<input type="hidden" name="module" value="'.$module.'">';
  3573. $doleditor = new DolEditor('editfilecontent', $content, '', '300', 'Full', 'In', true, false, 'ace', 0, '99%');
  3574. print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ?GETPOST('format', 'aZ09') : 'html'));
  3575. print '<br>';
  3576. print '<center>';
  3577. print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
  3578. print ' &nbsp; ';
  3579. print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
  3580. print '</center>';
  3581. print '</form>';
  3582. }
  3583. print '<br><br><br>';
  3584. $FILENAMEDOC = $modulelowercase.'.html';
  3585. $FILENAMEDOCPDF = $modulelowercase.'.pdf';
  3586. $outputfiledoc = dol_buildpath($modulelowercase, 0).'/doc/'.$FILENAMEDOC;
  3587. $outputfiledocurl = dol_buildpath($modulelowercase, 1).'/doc/'.$FILENAMEDOC;
  3588. $outputfiledocrel = $modulelowercase.'/doc/'.$FILENAMEDOC;
  3589. $outputfiledocpdf = dol_buildpath($modulelowercase, 0).'/doc/'.$FILENAMEDOCPDF;
  3590. $outputfiledocurlpdf = dol_buildpath($modulelowercase, 1).'/doc/'.$FILENAMEDOCPDF;
  3591. $outputfiledocrelpdf = $modulelowercase.'/doc/'.$FILENAMEDOCPDF;
  3592. // HTML
  3593. print '<span class="fa fa-file-o"></span> '.$langs->trans("PathToModuleDocumentation", "HTML").' : ';
  3594. if (!dol_is_file($outputfiledoc)) {
  3595. print '<span class="opacitymedium">'.$langs->trans("FileNotYetGenerated").'</span>';
  3596. } else {
  3597. print '<strong>';
  3598. print '<a href="'.$outputfiledocurl.'" target="_blank" rel="noopener noreferrer">';
  3599. print $outputfiledoc;
  3600. print '</a>';
  3601. print '</strong>';
  3602. print ' <span class="opacitymedium">('.$langs->trans("GeneratedOn").' '.dol_print_date(dol_filemtime($outputfiledoc), 'dayhour').')</span>';
  3603. 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>';
  3604. }
  3605. print '</strong><br>';
  3606. // PDF
  3607. print '<span class="fa fa-file-o"></span> '.$langs->trans("PathToModuleDocumentation", "PDF").' : ';
  3608. if (!dol_is_file($outputfiledocpdf)) {
  3609. print '<span class="opacitymedium">'.$langs->trans("FileNotYetGenerated").'</span>';
  3610. } else {
  3611. print '<strong>';
  3612. print '<a href="'.$outputfiledocurlpdf.'" target="_blank" rel="noopener noreferrer">';
  3613. print $outputfiledocpdf;
  3614. print '</a>';
  3615. print '</strong>';
  3616. print ' <span class="opacitymedium">('.$langs->trans("GeneratedOn").' '.dol_print_date(dol_filemtime($outputfiledocpdf), 'dayhour').')</span>';
  3617. 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>';
  3618. }
  3619. print '</strong><br>';
  3620. print '<br>';
  3621. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST" name="generatedoc">';
  3622. print '<input type="hidden" name="token" value="'.newToken().'">';
  3623. print '<input type="hidden" name="action" value="generatedoc">';
  3624. print '<input type="hidden" name="tab" value="'.dol_escape_htmltag($tab).'">';
  3625. print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
  3626. print '<input type="submit" class="button" name="generatedoc" value="'.$langs->trans("BuildDocumentation").'"';
  3627. if (!is_array($specs) || empty($specs)) {
  3628. print ' disabled="disabled"';
  3629. }
  3630. print '>';
  3631. print '</form>';
  3632. }
  3633. if ($tab == 'buildpackage') {
  3634. print '<!-- tab=buildpackage -->'."\n";
  3635. print '<span class="opacitymedium">'.$langs->trans("BuildPackageDesc").'</span>';
  3636. print '<br>';
  3637. if (!class_exists('ZipArchive') && !defined('ODTPHP_PATHTOPCLZIP')) {
  3638. print img_warning().' '.$langs->trans("ErrNoZipEngine");
  3639. print '<br>';
  3640. }
  3641. $modulelowercase = strtolower($module);
  3642. // Zip file to build
  3643. $FILENAMEZIP = '';
  3644. // Load module
  3645. $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
  3646. dol_include_once($pathtofile);
  3647. $class = 'mod'.$module;
  3648. if (class_exists($class)) {
  3649. try {
  3650. $moduleobj = new $class($db);
  3651. } catch (Exception $e) {
  3652. $error++;
  3653. dol_print_error($db, $e->getMessage());
  3654. }
  3655. } else {
  3656. $error++;
  3657. $langs->load("errors");
  3658. dol_print_error($db, $langs->trans("ErrorFailedToLoadModuleDescriptorForXXX", $module));
  3659. exit;
  3660. }
  3661. $arrayversion = explode('.', $moduleobj->version, 3);
  3662. if (count($arrayversion)) {
  3663. $FILENAMEZIP = "module_".$modulelowercase.'-'.$arrayversion[0].(empty($arrayversion[1]) ? '.0' : '.'.$arrayversion[1]).($arrayversion[2] ? ".".$arrayversion[2] : '').".zip";
  3664. $outputfilezip = dol_buildpath($modulelowercase, 0).'/bin/'.$FILENAMEZIP;
  3665. }
  3666. print '<br>';
  3667. print '<span class="fa fa-file-o"></span> '.$langs->trans("PathToModulePackage").' : ';
  3668. if (!dol_is_file($outputfilezip)) {
  3669. print '<span class="opacitymedium">'.$langs->trans("FileNotYetGenerated").'</span>';
  3670. } else {
  3671. $relativepath = $modulelowercase.'/bin/'.$FILENAMEZIP;
  3672. print '<strong><a href="'.DOL_URL_ROOT.'/document.php?modulepart=packages&file='.urlencode($relativepath).'">'.$outputfilezip.'</a></strong>';
  3673. print ' <span class="opacitymedium">('.$langs->trans("GeneratedOn").' '.dol_print_date(dol_filemtime($outputfilezip), 'dayhour').')</span>';
  3674. 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>';
  3675. }
  3676. print '</strong>';
  3677. print '<br>';
  3678. print '<br>';
  3679. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST" name="generatepackage">';
  3680. print '<input type="hidden" name="token" value="'.newToken().'">';
  3681. print '<input type="hidden" name="action" value="generatepackage">';
  3682. print '<input type="hidden" name="tab" value="'.dol_escape_htmltag($tab).'">';
  3683. print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
  3684. print '<input type="submit" class="button" name="generatepackage" value="'.$langs->trans("BuildPackage").'">';
  3685. print '</form>';
  3686. }
  3687. if ($tab == 'tabs') {
  3688. $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
  3689. $tabs = $moduleobj->tabs;
  3690. if ($action != 'editfile' || empty($file)) {
  3691. print '<span class="opacitymedium">';
  3692. $htmlhelp = $langs->trans("TabsDefDescTooltip", '{s1}');
  3693. $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);
  3694. print $form->textwithpicto($langs->trans("TabsDefDesc"), $htmlhelp, 1, 'help', '', 0, 2, 'helpondesc').'<br>';
  3695. print '</span>';
  3696. print '<br>';
  3697. print '<span class="fa fa-file-o"></span> '.$langs->trans("DescriptorFile").' : <strong>'.$pathtofile.'</strong>';
  3698. 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>';
  3699. print '<br>';
  3700. print '<br>';
  3701. print load_fiche_titre($langs->trans("ListOfTabsEntries"), '', '');
  3702. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  3703. print '<input type="hidden" name="token" value="'.newToken().'">';
  3704. print '<input type="hidden" name="action" value="addproperty">';
  3705. print '<input type="hidden" name="tab" value="objects">';
  3706. print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
  3707. print '<input type="hidden" name="tabobj" value="'.dol_escape_htmltag($tabobj).'">';
  3708. print '<div class="div-table-responsive">';
  3709. print '<table class="noborder small">';
  3710. print '<tr class="liste_titre">';
  3711. print_liste_field_titre("ObjectType", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
  3712. print_liste_field_titre("Tab", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
  3713. print_liste_field_titre("Title", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
  3714. print_liste_field_titre("LangFile", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
  3715. print_liste_field_titre("Condition", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
  3716. print_liste_field_titre("Path", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
  3717. print "</tr>\n";
  3718. if (count($tabs)) {
  3719. foreach ($tabs as $tab) {
  3720. $parts = explode(':', $tab['data']);
  3721. $objectType = $parts[0];
  3722. $tabName = $parts[1];
  3723. $tabTitle = isset($parts[2]) ? $parts[2] : '';
  3724. $langFile = isset($parts[3]) ? $parts[3] : '';
  3725. $condition = isset($parts[4]) ? $parts[4] : '';
  3726. $path = isset($parts[5]) ? $parts[5] : '';
  3727. // If we want to remove the tab, then the format is 'objecttype:tabname:optionalcondition'
  3728. // See: https://wiki.dolibarr.org/index.php?title=Tabs_system#To_remove_an_existing_tab
  3729. if ($tabName[0] === '-') {
  3730. $tabTitle = '';
  3731. $condition = isset($parts[2]) ? $parts[2] : '';
  3732. }
  3733. print '<tr class="oddeven">';
  3734. print '<td>';
  3735. print dol_escape_htmltag($parts[0]);
  3736. print '</td>';
  3737. print '<td>';
  3738. if ($tabName[0] === "+") {
  3739. print '<span class="badge badge-status4 badge-status">' . dol_escape_htmltag($tabName) . '</span>';
  3740. } else {
  3741. print '<span class="badge badge-status8 badge-status">' . dol_escape_htmltag($tabName) . '</span>';
  3742. }
  3743. print '</td>';
  3744. print '<td>';
  3745. print dol_escape_htmltag($tabTitle);
  3746. print '</td>';
  3747. print '<td>';
  3748. print dol_escape_htmltag($langFile);
  3749. print '</td>';
  3750. print '<td>';
  3751. print dol_escape_htmltag($condition);
  3752. print '</td>';
  3753. print '<td>';
  3754. print dol_escape_htmltag($path);
  3755. print '</td>';
  3756. print '</tr>';
  3757. }
  3758. } else {
  3759. print '<tr><td class="opacitymedium" colspan="5">'.$langs->trans("None").'</td></tr>';
  3760. }
  3761. print '</table>';
  3762. print '</div>';
  3763. print '</form>';
  3764. } else {
  3765. $fullpathoffile = dol_buildpath($file, 0);
  3766. $content = file_get_contents($fullpathoffile);
  3767. // New module
  3768. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  3769. print '<input type="hidden" name="token" value="'.newToken().'">';
  3770. print '<input type="hidden" name="action" value="savefile">';
  3771. print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
  3772. print '<input type="hidden" name="tab" value="'.$tab.'">';
  3773. print '<input type="hidden" name="module" value="'.$module.'">';
  3774. $doleditor = new DolEditor('editfilecontent', $content, '', '300', 'Full', 'In', true, false, 'ace', 0, '99%');
  3775. print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ?GETPOST('format', 'aZ09') : 'html'));
  3776. print '<br>';
  3777. print '<center>';
  3778. print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
  3779. print ' &nbsp; ';
  3780. print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
  3781. print '</center>';
  3782. print '</form>';
  3783. }
  3784. }
  3785. if ($tab != 'description') {
  3786. print dol_get_fiche_end();
  3787. }
  3788. }
  3789. }
  3790. print dol_get_fiche_end(); // End modules
  3791. // End of page
  3792. llxFooter();
  3793. $db->close();