diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 8eb357a3908..7224949a70b 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -4345,7 +4345,7 @@ abstract class CommonObject } /** - * Set status of an object + * Set status of an object. * * @param int $status Status to set * @param int $elementId Id of element to force (use this->id by default if null) diff --git a/htdocs/core/lib/ajax.lib.php b/htdocs/core/lib/ajax.lib.php index 8098fa7a16e..b6ec08da434 100644 --- a/htdocs/core/lib/ajax.lib.php +++ b/htdocs/core/lib/ajax.lib.php @@ -644,36 +644,41 @@ function ajax_constantonoff($code, $input = array(), $entity = null, $revertonof * This is called when MAIN_DIRECT_STATUS_UPDATE is set and it use tha ajax service objectonoff.php * * @param Object $object Object to set - * @param string $code Name of constant : status or status_buy for product by example + * @param string $code Name of property in object : 'status' or 'status_buy' for product by example * @param string $field Name of database field : 'tosell' or 'tobuy' for product by example * @param string $text_on Text if on * @param string $text_off Text if off * @param array $input Array of type->list of CSS element to switch. Example: array('disabled'=>array(0=>'cssid')) * @param string $morecss More CSS + * @param string $htmlname Name of HTML component. Keep '' or use a different value if you need to use this component several time on same page for same property. * @return string html for button on/off */ -function ajax_object_onoff($object, $code, $field, $text_on, $text_off, $input = array(), $morecss = '') +function ajax_object_onoff($object, $code, $field, $text_on, $text_off, $input = array(), $morecss = '', $htmlname = '') { global $langs; + if (empty($htmlname)) { + $htmlname = $code; + } + $out = ''; - $out .= ''.img_picto($langs->trans($text_off), 'switch_off').''; - $out .= ''.img_picto($langs->trans($text_on), 'switch_on').''; + $out .= ''.img_picto($langs->trans($text_off), 'switch_off').''; + $out .= ''.img_picto($langs->trans($text_on), 'switch_on').''; return $out; } diff --git a/htdocs/langs/en_US/website.lang b/htdocs/langs/en_US/website.lang index 298f7c6ab51..8644becdd8c 100644 --- a/htdocs/langs/en_US/website.lang +++ b/htdocs/langs/en_US/website.lang @@ -152,3 +152,4 @@ NextContainer=Next page/container PreviousContainer=Previous page/container WebsiteMustBeDisabled=The website must have the status "%s" WebpageMustBeDisabled=The web page must have the status "%s" +SetWebsiteOnlineBefore=When website is offline, all pages are offline. Change status of website first. diff --git a/htdocs/website/index.php b/htdocs/website/index.php index 7cf58a81971..55c2b8f31a8 100644 --- a/htdocs/website/index.php +++ b/htdocs/website/index.php @@ -420,6 +420,18 @@ if ($action == 'renamefile') { // Must be after include DOL_DOCUMENT_ROOT.'/core $action = 'file_manager'; } +if ($action == 'setwebsiteonline') { + $website->setStatut($website::STATUS_VALIDATED, null, '', 'WEBSITE_MODIFY', 'status'); + + header("Location: ".$_SERVER["PHP_SELF"].'?website='.GETPOST('website', 'alphanohtml').'&pageid='.GETPOST('websitepage', 'int')); + exit; +} +if ($action == 'setwebsiteoffline') { + $result = $website->setStatut($website::STATUS_DRAFT, null, '', 'WEBSITE_MODIFY', 'status'); + + header("Location: ".$_SERVER["PHP_SELF"].'?website='.GETPOST('website', 'alphanohtml').'&pageid='.GETPOST('websitepage', 'int')); + exit; +} if ($action == 'seteditinline') { dolibarr_set_const($db, 'WEBSITE_EDITINLINE', 1); setEventMessages($langs->trans("FeatureNotYetAvailable"), null, 'warnings'); @@ -478,7 +490,6 @@ if ($action == 'deletetemplate') { } } - // Set category if ($massaction == 'setcategory' && GETPOST('confirmmassaction', 'alpha') && $usercanedit) { $error = 0; @@ -517,7 +528,8 @@ if ($massaction == 'setcategory' && GETPOST('confirmmassaction', 'alpha') && $us // Now we reload list $listofpages = getPagesFromSearchCriterias($containertype, $algo, $searchkey, 1000, $sortfield, $sortorder, $langcode, $otherfilters, -1); } -// Set category + +// Del category if ($massaction == 'delcategory' && GETPOST('confirmmassaction', 'alpha') && $usercanedit) { $error = 0; $nbupdate = 0; @@ -2750,6 +2762,11 @@ if (!GETPOST('hide_websitemenu')) { } $atleastonepage = (is_array($array) && count($array) > 0); + $websitepage = new WebSitePage($db); + if ($pageid > 0 && ($action == 'preview' || $action == 'createfromclone' || $action == 'createpagefromclone')) { + $websitepage->fetch($pageid); + } + //var_dump($objectpage);exit; print '
'; @@ -2764,15 +2781,14 @@ if (!GETPOST('hide_websitemenu')) { print $langs->trans("Website").': '; print '
'; + // Button Add new website $urltocreatenewwebsite = $_SERVER["PHP_SELF"].'?action=createsite'; - //if (empty($conf->use_javascript_ajax)) { - print ''; - print ''; - print ''; - //} + print ''; + print ''; + print ''; // List of website - print ''; + print ''; $out = ''; $out .= ''; + print ''; + + // Switch offline/onine + if (!empty($conf->use_javascript_ajax)) { + print ''; + // Do not use ajax, we need a refresh of full page when we change status of a website + //print '
'; + //print ajax_object_onoff($object, 'status', 'status', 'Online', 'Offline', array(), 'valignmiddle', 'statuswebsite'); + //print '
'; + if ($website->status == $website::STATUS_DRAFT) { + $text_off = 'Offline'; + print 'ref).'&websitepage='.((int) $websitepage->id).'">'.img_picto($langs->trans($text_off), 'switch_off').''; + } else { + $text_off = 'Online'; + print 'ref).'&websitepage='.((int) $websitepage->id).'">'.img_picto($langs->trans($text_off), 'switch_on').''; + } + print '
'; + } + + // Refresh / Reload web site (for non javascript browers) + if (empty($conf->use_javascript_ajax)) { + print ''; + print ''; + print ''; } - print '
'; print ''; if ($websitekey && $websitekey != '-1' && ($action == 'preview' || $action == 'createfromclone' || $action == 'createpagefromclone' || $action == 'deletesite')) { - print '   '; - - //print ''; - print ''.dol_escape_htmltag($langs->trans("EditCss")).''; + // Edit website properties + print ''.dol_escape_htmltag($langs->trans("EditCss")).''; + // Import web site $importlabel = $langs->trans("ImportSite"); $exportlabel = $langs->trans("ExportSite"); if (!empty($conf->dol_optimize_smallscreen)) { @@ -2853,9 +2883,10 @@ if (!GETPOST('hide_websitemenu')) { print ''; } - //print ''; + // Export web site print ''; + // Clone web site print ''; // Delete website @@ -2988,46 +3019,57 @@ if (!GETPOST('hide_websitemenu')) { print $langs->trans("PageContainer").': '; print ''; + // Button Add new web page print ''; print 'ref).'" class=""'.$disabled.' title="'.dol_escape_htmltag($langs->trans("AddPage")).'">'; print ''; - //print ''; - //if ($action != 'addcontainer') { - $out = ''; + $out = ''; - $s = $formwebsite->selectContainer($website, 'pageid', $pageid, 0, $action, 'minwidth100 maxwidth200onsmartphone'); + $s = $formwebsite->selectContainer($website, 'pageid', $pageid, 0, $action, 'minwidth100 maxwidth200onsmartphone'); - if ($formwebsite->num >= 0) { - $out .= ''; - $out .= $s; - $out .= ''; + $out .= ''; + $out .= $s; + $out .= ''; - $urltocreatenewpage = $_SERVER["PHP_SELF"].'?action=createcontainer&token='.newToken().'&website='.urlencode($website->ref); + $urltocreatenewpage = $_SERVER["PHP_SELF"].'?action=createcontainer&token='.newToken().'&website='.urlencode($website->ref); - if (!empty($conf->use_javascript_ajax)) { - $out .= ''; - } + if (!empty($conf->use_javascript_ajax)) { + $out .= ''; } - print $out; - /*} else { - print $langs->trans("New"); - }*/ + print $out; + if (!empty($conf->use_javascript_ajax)) { + print ''; + //print '
'; + if ($object->status == $object::STATUS_DRAFT) { // website is off, we do not allow to change status of page + $text_off = 'SetWebsiteOnlineBefore'; + if ($objectpage->status == $objectpage::STATUS_DRAFT) { + print ''.img_picto($langs->trans($text_off), 'switch_off').''; + } else { + print ''.img_picto($langs->trans($text_off), 'switch_on').''; + } + } else { + print ajax_object_onoff($objectpage, 'status', 'status', 'Online', 'Offline', array(), 'valignmiddle', 'statuswebsitepage'); + } + //print '
'; + print '
'; + } + print ''; print ''; @@ -3059,23 +3101,18 @@ if (!GETPOST('hide_websitemenu')) { } if ($pagepreviousid) { - print ''.img_previous($langs->trans("PreviousContainer")).''; + print ''.img_previous($langs->trans("PreviousContainer")).''; } else { print ''.img_previous($langs->trans("PreviousContainer")).''; } if ($pagenextid) { - print ''.img_next($langs->trans("NextContainer")).''; + print ''.img_next($langs->trans("NextContainer")).''; } else { print ''.img_next($langs->trans("NextContainer")).''; } print ''; - $websitepage = new WebSitePage($db); - if ($pageid > 0 && ($action == 'preview' || $action == 'createfromclone' || $action == 'createpagefromclone')) { - $websitepage->fetch($pageid); - } - if ($action == 'preview' || $action == 'createfromclone' || $action == 'createpagefromclone' || $action == 'deletesite') { $disabled = ''; if (empty($user->rights->website->write)) { @@ -3153,15 +3190,15 @@ if (!GETPOST('hide_websitemenu')) { print ''; - print '   '; - - //print ''; + // Edit web page properties print ''.dol_escape_htmltag($langs->trans("EditPageMeta")).''; - //print ''; + // Edit HTML content print ''.dol_escape_htmltag($langs->trans($conf->dol_optimize_smallscreen ? "HTML" : "EditHTMLSource")).''; print ''; + + // Switch include dynamic content / edit inline print ''."\n"; print '
'; @@ -3522,13 +3559,16 @@ if ($action == 'editcss') { print ''; // Status of web site - print ''."\n"; - print ''; - print $langs->trans('Status'); - print ''; - print ajax_object_onoff($object, 'status', 'status', 'Enabled', 'Disabled'); - //print dol_print_date($pagedatecreation, 'dayhour'); - print ''; + if ($action != 'createcontainer') { + if (empty($conf->use_javascript_ajax)) { + print ''."\n"; + print ''; + print $langs->trans('Status'); + print ''; + print $form->selectyesno('status', $object->status); + print ''; + } + } // Main language print ''; @@ -3954,13 +3994,14 @@ if ($action == 'editmeta' || $action == 'createcontainer') { // Edit properties } if ($action != 'createcontainer') { - print ''."\n"; - print ''; - print $langs->trans('Status'); - print ''; - print ajax_object_onoff($objectpage, 'status', 'status', 'Enabled', 'Disabled'); - //print dol_print_date($pagedatecreation, 'dayhour'); - print ''; + if (empty($conf->use_javascript_ajax)) { + print ''."\n"; + print ''; + print $langs->trans('Status'); + print ''; + print $form->selectyesno('status', $objectpage->status); + print ''; + } } // Type of container @@ -3971,6 +4012,7 @@ if ($action == 'editmeta' || $action == 'createcontainer') { // Edit properties $formwebsite->selectTypeOfContainer('WEBSITE_TYPE_CONTAINER', (GETPOST('WEBSITE_TYPE_CONTAINER', 'alpha') ? GETPOST('WEBSITE_TYPE_CONTAINER', 'alpha') : $type_container), 0, '', 1); print ''; + // Example/templates of page if ($action == 'createcontainer') { print ''; print $langs->trans('WEBSITE_PAGE_EXAMPLE');