diff -urp --strip-trailing-cr /cygdrive/c/Program Files/Apache Group/Apache2/htdocs/drupaltest/sites/all/backup webform changes/old/webform/components/date.inc /cygdrive/c/Program Files/Apache Group/Apache2/htdocs/drupaltest/sites/all/modules/webformModified/components/date.inc
--- /cygdrive/c/Program Files/Apache Group/Apache2/htdocs/drupaltest/sites/all/backup webform changes/old/webform/components/date.inc 2008-06-26 22:41:44.000000000 -0400
+++ /cygdrive/c/Program Files/Apache Group/Apache2/htdocs/drupaltest/sites/all/modules/webformModified/components/date.inc 2008-07-02 15:56:24.061875000 -0400
@@ -265,11 +265,13 @@ function _webform_help_date($section) {
* submissions.
*/
function _webform_analysis_rows_date($component) {
- $query = 'SELECT no,data '.
- ' FROM {webform_submitted_data} '.
- ' WHERE nid = %d '.
- ' AND cid = %d '.
- ' ORDER BY sid,no ASC ';
+ $query = 'SELECT sd.no,sd.data '.
+ ' FROM {webform_submitted_data} sd'.
+' JOIN {webform_submissions} s ON sd.sid = s.sid'.
+ ' WHERE sd.nid = %d '.
+ ' AND sd.cid = %d '.
+' AND s.is_draft != 1'.
+ ' ORDER BY sd.sid,sd.no ASC ';
$result = db_query($query, $component['nid'], $component['cid']);
// build an array of timestamps from entered values.
diff -urp --strip-trailing-cr /cygdrive/c/Program Files/Apache Group/Apache2/htdocs/drupaltest/sites/all/backup webform changes/old/webform/components/email.inc /cygdrive/c/Program Files/Apache Group/Apache2/htdocs/drupaltest/sites/all/modules/webformModified/components/email.inc
--- /cygdrive/c/Program Files/Apache Group/Apache2/htdocs/drupaltest/sites/all/backup webform changes/old/webform/components/email.inc 2008-04-02 00:05:16.000000000 -0400
+++ /cygdrive/c/Program Files/Apache Group/Apache2/htdocs/drupaltest/sites/all/modules/webformModified/components/email.inc 2008-07-02 15:56:28.077500000 -0400
@@ -157,10 +157,12 @@ function _webform_help_email($section) {
* submissions.
*/
function _webform_analysis_rows_email($component) {
- $query = 'SELECT data '.
- ' FROM {webform_submitted_data} '.
- ' WHERE nid = %d '.
- ' AND cid = %d';
+ $query = 'SELECT sd.data '.
+ ' FROM {webform_submitted_data} sd'.
+' JOIN {webform_submissions} s ON sd.sid = s.sid'.
+ ' WHERE sd.nid = %d '.
+' AND s.is_draft != 1'.
+ ' AND sd.cid = %d';
$nonblanks = 0;
$submissions = 0;
$wordcount = 0;
diff -urp --strip-trailing-cr /cygdrive/c/Program Files/Apache Group/Apache2/htdocs/drupaltest/sites/all/backup webform changes/old/webform/components/file.inc /cygdrive/c/Program Files/Apache Group/Apache2/htdocs/drupaltest/sites/all/modules/webformModified/components/file.inc
--- /cygdrive/c/Program Files/Apache Group/Apache2/htdocs/drupaltest/sites/all/backup webform changes/old/webform/components/file.inc 2008-06-20 23:31:22.000000000 -0400
+++ /cygdrive/c/Program Files/Apache Group/Apache2/htdocs/drupaltest/sites/all/modules/webformModified/components/file.inc 2008-07-21 11:03:35.399375000 -0400
@@ -243,8 +243,8 @@ function _webform_render_file($component
'#attributes' => $component['extra']['attributes'],
'#tree' => false, // file_check_upload assumes a flat $_FILES structure.
'#validate' => array(
- '_webform_validate_file' => array($component['form_key'], $component['name'], $component['extra']['filtering']),
- '_webform_required_file' => array($component['form_key'], $component['name'], $component['mandatory']), // Custom required routine.
+ '_webform_CHECKALWAYS_validate_file' => array($component['form_key'], $component['name'], $component['extra']['filtering']),
+ '_webform_required_file' => array($component['form_key'], $component['name'], $component['mandatory'], $component), // Custom required routine.
),
'#prefix' => '
',
'#suffix' => '
',
@@ -257,22 +257,62 @@ function _webform_render_file($component
return $form_item;
}
-function _webform_required_file($form_element, $form_key, $fieldname, $required = false) {
- if (empty($_FILES['files']['name'][$form_key]) && $required) {
- form_set_error($fieldname, t('%field field is required.', array('%field' => $fieldname)));
- }
-}
+function _webform_required_file($form_element, $form_key, $fieldname, $required = false, $component) {
+
+ //now about when submitting for first time? is form #details sid available? if not look for way to include it //if( isset( $form_element['details']))
-function _webform_validate_file($form_element, $form_key, $fieldname, $filters) {
+ if( $required )
+ {//no new file
+
+ if( empty($_FILES['files']['name'][$form_key]) )
+ {
+ $qargs = array( $component['nid'], $form_element['#post']['details']['sid'], $component['cid'] );
+ $result = db_query("SELECT `data` FROM {webform_submitted_data} d WHERE nid=%d and sid=%d and cid=%d", $qargs );
+
+ if ($row = db_fetch_object($result))
+ {
+ $current_file = unserialize( $row->data ); //drupal_set_message( 'currentfile='. print_r( $current_file,1) );
+ if( trim($current_file['filepath']) == "" )
+ {//no filepath define before, user probably just saved form, and hence no filepath values
+ form_set_error($fieldname, t('%field field is required.', array('%field' => $fieldname)));
+ setFileComponantError($form_key);
+ }
+ else
+ {//filepath is defined/saved before
+ if(! file_exists($current_file['filepath']) )
+ {
+ form_set_error($fieldname, t('Your previously uploaded file %filename is not found/lost. The %field field is required so please reupload file.', array('%field' => $fieldname, '%filename'=>$current_file['filename'])) );
+ setFileComponantError($form_key);
+ }
+ }
+
+ }
+ else//no old data but no new data and since required, error
+ {
+ form_set_error($fieldname, t('%field field is required.', array('%field' => $fieldname)));
+ setFileComponantError($form_key);
+ }
+ }
+
+ }
+
+}
+function setFileComponantError($form_key){//drupal doesnt automatically handle so we handle setting css
+ drupal_add_js("$(document).ready(function(){
+ $('#webform-component-". $form_key ." input').addClass('error');//adds error class so highlights input field
+ });", "inline");
+}
+function _webform_CHECKALWAYS_validate_file($form_element, $form_key, $fieldname, $filters) {
// Set the current file as the default.
+
+ //return here or remove this part entirely with unset_req_fields if saving
+ if( empty($_FILES['files']['name'][ $form_key ]) ) //if saving no file wont have a name, maybe pass is_draft here later
+ return;
+
if (isset($form_element['#webform_current_file'])) {
form_set_value(array('#parents' => $form_element['#parents']), serialize($form_element['#webform_current_file']));
}
- if (empty($_FILES['files']['name'][$form_key])) {
- return;
- }
-
// Build a human readable list of extensions:
$extensions = $filters['types'];
if (count($extensions) > 1) {
@@ -289,12 +329,19 @@ function _webform_validate_file($form_el
$extension = strtolower(substr($_FILES['files']['name'][$form_key], $dot+1));
if (!in_array($extension, $extensions)) {
form_set_error($form_key, t("Files with the '%ext' extension are not allowed, please upload a file with a %exts extension.", array('%ext' => $extension, '%exts' => $extension_list)));
+ setFileComponantError($form_key);
}
// Now let's check the file size (limit is set in KB).
if ($_FILES['files']['size'][$form_key] > $filters['size']*1024) {
form_set_error($form_key, t("The file '%filename' is too large (%filesize KB). Please upload a file %maxsize KB or smaller.", array('%filename' => $_FILES['files']['name'][$form_key], '%filesize' => (int)($_FILES['files']['size'][$form_key]/1024), '%maxsize' => $filters['size'])));
+ setFileComponantError($form_key);
+ }
+ else if($_FILES['files']['size'][$form_key] <= 0){//a 0byte fake file (forget if a scenario creates this but included just in case) or nonexistant file on server
+ form_set_error($form_key, t("The file '%filename' does not seem to exist on your computer. Please click the Browse button and repick a file, and make sure to not modify the text that auto-fills the textfield.", array('%filename' => $_FILES['files']['name'][$form_key]) ));
+ setFileComponantError($form_key);
}
+
}
/**
@@ -308,17 +355,44 @@ function _webform_validate_file($form_el
* @return
* Nothing.
*/
-function _webform_submit_file(&$data, $component) {
+function _webform_submit_file(&$data, $component, $node) {
// Hack to get the form value for this file component (not necessary in D6).
global $form_values;
+ global $sidToInsert;
$data = $form_values[$component['form_key']];
$current_file = unserialize($data);
- if ($file = file_check_upload($component['form_key'])) {
- $upload_dir = file_directory_path() ."/webform/". $component['extra']['savelocation'];
-
- if (file_check_directory($upload_dir, FILE_CREATE_DIRECTORY)) {
+ if( isset($form_values['details']['sid']) )
+ $sid = $form_values['details']['sid'];
+ else
+ {//submitting value first time arrive at the page so no sid yet, so set one to preserve cool directory structure
+ if( !isset($sidToInsert) )
+ {
+ $sidToInsert = db_next_id('{webform_submissions}_sid');//is this safe to call here? what if two users submitting around same exact time? if not safe, store sid in database until inserted so other inserts can check to see what next $sid is , if orig way unsafe or database storage of next_ids is too much of hassle, then go back to old saving scheme where file is uploaded to generic webforms directory.... and change _insert hook back to old way
+ $sid = $sidToInsert;
+ }
+ else
+ $sid = $sidToInsert;//inserting 2nd+ file, reuse insert just gotten above
+ }
+
+ if ($file = file_check_upload($component['form_key'])) { //$_FILES["files"]["name"][$source] $_FILES["files"]["tmp_name"][$source]
+
+ if( trim($component['extra']['savelocation'])=='' )
+ {
+ $upload_dir_pre = file_directory_path() ."/webform/". $form_values['details']['nid']; //standardized structure to find easily
+ $upload_dir_append = "/". $sid;//makes sense to put in nid/sid i think so easier to find on server
+ $upload_dir = $upload_dir_pre.$upload_dir_append;
+ $dodetailedpath = TRUE;
+ }
+ else
+ $upload_dir = file_directory_path() ."/webform/". $component['extra']['savelocation'];
+
+ if (
+ ( ($dodetailedpath==FALSE) && file_check_directory($upload_dir, FILE_CREATE_DIRECTORY) )
+ ||
+ ( ($dodetailedpath==TRUE) && file_check_directory($upload_dir_pre, FILE_CREATE_DIRECTORY) && file_check_directory($upload_dir, FILE_CREATE_DIRECTORY) )
+ ) {
$file_saved = file_save_upload($component['form_key'], $upload_dir);
if (!$file_saved) {
drupal_set_message(t("The uploaded file %filename was unable to be saved. The destination directory may not be writable.", array('%filename' => $file_saved['filename'])), "error");
@@ -329,7 +403,7 @@ function _webform_submit_file(&$data, $c
}
}
else {
- drupal_set_message(t("The uploaded file was unable to be saved. The destination directory does not exist.", "error"));
+ drupal_set_message(t("The uploaded file was unable to be saved. The destination directory does not exist."), "error");
}
}
}
@@ -377,8 +451,14 @@ function _webform_submission_display_fil
if ($enabled) {
$form_item['#description'] = t('Uploading a new file will replace the current file.');
$form_item['#webform_current_file'] = $filedata;
+
+ drupal_add_js("$(document).ready(function(){
+
+ $('#webform-component-". $component['form_key'] ." label .form-required').append(' (You have already uploaded a file for this field so not required to reupload new file unless want to replace.)');
+ });", "inline");
}
}
+
return $form_item;
}
@@ -424,10 +504,12 @@ function _webform_help_file($section) {
* submissions.
*/
function _webform_analysis_rows_file($component) {
- $query = 'SELECT data '.
- ' FROM {webform_submitted_data} '.
- ' WHERE nid = %d '.
- ' AND cid = %d';
+ $query = 'SELECT sd.data '.
+ ' FROM {webform_submitted_data} sd'.
+' JOIN {webform_submissions} s ON sd.sid = s.sid'.
+ ' WHERE sd.nid = %d '.
+' AND s.is_draft != 1'.
+ ' AND sd.cid = %d';
$nonblanks = 0;
$submissions = 0;
$wordcount = 0;
diff -urp --strip-trailing-cr /cygdrive/c/Program Files/Apache Group/Apache2/htdocs/drupaltest/sites/all/backup webform changes/old/webform/components/grid.inc /cygdrive/c/Program Files/Apache Group/Apache2/htdocs/drupaltest/sites/all/modules/webformModified/components/grid.inc
--- /cygdrive/c/Program Files/Apache Group/Apache2/htdocs/drupaltest/sites/all/backup webform changes/old/webform/components/grid.inc 2008-06-29 19:54:10.000000000 -0400
+++ /cygdrive/c/Program Files/Apache Group/Apache2/htdocs/drupaltest/sites/all/modules/webformModified/components/grid.inc 2008-07-03 10:14:20.999375000 -0400
@@ -182,12 +182,14 @@ function _webform_analysis_rows_grid($co
$questions = array_values(_webform_grid_options($component['extra']['questions']));
// Generate a lookup table of results.
- $query = 'SELECT no, data, count(data) as datacount '.
- ' FROM {webform_submitted_data} '.
- ' WHERE nid = %d '.
- ' AND cid = %d '.
- " AND data != '0' AND data != '' ".
- ' GROUP BY no, data';
+ $query = 'SELECT sd.no, sd.data, count(sd.data) as datacount '.
+ ' FROM {webform_submitted_data} sd'.
+' JOIN {webform_submissions} s ON sd.sid = s.sid'.
+ ' WHERE sd.nid = %d '.
+ ' AND sd.cid = %d '.
+ " AND sd.data != '0' AND sd.data != '' ".
+' AND s.is_draft != 1'.
+ ' GROUP BY sd.no, sd.data';
$result = db_query($query, $component['nid'], $component['cid']);
$counts = array();
while ($data = db_fetch_object($result)) {
diff -urp --strip-trailing-cr /cygdrive/c/Program Files/Apache Group/Apache2/htdocs/drupaltest/sites/all/backup webform changes/old/webform/components/hidden.inc /cygdrive/c/Program Files/Apache Group/Apache2/htdocs/drupaltest/sites/all/modules/webformModified/components/hidden.inc
--- /cygdrive/c/Program Files/Apache Group/Apache2/htdocs/drupaltest/sites/all/backup webform changes/old/webform/components/hidden.inc 2008-05-08 15:38:02.000000000 -0400
+++ /cygdrive/c/Program Files/Apache Group/Apache2/htdocs/drupaltest/sites/all/modules/webformModified/components/hidden.inc 2008-07-02 15:56:50.280625000 -0400
@@ -102,10 +102,12 @@ function _webform_help_hidden($section)
* submissions.
*/
function _webform_analysis_rows_hidden($component) {
- $query = 'SELECT data '.
- ' FROM {webform_submitted_data} '.
- ' WHERE nid = %d '.
- ' AND cid = %d';
+ $query = 'SELECT sd.data '.
+ ' FROM {webform_submitted_data} sd'.
+' JOIN {webform_submissions} s ON sd.sid = s.sid'.
+ ' WHERE sd.nid = %d '.
+' AND s.is_draft != 1'.
+ ' AND sd.cid = %d';
$nonblanks = 0;
$submissions = 0;
$wordcount = 0;
diff -urp --strip-trailing-cr /cygdrive/c/Program Files/Apache Group/Apache2/htdocs/drupaltest/sites/all/backup webform changes/old/webform/components/select.inc /cygdrive/c/Program Files/Apache Group/Apache2/htdocs/drupaltest/sites/all/modules/webformModified/components/select.inc
--- /cygdrive/c/Program Files/Apache Group/Apache2/htdocs/drupaltest/sites/all/backup webform changes/old/webform/components/select.inc 2008-06-26 23:19:12.000000000 -0400
+++ /cygdrive/c/Program Files/Apache Group/Apache2/htdocs/drupaltest/sites/all/modules/webformModified/components/select.inc 2008-07-02 15:56:55.046250000 -0400
@@ -261,12 +261,14 @@ function _webform_help_select($section)
function _webform_analysis_rows_select($component) {
$options = _webform_select_options($component['extra']['items']);
- $query = 'SELECT data, count(data) as datacount '.
- ' FROM {webform_submitted_data} '.
- ' WHERE nid = %d '.
- ' AND cid = %d '.
- " AND data != '0' AND data != '' ".
- ' GROUP BY data ';
+ $query = 'SELECT sd.data, count(sd.data) as datacount '.
+ ' FROM {webform_submitted_data} sd'.
+' JOIN {webform_submissions} s ON sd.sid = s.sid'.
+ ' WHERE sd.nid = %d '.
+ ' AND sd.cid = %d '.
+' AND s.is_draft != 1'.
+ " AND sd.data != '0' AND sd.data != '' ".
+ ' GROUP BY sd.data ';
$result = db_query($query, $component['nid'], $component['cid']);
$rows = array();
while ($data = db_fetch_array($result)) {
diff -urp --strip-trailing-cr /cygdrive/c/Program Files/Apache Group/Apache2/htdocs/drupaltest/sites/all/backup webform changes/old/webform/components/textarea.inc /cygdrive/c/Program Files/Apache Group/Apache2/htdocs/drupaltest/sites/all/modules/webformModified/components/textarea.inc
--- /cygdrive/c/Program Files/Apache Group/Apache2/htdocs/drupaltest/sites/all/backup webform changes/old/webform/components/textarea.inc 2008-05-27 12:31:16.000000000 -0400
+++ /cygdrive/c/Program Files/Apache Group/Apache2/htdocs/drupaltest/sites/all/modules/webformModified/components/textarea.inc 2008-07-02 15:55:51.952500000 -0400
@@ -117,10 +117,12 @@ function _webform_help_textarea($section
* submissions.
*/
function _webform_analysis_rows_textarea($component) {
- $query = 'SELECT data '.
- ' FROM {webform_submitted_data} '.
- ' WHERE nid = %d '.
- ' AND cid = %d';
+ $query = 'SELECT sd.data '.
+ ' FROM {webform_submitted_data} sd'.
+' JOIN {webform_submissions} s ON sd.sid = s.sid'.
+ ' WHERE sd.nid = %d '.
+' AND s.is_draft != 1'.
+ ' AND sd.cid = %d';
$nonblanks = 0;
$submissions = 0;
$wordcount = 0;
diff -urp --strip-trailing-cr /cygdrive/c/Program Files/Apache Group/Apache2/htdocs/drupaltest/sites/all/backup webform changes/old/webform/components/textfield.inc /cygdrive/c/Program Files/Apache Group/Apache2/htdocs/drupaltest/sites/all/modules/webformModified/components/textfield.inc
--- /cygdrive/c/Program Files/Apache Group/Apache2/htdocs/drupaltest/sites/all/backup webform changes/old/webform/components/textfield.inc 2008-06-29 19:55:14.000000000 -0400
+++ /cygdrive/c/Program Files/Apache Group/Apache2/htdocs/drupaltest/sites/all/modules/webformModified/components/textfield.inc 2008-07-02 15:52:49.530625000 -0400
@@ -160,10 +160,12 @@ function _webform_help_textfield($sectio
* submissions.
*/
function _webform_analysis_rows_textfield($component) {
- $query = 'SELECT data '.
- ' FROM {webform_submitted_data} '.
- ' WHERE nid = %d '.
- ' AND cid = %d';
+ $query = 'SELECT sd.data '.
+ ' FROM {webform_submitted_data} sd'.
+' JOIN {webform_submissions} s ON sd.sid = s.sid'.
+ ' WHERE sd.nid = %d '.
+' AND s.is_draft != 1'.
+ ' AND sd.cid = %d';
$nonblanks = 0;
$submissions = 0;
$wordcount = 0;
diff -urp --strip-trailing-cr /cygdrive/c/Program Files/Apache Group/Apache2/htdocs/drupaltest/sites/all/backup webform changes/old/webform/components/time.inc /cygdrive/c/Program Files/Apache Group/Apache2/htdocs/drupaltest/sites/all/modules/webformModified/components/time.inc
--- /cygdrive/c/Program Files/Apache Group/Apache2/htdocs/drupaltest/sites/all/backup webform changes/old/webform/components/time.inc 2008-04-02 00:05:16.000000000 -0400
+++ /cygdrive/c/Program Files/Apache Group/Apache2/htdocs/drupaltest/sites/all/modules/webformModified/components/time.inc 2008-07-02 15:52:31.858750000 -0400
@@ -226,11 +226,13 @@ function _webform_help_time($section) {
* submissions.
*/
function _webform_analysis_rows_time($component) {
- $query = 'SELECT no,data '.
- ' FROM {webform_submitted_data} '.
- ' WHERE nid = %d '.
- ' AND cid = %d '.
- ' ORDER BY sid,no ASC ';
+ $query = 'SELECT sd.no,sd.data '.
+ ' FROM {webform_submitted_data} sd'.
+' JOIN {webform_submissions} s ON sd.sid = s.sid'.
+ ' WHERE sd.nid = %d '.
+ ' AND sd.cid = %d '.
+' AND s.is_draft != 1'.
+ ' ORDER BY sd.sid,sd.no ASC ';
$result = db_query($query, $component['nid'], $component['cid']);
// build an array of timestamps from entered values.
Only in /cygdrive/c/Program Files/Apache Group/Apache2/htdocs/drupaltest/sites/all/modules/webformModified/: temp
diff -urp --strip-trailing-cr /cygdrive/c/Program Files/Apache Group/Apache2/htdocs/drupaltest/sites/all/backup webform changes/old/webform/webform.module /cygdrive/c/Program Files/Apache Group/Apache2/htdocs/drupaltest/sites/all/modules/webformModified/webform.module
--- /cygdrive/c/Program Files/Apache Group/Apache2/htdocs/drupaltest/sites/all/backup webform changes/old/webform/webform.module 2008-06-30 16:09:48.000000000 -0400
+++ /cygdrive/c/Program Files/Apache Group/Apache2/htdocs/drupaltest/sites/all/modules/webformModified/webform.module 2008-07-18 17:55:18.790000000 -0400
@@ -113,6 +113,13 @@ function webform_menu($may_cache) {
'callback arguments' => array($node),
'access' => node_access('view', $node),
'type' => MENU_CALLBACK,
+ );
+ $items[]= array(
+ 'path' => 'node/'. $node->nid .'/draft_saved',
+ 'title' => t('Draft saved'),
+ 'callback' => '_webform_draft_confirmation',
+ 'callback arguments' => array(arg(1)),
+ 'type' => MENU_CALLBACK,
);
$items[] = array(
'path' => 'node/'. $nid .'/done',
@@ -201,15 +208,20 @@ function webform_menu($may_cache) {
'weight' => 2,
'type' => MENU_CALLBACK,
);
+
if (isset($sid)) {
include_once(drupal_get_path('module', 'webform') ."/webform_submissions.inc");
$submission = webform_get_submission($node->nid, $sid);
+ if(!$submission)//false value so page not found
+ drupal_not_found();
+
$items[] = array(
'path' => 'node/'. $nid .'/submission/'. $sid,
'title' => t('Webform submission'),
'callback' => 'drupal_get_form',
- 'callback arguments' => array('webform_client_form_'. $node->nid, $node, $submission, FALSE, FALSE),
+ //enabled, preview, isdraft
+ 'callback arguments' => array('webform_client_form_'. $node->nid, $node, $submission, FALSE, FALSE, FALSE, $submission->is_draft),//all of these were false before?
'access' => webform_submission_access($node, $submission, 'view'),
'type' => MENU_CALLBACK,
);
@@ -217,7 +229,7 @@ function webform_menu($may_cache) {
'path' => 'node/'. $nid .'/submission/'. $sid .'/view',
'title' => t('View'),
'callback' => 'drupal_get_form',
- 'callback arguments' => array('webform_client_form_'. $node->nid, $node, $submission, FALSE, FALSE),
+ 'callback arguments' => array('webform_client_form_'. $node->nid, $node, $submission, FALSE, FALSE, FALSE, $submission->is_draft),//all of these were false before?
'access' => webform_submission_access($node, $submission, 'view'),
'weight' => 0,
'type' => MENU_DEFAULT_LOCAL_TASK,
@@ -226,7 +238,7 @@ function webform_menu($may_cache) {
'path' => 'node/'. $nid .'/submission/'. $sid .'/edit',
'title' => t('Edit'),
'callback' => 'drupal_get_form',
- 'callback arguments' => array('webform_client_form_'. $node->nid, $node, $submission, TRUE, FALSE),
+ 'callback arguments' => array('webform_client_form_'. $node->nid, $node, $submission, TRUE, FALSE, FALSE, $submission->is_draft),//all of these were false before?
'access' => webform_submission_access($node, $submission, 'edit'),
'weight' => 1,
'type' => MENU_LOCAL_TASK,
@@ -287,6 +299,7 @@ function webform_access($op, $node) {
* All webform_client_form forms share the same form handler
*/
function webform_forms($args) {
+
$form_id = $args[0];
if (strpos($form_id, 'webform_client_form_') === 0) {
$forms[$form_id]['callback'] = 'webform_client_form';
@@ -301,10 +314,46 @@ function webform_forms($args) {
*/
function webform_file_download($file) {
$file = file_check_location(file_directory_path() .'/'. $file, file_directory_path() .'/webform/');
- if ($file && user_access('access webform results')) {
- $info = image_get_info(file_create_path($file));
- return array('Content-type: '. $info['mime_type']);
- }
+ //makes sense that if they save their submission and want to recome back to it to check on it... that they can dl and view their file to see if they want to replace it, also give access to anyone who can edit webform submissions
+ global $user;
+
+ //get sid of file so can figure out uid of who submitted this file as an answer (to base permissions off of)
+ //(originally had planned to get it based on filepath like 'webforms/nid/sid/filename' which i thought was useful and use currently but i allow the extra save functionality, which can be set in the webform options, to save to a generic directory like i assume people would want a folder like 'webforms/resume' that can be set in many webforms), So if extra save location is set, how would i get sid since not in the filepath anymore? i think i will handle by looking at the filepath in database, return the sid from webform_submitted_data, and get uid based on that, filepath shouldnt be the same for anything but ill check for that in case (maybe admin hand deleted the file, and forgot to delete database submission)
+ $result = db_query("SELECT `data`, nid, sid FROM {webform_submitted_data} d");
+ $numFiles = 0;
+ while( $row = db_fetch_object($result))
+ {
+ $data = unserialize($row->data);
+ $pathinfoFilePathUrl = pathinfo($file);
+ $pathinfoDB = pathinfo($data['filepath']);
+
+ //so making sure the database entry is same filepath if requested file
+ if( (realpath($pathinfoFilePathUrl['dirname'])==realpath($pathinfoDB['dirname'])) && ($pathinfoFilePathUrl['basename']==$pathinfoDB['basename']) )//base on filedir, and then filename cause windows seems to insert funky filenames like c:\files/webform/1/2/node1submissionfile.blah
+ {
+ $numFiles++;
+ $sid = $row->sid;
+ $nid = $row->nid;
+ //$cid = $row->cid; //info not needed
+ }
+ }
+
+
+ if( $numFiles == 1 )//found a match, now lets see if the user can access it by being an webformadmin-type person or if matches the user who submitted that file
+ {
+ $file_uid = db_result(db_query("SELECT uid FROM {webform_submissions} ws WHERE sid=%d AND nid=%d", $sid, $nid));
+ if ($file && (
+ user_access('access webform results')
+ || (user_access('edit own webform submissions') && ($file_uid==$user->uid) )
+ || (user_access('access own webform submissions') && ($file_uid==$user->uid) )
+ || user_access('edit webform submissions')
+ )) {
+ $info = image_get_info(file_create_path($file));
+ return array('Content-type: '. $info['mime_type']);
+ }
+ }
+ else
+ drupal_set_message( 'There are 2 of these files with same filepath in the database for some reason so we are not sure if you are allowed to access this file. Please ask website administrator to fix so you may get access.' ) ;
+
}
/**
@@ -314,8 +363,7 @@ function webform_insert($node) {
include_once(drupal_get_path('module', 'webform') .'/webform_components.inc');
// Insert the Webform.
- db_query("INSERT INTO {webform} (nid, confirmation, teaser, submit_text, submit_limit, submit_interval, email, email_from_name, email_from_address, email_subject, additional_validate, additional_submit) VALUES (%d, '%s', %d, '%s', %d, %d, '%s', '%s', '%s', '%s', '%s', '%s')", $node->nid, $node->webform['confirmation'], $node->webform['teaser'], $node->webform['submit_text'], $node->webform['submit_limit'], $node->webform['submit_interval'], $node->webform['email'], $node->webform['email_from_name'], $node->webform['email_from_address'], $node->webform['email_subject'], $node->webform['additional_validate'], $node->webform['additional_submit']);
-
+ db_query("INSERT INTO {webform} (nid, confirmation, teaser, submit_text, submit_limit, submit_interval, email, email_from_name, email_from_address, email_subject, additional_validate, additional_submit, allow_draft) VALUES (%d, '%s', %d, '%s', %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', %d)", $node->nid, $node->webform['confirmation'], $node->webform['teaser'], $node->webform['submit_text'], $node->webform['submit_limit'], $node->webform['submit_interval'], $node->webform['email'], $node->webform['email_from_name'], $node->webform['email_from_address'], $node->webform['email_subject'], $node->webform['additional_validate'], $node->webform['additional_submit'], $node->webform['allow_draft']);
// Insert the components into the database.
if (isset($node->webform['components']) && !empty($node->webform['components'])) {
foreach ($node->webform['components'] as $cid => $component) {
@@ -665,6 +713,14 @@ function webform_form(&$node, &$param) {
'#default_value' => $node->webform['submit_text'],
'#description' => t('By default the submit button on this form will have the label Submit. Enter a new title here to override the default.'),
);
+
+ // Allow save draft
+ $form['webform']['advanced']['allow_draft'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Allow users to save a draft'),
+ '#default_value' => $node->webform['allow_draft'],
+ );
+
if (user_access('use PHP for additional processing')) {
$form['webform']['advanced']['additional_validate'] = array(
'#type' => 'textarea',
@@ -892,7 +948,7 @@ function webform_view(&$node, $teaser =
$limit_exceeded = FALSE;
if (isset($_POST['op']) && $_POST['op'] == t('Preview')) {
- $preview = true;
+ $preview = TRUE;
$additions = webform_load($node);
$node->webform['components'] = $additions->webform['components'];
}
@@ -930,6 +986,7 @@ function webform_view(&$node, $teaser =
// Check if the user can add another submission.
if ($node->webform['submit_limit'] != -1) { // -1: Submissions are never throttled.
include_once(drupal_get_path('module', 'webform') ."/webform_submissions.inc");
+
if ($limit_exceeded = _webform_submission_limit_check($node)) {
$enabled = FALSE;
}
@@ -937,12 +994,25 @@ function webform_view(&$node, $teaser =
// Get a count of previous submissions by this user.
if ($user->uid && (user_access('access own webform submissions') || user_access('access webform results') || user_access('access webform submissions'))) {
- $submission_count = db_result(db_query("SELECT count(*) FROM {webform_submissions} WHERE nid = %d AND uid = %d", $node->nid, $user->uid));
+ $submission_count = db_result(db_query("SELECT count(*) FROM {webform_submissions} WHERE nid = %d AND uid = %d AND is_draft = false", $node->nid, $user->uid));
}
+ // Check if this user has a draft for this webform.
+ $is_draft = FALSE;
+ if ($node->webform['allow_draft'] && $user->uid != 0) {
+ // Draft found - display form with draft data for further editing.
+ if ($_draft_sid = _webform_fetch_draft_sid($node->nid, $user->uid)) {
+ include_once(drupal_get_path('module', 'webform') ."/webform_submissions.inc");
+ $submission = webform_get_submission($node->nid, $_draft_sid);
+ $enabled = TRUE;
+ $is_draft = TRUE;
+ }
+ }
+
// Render the form and generate the output.
- $form = drupal_get_form('webform_client_form_'. $node->nid, $node, $submission, $enabled, $preview);
- $output = theme('webform_view', $node, $teaser, $page, $form, $enabled);
+ $form = drupal_get_form('webform_client_form_'. $node->nid, $node, $submission, $enabled, $preview, NULL, $is_draft);//CHANGE from the save.patch... that one themed using just $form (no $output), formvalues not needed?
+ $output = theme('webform_view', $node, $teaser, $page, $form, $enabled, $is_draft); //just in case needs it? old patch only used output
+
// Remove the surrounding