Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
generic_search.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @package FDL
5 */
6 /**
7  * Generic searches
8  *
9  * @author Anakeen
10  * @version $Id: generic_search.php,v 1.39 2008/03/10 15:08:25 eric Exp $
11  * @package FDL
12  * @subpackage
13  */
14 /**
15  */
16 
17 include_once ("FDL/Class.DocSearch.php");
18 include_once ("FDL/freedom_util.php");
19 include_once ("GENERIC/generic_util.php");
20 /**
21  * Search a document by keyword
22  * @param Action &$action current action
23  * @global string $keyword Http var : keyword to search
24  * @global string $catg Http var : primary folder/search where search
25  * @global string $dirid Http var : secondary search for sub searches
26  */
28 {
29  // Get all the params
30  $keyword = $action->getArgument("keyword"); // keyword to search
31  $catgid = $action->getArgument("catg", getDefFld($action)); // primary folder/search where search
32  $searchMode = $action->getParam("GENE_SEARCHMODE", "words");
33 
34  $mysearches = ($action->getArgument("mysearches") == "yes");
35 
36  $onefamOrigin = $action->getArgument("onefam"); // onefam origin
37  if ($onefamOrigin) {
38  $onefamSearchMode = ApplicationParameterManager::getParameterValue($onefamOrigin, "ONEFAM_SEARCHMODE");
39  if ($onefamSearchMode) {
40  $searchMode = $onefamSearchMode;
41  }
42  }
43  $dbaccess = $action->dbaccess;
44 
45  $famid = getDefFam($action);
46  //change famid if it is a simplesearch
47  $sfamid = $famid;
48  if ($catgid) {
49  $dir = new_doc($dbaccess, $catgid);
50  if ($dir->isAlive()) {
51  $sfamid = $dir->getRawValue("se_famid", $famid);
52  }
53  }
54  $action->setParamU("GENE_LATESTTXTSEARCH", setUkey($action, $famid, $keyword));
55 
56  if ($mysearches) {
57  /*
58  * @var DocSearch $sdoc
59  */
60  $sdoc = createTmpDoc($dbaccess, 5); //new DocSearch($dbaccess);
61  $sdoc->title = sprintf(_("my search %s") , $keyword);
62  $sdoc->setValue("se_famid", 16);
63  $fdoc = new_doc($dbaccess, abs($famid));
64  if (!$keyword) {
65  $sdoc->title = sprintf(_("my searches about %s") , $fdoc->title);
66  }
67  $sdoc->Add();
68  $full = ($searchMode === "words");
69 
70  $sqlfilter = $sdoc->getSqlGeneralFilters($keyword, "yes", false, $full);
71  $sqlorder = getDefUSort($action, "title");
72  if ($sqlorder == "") {
73  $sdoc->clearValue("se_orderby");
74  }
75  $sqlfilter[] = "owner=" . $action->user->id;
76  $sqlfilter[] = "se_famid='" . pg_escape_string($famid) . "'";
77  $query = getSqlSearchDoc($dbaccess, 0, 16, $sqlfilter, false, true, "", false);
78 
79  $sdoc->AddQuery($query);
80  executeGenericList($action, array(
81  "onefam" => $onefamOrigin,
82  "famid" => $famid,
83  "dirid" => $sdoc->id,
84  "catg" => $catgid
85  ));
86  } elseif ($keyword) {
87  $dirid = $catgid;
89  $sdirid = 0;
90  if ($doc->defDoctype == 'S') { // case of search in search doc
91  $sdirid = $doc->id;
92  } else { // case of search in folder
93  if ($doc->id != getDefFld($action)) $sdirid = $dirid;
94  }
95  /* @var $sdoc DocSearch */
96  $sdoc = createTmpDoc($dbaccess, 5); //new DocSearch($dbaccess);
97  $sdoc->title = sprintf(_("Search : %s") , $keyword);
98  if ($sdirid > 0) {
99  if ($doc->id == getDefFld($action)) {
100  $sdoc->title = sprintf(_("search contains %s in all state") , $keyword);
101  } else {
102  $sdoc->title = sprintf(_("search contains %s in %s") , $keyword, $doc->getTitle());
103  }
104  }
105  $sdoc->setValue("se_famid", $sfamid);
106  $sdoc->Add();
107 
108  $only = (getInherit($action, $famid) == "N");
109 
110  try {
112  throw new \Dcp\Exception(sprintf(_("incorrect global filter %s") , $keyword));
113  } else {
114  $usePartial = ($searchMode === "characters");
115  $sqlfilter = array(
116  SearchDoc::getGeneralFilter($keyword, $useSpell = true, $fullOrder, $highlight, $usePartial)
117  );
118  }
119  }
120  catch(Dcp\SearchDoc\Exception $e) {
121  switch ($e->getDcpCode()) {
122  case "SD0007":
123  $err = sprintf(_("incorrect global filter %s") , $keyword);
125 
126  break;
127 
128  default:
129  $err = $e->getMessage();
131  }
132  $sqlfilter = array(
133  'false'
134  );
135  }
136  catch(Exception $e) {
137  $err = $e->getMessage();
139  $sqlfilter = array(
140  'false'
141  );
142  }
143  //$action->addLogMsg($sqlfilter);
144  $sqlorder = getDefUSort($action);
145  if ($sqlorder == "") {
146  $sdoc->clearValue("se_orderby");
147  }
148 
149  $query = getSqlSearchDoc($dbaccess, $sdirid, ($only) ? -($sfamid) : $sfamid, $sqlfilter, false, true, "", false);
150 
151  $sdoc->AddQuery($query);
152 
153  executeGenericList($action, array(
154  "onefam" => $onefamOrigin,
155  "famid" => $famid,
156  "dirid" => $sdoc->id,
157  "catg" => $catgid
158  ));
159  } else {
160  executeGenericList($action, array(
161  "onefam" => $onefamOrigin,
162  "famid" => $famid,
163  "dirid" => $catgid,
164  "catg" => $catgid
165  ));
166  }
167 }
168 
170 {
171  foreach ($args as $k => $v) {
172  SetHttpVar($k, $v);
173  }
174  $action->set("GENERIC_LIST", $action->parent);
175  $gen = $action->execute();
176  $action->lay->template = $gen;
177  $action->lay->noparse = true;
178 }
if(substr($wsh, 0, 1)!= '/') $args
global $action
getSqlSearchDoc($dbaccess, $dirid, $fromid, $sqlfilters=array(), $distinct=false, $latest=true, $trash="", $simplesearch=false, $folderRecursiveLevel=2, $join= '', $only="")
Definition: Lib.Dir.php:108
SetHttpVar($name, $def)
Definition: Lib.Http.php:150
$full
getDefUSort(Action &$action, $def="-revdate", $famid="")
getDefFld(Action &$action)
static checkGeneralFilter($keyword)
static getParameterValue($application, $parameterName)
static getGeneralFilter($keywords, $useSpell=false, &$pertinenceOrder= '', &$highlightWords= '', $usePartial=false)
addWarningMsg($msg)
Definition: Lib.Common.php:95
getDefFam(Action &$action)
setParamU($name, $val)
generic_search(Action &$action)
new_Doc($dbaccess, $id= '', $latest=false)
setUkey(Action &$action, $famid, $key)
$dir
Definition: resizeimg.php:144
executeGenericList(Action &$action, array $args)
getParam($name, $def="")
$keyword
static getArgument($k, $def= '')
$dbaccess
Definition: checkVault.php:17
if(($docid!==0)&&(!is_numeric($docid))) $query
createTmpDoc($dbaccess, $fromid, $defaultvalue=true)
getInherit(Action &$action, $famid="")
if($file) if($subject==""&&$file) if($subject=="") $err
← centre documentaire © anakeen