From 502e39c92ec8db4e9919187d7921457b11319bde Mon Sep 17 00:00:00 2001 From: Patrick Cool Date: Tue, 28 Aug 2007 14:32:02 +0200 Subject: [PATCH] [svn r12901] anonymous survey --- main/inc/lib/add_course.lib.inc.php | 1 + main/install/migrate-db-1.8.3-1.8.4-pre.sql | 1 + main/survey/create_new_survey.php | 5 ++- main/survey/fillsurvey.php | 35 ++++++++++++++---- main/survey/reporting.php | 17 ++++----- main/survey/survey.lib.php | 17 +++++++-- main/survey/survey.php | 40 ++++++++++----------- main/survey/survey_invite.php | 3 +- main/survey/survey_list.php | 37 +++++++++++++------ 9 files changed, 102 insertions(+), 54 deletions(-) diff --git a/main/inc/lib/add_course.lib.inc.php b/main/inc/lib/add_course.lib.inc.php index 84f1d3cbf4..8a5dfeb5fa 100644 --- a/main/inc/lib/add_course.lib.inc.php +++ b/main/inc/lib/add_course.lib.inc.php @@ -1273,6 +1273,7 @@ function update_Db_course($courseDbName) answered int NOT NULL, invite_mail text NOT NULL, reminder_mail text NOT NULL, + anonymous enum('0','1') NOT NULL default '0', PRIMARY KEY (survey_id) )"; diff --git a/main/install/migrate-db-1.8.3-1.8.4-pre.sql b/main/install/migrate-db-1.8.3-1.8.4-pre.sql index 33a4d47c5d..648e5b618b 100644 --- a/main/install/migrate-db-1.8.3-1.8.4-pre.sql +++ b/main/install/migrate-db-1.8.3-1.8.4-pre.sql @@ -28,3 +28,4 @@ INSERT INTO settings_options(variable,value,display_text) VALUES ('default_forum -- xxUSERxx -- xxCOURSExx +ALTER TABLE survey ADD anonymous ENUM( '0', '1' ) NOT NULL DEFAULT '0'; diff --git a/main/survey/create_new_survey.php b/main/survey/create_new_survey.php index d3dc0e5625..2022ebe3fd 100644 --- a/main/survey/create_new_survey.php +++ b/main/survey/create_new_survey.php @@ -21,7 +21,7 @@ * @package dokeos.survey * @author unknown, the initial survey that did not make it in 1.8 because of bad code * @author Patrick Cool , Ghent University: cleanup, refactoring and rewriting large parts (if not all) of the code -* @version $Id: create_new_survey.php 12272 2007-05-03 14:40:45Z elixir_julian $ +* @version $Id: create_new_survey.php 12901 2007-08-28 12:32:02Z pcool $ * * @todo only the available platform languages should be used => need an api get_languages and and api_get_available_languages (or a parameter) */ @@ -96,6 +96,7 @@ if ($_GET['action'] == 'edit' AND isset($_GET['survey_id']) AND is_numeric($_GET { $form_share_value = $defaults['survey_share']['survey_share']; } + $defaults['anonymous'] = $survey_data['anonymous']; } else { @@ -105,6 +106,7 @@ else $defaults['end_date'] = date('d-F-Y H:i', $startdateandxdays); $defaults['survey_share']['survey_share'] = 0; $form_share_value = 1; + $defaults['anonymous'] = 0; } // initiate the object @@ -135,6 +137,7 @@ $group[] =& HTML_QuickForm::createElement('radio', 'survey_share',null, get_lang $group[] =& HTML_QuickForm::createElement('radio', 'survey_share',null, get_lang('No'),0); $fck_attribute['Height'] = '200'; $form->addGroup($group, 'survey_share', get_lang('ShareSurvey'), ' '); +$form->addElement('checkbox', 'anonymous', get_lang('Anonymous')); $form->addElement('html_editor', 'survey_introduction', get_lang('SurveyIntroduction')); $form->addElement('html_editor', 'survey_thanks', get_lang('SurveyThanks')); $form->addElement('submit', 'submit_survey', get_lang('Ok')); diff --git a/main/survey/fillsurvey.php b/main/survey/fillsurvey.php index 0c56ce2fb8..7434a8afb2 100644 --- a/main/survey/fillsurvey.php +++ b/main/survey/fillsurvey.php @@ -118,6 +118,10 @@ else $survey_invitation['survey_id'] = $row['survey_id']; } +// getting the survey information +$survey_data = survey_manager::get_survey($survey_invitation['survey_id']); +$survey_data['survey_id'] = $survey_invitation['survey_id']; + // storing the answers if ($_POST) { @@ -163,7 +167,7 @@ if ($_POST) $option_id = $answer_value; $option_value = ''; } - store_answer($survey_invitation['user'], $survey_invitation['survey_id'], $survey_question_id, $option_id, $option_value); + store_answer($survey_invitation['user'], $survey_invitation['survey_id'], $survey_question_id, $option_id, $option_value, $survey_data); } } // all the other question types (open question, multiple choice, percentage, ...) @@ -179,21 +183,24 @@ if ($_POST) else { $option_value = 0; + if($types[$survey_question_id] == 'open') + { + $option_value = $value; + $value = 0; + + } } $survey_question_answer = $value; remove_answer($survey_invitation['user'], $survey_invitation['survey_id'], $survey_question_id); - store_answer($survey_invitation['user'], $survey_invitation['survey_id'], $survey_question_id, $value, $option_value); + store_answer($survey_invitation['user'], $survey_invitation['survey_id'], $survey_question_id, $value, $option_value, $survey_data); + //store_answer($user,$survey_id,$question_id, $option_id, $option_value, $survey_data); } } } } -// getting the survey information -$survey_data = survey_manager::get_survey($survey_invitation['survey_id']); -$survey_data['survey_id'] = $survey_invitation['survey_id']; - // displaying the survey title and subtitle (appears on every page) echo '
'.$survey_data['survey_title'].'
'; echo '
'.$survey_data['survey_subtitle'].'
'; @@ -293,7 +300,7 @@ Display :: display_footer(); * @author Patrick Cool , Ghent University * @version January 2007 */ -function store_answer($user, $survey_id, $question_id, $option_id, $option_value) +function store_answer($user, $survey_id, $question_id, $option_id, $option_value, $survey_data) { global $_course; global $types; @@ -303,6 +310,20 @@ function store_answer($user, $survey_id, $question_id, $option_id, $option_value // table definition $table_survey_answer = Database :: get_course_table(TABLE_SURVEY_ANSWER, $_course['db_name']); + // make the survey anonymous + if ($survey_data['anonymous'] == 1) + { + if (!$_SESSION['surveyuser']) + { + $user = md5($user.time()); + $_SESSION['surveyuser'] = $user; + } + else + { + $user = $_SESSION['surveyuser']; + } + } + $sql = "INSERT INTO $table_survey_answer (user, survey_id, question_id, option_id, value) VALUES ( '".Database::escape_string($user)."', '".Database::escape_string($survey_id)."', diff --git a/main/survey/reporting.php b/main/survey/reporting.php index c18cf66ea6..8ba3686310 100644 --- a/main/survey/reporting.php +++ b/main/survey/reporting.php @@ -21,7 +21,7 @@ * @package dokeos.survey * @author unknown, the initial survey that did not make it in 1.8 because of bad code * @author Patrick Cool , Ghent University: cleanup, refactoring and rewriting large parts of the code -* @version $Id: reporting.php 12586 2007-06-12 13:39:57Z elixir_julian $ +* @version $Id: reporting.php 12901 2007-08-28 12:32:02Z pcool $ * * @todo The question has to be more clearly indicated (same style as when filling the survey) */ @@ -340,6 +340,10 @@ function display_user_report() else { $second_parameter = $answers[$question['question_id']]; + if ($question['type'] == 'open') + { + $second_parameter = $all_answers[$question['question_id']][0]['value']; + } } $display = new $question['type']; @@ -449,7 +453,7 @@ function display_question_report($survey_data) $result = api_sql_query($sql, __FILE__, __LINE__); while ($row = mysql_fetch_assoc($result)) { - echo $row['option_id'].'
'; + echo $row['value'].'
'; } } @@ -747,11 +751,6 @@ function display_complete_report_row($possible_answers, $answers_of_user, $user) foreach ($possible_answers as $question_id=>$possible_option) { - - $sql='SELECT type FROM '.$table_survey_question.' WHERE question_id="'.$question_id.'"'; - $result=api_sql_query($sql); - $question_type=mysql_result($result,0,0); - foreach ($possible_option as $option_id=>$value) { echo ''; @@ -766,10 +765,6 @@ function display_complete_report_row($possible_answers, $answers_of_user, $user) echo 'v'; } } - elseif($question_type=='open'){ - $a_answer = $answers_of_user[$question_id]; - echo key($a_answer); - } echo ''; } } diff --git a/main/survey/survey.lib.php b/main/survey/survey.lib.php index 36ebeb86b3..a6daa748da 100644 --- a/main/survey/survey.lib.php +++ b/main/survey/survey.lib.php @@ -100,7 +100,11 @@ class survey_manager if (!$values['survey_id'] OR !is_numeric($values['survey_id'])) { - $sql = "INSERT INTO $table_survey (code, title, subtitle, author, lang, avail_from, avail_till, is_shared, template, intro, surveythanks, creation_date) VALUES ( + if ($values['anonymous']=='') + { + $values['anonymous']=0; + } + $sql = "INSERT INTO $table_survey (code, title, subtitle, author, lang, avail_from, avail_till, is_shared, template, intro, surveythanks, creation_date, anonymous) VALUES ( '".Database::escape_string($values['survey_code'])."', '".Database::escape_string($values['survey_title'])."', '".Database::escape_string($values['survey_subtitle'])."', @@ -112,7 +116,9 @@ class survey_manager '".Database::escape_string('template')."', '".Database::escape_string($values['survey_introduction'])."', '".Database::escape_string($values['survey_thanks'])."', - '".date()."')"; + '".date()."', + '".Database::escape_string($values['anonymous'])."' + )"; $result = api_sql_query($sql, __FILE__, __LINE__); $survey_id = mysql_insert_id(); @@ -124,6 +130,10 @@ class survey_manager } else { + if ($values['anonymous']=='') + { + $values['anonymous']=0; + } $sql = "UPDATE $table_survey SET code = '".Database::escape_string($values['survey_code'])."', title = '".Database::escape_string($values['survey_title'])."', @@ -135,7 +145,8 @@ class survey_manager is_shared = '".Database::escape_string($shared_survey_id)."', template = '".Database::escape_string('template')."', intro = '".Database::escape_string($values['survey_introduction'])."', - surveythanks = '".Database::escape_string($values['survey_thanks'])."' + surveythanks = '".Database::escape_string($values['survey_thanks'])."', + anonymous = '".Database::escape_string($values['anonymous'])."' WHERE survey_id = '".Database::escape_string($values['survey_id'])."'"; $result = api_sql_query($sql, __FILE__, __LINE__); diff --git a/main/survey/survey.php b/main/survey/survey.php index 765dd10d2c..134d3134e0 100644 --- a/main/survey/survey.php +++ b/main/survey/survey.php @@ -21,7 +21,7 @@ Tel. +32 (2) 211 34 56 * @package dokeos.survey * @author unknown * @author Patrick Cool , Ghent University: cleanup, refactoring and rewriting large parts of the code -* @version $Id: survey.php 12221 2007-05-01 23:23:49Z yannoo $ +* @version $Id: survey.php 12901 2007-08-28 12:32:02Z pcool $ * * @todo use quickforms for the forms */ @@ -98,24 +98,24 @@ if (isset($_GET['message'])) // Action links $survey_actions = get_lang('Survey').': '; -$survey_actions .= ''.Display::return_icon('edit.gif', get_lang('Edit')).''; -$survey_actions .= ''.Display::return_icon('delete.gif', get_lang('Delete')).''; +$survey_actions .= ''.Display::return_icon('edit.gif', get_lang('Edit')).''; +$survey_actions .= ''.Display::return_icon('delete.gif', get_lang('Delete')).''; //$survey_actions .= ''.Display::return_icon('copy.gif', get_lang('Copy')).''; -$survey_actions .= ''.Display::return_icon('preview.gif', get_lang('Preview')).''; -$survey_actions .= ''.Display::return_icon('survey_publish.gif', get_lang('Publish')).''; -$survey_actions .= ''.Display::return_icon('statistics.gif', get_lang('Reporting')).''; +$survey_actions .= ''.Display::return_icon('preview.gif', get_lang('Preview')).''; +$survey_actions .= ''.Display::return_icon('survey_publish.gif', get_lang('Publish')).''; +$survey_actions .= ''.Display::return_icon('statistics.gif', get_lang('Reporting')).''; echo '
'.$survey_actions.'
'; echo ''; echo '
'; @@ -146,7 +146,7 @@ while ($row = mysql_fetch_assoc($result)) echo ' '; if (strlen($row['survey_question']) > 100) { - echo substr($row['survey_question'],0, 100).' ... '; + echo substr(strip_tags($row['survey_question']),0, 100).' ... '; } else { @@ -156,15 +156,15 @@ while ($row = mysql_fetch_assoc($result)) echo ' '.get_lang(ucfirst($row['type'])).''; echo ' '.$row['number_of_options'].''; echo ' '; - echo ' '.Display::return_icon('edit.gif', get_lang('Edit')).''; - echo ' '.Display::return_icon('delete.gif', get_lang('Delete')).''; + echo ' '.Display::return_icon('edit.gif', get_lang('Edit')).''; + echo ' '.Display::return_icon('delete.gif', get_lang('Delete')).''; if ($question_counter > 1) { - echo ' '.Display::return_icon('up.gif', get_lang('MoveUp')).''; + echo ' '.Display::return_icon('up.gif', get_lang('MoveUp')).''; } if ($question_counter < $question_counter_max) { - echo ' '.Display::return_icon('down.gif', get_lang('MoveDown')).''; + echo ' '.Display::return_icon('down.gif', get_lang('MoveDown')).''; } echo ' '; $question_counter++; diff --git a/main/survey/survey_invite.php b/main/survey/survey_invite.php index c83b8280d5..dfd0540770 100644 --- a/main/survey/survey_invite.php +++ b/main/survey/survey_invite.php @@ -136,7 +136,8 @@ if ($form->validate()) $values['additional_users'] = $values['additional_users'].';'; // this is for the case when you enter only one email $temp = str_replace(',',';',$values['additional_users']); // this is to allow , and ; as email separators $additional_users = explode(';',$temp); - for($i=0; $i, Ghent University: cleanup, refactoring and rewriting large parts of the code -* @version $Id: survey_list.php 12221 2007-05-01 23:23:49Z yannoo $ +* @version $Id: survey_list.php 12901 2007-08-28 12:32:02Z pcool $ * * @todo The invite column is not done * @todo try to understand the white, blue, ... template stuff. @@ -122,9 +122,9 @@ if ($_POST['action']) // Action links -echo ''.get_lang('CreateNewSurvey').' | '; +echo ''.get_lang('CreateNewSurvey').' | '; //echo ''.get_lang('CreateExistingSurvey').' | '; -echo ''.get_lang('Search').''; +echo ''.get_lang('Search').''; // Main content display_survey_list(); @@ -207,8 +207,10 @@ function display_survey_list() $table->set_header(7, get_lang('AvailableFrom')); $table->set_header(8, get_lang('AvailableUntill')); $table->set_header(9, get_lang('Invite')); - $table->set_header(10, get_lang('Modify'), false); - $table->set_column_filter(10, 'modify_filter'); + $table->set_header(10, get_lang('Anonymous')); + $table->set_header(11, get_lang('Modify'), false); + $table->set_column_filter(10, 'anonymous_filter'); + $table->set_column_filter(11, 'modify_filter'); $table->set_form_actions(array ('delete' => get_lang('DeleteSurvey'))); $table->display(); @@ -274,7 +276,8 @@ function get_survey_data($from, $number_of_items, $column, $direction) survey.avail_from AS col7, survey.avail_till AS col8, CONCAT('',survey.answered,' / ',survey.invited, '') AS col9, - survey.survey_id AS col10 + survey.anonymous AS col10, + survey.survey_id AS col11 FROM $table_survey survey LEFT JOIN $table_survey_question survey_question ON survey.survey_id = survey_question.survey_id , $table_user user @@ -305,16 +308,28 @@ function get_survey_data($from, $number_of_items, $column, $direction) */ function modify_filter($survey_id) { - $return = ''.Display::return_icon('edit.gif', get_lang('Edit')).''; - $return .= ''.Display::return_icon('delete.gif', get_lang('Delete')).''; + $return = ''.Display::return_icon('edit.gif', get_lang('Edit')).''; + $return .= ''.Display::return_icon('delete.gif', get_lang('Delete')).''; //$return .= ''.Display::return_icon('copy.gif', get_lang('Copy')).''; //$return .= ''.Display::return_icon('add.gif', get_lang('Add')).''; - $return .= ''.Display::return_icon('preview.gif', get_lang('Preview')).''; - $return .= ''.Display::return_icon('survey_publish.gif', get_lang('Publish')).''; - $return .= ''.Display::return_icon('statistics.gif', get_lang('Reporting')).''; + $return .= ''.Display::return_icon('preview.gif', get_lang('Preview')).''; + $return .= ''.Display::return_icon('survey_publish.gif', get_lang('Publish')).''; + $return .= ''.Display::return_icon('statistics.gif', get_lang('Reporting')).''; return $return; } +function anonymous_filter($anonymous) +{ + if ($anonymous == 1) + { + return get_lang('Yes'); + } + else + { + return get_lang('No'); + } +} + /** * this function handles the search restriction for the SQL statements