diff --git a/main/survey/fillsurvey.php b/main/survey/fillsurvey.php index f30b55f63d..0aefa8688d 100644 --- a/main/survey/fillsurvey.php +++ b/main/survey/fillsurvey.php @@ -170,7 +170,7 @@ if (count($_POST) > 0) { // remark: when it is a multiple response then the value of the array is the option_id // when it is a scoring question then the key of the array is the option_id and the value is the value if (is_array($value)) { - SurveyUtil::remove_answer($survey_invitation['user'], $survey_invitation['survey_id'], $survey_question_id); + SurveyUtil::remove_answer($survey_invitation['user'], $survey_invitation['survey_id'], $survey_question_id, $course_id); foreach ($value as $answer_key => & $answer_value) { if ($types[$survey_question_id] == 'score') { $option_id = $answer_key; @@ -198,9 +198,8 @@ if (count($_POST) > 0) { } $survey_question_answer = $value; - SurveyUtil::remove_answer($survey_invitation['user'], $survey_invitation['survey_id'], $survey_question_id); + SurveyUtil::remove_answer($survey_invitation['user'], $survey_invitation['survey_id'], $survey_question_id, $course_id); SurveyUtil::store_answer($survey_invitation['user'], $survey_invitation['survey_id'], $survey_question_id, $value, $option_value, $survey_data); - //SurveyUtil::store_answer($user,$survey_id,$question_id, $option_id, $option_value, $survey_data); } } } @@ -227,14 +226,14 @@ if (count($_POST) > 0) { // Finding the question id by removing 'question' $survey_question_id = str_replace('question', '', $key); // We select the correct answer and the puntuacion - $sql = "SELECT value FROM $table_survey_question_option WHERE c_id = $course_id AND question_option_id='".Database::escape_string($value)."'"; + echo $sql = "SELECT value FROM $table_survey_question_option WHERE c_id = $course_id AND question_option_id='".Database::escape_string($value)."'"; $result = Database::query($sql); $row = Database::fetch_array($result, 'ASSOC'); $option_value = $row['value']; //$option_value = 0; $survey_question_answer = $value; // We save the answer after making sure that a possible previous attempt is deleted - SurveyUtil::remove_answer($survey_invitation['user'], $survey_invitation['survey_id'], $survey_question_id); + SurveyUtil::remove_answer($survey_invitation['user'], $survey_invitation['survey_id'], $survey_question_id, $course_id); SurveyUtil::store_answer($survey_invitation['user'], $survey_invitation['survey_id'], $survey_question_id, $value, $option_value, $survey_data); //SurveyUtil::store_answer($user,$survey_id,$question_id, $option_id, $option_value, $survey_data); } @@ -443,7 +442,7 @@ if (isset($_POST['finish_survey'])) { Display::display_confirmation_message(get_lang('SurveyFinished')); echo $survey_data['survey_thanks']; - survey_manager::update_survey_answered($survey_data['survey_id'], $survey_invitation['user'], $survey_invitation['survey_code']); + survey_manager::update_survey_answered($survey_data, $survey_invitation['user'], $survey_invitation['survey_code']); unset($_SESSION['paged_questions']); unset($_SESSION['page_questions_sec']); Display :: display_footer(); diff --git a/main/survey/survey.lib.php b/main/survey/survey.lib.php index 55ca97b49e..7c1d51681f 100644 --- a/main/survey/survey.lib.php +++ b/main/survey/survey.lib.php @@ -504,22 +504,27 @@ class survey_manager { * @author Patrick Cool , Ghent University * @version February 2007 */ - static function update_survey_answered($survey_id, $user, $survey_code) { + static function update_survey_answered($survey_data, $user, $survey_code) { // Database table definitions $table_survey = Database :: get_course_table(TABLE_SURVEY); $table_survey_invitation = Database :: get_course_table(TABLE_SURVEY_INVITATION); + $survey_id = $survey_data['survey_id']; + $course_id = $survey_data['c_id']; + $session_id = $survey_data['session_id']; + // Getting a list with all the people who have filled the survey - $people_filled = survey_manager::get_people_who_filled_survey($survey_id); + $people_filled = survey_manager::get_people_who_filled_survey($survey_id, false, $course_id); + $number = intval(count($people_filled)); - $course_id = api_get_course_int_id(); // Storing this value in the survey table $sql = "UPDATE $table_survey SET answered = $number WHERE c_id = $course_id AND survey_id = ".Database::escape_string($survey_id); Database::query($sql); // Storing that the user has finished the survey. - $sql = "UPDATE $table_survey_invitation SET answered='1' WHERE c_id = $course_id AND session_id='".api_get_session_id()."' AND user='".Database::escape_string($user)."' AND survey_code='".Database::escape_string($survey_code)."'"; + $sql = "UPDATE $table_survey_invitation SET answered='1' + WHERE c_id = $course_id AND session_id='".$session_id."' AND user='".Database::escape_string($user)."' AND survey_code='".Database::escape_string($survey_code)."'"; Database::query($sql); } @@ -1221,8 +1226,9 @@ class survey_manager { // Getting the survey information $survey_data = survey_manager::get_survey($survey_id); + if (empty($course_id)) { - $course_id = api_get_course_int_id(); + $course_id = api_get_course_int_id(); } else { $course_id = intval($course_id); } @@ -1248,7 +1254,6 @@ class survey_manager { $return[] = $row['user']; } } - return $return; } } @@ -2218,8 +2223,8 @@ class SurveyUtil { * @author Patrick Cool , Ghent University * @version January 2007 */ - static function remove_answer($user, $survey_id, $question_id) { - $course_id = api_get_course_int_id(); + static function remove_answer($user, $survey_id, $question_id, $course_id) { + $course_id = intval($course_id); // table definition $table_survey_answer = Database :: get_course_table(TABLE_SURVEY_ANSWER); $sql = "DELETE FROM $table_survey_answer @@ -2244,8 +2249,6 @@ class SurveyUtil { * @version January 2007 */ static function store_answer($user, $survey_id, $question_id, $option_id, $option_value, $survey_data) { - global $_course, $types; - // Table definition $table_survey_answer = Database :: get_course_table(TABLE_SURVEY_ANSWER); @@ -2258,7 +2261,7 @@ class SurveyUtil { $user = $_SESSION['surveyuser']; } } - $course_id = api_get_course_int_id(); + $course_id = $survey_data['c_id']; $sql = "INSERT INTO $table_survey_answer (c_id, user, survey_id, question_id, option_id, value) VALUES ( $course_id, @@ -4282,7 +4285,7 @@ class SurveyUtil { $course_id = api_get_course_int_id(); - //IF(is_shared<>0,'V','-') AS col6, + $sql = "SELECT survey.survey_id AS col0, CONCAT('',survey.title,'') AS col1, @@ -4295,14 +4298,16 @@ class SurveyUtil { survey.anonymous AS col8, survey.survey_id AS col9, survey.session_id AS session_id - FROM $table_survey survey LEFT JOIN $table_survey_question survey_question - ON survey.survey_id = survey_question.survey_id, $table_user user - WHERE survey.author = user.user_id AND survey.c_id = $course_id + FROM $table_survey survey + LEFT JOIN $table_survey_question survey_question ON survey.survey_id = survey_question.survey_id + INNER JOIN $table_user user ON (survey.author = user.user_id) + WHERE survey.c_id = $course_id AND survey_question.c_id = $course_id $search_restriction $condition_session "; $sql .= " GROUP BY survey.survey_id"; $sql .= " ORDER BY col$column $direction "; $sql .= " LIMIT $from,$number_of_items"; + $res = Database::query($sql); $surveys = array(); $array = array(); @@ -4313,7 +4318,6 @@ class SurveyUtil { // Validation when belonging to a session $session_img = api_get_session_image($survey['session_id'], $_user['status']); $array[2] = $survey[2] . $session_img; - $array[3] = $survey[3]; $array[4] = $survey[4]; $array[5] = $survey[5]; @@ -4322,7 +4326,6 @@ class SurveyUtil { $array[8] = $survey[8]; $array[9] = $survey[9]; //$array[10] = $survey[10]; - $surveys[] = $array; } return $surveys; @@ -4353,8 +4356,6 @@ class SurveyUtil { $table_survey_question = Database :: get_course_table(TABLE_SURVEY_QUESTION); $table_user = Database :: get_main_table(TABLE_MAIN_USER); - - $course_id = api_get_course_int_id(); //IF(is_shared<>0,'V','-') AS col6, diff --git a/main/survey/survey.php b/main/survey/survey.php index 5069216a5d..d2a0d292e4 100644 --- a/main/survey/survey.php +++ b/main/survey/survey.php @@ -76,7 +76,7 @@ $is_survey_type_1 = $survey_data['survey_type'] == 1; if (api_strlen(strip_tags($survey_data['title'])) > 40) { $tool_name .= '...'; } -$course_id = api_get_course_int_id(); + if ($is_survey_type_1 && $_GET['action'] == 'addgroup' || $_GET['action'] == 'deletegroup') { $_POST['name'] = trim($_POST['name']); diff --git a/main/wiki/index.php b/main/wiki/index.php index e1b9427180..4470d0b8c6 100644 --- a/main/wiki/index.php +++ b/main/wiki/index.php @@ -22,7 +22,6 @@ $current_course_tool = TOOL_WIKI; // including additional library scripts -require_once api_get_path(LIBRARY_PATH).'groupmanager.lib.php'; require_once api_get_path(LIBRARY_PATH).'mail.lib.inc.php'; require_once 'wiki.inc.php'; @@ -114,7 +113,7 @@ if ($_SESSION['_gid'] OR $_GET['group_id']) { } -if ($_POST['action']=='export_to_pdf' && isset($_POST['wiki_id']) && api_get_setting('students_export2pdf') == 'true') { +if ($_POST['action']=='export_to_pdf' && isset($_POST['wiki_id']) && api_get_setting('students_export2pdf') == 'true') { export_to_pdf($_POST['wiki_id'], api_get_course_id()); exit; } @@ -168,7 +167,7 @@ while ($is_editing_block=Database::fetch_array($result)) { } //second checks if has exceeded the time that a page may be available or if a page was edited and saved by its author if ($time_editing>$max_edit_time || ($is_editing_block['is_editing']==$_user['user_id'] && $_GET['action']!='edit')) { - $sql='UPDATE '.$tbl_wiki.' SET is_editing="0", time_edit="0000-00-00 00:00:00" + $sql='UPDATE '.$tbl_wiki.' SET is_editing="0", time_edit="0000-00-00 00:00:00" WHERE c_id = '.$course_id.' AND is_editing="'.$is_editing_block['is_editing'].'" '.$condition_session; Database::query($sql); } @@ -233,7 +232,7 @@ if ($_GET['view']) { } ///restore page - + if ($_GET['action']=='restorepage') { //Only teachers and platform admin can edit the index page. Only teachers and platform admin can edit an assignment teacher if (($current_row['reflink']=='index' || $current_row['reflink']=='' || $current_row['assignment']==1) && (!api_is_allowed_to_edit(false,true) && intval($_GET['group_id'])==0)) { @@ -501,7 +500,7 @@ if ($_GET['action']=='more') { //Submenu Random page //echo '
  • '.get_lang('RandomPage').'
  • ';//TODO: - + //Submenu Task //echo '
  • '.get_lang('Task').'
  • ';//TODO:task list order by start date or end date @@ -513,10 +512,10 @@ if ($_GET['action']=='more') { if ($_GET['action']=='statistics' && (api_is_allowed_to_edit(false,true) || api_is_platform_admin())) { echo '
    '.get_lang('Statistics').'
    '; - - + + //check all versions of all pages - + $total_words = 0; $total_links = 0; $total_links_anchors = 0; @@ -534,19 +533,19 @@ if ($_GET['action']=='statistics' && (api_is_allowed_to_edit(false,true) || api_ $total_youtube = 0; $total_multimedia = 0; $total_tables = 0; - + $sql="SELECT *, COUNT(*) AS TOTAL_VERS, SUM(hits) AS TOTAL_VISITS FROM ".$tbl_wiki." WHERE c_id = $course_id AND ".$groupfilter.$condition_session.""; - + $allpages=Database::query($sql); while ($row=Database::fetch_array($allpages)) { $total_versions = $row['TOTAL_VERS']; $total_visits = intval($row['TOTAL_VISITS']); } - + $sql="SELECT * FROM ".$tbl_wiki." WHERE c_id = $course_id AND ".$groupfilter.$condition_session.""; - $allpages=Database::query($sql); - - while ($row=Database::fetch_array($allpages)) { + $allpages=Database::query($sql); + + while ($row=Database::fetch_array($allpages)) { $total_words = $total_words+word_count($row['content']); $total_links = $total_links+substr_count($row['content'], "href="); $total_links_anchors = $total_links_anchors+substr_count($row['content'], 'href="#'); @@ -558,24 +557,24 @@ if ($_GET['action']=='statistics' && (api_is_allowed_to_edit(false,true) || api_ $total_images = $total_images+substr_count($row['content'], "