Fixing bug when inviting user to answer a survey see BT#5559

skala
Julio Montoya 13 years ago
parent e07a0cd1e0
commit e08f89ff81
  1. 25
      main/survey/survey.lib.php
  2. 8
      main/survey/survey_invite.php

@ -3823,7 +3823,7 @@ class SurveyUtil {
if (!array_key_exists($value, $survey_invitations)) { if (!array_key_exists($value, $survey_invitations)) {
$sql = "INSERT INTO $table_survey_invitation (c_id, user, survey_code, invitation_code, invitation_date) VALUES $sql = "INSERT INTO $table_survey_invitation (c_id, user, survey_code, invitation_code, invitation_date) VALUES
($course_id, '".Database::escape_string($value)."','".Database::escape_string($survey_data['code'])."','".Database::escape_string($invitation_code)."','".Database::escape_string(date('Y-m-d H:i:s'))."')"; ($course_id, '".Database::escape_string($value)."','".Database::escape_string($survey_data['code'])."','".Database::escape_string($invitation_code)."','".Database::escape_string(date('Y-m-d H:i:s'))."')";
$result = Database::query($sql); Database::query($sql);
} }
} }
// Send the email if checkboxed // Send the email if checkboxed
@ -3927,7 +3927,7 @@ class SurveyUtil {
// Updating the field in the survey table // Updating the field in the survey table
$sql = "UPDATE $table_survey SET invited = '".Database::escape_string($total_invited)."' WHERE c_id = $course_id AND code = '".Database::escape_string($survey_code)."'"; $sql = "UPDATE $table_survey SET invited = '".Database::escape_string($total_invited)."' WHERE c_id = $course_id AND code = '".Database::escape_string($survey_code)."'";
$result = Database::query($sql); Database::query($sql);
} }
/** /**
@ -3940,6 +3940,7 @@ class SurveyUtil {
* @todo consider making $defaults['additional_users'] also an array * @todo consider making $defaults['additional_users'] also an array
* *
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
* @author Julio Montoya, adding c_id fixes - Dec 2012
* @version January 2007 * @version January 2007
*/ */
static function get_invited_users($survey_code, $course_code = '') { static function get_invited_users($survey_code, $course_code = '') {
@ -3957,9 +3958,7 @@ class SurveyUtil {
$order_clause = api_sort_by_first_name() ? ' ORDER BY firstname, lastname' : ' ORDER BY lastname, firstname'; $order_clause = api_sort_by_first_name() ? ' ORDER BY firstname, lastname' : ' ORDER BY lastname, firstname';
$sql = "SELECT user $sql = "SELECT user
FROM $table_survey_invitation as table_invitation FROM $table_survey_invitation as table_invitation
LEFT JOIN $table_user as table_user WHERE table_invitation.c_id = $course_id AND survey_code='".Database::escape_string($survey_code)."'";
ON table_invitation.user = table_user.user_id AND table_invitation.c_id = $course_id
WHERE survey_code='".Database::escape_string($survey_code)."'".$order_clause;
$defaults = array(); $defaults = array();
$defaults['course_users'] = array(); $defaults['course_users'] = array();
@ -3976,6 +3975,18 @@ class SurveyUtil {
} }
} }
} }
if (!empty($defaults['course_users'])) {
$user_ids = implode("','", $defaults['course_users']);
$sql = "SELECT user_id FROM $table_user WHERE user_id IN ('$user_ids') $order_clause";
$result = Database::query($sql);
$fixed_users = array();
while ($row = Database::fetch_array($result)) {
$fixed_users[] = $row['user_id'];
}
$defaults['course_users'] = $fixed_users;
}
return $defaults; return $defaults;
} }
@ -4299,9 +4310,9 @@ class SurveyUtil {
survey.survey_id AS col9, survey.survey_id AS col9,
survey.session_id AS session_id survey.session_id AS session_id
FROM $table_survey survey FROM $table_survey survey
LEFT JOIN $table_survey_question survey_question ON survey.survey_id = survey_question.survey_id LEFT JOIN $table_survey_question survey_question ON (survey.survey_id = survey_question.survey_id AND survey_question.c_id = $course_id)
INNER JOIN $table_user user ON (survey.author = user.user_id) INNER JOIN $table_user user ON (survey.author = user.user_id)
WHERE survey.c_id = $course_id AND survey_question.c_id = $course_id WHERE survey.c_id = $course_id
$search_restriction $search_restriction
$condition_session "; $condition_session ";
$sql .= " GROUP BY survey.survey_id"; $sql .= " GROUP BY survey.survey_id";

@ -119,15 +119,16 @@ $users->setElementTemplate('
'); ');
$users->setButtonAttributes('add', array('class' => 'btn arrowr')); $users->setButtonAttributes('add', array('class' => 'btn arrowr'));
$users->setButtonAttributes('remove', array('class' => 'btn arrowl')); $users->setButtonAttributes('remove', array('class' => 'btn arrowl'));
// Additional users // Additional users
$form->addElement('textarea', 'additional_users', array(get_lang('AdditonalUsers'), get_lang('AdditonalUsersComment')), array('class' => 'span6', 'rows' => 2)); $form->addElement('textarea', 'additional_users', array(get_lang('AdditonalUsers'), get_lang('AdditonalUsersComment')), array('class' => 'span6', 'rows' => 5));
//$form->addElement('html', '<div> <h3>'.Display::return_icon('course.png', Security::remove_XSS(get_lang('SendMail')),'',ICON_SIZE_SMALL).' '.Security::remove_XSS(get_lang('SendMail')).'</h3><div>');
$form->addElement('html', '<div id="check_mail">'); $form->addElement('html', '<div id="check_mail">');
$form->addElement('checkbox', 'send_mail','', get_lang('SendMail')); $form->addElement('checkbox', 'send_mail','', get_lang('SendMail'));
$form->addElement('html', '</div>'); $form->addElement('html', '</div>');
$form->addElement('html', '<div id="mail_text">'); $form->addElement('html', '<div id="mail_text">');
// The title of the mail // The title of the mail
$form->addElement('text', 'mail_title', get_lang('MailTitle'), array('class' => 'span6')); $form->addElement('text', 'mail_title', get_lang('MailTitle'), array('class' => 'span6'));
// The text of the mail // The text of the mail
@ -169,6 +170,7 @@ if ($form->validate()) {
Display :: display_error_message(get_lang('FormHasErrorsPleaseComplete')); Display :: display_error_message(get_lang('FormHasErrorsPleaseComplete'));
// Getting the invited users // Getting the invited users
$defaults = SurveyUtil::get_invited_users($survey_data['code']); $defaults = SurveyUtil::get_invited_users($survey_data['code']);
// Getting the survey mail text // Getting the survey mail text
if (!empty($survey_data['reminder_mail'])) { if (!empty($survey_data['reminder_mail'])) {
$defaults['mail_text'] = $survey_data['reminder_mail']; $defaults['mail_text'] = $survey_data['reminder_mail'];
@ -216,6 +218,7 @@ if ($form->validate()) {
} else { } else {
// Getting the invited users // Getting the invited users
$defaults = SurveyUtil::get_invited_users($survey_data['code']); $defaults = SurveyUtil::get_invited_users($survey_data['code']);
// Getting the survey mail text // Getting the survey mail text
if (!empty($survey_data['reminder_mail'])) { if (!empty($survey_data['reminder_mail'])) {
$defaults['mail_text'] = $survey_data['reminder_mail']; $defaults['mail_text'] = $survey_data['reminder_mail'];
@ -224,6 +227,7 @@ if ($form->validate()) {
} }
$defaults['mail_title'] = $survey_data['mail_subject']; $defaults['mail_title'] = $survey_data['mail_subject'];
$defaults['send_mail'] = 1; $defaults['send_mail'] = 1;
$form->setDefaults($defaults); $form->setDefaults($defaults);
$form->display(); $form->display();
} }

Loading…
Cancel
Save