date filter added
Showing
3 changed files
with
112 additions
and
10 deletions
ajax.php
0 → 100644
1 | <?php | ||
2 | // This file is part of Moodle - http://moodle.org/ | ||
3 | // | ||
4 | // Moodle is free software: you can redistribute it and/or modify | ||
5 | // it under the terms of the GNU General Public License as published by | ||
6 | // the Free Software Foundation, either version 3 of the License, or | ||
7 | // (at your option) any later version. | ||
8 | // | ||
9 | // Moodle is distributed in the hope that it will be useful, | ||
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | // GNU General Public License for more details. | ||
13 | // | ||
14 | // You should have received a copy of the GNU General Public License | ||
15 | // along with Moodle. If not, see <http://www.gnu.org/licenses/>. | ||
16 | |||
17 | /** | ||
18 | * Log block caps. | ||
19 | * | ||
20 | * @package block_log | ||
21 | * @copyright Vanisha <vanisha@teknoturf.com> | ||
22 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
23 | */ | ||
24 | |||
25 | require_once(dirname(dirname(dirname(__FILE__))) . '/config.php'); | ||
26 | |||
27 | global $CFG; | ||
28 | require_login(); | ||
29 | |||
30 | if (isset($_GET['choice'])) { | ||
31 | $choice = $_GET['choice']; | ||
32 | |||
33 | if ($choice === 'get_logs') { | ||
34 | $date_filter = $_GET['date']; | ||
35 | $date_filter = date('d-m-y',strtotime($date_filter)); | ||
36 | $configpaths = get_config(null, 'block_log_path_info'); | ||
37 | |||
38 | $table_content_array = array(); $i =1; | ||
39 | $split_paths = explode(",",$configpaths); | ||
40 | foreach($split_paths as $split_path) { | ||
41 | $files = scandir($split_path); | ||
42 | foreach($files as $file) { | ||
43 | if($file === '.' || $file === '..') {continue;} | ||
44 | if( (strpos($file, $date_filter) !== false) && (strpos($file, '.log')) ) { | ||
45 | $n = new stdClass(); | ||
46 | $n->sno = $i; | ||
47 | $n->name = $file; | ||
48 | $n->log = file_get_contents($split_path.'/'.$file); | ||
49 | $table_content_array[] = $n; | ||
50 | $i = $i+1; | ||
51 | } | ||
52 | } | ||
53 | } | ||
54 | $response_obj = new stdClass(); | ||
55 | $response_obj->userdata = json_encode($table_content_array); | ||
56 | echo json_encode($response_obj); | ||
57 | } | ||
58 | } | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
... | @@ -14,6 +14,14 @@ | ... | @@ -14,6 +14,14 @@ |
14 | <label for="date_filter">Date</label> | 14 | <label for="date_filter">Date</label> |
15 | <input type="date" id="date_filter" class="form-control" aria-label="Default" aria-describedby="date_filter"> | 15 | <input type="date" id="date_filter" class="form-control" aria-label="Default" aria-describedby="date_filter"> |
16 | </div> | 16 | </div> |
17 | <div id="date_filter_error_div"></div> | ||
18 | </div> | ||
19 | <div class="input-group mb-3"> | ||
20 | <div> | ||
21 | <button id="filter_logs" class="btn btn-primary" type="button" title="Filter">Filter | ||
22 | <span class="icon-stack"><i style="line-height: 0.5em;" class="icon-filter icon-stack-base" aria-hidden="true"></i> | ||
23 | <i style="line-height: 0.2em;" class="icon-add"></i></span></button> | ||
24 | </div> | ||
17 | </div> | 25 | </div> |
18 | </div> | 26 | </div> |
19 | 27 | ||
... | @@ -33,14 +41,50 @@ | ... | @@ -33,14 +41,50 @@ |
33 | </div> | 41 | </div> |
34 | 42 | ||
35 | <script> | 43 | <script> |
36 | $('#view_logs_entries_table').DataTable({ | 44 | |
37 | dom: 'lBfrtip', | 45 | var log_DataTable = ""; |
38 | "pageLength": 30, | 46 | log_DataTable = $('#view_logs_entries_table').DataTable({ |
39 | "lengthChange": false, | 47 | dom: 'lBfrtip', |
40 | lengthMenu: [[10, 25, 50, 100],[10, 25, 50, 100]], | 48 | "pageLength": 30, |
41 | "language": { | 49 | "lengthChange": false, |
42 | "emptyTable": "No records found." | 50 | lengthMenu: [[10, 25, 50, 100],[10, 25, 50, 100]], |
43 | } | 51 | "language": { |
44 | }); | 52 | "emptyTable": "No records found." |
53 | }, | ||
54 | "columns": [ | ||
55 | { "data": "sno" }, | ||
56 | { "data": "name" }, | ||
57 | { "data": "log" } | ||
58 | ] | ||
59 | }); | ||
60 | |||
61 | $('#view_slots_filter').click(function() { | ||
62 | var date = $("#date_filter").val(); | ||
63 | if((date == '')) { | ||
64 | var alert_message = '<p style="color: red;">* Please select date filter.</p>'; | ||
65 | if(('#date_filter_error_div').length != 0 ) { | ||
66 | $('#date_filter_error_div').empty(); | ||
67 | } | ||
68 | $('#date_filter_error_div').append(alert_message); | ||
69 | |||
70 | } | ||
71 | else { | ||
72 | if(('#date_filter_error_div').length != 0 ) { | ||
73 | $('#date_filter_error_div').empty(); | ||
74 | } | ||
75 | $.ajax({ | ||
76 | method: "GET", | ||
77 | url: M.cfg.wwwroot + '/blocks/log/ajax.php', | ||
78 | data: {"choice" : "get_logs","date" : date} | ||
79 | }).done(function(response) { | ||
80 | var data = JSON.parse(response); | ||
81 | var userdata = JSON.parse(data.userdata); | ||
82 | log_DataTable.clear().draw(); | ||
83 | log_DataTable.rows.add(userdata).draw(); | ||
84 | |||
85 | }); | ||
86 | } | ||
87 | |||
88 | }); | ||
45 | 89 | ||
46 | </script> | 90 | </script> |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
... | @@ -49,7 +49,7 @@ $templatecontext = array(); | ... | @@ -49,7 +49,7 @@ $templatecontext = array(); |
49 | // breadcrumb template | 49 | // breadcrumb template |
50 | $templatecontext['breadcrumb_navbar'] = $OUTPUT->navbar(); | 50 | $templatecontext['breadcrumb_navbar'] = $OUTPUT->navbar(); |
51 | 51 | ||
52 | $configpaths = get_config('block_log', 'block_log_path_info'); | 52 | $configpaths = get_config(null, 'block_log_path_info'); |
53 | 53 | ||
54 | $isadmin = has_capability('block/log:manageall', context_system::instance()); | 54 | $isadmin = has_capability('block/log:manageall', context_system::instance()); |
55 | 55 | ... | ... |
-
Please register or sign in to post a comment