[svn r14639] General cleanup - Moved all functions into a SurveyUtil class

Added first version of XLS export of survey results (not fully functionnal yet) (see FS#2265)
skala
Yannick Warnier 17 years ago
parent 0a323306f2
commit 6f36c7c0a3
  1. 87
      main/survey/fillsurvey.php
  2. 14
      main/survey/preview.php
  3. 1224
      main/survey/reporting.php
  4. 1975
      main/survey/survey.lib.php
  5. 4
      main/survey/survey.php
  6. 76
      main/survey/survey_invitation.php
  7. 256
      main/survey/survey_invite.php
  8. 239
      main/survey/survey_list.php

@ -125,12 +125,6 @@ $survey_data['survey_id'] = $survey_invitation['survey_id'];
// storing the answers
if ($_POST)
{
/*
echo '<pre>';
print_r($_POST);
echo '</pre>';
*/
// getting all the types of the question (because of the special treatment of the score question type
$sql = "SELECT * FROM $table_survey_question WHERE survey_id = '".Database::escape_string($survey_invitation['survey_id'])."'";
$result = api_sql_query($sql, __FILE__, __LINE__);
@ -154,7 +148,7 @@ if ($_POST)
// when it is a scoring question then the key of the array is the option_id and the value is the value
if (is_array($value))
{
remove_answer($survey_invitation['user'], $survey_invitation['survey_id'], $survey_question_id);
SurveyUtil::remove_answer($survey_invitation['user'], $survey_invitation['survey_id'], $survey_question_id);
foreach ($value as $answer_key => $answer_value)
{
if ($types[$survey_question_id] == 'score')
@ -167,7 +161,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, $survey_data);
SurveyUtil::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, ...)
@ -192,9 +186,9 @@ if ($_POST)
$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, $survey_data);
//store_answer($user,$survey_id,$question_id, $option_id, $option_value, $survey_data);
SurveyUtil::remove_answer($survey_invitation['user'], $survey_invitation['survey_id'], $survey_question_id);
SurveyUtil::store_answer($survey_invitation['user'], $survey_invitation['survey_id'], $survey_question_id, $value, $option_value, $survey_data);
//SurveyUtil::store_answer($user,$survey_id,$question_id, $option_id, $option_value, $survey_data);
}
}
}
@ -337,75 +331,4 @@ echo '</form>';
// Footer
Display :: display_footer();
/**
* This function stores an answer of a user on a question of a survey
*
* @param mixed $user the user id or email of the person who fills the survey
* @param integer $survey_id the survey id
* @param integer $question_id the question id
* @param integer $option_id the option id
*
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
* @version January 2007
*/
function store_answer($user, $survey_id, $question_id, $option_id, $option_value, $survey_data)
{
global $_course;
global $types;
// 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)."',
'".Database::escape_string($question_id)."',
'".Database::escape_string($option_id)."',
'".Database::escape_string($option_value)."'
)";
$result = api_sql_query($sql, __FILE__, __LINE__);
}
/**
* This function removes an (or multiple) answer(s) of a user on a question of a survey
*
* @param mixed $user the user id or email of the person who fills the survey
* @param integer $survey_id the survey id
* @param integer $question_id the question id
* @param integer $option_id the option id
*
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
* @version January 2007
*/
function remove_answer($user, $survey_id, $question_id)
{
global $_course;
// table definition
$table_survey_answer = Database :: get_course_table(TABLE_SURVEY_ANSWER, $_course['db_name']);
$sql = "DELETE FROM $table_survey_answer
WHERE user = '".Database::escape_string($user)."'
AND survey_id = '".Database::escape_string($survey_id)."'
AND question_id = '".Database::escape_string($question_id)."'";
$result = api_sql_query($sql, __FILE__, __LINE__);
}
?>

