From 682d680d2aa75f8e585e80dbc4d9653a05246534 Mon Sep 17 00:00:00 2001 From: Xenomporio <> Date: Sat, 25 Jun 2022 11:33:55 +0200 Subject: [PATCH] module creator improvements layout .tpl fix --- tools/module_creator/module_creator.php | 60 +++++++++--- tools/module_creator/module_creator_edit.tpl | 93 ++++++++++--------- .../module_creator_php_template.txt | 17 ++-- 3 files changed, 103 insertions(+), 67 deletions(-) diff --git a/tools/module_creator/module_creator.php b/tools/module_creator/module_creator.php index d906da20..60570aa9 100644 --- a/tools/module_creator/module_creator.php +++ b/tools/module_creator/module_creator.php @@ -25,9 +25,20 @@ $user = 'xenomporiodev'; $passwd = 'xenomporiodev'; $schema = 'xenomporiodev'; -if ($argc == 2) { +if ($argc >= 2) { - $module_name = $argv[1]; + if (in_array('-v', $argv)) { + $verbose = true; + } else { + $verbose = false; + } + + if (!str_starts_with($argv[1],'-')) { + $module_name = $argv[1]; + } else { + info(); + exit; + } $module_class_name = ucfirst($module_name); $php_file_name = $module_name . ".php"; $php_template_file_name = "module_creator_php_template.txt"; @@ -109,6 +120,9 @@ if ($argc == 2) { $list_of_columns = implode(', ', $columns); $list_of_columns_in_quotes = "'" . implode('\', \'', $columns) . "'"; + $get_input = ""; + $set_input = ""; + foreach ($columns as $column) { $get_input = $get_input . "\$input['$column'] = \$this->app->Secure->GetPOST('$column');\n\t"; $set_input = $set_input . "\$this->app->Tpl->Set('" . strtoupper($column) . "', \$input['$column']);\n\t"; @@ -132,10 +146,6 @@ if ($argc == 2) { $php_file_contents = str_replace('PLACEHOLDER_SET_INPUT', $set_input, $php_file_contents); $php_file_contents = str_replace('PLACEHOLDER_COLUMNS', $list_of_columns_in_quotes, $php_file_contents); - if ($verbose) { - echo($php_file_contents); - } - $php_file = fopen($target_php_folder . $php_file_name, "w"); if (empty($php_file)) { echo ("Failed to write to " . $target_php_folder . $php_file_name); @@ -153,9 +163,6 @@ if ($argc == 2) { fclose($php_file); $list_template_contents = file_get_contents("module_creator_list.tpl"); - if ($verbose) { - echo($list_template_contents); - } fwrite($template_list_file, $list_template_contents); fclose($template_list_file); @@ -163,18 +170,45 @@ if ($argc == 2) { $edit_template_contents = str_replace('PLACEHOLDER_LEGEND', "".$module_name, $edit_template_contents); $edit_template_contents = str_replace('PLACEHOLDER_FIELDS', $edit_form, $edit_template_contents); - if ($verbose) { - echo($edit_template_contents); - } fwrite($template_edit_file, $edit_template_contents); fclose($template_edit_file); echo("\n\nCreated module files: \n"); echo ($target_php_folder . $php_file_name . "\n"); + if ($verbose) { + echo("-----------\n\n"); + echo($php_file_contents); + echo("-----------\n\n"); + } + echo ($target_tpl_folder . $template_list_file_name . "\n"); + if ($verbose) { + echo("-----------\n\n"); + echo($list_template_contents); + echo("-----------\n\n"); + } + echo ($target_tpl_folder . $template_edit_file_name . "\n"); + if ($verbose) { + echo("-----------\n\n"); + echo($edit_template_contents); + echo("-----------\n\n"); + } + } else { - echo("Wrong parameters\n"); + info(); + exit; +} + +function info() { + echo("\nXenomporio module creator\n"); + echo("Copyright 2022 (c) Xenomporio project\n\n"); + echo("Create a module.php file, a template for listing and a template for editing, based on a SQL table\n"); + echo("\n"); + echo("arg1: SQL table name\n"); + echo("Options\n"); + echo("\t-v: verbose output\n"); + echo("\n"); } diff --git a/tools/module_creator/module_creator_edit.tpl b/tools/module_creator/module_creator_edit.tpl index af03696e..b0f3ca48 100644 --- a/tools/module_creator/module_creator_edit.tpl +++ b/tools/module_creator/module_creator_edit.tpl @@ -1,49 +1,56 @@ - -
- + + + --> + diff --git a/tools/module_creator/module_creator_php_template.txt b/tools/module_creator/module_creator_php_template.txt index 0d3ee704..c8b3fafb 100644 --- a/tools/module_creator/module_creator_php_template.txt +++ b/tools/module_creator/module_creator_php_template.txt @@ -14,14 +14,11 @@ class PLACEHOLDER_MODULECLASSNAME { return; $this->app->ActionHandlerInit($this); - $this->app->ActionHandler("list", "PLACEHOLDER_LIST"); $this->app->ActionHandler("create", "PLACEHOLDER_EDIT"); // This automatically adds a "New" button $this->app->ActionHandler("edit", "PLACEHOLDER_EDIT"); $this->app->ActionHandler("delete", "PLACEHOLDER_DELETE"); - $this->app->DefaultActionHandler("list"); - $this->app->ActionHandlerListen($app); } @@ -46,10 +43,9 @@ class PLACEHOLDER_MODULECLASSNAME { $sql = "PLACEHOLDER_SQL_LIST"; - $where = "1 -"; -// $groupby = ""; + $where = "1"; $count = "SELECT count(DISTINCT id) FROM PLACEHOLDER_MODULENAME WHERE $where"; +// $groupby = ""; break; } @@ -57,8 +53,9 @@ class PLACEHOLDER_MODULECLASSNAME { $erg = false; foreach ($erlaubtevars as $k => $v) { - if (isset($$v)) + if (isset($$v)) { $erg[$v] = $$v; + } } return $erg; } @@ -130,8 +127,7 @@ class PLACEHOLDER_MODULECLASSNAME { $sql = "INSERT INTO PLACEHOLDER_MODULENAME (".$columns.") VALUES (".$values.") ON DUPLICATE KEY UPDATE ".$update; - - echo($sql); +// echo($sql); $this->app->DB->Update($sql); @@ -150,8 +146,7 @@ class PLACEHOLDER_MODULECLASSNAME { foreach ($result[0] as $key => $value) { $this->app->Tpl->Set(strtoupper($key), $value); } - - + /* * Add displayed items later *