$field_row['field_type'] = 'TEXT'; // default storage type. $field_row['field_id'] = $_REQUEST['field_id']; // set the template tag for the field $fields = JB_schema_get_static_fields(5); $field_row['template_tag'] = $fields[$_REQUEST['field_id']]['template_tag']; if ($fields[$_REQUEST['field_id']]['field_type']) { $field_row['field_type'] = $fields[$_REQUEST['field_id']]['field_type']; } else { $field_row['field_type'] = 'TEXT'; // default storage type. } } if ($field_row['template_tag'] == '') { // need to fix the template tag! $field_row['template_tag'] = JB_generate_template_tag(5); // update form field $sql = "UPDATE form_fields SET `template_tag`='" . jb_escape_sql($field_row['template_tag']) . "' WHERE form_id=5 AND field_id='" . jb_escape_sql($_REQUEST['field_id']) . "'"; JB_mysql_query($sql); } if ($_REQUEST['admin_only'] == false) { $_REQUEST['admin_only'] = 'N'; } if ($_REQUEST['linked'] == false) { $_REQUEST['linked'] = 'N'; } if ($_REQUEST['column_id'] != '') { $col_str = '`column_id`,'; $col_cal = '\'' . $_REQUEST['column_id'] . '\','; } $sql = "REPLACE INTO form_lists ({$col_str} `template_tag`, `field_id`, `sort_order`, `field_type`, `form_id`, `admin`, `truncate_length`, `linked`, `clean_format`, `is_bold`, `no_wrap`, `is_sortable`) VALUES ({$col_cal} '" . jb_escape_sql($field_row['template_tag']) . "', '" . jb_escape_sql($field_row['field_id']) . "', '" . jb_escape_sql($_REQUEST['sort_order']) . "', '" . jb_escape_sql($field_row['field_type']) . "', '5', '" . jb_escape_sql($_REQUEST['admin_only']) . "', '" . jb_escape_sql($_REQUEST['truncate_length']) . "', '" . jb_escape_sql($_REQUEST['linked']) . "', '" . jb_escape_sql($_REQUEST['clean_format']) . "', '" . jb_escape_sql($_REQUEST['is_bold']) . "', '" . jb_escape_sql($_REQUEST['no_wrap']) . "', '" . jb_escape_sql($_REQUEST['is_sortable']) . "')";
function JB_generate_template_tag($form_id) { // generate a random template tag. This help to fix older versions of the JB where some fields did not have a template tag... // generate a tag. $template_tag = ''; while (strlen($template_tag) < 4) { $template_tag .= chr(rand(97, 122)); } $unique = false; $sql = "select field_id from form_fields where template_tag='" . JB_escape_sql($template_tag) . "' and form_id='" . JB_escape_sql($form_id) . "' "; $result = JB_mysql_query($sql) or die($sql . mysql_error()); if (mysql_num_rows($result) == 0) { $unique = true; } // check if it is unique if ($unique) { return $template_tag; } else { return JB_generate_template_tag($form_id); // try again } }