Adding copy survey code see BT#5732

skala
Julio Montoya 12 years ago
parent a447309a05
commit fb94a886df
  1. 27
      main/survey/create_new_survey.php
  2. 165
      main/survey/survey.lib.php
  3. 19
      main/survey/survey.php
  4. 195
      main/survey/survey_list.php

@ -27,7 +27,7 @@ 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 type="text/javascript">
$htmlHeadXtra[] = '<script>
function advanced_parameters() {
if(document.getElementById(\'options\').style.display == \'none\') {
document.getElementById(\'options\').style.display = \'block\';
@ -70,13 +70,8 @@ $course_id = api_get_course_id();
$session_id = api_get_session_id();
$gradebook_link_type = 8; // LINK_SURVEY
/* $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 = $survey_data['title'];
// Breadcrumbs
if ($_GET['action'] == 'add') {
$interbreadcrumb[] = array('url' => 'survey_list.php', 'name' => get_lang('SurveyList'));
@ -124,36 +119,19 @@ if ($_GET['action'] == 'edit' && isset($survey_id) && is_numeric($survey_id)) {
}
$survey_code = $form->addElement('text', 'survey_code', get_lang('SurveyCode'), array('size' => '20', 'maxlength' => '20', 'id' => 'surveycode_title'));
//$form->applyFilter('survey_code', 'html_filter');
if ($_GET['action'] == 'edit') {
$survey_code->freeze();
//$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'));
//$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));
@ -226,7 +204,6 @@ if ((isset($_GET['action']) && $_GET['action'] == 'edit') && !empty($survey_id))
}
}
}
$form->addElement('html', '</div>');
}
}

@ -26,6 +26,28 @@ $htmlHeadXtra[] = '<script>
*/
class survey_manager {
public static function generate_unique_code($code) {
if (empty($code)) {
return false;
}
$course_id = api_get_course_int_id();
$table_survey = Database::get_course_table(TABLE_SURVEY);
$code = Database::escape_string($code);
$num = 0;
$new_code = $code;
while (true) {
$sql = "SELECT * FROM $table_survey WHERE code = '$new_code' AND c_id = $course_id";
$result = Database::query($sql);
if (Database::num_rows($result)) {
$num ++;
$new_code = $code.$num;
} else {
break;
}
}
return $code.$num;
}
public static function get_surveys($course_code, $session_id = 0) {
$table_survey = Database :: get_course_table(TABLE_SURVEY);
$course_info = api_get_course_info($course_code);
@ -54,8 +76,7 @@ class survey_manager {
* @assert('0') === false
* @todo this is the same function as in create_new_survey.php
*/
static function get_survey($survey_id, $shared = 0, $course_code = '') {
global $_course;
static function get_survey($survey_id, $shared = 0, $course_code = '', $simple_return = false) {
// Table definition
if (!empty($course_code)) {
@ -83,6 +104,9 @@ class survey_manager {
if (Database::num_rows($result)> 0) {
$return = Database::fetch_array($result,'ASSOC');
if ($simple_return) {
return $return;
}
// We do this (temporarily) to have the array match the quickform elements immediately
// idealiter the fields in the db match the quickform fields
$return['survey_code'] = $return['code'];
@ -115,7 +139,6 @@ class survey_manager {
* @version February 2007
*/
static function store_survey($values) {
global $_user;
// Table defnitions
$table_survey = Database :: get_course_table(TABLE_SURVEY);
@ -229,7 +252,7 @@ class survey_manager {
'".Database::escape_string(strtolower(CourseManager::generate_course_code(api_substr($values['survey_code'],0))))."',
'".Database::escape_string($values['survey_title'])."',
'".Database::escape_string($values['survey_subtitle'])."',
'".Database::escape_string($_user['user_id'])."',
'".api_get_user_id()."',
'".Database::escape_string($values['survey_language'])."',
'".Database::escape_string($values['start_date'])."',
'".Database::escape_string($values['end_date'])."',
@ -239,7 +262,7 @@ class survey_manager {
'".Database::escape_string($values['survey_thanks'])."',
'".api_get_utc_datetime()."',
'".Database::escape_string($values['anonymous'])."'".$additional['values'].",
".intval($_SESSION['id_session'])."
".api_get_session_id()."
)";
$result = Database::query($sql);
$survey_id = Database::insert_id();
@ -339,28 +362,28 @@ class survey_manager {
if (!$values['survey_id'] || !is_numeric($values['survey_id']) || $values['survey_share']['survey_share'] == 'true') {
$sql = "INSERT INTO $table_survey (code, title, subtitle, author, lang, template, intro, surveythanks, creation_date, course_code) VALUES (
'".Database::escape_string($values['survey_code'])."',
'".Database::escape_string($values['survey_title'])."',
'".Database::escape_string($values['survey_subtitle'])."',
'".Database::escape_string($_user['user_id'])."',
'".Database::escape_string($values['survey_language'])."',
'".Database::escape_string('template')."',
'".Database::escape_string($values['survey_introduction'])."',
'".Database::escape_string($values['survey_thanks'])."',
'".api_get_utc_datetime()."',
'".Database::escape_string($values['survey_code'])."',
'".Database::escape_string($values['survey_title'])."',
'".Database::escape_string($values['survey_subtitle'])."',
'".Database::escape_string($_user['user_id'])."',
'".Database::escape_string($values['survey_language'])."',
'template',
'".Database::escape_string($values['survey_introduction'])."',
'".Database::escape_string($values['survey_thanks'])."',
'".api_get_utc_datetime()."',
'".$_course['id']."')";
$result = Database::query($sql);
$return = Database::insert_id();
} else {
$sql = "UPDATE $table_survey SET
code = '".Database::escape_string($values['survey_code'])."',
title = '".Database::escape_string($values['survey_title'])."',
subtitle = '".Database::escape_string($values['survey_subtitle'])."',
author = '".Database::escape_string($_user['user_id'])."',
lang = '".Database::escape_string($values['survey_language'])."',
template = '".Database::escape_string('template')."',
intro = '".Database::escape_string($values['survey_introduction'])."',
surveythanks = '".Database::escape_string($values['survey_thanks'])."'
code = '".Database::escape_string($values['survey_code'])."',
title = '".Database::escape_string($values['survey_title'])."',
subtitle = '".Database::escape_string($values['survey_subtitle'])."',
author = '".Database::escape_string($_user['user_id'])."',
lang = '".Database::escape_string($values['survey_language'])."',
template = 'template',
intro = '".Database::escape_string($values['survey_introduction'])."',
surveythanks = '".Database::escape_string($values['survey_thanks'])."'
WHERE survey_id = '".Database::escape_string($values['survey_share']['survey_share'])."'";
$result = Database::query($sql);
$return = $values['survey_share']['survey_share'];
@ -417,7 +440,7 @@ class survey_manager {
return true;
}
function copy_survey($parent_survey, $new_survey_id) {
static function copy_survey($survey_id, $new_survey_id = null) {
$course_id = api_get_course_int_id();
// Database table definitions
@ -425,23 +448,38 @@ class survey_manager {
$table_survey_question_group = Database::get_course_table(TABLE_SURVEY_QUESTION_GROUP);
$table_survey_question = Database::get_course_table(TABLE_SURVEY_QUESTION);
$table_survey_options = Database::get_course_table(TABLE_SURVEY_QUESTION_OPTION);
$parent_survey = Database::escape_string($parent_survey);
$survey_id = Database::escape_string($survey_id);
// Get groups
$sql = "SELECT * from $table_survey_question_group WHERE c_id = $course_id AND survey_id='".$parent_survey."'";
$res = Database::query($sql);
if (Database::num_rows($res) === 0) {
$survey_data = self::get_survey($survey_id, 0, null, true);
if (empty($survey_data)) {
return true;
}
$new_survey_id = intval($new_survey_id);
if (empty($new_survey_id)) {
$params = $survey_data;
$params['code'] = self::generate_unique_code($params['code']);
$params['c_id'] = $course_id;
unset($params['survey_id']);
$params['session_id'] = api_get_session_id();
$params['title'] = $params['title'].' '.get_lang('Copy');
Database::insert($table_survey, $params);
$new_survey_id = Database::insert_id();
} else {
$new_survey_id = intval($new_survey_id);
}
$sql = "SELECT * from $table_survey_question_group WHERE c_id = $course_id AND survey_id='".$survey_id."'";
$res = Database::query($sql);
while($row = Database::fetch_array($res, 'ASSOC')){
$sql1 = 'INSERT INTO '.$table_survey_question_group.' (c_id, name,description,survey_id) VALUES
('.$course_id.', \''.Database::escape_string($row['name']).'\',\''.Database::escape_string($row['description']).'\',\''.$new_survey_id.'\')';
$res1 = Database::query($sql1);
Database::query($sql1);
$group_id[$row['id']] = Database::insert_id();
}
// Get questions
$sql = "SELECT * FROM $table_survey_question WHERE c_id = $course_id AND survey_id='".$parent_survey."'";
$sql = "SELECT * FROM $table_survey_question WHERE c_id = $course_id AND survey_id='".$survey_id."'";
$res = Database::query($sql);
while($row = Database::fetch_array($res, 'ASSOC')){
$sql2 = 'INSERT INTO '.$table_survey_question.' (c_id, survey_id,survey_question,survey_question_comment,type,display,sort,shared_question_id,max_value,survey_group_pri,survey_group_sec1,survey_group_sec2) VALUES '.
@ -452,12 +490,12 @@ class survey_manager {
}
// Get questions options
$sql = "SELECT * FROM $table_survey_options WHERE c_id = $course_id AND survey_id='".$parent_survey."'";
$sql = "SELECT * FROM $table_survey_options WHERE c_id = $course_id AND survey_id='".$survey_id."'";
$res = Database::query($sql);
while($row = Database::fetch_array($res ,'ASSOC')){
$sql3 = 'INSERT INTO '.$table_survey_options.' (c_id, question_id,survey_id,option_text,sort,value) VALUES ('.
" $course_id , '".$question_id[$row['question_id']]."','".$new_survey_id."','".Database::escape_string($row['option_text'])."','".$row['sort']."','".$row['value']."')";
$res3 = Database::query($sql3);
Database::query($sql3);
}
return true;
}
@ -681,7 +719,6 @@ class survey_manager {
while ($row = Database::fetch_array($result, 'ASSOC')) {
$return[$row['question_id']]['answers'][] = $row['option_text'];
}
return $return;
}
@ -695,7 +732,7 @@ class survey_manager {
* @version January 2007
*/
function save_question($form_content) {
static function save_question($form_content) {
global $survey_data;
if (strlen($form_content['question']) > 1) { // Checks lenght of the question
@ -814,7 +851,7 @@ class survey_manager {
}
// Storing the options of the question
$message_options=self::save_question_options($form_content, $survey_data);
$message_options = self::save_question_options($form_content, $survey_data);
} else {
$return_message = 'PleasFillAllAnswer';
}
@ -1029,7 +1066,7 @@ class survey_manager {
*
* @todo writing the update statement when editing a question
*/
function save_question_options($form_content, $survey_data) {
static function save_question_options($form_content, $survey_data) {
$course_id = api_get_course_int_id();
// A percentage question type has options 1 -> 100
if ($form_content['type'] == 'percentage') {
@ -1305,7 +1342,7 @@ class survey_question {
global $survey_data;
//$tool_name = '<img src="../img/'.self::icon_question($_GET['type']).'" alt="'.get_lang(ucfirst($_GET['type'])).'" title="'.get_lang(ucfirst($_GET['type'])).'" />';
$tool_name = Display::return_icon(self::icon_question(Security::remove_XSS($_GET['type'])), get_lang(ucfirst(Security::remove_XSS($_GET['type']))), array('align' => 'middle', 'height' => '22px')).' ';
$tool_name = Display::return_icon(survey_manager::icon_question(Security::remove_XSS($_GET['type'])), get_lang(ucfirst(Security::remove_XSS($_GET['type']))), array('align' => 'middle', 'height' => '22px')).' ';
if ($_GET['action'] == 'add') {
$tool_name .= get_lang('AddQuestion');
}
@ -1468,7 +1505,7 @@ class survey_question {
// Saving a question
if (isset($_POST['save_question'])) {
$message = self::save_question($form_content);
$message = survey_manager::save_question($form_content);
if ($message == 'QuestionAdded' || $message == 'QuestionUpdated' ) {
$sql='SELECT COUNT(*) FROM '.Database :: get_course_table(TABLE_SURVEY_QUESTION).' WHERE c_id = '.$course_id.' AND survey_id = '.intval($_GET['survey_id']);
@ -4208,7 +4245,7 @@ class SurveyUtil {
// Coach can see that only if the survey is in his session
if (api_is_allowed_to_edit() || api_is_element_in_the_session(TOOL_SURVEY, $survey_id)) {
$return .= '<a href="create_new_survey.php?'.api_get_cidreq().'&amp;action=edit&amp;survey_id='.$survey_id.'">'.Display::return_icon('edit.png', get_lang('Edit'),'',ICON_SIZE_SMALL).'</a>';
if (self::survey_generation_hash_available()) {
if (survey_manager::survey_generation_hash_available()) {
$return .= Display::url(Display::return_icon('new_link.png', get_lang('GenerateSurveyAccessLink'),'',ICON_SIZE_SMALL), 'generate_link.php?survey_id='.$survey_id.'&'.api_get_cidreq());
}
$return .= Display::url(Display::return_icon('copy.png', get_lang('DuplicateSurvey'),'',ICON_SIZE_SMALL), 'survey_list.php?action=copy_survey&survey_id='.$survey_id.'&'.api_get_cidreq());
@ -4621,7 +4658,7 @@ class SurveyUtil {
continue;
}
switch ($field_details[2]) {
case UserManager::USER_FIELD_TYPE_TEXT:
case ExtraField::FIELD_TYPE_TEXT:
$field_list_array['extra_'.$field_details[1]]['name'] = $field_details[3];
if ($field_details[7] == 0) {
$field_list_array['extra_'.$field_details[1]]['visibility'] = 0;
@ -4629,7 +4666,7 @@ class SurveyUtil {
$field_list_array['extra_'.$field_details[1]]['visibility'] = 1;
}
break;
case UserManager::USER_FIELD_TYPE_TEXTAREA:
case ExtraField::FIELD_TYPE_TEXTAREA:
$field_list_array['extra_'.$field_details[1]]['name'] = $field_details[3];
if ($field_details[7] == 0) {
$field_list_array['extra_'.$field_details[1]]['visibility'] = 0;
@ -4637,8 +4674,7 @@ class SurveyUtil {
$field_list_array['extra_'.$field_details[1]]['visibility'] = 1;
}
break;
case UserManager::USER_FIELD_TYPE_RADIO:
case ExtraField::FIELD_TYPE_RADIO:
$field_list_array['extra_'.$field_details[1]]['name'] = $field_details[3];
if ($field_details[7] == 0) {
$field_list_array['extra_'.$field_details[1]]['visibility'] = 0;
@ -4646,8 +4682,7 @@ class SurveyUtil {
$field_list_array['extra_'.$field_details[1]]['visibility'] = 1;
}
break;
case UserManager::USER_FIELD_TYPE_SELECT:
case ExtraField::FIELD_TYPE_SELECT:
$field_list_array['extra_'.$field_details[1]]['name'] = $field_details[3];
if ($field_details[7] == 0) {
$field_list_array['extra_'.$field_details[1]]['visibility'] = 0;
@ -4656,7 +4691,7 @@ class SurveyUtil {
}
break;
case UserManager::USER_FIELD_TYPE_SELECT_MULTIPLE:
case ExtraField::FIELD_TYPE_SELECT_MULTIPLE:
$field_list_array['extra_'.$field_details[1]]['name'] = $field_details[3];
if ($field_details[7] == 0) {
$field_list_array['extra_'.$field_details[1]]['visibility'] = 0;
@ -4665,7 +4700,7 @@ class SurveyUtil {
}
break;
case UserManager::USER_FIELD_TYPE_DATE:
case ExtraField::FIELD_TYPE_DATE:
$field_list_array['extra_'.$field_details[1]]['name'] = $field_details[3];
if ($field_details[7] == 0) {
$field_list_array['extra_'.$field_details[1]]['visibility'] = 0;
@ -4674,7 +4709,7 @@ class SurveyUtil {
}
break;
case UserManager::USER_FIELD_TYPE_DATETIME:
case ExtraField::FIELD_TYPE_DATETIME:
$field_list_array['extra_'.$field_details[1]]['name'] = $field_details[3];
if ($field_details[7] == 0) {
$field_list_array['extra_'.$field_details[1]]['visibility'] = 0;
@ -4683,45 +4718,15 @@ class SurveyUtil {
}
break;
case UserManager::USER_FIELD_TYPE_DOUBLE_SELECT:
case ExtraField::FIELD_TYPE_DOUBLE_SELECT:
$field_list_array['extra_'.$field_details[1]]['name'] = $field_details[3];
if ($field_details[7] == 0) {
$field_list_array['extra_'.$field_details[1]]['visibility'] = 0;
} else {
$field_list_array['extra_'.$field_details[1]]['visibility']=1;
}
/*
foreach ($field_details[8] as $key => $element) {
if ($element[2][0] == '*') {
$values['*'][$element[0]] = str_replace('*','',$element[2]);
} else {
$values[0][$element[0]] = $element[2];
}
}
$group = '';
$group[] =& HTML_QuickForm::createElement('select', 'extra_'.$field_details[1], '', $values[0], '');
$group[] =& HTML_QuickForm::createElement('select', 'extra_'.$field_details[1].'*', '', $values['*'], '');
$form->addGroup($group, 'extra_'.$field_details[1], $field_details[3], '&nbsp;');
if ($field_details[7] == 0) $form->freeze('extra_'.$field_details[1]);
// Recoding the selected values for double : if the user has selected certain values, we have to assign them to the correct select form
if (key_exists('extra_'.$field_details[1], $extra_data)) {
// Exploding all the selected values (of both select forms)
$selected_values = explode(';',$extra_data['extra_'.$field_details[1]]);
$extra_data['extra_'.$field_details[1]] = array();
// Looping through the selected values and assigning the selected values to either the first or second select form
foreach ($selected_values as $key => $selected_value) {
if (key_exists($selected_value, $values[0])) {
$extra_data['extra_'.$field_details[1]]['extra_'.$field_details[1]] = $selected_value;
} else {
$extra_data['extra_'.$field_details[1]]['extra_'.$field_details[1].'*'] = $selected_value;
}
}
}*/
break;
case UserManager::USER_FIELD_TYPE_DIVIDER:
case ExtraField::FIELD_TYPE_DIVIDER:
//$form->addElement('static',$field_details[1], '<br /><strong>'.$field_details[3].'</strong>');
break;
}

@ -42,8 +42,8 @@ $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'));
@ -69,10 +69,11 @@ if (api_strlen(strip_tags($survey_data['title'])) > 40) {
$tool_name .= '...';
}
if ($is_survey_type_1 && $_GET['action'] == 'addgroup' || $_GET['action'] == 'deletegroup') {
if ($is_survey_type_1 && $action == 'addgroup' || $action == 'deletegroup') {
$_POST['name'] = trim($_POST['name']);
if (($_GET['action'] == 'addgroup')) {
if ($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']).'\'');
@ -85,7 +86,7 @@ if ($is_survey_type_1 && $_GET['action'] == 'addgroup' || $_GET['action'] == 'de
}
}
if ($_GET['action'] == 'deletegroup'){
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';
}
@ -98,17 +99,17 @@ if ($is_survey_type_1 && $_GET['action'] == 'addgroup' || $_GET['action'] == 'de
Display::display_header($tool_name, 'Survey');
// Action handling
$my_action_survey = Security::remove_XSS($_GET['action']);
$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($_GET['action'])) {
if (($_GET['action'] == 'moveup' || $_GET['action'] == 'movedown') && isset($_GET['question_id'])) {
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 ($_GET['action'] == 'delete' AND is_numeric($_GET['question_id'])) {
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']);
}
}
@ -253,7 +254,7 @@ if ($is_survey_type_1) {
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 ($_GET['action'] == 'editgroup') {
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');

@ -2,18 +2,17 @@
/* For licensing terms, see /license.txt */
/**
* @package chamilo.survey
* @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
* @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
*/
// 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;
}
@ -21,7 +20,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);
@ -31,119 +30,121 @@ 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'));
SurveyUtil::survey_list_user($_user['user_id']);
Display :: display_footer();
exit;
Display :: display_header(get_lang('SurveyList'));
SurveyUtil::survey_list_user($_user['user_id']);
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['search'] == 'advanced') {
$interbreadcrumb[] = array('url' => 'survey_list.php', 'name' => get_lang('SurveyList'));
$tool_name = get_lang('SearchASurvey');
$interbreadcrumb[] = array('url' => 'survey_list.php', 'name' => get_lang('SurveyList'));
$tool_name = get_lang('SearchASurvey');
} else {
$tool_name = get_lang('SurveyList');
$tool_name = get_lang('SurveyList');
}
// Header
Display :: display_header($tool_name, 'Survey');
Display::display_header($tool_name, 'Survey');
// Tool introduction
Display::display_introduction_section('survey', 'left');
// Action handling: searching
if (isset ($_GET['search']) && $_GET['search'] == 'advanced') {
SurveyUtil::display_survey_search_form();
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);
}
// 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);
}
}
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,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::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);
}
$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::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);
}
}
if (isset($_GET['action']) && $_GET['action'] == 'copy_survey') {
survey_manager::copy_survey($_GET['survey_id']);
}
// Action handling: performing the same action on multiple surveys
if (isset($_POST['action']) && $_POST['action']) {
if (is_array($_POST['id'])) {
foreach ($_POST['id'] as $key => & $value) {
// getting the information of the survey (used for when the survey is shared)
$survey_data = survey_manager::get_survey($value);
// if the survey is shared => also delete the shared content
if (is_numeric($survey_data['survey_share'])) {
survey_manager::delete_survey($survey_data['survey_share'], true);
}
// delete the actual survey
survey_manager::delete_survey($value);
}
Display :: display_confirmation_message(get_lang('SurveysDeleted'), false);
} else {
Display :: display_error_message(get_lang('NoSurveysSelected'), false);
}
if (is_array($_POST['id'])) {
foreach ($_POST['id'] as $key => & $value) {
// getting the information of the survey (used for when the survey is shared)
$survey_data = survey_manager::get_survey($value);
// if the survey is shared => also delete the shared content
if (is_numeric($survey_data['survey_share'])) {
survey_manager::delete_survey($survey_data['survey_share'], true);
}
// delete the actual survey
survey_manager::delete_survey($value);
}
Display :: display_confirmation_message(get_lang('SurveysDeleted'), false);
} else {
Display :: display_error_message(get_lang('NoSurveysSelected'), false);
}
}
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> ';
// 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="survey_all_courses.php">'.get_lang('CreateExistingSurvey').'</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 '<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
if (api_is_course_coach() && $extend_rights_for_coachs == 'false') {
SurveyUtil::display_survey_list_for_coach();
SurveyUtil::display_survey_list_for_coach();
} else {
SurveyUtil::display_survey_list();
SurveyUtil::display_survey_list();
}
// Footer
@ -151,29 +152,37 @@ Display :: display_footer();
/* Bypass functions to make direct use from SortableTable possible */
function get_number_of_surveys() {
return SurveyUtil::get_number_of_surveys();
function 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);
function 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);
function 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();
function 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);
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);
}
function modify_filter_for_coach($survey_id) {
return SurveyUtil::modify_filter_for_coach($survey_id);
function modify_filter_for_coach($survey_id)
{
return SurveyUtil::modify_filter_for_coach($survey_id);
}
function anonymous_filter($anonymous) {
return SurveyUtil::anonymous_filter($anonymous);
function anonymous_filter($anonymous)
{
return SurveyUtil::anonymous_filter($anonymous);
}

Loading…
Cancel
Save