index.php 217 KB

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