';
- for ($j = 0; $j < $cols; $j++) {
+ for ($j = 0; $j < $colcount; $j++) {
$output .= '';
$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 .= "| $column | ";
+ }
+ }
+ $output .= ' ';
+ // values
$i=0;
foreach ($table as $row) {
$output .= '| '.implode(' | ',$row).' | ';
@@ -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 */
+
?>
|