Platform  3.1
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  * @license http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Anakeen - licence CC
5  * @package FDL
6 */
7 /**
8  * Generic searches
9  *
10  * @author Anakeen 2000
11  * @version $Id: generic_search.php,v 1.39 2008/03/10 15:08:25 eric Exp $
12  * @license http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Anakeen - licence CC
13  * @package FDL
14  * @subpackage
15  */
16 /**
17  */
18 
19 include_once ("FDL/Class.DocSearch.php");
20 include_once ("FDL/freedom_util.php");
21 include_once ("GENERIC/generic_util.php");
22 /**
23  * Search a document by keyword
24  * @param Action &$action current action
25  * @global keyword Http var : keyword to search
26  * @global catg Http var : primary folder/search where search
27  * @global dirid Http var : secondary search for sub searches
28  * @global mode Http var : (REGEXP|FULL) search mode regular expression or full text
29  */
31 {
32  // Get all the params
33  $keyword = GetHttpVars("keyword"); // keyword to search
34  $catgid = GetHttpVars("catg", getDefFld($action)); // primary folder/search where search
35  $dirid = GetHttpVars("dirid", getDefFld($action)); // temporary subsearch
36  $mode = GetHttpVars("mode");
37  $mysearches = (GetHttpVars("mysearches") == "yes");
38  $dbaccess = $action->GetParam("FREEDOM_DB");
39 
41  //change famid if it is a simplesearch
42  $sfamid = $famid;
43  if ($catgid) {
44  $dir = new_doc($dbaccess, $catgid);
45  if ($dir->isAlive()) {
46  $sfamid = $dir->getValue("se_famid", $famid);
47  }
48  }
49  $action->setParamU("GENE_LATESTTXTSEARCH", setUkey($action, $famid, $keyword));
50 
52  if ($mysearches) {
53 
54  $sdoc = createTmpDoc($dbaccess, 5); //new DocSearch($dbaccess);
55  $sdoc->title = sprintf(_("my search %s") , $keyword);
56  $sdoc->setValue("se_famid", 16);
57  $fdoc = new_doc($dbaccess, abs($famid));
58  if (!$keyword) $sdoc->title = sprintf(_("my searches about %s") , $fdoc->title);
59  $sdoc->Add();
60  $full = ($mode == "FULL");
61 
62  $sqlfilter = $sdoc->getSqlGeneralFilters($keyword, "yes", false, $full);
63  $sqlorder = getDefUSort($action, "title");
64  if ($sqlorder == "") $sdoc->deleteValue("se_orderby");
65  $sqlfilter[] = "owner=" . $action->user->id;
66  $sqlfilter[] = "se_famid='" . pg_escape_string($famid) . "'";
67  $query = getSqlSearchDoc($dbaccess, $sdirid, 16, $sqlfilter, false, true, "", false);
68 
69  $sdoc->AddQuery($query);
70 
71  redirect($action, GetHttpVars("app") , "GENERIC_LIST&sqlorder=title$pds&mode=$mode&famid=$famid&dirid=" . $sdoc->id . "&catg=$catgid");
72  } elseif ($keyword) {
73  if ($keyword[0] != ">") {
74  $dirid = $catgid;
75  $doc = new_Doc($dbaccess, $dirid);
76  $pds = $doc->urlWhatEncodeSpec("");
77  } else { // search sub searches
78  $keyword = substr($keyword, 1);
79  $catg = new_Doc($dbaccess, $catgid);
80  $pds = $catg->urlWhatEncodeSpec("");
81  $doc = new_Doc($dbaccess, $dirid);
82  }
83  $searchquery = "";
84  $sdirid = 0;
85  if ($doc->defDoctype == 'S') { // case of search in search doc
86  $sdirid = $doc->id;
87  } else { // case of search in folder
88  if ($doc->id != getDefFld($action)) $sdirid = $dirid;
89  }
90  $sdoc = createTmpDoc($dbaccess, 5); //new DocSearch($dbaccess);
91  $sdoc->title = sprintf(_("search %s") , $keyword);
92  if ($sdirid > 0) {
93  if ($doc->id == getDefFld($action)) $sdoc->title = sprintf(_("search contains %s in all state") , $keyword);
94  else $sdoc->title = sprintf(_("search contains %s in %s") , $keyword, $doc->getTitle());
95  }
96  $sdoc->setValue("se_famid", $sfamid);
97  $sdoc->Add();
98  // AddwarningMsg( "[dirid:$dirid][catg:$catgid][sdirid:$sdirid]");
99  $full = ($mode == "FULL");
100 
101  $only = (getInherit($action, $famid) == "N");
102 
103  $sqlfilter = $sdoc->getSqlGeneralFilters($keyword, "yes", false, $full);
104  $sqlorder = getDefUSort($action, "title");
105  if ($sqlorder == "") $sdoc->deleteValue("se_orderby");
106  if ($full) {
107  //if ($famid > 0) $sqlfilter[]="fromid=".intval($famid); // here function to retrieve descendants
108 
109  }
110 
111  $query = getSqlSearchDoc($dbaccess, $sdirid, ($only) ? -($sfamid) : $sfamid, $sqlfilter, false, true, "", false);
112  $sdoc->AddQuery($query);
113 
114  redirect($action, GetHttpVars("app") , "GENERIC_LIST$pds&mode=$mode&famid=$famid&dirid=" . $sdoc->id . "&catg=$catgid");
115  } else {
116  redirect($action, GetHttpVars("app") , "GENERIC_LIST$pds&mode=$mode&famid=$famid&dirid=" . $catgid . "&catg=$catgid");
117  }
118 }
119 ?>
← centre documentaire © anakeen - published under CC License - Dynacase