@ -68,7 +68,7 @@ $interbreadcrumb[] = array ("url" => "survey.php?survey_id=".$_GET['survey_id'],
Display :: display_header(get_lang('SurveyPreview'));
// We exit here is the first or last question is a pagebreak (which causes errors)
check_first_last_question($_GET['survey_id'], false);
SurveyUtil::check_first_last_question($_GET['survey_id'], false);
// only a course admin is allowed to preview a survey: you are NOT a course admin => error message
if (!api_is_allowed_to_edit())
@ -108,7 +108,7 @@ else
ORDER BY sort ASC";
$result = api_sql_query($sql, __FILE__, __LINE__);
while ($row = mysql_fetch_assoc($result))
while ($row = Database::fetch_array($result))
{
if($row['type'] == 'pagebreak')
{
@ -128,15 +128,15 @@ else
LEFT JOIN $table_survey_question_option survey_question_option
ON survey_question.question_id = survey_question_option.question_id
WHERE survey_question.survey_id = '".Database::escape_string($_GET['survey_id'])."'
AND survey_question.question_id IN (".implode(',',$paged_questions[$_GET['show']]).")
AND survey_question.question_id IN (".Database::escape_string(implode(',',$paged_questions[$_GET['show']])).")
ORDER BY survey_question.sort, survey_question_option.sort ASC";
$result = api_sql_query($sql, __FILE__, __LINE__);
$question_counter_max = mysql_num_rows($result);
$question_counter_max = Database::num_rows($result);
$counter = 0;
$limit=0;
$questions = array();
while ($row = mysql_fetch_assoc($result))
while ($row = Database::fetch_array($result))
{
// if the type is not a pagebreak we store it in the $questions array
if($row['type'] <> 'pagebreak')
@ -161,7 +161,7 @@ else
// selecting the maximum number of pages
$sql = "SELECT * FROM $table_survey_question WHERE type='".Database::escape_string('pagebreak')."' AND survey_id='".Database::escape_string($_GET['survey_id'])."'";
$result = api_sql_query($sql, __FILE__, __LINE__);
$numberofpages = mysql_num_rows($result) + 1;
$numberofpages = Database::num_rows($result) + 1;
// Displaying the form with the questions
if (isset($_GET['show']))
{
@ -171,7 +171,7 @@ else
{
$show = 0;
}
echo '<form id="question" name="question" method="post" action="'.api_get_self().'?survey_id='.$_GET['survey_id'].'&show='.$show.'">';
echo '<form id="question" name="question" method="post" action="'.api_get_self().'?survey_id='.Security::remove_XSS($_GET['survey_id']).'&show='.$show.'">';
if(is_array($questions) && count($questions)>0)
{
foreach ($questions as $key=>$question)

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

@ -21,7 +21,7 @@ Tel. +32 (2) 211 34 56
* @package dokeos.survey
* @author unknown
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University: cleanup, refactoring and rewriting large parts of the code
* @version $Id: survey.php 14636 2008-03-17 22:24:08Z yannoo $
* @version $Id: survey.php 14639 2008-03-18 05:31:08Z yannoo $
*
* @todo use quickforms for the forms
*/
@ -97,7 +97,7 @@ if (isset($_GET['message']))
}
// We exit here is the first or last question is a pagebreak (which causes errors)
check_first_last_question($_GET['survey_id']);
SurveyUtil::check_first_last_question($_GET['survey_id']);
// Action links
$survey_actions = get_lang('Survey').': ';

@ -41,7 +41,7 @@ require_once (api_get_path(LIBRARY_PATH)."mail.lib.inc.php");
/** @todo this has to be moved to a more appropriate place (after the display_header of the code)*/
if (!api_is_allowed_to_edit())
{
Display :: display_header();
Display :: display_header(get_lang('Survey'));
Display :: display_error_message(get_lang('NotAllowed'), false);
Display :: display_footer();
exit;
@ -157,12 +157,6 @@ echo '</table>';
// Footer
Display :: display_footer();
/**
* @todo add the additional parameters
*/
@ -173,70 +167,6 @@ $table->set_header(0, get_lang('User'));
$table->set_header(1, get_lang('InvitationCode'));
$table->set_header(2, get_lang('InvitationDate'));
$table->set_header(3, get_lang('Answered'));
$table->set_column_filter(3, 'modify_filter');
$table->set_column_filter(3, 'SurveyUtil::modify_filter');
$table->display();
*/
/**
* Get all the information about the invitations of a certain survey
*
* @return unknown
*
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
* @version January 2007
*
* @todo use survey_id parameter instead of $_GET
*/
function get_survey_invitations_data()
{
// Database table definition
$table_survey_invitation = Database :: get_course_table(TABLE_SURVEY_INVITATION);
$table_user = Database :: get_main_table(TABLE_MAIN_USER);
$sql = "SELECT
survey_invitation.user as col1,
survey_invitation.invitation_code as col2,
survey_invitation.invitation_date as col3,
'' as col4
FROM $table_survey_invitation survey_invitation
LEFT JOIN $table_user user ON survey_invitation.user = user.user_id
WHERE survey_invitation.survey_id = '".Database::escape_string($_GET['survey_id'])."'";
$res = api_sql_query($sql, __FILE__, __LINE__);
while ($row = mysql_fetch_array($res))
{
$survey_invitation_data[] = $row;
}
return $survey_invitation_data;
}
/**
* Get the total number of survey invitations for a given survey (through $_GET['survey_id'])
*
* @return unknown
*
* @todo use survey_id parameter instead of $_GET
*
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
* @version January 2007
*/
function get_number_of_survey_invitations()
{
// Database table definition
$table_survey_invitation = Database :: get_course_table(TABLE_SURVEY_INVITATION);
$sql = "SELECT count(user) AS total FROM $table_survey_invitation WHERE survey_id='".Database::escape_string($_GET['survey_id'])."'";
$res = api_sql_query($sql, __FILE__, __LINE__);
$row = mysql_fetch_assoc($res);
return $row['total'];
}
/**
* @todo use global array for answered or not
*
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
* @version January 2007
*/
function modify_filter()
{
}
?>
*/

@ -44,7 +44,7 @@ require_once (api_get_path(LIBRARY_PATH)."mail.lib.inc.php");
/** @todo this has to be moved to a more appropriate place (after the display_header of the code)*/
if (!api_is_allowed_to_edit())
{
Display :: display_header();
Display :: display_header(get_lang('Survey'));
Display :: display_error_message(get_lang('NotAllowed'), false);
Display :: display_footer();
exit;
@ -139,9 +139,9 @@ if ($form->validate())
{
$values = $form->exportValues();
// save the invitation mail
save_invite_mail($values['mail_text'], $values['resend_to_all']);
SurveyUtil::save_invite_mail($values['mail_text'], $values['resend_to_all']);
// saving the invitations for the course users
$count_course_users = save_invitations($values['course_users'], $values['mail_title'], $values['mail_text'], $values['resend_to_all']);
$count_course_users = SurveyUtil::save_invitations($values['course_users'], $values['mail_title'], $values['mail_text'], $values['resend_to_all']);
// saving the invitations for the additional users
$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
@ -150,16 +150,16 @@ if ($form->validate())
{
$additional_users[$i] = trim($additional_users[$i]);
}
$counter_additional_users = save_invitations($additional_users, $values['mail_title'], $values['mail_text'], $values['resend_to_all']);
$counter_additional_users = SurveyUtil::save_invitations($additional_users, $values['mail_title'], $values['mail_text'], $values['resend_to_all']);
// updating the invited field in the survey table
update_count_invited($survey_data['code']);
SurveyUtil::update_count_invited($survey_data['code']);
$total_count = $count_course_users + $counter_additional_users;
Display :: display_confirmation_message($total_count.' '.get_lang('InvitationsSend'), false);
}
else
{
// getting the invited users
$defaults = get_invited_users($survey_data['code']);
$defaults = SurveyUtil::get_invited_users($survey_data['code']);
// getting the survey mail text
if (!empty($survey_data['reminder_mail']))
{
@ -179,249 +179,5 @@ Display :: display_footer();
/**
* Save the invitation mail
*
* @param string Text of the e-mail
* @param integer Whether the mail contents are for invite mail (0, default) or reminder mail (1)
*
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
* @version January 2007
*/
function save_invite_mail($mailtext, $reminder=0)
{
// Database table definition
$table_survey = Database :: get_course_table(TABLE_SURVEY);
// reminder or not
if ($reminder == 0)
{
$mail_field = 'invite_mail';
}
else
{
$mail_field = 'reminder_mail';
}
$sql = "UPDATE $table_survey SET $mail_field = '".Database::escape_string($mailtext)."' WHERE survey_id = '".$_GET['survey_id']."'";
$result = api_sql_query($sql, __FILE__, __LINE__);
}
/**
* This function saves all the invitations of course users and additional users in the
*
* @param unknown_type $users_array
* @param string $invitation_title the title of the invitation is used as the title of the mail
* @param string $invitation_text the text of the invitation is used as the text of the mail.
* The $invitation_text has to contain a **link** string or this will automatically be added to the end
*
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
* @version January 2007
*
* @todo create the survey link
*/
function save_invitations($users_array, $invitation_title, $invitation_text, $reminder=0)
{
global $_user;
global $_course;
global $_configuration;
// getting the survey information
$survey_data = survey_manager::get_survey($_GET['survey_id']);
// Database table definition
$table_survey_invitation = Database :: get_course_table(TABLE_SURVEY_INVITATION);
$table_user = Database :: get_main_table(TABLE_MAIN_USER);
$already_invited = array();
$survey_invitations = array();
// get the people who are already invited
if ($reminder == 1)
{
$survey_invitations = get_invitations($survey_data['survey_code']);
}
else
{
$already_invited = get_invited_users($survey_data['code']);
}
$counter = 0;
if (is_array($users_array))
{
foreach ($users_array as $key=>$value)
{
if(isset($value))
{
// generating the unique code
if(is_array($survey_invitations))
{
if ($reminder == 1 AND array_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']
$add_users_array = explode(';',$already_invited['additional_users']);
if ((is_numeric($value) AND !in_array($value,$already_invited['course_users'])) OR (!is_numeric($value) AND !in_array($value,$add_users_array)))
{
if(is_array($survey_invitations))
{
if (!array_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;
$text_link = '<a href="'.$survey_link.'">'.get_lang('ClickHereToAnswerTheSurvey')."</a><br />\r\n<br />\r\n".get_lang('OrCopyPasteTheFollowingUrl')." <br />\r\n ".$survey_link;
$replace_count = 0;
$full_invitation_text = str_ireplace('**link**', $text_link ,$invitation_text, $replace_count);
if ($replace_count < 1)
{
$full_invitation_text = $full_invitation_text . "<br />\r\n<br />\r\n".$text_link;
}
// optionally: finding the e-mail of the course user
if (is_numeric($value))
{
$sql = "SELECT firstname, lastname, email FROM $table_user WHERE user_id='".Database::escape_string($value)."'";
$result = api_sql_query($sql, __FILE__, __LINE__);
$row = mysql_fetch_assoc($result);
$recipient_email = $row['email'];
$recipient_name = $row['firstname'].' '.$row['lastname'];
}
else
{
/** @todo check if the $value is a valid email */
$recipient_email = $value;
}
// sending the mail
$sender_name = $_user['firstName'].' '.$_user['lastName'];
$sender_email = $_user['mail'];
$replyto = array();
if(api_get_setting('survey_email_sender_noreply')=='noreply')
{
$noreply = api_get_setting('noreply_email_address');
if(!empty($noreply))
{
$replyto['Reply-to'] = $noreply;
$sender_name = $noreply;
$sender_email = $noreply;
}
}
api_mail_html($recipient_name, $recipient_email, $invitation_title, $full_invitation_text, $sender_name, $sender_email, $replyto);
//mail($recipient_email, strip_tags($invitation_title), strip_tags($invitation_text));
$counter++;
}
}
}
}
return $counter;
}
/**
* This function recalculates the number of users who have been invited and updates the survey table with this value.
*
* @param unknown_type $survey_id
*
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
* @version January 2007
*/
function update_count_invited($survey_code)
{
// Database table definition
$table_survey_invitation = Database :: get_course_table(TABLE_SURVEY_INVITATION);
$table_survey = Database :: get_course_table(TABLE_SURVEY);
// counting the number of people that are invited
$sql = "SELECT count(user) as total FROM $table_survey_invitation WHERE survey_code = '".Database::escape_string($survey_code)."'";
$result = api_sql_query($sql, __FILE__, __LINE__);
$row = mysql_fetch_assoc($result);
$total_invited = $row['total'];
// updating the field in the survey table
$sql = "UPDATE $table_survey SET invited = '".Database::escape_string($total_invited)."' WHERE code = '".Database::escape_string($survey_code)."'";
$result = api_sql_query($sql, __FILE__, __LINE__);
}
/**
* 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)
*
* @todo consider making $defaults['additional_users'] also an array
*
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
* @version January 2007
*/
function get_invited_users($survey_code)
{
// Database table definition
$table_survey_invitation = Database :: get_course_table(TABLE_SURVEY_INVITATION);
// Selecting all the invitations of this survey
$sql = "SELECT user FROM $table_survey_invitation WHERE survey_code='".Database::escape_string($survey_code)."'";
$defaults = array();
$defaults['course_users'] = array();
$defaults['additional_users'] = '';
$result = api_sql_query($sql, __FILE__, __LINE__);
while ($row = mysql_fetch_assoc($result))
{
if (is_numeric($row['user']))
{
$defaults['course_users'][] = $row['user'];
}
else
{
if (empty($defaults['additional_users']))
{
$defaults['additional_users'] = $row['user'];
}
else
{
$defaults['additional_users'] .= ';'.$row['user'];
}
}
}
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__);
$return = array();
while ($row = mysql_fetch_assoc($result))
{
$return[$row['user']] = $row;
}
return $return;
}
?>

@ -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: survey_list.php 13922 2007-12-04 23:20:19Z yannoo $
* @version $Id: survey_list.php 14639 2008-03-18 05:31:08Z yannoo $
*
* @todo use quickforms for the forms
*/
@ -40,7 +40,7 @@ require_once (api_get_path(LIBRARY_PATH)."/course.lib.php");
/** @todo this has to be moved to a more appropriate place (after the display_header of the code)*/
if (!api_is_allowed_to_edit())
{
Display :: display_header();
Display :: display_header(get_lang('Survey'));
Display :: display_error_message(get_lang('NotAllowed'), false);
Display :: display_footer();
exit;
@ -70,7 +70,7 @@ Display :: display_header($tool_name);
// Action handling: searching
if (isset ($_GET['search']) AND $_GET['search'] == 'advanced')
{
display_survey_search_form();
SurveyUtil::display_survey_search_form();
}
// Action handling: deleting a survey
if (isset($_GET['action']) AND $_GET['action'] == 'delete' AND isset($_GET['survey_id']) AND is_numeric($_GET['survey_id']))
@ -138,244 +138,25 @@ echo '<a href="create_new_survey.php?'.api_get_cidreq().'&amp;action=add">'.get_
echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;search=advanced">'.get_lang('Search').'</a>';
// Main content
display_survey_list();
SurveyUtil::display_survey_list();
// Footer
Display :: display_footer();
/**
* This function displays the form for searching a survey
*
* @return html code
*
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
* @version January 2007
*
* @todo use quickforms
* @todo consider moving this to surveymanager.inc.lib.php
*/
function display_survey_search_form()
{
echo '<form method="get" action="survey_list.php?search=advanced">';
echo '<table>
<tr>
<td>'.get_lang('Title').'</td>
<td><input type="text" name="keyword_title"/></td>
</tr>
<tr>
<td>'.get_lang('Code').'</td>
<td><input type="text" name="keyword_code"/></td>
</tr>
<tr>
<td>'.get_lang('Language').'</td>
<td>
<select name="keyword_language"><option value="%">'.get_lang('All').'</option>';
$languages = api_get_languages();
foreach ($languages['name'] as $index => $name)
{
echo '<option value="'.$languages['folder'][$index].'">'.$name.'</option>';
}
echo ' </select>
</td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="submit" name="do_search" value="'.get_lang('Ok').'"/></td>
</tr>
</table>
</form>';
}
/**
* This function displays the sortable table with all the surveys
*
* @return html code
*
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
* @version January 2007
*/
function display_survey_list()
{
$parameters = array();
if ($_GET['do_search'])
{
$message = get_lang('DisplaySearchResults').'<br />';
$message .= '<a href="'.api_get_self().'">'.get_lang('DisplayAll').'</a>';
Display::display_normal_message($message, false);
}
// Create a sortable table with survey-data
$table = new SortableTable('surveys', 'get_number_of_surveys', 'get_survey_data',2);
$table->set_additional_parameters($parameters);
$table->set_header(0, '', false);
$table->set_header(1, get_lang('SurveyName'));
$table->set_header(2, get_lang('SurveyCode'));
$table->set_header(3, get_lang('NumberOfQuestions'));
$table->set_header(4, get_lang('Author'));
$table->set_header(5, get_lang('Language'));
$table->set_header(6, get_lang('Shared'));
$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('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();
}
/**
* This function calculates the total number of surveys
*
* @return integer
*
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
* @version January 2007
*/
/* Bypass functions to make direct use from SortableTable possible */
function get_number_of_surveys()
{
global $table_survey;
$search_restriction = survey_search_restriction();
if ($search_restriction)
{
$search_restriction = 'WHERE '.$search_restriction;
}
$sql = "SELECT count(survey_id) AS total_number_of_items FROM ".$table_survey.' '.$search_restriction;
$res = api_sql_query($sql, __FILE__, __LINE__);
$obj = mysql_fetch_object($res);
return $obj->total_number_of_items;
return SurveyUtil::get_number_of_surveys();
}
/**
* This function gets all the survey data that is to be displayed in the sortable table
*
* @param unknown_type $from
* @param unknown_type $number_of_items
* @param unknown_type $column
* @param unknown_type $direction
* @return unknown
*
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
* @version January 2007
*/
function get_survey_data($from, $number_of_items, $column, $direction)
{
global $table_survey;
global $table_user;
global $table_survey_question;
// searching
$search_restriction = survey_search_restriction();
if ($search_restriction)
{
$search_restriction = ' AND '.$search_restriction;
}
$sql = "SELECT
survey.survey_id AS col0,
CONCAT('<a href=\"survey.php?survey_id=',survey.survey_id,'\">',survey.title,'</a>') AS col1,
survey.code AS col2,
count(survey_question.question_id) AS col3,
CONCAT(user.firstname, ' ', user.lastname) AS col4,
survey.lang AS col5,
IF(is_shared<>0,'V','-') AS col6,
survey.avail_from AS col7,
survey.avail_till AS col8,
CONCAT('<a href=\"survey_invitation.php?view=answered&amp;survey_id=',survey.survey_id,'\">',survey.answered,'</a> / <a href=\"survey_invitation.php?view=invited&amp;survey_id=',survey.survey_id,'\">',survey.invited, '</a>') AS col9,
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
WHERE survey.author = user.user_id
$search_restriction
";
$sql .= " GROUP BY survey.survey_id";
$sql .= " ORDER BY col$column $direction ";
$sql .= " LIMIT $from,$number_of_items";
$res = api_sql_query($sql, __FILE__, __LINE__);
$surveys = array ();
while ($survey = mysql_fetch_row($res))
{
$surveys[] = $survey;
}
return $surveys;
return SurveyUtil::get_survey_data($from, $number_of_items, $column, $direction);
}
/**
* This function changes the modify column of the sortable table
*
* @param integer $survey_id the id of the survey
* @return html code that are the actions that can be performed on any survey
*
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
* @version January 2007
*/
function modify_filter($survey_id)
{
global $charset;
$return = '<a href="create_new_survey.php?'.api_get_cidreq().'&amp;action=edit&amp;survey_id='.$survey_id.'">'.Display::return_icon('edit.gif', get_lang('Edit')).'</a>';
$return .= '<a href="survey_list.php?'.api_get_cidreq().'&amp;action=delete&amp;survey_id='.$survey_id.'" onclick="javascript:if(!confirm(\''.addslashes(htmlentities(get_lang("DeleteSurvey").'?',ENT_QUOTES,$charset)).'\')) return false;">'.Display::return_icon('delete.gif', get_lang('Delete')).'</a>';
//$return .= '<a href="create_survey_in_another_language.php?id_survey='.$survey_id.'">'.Display::return_icon('copy.gif', get_lang('Copy')).'</a>';
//$return .= '<a href="survey.php?survey_id='.$survey_id.'">'.Display::return_icon('add.gif', get_lang('Add')).'</a>';
$return .= '<a href="preview.php?'.api_get_cidreq().'&amp;survey_id='.$survey_id.'">'.Display::return_icon('preview.gif', get_lang('Preview')).'</a>';
$return .= '<a href="survey_invite.php?'.api_get_cidreq().'&amp;survey_id='.$survey_id.'">'.Display::return_icon('survey_publish.gif', get_lang('Publish')).'</a>';
$return .= '<a href="survey_list.php?'.api_get_cidreq().'&amp;action=empty&amp;survey_id='.$survey_id.'" onclick="javascript:if(!confirm(\''.addslashes(htmlentities(get_lang("EmptySurvey").'?')).'\')) return false;">'.Display::return_icon('empty.gif', get_lang('EmptySurvey')).'</a>';
$return .= '<a href="reporting.php?'.api_get_cidreq().'&amp;survey_id='.$survey_id.'">'.Display::return_icon('statistics.gif', get_lang('Reporting')).'</a>';
return $return;
return SurveyUtil::modify_filter($survey_id);
}
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
*
* @return false or a part of a SQL statement
*
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
* @version January 2007
*/
function survey_search_restriction()
{
if ($_GET['do_search'])
{
if ($_GET['keyword_title']<>'')
{
$search_term[] = 'title =\''.Database::escape_string($_GET['keyword_title']).'\'';
}
if ($_GET['keyword_code']<>'')
{
$search_term[] = 'code =\''.Database::escape_string($_GET['keyword_code']).'\'';
}
if ($_GET['keyword_language']<>'%')
{
$search_term[] = 'lang =\''.Database::escape_string($_GET['keyword_language']).'\'';
}
$search_restriction = implode(' AND ', $search_term);
return $search_restriction;
}
else
{
return false;
}
}
?>
return SurveyUtil::anonymous_filter($anonymous);
}
Loading…
Cancel
Save