From 92cf4f2fd1ae52ea63376b237761a80cea1464d9 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 28 Jan 2024 16:36:01 +0100 Subject: [PATCH 1/4] Mutualize code --- htdocs/admin/ticket_public.php | 6 +++--- htdocs/core/modules/modWebPortal.class.php | 2 ++ htdocs/langs/en_US/admin.lang | 2 ++ htdocs/langs/en_US/ticket.lang | 2 -- htdocs/langs/en_US/website.lang | 2 -- htdocs/langs/fr_FR/admin.lang | 1 + htdocs/langs/fr_FR/ticket.lang | 1 - htdocs/webportal/admin/configcss.php | 2 +- htdocs/webportal/admin/setup.php | 8 ++++---- htdocs/webportal/admin/setup_theme.php | 2 +- htdocs/website/index.php | 14 +++++++++----- 11 files changed, 23 insertions(+), 19 deletions(-) diff --git a/htdocs/admin/ticket_public.php b/htdocs/admin/ticket_public.php index e083c87d205..e58b0599b76 100644 --- a/htdocs/admin/ticket_public.php +++ b/htdocs/admin/ticket_public.php @@ -476,12 +476,12 @@ if (getDolGlobalInt('TICKET_ENABLE_PUBLIC_INTERFACE')) { // Url public interface $url_interface = getDolGlobalString("TICKET_URL_PUBLIC_INTERFACE"); - print ''.$langs->trans("TicketUrlPublicInterfaceLabelAdmin").''; + print ''.$langs->trans("UrlPublicInterfaceLabelAdmin").''; print ''; - print ''; + print ''; print ''; print ''; - print $form->textwithpicto('', $langs->trans("TicketUrlPublicInterfaceHelpAdmin"), 1, 'help'); + print $form->textwithpicto('', $langs->trans("UrlPublicInterfaceHelpAdmin"), 1, 'help'); print ''; print ''; diff --git a/htdocs/core/modules/modWebPortal.class.php b/htdocs/core/modules/modWebPortal.class.php index 6bd2885f31a..99f31d1907f 100644 --- a/htdocs/core/modules/modWebPortal.class.php +++ b/htdocs/core/modules/modWebPortal.class.php @@ -280,6 +280,7 @@ class modWebPortal extends DolibarrModules $this->menu = array(); $r = 0; // Add here entries to declare new menus + /* $this->menu[$r++] = array( 'fk_menu' => '', // '' if this is a top menu. For left menu, use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode 'type' => 'top', // This is a Top menu entry @@ -295,6 +296,7 @@ class modWebPortal extends DolibarrModules 'target' => '', 'user' => 2, // 0=Menu for internal users, 1=external users, 2=both ); + */ /*$this->menu[$r++]=array( 'fk_menu'=>'fk_mainmenu=webportal', // '' if this is a top menu. For left menu, use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode 'type'=>'left', // This is a Left menu entry diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang index fac5f950a30..1a8c9492605 100644 --- a/htdocs/langs/en_US/admin.lang +++ b/htdocs/langs/en_US/admin.lang @@ -2437,3 +2437,5 @@ ParametersForTestEnvironment=Parameters for test environment TryToKeepOnly=Try to keep only %s RecommendedForProduction=Recommended for Production RecommendedForDebug=Recommended for Debug +UrlPublicInterfaceLabelAdmin=Alternative URL for public interface +UrlPublicInterfaceHelpAdmin=It is possible to define an alias to the web server and thus make available the public interface with another URL (the virtual host server must act as a proxy on the standard URL) diff --git a/htdocs/langs/en_US/ticket.lang b/htdocs/langs/en_US/ticket.lang index 460e73e1cf1..e1493e9c14b 100644 --- a/htdocs/langs/en_US/ticket.lang +++ b/htdocs/langs/en_US/ticket.lang @@ -107,8 +107,6 @@ TicketsShowProgressionHelp=Enable this option to hide the progress of the ticket TicketCreateThirdPartyWithContactIfNotExist=Ask name and company name for unknown emails. TicketCreateThirdPartyWithContactIfNotExistHelp=Check if a third party or a contact exists for the email entered. If not, ask a name and a company name to create a third party with contact. PublicInterface=Public interface -TicketUrlPublicInterfaceLabelAdmin=Alternative URL for public interface -TicketUrlPublicInterfaceHelpAdmin=It is possible to define an alias to the web server and thus make available the public interface with another URL (the server must act as a proxy on this new URL) TicketPublicInterfaceTextHomeLabelAdmin=Welcome text of the public interface TicketPublicInterfaceTextHome=You can create a support ticket or view existing from its identifier tracking ticket. TicketPublicInterfaceTextHomeHelpAdmin=The text defined here will appear on the home page of the public interface. diff --git a/htdocs/langs/en_US/website.lang b/htdocs/langs/en_US/website.lang index 1b076f689b4..6d457dfb33b 100644 --- a/htdocs/langs/en_US/website.lang +++ b/htdocs/langs/en_US/website.lang @@ -174,8 +174,6 @@ WebPortalSetup = WebPortal setup WebPortalCSS=Web portal CSS Settings = Settings WebPortalSetupPage = WebPortal setup page -WEBPORTAL_ROOT_URL = Alternative virtual host URL -WebPortalRootUrlHelp = Public access url (http or https) if you have a virtual host or keep empty WEBPORTAL_TITLE = Brand name on header of public page UserAccountForWebPortalAreInThirdPartyTabHelp = Users accounts for WebPortal can be set on each third party card in Website accounts tab WebPortalAccessHidden = Hidden diff --git a/htdocs/langs/fr_FR/admin.lang b/htdocs/langs/fr_FR/admin.lang index b9876492cdd..9864434ff14 100644 --- a/htdocs/langs/fr_FR/admin.lang +++ b/htdocs/langs/fr_FR/admin.lang @@ -2440,3 +2440,4 @@ ParametersForTestEnvironment=Paramètres pour l'environnement de test TryToKeepOnly=Essayez de ne conserver que %s RecommendedForProduction=Recommandé pour la production RecommendedForDebug=Recommandé pour le débogage +UrlPublicInterfaceHelpAdmin=Il est possible de définir un alias vers le serveur et de rendre ainsi l'interface publique accessible avec une autre URL (le serveur doit agir comme un proxy sur cette nouvelle URL) diff --git a/htdocs/langs/fr_FR/ticket.lang b/htdocs/langs/fr_FR/ticket.lang index e8c90035e07..d910042f8ca 100644 --- a/htdocs/langs/fr_FR/ticket.lang +++ b/htdocs/langs/fr_FR/ticket.lang @@ -108,7 +108,6 @@ TicketCreateThirdPartyWithContactIfNotExist=Demandez le nom et le nom de l'entre TicketCreateThirdPartyWithContactIfNotExistHelp=Vérifiez s'il existe un tiers ou un contact pour l'e-mail saisi. Sinon, demandez un nom et un nom société pour créer un tiers avec contact. PublicInterface=Interface publique TicketUrlPublicInterfaceLabelAdmin=URL alternative pour l'interface publique -TicketUrlPublicInterfaceHelpAdmin=Il est possible de définir un alias vers le serveur et de rendre ainsi l'interface publique accessible avec une autre URL (le serveur doit agir comme un proxy sur cette nouvelle URL) TicketPublicInterfaceTextHomeLabelAdmin=Texte de bienvenue dans l'interface publique TicketPublicInterfaceTextHome=Vous pouvez créer un ticket ou consulter à partir d'un ID de ticket existant. TicketPublicInterfaceTextHomeHelpAdmin=Le texte défini ici apparaîtra sur la page d'accueil de l'interface publique. diff --git a/htdocs/webportal/admin/configcss.php b/htdocs/webportal/admin/configcss.php index 56842f4cf74..8f68e8e81c8 100644 --- a/htdocs/webportal/admin/configcss.php +++ b/htdocs/webportal/admin/configcss.php @@ -29,7 +29,7 @@ require_once DOL_DOCUMENT_ROOT . "/core/lib/admin.lib.php"; require_once DOL_DOCUMENT_ROOT . "/webportal/lib/webportal.lib.php"; // Translations -$langs->loadLangs(array("admin", "hrm", "other")); +$langs->loadLangs(array("admin", "hrm", "other", "website")); // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context $hookmanager->initHooks(array('webportalsetup', 'globalsetup')); diff --git a/htdocs/webportal/admin/setup.php b/htdocs/webportal/admin/setup.php index 334a97336cd..78e183d2a95 100644 --- a/htdocs/webportal/admin/setup.php +++ b/htdocs/webportal/admin/setup.php @@ -57,15 +57,15 @@ $useFormSetup = 1; if (!class_exists('FormSetup')) { require_once DOL_DOCUMENT_ROOT . '/core/class/html.formsetup.class.php'; } - $formSetup = new FormSetup($db); // root url $item = $formSetup->newItem('WEBPORTAL_ROOT_URL')->setAsString(); +$item->nameText = $langs->transnoentities('UrlPublicInterfaceLabelAdmin'); $item->fieldAttr = array('placeholder' => 'https://'); -$item->helpText = $langs->transnoentities('WebPortalRootUrlHelp'); +$item->helpText = $langs->transnoentities('UrlPublicInterfaceHelpAdmin'); require_once __DIR__ . '/../class/context.class.php'; -$context = Context::getInstance(); +//$context = Context::getInstance(); //$item->fieldOutputOverride = ''.img_picto('', 'globe', 'class="pictofixedwidth"').Context::getRootConfigUrl().''; @@ -270,7 +270,7 @@ print ajax_autoselect('publicurlmember'); // Setup page goes here print info_admin($langs->trans("UserAccountForWebPortalAreInThirdPartyTabHelp")); -print '
'; +print '

'; if ($action == 'edit') { print $formSetup->generateOutput(true); diff --git a/htdocs/webportal/admin/setup_theme.php b/htdocs/webportal/admin/setup_theme.php index 1e751389fea..9900f89d201 100644 --- a/htdocs/webportal/admin/setup_theme.php +++ b/htdocs/webportal/admin/setup_theme.php @@ -28,7 +28,7 @@ require_once DOL_DOCUMENT_ROOT . "/core/lib/admin.lib.php"; require_once DOL_DOCUMENT_ROOT . "/webportal/lib/webportal.lib.php"; // Translations -$langs->loadLangs(array("admin", "webportal")); +$langs->loadLangs(array("admin", "webportal", "website")); // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context $hookmanager->initHooks(array('webportalthemesetup', 'globalsetup')); diff --git a/htdocs/website/index.php b/htdocs/website/index.php index cd9859e447f..7e0e6183b72 100644 --- a/htdocs/website/index.php +++ b/htdocs/website/index.php @@ -2417,9 +2417,11 @@ if ($action == 'exportsite' && $user->hasRight('website', 'export')) { } } -// Overite site -if ($action == 'overwitesite' && $user->hasRight('website', 'export')) { - $fileofzip = $object->overwriteTemplate(); +// Overwrite site +if ($action == 'overwritesite' && $user->hasRight('website', 'export')) { + if (getDolGlobalString('WEBSITE_ALLOW_OVERWRITE_GIT_SOURCE')) { + $fileofzip = $object->overwriteTemplate(); + } } // Regenerate site if ($action == 'regeneratesite' && $usercanedit) { @@ -3065,8 +3067,10 @@ if (!GETPOST('hide_websitemenu')) { print ''; } - // overite template - print 'ref).'" class="button bordertransp"> '.dol_escape_htmltag($langs->trans("Overwrite")).''; + if (getDolGlobalString('WEBSITE_ALLOW_OVERWRITE_GIT_SOURCE')) { + // overite template + print 'ref).'" class="button bordertransp"> '.dol_escape_htmltag($langs->trans("Overwrite")).''; + } } else { print ''; } From 64233c312e1c317ebe4b9b639cebadc524216c91 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 28 Jan 2024 17:05:15 +0100 Subject: [PATCH 2/4] Debug v20 --- htdocs/website/class/website.class.php | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/htdocs/website/class/website.class.php b/htdocs/website/class/website.class.php index 642447afc23..7b6f2a00f3f 100644 --- a/htdocs/website/class/website.class.php +++ b/htdocs/website/class/website.class.php @@ -1608,8 +1608,9 @@ class Website extends CommonObject } /** - * Overite template by copy and past all files - * @return void + * Overite template by copying all files + * + * @return int <0 if KO, >0 if OK */ public function overwriteTemplate() { @@ -1618,11 +1619,15 @@ class Website extends CommonObject $website = $this; if (empty($website->id) || empty($website->ref)) { setEventMessages("Website id or ref is not defined", null, 'errors'); - return false; + return -1; + } + if (empty($website->name_template)) { + setEventMessages("To export the website template into the GIT sources directory, the name of the directory/template must be know. For this website, the variable 'name_template' is unknown, so export in GIT sources is not possible.", null, 'errors'); + return -1; } if (!is_writable($conf->website->dir_temp)) { setEventMessages("Temporary dir ".$conf->website->dir_temp." is not writable", null, 'errors'); - return ''; + return -1; } $sourcedir = $conf->website->dir_output."/".$website->ref; @@ -1717,6 +1722,7 @@ class Website extends CommonObject } } } + // Find the corresponding file in the destination folder if (in_array($nomFichierModifie, $namesSource)) { foreach ($arraydestdir as $destFile) { @@ -1730,7 +1736,7 @@ class Website extends CommonObject $result = $this->replaceLignEUsingNum($destFile['fullname'], $differences[$nomFichierModifie]); if ($result !== false) { if ($result == -2) { - setEventMessages("No permissions to write in file ".$nomFichierModifie." from template ".$website->name_template."", null, 'errors'); + setEventMessages("No permissions to write in file ".$nomFichierModifie." from the template ".$website->name_template."", null, 'errors'); header("Location: ".$_SERVER["PHP_SELF"].'?website='.$website->ref); exit(); } @@ -1747,7 +1753,7 @@ class Website extends CommonObject $result = $this->replaceLignEUsingNum($differences[$nomFichierModifie]['file_destination']['fullname'], $differences[$nomFichierModifie]); if ($result !== false) { if ($result == -2) { - setEventMessages("No permissions to write in file ".$differences[$nomFichierModifie]['file_destination']['name']." from template ".$website->name_template."", null, 'errors'); + setEventMessages("No permissions to write in file ".$differences[$nomFichierModifie]['file_destination']['name']." from the template ".$website->name_template."", null, 'errors'); header("Location: ".$_SERVER["PHP_SELF"].'?website='.$website->ref); exit(); } @@ -1768,8 +1774,10 @@ class Website extends CommonObject } else { setEventMessages("No file has been modified", null, 'errors'); } + // save state file $this->saveState($etatPrecedent, $fichierEtat); + header("Location: ".$_SERVER["PHP_SELF"].'?website='.$website->ref); exit(); } From 83154b2809b73cbb6346d904f80b18e7585bdbfb Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 28 Jan 2024 17:41:47 +0100 Subject: [PATCH 3/4] Better messages --- htdocs/website/class/website.class.php | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/htdocs/website/class/website.class.php b/htdocs/website/class/website.class.php index 7b6f2a00f3f..45c047b94bd 100644 --- a/htdocs/website/class/website.class.php +++ b/htdocs/website/class/website.class.php @@ -1632,12 +1632,15 @@ class Website extends CommonObject $sourcedir = $conf->website->dir_output."/".$website->ref; - $fichierEtat = $sourcedir . '/etat_fichiers.txt'; + $fichierEtat = $sourcedir . '/filelist-lastwrite-doctemplates.txt'; + // Get array with hash of files $etatPrecedent = $this->checkPreviousState($fichierEtat); + // Get list of all source files of the website $arraySourcedir = dol_dir_list($sourcedir); + // Get list of modified files $modifications = []; foreach ($arraySourcedir as $file) { if (substr($file['name'], -4) === '.old') { @@ -1650,12 +1653,12 @@ class Website extends CommonObject $modifications[] = $file; } - $etatPrecedent[$file['name']] = $hashActuel; + $etatPrecedent[$file['name']] = $hashActuel; // we store he new hash to record it later on disk. } - // listed modified files - - $destdir = DOL_DOCUMENT_ROOT . '/install/doctemplates/websites/'.$website->name_template; + // Replace modified files into the doctemplates directory. + $destdirrel = 'install/doctemplates/websites/'.$website->name_template; + $destdir = DOL_DOCUMENT_ROOT.'/'.$destdirrel; $arraydestdir = dol_dir_list($destdir, "all", 1); $differences = []; $names = array_column($arraydestdir, 'name'); @@ -1736,7 +1739,7 @@ class Website extends CommonObject $result = $this->replaceLignEUsingNum($destFile['fullname'], $differences[$nomFichierModifie]); if ($result !== false) { if ($result == -2) { - setEventMessages("No permissions to write in file ".$nomFichierModifie." from the template ".$website->name_template."", null, 'errors'); + setEventMessages("No permissions to write into file ".$destdirrel.'/'.$nomFichierModifie." from the current website ".$website->name_template."", null, 'errors'); header("Location: ".$_SERVER["PHP_SELF"].'?website='.$website->ref); exit(); } @@ -1753,7 +1756,7 @@ class Website extends CommonObject $result = $this->replaceLignEUsingNum($differences[$nomFichierModifie]['file_destination']['fullname'], $differences[$nomFichierModifie]); if ($result !== false) { if ($result == -2) { - setEventMessages("No permissions to write in file ".$differences[$nomFichierModifie]['file_destination']['name']." from the template ".$website->name_template."", null, 'errors'); + setEventMessages("No permissions to write into file ".$destdirrel.'/'.$differences[$nomFichierModifie]['file_destination']['name']." from the current website ".$website->name_template."", null, 'errors'); header("Location: ".$_SERVER["PHP_SELF"].'?website='.$website->ref); exit(); } @@ -1765,7 +1768,7 @@ class Website extends CommonObject } } if ($succes>0) { - // save state file + // Save the state file filelist.txt $this->saveState($etatPrecedent, $fichierEtat); setEventMessages("file ".$differences[$nomFichierModifie]['file_destination']['name']." was modified in template ".$website->name_template."", null, 'warnings'); header("Location: ".$_SERVER["PHP_SELF"].'?website='.$website->ref); @@ -1852,7 +1855,7 @@ class Website extends CommonObject */ public function initFilesStatus($sourcedir) { - $fichierEtat = $sourcedir . '/etat_fichiers.txt'; + $fichierEtat = $sourcedir . '/filelist-lastwrite-doctemplates.txt'; $etatPrecedent = $this->checkPreviousState($fichierEtat); From 38f897609d24bfb2214c6fa5c20478b896c3b227 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 28 Jan 2024 17:47:50 +0100 Subject: [PATCH 4/4] Trans --- htdocs/langs/en_US/website.lang | 1 + htdocs/website/index.php | 9 +++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/htdocs/langs/en_US/website.lang b/htdocs/langs/en_US/website.lang index 6d457dfb33b..d97f4ff23ac 100644 --- a/htdocs/langs/en_US/website.lang +++ b/htdocs/langs/en_US/website.lang @@ -232,3 +232,4 @@ WebPortalErrorFetchLoggedUser = Error when loading user (Id : %s) WebPortalErrorFetchLoggedThirdParty = Error when loading third-party (Id : %s) WebPortalErrorFetchLoggedMember = Error when loading member (Id : %s) WebPortalErrorFetchLoggedPartnership = Error when loading partnership (Third-party Id : %s, Member Id : %s) +ExportIntoGIT=Export into sources \ No newline at end of file diff --git a/htdocs/website/index.php b/htdocs/website/index.php index 7e0e6183b72..872431c1bb9 100644 --- a/htdocs/website/index.php +++ b/htdocs/website/index.php @@ -3022,6 +3022,11 @@ if (!GETPOST('hide_websitemenu')) { // Export web site print ''; + if (getDolGlobalString('WEBSITE_ALLOW_OVERWRITE_GIT_SOURCE')) { + // Overwrite template in sources + print 'ref).'" class="button bordertransp">'.dol_escape_htmltag($langs->trans("ExportIntoGIT")).''; + } + // Clone web site print ''; @@ -3067,10 +3072,6 @@ if (!GETPOST('hide_websitemenu')) { print ''; } - if (getDolGlobalString('WEBSITE_ALLOW_OVERWRITE_GIT_SOURCE')) { - // overite template - print 'ref).'" class="button bordertransp"> '.dol_escape_htmltag($langs->trans("Overwrite")).''; - } } else { print ''; }