7 require_once
'FDL/Class.Doc.php';
8 require_once
'FDL/freedom_util.php';
9 require_once
'EXTERNALS/fdl.php';
36 $argumentsCSV = array();
37 $defaultArgument = json_decode(
getParam(
"REPORT_DEFAULT_CSV",
"[]") ,
true);
38 $action->parent->addJsRef(
"lib/jquery/jquery.js");
41 $defaultDocArg = array();
43 $id =
$usage->addRequiredParameter(
"id",
"the id of the report");
47 $currentUserTag = $currentDoc->getUTag(
"document_export_csv");
48 if ($currentUserTag) $defaultDocArg = json_decode($currentUserTag->comment,
true);
51 $csvTmpFile =
$usage->addHiddenParameter(
"csvDownloadFile",
"tmp file to download");
52 $expVarName =
$usage->addHiddenParameter(
"exportId",
"expert ident");
53 $statusOnly =
$usage->addHiddenParameter(
"statusOnly",
"get status only");
55 $refresh = (
$usage->addOptionalParameter(
"refresh",
"would you refresh doc before build report", array(
58 ) ,
"FALSE") ==
"TRUE");
60 $default = isset($defaultDocArg[
"kind"]) ? $defaultDocArg[
"kind"] :
'simple';
61 $kind =
$usage->addOptionalParameter(
"kind",
"the kind of report", array(
65 $default = isset($defaultDocArg[
"pivot"]) ? $defaultDocArg[
"pivot"] :
'id';
66 $pivot =
$usage->addOptionalParameter(
"pivot",
"the pivot attr", array() , $default);
68 $default = isset($defaultDocArg[
"stripHtmlTag"]) ? $defaultDocArg[
"stripHtmlTag"] :
false;
69 $applyHtmlStrip =
$usage->addOptionalParameter(
"stripHtmlTag",
"strip html tags", array() , $default);
70 $applyHtmlStrip = ($applyHtmlStrip !=
"1");
72 $default = isset($defaultArgument[
"delimiter"]) ? $defaultArgument[
"delimiter"] :
';';
73 $argumentsCSV[
"delimiter"] =
$usage->addOptionalParameter(
"delimiter",
"the CSV delimiter", array() , $default);
74 $default = isset($defaultArgument[
"enclosure"]) ? $defaultArgument[
"enclosure"] :
'"';
75 $argumentsCSV[
"enclosure"] =
$usage->addOptionalParameter(
"enclosure",
"the CSV enclosure", array() , $default);
76 $default = isset($defaultArgument[
"encoding"]) ? $defaultArgument[
"encoding"] :
'ISO-8859-15//TRANSLIT';
77 $argumentsCSV[
"encoding"] =
$usage->addOptionalParameter(
"encoding",
"the CSV encoding", array() , $default);
78 $default = isset($defaultArgument[
"decimalSeparator"]) ? $defaultArgument[
"decimalSeparator"] :
'.';
79 $argumentsCSV[
"decimalSeparator"] =
$usage->addOptionalParameter(
"decimalSeparator",
"the decimalSeparator", array() , $default);
80 $default = isset($defaultArgument[
"dateFormat"]) ? $defaultArgument[
"dateFormat"] :
'US';
82 $argumentsCSV[
"dateFormat"] =
$usage->addOptionalParameter(
"dateFormat",
"the dateFormat", array(
88 $default = isset($defaultArgument[
"numericRender"]) ? $defaultArgument[
"numericRender"] :
'raw';
89 $argumentsCSV[
"numericRender"] =
$usage->addOptionalParameter(
"numericRender",
"the number render", array(
94 $displayForm =
$usage->addHiddenParameter(
"displayForm",
"");
95 $updateDefault =
$usage->addHiddenParameter(
"updateDefault",
"");
97 $usage->setStrictMode(
false);
99 $usageArguments = array(
119 $addedArguments = array();
122 if (!in_array($key, $usageArguments)) {
123 $addedArguments[] = array(
124 "argumentName" => $key,
130 $action->lay->eSetBlockData(
"addedArguments", $addedArguments);
134 $fileName = sprintf(
"%s_%s.%s", $currentDoc->getTitle() , date(
"Y_m_d-H_m_s") ,
"csv");
138 if ($statusOnly && $expVarName) {
139 header(
'Content-Type: application/json');
140 $action->lay->noparse =
true;
141 $action->lay->template = json_encode($action->read($expVarName));
144 if ($updateDefault) {
145 $action->
setParamU(
"REPORT_DEFAULT_CSV", json_encode($argumentsCSV));
146 $err = $currentDoc->addUTag($action->user->id,
"document_export_csv", json_encode(array(
149 "stripHtmlTag" => $applyHtmlStrip
152 error_log(__LINE__ . var_export(
$err,
true));
157 $action->lay->set(
"id", $currentDoc->id);
158 $expVarName = uniqid(
"EXPCSV");
159 $action->lay->eset(
"exportId", $expVarName);
160 $action->
Register($expVarName, array(
164 $attributeLay = array();
165 $attributeLay[] = array(
168 "libelle" => _(
"EXPORT_CSV : identifiant unique")
171 $isSelected =
function ($currentValue, $selectedValue)
173 return $currentValue == $selectedValue ?
"selected='selected'" :
"";
176 foreach ($attr as $currentAttr) {
177 $attributeLay[] = array(
178 "key" => $currentAttr[1],
179 "libelle" => strip_tags($currentAttr[0]) ,
180 "selected" => $isSelected($currentAttr[1], $pivot) ,
184 $action->lay->setBlockData(
"pivotAttribute", $attributeLay);
189 "selected" => $isSelected(
"simple", $kind) ,
190 "label" => _(
"EXPORT_CSV Simple")
194 "selected" => $isSelected(
"pivot", $kind) ,
195 "label" => _(
"EXPORT_CSV pivot")
198 $action->lay->setBlockData(
"kinds", $kinds);
203 "selected" => $isSelected(
"0", $applyHtmlStrip) ,
204 "label" => _(
"Strip Html tags")
208 "selected" => $isSelected(
"1", $applyHtmlStrip) ,
209 "label" => _(
"No strip Html tags")
212 $action->lay->setBlockData(
"stripHtml", $stripHtml);
217 "selected" => $isSelected(
"UTF-8", $argumentsCSV[
"encoding"]) ,
218 "label" => _(
"EXPORT_CSV utf8")
221 "key" =>
"ISO-8859-15//TRANSLIT",
222 "selected" => $isSelected(
"ISO-8859-15//TRANSLIT", $argumentsCSV[
"encoding"]) ,
223 "label" => _(
"EXPORT_CSV ISO-8859-15 (european)")
226 $action->lay->setBlockData(
"encodings", $encodings);
228 $dateFormats = array(
231 "selected" => $isSelected(
"US", $argumentsCSV[
"dateFormat"]) ,
232 "label" => _(
"EXPORT_CSV Date format US")
236 "selected" => $isSelected(
"FR", $argumentsCSV[
"dateFormat"]) ,
237 "label" => _(
"EXPORT_CSV Date format FR")
241 "selected" => $isSelected(
"ISO", $argumentsCSV[
"dateFormat"]) ,
242 "label" => _(
"EXPORT_CSV Date format ISO")
245 $action->lay->setBlockData(
"dateFormats", $dateFormats);
247 $numericRender = array(
250 "selected" => $isSelected(
"raw", $argumentsCSV[
"numericRender"]) ,
251 "label" => _(
"EXPORT_CSV raw numbers")
255 "selected" => $isSelected(
"format", $argumentsCSV[
"numericRender"]) ,
256 "label" => _(
"EXPORT_CSV formatted numbers ")
259 $action->lay->setBlockData(
"numericRender", $numericRender);
261 $action->lay->eset(
"delimiter", $argumentsCSV[
"delimiter"]);
262 $action->lay->eset(
"enclosure", $argumentsCSV[
"enclosure"]);
263 $action->lay->eset(
"decimalSeparator", $argumentsCSV[
"decimalSeparator"]);
266 $action->parent->setVolatileParam(
"exportSession", $expVarName);
272 $familyIdArray = $currentDoc->getFromDoc();
273 if (in_array($reportFamId, $familyIdArray)) {
276 $csvStruct = $currentDoc->generateCSVReportStruct(
true, $pivot, $argumentsCSV[
"decimalSeparator"], $argumentsCSV[
"dateFormat"], $refresh, $applyHtmlStrip, $argumentsCSV[
"numericRender"]);
280 $csvStruct = $currentDoc->generateCSVReportStruct(
false,
"", $argumentsCSV[
"decimalSeparator"], $argumentsCSV[
"dateFormat"], $refresh, $applyHtmlStrip, $argumentsCSV[
"numericRender"]);
283 if ($csvFile ===
false) {
284 $err = sprintf(_(
"Error creating temporary file in '%s'.") ,
getTmpDir());
287 $fp = fopen($csvFile,
'w');
289 foreach ($csvStruct as $currentLine) {
290 $encoding = $argumentsCSV[
"encoding"];
291 if ($encoding !=
"UTF-8") {
292 $currentLine =
convertLine($currentLine, $encoding);
294 fputcsv($fp, $currentLine, $argumentsCSV[
"delimiter"], $argumentsCSV[
"enclosure"]);
300 $content = file_get_contents($csvFile);
301 $action->lay->noparse =
true;
302 $action->lay->template = $content;
306 $fileName = sprintf(
"%s_%s.%s", $currentDoc->getTitle() , date(
"Y_m_d-H_m_s") ,
"csv");
308 $action->
Register($expVarName, array(
309 "status" => _(
"Export Done") ,
315 $action->
exitError(
'The document is not a report');
322 $returnArray = array();
323 foreach ($currentLine as $currentValue) {
325 $returnArray[] = iconv(
"UTF-8", $encoding, $currentValue);
convertLine($currentLine, $encoding)
exitError($texterr, $exit=true, $code="")
getParam($name, $def="")
must be in core or global type
Verify arguments for action function.
getDocAttr($dbaccess, $famid, $name="")
new_Doc($dbaccess, $id= '', $latest=false)
Http_DownloadFile($filename, $name, $mime_type= '', $inline=false, $cache=true, $deleteafter=false)
setMaxExecutionTimeTo($limit)
getIdFromName($dbaccess, $name)
if($file) if($subject==""&&$file) if($subject=="") $err