From 5b9757cb39d293b4b4ac0269b5df55c9ac2316ff Mon Sep 17 00:00:00 2001
From: loiclau <loic.lau@gmail.com>
Date: Wed, 16 Aug 2017 15:43:37 +0200
Subject: [PATCH] * add delete errors msg #5502

---
 .../centreon-knowledge/wikiApi.class.php      | 20 +++++++++++--------
 .../configKnowledge/templates/display.ihtml   | 11 +++++++++-
 2 files changed, 22 insertions(+), 9 deletions(-)

diff --git a/www/class/centreon-knowledge/wikiApi.class.php b/www/class/centreon-knowledge/wikiApi.class.php
index 10ad514b60..81ab654f73 100644
--- a/www/class/centreon-knowledge/wikiApi.class.php
+++ b/www/class/centreon-knowledge/wikiApi.class.php
@@ -244,16 +244,20 @@ class WikiApi
 
         $token = $this->getMethodToken('delete', $title);
 
-        $postfields = array(
-            'action' => 'delete',
-            'title' => $title,
-            'token' => $token
-        );
+        if($token){
+            $postfields = array(
+                'action' => 'delete',
+                'title' => $title,
+                'token' => $token
+            );
 
-        curl_setopt($this->curl, CURLOPT_POSTFIELDS, $postfields);
-        curl_exec($this->curl);
+            curl_setopt($this->curl, CURLOPT_POSTFIELDS, $postfields);
+            curl_exec($this->curl);
 
-        return true;
+            return true;
+        } else {
+            return false;
+        }
     }
 
     public function getAllPages()
diff --git a/www/include/configuration/configKnowledge/templates/display.ihtml b/www/include/configuration/configKnowledge/templates/display.ihtml
index 8b2e4cfc88..b4001a8f6d 100644
--- a/www/include/configuration/configKnowledge/templates/display.ihtml
+++ b/www/include/configuration/configKnowledge/templates/display.ihtml
@@ -1,4 +1,5 @@
 <script type="text/javascript" src="./include/common/javascript/tool.js"></script>
+<div id="errorMsg" class="inactive"></div>
 <form name='form' method="POST">
     <table class="ajaxOption table">
         <tr>
@@ -241,7 +242,15 @@
                 title: title
             }),
             success: function (data) {
-                location.reload()
+                if(data.result){
+                    location.reload()
+                } else {
+                    var msg = "Deletion failed, please check your wiki configuration and your wiki user rights.";
+                    var $popin = jQuery("#errorMsg");
+                    $popin.html(msg);
+                    jQuery($popin).css('display', 'block');
+                    $popin.centreonPopin("open");
+                }
             }
         });
     }
-- 
GitLab