Skip to content
Snippets Groups Projects
Commit 836f8329 authored by tbrehm's avatar tbrehm
Browse files

Fixed tpl generation classes and added missing language file createion code again.

parent b6a07cf3
No related branches found
No related tags found
No related merge requests found
...@@ -132,7 +132,48 @@ class listform_tpl_generator { ...@@ -132,7 +132,48 @@ class listform_tpl_generator {
} }
fclose($handle); fclose($handle);
/*$lang["page_txt"] = 'Page';
$lang["page_of_txt"] = 'of';
$lang["page_next_txt"] = 'Next';
$lang["page_back_txt"] = 'Back';
$lang["delete_txt"] = 'Delete';
$lang["filter_txt"] = 'Filter';
$lang["add_new_record_txt"] = 'Add new record';
*/
// save language file
$this->lng_add($lang,$listDef,$module);
} }
function lng_add($lang,$listDef,$module = '') {
global $go_api, $go_info,$conf;
if($module == '') {
$lng_file = "lib/lang/".$conf["language"]."_".$listDef['name']."_list.lng";
} else {
$lng_file = '../'.$module."/lib/lang/en_".$listDef['name']."_list.lng";
}
if(is_file($lng_file)) {
include_once($lng_file);
} else {
$wb = array();
}
$wb_out = array_merge($lang,$wb);
if(is_array($wb_out)) {
$fp = fopen ($lng_file, "w");
fwrite($fp,"<?php\r\n");
foreach($wb_out as $key => $val) {
$new_line = '$wb["'.$key.'"] = '."'$val';\r\n";
fwrite($fp,$new_line);
}
fwrite($fp,"?>");
fclose($fp);
}
}
} }
......
<?php <?php
/* /*
Copyright (c) 2007, Till Brehm, projektfarm Gmbh Copyright (c) 2007, Till Brehm, projektfarm Gmbh
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met: are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, * Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer. this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, * Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution. and/or other materials provided with the distribution.
* Neither the name of ISPConfig nor the names of its contributors * Neither the name of ISPConfig nor the names of its contributors
may be used to endorse or promote products derived from this software without may be used to endorse or promote products derived from this software without
specific prior written permission. specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
class tform_tpl_generator { class tform_tpl_generator {
function buildHTML($formDef,$tab) { function buildHTML($formDef,$tab) {
global $app; global $app;
$module = $_SESSION["s"]["module"]["name"]; $module = $_SESSION["s"]["module"]["name"];
$html = '<h2><tmpl_var name="list_head_txt"></h2> $html = '<h2><tmpl_var name="list_head_txt"></h2>
<p><tmpl_var name="list_desc_txt"></p> <p><tmpl_var name="list_desc_txt"></p>
<div class="panel panel_'.$formDef['name'].'"> <div class="panel panel_'.$formDef['name'].'">
<div class="pnl_formsarea"> <div class="pnl_formsarea">
<fieldset class="inlineLabels"><legend>'.$formDef['tabs'][$tab]['title'].'</legend>'; <fieldset class="inlineLabels"><legend>'.$formDef['tabs'][$tab]['title'].'</legend>';
$lang = array(); $lang = array();
$html_reqestedelement = "<em>*</em> "; $html_reqestedelement = "<em>*</em> ";
foreach($formDef['tabs'][$tab]['fields'] as $key => $field) { foreach($formDef['tabs'][$tab]['fields'] as $key => $field) {
if ($field['required'] == true ) { $html_reqcode = $html_reqestedelement; } else { $html_reqcode = ''; } if ($field['required'] == true ) { $html_reqcode = $html_reqestedelement; } else { $html_reqcode = ''; }
switch ($field['formtype']) { switch ($field['formtype']) {
case 'TEXT': case 'TEXT':
$html .= " $html .= "
<div class=\"ctrlHolder\"> <div class=\"ctrlHolder\">
<label for=\"".$key."\">".$html_reqcode."{tmpl_var name='".$key."_txt'}</label> <label for=\"".$key."\">".$html_reqcode."{tmpl_var name='".$key."_txt'}</label>
<input name=\"".$key."\" id=\"".$key."\" value=\"{tmpl_var name='".$key."'}\" size=\"".$field['width']."\" maxlength=\"".$field['maxlength']."\" type=\"text\" class=\"textInput\" /> <input name=\"".$key."\" id=\"".$key."\" value=\"{tmpl_var name='".$key."'}\" size=\"".$field['width']."\" maxlength=\"".$field['maxlength']."\" type=\"text\" class=\"textInput\" />
</div>"; </div>";
break; break;
case 'TEXTAREA': case 'TEXTAREA':
$html .= " $html .= "
<div class=\"ctrlHolder\"> <div class=\"ctrlHolder\">
<label for=\"".$key."\">".$html_reqcode."{tmpl_var name='".$key."_txt'}</label> <label for=\"".$key."\">".$html_reqcode."{tmpl_var name='".$key."_txt'}</label>
<textarea name=\"".$key."\" id=\"".$key."\" rows='".$field['rows']."' cols='".$field['cols']."'>{tmpl_var name='".$key."'}</textarea> <textarea name=\"".$key."\" id=\"".$key."\" rows='".$field['rows']."' cols='".$field['cols']."'>{tmpl_var name='".$key."'}</textarea>
</div>"; </div>";
break; break;
case 'SELECT': case 'SELECT':
$html .= " $html .= "
<div class=\"ctrlHolder\"> <div class=\"ctrlHolder\">
<label for=\"".$key."\">".$html_reqcode."{tmpl_var name='".$key."_txt'}</label> <label for=\"".$key."\">".$html_reqcode."{tmpl_var name='".$key."_txt'}</label>
<select name=\"".$key."\" id=\"".$key."\" class=\"selectInput\"> <select name=\"".$key."\" id=\"".$key."\" class=\"selectInput\">
{tmpl_var name='".$key."'} {tmpl_var name='".$key."'}
</select> </select>
</div>"; </div>";
break; break;
case 'MULTIPLE': case 'MULTIPLE':
$html .= " $html .= "
<div class=\"ctrlHolder\"> <div class=\"ctrlHolder\">
<label for=\"".$key."\">".$html_reqcode."{tmpl_var name='".$key."_txt'}</label> <label for=\"".$key."\">".$html_reqcode."{tmpl_var name='".$key."_txt'}</label>
<select multiple name=\"".$key."\" id=\"".$key."\" class=\"selectInput\"> <select multiple name=\"".$key."\" id=\"".$key."\" class=\"selectInput\">
{tmpl_var name='".$key."'} {tmpl_var name='".$key."'}
</select> </select>
</div>"; </div>";
break; break;
case 'PASSWORD': case 'PASSWORD':
$html .= " $html .= "
<div class=\"ctrlHolder\"> <div class=\"ctrlHolder\">
<label for=\"".$key."\">".$html_reqcode."{tmpl_var name='".$key."_txt'}</label> <label for=\"".$key."\">".$html_reqcode."{tmpl_var name='".$key."_txt'}</label>
<input name=\"".$key."\" id=\"".$key."\" value=\"{tmpl_var name='".$key."'}\" size=\"".$field['width']."\" maxlength=\"".$field['maxlength']."\" type=\"password\" class=\"textInput\" /> <input name=\"".$key."\" id=\"".$key."\" value=\"{tmpl_var name='".$key."'}\" size=\"".$field['width']."\" maxlength=\"".$field['maxlength']."\" type=\"password\" class=\"textInput\" />
</div>"; </div>";
break; break;
case 'CHECKBOX': case 'CHECKBOX':
$html .= " $html .= "
<div class=\"ctrlHolder\"> <div class=\"ctrlHolder\">
<p class=\"label\">".$html_reqcode."{tmpl_var name='".$key."_txt'}</p> <p class=\"label\">".$html_reqcode."{tmpl_var name='".$key."_txt'}</p>
<div class=\"multiField\"> <div class=\"multiField\">
{tmpl_var name='".$key."'} {tmpl_var name='".$key."'}
</div> </div>
</div>"; </div>";
break; break;
case 'CHECKBOXARRAY': case 'CHECKBOXARRAY':
$html .= " $html .= "
<div class=\"ctrlHolder\"> <div class=\"ctrlHolder\">
<p class=\"label\">".$html_reqcode."{tmpl_var name='".$key."_txt'}</p> <p class=\"label\">".$html_reqcode."{tmpl_var name='".$key."_txt'}</p>
<div class=\"multiField\"> <div class=\"multiField\">
{tmpl_var name='".$key."'} {tmpl_var name='".$key."'}
</div> </div>
</div>"; </div>";
break; break;
case 'RADIO': case 'RADIO':
$html .= " $html .= "
<div class=\"ctrlHolder\"> <div class=\"ctrlHolder\">
<p class=\"label\">".$html_reqcode."{tmpl_var name='".$key."_txt'}</p> <p class=\"label\">".$html_reqcode."{tmpl_var name='".$key."_txt'}</p>
<div class=\"multiField\"> <div class=\"multiField\">
{tmpl_var name='".$key."'} {tmpl_var name='".$key."'}
</div> </div>
</div>"; </div>";
break; break;
} }
// Language File Eintrag fr "Feld-Titel" anlegen // Language File Eintrag fr "Feld-Titel" anlegen
$lang[$key."_txt"] = $key; $lang[$key."_txt"] = $key;
// language File Eintrag, fr error-Text anlegen // language File Eintrag, fr error-Text anlegen
if(isset($field["errmsg"]) && $field["errmsg"] != '') { if(isset($field["errmsg"]) && $field["errmsg"] != '') {
$errmsg = $field["errmsg"]; $errmsg = $field["errmsg"];
$lang[$errmsg] = $errmsg; $lang[$errmsg] = $errmsg;
} }
} }
$html .= " $html .= "
</fieldset> </fieldset>
<input type=\"hidden\" name=\"id\" value=\"{tmpl_var name='id'}\"> <input type=\"hidden\" name=\"id\" value=\"{tmpl_var name='id'}\">
<div class=\"buttonHolder buttons\"> <div class=\"buttonHolder buttons\">
<button class=\"positive iconstxt icoPositive\" type=\"button\" value=\"{tmpl_var name='btn_save_txt'}\" onClick=\"submitForm('pageForm','".$module."/".$formDef["action"]."');\"><span>{tmpl_var name='btn_save_txt'}</span></button> <button class=\"positive iconstxt icoPositive\" type=\"button\" value=\"{tmpl_var name='btn_save_txt'}\" onClick=\"submitForm('pageForm','".$module."/".$formDef["action"]."');\"><span>{tmpl_var name='btn_save_txt'}</span></button>
<button class=\"negative iconstxt icoNegative\" type=\"button\" value=\"{tmpl_var name='btn_cancel_txt'}\" onClick=\"loadContent('".$module."/".$formDef["list_default"]."');\"><span>{tmpl_var name='btn_cancel_txt'}</span></button> <button class=\"negative iconstxt icoNegative\" type=\"button\" value=\"{tmpl_var name='btn_cancel_txt'}\" onClick=\"loadContent('".$module."/".$formDef["list_default"]."');\"><span>{tmpl_var name='btn_cancel_txt'}</span></button>
</div> </div>
</div> </div>
</div> </div>
"; ";
// speichere Template // speichere Template
if (!$handle = fopen($formDef['tabs'][$tab]['template'], 'w')) { if (!$handle = fopen($formDef['tabs'][$tab]['template'], 'w')) {
print "Cannot open file ($filename)"; print "Cannot open file ($filename)";
exit; exit;
} }
if (!fwrite($handle, $html)) { if (!fwrite($handle, $html)) {
print "Cannot write to file ($filename)"; print "Cannot write to file ($filename)";
exit; exit;
} }
fclose($handle); fclose($handle);
// berprfe, ob es die Tabelle schon gibt, $this->lng_add($lang,$formDef);
// ansonsten wird sie angelegt
$tables = $app->db->getTables(); // berprfe, ob es die Tabelle schon gibt,
// ansonsten wird sie angelegt
if(!@in_array($formDef['db_table'],$tables)) { $tables = $app->db->getTables();
// Datenbank noch nicht vorhanden
if(!@in_array($formDef['db_table'],$tables)) {
$columns = array(); // Datenbank noch nicht vorhanden
// fge ID Feld hinzu $columns = array();
$col = array( 'action' => 'add',
'name' => $formDef["db_table_idx"], // fge ID Feld hinzu
'type' => 'int64', $col = array( 'action' => 'add',
'typeValue' => '', 'name' => $formDef["db_table_idx"],
'defaultValue' => false, 'type' => 'int64',
'notNull' => true, 'typeValue' => '',
'autoInc' => true, 'defaultValue' => false,
'option' => 'primary' 'notNull' => true,
); 'autoInc' => true,
'option' => 'primary'
$columns[] = $col; );
$app->db->show_error_messages = true;
$columns[] = $col;
if($formDef["auth"] == 'yes') { $app->db->show_error_messages = true;
$col = array( 'action' => 'add', if($formDef["auth"] == 'yes') {
'name' => 'sys_userid',
'type' => 'int32', $col = array( 'action' => 'add',
'typeValue' => '', 'name' => 'sys_userid',
'defaultValue' => '0', 'type' => 'int32',
'notNull' => true 'typeValue' => '',
); 'defaultValue' => '0',
$columns[] = $col; 'notNull' => true
$col = array( 'action' => 'add', );
'name' => 'sys_groupid', $columns[] = $col;
'type' => 'int32', $col = array( 'action' => 'add',
'typeValue' => '', 'name' => 'sys_groupid',
'defaultValue' => '0', 'type' => 'int32',
'notNull' => true 'typeValue' => '',
); 'defaultValue' => '0',
$columns[] = $col; 'notNull' => true
$col = array( 'action' => 'add', );
'name' => 'sys_perm_user', $columns[] = $col;
'type' => 'varchar', $col = array( 'action' => 'add',
'typeValue' => '5', 'name' => 'sys_perm_user',
'defaultValue' => 'NULL', 'type' => 'varchar',
'notNull' => true 'typeValue' => '5',
); 'defaultValue' => 'NULL',
$columns[] = $col; 'notNull' => true
$col = array( 'action' => 'add', );
'name' => 'sys_perm_group', $columns[] = $col;
'type' => 'varchar', $col = array( 'action' => 'add',
'typeValue' => '5', 'name' => 'sys_perm_group',
'defaultValue' => 'NULL', 'type' => 'varchar',
'notNull' => true 'typeValue' => '5',
); 'defaultValue' => 'NULL',
$columns[] = $col; 'notNull' => true
$col = array( 'action' => 'add', );
'name' => 'sys_perm_other', $columns[] = $col;
'type' => 'varchar', $col = array( 'action' => 'add',
'typeValue' => '5', 'name' => 'sys_perm_other',
'defaultValue' => 'NULL', 'type' => 'varchar',
'notNull' => true 'typeValue' => '5',
); 'defaultValue' => 'NULL',
$columns[] = $col; 'notNull' => true
);
} $columns[] = $col;
}
foreach($formDef['tabs'] as $tab) {
foreach($tab["fields"] as $name => $field) {
/* foreach($formDef['tabs'] as $tab) {
$columns = array(action => add | alter | drop foreach($tab["fields"] as $name => $field) {
name => Spaltenname /*
name_new => neuer Spaltenname, nur bei 'alter' belegt $columns = array(action => add | alter | drop
type => 42go-Meta-Type: int16, int32, int64, double, char, varchar, text, blob name => Spaltenname
typeValue => Wert z.B. bei Varchar name_new => neuer Spaltenname, nur bei 'alter' belegt
defaultValue => Default Wert type => 42go-Meta-Type: int16, int32, int64, double, char, varchar, text, blob
notNull => true | false typeValue => Wert z.B. bei Varchar
autoInc => true | false defaultValue => Default Wert
option => unique | primary | index) notNull => true | false
autoInc => true | false
option => unique | primary | index)
*/
switch ($field["datatype"]) {
case 'INTEGER': */
$type = 'int32'; switch ($field["datatype"]) {
$typevalue = ''; case 'INTEGER':
$defaultValue = ($field["default"] != '')?$field["default"]:'0'; $type = 'int32';
break; $typevalue = '';
case 'DOUBLE': $defaultValue = ($field["default"] != '')?$field["default"]:'0';
$type = 'double'; break;
$typevalue = ''; case 'DOUBLE':
$defaultValue = ($field["default"] != '')?$field["default"]:'0'; $type = 'double';
break; $typevalue = '';
case 'CURRENCY': $defaultValue = ($field["default"] != '')?$field["default"]:'0';
$type = 'double'; break;
$typevalue = ''; case 'CURRENCY':
$defaultValue = ($field["default"] != '')?$field["default"]:'0'; $type = 'double';
break; $typevalue = '';
case 'VARCHAR': $defaultValue = ($field["default"] != '')?$field["default"]:'0';
$type = 'varchar'; break;
$typeValue = ($field["maxlength"] > 0 and $field["maxlength"] <= 256)?$field["maxlength"]:255; case 'VARCHAR':
// $defaultValue = ($field["default"] != '')?$field["default"]:'NOT NULL'; $type = 'varchar';
$defaultValue = ($field["default"] != '')?$field["default"]:'NULL'; $typeValue = ($field["maxlength"] > 0 and $field["maxlength"] <= 256)?$field["maxlength"]:255;
break; // $defaultValue = ($field["default"] != '')?$field["default"]:'NOT NULL';
case 'TEXT': $defaultValue = ($field["default"] != '')?$field["default"]:'NULL';
$type = 'text'; break;
$typevalue = ''; case 'TEXT':
$defaultValue = 'NULL'; $type = 'text';
break; $typevalue = '';
case 'DATE': $defaultValue = 'NULL';
$type = 'int64'; break;
$typevalue = ''; case 'DATE':
$defaultValue = ($field["default"] != '')?$field["default"]:'0'; $type = 'int64';
break; $typevalue = '';
} $defaultValue = ($field["default"] != '')?$field["default"]:'0';
break;
}
$col = array( 'action' => 'add',
'name' => $name,
'type' => $type, $col = array( 'action' => 'add',
'typeValue' => $typeValue, 'name' => $name,
'defaultValue' => $defaultValue, 'type' => $type,
'notNull' => true 'typeValue' => $typeValue,
); 'defaultValue' => $defaultValue,
'notNull' => true
$columns[] = $col; );
}
} $columns[] = $col;
}
$app->db->createTable($formDef["db_table"],$columns); }
} $app->db->createTable($formDef["db_table"],$columns);
}
}
}
function lng_add($lang,$formDef) {
global $go_api, $go_info,$conf;
$lng_file = "lib/lang/".$conf["language"]."_".$formDef['name'].".lng";
if(is_file($lng_file)) {
include($lng_file);
} else {
$wb = array();
}
$wb_out = array_merge($lang,$wb);
if(is_array($wb_out)) {
$fp = fopen ($lng_file, "w");
fwrite($fp,"<?php\r\n");
foreach($wb_out as $key => $val) {
$new_line = '$wb["'.$key.'"] = '."'$val';\r\n";
fwrite($fp,$new_line);
}
fwrite($fp,"?>");
fclose($fp);
}
}
}
?> ?>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment