index.php 209 KB

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