Only in survey/: orig Common subdirectories: survey/po and survey.patch/po diff -up survey/survey.install survey.patch/survey.install --- survey/survey.install 2007-05-11 08:49:09.000000000 -0700 +++ survey.patch/survey.install 2007-05-11 08:27:22.000000000 -0700 @@ -13,6 +13,7 @@ function survey_install() { fid int(11) not null, email text, result_page text, + layout text, primary key(nid) ) /*!40100 DEFAULT CHARACTER SET utf8 */;"); diff -up survey/survey.module survey.patch/survey.module --- survey/survey.module 2007-05-11 08:49:09.000000000 -0700 +++ survey.patch/survey.module 2007-05-11 08:46:42.000000000 -0700 @@ -83,8 +83,11 @@ function survey_menu($may_cache) { 'callback' => 'survey_excel', 'access' => user_access('maintain surveys'), 'callback arguments' => array($node), 'type' => MENU_LOCAL_TASK, 'weight' => 1); + $items[] = array('path' => 'node/' . $node->nid . '/layout', 'title' => t('layout'), + 'callback' => 'survey_layout', 'access' => user_access('maintain surveys')); } } + } return $items; } @@ -180,15 +183,68 @@ function survey_form(&$node) { */ function survey_view(&$node, $teaser = 0, $page = 0) { $node = node_prepare($node, $teaser); - $node->readmore = TRUE; - if ($page) { + if($node->layout != ''){ + $node->layout = stripslashes($node->layout); $node->content['survey'] = array( - '#value' => survey_response(array('nid' => $node->nid)), - '#weight' => 1); + '#value' => drupal_get_form('survey_layout_form_view', $node), + '#weight' => 1 + ); + } + else{ + $node->readmore = TRUE; + if ($page) { + $node->content['survey'] = array( + '#value' => survey_response(array('nid' => $node->nid)), + '#weight' => 1); + } } return $node; } +function survey_layout_form_view_submit($form_id, $form_values) { + return survey_response_form_submit($form_id, $form_values); +} + +/** + * Form callback function to create a special layout for a form + * if defined in the node. + */ +function survey_layout_form_view($node){ + //Split the layout on field id placeholders (e.g. {22}). + $layout_chunks = preg_split('/\{\d*\}/', $node->layout); + + $form = array(); + //$form['#action'] = url('survey/submit/');// . $node->nid); + + $max = sizeof($node->form->fields); + $chunk_count = 0; + + //Iterate over form fields and add prefixes and suffixes as necessary + //to shove the fields into the layout template given. + foreach ($node->form->fields as $idx => $field) { + $real_field = forms_get_field($field); + $real_field['#prefix'] = $layout_chunks[$chunk_count]; + //Last item, so add suffix. + if($chunk_count == $max - 1){ + $real_field['#suffix'] = $layout_chunks[$max]; + } + $form['field-' . $idx] = $real_field; + $chunk_count++; + } + + $form['nid'] = array( + '#type' => 'hidden', + '#value' => $node->nid + ); + $form['submit'] = array( + '#id' => 'submit', + '#type' => 'submit', + '#value' => t('Submit'), + '#weight' => 10000 + ); + return $form; +} + function survey_response($values) { $output = drupal_get_form('survey_response_form', $values); return $output; @@ -209,6 +265,7 @@ function survey_response_form($values) { function survey_load($node) { $survey = db_fetch_object(db_query("SELECT * FROM {survey} WHERE nid=%d", $node->nid)); $survey->form = forms_load(array('fid' => $survey->fid)); + $survey->layout = stripslashes($survey->layout); return $survey; } @@ -230,6 +287,16 @@ function survey_delete(&$node) { } /** + * Update the layout for a survey + */ +function survey_layout(){ + $nid = arg(1); + db_query('UPDATE {survey} SET layout = "%s" WHERE nid = %d', addslashes($_POST['layout']), $nid); + drupal_set_message(t('Form layout updated')); + drupal_goto('node/' . $nid . '/form'); +} + +/** * Show the fields for a survey */ function survey_fields() { @@ -237,20 +304,37 @@ function survey_fields() { $node = node_load(array('nid' => $nid)); foreach ($node->form->fields as $field) { - $rows[] = array(array('data' => $field->title), + $rows[] = array(array('data' => '{' . $field->ffid . '} ' . $field->title), array('data' => $field->type), array('data' => l(t('edit'), 'node/'.$nid.'/form/edit/'.$field->ffid)), array('data' => l(t('delete'), 'node/'.$nid.'/form/delete/'.$field->ffid))); } + if ($rows) { $output = theme('table', array(t('field'), t('type'), ' ', ' '), $rows); } else { $output = t('No fields defined'); } + $output .= drupal_get_form('survey_layout_form', $node); return $output; } +function survey_layout_form($node){ + $form['#action'] = url('node/' . $node->nid . '/layout'); + $form['layout'] = array( + '#id' => 'layout', + '#type' => 'textarea', + '#title' => t('Layout'), + '#default_value' => $node->layout, + '#rows' => 10, + '#cols' => 60, + '#description' => t('Optionally, enter a layout for the form, substituting bracketed numbers (e.g. "{22}") where form fields should appear.') + ); + $form['submit'] = array('#id' => 'submit', '#type' => 'submit', '#value' => t('Submit')); + return $form; +} + function survey_fields_edit($node, $ffid = NULL) { if ($ffid) { $field = db_fetch_object(db_query("SELECT * FROM {form_fields} WHERE ffid=%d", $ffid)); Only in survey/: survey.module.layout.patch Only in survey.patch/: test