index.php 201 KB

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