From 6f67c78cf8668e570c5ef7fd4430e3d0e4a66aef Mon Sep 17 00:00:00 2001 From: tbrehm <t.brehm@ispconfig.org> Date: Sat, 22 Nov 2008 07:49:58 -0500 Subject: [PATCH] Replaced php code for app version in main template with a template variable. --- interface/lib/classes/tform.inc.php | 175 +++++++++++++++++++++++++++++++++++----------------------- 1 files changed, 105 insertions(+), 70 deletions(-) diff --git a/interface/lib/classes/tform.inc.php b/interface/lib/classes/tform.inc.php index 9f920c6..dbb17fa 100644 --- a/interface/lib/classes/tform.inc.php +++ b/interface/lib/classes/tform.inc.php @@ -31,33 +31,30 @@ /** * Formularbehandlung * -* Funktionen zur Umwandlung von Formulardaten -* sowie zum vorbereiten von HTML und SQL -* Ausgaben +* Functions to validate, display and save form values * -* Tabellendefinition +* Database table field definitions * -* Datentypen: -* - INTEGER (Wandelt Ausdr�cke in Int um) +* Datatypes: +* - INTEGER (Converts data to int automatically) * - DOUBLE -* - CURRENCY (Formatiert Zahlen nach W�hrungsnotation) -* - VARCHAR (kein weiterer Format Check) -* - DATE (Datumsformat, Timestamp Umwandlung) +* - CURRENCY (Formats digits in currency notation) +* - VARCHAR (No format check) +* - DATE (Date format, converts from and to linux timestamps automatically) * * Formtype: -* - TEXT (normales Textfeld) -* - PASSWORD (Feldinhalt wird nicht angezeigt) -* - SELECT (Gibt Werte als option Feld aus) -* - MULTIPLE (Select-Feld mit nehreren Werten) +* - TEXT (Normal text field) +* - PASSWORD (password field, the content will not be displayed again to the user) +* - SELECT (Option fiield) +* - MULTIPLE (Allows selection of multiple values) * * VALUE: -* - Wert oder Array +* - Value or array * * SEPARATOR -* - Trennzeichen f�r multiple Felder +* - separator char used for fileds with multiple values * -* Hinweis: -* Das ID-Feld ist nicht bei den Table Values einzuf�gen. +* Hint: The auto increment (ID) filed of the table has not be be definied eoarately. * * @package form * @author Till Brehm @@ -67,7 +64,7 @@ class tform { /** - * Definition der Tabelle (array) + * Table definition (array) * @var tableDef */ var $tableDef; @@ -79,26 +76,25 @@ var $action; /** - * Tabellenname (String) + * Table name (String) * @var table_name */ var $table_name; /** - * Debug Variable + * Enable debigging * @var debug */ var $debug = 0; /** - * name des primary Field der Tabelle (string) + * name of the primary field of the datbase table (string) * @var table_index */ var $table_index; /** - * enth�lt die Fehlermeldung bei �berpr�fung - * der Variablen mit Regex + * contains the error message * @var errorMessage */ var $errorMessage = ''; @@ -111,9 +107,9 @@ var $diffrec = array(); /** - * Laden der Tabellendefinition + * Loading of the table definition * - * @param file: Pfad zur Tabellendefinition + * @param file: path to the form definition file * @return true */ /* @@ -153,15 +149,14 @@ /** - * Konvertiert die Daten des �bergebenen assoziativen - * Arrays in "menschenlesbare" Form. - * Datentyp Konvertierung, z.B. f�r Ausgabe in Listen. + * Converts the data in the array to human readable format + * Datatype conversion e.g. to show the data in lists * * @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($this->formDef['tabs'][$tab])) $app->error("Tab does not exist or the tab is empty (TAB: $tab)."); $new_record = ''; if(is_array($record)) { foreach($this->formDef['tabs'][$tab]['fields'] as $key => $field) { @@ -262,7 +257,7 @@ /** - * Record f�r Ausgabe in Formularen vorbereiten. + * Prepare the data record to show the data in a form. * * @param record = Datensatz als Array * @param action = NEW oder EDIT @@ -274,8 +269,8 @@ $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)."); + if(!is_array($this->formDef)) $app->error("No form definition found."); + if(!is_array($this->formDef['tabs'][$tab])) $app->error("The tab is empty or does not exist (TAB: $tab)."); $new_record = array(); if($action == 'EDIT') { @@ -303,10 +298,10 @@ case 'MULTIPLE': if(is_array($field['value'])) { - // aufsplitten ergebnisse + // Split $vals = explode($field['separator'],$val); - // HTML schreiben + // write HTML $out = ''; foreach($field['value'] as $k => $v) { @@ -344,8 +339,10 @@ foreach($vals as $tvl) { if(trim($tvl) == trim($k)) $checked = ' CHECKED'; } - - $out .= "<input name=\"".$key."[]\" type=\"checkbox\" value=\"$k\" $checked>$v <br />\r\n"; + $out .= "<span class=\"wf_oneChoice\">\r\n + <input type=\"checkbox\" value=\"$k\" id=\"".$key."[]\" name=\"".$key."[]\" $checked>\r\n + <label for=\"".$key."[]\" id=\"".$key."[]-L\" class=\"wf_postField\">$v</label>\r\n + </span><br />\r\n"; } } $new_record[$key] = $out; @@ -358,7 +355,10 @@ $out = ''; foreach($field['value'] as $k => $v) { $checked = ($k == $val)?' CHECKED':''; - $out .= "<input name='".$key."[]' type='radio' value='$k'$checked> $v<br>\r\n"; + $out .= "<span class=\"wf_oneChoice\">\r\n + <input type=\"radio\" value=\"$k\" id=\"".$key."[]\" name=\"".$key."[]\" $checked>\r\n + <label for=\"".$key."[]\" id=\"".$key."[]-L\" class=\"wf_postField\">$v</label>\r\n + </span><br />\r\n"; } } $new_record[$key] = $out; @@ -412,7 +412,7 @@ case 'CHECKBOX': // $checked = (empty($field["default"]))?'':' CHECKED'; - $checked = ($field["default"] == $field['value'][1])?' CHECKED':''; + $checked = ($field["default"] == $field['value'][1])?' CHECKED':''; $new_record[$key] = "<input name=\"".$key."\" type=\"checkbox\" value=\"".$field['value'][1]."\" $checked>\r\n"; break; @@ -430,8 +430,10 @@ foreach($vals as $tvl) { if(trim($tvl) == trim($k)) $checked = ' CHECKED'; } - - $out .= "<input name=\"".$key."[]\" type=\"checkbox\" value=\"$k\" $checked> $v<br />\r\n"; + $out .= "<span class=\"wf_oneChoice\">\r\n + <input type=\"checkbox\" value=\"$k\" id=\"".$key."[]\" name=\"".$key."[]\" $checked>\r\n + <label for=\"".$key."[]\" id=\"".$key."[]-L\" class=\"wf_postField\">$v</label>\r\n + </span><br />\r\n"; } } $new_record[$key] = $out; @@ -444,7 +446,10 @@ $out = ''; foreach($field['value'] as $k => $v) { $checked = ($k == $field["default"])?' CHECKED':''; - $out .= "<input name='".$key."[]' type='radio' value='$k'$checked> $v<br>\r\n"; + $out .= "<span class=\"wf_oneChoice\">\r\n + <input type=\"radio\" value=\"$k\" id=\"".$key."[]\" name=\"".$key."[]\" $checked>\r\n + <label for=\"".$key."[]\" id=\"".$key."[]-L\" class=\"wf_postField\">$v</label>\r\n + </span><br />\r\n"; } } $new_record[$key] = $out; @@ -463,15 +468,16 @@ } /** - * Record in "maschinen lesbares" Format �berf�hren - * und Werte gegen regul�re Ausdr�cke pr�fen. + * Rewrite the record data to be stored in the database + * and check values with regular expressions. * * @param record = Datensatz als Array * @return record */ function encode($record,$tab) { - - if(!is_array($this->formDef['tabs'][$tab])) $app->error("Tab ist leer oder existiert nicht (TAB: $tab)."); + global $app; + + if(!is_array($this->formDef['tabs'][$tab])) $app->error("Tab is empty or does not exist (TAB: $tab)."); //$this->errorMessage = ''; if(is_array($record)) { @@ -482,14 +488,14 @@ switch ($field['datatype']) { case 'VARCHAR': if(!@is_array($record[$key])) { - $new_record[$key] = (isset($record[$key]))?addslashes($record[$key]):''; + $new_record[$key] = (isset($record[$key]))?$app->db->quote($record[$key]):''; } else { $new_record[$key] = implode($field['separator'],$record[$key]); } break; case 'TEXT': if(!is_array($record[$key])) { - $new_record[$key] = addslashes($record[$key]); + $new_record[$key] = $app->db->quote($record[$key]); } else { $new_record[$key] = implode($field['separator'],$record[$key]); } @@ -503,12 +509,12 @@ } break; case 'INTEGER': - $new_record[$key] = (isset($record[$key]))?intval($record[$key]):0; + $new_record[$key] = (isset($record[$key]))?$record[$key]:0; //if($new_record[$key] != $record[$key]) $new_record[$key] = $field['default']; //if($key == 'refresh') die($record[$key]); break; case 'DOUBLE': - $new_record[$key] = addslashes($record[$key]); + $new_record[$key] = $app->db->quote($record[$key]); break; case 'CURRENCY': $new_record[$key] = str_replace(",",".",$record[$key]); @@ -648,7 +654,7 @@ } /** - * SQL Statement f�r Record erzeugen. + * Create the SQL staement. * * @param record = Datensatz als Array * @param action = INSERT oder UPDATE @@ -699,10 +705,16 @@ $salt.="$"; // $salt = substr(md5(time()),0,2); $record[$key] = crypt($record[$key],$salt); + $sql_insert_val .= "'".$app->db->quote($record[$key])."', "; + } elseif ($field['encryption'] == 'MYSQL') { + $sql_insert_val .= "PASSWORD('".$app->db->quote($record[$key])."'), "; + } elseif ($field['encryption'] == 'CLEARTEXT') { + $sql_insert_val .= "'".$app->db->quote($record[$key])."', "; } else { $record[$key] = md5($record[$key]); + $sql_insert_val .= "'".$app->db->quote($record[$key])."', "; } - $sql_insert_val .= "'".addslashes($record[$key])."', "; + } elseif ($field['formtype'] == 'CHECKBOX') { $sql_insert_key .= "`$key`, "; if($record[$key] == '') { @@ -726,10 +738,16 @@ $salt.="$"; // $salt = substr(md5(time()),0,2); $record[$key] = crypt($record[$key],$salt); + $sql_update .= "`$key` = '".$app->db->quote($record[$key])."', "; + } elseif (isset($field['encryption']) && $field['encryption'] == 'MYSQL') { + $sql_update .= "`$key` = PASSWORD('".$app->db->quote($record[$key])."'), "; + } elseif (isset($field['encryption']) && $field['encryption'] == 'CLEARTEXT') { + $sql_update .= "`$key` = '".$app->db->quote($record[$key])."', "; } else { $record[$key] = md5($record[$key]); + $sql_update .= "`$key` = '".$app->db->quote($record[$key])."', "; } - $sql_update .= "`$key` = '".addslashes($record[$key])."', "; + } elseif ($field['formtype'] == 'CHECKBOX') { if($record[$key] == '') { // if a checkbox is not set, we set it to the unchecked value @@ -751,7 +769,7 @@ } - // F�ge Backticks nur bei unvollst�ndigen Tabellennamen ein + // Add backticks for incomplete table names if(stristr($this->formDef['db_table'],'.')) { $escape = ''; } else { @@ -761,7 +779,7 @@ if($action == "INSERT") { if($this->formDef['auth'] == 'yes') { - // Setze User und Gruppe + // Set user and group $sql_insert_key .= "`sys_userid`, "; $sql_insert_val .= ($this->formDef["auth_preset"]["userid"] > 0)?"'".$this->formDef["auth_preset"]["userid"]."', ":"'".$_SESSION["s"]["user"]["userid"]."', "; $sql_insert_key .= "`sys_groupid`, "; @@ -777,6 +795,7 @@ $sql_insert_val = substr($sql_insert_val,0,-2); $sql = "INSERT INTO ".$escape.$this->formDef['db_table'].$escape." ($sql_insert_key) VALUES ($sql_insert_val)"; } else { + if($this->formDef['auth'] == 'yes') { if($primary_id != 0) { $sql_update = substr($sql_update,0,-2); $sql = "UPDATE ".$escape.$this->formDef['db_table'].$escape." SET ".$sql_update." WHERE ".$this->getAuthSQL('u')." AND ".$this->formDef['db_table_idx']." = ".$primary_id; @@ -784,6 +803,15 @@ } else { $app->error("Primary ID fehlt!"); } + } else { + if($primary_id != 0) { + $sql_update = substr($sql_update,0,-2); + $sql = "UPDATE ".$escape.$this->formDef['db_table'].$escape." SET ".$sql_update." WHERE ".$this->formDef['db_table_idx']." = ".$primary_id; + if($sql_ext_where != '') $sql .= " and ".$sql_ext_where; + } else { + $app->error("Primary ID fehlt!"); + } + } } return $sql; @@ -810,17 +838,16 @@ $active_tab = $this->getNextTab(); - // definiere Tabs + // go trough the tabs foreach( $this->formDef["tabs"] as $key => $tab) { $tab['name'] = $key; if($tab['name'] == $active_tab) { - // Wenn Modul gesetzt, dann setzte template pfad relativ zu modul. + // If module is set, then set the template path relative to the module.. if($this->module != '') $tab["template"] = "../".$this->module."/".$tab["template"]; - // �berpr�fe, ob das Template existiert, wenn nicht - // dann generiere das Template + // Generate the template if it does not exist yet. // Translate the title of the tab $tab['title'] = $this->lng($tab['title']); @@ -837,7 +864,7 @@ $tab["active"] = 0; } - // Die Datenfelder werden f�r die Tabs nicht ben�tigt + // Unset unused variables. unset($tab["fields"]); unset($tab["plugins"]); @@ -852,8 +879,8 @@ $app->tpl->setVar('form_active_tab',$active_tab); // Set form title - $form_hint = '<b>'.$this->lng($this->formDef["title"]).'</b>'; - if($this->formDef["description"] != '') $form_hint .= '<br><br>'.$this->lng($this->formDef["description"]); + $form_hint = $this->lng($this->formDef["title"]); + if($this->formDef["description"] != '') $form_hint .= '<div class="pageForm_description">'.$this->lng($this->formDef["description"]).'</div>'; $app->tpl->setVar('form_hint',$form_hint); // Set Wordbook for this form @@ -872,7 +899,7 @@ function datalogSave($action,$primary_id, $record_old, $record_new) { global $app,$conf; - // F�ge Backticks nur bei unvollst�ndigen Tabellennamen ein + // Add backticks for incomplete table names. if(stristr($this->formDef['db_table'],'.')) { $escape = ''; } else { @@ -966,14 +993,14 @@ } /* - Diese funktion �berpr�ft, ob ein User die Berechtigung $perm f�r den Datensatz mit der ID $record_id - hat. It record_id = 0, dann wird gegen die user Defaults des Formulares getestet. + This function checks if a user has the parmissions $perm for the data record with the ID $record_id + If record_id = 0, the the permissions are tested against the defaults of the form file. */ function checkPerm($record_id,$perm) { global $app; if($record_id > 0) { - // F�ge Backticks nur bei unvollst�ndigen Tabellennamen ein + // Add backticks for incomplete table names. if(stristr($this->formDef['db_table'],'.')) { $escape = ''; } else { @@ -1002,18 +1029,18 @@ } function getNextTab() { - // Welcher Tab wird angezeigt + // Which tab is shown if($this->errorMessage == '') { - // wenn kein Fehler vorliegt + // If there is no error if(isset($_REQUEST["next_tab"]) && $_REQUEST["next_tab"] != '') { - // wenn n�chster Tab bekannt + // If the next tab is known $active_tab = $_REQUEST["next_tab"]; } else { - // ansonsten ersten tab nehmen + // else use the default tab $active_tab = $this->formDef['tab_default']; } } else { - // bei Fehlern den gleichen Tab nochmal anzeigen + // Show the same tab again in case of an error $active_tab = $_SESSION["s"]["form"]["tab"]; } @@ -1024,6 +1051,14 @@ return $_SESSION["s"]["form"]["tab"]; } + function isReadonlyTab($tab) { + if(isset($this->formDef['tabs'][$tab]['readonly']) && $this->formDef['tabs'][$tab]['readonly'] == true) { + return true; + } else { + return false; + } + } + // translation function for forms, tries the form wordbook first and if this fails, it tries the global wordbook function lng($msg) { -- Gitblit v1.9.1