17 include_once (
"FDL/import_file.php");
18 include_once (
"WHAT/Lib.Prefix.php");
21 define(
"TAREXTRACT",
"/extract/");
22 define(
"TARTARS",
"/tars/");
27 $dtar = $action->
getParam(
"FREEDOM_UPLOADDIR");
28 if (substr($dtar, 0, 1) !=
'/') {
29 $dtar = $pubdir .
'/' . $dtar;
32 return $dtar .
"/" . $action->user->login .
TARTARS;
37 $dtar = $action->
getParam(
"FREEDOM_UPLOADDIR");
38 if (substr($dtar, 0, 1) !=
'/') {
39 $dtar = $pubdir .
'/' . $dtar;
42 return $dtar .
"/" . $action->user->login .
TAREXTRACT . $tar .
"_D";
67 global $importedFiles;
72 if ($handle = opendir(
$ldir)) {
75 while (
false !== (
$file = readdir($handle))) {
76 $absfile = str_replace(
"//",
"/",
"$ldir/$file");
77 if (is_file($absfile) && (
$file ==
"fdl.csv")) {
81 if ($lfamid > 0)
$famid = $lfamid;
82 if ($lfldid > 0) $dfldid = $lfldid;
86 if (!$defaultdoc)
$action->AddWarningMsg(sprintf(_(
"you cannot create this kind [%s] of document") ,
$famid));
88 if (($lfamid == 0) && (
$famid == 7)) {
90 $fimgattr = $defaultimg->GetFirstFileAttributes();
93 if (!$newdir)
$action->AddWarningMsg(sprintf(_(
"you cannot create this kind [%s] of folder") , $dfldid));
94 $ffileattr = $defaultdoc->GetFirstFileAttributes();
105 while (
false !== (
$file = readdir($handle))) {
107 $absfile = str_replace(
"//",
"/",
"$ldir/$file");
108 $level = substr_count($absfile,
"/");
109 $index =
"f$level/$nfile";
110 if (is_file($absfile)) {
112 if (!isset($importedFiles[$absfile])) {
116 "err" => ($defaultdoc) ?
"" : sprintf(_(
"you cannot create this kind [%s] of document") ,
$famid) ,
118 "foldername" =>
$ldir,
123 "anaclass" =>
"fileclass",
131 $tr[$index][
"err"] =
$err;
133 if (($lfamid == 0) && (
$famid == 7) && (substr($vfid, 0, 5) ==
"image")) {
134 $ddoc = & $defaultimg;
135 $fattr = $fimgattr->id;
137 $ddoc = & $defaultdoc;
139 $fattr = $ffileattr->id;
141 $tr[$index][
"err"] =
"no file attribute";
145 $tr[$index][
"familyname"] = $ddoc->fromname;
146 $tr[$index][
"familyid"] = $ddoc->fromid;
147 $tr[$index][
"action"] =
N_(
"to be add");
150 $ddoc->setValue($fattr, $vfid);
153 $tr[$index][
"action"] =
N_(
"not added");
154 $tr[$index][
"err"] =
$err;
156 $ddoc->addHistoryEntry(sprintf(
"create by import from archive %s", substr(basename(
$ldir) , 0, -2)));
157 $tr[$index][
"action"] =
N_(
"added");
158 $tr[$index][
"id"] = $ddoc->id;
162 $dir->insertDocument($ddoc->id);
164 $tr[$index][
"title"] = $ddoc->getTitle();
165 $tr[$index][
"id"] = $ddoc->id;
166 $tr[$index][
"familyid"] = $ddoc->fromid;
167 $tr[$index][
"familyname"] = $ddoc->fromname;
173 }
else if (is_dir($absfile) && (
$file[0] !=
'.')) {
178 if ((!$onlycsv) || (!preg_match(
"/^[0-9]+-.*_D$/i",
$file))) {
180 "err" => ($newdir) ?
"" : sprintf(_(
"you cannot create this kind [%s] of folder") , $dfldid) ,
182 "foldername" =>
$ldir,
187 "anaclass" =>
"fldclass",
188 "familyid" => $newdir->fromid,
189 "familyname" => $newdir->fromname,
190 "action" =>
N_(
"to be add")
194 $newdir->setTitle(
$file);
195 $err = $newdir->Add();
197 $tr[$index][
"action"] =
N_(
"not added");
199 $tr[$index][
"action"] =
N_(
"added");
200 $tr[$index][
"id"] = $newdir->id;
202 $dir->insertDocument($newdir->id);
208 $tr = array_merge($tr, $itr);
215 $err = sprintf(
"cannot open local directory %s",
$ldir);
226 $fcsv = fopen($fdlcsv,
"r");
228 $ldir = dirname($fdlcsv);
231 $tcolorder = array();
232 $separator = $enclosure =
"auto";
234 if ($separator ==
'') {
237 if ($enclosure ==
'') {
240 while (
$data = fgetcsv($fcsv, 0, $separator, $enclosure)) {
242 $level = substr_count(
$ldir,
"/");
243 $index =
"c$level/$nline";
253 "values" => array() ,
280 if (is_numeric(
$data[1])) $orfromid =
$data[1];
284 $tr[$index][
"action"] = sprintf(_(
"new column order %s") , implode(
" - ", $tcolorder[$orfromid]));
288 if (is_numeric(
$data[1])) $orfromid =
$data[1];
292 if (($tkeys[$orfromid][0] ==
"") || (count($tkeys[$orfromid]) == 0)) {
293 $tr[$index][
"err"] = sprintf(_(
"error in import keys : %s") , implode(
" - ", $tkeys[$orfromid]));
294 unset($tkeys[$orfromid]);
295 $tr[$index][
"action"] =
"ignored";
297 $tr[$index][
"action"] = sprintf(_(
"new import keys : %s") , implode(
" - ", $tkeys[$orfromid]));
304 if (isset($tkeys[$fromid])) $tk = $tkeys[$fromid];
309 if ($tr[$index][
"err"] ==
"") $nbdoc++;
346 for ($i = 0; $i < strlen(
$s); $i++) {
347 if (isset($td[ord(
$s[$i]) ])) $s2[$i] = $td[ord(
$s[$i]) ];
358 $handle = opendir(
$ldir);
359 if ($handle ===
false) {
360 return sprintf(_(
"Error opening directory '%s'.") ,
$ldir);
362 while (
false !== (
$file = readdir($handle))) {
363 if (
$file[0] !=
".") {
364 $afile =
"$ldir/$file";
366 if (is_file($afile)) {
368 return sprintf(_(
"Error renaming '%s' to '%s'.") , $afile,
WNGBdecode(
$file));
370 }
else if (is_dir($afile)) {
import_tar(&$action, $ftar, $dirid=0, $famid=7)
analyze_csv($fdlcsv, $dbaccess, $dirid, &$famid, &$dfldid, $analyze, $csvLinebreak= '\n')
static detectAutoCsvOptions($csvFileName, &$separator= 'auto', &$enclosure= 'auto')
getTarExtractDir(Action &$action, $tar)
getOrder(array $orderdata)
getTarUploadDir(Action &$action)
createDoc($dbaccess, $fromid, $control=true, $defaultvalues=true, $temporary=false)
AddVaultFile($dbaccess, $path, $analyze, &$vid)
getFamIdFromName($dbaccess, $name)
new_Doc($dbaccess, $id= '', $latest=false)
csvAddDoc($dbaccess, $data, $dirid=0, $analyze=false, $ldir= '', $policy="add", $tkey=array("title"), $prevalues=array(), $torder=array())
if($file) if($subject==""&&$file) if($subject=="") $err
import_directory(&$action, $ldir, $dirid=0, $famid=7, $dfldid=2, $onlycsv=false, $analyze=false, $csvLinebreak= '\n')