11 use \Dcp\AttributeIdentifiers\Report as MyAttributes;
20 "FREEDOM:VIEWMINIREPORT:T"
34 "title" => _(
"doctitle") ,
35 "revdate" => _(
"revdate") ,
36 "id" => _(
"document id") ,
37 "revision" => _(
"revision") ,
38 "state" => _(
"step") ,
47 public function editreport()
50 $action->parent->AddJsRef($action->GetParam(
"CORE_JSURL") .
"/selectbox.js");
51 $action->parent->AddJsRef($action->GetParam(
"CORE_PUBURL") .
"/FREEDOM/Layout/editreport.js");
53 $rfamid = GetHttpVars(
"sfamid", $this->
getRawValue(
"SE_FAMID", 1));
54 $rdoc =
createDoc($this->dbaccess, $rfamid,
false);
55 if ($rdoc ===
false) {
58 $lattr = $rdoc->GetNormalAttributes();
64 foreach ($lattr as $k => $v) {
66 $tcolumn1[$v->id] = array(
68 "alabel" => $v->getLabel()
74 foreach ($tinternals as $k => $v) {
75 $tinternals[$k] = array(
83 foreach ($tcols as $k => $vx) {
84 if (isset($tcolumn1[$vx])) {
85 $tcolumn2[$vx] = $tcolumn1[$vx];
86 unset($tcolumn1[$vx]);
88 if (isset($tinternals[$vx])) {
89 $tcolumn2[$vx] = $tinternals[$vx];
90 unset($tinternals[$vx]);
94 $this->lay->setBlockData(
"COLUMN1", $tcolumn1);
95 $this->lay->setBlockData(
"INTERNALS", $tinternals);
97 $this->lay->setBlockData(
"COLUMN2", $tcolumn2);
103 public function reportchoosecolumns($target =
"_self", $ulink =
true, $abstract =
false)
107 $action->parent->addJsRef(
"lib/jquery/jquery.js");
109 $doc = new_doc($this->dbaccess, $this->
getRawValue(MyAttributes::se_famid));
110 $toa =
$doc->getNormalAttributes();
115 $proFrame = new \FieldSetAttribute(
"_prop",
$doc->id, _(
"Document Properties"));
117 foreach ($colums as $k => $col) {
120 $proAttr[$colId] = new \NormalAttribute($colId,
$doc->id, _(\
Doc::$infofields[$colId][
"label"]) ,
"text",
"",
false, $k,
"",
"R",
false,
false,
false, $proFrame,
"",
"",
"");
123 $toa = array_merge($proAttr, $toa);
141 foreach ($toa as $oa) {
143 if ($oa->type ==
"array")
continue;
145 $struct = $oa->fieldSet->id;
147 $structTab = $structFrame = $structArray =
'';
149 $soa =
$doc->getAttribute($struct);
150 if ($struct ==
'_prop') {
153 $structArray = $structFrame = $structTab =
'';
154 if ($soa->type ==
"array") {
155 $structArray = $soa->id;
156 }
else if ($soa->type ==
"frame") {
157 $structFrame = $soa->id;
159 if (isset($soa->fieldSet) && $soa->fieldSet->id != \Adoc::HIDDENFIELD) {
160 if ($soa->fieldSet->type ==
"tab") {
161 $structTab = $soa->fieldSet->id;
163 if ($soa->fieldSet->type ==
"frame") {
164 $structFrame = $soa->fieldSet->id;
165 if (isset($soa->fieldSet->fieldSet) && $soa->fieldSet->fieldSet->type ==
"tab") {
166 $structTab = $soa->fieldSet->fieldSet->id;
171 if ($currentStruct) {
172 $soa =
$doc->getAttribute($currentStruct);
173 if ($currentStruct ==
'_prop') {
176 $currentArray = $currentFrame = $currentTab =
'';
177 if ($soa->type ==
"array") {
178 $currentArray = $soa->id;
179 }
else if ($soa->type ==
"frame") {
180 $currentFrame = $soa->id;
182 if (isset($soa->fieldSet) && $soa->fieldSet->id != \Adoc::HIDDENFIELD) {
183 if ($soa->fieldSet->type ==
"tab") {
184 $currentTab = $soa->fieldSet->id;
186 if ($soa->fieldSet->type ==
"frame") {
187 $currentFrame = $soa->fieldSet->id;
188 if (isset($soa->fieldSet->fieldSet) && $soa->fieldSet->fieldSet->type ==
"tab") {
189 $currentTab = $soa->fieldSet->fieldSet->id;
195 if ($structArray != $currentArray && $currentArray) {
196 $tattr[] = $this->getColumnBlockItem(
$doc, $currentArray,
false);
198 if ($structFrame != $currentFrame && $currentFrame) {
199 $tattr[] = $this->getColumnBlockItem(
$doc, $currentFrame,
false);
201 if ($structTab != $currentTab && $currentTab) {
202 $tattr[] = $this->getColumnBlockItem(
$doc, $currentTab,
false);
204 if ($structTab != $currentTab && $structTab) {
206 $tattr[] = $this->getColumnBlockItem(
$doc, $structTab,
true);
208 if ($structFrame != $currentFrame && $structFrame) {
209 $tattr[] = $this->getColumnBlockItem(
$doc, $structFrame,
true);
211 if ($structArray != $currentArray && $structArray) {
212 $tattr[] = $this->getColumnBlockItem(
$doc, $structArray,
true);
224 "need" => $oa->needed,
225 "hidden" => $oa->visibility ==
'H',
226 "attrname" => htmlspecialchars($oa->getLabel())
228 if (in_array($oa->type, $relTypes)) {
231 "doption" =>
'docid',
239 "need" => $oa->needed,
240 "hidden" => $oa->visibility ==
'H',
241 "attrname" => htmlspecialchars($oa->getLabel()) .
'<i> (' . _(
"report:docid") .
')</i>'
246 $currentStruct = $struct;
250 $tattr[] = $this->getColumnBlockItem(
$doc, $structArray,
false);
253 $tattr[] = $this->getColumnBlockItem(
$doc, $structFrame,
false);
256 $tattr[] = $this->getColumnBlockItem(
$doc, $structTab,
false);
259 $this->lay->setBlockData(
"ATTRS", $tattr);
260 $this->lay->set(
"famid",
$doc->id);
261 $this->lay->set(
"famtitle",
$doc->getHtmlTitle());
262 $this->lay->set(
"famicon",
$doc->getIcon(
"", 48));
265 protected function getColumnBlockItem(\
Doc &
$doc, $attrid, $isNew)
271 if ($attrid ==
"_prop") {
272 $soa = new \FieldSetAttribute(
"_prop", $doc->id, _(
"Document Properties"));
275 "attrid" => $soa->id,
278 "newframe" => $isNew && $soa->type ==
"frame",
279 "newtab" => $isNew && $soa->type ==
"tab",
280 "newarray" => $isNew && $soa->type ==
"array",
281 "endframe" => (!$isNew) && $soa->type ==
"frame",
282 "endtab" => (!$isNew) && $soa->type ==
"tab",
283 "endarray" => (!$isNew) && $soa->type ==
"array",
284 "need" => isset($soa->needed) && $soa->needed,
285 "hidden" => $soa->visibility ==
'H',
287 "attrname" => $soa->getLabel()
298 public function viewreport($target =
"_self", $ulink =
true, $abstract =
false)
301 $this->
viewattr($target, $ulink, $abstract);
302 $this->
viewprop($target, $ulink, $abstract);
303 $action->parent->AddCssRef(
"FREEDOM:viewreport.css",
true);
304 $action->parent->AddJsRef($action->GetParam(
"CORE_PUBURL") .
"/FREEDOM/Layout/sorttable.js");
308 $rdoc =
createDoc($this->dbaccess, $rfamid,
false);
309 if ($rdoc ===
false) {
310 $err = sprintf(_(
'Family [%s] not found') , $rfamid);
311 $this->lay->template = htmlspecialchars(
$err, ENT_QUOTES);
312 $this->lay->noparse =
true;
315 $lattr = $rdoc->GetNormalAttributes();
318 foreach ($lattr as $k => $v) {
320 $tcolumn1[$v->id] = array(
323 "rightfornumber" => ($v->type ==
"money") ?
"right" :
"left"
328 foreach ($tinternals as $k => $v) {
329 $tcolumn1[$k] = array(
332 "rightfornumber" =>
"left"
338 foreach ($tcols as $k => & $vcol) {
340 $tcolumn2[$k] = isset($tcolumn1[$vcol]) ? $tcolumn1[$vcol] : null;
341 if ($tDisplayOption[$k] ==
"docid") {
342 $tcolumn2[$k][
"collabel"].=
' (' . _(
"report:docid") .
')';
350 $this->lay->setBlockData(
"COLS", $tcolumn2);
351 $this->lay->set(
"HASCOLS", count($tcolumn2) > 0);
352 include_once (
"FDL/Lib.Dir.php");
354 $this->lay->set(
"reportstyle", $this->
getRawValue(
"REP_STYLE",
"perso"));
355 $this->lay->set(
"isperso", ($this->
getRawValue(
"REP_STYLE",
"perso") ==
"perso"));
357 $this->lay->setBlockData(
"PARAMS", array(
366 $order = $this->
getRawValue(
"REP_IDSORT",
"title");
367 $oa = $rdoc->getAttribute($order);
369 if (($oa->type ==
"docid") && ($oa->getOption(
"doctitle") !=
"")) {
370 $order = $oa->getOption(
"doctitle");
371 if ($order ==
'auto') $order = $oa->id .
'_title';
374 $order.=
" " . $this->
getRawValue(
"REP_ORDERSORT");
375 $s = new \SearchDoc($this->dbaccess, $this->
getRawValue(
"se_famid"));
376 $s->useCollection($this->initid);
377 $s->setOrder($order);
378 $s->returnsOnly($tcols);
379 $s->setObjectReturn();
380 $limit = intval($limit);
382 if ($limit == 0) $limit = $maxDisplayLimit;
383 else $limit = min($limit, $maxDisplayLimit);
384 $s->setSlice($limit);
399 $needRemoveLast =
false;
400 if (
$s->count() >= $maxDisplayLimit) {
401 addWarningMsg(sprintf(_(
"Max display limit %s reached. Use export to see all") , $maxDisplayLimit - 1));
402 $needRemoveLast =
true;
409 while ($rdoc =
$s->getNextDoc()) {
413 "docid" => $rdoc->id,
414 "troddoreven" => $trodd ?
"trodd" :
"treven"
422 foreach ($tcolumn2 as $ki => $vc) {
424 if ($rdoc->getRawValue($kc) ==
"") $tcell[$ki] = array(
432 $cval = (date(
"Y-m-d H:i:s", $rdoc->getRawValue($kc)));
438 $cval = $rdoc->getStatelabel();
443 $cval = $rdoc->getDocAnchor($rdoc->id,
'rdoc' . $rdoc->id,
true,
false,
true,
"fixed");
445 $cval = $rdoc->getHtmlTitle();
450 if ($tDisplayOption[$ki] ==
"docid") {
452 $cval = $rdoc->getRawValue($kc);
454 $cval = $rdoc->getPropertyValue($kc);
455 if ($cval ===
false) {
457 $cval = $rdoc->getHtmlValue($lattr[$kc], $rdoc->getRawValue($kc) , $target, $ulink);
460 if (isset($lattr[$kc]) && $lattr[$kc]->type ==
"image") {
461 $cval =
"<img width=\"40px\" src=\"$cval\">";
467 "rawval" => $rdoc->getRawValue($kc)
476 $tcell[$ki][
"bgcell"] = current($tcolor);
478 $tcell[$ki][
"tdoddoreven"] = $tdodd ?
"tdodd" :
"tdeven";
479 $tcell[$ki][
"rightfornumber"] = (isset($lattr[$kc]) && $lattr[$kc]->type ==
"money") ?
"right" :
"left";
482 $this->lay->setBlockData(
"row$k", $tcell);
485 if ($needRemoveLast) array_pop($trow);
486 $this->lay->setBlockData(
"ROWS", $trow);
491 foreach ($tfoots as $k => $v) {
501 foreach ($trow as $kr => $vr) {
502 $ctr = $this->lay->getBlockData($vr[
"CELLS"]);
503 if (isset($ctr[$k][
"rawval"])) $val+= $ctr[$k][
"rawval"];
505 if ($v ==
"MOY") $val = $val / count($trow);
509 if (isset($lattr[$tcols[$k]])) {
510 $val = $rdoc->getHtmlValue($lattr[$tcols[$k]], $val, $target, $ulink);
518 if (isset($tcolumn2[$k])) {
519 $footRight = $tcolumn2[$k][
"rightfornumber"];
523 "rightfornumber" => $footRight
526 $this->lay->setBlockData(
"TFOOT", $tlfoots);
539 public function generateCSVReportStruct($isPivotExport =
false, $pivotId =
"id", $separator =
".", $dateFormat =
"US", $refresh =
true, $stripHtmlTags =
false, $renderNumber =
"format")
541 require_once
'WHAT/Class.twoDimensionalArray.php';
542 require_once
'FDL/Class.SearchDoc.php';
546 $order = $this->
getRawValue(
"rep_idsort",
"title");
548 $mb0 = microtime(
true);
549 $this->
setStatus(_(
"Doing search request"));
559 $searchCols = $tcols;
560 $searchCols[] =
"cvid";
561 $searchCols[] =
"wid";
562 $search->returnsOnly($searchCols);
564 if ($isPivotExport) {
567 return $this->
generatePivotCSV(
$search, $tcols, $famDoc, $pivotId, $refresh, $separator, $dateFormat, $stripHtmlTags, $renderNumber);
570 return $this->
generateBasicCSV(
$search, $tcols, $tcolsOption, $famDoc, $refresh, $separator, $dateFormat, $stripHtmlTags, $renderNumber);
577 $expVarName = $action->getParam(
"exportSession");
578 if ($expVarName) $action->Register($expVarName, array(
585 $convertFormat = array(
586 "dateFormat" => $dateFormat,
587 'decimalSeparator' => $separator,
588 'stripHtmlTags' => $stripHtmlTags,
589 'renderNumber' => $renderNumber
592 $pivotColumnName = uniqid();
594 $singleAttributes = array();
595 $multipleAttributes = array();
596 $resultSingleArray = array();
597 $resultMultipleArray = array();
601 $resultSingleArray[$pivotColumnName] = array();
603 foreach ($columns as $currentColumnID) {
604 $attributeObject = $famDoc->
getAttribute($currentColumnID);
605 if (!$attributeObject) {
606 $singleAttributes[] = $currentColumnID;
607 $resultSingleArray[$currentColumnID] = array();
608 } elseif ($attributeObject->isMultiple()) {
609 if ($attributeObject->getOption(
'multiple') ==
"yes" && !$attributeObject->inArray()) {
610 $multipleAttributes[$currentColumnID] = array();
611 $multipleAttributes[$currentColumnID][] = $currentColumnID;
612 $resultMultipleArray[$currentColumnID] = array();
613 $resultMultipleArray[$currentColumnID][$pivotColumnName] = array();
614 $resultMultipleArray[$currentColumnID][$currentColumnID] = array();
616 $arrayID = $attributeObject->fieldSet->id;
617 if (!isset($multipleAttributes[$arrayID])) {
618 $multipleAttributes[$arrayID] = array();
619 $resultMultipleArray[$arrayID] = array();
620 $resultMultipleArray[$arrayID][$pivotColumnName] = array();
622 $multipleAttributes[$arrayID][] = $currentColumnID;
623 $resultMultipleArray[$arrayID][$currentColumnID] = array();
626 $singleAttributes[] = $currentColumnID;
627 $resultSingleArray[$currentColumnID] = array();
631 $nbDoc = $search->
count();
635 if ($k % 10 == 0) $this->
setStatus(sprintf(_(
"Pivot rendering %d/%d") , $k, $nbDoc));
637 $currentDoc->refresh();
641 $resultSingleArray[$pivotColumnName][] = $pivotValue;
642 foreach ($singleAttributes as $currentColumnID) {
643 $currentAttribute = $famDoc->
getAttribute($currentColumnID);
644 $resultSingleArray[$currentColumnID][] = $currentAttribute ? $this->
getCellValue($currentDoc, $currentAttribute, $convertFormat) : $this->
convertInternalElement($currentColumnID, $currentDoc);
647 foreach ($multipleAttributes as $currentKey => $currentArrayID) {
648 foreach ($currentArrayID as $currentColumnID) {
649 $currentAttribute = $famDoc->
getAttribute($currentColumnID);
650 $nbElement = count($currentDoc->getMultipleRawValues($currentColumnID));
651 for ($i = 0; $i < $nbElement; $i++) {
652 $resultMultipleArray[$currentKey][$currentColumnID][] = $this->
getCellValue($currentDoc, $currentAttribute, $convertFormat, $i);
655 for ($i = 0; $i < $nbElement; $i++) {
656 $resultMultipleArray[$currentKey][$pivotColumnName][] = $pivotValue;
662 $twoDimStruct = new \TwoDimensionStruct();
664 $firstRow[] = _(
"REPORT_pivot");
665 $twoDimStruct->addColumn($resultSingleArray[$pivotColumnName]);
667 foreach ($singleAttributes as $currentColumnID) {
668 $currentAttribute = $famDoc->
getAttribute($currentColumnID);
669 $firstRow[] = $currentAttribute ? $currentAttribute->getLabel() : $internals[$currentColumnID];
670 $twoDimStruct->addColumn($resultSingleArray[$currentColumnID]);
673 foreach ($multipleAttributes as $currentKey => $currentArrayID) {
678 $twoDimStruct->addColumn($emptyArray);
679 $firstRow[] = _(
"REPORT_pivot");
680 $twoDimStruct->addColumn($resultMultipleArray[$currentKey][$pivotColumnName]);
681 foreach ($currentArrayID as $currentColumnID) {
682 $currentAttribute = $famDoc->
getAttribute($currentColumnID);
683 $firstRow[] = $currentAttribute ? $currentAttribute->getLabel() : $internals[$currentColumnID];
684 $twoDimStruct->addColumn($resultMultipleArray[$currentKey][$currentColumnID]);
688 if ($twoDimStruct->insertRow(0, $firstRow,
true) == null) {
689 var_export($twoDimStruct->getLastErrorMessage());
692 return $twoDimStruct->getArray();
708 protected function generateBasicCSV(\
SearchDoc $search, Array $columns, Array $displayOptions, \
Doc $famDoc, $refresh, $separator, $dateFormat, $stripHtmlFormat =
true, $renderNumber =
"format")
710 $fc = new \FormatCollection();
712 $fc->useCollection($dl);
714 $htmlNoAccess = new \DOMDocument();
717 $fc->setNoAccessText(trim($htmlNoAccess->textContent));
718 if ($separator)
$fc->setDecimalSeparator($separator);
719 $fc->relationIconSize = 0;
720 $fc->stripHtmlTags($stripHtmlFormat);
721 switch ($dateFormat) {
734 $isAttrInArray = array();
735 foreach ($columns as $k => $col) {
740 $fc->addAttribute($col);
741 $isAttrInArray[$col] = $famDoc->
getAttribute($col)->inArray();
743 $fc->addProperty($col);
748 $fc->setLongtextMultipleBrToCr(
" ");
750 $fc->setHookAdvancedStatus(
function (
$s)
758 foreach ($columns as $kc => $col) {
762 $line[$kc] = $famDoc->
getLabel($col);
763 if ($displayOptions[$kc] ==
"docid") $line[$kc].=
' (' . _(
"report:docid") .
')';
767 foreach (
$r as $k => $render) {
769 foreach ($columns as $kc => $col) {
771 if (isset($render[
"attributes"][$col])) {
774 'displayDocId' => ($displayOptions[$kc] ==
"docid") ,
775 'stripHtmlTags' => $stripHtmlFormat
777 if ($renderNumber ===
"raw" && in_array($oa->type, array(
782 if (is_array($render[
"attributes"][$col])) {
784 foreach ($render[
"attributes"][$col] as $arender) {
785 $oneValue = $arender->value;
787 $oneValue = str_replace(
".", $separator, $oneValue);
789 $numValues[] = $oneValue;
791 $cellValue = implode(
"\n", $numValues);
793 $cellValue = $render[
"attributes"][$col]->value;
795 $cellValue = str_replace(
".", $separator, $cellValue);
800 if (isset($render[
"properties"][$col])) {
801 $cellValue = $render[
"properties"][$col];
802 if (is_object($cellValue)) {
803 $cellValue = $cellValue->displayValue;
807 $line[] = $cellValue;
816 switch ($internalName) {
818 return strftime(
"%x %T", $doc->
getRawValue($internalName));
839 public function viewminireport($target =
"_self", $ulink =
true, $abstract =
false)
841 $this->
viewreport($target, $ulink, $abstract);
& getAttribute($idAttr, &$oa=null, $useMask=true)
convertInternalElement($internalName,\Doc $doc)
static isAttributeAccessGranted(\Doc $doc,\BasicAttribute $attribute)
generateCSVReportStruct($isPivotExport=false, $pivotId="id", $separator=".", $dateFormat="US", $refresh=true, $stripHtmlTags=false, $renderNumber="format")
viewattr($target="_self", $ulink=true, $abstract=false, $viewhidden=false)
getReportColumns($dbaccess, $famid, $name="")
getCellValue(\Doc $doc,\BasicAttribute $oa, $format, $index=-1)
getFamilyParameterValue($idp, $def="")
generatePivotCSV(\SearchDoc $search, Array $columns,\Doc $famDoc, $pivotId, $refresh, $separator, $dateFormat, $stripHtmlTags, $renderNumber="format")
generateBasicCSV(\SearchDoc $search, Array $columns, Array $displayOptions,\Doc $famDoc, $refresh, $separator, $dateFormat, $stripHtmlFormat=true, $renderNumber="format")
viewprop($target="_self", $ulink=true, $abstract=false)
viewminireport($target="_self", $ulink=true, $abstract=false)
viewreport($target="_self", $ulink=true, $abstract=false)
getMultipleRawValues($idAttr, $def="", $index=-1)
createDoc($dbaccess, $fromid, $control=true, $defaultvalues=true, $temporary=false)
getHTMLTitle($id="-1", $def="", $latest=false)
getTextualValue(Doc $doc, $index=-1, Array $configuration=array())
new_Doc($dbaccess, $id= '', $latest=false)
createTmpDoc($dbaccess, $fromid, $defaultvalue=true)
if($file) if($subject==""&&$file) if($subject=="") $err
getRawValue($idAttr, $def="")