using the same form reduces duplicate code refs BT#7277

1.9.x
César Perales 12 years ago
parent 5a9d3bd05e
commit dd38b9117e
  1. 214
      main/mySpace/index.php

@ -648,8 +648,8 @@ if ($is_platform_admin && in_array($view, array('admin')) && $display != 'yourst
} }
$sessionFilter->addElement('select_ajax', 'exercise_name', get_lang('SearchExercise'), null, array('url' => $url, 'defaults' => $exerciseList, 'width' => '400px')); $sessionFilter->addElement('select_ajax', 'exercise_name', get_lang('SearchExercise'), null, array('url' => $url, 'defaults' => $exerciseList, 'width' => '400px'));
$script = '$("#exercise_name").on("change", function() { $script = '
console.log("test"); $("#exercise_name").on("change", function() {
var date_to = $("#date_to").val(); var date_to = $("#date_to").val();
var date_from = $("#date_from").val(); var date_from = $("#date_from").val();
var sessionId = $("#session_name").val(); var sessionId = $("#session_name").val();
@ -673,72 +673,69 @@ if ($is_platform_admin && in_array($view, array('admin')) && $display != 'yourst
});'; });';
} }
//survey filter
if (in_array($display, array('surveyoverview'))) {
//date filter $url = api_get_path(WEB_AJAX_PATH).'course.ajax.php?a=search_survey_by_course&session_id=' . $_GET['session_id'] . '&course_id=' . $_GET['course_id'] . '&survey_id=' . $_GET['survey_id'];
$sessionFilter->addElement('text', 'from', get_lang('From'), array('id' => 'date_from', 'value' => (!empty($_GET['date_from']) ? $_GET['date_from'] : ''), 'style' => 'width:75px' )); $surveyList = array();
$sessionFilter->addElement('text', 'to', get_lang('Until'), array('id' => 'date_to', 'value' => (!empty($_GET['date_to']) ? $_GET['date_to'] : ''), 'style' => 'width:75px' )); $surveyId = isset($_GET['survey_id']) ? intval($_GET['survey_id']) : null;
$courseId = isset($_GET['course_id']) ? intval($_GET['course_id']) : null;
$courseListUrl = api_get_self(); if (!empty($surveyId)) {
$course = api_get_course_info_by_id($courseId);
echo '<div class="">'; $surveyList = array();
echo $sessionFilter->return_form(); $exerciseInfo = survey_manager::get_survey($surveyId, 0, $course['code']);
echo '</div>'; $surveyList[] = array('id' => $exerciseInfo['survey_id'], 'text' => strip_tags(html_entity_decode($exerciseInfo['title'])));
echo '<script>
$(function() {
$("#session_name").on("change", function() {
var sessionId = $(this).val();
window.location = "'.$courseListUrl.'?view=admin&display='.$display.'&session_id="+sessionId;
});
$("#course_name").on("change", function() {
var sessionId = $("#session_name").val();
var courseId = $("#course_name").val();
window.location = "'.$courseListUrl.'?view=admin&display='.$display.'&session_id="+sessionId+"&course_id="+courseId;
});
' . $script . '
});
function areBothFilled() {
var returnValue = false;
if ((document.getElementById("date_from").value != "") && (document.getElementById("date_to").value != "")){
returnValue = true;
} }
return returnValue; $sessionFilter->addElement('select_ajax', 'survey_name', get_lang('SearchSurvey'), null, array('url' => $url, 'defaults' => $surveyList, 'width' => '400px'));
$script = '
$("#survey_name").on("change", function() {
var date_to = $("#date_to").val();
var date_from = $("#date_from").val();
var sessionId = $("#session_name").val();
var courseId = $("#course_name").val();
var surveyId = $("#survey_name").val();
window.location = "'.$courseListUrl.'?view=admin&display='.$display.'&session_id="+sessionId+"&course_id="+courseId+"&survey_id="+surveyId+"&date_to="+date_to+"&date_from="+date_from;
});
$("#date_from, #date_to").datepicker({
dateFormat: "yy-mm-dd",
onSelect: function( selectedDate ) {
var filled = areBothFilled();
if (filled) {
var date_to = $("#date_to").val();
var date_from = $("#date_from").val();
var sessionId = $("#session_name").val();
var courseId = $("#course_name").val();
var surveyId = $("#survey_name").val();
window.location = "'.$courseListUrl.'?view=admin&display='.$display.'&session_id="+sessionId+"&course_id="+courseId+"&survey_id="+surveyId+"&date_to="+date_to+"&date_from="+date_from;
}
}
});';
} }
</script>';
//Student Filter //Student and profile filter
if (in_array($display, array('accessoverview'))) if (in_array($display, array('accessoverview'))) {
{
$courseListUrl = api_get_self(); $url = api_get_path(WEB_AJAX_PATH).'course.ajax.php?a=search_user_by_course&session_id=' . $_GET['session_id'] . '&course_id=' . $_GET['course_id'];
$studentFilter = new FormValidator('student_filter', 'get', '', '', array('class'=> 'form-horizontal'), false); $studentList = array();
$url = api_get_path(WEB_AJAX_PATH).'course.ajax.php?a=search_user_by_course&session_id=' . $_GET['session_id'] . '&course_id=' . $_GET['course_id']; $studentId = isset($_GET['student_id']) ? $_GET['student_id'] : null;
if (!empty($studentId)) {
$studentList = array(); $studentList = array();
$studentId = isset($_GET['student_id']) ? $_GET['student_id'] : null; $studentInfo = UserManager::get_user_info_by_id($studentId);
if (!empty($studentId)) { $studentList[] = array('id' => $studentInfo['id'], 'text' => $studentInfo['username']);
$studentList = array(); }
$studentInfo = UserManager::get_user_info_by_id($studentId);
$studentList[] = array('id' => $studentInfo['id'], 'text' => $studentInfo['username']);
}
$studentFilter->addElement('text', 'from', get_lang('From'), array('id' => 'date_from', 'value' => (!empty($_GET['date_from']) ? $_GET['date_from'] : ''), 'style' => 'width:75px' )); $sessionFilter->addElement('select_ajax', 'student_name', get_lang('SearchStudent'), null, array('url' => $url, 'defaults' => $studentList, 'width' => '400px'), array('class' => 'pull-left'));
$studentFilter->addElement('text', 'to', get_lang('Until'), array('id' => 'date_to', 'value' => (!empty($_GET['date_to']) ? $_GET['date_to'] : ''), 'style' => 'width:75px' )); $options = array(
'' => get_lang('Select'),
$studentFilter->addElement('select_ajax', 'student_name', get_lang('SearchStudent'), null, array('url' => $url, 'defaults' => $studentList, 'width' => '400px'), array('class' => 'pull-left')); STUDENT => get_lang('Student'),
$options = array( COURSEMANAGER => get_lang('CourseManager'),
'' => get_lang('Select'), DRH => get_lang('Drh'),
STUDENT => get_lang('Student'), );
COURSEMANAGER => get_lang('CourseManager'), $sessionFilter->addElement('select', 'profile', get_lang('Profile'),$options, array('id' => 'profile'));
DRH => get_lang('Drh'),
); $script = '
$studentFilter->addElement('select', 'profile', get_lang('Profile'),$options, array('id' => 'profile')); $("#student_name").on("change", function() {
//$studentFilter->addElement('submit', '', get_lang('Generate'), 'id="generateReport"');
echo '<div class="">';
echo $studentFilter->return_form();
echo '</div>';
echo '<script>
$(function() {
$("#student_name").on("change", function() {
var date_to = $(\'#date_to\').val(); var date_to = $(\'#date_to\').val();
var date_from = $(\'#date_from\').val(); var date_from = $(\'#date_from\').val();
var sessionId = $("#session_name").val(); var sessionId = $("#session_name").val();
@ -767,77 +764,42 @@ if ($is_platform_admin && in_array($view, array('admin')) && $display != 'yourst
window.location = "'.$courseListUrl.'?view=admin&display='.$display.'&session_id="+sessionId+"&course_id="+courseId+"&student_id="+studentId+"&date_to="+date_to+"&date_from="+date_from; window.location = "'.$courseListUrl.'?view=admin&display='.$display.'&session_id="+sessionId+"&course_id="+courseId+"&student_id="+studentId+"&date_to="+date_to+"&date_from="+date_from;
} }
} }
}); });';
});
function areBothFilled() {
var returnValue = false;
if ((document.getElementById("date_from").value != "") && (document.getElementById("date_to").value != "")){
returnValue = true;
}
return returnValue;
}
</script>';
} }
if (in_array($display, array('surveyoverview')))
{
$surveyOverview = new FormValidator('survey_filter', 'get', '', '', array('class'=> 'form-horizontal'), false);
$url = api_get_path(WEB_AJAX_PATH).'course.ajax.php?a=search_survey_by_course&session_id=' . $_GET['session_id'] . '&course_id=' . $_GET['course_id'] . '&survey_id=' . $_GET['survey_id'];
$surveyList = array();
$surveyId = isset($_GET['survey_id']) ? intval($_GET['survey_id']) : null;
$courseId = isset($_GET['course_id']) ? intval($_GET['course_id']) : null;
if (!empty($surveyId)) {
$course = api_get_course_info_by_id($courseId);
$surveyList = array();
$exerciseInfo = survey_manager::get_survey($surveyId, 0, $course['code']);
$surveyList[] = array('id' => $exerciseInfo['survey_id'], 'text' => strip_tags(html_entity_decode($exerciseInfo['title'])));
}
$surveyOverview->addElement('select_ajax', 'survey_name', get_lang('SearchSurvey'), null, array('url' => $url, 'defaults' => $surveyList, 'width' => '400px'));
$surveyOverview->addElement('text', 'from', get_lang('From'), array('id' => 'date_from', 'value' => (!empty($_GET['date_from']) ? $_GET['date_from'] : ''), 'style' => 'width:75px' )); //date filter
$surveyOverview->addElement('text', 'to', get_lang('Until'), array('id' => 'date_to', 'value' => (!empty($_GET['date_to']) ? $_GET['date_to'] : ''), 'style' => 'width:75px' )); $sessionFilter->addElement('text', 'from', get_lang('From'), array('id' => 'date_from', 'value' => (!empty($_GET['date_from']) ? $_GET['date_from'] : ''), 'style' => 'width:75px' ));
$sessionFilter->addElement('text', 'to', get_lang('Until'), array('id' => 'date_to', 'value' => (!empty($_GET['date_to']) ? $_GET['date_to'] : ''), 'style' => 'width:75px' ));
$courseListUrl = api_get_self();
$sessionFilter->addElement('submit', '', get_lang('Generate'), 'id="generateReport"');
echo '<div class="">'; $courseListUrl = api_get_self();
echo $surveyOverview ->return_form();
echo '</div>';
echo '<script> echo '<div class="">';
$(function() { echo $sessionFilter->return_form();
$("#survey_name").on("change", function() { echo '</div>';
var date_to = $("#date_to").val(); echo '<script>
var date_from = $("#date_from").val(); $(function() {
var sessionId = $("#session_name").val(); $("#session_name").on("change", function() {
var courseId = $("#course_name").val(); var sessionId = $(this).val();
var surveyId = $("#survey_name").val(); window.location = "'.$courseListUrl.'?view=admin&display='.$display.'&session_id="+sessionId;
window.location = "'.$courseListUrl.'?view=admin&display='.$display.'&session_id="+sessionId+"&course_id="+courseId+"&survey_id="+surveyId+"&date_to="+date_to+"&date_from="+date_from;
});
$("#date_from, #date_to").datepicker({
dateFormat: "yy-mm-dd",
onSelect: function( selectedDate ) {
var filled = areBothFilled();
if (filled) {
var date_to = $("#date_to").val();
var date_from = $("#date_from").val();
var sessionId = $("#session_name").val();
var courseId = $("#course_name").val();
var surveyId = $("#survey_name").val();
window.location = "'.$courseListUrl.'?view=admin&display='.$display.'&session_id="+sessionId+"&course_id="+courseId+"&survey_id="+surveyId+"&date_to="+date_to+"&date_from="+date_from;
}
}
});
}); });
function areBothFilled() { $("#course_name").on("change", function() {
var returnValue = false; var sessionId = $("#session_name").val();
if ((document.getElementById("date_from").value != "") && (document.getElementById("date_to").value != "")){ var courseId = $("#course_name").val();
returnValue = true; window.location = "'.$courseListUrl.'?view=admin&display='.$display.'&session_id="+sessionId+"&course_id="+courseId;
} });
return returnValue; ' . $script . '
});
function areBothFilled() {
var returnValue = false;
if ((document.getElementById("date_from").value != "") && (document.getElementById("date_to").value != "")){
returnValue = true;
} }
</script>'; return returnValue;
} }
</script>';
} }

Loading…
Cancel
Save