18 include_once (
"FDL/Class.PDocSearch.php");
19 include_once (
"FDL/Lib.Dir.php");
28 "and" =>
"and", #
N_(
"and")
43 if (((!isset($this->fromid))) || ($this->fromid ==
"")) $this->fromid =
FAM_SEARCH;
53 $this->setValue(
"se_static",
"1");
54 $err = $this->addQuery($tquery);
61 if (is_array($tquery))
$query = implode(
";\n", $tquery);
64 if (
$query ==
"")
return "";
65 if ($this->
id ==
"")
return "";
67 if (substr(
$query, 0, 6) !=
"select") {
69 return sprintf(_(
"query [%s] not valid for select document") ,
$query);
71 $oqd =
new QueryDir($this->dbaccess);
76 if ($this->
id > 0) $this->
exec_query(
"delete from fld where dirid=" . intval($this->
id) .
" and qtype='M'");
79 $this->setValue(
"SE_SQLSELECT",
$query);
92 return _(
"containt of searches cannot be modified");
105 $query->AddQuery(
"dirid=" . $this->
id);
106 $query->AddQuery(
"qtype != 'S'");
107 $tq =
$query->Query(0, 0,
"TABLE");
110 return $tq[0][
"query"];
141 if (count(
$acls) > 0) {
143 foreach (
$acls as $acl) {
144 $dacl = $this->dacls[$acl];
146 $posacl = $dacl[
"pos"];
147 $filters[] =
"hasdocprivilege(" . $this->userid .
",profid," . (1 << intval($posacl)) .
")";
153 $filters[] =
"locked = -1";
154 $filters[] =
"lmodify = 'L'";
155 }
else if (
$latest ==
"allfixed") {
156 $filters[] =
"locked = -1";
159 $filters[] =
"locked = -1";
162 if ($this->
getValue(
"se_archive") > 0) {
163 $filters[] = sprintf(
"archiveid = %d", $this->
getValue(
"se_archive"));
174 $filters = array_merge($filters, $sqlfilters);
175 $this->setValue(
"se_orderby", $order);
182 if (strtolower(substr(
$keyword, 0, 5)) ==
"::get") {
185 $filters[] =
"svalues $op '$keyword' ";
190 foreach ($tkey as $k => $v) {
192 if ($v[strlen($v) - 1] ==
'"') {
194 $ckey.=
" " . substr($v, 0, -1);
195 $filters[] =
"svalues $op '$ckey' ";
199 }
else if ($v[0] ==
'"') {
200 if ($v[strlen($v) - 1] ==
'"') {
201 $ckey = substr($v, 1, -1);
202 $filters[] =
"svalues $op '$ckey' ";
205 $ckey = substr($v, 1);
208 $filters[] =
"svalues $op '$v' ";
212 $this->setValue(
"se_orderby",
" ");
231 $pspell_link =
false;
232 if (function_exists(
'pspell_new')) {
233 $pspell_link = pspell_new(
"fr",
"",
"",
"utf-8", PSPELL_FAST);
236 $sqlfilters = array();
237 if (count($tstatickeys) > 2) {
240 foreach ($tstatickeys as $k => $v) {
244 $keyword.=
" (\"" . str_replace(
" ",
"&", trim($v)) .
"\")";
253 $sqlfiltersbrut = array();
254 foreach ($tkeys as $k => $key) {
257 $tsearchkeys[$k] = $key;
258 if ($pspell_link !==
false) {
259 if ((!is_numeric($key)) && (strstr($key,
'|') ===
false) && (strstr($key,
'&') ===
false) && (ord($key[0]) > 47) && (!pspell_check($pspell_link, $key))) {
260 $suggestions = pspell_suggest($pspell_link, $key);
261 $sug = $suggestions[0];
263 if ($sug && (
unaccent($sug) != $key) && (!strstr($sug,
' '))) $tsearchkeys[$k] =
"$key|$sug";
266 if (strstr($key,
'"') !==
false) {
268 if (strstr($key,
'|') ===
false) {
269 $sqlfiltersbrut[] =
"svalues ~* '\\\\y" . pg_escape_string(str_replace(array(
279 ) , $key)) .
"\\\\y' ";
281 list($left, $right) = explode(
"|", $key);
282 if (strstr($left,
'"') !==
false) $q1 =
"svalues ~* '\\\\y" . pg_escape_string(str_replace(array(
292 ) , $left)) .
"\\\\y' ";
294 if (strstr($right,
'"') !==
false) $q2 =
"svalues ~* '\\\\y" . pg_escape_string(str_replace(array(
304 ) , $right)) .
"\\\\y' ";
306 $q3 =
"fulltext @@ to_tsquery('french','" . pg_escape_string(
unaccent($left)) .
"') ";
307 $q4 =
"fulltext @@ to_tsquery('french','" . pg_escape_string(
unaccent($right)) .
"') ";
309 if ((!$q1) && $q2) $sqlfiltersbrut[] =
"($q4 and $q2) or $q3";
310 elseif ((!$q2) && $q1) $sqlfiltersbrut[] =
"($q3 and $q1) or $q4";
311 elseif ($q2 && $q1) $sqlfiltersbrut[] =
"($q3 and $q1) or ($q4 and $q2)";
317 if (count($tsearchkeys) > 0) {
318 $fullkeys =
'(' . implode(
")&(", $tsearchkeys) .
')';
320 $fullkeys = pg_escape_string($fullkeys);
321 $sqlfilters[] =
"fulltext @@ to_tsquery('french','$fullkeys') ";
323 if (count($sqlfiltersbrut) > 0) $sqlfilters = array_merge($sqlfilters, $sqlfiltersbrut);
324 $sqlorder =
"ts_rank(fulltext,to_tsquery('french','$fullkeys')) desc";
330 if ($subfolder) $cdirid =
getRChildDirId($this->dbaccess, $dirid, array() , 0, $this->folderRecursiveLevel);
331 else $cdirid = $dirid;
343 if ($this->
getValue(
"se_famonly") ==
"yes") {
358 return ($this->
getValue(
"se_static") !=
"") || (($this->
getValue(
"se_latest") ==
"") && ($this->
getValue(
"se_case") ==
"") && ($this->
getValue(
"se_key") ==
""));
375 else $query =
'select id from only doc where false';
385 $rtarget = getHttpVars(
"rtarget");
386 $this->lay->set(
"rtarget", $rtarget);
387 $this->lay->set(
"restrict",
false);
388 $this->lay->set(
"archive",
false);
390 $farch = new_doc($this->dbaccess,
"ARCHIVING");
391 if ($farch) $this->lay->set(
"archive", ($farch->control(
"view") ==
""));
392 $this->lay->set(
"thekey", $this->
getValue(
"se_key"));
394 $action->parent->AddJsRef($action->GetParam(
"CORE_PUBURL") .
"/FDL/Layout/edittable.js");
395 $action->parent->AddJsRef($action->GetParam(
"CORE_PUBURL") .
"/FREEDOM/Layout/editdsearch.js");
400 if (method_exists(
$dir,
"isAuthorized")) {
401 if (
$dir->isAuthorized($classid)) {
403 if (
$dir->hasNoRestriction()) $tclassdoc =
GetClassesDoc($this->dbaccess, $action->user->id, $classid,
"TABLE");
405 $tclassdoc =
$dir->getAuthorizedFamilies();
406 $this->lay->set(
"restrict",
true);
409 $tclassdoc =
$dir->getAuthorizedFamilies();
410 $first = current($tclassdoc);
411 $famid = abs($first[
"id"]);
412 $this->lay->set(
"restrict",
true);
415 $tclassdoc =
GetClassesDoc($this->dbaccess, $action->user->id, $classid,
"TABLE");
418 $tclassdoc =
GetClassesDoc($this->dbaccess, $action->user->id, $classid,
"TABLE");
421 $this->lay->set(
"selfam", _(
"no family"));
423 foreach ($tclassdoc as $k => $cdoc) {
424 $selectclass[$k][
"idcdoc"] = $cdoc[
"id"];
425 $selectclass[$k][
"classname"] = $cdoc[
"title"];
426 if (abs($cdoc[
"initid"]) == abs(
$famid)) {
427 $selectclass[$k][
"selected"] =
"selected";
428 if (
$famid < 0) $this->lay->set(
"selfam", $cdoc[
"title"] .
" " . !!_(
"(only)"));
429 else $this->lay->set(
"selfam", $cdoc[
"title"]);
430 }
else $selectclass[$k][
"selected"] =
"";
433 $this->lay->SetBlockData(
"SELECTCLASS", $selectclass);
451 if ($controlview)
$uid = $this->userid;
453 $orderby = $this->
getValue(
"se_orderby",
"title");
454 $tdoc =
getChildDoc($this->dbaccess, $this->initid, 0,
"ALL",
$filter,
$uid,
"TABLE",
$famid,
false, $orderby,
true, $this->
getValue(
"se_trash"));