, 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'; // Including the global initialization file require_once '../inc/global.inc.php'; $this_section = SECTION_COURSES; // Including additional libraries //require_once api_get_path(LIBRARY_PATH).'survey.lib.php'; require_once 'survey.lib.php'; require_once api_get_path(LIBRARY_PATH).'course.lib.php'; /** @todo this has to be moved to a more appropriate place (after the display_header of the code)*/ // 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; } // 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); $user_info = Database :: get_main_table(TABLE_MAIN_SURVEY_REMINDER); // TODO: To be checked. TABLE_MAIN_SURVEY_REMINDER has not been defined. $survey_id = intval($_GET['survey_id']); // Breadcrumbs $interbreadcrumb[] = array ('url' => '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; } } if (api_substr($survey_data['title'], 0, 3) != '

') { $tool_name = strip_tags(api_substr(api_html_entity_decode($survey_data['title'], ENT_QUOTES), 0, 40)); } else { $tool_name = strip_tags(api_substr(api_html_entity_decode(api_substr($survey_data['title'], 3, -4), ENT_QUOTES), 0, 40)); } $is_survey_type_1 = $survey_data['survey_type'] == 1; if (api_strlen(strip_tags($survey_data['title'])) > 40) { $tool_name .= '...'; } if ($is_survey_type_1 && $_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 id = \''.Database::escape_string($_POST['group_id']).'\''); $sendmsg = 'GroupUpdatedSuccessfully'; } elseif(!empty($_POST['name'])) { Database::query('INSERT INTO '.$table_survey_question_group.' (name,description,survey_id) values (\''.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 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; } // Displaying the header Display::display_header($tool_name,'Survey'); // Action handling $my_action_survey = Security::remove_XSS($_GET['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'])) { 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); } } if (!empty($survey_data['survey_version'])) echo ''.get_lang('Version').': '.$survey_data['survey_version'].''; // 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 = ''.Display::return_icon('edit.gif', get_lang('Edit')).' '.get_lang('EditSurvey').''; $survey_actions .= ''.Display::return_icon('delete.gif', get_lang('Delete')).' '.get_lang('DeleteSurvey').''; //$survey_actions .= ''.Display::return_icon('copy.gif', get_lang('Copy')).''; $survey_actions .= ''.Display::return_icon('preview.gif', get_lang('Preview')).' '.get_lang('Preview').''; $survey_actions .= ''.Display::return_icon('survey_publish.gif', get_lang('Publish')).' '.get_lang('Publish').''; $survey_actions .= ''.Display::return_icon('statistics.gif', get_lang('Reporting')).' '.get_lang('Reporting').''; echo '

'.$survey_actions.'
'; if ($survey_data['survey_type'] == 0) { echo '
'; echo ''.Display::return_icon('yesno.gif', get_lang('YesNo')).'
'.get_lang('YesNo').'
'; echo ''.Display::return_icon('mcua.gif', get_lang('UniqueSelect')).'
'.get_lang('UniqueSelect').'
'; echo ''.Display::return_icon('mcma.gif', get_lang('MultipleResponse')).'
'.get_lang('MultipleResponse').'
'; echo ''.Display::return_icon('open_answer.gif', get_lang('Open')).'
'.get_lang('Open').'
'; echo ''.Display::return_icon('dropdown.gif', get_lang('Dropdown')).'
'.get_lang('Dropdown').'
'; echo ''.Display::return_icon('percentagequestion.gif', get_lang('Percentage')).'
'.get_lang('Percentage').'
'; echo ''.Display::return_icon('scorequestion.gif', get_lang('Score')).'
'.get_lang('Score').'
'; echo ''.Display::return_icon('commentquestion.gif', get_lang('Comment')).'
'.get_lang('Comment').'
'; echo ''.Display::return_icon('page_end.gif', get_lang('Pagebreak')).'
'.get_lang('Pagebreak').'
'; echo '
'; } else { echo '
'; //echo '
'.get_lang('Add groups').'
'; echo ''.get_lang('PersonalityQuestion').''; echo ''; } // Displaying the table header with all the questions echo ''; echo ' '; echo ' '; echo ' '; echo ' '; echo ' '; echo ' '; if ($is_survey_type_1) { echo ''; echo ''; } echo ' '; // Displaying the table contents with all the questions $question_counter = 1; $sql = "SELECT * FROM $table_survey_question_group WHERE 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 WHERE survey_question.survey_id = '".Database::escape_string($survey_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 ''; echo ' '; echo ' '; echo ' '; echo ' '; echo ' '; $question_counter++; if ($is_survey_type_1) { echo ''; echo ''; } echo ''; } echo '
'.get_lang('QuestionNumber').''.get_lang('Title').''.get_lang('Type').''.get_lang('NumberOfOptions').''.get_lang('Modify').''.get_lang('Condition').''.get_lang('Group').'
'.$question_counter.''; 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 ''.$tool_name.''.$row['number_of_options'].''; echo ' '.Display::return_icon('edit.gif', get_lang('Edit')).''; echo ' '.Display::return_icon('delete.gif', get_lang('Delete')).''; if ($question_counter > 1) { echo ' '.Display::return_icon('up.gif', get_lang('MoveUp')).''; } else { Display::display_icon('up_na.gif'); } if ($question_counter < $question_counter_max) { echo ' '.Display::return_icon('down.gif', get_lang('MoveDown')).''; } else { Display::display_icon('down_na.gif'); } echo ' '.(($row['survey_group_pri']==0)?get_lang('Secondary'):get_lang('Primary')).''.(($row['survey_group_pri']==0)?$groups[$row['survey_group_sec1']].'-'.$groups[$row['survey_group_sec2']]:$groups[$row['survey_group_pri']]).'
'; if ($is_survey_type_1) { echo '

'.get_lang('ManageGroups').'

'; 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 '
'.get_lang('Name').''.get_lang('Description').'
'; echo '
'; 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 ''; echo ''; echo ''; echo ''; } else { echo ''; echo ''; echo '
'; echo ''; echo ' '; echo ' '; echo ' '; echo ' '; echo ' '; $sql = 'SELECT id,name,description FROM '.$table_survey_question_group.' WHERE survey_id = '.Database::escape_string($survey_id).' ORDER BY name'; $rs = Database::query($sql); while($row = Database::fetch_array($rs,ASSOC)){ $grouplist .= ''; } echo $grouplist.'
'.get_lang('Name').''.get_lang('Description').''.get_lang('Modify').'
'.$row['name'].''.$row['description'].''. ''. Display::return_icon('edit.gif', get_lang('Edit')).' '. ''. Display::return_icon('delete.gif', get_lang('Delete')).''. '
'; } // Footer Display :: display_footer();