Index: webform_report.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/webform/webform_report.inc,v retrieving revision 1.15.2.11.2.4 diff -u -r1.15.2.11.2.4 webform_report.inc --- webform_report.inc 22 Feb 2008 17:26:45 -0000 1.15.2.11.2.4 +++ webform_report.inc 29 Mar 2008 23:34:51 -0000 @@ -13,8 +13,10 @@ * Retrieve lists of submissions for a given webform. */ function webform_results_submissions($node) { + global $user; + $header = theme('webform_results_submissions_header', $node); - $submissions = webform_get_submissions($node->nid, $header); + $submissions = user_access('access webform results') ? webform_get_submissions($node->nid, $header) : webform_get_submissions($node->nid, $header, $user->uid); return theme('webform_results_submissions', $node, $submissions); } @@ -25,13 +27,17 @@ * use it for sorting the results. */ function theme_webform_results_submissions_header($node) { - return array( + $columns = array( array('data' => t('#'), 'field' => 'sid', 'sort' => 'asc'), array('data' => t('Submitted'), 'field' => 'submitted'), - array('data' => t('User'), 'field' => 'name'), - array('data' => t('IP Address'), 'field' => 'remote_addr'), - array('data' => t('Operations'), 'colspan' => user_access('clear webform results') ? '3' : '2'), ); + if (user_access("access webform results")) { + $columns[] = array('data' => t('User'), 'field' => 'name'); + $columns[] = array('data' => t('IP Address'), 'field' => 'remote_addr'); + } + $columns[] = array('data' => t('Operations'), 'colspan' => 3); + + return $columns; } /** @@ -53,18 +59,18 @@ $row = array( $sid, format_date($submission->submitted, 'small'), - theme('username', $submission), - $submission->remote_addr, - l(t('View'), "node/$node->nid/submission/$sid"), ); + if (user_access('access webform results')) { + $row[] = theme('username', $submission); + $row[] = $submission->remote_addr; + } + $row[] = l(t('View'), "node/$node->nid/submission/$sid"); if ((user_access("edit own webform submissions") && ($user->uid == $submission->uid)) || user_access("edit webform submissions")) { $row[] = l(t('Edit'), "node/$node->nid/submission/$sid/edit"); + $row[] = l(t('Delete'), "node/$node->nid/submission/$sid/delete"); } else { - $row[] = t('Edit'); - } - if (user_access('clear webform results')) { - $row[] = l(t('Delete'), "node/$node->nid/submission/$sid/delete"); + $row[count($row) - 1] = array('data' => $row[count($row) - 1], 'colspan' => 3); } $rows[] = $row; } Index: webform.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/webform/webform.module,v retrieving revision 1.113.2.70.2.31 diff -u -r1.113.2.70.2.31 webform.module --- webform.module 29 Mar 2008 19:46:28 -0000 1.113.2.70.2.31 +++ webform.module 29 Mar 2008 23:34:51 -0000 @@ -143,7 +143,7 @@ 'title' => t('Results'), 'callback' => 'webform_results', 'callback arguments' => array($node), - 'access' => user_access('access webform results'), + 'access' => user_access('access webform results') || user_access('access webform submissions'), 'weight' => 2, 'type' => MENU_LOCAL_TASK, ); @@ -152,7 +152,7 @@ 'title' => t('Submissions'), 'callback' => 'webform_results', 'callback arguments' => array($node), - 'access' => user_access('access webform results'), + 'access' => user_access('access webform results') || user_access('access webform submissions') || (user_access('access own webform submissions') && $user->uid), 'weight' => 4, 'type' => MENU_DEFAULT_LOCAL_TASK, ); @@ -337,7 +337,7 @@ } /** - * Implemenation of hook_load(). + * Implementation of hook_load(). */ function webform_load($node) { $additions = new stdClass(); @@ -849,6 +849,13 @@ $node = node_prepare($node, $teaser); $node->content['webform'] = array('#value' => $output, '#weight' => 1); + if (user_access('access own webform submissions') && !(user_access('access webform results') || user_access('access webform submissions')) && $user->uid) { + $previous_submissions = db_query("SELECT count(*) FROM {webform_submissions} WHERE uid = %d", $user->uid); + if ($previous_submissions) { + drupal_set_message(t('You have already submitted this form. View your previous submissions.', array('!url' => url('node/'. $node->nid .'/results')))); + } + } + return $node; } Index: webform_submissions.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/webform/webform_submissions.inc,v retrieving revision 1.1.2.8 diff -u -r1.1.2.8 webform_submissions.inc --- webform_submissions.inc 21 Mar 2008 21:19:57 -0000 1.1.2.8 +++ webform_submissions.inc 29 Mar 2008 23:34:51 -0000 @@ -142,7 +142,7 @@ function webform_submission_delete_form_submit($form_id, $form_values) { webform_submission_delete($form_values['nid'], $form_values['sid']); drupal_set_message(t("Submission deleted")); - drupal_goto('node/'. $form_values['nid'] .'/results'); + return 'node/'. $form_values['nid'] .'/results'; } /** @@ -151,21 +151,29 @@ * @param $nid * The node ID for which submissions are being fetched. * @param $header - * If the results of this fetch will be used in a sortable table, pass the - * array header of the table. + * If the results of this fetch will be used in a sortable + * table, pass the array header of the table. + * @param $uid + * Optional; the user ID to filter the submissions by. + * @return $submissions + * An array of submissions matching your filters. */ -function webform_get_submissions($nid, $header = NULL) { +function webform_get_submissions($nid, $header = NULL, $uid = NULL) { $query = 'SELECT s.*, sd.cid, sd.no, sd.data, u.name, u.mail, u.status '. 'FROM {webform_submissions} s '. 'LEFT JOIN {webform_submitted_data} sd ON sd.sid = s.sid '. 'LEFT JOIN {users} u ON u.uid = s.uid '. 'WHERE sd.nid = %d'; + if ($uid) { + $query .= ' AND u.uid = %d'; + } + if (is_array($header)) { $query .= tablesort_sql($header); } - $res = db_query($query, $nid); + $res = db_query($query, $nid, $uid); $submissions = array(); $previous = array();