source: contrib/Dms/op/op.Search.php @ 3526

Revision 3526, 5.5 KB checked in by afernandes, 13 years ago (diff)

Ticket #1416 - Disponibilizado modulos Timesheet e DMS para a comunidade.

  • Property svn:executable set to *
Line 
1<?php
2include("../inc/inc.Settings.php");
3include("../inc/inc.AccessUtils.php");
4include("../inc/inc.ClassAccess.php");
5include("../inc/inc.ClassDocument.php");
6include("../inc/inc.ClassFolder.php");
7include("../inc/inc.ClassGroup.php");
8include("../inc/inc.ClassUser.php");
9include("../inc/inc.DBAccess.php");
10include("../inc/inc.Language.php");
11include("../inc/inc.OutUtils.php");
12include("../inc/inc.Authentication.php");
13
14$query                  = $_GET['query'];
15$mode                   = $_GET['mode'];
16$searchin               = $_GET['searchin'];
17$ownerid                = $_GET['ownerid'];
18$creationdate           = $_GET['creationdate'];
19$lastupdate             = $_GET['lastupdate'];
20$createstartmonth       = $_GET['createstartmonth'];
21$createstartday         = $_GET['createstartday'];
22$createstartyear        = $_GET['createstartyear'];
23$createendmonth         = $_GET['createendmonth'];
24$createendday           = $_GET['createendday'];
25$createendyear          = $_GET['createendyear'];
26$updatestartmonth       = $_GET['updatestartmonth'];
27$updatestartday         = $_GET['updatestartday'];
28$updatestartyear        = $_GET['updatestartyear'];
29$updateendmonth         = $_GET['updateendmonth'];
30$updateendday           = $_GET['updateendday'];
31$updateendyear          = $_GET['updateendyear'];
32
33$query = sanitizeString($query);
34$mode  = sanitizeString($mode);
35
36$targetid = isset($targetid) ? $targetid : $settings->_rootFolderID;
37$startFolder = getFolder($targetid);
38
39
40function getTime() {
41        if (function_exists('microtime')) {
42                $tm = microtime();
43                $tm = explode(' ', $tm);
44                return (float) sprintf('%f', $tm[1] + $tm[0]);
45        }
46        return time();
47}
48
49function markQuery($str, $tag = "b") {
50        GLOBAL $query;
51       
52        $querywords = split(" ", $query);
53       
54        foreach ($querywords as $queryword)
55                $str = eregi_replace("($queryword)", "<" . $tag . ">\\1</" . $tag . ">", $str);
56       
57        return $str;
58}
59
60function matches($document) {
61        GLOBAL $query, $mode, $searchin, $ownerid,  $creationdate, $lastupdate;
62        GLOBAL $createstartmonth, $createstartday, $createstartyear;
63        GLOBAL $createendmonth, $createendday, $createendyear;
64        GLOBAL $updatestartmonth, $updatestartday, $updatestartyear;
65        GLOBAL $updateendmonth, $updateendday, $updateendyear;
66       
67        if ($ownerid != -1) {
68                if ($ownerid != $document->_ownerID)
69                        return false;
70        }
71       
72        if ($creationdate == "true") {
73                $startdate = mktime(0,0,0, $createstartmonth, $createstartday, $createstartyear);
74                $stopdate  = mktime(23,59,59, $createendmonth, $createendday, $createendyear);
75                $date      = $document->getDate();
76               
77                if (($date < $startdate ) || ($date > $stopdate))
78                        return false;
79        }
80       
81        if ($lastupdate == "true") {
82                $startdate = mktime(0,0,0, $updatestartmonth, $updatestartday, $updatestartyear);
83                $stopdate  = mktime(23,59,59, $updateendmonth, $updateendday, $updateendyear);
84                $latestContent = $document->getLatestContent();
85                $date = $latestContent->getDate();
86               
87                if (($date < $startdate) || ($date > $stopdate))
88                        return false;
89        }
90       
91        $str = "";
92        if (in_array("keywords", $searchin))
93                $str .= $document->getKeywords() . " ";
94        if (in_array("name", $searchin))
95                $str .= $document->getName() . " ";
96        if (in_array("comment", $searchin))
97                $str .= $document->getComment();
98       
99        $querywords = split(" ", strtolower($query));
100        $keywords = split(" ", strtolower($str));
101       
102        $hitsCount = 0;
103        foreach ($querywords as $queryword) {
104                $found = false;
105               
106                foreach ($keywords as $keyword) {
107                        if ((substr_count($keyword, $queryword) > 0) || ($queryword == "%")) {
108                                $found = true;
109                                if ($mode == "or")
110                                        return true;
111                        }
112                }
113                if ($mode == "and" && !$found)
114                        return false;
115        }
116        if ($mode == "and")
117                return true;
118        else
119                return false;
120}
121
122
123function searchInFolder($folder) {
124        GLOBAl $results, $user;
125       
126        $documents = $folder->getDocuments();
127        $documents = filterAccess($documents, $user, M_READ);
128        $subFolders = $folder->getSubFolders();
129        $subFolders = filterAccess($subFolders, $user, M_READ);
130       
131        foreach ($documents as $document) {
132                if (matches($document))
133                        array_push($results, $document);
134        }
135        foreach ($subFolders as $subFolder)
136                searchInFolder($subFolder);
137}
138
139// ------------------------------------- Suche starten --------------------------------------------
140
141$startTime = getTime();
142$results = array();
143searchInFolder($startFolder);
144$searchTime = getTime() - $startTime;
145$searchTime = round($searchTime, 2);
146
147// ---------------------------------- Ausgabe der Ergebnisse --------------------------------------
148
149printHTMLHead( getMLText("search") );
150printTitleBar($startFolder);
151printCenterStart();
152
153printStartBox(getMLText("search_results"));
154
155?>
156
157<table width="100%">
158        <tr>
159                <td align="left" class="standardText">
160                        <?php
161                                if (count($results) == 0)
162                                        printMLText("search_no_results", array("query" => $query));
163                                else
164                                        printMLText("search_report", array("query" => $query, "count" => count($results)));
165                        ?>
166                </td>
167                <td align="right" class="standardText"><?php printMLText("search_time", array("time" => $searchTime));?></td>
168        </tr>
169</table>
170
171<?php
172if (count($results) == 0)
173{
174        printEndBox();
175        printCenterEnd();
176        printHTMLFoot();
177        exit;
178}
179
180print "<p><ol>";
181
182foreach ($results as $document) {
183        print "<li class=\"standardText\"><b>" . getMLText("name") . ": " . "<a class=\"standardText\" href=\"../out/out.ViewDocument.php?documentid=".$document->getID()."\">" . markQuery($document->getName(), "i") . "</a></b><br>";
184        $folder = $document->getFolder();
185        $path = $folder->getPath();
186        print getMLText("folder_path") . ": ";
187        for ($i = 0; $i  < count($path); $i++)
188        {
189                print $path[$i]->getName();
190                if ($i +1 < count($path))
191                        print " / ";
192        }
193        print "<br>";
194        print markQuery($document->getComment());
195        print "<br>&nbsp;</li>";
196}
197
198print "</ol>";
199
200printEndBox();
201printCenterEnd();
202printHTMLFoot();
203?>
Note: See TracBrowser for help on using the repository browser.