MDL-11515:
[moodle-linuxchix.git] / search / stats.php
blobcd956e0ceed34cb6a9f9596d4e44f08505b8d1c1
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 $navlinks = array();
39 $navlinks[] = array('name' => $strsearch, 'link' => "index.php", 'type' => 'misc');
40 $navlinks[] = array('name' => $strquery, 'link' => null, 'type' => 'misc');
41 $navigation = build_navigation($navlinks);
42 print_header("$site->shortname: $strsearch: $strquery", "$site->fullname", $navigation);
44 //keep things pretty, even if php5 isn't available
45 if (!$check) {
46 print_heading(search_check_php5(true));
47 print_footer();
48 exit(0);
51 print_box_start();
52 print_heading($strquery);
54 print_box_start();
56 $databasestr = get_string('database', 'search');
57 $documentsinindexstr = get_string('documentsinindex', 'search');
58 $deletionsinindexstr = get_string('deletionsinindex', 'search');
59 $documentsindatabasestr = get_string('documentsindatabase', 'search');
60 $databasestatestr = get_string('databasestate', 'search');
62 //this table is only for admins, shows index directory size and location
63 if (isadmin()) {
64 $datadirectorystr = get_string('datadirectory', 'search');
65 $inindexdirectorystr = get_string('filesinindexdirectory', 'search');
66 $totalsizestr = get_string('totalsize', 'search');
67 $errorsstr = get_string('errors', 'search');
68 $solutionsstr = get_string('solutions', 'search');
69 $checkdirstr = get_string('checkdir', 'search');
70 $checkdbstr = get_string('checkdb', 'search');
71 $checkdiradvicestr = get_string('checkdiradvice', 'search');
72 $checkdbadvicestr = get_string('checkdbadvice', 'search');
73 $runindexerteststr = get_string('runindexertest', 'search');
74 $runindexerstr = get_string('runindexer', 'search');
76 $admin_table->tablealign = "center";
77 $admin_table->align = array ("right", "left");
78 $admin_table->wrap = array ("nowrap", "nowrap");
79 $admin_table->cellpadding = 5;
80 $admin_table->cellspacing = 0;
81 $admin_table->width = '500';
83 $admin_table->data[] = array("<strong>{$datadirectorystr}</strong>", '<em><strong>'.$indexinfo->path.'</strong></em>');
84 $admin_table->data[] = array($inindexdirectorystr, $indexinfo->filecount);
85 $admin_table->data[] = array($totalsizestr, $indexinfo->size);
87 if ($indexinfo->time > 0) {
88 $admin_table->data[] = array(get_string('createdon', 'search'), date('r', $indexinfo->time));
90 else {
91 $admin_table->data[] = array(get_string('createdon', 'search'), '-');
94 if (!$indexinfo->valid($errors)) {
95 $admin_table->data[] = array("<strong>{$errorsstr}</strong>", '&nbsp;');
96 foreach ($errors as $key => $value) {
97 $admin_table->data[] = array($key.' ... ', $value);
101 print_table($admin_table);
102 print_spacer(20);
103 print_heading($solutionsstr);
105 unset($admin_table->data);
106 if (isset($errors['dir'])) {
107 $admin_table->data[] = array($checkdirstr, $checkdiradvicestr);
109 if (isset($errors['db'])) {
110 $admin_table->data[] = array($checkdbstr, $checkdbadvicestr);
113 $admin_table->data[] = array($runindexerteststr, '<a href="tests/index.php" target="_blank">tests/index.php</a>');
114 $admin_table->data[] = array($runindexerstr, '<a href="indexersplash.php" target="_blank">indexersplash.php</a>');
116 print_table($admin_table);
117 print_spacer(20);
120 //this is the standard summary table for normal users, shows document counts
121 $table->tablealign = "center";
122 $table->align = array ("right", "left");
123 $table->wrap = array ("nowrap", "nowrap");
124 $table->cellpadding = 5;
125 $table->cellspacing = 0;
126 $table->width = '500';
128 $table->data[] = array("<strong>{$databasestr}</strong>", "<em><strong>{$CFG->prefix}block_search_documents</strong></em>");
130 //add extra fields if we're admin
131 if (isadmin()) {
132 //don't want to confuse users if the two totals don't match (hint: they should)
133 $table->data[] = array($documentsinindexstr, $indexinfo->indexcount);
135 //*cough* they should match if deletions were actually removed from the index,
136 //as it turns out, they're only marked as deleted and not returned in search results
137 $table->data[] = array($deletionsinindexstr, (int)$indexinfo->indexcount - (int)$indexinfo->dbcount);
140 $table->data[] = array($documentsindatabasestr, $indexinfo->dbcount);
142 foreach($indexinfo->types as $key => $value) {
143 $table->data[] = array(get_string('documentsfor', 'search') . " '".get_string('modulenameplural', $key)."'", $value);
146 print_heading($databasestatestr);
147 print_table($table);
149 print_box_end();
150 print_box_end();
151 print_footer();