[svn r11451] survey update

skala
Patrick Cool 18 years ago
parent 2a1394cb02
commit 3af2c96b18
  1. 132
      main/survey/create_new_survey.php
  2. 102
      main/survey/fillsurvey.php
  3. 63
      main/survey/preview.php
  4. 36
      main/survey/question.php
  5. 34
      main/survey/reporting.php
  6. 511
      main/survey/survey.lib.php
  7. 106
      main/survey/survey.php
  8. 75
      main/survey/survey_invitation.php
  9. 114
      main/survey/survey_invite.php
  10. 166
      main/survey/survey_list.php

@ -21,11 +21,8 @@
* @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 (if not all) of the code
* @version $Id: create_new_survey.php 11349 2007-03-02 15:57:21Z elixir_julian $
* @version $Id: create_new_survey.php 11451 2007-03-06 21:54:30Z pcool $
*
* @todo rename this file to survey.php
* @todo try to understand the template stuff and implement it (if needed)
* @todo check if the code is really unique (when adding or editing)
* @todo only the available platform languages should be used => need an api get_languages and and api_get_available_languages (or a parameter)
*/
@ -35,10 +32,6 @@ $language_file = 'survey';
// including the global dokeos file
require_once ('../inc/global.inc.php');
$fck_attribute['Width'] = '100%';
$fck_attribute['Height'] = '200';
$fck_attribute['ToolbarSet'] = 'Survey';
// including additional libraries
/** @todo check if these are all needed */
/** @todo check if the starting / is needed. api_get_path probably ends with an / */
@ -62,28 +55,64 @@ $table_course_survey_rel = Database :: get_main_table(TABLE_MAIN_COURSE_SURVEY)
if (!api_is_allowed_to_edit())
{
Display :: display_header();
Display :: display_error_message(get_lang('NotAllowedHere'));
Display :: display_error_message(get_lang('NotAllowedHere'), false);
Display :: display_footer();
exit;
}
// getting the survey information
$survey_data = survey_manager::get_survey($_GET['survey_id']);
$urlname = substr(strip_tags($survey_data['title']), 0, 40);
if (strlen(strip_tags($survey_data['title'])) > 40)
{
$urlname .= '...';
}
// breadcrumbs
if ($_GET['action'] == 'add')
{
$interbreadcrumb[] = array ("url" => "survey_list.php", "name" => get_lang('Survey'));
$interbreadcrumb[] = array ("url" => "survey_list.php", "name" => get_lang('SurveyList'));
$tool_name = get_lang('CreateNewSurvey');
}
if ($_GET['action'] == 'edit' AND is_numeric($_GET['survey_id']))
{
$interbreadcrumb[] = array ("url" => "survey_list.php", "name" => get_lang('Survey'));
$interbreadcrumb[] = array ("url" => "survey_list.php", "name" => get_lang('SurveyList'));
$interbreadcrumb[] = array ("url" => "survey.php?survey_id=".$_GET['survey_id'], "name" => $urlname);
$tool_name = get_lang('EditSurvey');
}
// Displaying the header
Display::display_header($tool_name);
// Displaying the tool title
//api_display_tool_title($tool_name);
// getting the default values
if ($_GET['action'] == 'edit' AND isset($_GET['survey_id']) AND is_numeric($_GET['survey_id']))
{
$defaults = $survey_data;
$defaults['survey_id'] = $_GET['survey_id'];
$defaults['survey_share'] = array();
$defaults['survey_share']['survey_share'] = $survey_data['survey_share'];
if (!is_numeric($survey_data['survey_share']) OR $survey_data['survey_share'] == 0)
{
$form_share_value = 'true';
}
else
{
$form_share_value = $defaults['survey_share']['survey_share'];
}
}
else
{
$defaults['survey_language'] = $_course['language'];
$defaults['start_date']['d'] = date('d');
$defaults['start_date']['F'] = date('F');
$defaults['start_date']['Y'] = date('Y');
$defaults['start_date']['H'] = date('H');
$defaults['start_date']['i'] = date('i');
$defaults['end_date']['d'] = date('d');
$defaults['end_date']['F'] = date('F');
$defaults['end_date']['Y'] = date('Y');
$defaults['end_date']['H'] = date('H');
$defaults['end_date']['i'] = date('i');
$defaults['survey_share']['survey_share'] = 0;
$form_share_value = 1;
}
// initiate the object
$form = new FormValidator('forumcategory', 'post', $_SERVER['PHP_SELF'].'?action='.$_GET['action'].'&survey_id='.$_GET['survey_id']);
@ -93,9 +122,12 @@ if ($_GET['action'] == 'edit' AND isset($_GET['survey_id']) AND is_numeric($_GET
{
$form->addElement('hidden', 'survey_id');
}
$form->addElement('text', 'survey_code', get_lang('SurveyCode'), 'style="width: 200px;"');
$form->addElement('text', 'survey_title', get_lang('SurveyTitle'), 'style="width: 350px;"');
$form->addElement('text', 'survey_subtitle', get_lang('SurveySubTitle'), 'style="width: 350px;"');
$form->addElement('text', 'survey_code', get_lang('SurveyCode'), array('size' => '40'));
$fck_attribute['Width'] = '100%';
$fck_attribute['Height'] = '100';
$fck_attribute['ToolbarSet'] = 'Survey';
$form->addElement('html_editor', 'survey_title', get_lang('SurveyTitle'));
$form->addElement('html_editor', 'survey_subtitle', get_lang('SurveySubTitle'));
$lang_array = api_get_languages();
foreach ($lang_array['name'] as $key=>$value)
{
@ -105,8 +137,10 @@ $form->addElement('select', 'survey_language', get_lang('Language'), $languages)
$form->addElement('datepicker', 'start_date', get_lang('StartDate'));
$form->addElement('datepicker', 'end_date', get_lang('EndDate'));
$group='';
$group[] =& HTML_QuickForm::createElement('radio', 'survey_share',null, get_lang('Yes'),1);
$group[] =& HTML_QuickForm::createElement('radio', 'survey_share',null, get_lang('Yes'),$form_share_value);
/** @todo maybe it is better to change this into false instead see line 95 in survey.lib.php */
$group[] =& HTML_QuickForm::createElement('radio', 'survey_share',null, get_lang('No'),0);
$fck_attribute['Height'] = '200';
$form->addGroup($group, 'survey_share', get_lang('ShareSurvey'), '&nbsp;');
$form->addElement('html_editor', 'survey_introduction', get_lang('SurveyIntroduction'));
$form->addElement('html_editor', 'survey_thanks', get_lang('SurveyThanks'));
@ -117,41 +151,49 @@ $form->addRule('survey_code', '<div class="required">'.get_lang('ThisFieldIsRequ
$form->addRule('survey_title', '<div class="required">'.get_lang('ThisFieldIsRequired'), 'required');
$form->addRule('start_date', get_lang('InvalidDate'), 'date');
$form->addRule('end_date', get_lang('InvalidDate'), 'date');
/** @todo add a rule that checks if the end_date > start_date */
$form->addRule(array ('start_date', 'end_date'), get_lang('StartDateShouldBeBeforeEndDate'), 'date_compare', 'lte');
// setting the default values
if ($_GET['action'] == 'edit' AND isset($_GET['survey_id']) AND is_numeric($_GET['survey_id']))
{
$survey_data = survey_manager::get_survey($_GET['survey_id']);
$defaults = $survey_data;
$defaults['survey_id'] = $_GET['survey_id'];
}
else
{
$defaults['survey_language'] = $_course['language'];
$defaults['start_date']['d'] = date('d');
$defaults['start_date']['F'] = date('F');
$defaults['start_date']['Y'] = date('Y');
$defaults['start_date']['H'] = date('H');
$defaults['start_date']['i'] = date('i');
$defaults['end_date']['d'] = date('d');
$defaults['end_date']['F'] = date('F');
$defaults['end_date']['Y'] = date('Y');
$defaults['end_date']['H'] = date('H');
$defaults['end_date']['i'] = date('i');
$defaults['survey_share']['survey_share'] = 0;
}
$form->setDefaults($defaults);
// The validation or display
if( $form->validate() )
{
$values = $form->exportValues();
$return = survey_manager::store_survey($values);
Display::display_confirmation_message($return['message'],false);
// exporting the values
$values = $form->exportValues();
// storing the survey
$return = survey_manager::store_survey($values);
// deleting the shared survey if the survey is getting unshared (this only happens when editing)
if (is_numeric($survey_data['survey_share']) AND $values['survey_share']['survey_share'] == 0 AND $values['survey_id']<>'')
{
survey_manager::delete_survey($survey_data['survey_share'], true);
}
// storing the already existing questions and options of a survey that gets shared (this only happens when editing)
if ($survey_data['survey_share']== 0 AND $values['survey_share']['survey_share'] !== 0 AND $values['survey_id']<>'')
{
survey_manager::get_complete_survey_structure($return['id']);
}
if ($config['survey']['debug'])
{
// displaying a feedback message
Display::display_confirmation_message($return['message'], false);
}
else
{
// redirecting to the survey page (whilst showing the return message
header('location:survey.php?survey_id='.$return['id'].'&message='.$return['message']);
}
}
else
{
// Displaying the header
Display::display_header($tool_name);
// Displaying the tool title
//api_display_tool_title($tool_name);
// display the form
$form->display();
}

@ -26,6 +26,7 @@
* @todo use quickforms for the forms
* @todo check if the user already filled the survey and if this is the case then the answers have to be updated and not stored again.
* alterantively we could not allow people from filling the survey twice.
* @todo performance could be improved if not the survey_id was stored with the invitation but the survey_code
*/
// name of the language file that needs to be included
@ -56,18 +57,10 @@ $table_survey_invitation = Database :: get_course_table(TABLE_SURVEY_INVITATIO
// Header
Display :: display_header(get_lang('Survey'));
// debug
/*
echo '<pre>';
print_r($_POST);
echo '</pre>';
*/
// first we check if the needed parameters are present
if (!isset($_GET['course']) OR !isset($_GET['invitationcode']))
{
Display :: display_error_message(get_lang('SurveyParametersMissingUseCopyPaste'));
Display :: display_error_message(get_lang('SurveyParametersMissingUseCopyPaste'), false);
Display :: display_footer();
exit;
}
@ -77,12 +70,50 @@ $sql = "SELECT * FROM $table_survey_invitation WHERE invitation_code = '".mysql_
$result = api_sql_query($sql, __FILE__, __LINE__);
if (mysql_num_rows($result) < 1)
{
Display :: display_error_message(get_lang('WrongInvitationCode'));
Display :: display_error_message(get_lang('WrongInvitationCode'), false);
Display :: display_footer();
exit;
}
$survey_invitation = mysql_fetch_assoc($result);
// now we check if the user already filled the survey
if ($survey_invitation['answered'] == 1)
{
Display :: display_error_message(get_lang('YouAlreadyFilledThisSurvey'), false);
Display :: display_footer();
exit;
}
// checking if there is another survey with this code.
// If this is the case there will be a language choice
$sql = "SELECT * FROM $table_survey WHERE code='".mysql_real_escape_string($survey_invitation['survey_code'])."'";
$result = api_sql_query($sql, __FILE__, __LINE__);
if (mysql_num_rows($result) > 1)
{
if ($_POST['language'])
{
$survey_invitation['survey_id'] = $_POST['language'];
}
else
{
echo '<form id="language" name="language" method="POST" action="'.$_SERVER['PHP_SELF'].'?course='.$_GET['course'].'&invitationcode='.$_GET['invitationcode'].'">';
echo ' <select name="language">';
while ($row=mysql_fetch_assoc($result))
{
echo '<option value="'.$row['survey_id'].'">'.$row['lang'].'</option>';
}
echo '</select>';
echo ' <input type="submit" name="Submit" value="'.get_lang('Ok').'" />';
echo '</form>';
display::display_footer();
exit;
}
}
else
{
$row=mysql_fetch_assoc($result);
$survey_invitation['survey_id'] = $row['survey_id'];
}
// storing the answers
if ($_POST)
@ -94,6 +125,7 @@ if ($_POST)
$survey_question_id = str_replace('question', '',$key);
if (is_array($value))
{
remove_answer($survey_invitation['user'], $survey_invitation['survey_id'], $survey_question_id);
foreach ($value as $answer_key => $answer_value)
{
store_answer($survey_invitation['user'], $survey_invitation['survey_id'], $survey_question_id, $answer_value);
@ -102,29 +134,33 @@ if ($_POST)
else // multipleresponse
{
$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);
}
}
}
}
// survey information
// 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 '<div id="survey_title">'.$survey_data['survey_title'].'</div>';
echo '<div id="survey_subtitle">'.$survey_data['survey_subtitle'].'</div>';
// displaying the survey introduction
if (!isset($_GET['show']))
{
echo '<div id="survey_content">'.$survey_data['survey_introduction'].'</div>';
echo '<div id="survey_content" class="survey_content">'.$survey_data['survey_introduction'].'</div>';
$limit = 0;
}
// displaying the survey thanks message
if ($_POST['finish_survey'])
{
echo '<div id="survey_content"><strong>'.get_lang('SurveyFinished').'</strong>'.$survey_data['survey_thanks'].'</div>';
survey_manager::update_survey_answered($survey_invitation['survey_id']);
echo '<div id="survey_content" class="survey_content"><strong>'.get_lang('SurveyFinished').'</strong> <br />'.$survey_data['survey_thanks'].'</div>';
survey_manager::update_survey_answered($survey_data['survey_id'], $survey_invitation['user']);
Display :: display_footer();
exit;
}
@ -170,35 +206,30 @@ if (isset($_GET['show']))
// Displaying the form with the questions
echo '<form id="question" name="question" method="post" action="'.$_SERVER['PHP_SELF'].'?course='.$_GET['course'].'&invitationcode='.$_GET['invitationcode'].'&show='.$limit.'">';
echo '<input type="hidden" name="language" value="'.$_POST['language'].'" />';
foreach ($questions as $key=>$question)
{
$display = new $question['type'];
$display->render_question($question);
}
if (($limit AND $limit <> $question_counter_max) OR !$_GET['show'])
if (($limit AND $limit <> $question_counter_max) OR !isset($_GET['show']))
{
//echo '<a href="'.$_SERVER['PHP_SELF'].'?survey_id='.$survey_invitation['survey_id'].'&amp;show='.$limit.'">NEXT</a>';
echo '<input type="submit" name="next_survey_page" value="'.get_lang('Next').' >> " />';
}
if (!$limit AND $_GET['show'])
if (!$limit AND isset($_GET['show']))
{
echo '<input type="submit" name="finish_survey" value="'.get_lang('FinishSurvey').' >> " />';
}
echo '</form>';
/*
echo '<pre>';
print_r($questions);
echo '</pre>';
*/
// Footer
Display :: display_footer();
/**
* This function stores an answer on a survey
* 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
@ -223,4 +254,29 @@ function store_answer($user, $survey_id, $question_id, $option_id)
)";
$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 = '".mysql_real_escape_string($user)."'
AND survey_id = '".mysql_real_escape_string($survey_id)."'
AND question_id = '".mysql_real_escape_string($question_id)."'";
$result = api_sql_query($sql, __FILE__, __LINE__);
}
?>

@ -1,20 +1,20 @@
<?php
/*
DOKEOS - elearning and course management software
DOKEOS - elearning and course management software
For a full list of contributors, see documentation/credits.html
For a full list of contributors, see documentation/credits.html
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
See "documentation/licence.html" more details.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
See "documentation/licence.html" more details.
Contact:
Dokeos
Rue des Palais 44 Paleizenstraat
B-1030 Brussels - Belgium
Tel. +32 (2) 211 34 56
Contact:
Dokeos
Rue des Palais 44 Paleizenstraat
B-1030 Brussels - Belgium
Tel. +32 (2) 211 34 56
*/
/**
@ -43,48 +43,49 @@ $table_survey_question_option = Database :: get_course_table(TABLE_SURVEY_QUEST
$table_course = Database :: get_main_table(TABLE_MAIN_COURSE);
$table_user = Database :: get_main_table(TABLE_MAIN_USER);
// getting the survey information
$survey_data = survey_manager::get_survey($_GET['survey_id']);
$urlname = substr(strip_tags($survey_data['title']), 0, 40);
if (strlen(strip_tags($survey_data['title'])) > 40)
{
$urlname .= '...';
}
// breadcrumbs
$interbreadcrumb[] = array ("url" => 'survey_list.php', 'name' => get_lang('SurveyList'));
$interbreadcrumb[] = array ("url" => "survey.php?survey_id=".$_GET['survey_id'], "name" => $urlname);
// Header
Display :: display_header(get_lang('SurveyPreview'));
// debug
/*
echo '<pre>';
print_r($_POST);
echo '</pre>';
*/
// only a course admin is allowed to preview a survey: you are NOT a course admin => error message
if (!api_is_allowed_to_edit())
{
Display :: display_error_message(get_lang('NotAllowedHere'));
Display :: display_error_message(get_lang('NotAllowedHere'), false);
}
// only a course admin is allowed to preview a survey: you are a course admin
else
{
if (!isset($_GET['survey_id']) OR !is_numeric($_GET['survey_id']))
{
Display :: display_error_message(get_lang('InvallidSurvey'));
Display :: display_error_message(get_lang('InvallidSurvey'), false);
}
// survey information
$survey_data = survey_manager::get_survey($_GET['survey_id']);
echo '<div id="survey_title">'.$survey_data['survey_title'].'</div>';
echo '<div id="survey_subtitle">'.$survey_data['survey_subtitle'].'</div>';
// displaying the survey introduction
if (!isset($_GET['show']))
{
echo '<div id="survey_content">'.$survey_data['survey_introduction'].'</div>';
echo '<div id="survey_content" class="survey_content">'.$survey_data['survey_introduction'].'</div>';
$limit = 0;
}
// displaying the survey thanks message
if ($_POST['finish_survey'])
{
echo '<div id="survey_content"><strong>'.get_lang('SurveyFinished').'</strong>'.$survey_data['survey_thanks'].'</div>';
echo '<div id="survey_content" class="survey_content"><strong>'.get_lang('SurveyFinished').'</strong>'.$survey_data['survey_thanks'].'</div>';
Display :: display_footer();
exit;
}
@ -101,11 +102,12 @@ else
ORDER BY survey_question.sort ASC";
if ($_GET['show'])
{
$sql .= ' LIMIT '.($_GET['show']+1).',1000';
$sql .= ' LIMIT '.($_GET['show']+1).',1000';
}
$result = api_sql_query($sql, __FILE__, __LINE__);
$question_counter_max = mysql_num_rows($result);
$counter = 0;
$limit=0;
while ($row = mysql_fetch_assoc($result))
{
// if the type is not a pagebreak we store it in the $questions array
@ -135,23 +137,16 @@ else
$display = new $question['type'];
$display->render_question($question);
}
if (($limit AND $limit <> $question_counter_max) OR !$_GET['show'])
{
//echo '<a href="'.$_SERVER['PHP_SELF'].'?survey_id='.$_GET['survey_id'].'&amp;show='.$limit.'">NEXT</a>';
echo '<input type="submit" name="next_survey_page" value="'.get_lang('Next').' >> " />';
echo '<br /><input type="submit" name="next_survey_page" value="'.get_lang('Next').' >> " />';
}
if (!$limit AND $_GET['show'])
if ($limit==0 AND $_GET['show'])
{
echo '<input type="submit" name="finish_survey" value="'.get_lang('FinishSurvey').' >> " />';
}
echo '</form>';
/*
echo '<pre>';
print_r($questions);
echo '</pre>';
*/
}
// Footer

@ -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: question.php 11134 2007-02-16 14:39:59Z pcool $
* @version $Id: question.php 11451 2007-03-06 21:54:30Z pcool $
*/
// name of the language file that needs to be included
@ -38,7 +38,7 @@ require_once('survey.lib.php');
if (!api_is_allowed_to_edit())
{
Display :: display_header();
Display :: display_error_message(get_lang('NotAllowedHere'));
Display :: display_error_message(get_lang('NotAllowedHere'), false);
Display :: display_footer();
exit;
}
@ -51,9 +51,17 @@ $table_survey_question_option = Database :: get_course_table(TABLE_SURVEY_QUEST
$table_course = Database :: get_main_table(TABLE_MAIN_COURSE);
$table_user = Database :: get_main_table(TABLE_MAIN_USER);
// getting the survey information
$survey_data = survey_manager::get_survey($_GET['survey_id']);
$urlname = substr(strip_tags($survey_data['title']), 0, 40);
if (strlen(strip_tags($survey_data['title'])) > 40)
{
$urlname .= '...';
}
// breadcrumbs
$interbreadcrumb[] = array ("url" => 'survey_list.php', 'name' => get_lang('SurveyList'));
$interbreadcrumb[] = array ("url" => 'survey.php?survey_id='.$_GET['survey_id'], 'name' => get_lang('Survey'));
$interbreadcrumb[] = array ("url" => 'survey.php?survey_id='.$_GET['survey_id'], 'name' => $urlname);
// Tool name
if ($_GET['action'] == 'add')
@ -65,8 +73,7 @@ if ($_GET['action'] == 'edit')
$tool_name = get_lang('EditQuestion');
}
// Displaying the header
Display::display_header($tool_name);
// the possible question types
$possible_types = array('yesno', 'multiplechoice', 'multipleresponse', 'open', 'dropdown', 'comment', 'pagebreak');
@ -74,24 +81,29 @@ $possible_types = array('yesno', 'multiplechoice', 'multipleresponse', 'open', '
// checking if it is a valid type
if (!in_array($_GET['type'], $possible_types))
{
Display :: display_error_message(get_lang('TypeDoesNotExist'));
Display::display_header($tool_name);
Display :: display_error_message(get_lang('TypeDoesNotExist'), false);
Display :: display_footer();
}
// Displaying the survey information
$survey_data = survey_manager::get_survey($_GET['survey_id']);
echo '<a href="survey.php?survey_id='.$survey_data['survey_id'].'">'.$survey_data['title'].'</a><br />';
echo $survey_data['subtitle'];
// displaying the form for adding or editing the question
if (!$_POST['save_question'])
{
// Displaying the header
Display::display_header($tool_name);
echo '<img src="../img/'.survey_manager::icon_question($_GET['type']).'" alt="'.get_lang(ucfirst($_GET['type'])).'" title="'.get_lang(ucfirst($_GET['type'])).'" /><br />';
echo get_lang(ucfirst($_GET['type']));
$form = new $_GET['type'];
// The defaults values for the form
$form_content['horizontalvertical'] = 'vertical';
$form_content['answers'] = array('', '');
if ($_GET['type'] == 'yesno')
{
$form_content['answers'][0]=get_lang('Yes');
$form_content['answers'][1]=get_lang('No');
}
// We are editing a question
if (isset($_GET['question_id']) AND !empty($_GET['question_id']))
{

@ -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 11134 2007-02-16 14:39:59Z pcool $
* @version $Id: reporting.php 11451 2007-03-06 21:54:30Z pcool $
*
* @todo use quickforms for the forms
*/
@ -78,7 +78,7 @@ check_parameters();
if (!api_is_allowed_to_edit())
{
Display :: display_header();
Display :: display_error_message(get_lang('NotAllowedHere'));
Display :: display_error_message(get_lang('NotAllowedHere'), false);
Display :: display_footer();
exit;
}
@ -91,8 +91,17 @@ $table_course = Database :: get_main_table(TABLE_MAIN_COURSE);
$table_user = Database :: get_main_table(TABLE_MAIN_USER);
$user_info = Database :: get_main_table(TABLE_MAIN_SURVEY_REMINDER);
// getting the survey information
$survey_data = survey_manager::get_survey($_GET['survey_id']);
$urlname = substr(strip_tags($survey_data['title']), 0, 40);
if (strlen(strip_tags($survey_data['title'])) > 40)
{
$urlname .= '...';
}
// breadcrumbs
$interbreadcrumb[] = array ("url" => "survey_list.php", "name" => get_lang('SurveyList'));
$interbreadcrumb[] = array ('url' => 'survey.php?survey_id='.$_GET['survey_id'], 'name' => $urlname);
if (!$_GET['action'] OR $_GET['action'] == 'overview')
{
$tool_name = get_lang('Reporting');
@ -112,10 +121,10 @@ handle_reporting_actions();
if (!$_GET['action'] OR $_GET['action'] == 'overview')
{
echo '<b><a href="reporting.php?action=questionreport&amp;survey_id='.$_GET['survey_id'].'">see detailed report question by question</a></b> <br />In this report you see the results question by question. A basic statistical analysis is provided <br />';
echo '<b><a href="reporting.php?action=userreport&amp;survey_id='.$_GET['survey_id'].'">see the answers from a user</a></b><br />In this report you can see all the answers a specific user has given.<br />';
echo '<b><a href="reporting.php?action=comparativereport&amp;survey_id='.$_GET['survey_id'].'">Comparative report</a></b><br />In this report you can compare two questions.<br />';
echo '<b><a href="reporting.php?action=completereport&amp;survey_id='.$_GET['survey_id'].'">Complete report</a></b><br />In this report you get an overview of all the answers of all users on all questions. You also have the option to see only a selection of questions. You can export the results in CSV format and use this for processing in a statistical application<br />';
echo '<b><a href="reporting.php?action=questionreport&amp;survey_id='.$_GET['survey_id'].'">'.get_lang('DetailedReportByQuestion').'</a></b> <br />'.get_lang('DetailedReportByQuestionDetail').' <br /><br />';
echo '<b><a href="reporting.php?action=userreport&amp;survey_id='.$_GET['survey_id'].'">'.get_lang('DetailedReportByUser').'</a></b><br />'.get_lang('DetailedReportByUserDetail').'.<br /><br />';
echo '<b><a href="reporting.php?action=comparativereport&amp;survey_id='.$_GET['survey_id'].'">'.get_lang('ComparativeReport').'</a></b><br />'.get_lang('ComparativeReportDetail').'.<br /><br />';
echo '<b><a href="reporting.php?action=completereport&amp;survey_id='.$_GET['survey_id'].'">'.get_lang('CompleteReport').'</a></b><br />'.get_lang('CompleteReportDetail').'<br /><br />';
}
// Footer
@ -173,7 +182,7 @@ function check_parameters()
if ($error)
{
Display::display_header();
Display::display_error_message(get_lang('Error').': '.$error);
Display::display_error_message(get_lang('Error').': '.$error, false);
Display::display_footer();
exit;
}
@ -191,11 +200,6 @@ function check_parameters()
*/
function handle_reporting_actions()
{
// Displaying the survey information
$survey_data = survey_manager::get_survey($_GET['survey_id']);
echo '<strong>'.$survey_data['title'].'</strong><br />';
echo $survey_data['subtitle'].'<br />';
// getting the number of question
$questions_data = survey_manager::get_questions($_GET['survey_id']);
$survey_data['number_of_questions'] = count($questions_data);
@ -264,7 +268,7 @@ function display_user_report()
// step 2: displaying the survey and the answer of the selected users
if (isset($_GET['user']))
{
Display::display_normal_message(get_lang('AllQuestionsOnOnePage'));
Display::display_normal_message(get_lang('AllQuestionsOnOnePage'), false);
// 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.sort, survey_question.type,
@ -347,7 +351,7 @@ function display_question_report($survey_data)
$result = api_sql_query($sql, __FILE__, __LINE__);
$question = mysql_fetch_assoc($result);
if (!isset($_GET['question']) OR $_GET['question'] <> 0)
if ($_GET['question'] <> 0)
{
echo '<a href="reporting.php?action='.$_GET['action'].'&amp;survey_id='.$_GET['survey_id'].'&amp;question='.($offset-1).'">'.get_lang('PreviousQuestion').'</a>';
}
@ -734,7 +738,7 @@ function display_comparative_report()
$questions = survey_manager::get_questions($_GET['survey_id']);
// displaying an information message that only the questions with predefined answers can be used in a comparative report
Display::display_normal_message(get_lang('OnlyQuestionsWithPredefinedAnswers'));
Display::display_normal_message(get_lang('OnlyQuestionsWithPredefinedAnswers'), false);
// The form for selecting the axis of the table
echo '<form id="form1" name="form1" method="get" action="'.$_SERVER['PHP_SELF'].'?action='.$_GET['action'].'&survey_id='.$_GET['survey_id'].'&xaxis='.$_GET['xaxis'].'&y='.$_GET['yaxis'].'">';

@ -1,4 +1,5 @@
<?php
$config['survey']['debug'] = false;
/*
DOKEOS - elearning and course management software
@ -37,22 +38,28 @@ class survey_manager
* This function retrieves all the survey information
*
* @param integer $survey_id the id of the survey
* @param boolean $shared this parameter determines if we have to get the information of a survey from the central (shared) database or from the
* course database
*
* @return array
*
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
* @version January 2007
* @version February 2007
*
* @todo move this function to surveymanager.inc.lib.php
* @todo this is the same function as in create_new_survey.php
*/
function get_survey($survey_id)
function get_survey($survey_id,$shared=0)
{
global $_course;
// table definition
$tbl_survey = Database :: get_course_table(TABLE_SURVEY, $_course['db_name']);
$table_survey = Database :: get_course_table(TABLE_SURVEY, $_course['db_name']);
if ($shared<>0)
{
$table_survey = Database :: get_main_table(TABLE_MAIN_SHARED_SURVEY_QUESTION);
}
$sql = "SELECT * FROM $tbl_survey WHERE survey_id='".mysql_real_escape_string($survey_id)."'";
$sql = "SELECT * FROM $table_survey WHERE survey_id='".mysql_real_escape_string($survey_id)."'";
$result = api_sql_query($sql, __FILE__, __LINE__);
$return = mysql_fetch_assoc($result);
@ -71,22 +78,25 @@ class survey_manager
}
/**
* This function stores a survey in the database
* This function stores a survey in the database.
*
* @param array $values
* @return array $return the type of return message that has to be displayed and the message in it
*
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
* @version January 2007
*
* @todo move this function to surveymanager.inc.lib.php
* @version February 2007
*/
function store_survey($values)
{
global $_user;
// table defnitions
$table_survey = Database :: get_course_table(TABLE_SURVEY);
$table_survey = Database :: get_course_table(TABLE_SURVEY);
if ($values['survey_share']['survey_share'] !== '0')
{
$shared_survey_id = survey_manager::store_shared_survey($values);
}
if (!$values['survey_id'] OR !is_numeric($values['survey_id']))
{
@ -98,7 +108,7 @@ class survey_manager
'".mysql_real_escape_string($values['survey_language'])."',
'".mysql_real_escape_string($values['start_date'])."',
'".mysql_real_escape_string($values['end_date'])."',
'".mysql_real_escape_string($values['survey_share']['survey_share'])."',
'".mysql_real_escape_string($shared_survey_id)."',
'".mysql_real_escape_string('template')."',
'".mysql_real_escape_string($values['survey_introduction'])."',
'".mysql_real_escape_string($values['survey_thanks'])."',
@ -106,9 +116,11 @@ class survey_manager
$result = api_sql_query($sql, __FILE__, __LINE__);
$survey_id = mysql_insert_id();
$return['message'] = get_lang('SurveyCreatedSuccesfully').'<br />'.get_lang('YouCanNowAddQuestionToYourSurvey').': ';
$return['message'] .= '<a href="survey.php?survey_id='.$survey_id.'">'.get_lang('ClickHere').'</a>';
//$return['message'] = get_lang('SurveyCreatedSuccesfully').'<br />'.get_lang('YouCanNowAddQuestionToYourSurvey').': ';
//$return['message'] .= '<a href="survey.php?survey_id='.$survey_id.'">'.get_lang('ClickHere').'</a>';
$return['message'] = 'SurveyCreatedSuccesfully';
$return['type'] = 'confirmation';
$return['id'] = $survey_id;
}
else
{
@ -120,19 +132,72 @@ class survey_manager
lang = '".mysql_real_escape_string($values['survey_language'])."',
avail_from = '".mysql_real_escape_string($values['start_date'])."',
avail_till = '".mysql_real_escape_string($values['end_date'])."',
is_shared = '".mysql_real_escape_string($values['survey_share']['survey_share'])."',
is_shared = '".mysql_real_escape_string($shared_survey_id)."',
template = '".mysql_real_escape_string('template')."',
intro = '".mysql_real_escape_string($values['survey_introduction'])."',
surveythanks = '".mysql_real_escape_string($values['survey_thanks'])."'
WHERE survey_id = '".mysql_real_escape_string($values['survey_id'])."'";
$result = api_sql_query($sql, __FILE__, __LINE__);
$return['message'] = get_lang('SurveyUpdatedSuccesfully').'<br />'.get_lang('YouCanNowAddQuestionToYourSurvey').': ';
$return['message'] .= '<a href="survey.php?survey_id='.$values['survey_id'].'">'.get_lang('Here').'</a>';
$return['message'] .= get_lang('OrReturnToSurveyOverview').'<a href="survey_list.php">'.get_lang('Here').'</a>';
//$return['message'] = get_lang('SurveyUpdatedSuccesfully').'<br />'.get_lang('YouCanNowAddQuestionToYourSurvey').': ';
//$return['message'] .= '<a href="survey.php?survey_id='.$values['survey_id'].'">'.get_lang('Here').'</a>';
//$return['message'] .= get_lang('OrReturnToSurveyOverview').'<a href="survey_list.php">'.get_lang('Here').'</a>';
$return['message'] = 'SurveyUpdatedSuccesfully';
$return['type'] = 'confirmation';
$return['id'] = $values['survey_id'];
}
return $return;
}
/**
* This function stores a shared survey in the central database.
*
* @param array $values
* @return array $return the type of return message that has to be displayed and the message in it
*
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
* @version February 2007
*/
function store_shared_survey($values)
{
global $_user;
global $_course;
// table defnitions
$table_survey = Database :: get_main_table(TABLE_MAIN_SHARED_SURVEY);
if (!$values['survey_id'] OR !is_numeric($values['survey_id']) OR $values['survey_share']['survey_share'] == 'true')
{
$sql = "INSERT INTO $table_survey (code, title, subtitle, author, lang, template, intro, surveythanks, creation_date, course_code) VALUES (
'".mysql_real_escape_string($values['survey_code'])."',
'".mysql_real_escape_string($values['survey_title'])."',
'".mysql_real_escape_string($values['survey_subtitle'])."',
'".mysql_real_escape_string($_user['user_id'])."',
'".mysql_real_escape_string($values['survey_language'])."',
'".mysql_real_escape_string('template')."',
'".mysql_real_escape_string($values['survey_introduction'])."',
'".mysql_real_escape_string($values['survey_thanks'])."',
'".date()."',
'".$_course['id']."')";
$result = api_sql_query($sql, __FILE__, __LINE__);
$return = mysql_insert_id();
}
else
{
$sql = "UPDATE $table_survey SET
code = '".mysql_real_escape_string($values['survey_code'])."',
title = '".mysql_real_escape_string($values['survey_title'])."',
subtitle = '".mysql_real_escape_string($values['survey_subtitle'])."',
author = '".mysql_real_escape_string($_user['user_id'])."',
lang = '".mysql_real_escape_string($values['survey_language'])."',
template = '".mysql_real_escape_string('template')."',
intro = '".mysql_real_escape_string($values['survey_introduction'])."',
surveythanks = '".mysql_real_escape_string($values['survey_thanks'])."'
WHERE survey_id = '".mysql_real_escape_string($values['survey_share']['survey_share'])."'";
$result = api_sql_query($sql, __FILE__, __LINE__);
$return = $values['survey_share']['survey_share'];
}
return $return;
}
@ -145,17 +210,21 @@ class survey_manager
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
* @version January 2007
*/
function delete_survey($survey_id)
function delete_survey($survey_id, $shared=false)
{
// Database table definitions
$table_survey = Database :: get_course_table(TABLE_SURVEY);
$table_survey = Database :: get_course_table(TABLE_SURVEY);
if ($shared)
{
$table_survey = Database :: get_main_table(TABLE_MAIN_SHARED_SURVEY);
}
// deleting the survey
$sql = "DELETE from $table_survey WHERE survey_id='".mysql_real_escape_string($survey_id)."'";
$res = api_sql_query($sql, __FILE__, __LINE__);
// deleting the questions of the survey
survey_manager::delete_all_survey_questions($survey_id);
survey_manager::delete_all_survey_questions($survey_id, $shared);
return true;
}
@ -169,26 +238,91 @@ class survey_manager
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
* @version February 2007
*/
function update_survey_answered($survey_id)
function update_survey_answered($survey_id, $user)
{
global $_course;
// Database table definitions
$table_survey = Database :: get_course_table(TABLE_SURVEY, $_course['db_name']);
$table_survey = Database :: get_course_table(TABLE_SURVEY, $_course['db_name']);
$table_survey_invitation = Database :: get_course_table(TABLE_SURVEY_INVITATION, $_course['db_name']);
// getting a list with all the people who have filled the survey
$people_filled = survey_manager::get_people_who_filled_survey($survey_id);
$number = count($people_filled);
// storing this value
// storing this value in the survey table
$sql = "UPDATE $table_survey SET answered = '".mysql_real_escape_string($number)."' WHERE survey_id = '".mysql_real_escape_string($survey_id)."'";
$res = api_sql_query($sql, __FILE__, __LINE__);
// storing that the user has finished the survey.
$sql = "UPDATE $table_survey_invitation SET answered='1' WHERE user='".mysql_real_escape_string($user)."'";
$res = api_sql_query($sql, __FILE__, __LINE__);
}
/**
* This function gets a complete structure of a survey (all survey information, all question information
* of all the questions and all the options of all the questions.
*
* @param integer $survey_id the id of the survey
* @param boolean $shared this parameter determines if we have to get the information of a survey from the central (shared) database or from the
* course database
*
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
* @version February 2007
*/
function get_complete_survey_structure($survey_id, $shared=0)
{
// Database table definitions
$table_survey = Database :: get_course_table(TABLE_SURVEY);
$table_survey_question = Database :: get_course_table(TABLE_SURVEY_QUESTION);
$table_survey_question_option = Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION);
if ($shared<>0)
{
$table_survey = Database :: get_main_table(TABLE_MAIN_SHARED_SURVEY_QUESTION);
$table_survey_question = Database :: get_course_table(TABLE_SHARED_SURVEY_QUESTION);
$table_survey_question_option = Database :: get_main_table(TABLE_MAIN_SHARED_SURVEY_QUESTION_OPTION);
}
$structure = survey_manager::get_survey($survey_id, $shared);
$structure['questions'] = survey_manager::get_questions($survey_id);
}
/******************************************************************************************************
SURVEY QUESTION FUNCTIONS
*****************************************************************************************************/
/**
* This function return the "icon" of the question type
*
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
* @version February 2007
*/
function icon_question($type)
{
// the possible question types
$possible_types = array('yesno', 'multiplechoice', 'multipleresponse', 'open', 'dropdown', 'comment', 'pagebreak');
// the images array
$icon_question = array(
'yesno' => 'fill_in_blanks.gif',
'multiplechoice' => 'mcua.gif',
'multipleresponse' => 'mcma.gif',
'open' => 'open_answer.gif',
'dropdown' => 'fill_in_blanks.gif',
'comment' => 'fill_in_blanks.gif',
'pagebreak' => 'fill_in_blanks.gif');
if (in_array($type, $possible_types))
{
return $icon_question[$type];
}
else
{
return false;
}
}
/**
* This function retrieves all the information of a question
@ -201,21 +335,27 @@ class survey_manager
*
* @todo one sql call should do the trick
*/
function get_question($question_id)
function get_question($question_id, $shared=false)
{
// table definitions
$tbl_survey_question = Database :: get_course_table(TABLE_SURVEY_QUESTION);
$table_survey_question_option = Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION);
if ($shared)
{
$tbl_survey_question = Database :: get_main_table(TABLE_MAIN_SHARED_SURVEY_QUESTION);
$table_survey_question_option = Database :: get_main_table(TABLE_MAIN_SHARED_SURVEY_QUESTION_OPTION);
}
// getting the information of the question
$sql = "SELECT * FROM $tbl_survey_question WHERE question_id='".mysql_real_escape_string($question_id)."'";
$result = api_sql_query($sql, __FILE__, __LINE__);
$row = mysql_fetch_assoc($result);
$return['survey_id'] = $row['survey_id'];
$return['question_id'] = $row['question_id'];
$return['type'] = $row['type'];
$return['question'] = $row['survey_question'];
$return['survey_id'] = $row['survey_id'];
$return['question_id'] = $row['question_id'];
$return['type'] = $row['type'];
$return['question'] = $row['survey_question'];
$return['horizontalvertical'] = $row['display'];
$return['shared_question_id'] = $row['shared_question_id'];
// getting the information of the question options
$sql = "SELECT * FROM $table_survey_question_option WHERE question_id='".mysql_real_escape_string($question_id)."'";
@ -261,7 +401,7 @@ class survey_manager
}
// getting the information of the question options
$sql = "SELECT * FROM $table_survey_question_option WHERE question_id='".mysql_real_escape_string($question_id)."'";
$sql = "SELECT * FROM $table_survey_question_option WHERE survey_id='".mysql_real_escape_string($survey_id)."'";
$result = api_sql_query($sql, __FILE__, __LINE__);
while ($row = mysql_fetch_assoc($result))
{
@ -274,17 +414,10 @@ class survey_manager
* This function saves a question in the database.
* This can be either an update of an existing survey or storing a new survey
*
* @param integer $question_id the id of the question (used to determine weither it is a update or an insert)
* @param integer $survey_id the id of the survey
* @param string $question_title the question itself
* @param string $question_comment the comment of the question (not yet in use)
* @param string $question_display how the options of the questions should be displayed
* @param array $form_content all the information of the form
*
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
* @version January 2007
*
* @todo move to surveymanager.lib.php
* @todo return message, type and id (and display the information)
*/
function save_question($form_content)
{
@ -294,6 +427,16 @@ class survey_manager
$table_survey = Database :: get_course_table(TABLE_SURVEY, $_course['db_name']);
$tbl_survey_question = Database :: get_course_table(TABLE_SURVEY_QUESTION, $_course['db_name']);
// getting all the information of the survey
$survey_data = survey_manager::get_survey($form_content['survey_id']);
// storing the question in the shared database
if (is_numeric($survey_data['survey_share']) AND $survey_data['survey_share'] <> 0)
{
$shared_question_id = survey_manager::save_shared_question($form_content, $survey_data);
$form_content['shared_question_id'] = $shared_question_id;
}
// storing a new question
if ($form_content['question_id'] == '' OR !is_numeric($form_content['question_id']))
{
@ -304,17 +447,18 @@ class survey_manager
$max_sort = $row['max_sort'];
// adding the question to the survey_question table
$sql = "INSERT INTO $tbl_survey_question (survey_id,survey_question,survey_question_comment,type,display, sort) VALUES (
$sql = "INSERT INTO $tbl_survey_question (survey_id,survey_question,survey_question_comment,type,display, sort, shared_question_id) VALUES (
'".mysql_real_escape_string($form_content['survey_id'])."',
'".mysql_real_escape_string($form_content['question'])."',
'".mysql_real_escape_string($form_content['question_comment'])."',
'".mysql_real_escape_string($form_content['type'])."',
'".mysql_real_escape_string($form_content['horizontalvertical'])."',
'".mysql_real_escape_string($max_sort+1)."')";
'".mysql_real_escape_string($max_sort+1)."',
'".mysql_real_escape_string($form_content['shared_question_id'])."')";
$result = api_sql_query($sql, __FILE__, __LINE__);
$question_id = mysql_insert_id();
$form_content['question_id'] = $question_id;
$return_message = get_lang('QuestionAdded');
$return_message = 'QuestionAdded';
}
// updating an existing question
else
@ -326,14 +470,71 @@ class survey_manager
display = '".mysql_real_escape_string($form_content['horizontalvertical'])."'
WHERE question_id = '".mysql_real_escape_string($form_content['question_id'])."'";
$result = api_sql_query($sql, __FILE__, __LINE__);
$return_message = get_lang('QuestionUpdated');
$return_message = 'QuestionUpdated';
}
// storing the options of the question
survey_manager::save_question_options($form_content);
survey_manager::save_question_options($form_content, $survey_data);
return $return_message;
}
/**
* This function saves the question in the shared database
*
* @param array $form_content all the information of the form
* @param array $survey_data all the information of the survey
*
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
* @version February 2007
*
* @todo editing of a shared question
*/
function save_shared_question($form_content, $survey_data)
{
global $_course;
// table definitions
$tbl_survey_question = Database :: get_main_table(TABLE_MAIN_SHARED_SURVEY_QUESTION);
// storing a new question
if ($form_content['shared_question_id'] == '' OR !is_numeric($form_content['shared_question_id']))
{
// finding the max sort order of the questions in the given survey
$sql = "SELECT max(sort) AS max_sort FROM $tbl_survey_question
WHERE survey_id='".mysql_real_escape_string($survey_data['survey_share'])."'
AND code='".mysql_real_escape_string($_course['id'])."'";
$result = api_sql_query($sql, __FILE__, __LINE__);
$row = mysql_fetch_assoc($result);
$max_sort = $row['max_sort'];
// adding the question to the survey_question table
$sql = "INSERT INTO $tbl_survey_question (survey_id, survey_question, survey_question_comment, type, display, sort, code) VALUES (
'".mysql_real_escape_string($survey_data['survey_share'])."',
'".mysql_real_escape_string($form_content['question'])."',
'".mysql_real_escape_string($form_content['question_comment'])."',
'".mysql_real_escape_string($form_content['type'])."',
'".mysql_real_escape_string($form_content['horizontalvertical'])."',
'".mysql_real_escape_string($max_sort+1)."',
'".mysql_real_escape_string($_course['id'])."')";
$result = api_sql_query($sql, __FILE__, __LINE__);
$shared_question_id = mysql_insert_id();
}
// updating an existing question
else
{
// adding the question to the survey_question table
$sql = "UPDATE $tbl_survey_question SET
survey_question = '".mysql_real_escape_string($form_content['question'])."',
survey_question_comment = '".mysql_real_escape_string($form_content['question_comment'])."',
display = '".mysql_real_escape_string($form_content['horizontalvertical'])."'
WHERE question_id = '".mysql_real_escape_string($form_content['shared_question_id'])."'
AND code='".mysql_real_escape_string($_course['id'])."'";
$result = api_sql_query($sql, __FILE__, __LINE__);
$shared_question_id = $form_content['shared_question_id'];
}
return $shared_question_id;
}
/**
* This functions moves a question of a survey up or down
*
@ -394,23 +595,83 @@ class survey_manager
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
* @version January 2007
*/
function delete_all_survey_questions($survey_id)
function delete_all_survey_questions($survey_id, $shared=false)
{
// table definitions
$table_survey_question = Database :: get_course_table(TABLE_SURVEY_QUESTION);
if ($shared)
{
$table_survey_question = Database :: get_main_table(TABLE_MAIN_SHARED_SURVEY_QUESTION);
}
// deleting the survey questions
$sql = "DELETE from $table_survey_question WHERE survey_id='".mysql_real_escape_string($survey_id)."'";
$res = api_sql_query($sql, __FILE__, __LINE__);
// deleting all the options of the questions of the survey
survey_manager::delete_all_survey_questions_options($survey_id);
survey_manager::delete_all_survey_questions_options($survey_id, $shared);
// deleting all the answers on this survey
survey_manager::delete_all_survey_answers($survey_id);
}
/**
* This function deletes a survey question and all its options
*
* @param integer $survey_id the id of the survey
* @param integer $question_id the id of the question
* @param integer $shared
*
* @todo also delete the answers to this question
*
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
* @version March 2007
*/
function delete_survey_question($survey_id, $question_id, $shared=false)
{
// table definitions
$table_survey_question = Database :: get_course_table(TABLE_SURVEY_QUESTION);
if ($shared)
{
survey_manager::delete_shared_survey_question($survey_id, $question_id);
}
// deleting the survey questions
$sql = "DELETE from $table_survey_question WHERE survey_id='".mysql_real_escape_string($survey_id)."' AND question_id='".mysql_real_escape_string($question_id)."'";
$res = api_sql_query($sql, __FILE__, __LINE__);
// deleting the options of the question of the survey
survey_manager::delete_survey_question_option($survey_id, $question_id, $shared);
}
/**
* This function deletes a shared survey question from the main database and all its options
*
* @param integer $question_id the id of the question
* @param integer $shared
*
* @todo delete all the options of this question
*
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
* @version March 2007
*/
function delete_shared_survey_question($survey_id, $question_id)
{
// table definitions
$table_survey_question = Database :: get_main_table(TABLE_MAIN_SHARED_SURVEY_QUESTION);
// first we have to get the shared_question_id
$question_data = survey_manager::get_question($question_id);
// deleting the survey questions
$sql = "DELETE FROM $table_survey_question WHERE question_id='".mysql_real_escape_string($question_data['shared_question_id'])."'";
$res = api_sql_query($sql, __FILE__, __LINE__);
// deleting the options of the question of the survey
// survey_manager::delete_shared_survey_question_option($survey_id, $question_id, $shared);
}
/******************************************************************************************************
SURVEY QUESTION OPTIONS FUNCTIONS
*****************************************************************************************************/
@ -426,8 +687,13 @@ class survey_manager
*
* @todo writing the update statement when editing a question
*/
function save_question_options($form_content)
function save_question_options($form_content, $survey_data)
{
if (is_numeric($survey_data['survey_share']) AND $survey_data['survey_share'] <> 0)
{
survey_manager::save_shared_question_options($form_content, $survey_data);
}
// table defintion
$table_survey_question_option = Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION);
@ -451,6 +717,46 @@ class survey_manager
}
}
/**
* This function stores the options of the questions in the shared table
*
* @param array $form_content
* @return
*
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
* @version February 2007
*
* @todo writing the update statement when editing a question
*/
function save_shared_question_options($form_content, $survey_data)
{
// table defintion
$table_survey_question_option = Database :: get_main_table(TABLE_MAIN_SHARED_SURVEY_QUESTION_OPTION);
// we are editing a question so we first have to remove all the existing options from the database
$sql = "DELETE FROM $table_survey_question_option WHERE question_id = '".mysql_real_escape_string($form_content['shared_question_id'])."'";
$result = api_sql_query($sql, __FILE__, __LINE__);
$counter = 1;
foreach ($form_content['answers'] as $key=>$answer)
{
$sql = "INSERT INTO $table_survey_question_option (question_id, survey_id, option_text, sort) VALUES (
'".mysql_real_escape_string($form_content['shared_question_id'])."',
'".mysql_real_escape_string($survey_data['is_shared'])."',
'".mysql_real_escape_string($answer)."',
'".mysql_real_escape_string($counter)."')";
$result = api_sql_query($sql, __FILE__, __LINE__);
$counter++;
}
}
/*
if (is_numeric($survey_data['survey_share']) AND $survey_data['survey_share'] <> 0)
{
$form_content = survey_manager::save_shared_question($form_content, $survey_data);
}
*/
/**
* This function deletes all the options of the questions of a given survey
@ -462,10 +768,14 @@ class survey_manager
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
* @version January 2007
*/
function delete_all_survey_questions_options($survey_id)
function delete_all_survey_questions_options($survey_id, $shared=false)
{
// table definitions
$table_survey_question_option = Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION);
if ($shared)
{
$table_survey_question = Database :: get_main_table(TABLE_MAIN_SHARED_SURVEY_QUESTION_OPTION);
}
// deleting the options of the survey questions
$sql = "DELETE from $table_survey_question_option WHERE survey_id='".mysql_real_escape_string($survey_id)."'";
@ -474,6 +784,33 @@ class survey_manager
}
/**
* This function deletes the options of a given question
*
* @param unknown_type $survey_id
* @param unknown_type $question_id
* @param unknown_type $shared
* @return unknown
*
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
* @version March 2007
*/
function delete_survey_question_option($survey_id, $question_id, $shared=false)
{
// table definitions
$table_survey_question_option = Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION);
if ($shared)
{
$table_survey_question = Database :: get_main_table(TABLE_MAIN_SHARED_SURVEY_QUESTION_OPTION);
}
// deleting the options of the survey questions
$sql = "DELETE from $table_survey_question_option WHERE survey_id='".mysql_real_escape_string($survey_id)."' AND question_id='".mysql_real_escape_string($question_id)."'";
$res = api_sql_query($sql, __FILE__, __LINE__);
return true;
}
/******************************************************************************************************
SURVEY ANSWERS FUNCTIONS
@ -486,6 +823,8 @@ class survey_manager
* @param $survey_id the id of the survey that has to be deleted
* @return true
*
* @todo write the function
*
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
* @version January 2007
*/
@ -556,18 +895,23 @@ class question
*/
function create_form($form_content)
{
global $fck_attribute;
$this->html = '<form id="question_form" name="question_form" method="post" action="'.$_SERVER['PHP_SELF'].'?action='.$_GET['action'].'&type='.$_GET['type'].'&survey_id='.$_GET['survey_id'].'&question_id='.$_GET['question_id'].'">';
$this->html .= ' <input type="hidden" name="survey_id" id="survey_id" value="'.$_GET['survey_id'].'"/>';
$this->html .= ' <input type="hidden" name="question_id" id="question_id" value="'.$_GET['question_id'].'"/>';
$this->html .= ' <input type="hidden" name="shared_question_id" id="shared_question_id" value="'.$form_content['shared_question_id'].'"/>';
$this->html .= ' <input type="hidden" name="type" id="type" value="'.$_GET['type'].'"/>';
$this->html .= '<table>';
$this->html .= ' <tr>';
$this->html .= ' <td colspan="3"><strong>'.get_lang('Question').'</strong></td>';
$this->html .= ' </tr>';
$this->html .= ' <tr>';
$this->html .= ' <td><label for="question">'.get_lang('Question').'</label></td>';
$this->html .= ' <td><input type="text" name="question" id="question" value="'.$form_content['question'].'"/></td>';
$this->html .= ' <td>&nbsp;</td>';
//$this->html .= ' <td><label for="question">'.get_lang('Question').'</label></td>';
$fck_attribute['Width'] = '100%';
$fck_attribute['Height'] = '100';
$fck_attribute['ToolbarSet'] = 'Survey';
//$this->html .= ' <td><input type="text" name="question" id="question" value="'.$form_content['question'].'"/></td>';
$this->html .= ' <td colspan="3" width="500">'.api_return_html_area('question', $form_content['question']).'</td>';
$this->html .= ' </tr>';
/*
$this->html .= ' <tr>';
@ -576,6 +920,10 @@ class question
$this->html .= ' <td>&nbsp;</td>';
$this->html .= ' </tr>';
*/
$this->html .=' <tr>
<td colspan="">&nbsp</td>
</tr>';
return $this->html;
}
@ -609,6 +957,8 @@ class question
*/
function handle_action($form_content)
{
global $config;
// moving an answer up
if ($_POST['move_up'])
{
@ -654,7 +1004,15 @@ class question
if ($_POST['save_question'])
{
$message = survey_manager::save_question($form_content);
Display :: display_confirmation_message($message.'<br />'.get_lang('ReturnTo').' <a href="survey.php?survey_id='.$_GET['survey_id'].'">'.get_lang('Survey').'</a>',false);
if ($config['survey']['debug'])
{
Display :: display_header();
Display :: display_confirmation_message($message.'<br />'.get_lang('ReturnTo').' <a href="survey.php?survey_id='.$_GET['survey_id'].'">'.get_lang('Survey').'</a>', false);
}
else
{
header('location:survey.php?survey_id='.$_GET['survey_id'].'&message='.$message);
}
}
/**
@ -754,18 +1112,24 @@ class yesno extends question
$this->html .= ' </td>';
$this->html .= ' <td>&nbsp;</td>';
$this->html .= ' </tr>';
// The answers
$this->html .=' <tr>
<td colspan="">&nbsp</td>
</tr>';
// The options
$this->html .= ' <tr>';
$this->html .= ' <td colspan="3"><strong>'.get_lang('AnswerOptions').'</strong></td>';
$this->html .= ' </tr>';
$this->html .= ' <tr>';
$this->html .= ' <td align="right"><label for="answers[0]">1</label></td>';
$this->html .= ' <td><input type="text" name="answers[0]" id="answers[0]" value="'.$form_content['answers'][0].'" /></td>';
//$this->html .= ' <td><input type="text" name="answers[0]" id="answers[0]" value="'.$form_content['answers'][0].'" /></td>';
$this->html .= ' <td>'.api_return_html_area('answers[0]', $form_content['answers'][0]).'</td>';
$this->html .= ' <td><input type="image" src="../img/down.gif" value="move_down[0]" name="move_down[0]"/></td>';
$this->html .= ' </tr>';
$this->html .= ' <tr>';
$this->html .= ' <td align="right"><label for="answers[1]">2</label></td>';
$this->html .= ' <td><input type="text" name="answers[1]" id="answers[1]" value="'.$form_content['answers'][1].'" /></td>';
//$this->html .= ' <td><input type="text" name="answers[1]" id="answers[1]" value="'.$form_content['answers'][1].'" /></td>';
$this->html .= ' <td>'.api_return_html_area('answers[1]', $form_content['answers'][1]).'</td>';
$this->html .= ' <td><input type="image" src="../img/up.gif" value="move_up[1]" name="move_up[1]" /></td>';
$this->html .= ' </tr>';
}
@ -798,6 +1162,7 @@ class yesno extends question
echo '<div class="survey_question_options">';
echo $this->html;
echo '</div>';
echo '</div>';
}
}
@ -834,7 +1199,11 @@ class multiplechoice extends question
$this->html .= ' />'.get_lang('Vertical').'</label>'; $this->html .= ' </td>';
$this->html .= ' <td>&nbsp;</td>';
$this->html .= ' </tr>';
// The answers
$this->html .=' <tr>
<td colspan="">&nbsp</td>
</tr>';
// The Options
$this->html .= ' <tr>';
$this->html .= ' <td colspan="3"><strong>'.get_lang('AnswerOptions').'</strong></td>';
$this->html .= ' </tr>';
@ -843,16 +1212,25 @@ class multiplechoice extends question
{
$this->html .= ' <tr>';
$this->html .= ' <td align="right"><label for="answers['.$key.']">'.($key+1).'</label></td>';
$this->html .= ' <td><input type="text" name="answers['.$key.']" id="answers['.$key.']" value="'.$form_content['answers'][$key].'" /></td>';
//$this->html .= ' <td><input type="text" name="answers['.$key.']" id="answers['.$key.']" value="'.$form_content['answers'][$key].'" /></td>';
$this->html .= ' <td width="500">'.api_return_html_area('answers['.$key.']', $form_content['answers'][$key]).'</td>';
$this->html .= ' <td>';
if ($key<$total_number_of_answers-1)
{
$this->html .= ' <input type="image" src="../img/down.gif" value="move_down['.$key.']" name="move_down['.$key.']"/>';
}
else
{
$this->html .= ' <img src="../img/spacer.gif" alt="'.get_lang('Empty').'" title="'.get_lang('Empty').'" />';
}
if ($key>0)
{
$this->html .= ' <input type="image" src="../img/up.gif" value="move_up['.$key.']" name="move_up['.$key.']"/>';
}
else
{
$this->html .= ' <img src="../img/spacer.gif" alt="'.get_lang('Empty').'" title="'.get_lang('Empty').'" />';
}
if ($total_number_of_answers> 2)
{
$this->html .= ' <input type="image" src="../img/delete.gif" value="delete_answer['.$key.']" name="delete_answer['.$key.']"/>';
@ -915,7 +1293,12 @@ class multipleresponse extends question
$this->html .= ' />'.get_lang('Vertical').'</label>'; $this->html .= ' </td>';
$this->html .= ' <td>&nbsp;</td>';
$this->html .= ' </tr>';
// The answers
$this->html .=' <tr>
<td colspan="">&nbsp</td>
</tr>';
// The options
$this->html .= ' <tr>';
$this->html .= ' <td colspan="3"><strong>'.get_lang('AnswerOptions').'</strong></td>';
$this->html .= ' </tr>';
@ -924,16 +1307,25 @@ class multipleresponse extends question
{
$this->html .= ' <tr>';
$this->html .= ' <td align="right"><label for="answers['.$key.']">'.($key+1).'</label></td>';
$this->html .= ' <td><input type="text" name="answers['.$key.']" id="answers['.$key.']" value="'.$form_content['answers'][$key].'" /></td>';
//$this->html .= ' <td><input type="text" name="answers['.$key.']" id="answers['.$key.']" value="'.$form_content['answers'][$key].'" /></td>';
$this->html .= ' <td width="500">'.api_return_html_area('answers['.$key.']', $form_content['answers'][$key]).'</td>';
$this->html .= ' <td>';
if ($key<$total_number_of_answers-1)
{
$this->html .= ' <input type="image" src="../img/down.gif" value="move_down['.$key.']" name="move_down['.$key.']"/>';
}
else
{
$this->html .= ' <img src="../img/spacer.gif" alt="'.get_lang('Empty').'" title="'.get_lang('Empty').'" />';
}
if ($key>0)
{
$this->html .= ' <input type="image" src="../img/up.gif" value="move_up['.$key.']" name="move_up['.$key.']"/>';
}
else
{
$this->html .= ' <img src="../img/spacer.gif" alt="'.get_lang('Empty').'" title="'.get_lang('Empty').'" />';
}
if ($total_number_of_answers> 2)
{
$this->html .= ' <input type="image" src="../img/delete.gif" value="delete_answer['.$key.']" name="delete_answer['.$key.']"/>';
@ -955,7 +1347,6 @@ class multipleresponse extends question
*/
function render_question($form_content, $answers=array())
{
//print_r($form_content);
foreach ($form_content['options'] as $key=>$value)
{
$this->html .= '<label><input name="question'.$form_content['question_id'].'[]" type="checkbox" value="'.$key.'"';
@ -1118,6 +1509,8 @@ class comment extends question
{
echo '<div class="survey_question_wrapper">';
echo '<div class="survey_question">'.$form_content['survey_question'].'</div>';
echo '</div>';
echo "\n";
}
}

@ -1,30 +1,28 @@
<?php
/*
DOKEOS - elearning and course management software
DOKEOS - elearning and course management software
For a full list of contributors, see documentation/credits.html
For a full list of contributors, see documentation/credits.html
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
See "documentation/licence.html" more details.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
See "documentation/licence.html" more details.
Contact:
Dokeos
Rue des Palais 44 Paleizenstraat
B-1030 Brussels - Belgium
Tel. +32 (2) 211 34 56
Contact:
Dokeos
Rue des Palais 44 Paleizenstraat
B-1030 Brussels - Belgium
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 11350 2007-03-02 16:02:46Z elixir_julian $
* @version $Id: survey.php 11451 2007-03-06 21:54:30Z pcool $
*
* @todo The ansTarget column is not done
* @todo try to understand the white, blue, ... template stuff.
* @todo use quickforms for the forms
*/
@ -43,7 +41,7 @@ require_once (api_get_path(LIBRARY_PATH)."/course.lib.php");
if (!api_is_allowed_to_edit())
{
Display :: display_header();
Display :: display_error_message(get_lang('NotAllowedHere'));
Display :: display_error_message(get_lang('NotAllowedHere'), false);
Display :: display_footer();
exit;
}
@ -58,7 +56,14 @@ $user_info = Database :: get_main_table(TABLE_MAIN_SURVEY_REMINDER);
// breadcrumbs
$interbreadcrumb[] = array ("url" => "survey_list.php", "name" => get_lang('SurveyList'));
$tool_name = get_lang('Survey');
// getting the survey information
$survey_data = survey_manager::get_survey($_GET['survey_id']);
$tool_name = substr(strip_tags($survey_data['title']), 0, 40);
if (strlen(strip_tags($survey_data['title'])) > 40)
{
$tool_name .= '...';
}
// Displaying the header
Display::display_header($tool_name);
@ -69,33 +74,49 @@ if (isset($_GET['action']))
if (($_GET['action'] == 'moveup' OR $_GET['action'] == 'movedown') AND isset($_GET['question_id']))
{
survey_manager::move_survey_question($_GET['action'], $_GET['question_id'], $_GET['survey_id']);
Display::display_confirmation_message('SurveyQuestionMoved');
Display::display_confirmation_message('SurveyQuestionMoved', false);
}
if ($_GET['action'] == 'delete' AND is_numeric($_GET['question_id']))
{
survey_manager::delete_survey_question($_GET['survey_id'], $_GET['question_id'], $survey_data['is_shared']);
}
}
// Displaying the survey information
$survey_data = survey_manager::get_survey($_GET['survey_id']);
echo '<strong>'.$survey_data['title'].'</strong><br />';
echo $survey_data['subtitle'].'<br />';
if (isset($_GET['message']))
{
// we have created the survey or updated the survey
if (in_array($_GET['message'], array('SurveyUpdatedSuccesfully','SurveyCreatedSuccesfully')))
{
Display::display_confirmation_message(get_lang($_GET['message']).'<br />'.get_lang('YouCanNowAddQuestionToYourSurvey'), false);
}
// we have added a question
if (in_array($_GET['message'], array('QuestionAdded','QuestionUpdated')))
{
Display::display_confirmation_message(get_lang($_GET['message']), false);
}
}
// Action links
$survey_actions = '<a href="create_new_survey.php?action=edit&amp;survey_id='.$_GET['survey_id'].'">'.Display::return_icon('edit.gif').'</a>';
$survey_actions .= '<a href="survey_list.php?action=delete&amp;survey_id='.$_GET['survey_id'].'">'.Display::return_icon('delete.gif').'</a>';
$survey_actions .= '<a href="create_survey_in_another_language.php?id_survey='.$_GET['survey_id'].'">'.Display::return_icon('copy.gif').'</a>';
$survey_actions .= '<a href="preview.php?survey_id='.$_GET['survey_id'].'">'.Display::return_icon('preview.gif').'</a>';
$survey_actions .= '<a href="survey_invite.php?survey_id='.$_GET['survey_id'].'">'.Display::return_icon('survey_publish.gif').'</a>';
$survey_actions .= '<a href="reporting.php?survey_id='.$_GET['survey_id'].'">'.Display::return_icon('statistics.gif').'</a>';
$survey_actions = get_lang('Survey').': ';
$survey_actions .= '<a href="create_new_survey.php?action=edit&amp;survey_id='.$_GET['survey_id'].'">'.Display::return_icon('edit.gif', get_lang('Edit')).'</a>';
$survey_actions .= '<a href="survey_list.php?action=delete&amp;survey_id='.$_GET['survey_id'].'" onclick="javascript:if(!confirm(\''.addslashes(htmlentities(get_lang("DeleteSurvey").'?')).'\')) return false;">'.Display::return_icon('delete.gif', get_lang('Delete')).'</a>';
//$survey_actions .= '<a href="create_survey_in_another_language.php?id_survey='.$_GET['survey_id'].'">'.Display::return_icon('copy.gif', get_lang('Copy')).'</a>';
$survey_actions .= '<a href="preview.php?survey_id='.$_GET['survey_id'].'">'.Display::return_icon('preview.gif', get_lang('Preview')).'</a>';
$survey_actions .= '<a href="survey_invite.php?survey_id='.$_GET['survey_id'].'">'.Display::return_icon('survey_publish.gif', get_lang('Publish')).'</a>';
$survey_actions .= '<a href="reporting.php?survey_id='.$_GET['survey_id'].'">'.Display::return_icon('surveyreporting.gif', get_lang('Reporting')).'</a>';
echo '<div style="float:right;">'.$survey_actions.'</div>';
echo '<a href="question.php?action=add&type=yesno&amp;survey_id='.$_GET['survey_id'].'">'.get_lang('YesNo').'</a> | ';
echo '<a href="question.php?action=add&type=multiplechoice&amp;survey_id='.$_GET['survey_id'].'">'.get_lang('MultipleChoice').'</a> | ';
echo '<a href="question.php?action=add&type=multipleresponse&amp;survey_id='.$_GET['survey_id'].'">'.get_lang('MultipleResponse').'</a> | ';
echo '<a href="question.php?action=add&type=open&amp;survey_id='.$_GET['survey_id'].'">'.get_lang('Open').'</a> | ';
echo '<a href="question.php?action=add&type=dropdown&amp;survey_id='.$_GET['survey_id'].'">'.get_lang('Dropdown').'</a> | ';
//echo '<a href="question.php?action=add&type=percentage&amp;survey_id='.$_GET['survey_id'].'">'.get_lang('Dropdown').'</a> | ';
//echo '<a href="question.php?action=add&type=rating&amp;survey_id='.$_GET['survey_id'].'">'.get_lang('Dropdown').'</a> | ';
echo '<a href="question.php?action=add&type=comment&amp;survey_id='.$_GET['survey_id'].'">'.get_lang('Comment').'</a> | ';
echo '<a href="question.php?action=add&type=pagebreak&amp;survey_id='.$_GET['survey_id'].'">'.get_lang('Pagebreak').'</a>';
echo '<div>';
echo '<div style="float:left; text-align:center; margin:5px;"><a href="question.php?action=add&type=yesno&amp;survey_id='.$_GET['survey_id'].'"><img src="../img/yesno.gif" /><br />'.get_lang('YesNo').'</a></div>';
echo '<div style="float:left; text-align:center; margin:5px;"><a href="question.php?action=add&type=multiplechoice&amp;survey_id='.$_GET['survey_id'].'"><img src="../img/mcua.gif" /><br />'.get_lang('MultipleChoice').'</a></div>';
echo '<div style="float:left; text-align:center; margin:5px;"><a href="question.php?action=add&type=multipleresponse&amp;survey_id='.$_GET['survey_id'].'"><img src="../img/mcma.gif" /><br />'.get_lang('MultipleResponse').'</a></div>';
echo '<div style="float:left; text-align:center; margin:5px;"><a href="question.php?action=add&type=open&amp;survey_id='.$_GET['survey_id'].'"><img src="../img/open_answer.gif" /><br />'.get_lang('Open').'</a></div>';
echo '<div style="float:left; text-align:center; margin:5px;"><a href="question.php?action=add&type=dropdown&amp;survey_id='.$_GET['survey_id'].'"><img src="../img/dropdown.gif" /><br />'.get_lang('Dropdown').'</a></div>';
//echo '<div style="float:left"><a href="question.php?action=add&type=percentage&amp;survey_id='.$_GET['survey_id'].'"><img src="../img/fill_in_blanks.gif" /><br />'.get_lang('Dropdown').'</a></div>';
//echo '<div style="float:left"><a href="question.php?action=add&type=rating&amp;survey_id='.$_GET['survey_id'].'"><img src="../img/fill_in_blanks.gif" /><br />'.get_lang('Dropdown').'</a></div>';
echo '<div style="float:left; text-align:center; margin:5px;"><a href="question.php?action=add&type=comment&amp;survey_id='.$_GET['survey_id'].'"><img src="../img/commentquestion.gif" /><br />'.get_lang('Comment').'</a></div>';
echo '<div style="float:left; text-align:center; margin:5px;"><a href="question.php?action=add&type=pagebreak&amp;survey_id='.$_GET['survey_id'].'"><img src="../img/page_end.gif" /><br />'.get_lang('Pagebreak').'</a></div>';
echo '</div>';
echo '<div style="clear:both;"></div>';
// Displaying the table header with all the questions
@ -123,25 +144,24 @@ while ($row = mysql_fetch_assoc($result))
echo '<tr>';
echo ' <td>'.$question_counter.'</td>';
echo ' <td>'.$row['survey_question'].'</td>';
echo ' <td>'.$row['type'].'</td>';
echo ' <td>'.get_lang(ucfirst($row['type'])).'</td>';
echo ' <td>'.$row['number_of_options'].'</td>';
echo ' <td>';
echo ' <a href="question.php?action=edit&amp;type='.$row['type'].'&amp;survey_id='.$_GET['survey_id'].'&amp;question_id='.$row['question_id'].'">'.Display::return_icon('edit.gif').'</a>';
echo ' <a href="survey.php?action=delete&amp;survey_id='.$_GET['survey_id'].'&ampquestion_id='.$row['question_id'].'">'.Display::return_icon('delete.gif').'</a>';
echo ' <a href="question.php?action=edit&amp;type='.$row['type'].'&amp;survey_id='.$_GET['survey_id'].'&amp;question_id='.$row['question_id'].'">'.Display::return_icon('edit.gif', get_lang('Edit')).'</a>';
echo ' <a href="survey.php?action=delete&amp;survey_id='.$_GET['survey_id'].'&amp;question_id='.$row['question_id'].'" onclick="javascript:if(!confirm(\''.addslashes(htmlentities(get_lang("DeleteSurveyQuestion").'?')).'\')) return false;">'.Display::return_icon('delete.gif', get_lang('Delete')).'</a>';
if ($question_counter > 1)
{
echo ' <a href="survey.php?action=moveup&amp;survey_id='.$_GET['survey_id'].'&amp;question_id='.$row['question_id'].'">'.Display::return_icon('up.gif').'</a>';
echo ' <a href="survey.php?action=moveup&amp;survey_id='.$_GET['survey_id'].'&amp;question_id='.$row['question_id'].'">'.Display::return_icon('up.gif', get_lang('MoveUp')).'</a>';
}
if ($question_counter < $question_counter_max)
{
echo ' <a href="survey.php?action=movedown&amp;survey_id='.$_GET['survey_id'].'&amp;question_id='.$row['question_id'].'">'.Display::return_icon('down.gif').'</a>';
echo ' <a href="survey.php?action=movedown&amp;survey_id='.$_GET['survey_id'].'&amp;question_id='.$row['question_id'].'">'.Display::return_icon('down.gif', get_lang('MoveDown')).'</a>';
}
echo ' </td>';
$question_counter++;
}
echo '</table>';
// Footer
Display :: display_footer();
?>

@ -42,7 +42,7 @@ require_once (api_get_path(LIBRARY_PATH)."mail.lib.inc.php");
if (!api_is_allowed_to_edit())
{
Display :: display_header();
Display :: display_error_message(get_lang('NotAllowedHere'));
Display :: display_error_message(get_lang('NotAllowedHere'), false);
Display :: display_footer();
exit;
}
@ -55,9 +55,18 @@ $table_course = Database :: get_main_table(TABLE_MAIN_COURSE);
$table_user = Database :: get_main_table(TABLE_MAIN_USER);
$table_survey_invitation = Database :: get_course_table(TABLE_SURVEY_INVITATION);
// getting the survey information
$survey_data = survey_manager::get_survey($_GET['survey_id']);
$urlname = substr(strip_tags($survey_data['title']), 0, 40);
if (strlen(strip_tags($survey_data['title'])) > 40)
{
$urlname .= '...';
}
// breadcrumbs
$interbreadcrumb[] = array ('url' => 'survey_list.php', 'name' => get_lang('SurveyList'));
$interbreadcrumb[] = array ('url' => 'survey.php?survey_id='.$_GET['survey_id'], 'name' => get_lang('Survey'));
$interbreadcrumb[] = array ('url' => 'survey.php?survey_id='.$_GET['survey_id'], 'name' => $urlname);
$tool_name = get_lang('SurveyInvitations');
// Displaying the header
@ -66,22 +75,20 @@ Display::display_header($tool_name);
// Checking the parameters
if (!is_numeric($_GET['survey_id']))
{
Display::display_error_message(get_lang('Error'));
Display::display_error_message(get_lang('Error'), false);
Display::display_footer();
exit;
}
// Displaying the survey information
$survey_data = survey_manager::get_survey($_GET['survey_id']);
echo '<a href="survey.php?survey_id='.$survey_data['survey_id'].'">'.$survey_data['title'].'</a><br />';
echo $survey_data['subtitle'];
// Getting all the people who have filled this survey
$answered_data = survey_manager::get_people_who_filled_survey($_GET['survey_id']);
//
echo 'view invited | view answered | view unanswered';
echo ' <a href="'.$_SERVER['PHP_SELF'].'?survey_id='.(int)$_GET['survey_id'].'&amp;view=invited">'.get_lang('ViewInvited').'</a> |
<a href="'.$_SERVER['PHP_SELF'].'?survey_id='.(int)$_GET['survey_id'].'&amp;view=answered">'.get_lang('ViewAnswered').'</a> |
<a href="'.$_SERVER['PHP_SELF'].'?survey_id='.(int)$_GET['survey_id'].'&amp;view=unanswered">'.get_lang('ViewUnanswered').'</a> |
';
// table header
echo '<table class="data_table">';
@ -94,35 +101,37 @@ echo ' </tr>';
$sql = "SELECT survey_invitation.*, user.firstname, user.lastname, user.email FROM $table_survey_invitation survey_invitation
LEFT JOIN $table_user user ON survey_invitation.user = user.user_id
WHERE survey_invitation.survey_id = '".mysql_real_escape_string($_GET['survey_id'])."'";
WHERE survey_invitation.survey_code = '".mysql_real_escape_string($survey_data['code'])."'";
$res = api_sql_query($sql, __FILE__, __LINE__);
while ($row = mysql_fetch_assoc($res))
{
echo '<tr>';
if (is_numeric($row['user']))
if (!$_GET['view'] OR $_GET['view'] == 'invited' OR ($_GET['view'] == 'answered' AND in_array($row['user'], $answered_data)) OR ($_GET['view'] == 'unanswered' AND !in_array($row['user'], $answered_data)))
{
echo ' <td><a href="../user/userInfo.php?editMainUserInfo='.$row['user'].'">'.$row['firstname'].' '.$row['lastname'].'</a></td>';
echo '<tr>';
if (is_numeric($row['user']))
{
echo ' <td><a href="../user/userInfo.php?editMainUserInfo='.$row['user'].'">'.$row['firstname'].' '.$row['lastname'].'</a></td>';
}
else
{
echo ' <td>'.$row['user'].'</td>';
}
/** @todo this is temporary to allow the developer to quickly fill a survey as a different user */
// echo ' <td>'.$row['invitation_code'].'</td>';
echo ' <td><a href="fillsurvey.php?course='.$_course['sysCode'].'&amp;invitationcode='.$row['invitation_code'].'">'.$row['invitation_code'].'</td>';
echo ' <td>'.$row['invitation_date'].'</td>';
echo ' <td>';
if (in_array($row['user'], $answered_data))
{
echo '<a href="reporting.php?action=userreport&amp;survey_id='.$_GET['survey_id'].'&amp;user='.$row['user'].'">'.get_lang('ViewAnswers').'</a>';
}
else
{
echo '-';
}
echo ' </td>';
echo '</tr>';
}
else
{
echo ' <td>'.$row['user'].'</td>';
}
/** @todo this is temporary to allow the developer to quickly fill a survey as a different user */
// echo ' <td>'.$row['invitation_code'].'</td>';
echo ' <td><a href="fillsurvey.php?course='.$_course['sysCode'].'&amp;invitationcode='.$row['invitation_code'].'">'.$row['invitation_code'].'</td>';
echo ' <td>'.$row['invitation_date'].'</td>';
echo ' <td>';
if (in_array($row['user'], $answered_data))
{
echo '<a href="reporting.php?action=userreport&amp;survey_id='.$_GET['survey_id'].'&amp;user='.$row['user'].'">'.get_lang('ViewAnswers').'</a>';
}
else
{
echo '-';
}
echo ' </td>';
echo '</tr>';
}
// closing the table
echo '</table>';

@ -34,10 +34,6 @@ $language_file = 'survey';
// including the global dokeos file
require ('../inc/global.inc.php');
$fck_attribute['Width'] = '100%';
$fck_attribute['Height'] = '200';
$fck_attribute['ToolbarSet'] = 'Survey';
// including additional libraries
//require_once (api_get_path(LIBRARY_PATH)."/survey.lib.php");
require_once('survey.lib.php');
@ -49,7 +45,7 @@ require_once (api_get_path(LIBRARY_PATH)."mail.lib.inc.php");
if (!api_is_allowed_to_edit())
{
Display :: display_header();
Display :: display_error_message(get_lang('NotAllowedHere'));
Display :: display_error_message(get_lang('NotAllowedHere'), false);
Display :: display_footer();
exit;
}
@ -62,18 +58,30 @@ $table_course = Database :: get_main_table(TABLE_MAIN_COURSE);
$table_user = Database :: get_main_table(TABLE_MAIN_USER);
$user_info = Database :: get_main_table(TABLE_MAIN_SURVEY_REMINDER);
// getting the survey information
$survey_data = survey_manager::get_survey($_GET['survey_id']);
$urlname = substr(strip_tags($survey_data['title']), 0, 40);
if (strlen(strip_tags($survey_data['title'])) > 40)
{
$urlname .= '...';
}
// breadcrumbs
$interbreadcrumb[] = array ('url' => 'survey_list.php', 'name' => get_lang('SurveyList'));
$interbreadcrumb[] = array ('url' => 'survey.php?survey_id='.$_GET['survey_id'], 'name' => get_lang('Survey'));
$interbreadcrumb[] = array ('url' => 'survey.php?survey_id='.$_GET['survey_id'], 'name' => $urlname);
$tool_name = get_lang('SurveyPublication');
// Displaying the header
Display::display_header($tool_name);
// Displaying the survey information
$survey_data = survey_manager::get_survey($_GET['survey_id']);
echo '<a href="survey.php?survey_id='.$survey_data['survey_id'].'">'.$survey_data['title'].'</a><br />';
echo $survey_data['subtitle'];
// checking if there is another survey with this code.
// If this is the case there will be a language choice
$sql = "SELECT * FROM $table_survey WHERE code='".mysql_real_escape_string($survey_data['code'])."'";
$result = api_sql_query($sql, __FILE__, __LINE__);
if (mysql_num_rows($result) > 1)
{
Display::display_warning_message(get_lang('IdenticalSurveycodeWarning'));
}
// building the form for publishing the survey
$form = new FormValidator('publish_form','post', $_SERVER['PHP_SELF'].'?survey_id='.$_GET['survey_id']);
@ -84,10 +92,10 @@ foreach ($complete_user_list as $index => $user)
{
$possible_users[$user['user_id']] = $user['lastname'].' '.$user['firstname'];
}
$users = $form->addElement('advmultiselect', 'course_users', get_lang('CourseUsers'), $possible_users, 'style="width: 220px;"');
$users = $form->addElement('advmultiselect', 'course_users', get_lang('CourseUsers'), $possible_users);
$users->setElementTemplate('
{javascript}
<table{class} width="500">
<table{class}>
<!-- BEGIN label_2 --><tr><th>{label_2}</th><!-- END label_2 -->
<!-- BEGIN label_3 --><th>&nbsp;</th><th>{label_3}</th></tr><!-- END label_3 -->
<tr>
@ -98,38 +106,55 @@ $users->setElementTemplate('
</table>
');
// additional users
$form->addElement('textarea', 'additional_users', get_lang('AdditonalUsers'), array ('cols' => 100, 'rows' => 2));
$form->addElement('textarea', 'additional_users', get_lang('AdditonalUsers'), array ('cols' => 50, 'rows' => 2));
// additional users comment
$form->addElement('static', null, null, get_lang('AdditonalUsersComment'));
// the title of the mail
$form->addElement('text', 'mail_title', get_lang('MailTitle'), 'style="width: 350px"');
$form->addElement('text', 'mail_title', get_lang('MailTitle'),array('size' => '80'));
// the text of the mail
$fck_attribute['Width'] = '100%';
$fck_attribute['Height'] = '150';
$fck_attribute['ToolbarSet'] = 'Survey';
$form->addElement('html_editor', 'mail_text', get_lang('MailText'));
// some explanation of the mail
$form->addElement('static', null, null, get_lang('UseLinkSyntax'));
// allow resending to all selected users
$form->addElement('checkbox', 'resend_to_all', '', get_lang('ReminderResendToAllUsers'));
// submit button
$form->addElement('submit', 'submit', get_lang('Ok'));
// The rules (required fields)
$form->addRule('mail_title', get_lang('ThisFieldIsRequired'), 'required');
$form->addRule('mail_text', get_lang('ThisFieldIsRequired'), 'required');
if ($form->validate())
{
$values = $form->exportValues();
// save the invitation mail
save_invite_mail($values['mail_text']);
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']);
$count_course_users = 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
$additional_users = explode(';',$temp);
$counter_additional_users = save_invitations($additional_users, $values['mail_title'], $values['mail_text']);
$counter_additional_users = 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($_GET['survey_id']);
update_count_invited($survey_data['code']);
$total_count = $count_course_users + $counter_additional_users;
Display :: display_confirmation_message($total_count.' '.get_lang('InvitationsSend'));
Display :: display_confirmation_message($total_count.' '.get_lang('InvitationsSend'), false);
}
else
{
$defaults = get_invitations($_GET['survey_id']);
$defaults = get_invitations($survey_data['code']);
if (!empty($survey_data['reminder_mail']))
{
$defaults['mail_text'] = $survey_data['reminder_mail'];
}
else
{
$defaults['mail_text'] = $survey_data['invite_mail'];
}
$form->setDefaults($defaults);
$form->display();
}
@ -146,12 +171,22 @@ Display :: display_footer();
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
* @version January 2007
*/
function save_invite_mail($mailtext)
function save_invite_mail($mailtext, $reminder=0)
{
// Database table definition
$table_survey = Database :: get_course_table(TABLE_SURVEY);
$sql = "UPDATE $table_survey SET invite_mail = '".mysql_real_escape_string($mailtext)."' WHERE survey_id = '".$_GET['survey_id']."'";
// reminder or not
if ($reminder == 0)
{
$mail_field = 'invite_mail';
}
else
{
$mail_field = 'reminder_mail';
}
$sql = "UPDATE $table_survey SET $mail_field = '".mysql_real_escape_string($mailtext)."' WHERE survey_id = '".$_GET['survey_id']."'";
$result = api_sql_query($sql, __FILE__, __LINE__);
}
@ -168,18 +203,28 @@ function save_invite_mail($mailtext)
*
* @todo create the survey link
*/
function save_invitations($users_array, $invitation_title, $invitation_text)
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);
// get the people who are already invited
$already_invited = get_invitations($_GET['survey_id']);
if ($reminder == 1)
{
$already_invited = array();
}
else
{
$already_invited = get_invitations($survey_data['code']);
}
$counter = 0;
if (is_array($users_array))
@ -192,9 +237,8 @@ function save_invitations($users_array, $invitation_title, $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_id, invitation_code, invitation_date) VALUES
('".mysql_real_escape_string($value)."','".mysql_real_escape_string($_GET['survey_id'])."','".mysql_real_escape_string($invitation_code)."','".mysql_real_escape_string(date('Y-m-d H:i:s'))."')";
echo $sql;
$sql = "INSERT INTO $table_survey_invitation (user, survey_code, invitation_code, invitation_date) VALUES
('".mysql_real_escape_string($value)."','".mysql_real_escape_string($survey_data['code'])."','".mysql_real_escape_string($invitation_code)."','".mysql_real_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
@ -235,48 +279,48 @@ function save_invitations($users_array, $invitation_title, $invitation_text)
}
/**
* Enter description here...
* 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_id)
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_id = '".mysql_real_escape_string($survey_id)."'";
$sql = "SELECT count(user) as total FROM $table_survey_invitation WHERE survey_code = '".mysql_real_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 = '".mysql_real_escape_string($total_invited)."' WHERE survey_id = '".mysql_real_escape_string($survey_id)."'";
$sql = "UPDATE $table_survey SET invited = '".mysql_real_escape_string($total_invited)."' WHERE code = '".mysql_real_escape_string($survey_code)."'";
$result = api_sql_query($sql, __FILE__, __LINE__);
}
/**
* Enter description here...
* This function gets all the invitations for a given survey code.
*
* @param unknown_type $survey_id
* @return unknown
* @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_invitations($survey_id)
function get_invitations($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_id='".mysql_real_escape_string($survey_id)."'";
$sql = "SELECT user FROM $table_survey_invitation WHERE survey_code='".mysql_real_escape_string($survey_code)."'";
$result = api_sql_query($sql, __FILE__, __LINE__);
while ($row = mysql_fetch_assoc($result))

@ -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 11351 2007-03-02 16:03:00Z elixir_julian $
* @version $Id: survey_list.php 11451 2007-03-06 21:54:30Z pcool $
*
* @todo The invite column is not done
* @todo try to understand the white, blue, ... template stuff.
@ -43,7 +43,7 @@ require_once (api_get_path(LIBRARY_PATH)."/course.lib.php");
if (!api_is_allowed_to_edit())
{
Display :: display_header();
Display :: display_error_message(get_lang('NotAllowedHere'));
Display :: display_error_message(get_lang('NotAllowedHere'), false);
Display :: display_footer();
exit;
}
@ -57,6 +57,7 @@ $table_user = Database :: get_main_table(TABLE_MAIN_USER);
// language variables
if (isset ($_GET['search']) && $_GET['search'] == 'advanced')
{
$interbreadcrumb[] = array ('url' => 'survey_list.php', 'name' => get_lang('SurveyList'));
$tool_name = get_lang('SearchASurvey');
}
else
@ -76,14 +77,21 @@ if (isset ($_GET['search']) AND $_GET['search'] == 'advanced')
// Action handling: deleting a survey
if (isset($_GET['action']) AND $_GET['action'] == 'delete' AND isset($_GET['survey_id']) AND is_numeric($_GET['survey_id']))
{
// getting the information of the survey (used for when the survey is shared)
$survey_data = survey_manager::get_survey($_GET['survey_id']);
// if the survey is shared => also delete the shared content
if (is_numeric($survey_data['survey_share']))
{
survey_manager::delete_survey($survey_data['survey_share'], true);
}
$return = survey_manager :: delete_survey($_GET['survey_id']);
if ($return)
{
Display :: display_confirmation_message(get_lang('SurveyDeleted'));
Display :: display_confirmation_message(get_lang('SurveyDeleted'), false);
}
else
{
Display :: display_error_message(get_lang('ErrorOccurred'));
Display :: display_error_message(get_lang('ErrorOccurred'), false);
}
}
@ -94,13 +102,21 @@ if ($_POST['action'])
{
foreach ($_POST['id'] as $key=>$value)
{
delete_survey($value);
// getting the information of the survey (used for when the survey is shared)
$survey_data = survey_manager::get_survey($value);
// if the survey is shared => also delete the shared content
if (is_numeric($survey_data['survey_share']))
{
survey_manager::delete_survey($survey_data['survey_share'], true);
}
// delete the actual survey
survey_manager::delete_survey($value);
}
Display :: display_confirmation_message(get_lang('SurveyDeleted'));
Display :: display_confirmation_message(get_lang('SurveysDeleted'), false);
}
else
{
Display :: display_error_message(get_lang('NoSurveysSelected'));
Display :: display_error_message(get_lang('NoSurveysSelected'), false);
}
}
@ -175,7 +191,7 @@ function display_survey_list()
{
$message = get_lang('DisplaySearchResults').'<br />';
$message .= '<a href="'.$_SERVER['PHP_SELF'].'">'.get_lang('DisplayAll').'</a>';
Display::display_normal_message($message);
Display::display_normal_message($message, false);
}
// Create a sortable table with survey-data
@ -187,11 +203,12 @@ function display_survey_list()
$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('AvailableFrom'));
$table->set_header(7, get_lang('AvailableUntill'));
$table->set_header(8, get_lang('Invite'));
$table->set_header(9, get_lang('Modify'), false);
$table->set_column_filter(9, 'modify_filter');
$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('Modify'), false);
$table->set_column_filter(10, 'modify_filter');
$table->set_form_actions(array ('delete' => get_lang('DeleteSurvey')));
$table->display();
@ -253,10 +270,11 @@ function get_survey_data($from, $number_of_items, $column, $direction)
count(survey_question.question_id) AS col3,
CONCAT(user.firstname, ' ', user.lastname) AS col4,
survey.lang AS col5,
survey.avail_from AS col6,
survey.avail_till AS col7,
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 col8,
survey.survey_id AS col9
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.survey_id AS col10
FROM $table_survey survey
LEFT JOIN $table_survey_question survey_question ON survey.survey_id = survey_question.survey_id
, $table_user user
@ -287,13 +305,13 @@ function get_survey_data($from, $number_of_items, $column, $direction)
*/
function modify_filter($survey_id)
{
$return = '<a href="create_new_survey.php?action=edit&amp;survey_id='.$survey_id.'">'.Display::return_icon('edit.gif').'</a>';
$return .= '<a href="survey_list.php?action=delete&amp;survey_id='.$survey_id.'">'.Display::return_icon('delete.gif').'</a>';
//$return .= '<a href="create_survey_in_another_language.php?id_survey='.$survey_id.'">'.Display::return_icon('copy.gif').'</a>';
//$return .= '<a href="survey.php?survey_id='.$survey_id.'">'.Display::return_icon('add.gif').'</a>';
$return .= '<a href="preview.php?survey_id='.$survey_id.'">'.Display::return_icon('preview.gif').'</a>';
$return .= '<a href="survey_invite.php?survey_id='.$survey_id.'">'.Display::return_icon('survey_publish.gif').'</a>';
$return .= '<a href="reporting.php?survey_id='.$survey_id.'">'.Display::return_icon('statistics.gif').'</a>';
$return = '<a href="create_new_survey.php?action=edit&amp;survey_id='.$survey_id.'">'.Display::return_icon('edit.gif', get_lang('Edit')).'</a>';
$return .= '<a href="survey_list.php?action=delete&amp;survey_id='.$survey_id.'" onclick="javascript:if(!confirm(\''.addslashes(htmlentities(get_lang("DeleteSurvey").'?')).'\')) 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?survey_id='.$survey_id.'">'.Display::return_icon('preview.gif', get_lang('Preview')).'</a>';
$return .= '<a href="survey_invite.php?survey_id='.$survey_id.'">'.Display::return_icon('survey_publish.gif', get_lang('Publish')).'</a>';
$return .= '<a href="reporting.php?survey_id='.$survey_id.'">'.Display::return_icon('surveyreporting.gif', get_lang('Reporting')).'</a>';
return $return;
}
@ -331,102 +349,4 @@ function survey_search_restriction()
return false;
}
}
/* if(isset($published))
{
$sname = surveymanager::pick_surveyname($surveyid);
$error_message = get_lang('YourSurveyHasBeenPublished');
Display::display_error_message("Survey "."'".$sname."'"." ".$error_message);
}
$res = api_sql_query($sql,__FILE__,__LINE__);
if (mysql_num_rows($res) > 0)
{
$courses = array ();
while ($obj = mysql_fetch_object($res))
{
$template=$obj->template;
$surveyid = $obj->survey_id;
if($template=='template1'){$view='white';}
elseif($template=='template2'){$view='blue';}
elseif($template=='template3'){$view='brown';}
elseif($template=='template4'){$view='gray';}
else{$view=='blank';}
$sql_sent=" SELECT DISTINCT user_info.*
FROM $user_info as user_info
INNER JOIN $table_survey as survey
ON user_info.sid = survey.survey_id
AND survey.code = '".$obj->code."'";
$res_sent=api_sql_query($sql_sent);
$sent=mysql_num_rows($res_sent);
$attempted=0;
$sqlAttempt = ' SELECT DISTINCT *
FROM '.Database::get_main_table(TABLE_MAIN_SURVEY_USER).'
WHERE survey_id='.$obj->survey_id.' AND db_name="'.$db_name.'"';
$res_attempt=api_sql_query($sqlAttempt);
$attempted=mysql_num_rows($res_attempt);
if($sent=='0')
{$ratio=$attempted."/".$sent." "."(Not Published)";}
else
$ratio=$attempted."/".$sent;
$survey = array ();
$survey[] = '<input type="checkbox" name="survey_delete[]" value="'.$obj->survey_id.'">';
$survey[] = $obj->title;
$survey[] = $obj->code;
$idd=surveymanager::get_author($db_name,$surveyid);
$author=surveymanager::get_survey_author($idd);
$survey[] = $author;
$survey[] = $obj->lang;
$survey[] = $obj->avail_from ;
$survey[] = $obj->avail_till ;
$survey[] = $ratio;
//$NoOfQuestion=surveymanager::no_of_question($gid);
//$language=surveymanager::no_of_question($sid);
$survey[] = '<a href="survey_edit.php?surveyid='.$obj->survey_id.'"><img src="../img/edit.gif" border="0" align="absmiddle" alt="'.get_lang('Edit').'"/></a>'.'<a href="survey_list.php?&action=delete_surveys&survey_delete[]='.$obj->survey_id.'&delete_survey='.$obj->survey_id.'" onclick="javascript:if(!confirm('."'".addslashes(htmlentities(get_lang('ConfirmYourChoice')))."'".')) return false;"><img src="../img/delete.gif" border="0" align="absmiddle" alt="'.get_lang('Delete').'"/></a>'.'<a href="create_survey_in_another_language.php?id_survey='.$obj->survey_id.'"><img width="28" src="../img/copy.gif" border="0" align="absmiddle" alt="'.get_lang('CreateInAnotherLanguage').'" title="'.get_lang('CreateInAnotherLanguage').'" /></a>'.'<a href="survey_white.php?surveyid='.$surveyid.'&temp='.$template.'">&nbsp;<img src="../img/visible.gif" border="0" align="absmiddle" alt="'.get_lang('ViewSurvey').'"></a>'.'<a href="../announcements/announcements.php?action=add&publish_survey='.$obj->survey_id.'">&nbsp;<img src="../img/survey_publish.gif" border="0" align="absmiddle" alt="'.get_lang('Publish').'"></a>'.'<a href="reporting.php?surveyid='.$obj->survey_id.'">&nbsp;<img src="../img/surveyreporting.gif" border="0" align="absmiddle" alt="'.get_lang('Reporting').'"></a>';
$surveys[] = $survey;
}
$table_header[] = array (' ', false);
$table_header[] = array (get_lang('SurveyName'), true);
$table_header[] = array (get_lang('SurveyCode'), true);
$table_header[] = array (get_lang('Author'), true);
$table_header[] = array (get_lang('Language'), true);
$table_header[] = array (get_lang('AvailableFrom'), true);
$table_header[] = array (get_lang('AvailableTill'), true);
$table_header[] = array (get_lang('AnsTarget'), true);
$table_header[] = array (' ', false);
echo '<form method="get" action="survey_list.php" name="frm">';
Display :: display_sortable_table($table_header, $surveys, array (), array (), $parameters);
echo '<select name="action">';
echo '<option value="delete_surveys">'.get_lang('DeleteSurvey').'</option>';
echo '</select>';
echo '&nbsp;&nbsp;<input type="submit" value="'.get_lang('Ok').'" onclick="return validate(\'frm\');"/>';
echo '</form>';
}
else
{
if((isset ($_GET['keyword'])) || (isset ($_GET['keyword_title']))){
echo get_lang('NoSearchResults') ;
}
else{
$nosurvey=get_lang('NoSurveyAvailable');
api_display_tool_title($nosurvey);
}
}
}
*/
?>
?>
Loading…
Cancel
Save