📄 tform.inc.php
字号:
<?php/*Copyright (c) 2005, Till Brehm, projektfarm GmbhAll rights reserved.Redistribution and use in source and binary forms, with or without modification,are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of ISPConfig nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" ANDANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIEDWARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORYOF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDINGNEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.*//*** Formularbehandlung** Funktionen zur Umwandlung von Formulardaten* sowie zum vorbereiten von HTML und SQL* Ausgaben** Tabellendefinition** Datentypen:* - INTEGER (Wandelt Ausdr點ke in Int um)* - DOUBLE* - CURRENCY (Formatiert Zahlen nach W鋒rungsnotation)* - VARCHAR (kein weiterer Format Check)* - DATE (Datumsformat, Timestamp Umwandlung)** Formtype:* - TEXT (normales Textfeld)* - PASSWORD (Feldinhalt wird nicht angezeigt)* - SELECT (Gibt Werte als option Feld aus)* - MULTIPLE (Select-Feld mit nehreren Werten)** VALUE:* - Wert oder Array** SEPARATOR* - Trennzeichen f黵 multiple Felder** Hinweis:* Das ID-Feld ist nicht bei den Table Values einzuf黦en.** @package form* @author Till Brehm* @version 1.1*/class tform { /** * Definition der Tabelle (array) * @var tableDef */ var $tableDef; /** * Private * @var action */ var $action; /** * Tabellenname (String) * @var table_name */ var $table_name; /** * Debug Variable * @var debug */ var $debug = 0; /** * name des primary Field der Tabelle (string) * @var table_index */ var $table_index; /** * enth鋖t die Fehlermeldung bei 躡erpr黤ung * der Variablen mit Regex * @var errorMessage */ var $errorMessage = ''; var $dateformat = "d.m.Y"; var $formDef; var $wordbook; var $module; var $primary_id; /** * Laden der Tabellendefinition * * @param file: Pfad zur Tabellendefinition * @return true */ /* function loadTableDef($file) { global $app,$conf; include_once($file); $this->tableDef = $table; $this->table_name = $table_name; $this->table_index = $table_index; return true; } */ function loadFormDef($file,$module = '') { global $app,$conf; include_once($file); $this->formDef = $form; $this->module = $module; if($module == '') { include_once("lib/lang/".$_SESSION["s"]["language"]."_".$this->formDef["name"].".lng"); } else { include_once("../$module/lib/lang/".$_SESSION["s"]["language"]."_".$this->formDef["name"].".lng"); } $this->wordbook = $wb; return true; } /** * Konvertiert die Daten des 黚ergebenen assoziativen * Arrays in "menschenlesbare" Form. * Datentyp Konvertierung, z.B. f黵 Ausgabe in Listen. * * @param record * @return record */ function decode($record,$tab) { if(!is_array($this->formDef['tabs'][$tab])) $app->error("Tab ist leer oder existiert nicht (TAB: $tab)."); if(is_array($record)) { foreach($this->formDef['tabs'][$tab]['fields'] as $key => $field) { switch ($field['datatype']) { case 'VARCHAR': $new_record[$key] = stripslashes($record[$key]); break; case 'TEXT': $new_record[$key] = stripslashes($record[$key]); break; case 'DATE': if($record[$key] > 0) { $new_record[$key] = date($this->dateformat,$record[$key]); } break; case 'INTEGER': $new_record[$key] = intval($record[$key]); break; case 'DOUBLE': $new_record[$key] = $record[$key]; break; case 'CURRENCY': $new_record[$key] = number_format($record[$key], 2, ',', ''); break; default: $new_record[$key] = stripslashes($record[$key]); } } } return $new_record; } /** * Get the key => value array of a form filed from a datasource definitiom * * @param field = array with field definition * @param record = Dataset as array * @return key => value array for the value field of a form */ function getDatasourceData($field, $record) { global $app; $values = array(); if($field["datasource"]["type"] == 'SQL') { // Preparing SQL string. We will replace some // common placeholders $querystring = $field["datasource"]["querystring"]; $querystring = str_replace("{USERID}",$_SESSION["s"]["user"]["userid"],$querystring); $querystring = str_replace("{GROUPID}",$_SESSION["s"]["user"]["default_group"],$querystring); $querystring = str_replace("{GROUPS}",$_SESSION["s"]["user"]["groups"],$querystring); $table_idx = $this->formDef['db_table_idx']; $querystring = str_replace("{RECORDID}",$record[$table_idx],$querystring); $querystring = str_replace("{AUTHSQL}",$this->getAuthSQL('r'),$querystring); // Getting the records $tmp_records = $app->db->queryAllRecords($querystring); if($app->db->errorMessage != '') die($app->db->errorMessage); if(is_array($tmp_records)) { $key_field = $field["datasource"]["keyfield"]; $value_field = $field["datasource"]["valuefield"]; foreach($tmp_records as $tmp_rec) { $tmp_id = $tmp_rec[$key_field]; $values[$tmp_id] = $tmp_rec[$value_field]; } } } if($field["datasource"]["type"] == 'CUSTOM') { // Calls a custom class to validate this record if($field["datasource"]['class'] != '' and $field["datasource"]['function'] != '') { $datasource_class = $field["datasource"]['class']; $datasource_function = $field["datasource"]['function']; $app->uses($datasource_class); $values = $app->$datasource_class->$datasource_function($field, $record); } else { $this->errorMessage .= "Custom datasource class or function is empty<br>\r\n"; } } return $values; } /** * Record f黵 Ausgabe in Formularen vorbereiten. * * @param record = Datensatz als Array * @param action = NEW oder EDIT * @return record */ function getHTML($record, $tab, $action = 'NEW') { global $app; $this->action = $action; if(!is_array($this->formDef)) $app->error("Keine Formdefinition vorhanden."); if(!is_array($this->formDef['tabs'][$tab])) $app->error("Tab ist leer oder existiert nicht (TAB: $tab)."); $new_record = array(); if($action == 'EDIT') { $record = $this->decode($record,$tab); if(is_array($record)) { foreach($this->formDef['tabs'][$tab]['fields'] as $key => $field) { $val = $record[$key]; // If Datasource is set, get the data from there if(is_array($field['datasource'])) { $field["value"] = $this->getDatasourceData($field, $record); } switch ($field['formtype']) { case 'SELECT': if(is_array($field['value'])) { $out = ''; foreach($field['value'] as $k => $v) { $selected = ($k == $val)?' SELECTED':''; $out .= "<option value='$k'$selected>$v</option>\r\n"; } } $new_record[$key] = $out; break; case 'MULTIPLE': if(is_array($field['value'])) { // aufsplitten ergebnisse $vals = explode($field['separator'],$val); // HTML schreiben $out = ''; foreach($field['value'] as $k => $v) { $selected = ''; foreach($vals as $tvl) { if(trim($tvl) == trim($k)) $selected = ' SELECTED'; } $out .= "<option value='$k'$selected>$v</option>\r\n"; } } $new_record[$key] = $out; break; case 'PASSWORD':
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -