12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989 |
- <?php
- /* Copyright (C) 2004-2019 Laurent Destailleur <eldy@users.sourceforge.net>
- * Copyright (C) 2018-2019 Nicolas ZABOURI <info@inovea-conseil.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <https://www.gnu.org/licenses/>.
- *
- * You can also make a direct call the page with parameter like this:
- * htdocs/modulebuilder/index.php?module=Inventory@/pathtodolibarr/htdocs/product
- */
- /**
- * \file htdocs/modulebuilder/index.php
- * \brief Home page for module builder module
- *
- * You can add parameter dirins=/home/ldestailleur/git/dolibarr/htdocs/mymodule to force generation of module
- * into the dirins directory.
- */
- if (!defined('NOSCANPOSTFORINJECTION')) {
- define('NOSCANPOSTFORINJECTION', '1'); // Do not check anti SQL+XSS injection attack test
- }
- require '../main.inc.php';
- require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
- require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
- require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
- require_once DOL_DOCUMENT_ROOT.'/core/lib/modulebuilder.lib.php';
- require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
- require_once DOL_DOCUMENT_ROOT.'/core/class/utils.class.php';
- // Load translation files required by the page
- $langs->loadLangs(array("admin", "modulebuilder", "other", "cron", "errors"));
- $action = GETPOST('action', 'aZ09');
- $confirm = GETPOST('confirm', 'alpha');
- $cancel = GETPOST('cancel', 'alpha');
- $sortfield = '';
- $sortorder = '';
- $module = GETPOST('module', 'alpha');
- $tab = GETPOST('tab', 'aZ09');
- $tabobj = GETPOST('tabobj', 'alpha');
- $propertykey = GETPOST('propertykey', 'alpha');
- if (empty($module)) {
- $module = 'initmodule';
- }
- if (empty($tab)) {
- $tab = 'description';
- }
- if (empty($tabobj)) {
- $tabobj = 'newobjectifnoobj';
- }
- $file = GETPOST('file', 'alpha');
- $modulename = dol_sanitizeFileName(GETPOST('modulename', 'alpha'));
- $objectname = dol_sanitizeFileName(GETPOST('objectname', 'alpha'));
- // Security check
- if (empty($conf->modulebuilder->enabled)) {
- accessforbidden();
- }
- if (!$user->admin && empty($conf->global->MODULEBUILDER_FOREVERYONE)) {
- accessforbidden($langs->trans('ModuleBuilderNotAllowed'));
- }
- // Dir for custom dirs
- $tmp = explode(',', $dolibarr_main_document_root_alt);
- $dirins = $tmp[0];
- $dirread = $dirins;
- $forceddirread = 0;
- $tmpdir = explode('@', $module);
- if (!empty($tmpdir[1])) {
- $module = $tmpdir[0];
- $dirread = $tmpdir[1];
- $forceddirread = 1;
- }
- if (GETPOST('dirins', 'alpha')) {
- $dirread = $dirins = GETPOST('dirins', 'alpha');
- $forceddirread = 1;
- }
- $FILEFLAG = 'modulebuilder.txt';
- $now = dol_now();
- $newmask = 0;
- if (empty($newmask) && !empty($conf->global->MAIN_UMASK)) {
- $newmask = $conf->global->MAIN_UMASK;
- }
- if (empty($newmask)) { // This should no happen
- $newmask = '0664';
- }
- $result = restrictedArea($user, 'modulebuilder', null);
- $error = 0;
- $form = new Form($db);
- // Define $listofmodules
- $dirsrootforscan = array($dirread);
- // Add also the core modules into the list of modules to show/edit
- if ($dirread != DOL_DOCUMENT_ROOT && ($conf->global->MAIN_FEATURES_LEVEL >= 2 || !empty($conf->global->MODULEBUILDER_ADD_DOCUMENT_ROOT))) {
- $dirsrootforscan[] = DOL_DOCUMENT_ROOT;
- }
- // Search modules to edit
- $textforlistofdirs = '<!-- Directory scanned -->'."\n";
- $listofmodules = array();
- $i = 0;
- foreach ($dirsrootforscan as $dirread) {
- $moduletype = 'external';
- if ($dirread == DOL_DOCUMENT_ROOT) {
- $moduletype = 'internal';
- }
- $dirsincustom = dol_dir_list($dirread, 'directories');
- if (is_array($dirsincustom) && count($dirsincustom) > 0) {
- foreach ($dirsincustom as $dircustomcursor) {
- $fullname = $dircustomcursor['fullname'];
- if (dol_is_file($fullname.'/'.$FILEFLAG)) {
- // Get real name of module (MyModule instead of mymodule)
- $dirtoscanrel = basename($fullname).'/core/modules/';
- $descriptorfiles = dol_dir_list(dirname($fullname).'/'.$dirtoscanrel, 'files', 0, 'mod.*\.class\.php$');
- if (empty($descriptorfiles)) { // If descriptor not found into module dir, we look into main module dir.
- $dirtoscanrel = 'core/modules/';
- $descriptorfiles = dol_dir_list($fullname.'/../'.$dirtoscanrel, 'files', 0, 'mod'.strtoupper(basename($fullname)).'\.class\.php$');
- }
- $modulenamewithcase = '';
- $moduledescriptorrelpath = '';
- $moduledescriptorfullpath = '';
- foreach ($descriptorfiles as $descriptorcursor) {
- $modulenamewithcase = preg_replace('/^mod/', '', $descriptorcursor['name']);
- $modulenamewithcase = preg_replace('/\.class\.php$/', '', $modulenamewithcase);
- $moduledescriptorrelpath = $dirtoscanrel.$descriptorcursor['name'];
- $moduledescriptorfullpath = $descriptorcursor['fullname'];
- //var_dump($descriptorcursor);
- }
- if ($modulenamewithcase) {
- $listofmodules[$dircustomcursor['name']] = array(
- 'modulenamewithcase'=>$modulenamewithcase,
- 'moduledescriptorrelpath'=> $moduledescriptorrelpath,
- 'moduledescriptorfullpath'=>$moduledescriptorfullpath,
- 'moduledescriptorrootpath'=>$dirread,
- 'moduletype'=>$moduletype
- );
- }
- //var_dump($listofmodules);
- }
- }
- }
- if ($forceddirread && empty($listofmodules)) { // $forceddirread is 1 if we forced dir to read with dirins=... or with module=...@mydir
- $listofmodules[strtolower($module)] = array(
- 'modulenamewithcase'=>$module,
- 'moduledescriptorrelpath'=> 'notyetimplemented',
- 'moduledescriptorfullpath'=> 'notyetimplemented',
- 'moduledescriptorrootpath'=> 'notyetimplemented',
- );
- }
- // Show description of content
- $newdircustom = $dirins;
- if (empty($newdircustom)) {
- $newdircustom = img_warning();
- }
- // If dirread was forced to somewhere else, by using URL
- // htdocs/modulebuilder/index.php?module=Inventory@/home/ldestailleur/git/dolibarr/htdocs/product
- if (empty($i)) {
- $textforlistofdirs .= $langs->trans("DirScanned").' : ';
- } else {
- $textforlistofdirs .= ', ';
- }
- $textforlistofdirs .= '<strong class="wordbreakimp">'.$dirread.'</strong>';
- if ($dirread == DOL_DOCUMENT_ROOT) {
- if ($conf->global->MAIN_FEATURES_LEVEL >= 2) {
- $textforlistofdirs .= $form->textwithpicto('', $langs->trans("ConstantIsOn", "MAIN_FEATURES_LEVEL"));
- }
- if (!empty($conf->global->MODULEBUILDER_ADD_DOCUMENT_ROOT)) {
- $textforlistofdirs .= $form->textwithpicto('', $langs->trans("ConstantIsOn", "MODULEBUILDER_ADD_DOCUMENT_ROOT"));
- }
- }
- $i++;
- }
- /*
- * Actions
- */
- if ($dirins && $action == 'initmodule' && $modulename) {
- $modulename = ucfirst($modulename); // Force first letter in uppercase
- if (preg_match('/[^a-z0-9_]/i', $modulename)) {
- $error++;
- setEventMessages($langs->trans("SpaceOrSpecialCharAreNotAllowed"), null, 'errors');
- }
- if (!$error) {
- $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
- $destdir = $dirins.'/'.strtolower($modulename);
- $arrayreplacement = array(
- 'mymodule'=>strtolower($modulename),
- 'MyModule'=>$modulename
- );
- $result = dolCopyDir($srcdir, $destdir, 0, 0, $arrayreplacement);
- //dol_mkdir($destfile);
- if ($result <= 0) {
- if ($result < 0) {
- $error++;
- $langs->load("errors");
- setEventMessages($langs->trans("ErrorFailToCopyDir", $srcdir, $destdir), null, 'errors');
- } else {
- // $result == 0
- setEventMessages($langs->trans("AllFilesDidAlreadyExist", $srcdir, $destdir), null, 'warnings');
- }
- }
- if (!empty($conf->global->MODULEBUILDER_USE_ABOUT)) {
- dol_delete_file($destdir.'/admin/about.php');
- }
- // Delete dir and files that can be generated in sub tabs later if we need them (we want a minimal module first)
- dol_delete_dir_recursive($destdir.'/build/doxygen');
- dol_delete_dir_recursive($destdir.'/core/modules/mailings');
- dol_delete_dir_recursive($destdir.'/core/modules/'.strtolower($modulename).'');
- dol_delete_dir_recursive($destdir.'/core/tpl');
- dol_delete_dir_recursive($destdir.'/core/triggers');
- dol_delete_dir_recursive($destdir.'/doc');
- //dol_delete_dir_recursive($destdir.'/.tx');
- dol_delete_dir_recursive($destdir.'/core/boxes');
- dol_delete_file($destdir.'/admin/myobject_extrafields.php');
- dol_delete_file($destdir.'/sql/data.sql');
- dol_delete_file($destdir.'/sql/update_x.x.x-y.y.y.sql');
- dol_delete_file($destdir.'/class/actions_'.strtolower($modulename).'.class.php');
- dol_delete_file($destdir.'/class/api_'.strtolower($modulename).'.class.php');
- dol_delete_file($destdir.'/css/'.strtolower($modulename).'.css.php');
- dol_delete_file($destdir.'/js/'.strtolower($modulename).'.js.php');
- dol_delete_file($destdir.'/scripts/'.strtolower($modulename).'.php');
- dol_delete_file($destdir.'/test/phpunit/MyModuleFunctionnalTest.php');
- // Delete some files related to Object (because the previous dolCopyDir has copied everything)
- dol_delete_file($destdir.'/myobject_card.php');
- dol_delete_file($destdir.'/myobject_contact.php');
- dol_delete_file($destdir.'/myobject_note.php');
- dol_delete_file($destdir.'/myobject_document.php');
- dol_delete_file($destdir.'/myobject_agenda.php');
- dol_delete_file($destdir.'/myobject_list.php');
- dol_delete_file($destdir.'/lib/'.strtolower($modulename).'_myobject.lib.php');
- dol_delete_file($destdir.'/test/phpunit/MyObjectTest.php');
- dol_delete_file($destdir.'/sql/llx_'.strtolower($modulename).'_myobject.sql');
- dol_delete_file($destdir.'/sql/llx_'.strtolower($modulename).'_myobject_extrafields.sql');
- dol_delete_file($destdir.'/sql/llx_'.strtolower($modulename).'_myobject.key.sql');
- dol_delete_file($destdir.'/sql/llx_'.strtolower($modulename).'_myobject_extrafields.key.sql');
- dol_delete_file($destdir.'/img/object_myobject.png');
- dol_delete_file($destdir.'/class/myobject.class.php');
- dol_delete_dir($destdir.'/class', 1);
- dol_delete_dir($destdir.'/sql', 1);
- dol_delete_dir($destdir.'/scripts', 1);
- dol_delete_dir($destdir.'/js', 1);
- dol_delete_dir($destdir.'/css', 1);
- dol_delete_dir($destdir.'/test/phpunit', 1);
- dol_delete_dir($destdir.'/test', 1);
- }
- // Edit PHP files
- if (!$error) {
- $listofphpfilestoedit = dol_dir_list($destdir, 'files', 1, '\.(php|MD|js|sql|txt|xml|lang)$', '', 'fullname', SORT_ASC, 0, 1);
- foreach ($listofphpfilestoedit as $phpfileval) {
- //var_dump($phpfileval['fullname']);
- $arrayreplacement = array(
- 'mymodule'=>strtolower($modulename),
- 'MyModule'=>$modulename,
- 'MYMODULE'=>strtoupper($modulename),
- 'My module'=>$modulename,
- 'my module'=>$modulename,
- 'Mon module'=>$modulename,
- 'mon module'=>$modulename,
- 'htdocs/modulebuilder/template'=>strtolower($modulename),
- '---Put here your own copyright and developer email---'=>dol_print_date($now, '%Y').' '.$user->getFullName($langs).($user->email ? ' <'.$user->email.'>' : '')
- );
- if ($conf->global->MAIN_FEATURES_LEVEL >= 2) {
- if (!empty($conf->global->MODULEBUILDER_SPECIFIC_EDITOR_NAME)) {
- $arrayreplacement['Editor name'] = $conf->global->MODULEBUILDER_SPECIFIC_EDITOR_NAME;
- }
- if (!empty($conf->global->MODULEBUILDER_SPECIFIC_EDITOR_URL)) {
- $arrayreplacement['https://www.example.com'] = $conf->global->MODULEBUILDER_SPECIFIC_EDITOR_URL;
- }
- if (!empty($conf->global->MODULEBUILDER_SPECIFIC_AUTHOR)) {
- $arrayreplacement['---Put here your own copyright and developer email---'] = dol_print_date($now, '%Y').' '.$conf->global->MODULEBUILDER_SPECIFIC_AUTHOR;
- }
- if (!empty($conf->global->MODULEBUILDER_SPECIFIC_VERSION)) {
- $arrayreplacement['1.0'] = $conf->global->MODULEBUILDER_SPECIFIC_VERSION;
- }
- if (!empty($conf->global->MODULEBUILDER_SPECIFIC_FAMILY)) {
- $arrayreplacement['other'] = $conf->global->MODULEBUILDER_SPECIFIC_FAMILY;
- }
- }
- $result = dolReplaceInFile($phpfileval['fullname'], $arrayreplacement);
- //var_dump($result);
- if ($result < 0) {
- setEventMessages($langs->trans("ErrorFailToMakeReplacementInto", $phpfileval['fullname']), null, 'errors');
- }
- }
- if (!empty($conf->global->MODULEBUILDER_SPECIFIC_README)) {
- setEventMessages($langs->trans("ContentOfREADMECustomized"), null, 'warnings');
- dol_delete_file($destdir.'/README.md');
- file_put_contents($destdir.'/README.md', $conf->global->MODULEBUILDER_SPECIFIC_README);
- }
- }
- if (!$error) {
- setEventMessages('ModuleInitialized', null);
- $module = $modulename;
- $modulename = '';
- clearstatcache(true);
- if (function_exists('opcache_invalidate')) {
- opcache_reset(); // remove the include cache hell !
- }
- header("Location: ".$_SERVER["PHP_SELF"].'?module='.$modulename);
- exit;
- }
- }
- // init API
- if ($dirins && $action == 'initapi' && !empty($module)) {
- $modulename = ucfirst($module); // Force first letter in uppercase
- $objectname = $tabobj;
- dol_mkdir($dirins.'/'.strtolower($module).'/class');
- $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
- $srcfile = $srcdir.'/class/api_mymodule.class.php';
- $destfile = $dirins.'/'.strtolower($module).'/class/api_'.strtolower($module).'.class.php';
- //var_dump($srcfile);var_dump($destfile);
- $result = dol_copy($srcfile, $destfile, 0, 0);
- if ($result > 0) {
- //var_dump($phpfileval['fullname']);
- $arrayreplacement = array(
- 'mymodule'=>strtolower($modulename),
- 'MyModule'=>$modulename,
- 'MYMODULE'=>strtoupper($modulename),
- 'My module'=>$modulename,
- 'my module'=>$modulename,
- 'Mon module'=>$modulename,
- 'mon module'=>$modulename,
- 'htdocs/modulebuilder/template'=>strtolower($modulename),
- 'myobject'=>strtolower($objectname),
- 'MyObject'=>$objectname,
- 'MYOBJECT'=>strtoupper($objectname),
- '---Put here your own copyright and developer email---'=>dol_print_date($now, '%Y').' '.$user->getFullName($langs).($user->email ? ' <'.$user->email.'>' : '')
- );
- dolReplaceInFile($destfile, $arrayreplacement);
- } else {
- $langs->load("errors");
- setEventMessages($langs->trans('ErrorFailToCreateFile', $destfile), null, 'errors');
- }
- }
- // init PHPUnit
- if ($dirins && $action == 'initphpunit' && !empty($module)) {
- $modulename = ucfirst($module); // Force first letter in uppercase
- $objectname = $tabobj;
- dol_mkdir($dirins.'/'.strtolower($module).'/test/phpunit');
- $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
- $srcfile = $srcdir.'/test/phpunit/MyObjectTest.php';
- $destfile = $dirins.'/'.strtolower($module).'/test/phpunit/'.strtolower($objectname).'Test.php';
- $result = dol_copy($srcfile, $destfile, 0, 0);
- if ($result > 0) {
- //var_dump($phpfileval['fullname']);
- $arrayreplacement = array(
- 'mymodule'=>strtolower($modulename),
- 'MyModule'=>$modulename,
- 'MYMODULE'=>strtoupper($modulename),
- 'My module'=>$modulename,
- 'my module'=>$modulename,
- 'Mon module'=>$modulename,
- 'mon module'=>$modulename,
- 'htdocs/modulebuilder/template'=>strtolower($modulename),
- 'myobject'=>strtolower($objectname),
- 'MyObject'=>$objectname,
- 'MYOBJECT'=>strtoupper($objectname),
- '---Put here your own copyright and developer email---'=>dol_print_date($now, '%Y').' '.$user->getFullName($langs).($user->email ? ' <'.$user->email.'>' : '')
- );
- dolReplaceInFile($destfile, $arrayreplacement);
- } else {
- $langs->load("errors");
- setEventMessages($langs->trans('ErrorFailToCreateFile', $destfile), null, 'errors');
- }
- }
- // init ExtraFields
- if ($dirins && $action == 'initsqlextrafields' && !empty($module)) {
- $modulename = ucfirst($module); // Force first letter in uppercase
- $objectname = $tabobj;
- dol_mkdir($dirins.'/'.strtolower($module).'/sql');
- $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
- $srcfile1 = $srcdir.'/sql/llx_mymodule_myobject_extrafields.sql';
- $destfile1 = $dirins.'/'.strtolower($module).'/sql/llx_'.strtolower($module).'_'.strtolower($objectname).'_extrafields.sql';
- //var_dump($srcfile);var_dump($destfile);
- $result1 = dol_copy($srcfile1, $destfile1, 0, 0);
- $srcfile2 = $srcdir.'/sql/llx_mymodule_myobject_extrafields.key.sql';
- $destfile2 = $dirins.'/'.strtolower($module).'/sql/llx_'.strtolower($module).'_'.strtolower($objectname).'_extrafields.key.sql';
- //var_dump($srcfile);var_dump($destfile);
- $result2 = dol_copy($srcfile2, $destfile2, 0, 0);
- if ($result1 > 0 && $result2 > 0) {
- $modulename = ucfirst($module); // Force first letter in uppercase
- //var_dump($phpfileval['fullname']);
- $arrayreplacement = array(
- 'mymodule'=>strtolower($modulename),
- 'MyModule'=>$modulename,
- 'MYMODULE'=>strtoupper($modulename),
- 'My module'=>$modulename,
- 'my module'=>$modulename,
- 'Mon module'=>$modulename,
- 'mon module'=>$modulename,
- 'htdocs/modulebuilder/template'=>strtolower($modulename),
- 'My Object'=>$objectname,
- 'MyObject'=>$objectname,
- 'my object'=>strtolower($objectname),
- 'myobject'=>strtolower($objectname),
- '---Put here your own copyright and developer email---'=>dol_print_date($now, '%Y').' '.$user->getFullName($langs).($user->email ? ' <'.$user->email.'>' : '')
- );
- dolReplaceInFile($destfile1, $arrayreplacement);
- dolReplaceInFile($destfile2, $arrayreplacement);
- } else {
- $langs->load("errors");
- setEventMessages($langs->trans('ErrorFailToCreateFile', ''), null, 'errors');
- }
- // TODO Enable in class the property $isextrafieldmanaged = 1
- }
- // init Hook
- if ($dirins && $action == 'inithook' && !empty($module)) {
- dol_mkdir($dirins.'/'.strtolower($module).'/class');
- $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
- $srcfile = $srcdir.'/class/actions_mymodule.class.php';
- $destfile = $dirins.'/'.strtolower($module).'/class/actions_'.strtolower($module).'.class.php';
- //var_dump($srcfile);var_dump($destfile);
- $result = dol_copy($srcfile, $destfile, 0, 0);
- if ($result > 0) {
- $modulename = ucfirst($module); // Force first letter in uppercase
- //var_dump($phpfileval['fullname']);
- $arrayreplacement = array(
- 'mymodule'=>strtolower($modulename),
- 'MyModule'=>$modulename,
- 'MYMODULE'=>strtoupper($modulename),
- 'My module'=>$modulename,
- 'my module'=>$modulename,
- 'Mon module'=>$modulename,
- 'mon module'=>$modulename,
- 'htdocs/modulebuilder/template'=>strtolower($modulename),
- '---Put here your own copyright and developer email---'=>dol_print_date($now, '%Y').' '.$user->getFullName($langs).($user->email ? ' <'.$user->email.'>' : '')
- );
- dolReplaceInFile($destfile, $arrayreplacement);
- } else {
- $langs->load("errors");
- setEventMessages($langs->trans('ErrorFailToCreateFile', $destfile), null, 'errors');
- }
- }
- // init Trigger
- if ($dirins && $action == 'inittrigger' && !empty($module)) {
- dol_mkdir($dirins.'/'.strtolower($module).'/core/triggers');
- $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
- $srcfile = $srcdir.'/core/triggers/interface_99_modMyModule_MyModuleTriggers.class.php';
- $destfile = $dirins.'/'.strtolower($module).'/core/triggers/interface_99_mod'.$module.'_'.$module.'Triggers.class.php';
- //var_dump($srcfile);var_dump($destfile);
- $result = dol_copy($srcfile, $destfile, 0, 0);
- if ($result > 0) {
- $modulename = ucfirst($module); // Force first letter in uppercase
- //var_dump($phpfileval['fullname']);
- $arrayreplacement = array(
- 'mymodule'=>strtolower($modulename),
- 'MyModule'=>$modulename,
- 'MYMODULE'=>strtoupper($modulename),
- 'My module'=>$modulename,
- 'my module'=>$modulename,
- 'Mon module'=>$modulename,
- 'mon module'=>$modulename,
- 'htdocs/modulebuilder/template'=>strtolower($modulename),
- '---Put here your own copyright and developer email---'=>dol_print_date($now, '%Y').' '.$user->getFullName($langs).($user->email ? ' <'.$user->email.'>' : '')
- );
- dolReplaceInFile($destfile, $arrayreplacement);
- } else {
- $langs->load("errors");
- setEventMessages($langs->trans('ErrorFailToCreateFile', $destfile), null, 'errors');
- }
- }
- // init Widget
- if ($dirins && $action == 'initwidget' && !empty($module)) {
- dol_mkdir($dirins.'/'.strtolower($module).'/core/boxes');
- $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
- $srcfile = $srcdir.'/core/boxes/mymodulewidget1.php';
- $destfile = $dirins.'/'.strtolower($module).'/core/boxes/'.strtolower($module).'widget1.php';
- //var_dump($srcfile);var_dump($destfile);
- $result = dol_copy($srcfile, $destfile, 0, 0);
- if ($result > 0) {
- $modulename = ucfirst($module); // Force first letter in uppercase
- //var_dump($phpfileval['fullname']);
- $arrayreplacement = array(
- 'mymodule'=>strtolower($modulename),
- 'MyModule'=>$modulename,
- 'MYMODULE'=>strtoupper($modulename),
- 'My module'=>$modulename,
- 'my module'=>$modulename,
- 'Mon module'=>$modulename,
- 'mon module'=>$modulename,
- 'htdocs/modulebuilder/template'=>strtolower($modulename),
- '---Put here your own copyright and developer email---'=>dol_print_date($now, '%Y').' '.$user->getFullName($langs).($user->email ? ' <'.$user->email.'>' : '')
- );
- dolReplaceInFile($destfile, $arrayreplacement);
- } else {
- $langs->load("errors");
- setEventMessages($langs->trans('ErrorFailToCreateFile', $destfile), null, 'errors');
- }
- }
- // init CSS
- if ($dirins && $action == 'initcss' && !empty($module)) {
- dol_mkdir($dirins.'/'.strtolower($module).'/css');
- $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
- $srcfile = $srcdir.'/css/mymodule.css.php';
- $destfile = $dirins.'/'.strtolower($module).'/css/'.strtolower($module).'.css.php';
- //var_dump($srcfile);var_dump($destfile);
- $result = dol_copy($srcfile, $destfile, 0, 0);
- if ($result > 0) {
- $modulename = ucfirst($module); // Force first letter in uppercase
- //var_dump($phpfileval['fullname']);
- $arrayreplacement = array(
- 'mymodule'=>strtolower($modulename),
- 'MyModule'=>$modulename,
- 'MYMODULE'=>strtoupper($modulename),
- 'My module'=>$modulename,
- 'my module'=>$modulename,
- 'Mon module'=>$modulename,
- 'mon module'=>$modulename,
- 'htdocs/modulebuilder/template'=>strtolower($modulename),
- '---Put here your own copyright and developer email---'=>dol_print_date($now, '%Y').' '.$user->getFullName($langs).($user->email ? ' <'.$user->email.'>' : ''),
- );
- dolReplaceInFile($destfile, $arrayreplacement);
- // Update descriptor file to uncomment file
- $srcfile = $dirins.'/'.strtolower($module).'/core/modules/mod'.$module.'.class.php';
- $arrayreplacement = array('/\/\/\s*\''.preg_quote('/'.strtolower($module).'/css/'.strtolower($module).'.css.php', '/').'\'/' => '\'/'.strtolower($module).'/css/'.strtolower($module).'.css.php\'');
- dolReplaceInFile($srcfile, $arrayreplacement, '', 0, 0, 1);
- } else {
- $langs->load("errors");
- setEventMessages($langs->trans('ErrorFailToCreateFile', $destfile), null, 'errors');
- }
- }
- // init JS
- if ($dirins && $action == 'initjs' && !empty($module)) {
- dol_mkdir($dirins.'/'.strtolower($module).'/js');
- $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
- $srcfile = $srcdir.'/js/mymodule.js.php';
- $destfile = $dirins.'/'.strtolower($module).'/js/'.strtolower($module).'.js.php';
- //var_dump($srcfile);var_dump($destfile);
- $result = dol_copy($srcfile, $destfile, 0, 0);
- if ($result > 0) {
- $modulename = ucfirst($module); // Force first letter in uppercase
- //var_dump($phpfileval['fullname']);
- $arrayreplacement = array(
- 'mymodule'=>strtolower($modulename),
- 'MyModule'=>$modulename,
- 'MYMODULE'=>strtoupper($modulename),
- 'My module'=>$modulename,
- 'my module'=>$modulename,
- 'Mon module'=>$modulename,
- 'mon module'=>$modulename,
- 'htdocs/modulebuilder/template'=>strtolower($modulename),
- '---Put here your own copyright and developer email---'=>dol_print_date($now, '%Y').' '.$user->getFullName($langs).($user->email ? ' <'.$user->email.'>' : '')
- );
- dolReplaceInFile($destfile, $arrayreplacement);
- // Update descriptor file to uncomment file
- $srcfile = $dirins.'/'.strtolower($module).'/core/modules/mod'.$module.'.class.php';
- $arrayreplacement = array('/\/\/\s*\''.preg_quote('/'.strtolower($module).'/js/'.strtolower($module).'.js.php', '/').'\'/' => '\'/'.strtolower($module).'/js/'.strtolower($module).'.js.php\'');
- dolReplaceInFile($srcfile, $arrayreplacement, '', 0, 0, 1);
- } else {
- $langs->load("errors");
- setEventMessages($langs->trans('ErrorFailToCreateFile', $destfile), null, 'errors');
- }
- }
- // init CLI
- if ($dirins && $action == 'initcli' && !empty($module)) {
- dol_mkdir($dirins.'/'.strtolower($module).'/scripts');
- $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
- $srcfile = $srcdir.'/scripts/mymodule.php';
- $destfile = $dirins.'/'.strtolower($module).'/scripts/'.strtolower($module).'.php';
- //var_dump($srcfile);var_dump($destfile);
- $result = dol_copy($srcfile, $destfile, 0, 0);
- if ($result > 0) {
- $modulename = ucfirst($module); // Force first letter in uppercase
- //var_dump($phpfileval['fullname']);
- $arrayreplacement = array(
- 'mymodule'=>strtolower($modulename),
- 'MyModule'=>$modulename,
- 'MYMODULE'=>strtoupper($modulename),
- 'My module'=>$modulename,
- 'my module'=>$modulename,
- 'Mon module'=>$modulename,
- 'mon module'=>$modulename,
- 'htdocs/modulebuilder/template'=>strtolower($modulename),
- '__MYCOMPANY_NAME__'=>$mysoc->name,
- '__KEYWORDS__'=>$modulename,
- '__USER_FULLNAME__'=>$user->getFullName($langs),
- '__USER_EMAIL__'=>$user->email,
- '__YYYY-MM-DD__'=>dol_print_date($now, 'dayrfc'),
- '---Put here your own copyright and developer email---'=>dol_print_date($now, 'dayrfc').' '.$user->getFullName($langs).($user->email ? ' <'.$user->email.'>' : '')
- );
- dolReplaceInFile($destfile, $arrayreplacement);
- } else {
- $langs->load("errors");
- setEventMessages($langs->trans('ErrorFailToCreateFile', $destfile), null, 'errors');
- }
- }
- // init Doc
- if ($dirins && $action == 'initdoc' && !empty($module)) {
- dol_mkdir($dirins.'/'.strtolower($module).'/doc');
- $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
- $srcfile = $srcdir.'/doc/Documentation.asciidoc';
- $destfile = $dirins.'/'.strtolower($module).'/doc/Documentation.asciidoc';
- //var_dump($srcfile);var_dump($destfile);
- $result = dol_copy($srcfile, $destfile, 0, 0);
- if ($result > 0) {
- $modulename = ucfirst($module); // Force first letter in uppercase
- $modulelowercase = strtolower($module);
- //var_dump($phpfileval['fullname']);
- $arrayreplacement = array(
- 'mymodule'=>strtolower($modulename),
- 'MyModule'=>$modulename,
- 'MYMODULE'=>strtoupper($modulename),
- 'My module'=>$modulename,
- 'my module'=>$modulename,
- 'Mon module'=>$modulename,
- 'mon module'=>$modulename,
- 'htdocs/modulebuilder/template'=>strtolower($modulename),
- '__MYCOMPANY_NAME__'=>$mysoc->name,
- '__KEYWORDS__'=>$modulename,
- '__USER_FULLNAME__'=>$user->getFullName($langs),
- '__USER_EMAIL__'=>$user->email,
- '__YYYY-MM-DD__'=>dol_print_date($now, 'dayrfc'),
- '---Put here your own copyright and developer email---'=>dol_print_date($now, 'dayrfc').' '.$user->getFullName($langs).($user->email ? ' <'.$user->email.'>' : '')
- );
- dolReplaceInFile($destfile, $arrayreplacement);
- // Delete old documentation files
- $FILENAMEDOC = $modulelowercase.'.html';
- $FILENAMEDOCPDF = $modulelowercase.'.pdf';
- $outputfiledoc = dol_buildpath($modulelowercase, 0).'/doc/'.$FILENAMEDOC;
- $outputfiledocurl = dol_buildpath($modulelowercase, 1).'/doc/'.$FILENAMEDOC;
- $outputfiledocpdf = dol_buildpath($modulelowercase, 0).'/doc/'.$FILENAMEDOCPDF;
- $outputfiledocurlpdf = dol_buildpath($modulelowercase, 1).'/doc/'.$FILENAMEDOCPDF;
- dol_delete_file($outputfiledoc, 0, 0, 0, null, false, 0);
- dol_delete_file($outputfiledocpdf, 0, 0, 0, null, false, 0);
- } else {
- $langs->load("errors");
- setEventMessages($langs->trans('ErrorFailToCreateFile', $destfile), null, 'errors');
- }
- }
- // add Language
- if ($dirins && $action == 'addlanguage' && !empty($module)) {
- $newlangcode = GETPOST('newlangcode', 'aZ09');
- if ($newlangcode) {
- $modulelowercase = strtolower($module);
- // Dir for module
- $diroflang = dol_buildpath($modulelowercase, 0);
- if ($diroflang == $dolibarr_main_document_root.'/'.$modulelowercase) {
- // This is not a custom module, we force diroflang to htdocs root
- $diroflang = $dolibarr_main_document_root;
- $srcfile = $diroflang.'/langs/en_US/'.$modulelowercase.'.lang';
- $destfile = $diroflang.'/langs/'.$newlangcode.'/'.$modulelowercase.'.lang';
- $result = dol_copy($srcfile, $destfile, 0, 0);
- if ($result < 0) {
- setEventMessages($langs->trans("ErrorFailToCopyFile", $srcfile, $destfile), null, 'errors');
- }
- } else {
- $srcfile = $diroflang.'/langs/en_US';
- $destfile = $diroflang.'/langs/'.$newlangcode;
- $result = dolCopyDir($srcfile, $destfile, 0, 0);
- }
- } else {
- setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Language")), null, 'errors');
- }
- }
- // remove/delete File
- if ($dirins && $action == 'confirm_removefile' && !empty($module)) {
- $relativefilename = dol_sanitizePathName(GETPOST('file', 'restricthtml'));
- if ($relativefilename) {
- $dirnametodelete = dirname($relativefilename);
- $filetodelete = $dirins.'/'.$relativefilename;
- $dirtodelete = $dirins.'/'.$dirnametodelete;
- $result = dol_delete_file($filetodelete);
- if (!$result) {
- setEventMessages($langs->trans("ErrorFailToDeleteFile", basename($filetodelete)), null, 'errors');
- } else {
- if (dol_is_dir_empty($dirtodelete)) {
- dol_delete_dir($dirtodelete);
- }
- // Update descriptor file to comment file
- if (in_array($tab, array('css', 'js'))) {
- $srcfile = $dirins.'/'.strtolower($module).'/core/modules/mod'.$module.'.class.php';
- $arrayreplacement = array('/^\s*\''.preg_quote('/'.$relativefilename, '/').'\',*/m'=>' // \'/'.$relativefilename.'\',');
- dolReplaceInFile($srcfile, $arrayreplacement, '', 0, 0, 1);
- }
- }
- }
- }
- // Build the $fields array from SQL table (initfromtablename)
- if ($dirins && $action == 'initobject' && $module && GETPOST('createtablearray', 'alpha')) {
- $tablename = GETPOST('initfromtablename', 'alpha');
- $_results = $db->DDLDescTable($tablename);
- if (empty($_results)) {
- setEventMessages($langs->trans("ErrorTableNotFound", $tablename), null, 'errors');
- } else {
- /**
- * 'type' if the field format ('integer', 'integer:Class:pathtoclass', 'varchar(x)', 'double(24,8)', 'text', 'html', 'datetime', 'timestamp', 'float')
- * 'label' the translation key.
- * 'enabled' is a condition when the field must be managed.
- * '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)
- * 'noteditable' says if field is not editable (1 or 0)
- * 'notnull' is set to 1 if not null in database. Set to -1 if we must set data to null if empty ('' or 0).
- * 'default' is a default value for creation (can still be replaced by the global setup of default values)
- * 'index' if we want an index in database.
- * 'foreignkey'=>'tablename.field' if the field is a foreign key (it is recommanded to name the field fk_...).
- * 'position' is the sort order of field.
- * 'searchall' is 1 if we want to search in this field when making a search from the quick search button.
- * '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).
- * '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'
- * 'help' is a string visible as a tooltip on field
- * 'comment' is not used. You can store here any text of your choice. It is not used by application.
- * 'showoncombobox' if value of the field must be visible into the label of the combobox that list record
- * 'arrayofkeyval' to set list of value if type is a list of predefined values. For example: array("0"=>"Draft","1"=>"Active","-1"=>"Cancel")
- */
- /*public $fields=array(
- 'rowid' =>array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'index'=>1, 'position'=>1, 'comment'=>'Id'),
- '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'),
- 'entity' =>array('type'=>'integer', 'label'=>'Entity', 'enabled'=>1, 'visible'=>0, 'default'=>1, 'notnull'=>1, 'index'=>1, 'position'=>20),
- 'label' =>array('type'=>'varchar(255)', 'label'=>'Label', 'enabled'=>1, 'visible'=>1, 'position'=>30, 'searchall'=>1, 'css'=>'minwidth200', 'help'=>'Help text'),
- 'amount' =>array('type'=>'double(24,8)', 'label'=>'Amount', 'enabled'=>1, 'visible'=>1, 'default'=>'null', 'position'=>40, 'searchall'=>0, 'isameasure'=>1, 'help'=>'Help text'),
- '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'),
- 'description' =>array('type'=>'text', 'label'=>'Descrption', 'enabled'=>1, 'visible'=>0, 'position'=>60),
- 'note_public' =>array('type'=>'html', 'label'=>'NotePublic', 'enabled'=>1, 'visible'=>0, 'position'=>61),
- 'note_private' =>array('type'=>'html', 'label'=>'NotePrivate', 'enabled'=>1, 'visible'=>0, 'position'=>62),
- 'date_creation' =>array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>500),
- 'tms' =>array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>501),
- //'date_valid' =>array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-2, 'position'=>502),
- 'fk_user_creat' =>array('type'=>'integer', 'label'=>'UserAuthor', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>510),
- 'fk_user_modif' =>array('type'=>'integer', 'label'=>'UserModif', 'enabled'=>1, 'visible'=>-2, 'notnull'=>-1, 'position'=>511),
- //'fk_user_valid' =>array('type'=>'integer', 'label'=>'UserValidation', 'enabled'=>1, 'visible'=>-1, 'position'=>512),
- 'import_key' =>array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>1, 'visible'=>-2, 'notnull'=>-1, 'index'=>0, 'position'=>1000),
- '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')),
- );*/
- $string = 'public $fields=array('."\n";
- $string .= "<br>";
- $i = 10;
- while ($obj = $db->fetch_object($_results)) {
- // fieldname
- $fieldname = $obj->Field;
- // type
- $type = $obj->Type;
- if ($type == 'int(11)') {
- $type = 'integer';
- }
- if ($type == 'float') {
- $type = 'real';
- }
- if (strstr($type, 'tinyint')) {
- $type = 'integer';
- }
- if ($obj->Field == 'fk_soc') {
- $type = 'integer:Societe:societe/class/societe.class.php';
- }
- if (preg_match('/^fk_proj/', $obj->Field)) {
- $type = 'integer:Project:projet/class/project.class.php:1:fk_statut=1';
- }
- if (preg_match('/^fk_prod/', $obj->Field)) {
- $type = 'integer:Product:product/class/product.class.php:1';
- }
- if ($obj->Field == 'fk_warehouse') {
- $type = 'integer:Entrepot:product/stock/class/entrepot.class.php';
- }
- if (preg_match('/^(fk_user|fk_commercial)/', $obj->Field)) {
- $type = 'integer:User:user/class/user.class.php';
- }
- // notnull
- $notnull = ($obj->Null == 'YES' ? 0 : 1);
- if ($fieldname == 'fk_user_modif') {
- $notnull = -1;
- }
- // label
- $label = preg_replace('/_/', '', ucfirst($fieldname));
- if ($fieldname == 'rowid') {
- $label = 'TechnicalID';
- }
- if ($fieldname == 'import_key') {
- $label = 'ImportId';
- }
- if ($fieldname == 'fk_soc') {
- $label = 'ThirdParty';
- }
- if ($fieldname == 'tms') {
- $label = 'DateModification';
- }
- if ($fieldname == 'datec') {
- $label = 'DateCreation';
- }
- if ($fieldname == 'date_valid') {
- $label = 'DateValidation';
- }
- if ($fieldname == 'datev') {
- $label = 'DateValidation';
- }
- if ($fieldname == 'note_private') {
- $label = 'NotePublic';
- }
- if ($fieldname == 'note_public') {
- $label = 'NotePrivate';
- }
- if ($fieldname == 'fk_user_creat') {
- $label = 'UserAuthor';
- }
- if ($fieldname == 'fk_user_modif') {
- $label = 'UserModif';
- }
- if ($fieldname == 'fk_user_valid') {
- $label = 'UserValidation';
- }
- // visible
- $visible = -1;
- if ($fieldname == 'entity') {
- $visible = -2;
- }
- if ($fieldname == 'import_key') {
- $visible = -2;
- }
- if ($fieldname == 'fk_user_creat') {
- $visible = -2;
- }
- if ($fieldname == 'fk_user_modif') {
- $visible = -2;
- }
- if (in_array($fieldname, array('ref_ext', 'model_pdf', 'note_public', 'note_private'))) {
- $visible = 0;
- }
- // enabled
- $enabled = 1;
- // default
- $default = '';
- if ($fieldname == 'entity') {
- $default = 1;
- }
- // position
- $position = $i;
- if (in_array($fieldname, array('status', 'statut', 'fk_status', 'fk_statut'))) {
- $position = 500;
- }
- if ($fieldname == 'import_key') {
- $position = 900;
- }
- // index
- $index = 0;
- if ($fieldname == 'entity') {
- $index = 1;
- }
- // css
- $css = '';
- $cssview = '';
- $csslist = '';
- if (preg_match('/^fk_/', $fieldname)) {
- $css = 'maxwidth500 widthcentpercentminusxx';
- }
- if ($fieldname == 'label') {
- $css = 'minwidth300';
- $cssview = 'wordbreak';
- }
- if (in_array($fieldname, array('note_public', 'note_private'))) {
- $cssview = 'wordbreak';
- }
- $string .= "'".$obj->Field."' =>array('type'=>'".$type."', 'label'=>'".$label."',";
- if ($default != '') {
- $string .= " 'default'=>".$default.",";
- }
- $string .= " 'enabled'=>".$enabled.",";
- $string .= " 'visible'=>".$visible;
- if ($notnull) {
- $string .= ", 'notnull'=>".$notnull;
- }
- if ($fieldname == 'ref' || $fieldname == 'code') {
- $string .= ", 'showoncombobox'=>1";
- }
- $string .= ", 'position'=>".$position;
- if ($index) {
- $string .= ", 'index'=>".$index;
- }
- if ($css) {
- $string .= ", 'css'=>".$css;
- }
- if ($cssview) {
- $string .= ", 'cssview'=>".$cssview;
- }
- if ($csslist) {
- $string .= ", 'csslist'=>".$csslist;
- }
- $string .= "),\n";
- $string .= "<br>";
- $i += 5;
- }
- $string .= ');'."\n";
- $string .= "<br>";
- print $string;
- exit;
- }
- }
- if ($dirins && $action == 'initobject' && $module && $objectname) {
- $objectname = ucfirst($objectname);
- $dirins = $dirread = $listofmodules[strtolower($module)]['moduledescriptorrootpath'];
- $moduletype = $listofmodules[strtolower($module)]['moduletype'];
- if (preg_match('/[^a-z0-9_]/i', $objectname)) {
- $error++;
- setEventMessages($langs->trans("SpaceOrSpecialCharAreNotAllowed"), null, 'errors');
- $tabobj = 'newobject';
- }
- if (class_exists($objectname)) {
- // TODO Add a more efficient detection. Scan disk ?
- $error++;
- setEventMessages($langs->trans("AnObjectWithThisClassNameAlreadyExists"), null, 'errors');
- $tabobj = 'newobject';
- }
- $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
- $destdir = $dirins.'/'.strtolower($module);
- // The dir was not created by init
- dol_mkdir($destdir.'/class');
- dol_mkdir($destdir.'/img');
- dol_mkdir($destdir.'/lib');
- dol_mkdir($destdir.'/scripts');
- dol_mkdir($destdir.'/sql');
- // Scan dir class to find if an object with same name already exists.
- if (!$error) {
- $dirlist = dol_dir_list($destdir.'/class', 'files', 0, '\.txt$');
- $alreadyfound = false;
- foreach ($dirlist as $key => $val) {
- $filefound = preg_replace('/\.txt$/', '', $val['name']);
- if (strtolower($objectname) == strtolower($filefound) && $objectname != $filefound) {
- $alreadyfound = true;
- $error++;
- setEventMessages($langs->trans("AnObjectAlreadyExistWithThisNameAndDiffCase"), null, 'errors');
- break;
- }
- }
- }
- if (!$error) {
- // Copy some files
- $filetogenerate = array(
- 'myobject_card.php'=>strtolower($objectname).'_card.php',
- 'myobject_note.php'=>strtolower($objectname).'_note.php',
- 'myobject_contact.php'=>strtolower($objectname).'_contact.php',
- 'myobject_document.php'=>strtolower($objectname).'_document.php',
- 'myobject_agenda.php'=>strtolower($objectname).'_agenda.php',
- 'myobject_list.php'=>strtolower($objectname).'_list.php',
- 'admin/myobject_extrafields.php'=>'admin/'.strtolower($objectname).'_extrafields.php',
- 'lib/mymodule_myobject.lib.php'=>'lib/'.strtolower($module).'_'.strtolower($objectname).'.lib.php',
- //'test/phpunit/MyObjectTest.php'=>'test/phpunit/'.strtolower($objectname).'Test.php',
- 'sql/llx_mymodule_myobject.sql'=>'sql/llx_'.strtolower($module).'_'.strtolower($objectname).'.sql',
- 'sql/llx_mymodule_myobject.key.sql'=>'sql/llx_'.strtolower($module).'_'.strtolower($objectname).'.key.sql',
- 'sql/llx_mymodule_myobject_extrafields.sql'=>'sql/llx_'.strtolower($module).'_'.strtolower($objectname).'_extrafields.sql',
- 'sql/llx_mymodule_myobject_extrafields.key.sql'=>'sql/llx_'.strtolower($module).'_'.strtolower($objectname).'_extrafields.key.sql',
- //'scripts/mymodule.php'=>'scripts/'.strtolower($objectname).'.php',
- 'img/object_myobject.png'=>'img/object_'.strtolower($objectname).'.png',
- 'class/myobject.class.php'=>'class/'.strtolower($objectname).'.class.php',
- //'class/api_mymodule.class.php'=>'class/api_'.strtolower($module).'.class.php',
- );
- if (GETPOST('includerefgeneration', 'aZ09')) {
- dol_mkdir($destdir.'/core/modules/'.strtolower($module));
- $filetogenerate += array(
- 'core/modules/mymodule/mod_myobject_advanced.php'=>'core/modules/'.strtolower($module).'/mod_'.strtolower($objectname).'_advanced.php',
- 'core/modules/mymodule/mod_myobject_standard.php'=>'core/modules/'.strtolower($module).'/mod_'.strtolower($objectname).'_standard.php',
- 'core/modules/mymodule/modules_myobject.php'=>'core/modules/'.strtolower($module).'/modules_'.strtolower($objectname).'.php',
- );
- }
- if (GETPOST('includedocgeneration', 'aZ09')) {
- dol_mkdir($destdir.'/core/modules/'.strtolower($module));
- dol_mkdir($destdir.'/core/modules/'.strtolower($module).'/doc');
- $filetogenerate += array(
- 'core/modules/mymodule/doc/doc_generic_myobject_odt.modules.php'=>'core/modules/'.strtolower($module).'/doc/doc_generic_'.strtolower($objectname).'_odt.modules.php',
- 'core/modules/mymodule/doc/pdf_standard_myobject.modules.php'=>'core/modules/'.strtolower($module).'/doc/pdf_standard_'.strtolower($objectname).'.modules.php'
- );
- }
- foreach ($filetogenerate as $srcfile => $destfile) {
- $result = dol_copy($srcdir.'/'.$srcfile, $destdir.'/'.$destfile, $newmask, 0);
- if ($result <= 0) {
- if ($result < 0) {
- $error++;
- $langs->load("errors");
- setEventMessages($langs->trans("ErrorFailToCopyFile", $srcdir.'/'.$srcfile, $destdir.'/'.$destfile), null, 'errors');
- } else {
- // $result == 0
- setEventMessages($langs->trans("FileAlreadyExists", $destfile), null, 'warnings');
- }
- }
- }
- // Edit the class 'class/'.strtolower($objectname).'.class.php'
- if (GETPOST('includerefgeneration', 'aZ09')) {
- // Replace 'visible'=>1, 'noteditable'=>0, 'default'=>''
- $arrayreplacement = array(
- '/\'visible\'=>1,\s*\'noteditable\'=>0,\s*\'default\'=>\'\'/' => "'visible'=>4, 'noteditable'=>1, 'default'=>'(PROV)'"
- );
- //var_dump($arrayreplacement);exit;
- //var_dump($destdir.'/class/'.strtolower($objectname).'.class.php');exit;
- dolReplaceInFile($destdir.'/class/'.strtolower($objectname).'.class.php', $arrayreplacement, '', 0, 0, 1);
- $arrayreplacement = array(
- '/\'models\' => 0,/' => '\'models\' => 1,'
- );
- dolReplaceInFile($destdir.'/core/modules/mod'.$module.'.class.php', $arrayreplacement, '', 0, 0, 1);
- }
- // Edit the setup file and the card page
- if (GETPOST('includedocgeneration', 'aZ09')) {
- // Replace some var init into some files
- $arrayreplacement = array(
- '/\$includedocgeneration = 0;/' => '$includedocgeneration = 1;'
- );
- dolReplaceInFile($destdir.'/class/'.strtolower($objectname).'.class.php', $arrayreplacement, '', 0, 0, 1);
- dolReplaceInFile($destdir.'/'.strtolower($objectname).'_card.php', $arrayreplacement, '', 0, 0, 1);
- $arrayreplacement = array(
- '/\'models\' => 0,/' => '\'models\' => 1,'
- );
- dolReplaceInFile($destdir.'/core/modules/mod'.$module.'.class.php', $arrayreplacement, '', 0, 0, 1);
- }
- // TODO Update entries '$myTmpObjects['MyObject']=array('includerefgeneration'=>0, 'includedocgeneration'=>0);'
- // Scan for object class files
- $listofobject = dol_dir_list($destdir.'/class', 'files', 0, '\.class\.php$');
- $firstobjectname = '';
- foreach ($listofobject as $fileobj) {
- if (preg_match('/^api_/', $fileobj['name'])) {
- continue;
- }
- if (preg_match('/^actions_/', $fileobj['name'])) {
- continue;
- }
- $tmpcontent = file_get_contents($fileobj['fullname']);
- $reg = array();
- if (preg_match('/class\s+([^\s]*)\s+extends\s+CommonObject/ims', $tmpcontent, $reg)) {
- $objectnameloop = $reg[1];
- if (empty($firstobjectname)) {
- $firstobjectname = $objectnameloop;
- }
- }
- // Regenerate left menu entry in descriptor for $objectname
- $stringtoadd = "
- \$this->menu[\$r++]=array(
- // '' 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
- 'fk_menu'=>'fk_mainmenu=mymodule',
- // This is a Left menu entry
- 'type'=>'left',
- 'titre'=>'List MyObject',
- 'mainmenu'=>'mymodule',
- 'leftmenu'=>'mymodule_myobject',
- 'url'=>'/mymodule/myobject_list.php',
- // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
- 'langs'=>'mymodule@mymodule',
- 'position'=>1100+\$r,
- // 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.
- 'enabled'=>'\$conf->mymodule->enabled',
- // Use 'perms'=>'\$user->rights->mymodule->level1->level2' if you want your menu with a permission rules
- 'perms'=>'1',
- 'target'=>'',
- // 0=Menu for internal users, 1=external users, 2=both
- 'user'=>2,
- );
- \$this->menu[\$r++]=array(
- // '' 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
- 'fk_menu'=>'fk_mainmenu=mymodule,fk_leftmenu=mymodule_myobject',
- // This is a Left menu entry
- 'type'=>'left',
- 'titre'=>'New MyObject',
- 'mainmenu'=>'mymodule',
- 'leftmenu'=>'mymodule_myobject',
- 'url'=>'/mymodule/myobject_card.php?action=create',
- // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
- 'langs'=>'mymodule@mymodule',
- 'position'=>1100+\$r,
- // 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.
- 'enabled'=>'\$conf->mymodule->enabled',
- // Use 'perms'=>'\$user->rights->mymodule->level1->level2' if you want your menu with a permission rules
- 'perms'=>'1',
- 'target'=>'',
- // 0=Menu for internal users, 1=external users, 2=both
- 'user'=>2
- );\n";
- $stringtoadd = preg_replace('/MyObject/', $objectnameloop, $stringtoadd);
- $stringtoadd = preg_replace('/mymodule/', strtolower($module), $stringtoadd);
- $stringtoadd = preg_replace('/myobject/', strtolower($objectnameloop), $stringtoadd);
- $moduledescriptorfile = $destdir.'/core/modules/mod'.$module.'.class.php';
- // TODO Allow a replace with regex using dolReplaceInFile with param arryreplacementisregex to 1
- // TODO Avoid duplicate addition
- dolReplaceInFile($moduledescriptorfile, array('END MODULEBUILDER LEFTMENU MYOBJECT */' => '*/'."\n".$stringtoadd."\n\t\t/* END MODULEBUILDER LEFTMENU MYOBJECT */"));
- // Add module descriptor to list of files to replace "MyObject' string with real name of object.
- $filetogenerate[] = 'core/modules/mod'.$module.'.class.php';
- }
- }
- if (!$error) {
- // Edit PHP files to make replacement
- foreach ($filetogenerate as $destfile) {
- $phpfileval['fullname'] = $destdir.'/'.$destfile;
- //var_dump($phpfileval['fullname']);
- $arrayreplacement = array(
- 'mymodule'=>strtolower($module),
- 'MyModule'=>$module,
- 'MYMODULE'=>strtoupper($module),
- 'My module'=>$module,
- 'my module'=>$module,
- 'mon module'=>$module,
- 'Mon module'=>$module,
- 'htdocs/modulebuilder/template/'=>strtolower($modulename),
- 'myobject'=>strtolower($objectname),
- 'MyObject'=>$objectname,
- 'MYOBJECT'=>strtoupper($objectname)
- );
- $result = dolReplaceInFile($phpfileval['fullname'], $arrayreplacement);
- //var_dump($result);
- if ($result < 0) {
- setEventMessages($langs->trans("ErrorFailToMakeReplacementInto", $phpfileval['fullname']), null, 'errors');
- }
- }
- }
- if (!$error) {
- // Edit the class file to write properties
- $object = rebuildObjectClass($destdir, $module, $objectname, $newmask);
- if (is_numeric($object) && $object < 0) {
- $error++;
- }
- }
- if (!$error) {
- // Edit sql with new properties
- $result = rebuildObjectSql($destdir, $module, $objectname, $newmask, '', $object);
- if ($result < 0) {
- $error++;
- }
- }
- if (!$error) {
- setEventMessages($langs->trans('FilesForObjectInitialized', $objectname), null);
- $tabobj = $objectname;
- }
- }
- if ($dirins && ($action == 'droptable' || $action == 'droptableextrafields') && !empty($module) && !empty($tabobj)) {
- $objectname = $tabobj;
- $arrayoftables = array();
- if ($action == 'droptable') {
- $arrayoftables[] = MAIN_DB_PREFIX.strtolower($module).'_'.strtolower($tabobj);
- }
- if ($action == 'droptableextrafields') {
- $arrayoftables[] = MAIN_DB_PREFIX.strtolower($module).'_'.strtolower($tabobj).'_extrafields';
- }
- foreach ($arrayoftables as $tabletodrop) {
- $nb = -1;
- $sql = "SELECT COUNT(*) as nb FROM ".$tabletodrop;
- $resql = $db->query($sql);
- if ($resql) {
- $obj = $db->fetch_object($resql);
- if ($obj) {
- $nb = $obj->nb;
- }
- } else {
- if ($db->lasterrno() == 'DB_ERROR_NOSUCHTABLE') {
- setEventMessages($langs->trans("TableDoesNotExists", $tabletodrop), null, 'warnings');
- } else {
- dol_print_error($db);
- }
- }
- if ($nb == 0) {
- $resql = $db->DDLDropTable($tabletodrop);
- //var_dump($resql);
- setEventMessages($langs->trans("TableDropped", $tabletodrop), null, 'mesgs');
- } elseif ($nb > 0) {
- setEventMessages($langs->trans("TableNotEmptyDropCanceled", $tabletodrop), null, 'warnings');
- }
- }
- }
- if ($dirins && $action == 'addproperty' && empty($cancel) && !empty($module) && !empty($tabobj)) {
- $error = 0;
- $objectname = $tabobj;
- $dirins = $dirread = $listofmodules[strtolower($module)]['moduledescriptorrootpath'];
- $moduletype = $listofmodules[strtolower($module)]['moduletype'];
- $srcdir = $dirread.'/'.strtolower($module);
- $destdir = $dirins.'/'.strtolower($module);
- dol_mkdir($destdir);
- // We click on add property
- if (!GETPOST('regenerateclasssql') && !GETPOST('regeneratemissing')) {
- if (!GETPOST('propname', 'aZ09')) {
- $error++;
- setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Name")), null, 'errors');
- }
- if (!GETPOST('proplabel', 'alpha')) {
- $error++;
- setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Label")), null, 'errors');
- }
- if (!GETPOST('proptype', 'alpha')) {
- $error++;
- setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Type")), null, 'errors');
- }
- if (!$error) {
- $addfieldentry = array(
- 'name'=>GETPOST('propname', 'aZ09'),
- 'label'=>GETPOST('proplabel', 'alpha'),
- 'type'=>GETPOST('proptype', 'alpha'),
- 'arrayofkeyval'=>GETPOST('proparrayofkeyval', 'restricthtml'), // Example json string '{"0":"Draft","1":"Active","-1":"Cancel"}'
- 'visible'=>GETPOST('propvisible', 'int'),
- 'enabled'=>GETPOST('propenabled', 'int'),
- 'position'=>GETPOST('propposition', 'int'),
- 'notnull'=>GETPOST('propnotnull', 'int'),
- 'index'=>GETPOST('propindex', 'int'),
- 'searchall'=>GETPOST('propsearchall', 'int'),
- 'isameasure'=>GETPOST('propisameasure', 'int'),
- 'comment'=>GETPOST('propcomment', 'alpha'),
- 'help'=>GETPOST('prophelp', 'alpha'),
- 'css'=>GETPOST('propcss', 'alpha'), // Can be 'maxwidth500 widthcentpercentminusxx' for example
- 'cssview'=>GETPOST('propcssview', 'alpha'),
- 'csslist'=>GETPOST('propcsslist', 'alpha'),
- 'default'=>GETPOST('propdefault', 'restricthtml'),
- 'noteditable'=>intval(GETPOST('propnoteditable', 'int')),
- 'validate' => GETPOST('propvalidate', 'int')
- );
- if (!empty($addfieldentry['arrayofkeyval']) && !is_array($addfieldentry['arrayofkeyval'])) {
- $addfieldentry['arrayofkeyval'] = json_decode($addfieldentry['arrayofkeyval'], true);
- }
- }
- }
- /*if (GETPOST('regeneratemissing'))
- {
- setEventMessages($langs->trans("FeatureNotYetAvailable"), null, 'warnings');
- $error++;
- }*/
- // Edit the class file to write properties
- if (!$error) {
- $moduletype = 'external';
- $object = rebuildObjectClass($destdir, $module, $objectname, $newmask, $srcdir, $addfieldentry, $moduletype);
- if (is_numeric($object) && $object <= 0) {
- $error++;
- }
- }
- // Edit sql with new properties
- if (!$error) {
- $moduletype = 'external';
- $result = rebuildObjectSql($destdir, $module, $objectname, $newmask, $srcdir, $object, $moduletype);
- if ($result <= 0) {
- $error++;
- }
- }
- if (!$error) {
- setEventMessages($langs->trans('FilesForObjectUpdated', $objectname), null);
- setEventMessages($langs->trans('WarningDatabaseIsNotUpdated'), null);
- clearstatcache(true);
- // Make a redirect to reload all data
- header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=objects&module='.$module.($forceddirread ? '@'.$dirread : '').'&tabobj='.$objectname.'&nocache='.time());
- exit;
- }
- }
- if ($dirins && $action == 'confirm_deleteproperty' && $propertykey) {
- $objectname = $tabobj;
- $dirins = $dirread = $listofmodules[strtolower($module)]['moduledescriptorrootpath'];
- $moduletype = $listofmodules[strtolower($module)]['moduletype'];
- $srcdir = $dirread.'/'.strtolower($module);
- $destdir = $dirins.'/'.strtolower($module);
- dol_mkdir($destdir);
- // Edit the class file to write properties
- if (!$error) {
- $object = rebuildObjectClass($destdir, $module, $objectname, $newmask, $srcdir, array(), $propertykey);
- if (is_numeric($object) && $object <= 0) {
- $error++;
- }
- }
- // Edit sql with new properties
- if (!$error) {
- $result = rebuildObjectSql($destdir, $module, $objectname, $newmask, $srcdir, $object);
- if ($result <= 0) {
- $error++;
- }
- }
- if (!$error) {
- setEventMessages($langs->trans('FilesForObjectUpdated', $objectname), null);
- clearstatcache(true);
- // Make a redirect to reload all data
- header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=objects&module='.$module.($forceddirread ? '@'.$dirread : '').'&tabobj='.$objectname);
- exit;
- }
- }
- if ($dirins && $action == 'confirm_deletemodule') {
- if (preg_match('/[^a-z0-9_]/i', $module)) {
- $error++;
- setEventMessages($langs->trans("SpaceOrSpecialCharAreNotAllowed"), null, 'errors');
- }
- if (!$error) {
- $modulelowercase = strtolower($module);
- // Dir for module
- $dir = $dirins.'/'.$modulelowercase;
- $result = dol_delete_dir_recursive($dir);
- if ($result > 0) {
- setEventMessages($langs->trans("DirWasRemoved", $modulelowercase), null);
- clearstatcache(true);
- if (function_exists('opcache_invalidate')) {
- opcache_reset(); // remove the include cache hell !
- }
- header("Location: ".$_SERVER["PHP_SELF"].'?module=deletemodule');
- exit;
- } else {
- setEventMessages($langs->trans("PurgeNothingToDelete"), null, 'warnings');
- }
- }
- $action = '';
- $module = 'deletemodule';
- }
- if ($dirins && $action == 'confirm_deleteobject' && $objectname) {
- if (preg_match('/[^a-z0-9_]/i', $objectname)) {
- $error++;
- setEventMessages($langs->trans("SpaceOrSpecialCharAreNotAllowed"), null, 'errors');
- }
- if (!$error) {
- $modulelowercase = strtolower($module);
- $objectlowercase = strtolower($objectname);
- // Dir for module
- $dir = $dirins.'/'.$modulelowercase;
- // Delete some files
- $filetodelete = array(
- 'myobject_card.php'=>strtolower($objectname).'_card.php',
- 'myobject_note.php'=>strtolower($objectname).'_note.php',
- 'myobject_contact.php'=>strtolower($objectname).'_contact.php',
- 'myobject_document.php'=>strtolower($objectname).'_document.php',
- 'myobject_agenda.php'=>strtolower($objectname).'_agenda.php',
- 'myobject_list.php'=>strtolower($objectname).'_list.php',
- 'admin/myobject_extrafields.php'=>'admin/'.strtolower($objectname).'_extrafields.php',
- 'lib/mymodule_myobject.lib.php'=>'lib/'.strtolower($module).'_'.strtolower($objectname).'.lib.php',
- 'test/phpunit/MyObjectTest.php'=>'test/phpunit/'.strtolower($objectname).'Test.php',
- 'sql/llx_mymodule_myobject.sql'=>'sql/llx_'.strtolower($module).'_'.strtolower($objectname).'.sql',
- 'sql/llx_mymodule_myobject_extrafields.sql'=>'sql/llx_'.strtolower($module).'_'.strtolower($objectname).'_extrafields.sql',
- 'sql/llx_mymodule_myobject.key.sql'=>'sql/llx_'.strtolower($module).'_'.strtolower($objectname).'.key.sql',
- 'sql/llx_mymodule_myobject_extrafields.key.sql'=>'sql/llx_'.strtolower($module).'_'.strtolower($objectname).'_extrafields.key.sql',
- 'scripts/myobject.php'=>'scripts/'.strtolower($objectname).'.php',
- 'img/object_myobject.png'=>'img/object_'.strtolower($objectname).'.png',
- 'class/myobject.class.php'=>'class/'.strtolower($objectname).'.class.php',
- 'class/api_myobject.class.php'=>'class/api_'.strtolower($module).'.class.php',
- 'core/modules/mymodule/mod_myobject_advanced.php'=>'core/modules/'.strtolower($module).'/mod_'.strtolower($objectname).'_advanced.php',
- 'core/modules/mymodule/mod_myobject_standard.php'=>'core/modules/'.strtolower($module).'/mod_'.strtolower($objectname).'_standard.php',
- 'core/modules/mymodule/modules_myobject.php'=>'core/modules/'.strtolower($module).'/modules_'.strtolower($objectname).'.php',
- 'core/modules/mymodule/doc/doc_generic_myobject_odt.modules.php'=>'core/modules/'.strtolower($module).'/doc/doc_generic_'.strtolower($objectname).'_odt.modules.php',
- 'core/modules/mymodule/doc/pdf_standard_myobject.modules.php'=>'core/modules/'.strtolower($module).'/doc/pdf_standard_'.strtolower($objectname).'.modules.php'
- );
- $resultko = 0;
- foreach ($filetodelete as $filetodelete) {
- $resulttmp = dol_delete_file($dir.'/'.$filetodelete, 0, 0, 1);
- $resulttmp = dol_delete_file($dir.'/'.$filetodelete.'.back', 0, 0, 1);
- if (!$resulttmp) {
- $resultko++;
- }
- }
- if ($resultko == 0) {
- setEventMessages($langs->trans("FilesDeleted"), null);
- } else {
- setEventMessages($langs->trans("ErrorSomeFilesCouldNotBeDeleted"), null, 'warnings');
- }
- }
- $action = '';
- $tabobj = 'deleteobject';
- }
- if ($dirins && $action == 'generatedoc') {
- $modulelowercase = strtolower($module);
- // Dir for module
- $dirofmodule = dol_buildpath($modulelowercase, 0).'/doc';
- $FILENAMEDOC = strtolower($module).'.html';
- $util = new Utils($db);
- $result = $util->generateDoc($module);
- if ($result > 0) {
- setEventMessages($langs->trans("DocFileGeneratedInto", $dirofmodule), null);
- } else {
- setEventMessages($util->error, $util->errors, 'errors');
- }
- }
- if ($dirins && $action == 'generatepackage') {
- $modulelowercase = strtolower($module);
- $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
- // Dir for module
- $dir = dol_buildpath($modulelowercase, 0);
- // Zip file to build
- $FILENAMEZIP = '';
- // Load module
- dol_include_once($pathtofile);
- $class = 'mod'.$module;
- if (class_exists($class)) {
- try {
- $moduleobj = new $class($db);
- } catch (Exception $e) {
- $error++;
- dol_print_error($db, $e->getMessage());
- }
- } else {
- $error++;
- $langs->load("errors");
- dol_print_error($db, $langs->trans("ErrorFailedToLoadModuleDescriptorForXXX", $module));
- exit;
- }
- $arrayversion = explode('.', $moduleobj->version, 3);
- if (count($arrayversion)) {
- $FILENAMEZIP = "module_".$modulelowercase.'-'.$arrayversion[0].(empty($arrayversion[1]) ? '.0' : '.'.$arrayversion[1]).($arrayversion[2] ? '.'.$arrayversion[2] : '').'.zip';
- $dirofmodule = dol_buildpath($modulelowercase, 0).'/bin';
- $outputfilezip = $dirofmodule.'/'.$FILENAMEZIP;
- if ($dirofmodule) {
- if (!dol_is_dir($dirofmodule)) {
- dol_mkdir($dirofmodule);
- }
- // Note: We exclude /bin/ to not include the already generated zip
- $result = dol_compress_dir($dir, $outputfilezip, 'zip', '/\/bin\//', $modulelowercase);
- } else {
- $result = -1;
- }
- if ($result > 0) {
- setEventMessages($langs->trans("ZipFileGeneratedInto", $outputfilezip), null);
- } else {
- $error++;
- $langs->load("errors");
- setEventMessages($langs->trans("ErrorFailToGenerateFile", $outputfilezip), null, 'errors');
- }
- } else {
- $error++;
- $langs->load("errors");
- setEventMessages($langs->trans("ErrorCheckVersionIsDefined"), null, 'errors');
- }
- }
- // Save file
- if ($action == 'savefile' && empty($cancel)) {
- $relofcustom = basename($dirins);
- if ($relofcustom) {
- // Check that relative path ($file) start with name 'custom'
- if (!preg_match('/^'.$relofcustom.'/', $file)) {
- $file = $relofcustom.'/'.$file;
- }
- $pathoffile = dol_buildpath($file, 0);
- $pathoffilebackup = dol_buildpath($file.'.back', 0);
- // Save old version
- if (dol_is_file($pathoffile)) {
- dol_copy($pathoffile, $pathoffilebackup, 0, 1);
- }
- $check = 'restricthtml';
- $srclang = dol_mimetype($pathoffile, '', 3);
- if ($srclang == 'md') {
- $check = 'restricthtml';
- }
- if ($srclang == 'lang') {
- $check = 'restricthtml';
- }
- if ($srclang == 'php') {
- $check = 'none';
- }
- $content = GETPOST('editfilecontent', $check);
- // Save file on disk
- if ($content) {
- dol_delete_file($pathoffile);
- $result = file_put_contents($pathoffile, $content);
- if ($result) {
- @chmod($pathoffile, octdec($newmask));
- setEventMessages($langs->trans("FileSaved"), null);
- } else {
- setEventMessages($langs->trans("ErrorFailedToSaveFile"), null, 'errors');
- }
- } else {
- setEventMessages($langs->trans("ContentCantBeEmpty"), null, 'errors');
- //$action='editfile';
- $error++;
- }
- }
- }
- // Enable module
- if ($action == 'set' && $user->admin) {
- $param = '';
- if ($module) {
- $param .= '&module='.urlencode($module);
- }
- if ($tab) {
- $param .= '&tab='.urlencode($tab);
- }
- if ($tabobj) {
- $param .= '&tabobj='.urlencode($tabobj);
- }
- $value = GETPOST('value', 'alpha');
- $resarray = activateModule($value);
- if (!empty($resarray['errors'])) {
- setEventMessages('', $resarray['errors'], 'errors');
- } else {
- //var_dump($resarray);exit;
- if ($resarray['nbperms'] > 0) {
- $tmpsql = "SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX."user WHERE admin <> 1";
- $resqltmp = $db->query($tmpsql);
- if ($resqltmp) {
- $obj = $db->fetch_object($resqltmp);
- //var_dump($obj->nb);exit;
- if ($obj && $obj->nb > 1) {
- $msg = $langs->trans('ModuleEnabledAdminMustCheckRights');
- setEventMessages($msg, null, 'warnings');
- }
- } else {
- dol_print_error($db);
- }
- }
- }
- header("Location: ".$_SERVER["PHP_SELF"]."?".$param);
- exit;
- }
- // Disable module
- if ($action == 'reset' && $user->admin) {
- $param = '';
- if ($module) {
- $param .= '&module='.urlencode($module);
- }
- if ($tab) {
- $param .= '&tab='.urlencode($tab);
- }
- if ($tabobj) {
- $param .= '&tabobj='.urlencode($tabobj);
- }
- $value = GETPOST('value', 'alpha');
- $result = unActivateModule($value);
- if ($result) {
- setEventMessages($result, null, 'errors');
- }
- header("Location: ".$_SERVER["PHP_SELF"]."?".$param);
- exit;
- }
- /*
- * View
- */
- $form = new Form($db);
- $formadmin = new FormAdmin($db);
- // Set dir where external modules are installed
- if (!dol_is_dir($dirins)) {
- dol_mkdir($dirins);
- }
- $dirins_ok = (dol_is_dir($dirins));
- $help_url = '';
- $morejs = array(
- '/includes/ace/src/ace.js',
- '/includes/ace/src/ext-statusbar.js',
- '/includes/ace/src/ext-language_tools.js',
- //'/includes/ace/src/ext-chromevox.js'
- );
- $morecss = array();
- llxHeader('', $langs->trans("ModuleBuilder"), $help_url, '', 0, 0, $morejs, $morecss, '', 'classforhorizontalscrolloftabs');
- $text = $langs->trans("ModuleBuilder");
- print load_fiche_titre($text, '', 'title_setup');
- print '<span class="opacitymedium hideonsmartphone">'.$langs->trans("ModuleBuilderDesc", 'https://wiki.dolibarr.org/index.php/Module_development#Create_your_module').'</span><br>';
- //print $textforlistofdirs;
- //print '<br>';
- //var_dump($listofmodules);
- $message = '';
- if (!$dirins) {
- $message = info_admin($langs->trans("ConfFileMustContainCustom", DOL_DOCUMENT_ROOT.'/custom', DOL_DOCUMENT_ROOT));
- $allowfromweb = -1;
- } else {
- if ($dirins_ok) {
- if (!is_writable(dol_osencode($dirins))) {
- $langs->load("errors");
- $message = info_admin($langs->trans("ErrorFailedToWriteInDir", $dirins));
- $allowfromweb = 0;
- }
- } else {
- $message = info_admin($langs->trans("NotExistsDirect", $dirins).$langs->trans("InfDirAlt").$langs->trans("InfDirExample"));
- $allowfromweb = 0;
- }
- }
- if ($message) {
- print $message;
- }
- //print $langs->trans("ModuleBuilderDesc3", count($listofmodules), $FILEFLAG).'<br>';
- $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>';
- // Load module descriptor
- $error = 0;
- $moduleobj = null;
- if (!empty($module) && $module != 'initmodule' && $module != 'deletemodule') {
- $modulelowercase = strtolower($module);
- $loadclasserrormessage = '';
- // Load module
- try {
- $fullpathdirtodescriptor = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
- //throw(new Exception());
- dol_include_once($fullpathdirtodescriptor);
- $class = 'mod'.$module;
- } catch (Throwable $e) { // This is called in PHP 7 only. Never called with PHP 5.6
- $loadclasserrormessage = $e->getMessage()."<br>\n";
- $loadclasserrormessage .= 'File: '.$e->getFile()."<br>\n";
- $loadclasserrormessage .= 'Line: '.$e->getLine()."<br>\n";
- } catch (Exception $e) {
- $loadclasserrormessage = $e->getMessage()."<br>\n";
- $loadclasserrormessage .= 'File: '.$e->getFile()."<br>\n";
- $loadclasserrormessage .= 'Line: '.$e->getLine()."<br>\n";
- }
- if (class_exists($class)) {
- try {
- $moduleobj = new $class($db);
- } catch (Exception $e) {
- $error++;
- print $e->getMessage();
- }
- } else {
- if (empty($forceddirread)) {
- $error++;
- }
- $langs->load("errors");
- print '<!-- ErrorFailedToLoadModuleDescriptorForXXX -->';
- print img_warning('').' '.$langs->trans("ErrorFailedToLoadModuleDescriptorForXXX", $module).'<br>';
- print $loadclasserrormessage;
- }
- }
- print '<br>';
- // Tabs for all modules
- $head = array();
- $h = 0;
- $head[$h][0] = $_SERVER["PHP_SELF"].'?module=initmodule';
- $head[$h][1] = '<span class="valignmiddle text-plus-circle">'.$langs->trans("NewModule").'</span><span class="fa fa-plus-circle valignmiddle paddingleft"></span>';
- $head[$h][2] = 'initmodule';
- $h++;
- $linktoenabledisable = '';
- if (is_array($listofmodules) && count($listofmodules) > 0) {
- // Define $linktoenabledisable
- $modulelowercase = strtolower($module);
- $const_name = 'MAIN_MODULE_'.strtoupper($module);
- $param = '';
- if ($tab) {
- $param .= '&tab='.urlencode($tab);
- }
- if ($module) {
- $param .= '&module='.urlencode($module);
- }
- if ($tabobj) {
- $param .= '&tabobj='.urlencode($tabobj);
- }
- $urltomodulesetup = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?search_keyword='.urlencode($module).'">'.$langs->trans('Home').'-'.$langs->trans("Setup").'-'.$langs->trans("Modules").'</a>';
- if (!empty($conf->global->$const_name)) { // If module is already activated
- $linktoenabledisable .= '<a class="reposition asetresetmodule valignmiddle" href="'.$_SERVER["PHP_SELF"].'?id='.$moduleobj->numero.'&action=reset&value=mod'.$module.$param.'">';
- $linktoenabledisable .= img_picto($langs->trans("Activated"), 'switch_on', '', false, 0, 0, '', '', 1);
- $linktoenabledisable .= '</a>';
- $linktoenabledisable .= $form->textwithpicto('', $langs->trans("Warning").' : '.$langs->trans("ModuleIsLive"), -1, 'warning');
- $objMod = $moduleobj;
- $backtourlparam = '';
- $backtourlparam .= ($backtourlparam ? '&' : '?').'module='.$module; // No urlencode here, done later
- if ($tab) {
- $backtourlparam .= ($backtourlparam ? '&' : '?').'tab='.$tab; // No urlencode here, done later
- }
- $backtourl = $_SERVER["PHP_SELF"].$backtourlparam;
- $regs = array();
- if (is_array($objMod->config_page_url)) {
- $i = 0;
- foreach ($objMod->config_page_url as $page) {
- $urlpage = $page;
- if ($i++) {
- $linktoenabledisable .= ' <a href="'.$urlpage.'" title="'.$langs->trans($page).'">'.img_picto(ucfirst($page), "setup").'</a>';
- // print '<a href="'.$page.'">'.ucfirst($page).'</a> ';
- } else {
- if (preg_match('/^([^@]+)@([^@]+)$/i', $urlpage, $regs)) {
- $urltouse = dol_buildpath('/'.$regs[2].'/admin/'.$regs[1], 1);
- $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>';
- } else {
- // Case standard admin page (not a page provided by the
- // module but a page provided by dolibarr)
- $urltouse = DOL_URL_ROOT.'/admin/'.$urlpage;
- $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>';
- }
- }
- }
- } elseif (preg_match('/^([^@]+)@([^@]+)$/i', $objMod->config_page_url, $regs)) {
- $linktoenabledisable .= ' <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>';
- }
- } else {
- if (!empty($moduleobj)) {
- $linktoenabledisable .= '<a class="reposition asetresetmodule valignmiddle" href="'.$_SERVER["PHP_SELF"].'?id='.$moduleobj->numero.'&action=set&token='.newToken().'&value=mod'.$module.$param.'">';
- $linktoenabledisable .= img_picto($langs->trans("ModuleIsNotActive", $urltomodulesetup), 'switch_off', 'style="padding-right: 8px"', false, 0, 0, '', 'classfortooltip', 1);
- $linktoenabledisable .= "</a>\n";
- }
- }
- // Loop to show tab of each module
- foreach ($listofmodules as $tmpmodule => $tmpmodulearray) {
- $head[$h][0] = $_SERVER["PHP_SELF"].'?module='.$tmpmodulearray['modulenamewithcase'].($forceddirread ? '@'.$dirread : '');
- $head[$h][1] = $tmpmodulearray['modulenamewithcase'];
- $head[$h][2] = $tmpmodulearray['modulenamewithcase'];
- if ($tmpmodulearray['modulenamewithcase'] == $module) {
- $head[$h][4] = '<span class="inline-block">'.$linktoenabledisable.'</span>';
- }
- $h++;
- }
- }
- $head[$h][0] = $_SERVER["PHP_SELF"].'?module=deletemodule';
- $head[$h][1] = $langs->trans("DangerZone");
- $head[$h][2] = 'deletemodule';
- $h++;
- print dol_get_fiche_head($head, $module, '', -1, '', 0, $infomodulesfound, '', 8); // Modules
- if ($module == 'initmodule') {
- // New module
- print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
- print '<input type="hidden" name="token" value="'.newToken().'">';
- print '<input type="hidden" name="action" value="initmodule">';
- print '<input type="hidden" name="module" value="initmodule">';
- //print '<span class="opacitymedium">'.$langs->trans("ModuleBuilderDesc2", 'conf/conf.php', $newdircustom).'</span><br>';
- print $langs->trans("EnterNameOfModuleDesc").'<br>';
- print '<br>';
- print '<input type="text" name="modulename" value="'.dol_escape_htmltag($modulename).'" placeholder="'.dol_escape_htmltag($langs->trans("ModuleKey")).'"><br>';
- print '<br><input type="submit" class="button" name="create" value="'.dol_escape_htmltag($langs->trans("Create")).'"'.($dirins ? '' : ' disabled="disabled"').'>';
- print '</form>';
- } elseif ($module == 'deletemodule') {
- print '<!-- Form to init a module -->'."\n";
- print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST" name="delete">';
- print '<input type="hidden" name="token" value="'.newToken().'">';
- print '<input type="hidden" name="action" value="confirm_deletemodule">';
- print '<input type="hidden" name="module" value="deletemodule">';
- print $langs->trans("EnterNameOfModuleToDeleteDesc").'<br><br>';
- print '<input type="text" name="module" placeholder="'.dol_escape_htmltag($langs->trans("ModuleKey")).'" value="">';
- print '<input type="submit" class="button smallpaddingimp" value="'.$langs->trans("Delete").'"'.($dirins ? '' : ' disabled="disabled"').'>';
- print '</form>';
- } elseif (!empty($module)) {
- // Tabs for module
- if (!$error) {
- $dirread = $listofmodules[strtolower($module)]['moduledescriptorrootpath'];
- $head2 = array();
- $h = 0;
- $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=description&module='.$module.($forceddirread ? '@'.$dirread : '');
- $head2[$h][1] = $langs->trans("Description");
- $head2[$h][2] = 'description';
- $h++;
- $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=objects&module='.$module.($forceddirread ? '@'.$dirread : '');
- $head2[$h][1] = $langs->trans("Objects");
- $head2[$h][2] = 'objects';
- $h++;
- $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=languages&module='.$module.($forceddirread ? '@'.$dirread : '');
- $head2[$h][1] = $langs->trans("Languages");
- $head2[$h][2] = 'languages';
- $h++;
- $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=dictionaries&module='.$module.($forceddirread ? '@'.$dirread : '');
- $head2[$h][1] = $langs->trans("Dictionaries");
- $head2[$h][2] = 'dictionaries';
- $h++;
- $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=permissions&module='.$module.($forceddirread ? '@'.$dirread : '');
- $head2[$h][1] = $langs->trans("Permissions");
- $head2[$h][2] = 'permissions';
- $h++;
- $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=menus&module='.$module.($forceddirread ? '@'.$dirread : '');
- $head2[$h][1] = $langs->trans("Menus");
- $head2[$h][2] = 'menus';
- $h++;
- $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=hooks&module='.$module.($forceddirread ? '@'.$dirread : '');
- $head2[$h][1] = $langs->trans("Hooks");
- $head2[$h][2] = 'hooks';
- $h++;
- $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=triggers&module='.$module.($forceddirread ? '@'.$dirread : '');
- $head2[$h][1] = $langs->trans("Triggers");
- $head2[$h][2] = 'triggers';
- $h++;
- $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=widgets&module='.$module.($forceddirread ? '@'.$dirread : '');
- $head2[$h][1] = $langs->trans("Widgets");
- $head2[$h][2] = 'widgets';
- $h++;
- $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=exportimport&module='.$module.($forceddirread ? '@'.$dirread : '');
- $head2[$h][1] = $langs->trans("Export").'-'.$langs->trans("Import");
- $head2[$h][2] = 'exportimport';
- $h++;
- $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=css&module='.$module.($forceddirread ? '@'.$dirread : '');
- $head2[$h][1] = $langs->trans("CSS");
- $head2[$h][2] = 'css';
- $h++;
- $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=js&module='.$module.($forceddirread ? '@'.$dirread : '');
- $head2[$h][1] = $langs->trans("JS");
- $head2[$h][2] = 'js';
- $h++;
- $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=cli&module='.$module.($forceddirread ? '@'.$dirread : '');
- $head2[$h][1] = $langs->trans("CLI");
- $head2[$h][2] = 'cli';
- $h++;
- $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=cron&module='.$module.($forceddirread ? '@'.$dirread : '');
- $head2[$h][1] = $langs->trans("CronList");
- $head2[$h][2] = 'cron';
- $h++;
- $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=specifications&module='.$module.($forceddirread ? '@'.$dirread : '');
- $head2[$h][1] = $langs->trans("Documentation");
- $head2[$h][2] = 'specifications';
- $h++;
- $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=buildpackage&module='.$module.($forceddirread ? '@'.$dirread : '');
- $head2[$h][1] = $langs->trans("BuildPackage");
- $head2[$h][2] = 'buildpackage';
- $h++;
- print '<!-- Section for a given module -->';
- // Note module is inside $dirread
- if ($tab == 'description') {
- $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
- $pathtofilereadme = $modulelowercase.'/README.md';
- $pathtochangelog = $modulelowercase.'/ChangeLog.md';
- if ($action != 'editfile' || empty($file)) {
- print dol_get_fiche_head($head2, $tab, '', -1, '', 0, '', '', 0, 'formodulesuffix'); // Description - level 2
- print '<span class="opacitymedium">'.$langs->trans("ModuleBuilderDesc".$tab).'</span>';
- $infoonmodulepath = '';
- if (realpath($dirread.'/'.$modulelowercase) != $dirread.'/'.$modulelowercase) {
- $infoonmodulepath = '<span class="opacitymedium">'.$langs->trans("RealPathOfModule").' :</span> <strong>'.realpath($dirread.'/'.$modulelowercase).'</strong><br>';
- print ' '.$infoonmodulepath;
- }
- print '<br>';
- print '<table>';
- print '<tr><td>';
- print '<span class="fa fa-file-o"></span> '.$langs->trans("DescriptorFile").' : <strong>'.$pathtofile.'</strong>';
- 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>';
- print '</td></tr>';
- print '<tr><td><span class="fa fa-file-o"></span> '.$langs->trans("ReadmeFile").' : <strong>'.$pathtofilereadme.'</strong>';
- 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>';
- print '</td></tr>';
- print '<tr><td><span class="fa fa-file-o"></span> '.$langs->trans("ChangeLog").' : <strong>'.$pathtochangelog.'</strong>';
- 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>';
- print '</td></tr>';
- print '</table>';
- print '<br>';
- print load_fiche_titre($langs->trans("DescriptorFile"), '', '');
- if (!empty($moduleobj)) {
- print '<div class="underbanner clearboth"></div>';
- print '<div class="fichecenter">';
- print '<table class="border centpercent">';
- print '<tr class="liste_titre"><td class="titlefield">';
- print $langs->trans("Parameter");
- print '</td><td>';
- print $langs->trans("Value");
- print '</td></tr>';
- print '<tr><td>';
- print $langs->trans("Numero");
- print '</td><td>';
- print $moduleobj->numero;
- print ' (<a href="'.DOL_URL_ROOT.'/admin/system/modules.php?mainmenu=home&leftmenu=admintools_info" target="_blank" rel="noopener noreferrer">'.$langs->trans("SeeIDsInUse").'</a>';
- print ' - <a href="https://wiki.dolibarr.org/index.php/List_of_modules_id" target="_blank" rel="noopener noreferrer external">'.$langs->trans("SeeReservedIDsRangeHere").'</a>)';
- print '</td></tr>';
- print '<tr><td>';
- print $langs->trans("Name");
- print '</td><td>';
- print $moduleobj->getName();
- print '</td></tr>';
- print '<tr><td>';
- print $langs->trans("Version");
- print '</td><td>';
- print $moduleobj->getVersion();
- print '</td></tr>';
- print '<tr><td>';
- print $langs->trans("Family");
- //print "<br>'crm','financial','hr','projects','products','ecm','technic','interface','other'";
- print '</td><td>';
- print $moduleobj->family;
- print '</td></tr>';
- print '<tr><td>';
- print $langs->trans("EditorName");
- print '</td><td>';
- print $moduleobj->editor_name;
- print '</td></tr>';
- print '<tr><td>';
- print $langs->trans("EditorUrl");
- print '</td><td>';
- print $moduleobj->editor_url;
- print '</td></tr>';
- print '<tr><td>';
- print $langs->trans("Description");
- print '</td><td>';
- print $moduleobj->getDesc();
- print '</td></tr>';
- print '</table>';
- } else {
- print $langs->trans("ErrorFailedToLoadModuleDescriptorForXXX", $module).'<br>';
- }
- if (!empty($moduleobj)) {
- print '<br><br>';
- // Readme file
- print load_fiche_titre($langs->trans("ReadmeFile"), '', '');
- print '<!-- readme file -->';
- if (dol_is_file($dirread.'/'.$pathtofilereadme)) {
- print '<div class="underbanner clearboth"></div><div class="fichecenter">'.$moduleobj->getDescLong().'</div>';
- } else {
- print '<span class="opacitymedium">'.$langs->trans("ErrorFileNotFound", $pathtofilereadme).'</span>';
- }
- print '<br><br>';
- // ChangeLog
- print load_fiche_titre($langs->trans("ChangeLog"), '', '');
- print '<!-- changelog file -->';
- if (dol_is_file($dirread.'/'.$pathtochangelog)) {
- print '<div class="underbanner clearboth"></div><div class="fichecenter">'.$moduleobj->getChangeLog().'</div>';
- } else {
- print '<span class="opacitymedium">'.$langs->trans("ErrorFileNotFound", $pathtochangelog).'</span>';
- }
- }
- print dol_get_fiche_end();
- } else { // Edit text file
- $fullpathoffile = dol_buildpath($file, 0, 1); // Description - level 2
- if ($fullpathoffile) {
- $content = file_get_contents($fullpathoffile);
- }
- // New module
- print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
- print '<input type="hidden" name="token" value="'.newToken().'">';
- print '<input type="hidden" name="action" value="savefile">';
- print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
- print '<input type="hidden" name="tab" value="'.$tab.'">';
- print '<input type="hidden" name="module" value="'.$module.'">';
- print dol_get_fiche_head($head2, $tab, '', -1, '', 0, '', '', 0, 'formodulesuffix');
- $doleditor = new DolEditor('editfilecontent', $content, '', '300', 'Full', 'In', true, false, 'ace', 0, '99%', '');
- print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ?GETPOST('format', 'aZ09') : 'html'));
- print dol_get_fiche_end();
- print '<center>';
- print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
- print ' ';
- print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
- print '</center>';
- print '</form>';
- }
- } else {
- print dol_get_fiche_head($head2, $tab, '', -1, '', 0, '', '', 0, 'formodulesuffix'); // Level 2
- }
- if ($tab == 'languages') {
- if ($action != 'editfile' || empty($file)) {
- print '<span class="opacitymedium">'.$langs->trans("LanguageDefDesc").'</span><br>';
- print '<br>';
- print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
- print '<input type="hidden" name="token" value="'.newToken().'">';
- print '<input type="hidden" name="action" value="addlanguage">';
- print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
- print '<input type="hidden" name="tab" value="'.$tab.'">';
- print '<input type="hidden" name="module" value="'.$module.'">';
- print $formadmin->select_language($conf->global->MAIN_LANG_DEFAULT, 'newlangcode', 0, 0, 1, 0, 0, 'minwidth300', 1);
- print '<input type="submit" name="addlanguage" class="button smallpaddingimp" value="'.dol_escape_htmltag($langs->trans("AddLanguageFile")).'"><br>';
- print '</form>';
- print '<br>';
- print '<br>';
- $modulelowercase = strtolower($module);
- // Dir for module
- $diroflang = dol_buildpath($modulelowercase, 0);
- $diroflang .= '/langs';
- $langfiles = dol_dir_list($diroflang, 'files', 1, '\.lang$');
- if (!preg_match('/custom/', $dirread)) {
- // If this is not a module into custom
- $diroflang = $dirread;
- $diroflang .= '/langs';
- $langfiles = dol_dir_list($diroflang, 'files', 1, $modulelowercase.'\.lang$');
- }
- print '<table class="none">';
- foreach ($langfiles as $langfile) {
- $pathtofile = $modulelowercase.'/langs/'.$langfile['relativename'];
- if (!preg_match('/custom/', $dirread)) { // If this is not a module into custom
- $pathtofile = 'langs/'.$langfile['relativename'];
- }
- print '<tr><td><span class="fa fa-file-o"></span> '.$langs->trans("LanguageFile").' '.basename(dirname($pathtofile)).' : <strong>'.$pathtofile.'</strong>';
- 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>';
- 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>';
- print '</td>';
- }
- print '</table>';
- } else {
- // Edit text language file
- //print $langs->trans("UseAsciiDocFormat").'<br>';
- $fullpathoffile = dol_buildpath($file, 0);
- $content = file_get_contents($fullpathoffile);
- // New module
- print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
- print '<input type="hidden" name="token" value="'.newToken().'">';
- print '<input type="hidden" name="action" value="savefile">';
- print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
- print '<input type="hidden" name="tab" value="'.$tab.'">';
- print '<input type="hidden" name="module" value="'.$module.'">';
- $doleditor = new DolEditor('editfilecontent', $content, '', '300', 'Full', 'In', true, false, 'ace', 0, '99%');
- print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ?GETPOST('format', 'aZ09') : 'text'));
- print '<br>';
- print '<center>';
- print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
- print ' ';
- print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
- print '</center>';
- print '</form>';
- }
- }
- if ($tab == 'dictionaries') {
- $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
- $dicts = $moduleobj->dictionaries;
- if ($action != 'editfile' || empty($file)) {
- print '<span class="opacitymedium">';
- $htmlhelp = $langs->trans("DictionariesDefDescTooltip", '{s1}');
- $htmlhelp = str_replace('{s1}', '<a target="adminbis" class="nofocusvisible" href="'.DOL_URL_ROOT.'/admin/dict.php">'.$langs->trans('Setup').' - '.$langs->trans('Dictionaries').'</a>', $htmlhelp);
- print $form->textwithpicto($langs->trans("DictionariesDefDesc"), $htmlhelp, 1, 'help', '', 0, 2, 'helpondesc').'<br>';
- print '</span>';
- print '<br>';
- print '<span class="fa fa-file-o"></span> '.$langs->trans("DescriptorFile").' : <strong>'.$pathtofile.'</strong>';
- 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>';
- print '<br>';
- if (is_array($dicts) && !empty($dicts)) {
- print '<span class="fa fa-file-o"></span> '.$langs->trans("LanguageFile").' :</span> ';
- print '<strong>'.$dicts['langs'].'</strong>';
- print '<br>';
- }
- print load_fiche_titre($langs->trans("ListOfDictionariesEntries"), '', '');
- print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
- print '<input type="hidden" name="token" value="'.newToken().'">';
- print '<input type="hidden" name="action" value="addproperty">';
- print '<input type="hidden" name="tab" value="objects">';
- print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
- print '<input type="hidden" name="tabobj" value="'.dol_escape_htmltag($tabobj).'">';
- print '<div class="div-table-responsive">';
- print '<table class="noborder">';
- print '<tr class="liste_titre">';
- print_liste_field_titre("#", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
- print_liste_field_titre("Table", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
- print_liste_field_titre("Label", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
- print_liste_field_titre("SQL", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
- print_liste_field_titre("SQLSort", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
- print_liste_field_titre("FieldsView", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
- print_liste_field_titre("FieldsEdit", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
- print_liste_field_titre("FieldsInsert", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
- print_liste_field_titre("Rowid", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
- print_liste_field_titre("Condition", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
- print "</tr>\n";
- if (is_array($dicts) && is_array($dicts['tabname'])) {
- $i = 0;
- $maxi = count($dicts['tabname']);
- while ($i < $maxi) {
- print '<tr class="oddeven">';
- print '<td>';
- print ($i + 1);
- print '</td>';
- print '<td>';
- print $dicts['tabname'][$i];
- print '</td>';
- print '<td>';
- print $dicts['tablib'][$i];
- print '</td>';
- print '<td>';
- print $dicts['tabsql'][$i];
- print '</td>';
- print '<td>';
- print $dicts['tabsqlsort'][$i];
- print '</td>';
- print '<td>';
- print $dicts['tabfield'][$i];
- print '</td>';
- print '<td>';
- print $dicts['tabfieldvalue'][$i];
- print '</td>';
- print '<td>';
- print $dicts['tabfieldinsert'][$i];
- print '</td>';
- print '<td class="right">';
- print $dicts['tabrowid'][$i];
- print '</td>';
- print '<td class="right">';
- print $dicts['tabcond'][$i];
- print '</td>';
- print '</tr>';
- $i++;
- }
- } else {
- print '<tr><td colspan="5"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
- }
- print '</table>';
- print '</div>';
- print '</form>';
- } else {
- $fullpathoffile = dol_buildpath($file, 0);
- $content = file_get_contents($fullpathoffile);
- // New module
- print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
- print '<input type="hidden" name="token" value="'.newToken().'">';
- print '<input type="hidden" name="action" value="savefile">';
- print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
- print '<input type="hidden" name="tab" value="'.$tab.'">';
- print '<input type="hidden" name="module" value="'.$module.'">';
- $doleditor = new DolEditor('editfilecontent', $content, '', '300', 'Full', 'In', true, false, 'ace', 0, '99%');
- print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ?GETPOST('format', 'aZ09') : 'html'));
- print '<br>';
- print '<center>';
- print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
- print ' ';
- print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
- print '</center>';
- print '</form>';
- }
- }
- if ($tab == 'objects') {
- $head3 = array();
- $h = 0;
- // Dir for module
- $dir = $dirread.'/'.$modulelowercase.'/class';
- $head3[$h][0] = $_SERVER["PHP_SELF"].'?tab=objects&module='.$module.($forceddirread ? '@'.$dirread : '').'&tabobj=newobject';
- $head3[$h][1] = '<span class="valignmiddle text-plus-circle">'.$langs->trans("NewObjectInModulebuilder").'</span><span class="fa fa-plus-circle valignmiddle paddingleft"></span>';
- $head3[$h][2] = 'newobject';
- $h++;
- // Scan for object class files
- $listofobject = dol_dir_list($dir, 'files', 0, '\.class\.php$');
- $firstobjectname = '';
- foreach ($listofobject as $fileobj) {
- if (preg_match('/^api_/', $fileobj['name'])) {
- continue;
- }
- if (preg_match('/^actions_/', $fileobj['name'])) {
- continue;
- }
- $tmpcontent = file_get_contents($fileobj['fullname']);
- if (preg_match('/class\s+([^\s]*)\s+extends\s+CommonObject/ims', $tmpcontent, $reg)) {
- //$objectname = preg_replace('/\.txt$/', '', $fileobj['name']);
- $objectname = $reg[1];
- if (empty($firstobjectname)) {
- $firstobjectname = $objectname;
- }
- $head3[$h][0] = $_SERVER["PHP_SELF"].'?tab=objects&module='.$module.($forceddirread ? '@'.$dirread : '').'&tabobj='.$objectname;
- $head3[$h][1] = $objectname;
- $head3[$h][2] = $objectname;
- $h++;
- }
- }
- $head3[$h][0] = $_SERVER["PHP_SELF"].'?tab=objects&module='.$module.($forceddirread ? '@'.$dirread : '').'&tabobj=deleteobject';
- $head3[$h][1] = $langs->trans("DangerZone");
- $head3[$h][2] = 'deleteobject';
- $h++;
- // 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.
- if ($tabobj == 'newobjectifnoobj') {
- if ($firstobjectname) {
- $tabobj = $firstobjectname;
- } else {
- $tabobj = 'newobject';
- }
- }
- print dol_get_fiche_head($head3, $tabobj, '', -1, ''); // Level 3
- if ($tabobj == 'newobject') {
- // New object tab
- print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
- print '<input type="hidden" name="token" value="'.newToken().'">';
- print '<input type="hidden" name="action" value="initobject">';
- print '<input type="hidden" name="tab" value="objects">';
- print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
- print '<span class="opacitymedium">'.$langs->trans("EnterNameOfObjectDesc").'</span><br><br>';
- 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>';
- print '<input type="checkbox" name="includerefgeneration" id="includerefgeneration" value="includerefgeneration"> <label for="includerefgeneration">'.$form->textwithpicto($langs->trans("IncludeRefGeneration"), $langs->trans("IncludeRefGenerationHelp")).'</label><br>';
- print '<input type="checkbox" name="includedocgeneration" id="includedocgeneration" value="includedocgeneration"> <label for="includedocgeneration">'.$form->textwithpicto($langs->trans("IncludeDocGeneration"), $langs->trans("IncludeDocGenerationHelp")).'</label><br>';
- print '<input type="submit" class="button smallpaddingimp" name="create" value="'.dol_escape_htmltag($langs->trans("Generate")).'"'.($dirins ? '' : ' disabled="disabled"').'>';
- print '<br>';
- print '<br>';
- print '<br>';
- print $langs->trans("or");
- print '<br>';
- print '<br>';
- //print '<input type="checkbox" name="initfromtablecheck"> ';
- print $langs->trans("InitStructureFromExistingTable");
- print '<input type="text" name="initfromtablename" value="" placeholder="'.$langs->trans("TableName").'">';
- print '<input type="submit" class="button smallpaddingimp" name="createtablearray" value="'.dol_escape_htmltag($langs->trans("Generate")).'"'.($dirins ? '' : ' disabled="disabled"').'>';
- print '<br>';
- print '</form>';
- } elseif ($tabobj == 'deleteobject') {
- // Delete object tab
- print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
- print '<input type="hidden" name="token" value="'.newToken().'">';
- print '<input type="hidden" name="action" value="confirm_deleteobject">';
- print '<input type="hidden" name="tab" value="objects">';
- print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
- print $langs->trans("EnterNameOfObjectToDeleteDesc").'<br><br>';
- print '<input type="text" name="objectname" value="'.dol_escape_htmltag($modulename).'" placeholder="'.dol_escape_htmltag($langs->trans("ObjectKey")).'">';
- print '<input type="submit" class="button smallpaddingimp" name="delete" value="'.dol_escape_htmltag($langs->trans("Delete")).'"'.($dirins ? '' : ' disabled="disabled"').'>';
- print '</form>';
- } else {
- // tabobj = module
- if ($action == 'deleteproperty') {
- $formconfirm = $form->formconfirm(
- $_SERVER["PHP_SELF"].'?propertykey='.urlencode(GETPOST('propertykey', 'alpha')).'&objectname='.urlencode($objectname).'&tab='.urlencode($tab).'&module='.urlencode($module).'&tabobj='.urlencode($tabobj),
- $langs->trans('Delete'),
- $langs->trans('ConfirmDeleteProperty', GETPOST('propertykey', 'alpha')),
- 'confirm_deleteproperty',
- '',
- 0,
- 1
- );
- // Print form confirm
- print $formconfirm;
- }
- if ($action != 'editfile' || empty($file)) {
- try {
- //$pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
- $pathtoclass = strtolower($module).'/class/'.strtolower($tabobj).'.class.php';
- $pathtoapi = strtolower($module).'/class/api_'.strtolower($module).'.class.php';
- $pathtoagenda = strtolower($module).'/'.strtolower($tabobj).'_agenda.php';
- $pathtocard = strtolower($module).'/'.strtolower($tabobj).'_card.php';
- $pathtodocument = strtolower($module).'/'.strtolower($tabobj).'_document.php';
- $pathtolist = strtolower($module).'/'.strtolower($tabobj).'_list.php';
- $pathtonote = strtolower($module).'/'.strtolower($tabobj).'_note.php';
- $pathtocontact = strtolower($module).'/'.strtolower($tabobj).'_contact.php';
- $pathtophpunit = strtolower($module).'/test/phpunit/'.strtolower($tabobj).'Test.php';
- $pathtosql = strtolower($module).'/sql/llx_'.strtolower($module).'_'.strtolower($tabobj).'.sql';
- $pathtosqlextra = strtolower($module).'/sql/llx_'.strtolower($module).'_'.strtolower($tabobj).'_extrafields.sql';
- $pathtosqlkey = strtolower($module).'/sql/llx_'.strtolower($module).'_'.strtolower($tabobj).'.key.sql';
- $pathtosqlextrakey = strtolower($module).'/sql/llx_'.strtolower($module).'_'.strtolower($tabobj).'_extrafields.key.sql';
- $pathtolib = strtolower($module).'/lib/'.strtolower($module).'.lib.php';
- $pathtoobjlib = strtolower($module).'/lib/'.strtolower($module).'_'.strtolower($tabobj).'.lib.php';
- $pathtopicto = strtolower($module).'/img/object_'.strtolower($tabobj).'.png';
- //var_dump($pathtoclass); var_dump($dirread);
- $realpathtoclass = $dirread.'/'.$pathtoclass;
- $realpathtoapi = $dirread.'/'.$pathtoapi;
- $realpathtoagenda = $dirread.'/'.$pathtoagenda;
- $realpathtocard = $dirread.'/'.$pathtocard;
- $realpathtodocument = $dirread.'/'.$pathtodocument;
- $realpathtolist = $dirread.'/'.$pathtolist;
- $realpathtonote = $dirread.'/'.$pathtonote;
- $realpathtocontact = $dirread.'/'.$pathtocontact;
- $realpathtophpunit = $dirread.'/'.$pathtophpunit;
- $realpathtosql = $dirread.'/'.$pathtosql;
- $realpathtosqlextra = $dirread.'/'.$pathtosqlextra;
- $realpathtosqlkey = $dirread.'/'.$pathtosqlkey;
- $realpathtosqlextrakey = $dirread.'/'.$pathtosqlextrakey;
- $realpathtolib = $dirread.'/'.$pathtolib;
- $realpathtoobjlib = $dirread.'/'.$pathtoobjlib;
- $realpathtopicto = $dirread.'/'.$pathtopicto;
- if (empty($realpathtoapi)) { // For compatibility with some old modules
- $pathtoapi = strtolower($module).'/class/api_'.strtolower($module).'s.class.php';
- $realpathtoapi = $dirread.'/'.$pathtoapi;
- }
- $urloflist = dol_buildpath('/'.$pathtolist, 1);
- $urlofcard = dol_buildpath('/'.$pathtocard, 1);
- print '<div class="fichehalfleft smallxxx">';
- print '<span class="fa fa-file-o"></span> '.$langs->trans("ClassFile").' : <strong>'.($realpathtoclass ? '' : '<strike>').preg_replace('/^'.strtolower($module).'\//', '', $pathtoclass).($realpathtoclass ? '' : '</strike>').'</strong>';
- 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>';
- print '<br>';
- print '<span class="fa fa-file-o"></span> '.$langs->trans("ApiClassFile").' : <strong>'.($realpathtoapi ? '' : '<strike>').preg_replace('/^'.strtolower($module).'\//', '', $pathtoapi).($realpathtoapi ? '' : '</strike>').'</strong>';
- if (dol_is_file($realpathtoapi)) {
- 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>';
- print ' ';
- 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>';
- print ' ';
- if (empty($conf->global->$const_name)) { // If module is not activated
- print '<a href="#" class="classfortooltip" target="apiexplorer" title="'.$langs->trans("ModuleMustBeEnabled", $module).'"><strike>'.$langs->trans("GoToApiExplorer").'</strike></a>';
- } else {
- print '<a href="'.DOL_URL_ROOT.'/api/index.php/explorer/" target="apiexplorer">'.$langs->trans("GoToApiExplorer").'</a>';
- }
- } else {
- //print '<span class="opacitymedium">'.$langs->trans("FileNotYetGenerated").'</span> ';
- 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>';
- }
- // PHPUnit
- print '<br>';
- print '<span class="fa fa-file-o"></span> '.$langs->trans("TestClassFile").' : <strong>'.($realpathtophpunit ? '' : '<strike>').preg_replace('/^'.strtolower($module).'\//', '', $pathtophpunit).($realpathtophpunit ? '' : '</strike>').'</strong>';
- if (dol_is_file($realpathtophpunit)) {
- 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>';
- print ' ';
- 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>';
- } else {
- //print '<span class="opacitymedium">'.$langs->trans("FileNotYetGenerated").'</span> ';
- 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>';
- }
- print '<br>';
- print '<br>';
- print '<span class="fa fa-file-o"></span> '.$langs->trans("PageForLib").' : <strong>'.($realpathtolib ? '' : '<strike>').preg_replace('/^'.strtolower($module).'\//', '', $pathtolib).($realpathtolib ? '' : '</strike>').'</strong>';
- 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>';
- print '<br>';
- print '<span class="fa fa-file-o"></span> '.$langs->trans("PageForObjLib").' : <strong>'.($realpathtoobjlib ? '' : '<strike>').preg_replace('/^'.strtolower($module).'\//', '', $pathtoobjlib).($realpathtoobjlib ? '' : '</strike>').'</strong>';
- 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>';
- print '<br>';
- print '<span class="fa fa-file-image-o"></span> '.$langs->trans("Image").' : <strong>'.($realpathtopicto ? '' : '<strike>').preg_replace('/^'.strtolower($module).'\//', '', $pathtopicto).($realpathtopicto ? '' : '</strike>').'</strong>';
- //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>';
- print '<br>';
- print '<br>';
- print '<span class="fa fa-file-o"></span> '.$langs->trans("SqlFile").' : <strong>'.($realpathtosql ? '' : '<strike>').preg_replace('/^'.strtolower($module).'\//', '', $pathtosql).($realpathtosql ? '' : '</strike>').'</strong>';
- 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>';
- print ' <a class="reposition" href="'.$_SERVER["PHP_SELF"].'?tab='.$tab.'&tabobj='.$tabobj.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=droptable&token='.newToken().'">'.$langs->trans("DropTableIfEmpty").'</a>';
- //print ' <a href="'.$_SERVER["PHP_SELF"].'">'.$langs->trans("RunSql").'</a>';
- print '<br>';
- print '<span class="fa fa-file-o"></span> '.$langs->trans("SqlFileKey").' : <strong>'.($realpathtosqlkey ? '' : '<strike>').preg_replace('/^'.strtolower($module).'\//', '', $pathtosqlkey).($realpathtosqlkey ? '' : '</strike>').'</strong>';
- 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>';
- //print ' <a href="'.$_SERVER["PHP_SELF"].'">'.$langs->trans("RunSql").'</a>';
- print '<br>';
- print '<span class="fa fa-file-o"></span> '.$langs->trans("SqlFileExtraFields").' : <strong>'.($realpathtosqlextra ? '' : '<strike>').preg_replace('/^'.strtolower($module).'\//', '', $pathtosqlextra).($realpathtosqlextra ? '' : '</strike>').'</strong>';
- if (dol_is_file($realpathtosqlextra) && dol_is_file($realpathtosqlextrakey)) {
- 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>';
- print ' ';
- 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>';
- print ' ';
- 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>';
- } else {
- 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>';
- }
- //print ' <a href="'.$_SERVER["PHP_SELF"].'">'.$langs->trans("RunSql").'</a>';
- print '<br>';
- print '<span class="fa fa-file-o"></span> '.$langs->trans("SqlFileKeyExtraFields").' : <strong>'.($realpathtosqlextrakey ? '' : '<strike>').preg_replace('/^'.strtolower($module).'\//', '', $pathtosqlextrakey).($realpathtosqlextrakey ? '' : '</strike>').'</strong>';
- if (dol_is_file($realpathtosqlextra) && dol_is_file($realpathtosqlextrakey)) {
- 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>';
- print ' ';
- 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>';
- } else {
- 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>';
- }
- print '<br>';
- print '</div>';
- print '<div class="fichehalfleft smallxxxx">';
- 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>';
- 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>';
- print '<br>';
- 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>';
- 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>';
- print '<br>';
- print '<span class="fa fa-file-o"></span> '.$langs->trans("PageForContactTab").' : <strong>'.($realpathtocontact ? '' : '<strike>').preg_replace('/^'.strtolower($module).'\//', '', $pathtocontact).($realpathtocontact ? '' : '</strike>').'</strong>';
- 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>';
- if (dol_is_file($realpathtocontact)) {
- print ' ';
- 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>';
- }
- print '<br>';
- print '<span class="fa fa-file-o"></span> '.$langs->trans("PageForDocumentTab").' : <strong>'.($realpathtodocument ? '' : '<strike>').preg_replace('/^'.strtolower($module).'\//', '', $pathtodocument).($realpathtodocument ? '' : '</strike>').'</strong>';
- 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>';
- if (dol_is_file($realpathtodocument)) {
- print ' ';
- 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>';
- }
- print '<br>';
- print '<span class="fa fa-file-o"></span> '.$langs->trans("PageForNoteTab").' : <strong>'.($realpathtonote ? '' : '<strike>').preg_replace('/^'.strtolower($module).'\//', '', $pathtonote).($realpathtonote ? '' : '</strike>').'</strong>';
- 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>';
- if (dol_is_file($realpathtonote)) {
- print ' ';
- 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>';
- }
- print '<br>';
- print '<span class="fa fa-file-o"></span> '.$langs->trans("PageForAgendaTab").' : <strong>'.($realpathtoagenda ? '' : '<strike>').preg_replace('/^'.strtolower($module).'\//', '', $pathtoagenda).($realpathtoagenda ? '' : '</strike>').'</strong>';
- 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>';
- if (dol_is_file($realpathtoagenda)) {
- print ' ';
- 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>';
- }
- print '<br>';
- print '<br>';
- print '</div>';
- print '<br><br><br>';
- clearstatcache(true);
- if (function_exists('opcache_invalidate')) {
- opcache_invalidate($dirread.'/'.$pathtoclass, true); // remove the include cache hell !
- }
- if (empty($forceddirread) && empty($dirread)) {
- $result = dol_include_once($pathtoclass);
- } else {
- $result = @include_once $dirread.'/'.$pathtoclass;
- }
- if (class_exists($tabobj)) {
- try {
- $tmpobjet = @new $tabobj($db);
- } catch (Exception $e) {
- dol_syslog('Failed to load Constructor of class: '.$e->getMessage(), LOG_WARNING);
- }
- }
- if (!empty($tmpobjet)) {
- $reflector = new ReflectionClass($tabobj);
- $reflectorproperties = $reflector->getProperties(); // Can also use get_object_vars
- $reflectorpropdefault = $reflector->getDefaultProperties(); // Can also use get_object_vars
- //$propstat = $reflector->getStaticProperties();
- //var_dump($reflectorpropdefault);
- print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
- print '<input type="hidden" name="token" value="'.newToken().'">';
- print '<input type="hidden" name="action" value="addproperty">';
- print '<input type="hidden" name="tab" value="objects">';
- print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module.($forceddirread ? '@'.$dirread : '')).'">';
- print '<input type="hidden" name="tabobj" value="'.dol_escape_htmltag($tabobj).'">';
- print '<input class="button smallpaddingimp" type="submit" name="regenerateclasssql" value="'.$langs->trans("RegenerateClassAndSql").'">';
- print '<br><br>';
- print load_fiche_titre($langs->trans("ObjectProperties"), '', '');
- print '<!-- Table with properties of object -->'."\n";
- print '<div class="div-table-responsive">';
- print '<table class="noborder small">';
- print '<tr class="liste_titre">';
- print '<th>'.$langs->trans("Property");
- 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>)';
- print '</th>';
- print '<th>';
- print $form->textwithpicto($langs->trans("Label"), $langs->trans("YouCanUseTranslationKey"));
- print '</th>';
- print '<th>'.$form->textwithpicto($langs->trans("Type"), $langs->trans("TypeOfFieldsHelp")).'</th>';
- print '<th>'.$form->textwithpicto($langs->trans("ArrayOfKeyValues"), $langs->trans("ArrayOfKeyValuesDesc")).'</th>';
- print '<th class="center">'.$form->textwithpicto($langs->trans("NotNull"), $langs->trans("NotNullDesc")).'</th>';
- print '<th class="center">'.$langs->trans("DefaultValue").'</th>';
- print '<th class="center">'.$langs->trans("DatabaseIndex").'</th>';
- print '<th class="center">'.$langs->trans("ForeignKey").'</th>';
- print '<th class="right">'.$langs->trans("Position").'</th>';
- print '<th class="center">'.$form->textwithpicto($langs->trans("Enabled"), $langs->trans("EnabledDesc")).'</th>';
- print '<th class="center">'.$form->textwithpicto($langs->trans("Visible"), $langs->trans("VisibleDesc")).'</th>';
- print '<th class="center">'.$langs->trans("NotEditable").'</th>';
- print '<th class="center">'.$form->textwithpicto($langs->trans("SearchAll"), $langs->trans("SearchAllDesc")).'</th>';
- print '<th class="center">'.$form->textwithpicto($langs->trans("IsAMeasure"), $langs->trans("IsAMeasureDesc")).'</th>';
- print '<th class="center">'.$langs->trans("CSSClass").'</th>';
- print '<th class="center">'.$langs->trans("CSSViewClass").'</th>';
- print '<th class="center">'.$langs->trans("CSSListClass").'</th>';
- print '<th>'.$langs->trans("KeyForTooltip").'</th>';
- print '<th class="center">'.$langs->trans("ShowOnCombobox").'</th>';
- //print '<th class="center">'.$langs->trans("Disabled").'</th>';
- print '<th>'.$form->textwithpicto($langs->trans("Validate"), $langs->trans("ValidateModBuilderDesc")).'</th>';
- print '<th>'.$langs->trans("Comment").'</th>';
- print '<th></th>';
- print '</tr>';
- // We must use $reflectorpropdefault['fields'] to get list of fields because $tmpobjet->fields may have been
- // modified during the constructor and we want value into head of class before constructor is called.
- //$properties = dol_sort_array($tmpobjet->fields, 'position');
- $properties = dol_sort_array($reflectorpropdefault['fields'], 'position');
- if (!empty($properties)) {
- // Line to add a property
- print '<tr>';
- print '<td><input type="text" class="maxwidth75" name="propname" value="'.dol_escape_htmltag(GETPOST('propname', 'alpha')).'"></td>';
- print '<td><input type="text" class="maxwidth75" name="proplabel" value="'.dol_escape_htmltag(GETPOST('proplabel', 'alpha')).'"></td>';
- print '<td><input type="text" class="maxwidth75" name="proptype" value="'.dol_escape_htmltag(GETPOST('proptype', 'alpha')).'"></td>';
- print '<td><input type="text" class="maxwidth75" name="proparrayofkeyval" value="'.dol_escape_htmltag(GETPOST('proparrayofkeyval', 'restricthtml')).'"></td>';
- print '<td class="center"><input type="text" class="center maxwidth50" name="propnotnull" value="'.dol_escape_htmltag(GETPOST('propnotnull', 'alpha')).'"></td>';
- print '<td><input type="text" class="center maxwidth50" name="propdefault" value="'.dol_escape_htmltag(GETPOST('propdefault', 'alpha')).'"></td>';
- print '<td class="center"><input type="text" class="center maxwidth50" name="propindex" value="'.dol_escape_htmltag(GETPOST('propindex', 'alpha')).'"></td>';
- print '<td class="center"><input type="text" class="maxwidth100" name="propforeignkey" value="'.dol_escape_htmltag(GETPOST('propforeignkey', 'alpha')).'"></td>';
- print '<td class="right"><input type="text" class="right" size="2" name="propposition" value="'.dol_escape_htmltag(GETPOST('propposition', 'alpha')).'"></td>';
- print '<td class="center"><input type="text" class="center maxwidth50" name="propenabled" value="'.dol_escape_htmltag(GETPOST('propenabled', 'alpha')).'"></td>';
- print '<td class="center"><input type="text" class="center maxwidth50" name="propvisible" value="'.dol_escape_htmltag(GETPOST('propvisible', 'alpha')).'"></td>';
- print '<td class="center"><input type="text" class="center maxwidth50" name="propnoteditable" value="'.dol_escape_htmltag(GETPOST('propnoteditable', 'alpha')).'"></td>';
- print '<td class="center"><input type="text" class="center maxwidth50" name="propsearchall" value="'.dol_escape_htmltag(GETPOST('propsearchall', 'alpha')).'"></td>';
- print '<td class="center"><input type="text" class="center maxwidth50" name="propisameasure" value="'.dol_escape_htmltag(GETPOST('propisameasure', 'alpha')).'"></td>';
- print '<td class="center"><input type="text" class="maxwidth50" name="propcss" value="'.dol_escape_htmltag(GETPOST('propcss', 'alpha')).'"></td>';
- print '<td class="center"><input type="text" class="maxwidth50" name="propcssview" value="'.dol_escape_htmltag(GETPOST('propcssview', 'alpha')).'"></td>';
- print '<td class="center"><input type="text" class="maxwidth50" name="propcsslist" value="'.dol_escape_htmltag(GETPOST('propcsslist', 'alpha')).'"></td>';
- print '<td><input type="text" size="2" name="prophelp" value="'.dol_escape_htmltag(GETPOST('prophelp', 'alpha')).'"></td>';
- print '<td class="center"><input type="text" class="center maxwidth50" name="propshowoncombobox" value="'.dol_escape_htmltag(GETPOST('propshowoncombobox', 'alpha')).'"></td>';
- //print '<td class="center"><input type="text" size="2" name="propdisabled" value="'.dol_escape_htmltag(GETPOST('propdisabled', 'alpha')).'"></td>';
- print '<td><input type="number" step="1" min="0" max="1" class="text maxwidth100" name="propvalidate" value="'.dol_escape_htmltag(GETPOST('propvalidate', 'alpha')).'"></td>';
- print '<td><input class="text maxwidth100" name="propcomment" value="'.dol_escape_htmltag(GETPOST('propcomment', 'alpha')).'"></td>';
- print '<td class="center">';
- print '<input type="submit" class="button" name="add" value="'.$langs->trans("Add").'">';
- print '</td></tr>';
- // List of existing properties
- foreach ($properties as $propkey => $propval) {
- /* If from Reflection
- if ($propval->class == $tabobj)
- {
- $propname=$propval->getName();
- $comment=$propval->getDocComment();
- $type=gettype($tmpobjet->$propname);
- $default=$propdefault[$propname];
- // Discard generic properties
- if (in_array($propname, array('element', 'childtables', 'table_element', 'table_element_line', 'class_element_line', 'ismultientitymanaged'))) continue;
- // Keep or not lines
- if (in_array($propname, array('fk_element', 'lines'))) continue;
- }*/
- $propname = $propkey;
- $proplabel = $propval['label'];
- $proptype = $propval['type'];
- $proparrayofkeyval = $propval['arrayofkeyval'];
- $propnotnull = $propval['notnull'];
- $propdefault = $propval['default'];
- $propindex = $propval['index'];
- $propforeignkey = $propval['foreignkey'];
- $propposition = $propval['position'];
- $propenabled = $propval['enabled'];
- $propvisible = $propval['visible'];
- $propnoteditable = $propval['noteditable'];
- $propsearchall = $propval['searchall'];
- $propisameasure = $propval['isameasure'];
- $propcss = $propval['css'];
- $propcssview = $propval['cssview'];
- $propcsslist = $propval['csslist'];
- $prophelp = $propval['help'];
- $propshowoncombobox = $propval['showoncombobox'];
- //$propdisabled=$propval['disabled'];
- $propvalidate = $propval['validate'];
- $propcomment = $propval['comment'];
- print '<tr class="oddeven">';
- print '<td>';
- print dol_escape_htmltag($propname);
- print '</td>';
- print '<td>';
- print dol_escape_htmltag($proplabel);
- print '</td>';
- if ($action == 'editproperty' && $propname == $propertykey) {
- print '<td class="tdoverflowmax200">';
- print '<input type="hidden" name="propname" value="'.dol_escape_htmltag($propname).'">';
- print '<input type="hidden" name="proplabel" value="'.dol_escape_htmltag($proplabel).'">';
- print '<input name="proptype" value="'.dol_escape_htmltag($proptype).'"></input>';
- print '</td>';
- print '<td class="tdoverflowmax200">';
- print '<input name="proparrayofkeyval" value="';
- if (isset($proparrayofkeyval)) {
- print dol_escape_htmltag(json_encode($proparrayofkeyval, JSON_UNESCAPED_UNICODE));
- }
- print '">';
- print '</input>';
- print '</td>';
- print '<td>';
- print '<input class="center width50" name="propnotnull" value="'.dol_escape_htmltag($propnotnull).'">';
- print '</td>';
- print '<td>';
- print '<input class="maxwidth50" name="propdefault" value="'.dol_escape_htmltag($propdefault).'">';
- print '</td>';
- print '<td class="center">';
- print '<input class="center maxwidth50" name="propindex" value="'.dol_escape_htmltag($propindex).'">';
- print '</td>';
- print '<td>';
- print '<input class="center" name="propforeignkey" value="'.dol_escape_htmltag($propforeignkey).'">';
- print '</td>';
- print '<td>';
- print '<input class="right width50" name="propposition" value="'.dol_escape_htmltag($propposition).'">';
- print '</td>';
- print '<td>';
- print '<input class="center" name="propenabled" size="2" value="'.dol_escape_htmltag($propenabled).'">';
- print '</td>';
- print '<td>';
- print '<input class="center" name="propvisible" size="2" value="'.dol_escape_htmltag($propvisible).'">';
- print '</td>';
- print '<td>';
- print '<input class="center" name="propnoteditable" size="2" value="'.dol_escape_htmltag($propnoteditable).'">';
- print '</td>';
- print '<td>';
- print '<input class="center" name="propsearchall" size="2" value="'.dol_escape_htmltag($propsearchall).'">';
- print '</td>';
- print '<td>';
- print '<input class="center" name="propisameasure" size="2" value="'.dol_escape_htmltag($propisameasure).'">';
- print '</td>';
- print '<td>';
- print '<input class="center maxwidth50" name="propcss" value="'.dol_escape_htmltag($propcss).'">';
- print '</td>';
- print '<td>';
- print '<input class="center maxwidth50" name="propcssview" value="'.dol_escape_htmltag($propcssview).'">';
- print '</td>';
- print '<td>';
- print '<input class="center maxwidth50" name="propcsslist" value="'.dol_escape_htmltag($propcsslist).'">';
- print '</td>';
- print '<td>';
- print '<input class="maxwidth100" name="prophelp" value="'.dol_escape_htmltag($prophelp).'">';
- print '</td>';
- print '<td>';
- print '<input class="center maxwidth50" name="propshowoncombobox" value="'.dol_escape_htmltag($propshowoncombobox).'">';
- print '</td>';
- print '<td>';
- print '<input type="number" step="1" min="0" max="1" class="text maxwidth100" name="propvalidate" value="'.dol_escape_htmltag($propvalidate).'">';
- print '</td>';
- print '<td>';
- print '<input class="maxwidth100" name="propcomment" value="'.dol_escape_htmltag($propcomment).'">';
- print '</td>';
- print '<td class="center">';
- print '<input class="button smallpaddingimp" type="submit" name="edit" value="'.$langs->trans("Save").'">';
- print '<input class="button button-cancel smallpaddingimp" type="submit" name="cancel" value="'.$langs->trans("Cancel").'">';
- print '</td>';
- } else {
- print '<td class="tdoverflowmax200">';
- print '<span title="'.dol_escape_htmltag($proptype).'">'.dol_escape_htmltag($proptype).'</span>';
- print '</td>';
- print '<td class="tdoverflowmax200">';
- if ($proparrayofkeyval) {
- print '<span title="'.dol_escape_htmltag(json_encode($proparrayofkeyval, JSON_UNESCAPED_UNICODE)).'">';
- print dol_escape_htmltag(json_encode($proparrayofkeyval, JSON_UNESCAPED_UNICODE));
- print '</span>';
- }
- print '</td>';
- print '<td class="center">';
- print dol_escape_htmltag($propnotnull);
- print '</td>';
- print '<td>';
- print dol_escape_htmltag($propdefault);
- print '</td>';
- print '<td class="center">';
- print $propindex ? '1' : '';
- print '</td>';
- print '<td class="center">';
- print $propforeignkey ? dol_escape_htmltag($propforeignkey) : '';
- print '</td>';
- print '<td class="right">';
- print dol_escape_htmltag($propposition);
- print '</td>';
- print '<td class="center">';
- print $propenabled ? dol_escape_htmltag($propenabled) : '';
- print '</td>';
- print '<td class="center">';
- print $propvisible ? dol_escape_htmltag($propvisible) : '0';
- print '</td>';
- print '<td class="center">';
- print $propnoteditable ? dol_escape_htmltag($propnoteditable) : '';
- print '</td>';
- print '<td class="center">';
- print $propsearchall ? '1' : '';
- print '</td>';
- print '<td class="center">';
- print $propisameasure ? dol_escape_htmltag($propisameasure) : '';
- print '</td>';
- print '<td class="center">';
- print $propcss ? dol_escape_htmltag($propcss) : '';
- print '</td>';
- print '<td class="center">';
- print $propcssview ? dol_escape_htmltag($propcssview) : '';
- print '</td>';
- print '<td class="center">';
- print $propcsslist ? dol_escape_htmltag($propcsslist) : '';
- print '</td>';
- print '<td class="tdoverflowmax200">';
- print $prophelp ? dol_escape_htmltag($prophelp) : '';
- print '</td>';
- print '<td class="center">';
- print $propshowoncombobox ? dol_escape_htmltag($propshowoncombobox) : '';
- print '</td>';
- /*print '<td class="center">';
- print $propdisabled?$propdisabled:'';
- print '</td>';*/
- print '<td class="center">';
- print $propvalidate ? dol_escape_htmltag($propvalidate) : '';
- print '</td>';
- print '<td class="tdoverflowmax200">';
- print '<span title="'.dol_escape_htmltag($propcomment).'">';
- print dol_escape_htmltag($propcomment);
- print '</span>';
- print '</td>';
- print '<td class="center">';
- if ($propname != 'rowid') {
- 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>';
- 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>';
- }
- print '</td>';
- }
- print '</tr>';
- }
- } else {
- if ($tab == 'specifications') {
- if ($action != 'editfile' || empty($file)) {
- print '<span class="opacitymedium">'.$langs->trans("SpecDefDesc").'</span><br>';
- print '<br>';
- $specs = dol_dir_list(dol_buildpath($modulelowercase.'/doc', 0), 'files', 1, '(\.md|\.asciidoc)$', array('\/temp\/'));
- foreach ($specs as $spec) {
- $pathtofile = $modulelowercase.'/doc/'.$spec['relativename'];
- $format = 'asciidoc';
- if (preg_match('/\.md$/i', $spec['name'])) {
- $format = 'markdown';
- }
- print '<span class="fa fa-file-o"></span> '.$langs->trans("SpecificationFile").' : <strong>'.$pathtofile.'</strong>';
- 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>';
- print '<br>';
- }
- } else {
- // Use MD or asciidoc
- //print $langs->trans("UseAsciiDocFormat").'<br>';
- $fullpathoffile = dol_buildpath($file, 0);
- $content = file_get_contents($fullpathoffile);
- // New module
- print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
- print '<input type="hidden" name="token" value="'.newToken().'">';
- print '<input type="hidden" name="action" value="savefile">';
- print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
- print '<input type="hidden" name="tab" value="'.$tab.'">';
- print '<input type="hidden" name="module" value="'.$module.'">';
- $doleditor = new DolEditor('editfilecontent', $content, '', '300', 'Full', 'In', true, false, 'ace', 0, '99%');
- print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ?GETPOST('format', 'aZ09') : 'html'));
- print '<br>';
- print '<center>';
- print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
- print ' ';
- print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
- print '</center>';
- print '</form>';
- }
- }
- 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>';
- }
- print '</table>';
- print '</div>';
- print '</form>';
- } else {
- print '<tr><td><span class="warning">'.$langs->trans('Failed to init the object with the new.').'</warning></td></tr>';
- }
- } catch (Exception $e) {
- print $e->getMessage();
- }
- } else {
- if (empty($forceddirread)) {
- $fullpathoffile = dol_buildpath($file, 0);
- } else {
- $fullpathoffile = $dirread.'/'.$file;
- }
- $content = file_get_contents($fullpathoffile);
- // New module
- print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
- print '<input type="hidden" name="token" value="'.newToken().'">';
- print '<input type="hidden" name="action" value="savefile">';
- print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
- print '<input type="hidden" name="tab" value="'.$tab.'">';
- print '<input type="hidden" name="tabobj" value="'.dol_escape_htmltag($tabobj).'">';
- print '<input type="hidden" name="module" value="'.$module.($forceddirread ? '@'.$dirread : '').'">';
- $doleditor = new DolEditor('editfilecontent', $content, '', '300', 'Full', 'In', true, false, 'ace', 0, '99%');
- print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ?GETPOST('format', 'aZ09') : 'html'));
- print '<br>';
- print '<center>';
- print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
- print ' ';
- print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
- print '</center>';
- print '</form>';
- }
- }
- print dol_get_fiche_end(); // Level 3
- }
- if ($tab == 'menus') {
- $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
- $menus = $moduleobj->menu;
- if ($action != 'editfile' || empty($file)) {
- print '<span class="opacitymedium">';
- $htmlhelp = $langs->trans("MenusDefDescTooltip", '{s1}');
- $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);
- print $form->textwithpicto($langs->trans("MenusDefDesc"), $htmlhelp, 1, 'help', '', 0, 2, 'helpondesc').'<br>';
- print '</span>';
- print '<br>';
- print '<span class="fa fa-file-o"></span> '.$langs->trans("DescriptorFile").' : <strong>'.$pathtofile.'</strong>';
- 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>';
- print '<br>';
- print '<br>';
- print load_fiche_titre($langs->trans("ListOfMenusEntries"), '', '');
- print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
- print '<input type="hidden" name="token" value="'.newToken().'">';
- print '<input type="hidden" name="action" value="addproperty">';
- print '<input type="hidden" name="tab" value="objects">';
- print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
- print '<input type="hidden" name="tabobj" value="'.dol_escape_htmltag($tabobj).'">';
- print '<div class="div-table-responsive">';
- print '<table class="noborder small">';
- print '<tr class="liste_titre">';
- print_liste_field_titre("Type", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
- print_liste_field_titre("LinkToParentMenu", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
- print_liste_field_titre("Title", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
- print_liste_field_titre("mainmenu", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
- print_liste_field_titre("leftmenu", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
- print_liste_field_titre("RelativeURL", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
- print_liste_field_titre("LanguageFile", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
- print_liste_field_titre("Position", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder, 'right ');
- print_liste_field_titre("Enabled", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder, 'center ');
- print_liste_field_titre("Permission", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
- print_liste_field_titre("Target", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
- print_liste_field_titre("UserType", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder, 'right ');
- print "</tr>\n";
- if (count($menus)) {
- foreach ($menus as $menu) {
- print '<tr class="oddeven">';
- print '<td>';
- print dol_escape_htmltag($menu['type']);
- print '</td>';
- print '<td>';
- print dol_escape_htmltag($menu['fk_menu']);
- print '</td>';
- print '<td>';
- print dol_escape_htmltag($menu['titre']);
- print '</td>';
- print '<td>';
- print dol_escape_htmltag($menu['mainmenu']);
- print '</td>';
- print '<td>';
- print dol_escape_htmltag($menu['leftmenu']);
- print '</td>';
- print '<td class="tdoverflowmax300" title="'.dol_escape_htmltag($menu['url']).'">';
- print dol_escape_htmltag($menu['url']);
- print '</td>';
- print '<td>';
- print dol_escape_htmltag($menu['langs']);
- print '</td>';
- print '<td class="right">';
- print dol_escape_htmltag($menu['position']);
- print '</td>';
- print '<td class="center tdoverflowmax200" title="'.dol_escape_htmltag($menu['enabled']).'">';
- print dol_escape_htmltag($menu['enabled']);
- print '</td>';
- print '<td class="center tdoverflowmax200" title="'.dol_escape_htmltag($menu['perms']).'">';
- print dol_escape_htmltag($menu['perms']);
- print '</td>';
- print '<td>';
- print dol_escape_htmltag($menu['target']);
- print '</td>';
- print '<td class="right">';
- print dol_escape_htmltag($menu['user']);
- print '</td>';
- print '</tr>';
- }
- } else {
- print '<tr><td colspan="5"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
- }
- print '</table>';
- print '</div>';
- print '</form>';
- } else {
- $fullpathoffile = dol_buildpath($file, 0);
- $content = file_get_contents($fullpathoffile);
- // New module
- print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
- print '<input type="hidden" name="token" value="'.newToken().'">';
- print '<input type="hidden" name="action" value="savefile">';
- print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
- print '<input type="hidden" name="tab" value="'.$tab.'">';
- print '<input type="hidden" name="module" value="'.$module.'">';
- $doleditor = new DolEditor('editfilecontent', $content, '', '300', 'Full', 'In', true, false, 'ace', 0, '99%');
- print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ?GETPOST('format', 'aZ09') : 'html'));
- print '<br>';
- print '<center>';
- print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
- print ' ';
- print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
- print '</center>';
- print '</form>';
- }
- }
- if ($tab == 'permissions') {
- $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
- $perms = $moduleobj->rights;
- if ($action != 'editfile' || empty($file)) {
- print '<span class="opacitymedium">';
- $htmlhelp = $langs->trans("PermissionsDefDescTooltip", '{s1}');
- $htmlhelp = str_replace('{s1}', '<a target="adminbis" class="nofocusvisible" href="'.DOL_URL_ROOT.'/admin/perms.php">'.$langs->trans('DefaultRights').'</a>', $htmlhelp);
- print $form->textwithpicto($langs->trans("PermissionsDefDesc"), $htmlhelp, 1, 'help', '', 0, 2, 'helpondesc').'<br>';
- print '</span>';
- print '<br>';
- print '<span class="fa fa-file-o"></span> '.$langs->trans("DescriptorFile").' : <strong>'.$pathtofile.'</strong>';
- 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>';
- print '<br>';
- print '<br>';
- print load_fiche_titre($langs->trans("ListOfPermissionsDefined"), '', '');
- print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
- print '<input type="hidden" name="token" value="'.newToken().'">';
- print '<input type="hidden" name="action" value="addproperty">';
- print '<input type="hidden" name="tab" value="objects">';
- print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
- print '<input type="hidden" name="tabobj" value="'.dol_escape_htmltag($tabobj).'">';
- print '<div class="div-table-responsive">';
- print '<table class="noborder">';
- print '<tr class="liste_titre">';
- print_liste_field_titre("ID", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
- print_liste_field_titre("Label", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
- print_liste_field_titre("Permission", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
- print_liste_field_titre("", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
- print "</tr>\n";
- if (count($perms)) {
- foreach ($perms as $perm) {
- print '<tr class="oddeven">';
- print '<td>';
- print $perm[0];
- print '</td>';
- print '<td>';
- print $langs->trans($perm[1]);
- print '</td>';
- print '<td>';
- print $perm[4];
- print '</td>';
- print '<td>';
- print $perm[5];
- print '</td>';
- print '</tr>';
- }
- } else {
- print '<tr><td colspan="4"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
- }
- print '</table>';
- print '</div>';
- print '</form>';
- } else {
- $fullpathoffile = dol_buildpath($file, 0);
- $content = file_get_contents($fullpathoffile);
- // New module
- print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
- print '<input type="hidden" name="token" value="'.newToken().'">';
- print '<input type="hidden" name="action" value="savefile">';
- print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
- print '<input type="hidden" name="tab" value="'.$tab.'">';
- print '<input type="hidden" name="module" value="'.$module.'">';
- $doleditor = new DolEditor('editfilecontent', $content, '', '300', 'Full', 'In', true, false, 'ace', 0, '99%');
- print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ?GETPOST('format', 'aZ09') : 'html'));
- print '<br>';
- print '<center>';
- print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
- print ' ';
- print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
- print '</center>';
- print '</form>';
- }
- }
- if ($tab == 'hooks') {
- if ($action != 'editfile' || empty($file)) {
- print '<span class="opacitymedium">'.$langs->trans("HooksDefDesc").'</span><br>';
- print '<br>';
- print '<table>';
- $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
- print '<tr><td>';
- print '<span class="fa fa-file-o"></span> '.$langs->trans("DescriptorFile").' : <strong class="">'.$pathtofile.'</strong>';
- print '</td><td>';
- 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>';
- print '</td></tr>';
- print '<tr><td>';
- $pathtohook = strtolower($module).'/class/actions_'.strtolower($module).'.class.php';
- print '<span class="fa fa-file-o"></span> '.$langs->trans("HooksFile").' : ';
- if (dol_is_file($dirins.'/'.$pathtohook)) {
- print '<strong>'.$pathtohook.'</strong>';
- print '</td>';
- 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> ';
- 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>';
- } else {
- print '<span class="opacitymedium">'.$langs->trans("FileNotYetGenerated").'</span>';
- 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>';
- print '<td></td>';
- }
- print '</tr>';
- } else {
- $fullpathoffile = dol_buildpath($file, 0);
- $content = file_get_contents($fullpathoffile);
- // New module
- print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
- print '<input type="hidden" name="token" value="'.newToken().'">';
- print '<input type="hidden" name="action" value="savefile">';
- print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
- print '<input type="hidden" name="tab" value="'.$tab.'">';
- print '<input type="hidden" name="module" value="'.$module.'">';
- $doleditor = new DolEditor('editfilecontent', $content, '', '300', 'Full', 'In', true, false, 'ace', 0, '99%');
- print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ?GETPOST('format', 'aZ09') : 'html'));
- print '<br>';
- print '<center>';
- print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
- print ' ';
- print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
- print '</center>';
- print '</form>';
- }
- }
- if ($tab == 'triggers') {
- require_once DOL_DOCUMENT_ROOT.'/core/class/interfaces.class.php';
- $interfaces = new Interfaces($db);
- $triggers = $interfaces->getTriggersList(array('/'.strtolower($module).'/core/triggers'));
- if ($action != 'editfile' || empty($file)) {
- print '<span class="opacitymedium">'.$langs->trans("TriggerDefDesc").'</span><br>';
- print '<br>';
- print '<table>';
- $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
- print '<tr><td>';
- print '<span class="fa fa-file-o"></span> '.$langs->trans("DescriptorFile").' : <strong class="">'.$pathtofile.'</strong>';
- print '</td><td>';
- 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>';
- print '</td></tr>';
- if (!empty($triggers)) {
- foreach ($triggers as $trigger) {
- $pathtofile = $trigger['relpath'];
- print '<tr><td>';
- print '<span class="fa fa-file-o"></span> '.$langs->trans("TriggersFile").' : <strong>'.$pathtofile.'</strong>';
- 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>';
- 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>';
- print '</tr>';
- }
- } else {
- print '<tr><td>';
- print '<span class="fa fa-file-o"></span> '.$langs->trans("TriggersFile");
- print ' : <span class="opacitymedium">'.$langs->trans("FileNotYetGenerated").'</span>';
- print '<a href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=inittrigger&format=php">'.img_picto('Generate', 'generate', 'class="paddingleft"').'</a></td>';
- print '<td></td>';
- print '</tr>';
- }
- print '</table>';
- } else {
- $fullpathoffile = dol_buildpath($file, 0);
- $content = file_get_contents($fullpathoffile);
- // New module
- print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
- print '<input type="hidden" name="token" value="'.newToken().'">';
- print '<input type="hidden" name="action" value="savefile">';
- print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
- print '<input type="hidden" name="tab" value="'.$tab.'">';
- print '<input type="hidden" name="module" value="'.$module.'">';
- $doleditor = new DolEditor('editfilecontent', $content, '', '300', 'Full', 'In', true, false, 'ace', 0, '99%');
- print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ?GETPOST('format', 'aZ09') : 'html'));
- print '<br>';
- print '<center>';
- print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
- print ' ';
- print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
- print '</center>';
- print '</form>';
- }
- }
- if ($tab == 'css') {
- if ($action != 'editfile' || empty($file)) {
- print '<span class="opacitymedium">'.$langs->trans("CSSDesc").'</span><br>';
- print '<br>';
- print '<table>';
- print '<tr><td>';
- $pathtohook = strtolower($module).'/css/'.strtolower($module).'.css.php';
- print '<span class="fa fa-file-o"></span> '.$langs->trans("CSSFile").' : ';
- if (dol_is_file($dirins.'/'.$pathtohook)) {
- print '<strong>'.$pathtohook.'</strong>';
- 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>';
- 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>';
- } else {
- print '<span class="opacitymedium">'.$langs->trans("FileNotYetGenerated").'</span>';
- 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>';
- }
- print '</tr>';
- } else {
- $fullpathoffile = dol_buildpath($file, 0);
- $content = file_get_contents($fullpathoffile);
- // New module
- print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
- print '<input type="hidden" name="token" value="'.newToken().'">';
- print '<input type="hidden" name="action" value="savefile">';
- print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
- print '<input type="hidden" name="tab" value="'.$tab.'">';
- print '<input type="hidden" name="module" value="'.$module.'">';
- $doleditor = new DolEditor('editfilecontent', $content, '', '300', 'Full', 'In', true, false, 'ace', 0, '99%');
- print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ?GETPOST('format', 'aZ09') : 'html'));
- print '<br>';
- print '<center>';
- print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
- print ' ';
- print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
- print '</center>';
- print '</form>';
- }
- }
- if ($tab == 'js') {
- if ($action != 'editfile' || empty($file)) {
- print '<span class="opacitymedium">'.$langs->trans("JSDesc").'</span><br>';
- print '<br>';
- print '<table>';
- print '<tr><td>';
- $pathtohook = strtolower($module).'/js/'.strtolower($module).'.js.php';
- print '<span class="fa fa-file-o"></span> '.$langs->trans("JSFile").' : ';
- if (dol_is_file($dirins.'/'.$pathtohook)) {
- print '<strong>'.$pathtohook.'</strong>';
- 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>';
- 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>';
- } else {
- print '<span class="opacitymedium">'.$langs->trans("FileNotYetGenerated").'</span>';
- 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>';
- }
- print '</tr>';
- } else {
- $fullpathoffile = dol_buildpath($file, 0);
- $content = file_get_contents($fullpathoffile);
- // New module
- print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
- print '<input type="hidden" name="token" value="'.newToken().'">';
- print '<input type="hidden" name="action" value="savefile">';
- print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
- print '<input type="hidden" name="tab" value="'.$tab.'">';
- print '<input type="hidden" name="module" value="'.$module.'">';
- $doleditor = new DolEditor('editfilecontent', $content, '', '300', 'Full', 'In', true, false, 'ace', 0, '99%');
- print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ?GETPOST('format', 'aZ09') : 'html'));
- print '<br>';
- print '<center>';
- print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
- print ' ';
- print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
- print '</center>';
- print '</form>';
- }
- }
- if ($tab == 'widgets') {
- require_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
- $widgets = ModeleBoxes::getWidgetsList(array('/'.strtolower($module).'/core/boxes'));
- if ($action != 'editfile' || empty($file)) {
- print '<span class="opacitymedium">'.$langs->trans("WidgetDesc").'</span><br>';
- print '<br>';
- print '<table>';
- if (!empty($widgets)) {
- foreach ($widgets as $widget) {
- $pathtofile = $widget['relpath'];
- print '<tr><td><span class="fa fa-file-o"></span> '.$langs->trans("WidgetFile").' : <strong>'.$pathtofile.'</strong>';
- 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>';
- 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>';
- print '</tr>';
- }
- } else {
- print '<tr><td><span class="fa fa-file-o"></span> '.$langs->trans("WidgetFile").' : <span class="opacitymedium">'.$langs->trans("NoWidget").'</span>';
- 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>';
- print '</td></tr>';
- }
- print '</table>';
- } else {
- $fullpathoffile = dol_buildpath($file, 0);
- $content = file_get_contents($fullpathoffile);
- // New module
- print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
- print '<input type="hidden" name="token" value="'.newToken().'">';
- print '<input type="hidden" name="action" value="savefile">';
- print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
- print '<input type="hidden" name="tab" value="'.$tab.'">';
- print '<input type="hidden" name="module" value="'.$module.'">';
- $doleditor = new DolEditor('editfilecontent', $content, '', '300', 'Full', 'In', true, false, 'ace', 0, '99%');
- print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ?GETPOST('format', 'aZ09') : 'html'));
- print '<br>';
- print '<center>';
- print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
- print ' ';
- print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
- print '</center>';
- print '</form>';
- }
- }
- if ($tab == 'exportimport') {
- $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
- $exportlist = $moduleobj->export_label;
- $importlist = $moduleobj->import_label;
- if ($action != 'editfile' || empty($file)) {
- print '<span class="opacitymedium">'.$langs->transnoentities('ImportExportProfiles').'</span><br>';
- print '<br>';
- print '<span class="fa fa-file-o"></span> '.$langs->trans("DescriptorFile").' : <strong>'.$pathtofile.'</strong>';
- 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>';
- print '<br>';
- } else {
- $fullpathoffile = dol_buildpath($file, 0);
- $content = file_get_contents($fullpathoffile);
- // New module
- print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
- print '<input type="hidden" name="token" value="'.newToken().'">';
- print '<input type="hidden" name="action" value="savefile">';
- print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
- print '<input type="hidden" name="tab" value="'.$tab.'">';
- print '<input type="hidden" name="module" value="'.$module.'">';
- $doleditor = new DolEditor('editfilecontent', $content, '', '300', 'Full', 'In', true, false, 'ace', 0, '99%');
- print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ?GETPOST('format', 'aZ09') : 'html'));
- print '<br>';
- print '<center>';
- print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
- print ' ';
- print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
- print '</center>';
- print '</form>';
- }
- }
- if ($tab == 'cli') {
- $clifiles = array();
- $i = 0;
- $dircli = array('/'.strtolower($module).'/scripts');
- foreach ($dircli as $reldir) {
- $dir = dol_buildpath($reldir, 0);
- $newdir = dol_osencode($dir);
- // Check if directory exists (we do not use dol_is_dir to avoid loading files.lib.php at each call)
- if (!is_dir($newdir)) {
- continue;
- }
- $handle = opendir($newdir);
- if (is_resource($handle)) {
- while (($tmpfile = readdir($handle)) !== false) {
- if (is_readable($newdir.'/'.$file) && preg_match('/^(.+)\.php/', $tmpfile, $reg)) {
- if (preg_match('/\.back$/', $tmpfile)) {
- continue;
- }
- $clifiles[$i]['relpath'] = preg_replace('/^\//', '', $reldir).'/'.$tmpfile;
- $i++;
- }
- }
- closedir($handle);
- }
- }
- if ($action != 'editfile' || empty($file)) {
- print '<span class="opacitymedium">'.$langs->trans("CLIDesc").'</span><br>';
- print '<br>';
- print '<table>';
- if (!empty($clifiles)) {
- foreach ($clifiles as $clifile) {
- $pathtofile = $clifile['relpath'];
- print '<tr><td><span class="fa fa-file-o"></span> '.$langs->trans("CLIFile").' : <strong>'.$pathtofile.'</strong>';
- 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>';
- 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>';
- print '</tr>';
- }
- } else {
- print '<tr><td><span class="fa fa-file-o"></span> '.$langs->trans("CLIFile").' : <span class="opacitymedium">'.$langs->trans("FileNotYetGenerated"); '</span>';
- 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>';
- print '</td></tr>';
- }
- print '</table>';
- } else {
- $fullpathoffile = dol_buildpath($file, 0);
- $content = file_get_contents($fullpathoffile);
- // New module
- print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
- print '<input type="hidden" name="token" value="'.newToken().'">';
- print '<input type="hidden" name="action" value="savefile">';
- print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
- print '<input type="hidden" name="tab" value="'.$tab.'">';
- print '<input type="hidden" name="module" value="'.$module.'">';
- $doleditor = new DolEditor('editfilecontent', $content, '', '300', 'Full', 'In', true, false, 'ace', 0, '99%');
- print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ?GETPOST('format', 'aZ09') : 'html'));
- print '<br>';
- print '<center>';
- print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
- print ' ';
- print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
- print '</center>';
- print '</form>';
- }
- }
- if ($tab == 'cron') {
- $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
- $cronjobs = $moduleobj->cronjobs;
- if ($action != 'editfile' || empty($file)) {
- 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>';
- print '<br>';
- print '<span class="fa fa-file-o"></span> '.$langs->trans("DescriptorFile").' : <strong>'.$pathtofile.'</strong>';
- 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>';
- print '<br>';
- print '<br>';
- print load_fiche_titre($langs->trans("CronJobProfiles"), '', '');
- print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
- print '<input type="hidden" name="token" value="'.newToken().'">';
- print '<input type="hidden" name="action" value="addproperty">';
- print '<input type="hidden" name="tab" value="objects">';
- print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
- print '<input type="hidden" name="tabobj" value="'.dol_escape_htmltag($tabobj).'">';
- print '<div class="div-table-responsive">';
- print '<table class="noborder">';
- print '<tr class="liste_titre">';
- print_liste_field_titre("CronLabel", $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder);
- print_liste_field_titre("CronTask", '', '', "", $param, '', $sortfield, $sortorder);
- print_liste_field_titre("CronFrequency", '', "", "", $param, '', $sortfield, $sortorder);
- print_liste_field_titre("StatusAtInstall", $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder);
- print_liste_field_titre("Comment", $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder);
- print "</tr>\n";
- if (count($cronjobs)) {
- foreach ($cronjobs as $cron) {
- print '<tr class="oddeven">';
- print '<td>';
- print $cron['label'];
- print '</td>';
- print '<td>';
- if ($cron['jobtype'] == 'method') {
- $text = $langs->trans("CronClass");
- $texttoshow = $langs->trans('CronModule').': '.$module.'<br>';
- $texttoshow .= $langs->trans('CronClass').': '.$cron['class'].'<br>';
- $texttoshow .= $langs->trans('CronObject').': '.$cron['objectname'].'<br>';
- $texttoshow .= $langs->trans('CronMethod').': '.$cron['method'];
- $texttoshow .= '<br>'.$langs->trans('CronArgs').': '.$cron['parameters'];
- $texttoshow .= '<br>'.$langs->trans('Comment').': '.$langs->trans($cron['comment']);
- } elseif ($cron['jobtype'] == 'command') {
- $text = $langs->trans('CronCommand');
- $texttoshow = $langs->trans('CronCommand').': '.dol_trunc($cron['command']);
- $texttoshow .= '<br>'.$langs->trans('CronArgs').': '.$cron['parameters'];
- $texttoshow .= '<br>'.$langs->trans('Comment').': '.$langs->trans($cron['comment']);
- }
- print $form->textwithpicto($text, $texttoshow, 1);
- print '</td>';
- print '<td>';
- if ($cron['unitfrequency'] == "60") {
- print $langs->trans('CronEach')." ".($cron['frequency'])." ".$langs->trans('Minutes');
- }
- if ($cron['unitfrequency'] == "3600") {
- print $langs->trans('CronEach')." ".($cron['frequency'])." ".$langs->trans('Hours');
- }
- if ($cron['unitfrequency'] == "86400") {
- print $langs->trans('CronEach')." ".($cron['frequency'])." ".$langs->trans('Days');
- }
- if ($cron['unitfrequency'] == "604800") {
- print $langs->trans('CronEach')." ".($cron['frequency'])." ".$langs->trans('Weeks');
- }
- print '</td>';
- print '<td>';
- print $cron['status'];
- print '</td>';
- print '<td>';
- if (!empty($cron['comment'])) {
- print $cron['comment'];
- }
- print '</td>';
- print '</tr>';
- }
- } else {
- print '<tr><td colspan="5"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
- }
- print '</table>';
- print '</div>';
- print '</form>';
- } else {
- $fullpathoffile = dol_buildpath($file, 0);
- $content = file_get_contents($fullpathoffile);
- // New module
- print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
- print '<input type="hidden" name="token" value="'.newToken().'">';
- print '<input type="hidden" name="action" value="savefile">';
- print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
- print '<input type="hidden" name="tab" value="'.$tab.'">';
- print '<input type="hidden" name="module" value="'.$module.'">';
- $doleditor = new DolEditor('editfilecontent', $content, '', '300', 'Full', 'In', true, false, 'ace', 0, '99%');
- print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ?GETPOST('format', 'aZ09') : 'html'));
- print '<br>';
- print '<center>';
- print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
- print ' ';
- print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
- print '</center>';
- print '</form>';
- }
- }
- if ($tab == 'specifications') {
- $specs = dol_dir_list(dol_buildpath($modulelowercase.'/doc', 0), 'files', 1, '(\.md|\.asciidoc)$', array('\/temp\/'));
- if ($action != 'editfile' || empty($file)) {
- print '<span class="opacitymedium">'.$langs->trans("SpecDefDesc").'</span><br>';
- print '<br>';
- print '<table>';
- if (is_array($specs) && !empty($specs)) {
- foreach ($specs as $spec) {
- $pathtofile = $modulelowercase.'/doc/'.$spec['relativename'];
- $format = 'asciidoc';
- if (preg_match('/\.md$/i', $spec['name'])) {
- $format = 'markdown';
- }
- print '<tr><td>';
- print '<span class="fa fa-file-o"></span> '.$langs->trans("SpecificationFile").' : <strong>'.$pathtofile.'</strong>';
- 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>';
- 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>';
- print '</tr>';
- }
- } else {
- print '<tr><td>';
- print '<span class="fa fa-file-o"></span> '.$langs->trans("SpecificationFile").' : <span class="opacitymedium">'.$langs->trans("FileNotYetGenerated").'</span>';
- 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>';
- print '</tr>';
- }
- print '</table>';
- } else {
- // Use MD or asciidoc
- //print $langs->trans("UseAsciiDocFormat").'<br>';
- $fullpathoffile = dol_buildpath($file, 0);
- $content = file_get_contents($fullpathoffile);
- // New module
- print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
- print '<input type="hidden" name="token" value="'.newToken().'">';
- print '<input type="hidden" name="action" value="savefile">';
- print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
- print '<input type="hidden" name="tab" value="'.$tab.'">';
- print '<input type="hidden" name="module" value="'.$module.'">';
- $doleditor = new DolEditor('editfilecontent', $content, '', '300', 'Full', 'In', true, false, 'ace', 0, '99%');
- print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ?GETPOST('format', 'aZ09') : 'html'));
- print '<br>';
- print '<center>';
- print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
- print ' ';
- print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
- print '</center>';
- print '</form>';
- }
- print '<br><br><br>';
- $FILENAMEDOC = $modulelowercase.'.html';
- $FILENAMEDOCPDF = $modulelowercase.'.pdf';
- $outputfiledoc = dol_buildpath($modulelowercase, 0).'/doc/'.$FILENAMEDOC;
- $outputfiledocurl = dol_buildpath($modulelowercase, 1).'/doc/'.$FILENAMEDOC;
- $outputfiledocrel = $modulelowercase.'/doc/'.$FILENAMEDOC;
- $outputfiledocpdf = dol_buildpath($modulelowercase, 0).'/doc/'.$FILENAMEDOCPDF;
- $outputfiledocurlpdf = dol_buildpath($modulelowercase, 1).'/doc/'.$FILENAMEDOCPDF;
- $outputfiledocrelpdf = $modulelowercase.'/doc/'.$FILENAMEDOCPDF;
- // HTML
- print '<span class="fa fa-file-o"></span> '.$langs->trans("PathToModuleDocumentation", "HTML").' : ';
- if (!dol_is_file($outputfiledoc)) {
- print '<span class="opacitymedium">'.$langs->trans("FileNotYetGenerated").'</span>';
- } else {
- print '<strong>';
- print '<a href="'.$outputfiledocurl.'" target="_blank" rel="noopener noreferrer">';
- print $outputfiledoc;
- print '</a>';
- print '</strong>';
- print ' <span class="opacitymedium">('.$langs->trans("GeneratedOn").' '.dol_print_date(dol_filemtime($outputfiledoc), 'dayhour').')</span>';
- 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>';
- }
- print '</strong><br>';
- // PDF
- print '<span class="fa fa-file-o"></span> '.$langs->trans("PathToModuleDocumentation", "PDF").' : ';
- if (!dol_is_file($outputfiledocpdf)) {
- print '<span class="opacitymedium">'.$langs->trans("FileNotYetGenerated").'</span>';
- } else {
- print '<strong>';
- print '<a href="'.$outputfiledocurlpdf.'" target="_blank" rel="noopener noreferrer">';
- print $outputfiledocpdf;
- print '</a>';
- print '</strong>';
- print ' <span class="opacitymedium">('.$langs->trans("GeneratedOn").' '.dol_print_date(dol_filemtime($outputfiledocpdf), 'dayhour').')</span>';
- 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>';
- }
- print '</strong><br>';
- print '<br>';
- print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST" name="generatedoc">';
- print '<input type="hidden" name="token" value="'.newToken().'">';
- print '<input type="hidden" name="action" value="generatedoc">';
- print '<input type="hidden" name="tab" value="'.dol_escape_htmltag($tab).'">';
- print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
- print '<input type="submit" class="button" name="generatedoc" value="'.$langs->trans("BuildDocumentation").'"';
- if (!is_array($specs) || empty($specs)) {
- print ' disabled="disabled"';
- }
- print '>';
- print '</form>';
- }
- if ($tab == 'buildpackage') {
- print '<span class="opacitymedium">'.$langs->trans("BuildPackageDesc").'</span>';
- print '<br>';
- if (!class_exists('ZipArchive') && !defined('ODTPHP_PATHTOPCLZIP')) {
- print img_warning().' '.$langs->trans("ErrNoZipEngine");
- print '<br>';
- }
- $modulelowercase = strtolower($module);
- // Zip file to build
- $FILENAMEZIP = '';
- // Load module
- $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
- dol_include_once($pathtofile);
- $class = 'mod'.$module;
- if (class_exists($class)) {
- try {
- $moduleobj = new $class($db);
- } catch (Exception $e) {
- $error++;
- dol_print_error($db, $e->getMessage());
- }
- } else {
- $error++;
- $langs->load("errors");
- dol_print_error($db, $langs->trans("ErrorFailedToLoadModuleDescriptorForXXX", $module));
- exit;
- }
- $arrayversion = explode('.', $moduleobj->version, 3);
- if (count($arrayversion)) {
- $FILENAMEZIP = "module_".$modulelowercase.'-'.$arrayversion[0].(empty($arrayversion[1]) ? '.0' : '.'.$arrayversion[1]).($arrayversion[2] ? ".".$arrayversion[2] : '').".zip";
- $outputfilezip = dol_buildpath($modulelowercase, 0).'/bin/'.$FILENAMEZIP;
- }
- print '<br>';
- print '<span class="fa fa-file-o"></span> '.$langs->trans("PathToModulePackage").' : ';
- if (!dol_is_file($outputfilezip)) {
- print '<span class="opacitymedium">'.$langs->trans("FileNotYetGenerated").'</span>';
- } else {
- $relativepath = $modulelowercase.'/bin/'.$FILENAMEZIP;
- print '<strong><a href="'.DOL_URL_ROOT.'/document.php?modulepart=packages&file='.urlencode($relativepath).'">'.$outputfilezip.'</a></strong>';
- print ' <span class="opacitymedium">('.$langs->trans("GeneratedOn").' '.dol_print_date(dol_filemtime($outputfilezip), 'dayhour').')</span>';
- 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>';
- }
- print '</strong>';
- print '<br>';
- print '<br>';
- print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST" name="generatepackage">';
- print '<input type="hidden" name="token" value="'.newToken().'">';
- print '<input type="hidden" name="action" value="generatepackage">';
- print '<input type="hidden" name="tab" value="'.dol_escape_htmltag($tab).'">';
- print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
- print '<input type="submit" class="button" name="generatepackage" value="'.$langs->trans("BuildPackage").'">';
- print '</form>';
- }
- if ($tab != 'description') {
- print dol_get_fiche_end();
- }
- }
- }
- print dol_get_fiche_end(); // End modules
- // End of page
- llxFooter();
- $db->close();
|