diff --git a/htdocs/langs/en_US/website.lang b/htdocs/langs/en_US/website.lang index 816dae7e4a2..ebbcadaf944 100644 --- a/htdocs/langs/en_US/website.lang +++ b/htdocs/langs/en_US/website.lang @@ -18,6 +18,7 @@ EditPageMeta=Edit Meta EditPageSource=Edit HTML Source EditPageContent=Edit with CKEditor Website=Web site +AddWebsite=Add website Webpage=Web page/container AddPage=Add page/container HomePage=Home Page @@ -49,3 +50,4 @@ WebsiteId=Website ID CreateByFetchingExternalPage=Create page/container by fetching page from external URL... OrEnterPageInfoManually=Or create empty page from scratch... FetchAndCreate=Fetch and Create +ExportSite=Export site diff --git a/htdocs/websites/index.php b/htdocs/websites/index.php index 85752a3158f..c48e81c9e03 100644 --- a/htdocs/websites/index.php +++ b/htdocs/websites/index.php @@ -96,6 +96,7 @@ $action=GETPOST('action','alpha'); if (GETPOST('delete')) { $action='delete'; } if (GETPOST('preview')) $action='preview'; +if (GETPOST('createsite')) { $action='createsite'; } if (GETPOST('create')) { $action='create'; } if (GETPOST('editmedias')) { $action='editmedias'; } if (GETPOST('editcss')) { $action='editcss'; } @@ -155,9 +156,67 @@ $urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain * Actions */ -if (GETPOST('refreshsite')) $pageid=0; // If we change the site, we reset the pageid. +if (GETPOST('refreshsite')) // If we change the site, we reset the pageid and cancel addsite action. +{ + $pageid=0; + if ($action == 'addsite') $action = 'preview'; +} if (GETPOST('refreshpage') && ! in_array($action, array('updatecss'))) $action='preview'; + +// Add site +if ($action == 'addsite') +{ + $db->begin(); + + if (! $error && empty(GETPOST('WEBSITE_REF','alpha'))) + { + $error++; + setEventMessages($langs->transnoentities("ErrorFieldRequired", $langs->transnoentities("Ref")), null, 'errors'); + } + if (! $error && ! preg_match('/^[a-z0-9_\-\.]+$/i', GETPOST('WEBSITE_REF','alpha'))) + { + $error++; + setEventMessages($langs->transnoentities("ErrorFieldCanNotContainSpecialCharacters", $langs->transnoentities("Ref")), null, 'errors'); + } + + if (! $error) + { + $tmpobject=new Website($db); + $tmpobject->ref = GETPOST('WEBSITE_REF','alpha'); + $tmpobject->description = GETPOST('WEBSITE_DESCRIPTION','alpha'); + $tmpobject->virtualhost = GETPOST('WEBSITE_VIRTUALHOST','alpha'); + + $result = $tmpobject->create($user); + if ($result <= 0) + { + $error++; + setEventMessages($tmpobject->error, $tmpobject->errors, 'errors'); + } + } + + if (! $error) + { + $db->commit(); + setEventMessages($langs->trans("SiteAdded", $object->ref), null, 'mesgs'); + $action=''; + + header("Location: ".$_SERVER["PHP_SELF"].'?website='.$tmpobject->ref); + exit; + } + else + { + $db->rollback(); + $action='createsite'; + } + + if (! $error) + { + $action = 'preview'; + $id = $object->id; + } +} + // Add page if ($action == 'add') { @@ -820,6 +879,10 @@ llxHeader('', $langs->trans("WebsiteSetup"), $help_url, '', 0, 0, print "\n".'