[svn r16697] Implement ways of deleting an user's answer to a survey (closes FS#2509) (by cfasanando)

skala
Yannick Warnier 16 years ago
parent c0b6274e38
commit cfdd3c1e91
  1. 4
      main/survey/reporting.php
  2. 44
      main/survey/survey.lib.php

@ -24,7 +24,7 @@
* @package dokeos.survey
* @author unknown, the initial survey that did not make it in 1.8 because of bad code
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University: cleanup, refactoring and rewriting large parts of the code
* @version $Id: reporting.php 16409 2008-09-22 13:51:15Z elixir_inter $
* @version $Id: reporting.php 16697 2008-11-07 21:47:40Z yannoo $
*
* @todo The question has to be more clearly indicated (same style as when filling the survey)
*/
@ -147,7 +147,6 @@ Display::display_header($tool_name,'Survey');
// Action handling
SurveyUtil::handle_reporting_actions();
if (!$_GET['action'] OR $_GET['action'] == 'overview')
{
$myweb_survey_id = Security::remove_XSS($_GET['survey_id']);
@ -157,5 +156,6 @@ if (!$_GET['action'] OR $_GET['action'] == 'overview')
echo '<b><a href="reporting.php?action=completereport&amp;survey_id='.$myweb_survey_id.'">'.get_lang('CompleteReport').'</a></b><br />'.get_lang('CompleteReportDetail').'<br /><br />';
}
// Footer
Display :: display_footer();

@ -24,7 +24,7 @@
* @package dokeos.survey
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University: cleanup, refactoring and rewriting large parts (if not all) of the code
@author Julio Montoya Armas <gugli100@gmail.com>, Dokeos: Personality Test modification and rewriting large parts of the code
* @version $Id: survey.lib.php 16486 2008-10-10 13:32:05Z elixir_inter $
* @version $Id: survey.lib.php 16697 2008-11-07 21:47:40Z yannoo $
*
* @todo move this file to inc/lib
* @todo use consistent naming for the functions (save vs store for instance)
@ -2391,7 +2391,7 @@ class SurveyUtil {
}
// $_GET['action']
$allowed_actions = array('overview', 'questionreport', 'userreport', 'comparativereport', 'completereport');
$allowed_actions = array('overview', 'questionreport', 'userreport', 'comparativereport', 'completereport','deleteuserreport');
if (isset($_GET['action']) AND !in_array($_GET['action'], $allowed_actions))
{
$error = get_lang('ActionNotAllowed');
@ -2490,8 +2490,42 @@ class SurveyUtil {
{
SurveyUtil::display_complete_report();
}
if ($_GET['action'] == 'deleteuserreport')
{
SurveyUtil::delete_user_report($_GET['survey_id'],$_GET['user']);
//SurveyUtil::display_user_report(); //Could work but looks a bit clunky
}
}
/**
* This function deletes the report of an user who wants to retake the survey
* @param integer survey_id
* @param integer user_id
* @return void
* @author Christian Fasanando Flores <christian.fasanando@dokeos.com>
* @version November 2008
*/
function delete_user_report($survey_id,$user_id) {
$table_survey_answer = Database :: get_course_table(TABLE_SURVEY_ANSWER);
$table_survey_invitation = Database :: get_course_table(TABLE_SURVEY_INVITATION);
$table_survey = Database :: get_course_table(TABLE_SURVEY);
if (!empty($survey_id) && !empty($user_id)) {
// delete data from survey_answer by user_id and survey_id
$sql = "DELETE FROM $table_survey_answer WHERE survey_id = '".(int)$survey_id."' AND user = '".(int)$user_id."'";
$result = api_sql_query($sql, __FILE__, __LINE__);
// update field answered from survey_invitation by user_id and survey_id
$sql = "UPDATE $table_survey_invitation SET answered = '0' WHERE survey_code = (SELECT code FROM $table_survey WHERE survey_id = '".(int)$survey_id."') AND user = '".(int)$user_id."'";
$result = api_sql_query($sql, __FILE__, __LINE__);
}
if($result !== false) {
$message = get_lang('SurveyUserAnswersHaveBeenRemovedSuccessfully').'<br />
<a href="reporting.php?action=userreport&survey_id='.Security::remove_XSS($survey_id).'">'.get_lang('GoBack').'</a>';
Display::display_normal_message($message, false);
}
}
/**
* This function displays the user report which is basically nothing more than a one-page display of all the questions
* of the survey that is filled with the answers of the person who filled the survey.
@ -2540,7 +2574,7 @@ class SurveyUtil {
$name = $key+1;
$id = $person;
}
echo '<option value="reporting.php?action='.Security::remove_XSS($_GET['action']).'&amp;survey_id='.Security::remove_XSS($_GET['survey_id']).'&amp;user='.$id.'" ';
echo '<option value="reporting.php?action='.Security::remove_XSS($_GET['action']).'&amp;survey_id='.Security::remove_XSS($_GET['survey_id']).'&amp;user='.Security::remove_XSS($id).'" ';
if ($_GET['user'] == $person)
{
echo 'selected="selected"';
@ -2548,12 +2582,12 @@ class SurveyUtil {
echo '>'.$name.'</option>';
}
echo '</select>';
// step 2: displaying the survey and the answer of the selected users
if (isset($_GET['user']))
{
Display::display_normal_message(get_lang('AllQuestionsOnOnePage'), false);
echo '<a href="reporting.php?action=deleteuserreport&amp;survey_id='.Security::remove_XSS($_GET['survey_id']).'&amp;user='.Security::remove_XSS($_GET['user']).'" >'.get_lang('DeleteSurveyByUser').'</a>';
// getting all the questions and options
$sql = "SELECT survey_question.question_id, survey_question.survey_id, survey_question.survey_question, survey_question.display, survey_question.max_value, survey_question.sort, survey_question.type,
survey_question_option.question_option_id, survey_question_option.option_text, survey_question_option.sort as option_sort

Loading…
Cancel
Save