MDL-22054 the last blockname removed
[moodle.git] / search / stats.php
CommitLineData
682d4032 1<?php
70f52c70 2/**
2f338ab5 3* Global Search Engine for Moodle
3319ef85 4*
5* @package search
6* @category core
7* @subpackage search_engine
8* @author Michael Champanis (mchampan) [cynnical@gmail.com], Valery Fremaux [valery.fremaux@club-internet.fr] > 1.8
9* @date 2008/03/31
63c13a82 10* @version prepared for 2.0
3319ef85 11* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
2f338ab5 12*
13* Prints some basic statistics about the current index.
14* Does some diagnostics if you are logged in as an administrator.
70f52c70 15*
2f338ab5 16*/
17
3319ef85 18/**
19* includes and requires
20*/
2f338ab5 21require_once('../config.php');
63c13a82 22require_once($CFG->dirroot.'/search/lib.php');
2f338ab5 23
3319ef85 24/// checks global search is enabled
eef868d1 25
3319ef85 26 if ($CFG->forcelogin) {
27 require_login();
28 }
70f52c70 29
3319ef85 30 if (empty($CFG->enableglobalsearch)) {
32487831 31 print_error('globalsearchdisabled', 'search');
3319ef85 32 }
70f52c70 33
e3c7f155 34/// check for php5, but don't die yet
35
63c13a82 36 require_once($CFG->dirroot.'/search/indexlib.php');
70f52c70 37
66cb53c5 38 $indexinfo = new IndexInfo();
70f52c70 39
2a250a0b 40 $site = get_site();
70f52c70 41
3319ef85 42 $strsearch = get_string('search', 'search');
70f52c70 43 $strquery = get_string('statistics', 'search');
44
63c13a82 45 $site = get_site();
766ccfbd 46
a6855934
PS
47 $PAGE->set_url('/search/stats.php');
48 $PAGE->navbar->add($strsearch, new moodle_url('/search/index.php'));
49 $PAGE->navbar->add($strquery, new moodle_url('/search/stats.php'));
766ccfbd 50 $PAGE->set_title($strsearch);
51 $PAGE->set_heading($site->fullname);
52 echo $OUTPUT->header();
70f52c70 53
3319ef85 54/// keep things pretty, even if php5 isn't available
eef868d1 55
70f52c70 56 echo $OUTPUT->box_start();
f7a1496e 57 echo $OUTPUT->heading($strquery);
70f52c70 58
59 echo $OUTPUT->box_start();
60
3319ef85 61 $databasestr = get_string('database', 'search');
62 $documentsinindexstr = get_string('documentsinindex', 'search');
63 $deletionsinindexstr = get_string('deletionsinindex', 'search');
64 $documentsindatabasestr = get_string('documentsindatabase', 'search');
65 $databasestatestr = get_string('databasestate', 'search');
70f52c70 66
3319ef85 67/// this table is only for admins, shows index directory size and location
68
4f0c2d00 69 if (has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM))) {
3319ef85 70 $datadirectorystr = get_string('datadirectory', 'search');
71 $inindexdirectorystr = get_string('filesinindexdirectory', 'search');
72 $totalsizestr = get_string('totalsize', 'search');
73 $errorsstr = get_string('errors', 'search');
74 $solutionsstr = get_string('solutions', 'search');
75 $checkdirstr = get_string('checkdir', 'search');
76 $checkdbstr = get_string('checkdb', 'search');
77 $checkdiradvicestr = get_string('checkdiradvice', 'search');
78 $checkdbadvicestr = get_string('checkdbadvice', 'search');
79 $runindexerteststr = get_string('runindexertest', 'search');
80 $runindexerstr = get_string('runindexer', 'search');
70f52c70 81
c5339263 82 $admin_table = new html_table();
63c13a82 83 $admin_table->tablealign = 'center';
84 $admin_table->align = array ('right', 'left');
85 $admin_table->wrap = array ('nowrap', 'nowrap');
3319ef85 86 $admin_table->cellpadding = 5;
87 $admin_table->cellspacing = 0;
88 $admin_table->width = '500';
70f52c70 89
3319ef85 90 $admin_table->data[] = array("<strong>{$datadirectorystr}</strong>", '<em><strong>'.$indexinfo->path.'</strong></em>');
91 $admin_table->data[] = array($inindexdirectorystr, $indexinfo->filecount);
92 $admin_table->data[] = array($totalsizestr, $indexinfo->size);
70f52c70 93
3319ef85 94 if ($indexinfo->time > 0) {
95 $admin_table->data[] = array(get_string('createdon', 'search'), date('r', $indexinfo->time));
70f52c70 96 }
3319ef85 97 else {
98 $admin_table->data[] = array(get_string('createdon', 'search'), '-');
70f52c70 99 }
100
3319ef85 101 if (!$indexinfo->valid($errors)) {
102 $admin_table->data[] = array("<strong>{$errorsstr}</strong>", '&nbsp;');
103 foreach ($errors as $key => $value) {
104 $admin_table->data[] = array($key.' ... ', $value);
70f52c70 105 }
3319ef85 106 }
70f52c70 107
16be8974 108 echo html_writer::table($admin_table);
1ba862ec 109 echo $OUTPUT->spacer(array('height'=>20, 'br'=>true)); // should be done with CSS instead
f7a1496e 110 echo $OUTPUT->heading($solutionsstr);
70f52c70 111
3319ef85 112 unset($admin_table->data);
113 if (isset($errors['dir'])) {
114 $admin_table->data[] = array($checkdirstr, $checkdiradvicestr);
70f52c70 115 }
3319ef85 116 if (isset($errors['db'])) {
117 $admin_table->data[] = array($checkdbstr, $checkdbadvicestr);
70f52c70 118 }
119
3319ef85 120 $admin_table->data[] = array($runindexerteststr, '<a href="tests/index.php" target="_blank">tests/index.php</a>');
121 $admin_table->data[] = array($runindexerstr, '<a href="indexersplash.php" target="_blank">indexersplash.php</a>');
70f52c70 122
16be8974 123 echo html_writer::table($admin_table);
08822fd6 124 echo $OUTPUT->spacer($spacer) . '<br />';
70f52c70 125 }
126
3319ef85 127/// this is the standard summary table for normal users, shows document counts
128
c5339263 129 $table = new html_table();
63c13a82 130 $table->tablealign = 'center';
131 $table->align = array ('right', 'left');
132 $table->wrap = array ('nowrap', 'nowrap');
3319ef85 133 $table->cellpadding = 5;
134 $table->cellspacing = 0;
135 $table->width = '500';
70f52c70 136
3319ef85 137 $table->data[] = array("<strong>{$databasestr}</strong>", "<em><strong>{$CFG->prefix}".SEARCH_DATABASE_TABLE.'</strong></em>');
70f52c70 138
3319ef85 139/// add extra fields if we're admin
140
4f0c2d00 141 if (has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM))) {
3319ef85 142 //don't want to confuse users if the two totals don't match (hint: they should)
143 $table->data[] = array($documentsinindexstr, $indexinfo->indexcount);
70f52c70 144
3319ef85 145 //*cough* they should match if deletions were actually removed from the index,
146 //as it turns out, they're only marked as deleted and not returned in search results
147 $table->data[] = array($deletionsinindexstr, (int)$indexinfo->indexcount - (int)$indexinfo->dbcount);
70f52c70 148 }
149
3319ef85 150 $table->data[] = array($documentsindatabasestr, $indexinfo->dbcount);
70f52c70 151
63c13a82 152 foreach($indexinfo->types as $type) {
153 if ($type->type == 'mod'){
154 $table->data[] = array(get_string('documentsfor', 'search') . " '".get_string('modulenameplural', $type->name)."'", $type->records);
155 } else if ($type->type == 'block') {
150135ab 156 $table->data[] = array(get_string('documentsfor', 'search') . " '".get_string('pluginname', $type->name)."'", $type->records);
63c13a82 157 } else {
158 $table->data[] = array(get_string('documentsfor', 'search') . " '".get_string($type->name)."'", $type->records);
159 }
70f52c70 160
161 }
162
f7a1496e 163 echo $OUTPUT->heading($databasestatestr);
16be8974 164 echo html_writer::table($table);
70f52c70 165
166 echo $OUTPUT->box_end();
167 echo $OUTPUT->box_end();
daa2cd33 168 echo $OUTPUT->footer();
08822fd6 169?>