using the same form reduces duplicate code refs BT#7277

1.9.x
César Perales 12 years ago
parent 5a9d3bd05e
commit dd38b9117e
  1. 142
      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,43 +673,49 @@ 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);
$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'])));
}
$sessionFilter->addElement('select_ajax', 'survey_name', get_lang('SearchSurvey'), null, array('url' => $url, 'defaults' => $surveyList, 'width' => '400px'));
echo '<div class="">'; $script = '
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() {
$("#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 sessionId = $("#session_name").val();
var courseId = $("#course_name").val(); var courseId = $("#course_name").val();
window.location = "'.$courseListUrl.'?view=admin&display='.$display.'&session_id="+sessionId+"&course_id="+courseId; 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 . '
}); });
function areBothFilled() { $("#date_from, #date_to").datepicker({
var returnValue = false; dateFormat: "yy-mm-dd",
if ((document.getElementById("date_from").value != "") && (document.getElementById("date_to").value != "")){ onSelect: function( selectedDate ) {
returnValue = true; 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;
} }
return returnValue;
} }
</script>'; });';
}
//Student and profile filter
if (in_array($display, array('accessoverview'))) {
//Student Filter
if (in_array($display, array('accessoverview')))
{
$courseListUrl = api_get_self();
$studentFilter = new FormValidator('student_filter', 'get', '', '', array('class'=> 'form-horizontal'), false);
$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']; $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'];
$studentList = array(); $studentList = array();
$studentId = isset($_GET['student_id']) ? $_GET['student_id'] : null; $studentId = isset($_GET['student_id']) ? $_GET['student_id'] : null;
@ -719,25 +725,16 @@ if ($is_platform_admin && in_array($view, array('admin')) && $display != 'yourst
$studentList[] = array('id' => $studentInfo['id'], 'text' => $studentInfo['username']); $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' ));
$studentFilter->addElement('select_ajax', 'student_name', get_lang('SearchStudent'), null, array('url' => $url, 'defaults' => $studentList, 'width' => '400px'), array('class' => 'pull-left'));
$options = array( $options = array(
'' => get_lang('Select'), '' => get_lang('Select'),
STUDENT => get_lang('Student'), STUDENT => get_lang('Student'),
COURSEMANAGER => get_lang('CourseManager'), COURSEMANAGER => get_lang('CourseManager'),
DRH => get_lang('Drh'), DRH => get_lang('Drh'),
); );
$studentFilter->addElement('select', 'profile', get_lang('Profile'),$options, array('id' => 'profile')); $sessionFilter->addElement('select', 'profile', get_lang('Profile'),$options, array('id' => 'profile'));
//$studentFilter->addElement('submit', '', get_lang('Generate'), 'id="generateReport"');
echo '<div class="">'; $script = '
echo $studentFilter->return_form();
echo '</div>';
echo '<script>
$(function() {
$("#student_name").on("change", 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();
@ -767,66 +764,32 @@ 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>';
} //date filter
if (in_array($display, array('surveyoverview'))) $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' ));
$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' )); $sessionFilter->addElement('submit', '', get_lang('Generate'), 'id="generateReport"');
$surveyOverview->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(); $courseListUrl = api_get_self();
echo '<div class="">'; echo '<div class="">';
echo $surveyOverview ->return_form(); echo $sessionFilter->return_form();
echo '</div>'; echo '</div>';
echo '<script> echo '<script>
$(function() { $(function() {
$("#survey_name").on("change", function() { $("#session_name").on("change", function() {
var date_to = $("#date_to").val(); var sessionId = $(this).val();
var date_from = $("#date_from").val(); window.location = "'.$courseListUrl.'?view=admin&display='.$display.'&session_id="+sessionId;
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({ $("#course_name").on("change", function() {
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 sessionId = $("#session_name").val();
var courseId = $("#course_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;
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 . '
}); });
function areBothFilled() { function areBothFilled() {
var returnValue = false; var returnValue = false;
@ -836,7 +799,6 @@ if ($is_platform_admin && in_array($view, array('admin')) && $display != 'yourst
return returnValue; return returnValue;
} }
</script>'; </script>';
}
} }

Loading…
Cancel
Save