[svn r12952] Fixed 2 bugs:

1. reporting of non anonymous user did not display the user names
2. invitation reminder re-invited already invited users
http://www.dokeos.com/forum/viewtopic.php?t=11477
skala
Patrick Cool 18 years ago
parent e966fb2b5c
commit 03337c6f4e
  1. 48
      main/survey/reporting.php
  2. 27
      main/survey/survey.lib.php
  3. 51
      main/survey/survey_invite.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 <patrick.cool@UGent.be>, Ghent University: cleanup, refactoring and rewriting large parts of the code
* @version $Id: reporting.php 12912 2007-08-31 15:52:45Z pcool $
* @version $Id: reporting.php 12952 2007-09-07 07:07:17Z pcool $
*
* @todo The question has to be more clearly indicated (same style as when filling the survey)
*/
@ -158,6 +158,9 @@ Display :: display_footer();
function check_parameters()
{
$error = false;
// getting the survey data
$survey_data = survey_manager::get_survey($_GET['survey_id']);
// $_GET['survey_id'] has to be numeric
if (!is_numeric($_GET['survey_id']))
@ -176,8 +179,28 @@ function check_parameters()
if ($_GET['action'] == 'userreport')
{
global $people_filled;
$people_filled = survey_manager::get_people_who_filled_survey($_GET['survey_id']);
if (isset($_GET['user']) AND !in_array($_GET['user'], $people_filled))
if ($survey_data['anonymous'] == 0)
{
$people_filled_full_data = true;
}
else
{
$people_filled_full_data = false;
}
$people_filled = survey_manager::get_people_who_filled_survey($_GET['survey_id'], $people_filled_full_data);
if ($survey_data['anonymous'] == 0)
{
foreach ($people_filled as $key=>$value)
{
$people_filled_userids[]=$value['user_id'];
}
}
else
{
$people_filled_userids = $people_filled;
}
if (isset($_GET['user']) AND !in_array($_GET['user'], $people_filled_userids))
{
$error = get_lang('UnknowUser');
}
@ -257,8 +280,8 @@ function handle_reporting_actions()
*/
function display_user_report()
{
global $people_filled;
global $people_filled, $survey_data;
// Database table definitions
$table_survey_question = Database :: get_course_table(TABLE_SURVEY_QUESTION);
$table_survey_question_option = Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION);
@ -278,14 +301,25 @@ function display_user_report()
echo get_lang('SelectUserWhoFilledSurvey').'<br />';
echo '<select name="user" onchange="jumpMenu(\'parent\',this,0)">';
echo '<option value="reporting.php?action='.$_GET['action'].'&amp;survey_id='.$_GET['survey_id'].'">'.get_lang('SelectUser').'</option>';
foreach ($people_filled as $key=>$person)
{
echo '<option value="reporting.php?action='.$_GET['action'].'&amp;survey_id='.$_GET['survey_id'].'&amp;user='.$person.'" ';
if ($survey_data['anonymous'] == 0)
{
$name = $person['firstname'].' '.$person['lastname'];
$id = $person['user_id'];
}
else
{
$name = $person;
$id = $person;
}
echo '<option value="reporting.php?action='.$_GET['action'].'&amp;survey_id='.$_GET['survey_id'].'&amp;user='.$id.'" ';
if ($_GET['user'] == $person)
{
echo 'selected="selected"';
}
echo '>'.$person.'</option>';
echo '>'.$name.'</option>';
}
echo '</select>';

@ -874,12 +874,13 @@ class survey_manager
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
* @version February 2007
*/
function get_people_who_filled_survey($survey_id)
function get_people_who_filled_survey($survey_id, $all_user_info = false)
{
global $_course;
// Database table definition
$table_survey_invitation = Database :: get_course_table(TABLE_SURVEY_INVITATION, $_course['db_name']);
$table_survey_answer = Database :: get_course_table(TABLE_SURVEY_ANSWER, $_course['db_name']);
$table_user = Database :: get_main_table('user');
// variable initialisation
$return = array();
@ -887,11 +888,29 @@ class survey_manager
// getting the survey information
$survey_data = survey_manager::get_survey($survey_id);
$sql = "SELECT DISTINCT user FROM $table_survey_invitation WHERE survey_code= '".Database::escape_string($survey_data['code'])."' AND answered='1'";
if ($all_user_info)
{
$sql = "SELECT DISTINCT answered_user.user as invited_user, user.firstname, user.lastname, user.user_id
FROM $table_survey_answer answered_user, $table_user as user
WHERE answered_user.user = user.user_id
AND survey_id= '".Database::escape_string($survey_data['survey_id'])."'";
}
else
{
$sql = "SELECT DISTINCT user FROM $table_survey_answer WHERE survey_id= '".Database::escape_string($survey_data['survey_id'])."'";
}
echo $sql;
$res = api_sql_query($sql, __FILE__, __LINE__);
while ($row = mysql_fetch_assoc($res))
{
$return[] = $row['user'];
if ($all_user_info)
{
$return[] = $row;
}
else
{
$return[] = $row['user'];
}
}
return $return;

@ -158,7 +158,9 @@ if ($form->validate())
}
else
{
$defaults = get_invitations($survey_data['code']);
// getting the invited users
$defaults = get_invited_users($survey_data['code']);
// getting the survey mail text
if (!empty($survey_data['reminder_mail']))
{
$defaults['mail_text'] = $survey_data['reminder_mail'];
@ -234,10 +236,11 @@ function save_invitations($users_array, $invitation_title, $invitation_text, $re
if ($reminder == 1)
{
$already_invited = array();
$survey_invitations = get_invitations($survey_data['survey_code']);
}
else
{
$already_invited = get_invitations($survey_data['code']);
$already_invited = get_invited_users($survey_data['code']);
}
$counter = 0;
@ -246,16 +249,26 @@ function save_invitations($users_array, $invitation_title, $invitation_text, $re
foreach ($users_array as $key=>$value)
{
// generating the unique code
$invitation_code = md5($value.microtime());
if ($reminder == 1 AND key_exists($value,$survey_invitations))
{
$invitation_code = $survey_invitations[$value]['invitation_code'];
}
else
{
$invitation_code = md5($value.microtime());
}
$survey_link = '';
$full_invitation_text= '';
// storing the invitation (only if the user_id is not in $already_invited['course_users'] OR email is not in $already_invited['additional_users']
if ((is_numeric($value) AND !in_array($value,$already_invited['course_users'])) OR (!is_numeric($value) AND !strstr($already_invited['additional_users'], $value)) AND !empty($value))
{
$sql = "INSERT INTO $table_survey_invitation (user, survey_code, invitation_code, invitation_date) VALUES
('".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 = api_sql_query($sql, __FILE__, __LINE__);
if (!key_exists($value,$survey_invitations))
{
$sql = "INSERT INTO $table_survey_invitation (user, survey_code, invitation_code, invitation_date) VALUES
('".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 = api_sql_query($sql, __FILE__, __LINE__);
}
// replacing the **link** part with a valid link for the user
$survey_link = $_configuration['root_web'].$_configuration['code_append'].'survey/'.'fillsurvey.php?course='.$_course['sysCode'].'&invitationcode='.$invitation_code;
@ -324,7 +337,7 @@ function update_count_invited($survey_code)
}
/**
* This function gets all the invitations for a given survey code.
* This function gets all the invited users for a given survey code.
*
* @param unknown_type $survey_id
* @return array containing the course users and additional users (non course users)
@ -334,7 +347,7 @@ function update_count_invited($survey_code)
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
* @version January 2007
*/
function get_invitations($survey_code)
function get_invited_users($survey_code)
{
// Database table definition
$table_survey_invitation = Database :: get_course_table(TABLE_SURVEY_INVITATION);
@ -363,4 +376,26 @@ function get_invitations($survey_code)
}
return $defaults;
}
/**
* get all the invitations
*
* @param unknown_type $survey_code
* @return array
*
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
* @version September 2007
*/
function get_invitations($survey_code)
{
// Database table definition
$table_survey_invitation = Database :: get_course_table(TABLE_SURVEY_INVITATION);
$sql = "SELECT * FROM $table_survey_invitation WHERE survey_code = '".Database::escape_string($survey_code)."'";
$result = api_sql_query($sql, __FILE__, __LINE__);
while ($row = mysql_fetch_assoc($result))
{
$return[$row['user']] = $row;
}
return $return;
}
?>
Loading…
Cancel
Save