15 include_once (
"FDL/Class.Document.php");
16 include_once (
"FDL/Lib.FullSearch.php");
27 private $completeProperties =
false;
28 private $contentOnlyValue =
true;
29 private $contentOrderBy =
'';
30 private $contentSlice =
'ALL';
31 private $contentStart = 0;
32 private $contentKey =
'';
33 private $contentKeyMode =
'';
34 private $contentSearchProperty =
'';
35 private $contentFilter =
'';
36 private $contentVerifyHasChild =
false;
37 private $contentRecursiveLevel = 0;
38 private $contentMap = null;
39 private $onlyAttributes = null;
41 private $debug =
false;
46 private $documentList = null;
54 $this->debug = (!empty($debug));
59 $this->completeProperties =
$value;
63 $this->onlyAttributes =
$value;
67 $this->contentOnlyValue =
$value;
71 $this->contentOrderBy =
$value;
75 $this->contentSlice =
$value;
79 $this->contentStart =
$value;
83 $this->contentKey =
$value;
87 $this->contentKeyMode =
$value;
91 $this->contentSearchProperty =
$value;
95 $this->contentFilter =
$value;
99 $this->contentVerifyHasChild =
$value;
103 $this->contentRecursiveLevel = intval(
$value);
107 $this->contentMap = $callback;
114 if ($this->documentList)
return $this->getDocumentListContent();
130 include_once (
"FDL/Class.SearchDoc.php");
133 if ($this->contentOrderBy)
$s->orderby = $this->contentOrderBy;
134 $s->setSlice($this->contentSlice);
135 $s->setStart($this->contentStart);
136 $s->excludeConfidential();
137 $s->recursiveSearch = ($this->contentRecursiveLevel > 0);
138 $s->folderRecursiveLevel = $this->contentRecursiveLevel;
140 $out =
new stdClass();
143 $s->setObjectReturn();
144 $key = $this->contentKey;
146 if ($this->contentKeyMode ==
"word") {
147 $sqlfilters = array();
151 foreach ($sqlfilters as $vfilter)
$s->addFilter($vfilter);
152 if (!
$s->orderby)
$s->orderby = $fullorderby;
154 $s->addFilter(
"%s ~* '%s'", ($this->contentSearchProperty ? $this->contentSearchProperty :
"svalues") , $key);
157 if ($this->contentFilter) {
158 if (is_string($this->contentFilter)) {
159 $lfilter = strtolower($this->contentFilter);
160 if ((!strstr($lfilter,
'--')) && (!strstr($lfilter,
';')) && (!strstr($lfilter,
'insert')) && (!strstr($lfilter,
'alter')) && (!strstr($lfilter,
'delete')) && (!strstr($lfilter,
'update'))) {
162 $s->addFilter($this->contentFilter);
164 } elseif (is_object($this->contentFilter)) {
167 $err = $this->doc->object2SqlFilter($this->contentFilter, $ofamid, $sfilter);
169 if ($ofamid)
$s->fromid = $ofamid;
170 $s->addFilter($sfilter);
173 if ($this->onlyAttributes !== null) {
178 if ($this->debug)
$out->info =
$s->getSearchInfo();
183 $dl =
$s->getDocumentList();
185 return $this->getDocumentListContent();
188 }
else $this->error = sprintf(_(
"document not initialized"));
191 foreach ($content as & $v) {
192 $out->content[] = $v;
196 $out->date = date(
'Y-m-d H:i:s');
207 $this->documentList = $dl;
215 private function getDocumentListContent()
218 $dl = $this->documentList;
220 $out =
new stdClass();
222 $this->
setError(
"document list uninitialized");
225 $s = $dl->getSearchDocument();
226 if ($this->contentMap) $dl->listMap($this->contentMap);
227 if ($this->debug)
$out->info =
$s->getSearchInfo();
232 if ($this->onlyAttributes !== null) {
233 $tmpdoc->usePartialDocument($this->onlyAttributes);
236 $verifyhaschild = $this->contentVerifyHasChild;
240 foreach ($dl as
$doc) {
241 $tmpdoc->affect($doc);
242 if (!$doc->isConfidential()) {
243 if ($verifyhaschild) {
244 $tmpdoc->setVolatileProperty(
"haschildfolder",
hasChildFld($this->dbaccess, $tmpdoc->getProperty(
'initid') , ($doc->doctype ==
'S')));
246 $content[$kd] = $tmpdoc->getDocument($this->contentOnlyValue, $this->completeProperties);
251 $out->totalCount =
$s->count();
252 if ((
$out->totalCount ==
$s->slice) || (
$s->start > 0)) {
256 $oc =
$s->onlyCount();
257 if ($this->debug)
$out->info[
"totalCount"] =
$s->getSearchInfo();
258 if ($oc)
$out->totalCount = $oc;
262 $out->content = $content;
263 $out->date = date(
'Y-m-d H:i:s');
281 public function simpleSearch($key, $mode =
"word",
$famid = 0,
$filter =
"",
$start = 0,
$slice = 100, $orderby =
"", $onlyvalues =
true, $searchproperty =
"svalues", $whl =
false, $verifyhaschild =
false)
283 include_once (
"FDL/Class.SearchDoc.php");
285 $out =
new stdClass();
289 if (strstr(
$famid,
'|')) {
291 $tfamids = explode(
'|',
$famid);
292 foreach ($tfamids as $fid) {
293 if (!is_numeric($fid)) $fid = getFamidFromName($this->dbaccess, $fid);
294 if ($fid > 0) $tfid[] = $fid;
299 if (preg_match(
'/([\w:]*)\s?strict/', trim(
$famid) , $reg)) {
300 if (!is_numeric($reg[1])) $reg[1] =
getFamIdFromName($this->dbaccess, $reg[1]);
305 if ($mode ==
"word") {
306 $sqlfilters = array();
310 foreach ($sqlfilters as $vfilter)
$s->addFilter($vfilter);
311 if (!$orderby) $orderby = $fullorderby;
313 $s->addFilter(sprintf(
"%s ~* '%s'", $searchproperty, $key));
318 $lfilter = strtolower(
$filter);
319 if ((!strstr($lfilter,
'--')) && (!strstr($lfilter,
';')) && (!stristr($lfilter,
'insert')) && (!stristr($lfilter,
'alter')) && (!stristr($lfilter,
'delete')) && (!stristr($lfilter,
'update'))) {
323 } elseif (is_object(
$filter)) {
329 $sw->setValue(
"se_famid",
$famid);
333 $err = $sw->object2SqlFilter(
$filter, $ofamid, $sfilter);
336 $s->fromid = $ofamid;
338 $s->addFilter($sfilter);
342 if (count($tfid) > 0)
$s->addFilter(getSqlCond($tfid,
'fromid',
true));
343 $completeprop =
false;
347 if ($orderby)
$s->orderby = $orderby;
348 $s->setObjectReturn();
349 $s->excludeConfidential();
360 $ws->setValue(
"ba_title", sprintf(_(
"search %s") , $key));
362 $ws->addStaticQuery(
$s->getOriginalQuery());
364 $out->document = $tmpdoc->getDocument(
true,
false);
367 while ($doc =
$s->getNextDoc()) {
368 $tmpdoc->affect($doc);
369 if ($verifyhaschild) {
370 $tmpdoc->setVolatileProperty(
"haschildfolder",
hasChildFld($this->dbaccess, $tmpdoc->getProperty(
'initid') , ($doc->doctype ==
'S')));
372 $content[$idx] = $tmpdoc->getDocument($onlyvalues, $completeprop);
377 $out->totalCount =
$s->count();
382 $out->totalCount =
$s->onlyCount();
384 if (!isset(
$out->delay)) {
387 $out->delay.=
' count:' .
$info[
"delay"];
389 $out->content = $content;
396 $out->date = date(
'Y-m-d H:i:s');
406 $out =
new stdClass();
407 $fam = new_doc($this->dbaccess,
$famid);
408 if (!$fam->isAlive()) {
409 $out->error = sprintf(_(
"data:family %s not alive") ,
$famid);
410 } elseif ($fam->doctype !=
'C') {
411 $out->error = sprintf(_(
"data:document %s is not a family") ,
$famid);
415 $fld =
new Dir($this->dbaccess);
417 $tfam = $fld->GetChildFam(
$famid, $controlcreate);
418 if (count($tfam) > 0) {
421 $completeprop =
false;
422 foreach ($tfam as $id => $rawfam) {
423 $fam->affect($rawfam);
424 $tmpdoc->affect($fam);
425 if (!$tmpdoc->error) {
426 $content[] = $tmpdoc->getDocument($onlyvalues, $completeprop);
430 $out->content = $content;
431 $out->totalCount = count($content);
442 $out =
new stdClass();
449 $out->message = sprintf(_(
"document %d inserted") ,
$docid);
451 }
else $out->error = sprintf(_(
"document not set"));
461 $out =
new stdClass();
468 $out->message = sprintf(_(
"document %d deleted") ,
$docid);
470 }
else $out->error = sprintf(_(
"document not set"));
480 $out =
new stdClass();
481 include_once (
"DATA/Class.DocumentSelection.php");
483 $ids = $os->getIdentificators();
486 $out->notunlinked = array();
487 $out->unlinked = array();
488 $err = $this->doc->canModify();
492 foreach ($ids as
$docid) {
493 $err = $this->doc->removeDocument($docid);
497 $out->unlinked[
$docid] = sprintf(_(
"document %d unlinked") , $docid) .
"\n";
500 $out->unlinkedCount = count(
$out->unlinked);
501 $out->notUnlinkedCount = count(
$out->notunlinked);
503 }
else $out->error = sprintf(_(
"document not set"));
513 $out =
new stdClass();
516 $err = $this->doc->canModify();
520 $out->error = $this->doc->clear();
522 }
else $out->error = sprintf(_(
"document not set"));
532 $out =
new stdClass();
533 include_once (
"DATA/Class.DocumentSelection.php");
535 $ids = $os->getIdentificators();
538 $out->notmoved = array();
539 $out->moved = array();
540 $err = $this->doc->canModify();
545 $targetDoc = new_doc($this->dbaccess, $targetId);
546 if ($targetDoc->isAlive()) {
547 if ($targetDoc->defDoctype !=
'D')
$err = sprintf(_(
"target folder [%s] is not a folder") , $targetDoc->getTitle());
549 $err = $targetDoc->canModify();
552 $err = sprintf(_(
"target folder [%s] is not set") , $targetId);
557 foreach ($ids as
$docid) {
558 $err = $this->doc->moveDocument($docid, $targetDoc->initid);
562 $out->moved[
$docid] = sprintf(_(
"document %d moved") , $docid) .
"\n";
565 $out->movedCount = count(
$out->moved);
566 $out->notMovedCount = count(
$out->notmoved);
571 }
else $out->error = sprintf(_(
"document not set"));
581 $out =
new stdClass();
582 include_once (
"DATA/Class.DocumentSelection.php");
585 $tdocs = $os->getRawDocuments();
586 $out->notinserted = array();
587 $out->inserted = array();
588 $err = $this->doc->insertMultipleDocuments($tdocs,
"latest",
false,
$out->inserted,
$out->notinserted);
589 $out->insertedCount = count(
$out->inserted);
590 $out->notInsertedCount = count(
$out->notinserted);
592 }
else $out->error = sprintf(_(
"document not set"));
599 if (method_exists($this->doc,
"getAuthorizedFamilies")) {
602 "restriction" => $this->doc->hasNoRestriction() ?
false :
true,
603 "families" => $this->doc->getAuthorizedFamilies()
setContentOrderBy($value)
static getFullSqlFilters($keyword, &$sqlfilters, &$sqlorder, &$fullkeys)
insertDocuments($selection)
setContentVerifyHasChild($value)
moveDocuments($selection, $targetId)
unlinkDocuments($selection)
getHighlight(&$doc, $keys)
hasChildFld($dbaccess, $dirid, $issearch=false)
setContentKeyMode($value)
setContentSearchProperty($value)
setContentRecursiveLevel($value)
returnsOnlyAttributes(array $value)
setContentOnlyValue($value)
getFamIdFromName($dbaccess, $name)
getSubFamilies($famid, $controlcreate=false)
setContentCompleteProperties($value)
createTmpDoc($dbaccess, $fromid, $defaultvalue=true)
if($file) if($subject==""&&$file) if($subject=="") $err
useDocumentList(DocumentList &$dl)