6 include_once (
"FDL/import_file.php");
14 private $cr = array();
18 private $strict =
true;
20 private $onlyAnalyze =
false;
56 $this->strict = ($strict &&
true);
66 } elseif (is_string(
$reset)) {
80 $this->dirid = $dirid;
93 $point =
'dcp:importDocument';
97 $this->onlyAnalyze = $onlyAnalyze;
98 $this->fileName =
$file;
101 include_once (
"FREEDOM/freedom_ana_tar.php");
107 $err = sprintf(_(
"cannot extract archive %s: status : %s") ,
$file,
$err);
117 "values" => array() ,
124 $simpleFamilyFile = 7;
125 $simpleFamilyFolder = 2;
126 $dirid = $this->dirid;
127 $this->cr =
import_directory($action, $untardir, $dirid, $simpleFamilyFile, $simpleFamilyFolder, $onlycsv, $onlyAnalyze, $this->csvLinebreak);
133 $iXml = new \Dcp\Core\importXml();
134 $iXml->setPolicy($this->policy);
135 $iXml->setImportDirectory($this->dirid);
136 $iXml->setVerifyAttributeAccess($this->verifyAttributeAccess);
137 $iXml->analyzeOnly($this->onlyAnalyze);
138 $this->cr = $iXml->importSingleXmlFile(
$file);
139 }
else if (
$ext ==
"zip") {
140 $iXml = new \Dcp\Core\importXml();
141 $iXml->setPolicy($this->policy);
142 $iXml->setImportDirectory($this->dirid);
143 $iXml->setVerifyAttributeAccess($this->verifyAttributeAccess);
144 $iXml->analyzeOnly($this->onlyAnalyze);
145 $this->cr = $iXml->importZipFile(
$file);
151 catch(Exception $e) {
154 "title" =>
"unable to import",
155 "foldername" =>
"unable to import",
156 "filename" =>
"unable to import",
157 "familyname" =>
"unable to import",
158 "action" =>
"ignored",
159 "id" =>
"unable to import",
160 "specmsg" =>
"unable to import",
161 "err" => $e->getMessage()
186 $if->setImportDirectory($this->dirid);
187 $if->analyzeOnly($this->onlyAnalyze);
188 $if->setPolicy($this->policy);
189 $if->setVerifyAttributeAccess($this->verifyAttributeAccess);
190 $if->reset($this->reset);
191 $if->setCsvOptions($this->csvSeparator, $this->csvEnclosure, $this->csvLinebreak);
192 return $if->import();
201 foreach ($this->cr as $cr) {
202 if ($cr[
"err"]) $terr[] = $cr[
"err"];
204 if (count($terr) > 0) {
205 return '[' . implode(
"]\n[", $terr) .
']';
218 $flog = fopen(
$log,
"w");
225 fputs($flog, $lay->gen());
239 foreach ($this->cr as $k => $v) {
254 if (!isset($v[
"msg"])) $v[
"msg"] =
'';
255 if (!isset($v[
"values"])) $v[
"values"] = null;
256 $this->cr[$k][
"title"] = htmlspecialchars($v[
"title"], ENT_QUOTES);
257 $this->cr[$k][
"foldername"] = htmlspecialchars($v[
"foldername"], ENT_QUOTES);
258 $this->cr[$k][
"id"] = htmlspecialchars($v[
"id"], ENT_QUOTES);
259 $this->cr[$k][
"familyid"] = htmlspecialchars($v[
"familyid"], ENT_QUOTES);
260 $this->cr[$k][
"familyname"] = htmlspecialchars($v[
"familyname"], ENT_QUOTES);
261 $this->cr[$k][
"taction"] = htmlspecialchars(_($v[
"action"]) , ENT_QUOTES);
262 $this->cr[$k][
"order"] = htmlspecialchars($k, ENT_QUOTES);
263 $this->cr[$k][
"svalues"] = htmlspecialchars(
"", ENT_QUOTES);
264 $this->cr[$k][
"msg"] = nl2br(htmlspecialchars($v[
"msg"], ENT_QUOTES));
265 if (is_array($v[
"values"])) {
266 foreach ($v[
"values"] as $ka => $va) {
267 $this->cr[$k][
"svalues"].= sprintf(
"<LI %s>[%s:%s]</LI>", (($va ==
"/no change/") ?
' class="no"' :
'') , htmlspecialchars($ka, ENT_QUOTES) , htmlspecialchars($va, ENT_QUOTES));
270 if ($v[
"action"] ==
"ignored") $hasError =
true;
271 if ($v[
"action"] ==
"warning") $haswarning =
true;
272 $this->cr[$k][
"err"] = (($this->cr[$k][
"err"] !=
'') ?
"<ul><li>" . join(
"</li><li>", explode(
"\n", htmlspecialchars($this->cr[$k][
"err"], ENT_QUOTES))) .
"</li></ul>" :
"");
273 $this->cr[$k][
"action"] = htmlspecialchars($v[
"action"], ENT_QUOTES);
274 $this->cr[$k][
"specmsg"] = htmlspecialchars($v[
"specmsg"], ENT_QUOTES);
276 $nbdoc = count(array_filter($this->cr, array(
280 $lay->SetBlockData(
"ADDEDDOC", $this->cr);
282 $lay->
set(
"haserror", $hasError || !empty($errmsg));
283 $lay->
set(
"basename", $this->fileName);
284 $lay->
set(
"haswarning", $haswarning);
285 $lay->Set(
"nbdoc", $nbdoc);
286 $lay->
set(
"analyze", ($this->onlyAnalyze));
287 if ($this->onlyAnalyze) {
288 $lay->
set(
"processMessage", sprintf(
n___(
"%d document detected",
"%d documents detected", $nbdoc) , $nbdoc));
290 $lay->
set(
"processMessage", sprintf(
n___(
"%d document processed",
"%d documents processed", $nbdoc) , $nbdoc));
293 $lay->Set(
"nbprof", count(array_filter($this->cr, array(
306 $flog = fopen(
$log,
"w");
310 fputs($flog, sprintf(
"IMPORT BEGIN OK : %s\n", $this->begtime));
313 foreach ($this->cr as $v) {
315 if (!isset($v[
"msg"])) $v[
"msg"] =
'';
316 if (!isset($v[
"values"])) $v[
"values"] = null;
318 if (is_array($v[
"values"])) {
319 foreach ($v[
"values"] as $ka => $va) {
320 if ($va !=
"/no change/") $chg.=
"{" . $ka .
":" . str_replace(
"\n",
"-", $va) .
'}';
323 fputs($flog, sprintf(
"IMPORT DOC %s : [title:%s] [id:%d] [action:%s] [changes:%s] [message:%s] [specmsg:%s] %s\n", $v[
"err"] ?
"KO" :
"OK", $v[
"title"], $v[
"id"], $v[
"action"], $chg, str_replace(
"\n",
"-", $v[
"msg"]) , ($v[
"err"] ? (
'[error:' . str_replace(
"\n",
"-", $v[
"err"]) .
']') :
"") , (isset($v[
'specmsg']) ? str_replace(
"\n",
"-", $v[
'specmsg']) :
'')));
324 if ($v[
'action'] !==
'ignored') {
332 fputs($flog, sprintf(
"IMPORT COUNT OK : %d\n", $countok));
333 fputs($flog, sprintf(
"IMPORT COUNT KO : %d\n", $counterr));
342 return (($var[
"action"] ==
"added") || ($var[
"action"] ==
"updated"));
347 return (($var[
"action"] ==
"modprofil"));
Layout is a template generator.
writeHtmlCr(Layout &$lay)
setVerifyAttributeAccess($verifyAttributeAccess)
getSysMimeFile($f, $fn="")
getTarExtractDir(Action &$action, $tar)
setTargetDirectory($dirid)
n___($message, $message_plural, $num, $context="")
getLayoutFile($app, $layfile)
if($updateExistingTable) $point
static getTimeDate($hourdelta=0, $second=false)
extractTar($tar, $untardir, $mime="")
if($file) if($subject==""&&$file) if($subject=="") $err
setCsvOptions($csvSeparator= ';', $csvEnclosure= '"', $csvLinebreak = '\n')
importDocuments(Action &$action, $file, $onlyAnalyze=false, $archive=false)
import_directory(&$action, $ldir, $dirid=0, $famid=7, $dfldid=2, $onlycsv=false, $analyze=false, $csvLinebreak= '\n')