Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
fullsearchresult.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @package FDL
5 */
6 /**
7  * Full Text Search document
8  *
9  * @author Anakeen
10  * @version $Id: fullsearch.php,v 1.10 2008/01/04 17:56:37 eric Exp $
11  * @package FDL
12  * @subpackage GED
13  */
14 /**
15  */
16 
17 include_once ("FDL/Class.SearchDoc.php");
18 include_once ("FDL/Class.DocSearch.php");
19 
20 include_once ("FDL/freedom_util.php");
21 /**
22  * Fulltext Search document
23  * @param Action &$action current action
24  * @global string $keyword Http var : word to search in any values
25  * @global string $famid Http var : restrict to this family identioficator
26  * @global string $start Http var : page number
27  * @global string $dirid Http var : search identifier
28  */
30 {
31  $famid = $action->getArgument("famid", 0);
32  $keyword = $action->getArgument("_se_key", $action->getArgument("keyword")); // keyword to search
33  $page = $action->getArgument("page", 0); // page number
34  $dirid = $action->getArgument("dirid", 0); // special search
35  $slice = 10;
36  $start = $page * $slice;
37 
38  $action->lay->rSet("isdetail", false);
39  $action->lay->rSet("page", (int)($page + 1));
40  $action->lay->rSet("dirid", json_encode($dirid));
41  $action->lay->rSet("SUBSEARCH", ($start > 0));
42  $initpage = false;
43  $action->parent->AddJsRef($action->GetParam("CORE_JSURL") . "/resizeimg.js");
44 
45  $dbaccess = $action->dbaccess;
46  if (!is_numeric($famid)) $famid = getFamIdFromName($dbaccess, $famid);
47  $famtitle = "";
48  $globalCount = 0;
49  $nosearch = false;
50  if (($keyword == "") && ($dirid == 0) && ($famid == 0)) {
51  if ($initpage) {
52  $action->lay = new Layout(getLayoutFile("FGSEARCH", "fullsearch_empty.xml") , $action);
53  return;
54  }
55  $nosearch = true;
56  }
57  $action->lay->rSet("INITSEARCH", $nosearch);
58  $kfams = array();
59 
60  if ($keyword != "") {
61  // process family specification
62  $kl = explode(":", $keyword);
63  if (count($kl) > 1) {
64  $keyword = $kl[1];
65  $faml = $kl[0];
66  $tf = explode(",", $faml);
67  foreach ($tf as $k => $v) {
68  if ($v == "") continue;
69  $v = trim($v);
70  if ($v[0] != "~") {
71  $b = true;
72  $n = $v;
73  } else {
74  $b = false;
75  $n = substr($v, 1);
76  }
77  $kfams[] = array(
78  "include" => $b,
79  "kfam" => $n
80  );
81  }
82  }
83  }
84 
85  $searchMode = $action->getParam("FGSEARCH_SEARCHMODE", "words");
86  /* $bfam = array(); */
87  $tclassdoc = getNonSystemFamilies($dbaccess, $action->user->id, "TABLE");
88  if (!$nosearch) {
89 
90  $sqlfilters = array();
91  $famfilter = $or = $and = "";
92  if (count($kfams) > 0) {
93  $famid = 0;
94 
95  foreach ($kfams as $k => $v) {
96  foreach ($tclassdoc as $kdoc => $cdoc) {
97  if (strstr(strtolower($cdoc["title"]) , $v["kfam"]) != false) {
98  if ($v["include"]) $or.= ($or != "" ? " OR " : "") . "(fromid" . ($v["include"] ? "=" : "!=") . $cdoc["initid"] . ")";
99  else $and.= ($and != "" ? " AND " : "") . "(fromid" . ($v["include"] ? "=" : "!=") . $cdoc["initid"] . ")";
100  }
101  }
102  }
103  if ($or != "") $famfilter = "($or)";
104  if ($and != "") $famfilter.= ($famfilter != "" ? " AND " : "") . " ($and)";
105  }
106  $keys = $vardids = $displayedIds = '';
107 
108  $s = new SearchDoc($dbaccess, $famid);
109 
110  try {
111  $s->addFilter("usefor !~ '^S'");
112  $s->setObjectReturn();
113  if ($keyword != "") {
114 
115  $s->addGeneralFilter($keyword, true, $searchMode === "characters");
116  $s->setPertinenceOrder();
117  } else {
118  $sdoc = new_doc($dbaccess, $dirid);
119  $tkeys = $sdoc->getMultipleRawValues("se_keys");
120  foreach ($tkeys as $k => $v) if (!$v) unset($tkeys[$k]);
121  $keys = implode('|', $tkeys);
122  }
123  if ($famfilter != "") $sqlfilters[] = $famfilter;
124 
125  if ($dirid) {
126  $s->useCollection($dirid);
127  $vardids = "did_$dirid";
128  } else {
129  $vardids = "did_$famid$keys";
130  foreach ($sqlfilters as $filter) {
131  $s->addFilter($filter);
132  }
133  }
134  $displayedIds = array();
135  if ($start > 0) {
136  $displayedIds = $action->read($vardids);
137  if ($displayedIds && count($displayedIds) > 0) {
138  $sqlExclude = sprintf("initid not in (%s)", implode(",", $displayedIds));
139  $s->addFilter($sqlExclude);
140  } else {
141  $s->setStart($start);
142  }
143  }
144  $s->setSlice($slice + 1);
145  $s->excludeConfidential();
146  $s->search();
147  if ($s->getError()) {
148  addLogMsg($s->getSearchInfo());
149  $action->exitError($s->getError());
150  }
151  }
152  catch(Exception $e) {
153  $action->exitError(sprintf(_("Incorrect filter %s") , $keyword));
154  }
155 
156  if ($start == 0) {
157  if ($s->count() < ($slice + 1)) $globalCount = $s->count();
158  else {
159  $sc = new SearchDoc($dbaccess, $famid);
160  if ($keyword) $sc->addGeneralFilter($keyword, true, $searchMode === "characters");
161  if ($dirid) {
162  $sc->useCollection($dirid);
163  } else {
164  foreach ($sqlfilters as $filter) $sc->addFilter($filter);
165  }
166  $sc->addFilter("usefor !~ '^S'");
167  $sc->excludeConfidential();
168  $globalCount = $sc->onlyCount();
169  }
170  }
171 
172  $workdoc = new Doc($dbaccess);
173  if ($famid) $famtitle = $workdoc->getTitle($famid);
174 
175  if ($s->count() == ($slice + 1)) {
176  $action->lay->rSet("notthenend", true);
177 
178  $notTheEnd = true;
179  } else {
180  $action->lay->rSet("notthenend", false);
181  $notTheEnd = false;
182  }
183 
184  $action->lay->rSet("notfirst", ($start != 0));
185  $action->lay->eSet("theFollowingText", _("View next results"));
186  $c = 0;
187 
188  $k = 0;
189  $tdocs = array();
190  while ($doc = $s->getNextDoc()) {
191 
192  if ($doc->confidential) {
193  if (($doc->profid > 0) && ($workdoc->controlId($doc->profid, "confidential") != "")) {
194  continue;
195  }
196  }
197  $displayedIds[] = $doc->initid;
198  $c++;
199  $tdocs[$k]["number"] = htmlspecialchars($c + $start, ENT_QUOTES);
200  $tdocs[$k]["title"] = $doc->getHTMLTitle();
201  $tdocs[$k]["id"] = $doc->id;
202  /* Escape elements of highlight string */
203  $highlight = $s->getHighLightText($doc, '<strong>', '</strong>', $action->GetParam("FULLTEXT_HIGHTLIGHTSIZE", 200) , $searchMode === "words");
204  $tokens = preg_split('!(</?strong>)!', $highlight, -1, PREG_SPLIT_DELIM_CAPTURE);
205  foreach ($tokens as & $token) {
206  if ($token == '<strong>' || $token == '</strong>') {
207  continue;
208  }
209  $token = htmlspecialchars($token, ENT_QUOTES);
210  }
211  $tdocs[$k]["htext"] = str_replace('[', '&#1B;', nl2br(join('', $tokens)));
212  $tdocs[$k]["iconsrc"] = $doc->getIcon('', 20);
213  $tdocs[$k]["mdate"] = strftime("%a %d %b %Y", $doc->revdate);
214  $k++;
215  }
216 
217  if ($notTheEnd) {
218  array_pop($tdocs);
219  array_pop($displayedIds);
220  }
221  $action->register($vardids, $displayedIds);
222  $tpages = array();
223  if ($start > 0) {
224  for ($i = 0; $i < $start; $i+= $slice) {
225  $tpages[] = array(
226  "xpage" => $i / $slice + 1,
227  "xstart" => $i
228  );
229  }
230 
231  $action->lay->eSetBlockData("PAGES", $tpages);
232  }
233 
234  $action->lay->setBlockData("DOCS", $tdocs);
235 
236  $action->lay->eset("dirid", $dirid);
237  if ($dirid != 0) {
238  $sdoc = new_doc($dbaccess, $dirid);
239  if ($sdoc->isAffected()) {
240  $action->lay->rSet("isdetail", false);
241  $action->lay->eSet("searchtitle", $sdoc->title);
242  $action->lay->rSet("dirid", $sdoc->id);
243  }
244  }
245  } else {
246  $action->lay->rSet("cpage", "0");
247  $action->lay->rSet("notfirst", false);
248  $action->lay->rSet("notthenend", false);
249  }
250 
251  $famsuffix = ($famid == 0 ? "" : sprintf("<span class=\"families\">(%s %s)</span>", _("family search result") , $famtitle));
252  if ($globalCount == 0) {
253  $action->lay->rSet("resulttext", sprintf(_("No document found for <strong>%s</strong>%s") , htmlspecialchars($keyword) , $famsuffix));
254  } else if ($globalCount == 1) {
255  $action->lay->rSet("resulttext", sprintf(_("One document for <strong>%s</strong>%s") , htmlspecialchars($keyword) , $famsuffix));
256  } else {
257  $action->lay->rSet("resulttext", sprintf(_("Found <strong>%d</strong> Result for <strong>%s</strong>%s") , $globalCount, htmlspecialchars($keyword) , $famsuffix));
258  }
259  $action->lay->rSet("displayBottomBar", ($globalCount == 0 ? false : true));
260  $action->lay->rSet("displayTopBar", ($page == 0));
261 
262  $action->lay->eSet("searchdate", Doc::getDate(0, 0, 0, true));
263 }
264 
265 function strtr8($s, $c1, $c2)
266 {
267  $s9 = utf8_decode($s);
268  $s9 = strtr($s9, utf8_decode($c1) , utf8_decode($c2));
269  return utf8_encode($s9);
270 }
Layout is a template generator.
global $action
if($dbaccess=="") if($statusFile=== '') $famtitle
static getDate($daydelta=0, $dayhour="", $daymin="", $getlocale=false)
Definition: Class.Doc.php:8783
getNonSystemFamilies($dbaccess, $userid, $qtype="TABLE")
Definition: Lib.Dir.php:952
fullsearchresult(Action &$action)
if($famId) $s
strtr8($s, $c1, $c2)
exitError($texterr, $exit=true, $code="")
getLayoutFile($app, $layfile)
Definition: Lib.Common.php:258
getFamIdFromName($dbaccess, $name)
getParam($name, $def="")
$keyword
static getArgument($k, $def= '')
$dbaccess
Definition: checkVault.php:17
← centre documentaire © anakeen