AC_4897, AC_4898, AC_4899: Multifile uploader fixes.
[acontent.git] / documentation / search.php
1 <?php \r
2 /************************************************************************/\r
3 /* AContent                                                             */\r
4 /************************************************************************/\r
5 /* Copyright (c) 2010                                                   */\r
6 /* Inclusive Design Institute                                           */\r
7 /*                                                                      */\r
8 /* This program is free software. You can redistribute it and/or        */\r
9 /* modify it under the terms of the GNU General Public License          */\r
10 /* as published by the Free Software Foundation.                        */\r
11 /************************************************************************/\r
12 \r
13 define('TR_INCLUDE_PATH', '../include/');\r
14 include(TR_INCLUDE_PATH.'vitals.inc.php');\r
15 include_once(TR_INCLUDE_PATH.'handbook_pages.inc.php');\r
16 include_once(TR_INCLUDE_PATH.'classes/DAO/LanguageTextDAO.class.php');\r
17 \r
18 ?>\r
19 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict //EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\r
20 <html lang="<?php if ($missing_lang) { echo DEFAULT_LANGUAGE_CODE; } else { echo $req_lang; } ?>">\r
21 <head>\r
22         <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />\r
23         <title><?php echo _AT('Transformable_documentation'); ?></title>\r
24         <base target="body" />\r
25 <style>\r
26 body { font-family: Verdana,Arial,sans-serif; font-size: x-small; margin: 0px; padding: 0px; background: #fafafa; margin-left: -5px; }\r
27 ul, ol { list-style: none; padding-left: 0px; margin-left: -15px; }\r
28 li { margin-left: 19pt; padding-top: 2px; }\r
29 a { background-repeat: no-repeat; background-position: 0px 1px; padding-left: 12px; text-decoration: none; }\r
30 a.tree { background-image: url('../images/folder.gif'); }\r
31 a.leaf { background-image: url('../images/paper.gif'); }\r
32 a:link, a:visited { color: #006699; }\r
33 a:hover { color: #66AECC; }\r
34 </style>\r
35 </head>\r
36 <body>\r
37 <?php\r
38 echo '<a href="frame_toc.php" target="_self">';\r
39 echo _AT('back_to_contents');\r
40 echo '</a>';\r
41 \r
42 if ($_GET['query']) {\r
43         $_GET['query'] = str_replace(',', ' ', $_GET['query']);\r
44         $_GET['query'] = str_replace('"', '', $_GET['query']);\r
45 \r
46         if (strlen($_GET['query']) > 3) {\r
47                 $_GET['query'] = strtolower($_GET['query']);\r
48 \r
49                 $search_terms = explode(' ', $_GET['query']);\r
50 \r
51                 $results = array();\r
52 \r
53                 $languageTextDAO = new LanguageTextDAO();\r
54                 \r
55                 $final_match_rows = array();\r
56                 foreach ($search_terms as $term)\r
57                 {\r
58                         $match_rows = $languageTextDAO->getHelpByMatchingText($addslashes($term), $_SESSION['lang']);\r
59 \r
60                         if (is_array($match_rows)) $final_match_rows = array_merge($final_match_rows, $match_rows);\r
61                 }\r
62 \r
63                 if (is_array($final_match_rows)) \r
64                 {\r
65                         foreach ($final_match_rows as $match) \r
66                         {\r
67                                 if (is_array($result)) \r
68                                         $all_match_terms = array_keys($result);\r
69                                 else \r
70                                         $all_match_terms = array(); \r
71 \r
72                                 if (!in_array($match['term'], $all_match_terms))\r
73                                 { \r
74                                         $count = 0;\r
75         \r
76                                         $contents = strtolower($match['text']);\r
77         \r
78                                         foreach ($search_terms as $term) \r
79                                         {\r
80                                                 $term = trim($term);\r
81                                                 if ($term) {\r
82                                                         $count += substr_count($contents, $term);\r
83                                                 }\r
84                                         }\r
85         \r
86                                         if ($count) \r
87                                         {\r
88                                                 $results[$match['term']] = $count;\r
89                                         }\r
90                                 }\r
91                         }\r
92                 }\r
93 \r
94                 // replace term in match array with script name\r
95                 if ($results) \r
96                 {\r
97                         arsort($results);\r
98                         \r
99                         echo '<ol>';\r
100                         foreach ($results as $term => $count) \r
101                         {\r
102                                 foreach ($_pages as $this_page => $page_def)\r
103                                 {\r
104                                         if (strcmp($page_def['guide'], $term) == 0)\r
105                                                 echo '<li><a href="frame_content.php?p='.$this_page.'" class="leaf" target="body">'._AT($page_def['title_var']).'</a></li>';\r
106                                 }\r
107 \r
108                         }\r
109                         echo '</ol>';\r
110                 } else {\r
111                         echo '<p style="padding: 8px;">';\r
112                         echo _AT('no_results_found');\r
113                         echo '</p>';\r
114                 }\r
115         } else {\r
116                 echo '<p style="padding: 8px;">';\r
117                 echo _AT('search_term_longer_3_chars');\r
118                 echo '</p>';\r
119         }\r
120 }\r
121 ?>\r
122 </body>\r
123 </html>\r