From fdc597a1fd44dd906bda1afe7c3895ef4efbe0a7 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Sun, 29 Nov 2020 15:18:13 +0100 Subject: [PATCH] Internal: Update from 1.11.x --- public/main/mySpace/access_details.php | 7 +- .../main/mySpace/access_details_session.php | 6 +- public/main/mySpace/admin.php | 8 +- public/main/mySpace/admin_view.php | 77 ++++- public/main/mySpace/course.php | 9 + public/main/mySpace/current_courses.php | 2 +- public/main/mySpace/progression.php | 10 +- public/main/mySpace/session.php | 276 ++++++++++++++++- public/main/mySpace/session_filter.php | 206 ++++++++----- public/main/mySpace/student.php | 20 +- public/main/mySpace/teachers.php | 1 - public/main/survey/edit_meeting.php | 2 + public/main/survey/fillsurvey.php | 22 +- public/main/survey/reporting.php | 86 +++++- public/main/survey/survey.download.inc.php | 6 +- public/main/survey/survey.lib.php | 62 +++- public/main/survey/surveyUtil.class.php | 145 +++++---- public/main/survey/survey_invitation.php | 2 +- public/main/survey/survey_list.php | 282 ++++++++++++++++++ public/main/survey/survey_question.php | 4 +- 20 files changed, 1055 insertions(+), 178 deletions(-) diff --git a/public/main/mySpace/access_details.php b/public/main/mySpace/access_details.php index d88b53205e..cdf5dc8504 100644 --- a/public/main/mySpace/access_details.php +++ b/public/main/mySpace/access_details.php @@ -16,10 +16,10 @@ require_once __DIR__.'/../inc/global.inc.php'; api_block_anonymous_users(); // Access restrictions. -$is_allowedToTrack = api_is_platform_admin(true, true) || +$allowToTrack = api_is_platform_admin(true, true) || api_is_teacher() || api_is_course_tutor(); -if (!$is_allowedToTrack) { +if (!$allowToTrack) { api_not_allowed(true); exit; } @@ -138,7 +138,8 @@ $userInfo = api_get_user_info($user_id); echo Display::page_header(get_lang('Learner details in course')); echo Display::page_subheader( - get_lang('User').': '.$userInfo['complete_name'].' - '.get_lang('Course').': '.$courseInfo['title'].' ('.$course_code.')' + get_lang('User').': '.$userInfo['complete_name'].' - '. + get_lang('Course').': '.$courseInfo['title'].' ('.$course_code.')' ); $form->setDefaults(['from' => $from, 'to' => $to]); diff --git a/public/main/mySpace/access_details_session.php b/public/main/mySpace/access_details_session.php index e19fb86ce2..d85ab25b9a 100644 --- a/public/main/mySpace/access_details_session.php +++ b/public/main/mySpace/access_details_session.php @@ -244,7 +244,7 @@ function getReport($userId, $from, $to, $addTime = false) } } - $table = new HTML_Table(['class' => 'data_table']); + $table = new HTML_Table(['class' => 'table table-hover table-striped data_table']); $headers = [ get_lang('First connection'), get_lang('Last connection'), @@ -276,7 +276,7 @@ function getReport($userId, $from, $to, $addTime = false) $courseSessionTable .= '
'.Display::page_subheader3( $iconCourse.$data['name'][$courseId] ).'
'; - $table = new HTML_Table(['class' => 'data_table']); + $table = new HTML_Table(['class' => 'table table-hover table-striped data_table']); $headers = [ get_lang('Start Date'), get_lang('End Date'), @@ -306,7 +306,7 @@ function getReport($userId, $from, $to, $addTime = false) } $totalCourseSessionTable = ''; if ($courseSessionTableData) { - $table = new HTML_Table(['class' => 'data_table']); + $table = new HTML_Table(['class' => 'table table-hover table-striped data_table']); $headers = [ get_lang('Course'), get_lang('TotalDuration'), diff --git a/public/main/mySpace/admin.php b/public/main/mySpace/admin.php index 72314ba7d7..bd209883d4 100644 --- a/public/main/mySpace/admin.php +++ b/public/main/mySpace/admin.php @@ -38,9 +38,13 @@ $sql = "SELECT user.id as user_id,lastname,firstname,email $result_admins = Database::query($sql); if (api_is_western_name_order()) { - echo ''; + echo '
'.get_lang('First name').''.get_lang('Last name').''.get_lang('e-mail').'
+ + '; } else { - echo '
'.get_lang('First name').''.get_lang('Last name').''.get_lang('e-mail').'
'; + echo '
'.get_lang('Last name').''.get_lang('First name').''.get_lang('e-mail').'
+ + '; } if (api_is_western_name_order(PERSON_NAME_DATA_EXPORT)) { diff --git a/public/main/mySpace/admin_view.php b/public/main/mySpace/admin_view.php index a254a8f1c7..d04e6fc389 100644 --- a/public/main/mySpace/admin_view.php +++ b/public/main/mySpace/admin_view.php @@ -8,10 +8,47 @@ require_once __DIR__.'/../inc/global.inc.php'; api_block_anonymous_users(); -$exportCSV = isset($_GET['export']) && 'csv' === $_GET['export'] ? true : false; +$exportCSV = isset($_GET['export']) && $_GET['export'] === 'csv' ? true : false; +if (isset($_GET['export_csv']) && $exportCSV == false) { + // to export learningPath and company + $exportCSV = true; +} +$startDate = isset($_GET['startDate']) ? $_GET['startDate'] : null; +$endDate = isset($_GET['endDate']) ? $_GET['endDate'] : null; $display = isset($_GET['display']) ? Security::remove_XSS($_GET['display']) : null; +if (isset($_POST['display']) && $display == null) { + $display = Security::remove_XSS($_POST['display']); +} $htmlHeadXtra[] = api_get_jqgrid_js(); +$htmlHeadXtra[] = ' +'; // the section (for the tabs) $this_section = SECTION_TRACKING; @@ -33,6 +70,15 @@ if ($exportCSV) { } elseif ('course' === $display) { MySpace::export_tracking_course_overview(); exit; + } elseif ('company' === $display) { + MySpace::exportCompanyResumeCsv($startDate, $endDate); + exit; + } elseif ('learningPath' === $display) { + MySpace::displayResumeLP($startDate, $endDate, true); + exit; + } elseif ('learningPathByItem' === $display) { + MySpace::displayResumeLpByItem($startDate, $endDate, true); + exit; } } @@ -55,12 +101,39 @@ switch ($display) { case 'course': MySpace::display_tracking_course_overview(); break; + case 'company': + MySpace::displayResumeCompany($startDate, $endDate); + break; + case 'learningPath': + MySpace::displayResumeLP($startDate, $endDate); + break; + case 'learningPathByItem': + MySpace::displayResumeLpByItem($startDate, $endDate); + break; case 'accessoverview': $courseId = isset($_GET['course_id']) ? (int) $_GET['course_id'] : 0; + if ($courseId == 0 && $_POST['course_id']) { + $courseId = (int) $_POST['course_id']; + $_GET['course_id'] = $courseId; + } $sessionId = isset($_GET['session_id']) ? (int) $_GET['session_id'] : 0; + if ($sessionId == 0 && $_POST['session_id']) { + $sessionId = (int) $_POST['session_id']; + $_GET['session_id'] = $sessionId; + } $studentId = isset($_GET['student_id']) ? (int) $_GET['student_id'] : 0; + if ($studentId == 0 && $_POST['student_id']) { + $studentId = (int) $_POST['student_id']; + $_GET['student_id'] = $studentId; + } + $perPage = isset($_GET['tracking_access_overview_per_page']) ? $_GET['tracking_access_overview_per_page'] : 20; - MySpace::displayTrackingAccessOverView($courseId, $sessionId, $studentId); + $dates = isset($_GET['date']) ? $_GET['date'] : null; + if ($dates == null && $_POST['date']) { + $dates = $_POST['date']; + $_GET['date'] = $dates; + } + MySpace::displayTrackingAccessOverView($courseId, $sessionId, $studentId, $perPage, $dates); break; } diff --git a/public/main/mySpace/course.php b/public/main/mySpace/course.php index 63b096a82a..2d73222920 100644 --- a/public/main/mySpace/course.php +++ b/public/main/mySpace/course.php @@ -104,6 +104,15 @@ if (api_is_platform_admin(true, true)) { Display::return_icon('session.png', get_lang('Course sessions'), [], ICON_SIZE_MEDIUM), 'session.php' ); + $menu_items[] = Display::url( + get_lang('QuestionStats'), + api_get_path(WEB_CODE_PATH).'mySpace/question_stats_global.php' + ); + + $menu_items[] = Display::url( + get_lang('QuestionStatsDetailedReport'), + api_get_path(WEB_CODE_PATH).'mySpace/question_stats_global_detail.php' + ); if (api_can_login_as($user_id)) { $link = ''. Display::return_icon('login_as.png', get_lang('Login as'), null, ICON_SIZE_MEDIUM).'  '; diff --git a/public/main/mySpace/current_courses.php b/public/main/mySpace/current_courses.php index 2ac767aae5..60db2febd9 100644 --- a/public/main/mySpace/current_courses.php +++ b/public/main/mySpace/current_courses.php @@ -221,7 +221,7 @@ if (isset($_GET['export'])) { $interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('Reporting')]; Display::display_header(get_lang('Current courses')); -$table = new HTML_Table(['class' => 'data_table']); +$table = new HTML_Table(['class' => 'table table-hover table-striped data_table']); $row = 0; $column = 0; foreach ($headers as $header) { diff --git a/public/main/mySpace/progression.php b/public/main/mySpace/progression.php index b8b81f3faa..deaed29592 100644 --- a/public/main/mySpace/progression.php +++ b/public/main/mySpace/progression.php @@ -39,8 +39,14 @@ if (Database::num_rows($result_course) > 0) { $export_result = export_csv($header, $data, 'test.csv'); // TODO: There is no data for exporting yet. echo Display::return_message($export_result, 'error'); } - echo '
'.get_lang('Last name').''.get_lang('First name').''.get_lang('e-mail').'
'; - $header = [get_lang('Course'), get_lang('Frequentation time'), get_lang('Progress'), get_lang('Tests score')]; + echo '
'.get_lang('Course').''.get_lang('Frequentation time').''.get_lang('Progress').''.get_lang('Tests score').'
+ + + + + + '; + $header = [get_lang('Course'), get_lang('TempsFrequentation'), get_lang('Progression'), get_lang('MoyenneTest')]; while ($a_course = Database::fetch_array($result_course)) { // TODO: This query is to be checked, there are no HotPotatoes tests results. $sql_moy_test = "SELECT score,max_score diff --git a/public/main/mySpace/session.php b/public/main/mySpace/session.php index fb20cf6d27..c9dab7b262 100644 --- a/public/main/mySpace/session.php +++ b/public/main/mySpace/session.php @@ -12,6 +12,7 @@ $export_csv = false; if (isset($_REQUEST['export']) && 'csv' == $_REQUEST['export']) { $export_csv = true; } +$action = isset($_GET['action']) ? $_GET['action'] : ''; $id_coach = api_get_user_id(); if (isset($_REQUEST['id_coach']) && '' != $_REQUEST['id_coach']) { @@ -24,6 +25,277 @@ if (!$allowToTrack) { api_not_allowed(true); } +$studentId = isset($_GET['student']) ? (int) $_GET['student'] : 0; +$sessionId = isset($_GET['sid']) ? (int) $_GET['sid'] : 0; +$currentUrl = api_get_self().'?student='.$studentId.'&sid='.$sessionId; + +switch ($action) { + case 'export_to_pdf': + $allStudents = isset($_GET['all_students']) && 1 === (int) $_GET['all_students'] ? true : false; + $sessionToExport = isset($_GET['session_to_export']) ? (int) $_GET['session_to_export'] : 0; + $type = isset($_GET['type']) ? $_GET['type'] : 'attendance'; + $sessionInfo = api_get_session_info($sessionToExport); + if (empty($sessionInfo)) { + api_not_allowed(true); + } + $courses = Tracking::get_courses_list_from_session($sessionToExport); + $studentList = [$studentId]; + if ($allStudents) { + $users = SessionManager::get_users_by_session($sessionToExport, 0); + $studentList = array_column($users, 'user_id'); + } + + $totalCourses = count($courses); + $scoreDisplay = ScoreDisplay::instance(); + $table = Database::get_main_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS); + $pdfList = []; + foreach ($studentList as $studentId) { + $studentInfo = api_get_user_info($studentId); + $timeSpent = 0; + $numberVisits = 0; + $progress = 0; + $timeSpentPerCourse = []; + $progressPerCourse = []; + + foreach ($courses as $course) { + $courseId = $course['c_id']; + $courseTimeSpent = Tracking::get_time_spent_on_the_course($studentId, $courseId, $sessionToExport); + $timeSpentPerCourse[$courseId] = $courseTimeSpent; + $timeSpent += $courseTimeSpent; + $sql = "SELECT DISTINCT count(course_access_id) as count + FROM $table + WHERE + c_id = $courseId AND + session_id = $sessionToExport AND + user_id = $studentId"; + $result = Database::query($sql); + $row = Database::fetch_array($result); + $numberVisits += $row['count']; + $courseProgress = Tracking::get_avg_student_progress( + $studentId, + $course['code'], + [], + $sessionToExport + ); + $progressPerCourse[$courseId] = $courseProgress; + $progress += $courseProgress; + } + + $average = round($progress / $totalCourses, 1); + $average = empty($average) ? '0%' : $average.'%'; + $first = Tracking::get_first_connection_date($studentId); + $last = Tracking::get_last_connection_date($studentId); + $timeSpentContent = ''; + $pdfTitle = get_lang('AttestationOfAttendance'); + if ('attendance' === $type) { + $table = new HTML_Table(['class' => 'table table-hover table-striped data_table']); + $column = 0; + $row = 0; + $headers = [ + get_lang('TimeSpent'), + get_lang('NumberOfVisits'), + get_lang('GlobalProgress'), + get_lang('FirstLogin'), + get_lang('LastConnexionDate'), + ]; + foreach ($headers as $header) { + $table->setHeaderContents($row, $column, $header); + $column++; + } + $table->setCellContents(1, 0, api_time_to_hms($timeSpent)); + $table->setCellContents(1, 1, $numberVisits); + $table->setCellContents(1, 2, $average); + $table->setCellContents(1, 3, $first); + $table->setCellContents(1, 4, $last); + $timeSpentContent = $table->toHtml(); + } else { + $pdfTitle = get_lang('CertificateOfAchievement'); + } + + $courseTable = ''; + if (!empty($courses)) { + $courseTable .= '
'.get_lang('Course').''.get_lang('TempsFrequentation').''.get_lang('Progression').''.get_lang('MoyenneTest').'
'; + $courseTable .= ''; + $courseTable .= ' + + + '; + + if ('attendance' === $type) { + $courseTable .= ''; + } + $courseTable .= ''; + $courseTable .= ''; + $courseTable .= ''; + + $totalCourseTime = 0; + $totalAttendance = [0, 0]; + $totalScore = 0; + $totalProgress = 0; + $gradeBookTotal = [0, 0]; + $totalEvaluations = '0/0 (0%)'; + + foreach ($courses as $course) { + $courseId = $course['c_id']; + $courseInfoItem = api_get_course_info_by_id($courseId); + $courseId = $courseInfoItem['real_id']; + $courseCodeItem = $courseInfoItem['code']; + + $isSubscribed = CourseManager::is_user_subscribed_in_course( + $studentId, + $courseCodeItem, + true, + $sessionToExport + ); + + if ($isSubscribed) { + $timeInSeconds = $timeSpentPerCourse[$courseId]; + $totalCourseTime += $timeInSeconds; + $time_spent_on_course = api_time_to_hms($timeInSeconds); + $progress = $progressPerCourse[$courseId]; + $totalProgress += $progress; + + $bestScore = Tracking::get_avg_student_score( + $studentId, + $courseCodeItem, + [], + $sessionToExport, + false, + false, + true + ); + + if (is_numeric($bestScore)) { + $totalScore += $bestScore; + } + + $progress = empty($progress) ? '0%' : $progress.'%'; + $score = empty($bestScore) ? '0%' : $bestScore.'%'; + + $courseTable .= ' + + + '; + if ('attendance' === $type) { + $courseTable .= ''; + } + $courseTable .= ''; + } + } + + $totalAttendanceFormatted = $scoreDisplay->display_score($totalAttendance); + $totalScoreFormatted = $scoreDisplay->display_score([$totalScore / $totalCourses, 100], SCORE_AVERAGE); + $totalProgressFormatted = $scoreDisplay->display_score( + [$totalProgress / $totalCourses, 100], + SCORE_AVERAGE + ); + $totalEvaluations = $scoreDisplay->display_score($gradeBookTotal); + $totalTimeFormatted = api_time_to_hms($totalCourseTime); + $courseTable .= ' + + + + + '; + if ('attendance' === $type) { + $courseTable .= ''; + } + $courseTable .= ''; + $courseTable .= '
'.get_lang('FormationUnit').''.get_lang('ConnectionTime').''.get_lang('Progress').''.get_lang('Score').'
+ '. + $courseInfoItem['title'].' + '.$time_spent_on_course.''.$progress.''.$score.'
'.get_lang('Total').''.$totalTimeFormatted.''.$totalProgressFormatted.''.$totalScoreFormatted.'
'; + } + + $tpl = new Template('', false, false, false, true, false, false); + $tpl->assign('title', $pdfTitle); + $tpl->assign('session_title', $sessionInfo['name']); + $tpl->assign('session_info', $sessionInfo); + $sessionCategoryTitle = ''; + if (isset($sessionInfo['session_category_id'])) { + $sessionCategory = SessionManager::get_session_category($sessionInfo['session_category_id']); + if ($sessionCategory) { + $sessionCategoryTitle = $sessionCategory['name']; + } + } + $dateData = SessionManager::parseSessionDates($sessionInfo, false); + $dateToString = $dateData['access']; + $tpl->assign('session_display_dates', $dateToString); + $tpl->assign('session_category_title', $sessionCategoryTitle); + $tpl->assign('student', $studentInfo['complete_name']); + $tpl->assign('student_info', $studentInfo); + $tpl->assign('student_info_extra_fields', UserManager::get_extra_user_data($studentInfo['user_id'])); + $tpl->assign('table_progress', $timeSpentContent); + $tpl->assign( + 'subtitle', + sprintf( + get_lang('InSessionXYouHadTheFollowingResults'), + $sessionInfo['name'] + ) + ); + $tpl->assign('table_course', $courseTable); + $template = 'pdf_export_student.tpl'; + if ('achievement' === $type) { + $template = 'certificate_achievement.tpl'; + } + $content = $tpl->fetch($tpl->get_template('my_space/'.$template)); + + $params = [ + 'pdf_title' => get_lang('Resume'), + 'session_info' => $sessionInfo, + 'course_info' => '', + 'pdf_date' => '', + 'student_info' => $studentInfo, + 'show_grade_generated_date' => true, + 'show_real_course_teachers' => false, + 'show_teacher_as_myself' => false, + 'orientation' => 'P', + ]; + @$pdf = new PDF('A4', $params['orientation'], $params); + $pdf->setBackground($tpl->theme); + $mode = 'D'; + + $pdfName = $sessionInfo['name'].'_'.$studentInfo['complete_name']; + if ($allStudents) { + $mode = 'F'; + $pdfName = $studentInfo['complete_name']; + } + $pdf->set_footer(); + $result = @$pdf->content_to_pdf( + $content, + '', + $pdfName, + null, + $mode, + false, + null, + false, + true, + false + ); + $pdfList[] = $result; + } + + if (empty($pdfList)) { + api_not_allowed(true); + } + + // Creating a ZIP file. + $tempZipFile = api_get_path(SYS_ARCHIVE_PATH).uniqid('report_session_'.$sessionToExport, true).'.zip'; + + $zip = new PclZip($tempZipFile); + foreach ($pdfList as $file) { + $zip->add( + $file, + PCLZIP_OPT_REMOVE_PATH, + api_get_path(SYS_ARCHIVE_PATH) + ); + } + $name = $sessionInfo['name'].'_'.api_get_utc_datetime().'.zip'; + DocumentManager::file_send_for_download($tempZipFile, true, $name); + exit; + break; +} $htmlHeadXtra[] = api_get_jqgrid_js(); $interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('Reporting')]; Display::display_header(get_lang('Course sessions')); @@ -210,7 +482,7 @@ $orderUrl = api_get_path(WEB_AJAX_PATH).'session.ajax.php?a=order'; // Cleaning for (key in added_cols) { grid.hideCol(key); - }; + } grid.showCol('name'); grid.showCol('display_start_date'); grid.showCol('display_end_date'); @@ -221,7 +493,7 @@ $orderUrl = api_get_path(WEB_AJAX_PATH).'session.ajax.php?a=order'; grid.showCol('name').trigger('reloadGrid'); for (key in added_cols) { grid.showCol(key); - }; + } } var second_filters = []; diff --git a/public/main/mySpace/session_filter.php b/public/main/mySpace/session_filter.php index 72c5a2d6d6..4c298785e8 100644 --- a/public/main/mySpace/session_filter.php +++ b/public/main/mySpace/session_filter.php @@ -27,14 +27,73 @@ define('DATE_END_FILTER', 2); define('ALL_DATE_FILTER', 3); $certificateList = []; -$formSent = 0; $urlParam = ''; +$form = new FormValidator('search_user', 'GET', api_get_self()); +$innerJoinSessionRelUser = ''; +$whereCondictionDRH = ''; +$whereCondictionMultiUrl = ''; +if (api_is_drh()) { + $innerJoinSessionRelUser = "INNER JOIN $tblSessionRelUser as session_rel_user + ON (s.id = session_rel_user.session_id)"; + $whereCondictionDRH = "WHERE session_rel_user.user_id = ".api_get_user_id(); + $whereCondictionMultiUrl = " AND session_rel_user.user_id = ".api_get_user_id(); +} + +$sql = "SELECT s.id, name FROM $tblSession s + $innerJoinSessionRelUser + $whereCondictionDRH + ORDER BY name"; + +if (api_is_multiple_url_enabled()) { + $tblSessionRelAccessUrl = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION); + $accessUrlId = api_get_current_access_url_id(); + if ($accessUrlId != -1) { + $sql = "SELECT s.id, name FROM $tblSession s + INNER JOIN $tblSessionRelAccessUrl as session_rel_url + ON (s.id = session_rel_url.session_id) + $innerJoinSessionRelUser + WHERE access_url_id = $accessUrlId + $whereCondictionMultiUrl + ORDER BY name"; + } +} +$result = Database::query($sql); +$Sessions = Database::store_result($result); +$options = []; +$options['0'] = ''; +foreach ($Sessions as $enreg) { + $options[$enreg['id']] = $enreg['name']; +} -if (isset($_POST['formSent'])) { - $formSent = $_POST['formSent']; - $sessionId = (int) $_POST['session_id']; - $dateBegin = isset($_POST['date_begin']) ? strtotime($_POST['date_begin']) : null; - $dateEnd = isset($_POST['date_end']) ? strtotime($_POST['date_end'].' 23:59:59') : null; +$form->addElement('select', 'session_id', get_lang('SessionList'), $options, ['id' => 'session-id']); +$form->addDatePicker('date_begin', get_lang('DateStart'), ['id' => 'date-begin']); +$form->addDatePicker('date_end', get_lang('DateEnd'), ['id' => 'date-end']); + +// EXTRA FIELDS +$extraField = new ExtraField('user'); +$returnParams = $extraField->addElements( + $form, + 0, + [], + true, + false, + [], + [], + [], + false, + true +); + +$form->addElement('hidden', 'formSent', 1); +$form->addButtonSearch(get_lang('Search')); +$form->addButtonExport(get_lang('ExportAsCSV'), 'export'); + +if ($form->validate()) { + $values = $form->getSubmitValues(); + $exportToCsv = isset($values['export']); + $sessionId = (int) $_REQUEST['session_id']; + $dateBegin = isset($_REQUEST['date_begin']) ? strtotime($_REQUEST['date_begin']) : null; + $dateEnd = isset($_REQUEST['date_end']) ? strtotime($_REQUEST['date_end'].' 23:59:59') : null; $filterDate = 0; if (!empty($dateBegin)) { @@ -48,7 +107,7 @@ if (isset($_POST['formSent'])) { $extraField = new ExtraField('user'); $extraFieldsAll = $extraField->get_all(['filter = ?' => 1], 'option_order'); foreach ($extraFieldsAll as $field) { - if (!empty($_POST['extra_'.$field['variable']])) { + if (!empty($_REQUEST['extra_'.$field['variable']])) { $filterCheckList[$field['id']] = $field; } } @@ -137,19 +196,19 @@ if (isset($_POST['formSent'])) { switch ($field['field_type']) { case ExtraField::FIELD_TYPE_TEXT: case ExtraField::FIELD_TYPE_ALPHANUMERIC: - $pos = stripos($extraFieldValueData['value'], $_POST['extra_'.$field['variable']]); - if (false === $pos) { + $pos = stripos($extraFieldValueData['value'], $_REQUEST['extra_'.$field['variable']]); + if ($pos === false) { unset($certificateList[$key]); } break; case ExtraField::FIELD_TYPE_RADIO: - $valueRadio = $_POST['extra_'.$field['variable']]['extra_'.$field['variable']]; + $valueRadio = $_REQUEST['extra_'.$field['variable']]['extra_'.$field['variable']]; if ($extraFieldValueData['value'] != $valueRadio) { unset($certificateList[$key]); } break; case ExtraField::FIELD_TYPE_SELECT: - if ($extraFieldValueData['value'] != $_POST['extra_'.$field['variable']]) { + if ($extraFieldValueData['value'] != $_REQUEST['extra_'.$field['variable']]) { unset($certificateList[$key]); } break; @@ -159,15 +218,69 @@ if (isset($_POST['formSent'])) { } $params = [ - 'session_id' => (int) $_POST['session_id'], - 'date_begin' => Security::remove_XSS($_POST['date_begin']), - 'date_end' => Security::remove_XSS($_POST['date_end']), + 'session_id' => (int) $_REQUEST['session_id'], + 'date_begin' => Security::remove_XSS($_REQUEST['date_begin']), + 'date_end' => Security::remove_XSS($_REQUEST['date_end']), ]; //select of sessions foreach ($filterCheckList as $field) { - $params['extra_'.$field['variable']] = Security::remove_XSS($_POST['extra_'.$field['variable']]); + $params['extra_'.$field['variable']] = Security::remove_XSS($_REQUEST['extra_'.$field['variable']]); } $urlParam = http_build_query($params); + $dataToExport = []; + if ($exportToCsv) { + $headers = [ + get_lang('Session'), + get_lang('Course'), + get_lang('FirstName'), + get_lang('LastName'), + get_lang('Score'), + get_lang('Date'), + ]; + + $extraField = new ExtraField('user'); + foreach ($extraFieldsAll as $field) { + $headers[] = $field['display_text']; + } + $dataToExport[] = $headers; + + $sessionInfo = api_get_session_info($sessionId); + foreach ($certificateList as $index => $value) { + $categoryId = $value['category_id']; + $courseCode = $value['course_code']; + $courseInfo = api_get_course_info($courseCode); + $extraFields = []; + foreach ($extraFieldsAll as $field) { + $extraFieldValue = new ExtraFieldValue('user'); + $extraFieldValueData = $extraFieldValue->get_values_by_handler_and_field_id( + $value['user_id'], + $field['id'] + ); + $fieldValue = isset($extraFieldValueData['value']) ? $extraFieldValueData['value'] : ''; + if ('true' === $fieldValue) { + $fieldValue = get_lang('Yes'); + } + if ('false' === $fieldValue) { + $fieldValue = get_lang('No'); + } + $extraFields[] = $fieldValue; + } + + $list = GradebookUtils::get_list_gradebook_certificates_by_user_id($value['user_id'], $categoryId); + foreach ($list as $valueCertificate) { + $item = []; + $item[] = $sessionInfo['name']; + $item[] = $courseInfo['title']; + $item[] = $value['firstname']; + $item[] = $value['lastname']; + $item[] = $valueCertificate['score_certificate']; + $item[] = api_get_local_time($valueCertificate['created_at']); + $item = array_merge($item, $extraFields); + $dataToExport[] = $item; + } + } + Export::arrayToCsv($dataToExport, 'export'); + } } $htmlHeadXtra[] = ""; -$innerJoinSessionRelUser = ''; -$whereCondictionDRH = ''; -$whereCondictionMultiUrl = ''; -if (api_is_drh()) { - $innerJoinSessionRelUser = "INNER JOIN $tblSessionRelUser as session_rel_user - ON (s.id = session_rel_user.session_id)"; - $whereCondictionDRH = "WHERE session_rel_user.user_id = ".api_get_user_id(); - $whereCondictionMultiUrl = " AND session_rel_user.user_id = ".api_get_user_id(); -} - -//select of sessions -$sql = "SELECT s.id, name FROM $tblSession s - $innerJoinSessionRelUser - $whereCondictionDRH - ORDER BY name"; - -if (api_is_multiple_url_enabled()) { - $tblSessionRelAccessUrl = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION); - $accessUrlId = api_get_current_access_url_id(); - if (-1 != $accessUrlId) { - $sql = "SELECT s.id, name FROM $tblSession s - INNER JOIN $tblSessionRelAccessUrl as session_rel_url - ON (s.id = session_rel_url.session_id) - $innerJoinSessionRelUser - WHERE access_url_id = $accessUrlId - $whereCondictionMultiUrl - ORDER BY name"; - } -} -$result = Database::query($sql); -$Sessions = Database::store_result($result); -$options = []; -$options['0'] = ''; -foreach ($Sessions as $enreg) { - $options[$enreg['id']] = $enreg['name']; -} - -$form = new FormValidator('search_user', 'post', api_get_self()); -$form->addElement('select', 'session_id', get_lang('SessionList'), $options, ['id' => 'session-id']); -$form->addDatePicker('date_begin', get_lang('DateStart'), ['id' => 'date-begin']); -$form->addDatePicker('date_end', get_lang('DateEnd'), ['id' => 'date-end']); - -// EXTRA FIELDS -$extraField = new ExtraField('user'); -$returnParams = $extraField->addElements( - $form, - 0, - [], - true, - false, - [], - [], - [], - false, - true -); - -$form->addElement('hidden', 'formSent', 1); -$form->addButtonSearch(get_lang('Search')); $interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('MySpace')]; Display::display_header(get_lang('CertificatesSessions')); @@ -299,7 +353,7 @@ echo $form->returnForm(); if (0 == count($certificateList)) { echo Display::return_message(get_lang('NoResultsAvailable'), 'warning'); } else { - echo ''; + echo '
'; echo ''; foreach ($certificateList as $index => $value) { $categoryId = $value['category_id']; @@ -313,7 +367,7 @@ if (0 == count($certificateList)) { echo ''; echo ''; echo ' + + + + + +
'.$courseInfo['title'].'
- +
'; $list = GradebookUtils::get_list_gradebook_certificates_by_user_id($value['user_id'], $categoryId); diff --git a/public/main/mySpace/student.php b/public/main/mySpace/student.php index 4c11f68d49..81f84da26b 100644 --- a/public/main/mySpace/student.php +++ b/public/main/mySpace/student.php @@ -21,28 +21,28 @@ if (!$allowToTrack) { $nameTools = get_lang('Learners'); -$export_csv = isset($_GET['export']) && 'csv' == $_GET['export'] ? true : false; +$export_csv = isset($_GET['export']) && 'csv' === $_GET['export'] ? true : false; $keyword = isset($_GET['keyword']) ? Security::remove_XSS($_GET['keyword']) : null; -$active = isset($_GET['active']) ? intval($_GET['active']) : 1; -$sleepingDays = isset($_GET['sleeping_days']) ? intval($_GET['sleeping_days']) : null; +$active = isset($_GET['active']) ? (int) $_GET['active'] : 1; +$sleepingDays = isset($_GET['sleeping_days']) ? (int) $_GET['sleeping_days'] : null; $this_section = SECTION_TRACKING; $webCodePath = api_get_path(WEB_CODE_PATH); $interbreadcrumb[] = [ - "url" => api_is_student_boss() ? "#" : "index.php", - "name" => get_lang('Reporting'), + 'url' => api_is_student_boss() ? '#' : 'index.php', + 'name' => get_lang('Reporting'), ]; -if (isset($_GET["user_id"]) && "" != $_GET["user_id"] && !isset($_GET["type"])) { +if (isset($_GET['user_id']) && '' != $_GET['user_id'] && !isset($_GET['type'])) { $interbreadcrumb[] = [ - "url" => "teachers.php", - "name" => get_lang('Teachers'), + 'url' => 'teachers.php', + 'name' => get_lang('Teachers'), ]; } -if (isset($_GET["user_id"]) && "" != $_GET["user_id"] && isset($_GET["type"]) && "coach" == $_GET["type"]) { - $interbreadcrumb[] = ["url" => "coaches.php", "name" => get_lang('Coaches')]; +if (isset($_GET['user_id']) && '' != $_GET['user_id'] && isset($_GET['type']) && 'coach' === $_GET['type']) { + $interbreadcrumb[] = ['url' => 'coaches.php', 'name' => get_lang('Coaches')]; } function get_count_users() diff --git a/public/main/mySpace/teachers.php b/public/main/mySpace/teachers.php index 81f93cc6e4..8e0a5a1c7b 100644 --- a/public/main/mySpace/teachers.php +++ b/public/main/mySpace/teachers.php @@ -113,7 +113,6 @@ function get_users($from, $limit, $column, $direction) $all_datas = []; $url = api_get_path(WEB_CODE_PATH).'mySpace/myStudents.php'; foreach ($students as $student_data) { - var_dump($student_data); $student_id = $student_data['user_id']; $student_data = api_get_user_info($student_id); if (isset($_GET['id_session'])) { diff --git a/public/main/survey/edit_meeting.php b/public/main/survey/edit_meeting.php index 26460cf9dc..e58d63bf00 100644 --- a/public/main/survey/edit_meeting.php +++ b/public/main/survey/edit_meeting.php @@ -143,6 +143,8 @@ $form->addLabel( $form->addButtonUpdate(get_lang('Edit'), 'submit_survey'); +$surveyData['start_date'] = api_get_local_time($surveyData['start_date']); +$surveyData['end_date'] = api_get_local_time($surveyData['end_date']); $form->setDefaults($surveyData); // The validation or display diff --git a/public/main/survey/fillsurvey.php b/public/main/survey/fillsurvey.php index dd2d0aaecd..ac52d13f14 100644 --- a/public/main/survey/fillsurvey.php +++ b/public/main/survey/fillsurvey.php @@ -4,6 +4,7 @@ use ChamiloSession as Session; +$lastQuestion = 0; /** * @author unknown, the initial survey that did not make it in 1.8 because of bad code * @author Patrick Cool , Ghent University: cleanup, @@ -572,7 +573,7 @@ if ( Session::erase('page_questions_sec'); $paged_questions_sec = []; if (!empty($survey_data['survey_introduction'])) { - echo '
'.$survey_data['survey_introduction'].'
'; + echo '
'.Security::remove_XSS($survey_data['survey_introduction']).'
'; } $limit = 0; } @@ -639,7 +640,7 @@ if ($survey_data['form_fields'] && // Displaying the survey thanks message if (isset($_POST['finish_survey'])) { echo Display::return_message(get_lang('You have finished this survey.'), 'confirm'); - echo $survey_data['survey_thanks']; + echo Security::remove_XSS($survey_data['survey_thanks']); SurveyManager::update_survey_answered( $survey_data, @@ -653,6 +654,7 @@ if (isset($_POST['finish_survey'])) { ); if ($courseInfo && !api_is_anonymous()) { + echo '

