index.php 180 KB

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