@@ -156,7 +156,8 @@ function loadFormDef($file,$module = '') {
156156 */
157157 function decode ($ record ,$ tab ) {
158158 if (!is_array ($ this ->formDef ['tabs ' ][$ tab ])) $ app ->error ("Tab ist leer oder existiert nicht (TAB: $ tab). " );
159- if (is_array ($ record )) {
159+ $ new_record = '' ;
160+ if (is_array ($ record )) {
160161 foreach ($ this ->formDef ['tabs ' ][$ tab ]['fields ' ] as $ key => $ field ) {
161162 switch ($ field ['datatype ' ]) {
162163 case 'VARCHAR ' :
@@ -191,6 +192,7 @@ function decode($record,$tab) {
191192 }
192193
193194 }
195+
194196 return $ new_record ;
195197 }
196198
@@ -216,7 +218,11 @@ function getDatasourceData($field, $record) {
216218 $ querystring = str_replace ("{GROUPID} " ,$ _SESSION ["s " ]["user " ]["default_group " ],$ querystring );
217219 $ querystring = str_replace ("{GROUPS} " ,$ _SESSION ["s " ]["user " ]["groups " ],$ querystring );
218220 $ table_idx = $ this ->formDef ['db_table_idx ' ];
219- $ querystring = str_replace ("{RECORDID} " ,$ record [$ table_idx ],$ querystring );
221+
222+ $ tmp_recordid = (isset ($ record [$ table_idx ]))?$ record [$ table_idx ]:0 ;
223+ $ querystring = str_replace ("{RECORDID} " ,$ tmp_recordid ,$ querystring );
224+ unset($ tmp_recordid );
225+
220226 $ querystring = str_replace ("{AUTHSQL} " ,$ this ->getAuthSQL ('r ' ),$ querystring );
221227
222228 // Getting the records
@@ -273,14 +279,14 @@ function getHTML($record, $tab, $action = 'NEW') {
273279 $ val = $ record [$ key ];
274280
275281 // If Datasource is set, get the data from there
276- if (is_array ($ field ['datasource ' ])) {
282+ if (isset ( $ field [ ' datasource ' ]) && is_array ($ field ['datasource ' ])) {
277283 $ field ["value " ] = $ this ->getDatasourceData ($ field , $ record );
278284 }
279285
280286 switch ($ field ['formtype ' ]) {
281287 case 'SELECT ' :
288+ $ out = '' ;
282289 if (is_array ($ field ['value ' ])) {
283- $ out = '' ;
284290 foreach ($ field ['value ' ] as $ k => $ v ) {
285291 $ selected = ($ k == $ val )?' SELECTED ' :'' ;
286292 $ out .= "<option value=' $ k' $ selected> $ v</option> \r\n" ;
@@ -362,7 +368,7 @@ function getHTML($record, $tab, $action = 'NEW') {
362368 foreach ($ this ->formDef ['tabs ' ][$ tab ]['fields ' ] as $ key => $ field ) {
363369
364370 // If Datasource is set, get the data from there
365- if (is_array ($ field ['datasource ' ])) {
371+ if (@ is_array ($ field ['datasource ' ])) {
366372 $ field ["value " ] = $ this ->getDatasourceData ($ field , $ record );
367373 }
368374
@@ -371,8 +377,9 @@ function getHTML($record, $tab, $action = 'NEW') {
371377 if (is_array ($ field ['value ' ])) {
372378 $ out = '' ;
373379 foreach ($ field ['value ' ] as $ k => $ v ) {
374- $ selected = ($ k == $ val )?' SELECTED ' :'' ;
375- $ out .= "<option value=' $ k' $ selected> $ v</option> \r\n" ;
380+ //$selected = ($k == $val)?' SELECTED':'';
381+ $ selected = '' ;
382+ $ out .= "<option value=' $ k' $ selected> $ v</option> \r\n" ;
376383 }
377384 }
378385 $ new_record [$ key ] = $ out ;
@@ -464,12 +471,12 @@ function encode($record,$tab) {
464471 if (is_array ($ record )) {
465472 foreach ($ this ->formDef ['tabs ' ][$ tab ]['fields ' ] as $ key => $ field ) {
466473
467- if (is_array ($ field ['validators ' ])) $ this ->validateField ($ key , $ record [$ key ], $ field ['validators ' ]);
474+ if (isset ( $ field [ ' validators ' ]) && is_array ($ field ['validators ' ])) $ this ->validateField ($ key , ( isset ( $ record [$ key ]))? $ record [ $ key ]: '' , $ field ['validators ' ]);
468475
469476 switch ($ field ['datatype ' ]) {
470477 case 'VARCHAR ' :
471- if (!is_array ($ record [$ key ])) {
472- $ new_record [$ key ] = addslashes ($ record [$ key ]);
478+ if (!@ is_array ($ record [$ key ])) {
479+ $ new_record [$ key ] = ( isset ( $ record [ $ key ]))? addslashes ($ record [$ key ]): '' ;
473480 } else {
474481 $ new_record [$ key ] = implode ($ field ['separator ' ],$ record [$ key ]);
475482 }
@@ -490,7 +497,7 @@ function encode($record,$tab) {
490497 }
491498 break ;
492499 case 'INTEGER ' :
493- $ new_record [$ key ] = intval ($ record [$ key ]);
500+ $ new_record [$ key ] = ( isset ( $ record [ $ key ]))? intval ($ record [$ key ]): 0 ;
494501 //if($new_record[$key] != $record[$key]) $new_record[$key] = $field['default'];
495502 //if($key == 'refresh') die($record[$key]);
496503 break ;
@@ -503,7 +510,7 @@ function encode($record,$tab) {
503510 }
504511
505512 // The use of the field value is deprecated, use validators instead
506- if ($ field ['regex ' ] != '' ) {
513+ if (isset ( $ field [ ' regex ' ]) && $ field ['regex ' ] != '' ) {
507514 // Enable that "." matches also newlines
508515 $ field ['regex ' ] .= 's ' ;
509516 if (!preg_match ($ field ['regex ' ], $ record [$ key ])) {
@@ -531,6 +538,8 @@ function validateField($field_name, $field_value, $validators) {
531538
532539 global $ app ;
533540
541+ $ escape = '` ' ;
542+
534543 // loop trough the validators
535544 foreach ($ validators as $ validator ) {
536545
@@ -845,6 +854,7 @@ function showForm() {
845854
846855 function getDataRecord ($ primary_id ) {
847856 global $ app ;
857+ $ escape = '` ' ;
848858 $ sql = "SELECT * FROM " .$ escape .$ this ->formDef ['db_table ' ].$ escape ." WHERE " .$ this ->formDef ['db_table_idx ' ]." = " .$ primary_id ;
849859 return $ app ->db ->queryOneRecord ($ sql );
850860 }
@@ -925,7 +935,7 @@ function datalogSave($action,$primary_id, $record_old, $record_new) {
925935 */
926936
927937 // Insert the server_id, if the record has a server_id
928- $ server_id = ($ record_old ["server_id " ] > 0 )?$ record_old ["server_id " ]:0 ;
938+ $ server_id = (isset ( $ record_old [ " server_id " ]) && $ record_old ["server_id " ] > 0 )?$ record_old ["server_id " ]:0 ;
929939 if (isset ($ record_new ["server_id " ])) $ server_id = $ record_new ["server_id " ];
930940
931941 if (count ($ this ->diffrec ) > 0 ) {
@@ -1000,7 +1010,7 @@ function getNextTab() {
10001010 // Welcher Tab wird angezeigt
10011011 if ($ this ->errorMessage == '' ) {
10021012 // wenn kein Fehler vorliegt
1003- if ($ _REQUEST ["next_tab " ] != '' ) {
1013+ if (isset ( $ _REQUEST [ " next_tab " ]) && $ _REQUEST ["next_tab " ] != '' ) {
10041014 // wenn nächster Tab bekannt
10051015 $ active_tab = $ _REQUEST ["next_tab " ];
10061016 } else {
0 commit comments