17 include_once (
"DATA/Class.Document.php");
18 include_once (
"DATA/Lib.FullSearch.php");
25 private $completeProperties =
false;
26 private $contentOnlyValue =
true;
27 private $contentOrderBy =
'';
28 private $contentSlice =
'ALL';
29 private $contentStart = 0;
30 private $contentKey =
'';
31 private $contentKeyMode =
'';
32 private $contentSearchProperty =
'';
33 private $contentFilter =
'';
34 private $contentVerifyHasChild =
false;
35 private $contentRecursiveLevel = 0;
36 private $contentMap = null;
41 private $documentList = null;
45 $this->completeProperties =
$value;
49 $this->contentOnlyValue =
$value;
53 $this->contentOrderBy =
$value;
57 $this->contentSlice =
$value;
61 $this->contentStart =
$value;
65 $this->contentKey =
$value;
69 $this->contentKeyMode =
$value;
73 $this->contentSearchProperty =
$value;
77 $this->contentFilter =
$value;
81 $this->contentVerifyHasChild =
$value;
85 $this->contentRecursiveLevel = intval(
$value);
89 $this->contentMap = $callback;
96 if ($this->documentList)
return $this->getDocumentListContent();
112 include_once (
"FDL/Class.SearchDoc.php");
115 if ($this->contentOrderBy)
$s->orderby = $this->contentOrderBy;
116 $s->setSlice($this->contentSlice);
117 $s->setStart($this->contentStart);
118 $s->excludeConfidential();
119 $s->recursiveSearch = ($this->contentRecursiveLevel > 0);
120 $s->folderRecursiveLevel = $this->contentRecursiveLevel;
125 $s->setObjectReturn();
126 $key = $this->contentKey;
128 if ($this->contentKeyMode ==
"word") {
129 $sqlfilters = array();
133 foreach ($sqlfilters as $vfilter)
$s->addFilter($vfilter);
134 if (!
$s->orderby)
$s->orderby = $fullorderby;
136 $s->addFilter(
"%s ~* '%s'", ($this->contentSearchProperty ? $this->contentSearchProperty :
"svalues") , $key);
139 if ($this->contentFilter) {
140 if (is_string($this->contentFilter)) {
141 $lfilter = strtolower($this->contentFilter);
142 if ((!strstr($lfilter,
'--')) && (!strstr($lfilter,
';')) && (!strstr($lfilter,
'insert')) && (!strstr($lfilter,
'alter')) && (!strstr($lfilter,
'delete')) && (!strstr($lfilter,
'update'))) {
144 $s->addFilter($this->contentFilter);
146 } elseif (is_object($this->contentFilter)) {
149 $err = $this->doc->object2SqlFilter($this->contentFilter, $ofamid, $sfilter);
151 if ($ofamid)
$s->fromid = $ofamid;
152 $s->addFilter($sfilter);
157 $out->info =
$s->getSearchInfo();
163 return $this->getDocumentListContent();
166 }
else $this->error = sprintf(_(
"document not initialized"));
167 $out->error = $this->error;
170 $out->content[] = $v;
174 $out->date = date(
'Y-m-d H:i:s');
185 $this->documentList = $dl;
193 private function getDocumentListContent()
195 $dl = $this->documentList;
198 $this->
setError(
"document list uninitialized");
201 $s = $dl->getSearchDocument();
202 if ($this->contentMap) $dl->listMap($this->contentMap);
204 $out->info =
$s->getSearchInfo();
210 $verifyhaschild = $this->contentVerifyHasChild;
211 foreach ($dl as
$doc) {
212 $tmpdoc->affect($doc);
213 if (!$doc->isConfidential()) {
214 if ($verifyhaschild) {
215 $tmpdoc->setVolatileProperty(
"haschildfolder",
hasChildFld($this->dbaccess, $tmpdoc->getProperty(
'initid') , ($doc->doctype ==
'S')));
217 $content[$kd] = $tmpdoc->getDocument($this->contentOnlyValue, $this->completeProperties);
222 $out->totalCount =
$s->count();
223 if ((
$out->totalCount ==
$s->slice) || (
$s->start > 0)) {
227 $oc =
$s->onlyCount();
228 $out->info[
"totalCount"] =
$s->getSearchInfo();
229 if ($oc)
$out->totalCount = $oc;
232 $out->error = $this->error;
234 $out->date = date(
'Y-m-d H:i:s');
252 public function simpleSearch($key,
$mode =
"word",
$famid = 0,
$filter =
"",
$start = 0,
$slice = 100, $orderby =
"", $onlyvalues =
true, $searchproperty =
"svalues", $whl =
false, $verifyhaschild =
false)
254 include_once (
"FDL/Class.SearchDoc.php");
258 if (strstr(
$famid,
'|')) {
260 $tfamids = explode(
'|',
$famid);
261 foreach ($tfamids as $fid) {
262 if (!is_numeric($fid)) $fid = getFamidFromName($this->dbaccess, $fid);
263 if ($fid > 0) $tfid[] = $fid;
268 if (preg_match(
'/([\w:]*)\s?strict/', trim(
$famid) , $reg)) {
269 if (!is_numeric($reg[1])) $reg[1] =
getFamIdFromName($this->dbaccess, $reg[1]);
274 if (
$mode ==
"word") {
275 $sqlfilters = array();
279 foreach ($sqlfilters as $vfilter)
$s->addFilter($vfilter);
280 if (!$orderby) $orderby = $fullorderby;
282 $s->addFilter(sprintf(
"%s ~* '%s'", $searchproperty, $key));
287 $lfilter = strtolower(
$filter);
288 if ((!strstr($lfilter,
'--')) && (!strstr($lfilter,
';')) && (!stristr($lfilter,
'insert')) && (!stristr($lfilter,
'alter')) && (!stristr($lfilter,
'delete')) && (!stristr($lfilter,
'update'))) {
292 } elseif (is_object(
$filter)) {
295 $sw->setValue(
"se_famid",
$famid);
299 $err = $sw->object2SqlFilter(
$filter, $ofamid, $sfilter);
302 $s->fromid = $ofamid;
304 $s->addFilter($sfilter);
308 if (count($tfid) > 0)
$s->addFilter(getSqlCond($tfid,
'fromid',
true));
309 $completeprop =
false;
313 if ($orderby)
$s->orderby = $orderby;
315 $s->setObjectReturn();
316 $s->excludeConfidential();
318 $info =
$s->getDebugInfo();
319 $out->error = $info[
"error"];
324 $ws->setValue(
"ba_title", sprintf(_(
"search %s") , $key));
326 $ws->addStaticQuery(
$s->getOriginalQuery());
328 $out->document = $tmpdoc->getDocument(
true,
false);
331 while ($doc =
$s->nextDoc()) {
332 $tmpdoc->affect($doc);
333 if ($verifyhaschild) {
334 $tmpdoc->setVolatileProperty(
"haschildfolder",
hasChildFld($this->dbaccess, $tmpdoc->getProperty(
'initid') , ($doc->doctype ==
'S')));
336 $content[$idx] = $tmpdoc->getDocument($onlyvalues, $completeprop);
341 $out->totalCount =
$s->count();
347 $out->totalCount =
$s->onlyCount();
348 $info =
$s->getDebugInfo();
350 $out->delay.=
' count:' . $info[
"delay"];
359 $out->date = date(
'Y-m-d H:i:s');
370 $fam = new_doc($this->dbaccess,
$famid);
371 if (!$fam->isAlive()) {
372 $out->error = sprintf(_(
"data:family %s not alive") ,
$famid);
373 } elseif ($fam->doctype !=
'C') {
374 $out->error = sprintf(_(
"data:document %s is not a family") ,
$famid);
378 $fld =
new Dir($this->dbaccess);
380 $tfam = $fld->GetChildFam(
$famid, $controlcreate);
381 if (count($tfam) > 0) {
384 $completeprop =
false;
385 foreach ($tfam as
$id => $rawfam) {
386 $fam->affect($rawfam);
387 $tmpdoc->affect($fam);
388 if (!$tmpdoc->error) {
389 $content[] = $tmpdoc->getDocument($onlyvalues, $completeprop);
412 $out->message = sprintf(_(
"document %d inserted") ,
$docid);
414 }
else $out->error = sprintf(_(
"document not set"));
431 $out->message = sprintf(_(
"document %d deleted") ,
$docid);
433 }
else $out->error = sprintf(_(
"document not set"));
444 include_once (
"DATA/Class.DocumentSelection.php");
446 $ids = $os->getIdentificators();
449 $out->notunlinked = array();
450 $out->unlinked = array();
451 $err = $this->doc->canModify();
455 foreach ($ids as
$docid) {
456 $err = $this->doc->delFile($docid);
460 $out->unlinked[
$docid] = sprintf(_(
"document %d unlinked") , $docid) .
"\n";
463 $out->unlinkedCount = count(
$out->unlinked);
464 $out->notUnlinkedCount = count(
$out->notunlinked);
466 }
else $out->error = sprintf(_(
"document not set"));
479 $err = $this->doc->canModify();
483 $out->error = $this->doc->clear();
485 }
else $out->error = sprintf(_(
"document not set"));
496 include_once (
"DATA/Class.DocumentSelection.php");
498 $ids = $os->getIdentificators();
501 $out->notmoved = array();
502 $out->moved = array();
503 $err = $this->doc->canModify();
505 $targetDoc = new_doc($this->dbaccess, $targetId);
506 if ($targetDoc->isAlive()) {
507 if ($targetDoc->defDoctype !=
'D')
$err = sprintf(_(
"target folder [%s] is not a folder") , $targetDoc->getTitle());
509 $err = $targetDoc->canModify();
512 $err = sprintf(_(
"target folder [%s] is not set") , $targetId);
517 foreach ($ids as
$docid) {
518 $err = $this->doc->moveDocument($docid, $targetDoc->initid);
522 $out->moved[
$docid] = sprintf(_(
"document %d moved") , $docid) .
"\n";
525 $out->movedCount = count(
$out->moved);
526 $out->notMovedCount = count(
$out->notmoved);
531 }
else $out->error = sprintf(_(
"document not set"));
542 include_once (
"DATA/Class.DocumentSelection.php");
545 $tdocs = $os->getRawDocuments();
546 $out->notinserted = array();
547 $out->inserted = array();
548 $err = $this->doc->insertMDoc($tdocs,
"latest",
false,
$out->inserted,
$out->notinserted);
549 $out->insertedCount = count(
$out->inserted);
550 $out->notInsertedCount = count(
$out->notinserted);
552 }
else $out->error = sprintf(_(
"document not set"));
559 if (method_exists($this->doc,
"getAuthorizedFamilies")) {
562 "restriction" => $this->doc->hasNoRestriction() ?
false :
true,
563 "families" => $this->doc->getAuthorizedFamilies()