index.php 195 KB

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