From 3045449dbbd0a3b9358276ed0e2c2d0e4650bec1 Mon Sep 17 00:00:00 2001
From: Laurent Destailleur <eldy@destailleur.fr>
Date: Sun, 1 May 2016 17:01:38 +0200
Subject: [PATCH] Work on website module. Can delete a page.

---
 htdocs/langs/en_US/website.lang |  3 ++-
 htdocs/theme/eldy/style.css.php | 33 ++++++++++----------------
 htdocs/theme/md/style.css.php   |  8 ++++++-
 htdocs/websites/index.php       | 41 ++++++++++++++++++++++++++++++++-
 4 files changed, 61 insertions(+), 24 deletions(-)

diff --git a/htdocs/langs/en_US/website.lang b/htdocs/langs/en_US/website.lang
index 668ec7b3c07..3a09f226eb0 100644
--- a/htdocs/langs/en_US/website.lang
+++ b/htdocs/langs/en_US/website.lang
@@ -15,4 +15,5 @@ EditPageContent=Edit Content
 Website=Web site
 AddPage=Add page
 Page=Page
-PreviewOfSiteNotYetAvailable=Preview of your website <strong>%s</strong> not yet available. You must first add a page.
\ No newline at end of file
+PreviewOfSiteNotYetAvailable=Preview of your website <strong>%s</strong> not yet available. You must first add a page.
+PageDeleted=Page %s of website %s deleted
\ No newline at end of file
diff --git a/htdocs/theme/eldy/style.css.php b/htdocs/theme/eldy/style.css.php
index c33489e46fe..162310f4697 100644
--- a/htdocs/theme/eldy/style.css.php
+++ b/htdocs/theme/eldy/style.css.php
@@ -350,7 +350,7 @@ legend { margin-bottom: 8px; }
 fieldset { border: 1px solid #AAAAAA !important; }
 
 
-.button, input[name="sbmtConnexion"] {
+.button, .buttonDelete, input[name="sbmtConnexion"] {
     font-family: <?php print $fontlist ?>;
 	border-color: #c5c5c5;
 	border-color: rgba(0, 0, 0, 0.15) rgba(0, 0, 0, 0.15) rgba(0, 0, 0, 0.25);
@@ -383,17 +383,17 @@ fieldset { border: 1px solid #AAAAAA !important; }
 	-moz-box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2), 0 1px 2px rgba(0, 0, 0, 0.05);
 	box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2), 0 1px 2px rgba(0, 0, 0, 0.05);
 }
-.button:focus  {
+.button:focus, .buttonDelete:focus  {
 	-moz-box-shadow: 0px 0px 6px 1px rgba(0, 0, 60, 0.2), 0px 0px 0px rgba(60,60,60,0.1);
 	-webkit-box-shadow: 0px 0px 6px 1px rgba(0, 0, 60, 0.2), 0px 0px 0px rgba(60,60,60,0.1);
 	box-shadow: 0px 0px 6px 1px rgba(0, 0, 60, 0.2), 0px 0px 0px rgba(60,60,60,0.1);
 }
-.button:hover   {
+.button:hover, .buttonDelete:hover   {
 	-moz-box-shadow: 0px 0px 6px 1px rgba(0, 0, 0, 0.2), 0px 0px 0px rgba(60,60,60,0.1);
 	-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 {
+.button:disabled, .buttonDelete:disabled {
 	opacity: 0.4;
     filter: alpha(opacity=40); /* For IE8 and earlier */
     box-shadow: none;
@@ -1907,31 +1907,16 @@ span.butAction, span.butActionDelete {
 }
 
 .butAction:hover   {
-/*  for bootstrap look
-  color: #fff;
-  background-color: #286090;
-  border-color: #204d74;
-*/
   -moz-box-shadow: 0px 0px 6px 1px rgba(0, 0, 0, 0.2), 0px 0px 0px rgba(60,60,60,0.1);
   -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);
 }
 
-.butActionDelete, .butActionDelete:link, .butActionDelete:visited, .butActionDelete:hover, .butActionDelete:active {
-/* for bootstrap look
-  color: #fff;
-  background-color: #d9534f;
-  border-color: #d43f3a;
-*/
-   color: #800;
+.butActionDelete, .butActionDelete:link, .butActionDelete:visited, .butActionDelete:hover, .butActionDelete:active, .buttonDelete {
+   color: #800 !important;
 }
 
 .butActionDelete:hover {
-/*  for bootstrap look
-  color: #fff;
-  background-color: #c9302c;
-  border-color: #ac2925;
-*/
   -moz-box-shadow: 0px 0px 6px 1px rgba(0, 0, 0, 0.2), 0px 0px 0px rgba(60,60,60,0.1);
   -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);
@@ -3128,6 +3113,12 @@ td.hidden {
 	border-bottom: 1px solid #888;
 	background: #eee;
 }
+.websitebar .button, .websitebar .buttonDelete 
+{
+	padding: 2px 5px 3px 5px !important;
+	margin: 2px 4px 2px 4px  !important;
+    line-height: normal;
+}
 .websiteselection {
 	display: inline-block;
 	padding-left: 10px;
diff --git a/htdocs/theme/md/style.css.php b/htdocs/theme/md/style.css.php
index 58629477e76..3de39efb50f 100644
--- a/htdocs/theme/md/style.css.php
+++ b/htdocs/theme/md/style.css.php
@@ -1913,7 +1913,7 @@ span.butAction, span.butActionDelete {
     background-repeat: repeat-x    
 }
    
-.butActionDelete {
+.butActionDelete, .buttonDelete {
 	color: #ffffff !important;
 	text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.25);
 	background-color: #cc6d00;
@@ -2990,6 +2990,12 @@ td.hidden {
 	border-bottom: 1px solid #888;
 	background: #eee;
 }
+.websitebar .button, .websitebar .buttonDelete 
+{
+	padding: 2px 4px 2px 4px !important;
+	margin: 2px 4px 2px 4px  !important;
+    line-height: normal;
+}
 .websiteselection {
 	display: inline-block;
 	padding-left: 10px;
diff --git a/htdocs/websites/index.php b/htdocs/websites/index.php
index ea03c9fd7b7..0696c28c86d 100644
--- a/htdocs/websites/index.php
+++ b/htdocs/websites/index.php
@@ -81,6 +81,7 @@ $page=GETPOST('page', 'alpha');
 $pageid=GETPOST('pageid', 'alpha');
 $action=GETPOST('action','alpha');
 
+if (GETPOST('delete')) { $action='delete'; }
 if (GETPOST('preview')) $action='preview';
 if (GETPOST('create')) { $action='create'; }
 if (GETPOST('editmedia')) { $action='editmedia'; }
@@ -110,7 +111,7 @@ if ($website)
 {
     $res = $object->fetch(0, $website);
 }
-if ($pageid)
+if ($pageid && $action != 'add')
 {
     $res = $objectpage->fetch($pageid);
 }
@@ -207,6 +208,43 @@ if ($action == 'update')
     }
 }
 
+// Update page
+if ($action == 'delete')
+{
+    $db->begin();
+
+    $res = $object->fetch(0, $website);
+
+    $res = $objectpage->fetch($pageid, $object->fk_website);
+
+    if ($res > 0)
+    {
+        $res = $objectpage->delete($user);
+        if (! $res > 0)
+        {
+            $error++;
+            setEventMessages($objectpage->error, $objectpage->errors, 'errors');
+        }
+
+        if (! $error)
+        {
+            $db->commit();
+            setEventMessages($langs->trans("PageDeleted", $objectpage->pageurl, $website), null, 'mesgs');
+            
+            header("Location: ".$_SERVER["PHP_SELF"].'?website='.$website);
+            exit;
+        }
+        else
+        {
+            $db->rollback();
+        }
+    }
+    else
+    {
+        dol_print_error($db);
+    }
+}
+
 // Update css
 if ($action == 'updatecss')
 {
@@ -442,6 +480,7 @@ if (count($object->records) > 0)
         $out.='</select>';
         print $out;
         print '<input type="submit" class="button" name="refresh" value="'.$langs->trans("Refresh").'">';
+        print '<input type="submit" class="buttonDelete" name="delete" value="'.$langs->trans("Delete").'">';
         //print $form->selectarray('page', $array);
         print '</div>';
         print '<div class="websiteselection">';
-- 
GitLab