$tpl = new MSDTemplate(); $tpl->set_filenames(array('show' => './tpl/sqlbrowser/sql_record_update_inputmask.tpl')); $target = $mode == "searchedit" ? '?mode=searchedit' : '?mode=update'; // jump back to search hit list after saving $fields = getExtendedFieldInfo($db, $tablename); $sqledit = "SELECT * FROM `{$tablename}` WHERE " . $recordkey; $res = MSD_query($sqledit); $record = mysqli_fetch_array($res, MYSQLI_ASSOC); // get the record $num = sizeof($record); // get the nr of fields of the record // iterate fields $x = 0; $fieldnames = ''; foreach ($record as $field => $fieldvalue) { $fieldnames .= $field . '|'; $tpl->assign_block_vars('ROW', array('CLASS' => $x % 2 ? 1 : 2, 'FIELD_NAME' => $field, 'FIELD_VALUE' => my_quotes($fieldvalue), 'FIELD_ID' => correct_post_index($field))); if ('YES' == $fields[$field]['null']) { //field is nullable - precheck checkbox if value is null $tpl->assign_block_vars('ROW.IS_NULLABLE', array('NULL_CHECKED' => is_null($fieldvalue) ? ' checked="checked"' : '')); } $type = strtoupper($fields[$field]['type']); if (in_array($type, array('BLOB', 'TEXT'))) { $tpl->assign_block_vars('ROW.IS_TEXTAREA', array()); } else { $tpl->assign_block_vars('ROW.IS_TEXTINPUT', array()); } $x++; } $tpl->assign_vars(array('HIDDEN_FIELDS' => FormHiddenParams(), 'FIELDNAMES' => substr($fieldnames, 0, strlen($fieldnames) - 1), 'SQL_STATEMENT' => my_quotes($sql['sql_statement']), 'RECORDKEY' => my_quotes($recordkey), 'TARGET' => $target)); $tpl->pparse('show');
} $sqlu = substr($sqlu, 0, strlen($sqlu) - 2) . ' WHERE ' . $recordkey; $res = MSD_query($sqlu); $msg = '<p class="success">' . $lang['L_SQL_RECORDUPDATED'] . '</p>'; if (isset($mode) && $mode == 'searchedit') { $search = 1; } $sql_to_display_data = 1; } // handle insert action after submitting it if (isset($_POST['insert'])) { GetPostParams(); $f = explode('|', $_POST['feldnamen']); $sqlu = 'INSERT INTO `' . $tablename . '` SET '; for ($i = 0; $i < count($f); $i++) { $index = isset($_POST[$f[$i]]) ? $f[$i] : correct_post_index($f[$i]); if (isset($_POST['null_' . $index])) { // Yes, set it to NULL in Querystring $sqlu .= '`' . $f[$i] . '`=NULL, '; } else { $sqlu .= '`' . $f[$i] . '`=\'' . db_escape(convert_to_latin1($_POST[$index])) . '\', '; } } $sqlu = substr($sqlu, 0, strlen($sqlu) - 2); $res = MSD_query($sqlu); $msg = '<p class="success">' . $lang['L_SQL_RECORDINSERTED'] . '</p>'; $sql_to_display_data = 1; } if (isset($_POST['cancel'])) { GetPostParams(); }
<?php // insert a new record $tpl = new MSDTemplate(); $tpl->set_filenames(array('show' => './tpl/sqlbrowser/sql_record_insert_inputmask.tpl')); $sqledit = "SHOW FIELDS FROM `{$tablename}`"; $res = MSD_query($sqledit); $num = mysql_numrows($res); $feldnamen = ""; for ($x = 0; $x < $num; $x++) { $row = mysql_fetch_object($res); $feldnamen .= $row->Field . '|'; $tpl->assign_block_vars('ROW', array('CLASS' => $x % 2 ? 1 : 2, 'FIELD_NAME' => $row->Field, 'FIELD_ID' => correct_post_index($row->Field))); $type = strtoupper($row->Type); if (strtoupper($row->Null) == 'YES') { //field is nullable $tpl->assign_block_vars('ROW.IS_NULLABLE', array()); } if (in_array($type, array('BLOB', 'TEXT'))) { $tpl->assign_block_vars('ROW.IS_TEXTAREA', array()); } else { $tpl->assign_block_vars('ROW.IS_TEXTINPUT', array()); } } $tpl->assign_vars(array('HIDDEN_FIELDS' => FormHiddenParams(), 'FIELDNAMES' => substr($feldnamen, 0, strlen($feldnamen) - 1), 'SQL_STATEMENT' => my_quotes($sql['sql_statement']))); $tpl->pparse('show');