diff --git a/create_ticket_shortcode.php b/create_ticket_shortcode.php
new file mode 100644
index 0000000..26a7518
--- /dev/null
+++ b/create_ticket_shortcode.php
@@ -0,0 +1,105 @@
+
+
+
+
+
+
+ Kalifast Bug Reporter
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/module_setup.php b/module_setup.php
index 3633390..11d5a2e 100644
--- a/module_setup.php
+++ b/module_setup.php
@@ -90,4 +90,11 @@ add_action( 'activate_Kalifast_Bug_Reporter/module_setup.php', 'install_kalifast
add_action( 'deactivate_Kalifast_Bug_Reporter/module_setup.php', 'uninstall_kalifast_bug_reporter' );
require_once(ABSPATH . '/wp-content/plugins/Kalifast_Bug_Reporter/config_menu.php');
+
+
+
+function kft_ticket_form_shortcode() {
+ include dirname(__FILE__) . '/create_ticket_shortcode.php';
+}
+add_shortcode( 'KFT_TICKET_FORM', 'kft_ticket_form_shortcode');
Hyper Icon
\ No newline at end of file
diff --git a/reporter.php b/reporter.php
index 418e599..cf1dfab 100644
--- a/reporter.php
+++ b/reporter.php
@@ -79,6 +79,40 @@ class Reporter extends EISGE_Library_Core {
);
}
+
+ private function call_kft_app($url, $key, $host, $map_fields = false, $params = false) {
+ $url = $host."/api/".$key."/".$url;
+ $ch = curl_init($url);
+ curl_setopt($ch, CURLOPT_POST, 1);
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+
+ if($params) {
+
+ curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(array("json" => json_encode($params))));
+ }
+
+
+ $response = json_decode(curl_exec($ch), true);
+ curl_close($ch);
+
+ if(!$map_fields) {
+ return $response;
+ }
+ if($response["success"]) {
+ $response["data"] = array_map(function($item) use ($map_fields) {
+ $new_item = array();
+ foreach($map_fields as $field) {
+ $new_item[$field] = $item[$field];
+ }
+ return $new_item;
+ }, $response["data"]);
+ return $response["data"];
+ } else {
+ return false;
+ }
+ }
+
+
/**
* This function is called when the user wants to send a ticket to the Kalifast Application
@@ -97,8 +131,54 @@ class Reporter extends EISGE_Library_Core {
return $this->functionFailed("parameters", "Syntax error on parameters!");
}
-
- return $this->functionFailed("not_implemented", "Not implemented yet!");
+ // get the configuration
+ try {
+ $stmt = $this->PDO->prepare("SELECT kft_api_host, kft_api_key FROM kalifast_bug_reporter_config ORDER BY last_update DESC LIMIT 1");
+ $stmt->execute();
+ $row = $stmt->fetch(PDO::FETCH_ASSOC);
+ if(!$row) {
+ return $this->functionFailed("no_data", "No data found in the database");
+ }
+ $api_url = $row["kft_api_host"];
+ $api_key = $row["kft_api_key"];
+
+ $stmt = $this->PDO->prepare("SELECT ei_pool_id, ei_delivery_id, ei_user_id FROM kalifast_bug_reporter_config_ticket ORDER BY last_update DESC LIMIT 1");
+ $stmt->execute();
+ $ticket_config = $stmt->fetch(PDO::FETCH_ASSOC);
+ if(!$ticket_config) {
+ return $this->functionFailed("no_data", "No data found in the database");
+ }
+ $ei_pool_id = $ticket_config["ei_pool_id"];
+ $ei_delivery_id = $ticket_config["ei_delivery_id"];
+ $ei_user_id = $ticket_config["ei_user_id"];
+
+ } catch (PDOException $e) {
+ error_log($e->getMessage());
+ return $this->functionFailed("database_error", "Error while getting kalifast API data from the database");
+ }
+
+ // Send the ticket to the Kalifast Application
+ $url = $api_url."/api/".$api_key."SUBJECT/MAIN/EDIT/CORE/CREATENEWSUBJECT";
+ $json_array = array(
+ "title" => $parameters["title"],
+ "description" => "Ticket from ".$parameters["contact"] . " : " .$parameters["content"],
+ "delivery_id" => $ei_delivery_id,
+ "type_id" => "1",
+ "priority_id" => "1",
+ "in_charge_id" => $ei_user_id,
+ "status_id" => "1",
+ "pool_id" => $ei_pool_id,
+ "ei_subject_external_id" => "",
+ "risk_list" => array()
+ );
+ error_log (json_encode($json_array));
+ $response = $this->call_kft_app("SUBJECT/MAIN/EDIT/CORE/CREATENEWSUBJECT", $api_key, $api_url, false, $json_array);
+
+ if($response["success"]) {
+ return $this->functionSuccess("Ticket created");
+ } else {
+ return $this->functionFailed("kft_error", "Error while sending the ticket to the Kalifast Application");
+ }
}
@@ -131,31 +211,9 @@ class Reporter extends EISGE_Library_Core {
error_log($e->getMessage());
return $this->functionFailed("database_error", "Error while inserting kalifast ticket data the database");
}
-
-
}
- private function call_kft_app($url, $key, $host, $map_fields) {
- $url = $host."/api/".$key."/".$url;
- $ch = curl_init($url);
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- $response = json_decode(curl_exec($ch), true);
- curl_close($ch);
- if($response["success"]) {
- $response["data"] = array_map(function($item) use ($map_fields) {
- $new_item = array();
- foreach($map_fields as $field) {
- $new_item[$field] = $item[$field];
- }
- return $new_item;
- }, $response["data"]);
- return $response["data"];
- } else {
- return false;
- }
- }
/**
* This function is called when the user wants to get the Kalifast API host and key