From c1337a4318cd2fe4b4748cb17dd1f16cb0dd4d99 Mon Sep 17 00:00:00 2001
From: Jose Gonzalez <jose.gonzalez@artica.es>
Date: Tue, 17 Mar 2020 18:27:56 +0100
Subject: [PATCH] WIP: Backup upload

---
 .../modules/manage_block_templates.php        | 11 ++--
 .../include/class/ManageBlock.class.php       | 59 +++++++++++++++++--
 2 files changed, 60 insertions(+), 10 deletions(-)

diff --git a/pandora_console/godmode/modules/manage_block_templates.php b/pandora_console/godmode/modules/manage_block_templates.php
index 540dc7b5b3..d1ec375f86 100644
--- a/pandora_console/godmode/modules/manage_block_templates.php
+++ b/pandora_console/godmode/modules/manage_block_templates.php
@@ -13,10 +13,9 @@
 // GNU General Public License for more details.
 // Load global vars
 // TESTING
-/*
     ini_set('display_errors', 1);
     ini_set('display_startup_errors', 1);
-error_reporting(E_ALL); */
+error_reporting(E_ALL);
 $cipotes = false;
 // END
 global $config;
@@ -74,13 +73,13 @@ if (is_ajax()) {
     // Run.
     $manageBlock->run();
 
-    // List all Module Block
-    // Show the id_np selected
-    // Create new id_np
     if ($id_np == 0) {
+        // Create new id_np
         $manageBlock->moduleTemplateForm();
-        echo 'hola';
+    } else if ($id_np > 0) {
+        // Show the id_np selected
     } else {
+        // List all Module Block
         $manageBlock->moduleBlockList();
     }
 }
diff --git a/pandora_console/include/class/ManageBlock.class.php b/pandora_console/include/class/ManageBlock.class.php
index 7dba375d0e..e69898321d 100644
--- a/pandora_console/include/class/ManageBlock.class.php
+++ b/pandora_console/include/class/ManageBlock.class.php
@@ -63,6 +63,13 @@ class ManageBlock extends HTML
      */
     private $resultModuleBlocksTable;
 
+    /**
+     * Base URL for internal purposes
+     *
+     * @var string
+     */
+    private $baseUrl;
+
 
     /**
      * Constructor
@@ -108,6 +115,9 @@ class ManageBlock extends HTML
 
         $this->ajaxController = $ajax_controller;
 
+        // Set baseUrl for use it in several locations in this class
+        $this->baseUrl = 'index.php?sec=gmodules&sec2=godmode/modules/manage_block_templates';
+
         return $this;
     }
 
@@ -206,7 +216,7 @@ class ManageBlock extends HTML
         foreach ($this->resultModuleBlocksTable as $row) {
             $data = [];
             $data[0] = html_print_checkbox_extended('delete_multiple[]', $row['id_np'], false, false, '', 'class="check_delete"', true);
-            $data[1] = '<a href="index.php?sec=gmodules&amp;sec2=godmode/modules/manage_block_templates&amp;id_np='.$row['id_np'].'">'.io_safe_output($row['name']).'</a>';
+            $data[1] = '<a href="'.$this->baseUrl.'&amp;id_np='.$row['id_np'].'">'.io_safe_output($row['name']).'</a>';
             $data[2] = ui_print_truncate_text(io_safe_output($row['description']), 'description', true, true, true, '[&hellip;]');
             $table->cellclass[][3] = 'action_buttons';
             $data[3] = html_print_input_image(
@@ -225,12 +235,14 @@ class ManageBlock extends HTML
                 true,
                 ['title' => 'Export to CSV']
             );
-            $data[3] = '<a href="index.php?sec=gmodules&sec2=godmode/modules/manage_block_templates'.'&delete_profile=1&delete_profile='.$row['id_np'].'" '.'onclick="if (!confirm(\''.__('Are you sure?').'\')) return false;">'.html_print_image('images/cross.png', true, ['title' => __('Delete')]).'</a>';
-            $data[3] .= '<a href="index.php?sec=gmodules&sec2=godmode/modules/manage_block_templates'.'&export_profile='.$row['id_np'].'">'.html_print_image('images/csv.png', true, ['title' => __('Export to CSV')]).'</a>';
+            $data[3] = '<a href="'.$this->baseUrl.'&delete_profile=1&delete_profile='.$row['id_np'].'" '.'onclick="if (!confirm(\''.__('Are you sure?').'\')) return false;">'.html_print_image('images/cross.png', true, ['title' => __('Delete')]).'</a>';
+            $data[3] .= '<a href="'.$this->baseUrl.'&export_profile='.$row['id_np'].'">'.html_print_image('images/csv.png', true, ['title' => __('Export to CSV')]).'</a>';
 
             array_push($table->data, $data);
         }
 
+        // Sé que los echo son basurientos, pero de momento, me valen para ir montando
+        // LOS QUITARÉ, PROMESA DE CORONAVIRUS
         echo html_print_table($table, true);
 
         echo '<div style="float:right;" class="">';
@@ -239,7 +251,7 @@ class ManageBlock extends HTML
             [
                 'form'   => [
                     'method' => 'POST',
-                    'action' => 'index.php?sec=gmodules&amp;sec2=godmode/modules/manage_block_templates',
+                    'action' => $this->baseUrl,
                 ],
                 'inputs' => [
                     [
@@ -260,4 +272,43 @@ class ManageBlock extends HTML
     }
 
 
+    /**
+     * Prints Form for template
+     *
+     * @param  integer $id_np If not carried
+     * @return void
+     */
+    public function moduleTemplateForm(int $id_np=0)
+    {
+        if ($id_np == 0) {
+            $formButtonName = 'crt';
+            $formButtonLabel = __('Create');
+        } else {
+            $formButtonName = 'upd';
+            $formButtonLabel = __('Update');
+        }
+
+        $this->printForm(
+            [
+                'form'   => [
+                    'method' => 'POST',
+                    'action' => $this->baseUrl,
+                ],
+                'inputs' => [
+                    [
+                        'class'     => 'w100p',
+                        'arguments' => [
+                            'name'       => $formButtonName,
+                            'label'      => $formButtonLabel,
+                            'type'       => 'submit',
+                            'attributes' => 'class="sub next"',
+                            'return'     => true,
+                        ],
+                    ],
+                ],
+            ]
+        );
+    }
+
+
 }