| | |
| | | <?php |
| | | |
| | | /* |
| | | Copyright (c) 2005, Till Brehm, projektfarm Gmbh |
| | | Copyright (c) 2007, Till Brehm, projektfarm Gmbh |
| | | All rights reserved. |
| | | |
| | | Redistribution and use in source and binary forms, with or without modification, |
| | |
| | | * |
| | | * Hint: The auto increment (ID) filed of the table has not be be definied eoarately. |
| | | * |
| | | * @package form |
| | | * @author Till Brehm |
| | | * @version 1.1 |
| | | */ |
| | | |
| | | class tform { |
| | |
| | | $this->module = $module; |
| | | $wb = array(); |
| | | |
| | | include_once(ISPC_ROOT_PATH.'/lib/lang/'.$_SESSION['s']['language'].'.lng'); |
| | | if($module == '') { |
| | | if(is_file("lib/lang/".$_SESSION["s"]["language"]."_".$this->formDef["name"].".lng")) { |
| | | include_once("lib/lang/".$_SESSION["s"]["language"]."_".$this->formDef["name"].".lng"); |
| | | } |
| | | $lng_file = "lib/lang/".$_SESSION["s"]["language"]."_".$this->formDef["name"].".lng"; |
| | | if(!file_exists($lng_file)) $lng_file = "lib/lang/en_".$this->formDef["name"].".lng"; |
| | | include($lng_file); |
| | | } else { |
| | | if(is_file("../$module/lib/lang/".$_SESSION["s"]["language"]."_".$this->formDef["name"].".lng")) { |
| | | include_once("../$module/lib/lang/".$_SESSION["s"]["language"]."_".$this->formDef["name"].".lng"); |
| | | } |
| | | $lng_file = "../$module/lib/lang/".$_SESSION["s"]["language"]."_".$this->formDef["name"].".lng"; |
| | | if(!file_exists($lng_file)) $lng_file = "../$module/lib/lang/en_".$this->formDef["name"].".lng"; |
| | | include($lng_file); |
| | | } |
| | | $this->wordbook = $wb; |
| | | |
| | |
| | | $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"; |
| | | $this->errorMessage .= "Custom datasource class or function is empty<br />\r\n"; |
| | | } |
| | | } |
| | | |
| | | return $values; |
| | | |
| | | } |
| | | |
| | | //* If the parameter 'valuelimit' is set |
| | | function applyValueLimit($limit,$values) { |
| | | |
| | | global $app; |
| | | |
| | | $limit_parts = explode(':',$limit); |
| | | |
| | | //* values are limited to a comma separated list |
| | | if($limit_parts[0] == 'list') { |
| | | $allowed = explode(',',$limit_parts[1]); |
| | | } |
| | | |
| | | //* values are limited to a field in the client settings |
| | | if($limit_parts[0] == 'client') { |
| | | if($_SESSION["s"]["user"]["typ"] == 'admin') { |
| | | return $values; |
| | | } else { |
| | | $client_group_id = $_SESSION["s"]["user"]["default_group"]; |
| | | $client = $app->db->queryOneRecord("SELECT ".$limit_parts[1]." as lm FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $client_group_id"); |
| | | $allowed = explode(',',$client['lm']); |
| | | } |
| | | } |
| | | |
| | | //* values are limited to a field in the system settings |
| | | if($limit_parts[0] == 'system') { |
| | | $app->uses('getconf'); |
| | | $tmp_conf = $app->getconf->get_global_config($limit_parts[1]); |
| | | $tmp_key = $limit_parts[2]; |
| | | $allowed = $tmp_conf[$tmp_key]; |
| | | } |
| | | |
| | | $values_new = array(); |
| | | foreach($values as $key => $val) { |
| | | if(in_array($key,$allowed)) $values_new[$key] = $val; |
| | | } |
| | | |
| | | return $values_new; |
| | | } |
| | | |
| | | |
| | | /** |
| | |
| | | if(isset($field['datasource']) && is_array($field['datasource'])) { |
| | | $field["value"] = $this->getDatasourceData($field, $record); |
| | | } |
| | | |
| | | // If a limitation for the values is set |
| | | if(isset($field['valuelimit']) && is_array($field["value"])) { |
| | | $field["value"] = $this->applyValueLimit($field['valuelimit'],$field["value"]); |
| | | } |
| | | |
| | | switch ($field['formtype']) { |
| | | case 'SELECT': |
| | |
| | | $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"; |
| | | </span>\r\n"; |
| | | } |
| | | } |
| | | $new_record[$key] = $out; |
| | |
| | | |
| | | // If Datasource is set, get the data from there |
| | | if(@is_array($field['datasource'])) { |
| | | $field["value"] = $this->getDatasourceData($field, $record); |
| | | $field["value"] = $this->getDatasourceData($field, $record); |
| | | } |
| | | |
| | | // If a limitation for the values is set |
| | | if(isset($field['valuelimit']) && is_array($field["value"])) { |
| | | $field["value"] = $this->applyValueLimit($field['valuelimit'],$field["value"]); |
| | | } |
| | | |
| | | switch ($field['formtype']) { |
| | | case 'SELECT': |
| | |
| | | $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"; |
| | | </span>\r\n"; |
| | | } |
| | | } |
| | | $new_record[$key] = $out; |
| | |
| | | switch ($field['datatype']) { |
| | | case 'VARCHAR': |
| | | if(!@is_array($record[$key])) { |
| | | $new_record[$key] = (isset($record[$key]))?$app->db->quote($record[$key]):''; |
| | | $new_record[$key] = (isset($record[$key]))?$app->db->quote($record[$key]):''; |
| | | } else { |
| | | $new_record[$key] = implode($field['separator'],$record[$key]); |
| | | } |
| | |
| | | $field['regex'] .= 's'; |
| | | if(!preg_match($field['regex'], $record[$key])) { |
| | | $errmsg = $field['errmsg']; |
| | | $this->errorMessage .= $this->wordbook[$errmsg]."<br>\r\n"; |
| | | $this->errorMessage .= $this->wordbook[$errmsg]."<br />\r\n"; |
| | | } |
| | | } |
| | | |
| | |
| | | if(!preg_match($validator['regex'], $field_value)) { |
| | | $errmsg = $validator['errmsg']; |
| | | if(isset($this->wordbook[$errmsg])) { |
| | | $this->errorMessage .= $this->wordbook[$errmsg]."<br>\r\n"; |
| | | $this->errorMessage .= $this->wordbook[$errmsg]."<br />\r\n"; |
| | | } else { |
| | | $this->errorMessage .= $errmsg."<br>\r\n"; |
| | | $this->errorMessage .= $errmsg."<br />\r\n"; |
| | | } |
| | | } |
| | | break; |
| | |
| | | if($num_rec["number"] > 0) { |
| | | $errmsg = $validator['errmsg']; |
| | | if(isset($this->wordbook[$errmsg])) { |
| | | $this->errorMessage .= $this->wordbook[$errmsg]."<br>\r\n"; |
| | | $this->errorMessage .= $this->wordbook[$errmsg]."<br />\r\n"; |
| | | } else { |
| | | $this->errorMessage .= $errmsg."<br>\r\n"; |
| | | $this->errorMessage .= $errmsg."<br />\r\n"; |
| | | } |
| | | } |
| | | } else { |
| | |
| | | if($num_rec["number"] > 0) { |
| | | $errmsg = $validator['errmsg']; |
| | | if(isset($this->wordbook[$errmsg])) { |
| | | $this->errorMessage .= $this->wordbook[$errmsg]."<br>\r\n"; |
| | | $this->errorMessage .= $this->wordbook[$errmsg]."<br />\r\n"; |
| | | } else { |
| | | $this->errorMessage .= $errmsg."<br>\r\n"; |
| | | $this->errorMessage .= $errmsg."<br />\r\n"; |
| | | } |
| | | } |
| | | } |
| | |
| | | if(empty($field_value)) { |
| | | $errmsg = $validator['errmsg']; |
| | | if(isset($this->wordbook[$errmsg])) { |
| | | $this->errorMessage .= $this->wordbook[$errmsg]."<br>\r\n"; |
| | | $this->errorMessage .= $this->wordbook[$errmsg]."<br />\r\n"; |
| | | } else { |
| | | $this->errorMessage .= $errmsg."<br>\r\n"; |
| | | $this->errorMessage .= $errmsg."<br />\r\n"; |
| | | } |
| | | } |
| | | break; |
| | |
| | | if(!preg_match("/^\w+[\w.-]*\w+@\w+[\w.-]*\w+\.[a-z]{2,10}$/i", $field_value)) { |
| | | $errmsg = $validator['errmsg']; |
| | | if(isset($this->wordbook[$errmsg])) { |
| | | $this->errorMessage .= $this->wordbook[$errmsg]."<br>\r\n"; |
| | | $this->errorMessage .= $this->wordbook[$errmsg]."<br />\r\n"; |
| | | } else { |
| | | $this->errorMessage .= $errmsg."<br>\r\n"; |
| | | $this->errorMessage .= $errmsg."<br />\r\n"; |
| | | } |
| | | } |
| | | break; |
| | |
| | | if($tmpval === 0 and !empty($field_value)) { |
| | | $errmsg = $validator['errmsg']; |
| | | if(isset($this->wordbook[$errmsg])) { |
| | | $this->errorMessage .= $this->wordbook[$errmsg]."<br>\r\n"; |
| | | $this->errorMessage .= $this->wordbook[$errmsg]."<br />\r\n"; |
| | | } else { |
| | | $this->errorMessage .= $errmsg."<br>\r\n"; |
| | | $this->errorMessage .= $errmsg."<br />\r\n"; |
| | | } |
| | | } |
| | | break; |
| | |
| | | if(!is_numeric($field_value) || $field_value <= 0){ |
| | | $errmsg = $validator['errmsg']; |
| | | if(isset($this->wordbook[$errmsg])) { |
| | | $this->errorMessage .= $this->wordbook[$errmsg]."<br>\r\n"; |
| | | $this->errorMessage .= $this->wordbook[$errmsg]."<br />\r\n"; |
| | | } else { |
| | | $this->errorMessage .= $errmsg."<br>\r\n"; |
| | | $this->errorMessage .= $errmsg."<br />\r\n"; |
| | | } |
| | | } |
| | | break; |
| | | case 'ISIPV4': |
| | | $vip=1; |
| | | if(preg_match("/^[0-9]{1,3}(\.)[0-9]{1,3}(\.)[0-9]{1,3}(\.)[0-9]{1,3}$/", $field_value)){ |
| | | $groups=explode(".",$field_value); |
| | | foreach($groups as $group){ |
| | | if($group<0 OR $group>255) |
| | | $vip=0; |
| | | } |
| | | }else{$vip=0;} |
| | | if($vip==0) { |
| | | $errmsg = $validator['errmsg']; |
| | | if(isset($this->wordbook[$errmsg])) { |
| | | $this->errorMessage .= $this->wordbook[$errmsg]."<br />\r\n"; |
| | | } else { |
| | | $this->errorMessage .= $errmsg."<br />\r\n"; |
| | | } |
| | | } |
| | | break; |
| | | case 'CUSTOM': |
| | | // Calls a custom class to validate this record |
| | |
| | | $app->uses($validator_class); |
| | | $this->errorMessage .= $app->$validator_class->$validator_function($field_name, $field_value, $validator); |
| | | } else { |
| | | $this->errorMessage .= "Custom validator class or function is empty<br>\r\n"; |
| | | $this->errorMessage .= "Custom validator class or function is empty<br />\r\n"; |
| | | } |
| | | break; |
| | | default: |
| | |
| | | // checking permissions |
| | | if($this->formDef['auth'] == 'yes' && $_SESSION["s"]["user"]["typ"] != 'admin') { |
| | | if($action == "INSERT") { |
| | | if(!$this->checkPerm($primary_id,'i')) $this->errorMessage .= "Insert denied.<br>\r\n"; |
| | | if(!$this->checkPerm($primary_id,'i')) $this->errorMessage .= "Insert denied.<br />\r\n"; |
| | | } else { |
| | | if(!$this->checkPerm($primary_id,'u')) $this->errorMessage .= "Update denied.<br>\r\n"; |
| | | if(!$this->checkPerm($primary_id,'u')) $this->errorMessage .= "Update denied.<br />\r\n"; |
| | | } |
| | | } |
| | | |
| | |
| | | $escape = '`'; |
| | | } |
| | | |
| | | $diffrec = array(); |
| | | |
| | | $this->diffrec = array(); |
| | | /* |
| | | if(is_array($record_new) && count($record_new) > 0) { |
| | | foreach($record_new as $key => $val) { |
| | | if(@$record_old[$key] != $val) { |
| | |
| | | } |
| | | } |
| | | $this->diffrec = $diffrec; |
| | | |
| | | */ |
| | | |
| | | // Full diff records for ISPConfig, they have a different format then the simple diffrec |
| | | $diffrec_full = array(); |
| | |
| | | // Record has changed |
| | | $diffrec_full['old'][$key] = $val; |
| | | $diffrec_full['new'][$key] = $record_new[$key]; |
| | | $this->diffrec[$key] = array( 'new' => $record_new[$key], |
| | | 'old' => $val); |
| | | } else { |
| | | $diffrec_full['old'][$key] = $val; |
| | | $diffrec_full['new'][$key] = $val; |
| | |
| | | // Record has changed |
| | | $diffrec_full['new'][$key] = $val; |
| | | $diffrec_full['old'][$key] = $record_old[$key]; |
| | | $this->diffrec[$key] = array( 'old' => @$record_old[$key], |
| | | 'new' => $val); |
| | | } else { |
| | | $diffrec_full['new'][$key] = $val; |
| | | $diffrec_full['old'][$key] = $val; |
| | |
| | | } |
| | | } |
| | | |
| | | //$this->diffrec = $diffrec; |
| | | // Insert the server_id, if the record has a server_id |
| | | $server_id = (isset($record_old["server_id"]) && $record_old["server_id"] > 0)?$record_old["server_id"]:0; |
| | | if(isset($record_new["server_id"])) $server_id = $record_new["server_id"]; |
| | | |
| | | if(count($this->diffrec) > 0) { |
| | | $diffstr = $app->db->quote(serialize($diffrec_full)); |
| | | $diffstr = addslashes(serialize($diffrec_full)); |
| | | $username = $app->db->quote($_SESSION["s"]["user"]["username"]); |
| | | $dbidx = $this->formDef['db_table_idx'].":".$primary_id; |
| | | // $action = ($action == 'INSERT')?'i':'u'; |