Updated the 19 build version to 20081217
[moodle.git] / search / stats.php
blob8412241ef2787618006159ce98fffd27efb47a95
1 <?php
2 /**
3 * Global Search Engine for Moodle
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
10 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
12 * Prints some basic statistics about the current index.
13 * Does some diagnostics if you are logged in as an administrator.
17 /**
18 * includes and requires
20 require_once('../config.php');
21 require_once("{$CFG->dirroot}/search/lib.php");
23 /// checks global search is enabled
25 if ($CFG->forcelogin) {
26 require_login();
29 if (empty($CFG->enableglobalsearch)) {
30 error(get_string('globalsearchdisabled', 'search'));
33 /// check for php5, but don't die yet
35 if ($check = search_check_php5()) {
36 require_once("{$CFG->dirroot}/search/indexlib.php");
38 $indexinfo = new IndexInfo();
41 if (!$site = get_site()) {
42 redirect("index.php");
45 $strsearch = get_string('search', 'search');
46 $strquery = get_string('statistics', 'search');
48 if (!function_exists('build_navigation')){
49 print_header("$site->shortname: $strsearch: $strquery", "$site->fullname",
50 "<a href=\"index.php\">$strsearch</a> -> $strquery");
51 } else {
52 $navlinks[] = array('name' => $strsearch, 'link' => "index.php", 'type' => 'misc');
53 $navlinks[] = array('name' => $strquery, 'link' => null, 'type' => 'misc');
54 $navigation = build_navigation($navlinks);
55 $site = get_site();
56 print_header("$strsearch", "$site->fullname" , $navigation, "", "", true, "&nbsp;", navmenu($site));
59 /// keep things pretty, even if php5 isn't available
61 if (!$check) {
62 print_heading(search_check_php5(true));
63 print_footer();
64 exit(0);
67 print_box_start();
68 print_heading($strquery);
70 print_box_start();
72 $databasestr = get_string('database', 'search');
73 $documentsinindexstr = get_string('documentsinindex', 'search');
74 $deletionsinindexstr = get_string('deletionsinindex', 'search');
75 $documentsindatabasestr = get_string('documentsindatabase', 'search');
76 $databasestatestr = get_string('databasestate', 'search');
78 /// this table is only for admins, shows index directory size and location
80 if (isadmin()) {
81 $datadirectorystr = get_string('datadirectory', 'search');
82 $inindexdirectorystr = get_string('filesinindexdirectory', 'search');
83 $totalsizestr = get_string('totalsize', 'search');
84 $errorsstr = get_string('errors', 'search');
85 $solutionsstr = get_string('solutions', 'search');
86 $checkdirstr = get_string('checkdir', 'search');
87 $checkdbstr = get_string('checkdb', 'search');
88 $checkdiradvicestr = get_string('checkdiradvice', 'search');
89 $checkdbadvicestr = get_string('checkdbadvice', 'search');
90 $runindexerteststr = get_string('runindexertest', 'search');
91 $runindexerstr = get_string('runindexer', 'search');
93 $admin_table->tablealign = "center";
94 $admin_table->align = array ("right", "left");
95 $admin_table->wrap = array ("nowrap", "nowrap");
96 $admin_table->cellpadding = 5;
97 $admin_table->cellspacing = 0;
98 $admin_table->width = '500';
100 $admin_table->data[] = array("<strong>{$datadirectorystr}</strong>", '<em><strong>'.$indexinfo->path.'</strong></em>');
101 $admin_table->data[] = array($inindexdirectorystr, $indexinfo->filecount);
102 $admin_table->data[] = array($totalsizestr, $indexinfo->size);
104 if ($indexinfo->time > 0) {
105 $admin_table->data[] = array(get_string('createdon', 'search'), date('r', $indexinfo->time));
107 else {
108 $admin_table->data[] = array(get_string('createdon', 'search'), '-');
111 if (!$indexinfo->valid($errors)) {
112 $admin_table->data[] = array("<strong>{$errorsstr}</strong>", '&nbsp;');
113 foreach ($errors as $key => $value) {
114 $admin_table->data[] = array($key.' ... ', $value);
118 print_table($admin_table);
119 print_spacer(20);
120 print_heading($solutionsstr);
122 unset($admin_table->data);
123 if (isset($errors['dir'])) {
124 $admin_table->data[] = array($checkdirstr, $checkdiradvicestr);
126 if (isset($errors['db'])) {
127 $admin_table->data[] = array($checkdbstr, $checkdbadvicestr);
130 $admin_table->data[] = array($runindexerteststr, '<a href="tests/index.php" target="_blank">tests/index.php</a>');
131 $admin_table->data[] = array($runindexerstr, '<a href="indexersplash.php" target="_blank">indexersplash.php</a>');
133 print_table($admin_table);
134 print_spacer(20);
137 /// this is the standard summary table for normal users, shows document counts
139 $table->tablealign = "center";
140 $table->align = array ("right", "left");
141 $table->wrap = array ("nowrap", "nowrap");
142 $table->cellpadding = 5;
143 $table->cellspacing = 0;
144 $table->width = '500';
146 $table->data[] = array("<strong>{$databasestr}</strong>", "<em><strong>{$CFG->prefix}".SEARCH_DATABASE_TABLE.'</strong></em>');
148 /// add extra fields if we're admin
150 if (isadmin()) {
151 //don't want to confuse users if the two totals don't match (hint: they should)
152 $table->data[] = array($documentsinindexstr, $indexinfo->indexcount);
154 //*cough* they should match if deletions were actually removed from the index,
155 //as it turns out, they're only marked as deleted and not returned in search results
156 $table->data[] = array($deletionsinindexstr, (int)$indexinfo->indexcount - (int)$indexinfo->dbcount);
159 $table->data[] = array($documentsindatabasestr, $indexinfo->dbcount);
161 foreach($indexinfo->types as $key => $value) {
162 $table->data[] = array(get_string('documentsfor', 'search') . " '".get_string('modulenameplural', $key)."'", $value);
165 print_heading($databasestatestr);
166 print_table($table);
168 print_box_end();
169 print_box_end();
170 print_footer();