index.php 297 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495
  1. <?php
  2. /* Copyright (C) 2004-2023 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2018-2019 Nicolas ZABOURI <info@inovea-conseil.com>
  4. * Copyright (C) 2023 Alexandre Janniaux <alexandre.janniaux@gmail.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  18. *
  19. * You can also make a direct call the page with parameter like this:
  20. * htdocs/modulebuilder/index.php?module=Inventory@/pathtodolibarr/htdocs/product
  21. */
  22. /**
  23. * \file htdocs/modulebuilder/index.php
  24. * \brief Home page for module builder module
  25. *
  26. * You can add parameter dirins=/home/ldestailleur/git/dolibarr/htdocs/mymodule to force generation of module
  27. * into the dirins directory.
  28. */
  29. if (!defined('NOSCANPOSTFORINJECTION')) {
  30. define('NOSCANPOSTFORINJECTION', '1'); // Do not check anti SQL+XSS injection attack test
  31. }
  32. // Load Dolibarr environment
  33. require '../main.inc.php';
  34. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  35. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  36. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
  37. require_once DOL_DOCUMENT_ROOT.'/core/lib/modulebuilder.lib.php';
  38. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  39. require_once DOL_DOCUMENT_ROOT.'/core/class/utils.class.php';
  40. // Load translation files required by the page
  41. $langs->loadLangs(array("admin", "modulebuilder", "other", "cron", "errors"));
  42. // GET Parameters
  43. $action = GETPOST('action', 'aZ09');
  44. $confirm = GETPOST('confirm', 'alpha');
  45. $cancel = GETPOST('cancel', 'alpha');
  46. $sortfield = GETPOST('sortfield', 'alpha');
  47. $sortorder = GETPOST('sortorder', 'alpha');
  48. $module = GETPOST('module', 'alpha');
  49. $tab = GETPOST('tab', 'aZ09');
  50. $tabobj = GETPOST('tabobj', 'alpha');
  51. $tabdic = GETPOST('tabdic', 'alpha');
  52. $propertykey = GETPOST('propertykey', 'alpha');
  53. if (empty($module)) {
  54. $module = 'initmodule';
  55. }
  56. if (empty($tab)) {
  57. $tab = 'description';
  58. }
  59. if (empty($tabobj)) {
  60. $tabobj = 'newobjectifnoobj';
  61. }
  62. if (empty($tabdic)) {
  63. $tabdic = 'newdicifnodic';
  64. }
  65. $file = GETPOST('file', 'alpha');
  66. $modulename = dol_sanitizeFileName(GETPOST('modulename', 'alpha'));
  67. $objectname = dol_sanitizeFileName(GETPOST('objectname', 'alpha'));
  68. $dicname = dol_sanitizeFileName(GETPOST('dicname', 'alpha'));
  69. $editorname= GETPOST('editorname', 'alpha');
  70. $editorurl= GETPOST('editorurl', 'alpha');
  71. $version= GETPOST('version', 'alpha');
  72. $family= GETPOST('family', 'alpha');
  73. $picto= GETPOST('idpicto', 'alpha');
  74. $idmodule= GETPOST('idmodule', 'alpha');
  75. // Security check
  76. if (!isModEnabled('modulebuilder')) {
  77. accessforbidden('Module ModuleBuilder not enabled');
  78. }
  79. if (!$user->hasRight("modulebuilder", "run")) {
  80. accessforbidden('ModuleBuilderNotAllowed');
  81. }
  82. // Dir for custom dirs
  83. $tmp = explode(',', $dolibarr_main_document_root_alt);
  84. $dirins = $tmp[0];
  85. $dirread = $dirins;
  86. $forceddirread = 0;
  87. $tmpdir = explode('@', $module);
  88. if (!empty($tmpdir[1])) {
  89. $module = $tmpdir[0];
  90. $dirread = $tmpdir[1];
  91. $forceddirread = 1;
  92. }
  93. if (GETPOST('dirins', 'alpha')) {
  94. $dirread = $dirins = GETPOST('dirins', 'alpha');
  95. $forceddirread = 1;
  96. }
  97. $FILEFLAG = 'modulebuilder.txt';
  98. $now = dol_now();
  99. $newmask = 0;
  100. if (empty($newmask) && getDolGlobalString('MAIN_UMASK')) {
  101. $newmask = $conf->global->MAIN_UMASK;
  102. }
  103. if (empty($newmask)) { // This should no happen
  104. $newmask = '0664';
  105. }
  106. $result = restrictedArea($user, 'modulebuilder', null);
  107. $error = 0;
  108. $form = new Form($db);
  109. // Define $listofmodules
  110. $dirsrootforscan = array($dirread);
  111. // Add also the core modules into the list of modules to show/edit
  112. if ($dirread != DOL_DOCUMENT_ROOT && (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 2 || getDolGlobalString('MODULEBUILDER_ADD_DOCUMENT_ROOT'))) {
  113. $dirsrootforscan[] = DOL_DOCUMENT_ROOT;
  114. }
  115. // Search modules to edit
  116. $textforlistofdirs = '<!-- Directory scanned -->'."\n";
  117. $listofmodules = array();
  118. $i = 0;
  119. foreach ($dirsrootforscan as $tmpdirread) {
  120. $moduletype = 'external';
  121. if ($tmpdirread == DOL_DOCUMENT_ROOT) {
  122. $moduletype = 'internal';
  123. }
  124. $dirsincustom = dol_dir_list($tmpdirread, 'directories');
  125. if (is_array($dirsincustom) && count($dirsincustom) > 0) {
  126. foreach ($dirsincustom as $dircustomcursor) {
  127. $fullname = $dircustomcursor['fullname'];
  128. if (dol_is_file($fullname.'/'.$FILEFLAG)) {
  129. // Get real name of module (MyModule instead of mymodule)
  130. $dirtoscanrel = basename($fullname).'/core/modules/';
  131. $descriptorfiles = dol_dir_list(dirname($fullname).'/'.$dirtoscanrel, 'files', 0, 'mod.*\.class\.php$');
  132. if (empty($descriptorfiles)) { // If descriptor not found into module dir, we look into main module dir.
  133. $dirtoscanrel = 'core/modules/';
  134. $descriptorfiles = dol_dir_list($fullname.'/../'.$dirtoscanrel, 'files', 0, 'mod'.strtoupper(basename($fullname)).'\.class\.php$');
  135. }
  136. $modulenamewithcase = '';
  137. $moduledescriptorrelpath = '';
  138. $moduledescriptorfullpath = '';
  139. foreach ($descriptorfiles as $descriptorcursor) {
  140. $modulenamewithcase = preg_replace('/^mod/', '', $descriptorcursor['name']);
  141. $modulenamewithcase = preg_replace('/\.class\.php$/', '', $modulenamewithcase);
  142. $moduledescriptorrelpath = $dirtoscanrel.$descriptorcursor['name'];
  143. $moduledescriptorfullpath = $descriptorcursor['fullname'];
  144. //var_dump($descriptorcursor);
  145. }
  146. if ($modulenamewithcase) {
  147. $listofmodules[$dircustomcursor['name']] = array(
  148. 'modulenamewithcase'=>$modulenamewithcase,
  149. 'moduledescriptorrelpath'=> $moduledescriptorrelpath,
  150. 'moduledescriptorfullpath'=>$moduledescriptorfullpath,
  151. 'moduledescriptorrootpath'=>$tmpdirread,
  152. 'moduletype'=>$moduletype
  153. );
  154. }
  155. //var_dump($listofmodules);
  156. }
  157. }
  158. }
  159. if ($forceddirread && empty($listofmodules)) { // $forceddirread is 1 if we forced dir to read with dirins=... or with module=...@mydir
  160. $listofmodules[strtolower($module)] = array(
  161. 'modulenamewithcase'=>$module,
  162. 'moduledescriptorrelpath'=> 'notyetimplemented',
  163. 'moduledescriptorfullpath'=> 'notyetimplemented',
  164. 'moduledescriptorrootpath'=> 'notyetimplemented',
  165. );
  166. }
  167. // Show description of content
  168. $newdircustom = $dirins;
  169. if (empty($newdircustom)) {
  170. $newdircustom = img_warning();
  171. }
  172. // If dirread was forced to somewhere else, by using URL
  173. // htdocs/modulebuilder/index.php?module=Inventory@/home/ldestailleur/git/dolibarr/htdocs/product
  174. if (empty($i)) {
  175. $textforlistofdirs .= $langs->trans("DirScanned").' : ';
  176. } else {
  177. $textforlistofdirs .= ', ';
  178. }
  179. $textforlistofdirs .= '<strong class="wordbreakimp">'.$tmpdirread.'</strong>';
  180. if ($tmpdirread == DOL_DOCUMENT_ROOT) {
  181. if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 2) {
  182. $textforlistofdirs .= $form->textwithpicto('', $langs->trans("ConstantIsOn", "MAIN_FEATURES_LEVEL"));
  183. }
  184. if (getDolGlobalString('MODULEBUILDER_ADD_DOCUMENT_ROOT')) {
  185. $textforlistofdirs .= $form->textwithpicto('', $langs->trans("ConstantIsOn", "MODULEBUILDER_ADD_DOCUMENT_ROOT"));
  186. }
  187. }
  188. $i++;
  189. }
  190. /*
  191. * Actions
  192. */
  193. if ($dirins && $action == 'initmodule' && $modulename) {
  194. $modulename = ucfirst($modulename); // Force first letter in uppercase
  195. if (preg_match('/[^a-z0-9_]/i', $modulename)) {
  196. $error++;
  197. setEventMessages($langs->trans("SpaceOrSpecialCharAreNotAllowed"), null, 'errors');
  198. }
  199. if (!$error) {
  200. $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
  201. $destdir = $dirins.'/'.strtolower($modulename);
  202. $arrayreplacement = array(
  203. 'mymodule'=>strtolower($modulename),
  204. 'MyModule'=>$modulename
  205. );
  206. $result = dolCopyDir($srcdir, $destdir, 0, 0, $arrayreplacement);
  207. //dol_mkdir($destfile);
  208. if ($result <= 0) {
  209. if ($result < 0) {
  210. $error++;
  211. $langs->load("errors");
  212. setEventMessages($langs->trans("ErrorFailToCopyDir", $srcdir, $destdir), null, 'errors');
  213. } else {
  214. // $result == 0
  215. setEventMessages($langs->trans("AllFilesDidAlreadyExist", $srcdir, $destdir), null, 'warnings');
  216. }
  217. }
  218. // Copy last 'html.formsetup.class.php' to backport folder
  219. if (getDolGlobalInt('MODULEBUILDER_SUPPORT_COMPATIBILITY_V16')) {
  220. $tryToCopyFromSetupClass = true;
  221. $backportDest = $destdir .'/backport/v16/core/class';
  222. $backportFileSrc = DOL_DOCUMENT_ROOT.'/core/class/html.formsetup.class.php';
  223. $backportFileDest = $backportDest.'/html.formsetup.class.php';
  224. $result = dol_mkdir($backportDest);
  225. if ($result < 0) {
  226. $error++;
  227. $langs->load("errors");
  228. setEventMessages($langs->trans("ErrorFailToCreateDir", $backportDest), null, 'errors');
  229. $tryToCopyFromSetupClass = false;
  230. }
  231. if ($tryToCopyFromSetupClass) {
  232. $result = dol_copy($backportFileSrc, $backportFileDest);
  233. if ($result <= 0) {
  234. if ($result < 0) {
  235. $error++;
  236. $langs->load("errors");
  237. setEventMessages($langs->trans("ErrorFailToCopyFile", $backportFileSrc, $backportFileDest), null, 'errors');
  238. } else {
  239. setEventMessages($langs->trans("FileDidAlreadyExist", $backportFileDest), null, 'warnings');
  240. }
  241. }
  242. }
  243. }
  244. if (getDolGlobalString('MODULEBUILDER_USE_ABOUT')) {
  245. dol_delete_file($destdir.'/admin/about.php');
  246. }
  247. // Delete dir and files that can be generated in sub tabs later if we need them (we want a minimal module first)
  248. dol_delete_dir_recursive($destdir.'/build/doxygen');
  249. dol_delete_dir_recursive($destdir.'/core/modules/mailings');
  250. dol_delete_dir_recursive($destdir.'/core/modules/'.strtolower($modulename));
  251. dol_delete_dir_recursive($destdir.'/core/tpl');
  252. dol_delete_dir_recursive($destdir.'/core/triggers');
  253. dol_delete_dir_recursive($destdir.'/doc');
  254. //dol_delete_dir_recursive($destdir.'/.tx');
  255. dol_delete_dir_recursive($destdir.'/core/boxes');
  256. dol_delete_file($destdir.'/admin/myobject_extrafields.php');
  257. dol_delete_file($destdir.'/class/actions_'.strtolower($modulename).'.class.php');
  258. dol_delete_file($destdir.'/class/api_'.strtolower($modulename).'.class.php');
  259. dol_delete_file($destdir.'/css/'.strtolower($modulename).'.css.php');
  260. dol_delete_file($destdir.'/js/'.strtolower($modulename).'.js.php');
  261. dol_delete_file($destdir.'/scripts/'.strtolower($modulename).'.php');
  262. dol_delete_file($destdir.'/sql/data.sql');
  263. dol_delete_file($destdir.'/sql/update_x.x.x-y.y.y.sql');
  264. // Delete some files related to Object (because the previous dolCopyDir has copied everything)
  265. dol_delete_file($destdir.'/myobject_card.php');
  266. dol_delete_file($destdir.'/myobject_contact.php');
  267. dol_delete_file($destdir.'/myobject_note.php');
  268. dol_delete_file($destdir.'/myobject_document.php');
  269. dol_delete_file($destdir.'/myobject_agenda.php');
  270. dol_delete_file($destdir.'/myobject_list.php');
  271. dol_delete_file($destdir.'/lib/'.strtolower($modulename).'_myobject.lib.php');
  272. dol_delete_file($destdir.'/test/phpunit/functionnal/'.$modulename.'FunctionnalTest.php');
  273. dol_delete_file($destdir.'/test/phpunit/MyObjectTest.php');
  274. dol_delete_file($destdir.'/sql/llx_'.strtolower($modulename).'_myobject.sql');
  275. dol_delete_file($destdir.'/sql/llx_'.strtolower($modulename).'_myobject_extrafields.sql');
  276. dol_delete_file($destdir.'/sql/llx_'.strtolower($modulename).'_myobject.key.sql');
  277. dol_delete_file($destdir.'/sql/llx_'.strtolower($modulename).'_myobject_extrafields.key.sql');
  278. dol_delete_file($destdir.'/class/myobject.class.php');
  279. dol_delete_dir($destdir.'/class', 1);
  280. dol_delete_dir($destdir.'/css', 1);
  281. dol_delete_dir($destdir.'/js', 1);
  282. dol_delete_dir($destdir.'/scripts', 1);
  283. dol_delete_dir($destdir.'/sql', 1);
  284. dol_delete_dir($destdir.'/test/phpunit/functionnal', 1);
  285. dol_delete_dir($destdir.'/test/phpunit', 1);
  286. dol_delete_dir($destdir.'/test', 1);
  287. }
  288. // Edit PHP files
  289. if (!$error) {
  290. $listofphpfilestoedit = dol_dir_list($destdir, 'files', 1, '\.(php|MD|js|sql|txt|xml|lang)$', '', 'fullname', SORT_ASC, 0, 1);
  291. foreach ($listofphpfilestoedit as $phpfileval) {
  292. //var_dump($phpfileval['fullname']);
  293. $arrayreplacement = array(
  294. 'mymodule'=>strtolower($modulename),
  295. 'MyModule'=>$modulename,
  296. 'MYMODULE'=>strtoupper($modulename),
  297. 'My module'=>$modulename,
  298. 'my module'=>$modulename,
  299. 'Mon module'=>$modulename,
  300. 'mon module'=>$modulename,
  301. 'htdocs/modulebuilder/template'=>strtolower($modulename),
  302. '---Put here your own copyright and developer email---'=>dol_print_date($now, '%Y').' '.$user->getFullName($langs).($user->email ? ' <'.$user->email.'>' : ''),
  303. 'Editor name'=>$editorname,
  304. 'https://www.example.com'=>$editorurl,
  305. '$this->version = \'1.0\''=>'$this->version = \''.$version.'\'',
  306. '$this->picto = \'generic\';'=>(empty($picto)) ? '$this->picto = \'generic\'' : '$this->picto = \''.$picto.'\';',
  307. "modulefamily" =>$family,
  308. '500000'=>$idmodule
  309. );
  310. if (getDolGlobalString('MODULEBUILDER_SPECIFIC_AUTHOR')) {
  311. $arrayreplacement['---Put here your own copyright and developer email---'] = dol_print_date($now, '%Y').' ' . getDolGlobalString('MODULEBUILDER_SPECIFIC_AUTHOR');
  312. }
  313. $result = dolReplaceInFile($phpfileval['fullname'], $arrayreplacement);
  314. //var_dump($result);
  315. if ($result < 0) {
  316. setEventMessages($langs->trans("ErrorFailToMakeReplacementInto", $phpfileval['fullname']), null, 'errors');
  317. }
  318. }
  319. if (getDolGlobalString('MODULEBUILDER_SPECIFIC_README')) {
  320. setEventMessages($langs->trans("ContentOfREADMECustomized"), null, 'warnings');
  321. dol_delete_file($destdir.'/README.md');
  322. file_put_contents($destdir.'/README.md', $conf->global->MODULEBUILDER_SPECIFIC_README);
  323. }
  324. // for create file to add properties
  325. // file_put_contents($destdir.'/'.strtolower($modulename).'propertycard.php','');
  326. // $srcFileCard = DOL_DOCUMENT_ROOT.'/modulebuilder/card.php';
  327. // $destFileCard = $dirins.'/'.strtolower($modulename).'/template/card.php';
  328. // dol_copy($srcFileCard, $destdir.'/'.strtolower($modulename).'propertycard.php', 0,1, $arrayreplacement);
  329. }
  330. if (!$error) {
  331. setEventMessages('ModuleInitialized', null);
  332. $module = $modulename;
  333. clearstatcache(true);
  334. if (function_exists('opcache_invalidate')) {
  335. opcache_reset(); // remove the include cache hell !
  336. }
  337. header("Location: ".$_SERVER["PHP_SELF"].'?module='.$modulename);
  338. exit;
  339. }
  340. }
  341. // init API, PHPUnit
  342. if ($dirins && in_array($action, array('initapi', 'initphpunit', 'initpagecontact', 'initpagedocument', 'initpagenote', 'initpageagenda')) && !empty($module)) {
  343. $modulename = ucfirst($module); // Force first letter in uppercase
  344. $objectname = $tabobj;
  345. $varnametoupdate = '';
  346. $dirins = $listofmodules[strtolower($module)]['moduledescriptorrootpath'];
  347. $destdir = $dirins.'/'.strtolower($module);
  348. // Get list of existing objects
  349. $objects = dolGetListOfObjectClasses($destdir);
  350. if ($action == 'initapi') {
  351. if (file_exists($dirins.'/'.strtolower($module).'/class/api_'.strtolower($module).'.class.php')) {
  352. $result = dol_copy(DOL_DOCUMENT_ROOT.'/modulebuilder/template/class/api_mymodule.class.php', $dirins.'/'.strtolower($module).'/class/api_'.strtolower($module).'.class.php', 0, 1);
  353. }
  354. dol_mkdir($dirins.'/'.strtolower($module).'/class');
  355. $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
  356. $srcfile = $srcdir.'/class/api_mymodule.class.php';
  357. $destfile = $dirins.'/'.strtolower($module).'/class/api_'.strtolower($module).'.class.php';
  358. } elseif ($action == 'initphpunit') {
  359. dol_mkdir($dirins.'/'.strtolower($module).'/test/phpunit');
  360. $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
  361. $srcfile = $srcdir.'/test/phpunit/MyObjectTest.php';
  362. $destfile = $dirins.'/'.strtolower($module).'/test/phpunit/'.strtolower($objectname).'Test.php';
  363. } elseif ($action == 'initpagecontact') {
  364. dol_mkdir($dirins.'/'.strtolower($module));
  365. $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
  366. $srcfile = $srcdir.'/myobject_contact.php';
  367. $destfile = $dirins.'/'.strtolower($module).'/'.strtolower($objectname).'_contact.php';
  368. $varnametoupdate = 'showtabofpagecontact';
  369. } elseif ($action == 'initpagedocument') {
  370. dol_mkdir($dirins.'/'.strtolower($module));
  371. $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
  372. $srcfile = $srcdir.'/myobject_document.php';
  373. $destfile = $dirins.'/'.strtolower($module).'/'.strtolower($objectname).'_document.php';
  374. $varnametoupdate = 'showtabofpagedocument';
  375. } elseif ($action == 'initpagenote') {
  376. dol_mkdir($dirins.'/'.strtolower($module));
  377. $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
  378. $srcfile = $srcdir.'/myobject_note.php';
  379. $destfile = $dirins.'/'.strtolower($module).'/'.strtolower($objectname).'_note.php';
  380. $varnametoupdate = 'showtabofpagenote';
  381. } elseif ($action == 'initpageagenda') {
  382. dol_mkdir($dirins.'/'.strtolower($module));
  383. $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
  384. $srcfile = $srcdir.'/myobject_agenda.php';
  385. $destfile = $dirins.'/'.strtolower($module).'/'.strtolower($objectname).'_agenda.php';
  386. $varnametoupdate = 'showtabofpageagenda';
  387. }
  388. //var_dump($srcfile);
  389. //var_dump($destfile);
  390. if (!file_exists($destfile)) {
  391. $result = dol_copy($srcfile, $destfile, 0, 0);
  392. }
  393. if ($result > 0) {
  394. //var_dump($phpfileval['fullname']);
  395. $arrayreplacement = array(
  396. 'mymodule'=>strtolower($modulename),
  397. 'MyModule'=>$modulename,
  398. 'MYMODULE'=>strtoupper($modulename),
  399. 'My module'=>$modulename,
  400. 'my module'=>$modulename,
  401. 'Mon module'=>$modulename,
  402. 'mon module'=>$modulename,
  403. 'htdocs/modulebuilder/template'=>strtolower($modulename),
  404. 'myobject'=>strtolower($objectname),
  405. 'MyObject'=>$objectname,
  406. 'MYOBJECT'=>strtoupper($objectname),
  407. '---Put here your own copyright and developer email---'=>dol_print_date($now, '%Y').' '.$user->getFullName($langs).($user->email ? ' <'.$user->email.'>' : '')
  408. );
  409. if (count($objects) > 1) {
  410. addObjectsToApiFile($destfile, $objects, $modulename);
  411. } else {
  412. dolReplaceInFile($destfile, $arrayreplacement);
  413. dolReplaceInFile($destfile, array('/*begin methods CRUD*/' => '/*begin methods CRUD*/'."\n\t".'/*CRUD FOR '.strtoupper($objectname).'*/', '/*end methods CRUD*/' => '/*END CRUD FOR '.strtoupper($objectname).'*/'."\n\t".'/*end methods CRUD*/'));
  414. }
  415. if ($varnametoupdate) {
  416. // Now we update the object file to set $$varnametoupdate to 1
  417. $srcfile = $dirins.'/'.strtolower($module).'/lib/'.strtolower($module).'_'.strtolower($objectname).'.lib.php';
  418. $arrayreplacement = array('/\$'.$varnametoupdate.' = 0;/' => '$'.$varnametoupdate.' = 1;');
  419. dolReplaceInFile($srcfile, $arrayreplacement, '', 0, 0, 1);
  420. }
  421. } else {
  422. $langs->load("errors");
  423. setEventMessages($langs->trans('ErrorFailToCreateFile', $destfile), null, 'errors');
  424. }
  425. }
  426. // init ExtraFields
  427. if ($dirins && $action == 'initsqlextrafields' && !empty($module)) {
  428. $modulename = ucfirst($module); // Force first letter in uppercase
  429. $objectname = $tabobj;
  430. dol_mkdir($dirins.'/'.strtolower($module).'/sql');
  431. $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
  432. $srcfile1 = $srcdir.'/sql/llx_mymodule_myobject_extrafields.sql';
  433. $destfile1 = $dirins.'/'.strtolower($module).'/sql/llx_'.strtolower($module).'_'.strtolower($objectname).'_extrafields.sql';
  434. //var_dump($srcfile);
  435. //var_dump($destfile);
  436. $result1 = dol_copy($srcfile1, $destfile1, 0, 0);
  437. $srcfile2 = $srcdir.'/sql/llx_mymodule_myobject_extrafields.key.sql';
  438. $destfile2 = $dirins.'/'.strtolower($module).'/sql/llx_'.strtolower($module).'_'.strtolower($objectname).'_extrafields.key.sql';
  439. //var_dump($srcfile);
  440. //var_dump($destfile);
  441. $result2 = dol_copy($srcfile2, $destfile2, 0, 0);
  442. if ($result1 > 0 && $result2 > 0) {
  443. $modulename = ucfirst($module); // Force first letter in uppercase
  444. //var_dump($phpfileval['fullname']);
  445. $arrayreplacement = array(
  446. 'mymodule'=>strtolower($modulename),
  447. 'MyModule'=>$modulename,
  448. 'MYMODULE'=>strtoupper($modulename),
  449. 'My module'=>$modulename,
  450. 'my module'=>$modulename,
  451. 'Mon module'=>$modulename,
  452. 'mon module'=>$modulename,
  453. 'htdocs/modulebuilder/template'=>strtolower($modulename),
  454. 'My Object'=>$objectname,
  455. 'MyObject'=>$objectname,
  456. 'my object'=>strtolower($objectname),
  457. 'myobject'=>strtolower($objectname),
  458. '---Put here your own copyright and developer email---'=>dol_print_date($now, '%Y').' '.$user->getFullName($langs).($user->email ? ' <'.$user->email.'>' : '')
  459. );
  460. dolReplaceInFile($destfile1, $arrayreplacement);
  461. dolReplaceInFile($destfile2, $arrayreplacement);
  462. } else {
  463. $langs->load("errors");
  464. if ($result1 <= 0) {
  465. setEventMessages($langs->trans('ErrorFailToCreateFile', $destfile1), null, 'errors');
  466. }
  467. if ($result2 <= 0) {
  468. setEventMessages($langs->trans('ErrorFailToCreateFile', $destfile2), null, 'errors');
  469. }
  470. }
  471. // Now we update the object file to set $isextrafieldmanaged to 1
  472. $srcfile = $dirins.'/'.strtolower($module).'/class/'.strtolower($objectname).'.class.php';
  473. $arrayreplacement = array('/\$isextrafieldmanaged = 0;/' => '$isextrafieldmanaged = 1;');
  474. dolReplaceInFile($srcfile, $arrayreplacement, '', 0, 0, 1);
  475. }
  476. // init Hook
  477. if ($dirins && $action == 'inithook' && !empty($module)) {
  478. dol_mkdir($dirins.'/'.strtolower($module).'/class');
  479. $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
  480. $srcfile = $srcdir.'/class/actions_mymodule.class.php';
  481. $destfile = $dirins.'/'.strtolower($module).'/class/actions_'.strtolower($module).'.class.php';
  482. //var_dump($srcfile);
  483. //var_dump($destfile);
  484. $result = dol_copy($srcfile, $destfile, 0, 0);
  485. if ($result > 0) {
  486. $modulename = ucfirst($module); // Force first letter in uppercase
  487. //var_dump($phpfileval['fullname']);
  488. $arrayreplacement = array(
  489. 'mymodule'=>strtolower($modulename),
  490. 'MyModule'=>$modulename,
  491. 'MYMODULE'=>strtoupper($modulename),
  492. 'My module'=>$modulename,
  493. 'my module'=>$modulename,
  494. 'Mon module'=>$modulename,
  495. 'mon module'=>$modulename,
  496. 'htdocs/modulebuilder/template'=>strtolower($modulename),
  497. '---Put here your own copyright and developer email---'=>dol_print_date($now, '%Y').' '.$user->getFullName($langs).($user->email ? ' <'.$user->email.'>' : '')
  498. );
  499. dolReplaceInFile($destfile, $arrayreplacement);
  500. } else {
  501. $langs->load("errors");
  502. setEventMessages($langs->trans('ErrorFailToCreateFile', $destfile), null, 'errors');
  503. }
  504. }
  505. // init Trigger
  506. if ($dirins && $action == 'inittrigger' && !empty($module)) {
  507. dol_mkdir($dirins.'/'.strtolower($module).'/core/triggers');
  508. $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
  509. $srcfile = $srcdir.'/core/triggers/interface_99_modMyModule_MyModuleTriggers.class.php';
  510. $destfile = $dirins.'/'.strtolower($module).'/core/triggers/interface_99_mod'.$module.'_'.$module.'Triggers.class.php';
  511. //var_dump($srcfile);
  512. //var_dump($destfile);
  513. $result = dol_copy($srcfile, $destfile, 0, 0);
  514. if ($result > 0) {
  515. $modulename = ucfirst($module); // Force first letter in uppercase
  516. //var_dump($phpfileval['fullname']);
  517. $arrayreplacement = array(
  518. 'mymodule'=>strtolower($modulename),
  519. 'MyModule'=>$modulename,
  520. 'MYMODULE'=>strtoupper($modulename),
  521. 'My module'=>$modulename,
  522. 'my module'=>$modulename,
  523. 'Mon module'=>$modulename,
  524. 'mon module'=>$modulename,
  525. 'htdocs/modulebuilder/template'=>strtolower($modulename),
  526. '---Put here your own copyright and developer email---'=>dol_print_date($now, '%Y').' '.$user->getFullName($langs).($user->email ? ' <'.$user->email.'>' : '')
  527. );
  528. dolReplaceInFile($destfile, $arrayreplacement);
  529. } else {
  530. $langs->load("errors");
  531. setEventMessages($langs->trans('ErrorFailToCreateFile', $destfile), null, 'errors');
  532. }
  533. }
  534. // init Widget
  535. if ($dirins && $action == 'initwidget' && !empty($module)) {
  536. dol_mkdir($dirins.'/'.strtolower($module).'/core/boxes');
  537. $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
  538. $srcfile = $srcdir.'/core/boxes/mymodulewidget1.php';
  539. $destfile = $dirins.'/'.strtolower($module).'/core/boxes/'.strtolower($module).'widget1.php';
  540. //var_dump($srcfile);
  541. //var_dump($destfile);
  542. $result = dol_copy($srcfile, $destfile, 0, 0);
  543. if ($result > 0) {
  544. $modulename = ucfirst($module); // Force first letter in uppercase
  545. //var_dump($phpfileval['fullname']);
  546. $arrayreplacement = array(
  547. 'mymodule'=>strtolower($modulename),
  548. 'MyModule'=>$modulename,
  549. 'MYMODULE'=>strtoupper($modulename),
  550. 'My module'=>$modulename,
  551. 'my module'=>$modulename,
  552. 'Mon module'=>$modulename,
  553. 'mon module'=>$modulename,
  554. 'htdocs/modulebuilder/template'=>strtolower($modulename),
  555. '---Put here your own copyright and developer email---'=>dol_print_date($now, '%Y').' '.$user->getFullName($langs).($user->email ? ' <'.$user->email.'>' : '')
  556. );
  557. dolReplaceInFile($destfile, $arrayreplacement);
  558. } else {
  559. $langs->load("errors");
  560. setEventMessages($langs->trans('ErrorFailToCreateFile', $destfile), null, 'errors');
  561. }
  562. }
  563. // init CSS
  564. if ($dirins && $action == 'initcss' && !empty($module)) {
  565. dol_mkdir($dirins.'/'.strtolower($module).'/css');
  566. $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
  567. $srcfile = $srcdir.'/css/mymodule.css.php';
  568. $destfile = $dirins.'/'.strtolower($module).'/css/'.strtolower($module).'.css.php';
  569. //var_dump($srcfile);
  570. //var_dump($destfile);
  571. $result = dol_copy($srcfile, $destfile, 0, 0);
  572. if ($result > 0) {
  573. $modulename = ucfirst($module); // Force first letter in uppercase
  574. //var_dump($phpfileval['fullname']);
  575. $arrayreplacement = array(
  576. 'mymodule'=>strtolower($modulename),
  577. 'MyModule'=>$modulename,
  578. 'MYMODULE'=>strtoupper($modulename),
  579. 'My module'=>$modulename,
  580. 'my module'=>$modulename,
  581. 'Mon module'=>$modulename,
  582. 'mon module'=>$modulename,
  583. 'htdocs/modulebuilder/template'=>strtolower($modulename),
  584. '---Put here your own copyright and developer email---'=>dol_print_date($now, '%Y').' '.$user->getFullName($langs).($user->email ? ' <'.$user->email.'>' : ''),
  585. );
  586. dolReplaceInFile($destfile, $arrayreplacement);
  587. // Update descriptor file to uncomment file
  588. $srcfile = $dirins.'/'.strtolower($module).'/core/modules/mod'.$module.'.class.php';
  589. $arrayreplacement = array('/\/\/\s*\''.preg_quote('/'.strtolower($module).'/css/'.strtolower($module).'.css.php', '/').'\'/' => '\'/'.strtolower($module).'/css/'.strtolower($module).'.css.php\'');
  590. dolReplaceInFile($srcfile, $arrayreplacement, '', 0, 0, 1);
  591. } else {
  592. $langs->load("errors");
  593. setEventMessages($langs->trans('ErrorFailToCreateFile', $destfile), null, 'errors');
  594. }
  595. }
  596. // init JS
  597. if ($dirins && $action == 'initjs' && !empty($module)) {
  598. dol_mkdir($dirins.'/'.strtolower($module).'/js');
  599. $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
  600. $srcfile = $srcdir.'/js/mymodule.js.php';
  601. $destfile = $dirins.'/'.strtolower($module).'/js/'.strtolower($module).'.js.php';
  602. //var_dump($srcfile);
  603. //var_dump($destfile);
  604. $result = dol_copy($srcfile, $destfile, 0, 0);
  605. if ($result > 0) {
  606. $modulename = ucfirst($module); // Force first letter in uppercase
  607. //var_dump($phpfileval['fullname']);
  608. $arrayreplacement = array(
  609. 'mymodule'=>strtolower($modulename),
  610. 'MyModule'=>$modulename,
  611. 'MYMODULE'=>strtoupper($modulename),
  612. 'My module'=>$modulename,
  613. 'my module'=>$modulename,
  614. 'Mon module'=>$modulename,
  615. 'mon module'=>$modulename,
  616. 'htdocs/modulebuilder/template'=>strtolower($modulename),
  617. '---Put here your own copyright and developer email---'=>dol_print_date($now, '%Y').' '.$user->getFullName($langs).($user->email ? ' <'.$user->email.'>' : '')
  618. );
  619. dolReplaceInFile($destfile, $arrayreplacement);
  620. // Update descriptor file to uncomment file
  621. $srcfile = $dirins.'/'.strtolower($module).'/core/modules/mod'.$module.'.class.php';
  622. $arrayreplacement = array('/\/\/\s*\''.preg_quote('/'.strtolower($module).'/js/'.strtolower($module).'.js.php', '/').'\'/' => '\'/'.strtolower($module).'/js/'.strtolower($module).'.js.php\'');
  623. dolReplaceInFile($srcfile, $arrayreplacement, '', 0, 0, 1);
  624. } else {
  625. $langs->load("errors");
  626. setEventMessages($langs->trans('ErrorFailToCreateFile', $destfile), null, 'errors');
  627. }
  628. }
  629. // init CLI
  630. if ($dirins && $action == 'initcli' && !empty($module)) {
  631. dol_mkdir($dirins.'/'.strtolower($module).'/scripts');
  632. $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
  633. $srcfile = $srcdir.'/scripts/mymodule.php';
  634. $destfile = $dirins.'/'.strtolower($module).'/scripts/'.strtolower($module).'.php';
  635. //var_dump($srcfile);
  636. //var_dump($destfile);
  637. $result = dol_copy($srcfile, $destfile, 0, 0);
  638. if ($result > 0) {
  639. $modulename = ucfirst($module); // Force first letter in uppercase
  640. //var_dump($phpfileval['fullname']);
  641. $arrayreplacement = array(
  642. 'mymodule'=>strtolower($modulename),
  643. 'MyModule'=>$modulename,
  644. 'MYMODULE'=>strtoupper($modulename),
  645. 'My module'=>$modulename,
  646. 'my module'=>$modulename,
  647. 'Mon module'=>$modulename,
  648. 'mon module'=>$modulename,
  649. 'htdocs/modulebuilder/template'=>strtolower($modulename),
  650. '__MYCOMPANY_NAME__'=>$mysoc->name,
  651. '__KEYWORDS__'=>$modulename,
  652. '__USER_FULLNAME__'=>$user->getFullName($langs),
  653. '__USER_EMAIL__'=>$user->email,
  654. '__YYYY-MM-DD__'=>dol_print_date($now, 'dayrfc'),
  655. '---Put here your own copyright and developer email---'=>dol_print_date($now, 'dayrfc').' '.$user->getFullName($langs).($user->email ? ' <'.$user->email.'>' : '')
  656. );
  657. dolReplaceInFile($destfile, $arrayreplacement);
  658. } else {
  659. $langs->load("errors");
  660. setEventMessages($langs->trans('ErrorFailToCreateFile', $destfile), null, 'errors');
  661. }
  662. }
  663. // init Doc
  664. if ($dirins && $action == 'initdoc' && !empty($module)) {
  665. dol_mkdir($dirins.'/'.strtolower($module).'/doc');
  666. $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
  667. $srcfile = $srcdir.'/doc/Documentation.asciidoc';
  668. $destfile = $dirins.'/'.strtolower($module).'/doc/Documentation.asciidoc';
  669. //var_dump($srcfile);
  670. //var_dump($destfile);
  671. $result = dol_copy($srcfile, $destfile, 0, 0);
  672. if ($result > 0) {
  673. $modulename = ucfirst($module); // Force first letter in uppercase
  674. $modulelowercase = strtolower($module);
  675. //var_dump($phpfileval['fullname']);
  676. $arrayreplacement = array(
  677. 'mymodule'=>strtolower($modulename),
  678. 'MyModule'=>$modulename,
  679. 'MYMODULE'=>strtoupper($modulename),
  680. 'My module'=>$modulename,
  681. 'my module'=>$modulename,
  682. 'Mon module'=>$modulename,
  683. 'mon module'=>$modulename,
  684. 'htdocs/modulebuilder/template'=>strtolower($modulename),
  685. '__MYCOMPANY_NAME__'=>$mysoc->name,
  686. '__KEYWORDS__'=>$modulename,
  687. '__USER_FULLNAME__'=>$user->getFullName($langs),
  688. '__USER_EMAIL__'=>$user->email,
  689. '__YYYY-MM-DD__'=>dol_print_date($now, 'dayrfc'),
  690. '---Put here your own copyright and developer email---'=>dol_print_date($now, 'dayrfc').' '.$user->getFullName($langs).($user->email ? ' <'.$user->email.'>' : '')
  691. );
  692. dolReplaceInFile($destfile, $arrayreplacement);
  693. // add table of properties
  694. $dirins = $listofmodules[strtolower($module)]['moduledescriptorrootpath'];
  695. $destdir = $dirins.'/'.strtolower($module);
  696. $objects = dolGetListOfObjectClasses($destdir);
  697. foreach ($objects as $path=>$obj) {
  698. writePropsInAsciiDoc($path, $obj, $destfile);
  699. }
  700. // add table of permissions
  701. $moduledescriptorfile = $dirins.'/'.strtolower($module).'/core/modules/mod'.$module.'.class.php';
  702. writePermsInAsciiDoc($moduledescriptorfile, $destfile);
  703. // add api urls if file exist
  704. if (file_exists($dirins.'/'.strtolower($module).'/class/api_'.strtolower($module).'.class.php')) {
  705. $apiFile = $dirins.'/'.strtolower($module).'/class/api_'.strtolower($module).'.class.php';
  706. writeApiUrlsInDoc($apiFile, $destfile);
  707. }
  708. // add ChangeLog in Doc
  709. if (file_exists($dirins.'/'.strtolower($module).'/ChangeLog.md')) {
  710. $changeLog = $dirins.'/'.strtolower($module).'/ChangeLog.md';
  711. $string = file_get_contents($changeLog);
  712. $replace = explode("\n", $string);
  713. $strreplace = array();
  714. foreach ($replace as $line) {
  715. if ($line === '') {
  716. continue;
  717. }
  718. if (strpos($line, '##') !== false) {
  719. $strreplace[$line] = str_replace('##', '', $line);
  720. } else {
  721. $strreplace[$line] = $line;
  722. }
  723. }
  724. $stringLog = implode("\n", $strreplace);
  725. dolReplaceInFile($destfile, array('//include::ChangeLog.md[]' => '','__CHANGELOG__' => $stringLog));
  726. }
  727. // Delete old documentation files
  728. $FILENAMEDOC = $modulelowercase.'.html';
  729. $FILENAMEDOCPDF = $modulelowercase.'.pdf';
  730. $outputfiledoc = dol_buildpath($modulelowercase, 0).'/doc/'.$FILENAMEDOC;
  731. $outputfiledocurl = dol_buildpath($modulelowercase, 1).'/doc/'.$FILENAMEDOC;
  732. $outputfiledocpdf = dol_buildpath($modulelowercase, 0).'/doc/'.$FILENAMEDOCPDF;
  733. $outputfiledocurlpdf = dol_buildpath($modulelowercase, 1).'/doc/'.$FILENAMEDOCPDF;
  734. dol_delete_file($outputfiledoc, 0, 0, 0, null, false, 0);
  735. dol_delete_file($outputfiledocpdf, 0, 0, 0, null, false, 0);
  736. } else {
  737. $langs->load("errors");
  738. setEventMessages($langs->trans('ErrorFailToCreateFile', $destfile), null, 'errors');
  739. }
  740. }
  741. // add Language
  742. if ($dirins && $action == 'addlanguage' && !empty($module)) {
  743. $newlangcode = GETPOST('newlangcode', 'aZ09');
  744. if ($newlangcode) {
  745. $modulelowercase = strtolower($module);
  746. // Dir for module
  747. $diroflang = dol_buildpath($modulelowercase, 0);
  748. if ($diroflang == $dolibarr_main_document_root.'/'.$modulelowercase) {
  749. // This is not a custom module, we force diroflang to htdocs root
  750. $diroflang = $dolibarr_main_document_root;
  751. $srcfile = $diroflang.'/langs/en_US/'.$modulelowercase.'.lang';
  752. $destfile = $diroflang.'/langs/'.$newlangcode.'/'.$modulelowercase.'.lang';
  753. $result = dol_copy($srcfile, $destfile, 0, 0);
  754. if ($result < 0) {
  755. setEventMessages($langs->trans("ErrorFailToCopyFile", $srcfile, $destfile), null, 'errors');
  756. }
  757. } else {
  758. $srcdir = $diroflang.'/langs/en_US';
  759. $srcfile = $diroflang.'/langs/en_US/'.$modulelowercase.'.lang';
  760. $destdir = $diroflang.'/langs/'.$newlangcode;
  761. $arrayofreplacement = array();
  762. if (!dol_is_dir($srcfile) || !dol_is_file($srcfile)) {
  763. $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template/langs/en_US';
  764. $arrayofreplacement = array('mymodule'=>$modulelowercase);
  765. }
  766. $result = dolCopyDir($srcdir, $destdir, 0, 0, $arrayofreplacement);
  767. }
  768. } else {
  769. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Language")), null, 'errors');
  770. }
  771. }
  772. // Remove/delete File
  773. if ($dirins && $action == 'confirm_removefile' && !empty($module)) {
  774. $objectname = $tabobj;
  775. $dirins = $listofmodules[strtolower($module)]['moduledescriptorrootpath'];
  776. $destdir = $dirins.'/'.strtolower($module);
  777. $relativefilename = dol_sanitizePathName(GETPOST('file', 'restricthtml'));
  778. // Now we delete the file
  779. if ($relativefilename) {
  780. $dirnametodelete = dirname($relativefilename);
  781. $filetodelete = $dirins.'/'.$relativefilename;
  782. $dirtodelete = $dirins.'/'.$dirnametodelete;
  783. //check when we want delete api_file
  784. if (strpos($relativefilename, 'api') !== false) {
  785. $file_api = $destdir.'/class/api_'.strtolower($module).'.class.php';
  786. $removeFile = removeObjectFromApiFile($file_api, $objectname, $module);
  787. $var = getFromFile($file_api, '/*begin methods CRUD*/', '/*end methods CRUD*/');
  788. if (str_word_count($var) == 0) {
  789. $result = dol_delete_file($filetodelete);
  790. }
  791. if ($removeFile) {
  792. setEventMessages($langs->trans("ApiObjectDeleted"), null);
  793. }
  794. } else {
  795. $result = dol_delete_file($filetodelete);
  796. }
  797. if (!$result) {
  798. setEventMessages($langs->trans("ErrorFailToDeleteFile", basename($filetodelete)), null, 'errors');
  799. } else {
  800. // If we delete a .sql file, we delete also the other .sql file
  801. if (preg_match('/\.sql$/', $relativefilename)) {
  802. if (preg_match('/\.key\.sql$/', $relativefilename)) {
  803. $relativefilename = preg_replace('/\.key\.sql$/', '.sql', $relativefilename);
  804. $filetodelete = $dirins.'/'.$relativefilename;
  805. $result = dol_delete_file($filetodelete);
  806. } elseif (preg_match('/\.sql$/', $relativefilename)) {
  807. $relativefilename = preg_replace('/\.sql$/', '.key.sql', $relativefilename);
  808. $filetodelete = $dirins.'/'.$relativefilename;
  809. $result = dol_delete_file($filetodelete);
  810. }
  811. }
  812. if (dol_is_dir_empty($dirtodelete)) {
  813. dol_delete_dir($dirtodelete);
  814. }
  815. // Update descriptor file to comment file
  816. if (in_array($tab, array('css', 'js'))) {
  817. $srcfile = $dirins.'/'.strtolower($module).'/core/modules/mod'.$module.'.class.php';
  818. $arrayreplacement = array('/^\s*\''.preg_quote('/'.$relativefilename, '/').'\',*/m'=>' // \'/'.$relativefilename.'\',');
  819. dolReplaceInFile($srcfile, $arrayreplacement, '', 0, 0, 1);
  820. }
  821. if (preg_match('/_extrafields/', $relativefilename)) {
  822. // Now we update the object file to set $isextrafieldmanaged to 0
  823. $srcfile = $dirins.'/'.strtolower($module).'/class/'.strtolower($objectname).'.class.php';
  824. $arrayreplacement = array('/\$isextrafieldmanaged = 1;/' => '$isextrafieldmanaged = 0;');
  825. dolReplaceInFile($srcfile, $arrayreplacement, '', 0, 0, 1);
  826. }
  827. // Now we update the lib file to set $showtabofpagexxx to 0
  828. $varnametoupdate = '';
  829. $reg = array();
  830. if (preg_match('/_([a-z]+)\.php$/', $relativefilename, $reg)) {
  831. $varnametoupdate = 'showtabofpage'.$reg[1];
  832. }
  833. if ($varnametoupdate) {
  834. $srcfile = $dirins.'/'.strtolower($module).'/lib/'.strtolower($module).'_'.strtolower($objectname).'.lib.php';
  835. $arrayreplacement = array('/\$'.$varnametoupdate.' = 1;/' => '$'.$varnametoupdate.' = 0;');
  836. dolReplaceInFile($srcfile, $arrayreplacement, '', 0, 0, 1);
  837. }
  838. }
  839. }
  840. }
  841. // Init an object
  842. if ($dirins && $action == 'initobject' && $module && $objectname) {
  843. $objectname = ucfirst($objectname);
  844. $dirins = $dirread = $listofmodules[strtolower($module)]['moduledescriptorrootpath'];
  845. $moduletype = $listofmodules[strtolower($module)]['moduletype'];
  846. if (preg_match('/[^a-z0-9_]/i', $objectname)) {
  847. $error++;
  848. setEventMessages($langs->trans("SpaceOrSpecialCharAreNotAllowed"), null, 'errors');
  849. $tabobj = 'newobject';
  850. }
  851. if (class_exists($objectname)) {
  852. // TODO Add a more efficient detection. Scan disk ?
  853. $error++;
  854. setEventMessages($langs->trans("AnObjectWithThisClassNameAlreadyExists"), null, 'errors');
  855. $tabobj = 'newobject';
  856. }
  857. $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
  858. $destdir = $dirins.'/'.strtolower($module);
  859. // The dir was not created by init
  860. dol_mkdir($destdir.'/class');
  861. dol_mkdir($destdir.'/img');
  862. dol_mkdir($destdir.'/lib');
  863. dol_mkdir($destdir.'/scripts');
  864. dol_mkdir($destdir.'/sql');
  865. // Scan dir class to find if an object with same name already exists.
  866. if (!$error) {
  867. $dirlist = dol_dir_list($destdir.'/class', 'files', 0, '\.txt$');
  868. $alreadyfound = false;
  869. foreach ($dirlist as $key => $val) {
  870. $filefound = preg_replace('/\.txt$/', '', $val['name']);
  871. if (strtolower($objectname) == strtolower($filefound) && $objectname != $filefound) {
  872. $alreadyfound = true;
  873. $error++;
  874. setEventMessages($langs->trans("AnObjectAlreadyExistWithThisNameAndDiffCase"), null, 'errors');
  875. break;
  876. }
  877. }
  878. }
  879. // If we must reuse a table for properties, define $stringforproperties
  880. $stringforproperties = '';
  881. $tablename = GETPOST('initfromtablename', 'alpha');
  882. if ($tablename) {
  883. $_results = $db->DDLDescTable($tablename);
  884. if (empty($_results)) {
  885. $error++;
  886. $langs->load("errors");
  887. setEventMessages($langs->trans("ErrorTableNotFound", $tablename), null, 'errors');
  888. } else {
  889. /**
  890. * 'type' field format ('integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortfield]]]', 'sellist:TableName:LabelFieldName[:KeyFieldName[:KeyFieldParent[:Filter[:Sortfield]]]]', 'varchar(x)', 'double(24,8)', 'real', 'price', 'text', 'text:none', 'html', 'date', 'datetime', 'timestamp', 'duration', 'mail', 'phone', 'ip', 'url', 'password')
  891. * Note: Filter can be a string like "(t.ref:like:'SO-%') or (t.date_creation:<:'20160101') or (t.nature:is:NULL)"
  892. * 'label' the translation key.
  893. * 'picto' is code of a picto to show before value in forms
  894. * 'enabled' is a condition when the field must be managed (Example: 1 or '$conf->global->MY_SETUP_PARAM' or 'isModEnabled("multicurrency")' ...)
  895. * 'position' is the sort order of field.
  896. * 'notnull' is set to 1 if not null in database. Set to -1 if we must set data to null if empty ('' or 0).
  897. * 'visible' says if field is visible in list (Examples: 0=Not visible, 1=Visible on list and create/update/view forms, 2=Visible on list only, 3=Visible on create/update/view form only (not list), 4=Visible on list and update/view form only (not create). 5=Visible on list and view only (not create/not update). Using a negative value means field is not shown by default on list but can be selected for viewing)
  898. * 'noteditable' says if field is not editable (1 or 0)
  899. * 'alwayseditable' says if field can be modified also when status is not draft ('1' or '0')
  900. * 'default' is a default value for creation (can still be overwrote by the Setup of Default Values if field is editable in creation form). Note: If default is set to '(PROV)' and field is 'ref', the default value will be set to '(PROVid)' where id is rowid when a new record is created.
  901. * 'index' if we want an index in database.
  902. * 'foreignkey'=>'tablename.field' if the field is a foreign key (it is recommanded to name the field fk_...).
  903. * 'searchall' is 1 if we want to search in this field when making a search from the quick search button.
  904. * 'isameasure' must be set to 1 or 2 if field can be used for measure. Field type must be summable like integer or double(24,8). Use 1 in most cases, or 2 if you don't want to see the column total into list (for example for percentage)
  905. * 'css' and 'cssview' and 'csslist' is the CSS style to use on field. 'css' is used in creation and update. 'cssview' is used in view mode. 'csslist' is used for columns in lists. For example: 'css'=>'minwidth300 maxwidth500 widthcentpercentminusx', 'cssview'=>'wordbreak', 'csslist'=>'tdoverflowmax200'
  906. * 'help' is a 'TranslationString' to use to show a tooltip on field. You can also use 'TranslationString:keyfortooltiponlick' for a tooltip on click.
  907. * 'showoncombobox' if value of the field must be visible into the label of the combobox that list record
  908. * 'disabled' is 1 if we want to have the field locked by a 'disabled' attribute. In most cases, this is never set into the definition of $fields into class, but is set dynamically by some part of code.
  909. * 'arrayofkeyval' to set a list of values if type is a list of predefined values. For example: array("0"=>"Draft","1"=>"Active","-1"=>"Cancel"). Note that type can be 'integer' or 'varchar'
  910. * 'autofocusoncreate' to have field having the focus on a create form. Only 1 field should have this property set to 1.
  911. * 'comment' is not used. You can store here any text of your choice. It is not used by application.
  912. * 'validate' is 1 if need to validate with $this->validateField()
  913. * 'copytoclipboard' is 1 or 2 to allow to add a picto to copy value into clipboard (1=picto after label, 2=picto after value)
  914. */
  915. /*public $fields=array(
  916. 'rowid' =>array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'index'=>1, 'position'=>1, 'comment'=>'Id'),
  917. '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'),
  918. 'entity' =>array('type'=>'integer', 'label'=>'Entity', 'enabled'=>1, 'visible'=>0, 'default'=>1, 'notnull'=>1, 'index'=>1, 'position'=>20),
  919. 'label' =>array('type'=>'varchar(255)', 'label'=>'Label', 'enabled'=>1, 'visible'=>1, 'position'=>30, 'searchall'=>1, 'css'=>'minwidth200', 'help'=>'Help text', 'alwayseditable'=>'1'),
  920. 'amount' =>array('type'=>'double(24,8)', 'label'=>'Amount', 'enabled'=>1, 'visible'=>1, 'default'=>'null', 'position'=>40, 'searchall'=>0, 'isameasure'=>1, 'help'=>'Help text'),
  921. 'fk_soc' =>array('type'=>'integer:Societe:societe/class/societe.class.php', 'label'=>'ThirdParty', 'visible'=>1, 'enabled'=>1, 'position'=>50, 'notnull'=>-1, 'index'=>1, 'searchall'=>1, 'help'=>'LinkToThirdparty'),
  922. 'description' =>array('type'=>'text', 'label'=>'Descrption', 'enabled'=>1, 'visible'=>0, 'position'=>60),
  923. 'note_public' =>array('type'=>'html', 'label'=>'NotePublic', 'enabled'=>1, 'visible'=>0, 'position'=>61),
  924. 'note_private' =>array('type'=>'html', 'label'=>'NotePrivate', 'enabled'=>1, 'visible'=>0, 'position'=>62),
  925. 'date_creation' =>array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>500),
  926. 'tms' =>array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>501),
  927. //'date_valid' =>array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-2, 'position'=>502),
  928. 'fk_user_creat' =>array('type'=>'integer', 'label'=>'UserAuthor', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>510),
  929. 'fk_user_modif' =>array('type'=>'integer', 'label'=>'UserModif', 'enabled'=>1, 'visible'=>-2, 'notnull'=>-1, 'position'=>511),
  930. //'fk_user_valid' =>array('type'=>'integer', 'label'=>'UserValidation', 'enabled'=>1, 'visible'=>-1, 'position'=>512),
  931. 'import_key' =>array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>1, 'visible'=>-2, 'notnull'=>-1, 'index'=>0, 'position'=>1000),
  932. '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')),
  933. );*/
  934. $stringforproperties = '// BEGIN MODULEBUILDER PROPERTIES'."\n";
  935. $stringforproperties .= 'public $fields=array('."\n";
  936. $i = 10;
  937. while ($obj = $db->fetch_object($_results)) {
  938. // fieldname
  939. $fieldname = $obj->Field;
  940. // type
  941. $type = $obj->Type;
  942. if ($type == 'int(11)') {
  943. $type = 'integer';
  944. }
  945. if ($type == 'float') {
  946. $type = 'real';
  947. }
  948. if (strstr($type, 'tinyint')) {
  949. $type = 'integer';
  950. }
  951. if ($obj->Field == 'fk_soc') {
  952. $type = 'integer:Societe:societe/class/societe.class.php';
  953. }
  954. if (preg_match('/^fk_proj/', $obj->Field)) {
  955. $type = 'integer:Project:projet/class/project.class.php:1:fk_statut=1';
  956. }
  957. if (preg_match('/^fk_prod/', $obj->Field)) {
  958. $type = 'integer:Product:product/class/product.class.php:1';
  959. }
  960. if ($obj->Field == 'fk_warehouse') {
  961. $type = 'integer:Entrepot:product/stock/class/entrepot.class.php';
  962. }
  963. if (preg_match('/^(fk_user|fk_commercial)/', $obj->Field)) {
  964. $type = 'integer:User:user/class/user.class.php';
  965. }
  966. // notnull
  967. $notnull = ($obj->Null == 'YES' ? 0 : 1);
  968. if ($fieldname == 'fk_user_modif') {
  969. $notnull = -1;
  970. }
  971. // label
  972. $label = preg_replace('/_/', '', ucfirst($fieldname));
  973. if ($fieldname == 'rowid') {
  974. $label = 'TechnicalID';
  975. }
  976. if ($fieldname == 'import_key') {
  977. $label = 'ImportId';
  978. }
  979. if ($fieldname == 'fk_soc') {
  980. $label = 'ThirdParty';
  981. }
  982. if ($fieldname == 'tms') {
  983. $label = 'DateModification';
  984. }
  985. if ($fieldname == 'datec') {
  986. $label = 'DateCreation';
  987. }
  988. if ($fieldname == 'date_valid') {
  989. $label = 'DateValidation';
  990. }
  991. if ($fieldname == 'datev') {
  992. $label = 'DateValidation';
  993. }
  994. if ($fieldname == 'note_private') {
  995. $label = 'NotePublic';
  996. }
  997. if ($fieldname == 'note_public') {
  998. $label = 'NotePrivate';
  999. }
  1000. if ($fieldname == 'fk_user_creat') {
  1001. $label = 'UserAuthor';
  1002. }
  1003. if ($fieldname == 'fk_user_modif') {
  1004. $label = 'UserModif';
  1005. }
  1006. if ($fieldname == 'fk_user_valid') {
  1007. $label = 'UserValidation';
  1008. }
  1009. // visible
  1010. $visible = -1;
  1011. if ($fieldname == 'entity') {
  1012. $visible = -2;
  1013. }
  1014. if ($fieldname == 'import_key') {
  1015. $visible = -2;
  1016. }
  1017. if ($fieldname == 'fk_user_creat') {
  1018. $visible = -2;
  1019. }
  1020. if ($fieldname == 'fk_user_modif') {
  1021. $visible = -2;
  1022. }
  1023. if (in_array($fieldname, array('ref_ext', 'model_pdf', 'note_public', 'note_private'))) {
  1024. $visible = 0;
  1025. }
  1026. // enabled
  1027. $enabled = 1;
  1028. // default
  1029. $default = '';
  1030. if ($fieldname == 'entity') {
  1031. $default = 1;
  1032. }
  1033. // position
  1034. $position = $i;
  1035. if (in_array($fieldname, array('status', 'statut', 'fk_status', 'fk_statut'))) {
  1036. $position = 500;
  1037. }
  1038. if ($fieldname == 'import_key') {
  1039. $position = 900;
  1040. }
  1041. // $alwayseditable
  1042. if ($fieldname == 'label') {
  1043. $alwayseditable = 1;
  1044. }
  1045. // index
  1046. $index = 0;
  1047. if ($fieldname == 'entity') {
  1048. $index = 1;
  1049. }
  1050. // css, cssview, csslist
  1051. $css = '';
  1052. $cssview = '';
  1053. $csslist = '';
  1054. if (preg_match('/^fk_/', $fieldname)) {
  1055. $css = 'maxwidth500 widthcentpercentminusxx';
  1056. }
  1057. if ($fieldname == 'label') {
  1058. $css = 'minwidth300';
  1059. $cssview = 'wordbreak';
  1060. }
  1061. if (in_array($fieldname, array('note_public', 'note_private'))) {
  1062. $cssview = 'wordbreak';
  1063. }
  1064. if (in_array($fieldname, array('ref', 'label')) || preg_match('/integer:/', $type)) {
  1065. $csslist = 'tdoverflowmax150';
  1066. }
  1067. // type
  1068. $picto = $obj->Picto;
  1069. if ($obj->Field == 'fk_soc') {
  1070. $picto = 'company';
  1071. }
  1072. if (preg_match('/^fk_proj/', $obj->Field)) {
  1073. $picto = 'project';
  1074. }
  1075. // Build the property string
  1076. $stringforproperties .= "'".$obj->Field."'=>array('type'=>'".$type."', 'label'=>'".$label."',";
  1077. if ($default != '') {
  1078. $stringforproperties .= " 'default'=>".$default.",";
  1079. }
  1080. $stringforproperties .= " 'enabled'=>".$enabled.",";
  1081. $stringforproperties .= " 'visible'=>".$visible;
  1082. if ($notnull) {
  1083. $stringforproperties .= ", 'notnull'=>".$notnull;
  1084. }
  1085. if ($alwayseditable) {
  1086. $stringforproperties .= ", 'alwayseditable'=>1";
  1087. }
  1088. if ($fieldname == 'ref' || $fieldname == 'code') {
  1089. $stringforproperties .= ", 'showoncombobox'=>1";
  1090. }
  1091. $stringforproperties .= ", 'position'=>".$position;
  1092. if ($index) {
  1093. $stringforproperties .= ", 'index'=>".$index;
  1094. }
  1095. if ($picto) {
  1096. $stringforproperties .= ", 'picto'=>'".$picto."'";
  1097. }
  1098. if ($css) {
  1099. $stringforproperties .= ", 'css'=>'".$css."'";
  1100. }
  1101. if ($cssview) {
  1102. $stringforproperties .= ", 'cssview'=>'".$cssview."'";
  1103. }
  1104. if ($csslist) {
  1105. $stringforproperties .= ", 'csslist'=>'".$csslist."'";
  1106. }
  1107. $stringforproperties .= "),\n";
  1108. $i += 5;
  1109. }
  1110. $stringforproperties .= ');'."\n";
  1111. $stringforproperties .= '// END MODULEBUILDER PROPERTIES'."\n";
  1112. }
  1113. }
  1114. if (!$error) {
  1115. // Copy some files
  1116. $filetogenerate = array(
  1117. 'myobject_card.php'=>strtolower($objectname).'_card.php',
  1118. 'myobject_note.php'=>strtolower($objectname).'_note.php',
  1119. 'myobject_contact.php'=>strtolower($objectname).'_contact.php',
  1120. 'myobject_document.php'=>strtolower($objectname).'_document.php',
  1121. 'myobject_agenda.php'=>strtolower($objectname).'_agenda.php',
  1122. 'myobject_list.php'=>strtolower($objectname).'_list.php',
  1123. 'admin/myobject_extrafields.php'=>'admin/'.strtolower($objectname).'_extrafields.php',
  1124. 'lib/mymodule_myobject.lib.php'=>'lib/'.strtolower($module).'_'.strtolower($objectname).'.lib.php',
  1125. //'test/phpunit/MyObjectTest.php'=>'test/phpunit/'.strtolower($objectname).'Test.php',
  1126. 'sql/llx_mymodule_myobject.sql'=>'sql/llx_'.strtolower($module).'_'.strtolower($objectname).'.sql',
  1127. 'sql/llx_mymodule_myobject.key.sql'=>'sql/llx_'.strtolower($module).'_'.strtolower($objectname).'.key.sql',
  1128. 'sql/llx_mymodule_myobject_extrafields.sql'=>'sql/llx_'.strtolower($module).'_'.strtolower($objectname).'_extrafields.sql',
  1129. 'sql/llx_mymodule_myobject_extrafields.key.sql'=>'sql/llx_'.strtolower($module).'_'.strtolower($objectname).'_extrafields.key.sql',
  1130. //'scripts/mymodule.php'=>'scripts/'.strtolower($objectname).'.php',
  1131. 'class/myobject.class.php'=>'class/'.strtolower($objectname).'.class.php',
  1132. //'class/api_mymodule.class.php'=>'class/api_'.strtolower($module).'.class.php',
  1133. );
  1134. if (GETPOST('includerefgeneration', 'aZ09')) {
  1135. dol_mkdir($destdir.'/core/modules/'.strtolower($module));
  1136. $filetogenerate += array(
  1137. 'core/modules/mymodule/mod_myobject_advanced.php'=>'core/modules/'.strtolower($module).'/mod_'.strtolower($objectname).'_advanced.php',
  1138. 'core/modules/mymodule/mod_myobject_standard.php'=>'core/modules/'.strtolower($module).'/mod_'.strtolower($objectname).'_standard.php',
  1139. 'core/modules/mymodule/modules_myobject.php'=>'core/modules/'.strtolower($module).'/modules_'.strtolower($objectname).'.php',
  1140. );
  1141. }
  1142. if (GETPOST('includedocgeneration', 'aZ09')) {
  1143. dol_mkdir($destdir.'/core/modules/'.strtolower($module));
  1144. dol_mkdir($destdir.'/core/modules/'.strtolower($module).'/doc');
  1145. $filetogenerate += array(
  1146. 'core/modules/mymodule/doc/doc_generic_myobject_odt.modules.php'=>'core/modules/'.strtolower($module).'/doc/doc_generic_'.strtolower($objectname).'_odt.modules.php',
  1147. 'core/modules/mymodule/doc/pdf_standard_myobject.modules.php'=>'core/modules/'.strtolower($module).'/doc/pdf_standard_'.strtolower($objectname).'.modules.php'
  1148. );
  1149. }
  1150. if (GETPOST('generatepermissions', 'aZ09')) {
  1151. $firstobjectname = 'myobject';
  1152. $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
  1153. dol_include_once($pathtofile);
  1154. $class = 'mod'.$module;
  1155. if (class_exists($class)) {
  1156. try {
  1157. $moduleobj = new $class($db);
  1158. } catch (Exception $e) {
  1159. $error++;
  1160. dol_print_error($db, $e->getMessage());
  1161. }
  1162. }
  1163. $rights = $moduleobj->rights;
  1164. $moduledescriptorfile = $destdir.'/core/modules/mod'.$module.'.class.php';
  1165. $checkComment=checkExistComment($moduledescriptorfile, 1);
  1166. if ($checkComment < 0) {
  1167. setEventMessages($langs->trans("WarningCommentNotFound", $langs->trans("Permissions"), "mod".$module."class.php"), null, 'warnings');
  1168. } else {
  1169. $generatePerms = reWriteAllPermissions($moduledescriptorfile, $rights, null, null, $objectname, $module, -2);
  1170. if ($generatePerms < 0) {
  1171. setEventMessages($langs->trans("WarningPermissionAlreadyExist", $langs->transnoentities($objectname)), null, 'warnings');
  1172. }
  1173. }
  1174. }
  1175. if (!$error) {
  1176. foreach ($filetogenerate as $srcfile => $destfile) {
  1177. $result = dol_copy($srcdir.'/'.$srcfile, $destdir.'/'.$destfile, $newmask, 0);
  1178. if ($result <= 0) {
  1179. if ($result < 0) {
  1180. $error++;
  1181. $langs->load("errors");
  1182. setEventMessages($langs->trans("ErrorFailToCopyFile", $srcdir.'/'.$srcfile, $destdir.'/'.$destfile), null, 'errors');
  1183. } else {
  1184. // $result == 0
  1185. setEventMessages($langs->trans("FileAlreadyExists", $destfile), null, 'warnings');
  1186. }
  1187. }
  1188. $arrayreplacement = array(
  1189. '/myobject\.class\.php/' => strtolower($objectname).'.class.php',
  1190. '/myobject\.lib\.php/' => strtolower($objectname).'.lib.php',
  1191. );
  1192. dolReplaceInFile($destdir.'/'.$destfile, $arrayreplacement, '', 0, 0, 1);
  1193. }
  1194. }
  1195. // Replace property section with $stringforproperties
  1196. if (!$error && $stringforproperties) {
  1197. //var_dump($stringforproperties);exit;
  1198. $arrayreplacement = array(
  1199. '/\/\/ BEGIN MODULEBUILDER PROPERTIES.*\/\/ END MODULEBUILDER PROPERTIES/ims' => $stringforproperties
  1200. );
  1201. dolReplaceInFile($destdir.'/class/'.strtolower($objectname).'.class.php', $arrayreplacement, '', 0, 0, 1);
  1202. }
  1203. // Edit the class 'class/'.strtolower($objectname).'.class.php'
  1204. if (GETPOST('includerefgeneration', 'aZ09')) {
  1205. // Replace 'visible'=>1, 'noteditable'=>0, 'default'=>''
  1206. $arrayreplacement = array(
  1207. '/\'visible\'=>1,\s*\'noteditable\'=>0,\s*\'default\'=>\'\'/' => "'visible'=>4, 'noteditable'=>1, 'default'=>'(PROV)'"
  1208. );
  1209. //var_dump($arrayreplacement);exit;
  1210. //var_dump($destdir.'/class/'.strtolower($objectname).'.class.php');exit;
  1211. dolReplaceInFile($destdir.'/class/'.strtolower($objectname).'.class.php', $arrayreplacement, '', 0, 0, 1);
  1212. $arrayreplacement = array(
  1213. '/\'models\' => 0,/' => '\'models\' => 1,'
  1214. );
  1215. dolReplaceInFile($destdir.'/core/modules/mod'.$module.'.class.php', $arrayreplacement, '', 0, 0, 1);
  1216. }
  1217. // Edit the setup file and the card page
  1218. if (GETPOST('includedocgeneration', 'aZ09')) {
  1219. // Replace some var init into some files
  1220. $arrayreplacement = array(
  1221. '/\$includedocgeneration = 0;/' => '$includedocgeneration = 1;'
  1222. );
  1223. dolReplaceInFile($destdir.'/class/'.strtolower($objectname).'.class.php', $arrayreplacement, '', 0, 0, 1);
  1224. dolReplaceInFile($destdir.'/'.strtolower($objectname).'_card.php', $arrayreplacement, '', 0, 0, 1);
  1225. $arrayreplacement = array(
  1226. '/\'models\' => 0,/' => '\'models\' => 1,'
  1227. );
  1228. dolReplaceInFile($destdir.'/core/modules/mod'.$module.'.class.php', $arrayreplacement, '', 0, 0, 1);
  1229. }
  1230. // TODO Update entries '$myTmpObjects['MyObject']=array('includerefgeneration'=>0, 'includedocgeneration'=>0);'
  1231. // Scan for object class files
  1232. $listofobject = dol_dir_list($destdir.'/class', 'files', 0, '\.class\.php$');
  1233. $firstobjectname = '';
  1234. foreach ($listofobject as $fileobj) {
  1235. if (preg_match('/^api_/', $fileobj['name'])) {
  1236. continue;
  1237. }
  1238. if (preg_match('/^actions_/', $fileobj['name'])) {
  1239. continue;
  1240. }
  1241. $tmpcontent = file_get_contents($fileobj['fullname']);
  1242. $reg = array();
  1243. if (preg_match('/class\s+([^\s]*)\s+extends\s+CommonObject/ims', $tmpcontent, $reg)) {
  1244. $objectnameloop = $reg[1];
  1245. if (empty($firstobjectname)) {
  1246. $firstobjectname = $objectnameloop;
  1247. }
  1248. }
  1249. // Regenerate left menu entry in descriptor for $objectname
  1250. $stringtoadd = "
  1251. \$this->menu[\$r++]=array(
  1252. 'fk_menu'=>'fk_mainmenu=mymodule',
  1253. 'type'=>'left',
  1254. 'titre'=>'MyObject',
  1255. 'prefix' => img_picto('', \$this->picto, 'class=\"paddingright pictofixedwidth valignmiddle\"'),
  1256. 'mainmenu'=>'mymodule',
  1257. 'leftmenu'=>'myobject',
  1258. 'url'=>'/mymodule/myobject_list.php',
  1259. 'langs'=>'mymodule@mymodule',
  1260. 'position'=>1000+\$r,
  1261. 'enabled'=>'isModEnabled(\"mymodule\")',
  1262. 'perms'=>'\$user->hasRight(\"mymodule\", \"myobject\", \"read\")',
  1263. 'target'=>'',
  1264. 'user'=>2,
  1265. );
  1266. \$this->menu[\$r++]=array(
  1267. 'fk_menu'=>'fk_mainmenu=mymodule,fk_leftmenu=myobject',
  1268. 'type'=>'left',
  1269. 'titre'=>'List MyObject',
  1270. 'mainmenu'=>'mymodule',
  1271. 'leftmenu'=>'mymodule_myobject_list',
  1272. 'url'=>'/mymodule/myobject_list.php',
  1273. 'langs'=>'mymodule@mymodule',
  1274. 'position'=>1000+\$r,
  1275. 'enabled'=>'isModEnabled(\"mymodule\")',
  1276. 'perms'=>'\$user->hasRight(\"mymodule\", \"myobject\", \"read\")',
  1277. 'target'=>'',
  1278. 'user'=>2,
  1279. );
  1280. \$this->menu[\$r++]=array(
  1281. 'fk_menu'=>'fk_mainmenu=mymodule,fk_leftmenu=myobject',
  1282. 'type'=>'left',
  1283. 'titre'=>'New MyObject',
  1284. 'mainmenu'=>'mymodule',
  1285. 'leftmenu'=>'mymodule_myobject_new',
  1286. 'url'=>'/mymodule/myobject_card.php?action=create',
  1287. 'langs'=>'mymodule@mymodule',
  1288. 'position'=>1000+\$r,
  1289. 'enabled'=>'isModEnabled(\"mymodule\")',
  1290. 'perms'=>'\$user->hasRight(\"mymodule\", \"myobject\", \"write\")',
  1291. 'target'=>'',
  1292. 'user'=>2
  1293. );\n";
  1294. $stringtoadd = preg_replace('/MyObject/', $objectname, $stringtoadd);
  1295. $stringtoadd = preg_replace('/mymodule/', strtolower($module), $stringtoadd);
  1296. $stringtoadd = preg_replace('/myobject/', strtolower($objectname), $stringtoadd);
  1297. $moduledescriptorfile = $destdir.'/core/modules/mod'.$module.'.class.php';
  1298. }
  1299. // TODO Allow a replace with regex using dolReplaceInFile with param arryreplacementisregex to 1
  1300. // TODO Avoid duplicate addition
  1301. // load class and check if menu exist with same object name
  1302. $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
  1303. dol_include_once($pathtofile);
  1304. $class = 'mod'.$module;
  1305. if (class_exists($class)) {
  1306. try {
  1307. $moduleobj = new $class($db);
  1308. } catch (Exception $e) {
  1309. $error++;
  1310. dol_print_error($db, $e->getMessage());
  1311. }
  1312. }
  1313. $menus = $moduleobj->menu;
  1314. $counter = 0 ;
  1315. foreach ($menus as $menu) {
  1316. if ($menu['leftmenu'] == strtolower($objectname)) {
  1317. $counter++;
  1318. }
  1319. }
  1320. if (!$counter) {
  1321. $checkComment = checkExistComment($moduledescriptorfile, 0);
  1322. if ($checkComment < 0) {
  1323. $error++;
  1324. setEventMessages($langs->trans("WarningCommentNotFound", $langs->trans("Menus"), "mod".$module."class.php"), null, 'warnings');
  1325. } else {
  1326. dolReplaceInFile($moduledescriptorfile, array('/* END MODULEBUILDER LEFTMENU MYOBJECT */' => '/*LEFTMENU '.strtoupper($objectname).'*/'.$stringtoadd."\n\t\t".'/*END LEFTMENU '.strtoupper($objectname).'*/'."\n\t\t".'/* END MODULEBUILDER LEFTMENU MYOBJECT */'));
  1327. }
  1328. }
  1329. // Add module descriptor to list of files to replace "MyObject' string with real name of object.
  1330. $filetogenerate[] = 'core/modules/mod'.$module.'.class.php';
  1331. }
  1332. if (!$error) {
  1333. // Edit PHP files to make replacement
  1334. foreach ($filetogenerate as $destfile) {
  1335. $phpfileval['fullname'] = $destdir.'/'.$destfile;
  1336. //var_dump($phpfileval['fullname']);
  1337. $arrayreplacement = array(
  1338. 'mymodule'=>strtolower($module),
  1339. 'MyModule'=>$module,
  1340. 'MYMODULE'=>strtoupper($module),
  1341. 'My module'=>$module,
  1342. 'my module'=>$module,
  1343. 'mon module'=>$module,
  1344. 'Mon module'=>$module,
  1345. 'htdocs/modulebuilder/template/'=>strtolower($modulename),
  1346. 'myobject'=>strtolower($objectname),
  1347. 'MyObject'=>$objectname,
  1348. //'MYOBJECT'=>strtoupper($objectname),
  1349. '---Put here your own copyright and developer email---'=>dol_print_date($now, '%Y').' '.$user->getFullName($langs).($user->email ? ' <'.$user->email.'>' : '')
  1350. );
  1351. if (getDolGlobalString('MODULEBUILDER_SPECIFIC_AUTHOR')) {
  1352. $arrayreplacement['---Put here your own copyright and developer email---'] = dol_print_date($now, '%Y').' ' . getDolGlobalString('MODULEBUILDER_SPECIFIC_AUTHOR');
  1353. }
  1354. $result = dolReplaceInFile($phpfileval['fullname'], $arrayreplacement);
  1355. //var_dump($result);
  1356. if ($result < 0) {
  1357. setEventMessages($langs->trans("ErrorFailToMakeReplacementInto", $phpfileval['fullname']), null, 'errors');
  1358. }
  1359. }
  1360. }
  1361. if (!$error) {
  1362. // Edit the class file to write properties
  1363. $object = rebuildObjectClass($destdir, $module, $objectname, $newmask);
  1364. if (is_numeric($object) && $object <= 0) {
  1365. $pathoffiletoeditsrc = $destdir.'/class/'.strtolower($objectname).'.class.php';
  1366. setEventMessages($langs->trans('ErrorFailToCreateFile', $pathoffiletoeditsrc), null, 'errors');
  1367. $error++;
  1368. }
  1369. // check if documentation was generate and add table of properties object
  1370. $file = $destdir.'/class/'.strtolower($objectname).'.class.php';
  1371. $destfile = $destdir.'/doc/Documentation.asciidoc';
  1372. if (file_exists($destfile)) {
  1373. writePropsInAsciiDoc($file, $objectname, $destfile);
  1374. }
  1375. }
  1376. if (!$error) {
  1377. // Edit sql with new properties
  1378. $result = rebuildObjectSql($destdir, $module, $objectname, $newmask, '', $object);
  1379. if ($result <= 0) {
  1380. setEventMessages($langs->trans('ErrorFailToCreateFile', '.sql'), null);
  1381. $error++;
  1382. }
  1383. }
  1384. if (!$error) {
  1385. setEventMessages($langs->trans('FilesForObjectInitialized', $objectname), null);
  1386. $tabobj = $objectname;
  1387. } else {
  1388. $tabobj = 'newobject';
  1389. }
  1390. // check if module is enabled
  1391. if (isModEnabled(strtolower($module))) {
  1392. $result = unActivateModule(strtolower($module));
  1393. dolibarr_set_const($db, "MAIN_IHM_PARAMS_REV", (int) $conf->global->MAIN_IHM_PARAMS_REV + 1, 'chaine', 0, '', $conf->entity);
  1394. if ($result) {
  1395. setEventMessages($result, null, 'errors');
  1396. }
  1397. setEventMessages($langs->trans('WarningModuleNeedRefresh', $langs->transnoentities($module)), null, 'warnings');
  1398. header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=objects&module='.$module);
  1399. exit;
  1400. }
  1401. }
  1402. // Add a dictionary
  1403. if ($dirins && $action == 'initdic' && $module && empty($cancel)) {
  1404. $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
  1405. $destdir = $dirins.'/'.strtolower($module);
  1406. $moduledescriptorfile = $dirins.'/'.strtolower($module).'/core/modules/mod'.$module.'.class.php';
  1407. if (!GETPOST('dicname')) {
  1408. $error++;
  1409. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Table")), null, 'errors');
  1410. }
  1411. if (!GETPOST('label')) {
  1412. $error++;
  1413. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Lable")), null, 'errors');
  1414. }
  1415. if (!$error) {
  1416. $newdicname = $dicname;
  1417. if (!preg_match('/^c_/', $newdicname)) {
  1418. $newdicname = 'c_'.$dicname;
  1419. }
  1420. dol_include_once($pathtofile);
  1421. $class = 'mod'.$module;
  1422. if (class_exists($class)) {
  1423. try {
  1424. $moduleobj = new $class($db);
  1425. } catch (Exception $e) {
  1426. $error++;
  1427. dol_print_error($db, $e->getMessage());
  1428. }
  1429. } else {
  1430. $error++;
  1431. $langs->load("errors");
  1432. dol_print_error($db, $langs->trans("ErrorFailedToLoadModuleDescriptorForXXX", $module));
  1433. exit;
  1434. }
  1435. $dictionaries = $moduleobj->dictionaries;
  1436. $checkComment = checkExistComment($moduledescriptorfile, 2);
  1437. if ($checkComment < 0) {
  1438. setEventMessages($langs->trans("WarningCommentNotFound", $langs->trans("Dictionaries"), "mod".$module."class.php"), null, 'warnings');
  1439. } else {
  1440. createNewDictionnary($module, $moduledescriptorfile, $newdicname, $dictionaries);
  1441. if (function_exists('opcache_invalidate')) {
  1442. opcache_reset(); // remove the include cache hell !
  1443. }
  1444. clearstatcache(true);
  1445. header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=dictionaries&module='.$module.($forceddirread ? '@'.$dirread : ''));
  1446. exit;
  1447. }
  1448. }
  1449. }
  1450. // Delete a SQL table
  1451. if ($dirins && ($action == 'droptable' || $action == 'droptableextrafields') && !empty($module) && !empty($tabobj)) {
  1452. $objectname = $tabobj;
  1453. $arrayoftables = array();
  1454. if ($action == 'droptable') {
  1455. $arrayoftables[] = MAIN_DB_PREFIX.strtolower($module).'_'.strtolower($tabobj);
  1456. }
  1457. if ($action == 'droptableextrafields') {
  1458. $arrayoftables[] = MAIN_DB_PREFIX.strtolower($module).'_'.strtolower($tabobj).'_extrafields';
  1459. }
  1460. foreach ($arrayoftables as $tabletodrop) {
  1461. $nb = -1;
  1462. $sql = "SELECT COUNT(*) as nb FROM ".$tabletodrop;
  1463. $resql = $db->query($sql);
  1464. if ($resql) {
  1465. $obj = $db->fetch_object($resql);
  1466. if ($obj) {
  1467. $nb = $obj->nb;
  1468. }
  1469. } else {
  1470. if ($db->lasterrno() == 'DB_ERROR_NOSUCHTABLE') {
  1471. setEventMessages($langs->trans("TableDoesNotExists", $tabletodrop), null, 'warnings');
  1472. } else {
  1473. dol_print_error($db);
  1474. }
  1475. }
  1476. if ($nb == 0) {
  1477. $resql = $db->DDLDropTable($tabletodrop);
  1478. //var_dump($resql);
  1479. setEventMessages($langs->trans("TableDropped", $tabletodrop), null, 'mesgs');
  1480. } elseif ($nb > 0) {
  1481. setEventMessages($langs->trans("TableNotEmptyDropCanceled", $tabletodrop), null, 'warnings');
  1482. }
  1483. }
  1484. }
  1485. if ($dirins && $action == 'addproperty' && empty($cancel) && !empty($module) && (!empty($tabobj) || !empty(GETPOST('obj')))) {
  1486. $error = 0;
  1487. $objectname = (GETPOST('obj') ? GETPOST('obj') : $tabobj);
  1488. $dirins = $dirread = $listofmodules[strtolower($module)]['moduledescriptorrootpath'];
  1489. $moduletype = $listofmodules[strtolower($module)]['moduletype'];
  1490. $srcdir = $dirread.'/'.strtolower($module);
  1491. $destdir = $dirins.'/'.strtolower($module);
  1492. dol_mkdir($destdir);
  1493. $objects = dolGetListOfObjectClasses($destdir);
  1494. if (!in_array($objectname, array_values($objects))) {
  1495. $error++;
  1496. setEventMessages($langs->trans("ErrorObjectNotFound", $langs->transnoentities($objectname)), null, 'errors');
  1497. }
  1498. // We click on add property
  1499. if (!GETPOST('regenerateclasssql') && !GETPOST('regeneratemissing')) {
  1500. if (!GETPOST('propname', 'aZ09')) {
  1501. $error++;
  1502. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Name")), null, 'errors');
  1503. }
  1504. if (!GETPOST('proplabel', 'alpha')) {
  1505. $error++;
  1506. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Label")), null, 'errors');
  1507. }
  1508. if (!GETPOST('proptype', 'alpha')) {
  1509. $error++;
  1510. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Type")), null, 'errors');
  1511. }
  1512. if (!$error && !GETPOST('regenerateclasssql') && !GETPOST('regeneratemissing')) {
  1513. $addfieldentry = array(
  1514. 'name'=>GETPOST('propname', 'aZ09'),
  1515. 'label'=>GETPOST('proplabel', 'alpha'),
  1516. 'type'=>strtolower(GETPOST('proptype', 'alpha')),
  1517. 'arrayofkeyval'=>GETPOST('proparrayofkeyval', 'alphawithlgt'), // Example json string '{"0":"Draft","1":"Active","-1":"Cancel"}'
  1518. 'visible'=>GETPOST('propvisible', 'alphanohtml'),
  1519. 'enabled'=>GETPOST('propenabled', 'alphanohtml'),
  1520. 'position'=>GETPOST('propposition', 'int'),
  1521. 'notnull'=>GETPOST('propnotnull', 'int'),
  1522. 'index'=>GETPOST('propindex', 'int'),
  1523. 'foreignkey'=>GETPOST('propforeignkey', 'alpha'),
  1524. 'searchall'=>GETPOST('propsearchall', 'int'),
  1525. 'isameasure'=>GETPOST('propisameasure', 'int'),
  1526. 'comment'=>GETPOST('propcomment', 'alpha'),
  1527. 'help'=>GETPOST('prophelp', 'alpha'),
  1528. 'css'=>GETPOST('propcss', 'alpha'), // Can be 'maxwidth500 widthcentpercentminusxx' for example
  1529. 'cssview'=>GETPOST('propcssview', 'alpha'),
  1530. 'csslist'=>GETPOST('propcsslist', 'alpha'),
  1531. 'default'=>GETPOST('propdefault', 'restricthtml'),
  1532. 'noteditable'=>intval(GETPOST('propnoteditable', 'int')),
  1533. //'alwayseditable'=>intval(GETPOST('propalwayseditable', 'int')),
  1534. 'validate' => GETPOST('propvalidate', 'int')
  1535. );
  1536. if (!empty($addfieldentry['arrayofkeyval']) && !is_array($addfieldentry['arrayofkeyval'])) {
  1537. $tmpdecode = json_decode($addfieldentry['arrayofkeyval'], true);
  1538. if ($tmpdecode) { // If string is already a json
  1539. $addfieldentry['arrayofkeyval'] = $tmpdecode;
  1540. } else { // If string is a list of lines with "key,value"
  1541. $tmparray = dolExplodeIntoArray($addfieldentry['arrayofkeyval'], "\n", ",");
  1542. $addfieldentry['arrayofkeyval'] = $tmparray;
  1543. }
  1544. }
  1545. }
  1546. } else {
  1547. $addfieldentry = array();
  1548. }
  1549. /*if (GETPOST('regeneratemissing'))
  1550. {
  1551. setEventMessages($langs->trans("FeatureNotYetAvailable"), null, 'warnings');
  1552. $error++;
  1553. }*/
  1554. $moduletype = $listofmodules[strtolower($module)]['moduletype'];
  1555. // Edit the class file to write properties
  1556. if (!$error) {
  1557. $object = rebuildObjectClass($destdir, $module, $objectname, $newmask, $srcdir, $addfieldentry, $moduletype);
  1558. if (is_numeric($object) && $object <= 0) {
  1559. $pathoffiletoeditsrc = $destdir.'/class/'.strtolower($objectname).'.class.php';
  1560. setEventMessages($langs->trans('ErrorFailToCreateFile', $pathoffiletoeditsrc), null, 'errors');
  1561. $error++;
  1562. }
  1563. }
  1564. // Edit sql with new properties
  1565. if (!$error) {
  1566. $result = rebuildObjectSql($destdir, $module, $objectname, $newmask, $srcdir, $object, $moduletype);
  1567. if ($result <= 0) {
  1568. setEventMessages($langs->trans('ErrorFailToCreateFile', '.sql'), null, 'errors');
  1569. $error++;
  1570. }
  1571. }
  1572. if (!$error) {
  1573. clearstatcache(true);
  1574. setEventMessages($langs->trans('FilesForObjectUpdated', $objectname), null);
  1575. setEventMessages($langs->trans('WarningDatabaseIsNotUpdated'), null);
  1576. // Make a redirect to reload all data
  1577. header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=objects&module='.$module.($forceddirread ? '@'.$dirread : '').'&tabobj='.$objectname.'&nocache='.time());
  1578. exit;
  1579. }
  1580. }
  1581. if ($dirins && $action == 'confirm_deleteproperty' && $propertykey) {
  1582. $objectname = $tabobj;
  1583. $dirins = $dirread = $listofmodules[strtolower($module)]['moduledescriptorrootpath'];
  1584. $moduletype = $listofmodules[strtolower($module)]['moduletype'];
  1585. $srcdir = $dirread.'/'.strtolower($module);
  1586. $destdir = $dirins.'/'.strtolower($module);
  1587. dol_mkdir($destdir);
  1588. // Edit the class file to write properties
  1589. if (!$error) {
  1590. $object = rebuildObjectClass($destdir, $module, $objectname, $newmask, $srcdir, array(), $propertykey);
  1591. if (is_numeric($object) && $object <= 0) {
  1592. $pathoffiletoeditsrc = $destdir.'/class/'.strtolower($objectname).'.class.php';
  1593. setEventMessages($langs->trans('ErrorFailToCreateFile', $pathoffiletoeditsrc), null, 'errors');
  1594. $error++;
  1595. }
  1596. }
  1597. // Edit sql with new properties
  1598. if (!$error) {
  1599. $result = rebuildObjectSql($destdir, $module, $objectname, $newmask, $srcdir, $object);
  1600. if ($result <= 0) {
  1601. setEventMessages($langs->trans('ErrorFailToCreateFile', '.sql'), null, 'errors');
  1602. $error++;
  1603. }
  1604. }
  1605. if (!$error) {
  1606. setEventMessages($langs->trans('FilesForObjectUpdated', $objectname), null);
  1607. clearstatcache(true);
  1608. // Make a redirect to reload all data
  1609. header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=objects&module='.$module.($forceddirread ? '@'.$dirread : '').'&tabobj='.$objectname);
  1610. exit;
  1611. }
  1612. }
  1613. if ($dirins && $action == 'confirm_deletemodule') {
  1614. if (preg_match('/[^a-z0-9_]/i', $module)) {
  1615. $error++;
  1616. setEventMessages($langs->trans("SpaceOrSpecialCharAreNotAllowed"), null, 'errors');
  1617. }
  1618. if (!$error) {
  1619. $modulelowercase = strtolower($module);
  1620. // Dir for module
  1621. $dir = $dirins.'/'.$modulelowercase;
  1622. $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
  1623. // Dir for module
  1624. $dir = dol_buildpath($modulelowercase, 0);
  1625. // Zip file to build
  1626. $FILENAMEZIP = '';
  1627. // Load module
  1628. dol_include_once($pathtofile);
  1629. $class = 'mod'.$module;
  1630. if (class_exists($class)) {
  1631. try {
  1632. $moduleobj = new $class($db);
  1633. } catch (Exception $e) {
  1634. $error++;
  1635. dol_print_error($db, $e->getMessage());
  1636. }
  1637. } else {
  1638. $error++;
  1639. $langs->load("errors");
  1640. dol_print_error($db, $langs->trans("ErrorFailedToLoadModuleDescriptorForXXX", $module));
  1641. exit;
  1642. }
  1643. $moduleobj->remove();
  1644. $result = dol_delete_dir_recursive($dir);
  1645. if ($result > 0) {
  1646. setEventMessages($langs->trans("DirWasRemoved", $modulelowercase), null);
  1647. clearstatcache(true);
  1648. if (function_exists('opcache_invalidate')) {
  1649. opcache_reset(); // remove the include cache hell !
  1650. }
  1651. header("Location: ".$_SERVER["PHP_SELF"].'?module=deletemodule');
  1652. exit;
  1653. } else {
  1654. setEventMessages($langs->trans("PurgeNothingToDelete"), null, 'warnings');
  1655. }
  1656. }
  1657. $action = '';
  1658. $module = 'deletemodule';
  1659. }
  1660. if ($dirins && $action == 'confirm_deleteobject' && $objectname) {
  1661. if (preg_match('/[^a-z0-9_]/i', $objectname)) {
  1662. $error++;
  1663. setEventMessages($langs->trans("SpaceOrSpecialCharAreNotAllowed"), null, 'errors');
  1664. }
  1665. if (!$error) {
  1666. $modulelowercase = strtolower($module);
  1667. $objectlowercase = strtolower($objectname);
  1668. // Dir for module
  1669. $dir = $dirins.'/'.$modulelowercase;
  1670. // Delete some files
  1671. $filetodelete = array(
  1672. 'myobject_card.php'=>strtolower($objectname).'_card.php',
  1673. 'myobject_note.php'=>strtolower($objectname).'_note.php',
  1674. 'myobject_contact.php'=>strtolower($objectname).'_contact.php',
  1675. 'myobject_document.php'=>strtolower($objectname).'_document.php',
  1676. 'myobject_agenda.php'=>strtolower($objectname).'_agenda.php',
  1677. 'myobject_list.php'=>strtolower($objectname).'_list.php',
  1678. 'admin/myobject_extrafields.php'=>'admin/'.strtolower($objectname).'_extrafields.php',
  1679. 'lib/mymodule_myobject.lib.php'=>'lib/'.strtolower($module).'_'.strtolower($objectname).'.lib.php',
  1680. 'test/phpunit/MyObjectTest.php'=>'test/phpunit/'.strtolower($objectname).'Test.php',
  1681. 'sql/llx_mymodule_myobject.sql'=>'sql/llx_'.strtolower($module).'_'.strtolower($objectname).'.sql',
  1682. 'sql/llx_mymodule_myobject_extrafields.sql'=>'sql/llx_'.strtolower($module).'_'.strtolower($objectname).'_extrafields.sql',
  1683. 'sql/llx_mymodule_myobject.key.sql'=>'sql/llx_'.strtolower($module).'_'.strtolower($objectname).'.key.sql',
  1684. 'sql/llx_mymodule_myobject_extrafields.key.sql'=>'sql/llx_'.strtolower($module).'_'.strtolower($objectname).'_extrafields.key.sql',
  1685. 'scripts/myobject.php'=>'scripts/'.strtolower($objectname).'.php',
  1686. 'class/myobject.class.php'=>'class/'.strtolower($objectname).'.class.php',
  1687. 'class/api_myobject.class.php'=>'class/api_'.strtolower($module).'.class.php',
  1688. 'core/modules/mymodule/mod_myobject_advanced.php'=>'core/modules/'.strtolower($module).'/mod_'.strtolower($objectname).'_advanced.php',
  1689. 'core/modules/mymodule/mod_myobject_standard.php'=>'core/modules/'.strtolower($module).'/mod_'.strtolower($objectname).'_standard.php',
  1690. 'core/modules/mymodule/modules_myobject.php'=>'core/modules/'.strtolower($module).'/modules_'.strtolower($objectname).'.php',
  1691. 'core/modules/mymodule/doc/doc_generic_myobject_odt.modules.php'=>'core/modules/'.strtolower($module).'/doc/doc_generic_'.strtolower($objectname).'_odt.modules.php',
  1692. 'core/modules/mymodule/doc/pdf_standard_myobject.modules.php'=>'core/modules/'.strtolower($module).'/doc/pdf_standard_'.strtolower($objectname).'.modules.php'
  1693. );
  1694. //menu for the object selected
  1695. // load class and check if menu,permission,documentation exist for this object
  1696. $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
  1697. dol_include_once($pathtofile);
  1698. $class = 'mod'.$module;
  1699. if (class_exists($class)) {
  1700. try {
  1701. $moduleobj = new $class($db);
  1702. } catch (Exception $e) {
  1703. $error++;
  1704. dol_print_error($db, $e->getMessage());
  1705. }
  1706. }
  1707. $moduledescriptorfile = $dirins.'/'.strtolower($module).'/core/modules/mod'.$module.'.class.php';
  1708. // delete menus linked to the object
  1709. $menus = $moduleobj->menu;
  1710. $rewriteMenu = checkExistComment($moduledescriptorfile, 0);
  1711. if ($rewriteMenu < 0) {
  1712. setEventMessages($langs->trans("WarningCommentNotFound", $langs->trans("Menus"), "mod".$module."class.php"), null, 'warnings');
  1713. } else {
  1714. reWriteAllMenus($moduledescriptorfile, $menus, $objectname, null, -1);
  1715. }
  1716. // regenerate permissions and delete them
  1717. $permissions = $moduleobj->rights;
  1718. $rewritePerms = checkExistComment($moduledescriptorfile, 1);
  1719. if ($rewritePerms < 0) {
  1720. setEventMessages($langs->trans("WarningCommentNotFound", $langs->trans("Permissions"), "mod".$module."class.php"), null, 'warnings');
  1721. } else {
  1722. reWriteAllPermissions($moduledescriptorfile, $permissions, null, null, $objectname, '', -1);
  1723. }
  1724. if ($rewritePerms && $rewriteMenu) {
  1725. // check if documentation has been generated
  1726. $file_doc = $dirins.'/'.strtolower($module).'/doc/Documentation.asciidoc';
  1727. deletePropsAndPermsFromDoc($file_doc, $objectname);
  1728. clearstatcache(true);
  1729. if (function_exists('opcache_invalidate')) {
  1730. opcache_reset(); // remove the include cache hell !
  1731. }
  1732. $resultko = 0;
  1733. foreach ($filetodelete as $tmpfiletodelete) {
  1734. $resulttmp = dol_delete_file($dir.'/'.$tmpfiletodelete, 0, 0, 1);
  1735. $resulttmp = dol_delete_file($dir.'/'.$tmpfiletodelete.'.back', 0, 0, 1);
  1736. if (!$resulttmp) {
  1737. $resultko++;
  1738. }
  1739. }
  1740. if ($resultko == 0) {
  1741. setEventMessages($langs->trans("FilesDeleted"), null);
  1742. } else {
  1743. setEventMessages($langs->trans("ErrorSomeFilesCouldNotBeDeleted"), null, 'warnings');
  1744. }
  1745. }
  1746. }
  1747. $action = '';
  1748. if (! $error) {
  1749. $tabobj = 'newobject';
  1750. } else {
  1751. $tabobj = 'deleteobject';
  1752. }
  1753. // check if module is enabled
  1754. if (isModEnabled(strtolower($module))) {
  1755. $result = unActivateModule(strtolower($module));
  1756. dolibarr_set_const($db, "MAIN_IHM_PARAMS_REV", (int) $conf->global->MAIN_IHM_PARAMS_REV + 1, 'chaine', 0, '', $conf->entity);
  1757. if ($result) {
  1758. setEventMessages($result, null, 'errors');
  1759. }
  1760. setEventMessages($langs->trans('WarningModuleNeedRefresh', $langs->transnoentities($module)), null, 'warnings');
  1761. header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=objects&tabobj=deleteobject&module='.urlencode($module));
  1762. exit;
  1763. }
  1764. }
  1765. if (($dirins && $action == 'confirm_deletedictionary' && $dicname) || ($dirins && $action == 'confirm_deletedictionary' && GETPOST('dictionnarykey'))) {
  1766. $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
  1767. $destdir = $dirins.'/'.strtolower($module);
  1768. $moduledescriptorfile = $dirins.'/'.strtolower($module).'/core/modules/mod'.$module.'.class.php';
  1769. if (preg_match('/[^a-z0-9_]/i', $dicname)) {
  1770. $error++;
  1771. setEventMessages($langs->trans("SpaceOrSpecialCharAreNotAllowed"), null, 'errors');
  1772. }
  1773. if (!empty($dicname)) {
  1774. $newdicname = $dicname;
  1775. if (!preg_match('/^c_/', $newdicname)) {
  1776. $newdicname = 'c_'.strtolower($dicname);
  1777. }
  1778. }
  1779. dol_include_once($pathtofile);
  1780. $class = 'mod'.$module;
  1781. if (class_exists($class)) {
  1782. try {
  1783. $moduleobj = new $class($db);
  1784. } catch (Exception $e) {
  1785. $error++;
  1786. dol_print_error($db, $e->getMessage());
  1787. }
  1788. } else {
  1789. $error++;
  1790. $langs->load("errors");
  1791. dol_print_error($db, $langs->trans("ErrorFailedToLoadModuleDescriptorForXXX", $module));
  1792. exit;
  1793. }
  1794. $dicts = $moduleobj->dictionaries;
  1795. $checkComment = checkExistComment($moduledescriptorfile, 2);
  1796. if ($checkComment < 0) {
  1797. $error++;
  1798. setEventMessages($langs->trans("WarningCommentNotFound", $langs->trans("Dictionaries"), "mod".$module."class.php"), null, 'warnings');
  1799. }
  1800. if (!empty(GETPOST('dictionnarykey'))) {
  1801. $newdicname = $dicts['tabname'][GETPOST('dictionnarykey')-1];
  1802. }
  1803. //chercher la table dicname
  1804. $query = "SHOW TABLES LIKE '" . MAIN_DB_PREFIX.strtolower($newdicname) . "'";
  1805. $checkTable = $db->query($query);
  1806. if ($checkTable && $db->num_rows($checkTable) <= 0) {
  1807. $error++;
  1808. }
  1809. // search the key by name
  1810. $keyToDelete = null;
  1811. foreach ($dicts['tabname'] as $key => $table) {
  1812. //var_dump($table." /////// ".$newdicname);exit;
  1813. if (strtolower($table) === $newdicname) {
  1814. $keyToDelete = $key;
  1815. break;
  1816. }
  1817. }
  1818. // delete all dicname's key values from the dictionary
  1819. if ($keyToDelete !== null) {
  1820. $keysToDelete = ['tabname', 'tablib', 'tabsql', 'tabsqlsort', 'tabfield', 'tabfieldvalue', 'tabfieldinsert', 'tabrowid', 'tabcond', 'tabhelp'];
  1821. foreach ($keysToDelete as $key) {
  1822. unset($dicts[$key][$keyToDelete]);
  1823. }
  1824. } else {
  1825. $error++;
  1826. setEventMessages($langs->trans("ErrorDictionaryNotFound", ucfirst($dicname)), null, 'errors');
  1827. }
  1828. if (!$error) {
  1829. // delete table
  1830. $_results = $db->DDLDropTable(MAIN_DB_PREFIX.strtolower($newdicname));
  1831. if ($_results < 0) {
  1832. dol_print_error($db);
  1833. $langs->load("errors");
  1834. setEventMessages($langs->trans("ErrorTableNotFound", $newdicname), null, 'errors');
  1835. }
  1836. // rebuild file after update dictionaries
  1837. $result = updateDictionaryInFile($module, $moduledescriptorfile, $dicts);
  1838. if ($result > 0) {
  1839. setEventMessages($langs->trans("DictionaryDeleted", ucfirst(substr($newdicname, 2))), null);
  1840. }
  1841. if (function_exists('opcache_invalidate')) {
  1842. opcache_reset(); // remove the include cache hell !
  1843. }
  1844. clearstatcache(true);
  1845. header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=dictionaries&module='.$module.($forceddirread ? '@'.$dirread : ''));
  1846. exit;
  1847. }
  1848. }
  1849. if ($dirins && $action == 'updatedictionary' && GETPOST('dictionnarykey')) {
  1850. $keydict = GETPOST('dictionnarykey') - 1 ;
  1851. $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
  1852. $destdir = $dirins.'/'.strtolower($module);
  1853. $moduledescriptorfile = $dirins.'/'.strtolower($module).'/core/modules/mod'.$module.'.class.php';
  1854. dol_include_once($pathtofile);
  1855. $class = 'mod'.$module;
  1856. if (class_exists($class)) {
  1857. try {
  1858. $moduleobj = new $class($db);
  1859. } catch (Exception $e) {
  1860. $error++;
  1861. dol_print_error($db, $e->getMessage());
  1862. }
  1863. } else {
  1864. $error++;
  1865. $langs->load("errors");
  1866. dol_print_error($db, $langs->trans("ErrorFailedToLoadModuleDescriptorForXXX", $module));
  1867. exit;
  1868. }
  1869. $dicts = $moduleobj->dictionaries;
  1870. if (!empty(GETPOST('tablib')) && GETPOST('tablib') !== $dicts['tablib'][$keydict]) {
  1871. $dicts['tablib'][$keydict] = ucfirst(strtolower(GETPOST('tablib')));
  1872. $checkComment = checkExistComment($moduledescriptorfile, 2);
  1873. if ($checkComment < 0) {
  1874. setEventMessages($langs->trans("WarningCommentNotFound", $langs->trans("Dictionaries"), "mod".$module."class.php"), null, 'warnings');
  1875. } else {
  1876. $updateDict = updateDictionaryInFile($module, $moduledescriptorfile, $dicts);
  1877. if ($updateDict > 0) {
  1878. setEventMessages($langs->trans("DictionaryNameUpdated", ucfirst(GETPOST('tablib'))), null);
  1879. }
  1880. if (function_exists('opcache_invalidate')) {
  1881. opcache_reset(); // remove the include cache hell !
  1882. }
  1883. clearstatcache(true);
  1884. header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=dictionaries&module='.$module.($forceddirread ? '@'.$dirread : ''));
  1885. exit;
  1886. }
  1887. }
  1888. //var_dump(GETPOST('tablib'));exit;
  1889. }
  1890. if ($dirins && $action == 'generatedoc') {
  1891. $modulelowercase = strtolower($module);
  1892. // Dir for module
  1893. $dirofmodule = dol_buildpath($modulelowercase, 0).'/doc';
  1894. $FILENAMEDOC = strtolower($module).'.html';
  1895. $util = new Utils($db);
  1896. $result = $util->generateDoc($module);
  1897. if ($result > 0) {
  1898. setEventMessages($langs->trans("DocFileGeneratedInto", $dirofmodule), null);
  1899. } else {
  1900. setEventMessages($util->error, $util->errors, 'errors');
  1901. }
  1902. }
  1903. if ($dirins && $action == 'generatepackage') {
  1904. $modulelowercase = strtolower($module);
  1905. $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
  1906. // Dir for module
  1907. $dir = dol_buildpath($modulelowercase, 0);
  1908. // Zip file to build
  1909. $FILENAMEZIP = '';
  1910. // Load module
  1911. dol_include_once($pathtofile);
  1912. $class = 'mod'.$module;
  1913. if (class_exists($class)) {
  1914. try {
  1915. $moduleobj = new $class($db);
  1916. } catch (Exception $e) {
  1917. $error++;
  1918. dol_print_error($db, $e->getMessage());
  1919. }
  1920. } else {
  1921. $error++;
  1922. $langs->load("errors");
  1923. dol_print_error($db, $langs->trans("ErrorFailedToLoadModuleDescriptorForXXX", $module));
  1924. exit;
  1925. }
  1926. $arrayversion = explode('.', $moduleobj->version, 3);
  1927. if (count($arrayversion)) {
  1928. $FILENAMEZIP = "module_".$modulelowercase.'-'.$arrayversion[0].(empty($arrayversion[1]) ? '.0' : '.'.$arrayversion[1]).(empty($arrayversion[2]) ? '' : '.'.$arrayversion[2]).'.zip';
  1929. $dirofmodule = dol_buildpath($modulelowercase, 0).'/bin';
  1930. $outputfilezip = $dirofmodule.'/'.$FILENAMEZIP;
  1931. if ($dirofmodule) {
  1932. if (!dol_is_dir($dirofmodule)) {
  1933. dol_mkdir($dirofmodule);
  1934. }
  1935. // Note: We exclude /bin/ to not include the already generated zip
  1936. $result = dol_compress_dir($dir, $outputfilezip, 'zip', '/\/bin\/|\.git|\.old|\.back|\.ssh/', $modulelowercase);
  1937. } else {
  1938. $result = -1;
  1939. }
  1940. if ($result > 0) {
  1941. setEventMessages($langs->trans("ZipFileGeneratedInto", $outputfilezip), null);
  1942. } else {
  1943. $error++;
  1944. $langs->load("errors");
  1945. setEventMessages($langs->trans("ErrorFailToGenerateFile", $outputfilezip), null, 'errors');
  1946. }
  1947. } else {
  1948. $error++;
  1949. $langs->load("errors");
  1950. setEventMessages($langs->trans("ErrorCheckVersionIsDefined"), null, 'errors');
  1951. }
  1952. }
  1953. // Add permission
  1954. if ($dirins && $action == 'addright' && !empty($module) && empty($cancel)) {
  1955. $error = 0;
  1956. // load class and check if right exist
  1957. $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
  1958. dol_include_once($pathtofile);
  1959. $class = 'mod'.$module;
  1960. if (class_exists($class)) {
  1961. try {
  1962. $moduleobj = new $class($db);
  1963. } catch (Exception $e) {
  1964. $error++;
  1965. dol_print_error($db, $e->getMessage());
  1966. }
  1967. }
  1968. // verify informations entred
  1969. if (!GETPOST('label', 'alpha')) {
  1970. $error++;
  1971. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Label")), null, 'errors');
  1972. }
  1973. if (!GETPOST('permissionObj', 'alpha')) {
  1974. $error++;
  1975. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Rights")), null, 'errors');
  1976. }
  1977. $id = GETPOST('id', 'alpha');
  1978. $label = GETPOST('label', 'alpha');
  1979. $objectForPerms = strtolower(GETPOST('permissionObj', 'alpha'));
  1980. $crud = GETPOST('crud', 'alpha');
  1981. //check existing object permission
  1982. $counter = 0;
  1983. $permsForObject =array();
  1984. $permissions = $moduleobj->rights;
  1985. $allObject = array();
  1986. $countPerms = count($permissions);
  1987. for ($i =0; $i<$countPerms; $i++) {
  1988. if ($permissions[$i][4] == $objectForPerms) {
  1989. $counter++;
  1990. if (count($permsForObject) < 3) {
  1991. $permsForObject[] = $permissions[$i];
  1992. }
  1993. }
  1994. $allObject[] = $permissions[$i][4];
  1995. }
  1996. // check if label of object already exists
  1997. $countPermsObj = count($permsForObject);
  1998. for ($j = 0; $j<$countPermsObj; $j++) {
  1999. if (in_array($crud, $permsForObject[$j])) {
  2000. $error++;
  2001. setEventMessages($langs->trans("ErrorExistingPermission", $langs->transnoentities($crud), $langs->transnoentities($objectForPerms)), null, 'errors');
  2002. }
  2003. }
  2004. if (!$error) {
  2005. $key = $countPerms + 1;
  2006. //prepare right to add
  2007. $rightToAdd = [
  2008. 0=> $id,
  2009. 1=>$label,
  2010. 4=>$objectForPerms,
  2011. 5=>$crud
  2012. ];
  2013. if (isModEnabled(strtolower($module))) {
  2014. $result = unActivateModule(strtolower($module));
  2015. dolibarr_set_const($db, "MAIN_IHM_PARAMS_REV", (int) $conf->global->MAIN_IHM_PARAMS_REV + 1, 'chaine', 0, '', $conf->entity);
  2016. if ($result) {
  2017. setEventMessages($result, null, 'errors');
  2018. }
  2019. setEventMessages($langs->trans('WarningModuleNeedRefresh', $langs->transnoentities($module)), null, 'warnings');
  2020. }
  2021. }
  2022. $moduledescriptorfile = $dirins.'/'.strtolower($module).'/core/modules/mod'.$module.'.class.php';
  2023. //rewriting all permissions after add a right
  2024. $rewrite = checkExistComment($moduledescriptorfile, 1);
  2025. if ($rewrite < 0) {
  2026. setEventMessages($langs->trans("WarningCommentNotFound", $langs->trans("Permissions"), "mod".$module."class.php"), null, 'warnings');
  2027. } else {
  2028. reWriteAllPermissions($moduledescriptorfile, $permissions, $key, $rightToAdd, '', '', 1);
  2029. setEventMessages($langs->trans('PermissionAddedSuccesfuly'), null);
  2030. clearstatcache(true);
  2031. if (function_exists('opcache_invalidate')) {
  2032. opcache_reset(); // remove the include cache hell !
  2033. }
  2034. header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=permissions&module='.$module);
  2035. exit;
  2036. }
  2037. }
  2038. // Update permission
  2039. if ($dirins && GETPOST('action') == 'update_right' && GETPOST('modifyright')&& empty($cancel)) {
  2040. $error = 0;
  2041. // load class and check if right exist
  2042. $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
  2043. dol_include_once($pathtofile);
  2044. $class = 'mod'.$module;
  2045. if (class_exists($class)) {
  2046. try {
  2047. $moduleobj = new $class($db);
  2048. } catch (Exception $e) {
  2049. $error++;
  2050. dol_print_error($db, $e->getMessage());
  2051. }
  2052. }
  2053. // verify informations entred
  2054. if (!GETPOST('label', 'alpha')) {
  2055. $error++;
  2056. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Label")), null, 'errors');
  2057. }
  2058. if (!GETPOST('permissionObj', 'alpha')) {
  2059. $error++;
  2060. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Rights")), null, 'errors');
  2061. }
  2062. $label = GETPOST('label', 'alpha');
  2063. $objectForPerms = strtolower(GETPOST('permissionObj', 'alpha'));
  2064. $crud = GETPOST('crud', 'alpha');
  2065. if ($label == "Read objects of $module" && $crud != "read") {
  2066. $crud = "read";
  2067. $label == "Read objects of $module";
  2068. }
  2069. if ($label == "Create/Update objects of $module" && $crud != "write") {
  2070. $crud = "write";
  2071. $label == "Create/Update objects of $module";
  2072. }
  2073. if ($label == "Delete objects of $module" && $crud != "delete") {
  2074. $crud = "delete";
  2075. $label == "Delete objects of $module";
  2076. }
  2077. $permissions = $moduleobj->rights;
  2078. $key =(int) GETPOST('counter')-1;
  2079. //get permission want to delete from permissions array
  2080. $x1 = $permissions[$key][1];
  2081. $x2 = $permissions[$key][4];
  2082. $x3 = $permissions[$key][5];
  2083. //check existing object permission
  2084. $counter = 0;
  2085. $permsForObject =array();
  2086. $permissions = $moduleobj->rights;
  2087. $firstRight = 0;
  2088. $existRight = 0;
  2089. $allObject = array();
  2090. $countPerms = count($permissions);
  2091. for ($i =0; $i<$countPerms; $i++) {
  2092. if ($permissions[$i][4] == $objectForPerms) {
  2093. $counter++;
  2094. if (count($permsForObject) < 3) {
  2095. $permsForObject[] = $permissions[$i];
  2096. }
  2097. }
  2098. $allObject[] = $permissions[$i][4];
  2099. }
  2100. if ($label != $x1 && $crud != $x3) {
  2101. $countPermsObj = count($permsForObject);
  2102. for ($j = 0; $j<$countPermsObj; $j++) {
  2103. if (in_array($label, $permsForObject[$j])) {
  2104. $error++;
  2105. setEventMessages($langs->trans("ErrorExistingPermission", $langs->transnoentities($label), $langs->transnoentities($objectForPerms)), null, 'errors');
  2106. }
  2107. }
  2108. }
  2109. if (!$error) {
  2110. if (isModEnabled(strtolower($module))) {
  2111. $result = unActivateModule(strtolower($module));
  2112. dolibarr_set_const($db, "MAIN_IHM_PARAMS_REV", (int) $conf->global->MAIN_IHM_PARAMS_REV + 1, 'chaine', 0, '', $conf->entity);
  2113. if ($result) {
  2114. setEventMessages($result, null, 'errors');
  2115. }
  2116. setEventMessages($langs->trans('WarningModuleNeedRefresh', $langs->transnoentities($module)), null, 'warnings');
  2117. }
  2118. $moduledescriptorfile = $dirins.'/'.strtolower($module).'/core/modules/mod'.$module.'.class.php';
  2119. // rewriting all permissions after update permission needed
  2120. $rewrite = checkExistComment($moduledescriptorfile, 1);
  2121. if ($rewrite < 0) {
  2122. setEventMessages($langs->trans("WarningCommentNotFound", $langs->trans("Permissions"), "mod".$module."class.php"), null, 'warnings');
  2123. } else {
  2124. reWriteAllPermissions($moduledescriptorfile, $permissions, $key, $rightUpdated, '', '', 2);
  2125. setEventMessages($langs->trans('PermissionUpdatedSuccesfuly'), null);
  2126. clearstatcache(true);
  2127. if (function_exists('opcache_invalidate')) {
  2128. opcache_reset(); // remove the include cache hell !
  2129. }
  2130. header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=permissions&module='.$module);
  2131. exit;
  2132. }
  2133. }
  2134. }
  2135. // Delete permission
  2136. if ($dirins && $action == 'confirm_deleteright' && !empty($module) && GETPOST('permskey', 'int')) {
  2137. $error = 0;
  2138. // load class and check if right exist
  2139. $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
  2140. dol_include_once($pathtofile);
  2141. $class = 'mod'.$module;
  2142. if (class_exists($class)) {
  2143. try {
  2144. $moduleobj = new $class($db);
  2145. } catch (Exception $e) {
  2146. $error++;
  2147. dol_print_error($db, $e->getMessage());
  2148. }
  2149. }
  2150. $permissions = $moduleobj->rights;
  2151. $key = (int) GETPOST('permskey', 'int')-1;
  2152. if (!$error) {
  2153. // check if module is enabled
  2154. if (isModEnabled(strtolower($module))) {
  2155. $result = unActivateModule(strtolower($module));
  2156. dolibarr_set_const($db, "MAIN_IHM_PARAMS_REV", (int) $conf->global->MAIN_IHM_PARAMS_REV + 1, 'chaine', 0, '', $conf->entity);
  2157. if ($result) {
  2158. setEventMessages($result, null, 'errors');
  2159. }
  2160. setEventMessages($langs->trans('WarningModuleNeedRefresh', $langs->transnoentities($module)), null, 'warnings');
  2161. header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=permissions&module='.$module);
  2162. exit;
  2163. }
  2164. // rewriting all permissions
  2165. $moduledescriptorfile = $dirins.'/'.strtolower($module).'/core/modules/mod'.$module.'.class.php';
  2166. $rewrite = checkExistComment($moduledescriptorfile, 1);
  2167. if ($rewrite < 0) {
  2168. setEventMessages($langs->trans("WarningCommentNotFound", $langs->trans("Permissions"), "mod".$module."class.php"), null, 'warnings');
  2169. } else {
  2170. reWriteAllPermissions($moduledescriptorfile, $permissions, $key, null, '', '', 0);
  2171. setEventMessages($langs->trans('PermissionDeletedSuccesfuly'), null);
  2172. clearstatcache(true);
  2173. if (function_exists('opcache_invalidate')) {
  2174. opcache_reset(); // remove the include cache hell !
  2175. }
  2176. header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=permissions&module='.$module);
  2177. exit;
  2178. }
  2179. }
  2180. }
  2181. // Save file
  2182. if ($action == 'savefile' && empty($cancel)) {
  2183. $relofcustom = basename($dirins);
  2184. if ($relofcustom) {
  2185. // Check that relative path ($file) start with name 'custom'
  2186. if (!preg_match('/^'.$relofcustom.'/', $file)) {
  2187. $file = $relofcustom.'/'.$file;
  2188. }
  2189. $pathoffile = dol_buildpath($file, 0);
  2190. $pathoffilebackup = dol_buildpath($file.'.back', 0);
  2191. // Save old version
  2192. if (dol_is_file($pathoffile)) {
  2193. dol_copy($pathoffile, $pathoffilebackup, 0, 1);
  2194. }
  2195. $check = 'restricthtml';
  2196. $srclang = dol_mimetype($pathoffile, '', 3);
  2197. if ($srclang == 'md') {
  2198. $check = 'restricthtml';
  2199. }
  2200. if ($srclang == 'lang') {
  2201. $check = 'restricthtml';
  2202. }
  2203. if ($srclang == 'php') {
  2204. $check = 'none';
  2205. }
  2206. $content = GETPOST('editfilecontent', $check);
  2207. // Save file on disk
  2208. if ($content) {
  2209. dol_delete_file($pathoffile);
  2210. $result = file_put_contents($pathoffile, $content);
  2211. if ($result) {
  2212. dolChmod($pathoffile, $newmask);
  2213. setEventMessages($langs->trans("FileSaved"), null);
  2214. } else {
  2215. setEventMessages($langs->trans("ErrorFailedToSaveFile"), null, 'errors');
  2216. }
  2217. } else {
  2218. setEventMessages($langs->trans("ContentCantBeEmpty"), null, 'errors');
  2219. //$action='editfile';
  2220. $error++;
  2221. }
  2222. }
  2223. }
  2224. // Enable module
  2225. if ($action == 'set' && $user->admin) {
  2226. $param = '';
  2227. if ($module) {
  2228. $param .= '&module='.urlencode($module);
  2229. }
  2230. if ($tab) {
  2231. $param .= '&tab='.urlencode($tab);
  2232. }
  2233. if ($tabobj) {
  2234. $param .= '&tabobj='.urlencode($tabobj);
  2235. }
  2236. $value = GETPOST('value', 'alpha');
  2237. $resarray = activateModule($value);
  2238. if (!empty($resarray['errors'])) {
  2239. setEventMessages('', $resarray['errors'], 'errors');
  2240. } else {
  2241. //var_dump($resarray);exit;
  2242. if ($resarray['nbperms'] > 0) {
  2243. $tmpsql = "SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX."user WHERE admin <> 1";
  2244. $resqltmp = $db->query($tmpsql);
  2245. if ($resqltmp) {
  2246. $obj = $db->fetch_object($resqltmp);
  2247. //var_dump($obj->nb);exit;
  2248. if ($obj && $obj->nb > 1) {
  2249. $msg = $langs->trans('ModuleEnabledAdminMustCheckRights');
  2250. setEventMessages($msg, null, 'warnings');
  2251. }
  2252. } else {
  2253. dol_print_error($db);
  2254. }
  2255. }
  2256. }
  2257. header("Location: ".$_SERVER["PHP_SELF"]."?".$param);
  2258. exit;
  2259. }
  2260. // Disable module
  2261. if ($action == 'reset' && $user->admin) {
  2262. $param = '';
  2263. if ($module) {
  2264. $param .= '&module='.urlencode($module);
  2265. }
  2266. if ($tab) {
  2267. $param .= '&tab='.urlencode($tab);
  2268. }
  2269. if ($tabobj) {
  2270. $param .= '&tabobj='.urlencode($tabobj);
  2271. }
  2272. $value = GETPOST('value', 'alpha');
  2273. $result = unActivateModule($value);
  2274. if ($result) {
  2275. setEventMessages($result, null, 'errors');
  2276. }
  2277. header("Location: ".$_SERVER["PHP_SELF"]."?".$param);
  2278. exit;
  2279. }
  2280. // delete menu
  2281. if ($dirins && $action == 'confirm_deletemenu' && GETPOST('menukey', 'int')) {
  2282. // check if module is enabled
  2283. if (isModEnabled(strtolower($module))) {
  2284. $result = unActivateModule(strtolower($module));
  2285. dolibarr_set_const($db, "MAIN_IHM_PARAMS_REV", (int) $conf->global->MAIN_IHM_PARAMS_REV + 1, 'chaine', 0, '', $conf->entity);
  2286. if ($result) {
  2287. setEventMessages($result, null, 'errors');
  2288. }
  2289. setEventMessages($langs->trans('WarningModuleNeedRefresh', $langs->transnoentities($module)), null, 'warnings');
  2290. header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=menus&module='.$module);
  2291. exit;
  2292. }
  2293. // load class and check if menu exist
  2294. $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
  2295. dol_include_once($pathtofile);
  2296. $class = 'mod'.$module;
  2297. if (class_exists($class)) {
  2298. try {
  2299. $moduleobj = new $class($db);
  2300. } catch (Exception $e) {
  2301. $error++;
  2302. dol_print_error($db, $e->getMessage());
  2303. }
  2304. }
  2305. // get all objects and convert value to lower case for compare
  2306. $dir = $listofmodules[strtolower($module)]['moduledescriptorrootpath'];
  2307. $destdir = $dir.'/'.strtolower($module);
  2308. $objects = dolGetListOfObjectClasses($destdir);
  2309. $result = array_map('strtolower', $objects);
  2310. $menus = $moduleobj->menu;
  2311. $key = (int) GETPOST('menukey', 'int');
  2312. $moduledescriptorfile = $dirins.'/'.strtolower($module).'/core/modules/mod'.$module.'.class.php';
  2313. $checkcomment = checkExistComment($moduledescriptorfile, 0);
  2314. if ($checkcomment < 0) {
  2315. setEventMessages($langs->trans("WarningCommentNotFound", $langs->trans("Menus"), "mod".$module."class.php"), null, 'warnings');
  2316. } else {
  2317. if ($menus[$key]['fk_menu'] === 'fk_mainmenu='.strtolower($module)) {
  2318. if (in_array(strtolower($menus[$key]['leftmenu']), $result)) {
  2319. reWriteAllMenus($moduledescriptorfile, $menus, $menus[$key]['leftmenu'], $key, -1);
  2320. } else {
  2321. reWriteAllMenus($moduledescriptorfile, $menus, null, $key, 0);
  2322. }
  2323. } else {
  2324. reWriteAllMenus($moduledescriptorfile, $menus, null, $key, 0);
  2325. }
  2326. clearstatcache(true);
  2327. if (function_exists('opcache_invalidate')) {
  2328. opcache_reset(); // remove the include cache hell !
  2329. }
  2330. setEventMessages($langs->trans('MenuDeletedSuccessfuly'), null);
  2331. header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=menus&module='.$module);
  2332. exit;
  2333. }
  2334. }
  2335. // Add menu in module without initial object
  2336. if ($dirins && $action == 'addmenu' && empty($cancel)) {
  2337. // check if module is enabled
  2338. if (isModEnabled(strtolower($module))) {
  2339. $result = unActivateModule(strtolower($module));
  2340. dolibarr_set_const($db, "MAIN_IHM_PARAMS_REV", (int) $conf->global->MAIN_IHM_PARAMS_REV + 1, 'chaine', 0, '', $conf->entity);
  2341. if ($result) {
  2342. setEventMessages($result, null, 'errors');
  2343. }
  2344. setEventMessages($langs->trans('WarningModuleNeedRefresh', $langs->transnoentities($module)), null, 'warnings');
  2345. header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=menus&module='.$module);
  2346. exit;
  2347. }
  2348. $error = 0;
  2349. // load class and check if right exist
  2350. $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
  2351. dol_include_once($pathtofile);
  2352. $class = 'mod'.$module;
  2353. if (class_exists($class)) {
  2354. try {
  2355. $moduleobj = new $class($db);
  2356. } catch (Exception $e) {
  2357. $error++;
  2358. dol_print_error($db, $e->getMessage());
  2359. }
  2360. }
  2361. // get all menus
  2362. $menus = $moduleobj->menu;
  2363. //verify fields required
  2364. if (!GETPOST('type', 'alpha')) {
  2365. $error++;
  2366. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Type")), null, 'errors');
  2367. }
  2368. if (!GETPOST('titre', 'alpha')) {
  2369. $error++;
  2370. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Title")), null, 'errors');
  2371. }
  2372. if (!GETPOST('user', 'alpha')) {
  2373. $error++;
  2374. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("DetailUser")), null, 'errors');
  2375. }
  2376. if (!GETPOST('url', 'alpha')) {
  2377. $error++;
  2378. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Url")), null, 'errors');
  2379. }
  2380. if (!empty(GETPOST('target'))) {
  2381. $targets = array('_blank','_self','_parent','_top','');
  2382. if (!in_array(GETPOST('target'), $targets)) {
  2383. $error++;
  2384. setEventMessages($langs->trans("ErrorFieldValue", $langs->transnoentities("target")), null, 'errors');
  2385. }
  2386. }
  2387. // check if title or url already exist in menus
  2388. foreach ($menus as $menu) {
  2389. if (!empty(GETPOST('url')) && GETPOST('url') == $menu['url']) {
  2390. $error++;
  2391. setEventMessages($langs->trans("ErrorFieldExist", $langs->transnoentities("url")), null, 'errors');
  2392. break;
  2393. }
  2394. if (strtolower(GETPOST('titre')) == strtolower($menu['titre'])) {
  2395. $error++;
  2396. setEventMessages($langs->trans("ErrorFieldExist", $langs->transnoentities("titre")), null, 'errors');
  2397. break;
  2398. }
  2399. }
  2400. if (GETPOST('type', 'alpha') == 'left' && !empty(GETPOST('lefmenu', 'alpha'))) {
  2401. if (!str_contains(GETPOST('leftmenu'), strtolower($module))) {
  2402. $error++;
  2403. setEventMessages($langs->trans("WarningFieldsMustContains", $langs->transnoentities("leftmenu")), null, 'errors');
  2404. }
  2405. }
  2406. $dirins = $listofmodules[strtolower($module)]['moduledescriptorrootpath'];
  2407. $destdir = $dirins.'/'.strtolower($module);
  2408. $objects = dolGetListOfObjectClasses($destdir);
  2409. if (GETPOST('type', 'alpha') == 'left') {
  2410. if (empty(GETPOST('leftmenu')) && count($objects) >0) {
  2411. $error++;
  2412. setEventMessages($langs->trans("ErrorCoherenceMenu", $langs->transnoentities("leftmenu"), $langs->transnoentities("type")), null, 'errors');
  2413. }
  2414. }
  2415. if (GETPOST('type', 'alpha') == 'top') {
  2416. $error++;
  2417. setEventMessages($langs->trans("ErrorTypeMenu", $langs->transnoentities("type")), null, 'errors');
  2418. }
  2419. $moduledescriptorfile = $dirins.'/'.strtolower($module).'/core/modules/mod'.$module.'.class.php';
  2420. if (!$error) {
  2421. //stock forms in array
  2422. $menuToAdd = array(
  2423. 'fk_menu' => GETPOST('fk_menu', 'alpha'),
  2424. 'type' => GETPOST('type', 'alpha'),
  2425. 'titre' => ucfirst(GETPOST('titre', 'alpha')),
  2426. 'prefix' => '',
  2427. 'mainmenu' => GETPOST('mainmenu', 'alpha'),
  2428. 'leftmenu' => GETPOST('leftmenu', 'alpha'),
  2429. 'url' => GETPOST('url', 'alpha'),
  2430. 'langs' => strtolower($module)."@".strtolower($module),
  2431. 'position' => '',
  2432. 'enabled' => GETPOST('enabled', 'alpha'),
  2433. 'perms' => '$user->hasRight("'.strtolower($module).'", "'.GETPOST('objects', 'alpha').'", "'.GETPOST('perms', 'alpha').'")',
  2434. 'target' => GETPOST('target', 'alpha'),
  2435. 'user' => GETPOST('user', 'alpha'),
  2436. );
  2437. if (GETPOST('type') == 'left') {
  2438. unset($menuToAdd['prefix']);
  2439. if (empty(GETPOST('fk_menu'))) {
  2440. $menuToAdd['fk_menu'] = 'fk_mainmenu='.GETPOST('mainmenu', 'alpha');
  2441. } else {
  2442. $menuToAdd['fk_menu'] = 'fk_mainmenu='.GETPOST('mainmenu', 'alpha').',fk_leftmenu='.GETPOST('fk_menu');
  2443. }
  2444. }
  2445. if (GETPOST('enabled') == '1') {
  2446. $menuToAdd['enabled'] = 'isModEnabled("'.strtolower($module).'")';
  2447. } else {
  2448. $menuToAdd['enabled'] = "0";
  2449. }
  2450. if (empty(GETPOST('objects'))) {
  2451. $menuToAdd['perms'] = '1';
  2452. }
  2453. $checkcomment = checkExistComment($moduledescriptorfile, 0);
  2454. if ($checkcomment < 0) {
  2455. setEventMessages($langs->trans("WarningCommentNotFound", $langs->trans("Menus"), "mod".$module."class.php"), null, 'warnings');
  2456. } else {
  2457. // Write all menus
  2458. $result = reWriteAllMenus($moduledescriptorfile, $menus, $menuToAdd, null, 1);
  2459. clearstatcache(true);
  2460. if (function_exists('opcache_invalidate')) {
  2461. opcache_reset();
  2462. }
  2463. /*if ($result < 0) {
  2464. setEventMessages($langs->trans('ErrorMenuExistValue'), null, 'errors');
  2465. header("Location: ".$_SERVER["PHP_SELF"].'?action=editmenu&token='.newToken().'&menukey='.urlencode($key+1).'&tab='.urlencode($tab).'&module='.urlencode($module).'&tabobj='.($key+1));
  2466. exit;
  2467. }*/
  2468. header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=menus&module='.$module);
  2469. setEventMessages($langs->trans('MenuAddedSuccesfuly'), null);
  2470. exit;
  2471. }
  2472. }
  2473. }
  2474. // Modify a menu entry
  2475. if ($dirins && $action == "update_menu" && GETPOST('menukey', 'int') && GETPOST('tabobj')) {
  2476. $objectname = GETPOST('tabobj');
  2477. $dirins = $listofmodules[strtolower($module)]['moduledescriptorrootpath'];
  2478. $destdir = $dirins.'/'.strtolower($module);
  2479. $objects = dolGetListOfObjectClasses($destdir);
  2480. if (empty($cancel)) {
  2481. if (isModEnabled(strtolower($module))) {
  2482. $result = unActivateModule(strtolower($module));
  2483. dolibarr_set_const($db, "MAIN_IHM_PARAMS_REV", (int) $conf->global->MAIN_IHM_PARAMS_REV + 1, 'chaine', 0, '', $conf->entity);
  2484. if ($result) {
  2485. setEventMessages($result, null, 'errors');
  2486. }
  2487. setEventMessages($langs->trans('WarningModuleNeedRefresh', $langs->transnoentities($module)), null, 'warnings');
  2488. header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=menus&module='.$module);
  2489. exit;
  2490. }
  2491. $error = 0;
  2492. // for loading class and the menu wants to modify
  2493. $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
  2494. dol_include_once($pathtofile);
  2495. $class = 'mod'.$module;
  2496. if (class_exists($class)) {
  2497. try {
  2498. $moduleobj = new $class($db);
  2499. } catch (Exception $e) {
  2500. $error++;
  2501. dol_print_error($db, $e->getMessage());
  2502. }
  2503. }
  2504. $menus = $moduleobj->menu;
  2505. $key = (int) GETPOST('menukey', 'int') - 1;
  2506. $moduledescriptorfile = $dirins.'/'.strtolower($module).'/core/modules/mod'.$module.'.class.php';
  2507. //stock forms in array
  2508. $menuModify = array(
  2509. 'fk_menu' => GETPOST('fk_menu', 'alpha'),
  2510. 'type' => GETPOST('type', 'alpha'),
  2511. 'titre' => ucfirst(GETPOST('titre', 'alpha')),
  2512. 'mainmenu' => GETPOST('mainmenu', 'alpha'),
  2513. 'leftmenu' => $menus[$key]['leftmenu'],
  2514. 'url' => GETPOST('url', 'alpha'),
  2515. 'langs' => strtolower($module)."@".strtolower($module),
  2516. 'position' => '',
  2517. 'enabled' => GETPOST('enabled', 'alpha'),
  2518. 'perms' => GETPOST('perms', 'alpha'),
  2519. 'target' => GETPOST('target', 'alpha'),
  2520. 'user' => GETPOST('user', 'alpha'),
  2521. );
  2522. if (!empty(GETPOST('fk_menu')) && GETPOST('fk_menu') != $menus[$key]['fk_menu']) {
  2523. $menuModify['fk_menu'] = 'fk_mainmenu='.GETPOST('mainmenu').',fk_leftmenu='.GETPOST('fk_menu');
  2524. } elseif (GETPOST('fk_menu') == $menus[$key]['fk_menu']) {
  2525. $menuModify['fk_menu'] = $menus[$key]['fk_menu'];
  2526. } else {
  2527. $menuModify['fk_menu'] = 'fk_mainmenu='.GETPOST('mainmenu');
  2528. }
  2529. if ($menuModify['enabled'] === '') {
  2530. $menuModify['enabled'] = '1';
  2531. }
  2532. if ($menuModify['perms'] === '') {
  2533. $menuModify['perms'] = '1';
  2534. }
  2535. if (GETPOST('type', 'alpha') == 'top') {
  2536. $error++;
  2537. setEventMessages($langs->trans("ErrorTypeMenu", $langs->transnoentities("type")), null, 'errors');
  2538. }
  2539. if (!$error) {
  2540. //update menu
  2541. $checkComment = checkExistComment($moduledescriptorfile, 0);
  2542. if ($checkComment < 0) {
  2543. setEventMessages($langs->trans("WarningCommentNotFound", $langs->trans("Menus"), "mod".$module."class.php"), null, 'warnings');
  2544. } else {
  2545. // Write all menus
  2546. $result = reWriteAllMenus($moduledescriptorfile, $menus, $menuModify, $key, 2);
  2547. clearstatcache(true);
  2548. if (function_exists('opcache_invalidate')) {
  2549. opcache_reset();
  2550. }
  2551. if ($result < 0) {
  2552. setEventMessages($langs->trans('ErrorMenuExistValue'), null, 'errors');
  2553. //var_dump($_SESSION);exit;
  2554. header("Location: ".$_SERVER["PHP_SELF"].'?action=editmenu&token='.newToken().'&menukey='.urlencode($key+1).'&tab='.urlencode($tab).'&module='.urlencode($module).'&tabobj='.($key+1));
  2555. exit;
  2556. }
  2557. setEventMessages($langs->trans('MenuUpdatedSuccessfuly'), null);
  2558. header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=menus&module='.$module);
  2559. exit;
  2560. }
  2561. }
  2562. } else {
  2563. $_POST['type'] = '';
  2564. $_POST['titre'] = '';
  2565. $_POST['fk_menu'] = '';
  2566. $_POST['leftmenu'] = '';
  2567. $_POST['url'] = '';
  2568. }
  2569. }
  2570. // update properties description of module
  2571. if ($dirins && $action == "update_props_module" && !empty(GETPOST('keydescription', 'alpha')) && empty($cancel)) {
  2572. if (isModEnabled(strtolower($module))) {
  2573. $result = unActivateModule(strtolower($module));
  2574. dolibarr_set_const($db, "MAIN_IHM_PARAMS_REV", (int) $conf->global->MAIN_IHM_PARAMS_REV + 1, 'chaine', 0, '', $conf->entity);
  2575. if ($result) {
  2576. setEventMessages($result, null, 'errors');
  2577. }
  2578. setEventMessages($langs->trans('WarningModuleNeedRefresh', $langs->transnoentities($module)), null, 'warnings');
  2579. header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=menus&module='.$module);
  2580. exit;
  2581. }
  2582. $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
  2583. $moduledescriptorfile = $dirins.'/'.strtolower($module).'/core/modules/mod'.$module.'.class.php';
  2584. $modulelogfile = $dirins.'/'.strtolower($module).'/ChangeLog.md';
  2585. dol_include_once($pathtofile);
  2586. $class = 'mod'.$module;
  2587. if (class_exists($class)) {
  2588. try {
  2589. $moduleobj = new $class($db);
  2590. } catch (Exception $e) {
  2591. $error++;
  2592. dol_print_error($db, $e->getMessage());
  2593. }
  2594. }
  2595. $keydescription = GETPOST('keydescription', 'alpha');
  2596. switch ($keydescription) {
  2597. case 'desc':
  2598. $propertyToUpdate = 'description';
  2599. break;
  2600. case 'version':
  2601. case 'family':
  2602. case 'picto':
  2603. case 'editor_name':
  2604. case 'editor_url':
  2605. $propertyToUpdate = $keydescription;
  2606. break;
  2607. default:
  2608. $error = GETPOST('keydescription');
  2609. break;
  2610. }
  2611. if (isset($propertyToUpdate) && !empty(GETPOST('propsmodule'))) {
  2612. $newValue = GETPOST('propsmodule');
  2613. $lineToReplace = "\t\t\$this->$propertyToUpdate = ";
  2614. $newLine = "\t\t\$this->$propertyToUpdate = '$newValue';\n";
  2615. //for change version in log file
  2616. if ($propertyToUpdate === 'version') {
  2617. dolReplaceInFile($modulelogfile, array("## ".$moduleobj->$propertyToUpdate => $newValue));
  2618. }
  2619. $fileLines = file($moduledescriptorfile);
  2620. foreach ($fileLines as &$line) {
  2621. if (strpos($line, $lineToReplace) === 0) {
  2622. dolReplaceInFile($moduledescriptorfile, array($line => $newLine));
  2623. break;
  2624. }
  2625. }
  2626. clearstatcache(true);
  2627. if (function_exists('opcache_invalidate')) {
  2628. opcache_reset();
  2629. }
  2630. setEventMessages($langs->trans('PropertyModuleUpdated', $propertyToUpdate), null);
  2631. header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=description&module='.$module);
  2632. exit;
  2633. }
  2634. }
  2635. /*
  2636. * View
  2637. */
  2638. $form = new Form($db);
  2639. $formadmin = new FormAdmin($db);
  2640. // Set dir where external modules are installed
  2641. if (!dol_is_dir($dirins)) {
  2642. dol_mkdir($dirins);
  2643. }
  2644. $dirins_ok = (dol_is_dir($dirins));
  2645. $help_url = '';
  2646. $morejs = array(
  2647. '/includes/ace/src/ace.js',
  2648. '/includes/ace/src/ext-statusbar.js',
  2649. '/includes/ace/src/ext-language_tools.js',
  2650. //'/includes/ace/src/ext-chromevox.js'
  2651. );
  2652. $morecss = array();
  2653. llxHeader('', $langs->trans("ModuleBuilder"), $help_url, '', 0, 0, $morejs, $morecss, '', 'classforhorizontalscrolloftabs');
  2654. $text = $langs->trans("ModuleBuilder");
  2655. print load_fiche_titre($text, '', 'title_setup');
  2656. print '<span class="opacitymedium hideonsmartphone">'.$langs->trans("ModuleBuilderDesc", 'https://wiki.dolibarr.org/index.php/Module_development#Create_your_module').'</span>';
  2657. print '<br class="hideonsmartphone">';
  2658. //print $textforlistofdirs;
  2659. //print '<br>';
  2660. $message = '';
  2661. if (!$dirins) {
  2662. $message = info_admin($langs->trans("ConfFileMustContainCustom", DOL_DOCUMENT_ROOT.'/custom', DOL_DOCUMENT_ROOT));
  2663. $allowfromweb = -1;
  2664. } else {
  2665. if ($dirins_ok) {
  2666. if (!is_writable(dol_osencode($dirins))) {
  2667. $langs->load("errors");
  2668. $message = info_admin($langs->trans("ErrorFailedToWriteInDir", $dirins));
  2669. $allowfromweb = 0;
  2670. }
  2671. } else {
  2672. $message = info_admin($langs->trans("NotExistsDirect", $dirins).$langs->trans("InfDirAlt").$langs->trans("InfDirExample"));
  2673. $allowfromweb = 0;
  2674. }
  2675. }
  2676. if ($message) {
  2677. print $message;
  2678. }
  2679. //print $langs->trans("ModuleBuilderDesc3", count($listofmodules), $FILEFLAG).'<br>';
  2680. $infomodulesfound = '<div style="padding: 12px 9px 12px">'.$form->textwithpicto('', $langs->trans("ModuleBuilderDesc3", count($listofmodules)).'<br><br>'.$langs->trans("ModuleBuilderDesc4", $FILEFLAG).'<br>'.$textforlistofdirs).'</div>';
  2681. $dolibarrdataroot = preg_replace('/([\\/]+)$/i', '', DOL_DATA_ROOT);
  2682. $allowonlineinstall = true;
  2683. if (dol_is_file($dolibarrdataroot.'/installmodules.lock')) {
  2684. $allowonlineinstall = false;
  2685. }
  2686. if (empty($allowonlineinstall)) {
  2687. if (getDolGlobalString('MAIN_MESSAGE_INSTALL_MODULES_DISABLED_CONTACT_US')) {
  2688. // Show clean message
  2689. $message = info_admin($langs->trans('InstallModuleFromWebHasBeenDisabledContactUs'));
  2690. } else {
  2691. // Show technical message
  2692. $message = info_admin($langs->trans("InstallModuleFromWebHasBeenDisabledByFile", $dolibarrdataroot.'/installmodules.lock'), 0, 0, 1, 'warning');
  2693. }
  2694. print $message;
  2695. llxFooter();
  2696. exit(0);
  2697. }
  2698. // Load module descriptor
  2699. $error = 0;
  2700. $moduleobj = null;
  2701. if (!empty($module) && $module != 'initmodule' && $module != 'deletemodule') {
  2702. $modulelowercase = strtolower($module);
  2703. $loadclasserrormessage = '';
  2704. // Load module
  2705. try {
  2706. $fullpathdirtodescriptor = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
  2707. //throw(new Exception());
  2708. dol_include_once($fullpathdirtodescriptor);
  2709. $class = 'mod'.$module;
  2710. } catch (Throwable $e) { // This is called in PHP 7 only (includes Error and Exception)
  2711. $loadclasserrormessage = $e->getMessage()."<br>\n";
  2712. $loadclasserrormessage .= 'File: '.$e->getFile()."<br>\n";
  2713. $loadclasserrormessage .= 'Line: '.$e->getLine()."<br>\n";
  2714. }
  2715. if (class_exists($class)) {
  2716. try {
  2717. $moduleobj = new $class($db);
  2718. } catch (Exception $e) {
  2719. $error++;
  2720. print $e->getMessage();
  2721. }
  2722. } else {
  2723. if (empty($forceddirread)) {
  2724. $error++;
  2725. }
  2726. $langs->load("errors");
  2727. print '<!-- ErrorFailedToLoadModuleDescriptorForXXX -->';
  2728. print img_warning('').' '.$langs->trans("ErrorFailedToLoadModuleDescriptorForXXX", $module).'<br>';
  2729. print $loadclasserrormessage;
  2730. }
  2731. }
  2732. print '<br>';
  2733. // Tabs for all modules
  2734. $head = array();
  2735. $h = 0;
  2736. $head[$h][0] = $_SERVER["PHP_SELF"].'?module=initmodule';
  2737. $head[$h][1] = '<span class="valignmiddle text-plus-circle">'.$langs->trans("NewModule").'</span><span class="fa fa-plus-circle valignmiddle paddingleft"></span>';
  2738. $head[$h][2] = 'initmodule';
  2739. $h++;
  2740. $linktoenabledisable = '';
  2741. if (is_array($listofmodules) && count($listofmodules) > 0) {
  2742. // Define $linktoenabledisable
  2743. $modulelowercase = strtolower($module);
  2744. $param = '';
  2745. if ($tab) {
  2746. $param .= '&tab='.urlencode($tab);
  2747. }
  2748. if ($module) {
  2749. $param .= '&module='.urlencode($module);
  2750. }
  2751. if ($tabobj) {
  2752. $param .= '&tabobj='.urlencode($tabobj);
  2753. }
  2754. $urltomodulesetup = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?search_keyword='.urlencode($module).'">'.$langs->trans('Home').'-'.$langs->trans("Setup").'-'.$langs->trans("Modules").'</a>';
  2755. // Define $linktoenabledisable to show after module title
  2756. if (isModEnabled($modulelowercase)) { // If module is already activated
  2757. $linktoenabledisable .= '<a class="reposition asetresetmodule valignmiddle" href="'.$_SERVER["PHP_SELF"].'?id='.$moduleobj->numero.'&action=reset&token='.newToken().'&value=mod'.$module.$param.'">';
  2758. $linktoenabledisable .= img_picto($langs->trans("Activated"), 'switch_on', '', false, 0, 0, '', '', 1);
  2759. $linktoenabledisable .= '</a>';
  2760. $linktoenabledisable .= $form->textwithpicto('', $langs->trans("Warning").' : '.$langs->trans("ModuleIsLive"), -1, 'warning');
  2761. $objMod = $moduleobj;
  2762. $backtourlparam = '';
  2763. $backtourlparam .= ($backtourlparam ? '&' : '?').'module='.$module; // No urlencode here, done later
  2764. if ($tab) {
  2765. $backtourlparam .= ($backtourlparam ? '&' : '?').'tab='.$tab; // No urlencode here, done later
  2766. }
  2767. $backtourl = $_SERVER["PHP_SELF"].$backtourlparam;
  2768. $regs = array();
  2769. if (is_array($objMod->config_page_url)) {
  2770. $i = 0;
  2771. foreach ($objMod->config_page_url as $page) {
  2772. $urlpage = $page;
  2773. if ($i++) {
  2774. $linktoenabledisable .= ' <a href="'.$urlpage.'" title="'.$langs->trans($page).'">'.img_picto(ucfirst($page), "setup").'</a>';
  2775. // print '<a href="'.$page.'">'.ucfirst($page).'</a>&nbsp;';
  2776. } else {
  2777. if (preg_match('/^([^@]+)@([^@]+)$/i', $urlpage, $regs)) {
  2778. $urltouse = dol_buildpath('/'.$regs[2].'/admin/'.$regs[1], 1);
  2779. $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>';
  2780. } else {
  2781. // Case standard admin page (not a page provided by the
  2782. // module but a page provided by dolibarr)
  2783. $urltouse = DOL_URL_ROOT.'/admin/'.$urlpage;
  2784. $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>';
  2785. }
  2786. }
  2787. }
  2788. } elseif (preg_match('/^([^@]+)@([^@]+)$/i', $objMod->config_page_url, $regs)) {
  2789. $linktoenabledisable .= ' &nbsp; <a href="'.dol_buildpath('/'.$regs[2].'/admin/'.$regs[1], 1).'?save_lastsearch_values=1&backtopage='.urlencode($backtourl).'" title="'.$langs->trans("Setup").'">'.img_picto($langs->trans("Setup"), "setup", 'style="padding-right: 8px"').'</a>';
  2790. }
  2791. } else {
  2792. if (!empty($moduleobj)) {
  2793. $linktoenabledisable .= '<a class="reposition asetresetmodule valignmiddle" href="'.$_SERVER["PHP_SELF"].'?id='.$moduleobj->numero.'&action=set&token='.newToken().'&value=mod'.$module.$param.'">';
  2794. $linktoenabledisable .= img_picto($langs->trans("ModuleIsNotActive", $urltomodulesetup), 'switch_off', 'style="padding-right: 8px"', false, 0, 0, '', 'classfortooltip', 1);
  2795. $linktoenabledisable .= "</a>\n";
  2796. }
  2797. }
  2798. // Loop to show tab of each module
  2799. foreach ($listofmodules as $tmpmodule => $tmpmodulearray) {
  2800. $head[$h][0] = $_SERVER["PHP_SELF"].'?module='.$tmpmodulearray['modulenamewithcase'].($forceddirread ? '@'.$dirread : '');
  2801. $head[$h][1] = $tmpmodulearray['modulenamewithcase'];
  2802. $head[$h][2] = $tmpmodulearray['modulenamewithcase'];
  2803. if ($tmpmodulearray['modulenamewithcase'] == $module) {
  2804. $head[$h][4] = '<span class="inline-block">'.$linktoenabledisable.'</span>';
  2805. }
  2806. $h++;
  2807. }
  2808. }
  2809. $head[$h][0] = $_SERVER["PHP_SELF"].'?module=deletemodule';
  2810. $head[$h][1] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("DangerZone");
  2811. $head[$h][2] = 'deletemodule';
  2812. $h++;
  2813. print dol_get_fiche_head($head, $module, '', -1, '', 0, $infomodulesfound, '', 8); // Modules
  2814. if ($module == 'initmodule') {
  2815. // New module
  2816. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  2817. print '<input type="hidden" name="token" value="'.newToken().'">';
  2818. print '<input type="hidden" name="action" value="initmodule">';
  2819. print '<input type="hidden" name="module" value="initmodule">';
  2820. //print '<span class="opacitymedium">'.$langs->trans("ModuleBuilderDesc2", 'conf/conf.php', $newdircustom).'</span><br>';
  2821. print '<br>';
  2822. print '<div class="tagtable">';
  2823. print '<div class="tagtr"><div class="tagtd paddingright">';
  2824. print '<span class="opacitymedium">'.$langs->trans("IdModule").'</span>';
  2825. print '</div><div class="tagtd">';
  2826. print '<input type="text" name="idmodule" class="width75" value="500000" placeholder="'.dol_escape_htmltag($langs->trans("IdModule")).'">';
  2827. print '<span class="opacitymedium">';
  2828. print ' &nbsp; (';
  2829. print dolButtonToOpenUrlInDialogPopup('popup_modules_id', $langs->transnoentitiesnoconv("SeeIDsInUse"), $langs->transnoentitiesnoconv("SeeIDsInUse"), '/admin/system/modules.php?mainmenu=home&leftmenu=admintools_info', '', '');
  2830. print ' - ';
  2831. print '<a href="https://wiki.dolibarr.org/index.php/List_of_modules_id" target="_blank" rel="noopener noreferrer external">'.$langs->trans("SeeReservedIDsRangeHere").'</a>';
  2832. print ')';
  2833. print '</span>';
  2834. print '</div></div>';
  2835. print '<div class="tagtr"><div class="tagtd paddingright">';
  2836. print '<span class="opacitymedium fieldrequired">'.$langs->trans("ModuleName").'</span>';
  2837. print '</div><div class="tagtd">';
  2838. print '<input type="text" name="modulename" value="'.dol_escape_htmltag($modulename).'" autofocus>';
  2839. print ' '.$form->textwithpicto('', $langs->trans("EnterNameOfModuleDesc"));
  2840. print '</div></div>';
  2841. print '<div class="tagtr"><div class="tagtd paddingright">';
  2842. print '<span class="opacitymedium">'.$langs->trans("Description").'</span>';
  2843. print '</div><div class="tagtd">';
  2844. print '<input type="text" name="description" value="" class="minwidth500"><br>';
  2845. print '</div></div>';
  2846. print '<div class="tagtr"><div class="tagtd paddingright">';
  2847. print '<span class="opacitymedium">'.$langs->trans("Version").'</span>';
  2848. print '</div><div class="tagtd">';
  2849. print '<input type="text" name="version" class="width75" value="'.(GETPOSTISSET('version') ? GETPOST('version') : getDolGlobalString('MODULEBUILDER_SPECIFIC_VERSION', '1.0')).'" placeholder="'.dol_escape_htmltag($langs->trans("Version")).'">';
  2850. print '</div></div>';
  2851. print '<div class="tagtr"><div class="tagtd paddingright">';
  2852. print '<span class="opacitymedium">'.$langs->trans("Family").'</span>';
  2853. print '</div><div class="tagtd">';
  2854. print '<select name="family" id="family" class="minwidth400">';
  2855. $arrayoffamilies = array(
  2856. 'hr' => "ModuleFamilyHr",
  2857. 'crm' => "ModuleFamilyCrm",
  2858. 'srm' => "ModuleFamilySrm",
  2859. 'financial' => 'ModuleFamilyFinancial',
  2860. 'products' => 'ModuleFamilyProducts',
  2861. 'projects' => 'ModuleFamilyProjects',
  2862. 'ecm' => 'ModuleFamilyECM',
  2863. 'technic' => 'ModuleFamilyTechnic',
  2864. 'portal' => 'ModuleFamilyPortal',
  2865. 'interface' => 'ModuleFamilyInterface',
  2866. 'base' => 'ModuleFamilyBase',
  2867. 'other' => 'ModuleFamilyOther'
  2868. );
  2869. foreach ($arrayoffamilies as $key => $value) {
  2870. print '<option value="hr"'.($key == getDolGlobalString('MODULEBUILDER_SPECIFIC_FAMILY', 'other') ? ' selected="selected"' : '').' data-html="'.dol_escape_htmltag($langs->trans($value).' <span class="opacitymedium">- '.$key.'</span>').'">'.$langs->trans($value).'</option>';
  2871. }
  2872. print '</select>';
  2873. print ajax_combobox("family");
  2874. print '</div></div>';
  2875. print '<div class="tagtr"><div class="tagtd paddingright">';
  2876. print '<span class="opacitymedium">'.$langs->trans("Picto").'</span>';
  2877. print '</div><div class="tagtd">';
  2878. print '<input type="text" name="idpicto" value="'.(GETPOSTISSET('idpicto') ? GETPOST('idpicto') : getDolGlobalString('MODULEBUILDER_DEFAULTPICTO', 'fa-file-o')).'" placeholder="'.dol_escape_htmltag($langs->trans("Picto")).'">';
  2879. print $form->textwithpicto('', $langs->trans("Example").': fa-file-o, fa-globe, ... any font awesome code.<br>Advanced syntax is fa-fakey[_faprefix[_facolor[_fasize]]]');
  2880. print '</div></div>';
  2881. print '<div class="tagtr"><div class="tagtd paddingright">';
  2882. print '<span class="opacitymedium">'.$langs->trans("EditorName").'</span>';
  2883. print '</div><div class="tagtd">';
  2884. print '<input type="text" name="editorname" value="'.(GETPOSTISSET('editorname') ? GETPOST('editorname') : getDolGlobalString('MODULEBUILDER_SPECIFIC_EDITOR_NAME', $mysoc->name)).'" placeholder="'.dol_escape_htmltag($langs->trans("EditorName")).'"><br>';
  2885. print '</div></div>';
  2886. print '<div class="tagtr"><div class="tagtd paddingright">';
  2887. print '<span class="opacitymedium">'.$langs->trans("EditorUrl").'</span>';
  2888. print '</div><div class="tagtd">';
  2889. print '<input type="text" name="editorurl" value="'.(GETPOSTISSET('editorurl') ? GETPOST('editorurl') : getDolGlobalString('MODULEBUILDER_SPECIFIC_EDITOR_URL', $mysoc->url)).'" placeholder="'.dol_escape_htmltag($langs->trans("EditorUrl")).'"><br>';
  2890. print '</div></div>';
  2891. print '<br><input type="submit" class="button" name="create" value="'.dol_escape_htmltag($langs->trans("Create")).'"'.($dirins ? '' : ' disabled="disabled"').'>';
  2892. print '</form>';
  2893. } elseif ($module == 'deletemodule') {
  2894. print '<!-- Form to init a module -->'."\n";
  2895. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST" name="delete">';
  2896. print '<input type="hidden" name="token" value="'.newToken().'">';
  2897. print '<input type="hidden" name="action" value="confirm_deletemodule">';
  2898. print '<input type="hidden" name="module" value="deletemodule">';
  2899. print $langs->trans("EnterNameOfModuleToDeleteDesc").'<br><br>';
  2900. print '<input type="text" name="module" placeholder="'.dol_escape_htmltag($langs->trans("ModuleKey")).'" value="">';
  2901. print '<input type="submit" class="button smallpaddingimp" value="'.$langs->trans("Delete").'"'.($dirins ? '' : ' disabled="disabled"').'>';
  2902. print '</form>';
  2903. } elseif (!empty($module)) {
  2904. // Tabs for module
  2905. if (!$error) {
  2906. $dirread = $listofmodules[strtolower($module)]['moduledescriptorrootpath'];
  2907. $destdir = $dirread.'/'.strtolower($module);
  2908. $objects = dolGetListOfObjectClasses($destdir);
  2909. $diroflang = dol_buildpath($modulelowercase, 0)."/langs";
  2910. $countLangs = countItemsInDirectory($diroflang, 2);
  2911. $countDictionaries = (!empty($moduleobj->dictionaries) ? count($moduleobj->dictionaries['tabname']) : 0);
  2912. $countRights = count($moduleobj->rights);
  2913. $countMenus = count($moduleobj->menu);
  2914. $countTriggers = countItemsInDirectory(dol_buildpath($modulelowercase, 0)."/core/triggers");
  2915. $countWidgets = countItemsInDirectory(dol_buildpath($modulelowercase, 0)."/core/boxes");
  2916. $countCss = countItemsInDirectory(dol_buildpath($modulelowercase, 0)."/css");
  2917. $countJs = countItemsInDirectory(dol_buildpath($modulelowercase, 0)."/js");
  2918. $countCLI = countItemsInDirectory(dol_buildpath($modulelowercase, 0)."/scripts");
  2919. $hasDoc = countItemsInDirectory(dol_buildpath($modulelowercase, 0)."/doc");
  2920. //var_dump($moduleobj->dictionaries);exit;
  2921. $head2 = array();
  2922. $h = 0;
  2923. $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=description&module='.$module.($forceddirread ? '@'.$dirread : '');
  2924. $head2[$h][1] = $langs->trans("Description");
  2925. $head2[$h][2] = 'description';
  2926. $h++;
  2927. $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=objects&module='.$module.($forceddirread ? '@'.$dirread : '');
  2928. $head2[$h][1] = ((!is_array($objects) || count($objects) <= 0) ? $langs->trans("Objects") : $langs->trans("Objects").'<span class="marginleftonlyshort badge">'.count($objects)."</span>");
  2929. $head2[$h][2] = 'objects';
  2930. $h++;
  2931. $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=languages&module='.$module.($forceddirread ? '@'.$dirread : '');
  2932. $head2[$h][1] = ($countLangs <= 0 ? $langs->trans("Languages") : $langs->trans("Languages").'<span class="marginleftonlyshort badge">'.$countLangs."</span>");
  2933. $head2[$h][2] = 'languages';
  2934. $h++;
  2935. $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=dictionaries&module='.$module.($forceddirread ? '@'.$dirread : '');
  2936. $head2[$h][1] = ($countDictionaries == 0 ? $langs->trans("Dictionaries") : $langs->trans('Dictionaries').'<span class="marginleftonlyshort badge">'.$countDictionaries."</span>");
  2937. $head2[$h][2] = 'dictionaries';
  2938. $h++;
  2939. $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=permissions&module='.$module.($forceddirread ? '@'.$dirread : '');
  2940. $head2[$h][1] = ($countRights <= 0 ? $langs->trans("Permissions") : $langs->trans("Permissions").'<span class="marginleftonlyshort badge">'.$countRights."</span>");
  2941. $head2[$h][2] = 'permissions';
  2942. $h++;
  2943. $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=tabs&module='.$module.($forceddirread ? '@'.$dirread : '');
  2944. $head2[$h][1] = $langs->trans("Tabs");
  2945. $head2[$h][2] = 'tabs';
  2946. $h++;
  2947. $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=menus&module='.$module.($forceddirread ? '@'.$dirread : '');
  2948. $head2[$h][1] = ($countMenus <= 0 ? $langs->trans("Menus") : $langs->trans("Menus").'<span class="marginleftonlyshort badge">'.$countMenus."</span>");
  2949. $head2[$h][2] = 'menus';
  2950. $h++;
  2951. $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=hooks&module='.$module.($forceddirread ? '@'.$dirread : '');
  2952. $head2[$h][1] = $langs->trans("Hooks");
  2953. $head2[$h][2] = 'hooks';
  2954. $h++;
  2955. $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=triggers&module='.$module.($forceddirread ? '@'.$dirread : '');
  2956. $head2[$h][1] = ($countTriggers <= 0 ? $langs->trans("Triggers") : $langs->trans("Triggers").'<span class="marginleftonlyshort badge">'.$countTriggers."</span>");
  2957. $head2[$h][2] = 'triggers';
  2958. $h++;
  2959. $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=widgets&module='.$module.($forceddirread ? '@'.$dirread : '');
  2960. $head2[$h][1] = ($countWidgets <= 0 ? $langs->trans("Widgets") : $langs->trans("Widgets").'<span class="marginleftonlyshort badge">'.$countWidgets."</span>");
  2961. $head2[$h][2] = 'widgets';
  2962. $h++;
  2963. $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=exportimport&module='.$module.($forceddirread ? '@'.$dirread : '');
  2964. $head2[$h][1] = $langs->trans("Export").'-'.$langs->trans("Import");
  2965. $head2[$h][2] = 'exportimport';
  2966. $h++;
  2967. $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=css&module='.$module.($forceddirread ? '@'.$dirread : '');
  2968. $head2[$h][1] = ($countCss <= 0 ? $langs->trans("CSS") : $langs->trans("CSS")." (".$countCss.")");
  2969. $head2[$h][2] = 'css';
  2970. $h++;
  2971. $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=js&module='.$module.($forceddirread ? '@'.$dirread : '');
  2972. $head2[$h][1] = ($countJs <= 0 ? $langs->trans("JS") : $langs->trans("JS").'<span class="marginleftonlyshort badge">'.$countJs."</span>");
  2973. $head2[$h][2] = 'js';
  2974. $h++;
  2975. $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=cli&module='.$module.($forceddirread ? '@'.$dirread : '');
  2976. $head2[$h][1] = ($countCLI <= 0 ? $langs->trans("CLI") : $langs->trans("CLI").'<span class="marginleftonlyshort badge">'.$countCLI."</span>");
  2977. $head2[$h][2] = 'cli';
  2978. $h++;
  2979. $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=cron&module='.$module.($forceddirread ? '@'.$dirread : '');
  2980. $head2[$h][1] = $langs->trans("CronList");
  2981. $head2[$h][2] = 'cron';
  2982. $h++;
  2983. $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=specifications&module='.$module.($forceddirread ? '@'.$dirread : '');
  2984. $head2[$h][1] = ($hasDoc <= 0 ? $langs->trans("Documentation") : $langs->trans("Documentation").'<span class="paddingleft badge">'.$hasDoc."</span>");
  2985. $head2[$h][2] = 'specifications';
  2986. $h++;
  2987. $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=buildpackage&module='.$module.($forceddirread ? '@'.$dirread : '');
  2988. $head2[$h][1] = $langs->trans("BuildPackage");
  2989. $head2[$h][2] = 'buildpackage';
  2990. $h++;
  2991. $MAXTABFOROBJECT = 15;
  2992. print '<!-- Section for a given module -->';
  2993. // Note module is inside $dirread
  2994. if ($tab == 'description') {
  2995. print '<!-- tab=description -->'."\n";
  2996. $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
  2997. $pathtofilereadme = $modulelowercase.'/README.md';
  2998. $pathtochangelog = $modulelowercase.'/ChangeLog.md';
  2999. $realpathofmodule = realpath($dirread.'/'.$modulelowercase);
  3000. if ($action != 'editfile' || empty($file)) {
  3001. $morehtmlright = '';
  3002. if ($realpathofmodule != $dirread.'/'.$modulelowercase) {
  3003. $morehtmlright = '<div style="padding: 12px 9px 12px">'.$form->textwithpicto('', '<span class="opacitymedium">'.$langs->trans("RealPathOfModule").' :</span> <strong class="wordbreak">'.$realpathofmodule.'</strong>').'</div>';
  3004. }
  3005. print dol_get_fiche_head($head2, $tab, '', -1, '', 0, $morehtmlright, '', $MAXTABFOROBJECT, 'formodulesuffix'); // Description - level 2
  3006. print '<span class="opacitymedium">'.$langs->trans("ModuleBuilderDesc".$tab).'</span>';
  3007. print '<br><br>';
  3008. print '<table>';
  3009. print '<tr><td>';
  3010. print '<span class="fa fa-file-o"></span> '.$langs->trans("DescriptorFile").' : <strong class="wordbreak">'.$pathtofile.'</strong>';
  3011. print '</td><td><a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&token='.newToken().'&format=php&file='.urlencode($pathtofile).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
  3012. print '</td></tr>';
  3013. // List of setup pages
  3014. $listofsetuppages = dol_dir_list($realpathofmodule.'/admin', 'files', 0, '\.php$');
  3015. foreach ($listofsetuppages as $setuppage) {
  3016. //var_dump($setuppage);
  3017. print '<tr><td>';
  3018. print '<span class="fa fa-file-o"></span> '.$langs->trans("SetupFile").' : <strong class="wordbreak">'.$modulelowercase.'/admin/'.$setuppage['relativename'].'</strong>';
  3019. print '</td><td><a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&token='.newToken().'&format=php&file='.urlencode($modulelowercase.'/admin/'.$setuppage['relativename']).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
  3020. print '</td></tr>';
  3021. }
  3022. print '<tr><td><span class="fa fa-file-o"></span> '.$langs->trans("ReadmeFile").' : <strong class="wordbreak">'.$pathtofilereadme.'</strong>';
  3023. print '</td><td><a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&token='.newToken().'&format=markdown&file='.urlencode($pathtofilereadme).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
  3024. print '</td></tr>';
  3025. print '<tr><td><span class="fa fa-file-o"></span> '.$langs->trans("ChangeLog").' : <strong class="wordbreak">'.$pathtochangelog.'</strong>';
  3026. print '</td><td><a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&token='.newToken().'&format=markdown&file='.urlencode($pathtochangelog).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
  3027. print '</td></tr>';
  3028. print '</table>';
  3029. print '<br>';
  3030. print load_fiche_titre($form->textwithpicto($langs->trans("DescriptorFile"), $langs->transnoentitiesnoconv("File").' '.$pathtofile), '', '');
  3031. if (!empty($moduleobj)) {
  3032. print '<div class="underbanner clearboth"></div>';
  3033. print '<div class="fichecenter">';
  3034. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  3035. print '<input type="hidden" name="token" value="'.newToken().'">';
  3036. print '<input type="hidden" name="action" value="update_props_module">';
  3037. print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
  3038. print '<input type="hidden" name="tab" value="'.dol_escape_htmltag($tab).'">';
  3039. print '<input type="hidden" name="keydescription" value="'.dol_escape_htmltag(GETPOST('keydescription', 'alpha')).'">';
  3040. print '<table class="border centpercent">';
  3041. print '<tr class="liste_titre"><td class="titlefield">';
  3042. print $langs->trans("Parameter");
  3043. print '</td><td>';
  3044. print $langs->trans("Value");
  3045. print '</td></tr>';
  3046. print '<tr><td>';
  3047. print $langs->trans("IdModule");
  3048. print '</td><td>';
  3049. print $moduleobj->numero;
  3050. print '<span class="opacitymedium">';
  3051. print ' &nbsp; (';
  3052. print dolButtonToOpenUrlInDialogPopup('popup_modules_id', $langs->transnoentitiesnoconv("SeeIDsInUse"), $langs->transnoentitiesnoconv("SeeIDsInUse"), '/admin/system/modules.php?mainmenu=home&leftmenu=admintools_info', '', '');
  3053. print ' - <a href="https://wiki.dolibarr.org/index.php/List_of_modules_id" target="_blank" rel="noopener noreferrer external">'.$langs->trans("SeeReservedIDsRangeHere").'</a>)';
  3054. print '</span>';
  3055. print '</td></tr>';
  3056. print '<tr><td>';
  3057. print $langs->trans("ModuleName");
  3058. print '</td><td>';
  3059. print $moduleobj->getName();
  3060. print '</td></tr>';
  3061. print '<tr><td>';
  3062. print $langs->trans("Description");
  3063. print '</td><td>';
  3064. if ($action == 'edit_moduledescription' && GETPOST('keydescription', 'alpha') === 'desc') {
  3065. print '<input class="minwidth500" name="propsmodule" value="'.dol_escape_htmltag($moduleobj->description).'">';
  3066. print '<input class="reposition button smallpaddingimp" type="submit" name="modifydesc" value="'.$langs->trans("Modify").'"/>';
  3067. print '<input class="reposition button button-cancel smallpaddingimp" type="submit" name="cancel" value="'.$langs->trans("Cancel").'"/>';
  3068. } else {
  3069. print $moduleobj->getDesc();
  3070. print '<a class="editfielda reposition marginleftonly marginrighttonly paddingright paddingleft" href="'.$_SERVER["PHP_SELF"].'?action=edit_moduledescription&token='.newToken().'&tab='.urlencode($tab).'&module='.urlencode($module).'&keydescription=desc">'.img_edit().'</a>';
  3071. }
  3072. print '</td></tr>';
  3073. print '<tr><td>';
  3074. print $langs->trans("Version");
  3075. print '</td><td>';
  3076. if ($action == 'edit_moduledescription' && GETPOST('keydescription', 'alpha') === 'version') {
  3077. print '<input name="propsmodule" value="'.dol_escape_htmltag($moduleobj->getVersion()).'">';
  3078. print '<input class="reposition button smallpaddingimp" type="submit" name="modifyversion" value="'.$langs->trans("Modify").'"/>';
  3079. print '<input class="reposition button button-cancel smallpaddingimp" type="submit" name="cancel" value="'.$langs->trans("Cancel").'"/>';
  3080. } else {
  3081. print $moduleobj->getVersion();
  3082. print '<a class="editfielda reposition marginleftonly marginrighttonly paddingright paddingleft" href="'.$_SERVER["PHP_SELF"].'?action=edit_moduledescription&token='.newToken().'&tab='.urlencode($tab).'&module='.urlencode($module).'&keydescription=version">'.img_edit().'</a>';
  3083. }
  3084. print '</td></tr>';
  3085. print '<tr><td>';
  3086. print $langs->trans("Family");
  3087. //print "<br>'crm','financial','hr','projects','products','ecm','technic','interface','other'";
  3088. print '</td><td>';
  3089. if ($action == 'edit_moduledescription' && GETPOST('keydescription', 'alpha') === 'family') {
  3090. print '<select name="propsmodule" id="family" class="minwidth400">';
  3091. $arrayoffamilies = array(
  3092. 'hr' => "ModuleFamilyHr",
  3093. 'crm' => "ModuleFamilyCrm",
  3094. 'srm' => "ModuleFamilySrm",
  3095. 'financial' => 'ModuleFamilyFinancial',
  3096. 'products' => 'ModuleFamilyProducts',
  3097. 'projects' => 'ModuleFamilyProjects',
  3098. 'ecm' => 'ModuleFamilyECM',
  3099. 'technic' => 'ModuleFamilyTechnic',
  3100. 'portal' => 'ModuleFamilyPortal',
  3101. 'interface' => 'ModuleFamilyInterface',
  3102. 'base' => 'ModuleFamilyBase',
  3103. 'other' => 'ModuleFamilyOther'
  3104. );
  3105. print '<option value="'.$moduleobj->family.'" data-html="'.dol_escape_htmltag($langs->trans($arrayoffamilies[$moduleobj->family]).' <span class="opacitymedium">- '.$moduleobj->family.'</span>').'">'.$langs->trans($arrayoffamilies[$moduleobj->family]).'</option>';
  3106. foreach ($arrayoffamilies as $key => $value) {
  3107. if ($key != $moduleobj->family) {
  3108. print '<option value="'.$key.'" data-html="'.dol_escape_htmltag($langs->trans($value).' <span class="opacitymedium">- '.$key.'</span>').'">'.$langs->trans($value).'</option>';
  3109. }
  3110. }
  3111. print '</select>';
  3112. print '<input class="reposition button smallpaddingimp" type="submit" name="modifyfamily" value="'.$langs->trans("Modify").'"/>';
  3113. print '<input class="reposition button button-cancel smallpaddingimp" type="submit" name="cancel" value="'.$langs->trans("Cancel").'"/>';
  3114. } else {
  3115. print $moduleobj->family;
  3116. print '<a class="editfielda reposition marginleftonly marginrighttonly paddingright paddingleft" href="'.$_SERVER["PHP_SELF"].'?action=edit_moduledescription&token='.newToken().'&tab='.urlencode($tab).'&module='.urlencode($module).'&keydescription=family">'.img_edit().'</a>';
  3117. }
  3118. print '</td></tr>';
  3119. print '<tr><td>';
  3120. print $langs->trans("Picto");
  3121. print '</td><td>';
  3122. if ($action == 'edit_modulepicto' && GETPOST('keydescription', 'alpha') === 'picto') {
  3123. print '<input class="minwidth500" name="propsmodule" value="'.dol_escape_htmltag($moduleobj->picto).'">';
  3124. print '<input class="reposition button smallpaddingimp" type="submit" name="modifypicto" value="'.$langs->trans("Modify").'"/>';
  3125. print '<input class="reposition button button-cancel smallpaddingimp" type="submit" name="cancel" value="'.$langs->trans("Cancel").'"/>';
  3126. } else {
  3127. print $moduleobj->picto;
  3128. print ' &nbsp; '.img_picto('', $moduleobj->picto, 'class="valignmiddle pictomodule paddingrightonly"');
  3129. print '<a class="editfielda reposition marginleftonly marginrighttonly paddingright paddingleft" href="'.$_SERVER["PHP_SELF"].'?action=edit_modulepicto&token='.newToken().'&tab='.urlencode($tab).'&module='.urlencode($module).'&keydescription=picto">'.img_edit().'</a>';
  3130. }
  3131. print '</td></tr>';
  3132. print '<tr><td>';
  3133. print $langs->trans("EditorName");
  3134. print '</td><td>';
  3135. if ($action == 'edit_moduledescription' && GETPOST('keydescription', 'alpha') === 'editor_name') {
  3136. print '<input name="propsmodule" value="'.dol_escape_htmltag($moduleobj->editor_name).'">';
  3137. print '<input class="reposition button smallpaddingimp" type="submit" name="modifyname" value="'.$langs->trans("Modify").'"/>';
  3138. print '<input class="reposition button button-cancel smallpaddingimp" type="submit" name="cancel" value="'.$langs->trans("Cancel").'"/>';
  3139. } else {
  3140. print $moduleobj->editor_name;
  3141. print '<a class="editfielda reposition marginleftonly marginrighttonly paddingright paddingleft" href="'.$_SERVER["PHP_SELF"].'?action=edit_moduledescription&token='.newToken().'&tab='.urlencode($tab).'&module='.urlencode($module).'&keydescription=editor_name">'.img_edit().'</a>';
  3142. }
  3143. print '</td></tr>';
  3144. print '<tr><td>';
  3145. print $langs->trans("EditorUrl");
  3146. print '</td><td>';
  3147. if ($action == 'edit_moduledescription' && GETPOST('keydescription', 'alpha') === 'editor_url') {
  3148. print '<input name="propsmodule" value="'.dol_escape_htmltag($moduleobj->editor_url).'">';
  3149. print '<input class="reposition button smallpaddingimp" type="submit" name="modifyeditorurl" value="'.$langs->trans("Modify").'"/>';
  3150. print '<input class="reposition button button-cancel smallpaddingimp" type="submit" name="cancel" value="'.$langs->trans("Cancel").'"/>';
  3151. } else {
  3152. if (!empty($moduleobj->editor_url)) {
  3153. print '<a href="'.$moduleobj->editor_url.'" target="_blank" rel="noopener">'.$moduleobj->editor_url.' '.img_picto('', 'globe').'</a>';
  3154. }
  3155. print '<a class="editfielda reposition marginleftonly marginrighttonly paddingright paddingleft" href="'.$_SERVER["PHP_SELF"].'?action=edit_moduledescription&token='.newToken().'&tab='.urlencode($tab).'&module='.urlencode($module).'&keydescription=editor_url">'.img_edit().'</a>';
  3156. }
  3157. print '</td></tr>';
  3158. print '</table>';
  3159. print '</form>';
  3160. } else {
  3161. print $langs->trans("ErrorFailedToLoadModuleDescriptorForXXX", $module).'<br>';
  3162. }
  3163. if (!empty($moduleobj)) {
  3164. print '<br><br>';
  3165. // Readme file
  3166. print load_fiche_titre($form->textwithpicto($langs->trans("ReadmeFile"), $langs->transnoentitiesnoconv("File").' '.$pathtofilereadme), '', '');
  3167. print '<!-- readme file -->';
  3168. if (dol_is_file($dirread.'/'.$pathtofilereadme)) {
  3169. print '<div class="underbanner clearboth"></div><div class="fichecenter">'.$moduleobj->getDescLong().'</div>';
  3170. } else {
  3171. print '<span class="opacitymedium">'.$langs->trans("ErrorFileNotFound", $pathtofilereadme).'</span>';
  3172. }
  3173. print '<br><br>';
  3174. // ChangeLog
  3175. print load_fiche_titre($form->textwithpicto($langs->trans("ChangeLog"), $langs->transnoentitiesnoconv("File").' '.$pathtochangelog), '', '');
  3176. print '<!-- changelog file -->';
  3177. if (dol_is_file($dirread.'/'.$pathtochangelog)) {
  3178. print '<div class="underbanner clearboth"></div><div class="fichecenter">'.$moduleobj->getChangeLog().'</div>';
  3179. } else {
  3180. print '<span class="opacitymedium">'.$langs->trans("ErrorFileNotFound", $pathtochangelog).'</span>';
  3181. }
  3182. }
  3183. print dol_get_fiche_end();
  3184. } else { // Edit text file
  3185. $fullpathoffile = dol_buildpath($file, 0, 1); // Description - level 2
  3186. if ($fullpathoffile) {
  3187. $content = file_get_contents($fullpathoffile);
  3188. }
  3189. // New module
  3190. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  3191. print '<input type="hidden" name="token" value="'.newToken().'">';
  3192. print '<input type="hidden" name="action" value="savefile">';
  3193. print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
  3194. print '<input type="hidden" name="tab" value="'.$tab.'">';
  3195. print '<input type="hidden" name="module" value="'.$module.'">';
  3196. print dol_get_fiche_head($head2, $tab, '', -1, '', 0, '', '', 0, 'formodulesuffix');
  3197. $doleditor = new DolEditor('editfilecontent', $content, '', '300', 'Full', 'In', true, false, 'ace', 0, '99%', '');
  3198. print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ? GETPOST('format', 'aZ09') : 'html'));
  3199. print dol_get_fiche_end();
  3200. print '<center>';
  3201. print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
  3202. print ' &nbsp; ';
  3203. print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
  3204. print '</center>';
  3205. print '</form>';
  3206. }
  3207. } else {
  3208. print dol_get_fiche_head($head2, $tab, '', -1, '', 0, '', '', $MAXTABFOROBJECT, 'formodulesuffix'); // Level 2
  3209. }
  3210. if ($tab == 'languages') {
  3211. print '<!-- tab=languages -->'."\n";
  3212. if ($action != 'editfile' || empty($file)) {
  3213. print '<span class="opacitymedium">'.$langs->trans("LanguageDefDesc").'</span><br>';
  3214. print '<br>';
  3215. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  3216. print '<input type="hidden" name="token" value="'.newToken().'">';
  3217. print '<input type="hidden" name="action" value="addlanguage">';
  3218. print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
  3219. print '<input type="hidden" name="tab" value="'.$tab.'">';
  3220. print '<input type="hidden" name="module" value="'.$module.'">';
  3221. print $formadmin->select_language($conf->global->MAIN_LANG_DEFAULT, 'newlangcode', 0, 0, 1, 0, 0, 'minwidth300', 1);
  3222. print '<input type="submit" name="addlanguage" class="button smallpaddingimp" value="'.dol_escape_htmltag($langs->trans("AddLanguageFile")).'"><br>';
  3223. print '</form>';
  3224. print '<br>';
  3225. print '<br>';
  3226. $modulelowercase = strtolower($module);
  3227. // Dir for module
  3228. $diroflang = dol_buildpath($modulelowercase, 0);
  3229. $diroflang .= '/langs';
  3230. $langfiles = dol_dir_list($diroflang, 'files', 1, '\.lang$');
  3231. if (!preg_match('/custom/', $dirread)) {
  3232. // If this is not a module into custom
  3233. $diroflang = $dirread;
  3234. $diroflang .= '/langs';
  3235. $langfiles = dol_dir_list($diroflang, 'files', 1, $modulelowercase.'\.lang$');
  3236. }
  3237. print '<table class="none">';
  3238. foreach ($langfiles as $langfile) {
  3239. $pathtofile = $modulelowercase.'/langs/'.$langfile['relativename'];
  3240. if (!preg_match('/custom/', $dirread)) { // If this is not a module into custom
  3241. $pathtofile = 'langs/'.$langfile['relativename'];
  3242. }
  3243. print '<tr><td><span class="fa fa-file-o"></span> '.$langs->trans("LanguageFile").' '.basename(dirname($pathtofile)).' : <strong class="wordbreak">'.$pathtofile.'</strong>';
  3244. print '</td><td><a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&token='.newToken().'&format=ini&file='.urlencode($pathtofile).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
  3245. print '</td><td><a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=confirm_removefile&token='.newToken().'&file='.urlencode($pathtofile).'">'.img_picto($langs->trans("Delete"), 'delete').'</a>';
  3246. print '</td>';
  3247. }
  3248. print '</table>';
  3249. } else {
  3250. // Edit text language file
  3251. //print $langs->trans("UseAsciiDocFormat").'<br>';
  3252. $fullpathoffile = dol_buildpath($file, 0);
  3253. $content = file_get_contents($fullpathoffile);
  3254. // New module
  3255. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  3256. print '<input type="hidden" name="token" value="'.newToken().'">';
  3257. print '<input type="hidden" name="action" value="savefile">';
  3258. print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
  3259. print '<input type="hidden" name="tab" value="'.$tab.'">';
  3260. print '<input type="hidden" name="module" value="'.$module.'">';
  3261. $doleditor = new DolEditor('editfilecontent', $content, '', '300', 'Full', 'In', true, false, 'ace', 0, '99%');
  3262. print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ? GETPOST('format', 'aZ09') : 'text'));
  3263. print '<br>';
  3264. print '<center>';
  3265. print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
  3266. print ' &nbsp; ';
  3267. print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
  3268. print '</center>';
  3269. print '</form>';
  3270. }
  3271. }
  3272. if ($tab == 'objects') {
  3273. print '<!-- tab=objects -->'."\n";
  3274. $head3 = array();
  3275. $h = 0;
  3276. // Dir for module
  3277. $dir = $dirread.'/'.$modulelowercase.'/class';
  3278. $head3[$h][0] = $_SERVER["PHP_SELF"].'?tab=objects&module='.$module.($forceddirread ? '@'.$dirread : '').'&tabobj=newobject';
  3279. $head3[$h][1] = '<span class="valignmiddle text-plus-circle">'.$langs->trans("NewObjectInModulebuilder").'</span><span class="fa fa-plus-circle valignmiddle paddingleft"></span>';
  3280. $head3[$h][2] = 'newobject';
  3281. $h++;
  3282. // Scan for object class files
  3283. $listofobject = dol_dir_list($dir, 'files', 0, '\.class\.php$');
  3284. $firstobjectname = '';
  3285. foreach ($listofobject as $fileobj) {
  3286. if (preg_match('/^api_/', $fileobj['name'])) {
  3287. continue;
  3288. }
  3289. if (preg_match('/^actions_/', $fileobj['name'])) {
  3290. continue;
  3291. }
  3292. $tmpcontent = file_get_contents($fileobj['fullname']);
  3293. if (preg_match('/class\s+([^\s]*)\s+extends\s+CommonObject/ims', $tmpcontent, $reg)) {
  3294. //$objectname = preg_replace('/\.txt$/', '', $fileobj['name']);
  3295. $objectname = $reg[1];
  3296. if (empty($firstobjectname)) {
  3297. $firstobjectname = $objectname;
  3298. }
  3299. $pictoname = 'generic';
  3300. if (preg_match('/\$picto\s*=\s*["\']([^"\']+)["\']/', $tmpcontent, $reg)) {
  3301. $pictoname = $reg[1];
  3302. }
  3303. $head3[$h][0] = $_SERVER["PHP_SELF"].'?tab=objects&module='.$module.($forceddirread ? '@'.$dirread : '').'&tabobj='.$objectname;
  3304. $head3[$h][1] = img_picto('', $pictoname, 'class="pictofixedwidth valignmiddle"').$objectname;
  3305. $head3[$h][2] = $objectname;
  3306. $h++;
  3307. }
  3308. }
  3309. if ($h > 1) {
  3310. $head3[$h][0] = $_SERVER["PHP_SELF"].'?tab=objects&module='.$module.($forceddirread ? '@'.$dirread : '').'&tabobj=deleteobject';
  3311. $head3[$h][1] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("DangerZone");
  3312. $head3[$h][2] = 'deleteobject';
  3313. $h++;
  3314. }
  3315. // 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.
  3316. if ($tabobj == 'newobjectifnoobj') {
  3317. if ($firstobjectname) {
  3318. $tabobj = $firstobjectname;
  3319. } else {
  3320. $tabobj = 'newobject';
  3321. }
  3322. }
  3323. print dol_get_fiche_head($head3, $tabobj, '', -1, '', 0, '', '', 0, 'forobjectsuffix'); // Level 3
  3324. if ($tabobj == 'newobject') {
  3325. // New object tab
  3326. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  3327. print '<input type="hidden" name="token" value="'.newToken().'">';
  3328. print '<input type="hidden" name="action" value="initobject">';
  3329. print '<input type="hidden" name="tab" value="objects">';
  3330. print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
  3331. print '<span class="opacitymedium">'.$langs->trans("EnterNameOfObjectDesc").'</span><br><br>';
  3332. print '<div class="tagtable">';
  3333. print '<div class="tagtr"><div class="tagtd">';
  3334. print '<span class="opacitymedium">'.$langs->trans("ObjectKey").'</span> &nbsp; ';
  3335. print '</div><div class="tagtd">';
  3336. print '<input type="text" name="objectname" maxlength="64" value="'.dol_escape_htmltag(GETPOSTISSET('objectname') ? GETPOST('objectname', 'alpha') : $modulename).'" autofocus>';
  3337. print $form->textwithpicto('', $langs->trans("Example").': MyObject, ACamelCaseName, ...');
  3338. print '</div></div>';
  3339. print '<div class="tagtr"><div class="tagtd">';
  3340. print '<span class="opacitymedium">'.$langs->trans("Picto").'</span> &nbsp; ';
  3341. print '</div><div class="tagtd">';
  3342. print '<input type="text" name="idpicto" value="fa-file-o" placeholder="'.dol_escape_htmltag($langs->trans("Picto")).'">';
  3343. print $form->textwithpicto('', $langs->trans("Example").': fa-file-o, fa-globe, ... any font awesome code.<br>Advanced syntax is fa-fakey[_faprefix[_facolor[_fasize]]]');
  3344. print '</div></div>';
  3345. print '<div class="tagtr"><div class="tagtd">';
  3346. print '<span class="opacitymedium">'.$langs->trans("DefinePropertiesFromExistingTable").'</span> &nbsp; ';
  3347. print '</div><div class="tagtd">';
  3348. print '<input type="text" name="initfromtablename" value="'.GETPOST('initfromtablename').'" placeholder="'.$langs->trans("TableName").'">';
  3349. print $form->textwithpicto('', $langs->trans("DefinePropertiesFromExistingTableDesc").'<br>'.$langs->trans("DefinePropertiesFromExistingTableDesc2"));
  3350. print '</div></div>';
  3351. print '</div>';
  3352. print '<br>';
  3353. print '<input type="checkbox" name="includerefgeneration" id="includerefgeneration" value="includerefgeneration"> <label class="margintoponly" for="includerefgeneration">'.$form->textwithpicto($langs->trans("IncludeRefGeneration"), $langs->trans("IncludeRefGenerationHelp")).'</label><br>';
  3354. print '<input type="checkbox" name="includedocgeneration" id="includedocgeneration" value="includedocgeneration"> <label for="includedocgeneration">'.$form->textwithpicto($langs->trans("IncludeDocGeneration"), $langs->trans("IncludeDocGenerationHelp")).'</label><br>';
  3355. print '<input type="checkbox" name="generatepermissions" id="generatepermissions" value="generatepermissions"> <label for="generatepermissions">'.$form->textwithpicto($langs->trans("GeneratePermissions"), $langs->trans("GeneratePermissionsHelp")).'</label><br>';
  3356. print '<br>';
  3357. print '<input type="submit" class="button small" name="create" value="'.dol_escape_htmltag($langs->trans("GenerateCode")).'"'.($dirins ? '' : ' disabled="disabled"').'>';
  3358. print '<br>';
  3359. print '<br>';
  3360. /*
  3361. print '<br>';
  3362. print '<span class="opacitymedium">'.$langs->trans("or").'</span>';
  3363. print '<br>';
  3364. print '<br>';
  3365. //print '<input type="checkbox" name="initfromtablecheck"> ';
  3366. print $langs->trans("InitStructureFromExistingTable");
  3367. print '<input type="text" name="initfromtablename" value="" placeholder="'.$langs->trans("TableName").'">';
  3368. print '<input type="submit" class="button smallpaddingimp" name="createtablearray" value="'.dol_escape_htmltag($langs->trans("GenerateCode")).'"'.($dirins ? '' : ' disabled="disabled"').'>';
  3369. print '<br>';
  3370. */
  3371. print '</form>';
  3372. } elseif ($tabobj == 'createproperty') {
  3373. $attributesUnique = array(
  3374. 'proplabel' => $form->textwithpicto($langs->trans("Label"), $langs->trans("YouCanUseTranslationKey")),
  3375. 'propname' => $form->textwithpicto($langs->trans("Code"), $langs->trans("PropertyDesc"), 1, 'help', 'extracss', 0, 3, 'propertyhelp'),
  3376. 'proptype' => $form->textwithpicto($langs->trans("Type"), $langs->trans("TypeOfFieldsHelpIntro").'<br><br>'.$langs->trans("TypeOfFieldsHelp"), 1, 'help', 'extracss', 0, 3, 'typehelp'),
  3377. 'proparrayofkeyval' => $form->textwithpicto($langs->trans("ArrayOfKeyValues"), $langs->trans("ArrayOfKeyValuesDesc")),
  3378. 'propnotnull' => $form->textwithpicto($langs->trans("NotNull"), $langs->trans("NotNullDesc")),
  3379. 'propdefault' => $langs->trans("DefaultValue"),
  3380. 'propindex' => $langs->trans("DatabaseIndex"),
  3381. 'propforeignkey' => $form->textwithpicto($langs->trans("ForeignKey"), $langs->trans("ForeignKeyDesc"), 1, 'help', 'extracss', 0, 3, 'foreignkeyhelp'),
  3382. 'propposition' => $langs->trans("Position"),
  3383. 'propenabled' => $form->textwithpicto($langs->trans("Enabled"), $langs->trans("EnabledDesc"), 1, 'help', 'extracss', 0, 3, 'enabledhelp'),
  3384. 'propvisible' => $form->textwithpicto($langs->trans("Visibility"), $langs->trans("VisibleDesc").'<br><br>'.$langs->trans("ItCanBeAnExpression"), 1, 'help', 'extracss', 0, 3, 'visiblehelp'),
  3385. 'propnoteditable' => $langs->trans("NotEditable"),
  3386. //'propalwayseditable' => $langs->trans("AlwaysEditable"),
  3387. 'propsearchall' => $form->textwithpicto($langs->trans("SearchAll"), $langs->trans("SearchAllDesc")),
  3388. 'propisameasure' => $form->textwithpicto($langs->trans("IsAMeasure"), $langs->trans("IsAMeasureDesc")),
  3389. 'propcss' => $langs->trans("CSSClass"),
  3390. 'propcssview' => $langs->trans("CSSViewClass"),
  3391. 'propcsslist' => $langs->trans("CSSListClass"),
  3392. 'prophelp' => $langs->trans("KeyForTooltip"),
  3393. 'propshowoncombobox' => $langs->trans("ShowOnCombobox"),
  3394. //'propvalidate' => $form->textwithpicto($langs->trans("Validate"), $langs->trans("ValidateModBuilderDesc")),
  3395. 'propcomment' => $langs->trans("Comment"),
  3396. );
  3397. print '<form action="'.$_SERVER["PHP_SELF"].'?tab=objects&module='.urlencode($module).'&tabobj=createproperty&obj='.urlencode(GETPOST('obj')).'" method="POST">';
  3398. print '<input type="hidden" name="token" value="'.newToken().'">';
  3399. print '<input type="hidden" name="action" value="addproperty">';
  3400. print '<input type="hidden" name="tab" value="objects">';
  3401. print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
  3402. print '<input type="hidden" name="obj" value="'.dol_escape_htmltag(GETPOST('obj')).'">';
  3403. print '<table class="border centpercent tableforfieldcreate">'."\n";
  3404. $counter = 0;
  3405. foreach ($attributesUnique as $key => $attribute) {
  3406. if ($counter % 2 === 0) {
  3407. print '<tr>';
  3408. }
  3409. if ($key == 'propname' || $key == 'proplabel') {
  3410. print '<td class="titlefieldcreate fieldrequired">'.$attribute.'</td><td class="valuefieldcreate maxwidth50"><input class="maxwidth200" id="'.$key.'" type="text" name="'.$key.'" value="'.dol_escape_htmltag(GETPOST($key, 'alpha')).'"></td>';
  3411. } elseif ($key == 'proptype') {
  3412. print '<td class="titlefieldcreate fieldrequired">'.$attribute.'</td><td class="valuefieldcreate maxwidth50">';
  3413. print '<input class="maxwidth200" id="'.$key.'" list="datalist'.$key.'" type="text" name="'.$key.'" value="'.dol_escape_htmltag(GETPOST($key, 'alpha')).'">';
  3414. //print '<div id="suggestions"></div>';
  3415. print '<datalist id="datalist'.$key.'">';
  3416. print '<option>varchar(128)</option>';
  3417. print '<option>email</option>';
  3418. print '<option>phone</option>';
  3419. print '<option>ip</option>';
  3420. print '<option>url</option>';
  3421. print '<option>password</option>';
  3422. print '<option>text</option>';
  3423. print '<option>html</option>';
  3424. print '<option>date</option>';
  3425. print '<option>datetime</option>';
  3426. print '<option>integer</option>';
  3427. print '<option>double(28,4)</option>';
  3428. print '<option>real</option>';
  3429. print '<option>integer:ClassName:RelativePath/To/ClassFile.class.php[:1[:FILTER]]</option>';
  3430. // Combo with list of fields
  3431. /*
  3432. if (empty($formadmin)) {
  3433. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
  3434. $formadmin = new FormAdmin($db);
  3435. }
  3436. print $formadmin->selectTypeOfFields($key, GETPOST($key, 'alpha'));
  3437. */
  3438. print '</datalist>';
  3439. print '</td>';
  3440. //} elseif ($key == 'propvalidate') {
  3441. // print '<td class="titlefieldcreate">'.$attribute.'</td><td class="valuefieldcreate maxwidth50"><input type="number" step="1" min="0" max="1" class="text maxwidth100" value="'.dol_escape_htmltag(GETPOST($key, 'alpha')).'"></td>';
  3442. } elseif ($key == 'propvisible') {
  3443. print '<td class="titlefieldcreate">'.$attribute.'</td><td class="valuefieldcreate"><input class="maxwidth200" type="text" name="'.$key.'" value="'.dol_escape_htmltag(GETPOSTISSET($key) ? GETPOST($key, 'alpha') : "1").'"></td>';
  3444. } elseif ($key == 'propenabled') {
  3445. //$default = "isModEnabled('".strtolower($module)."')";
  3446. $default = 1;
  3447. print '<td class="titlefieldcreate">'.$attribute.'</td><td class="valuefieldcreate"><input class="maxwidth200" type="text" name="'.$key.'" value="'.dol_escape_htmltag(GETPOSTISSET($key) ? GETPOST($key, 'alpha') : $default).'"></td>';
  3448. } elseif ($key == 'proparrayofkeyval') {
  3449. print '<td class="titlefieldcreate tdproparrayofkeyval">'.$attribute.'</td><td class="valuefieldcreate"><textarea class="maxwidth200" name="'.$key.'">'.dol_escape_htmltag(GETPOSTISSET($key) ? GETPOST($key, 'alpha') : "").'</textarea></td>';
  3450. } else {
  3451. print '<td class="titlefieldcreate">'.$attribute.'</td><td class="valuefieldcreate"><input class="maxwidth200" type="text" name="'.$key.'" value="'.dol_escape_htmltag(GETPOSTISSET($key) ? GETPOST($key, 'alpha') : '').'"></td>';
  3452. }
  3453. $counter++;
  3454. if ($counter % 2 === 0) {
  3455. print '</tr>';
  3456. }
  3457. }
  3458. if ($counter % 2 !== 0) {
  3459. while ($counter % 2 !== 0) {
  3460. print '<td></td>';
  3461. $counter++;
  3462. }
  3463. print '</tr>';
  3464. }
  3465. print '</table><br>'."\n";
  3466. print '<div class="center">';
  3467. print '<input type="submit" class="button button-save" name="add" value="' . dol_escape_htmltag($langs->trans('Create')) . '">';
  3468. print '<input type="button" class="button button-cancel" name="cancel" value="' . dol_escape_htmltag($langs->trans('Cancel')) . '" onclick="goBack()">';
  3469. print '</div>';
  3470. print '</form>';
  3471. // javascript
  3472. print '<script>
  3473. function goBack() {
  3474. var url = "'.$_SERVER["PHP_SELF"].'?tab=objects&module='.urlencode($module).'";
  3475. window.location.href = url;
  3476. }
  3477. $(document).ready(function() {
  3478. $("#proplabel").on("keyup", function() {
  3479. console.log("key up on label");
  3480. s = cleanString($("#proplabel").val());
  3481. $("#propname").val(s);
  3482. });
  3483. function cleanString( stringtoclean )
  3484. {
  3485. // allow "a-z", "A-Z", "0-9" and "_"
  3486. stringtoclean = stringtoclean.replace(/[^a-z0-9_]+/ig, "");
  3487. stringtoclean = stringtoclean.toLowerCase();
  3488. if (!isNaN(stringtoclean)) {
  3489. return ""
  3490. }
  3491. while ( stringtoclean.length > 1 && !isNaN( stringtoclean.charAt(0)) ){
  3492. stringtoclean = stringtoclean.substr(1)
  3493. }
  3494. if (stringtoclean.length > 28) {
  3495. stringtoclean = stringtoclean.substring(0, 27);
  3496. }
  3497. return stringtoclean;
  3498. }
  3499. });';
  3500. print '</script>';
  3501. } elseif ($tabobj == 'deleteobject') {
  3502. // Delete object tab
  3503. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  3504. print '<input type="hidden" name="token" value="'.newToken().'">';
  3505. print '<input type="hidden" name="action" value="confirm_deleteobject">';
  3506. print '<input type="hidden" name="tab" value="objects">';
  3507. print '<input type="hidden" name="tabobj" value="deleteobject">';
  3508. print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
  3509. print $langs->trans("EnterNameOfObjectToDeleteDesc").'<br><br>';
  3510. print '<input type="text" name="objectname" value="'.dol_escape_htmltag($modulename).'" placeholder="'.dol_escape_htmltag($langs->trans("ObjectKey")).'">';
  3511. print '<input type="submit" class="button smallpaddingimp" name="delete" value="'.dol_escape_htmltag($langs->trans("Delete")).'"'.($dirins ? '' : ' disabled="disabled"').'>';
  3512. print '</form>';
  3513. } else {
  3514. // tabobj = module
  3515. if ($action == 'deleteproperty') {
  3516. $formconfirm = $form->formconfirm(
  3517. $_SERVER["PHP_SELF"].'?propertykey='.urlencode(GETPOST('propertykey', 'alpha')).'&objectname='.urlencode($objectname).'&tab='.urlencode($tab).'&module='.urlencode($module).'&tabobj='.urlencode($tabobj),
  3518. $langs->trans('Delete'),
  3519. $langs->trans('ConfirmDeleteProperty', GETPOST('propertykey', 'alpha')),
  3520. 'confirm_deleteproperty',
  3521. '',
  3522. 0,
  3523. 1
  3524. );
  3525. // Print form confirm
  3526. print $formconfirm;
  3527. }
  3528. if ($action != 'editfile' || empty($file)) {
  3529. try {
  3530. //$pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
  3531. $pathtoclass = strtolower($module).'/class/'.strtolower($tabobj).'.class.php';
  3532. $pathtoapi = strtolower($module).'/class/api_'.strtolower($module).'.class.php';
  3533. $pathtoagenda = strtolower($module).'/'.strtolower($tabobj).'_agenda.php';
  3534. $pathtocard = strtolower($module).'/'.strtolower($tabobj).'_card.php';
  3535. $pathtodocument = strtolower($module).'/'.strtolower($tabobj).'_document.php';
  3536. $pathtolist = strtolower($module).'/'.strtolower($tabobj).'_list.php';
  3537. $pathtonote = strtolower($module).'/'.strtolower($tabobj).'_note.php';
  3538. $pathtocontact = strtolower($module).'/'.strtolower($tabobj).'_contact.php';
  3539. $pathtophpunit = strtolower($module).'/test/phpunit/'.strtolower($tabobj).'Test.php';
  3540. // Try to load object class file
  3541. clearstatcache(true);
  3542. if (function_exists('opcache_invalidate')) {
  3543. opcache_invalidate($dirread.'/'.$pathtoclass, true); // remove the include cache hell !
  3544. }
  3545. if (empty($forceddirread) && empty($dirread)) {
  3546. $result = dol_include_once($pathtoclass);
  3547. $stringofinclude = "dol_include_once(".$pathtoclass.")";
  3548. } else {
  3549. $result = @include_once $dirread.'/'.$pathtoclass;
  3550. $stringofinclude = "@include_once ".$dirread.'/'.$pathtoclass;
  3551. }
  3552. if (class_exists($tabobj)) {
  3553. try {
  3554. $tmpobject = @new $tabobj($db);
  3555. } catch (Exception $e) {
  3556. dol_syslog('Failed to load Constructor of class: '.$e->getMessage(), LOG_WARNING);
  3557. }
  3558. } else {
  3559. print '<span class="warning">'.$langs->trans('Failed to find the class '.$tabobj.' despite the '.$stringofinclude).'</span><br><br>';
  3560. }
  3561. // Define path for sql file
  3562. $pathtosql = strtolower($module).'/sql/llx_'.strtolower($module).'_'.strtolower($tabobj).'-'.strtolower($module).'.sql';
  3563. $result = dol_buildpath($pathtosql);
  3564. if (! dol_is_file($result)) {
  3565. $pathtosql = strtolower($module).'/sql/llx_'.strtolower($module).'_'.strtolower($tabobj).'.sql';
  3566. $result = dol_buildpath($pathtosql);
  3567. if (! dol_is_file($result)) {
  3568. $pathtosql = 'install/mysql/tables/llx_'.strtolower($module).'_'.strtolower($tabobj).'-'.strtolower($module).'.sql';
  3569. $result = dol_buildpath($pathtosql);
  3570. if (! dol_is_file($result)) {
  3571. $pathtosql = 'install/mysql/tables/llx_'.strtolower($module).'-'.strtolower($module).'.sql';
  3572. $result = dol_buildpath($pathtosql);
  3573. if (! dol_is_file($result)) {
  3574. $pathtosql = 'install/mysql/tables/llx_'.strtolower($module).'.sql';
  3575. $pathtosqlextra = 'install/mysql/tables/llx_'.strtolower($module).'_extrafields.sql';
  3576. $result = dol_buildpath($pathtosql);
  3577. } else {
  3578. $pathtosqlextra = 'install/mysql/tables/llx_'.strtolower($module).'_extrafields-'.strtolower($module).'.sql';
  3579. }
  3580. } else {
  3581. $pathtosqlextra = 'install/mysql/tables/llx_'.strtolower($module).'_'.strtolower($tabobj).'_extrafields-'.strtolower($module).'.sql';
  3582. }
  3583. } else {
  3584. $pathtosqlextra = strtolower($module).'/sql/llx_'.strtolower($module).'_'.strtolower($tabobj).'_extrafields.sql';
  3585. }
  3586. } else {
  3587. $pathtosqlextra = strtolower($module).'/sql/llx_'.strtolower($module).'_'.strtolower($tabobj).'_extrafields-'.strtolower($module).'.sql';
  3588. }
  3589. $pathtosqlroot = preg_replace('/\/llx_.*$/', '', $pathtosql);
  3590. $pathtosqlkey = preg_replace('/\.sql$/', '.key.sql', $pathtosql);
  3591. $pathtosqlextrakey = preg_replace('/\.sql$/', '.key.sql', $pathtosqlextra);
  3592. $pathtolib = strtolower($module).'/lib/'.strtolower($module).'.lib.php';
  3593. $pathtoobjlib = strtolower($module).'/lib/'.strtolower($module).'_'.strtolower($tabobj).'.lib.php';
  3594. if (is_object($tmpobject) && property_exists($tmpobject, 'picto')) {
  3595. $pathtopicto = $tmpobject->picto;
  3596. $realpathtopicto = '';
  3597. } else {
  3598. $pathtopicto = strtolower($module).'/img/object_'.strtolower($tabobj).'.png';
  3599. $realpathtopicto = $dirread.'/'.$pathtopicto;
  3600. }
  3601. //var_dump($pathtoclass);
  3602. //var_dump($dirread);
  3603. $realpathtoclass = $dirread.'/'.$pathtoclass;
  3604. $realpathtoapi = $dirread.'/'.$pathtoapi;
  3605. $realpathtoagenda = $dirread.'/'.$pathtoagenda;
  3606. $realpathtocard = $dirread.'/'.$pathtocard;
  3607. $realpathtodocument = $dirread.'/'.$pathtodocument;
  3608. $realpathtolist = $dirread.'/'.$pathtolist;
  3609. $realpathtonote = $dirread.'/'.$pathtonote;
  3610. $realpathtocontact = $dirread.'/'.$pathtocontact;
  3611. $realpathtophpunit = $dirread.'/'.$pathtophpunit;
  3612. $realpathtosql = $dirread.'/'.$pathtosql;
  3613. $realpathtosqlextra = $dirread.'/'.$pathtosqlextra;
  3614. $realpathtosqlkey = $dirread.'/'.$pathtosqlkey;
  3615. $realpathtosqlextrakey = $dirread.'/'.$pathtosqlextrakey;
  3616. $realpathtolib = $dirread.'/'.$pathtolib;
  3617. $realpathtoobjlib = $dirread.'/'.$pathtoobjlib;
  3618. if (empty($realpathtoapi)) { // For compatibility with some old modules
  3619. $pathtoapi = strtolower($module).'/class/api_'.strtolower($module).'s.class.php';
  3620. $realpathtoapi = $dirread.'/'.$pathtoapi;
  3621. }
  3622. $urloflist = dol_buildpath('/'.$pathtolist, 1);
  3623. $urlofcard = dol_buildpath('/'.$pathtocard, 1);
  3624. $objs = array();
  3625. print '<!-- section for object -->';
  3626. print '<div class="fichehalfleft smallxxx">';
  3627. // Main DAO class file
  3628. print '<span class="fa fa-file-o"></span> '.$langs->trans("ClassFile").' : <strong>'.(dol_is_file($realpathtoclass) ? '' : '<strike>').preg_replace('/^'.strtolower($module).'\//', '', $pathtoclass).(dol_is_file($realpathtoclass) ? '' : '</strike>').'</strong>';
  3629. print ' <a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&tabobj='.$tabobj.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&token='.newToken().'&format=php&file='.urlencode($pathtoclass).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
  3630. print '<br>';
  3631. // Image
  3632. if ($realpathtopicto && dol_is_file($realpathtopicto)) {
  3633. print '<span class="fa fa-file-image-o"></span> '.$langs->trans("Image").' : <strong>'.(dol_is_file($realpathtopicto) ? '' : '<strike>').preg_replace('/^'.strtolower($module).'\//', '', $pathtopicto).(dol_is_file($realpathtopicto) ? '' : '</strike>').'</strong>';
  3634. //print ' <a href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&tabobj='.$tabobj.'&module='.$module.($forceddirread?'@'.$dirread:'').'&action=editfile&token='.newToken().'&format=php&file='.urlencode($pathtopicto).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
  3635. print '<br>';
  3636. } elseif (!empty($tmpobject)) {
  3637. print '<span class="fa fa-file-image-o"></span> '.$langs->trans("Image").' : '.img_picto('', $tmpobject->picto, 'class="pictofixedwidth valignmiddle"').$tmpobject->picto;
  3638. print '<br>';
  3639. }
  3640. // API file
  3641. print '<br>';
  3642. print '<span class="fa fa-file-o"></span> '.$langs->trans("ApiClassFile").' : <strong class="wordbreak">'.(dol_is_file($realpathtoapi) ? '' : '<strike><span class="opacitymedium">').preg_replace('/^'.strtolower($module).'\//', '', $pathtoapi).(dol_is_file($realpathtoapi) ? '' : '</span></strike>').'</strong>';
  3643. if (dol_is_file($realpathtoapi)) {
  3644. $file = file_get_contents($realpathtoapi);
  3645. if (preg_match('/var '.$tabobj.'\s+([^\s]*)\s/ims', $file, $objs)) {
  3646. print ' <a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&tabobj='.$tabobj.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&token='.newToken().'&format=php&file='.urlencode($pathtoapi).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
  3647. print ' ';
  3648. print '<a class="reposition editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&tabobj='.$tabobj.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=confirm_removefile&token='.newToken().'&file='.urlencode($pathtoapi).'">'.img_picto($langs->trans("Delete"), 'delete').'</a>';
  3649. print $form->textwithpicto('', $langs->trans("InfoForApiFile"), 1, 'warning');
  3650. print ' &nbsp; ';
  3651. if (!isModEnabled($modulelowercase)) { // If module is not activated
  3652. print '<a href="#" class="classfortooltip" target="apiexplorer" title="'.$langs->trans("ModuleMustBeEnabled", $module).'"><strike>'.$langs->trans("ApiExplorer").'</strike></a>';
  3653. } else {
  3654. print '<a href="'.DOL_URL_ROOT.'/api/index.php/explorer/" target="apiexplorer">'.$langs->trans("ApiExplorer").'</a>';
  3655. }
  3656. } else {
  3657. print '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&tabobj='.$tabobj.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=initapi&token='.newToken().'&format=php&file='.urlencode($pathtoapi).'">'.img_picto('AddAPIsForThisObject', 'generate', 'class="paddingleft"').'</a>';
  3658. }
  3659. } else {
  3660. print '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&tabobj='.$tabobj.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=initapi&token='.newToken().'&format=php&file='.urlencode($pathtoapi).'">'.img_picto('Generate', 'generate', 'class="paddingleft"').'</a>';
  3661. }
  3662. // PHPUnit
  3663. print '<br>';
  3664. print '<span class="fa fa-file-o"></span> '.$langs->trans("TestClassFile").' : <strong class="wordbreak">'.(dol_is_file($realpathtophpunit) ? '' : '<strike><span class="opacitymedium">').preg_replace('/^'.strtolower($module).'\//', '', $pathtophpunit).(dol_is_file($realpathtophpunit) ? '' : '</span></strike>').'</strong>';
  3665. if (dol_is_file($realpathtophpunit)) {
  3666. print ' <a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&tabobj='.$tabobj.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&token='.newToken().'&format=php&file='.urlencode($pathtophpunit).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
  3667. print ' ';
  3668. print '<a class="reposition editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&tabobj='.$tabobj.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=confirm_removefile&token='.newToken().'&file='.urlencode($pathtophpunit).'">'.img_picto($langs->trans("Delete"), 'delete').'</a>';
  3669. } else {
  3670. print '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&tabobj='.$tabobj.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=initphpunit&token='.newToken().'&format=php&file='.urlencode($pathtophpunit).'">'.img_picto('Generate', 'generate', 'class="paddingleft"').'</a>';
  3671. }
  3672. print '<br>';
  3673. print '<br>';
  3674. print '<span class="fa fa-file-o"></span> '.$langs->trans("PageForLib").' : <strong class="wordbreak">'.(dol_is_file($realpathtolib) ? '' : '<strike>').preg_replace('/^'.strtolower($module).'\//', '', $pathtolib).(dol_is_file($realpathtolib) ? '' : '</strike>').'</strong>';
  3675. print ' <a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&tabobj='.$tabobj.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&token='.newToken().'&format=php&file='.urlencode($pathtolib).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
  3676. print '<br>';
  3677. print '<span class="fa fa-file-o"></span> '.$langs->trans("PageForObjLib").' : <strong class="wordbreak">'.(dol_is_file($realpathtoobjlib) ? '' : '<strike>').preg_replace('/^'.strtolower($module).'\//', '', $pathtoobjlib).(dol_is_file($realpathtoobjlib) ? '' : '</strike>').'</strong>';
  3678. print ' <a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&tabobj='.$tabobj.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&token='.newToken().'&format=php&file='.urlencode($pathtoobjlib).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
  3679. print '<br>';
  3680. print '<br>';
  3681. print '<span class="fa fa-file-o"></span> '.$langs->trans("SqlFile").' : <strong class="wordbreak">'.(dol_is_file($realpathtosql) ? '' : '<strike>').preg_replace('/^'.strtolower($module).'\//', '', $pathtosql).(dol_is_file($realpathtosql) ? '' : '</strike>').'</strong>';
  3682. print ' <a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&tabobj='.$tabobj.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&token='.newToken().'&format=sql&file='.urlencode($pathtosql).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
  3683. print ' &nbsp; <a class="reposition" href="'.$_SERVER["PHP_SELF"].'?tab='.urlencode($tab).'&tabobj='.$tabobj.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=droptable&token='.newToken().'">'.$langs->trans("DropTableIfEmpty").'</a>';
  3684. //print ' &nbsp; <a href="'.$_SERVER["PHP_SELF"].'">'.$langs->trans("RunSql").'</a>';
  3685. print '<br>';
  3686. print '<span class="fa fa-file-o"></span> '.$langs->trans("SqlFileKey").' : <strong class="wordbreak">'.(dol_is_file($realpathtosqlkey) ? '' : '<strike>').preg_replace('/^'.strtolower($module).'\//', '', $pathtosqlkey).(dol_is_file($realpathtosqlkey) ? '' : '</strike>').'</strong>';
  3687. print ' <a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&tabobj='.$tabobj.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&token='.newToken().'&format=sql&file='.urlencode($pathtosqlkey).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
  3688. //print ' &nbsp; <a href="'.$_SERVER["PHP_SELF"].'">'.$langs->trans("RunSql").'</a>';
  3689. print '<br>';
  3690. print '<span class="fa fa-file-o"></span> '.$langs->trans("SqlFileExtraFields").' : <strong class="wordbreak">'.(dol_is_file($realpathtosqlextra) ? '' : '<strike><span class="opacitymedium">').preg_replace('/^'.strtolower($module).'\//', '', $pathtosqlextra).(dol_is_file($realpathtosqlextra) && dol_is_file($realpathtosqlextrakey) ? '' : '</span></strike>').'</strong>';
  3691. if (dol_is_file($realpathtosqlextra) && dol_is_file($realpathtosqlextrakey)) {
  3692. print ' <a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&tabobj='.$tabobj.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&token='.newToken().'&file='.urlencode($pathtosqlextra).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
  3693. print ' ';
  3694. print '<a class="reposition editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&tabobj='.$tabobj.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=confirm_removefile&token='.newToken().'&file='.urlencode($pathtosqlextra).'">'.img_picto($langs->trans("Delete"), 'delete').'</a>';
  3695. print ' &nbsp; ';
  3696. print '<a class="reposition editfielda" href="'.$_SERVER["PHP_SELF"].'?tab='.urlencode($tab).'&tabobj='.$tabobj.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=droptableextrafields&token='.newToken().'">'.$langs->trans("DropTableIfEmpty").'</a>';
  3697. } else {
  3698. print '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&tabobj='.$tabobj.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=initsqlextrafields&token='.newToken().'&format=sql&file='.urlencode($pathtosqlextra).'">'.img_picto('Generate', 'generate', 'class="paddingleft"').'</a>';
  3699. }
  3700. //print ' &nbsp; <a href="'.$_SERVER["PHP_SELF"].'">'.$langs->trans("RunSql").'</a>';
  3701. print '<br>';
  3702. print '<span class="fa fa-file-o"></span> '.$langs->trans("SqlFileKeyExtraFields").' : <strong class="wordbreak">'.(dol_is_file($realpathtosqlextrakey) ? '' : '<strike><span class="opacitymedium">').preg_replace('/^'.strtolower($module).'\//', '', $pathtosqlextrakey).(dol_is_file($realpathtosqlextra) && dol_is_file($realpathtosqlextrakey) ? '' : '</span></strike>').'</strong>';
  3703. if (dol_is_file($realpathtosqlextra) && dol_is_file($realpathtosqlextrakey)) {
  3704. print ' <a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&tabobj='.$tabobj.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&token='.newToken().'&format=sql&file='.urlencode($pathtosqlextrakey).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
  3705. print ' ';
  3706. print '<a class="reposition editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&tabobj='.$tabobj.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=confirm_removefile&token='.newToken().'&file='.urlencode($pathtosqlextrakey).'">'.img_picto($langs->trans("Delete"), 'delete').'</a>';
  3707. } else {
  3708. print '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&tabobj='.$tabobj.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=initsqlextrafields&token='.newToken().'&format=sql&file='.urlencode($pathtosqlextra).'">'.img_picto('Generate', 'generate', 'class="paddingleft"').'</a>';
  3709. }
  3710. print '<br>';
  3711. print '</div>';
  3712. print '<div class="fichehalfleft smallxxxx">';
  3713. print '<span class="fa fa-file-o"></span> '.$langs->trans("PageForList").' : <strong class="wordbreak"><a href="'.$urloflist.'" target="_test">'.(dol_is_file($realpathtolist) ? '' : '<strike><span class="opacitymedium">').preg_replace('/^'.strtolower($module).'\//', '', $pathtolist).(dol_is_file($realpathtolist) ? '' : '</span></strike>').'</a></strong>';
  3714. print ' <a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&tabobj='.$tabobj.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&token='.newToken().'&format=php&file='.urlencode($pathtolist).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
  3715. print '<br>';
  3716. print '<span class="fa fa-file-o"></span> '.$langs->trans("PageForCreateEditView").' : <strong class="wordbreak"><a href="'.$urlofcard.'?action=create" target="_test">'.(dol_is_file($realpathtocard) ? '' : '<strike>').preg_replace('/^'.strtolower($module).'\//', '', $pathtocard).(dol_is_file($realpathtocard) ? '' : '</strike>').'?action=create</a></strong>';
  3717. print ' <a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&tabobj='.$tabobj.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&token='.newToken().'&format=php&file='.urlencode($pathtocard).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
  3718. print '<br>';
  3719. // Page contact
  3720. print '<span class="fa fa-file-o"></span> '.$langs->trans("PageForContactTab").' : <strong class="wordbreak">'.(dol_is_file($realpathtocontact) ? '' : '<strike><span class="opacitymedium">').preg_replace('/^'.strtolower($module).'\//', '', $pathtocontact).(dol_is_file($realpathtocontact) ? '' : '</span></strike>').'</strong>';
  3721. print ' <a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&tabobj='.$tabobj.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&token='.newToken().'&format=php&file='.urlencode($pathtocontact).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
  3722. if (dol_is_file($realpathtocontact)) {
  3723. print ' ';
  3724. print '<a class="reposition editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&tabobj='.$tabobj.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=confirm_removefile&token='.newToken().'&file='.urlencode($pathtocontact).'">'.img_picto($langs->trans("Delete"), 'delete').'</a>';
  3725. } else {
  3726. print '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&tabobj='.$tabobj.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=initpagecontact&token='.newToken().'&format=php&file='.urlencode($pathtocontact).'">'.img_picto('Generate', 'generate', 'class="paddingleft"').'</a>';
  3727. }
  3728. print '<br>';
  3729. // Page document
  3730. print '<span class="fa fa-file-o"></span> '.$langs->trans("PageForDocumentTab").' : <strong class="wordbreak">'.(dol_is_file($realpathtodocument) ? '' : '<strike><span class="opacitymedium">').preg_replace('/^'.strtolower($module).'\//', '', $pathtodocument).(dol_is_file($realpathtodocument) ? '' : '</span></strike>').'</strong>';
  3731. print ' <a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&tabobj='.$tabobj.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&token='.newToken().'&format=php&file='.urlencode($pathtodocument).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
  3732. if (dol_is_file($realpathtodocument)) {
  3733. print ' ';
  3734. print '<a class="reposition editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&tabobj='.$tabobj.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=confirm_removefile&token='.newToken().'&file='.urlencode($pathtodocument).'">'.img_picto($langs->trans("Delete"), 'delete').'</a>';
  3735. } else {
  3736. print '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&tabobj='.$tabobj.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=initpagedocument&token='.newToken().'&format=php&file='.urlencode($pathtocontact).'">'.img_picto('Generate', 'generate', 'class="paddingleft"').'</a>';
  3737. }
  3738. print '<br>';
  3739. // Page notes
  3740. print '<span class="fa fa-file-o"></span> '.$langs->trans("PageForNoteTab").' : <strong class="wordbreak">'.(dol_is_file($realpathtonote) ? '' : '<strike><span class="opacitymedium">').preg_replace('/^'.strtolower($module).'\//', '', $pathtonote).(dol_is_file($realpathtonote) ? '' : '</span></strike>').'</strong>';
  3741. print ' <a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&tabobj='.$tabobj.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&token='.newToken().'&format=php&file='.urlencode($pathtonote).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
  3742. if (dol_is_file($realpathtonote)) {
  3743. print ' ';
  3744. print '<a class="reposition editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&tabobj='.$tabobj.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=confirm_removefile&token='.newToken().'&file='.urlencode($pathtonote).'">'.img_picto($langs->trans("Delete"), 'delete').'</a>';
  3745. } else {
  3746. print '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&tabobj='.$tabobj.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=initpagenote&token='.newToken().'&format=php&file='.urlencode($pathtocontact).'">'.img_picto('Generate', 'generate', 'class="paddingleft"').'</a>';
  3747. }
  3748. print '<br>';
  3749. // Page agenda
  3750. print '<span class="fa fa-file-o"></span> '.$langs->trans("PageForAgendaTab").' : <strong class="wordbreak">'.(dol_is_file($realpathtoagenda) ? '' : '<strike><span class="opacitymedium">').preg_replace('/^'.strtolower($module).'\//', '', $pathtoagenda).(dol_is_file($realpathtoagenda) ? '' : '</span></strike>').'</strong>';
  3751. print ' <a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&tabobj='.$tabobj.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&format=php&token='.newToken().'&file='.urlencode($pathtoagenda).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
  3752. if (dol_is_file($realpathtoagenda)) {
  3753. print ' ';
  3754. print '<a class="reposition editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&tabobj='.$tabobj.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=confirm_removefile&token='.newToken().'&file='.urlencode($pathtoagenda).'">'.img_picto($langs->trans("Delete"), 'delete').'</a>';
  3755. } else {
  3756. print '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&tabobj='.$tabobj.'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=initpageagenda&token='.newToken().'&format=php&file='.urlencode($pathtocontact).'">'.img_picto('Generate', 'generate', 'class="paddingleft"').'</a>';
  3757. }
  3758. print '<br>';
  3759. print '<br>';
  3760. print '</div>';
  3761. print '<br><br><br>';
  3762. if (!empty($tmpobject)) {
  3763. $reflector = new ReflectionClass($tabobj);
  3764. $reflectorproperties = $reflector->getProperties(); // Can also use get_object_vars
  3765. $reflectorpropdefault = $reflector->getDefaultProperties(); // Can also use get_object_vars
  3766. //$propstat = $reflector->getStaticProperties();
  3767. //var_dump($reflectorpropdefault);
  3768. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  3769. print '<input type="hidden" name="token" value="'.newToken().'">';
  3770. print '<input type="hidden" name="action" value="addproperty">';
  3771. print '<input type="hidden" name="tab" value="objects">';
  3772. print '<input type="hidden" name="page_y" value="">';
  3773. print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module.($forceddirread ? '@'.$dirread : '')).'">';
  3774. print '<input type="hidden" name="tabobj" value="'.dol_escape_htmltag($tabobj).'">';
  3775. print '<input class="button smallpaddingimp" type="submit" name="regenerateclasssql" value="'.$langs->trans("RegenerateClassAndSql").'">';
  3776. print '<br><br>';
  3777. $mod = strtolower($module);
  3778. $obj = strtolower($tabobj);
  3779. $newproperty = dolGetButtonTitle($langs->trans('NewProperty'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/modulebuilder/index.php?tab=objects&module='.urlencode($module).'&tabobj=createproperty&obj='.urlencode($tabobj));
  3780. print_barre_liste($langs->trans("ObjectProperties"), 0, $_SERVER["PHP_SELF"], '', '', '', '', '', 0, '', 0, $newproperty, '', '', 0, 0, 1);
  3781. //var_dump($reflectorpropdefault);exit;
  3782. print '<!-- Table with properties of object -->'."\n";
  3783. print '<div class="div-table-responsive">';
  3784. print '<table class="noborder small">';
  3785. print '<tr class="liste_titre">';
  3786. print '<th class="tdsticky tdstickygray">';
  3787. $htmltext = $langs->trans("PropertyDesc").'<br><br><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>';
  3788. print $form->textwithpicto($langs->trans("Code"), $htmltext, 1, 'help', 'extracss', 0, 3, 'propertyhelp');
  3789. print '</th>';
  3790. print '<th>';
  3791. print $form->textwithpicto($langs->trans("Label"), $langs->trans("YouCanUseTranslationKey"));
  3792. print '</th>';
  3793. print '<th>'.$form->textwithpicto($langs->trans("Type"), $langs->trans("TypeOfFieldsHelpIntro").'<br><br>'.$langs->trans("TypeOfFieldsHelp"), 1, 'help', 'extracss', 0, 3, 'typehelp').'</th>';
  3794. print '<th>'.$form->textwithpicto($langs->trans("ArrayOfKeyValues"), $langs->trans("ArrayOfKeyValuesDesc")).'</th>';
  3795. print '<th class="center">'.$form->textwithpicto($langs->trans("NotNull"), $langs->trans("NotNullDesc")).'</th>';
  3796. print '<th class="center">'.$langs->trans("DefaultValue").'</th>';
  3797. print '<th class="center">'.$langs->trans("DatabaseIndex").'</th>';
  3798. print '<th class="center">'.$form->textwithpicto($langs->trans("ForeignKey"), $langs->trans("ForeignKeyDesc"), 1, 'help', 'extracss', 0, 3, 'foreignkeyhelp').'</th>';
  3799. print '<th class="right">'.$langs->trans("Position").'</th>';
  3800. print '<th class="center">'.$form->textwithpicto($langs->trans("Enabled"), $langs->trans("EnabledDesc"), 1, 'help', 'extracss', 0, 3, 'enabledhelp').'</th>';
  3801. print '<th class="center">'.$form->textwithpicto($langs->trans("Visibility"), $langs->trans("VisibleDesc").'<br><br>'.$langs->trans("ItCanBeAnExpression"), 1, 'help', 'extracss', 0, 3, 'visiblehelp').'</th>';
  3802. print '<th class="center">'.$langs->trans("NotEditable").'</th>';
  3803. //print '<th class="center">'.$langs->trans("AlwaysEditable").'</th>';
  3804. print '<th class="center">'.$form->textwithpicto($langs->trans("SearchAll"), $langs->trans("SearchAllDesc")).'</th>';
  3805. print '<th class="center">'.$form->textwithpicto($langs->trans("IsAMeasure"), $langs->trans("IsAMeasureDesc")).'</th>';
  3806. print '<th class="center">'.$langs->trans("CSSClass").'</th>';
  3807. print '<th class="center">'.$langs->trans("CSSViewClass").'</th>';
  3808. print '<th class="center">'.$langs->trans("CSSListClass").'</th>';
  3809. print '<th>'.$langs->trans("KeyForTooltip").'</th>';
  3810. print '<th class="center">'.$langs->trans("ShowOnCombobox").'</th>';
  3811. //print '<th class="center">'.$langs->trans("Disabled").'</th>';
  3812. print '<th>'.$form->textwithpicto($langs->trans("Validate"), $langs->trans("ValidateModBuilderDesc")).'</th>';
  3813. print '<th>'.$langs->trans("Comment").'</th>';
  3814. print '<th class="tdstickyright tdstickyghostwhite"></th>';
  3815. print '</tr>';
  3816. // We must use $reflectorpropdefault['fields'] to get list of fields because $tmpobject->fields may have been
  3817. // modified during the constructor and we want value into head of class before constructor is called.
  3818. //$properties = dol_sort_array($tmpobject->fields, 'position');
  3819. $properties = dol_sort_array($reflectorpropdefault['fields'], 'position');
  3820. if (!empty($properties)) {
  3821. // List of existing properties
  3822. foreach ($properties as $propkey => $propval) {
  3823. /* If from Reflection
  3824. if ($propval->class == $tabobj)
  3825. {
  3826. $propname=$propval->getName();
  3827. $comment=$propval->getDocComment();
  3828. $type=gettype($tmpobject->$propname);
  3829. $default=$propdefault[$propname];
  3830. // Discard generic properties
  3831. if (in_array($propname, array('element', 'childtables', 'table_element', 'table_element_line', 'class_element_line', 'ismultientitymanaged'))) continue;
  3832. // Keep or not lines
  3833. if (in_array($propname, array('fk_element', 'lines'))) continue;
  3834. }*/
  3835. $propname = $propkey;
  3836. $proplabel = $propval['label'];
  3837. $proptype = $propval['type'];
  3838. $proparrayofkeyval = !empty($propval['arrayofkeyval']) ? $propval['arrayofkeyval'] : '';
  3839. $propnotnull = !empty($propval['notnull']) ? $propval['notnull'] : '0';
  3840. $propdefault = !empty($propval['default']) ? $propval['default'] : '';
  3841. $propindex = !empty($propval['index']) ? $propval['index'] : '';
  3842. $propforeignkey = !empty($propval['foreignkey']) ? $propval['foreignkey'] : '';
  3843. $propposition = $propval['position'];
  3844. $propenabled = $propval['enabled'];
  3845. $propvisible = $propval['visible'];
  3846. $propnoteditable = !empty($propval['noteditable']) ? $propval['noteditable'] : 0;
  3847. //$propalwayseditable = !empty($propval['alwayseditable'])?$propval['alwayseditable']:0;
  3848. $propsearchall = !empty($propval['searchall']) ? $propval['searchall'] : 0;
  3849. $propisameasure = !empty($propval['isameasure']) ? $propval['isameasure'] : 0;
  3850. $propcss = !empty($propval['css']) ? $propval['css'] : '';
  3851. $propcssview = !empty($propval['cssview']) ? $propval['cssview'] : '';
  3852. $propcsslist = !empty($propval['csslist']) ? $propval['csslist'] : '';
  3853. $prophelp = !empty($propval['help']) ? $propval['help'] : '';
  3854. $propshowoncombobox = !empty($propval['showoncombobox']) ? $propval['showoncombobox'] : 0;
  3855. //$propdisabled=$propval['disabled'];
  3856. $propvalidate = !empty($propval['validate']) ? $propval['validate'] : 0;
  3857. $propcomment = !empty($propval['comment']) ? $propval['comment'] : '';
  3858. print '<!-- line for object property -->'."\n";
  3859. print '<tr class="oddeven">';
  3860. print '<td class="tdsticky tdstickygray">';
  3861. print dol_escape_htmltag($propname);
  3862. print '</td>';
  3863. if ($action == 'editproperty' && $propname == $propertykey) {
  3864. print '<td>';
  3865. print '<input type="hidden" name="propname" value="'.dol_escape_htmltag($propname).'">';
  3866. print '<input name="proplabel" class="maxwidth125" value="'.dol_escape_htmltag($proplabel).'">';
  3867. print '</td>';
  3868. print '<td class="tdoverflowmax150">';
  3869. print '<input name="proptype" class="maxwidth125" value="'.dol_escape_htmltag($proptype).'"></input>';
  3870. print '</td>';
  3871. print '<td class="tdoverflowmax200">';
  3872. print '<textarea name="proparrayofkeyval">';
  3873. if (isset($proparrayofkeyval)) {
  3874. if (is_array($proparrayofkeyval) || $proparrayofkeyval != '') {
  3875. print dol_escape_htmltag(json_encode($proparrayofkeyval, JSON_UNESCAPED_UNICODE));
  3876. }
  3877. }
  3878. print '</textarea>';
  3879. print '</td>';
  3880. print '<td>';
  3881. print '<input class="center width50" name="propnotnull" value="'.dol_escape_htmltag($propnotnull).'">';
  3882. print '</td>';
  3883. print '<td>';
  3884. print '<input class="maxwidth50" name="propdefault" value="'.dol_escape_htmltag($propdefault).'">';
  3885. print '</td>';
  3886. print '<td class="center">';
  3887. print '<input class="center maxwidth50" name="propindex" value="'.dol_escape_htmltag($propindex).'">';
  3888. print '</td>';
  3889. print '<td>';
  3890. print '<input class="center maxwidth100" name="propforeignkey" value="'.dol_escape_htmltag($propforeignkey).'">';
  3891. print '</td>';
  3892. print '<td>';
  3893. print '<input class="right width50" name="propposition" value="'.dol_escape_htmltag($propposition).'">';
  3894. print '</td>';
  3895. print '<td>';
  3896. print '<input class="center width75" name="propenabled" value="'.dol_escape_htmltag($propenabled).'">';
  3897. print '</td>';
  3898. print '<td>';
  3899. print '<input class="center width75" name="propvisible" value="'.dol_escape_htmltag($propvisible).'">';
  3900. print '</td>';
  3901. print '<td>';
  3902. print '<input class="center width50" name="propnoteditable" size="2" value="'.dol_escape_htmltag($propnoteditable).'">';
  3903. print '</td>';
  3904. /*print '<td>';
  3905. print '<input class="center" name="propalwayseditable" size="2" value="'.dol_escape_htmltag($propalwayseditable).'">';
  3906. print '</td>';*/
  3907. print '<td>';
  3908. print '<input class="center width50" name="propsearchall" value="'.dol_escape_htmltag($propsearchall).'">';
  3909. print '</td>';
  3910. print '<td>';
  3911. print '<input class="center width50" name="propisameasure" value="'.dol_escape_htmltag($propisameasure).'">';
  3912. print '</td>';
  3913. print '<td>';
  3914. print '<input class="center maxwidth50" name="propcss" value="'.dol_escape_htmltag($propcss).'">';
  3915. print '</td>';
  3916. print '<td>';
  3917. print '<input class="center maxwidth50" name="propcssview" value="'.dol_escape_htmltag($propcssview).'">';
  3918. print '</td>';
  3919. print '<td>';
  3920. print '<input class="center maxwidth50" name="propcsslist" value="'.dol_escape_htmltag($propcsslist).'">';
  3921. print '</td>';
  3922. print '<td>';
  3923. print '<input class="maxwidth100" name="prophelp" value="'.dol_escape_htmltag($prophelp).'">';
  3924. print '</td>';
  3925. print '<td>';
  3926. print '<input class="center maxwidth50" name="propshowoncombobox" value="'.dol_escape_htmltag($propshowoncombobox).'">';
  3927. print '</td>';
  3928. print '<td>';
  3929. print '<input type="number" step="1" min="0" max="1" class="text maxwidth100" name="propvalidate" value="'.dol_escape_htmltag($propvalidate).'">';
  3930. print '</td>';
  3931. print '<td>';
  3932. print '<input class="maxwidth100" name="propcomment" value="'.dol_escape_htmltag($propcomment).'">';
  3933. print '</td>';
  3934. print '<td class="center minwidth75 tdstickyright tdstickyghostwhite">';
  3935. print '<input class="reposition button smallpaddingimp" type="submit" name="edit" value="'.$langs->trans("Save").'">';
  3936. print '<input class="reposition button button-cancel smallpaddingimp" type="submit" name="cancel" value="'.$langs->trans("Cancel").'">';
  3937. print '</td>';
  3938. } else {
  3939. print '<td class="tdoverflowmax200" title="'.dol_escape_htmltag($proplabel).'">';
  3940. print dol_escape_htmltag($proplabel);
  3941. print '</td>';
  3942. print '<td class="tdoverflowmax200">';
  3943. $pictoType = '';
  3944. $matches = array();
  3945. if (preg_match('/^varchar/', $proptype, $matches)) {
  3946. $pictoType = 'varchar';
  3947. } elseif (preg_match('/^integer:/', $proptype, $matches)) {
  3948. $pictoType = 'link';
  3949. } elseif (strpos($proptype, 'integer') === 0) {
  3950. $pictoType = substr($proptype, 0, 3);
  3951. } elseif (strpos($proptype, 'timestamp') === 0) {
  3952. $pictoType = 'datetime';
  3953. } elseif (strpos($proptype, 'real') === 0) {
  3954. $pictoType = 'double';
  3955. }
  3956. print(!empty($pictoType) ? getPictoForType($pictoType) : getPictoForType($proptype)).'<span title="'.dol_escape_htmltag($proptype).'">'.dol_escape_htmltag($proptype).'</span>';
  3957. print '</td>';
  3958. print '<td class="tdoverflowmax200">';
  3959. if ($proparrayofkeyval) {
  3960. print '<span title="'.dol_escape_htmltag(json_encode($proparrayofkeyval, JSON_UNESCAPED_UNICODE)).'">';
  3961. print dol_escape_htmltag(json_encode($proparrayofkeyval, JSON_UNESCAPED_UNICODE));
  3962. print '</span>';
  3963. }
  3964. print '</td>';
  3965. print '<td class="center">';
  3966. print dol_escape_htmltag($propnotnull);
  3967. print '</td>';
  3968. print '<td>';
  3969. print dol_escape_htmltag($propdefault);
  3970. print '</td>';
  3971. print '<td class="center">';
  3972. print $propindex ? '1' : '';
  3973. print '</td>';
  3974. print '<td class="center">';
  3975. print $propforeignkey ? dol_escape_htmltag($propforeignkey) : '';
  3976. print '</td>';
  3977. print '<td class="right">';
  3978. print dol_escape_htmltag($propposition);
  3979. print '</td>';
  3980. print '<td class="center tdoverflowmax100" title="'.($propnoteditable ? dol_escape_htmltag($propnoteditable) : '').'">';
  3981. print $propenabled ? dol_escape_htmltag($propenabled) : '';
  3982. print '</td>';
  3983. // Visibility
  3984. print '<td class="center tdoverflowmax100" title="'.($propvisible ? dol_escape_htmltag($propvisible) : '0').'">';
  3985. print $propvisible ? dol_escape_htmltag($propvisible) : '0';
  3986. print '</td>';
  3987. // Readonly
  3988. print '<td class="center tdoverflowmax100" title="'.($propnoteditable ? dol_escape_htmltag($propnoteditable) : '').'">';
  3989. print $propnoteditable ? dol_escape_htmltag($propnoteditable) : '';
  3990. print '</td>';
  3991. /*print '<td class="center">';
  3992. print $propalwayseditable ? dol_escape_htmltag($propalwayseditable) : '';
  3993. print '</td>';*/
  3994. print '<td class="center">';
  3995. print $propsearchall ? '1' : '';
  3996. print '</td>';
  3997. print '<td class="center">';
  3998. print $propisameasure ? dol_escape_htmltag($propisameasure) : '';
  3999. print '</td>';
  4000. print '<td class="center tdoverflowmax100" title="'.($propcss ? dol_escape_htmltag($propcss) : '').'">';
  4001. print $propcss ? dol_escape_htmltag($propcss) : '';
  4002. print '</td>';
  4003. print '<td class="center tdoverflowmax100" title="'.($propcssview ? dol_escape_htmltag($propcssview) : '').'">';
  4004. print $propcssview ? dol_escape_htmltag($propcssview) : '';
  4005. print '</td>';
  4006. print '<td class="center tdoverflowmax100" title="'.($propcsslist ? dol_escape_htmltag($propcsslist) : '').'">';
  4007. print $propcsslist ? dol_escape_htmltag($propcsslist) : '';
  4008. print '</td>';
  4009. // Key for tooltop
  4010. print '<td class="tdoverflowmax150" title="'.($prophelp ? dol_escape_htmltag($prophelp) : '').'">';
  4011. print $prophelp ? dol_escape_htmltag($prophelp) : '';
  4012. print '</td>';
  4013. print '<td class="center">';
  4014. print $propshowoncombobox ? dol_escape_htmltag($propshowoncombobox) : '';
  4015. print '</td>';
  4016. /*print '<td class="center">';
  4017. print $propdisabled?$propdisabled:'';
  4018. print '</td>';*/
  4019. print '<td class="center">';
  4020. print $propvalidate ? dol_escape_htmltag($propvalidate) : '';
  4021. print '</td>';
  4022. print '<td class="tdoverflowmax200">';
  4023. print '<span title="'.dol_escape_htmltag($propcomment).'">';
  4024. print dol_escape_htmltag($propcomment);
  4025. print '</span>';
  4026. print '</td>';
  4027. print '<td class="center minwidth75 tdstickyright tdstickyghostwhite">';
  4028. if ($propname != 'rowid') {
  4029. 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>';
  4030. print '<a class="reposition 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>';
  4031. }
  4032. print '</td>';
  4033. }
  4034. print '</tr>';
  4035. }
  4036. } else {
  4037. if ($tab == 'specifications') {
  4038. if ($action != 'editfile' || empty($file)) {
  4039. print '<span class="opacitymedium">'.$langs->trans("SpecDefDesc").'</span><br>';
  4040. print '<br>';
  4041. $specs = dol_dir_list(dol_buildpath($modulelowercase.'/doc', 0), 'files', 1, '(\.md|\.asciidoc)$', array('\/temp\/'));
  4042. foreach ($specs as $spec) {
  4043. $pathtofile = $modulelowercase.'/doc/'.$spec['relativename'];
  4044. $format = 'asciidoc';
  4045. if (preg_match('/\.md$/i', $spec['name'])) {
  4046. $format = 'markdown';
  4047. }
  4048. print '<span class="fa fa-file-o"></span> '.$langs->trans("SpecificationFile").' : <strong class="wordbreak">'.$pathtofile.'</strong>';
  4049. print ' <a href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&token='.newToken().'&format='.$format.'&file='.urlencode($pathtofile).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
  4050. print '<br>';
  4051. }
  4052. } else {
  4053. // Use MD or asciidoc
  4054. //print $langs->trans("UseAsciiDocFormat").'<br>';
  4055. $fullpathoffile = dol_buildpath($file, 0);
  4056. $content = file_get_contents($fullpathoffile);
  4057. // New module
  4058. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  4059. print '<input type="hidden" name="token" value="'.newToken().'">';
  4060. print '<input type="hidden" name="action" value="savefile">';
  4061. print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
  4062. print '<input type="hidden" name="tab" value="'.$tab.'">';
  4063. print '<input type="hidden" name="module" value="'.$module.'">';
  4064. $doleditor = new DolEditor('editfilecontent', $content, '', '300', 'Full', 'In', true, false, 'ace', 0, '99%');
  4065. print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ? GETPOST('format', 'aZ09') : 'html'));
  4066. print '<br>';
  4067. print '<center>';
  4068. print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
  4069. print ' &nbsp; ';
  4070. print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
  4071. print '</center>';
  4072. print '</form>';
  4073. }
  4074. }
  4075. 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>';
  4076. }
  4077. print '</table>';
  4078. print '</div>';
  4079. print '</form>';
  4080. } else {
  4081. print '<span class="warning">'.$langs->trans('Failed to init the object with the new '.$tabobj.'($db)').'</warning>';
  4082. }
  4083. } catch (Exception $e) {
  4084. print $e->getMessage();
  4085. }
  4086. } else {
  4087. if (empty($forceddirread)) {
  4088. $fullpathoffile = dol_buildpath($file, 0);
  4089. } else {
  4090. $fullpathoffile = $dirread.'/'.$file;
  4091. }
  4092. $content = file_get_contents($fullpathoffile);
  4093. // New module
  4094. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  4095. print '<input type="hidden" name="token" value="'.newToken().'">';
  4096. print '<input type="hidden" name="action" value="savefile">';
  4097. print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
  4098. print '<input type="hidden" name="tab" value="'.$tab.'">';
  4099. print '<input type="hidden" name="tabobj" value="'.dol_escape_htmltag($tabobj).'">';
  4100. print '<input type="hidden" name="module" value="'.$module.($forceddirread ? '@'.$dirread : '').'">';
  4101. $doleditor = new DolEditor('editfilecontent', $content, '', '300', 'Full', 'In', true, false, 'ace', 0, '99%');
  4102. print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ? GETPOST('format', 'aZ09') : 'html'));
  4103. print '<br>';
  4104. print '<center>';
  4105. print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
  4106. print ' &nbsp; ';
  4107. print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
  4108. print '</center>';
  4109. print '</form>';
  4110. }
  4111. }
  4112. print dol_get_fiche_end(); // Level 3
  4113. }
  4114. if ($tab == 'dictionaries') {
  4115. print '<!-- tab=dictionaries -->'."\n";
  4116. $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
  4117. $dicts = $moduleobj->dictionaries;
  4118. if ($action == 'deletedict') {
  4119. $formconfirm = $form->formconfirm(
  4120. $_SERVER["PHP_SELF"].'?dictionnarykey='.urlencode(GETPOST('dictionnarykey', 'int')).'&tab='.urlencode($tab).'&module='.urlencode($module),
  4121. $langs->trans('Delete'),
  4122. $langs->trans('Confirm Delete Dictionnary', GETPOST('dictionnarykey', 'alpha')),
  4123. 'confirm_deletedictionary',
  4124. '',
  4125. 0,
  4126. 1
  4127. );
  4128. print $formconfirm;
  4129. }
  4130. if ($action != 'editfile' || empty($file)) {
  4131. print '<span class="opacitymedium">';
  4132. $htmlhelp = $langs->trans("DictionariesDefDescTooltip", '{s1}');
  4133. $htmlhelp = str_replace('{s1}', '<a target="adminbis" class="nofocusvisible" href="'.DOL_URL_ROOT.'/admin/dict.php">'.$langs->trans('Setup').' - '.$langs->trans('Dictionaries').'</a>', $htmlhelp);
  4134. print $form->textwithpicto($langs->trans("DictionariesDefDesc"), $htmlhelp, 1, 'help', '', 0, 2, 'helpondesc').'<br>';
  4135. print '</span>';
  4136. print '<br>';
  4137. print '<span class="fa fa-file-o"></span> '.$langs->trans("DescriptorFile").' : <strong class="wordbreak">'.$pathtofile.'</strong>';
  4138. print ' <a class="editfielda paddingleft paddingright" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&token='.newToken().'&format=php&file='.urlencode($pathtofile).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
  4139. print '<br>';
  4140. if (is_array($dicts) && !empty($dicts)) {
  4141. print '<span class="fa fa-file-o"></span> '.$langs->trans("LanguageFile").' :</span> ';
  4142. print '<strong class="wordbreak">'.$dicts['langs'].'</strong>';
  4143. print '<br>';
  4144. }
  4145. print '<!-- tab=objects -->'."\n";
  4146. $head3 = array();
  4147. $h = 0;
  4148. // Dir for module
  4149. //$dir = $dirread.'/'.$modulelowercase.'/class';
  4150. $head3[$h][0] = $_SERVER["PHP_SELF"].'?tab=dictionaries&module='.$module.($forceddirread ? '@'.$dirread : '').'&tabdic=newdictionary';
  4151. $head3[$h][1] = '<span class="valignmiddle text-plus-circle">'.$langs->trans("NewDictionary").'</span><span class="fa fa-plus-circle valignmiddle paddingleft"></span>';
  4152. $head3[$h][2] = 'newdictionary';
  4153. $h++;
  4154. // Scan for object class files
  4155. //$listofobject = dol_dir_list($dir, 'files', 0, '\.class\.php$');
  4156. $firstdicname = '';
  4157. // if (!empty($dicts['tabname'])) {
  4158. // foreach ($dicts['tabname'] as $key => $dic) {
  4159. // $dicname = $dic;
  4160. // $diclabel = $dicts['tablib'][$key];
  4161. // if (empty($firstdicname)) {
  4162. // $firstdicname = $dicname;
  4163. // }
  4164. // $head3[$h][0] = $_SERVER["PHP_SELF"].'?tab=dictionaries&module='.$module.($forceddirread ? '@'.$dirread : '').'&tabdic='.$dicname;
  4165. // $head3[$h][1] = $diclabel;
  4166. // $head3[$h][2] = $dicname;
  4167. // $h++;
  4168. // }
  4169. // }
  4170. // if ($h > 1) {
  4171. // $head3[$h][0] = $_SERVER["PHP_SELF"].'?tab=dictionaries&module='.$module.($forceddirread ? '@'.$dirread : '').'&tabdic=deletedictionary';
  4172. // $head3[$h][1] = $langs->trans("DangerZone");
  4173. // $head3[$h][2] = 'deletedictionary';
  4174. // $h++;
  4175. // }
  4176. // 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.
  4177. // if ($tabdic == 'newdicifnodic') {
  4178. // if ($firstdicname) {
  4179. // $tabdic = $firstdicname;
  4180. // } else {
  4181. // $tabdic = 'newdictionary';
  4182. // }
  4183. // }
  4184. //print dol_get_fiche_head($head3, $tabdic, '', -1, ''); // Level 3
  4185. $newdict = dolGetButtonTitle($langs->trans('NewDictionary'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/modulebuilder/index.php?tab=dictionaries&module='.urlencode($module).'&tabdic=newdictionary');
  4186. print_barre_liste($langs->trans("ListOfDictionariesEntries"), '', $_SERVER["PHP_SELF"], '', '', '', '', '', '', '', 0, $newdict, '', '', 0, 0, 1);
  4187. if ($tabdic != 'newdictionary') {
  4188. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  4189. print '<input type="hidden" name="token" value="'.newToken().'">';
  4190. print '<input type="hidden" name="action" value="addDictionary">';
  4191. print '<input type="hidden" name="tab" value="dictionaries">';
  4192. print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
  4193. print '<input type="hidden" name="tabdic" value="'.dol_escape_htmltag($tabdic).'">';
  4194. print '<div class="div-table-responsive">';
  4195. print '<table class="noborder">';
  4196. print '<tr class="liste_titre">';
  4197. print_liste_field_titre("#", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder, 'thsticky thstickygrey ');
  4198. print_liste_field_titre("Table", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
  4199. print_liste_field_titre("Label", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
  4200. print_liste_field_titre("SQL", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
  4201. print_liste_field_titre("SQLSort", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
  4202. print_liste_field_titre("FieldsView", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
  4203. print_liste_field_titre("FieldsEdit", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
  4204. print_liste_field_titre("FieldsInsert", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
  4205. print_liste_field_titre("Rowid", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
  4206. print_liste_field_titre("Condition", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
  4207. print_liste_field_titre("", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
  4208. print "</tr>\n";
  4209. if (!empty($dicts) && is_array($dicts) && !empty($dicts['tabname']) && is_array($dicts['tabname'])) {
  4210. $i = 0;
  4211. $maxi = count($dicts['tabname']);
  4212. while ($i < $maxi) {
  4213. if ($action == 'editdict' && $i == (int) GETPOST('dictionnarykey', 'int')-1) {
  4214. print '<tr class="oddeven">';
  4215. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  4216. print '<input type="hidden" name="token" value="'.newToken().'">';
  4217. print '<input type="hidden" name="tab" value="dictionaries">';
  4218. print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
  4219. print '<input type="hidden" name="action" value="updatedictionary">';
  4220. print '<input type="hidden" name="dictionnarykey" value="'.($i+1).'">';
  4221. print '<td class="tdsticky tdstickygray">';
  4222. print($i + 1);
  4223. print '</td>';
  4224. print '<td>';
  4225. print '<input type="text" name="tabname" value="'.$dicts['tabname'][$i].'" readonly class="tdstickygray">';
  4226. print '</td>';
  4227. print '<td>';
  4228. print '<input type="text" name="tablib" value="'.$dicts['tablib'][$i].'">';
  4229. print '</td>';
  4230. print '<td>';
  4231. print '<input type="text" name="tabsql" value="'.$dicts['tabsql'][$i].'" readonly class="tdstickygray">';
  4232. print '</td>';
  4233. print '<td>';
  4234. print '<select name="tabsqlsort">';
  4235. print '<option value="'.dol_escape_htmltag($dicts['tabsqlsort'][$i]).'">'.$dicts['tabsqlsort'][$i].'</option>';
  4236. print '</select>';
  4237. print '</td>';
  4238. print '<td><select name="tabfield" >';
  4239. print '<option value="'.dol_escape_htmltag($dicts['tabfield'][$i]).'">'.$dicts['tabfield'][$i].'</option>';
  4240. print '</select></td>';
  4241. print '<td><select name="tabfieldvalue" >';
  4242. print '<option value="'.dol_escape_htmltag($dicts['tabfieldvalue'][$i]).'">'.$dicts['tabfieldvalue'][$i].'</option>';
  4243. print '</select></td>';
  4244. print '<td><select name="tabfieldinsert" >';
  4245. print '<option value="'.dol_escape_htmltag($dicts['tabfieldinsert'][$i]).'">'.$dicts['tabfieldinsert'][$i].'</option>';
  4246. print '</select></td>';
  4247. print '<td>';
  4248. print '<input type="text" name="tabrowid" value="'.dol_escape_htmltag($dicts['tabrowid'][$i]).'" readonly class="tdstickygray">';
  4249. print '</td>';
  4250. print '<td>';
  4251. print '<input type="text" name="tabcond" value="'.dol_escape_htmltag((empty($dicts['tabcond'][$i]) ? 'disabled' : 'enabled')).'" readonly class="tdstickygray">';
  4252. print '</td>';
  4253. print '<td class="center minwidth75 tdstickyright tdstickyghostwhite">';
  4254. print '<input id ="updatedict" class="reposition button smallpaddingimp" type="submit" name="updatedict" value="'.$langs->trans("Modify").'"/>';
  4255. print '<br>';
  4256. print '<input class="reposition button button-cancel smallpaddingimp" type="submit" name="cancel" value="'.$langs->trans("Cancel").'"/>';
  4257. print '</td>';
  4258. print '</form>';
  4259. print '</tr>';
  4260. } else {
  4261. print '<tr class="oddeven">';
  4262. print '<td class="tdsticky tdstickygray">';
  4263. print($i + 1);
  4264. print '</td>';
  4265. print '<td>';
  4266. print $dicts['tabname'][$i];
  4267. print '</td>';
  4268. print '<td>';
  4269. print $dicts['tablib'][$i];
  4270. print '</td>';
  4271. print '<td>';
  4272. print $dicts['tabsql'][$i];
  4273. print '</td>';
  4274. print '<td>';
  4275. print $dicts['tabsqlsort'][$i];
  4276. print '</td>';
  4277. print '<td>';
  4278. print $dicts['tabfield'][$i];
  4279. print '</td>';
  4280. print '<td>';
  4281. print $dicts['tabfieldvalue'][$i];
  4282. print '</td>';
  4283. print '<td>';
  4284. print $dicts['tabfieldinsert'][$i];
  4285. print '</td>';
  4286. print '<td >';
  4287. print $dicts['tabrowid'][$i];
  4288. print '</td>';
  4289. print '<td >';
  4290. print $dicts['tabcond'][$i];
  4291. print '</td>';
  4292. print '<td class="center minwidth75 tdstickyright tdstickyghostwhite">';
  4293. print '<a class="editfielda reposition marginleftonly marginrighttonly paddingright paddingleft" href="'.$_SERVER["PHP_SELF"].'?action=editdict&token='.newToken().'&dictionnarykey='.urlencode($i+1).'&tab='.urlencode($tab).'&module='.urlencode($module).'">'.img_edit().'</a>';
  4294. print '<a class="marginleftonly marginrighttonly paddingright paddingleft" href="'.$_SERVER["PHP_SELF"].'?action=deletedict&token='.newToken().'&dictionnarykey='.urlencode($i+1).'&tab='.urlencode($tab).'&module='.urlencode($module).'">'.img_delete().'</a>';
  4295. print '</td>';
  4296. print '</tr>';
  4297. }
  4298. $i++;
  4299. }
  4300. } else {
  4301. print '<tr><td colspan="10"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
  4302. }
  4303. print '</table>';
  4304. print '</div>';
  4305. print '</form>';
  4306. }
  4307. if ($tabdic == 'newdictionary') {
  4308. // New dic tab
  4309. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  4310. print '<input type="hidden" name="token" value="'.newToken().'">';
  4311. print '<input type="hidden" name="action" value="initdic">';
  4312. print '<input type="hidden" name="tab" value="dictionaries">';
  4313. print '<input type="hidden" name="tabdic" value="'.$tabdic.'">';
  4314. print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
  4315. print '<span class="opacitymedium">'.$langs->trans("EnterNameOfDictionaryDesc").'</span><br><br>';
  4316. print dol_get_fiche_head('');
  4317. print '<table class="border centpercent">';
  4318. print '<tbody>';
  4319. print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans("Table").'</td><td><input type="text" name="dicname" maxlength="64" value="'.dol_escape_htmltag(GETPOST('dicname', 'alpha') ? GETPOST('dicname', 'alpha') : $modulename).'" placeholder="'.dol_escape_htmltag($langs->trans("DicKey")).'" autofocus></td>';
  4320. print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans("Label").'</td><td><input type="text" name="label" value="'.dol_escape_htmltag(GETPOST('label', 'alpha')).'"></td></tr>';
  4321. print '<tr><td class="titlefieldcreate">'.$langs->trans("SQL").'</td><td><input type="text" style="width:50%;" name="sql" value="'.dol_escape_htmltag(GETPOST('sql', 'alpha')).'"></td></tr>';
  4322. print '<tr><td class="titlefieldcreate">'.$langs->trans("SQLSort").'</td><td><input type="text" name="sqlsort" value="'.dol_escape_htmltag(GETPOST('sqlsort', 'alpha')).'" readonly></td></tr>';
  4323. print '<tr><td class="titlefieldcreate">'.$langs->trans("FieldsView").'</td><td><input type="text" name="field" value="'.dol_escape_htmltag(GETPOST('field', 'alpha')).'"></td></tr>';
  4324. print '<tr><td class="titlefieldcreate">'.$langs->trans("FieldsEdit").'</td><td><input type="text" name="fieldvalue" value="'.dol_escape_htmltag(GETPOST('fieldvalue', 'alpha')).'"></td></tr>';
  4325. print '<tr><td class="titlefieldcreate">'.$langs->trans("FieldsInsert").'</td><td><input type="text" name="fieldinsert" value="'.dol_escape_htmltag(GETPOST('fieldinsert', 'alpha')).'"></td></tr>';
  4326. print '<tr><td class="titlefieldcreate">'.$langs->trans("Rowid").'</td><td><input type="text" name="rowid" value="'.dol_escape_htmltag(GETPOST('rowid', 'alpha')).'"></td></tr>';
  4327. print '<tr></tr>';
  4328. print '</tbody></table>';
  4329. print '<input type="submit" class="button" name="create" value="'.dol_escape_htmltag($langs->trans("GenerateCode")).'"'.($dirins ? '' : ' disabled="disabled"').'>';
  4330. print '<input id="cancel" type="submit" class="button" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
  4331. print dol_get_fiche_end();
  4332. print '</form>';
  4333. print '<script>
  4334. $(document).ready(function() {
  4335. $("input[name=\'dicname\']").on("blur", function() {
  4336. if ($(this).val().length > 0) {
  4337. $("input[name=\'label\']").val($(this).val());
  4338. $("input[name=\'sql\']").val("SELECT f.rowid as rowid, f.code, f.label, f.active FROM llx_c_" + $(this).val() + " as f");
  4339. $("input[name=\'sqlsort\']").val("label ASC");
  4340. $("input[name=\'field\']").val("code,label");
  4341. $("input[name=\'fieldvalue\']").val("code,label");
  4342. $("input[name=\'fieldinsert\']").val("code,label");
  4343. $("input[name=\'rowid\']").val("rowid");
  4344. } else {
  4345. $("input[name=\'label\']").val("");
  4346. $("input[name=\'sql\']").val("");
  4347. $("input[name=\'sqlsort\']").val("");
  4348. $("input[name=\'field\']").val("");
  4349. $("input[name=\'fieldvalue\']").val("");
  4350. $("input[name=\'fieldinsert\']").val("");
  4351. $("input[name=\'rowid\']").val("");
  4352. }
  4353. });
  4354. $("input[id=\'cancel\']").click(function() {
  4355. window.history.back();
  4356. });
  4357. });
  4358. </script>';
  4359. /*print '<br>';
  4360. print '<br>';
  4361. print '<br>';
  4362. print '<span class="opacitymedium">'.$langs->trans("or").'</span>';
  4363. print '<br>';
  4364. print '<br>';
  4365. //print '<input type="checkbox" name="initfromtablecheck"> ';
  4366. print $langs->trans("InitStructureFromExistingTable");
  4367. print '<input type="text" name="initfromtablename" value="" placeholder="'.$langs->trans("TableName").'">';
  4368. print '<input type="submit" class="button smallpaddingimp" name="createtablearray" value="'.dol_escape_htmltag($langs->trans("GenerateCode")).'"'.($dirins ? '' : ' disabled="disabled"').'>';
  4369. print '<br>';
  4370. */
  4371. } elseif ($tabdic == 'deletedictionary') {
  4372. // Delete dic tab
  4373. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  4374. print '<input type="hidden" name="token" value="'.newToken().'">';
  4375. print '<input type="hidden" name="action" value="confirm_deletedictionary">';
  4376. print '<input type="hidden" name="tab" value="dictionaries">';
  4377. print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
  4378. print $langs->trans("EnterNameOfDictionnaryToDeleteDesc").'<br><br>';
  4379. print '<input type="text" name="dicname" value="'.dol_escape_htmltag($modulename).'" placeholder="'.dol_escape_htmltag($langs->trans("DicKey")).'">';
  4380. print '<input type="submit" class="button smallpaddingimp" name="delete" value="'.dol_escape_htmltag($langs->trans("Delete")).'"'.($dirins ? '' : ' disabled="disabled"').'>';
  4381. print '</form>';
  4382. }
  4383. print dol_get_fiche_end();
  4384. } else {
  4385. $fullpathoffile = dol_buildpath($file, 0);
  4386. $content = file_get_contents($fullpathoffile);
  4387. // New module
  4388. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  4389. print '<input type="hidden" name="token" value="'.newToken().'">';
  4390. print '<input type="hidden" name="action" value="savefile">';
  4391. print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
  4392. print '<input type="hidden" name="tab" value="'.$tab.'">';
  4393. print '<input type="hidden" name="module" value="'.$module.'">';
  4394. $doleditor = new DolEditor('editfilecontent', $content, '', '300', 'Full', 'In', true, false, 'ace', 0, '99%');
  4395. print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ? GETPOST('format', 'aZ09') : 'html'));
  4396. print '<br>';
  4397. print '<center>';
  4398. print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
  4399. print ' &nbsp; ';
  4400. print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
  4401. print '</center>';
  4402. print '</form>';
  4403. }
  4404. }
  4405. if ($tab == 'menus') {
  4406. print '<!-- tab=menus -->'."\n";
  4407. $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
  4408. $dirins = $listofmodules[strtolower($module)]['moduledescriptorrootpath'];
  4409. $destdir = $dirins.'/'.strtolower($module);
  4410. $listofobject = dol_dir_list($destdir.'/class', 'files', 0, '\.class\.php$');
  4411. $objects = dolGetListOfObjectclasses($destdir);
  4412. $leftmenus = array();
  4413. $menus = $moduleobj->menu;
  4414. $permissions = $moduleobj->rights;
  4415. $crud = array('read'=>'CRUDRead', 'write'=>'CRUDCreateWrite', 'delete'=>'Delete');
  4416. //grouped permissions
  4417. $groupedRights = array();
  4418. foreach ($permissions as $right) {
  4419. $key = $right[4];
  4420. if (!isset($groupedRights[$key])) {
  4421. $groupedRights[$key] = array();
  4422. }
  4423. $groupedRights[$key][] = $right;
  4424. }
  4425. $groupedRights_json = json_encode($groupedRights);
  4426. if ($action == 'deletemenu') {
  4427. $formconfirms = $form->formconfirm(
  4428. $_SERVER["PHP_SELF"].'?menukey='.urlencode(GETPOST('menukey', 'int')).'&tab='.urlencode($tab).'&module='.urlencode($module),
  4429. $langs->trans('Delete'),
  4430. ($menus[GETPOST('menukey')]['fk_menu'] === 'fk_mainmenu='.strtolower($module) ? $langs->trans('Warning: you will delete all menus linked to this one.', GETPOST('menukey', 'int')) : $langs->trans('Confirm Delete Menu', GETPOST('menukey', 'int'))),
  4431. 'confirm_deletemenu',
  4432. '',
  4433. 0,
  4434. 1
  4435. );
  4436. print $formconfirms;
  4437. }
  4438. if ($action != 'editfile' || empty($file)) {
  4439. print '<span class="opacitymedium">';
  4440. $htmlhelp = $langs->trans("MenusDefDescTooltip", '{s1}');
  4441. $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);
  4442. print $form->textwithpicto($langs->trans("MenusDefDesc"), $htmlhelp, 1, 'help', '', 0, 2, 'helpondesc').'<br>';
  4443. print '</span>';
  4444. print '<br>';
  4445. print '<span class="fa fa-file-o"></span> '.$langs->trans("DescriptorFile").' : <strong class="wordbreak">'.$pathtofile.'</strong>';
  4446. print ' <a class="editfielda paddingleft paddingright" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&token='.newToken().'&format=php&file='.urlencode($pathtofile).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
  4447. print '<br>';
  4448. print '<br>';
  4449. print load_fiche_titre($langs->trans("ListOfMenusEntries"), '', '');
  4450. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  4451. print '<input type="hidden" name="token" value="'.newToken().'">';
  4452. print '<input type="hidden" name="action" value="addmenu">';
  4453. print '<input type="hidden" name="tab" value="menus">';
  4454. print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
  4455. print '<input type="hidden" name="tabobj" value="'.dol_escape_htmltag($tabobj).'">';
  4456. print '<div class="div-table-responsive">';
  4457. print '<table class="noborder small">';
  4458. $htmltextenabled = '<u>'.$langs->trans("Examples").':</u><br>';
  4459. $htmltextenabled .= '1 <span class="opacitymedium">(module always enabled)</span><br>';
  4460. $htmltextenabled .= '0 <span class="opacitymedium">(module always disabled)</span><br>';
  4461. $htmltextenabled .= 'isModEnabled(\''.dol_escape_htmltag(strtolower($module)).'\') <span class="opacitymedium">(enabled when module is enabled)</span>';
  4462. $htmltextperms = '<u>'.$langs->trans("Examples").':</u><br>';
  4463. $htmltextperms .= '1 <span class="opacitymedium">(access always allowed)</span><br>';
  4464. $htmltextperms .= '$user->hasright(\''.dol_escape_htmltag(strtolower($module)).'\', \'myobject\', \'read\') <span class="opacitymedium">(access allowed if user has permission module->object->read)</span>';
  4465. print '<tr class="liste_titre">';
  4466. print_liste_field_titre("#", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder, 'center tdsticky tdstickygray ');
  4467. print_liste_field_titre("Position", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
  4468. print_liste_field_titre("Title", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder, 'center');
  4469. print_liste_field_titre("LinkToParentMenu", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder, 'minwidth100 ');
  4470. print_liste_field_titre("mainmenu", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
  4471. print_liste_field_titre("leftmenu", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
  4472. print_liste_field_titre("URL", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder, '', $langs->transnoentitiesnoconv('DetailUrl'));
  4473. print_liste_field_titre("LanguageFile", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
  4474. print_liste_field_titre("Position", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder, 'right ');
  4475. print_liste_field_titre("Enabled", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder, 'center ', $langs->trans('DetailEnabled').'<br><br>'.$htmltextenabled);
  4476. print_liste_field_titre("Rights", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder, '', $langs->trans('DetailRight').'<br><br>'.$htmltextperms);
  4477. print_liste_field_titre("Target", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder, '', $langs->trans('DetailTarget'));
  4478. print_liste_field_titre("MenuForUsers", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder, 'center minwidth100 ', $langs->trans('DetailUser'));
  4479. print_liste_field_titre("", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder, 'center ', $langs->trans(''));
  4480. print "</tr>\n";
  4481. $r = count($menus)+1;
  4482. // for adding menu on module
  4483. print '<tr>';
  4484. print '<td class="center tdsticky tdstickygray"><input type="hidden" readonly class="center maxwidth50" name="propenabled" value="#"></td>';
  4485. print '<td class="center">';
  4486. print '<select class="maxwidth50" name="type">';
  4487. print '<option value="">'.$langs->trans("........").'</option><option value="'.dol_escape_htmltag("left").'">left</option><option value="'.dol_escape_htmltag("top").'">top</option>';
  4488. print '</select></td>';
  4489. print '<td class="left"><input type="text" class="left maxwidth100" name="titre" value="'.dol_escape_htmltag(GETPOST('titre', 'alpha')).'"></td>';
  4490. print '<td class="left">';
  4491. print '<select name="fk_menu">';
  4492. print '<option value="">'.$langs->trans("........").'</option>';
  4493. foreach ($menus as $obj) {
  4494. if ($obj['type'] == 'left' && !empty($obj['leftmenu'])) {
  4495. print "<option value=".strtolower($obj['leftmenu']).">".$obj['leftmenu']."</option>";
  4496. }
  4497. }
  4498. print '</select>';
  4499. print '</td>';
  4500. print '<td class="left"><input type="text" class="left maxwidth50" name="mainmenu" value="'.(empty(GETPOST('mainmenu')) ? strtolower($module) : dol_escape_htmltag(GETPOST('mainmenu', 'alpha'))).'"></td>';
  4501. print '<td class="center"><input id="leftmenu" type="text" class="left maxwidth50" name="leftmenu" value="'.dol_escape_htmltag(GETPOST('leftmenu', 'alpha')).'"></td>';
  4502. // URL
  4503. print '<td class="left"><input id="url" type="text" class="left maxwidth100" name="url" value="'.dol_escape_htmltag(GETPOST('url', 'alpha')).'"></td>';
  4504. print '<td class="left"><input type="text" class="left maxwidth75" name="langs" value="'.strtolower($module).'@'.strtolower($module).'" readonly></td>';
  4505. // Position
  4506. print '<td class="center"><input type="text" class="center maxwidth50 tdstickygray" name="position" value="'.(1000+$r).'" readonly></td>';
  4507. // Enabled
  4508. print '<td class="center">';
  4509. print '<input type="enabled" class="maxwidth125" value="'.dol_escape_htmltag(GETPOSTISSET('enabled') ? GETPOST('enabled') : 'isModEnabled(\''.$module.'\')').'">';
  4510. /*
  4511. print '<select class="maxwidth" name="enabled">';
  4512. print '<option value="1" selected>'.$langs->trans("Show").'</option>';
  4513. print '<option value="0">'.$langs->trans("Hide").'</option>';
  4514. print '</select>';
  4515. */
  4516. print '</td>';
  4517. // Perms
  4518. print '<td class="left">';
  4519. print '<select class="maxwidth" name="objects" id="objects">';
  4520. print '<option value=""></option>';
  4521. if (is_array($objects)) {
  4522. foreach ($objects as $value) {
  4523. print '<option value="'.strtolower($value).'">'.dol_escape_htmltag(strtolower($value)).'</option>';
  4524. }
  4525. }
  4526. print '</select>';
  4527. print '<select class="maxwidth hideobject" name="perms" id="perms">';
  4528. print '</select>';
  4529. print '</td>';
  4530. print '<td class="center"><input type="text" class="center maxwidth50" name="target" value="'.dol_escape_htmltag(GETPOST('target', 'alpha')).'"></td>';
  4531. print '<td class="center"><select class="maxwidth10" name="user"><option value="2">'.$langs->trans("AllMenus").'</option><option value="0">'.$langs->trans("Internal").'</option><option value="1">'.$langs->trans("External").'</option></select></td>';
  4532. print '<td class="center minwidth75 tdstickyright tdstickyghostwhite">';
  4533. print '<input type="submit" class="button" name="add" value="'.$langs->trans("Add").'">';
  4534. print '</td>';
  4535. print '</tr>';
  4536. // end form for add menu
  4537. //var_dump($menus);
  4538. // Loop on each menu entry
  4539. if (count($menus)) {
  4540. $i = 0;
  4541. foreach ($menus as $menu) {
  4542. $i++;
  4543. //for get parent in menu
  4544. $string = dol_escape_htmltag($menu['fk_menu']);
  4545. $value = substr($string, strpos($string, 'fk_leftmenu=') + strlen('fk_leftmenu='));
  4546. $propFk_menu = !empty($menu['fk_menu']) ? $menu['fk_menu'] : GETPOST('fk_menu');
  4547. $propTitre = !empty($menu['titre']) ? $menu['titre'] : GETPOST('titre');
  4548. $propMainmenu = !empty($menu['mainmenu']) ? $menu['mainmenu'] : GETPOST('mainmenu');
  4549. $propLeftmenu = !empty($menu['leftmenu']) ? $menu['leftmenu'] : GETPOST('leftmenu');
  4550. $propUrl = !empty($menu['url']) ? $menu['url'] : GETPOST('url', 'alpha');
  4551. $propPerms = !empty($menu['perms']) ? $menu['perms'] : GETPOST('perms');
  4552. $propUser = !empty($menu['user']) ? $menu['user'] : GETPOST('user');
  4553. $propTarget = !empty($menu['target']) ? $menu['target'] : GETPOST('target');
  4554. $propEnabled = !empty($menu['enabled']) ? $menu['enabled'] : GETPOST('enabled');
  4555. $objPerms = (empty($arguments[1]) ? '' : trim($arguments[1]));
  4556. $valPerms = (empty($arguments[2]) ? '' : trim($arguments[2]));
  4557. //$tabobject = ''; // We can't know what is $tabobject in most cases
  4558. if ($action == 'editmenu' && GETPOST('menukey', 'int') == $i) {
  4559. //var_dump($propPerms);exit;
  4560. print '<tr class="oddeven">';
  4561. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  4562. print '<input type="hidden" name="token" value="'.newToken().'">';
  4563. print '<input type="hidden" name="action" value="update_menu">';
  4564. print '<input type="hidden" name="tab" value="menus">';
  4565. print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
  4566. print '<input type="hidden" name="menukey" value="'.$i.'"/>';
  4567. //print '<input type="hidden" name="tabobject" value="'.dol_escape_htmltag($tabobject).'">';
  4568. print '<td class="tdsticky tdstickygray">';
  4569. print $i;
  4570. print '</td>';
  4571. // Position (top, left)
  4572. print '<td class="center">
  4573. <select class="center maxwidth50" name="type">
  4574. <option value="'.dol_escape_htmltag($menu['type']).'">
  4575. '.dol_escape_htmltag($menu['type']).'
  4576. </option>';
  4577. print '<option value="'.($menu['type'] == 'left' ? 'top' : 'left').'">';
  4578. if ($menu['type'] == 'left') {
  4579. print 'top';
  4580. } else {
  4581. print 'left';
  4582. }
  4583. print '</option></select></td>';
  4584. // Title
  4585. print '<td><input type="text" class="left maxwidth100" name="titre" value="'.dol_escape_htmltag($propTitre).'"></td>';
  4586. // Parent menu
  4587. print '<td>';
  4588. /*print '<select name="fk_menu" class="left maxwidth">';
  4589. print '<option value="'.dol_escape_htmltag($propFk_menu).'">'.dol_escape_htmltag($value).'</option>';
  4590. foreach ($menus as $obj) {
  4591. if ($obj['type'] == 'left' && $obj['leftmenu'] != $value && $obj['leftmenu'] != $menu['leftmenu']) {
  4592. print "<option value=".strtolower($obj['leftmenu']).">".$obj['leftmenu']."</option>";
  4593. }
  4594. }
  4595. print '</select>';*/
  4596. print '<input type="text" name="fk_menu" class="maxwidth150" value="'.dol_escape_htmltag($propFk_menu).'">';
  4597. print '</td>';
  4598. print '<td><input type="text" class="left maxwidth50" name="mainmenu" value="'.dol_escape_htmltag($propMainmenu).'" readonly></td>';
  4599. print '<td><input type="text" class="left maxwidth50" name="leftmenu" value="'.dol_escape_htmltag($propLeftmenu).'" readonly></td>';
  4600. // URL
  4601. print '<td><input type="text" class="left maxwidth250" name="url" value="'.dol_escape_htmltag($propUrl).'"></td>';
  4602. print '<td><input type="text" class="left maxwidth50" name="langs" value="'.strtolower($module).'@'.strtolower($module).'" readonly></td>';
  4603. // Position
  4604. print '<td class="center"><input type="text" class="center maxwidth50 tdstickygray" name="position" value="'.($menu['position']).'" readonly></td>';
  4605. // Enabled
  4606. print '<td class="nowraponall">';
  4607. print '<input type="text" class="maxwidth125" name="enabled" value="'.dol_escape_htmltag($propEnabled != '' ? $propEnabled : "isModEnabled('".dol_escape_htmltag($module)."')").'">';
  4608. $htmltext = '<u>'.$langs->trans("Examples").':</u><br>';
  4609. $htmltext .= '1 <span class="opacitymedium">(always enabled)</span><br>';
  4610. $htmltext .= '0 <span class="opacitymedium">(always disabled)</span><br>';
  4611. $htmltext .= 'isModEnabled(\''.dol_escape_htmltag($module).'\') <span class="opacitymedium">(enabled when module is enabled)</span><br>';
  4612. print $form->textwithpicto('', $htmltext);
  4613. /*
  4614. print '<select class="maxwidth50" name="enabledselect">';
  4615. print '<option value="1">1 (always enabled)</option>';
  4616. print '<option value="0">0 (always disabled)</option>';
  4617. print '<option value="isModEnabled(\''.dol_escape_htmltag($module).'\')" >isModEnabled(\''.dol_escape_htmltag($module).'\')</option>';
  4618. print '</select>';
  4619. */
  4620. print '</td>';
  4621. // Permissions
  4622. print '<td class="nowraponall">';
  4623. print '<input type="text" name="perms" value="'.dol_escape_htmltag($propPerms).'">';
  4624. /*
  4625. if (!empty($objPerms)) {
  4626. print '<input type="hidden" name="objects" value="'.$objPerms.'" />';
  4627. print '<select class="center maxwidth50" name="perms">';
  4628. if (!empty($valPerms)) {
  4629. print '<option selected value="'.dol_escape_htmltag($valPerms).'">'.dol_escape_htmltag($langs->trans($crud[$valPerms])).'</option>';
  4630. foreach ($crud as $key => $val) {
  4631. if ($valPerms != $key) {
  4632. print '<option value="'.dol_escape_htmltag($key).'">'.dol_escape_htmltag($langs->trans($val)).'</option>';
  4633. }
  4634. }
  4635. }
  4636. print '</select>';
  4637. } else {
  4638. print '<select class="center maxwidth50" name="objects">';
  4639. print '<option></option>';
  4640. foreach ($objects as $obj) {
  4641. print '<option value="'.dol_escape_htmltag(strtolower($obj)).'">'.dol_escape_htmltag($obj).'</option>';
  4642. }
  4643. print '</select>';
  4644. print '<select class="center maxwidth50" name="perms">';
  4645. foreach ($crud as $key => $val) {
  4646. print '<option value="'.dol_escape_htmltag($key).'">'.dol_escape_htmltag($key).'</option>';
  4647. }
  4648. print '</select>';
  4649. }*/
  4650. print '</td>';
  4651. // Target
  4652. print '<td class="center"><input type="text" class="center maxwidth50" name="target" value="'.dol_escape_htmltag($propTarget).'"></td>';
  4653. print '<td class="center"><select class="center maxwidth10" name="user"><option value="2">'.$langs->trans("AllMenus").'</option><option value="0">'.$langs->trans("Internal").'</option><option value="1">'.$langs->trans("External").'</option></select></td>';
  4654. print '<td class="center minwidth75 tdstickyright tdstickyghostwhite maxwidth75">';
  4655. print '<input class="reposition button smallpaddingimp" type="submit" name="edit" value="'.$langs->trans("Modify").'">';
  4656. print '<input class="reposition button button-cancel smallpaddingimp" type="submit" name="cancel" value="'.$langs->trans("Cancel").'">';
  4657. print '</td>';
  4658. print '</form>';
  4659. print '</tr>';
  4660. } else {
  4661. print '<tr class="oddeven">';
  4662. print '<td class="tdsticky tdstickygray">';
  4663. print $i;
  4664. print '</td>';
  4665. print '<td class="center">';
  4666. print dol_escape_htmltag($menu['type']);
  4667. print '</td>';
  4668. // Title
  4669. print '<td>';
  4670. print dol_escape_htmltag($menu['titre']);
  4671. print '</td>';
  4672. // Parent menu
  4673. print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($menu['fk_menu']).'">';
  4674. print dol_escape_htmltag($menu['fk_menu']);
  4675. print '</td>';
  4676. print '<td>';
  4677. print dol_escape_htmltag($menu['mainmenu']);
  4678. print '</td>';
  4679. print '<td>';
  4680. print dol_escape_htmltag($menu['leftmenu']);
  4681. print '</td>';
  4682. print '<td class="tdoverflowmax250" title="'.dol_escape_htmltag($menu['url']).'">';
  4683. print dol_escape_htmltag($menu['url']);
  4684. print '</td>';
  4685. print '<td>';
  4686. print dol_escape_htmltag($menu['langs']);
  4687. print '</td>';
  4688. // Position
  4689. print '<td class="center">';
  4690. print dol_escape_htmltag($menu['position']);
  4691. print '</td>';
  4692. // Enabled
  4693. print '<td class="tdoverflowmax200" title="'.dol_escape_htmltag($menu['enabled']).'">';
  4694. print dol_escape_htmltag($menu['enabled']);
  4695. print '</td>';
  4696. // Perms
  4697. print '<td class="tdoverflowmax200" title="'.dol_escape_htmltag($menu['perms']).'">';
  4698. print dol_escape_htmltag($langs->trans($menu['perms']));
  4699. print '</td>';
  4700. // Target
  4701. print '<td class="center tdoverflowmax200" title="'.dol_escape_htmltag($menu['target']).'">';
  4702. print dol_escape_htmltag($menu['target']);
  4703. print '</td>';
  4704. print '<td class="center">';
  4705. if ($menu['user'] == 2) {
  4706. print $langs->trans("AllMenus");
  4707. } elseif ($menu['user'] == 0) {
  4708. print $langs->trans('Internal');
  4709. } elseif ($menu['user'] == 1) {
  4710. print $langs->trans('External');
  4711. } else {
  4712. print $menu['user']; // should not happen
  4713. }
  4714. print '</td>';
  4715. print '<td class="center minwidth75 tdstickyright tdstickyghostwhite">';
  4716. if ($menu['titre'] != 'Module'.$module.'Name') {
  4717. print '<a class="editfielda reposition marginleftonly marginrighttonly paddingright paddingleft" href="'.$_SERVER["PHP_SELF"].'?action=editmenu&token='.newToken().'&menukey='.urlencode($i).'&tab='.urlencode($tab).'&module='.urlencode($module).'&tabobj='.urlencode($tabobj).'">'.img_edit().'</a>';
  4718. print '<a class="marginleftonly marginrighttonly paddingright paddingleft" href="'.$_SERVER["PHP_SELF"].'?action=deletemenu&token='.newToken().'&menukey='.urlencode($i-1).'&tab='.urlencode($tab).'&module='.urlencode($module).'&tabobj='.urlencode($tabobj).'">'.img_delete().'</a>';
  4719. }
  4720. print '</td>';
  4721. }
  4722. print '</tr>';
  4723. }
  4724. } else {
  4725. print '<tr><td colspan="5"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
  4726. }
  4727. print '</table>';
  4728. print '</div>';
  4729. print '</form>';
  4730. print '<script>
  4731. $(document).ready(function() {
  4732. //for fill in auto url
  4733. $("#leftmenu").on("input", function() {
  4734. var inputLeftMenu = $("#leftmenu").val();
  4735. if (inputLeftMenu !== \'\') {
  4736. var url = \''.dol_escape_js(strtolower($module)).'\' + inputLeftMenu + \'.php\';
  4737. $("#url").val(url);
  4738. }else {
  4739. $("#url").val("");
  4740. }
  4741. });
  4742. var groupedRights = ' . $groupedRights_json . ';
  4743. var objectsSelect = $("select[id=\'objects\']");
  4744. var permsSelect = $("select[id=\'perms\']");
  4745. objectsSelect.change(function() {
  4746. var selectedObject = $(this).val();
  4747. permsSelect.empty();
  4748. var rights = groupedRights[selectedObject];
  4749. if (rights) {
  4750. for (var i = 0; i < rights.length; i++) {
  4751. var right = rights[i];
  4752. var option = $("<option></option>").attr("value", right[5]).text(right[5]);
  4753. permsSelect.append(option);
  4754. }
  4755. } else {
  4756. var option = $("<option></option>").attr("value", "read").text("read");
  4757. permsSelect.append(option);
  4758. }
  4759. if (selectedObject !== "" && selectedObject !== null && rights) {
  4760. permsSelect.show();
  4761. } else {
  4762. permsSelect.hide();
  4763. }
  4764. if (objectsSelect.val() === "" || objectsSelect.val() === null) {
  4765. permsSelect.hide();
  4766. }
  4767. });
  4768. });
  4769. </script>';
  4770. // display permissions for each object
  4771. } else {
  4772. $fullpathoffile = dol_buildpath($file, 0);
  4773. $content = file_get_contents($fullpathoffile);
  4774. // New module
  4775. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  4776. print '<input type="hidden" name="token" value="'.newToken().'">';
  4777. print '<input type="hidden" name="action" value="savefile">';
  4778. print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
  4779. print '<input type="hidden" name="tab" value="'.$tab.'">';
  4780. print '<input type="hidden" name="module" value="'.$module.'">';
  4781. $doleditor = new DolEditor('editfilecontent', $content, '', '300', 'Full', 'In', true, false, 'ace', 0, '99%');
  4782. print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ? GETPOST('format', 'aZ09') : 'html'));
  4783. print '<br>';
  4784. print '<center>';
  4785. print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
  4786. print ' &nbsp; ';
  4787. print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
  4788. print '</center>';
  4789. print '</form>';
  4790. }
  4791. }
  4792. if ($tab == 'permissions') {
  4793. print '<!-- tab=permissions -->'."\n";
  4794. $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
  4795. $perms = $moduleobj->rights;
  4796. // Get list of existing objects
  4797. $dir = $dirread.'/'.$modulelowercase.'/class';
  4798. $listofobject = dol_dir_list($dir, 'files', 0, '\.class\.php$');
  4799. $objects = array('myobject');
  4800. $reg =array();
  4801. foreach ($listofobject as $fileobj) {
  4802. $tmpcontent = file_get_contents($fileobj['fullname']);
  4803. if (preg_match('/class\s+([^\s]*)\s+extends\s+CommonObject/ims', $tmpcontent, $reg)) {
  4804. $objects[$fileobj['fullname']] = $reg[1];
  4805. }
  4806. }
  4807. // declared select list for actions and labels permissions
  4808. $crud = array('read'=>'CRUDRead', 'write'=>'CRUDCreateWrite', 'delete'=>'Delete');
  4809. $labels = array("Read objects of ".$module, "Create/Update objects of ".$module, "Delete objects of ".$module);
  4810. $action = GETPOST('action', 'alpha');
  4811. if ($action == 'deleteright') {
  4812. $formconfirm = $form->formconfirm(
  4813. $_SERVER["PHP_SELF"].'?permskey='.urlencode(GETPOST('permskey', 'int')).'&tab='.urlencode($tab).'&module='.urlencode($module).'&tabobj='.urlencode($tabobj),
  4814. $langs->trans('Delete'),
  4815. $langs->trans('Confirm Delete Right', GETPOST('permskey', 'alpha')),
  4816. 'confirm_deleteright',
  4817. '',
  4818. 0,
  4819. 1
  4820. );
  4821. print $formconfirm;
  4822. }
  4823. if ($action != 'editfile' || empty($file)) {
  4824. print '<!-- Tab to manage permissions -->'."\n";
  4825. print '<span class="opacitymedium">';
  4826. $htmlhelp = $langs->trans("PermissionsDefDescTooltip", '{s1}');
  4827. $htmlhelp = str_replace('{s1}', '<a target="adminbis" class="nofocusvisible" href="'.DOL_URL_ROOT.'/admin/perms.php">'.$langs->trans('DefaultRights').'</a>', $htmlhelp);
  4828. print $form->textwithpicto($langs->trans("PermissionsDefDesc"), $htmlhelp, 1, 'help', '', 0, 2, 'helpondesc').'<br>';
  4829. print '</span>';
  4830. print '<br>';
  4831. print '<span class="fa fa-file-o"></span> '.$langs->trans("DescriptorFile").' : <strong class="wordbreak">'.$pathtofile.'</strong>';
  4832. print ' <a class="editfielda paddingleft paddingright" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&token='.newToken().'&format=php&file='.urlencode($pathtofile).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
  4833. print '<br>';
  4834. print '<br>';
  4835. print load_fiche_titre($langs->trans("ListOfPermissionsDefined"), '', '');
  4836. print '<!-- form to add permissions -->'."\n";
  4837. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  4838. print '<input type="hidden" name="token" value="'.newToken().'">';
  4839. print '<input type="hidden" name="action" value="addright">';
  4840. print '<input type="hidden" name="tab" value="permissions">';
  4841. print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
  4842. print '<input type="hidden" name="tabobj" value="'.dol_escape_htmltag($tabobj).'">';
  4843. print '<div class="div-table-responsive">';
  4844. print '<table class="noborder">';
  4845. print '<tr class="liste_titre">';
  4846. print_liste_field_titre("ID", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder, "center");
  4847. print_liste_field_titre("Object", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder, "center");
  4848. print_liste_field_titre("CRUD", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder, "center");
  4849. print_liste_field_titre("Label", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder, "center");
  4850. print_liste_field_titre("", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder, "center");
  4851. print "</tr>\n";
  4852. //form for add new right
  4853. print '<tr class="small">';
  4854. print '<td><input type="hidden" readonly name="id" class="width75" value="0"></td>';
  4855. print '<td><select class="minwidth100" name="permissionObj" id="permissionObj">';
  4856. print '<option value=""></option>';
  4857. foreach ($objects as $obj) {
  4858. if ($obj != 'myobject') {
  4859. print '<option value="'.$obj.'">'.$obj.'</option>';
  4860. }
  4861. }
  4862. print '</select></td>';
  4863. print '<td><select class="maxwidth75" name="crud" id="crud">';
  4864. print '<option value=""></option>';
  4865. foreach ($crud as $key => $val) {
  4866. print '<option value="'.$key.'">'.$langs->trans($val).'</option>';
  4867. }
  4868. print '</td>';
  4869. print '<td >';
  4870. print '<input type="text" name="label" id="label" class="minwidth200">';
  4871. print '</td>';
  4872. print '<td class="center minwidth75 tdstickyright tdstickyghostwhite">';
  4873. print '<input type="submit" class="button" name="add" value="'.$langs->trans("Add").'">';
  4874. print '</td>';
  4875. print '</tr>';
  4876. if (count($perms)) {
  4877. $i = 0;
  4878. foreach ($perms as $perm) {
  4879. $i++;
  4880. // section for editing right
  4881. if ($action == 'edit_right' && $perm[0] == (int) GETPOST('permskey', 'int')) {
  4882. print '<tr class="oddeven">';
  4883. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST" name="modifPerms">';
  4884. print '<input type="hidden" name="token" value="'.newToken().'">';
  4885. print '<input type="hidden" name="tab" value="permissions">';
  4886. print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
  4887. print '<input type="hidden" name="tabobj" value="'.dol_escape_htmltag($tabobj).'">';
  4888. print '<input type="hidden" name="action" value="update_right">';
  4889. print '<input type="hidden" name="counter" value="'.$i.'">';
  4890. print '<input type="hidden" name="permskey" value="'.$perm[0].'">';
  4891. print '<td class="tdsticky tdstickygray">';
  4892. print '<input class="width75" type="text" readonly value="'.dol_escape_htmltag($perm[0]).'"/>';
  4893. print '</td>';
  4894. print '<td>';
  4895. print '<select name="crud">';
  4896. print '<option value="'.dol_escape_htmltag($perm[5]).'">'.$langs->trans($perm[5]).'</option>';
  4897. foreach ($crud as $i=> $x) {
  4898. if ($perm[5] != $i) {
  4899. print '<option value="'.$i.'">'.$langs->trans(ucfirst($x)).'</option>';
  4900. }
  4901. }
  4902. print '</select>';
  4903. print '</td>';
  4904. print '<td><select name="permissionObj" >';
  4905. print '<option value="'.dol_escape_htmltag($perm[4]).'">'.ucfirst($perm[4]).'</option>';
  4906. print '</select></td>';
  4907. print '<td>';
  4908. print '<input type="text" name="label" value="'.dol_escape_htmltag($perm[1]).'">';
  4909. print '</td>';
  4910. print '<td class="center minwidth75 tdstickyright tdstickyghostwhite">';
  4911. print '<input id ="modifyPerm" class="reposition button smallpaddingimp" type="submit" name="modifyright" value="'.$langs->trans("Modify").'"/>';
  4912. print '<br>';
  4913. print '<input class="reposition button button-cancel smallpaddingimp" type="submit" name="cancel" value="'.$langs->trans("Cancel").'"/>';
  4914. print '</td>';
  4915. print '</form>';
  4916. print '</tr>';
  4917. } else {
  4918. // $perm can be module->object->crud or module->crud
  4919. print '<tr class="oddeven">';
  4920. print '<td>';
  4921. print dol_escape_htmltag($perm[0]);
  4922. print '</td>';
  4923. print '<td>';
  4924. if (in_array($perm[5], array('lire', 'read', 'creer', 'write', 'effacer', 'delete'))) {
  4925. print dol_escape_htmltag(ucfirst($perm[4]));
  4926. } else {
  4927. print ''; // No particular object
  4928. }
  4929. print '</td>';
  4930. print '<td>';
  4931. if (in_array($perm[5], array('lire', 'read', 'creer', 'write', 'effacer', 'delete'))) {
  4932. print ucfirst($langs->trans($perm[5]));
  4933. } else {
  4934. print ucfirst($langs->trans($perm[4]));
  4935. }
  4936. print '</td>';
  4937. print '<td>';
  4938. print $langs->trans($perm[1]);
  4939. print '</td>';
  4940. print '<td class="center minwidth75 tdstickyright tdstickyghostwhite">';
  4941. print '<a class="editfielda reposition marginleftonly marginrighttonly paddingright paddingleft" href="'.$_SERVER["PHP_SELF"].'?action=edit_right&token='.newToken().'&permskey='.urlencode($perm[0]).'&tab='.urlencode($tab).'&module='.urlencode($module).'&tabobj='.urlencode($tabobj).'">'.img_edit().'</a>';
  4942. print '<a class="marginleftonly marginrighttonly paddingright paddingleft" href="'.$_SERVER["PHP_SELF"].'?action=deleteright&token='.newToken().'&permskey='.urlencode($i).'&tab='.urlencode($tab).'&module='.urlencode($module).'&tabobj='.urlencode($tabobj).'">'.img_delete().'</a>';
  4943. print '</td>';
  4944. print '</tr>';
  4945. }
  4946. }
  4947. } else {
  4948. print '<tr><td colspan="5"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
  4949. }
  4950. print '</table>';
  4951. print '</div>';
  4952. print '</form>';
  4953. print '<script>
  4954. function updateInputField() {
  4955. value1 = $("#crud").val();
  4956. value2 = $("#permissionObj").val();
  4957. // Vérifie si les deux sélections sont faites
  4958. if (value1 && value2) {
  4959. switch(value1.toLowerCase()){
  4960. case "read":
  4961. $("#label").val("Read "+value2+" object of '.ucfirst($module).'")
  4962. break;
  4963. case "write":
  4964. $("#label").val("Create/Update "+value2+" object of '.ucfirst($module).'")
  4965. break;
  4966. case "delete":
  4967. $("#label").val("Delete "+value2+" object of '.ucfirst($module).'")
  4968. break;
  4969. default:
  4970. $("#label").val("")
  4971. }
  4972. }
  4973. }
  4974. $("#crud, #permissionObj").change(function(){
  4975. console.log("We change selection");
  4976. updateInputField();
  4977. });
  4978. </script>';
  4979. } else {
  4980. $fullpathoffile = dol_buildpath($file, 0);
  4981. $content = file_get_contents($fullpathoffile);
  4982. // New module
  4983. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  4984. print '<input type="hidden" name="token" value="'.newToken().'">';
  4985. print '<input type="hidden" name="action" value="savefile">';
  4986. print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
  4987. print '<input type="hidden" name="tab" value="'.$tab.'">';
  4988. print '<input type="hidden" name="module" value="'.$module.'">';
  4989. $doleditor = new DolEditor('editfilecontent', $content, '', '300', 'Full', 'In', true, false, 'ace', 0, '99%');
  4990. print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ? GETPOST('format', 'aZ09') : 'html'));
  4991. print '<br>';
  4992. print '<center>';
  4993. print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
  4994. print ' &nbsp; ';
  4995. print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
  4996. print '</center>';
  4997. print '</form>';
  4998. }
  4999. }
  5000. if ($tab == 'hooks') {
  5001. print '<!-- tab=hooks -->'."\n";
  5002. if ($action != 'editfile' || empty($file)) {
  5003. print '<span class="opacitymedium">'.$langs->trans("HooksDefDesc").'</span><br>';
  5004. print '<br>';
  5005. print '<table>';
  5006. $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
  5007. print '<tr><td>';
  5008. print '<span class="fa fa-file-o"></span> '.$langs->trans("DescriptorFile").' : <strong class="wordbreak">'.$pathtofile.'</strong>';
  5009. print '</td><td>';
  5010. print '<a class="editfielda paddingleft paddingright" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&token='.newToken().'&format=php&file='.urlencode($pathtofile).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
  5011. print '</td></tr>';
  5012. print '<tr><td>';
  5013. $pathtohook = strtolower($module).'/class/actions_'.strtolower($module).'.class.php';
  5014. print '<span class="fa fa-file-o"></span> '.$langs->trans("HooksFile").' : ';
  5015. if (dol_is_file($dirins.'/'.$pathtohook)) {
  5016. print '<strong class="wordbreak">'.$pathtohook.'</strong>';
  5017. print '</td>';
  5018. print '<td><a class="editfielda paddingleft paddingright" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&token='.newToken().'&format=php&file='.urlencode($pathtohook).'">'.img_picto($langs->trans("Edit"), 'edit').'</a> ';
  5019. print '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=confirm_removefile&token='.newToken().'&file='.urlencode($pathtohook).'">'.img_picto($langs->trans("Delete"), 'delete').'</a></td>';
  5020. } else {
  5021. print '<span class="opacitymedium">'.$langs->trans("FileNotYetGenerated").'</span>';
  5022. print '<a href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=inithook&format=php&file='.urlencode($pathtohook).'">'.img_picto('Generate', 'generate', 'class="paddingleft"').'</td>';
  5023. print '<td></td>';
  5024. }
  5025. print '</tr>';
  5026. } else {
  5027. $fullpathoffile = dol_buildpath($file, 0);
  5028. $content = file_get_contents($fullpathoffile);
  5029. // New module
  5030. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  5031. print '<input type="hidden" name="token" value="'.newToken().'">';
  5032. print '<input type="hidden" name="action" value="savefile">';
  5033. print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
  5034. print '<input type="hidden" name="tab" value="'.$tab.'">';
  5035. print '<input type="hidden" name="module" value="'.$module.'">';
  5036. $doleditor = new DolEditor('editfilecontent', $content, '', '300', 'Full', 'In', true, false, 'ace', 0, '99%');
  5037. print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ? GETPOST('format', 'aZ09') : 'html'));
  5038. print '<br>';
  5039. print '<center>';
  5040. print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
  5041. print ' &nbsp; ';
  5042. print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
  5043. print '</center>';
  5044. print '</form>';
  5045. }
  5046. }
  5047. if ($tab == 'triggers') {
  5048. print '<!-- tab=triggers -->'."\n";
  5049. require_once DOL_DOCUMENT_ROOT.'/core/class/interfaces.class.php';
  5050. $interfaces = new Interfaces($db);
  5051. $triggers = $interfaces->getTriggersList(array('/'.strtolower($module).'/core/triggers'));
  5052. if ($action != 'editfile' || empty($file)) {
  5053. print '<span class="opacitymedium">'.$langs->trans("TriggerDefDesc").'</span><br>';
  5054. print '<br>';
  5055. print '<table>';
  5056. $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
  5057. print '<tr><td>';
  5058. print '<span class="fa fa-file-o"></span> '.$langs->trans("DescriptorFile").' : <strong class="wordbreak">'.$pathtofile.'</strong>';
  5059. print '</td><td>';
  5060. print '<a class="editfielda paddingleft paddingright" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&token='.newToken().'&format=php&file='.urlencode($pathtofile).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
  5061. print '</td></tr>';
  5062. if (!empty($triggers)) {
  5063. foreach ($triggers as $trigger) {
  5064. $pathtofile = $trigger['relpath'];
  5065. print '<tr><td>';
  5066. print '<span class="fa fa-file-o"></span> '.$langs->trans("TriggersFile").' : <strong class="wordbreak">'.$pathtofile.'</strong>';
  5067. print '</td><td><a class="editfielda paddingleft paddingright" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&token='.newToken().'&format=php&file='.urlencode($pathtofile).'">'.img_picto($langs->trans("Edit"), 'edit').'</a></td>';
  5068. print '<td><a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=confirm_removefile&token='.newToken().'&file='.urlencode($pathtofile).'">'.img_picto($langs->trans("Delete"), 'delete').'</a></td>';
  5069. print '</tr>';
  5070. }
  5071. } else {
  5072. print '<tr><td>';
  5073. print '<span class="fa fa-file-o"></span> '.$langs->trans("TriggersFile");
  5074. print ' : <span class="opacitymedium">'.$langs->trans("FileNotYetGenerated").'</span>';
  5075. print '<a href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=inittrigger&format=php">'.img_picto('Generate', 'generate', 'class="paddingleft"').'</a></td>';
  5076. print '<td></td>';
  5077. print '</tr>';
  5078. }
  5079. print '</table>';
  5080. } else {
  5081. $fullpathoffile = dol_buildpath($file, 0);
  5082. $content = file_get_contents($fullpathoffile);
  5083. // New module
  5084. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  5085. print '<input type="hidden" name="token" value="'.newToken().'">';
  5086. print '<input type="hidden" name="action" value="savefile">';
  5087. print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
  5088. print '<input type="hidden" name="tab" value="'.$tab.'">';
  5089. print '<input type="hidden" name="module" value="'.$module.'">';
  5090. $doleditor = new DolEditor('editfilecontent', $content, '', '300', 'Full', 'In', true, false, 'ace', 0, '99%');
  5091. print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ? GETPOST('format', 'aZ09') : 'html'));
  5092. print '<br>';
  5093. print '<center>';
  5094. print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
  5095. print ' &nbsp; ';
  5096. print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
  5097. print '</center>';
  5098. print '</form>';
  5099. }
  5100. }
  5101. if ($tab == 'css') {
  5102. print '<!-- tab=css -->'."\n";
  5103. if ($action != 'editfile' || empty($file)) {
  5104. print '<span class="opacitymedium">'.$langs->trans("CSSDesc").'</span><br>';
  5105. print '<br>';
  5106. print '<table>';
  5107. print '<tr><td>';
  5108. $pathtohook = strtolower($module).'/css/'.strtolower($module).'.css.php';
  5109. print '<span class="fa fa-file-o"></span> '.$langs->trans("CSSFile").' : ';
  5110. if (dol_is_file($dirins.'/'.$pathtohook)) {
  5111. print '<strong class="wordbreak">'.$pathtohook.'</strong>';
  5112. print '</td><td><a class="editfielda paddingleft paddingright" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&token='.newToken().'&format=php&file='.urlencode($pathtohook).'">'.img_picto($langs->trans("Edit"), 'edit').'</a></td>';
  5113. print '</td><td><a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=confirm_removefile&token='.newToken().'&format='.$format.'&file='.urlencode($pathtohook).'">'.img_picto($langs->trans("Delete"), 'delete').'</a></td>';
  5114. } else {
  5115. print '<span class="opacitymedium">'.$langs->trans("FileNotYetGenerated").'</span>';
  5116. print '</td><td><a href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=initcss&format=php&file='.urlencode($pathtohook).'">'.img_picto('Generate', 'generate', 'class="paddingleft"').'</a></td>';
  5117. }
  5118. print '</tr>';
  5119. } else {
  5120. $fullpathoffile = dol_buildpath($file, 0);
  5121. $content = file_get_contents($fullpathoffile);
  5122. // New module
  5123. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  5124. print '<input type="hidden" name="token" value="'.newToken().'">';
  5125. print '<input type="hidden" name="action" value="savefile">';
  5126. print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
  5127. print '<input type="hidden" name="tab" value="'.$tab.'">';
  5128. print '<input type="hidden" name="module" value="'.$module.'">';
  5129. $doleditor = new DolEditor('editfilecontent', $content, '', '300', 'Full', 'In', true, false, 'ace', 0, '99%');
  5130. print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ? GETPOST('format', 'aZ09') : 'html'));
  5131. print '<br>';
  5132. print '<center>';
  5133. print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
  5134. print ' &nbsp; ';
  5135. print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
  5136. print '</center>';
  5137. print '</form>';
  5138. }
  5139. }
  5140. if ($tab == 'js') {
  5141. print '<!-- tab=js -->'."\n";
  5142. if ($action != 'editfile' || empty($file)) {
  5143. print '<span class="opacitymedium">'.$langs->trans("JSDesc").'</span><br>';
  5144. print '<br>';
  5145. print '<table>';
  5146. print '<tr><td>';
  5147. $pathtohook = strtolower($module).'/js/'.strtolower($module).'.js.php';
  5148. print '<span class="fa fa-file-o"></span> '.$langs->trans("JSFile").' : ';
  5149. if (dol_is_file($dirins.'/'.$pathtohook)) {
  5150. print '<strong class="wordbreak">'.$pathtohook.'</strong>';
  5151. print '</td><td><a class="editfielda paddingleft paddingright" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&token='.newToken().'&format=php&file='.urlencode($pathtohook).'">'.img_picto($langs->trans("Edit"), 'edit').'</a></td>';
  5152. print '</td><td><a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=confirm_removefile&token='.newToken().'&file='.urlencode($pathtohook).'">'.img_picto($langs->trans("Delete"), 'delete').'</a></td>';
  5153. } else {
  5154. print '<span class="opacitymedium">'.$langs->trans("FileNotYetGenerated").'</span>';
  5155. print '</td><td><a href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=initjs&token='.newToken().'&format=php&file='.urlencode($pathtohook).'">'.img_picto('Generate', 'generate', 'class="paddingleft"').'</a></td>';
  5156. }
  5157. print '</tr>';
  5158. } else {
  5159. $fullpathoffile = dol_buildpath($file, 0);
  5160. $content = file_get_contents($fullpathoffile);
  5161. // New module
  5162. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  5163. print '<input type="hidden" name="token" value="'.newToken().'">';
  5164. print '<input type="hidden" name="action" value="savefile">';
  5165. print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
  5166. print '<input type="hidden" name="tab" value="'.$tab.'">';
  5167. print '<input type="hidden" name="module" value="'.$module.'">';
  5168. $doleditor = new DolEditor('editfilecontent', $content, '', '300', 'Full', 'In', true, false, 'ace', 0, '99%');
  5169. print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ? GETPOST('format', 'aZ09') : 'html'));
  5170. print '<br>';
  5171. print '<center>';
  5172. print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
  5173. print ' &nbsp; ';
  5174. print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
  5175. print '</center>';
  5176. print '</form>';
  5177. }
  5178. }
  5179. if ($tab == 'widgets') {
  5180. print '<!-- tab=widgets -->'."\n";
  5181. require_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
  5182. $widgets = ModeleBoxes::getWidgetsList(array('/'.strtolower($module).'/core/boxes'));
  5183. if ($action != 'editfile' || empty($file)) {
  5184. print '<span class="opacitymedium">'.$langs->trans("WidgetDesc").'</span><br>';
  5185. print '<br>';
  5186. print '<table>';
  5187. if (!empty($widgets)) {
  5188. foreach ($widgets as $widget) {
  5189. $pathtofile = $widget['relpath'];
  5190. print '<tr><td><span class="fa fa-file-o"></span> '.$langs->trans("WidgetFile").' : <strong class="wordbreak">'.$pathtofile.'</strong>';
  5191. print '</td><td><a class="editfielda paddingleft paddingright" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&token='.newToken().'&format=php&file='.urlencode($pathtofile).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
  5192. print '</td><td><a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=confirm_removefile&token='.newToken().'&file='.urlencode($pathtofile).'">'.img_picto($langs->trans("Delete"), 'delete').'</a></td>';
  5193. print '</tr>';
  5194. }
  5195. } else {
  5196. print '<tr><td><span class="fa fa-file-o"></span> '.$langs->trans("WidgetFile").' : <span class="opacitymedium">'.$langs->trans("NoWidget").'</span>';
  5197. print '</td><td><a href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=initwidget&token='.newToken().'&format=php">'.img_picto('Generate', 'generate', 'class="paddingleft"').'</a>';
  5198. print '</td></tr>';
  5199. }
  5200. print '</table>';
  5201. } else {
  5202. $fullpathoffile = dol_buildpath($file, 0);
  5203. $content = file_get_contents($fullpathoffile);
  5204. // New module
  5205. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  5206. print '<input type="hidden" name="token" value="'.newToken().'">';
  5207. print '<input type="hidden" name="action" value="savefile">';
  5208. print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
  5209. print '<input type="hidden" name="tab" value="'.$tab.'">';
  5210. print '<input type="hidden" name="module" value="'.$module.'">';
  5211. $doleditor = new DolEditor('editfilecontent', $content, '', '300', 'Full', 'In', true, false, 'ace', 0, '99%');
  5212. print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ? GETPOST('format', 'aZ09') : 'html'));
  5213. print '<br>';
  5214. print '<center>';
  5215. print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
  5216. print ' &nbsp; ';
  5217. print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
  5218. print '</center>';
  5219. print '</form>';
  5220. }
  5221. }
  5222. if ($tab == 'exportimport') {
  5223. print '<!-- tab=exportimport -->'."\n";
  5224. $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
  5225. $exportlist = $moduleobj->export_label;
  5226. $importlist = $moduleobj->import_label;
  5227. if ($action != 'editfile' || empty($file)) {
  5228. print '<span class="opacitymedium">'.$langs->transnoentities('ImportExportProfiles').'</span><br>';
  5229. print '<br>';
  5230. print '<span class="fa fa-file-o"></span> '.$langs->trans("DescriptorFile").' : <strong class="wordbreak">'.$pathtofile.'</strong>';
  5231. print ' <a class="editfielda paddingleft paddingright" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&token='.newToken().'&format=php&file='.urlencode($pathtofile).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
  5232. print '<br>';
  5233. } else {
  5234. $fullpathoffile = dol_buildpath($file, 0);
  5235. $content = file_get_contents($fullpathoffile);
  5236. // New module
  5237. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  5238. print '<input type="hidden" name="token" value="'.newToken().'">';
  5239. print '<input type="hidden" name="action" value="savefile">';
  5240. print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
  5241. print '<input type="hidden" name="tab" value="'.$tab.'">';
  5242. print '<input type="hidden" name="module" value="'.$module.'">';
  5243. $doleditor = new DolEditor('editfilecontent', $content, '', '300', 'Full', 'In', true, false, 'ace', 0, '99%');
  5244. print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ? GETPOST('format', 'aZ09') : 'html'));
  5245. print '<br>';
  5246. print '<center>';
  5247. print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
  5248. print ' &nbsp; ';
  5249. print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
  5250. print '</center>';
  5251. print '</form>';
  5252. }
  5253. }
  5254. if ($tab == 'cli') {
  5255. print '<!-- tab=cli -->'."\n";
  5256. $clifiles = array();
  5257. $i = 0;
  5258. $dircli = array('/'.strtolower($module).'/scripts');
  5259. foreach ($dircli as $reldir) {
  5260. $dir = dol_buildpath($reldir, 0);
  5261. $newdir = dol_osencode($dir);
  5262. // Check if directory exists (we do not use dol_is_dir to avoid loading files.lib.php at each call)
  5263. if (!is_dir($newdir)) {
  5264. continue;
  5265. }
  5266. $handle = opendir($newdir);
  5267. if (is_resource($handle)) {
  5268. while (($tmpfile = readdir($handle)) !== false) {
  5269. if (is_readable($newdir.'/'.$tmpfile) && preg_match('/^(.+)\.php/', $tmpfile, $reg)) {
  5270. if (preg_match('/\.back$/', $tmpfile)) {
  5271. continue;
  5272. }
  5273. $clifiles[$i]['relpath'] = preg_replace('/^\//', '', $reldir).'/'.$tmpfile;
  5274. $i++;
  5275. }
  5276. }
  5277. closedir($handle);
  5278. }
  5279. }
  5280. if ($action != 'editfile' || empty($file)) {
  5281. print '<span class="opacitymedium">'.$langs->trans("CLIDesc").'</span><br>';
  5282. print '<br>';
  5283. print '<table>';
  5284. if (!empty($clifiles)) {
  5285. foreach ($clifiles as $clifile) {
  5286. $pathtofile = $clifile['relpath'];
  5287. print '<tr><td><span class="fa fa-file-o"></span> '.$langs->trans("CLIFile").' : <strong class="wordbreak">'.$pathtofile.'</strong>';
  5288. print '</td><td><a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&token='.newToken().'&format=php&file='.urlencode($pathtofile).'">'.img_picto($langs->trans("Edit"), 'edit').'</a></td>';
  5289. print '<td><a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=confirm_removefile&token='.newToken().'&file='.urlencode($pathtofile).'">'.img_picto($langs->trans("Delete"), 'delete').'</a></td>';
  5290. print '</tr>';
  5291. }
  5292. } else {
  5293. print '<tr><td><span class="fa fa-file-o"></span> '.$langs->trans("CLIFile").' : <span class="opacitymedium">'.$langs->trans("FileNotYetGenerated").'</span>';
  5294. print '</td><td><a href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=initcli&token='.newToken().'&format=php">'.img_picto('Generate', 'generate', 'class="paddingleft"').'</a>';
  5295. print '</td></tr>';
  5296. }
  5297. print '</table>';
  5298. } else {
  5299. $fullpathoffile = dol_buildpath($file, 0);
  5300. $content = file_get_contents($fullpathoffile);
  5301. // New module
  5302. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  5303. print '<input type="hidden" name="token" value="'.newToken().'">';
  5304. print '<input type="hidden" name="action" value="savefile">';
  5305. print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
  5306. print '<input type="hidden" name="tab" value="'.$tab.'">';
  5307. print '<input type="hidden" name="module" value="'.$module.'">';
  5308. $doleditor = new DolEditor('editfilecontent', $content, '', '300', 'Full', 'In', true, false, 'ace', 0, '99%');
  5309. print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ? GETPOST('format', 'aZ09') : 'html'));
  5310. print '<br>';
  5311. print '<center>';
  5312. print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
  5313. print ' &nbsp; ';
  5314. print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
  5315. print '</center>';
  5316. print '</form>';
  5317. }
  5318. }
  5319. if ($tab == 'cron') {
  5320. print '<!-- tab=cron -->'."\n";
  5321. $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
  5322. $cronjobs = $moduleobj->cronjobs;
  5323. if ($action != 'editfile' || empty($file)) {
  5324. 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>';
  5325. print '<br>';
  5326. print '<span class="fa fa-file-o"></span> '.$langs->trans("DescriptorFile").' : <strong class="wordbreak">'.$pathtofile.'</strong>';
  5327. print ' <a class="editfielda paddingleft paddingright" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&token='.newToken().'&format=php&file='.urlencode($pathtofile).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
  5328. print '<br>';
  5329. print '<br>';
  5330. print load_fiche_titre($langs->trans("CronJobProfiles"), '', '');
  5331. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  5332. print '<input type="hidden" name="token" value="'.newToken().'">';
  5333. print '<input type="hidden" name="action" value="addproperty">';
  5334. print '<input type="hidden" name="tab" value="objects">';
  5335. print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
  5336. print '<input type="hidden" name="tabobj" value="'.dol_escape_htmltag($tabobj).'">';
  5337. print '<div class="div-table-responsive">';
  5338. print '<table class="noborder">';
  5339. print '<tr class="liste_titre">';
  5340. print_liste_field_titre("CronLabel", $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder);
  5341. print_liste_field_titre("CronTask", '', '', "", $param, '', $sortfield, $sortorder);
  5342. print_liste_field_titre("CronFrequency", '', "", "", $param, '', $sortfield, $sortorder);
  5343. print_liste_field_titre("StatusAtInstall", $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder);
  5344. print_liste_field_titre("Comment", $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder);
  5345. print "</tr>\n";
  5346. if (count($cronjobs)) {
  5347. foreach ($cronjobs as $cron) {
  5348. print '<tr class="oddeven">';
  5349. print '<td>';
  5350. print $cron['label'];
  5351. print '</td>';
  5352. print '<td>';
  5353. if ($cron['jobtype'] == 'method') {
  5354. $text = $langs->trans("CronClass");
  5355. $texttoshow = $langs->trans('CronModule').': '.$module.'<br>';
  5356. $texttoshow .= $langs->trans('CronClass').': '.$cron['class'].'<br>';
  5357. $texttoshow .= $langs->trans('CronObject').': '.$cron['objectname'].'<br>';
  5358. $texttoshow .= $langs->trans('CronMethod').': '.$cron['method'];
  5359. $texttoshow .= '<br>'.$langs->trans('CronArgs').': '.$cron['parameters'];
  5360. $texttoshow .= '<br>'.$langs->trans('Comment').': '.$langs->trans($cron['comment']);
  5361. } elseif ($cron['jobtype'] == 'command') {
  5362. $text = $langs->trans('CronCommand');
  5363. $texttoshow = $langs->trans('CronCommand').': '.dol_trunc($cron['command']);
  5364. $texttoshow .= '<br>'.$langs->trans('CronArgs').': '.$cron['parameters'];
  5365. $texttoshow .= '<br>'.$langs->trans('Comment').': '.$langs->trans($cron['comment']);
  5366. }
  5367. print $form->textwithpicto($text, $texttoshow, 1);
  5368. print '</td>';
  5369. print '<td>';
  5370. if ($cron['unitfrequency'] == "60") {
  5371. print $langs->trans('CronEach')." ".($cron['frequency'])." ".$langs->trans('Minutes');
  5372. }
  5373. if ($cron['unitfrequency'] == "3600") {
  5374. print $langs->trans('CronEach')." ".($cron['frequency'])." ".$langs->trans('Hours');
  5375. }
  5376. if ($cron['unitfrequency'] == "86400") {
  5377. print $langs->trans('CronEach')." ".($cron['frequency'])." ".$langs->trans('Days');
  5378. }
  5379. if ($cron['unitfrequency'] == "604800") {
  5380. print $langs->trans('CronEach')." ".($cron['frequency'])." ".$langs->trans('Weeks');
  5381. }
  5382. print '</td>';
  5383. print '<td>';
  5384. print $cron['status'];
  5385. print '</td>';
  5386. print '<td>';
  5387. if (!empty($cron['comment'])) {
  5388. print $cron['comment'];
  5389. }
  5390. print '</td>';
  5391. print '</tr>';
  5392. }
  5393. } else {
  5394. print '<tr><td colspan="5"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
  5395. }
  5396. print '</table>';
  5397. print '</div>';
  5398. print '</form>';
  5399. } else {
  5400. $fullpathoffile = dol_buildpath($file, 0);
  5401. $content = file_get_contents($fullpathoffile);
  5402. // New module
  5403. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  5404. print '<input type="hidden" name="token" value="'.newToken().'">';
  5405. print '<input type="hidden" name="action" value="savefile">';
  5406. print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
  5407. print '<input type="hidden" name="tab" value="'.$tab.'">';
  5408. print '<input type="hidden" name="module" value="'.$module.'">';
  5409. $doleditor = new DolEditor('editfilecontent', $content, '', '300', 'Full', 'In', true, false, 'ace', 0, '99%');
  5410. print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ? GETPOST('format', 'aZ09') : 'html'));
  5411. print '<br>';
  5412. print '<center>';
  5413. print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
  5414. print ' &nbsp; ';
  5415. print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
  5416. print '</center>';
  5417. print '</form>';
  5418. }
  5419. }
  5420. if ($tab == 'specifications') {
  5421. print '<!-- tab=specifications -->'."\n";
  5422. $specs = dol_dir_list(dol_buildpath($modulelowercase.'/doc', 0), 'files', 1, '(\.md|\.asciidoc)$', array('\/temp\/'));
  5423. if ($action != 'editfile' || empty($file)) {
  5424. print '<span class="opacitymedium">'.$langs->trans("SpecDefDesc").'</span><br>';
  5425. print '<br>';
  5426. print '<table>';
  5427. if (is_array($specs) && !empty($specs)) {
  5428. foreach ($specs as $spec) {
  5429. $pathtofile = $modulelowercase.'/doc/'.$spec['relativename'];
  5430. $format = 'asciidoc';
  5431. if (preg_match('/\.md$/i', $spec['name'])) {
  5432. $format = 'markdown';
  5433. }
  5434. print '<tr><td>';
  5435. print '<span class="fa fa-file-o"></span> '.$langs->trans("SpecificationFile").' : <strong class="wordbreak">'.$pathtofile.'</strong>';
  5436. print '</td><td><a class="editfielda paddingleft paddingright" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&token='.newToken().'&format='.$format.'&file='.urlencode($pathtofile).'">'.img_picto($langs->trans("Edit"), 'edit').'</a></td>';
  5437. print '<td><a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=confirm_removefile&token='.newToken().'&format='.$format.'&file='.urlencode($pathtofile).'">'.img_picto($langs->trans("Delete"), 'delete').'</a></td>';
  5438. print '</tr>';
  5439. }
  5440. } else {
  5441. print '<tr><td>';
  5442. print '<span class="fa fa-file-o"></span> '.$langs->trans("SpecificationFile").' : <span class="opacitymedium">'.$langs->trans("FileNotYetGenerated").'</span>';
  5443. print '</td><td><a href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=initdoc&token='.newToken().'&format=php">'.img_picto('Generate', 'generate', 'class="paddingleft"').'</a></td>';
  5444. print '</tr>';
  5445. }
  5446. print '</table>';
  5447. } else {
  5448. // Use MD or asciidoc
  5449. //print $langs->trans("UseAsciiDocFormat").'<br>';
  5450. $fullpathoffile = dol_buildpath($file, 0);
  5451. $content = file_get_contents($fullpathoffile);
  5452. // New module
  5453. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  5454. print '<input type="hidden" name="token" value="'.newToken().'">';
  5455. print '<input type="hidden" name="action" value="savefile">';
  5456. print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
  5457. print '<input type="hidden" name="tab" value="'.$tab.'">';
  5458. print '<input type="hidden" name="module" value="'.$module.'">';
  5459. $doleditor = new DolEditor('editfilecontent', $content, '', '300', 'Full', 'In', true, false, 'ace', 0, '99%');
  5460. print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ? GETPOST('format', 'aZ09') : 'html'));
  5461. print '<br>';
  5462. print '<center>';
  5463. print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
  5464. print ' &nbsp; ';
  5465. print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
  5466. print '</center>';
  5467. print '</form>';
  5468. }
  5469. print '<br><br><br>';
  5470. $FILENAMEDOC = $modulelowercase.'.html';
  5471. $FILENAMEDOCPDF = $modulelowercase.'.pdf';
  5472. $outputfiledoc = dol_buildpath($modulelowercase, 0).'/doc/'.$FILENAMEDOC;
  5473. $outputfiledocurl = dol_buildpath($modulelowercase, 1).'/doc/'.$FILENAMEDOC;
  5474. $outputfiledocrel = $modulelowercase.'/doc/'.$FILENAMEDOC;
  5475. $outputfiledocpdf = dol_buildpath($modulelowercase, 0).'/doc/'.$FILENAMEDOCPDF;
  5476. $outputfiledocurlpdf = dol_buildpath($modulelowercase, 1).'/doc/'.$FILENAMEDOCPDF;
  5477. $outputfiledocrelpdf = $modulelowercase.'/doc/'.$FILENAMEDOCPDF;
  5478. // HTML
  5479. print '<span class="fa fa-file-o"></span> '.$langs->trans("PathToModuleDocumentation", "HTML").' : ';
  5480. if (!dol_is_file($outputfiledoc)) {
  5481. print '<span class="opacitymedium">'.$langs->trans("FileNotYetGenerated").'</span>';
  5482. } else {
  5483. print '<strong>';
  5484. print '<a href="'.$outputfiledocurl.'" target="_blank" rel="noopener noreferrer">';
  5485. print $outputfiledoc;
  5486. print '</a>';
  5487. print '</strong>';
  5488. print ' <span class="opacitymedium">('.$langs->trans("GeneratedOn").' '.dol_print_date(dol_filemtime($outputfiledoc), 'dayhour').')</span>';
  5489. print ' <a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=confirm_removefile&token='.newToken().'&format='.$format.'&file='.urlencode($outputfiledocrel).'">'.img_picto($langs->trans("Delete"), 'delete').'</a>';
  5490. }
  5491. print '</strong><br>';
  5492. // PDF
  5493. print '<span class="fa fa-file-o"></span> '.$langs->trans("PathToModuleDocumentation", "PDF").' : ';
  5494. if (!dol_is_file($outputfiledocpdf)) {
  5495. print '<span class="opacitymedium">'.$langs->trans("FileNotYetGenerated").'</span>';
  5496. } else {
  5497. print '<strong>';
  5498. print '<a href="'.$outputfiledocurlpdf.'" target="_blank" rel="noopener noreferrer">';
  5499. print $outputfiledocpdf;
  5500. print '</a>';
  5501. print '</strong>';
  5502. print ' <span class="opacitymedium">('.$langs->trans("GeneratedOn").' '.dol_print_date(dol_filemtime($outputfiledocpdf), 'dayhour').')</span>';
  5503. print ' <a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=confirm_removefile&token='.newToken().'&format='.$format.'&file='.urlencode($outputfiledocrelpdf).'">'.img_picto($langs->trans("Delete"), 'delete').'</a>';
  5504. }
  5505. print '</strong><br>';
  5506. print '<br>';
  5507. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST" name="generatedoc">';
  5508. print '<input type="hidden" name="token" value="'.newToken().'">';
  5509. print '<input type="hidden" name="action" value="generatedoc">';
  5510. print '<input type="hidden" name="tab" value="'.dol_escape_htmltag($tab).'">';
  5511. print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
  5512. print '<input type="submit" class="button" name="generatedoc" value="'.$langs->trans("BuildDocumentation").'"';
  5513. if (!is_array($specs) || empty($specs)) {
  5514. print ' disabled="disabled"';
  5515. }
  5516. print '>';
  5517. print '</form>';
  5518. }
  5519. if ($tab == 'buildpackage') {
  5520. print '<!-- tab=buildpackage -->'."\n";
  5521. print '<span class="opacitymedium">'.$langs->trans("BuildPackageDesc").'</span>';
  5522. print '<br>';
  5523. if (!class_exists('ZipArchive') && !defined('ODTPHP_PATHTOPCLZIP')) {
  5524. print img_warning().' '.$langs->trans("ErrNoZipEngine");
  5525. print '<br>';
  5526. }
  5527. $modulelowercase = strtolower($module);
  5528. // Zip file to build
  5529. $FILENAMEZIP = '';
  5530. // Load module
  5531. $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
  5532. dol_include_once($pathtofile);
  5533. $class = 'mod'.$module;
  5534. if (class_exists($class)) {
  5535. try {
  5536. $moduleobj = new $class($db);
  5537. } catch (Exception $e) {
  5538. $error++;
  5539. dol_print_error($db, $e->getMessage());
  5540. }
  5541. } else {
  5542. $error++;
  5543. $langs->load("errors");
  5544. dol_print_error($db, $langs->trans("ErrorFailedToLoadModuleDescriptorForXXX", $module));
  5545. exit;
  5546. }
  5547. $arrayversion = explode('.', $moduleobj->version, 3);
  5548. if (count($arrayversion)) {
  5549. $FILENAMEZIP = "module_".$modulelowercase.'-'.$arrayversion[0].(empty($arrayversion[1]) ? '.0' : '.'.$arrayversion[1]).(empty($arrayversion[2]) ? '' : ".".$arrayversion[2]).".zip";
  5550. $outputfilezip = dol_buildpath($modulelowercase, 0).'/bin/'.$FILENAMEZIP;
  5551. }
  5552. print '<br>';
  5553. print '<span class="fa fa-file-o"></span> '.$langs->trans("PathToModulePackage").' : ';
  5554. if (!dol_is_file($outputfilezip)) {
  5555. print '<span class="opacitymedium">'.$langs->trans("FileNotYetGenerated").'</span>';
  5556. } else {
  5557. $relativepath = $modulelowercase.'/bin/'.$FILENAMEZIP;
  5558. print '<strong><a href="'.DOL_URL_ROOT.'/document.php?modulepart=packages&file='.urlencode($relativepath).'">'.$outputfilezip.'</a></strong>';
  5559. print ' <span class="opacitymedium">('.$langs->trans("GeneratedOn").' '.dol_print_date(dol_filemtime($outputfilezip), 'dayhour').')</span>';
  5560. print ' <a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=confirm_removefile&token='.newToken().'&file='.urlencode($relativepath).'">'.img_picto($langs->trans("Delete"), 'delete').'</a>';
  5561. }
  5562. print '</strong>';
  5563. print '<br>';
  5564. print '<br>';
  5565. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST" name="generatepackage">';
  5566. print '<input type="hidden" name="token" value="'.newToken().'">';
  5567. print '<input type="hidden" name="action" value="generatepackage">';
  5568. print '<input type="hidden" name="tab" value="'.dol_escape_htmltag($tab).'">';
  5569. print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
  5570. print '<input type="submit" class="button" name="generatepackage" value="'.$langs->trans("BuildPackage").'">';
  5571. print '</form>';
  5572. }
  5573. if ($tab == 'tabs') {
  5574. $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
  5575. $tabs = $moduleobj->tabs;
  5576. if ($action != 'editfile' || empty($file)) {
  5577. print '<span class="opacitymedium">';
  5578. $htmlhelp = $langs->trans("TabsDefDescTooltip", '{s1}');
  5579. $htmlhelp = str_replace('{s1}', '<a target="adminbis" class="nofocusvisible" href="'.DOL_URL_ROOT.'/admin/menus/index.php">'.$langs->trans('Setup').' - '.$langs->trans('Tabs').'</a>', $htmlhelp);
  5580. print $form->textwithpicto($langs->trans("TabsDefDesc"), $htmlhelp, 1, 'help', '', 0, 2, 'helpondesc').'<br>';
  5581. print '</span>';
  5582. print '<br>';
  5583. print '<span class="fa fa-file-o"></span> '.$langs->trans("DescriptorFile").' : <strong>'.$pathtofile.'</strong>';
  5584. print ' <a class="editfielda paddingleft paddingright" href="'.$_SERVER['PHP_SELF'].'?tab='.urlencode($tab).'&module='.$module.($forceddirread ? '@'.$dirread : '').'&action=editfile&format=php&file='.urlencode($pathtofile).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
  5585. print '<br>';
  5586. print '<br>';
  5587. print load_fiche_titre($langs->trans("ListOfTabsEntries"), '', '');
  5588. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  5589. print '<input type="hidden" name="token" value="'.newToken().'">';
  5590. print '<input type="hidden" name="action" value="addproperty">';
  5591. print '<input type="hidden" name="tab" value="objects">';
  5592. print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
  5593. print '<input type="hidden" name="tabobj" value="'.dol_escape_htmltag($tabobj).'">';
  5594. print '<div class="div-table-responsive">';
  5595. print '<table class="noborder small">';
  5596. print '<tr class="liste_titre">';
  5597. print_liste_field_titre("ObjectType", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
  5598. print_liste_field_titre("Tab", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
  5599. print_liste_field_titre("Title", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
  5600. print_liste_field_titre("LangFile", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
  5601. print_liste_field_titre("Condition", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
  5602. print_liste_field_titre("Path", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
  5603. print "</tr>\n";
  5604. if (count($tabs)) {
  5605. foreach ($tabs as $tab) {
  5606. $parts = explode(':', $tab['data']);
  5607. $objectType = $parts[0];
  5608. $tabName = $parts[1];
  5609. $tabTitle = isset($parts[2]) ? $parts[2] : '';
  5610. $langFile = isset($parts[3]) ? $parts[3] : '';
  5611. $condition = isset($parts[4]) ? $parts[4] : '';
  5612. $path = isset($parts[5]) ? $parts[5] : '';
  5613. // If we want to remove the tab, then the format is 'objecttype:tabname:optionalcondition'
  5614. // See: https://wiki.dolibarr.org/index.php?title=Tabs_system#To_remove_an_existing_tab
  5615. if ($tabName[0] === '-') {
  5616. $tabTitle = '';
  5617. $condition = isset($parts[2]) ? $parts[2] : '';
  5618. }
  5619. print '<tr class="oddeven">';
  5620. print '<td>';
  5621. print dol_escape_htmltag($parts[0]);
  5622. print '</td>';
  5623. print '<td>';
  5624. if ($tabName[0] === "+") {
  5625. print '<span class="badge badge-status4 badge-status">' . dol_escape_htmltag($tabName) . '</span>';
  5626. } else {
  5627. print '<span class="badge badge-status8 badge-status">' . dol_escape_htmltag($tabName) . '</span>';
  5628. }
  5629. print '</td>';
  5630. print '<td>';
  5631. print dol_escape_htmltag($tabTitle);
  5632. print '</td>';
  5633. print '<td>';
  5634. print dol_escape_htmltag($langFile);
  5635. print '</td>';
  5636. print '<td>';
  5637. print dol_escape_htmltag($condition);
  5638. print '</td>';
  5639. print '<td>';
  5640. print dol_escape_htmltag($path);
  5641. print '</td>';
  5642. print '</tr>';
  5643. }
  5644. } else {
  5645. print '<tr><td colspan="5"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
  5646. }
  5647. print '</table>';
  5648. print '</div>';
  5649. print '</form>';
  5650. } else {
  5651. $fullpathoffile = dol_buildpath($file, 0);
  5652. $content = file_get_contents($fullpathoffile);
  5653. // New module
  5654. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  5655. print '<input type="hidden" name="token" value="'.newToken().'">';
  5656. print '<input type="hidden" name="action" value="savefile">';
  5657. print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
  5658. print '<input type="hidden" name="tab" value="'.$tab.'">';
  5659. print '<input type="hidden" name="module" value="'.$module.'">';
  5660. $doleditor = new DolEditor('editfilecontent', $content, '', '300', 'Full', 'In', true, false, 'ace', 0, '99%');
  5661. print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ? GETPOST('format', 'aZ09') : 'html'));
  5662. print '<br>';
  5663. print '<center>';
  5664. print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
  5665. print ' &nbsp; ';
  5666. print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
  5667. print '</center>';
  5668. print '</form>';
  5669. }
  5670. }
  5671. if ($tab != 'description') {
  5672. print dol_get_fiche_end();
  5673. }
  5674. }
  5675. }
  5676. print dol_get_fiche_end(); // End modules
  5677. // End of page
  5678. llxFooter();
  5679. $db->close();