index.php 104 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973
  1. <?php
  2. /* Copyright (C) 2016-2018 Laurent Destailleur <eldy@users.sourceforge.net>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. /**
  18. * \file htdocs/website/index.php
  19. * \ingroup website
  20. * \brief Page to website view/edit
  21. */
  22. define('NOSCANPOSTFORINJECTION',1);
  23. define('NOSTYLECHECK',1);
  24. header('X-XSS-Protection:0');
  25. require '../main.inc.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/lib/website.lib.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formwebsite.class.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  33. require_once DOL_DOCUMENT_ROOT.'/website/class/website.class.php';
  34. require_once DOL_DOCUMENT_ROOT.'/website/class/websitepage.class.php';
  35. $langs->loadLangs(array("admin","other","website","errors"));
  36. if (! $user->rights->website->read) accessforbidden();
  37. if (! ((GETPOST('testmenuhider','int') || ! empty($conf->global->MAIN_TESTMENUHIDER)) && empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)))
  38. {
  39. $conf->dol_hide_leftmenu = 1; // Force hide of left menu.
  40. }
  41. $error=0;
  42. $websitekey=GETPOST('website', 'alpha');
  43. $page=GETPOST('page', 'alpha');
  44. $pageid=GETPOST('pageid', 'int');
  45. $pageref=GETPOST('pageref', 'aZ09');
  46. $action=GETPOST('action','aZ09');
  47. $confirm=GETPOST('confirm','alpha');
  48. $cancel=GETPOST('cancel','alpha');
  49. $type_container=GETPOST('WEBSITE_TYPE_CONTAINER', 'alpha');
  50. $section_dir = GETPOST('section_dir', 'alpha');
  51. $file_manager = GETPOST('file_manager', 'alpha');
  52. if (GETPOST('deletesite','alpha')) { $action='deletesite'; }
  53. if (GETPOST('delete','alpha')) { $action='delete'; }
  54. if (GETPOST('preview','alpha')) $action='preview';
  55. if (GETPOST('createsite','alpha')) { $action='createsite'; }
  56. if (GETPOST('createcontainer','alpha')) { $action='createcontainer'; }
  57. if (GETPOST('editcss','alpha')) { $action='editcss'; }
  58. if (GETPOST('editmenu','alpha')) { $action='editmenu'; }
  59. if (GETPOST('setashome','alpha')) { $action='setashome'; }
  60. if (GETPOST('editmeta','alpha')) { $action='editmeta'; }
  61. if (GETPOST('editsource','alpha')) { $action='editsource'; }
  62. if (GETPOST('editcontent','alpha')) { $action='editcontent'; }
  63. if (GETPOST('exportsite','alpha')) { $action='exportsite'; }
  64. if (GETPOST('importsite','alpha')) { $action='importsite'; }
  65. if (GETPOST('createfromclone','alpha')) { $action='createfromclone'; }
  66. if (GETPOST('createpagefromclone','alpha')) { $action='createpagefromclone'; }
  67. if (empty($action) && $file_manager) $action='file_manager';
  68. // Load variable for pagination
  69. $limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit;
  70. $sortfield = GETPOST("sortfield",'alpha');
  71. $sortorder = GETPOST("sortorder",'alpha');
  72. $page = GETPOST("page",'int');
  73. if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
  74. $offset = $limit * $page;
  75. $pageprev = $page - 1;
  76. $pagenext = $page + 1;
  77. //if (! $sortfield) $sortfield='name';
  78. //if (! $sortorder) $sortorder='ASC';
  79. if (empty($action)) $action='preview';
  80. $object=new Website($db);
  81. $objectpage=new WebsitePage($db);
  82. $object->fetchAll(); // Init $object->records with list of websites
  83. // If website not defined, we take first found
  84. if (empty($websitekey))
  85. {
  86. foreach($object->records as $key => $valwebsite)
  87. {
  88. $websitekey=$valwebsite->ref;
  89. break;
  90. }
  91. }
  92. if ($websitekey)
  93. {
  94. $res = $object->fetch(0, $websitekey);
  95. }
  96. $website = $object;
  97. // Check pageid received as aprameter
  98. if ($pageid < 0) $pageid = 0;
  99. if (($pageid > 0 || $pageref) && $action != 'addcontainer')
  100. {
  101. $res = $objectpage->fetch($pageid, ($object->id > 0 ? $object->id : null), $pageref);
  102. // Check if pageid is inside the new website, if not we reset param pageid
  103. if ($res >= 0 && $object->id > 0)
  104. {
  105. if ($objectpage->fk_website != $object->id) // We have a bad page that does not belong to web site
  106. {
  107. if ($object->fk_default_home > 0)
  108. {
  109. $res = $objectpage->fetch($object->fk_default_home, $object->id, ''); // We search first page of web site
  110. if ($res > 0) $pageid = $object->fk_default_home;
  111. }
  112. else
  113. {
  114. $res = $objectpage->fetch(0, $object->id, ''); // We search first page of web site
  115. if ($res == 0) // Page was not found, we reset it
  116. {
  117. $objectpage=new WebsitePage($db);
  118. }
  119. else // We found a page, we set pageid to it.
  120. {
  121. $pageid = $objectpage->id;
  122. }
  123. }
  124. }
  125. else // We have a valid page. We force pageid for the case we got the page with a fetch on ref.
  126. {
  127. $pageid = $objectpage->id;
  128. }
  129. }
  130. }
  131. // Define pageid if pageid and pageref not received as parameter or was wrong
  132. if (empty($pageid) && empty($pageref) && $object->id > 0 && $action != 'createcontainer')
  133. {
  134. $pageid = $object->fk_default_home;
  135. if (empty($pageid))
  136. {
  137. $array=$objectpage->fetchAll($object->id, 'ASC,ASC', 'type_container,pageurl');
  138. if (! is_array($array) && $array < 0) dol_print_error('', $objectpage->error, $objectpage->errors);
  139. $atleastonepage=(is_array($array) && count($array) > 0);
  140. $firstpageid=0;$homepageid=0;
  141. foreach($array as $key => $valpage)
  142. {
  143. if (empty($firstpageid)) $firstpageid=$valpage->id;
  144. if ($object->fk_default_home && $key == $object->fk_default_home) $homepageid=$valpage->id;
  145. }
  146. $pageid=($homepageid?$homepageid:$firstpageid); // We choose home page and if not defined yet, we take first page
  147. }
  148. }
  149. global $dolibarr_main_data_root;
  150. $pathofwebsite=$dolibarr_main_data_root.'/website/'.$websitekey;
  151. $filehtmlheader=$pathofwebsite.'/htmlheader.html';
  152. $filecss=$pathofwebsite.'/styles.css.php';
  153. $filejs=$pathofwebsite.'/javascript.js.php';
  154. $filerobot=$pathofwebsite.'/robots.txt';
  155. $filehtaccess=$pathofwebsite.'/.htaccess';
  156. $filetpl=$pathofwebsite.'/page'.$pageid.'.tpl.php';
  157. $fileindex=$pathofwebsite.'/index.php';
  158. $filewrapper=$pathofwebsite.'/wrapper.php';
  159. // Define $urlwithroot
  160. $urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root));
  161. $urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
  162. //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
  163. $permtouploadfile = $user->rights->website->write;
  164. $diroutput = $conf->medias->multidir_output[$conf->entity];
  165. $relativepath=$section_dir;
  166. $upload_dir = $diroutput.'/'.$relativepath;
  167. $htmlheadercontentdefault = '';
  168. $htmlheadercontentdefault.='<link rel="stylesheet" id="google-fonts-css" href="//fonts.googleapis.com/css?family=Open+Sans:300,400,700" />'."\n";
  169. $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";
  170. $htmlheadercontentdefault.='<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>'."\n";
  171. $htmlheadercontentdefault.='<script src="//cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>'."\n";
  172. $htmlheadercontentdefault.='<script src="//cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js"></script>'."\n";
  173. $htmlheadercontentdefault.='<script src="//cdnjs.cloudflare.com/ajax/libs/popper.js/1.13.0/umd/popper.min.js"></script>'."\n";
  174. $htmlheadercontentdefault.='<script src="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-beta.2/js/bootstrap.min.js"></script>'."\n";
  175. $htmlheadercontentdefault.='<!--'."\n";
  176. $htmlheadercontentdefault.='<script src="/document.php?modulepart=medias&file=css/myfile.css"></script>'."\n";
  177. $htmlheadercontentdefault.='<script src="/document.php?modulepart=medias&file=js/myfile.js"></script>'."\n";
  178. $htmlheadercontentdefault.='-->'."\n";
  179. /*
  180. * Actions
  181. */
  182. $backtopage=$_SERVER["PHP_SELF"].'?file_manager=1&website='.$websitekey.'&pageid='.$pageid.(GETPOST('section_dir','alpha')?'&section_dir='.urlencode(GETPOST('section_dir','alpha')):''); // used after a confirm_deletefile into actions_linkedfiles.inc.php
  183. include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php';
  184. if ($action == 'renamefile') $action='file_manager'; // After actions_linkedfiles, if action were renamefile, we set it to 'file_manager'
  185. if ($action == 'seteditinline')
  186. {
  187. dolibarr_set_const($db, 'WEBSITE_EDITINLINE', 1);
  188. setEventMessages($langs->trans("FeatureNotYetAvailable"), null, 'warnings');
  189. dolibarr_set_const($db, 'WEBSITE_SUBCONTAINERSINLINE', 0); // Force disable of 'Include dynamic content'
  190. header("Location: ".$_SERVER["PHP_SELF"].'?website='.GETPOST('website','alphanohtml').'&pageid='.GETPOST('pageid','int'));
  191. exit;
  192. }
  193. if ($action == 'unseteditinline')
  194. {
  195. dolibarr_del_const($db, 'WEBSITE_EDITINLINE');
  196. header("Location: ".$_SERVER["PHP_SELF"].'?website='.GETPOST('website','alphanohtml').'&pageid='.GETPOST('pageid','int'));
  197. exit;
  198. }
  199. if ($action == 'setshowsubcontainers')
  200. {
  201. dolibarr_set_const($db, 'WEBSITE_SUBCONTAINERSINLINE', 1);
  202. dolibarr_set_const($db, 'WEBSITE_EDITINLINE', 0); // Force disable of edit inline
  203. header("Location: ".$_SERVER["PHP_SELF"].'?website='.GETPOST('website','alphanohtml').'&pageid='.GETPOST('pageid','int'));
  204. exit;
  205. }
  206. if ($action == 'unsetshowsubcontainers')
  207. {
  208. dolibarr_del_const($db, 'WEBSITE_SUBCONTAINERSINLINE');
  209. header("Location: ".$_SERVER["PHP_SELF"].'?website='.GETPOST('website','alphanohtml').'&pageid='.GETPOST('pageid','int'));
  210. exit;
  211. }
  212. // Add directory
  213. /*
  214. if ($action == 'adddir' && $permtouploadfile)
  215. {
  216. $ecmdir->ref = 'NOTUSEDYET';
  217. $ecmdir->label = GETPOST("label");
  218. $ecmdir->description = GETPOST("desc");
  219. //$id = $ecmdir->create($user);
  220. if ($id > 0)
  221. {
  222. header("Location: ".$_SERVER["PHP_SELF"]);
  223. exit;
  224. }
  225. else
  226. {
  227. setEventMessages('Error '.$langs->trans($ecmdir->error), null, 'errors');
  228. $action = "createcontainer";
  229. }
  230. clearstatcache();
  231. }
  232. */
  233. if (GETPOST('refreshsite','alpha')) // If we change the site, we reset the pageid and cancel addsite action.
  234. {
  235. $pageid=0;
  236. if ($action == 'addsite') $action = 'preview';
  237. }
  238. if (GETPOST('refreshpage','alpha') && ! in_array($action, array('updatecss'))) $action='preview';
  239. // Add site
  240. if ($action == 'addsite')
  241. {
  242. $db->begin();
  243. if (GETPOST('virtualhost','alpha') && ! preg_match('/^http/',GETPOST('virtualhost','alpha')))
  244. {
  245. $error++;
  246. setEventMessages($langs->trans('ErrorURLMustStartWithHttp', $langs->transnoentitiesnoconv("VirtualHost")), null, 'errors');
  247. }
  248. if (! $error && ! GETPOST('WEBSITE_REF','alpha'))
  249. {
  250. $error++;
  251. $langs->load("errors");
  252. setEventMessages($langs->transnoentities("ErrorFieldRequired", $langs->transnoentities("Ref")), null, 'errors');
  253. }
  254. if (! $error && ! preg_match('/^[a-z0-9_\-\.]+$/i', GETPOST('WEBSITE_REF','alpha')))
  255. {
  256. $error++;
  257. $langs->load("errors");
  258. setEventMessages($langs->transnoentities("ErrorFieldCanNotContainSpecialCharacters", $langs->transnoentities("Ref")), null, 'errors');
  259. }
  260. if (! $error)
  261. {
  262. $tmpobject=new Website($db);
  263. $tmpobject->ref = GETPOST('WEBSITE_REF','alpha');
  264. $tmpobject->description = GETPOST('WEBSITE_DESCRIPTION','alpha');
  265. $tmpobject->virtualhost = GETPOST('virtualhost','alpha');
  266. $result = $tmpobject->create($user);
  267. if ($result <= 0)
  268. {
  269. $error++;
  270. setEventMessages($tmpobject->error, $tmpobject->errors, 'errors');
  271. }
  272. }
  273. if (! $error)
  274. {
  275. $db->commit();
  276. setEventMessages($langs->trans("SiteAdded", $object->ref), null, 'mesgs');
  277. $action='';
  278. header("Location: ".$_SERVER["PHP_SELF"].'?website='.$tmpobject->ref);
  279. exit;
  280. }
  281. else
  282. {
  283. $db->rollback();
  284. $action='createsite';
  285. }
  286. if (! $error)
  287. {
  288. $action = 'preview';
  289. $id = $object->id;
  290. }
  291. }
  292. // Add page/container
  293. if ($action == 'addcontainer')
  294. {
  295. dol_mkdir($pathofwebsite);
  296. $db->begin();
  297. $objectpage->fk_website = $object->id;
  298. if (GETPOST('fetchexternalurl','alpha'))
  299. {
  300. $urltograb=GETPOST('externalurl','alpha');
  301. $grabimages=GETPOST('grabimages','alpha');
  302. $grabimagesinto=GETPOST('grabimagesinto','alpha');
  303. //var_dump($grabimages);exit;
  304. }
  305. if ($urltograb)
  306. {
  307. include_once DOL_DOCUMENT_ROOT.'/core/lib/geturl.lib.php';
  308. if (! preg_match('/^http/', $urltograb))
  309. {
  310. $error++;
  311. $langs->load("errors");
  312. setEventMessages('Error URL must start with http:// or https://', null, 'errors');
  313. $action = 'createcontainer';
  314. }
  315. if (! $error)
  316. {
  317. // Clean url to grab, so url can be
  318. // http://www.example.com/ or http://www.example.com/dir1/ or http://www.example.com/dir1/aaa
  319. $urltograbwithoutdomainandparam = preg_replace('/^https?:\/\/[^\/]+\/?/i', '', $urltograb);
  320. $urltograbwithoutdomainandparam = preg_replace('/\?.*$/', '', $urltograbwithoutdomainandparam);
  321. if (empty($urltograbwithoutdomainandparam) && ! preg_match('/\/$/', $urltograb))
  322. {
  323. $urltograb.='/';
  324. }
  325. $pageurl = dol_sanitizeFileName(preg_replace('/[\/\.]/','-', preg_replace('/\/+$/', '', $urltograbwithoutdomainandparam)));
  326. $urltograbdirwithoutslash = dirname($urltograb.'.');
  327. $urltograbdirrootwithoutslash = getRootURLFromURL($urltograbdirwithoutslash);
  328. // Exemple, now $urltograbdirwithoutslash is https://www.dolimed.com/screenshots
  329. // and $urltograbdirrootwithoutslash is https://www.dolimed.com
  330. }
  331. // Check pageurl is not already used
  332. if ($pageurl)
  333. {
  334. $tmpwebsitepage = new WebsitePage($db);
  335. $result = $tmpwebsitepage->fetch(0, $object->id, $pageurl);
  336. if ($result > 0)
  337. {
  338. setEventMessages($langs->trans("AliasPageAlreadyExists", $pageurl), null, 'errors');
  339. $error++;
  340. $action='createcontainer';
  341. }
  342. }
  343. if (! $error)
  344. {
  345. $tmp = getURLContent($urltograb);
  346. if ($tmp['curl_error_no'])
  347. {
  348. $error++;
  349. setEventMessages('Error getting '.$urltograb.': '.$tmp['curl_error_msg'], null, 'errors');
  350. $action='createcontainer';
  351. }
  352. elseif ($tmp['http_code'] != '200')
  353. {
  354. $error++;
  355. setEventMessages('Error getting '.$urltograb.': '.$tmp['http_code'], null, 'errors');
  356. $action='createcontainer';
  357. }
  358. else
  359. {
  360. // Remove comments
  361. $tmp['content'] = removeHtmlComment($tmp['content']);
  362. preg_match('/<head>(.*)<\/head>/ims', $tmp['content'], $reg);
  363. $head = $reg[1];
  364. $objectpage->type_container = 'page';
  365. $objectpage->pageurl = $pageurl;
  366. if (empty($objectpage->pageurl))
  367. {
  368. $tmpdomain = getDomainFromURL($urltograb);
  369. $objectpage->pageurl=$tmpdomain.'-home';
  370. }
  371. $objectpage->aliasalt = '';
  372. if (preg_match('/^(\d+)\-/', basename($urltograb), $reg)) $objectpage->aliasalt = $reg[1];
  373. if (preg_match('/<title>(.*)<\/title>/ims', $head, $regtmp))
  374. {
  375. $objectpage->title = $regtmp[1];
  376. }
  377. if (preg_match('/<meta name="title"[^"]+content="([^"]+)"/ims', $head, $regtmp))
  378. {
  379. if (empty($objectpage->title)) $objectpage->title = $regtmp[1]; // If title not found into <title>, we get it from <meta title>
  380. }
  381. if (preg_match('/<meta name="description"[^"]+content="([^"]+)"/ims', $head, $regtmp))
  382. {
  383. $objectpage->description = $regtmp[1];
  384. }
  385. if (preg_match('/<meta name="keywords"[^"]+content="([^"]+)"/ims', $head, $regtmp))
  386. {
  387. $objectpage->keywords = $regtmp[1];
  388. }
  389. if (preg_match('/<html\s+lang="([^"]+)"/ims', $tmp['content'], $regtmp))
  390. {
  391. $tmplang=explode('-', $regtmp[1]);
  392. $objectpage->lang = $tmplang[0].($tmplang[1] ? '_'.strtoupper($tmplang[1]) : '');
  393. }
  394. $tmp['content'] = preg_replace('/\s*<meta name="generator"[^"]+content="([^"]+)"\s*\/?>/ims', '', $tmp['content']);
  395. $objectpage->content = $tmp['content'];
  396. $objectpage->content = preg_replace('/^.*<body(\s[^>]*)*>/ims', '', $objectpage->content);
  397. $objectpage->content = preg_replace('/<\/body(\s[^>]*)*>.*$/ims', '', $objectpage->content);
  398. $absoluteurlinaction=$urltograbdirwithoutslash;
  399. // TODO Replace 'action="$urltograbdirwithoutslash' into action="/"
  400. // TODO Replace 'action="$urltograbdirwithoutslash..."' into action="..."
  401. // TODO Replace 'a href="$urltograbdirwithoutslash' into a href="/"
  402. // TODO Replace 'a href="$urltograbdirwithoutslash..."' into a href="..."
  403. // Now loop to fetch all css files. Include them inline into header of page
  404. $objectpage->htmlheader = $tmp['content'];
  405. $objectpage->htmlheader = preg_replace('/^.*<head(\s[^>]*)*>/ims', '', $objectpage->htmlheader);
  406. $objectpage->htmlheader = preg_replace('/<\/head(\s[^>]*)*>.*$/ims', '', $objectpage->htmlheader);
  407. $objectpage->htmlheader = preg_replace('/<base(\s[^>]*)*>\n*/ims', '', $objectpage->htmlheader);
  408. $objectpage->htmlheader = preg_replace('/<meta http-equiv="content-type"([^>]*)*>\n*/ims', '', $objectpage->htmlheader);
  409. $objectpage->htmlheader = preg_replace('/<meta name="robots"([^>]*)*>\n*/ims', '', $objectpage->htmlheader);
  410. $objectpage->htmlheader = preg_replace('/<meta name="title"([^>]*)*>\n*/ims', '', $objectpage->htmlheader);
  411. $objectpage->htmlheader = preg_replace('/<meta name="description"([^>]*)*>\n*/ims', '', $objectpage->htmlheader);
  412. $objectpage->htmlheader = preg_replace('/<meta name="keywords"([^>]*)*>\n*/ims', '', $objectpage->htmlheader);
  413. $objectpage->htmlheader = preg_replace('/<meta name="generator"([^>]*)*>\n*/ims', '', $objectpage->htmlheader);
  414. //$objectpage->htmlheader = preg_replace('/<meta name="verify-v1[^>]*>\n*/ims', '', $objectpage->htmlheader);
  415. //$objectpage->htmlheader = preg_replace('/<meta name="msvalidate.01[^>]*>\n*/ims', '', $objectpage->htmlheader);
  416. $objectpage->htmlheader = preg_replace('/<title>[^<]*<\/title>\n*/ims', '', $objectpage->htmlheader);
  417. $objectpage->htmlheader = preg_replace('/<link[^>]*rel="shortcut[^>]*>\n/ims', '', $objectpage->htmlheader);
  418. $objectpage->htmlheader = preg_replace('/<link[^>]*rel="canonical[^>]*>\n/ims', '', $objectpage->htmlheader);
  419. // Now loop to fetch JS
  420. $tmp = $objectpage->htmlheader;
  421. preg_match_all('/<script([^\.>]+)src=["\']([^"\'>]+)["\']([^>]*)><\/script>/i', $objectpage->htmlheader, $regs);
  422. $errorforsubresource = 0;
  423. foreach ($regs[0] as $key => $val)
  424. {
  425. dol_syslog("We will grab the resource found into script tag ".$regs[2][$key]);
  426. $linkwithoutdomain = $regs[2][$key];
  427. if (preg_match('/^\//', $regs[2][$key]))
  428. {
  429. $urltograbbis = $urltograbdirrootwithoutslash.$regs[2][$key]; // We use dirroot
  430. }
  431. else
  432. {
  433. $urltograbbis = $urltograbdirwithoutslash.'/'.$regs[2][$key]; // We use dir of grabbed file
  434. }
  435. //$filetosave = $conf->medias->multidir_output[$conf->entity].'/css/'.$object->ref.'/'.$objectpage->pageurl.(preg_match('/^\//', $regs[2][$key])?'':'/').$regs[2][$key];
  436. if (preg_match('/^http/', $regs[2][$key]))
  437. {
  438. $urltograbbis = $regs[2][$key];
  439. $linkwithoutdomain = preg_replace('/^https?:\/\/[^\/]+\//i', '', $regs[2][$key]);
  440. //$filetosave = $conf->medias->multidir_output[$conf->entity].'/css/'.$object->ref.'/'.$objectpage->pageurl.(preg_match('/^\//', $linkwithoutdomain)?'':'/').$linkwithoutdomain;
  441. }
  442. //print $domaintograb.' - '.$domaintograbbis.' - '.$urltograbdirwithoutslash.' - ';
  443. //print $linkwithoutdomain.' - '.$urltograbbis."<br>\n";
  444. // Test if this is an external URL of grabbed web site. If yes, we do not load resource
  445. $domaintograb = getDomainFromURL($urltograbdirwithoutslash);
  446. $domaintograbbis = getDomainFromURL($urltograbbis);
  447. if ($domaintograb != $domaintograbbis) continue;
  448. /*
  449. $tmpgeturl = getURLContent($urltograbbis);
  450. if ($tmpgeturl['curl_error_no'])
  451. {
  452. $error++;
  453. setEventMessages('Error getting script url '.$urltograbbis.': '.$tmpgeturl['curl_error_msg'], null, 'errors');
  454. $errorforsubresource++;
  455. $action='createcontainer';
  456. }
  457. elseif ($tmpgeturl['http_code'] != '200')
  458. {
  459. $error++;
  460. setEventMessages('Error getting script url '.$urltograbbis.': '.$tmpgeturl['http_code'], null, 'errors');
  461. $errorforsubresource++;
  462. $action='createcontainer';
  463. }
  464. else
  465. {
  466. dol_mkdir(dirname($filetosave));
  467. $fp = fopen($filetosave, "w");
  468. fputs($fp, $tmpgeturl['content']);
  469. fclose($fp);
  470. if (! empty($conf->global->MAIN_UMASK))
  471. @chmod($file, octdec($conf->global->MAIN_UMASK));
  472. }
  473. */
  474. //$filename = 'image/'.$object->ref.'/'.$objectpage->pageurl.(preg_match('/^\//', $linkwithoutdomain)?'':'/').$linkwithoutdomain;
  475. $tmp = preg_replace('/'.preg_quote($regs[0][$key],'/').'/i', '', $tmp);
  476. }
  477. $objectpage->htmlheader = trim($tmp)."\n";
  478. // Now loop to fetch CSS
  479. $pagecsscontent = "\n".'<style>'."\n";
  480. preg_match_all('/<link([^\.>]+)href=["\']([^"\'>]+\.css[^"\'>]*)["\']([^>]*)>/i', $objectpage->htmlheader, $regs);
  481. $errorforsubresource = 0;
  482. foreach ($regs[0] as $key => $val)
  483. {
  484. dol_syslog("We will grab the resources found into link tag ".$regs[2][$key]);
  485. $linkwithoutdomain = $regs[2][$key];
  486. if (preg_match('/^\//', $regs[2][$key]))
  487. {
  488. $urltograbbis = $urltograbdirrootwithoutslash.$regs[2][$key]; // We use dirroot
  489. }
  490. else
  491. {
  492. $urltograbbis = $urltograbdirwithoutslash.'/'.$regs[2][$key]; // We use dir of grabbed file
  493. }
  494. //$filetosave = $conf->medias->multidir_output[$conf->entity].'/css/'.$object->ref.'/'.$objectpage->pageurl.(preg_match('/^\//', $regs[2][$key])?'':'/').$regs[2][$key];
  495. if (preg_match('/^http/', $regs[2][$key]))
  496. {
  497. $urltograbbis = $regs[2][$key];
  498. $linkwithoutdomain = preg_replace('/^https?:\/\/[^\/]+\//i', '', $regs[2][$key]);
  499. //$filetosave = $conf->medias->multidir_output[$conf->entity].'/css/'.$object->ref.'/'.$objectpage->pageurl.(preg_match('/^\//', $linkwithoutdomain)?'':'/').$linkwithoutdomain;
  500. }
  501. //print $domaintograb.' - '.$domaintograbbis.' - '.$urltograbdirwithoutslash.' - ';
  502. //print $linkwithoutdomain.' - '.$urltograbbis."<br>\n";
  503. // Test if this is an external URL of grabbed web site. If yes, we do not load resource
  504. $domaintograb = getDomainFromURL($urltograbdirwithoutslash);
  505. $domaintograbbis = getDomainFromURL($urltograbbis);
  506. if ($domaintograb != $domaintograbbis) continue;
  507. $tmpgeturl = getURLContent($urltograbbis);
  508. if ($tmpgeturl['curl_error_no'])
  509. {
  510. $errorforsubresource++;
  511. setEventMessages('Error getting link tag url '.$urltograbbis.': '.$tmpgeturl['curl_error_msg'], null, 'errors');
  512. dol_syslog('Error getting '.$urltograbbis.': '.$tmpgeturl['curl_error_msg']);
  513. $action='createcontainer';
  514. }
  515. elseif ($tmpgeturl['http_code'] != '200')
  516. {
  517. $errorforsubresource++;
  518. setEventMessages('Error getting link tag url'.$urltograbbis.': '.$tmpgeturl['http_code'], null, 'errors');
  519. dol_syslog('Error getting '.$urltograbbis.': '.$tmpgeturl['curl_error_msg']);
  520. $action='createcontainer';
  521. }
  522. else
  523. {
  524. //dol_mkdir(dirname($filetosave));
  525. //$fp = fopen($filetosave, "w");
  526. //fputs($fp, $tmpgeturl['content']);
  527. //fclose($fp);
  528. //if (! empty($conf->global->MAIN_UMASK))
  529. // @chmod($file, octdec($conf->global->MAIN_UMASK));
  530. // $filename = 'image/'.$object->ref.'/'.$objectpage->pageurl.(preg_match('/^\//', $linkwithoutdomain)?'':'/').$linkwithoutdomain;
  531. $pagecsscontent.='/* Content of file '.$urltograbbis.' */'."\n";
  532. getAllImages($object, $objectpage, $urltograbbis, $tmpgeturl['content'], $action, 1, $grabimages, $grabimagesinto);
  533. $pagecsscontent.=$tmpgeturl['content']."\n";
  534. $objectpage->htmlheader = preg_replace('/'.preg_quote($regs[0][$key],'/').'\n*/ims', '', $objectpage->htmlheader);
  535. }
  536. }
  537. $pagecsscontent.='</style>';
  538. //var_dump($pagecsscontent);
  539. //print dol_escape_htmltag($tmp);exit;
  540. $objectpage->htmlheader .= trim($pagecsscontent)."\n";
  541. // Now loop to fetch all images into page
  542. $tmp = $objectpage->content;
  543. getAllImages($object, $objectpage, $urltograb, $tmp, $action, 1, $grabimages, $grabimagesinto);
  544. // Normalize links href to Dolibarr internal naming
  545. $tmp = preg_replace('/a href="\/([^\/"]+)\/([^\/"]+)"/', 'a href="/\1-\2.php"', $tmp);
  546. $tmp = preg_replace('/a href="\/([^\/"]+)\/([^\/"]+)\/([^\/"]+)"/', 'a href="/\1-\2-\3.php"', $tmp);
  547. $tmp = preg_replace('/a href="\/([^\/"]+)\/([^\/"]+)\/([^\/"]+)\/([^\/"]+)"/', 'a href="/\1-\2-\3-\4.php"', $tmp);
  548. //print dol_escape_htmltag($tmp);exit;
  549. $objectpage->content = $tmp;
  550. $objectpage->grabbed_from = $urltograb;
  551. }
  552. }
  553. }
  554. else
  555. {
  556. $objectpage->title = GETPOST('WEBSITE_TITLE','alpha');
  557. $objectpage->type_container = GETPOST('WEBSITE_TYPE_CONTAINER','alpha');
  558. $objectpage->pageurl = GETPOST('WEBSITE_PAGENAME','alpha');
  559. $objectpage->aliasalt = GETPOST('WEBSITE_ALIASALT','alpha');
  560. $objectpage->description = GETPOST('WEBSITE_DESCRIPTION','alpha');
  561. $objectpage->image = GETPOST('WEBSITE_IMAGE','alpha');
  562. $objectpage->keywords = GETPOST('WEBSITE_KEYWORDS','alpha');
  563. $objectpage->lang = GETPOST('WEBSITE_LANG','aZ09');
  564. $objectpage->htmlheader = GETPOST('htmlheader','none');
  565. $substitutionarray=array();
  566. $substitutionarray['__WEBSITE_CREATE_BY__']=$user->getFullName($langs);
  567. $sample = GETPOST('sample','alpha');
  568. if (empty($sample)) $sample='empty';
  569. $pathtosample = DOL_DOCUMENT_ROOT.'/website/samples/page-sample-'.$sample.'.html';
  570. // Init content with content into pagetemplate.html, blogposttempltate.html, ...
  571. $objectpage->content = make_substitutions(@file_get_contents($pathtosample), $substitutionarray);
  572. }
  573. if (! $error)
  574. {
  575. if (empty($objectpage->pageurl))
  576. {
  577. $langs->load("errors");
  578. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("WEBSITE_PAGENAME")), null, 'errors');
  579. $error++;
  580. $action='createcontainer';
  581. }
  582. else if (! preg_match('/^[a-z0-9\-\_]+$/i', $objectpage->pageurl))
  583. {
  584. $langs->load("errors");
  585. setEventMessages($langs->transnoentities("ErrorFieldCanNotContainSpecialCharacters", $langs->transnoentities('WEBSITE_PAGENAME')), null, 'errors');
  586. $error++;
  587. $action='createcontainer';
  588. }
  589. if (empty($objectpage->title))
  590. {
  591. $langs->load("errors");
  592. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("WEBSITE_TITLE")), null, 'errors');
  593. $error++;
  594. $action='createcontainer';
  595. }
  596. }
  597. if (! $error)
  598. {
  599. $res = $objectpage->create($user);
  600. if ($res <= 0)
  601. {
  602. $error++;
  603. setEventMessages($objectpage->error, $objectpage->errors, 'errors');
  604. $action='createcontainer';
  605. }
  606. }
  607. if (! $error)
  608. {
  609. if (! empty($objectpage->content))
  610. {
  611. $filealias=$pathofwebsite.'/'.$objectpage->pageurl.'.php';
  612. $filetpl=$pathofwebsite.'/page'.$objectpage->id.'.tpl.php';
  613. // Save page alias
  614. $result=dolSavePageAlias($filealias, $object, $objectpage);
  615. if (! $result) setEventMessages('Failed to write file '.$filealias, null, 'errors');
  616. // Save page of content
  617. $result=dolSavePageContent($filetpl, $object, $objectpage);
  618. if ($result)
  619. {
  620. setEventMessages($langs->trans("Saved"), null, 'mesgs');
  621. }
  622. else
  623. {
  624. setEventMessages('Failed to write file '.$filetpl, null, 'errors');
  625. $action = 'createcontainer';
  626. }
  627. }
  628. }
  629. if (! $error)
  630. {
  631. $db->commit();
  632. setEventMessages($langs->trans("PageAdded", $objectpage->pageurl), null, 'mesgs');
  633. $action='';
  634. }
  635. else
  636. {
  637. $db->rollback();
  638. }
  639. if (! $error)
  640. {
  641. $pageid = $objectpage->id;
  642. // To generate the CSS, robot and htmlheader file.
  643. // Check symlink to medias and restore it if ko
  644. $pathtomedias=DOL_DATA_ROOT.'/medias';
  645. $pathtomediasinwebsite=$pathofwebsite.'/medias';
  646. if (! is_link(dol_osencode($pathtomediasinwebsite)))
  647. {
  648. dol_syslog("Create symlink for ".$pathtomedias." into name ".$pathtomediasinwebsite);
  649. dol_mkdir(dirname($pathtomediasinwebsite)); // To be sure dir for website exists
  650. $result = symlink($pathtomedias, $pathtomediasinwebsite);
  651. }
  652. if (! dol_is_file($filehtmlheader))
  653. {
  654. $htmlheadercontent ="<html>\n";
  655. $htmlheadercontent.=$htmlheadercontentdefault;
  656. $htmlheadercontent.="</html>";
  657. $result=dolSaveHtmlHeader($filehtmlheader, $htmlheadercontent);
  658. }
  659. if (! dol_is_file($filecss))
  660. {
  661. $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;}";
  662. $result=dolSaveCssFile($filecss, $csscontent);
  663. }
  664. if (! dol_is_file($filejs))
  665. {
  666. $jscontent = "/* JS content (all pages) */\n";
  667. $result=dolSaveJsFile($filejs, $jscontent);
  668. }
  669. if (! dol_is_file($filerobot))
  670. {
  671. $robotcontent = "# Robot file. Generated with Dolibarr\nUser-agent: *\nAllow: /public/\nDisallow: /administrator/";
  672. $result=dolSaveRobotFile($filerobot, $robotcontent);
  673. }
  674. if (! dol_is_file($filehtaccess))
  675. {
  676. $htaccesscontent = "# Order allow,deny\n# Deny from all";
  677. $result=dolSaveHtaccessFile($filehtaccess, $htaccesscontent);
  678. }
  679. $action = 'preview';
  680. }
  681. }
  682. // Delete site
  683. if ($action == 'deletesite')
  684. {
  685. $error = 0;
  686. $db->begin();
  687. $res = $object->fetch(0, $websitekey);
  688. $website = $object;
  689. if ($res > 0)
  690. {
  691. $res = $object->delete($user);
  692. if ($res <= 0)
  693. {
  694. $error++;
  695. setEventMessages($object->error, $object->errors, 'errors');
  696. }
  697. }
  698. if (! $error)
  699. {
  700. $db->commit();
  701. setEventMessages($langs->trans("SiteDeleted", $object->ref, $websitekey), null, 'mesgs');
  702. header("Location: ".$_SERVER["PHP_SELF"]);
  703. exit;
  704. }
  705. else
  706. {
  707. $db->rollback();
  708. dol_print_error($db);
  709. }
  710. }
  711. // Delete page
  712. if ($action == 'delete')
  713. {
  714. $error = 0;
  715. $db->begin();
  716. $res = $object->fetch(0, $websitekey);
  717. $website = $object;
  718. $res = $objectpage->fetch($pageid, $object->fk_website);
  719. if ($res > 0)
  720. {
  721. $res = $objectpage->delete($user);
  722. if ($res <= 0)
  723. {
  724. $error++;
  725. setEventMessages($objectpage->error, $objectpage->errors, 'errors');
  726. }
  727. }
  728. if (! $error)
  729. {
  730. $db->commit();
  731. setEventMessages($langs->trans("PageDeleted", $objectpage->pageurl, $websitekey), null, 'mesgs');
  732. header("Location: ".$_SERVER["PHP_SELF"].'?website='.$websitekey);
  733. exit;
  734. }
  735. else
  736. {
  737. $db->rollback();
  738. dol_print_error($db);
  739. }
  740. }
  741. // Update css
  742. if ($action == 'updatecss')
  743. {
  744. if (GETPOST('refreshsite','alpha') || GETPOST('refreshpage','alpha')) // If we tried to reload another site/page, we stay on editcss mode.
  745. {
  746. $action='editcss';
  747. }
  748. else
  749. {
  750. $res = $object->fetch(0, $websitekey);
  751. $website = $object;
  752. if (GETPOSTISSET('virtualhost'))
  753. {
  754. if (GETPOST('virtualhost','alpha') && ! preg_match('/^http/',GETPOST('virtualhost','alpha')))
  755. {
  756. $error++;
  757. setEventMessages($langs->trans('ErrorURLMustStartWithHttp', $langs->transnoentitiesnoconv("VirtualHost")), null, 'errors');
  758. $action='editcss';
  759. }
  760. if (! $error)
  761. {
  762. $object->virtualhost = GETPOST('virtualhost','alpha');
  763. $result = $object->update($user);
  764. if ($result < 0)
  765. {
  766. $error++;
  767. setEventMessages($object->error, $object->errors, 'errors');
  768. $action='editcss';
  769. }
  770. }
  771. }
  772. if (! $error)
  773. {
  774. // Save master.inc.php file
  775. $filemaster=$pathofwebsite.'/master.inc.php';
  776. dol_syslog("Save master file ".$filemaster);
  777. dol_mkdir($pathofwebsite);
  778. // Now generate the master.inc.php page
  779. $result = dolSaveMasterFile($filemaster);
  780. if (! $result) setEventMessages('Failed to write file '.$filemaster, null, 'errors');
  781. // Html header file
  782. $htmlheadercontent ='';
  783. /* We disable php code since htmlheader is never executed as an include but only read by fgets_content.
  784. $htmlheadercontent.= "<?php // BEGIN PHP\n";
  785. $htmlheadercontent.= '$websitekey=basename(dirname(__FILE__));'."\n";
  786. $htmlheadercontent.= "if (! defined('USEDOLIBARRSERVER') && ! defined('USEDOLIBARREDITOR')) { require_once './master.inc.php'; } // Not already loaded"."\n";
  787. $htmlheadercontent.= "require_once DOL_DOCUMENT_ROOT.'/core/lib/website.lib.php';\n";
  788. $htmlheadercontent.= "require_once DOL_DOCUMENT_ROOT.'/core/website.inc.php';\n";
  789. $htmlheadercontent.= "ob_start();\n";
  790. // $htmlheadercontent.= "header('Content-type: text/html');\n"; // Not required. htmlheader.html is never call as a standalone page
  791. $htmlheadercontent.= "// END PHP ?>\n";*/
  792. $htmlheadercontent.= preg_replace(array('/<html>\n*/ims','/<\/html>\n*/ims'),array('',''),GETPOST('WEBSITE_HTML_HEADER', 'none'));
  793. /*$htmlheadercontent.= "\n".'<?php // BEGIN PHP'."\n";
  794. $htmlheadercontent.= '$tmp = ob_get_contents(); ob_end_clean(); dolWebsiteOutput($tmp);'."\n";
  795. $htmlheadercontent.= "// END PHP ?>"."\n";*/
  796. $htmlheadercontent = trim($htmlheadercontent)."\n";
  797. dolSaveHtmlHeader($filehtmlheader, $htmlheadercontent);
  798. // Css file
  799. $csscontent ='';
  800. $csscontent.= "<?php // BEGIN PHP\n";
  801. $csscontent.= '$websitekey=basename(dirname(__FILE__));'."\n";
  802. $csscontent.= "if (! defined('USEDOLIBARRSERVER') && ! defined('USEDOLIBARREDITOR')) { require_once dirname(__FILE__).'/master.inc.php'; } // Not already loaded"."\n"; // For the css, we need to set path of master using the dirname of css file.
  803. $csscontent.= "require_once DOL_DOCUMENT_ROOT.'/core/lib/website.lib.php';\n";
  804. $csscontent.= "require_once DOL_DOCUMENT_ROOT.'/core/website.inc.php';\n";
  805. $csscontent.= "ob_start();\n";
  806. $csscontent.= "header('Cache-Control: max-age=3600, public, must-revalidate');\n";
  807. $csscontent.= "header('Content-type: text/css');\n";
  808. $csscontent.= "// END PHP ?>\n";
  809. $csscontent.= GETPOST('WEBSITE_CSS_INLINE', 'none');
  810. $csscontent.= "\n".'<?php // BEGIN PHP'."\n";
  811. $csscontent.= '$tmp = ob_get_contents(); ob_end_clean(); dolWebsiteOutput($tmp);'."\n";
  812. $csscontent.= "// END PHP ?>"."\n";
  813. dol_syslog("Save css content into ".$filecss);
  814. dol_mkdir($pathofwebsite);
  815. $result = file_put_contents($filecss, $csscontent);
  816. if (! empty($conf->global->MAIN_UMASK))
  817. @chmod($filecss, octdec($conf->global->MAIN_UMASK));
  818. if (! $result)
  819. {
  820. $error++;
  821. setEventMessages('Failed to write file '.$filecss, null, 'errors');
  822. }
  823. // Js file
  824. $jscontent ='';
  825. $jscontent.= "<?php // BEGIN PHP\n";
  826. $jscontent.= '$websitekey=basename(dirname(__FILE__));'."\n";
  827. $jscontent.= "if (! defined('USEDOLIBARRSERVER') && ! defined('USEDOLIBARREDITOR')) { require_once dirname(__FILE__).'/master.inc.php'; } // Not already loaded"."\n"; // For the css, we need to set path of master using the dirname of css file.
  828. $jscontent.= "require_once DOL_DOCUMENT_ROOT.'/core/lib/website.lib.php';\n";
  829. $jscontent.= "require_once DOL_DOCUMENT_ROOT.'/core/website.inc.php';\n";
  830. $jscontent.= "ob_start();\n";
  831. $jscontent.= "header('Cache-Control: max-age=3600, public, must-revalidate');\n";
  832. $jscontent.= "header('Content-type: application/javascript');\n";
  833. $jscontent.= "// END PHP ?>\n";
  834. $jscontent.= GETPOST('WEBSITE_JS_INLINE', 'none');
  835. $jscontent.= "\n".'<?php // BEGIN PHP'."\n";
  836. $jscontent.= '$tmp = ob_get_contents(); ob_end_clean(); dolWebsiteOutput($tmp);'."\n";
  837. $jscontent.= "// END PHP ?>"."\n";
  838. dol_syslog("Save js content into ".$filejs);
  839. dol_mkdir($pathofwebsite);
  840. $result = file_put_contents($filejs, $jscontent);
  841. if (! empty($conf->global->MAIN_UMASK))
  842. @chmod($filejs, octdec($conf->global->MAIN_UMASK));
  843. if (! $result)
  844. {
  845. $error++;
  846. setEventMessages('Failed to write file '.$filejs, null, 'errors');
  847. }
  848. // Robot file
  849. $robotcontent ='';
  850. /*$robotcontent.= "<?php // BEGIN PHP\n";
  851. $robotcontent.= '$websitekey=basename(dirname(__FILE__));'."\n";
  852. $robotcontent.= "if (! defined('USEDOLIBARRSERVER') && ! defined('USEDOLIBARREDITOR')) { require_once './master.inc.php'; } // Not already loaded"."\n";
  853. $robotcontent.= "require_once DOL_DOCUMENT_ROOT.'/core/lib/website.lib.php';\n";
  854. $robotcontent.= "require_once DOL_DOCUMENT_ROOT.'/core/website.inc.php';\n";
  855. $robotcontent.= "ob_start();\n";
  856. $robotcontent.= "header('Cache-Control: max-age=3600, public, must-revalidate');\n";
  857. $robotcontent.= "header('Content-type: text/css');\n";
  858. $robotcontent.= "// END PHP ?>\n";*/
  859. $robotcontent.= GETPOST('WEBSITE_ROBOT', 'none');
  860. /*$robotcontent.= "\n".'<?php // BEGIN PHP'."\n";
  861. $robotcontent.= '$tmp = ob_get_contents(); ob_end_clean(); dolWebsiteOutput($tmp);'."\n";
  862. $robotcontent.= "// END PHP ?>"."\n";*/
  863. dol_syslog("Save file robot into ".$filerobot);
  864. dol_mkdir($pathofwebsite);
  865. $result = file_put_contents($filerobot, $robotcontent);
  866. if (! empty($conf->global->MAIN_UMASK))
  867. @chmod($filerobot, octdec($conf->global->MAIN_UMASK));
  868. if (! $result)
  869. {
  870. $error++;
  871. setEventMessages('Failed to write file '.$filerobot, null, 'errors');
  872. }
  873. // Css file
  874. $htaccesscontent ='';
  875. /*$htaccesscontent.= "<?php // BEGIN PHP\n";
  876. $htaccesscontent.= '$websitekey=basename(dirname(__FILE__));'."\n";
  877. $htaccesscontent.= "if (! defined('USEDOLIBARRSERVER') && ! defined('USEDOLIBARREDITOR')) { require_once './master.inc.php'; } // Not already loaded"."\n";
  878. $htaccesscontent.= "require_once DOL_DOCUMENT_ROOT.'/core/lib/website.lib.php';\n";
  879. $htaccesscontent.= "require_once DOL_DOCUMENT_ROOT.'/core/website.inc.php';\n";
  880. $htaccesscontent.= "ob_start();\n";
  881. $htaccesscontent.= "header('Cache-Control: max-age=3600, public, must-revalidate');\n";
  882. $htaccesscontent.= "header('Content-type: text/css');\n";
  883. $htaccesscontent.= "// END PHP ?>\n";*/
  884. $htaccesscontent.= GETPOST('WEBSITE_HTACCESS', 'none');
  885. /*$htaccesscontent.= "\n".'<?php // BEGIN PHP'."\n";
  886. $htaccesscontent.= '$tmp = ob_get_contents(); ob_end_clean(); dolWebsiteOutput($tmp);'."\n";
  887. $htaccesscontent.= "// END PHP ?>"."\n";*/
  888. dol_syslog("Save file htaccess into ".$filehtaccess);
  889. dol_mkdir($pathofwebsite);
  890. $result = file_put_contents($filehtaccess, $htaccesscontent);
  891. if (! empty($conf->global->MAIN_UMASK))
  892. @chmod($filehtaccess, octdec($conf->global->MAIN_UMASK));
  893. if (! $result)
  894. {
  895. $error++;
  896. setEventMessages('Failed to write file '.$filehtaccess, null, 'errors');
  897. }
  898. // Message if no error
  899. if (! $error)
  900. {
  901. setEventMessages($langs->trans("Saved"), null, 'mesgs');
  902. }
  903. $action='preview';
  904. }
  905. }
  906. }
  907. // Update page
  908. if ($action == 'setashome')
  909. {
  910. $db->begin();
  911. $object->fetch(0, $websitekey);
  912. $website = $object;
  913. $object->fk_default_home = $pageid;
  914. $res = $object->update($user);
  915. if (! $res > 0)
  916. {
  917. $error++;
  918. setEventMessages($object->error, $object->errors, 'errors');
  919. }
  920. if (! $error)
  921. {
  922. $db->commit();
  923. // Generate the index.php page to be the home page
  924. //-------------------------------------------------
  925. $result = dolSaveIndexPage($pathofwebsite, $fileindex, $filetpl, $filewrapper);
  926. if ($result) setEventMessages($langs->trans("Saved"), null, 'mesgs');
  927. else setEventMessages('Failed to write file '.$fileindex, null, 'errors');
  928. $action='preview';
  929. }
  930. else
  931. {
  932. $db->rollback();
  933. }
  934. }
  935. // Update page (meta)
  936. if ($action == 'updatemeta')
  937. {
  938. $db->begin();
  939. $result = $object->fetch(0, $websitekey);
  940. $website = $object;
  941. $objectpage->fk_website = $object->id;
  942. // Check parameters
  943. if (! preg_match('/^[a-z0-9\-\_]+$/i', GETPOST('WEBSITE_PAGENAME', 'alpha')))
  944. {
  945. $error++;
  946. $langs->load("errors");
  947. setEventMessages($langs->transnoentities("ErrorFieldCanNotContainSpecialCharacters", $langs->transnoentities('WEBSITE_PAGENAME')), null, 'errors');
  948. $action='editmeta';
  949. }
  950. $res = $objectpage->fetch($pageid, $object->id);
  951. if ($res <= 0)
  952. {
  953. $error++;
  954. setEventMessages('Page not found '.$objectpage->error, $objectpage->errors, 'errors');
  955. }
  956. // Check alias not exists
  957. if (! $error && GETPOST('WEBSITE_PAGENAME', 'alpha'))
  958. {
  959. $websitepagetemp=new WebsitePage($db);
  960. $result = $websitepagetemp->fetch(-1 * $objectpage->id, $object->id, GETPOST('WEBSITE_PAGENAME', 'alpha'));
  961. if ($result < 0)
  962. {
  963. $error++;
  964. $langs->load("errors");
  965. setEventMessages($websitepagetemp->error, $websitepagetemp->errors, 'errors');
  966. $action = 'editmeta';
  967. }
  968. if ($result > 0)
  969. {
  970. $error++;
  971. $langs->load("errors");
  972. setEventMessages($langs->trans("ErrorAPageWithThisNameOrAliasAlreadyExists", $websitepagetemp->pageurl), null, 'errors');
  973. $action = 'editmeta';
  974. }
  975. }
  976. if (! $error && GETPOST('WEBSITE_ALIASALT', 'alpha'))
  977. {
  978. $arrayofaliastotest=explode(',', GETPOST('WEBSITE_ALIASALT', 'alpha'));
  979. $websitepagetemp=new WebsitePage($db);
  980. foreach($arrayofaliastotest as $aliastotest)
  981. {
  982. $result = $websitepagetemp->fetch(-1 * $objectpage->id, $object->id, $aliastotest);
  983. if ($result < 0)
  984. {
  985. $error++;
  986. $langs->load("errors");
  987. setEventMessages($websitepagetemp->error, $websitepagetemp->errors, 'errors');
  988. $action = 'editmeta';
  989. break;
  990. }
  991. if ($result > 0)
  992. {
  993. $error++;
  994. $langs->load("errors");
  995. setEventMessages($langs->trans("ErrorAPageWithThisNameOrAliasAlreadyExists", $websitepagetemp->pageurl), null, 'errors');
  996. $action = 'editmeta';
  997. break;
  998. }
  999. }
  1000. }
  1001. if (! $error)
  1002. {
  1003. $objectpage->old_object = clone $objectpage;
  1004. $objectpage->title = GETPOST('WEBSITE_TITLE', 'alpha');
  1005. $objectpage->type_container = GETPOST('WEBSITE_TYPE_CONTAINER', 'alpha');
  1006. $objectpage->pageurl = GETPOST('WEBSITE_PAGENAME', 'alpha');
  1007. $objectpage->aliasalt = GETPOST('WEBSITE_ALIASALT', 'alpha');
  1008. $objectpage->description = GETPOST('WEBSITE_DESCRIPTION', 'alpha');
  1009. $objectpage->image = GETPOST('WEBSITE_IMAGE', 'alpha');
  1010. $objectpage->keywords = GETPOST('WEBSITE_KEYWORDS', 'alpha');
  1011. $objectpage->lang = GETPOST('WEBSITE_LANG', 'aZ09');
  1012. $objectpage->htmlheader = trim(GETPOST('htmlheader', 'none'));
  1013. $newdatecreation=dol_mktime(GETPOST('datecreationhour','int'), GETPOST('datecreationmin','int'), GETPOST('datecreationsec','int'), GETPOST('datecreationmonth','int'), GETPOST('datecreationday','int'), GETPOST('datecreationyear','int'));
  1014. if ($newdatecreation) $objectpage->date_creation = $newdatecreation;
  1015. $res = $objectpage->update($user);
  1016. if (! ($res > 0))
  1017. {
  1018. $langs->load("errors");
  1019. if ($db->lasterrno == 'DB_ERROR_RECORD_ALREADY_EXISTS')
  1020. {
  1021. $error++;
  1022. $langs->load("errors");
  1023. setEventMessages($langs->trans("ErrorAPageWithThisNameOrAliasAlreadyExists"), null, 'errors');
  1024. $action = 'editmeta';
  1025. }
  1026. else
  1027. {
  1028. $error++;
  1029. $langs->load("errors");
  1030. setEventMessages($objectpage->error, $objectpage->errors, 'errors');
  1031. $action = 'editmeta';
  1032. }
  1033. }
  1034. }
  1035. if (! $error)
  1036. {
  1037. $db->commit();
  1038. }
  1039. else
  1040. {
  1041. $db->rollback();
  1042. }
  1043. if (! $error)
  1044. {
  1045. $filemaster=$pathofwebsite.'/master.inc.php';
  1046. $fileoldalias=$pathofwebsite.'/'.$objectpage->old_object->pageurl.'.php';
  1047. $filealias=$pathofwebsite.'/'.$objectpage->pageurl.'.php';
  1048. dol_mkdir($pathofwebsite);
  1049. // Now generate the master.inc.php page
  1050. $result = dolSaveMasterFile($filemaster);
  1051. if (! $result) setEventMessages('Failed to write file '.$filemaster, null, 'errors');
  1052. // Now delete the alias.php page
  1053. if (! empty($fileoldalias))
  1054. {
  1055. dol_syslog("We delete old alias page name=".$fileoldalias." to build a new alias page=".$filealias);
  1056. dol_delete_file($fileoldalias);
  1057. }
  1058. // Now delete the alternative alias.php pages
  1059. if (! empty($objectpage->old_object->aliasalt))
  1060. {
  1061. $tmpaltaliases=explode(',', $objectpage->old_object->aliasalt);
  1062. if (is_array($tmpaltaliases))
  1063. {
  1064. foreach($tmpaltaliases as $tmpaliasalt)
  1065. {
  1066. dol_syslog("We delete old alt alias pages name=".trim($tmpaliasalt));
  1067. dol_delete_file($pathofwebsite.'/'.trim($tmpaliasalt).'.php');
  1068. }
  1069. }
  1070. }
  1071. // Save page alias
  1072. $result=dolSavePageAlias($filealias, $object, $objectpage);
  1073. if (! $result) setEventMessages('Failed to write file '.$filealias, null, 'errors');
  1074. // Save alt aliases
  1075. if (! empty($objectpage->aliasalt))
  1076. {
  1077. $tmpaltaliases=explode(',', $objectpage->aliasalt);
  1078. if (is_array($tmpaltaliases))
  1079. {
  1080. foreach($tmpaltaliases as $tmpaliasalt)
  1081. {
  1082. $result=dolSavePageAlias($pathofwebsite.'/'.trim($tmpaliasalt).'.php', $object, $objectpage);
  1083. if (! $result) setEventMessages('Failed to write file '.$pathofwebsite.'/'.trim($tmpaliasalt).'.php', null, 'errors');
  1084. }
  1085. }
  1086. }
  1087. // Save page of content
  1088. $result=dolSavePageContent($filetpl, $object, $objectpage);
  1089. if ($result)
  1090. {
  1091. setEventMessages($langs->trans("Saved"), null, 'mesgs');
  1092. //header("Location: ".$_SERVER["PHP_SELF"].'?website='.$websitekey.'&pageid='.$pageid);
  1093. //exit;
  1094. }
  1095. else
  1096. {
  1097. setEventMessages('Failed to write file '.$filetpl, null, 'errors');
  1098. //header("Location: ".$_SERVER["PHP_SELF"].'?website='.$websitekey.'&pageid='.$pageid);
  1099. //exit;
  1100. }
  1101. $action='preview';
  1102. }
  1103. }
  1104. // Update page
  1105. if (($action == 'updatesource' || $action == 'updatecontent' || $action == 'confirm_createfromclone' || $action == 'confirm_createpagefromclone')
  1106. || ($action == 'preview' && (GETPOST('refreshsite') || GETPOST('refreshpage') || GETPOST('preview'))))
  1107. {
  1108. $object->fetch(0, $websitekey);
  1109. $website = $object;
  1110. if ($action == 'confirm_createfromclone')
  1111. {
  1112. $db->begin();
  1113. $objectnew = new Website($db);
  1114. $result = $objectnew->createFromClone($user, GETPOST('id','int'), GETPOST('siteref','aZ09'), (GETPOST('newlang','aZ09')?GETPOST('newlang','aZ09'):''));
  1115. if ($result < 0)
  1116. {
  1117. $error++;
  1118. setEventMessages($objectnew->error, $objectnew->errors, 'errors');
  1119. $action='preview';
  1120. $db->rollback();
  1121. }
  1122. else
  1123. {
  1124. $object = $objectnew;
  1125. $id = $object->id;
  1126. $pageid = $object->fk_default_home;
  1127. $websitekey = GETPOST('siteref','aZ09');
  1128. $db->commit();
  1129. }
  1130. }
  1131. if ($action == 'confirm_createpagefromclone')
  1132. {
  1133. $istranslation=(GETPOST('is_a_translation','aZ09')=='on'?1:0);
  1134. if ($istranslation)
  1135. {
  1136. if (GETPOST('newlang','aZ09') == $objectpage->lang)
  1137. {
  1138. $error++;
  1139. setEventMessages($langs->trans("LanguageMustNotBeSameThanClonedPage"), null, 'errors');
  1140. $action='preview';
  1141. }
  1142. }
  1143. if (! $error)
  1144. {
  1145. $db->begin();
  1146. $newwebsiteid = GETPOST('newwebsite','int');
  1147. $pathofwebsitenew = $pathofwebsite;
  1148. $tmpwebsite=new Website($db);
  1149. if ($newwebsiteid > 0 && $newwebsiteid != $object->id)
  1150. {
  1151. $tmpwebsite->fetch($newwebsiteid);
  1152. $pathofwebsitenew = $dolibarr_main_data_root.'/website/'.$tmpwebsite->ref;
  1153. }
  1154. else
  1155. {
  1156. $tmpwebsite = $object;
  1157. }
  1158. $objectpage = new WebsitePage($db);
  1159. $resultpage = $objectpage->createFromClone($user, $pageid, GETPOST('pageurl','aZ09'), (GETPOST('newlang','aZ09')?GETPOST('newlang','aZ09'):''), $istranslation, $newwebsiteid);
  1160. if ($resultpage < 0)
  1161. {
  1162. $error++;
  1163. setEventMessages($objectpage->error, $objectpage->errors, 'errors');
  1164. $action='createpagefromclone';
  1165. $db->rollback();
  1166. }
  1167. else
  1168. {
  1169. $fileindex=$pathofwebsitenew.'/index.php';
  1170. $filetpl=$pathofwebsitenew.'/page'.$resultpage->id.'.tpl.php';
  1171. $filewrapper=$pathofwebsitenew.'/wrapper.php';
  1172. //var_dump($pathofwebsitenew);
  1173. //var_dump($filetpl);
  1174. //exit;
  1175. dolSavePageContent($filetpl, $tmpwebsite, $resultpage);
  1176. // Switch on the new page if web site of new page/container is same
  1177. if (empty($newwebsiteid) || $newwebsiteid == $object->id)
  1178. {
  1179. $pageid = $resultpage->id;
  1180. }
  1181. $db->commit();
  1182. }
  1183. }
  1184. }
  1185. $res = 0;
  1186. if (! $error)
  1187. {
  1188. // Check symlink to medias and restore it if ko
  1189. $pathtomedias=DOL_DATA_ROOT.'/medias';
  1190. $pathtomediasinwebsite=$pathofwebsite.'/medias';
  1191. if (! is_link(dol_osencode($pathtomediasinwebsite)))
  1192. {
  1193. dol_syslog("Create symlink for ".$pathtomedias." into name ".$pathtomediasinwebsite);
  1194. dol_mkdir(dirname($pathtomediasinwebsite)); // To be sure dir for website exists
  1195. $result = symlink($pathtomedias, $pathtomediasinwebsite);
  1196. }
  1197. /*if (GETPOST('savevirtualhost') && $object->virtualhost != GETPOST('previewsite'))
  1198. {
  1199. $object->virtualhost = GETPOST('previewsite', 'alpha');
  1200. $object->update($user);
  1201. }*/
  1202. $objectpage->fk_website = $object->id;
  1203. if ($pageid > 0)
  1204. {
  1205. $res = $objectpage->fetch($pageid);
  1206. }
  1207. else
  1208. {
  1209. $res=0;
  1210. if ($object->fk_default_home > 0)
  1211. {
  1212. $res = $objectpage->fetch($object->fk_default_home);
  1213. }
  1214. if (! ($res > 0))
  1215. {
  1216. $res = $objectpage->fetch(0, $object->id);
  1217. }
  1218. }
  1219. }
  1220. if (! $error && $res > 0)
  1221. {
  1222. if ($action == 'updatesource' || $action == 'updatecontent')
  1223. {
  1224. $db->begin();
  1225. $objectpage->content = GETPOST('PAGE_CONTENT','none');
  1226. // Clean data. We remove all the head section.
  1227. $objectpage->content = preg_replace('/<head>.*<\/head>/ims', '', $objectpage->content);
  1228. /* $objectpage->content = preg_replace('/<base\s+href=[\'"][^\'"]+[\'"]\s/?>/s', '', $objectpage->content); */
  1229. $res = $objectpage->update($user);
  1230. if ($res < 0)
  1231. {
  1232. $error++;
  1233. setEventMessages($objectpage->error, $objectpage->errors, 'errors');
  1234. }
  1235. if (! $error)
  1236. {
  1237. $db->commit();
  1238. $filemaster=$pathofwebsite.'/master.inc.php';
  1239. //$fileoldalias=$pathofwebsite.'/'.$objectpage->old_object->pageurl.'.php';
  1240. $filealias=$pathofwebsite.'/'.$objectpage->pageurl.'.php';
  1241. dol_mkdir($pathofwebsite);
  1242. // Now generate the master.inc.php page
  1243. $result = dolSaveMasterFile($filemaster);
  1244. if (! $result) setEventMessages('Failed to write file '.$filemaster, null, 'errors');
  1245. // Now generate the alias.php page
  1246. if (! empty($fileoldalias))
  1247. {
  1248. dol_syslog("We regenerate alias page new name=".$filealias.", old name=".$fileoldalias);
  1249. dol_delete_file($fileoldalias);
  1250. }
  1251. // Save page alias
  1252. $result=dolSavePageAlias($filealias, $object, $objectpage);
  1253. if (! $result) setEventMessages('Failed to write file '.$filealias, null, 'errors');
  1254. // Save page content
  1255. $result=dolSavePageContent($filetpl, $object, $objectpage);
  1256. if ($result)
  1257. {
  1258. setEventMessages($langs->trans("Saved"), null, 'mesgs');
  1259. header("Location: ".$_SERVER["PHP_SELF"].'?website='.$websitekey.'&pageid='.$pageid);
  1260. exit;
  1261. }
  1262. else
  1263. {
  1264. setEventMessages('Failed to write file '.$filetpl, null, 'errors');
  1265. header("Location: ".$_SERVER["PHP_SELF"].'?website='.$websitekey.'&pageid='.$pageid);
  1266. exit;
  1267. }
  1268. }
  1269. else
  1270. {
  1271. $db->rollback();
  1272. }
  1273. }
  1274. else
  1275. {
  1276. header("Location: ".$_SERVER["PHP_SELF"].'?website='.$websitekey.'&pageid='.$pageid);
  1277. exit;
  1278. }
  1279. }
  1280. else
  1281. {
  1282. if (! $error)
  1283. {
  1284. if (empty($websitekey) || $websitekey == '-1')
  1285. {
  1286. setEventMessages($langs->trans("NoWebSiteCreateOneFirst"), null, 'warnings');
  1287. }
  1288. else
  1289. {
  1290. setEventMessages($langs->trans("NoPageYet"), null, 'warnings');
  1291. setEventMessages($langs->trans("YouCanCreatePageOrImportTemplate"), null, 'warnings');
  1292. }
  1293. }
  1294. }
  1295. }
  1296. // Export site
  1297. if ($action == 'exportsite')
  1298. {
  1299. $fileofzip = $object->exportWebSite();
  1300. if ($fileofzip)
  1301. {
  1302. $file_name = basename($fileofzip);
  1303. header("Content-Type: application/zip");
  1304. header("Content-Disposition: attachment; filename=".$file_name);
  1305. header("Content-Length: " . filesize($fileofzip));
  1306. readfile($fileofzip);
  1307. exit;
  1308. }
  1309. }
  1310. // Import site
  1311. if ($action == 'importsiteconfirm')
  1312. {
  1313. if (empty($_FILES))
  1314. {
  1315. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("File")), null, 'errors');
  1316. $action = 'importsite';
  1317. }
  1318. else
  1319. {
  1320. if (! empty($_FILES))
  1321. {
  1322. // Check symlink to medias and restore it if ko
  1323. $pathtomedias=DOL_DATA_ROOT.'/medias';
  1324. $pathtomediasinwebsite=$pathofwebsite.'/medias';
  1325. if (! is_link(dol_osencode($pathtomediasinwebsite)))
  1326. {
  1327. dol_syslog("Create symlink for ".$pathtomedias." into name ".$pathtomediasinwebsite);
  1328. dol_mkdir(dirname($pathtomediasinwebsite)); // To be sure dir for website exists
  1329. $result = symlink($pathtomedias, $pathtomediasinwebsite);
  1330. if (! $result)
  1331. {
  1332. setEventMessages($langs->trans("ErrorFieldToCreateSymLinkToMedias", $pathtomediasinwebsite, $pathtomedias), null, 'errors');
  1333. $action = 'importsite';
  1334. }
  1335. }
  1336. if (is_array($_FILES['userfile']['tmp_name'])) $userfiles=$_FILES['userfile']['tmp_name'];
  1337. else $userfiles=array($_FILES['userfile']['tmp_name']);
  1338. foreach($userfiles as $key => $userfile)
  1339. {
  1340. if (empty($_FILES['userfile']['tmp_name'][$key]))
  1341. {
  1342. $error++;
  1343. if ($_FILES['userfile']['error'][$key] == 1 || $_FILES['userfile']['error'][$key] == 2){
  1344. setEventMessages($langs->trans('ErrorFileSizeTooLarge'), null, 'errors');
  1345. $action = 'importsite';
  1346. }
  1347. else {
  1348. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("File")), null, 'errors');
  1349. $action = 'importsite';
  1350. }
  1351. }
  1352. }
  1353. if (! $error)
  1354. {
  1355. $upload_dir = $conf->website->dir_temp;
  1356. $result = dol_add_file_process($upload_dir, 1, -1, 'userfile', '');
  1357. // Get name of file (take last one if several name provided)
  1358. $fileofzip = $upload_dir.'/unknown';
  1359. foreach($_FILES as $key => $ifile)
  1360. {
  1361. foreach($ifile['name'] as $key2 => $ifile2)
  1362. {
  1363. $fileofzip = $upload_dir . '/' .$ifile2;
  1364. }
  1365. }
  1366. $result = $object->importWebSite($fileofzip);
  1367. if ($result < 0)
  1368. {
  1369. setEventMessages($object->error, $object->errors, 'errors');
  1370. $action = 'importsite';
  1371. }
  1372. else
  1373. {
  1374. header("Location: ".$_SERVER["PHP_SELF"].'?website='.$object->ref);
  1375. exit();
  1376. }
  1377. }
  1378. }
  1379. }
  1380. }
  1381. /*
  1382. * View
  1383. */
  1384. $form = new Form($db);
  1385. $formadmin = new FormAdmin($db);
  1386. $formwebsite = new FormWebsite($db);
  1387. $formother = new FormOther($db);
  1388. $help_url='';
  1389. $arrayofjs = array(
  1390. '/includes/ace/ace.js',
  1391. '/includes/ace/ext-statusbar.js',
  1392. '/includes/ace/ext-language_tools.js',
  1393. //'/includes/ace/ext-chromevox.js'
  1394. //'/includes/jquery/plugins/jqueryscoped/jquery.scoped.js',
  1395. );
  1396. $arrayofcss = array();
  1397. $moreheadcss='';
  1398. $moreheadjs='';
  1399. $arrayofjs[]='includes/jquery/plugins/blockUI/jquery.blockUI.js';
  1400. $arrayofjs[]='core/js/blockUI.js'; // Used by ecm/tpl/enabledfiletreeajax.tpl.php
  1401. if (empty($conf->global->MAIN_ECM_DISABLE_JS)) $arrayofjs[]="includes/jquery/plugins/jqueryFileTree/jqueryFileTree.js";
  1402. $moreheadjs.='<script type="text/javascript">'."\n";
  1403. $moreheadjs.='var indicatorBlockUI = \''.DOL_URL_ROOT."/theme/".$conf->theme."/img/working.gif".'\';'."\n";
  1404. $moreheadjs.='</script>'."\n";
  1405. llxHeader($moreheadcss.$moreheadjs, $langs->trans("WebsiteSetup"), $help_url, '', 0, 0, $arrayofjs, $arrayofcss, '', '', '<!-- Begin div class="fiche" -->'."\n".'<div class="fichebutwithotherclass">');
  1406. print "\n".'<form action="'.$_SERVER["PHP_SELF"].'" method="POST" enctype="multipart/form-data">';
  1407. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  1408. if ($action == 'createsite')
  1409. {
  1410. print '<input type="hidden" name="action" value="addsite">';
  1411. }
  1412. if ($action == 'createcontainer')
  1413. {
  1414. print '<input type="hidden" name="action" value="addcontainer">';
  1415. }
  1416. if ($action == 'editcss')
  1417. {
  1418. print '<input type="hidden" name="action" value="updatecss">';
  1419. }
  1420. if ($action == 'editmenu')
  1421. {
  1422. print '<input type="hidden" name="action" value="updatemenu">';
  1423. }
  1424. if ($action == 'setashome')
  1425. {
  1426. print '<input type="hidden" name="action" value="updateashome">';
  1427. }
  1428. if ($action == 'editmeta')
  1429. {
  1430. print '<input type="hidden" name="action" value="updatemeta">';
  1431. }
  1432. if ($action == 'editsource')
  1433. {
  1434. print '<input type="hidden" name="action" value="updatesource">';
  1435. }
  1436. if ($action == 'editcontent')
  1437. {
  1438. print '<input type="hidden" name="action" value="updatecontent">';
  1439. }
  1440. if ($action == 'edit')
  1441. {
  1442. print '<input type="hidden" name="action" value="update">';
  1443. }
  1444. if ($action == 'importsite')
  1445. {
  1446. print '<input type="hidden" name="action" value="importsiteconfirm">';
  1447. }
  1448. if ($action == 'file_manager')
  1449. {
  1450. print '<input type="hidden" name="action" value="file_manager">';
  1451. }
  1452. print '<div>';
  1453. // Add a margin under toolbar ?
  1454. $style='';
  1455. if ($action != 'preview' && $action != 'editcontent' && $action != 'editsource') $style=' margin-bottom: 5px;';
  1456. if (! GETPOST('hide_websitemenu'))
  1457. {
  1458. //var_dump($objectpage);exit;
  1459. print '<div class="centpercent websitebar">';
  1460. // ***** Part for web sites
  1461. print '<!-- Bar for website -->';
  1462. print '<div class="websiteselection hideonsmartphoneimp minwidth100 tdoverflowmax100">';
  1463. print $langs->trans("Website").' : ';
  1464. print '</div>';
  1465. print '<div class="websiteselection hideonsmartphoneimp">';
  1466. print ' <input type="submit"'.$disabled.' class="button" value="'.dol_escape_htmltag($langs->trans("Add")).'" name="createsite">';
  1467. print '</div>';
  1468. // List of website
  1469. print '<div class="websiteselection">';
  1470. $out='';
  1471. $out.='<select name="website" class="minwidth100" id="website">';
  1472. if (empty($object->records)) $out.='<option value="-1">&nbsp;</option>';
  1473. // Loop on each sites
  1474. $i=0;
  1475. foreach($object->records as $key => $valwebsite)
  1476. {
  1477. if (empty($websitekey)) $websitekey=$valwebsite->ref;
  1478. $out.='<option value="'.$valwebsite->ref.'"';
  1479. if ($websitekey == $valwebsite->ref) $out.=' selected'; // To preselect a value
  1480. $out.='>';
  1481. $out.=$valwebsite->ref;
  1482. $out.='</option>';
  1483. $i++;
  1484. }
  1485. $out.='</select>';
  1486. $out.=ajax_combobox('website');
  1487. print $out;
  1488. //print '<input type="submit" class="button" name="refreshsite" value="'.$langs->trans("Load").'">';
  1489. print '<input type="image" class="valignmiddle" src="'.img_picto('', 'refresh', '', 0, 1).'" name="refreshpage" value="'.$langs->trans("Load").'">';
  1490. if ($websitekey)
  1491. {
  1492. $virtualurl='';
  1493. $dataroot=DOL_DATA_ROOT.'/website/'.$websitekey;
  1494. if (! empty($object->virtualhost)) $virtualurl=$object->virtualhost;
  1495. }
  1496. $array=array();
  1497. if ($object->id > 0)
  1498. {
  1499. $array=$objectpage->fetchAll($object->id, 'ASC,ASC', 'type_container,pageurl');
  1500. }
  1501. if (! is_array($array) && $array < 0) dol_print_error('', $objectpage->error, $objectpage->errors);
  1502. $atleastonepage=(is_array($array) && count($array) > 0);
  1503. if ($websitekey && $websitekey != '-1' && ($action == 'preview' || $action == 'createfromclone' || $action == 'createpagefromclone'))
  1504. {
  1505. $disabled='';
  1506. if (empty($user->rights->website->write)) $disabled=' disabled="disabled"';
  1507. print ' &nbsp; ';
  1508. print '<input type="submit" class="button nobordertransp"'.$disabled.' value="'.dol_escape_htmltag($langs->trans("EditCss")).'" name="editcss">';
  1509. //print '<input type="submit" class="button"'.$disabled.' value="'.dol_escape_htmltag($langs->trans("EditMenu")).'" name="editmenu">';
  1510. print '<input type="submit" class="button nobordertransp"'.$disabled.' value="'.dol_escape_htmltag($langs->trans("CloneSite")).'" name="createfromclone">';
  1511. print '<input type="submit" class="button nobordertransp"'.$disabled.' value="'.dol_escape_htmltag($langs->trans("ExportSite")).'" name="exportsite">';
  1512. if (! $atleastonepage)
  1513. {
  1514. print '<input type="submit" class="button nobordertransp"'.$disabled.' value="'.dol_escape_htmltag($langs->trans("ImportSite")).'" name="importsite">';
  1515. }
  1516. else
  1517. {
  1518. print '<input type="submit" class="button nobordertransp" disabled="disabled" value="'.dol_escape_htmltag($langs->trans("ImportSite")).'" name="importsite">';
  1519. }
  1520. print '<input type="submit" class="buttonDelete" name="deletesite" value="'.$langs->trans("Delete").'"'.($atleastonepage?' disabled="disabled"':'').'>';
  1521. print ' &nbsp; ';
  1522. print '<input type="submit" class="button nobordertransp"'.$disabled.' value="'.dol_escape_htmltag($langs->trans("MediaFiles")).'" name="file_manager">';
  1523. /*print '<a class="button button_file_manager"'.$disabled.'>'.dol_escape_htmltag($langs->trans("MediaFiles")).'</a>';
  1524. print '<script language="javascript">
  1525. jQuery(document).ready(function () {
  1526. jQuery(".button_file_manager").click(function () {
  1527. var $dialog = $(\'<div></div>\').html(\'<iframe style="border: 0px;" src="'.DOL_URL_ROOT.'/website/index.php?hide_websitemenu=1&dol_hide_topmenu=1&dol_hide_leftmenu=1&file_manager=1&website='.$websitekey.'&pageid='.$pageid.'" width="100%" height="100%"></iframe>\')
  1528. .dialog({
  1529. autoOpen: false,
  1530. modal: true,
  1531. height: 500,
  1532. width: \'80%\',
  1533. title: "'.dol_escape_js($langs->trans("FileManager")).'"
  1534. });
  1535. $dialog.dialog(\'open\');
  1536. });
  1537. });
  1538. </script>';
  1539. */
  1540. }
  1541. print '</div>';
  1542. // Toolbar for websites
  1543. print '<div class="websitetools websiteselection">';
  1544. if ($action == 'preview' || $action == 'createfromclone' || $action == 'createpagefromclone')
  1545. {
  1546. $urlext=$virtualurl;
  1547. $urlint=$urlwithroot.'/public/website/index.php?website='.$websitekey;
  1548. print '<div class="websiteinputurl valignmiddle" id="websiteinputurl">';
  1549. $linktotestonwebserver = '<a href="'.($virtualurl?$virtualurl:'#').'" class="valignmiddle">';
  1550. $linktotestonwebserver.= $langs->trans("TestDeployOnWeb", $virtualurl).' '.img_picto('','object_globe');
  1551. $linktotestonwebserver.= '</a>';
  1552. $htmltext = '';
  1553. if (empty($object->fk_default_home))
  1554. {
  1555. $htmltext.= '<br><span class="error">'.$langs->trans("YouMustDefineTheHomePage").'</span><br><br>';
  1556. }
  1557. elseif (empty($virtualurl))
  1558. {
  1559. $htmltext.= '<br><span class="error">'.$langs->trans("VirtualHostUrlNotDefined").'</span><br><br>';
  1560. }
  1561. else
  1562. {
  1563. $htmltext.= '<br><center>'.$langs->trans("GoTo").' <a href="'.$virtualurl.'" target="_website">'.$virtualurl.'</a></center><br>';
  1564. }
  1565. if (! empty($conf->global->WEBSITE_REPLACE_INFO_ABOUT_USAGE_WITH_WEBSERVER))
  1566. {
  1567. $htmltext.= '<br>'.$conf->global->WEBSITE_REPLACE_INFO_ABOUT_USAGE_WITH_WEBSERVER;
  1568. }
  1569. else
  1570. {
  1571. $htmltext.=$langs->trans("SetHereVirtualHost", $dataroot);
  1572. $htmltext.='<br>';
  1573. $htmltext.='<br>'.$langs->trans("CheckVirtualHostPerms", $langs->transnoentitiesnoconv("ReadPerm"), DOL_DOCUMENT_ROOT);
  1574. $htmltext.='<br>'.$langs->trans("CheckVirtualHostPerms", $langs->transnoentitiesnoconv("WritePerm"), DOL_DATA_ROOT.'/website<br>'.DOL_DATA_ROOT.'/medias');
  1575. $htmltext.='<br>';
  1576. $htmltext.='<br>';
  1577. $htmltext.=$langs->trans("YouCanAlsoTestWithPHPS", $dataroot);
  1578. }
  1579. print $form->textwithpicto($linktotestonwebserver, $htmltext, 1, 'none', 'valignmiddle', 0, 2, 'helpvirtualhost');
  1580. print '</div>';
  1581. }
  1582. if (in_array($action, array('editcss','editmenu','file_manager')))
  1583. {
  1584. if (preg_match('/^create/',$action) && $action != 'file_manager') print '<input type="submit" id="savefile" class="button buttonforacesave" value="'.dol_escape_htmltag($langs->trans("Save")).'" name="update">';
  1585. if (preg_match('/^edit/',$action) && $action != 'file_manager') print '<input type="submit" id="savefile" class="button buttonforacesave" value="'.dol_escape_htmltag($langs->trans("Save")).'" name="update">';
  1586. if ($action != 'preview') print '<input type="submit" class="button" value="'.dol_escape_htmltag($langs->trans("Cancel")).'" name="preview">';
  1587. }
  1588. print '</div>';
  1589. // Toolbar for pages
  1590. if ($websitekey && $websitekey != '-1' && ! in_array($action, array('editcss','editmenu','importsite')))
  1591. {
  1592. print '</div>'; // Close current websitebar to open a new one
  1593. print '<!-- Bar for websitepage -->';
  1594. print '<div class="centpercent websitebar"'.($style?' style="'.$style.'"':'').'">';
  1595. print '<div class="websiteselection hideonsmartphoneimp minwidth100 tdoverflowmax100">';
  1596. print $langs->trans("PageContainer").': ';
  1597. print '</div>';
  1598. print '<div class="websiteselection hideonsmartphoneimp">';
  1599. print '<input type="submit"'.$disabled.' class="button" value="'.dol_escape_htmltag($langs->trans("Add")).'" name="createcontainer">';
  1600. print '</div>';
  1601. print '<div class="websiteselection">';
  1602. if ($action != 'addcontainer')
  1603. {
  1604. $out='';
  1605. if ($atleastonepage && $action != 'editsource')
  1606. {
  1607. $out.='<select name="pageid" id="pageid" class="minwidth200 maxwidth300">';
  1608. }
  1609. else
  1610. {
  1611. $out.='<select name="pageidbis" id="pageid" class="minwidth200 maxwidth300" disabled="disabled">';
  1612. }
  1613. if ($atleastonepage)
  1614. {
  1615. if (empty($pageid) && $action != 'createcontainer') // Page id is not defined, we try to take one
  1616. {
  1617. $firstpageid=0;$homepageid=0;
  1618. foreach($array as $key => $valpage)
  1619. {
  1620. if (empty($firstpageid)) $firstpageid=$valpage->id;
  1621. if ($object->fk_default_home && $key == $object->fk_default_home) $homepageid=$valpage->id;
  1622. }
  1623. $pageid=$homepageid?$homepageid:$firstpageid; // We choose home page and if not defined yet, we take first page
  1624. }
  1625. foreach($array as $key => $valpage)
  1626. {
  1627. $out.='<option value="'.$key.'"';
  1628. if ($pageid > 0 && $pageid == $key) $out.=' selected'; // To preselect a value
  1629. $out.='>';
  1630. $out.='['.$valpage->type_container.' '.sprintf("%03d", $valpage->id).'] ';
  1631. $out.=$valpage->pageurl.' - '.$valpage->title;
  1632. if ($object->fk_default_home && $key == $object->fk_default_home) $out.=' ('.$langs->trans("HomePage").')';
  1633. $out.='</option>';
  1634. }
  1635. }
  1636. else $out.='<option value="-1">&nbsp;</option>';
  1637. $out.='</select>';
  1638. if ($atleastonepage && $action != 'editsource')
  1639. {
  1640. $out.=ajax_combobox('pageid');
  1641. }
  1642. else
  1643. {
  1644. $out.='<input type="hidden" name="pageid" value="'.$pageid.'">';
  1645. $out.=ajax_combobox('pageid');
  1646. }
  1647. print $out;
  1648. }
  1649. else
  1650. {
  1651. print $langs->trans("New");
  1652. }
  1653. //print '<input type="submit" class="button" name="refreshpage" value="'.$langs->trans("Load").'"'.($atleastonepage?'':' disabled="disabled"').'>';
  1654. print '<input type="image" class="valignmiddle" src="'.img_picto('', 'refresh', '', 0, 1).'" name="refreshpage" value="'.$langs->trans("Load").'"'.(($atleastonepage && $action != 'editsource')?'':' disabled="disabled"').'>';
  1655. // Print nav arrows
  1656. $pagepreviousid=0;
  1657. $pagenextid=0;
  1658. if ($pageid)
  1659. {
  1660. $sql = 'SELECT MAX(rowid) as pagepreviousid FROM '.MAIN_DB_PREFIX.'website_page WHERE rowid < '.$pageid.' AND fk_website = '.$object->id;
  1661. $resql = $db->query($sql);
  1662. if ($resql)
  1663. {
  1664. $obj = $db->fetch_object($resql);
  1665. if ($obj)
  1666. {
  1667. $pagepreviousid = $obj->pagepreviousid;
  1668. }
  1669. }
  1670. else dol_print_error($db);
  1671. $sql = 'SELECT MIN(rowid) as pagenextid FROM '.MAIN_DB_PREFIX.'website_page WHERE rowid > '.$pageid.' AND fk_website = '.$object->id;
  1672. $resql = $db->query($sql);
  1673. if ($resql)
  1674. {
  1675. $obj = $db->fetch_object($resql);
  1676. if ($obj)
  1677. {
  1678. $pagenextid = $obj->pagenextid;
  1679. }
  1680. }
  1681. else dol_print_error($db);
  1682. }
  1683. if ($pagepreviousid) print '<a class="valignmiddle" href="'.$_SERVER['PHP_SELF'].'?website='.urlencode($object->ref).'&pageid='.$pagepreviousid.'&action='.$action.'">'.img_previous($langs->trans("PreviousContainer")).'</a>';
  1684. else print '<span class="valignmiddle opacitymedium">'.img_previous($langs->trans("PreviousContainer")).'</span>';
  1685. if ($pagenextid) print '<a class="valignmiddle" href="'.$_SERVER['PHP_SELF'].'?website='.urlencode($object->ref).'&pageid='.$pagenextid.'&action='.$action.'">'.img_next($langs->trans("NextContainer")).'</a>';
  1686. else print '<span class="valignmiddle opacitymedium">'.img_next($langs->trans("NextContainer")).'</span>';
  1687. $websitepage = new WebSitePage($db);
  1688. if ($pageid > 0 && ($action == 'preview' || $action == 'createfromclone' || $action == 'createpagefromclone'))
  1689. {
  1690. $websitepage->fetch($pageid);
  1691. }
  1692. if ($action == 'preview' || $action == 'createfromclone' || $action == 'createpagefromclone')
  1693. {
  1694. $disabled='';
  1695. if (empty($user->rights->website->write)) $disabled=' disabled="disabled"';
  1696. // Confirmation to clone
  1697. if ($action == 'createfromclone') {
  1698. // Create an array for form
  1699. $formquestion = array(
  1700. array('type' => 'text', 'name' => 'siteref', 'label'=> $langs->trans("WebSite") ,'value'=> 'copy_of_'.$object->ref),
  1701. //array('type' => 'checkbox', 'name' => 'is_a_translation', 'label' => $langs->trans("SiteIsANewTranslation"), 'value' => 0),
  1702. //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')),
  1703. //array('type' => 'other','name' => 'newwebsite','label' => $langs->trans("WebSite"), 'value' => $formwebsite->selectWebsite($object->id, 'newwebsite', 0))
  1704. );
  1705. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id='.$object->id, $langs->trans('CloneSite'), '', 'confirm_createfromclone', $formquestion, 0, 1, 200);
  1706. print $formconfirm;
  1707. }
  1708. if ($pageid > 0 && $atleastonepage) // pageid can be set without pages, if homepage of site is set and all page were removed
  1709. {
  1710. // Confirmation to clone
  1711. if ($action == 'createpagefromclone') {
  1712. // Create an array for form
  1713. $preselectedlanguage = GETPOST('newlang', 'az09') ? GETPOST('newlang', 'az09') : ($objectpage->lang ? $objectpage->lang : $langs->defaultlang);
  1714. $formquestion = array(
  1715. array('type' => 'hidden', 'name' => 'sourcepageurl', 'value'=> $objectpage->pageurl),
  1716. array('type' => 'checkbox', 'tdclass'=>'maxwidth200', 'name' => 'is_a_translation', 'label' => $langs->trans("PageIsANewTranslation"), 'value' => 0),
  1717. array('type' => 'other','name' => 'newlang', 'label' => $langs->trans("Language"), 'value' => $formadmin->select_language($preselectedlanguage, 'newlang', 0, null, 1, 0, 0, 'minwidth200', 0, 1)),
  1718. array('type' => 'other','name' => 'newwebsite', 'label' => $langs->trans("WebSite"), 'value' => $formwebsite->selectWebsite($object->id, 'newwebsite', 0)),
  1719. array('type' => 'text', 'tdclass'=>'maxwidth200 fieldrequired', 'name' => 'pageurl', 'label'=> $langs->trans("WEBSITE_PAGENAME"), 'value'=> 'copy_of_'.$objectpage->pageurl),
  1720. );
  1721. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?website='.$object->ref.'&pageid=' . $pageid, $langs->trans('ClonePage'), '', 'confirm_createpagefromclone', $formquestion, 0, 1, 300, 550);
  1722. print $formconfirm;
  1723. }
  1724. print ' &nbsp; ';
  1725. print '<input type="submit" class="button nobordertransp"'.$disabled.' value="'.dol_escape_htmltag($langs->trans("EditPageMeta")).'" name="editmeta">';
  1726. print '<input type="submit" class="button nobordertransp"'.$disabled.' value="'.dol_escape_htmltag($langs->trans("EditHTMLSource")).'" name="editsource">';
  1727. print '<!-- button EditInLine and ShowSubcontainers -->'."\n";
  1728. print '<div class="websiteselectionsection inline-block">';
  1729. print '<div class="inline-block">';
  1730. print $langs->trans("EditInLine");
  1731. if ($websitepage->grabbed_from)
  1732. {
  1733. //print '<input type="submit" class="button nobordertransp" disabled="disabled" title="'.dol_escape_htmltag($langs->trans("OnlyEditionOfSourceForGrabbedContent")).'" value="'.dol_escape_htmltag($langs->trans("EditWithEditor")).'" name="editcontent">';
  1734. print '<a class="button nobordertransp opacitymedium nohoverborder"'.$disabled.' href="#" disabled="disabled" title="'.dol_escape_htmltag($langs->trans("OnlyEditionOfSourceForGrabbedContent")).'">'.img_picto($langs->trans("OnlyEditionOfSourceForGrabbedContent"),'switch_off','',false,0,0,'','nomarginleft').'</a>';
  1735. }
  1736. else
  1737. {
  1738. //print '<input type="submit" class="button nobordertransp"'.$disabled.' value="'.dol_escape_htmltag($langs->trans("EditWithEditor")).'" name="editcontent">';
  1739. if (empty($conf->global->WEBSITE_EDITINLINE))
  1740. {
  1741. print '<a class="button nobordertransp nohoverborder"'.$disabled.' href="'.$_SERVER["PHP_SELF"].'?website='.$object->ref.'&pageid='.$websitepage->id.'&action=seteditinline">'.img_picto($langs->trans("EditInLineOff"),'switch_off','',false,0,0,'','nomarginleft').'</a>';
  1742. }
  1743. else
  1744. {
  1745. print '<a class="button nobordertransp nohoverborder"'.$disabled.' href="'.$_SERVER["PHP_SELF"].'?website='.$object->ref.'&pageid='.$websitepage->id.'&action=unseteditinline">'.img_picto($langs->trans("EditInLineOn"),'switch_on','',false,0,0,'','nomarginleft').'</a>';
  1746. }
  1747. }
  1748. print '</div>';
  1749. print '<div class="inline-block">';
  1750. print $langs->trans("ShowSubcontainers");
  1751. /*if ($websitepage->grabbed_from)
  1752. {
  1753. print '<a class="button nobordertransp opacitymedium nohoverborder"'.$disabled.' href="#" disabled="disabled" title="'.dol_escape_htmltag($langs->trans("OnlyEditionOfSourceForGrabbedContent")).'">'.img_picto($langs->trans("OnlyEditionOfSourceForGrabbedContent"),'switch_off','',false,0,0,'','nomarginleft').'</a>';
  1754. }
  1755. else
  1756. {*/
  1757. if (empty($conf->global->WEBSITE_SUBCONTAINERSINLINE))
  1758. {
  1759. print '<a class="button nobordertransp nohoverborder"'.$disabled.' href="'.$_SERVER["PHP_SELF"].'?website='.$object->ref.'&pageid='.$websitepage->id.'&action=setshowsubcontainers">'.img_picto($langs->trans("ShowSubContainersOff"),'switch_off','',false,0,0,'','nomarginleft').'</a>';
  1760. }
  1761. else
  1762. {
  1763. print '<a class="button nobordertransp nohoverborder"'.$disabled.' href="'.$_SERVER["PHP_SELF"].'?website='.$object->ref.'&pageid='.$websitepage->id.'&action=unsetshowsubcontainers">'.img_picto($langs->trans("ShowSubContainersOn"),'switch_on','',false,0,0,'','nomarginleft').'</a>';
  1764. }
  1765. /*}*/
  1766. print '</div>';
  1767. print '</div>';
  1768. if ($object->fk_default_home > 0 && $pageid == $object->fk_default_home) print '<input type="submit" class="button nobordertransp" disabled="disabled" value="'.dol_escape_htmltag($langs->trans("SetAsHomePage")).'" name="setashome">';
  1769. else print '<input type="submit" class="button nobordertransp"'.$disabled.' value="'.dol_escape_htmltag($langs->trans("SetAsHomePage")).'" name="setashome">';
  1770. print '<input type="submit" class="button nobordertransp"'.$disabled.' value="'.dol_escape_htmltag($langs->trans("ClonePage")).'" name="createpagefromclone">';
  1771. print '<input type="submit" class="buttonDelete" name="delete" value="'.$langs->trans("Delete").'"'.($atleastonepage?'':' disabled="disabled"').'>';
  1772. }
  1773. }
  1774. print '</div>'; // end website selection
  1775. print '<div class="websitetools">';
  1776. if (($pageid > 0 && $atleastonepage) && ($action == 'preview' || $action == 'createfromclone' || $action == 'createpagefromclone'))
  1777. {
  1778. $realpage=$urlwithroot.'/public/website/index.php?website='.$websitekey.'&pageref='.$websitepage->pageurl;
  1779. $pagealias = $websitepage->pageurl;
  1780. $htmltext = $langs->trans("PreviewSiteServedByDolibarr", $langs->transnoentitiesnoconv("Page"), $langs->transnoentitiesnoconv("Page"), $realpage, $dataroot);
  1781. $htmltext.='<br>'.$langs->trans("CheckVirtualHostPerms", $langs->transnoentitiesnoconv("ReadPerm"), DOL_DOCUMENT_ROOT);
  1782. $htmltext.='<br>'.$langs->trans("CheckVirtualHostPerms", $langs->transnoentitiesnoconv("WritePerm"), DOL_DATA_ROOT.'/website<br>'.DOL_DATA_ROOT.'/medias');
  1783. print '<a class="websitebuttonsitepreview" id="previewpage" href="'.$realpage.'&nocache='.dol_now().'" class="button" target="tab'.$websitekey.'" alt="'.dol_escape_htmltag($htmltext).'">';
  1784. print $form->textwithpicto('', $htmltext, 1, 'preview');
  1785. print '</a>'; // View page in new Tab
  1786. print '<div class="websiteinputurl" id="websiteinputpage">';
  1787. print '<input type="text" id="previewpageurl" class="minwidth200imp" name="previewsite" value="'.$pagealias.'" disabled="disabled">';
  1788. $htmltext=$langs->trans("PageNameAliasHelp", $langs->transnoentitiesnoconv("EditPageMeta"));
  1789. print $form->textwithpicto('', $htmltext, 1, 'help', '', 0, 2, 'helppagealias');
  1790. print '</div>';
  1791. $urlext=$virtualurl.'/'.$pagealias.'.php';
  1792. $urlint=$urlwithroot.'/public/website/index.php?website='.$websitekey;
  1793. $htmltext = $langs->trans("PreviewSiteServedByWebServer", $langs->transnoentitiesnoconv("Page"), $langs->transnoentitiesnoconv("Page"), $dataroot, $virtualurl?$urlext:'<span class="error">'.$langs->trans("VirtualHostUrlNotDefined").'</span>');
  1794. print '<a class="websitebuttonsitepreview'.($virtualurl?'':' websitebuttonsitepreviewdisabled cursornotallowed').'" id="previewpageext" href="'.$urlext.'" target="tab'.$websitekey.'ext" alt="'.dol_escape_htmltag($htmltext).'">';
  1795. print $form->textwithpicto('', $htmltext, 1, 'preview_ext');
  1796. print '</a>';
  1797. //print '<input type="submit" class="button" name="previewpage" target="tab'.$websitekey.'"value="'.$langs->trans("ViewPageInNewTab").'">';
  1798. // TODO Add js to save alias like we save virtual host name and use dynamic virtual host for url of id=previewpageext
  1799. }
  1800. if (! in_array($action, array('editcss','editmenu','file_manager','createsite','createcontainer','createpagefromclone')))
  1801. {
  1802. if (preg_match('/^create/',$action)) print '<input type="submit" id="savefile" class="button buttonforacesave" value="'.dol_escape_htmltag($langs->trans("Save")).'" name="update">';
  1803. if (preg_match('/^edit/',$action)) print '<input type="submit" id="savefile" class="button buttonforacesave" value="'.dol_escape_htmltag($langs->trans("Save")).'" name="update">';
  1804. if ($action != 'preview') print '<input type="submit" class="button" value="'.dol_escape_htmltag($langs->trans("Cancel")).'" name="preview">';
  1805. }
  1806. print '</div>'; // end websitetools
  1807. print '<div class="websitehelp">';
  1808. if (GETPOST('editsource', 'alpha') || GETPOST('editcontent', 'alpha'))
  1809. {
  1810. $htmltext=$langs->transnoentitiesnoconv("YouCanEditHtmlSource").'<br>';
  1811. print $form->textwithpicto($langs->trans("SyntaxHelp"), $htmltext, 1, 'help', 'inline-block', 1, 2, 'tooltipsubstitution');
  1812. }
  1813. print '</div>'; // end websitehelp
  1814. if ($action == 'preview' || $action == 'createfromclone' || $action == 'createpagefromclone')
  1815. {
  1816. // Adding jquery code to change on the fly url of preview ext
  1817. if (! empty($conf->use_javascript_ajax))
  1818. {
  1819. print '<script type="text/javascript" language="javascript">
  1820. jQuery(document).ready(function() {
  1821. jQuery("#websiteinputurl").keyup(function() {
  1822. console.log("Website external url modified "+jQuery("#previewsiteurl").val());
  1823. if (jQuery("#previewsiteurl").val() != "" && jQuery("#previewsiteurl").val().startsWith("http"))
  1824. {
  1825. jQuery("a.websitebuttonsitepreviewdisabled img").css({ opacity: 1 });
  1826. }
  1827. else jQuery("a.websitebuttonsitepreviewdisabled img").css({ opacity: 0.2 });
  1828. ';
  1829. print '
  1830. });
  1831. jQuery("#previewsiteext,#previewpageext").click(function() {
  1832. newurl=jQuery("#previewsiteurl").val();
  1833. if (! newurl.startsWith("http"))
  1834. {
  1835. alert(\''.dol_escape_js($langs->trans("ErrorURLMustStartWithHttp")).'\');
  1836. return false;
  1837. }
  1838. newpage=jQuery("#previewsiteurl").val() + "/" + jQuery("#previewpageurl").val() + ".php";
  1839. console.log("Open url "+newurl);
  1840. /* Save url */
  1841. jQuery.ajax({
  1842. method: "POST",
  1843. url: "'.DOL_URL_ROOT.'/core/ajax/saveinplace.php",
  1844. data: {
  1845. field: \'editval_virtualhost\',
  1846. element: \'website\',
  1847. table_element: \'website\',
  1848. fk_element: '.$object->id.',
  1849. value: newurl,
  1850. },
  1851. context: document.body
  1852. });
  1853. jQuery("#previewsiteext").attr("href",newurl);
  1854. jQuery("#previewpageext").attr("href",newpage);
  1855. });
  1856. });
  1857. </script>';
  1858. }
  1859. }
  1860. }
  1861. print '</div>'; // end current websitebar
  1862. }
  1863. $head = array();
  1864. /*
  1865. * Edit Site HTML header and CSS
  1866. */
  1867. if ($action == 'editcss')
  1868. {
  1869. print '<div class="fiche">';
  1870. print '<br>';
  1871. if (GETPOST('editcss','alpha') || GETPOST('refreshpage','alpha'))
  1872. {
  1873. $csscontent = @file_get_contents($filecss);
  1874. // Clean the php css file to remove php code and get only css part
  1875. $csscontent = preg_replace('/<\?php \/\/ BEGIN PHP[^\?]*END PHP \?>\n*/ims', '', $csscontent);
  1876. }
  1877. else
  1878. {
  1879. $csscontent = GETPOST('WEBSITE_CSS_INLINE');
  1880. }
  1881. if (! trim($csscontent)) $csscontent='/* CSS content (all pages) */'."\n"."body.bodywebsite { margin: 0; font-family: 'Open Sans', sans-serif; }\n.bodywebsite h1 { margin-top: 0; margin-bottom: 0; padding: 10px;}";
  1882. if (GETPOST('editcss','alpha') || GETPOST('refreshpage','alpha'))
  1883. {
  1884. $jscontent = @file_get_contents($filejs);
  1885. // Clean the php js file to remove php code and get only js part
  1886. $jscontent = preg_replace('/<\?php \/\/ BEGIN PHP[^\?]*END PHP \?>\n*/ims', '', $jscontent);
  1887. }
  1888. else
  1889. {
  1890. $jscontent = GETPOST('WEBSITE_JS_INLINE');
  1891. }
  1892. if (! trim($jscontent)) $jscontent='/* JS content (all pages) */'."\n";
  1893. if (GETPOST('editcss','alpha') || GETPOST('refreshpage','alpha'))
  1894. {
  1895. $htmlheadercontent = @file_get_contents($filehtmlheader);
  1896. // Clean the php htmlheader file to remove php code and get only html part
  1897. $htmlheadercontent = preg_replace('/<\?php \/\/ BEGIN PHP[^\?]*END PHP \?>\n*/ims', '', $htmlheadercontent);
  1898. }
  1899. else
  1900. {
  1901. $htmlheadercontent = GETPOST('WEBSITE_HTML_HEADER');
  1902. }
  1903. if (! trim($htmlheadercontent))
  1904. {
  1905. $htmlheadercontent ="<html>\n";
  1906. $htmlheadercontent.=$htmlheadercontentdefault;
  1907. $htmlheadercontent.="</html>";
  1908. }
  1909. else
  1910. {
  1911. $htmlheadercontent = preg_replace('/^\s*<html>/ims', '', $htmlheadercontent);
  1912. $htmlheadercontent = preg_replace('/<\/html>\s*$/ims', '', $htmlheadercontent);
  1913. $htmlheadercontent='<html>'."\n".trim($htmlheadercontent)."\n".'</html>';
  1914. }
  1915. if (GETPOST('editcss','alpha') || GETPOST('refreshpage','alpha'))
  1916. {
  1917. $robotcontent = @file_get_contents($filerobot);
  1918. // Clean the php htmlheader file to remove php code and get only html part
  1919. $robotcontent = preg_replace('/<\?php \/\/ BEGIN PHP[^\?]*END PHP \?>\n*/ims', '', $robotcontent);
  1920. }
  1921. else
  1922. {
  1923. $robotcontent = GETPOST('WEBSITE_ROBOT');
  1924. }
  1925. if (! trim($robotcontent))
  1926. {
  1927. $robotcontent.="# Robot file. Generated with ".DOL_APPLICATION_TITLE."\n";
  1928. $robotcontent.="User-agent: *\n";
  1929. $robotcontent.="Allow: /public/\n";
  1930. $robotcontent.="Disallow: /administrator/\n";
  1931. }
  1932. if (GETPOST('editcss','alpha') || GETPOST('refreshpage','alpha'))
  1933. {
  1934. $htaccesscontent = @file_get_contents($filehtaccess);
  1935. // Clean the php htaccesscontent file to remove php code and get only html part
  1936. $htaccesscontent = preg_replace('/<\?php \/\/ BEGIN PHP[^\?]*END PHP \?>\n*/ims', '', $htaccesscontent);
  1937. }
  1938. else
  1939. {
  1940. $htaccesscontent = GETPOST('WEBSITE_HTACCESS');
  1941. }
  1942. if (! trim($htaccesscontent))
  1943. {
  1944. $htaccesscontent.="# Order allow,deny\n";
  1945. $htaccesscontent.="# Deny from all\n";
  1946. }
  1947. //else $htaccesscontent='<html>'."\n".$htaccesscontent."\n".'</html>';*/
  1948. dol_fiche_head();
  1949. print '<!-- Edit CSS -->'."\n";
  1950. print '<table class="border" width="100%">';
  1951. // Website
  1952. print '<tr><td class="titlefieldcreate">';
  1953. print $langs->trans('WebSite');
  1954. print '</td><td>';
  1955. print $websitekey;
  1956. print '</td></tr>';
  1957. // CSS file
  1958. print '<tr><td class="tdtop">';
  1959. print $langs->trans('WEBSITE_CSS_INLINE');
  1960. print '</td><td>';
  1961. $doleditor=new DolEditor('WEBSITE_CSS_INLINE', $csscontent, '', '220', 'ace', 'In', true, false, 'ace', 0, '100%', '');
  1962. print $doleditor->Create(1, '', true, 'CSS', 'css');
  1963. print '</td></tr>';
  1964. // JS file
  1965. print '<tr><td class="tdtop">';
  1966. print $langs->trans('WEBSITE_JS_INLINE');
  1967. print '</td><td>';
  1968. $doleditor=new DolEditor('WEBSITE_JS_INLINE', $jscontent, '', '220', 'ace', 'In', true, false, 'ace', 0, '100%', '');
  1969. print $doleditor->Create(1, '', true, 'JS', 'javascript');
  1970. print '</td></tr>';
  1971. // Common HTML header
  1972. print '<tr><td class="tdtop">';
  1973. $htmlhelp=$langs->trans("Example").' :<br>';
  1974. $htmlhelp.=dol_htmlentitiesbr($htmlheadercontentdefault);
  1975. print $form->textwithpicto($langs->trans('WEBSITE_HTML_HEADER'), $htmlhelp, 1, 'help', '', 0, 2, 'htmlheadertooltip');
  1976. print '</td><td>';
  1977. $doleditor=new DolEditor('WEBSITE_HTML_HEADER', $htmlheadercontent, '', '220', 'ace', 'In', true, false, 'ace', 0, '100%', '');
  1978. print $doleditor->Create(1, '', true, 'HTML Header', 'html');
  1979. print '</td></tr>';
  1980. // Robot file
  1981. print '<tr><td class="tdtop">';
  1982. print $langs->trans('WEBSITE_ROBOT');
  1983. print '</td><td>';
  1984. $doleditor=new DolEditor('WEBSITE_ROBOT', $robotcontent, '', '220', 'ace', 'In', true, false, 'ace', 0, '100%', '');
  1985. print $doleditor->Create(1, '', true, 'Robot file', 'text');
  1986. print '</td></tr>';
  1987. // .htaccess
  1988. print '<tr><td class="tdtop">';
  1989. print $langs->trans('WEBSITE_HTACCESS');
  1990. print '</td><td>';
  1991. $doleditor=new DolEditor('WEBSITE_HTACCESS', $htaccesscontent, '', '220', 'ace', 'In', true, false, 'ace', 0, '100%', '');
  1992. print $doleditor->Create(1, '', true, $langs->trans("File").' .htaccess', 'text');
  1993. print '</td></tr>';
  1994. // VirtualHost
  1995. print '<tr><td class="tdtop">';
  1996. $htmltext = $langs->trans("SetHereVirtualHost", DOL_DATA_ROOT.'/website/<i>'.$websitekey.'</i>');
  1997. $htmltext.='<br>';
  1998. $htmltext.='<br>'.$langs->trans("CheckVirtualHostPerms", $langs->transnoentitiesnoconv("ReadPerm"), DOL_DOCUMENT_ROOT);
  1999. $htmltext.='<br>'.$langs->trans("CheckVirtualHostPerms", $langs->transnoentitiesnoconv("WritePerm"), DOL_DATA_ROOT.'/website<br>'.DOL_DATA_ROOT.'/medias');
  2000. print $form->textwithpicto($langs->trans('Virtualhost'), $htmltext, 1, 'help', '', 0, 2, 'virtualhosttooltip');
  2001. print '</td><td>';
  2002. print '<input type="text" class="flat" value="'.(GETPOSTISSET('virtualhost') ? GETPOST('virtualhost','alpha') : $virtualurl).'" name="virtualhost">';
  2003. print '</td>';
  2004. print '</table>';
  2005. dol_fiche_end();
  2006. print '</div>';
  2007. print '<br>';
  2008. }
  2009. if ($action == 'createsite')
  2010. {
  2011. print '<div class="fiche">';
  2012. print '<br>';
  2013. /*$h = 0;
  2014. $head = array();
  2015. $head[$h][0] = dol_buildpath('/website/index.php',1).'?id='.$object->id;
  2016. $head[$h][1] = $langs->trans("AddSite");
  2017. $head[$h][2] = 'card';
  2018. $h++;
  2019. dol_fiche_head($head, 'card', $langs->trans("AddSite"), -1, 'globe');
  2020. */
  2021. if ($action == 'createcontainer') print load_fiche_titre($langs->trans("AddSite"));
  2022. print '<!-- Add site -->'."\n";
  2023. //print '<div class="fichecenter">';
  2024. print '<table class="border" width="100%">';
  2025. if (GETPOST('WEBSITE_REF')) $siteref=GETPOST('WEBSITE_REF','alpha');
  2026. if (GETPOST('WEBSITE_DESCRIPTION')) $sitedesc=GETPOST('WEBSITE_DESCRIPTION','alpha');
  2027. print '<tr><td class="titlefieldcreate fieldrequired">';
  2028. print $langs->trans('Ref');
  2029. print '</td><td>';
  2030. print '<input type="text" class="flat maxwidth300" name="WEBSITE_REF" value="'.dol_escape_htmltag($siteref).'">';
  2031. print '</td></tr>';
  2032. print '<tr><td>';
  2033. print $langs->trans('Description');
  2034. print '</td><td>';
  2035. print '<input type="text" class="flat minwidth300" name="WEBSITE_DESCRIPTION" value="'.dol_escape_htmltag($sitedesc).'">';
  2036. print '</td></tr>';
  2037. print '<tr><td>';
  2038. $htmltext = $langs->trans("SetHereVirtualHost", DOL_DATA_ROOT.'/website/<i>websiteref</i>');
  2039. $htmltext.='<br>';
  2040. $htmltext.='<br>'.$langs->trans("CheckVirtualHostPerms", $langs->transnoentitiesnoconv("ReadPerm"), DOL_DOCUMENT_ROOT);
  2041. $htmltext.='<br>'.$langs->trans("CheckVirtualHostPerms", $langs->transnoentitiesnoconv("WritePerm"), DOL_DATA_ROOT.'/website<br>'.DOL_DATA_ROOT.'/medias');
  2042. print $form->textwithpicto($langs->trans('Virtualhost'), $htmltext, 1, 'help', '', 0, 2, 'virtualhosttooltip');
  2043. print '</td><td>';
  2044. print '<input type="text" class="flat minwidth300" name="virtualhost" value="'.dol_escape_htmltag(GETPOST('virtualhost','alpha')).'">';
  2045. print '</td></tr>';
  2046. print '</table>';
  2047. if ($action == 'createsite')
  2048. {
  2049. print '<div class="center">';
  2050. print '<input class="button" type="submit" name="addcontainer" value="'.$langs->trans("Create").'">';
  2051. print '<input class="button" type="submit" name="preview" value="'.$langs->trans("Cancel").'">';
  2052. print '</div>';
  2053. }
  2054. //print '</div>';
  2055. //dol_fiche_end();
  2056. print '</div>';
  2057. print '<br>';
  2058. }
  2059. if ($action == 'importsite')
  2060. {
  2061. print '<div class="fiche">';
  2062. print '<br>';
  2063. print load_fiche_titre($langs->trans("ImportSite"));
  2064. dol_fiche_head(array(), '0', '', -1);
  2065. print $langs->trans("ZipOfWebsitePackageToImport").'<br><br>';
  2066. print '<input class="flat minwidth400" type="file" name="userfile[]" accept=".zip">';
  2067. print '<input type="submit" class="button" name="buttonsubmitimportfile" value="'.dol_escape_htmltag($langs->trans("Upload")).'">';
  2068. print '<input type="submit" class="button" name="preview" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
  2069. dol_fiche_end();
  2070. print '</div>';
  2071. print '<br>';
  2072. }
  2073. if ($action == 'editmeta' || $action == 'createcontainer')
  2074. {
  2075. print '<div class="fiche">';
  2076. print '<br>';
  2077. /*$h = 0;
  2078. $head = array();
  2079. $head[$h][0] = dol_buildpath('/website/index.php',1).'?id='.$object->id;
  2080. $head[$h][1] = $langs->trans("AddPage");
  2081. $head[$h][2] = 'card';
  2082. $h++;
  2083. dol_fiche_head($head, 'card', $langs->trans("AddPage"), -1, 'globe');
  2084. */
  2085. if ($action == 'createcontainer') print load_fiche_titre($langs->trans("AddPage"));
  2086. print '<!-- Edit or create page/container -->'."\n";
  2087. //print '<div class="fichecenter">';
  2088. if ($action == 'createcontainer')
  2089. {
  2090. print '<br>';
  2091. print ' * '.$langs->trans("CreateByFetchingExternalPage").'<br><hr>';
  2092. print '<table class="border" width="100%">';
  2093. print '<tr><td class="titlefield">';
  2094. print $langs->trans("URL");
  2095. print '</td><td>';
  2096. print info_admin($langs->trans("OnlyEditionOfSourceForGrabbedContentFuture"), 0, 0, 'warning');
  2097. print '<input class="flat minwidth500" type="text" name="externalurl" value="'.dol_escape_htmltag(GETPOST('externalurl','alpha')).'" placeholder="https://externalsite/pagetofetch"> ';
  2098. print '<br><input class="flat paddingtop" type="checkbox" name="grabimages" value="1" checked="checked"> '.$langs->trans("GrabImagesInto");
  2099. print ' ';
  2100. print $langs->trans("ImagesShouldBeSavedInto").' ';
  2101. $arraygrabimagesinto=array('root'=>$langs->trans("WebsiteRootOfImages"), 'subpage'=>$langs->trans("SubdirOfPage"));
  2102. print $form->selectarray('grabimagesinto', $arraygrabimagesinto, GETPOSTISSET('grabimagesinto')?GETPOST('grabimagesinto'):'root');
  2103. print '<br>';
  2104. print '<input class="button" style="margin-top: 5px" type="submit" name="fetchexternalurl" value="'.dol_escape_htmltag($langs->trans("FetchAndCreate")).'">';
  2105. print '</td></tr>';
  2106. print '</table>';
  2107. print '<br>';
  2108. print ' * '.$langs->trans("OrEnterPageInfoManually").'<br><hr>';
  2109. }
  2110. print '<table class="border" width="100%">';
  2111. if ($action != 'createcontainer')
  2112. {
  2113. print '<tr><td class="titlefield">';
  2114. print $langs->trans('IDOfPage');
  2115. print '</td><td>';
  2116. print $pageid;
  2117. print '</td></tr>';
  2118. print '<tr><td class="titlefield">';
  2119. print $langs->trans('InternalURLOfPage');
  2120. print '</td><td>';
  2121. print '/public/website/index.php?website='.urlencode($websitekey).'&pageid='.urlencode($pageid);
  2122. print '</td></tr>';
  2123. /*
  2124. print '<tr><td class="titlefield">';
  2125. print $langs->trans('InitiallyGrabbedFrom');
  2126. print '</td><td>';
  2127. print $objectpage->grabbed_from;
  2128. print '</td></tr>';
  2129. */
  2130. $type_container=$objectpage->type_container;
  2131. $pageurl=$objectpage->pageurl;
  2132. $pagealiasalt=$objectpage->aliasalt;
  2133. $pagetitle=$objectpage->title;
  2134. $pagedescription=$objectpage->description;
  2135. $pageimage=$objectpage->image;
  2136. $pagekeywords=$objectpage->keywords;
  2137. $pagelang=$objectpage->lang;
  2138. $pagehtmlheader=$objectpage->htmlheader;
  2139. $pagedatecreation=$objectpage->date_creation;
  2140. $pagedatemodification=$objectpage->date_modification;
  2141. $pageauthorid=$objectpage->fk_user_creat;
  2142. $pageusermodifid=$objectpage->fk_user_modif;
  2143. }
  2144. else
  2145. {
  2146. $type_container = 'page';
  2147. $pagedatecreation=dol_now();
  2148. $pageauthorid=$user->id;
  2149. $pageusermodifid=0;
  2150. }
  2151. if (GETPOST('WEBSITE_TITLE','alpha')) $pagetitle=GETPOST('WEBSITE_TITLE','alpha');
  2152. if (GETPOST('WEBSITE_PAGENAME','alpha')) $pageurl=GETPOST('WEBSITE_PAGENAME','alpha');
  2153. if (GETPOST('WEBSITE_ALIASALT','alpha')) $pagealiasalt=GETPOST('WEBSITE_ALIASALT','alpha');
  2154. if (GETPOST('WEBSITE_DESCRIPTION','alpha')) $pagedescription=GETPOST('WEBSITE_DESCRIPTION','alpha');
  2155. if (GETPOST('WEBSITE_IMAGE','alpha')) $pageimage=GETPOST('WEBSITE_IMAGE','alpha');
  2156. if (GETPOST('WEBSITE_KEYWORDS','alpha')) $pagekeywords=GETPOST('WEBSITE_KEYWORDS','alpha');
  2157. if (GETPOST('WEBSITE_LANG','aZ09')) $pagelang=GETPOST('WEBSITE_LANG','aZ09');
  2158. if (GETPOST('htmlheader','none')) $pagehtmlheader=GETPOST('htmlheader','none');
  2159. // Title
  2160. print '<tr><td class="fieldrequired">';
  2161. print $langs->trans('WEBSITE_TITLE');
  2162. print '</td><td>';
  2163. print '<input type="text" class="flat quatrevingtpercent" name="WEBSITE_TITLE" id="WEBSITE_TITLE" value="'.dol_escape_htmltag($pagetitle).'">';
  2164. print '</td></tr>';
  2165. // Alias
  2166. print '<tr><td class="titlefieldcreate fieldrequired">';
  2167. print $langs->trans('WEBSITE_PAGENAME');
  2168. print '</td><td>';
  2169. print '<input type="text" class="flat minwidth300" name="WEBSITE_PAGENAME" id="WEBSITE_PAGENAME" value="'.dol_escape_htmltag($pageurl).'">';
  2170. print '</td></tr>';
  2171. // Type of container
  2172. print '<tr><td class="titlefield fieldrequired">';
  2173. print $langs->trans('WEBSITE_TYPE_CONTAINER');
  2174. print '</td><td>';
  2175. print $formwebsite->selectTypeOfContainer('WEBSITE_TYPE_CONTAINER', (GETPOST('WEBSITE_TYPE_CONTAINER','alpha')?GETPOST('WEBSITE_TYPE_CONTAINER','alpha'):$type_container));
  2176. print '</td></tr>';
  2177. if ($action == 'createcontainer')
  2178. {
  2179. print '<tr><td class="titlefield fieldrequired">';
  2180. print $langs->trans('WEBSITE_PAGE_EXAMPLE');
  2181. print '</td><td>';
  2182. print $formwebsite->selectSampleOfContainer('sample', (GETPOST('sample','alpha')?GETPOST('sample','alpha'):'corporatehomepage'));
  2183. print '</td></tr>';
  2184. }
  2185. print '<tr><td>';
  2186. print $langs->trans('WEBSITE_DESCRIPTION');
  2187. print '</td><td>';
  2188. print '<input type="text" class="flat quatrevingtpercent" name="WEBSITE_DESCRIPTION" value="'.dol_escape_htmltag($pagedescription).'">';
  2189. print '</td></tr>';
  2190. print '<tr><td>';
  2191. $htmlhelp=$langs->trans("WEBSITE_IMAGEDesc");
  2192. print $form->textwithpicto($langs->trans('WEBSITE_IMAGE'), $htmlhelp, 1, 'help', '', 0, 2, 'imagetooltip');
  2193. print '</td><td>';
  2194. print '<input type="text" class="flat quatrevingtpercent" name="WEBSITE_IMAGE" value="'.dol_escape_htmltag($pageimage).'">';
  2195. print '</td></tr>';
  2196. print '<tr><td>';
  2197. print $langs->trans('WEBSITE_KEYWORDS');
  2198. print '</td><td>';
  2199. print '<input type="text" class="flat quatrevingtpercent" name="WEBSITE_KEYWORDS" value="'.dol_escape_htmltag($pagekeywords).'">';
  2200. print '</td></tr>';
  2201. print '<tr><td>';
  2202. print $langs->trans('Language');
  2203. print '</td><td>';
  2204. print $formadmin->select_language($pagelang?$pagelang:$langs->defaultlang, 'WEBSITE_LANG', 0, null, '1');
  2205. print '</td></tr>';
  2206. if ($action != 'createcontainer')
  2207. {
  2208. // Translation of
  2209. if ($objectpage->fk_page > 0)
  2210. {
  2211. print '<tr><td>';
  2212. print $langs->trans('ThisPageIsTranslationOf');
  2213. print '</td><td>';
  2214. $sourcepage=new WebsitePage($db);
  2215. $result = $sourcepage->fetch($objectpage->fk_page);
  2216. if ($result == 0) // not found, we can reset value
  2217. {
  2218. }
  2219. elseif ($result > 0)
  2220. {
  2221. print $sourcepage->getNomUrl(1);
  2222. }
  2223. print '</td></tr>';
  2224. }
  2225. // Has translation pages
  2226. $sql='SELECT rowid, lang from '.MAIN_DB_PREFIX.'website_page where fk_page = '.$objectpage->id;
  2227. $resql = $db->query($sql);
  2228. if ($resql)
  2229. {
  2230. $num_rows = $db->num_rows($resql);
  2231. if ($num_rows > 0)
  2232. {
  2233. print '<tr><td>';
  2234. print $langs->trans('ThisPageHasTranslationPages');
  2235. print '</td><td>';
  2236. $i=0;
  2237. while ($obj = $db->fetch_object($resql))
  2238. {
  2239. $tmppage=new WebsitePage($db);
  2240. $tmppage->fetch($obj->rowid);
  2241. if ($i > 0) print ' - ';
  2242. print $tmppage->getNomUrl(1).' ('.$tmppage->lang.')';
  2243. $i++;
  2244. }
  2245. print '</td></tr>';
  2246. }
  2247. }
  2248. else dol_print_error($db);
  2249. }
  2250. print '<tr><td class="titlefieldcreate">';
  2251. $htmlhelp=$langs->trans("WEBSITE_ALIASALTDesc");
  2252. print $form->textwithpicto($langs->trans('WEBSITE_ALIASALT'), $htmlhelp, 1, 'help', '', 0, 2, 'aliastooltip');
  2253. print '</td><td>';
  2254. print '<input type="text" class="flat minwidth300" name="WEBSITE_ALIASALT" value="'.dol_escape_htmltag($pagealiasalt).'">';
  2255. print '</td></tr>';
  2256. $fuser=new User($db);
  2257. print '<tr><td>';
  2258. print $langs->trans('Author');
  2259. print '</td><td>';
  2260. if ($pageauthorid > 0)
  2261. {
  2262. $fuser->fetch($pageauthorid);
  2263. print $fuser->getNomUrl(1);
  2264. }
  2265. print '</td></tr>';
  2266. print '<tr><td>';
  2267. print $langs->trans('DateCreation');
  2268. print '</td><td>';
  2269. print $form->select_date($pagedatecreation, 'datecreation', 1, 1, 0, '', 1, 1);
  2270. //print dol_print_date($pagedatecreation, 'dayhour');
  2271. print '</td></tr>';
  2272. if ($action != 'createcontainer')
  2273. {
  2274. print '<tr><td>';
  2275. print $langs->trans('LastModificationAuthor');
  2276. print '</td><td>';
  2277. if ($pageusermodifid > 0)
  2278. {
  2279. $fuser->fetch($pageusermodifid);
  2280. print $fuser->getNomUrl(1);
  2281. }
  2282. print '</td></tr>';
  2283. print '<tr><td>';
  2284. print $langs->trans('DateModification');
  2285. print '</td><td>';
  2286. print dol_print_date($pagedatemodification, 'dayhour', 'tzuser');
  2287. print '</td></tr>';
  2288. }
  2289. print '<tr><td class="tdhtmlheader tdtop">';
  2290. $htmlhelp =$langs->trans("EditTheWebSiteForACommonHeader").'<br><br>';
  2291. $htmlhelp.=$langs->trans("Example").' :<br>';
  2292. $htmlhelp.=dol_htmlentitiesbr($htmlheadercontentdefault);
  2293. print $form->textwithpicto($langs->trans('HtmlHeaderPage'), $htmlhelp, 1, 'help', '', 0, 2, 'htmlheadertooltip');
  2294. print '</td><td>';
  2295. $doleditor=new DolEditor('htmlheader', $pagehtmlheader, '', '120', 'ace', 'In', true, false, 'ace', ROWS_3, '100%', '');
  2296. print $doleditor->Create(1, '', true, 'HTML Header', 'html');
  2297. print '</td></tr>';
  2298. print '</table>';
  2299. if ($action == 'createcontainer')
  2300. {
  2301. print '<div class="center">';
  2302. print '<input class="button" type="submit" name="addcontainer" value="'.$langs->trans("Create").'">';
  2303. print '<input class="button" type="submit" name="preview" value="'.$langs->trans("Cancel").'">';
  2304. print '</div>';
  2305. }
  2306. if ($action == 'createcontainer')
  2307. {
  2308. print '<script type="text/javascript" language="javascript">
  2309. jQuery(document).ready(function() {
  2310. var disableautofillofalias = 0;
  2311. jQuery("#WEBSITE_TITLE").keyup(function() {
  2312. if (disableautofillofalias == 0)
  2313. {
  2314. var valnospecial = jQuery("#WEBSITE_TITLE").val().replace(/[^\w]/gi, \'-\').toLowerCase();
  2315. valnospecial = valnospecial.replace(/\-+/g, \'-\').replace(/\-$/, \'\');
  2316. console.log("disableautofillofalias=0 so we replace WEBSITE_TITLE with "+valnospecial);
  2317. jQuery("#WEBSITE_PAGENAME").val(valnospecial);
  2318. }
  2319. });
  2320. jQuery("#WEBSITE_PAGENAME").keyup(function() {
  2321. disableautofillofalias = 1;
  2322. });
  2323. });
  2324. </script>';
  2325. }
  2326. //print '</div>';
  2327. //dol_fiche_end();
  2328. print '</div>';
  2329. print '<br>';
  2330. }
  2331. if ($action == 'editfile' || $action == 'file_manager')
  2332. {
  2333. print '<!-- Edit Media -->'."\n";
  2334. print '<div class="fiche"><br><br>';
  2335. //print '<div class="center">'.$langs->trans("FeatureNotYetAvailable").'</center>';
  2336. $module = 'medias';
  2337. if (empty($url)) $url=DOL_URL_ROOT.'/website/index.php'; // Must be an url without param
  2338. include DOL_DOCUMENT_ROOT.'/core/tpl/filemanager.tpl.php';
  2339. print '</div>';
  2340. }
  2341. if ($action == 'editmenu')
  2342. {
  2343. print '<!-- Edit Menu -->'."\n";
  2344. print '<div class="center">'.$langs->trans("FeatureNotYetAvailable").'</center>';
  2345. }
  2346. if ($action == 'editsource')
  2347. {
  2348. // Editing with source editor
  2349. $contentforedit = '';
  2350. //$contentforedit.='<style scoped>'."\n"; // "scoped" means "apply to parent element only". Not yet supported by browsers
  2351. //$contentforedit.=$csscontent;
  2352. //$contentforedit.='</style>'."\n";
  2353. $contentforedit .= $objectpage->content;
  2354. //var_dump($_SESSION["dol_screenheight"]);
  2355. $maxheightwin=480;
  2356. if (isset($_SESSION["dol_screenheight"]))
  2357. {
  2358. if ($_SESSION["dol_screenheight"] > 680) $maxheightwin = $_SESSION["dol_screenheight"]-400;
  2359. if ($_SESSION["dol_screenheight"] > 800) $maxheightwin = $_SESSION["dol_screenheight"]-490;
  2360. }
  2361. //var_dump($_SESSION["dol_screenheight"]);
  2362. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  2363. $doleditor=new DolEditor('PAGE_CONTENT',$contentforedit,'',$maxheightwin,'Full','',true,true,'ace',ROWS_5,'40%');
  2364. $doleditor->Create(0, '', false, 'HTML Source', 'php');
  2365. }
  2366. /*if ($action == 'editcontent')
  2367. {
  2368. // Editing with default ckeditor
  2369. $contentforedit = '';
  2370. //$contentforedit.='<style scoped>'."\n"; // "scoped" means "apply to parent element only". Not yet supported by browsers
  2371. //$contentforedit.=$csscontent;
  2372. //$contentforedit.='</style>'."\n";
  2373. $contentforedit .= $objectpage->content;
  2374. $contentforedit = preg_replace('/(<img.*src=")(?!http)/', '\1'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file=', $contentforedit, -1, $nbrep);
  2375. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  2376. $doleditor=new DolEditor('PAGE_CONTENT',$contentforedit,'',500,'Full','',true,true,true,ROWS_5,'90%');
  2377. $doleditor->Create(0, '', false);
  2378. }*/
  2379. print "</div>\n";
  2380. print "</form>\n";
  2381. if ($action == 'preview' || $action == 'createfromclone' || $action == 'createpagefromclone')
  2382. {
  2383. if ($pageid > 0 && $atleastonepage)
  2384. {
  2385. // $filejs
  2386. // $filecss
  2387. // $filephp
  2388. // Ouput page under the Dolibarr top menu
  2389. $objectpage->fetch($pageid);
  2390. $jscontent = @file_get_contents($filejs);
  2391. $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";
  2392. // Include a html so we can benefit of the header of page.
  2393. // Note: We can't use iframe as it can be used to include another external html file
  2394. // Note: We can't use frame as it is deprecated.
  2395. /*if ($includepageintoaframeoradiv == 'iframe')
  2396. {
  2397. $out .= "<iframe><body></html>";
  2398. }*/
  2399. $out.="\n<html><head>\n";
  2400. $out.="<!-- htmlheader/style of page from database -->\n";
  2401. $out.=dolWebsiteReplacementOfLinks($object, $objectpage->htmlheader, 1);
  2402. $out.="</head>\n";
  2403. $out.="\n<body>";
  2404. $out.='<div id="websitecontentundertopmenu" class="websitecontentundertopmenu boostrap-iso">'."\n";
  2405. // REPLACEMENT OF LINKS When page called by website editor
  2406. $out.='<!-- style of website from file -->'."\n";
  2407. $out.='<style scoped>'."\n"; // "scoped" means "apply to parent element only". No more supported by browsers, snif !
  2408. $tmpout='';
  2409. $tmpout.= '/* Include website CSS file */'."\n";
  2410. //$csscontent = @file_get_contents($filecss);
  2411. ob_start();
  2412. include $filecss;
  2413. $csscontent = ob_get_contents();
  2414. ob_end_clean();
  2415. $tmpout.= dolWebsiteReplacementOfLinks($object, $csscontent, 1);
  2416. $tmpout.= '/* Include style from the HTML header of page */'."\n";
  2417. // Clean the html header of page to get only <style> content
  2418. $tmp = preg_split('(<style[^>]*>|</style>)', $objectpage->htmlheader);
  2419. $tmpstyleinheader ='';
  2420. $i=0;
  2421. foreach($tmp as $valtmp)
  2422. {
  2423. $i++;
  2424. if ($i % 2 == 0) $tmpstyleinheader.=$valtmp."\n";
  2425. }
  2426. $tmpout.= $tmpstyleinheader."\n";
  2427. // Clean style that may affect global style of Dolibarr
  2428. $tmpout=preg_replace('/}[\s\n]*body\s*{[^}]+}/ims','}',$tmpout);
  2429. $out.=$tmpout;
  2430. $out.='</style>'."\n";
  2431. // Note: <div> or <section> with contenteditable="true" inside this can be edited with inline ckeditor
  2432. // Do not enable the contenteditable when page was grabbed, ckeditor is removing span and adding borders,
  2433. // so editable will be available only from container created from scratch
  2434. //$out.='<div id="bodywebsite" class="bodywebsite"'.($objectpage->grabbed_from ? ' contenteditable="true"' : '').'>'."\n";
  2435. $out.='<div id="divbodywebsite" class="bodywebsite">'."\n";
  2436. $newcontent = $objectpage->content;
  2437. // If mode WEBSITE_SUBCONTAINERSINLINE is on
  2438. if (! empty($conf->global->WEBSITE_SUBCONTAINERSINLINE))
  2439. {
  2440. define('USEDOLIBARREDITOR', 1);
  2441. //var_dump($filetpl);
  2442. $filephp = $filetpl;
  2443. ob_start();
  2444. include $filephp;
  2445. $newcontent = ob_get_contents();
  2446. ob_end_clean();
  2447. }
  2448. // Change the contenteditable to "true" or "false" when mode Edit Inline is on or off
  2449. if (empty($conf->global->WEBSITE_EDITINLINE))
  2450. {
  2451. $newcontent = preg_replace('/(div|section)(\s[^\>]*)contenteditable="true"/', '\1\2', $newcontent);
  2452. }
  2453. else
  2454. {
  2455. // TODO Add the contenteditable="true" when mode Edit Inline is on
  2456. }
  2457. $out.=dolWebsiteReplacementOfLinks($object, $newcontent)."\n";
  2458. //$out.=$newcontent;
  2459. $out.='</div>';
  2460. $out.='</div> <!-- End div id=websitecontentundertopmenu -->';
  2461. /*if ($includepageintoaframeoradiv == 'iframe')
  2462. {
  2463. $out .= "</body></html></iframe>";
  2464. }*/
  2465. $out .= "\n</body></html>\n";
  2466. $out.= "\n".'<!-- End page content '.$filetpl.' -->'."\n\n";
  2467. print $out;
  2468. /*file_put_contents($filetpl, $out);
  2469. if (! empty($conf->global->MAIN_UMASK))
  2470. @chmod($filetpl, octdec($conf->global->MAIN_UMASK));
  2471. // Output file on browser
  2472. dol_syslog("index.php include $filetpl $filename content-type=$type");
  2473. $original_file_osencoded=dol_osencode($filetpl); // New file name encoded in OS encoding charset
  2474. // This test if file exists should be useless. We keep it to find bug more easily
  2475. if (! file_exists($original_file_osencoded))
  2476. {
  2477. dol_print_error(0,$langs->trans("ErrorFileDoesNotExists",$original_file));
  2478. exit;
  2479. }
  2480. //include_once $original_file_osencoded;
  2481. */
  2482. /*print '<iframe class="websiteiframenoborder centpercent" src="'.DOL_URL_ROOT.'/public/website/index.php?website='.$websitekey.'&pageid='.$pageid.'"/>';
  2483. print '</iframe>';*/
  2484. }
  2485. else
  2486. {
  2487. if (empty($websitekey) || $websitekey == '-1')
  2488. {
  2489. print '<br><br><div class="center">'.$langs->trans("NoWebSiteCreateOneFirst").'</center><br><br><br>';
  2490. print '<div class="center"><div class="logo_setup"></div></div>';
  2491. }
  2492. else
  2493. {
  2494. print '<br><br><div class="center">'.$langs->trans("PreviewOfSiteNotYetAvailable", $object->ref).'</center><br><br><br>';
  2495. print '<div class="center"><div class="logo_setup"></div></div>';
  2496. }
  2497. }
  2498. }
  2499. // End of page
  2500. llxFooter();
  2501. $db->close();