Index: survey.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/survey/survey.module,v
retrieving revision 1.3
diff -u -r1.3 survey.module
--- survey.module	27 Nov 2004 02:10:33 -0000	1.3
+++ survey.module	4 Mar 2005 22:01:11 -0000
@@ -1,5 +1,5 @@
 <?php
-// $Id: survey.module,v 1.3 2004/11/27 02:10:33 walkah Exp $
+// $Id: survey.module,v 1.3.2.1 2005/02/16 02:07:58 walkah Exp $
 
 /**
  * Implementation of hook_help
@@ -50,6 +50,8 @@
         $items[] = array('path' => 'node/'.$node->nid.'/form', 'title' => t('form'),
                          'callback' => 'survey_fields', 'access' => user_access('maintain surveys'),
                          'type' => MENU_LOCAL_TASK, 'weight' => 3);
+        $items[] = array('path' => 'node/'. $node->nid.'/form/list', 'title' => t('list'),
+                         'type' => MENU_DEFAULT_LOCAL_TASK);
         $items[] = array('path' => 'node/'.$node->nid.'/form/edit', 'title' => t('add field'),
                          'callback' => 'survey_fields_edit', 'access' => user_access('maintain surveys'),
                          'type' => MENU_LOCAL_TASK, 'weight' => 4);
@@ -60,6 +62,8 @@
         $items[] = array('path' => 'node/'.$node->nid.'/responses', 'title' => t('responses'),
                          'callback' => 'survey_responses', 'access' => user_access('maintain surveys'),
                          'type' => MENU_LOCAL_TASK, 'weight' => 5);
+        $items[] = array('path' => 'node/'. $node->nid.'/responses/list', 'title' => t('list'),
+                         'type' => MENU_DEFAULT_LOCAL_TASK);
         $items[] = array('path' => 'node/'.$node->nid.'/responses/excel', 'title' => t('download to excel'),
                          'callback' => 'survey_excel', 'access' => user_access('maintain surveys'),
                          'type' => MENU_LOCAL_TASK, 'weight' => 1);
@@ -111,6 +115,7 @@
   $output .= filter_form('format', $node->format);
   $output .= form_textfield(t('Path for "thank you" page'), "result_page", $node->result_page, 70, 70, t("This page is displayed after the form is submitted.  If you are not using clean URLs, specify the part after '?q='.  If unsure, specify nothing."));
   $output .= form_textfield(t('Email address'), "email", $node->email, 70, 70, t("This email address will receive a copy of each survey submission"));
+  $output .= form_checkbox(t('Anonymous Submissions'), 'anonymous', 1, $node->anonymous);
 
   $output .= form_hidden('fid', $node->fid);
 
@@ -142,12 +147,12 @@
 function survey_insert(&$node) {
   // first thing to do is create a form to associate to this survey
   $node->fid = forms_create('survey');
-  db_query("INSERT INTO {survey} (nid, fid, email, result_page) VALUES (%d, %d, '%s', '%s')",
-           $node->nid, $node->fid, $node->email, $node->result_page);
+  db_query("INSERT INTO {survey} (nid, fid, email, result_page, anonymous) VALUES (%d, %d, '%s', '%s', %d)",
+           $node->nid, $node->fid, $node->email, $node->result_page, $node->anonymous);
 }
 
 function survey_update(&$node) {
-  db_query("UPDATE {survey} SET email='%s', result_page='%s' WHERE nid=%d", $node->email, $node->result_page, $node->nid);
+  db_query("UPDATE {survey} SET email='%s', result_page='%s', anonymous=%d WHERE nid=%d", $node->email, $node->result_page, $node->anonymous, $node->nid);
 }
 
 function survey_delete(&$node) {
@@ -219,18 +224,29 @@
 
 function survey_submit() {
   global $user;
-  
+  $uid = $user->uid;
+  $username = $user->name;
   $survey = node_load(array('nid' => arg(2)));
 
   $error = forms_validate($survey->form, $_POST['edit']);
   if (!$error) {
+    if($survey->anonymous) {
+      $uid = 0;
+      $username = variable_get('anonymous', t('Anonymous'));
+    }
     $responses = array();
     $rid = db_next_id("{survey_responses}_rid");
-    db_query("INSERT INTO {survey_responses} (rid, nid, uid, created) VALUES (%d, %d, %d, %d)", $rid, $survey->nid, $user->uid, time());
+    db_query("INSERT INTO {survey_responses} (rid, nid, uid, created) VALUES (%d, %d, %d, %d)", $rid, $survey->nid, $uid, time());
     foreach ($survey->form->fields as $field) {
       if ($_POST['edit'][$field->name]) {
-        $responses[$field->title] = $_POST['edit'][$field->name];
-        db_query("INSERT INTO {survey_fields} (rid, ffid, value) VALUES (%d, %d, '%s')", $rid, $field->ffid, $_POST['edit'][$field->name]);
+        if (is_array($_POST['edit'][$field->name])) {
+          $value = implode(';', $_POST['edit'][$field->name]);
+        }
+        else {
+          $value = $_POST['edit'][$field->name];
+        }
+        $responses[$field->title] = $value;
+        db_query("INSERT INTO {survey_fields} (rid, ffid, value) VALUES (%d, %d, '%s')", $rid, $field->ffid, $value);
       }
     }
 
@@ -241,7 +257,7 @@
         $body.= $value . "\n\n";
       }
       $body.= "-----\n";
-      $body.= t("Submitted by %name on %date\n", array('%name' => $user->name . ' ('.url('user/'.$user->uid, NULL, NULL, TRUE) .')', '%date' => format_date(time())));
+      $body.= t("Submitted by %name on %date\n", array('%name' => $username . ' ('.url('user/'.$uid, NULL, NULL, TRUE) .')', '%date' => format_date(time())));
 
       $from = variable_get('site_mail', ini_get('sendmail_from'));
       $headers = "From: $from\nReply-to: $from\nX-Mailer: Drupal\nReturn-path: $from\nErrors-to: $from";      
@@ -254,8 +270,12 @@
     else {
       drupal_set_message(t('Thank you for your submission'), 'success');
     }
+    
+    drupal_goto('node/'.$survey->nid);
+  }
+  else {
+    print(theme('page', node_view($survey, 0, 1)));
   }
-  drupal_goto('node/'.$survey->nid);
 }
 
 function survey_responses() {
@@ -274,7 +294,7 @@
   }
   else {
     $header = array(t('Submitted by'), t('Date'), '');
-    $res = pager_query("SELECT u.uid, u.name, r.created, r.rid FROM {users} u INNER JOIN {survey_responses} r ON r.uid=u.uid ORDER BY created DESC", 50);
+    $res = pager_query("SELECT u.uid, u.name, r.created, r.rid FROM {users} u INNER JOIN {survey_responses} r ON r.uid=u.uid WHERE r.nid=%d ORDER BY created DESC", 50, NULL, NULL, $survey->nid);
     while ($response = db_fetch_object($res)) {
       $rows[] = array(format_name($response), format_date($response->created),
                       l(t('view'), 'node/'.$survey->nid.'/responses/'.$response->rid));
