📄 tform.inc.php
字号:
} return true; } /** * SQL Statement f黵 Record erzeugen. * * @param record = Datensatz als Array * @param action = INSERT oder UPDATE * @param primary_id * @return record */ function getSQL($record, $tab, $action = 'INSERT', $primary_id = 0, $sql_ext_where = '') { global $app; // If there are no data records on the tab, return empty sql string if(count($this->formDef['tabs'][$tab]['fields']) == 0) return ''; // checking permissions if($this->formDef['auth'] == 'yes') { if($action == "INSERT") { if(!$this->checkPerm($primary_id,'i')) $this->errorMessage .= "Insert denied.<br>\r\n"; } else { if(!$this->checkPerm($primary_id,'u')) $this->errorMessage .= "Insert denied.<br>\r\n"; } } $this->action = $action; $this->primary_id = $primary_id; $record = $this->encode($record,$tab); $sql_insert_key = ''; $sql_insert_val = ''; $sql_update = ''; if(!is_array($this->formDef)) $app->error("Keine Formulardefinition vorhanden."); if(!is_array($this->formDef['tabs'][$tab])) $app->error("Tab ist leer oder existiert nicht (TAB: $tab)."); // gehe durch alle Felder des Tabs if(is_array($record)) { foreach($this->formDef['tabs'][$tab]['fields'] as $key => $field) { // Wenn es kein leeres Passwortfeld ist if (!($field['formtype'] == 'PASSWORD' and $record[$key] == '')) { // Erzeuge Insert oder Update Quelltext if($action == "INSERT") { if($field['formtype'] == 'PASSWORD') { $sql_insert_key .= "`$key`, "; if($field['encryption'] == 'CRYPT') { $sql_insert_val .= "'".crypt($record[$key])."', "; } else { $sql_insert_val .= "md5('".$record[$key]."'), "; } } else { $sql_insert_key .= "`$key`, "; $sql_insert_val .= "'".$record[$key]."', "; } } else { if($field['formtype'] == 'PASSWORD') { if($field['encryption'] == 'CRYPT') { $sql_update .= "`$key` = '".crypt($record[$key])."', "; } else { $sql_update .= "`$key` = md5('".$record[$key]."'), "; } } else { $sql_update .= "`$key` = '".$record[$key]."', "; } } } } } // F黦e Backticks nur bei unvollst鋘digen Tabellennamen ein if(stristr($this->formDef['db_table'],'.')) { $escape = ''; } else { $escape = '`'; } if($action == "INSERT") { if($this->formDef['auth'] == 'yes') { // Setze User und Gruppe $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`, "; $sql_insert_val .= ($this->formDef["auth_preset"]["groupid"] > 0)?"'".$this->formDef["auth_preset"]["groupid"]."', ":"'".$_SESSION["s"]["user"]["default_group"]."', "; $sql_insert_key .= "`sys_perm_user`, "; $sql_insert_val .= "'".$this->formDef["auth_preset"]["perm_user"]."', "; $sql_insert_key .= "`sys_perm_group`, "; $sql_insert_val .= "'".$this->formDef["auth_preset"]["perm_group"]."', "; $sql_insert_key .= "`sys_perm_other`, "; $sql_insert_val .= "'".$this->formDef["auth_preset"]["perm_other"]."', "; } $sql_insert_key = substr($sql_insert_key,0,-2); $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($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!"); } } // Daten in History tabelle speichern if($this->errorMessage == '' and $this->formDef['db_history'] == 'yes') $this->datalogSave($action,$primary_id,$record); // die($sql); return $sql; } /** * Debugging arrays. * * @param array_data */ function dbg($array_data) { echo "<pre>"; print_r($array_data); echo "</pre>"; } function showForm() { global $app,$conf; if(!is_array($this->formDef)) die("Form Definition wurde nicht geladen."); $active_tab = $this->getNextTab(); // definiere 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($this->module != '') $tab["template"] = "../".$this->module."/".$tab["template"]; // 黚erpr黤e, ob das Template existiert, wenn nicht // dann generiere das Template if(!is_file($tab["template"])) { $app->uses('tform_tpl_generator'); $app->tform_tpl_generator->buildHTML($this->formDef,$tab['name']); } $app->tpl->setInclude('content_tpl',$tab["template"]); $tab["active"] = 1; $_SESSION["s"]["form"]["tab"] = $tab['name']; } else { $tab["active"] = 0; } // Die Datenfelder werden f黵 die Tabs nicht ben鰐igt unset($tab["fields"]); unset($tab["plugins"]); $frmTab[] = $tab; } // setting form tabs $app->tpl->setLoop("formTab", $frmTab); // Set form action $app->tpl->setVar('form_action',$this->formDef["action"]); $app->tpl->setVar('form_active_tab',$active_tab); // Set form title $form_hint = '<b>'.$this->formDef["title"].'</b>'; if($this->formDef["description"] != '') $form_hint .= '<br><br>'.$this->formDef["description"]; $app->tpl->setVar('form_hint',$form_hint); // Set Wordbook for this form $app->tpl->setVar($this->wordbook); } function datalogSave($action,$primary_id,$record_new) { global $app,$conf; // F黦e Backticks nur bei unvollst鋘digen Tabellennamen ein if(stristr($this->formDef['db_table'],'.')) { $escape = ''; } else { $escape = '`'; } if($action == "UPDATE") { $sql = "SELECT * FROM ".$escape.$this->formDef['db_table'].$escape." WHERE ".$this->formDef['db_table_idx']." = ".$primary_id; $record_old = $app->db->queryOneRecord($sql); } else { $record_old = array(); } $diffrec = array(); if(is_array($record_new)) { foreach($record_new as $key => $val) { if($record_old[$key] != $val) { // Datensatz hat sich ge鋘dert $diffrec[$key] = array('old' => $record_old[$key], 'new' => $val); } } } // Insert the server_id, if the record has a server_id $server_id = ($record_old["server_id"] > 0)?$record_old["server_id"]:0; if(count($diffrec) > 0) { // We need the full records in ISPConfig, not only the diffs $diffrec = array( 'old' => $record_old, 'new' => $record_new); $diffstr = $app->db->quote(serialize($diffrec)); $username = $app->db->quote($_SESSION["s"]["user"]["username"]); $dbidx = $this->formDef['db_table_idx'].":".$primary_id; $action = ($action == 'INSERT')?'i':'u'; $sql = "INSERT INTO sys_datalog (dbtable,dbidx,server_id,action,tstamp,user,data) VALUES ('".$this->formDef['db_table']."','$dbidx','$server_id','$action','".time()."','$username','$diffstr')"; $app->db->query($sql); } return true; } function getAuthSQL($perm) { $sql = '('; $sql .= "(sys_userid = ".$_SESSION["s"]["user"]["userid"]." AND sys_perm_user like '%$perm%') OR "; $sql .= "(sys_groupid IN (".$_SESSION["s"]["user"]["groups"].") AND sys_perm_group like '%$perm%') OR "; $sql .= "sys_perm_other like '%$perm%'"; $sql .= ')'; return $sql; } /* Diese funktion 黚erpr黤t, ob ein User die Berechtigung $perm f黵 den Datensatz mit der ID $record_id hat. It record_id = 0, dann wird gegen die user Defaults des Formulares getestet. */ function checkPerm($record_id,$perm) { global $app; if($record_id > 0) { // F黦e Backticks nur bei unvollst鋘digen Tabellennamen ein if(stristr($this->formDef['db_table'],'.')) { $escape = ''; } else { $escape = '`'; } $sql = "SELECT ".$this->formDef['db_table_idx']." FROM ".$escape.$this->formDef['db_table'].$escape." WHERE ".$this->formDef['db_table_idx']." = ".$record_id." AND ".$this->getAuthSQL($perm); if($record = $app->db->queryOneRecord($sql)) { return true; } else { return false; } } else { $result = false; if($this->formDef["auth_preset"]["userid"] == $_SESSION["s"]["user"]["userid"] && stristr($perm,$this->formDef["auth_preset"]["perm_user"])) $result = true; if($this->formDef["auth_preset"]["groupid"] == $_SESSION["s"]["user"]["groupid"] && stristr($perm,$this->formDef["auth_preset"]["perm_group"])) $result = true; if(@stristr($this->formDef["auth_preset"]["perm_other"],$perm)) $result = true; // if preset == 0, everyone can insert a record of this type if($this->formDef["auth_preset"]["userid"] == 0 AND $this->formDef["auth_preset"]["groupid"] == 0 AND (@stristr($this->formDef["auth_preset"]["perm_user"],$perm) OR @stristr($this->formDef["auth_preset"]["perm_group"],$perm))) $result = true; return $result; } } function getNextTab() { // Welcher Tab wird angezeigt if($this->errorMessage == '') { // wenn kein Fehler vorliegt if($_REQUEST["next_tab"] != '') { // wenn n鋍hster Tab bekannt $active_tab = $_REQUEST["next_tab"]; } else { // ansonsten ersten tab nehmen $active_tab = $this->formDef['tab_default']; } } else { // bei Fehlern den gleichen Tab nochmal anzeigen $active_tab = $_SESSION["s"]["form"]["tab"]; } return $active_tab; } function getCurrentTab() { return $_SESSION["s"]["form"]["tab"]; }}?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -