index.php 292 KB

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