index.php 200 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131
  1. <?php
  2. /* Copyright (C) 2016-2023 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2020 Nicolas ZABOURI <info@inovea-conseil.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \file htdocs/website/index.php
  20. * \ingroup website
  21. * \brief Page to website view/edit
  22. */
  23. define('NOSCANPOSTFORINJECTION', 1);
  24. define('NOSTYLECHECK', 1);
  25. define('USEDOLIBARREDITOR', 1);
  26. define('FORCE_CKEDITOR', 1); // We need CKEditor, even if module is off.
  27. if (!defined('DISABLE_JS_GRAHP')) define('DISABLE_JS_GRAPH', 1);
  28. //header('X-XSS-Protection:0'); // Disable XSS filtering protection of some browsers (note: use of Content-Security-Policy is more efficient). Disabled as deprecated.
  29. // Load Dolibarr environment
  30. require '../main.inc.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  33. require_once DOL_DOCUMENT_ROOT.'/core/lib/website.lib.php';
  34. require_once DOL_DOCUMENT_ROOT.'/core/lib/website2.lib.php';
  35. require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
  36. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  37. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
  38. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formwebsite.class.php';
  39. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  40. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  41. require_once DOL_DOCUMENT_ROOT.'/website/class/website.class.php';
  42. require_once DOL_DOCUMENT_ROOT.'/website/class/websitepage.class.php';
  43. require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  44. // Load translation files required by the page
  45. $langs->loadLangs(array("admin", "other", "website", "errors"));
  46. // Security check
  47. if (!$user->hasRight('website', 'read')) {
  48. accessforbidden();
  49. }
  50. $conf->dol_hide_leftmenu = 1; // Force hide of left menu.
  51. $error = 0;
  52. $websiteid = GETPOST('websiteid', 'int');
  53. $websitekey = GETPOST('website', 'alpha');
  54. $page = GETPOST('page', 'alpha');
  55. $pageid = GETPOST('pageid', 'int');
  56. $pageref = GETPOST('pageref', 'alphanohtml');
  57. $action = GETPOST('action', 'aZ09');
  58. $massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists)
  59. $confirm = GETPOST('confirm', 'alpha');
  60. $cancel = GETPOST('cancel', 'alpha');
  61. $toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list
  62. $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'websitelist'; // To manage different context of search
  63. $backtopage = GETPOST('backtopage', 'alpha'); // Go back to a dedicated page
  64. $optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
  65. $dol_hide_topmenu = GETPOST('dol_hide_topmenu', 'int');
  66. $dol_hide_leftmenu = GETPOST('dol_hide_leftmenu', 'int');
  67. $dol_openinpopup = GETPOST('dol_openinpopup', 'aZ09');
  68. $type_container = GETPOST('WEBSITE_TYPE_CONTAINER', 'alpha');
  69. $section_dir = GETPOST('section_dir', 'alpha');
  70. $file_manager = GETPOST('file_manager', 'alpha');
  71. $replacesite = GETPOST('replacesite', 'alpha');
  72. $mode = GETPOST('mode', 'alpha');
  73. if (GETPOST('deletesite', 'alpha')) {
  74. $action = 'deletesite';
  75. }
  76. if (GETPOST('delete', 'alpha')) {
  77. $action = 'delete';
  78. }
  79. if (GETPOST('preview', 'alpha')) {
  80. $action = 'preview';
  81. }
  82. if (GETPOST('createsite', 'alpha')) {
  83. $action = 'createsite';
  84. }
  85. if (GETPOST('createcontainer', 'alpha')) {
  86. $action = 'createcontainer';
  87. }
  88. if (GETPOST('editcss', 'alpha')) {
  89. $action = 'editcss';
  90. }
  91. if (GETPOST('editmenu', 'alpha')) {
  92. $action = 'editmenu';
  93. }
  94. if (GETPOST('setashome', 'alpha')) {
  95. $action = 'setashome';
  96. }
  97. if (GETPOST('editmeta', 'alpha')) {
  98. $action = 'editmeta';
  99. }
  100. if (GETPOST('editsource', 'alpha')) {
  101. $action = 'editsource';
  102. }
  103. if (GETPOST('editcontent', 'alpha')) {
  104. $action = 'editcontent';
  105. }
  106. if (GETPOST('exportsite', 'alpha')) {
  107. $action = 'exportsite';
  108. }
  109. if (GETPOST('importsite', 'alpha')) {
  110. $action = 'importsite';
  111. }
  112. if (GETPOST('createfromclone', 'alpha')) {
  113. $action = 'createfromclone';
  114. }
  115. if (GETPOST('createpagefromclone', 'alpha')) {
  116. $action = 'createpagefromclone';
  117. }
  118. if (empty($action) && $file_manager) {
  119. $action = 'file_manager';
  120. }
  121. if ($action == 'replacesite' || (empty($action) && $replacesite)) {
  122. $mode = 'replacesite';
  123. }
  124. if (GETPOST('refreshsite') || GETPOST('refreshsite_x') || GETPOST('refreshsite.x')) {
  125. $pageid = 0;
  126. }
  127. // Load variable for pagination
  128. $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
  129. $sortfield = GETPOST('sortfield', 'aZ09comma');
  130. $sortorder = GETPOST('sortorder', 'aZ09comma');
  131. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  132. if (empty($page) || $page == -1) {
  133. $page = 0;
  134. } // If $page is not defined, or '' or -1
  135. $offset = $limit * $page;
  136. $pageprev = $page - 1;
  137. $pagenext = $page + 1;
  138. //if (! $sortfield) $sortfield='name';
  139. //if (! $sortorder) $sortorder='ASC';
  140. if (empty($action)) {
  141. $action = 'preview';
  142. }
  143. $object = new Website($db);
  144. $objectpage = new WebsitePage($db);
  145. $listofwebsites = $object->fetchAll('ASC', 'position'); // Init list of websites
  146. // If website not defined, we take first found
  147. if (!($websiteid > 0) && empty($websitekey) && $action != 'createsite') {
  148. foreach ($listofwebsites as $key => $valwebsite) {
  149. $websitekey = $valwebsite->ref;
  150. break;
  151. }
  152. }
  153. if ($websiteid > 0 || $websitekey) {
  154. $res = $object->fetch($websiteid, $websitekey);
  155. $websitekey = $object->ref;
  156. }
  157. $website = $object;
  158. // Check pageid received as parameter
  159. if ($pageid < 0) {
  160. $pageid = 0;
  161. }
  162. if (($pageid > 0 || $pageref) && $action != 'addcontainer') {
  163. $res = $objectpage->fetch($pageid, ($object->id > 0 ? $object->id : null), $pageref);
  164. if ($res == 0) {
  165. $res = $objectpage->fetch($pageid, ($object->id > 0 ? $object->id : null), null, $pageref);
  166. }
  167. // Check if pageid is inside the new website, if not we reset param pageid
  168. if ($res >= 0 && $object->id > 0) {
  169. if ($objectpage->fk_website != $object->id) { // We have a bad page that does not belong to web site
  170. if ($object->fk_default_home > 0) {
  171. $res = $objectpage->fetch($object->fk_default_home, $object->id, ''); // We search first page of web site
  172. if ($res > 0) {
  173. $pageid = $object->fk_default_home;
  174. }
  175. } else {
  176. $res = $objectpage->fetch(0, $object->id, ''); // We search first page of web site
  177. if ($res == 0) { // Page was not found, we reset it
  178. $objectpage = new WebsitePage($db);
  179. } else // We found a page, we set pageid to it.
  180. {
  181. $pageid = $objectpage->id;
  182. }
  183. }
  184. } else // We have a valid page. We force pageid for the case we got the page with a fetch on ref.
  185. {
  186. $pageid = $objectpage->id;
  187. }
  188. }
  189. }
  190. // Define pageid if pageid and pageref not received as parameter or was wrong
  191. if (empty($pageid) && empty($pageref) && $object->id > 0 && $action != 'createcontainer') {
  192. $pageid = $object->fk_default_home;
  193. if (empty($pageid)) {
  194. $array = $objectpage->fetchAll($object->id, 'ASC,ASC', 'type_container,pageurl');
  195. if (!is_array($array) && $array < 0) {
  196. dol_print_error('', $objectpage->error, $objectpage->errors);
  197. }
  198. $atleastonepage = (is_array($array) && count($array) > 0);
  199. $firstpageid = 0; $homepageid = 0;
  200. foreach ($array as $key => $valpage) {
  201. if (empty($firstpageid)) {
  202. $firstpageid = $valpage->id;
  203. }
  204. if ($object->fk_default_home && $key == $object->fk_default_home) {
  205. $homepageid = $valpage->id;
  206. }
  207. }
  208. $pageid = ($homepageid ? $homepageid : $firstpageid); // We choose home page and if not defined yet, we take first page
  209. }
  210. }
  211. global $dolibarr_main_data_root;
  212. $pathofwebsite = $dolibarr_main_data_root.($conf->entity > 1 ? '/'.$conf->entity : '').'/website/'.$websitekey;
  213. $filehtmlheader = $pathofwebsite.'/htmlheader.html';
  214. $filecss = $pathofwebsite.'/styles.css.php';
  215. $filejs = $pathofwebsite.'/javascript.js.php';
  216. $filerobot = $pathofwebsite.'/robots.txt';
  217. $filehtaccess = $pathofwebsite.'/.htaccess';
  218. $filetpl = $pathofwebsite.'/page'.$pageid.'.tpl.php';
  219. $fileindex = $pathofwebsite.'/index.php';
  220. $filewrapper = $pathofwebsite.'/wrapper.php';
  221. $filemanifestjson = $pathofwebsite.'/manifest.json.php';
  222. $filereadme = $pathofwebsite.'/README.md';
  223. $filelicense = $pathofwebsite.'/LICENSE';
  224. $filemaster = $pathofwebsite.'/master.inc.php';
  225. // Define $urlwithroot
  226. $urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
  227. $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
  228. //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
  229. $permtouploadfile = $user->hasRight('website', 'write');
  230. $diroutput = $conf->medias->multidir_output[$conf->entity];
  231. $relativepath = $section_dir;
  232. $upload_dir = preg_replace('/\/$/', '', $diroutput).'/'.preg_replace('/^\//', '', $relativepath);
  233. $htmlheadercontentdefault = '';
  234. $htmlheadercontentdefault .= '<link rel="stylesheet" id="google-fonts-css" href="//fonts.googleapis.com/css?family=Open+Sans:300,400,700" />'."\n";
  235. $htmlheadercontentdefault .= '<link rel="stylesheet" id="font-wasesome-css" href="//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" />'."\n";
  236. $htmlheadercontentdefault .= '<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>'."\n";
  237. $htmlheadercontentdefault .= '<script src="//cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>'."\n";
  238. $htmlheadercontentdefault .= '<!--'."\n";
  239. $htmlheadercontentdefault .= '<script src="/document.php?modulepart=medias&file=css/myfile.css"></script>'."\n";
  240. $htmlheadercontentdefault .= '<script src="/document.php?modulepart=medias&file=js/myfile.js"></script>'."\n";
  241. $htmlheadercontentdefault .= '-->'."\n";
  242. $manifestjsoncontentdefault = '';
  243. $manifestjsoncontentdefault .= '{
  244. "name": "MyWebsite",
  245. "short_name": "MyWebsite",
  246. "start_url": "/",
  247. "lang": "en-US",
  248. "display": "standalone",
  249. "background_color": "#fff",
  250. "description": "A simple Web app.",
  251. "icons": [{
  252. "src": "images/'.urlencode($website->ref).'/homescreen48.png",
  253. "sizes": "48x48",
  254. "type": "image/png"
  255. }, {
  256. "src": "image/'.urlencode($website->ref).'/homescreen72.png",
  257. "sizes": "72x72",
  258. "type": "image/png"
  259. }, {
  260. "src": "image/'.urlencode($website->ref).'/homescreen96.png",
  261. "sizes": "96x96",
  262. "type": "image/png"
  263. }, {
  264. "src": "image/'.urlencode($website->ref).'/homescreen144.png",
  265. "sizes": "144x144",
  266. "type": "image/png"
  267. }, {
  268. "src": "image/'.urlencode($website->ref).'/homescreen168.png",
  269. "sizes": "168x168",
  270. "type": "image/png"
  271. }, {
  272. "src": "image/'.urlencode($website->ref).'/homescreen192.png",
  273. "sizes": "192x192",
  274. "type": "image/png"
  275. }],
  276. "related_applications": [{
  277. "platform": "play",
  278. "url": "https://play.google.com/store/apps/details?id=com.nltechno.dolidroidpro"
  279. }]
  280. }';
  281. $listofpages = array();
  282. $algo = '';
  283. if (GETPOST('optionmeta')) {
  284. $algo .= 'meta';
  285. }
  286. if (GETPOST('optioncontent')) {
  287. $algo .= 'content';
  288. }
  289. if (GETPOST('optionsitefiles')) {
  290. $algo .= 'sitefiles';
  291. }
  292. if (empty($sortfield)) {
  293. if ($action == 'file_manager') {
  294. $sortfield = 'name'; $sortorder = 'ASC';
  295. } else {
  296. $sortfield = 'pageurl'; $sortorder = 'ASC';
  297. }
  298. }
  299. $searchkey = GETPOST('searchstring', 'restricthtml');
  300. if ($action == 'replacesite' || $mode == 'replacesite') {
  301. $containertype = GETPOST('optioncontainertype', 'aZ09') != '-1' ? GETPOST('optioncontainertype', 'aZ09') : '';
  302. $langcode = GETPOST('optionlanguage', 'aZ09');
  303. $otherfilters = array();
  304. if (GETPOST('optioncategory', 'int') > 0) {
  305. $otherfilters['category'] = GETPOST('optioncategory', 'int');
  306. }
  307. $listofpages = getPagesFromSearchCriterias($containertype, $algo, $searchkey, 1000, $sortfield, $sortorder, $langcode, $otherfilters, -1);
  308. }
  309. $usercanedit = $user->rights->website->write;
  310. $permissiontoadd = $user->rights->website->write; // Used by the include of actions_addupdatedelete.inc.php and actions_linkedfiles
  311. $permissiontodelete = $user->hasRight('website', 'delete');
  312. /*
  313. * Actions
  314. */
  315. // Protections
  316. if (GETPOST('refreshsite') || GETPOST('refreshsite_x') || GETPOST('refreshsite.x') || GETPOST('refreshpage') || GETPOST('refreshpage_x') || GETPOST('refreshpage.x')) {
  317. $action = 'preview'; // To avoid to make an action on another page or another site when we click on button to select another site or page.
  318. }
  319. if (GETPOST('refreshsite', 'alpha') || GETPOST('refreshsite.x', 'alpha') || GETPOST('refreshsite_x', 'alpha')) { // If we change the site, we reset the pageid and cancel addsite action.
  320. if ($action == 'addsite') {
  321. $action = 'preview';
  322. }
  323. if ($action == 'updatesource') {
  324. $action = 'preview';
  325. }
  326. $pageid = $object->fk_default_home;
  327. if (empty($pageid)) {
  328. $array = $objectpage->fetchAll($object->id, 'ASC,ASC', 'type_container,pageurl');
  329. if (!is_array($array) && $array < 0) {
  330. dol_print_error('', $objectpage->error, $objectpage->errors);
  331. }
  332. $atleastonepage = (is_array($array) && count($array) > 0);
  333. $firstpageid = 0; $homepageid = 0;
  334. foreach ($array as $key => $valpage) {
  335. if (empty($firstpageid)) {
  336. $firstpageid = $valpage->id;
  337. }
  338. if ($object->fk_default_home && $key == $object->fk_default_home) {
  339. $homepageid = $valpage->id;
  340. }
  341. }
  342. $pageid = ($homepageid ? $homepageid : $firstpageid); // We choose home page and if not defined yet, we take first page
  343. }
  344. }
  345. if (GETPOST('refreshpage', 'alpha') && !in_array($action, array('updatecss'))) {
  346. $action = 'preview';
  347. }
  348. if ($cancel && $action == 'renamefile') {
  349. $cancel = '';
  350. }
  351. // Cancel
  352. if ($cancel) {
  353. $action = 'preview';
  354. $mode = '';
  355. if ($backtopage) {
  356. header("Location: ".$backtopage);
  357. exit;
  358. }
  359. }
  360. $savbacktopage = $backtopage;
  361. $backtopage = $_SERVER["PHP_SELF"].'?file_manager=1&website='.urlencode($websitekey).'&pageid='.urlencode($pageid).(GETPOST('section_dir', 'alpha') ? '&section_dir='.urlencode(GETPOST('section_dir', 'alpha')) : ''); // used after a confirm_deletefile into actions_linkedfiles.inc.php
  362. if ($sortfield) {
  363. $backtopage .= '&sortfield='.urlencode($sortfield);
  364. }
  365. if ($sortorder) {
  366. $backtopage .= '&sortorder='.urlencode($sortorder);
  367. }
  368. include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php'; // This manage 'sendit', 'confirm_deletefile', 'renamefile' action when submitting new file.
  369. $backtopage = $savbacktopage;
  370. //var_dump($backtopage);
  371. //var_dump($action);
  372. if ($action == 'renamefile') { // Must be after include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php'; If action were renamefile, we set it to 'file_manager'
  373. $action = 'file_manager';
  374. }
  375. if ($action == 'setwebsiteonline' && $usercanedit) {
  376. $website->setStatut($website::STATUS_VALIDATED, null, '', 'WEBSITE_MODIFY', 'status');
  377. header("Location: ".$_SERVER["PHP_SELF"].'?website='.GETPOST('website', 'alphanohtml').'&pageid='.GETPOST('websitepage', 'int'));
  378. exit;
  379. }
  380. if ($action == 'setwebsiteoffline' && $usercanedit) {
  381. $result = $website->setStatut($website::STATUS_DRAFT, null, '', 'WEBSITE_MODIFY', 'status');
  382. header("Location: ".$_SERVER["PHP_SELF"].'?website='.GETPOST('website', 'alphanohtml').'&pageid='.GETPOST('websitepage', 'int'));
  383. exit;
  384. }
  385. if ($action == 'seteditinline') { // No need of write permission
  386. dolibarr_set_const($db, 'WEBSITE_EDITINLINE', 1);
  387. setEventMessages($langs->trans("FeatureNotYetAvailable"), null, 'warnings');
  388. //dolibarr_set_const($db, 'WEBSITE_SUBCONTAINERSINLINE', 0); // Force disable of 'Include dynamic content'
  389. header("Location: ".$_SERVER["PHP_SELF"].'?website='.GETPOST('website', 'alphanohtml').'&pageid='.GETPOST('pageid', 'int'));
  390. exit;
  391. }
  392. if ($action == 'unseteditinline') { // No need of write permission
  393. dolibarr_del_const($db, 'WEBSITE_EDITINLINE');
  394. header("Location: ".$_SERVER["PHP_SELF"].'?website='.GETPOST('website', 'alphanohtml').'&pageid='.GETPOST('pageid', 'int'));
  395. exit;
  396. }
  397. if ($action == 'setshowsubcontainers') { // No need of write permission
  398. dolibarr_set_const($db, 'WEBSITE_SUBCONTAINERSINLINE', 1);
  399. //dolibarr_set_const($db, 'WEBSITE_EDITINLINE', 0); // Force disable of edit inline
  400. header("Location: ".$_SERVER["PHP_SELF"].'?website='.GETPOST('website', 'alphanohtml').'&pageid='.GETPOST('pageid', 'int'));
  401. exit;
  402. }
  403. if ($action == 'unsetshowsubcontainers') { // No need of write permission
  404. dolibarr_del_const($db, 'WEBSITE_SUBCONTAINERSINLINE');
  405. header("Location: ".$_SERVER["PHP_SELF"].'?website='.GETPOST('website', 'alphanohtml').'&pageid='.GETPOST('pageid', 'int'));
  406. exit;
  407. }
  408. if ($massaction == 'replace' && GETPOST('confirmmassaction', 'alpha') && !$searchkey && $usercanedit) {
  409. $mode = 'replacesite';
  410. $action = 'replacesite';
  411. $massaction = '';
  412. }
  413. if ($action == 'deletetemplate' && $usercanedit) {
  414. $dirthemes = array('/doctemplates/websites');
  415. if (!empty($conf->modules_parts['websitetemplates'])) { // Using this feature slow down application
  416. foreach ($conf->modules_parts['websitetemplates'] as $reldir) {
  417. $dirthemes = array_merge($dirthemes, (array) ($reldir.'doctemplates/websites'));
  418. }
  419. }
  420. $dirthemes = array_unique($dirthemes);
  421. // Delete template files and dir
  422. $mode = 'importsite';
  423. $action = 'importsite';
  424. if (count($dirthemes)) {
  425. $i = 0;
  426. foreach ($dirthemes as $dir) {
  427. //print $dirroot.$dir;exit;
  428. $dirtheme = DOL_DATA_ROOT.$dir; // This include loop on $conf->file->dol_document_root
  429. if (is_dir($dirtheme)) {
  430. $templateuserfile = GETPOST('templateuserfile');
  431. $imguserfile = preg_replace('/\.zip$/', '', $templateuserfile).'.jpg';
  432. dol_delete_file($dirtheme.'/'.$templateuserfile);
  433. dol_delete_file($dirtheme.'/'.$imguserfile);
  434. }
  435. }
  436. }
  437. }
  438. // Set category
  439. if ($massaction == 'setcategory' && GETPOST('confirmmassaction', 'alpha') && $usercanedit) {
  440. $error = 0;
  441. $nbupdate = 0;
  442. $db->begin();
  443. $categoryid = GETPOST('setcategory', 'int');
  444. if ($categoryid > 0) {
  445. $tmpwebsitepage = new WebsitePage($db);
  446. $category = new Categorie($db);
  447. $category->fetch($categoryid);
  448. foreach ($toselect as $tmpid) {
  449. $tmpwebsitepage->id = $tmpid;
  450. $result = $category->add_type($tmpwebsitepage, 'website_page');
  451. if ($result < 0 && $result != -3) {
  452. $error++;
  453. setEventMessages($category->error, $category->errors, 'errors');
  454. break;
  455. } else {
  456. $nbupdate++;
  457. }
  458. }
  459. }
  460. if ($error) {
  461. $db->rollback();
  462. } else {
  463. if ($nbupdate) {
  464. setEventMessages($langs->trans("RecordsModified", $nbupdate), null, 'mesgs');
  465. }
  466. $db->commit();
  467. }
  468. // Now we reload list
  469. $listofpages = getPagesFromSearchCriterias($containertype, $algo, $searchkey, 1000, $sortfield, $sortorder, $langcode, $otherfilters, -1);
  470. }
  471. // Del category
  472. if ($massaction == 'delcategory' && GETPOST('confirmmassaction', 'alpha') && $usercanedit) {
  473. $error = 0;
  474. $nbupdate = 0;
  475. $db->begin();
  476. $categoryid = GETPOST('setcategory', 'int');
  477. if ($categoryid > 0) {
  478. $tmpwebsitepage = new WebsitePage($db);
  479. $category = new Categorie($db);
  480. $category->fetch($categoryid);
  481. foreach ($toselect as $tmpid) {
  482. $tmpwebsitepage->id = $tmpid;
  483. $result = $category->del_type($tmpwebsitepage, 'website_page');
  484. if ($result < 0 && $result != -3) {
  485. $error++;
  486. setEventMessages($category->error, $category->errors, 'errors');
  487. break;
  488. } else {
  489. $nbupdate++;
  490. }
  491. }
  492. }
  493. if ($error) {
  494. $db->rollback();
  495. } else {
  496. if ($nbupdate) {
  497. setEventMessages($langs->trans("RecordsModified", $nbupdate), null, 'mesgs');
  498. }
  499. $db->commit();
  500. }
  501. // Now we reload list
  502. $listofpages = getPagesFromSearchCriterias($containertype, $algo, $searchkey, 1000, $sortfield, $sortorder, $langcode, $otherfilters, -1);
  503. }
  504. // Replacement of string into pages
  505. if ($massaction == 'replace' && GETPOST('confirmmassaction', 'alpha') && $usercanedit) {
  506. $replacestring = GETPOST('replacestring', 'none');
  507. $dolibarrdataroot = preg_replace('/([\\/]+)$/i', '', DOL_DATA_ROOT);
  508. $allowimportsite = true;
  509. if (dol_is_file($dolibarrdataroot.'/installmodules.lock')) {
  510. $allowimportsite = false;
  511. }
  512. if (!$allowimportsite) {
  513. // Blocked by installmodules.lock
  514. if (getDolGlobalString('MAIN_MESSAGE_INSTALL_MODULES_DISABLED_CONTACT_US')) {
  515. // Show clean corporate message
  516. $message = $langs->trans('InstallModuleFromWebHasBeenDisabledContactUs');
  517. } else {
  518. // Show technical generic message
  519. $message = $langs->trans("InstallModuleFromWebHasBeenDisabledByFile", $dolibarrdataroot.'/installmodules.lock');
  520. }
  521. setEventMessages($message, null, 'errors');
  522. } elseif (!$user->hasRight('website', 'writephp')) {
  523. setEventMessages("NotAllowedToAddDynamicContent", null, 'errors');
  524. } elseif (!$replacestring) {
  525. setEventMessages("ErrorReplaceStringEmpty", null, 'errors');
  526. } else {
  527. $nbreplacement = 0;
  528. foreach ($toselect as $keyselected) {
  529. $objectpage = $listofpages['list'][$keyselected];
  530. if ($objectpage->pageurl) {
  531. dol_syslog("Replace string into page ".$objectpage->pageurl);
  532. if (GETPOST('optioncontent', 'aZ09')) {
  533. $objectpage->content = str_replace($searchkey, $replacestring, $objectpage->content);
  534. }
  535. if (GETPOST('optionmeta', 'aZ09')) {
  536. $objectpage->title = str_replace($searchkey, $replacestring, $objectpage->title);
  537. $objectpage->description = str_replace($searchkey, $replacestring, $objectpage->description);
  538. $objectpage->keywords = str_replace($searchkey, $replacestring, $objectpage->keywords);
  539. }
  540. $filealias = $pathofwebsite.'/'.$objectpage->pageurl.'.php';
  541. $filetpl = $pathofwebsite.'/page'.$objectpage->id.'.tpl.php';
  542. // Save page alias
  543. $result = dolSavePageAlias($filealias, $object, $objectpage);
  544. if (!$result) {
  545. setEventMessages('Failed to write file '.basename($filealias), null, 'errors');
  546. }
  547. // Save page of content
  548. $result = dolSavePageContent($filetpl, $object, $objectpage, 1);
  549. if ($result) {
  550. $nbreplacement++;
  551. //var_dump($objectpage->content);exit;
  552. $objectpage->update($user);
  553. } else {
  554. $error++;
  555. setEventMessages('Failed to write file '.$filetpl, null, 'errors');
  556. $action = 'createcontainer';
  557. break;
  558. }
  559. }
  560. }
  561. if ($nbreplacement > 0) {
  562. setEventMessages($langs->trans("ReplacementDoneInXPages", $nbreplacement), null, 'mesgs');
  563. }
  564. $containertype = GETPOST('optioncontainertype', 'aZ09') != '-1' ? GETPOST('optioncontainertype', 'aZ09') : '';
  565. $langcode = GETPOST('optionlanguage', 'aZ09');
  566. $otherfilters = array();
  567. if (GETPOST('optioncategory', 'int') > 0) {
  568. $otherfilters['category'] = GETPOST('optioncategory', 'int');
  569. }
  570. // Now we reload list
  571. $listofpages = getPagesFromSearchCriterias($containertype, $algo, $searchkey, 1000, $sortfield, $sortorder, $langcode, $otherfilters);
  572. }
  573. }
  574. // Add directory
  575. /*
  576. if ($action == 'adddir' && $permtouploadfile)
  577. {
  578. $ecmdir->ref = 'NOTUSEDYET';
  579. $ecmdir->label = GETPOST("label");
  580. $ecmdir->description = GETPOST("desc");
  581. //$id = $ecmdir->create($user);
  582. if ($id > 0)
  583. {
  584. header("Location: ".$_SERVER["PHP_SELF"]);
  585. exit;
  586. }
  587. else
  588. {
  589. setEventMessages('Error '.$langs->trans($ecmdir->error), null, 'errors');
  590. $action = "createcontainer";
  591. }
  592. clearstatcache();
  593. }
  594. */
  595. // Add site
  596. if ($action == 'addsite' && $usercanedit) {
  597. $db->begin();
  598. if (GETPOST('virtualhost', 'alpha') && !preg_match('/^http/', GETPOST('virtualhost', 'alpha'))) {
  599. $error++;
  600. setEventMessages($langs->trans('ErrorURLMustStartWithHttp', $langs->transnoentitiesnoconv("VirtualHost")), null, 'errors');
  601. }
  602. if (!$error && !GETPOST('WEBSITE_REF', 'alpha')) {
  603. $error++;
  604. $langs->load("errors");
  605. setEventMessages($langs->transnoentities("ErrorFieldRequired", $langs->transnoentities("WebsiteName")), null, 'errors');
  606. }
  607. if (!$error && !preg_match('/^[a-z0-9_\-\.]+$/i', GETPOST('WEBSITE_REF', 'alpha'))) {
  608. $error++;
  609. $langs->load("errors");
  610. setEventMessages($langs->transnoentities("ErrorFieldCanNotContainSpecialCharacters", $langs->transnoentities("Ref")), null, 'errors');
  611. }
  612. if (!$error) {
  613. $arrayotherlang = explode(',', GETPOST('WEBSITE_OTHERLANG', 'alphanohtml'));
  614. foreach ($arrayotherlang as $key => $val) {
  615. // It possible we have empty val here if postparam WEBSITE_OTHERLANG is empty or set like this : 'en,,sv' or 'en,sv,'
  616. if (empty(trim($val))) continue;
  617. $arrayotherlang[$key] = substr(trim($val), 0, 2); // Kept short language code only
  618. }
  619. $tmpobject = new Website($db);
  620. $tmpobject->ref = GETPOST('WEBSITE_REF', 'alpha');
  621. $tmpobject->description = GETPOST('WEBSITE_DESCRIPTION', 'alphanohtml');
  622. $tmpobject->lang = GETPOST('WEBSITE_LANG', 'aZ09');
  623. $tmpobject->otherlang = join(',', $arrayotherlang);
  624. $tmpobject->virtualhost = GETPOST('virtualhost', 'alpha');
  625. $result = $tmpobject->create($user);
  626. if ($result == 0) {
  627. $error++;
  628. setEventMessages($langs->trans("ErrorLabelAlreadyExists"), null, 'errors');
  629. } elseif ($result < 0) {
  630. $error++;
  631. setEventMessages($tmpobject->error, $tmpobject->errors, 'errors');
  632. }
  633. }
  634. if (!$error) {
  635. $db->commit();
  636. setEventMessages($langs->trans("SiteAdded", $object->ref), null, 'mesgs');
  637. $action = '';
  638. header("Location: ".$_SERVER["PHP_SELF"].'?website='.$tmpobject->ref);
  639. exit;
  640. } else {
  641. $db->rollback();
  642. $action = 'createsite';
  643. }
  644. if (!$error) {
  645. $action = 'preview';
  646. $id = $object->id;
  647. }
  648. }
  649. // Add page/container
  650. if ($action == 'addcontainer' && $usercanedit) {
  651. dol_mkdir($pathofwebsite);
  652. $db->begin();
  653. $objectpage->fk_website = $object->id;
  654. if (GETPOSTISSET('fetchexternalurl')) { // Fetch from external url
  655. $urltograb = GETPOST('externalurl', 'alpha');
  656. $grabimages = GETPOST('grabimages', 'alpha');
  657. $grabimagesinto = GETPOST('grabimagesinto', 'alpha');
  658. include_once DOL_DOCUMENT_ROOT.'/core/lib/geturl.lib.php';
  659. if (empty($urltograb)) {
  660. $error++;
  661. $langs->load("errors");
  662. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("URL")), null, 'errors');
  663. $action = 'createcontainer';
  664. } elseif (!preg_match('/^http/', $urltograb)) {
  665. $error++;
  666. $langs->load("errors");
  667. setEventMessages('Error URL must start with http:// or https://', null, 'errors');
  668. $action = 'createcontainer';
  669. }
  670. if (!$error) {
  671. // Clean url to grab, so url can be
  672. // http://www.example.com/ or http://www.example.com/dir1/ or http://www.example.com/dir1/aaa
  673. $urltograbwithoutdomainandparam = preg_replace('/^https?:\/\/[^\/]+\/?/i', '', $urltograb);
  674. //$urltograbwithoutdomainandparam = preg_replace('/^file:\/\/[^\/]+\/?/i', '', $urltograb);
  675. $urltograbwithoutdomainandparam = preg_replace('/\?.*$/', '', $urltograbwithoutdomainandparam);
  676. if (empty($urltograbwithoutdomainandparam) && !preg_match('/\/$/', $urltograb)) {
  677. $urltograb .= '/';
  678. }
  679. $pageurl = dol_sanitizeFileName(preg_replace('/[\/\.]/', '-', preg_replace('/\/+$/', '', $urltograbwithoutdomainandparam)));
  680. $urltograbdirwithoutslash = dirname($urltograb.'.');
  681. $urltograbdirrootwithoutslash = getRootURLFromURL($urltograbdirwithoutslash);
  682. // Exemple, now $urltograbdirwithoutslash is https://www.dolimed.com/screenshots
  683. // and $urltograbdirrootwithoutslash is https://www.dolimed.com
  684. }
  685. // Check pageurl is not already used
  686. if ($pageurl) {
  687. $tmpwebsitepage = new WebsitePage($db);
  688. $result = $tmpwebsitepage->fetch(0, $object->id, $pageurl);
  689. if ($result > 0) {
  690. setEventMessages($langs->trans("AliasPageAlreadyExists", $pageurl), null, 'errors');
  691. $error++;
  692. $action = 'createcontainer';
  693. }
  694. }
  695. if (!$error) {
  696. $tmp = getURLContent($urltograb, 'GET', '', 1, array(), array('http', 'https'), 0);
  697. if ($tmp['curl_error_no']) {
  698. $error++;
  699. setEventMessages('Error getting '.$urltograb.': '.$tmp['curl_error_msg'], null, 'errors');
  700. $action = 'createcontainer';
  701. } elseif ($tmp['http_code'] != '200') {
  702. $error++;
  703. setEventMessages('Error getting '.$urltograb.': '.$tmp['http_code'], null, 'errors');
  704. $action = 'createcontainer';
  705. } else {
  706. // Remove comments
  707. $tmp['content'] = removeHtmlComment($tmp['content']);
  708. // Check there is no PHP content into the imported file (must be only HTML + JS)
  709. $phpcontent = dolKeepOnlyPhpCode($tmp['content']);
  710. if ($phpcontent) {
  711. $error++;
  712. setEventMessages('Error getting '.$urltograb.': file that include PHP content is not allowed', null, 'errors');
  713. $action = 'createcontainer';
  714. }
  715. }
  716. if (!$error) {
  717. $regs = array();
  718. preg_match('/<head>(.*)<\/head>/ims', $tmp['content'], $regs);
  719. $head = $regs[1];
  720. $objectpage->type_container = 'page';
  721. $objectpage->pageurl = $pageurl;
  722. if (empty($objectpage->pageurl)) {
  723. $tmpdomain = getDomainFromURL($urltograb);
  724. $objectpage->pageurl = $tmpdomain.'-home';
  725. }
  726. $objectpage->aliasalt = '';
  727. if (preg_match('/^(\d+)\-/', basename($urltograb), $regs)) {
  728. $objectpage->aliasalt = $regs[1];
  729. }
  730. $regtmp = array();
  731. if (preg_match('/<title>(.*)<\/title>/ims', $head, $regtmp)) {
  732. $objectpage->title = $regtmp[1];
  733. }
  734. if (preg_match('/<meta name="title"[^"]+content="([^"]+)"/ims', $head, $regtmp)) {
  735. if (empty($objectpage->title)) {
  736. $objectpage->title = $regtmp[1]; // If title not found into <title>, we get it from <meta title>
  737. }
  738. }
  739. if (preg_match('/<meta name="description"[^"]+content="([^"]+)"/ims', $head, $regtmp)) {
  740. $objectpage->description = $regtmp[1];
  741. }
  742. if (preg_match('/<meta name="keywords"[^"]+content="([^"]+)"/ims', $head, $regtmp)) {
  743. $objectpage->keywords = $regtmp[1];
  744. }
  745. if (preg_match('/<html\s+lang="([^"]+)"/ims', $tmp['content'], $regtmp)) {
  746. $tmplang = explode('-', $regtmp[1]);
  747. $objectpage->lang = $tmplang[0].($tmplang[1] ? '_'.strtoupper($tmplang[1]) : '');
  748. }
  749. $tmp['content'] = preg_replace('/\s*<meta name="generator"[^"]+content="([^"]+)"\s*\/?>/ims', '', $tmp['content']);
  750. $objectpage->content = $tmp['content'];
  751. $objectpage->content = preg_replace('/^.*<body(\s[^>]*)*>/ims', '', $objectpage->content);
  752. $objectpage->content = preg_replace('/<\/body(\s[^>]*)*>.*$/ims', '', $objectpage->content);
  753. // TODO Replace 'action="$urltograbdirwithoutslash' into action="/"
  754. // TODO Replace 'action="$urltograbdirwithoutslash..."' into action="..."
  755. // TODO Replace 'a href="$urltograbdirwithoutslash' into a href="/"
  756. // TODO Replace 'a href="$urltograbdirwithoutslash..."' into a href="..."
  757. // Now loop to fetch all css files. Include them inline into header of page
  758. $objectpage->htmlheader = $tmp['content'];
  759. $objectpage->htmlheader = preg_replace('/^.*<head(\s[^>]*)*>/ims', '', $objectpage->htmlheader);
  760. $objectpage->htmlheader = preg_replace('/<\/head(\s[^>]*)*>.*$/ims', '', $objectpage->htmlheader);
  761. $objectpage->htmlheader = preg_replace('/<base(\s[^>]*)*>\n*/ims', '', $objectpage->htmlheader);
  762. $objectpage->htmlheader = preg_replace('/<meta http-equiv="content-type"([^>]*)*>\n*/ims', '', $objectpage->htmlheader);
  763. $objectpage->htmlheader = preg_replace('/<meta name="robots"([^>]*)*>\n*/ims', '', $objectpage->htmlheader);
  764. $objectpage->htmlheader = preg_replace('/<meta name="title"([^>]*)*>\n*/ims', '', $objectpage->htmlheader);
  765. $objectpage->htmlheader = preg_replace('/<meta name="description"([^>]*)*>\n*/ims', '', $objectpage->htmlheader);
  766. $objectpage->htmlheader = preg_replace('/<meta name="keywords"([^>]*)*>\n*/ims', '', $objectpage->htmlheader);
  767. $objectpage->htmlheader = preg_replace('/<meta name="generator"([^>]*)*>\n*/ims', '', $objectpage->htmlheader);
  768. //$objectpage->htmlheader = preg_replace('/<meta name="verify-v1[^>]*>\n*/ims', '', $objectpage->htmlheader);
  769. //$objectpage->htmlheader = preg_replace('/<meta name="msvalidate.01[^>]*>\n*/ims', '', $objectpage->htmlheader);
  770. $objectpage->htmlheader = preg_replace('/<title>[^<]*<\/title>\n*/ims', '', $objectpage->htmlheader);
  771. $objectpage->htmlheader = preg_replace('/<link[^>]*rel="shortcut[^>]*>\n/ims', '', $objectpage->htmlheader);
  772. $objectpage->htmlheader = preg_replace('/<link[^>]*rel="alternate[^>]*>\n/ims', '', $objectpage->htmlheader);
  773. $objectpage->htmlheader = preg_replace('/<link[^>]*rel="canonical[^>]*>\n/ims', '', $objectpage->htmlheader);
  774. // Now loop to fetch JS
  775. $tmp = $objectpage->htmlheader;
  776. // We grab files found into <script> tags
  777. preg_match_all('/<script([^\.>]+)src=["\']([^"\'>]+)["\']([^>]*)><\/script>/i', $objectpage->htmlheader, $regs);
  778. $errorforsubresource = 0;
  779. foreach ($regs[0] as $key => $val) {
  780. dol_syslog("We will grab the script resource found into script tag ".$regs[2][$key]);
  781. $linkwithoutdomain = $regs[2][$key];
  782. if (preg_match('/^\//', $regs[2][$key])) {
  783. $urltograbbis = $urltograbdirrootwithoutslash.$regs[2][$key]; // We use dirroot
  784. } else {
  785. $urltograbbis = $urltograbdirwithoutslash.'/'.$regs[2][$key]; // We use dir of grabbed file
  786. }
  787. //$filetosave = $conf->medias->multidir_output[$conf->entity].'/css/'.$object->ref.'/'.$objectpage->pageurl.(preg_match('/^\//', $regs[2][$key])?'':'/').$regs[2][$key];
  788. if (preg_match('/^http/', $regs[2][$key])) {
  789. $urltograbbis = $regs[2][$key];
  790. $linkwithoutdomain = preg_replace('/^https?:\/\/[^\/]+\//i', '', $regs[2][$key]);
  791. //$filetosave = $conf->medias->multidir_output[$conf->entity].'/css/'.$object->ref.'/'.$objectpage->pageurl.(preg_match('/^\//', $linkwithoutdomain)?'':'/').$linkwithoutdomain;
  792. }
  793. //print $domaintograb.' - '.$domaintograbbis.' - '.$urltograbdirwithoutslash.' - ';
  794. //print $linkwithoutdomain.' - '.$urltograbbis."<br>\n";
  795. // Test if this is an external URL of grabbed web site. If yes, we do not load resource
  796. $domaintograb = getDomainFromURL($urltograbdirwithoutslash);
  797. $domaintograbbis = getDomainFromURL($urltograbbis);
  798. if ($domaintograb != $domaintograbbis) {
  799. continue;
  800. }
  801. /*
  802. $tmpgeturl = getURLContent($urltograbbis, 'GET', '', 1, array(), array('http', 'https'), 0);
  803. if ($tmpgeturl['curl_error_no'])
  804. {
  805. $error++;
  806. setEventMessages('Error getting script url '.$urltograbbis.': '.$tmpgeturl['curl_error_msg'], null, 'errors');
  807. $errorforsubresource++;
  808. $action='createcontainer';
  809. }
  810. elseif ($tmpgeturl['http_code'] != '200')
  811. {
  812. $error++;
  813. setEventMessages('Error getting script url '.$urltograbbis.': '.$tmpgeturl['http_code'], null, 'errors');
  814. $errorforsubresource++;
  815. $action='createcontainer';
  816. }
  817. else
  818. {
  819. dol_mkdir(dirname($filetosave));
  820. $fp = fopen($filetosave, "w");
  821. fputs($fp, $tmpgeturl['content']);
  822. fclose($fp);
  823. dolChmod($file);
  824. }
  825. */
  826. //$filename = 'image/'.$object->ref.'/'.$objectpage->pageurl.(preg_match('/^\//', $linkwithoutdomain)?'':'/').$linkwithoutdomain;
  827. $tmp = preg_replace('/'.preg_quote($regs[0][$key], '/').'/i', '', $tmp);
  828. }
  829. $objectpage->htmlheader = trim($tmp)."\n";
  830. // Now we grab CSS found into <link> tags
  831. $pagecsscontent = "\n".'<style>'."\n";
  832. preg_match_all('/<link([^\.>]+)href=["\']([^"\'>]+\.css[^"\'>]*)["\']([^>]*)>/i', $objectpage->htmlheader, $regs);
  833. $errorforsubresource = 0;
  834. foreach ($regs[0] as $key => $val) {
  835. dol_syslog("We will grab the css resources found into link tag ".$regs[2][$key]);
  836. $linkwithoutdomain = $regs[2][$key];
  837. if (preg_match('/^\//', $regs[2][$key])) {
  838. $urltograbbis = $urltograbdirrootwithoutslash.$regs[2][$key]; // We use dirroot
  839. } else {
  840. $urltograbbis = $urltograbdirwithoutslash.'/'.$regs[2][$key]; // We use dir of grabbed file
  841. }
  842. //$filetosave = $conf->medias->multidir_output[$conf->entity].'/css/'.$object->ref.'/'.$objectpage->pageurl.(preg_match('/^\//', $regs[2][$key])?'':'/').$regs[2][$key];
  843. if (preg_match('/^http/', $regs[2][$key])) {
  844. $urltograbbis = $regs[2][$key];
  845. $linkwithoutdomain = preg_replace('/^https?:\/\/[^\/]+\//i', '', $regs[2][$key]);
  846. //$filetosave = $conf->medias->multidir_output[$conf->entity].'/css/'.$object->ref.'/'.$objectpage->pageurl.(preg_match('/^\//', $linkwithoutdomain)?'':'/').$linkwithoutdomain;
  847. }
  848. //print $domaintograb.' - '.$domaintograbbis.' - '.$urltograbdirwithoutslash.' - ';
  849. //print $linkwithoutdomain.' - '.$urltograbbis."<br>\n";
  850. // Test if this is an external URL of grabbed web site. If yes, we do not load resource
  851. $domaintograb = getDomainFromURL($urltograbdirwithoutslash);
  852. $domaintograbbis = getDomainFromURL($urltograbbis);
  853. if ($domaintograb != $domaintograbbis) {
  854. continue;
  855. }
  856. $tmpgeturl = getURLContent($urltograbbis, 'GET', '', 1, array(), array('http', 'https'), 0);
  857. if ($tmpgeturl['curl_error_no']) {
  858. $errorforsubresource++;
  859. setEventMessages('Error getting link tag url '.$urltograbbis.': '.$tmpgeturl['curl_error_msg'], null, 'errors');
  860. dol_syslog('Error getting '.$urltograbbis.': '.$tmpgeturl['curl_error_msg']);
  861. $action = 'createcontainer';
  862. } elseif ($tmpgeturl['http_code'] != '200') {
  863. $errorforsubresource++;
  864. setEventMessages('Error getting link tag url '.$urltograbbis.': '.$tmpgeturl['http_code'], null, 'errors');
  865. dol_syslog('Error getting '.$urltograbbis.': '.$tmpgeturl['curl_error_msg']);
  866. $action = 'createcontainer';
  867. } else {
  868. // Clean some comment
  869. //$tmpgeturl['content'] = dol_string_is_good_iso($tmpgeturl['content'], 1);
  870. //$tmpgeturl['content'] = mb_convert_encoding($tmpgeturl['content'], 'UTF-8', 'UTF-8');
  871. //$tmpgeturl['content'] = remove_bs($tmpgeturl['content']);
  872. //$tmpgeturl['content'] = str_replace('$screen-md-max', 'auto', $tmpgeturl['content']);
  873. //var_dump($tmpgeturl['content']);exit;
  874. $tmpgeturl['content'] = preg_replace('/\/\*\s+CSS content[a-z\s]*\s+\*\//', '', $tmpgeturl['content']);
  875. //dol_mkdir(dirname($filetosave));
  876. //$fp = fopen($filetosave, "w");
  877. //fputs($fp, $tmpgeturl['content']);
  878. //fclose($fp);
  879. //dolChmod($file);
  880. // $filename = 'image/'.$object->ref.'/'.$objectpage->pageurl.(preg_match('/^\//', $linkwithoutdomain)?'':'/').$linkwithoutdomain;
  881. $pagecsscontent .= '/* Content of file '.$urltograbbis.' */'."\n";
  882. getAllImages($object, $objectpage, $urltograbbis, $tmpgeturl['content'], $action, 1, $grabimages, $grabimagesinto);
  883. // We try to convert the CSS we got by adding a prefix .bodywebsite with lessc to avoid conflict with CSS of Dolibarr.
  884. include_once DOL_DOCUMENT_ROOT.'/core/class/lessc.class.php';
  885. $lesscobj = new Lessc();
  886. try {
  887. $contentforlessc = ".bodywebsite {\n".$tmpgeturl['content']."\n}\n";
  888. //print '<pre>'.$contentforlessc.'</pre>';
  889. $contentforlessc = $lesscobj->compile($contentforlessc);
  890. //var_dump($contentforlessc); exit;
  891. $pagecsscontent .= $contentforlessc."\n";
  892. //$pagecsscontent.=$tmpgeturl['content']."\n";
  893. } catch (exception $e) {
  894. //echo "failed to compile lessc";
  895. dol_syslog("Failed to compile the CSS from URL ".$urltograbbis." with lessc: ".$e->getMessage(), LOG_WARNING);
  896. $pagecsscontent .= $tmpgeturl['content']."\n";
  897. }
  898. $objectpage->htmlheader = preg_replace('/'.preg_quote($regs[0][$key], '/').'\n*/ims', '', $objectpage->htmlheader);
  899. }
  900. }
  901. $pagecsscontent .= '</style>';
  902. //var_dump($pagecsscontent);
  903. //print dol_escape_htmltag($tmp);exit;
  904. $objectpage->htmlheader .= trim($pagecsscontent)."\n";
  905. // Now we have to fetch all images into page
  906. $tmp = $objectpage->content;
  907. getAllImages($object, $objectpage, $urltograb, $tmp, $action, 1, $grabimages, $grabimagesinto);
  908. // Normalize links href to Dolibarr internal naming
  909. $tmp = preg_replace('/a href="\/([^\/"]+)\/([^\/"]+)"/', 'a href="/\1-\2.php"', $tmp);
  910. $tmp = preg_replace('/a href="\/([^\/"]+)\/([^\/"]+)\/([^\/"]+)"/', 'a href="/\1-\2-\3.php"', $tmp);
  911. $tmp = preg_replace('/a href="\/([^\/"]+)\/([^\/"]+)\/([^\/"]+)\/([^\/"]+)"/', 'a href="/\1-\2-\3-\4.php"', $tmp);
  912. //print dol_escape_htmltag($tmp);exit;
  913. $objectpage->content = $tmp;
  914. $objectpage->grabbed_from = $urltograb;
  915. }
  916. }
  917. } else {
  918. $newaliasnames = '';
  919. if (!$error && GETPOST('WEBSITE_ALIASALT', 'alpha')) {
  920. $arrayofaliastotest = explode(',', str_replace(array('<', '>'), '', GETPOST('WEBSITE_ALIASALT', 'alpha')));
  921. $websitepagetemp = new WebsitePage($db);
  922. foreach ($arrayofaliastotest as $aliastotest) {
  923. $aliastotest = trim(preg_replace('/\.php$/i', '', $aliastotest));
  924. // Disallow alias name pageX (already used to save the page with id)
  925. if (preg_match('/^page\d+/i', $aliastotest)) {
  926. $error++;
  927. $langs->load("errors");
  928. setEventMessages("Alias name 'pageX' is not allowed", null, 'errors');
  929. $action = 'createcontainer';
  930. break;
  931. } else {
  932. $result = $websitepagetemp->fetch(0, $object->id, $aliastotest);
  933. if ($result < 0) {
  934. $error++;
  935. $langs->load("errors");
  936. setEventMessages($websitepagetemp->error, $websitepagetemp->errors, 'errors');
  937. $action = 'createcontainer';
  938. break;
  939. }
  940. if ($result > 0) {
  941. $error++;
  942. $langs->load("errors");
  943. setEventMessages($langs->trans("ErrorAPageWithThisNameOrAliasAlreadyExists", $websitepagetemp->pageurl), null, 'errors');
  944. $action = 'createcontainer';
  945. break;
  946. }
  947. $newaliasnames .= ($newaliasnames ? ', ' : '').$aliastotest;
  948. }
  949. }
  950. }
  951. $objectpage->title = str_replace(array('<', '>'), '', GETPOST('WEBSITE_TITLE', 'alphanohtml'));
  952. $objectpage->type_container = GETPOST('WEBSITE_TYPE_CONTAINER', 'aZ09');
  953. $objectpage->pageurl = GETPOST('WEBSITE_PAGENAME', 'alpha');
  954. $objectpage->aliasalt = $newaliasnames;
  955. $objectpage->description = str_replace(array('<', '>'), '', GETPOST('WEBSITE_DESCRIPTION', 'alphanohtml'));
  956. $objectpage->lang = GETPOST('WEBSITE_LANG', 'aZ09');
  957. $objectpage->otherlang = GETPOST('WEBSITE_OTHERLANG', 'aZ09comma');
  958. $objectpage->image = GETPOST('WEBSITE_IMAGE', 'alpha');
  959. $objectpage->keywords = str_replace(array('<', '>'), '', GETPOST('WEBSITE_KEYWORDS', 'alphanohtml'));
  960. $objectpage->allowed_in_frames = GETPOST('WEBSITE_ALLOWED_IN_FRAMES', 'aZ09');
  961. $objectpage->htmlheader = GETPOST('htmlheader', 'none');
  962. $objectpage->author_alias = GETPOST('WEBSITE_AUTHORALIAS', 'alphanohtml');
  963. $objectpage->object_type = GETPOST('WEBSITE_OBJECTCLASS');
  964. $objectpage->fk_object = GETPOST('WEBSITE_OBJECTID');
  965. $substitutionarray = array();
  966. $substitutionarray['__WEBSITE_CREATE_BY__'] = $user->getFullName($langs);
  967. // Define id of page the new page is translation of
  968. $pageidfortranslation = (GETPOST('pageidfortranslation', 'int') > 0 ? GETPOST('pageidfortranslation', 'int') : 0);
  969. if ($pageidfortranslation > 0) {
  970. // Check if the page we are translation of is alreayd a translation of a source page. if yes, we will use source id instead
  971. $objectpagetmp = new WebsitePage($db);
  972. $objectpagetmp->fetch($pageidfortranslation);
  973. if ($objectpagetmp->fk_page > 0) {
  974. $pageidfortranslation = $objectpagetmp->fk_page;
  975. }
  976. }
  977. $objectpage->fk_page = $pageidfortranslation;
  978. $sample = GETPOST('sample', 'alpha');
  979. if (empty($sample)) {
  980. $sample = 'empty';
  981. }
  982. $pathtosample = DOL_DOCUMENT_ROOT.'/website/samples/page-sample-'.dol_sanitizeFileName($sample).'.html';
  983. // Init content with content into pagetemplate.html, blogposttempltate.html, ...
  984. $objectpage->content = make_substitutions(@file_get_contents($pathtosample), $substitutionarray);
  985. }
  986. if (!$error) {
  987. if (empty($objectpage->pageurl)) {
  988. $langs->load("errors");
  989. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("WEBSITE_PAGENAME")), null, 'errors');
  990. $error++;
  991. $action = 'createcontainer';
  992. } elseif (!preg_match('/^[a-z0-9\-\_]+$/i', $objectpage->pageurl)) {
  993. $langs->load("errors");
  994. setEventMessages($langs->transnoentities("ErrorFieldCanNotContainSpecialCharacters", $langs->transnoentities('WEBSITE_PAGENAME')), null, 'errors');
  995. $error++;
  996. $action = 'createcontainer';
  997. }
  998. if (empty($objectpage->title)) {
  999. $langs->load("errors");
  1000. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("WEBSITE_TITLE")), null, 'errors');
  1001. $error++;
  1002. $action = 'createcontainer';
  1003. }
  1004. if ($objectpage->fk_page > 0 && empty($objectpage->lang)) {
  1005. $langs->load("errors");
  1006. setEventMessages($langs->trans("ErrorLanguageRequiredIfPageIsTranslationOfAnother"), null, 'errors');
  1007. $error++;
  1008. $action = 'createcontainer';
  1009. }
  1010. if ($objectpage->fk_page > 0 && !empty($objectpage->lang)) {
  1011. if ($objectpage->lang == $website->lang) {
  1012. $langs->load("errors");
  1013. setEventMessages($langs->trans("ErrorLanguageMustNotBeSourceLanguageIfPageIsTranslationOfAnother"), null, 'errors');
  1014. $error++;
  1015. $action = 'createcontainer';
  1016. }
  1017. }
  1018. }
  1019. if (!$error) {
  1020. $pageid = $objectpage->create($user);
  1021. if ($pageid <= 0) {
  1022. $error++;
  1023. setEventMessages($objectpage->error, $objectpage->errors, 'errors');
  1024. $action = 'createcontainer';
  1025. }
  1026. }
  1027. if (!$error) {
  1028. // Website categories association
  1029. $categoriesarray = GETPOST('categories', 'array');
  1030. $result = $objectpage->setCategories($categoriesarray);
  1031. if ($result < 0) {
  1032. $error++;
  1033. setEventMessages($object->error, $object->errors, 'errors');
  1034. }
  1035. }
  1036. if (!$error) {
  1037. // If there is no home page yet, this new page will be set as the home page
  1038. if (empty($object->fk_default_home)) {
  1039. $object->fk_default_home = $pageid;
  1040. $res = $object->update($user);
  1041. if ($res <= 0) {
  1042. $error++;
  1043. setEventMessages($object->error, $object->errors, 'errors');
  1044. } else {
  1045. $filetpl = $pathofwebsite.'/page'.$pageid.'.tpl.php';
  1046. // Generate the index.php page (to be the home page) and the wrapper.php file
  1047. $result = dolSaveIndexPage($pathofwebsite, $fileindex, $filetpl, $filewrapper, $object);
  1048. if ($result <= 0) {
  1049. setEventMessages('Failed to write file '.$fileindex, null, 'errors');
  1050. }
  1051. }
  1052. }
  1053. }
  1054. if (!$error) {
  1055. if (!empty($objectpage->content)) {
  1056. $filealias = $pathofwebsite.'/'.$objectpage->pageurl.'.php';
  1057. $filetpl = $pathofwebsite.'/page'.$objectpage->id.'.tpl.php';
  1058. // Save page alias
  1059. $result = dolSavePageAlias($filealias, $object, $objectpage);
  1060. if (!$result) {
  1061. setEventMessages('Failed to write file '.basename($filealias), null, 'errors');
  1062. }
  1063. // Save page of content
  1064. $result = dolSavePageContent($filetpl, $object, $objectpage, 1);
  1065. if ($result) {
  1066. setEventMessages($langs->trans("Saved"), null, 'mesgs');
  1067. } else {
  1068. setEventMessages('Failed to write file '.$filetpl, null, 'errors');
  1069. $action = 'createcontainer';
  1070. }
  1071. }
  1072. }
  1073. if (!$error) {
  1074. $db->commit();
  1075. setEventMessages($langs->trans("PageAdded", $objectpage->pageurl), null, 'mesgs');
  1076. $action = '';
  1077. } else {
  1078. $db->rollback();
  1079. }
  1080. if (!$error) {
  1081. $pageid = $objectpage->id;
  1082. // To generate the CSS, robot and htmlheader file.
  1083. // Check symlink to medias and restore it if ko
  1084. $pathtomedias = DOL_DATA_ROOT.'/medias';
  1085. $pathtomediasinwebsite = $pathofwebsite.'/medias';
  1086. if (!is_link(dol_osencode($pathtomediasinwebsite))) {
  1087. dol_syslog("Create symlink for ".$pathtomedias." into name ".$pathtomediasinwebsite);
  1088. dol_mkdir(dirname($pathtomediasinwebsite)); // To be sure dir for website exists
  1089. $result = symlink($pathtomedias, $pathtomediasinwebsite);
  1090. }
  1091. // Now generate the master.inc.php page if it does not exists yet
  1092. if (!dol_is_file($filemaster)) {
  1093. $result = dolSaveMasterFile($filemaster);
  1094. if (!$result) {
  1095. $error++;
  1096. setEventMessages('Failed to write file '.$filemaster, null, 'errors');
  1097. }
  1098. }
  1099. if (!dol_is_file($filehtmlheader)) {
  1100. $htmlheadercontent = "<html>\n";
  1101. $htmlheadercontent .= $htmlheadercontentdefault;
  1102. $htmlheadercontent .= "</html>";
  1103. $result = dolSaveHtmlHeader($filehtmlheader, $htmlheadercontent);
  1104. }
  1105. if (!dol_is_file($filecss)) {
  1106. $csscontent = "/* CSS content (all pages) */\nbody.bodywebsite { margin: 0; font-family: 'Open Sans', sans-serif; }\n.bodywebsite h1 { margin-top: 0; margin-bottom: 0; padding: 10px;}";
  1107. $result = dolSaveCssFile($filecss, $csscontent);
  1108. }
  1109. if (!dol_is_file($filejs)) {
  1110. $jscontent = "/* JS content (all pages) */\n";
  1111. $result = dolSaveJsFile($filejs, $jscontent);
  1112. }
  1113. if (!dol_is_file($filerobot)) {
  1114. $robotcontent = "# Robot file. Generated with Dolibarr\nUser-agent: *\nAllow: /public/\nDisallow: /administrator/";
  1115. $result = dolSaveRobotFile($filerobot, $robotcontent);
  1116. }
  1117. if (!dol_is_file($filehtaccess)) {
  1118. $htaccesscontent = "# Order allow,deny\n# Deny from all";
  1119. $result = dolSaveHtaccessFile($filehtaccess, $htaccesscontent);
  1120. }
  1121. if (!dol_is_file($filemanifestjson)) {
  1122. $manifestjsoncontent = "";
  1123. $result = dolSaveManifestJson($filemanifestjson, $manifestjsoncontent);
  1124. }
  1125. if (!dol_is_file($filereadme)) {
  1126. $readmecontent = "Website generated by Dolibarr ERP CRM";
  1127. $result = dolSaveReadme($filereadme, $readmecontent);
  1128. }
  1129. if (!dol_is_file($filelicense)) {
  1130. $licensecontent = "MIT License";
  1131. $result = dolSaveLicense($filelicense, $licensecontent);
  1132. }
  1133. $action = 'preview';
  1134. }
  1135. }
  1136. // Delete site
  1137. if ($action == 'confirm_deletesite' && $confirm == 'yes' && $permissiontodelete) {
  1138. $error = 0;
  1139. $db->begin();
  1140. $res = $object->fetch(GETPOST('id', 'int'));
  1141. $website = $object;
  1142. if ($res > 0) {
  1143. $res = $object->delete($user);
  1144. if ($res <= 0) {
  1145. $error++;
  1146. setEventMessages($object->error, $object->errors, 'errors');
  1147. }
  1148. }
  1149. if (!$error) {
  1150. if (GETPOST('delete_also_js', 'alpha') == 'on') {
  1151. $pathofwebsitejs = DOL_DATA_ROOT.'/medias/js/'.$object->ref;
  1152. dol_delete_dir_recursive($pathofwebsitejs);
  1153. }
  1154. if (GETPOST('delete_also_medias', 'alpha') == 'on') {
  1155. $pathofwebsitemedias = DOL_DATA_ROOT.'/medias/image/'.$object->ref;
  1156. dol_delete_dir_recursive($pathofwebsitemedias);
  1157. }
  1158. }
  1159. if (!$error) {
  1160. $db->commit();
  1161. setEventMessages($langs->trans("SiteDeleted", $object->ref), null, 'mesgs');
  1162. header("Location: ".$_SERVER["PHP_SELF"].'?id='.$object->id);
  1163. exit;
  1164. } else {
  1165. $db->rollback();
  1166. setEventMessages($object->error, $object->errors, 'errors');
  1167. }
  1168. }
  1169. // Delete page (from website page menu)
  1170. if (GETPOSTISSET('pageid') && $action == 'delete' && $permissiontodelete && !GETPOST('file_manager')) {
  1171. $error = 0;
  1172. $db->begin();
  1173. $res = $object->fetch(0, $websitekey);
  1174. $website = $object;
  1175. $res = $objectpage->fetch($pageid, $object->id);
  1176. if ($res > 0) {
  1177. $res = $objectpage->delete($user);
  1178. if ($res <= 0) {
  1179. $error++;
  1180. setEventMessages($objectpage->error, $objectpage->errors, 'errors');
  1181. }
  1182. }
  1183. if (!$error) {
  1184. $db->commit();
  1185. setEventMessages($langs->trans("PageDeleted", $objectpage->pageurl, $websitekey), null, 'mesgs');
  1186. header("Location: ".$_SERVER["PHP_SELF"].'?website='.$websitekey);
  1187. exit;
  1188. } else {
  1189. $db->rollback();
  1190. dol_print_error($db);
  1191. }
  1192. }
  1193. // Delete page (from menu search)
  1194. if (!GETPOSTISSET('pageid')) {
  1195. $objectclass = 'WebsitePage';
  1196. // Add part of code from actions_massactions.inc.php
  1197. // Delete record from mass action (massaction = 'delete' for direct delete, action/confirm='delete'/'yes' with a confirmation step before)
  1198. if (!$error && ($massaction == 'delete' || ($action == 'delete' && $confirm == 'yes')) && $permissiontodelete) {
  1199. $db->begin();
  1200. $objecttmp = new $objectclass($db);
  1201. $nbok = 0;
  1202. foreach ($toselect as $toselectid) {
  1203. $result = $objecttmp->fetch($toselectid);
  1204. if ($result > 0) {
  1205. $result = $objecttmp->delete($user);
  1206. if ($result <= 0) {
  1207. setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
  1208. $error++;
  1209. break;
  1210. } else {
  1211. $nbok++;
  1212. }
  1213. } else {
  1214. setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
  1215. $error++;
  1216. break;
  1217. }
  1218. }
  1219. if (!$error) {
  1220. if ($nbok > 1) {
  1221. setEventMessages($langs->trans("RecordsDeleted", $nbok), null, 'mesgs');
  1222. } else {
  1223. setEventMessages($langs->trans("RecordDeleted", $nbok), null, 'mesgs');
  1224. }
  1225. $db->commit();
  1226. } else {
  1227. $db->rollback();
  1228. }
  1229. //var_dump($listofobjectthirdparties);exit;
  1230. }
  1231. if ($action == 'delete') {
  1232. $mode = 'replacesite';
  1233. $action = 'replacesite';
  1234. $containertype = GETPOST('optioncontainertype', 'aZ09') != '-1' ? GETPOST('optioncontainertype', 'aZ09') : '';
  1235. $langcode = GETPOST('optionlanguage', 'aZ09');
  1236. $otherfilters = array();
  1237. if (GETPOST('optioncategory', 'int') > 0) {
  1238. $otherfilters['category'] = GETPOST('optioncategory', 'int');
  1239. }
  1240. $listofpages = getPagesFromSearchCriterias($containertype, $algo, $searchkey, 1000, $sortfield, $sortorder, $langcode, $otherfilters);
  1241. }
  1242. }
  1243. // Update css site properties. Re-generates also the wrapper.
  1244. if ($action == 'updatecss' && $usercanedit) {
  1245. // If we tried to reload another site/page, we stay on editcss mode.
  1246. if (GETPOST('refreshsite') || GETPOST('refreshsite_x') || GETPOST('refreshsite.x') || GETPOST('refreshpage') || GETPOST('refreshpage_x') || GETPOST('refreshpage.x')) {
  1247. $action = 'editcss';
  1248. } else {
  1249. $res = $object->fetch(0, $websitekey);
  1250. $website = $object;
  1251. if (GETPOSTISSET('virtualhost')) {
  1252. $tmpvirtualhost = preg_replace('/\/$/', '', GETPOST('virtualhost', 'alpha'));
  1253. if ($tmpvirtualhost && !preg_match('/^http/', $tmpvirtualhost)) {
  1254. $error++;
  1255. setEventMessages($langs->trans('ErrorURLMustStartWithHttp', $langs->transnoentitiesnoconv("VirtualHost")), null, 'errors');
  1256. $action = 'editcss';
  1257. }
  1258. if (!$error) {
  1259. $arrayotherlang = explode(',', GETPOST('WEBSITE_OTHERLANG', 'alphanohtml'));
  1260. foreach ($arrayotherlang as $key => $val) {
  1261. // It possible we have empty val here if postparam WEBSITE_OTHERLANG is empty or set like this : 'en,,sv' or 'en,sv,'
  1262. if (empty(trim($val))) continue;
  1263. $arrayotherlang[$key] = substr(trim($val), 0, 2); // Kept short language code only
  1264. }
  1265. $object->virtualhost = $tmpvirtualhost;
  1266. $object->lang = GETPOST('WEBSITE_LANG', 'aZ09');
  1267. $object->otherlang = join(',', $arrayotherlang);
  1268. $object->use_manifest = GETPOSTINT('use_manifest');
  1269. $result = $object->update($user);
  1270. if ($result < 0) {
  1271. $error++;
  1272. setEventMessages($object->error, $object->errors, 'errors');
  1273. $action = 'editcss';
  1274. }
  1275. }
  1276. }
  1277. if (!$error) {
  1278. if (($_FILES['addedfile']["name"] != '')) {
  1279. $uploadfolder = $conf->website->dir_output.'/'.$websitekey;
  1280. if ($_FILES['addedfile']['type'] != 'image/png') {
  1281. $error++;
  1282. setEventMessages($langs->trans('ErrorFaviconType'), array(), 'errors');
  1283. }
  1284. $filetoread = realpath(dol_osencode($_FILES['addedfile']['tmp_name']));
  1285. $filesize = getimagesize($filetoread);
  1286. if ($filesize[0] != $filesize[1]) {
  1287. $error++;
  1288. setEventMessages($langs->trans('ErrorFaviconMustBeASquaredImage'), array(), 'errors');
  1289. }
  1290. if (! $error && ($filesize[0] != 16 && $filesize[0] != 32 && $filesize[0] != 64)) {
  1291. $error++;
  1292. setEventMessages($langs->trans('ErrorFaviconSize'), array(), 'errors');
  1293. }
  1294. if (!$error) {
  1295. dol_add_file_process($uploadfolder, 1, 0, 'addedfile', 'favicon.png');
  1296. }
  1297. }
  1298. if ($error) {
  1299. if (!GETPOSTISSET('updateandstay')) { // If we click on "Save And Stay", we don not make the redirect
  1300. $action = 'preview';
  1301. if ($backtopage) {
  1302. $backtopage = preg_replace('/searchstring=[^&]*/', '', $backtopage); // Clean backtopage url
  1303. header("Location: ".$backtopage);
  1304. exit;
  1305. }
  1306. } else {
  1307. $action = 'editcss';
  1308. }
  1309. }
  1310. }
  1311. if (!$error) {
  1312. // Save master.inc.php file
  1313. dol_syslog("Save master file ".$filemaster);
  1314. dol_mkdir($pathofwebsite);
  1315. // Now generate the master.inc.php page
  1316. $result = dolSaveMasterFile($filemaster);
  1317. if (!$result) {
  1318. $error++;
  1319. setEventMessages('Failed to write file '.$filemaster, null, 'errors');
  1320. }
  1321. $dataposted = trim(GETPOST('WEBSITE_HTML_HEADER', 'none'));
  1322. $dataposted = preg_replace(array('/<html>\n*/ims', '/<\/html>\n*/ims'), array('', ''), $dataposted);
  1323. $dataposted = str_replace('<?=', '<?php', $dataposted);
  1324. // Html header file
  1325. $phpfullcodestringold = '';
  1326. $phpfullcodestring = dolKeepOnlyPhpCode($dataposted);
  1327. // Security analysis
  1328. $errorphpcheck = checkPHPCode($phpfullcodestringold, $phpfullcodestring); // Contains the setEventMessages
  1329. if (!$errorphpcheck) {
  1330. $htmlheadercontent = '';
  1331. /* We disable php code since htmlheader is never executed as an include but only read by fgets_content.
  1332. $htmlheadercontent.= "<?php // BEGIN PHP\n";
  1333. $htmlheadercontent.= '$websitekey=basename(__DIR__);'."\n";
  1334. $htmlheadercontent.= "if (! defined('USEDOLIBARRSERVER') && ! defined('USEDOLIBARREDITOR')) { require_once './master.inc.php'; } // Load env if not already loaded"."\n";
  1335. $htmlheadercontent.= "require_once DOL_DOCUMENT_ROOT.'/core/lib/website.lib.php';\n";
  1336. $htmlheadercontent.= "require_once DOL_DOCUMENT_ROOT.'/core/website.inc.php';\n";
  1337. $htmlheadercontent.= "ob_start();\n";
  1338. // $htmlheadercontent.= "header('Content-type: text/html');\n"; // Not required. htmlheader.html is never call as a standalone page
  1339. $htmlheadercontent.= "// END PHP ?>\n";*/
  1340. $htmlheadercontent .= $dataposted."\n";
  1341. /*$htmlheadercontent.= "\n".'<?php // BEGIN PHP'."\n";
  1342. $htmlheadercontent.= '$tmp = ob_get_contents(); ob_end_clean(); dolWebsiteOutput($tmp);'."\n";
  1343. $htmlheadercontent.= "// END PHP ?>"."\n";*/
  1344. $result = dolSaveHtmlHeader($filehtmlheader, $htmlheadercontent);
  1345. if (!$result) {
  1346. $error++;
  1347. setEventMessages('Failed to write file '.$filehtmlheader, null, 'errors');
  1348. }
  1349. } else {
  1350. $error++;
  1351. }
  1352. $dataposted = trim(GETPOST('WEBSITE_CSS_INLINE', 'none'));
  1353. $dataposted = str_replace('<?=', '<?php', $dataposted);
  1354. // Css file
  1355. $phpfullcodestringold = '';
  1356. $phpfullcodestring = dolKeepOnlyPhpCode($dataposted);
  1357. // Security analysis
  1358. $errorphpcheck = checkPHPCode($phpfullcodestringold, $phpfullcodestring); // Contains the setEventMessages
  1359. if (!$errorphpcheck) {
  1360. $csscontent = '';
  1361. $csscontent .= "<?php // BEGIN PHP\n";
  1362. $csscontent .= '$websitekey=basename(__DIR__);'."\n";
  1363. $csscontent .= "if (! defined('USEDOLIBARRSERVER') && ! defined('USEDOLIBARREDITOR')) { require_once __DIR__.'/master.inc.php'; } // Load env if not already loaded\n"; // For the css, we need to set path of master using the dirname of css file.
  1364. $csscontent .= "require_once DOL_DOCUMENT_ROOT.'/core/lib/website.lib.php';\n";
  1365. $csscontent .= "require_once DOL_DOCUMENT_ROOT.'/core/website.inc.php';\n";
  1366. $csscontent .= "ob_start();\n";
  1367. $csscontent .= "if (! headers_sent()) { /* because file is included inline when in edit mode and we don't want warning */ \n";
  1368. $csscontent .= "header('Cache-Control: max-age=3600, public, must-revalidate');\n";
  1369. $csscontent .= "header('Content-type: text/css');\n";
  1370. $csscontent .= "}\n";
  1371. $csscontent .= "// END PHP ?>\n";
  1372. $csscontent .= $dataposted."\n";
  1373. $csscontent .= '<?php // BEGIN PHP'."\n";
  1374. $csscontent .= '$tmp = ob_get_contents(); ob_end_clean(); dolWebsiteOutput($tmp, "css");'."\n";
  1375. $csscontent .= "// END PHP ?>\n";
  1376. dol_syslog("Save css content into ".$filecss);
  1377. $result = dolSaveCssFile($filecss, $csscontent);
  1378. if (!$result) {
  1379. $error++;
  1380. setEventMessages('Failed to write file '.$filecss, null, 'errors');
  1381. }
  1382. } else {
  1383. $error++;
  1384. }
  1385. $dataposted = trim(GETPOST('WEBSITE_JS_INLINE', 'none'));
  1386. $dataposted = str_replace('<?=', '<?php', $dataposted);
  1387. // Js file
  1388. $phpfullcodestringold = '';
  1389. $phpfullcodestring = dolKeepOnlyPhpCode($dataposted);
  1390. // Security analysis
  1391. $errorphpcheck = checkPHPCode($phpfullcodestringold, $phpfullcodestring); // Contains the setEventMessages
  1392. if (!$errorphpcheck) {
  1393. $jscontent = '';
  1394. $jscontent .= "<?php // BEGIN PHP\n";
  1395. $jscontent .= '$websitekey=basename(__DIR__);'."\n";
  1396. $jscontent .= "if (! defined('USEDOLIBARRSERVER') && ! defined('USEDOLIBARREDITOR')) { require_once __DIR__.'/master.inc.php'; } // Load env if not already loaded\n"; // For the css, we need to set path of master using the dirname of css file.
  1397. $jscontent .= "require_once DOL_DOCUMENT_ROOT.'/core/lib/website.lib.php';\n";
  1398. $jscontent .= "require_once DOL_DOCUMENT_ROOT.'/core/website.inc.php';\n";
  1399. $jscontent .= "ob_start();\n";
  1400. $jscontent .= "header('Cache-Control: max-age=3600, public, must-revalidate');\n";
  1401. $jscontent .= "header('Content-type: application/javascript');\n";
  1402. $jscontent .= "// END PHP ?>\n";
  1403. $jscontent .= $dataposted."\n";
  1404. $jscontent .= '<?php // BEGIN PHP'."\n";
  1405. $jscontent .= '$tmp = ob_get_contents(); ob_end_clean(); dolWebsiteOutput($tmp, "js");'."\n";
  1406. $jscontent .= "// END PHP ?>\n";
  1407. $result = dolSaveJsFile($filejs, $jscontent);
  1408. if (!$result) {
  1409. $error++;
  1410. setEventMessages('Failed to write file '.$filejs, null, 'errors');
  1411. }
  1412. } else {
  1413. $error++;
  1414. }
  1415. $dataposted = trim(GETPOST('WEBSITE_ROBOT', 'restricthtml'));
  1416. $dataposted = str_replace('<?=', '<?php', $dataposted);
  1417. // Robot file
  1418. $phpfullcodestringold = '';
  1419. $phpfullcodestring = dolKeepOnlyPhpCode($dataposted);
  1420. // Security analysis
  1421. $errorphpcheck = checkPHPCode($phpfullcodestringold, $phpfullcodestring); // Contains the setEventMessages
  1422. if (!$errorphpcheck) {
  1423. $robotcontent = '';
  1424. /*$robotcontent.= "<?php // BEGIN PHP\n";
  1425. $robotcontent.= '$websitekey=basename(__DIR__);'."\n";
  1426. $robotcontent.= "if (! defined('USEDOLIBARRSERVER') && ! defined('USEDOLIBARREDITOR')) { require_once './master.inc.php'; } // Load env if not already loaded"."\n";
  1427. $robotcontent.= "require_once DOL_DOCUMENT_ROOT.'/core/lib/website.lib.php';\n";
  1428. $robotcontent.= "require_once DOL_DOCUMENT_ROOT.'/core/website.inc.php';\n";
  1429. $robotcontent.= "ob_start();\n";
  1430. $robotcontent.= "header('Cache-Control: max-age=3600, public, must-revalidate');\n";
  1431. $robotcontent.= "header('Content-type: text/css');\n";
  1432. $robotcontent.= "// END PHP ?>\n";*/
  1433. $robotcontent .= $dataposted."\n";
  1434. /*$robotcontent.= "\n".'<?php // BEGIN PHP'."\n";
  1435. $robotcontent.= '$tmp = ob_get_contents(); ob_end_clean(); dolWebsiteOutput($tmp, "robot");'."\n";
  1436. $robotcontent.= "// END PHP ?>"."\n";*/
  1437. $result = dolSaveRobotFile($filerobot, $robotcontent);
  1438. if (!$result) {
  1439. $error++;
  1440. setEventMessages('Failed to write file '.$filerobot, null, 'errors');
  1441. }
  1442. } else {
  1443. $error++;
  1444. }
  1445. $dataposted = trim(GETPOST('WEBSITE_HTACCESS', 'restricthtml'));
  1446. $dataposted = str_replace('<?=', '<?php', $dataposted);
  1447. // Htaccess file
  1448. $phpfullcodestringold = '';
  1449. $phpfullcodestring = dolKeepOnlyPhpCode($dataposted);
  1450. // Security analysis
  1451. $errorphpcheck = checkPHPCode($phpfullcodestringold, $phpfullcodestring); // Contains the setEventMessages
  1452. if (!$errorphpcheck) {
  1453. $htaccesscontent = '';
  1454. $htaccesscontent .= $dataposted."\n";
  1455. $result = dolSaveHtaccessFile($filehtaccess, $htaccesscontent);
  1456. if (!$result) {
  1457. $error++;
  1458. setEventMessages('Failed to write file '.$filehtaccess, null, 'errors');
  1459. }
  1460. } else {
  1461. $error++;
  1462. }
  1463. $dataposted = trim(GETPOST('WEBSITE_MANIFEST_JSON', 'none'));
  1464. $dataposted = str_replace('<?=', '<?php', $dataposted);
  1465. // Manifest.json file
  1466. $phpfullcodestringold = '';
  1467. $phpfullcodestring = dolKeepOnlyPhpCode($dataposted);
  1468. // Security analysis
  1469. $errorphpcheck = checkPHPCode($phpfullcodestringold, $phpfullcodestring); // Contains the setEventMessages
  1470. if (!$errorphpcheck) {
  1471. $manifestjsoncontent = '';
  1472. $manifestjsoncontent .= "<?php // BEGIN PHP\n";
  1473. $manifestjsoncontent .= '$websitekey=basename(__DIR__);'."\n";
  1474. $manifestjsoncontent .= "if (! defined('USEDOLIBARRSERVER') && ! defined('USEDOLIBARREDITOR')) { require_once __DIR__.'/master.inc.php'; } // Load env if not already loaded\n"; // For the css, we need to set path of master using the dirname of css file.
  1475. $manifestjsoncontent .= "require_once DOL_DOCUMENT_ROOT.'/core/lib/website.lib.php';\n";
  1476. $manifestjsoncontent .= "require_once DOL_DOCUMENT_ROOT.'/core/website.inc.php';\n";
  1477. $manifestjsoncontent .= "ob_start();\n";
  1478. $manifestjsoncontent .= "header('Cache-Control: max-age=3600, public, must-revalidate');\n";
  1479. $manifestjsoncontent .= "header('Content-type: application/manifest+json');\n";
  1480. $manifestjsoncontent .= "// END PHP ?>\n";
  1481. $manifestjsoncontent .= $dataposted."\n";
  1482. $manifestjsoncontent .= '<?php // BEGIN PHP'."\n";
  1483. $manifestjsoncontent .= '$tmp = ob_get_contents(); ob_end_clean(); dolWebsiteOutput($tmp, "manifest");'."\n";
  1484. $manifestjsoncontent .= "// END PHP ?>\n";
  1485. $result = dolSaveManifestJson($filemanifestjson, $manifestjsoncontent);
  1486. if (!$result) {
  1487. $error++;
  1488. setEventMessages('Failed to write file '.$filemanifestjson, null, 'errors');
  1489. }
  1490. } else {
  1491. $error++;
  1492. }
  1493. $dataposted = trim(GETPOST('WEBSITE_README', 'restricthtml'));
  1494. $dataposted = str_replace('<?=', '<?php', $dataposted);
  1495. // README.md file
  1496. $phpfullcodestringold = '';
  1497. $phpfullcodestring = dolKeepOnlyPhpCode($dataposted);
  1498. // Security analysis
  1499. $errorphpcheck = checkPHPCode($phpfullcodestringold, $phpfullcodestring); // Contains the setEventMessages
  1500. if (!$errorphpcheck) {
  1501. $readmecontent = '';
  1502. /*$readmecontent.= "<?php // BEGIN PHP\n";
  1503. $readmecontent.= '$websitekey=basename(__DIR__);'."\n";
  1504. $readmecontent.= "if (! defined('USEDOLIBARRSERVER') && ! defined('USEDOLIBARREDITOR')) { require_once __DIR__.'/master.inc.php'; } // Load env if not already loaded"."\n"; // For the css, we need to set path of master using the dirname of css file.
  1505. $readmecontent.= "require_once DOL_DOCUMENT_ROOT.'/core/lib/website.lib.php';\n";
  1506. $readmecontent.= "require_once DOL_DOCUMENT_ROOT.'/core/website.inc.php';\n";
  1507. $readmecontent.= "ob_start();\n";
  1508. $readmecontent.= "header('Cache-Control: max-age=3600, public, must-revalidate');\n";
  1509. $readmecontent.= "header('Content-type: application/manifest+json');\n";
  1510. $readmecontent.= "// END PHP ?>\n";*/
  1511. $readmecontent .= $dataposted."\n";
  1512. /*$readmecontent.= '<?php // BEGIN PHP'."\n";
  1513. $readmecontent.= '$tmp = ob_get_contents(); ob_end_clean(); dolWebsiteOutput($tmp, "manifest");'."\n";
  1514. $readmecontent.= "// END PHP ?>"."\n";*/
  1515. $result = dolSaveReadme($filereadme, $readmecontent);
  1516. if (!$result) {
  1517. $error++;
  1518. setEventMessages('Failed to write file '.$filereadme, null, 'errors');
  1519. }
  1520. } else {
  1521. $error++;
  1522. }
  1523. $dataposted = trim(GETPOST('WEBSITE_LICENSE', 'restricthtml'));
  1524. $dataposted = str_replace('<?=', '<?php', $dataposted);
  1525. // LICENSE file
  1526. $phpfullcodestringold = '';
  1527. $phpfullcodestring = dolKeepOnlyPhpCode($dataposted);
  1528. // Security analysis
  1529. $errorphpcheck = checkPHPCode($phpfullcodestringold, $phpfullcodestring); // Contains the setEventMessages
  1530. if (!$errorphpcheck) {
  1531. $licensecontent = '';
  1532. /*$readmecontent.= "<?php // BEGIN PHP\n";
  1533. $readmecontent.= '$websitekey=basename(__DIR__);'."\n";
  1534. $readmecontent.= "if (! defined('USEDOLIBARRSERVER') && ! defined('USEDOLIBARREDITOR')) { require_once __DIR__.'/master.inc.php'; } // Load env if not already loaded"."\n"; // For the css, we need to set path of master using the dirname of css file.
  1535. $readmecontent.= "require_once DOL_DOCUMENT_ROOT.'/core/lib/website.lib.php';\n";
  1536. $readmecontent.= "require_once DOL_DOCUMENT_ROOT.'/core/website.inc.php';\n";
  1537. $readmecontent.= "ob_start();\n";
  1538. $readmecontent.= "header('Cache-Control: max-age=3600, public, must-revalidate');\n";
  1539. $readmecontent.= "header('Content-type: application/manifest+json');\n";
  1540. $readmecontent.= "// END PHP ?>\n";*/
  1541. $licensecontent .= $dataposted."\n";
  1542. /*$readmecontent.= '<?php // BEGIN PHP'."\n";
  1543. $readmecontent.= '$tmp = ob_get_contents(); ob_end_clean(); dolWebsiteOutput($tmp, "manifest");'."\n";
  1544. $readmecontent.= "// END PHP ?>"."\n";*/
  1545. $result = dolSaveLicense($filelicense, $licensecontent);
  1546. if (!$result) {
  1547. $error++;
  1548. setEventMessages('Failed to write file '.$filelicense, null, 'errors');
  1549. }
  1550. } else {
  1551. $error++;
  1552. }
  1553. // Save wrapper.php
  1554. $result = dolSaveIndexPage($pathofwebsite, '', '', $filewrapper, $object);
  1555. // Message if no error
  1556. if (!$error) {
  1557. setEventMessages($langs->trans("Saved"), null, 'mesgs');
  1558. }
  1559. if (!GETPOSTISSET('updateandstay')) { // If we click on "Save And Stay", we don not make the redirect
  1560. $action = 'preview';
  1561. if ($backtopage) {
  1562. $backtopage = preg_replace('/searchstring=[^&]*/', '', $backtopage); // Clean backtopage url
  1563. header("Location: ".$backtopage);
  1564. exit;
  1565. }
  1566. } else {
  1567. $action = 'editcss';
  1568. }
  1569. }
  1570. }
  1571. }
  1572. // Update page
  1573. if ($action == 'setashome' && $usercanedit) {
  1574. $db->begin();
  1575. $object->fetch(0, $websitekey);
  1576. $website = $object;
  1577. $object->fk_default_home = $pageid;
  1578. $res = $object->update($user);
  1579. if (! ($res > 0)) {
  1580. $error++;
  1581. setEventMessages($object->error, $object->errors, 'errors');
  1582. }
  1583. if (!$error) {
  1584. $db->commit();
  1585. $filetpl = $pathofwebsite.'/page'.$pageid.'.tpl.php';
  1586. // Generate the index.php page to be the home page
  1587. $result = dolSaveIndexPage($pathofwebsite, $fileindex, $filetpl, $filewrapper, $object);
  1588. if ($result) {
  1589. setEventMessages($langs->trans("Saved"), null, 'mesgs');
  1590. } else {
  1591. setEventMessages('Failed to write file '.$fileindex, null, 'errors');
  1592. }
  1593. $action = 'preview';
  1594. } else {
  1595. $db->rollback();
  1596. }
  1597. }
  1598. // Update page properties (meta)
  1599. if ($action == 'updatemeta' && $usercanedit) {
  1600. $db->begin();
  1601. $result = $object->fetch(0, $websitekey);
  1602. $website = $object;
  1603. $objectpage->fk_website = $object->id;
  1604. // Check parameters
  1605. if (!preg_match('/^[a-z0-9\-\_]+$/i', GETPOST('WEBSITE_PAGENAME', 'alpha'))) {
  1606. $error++;
  1607. $langs->load("errors");
  1608. setEventMessages($langs->transnoentities("ErrorFieldCanNotContainSpecialCharacters", $langs->transnoentities('WEBSITE_PAGENAME')), null, 'errors');
  1609. $action = 'editmeta';
  1610. }
  1611. $res = $objectpage->fetch($pageid, $object->id);
  1612. if ($res <= 0) {
  1613. $error++;
  1614. setEventMessages('Page not found '.$objectpage->error, $objectpage->errors, 'errors');
  1615. }
  1616. // Check alias not exists
  1617. if (!$error && GETPOST('WEBSITE_PAGENAME', 'alpha')) {
  1618. $websitepagetemp = new WebsitePage($db);
  1619. $result = $websitepagetemp->fetch(-1 * $objectpage->id, $object->id, GETPOST('WEBSITE_PAGENAME', 'alpha'));
  1620. if ($result < 0) {
  1621. $error++;
  1622. $langs->load("errors");
  1623. setEventMessages($websitepagetemp->error, $websitepagetemp->errors, 'errors');
  1624. $action = 'editmeta';
  1625. }
  1626. if ($result > 0) {
  1627. $error++;
  1628. $langs->load("errors");
  1629. setEventMessages($langs->trans("ErrorAPageWithThisNameOrAliasAlreadyExists", $websitepagetemp->pageurl), null, 'errors');
  1630. $action = 'editmeta';
  1631. }
  1632. }
  1633. $newaliasnames = '';
  1634. if (!$error && GETPOST('WEBSITE_ALIASALT', 'alpha')) {
  1635. $arrayofaliastotest = explode(',', str_replace(array('<', '>'), '', GETPOST('WEBSITE_ALIASALT', 'alpha')));
  1636. $websitepagetemp = new WebsitePage($db);
  1637. foreach ($arrayofaliastotest as $aliastotest) {
  1638. $aliastotest = trim(preg_replace('/\.php$/i', '', $aliastotest));
  1639. // Disallow alias name pageX (already used to save the page with id)
  1640. if (preg_match('/^page\d+/i', $aliastotest)) {
  1641. $error++;
  1642. $langs->load("errors");
  1643. setEventMessages("Alias name 'pageX' is not allowed", null, 'errors');
  1644. $action = 'editmeta';
  1645. break;
  1646. } else {
  1647. $result = $websitepagetemp->fetch(-1 * $objectpage->id, $object->id, $aliastotest);
  1648. if ($result < 0) {
  1649. $error++;
  1650. $langs->load("errors");
  1651. setEventMessages($websitepagetemp->error, $websitepagetemp->errors, 'errors');
  1652. $action = 'editmeta';
  1653. break;
  1654. }
  1655. if ($result > 0) {
  1656. $error++;
  1657. $langs->load("errors");
  1658. setEventMessages($langs->trans("ErrorAPageWithThisNameOrAliasAlreadyExists", $websitepagetemp->pageurl), null, 'errors');
  1659. $action = 'editmeta';
  1660. break;
  1661. }
  1662. $newaliasnames .= ($newaliasnames ? ', ' : '').$aliastotest;
  1663. }
  1664. }
  1665. }
  1666. if (!$error) {
  1667. $objectpage->old_object = clone $objectpage;
  1668. $objectpage->title = str_replace(array('<', '>'), '', GETPOST('WEBSITE_TITLE', 'alphanohtml'));
  1669. $objectpage->type_container = GETPOST('WEBSITE_TYPE_CONTAINER', 'aZ09');
  1670. $objectpage->pageurl = GETPOST('WEBSITE_PAGENAME', 'alpha');
  1671. $objectpage->aliasalt = $newaliasnames;
  1672. $objectpage->lang = GETPOST('WEBSITE_LANG', 'aZ09');
  1673. $objectpage->otherlang = GETPOST('WEBSITE_OTHERLANG', 'aZ09comma');
  1674. $objectpage->description = str_replace(array('<', '>'), '', GETPOST('WEBSITE_DESCRIPTION', 'alphanohtml'));
  1675. $objectpage->image = GETPOST('WEBSITE_IMAGE', 'alpha');
  1676. $objectpage->keywords = str_replace(array('<', '>'), '', GETPOST('WEBSITE_KEYWORDS', 'alphanohtml'));
  1677. $objectpage->allowed_in_frames = GETPOST('WEBSITE_ALLOWED_IN_FRAMES', 'aZ09');
  1678. $objectpage->htmlheader = trim(GETPOST('htmlheader', 'none'));
  1679. $objectpage->fk_page = (GETPOST('pageidfortranslation', 'int') > 0 ? GETPOST('pageidfortranslation', 'int') : 0);
  1680. $objectpage->author_alias = trim(GETPOST('WEBSITE_AUTHORALIAS', 'alphanohtml'));
  1681. $objectpage->object_type = GETPOST('WEBSITE_OBJECTCLASS', 'alpha');
  1682. $objectpage->fk_object = GETPOST('WEBSITE_OBJECTID', 'aZ09');
  1683. $newdatecreation = dol_mktime(GETPOST('datecreationhour', 'int'), GETPOST('datecreationmin', 'int'), GETPOST('datecreationsec', 'int'), GETPOST('datecreationmonth', 'int'), GETPOST('datecreationday', 'int'), GETPOST('datecreationyear', 'int'));
  1684. if ($newdatecreation) {
  1685. $objectpage->date_creation = $newdatecreation;
  1686. }
  1687. $res = $objectpage->update($user);
  1688. if (!($res > 0)) {
  1689. $langs->load("errors");
  1690. if ($db->lasterrno == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
  1691. $error++;
  1692. $langs->load("errors");
  1693. setEventMessages($langs->trans("ErrorAPageWithThisNameOrAliasAlreadyExists"), null, 'errors');
  1694. $action = 'editmeta';
  1695. } else {
  1696. $error++;
  1697. $langs->load("errors");
  1698. setEventMessages($objectpage->error, $objectpage->errors, 'errors');
  1699. $action = 'editmeta';
  1700. }
  1701. }
  1702. }
  1703. if (!$error) {
  1704. // Website categories association
  1705. $categoriesarray = GETPOST('categories', 'array');
  1706. $result = $objectpage->setCategories($categoriesarray);
  1707. if ($result < 0) {
  1708. $error++;
  1709. setEventMessages($object->error, $object->errors, 'errors');
  1710. }
  1711. }
  1712. if (!$error) {
  1713. $db->commit();
  1714. } else {
  1715. $db->rollback();
  1716. }
  1717. if (!$error) {
  1718. $filemaster = $pathofwebsite.'/master.inc.php';
  1719. $fileoldalias = $pathofwebsite.'/'.$objectpage->old_object->pageurl.'.php';
  1720. $filealias = $pathofwebsite.'/'.$objectpage->pageurl.'.php';
  1721. dol_mkdir($pathofwebsite);
  1722. // Now generate the master.inc.php page
  1723. $result = dolSaveMasterFile($filemaster);
  1724. if (!$result) {
  1725. setEventMessages('Failed to write file '.$filemaster, null, 'errors');
  1726. }
  1727. // Now delete the alias.php page
  1728. if (!empty($fileoldalias)) {
  1729. dol_syslog("We delete old alias page name=".$fileoldalias." to build a new alias page=".$filealias);
  1730. dol_delete_file($fileoldalias);
  1731. // Delete also pages into language subdirectories
  1732. if (empty($objectpage->lang) || !in_array($objectpage->lang, explode(',', $object->otherlang))) {
  1733. $dirname = dirname($fileoldalias);
  1734. $filename = basename($fileoldalias);
  1735. $sublangs = explode(',', $object->otherlang);
  1736. foreach ($sublangs as $sublang) {
  1737. // Under certain conditions $sublang can be an empty string
  1738. // ($object->otherlang with empty string or with string like this 'en,,sv')
  1739. // if is the case we try to re-delete the main alias file. Avoid it.
  1740. if (empty(trim($sublang))) continue;
  1741. $fileoldaliassub = $dirname.'/'.$sublang.'/'.$filename;
  1742. dol_delete_file($fileoldaliassub);
  1743. }
  1744. }
  1745. }
  1746. // Now delete the alternative alias.php pages
  1747. if (!empty($objectpage->old_object->aliasalt)) {
  1748. $tmpaltaliases = explode(',', $objectpage->old_object->aliasalt);
  1749. if (is_array($tmpaltaliases)) {
  1750. foreach ($tmpaltaliases as $tmpaliasalt) {
  1751. dol_syslog("We delete old alt alias pages name=".trim($tmpaliasalt));
  1752. dol_delete_file($pathofwebsite.'/'.trim($tmpaliasalt).'.php');
  1753. // Delete also pages into language subdirectories
  1754. if (empty($objectpage->lang) || !in_array($objectpage->lang, explode(',', $object->otherlang))) {
  1755. $dirname = dirname($pathofwebsite.'/'.trim($tmpaliasalt).'.php');
  1756. $filename = basename($pathofwebsite.'/'.trim($tmpaliasalt).'.php');
  1757. $sublangs = explode(',', $object->otherlang);
  1758. foreach ($sublangs as $sublang) {
  1759. // Under certain conditions $ sublang can be an empty string
  1760. // ($object->otherlang with empty string or with string like this 'en,,sv')
  1761. // if is the case we try to re-delete the main alias file. Avoid it.
  1762. if (empty(trim($sublang))) continue;
  1763. $fileoldaliassub = $dirname.'/'.$sublang.'/'.$filename;
  1764. dol_delete_file($fileoldaliassub);
  1765. }
  1766. }
  1767. }
  1768. }
  1769. }
  1770. // Save page main alias
  1771. $result = dolSavePageAlias($filealias, $object, $objectpage);
  1772. if (!$result) {
  1773. setEventMessages('Failed to write file '.$filealias, null, 'errors');
  1774. }
  1775. // Save alt aliases
  1776. if (!empty($objectpage->aliasalt)) {
  1777. $tmpaltaliases = explode(',', $objectpage->aliasalt);
  1778. if (is_array($tmpaltaliases)) {
  1779. foreach ($tmpaltaliases as $tmpaliasalt) {
  1780. if (trim($tmpaliasalt)) {
  1781. $filealias = $pathofwebsite.'/'.trim($tmpaliasalt).'.php';
  1782. $result = dolSavePageAlias($filealias, $object, $objectpage);
  1783. if (!$result) {
  1784. setEventMessages('Failed to write file '.basename($filealias), null, 'errors');
  1785. }
  1786. }
  1787. }
  1788. }
  1789. }
  1790. // Save page of content
  1791. $result = dolSavePageContent($filetpl, $object, $objectpage, 1);
  1792. if ($result) {
  1793. setEventMessages($langs->trans("Saved"), null, 'mesgs');
  1794. if (!GETPOSTISSET('updateandstay')) { // If we click on "Save And Stay", we do not make the redirect
  1795. //header("Location: ".$_SERVER["PHP_SELF"].'?website='.$websitekey.'&pageid='.$pageid);
  1796. //exit;
  1797. $action = 'preview';
  1798. } else {
  1799. $action = 'editmeta';
  1800. }
  1801. } else {
  1802. setEventMessages('Failed to write file '.$filetpl, null, 'errors');
  1803. //header("Location: ".$_SERVER["PHP_SELF"].'?website='.$websitekey.'&pageid='.$pageid);
  1804. //exit;
  1805. $action = 'preview';
  1806. }
  1807. }
  1808. }
  1809. // Update page
  1810. if ($usercanedit && (($action == 'updatesource' || $action == 'updatecontent' || $action == 'confirm_createfromclone' || $action == 'confirm_createpagefromclone')
  1811. || ($action == 'preview' && (GETPOST('refreshsite') || GETPOST('refreshpage') || GETPOST('preview'))))) {
  1812. $object->fetch(0, $websitekey);
  1813. $website = $object;
  1814. if ($action == 'confirm_createfromclone') {
  1815. $db->begin();
  1816. $objectnew = new Website($db);
  1817. $result = $objectnew->createFromClone($user, GETPOST('id', 'int'), GETPOST('siteref', 'aZ09'), (GETPOST('newlang', 'aZ09') ?GETPOST('newlang', 'aZ09') : ''));
  1818. if ($result < 0) {
  1819. $error++;
  1820. setEventMessages($objectnew->error, $objectnew->errors, 'errors');
  1821. $action = 'preview';
  1822. $db->rollback();
  1823. } else {
  1824. $object = $objectnew;
  1825. $id = $object->id;
  1826. $pageid = $object->fk_default_home;
  1827. $websitekey = GETPOST('siteref', 'aZ09');
  1828. $db->commit();
  1829. }
  1830. }
  1831. if ($action == 'confirm_createpagefromclone') {
  1832. $istranslation = (GETPOST('is_a_translation', 'aZ09') == 'on' ? 1 : 0);
  1833. // Protection if it is a translation page
  1834. if ($istranslation) {
  1835. if (GETPOST('newlang', 'aZ09') == $objectpage->lang || !GETPOST('newlang', 'aZ09')) {
  1836. $error++;
  1837. setEventMessages($langs->trans("LanguageMustNotBeSameThanClonedPage"), null, 'errors');
  1838. $action = 'preview';
  1839. }
  1840. if (GETPOST('newwebsite', 'int') != $object->id) {
  1841. $error++;
  1842. setEventMessages($langs->trans("WebsiteMustBeSameThanClonedPageIfTranslation"), null, 'errors');
  1843. $action = 'preview';
  1844. }
  1845. }
  1846. if (!$error) {
  1847. $db->begin();
  1848. $newwebsiteid = GETPOST('newwebsite', 'int');
  1849. $pathofwebsitenew = $pathofwebsite;
  1850. $tmpwebsite = new Website($db);
  1851. if ($newwebsiteid > 0 && $newwebsiteid != $object->id) {
  1852. $tmpwebsite->fetch($newwebsiteid);
  1853. $pathofwebsitenew = $dolibarr_main_data_root.($conf->entity > 1 ? '/'.$conf->entity : '').'/website/'.$tmpwebsite->ref;
  1854. } else {
  1855. $tmpwebsite = $object;
  1856. }
  1857. $objectpage = new WebsitePage($db);
  1858. $resultpage = $objectpage->createFromClone($user, $pageid, GETPOST('newpageurl', 'aZ09'), (GETPOST('newlang', 'aZ09') ? GETPOST('newlang', 'aZ09') : ''), $istranslation, $newwebsiteid, GETPOST('newtitle', 'alphanohtml'));
  1859. if ($resultpage < 0) {
  1860. $error++;
  1861. setEventMessages($objectpage->error, $objectpage->errors, 'errors');
  1862. $action = 'createpagefromclone';
  1863. $db->rollback();
  1864. } else {
  1865. $filetpl = $pathofwebsitenew.'/page'.$resultpage->id.'.tpl.php';
  1866. $fileindex = $pathofwebsitenew.'/index.php';
  1867. $filewrapper = $pathofwebsitenew.'/wrapper.php';
  1868. //var_dump($pathofwebsitenew);
  1869. //var_dump($filetpl);
  1870. //exit;
  1871. dolSavePageContent($filetpl, $tmpwebsite, $resultpage, 1);
  1872. // Switch on the new page if web site of new page/container is same
  1873. if (empty($newwebsiteid) || $newwebsiteid == $object->id) {
  1874. $pageid = $resultpage->id;
  1875. }
  1876. $db->commit();
  1877. }
  1878. }
  1879. }
  1880. $res = 0;
  1881. if (!$error) {
  1882. // Check symlink to medias and restore it if ko
  1883. $pathtomedias = DOL_DATA_ROOT.'/medias';
  1884. $pathtomediasinwebsite = $pathofwebsite.'/medias';
  1885. if (!is_link(dol_osencode($pathtomediasinwebsite))) {
  1886. dol_syslog("Create symlink for ".$pathtomedias." into name ".$pathtomediasinwebsite);
  1887. dol_mkdir(dirname($pathtomediasinwebsite)); // To be sure dir for website exists
  1888. $result = symlink($pathtomedias, $pathtomediasinwebsite);
  1889. }
  1890. /*if (GETPOST('savevirtualhost') && $object->virtualhost != GETPOST('previewsite'))
  1891. {
  1892. $object->virtualhost = GETPOST('previewsite', 'alpha');
  1893. $object->update($user);
  1894. }*/
  1895. $objectpage->fk_website = $object->id;
  1896. if ($pageid > 0) {
  1897. $res = $objectpage->fetch($pageid);
  1898. } else {
  1899. $res = 0;
  1900. if ($object->fk_default_home > 0) {
  1901. $res = $objectpage->fetch($object->fk_default_home);
  1902. }
  1903. if (!($res > 0)) {
  1904. $res = $objectpage->fetch(0, $object->id);
  1905. }
  1906. }
  1907. }
  1908. if (!$error && $res > 0) {
  1909. if ($action == 'updatesource' || $action == 'updatecontent') {
  1910. $db->begin();
  1911. $phpfullcodestringold = dolKeepOnlyPhpCode($objectpage->content);
  1912. $objectpage->content = GETPOST('PAGE_CONTENT', 'none'); // any HTML content allowed
  1913. $phpfullcodestring = dolKeepOnlyPhpCode($objectpage->content);
  1914. // Security analysis (check PHP content and check permission website->writephp if php content is modified)
  1915. $error = checkPHPCode($phpfullcodestringold, $phpfullcodestring);
  1916. if ($error) {
  1917. if ($action == 'updatesource') {
  1918. $action = 'editsource';
  1919. }
  1920. if ($action == 'updatecontent') {
  1921. $action = 'editcontent';
  1922. }
  1923. }
  1924. // Clean data. We remove all the head section.
  1925. $objectpage->content = preg_replace('/<head>.*<\/head>/ims', '', $objectpage->content);
  1926. /* $objectpage->content = preg_replace('/<base\s+href=[\'"][^\'"]+[\'"]\s/?>/s', '', $objectpage->content); */
  1927. $res = $objectpage->update($user);
  1928. if ($res < 0) {
  1929. $error++;
  1930. setEventMessages($objectpage->error, $objectpage->errors, 'errors');
  1931. if ($action == 'updatesource') {
  1932. $action = 'editsource';
  1933. }
  1934. if ($action == 'updatecontent') {
  1935. $action = 'editcontent';
  1936. }
  1937. }
  1938. if (!$error) {
  1939. $db->commit();
  1940. $filemaster = $pathofwebsite.'/master.inc.php';
  1941. //$fileoldalias=$pathofwebsite.'/'.$objectpage->old_object->pageurl.'.php';
  1942. $filealias = $pathofwebsite.'/'.$objectpage->pageurl.'.php';
  1943. dol_mkdir($pathofwebsite);
  1944. // Now generate the master.inc.php page
  1945. $result = dolSaveMasterFile($filemaster);
  1946. if (!$result) {
  1947. setEventMessages('Failed to write the master file file '.$filemaster, null, 'errors');
  1948. }
  1949. // Now delete the old alias.php page if we removed one
  1950. /*if (!empty($fileoldalias))
  1951. {
  1952. dol_syslog("We regenerate alias page new name=".$filealias.", old name=".$fileoldalias);
  1953. dol_delete_file($fileoldalias);
  1954. // Delete also pages into language subdirectories
  1955. if (empty($objectpage->lang) || !in_array($objectpage->lang, explode(',', $object->otherlang))) {
  1956. $dirname = dirname($fileoldalias);
  1957. $filename = basename($fileoldalias);
  1958. $sublangs = explode(',', $object->otherlang);
  1959. foreach ($sublangs as $sublang) {
  1960. $fileoldaliassub = $dirname.'/'.$sublang.'/'.$filename;
  1961. dol_delete_file($fileoldaliassub);
  1962. }
  1963. }
  1964. }*/
  1965. // Save page alias
  1966. $result = dolSavePageAlias($filealias, $object, $objectpage);
  1967. if (!$result) {
  1968. setEventMessages('Failed to write the alias file '.basename($filealias), null, 'errors');
  1969. }
  1970. // Save page content
  1971. $result = dolSavePageContent($filetpl, $object, $objectpage, 1);
  1972. if ($result) {
  1973. setEventMessages($langs->trans("Saved"), null, 'mesgs');
  1974. if (!GETPOSTISSET('updateandstay')) { // If we click on "Save And Stay", we do not make the redirect
  1975. if ($backtopage) {
  1976. header("Location: ".$backtopage);
  1977. exit;
  1978. } else {
  1979. header("Location: ".$_SERVER["PHP_SELF"].'?website='.$websitekey.'&pageid='.$pageid);
  1980. exit;
  1981. }
  1982. } else {
  1983. if ($action == 'updatesource') {
  1984. $action = 'editsource';
  1985. }
  1986. if ($action == 'updatecontent') {
  1987. $action = 'editcontent';
  1988. }
  1989. }
  1990. } else {
  1991. setEventMessages('Failed to write file '.$filetpl, null, 'errors');
  1992. header("Location: ".$_SERVER["PHP_SELF"].'?website='.$websitekey.'&pageid='.$pageid);
  1993. exit;
  1994. }
  1995. } else {
  1996. $db->rollback();
  1997. }
  1998. } else {
  1999. header("Location: ".$_SERVER["PHP_SELF"].'?website='.$websitekey.'&pageid='.$pageid);
  2000. exit;
  2001. }
  2002. } else {
  2003. if (!$error) {
  2004. if (empty($websitekey) || $websitekey == '-1') {
  2005. setEventMessages($langs->trans("NoWebSiteCreateOneFirst"), null, 'warnings');
  2006. } else {
  2007. setEventMessages($langs->trans("NoPageYet"), null, 'warnings');
  2008. setEventMessages($langs->trans("YouCanCreatePageOrImportTemplate"), null, 'warnings');
  2009. }
  2010. }
  2011. }
  2012. }
  2013. // Export site
  2014. if ($action == 'exportsite' && $user->hasRight('website', 'export')) {
  2015. $fileofzip = $object->exportWebSite();
  2016. if ($fileofzip) {
  2017. $file_name = basename($fileofzip);
  2018. header("Content-Type: application/zip");
  2019. header("Content-Disposition: attachment; filename=".$file_name);
  2020. header("Content-Length: ".filesize($fileofzip));
  2021. readfile($fileofzip);
  2022. exit;
  2023. } else {
  2024. setEventMessages($object->error, $object->errors, 'errors');
  2025. $action = 'preview';
  2026. }
  2027. }
  2028. // Regenerate site
  2029. if ($action == 'regeneratesite' && $usercanedit) {
  2030. // Check symlink to medias and restore it if ko. Recreate also dir of website if not found.
  2031. $pathtomedias = DOL_DATA_ROOT.'/medias';
  2032. $pathtomediasinwebsite = $pathofwebsite.'/medias';
  2033. if (!is_link(dol_osencode($pathtomediasinwebsite))) {
  2034. dol_syslog("Create symlink for ".$pathtomedias." into name ".$pathtomediasinwebsite);
  2035. dol_mkdir(dirname($pathtomediasinwebsite)); // To be sure that the directory for website exists
  2036. $result = symlink($pathtomedias, $pathtomediasinwebsite);
  2037. if (!$result) {
  2038. $langs->load("errors");
  2039. setEventMessages($langs->trans("ErrorFailedToCreateSymLinkToMedias", $pathtomediasinwebsite, $pathtomedias), null, 'errors');
  2040. $action = 'preview';
  2041. }
  2042. }
  2043. $result = $object->rebuildWebSiteFiles();
  2044. if ($result > 0) {
  2045. setEventMessages($langs->trans("PagesRegenerated", $result), null, 'mesgs');
  2046. $action = 'preview';
  2047. } else {
  2048. setEventMessages($object->error, $object->errors, 'errors');
  2049. $action = 'preview';
  2050. }
  2051. }
  2052. // Import site
  2053. if ($action == 'importsiteconfirm' && $usercanedit) {
  2054. $dolibarrdataroot = preg_replace('/([\\/]+)$/i', '', DOL_DATA_ROOT);
  2055. $allowimportsite = true;
  2056. if (dol_is_file($dolibarrdataroot.'/installmodules.lock')) {
  2057. $allowimportsite = false;
  2058. }
  2059. if ($allowimportsite) {
  2060. if (empty($_FILES) && !GETPOSTISSET('templateuserfile')) {
  2061. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("File")), null, 'errors');
  2062. $action = 'importsite';
  2063. } else {
  2064. if (!empty($_FILES) || GETPOSTISSET('templateuserfile')) {
  2065. // Check symlink to medias and restore it if ko. Recreate also dir of website if not found.
  2066. $pathtomedias = DOL_DATA_ROOT.'/medias';
  2067. $pathtomediasinwebsite = $pathofwebsite.'/medias';
  2068. if (!is_link(dol_osencode($pathtomediasinwebsite))) {
  2069. dol_syslog("Create symlink for ".$pathtomedias." into name ".$pathtomediasinwebsite);
  2070. dol_mkdir(dirname($pathtomediasinwebsite)); // To be sure dir for website exists
  2071. $result = symlink($pathtomedias, $pathtomediasinwebsite);
  2072. if (!$result) {
  2073. $langs->load("errors");
  2074. setEventMessages($langs->trans("ErrorFailedToCreateSymLinkToMedias", $pathtomediasinwebsite, $pathtomedias), null, 'errors');
  2075. $action = 'importsite';
  2076. }
  2077. }
  2078. $fileofzip = '';
  2079. if (GETPOSTISSET('templateuserfile')) {
  2080. // Case we selected one template
  2081. $fileofzip = DOL_DATA_ROOT.'/doctemplates/websites/'.GETPOST('templateuserfile', 'alpha'); // $fileofzip will be sanitized later into the importWebSite()
  2082. } elseif (!empty($_FILES) && is_array($_FILES['userfile'])) {
  2083. // Case we upload a new template
  2084. if (is_array($_FILES['userfile']['tmp_name'])) {
  2085. $userfiles = $_FILES['userfile']['tmp_name'];
  2086. } else {
  2087. $userfiles = array($_FILES['userfile']['tmp_name']);
  2088. }
  2089. // Check if $_FILES is ok
  2090. foreach ($userfiles as $key => $userfile) {
  2091. if (empty($_FILES['userfile']['tmp_name'][$key])) {
  2092. $error++;
  2093. if ($_FILES['userfile']['error'][$key] == 1 || $_FILES['userfile']['error'][$key] == 2) {
  2094. setEventMessages($langs->trans('ErrorFileSizeTooLarge'), null, 'errors');
  2095. $action = 'importsite';
  2096. } else {
  2097. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("File")), null, 'errors');
  2098. $action = 'importsite';
  2099. }
  2100. }
  2101. }
  2102. if (!$error) {
  2103. //$upload_dir = $conf->website->dir_temp;
  2104. $upload_dir = DOL_DATA_ROOT.'/doctemplates/websites/';
  2105. $result = dol_add_file_process($upload_dir, 1, -1, 'userfile', '');
  2106. }
  2107. // Get name of file (take last one if several name provided)
  2108. /*
  2109. $fileofzip = $upload_dir.'/unknown';
  2110. foreach ($_FILES as $key => $ifile) {
  2111. foreach ($ifile['name'] as $key2 => $ifile2) {
  2112. $fileofzip = $upload_dir.'/'.$ifile2;
  2113. }
  2114. }
  2115. */
  2116. $action = 'importsite';
  2117. }
  2118. if (!$error && GETPOSTISSET('templateuserfile')) {
  2119. $result = $object->importWebSite($fileofzip);
  2120. if ($result < 0) {
  2121. setEventMessages($object->error, $object->errors, 'errors');
  2122. $action = 'importsite';
  2123. } else {
  2124. // Force mode dynamic on
  2125. dolibarr_set_const($db, 'WEBSITE_SUBCONTAINERSINLINE', 1, 'chaine', 0, '', $conf->entity);
  2126. header("Location: ".$_SERVER["PHP_SELF"].'?website='.$object->ref);
  2127. exit();
  2128. }
  2129. }
  2130. }
  2131. }
  2132. } else {
  2133. if (getDolGlobalString('MAIN_MESSAGE_INSTALL_MODULES_DISABLED_CONTACT_US')) {
  2134. // Show clean corporate message
  2135. $message = $langs->trans('InstallModuleFromWebHasBeenDisabledContactUs');
  2136. } else {
  2137. // Show technical generic message
  2138. $message = $langs->trans("InstallModuleFromWebHasBeenDisabledByFile", $dolibarrdataroot.'/installmodules.lock');
  2139. }
  2140. setEventMessages($message, null, 'errors');
  2141. }
  2142. }
  2143. $domainname = '0.0.0.0:8080';
  2144. $tempdir = $conf->website->dir_output.'/'.$websitekey.'/';
  2145. // Generate web site sitemaps
  2146. if ($action == 'generatesitemaps' && $usercanedit) {
  2147. // Define $domainname
  2148. if ($website->virtualhost) {
  2149. $domainname = $website->virtualhost;
  2150. }
  2151. if (! preg_match('/^http/i', $domainname)) {
  2152. $domainname = 'https://'.$domainname;
  2153. }
  2154. $domtree = new DOMDocument('1.0', 'UTF-8');
  2155. $root = $domtree->createElementNS('http://www.sitemaps.org/schemas/sitemap/0.9', 'urlset');
  2156. $root->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:xhtml', 'http://www.w3.org/1999/xhtml');
  2157. $domtree->formatOutput = true;
  2158. $addrsswrapper = 0;
  2159. $xmlname = 'sitemap.xml';
  2160. $sql = "SELECT wp.rowid, wp.type_container , wp.pageurl, wp.lang, wp.fk_page, wp.tms as tms,";
  2161. $sql .= " w.virtualhost, w.fk_default_home";
  2162. $sql .= " FROM ".MAIN_DB_PREFIX."website_page as wp, ".MAIN_DB_PREFIX."website as w";
  2163. $sql .= " WHERE wp.type_container IN ('page', 'blogpost')";
  2164. $sql .= " AND wp.fk_website = w.rowid";
  2165. $sql .= " AND wp.status = ".WebsitePage::STATUS_VALIDATED;
  2166. $sql .= " AND wp.pageurl NOT IN ('404', '500', '501', '503')";
  2167. $sql .= " AND w.ref = '".dol_escape_json($websitekey)."'";
  2168. $sql .= " ORDER BY wp.tms DESC, wp.rowid DESC";
  2169. $resql = $db->query($sql);
  2170. if ($resql) {
  2171. $num_rows = $db->num_rows($resql);
  2172. if ($num_rows > 0) {
  2173. $i = 0;
  2174. while ($i < $num_rows) {
  2175. $objp = $db->fetch_object($resql);
  2176. $url = $domtree->createElement('url');
  2177. $shortlangcode = '';
  2178. if ($objp->lang) {
  2179. $shortlangcode = substr($objp->lang, 0, 2); // en_US or en-US -> en
  2180. }
  2181. if (empty($shortlangcode)) {
  2182. $shortlangcode = substr($object->lang, 0, 2); // Use short lang code of website
  2183. }
  2184. // Is it a blog post for the RSS wrapper ?
  2185. if ($objp->type_container == 'blogpost') {
  2186. $addrsswrapper = 1;
  2187. }
  2188. // Forge $pageurl, adding language prefix if it is an alternative language
  2189. $pageurl = $objp->pageurl.'.php';
  2190. if ($objp->fk_default_home == $objp->rowid) {
  2191. $pageurl = '';
  2192. } else {
  2193. if ($shortlangcode != substr($object->lang, 0, 2)) {
  2194. $pageurl = $shortlangcode.'/'.$pageurl;
  2195. }
  2196. }
  2197. //$pathofpage = $dolibarr_main_url_root.'/'.$pageurl.'.php';
  2198. // URL of sitemaps must end with trailing slash if page is ''
  2199. $loc = $domtree->createElement('loc', $domainname.'/'.$pageurl);
  2200. $lastmod = $domtree->createElement('lastmod', dol_print_date($db->jdate($objp->tms), 'dayrfc', 'gmt'));
  2201. $priority = $domtree->createElement('priority', '1');
  2202. $url->appendChild($loc);
  2203. $url->appendChild($lastmod);
  2204. // Add suggested frequency for refresh
  2205. if (!empty($conf->global->WEBSITE_SITEMAPS_ADD_WEEKLY_FREQ)) {
  2206. $changefreq = $domtree->createElement('changefreq', 'weekly'); // TODO Manage other values
  2207. $url->appendChild($changefreq);
  2208. }
  2209. // Add higher priority for home page
  2210. if ($objp->fk_default_home == $objp->rowid) {
  2211. $url->appendChild($priority);
  2212. }
  2213. // Now add alternate language entries
  2214. if ($object->isMultiLang()) {
  2215. $alternatefound = 0;
  2216. // Add page "translation of"
  2217. $translationof = $objp->fk_page;
  2218. if ($translationof) {
  2219. $tmppage = new WebsitePage($db);
  2220. $tmppage->fetch($translationof);
  2221. if ($tmppage->id > 0) {
  2222. $tmpshortlangcode = '';
  2223. if ($tmppage->lang) {
  2224. $tmpshortlangcode = preg_replace('/[_-].*$/', '', $tmppage->lang); // en_US or en-US -> en
  2225. }
  2226. if (empty($tmpshortlangcode)) {
  2227. $tmpshortlangcode = preg_replace('/[_-].*$/', '', $object->lang); // en_US or en-US -> en
  2228. }
  2229. if ($tmpshortlangcode != $shortlangcode) {
  2230. $xhtmllink = $domtree->createElement('xhtml:link', '');
  2231. $xhtmllink->setAttribute("rel", "alternate");
  2232. $xhtmllink->setAttribute("hreflang", $tmpshortlangcode);
  2233. $xhtmllink->setAttribute("href", $domainname.($objp->fk_default_home == $tmppage->id ? '/' : (($tmpshortlangcode != substr($object->lang, 0, 2)) ? '/'.$tmpshortlangcode : '').'/'.$tmppage->pageurl.'.php'));
  2234. $url->appendChild($xhtmllink);
  2235. $alternatefound++;
  2236. }
  2237. }
  2238. }
  2239. // Add "has translation pages"
  2240. $sql = 'SELECT rowid as id, lang, pageurl from '.MAIN_DB_PREFIX.'website_page';
  2241. $sql .= " WHERE status = ".((int) WebsitePage::STATUS_VALIDATED).' AND fk_page IN ('.$db->sanitize($objp->rowid.($translationof ? ", ".$translationof : "")).")";
  2242. $resqlhastrans = $db->query($sql);
  2243. if ($resqlhastrans) {
  2244. $num_rows_hastrans = $db->num_rows($resqlhastrans);
  2245. if ($num_rows_hastrans > 0) {
  2246. while ($objhastrans = $db->fetch_object($resqlhastrans)) {
  2247. $tmpshortlangcode = '';
  2248. if ($objhastrans->lang) {
  2249. $tmpshortlangcode = preg_replace('/[_-].*$/', '', $objhastrans->lang); // en_US or en-US -> en
  2250. }
  2251. if ($tmpshortlangcode != $shortlangcode) {
  2252. $xhtmllink = $domtree->createElement('xhtml:link', '');
  2253. $xhtmllink->setAttribute("rel", "alternate");
  2254. $xhtmllink->setAttribute("hreflang", $tmpshortlangcode);
  2255. $xhtmllink->setAttribute("href", $domainname.($objp->fk_default_home == $objhastrans->id ? '/' : (($tmpshortlangcode != substr($object->lang, 0, 2) ? '/'.$tmpshortlangcode : '')).'/'.$objhastrans->pageurl.'.php'));
  2256. $url->appendChild($xhtmllink);
  2257. $alternatefound++;
  2258. }
  2259. }
  2260. }
  2261. } else {
  2262. dol_print_error($db);
  2263. }
  2264. if ($alternatefound) {
  2265. // Add myself
  2266. $xhtmllink = $domtree->createElement('xhtml:link', '');
  2267. $xhtmllink->setAttribute("rel", "alternate");
  2268. $xhtmllink->setAttribute("hreflang", $shortlangcode);
  2269. $xhtmllink->setAttribute("href", $domainname.'/'.$pageurl);
  2270. $url->appendChild($xhtmllink);
  2271. }
  2272. }
  2273. // Now add sitempas extension for news
  2274. // TODO When adding and when not ?
  2275. /*<news:news>
  2276. <news:publication>
  2277. <news:name>The Example Times</news:name>
  2278. <news:language>en</news:language>
  2279. </news:publication>
  2280. <news:publication_date>2008-12-23</news:publication_date>
  2281. <news:title>Companies A, B in Merger Talks</news:title>
  2282. </news:news>
  2283. */
  2284. $root->appendChild($url);
  2285. $i++;
  2286. }
  2287. // Adding a RSS feed into a sitemap should nto be required. The RSS contains pages that are already included into
  2288. // the sitemap and RSS feeds are not shown into index.
  2289. if ($addrsswrapper && getDolGlobalInt('WEBSITE_ADD_RSS_FEED_INTO_SITEMAP')) {
  2290. $url = $domtree->createElement('url');
  2291. $pageurl = 'wrapper.php?rss=1';
  2292. // URL of sitemaps must end with trailing slash if page is ''
  2293. $loc = $domtree->createElement('loc', $domainname.'/'.$pageurl);
  2294. $lastmod = $domtree->createElement('lastmod', dol_print_date($db->jdate(dol_now()), 'dayrfc', 'gmt'));
  2295. $url->appendChild($loc);
  2296. $url->appendChild($lastmod);
  2297. // Add suggested frequency for refresh
  2298. if (!empty($conf->global->WEBSITE_SITEMAPS_ADD_WEEKLY_FREQ)) {
  2299. $changefreq = $domtree->createElement('changefreq', 'weekly'); // TODO Manage other values
  2300. $url->appendChild($changefreq);
  2301. }
  2302. $root->appendChild($url);
  2303. }
  2304. $domtree->appendChild($root);
  2305. if ($domtree->save($tempdir.$xmlname)) {
  2306. dolChmod($tempdir.$xmlname);
  2307. setEventMessages($langs->trans("SitemapGenerated", $xmlname), null, 'mesgs');
  2308. } else {
  2309. setEventMessages($object->error, $object->errors, 'errors');
  2310. }
  2311. }
  2312. } else {
  2313. dol_print_error($db);
  2314. }
  2315. // Add the entry Sitemap: into the robot.txt file.
  2316. $robotcontent = @file_get_contents($filerobot);
  2317. $robotsitemap = "Sitemap: ".$domainname."/".$xmlname;
  2318. $result = strpos($robotcontent, 'Sitemap: ');
  2319. if ($result) {
  2320. $result = preg_replace('/Sitemap:.*/', $robotsitemap, $robotcontent);
  2321. $robotcontent = $result ? $result : $robotcontent;
  2322. } else {
  2323. $robotcontent .= $robotsitemap."\n";
  2324. }
  2325. $result = dolSaveRobotFile($filerobot, $robotcontent);
  2326. if (!$result) {
  2327. $error++;
  2328. setEventMessages('Failed to write file '.$filerobot, null, 'errors');
  2329. }
  2330. $action = 'preview';
  2331. }
  2332. /*
  2333. * View
  2334. */
  2335. $form = new Form($db);
  2336. $formadmin = new FormAdmin($db);
  2337. $formwebsite = new FormWebsite($db);
  2338. $formother = new FormOther($db);
  2339. $formconfirm = "";
  2340. // Confirm generation of website sitemaps
  2341. if ($action == 'confirmgeneratesitemaps') {
  2342. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?website='.urlencode($website->ref), $langs->trans('ConfirmSitemapsCreation'), $langs->trans('ConfirmGenerateSitemaps', $object->ref), 'generatesitemaps', '', "yes", 1);
  2343. $action = 'preview';
  2344. }
  2345. $helpurl = 'EN:Module_Website|FR:Module_Website_FR|ES:M&oacute;dulo_Website';
  2346. $arrayofjs = array(
  2347. '/includes/ace/src/ace.js',
  2348. '/includes/ace/src/ext-statusbar.js',
  2349. '/includes/ace/src/ext-language_tools.js',
  2350. //'/includes/ace/src/ext-chromevox.js'
  2351. //'/includes/jquery/plugins/jqueryscoped/jquery.scoped.js',
  2352. );
  2353. $arrayofcss = array();
  2354. $moreheadcss = '';
  2355. $moreheadjs = '';
  2356. $arrayofjs[] = 'includes/jquery/plugins/blockUI/jquery.blockUI.js';
  2357. $arrayofjs[] = 'core/js/blockUI.js'; // Used by ecm/tpl/enabledfiletreeajax.tpl.php
  2358. if (empty($conf->global->MAIN_ECM_DISABLE_JS)) {
  2359. $arrayofjs[] = "includes/jquery/plugins/jqueryFileTree/jqueryFileTree.js";
  2360. }
  2361. $moreheadjs .= '<script type="text/javascript">'."\n";
  2362. $moreheadjs .= 'var indicatorBlockUI = \''.DOL_URL_ROOT."/theme/".$conf->theme."/img/working.gif".'\';'."\n";
  2363. $moreheadjs .= '</script>'."\n";
  2364. llxHeader($moreheadcss.$moreheadjs, $langs->trans("Website").(empty($website->ref) ? '' : ' - '.$website->ref), $helpurl, '', 0, 0, $arrayofjs, $arrayofcss, '', '', '<!-- Begin div class="fiche" -->'."\n".'<div class="fichebutwithotherclass">');
  2365. print "\n";
  2366. print '<!-- Open form for all page -->'."\n";
  2367. print '<form action="'.$_SERVER["PHP_SELF"].($action == 'file_manager' ? '?uploadform=1': '').'" method="POST" enctype="multipart/form-data" class="websiteformtoolbar">';
  2368. print '<input type="hidden" name="token" value="'.newToken().'">';
  2369. print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
  2370. print '<input type="hidden" name="dol_openinpopup" value="'.$dol_openinpopup.'">';
  2371. if ($action == 'createsite') {
  2372. print '<input type="hidden" name="action" value="addsite">';
  2373. }
  2374. if ($action == 'createcontainer') {
  2375. print '<input type="hidden" name="action" value="addcontainer">';
  2376. }
  2377. if ($action == 'editcss') {
  2378. print '<input type="hidden" name="action" value="updatecss">';
  2379. }
  2380. if ($action == 'editmenu') {
  2381. print '<input type="hidden" name="action" value="updatemenu">';
  2382. }
  2383. if ($action == 'setashome') {
  2384. print '<input type="hidden" name="action" value="updateashome">';
  2385. }
  2386. if ($action == 'editmeta') {
  2387. print '<input type="hidden" name="action" value="updatemeta">';
  2388. }
  2389. if ($action == 'editsource') {
  2390. print '<input type="hidden" name="action" value="updatesource">';
  2391. }
  2392. if ($action == 'editcontent') {
  2393. print '<input type="hidden" name="action" value="updatecontent">';
  2394. }
  2395. if ($action == 'edit') {
  2396. print '<input type="hidden" name="action" value="update">';
  2397. }
  2398. if ($action == 'importsite') {
  2399. print '<input type="hidden" name="action" value="importsiteconfirm">';
  2400. }
  2401. if ($action == 'file_manager') {
  2402. print '<input type="hidden" name="action" value="file_manager">';
  2403. }
  2404. if ($mode) {
  2405. print '<input type="hidden" name="mode" value="'.$mode.'">';
  2406. }
  2407. print '<div>';
  2408. // Add a margin under toolbar ?
  2409. $style = '';
  2410. if ($action != 'preview' && $action != 'editcontent' && $action != 'editsource' && !GETPOST('createpagefromclone', 'alphanohtml')) {
  2411. $style = ' margin-bottom: 5px;';
  2412. }
  2413. if (!GETPOST('hide_websitemenu')) {
  2414. $disabled = '';
  2415. if (!$user->hasRight('website', 'write')) {
  2416. $disabled = ' disabled="disabled"';
  2417. }
  2418. $disabledexport = '';
  2419. if (!$user->hasRight('website', 'export')) {
  2420. $disabledexport = ' disabled="disabled"';
  2421. }
  2422. if ($websitekey) {
  2423. $virtualurl = '';
  2424. $dataroot = DOL_DATA_ROOT.($conf->entity > 1 ? '/'.$conf->entity : '').'/website/'.$websitekey;
  2425. if (!empty($object->virtualhost)) {
  2426. $virtualurl = $object->virtualhost;
  2427. }
  2428. }
  2429. $array = array();
  2430. if ($object->id > 0) {
  2431. $array = $objectpage->fetchAll($object->id, 'ASC,ASC', 'type_container,pageurl');
  2432. $object->lines = $array;
  2433. }
  2434. if (!is_array($array) && $array < 0) {
  2435. dol_print_error('', $objectpage->error, $objectpage->errors);
  2436. }
  2437. $atleastonepage = (is_array($array) && count($array) > 0);
  2438. $websitepage = new WebsitePage($db);
  2439. if ($pageid > 0) {
  2440. $websitepage->fetch($pageid);
  2441. }
  2442. //var_dump($objectpage);exit;
  2443. print '<div class="centpercent websitebar'.(GETPOST('dol_openinpopup', 'aZ09') ? ' hiddenforpopup' : '').'">';
  2444. //
  2445. // Toolbar for websites
  2446. //
  2447. print '<!-- Toolbar for website -->';
  2448. if ($action != 'file_manager') {
  2449. print '<div class="websiteselection hideonsmartphoneimp minwidth75 tdoverflowmax100 inline-block">';
  2450. print $langs->trans("Website").': ';
  2451. print '</div>';
  2452. // Button Add new website
  2453. $urltocreatenewwebsite = $_SERVER["PHP_SELF"].'?action=createsite';
  2454. print '<span class="websiteselection paddingrightonly">';
  2455. print '<a href="'.$urltocreatenewwebsite.'" class=""'.$disabled.' title="'.dol_escape_htmltag($langs->trans("AddWebsite")).'"><span class="fa fa-plus-circle valignmiddle btnTitle-icon"><span></a>';
  2456. print '</span>';
  2457. // List of website
  2458. print '<span class="websiteselection nopaddingrightimp">';
  2459. $out = '';
  2460. $out .= '<select name="website" class="minwidth100 width200 maxwidth150onsmartphone" id="website">';
  2461. if (empty($listofwebsites)) {
  2462. $out .= '<option value="-1">&nbsp;</option>';
  2463. }
  2464. // Loop on each sites
  2465. $i = 0;
  2466. foreach ($listofwebsites as $key => $valwebsite) {
  2467. if (empty($websitekey)) {
  2468. if ($action != 'createsite') {
  2469. $websitekey = $valwebsite->ref;
  2470. }
  2471. }
  2472. $out .= '<option value="'.$valwebsite->ref.'"';
  2473. if ($websitekey == $valwebsite->ref) {
  2474. $out .= ' selected'; // To preselect a value
  2475. }
  2476. //$outoption = $valwebsite->getLibStatut(3).' '.$valwebsite->ref.' ';
  2477. $outoption = (($valwebsite->status == $valwebsite::STATUS_DRAFT) ? '<span class="opacitymedium">' : '').$valwebsite->ref.(($valwebsite->status == $valwebsite::STATUS_DRAFT) ? '</span>' : '');
  2478. $out .= ' data-html="'.dol_escape_htmltag($outoption).'"';
  2479. $out .= '>';
  2480. $out .= $valwebsite->ref;
  2481. $out .= '</option>';
  2482. $i++;
  2483. }
  2484. $out .= '</select>';
  2485. $out .= ajax_combobox('website');
  2486. if (!empty($conf->use_javascript_ajax)) {
  2487. $out .= '<script type="text/javascript">';
  2488. $out .= 'jQuery(document).ready(function () {';
  2489. $out .= ' jQuery("#website").change(function () {';
  2490. $out .= ' console.log("We select "+jQuery("#website option:selected").val());';
  2491. $out .= ' if (jQuery("#website option:selected").val() == \'-2\') {';
  2492. $out .= ' window.location.href = "'.dol_escape_js($urltocreatenewwebsite).'";';
  2493. $out .= ' } else {';
  2494. $out .= ' window.location.href = "'.$_SERVER["PHP_SELF"].'?website="+jQuery("#website option:selected").val();';
  2495. $out .= ' }';
  2496. $out .= ' });';
  2497. $out .= '});';
  2498. $out .= '</script>';
  2499. }
  2500. print $out;
  2501. print '</span>';
  2502. // Switch offline/onine
  2503. if (!empty($conf->use_javascript_ajax)) {
  2504. print '<span class="websiteselection">';
  2505. // Do not use ajax, we need a refresh of full page when we change status of a website
  2506. //print '<div class="inline-block marginrightonly">';
  2507. //print ajax_object_onoff($object, 'status', 'status', 'Online', 'Offline', array(), 'valignmiddle inline-block', 'statuswebsite');
  2508. //print '</div>';
  2509. if ($website->status == $website::STATUS_DRAFT) {
  2510. $text_off = 'Offline';
  2511. print '<a href="'.$_SERVER["PHP_SELF"].'?action=setwebsiteonline&token='.newToken().'&website='.urlencode($website->ref).'&websitepage='.((int) $websitepage->id).'">'.img_picto($langs->trans($text_off), 'switch_off').'</a>';
  2512. } else {
  2513. $text_off = 'Online';
  2514. print '<a href="'.$_SERVER["PHP_SELF"].'?action=setwebsiteoffline&token='.newToken().'&website='.urlencode($website->ref).'&websitepage='.((int) $websitepage->id).'">'.img_picto($langs->trans($text_off), 'switch_on').'</a>';
  2515. }
  2516. print '</span>';
  2517. }
  2518. // Refresh / Reload web site (for non javascript browers)
  2519. if (empty($conf->use_javascript_ajax)) {
  2520. print '<span class="websiteselection">';
  2521. print '<input type="image" class="valignmiddle" src="'.img_picto('', 'refresh', '', 0, 1).'" name="refreshsite" value="'.$langs->trans("Load").'">';
  2522. print '</span>';
  2523. }
  2524. print '<span class="websiteselection">';
  2525. if ($websitekey && $websitekey != '-1' && ($action == 'preview' || $action == 'createfromclone' || $action == 'createpagefromclone' || $action == 'deletesite')) {
  2526. // Edit website properties
  2527. print '<a href="'.$_SERVER["PHP_SELF"].'?website='.urlencode($object->ref).'&pageid='.((int) $pageid).'&action=editcss&token='.newToken().'" class="button bordertransp" title="'.dol_escape_htmltag($langs->trans("EditCss")).'"'.$disabled.'><span class="fa fa-cog paddingrightonly"></span><span class="hideonsmartphone">'.dol_escape_htmltag($langs->trans("EditCss")).'</span></a>';
  2528. // Import web site
  2529. $importlabel = $langs->trans("ImportSite");
  2530. $exportlabel = $langs->trans("ExportSite");
  2531. if (!empty($conf->dol_optimize_smallscreen)) {
  2532. $importlabel = $langs->trans("Import");
  2533. $exportlabel = $langs->trans("Export");
  2534. }
  2535. if ($atleastonepage) {
  2536. print '<input type="submit" class="button bordertransp" disabled="disabled" value="'.dol_escape_htmltag($importlabel).'" name="importsite">';
  2537. } else {
  2538. print '<input type="submit" class="button bordertransp"'.$disabled.' value="'.dol_escape_htmltag($importlabel).'" name="importsite">';
  2539. }
  2540. // Export web site
  2541. print '<input type="submit" class="button bordertransp"'.$disabledexport.' value="'.dol_escape_htmltag($exportlabel).'" name="exportsite">';
  2542. // Clone web site
  2543. print '<input type="submit" class="button bordertransp"'.$disabled.' value="'.dol_escape_htmltag($langs->trans("CloneSite")).'" name="createfromclone">';
  2544. // Delete website
  2545. if (!$permissiontodelete) {
  2546. $disabled = ' disabled="disabled"';
  2547. $title = $langs->trans("NotEnoughPermissions");
  2548. $url = '#';
  2549. } else {
  2550. if ($website->status == $website::STATUS_VALIDATED) {
  2551. $disabled = ' disabled="disabled"';
  2552. $title = $langs->trans("WebsiteMustBeDisabled", $langs->transnoentitiesnoconv($website->LibStatut(0, 0)));
  2553. $url = '#';
  2554. } else {
  2555. $disabled = '';
  2556. $title = $langs->trans("Delete");
  2557. $url = $_SERVER["PHP_SELF"].'?action=deletesite&token='.newToken().'&website='.urlencode($website->ref);
  2558. }
  2559. }
  2560. print '<a href="'.$url.'" class="button buttonDelete bordertransp'.($disabled ? ' disabled' : '').'"'.$disabled.' title="'.dol_escape_htmltag($title).'">'.img_picto('', 'delete', 'class=""').'<span class="hideonsmartphone paddingleft">'.$langs->trans("Delete").'</span></a>';
  2561. // Regenerate all pages
  2562. print '<a href="'.$_SERVER["PHP_SELF"].'?action=regeneratesite&token='.newToken().'&website='.urlencode($website->ref).'" class="button bordertransp"'.$disabled.' title="'.dol_escape_htmltag($langs->trans("RegenerateWebsiteContent")).'"><span class="far fa-hdd"></span></a>';
  2563. // Generate site map
  2564. print '<a href="'.$_SERVER["PHP_SELF"].'?action=confirmgeneratesitemaps&token='.newToken().'&website='.urlencode($website->ref).'" class="button bordertransp"'.$disabled.' title="'.dol_escape_htmltag($langs->trans("GenerateSitemaps")).'"><span class="fa fa-sitemap"></span></a>';
  2565. // Find / replace tool
  2566. print '<a href="'.$_SERVER["PHP_SELF"].'?action=replacesite&website='.urlencode($website->ref).'" class="button bordertransp"'.$disabled.' title="'.dol_escape_htmltag($langs->trans("ReplaceWebsiteContent")).'"><span class="fa fa-search"></span></a>';
  2567. }
  2568. print '</span>';
  2569. if ($websitekey && $websitekey != '-1' && ($action == 'preview' || $action == 'createfromclone' || $action == 'createpagefromclone' || $action == 'deletesite')) {
  2570. print '<span class="websiteselection">';
  2571. print dolButtonToOpenUrlInDialogPopup('file_manager', $langs->transnoentitiesnoconv("MediaFiles"), '<span class="fa fa-image"></span>', '/website/index.php?action=file_manager&website='.urlencode($website->ref).'&section_dir='.urlencode('image/'.$website->ref.'/'), $disabled);
  2572. if (isModEnabled('categorie')) {
  2573. //print '<a href="'.DOL_URL_ROOT.'/categories/index.php?leftmenu=website&dol_hide_leftmenu=1&nosearch=1&type=website_page&website='.$website->ref.'" class="button bordertransp"'.$disabled.' title="'.dol_escape_htmltag($langs->trans("Categories")).'"><span class="fa fa-tags"></span></a>';
  2574. print dolButtonToOpenUrlInDialogPopup('categories', $langs->transnoentitiesnoconv("Categories"), '<span class="fa fa-tags"></span>', '/categories/index.php?leftmenu=website&nosearch=1&type=website_page&website='.urlencode($website->ref), $disabled);
  2575. }
  2576. print '</span>';
  2577. }
  2578. } else {
  2579. print '<input type="hidden" name="website" id="website" value="'.$websitekey.'">';
  2580. }
  2581. print '<span class="websitetools">';
  2582. if ($action == 'preview' || $action == 'createfromclone' || $action == 'createpagefromclone' || $action == 'deletesite') {
  2583. $urlext = $virtualurl;
  2584. $urlint = $urlwithroot.'/public/website/index.php?website='.$websitekey;
  2585. print '<span class="websiteinputurl valignmiddle" id="websiteinputurl">';
  2586. $linktotestonwebserver = '<a href="'.($virtualurl ? $virtualurl : '#').'" class="valignmiddle">';
  2587. $linktotestonwebserver .= '<span class="hideonsmartphone paddingrightonly">'.$langs->trans("TestDeployOnWeb", $virtualurl).'</span>'.img_picto('', 'globe');
  2588. $linktotestonwebserver .= '</a>';
  2589. $htmltext = '';
  2590. if (empty($object->fk_default_home)) {
  2591. $htmltext .= '<br><span class="error">'.$langs->trans("YouMustDefineTheHomePage").'</span><br><br>';
  2592. } elseif (empty($virtualurl)) {
  2593. //$htmltext .= '<br><span class="error">'.$langs->trans("VirtualHostUrlNotDefined").'</span><br><br>';
  2594. } else {
  2595. $htmltext .= '<br><center>'.$langs->trans("GoTo").' <a href="'.$virtualurl.'" target="_website">'.$virtualurl.'</a></center><br>';
  2596. }
  2597. if (!empty($conf->global->WEBSITE_REPLACE_INFO_ABOUT_USAGE_WITH_WEBSERVER)) {
  2598. $htmltext .= '<!-- Message defined translate key set into WEBSITE_REPLACE_INFO_ABOUT_USAGE_WITH_WEBSERVER -->';
  2599. $htmltext .= '<br>'.$langs->trans($conf->global->WEBSITE_REPLACE_INFO_ABOUT_USAGE_WITH_WEBSERVER);
  2600. } else {
  2601. $htmltext .= $langs->trans("SetHereVirtualHost", $dataroot);
  2602. $htmltext .= '<br>';
  2603. $htmltext .= '<br>'.$langs->trans("CheckVirtualHostPerms", $langs->transnoentitiesnoconv("ReadPerm"), DOL_DOCUMENT_ROOT);
  2604. $htmltext .= '<br>'.$langs->trans("CheckVirtualHostPerms", $langs->transnoentitiesnoconv("WritePerm"), '{s1}');
  2605. $htmltext = str_replace('{s1}', DOL_DATA_ROOT.'/website<br>'.DOL_DATA_ROOT.'/medias', $htmltext);
  2606. $examplewithapache = '#php_admin_value open_basedir /tmp/:'.DOL_DOCUMENT_ROOT.':'.DOL_DATA_ROOT.':/dev/urandom'."\n";
  2607. $examplewithapache .= '<Directory "'.DOL_DOCUMENT_ROOT.'">'."\n";
  2608. $examplewithapache .= 'AllowOverride FileInfo Options
  2609. Options -Indexes -MultiViews -FollowSymLinks -ExecCGI
  2610. Require all granted
  2611. </Directory>
  2612. <Directory "'.DOL_DATA_ROOT.'/website">
  2613. AllowOverride FileInfo Options
  2614. Options -Indexes -MultiViews +FollowSymLinks -ExecCGI
  2615. Require all granted
  2616. </Directory>
  2617. <Directory "'.DOL_DATA_ROOT.'/medias">
  2618. AllowOverride FileInfo Options
  2619. Options -Indexes -MultiViews -FollowSymLinks -ExecCGI
  2620. Require all granted
  2621. </Directory>';
  2622. $htmltext .= '<br>'.$langs->trans("ExampleToUseInApacheVirtualHostConfig").':<br>';
  2623. $htmltext .= '<div class="centpercent exampleapachesetup">'.dol_nl2br(dol_escape_htmltag($examplewithapache, 1, 1)).'</div>';
  2624. $htmltext .= '<br>';
  2625. $htmltext .= $langs->trans("YouCanAlsoTestWithPHPS", $dataroot);
  2626. $htmltext .= '<br>';
  2627. $htmltext .= '<br>';
  2628. $htmltext .= $langs->trans("YouCanAlsoDeployToAnotherWHP");
  2629. }
  2630. print $form->textwithpicto($linktotestonwebserver, $htmltext, 1, 'none', 'valignmiddle', 0, 3, 'helpvirtualhost');
  2631. print '</span>';
  2632. }
  2633. if (in_array($action, array('editcss', 'editmenu', 'file_manager', 'replacesiteconfirm')) || in_array($mode, array('replacesite'))) {
  2634. if ($action == 'editcss') {
  2635. print '<input type="submit" id="savefileandstay" class="button buttonforacesave hideonsmartphone small" value="'.dol_escape_htmltag($langs->trans("SaveAndStay")).'" name="updateandstay">';
  2636. }
  2637. if (preg_match('/^create/', $action) && $action != 'file_manager' && $action != 'replacesite' && $action != 'replacesiteconfirm') {
  2638. print '<input type="submit" id="savefile" class="button buttonforacesave button-save small" value="'.dol_escape_htmltag($langs->trans("Save")).'" name="update">';
  2639. }
  2640. if (preg_match('/^edit/', $action) && $action != 'file_manager' && $action != 'replacesite' && $action != 'replacesiteconfirm') {
  2641. print '<input type="submit" id="savefile" class="button buttonforacesave button-save small" value="'.dol_escape_htmltag($langs->trans("Save")).'" name="update">';
  2642. }
  2643. if ($action != 'preview') {
  2644. print '<input type="submit" class="button button-cancel small" value="'.dol_escape_htmltag($langs->trans("Cancel")).'" name="cancel">';
  2645. }
  2646. }
  2647. print '</span>';
  2648. //
  2649. // Toolbar for pages
  2650. //
  2651. if ($websitekey && $websitekey != '-1' && (!in_array($action, array('editcss', 'editmenu', 'importsite', 'file_manager', 'replacesite', 'replacesiteconfirm'))) && (!in_array($mode, array('replacesite'))) && !$file_manager) {
  2652. print '</div>'; // Close current websitebar to open a new one
  2653. print '<!-- Toolbar for websitepage -->';
  2654. print '<div class="centpercent websitebar"'.($style ? ' style="'.$style.'"' : '').'>';
  2655. print '<div class="websiteselection hideonsmartphoneimp minwidth75 tdoverflowmax100 inline-block">';
  2656. print $langs->trans("PageContainer").': ';
  2657. print '</div>';
  2658. // Button Add new web page
  2659. print '<span class="websiteselection paddingrightonly">';
  2660. print '<a href="'.$_SERVER["PHP_SELF"].'?action=createcontainer&token='.newToken().'&website='.urlencode($website->ref).'" class=""'.$disabled.' title="'.dol_escape_htmltag($langs->trans("AddPage")).'"><span class="fa fa-plus-circle valignmiddle btnTitle-icon"></span></a>';
  2661. print '</span>';
  2662. $out = '';
  2663. $s = $formwebsite->selectContainer($website, 'pageid', $pageid, 0, $action, 'minwidth100 maxwidth200onsmartphone');
  2664. $out .= '<span class="websiteselection nopaddingrightimp">';
  2665. $out .= $s;
  2666. $out .= '</span>';
  2667. $urltocreatenewpage = $_SERVER["PHP_SELF"].'?action=createcontainer&token='.newToken().'&website='.urlencode($website->ref);
  2668. if (!empty($conf->use_javascript_ajax)) {
  2669. $out .= '<script type="text/javascript">';
  2670. $out .= 'jQuery(document).ready(function () {';
  2671. $out .= ' jQuery("#pageid").change(function () {';
  2672. $out .= ' console.log("We select "+jQuery("#pageid option:selected").val());';
  2673. $out .= ' if (jQuery("#pageid option:selected").val() == \'-2\') {';
  2674. $out .= ' window.location.href = "'.$urltocreatenewpage.'";';
  2675. $out .= ' } else {';
  2676. $out .= ' window.location.href = "'.$_SERVER["PHP_SELF"].'?website='.urlencode($website->ref).'&pageid="+jQuery("#pageid option:selected").val();';
  2677. $out .= ' }';
  2678. $out .= ' });';
  2679. $out .= '});';
  2680. $out .= '</script>';
  2681. }
  2682. print $out;
  2683. if (!empty($conf->use_javascript_ajax)) {
  2684. print '<span class="websiteselection">';
  2685. //print '<div class="inline-block marginrightonly">';
  2686. if ($object->status == $object::STATUS_DRAFT) { // website is off, we do not allow to change status of page
  2687. $text_off = 'SetWebsiteOnlineBefore';
  2688. if ($websitepage->status == $websitepage::STATUS_DRAFT) { // page is off
  2689. print '<span class="valignmiddle disabled opacitymedium">'.img_picto($langs->trans($text_off), 'switch_off').'</span>';
  2690. } else {
  2691. print '<span class="valignmiddle disabled opacitymedium">'.img_picto($langs->trans($text_off), 'switch_on').'</span>';
  2692. }
  2693. } else {
  2694. print ajax_object_onoff($websitepage, 'status', 'status', 'Online', 'Offline', array(), 'valignmiddle inline-block'.(empty($websitepage->id) ? ' opacitymedium disabled' : ''), 'statuswebsitepage');
  2695. }
  2696. //print '</div>';
  2697. print '</span>';
  2698. }
  2699. print '<span class="websiteselection">';
  2700. print '<input type="image" class="valignmiddle buttonwebsite" src="'.img_picto('', 'refresh', '', 0, 1).'" name="refreshpage" value="'.$langs->trans("Load").'"'.(($action != 'editsource') ? '' : ' disabled="disabled"').'>';
  2701. // Print nav arrows
  2702. $pagepreviousid = 0;
  2703. $pagenextid = 0;
  2704. if ($pageid) {
  2705. $sql = "SELECT MAX(rowid) as pagepreviousid FROM ".MAIN_DB_PREFIX."website_page WHERE rowid < ".((int) $pageid)." AND fk_website = ".((int) $object->id);
  2706. $resql = $db->query($sql);
  2707. if ($resql) {
  2708. $obj = $db->fetch_object($resql);
  2709. if ($obj) {
  2710. $pagepreviousid = $obj->pagepreviousid;
  2711. }
  2712. } else {
  2713. dol_print_error($db);
  2714. }
  2715. $sql = "SELECT MIN(rowid) as pagenextid FROM ".MAIN_DB_PREFIX."website_page WHERE rowid > ".((int) $pageid)." AND fk_website = ".((int) $object->id);
  2716. $resql = $db->query($sql);
  2717. if ($resql) {
  2718. $obj = $db->fetch_object($resql);
  2719. if ($obj) {
  2720. $pagenextid = $obj->pagenextid;
  2721. }
  2722. } else {
  2723. dol_print_error($db);
  2724. }
  2725. }
  2726. if ($pagepreviousid) {
  2727. print '<a class="valignmiddle" href="'.$_SERVER['PHP_SELF'].'?website='.urlencode($object->ref).'&pageid='.((int) $pagepreviousid).'&action='.urlencode($action).'&token='.newToken().'">'.img_previous($langs->trans("PreviousContainer")).'</a>';
  2728. } else {
  2729. print '<span class="valignmiddle opacitymedium">'.img_previous($langs->trans("PreviousContainer")).'</span>';
  2730. }
  2731. if ($pagenextid) {
  2732. print '<a class="valignmiddle" href="'.$_SERVER['PHP_SELF'].'?website='.urlencode($object->ref).'&pageid='.((int) $pagenextid).'&action='.urlencode($action).'&token='.newToken().'">'.img_next($langs->trans("NextContainer")).'</a>';
  2733. } else {
  2734. print '<span class="valignmiddle opacitymedium">'.img_next($langs->trans("NextContainer")).'</span>';
  2735. }
  2736. print '</span>';
  2737. if ($action == 'preview' || $action == 'createfromclone' || $action == 'createpagefromclone' || $action == 'deletesite') {
  2738. $disabled = '';
  2739. if (!$user->hasRight('website', 'write')) {
  2740. $disabled = ' disabled="disabled"';
  2741. }
  2742. // Confirmation delete site
  2743. if ($action == 'deletesite') {
  2744. // Create an array for form
  2745. $formquestion = array(
  2746. array('type' => 'checkbox', 'name' => 'delete_also_js', 'label' => $langs->trans("DeleteAlsoJs"), 'value' => 0),
  2747. array('type' => 'checkbox', 'name' => 'delete_also_medias', 'label' => $langs->trans("DeleteAlsoMedias"), 'value' => 0),
  2748. //array('type' => 'other','name' => 'newlang','label' => $langs->trans("Language"), 'value' => $formadmin->select_language(GETPOST('newlang', 'aZ09')?GETPOST('newlang', 'aZ09'):$langs->defaultlang, 'newlang', 0, null, '', 0, 0, 'minwidth200')),
  2749. //array('type' => 'other','name' => 'newwebsite','label' => $langs->trans("WebSite"), 'value' => $formwebsite->selectWebsite($object->id, 'newwebsite', 0))
  2750. );
  2751. if ($atleastonepage) {
  2752. $langs->load("errors");
  2753. $formquestion[] = array('type' => 'onecolumn', 'value' => '<div class="warning">'.$langs->trans("WarningPagesWillBeDeleted").'</div>');
  2754. }
  2755. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteWebsite'), '', 'confirm_deletesite', $formquestion, 0, 1, 210 + ($atleastonepage ? 70 : 0), 580);
  2756. print $formconfirm;
  2757. }
  2758. // Confirmation to clone
  2759. if ($action == 'createfromclone') {
  2760. // Create an array for form
  2761. $formquestion = array(
  2762. array('type' => 'text', 'name' => 'siteref', 'label'=> $langs->trans("WebSite"), 'value'=> 'copy_of_'.$object->ref)
  2763. );
  2764. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('CloneSite'), '', 'confirm_createfromclone', $formquestion, 0, 1, 200);
  2765. print $formconfirm;
  2766. }
  2767. if ($pageid > 0 && $atleastonepage) { // pageid can be set without pages, if homepage of site is set and all pages were removed
  2768. // Confirmation to clone
  2769. if ($action == 'createpagefromclone') {
  2770. // Create an array for form
  2771. $preselectedlanguage = GETPOST('newlang', 'aZ09') ? GETPOST('newlang', 'aZ09') : ''; // Dy default, we do not force any language on pages
  2772. $onlylang = array();
  2773. if ($website->otherlang) {
  2774. if (!empty($website->lang)) {
  2775. $onlylang[$website->lang] = $website->lang.' ('.$langs->trans("Default").')';
  2776. }
  2777. foreach (explode(',', $website->otherlang) as $langkey) {
  2778. if (empty(trim($langkey))) continue;
  2779. $onlylang[$langkey] = $langkey;
  2780. }
  2781. $textifempty = $langs->trans("Default");
  2782. } else {
  2783. $onlylang['none'] = 'none';
  2784. $textifempty = $langs->trans("Default");
  2785. }
  2786. $formquestion = array(
  2787. array('type' => 'hidden', 'name' => 'sourcepageurl', 'value'=> $objectpage->pageurl),
  2788. array('type' => 'other', 'tdclass'=>'fieldrequired', 'name' => 'newwebsite', 'label' => $langs->trans("WebSite"), 'value' => $formwebsite->selectWebsite($object->id, 'newwebsite', 0)),
  2789. array('type' => 'text', 'tdclass'=>'maxwidth200 fieldrequired', 'moreattr'=>'autofocus="autofocus"', 'name' => 'newtitle', 'label'=> $langs->trans("WEBSITE_TITLE"), 'value'=> $langs->trans("CopyOf").' '.$objectpage->title),
  2790. array('type' => 'text', 'tdclass'=>'maxwidth200', 'name' => 'newpageurl', 'label'=> $langs->trans("WEBSITE_PAGENAME"), 'value'=> '')
  2791. );
  2792. if (count($onlylang) > 1) {
  2793. $formquestion[] = array('type' => 'checkbox', 'tdclass'=>'maxwidth200', 'name' => 'is_a_translation', 'label' => $langs->trans("PageIsANewTranslation"), 'value' => 0, 'morecss'=>'margintoponly');
  2794. }
  2795. $value= $formadmin->select_language($preselectedlanguage, 'newlang', 0, null, $textifempty, 0, 0, 'minwidth200', 1, 0, 0, $onlylang, 1);
  2796. $formquestion[] = array('type' => 'other', 'name' => 'newlang', 'label' => $form->textwithpicto($langs->trans("Language"), $langs->trans("DefineListOfAltLanguagesInWebsiteProperties")), 'value' => $value);
  2797. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?website='.$object->ref.'&pageid='.$pageid, $langs->trans('ClonePage'), '', 'confirm_createpagefromclone', $formquestion, 0, 1, 300, 550);
  2798. print $formconfirm;
  2799. }
  2800. print '<span class="websiteselection">';
  2801. // Edit web page properties
  2802. print '<a href="'.$_SERVER["PHP_SELF"].'?website='.$object->ref.'&pageid='.$pageid.'&action=editmeta&token='.newToken().'" class="button bordertransp" title="'.dol_escape_htmltag($langs->trans("EditPageMeta")).'"'.$disabled.'><span class="fa fa-cog paddingrightonly"></span><span class="hideonsmartphone">'.dol_escape_htmltag($langs->trans("EditPageMeta")).'</span></a>';
  2803. // Edit HTML content
  2804. print '<a href="'.$_SERVER["PHP_SELF"].'?website='.$object->ref.'&pageid='.$pageid.'&action=editsource&token='.newToken().'" class="button bordertransp"'.$disabled.'>'.dol_escape_htmltag($langs->trans($conf->dol_optimize_smallscreen ? "HTML" : "EditHTMLSource")).'</a>';
  2805. // Edit CKEditor
  2806. if (getDolGlobalInt('WEBSITE_ALLOW_CKEDITOR')) {
  2807. print '<a href="'.$_SERVER["PHP_SELF"].'?website='.$object->ref.'&pageid='.$pageid.'&action=editcontent&token='.newToken().'" class="button bordertransp"'.$disabled.'>'.dol_escape_htmltag($langs->trans($conf->dol_optimize_smallscreen ? "CKEditor" : "CKEditor")).'</a>';
  2808. }
  2809. print '</span>';
  2810. // Switch include dynamic content / edit inline
  2811. print '<!-- button EditInLine and ShowSubcontainers -->'."\n";
  2812. print '<div class="websiteselectionsection inline-block">';
  2813. print '<div class="inline-block marginrightonly">'; // Button include dynamic contant
  2814. print $langs->trans("ShowSubcontainers");
  2815. if (empty($conf->global->WEBSITE_SUBCONTAINERSINLINE)) {
  2816. print '<a class="nobordertransp nohoverborder marginleftonlyshort valignmiddle"'.$disabled.' href="'.$_SERVER["PHP_SELF"].'?website='.$object->ref.'&pageid='.$websitepage->id.'&action=setshowsubcontainers&token='.newToken().'">'.img_picto($langs->trans("ShowSubContainersOnOff", $langs->transnoentitiesnoconv("Off")), 'switch_off', '', false, 0, 0, '', 'nomarginleft').'</a>';
  2817. } else {
  2818. print '<a class="nobordertransp nohoverborder marginleftonlyshort valignmiddle"'.$disabled.' href="'.$_SERVER["PHP_SELF"].'?website='.$object->ref.'&pageid='.$websitepage->id.'&action=unsetshowsubcontainers&token='.newToken().'">'.img_picto($langs->trans("ShowSubContainersOnOff", $langs->transnoentitiesnoconv("On")), 'switch_on', '', false, 0, 0, '', 'nomarginleft').'</a>';
  2819. }
  2820. print '</div>';
  2821. print '<div class="inline-block marginrightonly">'; // Button edit inline
  2822. print '<span id="switchckeditorinline">'."\n";
  2823. // Enable CKEditor inline with js on section and div with conteneditable=true
  2824. print '<!-- Code to enabled edit inline ckeditor -->'."\n";
  2825. print '<script type="text/javascript">
  2826. $(document).ready(function() {
  2827. var isEditingEnabled = '.(getDolGlobalString("WEBSITE_EDITINLINE") ? 'true' : 'false').';
  2828. if (isEditingEnabled)
  2829. {
  2830. switchEditorOnline(true);
  2831. }
  2832. $( "#switchckeditorinline" ).click(function() {
  2833. switchEditorOnline();
  2834. });
  2835. function switchEditorOnline(forceenable)
  2836. {
  2837. if (! isEditingEnabled || forceenable)
  2838. {
  2839. console.log("Enable inline edit");
  2840. jQuery(\'section[contenteditable="true"],div[contenteditable="true"]\').each(function(idx){
  2841. var idtouse = $(this).attr(\'id\');
  2842. console.log("Enable inline edit for "+idtouse);
  2843. if (idtouse !== undefined) {
  2844. var inlineditor = CKEDITOR.inline(idtouse, {
  2845. // Allow some non-standard markup that we used in the introduction.
  2846. // + a[target];div{float,display} ?
  2847. extraAllowedContent: \'span(*);cite(*);q(*);dl(*);dt(*);dd(*);ul(*);li(*);header(*);button(*);h1(*);h2(*);\',
  2848. //extraPlugins: \'sourcedialog\',
  2849. removePlugins: \'flash,stylescombo,exportpdf,scayt,wsc,pagebreak,iframe,smiley\',
  2850. // Show toolbar on startup (optional).
  2851. // startupFocus: true
  2852. });
  2853. // Custom bar tool
  2854. // Note the Source tool does not work on inline
  2855. inlineditor.config.toolbar = [
  2856. [\'Templates\',\'NewPage\'],
  2857. [\'Save\'],
  2858. [\'Maximize\',\'Preview\'],
  2859. [\'PasteText\'],
  2860. [\'Undo\',\'Redo\',\'-\',\'Find\',\'Replace\',\'-\',\'SelectAll\',\'RemoveFormat\'],
  2861. [\'CreateDiv\',\'ShowBlocks\'],
  2862. [\'Form\', \'Checkbox\', \'Radio\', \'TextField\', \'Textarea\', \'Select\', \'Button\', \'ImageButton\', \'HiddenField\'],
  2863. [\'Bold\',\'Italic\',\'Underline\',\'Strike\',\'Superscript\'],
  2864. [\'NumberedList\',\'BulletedList\',\'-\',\'Outdent\',\'Indent\',\'Blockquote\'],
  2865. [\'JustifyLeft\',\'JustifyCenter\',\'JustifyRight\',\'JustifyBlock\'],
  2866. [\'Link\',\'Unlink\'],
  2867. [\'Image\',\'Table\',\'HorizontalRule\'],
  2868. [\'Styles\',\'Format\',\'Font\',\'FontSize\'],
  2869. [\'TextColor\',\'BGColor\']
  2870. ];
  2871. // Start editor
  2872. //inlineditor.on(\'instanceReady\', function () {
  2873. // ...
  2874. //});
  2875. }
  2876. })
  2877. isEditingEnabled = true;
  2878. } else {
  2879. console.log("Disable inline edit");
  2880. for(name in CKEDITOR.instances) {
  2881. CKEDITOR.instances[name].destroy(true);
  2882. }
  2883. isEditingEnabled = false;
  2884. }
  2885. }
  2886. });
  2887. </script>';
  2888. print $langs->trans("EditInLine");
  2889. print '</span>';
  2890. //$disableeditinline = $websitepage->grabbed_from;
  2891. $disableeditinline = 0;
  2892. if ($disableeditinline) {
  2893. //print '<input type="submit" class="button bordertransp" disabled="disabled" title="'.dol_escape_htmltag($langs->trans("OnlyEditionOfSourceForGrabbedContent")).'" value="'.dol_escape_htmltag($langs->trans("EditWithEditor")).'" name="editcontent">';
  2894. print '<a class="nobordertransp opacitymedium nohoverborder marginleftonlyshort"'.$disabled.' href="#" disabled="disabled" title="'.dol_escape_htmltag($langs->trans("OnlyEditionOfSourceForGrabbedContent")).'">'.img_picto($langs->trans("OnlyEditionOfSourceForGrabbedContent"), 'switch_off', '', false, 0, 0, '', 'nomarginleft').'</a>';
  2895. } else {
  2896. //print '<input type="submit" class="button nobordertransp"'.$disabled.' value="'.dol_escape_htmltag($langs->trans("EditWithEditor")).'" name="editcontent">';
  2897. if (empty($conf->global->WEBSITE_EDITINLINE)) {
  2898. print '<a class="nobordertransp nohoverborder marginleftonlyshort valignmiddle"'.$disabled.' href="'.$_SERVER["PHP_SELF"].'?website='.$object->ref.'&pageid='.$websitepage->id.'&action=seteditinline&token='.newToken().'">'.img_picto($langs->trans("EditInLineOnOff", $langs->transnoentitiesnoconv("Off")), 'switch_off', '', false, 0, 0, '', 'nomarginleft').'</a>';
  2899. } else {
  2900. print '<a class="nobordertransp nohoverborder marginleftonlyshort valignmiddle"'.$disabled.' href="'.$_SERVER["PHP_SELF"].'?website='.$object->ref.'&pageid='.$websitepage->id.'&action=unseteditinline&token='.newToken().'">'.img_picto($langs->trans("EditInLineOnOff", $langs->transnoentitiesnoconv("On")), 'switch_on', '', false, 0, 0, '', 'nomarginleft').'</a>';
  2901. }
  2902. }
  2903. print '</div>';
  2904. print '</div>';
  2905. // Set page as homepage
  2906. print '<span class="websiteselection">';
  2907. if ($object->fk_default_home > 0 && $pageid == $object->fk_default_home) {
  2908. //$disabled=' disabled="disabled"';
  2909. //print '<span class="button bordertransp disabled"'.$disabled.' title="'.dol_escape_htmltag($langs->trans("SetAsHomePage")).'"><span class="fas fa-home"></span></span>';
  2910. //print '<input type="submit" class="button bordertransp" disabled="disabled" value="'.dol_escape_htmltag($langs->trans("SetAsHomePage")).'" name="setashome">';
  2911. print '<a href="#" class="button bordertransp disabled" disabled="disabled" title="'.dol_escape_htmltag($langs->trans("SetAsHomePage")).'"><span class="fas fa-home valignmiddle btnTitle-icon"></span></a>';
  2912. } else {
  2913. //$disabled='';
  2914. //print '<input type="submit" class="button bordertransp"'.$disabled.' value="'.dol_escape_htmltag($langs->trans("SetAsHomePage")).'" name="setashome">';
  2915. print '<a href="'.$_SERVER["PHP_SELF"].'?action=setashome&token='.newToken().'&website='.urlencode($website->ref).'&pageid='.((int) $pageid).'" class="button bordertransp"'.$disabled.' title="'.dol_escape_htmltag($langs->trans("SetAsHomePage")).'"><span class="fas fa-home valignmiddle btnTitle-icon"></span></a>';
  2916. }
  2917. print '<input type="submit" class="button bordertransp"'.$disabled.' value="'.dol_escape_htmltag($langs->trans("ClonePage")).'" name="createpagefromclone">';
  2918. // Delete
  2919. if ($websitepage->status != $websitepage::STATUS_DRAFT) {
  2920. $disabled = ' disabled="disabled"';
  2921. $title = $langs->trans("WebpageMustBeDisabled", $langs->transnoentitiesnoconv($websitepage->LibStatut(0, 0)));
  2922. $url = '#';
  2923. } else {
  2924. $disabled = '';
  2925. $title = '';
  2926. $url = $_SERVER["PHP_SELF"].'?action=delete&token='.newToken().'&pageid='.((int) $websitepage->id).'&website='.urlencode($website->ref); // action=delete for webpage, deletesite for website
  2927. }
  2928. print '<a href="'.$url.'" class="button buttonDelete bordertransp'.($disabled ? ' disabled' : '').'"'.$disabled.' title="'.dol_escape_htmltag($title).'">'.img_picto('', 'delete', 'class=""').'<span class="hideonsmartphone paddingleft">'.$langs->trans("Delete").'</span></a>';
  2929. print '</span>';
  2930. }
  2931. }
  2932. //print '</span>'; // end website selection
  2933. print '<span class="websitetools">';
  2934. if (($pageid > 0 && $atleastonepage) && ($action == 'preview' || $action == 'createfromclone' || $action == 'createpagefromclone' || $action == 'deletesite')) {
  2935. $realpage = $urlwithroot.'/public/website/index.php?website='.$websitekey.'&pageref='.$websitepage->pageurl;
  2936. $pagealias = $websitepage->pageurl;
  2937. $htmltext = $langs->trans("PreviewSiteServedByDolibarr", $langs->transnoentitiesnoconv("Page"), $langs->transnoentitiesnoconv("Page"), $realpage, $dataroot);
  2938. $htmltext .= '<br>'.$langs->trans("CheckVirtualHostPerms", $langs->transnoentitiesnoconv("ReadPerm"), '{s1}');
  2939. $htmltext = str_replace('{s1}', $dataroot.'<br>'.DOL_DATA_ROOT.'/medias<br>'.DOL_DOCUMENT_ROOT, $htmltext);
  2940. //$htmltext .= '<br>'.$langs->trans("CheckVirtualHostPerms", $langs->transnoentitiesnoconv("WritePerm"), '{s1}');
  2941. //$htmltext = str_replace('{s1}', DOL_DATA_ROOT.'/medias', $htmltext);
  2942. print '<div class="websiteinputurl inline-block paddingright">';
  2943. print '<a class="websitebuttonsitepreview inline-block" id="previewpage" href="'.$realpage.'&nocache='.dol_now().'" class="button" target="tab'.$websitekey.'" alt="'.dol_escape_htmltag($htmltext).'">';
  2944. print $form->textwithpicto('', $htmltext, 1, 'preview');
  2945. print '</a>'; // View page in new Tab
  2946. print '</div>';
  2947. /*print '<div class="websiteinputurl inline-block" id="websiteinputpage">';
  2948. print '<input type="text" id="previewpageurl" class="minwidth200imp" name="previewsite" value="'.$pagealias.'" disabled="disabled">';
  2949. $htmltext = $langs->trans("PageNameAliasHelp", $langs->transnoentitiesnoconv("EditPageMeta"));
  2950. print $form->textwithpicto('', $htmltext, 1, 'help', '', 0, 2, 'helppagealias');
  2951. print '</div>';*/
  2952. /*
  2953. $urlext = $virtualurl.'/'.$pagealias.'.php';
  2954. $urlint = $urlwithroot.'/public/website/index.php?website='.$websitekey;
  2955. $htmltext = $langs->trans("PreviewSiteServedByWebServer", $langs->transnoentitiesnoconv("Page"), $langs->transnoentitiesnoconv("Page"), $dataroot, $virtualurl ? $urlext : '<span class="error">'.$langs->trans("VirtualHostUrlNotDefined").'</span>');
  2956. print '<a class="websitebuttonsitepreview'.($virtualurl ? '' : ' websitebuttonsitepreviewdisabled cursornotallowed').'" id="previewpageext" href="'.$urlext.'" target="tab'.$websitekey.'ext" alt="'.dol_escape_htmltag($htmltext).'">';
  2957. print $form->textwithpicto('', $htmltext, 1, 'preview_ext');
  2958. print '</a>';
  2959. */
  2960. //print '<input type="submit" class="button" name="previewpage" target="tab'.$websitekey.'"value="'.$langs->trans("ViewPageInNewTab").'">';
  2961. // TODO Add js to save alias like we save virtual host name and use dynamic virtual host for url of id=previewpageext
  2962. }
  2963. if (!in_array($mode, array('replacesite')) && !in_array($action, array('editcss', 'editmenu', 'file_manager', 'replacesiteconfirm', 'createsite', 'createcontainer', 'createfromclone', 'createpagefromclone', 'deletesite'))) {
  2964. if ($action == 'editsource' || $action == 'editmeta') {
  2965. print '<input type="submit" id="savefileandstay" class="button buttonforacesave hideonsmartphone small" value="'.dol_escape_htmltag($langs->trans("SaveAndStay")).'" name="updateandstay">';
  2966. }
  2967. if (preg_match('/^create/', $action)) {
  2968. print '<input type="submit" id="savefile" class="button buttonforacesave button-save small" value="'.dol_escape_htmltag($langs->trans("Save")).'" name="update">';
  2969. }
  2970. if (preg_match('/^edit/', $action)) {
  2971. print '<input type="submit" id="savefile" class="button buttonforacesave button-save small" value="'.dol_escape_htmltag($langs->trans("Save")).'" name="update">';
  2972. }
  2973. if ($action != 'preview') {
  2974. print '<input type="submit" class="button button-cancel small" value="'.dol_escape_htmltag($langs->trans("Cancel")).'" name="cancel">';
  2975. }
  2976. }
  2977. print '</span>'; // end websitetools
  2978. print '<span class="websitehelp">';
  2979. if ($action == 'editsource' || $action == 'editcontent' || GETPOST('editsource', 'alpha') || GETPOST('editcontent', 'alpha')) {
  2980. $url = 'https://wiki.dolibarr.org/index.php/Module_Website';
  2981. $htmltext = $langs->transnoentitiesnoconv("YouCanEditHtmlSource", $url);
  2982. $htmltext .= $langs->transnoentitiesnoconv("YouCanEditHtmlSource2", $url);
  2983. $htmltext .= $langs->transnoentitiesnoconv("YouCanEditHtmlSourceMore", $url);
  2984. $htmltext .= '<br>';
  2985. if ($conf->browser->layout == 'phone') {
  2986. print $form->textwithpicto('', $htmltext, 1, 'help', 'inline-block', 1, 2, 'tooltipsubstitution');
  2987. } else {
  2988. //img_help(($tooltiptrigger != '' ? 2 : 1), $alt)
  2989. print $form->textwithpicto($langs->trans("SyntaxHelp").' '.img_help(2, $langs->trans("SyntaxHelp")), $htmltext, 1, 'none', 'inline-block', 1, 2, 'tooltipsubstitution');
  2990. }
  2991. }
  2992. print '</span>'; // end websitehelp
  2993. if ($action == 'preview' || $action == 'createfromclone' || $action == 'createpagefromclone') {
  2994. // Adding jquery code to change on the fly url of preview ext
  2995. if (!empty($conf->use_javascript_ajax)) {
  2996. print '<script type="text/javascript">
  2997. jQuery(document).ready(function() {
  2998. jQuery("#websiteinputurl").keyup(function() {
  2999. console.log("Website external url modified "+jQuery("#previewsiteurl").val());
  3000. if (jQuery("#previewsiteurl").val() != "" && jQuery("#previewsiteurl").val().startsWith("http"))
  3001. {
  3002. jQuery("a.websitebuttonsitepreviewdisabled img").css({ opacity: 1 });
  3003. }
  3004. else jQuery("a.websitebuttonsitepreviewdisabled img").css({ opacity: 0.2 });
  3005. ';
  3006. print '
  3007. });
  3008. jQuery("#previewsiteext,#previewpageext").click(function() {
  3009. newurl=jQuery("#previewsiteurl").val();
  3010. if (! newurl.startsWith("http"))
  3011. {
  3012. alert(\''.dol_escape_js($langs->trans("ErrorURLMustStartWithHttp")).'\');
  3013. return false;
  3014. }
  3015. newpage=jQuery("#previewsiteurl").val() + "/" + jQuery("#previewpageurl").val() + ".php";
  3016. console.log("Open url "+newurl);
  3017. /* Save url */
  3018. jQuery.ajax({
  3019. method: "POST",
  3020. url: "'.DOL_URL_ROOT.'/core/ajax/saveinplace.php",
  3021. data: {
  3022. field: \'editval_virtualhost\',
  3023. element: \'website\',
  3024. table_element: \'website\',
  3025. fk_element: '.((int) $object->id).',
  3026. value: newurl,
  3027. },
  3028. context: document.body
  3029. });
  3030. jQuery("#previewsiteext").attr("href",newurl);
  3031. jQuery("#previewpageext").attr("href",newpage);
  3032. });
  3033. });
  3034. </script>';
  3035. }
  3036. }
  3037. }
  3038. print '</div>'; // end current websitebar
  3039. }
  3040. $head = array();
  3041. /*
  3042. * Edit Site HTML header and CSS
  3043. */
  3044. if ($action == 'editcss') {
  3045. print '<div class="fiche">';
  3046. print '<br>';
  3047. if (!GETPOSTISSET('WEBSITE_CSS_INLINE')) {
  3048. $csscontent = @file_get_contents($filecss);
  3049. // Clean the php css file to remove php code and get only css part
  3050. $csscontent = preg_replace('/<\?php \/\/ BEGIN PHP[^\?]*END PHP \?>\n*/ims', '', $csscontent);
  3051. } else {
  3052. $csscontent = GETPOST('WEBSITE_CSS_INLINE', 'none');
  3053. }
  3054. if (!trim($csscontent)) {
  3055. $csscontent = '/* CSS content (all pages) */'."\nbody.bodywebsite { margin: 0; font-family: 'Open Sans', sans-serif; }\n.bodywebsite h1 { margin-top: 0; margin-bottom: 0; padding: 10px;}";
  3056. }
  3057. if (!GETPOSTISSET('WEBSITE_JS_INLINE')) {
  3058. $jscontent = @file_get_contents($filejs);
  3059. // Clean the php js file to remove php code and get only js part
  3060. $jscontent = preg_replace('/<\?php \/\/ BEGIN PHP[^\?]*END PHP \?>\n*/ims', '', $jscontent);
  3061. } else {
  3062. $jscontent = GETPOST('WEBSITE_JS_INLINE', 'none');
  3063. }
  3064. if (!trim($jscontent)) {
  3065. $jscontent = '/* JS content (all pages) */'."\n";
  3066. }
  3067. if (!GETPOSTISSET('WEBSITE_HTML_HEADER')) {
  3068. $htmlheadercontent = @file_get_contents($filehtmlheader);
  3069. // Clean the php htmlheader file to remove php code and get only html part
  3070. $htmlheadercontent = preg_replace('/<\?php \/\/ BEGIN PHP[^\?]*END PHP \?>\n*/ims', '', $htmlheadercontent);
  3071. } else {
  3072. $htmlheadercontent = GETPOST('WEBSITE_HTML_HEADER', 'none');
  3073. }
  3074. if (!trim($htmlheadercontent)) {
  3075. $htmlheadercontent = "<html>\n";
  3076. $htmlheadercontent .= $htmlheadercontentdefault;
  3077. $htmlheadercontent .= "</html>";
  3078. } else {
  3079. $htmlheadercontent = preg_replace('/^\s*<html>/ims', '', $htmlheadercontent);
  3080. $htmlheadercontent = preg_replace('/<\/html>\s*$/ims', '', $htmlheadercontent);
  3081. $htmlheadercontent = '<html>'."\n".trim($htmlheadercontent)."\n".'</html>';
  3082. }
  3083. if (!GETPOSTISSET('WEBSITE_ROBOT')) {
  3084. $robotcontent = @file_get_contents($filerobot);
  3085. // Clean the php htmlheader file to remove php code and get only html part
  3086. $robotcontent = preg_replace('/<\?php \/\/ BEGIN PHP[^\?]*END PHP \?>\n*/ims', '', $robotcontent);
  3087. } else {
  3088. $robotcontent = GETPOST('WEBSITE_ROBOT', 'nothtml');
  3089. }
  3090. if (!trim($robotcontent)) {
  3091. $robotcontent .= "# Robot file. Generated with ".DOL_APPLICATION_TITLE."\n";
  3092. $robotcontent .= "User-agent: *\n";
  3093. $robotcontent .= "Allow: /public/\n";
  3094. $robotcontent .= "Disallow: /administrator/\n";
  3095. }
  3096. if (!GETPOSTISSET('WEBSITE_HTACCESS')) {
  3097. $htaccesscontent = @file_get_contents($filehtaccess);
  3098. // Clean the php htaccesscontent file to remove php code and get only html part
  3099. $htaccesscontent = preg_replace('/<\?php \/\/ BEGIN PHP[^\?]*END PHP \?>\n*/ims', '', $htaccesscontent);
  3100. } else {
  3101. $htaccesscontent = GETPOST('WEBSITE_HTACCESS', 'nohtml'); // We must use 'nohtml' and not 'alphanohtml' because we must accept "
  3102. }
  3103. if (!trim($htaccesscontent)) {
  3104. $htaccesscontent .= "# Order allow,deny\n";
  3105. $htaccesscontent .= "# Deny from all\n";
  3106. }
  3107. if (!GETPOSTISSET('WEBSITE_MANIFEST_JSON')) {
  3108. $manifestjsoncontent = @file_get_contents($filemanifestjson);
  3109. // Clean the manifestjson file to remove php code and get only html part
  3110. $manifestjsoncontent = preg_replace('/<\?php \/\/ BEGIN PHP[^\?]*END PHP \?>\n*/ims', '', $manifestjsoncontent);
  3111. } else {
  3112. $manifestjsoncontent = GETPOST('WEBSITE_MANIFEST_JSON', 'restricthtml');
  3113. }
  3114. if (!trim($manifestjsoncontent)) {
  3115. //$manifestjsoncontent.="";
  3116. }
  3117. if (!GETPOSTISSET('WEBSITE_README')) {
  3118. $readmecontent = @file_get_contents($filereadme);
  3119. // Clean the readme file to remove php code and get only html part
  3120. $readmecontent = preg_replace('/<\?php \/\/ BEGIN PHP[^\?]*END PHP \?>\n*/ims', '', $readmecontent);
  3121. } else {
  3122. $readmecontent = GETPOST('WEBSITE_README', 'none');
  3123. }
  3124. if (!trim($readmecontent)) {
  3125. //$readmecontent.="";
  3126. }
  3127. if (!GETPOSTISSET('WEBSITE_LICENSE')) {
  3128. $licensecontent = @file_get_contents($filelicense);
  3129. // Clean the readme file to remove php code and get only html part
  3130. $licensecontent = preg_replace('/<\?php \/\/ BEGIN PHP[^\?]*END PHP \?>\n*/ims', '', $licensecontent);
  3131. } else {
  3132. $licensecontent = GETPOST('WEBSITE_LICENSE', 'none');
  3133. }
  3134. if (!trim($licensecontent)) {
  3135. //$readmecontent.="";
  3136. }
  3137. print dol_get_fiche_head();
  3138. print '<!-- Edit Website properties -->'."\n";
  3139. print '<table class="border centpercent">';
  3140. // Website
  3141. print '<tr><td class="titlefieldcreate fieldrequired">';
  3142. print $langs->trans('WebSite');
  3143. print '</td><td>';
  3144. print $websitekey;
  3145. print '</td></tr>';
  3146. // Status of web site
  3147. if ($action != 'createcontainer') {
  3148. if (empty($conf->use_javascript_ajax)) {
  3149. print '<!-- Status of web site page -->'."\n";
  3150. print '<tr><td class="fieldrequired">';
  3151. print $langs->trans('Status');
  3152. print '</td><td>';
  3153. print $form->selectyesno('status', $object->status);
  3154. print '</td></tr>';
  3155. }
  3156. }
  3157. // Main language
  3158. print '<tr><td class="tdtop fieldrequired">';
  3159. $htmltext = '';
  3160. print $form->textwithpicto($langs->trans('MainLanguage'), $htmltext, 1, 'help', '', 0, 2, 'WEBSITE_LANG');
  3161. print '</td><td>';
  3162. print img_picto('', 'language', 'class="picotfixedwidth"');
  3163. print $formadmin->select_language((GETPOSTISSET('WEBSITE_LANG') ? GETPOST('WEBSITE_LANG', 'aZ09comma') : ($object->lang ? $object->lang : '0')), 'WEBSITE_LANG', 0, null, 1, 0, 0, 'minwidth300', 2, 0, 0, array(), 1);
  3164. print '</td>';
  3165. print '</tr>';
  3166. // Other languages
  3167. print '<tr><td class="tdtop">';
  3168. $htmltext = $langs->trans("Example").': fr,de,sv,it,pt';
  3169. print $form->textwithpicto($langs->trans('OtherLanguages'), $htmltext, 1, 'help', '', 0, 2);
  3170. print '</td><td>';
  3171. print img_picto('', 'language', 'class="picotfixedwidth"');
  3172. print '<input type="text" class="flat" value="'.(GETPOSTISSET('WEBSITE_OTHERLANG') ? GETPOST('WEBSITE_OTHERLANG', 'alpha') : $object->otherlang).'" name="WEBSITE_OTHERLANG">';
  3173. print '</td>';
  3174. print '</tr>';
  3175. // VirtualHost
  3176. print '<tr><td class="tdtop">';
  3177. $htmltext = $langs->trans("VirtualhostDesc");
  3178. print $form->textwithpicto($langs->trans('Virtualhost'), $htmltext, 1, 'help', '', 0, 2, 'virtualhosttooltip');
  3179. print '</td><td>';
  3180. print '<input type="text" class="flat minwidth300" value="'.(GETPOSTISSET('virtualhost') ? GETPOST('virtualhost', 'alpha') : $virtualurl).'" name="virtualhost">';
  3181. print '</td>';
  3182. print '</tr>';
  3183. // Favicon
  3184. print '<tr><td>';
  3185. print $form->textwithpicto($langs->trans('ImportFavicon'), $langs->trans('FaviconTooltip'));
  3186. print '</td><td>';
  3187. $maxfilesizearray = getMaxFileSizeArray();
  3188. $maxmin = $maxfilesizearray['maxmin'];
  3189. if ($maxmin > 0) {
  3190. print '<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).'">'; // MAX_FILE_SIZE must precede the field type=file
  3191. }
  3192. print '<input type="file" class="flat minwidth300" name="addedfile" id="addedfile"/>';
  3193. $uploadfolder = $conf->website->dir_output.'/'.$websitekey;
  3194. if (dol_is_file($uploadfolder.'/favicon.png')) {
  3195. print '<div class="inline-block valignmiddle marginrightonly">';
  3196. print '<img style="max-height: 80px" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart=website&file='.$websitekey.'/favicon.png">';
  3197. print '</div>';
  3198. }
  3199. print '</tr></td>';
  3200. // CSS file
  3201. print '<tr><td class="tdtop">';
  3202. $htmlhelp = $langs->trans("CSSContentTooltipHelp");
  3203. print $form->textwithpicto($langs->trans('WEBSITE_CSS_INLINE'), $htmlhelp, 1, 'help', '', 0, 2, 'csstooltip');
  3204. print '</td><td>';
  3205. $poscursor = array('x'=>GETPOST('WEBSITE_CSS_INLINE_x'), 'y'=>GETPOST('WEBSITE_CSS_INLINE_y'));
  3206. $doleditor = new DolEditor('WEBSITE_CSS_INLINE', $csscontent, '', '220', 'ace', 'In', true, false, 'ace', 0, '100%', '', $poscursor);
  3207. print $doleditor->Create(1, '', true, 'CSS', 'css');
  3208. print '</td></tr>';
  3209. // JS file
  3210. print '<tr><td class="tdtop">';
  3211. $textwithhelp = $langs->trans('WEBSITE_JS_INLINE');
  3212. $htmlhelp2 = $langs->trans("LinkAndScriptsHereAreNotLoadedInEditor").'<br>';
  3213. print $form->textwithpicto($textwithhelp, $htmlhelp2, 1, 'warning', '', 0, 2, 'htmljstooltip2');
  3214. print '</td><td>';
  3215. $poscursor = array('x'=>GETPOST('WEBSITE_JS_INLINE_x'), 'y'=>GETPOST('WEBSITE_JS_INLINE_y'));
  3216. $doleditor = new DolEditor('WEBSITE_JS_INLINE', $jscontent, '', '220', 'ace', 'In', true, false, 'ace', 0, '100%', '', $poscursor);
  3217. print $doleditor->Create(1, '', true, 'JS', 'javascript');
  3218. print '</td></tr>';
  3219. // Common HTML header
  3220. print '<tr><td class="tdtop">';
  3221. print $langs->trans('WEBSITE_HTML_HEADER');
  3222. $htmlhelp = $langs->trans("Example").' :<br>';
  3223. $htmlhelp .= dol_htmlentitiesbr($htmlheadercontentdefault);
  3224. $textwithhelp = $form->textwithpicto('', $htmlhelp, 1, 'help', '', 0, 2, 'htmlheadertooltip');
  3225. $htmlhelp2 = $langs->trans("LinkAndScriptsHereAreNotLoadedInEditor").'<br>';
  3226. print $form->textwithpicto($textwithhelp, $htmlhelp2, 1, 'warning', '', 0, 2, 'htmlheadertooltip2');
  3227. print '</td><td>';
  3228. $poscursor = array('x'=>GETPOST('WEBSITE_HTML_HEADER_x'), 'y'=>GETPOST('WEBSITE_HTML_HEADER_y'));
  3229. $doleditor = new DolEditor('WEBSITE_HTML_HEADER', $htmlheadercontent, '', '220', 'ace', 'In', true, false, 'ace', 0, '100%', '', $poscursor);
  3230. print $doleditor->Create(1, '', true, 'HTML Header', 'html');
  3231. print '</td></tr>';
  3232. // Robot file
  3233. print '<tr><td class="tdtop">';
  3234. print $langs->trans('WEBSITE_ROBOT');
  3235. print '</td><td>';
  3236. $poscursor = array('x'=>GETPOST('WEBSITE_ROBOT_x'), 'y'=>GETPOST('WEBSITE_ROBOT_y'));
  3237. $doleditor = new DolEditor('WEBSITE_ROBOT', $robotcontent, '', '220', 'ace', 'In', true, false, 'ace', 0, '100%', '', $poscursor);
  3238. print $doleditor->Create(1, '', true, 'Robot file', 'text');
  3239. print '</td></tr>';
  3240. // .htaccess
  3241. print '<tr><td class="tdtop">';
  3242. print $langs->trans('WEBSITE_HTACCESS');
  3243. print '</td><td>';
  3244. $poscursor = array('x'=>GETPOST('WEBSITE_HTACCESS_x'), 'y'=>GETPOST('WEBSITE_HTACCESS_y'));
  3245. $doleditor = new DolEditor('WEBSITE_HTACCESS', $htaccesscontent, '', '220', 'ace', 'In', true, false, 'ace', 0, '100%', '', $poscursor);
  3246. print $doleditor->Create(1, '', true, $langs->trans("File").' .htaccess', 'text');
  3247. print '</td></tr>';
  3248. // Manifest.json
  3249. print '<tr><td class="tdtop">';
  3250. $htmlhelp = $langs->trans("Example").' :<br>';
  3251. $htmlhelp .= '<small>'.dol_htmlentitiesbr($manifestjsoncontentdefault).'</small>';
  3252. print $form->textwithpicto($langs->trans('WEBSITE_MANIFEST_JSON'), $htmlhelp, 1, 'help', '', 0, 2, 'manifestjsontooltip');
  3253. print '</td><td>';
  3254. print $langs->trans("UseManifest").': '.$form->selectyesno('use_manifest', $website->use_manifest, 1).'<br>';
  3255. $poscursor = array('x'=>GETPOST('WEBSITE_MANIFEST_JSON_x'), 'y'=>GETPOST('WEBSITE_MANIFEST_JSON_y'));
  3256. $doleditor = new DolEditor('WEBSITE_MANIFEST_JSON', $manifestjsoncontent, '', '220', 'ace', 'In', true, false, 'ace', 0, '100%', '', $poscursor);
  3257. print $doleditor->Create(1, '', true, $langs->trans("File").' manifest.json', 'text');
  3258. print '</td></tr>';
  3259. // README.md
  3260. print '<tr><td class="tdtop">';
  3261. $htmlhelp = $langs->trans("EnterHereReadmeInformation");
  3262. print $form->textwithpicto($langs->trans("File").' README.md', $htmlhelp, 1, 'help', '', 0, 2, 'readmetooltip');
  3263. print '</td><td>';
  3264. $poscursor = array('x'=>GETPOST('WEBSITE_README_x'), 'y'=>GETPOST('WEBSITE_README_y'));
  3265. $doleditor = new DolEditor('WEBSITE_README', $readmecontent, '', '220', 'ace', 'In', true, false, 'ace', 0, '100%', '', $poscursor);
  3266. print $doleditor->Create(1, '', true, $langs->trans("File").' README.md', 'text');
  3267. print '</td></tr>';
  3268. // LICENSE
  3269. print '<tr><td class="tdtop">';
  3270. $htmlhelp = $langs->trans("EnterHereLicenseInformation");
  3271. print $form->textwithpicto($langs->trans("File").' LICENSE', $htmlhelp, 1, 'help', '', 0, 2, 'licensetooltip');
  3272. print '</td><td>';
  3273. $poscursor = array('x'=>GETPOST('WEBSITE_LICENSE_x'), 'y'=>GETPOST('WEBSITE_LICENSE_y'));
  3274. $doleditor = new DolEditor('WEBSITE_LICENSE', $licensecontent, '', '220', 'ace', 'In', true, false, 'ace', 0, '100%', '', $poscursor);
  3275. print $doleditor->Create(1, '', true, $langs->trans("File").' LICENSE', 'text');
  3276. print '</td></tr>';
  3277. // RSS
  3278. print '<tr><td class="tdtop">';
  3279. $htmlhelp = $langs->trans('RSSFeedDesc');
  3280. print $form->textwithpicto($langs->trans('RSSFeed'), $htmlhelp, 1, 'help', '', 0, 2, '');
  3281. print '</td><td>';
  3282. print '/wrapper.php?rss=1[&l=XX][&limit=123]';
  3283. print '</td></tr>';
  3284. print '</table>';
  3285. print dol_get_fiche_end();
  3286. print '</div>';
  3287. print '<br>';
  3288. }
  3289. if ($action == 'createsite') {
  3290. print '<div class="fiche">';
  3291. print '<br>';
  3292. /*$h = 0;
  3293. $head = array();
  3294. $head[$h][0] = dol_buildpath('/website/index.php',1).'?id='.$object->id;
  3295. $head[$h][1] = $langs->trans("AddSite");
  3296. $head[$h][2] = 'card';
  3297. $h++;
  3298. print dol_get_fiche_head($head, 'card', $langs->trans("AddSite"), -1, 'globe');
  3299. */
  3300. if ($action == 'createcontainer') {
  3301. print load_fiche_titre($langs->trans("AddSite"));
  3302. }
  3303. print '<!-- Add site -->'."\n";
  3304. print '<div class="tabBar tabBarWithBottom">';
  3305. print '<table class="border centpercent">';
  3306. $siteref = $sitedesc = $sitelang = $siteotherlang = '';
  3307. if (GETPOST('WEBSITE_REF')) {
  3308. $siteref = GETPOST('WEBSITE_REF', 'aZ09');
  3309. }
  3310. if (GETPOST('WEBSITE_DESCRIPTION')) {
  3311. $sitedesc = GETPOST('WEBSITE_DESCRIPTION', 'alpha');
  3312. }
  3313. if (GETPOST('WEBSITE_LANG')) {
  3314. $sitelang = GETPOST('WEBSITE_LANG', 'aZ09');
  3315. }
  3316. if (GETPOST('WEBSITE_OTHERLANG')) {
  3317. $siteotherlang = GETPOST('WEBSITE_OTHERLANG', 'aZ09comma');
  3318. }
  3319. print '<tr><td class="titlefieldcreate fieldrequired">';
  3320. print $form->textwithpicto($langs->trans('WebsiteName'), $langs->trans("Example").': MyPortal, www.mywebsite.com, ...');
  3321. print '</td><td>';
  3322. print '<input type="text" class="flat maxwidth300" name="WEBSITE_REF" value="'.dol_escape_htmltag($siteref).'" autofocus>';
  3323. print '</td></tr>';
  3324. print '<tr><td class="fieldrequired">';
  3325. print $langs->trans('MainLanguage');
  3326. print '</td><td>';
  3327. $shortlangcode = preg_replace('/[_-].*$/', '', trim($langs->defaultlang));
  3328. print img_picto('', 'language', 'class="pictofixedwidth"');
  3329. print $formadmin->select_language((GETPOSTISSET('WEBSITE_LANG') ? GETPOST('WEBSITE_LANG', 'aZ09comma') : $shortlangcode), 'WEBSITE_LANG', 0, null, 1, 0, 0, 'minwidth300', 2, 0, 0, array(), 1);
  3330. print '</td></tr>';
  3331. print '<tr><td>';
  3332. $htmltext = $langs->trans("Example").': fr,de,sv,it,pt';
  3333. print $form->textwithpicto($langs->trans('OtherLanguages'), $htmltext, 1, 'help', '', 0, 2);
  3334. print '</td><td>';
  3335. print img_picto('', 'language', 'class="pictofixedwidth"');
  3336. print '<input type="text" class="flat minwidth300" name="WEBSITE_OTHERLANG" value="'.dol_escape_htmltag($siteotherlang).'">';
  3337. print '</td></tr>';
  3338. print '<tr><td>';
  3339. print $langs->trans('Description');
  3340. print '</td><td>';
  3341. print '<input type="text" class="flat minwidth500" name="WEBSITE_DESCRIPTION" value="'.dol_escape_htmltag($sitedesc).'">';
  3342. print '</td></tr>';
  3343. print '<tr><td>';
  3344. $htmltext = $langs->trans("VirtualhostDesc");
  3345. /*$htmltext = str_replace('{s1}', DOL_DATA_ROOT.($conf->entity > 1 ? '/'.$conf->entity : '').'/website/<i>websiteref</i>', $htmltext);
  3346. $htmltext .= '<br>';
  3347. $htmltext .= '<br>'.$langs->trans("CheckVirtualHostPerms", $langs->transnoentitiesnoconv("ReadPerm"), DOL_DOCUMENT_ROOT);
  3348. $htmltext .= '<br>'.$langs->trans("CheckVirtualHostPerms", $langs->transnoentitiesnoconv("WritePerm"), '{s1}');
  3349. $htmltext = str_replace('{s1}', DOL_DATA_ROOT.'/website<br>'.DOL_DATA_ROOT.'/medias', $htmltext);*/
  3350. print $form->textwithpicto($langs->trans('Virtualhost'), $htmltext, 1, 'help', '', 0, 2, '');
  3351. print '</td><td>';
  3352. print '<input type="text" class="flat minwidth300" name="virtualhost" value="'.dol_escape_htmltag(GETPOST('virtualhost', 'alpha')).'">';
  3353. print '</td></tr>';
  3354. print '</table>';
  3355. print '</div>';
  3356. if ($action == 'createsite') {
  3357. print '<div class="center">';
  3358. print '<input type="submit" class="button small" name="addcontainer" value="'.$langs->trans("Create").'">';
  3359. print '<input class="button button-cancel small" type="submit" name="preview" value="'.$langs->trans("Cancel").'">';
  3360. print '</div>';
  3361. }
  3362. //print '</div>';
  3363. //print dol_get_fiche_end();
  3364. print '</div>';
  3365. print '<br>';
  3366. }
  3367. if ($action == 'importsite') {
  3368. print '<div class="fiche">';
  3369. print '<br>';
  3370. print load_fiche_titre($langs->trans("ImportSite"));
  3371. print dol_get_fiche_head(array(), '0', '', -1);
  3372. print '<span class="opacitymedium">'.$langs->trans("ZipOfWebsitePackageToImport").'</span><br><br>';
  3373. $dolibarrdataroot = preg_replace('/([\\/]+)$/i', '', DOL_DATA_ROOT);
  3374. $allowimportsite = true;
  3375. if (dol_is_file($dolibarrdataroot.'/installmodules.lock')) {
  3376. $allowimportsite = false;
  3377. }
  3378. if ($allowimportsite) {
  3379. $maxfilesizearray = getMaxFileSizeArray();
  3380. $maxmin = $maxfilesizearray['maxmin'];
  3381. if ($maxmin > 0) {
  3382. print '<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).'">'; // MAX_FILE_SIZE must precede the field type=file
  3383. }
  3384. print '<input class="flat minwidth400" type="file" name="userfile[]" accept=".zip">';
  3385. print '<input type="submit" class="button small" name="buttonsubmitimportfile" value="'.dol_escape_htmltag($langs->trans("Upload")).'">';
  3386. print '<input type="submit" class="button button-cancel small" name="preview" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
  3387. print '<br><br><br>';
  3388. } else {
  3389. if (getDolGlobalString('MAIN_MESSAGE_INSTALL_MODULES_DISABLED_CONTACT_US')) {
  3390. // Show clean corporate message
  3391. $message = $langs->trans('InstallModuleFromWebHasBeenDisabledContactUs');
  3392. } else {
  3393. // Show technical generic message
  3394. $message = $langs->trans("InstallModuleFromWebHasBeenDisabledByFile", $dolibarrdataroot.'/installmodules.lock');
  3395. }
  3396. print info_admin($message).'<br><br>';
  3397. }
  3398. print '<span class="opacitymedium">'.$langs->trans("ZipOfWebsitePackageToLoad").'</span><br><br>';
  3399. showWebsiteTemplates($website);
  3400. print dol_get_fiche_end();
  3401. print '</div>';
  3402. print '<br>';
  3403. }
  3404. if ($action == 'editmeta' || $action == 'createcontainer') { // Edit properties of a web site OR properties of a web page
  3405. print '<div class="fiche">';
  3406. print '<br>';
  3407. /*$h = 0;
  3408. $head = array();
  3409. $head[$h][0] = dol_buildpath('/website/index.php',1).'?id='.$object->id;
  3410. $head[$h][1] = $langs->trans("AddPage");
  3411. $head[$h][2] = 'card';
  3412. $h++;
  3413. print dol_get_fiche_head($head, 'card', $langs->trans("AddPage"), -1, 'globe');
  3414. */
  3415. if ($action == 'createcontainer') {
  3416. print load_fiche_titre($langs->trans("AddPage"));
  3417. }
  3418. print '<!-- Edit or create page/container -->'."\n";
  3419. //print '<div class="fichecenter">';
  3420. $hiddenfromfetchingafterload = ' hideobject';
  3421. $hiddenmanuallyafterload = ' hideobject';
  3422. if (GETPOST('radiocreatefrom') == 'checkboxcreatefromfetching') {
  3423. $hiddenfromfetchingafterload = '';
  3424. }
  3425. if (GETPOST('radiocreatefrom') == 'checkboxcreatemanually') {
  3426. $hiddenmanuallyafterload = '';
  3427. }
  3428. if ($action == 'editmeta' || empty($conf->use_javascript_ajax)) { // No autohide/show in such case
  3429. $hiddenfromfetchingafterload = '';
  3430. $hiddenmanuallyafterload = '';
  3431. }
  3432. if ($action == 'createcontainer') {
  3433. print '<br>';
  3434. if (!empty($conf->use_javascript_ajax)) {
  3435. print '<input type="radio" name="radiocreatefrom" id="checkboxcreatemanually" value="checkboxcreatemanually"'.(GETPOST('radiocreatefrom') == 'checkboxcreatemanually' ? ' checked' : '').'> ';
  3436. }
  3437. print '<label for="checkboxcreatemanually"><span class="opacitymediumxx">'.$langs->trans("OrEnterPageInfoManually").'</span></label><br>';
  3438. print '<hr class="tablecheckboxcreatemanually'.$hiddenmanuallyafterload.'">';
  3439. }
  3440. print '<table class="border tableforfield nobackground centpercent tablecheckboxcreatemanually'.$hiddenmanuallyafterload.'">';
  3441. if ($action != 'createcontainer') {
  3442. print '<tr><td class="titlefield fieldrequired">';
  3443. print $langs->trans('IDOfPage').' - '.$langs->trans('InternalURLOfPage');
  3444. print '</td><td>';
  3445. print $pageid;
  3446. //print '</td></tr>';
  3447. //print '<tr><td class="titlefield fieldrequired">';
  3448. //print $langs->trans('InternalURLOfPage');
  3449. //print '</td><td>';
  3450. print ' &nbsp; - &nbsp; ';
  3451. print '/public/website/index.php?website='.urlencode($websitekey).'&pageid='.urlencode($pageid);
  3452. //if ($objectpage->grabbed_from) print ' - <span class="opacitymedium">'.$langs->trans('InitiallyGrabbedFrom').' '.$objectpage->grabbed_from.'</span>';
  3453. print '</td></tr>';
  3454. $type_container = $objectpage->type_container;
  3455. $pageurl = $objectpage->pageurl;
  3456. $pagealiasalt = $objectpage->aliasalt;
  3457. $pagetitle = $objectpage->title;
  3458. $pagedescription = $objectpage->description;
  3459. $pageimage = $objectpage->image;
  3460. $pagekeywords = $objectpage->keywords;
  3461. $pagelang = $objectpage->lang;
  3462. $pageallowedinframes = $objectpage->allowed_in_frames;
  3463. $pagehtmlheader = $objectpage->htmlheader;
  3464. $pagedatecreation = $objectpage->date_creation;
  3465. $pagedatemodification = $objectpage->date_modification;
  3466. $pageauthorid = $objectpage->fk_user_creat;
  3467. $pageusermodifid = $objectpage->fk_user_modif;
  3468. $pageauthoralias = $objectpage->author_alias;
  3469. $pagestatus = $objectpage->status;
  3470. } else { // $action = 'createcontainer'
  3471. $type_container = 'page';
  3472. $pageurl = '';
  3473. $pagealiasalt = '';
  3474. $pagetitle = '';
  3475. $pagedescription = '';
  3476. $pageimage = '';
  3477. $pagekeywords = '';
  3478. $pagelang = '';
  3479. $pageallowedinframes = 0;
  3480. $pagehtmlheader = '';
  3481. $pagedatecreation = dol_now();
  3482. $pagedatemodification = '';
  3483. $pageauthorid = $user->id;
  3484. $pageusermodifid = 0;
  3485. $pageauthoralias = '';
  3486. $pagestatus = 1;
  3487. }
  3488. if (GETPOST('WEBSITE_TITLE', 'alpha')) {
  3489. $pagetitle = str_replace(array('<', '>'), '', GETPOST('WEBSITE_TITLE', 'alphanohtml'));
  3490. }
  3491. if (GETPOST('WEBSITE_PAGENAME', 'alpha')) {
  3492. $pageurl = GETPOST('WEBSITE_PAGENAME', 'alpha');
  3493. }
  3494. if (GETPOST('WEBSITE_ALIASALT', 'alpha')) {
  3495. $pagealiasalt = str_replace(array('<', '>'), '', GETPOST('WEBSITE_ALIASALT', 'alphanohtml'));
  3496. }
  3497. if (GETPOST('WEBSITE_DESCRIPTION', 'alpha')) {
  3498. $pagedescription = str_replace(array('<', '>'), '', GETPOST('WEBSITE_DESCRIPTION', 'alphanohtml'));
  3499. }
  3500. if (GETPOST('WEBSITE_IMAGE', 'alpha')) {
  3501. $pageimage = GETPOST('WEBSITE_IMAGE', 'alpha');
  3502. }
  3503. if (GETPOST('WEBSITE_KEYWORDS', 'alpha')) {
  3504. $pagekeywords = str_replace(array('<', '>'), '', GETPOST('WEBSITE_KEYWORDS', 'alphanohtml'));
  3505. }
  3506. if (GETPOST('WEBSITE_LANG', 'aZ09')) {
  3507. $pagelang = GETPOST('WEBSITE_LANG', 'aZ09');
  3508. }
  3509. if (GETPOST('WEBSITE_ALLOWED_IN_FRAMES', 'aZ09')) {
  3510. $pageallowedinframes = GETPOST('WEBSITE_ALLOWED_IN_FRAMES', 'aZ09');
  3511. }
  3512. if (GETPOST('htmlheader', 'none')) {
  3513. $pagehtmlheader = GETPOST('htmlheader', 'none');
  3514. }
  3515. if ($action != 'createcontainer') {
  3516. if (empty($conf->use_javascript_ajax)) {
  3517. print '<!-- Status of web site page -->'."\n";
  3518. print '<tr><td class="fieldrequired">';
  3519. print $langs->trans('Status');
  3520. print '</td><td>';
  3521. print $form->selectyesno('status', $objectpage->status);
  3522. print '</td></tr>';
  3523. }
  3524. }
  3525. // Type of container
  3526. print '<tr><td class="titlefield fieldrequired">';
  3527. print $langs->trans('WEBSITE_TYPE_CONTAINER');
  3528. print '</td><td>';
  3529. print img_picto('', 'object_technic', 'class="paddingrightonly"').' ';
  3530. $formwebsite->selectTypeOfContainer('WEBSITE_TYPE_CONTAINER', (GETPOST('WEBSITE_TYPE_CONTAINER', 'alpha') ? GETPOST('WEBSITE_TYPE_CONTAINER', 'alpha') : $type_container), 0, '', 1);
  3531. print '</td></tr>';
  3532. // Example/templates of page
  3533. if ($action == 'createcontainer') {
  3534. print '<tr><td class="titlefield fieldrequired">';
  3535. print $langs->trans('WEBSITE_PAGE_EXAMPLE');
  3536. print '</td><td>';
  3537. print $formwebsite->selectSampleOfContainer('sample', (GETPOSTISSET('sample') ? GETPOST('sample', 'alpha') : 'empty'), 0, '', 1, 'minwidth300');
  3538. print '</td></tr>';
  3539. }
  3540. // Title
  3541. print '<tr><td class="fieldrequired">';
  3542. print $langs->trans('WEBSITE_TITLE');
  3543. print '</td><td>';
  3544. print '<input type="text" class="flat quatrevingtpercent" name="WEBSITE_TITLE" id="WEBSITE_TITLE" value="'.dol_escape_htmltag($pagetitle).'" autofocus>';
  3545. print '</td></tr>';
  3546. // Alias
  3547. print '<tr><td class="titlefieldcreate fieldrequired">';
  3548. print $langs->trans('WEBSITE_PAGENAME');
  3549. print '</td><td>';
  3550. print '<input type="text" class="flat minwidth300" name="WEBSITE_PAGENAME" id="WEBSITE_PAGENAME" value="'.dol_escape_htmltag($pageurl).'">';
  3551. print '</td></tr>';
  3552. print '<tr><td class="titlefieldcreate">';
  3553. $htmlhelp = $langs->trans("WEBSITE_ALIASALTDesc");
  3554. print $form->textwithpicto($langs->trans('WEBSITE_ALIASALT'), $htmlhelp, 1, 'help', '', 0, 2, 'aliastooltip');
  3555. print '</td><td>';
  3556. print '<input type="text" class="flat minwidth500" name="WEBSITE_ALIASALT" value="'.dol_escape_htmltag($pagealiasalt).'">';
  3557. print '</td></tr>';
  3558. print '<tr><td>';
  3559. print $langs->trans('WEBSITE_DESCRIPTION');
  3560. print '</td><td>';
  3561. print '<input type="text" class="flat quatrevingtpercent" name="WEBSITE_DESCRIPTION" value="'.dol_escape_htmltag($pagedescription).'">';
  3562. print '</td></tr>';
  3563. print '<tr><td>';
  3564. $htmlhelp = $langs->trans("WEBSITE_IMAGEDesc");
  3565. print $form->textwithpicto($langs->trans('WEBSITE_IMAGE'), $htmlhelp, 1, 'help', '', 0, 2, 'imagetooltip');
  3566. print '</td><td>';
  3567. print '<input type="text" class="flat quatrevingtpercent" name="WEBSITE_IMAGE" value="'.dol_escape_htmltag($pageimage).'">';
  3568. print '</td></tr>';
  3569. // Keywords
  3570. print '<tr><td>';
  3571. $htmlhelp = $langs->trans("WEBSITE_KEYWORDSDesc");
  3572. print $form->textwithpicto($langs->trans('WEBSITE_KEYWORDS'), $htmlhelp, 1, 'help', '', 0, 2, 'keywordtooltip');
  3573. print '</td><td>';
  3574. print '<input type="text" class="flat quatrevingtpercent" name="WEBSITE_KEYWORDS" value="'.dol_escape_htmltag($pagekeywords).'">';
  3575. print '</td></tr>';
  3576. print '<tr><td>';
  3577. print $langs->trans('Language');
  3578. print '</td><td>';
  3579. $onlykeys = array();
  3580. if ($object->lang) {
  3581. $onlykeys[$object->lang] = $object->lang;
  3582. } else {
  3583. $onlykeys[$langs->defaultlang] = $langs->defaultlang;
  3584. }
  3585. if ($object->otherlang) {
  3586. $tmparray = explode(',', $object->otherlang);
  3587. foreach ($tmparray as $key) {
  3588. $tmpkey = trim($key);
  3589. if (strlen($key) == 2) {
  3590. $tmpkey = strtolower($key);
  3591. }
  3592. $onlykeys[$tmpkey] = $tmpkey;
  3593. }
  3594. }
  3595. if (empty($object->lang) && empty($object->otherlang)) {
  3596. $onlykeys = null; // We keep full list of languages
  3597. }
  3598. print img_picto('', 'language', 'class="pictofixedwidth"').$formadmin->select_language($pagelang ? $pagelang : '', 'WEBSITE_LANG', 0, null, '1', 0, 0, 'minwidth200', 0, 0, 0, $onlykeys, 1);
  3599. $htmltext = $langs->trans("AvailableLanguagesAreDefinedIntoWebsiteProperties");
  3600. print $form->textwithpicto('', $htmltext);
  3601. print '</td></tr>';
  3602. // Translation of
  3603. $translationof = 0;
  3604. $translatedby = 0;
  3605. print '<!-- Translation of --><tr><td>';
  3606. print $langs->trans('TranslationLinks');
  3607. print '</td><td>';
  3608. if ($action != 'createcontainer') {
  3609. // Has translation pages
  3610. $sql = "SELECT rowid, lang from ".MAIN_DB_PREFIX."website_page where fk_page = ".((int) $objectpage->id);
  3611. $resql = $db->query($sql);
  3612. if ($resql) {
  3613. $num_rows = $db->num_rows($resql);
  3614. if ($num_rows > 0) {
  3615. print '<span class="opacitymedium">'.$langs->trans('ThisPageHasTranslationPages').':</span>';
  3616. $i = 0;
  3617. $tmppage = new WebsitePage($db);
  3618. $tmpstring = '';
  3619. while ($obj = $db->fetch_object($resql)) {
  3620. $result = $tmppage->fetch($obj->rowid);
  3621. if ($result > 0) {
  3622. if ($i > 0) {
  3623. $tmpstring .= '<br>';
  3624. }
  3625. $tmpstring .= $tmppage->getNomUrl(1).' ('.$tmppage->lang.')';
  3626. $translatedby++;
  3627. $i++;
  3628. }
  3629. }
  3630. if ($i > 1) {
  3631. print '<br>';
  3632. } else {
  3633. print ' ';
  3634. }
  3635. print $tmpstring;
  3636. }
  3637. } else {
  3638. dol_print_error($db);
  3639. }
  3640. }
  3641. if (empty($translatedby) && ($action == 'editmeta' || $action == 'createcontainer' || $objectpage->fk_page > 0)) {
  3642. $sourcepage = new WebsitePage($db);
  3643. $result = $sourcepage->fetch($objectpage->fk_page);
  3644. if ($result == 0) {
  3645. // not found, we can reset value to clean database
  3646. } elseif ($result > 0) {
  3647. $translationof = $objectpage->fk_page;
  3648. print '<span class="opacitymedium">'.$langs->trans('ThisPageIsTranslationOf').'</span> ';
  3649. print $formwebsite->selectContainer($website, 'pageidfortranslation', ($translationof ? $translationof : -1), 1, $action, 'minwidth300', array($objectpage->id));
  3650. if ($translationof > 0 && $sourcepage->lang) {
  3651. print $sourcepage->getNomUrl(2).' ('.$sourcepage->lang.')';
  3652. }
  3653. }
  3654. }
  3655. print '</td></tr>';
  3656. // Allowed in frames
  3657. print '<tr><td>';
  3658. print $langs->trans('AllowedInFrames');
  3659. //$htmlhelp = $langs->trans("AllowedInFramesDesc");
  3660. //print $form->textwithpicto($langs->trans('AllowedInFrames'), $htmlhelp, 1, 'help', '', 0, 2, 'allowedinframestooltip');
  3661. print '</td><td>';
  3662. print '<input type="checkbox" class="flat" name="WEBSITE_ALLOWED_IN_FRAMES" value="1"'.($pageallowedinframes ? 'checked="checked"' : '').'>';
  3663. print '</td></tr>';
  3664. // Categories
  3665. if (isModEnabled('categorie') && $user->hasRight('categorie', 'lire')) {
  3666. $langs->load('categories');
  3667. if (!GETPOSTISSET('categories')) {
  3668. $cate_arbo = $form->select_all_categories(Categorie::TYPE_WEBSITE_PAGE, '', null, null, null, 1);
  3669. $c = new Categorie($db);
  3670. $cats = $c->containing($objectpage->id, Categorie::TYPE_WEBSITE_PAGE);
  3671. $arrayselected = array();
  3672. if (is_array($cats)) {
  3673. foreach ($cats as $cat) {
  3674. $arrayselected[] = $cat->id;
  3675. }
  3676. }
  3677. $cate_arbo = $form->select_all_categories(Categorie::TYPE_WEBSITE_PAGE, '', 'parent', null, null, 1);
  3678. }
  3679. print '<tr><td class="toptd">'.$form->editfieldkey('Categories', 'categories', '', $objectpage, 0).'</td><td>';
  3680. print img_picto('', 'category', 'class="pictofixedwidth"');
  3681. print $form->multiselectarray('categories', $cate_arbo, (GETPOSTISSET('categories') ? GETPOST('categories', 'array') : $arrayselected), null, null, 'minwidth200 widthcentpercentminusxx');
  3682. print "</td></tr>";
  3683. }
  3684. if (!empty($conf->global->WEBSITE_PAGE_SHOW_INTERNAL_LINKS_TO_OBJECT)) { // TODO Replace this with link into element_element ?
  3685. print '<tr><td class="titlefieldcreate">';
  3686. print 'ObjectClass';
  3687. print '</td><td>';
  3688. print '<input type="text" class="flat minwidth300" name="WEBSITE_OBJECTCLASS" placeholder="ClassName::/path/class/ObjectClass.class.php" >';
  3689. print '</td></tr>';
  3690. print '<tr><td class="titlefieldcreate">';
  3691. print 'ObjectID';
  3692. print '</td><td>';
  3693. print '<input type="text" class="flat minwidth300" name="WEBSITE_OBJECTID" >';
  3694. print '</td></tr>';
  3695. }
  3696. $fuser = new User($db);
  3697. print '<tr><td>';
  3698. print $langs->trans('Author');
  3699. print '</td><td>';
  3700. if ($pageauthorid > 0) {
  3701. $fuser->fetch($pageauthorid);
  3702. print $fuser->getNomUrl(1);
  3703. } else {
  3704. print '<span class="opacitymedium">'.$langs->trans("Unknown").'</span>';
  3705. }
  3706. print '</td></tr>';
  3707. print '<tr><td>';
  3708. print $langs->trans('PublicAuthorAlias');
  3709. print '</td><td>';
  3710. print '<input type="text" class="flat minwidth300" name="WEBSITE_AUTHORALIAS" value="'.dol_escape_htmltag($pageauthoralias).'" placeholder="Anonymous">';
  3711. print '</td></tr>';
  3712. print '<tr><td>';
  3713. print $langs->trans('DateCreation');
  3714. print '</td><td>';
  3715. print $form->selectDate($pagedatecreation, 'datecreation', 1, 1, 0, '', 1, 1);
  3716. //print dol_print_date($pagedatecreation, 'dayhour');
  3717. print '</td></tr>';
  3718. if ($action != 'createcontainer') {
  3719. print '<tr><td>';
  3720. print $langs->trans('UserModif');
  3721. print '</td><td>';
  3722. if ($pageusermodifid > 0) {
  3723. $fuser->fetch($pageusermodifid);
  3724. print $fuser->getNomUrl(1);
  3725. }
  3726. print '</td></tr>';
  3727. print '<tr><td>';
  3728. print $langs->trans('DateModification');
  3729. print '</td><td>';
  3730. print dol_print_date($pagedatemodification, 'dayhour', 'tzuser');
  3731. print '</td></tr>';
  3732. }
  3733. print '<tr><td class="tdhtmlheader tdtop">';
  3734. $htmlhelp = $langs->trans("EditTheWebSiteForACommonHeader").'<br><br>';
  3735. $htmlhelp .= $langs->trans("Example").' :<br>';
  3736. $htmlhelp .= dol_htmlentitiesbr($htmlheadercontentdefault);
  3737. print $form->textwithpicto($langs->trans('HtmlHeaderPage'), $htmlhelp, 1, 'help', '', 0, 2, 'htmlheadertooltip');
  3738. print '</td><td>';
  3739. $poscursor = array('x'=>GETPOST('htmlheader_x'), 'y'=>GETPOST('htmlheader_y'));
  3740. $doleditor = new DolEditor('htmlheader', $pagehtmlheader, '', '120', 'ace', 'In', true, false, 'ace', ROWS_3, '100%', '', $poscursor);
  3741. print $doleditor->Create(1, '', true, 'HTML Header', 'html');
  3742. print '</td></tr>';
  3743. print '</table>';
  3744. if ($action == 'createcontainer') {
  3745. print '<div class="center tablecheckboxcreatemanually'.$hiddenmanuallyafterload.'">';
  3746. print '<input type="submit" class="button small" name="addcontainer" value="'.$langs->trans("Create").'">';
  3747. print '<input class="button button-cancel small" type="submit" name="preview" value="'.$langs->trans("Cancel").'">';
  3748. print '</div>';
  3749. print '<br>';
  3750. if (!empty($conf->use_javascript_ajax)) {
  3751. print '<input type="radio" name="radiocreatefrom" id="checkboxcreatefromfetching" value="checkboxcreatefromfetching"'.(GETPOST('radiocreatefrom') == 'checkboxcreatefromfetching' ? ' checked' : '').'> ';
  3752. }
  3753. print '<label for="checkboxcreatefromfetching"><span class="opacitymediumxx">'.$langs->trans("CreateByFetchingExternalPage").'</span></label><br>';
  3754. print '<hr class="tablecheckboxcreatefromfetching'.$hiddenfromfetchingafterload.'">';
  3755. print '<table class="tableforfield centpercent tablecheckboxcreatefromfetching'.$hiddenfromfetchingafterload.'">';
  3756. print '<tr><td class="titlefield">';
  3757. print $langs->trans("URL");
  3758. print '</td><td>';
  3759. print info_admin($langs->trans("OnlyEditionOfSourceForGrabbedContentFuture"), 0, 0, 'warning');
  3760. print '<input class="flat minwidth500" type="text" name="externalurl" value="'.dol_escape_htmltag(GETPOST('externalurl', 'alpha')).'" placeholder="https://externalsite/pagetofetch"> ';
  3761. print '<br><input class="flat paddingtop" type="checkbox" name="grabimages" value="1" checked="checked"> '.$langs->trans("GrabImagesInto");
  3762. print ' ';
  3763. print $langs->trans("ImagesShouldBeSavedInto").' ';
  3764. $arraygrabimagesinto = array('root'=>$langs->trans("WebsiteRootOfImages"), 'subpage'=>$langs->trans("SubdirOfPage"));
  3765. print $form->selectarray('grabimagesinto', $arraygrabimagesinto, GETPOSTISSET('grabimagesinto') ? GETPOST('grabimagesinto') : 'root', 0, 0, 0, '', 0, 0, 0, '', '', 1);
  3766. print '<br>';
  3767. print '<input class="button small" style="margin-top: 5px" type="submit" name="fetchexternalurl" value="'.dol_escape_htmltag($langs->trans("FetchAndCreate")).'">';
  3768. print '<input class="button button-cancel small" type="submit" name="preview" value="'.$langs->trans("Cancel").'">';
  3769. print '</td></tr>';
  3770. print '</table>';
  3771. }
  3772. if ($action == 'createcontainer') {
  3773. print '<script type="text/javascript">
  3774. jQuery(document).ready(function() {
  3775. var disableautofillofalias = 0;
  3776. var selectedm = \'\';
  3777. var selectedf = \'\';
  3778. jQuery("#WEBSITE_TITLE").keyup(function() {
  3779. if (disableautofillofalias == 0)
  3780. {
  3781. var valnospecial = jQuery("#WEBSITE_TITLE").val();
  3782. valnospecial = valnospecial.replace(/[éèê]/g, \'e\').replace(/[à]/g, \'a\').replace(/[ù]/g, \'u\').replace(/[î]/g, \'i\');
  3783. valnospecial = valnospecial.replace(/[ç]/g, \'c\').replace(/[ö]/g, \'o\');
  3784. valnospecial = valnospecial.replace(/[^\w]/gi, \'-\').toLowerCase();
  3785. valnospecial = valnospecial.replace(/\-+/g, \'-\').replace(/\-$/, \'\');
  3786. console.log("disableautofillofalias=0 so we replace WEBSITE_TITLE with "+valnospecial);
  3787. jQuery("#WEBSITE_PAGENAME").val(valnospecial);
  3788. }
  3789. });
  3790. jQuery("#WEBSITE_PAGENAME").keyup(function() {
  3791. disableautofillofalias = 1;
  3792. });
  3793. jQuery("#checkboxcreatefromfetching,#checkboxcreatemanually").click(function() {
  3794. console.log("we select a method to create a new container "+jQuery("#checkboxcreatefromfetching:checked").val())
  3795. jQuery(".tablecheckboxcreatefromfetching").hide();
  3796. jQuery(".tablecheckboxcreatemanually").hide();
  3797. if (typeof(jQuery("#checkboxcreatefromfetching:checked").val()) != \'undefined\') {
  3798. console.log("show a");
  3799. if (selectedf != \'createfromfetching\') {
  3800. jQuery(".tablecheckboxcreatefromfetching").show();
  3801. selectedf = \'createfromfetching\';
  3802. selectedm = \'\';
  3803. } else {
  3804. jQuery(".tablecheckboxcreatefromfetching").hide();
  3805. selectedf = \'\';
  3806. }
  3807. }
  3808. if (typeof(jQuery("#checkboxcreatemanually:checked").val()) != \'undefined\') {
  3809. console.log("show b");
  3810. if (selectedm != \'createmanually\') {
  3811. jQuery(".tablecheckboxcreatemanually").show();
  3812. selectedm = \'createmanually\';
  3813. selectedf = \'\';
  3814. } else {
  3815. jQuery(".tablecheckboxcreatemanually").hide();
  3816. selectedm = \'\';
  3817. }
  3818. }
  3819. });
  3820. });
  3821. </script>';
  3822. }
  3823. //print '</div>';
  3824. //print dol_get_fiche_end();
  3825. print '</div>';
  3826. print '<br>';
  3827. }
  3828. // Print formconfirm
  3829. if ($action == 'preview') {
  3830. print $formconfirm;
  3831. }
  3832. if ($action == 'editfile' || $action == 'file_manager' || $action == 'convertimgwebp' || $action == 'confirmconvertimgwebp') {
  3833. print '<!-- Edit Media -->'."\n";
  3834. print '<div class="fiche"><br>';
  3835. //print '<div class="center">'.$langs->trans("FeatureNotYetAvailable").'</center>';
  3836. $module = 'medias';
  3837. $formalreadyopen = 2; // So the form to submit a new file will not be opened another time inside the core/tpl/filemanager.tpl.php
  3838. if (empty($url)) {
  3839. $url = DOL_URL_ROOT.'/website/index.php'; // Must be an url without param
  3840. }
  3841. include DOL_DOCUMENT_ROOT.'/core/tpl/filemanager.tpl.php';
  3842. print '</div>';
  3843. }
  3844. if ($action == 'editmenu') {
  3845. print '<!-- Edit Menu -->'."\n";
  3846. print '<div class="center">'.$langs->trans("FeatureNotYetAvailable").'</center>';
  3847. }
  3848. if ($action == 'editsource') {
  3849. // Editing with source editor
  3850. $contentforedit = '';
  3851. //$contentforedit.='<style scoped>'."\n"; // "scoped" means "apply to parent element only". Not yet supported by browsers
  3852. //$contentforedit.=$csscontent;
  3853. //$contentforedit.='</style>'."\n";
  3854. $contentforedit .= $objectpage->content;
  3855. //var_dump($_SESSION["dol_screenheight"]);
  3856. $maxheightwin = 480;
  3857. if (isset($_SESSION["dol_screenheight"])) {
  3858. if ($_SESSION["dol_screenheight"] > 680) {
  3859. $maxheightwin = $_SESSION["dol_screenheight"] - 400;
  3860. }
  3861. if ($_SESSION["dol_screenheight"] > 800) {
  3862. $maxheightwin = $_SESSION["dol_screenheight"] - 490;
  3863. }
  3864. }
  3865. $poscursor = array('x'=>GETPOST('PAGE_CONTENT_x'), 'y'=>GETPOST('PAGE_CONTENT_y'));
  3866. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  3867. $doleditor = new DolEditor('PAGE_CONTENT', $contentforedit, '', $maxheightwin, 'Full', '', true, true, 'ace', ROWS_5, '40%', 0, $poscursor);
  3868. $doleditor->Create(0, '', false, 'HTML Source', 'php');
  3869. }
  3870. if ($action == 'editcontent') {
  3871. // Editing with default ckeditor
  3872. $contentforedit = '';
  3873. //$contentforedit.='<style scoped>'."\n"; // "scoped" means "apply to parent element only". Not yet supported by browsers
  3874. //$contentforedit.=$csscontent;
  3875. //$contentforedit.='</style>'."\n";
  3876. $contentforedit .= $objectpage->content;
  3877. $nbrep = array();
  3878. $contentforedit = preg_replace('/(<img.*src=")(?!http)/', '\1'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file=', $contentforedit, -1, $nbrep);
  3879. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  3880. $poscursor = array('x'=>GETPOST('PAGE_CONTENT_x'), 'y'=>GETPOST('PAGE_CONTENT_y'));
  3881. $doleditor=new DolEditor('PAGE_CONTENT', $contentforedit, '', 500, 'Full', '', true, true, true, ROWS_5, '90%', 0, $poscursor);
  3882. $doleditor->Create(0, '', false);
  3883. }
  3884. print "</div>\n";
  3885. print "</form>\n";
  3886. if ($mode == 'replacesite' || $massaction == 'replace') {
  3887. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  3888. print '<input type="hidden" name="token" value="'.newToken().'">';
  3889. print '<input type="hidden" name="action" value="replacesiteconfirm">';
  3890. print '<input type="hidden" name="mode" value="replacesite">';
  3891. print '<input type="hidden" name="website" value="'.$website->ref.'">';
  3892. print '<!-- Search page and replace string -->'."\n";
  3893. print '<div class="fiche"><br>';
  3894. print load_fiche_titre($langs->trans("ReplaceWebsiteContent"), '', 'search');
  3895. print '<div class="fichecenter"><div class="fichehalfleft">';
  3896. print '<div class="tagtable">';
  3897. print '<div class="tagtr">';
  3898. print '<div class="tagtd paddingrightonly opacitymedium">';
  3899. print $langs->trans("SearchReplaceInto");
  3900. print '</div>';
  3901. print '<div class="tagtd">';
  3902. print '<input type="checkbox" class="marginleftonly" id="checkboxoptioncontent" name="optioncontent" value="content"'.((!GETPOSTISSET('buttonreplacesitesearch') || GETPOST('optioncontent', 'aZ09')) ? ' checked' : '').'> <label for="checkboxoptioncontent" class="tdoverflowmax150onsmartphone inline-block valignmiddle">'.$langs->trans("Content").'</label><br>';
  3903. print '<input type="checkbox" class="marginleftonly" id="checkboxoptionmeta" name="optionmeta" value="meta"'.(GETPOST('optionmeta', 'aZ09') ? ' checked' : '').'> <label for="checkboxoptionmeta" class="tdoverflowmax150onsmartphone inline-block valignmiddle">'.$langs->trans("Title").' | '.$langs->trans("Description").' | '.$langs->trans("Keywords").'</label><br>';
  3904. print '<input type="checkbox" class="marginleftonly" id="checkboxoptionsitefiles" name="optionsitefiles" value="sitefiles"'.(GETPOST('optionsitefiles', 'aZ09') ? ' checked' : '').'> <label for="checkboxoptionsitefiles" class="tdoverflowmax150onsmartphone inline-block valignmiddle">'.$langs->trans("GlobalCSSorJS").'</label><br>';
  3905. print '</div>';
  3906. print '</div>';
  3907. print '<div class="tagtr">';
  3908. print '<div class="tagtd paddingrightonly opacitymedium" style="padding-right: 10px !important">';
  3909. print $langs->trans("SearchString");
  3910. print '</div>';
  3911. print '<div class="tagtd">';
  3912. print '<input type="text" name="searchstring" value="'.dol_escape_htmltag($searchkey, 0, 0, '', 1).'" autofocus>';
  3913. print '</div>';
  3914. print '</div>';
  3915. print '</div>';
  3916. print '</div><div class="fichehalfleft">';
  3917. print '<div class="tagtable">';
  3918. print '<div class="tagtr">';
  3919. print '<div class="tagtd paddingrightonly opacitymedium tdoverflowmax100onsmartphone" style="padding-right: 10px !important">';
  3920. print $langs->trans("WEBSITE_TYPE_CONTAINER");
  3921. print '</div>';
  3922. print '<div class="tagtd">';
  3923. print img_picto('', 'object_technic', 'class="paddingrightonly"').' ';
  3924. $formwebsite->selectTypeOfContainer('optioncontainertype', (GETPOST('optioncontainertype', 'alpha') ? GETPOST('optioncontainertype', 'alpha') : ''), 1, '', 1, 'minwidth125 maxwidth400 widthcentpercentminusx');
  3925. print '</div>';
  3926. print '</div>';
  3927. print '<div class="tagtr">';
  3928. print '<div class="tagtd paddingrightonly opacitymedium tdoverflowmax100onsmartphone" style="padding-right: 10px !important">';
  3929. print $langs->trans("Language");
  3930. print '</div>';
  3931. print '<div class="tagtd">';
  3932. print img_picto('', 'language', 'class="paddingrightonly"').' '.$formadmin->select_language(GETPOSTISSET('optionlanguage') ? GETPOST('optionlanguage') : '', 'optionlanguage', 0, null, '1', 0, 0, 'minwidth125 maxwidth400 widthcentpercentminusx', 2, 0, 0, null, 1);
  3933. print '</div>';
  3934. print '</div>';
  3935. // Categories
  3936. if (isModEnabled('categorie') && $user->hasRight('categorie', 'lire')) {
  3937. print '<div class="tagtr">';
  3938. print '<div class="tagtd paddingrightonly marginrightonly opacitymedium tdoverflowmax100onsmartphone" style="padding-right: 10px !important">';
  3939. print $langs->trans("Category");
  3940. print '</div>';
  3941. print '<div class="tagtd">';
  3942. print img_picto('', 'category', 'class="paddingrightonly"').' '.$form->select_all_categories(Categorie::TYPE_WEBSITE_PAGE, GETPOSTISSET('optioncategory') ? GETPOST('optioncategory') : '', 'optioncategory', 0, 0, 0, 0, 'minwidth125 maxwidth400 widthcentpercentminusx');
  3943. include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
  3944. print ajax_combobox('optioncategory');
  3945. print '</div>';
  3946. print '</div>';
  3947. }
  3948. print '</div>';
  3949. print '<input type="submit" class="button margintoponly" name="buttonreplacesitesearch" value="'.dol_escape_htmltag($langs->trans("Search")).'">';
  3950. print '</div></div>';
  3951. if ($mode == 'replacesite') {
  3952. print '<!-- List of search result -->'."\n";
  3953. print '<div class="rowsearchresult clearboth">';
  3954. print '<br>';
  3955. print '<br>';
  3956. if ($listofpages['code'] == 'OK') {
  3957. $arrayofselected = is_array($toselect) ? $toselect : array();
  3958. $param = '';
  3959. $nbtotalofrecords = count($listofpages['list']);
  3960. $num = $limit;
  3961. $permissiontodelete = $user->hasRight('website', 'delete');
  3962. // List of mass actions available
  3963. $arrayofmassactions = array();
  3964. if ($user->hasRight('website', 'writephp') && $searchkey) {
  3965. $arrayofmassactions['replace'] = img_picto('', 'replacement', 'class="pictofixedwidth"').$langs->trans("Replace");
  3966. }
  3967. if ($user->hasRight('website', 'write')) {
  3968. $arrayofmassactions['setcategory'] = img_picto('', 'category', 'class="pictofixedwidth"').$langs->trans("ClassifyInCategory");
  3969. }
  3970. if ($user->hasRight('website', 'write')) {
  3971. $arrayofmassactions['delcategory'] = img_picto('', 'category', 'class="pictofixedwidth"').$langs->trans("RemoveCategory");
  3972. }
  3973. if ($permissiontodelete) {
  3974. $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
  3975. }
  3976. if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) {
  3977. $arrayofmassactions = array();
  3978. }
  3979. $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
  3980. $massactionbutton .= '<div class="massactionother massactionreplace hidden">';
  3981. $massactionbutton .= $langs->trans("ReplaceString");
  3982. $massactionbutton .= ' <input type="text" name="replacestring" value="'.dol_escape_htmltag(GETPOST('replacestring', 'none')).'">';
  3983. $massactionbutton .= '</div>';
  3984. $massactionbutton .= '<div class="massactionother massactionsetcategory massactiondelcategory hidden">';
  3985. $massactionbutton .= img_picto('', 'category').' '.$langs->trans("Category");
  3986. $massactionbutton .= ' '.$form->select_all_categories(Categorie::TYPE_WEBSITE_PAGE, GETPOSTISSET('setcategory') ? GETPOST('setcategory') : '', 'setcategory', 64, 0, 0, 0, 'minwidth300 alignstart');
  3987. include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
  3988. $massactionbutton .= ajax_combobox('setcategory');
  3989. $massactionbutton .= '</div>';
  3990. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  3991. //$selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN', '')); // This also change content of $arrayfields
  3992. $selectedfields = '';
  3993. $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
  3994. print_barre_liste($langs->trans("Results"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'generic', 0, '', '', $limit, 1, 1, 1);
  3995. $topicmail = "WebsitePageRef";
  3996. $modelmail = "websitepage_send";
  3997. $objecttmp = new WebsitePage($db);
  3998. $trackid = 'wsp'.$object->id;
  3999. include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
  4000. $param = 'mode=replacesite&website='.urlencode($website->ref);
  4001. $param .= '&searchstring='.urlencode($searchkey);
  4002. if (GETPOST('optioncontent')) {
  4003. $param .= '&optioncontent=content';
  4004. }
  4005. if (GETPOST('optionmeta')) {
  4006. $param .= '&optionmeta=meta';
  4007. }
  4008. if (GETPOST('optionsitefiles')) {
  4009. $param .= '&optionsitefiles=optionsitefiles';
  4010. }
  4011. if (GETPOST('optioncontainertype')) {
  4012. $param .= '&optioncontainertype='.GETPOST('optioncontainertype', 'aZ09');
  4013. }
  4014. if (GETPOST('optionlanguage')) {
  4015. $param .= '&optionlanguage='.GETPOST('optionlanguage', 'aZ09');
  4016. }
  4017. if (GETPOST('optioncategory')) {
  4018. $param .= '&optioncategory='.GETPOST('optioncategory', 'aZ09');
  4019. }
  4020. print '<div class="div-table-responsive-no-min">';
  4021. print '<table class="noborder centpercent">';
  4022. print '<tr class="liste_titre">';
  4023. print getTitleFieldOfList("Type", 0, $_SERVER['PHP_SELF'], 'type_container', '', $param, '', $sortfield, $sortorder, '')."\n";
  4024. print getTitleFieldOfList("Page", 0, $_SERVER['PHP_SELF'], 'pageurl', '', $param, '', $sortfield, $sortorder, '')."\n";
  4025. print getTitleFieldOfList("Categories", 0, $_SERVER['PHP_SELF']);
  4026. print getTitleFieldOfList("Language", 0, $_SERVER['PHP_SELF'], 'lang', '', $param, '', $sortfield, $sortorder, 'center ')."\n";
  4027. print getTitleFieldOfList("", 0, $_SERVER['PHP_SELF']);
  4028. print getTitleFieldOfList("DateLastModification", 0, $_SERVER['PHP_SELF'], 'tms', '', $param, '', $sortfield, $sortorder, 'center ')."\n"; // Date last modif
  4029. print getTitleFieldOfList("", 0, $_SERVER['PHP_SELF']);
  4030. print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
  4031. print '</tr>';
  4032. require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  4033. $c = new Categorie($db);
  4034. $totalnbwords = 0;
  4035. foreach ($listofpages['list'] as $answerrecord) {
  4036. if (is_object($answerrecord) && get_class($answerrecord) == 'WebsitePage') {
  4037. print '<tr>';
  4038. // Type of container
  4039. print '<td class="nowraponall">'.$langs->trans("Container").' - ';
  4040. print $langs->trans($answerrecord->type_container); // TODO Use label of container
  4041. print '</td>';
  4042. // Container url and label
  4043. print '<td>';
  4044. print $answerrecord->getNomUrl(1);
  4045. print ' <span class="opacitymedium">('.($answerrecord->title ? $answerrecord->title : $langs->trans("NoTitle")).')</span>';
  4046. //print '</td>';
  4047. //print '<td class="tdoverflow100">';
  4048. print '<br>';
  4049. print '<span class="opacitymedium">'.$answerrecord->description.'</span>';
  4050. print '</td>';
  4051. // Categories - Tags
  4052. print '<td>';
  4053. if (isModEnabled('categorie') && $user->hasRight('categorie', 'lire')) {
  4054. // Get current categories
  4055. $existing = $c->containing($answerrecord->id, Categorie::TYPE_WEBSITE_PAGE, 'object');
  4056. if (is_array($existing)) {
  4057. foreach ($existing as $tmpcategory) {
  4058. //var_dump($tmpcategory);
  4059. print img_object($langs->trans("Category").' : '.$tmpcategory->label, 'category', 'style="padding-left: 2px; padding-right: 2px; color: #'.($tmpcategory->color != '' ? $tmpcategory->color : '888').'"');
  4060. }
  4061. }
  4062. }
  4063. //var_dump($existing);
  4064. print '</td>';
  4065. $param = '?mode=replacesite';
  4066. $param .= '&websiteid='.$website->id;
  4067. $param .= '&optioncontent='.GETPOST('optioncontent', 'aZ09');
  4068. $param .= '&optionmeta='.GETPOST('optionmeta', 'aZ09');
  4069. $param .= '&optionsitefiles='.GETPOST('optionsitefiles', 'aZ09');
  4070. $param .= '&optioncontainertype='.GETPOST('optioncontainertype', 'aZ09');
  4071. $param .= '&optionlanguage='.GETPOST('optionlanguage', 'aZ09');
  4072. $param .= '&optioncategory='.GETPOST('optioncategory', 'aZ09');
  4073. $param .= '&searchstring='.urlencode($searchkey);
  4074. // Language
  4075. print '<td class="center">';
  4076. print picto_from_langcode($answerrecord->lang, $answerrecord->lang);
  4077. print '</td>';
  4078. // Number of words
  4079. print '<td class="center nowraponall">';
  4080. $textwithouthtml = dol_string_nohtmltag(dolStripPhpCode($answerrecord->content));
  4081. $characterMap = 'áàéèëíóúüñùç0123456789';
  4082. $nbofwords = str_word_count($textwithouthtml, 0, $characterMap);
  4083. if ($nbofwords) {
  4084. print $nbofwords.' '.$langs->trans("words");
  4085. $totalnbwords += $nbofwords;
  4086. }
  4087. print '</td>';
  4088. // Date last modification
  4089. print '<td class="center nowraponall">';
  4090. print dol_print_date($answerrecord->date_modification, 'dayhour');
  4091. print '</td>';
  4092. // Edit properties, HTML sources, status
  4093. print '<td class="tdwebsitesearchresult right nowraponall">';
  4094. $disabled = '';
  4095. $urltoedithtmlsource = $_SERVER["PHP_SELF"].'?action=editmeta&token='.newToken().'&websiteid='.$website->id.'&pageid='.$answerrecord->id.'&backtopage='.urlencode($_SERVER["PHP_SELF"].$param);
  4096. if (!$user->hasRight('website', 'write')) {
  4097. $disabled = ' disabled';
  4098. $urltoedithtmlsource = '';
  4099. }
  4100. print '<a class="editfielda marginleftonly marginrightonly '.$disabled.'" href="'.$urltoedithtmlsource.'" title="'.$langs->trans("EditPageMeta").'">'.img_picto($langs->trans("EditPageMeta"), 'pencil-ruler').'</a>';
  4101. $disabled = '';
  4102. $urltoedithtmlsource = $_SERVER["PHP_SELF"].'?action=editsource&token='.newToken().'&websiteid='.$website->id.'&pageid='.$answerrecord->id.'&backtopage='.urlencode($_SERVER["PHP_SELF"].$param);
  4103. if (!$user->hasRight('website', 'write')) {
  4104. $disabled = ' disabled';
  4105. $urltoedithtmlsource = '';
  4106. }
  4107. print '<a class="editfielda marginleftonly marginrightonly '.$disabled.'" href="'.$urltoedithtmlsource.'" title="'.$langs->trans("EditHTMLSource").'">'.img_picto($langs->trans("EditHTMLSource"), 'edit').'</a>';
  4108. print '<span class="marginleftonly marginrightonly"></span>';
  4109. print ajax_object_onoff($answerrecord, 'status', 'status', 'Enabled', 'Disabled', array(), 'valignmiddle inline-block');
  4110. print '</td>';
  4111. // Action column
  4112. print '<td class="nowrap center">';
  4113. print '<!-- Status of page -->'."\n";
  4114. if ($massactionbutton || $massaction) {
  4115. $selected = 0;
  4116. if (in_array($answerrecord->id, $arrayofselected)) {
  4117. $selected = 1;
  4118. }
  4119. print '<input id="'.$answerrecord->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$answerrecord->id.'"'.($selected ? ' checked="checked"' : '').'>';
  4120. }
  4121. print '</td>';
  4122. print '</tr>';
  4123. } else {
  4124. print '<tr>';
  4125. // Type of container
  4126. print '<td>';
  4127. $translateofrecordtype = array(
  4128. 'website_csscontent'=>'WEBSITE_CSS_INLINE',
  4129. 'website_jscontent'=>'WEBSITE_JS_INLINE',
  4130. 'website_robotcontent'=>'WEBSITE_ROBOT',
  4131. 'website_htmlheadercontent'=>'WEBSITE_HTML_HEADER',
  4132. 'website_htaccess'=>'WEBSITE_HTACCESS',
  4133. 'website_readme'=>'WEBSITE_README',
  4134. 'website_manifestjson'=>'WEBSITE_MANIFEST_JSON'
  4135. );
  4136. if (!empty($translateofrecordtype[$answerrecord['type']])) {
  4137. print $langs->trans($translateofrecordtype[$answerrecord['type']]);
  4138. } else {
  4139. print $answerrecord['type'];
  4140. }
  4141. print '</td>';
  4142. $param = '?mode=replacesite';
  4143. $param .= '&websiteid='.$website->id;
  4144. $param .= '&optioncontent='.GETPOST('optioncontent', 'aZ09');
  4145. $param .= '&optionmeta='.GETPOST('optionmeta', 'aZ09');
  4146. $param .= '&optionsitefiles='.GETPOST('optionsitefiles', 'aZ09');
  4147. $param .= '&optioncontainertype='.GETPOST('optioncontainertype', 'aZ09');
  4148. $param .= '&optionlanguage='.GETPOST('optionlanguage', 'aZ09');
  4149. $param .= '&optioncategory='.GETPOST('optioncategory', 'aZ09');
  4150. $param .= '&searchstring='.urlencode($searchkey);
  4151. // Container url and label
  4152. print '<td>';
  4153. $backtopageurl = $_SERVER["PHP_SELF"].$param;
  4154. print '<a href="'.$_SERVER["PHP_SELF"].'?action=editcss&token='.newToken().'&website='.urlencode($website->ref).'&backtopage='.urlencode($backtopageurl).'">'.$langs->trans("EditCss").'</a>';
  4155. print '</td>';
  4156. // Language
  4157. print '<td>';
  4158. print '</td>';
  4159. // Categories - Tags
  4160. print '<td>';
  4161. print '</td>';
  4162. // Nb of words
  4163. print '<td>';
  4164. print '</td>';
  4165. // Date last modification
  4166. print '<td class="center nowraponall">';
  4167. //print dol_print_date(filemtime());
  4168. print '</td>';
  4169. // Edit properties, HTML sources, status
  4170. print '<td>';
  4171. print '</td>';
  4172. // Action column
  4173. print '<td class="nowrap center">';
  4174. print '</td>';
  4175. print '</tr>';
  4176. }
  4177. }
  4178. if (count($listofpages['list']) >= 2) {
  4179. // Total
  4180. print '<tr class="lite_titre">';
  4181. // Type of container
  4182. print '<td>';
  4183. print $langs->trans("Total");
  4184. print '</td>';
  4185. // Container url and label
  4186. print '<td>';
  4187. print '</td>';
  4188. // Language
  4189. print '<td>';
  4190. print '</td>';
  4191. // Categories - Tags
  4192. print '<td>';
  4193. print '</td>';
  4194. // Nb of words
  4195. print '<td class="center nowraponall">';
  4196. print $totalnbwords.' '.$langs->trans("words");
  4197. print '</td>';
  4198. // Date last modification
  4199. print '<td>';
  4200. print '</td>';
  4201. // Edit properties, HTML sources, status
  4202. print '<td>';
  4203. print '</td>';
  4204. // Action column
  4205. print '<td class="nowrap center">';
  4206. print '</td>';
  4207. print '</tr>';
  4208. }
  4209. print '</table>';
  4210. print '</div>';
  4211. print '<br>';
  4212. } else {
  4213. print '<div class="warning">'.$listofpages['message'].'</div>';
  4214. }
  4215. print '</div>';
  4216. }
  4217. print '</form>';
  4218. }
  4219. if ((empty($action) || $action == 'preview' || $action == 'createfromclone' || $action == 'createpagefromclone') && !in_array($mode, array('replacesite'))) {
  4220. if ($pageid > 0 && $atleastonepage) {
  4221. // $filejs
  4222. // $filecss
  4223. // $filephp
  4224. // Ouput page under the Dolibarr top menu
  4225. $objectpage->fetch($pageid);
  4226. $jscontent = @file_get_contents($filejs);
  4227. $out = '<!-- Page content '.$filetpl.' : Div with (Htmlheader/Style of page from database + CSS Of website from file + Page content from database or by include if WEBSITE_SUBCONTAINERSINLINE is on) -->'."\n";
  4228. // Include a html so we can benefit of the header of page.
  4229. // Note: We can't use iframe as it can be used to include another external html file
  4230. // Note: We can't use frame as it is deprecated.
  4231. /*if ($includepageintoaframeoradiv == 'iframe')
  4232. {
  4233. $out .= "<iframe><body></html>";
  4234. }*/
  4235. $out .= "\n<html><head>\n";
  4236. $out .= "<!-- htmlheader/style of page from database -->\n";
  4237. $out .= dolWebsiteReplacementOfLinks($object, $objectpage->htmlheader, 1, 'htmlheader');
  4238. $out .= "<!-- htmlheader/style of website from files -->\n";
  4239. // TODO Keep only the <link> or the <script> tags
  4240. /*
  4241. $htmlheadercontent = @file_get_contents($filehtmlheader);
  4242. $dom = new DOMDocument;
  4243. @$dom->loadHTML($htmlheadercontent);
  4244. $styles = $dom->getElementsByTagName('link');
  4245. $scripts = $dom->getElementsByTagName('script');
  4246. foreach($styles as $stylescursor)
  4247. {
  4248. $out.=$stylescursor;
  4249. }
  4250. foreach($scripts as $scriptscursor)
  4251. {
  4252. $out.=$scriptscursor;
  4253. }
  4254. */
  4255. $out .= "</head>\n";
  4256. $out .= "\n<body>";
  4257. $out .= '<div id="websitecontentundertopmenu" class="websitecontentundertopmenu boostrap-iso">'."\n";
  4258. // REPLACEMENT OF LINKS When page called by website editor
  4259. $out .= '<!-- style of website from file -->'."\n";
  4260. $out .= '<style scoped>'."\n"; // "scoped" means "apply to parent element only and not grand parent". No more supported by browsers, snif !
  4261. $tmpout = '';
  4262. $tmpout .= '/* Include website CSS file */'."\n";
  4263. //$csscontent = @file_get_contents($filecss);
  4264. ob_start();
  4265. include $filecss;
  4266. $csscontent = ob_get_contents();
  4267. ob_end_clean();
  4268. $tmpout .= dolWebsiteReplacementOfLinks($object, $csscontent, 1, 'css');
  4269. $tmpout .= '/* Include style from the HTML header of page */'."\n";
  4270. // Clean the html header of page to get only <style> content
  4271. $tmp = preg_split('(<style[^>]*>|</style>)', $objectpage->htmlheader);
  4272. $tmpstyleinheader = '';
  4273. $i = 0;
  4274. foreach ($tmp as $valtmp) {
  4275. $i++;
  4276. if ($i % 2 == 0) {
  4277. $tmpstyleinheader .= $valtmp."\n";
  4278. }
  4279. }
  4280. $tmpout .= $tmpstyleinheader."\n";
  4281. // Clean style that may affect global style of Dolibarr
  4282. $tmpout = preg_replace('/}[\s\n]*body\s*{[^}]+}/ims', '}', $tmpout);
  4283. $out .= $tmpout;
  4284. $out .= '</style>'."\n";
  4285. // Note: <div> or <section> with contenteditable="true" inside this can be edited with inline ckeditor
  4286. // Do not enable the contenteditable when page was grabbed, ckeditor is removing span and adding borders,
  4287. // so editable will be available only from container created from scratch
  4288. //$out.='<div id="bodywebsite" class="bodywebsite"'.($objectpage->grabbed_from ? ' contenteditable="true"' : '').'>'."\n";
  4289. $out .= '<div id="divbodywebsite" class="bodywebsite bodywebpage-'.$objectpage->ref.'">'."\n";
  4290. $newcontent = $objectpage->content;
  4291. // If mode WEBSITE_SUBCONTAINERSINLINE is on
  4292. if (!empty($conf->global->WEBSITE_SUBCONTAINERSINLINE)) {
  4293. // TODO Check file $filephp exists, if not create it.
  4294. //var_dump($filetpl);
  4295. $filephp = $filetpl;
  4296. ob_start();
  4297. try {
  4298. $res = include $filephp;
  4299. if (empty($res)) {
  4300. print "ERROR: Failed to include file '".$filephp."'. Try to edit and re-save page ith this ID.";
  4301. }
  4302. } catch (Exception $e) {
  4303. print $e->getMessage();
  4304. }
  4305. $newcontent = ob_get_contents();
  4306. ob_end_clean();
  4307. }
  4308. // Change the contenteditable to "true" or "false" when mode Edit Inline is on or off
  4309. if (empty($conf->global->WEBSITE_EDITINLINE)) {
  4310. // Remove the contenteditable="true"
  4311. $newcontent = preg_replace('/(div|section)(\s[^\>]*)contenteditable="true"/', '\1\2', $newcontent);
  4312. } else {
  4313. // Keep the contenteditable="true" when mode Edit Inline is on
  4314. }
  4315. $out .= dolWebsiteReplacementOfLinks($object, $newcontent, 0, 'html', $objectpage->id)."\n";
  4316. //$out.=$newcontent;
  4317. $out .= '</div>';
  4318. $out .= '</div> <!-- End div id=websitecontentundertopmenu -->';
  4319. /*if ($includepageintoaframeoradiv == 'iframe')
  4320. {
  4321. $out .= "</body></html></iframe>";
  4322. }*/
  4323. $out .= "\n</body></html>\n";
  4324. $out .= "\n".'<!-- End page content '.$filetpl.' -->'."\n\n";
  4325. print $out;
  4326. /*file_put_contents($filetpl, $out);
  4327. dolChmod($filetpl);
  4328. // Output file on browser
  4329. dol_syslog("index.php include $filetpl $filename content-type=$type");
  4330. $original_file_osencoded=dol_osencode($filetpl); // New file name encoded in OS encoding charset
  4331. // This test if file exists should be useless. We keep it to find bug more easily
  4332. if (! file_exists($original_file_osencoded))
  4333. {
  4334. dol_print_error(0,$langs->trans("ErrorFileDoesNotExists",$original_file));
  4335. exit;
  4336. }
  4337. //include_once $original_file_osencoded;
  4338. */
  4339. /*print '<iframe class="websiteiframenoborder centpercent" src="'.DOL_URL_ROOT.'/public/website/index.php?website='.$websitekey.'&pageid='.$pageid.'"/>';
  4340. print '</iframe>';*/
  4341. } else {
  4342. if (empty($websitekey) || $websitekey == '-1') {
  4343. print '<br><br><div class="center previewnotyetavailable"><span class="">'.$langs->trans("NoWebSiteCreateOneFirst").'</span></div><br><br><br>';
  4344. print '<div class="center"><div class="logo_setup"></div></div>';
  4345. } else {
  4346. print '<br><br><div class="center previewnotyetavailable"><span class="">'.$langs->trans("PreviewOfSiteNotYetAvailable", $object->ref).'</span></div><br><br><br>';
  4347. print '<div class="center"><div class="logo_setup"></div></div>';
  4348. }
  4349. }
  4350. }
  4351. // End of page
  4352. llxFooter();
  4353. $db->close();