c8627f47 by vanisha

date filter added

1 parent 36cae97a
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Log block caps.
*
* @package block_log
* @copyright Vanisha <vanisha@teknoturf.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once(dirname(dirname(dirname(__FILE__))) . '/config.php');
global $CFG;
require_login();
if (isset($_GET['choice'])) {
$choice = $_GET['choice'];
if ($choice === 'get_logs') {
$date_filter = $_GET['date'];
$date_filter = date('d-m-y',strtotime($date_filter));
$configpaths = get_config(null, 'block_log_path_info');
$table_content_array = array(); $i =1;
$split_paths = explode(",",$configpaths);
foreach($split_paths as $split_path) {
$files = scandir($split_path);
foreach($files as $file) {
if($file === '.' || $file === '..') {continue;}
if( (strpos($file, $date_filter) !== false) && (strpos($file, '.log')) ) {
$n = new stdClass();
$n->sno = $i;
$n->name = $file;
$n->log = file_get_contents($split_path.'/'.$file);
$table_content_array[] = $n;
$i = $i+1;
}
}
}
$response_obj = new stdClass();
$response_obj->userdata = json_encode($table_content_array);
echo json_encode($response_obj);
}
}
\ No newline at end of file
......@@ -14,6 +14,14 @@
<label for="date_filter">Date</label>
<input type="date" id="date_filter" class="form-control" aria-label="Default" aria-describedby="date_filter">
</div>
<div id="date_filter_error_div"></div>
</div>
<div class="input-group mb-3">
<div>
<button id="filter_logs" class="btn btn-primary" type="button" title="Filter">Filter
<span class="icon-stack"><i style="line-height: 0.5em;" class="icon-filter icon-stack-base" aria-hidden="true"></i>
<i style="line-height: 0.2em;" class="icon-add"></i></span></button>
</div>
</div>
</div>
......@@ -33,14 +41,50 @@
</div>
<script>
$('#view_logs_entries_table').DataTable({
dom: 'lBfrtip',
"pageLength": 30,
"lengthChange": false,
lengthMenu: [[10, 25, 50, 100],[10, 25, 50, 100]],
"language": {
"emptyTable": "No records found."
}
});
var log_DataTable = "";
log_DataTable = $('#view_logs_entries_table').DataTable({
dom: 'lBfrtip',
"pageLength": 30,
"lengthChange": false,
lengthMenu: [[10, 25, 50, 100],[10, 25, 50, 100]],
"language": {
"emptyTable": "No records found."
},
"columns": [
{ "data": "sno" },
{ "data": "name" },
{ "data": "log" }
]
});
$('#view_slots_filter').click(function() {
var date = $("#date_filter").val();
if((date == '')) {
var alert_message = '<p style="color: red;">* Please select date filter.</p>';
if(('#date_filter_error_div').length != 0 ) {
$('#date_filter_error_div').empty();
}
$('#date_filter_error_div').append(alert_message);
}
else {
if(('#date_filter_error_div').length != 0 ) {
$('#date_filter_error_div').empty();
}
$.ajax({
method: "GET",
url: M.cfg.wwwroot + '/blocks/log/ajax.php',
data: {"choice" : "get_logs","date" : date}
}).done(function(response) {
var data = JSON.parse(response);
var userdata = JSON.parse(data.userdata);
log_DataTable.clear().draw();
log_DataTable.rows.add(userdata).draw();
});
}
});
</script>
\ No newline at end of file
......
......@@ -49,7 +49,7 @@ $templatecontext = array();
// breadcrumb template
$templatecontext['breadcrumb_navbar'] = $OUTPUT->navbar();
$configpaths = get_config('block_log', 'block_log_path_info');
$configpaths = get_config(null, 'block_log_path_info');
$isadmin = has_capability('block/log:manageall', context_system::instance());
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!