19 include_once (
"FDL/Lib.Dir.php");
20 include_once (
"FDL/Lib.Util.php");
21 include_once (
"FDL/Class.DocAttr.php");
22 include_once (
"VAULT/Class.VaultFile.php");
23 include_once (
"FDL/import_file.php");
47 if ($eformat ==
"X") {
49 include_once (
"FDL/exportxmlfld.php");
53 if ((!
$fldid) && $selection) {
54 $selection = json_decode($selection);
55 include_once (
"DATA/Class.DocumentSelection.php");
56 include_once (
"FDL/Class.SearchDoc.php");
58 $ids = $os->getIdentificators();
60 $s->addFilter(getSqlCond($ids,
"id",
true));
64 if (!
$fldid) $action->exitError(_(
"no export folder specified"));
68 $fname = str_replace(array(
77 usort(
$tdoc,
"orderbyfromid");
80 $foutdir = uniqid(
getTmpDir() .
"/exportfld");
81 if (!mkdir($foutdir))
exit();
83 $foutname = $foutdir .
"/fdl.csv";
85 $foutname = uniqid(
getTmpDir() .
"/exportfld") .
".csv";
87 $fout = fopen($foutname,
"w");
91 if (count(
$tdoc) > 0) {
100 foreach (
$tdoc as $k => $zdoc) {
101 if (!is_array($zdoc))
continue;
102 if ($zdoc[
"doctype"] ==
"C") {
107 $doc->Affect($zdoc,
true);
112 $tmoredoc[$fp[
"id"]] = $fp;
113 if ($fp[
"name"] !=
"") $fpname = $fp[
"name"];
114 else $fpname = $fp[
"id"];
120 if ($cp[
"name"] !=
"") $cpname = $cp[
"name"];
121 else $cpname = $cp[
"id"];
122 $tmoredoc[$cp[
"id"]] = $cp;
124 if (
$doc->ccvid > 0) {
126 if ($cv[
"name"] !=
"") $cvname = $cv[
"name"];
127 else $cvname = $cv[
"id"];
128 $tmskid =
$doc->_val2array($cv[
"cv_mskid"]);
130 foreach ($tmskid as $kmsk => $imsk) {
133 if ($msk) $tmoredoc[$msk[
"id"]] = $msk;
137 $tmoredoc[$cv[
"id"]] = $cv;
142 if ($wdoc->name !=
"") $wname = $wdoc->name;
143 else $wname = $wdoc->id;
144 $tattr = $wdoc->getAttributes();
145 foreach ($tattr as $ka => $oa) {
146 if ($oa->type ==
"docid") {
147 $tdid = $wdoc->getTValue($ka);
148 foreach ($tdid as $did) {
152 $tmoredoc[$m[
"id"]] = $m;
153 if ($m[
"cv_mskid"] !=
'') {
154 $tmskid =
$doc->_val2array($m[
"cv_mskid"]);
155 foreach ($tmskid as $kmsk => $imsk) {
158 if ($msk) $tmoredoc[$msk[
"id"]] = $msk;
162 if ($m[
"tm_tmail"] !=
'') {
163 $tmskid =
$doc->_val2array(str_replace(
'<BR>',
"\n", $m[
"tm_tmail"]));
164 foreach ($tmskid as $kmsk => $imsk) {
167 if ($msk) $tmoredoc[$msk[
"id"]] = $msk;
178 if ($cvname || $wname || $cpname || $fpname) {
179 $send.=
"BEGIN;;;;;" .
$doc->name .
"\n";
180 if ($fpname) $send.=
"PROFID;" . $fpname .
"\n";
181 if ($cvname) $send.=
"CVID;" . $cvname .
"\n";
182 if ($wname) $send.=
"WID;" . $wname .
"\n";
183 if (
$doc->cprofid) $send.=
"CPROFID;" . $cpname .
"\n";
192 foreach (
$tdoc as $k => $zdoc) {
193 if ($cachedoc[$zdoc[
"fromid"]])
$doc = $cachedoc[$zdoc[
"fromid"]];
196 $doc = $cachedoc[$zdoc[
"fromid"]];
199 $doc->Affect($zdoc,
true);
201 if (
$doc->doctype !=
"C") {
202 exportonedoc(
$doc, $ef, $fout, $wprof, $wfile, $wident, $wutf8, $nopref, $eformat);
209 foreach ($ef as $info) {
210 $source = $info[
"path"];
211 $ddir = $foutdir .
'/' . $info[
"ldir"];
212 if (!is_dir($ddir)) mkdir($ddir);
213 $dest = $ddir .
'/' . $info[
"fname"];
214 if (!@copy($source,
$dest))
$err.= sprintf(_(
"cannot copy %s") ,
$dest);
216 if (
$err) $action->addWarningMsg(
$err);
217 system(sprintf(
"cd %s && zip -r fdl * > /dev/null", escapeshellarg($foutdir)) ,
$ret);
218 if (is_file(
"$foutdir/fdl.zip")) {
219 $foutname = $foutdir .
"/fdl.zip";
224 $action->exitError(_(
"Zip Archive cannot be created"));
235 if ($iso ===
true) $utf8 =
false;
238 if (!$utf8) fputs(
$r, utf8_decode(
$s));
245 if (
$a[
"fromid"] == $b[
"fromid"])
return 0;
246 if (
$a[
"fromid"] > $b[
"fromid"])
return 1;
258 if (!is_dir(
$dirname))
return false;
262 if (
$d = opendir($dcur)) {
263 while ($f = readdir(
$d)) {
264 if ($f ==
'.' || $f ==
'..')
continue;
265 $f = $dcur .
'/' . $f;
281 $doc->acls[] =
"viewacl";
282 $doc->acls[] =
"modifyacl";
286 $q->AddQuery(
"docid=" .
$doc->profid);
287 $acls =
$q->Query(0, 0,
"TABLE");
292 foreach ($acls as $va) {
295 $uid = $va[
"userid"];
297 foreach (
$doc->acls as $acl) {
298 $bup = (
$doc->ControlUp($up, $acl) ==
"");
299 $bun = (
$doc->ControlUp($un, $acl) ==
"");
304 $qvg->AddQuery(
"num=$uid");
305 $tvu = $qvg->Query(0, 1,
"TABLE");
306 $uid = $tvu[0][
"id"];
310 if ($bup) $tpa[] = $acl;
311 else $tpa[] =
"-" . $acl;
316 if (count($tpu) > 0) {
319 foreach ($tpu as $ku =>
$uid) {
330 if (
$u->isAffected()) {
332 if (($du[
"name"] !=
"") && ($du[
"us_whatid"] ==
$uid))
return $du[
"name"];
336 function exportonedoc(&
$doc, &$ef, $fout, $wprof, $wfile, $wident, $wutf8, $nopref, $eformat)
338 static $prevfromid = - 1;
340 static $trans =
false;
342 static $alreadyExported = array();
344 if (!
$doc->isAffected())
return;
345 if (in_array(
$doc->id, $alreadyExported))
return;
346 $alreadyExported[] =
$doc->id;
350 $trans = get_html_translation_table(HTML_ENTITIES);
351 $trans = array_flip($trans);
352 $trans = array_map(
"utf8_encode", $trans);
356 if ($prevfromid !=
$doc->fromid) {
357 if (($eformat !=
"I") && ($prevfromid > 0))
fputs_utf8($fout,
"\n");
358 $adoc =
$doc->getFamDoc();
359 if ($adoc->name !=
"") $fromname = $adoc->name;
360 else $fromname = $adoc->id;
361 if (!$fromname)
return;
362 $lattr = $adoc->GetExportAttributes($wfile, $nopref);
363 if ($eformat ==
"I")
fputs_utf8($fout,
"//FAM;" . $adoc->title .
"(" . $fromname .
");<specid>;<fldid>;");
364 foreach (
$lattr as $ka => $attr) {
368 if ($eformat ==
"I") {
369 fputs_utf8($fout,
"ORDER;" . $fromname .
";;;");
370 foreach (
$lattr as $ka => $attr) {
375 $prevfromid =
$doc->fromid;
384 if ($eformat ==
"I")
fputs_utf8($fout,
"DOC;" . $fromname .
";" .
$name .
";" . $efldid .
";");
386 foreach (
$lattr as $ka => $attr) {
387 if ($eformat ==
'F')
$value = str_replace(array(
390 ) ,
'\\n',
$doc->getHtmlAttrValue($attr->id,
'',
false, -1,
false));
393 if (($attr->type ==
"image") || ($attr->type ==
"file")) {
394 $tfiles =
$doc->vault_properties($attr);
396 foreach ($tfiles as $f) {
401 "path" => $f[
"path"],
406 $value = implode(
"\n",
$tf);
407 }
else if ($attr->type ==
"docid") {
409 if (strstr($value,
"\n") || ($attr->getOption(
"multiple") ==
"yes")) {
412 foreach (
$tid as $did) {
413 $brtid = explode(
"<BR>", $did);
415 foreach ($brtid as $brid) {
417 if ($n) $tnbr[] = $n;
418 else $tnbr[] = $brid;
420 $tn[] = implode(
'<BR>', $tnbr);
422 $value = implode(
"\n", $tn);
429 $value = preg_replace(
"/(\&[a-zA-Z0-9\#]+;)/es",
"strtr('\\1',\$trans)", $value);
431 $value = preg_replace(
"/\&#([0-9]+);/es",
"chr('\\1')", $value);
447 else if (
$doc->profid > 0) {
450 if (!$dname) $dname =
$doc->id;
455 exportonedoc($pdoc, $ef, $fout, $wprof, $wfile, $wident, $wutf8, $nopref, $eformat);