'; echo Display::toolbarButton( get_lang('Return to Course Homepage'), api_get_course_url($courseInfo['code']), @@ -807,6 +809,11 @@ if ((isset($_GET['show']) && '' != $_GET['show']) || $questions[$sort]['parent_option_id'] = isset($row['parent_option_id']) ? $row['parent_option_id'] : 0; } $counter++; + if (isset($_GET['show']) && (int) $_GET['show'] >= 0) { + $lastQuestion = (int) $_GET['show'] - 1; + } else { + $lastQuestion = (int) $row['question_option_id']; + } } } } elseif ('1' === $survey_data['survey_type']) { @@ -1340,6 +1347,17 @@ if ('0' == $survey_data['survey_type']) { 'success' ); } else { + if ( + api_get_configuration_value('survey_backwards_enable') + ) { + if ($lastQuestion >= 0) { + $form->addHtml( + "". + " " + .get_lang('Back')." " + ); + } + } $form->addButton( 'next_survey_page', get_lang('Next'), diff --git a/public/main/survey/reporting.php b/public/main/survey/reporting.php index 129707ffcd..1892086c60 100644 --- a/public/main/survey/reporting.php +++ b/public/main/survey/reporting.php @@ -26,10 +26,7 @@ if (0 == $survey_data['anonymous']) { } else { $people_filled_full_data = false; } -$people_filled = SurveyManager::get_people_who_filled_survey( - $survey_id, - $people_filled_full_data -); +$people_filled = SurveyManager::get_people_who_filled_survey($survey_id, $people_filled_full_data); // Checking the parameters SurveyUtil::check_parameters($people_filled); @@ -40,7 +37,7 @@ $isDrhOfCourse = CourseManager::isUserSubscribedInCourseAsDrh( ); /** @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) || $isDrhOfCourse) { +if ($isDrhOfCourse || !api_is_allowed_to_edit(false, true)) { // Show error message if the survey can be seen only by tutors if (SURVEY_VISIBLE_TUTOR == $survey_data['visible_results']) { api_not_allowed(true); @@ -135,6 +132,85 @@ if ('overview' == $action) { } } +$htmlHeadXtra[] = ''; // Displaying the header Display::display_header($tool_name, 'Survey'); diff --git a/public/main/survey/survey.download.inc.php b/public/main/survey/survey.download.inc.php index bfde6d1fcd..a83ef585ec 100644 --- a/public/main/survey/survey.download.inc.php +++ b/public/main/survey/survey.download.inc.php @@ -69,6 +69,8 @@ function check_download_survey($course, $invitation, $doc_url) $survey_invitation['survey_id'] = $row['survey_id']; } + $doc_url = Database::escape_string($doc_url); + $survey_invitation['survey_id'] = Database::escape_string($survey_invitation['survey_id']); $sql = "SELECT count(*) FROM $table_survey WHERE @@ -85,8 +87,8 @@ function check_download_survey($course, $invitation, $doc_url) WHERE c_id = $course_id AND survey_id = ".$survey_invitation['survey_id']." AND ( - survey_question LIKE '%$doc_url%' - or survey_question_comment LIKE '%$doc_url%' + survey_question LIKE '%$doc_url%' OR + survey_question_comment LIKE '%$doc_url%' ) UNION SELECT count(*) diff --git a/public/main/survey/survey.lib.php b/public/main/survey/survey.lib.php index b8caa9da01..697cc4abcb 100644 --- a/public/main/survey/survey.lib.php +++ b/public/main/survey/survey.lib.php @@ -372,9 +372,15 @@ class SurveyManager $survey_id = $survey->getIid(); if ($survey_id > 0) { - $sql = "UPDATE $table_survey SET survey_id = $survey_id - WHERE iid = $survey_id"; - Database::query($sql); + Event::addEvent( + LOG_SURVEY_CREATED, + LOG_SURVEY_ID, + $survey_id, + null, + api_get_user_id(), + api_get_course_int_id(), + api_get_session_id() + ); // Insert into item_property api_item_property_update( @@ -659,6 +665,15 @@ class SurveyManager Database::query($sql); } + Event::addEvent( + LOG_SURVEY_DELETED, + LOG_SURVEY_ID, + $survey_id, + null, + api_get_user_id(), + api_get_course_int_id(), + api_get_session_id() + ); // Deleting groups of this survey $sql = "DELETE FROM $table_survey_question_group WHERE c_id = $course_id AND survey_id='".$survey_id."'"; @@ -864,6 +879,15 @@ class SurveyManager WHERE c_id = '.$courseId.' AND survey_id='.$surveyId; Database::query($sql); + Event::addEvent( + LOG_SURVEY_CLEAN_RESULTS, + LOG_SURVEY_ID, + $surveyId, + null, + api_get_user_id(), + api_get_course_int_id(), + api_get_session_id() + ); return true; } @@ -2379,6 +2403,14 @@ class SurveyManager return false; } + $extraFieldValue = new ExtraFieldValue('survey'); + $groupData = $extraFieldValue->get_values_by_handler_and_field_variable($surveyId, 'group_id'); + $groupId = null; + if ($groupData && !empty($groupData['value'])) { + $groupId = (int) $groupData['value']; + } + + if (null === $groupId) { $obj = new UserGroup(); $options['where'] = [' usergroup.course_id = ? ' => $courseId]; $classList = $obj->getUserGroupInCourse($options); @@ -2395,23 +2427,25 @@ class SurveyManager ]; } - self::parseMultiplicateUserList($classToParse, $questions, $courseId, $surveyData); - - $extraFieldValue = new ExtraFieldValue('survey'); - $groupData = $extraFieldValue->get_values_by_handler_and_field_variable($surveyId, 'group_id'); - if ($groupData && !empty($groupData['value'])) { - $groupInfo = GroupManager::get_group_properties($groupData['value']); + self::parseMultiplicateUserList($classToParse, $questions, $courseId, $surveyData, true); + } else { + $groupInfo = GroupManager::get_group_properties($groupId); if (!empty($groupInfo)) { $users = GroupManager::getStudents($groupInfo['iid'], true); if (!empty($users)) { $users = array_column($users, 'id'); - $classToParse = [ + self::parseMultiplicateUserList( + [ [ 'name' => $groupInfo['name'], 'users' => $users, ], - ]; - self::parseMultiplicateUserList($classToParse, $questions, $courseId, $surveyData); + ], + $questions, + $courseId, + $surveyData, + false + ); } } } @@ -2419,7 +2453,7 @@ class SurveyManager return true; } - public static function parseMultiplicateUserList($itemList, $questions, $courseId, $surveyData) + public static function parseMultiplicateUserList($itemList, $questions, $courseId, $surveyData, $addClassNewPage = false) { if (empty($itemList) || empty($questions)) { return false; @@ -2490,7 +2524,7 @@ class SurveyManager } } - if ($classCounter < count($itemList)) { + if ($addClassNewPage && $classCounter < count($itemList)) { // Add end page $values = [ 'c_id' => $courseId, diff --git a/public/main/survey/surveyUtil.class.php b/public/main/survey/surveyUtil.class.php index 570453ebea..f7c0625633 100644 --- a/public/main/survey/surveyUtil.class.php +++ b/public/main/survey/surveyUtil.class.php @@ -221,9 +221,9 @@ class SurveyUtil Display::display_header($tool_name); Display::display_footer(); exit; - } else { - return true; } + + return true; } /** @@ -575,7 +575,7 @@ class SurveyUtil $offset = !isset($_GET['question']) ? 0 : (int) $_GET['question']; $currentQuestion = isset($_GET['question']) ? (int) $_GET['question'] : 0; $surveyId = (int) $survey_data['survey_id']; - $action = Security::remove_XSS($_GET['action']); + $action = isset($_GET['action']) ? Security::remove_XSS($_GET['action']) : ''; $course_id = api_get_course_int_id(); // Database table definitions @@ -585,14 +585,40 @@ class SurveyUtil $questions = []; echo '
'; - echo ''. + echo ''. Display::return_icon( 'back.png', get_lang('Back to').' '.get_lang('Reporting overview'), '', ICON_SIZE_MEDIUM ).''; + echo Display::url( + Display::return_icon( + 'pdf.png', + get_lang('ExportToPdf'), + '', + ICON_SIZE_MEDIUM + ), + 'javascript: void(0);', + ['onclick' => 'exportToPdf();'] + ); echo '
'; + $fromUntil = sprintf(get_lang('FromXUntilY'), $survey_data['avail_from'], $survey_data['avail_till']); + $data = [ + get_lang('SurveyTitle') => $survey_data['title'], + get_lang('SurveySubTitle') => $survey_data['subtitle'], + get_lang('Dates') => $fromUntil, + get_lang('SurveyIntroduction') => $survey_data['intro'], + ]; + + $table = new HTML_Table(['id' => 'pdf_table', 'class' => 'table']); + $row = 0; + foreach ($data as $label => $item) { + $table->setCellContents($row, 0, $label); + $table->setCellContents($row, 1, $item); + $row++; + } if ($survey_data['number_of_questions'] > 0) { $limitStatement = null; @@ -636,7 +662,9 @@ class SurveyUtil $questions[$row['question_id']] = $row; } } + echo '
'; foreach ($questions as $question) { + echo '
'; $chartData = []; $options = []; $questionId = (int) $question['question_id']; @@ -705,18 +733,19 @@ class SurveyUtil array_push($chartData, ['option' => $optionText, 'votes' => $votes]); } $chartContainerId = 'chartContainer'.$question['question_id']; - echo '
'; + echo '
'; + echo self::drawChart($chartData, false, $chartContainerId, false); + echo '
'; - echo self::drawChart($chartData, false, $chartContainerId); // displaying the table: headers - echo '
'; + echo '
'; echo ' '; echo ' '; echo ' '; echo ' '; echo ' '; - echo ' '; + echo ' '; // Displaying the table: the content if (is_array($options)) { @@ -756,8 +785,11 @@ class SurveyUtil echo ' '; - echo ' '; - echo ' '; - echo ' '; - echo ' '; - echo ' '; - echo '
 '.get_lang('Absolute total').''.get_lang('Percentage').''.get_lang('Graphic').'
'; $size = $answers_number * 2; if ($size > 0) { - echo '
 
'; + echo '
+   +
'; } else { echo '
'.get_lang("No data available").'
'; } @@ -776,16 +808,21 @@ class SurveyUtil } // displaying the table: footer (totals) - echo '
'.get_lang('Total').''.$optionResult.'  
'; + echo '
'.get_lang('Total').''.$optionResult.'  
'; + } echo ''; } - } + echo ''; + + // Survey information, needed for the PDF export. + echo Display::page_subheader(get_lang('Survey')).'
'; + $table->display(); if (isset($_GET['viewoption'])) { echo '
'; @@ -892,7 +929,7 @@ class SurveyUtil echo ' '.get_lang('Absolute total').''; echo ' '.get_lang('Percentage').''; echo ' '.get_lang('Graphic').''; - echo ' '; + echo ' '; // Displaying the table: the content foreach ($options as $key => &$value) { for ($i = 1; $i <= $question['max_value']; $i++) { @@ -1004,7 +1041,7 @@ class SurveyUtil .$surveyId.'&'.api_get_cidreq().'">'; // The table - $content .= '
'; + $content .= '
'; // Getting the number of options per question $content .= ' '; $content .= '
'; @@ -2917,6 +2954,7 @@ class SurveyUtil $table->set_column_filter(8, 'anonymous_filter'); $actions = [ 'export_all' => get_lang('ExportResults'), + 'export_by_class' => get_lang('ExportByClass'), 'send_to_tutors' => get_lang('SendToGroupTutors'), 'multiplicate' => get_lang('MultiplicateQuestions'), 'delete' => get_lang('DeleteSurvey'), @@ -3836,62 +3874,69 @@ class SurveyUtil * * @return string (direct output) */ - public static function drawChart( - $chartData, - $hasSerie = false, - $chartContainerId = 'chartContainer' - ) { + public static function drawChart($chartData, $hasSerie = false, $chartContainerId = 'chartContainer', $loadLibs = true) + { $htmlChart = ''; if (api_browser_support('svg')) { - $htmlChart .= api_get_js('d3/d3.v3.5.4.min.js'); - $htmlChart .= api_get_js('dimple.v2.1.2.min.js').' - '; + $htmlChart .= 'myChart.draw();'; + $htmlChart .= ''; } return $htmlChart; diff --git a/public/main/survey/survey_invitation.php b/public/main/survey/survey_invitation.php index 6d5613f66f..cc63b80f02 100644 --- a/public/main/survey/survey_invitation.php +++ b/public/main/survey/survey_invitation.php @@ -104,7 +104,7 @@ echo ''; echo ''; // Table header -echo ''; +echo '
'; echo ' '; echo ' '; echo ' '; diff --git a/public/main/survey/survey_list.php b/public/main/survey/survey_list.php index 922bc1883d..407cdb7c25 100644 --- a/public/main/survey/survey_list.php +++ b/public/main/survey/survey_list.php @@ -86,6 +86,288 @@ if (isset($_POST['action']) && $_POST['action'] && isset($_POST['id']) && is_arr api_not_allowed(true); } + switch ($action) { + case 'export_by_class': + $surveyList = []; + $course_id = api_get_course_int_id(); + $extraFieldValue = new ExtraFieldValue('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_answer = Database::get_course_table(TABLE_SURVEY_ANSWER); + + foreach ($_POST['id'] as $value) { + $surveyData = SurveyManager::get_survey($value); + $surveyId = $surveyData['survey_id']; + if (empty($surveyData)) { + continue; + } + $surveyData['title'] = api_html_entity_decode(trim(strip_tags($surveyData['title']))); + $groupData = $extraFieldValue->get_values_by_handler_and_field_variable( + $surveyId, + 'group_id' + ); + $groupTitle = ''; + if ($groupData && !empty($groupData['value'])) { + $groupInfo = GroupManager::get_group_properties($groupData['value']); + if ($groupInfo['name']) { + $groupTitle = api_html_entity_decode($groupInfo['name']); + } + } + $surveyData['group_title'] = $groupTitle; + + $firstUser = ''; + $table = Database::get_course_table(TABLE_SURVEY_INVITATION); + $sql = "SELECT * FROM $table + WHERE + answered = 1 AND + c_id = $course_id AND + session_id = $sessionId AND + survey_code = '".Database::escape_string($surveyData['code'])."' + "; + $result = Database::query($sql); + $usersWithAnswers = []; + while ($row = Database::fetch_array($result)) { + if (isset($usersWithAnswers[$row['user']])) { + continue; + } + $userInfo = api_get_user_info($row['user']); + $usersWithAnswers[$row['user']] = $userInfo; + } + + $sql = "SELECT + survey_question.question_id, + survey_question.survey_id, + survey_question.survey_question, + survey_question.display, + survey_question.max_value, + survey_question.sort, + survey_question.type, + survey_question_option.question_option_id, + survey_question_option.option_text, + survey_question_option.sort as option_sort + 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 AND + survey_question_option.c_id = $course_id + WHERE + survey_question NOT LIKE '%{{%' AND + survey_question.survey_id = '".$surveyId."' AND + survey_question.c_id = $course_id + ORDER BY survey_question.sort, survey_question_option.sort ASC"; + $result = Database::query($sql); + $questionsOptions = []; + while ($row = Database::fetch_array($result, 'ASSOC')) { + if ($row['type'] != 'pagebreak') { + $questionsOptions[$row['sort']]['question_id'] = $row['question_id']; + $questionsOptions[$row['sort']]['survey_id'] = $row['survey_id']; + $questionsOptions[$row['sort']]['survey_question'] = $row['survey_question']; + $questionsOptions[$row['sort']]['display'] = $row['display']; + $questionsOptions[$row['sort']]['type'] = $row['type']; + $questionsOptions[$row['sort']]['maximum_score'] = $row['max_value']; + $questionsOptions[$row['sort']]['options'][$row['question_option_id']] = $row['option_text']; + } + } + + $sql = "SELECT * FROM $table_survey_answer + WHERE c_id = $course_id AND survey_id = $surveyId "; + $userAnswers = []; + $all_answers = []; + $result = Database::query($sql); + while ($answers_of_user = Database::fetch_array($result, 'ASSOC')) { + $userAnswers[$answers_of_user['user']][$surveyId][$answers_of_user['question_id']][] = $answers_of_user['option_id']; + $all_answers[$answers_of_user['user']][$answers_of_user['question_id']][] = $answers_of_user; + } + + foreach ($questionsOptions as $question) { + foreach ($usersWithAnswers as $userData) { + $userIdItem = $userData['user_id']; + // If the question type is a scoring then we have to format the answers differently + switch ($question['type']) { + /*case 'score': + $finalAnswer = []; + if (is_array($question) && is_array($all_answers)) { + foreach ($all_answers[$question['question_id']] as $key => &$answer_array) { + $finalAnswer[$answer_array['option_id']] = $answer_array['value']; + } + } + break;*/ + case 'multipleresponse': + $finalAnswer = isset($userAnswers[$userIdItem][$surveyId][$question['question_id']]) ? $userAnswers[$userIdItem][$surveyId][$question['question_id']] : ''; + if (is_array($finalAnswer)) { + $items = []; + foreach ($finalAnswer as $option) { + foreach ($question['options'] as $optionId => $text) { + if ($option == $optionId) { + $items[] = api_html_entity_decode(strip_tags($text)); + } + } + } + $finalAnswer = implode(' - ', $items); + } + break; + default: + $finalAnswer = ''; + if (isset($all_answers[$userIdItem][$question['question_id']])) { + $finalAnswer = $all_answers[$userIdItem][$question['question_id']][0]['option_id']; + foreach ($question['options'] as $optionId => $text) { + if ($finalAnswer == $optionId) { + $finalAnswer = api_html_entity_decode(strip_tags($text)); + break; + } + } + } + break; + } + $userAnswers[$userIdItem][$surveyId][$question['question_id']] = $finalAnswer; + } + } + + $surveyData['user_with_answers'] = $usersWithAnswers; + $surveyData['user_answers'] = $userAnswers; + $surveyData['questions'] = SurveyManager::get_questions($surveyId); + $surveyList[] = $surveyData; + } + + $userGroup = new UserGroup(); + $options = []; + $options['where'] = [' usergroup.course_id = ? ' => $course_id]; + $classes = $userGroup->getUserGroupInCourse($options, 0); + + @$spreadsheet = new PHPExcel(); + $counter = 0; + foreach ($classes as $class) { + $users = $userGroup->getUserListByUserGroup($class['id'], 'u.lastname ASC'); + $page = @$spreadsheet->createSheet($counter); + @$page->setTitle($class['name']); + $firstColumn = 3; + $column = 3; + $columnQuestion = 3; + foreach ($surveyList as $survey) { + $questions = $survey['questions']; + $usersWithAnswers = $survey['user_with_answers']; + foreach ($usersWithAnswers as $userAnswer) { + $userId = $userAnswer['user_id']; + $cell = @$page->setCellValueByColumnAndRow( + $column, + 1, + //$survey['title'].$survey['group_title'].' - '.$userAnswer['complete_name'] + $survey['group_title'].' - '.$userAnswer['complete_name'] + ); + $coordinate = $page->getCellByColumnAndRow($column, 1)->getCoordinate(); + /*if (!empty($coordinate)) { + $dimension = $cell->getColumnDimension($coordinate); + if ($dimension) { + $cell->getColumnDimension($coordinate)->setAutoSize(false); + $cell->getColumnDimension($coordinate)->setWidth("120"); + } + }*/ + //$page->getCellByColumnAndRow($column, 1)->getColumnDimension($coordinate)->setWidth(80); + $questionCounter = 0; + $firstCoordinate = $coordinate; + $lastCoordinate = ''; + foreach ($questions as $question) { + $questionTitle = $question['question']; + if (strpos($question['question'], '{{')) { + $questionPosition = $column + $questionCounter; + $cell = @$page->setCellValueByColumnAndRow( + $questionPosition, + 2, + strip_tags($questionTitle), + true + ); + + //$coordinate = @$page->getCellByColumnAndRow($questionPosition, 2)->getCoordinate(); + //$page->getColumnDimension($coordinate); + /*$dimension = @$page->getColumnDimension($questionPosition); + if ($dimension) { + $dimension->setAutoSize(true); + $dimension->setWidth(200); + //$cell->getColumnDimension($coordinate)->setAutoSize(false); + //$cell->getColumnDimension($coordinate)->setWidth("120"); + }*/ + + $coordinate = $page->getCellByColumnAndRow($questionPosition, 1)->getCoordinate(); + $lastCoordinate = $coordinate; + $rowStudent = 3; + foreach ($users as $user) { + $completeName = $user['firstname'].' '.$user['lastname']; + $questionTitle = str_replace( + '{{student_full_name}}', + $completeName, + $question['question'] + ); + + foreach ($questions as $questionData) { + if (strpos($questionData['question'], '{{') === false) { + if ($questionTitle === $questionData['question']) { + foreach ($survey['user_answers'][$userId][$survey['survey_id']] as $questionId => $answerData) { + if ($questionData['question_id'] == $questionId) { + if (is_array($answerData)) { + $answerData = implode(', ', $answerData); + } + @$page->setCellValueByColumnAndRow( + $questionPosition, + $rowStudent, + $answerData, + true + ); + break; + } + } + break; + } + } + } + $rowStudent++; + } + + $questionCounter++; + $columnQuestion++; + } + } + $column += $questionCounter; + $columnQuestion = $column; + + if (!empty($lastCoordinate)) { + $page->mergeCells($firstCoordinate.':'.$lastCoordinate); + } + } + + $questionPerUser = []; + foreach ($questions as $question) { + if (strpos($question['question'], '{{')) { + } else { + foreach ($users as $user) { + $completeName = $user['firstname'].' '.$user['lastname']; + if (strpos($question['question'], $completeName)) { + break; + } + $questionPerUser[$user['id']][] = $question['question_id']; + } + } + } + } + + $row = 2; + foreach ($users as $user) { + $userId = $user['id']; + $columnUser = 0; + @$page->setCellValueByColumnAndRow($columnUser++, $row, $user['lastname']); + @$page->setCellValueByColumnAndRow($columnUser++, $row, $user['firstname']); + $row++; + } + $counter++; + } + $spreadsheet->setActiveSheetIndex(0); + $file = api_get_path(SYS_ARCHIVE_PATH).uniqid('report', true); + @$writer = new PHPExcel_Writer_Excel2007($spreadsheet); + @$writer->save($file); + + DocumentManager::file_send_for_download($file, true, get_lang('Report').'.xlsx'); + break; + } $exportList = []; foreach ($_POST['id'] as $value) { $surveyData = SurveyManager::get_survey($value); diff --git a/public/main/survey/survey_question.php b/public/main/survey/survey_question.php index 3279911b6b..48fa84725d 100644 --- a/public/main/survey/survey_question.php +++ b/public/main/survey/survey_question.php @@ -25,7 +25,7 @@ class survey_question $questions = SurveyManager::get_questions($surveyId); $newQuestionList = []; - $allowTypes = ['yesno', 'multiplechoice']; + $allowTypes = ['yesno', 'multiplechoice', 'multipleresponse']; foreach ($questions as $question) { if (in_array($question['type'], $allowTypes)) { $newQuestionList[$question['sort']] = $question; @@ -64,7 +64,7 @@ class survey_question $.getJSON({ url: "'.$url.'" + "&question_id=" + questionId, success: function(data) { - $("#parent_options").html(data); + $("#option_list").show(); $.each(data, function(key, value) { $("
'.get_lang('User').''.get_lang('Invitation date').'