, Ghent University: cleanup, refactoring and rewriting large parts (if not all) of the code * @author Julio Montoya Armas , Chamilo: Personality Test modification and rewriting large parts of the code * @version $Id: survey.lib.php 22296 2009-07-22 22:05:50Z cfasanando $ * * @todo move this file to inc/lib * @todo use consistent naming for the functions (save vs store for instance) */ $config['survey']['debug'] = false; //require_once '../inc/global.inc.php'; require_once api_get_path(LIBRARY_PATH).'sortabletable.class.php'; require_once api_get_path(LIBRARY_PATH).'usermanager.lib.php'; $htmlHeadXtra[] = ''; //jQuery $htmlHeadXtra[] = ''; class survey_manager { /*** * SYRVEY FUNCTIONS */ /** * This function retrieves all the survey information * * @param integer $survey_id the id of the survey * @param boolean $shared this parameter determines if we have to get the information of a survey from the central (shared) database or from the * course database * @param string course code optional * @return array * * @author Patrick Cool , Ghent University * @version February 2007 * * @todo this is the same function as in create_new_survey.php */ function get_survey($survey_id, $shared = 0, $course_code = '') { global $_course; // Table definition if (!empty($course_code)) { $my_course_id = $course_code; } else if (isset($_GET['course'])) { $my_course_id = Security::remove_XSS($_GET['course']); } else { $my_course_id = api_get_course_id(); } $my_course_info = api_get_course_info($my_course_id); $table_survey = Database :: get_course_table(TABLE_SURVEY, $my_course_info['dbName']); if ($shared != 0) { $table_survey = Database :: get_main_table(TABLE_MAIN_SHARED_SURVEY_QUESTION); } $sql = "SELECT * FROM $table_survey WHERE survey_id='".Database::escape_string($survey_id)."'"; $result = Database::query($sql); $return = array(); if (Database::num_rows($result)> 0) { $return = Database::fetch_array($result,'ASSOC'); // 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']; $return['survey_title'] = $return['title']; $return['survey_subtitle'] = $return['subtitle']; $return['survey_language'] = $return['lang']; $return['start_date'] = $return['avail_from']; $return['end_date'] = $return['avail_till']; $return['survey_share'] = $return['is_shared']; $return['survey_introduction'] = $return['intro']; $return['survey_thanks'] = $return['surveythanks']; $return['survey_type'] = $return['survey_type']; $return['one_question_per_page']= $return['one_question_per_page']; $return['show_form_profile'] = $return['show_form_profile']; $return['input_name_list'] = $return['input_name_list']; $return['shuffle'] = $return['shuffle']; $return['parent_id'] = $return['parent_id']; $return['survey_version'] = $return['survey_version']; return $return; } else { return $return; } } /** * This function stores a survey in the database. * * @param array $values * @return array $return the type of return message that has to be displayed and the message in it * * @author Patrick Cool , Ghent University * @version February 2007 */ function store_survey($values) { global $_user; // Table defnitions $table_survey = Database :: get_course_table(TABLE_SURVEY); /*if ($values['survey_share']['survey_share'] !== '0') { $shared_survey_id = survey_manager::store_shared_survey($values); }*/ $shared_survey_id = 0; if (!$values['survey_id'] || !is_numeric($values['survey_id'])) { // Check if the code doesn't soon exists in this language $sql = 'SELECT 1 FROM '.$table_survey.' WHERE code="'.Database::escape_string($values['survey_code']).'" AND lang="'.Database::escape_string($values['survey_language']).'"'; $rs = Database::query($sql); if (Database::num_rows($rs) > 0) { $return['message'] = 'ThisSurveyCodeSoonExistsInThisLanguage'; $return['type'] = 'error'; $return['id'] = isset($values['survey_id']) ? $values['survey_id'] : 0; return $return; } if ($values['anonymous'] == '') { $values['anonymous'] = 0; } $additional['columns'] = ''; $additional['values'] = ''; if ($values['anonymous'] == 0) { // Input_name_list $additional['columns'] .= ', show_form_profile'; $additional['values'] .= ",'".Database::escape_string($values['show_form_profile'])."'"; if ($values['show_form_profile'] == 1) { // Input_name_list $fields = explode(',', $values['input_name_list']); $field_values = ''; foreach ($fields as & $field) { if ($field != '') { if ($values[$field] == '') { $values[$field] = 0; } $field_values.= $field.':'.$values[$field].'@'; } } $additional['columns'] .= ', form_fields'; $additional['values'] .= ",'".Database::escape_string($field_values)."'"; } else { $additional['columns'] .= ', form_fields'; $additional['values'] .= ",''"; } } else { // Input_name_list $additional['columns'] .= ', show_form_profile'; $additional['values'] .= ",'0'"; $additional['columns'] .= ', form_fields'; $additional['values'] .= ",''"; } if ($values['survey_type'] == 1) { $additional['columns'] .= ', survey_type'; $additional['values'] .= ",'1'"; $additional['columns'] .= ', shuffle'; $additional['values'] .= ",'".Database::escape_string($values['shuffle'])."'"; $additional['columns'] .= ', one_question_per_page'; $additional['values'] .= ",'".Database::escape_string($values['one_question_per_page'])."'"; $additional['columns'] .= ', parent_id'; $additional['values'] .= ",'".Database::escape_string($values['parent_id'])."'"; // Logic for versioning surveys if (!empty($values['parent_id'])) { $additional['columns'] .= ', survey_version'; $sql = 'SELECT survey_version FROM '.$table_survey.' WHERE parent_id = '.Database::escape_string($values['parent_id']).' ORDER BY survey_version DESC LIMIT 1'; $rs = Database::query($sql); if (Database::num_rows($rs) === 0) { $sql = 'SELECT survey_version FROM '.$table_survey.' WHERE survey_id = '.Database::escape_string($values['parent_id']); $rs = Database::query($sql); $getversion = Database::fetch_array($rs, 'ASSOC'); if (empty($getversion['survey_version'])) { $additional['values'] .= ",'".++$getversion['survey_version']."'"; } else { $additional['values'] .= ",'".$getversion['survey_version'].".1'"; } } else { $row = Database::fetch_array($rs, 'ASSOC'); $pos = api_strpos($row['survey_version']); if ($pos === false) { //$new_version = substr($row['survey_version'],$pos, count()) $row['survey_version'] = $row['survey_version'] + 1; $additional['values'] .= ",'".$row['survey_version']."'"; } else { $getlast = api_split('\.', $row['survey_version']); $lastversion = array_pop($getlast); $lastversion = $lastversion + 1; $add = implode('.', $getlast); if ($add != '') { $insertnewversion = $add.'.'.$lastversion; } else { $insertnewversion = $lastversion; } $additional['values'] .= ",'".$insertnewversion."'"; } } } } $sql = "INSERT INTO $table_survey (code, title, subtitle, author, lang, avail_from, avail_till, is_shared, template, intro, surveythanks, creation_date, anonymous".$additional['columns'].", session_id) VALUES ( '".Database::escape_string(strtolower(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'])."', '".Database::escape_string($values['survey_language'])."', '".Database::escape_string($values['start_date'])."', '".Database::escape_string($values['end_date'])."', '".Database::escape_string($shared_survey_id)."', '".Database::escape_string('template')."', '".Database::escape_string($values['survey_introduction'])."', '".Database::escape_string($values['survey_thanks'])."', '".date('Y-m-d H:i:s')."', '".Database::escape_string($values['anonymous'])."'".$additional['values'].", ".intval($_SESSION['id_session'])." )"; $result = Database::query($sql); $survey_id = Database::insert_id(); if ($survey_id > 0) { // Insert into item_property api_item_property_update(api_get_course_info(), TOOL_SURVEY, $survey_id, 'SurveyAdded', api_get_user_id()); } if ($values['survey_type'] == 1 && !empty($values['parent_id'])) { survey_manager::copy_survey($values['parent_id'],$survey_id); } //$return['message'] = get_lang('SurveyCreatedSuccesfully').'
'.get_lang('YouCanNowAddQuestionToYourSurvey').': '; //$return['message'] .= ''.get_lang('ClickHere').''; $return['message'] = 'SurveyCreatedSuccesfully'; $return['type'] = 'confirmation'; $return['id'] = $survey_id; } else { // Check whether the code doesn't soon exists in this language $sql = 'SELECT 1 FROM '.$table_survey.' WHERE code="'.Database::escape_string($values['survey_code']).'" AND lang="'.Database::escape_string($values['survey_language']).'" AND survey_id!='.intval($values['survey_id']); $rs = Database::query($sql); if (Database::num_rows($rs) > 0) { $return['message'] = 'ThisSurveyCodeSoonExistsInThisLanguage'; $return['type'] = 'error'; $return['id'] = isset($values['survey_id']) ? $values['survey_id'] : 0; return $return; } if ($values['anonymous'] == '') { $values['anonymous'] = 0; } $additionalsets = ", shuffle = '".Database::escape_string($values['shuffle'])."'"; $additionalsets .= ", one_question_per_page = '".Database::escape_string($values['one_question_per_page'])."'"; if ($values['anonymous'] == 0) { $additionalsets .= ", show_form_profile = '".Database::escape_string($values['show_form_profile'])."'"; if ($values['show_form_profile'] == 1) { $fields = explode(',',$values['input_name_list']); $field_values = ''; foreach ($fields as & $field) { if ($field != '') { if ($values[$field] == '') { $values[$field] = 0; } $field_values.= $field.':'.$values[$field].'@'; } } $additionalsets .= ", form_fields = '".Database::escape_string($field_values)."'"; } else { $additionalsets .= ", form_fields = '' "; } } else { $additionalsets .= ", show_form_profile = '0'"; $additionalsets .= ", form_fields = '' "; } $sql = "UPDATE $table_survey SET 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'])."', avail_from = '".Database::escape_string($values['start_date'])."', avail_till = '".Database::escape_string($values['end_date'])."', is_shared = '".Database::escape_string($shared_survey_id)."', template = '".Database::escape_string('template')."', intro = '".Database::escape_string($values['survey_introduction'])."', surveythanks = '".Database::escape_string($values['survey_thanks'])."', anonymous = '".Database::escape_string($values['anonymous'])."'".$additionalsets." WHERE survey_id = '".Database::escape_string($values['survey_id'])."'"; $result = Database::query($sql); // Update into item_property (update) api_item_property_update(api_get_course_info(), TOOL_SURVEY, Database::escape_string($values['survey_id']), 'SurveyUpdated', api_get_user_id()); //$return['message'] = get_lang('SurveyUpdatedSuccesfully').'
'.get_lang('YouCanNowAddQuestionToYourSurvey').': '; //$return['message'] .= ''.get_lang('Here').''; //$return['message'] .= get_lang('OrReturnToSurveyOverview').''.get_lang('Here').''; $return['message'] = 'SurveyUpdatedSuccesfully'; $return['type'] = 'confirmation'; $return['id'] = $values['survey_id']; } return $return; } /** * This function stores a shared survey in the central database. * * @param array $values * @return array $return the type of return message that has to be displayed and the message in it * * @author Patrick Cool , Ghent University * @version February 2007 */ function store_shared_survey($values) { global $_user, $_course; // Table defnitions $table_survey = Database :: get_main_table(TABLE_MAIN_SHARED_SURVEY); 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'])."', '".date('Y-m-d H:i:s')."', '".$_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'])."' WHERE survey_id = '".Database::escape_string($values['survey_share']['survey_share'])."'"; $result = Database::query($sql); $return = $values['survey_share']['survey_share']; } return $return; } /** * This function deletes a survey (and also all the question in that survey * * @param $survey_id the id of the survey that has to be deleted * @return true * * @author Patrick Cool , Ghent University * @version January 2007 */ function delete_survey($survey_id, $shared=false, $course_code = '') { // Database table definitions $table_survey = Database :: get_course_table(TABLE_SURVEY,$course_code); $table_survey_question_group = Database :: get_course_table(TABLE_SURVEY_QUESTION_GROUP, $course_code); if ($shared) { $table_survey = Database :: get_main_table(TABLE_MAIN_SHARED_SURVEY); } // Deleting the survey $sql = "DELETE from $table_survey WHERE survey_id='".Database::escape_string($survey_id)."'"; $res = Database::query($sql); // Deleting groups of this survey $sql = "DELETE from $table_survey_question_group WHERE survey_id='".Database::escape_string($survey_id)."'"; $res = Database::query($sql); // Deleting the questions of the survey survey_manager::delete_all_survey_questions($survey_id, $shared); // Update into item_property (delete) api_item_property_update(api_get_course_info(), TOOL_SURVEY, Database::escape_string($survey_id), 'delete', api_get_user_id()); return true; } function copy_survey($parent_survey, $new_survey_id) { // Database table definitions $table_survey = Database :: get_course_table(TABLE_SURVEY); $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); // Get groups $sql = "SELECT * from $table_survey_question_group WHERE survey_id='".$parent_survey."'"; $res = Database::query($sql); if (Database::num_rows($res) === 0) { return true; } while($row = Database::fetch_array($res, 'ASSOC')){ $sql1 = 'INSERT INTO '.$table_survey_question_group.' (name,description,survey_id) VALUES (\''.Database::escape_string($row['name']).'\',\''.Database::escape_string($row['description']).'\',\''.$new_survey_id.'\')'; $res1 = Database::query($sql1); $group_id[$row['id']] = Database::insert_id(); } // Get questions $sql = "SELECT * FROM $table_survey_question WHERE survey_id='".$parent_survey."'"; $res = Database::query($sql); while($row = Database::fetch_array($res, 'ASSOC')){ $sql2 = 'INSERT INTO '.$table_survey_question.' (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 '. '(\''.$new_survey_id.'\',\''.Database::escape_string($row['survey_question']).'\',\''.Database::escape_string($row['survey_comment']).'\',\''.$row['type'].'\',\''.$row['display'].'\',\''.$row['sort'].'\',\''.$row['shared_question_id'].'\',\''.$row['max_value']. '\',\''.$group_id[$row['survey_group_pri']].'\',\''.$group_id[$row['survey_group_sec1']].'\',\''.$group_id[$row['survey_group_sec2']].'\')'; $res2 = Database::query($sql2); $question_id[$row['question_id']] = Database::insert_id(); } // Get questions options $sql = "SELECT * FROM $table_survey_options WHERE survey_id='".$parent_survey."'"; $res = Database::query($sql); while($row = Database::fetch_array($res ,'ASSOC')){ $sql3 = 'INSERT INTO '.$table_survey_options.' (question_id,survey_id,option_text,sort,value) VALUES ('. "'".$question_id[$row['question_id']]."','".$new_survey_id."','".Database::escape_string($row['option_text'])."','".$row['sort']."','".$row['value']."')"; $res3 = Database::query($sql3); } return true; } /** * This function duplicates a survey (and also all the question in that survey * * @param $survey_id the id of the survey that has to be duplicated * @return true * * @author Eric Marguin , Elixir Interactive * @version October 2007 */ function empty_survey($survey_id) { // Database table definitions $table_survey_invitation = Database :: get_course_table(TABLE_SURVEY_INVITATION); $table_survey_answer = Database :: get_course_table(TABLE_SURVEY_ANSWER); $table_survey = Database :: get_course_table(TABLE_SURVEY); $datas = survey_manager::get_survey($survey_id); $session_where = ''; if (api_get_session_id() != 0) { $session_where = ' AND session_id = "'.api_get_session_id().'" '; } $sql = 'DELETE FROM '.$table_survey_invitation.' WHERE survey_code = "'.Database::escape_string($datas['code']).'" '.$session_where.' '; Database::query($sql); $sql = 'DELETE FROM '.$table_survey_answer.' WHERE survey_id='.intval($survey_id); Database::query($sql); $sql = 'UPDATE '.$table_survey.' SET invited=0, answered=0 WHERE survey_id='.intval($survey_id); Database::query($sql); return true; } /** * This function recalculates the number of people who have taken the survey (=filled at least one question) * * @param $survey_id the id of the survey somebody * @return true * * @author Patrick Cool , Ghent University * @version February 2007 */ function update_survey_answered($survey_id, $user, $survey_code) { global $_course; // Database table definitions $table_survey = Database :: get_course_table(TABLE_SURVEY, $_course['db_name']); $table_survey_invitation = Database :: get_course_table(TABLE_SURVEY_INVITATION, $_course['db_name']); // Getting a list with all the people who have filled the survey $people_filled = survey_manager::get_people_who_filled_survey($survey_id); $number = count($people_filled); // Storing this value in the survey table $sql = "UPDATE $table_survey SET answered = '".Database::escape_string($number)."' WHERE survey_id = '".Database::escape_string($survey_id)."'"; $res = Database::query($sql); // Storing that the user has finished the survey. $sql = "UPDATE $table_survey_invitation SET answered='1' WHERE session_id='".api_get_session_id()."' AND user='".Database::escape_string($user)."' AND survey_code='".Database::escape_string($survey_code)."'"; $res = Database::query($sql); } /** * This function gets a complete structure of a survey (all survey information, all question information * of all the questions and all the options of all the questions. * * @param integer $survey_id the id of the survey * @param boolean $shared this parameter determines if we have to get the information of a survey from the central (shared) database or from the * course database * * @author Patrick Cool , Ghent University * @version February 2007 */ function get_complete_survey_structure($survey_id, $shared = 0) { // Database table definitions $table_survey = Database :: get_course_table(TABLE_SURVEY); $table_survey_question = Database :: get_course_table(TABLE_SURVEY_QUESTION); $table_survey_question_option = Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION); if ($shared != 0) { $table_survey = Database :: get_main_table(TABLE_MAIN_SHARED_SURVEY_QUESTION); $table_survey_question = Database :: get_course_table(TABLE_SHARED_SURVEY_QUESTION); $table_survey_question_option = Database :: get_main_table(TABLE_MAIN_SHARED_SURVEY_QUESTION_OPTION); } $structure = survey_manager::get_survey($survey_id, $shared); $structure['questions'] = survey_manager::get_questions($survey_id); } /*** * SYRVEY QUESTION FUNCTIONS */ /** * This function return the "icon" of the question type * * @author Patrick Cool , Ghent University * @version February 2007 */ function icon_question($type) { // the possible question types $possible_types = array('personality', 'yesno', 'multiplechoice', 'multipleresponse', 'open', 'dropdown', 'comment', 'pagebreak', 'percentage', 'score'); // the images array $icon_question = array( 'yesno' => 'yesno.gif', 'personality' => 'yesno.gif', 'multiplechoice' => 'mcua.gif', 'multipleresponse' => 'mcma.gif', 'open' => 'open_answer.gif', 'dropdown' => 'dropdown.gif', 'percentage' => 'percentagequestion.gif', 'score' => 'scorequestion.gif', 'comment' => 'commentquestion.gif', 'pagebreak' => 'page_end.gif', ); if (in_array($type, $possible_types)) { return $icon_question[$type]; } else { return false; } } /** * This function retrieves all the information of a question * * @param integer $question_id the id of the question * @return array * * @author Patrick Cool , Ghent University * @version January 2007 * * @todo one sql call should do the trick */ function get_question($question_id, $shared = false) { // Table definitions $tbl_survey_question = Database :: get_course_table(TABLE_SURVEY_QUESTION); $table_survey_question_option = Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION); if ($shared) { $tbl_survey_question = Database :: get_main_table(TABLE_MAIN_SHARED_SURVEY_QUESTION); $table_survey_question_option = Database :: get_main_table(TABLE_MAIN_SHARED_SURVEY_QUESTION_OPTION); } // Getting the information of the question $sql = "SELECT * FROM $tbl_survey_question WHERE question_id='".Database::escape_string($question_id)."' ORDER BY `sort`"; $result = Database::query($sql); $row = Database::fetch_array($result,'ASSOC'); $return['survey_id'] = $row['survey_id']; $return['question_id'] = $row['question_id']; $return['type'] = $row['type']; $return['question'] = $row['survey_question']; $return['horizontalvertical'] = $row['display']; $return['shared_question_id'] = $row['shared_question_id']; $return['maximum_score'] = $row['max_value']; if ($row['survey_group_pri'] != 0) { $return['assigned'] = $row['survey_group_pri']; $return['choose'] = 1; } else { $return['assigned1'] = $row['survey_group_sec1']; $return['assigned2'] = $row['survey_group_sec2']; $return['choose'] = 2; } // Getting the information of the question options $sql = "SELECT * FROM $table_survey_question_option WHERE question_id='".Database::escape_string($question_id)."' ORDER BY `sort` "; $result = Database::query($sql); while ($row = Database::fetch_array($result, 'ASSOC')) { /** @todo this should be renamed to options instead of answers */ $return['answers'][] = $row['option_text']; $return['values'][] = $row['value']; /** @todo this can be done more elegantly (used in reporting) */ $return['answersid'][] = $row['question_option_id']; } return $return; } /** * This function gets all the question of any given survey * * @param integer $survey_id the id of the survey * @return array containing all the questions of the survey * * @author Patrick Cool , Ghent University * @version February 2007 * * @todo one sql call should do the trick */ function get_questions($survey_id) { // Table definitions $tbl_survey_question = Database :: get_course_table(TABLE_SURVEY_QUESTION); $table_survey_question_option = Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION); // Getting the information of the question $sql = "SELECT * FROM $tbl_survey_question WHERE survey_id='".Database::escape_string($survey_id)."'"; $result = Database::query($sql); while ($row = Database::fetch_array($result, 'ASSOC')) { $return[$row['question_id']]['survey_id'] = $row['survey_id']; $return[$row['question_id']]['question_id'] = $row['question_id']; $return[$row['question_id']]['type'] = $row['type']; $return[$row['question_id']]['question'] = $row['survey_question']; $return[$row['question_id']]['horizontalvertical'] = $row['display']; $return[$row['question_id']]['maximum_score'] = $row['max_value']; $return[$row['question_id']]['sort'] = $row['sort']; } // Getting the information of the question options $sql = "SELECT * FROM $table_survey_question_option WHERE survey_id='".Database::escape_string($survey_id)."'"; $result = Database::query($sql); while ($row = Database::fetch_array($result, 'ASSOC')) { $return[$row['question_id']]['answers'][] = $row['option_text']; } return $return; } /** * This function saves a question in the database. * This can be either an update of an existing survey or storing a new survey * * @param array $form_content all the information of the form * * @author Patrick Cool , Ghent University * @version January 2007 */ function save_question($form_content) { global $survey_data; if (strlen($form_content['question']) > 1) { // Checks lenght of the question $empty_answer = false; if ($survey_data['survey_type'] == 1) { if (empty($form_content['choose'])) { $return_message = 'PleaseChooseACondition'; return $return_message; } if (($form_content['choose']==2)&&($form_content['assigned1'] == $form_content['assigned2'])) { $return_message = 'ChooseDifferentCategories'; return $return_message; } } if ($form_content['type'] != 'percentage') { for ($i = 0; $i < count($form_content['answers']); $i++) { if (strlen($form_content['answers'][$i]) < 1) { $empty_answer = true; break; } } } if ($form_content['type'] == 'score') { if (strlen($form_content['maximum_score']) < 1) { $empty_answer = true; } } $additional = array(); if (!$empty_answer) { global $_course; // Table definitions $table_survey = Database :: get_course_table(TABLE_SURVEY, $_course['db_name']); $tbl_survey_question = Database :: get_course_table(TABLE_SURVEY_QUESTION, $_course['db_name']); // Getting all the information of the survey $survey_data = survey_manager::get_survey($form_content['survey_id']); // Storing the question in the shared database if (is_numeric($survey_data['survey_share']) && $survey_data['survey_share'] != 0) { $shared_question_id = survey_manager::save_shared_question($form_content, $survey_data); $form_content['shared_question_id'] = $shared_question_id; } // Storing a new question if ($form_content['question_id'] == '' || !is_numeric($form_content['question_id'])) { // Finding the max sort order of the questions in the given survey $sql = "SELECT max(sort) AS max_sort FROM $tbl_survey_question WHERE survey_id='".Database::escape_string($form_content['survey_id'])."'"; $result = Database::query($sql); $row = Database::fetch_array($result,'ASSOC'); $max_sort = $row['max_sort']; // Some variables defined for survey-test type $additional['column'] = ''; $additional['value'] = ''; if ($_POST['choose'] == 1) { $additional['column'] = ',survey_group_pri'; $additional['value'] = ",'".Database::escape_string($_POST['assigned'])."'"; } elseif($_POST['choose'] == 2) { $additional['column'] = ',survey_group_sec1, survey_group_sec2'; $additional['value'] = ",'".Database::escape_string($_POST['assigned1'])."'".",'".Database::escape_string($_POST['assigned2'])."'"; } // Adding the question to the survey_question table $sql = "INSERT INTO $tbl_survey_question (survey_id,survey_question,survey_question_comment,type,display, sort, shared_question_id, max_value".$additional['column'].") VALUES ( '".Database::escape_string($form_content['survey_id'])."', '".Database::escape_string($form_content['question'])."', '".Database::escape_string($form_content['question_comment'])."', '".Database::escape_string($form_content['type'])."', '".Database::escape_string($form_content['horizontalvertical'])."', '".Database::escape_string($max_sort+1)."', '".Database::escape_string($form_content['shared_question_id'])."', '".Database::escape_string($form_content['maximum_score'])."'". $additional['value']." )"; $result = Database::query($sql); $question_id = Database::insert_id(); $form_content['question_id'] = $question_id; $return_message = 'QuestionAdded'; } // Updating an existing question else { $additionalsets = ''; if ($_POST['choose'] == 1) { $additionalsets = ',survey_group_pri = \''.Database::escape_string($_POST['assigned']).'\', survey_group_sec1 = \'0\', survey_group_sec2 = \'0\' '; } elseif ($_POST['choose'] == 2) { $additionalsets = ',survey_group_pri = \'0\', survey_group_sec1 = \''.Database::escape_string($_POST['assigned1']).'\', survey_group_sec2 = \''.Database::escape_string($_POST['assigned2']).'\' '; } $setadditionals = $additional['set'][1].$additional['set'][2].$additional['set'][3]; // Adding the question to the survey_question table $sql = "UPDATE $tbl_survey_question SET survey_question = '".Database::escape_string($form_content['question'])."', survey_question_comment = '".Database::escape_string($form_content['question_comment'])."', display = '".Database::escape_string($form_content['horizontalvertical'])."', max_value = '".Database::escape_string($form_content['maximum_score'])."'" . $additionalsets." WHERE question_id = '".Database::escape_string($form_content['question_id'])."'"; $result = Database::query($sql); $return_message = 'QuestionUpdated'; } // Storing the options of the question $message_options=survey_manager::save_question_options($form_content, $survey_data); } else { $return_message = 'PleasFillAllAnswer'; } } else { $return_message = 'PleaseEnterAQuestion'; } return $return_message; } /** * This function saves the question in the shared database * * @param array $form_content all the information of the form * @param array $survey_data all the information of the survey * * @author Patrick Cool , Ghent University * @version February 2007 * * @todo editing of a shared question */ function save_shared_question($form_content, $survey_data) { global $_course; // Table definitions $tbl_survey_question = Database :: get_main_table(TABLE_MAIN_SHARED_SURVEY_QUESTION); // Storing a new question if ($form_content['shared_question_id'] == '' || !is_numeric($form_content['shared_question_id'])) { // Finding the max sort order of the questions in the given survey $sql = "SELECT max(sort) AS max_sort FROM $tbl_survey_question WHERE survey_id='".Database::escape_string($survey_data['survey_share'])."' AND code='".Database::escape_string($_course['id'])."'"; $result = Database::query($sql); $row = Database::fetch_array($result,'ASSOC'); $max_sort = $row['max_sort']; // Adding the question to the survey_question table $sql = "INSERT INTO $tbl_survey_question (survey_id, survey_question, survey_question_comment, type, display, sort, code) VALUES ( '".Database::escape_string($survey_data['survey_share'])."', '".Database::escape_string($form_content['question'])."', '".Database::escape_string($form_content['question_comment'])."', '".Database::escape_string($form_content['type'])."', '".Database::escape_string($form_content['horizontalvertical'])."', '".Database::escape_string($max_sort+1)."', '".Database::escape_string($_course['id'])."')"; $result = Database::query($sql); $shared_question_id = Database::insert_id(); } // Updating an existing question else { // adding the question to the survey_question table $sql = "UPDATE $tbl_survey_question SET survey_question = '".Database::escape_string($form_content['question'])."', survey_question_comment = '".Database::escape_string($form_content['question_comment'])."', display = '".Database::escape_string($form_content['horizontalvertical'])."' WHERE question_id = '".Database::escape_string($form_content['shared_question_id'])."' AND code='".Database::escape_string($_course['id'])."'"; $result = Database::query($sql); $shared_question_id = $form_content['shared_question_id']; } return $shared_question_id; } /** * This functions moves a question of a survey up or down * * @param string $direction * @param integer $survey_question_id * @param integer $survey_id * * @author Patrick Cool , Ghent University * @version January 2007 */ function move_survey_question($direction, $survey_question_id, $survey_id) { // Table definition $table_survey_question = Database :: get_course_table(TABLE_SURVEY_QUESTION); if ($direction == 'moveup') { $sort = 'DESC'; } if ($direction == 'movedown') { $sort = 'ASC'; } // Finding the two questions that needs to be swapped $sql = "SELECT * FROM $table_survey_question WHERE survey_id='".Database::escape_string($survey_id)."' ORDER BY sort $sort"; $result = Database::query($sql); $found = false; while ($row = Database::fetch_array($result, 'ASSOC')) { if ($found) { $question_id_two = $row['question_id']; $question_sort_two = $row['sort']; $found = false; } if ($row['question_id'] == $survey_question_id) { $found = true; $question_id_one = $row['question_id']; $question_sort_one = $row['sort']; } } $sql1 = "UPDATE $table_survey_question SET sort = '".Database::escape_string($question_sort_two)."' WHERE question_id='".Database::escape_string($question_id_one)."'"; $result = Database::query($sql1); $sql2 = "UPDATE $table_survey_question SET sort = '".Database::escape_string($question_sort_one)."' WHERE question_id='".Database::escape_string($question_id_two)."'"; $result = Database::query($sql2); } /** * This function deletes all the questions of a given survey * This function is normally only called when a survey is deleted * * @param $survey_id the id of the survey that has to be deleted * @return true * * @author Patrick Cool , Ghent University * @version January 2007 */ function delete_all_survey_questions($survey_id, $shared = false) { // Table definitions $table_survey_question = Database :: get_course_table(TABLE_SURVEY_QUESTION); if ($shared) { $table_survey_question = Database :: get_main_table(TABLE_MAIN_SHARED_SURVEY_QUESTION); } // Deleting the survey questions $sql = "DELETE from $table_survey_question WHERE survey_id='".Database::escape_string($survey_id)."'"; $res = Database::query($sql); // Deleting all the options of the questions of the survey survey_manager::delete_all_survey_questions_options($survey_id, $shared); // Deleting all the answers on this survey survey_manager::delete_all_survey_answers($survey_id); } /** * This function deletes a survey question and all its options * * @param integer $survey_id the id of the survey * @param integer $question_id the id of the question * @param integer $shared * * @todo also delete the answers to this question * * @author Patrick Cool , Ghent University * @version March 2007 */ function delete_survey_question($survey_id, $question_id, $shared = false) { // Table definitions $table_survey_question = Database :: get_course_table(TABLE_SURVEY_QUESTION); if ($shared) { survey_manager::delete_shared_survey_question($survey_id, $question_id); } // Deleting the survey questions $sql = "DELETE from $table_survey_question WHERE survey_id='".Database::escape_string($survey_id)."' AND question_id='".Database::escape_string($question_id)."'"; $res = Database::query($sql); // Deleting the options of the question of the survey survey_manager::delete_survey_question_option($survey_id, $question_id, $shared); } /** * This function deletes a shared survey question from the main database and all its options * * @param integer $question_id the id of the question * @param integer $shared * * @todo delete all the options of this question * * @author Patrick Cool , Ghent University * @version March 2007 */ function delete_shared_survey_question($survey_id, $question_id) { // Table definitions $table_survey_question = Database :: get_main_table(TABLE_MAIN_SHARED_SURVEY_QUESTION); $table_survey_question_option = Database :: get_main_table(TABLE_MAIN_SHARED_SURVEY_QUESTION_OPTION); // First we have to get the shared_question_id $question_data = survey_manager::get_question($question_id); // Deleting the survey questions $sql = "DELETE FROM $table_survey_question WHERE question_id='".Database::escape_string($question_data['shared_question_id'])."'"; $res = Database::query($sql); // Deleting the options of the question of the survey question $sql = "DELETE FROM $table_survey_question_option WHERE question_id='".Database::escape_string($question_data['shared_question_id'])."'"; $res = Database::query($sql); } /** * SURVEY QUESTION OPTIONS FUNCTIONS */ /** * This function stores the options of the questions in the table * * @param array $form_content * @return * @author Patrick Cool , Ghent University * @version January 2007 * * @todo writing the update statement when editing a question */ function save_question_options($form_content, $survey_data) { // A percentage question type has options 1 -> 100 if ($form_content['type'] == 'percentage') { for($i = 1; $i < 101; $i++) { $form_content['answers'][] = $i; } } if (is_numeric($survey_data['survey_share']) && $survey_data['survey_share'] != 0) { survey_manager::save_shared_question_options($form_content, $survey_data); } // Table defintion $table_survey_question_option = Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION); // We are editing a question so we first have to remove all the existing options from the database if (is_numeric($form_content['question_id'])) { $sql = "DELETE FROM $table_survey_question_option WHERE question_id = '".Database::escape_string($form_content['question_id'])."'"; $result = Database::query($sql); } $counter = 1; if (is_array($form_content['answers'])) { //foreach ($form_content['answers'] as $key => $answer) { for ($i = 0; $i < count($form_content['answers']); $i++) { $sql = "INSERT INTO $table_survey_question_option (question_id, survey_id, option_text, value,sort) VALUES ( '".Database::escape_string($form_content['question_id'])."', '".Database::escape_string($form_content['survey_id'])."', '".Database::escape_string($form_content['answers'][$i])."', '".Database::escape_string($form_content['values'][$i])."', '".Database::escape_string($counter)."')"; $result = Database::query($sql); $counter++; } } } /** * This function stores the options of the questions in the shared table * * @param array $form_content * @return * * @author Patrick Cool , Ghent University * @version February 2007 * * @todo writing the update statement when editing a question */ function save_shared_question_options($form_content, $survey_data) { if (is_array($form_content) && is_array($form_content['answers'])) { // Table defintion $table_survey_question_option = Database :: get_main_table(TABLE_MAIN_SHARED_SURVEY_QUESTION_OPTION); // We are editing a question so we first have to remove all the existing options from the database $sql = "DELETE FROM $table_survey_question_option WHERE question_id = '".Database::escape_string($form_content['shared_question_id'])."'"; $result = Database::query($sql); $counter = 1; foreach ($form_content['answers'] as $key => & $answer) { $sql = "INSERT INTO $table_survey_question_option (question_id, survey_id, option_text, sort) VALUES ( '".Database::escape_string($form_content['shared_question_id'])."', '".Database::escape_string($survey_data['is_shared'])."', '".Database::escape_string($answer)."', '".Database::escape_string($counter)."')"; $result = Database::query($sql); $counter++; } } } /* if (is_numeric($survey_data['survey_share']) AND $survey_data['survey_share'] != 0) { $form_content = survey_manager::save_shared_question($form_content, $survey_data); } */ /** * This function deletes all the options of the questions of a given survey * This function is normally only called when a survey is deleted * * @param $survey_id the id of the survey that has to be deleted * @return true * * @author Patrick Cool , Ghent University * @version January 2007 */ function delete_all_survey_questions_options($survey_id, $shared = false) { // Table definitions $table_survey_question_option = Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION); if ($shared) { $table_survey_question = Database :: get_main_table(TABLE_MAIN_SHARED_SURVEY_QUESTION_OPTION); } // Deleting the options of the survey questions $sql = "DELETE from $table_survey_question_option WHERE survey_id='".Database::escape_string($survey_id)."'"; $res = Database::query($sql); return true; } /** * This function deletes the options of a given question * * @param unknown_type $survey_id * @param unknown_type $question_id * @param unknown_type $shared * @return unknown * * @author Patrick Cool , Ghent University * @version March 2007 */ function delete_survey_question_option($survey_id, $question_id, $shared = false) { // Table definitions $table_survey_question_option = Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION); if ($shared) { $table_survey_question = Database :: get_main_table(TABLE_MAIN_SHARED_SURVEY_QUESTION_OPTION); } // Deleting the options of the survey questions $sql = "DELETE from $table_survey_question_option WHERE survey_id='".Database::escape_string($survey_id)."' AND question_id='".Database::escape_string($question_id)."'"; $res = Database::query($sql); return true; } /** * SURVEY ANSWERS FUNCTIONS */ /** * This function deletes all the answers anyone has given on this survey * This function is normally only called when a survey is deleted * * @param $survey_id the id of the survey that has to be deleted * @return true * * @todo write the function * * @author Patrick Cool , Ghent University * @version January 2007,december 2008 */ function delete_all_survey_answers($survey_id) { $table_survey_answer = Database :: get_course_table(TABLE_SURVEY_ANSWER); Database::query('DELETE FROM '.$table_survey_answer.' WHERE survey_id='.$survey_id); return true; } /** * This function gets all the persons who have filled the survey * * @param integer $survey_id * @return array * * @author Patrick Cool , Ghent University * @version February 2007 */ function get_people_who_filled_survey($survey_id, $all_user_info = false) { global $_course; // Database table definition $table_survey_answer = Database :: get_course_table(TABLE_SURVEY_ANSWER, $_course['db_name']); $table_user = Database :: get_main_table('user'); // Variable initialisation $return = array(); // Getting the survey information $survey_data = survey_manager::get_survey($survey_id); if ($all_user_info) { $order_clause = api_sort_by_first_name() ? ' ORDER BY user.firstname, user.lastname' : ' ORDER BY user.lastname, user.firstname'; $sql = "SELECT DISTINCT answered_user.user as invited_user, user.firstname, user.lastname, user.user_id FROM $table_survey_answer answered_user LEFT JOIN $table_user as user ON answered_user.user = user.user_id WHERE survey_id= '".Database::escape_string($survey_data['survey_id'])."'". $order_clause; } else { $sql = "SELECT DISTINCT user FROM $table_survey_answer WHERE survey_id= '".Database::escape_string($survey_data['survey_id'])."'"; } $res = Database::query($sql); while ($row = Database::fetch_array($res, 'ASSOC')) { if ($all_user_info) { $return[] = $row; } else { $return[] = $row['user']; } } return $return; } } class survey_question { // The html code of the form public $html; /** * This function does the generic part of any survey question: the question field * * @author Patrick Cool , Ghent University * @version January 2007 * * @todo the form_text has to become a wysiwyg editor or adding a question_comment field * @todo consider adding a question_comment form element */ function create_form($form_content) { global $survey_data; //$tool_name = ''.get_lang(ucfirst($_GET['type'])).''; $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'); } if ($_GET['action'] == 'edit') { $tool_name .= get_lang('EditQuestion'); } if ($_GET['type'] == 'yesno') { $tool_name .= ': '.get_lang('YesNo'); } else if ($_GET['type'] == 'multiplechoice') { $tool_name .= ': '.get_lang('UniqueSelect'); } else { $tool_name .= ': '.get_lang(api_ucfirst(Security::remove_XSS($_GET['type']))); } $this->html .= '
'.$tool_name.'
'; $this->html .= '
'; $this->html .= ' '; $this->html .= ' '; $this->html .= ' '; $this->html .= ' '; // question field $this->html .= '
'; $this->html .= '
'; $this->html .= ' * '.get_lang('Question'); $this->html .= '
'; $this->html .= '
'; $this->html .= api_return_html_area('question', Security::remove_XSS(stripslashes($form_content['question']), STUDENT), '', '', null, array('ToolbarSet' => 'Survey', 'Width' => '100%', 'Height' => '120')); $this->html .= '
'; $this->html .= '
'; /* $this->html .= ' '; $this->html .= ' '; $this->html .= ' '; $this->html .= '  '; $this->html .= ' '; */ //$this->html .= ''; //$this->html .=' '; if ($survey_data['survey_type'] == 1) { $table_survey_question_group = Database::get_course_table(TABLE_SURVEY_QUESTION_GROUP); $sql = 'SELECT id,name FROM '.$table_survey_question_group.' WHERE survey_id = '.(int)$_GET['survey_id'].' ORDER BY name'; $rs = Database::query($sql); while($row = Database::fetch_array($rs, 'NUM')) { $glist .= ''; } $grouplist = $grouplist1 = $grouplist2 = $glist; if (!empty($form_content['assigned'])) { $grouplist = str_replace('
 
