, Ghent University: cleanup, refactoring and rewriting large parts of the code * @version $Id: survey.php 17900 2009-01-21 17:02:59Z cvargas1 $ * * @todo use quickforms for the forms */ // name of the language file that needs to be included $language_file = 'survey'; // including the global dokeos file require ('../inc/global.inc.php'); // 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('Survey')); 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); // breadcrumbs $interbreadcrumb[] = array ("url" => "survey_list.php", "name" => get_lang('SurveyList')); // getting the survey information $survey_data = survey_manager::get_survey($_GET['survey_id']); if (substr($survey_data['title'],0,3)!='
'){
$tool_name = substr(html_entity_decode($survey_data['title'],ENT_QUOTES,$charset), 0, 40);
}else{
$tool_name = substr(html_entity_decode(substr($survey_data['title'],3,-4),ENT_QUOTES,$charset), 0, 40);
}
$is_survey_type_1 = ($survey_data['survey_type']==1)?true:false;
if (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']))
{
api_sql_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']))
{
api_sql_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($_GET['survey_id']).'\') ');
$sendmsg = 'GroupCreatedSuccessfully';
} else {
$sendmsg = 'GroupNeedName';
}
}
if($_GET['action']=='deletegroup'){
api_sql_query('DELETE FROM '.$table_survey_question_group.' WHERE id = '.Database::escape_string($_GET['gid']).' and survey_id = '.Database::escape_string($_GET['survey_id']));
$sendmsg = 'GroupDeletedSuccessfully';
}
header('Location:survey.php?survey_id='.(int)$_GET['survey_id'].'&sendmsg='.$sendmsg);
exit;
}
// Displaying the header
Display::display_header($tool_name,'Survey');
// Action handling
if (isset($_GET['action']))
{
if (($_GET['action'] == 'moveup' OR $_GET['action'] == 'movedown') AND isset($_GET['question_id']))
{
survey_manager::move_survey_question($_GET['action'], $_GET['question_id'], $_GET['survey_id']);
Display::display_confirmation_message(get_lang('SurveyQuestionMoved'), false);
}
if ($_GET['action'] == 'delete' AND is_numeric($_GET['question_id']))
{
survey_manager::delete_survey_question($_GET['survey_id'], $_GET['question_id'], $survey_data['is_shared']);
}
}
if (isset($_GET['message']))
{
// we have created the survey or updated the survey
if (in_array($_GET['message'], array('SurveyUpdatedSuccesfully','SurveyCreatedSuccesfully')))
{
Display::display_confirmation_message(get_lang($_GET['message']).'
'.get_lang('YouCanNowAddQuestionToYourSurvey'), false);
}
// we have added a question
if (in_array($_GET['message'], array('QuestionAdded','QuestionUpdated')))
{
Display::display_confirmation_message(get_lang($_GET['message']), false);
}
if (in_array($_GET['message'], array('YouNeedToCreateGroups')))
{
Display::display_warning_message(get_lang($_GET['message']), 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 = get_lang('Survey').': ';
$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 '
'.get_lang('YesNo').'';
echo '
'.get_lang('MultipleChoice').'';
echo '
'.get_lang('MultipleResponse').'';
echo '
'.get_lang('Open').'';
echo '
'.get_lang('Dropdown').'';
echo '
'.get_lang('Percentage').'';
echo '
'.get_lang('Score').'';
echo '
'.get_lang('Comment').'';
echo '
'.get_lang('Pagebreak').'';
echo '
'.get_lang('PersonalityQuestion').'';
echo '';
}
// Displaying the table header with all the questions
echo '| '.get_lang('QuestionNumber').' | '; echo ''.get_lang('Title').' | '; echo ''.get_lang('Type').' | '; echo ''.get_lang('NumberOfOptions').' | '; echo ''.get_lang('Modify').' | '; if($is_survey_type_1) { echo ''.get_lang('Condition').' | '; echo ''.get_lang('Group').' | '; } echo '
|---|---|---|---|---|---|---|
| '.$question_counter.' | '; echo ''; if (strlen($row['survey_question']) > 100) { echo substr(strip_tags($row['survey_question']),0, 100).' ... '; } else { echo $row['survey_question']; } echo ' | '; echo ''.get_lang(ucfirst($row['type'])).' | '; echo ''.$row['number_of_options'].' | '; echo '';
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 {
echo ' ';
}
if ($question_counter < $question_counter_max)
{
echo ' '.Display::return_icon('down.gif', get_lang('MoveDown')).'';
} else {
echo ' ';
}
echo ' | ';
$question_counter++;
if($is_survey_type_1)
{
echo ''.(($row['survey_group_pri']==0)?get_lang('Secondary'):get_lang('Primary')).' | '; echo ''.(($row['survey_group_pri']==0)?$groups[$row['survey_group_sec1']].'-'.$groups[$row['survey_group_sec2']]:$groups[$row['survey_group_pri']]).' | '; } echo '
| '.get_lang('Name').' | '.get_lang('Description').' |