Updating from 1.9.x

1.10.x
Julio Montoya 11 years ago
parent f6a3791b08
commit 37ce03a9c4
  1. 106
      main/inc/lib/gradebook.lib.php
  2. 224
      main/survey/create_new_survey.php
  3. 319
      main/survey/fillsurvey.php
  4. 5
      main/survey/generate_link.php
  5. 7
      main/survey/link.php
  6. 89
      main/survey/preview.php
  7. 32
      main/survey/question.php
  8. 40
      main/survey/reporting.php
  9. 55
      main/survey/survey.download.inc.php
  10. 9127
      main/survey/survey.lib.php
  11. 386
      main/survey/survey.php
  12. 98
      main/survey/survey_invitation.php
  13. 257
      main/survey/survey_invite.php
  14. 167
      main/survey/survey_list.php

@ -3,33 +3,20 @@
/**
* This class provides methods for the notebook management.
* Include/require it in your code to use its features.
* @package chamilo.library
* @package chamilo.library
*/
/**
* Code
*/
class Gradebook extends Model
{
public $columns = array(
'id',
'name',
'description',
'course_code',
'parent_id',
'grade_model_id',
'session_id',
'weight',
'user_id'
);
public $columns = array('id', 'name', 'description', 'course_code', 'parent_id', 'grade_model_id', 'session_id', 'weight', 'user_id');
public function __construct()
{
$this->table = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY);
$this->table_skill = Database::get_main_table(TABLE_MAIN_SKILL);
$this->table_skill_rel_gradebook = Database::get_main_table(TABLE_MAIN_SKILL_REL_GRADEBOOK);
$this->table = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY);
$this->table_skill = Database::get_main_table(TABLE_MAIN_SKILL);
$this->table_skill_rel_gradebook = Database::get_main_table(TABLE_MAIN_SKILL_REL_GRADEBOOK);
}
/**
@ -41,24 +28,28 @@ class Gradebook extends Model
*/
public static function is_active($c_id = null)
{
$name = 'gradebook';
$table = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
$sql = "SELECT * from $table WHERE variable='course_hide_tools' AND subkey='$name'";
$setting = ResultSet::create($sql)->first();
$setting = $setting ? $setting : array();
$name = 'gradebook';
$table = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
$sql = "SELECT * from $table WHERE variable='course_hide_tools' AND subkey='$name' LIMIT 1";
$result = Database::query($sql);
$setting = Database::store_result($result);
$setting = isset($setting[0]) ? $setting[0] : null;
$setting = $setting ? $setting : array();
$inactive = isset($setting['selected_value']) && $setting['selected_value'] == 'true';
if ($inactive) {
return false;
}
$c_id = $c_id ? intval($c_id) : api_get_course_int_id();
$table = Database::get_course_table(TABLE_TOOL_LIST);
$sql = "SELECT * from $table WHERE c_id = $c_id and name='$name'";
$item = ResultSet::create($sql)->first();
$c_id = $c_id ? intval($c_id) : api_get_course_int_id();
$table = Database::get_course_table(TABLE_TOOL_LIST);
$sql = "SELECT * from $table WHERE c_id = $c_id and name='$name' LIMIT 1";
$result = Database::query($sql);
$item = Database::store_result($result, 'ASSOC');
$item = isset($item[0]) ? $item[0] : null;
if (empty($item)) {
return true;
}
return $item['visibility'] == '1';
}
@ -69,8 +60,8 @@ class Gradebook extends Model
if (empty($gradebook['name'])) {
$gradebook['name'] = $gradebook['course_code'];
}
//$gradebook['name'] = $gradebook['course_code'] .' > '.$gradebook['name'];
}
return $gradebooks;
}
@ -85,16 +76,14 @@ class Gradebook extends Model
if (!empty($skill_list)) {
//Cleaning skills
$skill_list = array_map('intval', $skill_list);
$skill_list = array_filter($skill_list);
$skill_gradebook = new SkillRelGradebook();
$skill_gradebooks_source = $skill_gradebook->get_all(
array('where' => array('gradebook_id = ?' => $gradebook_id))
);
$clean_gradebook = array();
$skill_list = array_map('intval', $skill_list);
$skill_list = array_filter($skill_list);
$skill_gradebook = new SkillRelGradebook();
$skill_gradebooks_source = $skill_gradebook->get_all(array('where'=>array('gradebook_id = ?' =>$gradebook_id)));
$clean_gradebook = array();
if (!empty($skill_gradebooks_source)) {
foreach ($skill_gradebooks_source as $source) {
$clean_gradebook[] = $source['skill_id'];
foreach($skill_gradebooks_source as $source) {
$clean_gradebook[]= $source['skill_id'];
}
}
if (!empty($clean_gradebook)) {
@ -102,7 +91,7 @@ class Gradebook extends Model
}
foreach ($skill_list as $skill_id) {
$params = array();
$params = array();
$params['gradebook_id'] = $gradebook_id;
$params['skill_id'] = $skill_id;
if (!$skill_gradebook->exists_gradebook_skill($gradebook_id, $skill_id)) {
@ -111,15 +100,13 @@ class Gradebook extends Model
}
if (!empty($skill_to_remove)) {
foreach ($skill_to_remove as $remove) {
foreach($skill_to_remove as $remove) {
$skill_item = $skill_gradebook->get_skill_info($remove, $gradebook_id);
$skill_gradebook->delete($skill_item['id']);
}
}
return true;
}
return false;
}
@ -132,9 +119,8 @@ class Gradebook extends Model
*/
public function show_skill_form($gradebook_id, $url, $header = null)
{
$form = new FormValidator('gradebook_add_skill', 'POST', $url);
// Settting the form elements
// Setting the form elements
if (!isset($header)) {
$header = get_lang('Add');
}
@ -142,44 +128,40 @@ class Gradebook extends Model
$id = isset($_GET['id']) ? intval($_GET['id']) : '';
$form->addElement('hidden', 'id', $id);
$skill = new Skill();
$skills = $skill->get_all();
$skill = new Skill();
$skills = $skill->get_all();
$clean_skill_list = array();
foreach ($skills as $skill) {
$clean_skill_list[$skill['id']] = $skill['name'];
}
$form->addElement(
'select',
'skill',
get_lang('Skills'),
$clean_skill_list,
array('width' => '450px', 'class' => 'chzn-select', 'multiple' => 'multiple')
);
$selected_skills = self::get_skills_by_gradebook($gradebook_id);
$form->addElement('select', 'skill', get_lang('Skills'), $clean_skill_list, array('width'=>'450px', 'class'=>'chzn-select','multiple' => 'multiple'));
$selected_skills = self::get_skills_by_gradebook($gradebook_id);
$clean_selected_skills = array();
if (!empty($selected_skills)) {
foreach ($selected_skills as $skill) {
foreach($selected_skills as $skill) {
$clean_selected_skills[] = $skill['id'];
}
}
$form->addElement('style_submit_button', 'submit', get_lang('Add'), 'class="save"');
$form->setDefaults(array('skill' => $clean_selected_skills));
$form->setDefaults(array('skill'=>$clean_selected_skills));
return $form;
}
/**
* @param int $gradebook_id
* @return array|resource
*/
function get_skills_by_gradebook($gradebook_id)
{
$gradebook_id = intval($gradebook_id);
$sql = "SELECT skill.id, skill.name FROM {$this->table_skill} skill INNER JOIN {$this->table_skill_rel_gradebook} skill_rel_gradebook
$sql = "SELECT skill.id, skill.name FROM {$this->table_skill} skill INNER JOIN {$this->table_skill_rel_gradebook} skill_rel_gradebook
ON skill.id = skill_rel_gradebook.skill_id
WHERE skill_rel_gradebook.gradebook_id = $gradebook_id";
$result = Database::query($sql);
$result = Database::store_result($result, 'ASSOC');
$result = Database::query($sql);
$result = Database::store_result($result,'ASSOC');
return $result;
}

@ -1,15 +1,14 @@
<?php
/* For licensing terms, see /license.txt */
/**
* @package chamilo.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
* @author Julio Montoya Armas <gugli100@gmail.com>, Chamilo: Personality Test modification and rewriting large parts of the code
* @version $Id: create_new_survey.php 22297 2009-07-22 22:08:30Z cfasanando $
* @package chamilo.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
* @author Julio Montoya Armas <gugli100@gmail.com>, Chamilo: Personality Test modification and rewriting large parts of the code
* @version $Id: create_new_survey.php 22297 2009-07-22 22:08:30Z cfasanando $
*
* @todo only the available platform languages should be used => need an api get_languages and and api_get_available_languages (or a parameter)
* @todo only the available platform languages should be used => need an api get_languages and and api_get_available_languages (or a parameter)
*/
// Language file that needs to be included
$language_file = 'survey';
@ -24,12 +23,24 @@ $this_section = SECTION_COURSES;
/** @todo check if the starting / is needed. api_get_path probably ends with an / */
//require_once api_get_path(LIBRARY_PATH).'survey.lib.php';
require_once 'survey.lib.php';
//require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php';
require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/gradebook_functions.inc.php';
$htmlHeadXtra[] = '<script>
function advanced_parameters() {
if (document.getElementById(\'options\').style.display == \'none\') {
document.getElementById(\'options\').style.display = \'block\';
document.getElementById(\'plus_minus\').innerHTML=\'&nbsp;'.Display::return_icon('div_hide.gif', get_lang('Hide'), array('style' => 'vertical-align:middle')).'&nbsp;'.get_lang('AdvancedParameters').'\';
} else {
document.getElementById(\'options\').style.display = \'none\';
document.getElementById(\'plus_minus\').innerHTML=\'&nbsp;'.Display::return_icon('div_show.gif', get_lang('Show'), array('style' => 'vertical-align:middle')).'&nbsp;'.get_lang('AdvancedParameters').'\';
}
}
function setFocus(){
$("#surveycode_title").focus();
$("#surveycode_title").focus();
}
$(document).ready(function () {
setFocus();
});
@ -44,10 +55,9 @@ $table_gradebook_link = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
/** @todo this has to be moved to a more appropriate place (after the display_header of the code) */
// If user is not teacher or if he's a coach trying to access an element out of his session
if (!api_is_allowed_to_edit()) {
if (!api_is_course_coach() || (!empty($_GET['survey_id']) && !api_is_element_in_the_session(
TOOL_SURVEY,
intval($_GET['survey_id'])
))
if (!api_is_course_coach() ||
(!empty($_GET['survey_id']) &&
!api_is_element_in_the_session(TOOL_SURVEY, $_GET['survey_id']))
) {
api_not_allowed(true);
exit;
@ -55,27 +65,35 @@ if (!api_is_allowed_to_edit()) {
}
// Getting the survey information
$survey_id = Security::remove_XSS($_GET['survey_id']);
$survey_id = isset($_GET['survey_id']) ? intval($_GET['survey_id']) : null;
$survey_data = survey_manager::get_survey($survey_id);
// Additional information
$course_id = api_get_course_id();
$session_id = api_get_session_id();
$gradebook_link_type = 8; // LINK_SURVEY
$urlname = $survey_data['title'];
$gradebook_link_type = 8;
$urlname = isset($survey_data['title']) ? strip_tags($survey_data['title']) : null;
// Breadcrumbs
if ($_GET['action'] == 'add') {
$interbreadcrumb[] = array('url' => 'survey_list.php', 'name' => get_lang('SurveyList'));
$interbreadcrumb[] = array(
'url' => api_get_path(WEB_CODE_PATH).'survey/survey_list.php?'.api_get_cidreq(),
'name' => get_lang('SurveyList')
);
$tool_name = get_lang('CreateNewSurvey');
}
if ($_GET['action'] == 'edit' && is_numeric($survey_id)) {
$interbreadcrumb[] = array('url' => 'survey_list.php', 'name' => get_lang('SurveyList'));
$interbreadcrumb[] = array('url' => 'survey.php?survey_id='.$survey_id, 'name' => strip_tags($urlname));
$interbreadcrumb[] = array(
'url' => api_get_path(WEB_CODE_PATH).'survey/survey_list.php?'.api_get_cidreq(),
'name' => get_lang('SurveyList')
);
$interbreadcrumb[] = array(
'url' => api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.$survey_id.'&'.api_get_cidreq(),
'name' => Security::remove_XSS($urlname)
);
$tool_name = get_lang('EditSurvey');
}
$gradebook_link_id = null;
// Getting the default values
if ($_GET['action'] == 'edit' && isset($survey_id) && is_numeric($survey_id)) {
$defaults = $survey_data;
@ -86,10 +104,7 @@ if ($_GET['action'] == 'edit' && isset($survey_id) && is_numeric($survey_id)) {
$gradebook_link_id = $link_info['id'];
if ($link_info) {
if ($sql_result_array = Database::fetch_array(
Database::query('SELECT weight FROM '.$table_gradebook_link.' WHERE id='.$gradebook_link_id)
)
) {
if ($sql_result_array = Database::fetch_array(Database::query('SELECT weight FROM '.$table_gradebook_link.' WHERE id='.$gradebook_link_id))) {
$defaults['survey_qualify_gradebook'] = $gradebook_link_id;
$defaults['survey_weight'] = number_format($sql_result_array['weight'], 2, '.', '');
}
@ -99,82 +114,70 @@ if ($_GET['action'] == 'edit' && isset($survey_id) && is_numeric($survey_id)) {
$defaults['start_date'] = date('d-F-Y H:i');
$startdateandxdays = time() + 864000; // today + 10 days
$defaults['end_date'] = date('d-F-Y H:i', $startdateandxdays);
//$defaults['survey_share']['survey_share'] = 0;
//$form_share_value = 1;
$defaults['anonymous'] = 0;
}
// Initialize the object
$form = new FormValidator('survey', 'post', api_get_self().'?action='.Security::remove_XSS(
$_GET['action']
).'&survey_id='.$survey_id);
$form = new FormValidator('survey', 'post', api_get_self().'?action='.Security::remove_XSS($_GET['action']).'&survey_id='.$survey_id);
$form->addElement('header', '', $tool_name);
// Settting the form elements
// Setting the form elements
if ($_GET['action'] == 'edit' && isset($survey_id) && is_numeric($survey_id)) {
$form->addElement('hidden', 'survey_id');
}
$survey_code = $form->addElement(
'text',
'survey_code',
get_lang('SurveyCode'),
array('size' => '20', 'maxlength' => '20', 'id' => 'surveycode_title')
);
$survey_code = $form->addElement('text', 'survey_code', get_lang('SurveyCode'), array('size' => '20', 'maxlength' => '20', 'id' => 'surveycode_title'));
$form->addElement(
'html_editor',
'survey_title',
get_lang('SurveyTitle'),
null,
array('ToolbarSet' => 'Survey', 'Width' => '100%', 'Height' => '200')
);
$form->addElement(
'html_editor',
'survey_subtitle',
get_lang('SurveySubTitle'),
null,
array('ToolbarSet' => 'Survey', 'Width' => '100%', 'Height' => '100', 'ToolbarStartExpanded' => false)
);
if ($_GET['action'] == 'edit') {
$survey_code->freeze();
$form->applyFilter('survey_code', 'api_strtoupper');
}
$form->addElement('html_editor', 'survey_title', get_lang('SurveyTitle'), null, array('ToolbarSet' => 'Survey', 'Width' => '100%', 'Height' => '200'));
$form->addElement('html_editor', 'survey_subtitle', get_lang('SurveySubTitle'), null, array('ToolbarSet' => 'Survey', 'Width' => '100%', 'Height' => '100', 'ToolbarStartExpanded' => false));
/*
//Language selection has been disabled. If you want to re-enable, please
//disable the following line (hidden language field).
$lang_array = api_get_languages();
foreach ($lang_array['name'] as $key => $value) {
$languages[$lang_array['folder'][$key]] = $value;
}
$form->addElement('select', 'survey_language', get_lang('Language'), $languages);
*/
// Pass the language of the survey in the form
$form->addElement('hidden', 'survey_language');
$form->addElement('datepickerdate', 'start_date', get_lang('StartDate'), array('form_name' => 'survey'));
$form->addElement('datepickerdate', 'end_date', get_lang('EndDate'), array('form_name' => 'survey'));
$form->addElement('date_picker', 'start_date', get_lang('StartDate'));
$form->addElement('date_picker', 'end_date', get_lang('EndDate'));
//$group = '';
//$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);
//$form->addGroup($group, 'survey_share', get_lang('ShareSurvey'), '&nbsp;');
$form->addElement('checkbox', 'anonymous', null, get_lang('Anonymous'));
$form->addElement('html_editor', 'survey_introduction', get_lang('SurveyIntroduction'), null, array('ToolbarSet' => 'Survey', 'Width' => '100%', 'Height' => '130', 'ToolbarStartExpanded' => false));
$form->addElement('html_editor', 'survey_thanks', get_lang('SurveyThanks'), null, array('ToolbarSet' => 'Survey', 'Width' => '100%', 'Height' => '130', 'ToolbarStartExpanded' => false));
// Aditional Parameters
$form->addElement(
'html_editor',
'survey_introduction',
get_lang('SurveyIntroduction'),
null,
array('ToolbarSet' => 'Survey', 'Width' => '100%', 'Height' => '130', 'ToolbarStartExpanded' => false)
);
$form->addElement(
'html_editor',
'survey_thanks',
get_lang('SurveyThanks'),
null,
array('ToolbarSet' => 'Survey', 'Width' => '100%', 'Height' => '130', 'ToolbarStartExpanded' => false)
'advanced_settings',
'<a href="javascript: void(0);" onclick="javascript: advanced_parameters();">
<span id="plus_minus">&nbsp;'.
Display::return_icon('div_show.gif', null, array('style' => 'vertical-align:middle')).'&nbsp;'.get_lang('AdvancedParameters').'</span></a>'
);
$form->addElement('advanced_settings', 'options', get_lang('AdvancedParameters'));
$form->addElement('html', '<div id="options_options" style="display: none;">');
$form->addElement('html', '<div id="options" style="display: none;">');
if (Gradebook::is_active()) {
// An option: Qualify the fact that survey has been answered in the gradebook
$form->addElement(
'checkbox',
'survey_qualify_gradebook',
null,
get_lang('QualifyInGradebook'),
'onclick="javascript: if (this.checked) { document.getElementById(\'gradebook_options\').style.display = \'block\'; } else { document.getElementById(\'gradebook_options\').style.display = \'none\'; }"'
);
$form->addElement('checkbox', 'survey_qualify_gradebook', null, get_lang('QualifyInGradebook'), 'onclick="javascript: if (this.checked) { document.getElementById(\'gradebook_options\').style.display = \'block\'; } else { document.getElementById(\'gradebook_options\').style.display = \'none\'; }"');
$form->addElement('html', '<div id="gradebook_options"'.($gradebook_link_id ? '' : ' style="display:none"').'>');
$form->addElement(
'text',
'survey_weight',
get_lang('QualifyWeight'),
'value="0.00" style="width: 40px;" onfocus="javascript: this.select();"'
);
$form->addElement('text', 'survey_weight', get_lang('QualifyWeight'), 'value="0.00" style="width: 40px;" onfocus="javascript: this.select();"');
$form->applyFilter('survey_weight', 'html_filter');
$form->addElement('html', '</div>');
}
@ -193,38 +196,32 @@ if ($_GET['action'] == 'add') {
$defaults['parent_id'] = 0;
}
if ($survey_data['survey_type'] == 1 || $_GET['action'] == 'add') {
if (isset($survey_data['survey_type']) && $survey_data['survey_type'] == 1 || $_GET['action'] == 'add') {
$form->addElement('checkbox', 'one_question_per_page', null, get_lang('OneQuestionPerPage'));
$form->addElement('checkbox', 'shuffle', null, get_lang('ActivateShuffle'));
}
$input_name_list = null;
if ((isset($_GET['action']) && $_GET['action'] == 'edit') && !empty($survey_id)) {
if ($survey_data['anonymous'] == 0) {
$form->addElement(
'checkbox',
'show_form_profile',
null,
get_lang('ShowFormProfile'),
'onclick="javascript: if(this.checked){document.getElementById(\'options_field\').style.display = \'block\';}else{document.getElementById(\'options_field\').style.display = \'none\';}"'
);
$form->addElement('checkbox', 'show_form_profile', null, get_lang('ShowFormProfile'), 'onclick="javascript: if(this.checked){document.getElementById(\'options_field\').style.display = \'block\';}else{document.getElementById(\'options_field\').style.display = \'none\';}"');
if ($survey_data['show_form_profile'] == 1) {
$form->addElement('html', '<div id="options_field" style="display:block">');
} else {
$form->addElement('html', '<div id="options_field" style="display:none">');
}
$input_name_list = null;
$field_list = SurveyUtil::make_field_list();
if (is_array($field_list)) {
// TODO hide and show the list in a fancy DIV
foreach ($field_list as $key => & $field) {
if ($field['visibility'] == 1) {
$form->addElement('checkbox', 'profile_'.$key, ' ', '&nbsp;&nbsp;'.$field['name']);
$input_name_list .= 'profile_'.$key.',';
$input_name_list.= 'profile_'.$key.',';
}
}
// Needed to know the fields
// Necessary to know the fields
$form->addElement('hidden', 'input_name_list', $input_name_list);
// Set defaults form fields
@ -238,6 +235,7 @@ if ((isset($_GET['action']) && $_GET['action'] == 'edit') && !empty($survey_id))
}
}
}
$form->addElement('html', '</div>');
}
}
@ -273,54 +271,62 @@ if ($form->validate()) {
// 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']) && $values['survey_share']['survey_share'] == 0 && $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 && $values['survey_share']['survey_share'] !== 0 && $values['survey_id'] != '') {
survey_manager::get_complete_survey_structure($return['id']);
}
*/
if ($return['type'] == 'error') {
// Display the error
Display::display_error_message(get_lang($return['message']), false);
// Displaying the header
Display::display_header($tool_name);
// Display the error
Display::display_error_message(get_lang($return['message']), false);
// Display the form
$form->display();
} else {
$gradebook_option = isset($values['survey_qualify_gradebook']) && $values['survey_qualify_gradebook'] > 0;
$gradebook_option = $values['survey_qualify_gradebook'] > 0;
if ($gradebook_option) {
$survey_id = intval($return['id']);
if ($survey_id > 0) {
$title_gradebook = ''; // Not needed here.
$description_gradebook = ''; // Not needed here.
$survey_weight = floatval($_POST['survey_weight']);
$max_score = 1;
$date = time(); // TODO: Maybe time zones implementation is needed here.
$visible = 1; // 1 = visible
$link_info = is_resource_in_course_gradebook($course_id, $gradebook_link_type, $survey_id, $session_id);
$gradebook_link_id = $link_info['id'];
if (!$gradebook_link_id) {
add_resource_to_course_gradebook(
$course_id,
$gradebook_link_type,
$survey_id,
null,
$survey_weight,
$max_score,
null,
1,
$session_id
);
add_resource_to_course_gradebook($course_id, $gradebook_link_type, $survey_id, $title_gradebook, $survey_weight, $max_score, $description_gradebook, 1, $session_id);
} else {
Database::query(
'UPDATE '.$table_gradebook_link.' SET weight='.$survey_weight.' WHERE id='.$gradebook_link_id
);
Database::query('UPDATE '.$table_gradebook_link.' SET weight='.$survey_weight.' WHERE id='.$gradebook_link_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']);
header('location: '.api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.$return['id'].'&message='.$return['message'].'&'.api_get_cidreq());
exit;
}
} else {
// Displaying the header
Display::display_header($tool_name);
$form->display();
}
// Footer
Display :: display_footer();

@ -1,18 +1,17 @@
<?php
/* For licensing terms, see /license.txt */
/**
* @package chamilo.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
* @author Julio Montoya Armas <gugli100@gmail.com>, Chamilo: Personality Test modification and rewriting large parts of the code as well
* @version $Id: survey_list.php 10680 2007-01-11 21:26:23Z pcool $
*
* @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
* @package chamilo.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
* @author Julio Montoya Armas <gugli100@gmail.com>, Chamilo: Personality Test modification and rewriting large parts of the code as well
* @version $Id: survey_list.php 10680 2007-01-11 21:26:23Z pcool $
*
* @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
*/
// Language file that needs to be included
$language_file = 'survey';
@ -27,15 +26,30 @@ if (!isset($_GET['cidReq'])) {
require_once '../inc/global.inc.php';
// Including additional libraries
//require_once api_get_path(LIBRARY_PATH).'survey.lib.php';
require_once 'survey.lib.php';
// Breadcrumbs
if (!empty($_user)) {
$interbreadcrumb[] = array('url' => 'survey_list.php?cidReq='.Security::remove_XSS($_GET['course']), 'name' => get_lang('SurveyList'));
$interbreadcrumb[] = array(
'url' => api_get_path(WEB_CODE_PATH).'survey/survey_list.php?cidReq='.Security::remove_XSS($_GET['course']),
'name' => get_lang('SurveyList')
);
}
if (($_GET['invitationcode'] == 'auto' && isset($_GET['scode'])) && ((!(isset($_user['user_id']) && $_user['user_id']) || api_is_anonymous($_user['user_id'], true)))) {
// anonymous users not allowed
api_not_allowed();
// Database table definitions
$table_survey = Database :: get_course_table(TABLE_SURVEY);
$table_survey_answer = Database :: get_course_table(TABLE_SURVEY_ANSWER);
$table_survey_question = Database :: get_course_table(TABLE_SURVEY_QUESTION);
$table_survey_question_option = Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION);
$table_survey_invitation = Database :: get_course_table(TABLE_SURVEY_INVITATION);
$table_user = Database :: get_main_table(TABLE_MAIN_USER);
// Check if user is anonymous or not
if (api_is_anonymous($_user['user_id'], true)) {
$isAnonymous = true;
} else {
$isAnonymous = false;
}
// getting all the course information
@ -50,20 +64,25 @@ if (empty($course_info)) {
}
$course_id = $course_info['real_id'];
$surveyCode = isset($_GET['scode']) ? Database::escape_string($_GET['scode']) : '';
if ($surveyCode != "") {
// Firstly we check if this survey is ready for anonymous use:
$sqlAnonymous = "SELECT anonymous FROM $table_survey WHERE c_id = $course_id AND code ='".$surveyCode."'";
$resultAnonymous = Database::query($sqlAnonymous);
$rowAnonymous = Database::fetch_array($resultAnonymous, 'ASSOC');
// If is anonymous and is not allowed to take the survey to anonymous users, forbid access:
if (!isset($rowAnonymous['anonymous']) || ($rowAnonymous['anonymous'] == 0 && api_is_anonymous($_user['user_id'], true)) || count($rowAnonymous) == 0) {
api_not_allowed();
}
// If is anonymous and it is allowed to take the survey as anonymous, mark survey as anonymous:
} else {
//nothing to do
}
// Header
Display :: display_header(get_lang('ToolSurvey'));
// Database table definitions
$table_survey = Database :: get_course_table(TABLE_SURVEY);
$table_survey_answer = Database :: get_course_table(TABLE_SURVEY_ANSWER);
$table_survey_question = Database :: get_course_table(TABLE_SURVEY_QUESTION);
$table_survey_question_option = Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION);
$table_survey_invitation = Database :: get_course_table(TABLE_SURVEY_INVITATION);
$table_user = Database :: get_main_table(TABLE_MAIN_USER);
// First we check if the needed parameters are present
if ((!isset($_GET['course']) || !isset($_GET['invitationcode'])) && !isset($_GET['user_id'])) {
Display :: display_error_message(get_lang('SurveyParametersMissingUseCopyPaste'), false);
@ -76,11 +95,16 @@ $invitationcode = $_GET['invitationcode'];
// Start auto-invitation feature FS#3403 (all-users-can-do-the-survey-URL handling)
if ($invitationcode == 'auto' && isset($_GET['scode'])) {
$userid = $_user['user_id'];
$surveyCode = Database::escape_string($_GET['scode']); // Survey_code of the survey
if ($isAnonymous) {
$autoInvitationcode = "auto-ANONY_".md5(time())."-$surveyCode";
} else {
// New invitation code from userid
$autoInvitationcode = "auto-$userid-$surveyCode";
}
$scode = Database::escape_string($_GET['scode']); // Survey_code of the survey
$autoInvitationcode = "auto-$userid-$scode"; // New invitation code from userid
// The survey code must exist in this course, or the URL is invalid
$sql = "SELECT * FROM $table_survey WHERE c_id = $course_id AND code ='".$scode."'";
$sql = "SELECT * FROM $table_survey WHERE c_id = $course_id AND code = '".$surveyCode."'";
$result = Database::query($sql);
if (Database :: num_rows($result) > 0) { // Ok
// Check availability
@ -92,7 +116,7 @@ if ($invitationcode == 'auto' && isset($_GET['scode'])) {
$result = Database::query($sql);
if (Database :: num_rows($result) == 0) { // Ok
$sql = "INSERT INTO $table_survey_invitation (c_id, survey_code,user, invitation_code, invitation_date) ";
$sql .= " VALUES ($course_id, \"$scode\", \"$userid\", \"$autoInvitationcode\", now())";
$sql .= " VALUES ($course_id, \"$surveyCode\", \"$userid\", \"$autoInvitationcode\", now())";
Database::query($sql);
}
// From here we use the new invitationcode auto-userid-surveycode string
@ -102,7 +126,10 @@ if ($invitationcode == 'auto' && isset($_GET['scode'])) {
}
// Now we check if the invitationcode is valid
$sql = "SELECT * FROM $table_survey_invitation WHERE c_id = $course_id AND invitation_code = '".Database :: escape_string($invitationcode)."'";
$sql = "SELECT * FROM $table_survey_invitation
WHERE
c_id = $course_id AND
invitation_code = '".Database :: escape_string($invitationcode)."'";
$result = Database::query($sql); // false = suppress errors
if (Database::num_rows($result) < 1) {
Display :: display_error_message(get_lang('WrongInvitationCode'), false);
@ -113,7 +140,7 @@ if (Database::num_rows($result) < 1) {
$survey_invitation = Database::fetch_array($result, 'ASSOC');
// Now we check if the user already filled the survey
if ($survey_invitation['answered'] == 1 && !isset($_GET['user_id'])) {
if ($isAnonymous && isset($_SESSION['surveyuser']) || ($survey_invitation['answered'] == 1 && !isset($_GET['user_id']))) {
Display :: display_error_message(get_lang('YouAlreadyFilledThisSurvey'), false);
Display :: display_footer();
exit;
@ -121,7 +148,10 @@ if ($survey_invitation['answered'] == 1 && !isset($_GET['user_id'])) {
// 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 c_id = $course_id AND code='".Database::escape_string($survey_invitation['survey_code'])."'";
$sql = "SELECT * FROM $table_survey
WHERE
c_id = $course_id AND
code='".Database::escape_string($survey_invitation['survey_code'])."'";
$result = Database::query($sql);
if (Database::num_rows($result) > 1) {
@ -152,15 +182,16 @@ $survey_data['survey_id'] = $survey_invitation['survey_id'];
if (count($_POST) > 0) {
if ($survey_data['survey_type'] === '0') {
// Getting all the types of the question (because of the special treatment of the score question type
$sql = "SELECT * FROM $table_survey_question WHERE c_id = $course_id AND survey_id = '".Database::escape_string($survey_invitation['survey_id'])."'";
$sql = "SELECT * FROM $table_survey_question
WHERE
c_id = $course_id AND
survey_id = '".Database::escape_string($survey_invitation['survey_id'])."'";
$result = Database::query($sql);
while ($row = Database::fetch_array($result, 'ASSOC')) {
$types[$row['question_id']] = $row['type'];
}
if ($survey_data['anonymous'] == 0) {
$survey_invitation['user'] = api_get_user_id();
}
// Looping through all the post values
foreach ($_POST as $key => & $value) {
// If the post value key contains the string 'question' then it is an answer on a question
@ -183,11 +214,13 @@ if (count($_POST) > 0) {
}
SurveyUtil::store_answer($survey_invitation['user'], $survey_invitation['survey_id'], $survey_question_id, $option_id, $option_value, $survey_data);
}
}
// All the other question types (open question, multiple choice, percentage, ...)
else {
} else {
// All the other question types (open question, multiple choice, percentage, ...)
if ($types[$survey_question_id] == 'percentage') {
$sql = "SELECT * FROM $table_survey_question_option WHERE c_id = $course_id AND question_option_id='".Database::escape_string($value)."'";
$sql = "SELECT * FROM $table_survey_question_option
WHERE
c_id = $course_id AND
question_option_id='".Database::escape_string($value)."'";
$result = Database::query($sql);
$row = Database::fetch_array($result, 'ASSOC');
$option_value = $row['option_text'];
@ -213,16 +246,16 @@ if (count($_POST) > 0) {
$shuffle = ' ORDER BY RAND() ';
}
$sql = "SELECT * FROM $table_survey_question
WHERE c_id = $course_id AND survey_id = '".Database::escape_string($survey_invitation['survey_id'])."'
AND survey_group_pri = '0' $shuffle";
WHERE
c_id = $course_id AND
survey_id = '".Database::escape_string($survey_invitation['survey_id'])."' AND
survey_group_pri = '0' $shuffle";
$result = Database::query($sql);
// There is only one question type for conditional surveys
while ($row = Database::fetch_array($result, 'ASSOC')) {
$types[$row['question_id']] = $row['type'];
}
if ($survey_data['anonymous'] == 0) {
$survey_invitation['user'] = api_get_user_id();
}
// Looping through all the post values
foreach ($_POST as $key => & $value) {
// If the post value key contains the string 'question' then it is an answer to a question
@ -288,8 +321,12 @@ if ($survey_data['form_fields'] != '' && $survey_data['anonymous'] == 0 && is_ar
}
// We use the same form as in auth/profile.php
$form = new FormValidator('profile', 'post', api_get_self()."?".str_replace('&show_form=1', '&show_form=1', $_SERVER['QUERY_STRING']), null,
array('style' => 'width: 75%; float: '.($text_dir == 'rtl' ? 'right;' : 'left;'))
$form = new FormValidator(
'profile',
'post',
api_get_self()."?".str_replace('&show_form=1', '&show_form=1', $_SERVER['QUERY_STRING']),
null,
array('style' => 'width: 75%; float: '.($text_dir == 'rtl' ? 'right;' : 'left;'))
);
if (api_is_western_name_order()) {
@ -498,27 +535,55 @@ if (isset($_GET['show']) || isset($_POST['personality'])) {
// Get the user into survey answer table (user or anonymus)
$my_user_id = ($survey_data['anonymous'] == 1) ? $_SESSION['surveyuser'] : api_get_user_id();
$sql = "SELECT survey_question.survey_group_sec1, survey_question.survey_group_sec2, survey_question.survey_group_pri,
survey_question.question_id, survey_question.survey_id, survey_question.survey_question, survey_question.display, survey_question.sort, survey_question.type, survey_question.max_value,
survey_question_option.question_option_id, survey_question_option.option_text, survey_question_option.sort as option_sort
FROM $table_survey_question survey_question
LEFT JOIN $table_survey_question_option survey_question_option
ON survey_question.question_id = survey_question_option.question_id AND survey_question_option.c_id = $course_id
WHERE survey_question.survey_id = '".Database :: escape_string($survey_invitation['survey_id'])."'
AND survey_question.question_id NOT IN (SELECT sa.question_id FROM ".$table_survey_answer." sa WHERE sa.user='".$my_user_id."') AND
survey_question.c_id = $course_id
ORDER BY survey_question.sort, survey_question_option.sort ASC";
$sql = "SELECT
survey_question.survey_group_sec1,
survey_question.survey_group_sec2,
survey_question.survey_group_pri,
survey_question.question_id,
survey_question.survey_id,
survey_question.survey_question,
survey_question.display,
survey_question.sort,
survey_question.type,
survey_question.max_value,
survey_question_option.question_option_id,
survey_question_option.option_text,
survey_question_option.sort as option_sort
FROM $table_survey_question survey_question
LEFT JOIN $table_survey_question_option survey_question_option
ON survey_question.question_id = survey_question_option.question_id AND survey_question_option.c_id = $course_id
WHERE
survey_question.survey_id = '".Database :: escape_string($survey_invitation['survey_id'])."' AND
survey_question.question_id NOT IN (
SELECT sa.question_id
FROM ".$table_survey_answer." sa
WHERE
sa.user='".$my_user_id."') AND
survey_question.c_id = $course_id
ORDER BY survey_question.sort, survey_question_option.sort ASC";
} else {
$sql = "SELECT survey_question.survey_group_sec1, survey_question.survey_group_sec2, survey_question.survey_group_pri,
survey_question.question_id, survey_question.survey_id, survey_question.survey_question, survey_question.display, survey_question.sort, survey_question.type, survey_question.max_value,
survey_question_option.question_option_id, survey_question_option.option_text, survey_question_option.sort as option_sort
FROM $table_survey_question survey_question
LEFT JOIN $table_survey_question_option survey_question_option
ON survey_question.question_id = survey_question_option.question_id AND survey_question_option.c_id = $course_id
WHERE survey_question.survey_id = '".Database::escape_string($survey_invitation['survey_id'])."' AND
survey_question.question_id IN (".implode(',', $paged_questions[$_GET['show']]).") AND
survey_question.c_id = $course_id
ORDER BY survey_question.sort, survey_question_option.sort ASC";
$sql = "SELECT
survey_question.survey_group_sec1,
survey_question.survey_group_sec2,
survey_question.survey_group_pri,
survey_question.question_id,
survey_question.survey_id,
survey_question.survey_question,
survey_question.display,
survey_question.sort,
survey_question.type,
survey_question.max_value,
survey_question_option.question_option_id,
survey_question_option.option_text,
survey_question_option.sort as option_sort
FROM $table_survey_question survey_question
LEFT JOIN $table_survey_question_option survey_question_option
ON survey_question.question_id = survey_question_option.question_id AND survey_question_option.c_id = $course_id
WHERE
survey_question.survey_id = '".Database::escape_string($survey_invitation['survey_id'])."' AND
survey_question.question_id IN (".implode(',', $paged_questions[$_GET['show']]).") AND
survey_question.c_id = $course_id
ORDER BY survey_question.sort, survey_question_option.sort ASC";
}
$result = Database::query($sql);
@ -538,9 +603,8 @@ if (isset($_GET['show']) || isset($_POST['personality'])) {
$questions[$row['sort']]['type'] = $row['type'];
$questions[$row['sort']]['options'][$row['question_option_id']] = $row['option_text'];
$questions[$row['sort']]['maximum_score'] = $row['max_value'];
}
// If the type is a pagebreak we are finished loading the questions for this page
else {
} else {
// If the type is a pagebreak we are finished loading the questions for this page
break;
}
$counter++;
@ -563,12 +627,14 @@ if (isset($_GET['show']) || isset($_POST['personality'])) {
// Get current user results
$results = array();
$sql = "SELECT survey_group_pri, user, SUM(value) as value
FROM $table_survey_answer as survey_answer INNER JOIN $table_survey_question as survey_question
ON (survey_question.question_id = survey_answer.question_id)
WHERE survey_answer.survey_id='".$my_survey_id."' AND
survey_answer.user='".$current_user."' AND
survey_answer.c_id = $course_id AND
survey_question.c_id = $course_id AND
FROM $table_survey_answer as survey_answer
INNER JOIN $table_survey_question as survey_question
ON (survey_question.question_id = survey_answer.question_id)
WHERE
survey_answer.survey_id='".$my_survey_id."' AND
survey_answer.user='".$current_user."' AND
survey_answer.c_id = $course_id AND
survey_question.c_id = $course_id AND
GROUP BY survey_group_pri
ORDER BY survey_group_pri
";
@ -585,16 +651,20 @@ if (isset($_GET['show']) || isset($_POST['personality'])) {
$totals = array();
$sql = "SELECT SUM(temp.value) as value, temp.survey_group_pri FROM
(
SELECT MAX(value) as value, survey_group_pri, survey_question.question_id
FROM $table_survey_question as survey_question
INNER JOIN $table_survey_question_option as survey_question_option
ON (survey_question.question_id = survey_question_option.question_id)
WHERE survey_question.survey_id='".$my_survey_id."' AND
survey_question.c_id = $course_id AND
survey_question_option.c_id = $course_id AND
survey_group_sec1='0' AND
survey_group_sec2='0'
GROUP BY survey_group_pri, survey_question.question_id
SELECT
MAX(value) as value,
survey_group_pri,
survey_question.question_id
FROM $table_survey_question as survey_question
INNER JOIN $table_survey_question_option as survey_question_option
ON (survey_question.question_id = survey_question_option.question_id)
WHERE
survey_question.survey_id='".$my_survey_id."' AND
survey_question.c_id = $course_id AND
survey_question_option.c_id = $course_id AND
survey_group_sec1='0' AND
survey_group_sec2='0'
GROUP BY survey_group_pri, survey_question.question_id
) as temp
GROUP BY temp.survey_group_pri
@ -754,9 +824,11 @@ if (isset($_GET['show']) || isset($_POST['personality'])) {
if (empty($_SESSION['page_questions_sec']) && !is_array($_SESSION['page_questions_sec']) && count($_SESSION['page_questions_sec'] == 0)) {
$sql = "SELECT * FROM $table_survey_question
WHERE c_id = $course_id AND survey_id = '".$my_survey_id."'
AND ($secondary )
ORDER BY sort ASC";
WHERE
c_id = $course_id AND
survey_id = '".$my_survey_id."' AND
($secondary )
ORDER BY sort ASC";
$result = Database::query($sql);
$counter = 0;
while ($row = Database::fetch_array($result, 'ASSOC')) {
@ -790,15 +862,28 @@ if (isset($_GET['show']) || isset($_POST['personality'])) {
//echo '<pre>'; print_r($paged_questions_sec); echo '</pre>';
if (is_array($paged_questions_sec)) {
$sql = "SELECT survey_question.survey_group_sec1, survey_question.survey_group_sec2, survey_question.survey_group_pri,
survey_question.question_id, survey_question.survey_id, survey_question.survey_question, survey_question.display, survey_question.sort, survey_question.type, survey_question.max_value,
survey_question_option.question_option_id, survey_question_option.option_text, survey_question_option.sort as option_sort
$sql = "SELECT
survey_question.survey_group_sec1,
survey_question.survey_group_sec2,
survey_question.survey_group_pri,
survey_question.question_id,
survey_question.survey_id,
survey_question.survey_question,
survey_question.display,
survey_question.sort,
survey_question.type,
survey_question.max_value,
survey_question_option.question_option_id,
survey_question_option.option_text,
survey_question_option.sort as option_sort
FROM $table_survey_question survey_question
LEFT JOIN $table_survey_question_option survey_question_option
ON survey_question.question_id = survey_question_option.question_id AND survey_question_option.c_id = $course_id
WHERE survey_question.survey_id = '".$my_survey_id."' AND
survey_question.c_id = $course_id AND
survey_question.question_id IN (".implode(',', $paged_questions_sec[$val]).")
ON survey_question.question_id = survey_question_option.question_id AND
survey_question_option.c_id = $course_id
WHERE
survey_question.survey_id = '".$my_survey_id."' AND
survey_question.c_id = $course_id AND
survey_question.question_id IN (".implode(',', $paged_questions_sec[$val]).")
ORDER $shuffle ";
$result = Database::query($sql);
@ -849,9 +934,12 @@ if (isset($_GET['show']) || isset($_POST['personality'])) {
if (empty($_SESSION['paged_questions'])) {
$sql = "SELECT * FROM $table_survey_question
WHERE c_id = $course_id AND survey_id = '".Database::escape_string($survey_invitation['survey_id'])."'
AND survey_group_sec1='0' AND survey_group_sec2='0'
ORDER ".$order_sql." ";
WHERE
c_id = $course_id AND
survey_id = '".Database::escape_string($survey_invitation['survey_id'])."' AND
survey_group_sec1='0' AND
survey_group_sec2='0'
ORDER ".$order_sql." ";
//echo '<br />'; echo '<br />';
$result = Database::query($sql);
$counter = 0;
@ -893,15 +981,28 @@ if (isset($_GET['show']) || isset($_POST['personality'])) {
if ($imploded != '') {
// The answers are always in the same order NO shuffle
$order_sql = ' BY survey_question.sort, survey_question_option.sort ASC ';
$sql = "SELECT survey_question.survey_group_sec1, survey_question.survey_group_sec2, survey_question.survey_group_pri,
survey_question.question_id, survey_question.survey_id, survey_question.survey_question, survey_question.display, survey_question.sort, survey_question.type, survey_question.max_value,
survey_question_option.question_option_id, survey_question_option.option_text, survey_question_option.sort as option_sort
$sql = "SELECT
survey_question.survey_group_sec1,
survey_question.survey_group_sec2,
survey_question.survey_group_pri,
survey_question.question_id,
survey_question.survey_id,
survey_question.survey_question,
survey_question.display,
survey_question.sort,
survey_question.type,
survey_question.max_value,
survey_question_option.question_option_id,
survey_question_option.option_text,
survey_question_option.sort as option_sort
FROM $table_survey_question survey_question
LEFT JOIN $table_survey_question_option survey_question_option
ON survey_question.question_id = survey_question_option.question_id AND survey_question_option.c_id = $course_id
WHERE survey_question.survey_id = '".Database :: escape_string($survey_invitation['survey_id'])."' AND
survey_question.c_id = $course_id AND
survey_question.question_id IN (".$imploded.")
ON survey_question.question_id = survey_question_option.question_id AND
survey_question_option.c_id = $course_id
WHERE
survey_question.survey_id = '".Database :: escape_string($survey_invitation['survey_id'])."' AND
survey_question.c_id = $course_id AND
survey_question.question_id IN (".$imploded.")
ORDER $order_sql ";
$result = Database::query($sql);
$question_counter_max = Database :: num_rows($result);
@ -940,7 +1041,11 @@ if (isset($_GET['show']) || isset($_POST['personality'])) {
}
// Selecting the maximum number of pages
$sql = "SELECT * FROM $table_survey_question WHERE c_id = $course_id AND type='".Database::escape_string('pagebreak')."' AND survey_id='".Database::escape_string($survey_invitation['survey_id'])."'";
$sql = "SELECT * FROM $table_survey_question
WHERE
c_id = $course_id AND
type='".Database::escape_string('pagebreak')."' AND
survey_id='".Database::escape_string($survey_invitation['survey_id'])."'";
$result = Database::query($sql);
$numberofpages = Database::num_rows($result) + 1;

@ -1,5 +1,4 @@
<?php
/* For licensing terms, see /license.txt */
$language_file = 'survey';
@ -17,8 +16,8 @@ if (empty($survey_id)) {
$survey_data = survey_manager::get_survey($survey_id);
$interbreadcrumb[] = array('url' => 'survey_list.php', 'name' => get_lang('SurveyList'));
$interbreadcrumb[] = array('url' => 'survey.php?survey_id='.$survey_id, 'name' => strip_tags($survey_data['title']));
$interbreadcrumb[] = array('url' => api_get_path(WEB_CODE_PATH).'survey/survey_list.php', 'name' => get_lang('SurveyList'));
$interbreadcrumb[] = array('url' => api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.$survey_id, 'name' => strip_tags($survey_data['title']));
Display::display_header(get_lang('Survey'), 'Survey');

@ -3,11 +3,6 @@
require_once '../inc/global.inc.php';
/*
if (!api_is_allowed_to_edit(false, true)) {
api_not_allowed(true);
}*/
$survey_id = isset($_REQUEST['i']) ? intval($_REQUEST['i']) : null;
if (empty($survey_id)) {
@ -41,4 +36,4 @@ if ($hash_is_valid && $course_info) {
}
} else {
api_not_allowed(true);
}
}

@ -26,14 +26,36 @@ $table_survey_question = Database :: get_course_table(TABLE_SURVEY_QUESTION);
$table_survey_question_option = Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION);
$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);
$course_id = api_get_course_int_id();
$userId = api_get_user_id();
$surveyId = Database::escape_string($_GET['survey_id']);
$userInvited = 0;
//query to ask if logged user is allowed to see the preview (if he is invited of he is a teacher)
$sql = "SELECT survey_invitation.user
FROM $table_survey_invitation survey_invitation
LEFT JOIN $table_survey survey
ON survey_invitation.survey_code = survey.code
WHERE
survey_invitation.c_id = $course_id AND
survey.survey_id = $surveyId AND
survey_invitation.user = $userId";
$result = Database::query($sql);
if (Database::num_rows($result) > 0) {
$userInvited = 1;
}
if ($userInvited == 0) {
if(!api_is_allowed_to_edit()) {
api_not_allowed();
}
}
// We exit here if ther is no valid $_GET parameter
if (!isset($_GET['survey_id']) || !is_numeric($_GET['survey_id'])){
Display :: display_header(get_lang('SurveyPreview'));
Display :: display_error_message(get_lang('InvallidSurvey'), false);
Display :: display_footer();
Display::display_header(get_lang('SurveyPreview'));
Display::display_error_message(get_lang('InvallidSurvey'), false);
Display::display_footer();
exit;
}
@ -42,22 +64,17 @@ $survey_id = intval($_GET['survey_id']);
$survey_data = survey_manager::get_survey($survey_id);
if (empty($survey_data)) {
Display :: display_header(get_lang('SurveyPreview'));
Display :: display_error_message(get_lang('InvallidSurvey'), false);
Display :: display_footer();
Display::display_header(get_lang('SurveyPreview'));
Display::display_error_message(get_lang('InvallidSurvey'), false);
Display::display_footer();
exit;
}
/*$urlname = strip_tags(api_substr(api_html_entity_decode($survey_data['title'], ENT_QUOTES), 0, 40));
if (api_strlen(strip_tags($survey_data['title'])) > 40) {
$urlname .= '...';
}*/
$urlname = strip_tags($survey_data['title']);
// Breadcrumbs
$interbreadcrumb[] = array('url' => 'survey_list.php', 'name' => get_lang('SurveyList'));
$interbreadcrumb[] = array('url' => 'survey.php?survey_id='.$survey_id, 'name' => $urlname);
$interbreadcrumb[] = array('url' => api_get_path(WEB_CODE_PATH).'survey/survey_list.php', 'name' => get_lang('SurveyList'));
$interbreadcrumb[] = array('url' => api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.$survey_id, 'name' => $urlname);
// Header
Display :: display_header(get_lang('SurveyPreview'));
@ -65,9 +82,14 @@ Display :: display_header(get_lang('SurveyPreview'));
// We exit here is the first or last question is a pagebreak (which causes errors)
SurveyUtil::check_first_last_question($survey_id, false);
$counter_question = 0;
$questions = array();
// Only a course admin is allowed to preview a survey: you are NOT a course admin => error message
/*
if (!api_is_allowed_to_edit(false, true)) {
Display :: display_error_message(get_lang('NotAllowed'), false);
}*/
$counter_question = 0;
// Only a course admin is allowed to preview a survey: you are a course admin
if (api_is_course_admin() || (api_is_course_admin() && $_GET['isStudentView'] == 'true') || api_is_allowed_to_session_edit(false, true)) {
// Survey information
@ -90,6 +112,8 @@ if (api_is_course_admin() || (api_is_course_admin() && $_GET['isStudentView'] ==
exit;
}
$questions = array();
if (isset($_GET['show'])) {
// Getting all the questions for this page and add them to a multidimensional array where the first index is the page.
// as long as there is no pagebreak fount we keep adding questions to the page
@ -114,13 +138,24 @@ if (api_is_course_admin() || (api_is_course_admin() && $_GET['isStudentView'] ==
}
if (array_key_exists($_GET['show'], $paged_questions)) {
$sql = "SELECT survey_question.question_id, survey_question.survey_id, survey_question.survey_question, survey_question.display, survey_question.sort, survey_question.type, survey_question.max_value,
survey_question_option.question_option_id, survey_question_option.option_text, survey_question_option.sort as option_sort
FROM $table_survey_question survey_question LEFT JOIN $table_survey_question_option survey_question_option
$sql = "SELECT
survey_question.question_id,
survey_question.survey_id,
survey_question.survey_question,
survey_question.display,
survey_question.sort,
survey_question.type,
survey_question.max_value,
survey_question_option.question_option_id,
survey_question_option.option_text,
survey_question_option.sort as option_sort
FROM $table_survey_question survey_question
LEFT JOIN $table_survey_question_option survey_question_option
ON survey_question.question_id = survey_question_option.question_id AND survey_question_option.c_id = $course_id
WHERE survey_question.survey_id = '".Database::escape_string($survey_id)."' AND
survey_question.question_id IN (".Database::escape_string(implode(',',$paged_questions[$_GET['show']])).") AND
survey_question.c_id = $course_id
WHERE
survey_question.survey_id = '".Database::escape_string($survey_id)."' AND
survey_question.question_id IN (".Database::escape_string(implode(',',$paged_questions[$_GET['show']])).") AND
survey_question.c_id = $course_id
ORDER BY survey_question.sort, survey_question_option.sort ASC";
$result = Database::query($sql);
@ -145,8 +180,13 @@ if (api_is_course_admin() || (api_is_course_admin() && $_GET['isStudentView'] ==
}
}
}
// Selecting the maximum number of pages
$sql = "SELECT * FROM $table_survey_question WHERE c_id = $course_id AND type='".Database::escape_string('pagebreak')."' AND survey_id='".Database::escape_string($survey_id)."'";
$sql = "SELECT * FROM $table_survey_question
WHERE
c_id = $course_id AND
type='".Database::escape_string('pagebreak')."' AND
survey_id='".Database::escape_string($survey_id)."'";
$result = Database::query($sql);
$numberofpages = Database::num_rows($result) + 1;
// Displaying the form with the questions
@ -155,9 +195,10 @@ if (api_is_course_admin() || (api_is_course_admin() && $_GET['isStudentView'] ==
} else {
$show = 0;
}
echo '<form id="question" name="question" method="post" action="'.api_get_self().'?survey_id='.Security::remove_XSS($survey_id).'&show='.$show.'">';
if (isset($questions) && is_array($questions) && count($questions) > 0) {
if (is_array($questions) && count($questions) > 0) {
foreach ($questions as $key => & $question) {
$ch_type = 'ch_'.$question['type'];
$display = new $ch_type;

@ -22,8 +22,7 @@ $(document).ready( function() {
$("button").click(function() {
$("#is_executable").attr("value",$(this).attr("name"));
});
});
</script>';
} ); </script>';
/** @todo this has to be moved to a more appropriate place (after the display_header of the code)*/
if (!api_is_allowed_to_edit(false, true)) {
@ -35,7 +34,6 @@ if (!api_is_allowed_to_edit(false, true)) {
// Is valid request
$is_valid_request = isset($_REQUEST['is_executable']) ? $_REQUEST['is_executable'] : null;
if ($request_index != $is_valid_request) {
if ($request_index == 'save_question') {
unset($_POST[$request_index]);
@ -72,17 +70,20 @@ if (api_strlen(strip_tags($survey_data['title'])) > 40) {
}
if ($survey_data['survey_type'] == 1) {
$sql = 'SELECT id FROM '.Database :: get_course_table(TABLE_SURVEY_QUESTION_GROUP).' WHERE c_id = '.$course_id.' AND survey_id = '.(int)$_GET['survey_id'].' LIMIT 1';
$sql = 'SELECT id FROM '.Database :: get_course_table(TABLE_SURVEY_QUESTION_GROUP).'
WHERE
c_id = '.$course_id.' AND
survey_id = '.(int)$_GET['survey_id'].' LIMIT 1';
$rs = Database::query($sql);
if(Database::num_rows($rs)===0) {
header('Location: survey.php?survey_id='.(int)$_GET['survey_id'].'&message='.'YouNeedToCreateGroups');
header('Location: '.api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.(int)$_GET['survey_id'].'&message='.'YouNeedToCreateGroups');
exit;
}
}
// Breadcrumbs
$interbreadcrumb[] = array ('url' => 'survey_list.php', 'name' => get_lang('SurveyList'));
$interbreadcrumb[] = array ('url' => 'survey.php?survey_id='.Security::remove_XSS($_GET['survey_id']), 'name' => strip_tags($urlname));
$interbreadcrumb[] = array ('url' => api_get_path(WEB_CODE_PATH).'survey/survey_list.php', 'name' => get_lang('SurveyList'));
$interbreadcrumb[] = array ('url' => api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.Security::remove_XSS($_GET['survey_id']), 'name' => strip_tags($urlname));
// Tool name
if ($_GET['action'] == 'add') {
@ -97,7 +98,7 @@ $possible_types = array('personality', 'yesno', 'multiplechoice', 'multiplerespo
// Actions
$actions = '<div class="actions">';
$actions .= '<a href="survey.php?survey_id='.Security::remove_XSS($_GET['survey_id']).'">'.Display::return_icon('back.png', get_lang('BackToSurvey'),'',ICON_SIZE_MEDIUM).'</a>';
$actions .= '<a href="'.api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.Security::remove_XSS($_GET['survey_id']).'">'.Display::return_icon('back.png', get_lang('BackToSurvey'),'',ICON_SIZE_MEDIUM).'</a>';
$actions .= '</div>';
// Checking if it is a valid type
if (!in_array($_GET['type'], $possible_types)) {
@ -118,7 +119,11 @@ if (empty($_POST['save_question']) && in_array($_GET['type'], $possible_types))
if (isset($_SESSION['temp_sys_message'])) {
$error_message=$_SESSION['temp_sys_message'];
unset($_SESSION['temp_sys_message']);
if ($error_message == 'PleaseEnterAQuestion' || $error_message == 'PleasFillAllAnswer'|| $error_message == 'PleaseChooseACondition'|| $error_message == 'ChooseDifferentCategories') {
if ($error_message == 'PleaseEnterAQuestion' ||
$error_message == 'PleasFillAllAnswer'||
$error_message == 'PleaseChooseACondition'||
$error_message == 'ChooseDifferentCategories'
) {
Display::display_error_message(get_lang($error_message), true);
}
}
@ -156,7 +161,10 @@ if (empty($_POST['save_question']) && in_array($_GET['type'], $possible_types))
// An action has been performed (for instance adding a possible answer, moving an answer, ...)
if ($_POST) {
$form_content = $_POST;
$form_content = $form->handle_action($form_content);
$form_content = $form->handle_action(
$survey_data,
$form_content
);
}
if ($error_message != '') {
@ -171,12 +179,12 @@ if (empty($_POST['save_question']) && in_array($_GET['type'], $possible_types))
unset($_SESSION['temp_horizontalvertical']);
}
$form->create_form($form_content);
$form->create_form($survey_data, $form_content);
$form->render_form();
} else {
$form_content = $_POST;
$form = new survey_question();
$form->handle_action($form_content);
$form->handle_action($survey_data, $form_content);
}
// Footer

@ -17,7 +17,6 @@ $language_file = 'survey';
require_once '../inc/global.inc.php';
require_once 'survey.lib.php';
$this_section = SECTION_COURSES;
$survey_id = intval($_GET['survey_id']);
// Export
@ -25,17 +24,17 @@ $survey_id = intval($_GET['survey_id']);
* @todo use export_table_csv($data, $filename = 'export')
*/
if (isset($_POST['export_report']) && $_POST['export_report']) {
switch($_POST['export_format']) {
switch ($_POST['export_format']) {
case 'xls':
$survey_data = survey_manager::get_survey($survey_id);
$filename = 'survey_results_'.$survey_id.'.xls';
$data = SurveyUtil::export_complete_report_xls($filename, $_GET['user_id']);
$data = SurveyUtil::export_complete_report_xls($survey_data, $filename, $_GET['user_id']);
exit;
break;
case 'csv':
default:
$survey_data = survey_manager::get_survey($survey_id);
$data = SurveyUtil::export_complete_report($_GET['user_id']);
$data = SurveyUtil::export_complete_report($survey_data, $_GET['user_id']);
//$filename = 'fileexport.csv';
$filename = 'survey_results_'.$survey_id.'.csv';
@ -61,8 +60,19 @@ if (isset($_POST['export_report']) && $_POST['export_report']) {
}
}
if ($survey_data['anonymous'] == 0) {
$people_filled_full_data = true;
} else {
$people_filled_full_data = false;
}
$people_filled = survey_manager::get_people_who_filled_survey(
$_GET['survey_id'],
$people_filled_full_data
);
// Checking the parameters
SurveyUtil::check_parameters();
SurveyUtil::check_parameters($people_filled);
/** @todo this has to be moved to a more appropriate place (after the display_header of the code)*/
if (!api_is_allowed_to_edit(false, true)) {
@ -92,12 +102,15 @@ if (api_strlen(strip_tags($survey_data['title'])) > 40) {
}
// Breadcrumbs
$interbreadcrumb[] = array('url' => 'survey_list.php', 'name' => get_lang('SurveyList'));
$interbreadcrumb[] = array('url' => 'survey.php?survey_id='.$survey_id, 'name' => $urlname);
$interbreadcrumb[] = array('url' => api_get_path(WEB_CODE_PATH).'survey/survey_list.php', 'name' => get_lang('SurveyList'));
$interbreadcrumb[] = array('url' => api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.$survey_id, 'name' => $urlname);
if (!$_GET['action'] OR $_GET['action'] == 'overview') {
$tool_name = get_lang('Reporting');
} else {
$interbreadcrumb[] = array('url' => 'reporting.php?survey_id='.$survey_id, 'name' => get_lang('Reporting'));
$interbreadcrumb[] = array(
'url' => api_get_path(WEB_CODE_PATH).'survey/reporting.php?survey_id='.$survey_id,
'name' => get_lang('Reporting')
);
switch ($_GET['action']) {
case 'questionreport':
$tool_name = get_lang('DetailedReportByQuestion');
@ -118,19 +131,20 @@ if (!$_GET['action'] OR $_GET['action'] == 'overview') {
Display::display_header($tool_name, 'Survey');
// Action handling
SurveyUtil::handle_reporting_actions();
SurveyUtil::handle_reporting_actions($people_filled);
// Actions bar
echo '<div class="actions">';
echo '<a href="survey.php?survey_id='.$survey_id.'">'.Display::return_icon('back.png', get_lang('BackToSurvey'),'',ICON_SIZE_MEDIUM).'</a>';
echo '<a href="'.api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.$survey_id.'">'.
Display::return_icon('back.png', get_lang('BackToSurvey'),'',ICON_SIZE_MEDIUM).'</a>';
echo '</div>';
// Content
if (!$_GET['action'] || $_GET['action'] == 'overview') {
$myweb_survey_id = $survey_id;
echo '<div class="sectiontitle"><a href="reporting.php?action=questionreport&amp;survey_id='.$myweb_survey_id.'">'.Display::return_icon('survey_reporting_question.gif',get_lang('DetailedReportByQuestion')).' '.get_lang('DetailedReportByQuestion').'</a></div><div class="sectioncomment">'.get_lang('DetailedReportByQuestionDetail').' </div>';
echo '<div class="sectiontitle"><a href="reporting.php?action=userreport&amp;survey_id='.$myweb_survey_id.'">'.Display::return_icon('survey_reporting_user.gif',get_lang('DetailedReportByUser')).' '.get_lang('DetailedReportByUser').'</a></div><div class="sectioncomment">'.get_lang('DetailedReportByUserDetail').'.</div>';
echo '<div class="sectiontitle"><a href="reporting.php?action=comparativereport&amp;survey_id='.$myweb_survey_id.'">'.Display::return_icon('survey_reporting_comparative.gif',get_lang('ComparativeReport')).' '.get_lang('ComparativeReport').'</a></div><div class="sectioncomment">'.get_lang('ComparativeReportDetail').'.</div>';
echo '<div class="sectiontitle"><a href="'.api_get_path(WEB_CODE_PATH).'survey/reporting.php?action=questionreport&amp;survey_id='.$myweb_survey_id.'">'.Display::return_icon('survey_reporting_question.gif',get_lang('DetailedReportByQuestion')).' '.get_lang('DetailedReportByQuestion').'</a></div><div class="sectioncomment">'.get_lang('DetailedReportByQuestionDetail').' </div>';
echo '<div class="sectiontitle"><a href="'.api_get_path(WEB_CODE_PATH).'survey/reporting.php?action=userreport&amp;survey_id='.$myweb_survey_id.'">'.Display::return_icon('survey_reporting_user.gif',get_lang('DetailedReportByUser')).' '.get_lang('DetailedReportByUser').'</a></div><div class="sectioncomment">'.get_lang('DetailedReportByUserDetail').'.</div>';
echo '<div class="sectiontitle"><a href="'.api_get_path(WEB_CODE_PATH).'survey/reporting.php?action=comparativereport&amp;survey_id='.$myweb_survey_id.'">'.Display::return_icon('survey_reporting_comparative.gif',get_lang('ComparativeReport')).' '.get_lang('ComparativeReport').'</a></div><div class="sectioncomment">'.get_lang('ComparativeReportDetail').'.</div>';
echo '<div class="sectiontitle"><a href="reporting.php?action=completereport&amp;survey_id='.$myweb_survey_id.'">'.Display::return_icon('survey_reporting_complete.gif',get_lang('CompleteReport')).' '.get_lang('CompleteReport').'</a></div><div class="sectioncomment">'.get_lang('CompleteReportDetail').'</div>';
}

@ -26,7 +26,10 @@ function check_download_survey($course, $invitation, $doc_url) {
$table_survey_invitation = Database :: get_course_table(TABLE_SURVEY_INVITATION);
// Now we check if the invitationcode is valid
$sql = "SELECT * FROM $table_survey_invitation WHERE c_id = $course_id AND invitation_code = '".Database::escape_string($invitation)."'";
$sql = "SELECT * FROM $table_survey_invitation
WHERE
c_id = $course_id AND
invitation_code = '".Database::escape_string($invitation)."'";
$result = Database::query($sql);
if (Database::num_rows($result) < 1) {
Display :: display_error_message(get_lang('WrongInvitationCode'), false);
@ -47,13 +50,16 @@ function check_download_survey($course, $invitation, $doc_url) {
// Fetch survey ID
// If this is the case there will be a language choice
$sql = "SELECT * FROM $table_survey WHERE c_id = $course_id AND code='".Database::escape_string($survey_invitation['survey_code'])."'";
$sql = "SELECT * FROM $table_survey
WHERE
c_id = $course_id AND
code='".Database::escape_string($survey_invitation['survey_code'])."'";
$result = Database::query($sql);
if (Database::num_rows($result) > 1) {
if ($_POST['language']) {
$survey_invitation['survey_id'] = $_POST['language'];
} else {
echo '<form id="language" name="language" method="POST" action="'.api_get_self().'?course='.Security::remove_XSS($_GET['course']).'&invitationcode='.Security::remove_XSS($_GET['invitationcode']).'">';
echo '<form id="language" name="language" method="POST" action="'.api_get_self().'?course='.$_GET['course'].'&invitationcode='.$_GET['invitationcode'].'">';
echo ' <select name="language">';
while ($row = Database::fetch_assoc($result)) {
echo '<option value="'.$row['survey_id'].'">'.$row['lang'].'</option>';
@ -69,22 +75,33 @@ function check_download_survey($course, $invitation, $doc_url) {
$survey_invitation['survey_id'] = $row['survey_id'];
}
$sql = "SELECT count(*) FROM $table_survey WHERE c_id = $course_id AND survey_id = ".$survey_invitation['survey_id']."
and (
title LIKE '%$doc_url%'
or subtitle LIKE '%$doc_url%'
or intro LIKE '%$doc_url%'
or surveythanks LIKE '%$doc_url%'
)
union select count(*) from $table_survey_question where c_id = $course_id AND survey_id = ".$survey_invitation['survey_id']."
and (
survey_question LIKE '%$doc_url%'
or survey_question_comment LIKE '%$doc_url%'
)
union select count(*) from $table_survey_question_option where c_id = $course_id AND survey_id = ".$survey_invitation['survey_id']."
and (
option_text LIKE '%$doc_url%'
)";
$sql = "SELECT count(*)
FROM $table_survey
WHERE
c_id = $course_id AND
survey_id = ".$survey_invitation['survey_id']." AND (
title LIKE '%$doc_url%'
or subtitle LIKE '%$doc_url%'
or intro LIKE '%$doc_url%'
or surveythanks LIKE '%$doc_url%'
)
UNION
SELECT count(*)
FROM $table_survey_question
WHERE
c_id = $course_id AND
survey_id = ".$survey_invitation['survey_id']." AND (
survey_question LIKE '%$doc_url%'
or survey_question_comment LIKE '%$doc_url%'
)
UNION
SELECT count(*)
FROM $table_survey_question_option
WHERE
c_id = $course_id AND
survey_id = ".$survey_invitation['survey_id']." AND (
option_text LIKE '%$doc_url%'
)";
$result = Database::query($sql);
if (Database::num_rows($result) == 0) {
Display :: display_error_message(get_lang('WrongInvitationCode'), false);

File diff suppressed because it is too large Load Diff

@ -2,12 +2,13 @@
/* For licensing terms, see /license.txt */
/**
* @package chamilo.survey
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University: cleanup, refactoring and rewriting large parts of the code
* @package chamilo.survey
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University: cleanup, refactoring and rewriting large parts of the code
* @version $Id: survey.php 22573 2009-08-03 03:38:13Z yannoo $
*
* @todo use quickforms for the forms
*/
// Language file that needs to be included
$language_file = 'survey';
@ -15,49 +16,49 @@ $language_file = 'survey';
require_once '../inc/global.inc.php';
$this_section = SECTION_COURSES;
$current_course_tool = TOOL_SURVEY;
$current_course_tool = TOOL_SURVEY;
api_protect_course_script(true);
// Including additional libraries
require_once 'survey.lib.php';
/** @todo this has to be moved to a more appropriate place (after the display_header of the code) */
/** @todo this has to be moved to a more appropriate place (after the display_header of the code)*/
// Coach can't view this page
$extend_rights_for_coachs = api_get_setting('extend_rights_for_coach_on_survey');
if (!api_is_allowed_to_edit(false, true) || (api_is_course_coach() && $extend_rights_for_coachs == 'false')) {
Display :: display_header(get_lang('ToolSurvey'));
Display :: display_error_message(get_lang('NotAllowed'), false);
Display :: display_footer();
exit;
Display :: display_header(get_lang('ToolSurvey'));
Display :: display_error_message(get_lang('NotAllowed'), false);
Display :: display_footer();
exit;
}
// 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);
$table_survey_question_group = Database :: get_course_table(TABLE_SURVEY_QUESTION_GROUP);
$table_course = Database :: get_main_table(TABLE_MAIN_COURSE);
$table_user = Database :: get_main_table(TABLE_MAIN_USER);
$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);
$table_survey_question_group = Database :: get_course_table(TABLE_SURVEY_QUESTION_GROUP);
$table_course = Database :: get_main_table(TABLE_MAIN_COURSE);
$table_user = Database :: get_main_table(TABLE_MAIN_USER);
$survey_id = intval($_GET['survey_id']);
$course_id = api_get_course_int_id();
$action = isset($_GET['action']) ? $_GET['action'] : null;
// Breadcrumbs
$interbreadcrumb[] = array('url' => 'survey_list.php', 'name' => get_lang('SurveyList'));
$interbreadcrumb[] = array ('url' => api_get_path(WEB_CODE_PATH).'survey/survey_list.php', 'name' => get_lang('SurveyList'));
// Getting the survey information
if (isset($_GET['survey_id'])) {
$course_code = api_get_course_id();
if ($course_code != -1) {
$survey_data = survey_manager::get_survey($survey_id);
} else {
Display :: display_header(get_lang('ToolSurvey'));
Display :: display_error_message(get_lang('NotAllowed'), false);
Display :: display_footer();
exit;
}
$course_code = api_get_course_id();
if ($course_code!=-1) {
$survey_data = survey_manager::get_survey($survey_id);
} else {
Display :: display_header(get_lang('ToolSurvey'));
Display :: display_error_message(get_lang('NotAllowed'), false);
Display :: display_footer();
exit;
}
}
$tool_name = strip_tags($survey_data['title']);
@ -65,32 +66,33 @@ $tool_name = strip_tags($survey_data['title']);
$is_survey_type_1 = $survey_data['survey_type'] == 1;
if (api_strlen(strip_tags($survey_data['title'])) > 40) {
$tool_name .= '...';
$tool_name .= '...';
}
if ($is_survey_type_1 && $action == 'addgroup' || $action == 'deletegroup') {
$_POST['name'] = trim($_POST['name']);
if ($action == 'addgroup') {
if (!empty($_POST['group_id'])) {
Database::query('UPDATE '.$table_survey_question_group.' SET description = \''.Database::escape_string($_POST['description']).'\'
if ($is_survey_type_1 &&
isset($_GET['action']) &&
($_GET['action'] == 'addgroup' || $_GET['action'] == 'deletegroup')
) {
$_POST['name'] = trim($_POST['name']);
if ($_GET['action'] == 'addgroup') {
if (!empty($_POST['group_id'])) {
Database::query('UPDATE '.$table_survey_question_group.' SET description = \''.Database::escape_string($_POST['description']).'\'
WHERE c_id = '.$course_id.' AND id = \''.Database::escape_string($_POST['group_id']).'\'');
$sendmsg = 'GroupUpdatedSuccessfully';
} elseif (!empty($_POST['name'])) {
Database::query('INSERT INTO '.$table_survey_question_group.' (c_id, name,description,survey_id) values ('.$course_id.', \''.Database::escape_string($_POST['name']).'\',\''.Database::escape_string($_POST['description']).'\',\''.Database::escape_string($survey_id).'\') ');
$sendmsg = 'GroupCreatedSuccessfully';
} else {
$sendmsg = 'GroupNeedName';
}
}
if ($action == 'deletegroup') {
Database::query('DELETE FROM '.$table_survey_question_group.' WHERE c_id = '.$course_id.' AND id = '.Database::escape_string($_GET['gid']).' and survey_id = '.Database::escape_string($survey_id));
$sendmsg = 'GroupDeletedSuccessfully';
}
header('Location:survey.php?survey_id='.$survey_id.'&sendmsg='.$sendmsg);
exit;
$sendmsg = 'GroupUpdatedSuccessfully';
} elseif(!empty($_POST['name'])) {
Database::query('INSERT INTO '.$table_survey_question_group.' (c_id, name,description,survey_id) values ('.$course_id.', \''.Database::escape_string($_POST['name']).'\',\''.Database::escape_string($_POST['description']).'\',\''.Database::escape_string($survey_id).'\') ');
$sendmsg = 'GroupCreatedSuccessfully';
} else {
$sendmsg = 'GroupNeedName';
}
}
if ($_GET['action'] == 'deletegroup'){
Database::query('DELETE FROM '.$table_survey_question_group.' WHERE c_id = '.$course_id.' AND id = '.Database::escape_string($_GET['gid']).' and survey_id = '.Database::escape_string($survey_id));
$sendmsg = 'GroupDeletedSuccessfully';
}
header('Location: '.api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.$survey_id.'&sendmsg='.$sendmsg);
exit;
}
// Displaying the header
@ -98,69 +100,65 @@ if ($is_survey_type_1 && $action == 'addgroup' || $action == 'deletegroup') {
Display::display_header($tool_name, 'Survey');
// Action handling
$my_action_survey = Security::remove_XSS($action);
$my_question_id_survey = Security::remove_XSS($_GET['question_id']);
$my_survey_id_survey = Security::remove_XSS($_GET['survey_id']);
$message_information = Security::remove_XSS($_GET['message']);
if (isset($action)) {
if (($action == 'moveup' || $action == 'movedown') && isset($_GET['question_id'])) {
survey_manager::move_survey_question($my_action_survey, $my_question_id_survey, $my_survey_id_survey);
Display::display_confirmation_message(get_lang('SurveyQuestionMoved'));
}
if ($action == 'delete' AND is_numeric($_GET['question_id'])) {
survey_manager::delete_survey_question($my_survey_id_survey, $my_question_id_survey, $survey_data['is_shared']);
}
$my_action_survey = isset($_GET['action']) ? Security::remove_XSS($_GET['action']) : null;
$my_question_id_survey = isset($_GET['question_id']) ? Security::remove_XSS($_GET['question_id']) : null;
$my_survey_id_survey = Security::remove_XSS($_GET['survey_id']);
$message_information = isset($_GET['message']) ? Security::remove_XSS($_GET['message']) : null;
if (isset($_GET['action'])) {
if (($_GET['action'] == 'moveup' || $_GET['action'] == 'movedown') && isset($_GET['question_id'])) {
survey_manager::move_survey_question($my_action_survey,$my_question_id_survey,$my_survey_id_survey);
Display::display_confirmation_message(get_lang('SurveyQuestionMoved'));
}
if ($_GET['action'] == 'delete' AND is_numeric($_GET['question_id'])) {
survey_manager::delete_survey_question($my_survey_id_survey, $my_question_id_survey, $survey_data['is_shared']);
}
}
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($message_information).', '.PHP_EOL.api_strtolower(get_lang('YouCanNowAddQuestionToYourSurvey')));
}
// We have added a question
if (in_array($_GET['message'], array('QuestionAdded', 'QuestionUpdated'))) {
Display::display_confirmation_message(get_lang($message_information));
}
if (in_array($_GET['message'], array('YouNeedToCreateGroups'))) {
Display::display_warning_message(get_lang($message_information), false);
}
// We have created the survey or updated the survey
if (in_array($_GET['message'], array('SurveyUpdatedSuccesfully','SurveyCreatedSuccesfully'))) {
Display::display_confirmation_message(get_lang($message_information).', '.PHP_EOL.api_strtolower(get_lang('YouCanNowAddQuestionToYourSurvey')));
}
// We have added a question
if (in_array($_GET['message'], array('QuestionAdded', 'QuestionUpdated'))) {
Display::display_confirmation_message(get_lang($message_information));
}
if (in_array($_GET['message'], array('YouNeedToCreateGroups'))) {
Display::display_warning_message(get_lang($message_information), false);
}
}
if (!empty($survey_data['survey_version']))
echo '<b>'.get_lang('Version').': '.$survey_data['survey_version'].'</b>';
if (!empty($survey_data['survey_version'])) echo '<b>'.get_lang('Version').': '.$survey_data['survey_version'].'</b>';
// We exit here is the first or last question is a pagebreak (which causes errors)
SurveyUtil::check_first_last_question($_GET['survey_id']);
// Action links
$survey_actions = '<a href="create_new_survey.php?'.api_get_cidreq().'&amp;action=edit&amp;survey_id='.$survey_id.'">'.Display::return_icon('edit.png', get_lang('EditSurvey'), '', ICON_SIZE_MEDIUM).'</a>';
$survey_actions .= '<a href="survey_list.php?'.api_get_cidreq().'&amp;action=delete&amp;survey_id='.$survey_id.'" onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang('DeleteSurvey').'?', ENT_QUOTES)).'\')) return false;">'.Display::return_icon('delete.png', get_lang('DeleteSurvey'), '', ICON_SIZE_MEDIUM).'</a>';
//$survey_actions .= '<a href="create_survey_in_another_language.php?id_survey='.$survey_id.'">'.Display::return_icon('copy.gif', get_lang('Copy')).'</a>';
$survey_actions .= '<a href="preview.php?'.api_get_cidreq().'&amp;survey_id='.$survey_id.'">'.Display::return_icon('preview_view.png', get_lang('Preview'), '', ICON_SIZE_MEDIUM).'</a>';
$survey_actions .= '<a href="survey_invite.php?'.api_get_cidreq().'&amp;survey_id='.$survey_id.'">'.Display::return_icon('mail_send.png', get_lang('Publish'), '', ICON_SIZE_MEDIUM).'</a>';
$survey_actions .= '<a href="reporting.php?'.api_get_cidreq().'&amp;survey_id='.$survey_id.'">'.Display::return_icon('stats.png', get_lang('Reporting'), '', ICON_SIZE_MEDIUM).'</a>';
$survey_actions = '<a href="'.api_get_path(WEB_CODE_PATH).'survey/create_new_survey.php?'.api_get_cidreq().'&amp;action=edit&amp;survey_id='.$survey_id.'">'.Display::return_icon('edit.png', get_lang('EditSurvey'),'',ICON_SIZE_MEDIUM).'</a>';
$survey_actions .= '<a href="'.api_get_path(WEB_CODE_PATH).'survey/survey_list.php?'.api_get_cidreq().'&amp;action=delete&amp;survey_id='.$survey_id.'" onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang('DeleteSurvey').'?', ENT_QUOTES)).'\')) return false;">'.Display::return_icon('delete.png', get_lang('DeleteSurvey'),'',ICON_SIZE_MEDIUM).'</a>';
//$survey_actions .= '<a href="'.api_get_path(WEB_CODE_PATH).'survey/create_survey_in_another_language.php?id_survey='.$survey_id.'">'.Display::return_icon('copy.gif', get_lang('Copy')).'</a>';
$survey_actions .= '<a href="'.api_get_path(WEB_CODE_PATH).'survey/preview.php?'.api_get_cidreq().'&amp;survey_id='.$survey_id.'">'.Display::return_icon('preview_view.png', get_lang('Preview'),'',ICON_SIZE_MEDIUM).'</a>';
$survey_actions .= '<a href="'.api_get_path(WEB_CODE_PATH).'survey/survey_invite.php?'.api_get_cidreq().'&amp;survey_id='.$survey_id.'">'.Display::return_icon('mail_send.png', get_lang('Publish'),'',ICON_SIZE_MEDIUM).'</a>';
$survey_actions .= '<a href="'.api_get_path(WEB_CODE_PATH).'survey/reporting.php?'.api_get_cidreq().'&amp;survey_id='.$survey_id.'">'.Display::return_icon('stats.png', get_lang('Reporting'),'',ICON_SIZE_MEDIUM).'</a>';
echo '<div class="actions">'.$survey_actions.'</div>';
if ($survey_data['survey_type'] == 0) {
echo '<div class="actionsbig">';
echo '<a style="padding-left:0px;" href="question.php?'.api_get_cidreq().'&amp;action=add&type=yesno&amp;survey_id='.$survey_id.'">'.Display::return_icon('yesno.gif', get_lang('YesNo')).'</a>';
echo '<a href="question.php?'.api_get_cidreq().'&amp;action=add&type=multiplechoice&amp;survey_id='.$survey_id.'">'.Display::return_icon('mcua.gif', get_lang('UniqueSelect')).'<br /></a>';
echo '<a href="question.php?'.api_get_cidreq().'&amp;action=add&type=multipleresponse&amp;survey_id='.$survey_id.'">'.Display::return_icon('mcma.gif', get_lang('MultipleResponse')).'</a>';
echo '<a href="question.php?'.api_get_cidreq().'&amp;action=add&type=open&amp;survey_id='.$survey_id.'">'.Display::return_icon('open_answer.gif', get_lang('Open')).'<br /></a>';
echo '<a href="question.php?'.api_get_cidreq().'&amp;action=add&type=dropdown&amp;survey_id='.$survey_id.'">'.Display::return_icon('dropdown.gif', get_lang('Dropdown')).'<br /></a>';
echo '<a href="question.php?'.api_get_cidreq().'&amp;action=add&type=percentage&amp;survey_id='.$survey_id.'">'.Display::return_icon('percentagequestion.gif', get_lang('Percentage')).'<br /></a>';
echo '<a href="question.php?'.api_get_cidreq().'&amp;action=add&type=score&amp;survey_id='.$survey_id.'">'.Display::return_icon('scorequestion.gif', get_lang('Score')).'</a>';
echo '<a href="question.php?'.api_get_cidreq().'&amp;action=add&type=comment&amp;survey_id='.$survey_id.'">'.Display::return_icon('commentquestion.gif', get_lang('Comment')).'</a>';
echo '<a href="question.php?'.api_get_cidreq().'&amp;action=add&type=pagebreak&amp;survey_id='.$survey_id.'">'.Display::return_icon('page_end.gif', get_lang('Pagebreak')).'</a>';
echo '</div>';
echo '<div class="actionsbig">';
echo '<a style="padding-left:0px;" href="'.api_get_path(WEB_CODE_PATH).'survey/question.php?'.api_get_cidreq().'&amp;action=add&type=yesno&amp;survey_id='.$survey_id.'">'.Display::return_icon('yesno.gif', get_lang('YesNo')).'</a>';
echo '<a href="'.api_get_path(WEB_CODE_PATH).'survey/question.php?'.api_get_cidreq().'&amp;action=add&type=multiplechoice&amp;survey_id='.$survey_id.'">'.Display::return_icon('mcua.gif', get_lang('UniqueSelect')).'<br /></a>';
echo '<a href="'.api_get_path(WEB_CODE_PATH).'survey/question.php?'.api_get_cidreq().'&amp;action=add&type=multipleresponse&amp;survey_id='.$survey_id.'">'.Display::return_icon('mcma.gif', get_lang('MultipleResponse')).'</a>';
echo '<a href="'.api_get_path(WEB_CODE_PATH).'survey/question.php?'.api_get_cidreq().'&amp;action=add&type=open&amp;survey_id='.$survey_id.'">'.Display::return_icon('open_answer.gif', get_lang('Open')).'<br /></a>';
echo '<a href="'.api_get_path(WEB_CODE_PATH).'survey/question.php?'.api_get_cidreq().'&amp;action=add&type=dropdown&amp;survey_id='.$survey_id.'">'.Display::return_icon('dropdown.gif', get_lang('Dropdown')).'<br /></a>';
echo '<a href="'.api_get_path(WEB_CODE_PATH).'survey/question.php?'.api_get_cidreq().'&amp;action=add&type=percentage&amp;survey_id='.$survey_id.'">'.Display::return_icon('percentagequestion.gif', get_lang('Percentage')).'<br /></a>';
echo '<a href="'.api_get_path(WEB_CODE_PATH).'survey/question.php?'.api_get_cidreq().'&amp;action=add&type=score&amp;survey_id='.$survey_id.'">'.Display::return_icon('scorequestion.gif', get_lang('Score')).'</a>';
echo '<a href="'.api_get_path(WEB_CODE_PATH).'survey/question.php?'.api_get_cidreq().'&amp;action=add&type=comment&amp;survey_id='.$survey_id.'">'.Display::return_icon('commentquestion.gif', get_lang('Comment')).'</a>';
echo '<a href="'.api_get_path(WEB_CODE_PATH).'survey/question.php?'.api_get_cidreq().'&amp;action=add&type=pagebreak&amp;survey_id='.$survey_id.'">'.Display::return_icon('page_end.gif', get_lang('Pagebreak')).'</a>';
echo '</div>';
} else {
echo '<div class="actionsbig">';
echo '<a style="padding-left:0px;" href="question.php?'.api_get_cidreq().'&amp;action=add&type=personality&amp;survey_id='.$survey_id.'">
'.Display::return_icon('yesno.gif').'
</a>
</div>';
echo '</div>';
echo '<div class="actionsbig">';
echo '<a style="padding-left:0px;" href="'.api_get_path(WEB_CODE_PATH).'survey/question.php?'.api_get_cidreq().'&amp;action=add&type=personality&amp;survey_id='.$survey_id.'"><img src="../img/yesno.gif" /></a></div>';
echo '</div>';
}
// Displaying the table header with all the questions
@ -172,124 +170,124 @@ echo ' <th>'.get_lang('Type').'</th>';
echo ' <th width="50" >'.get_lang('NumberOfOptions').'</th>';
echo ' <th width="100">'.get_lang('Modify').'</th>';
if ($is_survey_type_1) {
echo '<th width="100">'.get_lang('Condition').'</th>';
echo '<th width="100">'.get_lang('Condition').'</th>';
echo '<th width="40">'.get_lang('Group').'</th>';
}
echo ' </tr>';
// Displaying the table contents with all the questions
$question_counter = 1;
$sql = "SELECT * FROM $table_survey_question_group WHERE c_id = '.$course_id.' AND survey_id = '".Database::escape_string($survey_id)."' ORDER BY id";
$sql = "SELECT * FROM $table_survey_question_group
WHERE c_id = '.$course_id.' AND survey_id = '".Database::escape_string($survey_id)."' ORDER BY id";
$result = Database::query($sql);
$groups = array();
while ($row = Database::fetch_array($result)) {
$groups[$row['id']] = $row['name'];
}
$sql = "SELECT survey_question.*, count(survey_question_option.question_option_id) as number_of_options
FROM $table_survey_question survey_question
LEFT JOIN $table_survey_question_option survey_question_option
ON survey_question.question_id = survey_question_option.question_id AND survey_question_option.c_id = $course_id
WHERE survey_question.survey_id = '".Database::escape_string($survey_id)."' AND
survey_question.c_id = $course_id
GROUP BY survey_question.question_id
ORDER BY survey_question.sort ASC";
FROM $table_survey_question survey_question
LEFT JOIN $table_survey_question_option survey_question_option
ON survey_question.question_id = survey_question_option.question_id AND survey_question_option.c_id = $course_id
WHERE
survey_question.survey_id = '".Database::escape_string($survey_id)."' AND
survey_question.c_id = $course_id
GROUP BY survey_question.question_id
ORDER BY survey_question.sort ASC";
$result = Database::query($sql);
$question_counter_max = Database::num_rows($result);
while ($row = Database::fetch_array($result, 'ASSOC')) {
echo '<tr>';
echo ' <td>'.$question_counter.'</td>';
echo ' <td>';
if (api_strlen($row['survey_question']) > 100) {
echo api_substr(strip_tags($row['survey_question']), 0, 100).' ... ';
} else {
echo $row['survey_question'];
echo '<tr>';
echo ' <td>'.$question_counter.'</td>';
echo ' <td>';
if (api_strlen($row['survey_question']) > 100) {
echo api_substr(strip_tags($row['survey_question']), 0, 100).' ... ';
} else {
echo $row['survey_question'];
}
if ($row['type'] == 'yesno') {
$tool_name = get_lang('YesNo');
} else if ($row['type'] == 'multiplechoice') {
$tool_name = get_lang('UniqueSelect');
} else {
$tool_name = get_lang(api_ucfirst(Security::remove_XSS($row['type'])));
}
echo '</td>';
echo ' <td>'.$tool_name.'</td>';
echo ' <td>'.$row['number_of_options'].'</td>';
echo ' <td>';
echo ' <a href="'.api_get_path(WEB_CODE_PATH).'survey/question.php?'.api_get_cidreq().'&amp;action=edit&amp;type='.$row['type'].'&amp;survey_id='.$survey_id.'&amp;question_id='.$row['question_id'].'">'.Display::return_icon('edit.png', get_lang('Edit'),'',ICON_SIZE_SMALL).'</a>';
echo ' <a href="'.api_get_path(WEB_CODE_PATH).'survey/survey.php?'.api_get_cidreq().'&amp;action=delete&amp;survey_id='.$survey_id.'&amp;question_id='.$row['question_id'].'" onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang("DeleteSurveyQuestion").'?',ENT_QUOTES,$charset)).'\')) return false;">'.Display::return_icon('delete.png', get_lang('Delete'),'',ICON_SIZE_SMALL).'</a>';
if ($question_counter > 1) {
echo ' <a href="'.api_get_path(WEB_CODE_PATH).'survey/survey.php?'.api_get_cidreq().'&amp;action=moveup&amp;survey_id='.$survey_id.'&amp;question_id='.$row['question_id'].'">'.Display::return_icon('up.png', get_lang('MoveUp'),'',ICON_SIZE_SMALL).'</a>';
} else {
Display::display_icon('up_na.png','&nbsp;','',ICON_SIZE_SMALL);
}
if ($question_counter < $question_counter_max) {
echo ' <a href="'.api_get_path(WEB_CODE_PATH).'survey/survey.php?'.api_get_cidreq().'&amp;action=movedown&amp;survey_id='.$survey_id.'&amp;question_id='.$row['question_id'].'">'.Display::return_icon('down.png', get_lang('MoveDown'),'',ICON_SIZE_SMALL).'</a>';
} else {
Display::display_icon('down_na.png','&nbsp;','',ICON_SIZE_SMALL);
}
echo ' </td>';
$question_counter++;
if ($is_survey_type_1) {
echo '<td>'.(($row['survey_group_pri']==0)?get_lang('Secondary'):get_lang('Primary')).'</td>';
echo '<td>'.(($row['survey_group_pri']==0)?$groups[$row['survey_group_sec1']].'-'.$groups[$row['survey_group_sec2']]:$groups[$row['survey_group_pri']]).'</td>';
}
if ($row['type'] == 'yesno') {
$tool_name = get_lang('YesNo');
} else if ($row['type'] == 'multiplechoice') {
$tool_name = get_lang('UniqueSelect');
} else {
$tool_name = get_lang(api_ucfirst(Security::remove_XSS($row['type'])));
}
echo '</td>';
echo ' <td>'.$tool_name.'</td>';
echo ' <td>'.$row['number_of_options'].'</td>';
echo ' <td>';
echo ' <a href="question.php?'.api_get_cidreq().'&amp;action=edit&amp;type='.$row['type'].'&amp;survey_id='.$survey_id.'&amp;question_id='.$row['question_id'].'">'.Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_SMALL).'</a>';
echo ' <a href="survey.php?'.api_get_cidreq().'&amp;action=delete&amp;survey_id='.$survey_id.'&amp;question_id='.$row['question_id'].'" onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang("DeleteSurveyQuestion").'?', ENT_QUOTES, $charset)).'\')) return false;">'.Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL).'</a>';
if ($question_counter > 1) {
echo ' <a href="survey.php?'.api_get_cidreq().'&amp;action=moveup&amp;survey_id='.$survey_id.'&amp;question_id='.$row['question_id'].'">'.Display::return_icon('up.png', get_lang('MoveUp'), '', ICON_SIZE_SMALL).'</a>';
} else {
Display::display_icon('up_na.png', '&nbsp;', '', ICON_SIZE_SMALL);
}
if ($question_counter < $question_counter_max) {
echo ' <a href="survey.php?'.api_get_cidreq().'&amp;action=movedown&amp;survey_id='.$survey_id.'&amp;question_id='.$row['question_id'].'">'.Display::return_icon('down.png', get_lang('MoveDown'), '', ICON_SIZE_SMALL).'</a>';
} else {
Display::display_icon('down_na.png', '&nbsp;', '', ICON_SIZE_SMALL);
}
echo ' </td>';
$question_counter++;
if ($is_survey_type_1) {
echo '<td>'.(($row['survey_group_pri'] == 0) ? get_lang('Secondary') : get_lang('Primary')).'</td>';
echo '<td>'.(($row['survey_group_pri'] == 0) ? $groups[$row['survey_group_sec1']].'-'.$groups[$row['survey_group_sec2']] : $groups[$row['survey_group_pri']]).'</td>';
}
echo '</tr>';
echo '</tr>';
}
echo '</table>';
if ($is_survey_type_1) {
echo '<br /><br /><b>'.get_lang('ManageGroups').'</b><br /><br />';
if (in_array($_GET['sendmsg'], array('GroupUpdatedSuccessfully', 'GroupDeletedSuccessfully', 'GroupCreatedSuccessfully'))) {
echo Display::display_confirmation_message(get_lang($_GET['sendmsg']), false);
}
if (in_array($_GET['sendmsg'], array('GroupNeedName'))) {
echo Display::display_warning_message(get_lang($_GET['sendmsg']), false);
}
echo '<table border="0"><tr><td width="100">'.get_lang('Name').'</td><td>'.get_lang('Description').'</td></tr></table>';
echo '<form action="survey.php?action=addgroup&survey_id='.$survey_id.'" method="post">';
if ($action == 'editgroup') {
$sql = 'SELECT name,description FROM '.$table_survey_question_group.' WHERE id = '.Database::escape_string($_GET['gid']).' AND survey_id = '.Database::escape_string($survey_id).' limit 1';
$rs = Database::query($sql);
$editedrow = Database::fetch_array($rs, 'ASSOC');
echo '<input type="text" maxlength="20" name="name" value="'.$editedrow['name'].'" size="10" disabled>';
echo '<input type="text" maxlength="150" name="description" value="'.$editedrow['description'].'" size="40">';
echo '<input type="hidden" name="group_id" value="'.Security::remove_XSS($_GET['gid']).'">';
echo '<input type="submit" value="'.get_lang('Save').'"'.'<input type="button" value="'.get_lang('Cancel').'" onclick="window.location.href = \'survey.php?survey_id='.Security::remove_XSS($survey_id).'\';" />';
} else {
echo '<input type="text" maxlength="20" name="name" value="" size="10">';
echo '<input type="text" maxlength="250" name="description" value="" size="80">';
echo '<input type="submit" value="'.get_lang('Create').'"';
}
echo '</form><br />';
echo '<table class="data_table">';
echo ' <tr class="row_odd">';
echo ' <th width="200">'.get_lang('Name').'</th>';
echo ' <th>'.get_lang('Description').'</th>';
echo ' <th width="100">'.get_lang('Modify').'</th>';
echo ' </tr>';
$sql = 'SELECT id,name,description FROM '.$table_survey_question_group.' WHERE c_id = '.$course_id.' AND survey_id = '.Database::escape_string($survey_id).' ORDER BY name';
$rs = Database::query($sql);
while ($row = Database::fetch_array($rs, ASSOC)) {
$grouplist .= '<tr><td>'.$row['name'].'</td><td>'.$row['description'].'</td><td>'.
'<a href="survey.php?survey_id='.$survey_id.'&gid='.$row['id'].'&action=editgroup">'.
Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_SMALL).'</a> '.
'<a href="survey.php?survey_id='.$survey_id.'&gid='.$row['id'].'&action=deletegroup" onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(sprintf(get_lang('DeleteSurveyGroup'), $row['name']).'?', ENT_QUOTES)).'\')) return false;">'.
Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL).'</a>'.
'</td></tr>';
}
echo $grouplist.'</table>';
echo '<br /><br /><b>'.get_lang('ManageGroups').'</b><br /><br />';
if (in_array($_GET['sendmsg'], array('GroupUpdatedSuccessfully', 'GroupDeletedSuccessfully', 'GroupCreatedSuccessfully'))) {
echo Display::display_confirmation_message(get_lang($_GET['sendmsg']), false);
}
if (in_array($_GET['sendmsg'], array('GroupNeedName'))){
echo Display::display_warning_message(get_lang($_GET['sendmsg']), false);
}
echo '<table border="0"><tr><td width="100">'.get_lang('Name').'</td><td>'.get_lang('Description').'</td></tr></table>';
echo '<form action="'.api_get_path(WEB_CODE_PATH).'survey/survey.php?action=addgroup&survey_id='.$survey_id.'" method="post">';
if ($_GET['action'] == 'editgroup') {
$sql = 'SELECT name,description FROM '.$table_survey_question_group.' WHERE id = '.Database::escape_string($_GET['gid']).' AND survey_id = '.Database::escape_string($survey_id).' limit 1';
$rs = Database::query($sql);
$editedrow = Database::fetch_array($rs,'ASSOC');
echo '<input type="text" maxlength="20" name="name" value="'.$editedrow['name'].'" size="10" disabled>';
echo '<input type="text" maxlength="150" name="description" value="'.$editedrow['description'].'" size="40">';
echo '<input type="hidden" name="group_id" value="'.Security::remove_XSS($_GET['gid']).'">';
echo '<input type="submit" value="'.get_lang('Save').'"'.'<input type="button" value="'.get_lang('Cancel').'" onclick="window.location.href = \'survey.php?survey_id='.Security::remove_XSS($survey_id).'\';" />';
} else {
echo '<input type="text" maxlength="20" name="name" value="" size="10">';
echo '<input type="text" maxlength="250" name="description" value="" size="80">';
echo '<input type="submit" value="'.get_lang('Create').'"';
}
echo '</form><br />';
echo '<table class="data_table">';
echo ' <tr class="row_odd">';
echo ' <th width="200">'.get_lang('Name').'</th>';
echo ' <th>'.get_lang('Description').'</th>';
echo ' <th width="100">'.get_lang('Modify').'</th>';
echo ' </tr>';
$sql = 'SELECT id,name,description FROM '.$table_survey_question_group.' WHERE c_id = '.$course_id.' AND survey_id = '.Database::escape_string($survey_id).' ORDER BY name';
$rs = Database::query($sql);
while($row = Database::fetch_array($rs,ASSOC)){
$grouplist .= '<tr><td>'.$row['name'].'</td><td>'.$row['description'].'</td><td>'.
'<a href="'.api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.$survey_id.'&gid='.$row['id'].'&action=editgroup">'.
Display::return_icon('edit.png', get_lang('Edit'),'',ICON_SIZE_SMALL).'</a> '.
'<a href="'.api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.$survey_id.'&gid='.$row['id'].'&action=deletegroup" onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(sprintf(get_lang('DeleteSurveyGroup'),$row['name']).'?',ENT_QUOTES)).'\')) return false;">'.
Display::return_icon('delete.png', get_lang('Delete'),'',ICON_SIZE_SMALL).'</a>'.
'</td></tr>';
}
echo $grouplist.'</table>';
}
// Footer

@ -2,12 +2,13 @@
/* For licensing terms, see /license.txt */
/**
* @package chamilo.survey
* @package chamilo.survey
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University: cleanup, refactoring and rewriting large parts of the code
* @version $Id: survey_invite.php 10680 2007-01-11 21:26:23Z pcool $
*
* @todo the answered column
*/
// Language file that needs to be included
$language_file = 'survey';
@ -16,13 +17,14 @@ require '../inc/global.inc.php';
// Including additional libraries
require_once 'survey.lib.php';
require_once api_get_path(LIBRARY_PATH).'mail.lib.inc.php';
/** @todo this has to be moved to a more appropriate place (after the display_header of the code) */
/** @todo this has to be moved to a more appropriate place (after the display_header of the code)*/
if (!api_is_allowed_to_edit(false, true)) {
Display :: display_header(get_lang('ToolSurvey'));
Display :: display_error_message(get_lang('NotAllowed'), false);
Display :: display_footer();
exit;
Display :: display_header(get_lang('ToolSurvey'));
Display :: display_error_message(get_lang('NotAllowed'), false);
Display :: display_footer();
exit;
}
// Database table definitions
@ -35,65 +37,67 @@ $table_survey_invitation = Database :: get_course_table(TABLE_SURVEY_INVITATIO
$tool_name = get_lang('SurveyInvitations');
// Getting the survey information
// We exit here if ther is no valid $_GET parameter
if (!isset($_GET['survey_id']) OR !is_numeric($_GET['survey_id'])) {
Display :: display_header($tool_name);
Display :: display_error_message(get_lang('InvallidSurvey'), false);
Display :: display_footer();
exit;
Display :: display_header($tool_name);
Display :: display_error_message(get_lang('InvallidSurvey'), false);
Display :: display_footer();
exit;
}
$survey_id = Security::remove_XSS($_GET['survey_id']);
$survey_data = survey_manager::get_survey($survey_id);
if (empty($survey_data)) {
Display :: display_header($tool_name);
Display :: display_error_message(get_lang('InvallidSurvey'), false);
Display :: display_footer();
exit;
Display :: display_header($tool_name);
Display :: display_error_message(get_lang('InvallidSurvey'), false);
Display :: display_footer();
exit;
}
$urlname = strip_tags(api_substr(api_html_entity_decode($survey_data['title'], ENT_QUOTES), 0, 40));
if (api_strlen(strip_tags($survey_data['title'])) > 40) {
$urlname .= '...';
$urlname .= '...';
}
// Breadcrumbs
$interbreadcrumb[] = array('url' => 'survey_list.php', 'name' => get_lang('SurveyList'));
$interbreadcrumb[] = array('url' => 'survey.php?survey_id='.$survey_id, 'name' => $urlname);
$interbreadcrumb[] = array('url' => api_get_path(WEB_CODE_PATH).'survey/survey_list.php', 'name' => get_lang('SurveyList'));
$interbreadcrumb[] = array('url' => api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.$survey_id, 'name' => $urlname);
// Displaying the header
Display::display_header($tool_name);
// Checking the parameters
if (!is_numeric($survey_id)) {
Display::display_error_message(get_lang('Error'), false);
Display::display_footer();
exit;
Display::display_error_message(get_lang('Error'), false);
Display::display_footer();
exit;
}
// Getting all the people who have filled this survey
$answered_data = survey_manager::get_people_who_filled_survey($survey_id);
if ($survey_data['anonymous'] == 1) {
Display::display_normal_message(get_lang('AnonymousSurveyCannotKnowWhoAnswered').' '.count($answered_data).' '.get_lang('PeopleAnswered'));
$answered_data = array();
Display::display_normal_message(get_lang('AnonymousSurveyCannotKnowWhoAnswered').' '.count($answered_data).' '.get_lang('PeopleAnswered'));
$answered_data = array();
}
if (!isset($_GET['view']) OR $_GET['view'] == 'invited') {
echo get_lang('ViewInvited').' | ';
echo get_lang('ViewInvited'). ' | ';
} else {
echo ' <a href="'.api_get_self().'?survey_id='.$survey_id.'&amp;view=invited">'.get_lang('ViewInvited').'</a> |';
echo ' <a href="'.api_get_self().'?survey_id='.$survey_id.'&amp;view=invited">'.get_lang('ViewInvited').'</a> |';
}
if ($_GET['view'] == 'answered') {
echo get_lang('ViewAnswered').' | ';
echo get_lang('ViewAnswered').' | ';
} else {
echo ' <a href="'.api_get_self().'?survey_id='.$survey_id.'&amp;view=answered">'.get_lang('ViewAnswered').'</a> |';
echo ' <a href="'.api_get_self().'?survey_id='.$survey_id.'&amp;view=answered">'.get_lang('ViewAnswered').'</a> |';
}
if ($_GET['view'] == 'unanswered') {
echo get_lang('ViewUnanswered');
echo get_lang('ViewUnanswered');
} else {
echo ' <a href="'.api_get_self().'?survey_id='.$survey_id.'&amp;view=unanswered">'.get_lang('ViewUnanswered').'</a>';
echo ' <a href="'.api_get_self().'?survey_id='.$survey_id.'&amp;view=unanswered">'.get_lang('ViewUnanswered').'</a>';
}
// Table header
@ -109,31 +113,31 @@ $course_id = api_get_course_int_id();
$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 AND survey_invitation.c_id = $course_id)
WHERE survey_invitation.survey_code = '".Database::escape_string($survey_data['code'])."' AND group_id = 0 ";
WHERE survey_invitation.survey_code = '".Database::escape_string($survey_data['code'])."' ";
$res = Database::query($sql);
while ($row = Database::fetch_assoc($res)) {
if (!$_GET['view'] || $_GET['view'] == 'invited' || ($_GET['view'] == 'answered' && in_array($row['user'], $answered_data)) || ($_GET['view'] == 'unanswered' && !in_array($row['user'], $answered_data))) {
echo '<tr>';
if (is_numeric($row['user'])) {
echo ' <td><a href="../user/userInfo.php?editMainUserInfo='.$row['user'].'">'.api_get_person_name($row['firstname'], $row['lastname']).'</a></td>';
} else {
echo ' <td>'.$row['user'].'</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='.$survey_id.'&amp;user='.$row['user'].'">'.get_lang('ViewAnswers').'</a>';
} else {
echo '-';
}
echo ' </td>';
echo '</tr>';
}
if (!$_GET['view'] || $_GET['view'] == 'invited' || ($_GET['view'] == 'answered' && in_array($row['user'], $answered_data)) || ($_GET['view'] == 'unanswered' && !in_array($row['user'], $answered_data))) {
echo '<tr>';
if (is_numeric($row['user'])) {
echo ' <td><a href="'.api_get_path(WEB_CODE_PATH).'user/userInfo.php?editMainUserInfo='.$row['user'].'">'.api_get_person_name($row['firstname'], $row['lastname']).'</a></td>';
} else {
echo ' <td>'.$row['user'].'</td>';
}
echo ' <td>'.$row['invitation_date'].'</td>';
echo ' <td>';
if (in_array($row['user'], $answered_data)) {
echo '<a href="'.api_get_path(WEB_CODE_PATH).'survey/reporting.php?action=userreport&amp;survey_id='.$survey_id.'&amp;user='.$row['user'].'">'.get_lang('ViewAnswers').'</a>';
} else {
echo '-';
}
echo ' </td>';
echo '</tr>';
}
}
// Closing the table
echo '</table>';
// Footer
Display :: display_footer();
Display :: display_footer();

@ -2,15 +2,15 @@
/* For licensing terms, see /license.txt */
/**
* @package chamilo.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
* @author Julio Montoya Chamilo: cleanup, refactoring, security improvements
* @version $Id: survey_invite.php 10680 2007-01-11 21:26:23Z pcool $
* @package chamilo.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
* @author Julio Montoya Chamilo: cleanup, refactoring, security improvements
* @version $Id: survey_invite.php 10680 2007-01-11 21:26:23Z pcool $
*
* @todo checking if the additional emails are valid (or add a rule for this)
* @todo check if the mailtext contains the **link** part, if not, add the link to the end
* @todo add rules: title and text cannot be empty
* @todo checking if the additional emails are valid (or add a rule for this)
* @todo check if the mailtext contains the **link** part, if not, add the link to the end
* @todo add rules: title and text cannot be empty
*/
// Language file that needs to be included
@ -21,22 +21,23 @@ require_once '../inc/global.inc.php';
// Including additional libraries
require_once 'survey.lib.php';
require_once api_get_path(LIBRARY_PATH).'mail.lib.inc.php';
$this_section = SECTION_COURSES;
if (!api_is_allowed_to_edit(false, true)) {
Display :: display_header(get_lang('ToolSurvey'));
Display :: display_error_message(get_lang('NotAllowed'), false);
Display :: display_footer();
exit;
Display :: display_header(get_lang('ToolSurvey'));
Display :: display_error_message(get_lang('NotAllowed'), false);
Display :: display_footer();
exit;
}
// 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);
$table_course = Database :: get_main_table(TABLE_MAIN_COURSE);
$table_user = Database :: get_main_table(TABLE_MAIN_USER);
$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);
$table_course = Database :: get_main_table(TABLE_MAIN_COURSE);
$table_user = Database :: get_main_table(TABLE_MAIN_USER);
$course_id = api_get_course_int_id();
@ -44,28 +45,28 @@ $course_id = api_get_course_int_id();
$survey_id = Security::remove_XSS($_GET['survey_id']);
$survey_data = survey_manager::get_survey($survey_id);
if (empty($survey_data)) {
Display :: display_header(get_lang('ToolSurvey'));
Display :: display_error_message(get_lang('InvallidSurvey'), false);
Display :: display_footer();
exit;
Display :: display_header(get_lang('ToolSurvey'));
Display :: display_error_message(get_lang('InvallidSurvey'), false);
Display :: display_footer();
exit;
}
$urlname = strip_tags(api_substr(api_html_entity_decode($survey_data['title'], ENT_QUOTES), 0, 40));
if (api_strlen(strip_tags($survey_data['title'])) > 40) {
$urlname .= '...';
$urlname .= '...';
}
// Breadcrumbs
$interbreadcrumb[] = array('url' => 'survey_list.php', 'name' => get_lang('SurveyList'));
$interbreadcrumb[] = array('url' => api_get_path(WEB_CODE_PATH).'survey/survey_list.php', 'name' => get_lang('SurveyList'));
if (api_is_course_admin()) {
$interbreadcrumb[] = array('url' => 'survey.php?survey_id='.$survey_id, 'name' => $urlname);
$interbreadcrumb[] = array('url' => api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.$survey_id, 'name' => $urlname);
} else {
$interbreadcrumb[] = array('url' => 'survey_invite.php?survey_id='.$survey_id, 'name' => $urlname);
$interbreadcrumb[] = array('url' => api_get_path(WEB_CODE_PATH).'survey/survey_invite.php?survey_id='.$survey_id, 'name' => $urlname);
}
$tool_name = get_lang('SurveyPublication');
// Displaying the header
Display::display_header($tool_name, 'Survey');
Display::display_header($tool_name,'Survey');
echo '<script>
$(function() {
@ -77,26 +78,23 @@ $(function() {
// 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 c_id = $course_id AND code='".Database::escape_string(
$survey_data['code']
)."'";
$sql = "SELECT * FROM $table_survey WHERE c_id = $course_id AND code='".Database::escape_string($survey_data['code'])."'";
$result = Database::query($sql);
if (Database::num_rows($result) > 1) {
Display::display_warning_message(get_lang('IdenticalSurveycodeWarning'));
Display::display_warning_message(get_lang('IdenticalSurveycodeWarning'));
}
// Invited / answered message
if ($survey_data['invited'] > 0 && !isset($_POST['submit'])) {
$message = '<a href="survey_invitation.php?view=answered&amp;survey_id='.$survey_data['survey_id'].'">'.$survey_data['answered'].'</a> ';
$message .= get_lang('HaveAnswered').' ';
$message .= '<a href="survey_invitation.php?view=invited&amp;survey_id='.$survey_data['survey_id'].'">'.$survey_data['invited'].'</a> ';
$message .= get_lang('WereInvited');
Display::display_normal_message($message, false);
$message = '<a href="'.api_get_path(WEB_CODE_PATH).'survey/survey_invitation.php?view=answered&amp;survey_id='.$survey_data['survey_id'].'">'.$survey_data['answered'].'</a> ';
$message .= get_lang('HaveAnswered').' ';
$message .= '<a href="'.api_get_path(WEB_CODE_PATH).'survey/survey_invitation.php?view=invited&amp;survey_id='.$survey_data['survey_id'].'">'.$survey_data['invited'].'</a> ';
$message .= get_lang('WereInvited');
Display::display_normal_message($message, false);
}
// Building the form for publishing the survey
$form = new FormValidator('publish_form', 'post', api_get_self().'?survey_id='.$survey_id.'&'.api_get_cidReq());
$form->addElement('header', '', $tool_name);
// Course users
@ -108,24 +106,29 @@ $complete_user_list = CourseManager::get_user_list_from_course_code(
);
$possible_users = array();
foreach ($complete_user_list as & $user) {
$possible_users[$user['user_id']] = api_get_person_name($user['firstname'], $user['lastname']);
$possible_users[$user['user_id']] = api_get_person_name($user['firstname'], $user['lastname']);
}
$list = UserManager::generate_user_group_array(api_get_course_id(), api_get_session_id());
$users = $form->addElement('advmultiselect', 'course_users', get_lang('CourseUsers'), $list);
$users->setButtonAttributes('add');
$users->setButtonAttributes('remove');
$users = $form->addElement('advmultiselect', 'course_users', get_lang('CourseUsers'), $possible_users, 'style="width: 250px; height: 200px;"');
$users->setElementTemplate('
{javascript}
<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>
<td valign="top">{unselected}</td>
<td align="center">{add}<br /><br />{remove}</td>
<td valign="top">{selected}</td>
</tr>
</table>
');
$users->setButtonAttributes('add', array('class' => 'btn arrowr'));
$users->setButtonAttributes('remove', array('class' => 'btn arrowl'));
// Additional users
$form->addElement(
'textarea',
'additional_users',
array(get_lang('AdditonalUsers'), get_lang('AdditonalUsersComment')),
array('class' => 'span6', 'rows' => 5)
);
$form->addElement('textarea', 'additional_users', array(get_lang('AdditonalUsers'), get_lang('AdditonalUsersComment')), array('class' => 'span6', 'rows' => 5));
$form->addElement('html', '<div id="check_mail">');
$form->addElement('checkbox', 'send_mail', '', get_lang('SendMail'));
$form->addElement('checkbox', 'send_mail','', get_lang('SendMail'));
$form->addElement('html', '</div>');
$form->addElement('html', '<div id="mail_text">');
@ -133,121 +136,103 @@ $form->addElement('html', '<div id="mail_text">');
// The title of the mail
$form->addElement('text', 'mail_title', get_lang('MailTitle'), array('class' => 'span6'));
// The text of the mail
$form->addElement(
'html_editor',
'mail_text',
array(get_lang('MailText'), get_lang('UseLinkSyntax')),
null,
array('ToolbarSet' => 'Survey', 'Width' => '100%', 'Height' => '150')
);
$form->addElement('html_editor', 'mail_text', array(get_lang('MailText'), get_lang('UseLinkSyntax')), null, array('ToolbarSet' => 'Survey', 'Width' => '100%', 'Height' => '150'));
$form->addElement('html', '</div>');
// You cab send a reminder to unanswered people if the survey is not anonymous
if ($survey_data['anonymous'] != 1) {
$form->addElement('checkbox', 'remindUnAnswered', '', get_lang('RemindUnanswered'));
$form->addElement('checkbox', 'remindUnAnswered', '', get_lang('RemindUnanswered'));
}
// Allow resending to all selected users
$form->addElement('checkbox', 'resend_to_all', '', get_lang('ReminderResendToAllUsers'));
// Submit button
$form->addElement('style_submit_button', 'submit', get_lang('PublishSurvey'), 'class="save"');
// The rules (required fields)
/*if ($survey_data['send_mail'] == 0) {
$form->addRule('mail_title', get_lang('ThisFieldIsRequired'), 'required');
$form->addRule('mail_text', get_lang('ThisFieldIsRequired'), 'required');
}*/
$portal_url = api_get_path(WEB_PATH);
if (api_is_multiple_url_enabled()) {
$access_url_id = api_get_current_access_url_id();
if ($access_url_id != -1) {
$url = api_get_access_url($access_url_id);
$portal_url = $url['url'];
}
if ($_configuration['multiple_access_urls']) {
$access_url_id = api_get_current_access_url_id();
if ($access_url_id != -1) {
$url = api_get_access_url($access_url_id);
$portal_url = $url['url'];
}
}
// Show the URL that can be used by users to fill a survey without invitation
$auto_survey_link = $portal_url.'main/survey/fillsurvey.php?course='.$_course['sysCode'].'&invitationcode=auto&scode='.$survey_data['survey_code'];
$form->addElement('label', null, get_lang('AutoInviteLink'));
$form->addElement('label', null, "<pre>$auto_survey_link</pre>");
$form->addElement('label', null, $auto_survey_link);
if ($form->validate()) {
$values = $form->exportValues();
if (isset($values['send_mail']) && $values['send_mail'] == 1) {
$values = $form->exportValues();
if ($values['send_mail'] == 1) {
if (empty($values['mail_title']) || empty($values['mail_text'])) {
Display :: display_error_message(get_lang('FormHasErrorsPleaseComplete'));
// Getting the invited users
$defaults = SurveyUtil::get_invited_users($survey_data['code']);
// Getting the survey mail text
if (!empty($survey_data['reminder_mail'])) {
$defaults['mail_text'] = $survey_data['reminder_mail'];
} else {
$defaults['mail_text'] = $survey_data['invite_mail'];
}
$defaults['mail_title'] = $survey_data['mail_subject'];
$defaults['send_mail'] = 1;
$form->setDefaults($defaults);
$defaults = SurveyUtil::get_invited_users($survey_data['code']);
// Getting the survey mail text
if (!empty($survey_data['reminder_mail'])) {
$defaults['mail_text'] = $survey_data['reminder_mail'];
} else {
$defaults['mail_text'] = $survey_data['invite_mail'];
}
$defaults['mail_title'] = $survey_data['mail_subject'];
$defaults['send_mail'] = 1;
$form->setDefaults($defaults);
$form->display();
return;
}
}
// Save the invitation mail
SurveyUtil::save_invite_mail($values['mail_text'], $values['mail_title'], !empty($survey_data['invite_mail']));
// Saving the invitations for the course users
$count_course_users = SurveyUtil::save_invitations(
$values['course_users'],
$values['mail_title'],
$values['mail_text'],
$values['resend_to_all'],
$values['send_mail'],
$values['remindUnAnswered']
);
// 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);
for ($i = 0; $i < count($additional_users); $i++) {
$additional_users[$i] = trim($additional_users[$i]);
}
$counter_additional_users = SurveyUtil::save_invitations(
$additional_users,
$values['mail_title'],
$values['mail_text'],
$values['resend_to_all'],
$values['send_mail'],
$values['remindUnAnswered']
);
// Updating the invited field in the survey table
SurveyUtil::update_count_invited($survey_data['code']);
$total_count = $count_course_users + $counter_additional_users;
$total_invited = count(SurveyUtil::get_invitations($survey_data['code']));
SurveyUtil::save_invite_mail($values['mail_text'], $values['mail_title'], !empty($survey_data['invite_mail']));
// Saving the invitations for the course users
$count_course_users = SurveyUtil::save_invitations($values['course_users'], $values['mail_title'],
$values['mail_text'], $values['resend_to_all'], $values['send_mail'], $values['remindUnAnswered']);
// 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);
for ($i = 0; $i < count($additional_users); $i++) {
$additional_users[$i] = trim($additional_users[$i]);
}
$counter_additional_users = SurveyUtil::save_invitations($additional_users, $values['mail_title'],
$values['mail_text'], $values['resend_to_all'], $values['send_mail'], $values['remindUnAnswered']);
// Updating the invited field in the survey table
SurveyUtil::update_count_invited($survey_data['code']);
$total_count = $count_course_users + $counter_additional_users;
$table_survey = Database :: get_course_table(TABLE_SURVEY);
// Counting the number of people that are invited
$sql = "SELECT * FROM $table_survey WHERE c_id = $course_id AND code = '".Database::escape_string($survey_data['code'])."'";
$result = Database::query($sql);
$row = Database::fetch_array($result);
$total_invited = $row['invited'];
if ($total_invited > 0) {
$message = '<a href="survey_invitation.php?view=answered&amp;survey_id='.$survey_data['survey_id'].'">'.$survey_data['answered'].'</a> ';
$message .= get_lang('HaveAnswered').' ';
$message .= '<a href="survey_invitation.php?view=invited&amp;survey_id='.$survey_data['survey_id'].'">'.$total_invited.'</a> ';
$message .= get_lang('WereInvited');
Display::display_normal_message($message, false);
Display::display_confirmation_message($total_count.' '.get_lang('InvitationsSend'));
$message = '<a href="'.api_get_path(WEB_CODE_PATH).'survey/survey_invitation.php?view=answered&amp;survey_id='.$survey_data['survey_id'].'">'.$survey_data['answered'].'</a> ';
$message .= get_lang('HaveAnswered').' ';
$message .= '<a href="'.api_get_path(WEB_CODE_PATH).'survey/survey_invitation.php?view=invited&amp;survey_id='.$survey_data['survey_id'].'">'.$total_invited.'</a> ';
$message .= get_lang('WereInvited');
Display::display_normal_message($message, false);
Display::display_confirmation_message($total_count.' '.get_lang('InvitationsSend'));
}
} else {
// Getting the invited users
$defaults = SurveyUtil::get_invited_users($survey_data['code']);
// Getting the survey mail text
if (!empty($survey_data['reminder_mail'])) {
$defaults['mail_text'] = $survey_data['reminder_mail'];
} else {
$defaults['mail_text'] = $survey_data['invite_mail'];
}
$defaults['mail_title'] = $survey_data['mail_subject'];
$defaults['send_mail'] = 1;
$defaults['course_users'] = array_keys(
UserManager::transform_user_group_array($defaults['course_users'], $defaults['course_groups'], true, true)
);
$form->setDefaults($defaults);
// Getting the invited users
$defaults = SurveyUtil::get_invited_users($survey_data['code']);
// Getting the survey mail text
if (!empty($survey_data['reminder_mail'])) {
$defaults['mail_text'] = $survey_data['reminder_mail'];
} else {
$defaults['mail_text'] = $survey_data['invite_mail'];
}
$defaults['mail_title'] = $survey_data['mail_subject'];
$defaults['send_mail'] = 1;
$form->setDefaults($defaults);
$form->display();
}
Display :: display_footer();
Display :: display_footer();

@ -2,17 +2,18 @@
/* For licensing terms, see /license.txt */
/**
* @package chamilo.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
* @author Julio Montoya Armas <gugli100@gmail.com>, Chamilo: Personality Test modification and rewriting large parts of the code
* @version $Id: survey_list.php 21933 2009-07-09 06:08:22Z ivantcholakov $
* @package chamilo.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
* @author Julio Montoya Armas <gugli100@gmail.com>, Chamilo: Personality Test modification and rewriting large parts of the code
* @version $Id: survey_list.php 21933 2009-07-09 06:08:22Z ivantcholakov $
*
* @todo use quickforms for the forms
* @todo use quickforms for the forms
*/
// Language file that needs to be included
$language_file = 'survey';
if (!isset($_GET['cidReq'])) {
if (!isset ($_GET['cidReq'])){
$_GET['cidReq'] = 'none'; // Prevent sql errors
$cidReset = true;
}
@ -20,7 +21,7 @@ if (!isset($_GET['cidReq'])) {
// Including the global initialization file
require_once '../inc/global.inc.php';
$this_section = SECTION_COURSES;
$current_course_tool = TOOL_SURVEY;
$current_course_tool = TOOL_SURVEY;
api_protect_course_script(true);
@ -30,25 +31,25 @@ require_once 'survey.lib.php';
// Tracking
event_access_tool(TOOL_SURVEY);
/** @todo This has to be moved to a more appropriate place (after the display_header of the code) */
/** @todo This has to be moved to a more appropriate place (after the display_header of the code)*/
if (!api_is_allowed_to_edit(false, true)) { // Coach can see this
Display :: display_header(get_lang('SurveyList'));
Display::display_header(get_lang('SurveyList'));
SurveyUtil::survey_list_user($_user['user_id']);
Display :: display_footer();
Display::display_footer();
exit;
}
$extend_rights_for_coachs = api_get_setting('extend_rights_for_coach_on_survey');
// Database table definitions
$table_survey = Database :: get_course_table(TABLE_SURVEY);
$table_survey_question = Database :: get_course_table(TABLE_SURVEY_QUESTION);
$table_course = Database :: get_main_table(TABLE_MAIN_COURSE);
$table_user = Database :: get_main_table(TABLE_MAIN_USER);
$table_survey = Database :: get_course_table(TABLE_SURVEY);
$table_survey_question = Database :: get_course_table(TABLE_SURVEY_QUESTION);
$table_course = Database :: get_main_table(TABLE_MAIN_COURSE);
$table_user = Database :: get_main_table(TABLE_MAIN_USER);
// Language variables
if (isset($_GET['search']) && $_GET['action'] == 'search') {
$interbreadcrumb[] = array('url' => 'survey_list.php', 'name' => get_lang('SurveyList'));
if (isset($_GET['search']) && $_GET['search'] == 'advanced') {
$interbreadcrumb[] = array('url' => api_get_path(WEB_CODE_PATH).'survey/survey_list.php', 'name' => get_lang('SurveyList'));
$tool_name = get_lang('SearchASurvey');
} else {
$tool_name = get_lang('SurveyList');
@ -60,63 +61,53 @@ Display::display_header($tool_name, 'Survey');
// Tool introduction
Display::display_introduction_section('survey', 'left');
// Action handling
$action = isset($_GET['action']) ? $_GET['action'] : null;
switch ($action) {
case 'search' :
SurveyUtil::display_survey_search_form();
break;
case 'delete':
if (isset($_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 (api_is_course_coach() && intval($_SESSION['id_session']) != $survey_data['session_id']) {
// The coach can't delete a survey not belonging to his session
api_not_allowed();
exit;
}
// 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);
}
// Action handling: searching
if (isset ($_GET['search']) && $_GET['search'] == 'advanced') {
SurveyUtil::display_survey_search_form();
}
// Action handling: deleting a survey
if (isset($_GET['action']) && $_GET['action'] == 'delete' && isset($_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 (api_is_course_coach() && intval($_SESSION['id_session']) != $survey_data['session_id']) {
// The coach can't delete a survey not belonging to his session
api_not_allowed();
exit;
}
// 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'), false);
} else {
Display :: display_error_message(get_lang('ErrorOccurred'), false);
}
}
break;
case 'empty':
$mysession = api_get_session_id();
if ($mysession != 0) {
if (!((api_is_course_coach() || api_is_platform_admin()) && api_is_element_in_the_session(
TOOL_SURVEY,
intval($_GET['survey_id'])
))
) {
// The coach can't empty a survey not belonging to his session
api_not_allowed();
exit;
}
} else {
if (!(api_is_course_admin() || api_is_platform_admin())) {
api_not_allowed();
exit;
}
$return = survey_manager :: delete_survey($_GET['survey_id']);
if ($return) {
Display::display_confirmation_message(get_lang('SurveyDeleted'), false);
} else {
Display::display_error_message(get_lang('ErrorOccurred'), false);
}
}
if (isset($_GET['action']) && $_GET['action'] == 'empty') {
$mysession = api_get_session_id();
if ($mysession != 0) {
if (!((api_is_course_coach() || api_is_platform_admin()) &&
api_is_element_in_the_session(TOOL_SURVEY, $_GET['survey_id']))) {
// The coach can't empty a survey not belonging to his session
api_not_allowed();
exit;
}
$return = survey_manager::empty_survey(intval($_GET['survey_id']));
if ($return) {
Display :: display_confirmation_message(get_lang('SurveyEmptied'), false);
} else {
Display :: display_error_message(get_lang('ErrorOccurred'), false);
} else {
if (!(api_is_course_admin() || api_is_platform_admin())) {
api_not_allowed();
exit;
}
break;
case 'copy_survey':
survey_manager::copy_survey($_GET['survey_id']);
break;
}
$return = survey_manager::empty_survey(intval($_GET['survey_id']));
if ($return) {
Display :: display_confirmation_message(get_lang('SurveyEmptied'), false);
} else {
Display :: display_error_message(get_lang('ErrorOccurred'), false);
}
}
// Action handling: performing the same action on multiple surveys
@ -138,23 +129,12 @@ if (isset($_POST['action']) && $_POST['action']) {
}
}
echo '<div class="actions">';
if (!api_is_course_coach() || $extend_rights_for_coachs == 'true') {
// Action links
echo '<a href="create_new_survey.php?'.api_get_cidreq().'&amp;action=add">'.Display::return_icon(
'new_survey.png',
get_lang('CreateNewSurvey'),
'',
ICON_SIZE_MEDIUM
).'</a> ';
}
echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;action=search">'.Display::return_icon(
'search.png',
get_lang('Search'),
'',
ICON_SIZE_MEDIUM
).'</a>';
// Action links
echo '<a href="'.api_get_path(WEB_CODE_PATH).'survey/create_new_survey.php?'.api_get_cidreq().'&amp;action=add">'.Display::return_icon('new_survey.png', get_lang('CreateNewSurvey'),'',ICON_SIZE_MEDIUM).'</a> ';
}
echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;search=advanced">'.Display::return_icon('search.png', get_lang('Search'),'',ICON_SIZE_MEDIUM).'</a>';
echo '</div>';
// Load main content
@ -171,35 +151,34 @@ Display :: display_footer();
function get_number_of_surveys()
{
return SurveyUtil::get_number_of_surveys();
return SurveyUtil::get_number_of_surveys();
}
function get_survey_data($from, $number_of_items, $column, $direction)
{
return SurveyUtil::get_survey_data($from, $number_of_items, $column, $direction);
return SurveyUtil::get_survey_data($from, $number_of_items, $column, $direction);
}
function modify_filter($survey_id)
{
return SurveyUtil::modify_filter($survey_id);
return SurveyUtil::modify_filter($survey_id);
}
function get_number_of_surveys_for_coach()
{
return SurveyUtil::get_number_of_surveys_for_coach();
return SurveyUtil::get_number_of_surveys_for_coach();
}
function get_survey_data_for_coach($from, $number_of_items, $column, $direction)
{
return SurveyUtil::get_survey_data_for_coach($from, $number_of_items, $column, $direction);
return SurveyUtil::get_survey_data_for_coach($from, $number_of_items, $column, $direction);
}
function modify_filter_for_coach($survey_id)
{
return SurveyUtil::modify_filter_for_coach($survey_id);
return SurveyUtil::modify_filter_for_coach($survey_id);
}
function anonymous_filter($anonymous)
{
return SurveyUtil::anonymous_filter($anonymous);
return SurveyUtil::anonymous_filter($anonymous);
}

Loading…
Cancel
Save