Platform  3.1
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
search_fulltext.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  * Generated Header (not documented yet)
9  *
10  * @author Anakeen 2000
11  * @version $Id: search_fulltext.php,v 1.9 2007/10/15 13:01:06 eric Exp $
12  * @license http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Anakeen - licence CC
13  * @package FDL
14  * @subpackage GED
15  */
16 /**
17  */
18 // ---------------------------------------------------------------
19 // $Id: search_fulltext.php,v 1.9 2007/10/15 13:01:06 eric Exp $
20 // $Source: /home/cvsroot/anakeen/freedom/freedom/Action/Freedom/search_fulltext.php,v $
21 // ---------------------------------------------------------------
22 include_once ("FDL/Class.DocSearch.php");
23 include_once ("FDL/Class.Dir.php");
24 include_once ("FDL/Lib.Dir.php");
25 include_once ("FDL/Class.QueryDir.php");
26 include_once ("FDL/freedom_util.php");
27 
29 {
30  $ifile = basename($name);
31  $te = explode(".", $ifile);
32  return $te[0];
33 }
34 
35 function search_error(&$action, $msg)
36 {
37  $action->log->error($msg);
38  print "<h2>" . $msg . "</h2>";
39  exit;
40 }
41 // -----------------------------------
43 {
44  // -----------------------------------
45  global $tpt, $ipt;
46 
47  if (!extension_loaded('mnogosearch')) search_error($action, _("mnogosearch php extension not loaded"));
48 
49  $baseurl = $action->GetParam("CORE_BASEURL");
50  $standurl = $action->GetParam("CORE_STANDURL");
51  $dbaccess = $action->GetParam("FREEDOM_DB");
52  // Get all the params
53  $keyword = GetHttpVars("keyword"); // keyword to search
54  $title = GetHttpVars("title", _("new search ") . $keyword); // title of the search
55  $latest = GetHttpVars("latest", false); // only latest revision
56  $s_match = GetHttpVars("matchid", 0); // matching ploicy
57  $adminstat[0]["match"] = $s_match;
58  $s_searchfor = GetHttpVars("searchforid", 0); // search policy
59  $adminstat[0]["searchfor"] = $s_searchfor;
60  $viewfile = GetHttpVars("viewfile", false); // display files
61  $famid = GetHttpVars("famid"); // famid restrictive familly
62  $action->lay->Set("classdoc", _(" any familly"));
63  $tclassdoc = GetClassesDoc($dbaccess, $action->user->id, 0, "TABLE");
64  while (list($k, $cdoc) = each($tclassdoc)) {
65  if ($famid == $cdoc["initid"]) $action->lay->Set("classdoc", $cdoc["title"]);
66  }
67 
68  $fromdir = GetHttpVars("fromdir", false); // the keyword is case sensitive
69  $dirid = GetHttpVars("dirid");
70 
71  $refresh = GetHttpVars("refresh", "no"); // force folder refresh
72  $startpage = GetHttpVars("page", "0"); // page number
73  $action->parent->AddJsRef($action->GetParam("CORE_JSURL") . "/subwindow.js");
74  $action->parent->AddJsRef($action->GetParam("CORE_JSURL") . "/geometry.js");
75 
76  $searchtitle = _("search for ") . " : " . $keyword . ", ";
77  if ($fromdir) $searchtitle.= _(" from current folder");
78  else $searchtitle.= _(" from any folder");
79  $action->lay->Set("dirtitle", $searchtitle);
80  $action->lay->Set("dirid", $dirid);
81 
82  $with_abstract = false;
83  $start = 0;
84  // ------------------------------------------------------
85  // definition of popup menu
86  $with_popup = true;
87  include_once ("FDL/popup_util.php");
88  popupInit("popuplist", array(
89  'vprop',
90  'editdoc',
91  'cancel',
92  'copy',
93  'duplicate',
94  'ifld',
95  'delete'
96  ));
97  $slice = "1000";
98 
99  $s_db = $action->GetParam("MNOGOSEARCH_DB", "pgsql://anakeen@localhost/mnoGoSearch/");
100  $s_dbmode = $action->GetParam("MNOGOSEARCH_DBMODE", "crc");
101 
102  $search_limit = $action->GetParam("MNOGOSEARCH_SEARCHLIMIT", "%/freedom/fs/%");
103 
104  $udm_param = array();
105  // Get first page only
106  $udm_param[UDM_PARAM_PAGE_NUM] = 0;
107  $udm_param[UDM_PARAM_TRACK_MODE] = UDM_TRACK_DISABLED;
108  $udm_param[UDM_PARAM_PAGE_SIZE] = $action->GetParam("MNOGOSEARCH_RESULTBYPAGE", 1000);
109  $udm_param[UDM_PARAM_CACHE_MODE] = $action->GetParam("MNOGOSEARCH_CACHE", UDM_CACHE_ENABLED);
110  $udm_param[UDM_PARAM_PHRASE_MODE] = $action->GetParam("MNOGOSEARCH_PHRASE", UDM_PHRASE_ENABLED);
111  $udm_param[UDM_PARAM_CHARSET] = $action->GetParam("MNOGOSEARCH_CHARSET", "8859-1");
112  $udm_param[UDM_PARAM_STOPTABLE] = $action->GetParam("MNOGOSEARCH_STOPTABLE", "stopword");
113 
114  $udm_param[UDM_PARAM_SEARCH_MODE] = $s_match;
115 
116  $udm_param[UDM_PARAM_WORD_MATCH] = $s_searchfor;
117 
118  $search = udm_alloc_agent($s_db, $s_dbmode);
119  if (!$search) search_error($action, _("can't connect mnogosearch db"));
120 
121  while (list($k, $v) = each($udm_param)) {
122  if (!Udm_Set_Agent_Param($search, $k, $v)) {
123  $action->log->warn("Udm_Set_Agent_Param {$k} = {$v} returns an error");
124  }
125  }
126 
127  Udm_Add_Search_Limit($search, UDM_LIMIT_URL, $search_limit);
128  $res = Udm_Find($search, urldecode($keyword));
129  if (Udm_Errno($search) > 0) {
130  search_error($action, _("Udm_Find Error : ") . Udm_Error($search));
131  }
132 
133  $action->lay->Set("stime", Udm_Get_Res_Param($res, UDM_PARAM_SEARCHTIME));
134  $action->lay->Set("totalcnt", udm_get_doc_count($search));
135  $adminstat[0]["infos"] = Udm_Get_Res_Param($res, UDM_PARAM_WORDINFO);
136 
137  $found = Udm_Get_Res_Param($res, UDM_PARAM_FOUND);
138  $adminstat[0]["ffound"] = $found;
139  $adminfile = array();
140  $doclist = array();
141  $idoc = 0;
142  if ($found > 0) {
143  $rows = Udm_Get_Res_Param($res, UDM_PARAM_NUM_ROWS);
144  $adminstat[0]["fviewed"] = $rows;
145  for ($i = 0; $i < $rows; $i++) {
146  $resurl = Udm_Get_Res_Field($res, $i, UDM_FIELD_URL);
147  $adminfile[$i]["ix"] = "";
148  $adminfile[$i]["filename"] = $resurl;
149  $idf = fileNameToId($resurl);
150  if ($idf > 0) {
151  // Querying db ...
152  $filter = array();
153  $filter[] = "values like '%|$idf'";
154 
155  if ($famid == 0) $famid = "";
156  $cdirid = 0;
157  if ($fromdir) {
158  $cdirid = getRChildDirId($dbaccess, $dirid);
159  }
160  $rq = getChildDoc($dbaccess, $cdirid, 0, 100, $filter, $action->user->id, "TABLE", $famid);
161 
162  if (is_array($rq) && count($rq) > 0) {
163  while (count($rq) > 0 && list($kv, $vd) = each($rq)) {
164  $adminfile[$i]["ix"].= "[" . $vd["id"] . "]";
165  if (!isset($doclist[$vd["id"]])) $doclist[$vd["id"]]["fcnt"] = 0;
166  $x = $doclist[$vd["id"]]["fcnt"];
167  $doclist[$vd["id"]]["fcnt"]++;
168  // $doclist[$vd["id"]][$x]["attrid"] = $vd["attrid"];
169  $doclist[$vd["id"]][$x]["file"] = $resurl;
170  $doclist[$vd["id"]][$x]["idv"] = $idf;
171  $doclist[$vd["id"]][$x]["size"] = Udm_Get_Res_Field($res, $i, UDM_FIELD_SIZE);
172  $doclist[$vd["id"]][$x]["rate"] = Udm_Get_Res_Field($res, $i, UDM_FIELD_RATING);
173  $doclist[$vd["id"]][$x]["modi"] = Udm_Get_Res_Field($res, $i, UDM_FIELD_MODIFIED);
174  }
175  }
176  unset($query);
177  }
178  }
179  }
180  Udm_Free_Res($res);
181  Udm_Free_Agent($search);
182 
183  $kdiv = 1;
184  $tdoc = array();
185  $nbseedoc = $nbdoc = 0;
186  reset($doclist);
187  while (list($kd, $vd) = each($doclist)) {
188  $doc = new_Doc($dbaccess, $kd);
189  $nbseedoc++;
190  $k = $nbdoc;
191  $nbdoc++; // one more visible doc
192  $docid = $doc->id;
193 
194  $tdoc[$k]["id"] = $docid;
195  if ($with_abstract) $tdoc[$k]["blockabstract"] = "abstract_$k";
196 
197  $tdoc[$k]["title"] = $doc->title;
198  if (strlen($doc->title) > 20) $tdoc[$k]["abrvtitle"] = substr($doc->title, 0, 12) . "... " . substr($doc->title, -5);
199  else $tdoc[$k]["abrvtitle"] = $doc->title;
200  $tdoc[$k]["profid"] = $doc->profid;
201  $tdoc[$k]["iconsrc"] = $doc->geticon();
202  $tdoc[$k]["divid"] = $kdiv;
203 
204  $tdoc[$k]["locked"] = "";
205  if ($doc->isRevisable()) {
206  if (($doc->locked > 0) && ($doc->locked == $action->parent->user->id)) $tdoc[$k]["locked"] = $action->GetIcon("clef1.gif", N_("locked") , 20, 20);
207  else if ($doc->locked > 0) $tdoc[$k]["locked"] = $action->GetIcon("clef2.gif", N_("locked") , 20, 20);
208  else if ($doc->locked < 0) $tdoc[$k]["locked"] = $action->GetIcon("nowrite.png", N_("fixed") , 20, 20);
209  else if ($doc->lmodify == "Y") if ($doc->doctype == 'F') $tdoc[$k]["locked"] = $action->GetIcon("changed2.gif", N_("changed") , 20, 20);
210  }
211 
212  if ($with_popup) {
213  popupActive("popuplist", $kdiv, 'vprop');
214  popupActive("popuplist", $kdiv, 'cancel');
215  popupActive("popuplist", $kdiv, 'copy');
216  popupActive("popuplist", $kdiv, 'ifld');
217  popupInvisible("popuplist", $kdiv, 'editdoc');
218  popupInvisible("popuplist", $kdiv, 'delete');
219  popupInvisible("popuplist", $kdiv, 'duplicate');
220  }
221 
222  $kdiv++;
223  if ($doc->doctype == 'F') $tdoc[$k]["revision"] = $doc->revision;
224  else $tdoc[$k]["revision"] = "";
225  $tdoc[$k]["state"] = $action->Text($doc->state);
226 
227  if ($doc->classname == 'Dir') $tdoc[$k]["isfld"] = "true";
228  else $tdoc[$k]["isfld"] = "false";
229 
230  if ($with_abstract) {
231  // search abstract for freedom item
232  $query_val->basic_elem->sup_where = array(
233  "(docid=$docid)",
234  $sql_cond_abs
235  );
236 
237  $tablevalue = $query_val->Query();
238  // Set the table elements
239  $tableabstract = array();
240  $nbabs = 0; // nb abstract
241  for ($i = 0; $i < $query_val->nb; $i++) {
242 
243  $lvalue = chop($tablevalue[$i]->value);
244 
245  if ($lvalue != "") {
246  $oattr = $doc->GetAttribute($tablevalue[$i]->attrid);
247 
248  $tdoc[$k][$tablevalue[$i]->attrid] = $lvalue;
249 
250  $tableabstract[$nbabs]["name"] = $action->text($oattr->labeltext);
251  $tableabstract[$nbabs]["valid"] = $tablevalue[$i]->attrid;
252  switch ($oattr->type) {
253  case "image":
254 
255  $efile = $doc->GetHtmlValue($oattr, $lvalue, "finfo");
256 
257  $tableabstract[$nbabs]["value"] = "<IMG align=\"absbottom\" width=\"30\" SRC=\"" . $efile . "\">";
258  break;
259 
260  default:
261  $tableabstract[$nbabs]["value"] = $doc->GetHtmlValue($oattr, $lvalue, "finfo");
262  break;
263  }
264  $nbabs++;
265  }
266  }
267  $action->lay->SetBlockData("abstract_$k", $tableabstract);
268 
269  unset($tableabstract);
270  }
271 
272  if ($viewfile) {
273  $rlay = $action->GetLayoutFile("search_fulltext_result.xml");
274  $rlay = new Layout($action->GetLayoutFile("search_fulltext_result.xml") , $action);
275  $filed = array();
276  for ($if = 0; $if < $vd["fcnt"]; $if++) {
277  $value = chop($doc->GetValue($vd[$if]["attrid"]));
278  $filed[$if]["imgsrc"] = $doc->GetHtmlValue($doc->GetAttribute($vd[$if]["attrid"]) , $value, "_self", "Y");
279  $filed[$if]["rating"] = $vd[$if]["rate"];
280  $filed[$if]["date"] = strftime("%d/%m/%Y %H:%M", $vd[$if]["modi"]);
281  }
282  $rlay->SetBlockData("ALLRESULT", $filed);
283  $tdoc[$k]["SEARCHRESULT"] = $rlay->Gen();
284  unset($filed);
285  unset($rlay);
286  } else {
287  $tdoc[$k]["SEARCHRESULT"] = "";
288  }
289  }
290  // Out
291  //------------------------------
292  // display popup action
293  $tboo[0]["boo"] = "";
294  $action->lay->SetBlockData("VIEWPROP", $tboo);
295  $action->lay->Set("nbdiv", $kdiv - 1);
296  $action->lay->SetBlockData("TABLEBODY", $tdoc);
297  if ($with_popup) {
298  popupGen($kdiv - 1);
299  $licon = new Layout($action->Getparam("CORE_PUBDIR") . "/FDL/Layout/manageicon.js", $action);
300  $licon->Set("nbdiv", $kdiv - 1);
301  $action->parent->AddJsCode($licon->gen());
302  }
303  // when slicing
304  $pagefolder[$startpage + 1] = $nbseedoc + $start;
305  $action->Register("pagefolder", $pagefolder);
306  $action->lay->Set("next", $startpage + 1);
307  $action->lay->Set("prev", $startpage - 1);
308  $action->lay->Set("nbdoc", $nbdoc);
309 
310  if ($action->user->id == 1) {
311  $action->lay->SetBlockData("ADMIN", $adminstat);
312  $action->lay->SetBlockData("ADMINFILES", $adminfile);
313  }
314  return $nbdoc;
315 }
316 ?>
← centre documentaire © anakeen - published under CC License - Dynacase