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.'/ajax');
  249. dol_delete_dir_recursive($destdir.'/build/doxygen');
  250. dol_delete_dir_recursive($destdir.'/core/modules/mailings');
  251. dol_delete_dir_recursive($destdir.'/core/modules/'.strtolower($modulename));
  252. dol_delete_dir_recursive($destdir.'/core/tpl');
  253. dol_delete_dir_recursive($destdir.'/core/triggers');
  254. dol_delete_dir_recursive($destdir.'/doc');
  255. //dol_delete_dir_recursive($destdir.'/.tx');
  256. dol_delete_dir_recursive($destdir.'/core/boxes');
  257. dol_delete_file($destdir.'/admin/myobject_extrafields.php');
  258. dol_delete_file($destdir.'/class/actions_'.strtolower($modulename).'.class.php');
  259. dol_delete_file($destdir.'/class/api_'.strtolower($modulename).'.class.php');
  260. dol_delete_file($destdir.'/css/'.strtolower($modulename).'.css.php');
  261. dol_delete_file($destdir.'/js/'.strtolower($modulename).'.js.php');
  262. dol_delete_file($destdir.'/scripts/'.strtolower($modulename).'.php');
  263. dol_delete_file($destdir.'/sql/data.sql');
  264. dol_delete_file($destdir.'/sql/update_x.x.x-y.y.y.sql');
  265. // Delete some files related to Object (because the previous dolCopyDir has copied everything)
  266. dol_delete_file($destdir.'/myobject_card.php');
  267. dol_delete_file($destdir.'/myobject_contact.php');
  268. dol_delete_file($destdir.'/myobject_note.php');
  269. dol_delete_file($destdir.'/myobject_document.php');
  270. dol_delete_file($destdir.'/myobject_agenda.php');
  271. dol_delete_file($destdir.'/myobject_list.php');
  272. dol_delete_file($destdir.'/lib/'.strtolower($modulename).'_myobject.lib.php');
  273. dol_delete_file($destdir.'/test/phpunit/functional/'.$modulename.'FunctionalTest.php');
  274. dol_delete_file($destdir.'/test/phpunit/MyObjectTest.php');
  275. dol_delete_file($destdir.'/sql/llx_'.strtolower($modulename).'_myobject.sql');
  276. dol_delete_file($destdir.'/sql/llx_'.strtolower($modulename).'_myobject_extrafields.sql');
  277. dol_delete_file($destdir.'/sql/llx_'.strtolower($modulename).'_myobject.key.sql');
  278. dol_delete_file($destdir.'/sql/llx_'.strtolower($modulename).'_myobject_extrafields.key.sql');
  279. dol_delete_file($destdir.'/class/myobject.class.php');
  280. dol_delete_dir($destdir.'/class', 1);
  281. dol_delete_dir($destdir.'/css', 1);
  282. dol_delete_dir($destdir.'/js', 1);
  283. dol_delete_dir($destdir.'/scripts', 1);
  284. dol_delete_dir($destdir.'/sql', 1);
  285. dol_delete_dir($destdir.'/test/phpunit/functionnal', 1);
  286. dol_delete_dir($destdir.'/test/phpunit', 1);
  287. dol_delete_dir($destdir.'/test', 1);
  288. }
  289. // Edit PHP files
  290. if (!$error) {
  291. $listofphpfilestoedit = dol_dir_list($destdir, 'files', 1, '\.(php|MD|js|sql|txt|xml|lang)$', '', 'fullname', SORT_ASC, 0, 1);
  292. foreach ($listofphpfilestoedit as $phpfileval) {
  293. //var_dump($phpfileval['fullname']);
  294. $arrayreplacement = array(
  295. 'mymodule'=>strtolower($modulename),
  296. 'MyModule'=>$modulename,
  297. 'MYMODULE'=>strtoupper($modulename),
  298. 'My module'=>$modulename,
  299. 'my module'=>$modulename,
  300. 'Mon module'=>$modulename,
  301. 'mon module'=>$modulename,
  302. 'htdocs/modulebuilder/template'=>strtolower($modulename),
  303. '---Put here your own copyright and developer email---'=>dol_print_date($now, '%Y').' '.$user->getFullName($langs).($user->email ? ' <'.$user->email.'>' : ''),
  304. 'Editor name'=>$editorname,
  305. 'https://www.example.com'=>$editorurl,
  306. '$this->version = \'1.0\''=>'$this->version = \''.$version.'\'',
  307. '$this->picto = \'generic\';'=>(empty($picto)) ? '$this->picto = \'generic\'' : '$this->picto = \''.$picto.'\';',
  308. "modulefamily" =>$family,
  309. '500000'=>$idmodule
  310. );
  311. if (getDolGlobalString('MODULEBUILDER_SPECIFIC_AUTHOR')) {
  312. $arrayreplacement['---Put here your own copyright and developer email---'] = dol_print_date($now, '%Y').' ' . getDolGlobalString('MODULEBUILDER_SPECIFIC_AUTHOR');
  313. }
  314. $result = dolReplaceInFile($phpfileval['fullname'], $arrayreplacement);
  315. //var_dump($result);
  316. if ($result < 0) {
  317. setEventMessages($langs->trans("ErrorFailToMakeReplacementInto", $phpfileval['fullname']), null, 'errors');
  318. }
  319. }
  320. if (getDolGlobalString('MODULEBUILDER_SPECIFIC_README')) {
  321. setEventMessages($langs->trans("ContentOfREADMECustomized"), null, 'warnings');
  322. dol_delete_file($destdir.'/README.md');
  323. file_put_contents($destdir.'/README.md', $conf->global->MODULEBUILDER_SPECIFIC_README);
  324. }
  325. // for create file to add properties
  326. // file_put_contents($destdir.'/'.strtolower($modulename).'propertycard.php','');
  327. // $srcFileCard = DOL_DOCUMENT_ROOT.'/modulebuilder/card.php';
  328. // $destFileCard = $dirins.'/'.strtolower($modulename).'/template/card.php';
  329. // dol_copy($srcFileCard, $destdir.'/'.strtolower($modulename).'propertycard.php', 0,1, $arrayreplacement);
  330. }
  331. if (!$error) {
  332. setEventMessages('ModuleInitialized', null);
  333. $module = $modulename;
  334. clearstatcache(true);
  335. if (function_exists('opcache_invalidate')) {
  336. opcache_reset(); // remove the include cache hell !
  337. }
  338. header("Location: ".$_SERVER["PHP_SELF"].'?module='.$modulename);
  339. exit;
  340. }
  341. }
  342. // init API, PHPUnit
  343. if ($dirins && in_array($action, array('initapi', 'initphpunit', 'initpagecontact', 'initpagedocument', 'initpagenote', 'initpageagenda')) && !empty($module)) {
  344. $modulename = ucfirst($module); // Force first letter in uppercase
  345. $objectname = $tabobj;
  346. $varnametoupdate = '';
  347. $dirins = $listofmodules[strtolower($module)]['moduledescriptorrootpath'];
  348. $destdir = $dirins.'/'.strtolower($module);
  349. // Get list of existing objects
  350. $objects = dolGetListOfObjectClasses($destdir);
  351. if ($action == 'initapi') {
  352. if (file_exists($dirins.'/'.strtolower($module).'/class/api_'.strtolower($module).'.class.php')) {
  353. $result = dol_copy(DOL_DOCUMENT_ROOT.'/modulebuilder/template/class/api_mymodule.class.php', $dirins.'/'.strtolower($module).'/class/api_'.strtolower($module).'.class.php', 0, 1);
  354. }
  355. dol_mkdir($dirins.'/'.strtolower($module).'/class');
  356. $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
  357. $srcfile = $srcdir.'/class/api_mymodule.class.php';
  358. $destfile = $dirins.'/'.strtolower($module).'/class/api_'.strtolower($module).'.class.php';
  359. } elseif ($action == 'initphpunit') {
  360. dol_mkdir($dirins.'/'.strtolower($module).'/test/phpunit');
  361. $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
  362. $srcfile = $srcdir.'/test/phpunit/MyObjectTest.php';
  363. $destfile = $dirins.'/'.strtolower($module).'/test/phpunit/'.strtolower($objectname).'Test.php';
  364. } elseif ($action == 'initpagecontact') {
  365. dol_mkdir($dirins.'/'.strtolower($module));
  366. $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
  367. $srcfile = $srcdir.'/myobject_contact.php';
  368. $destfile = $dirins.'/'.strtolower($module).'/'.strtolower($objectname).'_contact.php';
  369. $varnametoupdate = 'showtabofpagecontact';
  370. } elseif ($action == 'initpagedocument') {
  371. dol_mkdir($dirins.'/'.strtolower($module));
  372. $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
  373. $srcfile = $srcdir.'/myobject_document.php';
  374. $destfile = $dirins.'/'.strtolower($module).'/'.strtolower($objectname).'_document.php';
  375. $varnametoupdate = 'showtabofpagedocument';
  376. } elseif ($action == 'initpagenote') {
  377. dol_mkdir($dirins.'/'.strtolower($module));
  378. $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
  379. $srcfile = $srcdir.'/myobject_note.php';
  380. $destfile = $dirins.'/'.strtolower($module).'/'.strtolower($objectname).'_note.php';
  381. $varnametoupdate = 'showtabofpagenote';
  382. } elseif ($action == 'initpageagenda') {
  383. dol_mkdir($dirins.'/'.strtolower($module));
  384. $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
  385. $srcfile = $srcdir.'/myobject_agenda.php';
  386. $destfile = $dirins.'/'.strtolower($module).'/'.strtolower($objectname).'_agenda.php';
  387. $varnametoupdate = 'showtabofpageagenda';
  388. }
  389. //var_dump($srcfile);
  390. //var_dump($destfile);
  391. if (!file_exists($destfile)) {
  392. $result = dol_copy($srcfile, $destfile, 0, 0);
  393. }
  394. if ($result > 0) {
  395. //var_dump($phpfileval['fullname']);
  396. $arrayreplacement = array(
  397. 'mymodule'=>strtolower($modulename),
  398. 'MyModule'=>$modulename,
  399. 'MYMODULE'=>strtoupper($modulename),
  400. 'My module'=>$modulename,
  401. 'my module'=>$modulename,
  402. 'Mon module'=>$modulename,
  403. 'mon module'=>$modulename,
  404. 'htdocs/modulebuilder/template'=>strtolower($modulename),
  405. 'myobject'=>strtolower($objectname),
  406. 'MyObject'=>$objectname,
  407. 'MYOBJECT'=>strtoupper($objectname),
  408. '---Put here your own copyright and developer email---'=>dol_print_date($now, '%Y').' '.$user->getFullName($langs).($user->email ? ' <'.$user->email.'>' : '')
  409. );
  410. if (count($objects) > 1) {
  411. addObjectsToApiFile($destfile, $objects, $modulename);
  412. } else {
  413. dolReplaceInFile($destfile, $arrayreplacement);
  414. 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*/'));
  415. }
  416. if ($varnametoupdate) {
  417. // Now we update the object file to set $$varnametoupdate to 1
  418. $srcfile = $dirins.'/'.strtolower($module).'/lib/'.strtolower($module).'_'.strtolower($objectname).'.lib.php';
  419. $arrayreplacement = array('/\$'.preg_quote($varnametoupdate, '/').' = 0;/' => '$'.$varnametoupdate.' = 1;');
  420. dolReplaceInFile($srcfile, $arrayreplacement, '', 0, 0, 1);
  421. }
  422. } else {
  423. $langs->load("errors");
  424. setEventMessages($langs->trans('ErrorFailToCreateFile', $destfile), null, 'errors');
  425. }
  426. }
  427. // init ExtraFields
  428. if ($dirins && $action == 'initsqlextrafields' && !empty($module)) {
  429. $modulename = ucfirst($module); // Force first letter in uppercase
  430. $objectname = $tabobj;
  431. dol_mkdir($dirins.'/'.strtolower($module).'/sql');
  432. $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
  433. $srcfile1 = $srcdir.'/sql/llx_mymodule_myobject_extrafields.sql';
  434. $destfile1 = $dirins.'/'.strtolower($module).'/sql/llx_'.strtolower($module).'_'.strtolower($objectname).'_extrafields.sql';
  435. //var_dump($srcfile);
  436. //var_dump($destfile);
  437. $result1 = dol_copy($srcfile1, $destfile1, 0, 0);
  438. $srcfile2 = $srcdir.'/sql/llx_mymodule_myobject_extrafields.key.sql';
  439. $destfile2 = $dirins.'/'.strtolower($module).'/sql/llx_'.strtolower($module).'_'.strtolower($objectname).'_extrafields.key.sql';
  440. //var_dump($srcfile);
  441. //var_dump($destfile);
  442. $result2 = dol_copy($srcfile2, $destfile2, 0, 0);
  443. if ($result1 > 0 && $result2 > 0) {
  444. $modulename = ucfirst($module); // Force first letter in uppercase
  445. //var_dump($phpfileval['fullname']);
  446. $arrayreplacement = array(
  447. 'mymodule'=>strtolower($modulename),
  448. 'MyModule'=>$modulename,
  449. 'MYMODULE'=>strtoupper($modulename),
  450. 'My module'=>$modulename,
  451. 'my module'=>$modulename,
  452. 'Mon module'=>$modulename,
  453. 'mon module'=>$modulename,
  454. 'htdocs/modulebuilder/template'=>strtolower($modulename),
  455. 'My Object'=>$objectname,
  456. 'MyObject'=>$objectname,
  457. 'my object'=>strtolower($objectname),
  458. 'myobject'=>strtolower($objectname),
  459. '---Put here your own copyright and developer email---'=>dol_print_date($now, '%Y').' '.$user->getFullName($langs).($user->email ? ' <'.$user->email.'>' : '')
  460. );
  461. dolReplaceInFile($destfile1, $arrayreplacement);
  462. dolReplaceInFile($destfile2, $arrayreplacement);
  463. } else {
  464. $langs->load("errors");
  465. if ($result1 <= 0) {
  466. setEventMessages($langs->trans('ErrorFailToCreateFile', $destfile1), null, 'errors');
  467. }
  468. if ($result2 <= 0) {
  469. setEventMessages($langs->trans('ErrorFailToCreateFile', $destfile2), null, 'errors');
  470. }
  471. }
  472. // Now we update the object file to set $isextrafieldmanaged to 1
  473. $srcfile = $dirins.'/'.strtolower($module).'/class/'.strtolower($objectname).'.class.php';
  474. $arrayreplacement = array('/\$isextrafieldmanaged = 0;/' => '$isextrafieldmanaged = 1;');
  475. dolReplaceInFile($srcfile, $arrayreplacement, '', 0, 0, 1);
  476. }
  477. // init Hook
  478. if ($dirins && $action == 'inithook' && !empty($module)) {
  479. dol_mkdir($dirins.'/'.strtolower($module).'/class');
  480. $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
  481. $srcfile = $srcdir.'/class/actions_mymodule.class.php';
  482. $destfile = $dirins.'/'.strtolower($module).'/class/actions_'.strtolower($module).'.class.php';
  483. //var_dump($srcfile);
  484. //var_dump($destfile);
  485. $result = dol_copy($srcfile, $destfile, 0, 0);
  486. if ($result > 0) {
  487. $modulename = ucfirst($module); // Force first letter in uppercase
  488. //var_dump($phpfileval['fullname']);
  489. $arrayreplacement = array(
  490. 'mymodule'=>strtolower($modulename),
  491. 'MyModule'=>$modulename,
  492. 'MYMODULE'=>strtoupper($modulename),
  493. 'My module'=>$modulename,
  494. 'my module'=>$modulename,
  495. 'Mon module'=>$modulename,
  496. 'mon module'=>$modulename,
  497. 'htdocs/modulebuilder/template'=>strtolower($modulename),
  498. '---Put here your own copyright and developer email---'=>dol_print_date($now, '%Y').' '.$user->getFullName($langs).($user->email ? ' <'.$user->email.'>' : '')
  499. );
  500. dolReplaceInFile($destfile, $arrayreplacement);
  501. } else {
  502. $langs->load("errors");
  503. setEventMessages($langs->trans('ErrorFailToCreateFile', $destfile), null, 'errors');
  504. }
  505. }
  506. // init Trigger
  507. if ($dirins && $action == 'inittrigger' && !empty($module)) {
  508. dol_mkdir($dirins.'/'.strtolower($module).'/core/triggers');
  509. $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
  510. $srcfile = $srcdir.'/core/triggers/interface_99_modMyModule_MyModuleTriggers.class.php';
  511. $destfile = $dirins.'/'.strtolower($module).'/core/triggers/interface_99_mod'.$module.'_'.$module.'Triggers.class.php';
  512. //var_dump($srcfile);
  513. //var_dump($destfile);
  514. $result = dol_copy($srcfile, $destfile, 0, 0);
  515. if ($result > 0) {
  516. $modulename = ucfirst($module); // Force first letter in uppercase
  517. //var_dump($phpfileval['fullname']);
  518. $arrayreplacement = array(
  519. 'mymodule'=>strtolower($modulename),
  520. 'MyModule'=>$modulename,
  521. 'MYMODULE'=>strtoupper($modulename),
  522. 'My module'=>$modulename,
  523. 'my module'=>$modulename,
  524. 'Mon module'=>$modulename,
  525. 'mon module'=>$modulename,
  526. 'htdocs/modulebuilder/template'=>strtolower($modulename),
  527. '---Put here your own copyright and developer email---'=>dol_print_date($now, '%Y').' '.$user->getFullName($langs).($user->email ? ' <'.$user->email.'>' : '')
  528. );
  529. dolReplaceInFile($destfile, $arrayreplacement);
  530. } else {
  531. $langs->load("errors");
  532. setEventMessages($langs->trans('ErrorFailToCreateFile', $destfile), null, 'errors');
  533. }
  534. }
  535. // init Widget
  536. if ($dirins && $action == 'initwidget' && !empty($module)) {
  537. dol_mkdir($dirins.'/'.strtolower($module).'/core/boxes');
  538. $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
  539. $srcfile = $srcdir.'/core/boxes/mymodulewidget1.php';
  540. $destfile = $dirins.'/'.strtolower($module).'/core/boxes/'.strtolower($module).'widget1.php';
  541. //var_dump($srcfile);
  542. //var_dump($destfile);
  543. $result = dol_copy($srcfile, $destfile, 0, 0);
  544. if ($result > 0) {
  545. $modulename = ucfirst($module); // Force first letter in uppercase
  546. //var_dump($phpfileval['fullname']);
  547. $arrayreplacement = array(
  548. 'mymodule'=>strtolower($modulename),
  549. 'MyModule'=>$modulename,
  550. 'MYMODULE'=>strtoupper($modulename),
  551. 'My module'=>$modulename,
  552. 'my module'=>$modulename,
  553. 'Mon module'=>$modulename,
  554. 'mon module'=>$modulename,
  555. 'htdocs/modulebuilder/template'=>strtolower($modulename),
  556. '---Put here your own copyright and developer email---'=>dol_print_date($now, '%Y').' '.$user->getFullName($langs).($user->email ? ' <'.$user->email.'>' : '')
  557. );
  558. dolReplaceInFile($destfile, $arrayreplacement);
  559. } else {
  560. $langs->load("errors");
  561. setEventMessages($langs->trans('ErrorFailToCreateFile', $destfile), null, 'errors');
  562. }
  563. }
  564. // init CSS
  565. if ($dirins && $action == 'initcss' && !empty($module)) {
  566. dol_mkdir($dirins.'/'.strtolower($module).'/css');
  567. $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
  568. $srcfile = $srcdir.'/css/mymodule.css.php';
  569. $destfile = $dirins.'/'.strtolower($module).'/css/'.strtolower($module).'.css.php';
  570. //var_dump($srcfile);
  571. //var_dump($destfile);
  572. $result = dol_copy($srcfile, $destfile, 0, 0);
  573. if ($result > 0) {
  574. $modulename = ucfirst($module); // Force first letter in uppercase
  575. //var_dump($phpfileval['fullname']);
  576. $arrayreplacement = array(
  577. 'mymodule'=>strtolower($modulename),
  578. 'MyModule'=>$modulename,
  579. 'MYMODULE'=>strtoupper($modulename),
  580. 'My module'=>$modulename,
  581. 'my module'=>$modulename,
  582. 'Mon module'=>$modulename,
  583. 'mon module'=>$modulename,
  584. 'htdocs/modulebuilder/template'=>strtolower($modulename),
  585. '---Put here your own copyright and developer email---'=>dol_print_date($now, '%Y').' '.$user->getFullName($langs).($user->email ? ' <'.$user->email.'>' : ''),
  586. );
  587. dolReplaceInFile($destfile, $arrayreplacement);
  588. // Update descriptor file to uncomment file
  589. $srcfile = $dirins.'/'.strtolower($module).'/core/modules/mod'.$module.'.class.php';
  590. $arrayreplacement = array('/\/\/\s*\''.preg_quote('/'.strtolower($module).'/css/'.strtolower($module).'.css.php', '/').'\'/' => '\'/'.strtolower($module).'/css/'.strtolower($module).'.css.php\'');
  591. dolReplaceInFile($srcfile, $arrayreplacement, '', 0, 0, 1);
  592. } else {
  593. $langs->load("errors");
  594. setEventMessages($langs->trans('ErrorFailToCreateFile', $destfile), null, 'errors');
  595. }
  596. }
  597. // init JS
  598. if ($dirins && $action == 'initjs' && !empty($module)) {
  599. dol_mkdir($dirins.'/'.strtolower($module).'/js');
  600. $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
  601. $srcfile = $srcdir.'/js/mymodule.js.php';
  602. $destfile = $dirins.'/'.strtolower($module).'/js/'.strtolower($module).'.js.php';
  603. //var_dump($srcfile);
  604. //var_dump($destfile);
  605. $result = dol_copy($srcfile, $destfile, 0, 0);
  606. if ($result > 0) {
  607. $modulename = ucfirst($module); // Force first letter in uppercase
  608. //var_dump($phpfileval['fullname']);
  609. $arrayreplacement = array(
  610. 'mymodule'=>strtolower($modulename),
  611. 'MyModule'=>$modulename,
  612. 'MYMODULE'=>strtoupper($modulename),
  613. 'My module'=>$modulename,
  614. 'my module'=>$modulename,
  615. 'Mon module'=>$modulename,
  616. 'mon module'=>$modulename,
  617. 'htdocs/modulebuilder/template'=>strtolower($modulename),
  618. '---Put here your own copyright and developer email---'=>dol_print_date($now, '%Y').' '.$user->getFullName($langs).($user->email ? ' <'.$user->email.'>' : '')
  619. );
  620. dolReplaceInFile($destfile, $arrayreplacement);
  621. // Update descriptor file to uncomment file
  622. $srcfile = $dirins.'/'.strtolower($module).'/core/modules/mod'.$module.'.class.php';
  623. $arrayreplacement = array('/\/\/\s*\''.preg_quote('/'.strtolower($module).'/js/'.strtolower($module).'.js.php', '/').'\'/' => '\'/'.strtolower($module).'/js/'.strtolower($module).'.js.php\'');
  624. dolReplaceInFile($srcfile, $arrayreplacement, '', 0, 0, 1);
  625. } else {
  626. $langs->load("errors");
  627. setEventMessages($langs->trans('ErrorFailToCreateFile', $destfile), null, 'errors');
  628. }
  629. }
  630. // init CLI
  631. if ($dirins && $action == 'initcli' && !empty($module)) {
  632. dol_mkdir($dirins.'/'.strtolower($module).'/scripts');
  633. $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
  634. $srcfile = $srcdir.'/scripts/mymodule.php';
  635. $destfile = $dirins.'/'.strtolower($module).'/scripts/'.strtolower($module).'.php';
  636. //var_dump($srcfile);
  637. //var_dump($destfile);
  638. $result = dol_copy($srcfile, $destfile, 0, 0);
  639. if ($result > 0) {
  640. $modulename = ucfirst($module); // Force first letter in uppercase
  641. //var_dump($phpfileval['fullname']);
  642. $arrayreplacement = array(
  643. 'mymodule'=>strtolower($modulename),
  644. 'MyModule'=>$modulename,
  645. 'MYMODULE'=>strtoupper($modulename),
  646. 'My module'=>$modulename,
  647. 'my module'=>$modulename,
  648. 'Mon module'=>$modulename,
  649. 'mon module'=>$modulename,
  650. 'htdocs/modulebuilder/template'=>strtolower($modulename),
  651. '__MYCOMPANY_NAME__'=>$mysoc->name,
  652. '__KEYWORDS__'=>$modulename,
  653. '__USER_FULLNAME__'=>$user->getFullName($langs),
  654. '__USER_EMAIL__'=>$user->email,
  655. '__YYYY-MM-DD__'=>dol_print_date($now, 'dayrfc'),
  656. '---Put here your own copyright and developer email---'=>dol_print_date($now, 'dayrfc').' '.$user->getFullName($langs).($user->email ? ' <'.$user->email.'>' : '')
  657. );
  658. dolReplaceInFile($destfile, $arrayreplacement);
  659. } else {
  660. $langs->load("errors");
  661. setEventMessages($langs->trans('ErrorFailToCreateFile', $destfile), null, 'errors');
  662. }
  663. }
  664. // init Doc
  665. if ($dirins && $action == 'initdoc' && !empty($module)) {
  666. dol_mkdir($dirins.'/'.strtolower($module).'/doc');
  667. $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
  668. $srcfile = $srcdir.'/doc/Documentation.asciidoc';
  669. $destfile = $dirins.'/'.strtolower($module).'/doc/Documentation.asciidoc';
  670. //var_dump($srcfile);
  671. //var_dump($destfile);
  672. $result = dol_copy($srcfile, $destfile, 0, 0);
  673. if ($result > 0) {
  674. $modulename = ucfirst($module); // Force first letter in uppercase
  675. $modulelowercase = strtolower($module);
  676. //var_dump($phpfileval['fullname']);
  677. $arrayreplacement = array(
  678. 'mymodule'=>strtolower($modulename),
  679. 'MyModule'=>$modulename,
  680. 'MYMODULE'=>strtoupper($modulename),
  681. 'My module'=>$modulename,
  682. 'my module'=>$modulename,
  683. 'Mon module'=>$modulename,
  684. 'mon module'=>$modulename,
  685. 'htdocs/modulebuilder/template'=>strtolower($modulename),
  686. '__MYCOMPANY_NAME__'=>$mysoc->name,
  687. '__KEYWORDS__'=>$modulename,
  688. '__USER_FULLNAME__'=>$user->getFullName($langs),
  689. '__USER_EMAIL__'=>$user->email,
  690. '__YYYY-MM-DD__'=>dol_print_date($now, 'dayrfc'),
  691. '---Put here your own copyright and developer email---'=>dol_print_date($now, 'dayrfc').' '.$user->getFullName($langs).($user->email ? ' <'.$user->email.'>' : '')
  692. );
  693. dolReplaceInFile($destfile, $arrayreplacement);
  694. // add table of properties
  695. $dirins = $listofmodules[strtolower($module)]['moduledescriptorrootpath'];
  696. $destdir = $dirins.'/'.strtolower($module);
  697. $objects = dolGetListOfObjectClasses($destdir);
  698. foreach ($objects as $path=>$obj) {
  699. writePropsInAsciiDoc($path, $obj, $destfile);
  700. }
  701. // add table of permissions
  702. $moduledescriptorfile = $dirins.'/'.strtolower($module).'/core/modules/mod'.$module.'.class.php';
  703. writePermsInAsciiDoc($moduledescriptorfile, $destfile);
  704. // add api urls if file exist
  705. if (file_exists($dirins.'/'.strtolower($module).'/class/api_'.strtolower($module).'.class.php')) {
  706. $apiFile = $dirins.'/'.strtolower($module).'/class/api_'.strtolower($module).'.class.php';
  707. writeApiUrlsInDoc($apiFile, $destfile);
  708. }
  709. // add ChangeLog in Doc
  710. if (file_exists($dirins.'/'.strtolower($module).'/ChangeLog.md')) {
  711. $changeLog = $dirins.'/'.strtolower($module).'/ChangeLog.md';
  712. $string = file_get_contents($changeLog);
  713. $replace = explode("\n", $string);
  714. $strreplace = array();
  715. foreach ($replace as $line) {
  716. if ($line === '') {
  717. continue;
  718. }
  719. if (strpos($line, '##') !== false) {
  720. $strreplace[$line] = str_replace('##', '', $line);
  721. } else {
  722. $strreplace[$line] = $line;
  723. }
  724. }
  725. $stringLog = implode("\n", $strreplace);
  726. dolReplaceInFile($destfile, array('//include::ChangeLog.md[]' => '','__CHANGELOG__' => $stringLog));
  727. }
  728. // Delete old documentation files
  729. $FILENAMEDOC = $modulelowercase.'.html';
  730. $FILENAMEDOCPDF = $modulelowercase.'.pdf';
  731. $outputfiledoc = dol_buildpath($modulelowercase, 0).'/doc/'.$FILENAMEDOC;
  732. $outputfiledocurl = dol_buildpath($modulelowercase, 1).'/doc/'.$FILENAMEDOC;
  733. $outputfiledocpdf = dol_buildpath($modulelowercase, 0).'/doc/'.$FILENAMEDOCPDF;
  734. $outputfiledocurlpdf = dol_buildpath($modulelowercase, 1).'/doc/'.$FILENAMEDOCPDF;
  735. dol_delete_file($outputfiledoc, 0, 0, 0, null, false, 0);
  736. dol_delete_file($outputfiledocpdf, 0, 0, 0, null, false, 0);
  737. } else {
  738. $langs->load("errors");
  739. setEventMessages($langs->trans('ErrorFailToCreateFile', $destfile), null, 'errors');
  740. }
  741. }
  742. // add Language
  743. if ($dirins && $action == 'addlanguage' && !empty($module)) {
  744. $newlangcode = GETPOST('newlangcode', 'aZ09');
  745. if ($newlangcode) {
  746. $modulelowercase = strtolower($module);
  747. // Dir for module
  748. $diroflang = dol_buildpath($modulelowercase, 0);
  749. if ($diroflang == $dolibarr_main_document_root.'/'.$modulelowercase) {
  750. // This is not a custom module, we force diroflang to htdocs root
  751. $diroflang = $dolibarr_main_document_root;
  752. $srcfile = $diroflang.'/langs/en_US/'.$modulelowercase.'.lang';
  753. $destfile = $diroflang.'/langs/'.$newlangcode.'/'.$modulelowercase.'.lang';
  754. $result = dol_copy($srcfile, $destfile, 0, 0);
  755. if ($result < 0) {
  756. setEventMessages($langs->trans("ErrorFailToCopyFile", $srcfile, $destfile), null, 'errors');
  757. }
  758. } else {
  759. $srcdir = $diroflang.'/langs/en_US';
  760. $srcfile = $diroflang.'/langs/en_US/'.$modulelowercase.'.lang';
  761. $destdir = $diroflang.'/langs/'.$newlangcode;
  762. $arrayofreplacement = array();
  763. if (!dol_is_dir($srcfile) || !dol_is_file($srcfile)) {
  764. $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template/langs/en_US';
  765. $arrayofreplacement = array('mymodule'=>$modulelowercase);
  766. }
  767. $result = dolCopyDir($srcdir, $destdir, 0, 0, $arrayofreplacement);
  768. }
  769. } else {
  770. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Language")), null, 'errors');
  771. }
  772. }
  773. // Remove/delete File
  774. if ($dirins && $action == 'confirm_removefile' && !empty($module)) {
  775. $objectname = $tabobj;
  776. $dirins = $listofmodules[strtolower($module)]['moduledescriptorrootpath'];
  777. $destdir = $dirins.'/'.strtolower($module);
  778. $relativefilename = dol_sanitizePathName(GETPOST('file', 'restricthtml'));
  779. // Now we delete the file
  780. if ($relativefilename) {
  781. $dirnametodelete = dirname($relativefilename);
  782. $filetodelete = $dirins.'/'.$relativefilename;
  783. $dirtodelete = $dirins.'/'.$dirnametodelete;
  784. //check when we want delete api_file
  785. if (strpos($relativefilename, 'api') !== false) {
  786. $file_api = $destdir.'/class/api_'.strtolower($module).'.class.php';
  787. $removeFile = removeObjectFromApiFile($file_api, $objectname, $module);
  788. $var = getFromFile($file_api, '/*begin methods CRUD*/', '/*end methods CRUD*/');
  789. if (str_word_count($var) == 0) {
  790. $result = dol_delete_file($filetodelete);
  791. }
  792. if ($removeFile) {
  793. setEventMessages($langs->trans("ApiObjectDeleted"), null);
  794. }
  795. } else {
  796. $result = dol_delete_file($filetodelete);
  797. }
  798. if (!$result) {
  799. setEventMessages($langs->trans("ErrorFailToDeleteFile", basename($filetodelete)), null, 'errors');
  800. } else {
  801. // If we delete a .sql file, we delete also the other .sql file
  802. if (preg_match('/\.sql$/', $relativefilename)) {
  803. if (preg_match('/\.key\.sql$/', $relativefilename)) {
  804. $relativefilename = preg_replace('/\.key\.sql$/', '.sql', $relativefilename);
  805. $filetodelete = $dirins.'/'.$relativefilename;
  806. $result = dol_delete_file($filetodelete);
  807. } elseif (preg_match('/\.sql$/', $relativefilename)) {
  808. $relativefilename = preg_replace('/\.sql$/', '.key.sql', $relativefilename);
  809. $filetodelete = $dirins.'/'.$relativefilename;
  810. $result = dol_delete_file($filetodelete);
  811. }
  812. }
  813. if (dol_is_dir_empty($dirtodelete)) {
  814. dol_delete_dir($dirtodelete);
  815. }
  816. // Update descriptor file to comment file
  817. if (in_array($tab, array('css', 'js'))) {
  818. $srcfile = $dirins.'/'.strtolower($module).'/core/modules/mod'.$module.'.class.php';
  819. $arrayreplacement = array('/^\s*\''.preg_quote('/'.$relativefilename, '/').'\',*/m'=>' // \'/'.$relativefilename.'\',');
  820. dolReplaceInFile($srcfile, $arrayreplacement, '', 0, 0, 1);
  821. }
  822. if (preg_match('/_extrafields/', $relativefilename)) {
  823. // Now we update the object file to set $isextrafieldmanaged to 0
  824. $srcfile = $dirins.'/'.strtolower($module).'/class/'.strtolower($objectname).'.class.php';
  825. $arrayreplacement = array('/\$isextrafieldmanaged = 1;/' => '$isextrafieldmanaged = 0;');
  826. dolReplaceInFile($srcfile, $arrayreplacement, '', 0, 0, 1);
  827. }
  828. // Now we update the lib file to set $showtabofpagexxx to 0
  829. $varnametoupdate = '';
  830. $reg = array();
  831. if (preg_match('/_([a-z]+)\.php$/', $relativefilename, $reg)) {
  832. $varnametoupdate = 'showtabofpage'.$reg[1];
  833. }
  834. if ($varnametoupdate) {
  835. $srcfile = $dirins.'/'.strtolower($module).'/lib/'.strtolower($module).'_'.strtolower($objectname).'.lib.php';
  836. $arrayreplacement = array('/\$'.preg_quote($varnametoupdate, '/').' = 1;/' => '$'.preg_quote($varnametoupdate, '/').' = 0;');
  837. dolReplaceInFile($srcfile, $arrayreplacement, '', 0, 0, 1);
  838. }
  839. }
  840. }
  841. }
  842. // Init an object
  843. if ($dirins && $action == 'initobject' && $module && $objectname) {
  844. $objectname = ucfirst($objectname);
  845. $dirins = $dirread = $listofmodules[strtolower($module)]['moduledescriptorrootpath'];
  846. $moduletype = $listofmodules[strtolower($module)]['moduletype'];
  847. if (preg_match('/[^a-z0-9_]/i', $objectname)) {
  848. $error++;
  849. setEventMessages($langs->trans("SpaceOrSpecialCharAreNotAllowed"), null, 'errors');
  850. $tabobj = 'newobject';
  851. }
  852. if (class_exists($objectname)) {
  853. // TODO Add a more efficient detection. Scan disk ?
  854. $error++;
  855. setEventMessages($langs->trans("AnObjectWithThisClassNameAlreadyExists"), null, 'errors');
  856. $tabobj = 'newobject';
  857. }
  858. $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
  859. $destdir = $dirins.'/'.strtolower($module);
  860. // The dir was not created by init
  861. dol_mkdir($destdir.'/class');
  862. dol_mkdir($destdir.'/img');
  863. dol_mkdir($destdir.'/lib');
  864. dol_mkdir($destdir.'/scripts');
  865. dol_mkdir($destdir.'/sql');
  866. // Scan dir class to find if an object with same name already exists.
  867. if (!$error) {
  868. $dirlist = dol_dir_list($destdir.'/class', 'files', 0, '\.txt$');
  869. $alreadyfound = false;
  870. foreach ($dirlist as $key => $val) {
  871. $filefound = preg_replace('/\.txt$/', '', $val['name']);
  872. if (strtolower($objectname) == strtolower($filefound) && $objectname != $filefound) {
  873. $alreadyfound = true;
  874. $error++;
  875. setEventMessages($langs->trans("AnObjectAlreadyExistWithThisNameAndDiffCase"), null, 'errors');
  876. break;
  877. }
  878. }
  879. }
  880. // If we must reuse a table for properties, define $stringforproperties
  881. $stringforproperties = '';
  882. $tablename = GETPOST('initfromtablename', 'alpha');
  883. if ($tablename) {
  884. $_results = $db->DDLDescTable($tablename);
  885. if (empty($_results)) {
  886. $error++;
  887. $langs->load("errors");
  888. setEventMessages($langs->trans("ErrorTableNotFound", $tablename), null, 'errors');
  889. } else {
  890. /**
  891. * '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')
  892. * Note: Filter can be a string like "(t.ref:like:'SO-%') or (t.date_creation:<:'20160101') or (t.nature:is:NULL)"
  893. * 'label' the translation key.
  894. * 'picto' is code of a picto to show before value in forms
  895. * 'enabled' is a condition when the field must be managed (Example: 1 or '$conf->global->MY_SETUP_PARAM' or 'isModEnabled("multicurrency")' ...)
  896. * 'position' is the sort order of field.
  897. * 'notnull' is set to 1 if not null in database. Set to -1 if we must set data to null if empty ('' or 0).
  898. * '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)
  899. * 'noteditable' says if field is not editable (1 or 0)
  900. * 'alwayseditable' says if field can be modified also when status is not draft ('1' or '0')
  901. * '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.
  902. * 'index' if we want an index in database.
  903. * 'foreignkey'=>'tablename.field' if the field is a foreign key (it is recommanded to name the field fk_...).
  904. * 'searchall' is 1 if we want to search in this field when making a search from the quick search button.
  905. * '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)
  906. * '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'
  907. * 'help' is a 'TranslationString' to use to show a tooltip on field. You can also use 'TranslationString:keyfortooltiponlick' for a tooltip on click.
  908. * 'showoncombobox' if value of the field must be visible into the label of the combobox that list record
  909. * '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.
  910. * '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'
  911. * 'autofocusoncreate' to have field having the focus on a create form. Only 1 field should have this property set to 1.
  912. * 'comment' is not used. You can store here any text of your choice. It is not used by application.
  913. * 'validate' is 1 if need to validate with $this->validateField()
  914. * 'copytoclipboard' is 1 or 2 to allow to add a picto to copy value into clipboard (1=picto after label, 2=picto after value)
  915. */
  916. /*public $fields=array(
  917. 'rowid' =>array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'index'=>1, 'position'=>1, 'comment'=>'Id'),
  918. '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'),
  919. 'entity' =>array('type'=>'integer', 'label'=>'Entity', 'enabled'=>1, 'visible'=>0, 'default'=>1, 'notnull'=>1, 'index'=>1, 'position'=>20),
  920. 'label' =>array('type'=>'varchar(255)', 'label'=>'Label', 'enabled'=>1, 'visible'=>1, 'position'=>30, 'searchall'=>1, 'css'=>'minwidth200', 'help'=>'Help text', 'alwayseditable'=>'1'),
  921. 'amount' =>array('type'=>'double(24,8)', 'label'=>'Amount', 'enabled'=>1, 'visible'=>1, 'default'=>'null', 'position'=>40, 'searchall'=>0, 'isameasure'=>1, 'help'=>'Help text'),
  922. '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'),
  923. 'description' =>array('type'=>'text', 'label'=>'Descrption', 'enabled'=>1, 'visible'=>0, 'position'=>60),
  924. 'note_public' =>array('type'=>'html', 'label'=>'NotePublic', 'enabled'=>1, 'visible'=>0, 'position'=>61),
  925. 'note_private' =>array('type'=>'html', 'label'=>'NotePrivate', 'enabled'=>1, 'visible'=>0, 'position'=>62),
  926. 'date_creation' =>array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>500),
  927. 'tms' =>array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>501),
  928. //'date_valid' =>array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-2, 'position'=>502),
  929. 'fk_user_creat' =>array('type'=>'integer', 'label'=>'UserAuthor', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>510),
  930. 'fk_user_modif' =>array('type'=>'integer', 'label'=>'UserModif', 'enabled'=>1, 'visible'=>-2, 'notnull'=>-1, 'position'=>511),
  931. //'fk_user_valid' =>array('type'=>'integer', 'label'=>'UserValidation', 'enabled'=>1, 'visible'=>-1, 'position'=>512),
  932. 'import_key' =>array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>1, 'visible'=>-2, 'notnull'=>-1, 'index'=>0, 'position'=>1000),
  933. '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')),
  934. );*/
  935. $stringforproperties = '// BEGIN MODULEBUILDER PROPERTIES'."\n";
  936. $stringforproperties .= 'public $fields=array('."\n";
  937. $i = 10;
  938. while ($obj = $db->fetch_object($_results)) {
  939. // fieldname
  940. $fieldname = $obj->Field;
  941. // type
  942. $type = $obj->Type;
  943. if ($type == 'int(11)') {
  944. $type = 'integer';
  945. }
  946. if ($type == 'float') {
  947. $type = 'real';
  948. }
  949. if (strstr($type, 'tinyint')) {
  950. $type = 'integer';
  951. }
  952. if ($obj->Field == 'fk_soc') {
  953. $type = 'integer:Societe:societe/class/societe.class.php';
  954. }
  955. if (preg_match('/^fk_proj/', $obj->Field)) {
  956. $type = 'integer:Project:projet/class/project.class.php:1:fk_statut=1';
  957. }
  958. if (preg_match('/^fk_prod/', $obj->Field)) {
  959. $type = 'integer:Product:product/class/product.class.php:1';
  960. }
  961. if ($obj->Field == 'fk_warehouse') {
  962. $type = 'integer:Entrepot:product/stock/class/entrepot.class.php';
  963. }
  964. if (preg_match('/^(fk_user|fk_commercial)/', $obj->Field)) {
  965. $type = 'integer:User:user/class/user.class.php';
  966. }
  967. // notnull
  968. $notnull = ($obj->Null == 'YES' ? 0 : 1);
  969. if ($fieldname == 'fk_user_modif') {
  970. $notnull = -1;
  971. }
  972. // label
  973. $label = preg_replace('/_/', '', ucfirst($fieldname));
  974. if ($fieldname == 'rowid') {
  975. $label = 'TechnicalID';
  976. }
  977. if ($fieldname == 'import_key') {
  978. $label = 'ImportId';
  979. }
  980. if ($fieldname == 'fk_soc') {
  981. $label = 'ThirdParty';
  982. }
  983. if ($fieldname == 'tms') {
  984. $label = 'DateModification';
  985. }
  986. if ($fieldname == 'datec') {
  987. $label = 'DateCreation';
  988. }
  989. if ($fieldname == 'date_valid') {
  990. $label = 'DateValidation';
  991. }
  992. if ($fieldname == 'datev') {
  993. $label = 'DateValidation';
  994. }
  995. if ($fieldname == 'note_private') {
  996. $label = 'NotePublic';
  997. }
  998. if ($fieldname == 'note_public') {
  999. $label = 'NotePrivate';
  1000. }
  1001. if ($fieldname == 'fk_user_creat') {
  1002. $label = 'UserAuthor';
  1003. }
  1004. if ($fieldname == 'fk_user_modif') {
  1005. $label = 'UserModif';
  1006. }
  1007. if ($fieldname == 'fk_user_valid') {
  1008. $label = 'UserValidation';
  1009. }
  1010. // visible
  1011. $visible = -1;
  1012. if ($fieldname == 'entity') {
  1013. $visible = -2;
  1014. }
  1015. if ($fieldname == 'import_key') {
  1016. $visible = -2;
  1017. }
  1018. if ($fieldname == 'fk_user_creat') {
  1019. $visible = -2;
  1020. }
  1021. if ($fieldname == 'fk_user_modif') {
  1022. $visible = -2;
  1023. }
  1024. if (in_array($fieldname, array('ref_ext', 'model_pdf', 'note_public', 'note_private'))) {
  1025. $visible = 0;
  1026. }
  1027. // enabled
  1028. $enabled = 1;
  1029. // default
  1030. $default = '';
  1031. if ($fieldname == 'entity') {
  1032. $default = 1;
  1033. }
  1034. // position
  1035. $position = $i;
  1036. if (in_array($fieldname, array('status', 'statut', 'fk_status', 'fk_statut'))) {
  1037. $position = 500;
  1038. }
  1039. if ($fieldname == 'import_key') {
  1040. $position = 900;
  1041. }
  1042. // $alwayseditable
  1043. if ($fieldname == 'label') {
  1044. $alwayseditable = 1;
  1045. }
  1046. // index
  1047. $index = 0;
  1048. if ($fieldname == 'entity') {
  1049. $index = 1;
  1050. }
  1051. // css, cssview, csslist
  1052. $css = '';
  1053. $cssview = '';
  1054. $csslist = '';
  1055. if (preg_match('/^fk_/', $fieldname)) {
  1056. $css = 'maxwidth500 widthcentpercentminusxx';
  1057. }
  1058. if ($fieldname == 'label') {
  1059. $css = 'minwidth300';
  1060. $cssview = 'wordbreak';
  1061. }
  1062. if (in_array($fieldname, array('note_public', 'note_private'))) {
  1063. $cssview = 'wordbreak';
  1064. }
  1065. if (in_array($fieldname, array('ref', 'label')) || preg_match('/integer:/', $type)) {
  1066. $csslist = 'tdoverflowmax150';
  1067. }
  1068. // type
  1069. $picto = $obj->Picto;
  1070. if ($obj->Field == 'fk_soc') {
  1071. $picto = 'company';
  1072. }
  1073. if (preg_match('/^fk_proj/', $obj->Field)) {
  1074. $picto = 'project';
  1075. }
  1076. // Build the property string
  1077. $stringforproperties .= "'".$obj->Field."'=>array('type'=>'".$type."', 'label'=>'".$label."',";
  1078. if ($default != '') {
  1079. $stringforproperties .= " 'default'=>".$default.",";
  1080. }
  1081. $stringforproperties .= " 'enabled'=>".$enabled.",";
  1082. $stringforproperties .= " 'visible'=>".$visible;
  1083. if ($notnull) {
  1084. $stringforproperties .= ", 'notnull'=>".$notnull;
  1085. }
  1086. if ($alwayseditable) {
  1087. $stringforproperties .= ", 'alwayseditable'=>1";
  1088. }
  1089. if ($fieldname == 'ref' || $fieldname == 'code') {
  1090. $stringforproperties .= ", 'showoncombobox'=>1";
  1091. }
  1092. $stringforproperties .= ", 'position'=>".$position;
  1093. if ($index) {
  1094. $stringforproperties .= ", 'index'=>".$index;
  1095. }
  1096. if ($picto) {
  1097. $stringforproperties .= ", 'picto'=>'".$picto."'";
  1098. }
  1099. if ($css) {
  1100. $stringforproperties .= ", 'css'=>'".$css."'";
  1101. }
  1102. if ($cssview) {
  1103. $stringforproperties .= ", 'cssview'=>'".$cssview."'";
  1104. }
  1105. if ($csslist) {
  1106. $stringforproperties .= ", 'csslist'=>'".$csslist."'";
  1107. }
  1108. $stringforproperties .= "),\n";
  1109. $i += 5;
  1110. }
  1111. $stringforproperties .= ');'."\n";
  1112. $stringforproperties .= '// END MODULEBUILDER PROPERTIES'."\n";
  1113. }
  1114. }
  1115. if (!$error) {
  1116. // Copy some files
  1117. $filetogenerate = array(
  1118. 'myobject_card.php'=>strtolower($objectname).'_card.php',
  1119. 'myobject_note.php'=>strtolower($objectname).'_note.php',
  1120. 'myobject_contact.php'=>strtolower($objectname).'_contact.php',
  1121. 'myobject_document.php'=>strtolower($objectname).'_document.php',
  1122. 'myobject_agenda.php'=>strtolower($objectname).'_agenda.php',
  1123. 'myobject_list.php'=>strtolower($objectname).'_list.php',
  1124. 'admin/myobject_extrafields.php'=>'admin/'.strtolower($objectname).'_extrafields.php',
  1125. 'lib/mymodule_myobject.lib.php'=>'lib/'.strtolower($module).'_'.strtolower($objectname).'.lib.php',
  1126. //'test/phpunit/MyObjectTest.php'=>'test/phpunit/'.strtolower($objectname).'Test.php',
  1127. 'sql/llx_mymodule_myobject.sql'=>'sql/llx_'.strtolower($module).'_'.strtolower($objectname).'.sql',
  1128. 'sql/llx_mymodule_myobject.key.sql'=>'sql/llx_'.strtolower($module).'_'.strtolower($objectname).'.key.sql',
  1129. 'sql/llx_mymodule_myobject_extrafields.sql'=>'sql/llx_'.strtolower($module).'_'.strtolower($objectname).'_extrafields.sql',
  1130. 'sql/llx_mymodule_myobject_extrafields.key.sql'=>'sql/llx_'.strtolower($module).'_'.strtolower($objectname).'_extrafields.key.sql',
  1131. //'scripts/mymodule.php'=>'scripts/'.strtolower($objectname).'.php',
  1132. 'class/myobject.class.php'=>'class/'.strtolower($objectname).'.class.php',
  1133. //'class/api_mymodule.class.php'=>'class/api_'.strtolower($module).'.class.php',
  1134. );
  1135. if (GETPOST('includerefgeneration', 'aZ09')) {
  1136. dol_mkdir($destdir.'/core/modules/'.strtolower($module));
  1137. $filetogenerate += array(
  1138. 'core/modules/mymodule/mod_myobject_advanced.php'=>'core/modules/'.strtolower($module).'/mod_'.strtolower($objectname).'_advanced.php',
  1139. 'core/modules/mymodule/mod_myobject_standard.php'=>'core/modules/'.strtolower($module).'/mod_'.strtolower($objectname).'_standard.php',
  1140. 'core/modules/mymodule/modules_myobject.php'=>'core/modules/'.strtolower($module).'/modules_'.strtolower($objectname).'.php',
  1141. );
  1142. }
  1143. if (GETPOST('includedocgeneration', 'aZ09')) {
  1144. dol_mkdir($destdir.'/core/modules/'.strtolower($module));
  1145. dol_mkdir($destdir.'/core/modules/'.strtolower($module).'/doc');
  1146. $filetogenerate += array(
  1147. 'core/modules/mymodule/doc/doc_generic_myobject_odt.modules.php'=>'core/modules/'.strtolower($module).'/doc/doc_generic_'.strtolower($objectname).'_odt.modules.php',
  1148. 'core/modules/mymodule/doc/pdf_standard_myobject.modules.php'=>'core/modules/'.strtolower($module).'/doc/pdf_standard_'.strtolower($objectname).'.modules.php'
  1149. );
  1150. }
  1151. if (GETPOST('generatepermissions', 'aZ09')) {
  1152. $firstobjectname = 'myobject';
  1153. $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
  1154. dol_include_once($pathtofile);
  1155. $class = 'mod'.$module;
  1156. if (class_exists($class)) {
  1157. try {
  1158. $moduleobj = new $class($db);
  1159. } catch (Exception $e) {
  1160. $error++;
  1161. dol_print_error($db, $e->getMessage());
  1162. }
  1163. }
  1164. $rights = $moduleobj->rights;
  1165. $moduledescriptorfile = $destdir.'/core/modules/mod'.$module.'.class.php';
  1166. $checkComment=checkExistComment($moduledescriptorfile, 1);
  1167. if ($checkComment < 0) {
  1168. setEventMessages($langs->trans("WarningCommentNotFound", $langs->trans("Permissions"), "mod".$module."class.php"), null, 'warnings');
  1169. } else {
  1170. $generatePerms = reWriteAllPermissions($moduledescriptorfile, $rights, null, null, $objectname, $module, -2);
  1171. if ($generatePerms < 0) {
  1172. setEventMessages($langs->trans("WarningPermissionAlreadyExist", $langs->transnoentities($objectname)), null, 'warnings');
  1173. }
  1174. }
  1175. }
  1176. if (!$error) {
  1177. foreach ($filetogenerate as $srcfile => $destfile) {
  1178. $result = dol_copy($srcdir.'/'.$srcfile, $destdir.'/'.$destfile, $newmask, 0);
  1179. if ($result <= 0) {
  1180. if ($result < 0) {
  1181. $error++;
  1182. $langs->load("errors");
  1183. setEventMessages($langs->trans("ErrorFailToCopyFile", $srcdir.'/'.$srcfile, $destdir.'/'.$destfile), null, 'errors');
  1184. } else {
  1185. // $result == 0
  1186. setEventMessages($langs->trans("FileAlreadyExists", $destfile), null, 'warnings');
  1187. }
  1188. }
  1189. $arrayreplacement = array(
  1190. '/myobject\.class\.php/' => strtolower($objectname).'.class.php',
  1191. '/myobject\.lib\.php/' => strtolower($objectname).'.lib.php',
  1192. );
  1193. dolReplaceInFile($destdir.'/'.$destfile, $arrayreplacement, '', 0, 0, 1);
  1194. }
  1195. }
  1196. // Replace property section with $stringforproperties
  1197. if (!$error && $stringforproperties) {
  1198. //var_dump($stringforproperties);exit;
  1199. $arrayreplacement = array(
  1200. '/\/\/ BEGIN MODULEBUILDER PROPERTIES.*\/\/ END MODULEBUILDER PROPERTIES/ims' => $stringforproperties
  1201. );
  1202. dolReplaceInFile($destdir.'/class/'.strtolower($objectname).'.class.php', $arrayreplacement, '', 0, 0, 1);
  1203. }
  1204. // Edit the class 'class/'.strtolower($objectname).'.class.php'
  1205. if (GETPOST('includerefgeneration', 'aZ09')) {
  1206. // Replace 'visible'=>1, 'noteditable'=>0, 'default'=>''
  1207. $arrayreplacement = array(
  1208. '/\'visible\'=>1,\s*\'noteditable\'=>0,\s*\'default\'=>\'\'/' => "'visible'=>4, 'noteditable'=>1, 'default'=>'(PROV)'"
  1209. );
  1210. //var_dump($arrayreplacement);exit;
  1211. //var_dump($destdir.'/class/'.strtolower($objectname).'.class.php');exit;
  1212. dolReplaceInFile($destdir.'/class/'.strtolower($objectname).'.class.php', $arrayreplacement, '', 0, 0, 1);
  1213. $arrayreplacement = array(
  1214. '/\'models\' => 0,/' => '\'models\' => 1,'
  1215. );
  1216. dolReplaceInFile($destdir.'/core/modules/mod'.$module.'.class.php', $arrayreplacement, '', 0, 0, 1);
  1217. }
  1218. // Edit the setup file and the card page
  1219. if (GETPOST('includedocgeneration', 'aZ09')) {
  1220. // Replace some var init into some files
  1221. $arrayreplacement = array(
  1222. '/\$includedocgeneration = 0;/' => '$includedocgeneration = 1;'
  1223. );
  1224. dolReplaceInFile($destdir.'/class/'.strtolower($objectname).'.class.php', $arrayreplacement, '', 0, 0, 1);
  1225. dolReplaceInFile($destdir.'/'.strtolower($objectname).'_card.php', $arrayreplacement, '', 0, 0, 1);
  1226. $arrayreplacement = array(
  1227. '/\'models\' => 0,/' => '\'models\' => 1,'
  1228. );
  1229. dolReplaceInFile($destdir.'/core/modules/mod'.$module.'.class.php', $arrayreplacement, '', 0, 0, 1);
  1230. }
  1231. // TODO Update entries '$myTmpObjects['MyObject']=array('includerefgeneration'=>0, 'includedocgeneration'=>0);'
  1232. // Scan for object class files
  1233. $listofobject = dol_dir_list($destdir.'/class', 'files', 0, '\.class\.php$');
  1234. $firstobjectname = '';
  1235. foreach ($listofobject as $fileobj) {
  1236. if (preg_match('/^api_/', $fileobj['name'])) {
  1237. continue;
  1238. }
  1239. if (preg_match('/^actions_/', $fileobj['name'])) {
  1240. continue;
  1241. }
  1242. $tmpcontent = file_get_contents($fileobj['fullname']);
  1243. $reg = array();
  1244. if (preg_match('/class\s+([^\s]*)\s+extends\s+CommonObject/ims', $tmpcontent, $reg)) {
  1245. $objectnameloop = $reg[1];
  1246. if (empty($firstobjectname)) {
  1247. $firstobjectname = $objectnameloop;
  1248. }
  1249. }
  1250. // Regenerate left menu entry in descriptor for $objectname
  1251. $stringtoadd = "
  1252. \$this->menu[\$r++]=array(
  1253. 'fk_menu'=>'fk_mainmenu=mymodule',
  1254. 'type'=>'left',
  1255. 'titre'=>'MyObject',
  1256. 'prefix' => img_picto('', \$this->picto, 'class=\"paddingright pictofixedwidth valignmiddle\"'),
  1257. 'mainmenu'=>'mymodule',
  1258. 'leftmenu'=>'myobject',
  1259. 'url'=>'/mymodule/myobject_list.php',
  1260. 'langs'=>'mymodule@mymodule',
  1261. 'position'=>1000+\$r,
  1262. 'enabled'=>'isModEnabled(\"mymodule\")',
  1263. 'perms'=>'\$user->hasRight(\"mymodule\", \"myobject\", \"read\")',
  1264. 'target'=>'',
  1265. 'user'=>2,
  1266. );
  1267. \$this->menu[\$r++]=array(
  1268. 'fk_menu'=>'fk_mainmenu=mymodule,fk_leftmenu=myobject',
  1269. 'type'=>'left',
  1270. 'titre'=>'List MyObject',
  1271. 'mainmenu'=>'mymodule',
  1272. 'leftmenu'=>'mymodule_myobject_list',
  1273. 'url'=>'/mymodule/myobject_list.php',
  1274. 'langs'=>'mymodule@mymodule',
  1275. 'position'=>1000+\$r,
  1276. 'enabled'=>'isModEnabled(\"mymodule\")',
  1277. 'perms'=>'\$user->hasRight(\"mymodule\", \"myobject\", \"read\")',
  1278. 'target'=>'',
  1279. 'user'=>2,
  1280. );
  1281. \$this->menu[\$r++]=array(
  1282. 'fk_menu'=>'fk_mainmenu=mymodule,fk_leftmenu=myobject',
  1283. 'type'=>'left',
  1284. 'titre'=>'New MyObject',
  1285. 'mainmenu'=>'mymodule',
  1286. 'leftmenu'=>'mymodule_myobject_new',
  1287. 'url'=>'/mymodule/myobject_card.php?action=create',
  1288. 'langs'=>'mymodule@mymodule',
  1289. 'position'=>1000+\$r,
  1290. 'enabled'=>'isModEnabled(\"mymodule\")',
  1291. 'perms'=>'\$user->hasRight(\"mymodule\", \"myobject\", \"write\")',
  1292. 'target'=>'',
  1293. 'user'=>2
  1294. );\n";
  1295. $stringtoadd = preg_replace('/MyObject/', $objectname, $stringtoadd);
  1296. $stringtoadd = preg_replace('/mymodule/', strtolower($module), $stringtoadd);
  1297. $stringtoadd = preg_replace('/myobject/', strtolower($objectname), $stringtoadd);
  1298. $moduledescriptorfile = $destdir.'/core/modules/mod'.$module.'.class.php';
  1299. }
  1300. // TODO Allow a replace with regex using dolReplaceInFile with param arryreplacementisregex to 1
  1301. // TODO Avoid duplicate addition
  1302. // load class and check if menu exist with same object name
  1303. $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
  1304. dol_include_once($pathtofile);
  1305. $class = 'mod'.$module;
  1306. if (class_exists($class)) {
  1307. try {
  1308. $moduleobj = new $class($db);
  1309. } catch (Exception $e) {
  1310. $error++;
  1311. dol_print_error($db, $e->getMessage());
  1312. }
  1313. }
  1314. $menus = $moduleobj->menu;
  1315. $counter = 0 ;
  1316. foreach ($menus as $menu) {
  1317. if ($menu['leftmenu'] == strtolower($objectname)) {
  1318. $counter++;
  1319. }
  1320. }
  1321. if (!$counter) {
  1322. $checkComment = checkExistComment($moduledescriptorfile, 0);
  1323. if ($checkComment < 0) {
  1324. $error++;
  1325. setEventMessages($langs->trans("WarningCommentNotFound", $langs->trans("Menus"), "mod".$module."class.php"), null, 'warnings');
  1326. } else {
  1327. $arrayofreplacement = array('/* END MODULEBUILDER LEFTMENU MYOBJECT */' => '/*LEFTMENU '.strtoupper($objectname).'*/'.$stringtoadd."\n\t\t".'/*END LEFTMENU '.strtoupper($objectname).'*/'."\n\t\t".'/* END MODULEBUILDER LEFTMENU MYOBJECT */');
  1328. dolReplaceInFile($moduledescriptorfile, $arrayofreplacement);
  1329. }
  1330. }
  1331. // Add module descriptor to list of files to replace "MyObject' string with real name of object.
  1332. $filetogenerate[] = 'core/modules/mod'.$module.'.class.php';
  1333. }
  1334. if (!$error) {
  1335. // Edit PHP files to make replacement
  1336. foreach ($filetogenerate as $destfile) {
  1337. $phpfileval['fullname'] = $destdir.'/'.$destfile;
  1338. //var_dump($phpfileval['fullname']);
  1339. $arrayreplacement = array(
  1340. 'mymodule'=>strtolower($module),
  1341. 'MyModule'=>$module,
  1342. 'MYMODULE'=>strtoupper($module),
  1343. 'My module'=>$module,
  1344. 'my module'=>$module,
  1345. 'mon module'=>$module,
  1346. 'Mon module'=>$module,
  1347. 'htdocs/modulebuilder/template/'=>strtolower($modulename),
  1348. 'myobject'=>strtolower($objectname),
  1349. 'MyObject'=>$objectname,
  1350. //'MYOBJECT'=>strtoupper($objectname),
  1351. '---Put here your own copyright and developer email---'=>dol_print_date($now, '%Y').' '.$user->getFullName($langs).($user->email ? ' <'.$user->email.'>' : '')
  1352. );
  1353. if (getDolGlobalString('MODULEBUILDER_SPECIFIC_AUTHOR')) {
  1354. $arrayreplacement['---Put here your own copyright and developer email---'] = dol_print_date($now, '%Y').' ' . getDolGlobalString('MODULEBUILDER_SPECIFIC_AUTHOR');
  1355. }
  1356. $result = dolReplaceInFile($phpfileval['fullname'], $arrayreplacement);
  1357. //var_dump($result);
  1358. if ($result < 0) {
  1359. setEventMessages($langs->trans("ErrorFailToMakeReplacementInto", $phpfileval['fullname']), null, 'errors');
  1360. }
  1361. }
  1362. }
  1363. if (!$error) {
  1364. // Edit the class file to write properties
  1365. $object = rebuildObjectClass($destdir, $module, $objectname, $newmask);
  1366. if (is_numeric($object) && $object <= 0) {
  1367. $pathoffiletoeditsrc = $destdir.'/class/'.strtolower($objectname).'.class.php';
  1368. setEventMessages($langs->trans('ErrorFailToCreateFile', $pathoffiletoeditsrc), null, 'errors');
  1369. $error++;
  1370. }
  1371. // check if documentation was generate and add table of properties object
  1372. $file = $destdir.'/class/'.strtolower($objectname).'.class.php';
  1373. $destfile = $destdir.'/doc/Documentation.asciidoc';
  1374. if (file_exists($destfile)) {
  1375. writePropsInAsciiDoc($file, $objectname, $destfile);
  1376. }
  1377. }
  1378. if (!$error) {
  1379. // Edit sql with new properties
  1380. $result = rebuildObjectSql($destdir, $module, $objectname, $newmask, '', $object);
  1381. if ($result <= 0) {
  1382. setEventMessages($langs->trans('ErrorFailToCreateFile', '.sql'), null);
  1383. $error++;
  1384. }
  1385. }
  1386. if (!$error) {
  1387. setEventMessages($langs->trans('FilesForObjectInitialized', $objectname), null);
  1388. $tabobj = $objectname;
  1389. } else {
  1390. $tabobj = 'newobject';
  1391. }
  1392. // check if module is enabled
  1393. if (isModEnabled(strtolower($module))) {
  1394. $result = unActivateModule(strtolower($module));
  1395. dolibarr_set_const($db, "MAIN_IHM_PARAMS_REV", (int) $conf->global->MAIN_IHM_PARAMS_REV + 1, 'chaine', 0, '', $conf->entity);
  1396. if ($result) {
  1397. setEventMessages($result, null, 'errors');
  1398. }
  1399. setEventMessages($langs->trans('WarningModuleNeedRefresh', $langs->transnoentities($module)), null, 'warnings');
  1400. header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=objects&module='.$module);
  1401. exit;
  1402. }
  1403. }
  1404. // Add a dictionary
  1405. if ($dirins && $action == 'initdic' && $module && empty($cancel)) {
  1406. $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
  1407. $destdir = $dirins.'/'.strtolower($module);
  1408. $moduledescriptorfile = $dirins.'/'.strtolower($module).'/core/modules/mod'.$module.'.class.php';
  1409. if (!GETPOST('dicname')) {
  1410. $error++;
  1411. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Table")), null, 'errors');
  1412. }
  1413. if (!GETPOST('label')) {
  1414. $error++;
  1415. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Lable")), null, 'errors');
  1416. }
  1417. if (!$error) {
  1418. $newdicname = $dicname;
  1419. if (!preg_match('/^c_/', $newdicname)) {
  1420. $newdicname = 'c_'.$dicname;
  1421. }
  1422. dol_include_once($pathtofile);
  1423. $class = 'mod'.$module;
  1424. if (class_exists($class)) {
  1425. try {
  1426. $moduleobj = new $class($db);
  1427. } catch (Exception $e) {
  1428. $error++;
  1429. dol_print_error($db, $e->getMessage());
  1430. }
  1431. } else {
  1432. $error++;
  1433. $langs->load("errors");
  1434. dol_print_error($db, $langs->trans("ErrorFailedToLoadModuleDescriptorForXXX", $module));
  1435. exit;
  1436. }
  1437. $dictionaries = $moduleobj->dictionaries;
  1438. $checkComment = checkExistComment($moduledescriptorfile, 2);
  1439. if ($checkComment < 0) {
  1440. setEventMessages($langs->trans("WarningCommentNotFound", $langs->trans("Dictionaries"), "mod".$module."class.php"), null, 'warnings');
  1441. } else {
  1442. createNewDictionnary($module, $moduledescriptorfile, $newdicname, $dictionaries);
  1443. if (function_exists('opcache_invalidate')) {
  1444. opcache_reset(); // remove the include cache hell !
  1445. }
  1446. clearstatcache(true);
  1447. header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=dictionaries&module='.$module.($forceddirread ? '@'.$dirread : ''));
  1448. exit;
  1449. }
  1450. }
  1451. }
  1452. // Delete a SQL table
  1453. if ($dirins && ($action == 'droptable' || $action == 'droptableextrafields') && !empty($module) && !empty($tabobj)) {
  1454. $objectname = $tabobj;
  1455. $arrayoftables = array();
  1456. if ($action == 'droptable') {
  1457. $arrayoftables[] = MAIN_DB_PREFIX.strtolower($module).'_'.strtolower($tabobj);
  1458. }
  1459. if ($action == 'droptableextrafields') {
  1460. $arrayoftables[] = MAIN_DB_PREFIX.strtolower($module).'_'.strtolower($tabobj).'_extrafields';
  1461. }
  1462. foreach ($arrayoftables as $tabletodrop) {
  1463. $nb = -1;
  1464. $sql = "SELECT COUNT(*) as nb FROM ".$tabletodrop;
  1465. $resql = $db->query($sql);
  1466. if ($resql) {
  1467. $obj = $db->fetch_object($resql);
  1468. if ($obj) {
  1469. $nb = $obj->nb;
  1470. }
  1471. } else {
  1472. if ($db->lasterrno() == 'DB_ERROR_NOSUCHTABLE') {
  1473. setEventMessages($langs->trans("TableDoesNotExists", $tabletodrop), null, 'warnings');
  1474. } else {
  1475. dol_print_error($db);
  1476. }
  1477. }
  1478. if ($nb == 0) {
  1479. $resql = $db->DDLDropTable($tabletodrop);
  1480. //var_dump($resql);
  1481. setEventMessages($langs->trans("TableDropped", $tabletodrop), null, 'mesgs');
  1482. } elseif ($nb > 0) {
  1483. setEventMessages($langs->trans("TableNotEmptyDropCanceled", $tabletodrop), null, 'warnings');
  1484. }
  1485. }
  1486. }
  1487. if ($dirins && $action == 'addproperty' && empty($cancel) && !empty($module) && (!empty($tabobj) || !empty(GETPOST('obj')))) {
  1488. $error = 0;
  1489. $objectname = (GETPOST('obj') ? GETPOST('obj') : $tabobj);
  1490. $dirins = $dirread = $listofmodules[strtolower($module)]['moduledescriptorrootpath'];
  1491. $moduletype = $listofmodules[strtolower($module)]['moduletype'];
  1492. $srcdir = $dirread.'/'.strtolower($module);
  1493. $destdir = $dirins.'/'.strtolower($module);
  1494. dol_mkdir($destdir);
  1495. $objects = dolGetListOfObjectClasses($destdir);
  1496. if (!in_array($objectname, array_values($objects))) {
  1497. $error++;
  1498. setEventMessages($langs->trans("ErrorObjectNotFound", $langs->transnoentities($objectname)), null, 'errors');
  1499. }
  1500. // We click on add property
  1501. if (!GETPOST('regenerateclasssql') && !GETPOST('regeneratemissing')) {
  1502. if (!GETPOST('propname', 'aZ09')) {
  1503. $error++;
  1504. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Name")), null, 'errors');
  1505. }
  1506. if (!GETPOST('proplabel', 'alpha')) {
  1507. $error++;
  1508. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Label")), null, 'errors');
  1509. }
  1510. if (!GETPOST('proptype', 'alpha')) {
  1511. $error++;
  1512. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Type")), null, 'errors');
  1513. }
  1514. if (!$error && !GETPOST('regenerateclasssql') && !GETPOST('regeneratemissing')) {
  1515. $addfieldentry = array(
  1516. 'name'=>GETPOST('propname', 'aZ09'),
  1517. 'label'=>GETPOST('proplabel', 'alpha'),
  1518. 'type'=>strtolower(GETPOST('proptype', 'alpha')),
  1519. 'arrayofkeyval'=>GETPOST('proparrayofkeyval', 'alphawithlgt'), // Example json string '{"0":"Draft","1":"Active","-1":"Cancel"}'
  1520. 'visible'=>GETPOST('propvisible', 'alphanohtml'),
  1521. 'enabled'=>GETPOST('propenabled', 'alphanohtml'),
  1522. 'position'=>GETPOST('propposition', 'int'),
  1523. 'notnull'=>GETPOST('propnotnull', 'int'),
  1524. 'index'=>GETPOST('propindex', 'int'),
  1525. 'foreignkey'=>GETPOST('propforeignkey', 'alpha'),
  1526. 'searchall'=>GETPOST('propsearchall', 'int'),
  1527. 'isameasure'=>GETPOST('propisameasure', 'int'),
  1528. 'comment'=>GETPOST('propcomment', 'alpha'),
  1529. 'help'=>GETPOST('prophelp', 'alpha'),
  1530. 'css'=>GETPOST('propcss', 'alpha'), // Can be 'maxwidth500 widthcentpercentminusxx' for example
  1531. 'cssview'=>GETPOST('propcssview', 'alpha'),
  1532. 'csslist'=>GETPOST('propcsslist', 'alpha'),
  1533. 'default'=>GETPOST('propdefault', 'restricthtml'),
  1534. 'noteditable'=>intval(GETPOST('propnoteditable', 'int')),
  1535. //'alwayseditable'=>intval(GETPOST('propalwayseditable', 'int')),
  1536. 'validate' => GETPOST('propvalidate', 'int')
  1537. );
  1538. if (!empty($addfieldentry['arrayofkeyval']) && !is_array($addfieldentry['arrayofkeyval'])) {
  1539. $tmpdecode = json_decode($addfieldentry['arrayofkeyval'], true);
  1540. if ($tmpdecode) { // If string is already a json
  1541. $addfieldentry['arrayofkeyval'] = $tmpdecode;
  1542. } else { // If string is a list of lines with "key,value"
  1543. $tmparray = dolExplodeIntoArray($addfieldentry['arrayofkeyval'], "\n", ",");
  1544. $addfieldentry['arrayofkeyval'] = $tmparray;
  1545. }
  1546. }
  1547. }
  1548. } else {
  1549. $addfieldentry = array();
  1550. }
  1551. /*if (GETPOST('regeneratemissing'))
  1552. {
  1553. setEventMessages($langs->trans("FeatureNotYetAvailable"), null, 'warnings');
  1554. $error++;
  1555. }*/
  1556. $moduletype = $listofmodules[strtolower($module)]['moduletype'];
  1557. // Edit the class file to write properties
  1558. if (!$error) {
  1559. $object = rebuildObjectClass($destdir, $module, $objectname, $newmask, $srcdir, $addfieldentry, $moduletype);
  1560. if (is_numeric($object) && $object <= 0) {
  1561. $pathoffiletoeditsrc = $destdir.'/class/'.strtolower($objectname).'.class.php';
  1562. setEventMessages($langs->trans('ErrorFailToCreateFile', $pathoffiletoeditsrc), null, 'errors');
  1563. $error++;
  1564. }
  1565. }
  1566. // Edit sql with new properties
  1567. if (!$error) {
  1568. $result = rebuildObjectSql($destdir, $module, $objectname, $newmask, $srcdir, $object, $moduletype);
  1569. if ($result <= 0) {
  1570. setEventMessages($langs->trans('ErrorFailToCreateFile', '.sql'), null, 'errors');
  1571. $error++;
  1572. }
  1573. }
  1574. if (!$error) {
  1575. clearstatcache(true);
  1576. setEventMessages($langs->trans('FilesForObjectUpdated', $objectname), null);
  1577. setEventMessages($langs->trans('WarningDatabaseIsNotUpdated'), null);
  1578. // Make a redirect to reload all data
  1579. header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=objects&module='.$module.($forceddirread ? '@'.$dirread : '').'&tabobj='.$objectname.'&nocache='.time());
  1580. exit;
  1581. }
  1582. }
  1583. if ($dirins && $action == 'confirm_deleteproperty' && $propertykey) {
  1584. $objectname = $tabobj;
  1585. $dirins = $dirread = $listofmodules[strtolower($module)]['moduledescriptorrootpath'];
  1586. $moduletype = $listofmodules[strtolower($module)]['moduletype'];
  1587. $srcdir = $dirread.'/'.strtolower($module);
  1588. $destdir = $dirins.'/'.strtolower($module);
  1589. dol_mkdir($destdir);
  1590. // Edit the class file to write properties
  1591. if (!$error) {
  1592. $object = rebuildObjectClass($destdir, $module, $objectname, $newmask, $srcdir, array(), $propertykey);
  1593. if (is_numeric($object) && $object <= 0) {
  1594. $pathoffiletoeditsrc = $destdir.'/class/'.strtolower($objectname).'.class.php';
  1595. setEventMessages($langs->trans('ErrorFailToCreateFile', $pathoffiletoeditsrc), null, 'errors');
  1596. $error++;
  1597. }
  1598. }
  1599. // Edit sql with new properties
  1600. if (!$error) {
  1601. $result = rebuildObjectSql($destdir, $module, $objectname, $newmask, $srcdir, $object);
  1602. if ($result <= 0) {
  1603. setEventMessages($langs->trans('ErrorFailToCreateFile', '.sql'), null, 'errors');
  1604. $error++;
  1605. }
  1606. }
  1607. if (!$error) {
  1608. setEventMessages($langs->trans('FilesForObjectUpdated', $objectname), null);
  1609. clearstatcache(true);
  1610. // Make a redirect to reload all data
  1611. header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=objects&module='.$module.($forceddirread ? '@'.$dirread : '').'&tabobj='.$objectname);
  1612. exit;
  1613. }
  1614. }
  1615. if ($dirins && $action == 'confirm_deletemodule') {
  1616. if (preg_match('/[^a-z0-9_]/i', $module)) {
  1617. $error++;
  1618. setEventMessages($langs->trans("SpaceOrSpecialCharAreNotAllowed"), null, 'errors');
  1619. }
  1620. if (!$error) {
  1621. $modulelowercase = strtolower($module);
  1622. // Dir for module
  1623. $dir = $dirins.'/'.$modulelowercase;
  1624. $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
  1625. // Dir for module
  1626. $dir = dol_buildpath($modulelowercase, 0);
  1627. // Zip file to build
  1628. $FILENAMEZIP = '';
  1629. // Load module
  1630. dol_include_once($pathtofile);
  1631. $class = 'mod'.$module;
  1632. if (class_exists($class)) {
  1633. try {
  1634. $moduleobj = new $class($db);
  1635. } catch (Exception $e) {
  1636. $error++;
  1637. dol_print_error($db, $e->getMessage());
  1638. }
  1639. } else {
  1640. $error++;
  1641. $langs->load("errors");
  1642. dol_print_error($db, $langs->trans("ErrorFailedToLoadModuleDescriptorForXXX", $module));
  1643. exit;
  1644. }
  1645. $moduleobj->remove();
  1646. $result = dol_delete_dir_recursive($dir);
  1647. if ($result > 0) {
  1648. setEventMessages($langs->trans("DirWasRemoved", $modulelowercase), null);
  1649. clearstatcache(true);
  1650. if (function_exists('opcache_invalidate')) {
  1651. opcache_reset(); // remove the include cache hell !
  1652. }
  1653. header("Location: ".$_SERVER["PHP_SELF"].'?module=deletemodule');
  1654. exit;
  1655. } else {
  1656. setEventMessages($langs->trans("PurgeNothingToDelete"), null, 'warnings');
  1657. }
  1658. }
  1659. $action = '';
  1660. $module = 'deletemodule';
  1661. }
  1662. if ($dirins && $action == 'confirm_deleteobject' && $objectname) {
  1663. if (preg_match('/[^a-z0-9_]/i', $objectname)) {
  1664. $error++;
  1665. setEventMessages($langs->trans("SpaceOrSpecialCharAreNotAllowed"), null, 'errors');
  1666. }
  1667. if (!$error) {
  1668. $modulelowercase = strtolower($module);
  1669. $objectlowercase = strtolower($objectname);
  1670. // Dir for module
  1671. $dir = $dirins.'/'.$modulelowercase;
  1672. // Delete some files
  1673. $filetodelete = array(
  1674. 'myobject_card.php'=>strtolower($objectname).'_card.php',
  1675. 'myobject_note.php'=>strtolower($objectname).'_note.php',
  1676. 'myobject_contact.php'=>strtolower($objectname).'_contact.php',
  1677. 'myobject_document.php'=>strtolower($objectname).'_document.php',
  1678. 'myobject_agenda.php'=>strtolower($objectname).'_agenda.php',
  1679. 'myobject_list.php'=>strtolower($objectname).'_list.php',
  1680. 'admin/myobject_extrafields.php'=>'admin/'.strtolower($objectname).'_extrafields.php',
  1681. 'lib/mymodule_myobject.lib.php'=>'lib/'.strtolower($module).'_'.strtolower($objectname).'.lib.php',
  1682. 'test/phpunit/MyObjectTest.php'=>'test/phpunit/'.strtolower($objectname).'Test.php',
  1683. 'sql/llx_mymodule_myobject.sql'=>'sql/llx_'.strtolower($module).'_'.strtolower($objectname).'.sql',
  1684. 'sql/llx_mymodule_myobject_extrafields.sql'=>'sql/llx_'.strtolower($module).'_'.strtolower($objectname).'_extrafields.sql',
  1685. 'sql/llx_mymodule_myobject.key.sql'=>'sql/llx_'.strtolower($module).'_'.strtolower($objectname).'.key.sql',
  1686. 'sql/llx_mymodule_myobject_extrafields.key.sql'=>'sql/llx_'.strtolower($module).'_'.strtolower($objectname).'_extrafields.key.sql',
  1687. 'scripts/myobject.php'=>'scripts/'.strtolower($objectname).'.php',
  1688. 'class/myobject.class.php'=>'class/'.strtolower($objectname).'.class.php',
  1689. 'class/api_myobject.class.php'=>'class/api_'.strtolower($module).'.class.php',
  1690. 'core/modules/mymodule/mod_myobject_advanced.php'=>'core/modules/'.strtolower($module).'/mod_'.strtolower($objectname).'_advanced.php',
  1691. 'core/modules/mymodule/mod_myobject_standard.php'=>'core/modules/'.strtolower($module).'/mod_'.strtolower($objectname).'_standard.php',
  1692. 'core/modules/mymodule/modules_myobject.php'=>'core/modules/'.strtolower($module).'/modules_'.strtolower($objectname).'.php',
  1693. 'core/modules/mymodule/doc/doc_generic_myobject_odt.modules.php'=>'core/modules/'.strtolower($module).'/doc/doc_generic_'.strtolower($objectname).'_odt.modules.php',
  1694. 'core/modules/mymodule/doc/pdf_standard_myobject.modules.php'=>'core/modules/'.strtolower($module).'/doc/pdf_standard_'.strtolower($objectname).'.modules.php'
  1695. );
  1696. //menu for the object selected
  1697. // load class and check if menu,permission,documentation exist for this object
  1698. $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
  1699. dol_include_once($pathtofile);
  1700. $class = 'mod'.$module;
  1701. if (class_exists($class)) {
  1702. try {
  1703. $moduleobj = new $class($db);
  1704. } catch (Exception $e) {
  1705. $error++;
  1706. dol_print_error($db, $e->getMessage());
  1707. }
  1708. }
  1709. $moduledescriptorfile = $dirins.'/'.strtolower($module).'/core/modules/mod'.$module.'.class.php';
  1710. // delete menus linked to the object
  1711. $menus = $moduleobj->menu;
  1712. $rewriteMenu = checkExistComment($moduledescriptorfile, 0);
  1713. if ($rewriteMenu < 0) {
  1714. setEventMessages($langs->trans("WarningCommentNotFound", $langs->trans("Menus"), "mod".$module."class.php"), null, 'warnings');
  1715. } else {
  1716. reWriteAllMenus($moduledescriptorfile, $menus, $objectname, null, -1);
  1717. }
  1718. // regenerate permissions and delete them
  1719. $permissions = $moduleobj->rights;
  1720. $rewritePerms = checkExistComment($moduledescriptorfile, 1);
  1721. if ($rewritePerms < 0) {
  1722. setEventMessages($langs->trans("WarningCommentNotFound", $langs->trans("Permissions"), "mod".$module."class.php"), null, 'warnings');
  1723. } else {
  1724. reWriteAllPermissions($moduledescriptorfile, $permissions, null, null, $objectname, '', -1);
  1725. }
  1726. if ($rewritePerms && $rewriteMenu) {
  1727. // check if documentation has been generated
  1728. $file_doc = $dirins.'/'.strtolower($module).'/doc/Documentation.asciidoc';
  1729. deletePropsAndPermsFromDoc($file_doc, $objectname);
  1730. clearstatcache(true);
  1731. if (function_exists('opcache_invalidate')) {
  1732. opcache_reset(); // remove the include cache hell !
  1733. }
  1734. $resultko = 0;
  1735. foreach ($filetodelete as $tmpfiletodelete) {
  1736. $resulttmp = dol_delete_file($dir.'/'.$tmpfiletodelete, 0, 0, 1);
  1737. $resulttmp = dol_delete_file($dir.'/'.$tmpfiletodelete.'.back', 0, 0, 1);
  1738. if (!$resulttmp) {
  1739. $resultko++;
  1740. }
  1741. }
  1742. if ($resultko == 0) {
  1743. setEventMessages($langs->trans("FilesDeleted"), null);
  1744. } else {
  1745. setEventMessages($langs->trans("ErrorSomeFilesCouldNotBeDeleted"), null, 'warnings');
  1746. }
  1747. }
  1748. }
  1749. $action = '';
  1750. if (! $error) {
  1751. $tabobj = 'newobject';
  1752. } else {
  1753. $tabobj = 'deleteobject';
  1754. }
  1755. // check if module is enabled
  1756. if (isModEnabled(strtolower($module))) {
  1757. $result = unActivateModule(strtolower($module));
  1758. dolibarr_set_const($db, "MAIN_IHM_PARAMS_REV", (int) $conf->global->MAIN_IHM_PARAMS_REV + 1, 'chaine', 0, '', $conf->entity);
  1759. if ($result) {
  1760. setEventMessages($result, null, 'errors');
  1761. }
  1762. setEventMessages($langs->trans('WarningModuleNeedRefresh', $langs->transnoentities($module)), null, 'warnings');
  1763. header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=objects&tabobj=deleteobject&module='.urlencode($module));
  1764. exit;
  1765. }
  1766. }
  1767. if (($dirins && $action == 'confirm_deletedictionary' && $dicname) || ($dirins && $action == 'confirm_deletedictionary' && GETPOST('dictionnarykey'))) {
  1768. $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
  1769. $destdir = $dirins.'/'.strtolower($module);
  1770. $moduledescriptorfile = $dirins.'/'.strtolower($module).'/core/modules/mod'.$module.'.class.php';
  1771. if (preg_match('/[^a-z0-9_]/i', $dicname)) {
  1772. $error++;
  1773. setEventMessages($langs->trans("SpaceOrSpecialCharAreNotAllowed"), null, 'errors');
  1774. }
  1775. if (!empty($dicname)) {
  1776. $newdicname = $dicname;
  1777. if (!preg_match('/^c_/', $newdicname)) {
  1778. $newdicname = 'c_'.strtolower($dicname);
  1779. }
  1780. }
  1781. dol_include_once($pathtofile);
  1782. $class = 'mod'.$module;
  1783. if (class_exists($class)) {
  1784. try {
  1785. $moduleobj = new $class($db);
  1786. } catch (Exception $e) {
  1787. $error++;
  1788. dol_print_error($db, $e->getMessage());
  1789. }
  1790. } else {
  1791. $error++;
  1792. $langs->load("errors");
  1793. dol_print_error($db, $langs->trans("ErrorFailedToLoadModuleDescriptorForXXX", $module));
  1794. exit;
  1795. }
  1796. $dicts = $moduleobj->dictionaries;
  1797. $checkComment = checkExistComment($moduledescriptorfile, 2);
  1798. if ($checkComment < 0) {
  1799. $error++;
  1800. setEventMessages($langs->trans("WarningCommentNotFound", $langs->trans("Dictionaries"), "mod".$module."class.php"), null, 'warnings');
  1801. }
  1802. if (!empty(GETPOST('dictionnarykey'))) {
  1803. $newdicname = $dicts['tabname'][GETPOST('dictionnarykey')-1];
  1804. }
  1805. //chercher la table dicname
  1806. $query = "SHOW TABLES LIKE '" . MAIN_DB_PREFIX.strtolower($newdicname) . "'";
  1807. $checkTable = $db->query($query);
  1808. if ($checkTable && $db->num_rows($checkTable) <= 0) {
  1809. $error++;
  1810. }
  1811. // search the key by name
  1812. $keyToDelete = null;
  1813. foreach ($dicts['tabname'] as $key => $table) {
  1814. //var_dump($table." /////// ".$newdicname);exit;
  1815. if (strtolower($table) === $newdicname) {
  1816. $keyToDelete = $key;
  1817. break;
  1818. }
  1819. }
  1820. // delete all dicname's key values from the dictionary
  1821. if ($keyToDelete !== null) {
  1822. $keysToDelete = ['tabname', 'tablib', 'tabsql', 'tabsqlsort', 'tabfield', 'tabfieldvalue', 'tabfieldinsert', 'tabrowid', 'tabcond', 'tabhelp'];
  1823. foreach ($keysToDelete as $key) {
  1824. unset($dicts[$key][$keyToDelete]);
  1825. }
  1826. } else {
  1827. $error++;
  1828. setEventMessages($langs->trans("ErrorDictionaryNotFound", ucfirst($dicname)), null, 'errors');
  1829. }
  1830. if (!$error) {
  1831. // delete table
  1832. $_results = $db->DDLDropTable(MAIN_DB_PREFIX.strtolower($newdicname));
  1833. if ($_results < 0) {
  1834. dol_print_error($db);
  1835. $langs->load("errors");
  1836. setEventMessages($langs->trans("ErrorTableNotFound", $newdicname), null, 'errors');
  1837. }
  1838. // rebuild file after update dictionaries
  1839. $result = updateDictionaryInFile($module, $moduledescriptorfile, $dicts);
  1840. if ($result > 0) {
  1841. setEventMessages($langs->trans("DictionaryDeleted", ucfirst(substr($newdicname, 2))), null);
  1842. }
  1843. if (function_exists('opcache_invalidate')) {
  1844. opcache_reset(); // remove the include cache hell !
  1845. }
  1846. clearstatcache(true);
  1847. header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=dictionaries&module='.$module.($forceddirread ? '@'.$dirread : ''));
  1848. exit;
  1849. }
  1850. }
  1851. if ($dirins && $action == 'updatedictionary' && GETPOST('dictionnarykey')) {
  1852. $keydict = GETPOST('dictionnarykey') - 1 ;
  1853. $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
  1854. $destdir = $dirins.'/'.strtolower($module);
  1855. $moduledescriptorfile = $dirins.'/'.strtolower($module).'/core/modules/mod'.$module.'.class.php';
  1856. dol_include_once($pathtofile);
  1857. $class = 'mod'.$module;
  1858. if (class_exists($class)) {
  1859. try {
  1860. $moduleobj = new $class($db);
  1861. } catch (Exception $e) {
  1862. $error++;
  1863. dol_print_error($db, $e->getMessage());
  1864. }
  1865. } else {
  1866. $error++;
  1867. $langs->load("errors");
  1868. dol_print_error($db, $langs->trans("ErrorFailedToLoadModuleDescriptorForXXX", $module));
  1869. exit;
  1870. }
  1871. $dicts = $moduleobj->dictionaries;
  1872. if (!empty(GETPOST('tablib')) && GETPOST('tablib') !== $dicts['tablib'][$keydict]) {
  1873. $dicts['tablib'][$keydict] = ucfirst(strtolower(GETPOST('tablib')));
  1874. $checkComment = checkExistComment($moduledescriptorfile, 2);
  1875. if ($checkComment < 0) {
  1876. setEventMessages($langs->trans("WarningCommentNotFound", $langs->trans("Dictionaries"), "mod".$module."class.php"), null, 'warnings');
  1877. } else {
  1878. $updateDict = updateDictionaryInFile($module, $moduledescriptorfile, $dicts);
  1879. if ($updateDict > 0) {
  1880. setEventMessages($langs->trans("DictionaryNameUpdated", ucfirst(GETPOST('tablib'))), null);
  1881. }
  1882. if (function_exists('opcache_invalidate')) {
  1883. opcache_reset(); // remove the include cache hell !
  1884. }
  1885. clearstatcache(true);
  1886. header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=dictionaries&module='.$module.($forceddirread ? '@'.$dirread : ''));
  1887. exit;
  1888. }
  1889. }
  1890. //var_dump(GETPOST('tablib'));exit;
  1891. }
  1892. if ($dirins && $action == 'generatedoc') {
  1893. $modulelowercase = strtolower($module);
  1894. // Dir for module
  1895. $dirofmodule = dol_buildpath($modulelowercase, 0).'/doc';
  1896. $FILENAMEDOC = strtolower($module).'.html';
  1897. $util = new Utils($db);
  1898. $result = $util->generateDoc($module);
  1899. if ($result > 0) {
  1900. setEventMessages($langs->trans("DocFileGeneratedInto", $dirofmodule), null);
  1901. } else {
  1902. setEventMessages($util->error, $util->errors, 'errors');
  1903. }
  1904. }
  1905. if ($dirins && $action == 'generatepackage') {
  1906. $modulelowercase = strtolower($module);
  1907. $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
  1908. // Dir for module
  1909. $dir = dol_buildpath($modulelowercase, 0);
  1910. // Zip file to build
  1911. $FILENAMEZIP = '';
  1912. // Load module
  1913. dol_include_once($pathtofile);
  1914. $class = 'mod'.$module;
  1915. if (class_exists($class)) {
  1916. try {
  1917. $moduleobj = new $class($db);
  1918. } catch (Exception $e) {
  1919. $error++;
  1920. dol_print_error($db, $e->getMessage());
  1921. }
  1922. } else {
  1923. $error++;
  1924. $langs->load("errors");
  1925. dol_print_error($db, $langs->trans("ErrorFailedToLoadModuleDescriptorForXXX", $module));
  1926. exit;
  1927. }
  1928. $arrayversion = explode('.', $moduleobj->version, 3);
  1929. if (count($arrayversion)) {
  1930. $FILENAMEZIP = "module_".$modulelowercase.'-'.$arrayversion[0].(empty($arrayversion[1]) ? '.0' : '.'.$arrayversion[1]).(empty($arrayversion[2]) ? '' : '.'.$arrayversion[2]).'.zip';
  1931. $dirofmodule = dol_buildpath($modulelowercase, 0).'/bin';
  1932. $outputfilezip = $dirofmodule.'/'.$FILENAMEZIP;
  1933. if ($dirofmodule) {
  1934. if (!dol_is_dir($dirofmodule)) {
  1935. dol_mkdir($dirofmodule);
  1936. }
  1937. // Note: We exclude /bin/ to not include the already generated zip
  1938. $result = dol_compress_dir($dir, $outputfilezip, 'zip', '/\/bin\/|\.git|\.old|\.back|\.ssh/', $modulelowercase);
  1939. } else {
  1940. $result = -1;
  1941. }
  1942. if ($result > 0) {
  1943. setEventMessages($langs->trans("ZipFileGeneratedInto", $outputfilezip), null);
  1944. } else {
  1945. $error++;
  1946. $langs->load("errors");
  1947. setEventMessages($langs->trans("ErrorFailToGenerateFile", $outputfilezip), null, 'errors');
  1948. }
  1949. } else {
  1950. $error++;
  1951. $langs->load("errors");
  1952. setEventMessages($langs->trans("ErrorCheckVersionIsDefined"), null, 'errors');
  1953. }
  1954. }
  1955. // Add permission
  1956. if ($dirins && $action == 'addright' && !empty($module) && empty($cancel)) {
  1957. $error = 0;
  1958. // load class and check if right exist
  1959. $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
  1960. dol_include_once($pathtofile);
  1961. $class = 'mod'.$module;
  1962. if (class_exists($class)) {
  1963. try {
  1964. $moduleobj = new $class($db);
  1965. } catch (Exception $e) {
  1966. $error++;
  1967. dol_print_error($db, $e->getMessage());
  1968. }
  1969. }
  1970. // verify informations entred
  1971. if (!GETPOST('label', 'alpha')) {
  1972. $error++;
  1973. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Label")), null, 'errors');
  1974. }
  1975. if (!GETPOST('permissionObj', 'alpha')) {
  1976. $error++;
  1977. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Rights")), null, 'errors');
  1978. }
  1979. $id = GETPOST('id', 'alpha');
  1980. $label = GETPOST('label', 'alpha');
  1981. $objectForPerms = strtolower(GETPOST('permissionObj', 'alpha'));
  1982. $crud = GETPOST('crud', 'alpha');
  1983. //check existing object permission
  1984. $counter = 0;
  1985. $permsForObject =array();
  1986. $permissions = $moduleobj->rights;
  1987. $allObject = array();
  1988. $countPerms = count($permissions);
  1989. for ($i =0; $i<$countPerms; $i++) {
  1990. if ($permissions[$i][4] == $objectForPerms) {
  1991. $counter++;
  1992. if (count($permsForObject) < 3) {
  1993. $permsForObject[] = $permissions[$i];
  1994. }
  1995. }
  1996. $allObject[] = $permissions[$i][4];
  1997. }
  1998. // check if label of object already exists
  1999. $countPermsObj = count($permsForObject);
  2000. for ($j = 0; $j<$countPermsObj; $j++) {
  2001. if (in_array($crud, $permsForObject[$j])) {
  2002. $error++;
  2003. setEventMessages($langs->trans("ErrorExistingPermission", $langs->transnoentities($crud), $langs->transnoentities($objectForPerms)), null, 'errors');
  2004. }
  2005. }
  2006. if (!$error) {
  2007. $key = $countPerms + 1;
  2008. //prepare right to add
  2009. $rightToAdd = [
  2010. 0=> $id,
  2011. 1=>$label,
  2012. 4=>$objectForPerms,
  2013. 5=>$crud
  2014. ];
  2015. if (isModEnabled(strtolower($module))) {
  2016. $result = unActivateModule(strtolower($module));
  2017. dolibarr_set_const($db, "MAIN_IHM_PARAMS_REV", (int) $conf->global->MAIN_IHM_PARAMS_REV + 1, 'chaine', 0, '', $conf->entity);
  2018. if ($result) {
  2019. setEventMessages($result, null, 'errors');
  2020. }
  2021. setEventMessages($langs->trans('WarningModuleNeedRefresh', $langs->transnoentities($module)), null, 'warnings');
  2022. }
  2023. }
  2024. $moduledescriptorfile = $dirins.'/'.strtolower($module).'/core/modules/mod'.$module.'.class.php';
  2025. //rewriting all permissions after add a right
  2026. $rewrite = checkExistComment($moduledescriptorfile, 1);
  2027. if ($rewrite < 0) {
  2028. setEventMessages($langs->trans("WarningCommentNotFound", $langs->trans("Permissions"), "mod".$module."class.php"), null, 'warnings');
  2029. } else {
  2030. reWriteAllPermissions($moduledescriptorfile, $permissions, $key, $rightToAdd, '', '', 1);
  2031. setEventMessages($langs->trans('PermissionAddedSuccesfuly'), null);
  2032. clearstatcache(true);
  2033. if (function_exists('opcache_invalidate')) {
  2034. opcache_reset(); // remove the include cache hell !
  2035. }
  2036. header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=permissions&module='.$module);
  2037. exit;
  2038. }
  2039. }
  2040. // Update permission
  2041. if ($dirins && GETPOST('action') == 'update_right' && GETPOST('modifyright')&& empty($cancel)) {
  2042. $error = 0;
  2043. // load class and check if right exist
  2044. $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
  2045. dol_include_once($pathtofile);
  2046. $class = 'mod'.$module;
  2047. if (class_exists($class)) {
  2048. try {
  2049. $moduleobj = new $class($db);
  2050. } catch (Exception $e) {
  2051. $error++;
  2052. dol_print_error($db, $e->getMessage());
  2053. }
  2054. }
  2055. // verify informations entred
  2056. if (!GETPOST('label', 'alpha')) {
  2057. $error++;
  2058. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Label")), null, 'errors');
  2059. }
  2060. if (!GETPOST('permissionObj', 'alpha')) {
  2061. $error++;
  2062. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Rights")), null, 'errors');
  2063. }
  2064. $label = GETPOST('label', 'alpha');
  2065. $objectForPerms = strtolower(GETPOST('permissionObj', 'alpha'));
  2066. $crud = GETPOST('crud', 'alpha');
  2067. if ($label == "Read objects of $module" && $crud != "read") {
  2068. $crud = "read";
  2069. $label == "Read objects of $module";
  2070. }
  2071. if ($label == "Create/Update objects of $module" && $crud != "write") {
  2072. $crud = "write";
  2073. $label == "Create/Update objects of $module";
  2074. }
  2075. if ($label == "Delete objects of $module" && $crud != "delete") {
  2076. $crud = "delete";
  2077. $label == "Delete objects of $module";
  2078. }
  2079. $permissions = $moduleobj->rights;
  2080. $key =(int) GETPOST('counter')-1;
  2081. //get permission want to delete from permissions array
  2082. $x1 = $permissions[$key][1];
  2083. $x2 = $permissions[$key][4];
  2084. $x3 = $permissions[$key][5];
  2085. //check existing object permission
  2086. $counter = 0;
  2087. $permsForObject =array();
  2088. $permissions = $moduleobj->rights;
  2089. $firstRight = 0;
  2090. $existRight = 0;
  2091. $allObject = array();
  2092. $countPerms = count($permissions);
  2093. for ($i =0; $i<$countPerms; $i++) {
  2094. if ($permissions[$i][4] == $objectForPerms) {
  2095. $counter++;
  2096. if (count($permsForObject) < 3) {
  2097. $permsForObject[] = $permissions[$i];
  2098. }
  2099. }
  2100. $allObject[] = $permissions[$i][4];
  2101. }
  2102. if ($label != $x1 && $crud != $x3) {
  2103. $countPermsObj = count($permsForObject);
  2104. for ($j = 0; $j<$countPermsObj; $j++) {
  2105. if (in_array($label, $permsForObject[$j])) {
  2106. $error++;
  2107. setEventMessages($langs->trans("ErrorExistingPermission", $langs->transnoentities($label), $langs->transnoentities($objectForPerms)), null, 'errors');
  2108. }
  2109. }
  2110. }
  2111. if (!$error) {
  2112. if (isModEnabled(strtolower($module))) {
  2113. $result = unActivateModule(strtolower($module));
  2114. dolibarr_set_const($db, "MAIN_IHM_PARAMS_REV", (int) $conf->global->MAIN_IHM_PARAMS_REV + 1, 'chaine', 0, '', $conf->entity);
  2115. if ($result) {
  2116. setEventMessages($result, null, 'errors');
  2117. }
  2118. setEventMessages($langs->trans('WarningModuleNeedRefresh', $langs->transnoentities($module)), null, 'warnings');
  2119. }
  2120. $moduledescriptorfile = $dirins.'/'.strtolower($module).'/core/modules/mod'.$module.'.class.php';
  2121. // rewriting all permissions after update permission needed
  2122. $rewrite = checkExistComment($moduledescriptorfile, 1);
  2123. if ($rewrite < 0) {
  2124. setEventMessages($langs->trans("WarningCommentNotFound", $langs->trans("Permissions"), "mod".$module."class.php"), null, 'warnings');
  2125. } else {
  2126. reWriteAllPermissions($moduledescriptorfile, $permissions, $key, $rightUpdated, '', '', 2);
  2127. setEventMessages($langs->trans('PermissionUpdatedSuccesfuly'), null);
  2128. clearstatcache(true);
  2129. if (function_exists('opcache_invalidate')) {
  2130. opcache_reset(); // remove the include cache hell !
  2131. }
  2132. header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=permissions&module='.$module);
  2133. exit;
  2134. }
  2135. }
  2136. }
  2137. // Delete permission
  2138. if ($dirins && $action == 'confirm_deleteright' && !empty($module) && GETPOST('permskey', 'int')) {
  2139. $error = 0;
  2140. // load class and check if right exist
  2141. $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
  2142. dol_include_once($pathtofile);
  2143. $class = 'mod'.$module;
  2144. if (class_exists($class)) {
  2145. try {
  2146. $moduleobj = new $class($db);
  2147. } catch (Exception $e) {
  2148. $error++;
  2149. dol_print_error($db, $e->getMessage());
  2150. }
  2151. }
  2152. $permissions = $moduleobj->rights;
  2153. $key = (int) GETPOST('permskey', 'int')-1;
  2154. if (!$error) {
  2155. // check if module is enabled
  2156. if (isModEnabled(strtolower($module))) {
  2157. $result = unActivateModule(strtolower($module));
  2158. dolibarr_set_const($db, "MAIN_IHM_PARAMS_REV", (int) $conf->global->MAIN_IHM_PARAMS_REV + 1, 'chaine', 0, '', $conf->entity);
  2159. if ($result) {
  2160. setEventMessages($result, null, 'errors');
  2161. }
  2162. setEventMessages($langs->trans('WarningModuleNeedRefresh', $langs->transnoentities($module)), null, 'warnings');
  2163. header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=permissions&module='.$module);
  2164. exit;
  2165. }
  2166. // rewriting all permissions
  2167. $moduledescriptorfile = $dirins.'/'.strtolower($module).'/core/modules/mod'.$module.'.class.php';
  2168. $rewrite = checkExistComment($moduledescriptorfile, 1);
  2169. if ($rewrite < 0) {
  2170. setEventMessages($langs->trans("WarningCommentNotFound", $langs->trans("Permissions"), "mod".$module."class.php"), null, 'warnings');
  2171. } else {
  2172. reWriteAllPermissions($moduledescriptorfile, $permissions, $key, null, '', '', 0);
  2173. setEventMessages($langs->trans('PermissionDeletedSuccesfuly'), null);
  2174. clearstatcache(true);
  2175. if (function_exists('opcache_invalidate')) {
  2176. opcache_reset(); // remove the include cache hell !
  2177. }
  2178. header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=permissions&module='.$module);
  2179. exit;
  2180. }
  2181. }
  2182. }
  2183. // Save file
  2184. if ($action == 'savefile' && empty($cancel)) {
  2185. $relofcustom = basename($dirins);
  2186. if ($relofcustom) {
  2187. // Check that relative path ($file) start with name 'custom'
  2188. if (!preg_match('/^'.$relofcustom.'/', $file)) {
  2189. $file = $relofcustom.'/'.$file;
  2190. }
  2191. $pathoffile = dol_buildpath($file, 0);
  2192. $pathoffilebackup = dol_buildpath($file.'.back', 0);
  2193. // Save old version
  2194. if (dol_is_file($pathoffile)) {
  2195. dol_copy($pathoffile, $pathoffilebackup, 0, 1);
  2196. }
  2197. $check = 'restricthtml';
  2198. $srclang = dol_mimetype($pathoffile, '', 3);
  2199. if ($srclang == 'md') {
  2200. $check = 'restricthtml';
  2201. }
  2202. if ($srclang == 'lang') {
  2203. $check = 'restricthtml';
  2204. }
  2205. if ($srclang == 'php') {
  2206. $check = 'none';
  2207. }
  2208. $content = GETPOST('editfilecontent', $check);
  2209. // Save file on disk
  2210. if ($content) {
  2211. dol_delete_file($pathoffile);
  2212. $result = file_put_contents($pathoffile, $content);
  2213. if ($result) {
  2214. dolChmod($pathoffile, $newmask);
  2215. setEventMessages($langs->trans("FileSaved"), null);
  2216. } else {
  2217. setEventMessages($langs->trans("ErrorFailedToSaveFile"), null, 'errors');
  2218. }
  2219. } else {
  2220. setEventMessages($langs->trans("ContentCantBeEmpty"), null, 'errors');
  2221. //$action='editfile';
  2222. $error++;
  2223. }
  2224. }
  2225. }
  2226. // Enable module
  2227. if ($action == 'set' && $user->admin) {
  2228. $param = '';
  2229. if ($module) {
  2230. $param .= '&module='.urlencode($module);
  2231. }
  2232. if ($tab) {
  2233. $param .= '&tab='.urlencode($tab);
  2234. }
  2235. if ($tabobj) {
  2236. $param .= '&tabobj='.urlencode($tabobj);
  2237. }
  2238. $value = GETPOST('value', 'alpha');
  2239. $resarray = activateModule($value);
  2240. if (!empty($resarray['errors'])) {
  2241. setEventMessages('', $resarray['errors'], 'errors');
  2242. } else {
  2243. //var_dump($resarray);exit;
  2244. if ($resarray['nbperms'] > 0) {
  2245. $tmpsql = "SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX."user WHERE admin <> 1";
  2246. $resqltmp = $db->query($tmpsql);
  2247. if ($resqltmp) {
  2248. $obj = $db->fetch_object($resqltmp);
  2249. //var_dump($obj->nb);exit;
  2250. if ($obj && $obj->nb > 1) {
  2251. $msg = $langs->trans('ModuleEnabledAdminMustCheckRights');
  2252. setEventMessages($msg, null, 'warnings');
  2253. }
  2254. } else {
  2255. dol_print_error($db);
  2256. }
  2257. }
  2258. }
  2259. header("Location: ".$_SERVER["PHP_SELF"]."?".$param);
  2260. exit;
  2261. }
  2262. // Disable module
  2263. if ($action == 'reset' && $user->admin) {
  2264. $param = '';
  2265. if ($module) {
  2266. $param .= '&module='.urlencode($module);
  2267. }
  2268. if ($tab) {
  2269. $param .= '&tab='.urlencode($tab);
  2270. }
  2271. if ($tabobj) {
  2272. $param .= '&tabobj='.urlencode($tabobj);
  2273. }
  2274. $value = GETPOST('value', 'alpha');
  2275. $result = unActivateModule($value);
  2276. if ($result) {
  2277. setEventMessages($result, null, 'errors');
  2278. }
  2279. header("Location: ".$_SERVER["PHP_SELF"]."?".$param);
  2280. exit;
  2281. }
  2282. // delete menu
  2283. if ($dirins && $action == 'confirm_deletemenu' && GETPOST('menukey', 'int')) {
  2284. // check if module is enabled
  2285. if (isModEnabled(strtolower($module))) {
  2286. $result = unActivateModule(strtolower($module));
  2287. dolibarr_set_const($db, "MAIN_IHM_PARAMS_REV", (int) $conf->global->MAIN_IHM_PARAMS_REV + 1, 'chaine', 0, '', $conf->entity);
  2288. if ($result) {
  2289. setEventMessages($result, null, 'errors');
  2290. }
  2291. setEventMessages($langs->trans('WarningModuleNeedRefresh', $langs->transnoentities($module)), null, 'warnings');
  2292. header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=menus&module='.$module);
  2293. exit;
  2294. }
  2295. // load class and check if menu exist
  2296. $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
  2297. dol_include_once($pathtofile);
  2298. $class = 'mod'.$module;
  2299. if (class_exists($class)) {
  2300. try {
  2301. $moduleobj = new $class($db);
  2302. } catch (Exception $e) {
  2303. $error++;
  2304. dol_print_error($db, $e->getMessage());
  2305. }
  2306. }
  2307. // get all objects and convert value to lower case for compare
  2308. $dir = $listofmodules[strtolower($module)]['moduledescriptorrootpath'];
  2309. $destdir = $dir.'/'.strtolower($module);
  2310. $objects = dolGetListOfObjectClasses($destdir);
  2311. $result = array_map('strtolower', $objects);
  2312. $menus = $moduleobj->menu;
  2313. $key = (int) GETPOST('menukey', 'int');
  2314. $moduledescriptorfile = $dirins.'/'.strtolower($module).'/core/modules/mod'.$module.'.class.php';
  2315. $checkcomment = checkExistComment($moduledescriptorfile, 0);
  2316. if ($checkcomment < 0) {
  2317. setEventMessages($langs->trans("WarningCommentNotFound", $langs->trans("Menus"), "mod".$module."class.php"), null, 'warnings');
  2318. } else {
  2319. if ($menus[$key]['fk_menu'] === 'fk_mainmenu='.strtolower($module)) {
  2320. if (in_array(strtolower($menus[$key]['leftmenu']), $result)) {
  2321. reWriteAllMenus($moduledescriptorfile, $menus, $menus[$key]['leftmenu'], $key, -1);
  2322. } else {
  2323. reWriteAllMenus($moduledescriptorfile, $menus, null, $key, 0);
  2324. }
  2325. } else {
  2326. reWriteAllMenus($moduledescriptorfile, $menus, null, $key, 0);
  2327. }
  2328. clearstatcache(true);
  2329. if (function_exists('opcache_invalidate')) {
  2330. opcache_reset(); // remove the include cache hell !
  2331. }
  2332. setEventMessages($langs->trans('MenuDeletedSuccessfuly'), null);
  2333. header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=menus&module='.$module);
  2334. exit;
  2335. }
  2336. }
  2337. // Add menu in module without initial object
  2338. if ($dirins && $action == 'addmenu' && empty($cancel)) {
  2339. // check if module is enabled
  2340. if (isModEnabled(strtolower($module))) {
  2341. $result = unActivateModule(strtolower($module));
  2342. dolibarr_set_const($db, "MAIN_IHM_PARAMS_REV", (int) $conf->global->MAIN_IHM_PARAMS_REV + 1, 'chaine', 0, '', $conf->entity);
  2343. if ($result) {
  2344. setEventMessages($result, null, 'errors');
  2345. }
  2346. setEventMessages($langs->trans('WarningModuleNeedRefresh', $langs->transnoentities($module)), null, 'warnings');
  2347. header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=menus&module='.$module);
  2348. exit;
  2349. }
  2350. $error = 0;
  2351. // load class and check if right exist
  2352. $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
  2353. dol_include_once($pathtofile);
  2354. $class = 'mod'.$module;
  2355. if (class_exists($class)) {
  2356. try {
  2357. $moduleobj = new $class($db);
  2358. } catch (Exception $e) {
  2359. $error++;
  2360. dol_print_error($db, $e->getMessage());
  2361. }
  2362. }
  2363. // get all menus
  2364. $menus = $moduleobj->menu;
  2365. //verify fields required
  2366. if (!GETPOST('type', 'alpha')) {
  2367. $error++;
  2368. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Type")), null, 'errors');
  2369. }
  2370. if (!GETPOST('titre', 'alpha')) {
  2371. $error++;
  2372. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Title")), null, 'errors');
  2373. }
  2374. if (!GETPOST('user', 'alpha')) {
  2375. $error++;
  2376. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("DetailUser")), null, 'errors');
  2377. }
  2378. if (!GETPOST('url', 'alpha')) {
  2379. $error++;
  2380. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Url")), null, 'errors');
  2381. }
  2382. if (!empty(GETPOST('target'))) {
  2383. $targets = array('_blank','_self','_parent','_top','');
  2384. if (!in_array(GETPOST('target'), $targets)) {
  2385. $error++;
  2386. setEventMessages($langs->trans("ErrorFieldValue", $langs->transnoentities("target")), null, 'errors');
  2387. }
  2388. }
  2389. // check if title or url already exist in menus
  2390. foreach ($menus as $menu) {
  2391. if (!empty(GETPOST('url')) && GETPOST('url') == $menu['url']) {
  2392. $error++;
  2393. setEventMessages($langs->trans("ErrorFieldExist", $langs->transnoentities("url")), null, 'errors');
  2394. break;
  2395. }
  2396. if (strtolower(GETPOST('titre')) == strtolower($menu['titre'])) {
  2397. $error++;
  2398. setEventMessages($langs->trans("ErrorFieldExist", $langs->transnoentities("titre")), null, 'errors');
  2399. break;
  2400. }
  2401. }
  2402. if (GETPOST('type', 'alpha') == 'left' && !empty(GETPOST('lefmenu', 'alpha'))) {
  2403. if (!str_contains(GETPOST('leftmenu'), strtolower($module))) {
  2404. $error++;
  2405. setEventMessages($langs->trans("WarningFieldsMustContains", $langs->transnoentities("leftmenu")), null, 'errors');
  2406. }
  2407. }
  2408. $dirins = $listofmodules[strtolower($module)]['moduledescriptorrootpath'];
  2409. $destdir = $dirins.'/'.strtolower($module);
  2410. $objects = dolGetListOfObjectClasses($destdir);
  2411. if (GETPOST('type', 'alpha') == 'left') {
  2412. if (empty(GETPOST('leftmenu')) && count($objects) >0) {
  2413. $error++;
  2414. setEventMessages($langs->trans("ErrorCoherenceMenu", $langs->transnoentities("leftmenu"), $langs->transnoentities("type")), null, 'errors');
  2415. }
  2416. }
  2417. if (GETPOST('type', 'alpha') == 'top') {
  2418. $error++;
  2419. setEventMessages($langs->trans("ErrorTypeMenu", $langs->transnoentities("type")), null, 'errors');
  2420. }
  2421. $moduledescriptorfile = $dirins.'/'.strtolower($module).'/core/modules/mod'.$module.'.class.php';
  2422. if (!$error) {
  2423. //stock forms in array
  2424. $menuToAdd = array(
  2425. 'fk_menu' => GETPOST('fk_menu', 'alpha'),
  2426. 'type' => GETPOST('type', 'alpha'),
  2427. 'titre' => ucfirst(GETPOST('titre', 'alpha')),
  2428. 'prefix' => '',
  2429. 'mainmenu' => GETPOST('mainmenu', 'alpha'),
  2430. 'leftmenu' => GETPOST('leftmenu', 'alpha'),
  2431. 'url' => GETPOST('url', 'alpha'),
  2432. 'langs' => strtolower($module)."@".strtolower($module),
  2433. 'position' => '',
  2434. 'enabled' => GETPOST('enabled', 'alpha'),
  2435. 'perms' => '$user->hasRight("'.strtolower($module).'", "'.GETPOST('objects', 'alpha').'", "'.GETPOST('perms', 'alpha').'")',
  2436. 'target' => GETPOST('target', 'alpha'),
  2437. 'user' => GETPOST('user', 'alpha'),
  2438. );
  2439. if (GETPOST('type') == 'left') {
  2440. unset($menuToAdd['prefix']);
  2441. if (empty(GETPOST('fk_menu'))) {
  2442. $menuToAdd['fk_menu'] = 'fk_mainmenu='.GETPOST('mainmenu', 'alpha');
  2443. } else {
  2444. $menuToAdd['fk_menu'] = 'fk_mainmenu='.GETPOST('mainmenu', 'alpha').',fk_leftmenu='.GETPOST('fk_menu');
  2445. }
  2446. }
  2447. if (GETPOST('enabled') == '1') {
  2448. $menuToAdd['enabled'] = 'isModEnabled("'.strtolower($module).'")';
  2449. } else {
  2450. $menuToAdd['enabled'] = "0";
  2451. }
  2452. if (empty(GETPOST('objects'))) {
  2453. $menuToAdd['perms'] = '1';
  2454. }
  2455. $checkcomment = checkExistComment($moduledescriptorfile, 0);
  2456. if ($checkcomment < 0) {
  2457. setEventMessages($langs->trans("WarningCommentNotFound", $langs->trans("Menus"), "mod".$module."class.php"), null, 'warnings');
  2458. } else {
  2459. // Write all menus
  2460. $result = reWriteAllMenus($moduledescriptorfile, $menus, $menuToAdd, null, 1);
  2461. clearstatcache(true);
  2462. if (function_exists('opcache_invalidate')) {
  2463. opcache_reset();
  2464. }
  2465. /*if ($result < 0) {
  2466. setEventMessages($langs->trans('ErrorMenuExistValue'), null, 'errors');
  2467. header("Location: ".$_SERVER["PHP_SELF"].'?action=editmenu&token='.newToken().'&menukey='.urlencode($key+1).'&tab='.urlencode($tab).'&module='.urlencode($module).'&tabobj='.($key+1));
  2468. exit;
  2469. }*/
  2470. header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=menus&module='.$module);
  2471. setEventMessages($langs->trans('MenuAddedSuccesfuly'), null);
  2472. exit;
  2473. }
  2474. }
  2475. }
  2476. // Modify a menu entry
  2477. if ($dirins && $action == "update_menu" && GETPOST('menukey', 'int') && GETPOST('tabobj')) {
  2478. $objectname = GETPOST('tabobj');
  2479. $dirins = $listofmodules[strtolower($module)]['moduledescriptorrootpath'];
  2480. $destdir = $dirins.'/'.strtolower($module);
  2481. $objects = dolGetListOfObjectClasses($destdir);
  2482. if (empty($cancel)) {
  2483. if (isModEnabled(strtolower($module))) {
  2484. $result = unActivateModule(strtolower($module));
  2485. dolibarr_set_const($db, "MAIN_IHM_PARAMS_REV", (int) $conf->global->MAIN_IHM_PARAMS_REV + 1, 'chaine', 0, '', $conf->entity);
  2486. if ($result) {
  2487. setEventMessages($result, null, 'errors');
  2488. }
  2489. setEventMessages($langs->trans('WarningModuleNeedRefresh', $langs->transnoentities($module)), null, 'warnings');
  2490. header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=menus&module='.$module);
  2491. exit;
  2492. }
  2493. $error = 0;
  2494. // for loading class and the menu wants to modify
  2495. $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
  2496. dol_include_once($pathtofile);
  2497. $class = 'mod'.$module;
  2498. if (class_exists($class)) {
  2499. try {
  2500. $moduleobj = new $class($db);
  2501. } catch (Exception $e) {
  2502. $error++;
  2503. dol_print_error($db, $e->getMessage());
  2504. }
  2505. }
  2506. $menus = $moduleobj->menu;
  2507. $key = (int) GETPOST('menukey', 'int') - 1;
  2508. $moduledescriptorfile = $dirins.'/'.strtolower($module).'/core/modules/mod'.$module.'.class.php';
  2509. //stock forms in array
  2510. $menuModify = array(
  2511. 'fk_menu' => GETPOST('fk_menu', 'alpha'),
  2512. 'type' => GETPOST('type', 'alpha'),
  2513. 'titre' => ucfirst(GETPOST('titre', 'alpha')),
  2514. 'mainmenu' => GETPOST('mainmenu', 'alpha'),
  2515. 'leftmenu' => $menus[$key]['leftmenu'],
  2516. 'url' => GETPOST('url', 'alpha'),
  2517. 'langs' => strtolower($module)."@".strtolower($module),
  2518. 'position' => '',
  2519. 'enabled' => GETPOST('enabled', 'alpha'),
  2520. 'perms' => GETPOST('perms', 'alpha'),
  2521. 'target' => GETPOST('target', 'alpha'),
  2522. 'user' => GETPOST('user', 'alpha'),
  2523. );
  2524. if (!empty(GETPOST('fk_menu')) && GETPOST('fk_menu') != $menus[$key]['fk_menu']) {
  2525. $menuModify['fk_menu'] = 'fk_mainmenu='.GETPOST('mainmenu').',fk_leftmenu='.GETPOST('fk_menu');
  2526. } elseif (GETPOST('fk_menu') == $menus[$key]['fk_menu']) {
  2527. $menuModify['fk_menu'] = $menus[$key]['fk_menu'];
  2528. } else {
  2529. $menuModify['fk_menu'] = 'fk_mainmenu='.GETPOST('mainmenu');
  2530. }
  2531. if ($menuModify['enabled'] === '') {
  2532. $menuModify['enabled'] = '1';
  2533. }
  2534. if ($menuModify['perms'] === '') {
  2535. $menuModify['perms'] = '1';
  2536. }
  2537. if (GETPOST('type', 'alpha') == 'top') {
  2538. $error++;
  2539. setEventMessages($langs->trans("ErrorTypeMenu", $langs->transnoentities("type")), null, 'errors');
  2540. }
  2541. if (!$error) {
  2542. //update menu
  2543. $checkComment = checkExistComment($moduledescriptorfile, 0);
  2544. if ($checkComment < 0) {
  2545. setEventMessages($langs->trans("WarningCommentNotFound", $langs->trans("Menus"), "mod".$module."class.php"), null, 'warnings');
  2546. } else {
  2547. // Write all menus
  2548. $result = reWriteAllMenus($moduledescriptorfile, $menus, $menuModify, $key, 2);
  2549. clearstatcache(true);
  2550. if (function_exists('opcache_invalidate')) {
  2551. opcache_reset();
  2552. }
  2553. if ($result < 0) {
  2554. setEventMessages($langs->trans('ErrorMenuExistValue'), null, 'errors');
  2555. //var_dump($_SESSION);exit;
  2556. header("Location: ".$_SERVER["PHP_SELF"].'?action=editmenu&token='.newToken().'&menukey='.urlencode($key+1).'&tab='.urlencode($tab).'&module='.urlencode($module).'&tabobj='.($key+1));
  2557. exit;
  2558. }
  2559. setEventMessages($langs->trans('MenuUpdatedSuccessfuly'), null);
  2560. header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=menus&module='.$module);
  2561. exit;
  2562. }
  2563. }
  2564. } else {
  2565. $_POST['type'] = '';
  2566. $_POST['titre'] = '';
  2567. $_POST['fk_menu'] = '';
  2568. $_POST['leftmenu'] = '';
  2569. $_POST['url'] = '';
  2570. }
  2571. }
  2572. // update properties description of module
  2573. if ($dirins && $action == "update_props_module" && !empty(GETPOST('keydescription', 'alpha')) && empty($cancel)) {
  2574. if (isModEnabled(strtolower($module))) {
  2575. $result = unActivateModule(strtolower($module));
  2576. dolibarr_set_const($db, "MAIN_IHM_PARAMS_REV", (int) $conf->global->MAIN_IHM_PARAMS_REV + 1, 'chaine', 0, '', $conf->entity);
  2577. if ($result) {
  2578. setEventMessages($result, null, 'errors');
  2579. }
  2580. setEventMessages($langs->trans('WarningModuleNeedRefresh', $langs->transnoentities($module)), null, 'warnings');
  2581. header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=menus&module='.$module);
  2582. exit;
  2583. }
  2584. $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
  2585. $moduledescriptorfile = $dirins.'/'.strtolower($module).'/core/modules/mod'.$module.'.class.php';
  2586. $modulelogfile = $dirins.'/'.strtolower($module).'/ChangeLog.md';
  2587. dol_include_once($pathtofile);
  2588. $class = 'mod'.$module;
  2589. if (class_exists($class)) {
  2590. try {
  2591. $moduleobj = new $class($db);
  2592. } catch (Exception $e) {
  2593. $error++;
  2594. dol_print_error($db, $e->getMessage());
  2595. }
  2596. }
  2597. $keydescription = GETPOST('keydescription', 'alpha');
  2598. switch ($keydescription) {
  2599. case 'desc':
  2600. $propertyToUpdate = 'description';
  2601. break;
  2602. case 'version':
  2603. case 'family':
  2604. case 'picto':
  2605. case 'editor_name':
  2606. case 'editor_url':
  2607. $propertyToUpdate = $keydescription;
  2608. break;
  2609. default:
  2610. $error = GETPOST('keydescription');
  2611. break;
  2612. }
  2613. if (isset($propertyToUpdate) && !empty(GETPOST('propsmodule'))) {
  2614. $newValue = GETPOST('propsmodule');
  2615. $lineToReplace = "\t\t\$this->$propertyToUpdate = ";
  2616. $newLine = "\t\t\$this->$propertyToUpdate = '$newValue';\n";
  2617. //for change version in log file
  2618. if ($propertyToUpdate === 'version') {
  2619. dolReplaceInFile($modulelogfile, array("## ".$moduleobj->$propertyToUpdate => $newValue));
  2620. }
  2621. $fileLines = file($moduledescriptorfile);
  2622. foreach ($fileLines as &$line) {
  2623. if (strpos($line, $lineToReplace) === 0) {
  2624. dolReplaceInFile($moduledescriptorfile, array($line => $newLine));
  2625. break;
  2626. }
  2627. }
  2628. clearstatcache(true);
  2629. if (function_exists('opcache_invalidate')) {
  2630. opcache_reset();
  2631. }
  2632. setEventMessages($langs->trans('PropertyModuleUpdated', $propertyToUpdate), null);
  2633. header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=description&module='.$module);
  2634. exit;
  2635. }
  2636. }
  2637. /*
  2638. * View
  2639. */
  2640. $form = new Form($db);
  2641. $formadmin = new FormAdmin($db);
  2642. // Set dir where external modules are installed
  2643. if (!dol_is_dir($dirins)) {
  2644. dol_mkdir($dirins);
  2645. }
  2646. $dirins_ok = (dol_is_dir($dirins));
  2647. $help_url = '';
  2648. $morejs = array(
  2649. '/includes/ace/src/ace.js',
  2650. '/includes/ace/src/ext-statusbar.js',
  2651. '/includes/ace/src/ext-language_tools.js',
  2652. //'/includes/ace/src/ext-chromevox.js'
  2653. );
  2654. $morecss = array();
  2655. llxHeader('', $langs->trans("ModuleBuilder"), $help_url, '', 0, 0, $morejs, $morecss, '', 'classforhorizontalscrolloftabs');
  2656. $text = $langs->trans("ModuleBuilder");
  2657. print load_fiche_titre($text, '', 'title_setup');
  2658. print '<span class="opacitymedium hideonsmartphone">'.$langs->trans("ModuleBuilderDesc", 'https://wiki.dolibarr.org/index.php/Module_development#Create_your_module').'</span>';
  2659. print '<br class="hideonsmartphone">';
  2660. //print $textforlistofdirs;
  2661. //print '<br>';
  2662. $message = '';
  2663. if (!$dirins) {
  2664. $message = info_admin($langs->trans("ConfFileMustContainCustom", DOL_DOCUMENT_ROOT.'/custom', DOL_DOCUMENT_ROOT));
  2665. $allowfromweb = -1;
  2666. } else {
  2667. if ($dirins_ok) {
  2668. if (!is_writable(dol_osencode($dirins))) {
  2669. $langs->load("errors");
  2670. $message = info_admin($langs->trans("ErrorFailedToWriteInDir", $dirins));
  2671. $allowfromweb = 0;
  2672. }
  2673. } else {
  2674. $message = info_admin($langs->trans("NotExistsDirect", $dirins).$langs->trans("InfDirAlt").$langs->trans("InfDirExample"));
  2675. $allowfromweb = 0;
  2676. }
  2677. }
  2678. if ($message) {
  2679. print $message;
  2680. }
  2681. //print $langs->trans("ModuleBuilderDesc3", count($listofmodules), $FILEFLAG).'<br>';
  2682. $infomodulesfound = '<div style="padding: 12px 9px 12px">'.$form->textwithpicto('', $langs->trans("ModuleBuilderDesc3", count($listofmodules)).'<br><br>'.$langs->trans("ModuleBuilderDesc4", $FILEFLAG).'<br>'.$textforlistofdirs).'</div>';
  2683. $dolibarrdataroot = preg_replace('/([\\/]+)$/i', '', DOL_DATA_ROOT);
  2684. $allowonlineinstall = true;
  2685. if (dol_is_file($dolibarrdataroot.'/installmodules.lock')) {
  2686. $allowonlineinstall = false;
  2687. }
  2688. if (empty($allowonlineinstall)) {
  2689. if (getDolGlobalString('MAIN_MESSAGE_INSTALL_MODULES_DISABLED_CONTACT_US')) {
  2690. // Show clean message
  2691. $message = info_admin($langs->trans('InstallModuleFromWebHasBeenDisabledContactUs'));
  2692. } else {
  2693. // Show technical message
  2694. $message = info_admin($langs->trans("InstallModuleFromWebHasBeenDisabledByFile", $dolibarrdataroot.'/installmodules.lock'), 0, 0, 1, 'warning');
  2695. }
  2696. print $message;
  2697. llxFooter();
  2698. exit(0);
  2699. }
  2700. // Load module descriptor
  2701. $error = 0;
  2702. $moduleobj = null;
  2703. if (!empty($module) && $module != 'initmodule' && $module != 'deletemodule') {
  2704. $modulelowercase = strtolower($module);
  2705. $loadclasserrormessage = '';
  2706. // Load module
  2707. try {
  2708. $fullpathdirtodescriptor = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
  2709. //throw(new Exception());
  2710. dol_include_once($fullpathdirtodescriptor);
  2711. $class = 'mod'.$module;
  2712. } catch (Throwable $e) { // This is called in PHP 7 only (includes Error and Exception)
  2713. $loadclasserrormessage = $e->getMessage()."<br>\n";
  2714. $loadclasserrormessage .= 'File: '.$e->getFile()."<br>\n";
  2715. $loadclasserrormessage .= 'Line: '.$e->getLine()."<br>\n";
  2716. }
  2717. if (class_exists($class)) {
  2718. try {
  2719. $moduleobj = new $class($db);
  2720. } catch (Exception $e) {
  2721. $error++;
  2722. print $e->getMessage();
  2723. }
  2724. } else {
  2725. if (empty($forceddirread)) {
  2726. $error++;
  2727. }
  2728. $langs->load("errors");
  2729. print '<!-- ErrorFailedToLoadModuleDescriptorForXXX -->';
  2730. print img_warning('').' '.$langs->trans("ErrorFailedToLoadModuleDescriptorForXXX", $module).'<br>';
  2731. print $loadclasserrormessage;
  2732. }
  2733. }
  2734. print '<br>';
  2735. // Tabs for all modules
  2736. $head = array();
  2737. $h = 0;
  2738. $head[$h][0] = $_SERVER["PHP_SELF"].'?module=initmodule';
  2739. $head[$h][1] = '<span class="valignmiddle text-plus-circle">'.$langs->trans("NewModule").'</span><span class="fa fa-plus-circle valignmiddle paddingleft"></span>';
  2740. $head[$h][2] = 'initmodule';
  2741. $h++;
  2742. $linktoenabledisable = '';
  2743. if (is_array($listofmodules) && count($listofmodules) > 0) {
  2744. // Define $linktoenabledisable
  2745. $modulelowercase = strtolower($module);
  2746. $param = '';
  2747. if ($tab) {
  2748. $param .= '&tab='.urlencode($tab);
  2749. }
  2750. if ($module) {
  2751. $param .= '&module='.urlencode($module);
  2752. }
  2753. if ($tabobj) {
  2754. $param .= '&tabobj='.urlencode($tabobj);
  2755. }
  2756. $urltomodulesetup = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?search_keyword='.urlencode($module).'">'.$langs->trans('Home').'-'.$langs->trans("Setup").'-'.$langs->trans("Modules").'</a>';
  2757. // Define $linktoenabledisable to show after module title
  2758. if (isModEnabled($modulelowercase)) { // If module is already activated
  2759. $linktoenabledisable .= '<a class="reposition asetresetmodule valignmiddle" href="'.$_SERVER["PHP_SELF"].'?id='.$moduleobj->numero.'&action=reset&token='.newToken().'&value=mod'.$module.$param.'">';
  2760. $linktoenabledisable .= img_picto($langs->trans("Activated"), 'switch_on', '', false, 0, 0, '', '', 1);
  2761. $linktoenabledisable .= '</a>';
  2762. $linktoenabledisable .= $form->textwithpicto('', $langs->trans("Warning").' : '.$langs->trans("ModuleIsLive"), -1, 'warning');
  2763. $objMod = $moduleobj;
  2764. $backtourlparam = '';
  2765. $backtourlparam .= ($backtourlparam ? '&' : '?').'module='.$module; // No urlencode here, done later
  2766. if ($tab) {
  2767. $backtourlparam .= ($backtourlparam ? '&' : '?').'tab='.$tab; // No urlencode here, done later
  2768. }
  2769. $backtourl = $_SERVER["PHP_SELF"].$backtourlparam;
  2770. $regs = array();
  2771. if (is_array($objMod->config_page_url)) {
  2772. $i = 0;
  2773. foreach ($objMod->config_page_url as $page) {
  2774. $urlpage = $page;
  2775. if ($i++) {
  2776. $linktoenabledisable .= ' <a href="'.$urlpage.'" title="'.$langs->trans($page).'">'.img_picto(ucfirst($page), "setup").'</a>';
  2777. // print '<a href="'.$page.'">'.ucfirst($page).'</a>&nbsp;';
  2778. } else {
  2779. if (preg_match('/^([^@]+)@([^@]+)$/i', $urlpage, $regs)) {
  2780. $urltouse = dol_buildpath('/'.$regs[2].'/admin/'.$regs[1], 1);
  2781. $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>';
  2782. } else {
  2783. // Case standard admin page (not a page provided by the
  2784. // module but a page provided by dolibarr)
  2785. $urltouse = DOL_URL_ROOT.'/admin/'.$urlpage;
  2786. $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>';
  2787. }
  2788. }
  2789. }
  2790. } elseif (preg_match('/^([^@]+)@([^@]+)$/i', $objMod->config_page_url, $regs)) {
  2791. $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>';
  2792. }
  2793. } else {
  2794. if (!empty($moduleobj)) {
  2795. $linktoenabledisable .= '<a class="reposition asetresetmodule valignmiddle" href="'.$_SERVER["PHP_SELF"].'?id='.$moduleobj->numero.'&action=set&token='.newToken().'&value=mod'.$module.$param.'">';
  2796. $linktoenabledisable .= img_picto($langs->trans("ModuleIsNotActive", $urltomodulesetup), 'switch_off', 'style="padding-right: 8px"', false, 0, 0, '', 'classfortooltip', 1);
  2797. $linktoenabledisable .= "</a>\n";
  2798. }
  2799. }
  2800. // Loop to show tab of each module
  2801. foreach ($listofmodules as $tmpmodule => $tmpmodulearray) {
  2802. $head[$h][0] = $_SERVER["PHP_SELF"].'?module='.$tmpmodulearray['modulenamewithcase'].($forceddirread ? '@'.$dirread : '');
  2803. $head[$h][1] = $tmpmodulearray['modulenamewithcase'];
  2804. $head[$h][2] = $tmpmodulearray['modulenamewithcase'];
  2805. if ($tmpmodulearray['modulenamewithcase'] == $module) {
  2806. $head[$h][4] = '<span class="inline-block">'.$linktoenabledisable.'</span>';
  2807. }
  2808. $h++;
  2809. }
  2810. }
  2811. $head[$h][0] = $_SERVER["PHP_SELF"].'?module=deletemodule';
  2812. $head[$h][1] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("DangerZone");
  2813. $head[$h][2] = 'deletemodule';
  2814. $h++;
  2815. print dol_get_fiche_head($head, $module, '', -1, '', 0, $infomodulesfound, '', 8); // Modules
  2816. if ($module == 'initmodule') {
  2817. // New module
  2818. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  2819. print '<input type="hidden" name="token" value="'.newToken().'">';
  2820. print '<input type="hidden" name="action" value="initmodule">';
  2821. print '<input type="hidden" name="module" value="initmodule">';
  2822. //print '<span class="opacitymedium">'.$langs->trans("ModuleBuilderDesc2", 'conf/conf.php', $newdircustom).'</span><br>';
  2823. print '<br>';
  2824. print '<div class="tagtable">';
  2825. print '<div class="tagtr"><div class="tagtd paddingright">';
  2826. print '<span class="opacitymedium">'.$langs->trans("IdModule").'</span>';
  2827. print '</div><div class="tagtd">';
  2828. print '<input type="text" name="idmodule" class="width75" value="500000" placeholder="'.dol_escape_htmltag($langs->trans("IdModule")).'">';
  2829. print '<span class="opacitymedium">';
  2830. print ' &nbsp; (';
  2831. print dolButtonToOpenUrlInDialogPopup('popup_modules_id', $langs->transnoentitiesnoconv("SeeIDsInUse"), $langs->transnoentitiesnoconv("SeeIDsInUse"), '/admin/system/modules.php?mainmenu=home&leftmenu=admintools_info', '', '');
  2832. print ' - ';
  2833. print '<a href="https://wiki.dolibarr.org/index.php/List_of_modules_id" target="_blank" rel="noopener noreferrer external">'.$langs->trans("SeeReservedIDsRangeHere").'</a>';
  2834. print ')';
  2835. print '</span>';
  2836. print '</div></div>';
  2837. print '<div class="tagtr"><div class="tagtd paddingright">';
  2838. print '<span class="opacitymedium fieldrequired">'.$langs->trans("ModuleName").'</span>';
  2839. print '</div><div class="tagtd">';
  2840. print '<input type="text" name="modulename" value="'.dol_escape_htmltag($modulename).'" autofocus>';
  2841. print ' '.$form->textwithpicto('', $langs->trans("EnterNameOfModuleDesc"));
  2842. print '</div></div>';
  2843. print '<div class="tagtr"><div class="tagtd paddingright">';
  2844. print '<span class="opacitymedium">'.$langs->trans("Description").'</span>';
  2845. print '</div><div class="tagtd">';
  2846. print '<input type="text" name="description" value="" class="minwidth500"><br>';
  2847. print '</div></div>';
  2848. print '<div class="tagtr"><div class="tagtd paddingright">';
  2849. print '<span class="opacitymedium">'.$langs->trans("Version").'</span>';
  2850. print '</div><div class="tagtd">';
  2851. 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")).'">';
  2852. print '</div></div>';
  2853. print '<div class="tagtr"><div class="tagtd paddingright">';
  2854. print '<span class="opacitymedium">'.$langs->trans("Family").'</span>';
  2855. print '</div><div class="tagtd">';
  2856. print '<select name="family" id="family" class="minwidth400">';
  2857. $arrayoffamilies = array(
  2858. 'hr' => "ModuleFamilyHr",
  2859. 'crm' => "ModuleFamilyCrm",
  2860. 'srm' => "ModuleFamilySrm",
  2861. 'financial' => 'ModuleFamilyFinancial',
  2862. 'products' => 'ModuleFamilyProducts',
  2863. 'projects' => 'ModuleFamilyProjects',
  2864. 'ecm' => 'ModuleFamilyECM',
  2865. 'technic' => 'ModuleFamilyTechnic',
  2866. 'portal' => 'ModuleFamilyPortal',
  2867. 'interface' => 'ModuleFamilyInterface',
  2868. 'base' => 'ModuleFamilyBase',
  2869. 'other' => 'ModuleFamilyOther'
  2870. );
  2871. foreach ($arrayoffamilies as $key => $value) {
  2872. 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>';
  2873. }
  2874. print '</select>';
  2875. print ajax_combobox("family");
  2876. print '</div></div>';
  2877. print '<div class="tagtr"><div class="tagtd paddingright">';
  2878. print '<span class="opacitymedium">'.$langs->trans("Picto").'</span>';
  2879. print '</div><div class="tagtd">';
  2880. print '<input type="text" name="idpicto" value="'.(GETPOSTISSET('idpicto') ? GETPOST('idpicto') : getDolGlobalString('MODULEBUILDER_DEFAULTPICTO', 'fa-file-o')).'" placeholder="'.dol_escape_htmltag($langs->trans("Picto")).'">';
  2881. print $form->textwithpicto('', $langs->trans("Example").': fa-file-o, fa-globe, ... any font awesome code.<br>Advanced syntax is fa-fakey[_faprefix[_facolor[_fasize]]]');
  2882. print '</div></div>';
  2883. print '<div class="tagtr"><div class="tagtd paddingright">';
  2884. print '<span class="opacitymedium">'.$langs->trans("EditorName").'</span>';
  2885. print '</div><div class="tagtd">';
  2886. 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>';
  2887. print '</div></div>';
  2888. print '<div class="tagtr"><div class="tagtd paddingright">';
  2889. print '<span class="opacitymedium">'.$langs->trans("EditorUrl").'</span>';
  2890. print '</div><div class="tagtd">';
  2891. 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>';
  2892. print '</div></div>';
  2893. print '<br><input type="submit" class="button" name="create" value="'.dol_escape_htmltag($langs->trans("Create")).'"'.($dirins ? '' : ' disabled="disabled"').'>';
  2894. print '</form>';
  2895. } elseif ($module == 'deletemodule') {
  2896. print '<!-- Form to init a module -->'."\n";
  2897. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST" name="delete">';
  2898. print '<input type="hidden" name="token" value="'.newToken().'">';
  2899. print '<input type="hidden" name="action" value="confirm_deletemodule">';
  2900. print '<input type="hidden" name="module" value="deletemodule">';
  2901. print $langs->trans("EnterNameOfModuleToDeleteDesc").'<br><br>';
  2902. print '<input type="text" name="module" placeholder="'.dol_escape_htmltag($langs->trans("ModuleKey")).'" value="">';
  2903. print '<input type="submit" class="button smallpaddingimp" value="'.$langs->trans("Delete").'"'.($dirins ? '' : ' disabled="disabled"').'>';
  2904. print '</form>';
  2905. } elseif (!empty($module)) {
  2906. // Tabs for module
  2907. if (!$error) {
  2908. $dirread = $listofmodules[strtolower($module)]['moduledescriptorrootpath'];
  2909. $destdir = $dirread.'/'.strtolower($module);
  2910. $objects = dolGetListOfObjectClasses($destdir);
  2911. $diroflang = dol_buildpath($modulelowercase, 0)."/langs";
  2912. $countLangs = countItemsInDirectory($diroflang, 2);
  2913. $countDictionaries = (!empty($moduleobj->dictionaries) ? count($moduleobj->dictionaries['tabname']) : 0);
  2914. $countRights = count($moduleobj->rights);
  2915. $countMenus = count($moduleobj->menu);
  2916. $countTriggers = countItemsInDirectory(dol_buildpath($modulelowercase, 0)."/core/triggers");
  2917. $countWidgets = countItemsInDirectory(dol_buildpath($modulelowercase, 0)."/core/boxes");
  2918. $countCss = countItemsInDirectory(dol_buildpath($modulelowercase, 0)."/css");
  2919. $countJs = countItemsInDirectory(dol_buildpath($modulelowercase, 0)."/js");
  2920. $countCLI = countItemsInDirectory(dol_buildpath($modulelowercase, 0)."/scripts");
  2921. $hasDoc = countItemsInDirectory(dol_buildpath($modulelowercase, 0)."/doc");
  2922. //var_dump($moduleobj->dictionaries);exit;
  2923. $head2 = array();
  2924. $h = 0;
  2925. $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=description&module='.$module.($forceddirread ? '@'.$dirread : '');
  2926. $head2[$h][1] = $langs->trans("Description");
  2927. $head2[$h][2] = 'description';
  2928. $h++;
  2929. $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=objects&module='.$module.($forceddirread ? '@'.$dirread : '');
  2930. $head2[$h][1] = ((!is_array($objects) || count($objects) <= 0) ? $langs->trans("Objects") : $langs->trans("Objects").'<span class="marginleftonlyshort badge">'.count($objects)."</span>");
  2931. $head2[$h][2] = 'objects';
  2932. $h++;
  2933. $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=languages&module='.$module.($forceddirread ? '@'.$dirread : '');
  2934. $head2[$h][1] = ($countLangs <= 0 ? $langs->trans("Languages") : $langs->trans("Languages").'<span class="marginleftonlyshort badge">'.$countLangs."</span>");
  2935. $head2[$h][2] = 'languages';
  2936. $h++;
  2937. $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=dictionaries&module='.$module.($forceddirread ? '@'.$dirread : '');
  2938. $head2[$h][1] = ($countDictionaries == 0 ? $langs->trans("Dictionaries") : $langs->trans('Dictionaries').'<span class="marginleftonlyshort badge">'.$countDictionaries."</span>");
  2939. $head2[$h][2] = 'dictionaries';
  2940. $h++;
  2941. $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=permissions&module='.$module.($forceddirread ? '@'.$dirread : '');
  2942. $head2[$h][1] = ($countRights <= 0 ? $langs->trans("Permissions") : $langs->trans("Permissions").'<span class="marginleftonlyshort badge">'.$countRights."</span>");
  2943. $head2[$h][2] = 'permissions';
  2944. $h++;
  2945. $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=tabs&module='.$module.($forceddirread ? '@'.$dirread : '');
  2946. $head2[$h][1] = $langs->trans("Tabs");
  2947. $head2[$h][2] = 'tabs';
  2948. $h++;
  2949. $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=menus&module='.$module.($forceddirread ? '@'.$dirread : '');
  2950. $head2[$h][1] = ($countMenus <= 0 ? $langs->trans("Menus") : $langs->trans("Menus").'<span class="marginleftonlyshort badge">'.$countMenus."</span>");
  2951. $head2[$h][2] = 'menus';
  2952. $h++;
  2953. $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=hooks&module='.$module.($forceddirread ? '@'.$dirread : '');
  2954. $head2[$h][1] = $langs->trans("Hooks");
  2955. $head2[$h][2] = 'hooks';
  2956. $h++;
  2957. $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=triggers&module='.$module.($forceddirread ? '@'.$dirread : '');
  2958. $head2[$h][1] = ($countTriggers <= 0 ? $langs->trans("Triggers") : $langs->trans("Triggers").'<span class="marginleftonlyshort badge">'.$countTriggers."</span>");
  2959. $head2[$h][2] = 'triggers';
  2960. $h++;
  2961. $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=widgets&module='.$module.($forceddirread ? '@'.$dirread : '');
  2962. $head2[$h][1] = ($countWidgets <= 0 ? $langs->trans("Widgets") : $langs->trans("Widgets").'<span class="marginleftonlyshort badge">'.$countWidgets."</span>");
  2963. $head2[$h][2] = 'widgets';
  2964. $h++;
  2965. $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=exportimport&module='.$module.($forceddirread ? '@'.$dirread : '');
  2966. $head2[$h][1] = $langs->trans("Export").'-'.$langs->trans("Import");
  2967. $head2[$h][2] = 'exportimport';
  2968. $h++;
  2969. $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=css&module='.$module.($forceddirread ? '@'.$dirread : '');
  2970. $head2[$h][1] = ($countCss <= 0 ? $langs->trans("CSS") : $langs->trans("CSS")." (".$countCss.")");
  2971. $head2[$h][2] = 'css';
  2972. $h++;
  2973. $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=js&module='.$module.($forceddirread ? '@'.$dirread : '');
  2974. $head2[$h][1] = ($countJs <= 0 ? $langs->trans("JS") : $langs->trans("JS").'<span class="marginleftonlyshort badge">'.$countJs."</span>");
  2975. $head2[$h][2] = 'js';
  2976. $h++;
  2977. $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=cli&module='.$module.($forceddirread ? '@'.$dirread : '');
  2978. $head2[$h][1] = ($countCLI <= 0 ? $langs->trans("CLI") : $langs->trans("CLI").'<span class="marginleftonlyshort badge">'.$countCLI."</span>");
  2979. $head2[$h][2] = 'cli';
  2980. $h++;
  2981. $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=cron&module='.$module.($forceddirread ? '@'.$dirread : '');
  2982. $head2[$h][1] = $langs->trans("CronList");
  2983. $head2[$h][2] = 'cron';
  2984. $h++;
  2985. $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=specifications&module='.$module.($forceddirread ? '@'.$dirread : '');
  2986. $head2[$h][1] = ($hasDoc <= 0 ? $langs->trans("Documentation") : $langs->trans("Documentation").'<span class="paddingleft badge">'.$hasDoc."</span>");
  2987. $head2[$h][2] = 'specifications';
  2988. $h++;
  2989. $head2[$h][0] = $_SERVER["PHP_SELF"].'?tab=buildpackage&module='.$module.($forceddirread ? '@'.$dirread : '');
  2990. $head2[$h][1] = $langs->trans("BuildPackage");
  2991. $head2[$h][2] = 'buildpackage';
  2992. $h++;
  2993. $MAXTABFOROBJECT = 15;
  2994. print '<!-- Section for a given module -->';
  2995. // Note module is inside $dirread
  2996. if ($tab == 'description') {
  2997. print '<!-- tab=description -->'."\n";
  2998. $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
  2999. $pathtofilereadme = $modulelowercase.'/README.md';
  3000. $pathtochangelog = $modulelowercase.'/ChangeLog.md';
  3001. $realpathofmodule = realpath($dirread.'/'.$modulelowercase);
  3002. if ($action != 'editfile' || empty($file)) {
  3003. $morehtmlright = '';
  3004. if ($realpathofmodule != $dirread.'/'.$modulelowercase) {
  3005. $morehtmlright = '<div style="padding: 12px 9px 12px">'.$form->textwithpicto('', '<span class="opacitymedium">'.$langs->trans("RealPathOfModule").' :</span> <strong class="wordbreak">'.$realpathofmodule.'</strong>').'</div>';
  3006. }
  3007. print dol_get_fiche_head($head2, $tab, '', -1, '', 0, $morehtmlright, '', $MAXTABFOROBJECT, 'formodulesuffix'); // Description - level 2
  3008. print '<span class="opacitymedium">'.$langs->trans("ModuleBuilderDesc".$tab).'</span>';
  3009. print '<br><br>';
  3010. print '<table>';
  3011. print '<tr><td>';
  3012. print '<span class="fa fa-file-o"></span> '.$langs->trans("DescriptorFile").' : <strong class="wordbreak">'.$pathtofile.'</strong>';
  3013. 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>';
  3014. print '</td></tr>';
  3015. // List of setup pages
  3016. $listofsetuppages = dol_dir_list($realpathofmodule.'/admin', 'files', 0, '\.php$');
  3017. foreach ($listofsetuppages as $setuppage) {
  3018. //var_dump($setuppage);
  3019. print '<tr><td>';
  3020. print '<span class="fa fa-file-o"></span> '.$langs->trans("SetupFile").' : <strong class="wordbreak">'.$modulelowercase.'/admin/'.$setuppage['relativename'].'</strong>';
  3021. 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>';
  3022. print '</td></tr>';
  3023. }
  3024. print '<tr><td><span class="fa fa-file-o"></span> '.$langs->trans("ReadmeFile").' : <strong class="wordbreak">'.$pathtofilereadme.'</strong>';
  3025. 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>';
  3026. print '</td></tr>';
  3027. print '<tr><td><span class="fa fa-file-o"></span> '.$langs->trans("ChangeLog").' : <strong class="wordbreak">'.$pathtochangelog.'</strong>';
  3028. 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>';
  3029. print '</td></tr>';
  3030. print '</table>';
  3031. print '<br>';
  3032. print load_fiche_titre($form->textwithpicto($langs->trans("DescriptorFile"), $langs->transnoentitiesnoconv("File").' '.$pathtofile), '', '');
  3033. if (!empty($moduleobj)) {
  3034. print '<div class="underbanner clearboth"></div>';
  3035. print '<div class="fichecenter">';
  3036. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  3037. print '<input type="hidden" name="token" value="'.newToken().'">';
  3038. print '<input type="hidden" name="action" value="update_props_module">';
  3039. print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
  3040. print '<input type="hidden" name="tab" value="'.dol_escape_htmltag($tab).'">';
  3041. print '<input type="hidden" name="keydescription" value="'.dol_escape_htmltag(GETPOST('keydescription', 'alpha')).'">';
  3042. print '<table class="border centpercent">';
  3043. print '<tr class="liste_titre"><td class="titlefield">';
  3044. print $langs->trans("Parameter");
  3045. print '</td><td>';
  3046. print $langs->trans("Value");
  3047. print '</td></tr>';
  3048. print '<tr><td>';
  3049. print $langs->trans("IdModule");
  3050. print '</td><td>';
  3051. print $moduleobj->numero;
  3052. print '<span class="opacitymedium">';
  3053. print ' &nbsp; (';
  3054. print dolButtonToOpenUrlInDialogPopup('popup_modules_id', $langs->transnoentitiesnoconv("SeeIDsInUse"), $langs->transnoentitiesnoconv("SeeIDsInUse"), '/admin/system/modules.php?mainmenu=home&leftmenu=admintools_info', '', '');
  3055. print ' - <a href="https://wiki.dolibarr.org/index.php/List_of_modules_id" target="_blank" rel="noopener noreferrer external">'.$langs->trans("SeeReservedIDsRangeHere").'</a>)';
  3056. print '</span>';
  3057. print '</td></tr>';
  3058. print '<tr><td>';
  3059. print $langs->trans("ModuleName");
  3060. print '</td><td>';
  3061. print $moduleobj->getName();
  3062. print '</td></tr>';
  3063. print '<tr><td>';
  3064. print $langs->trans("Description");
  3065. print '</td><td>';
  3066. if ($action == 'edit_moduledescription' && GETPOST('keydescription', 'alpha') === 'desc') {
  3067. print '<input class="minwidth500" name="propsmodule" value="'.dol_escape_htmltag($moduleobj->description).'">';
  3068. print '<input class="reposition button smallpaddingimp" type="submit" name="modifydesc" value="'.$langs->trans("Modify").'"/>';
  3069. print '<input class="reposition button button-cancel smallpaddingimp" type="submit" name="cancel" value="'.$langs->trans("Cancel").'"/>';
  3070. } else {
  3071. print $moduleobj->getDesc();
  3072. 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>';
  3073. }
  3074. print '</td></tr>';
  3075. print '<tr><td>';
  3076. print $langs->trans("Version");
  3077. print '</td><td>';
  3078. if ($action == 'edit_moduledescription' && GETPOST('keydescription', 'alpha') === 'version') {
  3079. print '<input name="propsmodule" value="'.dol_escape_htmltag($moduleobj->getVersion()).'">';
  3080. print '<input class="reposition button smallpaddingimp" type="submit" name="modifyversion" value="'.$langs->trans("Modify").'"/>';
  3081. print '<input class="reposition button button-cancel smallpaddingimp" type="submit" name="cancel" value="'.$langs->trans("Cancel").'"/>';
  3082. } else {
  3083. print $moduleobj->getVersion();
  3084. 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>';
  3085. }
  3086. print '</td></tr>';
  3087. print '<tr><td>';
  3088. print $langs->trans("Family");
  3089. //print "<br>'crm','financial','hr','projects','products','ecm','technic','interface','other'";
  3090. print '</td><td>';
  3091. if ($action == 'edit_moduledescription' && GETPOST('keydescription', 'alpha') === 'family') {
  3092. print '<select name="propsmodule" id="family" class="minwidth400">';
  3093. $arrayoffamilies = array(
  3094. 'hr' => "ModuleFamilyHr",
  3095. 'crm' => "ModuleFamilyCrm",
  3096. 'srm' => "ModuleFamilySrm",
  3097. 'financial' => 'ModuleFamilyFinancial',
  3098. 'products' => 'ModuleFamilyProducts',
  3099. 'projects' => 'ModuleFamilyProjects',
  3100. 'ecm' => 'ModuleFamilyECM',
  3101. 'technic' => 'ModuleFamilyTechnic',
  3102. 'portal' => 'ModuleFamilyPortal',
  3103. 'interface' => 'ModuleFamilyInterface',
  3104. 'base' => 'ModuleFamilyBase',
  3105. 'other' => 'ModuleFamilyOther'
  3106. );
  3107. 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>';
  3108. foreach ($arrayoffamilies as $key => $value) {
  3109. if ($key != $moduleobj->family) {
  3110. print '<option value="'.$key.'" data-html="'.dol_escape_htmltag($langs->trans($value).' <span class="opacitymedium">- '.$key.'</span>').'">'.$langs->trans($value).'</option>';
  3111. }
  3112. }
  3113. print '</select>';
  3114. print '<input class="reposition button smallpaddingimp" type="submit" name="modifyfamily" value="'.$langs->trans("Modify").'"/>';
  3115. print '<input class="reposition button button-cancel smallpaddingimp" type="submit" name="cancel" value="'.$langs->trans("Cancel").'"/>';
  3116. } else {
  3117. print $moduleobj->family;
  3118. 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>';
  3119. }
  3120. print '</td></tr>';
  3121. print '<tr><td>';
  3122. print $langs->trans("Picto");
  3123. print '</td><td>';
  3124. if ($action == 'edit_modulepicto' && GETPOST('keydescription', 'alpha') === 'picto') {
  3125. print '<input class="minwidth500" name="propsmodule" value="'.dol_escape_htmltag($moduleobj->picto).'">';
  3126. print '<input class="reposition button smallpaddingimp" type="submit" name="modifypicto" value="'.$langs->trans("Modify").'"/>';
  3127. print '<input class="reposition button button-cancel smallpaddingimp" type="submit" name="cancel" value="'.$langs->trans("Cancel").'"/>';
  3128. } else {
  3129. print $moduleobj->picto;
  3130. print ' &nbsp; '.img_picto('', $moduleobj->picto, 'class="valignmiddle pictomodule paddingrightonly"');
  3131. 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>';
  3132. }
  3133. print '</td></tr>';
  3134. print '<tr><td>';
  3135. print $langs->trans("EditorName");
  3136. print '</td><td>';
  3137. if ($action == 'edit_moduledescription' && GETPOST('keydescription', 'alpha') === 'editor_name') {
  3138. print '<input name="propsmodule" value="'.dol_escape_htmltag($moduleobj->editor_name).'">';
  3139. print '<input class="reposition button smallpaddingimp" type="submit" name="modifyname" value="'.$langs->trans("Modify").'"/>';
  3140. print '<input class="reposition button button-cancel smallpaddingimp" type="submit" name="cancel" value="'.$langs->trans("Cancel").'"/>';
  3141. } else {
  3142. print $moduleobj->editor_name;
  3143. 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>';
  3144. }
  3145. print '</td></tr>';
  3146. print '<tr><td>';
  3147. print $langs->trans("EditorUrl");
  3148. print '</td><td>';
  3149. if ($action == 'edit_moduledescription' && GETPOST('keydescription', 'alpha') === 'editor_url') {
  3150. print '<input name="propsmodule" value="'.dol_escape_htmltag($moduleobj->editor_url).'">';
  3151. print '<input class="reposition button smallpaddingimp" type="submit" name="modifyeditorurl" value="'.$langs->trans("Modify").'"/>';
  3152. print '<input class="reposition button button-cancel smallpaddingimp" type="submit" name="cancel" value="'.$langs->trans("Cancel").'"/>';
  3153. } else {
  3154. if (!empty($moduleobj->editor_url)) {
  3155. print '<a href="'.$moduleobj->editor_url.'" target="_blank" rel="noopener">'.$moduleobj->editor_url.' '.img_picto('', 'globe').'</a>';
  3156. }
  3157. 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>';
  3158. }
  3159. print '</td></tr>';
  3160. print '</table>';
  3161. print '</form>';
  3162. } else {
  3163. print $langs->trans("ErrorFailedToLoadModuleDescriptorForXXX", $module).'<br>';
  3164. }
  3165. if (!empty($moduleobj)) {
  3166. print '<br><br>';
  3167. // Readme file
  3168. print load_fiche_titre($form->textwithpicto($langs->trans("ReadmeFile"), $langs->transnoentitiesnoconv("File").' '.$pathtofilereadme), '', '');
  3169. print '<!-- readme file -->';
  3170. if (dol_is_file($dirread.'/'.$pathtofilereadme)) {
  3171. print '<div class="underbanner clearboth"></div><div class="fichecenter">'.$moduleobj->getDescLong().'</div>';
  3172. } else {
  3173. print '<span class="opacitymedium">'.$langs->trans("ErrorFileNotFound", $pathtofilereadme).'</span>';
  3174. }
  3175. print '<br><br>';
  3176. // ChangeLog
  3177. print load_fiche_titre($form->textwithpicto($langs->trans("ChangeLog"), $langs->transnoentitiesnoconv("File").' '.$pathtochangelog), '', '');
  3178. print '<!-- changelog file -->';
  3179. if (dol_is_file($dirread.'/'.$pathtochangelog)) {
  3180. print '<div class="underbanner clearboth"></div><div class="fichecenter">'.$moduleobj->getChangeLog().'</div>';
  3181. } else {
  3182. print '<span class="opacitymedium">'.$langs->trans("ErrorFileNotFound", $pathtochangelog).'</span>';
  3183. }
  3184. }
  3185. print dol_get_fiche_end();
  3186. } else { // Edit text file
  3187. $fullpathoffile = dol_buildpath($file, 0, 1); // Description - level 2
  3188. if ($fullpathoffile) {
  3189. $content = file_get_contents($fullpathoffile);
  3190. }
  3191. // New module
  3192. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  3193. print '<input type="hidden" name="token" value="'.newToken().'">';
  3194. print '<input type="hidden" name="action" value="savefile">';
  3195. print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
  3196. print '<input type="hidden" name="tab" value="'.$tab.'">';
  3197. print '<input type="hidden" name="module" value="'.$module.'">';
  3198. print dol_get_fiche_head($head2, $tab, '', -1, '', 0, '', '', 0, 'formodulesuffix');
  3199. $doleditor = new DolEditor('editfilecontent', $content, '', '300', 'Full', 'In', true, false, 'ace', 0, '99%', '');
  3200. print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ? GETPOST('format', 'aZ09') : 'html'));
  3201. print dol_get_fiche_end();
  3202. print '<center>';
  3203. print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
  3204. print ' &nbsp; ';
  3205. print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
  3206. print '</center>';
  3207. print '</form>';
  3208. }
  3209. } else {
  3210. print dol_get_fiche_head($head2, $tab, '', -1, '', 0, '', '', $MAXTABFOROBJECT, 'formodulesuffix'); // Level 2
  3211. }
  3212. if ($tab == 'languages') {
  3213. print '<!-- tab=languages -->'."\n";
  3214. if ($action != 'editfile' || empty($file)) {
  3215. print '<span class="opacitymedium">'.$langs->trans("LanguageDefDesc").'</span><br>';
  3216. print '<br>';
  3217. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  3218. print '<input type="hidden" name="token" value="'.newToken().'">';
  3219. print '<input type="hidden" name="action" value="addlanguage">';
  3220. print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
  3221. print '<input type="hidden" name="tab" value="'.$tab.'">';
  3222. print '<input type="hidden" name="module" value="'.$module.'">';
  3223. print $formadmin->select_language($conf->global->MAIN_LANG_DEFAULT, 'newlangcode', 0, 0, 1, 0, 0, 'minwidth300', 1);
  3224. print '<input type="submit" name="addlanguage" class="button smallpaddingimp" value="'.dol_escape_htmltag($langs->trans("AddLanguageFile")).'"><br>';
  3225. print '</form>';
  3226. print '<br>';
  3227. print '<br>';
  3228. $modulelowercase = strtolower($module);
  3229. // Dir for module
  3230. $diroflang = dol_buildpath($modulelowercase, 0);
  3231. $diroflang .= '/langs';
  3232. $langfiles = dol_dir_list($diroflang, 'files', 1, '\.lang$');
  3233. if (!preg_match('/custom/', $dirread)) {
  3234. // If this is not a module into custom
  3235. $diroflang = $dirread;
  3236. $diroflang .= '/langs';
  3237. $langfiles = dol_dir_list($diroflang, 'files', 1, $modulelowercase.'\.lang$');
  3238. }
  3239. print '<table class="none">';
  3240. foreach ($langfiles as $langfile) {
  3241. $pathtofile = $modulelowercase.'/langs/'.$langfile['relativename'];
  3242. if (!preg_match('/custom/', $dirread)) { // If this is not a module into custom
  3243. $pathtofile = 'langs/'.$langfile['relativename'];
  3244. }
  3245. print '<tr><td><span class="fa fa-file-o"></span> '.$langs->trans("LanguageFile").' '.basename(dirname($pathtofile)).' : <strong class="wordbreak">'.$pathtofile.'</strong>';
  3246. 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>';
  3247. 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>';
  3248. print '</td>';
  3249. }
  3250. print '</table>';
  3251. } else {
  3252. // Edit text language file
  3253. //print $langs->trans("UseAsciiDocFormat").'<br>';
  3254. $fullpathoffile = dol_buildpath($file, 0);
  3255. $content = file_get_contents($fullpathoffile);
  3256. // New module
  3257. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  3258. print '<input type="hidden" name="token" value="'.newToken().'">';
  3259. print '<input type="hidden" name="action" value="savefile">';
  3260. print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
  3261. print '<input type="hidden" name="tab" value="'.$tab.'">';
  3262. print '<input type="hidden" name="module" value="'.$module.'">';
  3263. $doleditor = new DolEditor('editfilecontent', $content, '', '300', 'Full', 'In', true, false, 'ace', 0, '99%');
  3264. print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ? GETPOST('format', 'aZ09') : 'text'));
  3265. print '<br>';
  3266. print '<center>';
  3267. print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
  3268. print ' &nbsp; ';
  3269. print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
  3270. print '</center>';
  3271. print '</form>';
  3272. }
  3273. }
  3274. if ($tab == 'objects') {
  3275. print '<!-- tab=objects -->'."\n";
  3276. $head3 = array();
  3277. $h = 0;
  3278. // Dir for module
  3279. $dir = $dirread.'/'.$modulelowercase.'/class';
  3280. $head3[$h][0] = $_SERVER["PHP_SELF"].'?tab=objects&module='.$module.($forceddirread ? '@'.$dirread : '').'&tabobj=newobject';
  3281. $head3[$h][1] = '<span class="valignmiddle text-plus-circle">'.$langs->trans("NewObjectInModulebuilder").'</span><span class="fa fa-plus-circle valignmiddle paddingleft"></span>';
  3282. $head3[$h][2] = 'newobject';
  3283. $h++;
  3284. // Scan for object class files
  3285. $listofobject = dol_dir_list($dir, 'files', 0, '\.class\.php$');
  3286. $firstobjectname = '';
  3287. foreach ($listofobject as $fileobj) {
  3288. if (preg_match('/^api_/', $fileobj['name'])) {
  3289. continue;
  3290. }
  3291. if (preg_match('/^actions_/', $fileobj['name'])) {
  3292. continue;
  3293. }
  3294. $tmpcontent = file_get_contents($fileobj['fullname']);
  3295. if (preg_match('/class\s+([^\s]*)\s+extends\s+CommonObject/ims', $tmpcontent, $reg)) {
  3296. //$objectname = preg_replace('/\.txt$/', '', $fileobj['name']);
  3297. $objectname = $reg[1];
  3298. if (empty($firstobjectname)) {
  3299. $firstobjectname = $objectname;
  3300. }
  3301. $pictoname = 'generic';
  3302. if (preg_match('/\$picto\s*=\s*["\']([^"\']+)["\']/', $tmpcontent, $reg)) {
  3303. $pictoname = $reg[1];
  3304. }
  3305. $head3[$h][0] = $_SERVER["PHP_SELF"].'?tab=objects&module='.$module.($forceddirread ? '@'.$dirread : '').'&tabobj='.$objectname;
  3306. $head3[$h][1] = img_picto('', $pictoname, 'class="pictofixedwidth valignmiddle"').$objectname;
  3307. $head3[$h][2] = $objectname;
  3308. $h++;
  3309. }
  3310. }
  3311. if ($h > 1) {
  3312. $head3[$h][0] = $_SERVER["PHP_SELF"].'?tab=objects&module='.$module.($forceddirread ? '@'.$dirread : '').'&tabobj=deleteobject';
  3313. $head3[$h][1] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("DangerZone");
  3314. $head3[$h][2] = 'deleteobject';
  3315. $h++;
  3316. }
  3317. // 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.
  3318. if ($tabobj == 'newobjectifnoobj') {
  3319. if ($firstobjectname) {
  3320. $tabobj = $firstobjectname;
  3321. } else {
  3322. $tabobj = 'newobject';
  3323. }
  3324. }
  3325. print dol_get_fiche_head($head3, $tabobj, '', -1, '', 0, '', '', 0, 'forobjectsuffix'); // Level 3
  3326. if ($tabobj == 'newobject') {
  3327. // New object tab
  3328. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  3329. print '<input type="hidden" name="token" value="'.newToken().'">';
  3330. print '<input type="hidden" name="action" value="initobject">';
  3331. print '<input type="hidden" name="tab" value="objects">';
  3332. print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
  3333. print '<span class="opacitymedium">'.$langs->trans("EnterNameOfObjectDesc").'</span><br><br>';
  3334. print '<div class="tagtable">';
  3335. print '<div class="tagtr"><div class="tagtd">';
  3336. print '<span class="opacitymedium">'.$langs->trans("ObjectKey").'</span> &nbsp; ';
  3337. print '</div><div class="tagtd">';
  3338. print '<input type="text" name="objectname" maxlength="64" value="'.dol_escape_htmltag(GETPOSTISSET('objectname') ? GETPOST('objectname', 'alpha') : $modulename).'" autofocus>';
  3339. print $form->textwithpicto('', $langs->trans("Example").': MyObject, ACamelCaseName, ...');
  3340. print '</div></div>';
  3341. print '<div class="tagtr"><div class="tagtd">';
  3342. print '<span class="opacitymedium">'.$langs->trans("Picto").'</span> &nbsp; ';
  3343. print '</div><div class="tagtd">';
  3344. print '<input type="text" name="idpicto" value="fa-file-o" placeholder="'.dol_escape_htmltag($langs->trans("Picto")).'">';
  3345. print $form->textwithpicto('', $langs->trans("Example").': fa-file-o, fa-globe, ... any font awesome code.<br>Advanced syntax is fa-fakey[_faprefix[_facolor[_fasize]]]');
  3346. print '</div></div>';
  3347. print '<div class="tagtr"><div class="tagtd">';
  3348. print '<span class="opacitymedium">'.$langs->trans("DefinePropertiesFromExistingTable").'</span> &nbsp; ';
  3349. print '</div><div class="tagtd">';
  3350. print '<input type="text" name="initfromtablename" value="'.GETPOST('initfromtablename').'" placeholder="'.$langs->trans("TableName").'">';
  3351. print $form->textwithpicto('', $langs->trans("DefinePropertiesFromExistingTableDesc").'<br>'.$langs->trans("DefinePropertiesFromExistingTableDesc2"));
  3352. print '</div></div>';
  3353. print '</div>';
  3354. print '<br>';
  3355. 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>';
  3356. print '<input type="checkbox" name="includedocgeneration" id="includedocgeneration" value="includedocgeneration"> <label for="includedocgeneration">'.$form->textwithpicto($langs->trans("IncludeDocGeneration"), $langs->trans("IncludeDocGenerationHelp")).'</label><br>';
  3357. print '<input type="checkbox" name="generatepermissions" id="generatepermissions" value="generatepermissions"> <label for="generatepermissions">'.$form->textwithpicto($langs->trans("GeneratePermissions"), $langs->trans("GeneratePermissionsHelp")).'</label><br>';
  3358. print '<br>';
  3359. print '<input type="submit" class="button small" name="create" value="'.dol_escape_htmltag($langs->trans("GenerateCode")).'"'.($dirins ? '' : ' disabled="disabled"').'>';
  3360. print '<br>';
  3361. print '<br>';
  3362. /*
  3363. print '<br>';
  3364. print '<span class="opacitymedium">'.$langs->trans("or").'</span>';
  3365. print '<br>';
  3366. print '<br>';
  3367. //print '<input type="checkbox" name="initfromtablecheck"> ';
  3368. print $langs->trans("InitStructureFromExistingTable");
  3369. print '<input type="text" name="initfromtablename" value="" placeholder="'.$langs->trans("TableName").'">';
  3370. print '<input type="submit" class="button smallpaddingimp" name="createtablearray" value="'.dol_escape_htmltag($langs->trans("GenerateCode")).'"'.($dirins ? '' : ' disabled="disabled"').'>';
  3371. print '<br>';
  3372. */
  3373. print '</form>';
  3374. } elseif ($tabobj == 'createproperty') {
  3375. $attributesUnique = array(
  3376. 'proplabel' => $form->textwithpicto($langs->trans("Label"), $langs->trans("YouCanUseTranslationKey")),
  3377. 'propname' => $form->textwithpicto($langs->trans("Code"), $langs->trans("PropertyDesc"), 1, 'help', 'extracss', 0, 3, 'propertyhelp'),
  3378. 'proptype' => $form->textwithpicto($langs->trans("Type"), $langs->trans("TypeOfFieldsHelpIntro").'<br><br>'.$langs->trans("TypeOfFieldsHelp"), 1, 'help', 'extracss', 0, 3, 'typehelp'),
  3379. 'proparrayofkeyval' => $form->textwithpicto($langs->trans("ArrayOfKeyValues"), $langs->trans("ArrayOfKeyValuesDesc")),
  3380. 'propnotnull' => $form->textwithpicto($langs->trans("NotNull"), $langs->trans("NotNullDesc")),
  3381. 'propdefault' => $langs->trans("DefaultValue"),
  3382. 'propindex' => $langs->trans("DatabaseIndex"),
  3383. 'propforeignkey' => $form->textwithpicto($langs->trans("ForeignKey"), $langs->trans("ForeignKeyDesc"), 1, 'help', 'extracss', 0, 3, 'foreignkeyhelp'),
  3384. 'propposition' => $langs->trans("Position"),
  3385. 'propenabled' => $form->textwithpicto($langs->trans("Enabled"), $langs->trans("EnabledDesc"), 1, 'help', 'extracss', 0, 3, 'enabledhelp'),
  3386. 'propvisible' => $form->textwithpicto($langs->trans("Visibility"), $langs->trans("VisibleDesc").'<br><br>'.$langs->trans("ItCanBeAnExpression"), 1, 'help', 'extracss', 0, 3, 'visiblehelp'),
  3387. 'propnoteditable' => $langs->trans("NotEditable"),
  3388. //'propalwayseditable' => $langs->trans("AlwaysEditable"),
  3389. 'propsearchall' => $form->textwithpicto($langs->trans("SearchAll"), $langs->trans("SearchAllDesc")),
  3390. 'propisameasure' => $form->textwithpicto($langs->trans("IsAMeasure"), $langs->trans("IsAMeasureDesc")),
  3391. 'propcss' => $langs->trans("CSSClass"),
  3392. 'propcssview' => $langs->trans("CSSViewClass"),
  3393. 'propcsslist' => $langs->trans("CSSListClass"),
  3394. 'prophelp' => $langs->trans("KeyForTooltip"),
  3395. 'propshowoncombobox' => $langs->trans("ShowOnCombobox"),
  3396. //'propvalidate' => $form->textwithpicto($langs->trans("Validate"), $langs->trans("ValidateModBuilderDesc")),
  3397. 'propcomment' => $langs->trans("Comment"),
  3398. );
  3399. print '<form action="'.$_SERVER["PHP_SELF"].'?tab=objects&module='.urlencode($module).'&tabobj=createproperty&obj='.urlencode(GETPOST('obj')).'" method="POST">';
  3400. print '<input type="hidden" name="token" value="'.newToken().'">';
  3401. print '<input type="hidden" name="action" value="addproperty">';
  3402. print '<input type="hidden" name="tab" value="objects">';
  3403. print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
  3404. print '<input type="hidden" name="obj" value="'.dol_escape_htmltag(GETPOST('obj')).'">';
  3405. print '<table class="border centpercent tableforfieldcreate">'."\n";
  3406. $counter = 0;
  3407. foreach ($attributesUnique as $key => $attribute) {
  3408. if ($counter % 2 === 0) {
  3409. print '<tr>';
  3410. }
  3411. if ($key == 'propname' || $key == 'proplabel') {
  3412. 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>';
  3413. } elseif ($key == 'proptype') {
  3414. print '<td class="titlefieldcreate fieldrequired">'.$attribute.'</td><td class="valuefieldcreate maxwidth50">';
  3415. print '<input class="maxwidth200" id="'.$key.'" list="datalist'.$key.'" type="text" name="'.$key.'" value="'.dol_escape_htmltag(GETPOST($key, 'alpha')).'">';
  3416. //print '<div id="suggestions"></div>';
  3417. print '<datalist id="datalist'.$key.'">';
  3418. print '<option>varchar(128)</option>';
  3419. print '<option>email</option>';
  3420. print '<option>phone</option>';
  3421. print '<option>ip</option>';
  3422. print '<option>url</option>';
  3423. print '<option>password</option>';
  3424. print '<option>text</option>';
  3425. print '<option>html</option>';
  3426. print '<option>date</option>';
  3427. print '<option>datetime</option>';
  3428. print '<option>integer</option>';
  3429. print '<option>double(28,4)</option>';
  3430. print '<option>real</option>';
  3431. print '<option>integer:ClassName:RelativePath/To/ClassFile.class.php[:1[:FILTER]]</option>';
  3432. // Combo with list of fields
  3433. /*
  3434. if (empty($formadmin)) {
  3435. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
  3436. $formadmin = new FormAdmin($db);
  3437. }
  3438. print $formadmin->selectTypeOfFields($key, GETPOST($key, 'alpha'));
  3439. */
  3440. print '</datalist>';
  3441. print '</td>';
  3442. //} elseif ($key == 'propvalidate') {
  3443. // 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>';
  3444. } elseif ($key == 'propvisible') {
  3445. 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>';
  3446. } elseif ($key == 'propenabled') {
  3447. //$default = "isModEnabled('".strtolower($module)."')";
  3448. $default = 1;
  3449. 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>';
  3450. } elseif ($key == 'proparrayofkeyval') {
  3451. 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>';
  3452. } else {
  3453. 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>';
  3454. }
  3455. $counter++;
  3456. if ($counter % 2 === 0) {
  3457. print '</tr>';
  3458. }
  3459. }
  3460. if ($counter % 2 !== 0) {
  3461. while ($counter % 2 !== 0) {
  3462. print '<td></td>';
  3463. $counter++;
  3464. }
  3465. print '</tr>';
  3466. }
  3467. print '</table><br>'."\n";
  3468. print '<div class="center">';
  3469. print '<input type="submit" class="button button-save" name="add" value="' . dol_escape_htmltag($langs->trans('Create')) . '">';
  3470. print '<input type="button" class="button button-cancel" name="cancel" value="' . dol_escape_htmltag($langs->trans('Cancel')) . '" onclick="goBack()">';
  3471. print '</div>';
  3472. print '</form>';
  3473. // javascript
  3474. print '<script>
  3475. function goBack() {
  3476. var url = "'.$_SERVER["PHP_SELF"].'?tab=objects&module='.urlencode($module).'";
  3477. window.location.href = url;
  3478. }
  3479. $(document).ready(function() {
  3480. $("#proplabel").on("keyup", function() {
  3481. console.log("key up on label");
  3482. s = cleanString($("#proplabel").val());
  3483. $("#propname").val(s);
  3484. });
  3485. function cleanString( stringtoclean )
  3486. {
  3487. // allow "a-z", "A-Z", "0-9" and "_"
  3488. stringtoclean = stringtoclean.replace(/[^a-z0-9_]+/ig, "");
  3489. stringtoclean = stringtoclean.toLowerCase();
  3490. if (!isNaN(stringtoclean)) {
  3491. return ""
  3492. }
  3493. while ( stringtoclean.length > 1 && !isNaN( stringtoclean.charAt(0)) ){
  3494. stringtoclean = stringtoclean.substr(1)
  3495. }
  3496. if (stringtoclean.length > 28) {
  3497. stringtoclean = stringtoclean.substring(0, 27);
  3498. }
  3499. return stringtoclean;
  3500. }
  3501. });';
  3502. print '</script>';
  3503. } elseif ($tabobj == 'deleteobject') {
  3504. // Delete object tab
  3505. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  3506. print '<input type="hidden" name="token" value="'.newToken().'">';
  3507. print '<input type="hidden" name="action" value="confirm_deleteobject">';
  3508. print '<input type="hidden" name="tab" value="objects">';
  3509. print '<input type="hidden" name="tabobj" value="deleteobject">';
  3510. print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
  3511. print $langs->trans("EnterNameOfObjectToDeleteDesc").'<br><br>';
  3512. print '<input type="text" name="objectname" value="'.dol_escape_htmltag($modulename).'" placeholder="'.dol_escape_htmltag($langs->trans("ObjectKey")).'">';
  3513. print '<input type="submit" class="button smallpaddingimp" name="delete" value="'.dol_escape_htmltag($langs->trans("Delete")).'"'.($dirins ? '' : ' disabled="disabled"').'>';
  3514. print '</form>';
  3515. } else {
  3516. // tabobj = module
  3517. if ($action == 'deleteproperty') {
  3518. $formconfirm = $form->formconfirm(
  3519. $_SERVER["PHP_SELF"].'?propertykey='.urlencode(GETPOST('propertykey', 'alpha')).'&objectname='.urlencode($objectname).'&tab='.urlencode($tab).'&module='.urlencode($module).'&tabobj='.urlencode($tabobj),
  3520. $langs->trans('Delete'),
  3521. $langs->trans('ConfirmDeleteProperty', GETPOST('propertykey', 'alpha')),
  3522. 'confirm_deleteproperty',
  3523. '',
  3524. 0,
  3525. 1
  3526. );
  3527. // Print form confirm
  3528. print $formconfirm;
  3529. }
  3530. if ($action != 'editfile' || empty($file)) {
  3531. try {
  3532. //$pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
  3533. $pathtoclass = strtolower($module).'/class/'.strtolower($tabobj).'.class.php';
  3534. $pathtoapi = strtolower($module).'/class/api_'.strtolower($module).'.class.php';
  3535. $pathtoagenda = strtolower($module).'/'.strtolower($tabobj).'_agenda.php';
  3536. $pathtocard = strtolower($module).'/'.strtolower($tabobj).'_card.php';
  3537. $pathtodocument = strtolower($module).'/'.strtolower($tabobj).'_document.php';
  3538. $pathtolist = strtolower($module).'/'.strtolower($tabobj).'_list.php';
  3539. $pathtonote = strtolower($module).'/'.strtolower($tabobj).'_note.php';
  3540. $pathtocontact = strtolower($module).'/'.strtolower($tabobj).'_contact.php';
  3541. $pathtophpunit = strtolower($module).'/test/phpunit/'.strtolower($tabobj).'Test.php';
  3542. // Try to load object class file
  3543. clearstatcache(true);
  3544. if (function_exists('opcache_invalidate')) {
  3545. opcache_invalidate($dirread.'/'.$pathtoclass, true); // remove the include cache hell !
  3546. }
  3547. if (empty($forceddirread) && empty($dirread)) {
  3548. $result = dol_include_once($pathtoclass);
  3549. $stringofinclude = "dol_include_once(".$pathtoclass.")";
  3550. } else {
  3551. $result = @include_once $dirread.'/'.$pathtoclass;
  3552. $stringofinclude = "@include_once ".$dirread.'/'.$pathtoclass;
  3553. }
  3554. if (class_exists($tabobj)) {
  3555. try {
  3556. $tmpobject = @new $tabobj($db);
  3557. } catch (Exception $e) {
  3558. dol_syslog('Failed to load Constructor of class: '.$e->getMessage(), LOG_WARNING);
  3559. }
  3560. } else {
  3561. print '<span class="warning">'.$langs->trans('Failed to find the class '.$tabobj.' despite the '.$stringofinclude).'</span><br><br>';
  3562. }
  3563. // Define path for sql file
  3564. $pathtosql = strtolower($module).'/sql/llx_'.strtolower($module).'_'.strtolower($tabobj).'-'.strtolower($module).'.sql';
  3565. $result = dol_buildpath($pathtosql);
  3566. if (! dol_is_file($result)) {
  3567. $pathtosql = strtolower($module).'/sql/llx_'.strtolower($module).'_'.strtolower($tabobj).'.sql';
  3568. $result = dol_buildpath($pathtosql);
  3569. if (! dol_is_file($result)) {
  3570. $pathtosql = 'install/mysql/tables/llx_'.strtolower($module).'_'.strtolower($tabobj).'-'.strtolower($module).'.sql';
  3571. $result = dol_buildpath($pathtosql);
  3572. if (! dol_is_file($result)) {
  3573. $pathtosql = 'install/mysql/tables/llx_'.strtolower($module).'-'.strtolower($module).'.sql';
  3574. $result = dol_buildpath($pathtosql);
  3575. if (! dol_is_file($result)) {
  3576. $pathtosql = 'install/mysql/tables/llx_'.strtolower($module).'.sql';
  3577. $pathtosqlextra = 'install/mysql/tables/llx_'.strtolower($module).'_extrafields.sql';
  3578. $result = dol_buildpath($pathtosql);
  3579. } else {
  3580. $pathtosqlextra = 'install/mysql/tables/llx_'.strtolower($module).'_extrafields-'.strtolower($module).'.sql';
  3581. }
  3582. } else {
  3583. $pathtosqlextra = 'install/mysql/tables/llx_'.strtolower($module).'_'.strtolower($tabobj).'_extrafields-'.strtolower($module).'.sql';
  3584. }
  3585. } else {
  3586. $pathtosqlextra = strtolower($module).'/sql/llx_'.strtolower($module).'_'.strtolower($tabobj).'_extrafields.sql';
  3587. }
  3588. } else {
  3589. $pathtosqlextra = strtolower($module).'/sql/llx_'.strtolower($module).'_'.strtolower($tabobj).'_extrafields-'.strtolower($module).'.sql';
  3590. }
  3591. $pathtosqlroot = preg_replace('/\/llx_.*$/', '', $pathtosql);
  3592. $pathtosqlkey = preg_replace('/\.sql$/', '.key.sql', $pathtosql);
  3593. $pathtosqlextrakey = preg_replace('/\.sql$/', '.key.sql', $pathtosqlextra);
  3594. $pathtolib = strtolower($module).'/lib/'.strtolower($module).'.lib.php';
  3595. $pathtoobjlib = strtolower($module).'/lib/'.strtolower($module).'_'.strtolower($tabobj).'.lib.php';
  3596. if (is_object($tmpobject) && property_exists($tmpobject, 'picto')) {
  3597. $pathtopicto = $tmpobject->picto;
  3598. $realpathtopicto = '';
  3599. } else {
  3600. $pathtopicto = strtolower($module).'/img/object_'.strtolower($tabobj).'.png';
  3601. $realpathtopicto = $dirread.'/'.$pathtopicto;
  3602. }
  3603. //var_dump($pathtoclass);
  3604. //var_dump($dirread);
  3605. $realpathtoclass = $dirread.'/'.$pathtoclass;
  3606. $realpathtoapi = $dirread.'/'.$pathtoapi;
  3607. $realpathtoagenda = $dirread.'/'.$pathtoagenda;
  3608. $realpathtocard = $dirread.'/'.$pathtocard;
  3609. $realpathtodocument = $dirread.'/'.$pathtodocument;
  3610. $realpathtolist = $dirread.'/'.$pathtolist;
  3611. $realpathtonote = $dirread.'/'.$pathtonote;
  3612. $realpathtocontact = $dirread.'/'.$pathtocontact;
  3613. $realpathtophpunit = $dirread.'/'.$pathtophpunit;
  3614. $realpathtosql = $dirread.'/'.$pathtosql;
  3615. $realpathtosqlextra = $dirread.'/'.$pathtosqlextra;
  3616. $realpathtosqlkey = $dirread.'/'.$pathtosqlkey;
  3617. $realpathtosqlextrakey = $dirread.'/'.$pathtosqlextrakey;
  3618. $realpathtolib = $dirread.'/'.$pathtolib;
  3619. $realpathtoobjlib = $dirread.'/'.$pathtoobjlib;
  3620. if (empty($realpathtoapi)) { // For compatibility with some old modules
  3621. $pathtoapi = strtolower($module).'/class/api_'.strtolower($module).'s.class.php';
  3622. $realpathtoapi = $dirread.'/'.$pathtoapi;
  3623. }
  3624. $urloflist = dol_buildpath('/'.$pathtolist, 1);
  3625. $urlofcard = dol_buildpath('/'.$pathtocard, 1);
  3626. $objs = array();
  3627. print '<!-- section for object -->';
  3628. print '<div class="fichehalfleft smallxxx">';
  3629. // Main DAO class file
  3630. 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>';
  3631. 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>';
  3632. print '<br>';
  3633. // Image
  3634. if ($realpathtopicto && dol_is_file($realpathtopicto)) {
  3635. 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>';
  3636. //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>';
  3637. print '<br>';
  3638. } elseif (!empty($tmpobject)) {
  3639. print '<span class="fa fa-file-image-o"></span> '.$langs->trans("Image").' : '.img_picto('', $tmpobject->picto, 'class="pictofixedwidth valignmiddle"').$tmpobject->picto;
  3640. print '<br>';
  3641. }
  3642. // API file
  3643. print '<br>';
  3644. 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>';
  3645. if (dol_is_file($realpathtoapi)) {
  3646. $file = file_get_contents($realpathtoapi);
  3647. if (preg_match('/var '.$tabobj.'\s+([^\s]*)\s/ims', $file, $objs)) {
  3648. 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>';
  3649. print ' ';
  3650. 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>';
  3651. print $form->textwithpicto('', $langs->trans("InfoForApiFile"), 1, 'warning');
  3652. print ' &nbsp; ';
  3653. if (!isModEnabled($modulelowercase)) { // If module is not activated
  3654. print '<a href="#" class="classfortooltip" target="apiexplorer" title="'.$langs->trans("ModuleMustBeEnabled", $module).'"><strike>'.$langs->trans("ApiExplorer").'</strike></a>';
  3655. } else {
  3656. print '<a href="'.DOL_URL_ROOT.'/api/index.php/explorer/" target="apiexplorer">'.$langs->trans("ApiExplorer").'</a>';
  3657. }
  3658. } else {
  3659. 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>';
  3660. }
  3661. } else {
  3662. 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>';
  3663. }
  3664. // PHPUnit
  3665. print '<br>';
  3666. 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>';
  3667. if (dol_is_file($realpathtophpunit)) {
  3668. 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>';
  3669. print ' ';
  3670. 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>';
  3671. } else {
  3672. 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>';
  3673. }
  3674. print '<br>';
  3675. print '<br>';
  3676. 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>';
  3677. 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>';
  3678. print '<br>';
  3679. 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>';
  3680. 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>';
  3681. print '<br>';
  3682. print '<br>';
  3683. 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>';
  3684. 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>';
  3685. 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>';
  3686. //print ' &nbsp; <a href="'.$_SERVER["PHP_SELF"].'">'.$langs->trans("RunSql").'</a>';
  3687. print '<br>';
  3688. 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>';
  3689. 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>';
  3690. //print ' &nbsp; <a href="'.$_SERVER["PHP_SELF"].'">'.$langs->trans("RunSql").'</a>';
  3691. print '<br>';
  3692. 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>';
  3693. if (dol_is_file($realpathtosqlextra) && dol_is_file($realpathtosqlextrakey)) {
  3694. 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>';
  3695. print ' ';
  3696. 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>';
  3697. print ' &nbsp; ';
  3698. 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>';
  3699. } else {
  3700. 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>';
  3701. }
  3702. //print ' &nbsp; <a href="'.$_SERVER["PHP_SELF"].'">'.$langs->trans("RunSql").'</a>';
  3703. print '<br>';
  3704. 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>';
  3705. if (dol_is_file($realpathtosqlextra) && dol_is_file($realpathtosqlextrakey)) {
  3706. 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>';
  3707. print ' ';
  3708. 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>';
  3709. } else {
  3710. 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>';
  3711. }
  3712. print '<br>';
  3713. print '</div>';
  3714. print '<div class="fichehalfleft smallxxxx">';
  3715. 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>';
  3716. 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>';
  3717. print '<br>';
  3718. 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>';
  3719. 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>';
  3720. print '<br>';
  3721. // Page contact
  3722. 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>';
  3723. 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>';
  3724. if (dol_is_file($realpathtocontact)) {
  3725. print ' ';
  3726. 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>';
  3727. } else {
  3728. 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>';
  3729. }
  3730. print '<br>';
  3731. // Page document
  3732. 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>';
  3733. 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>';
  3734. if (dol_is_file($realpathtodocument)) {
  3735. print ' ';
  3736. 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>';
  3737. } else {
  3738. 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>';
  3739. }
  3740. print '<br>';
  3741. // Page notes
  3742. 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>';
  3743. 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>';
  3744. if (dol_is_file($realpathtonote)) {
  3745. print ' ';
  3746. 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>';
  3747. } else {
  3748. 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>';
  3749. }
  3750. print '<br>';
  3751. // Page agenda
  3752. 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>';
  3753. 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>';
  3754. if (dol_is_file($realpathtoagenda)) {
  3755. print ' ';
  3756. 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>';
  3757. } else {
  3758. 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>';
  3759. }
  3760. print '<br>';
  3761. print '<br>';
  3762. print '</div>';
  3763. print '<br><br><br>';
  3764. if (!empty($tmpobject)) {
  3765. $reflector = new ReflectionClass($tabobj);
  3766. $reflectorproperties = $reflector->getProperties(); // Can also use get_object_vars
  3767. $reflectorpropdefault = $reflector->getDefaultProperties(); // Can also use get_object_vars
  3768. //$propstat = $reflector->getStaticProperties();
  3769. //var_dump($reflectorpropdefault);
  3770. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  3771. print '<input type="hidden" name="token" value="'.newToken().'">';
  3772. print '<input type="hidden" name="action" value="addproperty">';
  3773. print '<input type="hidden" name="tab" value="objects">';
  3774. print '<input type="hidden" name="page_y" value="">';
  3775. print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module.($forceddirread ? '@'.$dirread : '')).'">';
  3776. print '<input type="hidden" name="tabobj" value="'.dol_escape_htmltag($tabobj).'">';
  3777. print '<input class="button smallpaddingimp" type="submit" name="regenerateclasssql" value="'.$langs->trans("RegenerateClassAndSql").'">';
  3778. print '<br><br>';
  3779. $mod = strtolower($module);
  3780. $obj = strtolower($tabobj);
  3781. $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));
  3782. print_barre_liste($langs->trans("ObjectProperties"), 0, $_SERVER["PHP_SELF"], '', '', '', '', '', 0, '', 0, $newproperty, '', '', 0, 0, 1);
  3783. //var_dump($reflectorpropdefault);exit;
  3784. print '<!-- Table with properties of object -->'."\n";
  3785. print '<div class="div-table-responsive">';
  3786. print '<table class="noborder small">';
  3787. print '<tr class="liste_titre">';
  3788. print '<th class="tdsticky tdstickygray">';
  3789. $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>';
  3790. print $form->textwithpicto($langs->trans("Code"), $htmltext, 1, 'help', 'extracss', 0, 3, 'propertyhelp');
  3791. print '</th>';
  3792. print '<th>';
  3793. print $form->textwithpicto($langs->trans("Label"), $langs->trans("YouCanUseTranslationKey"));
  3794. print '</th>';
  3795. print '<th>'.$form->textwithpicto($langs->trans("Type"), $langs->trans("TypeOfFieldsHelpIntro").'<br><br>'.$langs->trans("TypeOfFieldsHelp"), 1, 'help', 'extracss', 0, 3, 'typehelp').'</th>';
  3796. print '<th>'.$form->textwithpicto($langs->trans("ArrayOfKeyValues"), $langs->trans("ArrayOfKeyValuesDesc")).'</th>';
  3797. print '<th class="center">'.$form->textwithpicto($langs->trans("NotNull"), $langs->trans("NotNullDesc")).'</th>';
  3798. print '<th class="center">'.$langs->trans("DefaultValue").'</th>';
  3799. print '<th class="center">'.$langs->trans("DatabaseIndex").'</th>';
  3800. print '<th class="center">'.$form->textwithpicto($langs->trans("ForeignKey"), $langs->trans("ForeignKeyDesc"), 1, 'help', 'extracss', 0, 3, 'foreignkeyhelp').'</th>';
  3801. print '<th class="right">'.$langs->trans("Position").'</th>';
  3802. print '<th class="center">'.$form->textwithpicto($langs->trans("Enabled"), $langs->trans("EnabledDesc"), 1, 'help', 'extracss', 0, 3, 'enabledhelp').'</th>';
  3803. print '<th class="center">'.$form->textwithpicto($langs->trans("Visibility"), $langs->trans("VisibleDesc").'<br><br>'.$langs->trans("ItCanBeAnExpression"), 1, 'help', 'extracss', 0, 3, 'visiblehelp').'</th>';
  3804. print '<th class="center">'.$langs->trans("NotEditable").'</th>';
  3805. //print '<th class="center">'.$langs->trans("AlwaysEditable").'</th>';
  3806. print '<th class="center">'.$form->textwithpicto($langs->trans("SearchAll"), $langs->trans("SearchAllDesc")).'</th>';
  3807. print '<th class="center">'.$form->textwithpicto($langs->trans("IsAMeasure"), $langs->trans("IsAMeasureDesc")).'</th>';
  3808. print '<th class="center">'.$langs->trans("CSSClass").'</th>';
  3809. print '<th class="center">'.$langs->trans("CSSViewClass").'</th>';
  3810. print '<th class="center">'.$langs->trans("CSSListClass").'</th>';
  3811. print '<th>'.$langs->trans("KeyForTooltip").'</th>';
  3812. print '<th class="center">'.$langs->trans("ShowOnCombobox").'</th>';
  3813. //print '<th class="center">'.$langs->trans("Disabled").'</th>';
  3814. print '<th>'.$form->textwithpicto($langs->trans("Validate"), $langs->trans("ValidateModBuilderDesc")).'</th>';
  3815. print '<th>'.$langs->trans("Comment").'</th>';
  3816. print '<th class="tdstickyright tdstickyghostwhite"></th>';
  3817. print '</tr>';
  3818. // We must use $reflectorpropdefault['fields'] to get list of fields because $tmpobject->fields may have been
  3819. // modified during the constructor and we want value into head of class before constructor is called.
  3820. //$properties = dol_sort_array($tmpobject->fields, 'position');
  3821. $properties = dol_sort_array($reflectorpropdefault['fields'], 'position');
  3822. if (!empty($properties)) {
  3823. // List of existing properties
  3824. foreach ($properties as $propkey => $propval) {
  3825. /* If from Reflection
  3826. if ($propval->class == $tabobj)
  3827. {
  3828. $propname=$propval->getName();
  3829. $comment=$propval->getDocComment();
  3830. $type=gettype($tmpobject->$propname);
  3831. $default=$propdefault[$propname];
  3832. // Discard generic properties
  3833. if (in_array($propname, array('element', 'childtables', 'table_element', 'table_element_line', 'class_element_line', 'ismultientitymanaged'))) continue;
  3834. // Keep or not lines
  3835. if (in_array($propname, array('fk_element', 'lines'))) continue;
  3836. }*/
  3837. $propname = $propkey;
  3838. $proplabel = $propval['label'];
  3839. $proptype = $propval['type'];
  3840. $proparrayofkeyval = !empty($propval['arrayofkeyval']) ? $propval['arrayofkeyval'] : '';
  3841. $propnotnull = !empty($propval['notnull']) ? $propval['notnull'] : '0';
  3842. $propdefault = !empty($propval['default']) ? $propval['default'] : '';
  3843. $propindex = !empty($propval['index']) ? $propval['index'] : '';
  3844. $propforeignkey = !empty($propval['foreignkey']) ? $propval['foreignkey'] : '';
  3845. $propposition = $propval['position'];
  3846. $propenabled = $propval['enabled'];
  3847. $propvisible = $propval['visible'];
  3848. $propnoteditable = !empty($propval['noteditable']) ? $propval['noteditable'] : 0;
  3849. //$propalwayseditable = !empty($propval['alwayseditable'])?$propval['alwayseditable']:0;
  3850. $propsearchall = !empty($propval['searchall']) ? $propval['searchall'] : 0;
  3851. $propisameasure = !empty($propval['isameasure']) ? $propval['isameasure'] : 0;
  3852. $propcss = !empty($propval['css']) ? $propval['css'] : '';
  3853. $propcssview = !empty($propval['cssview']) ? $propval['cssview'] : '';
  3854. $propcsslist = !empty($propval['csslist']) ? $propval['csslist'] : '';
  3855. $prophelp = !empty($propval['help']) ? $propval['help'] : '';
  3856. $propshowoncombobox = !empty($propval['showoncombobox']) ? $propval['showoncombobox'] : 0;
  3857. //$propdisabled=$propval['disabled'];
  3858. $propvalidate = !empty($propval['validate']) ? $propval['validate'] : 0;
  3859. $propcomment = !empty($propval['comment']) ? $propval['comment'] : '';
  3860. print '<!-- line for object property -->'."\n";
  3861. print '<tr class="oddeven">';
  3862. print '<td class="tdsticky tdstickygray">';
  3863. print dol_escape_htmltag($propname);
  3864. print '</td>';
  3865. if ($action == 'editproperty' && $propname == $propertykey) {
  3866. print '<td>';
  3867. print '<input type="hidden" name="propname" value="'.dol_escape_htmltag($propname).'">';
  3868. print '<input name="proplabel" class="maxwidth125" value="'.dol_escape_htmltag($proplabel).'">';
  3869. print '</td>';
  3870. print '<td class="tdoverflowmax150">';
  3871. print '<input name="proptype" class="maxwidth125" value="'.dol_escape_htmltag($proptype).'"></input>';
  3872. print '</td>';
  3873. print '<td class="tdoverflowmax200">';
  3874. print '<textarea name="proparrayofkeyval">';
  3875. if (isset($proparrayofkeyval)) {
  3876. if (is_array($proparrayofkeyval) || $proparrayofkeyval != '') {
  3877. print dol_escape_htmltag(json_encode($proparrayofkeyval, JSON_UNESCAPED_UNICODE));
  3878. }
  3879. }
  3880. print '</textarea>';
  3881. print '</td>';
  3882. print '<td>';
  3883. print '<input class="center width50" name="propnotnull" value="'.dol_escape_htmltag($propnotnull).'">';
  3884. print '</td>';
  3885. print '<td>';
  3886. print '<input class="maxwidth50" name="propdefault" value="'.dol_escape_htmltag($propdefault).'">';
  3887. print '</td>';
  3888. print '<td class="center">';
  3889. print '<input class="center maxwidth50" name="propindex" value="'.dol_escape_htmltag($propindex).'">';
  3890. print '</td>';
  3891. print '<td>';
  3892. print '<input class="center maxwidth100" name="propforeignkey" value="'.dol_escape_htmltag($propforeignkey).'">';
  3893. print '</td>';
  3894. print '<td>';
  3895. print '<input class="right width50" name="propposition" value="'.dol_escape_htmltag($propposition).'">';
  3896. print '</td>';
  3897. print '<td>';
  3898. print '<input class="center width75" name="propenabled" value="'.dol_escape_htmltag($propenabled).'">';
  3899. print '</td>';
  3900. print '<td>';
  3901. print '<input class="center width75" name="propvisible" value="'.dol_escape_htmltag($propvisible).'">';
  3902. print '</td>';
  3903. print '<td>';
  3904. print '<input class="center width50" name="propnoteditable" size="2" value="'.dol_escape_htmltag($propnoteditable).'">';
  3905. print '</td>';
  3906. /*print '<td>';
  3907. print '<input class="center" name="propalwayseditable" size="2" value="'.dol_escape_htmltag($propalwayseditable).'">';
  3908. print '</td>';*/
  3909. print '<td>';
  3910. print '<input class="center width50" name="propsearchall" value="'.dol_escape_htmltag($propsearchall).'">';
  3911. print '</td>';
  3912. print '<td>';
  3913. print '<input class="center width50" name="propisameasure" value="'.dol_escape_htmltag($propisameasure).'">';
  3914. print '</td>';
  3915. print '<td>';
  3916. print '<input class="center maxwidth50" name="propcss" value="'.dol_escape_htmltag($propcss).'">';
  3917. print '</td>';
  3918. print '<td>';
  3919. print '<input class="center maxwidth50" name="propcssview" value="'.dol_escape_htmltag($propcssview).'">';
  3920. print '</td>';
  3921. print '<td>';
  3922. print '<input class="center maxwidth50" name="propcsslist" value="'.dol_escape_htmltag($propcsslist).'">';
  3923. print '</td>';
  3924. print '<td>';
  3925. print '<input class="maxwidth100" name="prophelp" value="'.dol_escape_htmltag($prophelp).'">';
  3926. print '</td>';
  3927. print '<td>';
  3928. print '<input class="center maxwidth50" name="propshowoncombobox" value="'.dol_escape_htmltag($propshowoncombobox).'">';
  3929. print '</td>';
  3930. print '<td>';
  3931. print '<input type="number" step="1" min="0" max="1" class="text maxwidth100" name="propvalidate" value="'.dol_escape_htmltag($propvalidate).'">';
  3932. print '</td>';
  3933. print '<td>';
  3934. print '<input class="maxwidth100" name="propcomment" value="'.dol_escape_htmltag($propcomment).'">';
  3935. print '</td>';
  3936. print '<td class="center minwidth75 tdstickyright tdstickyghostwhite">';
  3937. print '<input class="reposition button smallpaddingimp" type="submit" name="edit" value="'.$langs->trans("Save").'">';
  3938. print '<input class="reposition button button-cancel smallpaddingimp" type="submit" name="cancel" value="'.$langs->trans("Cancel").'">';
  3939. print '</td>';
  3940. } else {
  3941. print '<td class="tdoverflowmax200" title="'.dol_escape_htmltag($proplabel).'">';
  3942. print dol_escape_htmltag($proplabel);
  3943. print '</td>';
  3944. print '<td class="tdoverflowmax200">';
  3945. $pictoType = '';
  3946. $matches = array();
  3947. if (preg_match('/^varchar/', $proptype, $matches)) {
  3948. $pictoType = 'varchar';
  3949. } elseif (preg_match('/^integer:/', $proptype, $matches)) {
  3950. $pictoType = 'link';
  3951. } elseif (strpos($proptype, 'integer') === 0) {
  3952. $pictoType = substr($proptype, 0, 3);
  3953. } elseif (strpos($proptype, 'timestamp') === 0) {
  3954. $pictoType = 'datetime';
  3955. } elseif (strpos($proptype, 'real') === 0) {
  3956. $pictoType = 'double';
  3957. }
  3958. print(!empty($pictoType) ? getPictoForType($pictoType) : getPictoForType($proptype)).'<span title="'.dol_escape_htmltag($proptype).'">'.dol_escape_htmltag($proptype).'</span>';
  3959. print '</td>';
  3960. print '<td class="tdoverflowmax200">';
  3961. if ($proparrayofkeyval) {
  3962. print '<span title="'.dol_escape_htmltag(json_encode($proparrayofkeyval, JSON_UNESCAPED_UNICODE)).'">';
  3963. print dol_escape_htmltag(json_encode($proparrayofkeyval, JSON_UNESCAPED_UNICODE));
  3964. print '</span>';
  3965. }
  3966. print '</td>';
  3967. print '<td class="center">';
  3968. print dol_escape_htmltag($propnotnull);
  3969. print '</td>';
  3970. print '<td>';
  3971. print dol_escape_htmltag($propdefault);
  3972. print '</td>';
  3973. print '<td class="center">';
  3974. print $propindex ? '1' : '';
  3975. print '</td>';
  3976. print '<td class="center">';
  3977. print $propforeignkey ? dol_escape_htmltag($propforeignkey) : '';
  3978. print '</td>';
  3979. print '<td class="right">';
  3980. print dol_escape_htmltag($propposition);
  3981. print '</td>';
  3982. print '<td class="center tdoverflowmax100" title="'.($propnoteditable ? dol_escape_htmltag($propnoteditable) : '').'">';
  3983. print $propenabled ? dol_escape_htmltag($propenabled) : '';
  3984. print '</td>';
  3985. // Visibility
  3986. print '<td class="center tdoverflowmax100" title="'.($propvisible ? dol_escape_htmltag($propvisible) : '0').'">';
  3987. print $propvisible ? dol_escape_htmltag($propvisible) : '0';
  3988. print '</td>';
  3989. // Readonly
  3990. print '<td class="center tdoverflowmax100" title="'.($propnoteditable ? dol_escape_htmltag($propnoteditable) : '').'">';
  3991. print $propnoteditable ? dol_escape_htmltag($propnoteditable) : '';
  3992. print '</td>';
  3993. /*print '<td class="center">';
  3994. print $propalwayseditable ? dol_escape_htmltag($propalwayseditable) : '';
  3995. print '</td>';*/
  3996. print '<td class="center">';
  3997. print $propsearchall ? '1' : '';
  3998. print '</td>';
  3999. print '<td class="center">';
  4000. print $propisameasure ? dol_escape_htmltag($propisameasure) : '';
  4001. print '</td>';
  4002. print '<td class="center tdoverflowmax100" title="'.($propcss ? dol_escape_htmltag($propcss) : '').'">';
  4003. print $propcss ? dol_escape_htmltag($propcss) : '';
  4004. print '</td>';
  4005. print '<td class="center tdoverflowmax100" title="'.($propcssview ? dol_escape_htmltag($propcssview) : '').'">';
  4006. print $propcssview ? dol_escape_htmltag($propcssview) : '';
  4007. print '</td>';
  4008. print '<td class="center tdoverflowmax100" title="'.($propcsslist ? dol_escape_htmltag($propcsslist) : '').'">';
  4009. print $propcsslist ? dol_escape_htmltag($propcsslist) : '';
  4010. print '</td>';
  4011. // Key for tooltop
  4012. print '<td class="tdoverflowmax150" title="'.($prophelp ? dol_escape_htmltag($prophelp) : '').'">';
  4013. print $prophelp ? dol_escape_htmltag($prophelp) : '';
  4014. print '</td>';
  4015. print '<td class="center">';
  4016. print $propshowoncombobox ? dol_escape_htmltag($propshowoncombobox) : '';
  4017. print '</td>';
  4018. /*print '<td class="center">';
  4019. print $propdisabled?$propdisabled:'';
  4020. print '</td>';*/
  4021. print '<td class="center">';
  4022. print $propvalidate ? dol_escape_htmltag($propvalidate) : '';
  4023. print '</td>';
  4024. print '<td class="tdoverflowmax200">';
  4025. print '<span title="'.dol_escape_htmltag($propcomment).'">';
  4026. print dol_escape_htmltag($propcomment);
  4027. print '</span>';
  4028. print '</td>';
  4029. print '<td class="center minwidth75 tdstickyright tdstickyghostwhite">';
  4030. if ($propname != 'rowid') {
  4031. 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>';
  4032. 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>';
  4033. }
  4034. print '</td>';
  4035. }
  4036. print '</tr>';
  4037. }
  4038. } else {
  4039. if ($tab == 'specifications') {
  4040. if ($action != 'editfile' || empty($file)) {
  4041. print '<span class="opacitymedium">'.$langs->trans("SpecDefDesc").'</span><br>';
  4042. print '<br>';
  4043. $specs = dol_dir_list(dol_buildpath($modulelowercase.'/doc', 0), 'files', 1, '(\.md|\.asciidoc)$', array('\/temp\/'));
  4044. foreach ($specs as $spec) {
  4045. $pathtofile = $modulelowercase.'/doc/'.$spec['relativename'];
  4046. $format = 'asciidoc';
  4047. if (preg_match('/\.md$/i', $spec['name'])) {
  4048. $format = 'markdown';
  4049. }
  4050. print '<span class="fa fa-file-o"></span> '.$langs->trans("SpecificationFile").' : <strong class="wordbreak">'.$pathtofile.'</strong>';
  4051. 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>';
  4052. print '<br>';
  4053. }
  4054. } else {
  4055. // Use MD or asciidoc
  4056. //print $langs->trans("UseAsciiDocFormat").'<br>';
  4057. $fullpathoffile = dol_buildpath($file, 0);
  4058. $content = file_get_contents($fullpathoffile);
  4059. // New module
  4060. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  4061. print '<input type="hidden" name="token" value="'.newToken().'">';
  4062. print '<input type="hidden" name="action" value="savefile">';
  4063. print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
  4064. print '<input type="hidden" name="tab" value="'.$tab.'">';
  4065. print '<input type="hidden" name="module" value="'.$module.'">';
  4066. $doleditor = new DolEditor('editfilecontent', $content, '', '300', 'Full', 'In', true, false, 'ace', 0, '99%');
  4067. print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ? GETPOST('format', 'aZ09') : 'html'));
  4068. print '<br>';
  4069. print '<center>';
  4070. print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
  4071. print ' &nbsp; ';
  4072. print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
  4073. print '</center>';
  4074. print '</form>';
  4075. }
  4076. }
  4077. 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>';
  4078. }
  4079. print '</table>';
  4080. print '</div>';
  4081. print '</form>';
  4082. } else {
  4083. print '<span class="warning">'.$langs->trans('Failed to init the object with the new '.$tabobj.'($db)').'</warning>';
  4084. }
  4085. } catch (Exception $e) {
  4086. print $e->getMessage();
  4087. }
  4088. } else {
  4089. if (empty($forceddirread)) {
  4090. $fullpathoffile = dol_buildpath($file, 0);
  4091. } else {
  4092. $fullpathoffile = $dirread.'/'.$file;
  4093. }
  4094. $content = file_get_contents($fullpathoffile);
  4095. // New module
  4096. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  4097. print '<input type="hidden" name="token" value="'.newToken().'">';
  4098. print '<input type="hidden" name="action" value="savefile">';
  4099. print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
  4100. print '<input type="hidden" name="tab" value="'.$tab.'">';
  4101. print '<input type="hidden" name="tabobj" value="'.dol_escape_htmltag($tabobj).'">';
  4102. print '<input type="hidden" name="module" value="'.$module.($forceddirread ? '@'.$dirread : '').'">';
  4103. $doleditor = new DolEditor('editfilecontent', $content, '', '300', 'Full', 'In', true, false, 'ace', 0, '99%');
  4104. print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ? GETPOST('format', 'aZ09') : 'html'));
  4105. print '<br>';
  4106. print '<center>';
  4107. print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
  4108. print ' &nbsp; ';
  4109. print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
  4110. print '</center>';
  4111. print '</form>';
  4112. }
  4113. }
  4114. print dol_get_fiche_end(); // Level 3
  4115. }
  4116. if ($tab == 'dictionaries') {
  4117. print '<!-- tab=dictionaries -->'."\n";
  4118. $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
  4119. $dicts = $moduleobj->dictionaries;
  4120. if ($action == 'deletedict') {
  4121. $formconfirm = $form->formconfirm(
  4122. $_SERVER["PHP_SELF"].'?dictionnarykey='.urlencode(GETPOST('dictionnarykey', 'int')).'&tab='.urlencode($tab).'&module='.urlencode($module),
  4123. $langs->trans('Delete'),
  4124. $langs->trans('Confirm Delete Dictionnary', GETPOST('dictionnarykey', 'alpha')),
  4125. 'confirm_deletedictionary',
  4126. '',
  4127. 0,
  4128. 1
  4129. );
  4130. print $formconfirm;
  4131. }
  4132. if ($action != 'editfile' || empty($file)) {
  4133. print '<span class="opacitymedium">';
  4134. $htmlhelp = $langs->trans("DictionariesDefDescTooltip", '{s1}');
  4135. $htmlhelp = str_replace('{s1}', '<a target="adminbis" class="nofocusvisible" href="'.DOL_URL_ROOT.'/admin/dict.php">'.$langs->trans('Setup').' - '.$langs->trans('Dictionaries').'</a>', $htmlhelp);
  4136. print $form->textwithpicto($langs->trans("DictionariesDefDesc"), $htmlhelp, 1, 'help', '', 0, 2, 'helpondesc').'<br>';
  4137. print '</span>';
  4138. print '<br>';
  4139. print '<span class="fa fa-file-o"></span> '.$langs->trans("DescriptorFile").' : <strong class="wordbreak">'.$pathtofile.'</strong>';
  4140. 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>';
  4141. print '<br>';
  4142. if (is_array($dicts) && !empty($dicts)) {
  4143. print '<span class="fa fa-file-o"></span> '.$langs->trans("LanguageFile").' :</span> ';
  4144. print '<strong class="wordbreak">'.$dicts['langs'].'</strong>';
  4145. print '<br>';
  4146. }
  4147. $head3 = array();
  4148. $h = 0;
  4149. // Dir for module
  4150. //$dir = $dirread.'/'.$modulelowercase.'/class';
  4151. $head3[$h][0] = $_SERVER["PHP_SELF"].'?tab=dictionaries&module='.$module.($forceddirread ? '@'.$dirread : '').'&tabdic=newdictionary';
  4152. $head3[$h][1] = '<span class="valignmiddle text-plus-circle">'.$langs->trans("NewDictionary").'</span><span class="fa fa-plus-circle valignmiddle paddingleft"></span>';
  4153. $head3[$h][2] = 'newdictionary';
  4154. $h++;
  4155. // Scan for object class files
  4156. //$listofobject = dol_dir_list($dir, 'files', 0, '\.class\.php$');
  4157. $firstdicname = '';
  4158. // if (!empty($dicts['tabname'])) {
  4159. // foreach ($dicts['tabname'] as $key => $dic) {
  4160. // $dicname = $dic;
  4161. // $diclabel = $dicts['tablib'][$key];
  4162. // if (empty($firstdicname)) {
  4163. // $firstdicname = $dicname;
  4164. // }
  4165. // $head3[$h][0] = $_SERVER["PHP_SELF"].'?tab=dictionaries&module='.$module.($forceddirread ? '@'.$dirread : '').'&tabdic='.$dicname;
  4166. // $head3[$h][1] = $diclabel;
  4167. // $head3[$h][2] = $dicname;
  4168. // $h++;
  4169. // }
  4170. // }
  4171. // if ($h > 1) {
  4172. // $head3[$h][0] = $_SERVER["PHP_SELF"].'?tab=dictionaries&module='.$module.($forceddirread ? '@'.$dirread : '').'&tabdic=deletedictionary';
  4173. // $head3[$h][1] = $langs->trans("DangerZone");
  4174. // $head3[$h][2] = 'deletedictionary';
  4175. // $h++;
  4176. // }
  4177. // 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.
  4178. // if ($tabdic == 'newdicifnodic') {
  4179. // if ($firstdicname) {
  4180. // $tabdic = $firstdicname;
  4181. // } else {
  4182. // $tabdic = 'newdictionary';
  4183. // }
  4184. // }
  4185. //print dol_get_fiche_head($head3, $tabdic, '', -1, ''); // Level 3
  4186. $newdict = dolGetButtonTitle($langs->trans('NewDictionary'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/modulebuilder/index.php?tab=dictionaries&module='.urlencode($module).'&tabdic=newdictionary');
  4187. print_barre_liste($langs->trans("ListOfDictionariesEntries"), '', $_SERVER["PHP_SELF"], '', '', '', '', '', '', '', 0, $newdict, '', '', 0, 0, 1);
  4188. if ($tabdic != 'newdictionary') {
  4189. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  4190. print '<input type="hidden" name="token" value="'.newToken().'">';
  4191. print '<input type="hidden" name="action" value="addDictionary">';
  4192. print '<input type="hidden" name="tab" value="dictionaries">';
  4193. print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
  4194. print '<input type="hidden" name="tabdic" value="'.dol_escape_htmltag($tabdic).'">';
  4195. print '<div class="div-table-responsive">';
  4196. print '<table class="noborder">';
  4197. print '<tr class="liste_titre">';
  4198. print_liste_field_titre("#", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder, 'thsticky thstickygrey ');
  4199. print_liste_field_titre("Table", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
  4200. print_liste_field_titre("Label", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
  4201. print_liste_field_titre("SQL", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
  4202. print_liste_field_titre("SQLSort", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
  4203. print_liste_field_titre("FieldsView", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
  4204. print_liste_field_titre("FieldsEdit", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
  4205. print_liste_field_titre("FieldsInsert", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
  4206. print_liste_field_titre("Rowid", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
  4207. print_liste_field_titre("Condition", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
  4208. print_liste_field_titre("", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
  4209. print "</tr>\n";
  4210. if (!empty($dicts) && is_array($dicts) && !empty($dicts['tabname']) && is_array($dicts['tabname'])) {
  4211. $i = 0;
  4212. $maxi = count($dicts['tabname']);
  4213. while ($i < $maxi) {
  4214. if ($action == 'editdict' && $i == (int) GETPOST('dictionnarykey', 'int')-1) {
  4215. print '<tr class="oddeven">';
  4216. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  4217. print '<input type="hidden" name="token" value="'.newToken().'">';
  4218. print '<input type="hidden" name="tab" value="dictionaries">';
  4219. print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
  4220. print '<input type="hidden" name="action" value="updatedictionary">';
  4221. print '<input type="hidden" name="dictionnarykey" value="'.($i+1).'">';
  4222. print '<td class="tdsticky tdstickygray">';
  4223. print($i + 1);
  4224. print '</td>';
  4225. print '<td>';
  4226. print '<input type="text" name="tabname" value="'.$dicts['tabname'][$i].'" readonly class="tdstickygray">';
  4227. print '</td>';
  4228. print '<td>';
  4229. print '<input type="text" name="tablib" value="'.$dicts['tablib'][$i].'">';
  4230. print '</td>';
  4231. print '<td>';
  4232. print '<input type="text" name="tabsql" value="'.$dicts['tabsql'][$i].'" readonly class="tdstickygray">';
  4233. print '</td>';
  4234. print '<td>';
  4235. print '<select name="tabsqlsort">';
  4236. print '<option value="'.dol_escape_htmltag($dicts['tabsqlsort'][$i]).'">'.$dicts['tabsqlsort'][$i].'</option>';
  4237. print '</select>';
  4238. print '</td>';
  4239. print '<td><select name="tabfield" >';
  4240. print '<option value="'.dol_escape_htmltag($dicts['tabfield'][$i]).'">'.$dicts['tabfield'][$i].'</option>';
  4241. print '</select></td>';
  4242. print '<td><select name="tabfieldvalue" >';
  4243. print '<option value="'.dol_escape_htmltag($dicts['tabfieldvalue'][$i]).'">'.$dicts['tabfieldvalue'][$i].'</option>';
  4244. print '</select></td>';
  4245. print '<td><select name="tabfieldinsert" >';
  4246. print '<option value="'.dol_escape_htmltag($dicts['tabfieldinsert'][$i]).'">'.$dicts['tabfieldinsert'][$i].'</option>';
  4247. print '</select></td>';
  4248. print '<td>';
  4249. print '<input type="text" name="tabrowid" value="'.dol_escape_htmltag($dicts['tabrowid'][$i]).'" readonly class="tdstickygray">';
  4250. print '</td>';
  4251. print '<td>';
  4252. print '<input type="text" name="tabcond" value="'.dol_escape_htmltag((empty($dicts['tabcond'][$i]) ? 'disabled' : 'enabled')).'" readonly class="tdstickygray">';
  4253. print '</td>';
  4254. print '<td class="center minwidth75 tdstickyright tdstickyghostwhite">';
  4255. print '<input id ="updatedict" class="reposition button smallpaddingimp" type="submit" name="updatedict" value="'.$langs->trans("Modify").'"/>';
  4256. print '<br>';
  4257. print '<input class="reposition button button-cancel smallpaddingimp" type="submit" name="cancel" value="'.$langs->trans("Cancel").'"/>';
  4258. print '</td>';
  4259. print '</form>';
  4260. print '</tr>';
  4261. } else {
  4262. print '<tr class="oddeven">';
  4263. print '<td class="tdsticky tdstickygray">';
  4264. print($i + 1);
  4265. print '</td>';
  4266. print '<td>';
  4267. print $dicts['tabname'][$i];
  4268. print '</td>';
  4269. print '<td>';
  4270. print $dicts['tablib'][$i];
  4271. print '</td>';
  4272. print '<td>';
  4273. print $dicts['tabsql'][$i];
  4274. print '</td>';
  4275. print '<td>';
  4276. print $dicts['tabsqlsort'][$i];
  4277. print '</td>';
  4278. print '<td>';
  4279. print $dicts['tabfield'][$i];
  4280. print '</td>';
  4281. print '<td>';
  4282. print $dicts['tabfieldvalue'][$i];
  4283. print '</td>';
  4284. print '<td>';
  4285. print $dicts['tabfieldinsert'][$i];
  4286. print '</td>';
  4287. print '<td >';
  4288. print $dicts['tabrowid'][$i];
  4289. print '</td>';
  4290. print '<td >';
  4291. print $dicts['tabcond'][$i];
  4292. print '</td>';
  4293. print '<td class="center minwidth75 tdstickyright tdstickyghostwhite">';
  4294. 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>';
  4295. 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>';
  4296. print '</td>';
  4297. print '</tr>';
  4298. }
  4299. $i++;
  4300. }
  4301. } else {
  4302. print '<tr><td colspan="11"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
  4303. }
  4304. print '</table>';
  4305. print '</div>';
  4306. print '</form>';
  4307. }
  4308. if ($tabdic == 'newdictionary') {
  4309. // New dic tab
  4310. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  4311. print '<input type="hidden" name="token" value="'.newToken().'">';
  4312. print '<input type="hidden" name="action" value="initdic">';
  4313. print '<input type="hidden" name="tab" value="dictionaries">';
  4314. print '<input type="hidden" name="tabdic" value="'.$tabdic.'">';
  4315. print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
  4316. print '<span class="opacitymedium">'.$langs->trans("EnterNameOfDictionaryDesc").'</span><br><br>';
  4317. print dol_get_fiche_head('');
  4318. print '<table class="border centpercent">';
  4319. print '<tbody>';
  4320. 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>';
  4321. 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>';
  4322. 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>';
  4323. 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>';
  4324. print '<tr><td class="titlefieldcreate">'.$langs->trans("FieldsView").'</td><td><input type="text" name="field" value="'.dol_escape_htmltag(GETPOST('field', 'alpha')).'"></td></tr>';
  4325. print '<tr><td class="titlefieldcreate">'.$langs->trans("FieldsEdit").'</td><td><input type="text" name="fieldvalue" value="'.dol_escape_htmltag(GETPOST('fieldvalue', 'alpha')).'"></td></tr>';
  4326. print '<tr><td class="titlefieldcreate">'.$langs->trans("FieldsInsert").'</td><td><input type="text" name="fieldinsert" value="'.dol_escape_htmltag(GETPOST('fieldinsert', 'alpha')).'"></td></tr>';
  4327. print '<tr><td class="titlefieldcreate">'.$langs->trans("Rowid").'</td><td><input type="text" name="rowid" value="'.dol_escape_htmltag(GETPOST('rowid', 'alpha')).'"></td></tr>';
  4328. print '<tr></tr>';
  4329. print '</tbody></table>';
  4330. print '<input type="submit" class="button" name="create" value="'.dol_escape_htmltag($langs->trans("GenerateCode")).'"'.($dirins ? '' : ' disabled="disabled"').'>';
  4331. print '<input id="cancel" type="submit" class="button" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
  4332. print dol_get_fiche_end();
  4333. print '</form>';
  4334. print '<script>
  4335. $(document).ready(function() {
  4336. $("input[name=\'dicname\']").on("blur", function() {
  4337. if ($(this).val().length > 0) {
  4338. $("input[name=\'label\']").val($(this).val());
  4339. $("input[name=\'sql\']").val("SELECT f.rowid as rowid, f.code, f.label, f.active FROM llx_c_" + $(this).val() + " as f");
  4340. $("input[name=\'sqlsort\']").val("label ASC");
  4341. $("input[name=\'field\']").val("code,label");
  4342. $("input[name=\'fieldvalue\']").val("code,label");
  4343. $("input[name=\'fieldinsert\']").val("code,label");
  4344. $("input[name=\'rowid\']").val("rowid");
  4345. } else {
  4346. $("input[name=\'label\']").val("");
  4347. $("input[name=\'sql\']").val("");
  4348. $("input[name=\'sqlsort\']").val("");
  4349. $("input[name=\'field\']").val("");
  4350. $("input[name=\'fieldvalue\']").val("");
  4351. $("input[name=\'fieldinsert\']").val("");
  4352. $("input[name=\'rowid\']").val("");
  4353. }
  4354. });
  4355. $("input[id=\'cancel\']").click(function() {
  4356. window.history.back();
  4357. });
  4358. });
  4359. </script>';
  4360. /*print '<br>';
  4361. print '<br>';
  4362. print '<br>';
  4363. print '<span class="opacitymedium">'.$langs->trans("or").'</span>';
  4364. print '<br>';
  4365. print '<br>';
  4366. //print '<input type="checkbox" name="initfromtablecheck"> ';
  4367. print $langs->trans("InitStructureFromExistingTable");
  4368. print '<input type="text" name="initfromtablename" value="" placeholder="'.$langs->trans("TableName").'">';
  4369. print '<input type="submit" class="button smallpaddingimp" name="createtablearray" value="'.dol_escape_htmltag($langs->trans("GenerateCode")).'"'.($dirins ? '' : ' disabled="disabled"').'>';
  4370. print '<br>';
  4371. */
  4372. } elseif ($tabdic == 'deletedictionary') {
  4373. // Delete dic tab
  4374. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  4375. print '<input type="hidden" name="token" value="'.newToken().'">';
  4376. print '<input type="hidden" name="action" value="confirm_deletedictionary">';
  4377. print '<input type="hidden" name="tab" value="dictionaries">';
  4378. print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
  4379. print $langs->trans("EnterNameOfDictionnaryToDeleteDesc").'<br><br>';
  4380. print '<input type="text" name="dicname" value="'.dol_escape_htmltag($modulename).'" placeholder="'.dol_escape_htmltag($langs->trans("DicKey")).'">';
  4381. print '<input type="submit" class="button smallpaddingimp" name="delete" value="'.dol_escape_htmltag($langs->trans("Delete")).'"'.($dirins ? '' : ' disabled="disabled"').'>';
  4382. print '</form>';
  4383. }
  4384. print dol_get_fiche_end();
  4385. } else {
  4386. $fullpathoffile = dol_buildpath($file, 0);
  4387. $content = file_get_contents($fullpathoffile);
  4388. // New module
  4389. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  4390. print '<input type="hidden" name="token" value="'.newToken().'">';
  4391. print '<input type="hidden" name="action" value="savefile">';
  4392. print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
  4393. print '<input type="hidden" name="tab" value="'.$tab.'">';
  4394. print '<input type="hidden" name="module" value="'.$module.'">';
  4395. $doleditor = new DolEditor('editfilecontent', $content, '', '300', 'Full', 'In', true, false, 'ace', 0, '99%');
  4396. print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ? GETPOST('format', 'aZ09') : 'html'));
  4397. print '<br>';
  4398. print '<center>';
  4399. print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
  4400. print ' &nbsp; ';
  4401. print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
  4402. print '</center>';
  4403. print '</form>';
  4404. }
  4405. }
  4406. if ($tab == 'menus') {
  4407. print '<!-- tab=menus -->'."\n";
  4408. $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
  4409. $dirins = $listofmodules[strtolower($module)]['moduledescriptorrootpath'];
  4410. $destdir = $dirins.'/'.strtolower($module);
  4411. $listofobject = dol_dir_list($destdir.'/class', 'files', 0, '\.class\.php$');
  4412. $objects = dolGetListOfObjectclasses($destdir);
  4413. $leftmenus = array();
  4414. $menus = $moduleobj->menu;
  4415. $permissions = $moduleobj->rights;
  4416. $crud = array('read'=>'CRUDRead', 'write'=>'CRUDCreateWrite', 'delete'=>'Delete');
  4417. //grouped permissions
  4418. $groupedRights = array();
  4419. foreach ($permissions as $right) {
  4420. $key = $right[4];
  4421. if (!isset($groupedRights[$key])) {
  4422. $groupedRights[$key] = array();
  4423. }
  4424. $groupedRights[$key][] = $right;
  4425. }
  4426. $groupedRights_json = json_encode($groupedRights);
  4427. if ($action == 'deletemenu') {
  4428. $formconfirms = $form->formconfirm(
  4429. $_SERVER["PHP_SELF"].'?menukey='.urlencode(GETPOST('menukey', 'int')).'&tab='.urlencode($tab).'&module='.urlencode($module),
  4430. $langs->trans('Delete'),
  4431. ($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'))),
  4432. 'confirm_deletemenu',
  4433. '',
  4434. 0,
  4435. 1
  4436. );
  4437. print $formconfirms;
  4438. }
  4439. if ($action != 'editfile' || empty($file)) {
  4440. print '<span class="opacitymedium">';
  4441. $htmlhelp = $langs->trans("MenusDefDescTooltip", '{s1}');
  4442. $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);
  4443. print $form->textwithpicto($langs->trans("MenusDefDesc"), $htmlhelp, 1, 'help', '', 0, 2, 'helpondesc').'<br>';
  4444. print '</span>';
  4445. print '<br>';
  4446. print '<span class="fa fa-file-o"></span> '.$langs->trans("DescriptorFile").' : <strong class="wordbreak">'.$pathtofile.'</strong>';
  4447. 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>';
  4448. print '<br>';
  4449. print '<br>';
  4450. print load_fiche_titre($langs->trans("ListOfMenusEntries"), '', '');
  4451. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  4452. print '<input type="hidden" name="token" value="'.newToken().'">';
  4453. print '<input type="hidden" name="action" value="addmenu">';
  4454. print '<input type="hidden" name="tab" value="menus">';
  4455. print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
  4456. print '<input type="hidden" name="tabobj" value="'.dol_escape_htmltag($tabobj).'">';
  4457. print '<div class="div-table-responsive">';
  4458. print '<table class="noborder small">';
  4459. $htmltextenabled = '<u>'.$langs->trans("Examples").':</u><br>';
  4460. $htmltextenabled .= '1 <span class="opacitymedium">(module always enabled)</span><br>';
  4461. $htmltextenabled .= '0 <span class="opacitymedium">(module always disabled)</span><br>';
  4462. $htmltextenabled .= 'isModEnabled(\''.dol_escape_htmltag(strtolower($module)).'\') <span class="opacitymedium">(enabled when module is enabled)</span>';
  4463. $htmltextperms = '<u>'.$langs->trans("Examples").':</u><br>';
  4464. $htmltextperms .= '1 <span class="opacitymedium">(access always allowed)</span><br>';
  4465. $htmltextperms .= '$user->hasright(\''.dol_escape_htmltag(strtolower($module)).'\', \'myobject\', \'read\') <span class="opacitymedium">(access allowed if user has permission module->object->read)</span>';
  4466. print '<tr class="liste_titre">';
  4467. print_liste_field_titre("#", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder, 'center tdsticky tdstickygray ');
  4468. print_liste_field_titre("Position", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
  4469. print_liste_field_titre("Title", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder, 'center');
  4470. print_liste_field_titre("LinkToParentMenu", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder, 'minwidth100 ');
  4471. print_liste_field_titre("mainmenu", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
  4472. print_liste_field_titre("leftmenu", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
  4473. print_liste_field_titre("URL", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder, '', $langs->transnoentitiesnoconv('DetailUrl'));
  4474. print_liste_field_titre("LanguageFile", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
  4475. print_liste_field_titre("Position", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder, 'right ');
  4476. print_liste_field_titre("Enabled", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder, 'center ', $langs->trans('DetailEnabled').'<br><br>'.$htmltextenabled);
  4477. print_liste_field_titre("Rights", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder, '', $langs->trans('DetailRight').'<br><br>'.$htmltextperms);
  4478. print_liste_field_titre("Target", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder, '', $langs->trans('DetailTarget'));
  4479. print_liste_field_titre("MenuForUsers", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder, 'center minwidth100 ', $langs->trans('DetailUser'));
  4480. print_liste_field_titre("", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder, 'center ', $langs->trans(''));
  4481. print "</tr>\n";
  4482. $r = count($menus)+1;
  4483. // for adding menu on module
  4484. print '<tr>';
  4485. print '<td class="center tdsticky tdstickygray"><input type="hidden" readonly class="center maxwidth50" name="propenabled" value="#"></td>';
  4486. print '<td class="center">';
  4487. print '<select class="maxwidth50" name="type">';
  4488. print '<option value="">'.$langs->trans("........").'</option><option value="'.dol_escape_htmltag("left").'">left</option><option value="'.dol_escape_htmltag("top").'">top</option>';
  4489. print '</select></td>';
  4490. print '<td class="left"><input type="text" class="left maxwidth100" name="titre" value="'.dol_escape_htmltag(GETPOST('titre', 'alpha')).'"></td>';
  4491. print '<td class="left">';
  4492. print '<select name="fk_menu">';
  4493. print '<option value="">'.$langs->trans("........").'</option>';
  4494. foreach ($menus as $obj) {
  4495. if ($obj['type'] == 'left' && !empty($obj['leftmenu'])) {
  4496. print "<option value=".strtolower($obj['leftmenu']).">".$obj['leftmenu']."</option>";
  4497. }
  4498. }
  4499. print '</select>';
  4500. print '</td>';
  4501. 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>';
  4502. print '<td class="center"><input id="leftmenu" type="text" class="left maxwidth50" name="leftmenu" value="'.dol_escape_htmltag(GETPOST('leftmenu', 'alpha')).'"></td>';
  4503. // URL
  4504. print '<td class="left"><input id="url" type="text" class="left maxwidth100" name="url" value="'.dol_escape_htmltag(GETPOST('url', 'alpha')).'"></td>';
  4505. print '<td class="left"><input type="text" class="left maxwidth75" name="langs" value="'.strtolower($module).'@'.strtolower($module).'" readonly></td>';
  4506. // Position
  4507. print '<td class="center"><input type="text" class="center maxwidth50 tdstickygray" name="position" value="'.(1000+$r).'" readonly></td>';
  4508. // Enabled
  4509. print '<td class="center">';
  4510. print '<input type="enabled" class="maxwidth125" value="'.dol_escape_htmltag(GETPOSTISSET('enabled') ? GETPOST('enabled') : 'isModEnabled(\''.$module.'\')').'">';
  4511. /*
  4512. print '<select class="maxwidth" name="enabled">';
  4513. print '<option value="1" selected>'.$langs->trans("Show").'</option>';
  4514. print '<option value="0">'.$langs->trans("Hide").'</option>';
  4515. print '</select>';
  4516. */
  4517. print '</td>';
  4518. // Perms
  4519. print '<td class="left">';
  4520. print '<select class="maxwidth" name="objects" id="objects">';
  4521. print '<option value=""></option>';
  4522. if (is_array($objects)) {
  4523. foreach ($objects as $value) {
  4524. print '<option value="'.strtolower($value).'">'.dol_escape_htmltag(strtolower($value)).'</option>';
  4525. }
  4526. }
  4527. print '</select>';
  4528. print '<select class="maxwidth hideobject" name="perms" id="perms">';
  4529. print '</select>';
  4530. print '</td>';
  4531. print '<td class="center"><input type="text" class="center maxwidth50" name="target" value="'.dol_escape_htmltag(GETPOST('target', 'alpha')).'"></td>';
  4532. 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>';
  4533. print '<td class="center minwidth75 tdstickyright tdstickyghostwhite">';
  4534. print '<input type="submit" class="button" name="add" value="'.$langs->trans("Add").'">';
  4535. print '</td>';
  4536. print '</tr>';
  4537. // end form for add menu
  4538. //var_dump($menus);
  4539. // Loop on each menu entry
  4540. if (count($menus)) {
  4541. $i = 0;
  4542. foreach ($menus as $menu) {
  4543. $i++;
  4544. //for get parent in menu
  4545. $string = dol_escape_htmltag($menu['fk_menu']);
  4546. $value = substr($string, strpos($string, 'fk_leftmenu=') + strlen('fk_leftmenu='));
  4547. $propFk_menu = !empty($menu['fk_menu']) ? $menu['fk_menu'] : GETPOST('fk_menu');
  4548. $propTitre = !empty($menu['titre']) ? $menu['titre'] : GETPOST('titre');
  4549. $propMainmenu = !empty($menu['mainmenu']) ? $menu['mainmenu'] : GETPOST('mainmenu');
  4550. $propLeftmenu = !empty($menu['leftmenu']) ? $menu['leftmenu'] : GETPOST('leftmenu');
  4551. $propUrl = !empty($menu['url']) ? $menu['url'] : GETPOST('url', 'alpha');
  4552. $propPerms = !empty($menu['perms']) ? $menu['perms'] : GETPOST('perms');
  4553. $propUser = !empty($menu['user']) ? $menu['user'] : GETPOST('user');
  4554. $propTarget = !empty($menu['target']) ? $menu['target'] : GETPOST('target');
  4555. $propEnabled = !empty($menu['enabled']) ? $menu['enabled'] : GETPOST('enabled');
  4556. $objPerms = (empty($arguments[1]) ? '' : trim($arguments[1]));
  4557. $valPerms = (empty($arguments[2]) ? '' : trim($arguments[2]));
  4558. //$tabobject = ''; // We can't know what is $tabobject in most cases
  4559. if ($action == 'editmenu' && GETPOST('menukey', 'int') == $i) {
  4560. //var_dump($propPerms);exit;
  4561. print '<tr class="oddeven">';
  4562. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  4563. print '<input type="hidden" name="token" value="'.newToken().'">';
  4564. print '<input type="hidden" name="action" value="update_menu">';
  4565. print '<input type="hidden" name="tab" value="menus">';
  4566. print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
  4567. print '<input type="hidden" name="menukey" value="'.$i.'"/>';
  4568. //print '<input type="hidden" name="tabobject" value="'.dol_escape_htmltag($tabobject).'">';
  4569. print '<td class="tdsticky tdstickygray">';
  4570. print $i;
  4571. print '</td>';
  4572. // Position (top, left)
  4573. print '<td class="center">
  4574. <select class="center maxwidth50" name="type">
  4575. <option value="'.dol_escape_htmltag($menu['type']).'">
  4576. '.dol_escape_htmltag($menu['type']).'
  4577. </option>';
  4578. print '<option value="'.($menu['type'] == 'left' ? 'top' : 'left').'">';
  4579. if ($menu['type'] == 'left') {
  4580. print 'top';
  4581. } else {
  4582. print 'left';
  4583. }
  4584. print '</option></select></td>';
  4585. // Title
  4586. print '<td><input type="text" class="left maxwidth100" name="titre" value="'.dol_escape_htmltag($propTitre).'"></td>';
  4587. // Parent menu
  4588. print '<td>';
  4589. /*print '<select name="fk_menu" class="left maxwidth">';
  4590. print '<option value="'.dol_escape_htmltag($propFk_menu).'">'.dol_escape_htmltag($value).'</option>';
  4591. foreach ($menus as $obj) {
  4592. if ($obj['type'] == 'left' && $obj['leftmenu'] != $value && $obj['leftmenu'] != $menu['leftmenu']) {
  4593. print "<option value=".strtolower($obj['leftmenu']).">".$obj['leftmenu']."</option>";
  4594. }
  4595. }
  4596. print '</select>';*/
  4597. print '<input type="text" name="fk_menu" class="maxwidth150" value="'.dol_escape_htmltag($propFk_menu).'">';
  4598. print '</td>';
  4599. print '<td><input type="text" class="left maxwidth50" name="mainmenu" value="'.dol_escape_htmltag($propMainmenu).'" readonly></td>';
  4600. print '<td><input type="text" class="left maxwidth50" name="leftmenu" value="'.dol_escape_htmltag($propLeftmenu).'" readonly></td>';
  4601. // URL
  4602. print '<td><input type="text" class="left maxwidth250" name="url" value="'.dol_escape_htmltag($propUrl).'"></td>';
  4603. print '<td><input type="text" class="left maxwidth50" name="langs" value="'.strtolower($module).'@'.strtolower($module).'" readonly></td>';
  4604. // Position
  4605. print '<td class="center"><input type="text" class="center maxwidth50 tdstickygray" name="position" value="'.($menu['position']).'" readonly></td>';
  4606. // Enabled
  4607. print '<td class="nowraponall">';
  4608. print '<input type="text" class="maxwidth125" name="enabled" value="'.dol_escape_htmltag($propEnabled != '' ? $propEnabled : "isModEnabled('".dol_escape_htmltag($module)."')").'">';
  4609. $htmltext = '<u>'.$langs->trans("Examples").':</u><br>';
  4610. $htmltext .= '1 <span class="opacitymedium">(always enabled)</span><br>';
  4611. $htmltext .= '0 <span class="opacitymedium">(always disabled)</span><br>';
  4612. $htmltext .= 'isModEnabled(\''.dol_escape_htmltag($module).'\') <span class="opacitymedium">(enabled when module is enabled)</span><br>';
  4613. print $form->textwithpicto('', $htmltext);
  4614. /*
  4615. print '<select class="maxwidth50" name="enabledselect">';
  4616. print '<option value="1">1 (always enabled)</option>';
  4617. print '<option value="0">0 (always disabled)</option>';
  4618. print '<option value="isModEnabled(\''.dol_escape_htmltag($module).'\')" >isModEnabled(\''.dol_escape_htmltag($module).'\')</option>';
  4619. print '</select>';
  4620. */
  4621. print '</td>';
  4622. // Permissions
  4623. print '<td class="nowraponall">';
  4624. print '<input type="text" name="perms" value="'.dol_escape_htmltag($propPerms).'">';
  4625. /*
  4626. if (!empty($objPerms)) {
  4627. print '<input type="hidden" name="objects" value="'.$objPerms.'" />';
  4628. print '<select class="center maxwidth50" name="perms">';
  4629. if (!empty($valPerms)) {
  4630. print '<option selected value="'.dol_escape_htmltag($valPerms).'">'.dol_escape_htmltag($langs->trans($crud[$valPerms])).'</option>';
  4631. foreach ($crud as $key => $val) {
  4632. if ($valPerms != $key) {
  4633. print '<option value="'.dol_escape_htmltag($key).'">'.dol_escape_htmltag($langs->trans($val)).'</option>';
  4634. }
  4635. }
  4636. }
  4637. print '</select>';
  4638. } else {
  4639. print '<select class="center maxwidth50" name="objects">';
  4640. print '<option></option>';
  4641. foreach ($objects as $obj) {
  4642. print '<option value="'.dol_escape_htmltag(strtolower($obj)).'">'.dol_escape_htmltag($obj).'</option>';
  4643. }
  4644. print '</select>';
  4645. print '<select class="center maxwidth50" name="perms">';
  4646. foreach ($crud as $key => $val) {
  4647. print '<option value="'.dol_escape_htmltag($key).'">'.dol_escape_htmltag($key).'</option>';
  4648. }
  4649. print '</select>';
  4650. }*/
  4651. print '</td>';
  4652. // Target
  4653. print '<td class="center"><input type="text" class="center maxwidth50" name="target" value="'.dol_escape_htmltag($propTarget).'"></td>';
  4654. 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>';
  4655. print '<td class="center minwidth75 tdstickyright tdstickyghostwhite maxwidth75">';
  4656. print '<input class="reposition button smallpaddingimp" type="submit" name="edit" value="'.$langs->trans("Modify").'">';
  4657. print '<input class="reposition button button-cancel smallpaddingimp" type="submit" name="cancel" value="'.$langs->trans("Cancel").'">';
  4658. print '</td>';
  4659. print '</form>';
  4660. print '</tr>';
  4661. } else {
  4662. print '<tr class="oddeven">';
  4663. print '<td class="tdsticky tdstickygray">';
  4664. print $i;
  4665. print '</td>';
  4666. print '<td class="center">';
  4667. print dol_escape_htmltag($menu['type']);
  4668. print '</td>';
  4669. // Title
  4670. print '<td>';
  4671. print dol_escape_htmltag($menu['titre']);
  4672. print '</td>';
  4673. // Parent menu
  4674. print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($menu['fk_menu']).'">';
  4675. print dol_escape_htmltag($menu['fk_menu']);
  4676. print '</td>';
  4677. print '<td>';
  4678. print dol_escape_htmltag($menu['mainmenu']);
  4679. print '</td>';
  4680. print '<td>';
  4681. print dol_escape_htmltag($menu['leftmenu']);
  4682. print '</td>';
  4683. print '<td class="tdoverflowmax250" title="'.dol_escape_htmltag($menu['url']).'">';
  4684. print dol_escape_htmltag($menu['url']);
  4685. print '</td>';
  4686. print '<td>';
  4687. print dol_escape_htmltag($menu['langs']);
  4688. print '</td>';
  4689. // Position
  4690. print '<td class="center">';
  4691. print dol_escape_htmltag($menu['position']);
  4692. print '</td>';
  4693. // Enabled
  4694. print '<td class="tdoverflowmax200" title="'.dol_escape_htmltag($menu['enabled']).'">';
  4695. print dol_escape_htmltag($menu['enabled']);
  4696. print '</td>';
  4697. // Perms
  4698. print '<td class="tdoverflowmax200" title="'.dol_escape_htmltag($menu['perms']).'">';
  4699. print dol_escape_htmltag($langs->trans($menu['perms']));
  4700. print '</td>';
  4701. // Target
  4702. print '<td class="center tdoverflowmax200" title="'.dol_escape_htmltag($menu['target']).'">';
  4703. print dol_escape_htmltag($menu['target']);
  4704. print '</td>';
  4705. print '<td class="center">';
  4706. if ($menu['user'] == 2) {
  4707. print $langs->trans("AllMenus");
  4708. } elseif ($menu['user'] == 0) {
  4709. print $langs->trans('Internal');
  4710. } elseif ($menu['user'] == 1) {
  4711. print $langs->trans('External');
  4712. } else {
  4713. print $menu['user']; // should not happen
  4714. }
  4715. print '</td>';
  4716. print '<td class="center minwidth75 tdstickyright tdstickyghostwhite">';
  4717. if ($menu['titre'] != 'Module'.$module.'Name') {
  4718. 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>';
  4719. 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>';
  4720. }
  4721. print '</td>';
  4722. }
  4723. print '</tr>';
  4724. }
  4725. } else {
  4726. print '<tr><td colspan="14"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
  4727. }
  4728. print '</table>';
  4729. print '</div>';
  4730. print '</form>';
  4731. print '<script>
  4732. $(document).ready(function() {
  4733. //for fill in auto url
  4734. $("#leftmenu").on("input", function() {
  4735. var inputLeftMenu = $("#leftmenu").val();
  4736. if (inputLeftMenu !== \'\') {
  4737. var url = \''.dol_escape_js(strtolower($module)).'\' + inputLeftMenu + \'.php\';
  4738. $("#url").val(url);
  4739. }else {
  4740. $("#url").val("");
  4741. }
  4742. });
  4743. var groupedRights = ' . $groupedRights_json . ';
  4744. var objectsSelect = $("select[id=\'objects\']");
  4745. var permsSelect = $("select[id=\'perms\']");
  4746. objectsSelect.change(function() {
  4747. var selectedObject = $(this).val();
  4748. permsSelect.empty();
  4749. var rights = groupedRights[selectedObject];
  4750. if (rights) {
  4751. for (var i = 0; i < rights.length; i++) {
  4752. var right = rights[i];
  4753. var option = $("<option></option>").attr("value", right[5]).text(right[5]);
  4754. permsSelect.append(option);
  4755. }
  4756. } else {
  4757. var option = $("<option></option>").attr("value", "read").text("read");
  4758. permsSelect.append(option);
  4759. }
  4760. if (selectedObject !== "" && selectedObject !== null && rights) {
  4761. permsSelect.show();
  4762. } else {
  4763. permsSelect.hide();
  4764. }
  4765. if (objectsSelect.val() === "" || objectsSelect.val() === null) {
  4766. permsSelect.hide();
  4767. }
  4768. });
  4769. });
  4770. </script>';
  4771. // display permissions for each object
  4772. } else {
  4773. $fullpathoffile = dol_buildpath($file, 0);
  4774. $content = file_get_contents($fullpathoffile);
  4775. // New module
  4776. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  4777. print '<input type="hidden" name="token" value="'.newToken().'">';
  4778. print '<input type="hidden" name="action" value="savefile">';
  4779. print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
  4780. print '<input type="hidden" name="tab" value="'.$tab.'">';
  4781. print '<input type="hidden" name="module" value="'.$module.'">';
  4782. $doleditor = new DolEditor('editfilecontent', $content, '', '300', 'Full', 'In', true, false, 'ace', 0, '99%');
  4783. print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ? GETPOST('format', 'aZ09') : 'html'));
  4784. print '<br>';
  4785. print '<center>';
  4786. print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
  4787. print ' &nbsp; ';
  4788. print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
  4789. print '</center>';
  4790. print '</form>';
  4791. }
  4792. }
  4793. if ($tab == 'permissions') {
  4794. print '<!-- tab=permissions -->'."\n";
  4795. $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
  4796. $perms = $moduleobj->rights;
  4797. // Get list of existing objects
  4798. $dir = $dirread.'/'.$modulelowercase.'/class';
  4799. $listofobject = dol_dir_list($dir, 'files', 0, '\.class\.php$');
  4800. $objects = array('myobject');
  4801. $reg =array();
  4802. foreach ($listofobject as $fileobj) {
  4803. $tmpcontent = file_get_contents($fileobj['fullname']);
  4804. if (preg_match('/class\s+([^\s]*)\s+extends\s+CommonObject/ims', $tmpcontent, $reg)) {
  4805. $objects[$fileobj['fullname']] = $reg[1];
  4806. }
  4807. }
  4808. // declared select list for actions and labels permissions
  4809. $crud = array('read'=>'CRUDRead', 'write'=>'CRUDCreateWrite', 'delete'=>'Delete');
  4810. $labels = array("Read objects of ".$module, "Create/Update objects of ".$module, "Delete objects of ".$module);
  4811. $action = GETPOST('action', 'alpha');
  4812. if ($action == 'deleteright') {
  4813. $formconfirm = $form->formconfirm(
  4814. $_SERVER["PHP_SELF"].'?permskey='.urlencode(GETPOST('permskey', 'int')).'&tab='.urlencode($tab).'&module='.urlencode($module).'&tabobj='.urlencode($tabobj),
  4815. $langs->trans('Delete'),
  4816. $langs->trans('Confirm Delete Right', GETPOST('permskey', 'alpha')),
  4817. 'confirm_deleteright',
  4818. '',
  4819. 0,
  4820. 1
  4821. );
  4822. print $formconfirm;
  4823. }
  4824. if ($action != 'editfile' || empty($file)) {
  4825. print '<!-- Tab to manage permissions -->'."\n";
  4826. print '<span class="opacitymedium">';
  4827. $htmlhelp = $langs->trans("PermissionsDefDescTooltip", '{s1}');
  4828. $htmlhelp = str_replace('{s1}', '<a target="adminbis" class="nofocusvisible" href="'.DOL_URL_ROOT.'/admin/perms.php">'.$langs->trans('DefaultRights').'</a>', $htmlhelp);
  4829. print $form->textwithpicto($langs->trans("PermissionsDefDesc"), $htmlhelp, 1, 'help', '', 0, 2, 'helpondesc').'<br>';
  4830. print '</span>';
  4831. print '<br>';
  4832. print '<span class="fa fa-file-o"></span> '.$langs->trans("DescriptorFile").' : <strong class="wordbreak">'.$pathtofile.'</strong>';
  4833. 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>';
  4834. print '<br>';
  4835. print '<br>';
  4836. print load_fiche_titre($langs->trans("ListOfPermissionsDefined"), '', '');
  4837. print '<!-- form to add permissions -->'."\n";
  4838. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  4839. print '<input type="hidden" name="token" value="'.newToken().'">';
  4840. print '<input type="hidden" name="action" value="addright">';
  4841. print '<input type="hidden" name="tab" value="permissions">';
  4842. print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
  4843. print '<input type="hidden" name="tabobj" value="'.dol_escape_htmltag($tabobj).'">';
  4844. print '<div class="div-table-responsive">';
  4845. print '<table class="noborder">';
  4846. print '<tr class="liste_titre">';
  4847. print_liste_field_titre("ID", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder, "center");
  4848. print_liste_field_titre("Object", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder, "center");
  4849. print_liste_field_titre("CRUD", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder, "center");
  4850. print_liste_field_titre("Label", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder, "center");
  4851. print_liste_field_titre("", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder, "center");
  4852. print "</tr>\n";
  4853. //form for add new right
  4854. print '<tr class="small">';
  4855. print '<td><input type="hidden" readonly name="id" class="width75" value="0"></td>';
  4856. print '<td><select class="minwidth100" name="permissionObj" id="permissionObj">';
  4857. print '<option value=""></option>';
  4858. foreach ($objects as $obj) {
  4859. if ($obj != 'myobject') {
  4860. print '<option value="'.$obj.'">'.$obj.'</option>';
  4861. }
  4862. }
  4863. print '</select></td>';
  4864. print '<td><select class="maxwidth75" name="crud" id="crud">';
  4865. print '<option value=""></option>';
  4866. foreach ($crud as $key => $val) {
  4867. print '<option value="'.$key.'">'.$langs->trans($val).'</option>';
  4868. }
  4869. print '</td>';
  4870. print '<td >';
  4871. print '<input type="text" name="label" id="label" class="minwidth200">';
  4872. print '</td>';
  4873. print '<td class="center minwidth75 tdstickyright tdstickyghostwhite">';
  4874. print '<input type="submit" class="button" name="add" value="'.$langs->trans("Add").'">';
  4875. print '</td>';
  4876. print '</tr>';
  4877. if (count($perms)) {
  4878. $i = 0;
  4879. foreach ($perms as $perm) {
  4880. $i++;
  4881. // section for editing right
  4882. if ($action == 'edit_right' && $perm[0] == (int) GETPOST('permskey', 'int')) {
  4883. print '<tr class="oddeven">';
  4884. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST" name="modifPerms">';
  4885. print '<input type="hidden" name="token" value="'.newToken().'">';
  4886. print '<input type="hidden" name="tab" value="permissions">';
  4887. print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
  4888. print '<input type="hidden" name="tabobj" value="'.dol_escape_htmltag($tabobj).'">';
  4889. print '<input type="hidden" name="action" value="update_right">';
  4890. print '<input type="hidden" name="counter" value="'.$i.'">';
  4891. print '<input type="hidden" name="permskey" value="'.$perm[0].'">';
  4892. print '<td class="tdsticky tdstickygray">';
  4893. print '<input class="width75" type="text" readonly value="'.dol_escape_htmltag($perm[0]).'"/>';
  4894. print '</td>';
  4895. print '<td>';
  4896. print '<select name="crud">';
  4897. print '<option value="'.dol_escape_htmltag($perm[5]).'">'.$langs->trans($perm[5]).'</option>';
  4898. foreach ($crud as $i=> $x) {
  4899. if ($perm[5] != $i) {
  4900. print '<option value="'.$i.'">'.$langs->trans(ucfirst($x)).'</option>';
  4901. }
  4902. }
  4903. print '</select>';
  4904. print '</td>';
  4905. print '<td><select name="permissionObj" >';
  4906. print '<option value="'.dol_escape_htmltag($perm[4]).'">'.ucfirst($perm[4]).'</option>';
  4907. print '</select></td>';
  4908. print '<td>';
  4909. print '<input type="text" name="label" value="'.dol_escape_htmltag($perm[1]).'">';
  4910. print '</td>';
  4911. print '<td class="center minwidth75 tdstickyright tdstickyghostwhite">';
  4912. print '<input id ="modifyPerm" class="reposition button smallpaddingimp" type="submit" name="modifyright" value="'.$langs->trans("Modify").'"/>';
  4913. print '<br>';
  4914. print '<input class="reposition button button-cancel smallpaddingimp" type="submit" name="cancel" value="'.$langs->trans("Cancel").'"/>';
  4915. print '</td>';
  4916. print '</form>';
  4917. print '</tr>';
  4918. } else {
  4919. // $perm can be module->object->crud or module->crud
  4920. print '<tr class="oddeven">';
  4921. print '<td>';
  4922. print dol_escape_htmltag($perm[0]);
  4923. print '</td>';
  4924. print '<td>';
  4925. if (in_array($perm[5], array('lire', 'read', 'creer', 'write', 'effacer', 'delete'))) {
  4926. print dol_escape_htmltag(ucfirst($perm[4]));
  4927. } else {
  4928. print ''; // No particular object
  4929. }
  4930. print '</td>';
  4931. print '<td>';
  4932. if (in_array($perm[5], array('lire', 'read', 'creer', 'write', 'effacer', 'delete'))) {
  4933. print ucfirst($langs->trans($perm[5]));
  4934. } else {
  4935. print ucfirst($langs->trans($perm[4]));
  4936. }
  4937. print '</td>';
  4938. print '<td>';
  4939. print $langs->trans($perm[1]);
  4940. print '</td>';
  4941. print '<td class="center minwidth75 tdstickyright tdstickyghostwhite">';
  4942. 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>';
  4943. 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>';
  4944. print '</td>';
  4945. print '</tr>';
  4946. }
  4947. }
  4948. } else {
  4949. print '<tr><td colspan="5"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
  4950. }
  4951. print '</table>';
  4952. print '</div>';
  4953. print '</form>';
  4954. print '<script>
  4955. function updateInputField() {
  4956. value1 = $("#crud").val();
  4957. value2 = $("#permissionObj").val();
  4958. // Vérifie si les deux sélections sont faites
  4959. if (value1 && value2) {
  4960. switch(value1.toLowerCase()){
  4961. case "read":
  4962. $("#label").val("Read "+value2+" object of '.ucfirst($module).'")
  4963. break;
  4964. case "write":
  4965. $("#label").val("Create/Update "+value2+" object of '.ucfirst($module).'")
  4966. break;
  4967. case "delete":
  4968. $("#label").val("Delete "+value2+" object of '.ucfirst($module).'")
  4969. break;
  4970. default:
  4971. $("#label").val("")
  4972. }
  4973. }
  4974. }
  4975. $("#crud, #permissionObj").change(function(){
  4976. console.log("We change selection");
  4977. updateInputField();
  4978. });
  4979. </script>';
  4980. } else {
  4981. $fullpathoffile = dol_buildpath($file, 0);
  4982. $content = file_get_contents($fullpathoffile);
  4983. // New module
  4984. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  4985. print '<input type="hidden" name="token" value="'.newToken().'">';
  4986. print '<input type="hidden" name="action" value="savefile">';
  4987. print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
  4988. print '<input type="hidden" name="tab" value="'.$tab.'">';
  4989. print '<input type="hidden" name="module" value="'.$module.'">';
  4990. $doleditor = new DolEditor('editfilecontent', $content, '', '300', 'Full', 'In', true, false, 'ace', 0, '99%');
  4991. print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ? GETPOST('format', 'aZ09') : 'html'));
  4992. print '<br>';
  4993. print '<center>';
  4994. print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
  4995. print ' &nbsp; ';
  4996. print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
  4997. print '</center>';
  4998. print '</form>';
  4999. }
  5000. }
  5001. if ($tab == 'hooks') {
  5002. print '<!-- tab=hooks -->'."\n";
  5003. if ($action != 'editfile' || empty($file)) {
  5004. print '<span class="opacitymedium">'.$langs->trans("HooksDefDesc").'</span><br>';
  5005. print '<br>';
  5006. print '<table>';
  5007. $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
  5008. print '<tr><td>';
  5009. print '<span class="fa fa-file-o"></span> '.$langs->trans("DescriptorFile").' : <strong class="wordbreak">'.$pathtofile.'</strong>';
  5010. print '</td><td>';
  5011. 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>';
  5012. print '</td></tr>';
  5013. print '<tr><td>';
  5014. $pathtohook = strtolower($module).'/class/actions_'.strtolower($module).'.class.php';
  5015. print '<span class="fa fa-file-o"></span> '.$langs->trans("HooksFile").' : ';
  5016. if (dol_is_file($dirins.'/'.$pathtohook)) {
  5017. print '<strong class="wordbreak">'.$pathtohook.'</strong>';
  5018. print '</td>';
  5019. 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> ';
  5020. 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>';
  5021. } else {
  5022. print '<span class="opacitymedium">'.$langs->trans("FileNotYetGenerated").'</span>';
  5023. 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>';
  5024. print '<td></td>';
  5025. }
  5026. print '</tr>';
  5027. } else {
  5028. $fullpathoffile = dol_buildpath($file, 0);
  5029. $content = file_get_contents($fullpathoffile);
  5030. // New module
  5031. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  5032. print '<input type="hidden" name="token" value="'.newToken().'">';
  5033. print '<input type="hidden" name="action" value="savefile">';
  5034. print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
  5035. print '<input type="hidden" name="tab" value="'.$tab.'">';
  5036. print '<input type="hidden" name="module" value="'.$module.'">';
  5037. $doleditor = new DolEditor('editfilecontent', $content, '', '300', 'Full', 'In', true, false, 'ace', 0, '99%');
  5038. print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ? GETPOST('format', 'aZ09') : 'html'));
  5039. print '<br>';
  5040. print '<center>';
  5041. print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
  5042. print ' &nbsp; ';
  5043. print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
  5044. print '</center>';
  5045. print '</form>';
  5046. }
  5047. }
  5048. if ($tab == 'triggers') {
  5049. print '<!-- tab=triggers -->'."\n";
  5050. require_once DOL_DOCUMENT_ROOT.'/core/class/interfaces.class.php';
  5051. $interfaces = new Interfaces($db);
  5052. $triggers = $interfaces->getTriggersList(array('/'.strtolower($module).'/core/triggers'));
  5053. if ($action != 'editfile' || empty($file)) {
  5054. print '<span class="opacitymedium">'.$langs->trans("TriggerDefDesc").'</span><br>';
  5055. print '<br>';
  5056. print '<table>';
  5057. $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
  5058. print '<tr><td>';
  5059. print '<span class="fa fa-file-o"></span> '.$langs->trans("DescriptorFile").' : <strong class="wordbreak">'.$pathtofile.'</strong>';
  5060. print '</td><td>';
  5061. 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>';
  5062. print '</td></tr>';
  5063. if (!empty($triggers)) {
  5064. foreach ($triggers as $trigger) {
  5065. $pathtofile = $trigger['relpath'];
  5066. print '<tr><td>';
  5067. print '<span class="fa fa-file-o"></span> '.$langs->trans("TriggersFile").' : <strong class="wordbreak">'.$pathtofile.'</strong>';
  5068. 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>';
  5069. 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>';
  5070. print '</tr>';
  5071. }
  5072. } else {
  5073. print '<tr><td>';
  5074. print '<span class="fa fa-file-o"></span> '.$langs->trans("TriggersFile");
  5075. print ' : <span class="opacitymedium">'.$langs->trans("FileNotYetGenerated").'</span>';
  5076. 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>';
  5077. print '<td></td>';
  5078. print '</tr>';
  5079. }
  5080. print '</table>';
  5081. } else {
  5082. $fullpathoffile = dol_buildpath($file, 0);
  5083. $content = file_get_contents($fullpathoffile);
  5084. // New module
  5085. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  5086. print '<input type="hidden" name="token" value="'.newToken().'">';
  5087. print '<input type="hidden" name="action" value="savefile">';
  5088. print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
  5089. print '<input type="hidden" name="tab" value="'.$tab.'">';
  5090. print '<input type="hidden" name="module" value="'.$module.'">';
  5091. $doleditor = new DolEditor('editfilecontent', $content, '', '300', 'Full', 'In', true, false, 'ace', 0, '99%');
  5092. print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ? GETPOST('format', 'aZ09') : 'html'));
  5093. print '<br>';
  5094. print '<center>';
  5095. print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
  5096. print ' &nbsp; ';
  5097. print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
  5098. print '</center>';
  5099. print '</form>';
  5100. }
  5101. }
  5102. if ($tab == 'css') {
  5103. print '<!-- tab=css -->'."\n";
  5104. if ($action != 'editfile' || empty($file)) {
  5105. print '<span class="opacitymedium">'.$langs->trans("CSSDesc").'</span><br>';
  5106. print '<br>';
  5107. print '<table>';
  5108. print '<tr><td>';
  5109. $pathtohook = strtolower($module).'/css/'.strtolower($module).'.css.php';
  5110. print '<span class="fa fa-file-o"></span> '.$langs->trans("CSSFile").' : ';
  5111. if (dol_is_file($dirins.'/'.$pathtohook)) {
  5112. print '<strong class="wordbreak">'.$pathtohook.'</strong>';
  5113. 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>';
  5114. 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>';
  5115. } else {
  5116. print '<span class="opacitymedium">'.$langs->trans("FileNotYetGenerated").'</span>';
  5117. 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>';
  5118. }
  5119. print '</tr>';
  5120. } else {
  5121. $fullpathoffile = dol_buildpath($file, 0);
  5122. $content = file_get_contents($fullpathoffile);
  5123. // New module
  5124. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  5125. print '<input type="hidden" name="token" value="'.newToken().'">';
  5126. print '<input type="hidden" name="action" value="savefile">';
  5127. print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
  5128. print '<input type="hidden" name="tab" value="'.$tab.'">';
  5129. print '<input type="hidden" name="module" value="'.$module.'">';
  5130. $doleditor = new DolEditor('editfilecontent', $content, '', '300', 'Full', 'In', true, false, 'ace', 0, '99%');
  5131. print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ? GETPOST('format', 'aZ09') : 'html'));
  5132. print '<br>';
  5133. print '<center>';
  5134. print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
  5135. print ' &nbsp; ';
  5136. print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
  5137. print '</center>';
  5138. print '</form>';
  5139. }
  5140. }
  5141. if ($tab == 'js') {
  5142. print '<!-- tab=js -->'."\n";
  5143. if ($action != 'editfile' || empty($file)) {
  5144. print '<span class="opacitymedium">'.$langs->trans("JSDesc").'</span><br>';
  5145. print '<br>';
  5146. print '<table>';
  5147. print '<tr><td>';
  5148. $pathtohook = strtolower($module).'/js/'.strtolower($module).'.js.php';
  5149. print '<span class="fa fa-file-o"></span> '.$langs->trans("JSFile").' : ';
  5150. if (dol_is_file($dirins.'/'.$pathtohook)) {
  5151. print '<strong class="wordbreak">'.$pathtohook.'</strong>';
  5152. 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>';
  5153. 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>';
  5154. } else {
  5155. print '<span class="opacitymedium">'.$langs->trans("FileNotYetGenerated").'</span>';
  5156. 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>';
  5157. }
  5158. print '</tr>';
  5159. } else {
  5160. $fullpathoffile = dol_buildpath($file, 0);
  5161. $content = file_get_contents($fullpathoffile);
  5162. // New module
  5163. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  5164. print '<input type="hidden" name="token" value="'.newToken().'">';
  5165. print '<input type="hidden" name="action" value="savefile">';
  5166. print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
  5167. print '<input type="hidden" name="tab" value="'.$tab.'">';
  5168. print '<input type="hidden" name="module" value="'.$module.'">';
  5169. $doleditor = new DolEditor('editfilecontent', $content, '', '300', 'Full', 'In', true, false, 'ace', 0, '99%');
  5170. print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ? GETPOST('format', 'aZ09') : 'html'));
  5171. print '<br>';
  5172. print '<center>';
  5173. print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
  5174. print ' &nbsp; ';
  5175. print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
  5176. print '</center>';
  5177. print '</form>';
  5178. }
  5179. }
  5180. if ($tab == 'widgets') {
  5181. print '<!-- tab=widgets -->'."\n";
  5182. require_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
  5183. $widgets = ModeleBoxes::getWidgetsList(array('/'.strtolower($module).'/core/boxes'));
  5184. if ($action != 'editfile' || empty($file)) {
  5185. print '<span class="opacitymedium">'.$langs->trans("WidgetDesc").'</span><br>';
  5186. print '<br>';
  5187. print '<table>';
  5188. if (!empty($widgets)) {
  5189. foreach ($widgets as $widget) {
  5190. $pathtofile = $widget['relpath'];
  5191. print '<tr><td><span class="fa fa-file-o"></span> '.$langs->trans("WidgetFile").' : <strong class="wordbreak">'.$pathtofile.'</strong>';
  5192. 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>';
  5193. 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>';
  5194. print '</tr>';
  5195. }
  5196. } else {
  5197. print '<tr><td><span class="fa fa-file-o"></span> '.$langs->trans("WidgetFile").' : <span class="opacitymedium">'.$langs->trans("NoWidget").'</span>';
  5198. 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>';
  5199. print '</td></tr>';
  5200. }
  5201. print '</table>';
  5202. } else {
  5203. $fullpathoffile = dol_buildpath($file, 0);
  5204. $content = file_get_contents($fullpathoffile);
  5205. // New module
  5206. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  5207. print '<input type="hidden" name="token" value="'.newToken().'">';
  5208. print '<input type="hidden" name="action" value="savefile">';
  5209. print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
  5210. print '<input type="hidden" name="tab" value="'.$tab.'">';
  5211. print '<input type="hidden" name="module" value="'.$module.'">';
  5212. $doleditor = new DolEditor('editfilecontent', $content, '', '300', 'Full', 'In', true, false, 'ace', 0, '99%');
  5213. print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ? GETPOST('format', 'aZ09') : 'html'));
  5214. print '<br>';
  5215. print '<center>';
  5216. print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
  5217. print ' &nbsp; ';
  5218. print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
  5219. print '</center>';
  5220. print '</form>';
  5221. }
  5222. }
  5223. if ($tab == 'exportimport') {
  5224. print '<!-- tab=exportimport -->'."\n";
  5225. $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
  5226. $exportlist = $moduleobj->export_label;
  5227. $importlist = $moduleobj->import_label;
  5228. if ($action != 'editfile' || empty($file)) {
  5229. print '<span class="opacitymedium">'.$langs->transnoentities('ImportExportProfiles').'</span><br>';
  5230. print '<br>';
  5231. print '<span class="fa fa-file-o"></span> '.$langs->trans("DescriptorFile").' : <strong class="wordbreak">'.$pathtofile.'</strong>';
  5232. 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>';
  5233. print '<br>';
  5234. } else {
  5235. $fullpathoffile = dol_buildpath($file, 0);
  5236. $content = file_get_contents($fullpathoffile);
  5237. // New module
  5238. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  5239. print '<input type="hidden" name="token" value="'.newToken().'">';
  5240. print '<input type="hidden" name="action" value="savefile">';
  5241. print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
  5242. print '<input type="hidden" name="tab" value="'.$tab.'">';
  5243. print '<input type="hidden" name="module" value="'.$module.'">';
  5244. $doleditor = new DolEditor('editfilecontent', $content, '', '300', 'Full', 'In', true, false, 'ace', 0, '99%');
  5245. print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ? GETPOST('format', 'aZ09') : 'html'));
  5246. print '<br>';
  5247. print '<center>';
  5248. print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
  5249. print ' &nbsp; ';
  5250. print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
  5251. print '</center>';
  5252. print '</form>';
  5253. }
  5254. }
  5255. if ($tab == 'cli') {
  5256. print '<!-- tab=cli -->'."\n";
  5257. $clifiles = array();
  5258. $i = 0;
  5259. $dircli = array('/'.strtolower($module).'/scripts');
  5260. foreach ($dircli as $reldir) {
  5261. $dir = dol_buildpath($reldir, 0);
  5262. $newdir = dol_osencode($dir);
  5263. // Check if directory exists (we do not use dol_is_dir to avoid loading files.lib.php at each call)
  5264. if (!is_dir($newdir)) {
  5265. continue;
  5266. }
  5267. $handle = opendir($newdir);
  5268. if (is_resource($handle)) {
  5269. while (($tmpfile = readdir($handle)) !== false) {
  5270. if (is_readable($newdir.'/'.$tmpfile) && preg_match('/^(.+)\.php/', $tmpfile, $reg)) {
  5271. if (preg_match('/\.back$/', $tmpfile)) {
  5272. continue;
  5273. }
  5274. $clifiles[$i]['relpath'] = preg_replace('/^\//', '', $reldir).'/'.$tmpfile;
  5275. $i++;
  5276. }
  5277. }
  5278. closedir($handle);
  5279. }
  5280. }
  5281. if ($action != 'editfile' || empty($file)) {
  5282. print '<span class="opacitymedium">'.$langs->trans("CLIDesc").'</span><br>';
  5283. print '<br>';
  5284. print '<table>';
  5285. if (!empty($clifiles)) {
  5286. foreach ($clifiles as $clifile) {
  5287. $pathtofile = $clifile['relpath'];
  5288. print '<tr><td><span class="fa fa-file-o"></span> '.$langs->trans("CLIFile").' : <strong class="wordbreak">'.$pathtofile.'</strong>';
  5289. 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>';
  5290. 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>';
  5291. print '</tr>';
  5292. }
  5293. } else {
  5294. print '<tr><td><span class="fa fa-file-o"></span> '.$langs->trans("CLIFile").' : <span class="opacitymedium">'.$langs->trans("FileNotYetGenerated").'</span>';
  5295. 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>';
  5296. print '</td></tr>';
  5297. }
  5298. print '</table>';
  5299. } else {
  5300. $fullpathoffile = dol_buildpath($file, 0);
  5301. $content = file_get_contents($fullpathoffile);
  5302. // New module
  5303. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  5304. print '<input type="hidden" name="token" value="'.newToken().'">';
  5305. print '<input type="hidden" name="action" value="savefile">';
  5306. print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
  5307. print '<input type="hidden" name="tab" value="'.$tab.'">';
  5308. print '<input type="hidden" name="module" value="'.$module.'">';
  5309. $doleditor = new DolEditor('editfilecontent', $content, '', '300', 'Full', 'In', true, false, 'ace', 0, '99%');
  5310. print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ? GETPOST('format', 'aZ09') : 'html'));
  5311. print '<br>';
  5312. print '<center>';
  5313. print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
  5314. print ' &nbsp; ';
  5315. print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
  5316. print '</center>';
  5317. print '</form>';
  5318. }
  5319. }
  5320. if ($tab == 'cron') {
  5321. print '<!-- tab=cron -->'."\n";
  5322. $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
  5323. $cronjobs = $moduleobj->cronjobs;
  5324. if ($action != 'editfile' || empty($file)) {
  5325. 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>';
  5326. print '<br>';
  5327. print '<span class="fa fa-file-o"></span> '.$langs->trans("DescriptorFile").' : <strong class="wordbreak">'.$pathtofile.'</strong>';
  5328. 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>';
  5329. print '<br>';
  5330. print '<br>';
  5331. print load_fiche_titre($langs->trans("CronJobProfiles"), '', '');
  5332. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  5333. print '<input type="hidden" name="token" value="'.newToken().'">';
  5334. print '<input type="hidden" name="action" value="addproperty">';
  5335. print '<input type="hidden" name="tab" value="objects">';
  5336. print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
  5337. print '<input type="hidden" name="tabobj" value="'.dol_escape_htmltag($tabobj).'">';
  5338. print '<div class="div-table-responsive">';
  5339. print '<table class="noborder">';
  5340. print '<tr class="liste_titre">';
  5341. print_liste_field_titre("CronLabel", $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder);
  5342. print_liste_field_titre("CronTask", '', '', "", $param, '', $sortfield, $sortorder);
  5343. print_liste_field_titre("CronFrequency", '', "", "", $param, '', $sortfield, $sortorder);
  5344. print_liste_field_titre("StatusAtInstall", $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder);
  5345. print_liste_field_titre("Comment", $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder);
  5346. print "</tr>\n";
  5347. if (count($cronjobs)) {
  5348. foreach ($cronjobs as $cron) {
  5349. print '<tr class="oddeven">';
  5350. print '<td>';
  5351. print $cron['label'];
  5352. print '</td>';
  5353. print '<td>';
  5354. if ($cron['jobtype'] == 'method') {
  5355. $text = $langs->trans("CronClass");
  5356. $texttoshow = $langs->trans('CronModule').': '.$module.'<br>';
  5357. $texttoshow .= $langs->trans('CronClass').': '.$cron['class'].'<br>';
  5358. $texttoshow .= $langs->trans('CronObject').': '.$cron['objectname'].'<br>';
  5359. $texttoshow .= $langs->trans('CronMethod').': '.$cron['method'];
  5360. $texttoshow .= '<br>'.$langs->trans('CronArgs').': '.$cron['parameters'];
  5361. $texttoshow .= '<br>'.$langs->trans('Comment').': '.$langs->trans($cron['comment']);
  5362. } elseif ($cron['jobtype'] == 'command') {
  5363. $text = $langs->trans('CronCommand');
  5364. $texttoshow = $langs->trans('CronCommand').': '.dol_trunc($cron['command']);
  5365. $texttoshow .= '<br>'.$langs->trans('CronArgs').': '.$cron['parameters'];
  5366. $texttoshow .= '<br>'.$langs->trans('Comment').': '.$langs->trans($cron['comment']);
  5367. }
  5368. print $form->textwithpicto($text, $texttoshow, 1);
  5369. print '</td>';
  5370. print '<td>';
  5371. if ($cron['unitfrequency'] == "60") {
  5372. print $langs->trans('CronEach')." ".($cron['frequency'])." ".$langs->trans('Minutes');
  5373. }
  5374. if ($cron['unitfrequency'] == "3600") {
  5375. print $langs->trans('CronEach')." ".($cron['frequency'])." ".$langs->trans('Hours');
  5376. }
  5377. if ($cron['unitfrequency'] == "86400") {
  5378. print $langs->trans('CronEach')." ".($cron['frequency'])." ".$langs->trans('Days');
  5379. }
  5380. if ($cron['unitfrequency'] == "604800") {
  5381. print $langs->trans('CronEach')." ".($cron['frequency'])." ".$langs->trans('Weeks');
  5382. }
  5383. print '</td>';
  5384. print '<td>';
  5385. print $cron['status'];
  5386. print '</td>';
  5387. print '<td>';
  5388. if (!empty($cron['comment'])) {
  5389. print $cron['comment'];
  5390. }
  5391. print '</td>';
  5392. print '</tr>';
  5393. }
  5394. } else {
  5395. print '<tr><td colspan="5"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
  5396. }
  5397. print '</table>';
  5398. print '</div>';
  5399. print '</form>';
  5400. } else {
  5401. $fullpathoffile = dol_buildpath($file, 0);
  5402. $content = file_get_contents($fullpathoffile);
  5403. // New module
  5404. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  5405. print '<input type="hidden" name="token" value="'.newToken().'">';
  5406. print '<input type="hidden" name="action" value="savefile">';
  5407. print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
  5408. print '<input type="hidden" name="tab" value="'.$tab.'">';
  5409. print '<input type="hidden" name="module" value="'.$module.'">';
  5410. $doleditor = new DolEditor('editfilecontent', $content, '', '300', 'Full', 'In', true, false, 'ace', 0, '99%');
  5411. print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ? GETPOST('format', 'aZ09') : 'html'));
  5412. print '<br>';
  5413. print '<center>';
  5414. print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
  5415. print ' &nbsp; ';
  5416. print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
  5417. print '</center>';
  5418. print '</form>';
  5419. }
  5420. }
  5421. if ($tab == 'specifications') {
  5422. print '<!-- tab=specifications -->'."\n";
  5423. $specs = dol_dir_list(dol_buildpath($modulelowercase.'/doc', 0), 'files', 1, '(\.md|\.asciidoc)$', array('\/temp\/'));
  5424. if ($action != 'editfile' || empty($file)) {
  5425. print '<span class="opacitymedium">'.$langs->trans("SpecDefDesc").'</span><br>';
  5426. print '<br>';
  5427. print '<table>';
  5428. if (is_array($specs) && !empty($specs)) {
  5429. foreach ($specs as $spec) {
  5430. $pathtofile = $modulelowercase.'/doc/'.$spec['relativename'];
  5431. $format = 'asciidoc';
  5432. if (preg_match('/\.md$/i', $spec['name'])) {
  5433. $format = 'markdown';
  5434. }
  5435. print '<tr><td>';
  5436. print '<span class="fa fa-file-o"></span> '.$langs->trans("SpecificationFile").' : <strong class="wordbreak">'.$pathtofile.'</strong>';
  5437. 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>';
  5438. 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>';
  5439. print '</tr>';
  5440. }
  5441. } else {
  5442. print '<tr><td>';
  5443. print '<span class="fa fa-file-o"></span> '.$langs->trans("SpecificationFile").' : <span class="opacitymedium">'.$langs->trans("FileNotYetGenerated").'</span>';
  5444. 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>';
  5445. print '</tr>';
  5446. }
  5447. print '</table>';
  5448. } else {
  5449. // Use MD or asciidoc
  5450. //print $langs->trans("UseAsciiDocFormat").'<br>';
  5451. $fullpathoffile = dol_buildpath($file, 0);
  5452. $content = file_get_contents($fullpathoffile);
  5453. // New module
  5454. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  5455. print '<input type="hidden" name="token" value="'.newToken().'">';
  5456. print '<input type="hidden" name="action" value="savefile">';
  5457. print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
  5458. print '<input type="hidden" name="tab" value="'.$tab.'">';
  5459. print '<input type="hidden" name="module" value="'.$module.'">';
  5460. $doleditor = new DolEditor('editfilecontent', $content, '', '300', 'Full', 'In', true, false, 'ace', 0, '99%');
  5461. print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ? GETPOST('format', 'aZ09') : 'html'));
  5462. print '<br>';
  5463. print '<center>';
  5464. print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
  5465. print ' &nbsp; ';
  5466. print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
  5467. print '</center>';
  5468. print '</form>';
  5469. }
  5470. print '<br><br><br>';
  5471. $FILENAMEDOC = $modulelowercase.'.html';
  5472. $FILENAMEDOCPDF = $modulelowercase.'.pdf';
  5473. $outputfiledoc = dol_buildpath($modulelowercase, 0).'/doc/'.$FILENAMEDOC;
  5474. $outputfiledocurl = dol_buildpath($modulelowercase, 1).'/doc/'.$FILENAMEDOC;
  5475. $outputfiledocrel = $modulelowercase.'/doc/'.$FILENAMEDOC;
  5476. $outputfiledocpdf = dol_buildpath($modulelowercase, 0).'/doc/'.$FILENAMEDOCPDF;
  5477. $outputfiledocurlpdf = dol_buildpath($modulelowercase, 1).'/doc/'.$FILENAMEDOCPDF;
  5478. $outputfiledocrelpdf = $modulelowercase.'/doc/'.$FILENAMEDOCPDF;
  5479. // HTML
  5480. print '<span class="fa fa-file-o"></span> '.$langs->trans("PathToModuleDocumentation", "HTML").' : ';
  5481. if (!dol_is_file($outputfiledoc)) {
  5482. print '<span class="opacitymedium">'.$langs->trans("FileNotYetGenerated").'</span>';
  5483. } else {
  5484. print '<strong>';
  5485. print '<a href="'.$outputfiledocurl.'" target="_blank" rel="noopener noreferrer">';
  5486. print $outputfiledoc;
  5487. print '</a>';
  5488. print '</strong>';
  5489. print ' <span class="opacitymedium">('.$langs->trans("GeneratedOn").' '.dol_print_date(dol_filemtime($outputfiledoc), 'dayhour').')</span>';
  5490. 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>';
  5491. }
  5492. print '</strong><br>';
  5493. // PDF
  5494. print '<span class="fa fa-file-o"></span> '.$langs->trans("PathToModuleDocumentation", "PDF").' : ';
  5495. if (!dol_is_file($outputfiledocpdf)) {
  5496. print '<span class="opacitymedium">'.$langs->trans("FileNotYetGenerated").'</span>';
  5497. } else {
  5498. print '<strong>';
  5499. print '<a href="'.$outputfiledocurlpdf.'" target="_blank" rel="noopener noreferrer">';
  5500. print $outputfiledocpdf;
  5501. print '</a>';
  5502. print '</strong>';
  5503. print ' <span class="opacitymedium">('.$langs->trans("GeneratedOn").' '.dol_print_date(dol_filemtime($outputfiledocpdf), 'dayhour').')</span>';
  5504. 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>';
  5505. }
  5506. print '</strong><br>';
  5507. print '<br>';
  5508. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST" name="generatedoc">';
  5509. print '<input type="hidden" name="token" value="'.newToken().'">';
  5510. print '<input type="hidden" name="action" value="generatedoc">';
  5511. print '<input type="hidden" name="tab" value="'.dol_escape_htmltag($tab).'">';
  5512. print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
  5513. print '<input type="submit" class="button" name="generatedoc" value="'.$langs->trans("BuildDocumentation").'"';
  5514. if (!is_array($specs) || empty($specs)) {
  5515. print ' disabled="disabled"';
  5516. }
  5517. print '>';
  5518. print '</form>';
  5519. }
  5520. if ($tab == 'buildpackage') {
  5521. print '<!-- tab=buildpackage -->'."\n";
  5522. print '<span class="opacitymedium">'.$langs->trans("BuildPackageDesc").'</span>';
  5523. print '<br>';
  5524. if (!class_exists('ZipArchive') && !defined('ODTPHP_PATHTOPCLZIP')) {
  5525. print img_warning().' '.$langs->trans("ErrNoZipEngine");
  5526. print '<br>';
  5527. }
  5528. $modulelowercase = strtolower($module);
  5529. // Zip file to build
  5530. $FILENAMEZIP = '';
  5531. // Load module
  5532. $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
  5533. dol_include_once($pathtofile);
  5534. $class = 'mod'.$module;
  5535. if (class_exists($class)) {
  5536. try {
  5537. $moduleobj = new $class($db);
  5538. } catch (Exception $e) {
  5539. $error++;
  5540. dol_print_error($db, $e->getMessage());
  5541. }
  5542. } else {
  5543. $error++;
  5544. $langs->load("errors");
  5545. dol_print_error($db, $langs->trans("ErrorFailedToLoadModuleDescriptorForXXX", $module));
  5546. exit;
  5547. }
  5548. $arrayversion = explode('.', $moduleobj->version, 3);
  5549. if (count($arrayversion)) {
  5550. $FILENAMEZIP = "module_".$modulelowercase.'-'.$arrayversion[0].(empty($arrayversion[1]) ? '.0' : '.'.$arrayversion[1]).(empty($arrayversion[2]) ? '' : ".".$arrayversion[2]).".zip";
  5551. $outputfilezip = dol_buildpath($modulelowercase, 0).'/bin/'.$FILENAMEZIP;
  5552. }
  5553. print '<br>';
  5554. print '<span class="fa fa-file-o"></span> '.$langs->trans("PathToModulePackage").' : ';
  5555. if (!dol_is_file($outputfilezip)) {
  5556. print '<span class="opacitymedium">'.$langs->trans("FileNotYetGenerated").'</span>';
  5557. } else {
  5558. $relativepath = $modulelowercase.'/bin/'.$FILENAMEZIP;
  5559. print '<strong><a href="'.DOL_URL_ROOT.'/document.php?modulepart=packages&file='.urlencode($relativepath).'">'.$outputfilezip.'</a></strong>';
  5560. print ' <span class="opacitymedium">('.$langs->trans("GeneratedOn").' '.dol_print_date(dol_filemtime($outputfilezip), 'dayhour').')</span>';
  5561. 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>';
  5562. }
  5563. print '</strong>';
  5564. print '<br>';
  5565. print '<br>';
  5566. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST" name="generatepackage">';
  5567. print '<input type="hidden" name="token" value="'.newToken().'">';
  5568. print '<input type="hidden" name="action" value="generatepackage">';
  5569. print '<input type="hidden" name="tab" value="'.dol_escape_htmltag($tab).'">';
  5570. print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
  5571. print '<input type="submit" class="button" name="generatepackage" value="'.$langs->trans("BuildPackage").'">';
  5572. print '</form>';
  5573. }
  5574. if ($tab == 'tabs') {
  5575. $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath'];
  5576. $tabs = $moduleobj->tabs;
  5577. if ($action != 'editfile' || empty($file)) {
  5578. print '<span class="opacitymedium">';
  5579. $htmlhelp = $langs->trans("TabsDefDescTooltip", '{s1}');
  5580. $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);
  5581. print $form->textwithpicto($langs->trans("TabsDefDesc"), $htmlhelp, 1, 'help', '', 0, 2, 'helpondesc').'<br>';
  5582. print '</span>';
  5583. print '<br>';
  5584. print '<span class="fa fa-file-o"></span> '.$langs->trans("DescriptorFile").' : <strong>'.$pathtofile.'</strong>';
  5585. 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>';
  5586. print '<br>';
  5587. print '<br>';
  5588. print load_fiche_titre($langs->trans("ListOfTabsEntries"), '', '');
  5589. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  5590. print '<input type="hidden" name="token" value="'.newToken().'">';
  5591. print '<input type="hidden" name="action" value="addproperty">';
  5592. print '<input type="hidden" name="tab" value="objects">';
  5593. print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
  5594. print '<input type="hidden" name="tabobj" value="'.dol_escape_htmltag($tabobj).'">';
  5595. print '<div class="div-table-responsive">';
  5596. print '<table class="noborder small">';
  5597. print '<tr class="liste_titre">';
  5598. print_liste_field_titre("ObjectType", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
  5599. print_liste_field_titre("Tab", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
  5600. print_liste_field_titre("Title", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
  5601. print_liste_field_titre("LangFile", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
  5602. print_liste_field_titre("Condition", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
  5603. print_liste_field_titre("Path", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder);
  5604. print "</tr>\n";
  5605. if (count($tabs)) {
  5606. foreach ($tabs as $tab) {
  5607. $parts = explode(':', $tab['data']);
  5608. $objectType = $parts[0];
  5609. $tabName = $parts[1];
  5610. $tabTitle = isset($parts[2]) ? $parts[2] : '';
  5611. $langFile = isset($parts[3]) ? $parts[3] : '';
  5612. $condition = isset($parts[4]) ? $parts[4] : '';
  5613. $path = isset($parts[5]) ? $parts[5] : '';
  5614. // If we want to remove the tab, then the format is 'objecttype:tabname:optionalcondition'
  5615. // See: https://wiki.dolibarr.org/index.php?title=Tabs_system#To_remove_an_existing_tab
  5616. if ($tabName[0] === '-') {
  5617. $tabTitle = '';
  5618. $condition = isset($parts[2]) ? $parts[2] : '';
  5619. }
  5620. print '<tr class="oddeven">';
  5621. print '<td>';
  5622. print dol_escape_htmltag($parts[0]);
  5623. print '</td>';
  5624. print '<td>';
  5625. if ($tabName[0] === "+") {
  5626. print '<span class="badge badge-status4 badge-status">' . dol_escape_htmltag($tabName) . '</span>';
  5627. } else {
  5628. print '<span class="badge badge-status8 badge-status">' . dol_escape_htmltag($tabName) . '</span>';
  5629. }
  5630. print '</td>';
  5631. print '<td>';
  5632. print dol_escape_htmltag($tabTitle);
  5633. print '</td>';
  5634. print '<td>';
  5635. print dol_escape_htmltag($langFile);
  5636. print '</td>';
  5637. print '<td>';
  5638. print dol_escape_htmltag($condition);
  5639. print '</td>';
  5640. print '<td>';
  5641. print dol_escape_htmltag($path);
  5642. print '</td>';
  5643. print '</tr>';
  5644. }
  5645. } else {
  5646. print '<tr><td colspan="5"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
  5647. }
  5648. print '</table>';
  5649. print '</div>';
  5650. print '</form>';
  5651. } else {
  5652. $fullpathoffile = dol_buildpath($file, 0);
  5653. $content = file_get_contents($fullpathoffile);
  5654. // New module
  5655. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  5656. print '<input type="hidden" name="token" value="'.newToken().'">';
  5657. print '<input type="hidden" name="action" value="savefile">';
  5658. print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
  5659. print '<input type="hidden" name="tab" value="'.$tab.'">';
  5660. print '<input type="hidden" name="module" value="'.$module.'">';
  5661. $doleditor = new DolEditor('editfilecontent', $content, '', '300', 'Full', 'In', true, false, 'ace', 0, '99%');
  5662. print $doleditor->Create(1, '', false, $langs->trans("File").' : '.$file, (GETPOST('format', 'aZ09') ? GETPOST('format', 'aZ09') : 'html'));
  5663. print '<br>';
  5664. print '<center>';
  5665. print '<input type="submit" class="button buttonforacesave button-save" id="savefile" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
  5666. print ' &nbsp; ';
  5667. print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
  5668. print '</center>';
  5669. print '</form>';
  5670. }
  5671. }
  5672. if ($tab != 'description') {
  5673. print dol_get_fiche_end();
  5674. }
  5675. }
  5676. }
  5677. print dol_get_fiche_end(); // End modules
  5678. // End of page
  5679. llxFooter();
  5680. $db->close();