module_creator with column selection

This commit is contained in:
OpenXE 2022-11-07 10:11:33 +00:00
parent 8032bf779a
commit 20c64a97ea

View File

@ -25,6 +25,8 @@ $user = 'openxe';
$passwd = 'openxe'; $passwd = 'openxe';
$schema = 'openxe'; $schema = 'openxe';
echo("\n");
if ($argc >= 2) { if ($argc >= 2) {
if (in_array('-v', $argv)) { if (in_array('-v', $argv)) {
@ -39,12 +41,34 @@ if ($argc >= 2) {
$force = false; $force = false;
} }
if (!str_starts_with($argv[1],'-')) { if (strpos($argv[1],'-') == 0) {
$module_name = $argv[1]; $module_name = $argv[1];
} else { } else {
info(); info();
exit; exit;
} }
// column selection
$selected_columns = array();
// Set selected_columns here or per parameter -c col1,col2,col3
// $selected_columns = array('belegnr','adresse','projekt');
if (in_array('-c', $argv)) {
$pos = array_keys($argv, '-c')[0];
$pos++;
if (isset($argv[$pos])) {
$selected_columns = explode(',',$argv[$pos]);
}
}
if (empty($selected_columns)) {
echo("Selected all columns.\n");
} else {
echo("Selected ".count($selected_columns)." columns,\n");
}
$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";
@ -89,40 +113,52 @@ if ($argc >= 2) {
/* Iterate through the result set */ /* Iterate through the result set */
echo "FIELD\t\t\t\tType\t\tNull\tKey\tDefault\tExtra\n"; echo "FIELD\t\t\t\tType\t\tNull\tKey\tDefault\tExtra\n";
while ($row = mysqli_fetch_assoc($result)) { while ($row = mysqli_fetch_assoc($result)) {
foreach ($row as $key => $value) {
echo($value);
switch ($key) { $column_processed = false;
case 'Field':
$colwidth = 32;
if ($value != 'id') { if (empty($selected_columns) || in_array($row['Field'],$selected_columns) || $row['Field'] == 'id') {
$columns[] = $value;
$sql_columns[] = $table_short_name.".".$value;
}
break; foreach ($row as $key => $value) {
case 'Type':
$colwidth = 16; echo($value);
break;
default: switch ($key) {
$colwidth = 8; case 'Field':
break; $colwidth = 32;
if ($value != 'id') {
$column_processed = true;
$columns[] = $value;
$sql_columns[] = $table_short_name.".".$value;
}
break;
case 'Type':
$colwidth = 16;
break;
default:
$colwidth = 8;
break;
}
for ($filler = strlen($value); $filler < $colwidth; $filler++) {
echo(" ");
}
} }
for ($filler = strlen($value); $filler < $colwidth; $filler++) { // Build edit form
echo(" "); // <tr><td>{|Bezeichnung|}:*</td><td><input type="text" id="bezeichnung" name="bezeichnung" value="[BEZEICHNUNG]" size="40"></td></tr>
}
if ($row['Field'] != 'id') {
$edit_form = $edit_form . '<tr><td>{|' . ucfirst($row['Field']) . '|}:</td><td><input type="text" name="' . $row['Field'].'" id="'.$row['Field'].'" value="[' . strtoupper($row['Field']) . ']" size="20"></td></tr>' . "\n";
}
echo("\n");
} }
}
// Build edit form if (empty($columns)) {
// <tr><td>{|Bezeichnung|}:*</td><td><input type="text" id="bezeichnung" name="bezeichnung" value="[BEZEICHNUNG]" size="40"></td></tr> echo("No matching columns found!\n");
exit();
if ($row['Field'] != 'id') {
$edit_form = $edit_form . '<tr><td>{|' . ucfirst($row['Field']) . '|}:</td><td><input type="text" name="' . $row['Field'].'" id="'.$row['Field'].'" value="[' . strtoupper($row['Field']) . ']" size="20"></td></tr>' . "\n";
}
echo("\n");
} }
// Create php file // Create php file
@ -222,6 +258,8 @@ function info() {
echo("arg1: SQL table name\n"); echo("arg1: SQL table name\n");
echo("Options\n"); echo("Options\n");
echo("\t-v: verbose output\n"); echo("\t-v: verbose output\n");
echo("\t-f: force override of existing files\n");
echo("\t-c: select columns like this: -c col1,col2,col3,col3\n");
echo("\n"); echo("\n");
} }