From fe93ee4d083c8de81439920dcac229529a6f9009 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 19 Dec 2020 13:03:40 +0100 Subject: [PATCH] Debug website module for multilanguage --- htdocs/core/class/html.formwebsite.class.php | 18 +++++++--- htdocs/langs/en_US/errors.lang | 4 ++- htdocs/langs/en_US/website.lang | 2 +- htdocs/website/index.php | 38 +++++++++++++++----- 4 files changed, 47 insertions(+), 15 deletions(-) diff --git a/htdocs/core/class/html.formwebsite.class.php b/htdocs/core/class/html.formwebsite.class.php index 0f3e9a357b8..8cbb7967415 100644 --- a/htdocs/core/class/html.formwebsite.class.php +++ b/htdocs/core/class/html.formwebsite.class.php @@ -107,9 +107,10 @@ class FormWebsite * @param string $selected Selected value * @param int $useempty 1=Add an empty value in list, 2=Add an empty value in list only if there is more than 2 entries. * @param string $moreattrib More attributes on HTML select tag + * @param int $addjscombo Add js combo * @return void */ - public function selectTypeOfContainer($htmlname, $selected = '', $useempty = 0, $moreattrib = '') + public function selectTypeOfContainer($htmlname, $selected = '', $useempty = 0, $moreattrib = '', $addjscombo = 0) { global $langs, $conf, $user; @@ -128,7 +129,7 @@ class FormWebsite $i = 0; if ($num) { - print ''; if ($useempty == 1 || ($useempty == 2 && $num > 1)) { print ''; @@ -149,6 +150,10 @@ class FormWebsite } print ""; if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1); + + if ($addjscombo) { + print ajax_combobox('select'.$htmlname); + } } else { print $langs->trans("NoTypeOfPagePleaseEditDictionary"); } @@ -165,9 +170,10 @@ class FormWebsite * @param string $selected Selected value * @param int $useempty 1=Add an empty value in list * @param string $moreattrib More attributes on HTML select tag + * @param int $addjscombo Add js combo * @return string HTML select component with list of type of containers */ - public function selectSampleOfContainer($htmlname, $selected = '', $useempty = 0, $moreattrib = '') + public function selectSampleOfContainer($htmlname, $selected = '', $useempty = 0, $moreattrib = '', $addjscombo = 0) { global $langs, $conf, $user; @@ -190,7 +196,7 @@ class FormWebsite } $out = ''; - $out .= ''; if ($useempty == 1 || $useempty == 2) { @@ -210,6 +216,10 @@ class FormWebsite } $out .= ""; + if ($addjscombo) { + $out .= ajax_combobox('select'.$htmlname); + } + return $out; } diff --git a/htdocs/langs/en_US/errors.lang b/htdocs/langs/en_US/errors.lang index 9a20094a7aa..056bec48fe9 100644 --- a/htdocs/langs/en_US/errors.lang +++ b/htdocs/langs/en_US/errors.lang @@ -252,7 +252,9 @@ ErrorValueLength=Length of field '%s' must be higher than '%s' ErrorReservedKeyword=The word '%s' is a reserved keyword ErrorNotAvailableWithThisDistribution=Not available with this distribution ErrorPublicInterfaceNotEnabled=Public interface was not enabled - +ErrorLanguageRequiredIfPageIsTranslationOfAnother=The language of new page must be defined if it is set as a translation of another page +ErrorLanguageMustNotBeSourceLanguageIfPageIsTranslationOfAnother=The language of new page must not be the source language if it is set as a translation of another page + # Warnings WarningParamUploadMaxFileSizeHigherThanPostMaxSize=Your PHP parameter upload_max_filesize (%s) is higher than PHP parameter post_max_size (%s). This is not a consistent setup. WarningPasswordSetWithNoAccount=A password was set for this member. However, no user account was created. So this password is stored but can't be used to login to Dolibarr. It may be used by an external module/interface but if you don't need to define any login nor password for a member, you can disable option "Manage a login for each member" from Member module setup. If you need to manage a login but don't need any password, you can keep this field empty to avoid this warning. Note: Email can also be used as a login if the member is linked to a user. diff --git a/htdocs/langs/en_US/website.lang b/htdocs/langs/en_US/website.lang index b6dbee28994..7793fa5dead 100644 --- a/htdocs/langs/en_US/website.lang +++ b/htdocs/langs/en_US/website.lang @@ -100,7 +100,7 @@ EmptyPage=Empty page ExternalURLMustStartWithHttp=External URL must start with http:// or https:// ZipOfWebsitePackageToImport=Upload the Zip file of the website template package ZipOfWebsitePackageToLoad=or Choose an available embedded website template package -ShowSubcontainers=Include dynamic content +ShowSubcontainers=Show dynamic content InternalURLOfPage=Internal URL of page ThisPageIsTranslationOf=This page/container is a translation of ThisPageHasTranslationPages=This page/container has translation diff --git a/htdocs/website/index.php b/htdocs/website/index.php index f36225b2407..c1fe6f84c77 100644 --- a/htdocs/website/index.php +++ b/htdocs/website/index.php @@ -940,6 +940,7 @@ if ($action == 'addcontainer') $objectpage->keywords = str_replace(array('<', '>'), '', GETPOST('WEBSITE_KEYWORDS', 'alphanohtml')); $objectpage->allowed_in_frames = GETPOST('WEBSITE_ALLOWED_IN_FRAMES', 'aZ09'); $objectpage->htmlheader = GETPOST('htmlheader', 'none'); + $objectpage->fk_page = (GETPOST('pageidfortranslation', 'int') > 0 ? GETPOST('pageidfortranslation', 'int') : 0); $objectpage->author_alias = GETPOST('WEBSITE_AUTHORALIAS', 'alphanohtml'); $objectpage->object_type = GETPOST('WEBSITE_OBJECTCLASS'); $objectpage->fk_object = GETPOST('WEBSITE_OBJECTID'); @@ -949,7 +950,7 @@ if ($action == 'addcontainer') $sample = GETPOST('sample', 'alpha'); if (empty($sample)) $sample = 'empty'; - $pathtosample = DOL_DOCUMENT_ROOT.'/website/samples/page-sample-'.$sample.'.html'; + $pathtosample = DOL_DOCUMENT_ROOT.'/website/samples/page-sample-'.dol_sanitizeFileName($sample).'.html'; // Init content with content into pagetemplate.html, blogposttempltate.html, ... $objectpage->content = make_substitutions(@file_get_contents($pathtosample), $substitutionarray); @@ -978,6 +979,22 @@ if ($action == 'addcontainer') $error++; $action = 'createcontainer'; } + if ($objectpage->fk_page > 0 && empty($objectpage->lang)) + { + $langs->load("errors"); + setEventMessages($langs->trans("ErrorLanguageRequiredIfPageIsTranslationOfAnother"), null, 'errors'); + $error++; + $action = 'createcontainer'; + } + if ($objectpage->fk_page > 0 && !empty($objectpage->lang)) + { + if ($objectpage->lang == $website->lang) { + $langs->load("errors"); + setEventMessages($langs->trans("ErrorLanguageMustNotBeSourceLanguageIfPageIsTranslationOfAnother"), null, 'errors'); + $error++; + $action = 'createcontainer'; + } + } } if (!$error) @@ -3231,14 +3248,16 @@ if ($action == 'createsite') print ''; print ''; - print $langs->trans('OtherLanguages'); + $htmltext = $langs->trans("Example").': fr,de,sv,it,pt'; + print $form->textwithpicto($langs->trans('OtherLanguages'), $htmltext, 1, 'help', '', 0, 2); print ''; print ''; print ''; print ''; - $htmltext = $langs->trans("SetHereVirtualHost", DOL_DATA_ROOT.'/website/websiteref'); + $htmltext = $langs->trans("SetHereVirtualHost", '{s1}'); + $htmltext = str_replace('{s1}', DOL_DATA_ROOT.'/website/websiteref', $htmltext); $htmltext .= '
'; $htmltext .= '
'.$langs->trans("CheckVirtualHostPerms", $langs->transnoentitiesnoconv("ReadPerm"), DOL_DOCUMENT_ROOT); $htmltext .= '
'.$langs->trans("CheckVirtualHostPerms", $langs->transnoentitiesnoconv("WritePerm"), '{s1}'); @@ -3351,7 +3370,7 @@ if ($action == 'editmeta' || $action == 'createcontainer') // Edit properties of print ' '; print $langs->trans("ImagesShouldBeSavedInto").' '; $arraygrabimagesinto = array('root'=>$langs->trans("WebsiteRootOfImages"), 'subpage'=>$langs->trans("SubdirOfPage")); - print $form->selectarray('grabimagesinto', $arraygrabimagesinto, GETPOSTISSET('grabimagesinto') ?GETPOST('grabimagesinto') : 'root'); + print $form->selectarray('grabimagesinto', $arraygrabimagesinto, GETPOSTISSET('grabimagesinto') ? GETPOST('grabimagesinto') : 'root', 0, 0, 0, '', 0, 0, 0, '', '', 1); print '
'; print ''; print ''; @@ -3433,7 +3452,7 @@ if ($action == 'editmeta' || $action == 'createcontainer') // Edit properties of print $langs->trans('WEBSITE_TYPE_CONTAINER'); print ''; print img_picto('', 'object_technic', 'class="paddingrightonly"').' '; - $formwebsite->selectTypeOfContainer('WEBSITE_TYPE_CONTAINER', (GETPOST('WEBSITE_TYPE_CONTAINER', 'alpha') ?GETPOST('WEBSITE_TYPE_CONTAINER', 'alpha') : $type_container)); + $formwebsite->selectTypeOfContainer('WEBSITE_TYPE_CONTAINER', (GETPOST('WEBSITE_TYPE_CONTAINER', 'alpha') ? GETPOST('WEBSITE_TYPE_CONTAINER', 'alpha') : $type_container), 0, '', 1); print ''; if ($action == 'createcontainer') @@ -3441,7 +3460,7 @@ if ($action == 'editmeta' || $action == 'createcontainer') // Edit properties of print ''; print $langs->trans('WEBSITE_PAGE_EXAMPLE'); print ''; - print $formwebsite->selectSampleOfContainer('sample', (GETPOSTISSET('sample') ?GETPOST('sample', 'alpha') : 'empty')); + print $formwebsite->selectSampleOfContainer('sample', (GETPOSTISSET('sample') ? GETPOST('sample', 'alpha') : 'empty'), 0, '', 1); print ''; } @@ -3561,7 +3580,7 @@ if ($action == 'editmeta' || $action == 'createcontainer') // Edit properties of $translationof = $objectpage->fk_page; print ''.$langs->trans('ThisPageIsTranslationOf').' '; print $formwebsite->selectContainer($website, 'pageidfortranslation', ($translationof ? $translationof : -1), 1, $action, 'minwidth300', array($objectpage->id)); - if ($translationof > 0) { + if ($translationof > 0 && $sourcepage->lang) { print $sourcepage->getNomUrl(2).' ('.$sourcepage->lang.')'; } } @@ -3596,8 +3615,9 @@ if ($action == 'editmeta' || $action == 'createcontainer') // Edit properties of $cate_arbo = $form->select_all_categories(Categorie::TYPE_WEBSITE_PAGE, '', 'parent', null, null, 1); } - print ''.$form->editfieldkey('Categories', 'categories', '', $objectpage, 0).''; - print img_picto('', 'category', 'class="paddingright"').$form->multiselectarray('categories', $cate_arbo, (GETPOSTISSET('categories') ? GETPOST('categories', 'array') : $arrayselected), null, null, 'quatrevingtpercent widthcentpercentminusx'); + print ''.$form->editfieldkey('Categories', 'categories', '', $objectpage, 0).''; + print img_picto('', 'category', 'class="paddingright"'); + print $form->multiselectarray('categories', $cate_arbo, (GETPOSTISSET('categories') ? GETPOST('categories', 'array') : $arrayselected), null, null, 'quatrevingtpercent widthcentpercentminusx'); print ""; }