11 const useAclDocumentType =
":useDocument";
12 const useAclAccountType =
":useAccount";
14 protected $alreadyExported = array();
16 protected $prevfromid = - 1;
17 protected $familyName =
'';
20 protected $encoding =
'utf-8';
21 protected $verifyAttributeAccess =
false;
22 protected $attributeGrants = array();
24 protected $exportAccountType = self::useAclAccountType;
26 private $logicalName = [];
36 $this->noAccessText = $noAccessText;
44 $this->verifyAttributeAccess = $verifyAttributeAccess;
51 $this->encoding = $encoding;
70 $this->alreadyExported = array();
77 static $htmlTransMapping =
false;
78 if (!$htmlTransMapping) {
80 $htmlTransMapping = get_html_translation_table(HTML_ENTITIES);
81 $htmlTransMapping = array_flip($htmlTransMapping);
82 $htmlTransMapping = array_map(
"utf8_encode", $htmlTransMapping);
84 return $htmlTransMapping;
89 if (!isset($this->logins[$uid])) {
90 simpleQuery(
"", sprintf(
"select login from users where id=%d", $uid) ,
$login,
true,
true);
93 return $this->logins[$uid];
97 if (!isset($this->logicalName[$uid])) {
98 simpleQuery(
"", sprintf(
"select name from docread where id=(select fid from users where id = %d)", $uid) , $logicalName,
true,
true);
99 $this->logicalName[$uid] = $logicalName ? $logicalName : 0;
101 return $this->logicalName[$uid];
112 $doc->acls[] =
"viewacl";
113 $doc->acls[] =
"modifyacl";
114 if (
$doc->name !=
"") $name =
$doc->name;
115 else $name =
$doc->id;
119 $q->AddQuery(sprintf(
"docid=%d",
$doc->profid));
120 $q->order_by =
"userid";
121 $acls =
$q->Query(0, 0,
"TABLE");
125 foreach ($acls as $va) {
127 $uid = $va[
"userid"];
130 $qvg = new \QueryDb(
$dbaccess,
"VGroup");
131 $qvg->AddQuery(sprintf(
"num=%d", $uid));
132 $tvu = $qvg->Query(0, 1,
"TABLE");
133 $uid = sprintf(
"attribute(%s)", $tvu[0][
"id"]);
135 if ($this->exportAccountType === self::useAclDocumentType) {
136 $uln = $this->getUserLogicalName($uid);
138 if (preg_match(
'/^attribute\(.*\)$/', $uln)) {
139 $uid = sprintf(
"document(%s)", $uln);
144 $uid = $this->getUserLogin($uid);
146 $uid = sprintf(
"account(%s)", $uid);
150 $uid = $this->getUserLogin($uid);
151 if (preg_match(
'/^attribute\(.*\)$/', $uid)) {
152 $uid = sprintf(
"account(%s)", $uid);
156 foreach (
$doc->acls as $kAcl => $acl) {
157 $bup = (
$doc->ControlUp($up, $acl) ==
"");
159 $tAcls[$kAcl .
"-" . $uid] = [
"uid" => $uid,
"acl" => $acl];
165 if (
$doc->extendedAcls) {
166 $extAcls = array_keys(
$doc->extendedAcls);
168 simpleQuery(
$dbaccess, sprintf(
"select * from docpermext where docid=%d and %s order by userid",
$doc->profid, $aclCond) , $eAcls);
170 foreach ($eAcls as $kAcl => $aAcl) {
171 $uid = $aAcl[
"userid"];
173 $qvg = new \QueryDb(
$dbaccess,
"VGroup");
174 $qvg->AddQuery(sprintf(
"num=%d", $uid));
175 $tvu = $qvg->Query(0, 1,
"TABLE");
176 $uid = sprintf(
"attribute(%s)", $tvu[0][
"id"]);
178 $uid = $this->getUserLogin($uid);
179 if (preg_match(
'/^attribute\(.*\)$/', $uid)) {
180 $uid = sprintf(
"account(%s)", $uid);
184 $tAcls[
"e".$kAcl .
"-" . $uid] = [
"uid" => $uid,
"acl" => $aAcl[
"acl"]];
188 if (count($tAcls) > 0) {
192 $this->exportAccountType,
196 foreach ($tAcls as $ku => $oneAcl) {
198 $data[] = sprintf(
"%s=%s", $oneAcl[
"acl"], $oneAcl[
"uid"]);
206 public function cvsExport(\
Doc &
$doc, &$ef, $fout, $wprof, $wfile, $wident, $wutf8, $nopref, $eformat)
208 $this->csvExport($doc, $ef, $fout, $wprof, $wfile, $wident, $wutf8, $nopref, $eformat);
210 public function csvExport(\
Doc &
$doc, &$ef, $fout, $wprof, $wfile, $wident, $wutf8, $nopref, $eformat)
214 if (in_array($doc->id, $this->alreadyExported))
return;
215 $this->alreadyExported[] = $doc->id;
223 if ($this->prevfromid != $doc->fromid) {
224 if (($eformat !=
"I") && ($this->prevfromid > 0)) {
228 if ($adoc->name !=
"") $this->familyName = $adoc->name;
229 else $this->familyName = $adoc->id;
230 if (!$this->familyName)
return;
231 $this->lattr = $adoc->GetExportAttributes($wfile, $nopref);
234 if ($eformat ==
"I") {
237 $adoc->title .
"(" . $this->familyName .
")",
244 foreach ($this->lattr as $attr) {
245 $data[] = $attr->getLabel();
249 WriteCsv::fput($fout,
$data);
251 if ($eformat ==
"I") {
259 foreach ($this->lattr as $attr) {
264 WriteCsv::fput($fout,
$data);
268 $this->prevfromid = $doc->fromid;
271 if ($doc->name !=
"" && $doc->locked != - 1) {
272 $docName = $doc->name;
274 if ($doc->locked != - 1) {
276 $docName = $doc->name;
278 }
else if ($wident) {
282 if ($eformat ==
"I") {
291 foreach ($this->lattr as $attr) {
292 if ($this->verifyAttributeAccess && !\Dcp\VerifyAttributeAccess::isAttributeAccessGranted($doc, $attr)) {
293 $data[] = $this->noAccessText;
297 if ($eformat ==
'F') {
298 if ($this->csvEnclosure) {
299 $value = str_replace(array(
307 $value = str_replace(array(
317 if (($attr->type ==
"image") || ($attr->type ==
"file")) {
320 foreach ($tfiles as $f) {
321 $ldir = $doc->id .
'-' . preg_replace(
'/[^a-zA-Z0-9_.-]/',
'_',
unaccent($doc->title)) .
"_D";
325 "path" => $f[
"path"],
330 $value = implode(
"\n", $tf);
331 }
else if ($attr->type ==
"docid" || $attr->type ==
"account" || $attr->type ==
"thesaurus") {
332 $docrevOption = $attr->getOption(
"docrev",
"latest");
334 if (strstr(
$value,
"\n") || ($attr->getOption(
"multiple") ==
"yes")) {
337 foreach (
$tid as $did) {
338 $brtid = explode(
"<BR>", $did);
340 foreach ($brtid as $brid) {
343 if ($docrevOption ===
"latest") {
346 addWarningMsg(sprintf(_(
"Doc %s : Attribut \"%s\" reference revised identifier : cannot use logical name") , $doc->
getTitle() , $attr->getLabel()));
353 $tn[] = implode(
'<BR>', $tnbr);
355 $value = implode(
"\n", $tn);
359 if ($docrevOption ===
"latest") {
362 addWarningMsg(sprintf(_(
"Doc %s : Attribut \"%s\" reference revised identifier : cannot use logical name") , $doc->
getTitle() , $attr->getLabel()));
367 }
else if ($attr->type ==
"htmltext") {
370 $value = preg_replace_callback(
'/(<img.*?src=")(((?=.*docid=(.*?)&)(?=.*attrid=(.*?)&)(?=.*index=(-?[0-9]+)))|(file\/(.*?)\/[0-9]+\/(.*?)\/(-?[0-9]+))).*?"/',
function ($matches) use (&$ef)
372 if (isset($matches[7])) {
374 $attrid = $matches[9];
375 $index = $matches[10] ==
"-1" ? 0 : $matches[10];
378 $index = $matches[6] ==
"-1" ? 0 : $matches[6];
379 $attrid = $matches[5];
384 $f = $tfiles[$index];
386 $ldir = $doc->id .
'-' . preg_replace(
'/[^a-zA-Z0-9_.-]/',
'_',
unaccent($doc->title)) .
"_D";
389 "path" => $f[
"path"],
393 return $matches[1] .
"file://" . $fname .
'"';
398 $trans = $this->getTrans();
399 $value = preg_replace_callback(
'/(\&[a-zA-Z0-9\#]+;)/s',
function ($matches) use ($trans)
401 return strtr($matches[1], $trans);
405 $value = preg_replace_callback(
'/\&#([0-9]+);/s',
function ($matches)
407 return chr($matches[1]);
415 $profid = ($doc->dprofid) ? $doc->dprofid : $doc->profid;
416 if ($profid == $doc->id) {
417 $this->exportProfil($fout, $doc->id);
418 }
else if ($profid > 0) {
421 if (!$dname) $dname = $doc->id;
422 if (!$name) $name = $profid;
423 if (!isset(
$tdoc[$profid])) {
424 $tdoc[$profid] =
true;
426 $this->csvExport($pdoc, $ef, $fout, $wprof, $wfile, $wident, $wutf8, $nopref, $eformat);
444 $availables = [self::useAclAccountType, self::useAclDocumentType];
445 if (!in_array($exportAccountType, $availables)) {
446 throw new Exception(
"PRFL0300", $exportAccountType, implode(
", ", $availables));
448 $this->exportAccountType = $exportAccountType;
vault_properties(NormalAttribute $attr)
setCsvSeparator($csvSeparator)
getHtmlAttrValue($attrid, $target="_self", $htmllink=2, $index=-1, $entities=true, $abstract=false)
setCsvEnclosure($csvEnclosure)
& getAttribute($idAttr, &$oa=null, $useMask=true)
csvExport(\Doc &$doc, &$ef, $fout, $wprof, $wfile, $wident, $wutf8, $nopref, $eformat)
static rawValueToArray($v)
Exception class use exceptionCode to identifiy correctly exception.
setNoAccessText($noAccessText)
getTitle($id="-1", $def="", $latest=false)
exportProfil($fout, $docid)
setVerifyAttributeAccess($verifyAttributeAccess)
setNameAuto($temporary=false)
new_Doc($dbaccess, $id= '', $latest=false)
cvsExport(\Doc &$doc, &$ef, $fout, $wprof, $wfile, $wident, $wutf8, $nopref, $eformat)
GetSqlCond($Table, $column, $integer=false)
getNameFromId($dbaccess, $id)
setExportAccountType($exportAccountType)
static fput($handler, array $data)
simpleQuery($dbaccess, $query, &$result=array(), $singlecolumn=false, $singleresult=false, $useStrict=null)
if($file) if($subject==""&&$file) if($subject=="") $err
getRawValue($idAttr, $def="")