From 9026a458a084991bbda2d04b2207832cd878f2fb Mon Sep 17 00:00:00 2001
From: pedro_morgan <pedro_morgan@ispconfig3>
Date: Sat, 18 Aug 2007 22:59:59 -0400
Subject: [PATCH] * Ammended config in with $DB connection idea * Minor tweaks to app * Made $conf global in teh tempalte class (its not global in the loader function either)
---
interface/lib/classes/tform.inc.php | 62 ++++++++++++++++++++++++-------
1 files changed, 48 insertions(+), 14 deletions(-)
diff --git a/interface/lib/classes/tform.inc.php b/interface/lib/classes/tform.inc.php
index 81810b9..c36a451 100644
--- a/interface/lib/classes/tform.inc.php
+++ b/interface/lib/classes/tform.inc.php
@@ -539,7 +539,11 @@
$validator['regex'] .= 's';
if(!preg_match($validator['regex'], $field_value)) {
$errmsg = $validator['errmsg'];
- $this->errorMessage .= $this->wordbook[$errmsg]."<br>\r\n";
+ if(isset($this->wordbook[$errmsg])) {
+ $this->errorMessage .= $this->wordbook[$errmsg]."<br>\r\n";
+ } else {
+ $this->errorMessage .= $errmsg."<br>\r\n";
+ }
}
break;
case 'UNIQUE':
@@ -766,9 +770,7 @@
$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);
+
return $sql;
}
@@ -839,11 +841,16 @@
// Set Wordbook for this form
$app->tpl->setVar($this->wordbook);
- }
+ }
+ function getDataRecord($primary_id) {
+ global $app;
+ $sql = "SELECT * FROM ".$escape.$this->formDef['db_table'].$escape." WHERE ".$this->formDef['db_table_idx']." = ".$primary_id;
+ return $app->db->queryOneRecord($sql);
+ }
+
-
- function datalogSave($action,$primary_id,$record_new) {
+ function datalogSave($action,$primary_id, $record_old, $record_new) {
global $app,$conf;
// F�ge Backticks nur bei unvollst�ndigen Tabellennamen ein
@@ -852,17 +859,19 @@
} else {
$escape = '`';
}
-
- if($action == "UPDATE") {
+
+ /*
+ if($action == "UPDATE" or $action == "DELETE") {
$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)) {
+ if(is_array($record_new) && count($record_new) > 0) {
foreach($record_new as $key => $val) {
if($record_old[$key] != $val) {
// Record has changed
@@ -870,13 +879,22 @@
'new' => $val);
}
}
+ } elseif(is_array($record_old)) {
+ foreach($record_old as $key => $val) {
+ if($record_new[$key] != $val) {
+ // Record has changed
+ $diffrec[$key] = array('new' => $record_new[$key],
+ 'old' => $val);
+ }
+ }
}
$this->diffrec = $diffrec;
+
// Full diff records for ISPConfig, they have a different format then the simple diffrec
$diffrec_full = array();
- if(is_array($record_old)) {
+ if(is_array($record_old) && count($record_old) > 0) {
foreach($record_old as $key => $val) {
if(isset($record_new[$key]) && $record_new[$key] != $val) {
// Record has changed
@@ -885,6 +903,17 @@
} else {
$diffrec_full['old'][$key] = $val;
$diffrec_full['new'][$key] = $val;
+ }
+ }
+ } elseif(is_array($record_new)) {
+ foreach($record_new as $key => $val) {
+ if(isset($record_new[$key]) && $record_old[$key] != $val) {
+ // Record has changed
+ $diffrec_full['new'][$key] = $val;
+ $diffrec_full['old'][$key] = $record_old[$key];
+ } else {
+ $diffrec_full['new'][$key] = $val;
+ $diffrec_full['old'][$key] = $val;
}
}
}
@@ -903,7 +932,11 @@
$diffstr = $app->db->quote(serialize($diffrec_full));
$username = $app->db->quote($_SESSION["s"]["user"]["username"]);
$dbidx = $this->formDef['db_table_idx'].":".$primary_id;
- $action = ($action == 'INSERT')?'i':'u';
+ // $action = ($action == 'INSERT')?'i':'u';
+
+ if($action == 'INSERT') $action = 'i';
+ if($action == 'UPDATE') $action = 'u';
+ if($action == 'DELETE') $action = 'd';
$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);
}
@@ -916,9 +949,10 @@
if($_SESSION["s"]["user"]["typ"] == 'admin') {
return '1';
} else {
- $sql = '(';
+ $groups = ( $_SESSION["s"]["user"]["groups"] ) ? $_SESSION["s"]["user"]["groups"] : 0;
+ $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_groupid IN (".$groups.") AND sys_perm_group like '%$perm%') OR ";
$sql .= "sys_perm_other like '%$perm%'";
$sql .= ')';
--
Gitblit v1.9.1