Should be $COURSE not $course
[moodle-linuxchix.git] / search / stats.php
blob412205595b6832d76269e2c5b6f93ca88ebf8368
1 <?php
2 /**
3 * Global Search Engine for Moodle
4 * Michael Champanis (mchampan) [cynnical@gmail.com]
5 * review 1.8+ : Valery Fremaux [valery.fremaux@club-internet.fr]
6 * 2007/08/02
8 * Prints some basic statistics about the current index.
9 * Does some diagnostics if you are logged in as an administrator.
13 require_once('../config.php');
14 require_once("{$CFG->dirroot}/search/lib.php");
16 if ($CFG->forcelogin) {
17 require_login();
20 if (empty($CFG->enableglobalsearch)) {
21 error(get_string('globalsearchdisabled', 'search'));
24 //check for php5, but don't die yet
25 if ($check = search_check_php5()) {
26 require_once("{$CFG->dirroot}/search/indexlib.php");
28 $indexinfo = new IndexInfo();
31 if (!$site = get_site()) {
32 redirect("index.php");
35 $strsearch = get_string('search', 'search');
36 $strquery = get_string('statistics', 'search');
38 print_header("$site->shortname: $strsearch: $strquery", "$site->fullname",
39 "<a href=\"index.php\">$strsearch</a> -> $strquery");
41 //keep things pretty, even if php5 isn't available
42 if (!$check) {
43 print_heading(search_check_php5(true));
44 print_footer();
45 exit(0);
48 print_box_start();
49 print_heading($strquery);
51 print_box_start();
53 $databasestr = get_string('database', 'search');
54 $documentsinindexstr = get_string('documentsinindex', 'search');
55 $deletionsinindexstr = get_string('deletionsinindex', 'search');
56 $documentsindatabasestr = get_string('documentsindatabase', 'search');
57 $databasestatestr = get_string('databasestate', 'search');
59 //this table is only for admins, shows index directory size and location
60 if (isadmin()) {
61 $datadirectorystr = get_string('datadirectory', 'search');
62 $inindexdirectorystr = get_string('filesinindexdirectory', 'search');
63 $totalsizestr = get_string('totalsize', 'search');
64 $errorsstr = get_string('errors', 'search');
65 $solutionsstr = get_string('solutions', 'search');
66 $checkdirstr = get_string('checkdir', 'search');
67 $checkdbstr = get_string('checkdb', 'search');
68 $checkdiradvicestr = get_string('checkdiradvice', 'search');
69 $checkdbadvicestr = get_string('checkdbadvice', 'search');
70 $runindexerteststr = get_string('runindexertest', 'search');
71 $runindexerstr = get_string('runindexer', 'search');
73 $admin_table->tablealign = "center";
74 $admin_table->align = array ("right", "left");
75 $admin_table->wrap = array ("nowrap", "nowrap");
76 $admin_table->cellpadding = 5;
77 $admin_table->cellspacing = 0;
78 $admin_table->width = '500';
80 $admin_table->data[] = array("<strong>{$datadirectorystr}</strong>", '<em><strong>'.$indexinfo->path.'</strong></em>');
81 $admin_table->data[] = array($inindexdirectorystr, $indexinfo->filecount);
82 $admin_table->data[] = array($totalsizestr, $indexinfo->size);
84 if ($indexinfo->time > 0) {
85 $admin_table->data[] = array(get_string('createdon', 'search'), date('r', $indexinfo->time));
87 else {
88 $admin_table->data[] = array(get_string('createdon', 'search'), '-');
91 if (!$indexinfo->valid($errors)) {
92 $admin_table->data[] = array("<strong>{$errorsstr}</strong>", '&nbsp;');
93 foreach ($errors as $key => $value) {
94 $admin_table->data[] = array($key.' ... ', $value);
98 print_table($admin_table);
99 print_spacer(20);
100 print_heading($solutionsstr);
102 unset($admin_table->data);
103 if (isset($errors['dir'])) {
104 $admin_table->data[] = array($checkdirstr, $checkdiradvicestr);
106 if (isset($errors['db'])) {
107 $admin_table->data[] = array($checkdbstr, $checkdbadvicestr);
110 $admin_table->data[] = array($runindexerteststr, '<a href="tests/index.php" target="_blank">tests/index.php</a>');
111 $admin_table->data[] = array($runindexerstr, '<a href="indexersplash.php" target="_blank">indexersplash.php</a>');
113 print_table($admin_table);
114 print_spacer(20);
117 //this is the standard summary table for normal users, shows document counts
118 $table->tablealign = "center";
119 $table->align = array ("right", "left");
120 $table->wrap = array ("nowrap", "nowrap");
121 $table->cellpadding = 5;
122 $table->cellspacing = 0;
123 $table->width = '500';
125 $table->data[] = array("<strong>{$databasestr}</strong>", "<em><strong>{$CFG->prefix}block_search_documents</strong></em>");
127 //add extra fields if we're admin
128 if (isadmin()) {
129 //don't want to confuse users if the two totals don't match (hint: they should)
130 $table->data[] = array($documentsinindexstr, $indexinfo->indexcount);
132 //*cough* they should match if deletions were actually removed from the index,
133 //as it turns out, they're only marked as deleted and not returned in search results
134 $table->data[] = array($deletionsinindexstr, (int)$indexinfo->indexcount - (int)$indexinfo->dbcount);
137 $table->data[] = array($documentsindatabasestr, $indexinfo->dbcount);
139 foreach($indexinfo->types as $key => $value) {
140 $table->data[] = array(get_string('documentsfor', 'search') . " '".get_string('modulenameplural', $key)."'", $value);
143 print_heading($databasestatestr);
144 print_table($table);
146 print_box_end();
147 print_box_end();
148 print_footer();