--- field_table.inc.old 2005-11-03 17:38:51.000000000 +0000 +++ field_table.inc 2006-02-24 20:39:22.109375000 +0000 @@ -5,26 +5,31 @@ } function flexinode_field_table_form($field, $node) { - + // prepare default values for the table $fieldname = 'flexinode_'. $field->field_id; - if ($node->$fieldname) { - $table=$node->$fieldname; - $rows=count($table)+1; - $cols=count($table[0])+1; - } - else { - $table=array(); - $rows=8; - $cols=5; - } + $table = ($node->$fieldname) ? $node->$fieldname : array(); + $rows = ($node->$fieldname) ? count($table)+1 : $field->rows; + $options_cols = $field->options[1]; + // prepare table + $title = t($field->label); $output = ''; - $output .= form_hidden($fieldname.'_rows',$rows); + $output .= form_hidden($fieldname.'_rows', $rows); $output .= '
'; $output .= ''; - $title = t($field->label); + // header rows + $colcount = 0; + $output .= ''; + foreach ($options_cols as $column) { + if ($column != '') { + $output .= ""; + $colcount++; + } + } + $output .= ''; + // value rows for ($i = 0; $i < $rows; $i++) { $output .= ''; - for ($j = 0; $j < $cols; $j++) { + for ($j = 0; $j < $colcount; $j++) { $output .= '
$column
'; $value = (isset($table[$i]) && isset($table[$i][$j])) ? $table[$i][$j] : ''; $output .= form_textarea('', $fieldname.'_'.$i.'][', $value, 10, 3); @@ -37,7 +42,6 @@ } function flexinode_field_table_validate($field, $node) { - $fieldname = 'flexinode_'. $field->field_id; if (!isset($_POST['edit'])) { return array('value' => $node->$fieldname); @@ -62,18 +66,17 @@ return (array('value' => $value)); } -function flexinode_field_table_insert($field, $node) { +function flexinode_field_table_db_select($field) { $fieldname = 'flexinode_'. $field->field_id; - db_query("INSERT INTO {flexinode_data} (nid, field_id, serialized_data) VALUES (%d, %d, '%s')", $node->nid, $field->field_id, serialize($node->$fieldname)); + return $fieldname .'.serialized_data AS '. $fieldname; } -function flexinode_field_table_db_select($field) { +function flexinode_field_table_insert($field, $node) { $fieldname = 'flexinode_'. $field->field_id; - return $fieldname .'.serialized_data AS '. $fieldname; + db_query("INSERT INTO {flexinode_data} (nid, field_id, serialized_data) VALUES (%d, %d, '%s')", $node->nid, $field->field_id, serialize($node->$fieldname)); } function flexinode_field_table_load($field, $node) { - $fieldname = 'flexinode_'. $field->field_id; if (isset($table_phase)) $table_phase++; else $table_phase=0; return unserialize($node->$fieldname); @@ -84,6 +87,15 @@ $fieldname = 'flexinode_'. $field->field_id; $table = $node->$fieldname; $output = ""; + // header + $output .= ''; + foreach ($field->options[1] as $column) { + if ($column != '') { + $output .= ""; + } + } + $output .= ''; + // values $i=0; foreach ($table as $row) { $output .= ''; @@ -93,10 +105,52 @@ return $output; } +function flexinode_field_table_config($field, $edit) { + // default number of rows that will be available in the table + $form .= form_textfield(t('Default number of rows'), 'rows', $edit['rows'], 60, 10); + + // options[1] has the array of columns available to the table + $addmore = 2; + if ($edit['options']) { + foreach ($edit['options'][1] as $column) { + $column_fields .= form_textfield('', 'options][1][', $column, 60, 128); + $addmore += ($column == '' ? -1 : 1); + } + } + for($i = 0; $i < $addmore; $i++) { + $column_fields .= form_textfield('', 'options][1][', '', 60, 128); + } + $column_fields .= form_submit(t('More')); + $form .= form_group(t('Columns'), $column_fields, t('Definition of the table columns. For more columns, click "More".')); + + // return this custom options + return $form; +} + +/** + * @addtogroup themeable + * @{ + */ + +/** + * Format a single-line text field for display in a node. + * + * @param field_id + * Which field is being displayed (useful when overriding this function + * if you want to style one particular field differently). + * @param label + * The label for the field as displayed on the node form. + * @param value + * The value that the user entered for the field. + * @param formatted_value + * The value that the user entered for the field as pre-formatted by the module. + */ function theme_flexinode_table($field_id, $label, $value, $formatted_value) { $output = theme('form_element', $label, $formatted_value); $output = '
'. $output .'
'; return $output; } +/** @} End of addtogroup themeable */ + ?>
$column
'.implode('',$row).'