diff --git a/Controller/SupportAppController.php b/Controller/SupportAppController.php
new file mode 100644
index 0000000..e4b5235
--- /dev/null
+++ b/Controller/SupportAppController.php
@@ -0,0 +1,40 @@
+loadModel("Support.SettingsSupport");
+ $discordWebhook = $this->SettingsSupport->find("first");
+ if (empty($discordWebhook) || empty($discordWebhook["SettingsSupport"]["discord_webhook"]))
+ return false;
+
+ $discordWebhook = explode("/", $discordWebhook["SettingsSupport"]["discord_webhook"]);
+ $webhookData = [
+ "id" => $discordWebhook[5],
+ "token" => $discordWebhook[6]
+ ];
+
+ $handle = curl_init("https://discord.com/api/webhooks/" . $webhookData["id"] . "/" . $webhookData["token"]);
+
+ $data = json_encode([
+ "content" => $msg,
+ "embeds" => $embedData
+ ]);
+
+ curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
+ curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, false);
+ curl_setopt($handle, CURLOPT_POST, true);
+ curl_setopt($handle, CURLOPT_HEADER, true);
+ curl_setopt($handle, CURLOPT_HTTPHEADER,
+ array(
+ 'Content-Type:application/json',
+ 'Content-Length: ' . strlen($data)
+ )
+ );
+ curl_setopt($handle, CURLOPT_POSTFIELDS, $data);
+
+ $res = curl_exec($handle);
+ return true;
+ }
+}
+
diff --git a/Controller/SupportController.php b/Controller/SupportController.php
index 3ce22a8..c485fe0 100644
--- a/Controller/SupportController.php
+++ b/Controller/SupportController.php
@@ -1,6 +1,6 @@
layout = 'admin';
- if (!$this->Permissions->can('SETTINGS_SUPPORT'))
+ if (!$this->Permissions->can('PERMISSIONS__SETTINGS_SUPPORT'))
throw new ForbiddenException();
- $this->set('title_for_layout', $this->Lang->get('SUPPORT__SETTINGS_TITLE') . ' - ' . $this->Lang->get('SUPPORT__SUPPORT'));
+
$this->loadModel('Support.SettingsSupport');
+ if ($this->request->is('post')) {
+ if (!isset($this->request->data["webhook"])) {
+ return $this->sendJSON(['statut' => false, 'msg' => $this->Lang->get('ERROR__FILL_ALL_FIELDS')]);
+ }
+
+ $settings = $this->SettingsSupport->find('first');
+ if (!$settings) {
+ $this->SettingsSupport->create([
+ "discord_webhook" => $this->request->data["webhook"]
+ ]);
+ } else {
+ $this->SettingsSupport->read(null, $settings["SettingsSupport"]["id"]);
+ $this->SettingsSupport->set([
+ "discord_webhook" => $this->request->data["webhook"]
+ ]);
+ }
+
+ $this->SettingsSupport->save();
+ $this->Session->setFlash($this->Lang->get('CONFIG__EDIT_SUCCESS'), 'default.success');
+ $this->redirect("/admin/support/config");
+ }
+
+ $this->set('title_for_layout', $this->Lang->get('SUPPORT__SETTINGS_TITLE') . ' - ' . $this->Lang->get('SUPPORT__SUPPORT'));
$settings = $this->SettingsSupport->find('first');
+ if ($settings) {
+ $settings = $settings["SettingsSupport"];
+ }
+
$this->set(compact('settings'));
}
@@ -222,6 +249,17 @@ function ajax_create()
));
$this->Ticket->save();
$this->Notification->setToAdmin($this->User->getKey('pseudo') . ' ' . $this->Lang->get('SUPPORT__NOTIF_CREATE'));
+
+ $this->loadModel("Support.CategoriesSupport");
+ $categorieName = $this->CategoriesSupport->find("first", ["conditions" => ["id" => $this->request->data['categorie']]])["CategoriesSupport"]["name"];
+ $this->sendDiscordMessage("", [array(
+ "title" => "SUPPORT: Nouveau ticket par " . $this->User->getKey("pseudo"),
+ "color" => "3447003",
+ "description" => $this->Lang->get('SUPPORT__DISCORD_EMBED_CREATE_DESCRIPTION',
+ ['{SUBJECT_NAME}' => $this->request->data['subject'], '{CATEGORIE_NAME}' => $categorieName]
+ )
+ )]);
+
$this->sendJSON(['statut' => true, 'msg' => $this->Lang->get('SUPPORT__SUCCESS_CREATE')]);
}
diff --git a/SQL/schema.php b/SQL/schema.php
index b46768e..bd26c98 100755
--- a/SQL/schema.php
+++ b/SQL/schema.php
@@ -35,6 +35,7 @@ public function after($event = array()) {
public $support__settings = array(
'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'unsigned' => false, 'key' => 'primary'),
'suffix_reply' => array('type' => 'text', 'null' => true, 'default' => null, 'collate' => 'latin1_swedish_ci', 'charset' => 'latin1'),
+ 'discord_webhook' => array('type' => 'text', 'null' => true, 'default' => null, 'collate' => 'latin1_swedish_ci', 'charset' => 'latin1'),
'indexes' => array(
'PRIMARY' => array('column' => 'id', 'unique' => 1)
),
diff --git a/View/Support/admin_config.ctp b/View/Support/admin_config.ctp
index 41c9cd5..3435ff0 100644
--- a/View/Support/admin_config.ctp
+++ b/View/Support/admin_config.ctp
@@ -1,12 +1,18 @@
-
= $Lang->get('SUPPORT__SETTINGS_TITLE'); ?>