diff --git a/config_menu.php b/config_menu.php
new file mode 100644
index 0000000..09ca707
--- /dev/null
+++ b/config_menu.php
@@ -0,0 +1,98 @@
+
+
+
+
+
+
+
KFT-Bug-Reporter configuration
+
+
+
+ moduleInstall(array
(
'application' => 'eisge_api',
- 'module' => 'Kalifast-Bug-Reporter',
+ 'module' => 'Kalifast_Bug_Reporter',
'module_desc' => 'A module to let the user create KALIFAST tickets',
'libraries' => array(
array(
@@ -31,14 +31,48 @@ function install_kalifast_bug_reporter() {
),
'modes' => array('DISPLAY', 'EDIT')
));
+
+
+ init_kalifast_bug_reporter_database();
+
}
+/* Function to init database tables */
+function init_kalifast_bug_reporter_database() {
+ // Open new PDO
+ $PDO = new PDO('mysql:host='.DB_HOST.';dbname='.DB_NAME, DB_USER, DB_PASSWORD);
+
+ // Create the table
+ $PDO->exec('CREATE TABLE IF NOT EXISTS `kalifast_bug_reporter_config` (
+ `id` int(11) NOT NULL AUTO_INCREMENT,
+ `last_update` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
+ `kft_api_host` varchar(255) NOT NULL,
+ `kft_api_key` varchar(255) NOT NULL,
+ PRIMARY KEY (`id`)
+ )');
+}
+
+/* Function to uninstall database tables */
+function uninstall_kalifast_bug_reporter_database() {
+ // Open new PDO
+ $PDO = new PDO('mysql:host='.DB_HOST.';dbname='.DB_NAME, DB_USER, DB_PASSWORD);
+
+ // Drop the table
+ $PDO->exec('DROP TABLE IF EXISTS `kalifast_bug_reporter_config`');
+}
+
+
/* Unregister the module */
function uninstall_kalifast_bug_reporter() {
$instance = new EISGE_Module_Core();
$instance->moduleUninstall(array('application' => 'eisge_api', 'module'=>'Kalifast-Bug-Reporter'));
+
+ // uninstall_kalifast_bug_reporter_database();
}
/* Setup hooks */
-add_action( 'activate_Kalifast-Bug-Reporter/module_setup.php', 'install_kalifast_bug_reporter' );
-add_action( 'deactivate_Kalifast-Bug-Reporter/module_setup.php', 'uninstall_kalifast_bug_reporter' );
+add_action( 'activate_Kalifast_Bug_Reporter/module_setup.php', 'install_kalifast_bug_reporter' );
+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');
+Hyper Icon
diff --git a/reporter.php b/reporter.php
index 2e77adf..912a53f 100644
--- a/reporter.php
+++ b/reporter.php
@@ -12,12 +12,126 @@ class Reporter extends EISGE_Library_Core {
"mode" => "EDIT",
"guest_mod" => true,
"desc" => "Send a ticket to the Kalifast Application",
+ "args" => array(
+ array(
+ "name" => "title",
+ "type" => "string",
+ "description" => "Title of the ticket"
+ ),
+ array(
+ "name" => "content",
+ "type" => "string",
+ "description" => "Content of the ticket"
+ ),
+ array(
+ "name" => "contact",
+ "type" => "string",
+ "description" => "Contact of the ticket's author"
+ ),
+ )
+ ),
+ "get_kalifast_api_configuration" => array(
+ "mode" => "DISPLAY",
+ "guest_mod" => false,
+ "desc" => "Get the Kalifast API host and key",
"args" => "no_args"
+ ),
+ "configure_kalifast_api" => array(
+ "mode" => "EDIT",
+ "guest_mod" => false,
+ "desc" => "Configure the Kalifast API host and key",
+ "args" => array(
+ array(
+ "name" => "kft_api_host",
+ "type" => "string",
+ "description" => "Host of the Kalifast App"
+ ),
+ array(
+ "name" => "kft_api_key",
+ "type" => "string",
+ "description" => "API Key of the Kalifast App"
+ ),
+ )
)
+
);
}
+
+ /**
+ * This function is called when the user wants to send a ticket to the Kalifast Application
+ */
public function post_kalifast_ticket(){
+
+ /* Check the parameters */
+ $parameters = $this->checkArguments($this->dataIn,
+ array(
+ "title" => "string",
+ "content" => "string",
+ "contact" => "string"
+ )
+ );
+ if (!$parameters) {
+ return $this->functionFailed("parameters", "Syntax error on parameters!");
+ }
+
+
return $this->functionFailed("not_implemented", "Not implemented yet!");
}
-}
\ No newline at end of file
+
+
+ /**
+ * This function is called when the user wants to get the Kalifast API host and key
+ */
+ public function get_kalifast_api_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->functionSuccess($row);
+ }
+ return $this->functionFailed("no_data", "No data found in the database");
+
+
+ } catch (PDOException $e) {
+ error_log($e->getMessage());
+ return $this->functionFailed("database_error", "Error while getting kalifast API data from the database");
+ }
+ }
+
+
+ /**
+ * This function is called when the user wants to configure the Kalifast API host and key
+ */
+ public function configure_kalifast_api(){
+
+ /* Check the parameters */
+ $parameters = $this->checkArguments($this->dataIn,
+ array(
+ "kft_api_host" => "string",
+ "kft_api_key" => "string"
+ )
+ );
+ if (!$parameters) {
+ return $this->functionFailed("parameters", "Syntax error on parameters!");
+ }
+
+
+ try {
+ $stmt = $this->PDO->prepare("DELETE FROM kalifast_bug_reporter_config");
+
+ $stmt = $this->PDO->prepare("INSERT INTO kalifast_bug_reporter_config (kft_api_host, kft_api_key) VALUES (:kft_api_host, :kft_api_key)");
+ $stmt->bindParam(':kft_api_host', $parameters["kft_api_host"]);
+ $stmt->bindParam(':kft_api_key', $parameters["kft_api_key"]);
+ $stmt->execute();
+ return $this->functionSuccess("Kalifast API data inserted into the database");
+
+ } catch (PDOException $e) {
+ error_log($e->getMessage());
+ return $this->functionFailed("database_error", "Error while inserting kalifast API data the database");
+ }
+
+ }
+}