From 1415ad5b53f86122b56badd788bf424a809d7758 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 2 Jun 2019 17:27:00 +0200 Subject: [PATCH] Debug website module --- htdocs/langs/en_US/website.lang | 5 +- htdocs/theme/eldy/global.inc.php | 2 +- htdocs/theme/md/style.css.php | 2 +- htdocs/website/class/website.class.php | 21 +++++--- htdocs/website/index.php | 69 ++++++++++++++++++++------ 5 files changed, 76 insertions(+), 23 deletions(-) diff --git a/htdocs/langs/en_US/website.lang b/htdocs/langs/en_US/website.lang index 4655bf3493a..43f82e9f1fb 100644 --- a/htdocs/langs/en_US/website.lang +++ b/htdocs/langs/en_US/website.lang @@ -97,4 +97,7 @@ ThisPageHasTranslationPages=This page/container has translation NoWebSiteCreateOneFirst=No website has been created yet. Create one first. GoTo=Go to DynamicPHPCodeContainsAForbiddenInstruction=You add dynamic PHP code that contains the PHP instruction '%s' that is forbidden by default as dynamic content (see hidden options WEBSITE_PHP_ALLOW_xxx to increase list of allowed commands). -NotAllowedToAddDynamicContent=You don't have permission to add or edit PHP dynamic content in websites. Ask permission or just keep code into php tags unmodified. \ No newline at end of file +NotAllowedToAddDynamicContent=You don't have permission to add or edit PHP dynamic content in websites. Ask permission or just keep code into php tags unmodified. +ReplaceWebsiteContent=Replace website content +DeleteAlsoJs=Delete also all javascript files specific to this website? +DeleteAlsoMedias=Delete also all medias files specific to this website? \ No newline at end of file diff --git a/htdocs/theme/eldy/global.inc.php b/htdocs/theme/eldy/global.inc.php index 010d2bd8eed..70496d8689a 100644 --- a/htdocs/theme/eldy/global.inc.php +++ b/htdocs/theme/eldy/global.inc.php @@ -313,7 +313,7 @@ hr { border: 0; border-top: 1px solid #ccc; } -webkit-box-shadow: 0px 0px 1px 1px rgba(0, 0, 0, 0.2), 0px 0px 0px rgba(60,60,60,0.1); box-shadow: 0px 0px 1px 1px rgba(0, 0, 0, 0.2), 0px 0px 0px rgba(60,60,60,0.1); } -.button:disabled, .buttonDelete:disabled { +.button:disabled, .buttonDelete:disabled, .button.disabled { opacity: 0.4; box-shadow: none; -webkit-box-shadow: none; diff --git a/htdocs/theme/md/style.css.php b/htdocs/theme/md/style.css.php index 2dfdf4e28a1..98618800e39 100644 --- a/htdocs/theme/md/style.css.php +++ b/htdocs/theme/md/style.css.php @@ -540,7 +540,7 @@ hr { border: 0; border-top: 1px solid #ccc; } -webkit-box-shadow: 0px 0px 6px 1px rgba(0, 0, 0, 0.2), 0px 0px 0px rgba(60,60,60,0.1); box-shadow: 0px 0px 6px 1px rgba(0, 0, 0, 0.2), 0px 0px 0px rgba(60,60,60,0.1); } -.button:disabled, .buttonDelete:disabled { +.button:disabled, .buttonDelete:disabled, .button.disabled { opacity: 0.4; box-shadow: none; -webkit-box-shadow: none; diff --git a/htdocs/website/class/website.class.php b/htdocs/website/class/website.class.php index a12bb2ebf11..5405f723a0c 100644 --- a/htdocs/website/class/website.class.php +++ b/htdocs/website/class/website.class.php @@ -489,8 +489,7 @@ class Website extends CommonObject if (! $error && ! empty($this->ref)) { - global $dolibarr_main_data_root; - $pathofwebsite=$dolibarr_main_data_root.'/website/'.$this->ref; + $pathofwebsite=DOL_DATA_ROOT.'/website/'.$this->ref; dol_delete_dir_recursive($pathofwebsite); } @@ -519,7 +518,7 @@ class Website extends CommonObject */ public function createFromClone($user, $fromid, $newref, $newlang = '') { - global $conf, $hookmanager; + global $conf; global $dolibarr_main_data_root; $now = dol_now(); @@ -542,8 +541,9 @@ class Website extends CommonObject $object->fetch($fromid); $oldidforhome=$object->fk_default_home; + $oldref=$object->ref; - $pathofwebsiteold=$dolibarr_main_data_root.'/website/'.$object->ref; + $pathofwebsiteold=$dolibarr_main_data_root.'/website/'.$oldref; $pathofwebsitenew=$dolibarr_main_data_root.'/website/'.$newref; dol_delete_dir_recursive($pathofwebsitenew); @@ -575,8 +575,8 @@ class Website extends CommonObject dolCopyDir($pathofwebsiteold, $pathofwebsitenew, $conf->global->MAIN_UMASK, 0); // Check symlink to medias and restore it if ko - $pathtomedias=DOL_DATA_ROOT.'/medias'; - $pathtomediasinwebsite=$pathofwebsitenew.'/medias'; + $pathtomedias=DOL_DATA_ROOT.'/medias'; // Target + $pathtomediasinwebsite=$pathofwebsitenew.'/medias'; // Source / Link name if (! is_link(dol_osencode($pathtomediasinwebsite))) { dol_syslog("Create symlink for ".$pathtomedias." into name ".$pathtomediasinwebsite); @@ -584,6 +584,15 @@ class Website extends CommonObject $result = symlink($pathtomedias, $pathtomediasinwebsite); } + // Copy images and js dir + $pathofmediasjsold=DOL_DATA_ROOT.'/medias/js/'.$oldref; + $pathofmediasjsnew=DOL_DATA_ROOT.'/medias/js/'.$newref; + dolCopyDir($pathofmediasjsold, $pathofmediasjsnew, $conf->global->MAIN_UMASK, 0); + + $pathofmediasimageold=DOL_DATA_ROOT.'/medias/image/'.$oldref; + $pathofmediasimagenew=DOL_DATA_ROOT.'/medias/image/'.$newref; + dolCopyDir($pathofmediasimageold, $pathofmediasimagenew, $conf->global->MAIN_UMASK, 0); + $newidforhome=0; // Duplicate pages diff --git a/htdocs/website/index.php b/htdocs/website/index.php index 379e5d2e05c..76d063393f8 100644 --- a/htdocs/website/index.php +++ b/htdocs/website/index.php @@ -799,13 +799,13 @@ if ($action == 'addcontainer') } // Delete site -if ($action == 'deletesite') +if ($action == 'confirm_deletesite' && $confirm == 'yes') { $error = 0; $db->begin(); - $res = $object->fetch(0, $websitekey); + $res = $object->fetch(GETPOST('id', 'int')); $website = $object; if ($res > 0) @@ -817,13 +817,28 @@ if ($action == 'deletesite') setEventMessages($object->error, $object->errors, 'errors'); } } + if (! $error) + { + if (GETPOST('delete_also_js', 'alpha') == 'on') + { + $pathofwebsitejs=DOL_DATA_ROOT.'/medias/js/'.$object->ref; + + dol_delete_dir_recursive($pathofwebsitejs); + } + if (GETPOST('delete_also_medias', 'alpha') == 'on') + { + $pathofwebsitemedias=DOL_DATA_ROOT.'/medias/image/'.$object->ref; + + dol_delete_dir_recursive($pathofwebsitemedias); + } + } if (! $error) { $db->commit(); - setEventMessages($langs->trans("SiteDeleted", $object->ref, $websitekey), null, 'mesgs'); + setEventMessages($langs->trans("SiteDeleted", $object->ref), null, 'mesgs'); - header("Location: ".$_SERVER["PHP_SELF"]); + header("Location: ".$_SERVER["PHP_SELF"].'?id='.$object->id); exit; } else @@ -1815,7 +1830,7 @@ if (! GETPOST('hide_websitemenu')) if (! is_array($array) && $array < 0) dol_print_error('', $objectpage->error, $objectpage->errors); $atleastonepage=(is_array($array) && count($array) > 0); - if ($websitekey && $websitekey != '-1' && ($action == 'preview' || $action == 'createfromclone' || $action == 'createpagefromclone')) + if ($websitekey && $websitekey != '-1' && ($action == 'preview' || $action == 'createfromclone' || $action == 'createpagefromclone' || $action == 'deletesite')) { $disabled=''; if (empty($user->rights->website->write)) $disabled=' disabled="disabled"'; @@ -1862,7 +1877,7 @@ if (! GETPOST('hide_websitemenu')) */ //print ''.dol_escape_htmltag($langs->trans("Replace")).'" name="replacesite">'; - print 'ref.'" class="button nobordertransp"'.$disabled.' title="'.dol_escape_htmltag($langs->trans("ReplaceWebSiteContent")).'">'; + print 'ref.'" class="button nobordertransp"'.$disabled.' title="'.dol_escape_htmltag($langs->trans("ReplaceWebsiteContent")).'">'; } print ''; @@ -1872,7 +1887,7 @@ if (! GETPOST('hide_websitemenu')) print '
'; - if ($action == 'preview' || $action == 'createfromclone' || $action == 'createpagefromclone') + if ($action == 'preview' || $action == 'createfromclone' || $action == 'createpagefromclone' || $action == 'deletesite') { $urlext=$virtualurl; $urlint=$urlwithroot.'/public/website/index.php?website='.$websitekey; @@ -2038,11 +2053,26 @@ if (! GETPOST('hide_websitemenu')) $websitepage->fetch($pageid); } - if ($action == 'preview' || $action == 'createfromclone' || $action == 'createpagefromclone') + if ($action == 'preview' || $action == 'createfromclone' || $action == 'createpagefromclone' || $action == 'deletesite') { $disabled=''; if (empty($user->rights->website->write)) $disabled=' disabled="disabled"'; + // Confirmation delete site + if ($action == 'deletesite') { + // Create an array for form + $formquestion = array( + array('type' => 'checkbox', 'name' => 'delete_also_js', 'label' => $langs->trans("DeleteAlsoJs"), 'value' => 0), + array('type' => 'checkbox', 'name' => 'delete_also_medias', 'label' => $langs->trans("DeleteAlsoMedias"), 'value' => 0), + //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')), + //array('type' => 'other','name' => 'newwebsite','label' => $langs->trans("WebSite"), 'value' => $formwebsite->selectWebsite($object->id, 'newwebsite', 0)) + ); + + $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id='.$object->id, $langs->trans('DeleteWebsite'), '', 'confirm_deletesite', $formquestion, 0, 1, 200); + + print $formconfirm; + } + // Confirmation to clone if ($action == 'createfromclone') { // Create an array for form @@ -2058,7 +2088,7 @@ if (! GETPOST('hide_websitemenu')) print $formconfirm; } - if ($pageid > 0 && $atleastonepage) // pageid can be set without pages, if homepage of site is set and all page were removed + if ($pageid > 0 && $atleastonepage) // pageid can be set without pages, if homepage of site is set and all pages were removed { // Confirmation to clone if ($action == 'createpagefromclone') { @@ -2125,8 +2155,19 @@ if (! GETPOST('hide_websitemenu')) print '
'; print ''; - if ($object->fk_default_home > 0 && $pageid == $object->fk_default_home) print ''; - else print ''; + // @TODO Move this action into a combo list + if ($object->fk_default_home > 0 && $pageid == $object->fk_default_home) + { + //$disabled=' disabled="disabled"'; + //print ''; + print ''; + } + else + { + //$disabled=''; + //print 'ref.'" class="button nobordertransp"'.$disabled.' title="'.dol_escape_htmltag($langs->trans("SetAsHomePage")).'">'; + print ''; + } print ''; print ''; } @@ -2136,7 +2177,7 @@ if (! GETPOST('hide_websitemenu')) print '
'; - if (($pageid > 0 && $atleastonepage) && ($action == 'preview' || $action == 'createfromclone' || $action == 'createpagefromclone')) + if (($pageid > 0 && $atleastonepage) && ($action == 'preview' || $action == 'createfromclone' || $action == 'createpagefromclone' || $action == 'deletesite')) { $realpage=$urlwithroot.'/public/website/index.php?website='.$websitekey.'&pageref='.$websitepage->pageurl; $pagealias = $websitepage->pageurl; @@ -2167,7 +2208,7 @@ if (! GETPOST('hide_websitemenu')) // TODO Add js to save alias like we save virtual host name and use dynamic virtual host for url of id=previewpageext } - if (! in_array($action, array('editcss','editmenu','file_manager','replacesite','createsite','createcontainer','createpagefromclone'))) + if (! in_array($action, array('editcss','editmenu','file_manager','replacesite','createsite','createcontainer','createfromclone','createpagefromclone','deletesite'))) { if (preg_match('/^create/', $action)) print ''; if (preg_match('/^edit/', $action)) print ''; @@ -2842,7 +2883,7 @@ if ($action == 'replacesite') print ''."\n"; print '

'; - print load_fiche_titre($langs->trans("ReplaceWebSiteContent")); + print load_fiche_titre($langs->trans("ReplaceWebsiteContent")); print '
'.$langs->trans("FeatureNotYetAvailable").'';