module creator improvements layout .tpl fix

This commit is contained in:
Xenomporio 2022-06-25 11:33:55 +02:00
parent a80e69efa2
commit 682d680d2a
3 changed files with 103 additions and 67 deletions

View File

@ -25,9 +25,20 @@ $user = 'xenomporiodev';
$passwd = 'xenomporiodev'; $passwd = 'xenomporiodev';
$schema = '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); $module_class_name = ucfirst($module_name);
$php_file_name = $module_name . ".php"; $php_file_name = $module_name . ".php";
$php_template_file_name = "module_creator_php_template.txt"; $php_template_file_name = "module_creator_php_template.txt";
@ -109,6 +120,9 @@ if ($argc == 2) {
$list_of_columns = implode(', ', $columns); $list_of_columns = implode(', ', $columns);
$list_of_columns_in_quotes = "'" . implode('\', \'', $columns) . "'"; $list_of_columns_in_quotes = "'" . implode('\', \'', $columns) . "'";
$get_input = "";
$set_input = "";
foreach ($columns as $column) { foreach ($columns as $column) {
$get_input = $get_input . "\$input['$column'] = \$this->app->Secure->GetPOST('$column');\n\t"; $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"; $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_SET_INPUT', $set_input, $php_file_contents);
$php_file_contents = str_replace('PLACEHOLDER_COLUMNS', $list_of_columns_in_quotes, $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"); $php_file = fopen($target_php_folder . $php_file_name, "w");
if (empty($php_file)) { if (empty($php_file)) {
echo ("Failed to write to " . $target_php_folder . $php_file_name); echo ("Failed to write to " . $target_php_folder . $php_file_name);
@ -153,9 +163,6 @@ if ($argc == 2) {
fclose($php_file); fclose($php_file);
$list_template_contents = file_get_contents("module_creator_list.tpl"); $list_template_contents = file_get_contents("module_creator_list.tpl");
if ($verbose) {
echo($list_template_contents);
}
fwrite($template_list_file, $list_template_contents); fwrite($template_list_file, $list_template_contents);
fclose($template_list_file); fclose($template_list_file);
@ -163,18 +170,45 @@ if ($argc == 2) {
$edit_template_contents = str_replace('PLACEHOLDER_LEGEND', "<!--Legend for this form area goes here>-->".$module_name, $edit_template_contents); $edit_template_contents = str_replace('PLACEHOLDER_LEGEND', "<!--Legend for this form area goes here>-->".$module_name, $edit_template_contents);
$edit_template_contents = str_replace('PLACEHOLDER_FIELDS', $edit_form, $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); fwrite($template_edit_file, $edit_template_contents);
fclose($template_edit_file); fclose($template_edit_file);
echo("\n\nCreated module files: \n"); echo("\n\nCreated module files: \n");
echo ($target_php_folder . $php_file_name . "\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"); 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"); echo ($target_tpl_folder . $template_edit_file_name . "\n");
if ($verbose) {
echo("-----------\n\n");
echo($edit_template_contents);
echo("-----------\n\n");
}
} else { } 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");
} }

View File

@ -1,49 +1,56 @@
<!-- Example for multiple tabs
<div id="tabs"> <div id="tabs">
<ul> <ul>
<li><a href="#tabs-1">First Tab</a></li> <li><a href="#tabs-1"></a></li>
<li><a href="#tabs-2">Second Tab</a></li> </ul>
</ul> <!-- Example for multiple tabs
--> <ul hidden">
<form action="" method="post"> <li><a href="#tabs-1">First Tab</a></li>
<li><a href="#tabs-2">Second Tab</a></li>
</ul>
-->
<div id="tabs-1"> <div id="tabs-1">
[MESSAGE] [MESSAGE]
<div class="row"> <form action="" method="post">
<div class="row-height"> [FORMHANDLEREVENT]
<div class="col-xs-12 col-md-12 col-md-height"> <div class="row">
<div class="inside inside-full-height"> <div class="row-height">
<fieldset> <div class="col-xs-12 col-md-12 col-md-height">
<legend>{|PLACEHOLDER_LEGEND|}</legend> <div class="inside inside-full-height">
<table width="100%" border="0" class="mkTableFormular"> <fieldset>
PLACEHOLDER_FIELDS <legend>{|PLACEHOLDER_LEGEND|}</legend>
</table> <table width="100%" border="0" class="mkTableFormular">
</fieldset> PLACEHOLDER_FIELDS
<input type="submit" name="submit" value="Speichern" style="float:right"/> </table>
</div> </fieldset>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
<!-- Example for second tab <input type="submit" name="submit" value="Speichern" style="float:right"/>
</form>
</div>
<!-- Example for 2nd tab
<div id="tabs-2"> <div id="tabs-2">
[MESSAGE] [MESSAGE]
<div class="row"> <form action="" method="post">
<div class="row-height"> [FORMHANDLEREVENT]
<div class="col-xs-12 col-md-12 col-md-height"> <div class="row">
<div class="inside inside-full-height"> <div class="row-height">
<fieldset> <div class="col-xs-12 col-md-12 col-md-height">
<legend>{|Legend goes here|}</legend> <div class="inside inside-full-height">
<table width="100%" border="0" class="mkTableFormular"> <fieldset>
PLACEHOLDER_FIELDS <legend>{|...|}</legend>
</table> <table width="100%" border="0" class="mkTableFormular">
</fieldset> ...
<input type="submit" name="submit" value="Speichern" style="float:right"/> </table>
</div> </fieldset>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
--> <input type="submit" name="submit" value="Speichern" style="float:right"/>
</form> </form>
</div>
-->
</div>

View File

@ -14,14 +14,11 @@ class PLACEHOLDER_MODULECLASSNAME {
return; return;
$this->app->ActionHandlerInit($this); $this->app->ActionHandlerInit($this);
$this->app->ActionHandler("list", "PLACEHOLDER_LIST"); $this->app->ActionHandler("list", "PLACEHOLDER_LIST");
$this->app->ActionHandler("create", "PLACEHOLDER_EDIT"); // This automatically adds a "New" button $this->app->ActionHandler("create", "PLACEHOLDER_EDIT"); // This automatically adds a "New" button
$this->app->ActionHandler("edit", "PLACEHOLDER_EDIT"); $this->app->ActionHandler("edit", "PLACEHOLDER_EDIT");
$this->app->ActionHandler("delete", "PLACEHOLDER_DELETE"); $this->app->ActionHandler("delete", "PLACEHOLDER_DELETE");
$this->app->DefaultActionHandler("list"); $this->app->DefaultActionHandler("list");
$this->app->ActionHandlerListen($app); $this->app->ActionHandlerListen($app);
} }
@ -46,10 +43,9 @@ class PLACEHOLDER_MODULECLASSNAME {
$sql = "PLACEHOLDER_SQL_LIST"; $sql = "PLACEHOLDER_SQL_LIST";
$where = "1 $where = "1";
";
// $groupby = "";
$count = "SELECT count(DISTINCT id) FROM PLACEHOLDER_MODULENAME WHERE $where"; $count = "SELECT count(DISTINCT id) FROM PLACEHOLDER_MODULENAME WHERE $where";
// $groupby = "";
break; break;
} }
@ -57,8 +53,9 @@ class PLACEHOLDER_MODULECLASSNAME {
$erg = false; $erg = false;
foreach ($erlaubtevars as $k => $v) { foreach ($erlaubtevars as $k => $v) {
if (isset($$v)) if (isset($$v)) {
$erg[$v] = $$v; $erg[$v] = $$v;
}
} }
return $erg; return $erg;
} }
@ -130,8 +127,7 @@ class PLACEHOLDER_MODULECLASSNAME {
$sql = "INSERT INTO PLACEHOLDER_MODULENAME (".$columns.") VALUES (".$values.") ON DUPLICATE KEY UPDATE ".$update; $sql = "INSERT INTO PLACEHOLDER_MODULENAME (".$columns.") VALUES (".$values.") ON DUPLICATE KEY UPDATE ".$update;
// echo($sql);
echo($sql);
$this->app->DB->Update($sql); $this->app->DB->Update($sql);
@ -150,8 +146,7 @@ class PLACEHOLDER_MODULECLASSNAME {
foreach ($result[0] as $key => $value) { foreach ($result[0] as $key => $value) {
$this->app->Tpl->Set(strtoupper($key), $value); $this->app->Tpl->Set(strtoupper($key), $value);
} }
/* /*
* Add displayed items later * Add displayed items later
* *