'.get_lang('Condition').' '.get_lang('Primary').'
'.'
'; $this->html .= ' '.get_lang('Secondary').'
'.' '. '' .'

'; } return $this->html; } /** * This functions displays the form after the html variable has correctly been finished * (adding a submit button, closing the table and closing the form) * * @author Patrick Cool , Ghent University * @version January 2007 * */ function render_form() { if (isset($_GET['question_id']) and !empty($_GET['question_id'])) { $class = 'save'; $text = get_lang('ModifyQuestionSurvey'); } else { $class = 'add'; $text = get_lang('CreateQuestionSurvey'); } if ($_GET['type'] == 'yesno' || $_GET['type'] == 'open'|| $_GET['type'] == 'percentage' || $_GET['type'] == 'comment' || $_GET['type'] == 'pagebreak') { $this->html .= '
'; $this->html .= '
'; $this->html .= '
'; $this->html .= '
'; } $this->html .= ' '; $this->html .= '
'; $this->html .= '
'; //$this->html .= '
'; $this->html .= '
'; echo $this->html; } /** * This function handles the actions on a question and its answers * * @todo consider using $form_content instead of $_POST * * @author Patrick Cool , Ghent University * @version January 2007 */ function handle_action($form_content) { global $config; // Moving an answer up if ($_POST['move_up']) { foreach ($_POST['move_up'] as $key => & $value) { $id1 = $key; $content1 = $form_content['answers'][$id1]; $id2 = $key - 1; $content2 = $form_content['answers'][$id2]; $form_content['answers'][$id1] = $content2; $form_content['answers'][$id2] = $content1; } } // Moving an answer down if ($_POST['move_down']) { foreach ($_POST['move_down'] as $key => & $value) { $id1 = $key; $content1 = $form_content['answers'][$id1]; $id2 = $key + 1; $content2 = $form_content['answers'][$id2]; $form_content['answers'][$id1] = $content2; $form_content['answers'][$id2] = $content1; } } // Adding an answer if (isset($_POST['add_answer'])) { $form_content['answers'][] = ''; } // Removing an answer if (isset($_POST['remove_answer'])) { $max_answer = count($form_content['answers']); unset($form_content['answers'][$max_answer - 1]); } // Saving a question if (isset($_POST['save_question'])) { $message = survey_manager::save_question($form_content); if ($message == 'QuestionAdded' || $message == 'QuestionUpdated' ) { $sql='SELECT COUNT(*) FROM '.Database :: get_course_table(TABLE_SURVEY_QUESTION).' WHERE survey_id = '.(int)$_GET['survey_id']; $res = Database :: fetch_array (Database::query($sql)); if ($config['survey']['debug']) { Display :: display_header(); Display :: display_confirmation_message($message.'
'.get_lang('ReturnTo').' '.get_lang('Survey').'', false); } else { header('Location:survey.php?survey_id='.Security::remove_XSS($_GET['survey_id']).'&message='.$message); exit(); } } else { if ($message == 'PleaseEnterAQuestion' || $message == 'PleasFillAllAnswer'|| $message == 'PleaseChooseACondition'|| $message == 'ChooseDifferentCategories') { $_SESSION['temp_user_message'] = $form_content['question']; $_SESSION['temp_horizontalvertical'] = $form_content['horizontalvertical']; $_SESSION['temp_sys_message'] = $message; $_SESSION['temp_answers'] = $form_content['answers']; $_SESSION['temp_values'] = $form_content['values']; header('location:question.php?'.api_get_cidreq().'&question_id='.Security::remove_XSS($_GET['question_id']).'&survey_id='.Security::remove_XSS($_GET['survey_id']).'&action='.Security::remove_XSS($_GET['action']).'&type='.Security::remove_XSS($_GET['type']).''); } } } /** * This solution is a little bit strange but I could not find a different solution. */ if ($_POST['delete_answer']) { foreach ($_POST['delete_answer'] as $key => & $value) { unset($form_content['answers'][$key]); $deleted = $key; } foreach ($form_content['answers'] as $key => & $value) { if ($key > $deleted) { $form_content['answers'][$key - 1] = $form_content['answers'][$key]; unset($form_content['answers'][$key]); } } } return $form_content; } /** * This functions adds two buttons. One to add an option, one to remove an option * * @param unknown_type $form_content * @return html code * * @author Patrick Cool , Ghent University * @version January 2007 */ function add_remove_buttons($form_content) { if (count($form_content['answers']) <= 2) { $remove_answer_attribute = 'disabled="disabled"'; } $return .= '
'; $return .= '
'; $return .= '
'; $return .= '
'; $return .= ' '; $return .= ' '; $return .= ' '; return $return; } /** * Render the question. In this case this starts with the form tag * * @param unknown_type $form_content * * @author Patrick Cool , Ghent University * @version January 2007 */ function render_question($form_content) { $this->html = '
'; echo $this->html; } } class ch_yesno extends survey_question { /** * This function creates the form elements for the yesno questions * * @author Patrick Cool , Ghent University * @version January 2007 */ function create_form($form_content) { $this->html = parent::create_form($form_content); // Horizontal or vertical $this->html .= '
'; $this->html .= '
'; $this->html .= get_lang('DisplayAnswersHorVert'); $this->html .= '
'; $this->html .= '
'; $this->html .= ' html .= 'checked="checked"'; } $this->html .= '/>'.get_lang('Horizontal').'
'; $this->html .= ' html .= 'checked="checked"'; } $this->html .= ' />'.get_lang('Vertical').''; $this->html .= '
'; $this->html .= '
'; // The options $this->html .= '
'; $this->html .= '
'; $this->html .= get_lang('AnswerOptions'); $this->html .= '
'; $this->html .= '
'; $this->html .= ' '; $this->html .= ' '; $this->html .= ' '; //$this->html .= ' '; $this->html .= ' '; $this->html .= ' '; $this->html .= ' '; $this->html .= ' '; $this->html .= ' '; //$this->html .= ' '; $this->html .= ' '; $this->html .= ' '; $this->html .= ' '; $this->html .= '
'.api_return_html_area('answers[0]', stripslashes($form_content['answers'][0]), '', '', null, array('ToolbarSet' => 'Survey', 'Width' => '100%', 'Height' => '120')).'
'.api_return_html_area('answers[1]', stripslashes($form_content['answers'][1]), '', '', null, array('ToolbarSet' => 'Survey', 'Width' => '100%', 'Height' => '120')).'
'; $this->html .= '
'; $this->html .= '
'; } /** * Render the yes not question type * * @param unknown_type $form_content * * @author Patrick Cool , Ghent University * @version January 2007 */ function render_question($form_content, $answers = array()) { if (is_array($form_content['options'])) { // Check if data is correct foreach ($form_content['options'] as $key => & $value) { $this->html .= '
'; $this->html .= ' html .= 'checked="checked"'; } $this->html .= ' />'.get_lang('Vertical').''; $this->html .= ' '; $this->html .= '  '; $this->html .= ' '; $this->html .= '   '; // The options $this->html .= ' '; $this->html .= ' '.get_lang('AnswerOptions').''; $this->html .= ' '; $total_number_of_answers = count($form_content['answers']); $question_values = array(); // Values of question options if (is_array($form_content['values'])) { // Check if data is correct foreach ($form_content['values'] as $key => & $value) { $question_values [] = ''; } } $count = 0; if (is_array($form_content['answers'])) { foreach ($form_content['answers'] as $key => & $value) { $this->html .= ' '; $this->html .= ' '; //$this->html .= ' '; $this->html .= ' '.api_return_html_area('answers['.$key.']', api_html_entity_decode(stripslashes($form_content['answers'][$key])), '', '', null, array('ToolbarSet' => 'Survey', 'Width' => '100%', 'Height' => '120')).''; $this->html .= ' '; if ($total_number_of_answers > 2) { $this->html .= $question_values[$count]; } if ($key < $total_number_of_answers - 1) { $this->html .= ' '; } if ($key > 0) { $this->html .= ' '; } if ($total_number_of_answers > 2) { $this->html .= ' '; } $this->html .= ' '; $this->html .= ' '; $count++; } } // The buttons for adding or removing //$this->html .= parent :: add_remove_buttons($form_content); } /** * Render the multiple response question type * * @param unknown_type $form_content * * @author Patrick Cool , Ghent University * @version January 2007 */ function render_question($form_content, $answers = array()) { $question = new ch_yesno(); $question->render_question($form_content, $answers); } } class ch_multipleresponse extends survey_question { /** * This function creates the form elements for the multiple response questions * * @author Patrick Cool , Ghent University * @version January 2007 */ function create_form($form_content) { $this->html = parent::create_form($form_content); // Horizontal or vertical $this->html .= '
'; $this->html .= '
'; $this->html .= get_lang('DisplayAnswersHorVert'); $this->html .= '
'; $this->html .= '
'; $this->html .= ' html .= 'checked="checked"'; } $this->html .= '/>'.get_lang('Horizontal').'
'; $this->html .= ' html .= 'checked="checked"'; } $this->html .= ' />'.get_lang('Vertical').''; $this->html .= '
'; $this->html .= '
'; // The options $this->html .= '
'; $this->html .= '
'; $this->html .= get_lang('AnswerOptions'); $this->html .= '
'; $this->html .= '
'; $total_number_of_answers = count($form_content['answers']); $this->html .= ' '; if (is_array($form_content['answers'])) { // Values of question options foreach ($form_content['answers'] as $key => & $value) { $this->html .= ' '; $this->html .= ' '; //$this->html .= ' '; $this->html .= ' '; $this->html .= ' '; $this->html .= ' '; } } // The buttons for adding or removing $this->html .= '
'.api_return_html_area('answers['.$key.']', api_html_entity_decode(stripslashes($form_content['answers'][$key]), ENT_QUOTES), '', '', null, array('ToolbarSet' => 'Survey', 'Width' => '100%', 'Height' => '120')).''; if ($key<$total_number_of_answers - 1) { $this->html .= ' '; } if ($key > 0) { $this->html .= ' '; } if ($total_number_of_answers > 2) { $this->html .= ' '; } $this->html .= '
'; $this->html .= '
'; $this->html .= '
'; $this->html .= parent :: add_remove_buttons($form_content); } /** * Render the multiple response question type * * @param unknown_type $form_content * * @author Patrick Cool , Ghent University * @version January 2007 */ function render_question($form_content, $answers = array()) { foreach ($form_content['options'] as $key => & $value) { $this->html .= '