16 include_once (
"FDL/import_file.php");
 
   20     private $currentAttrid = 
"";
 
   61     private $knownLogicalNames = array();
 
  101         $this->folderIds = 
$dirid;
 
  105         $this->importFilePath = 
$path;
 
  110         $this->orders = $order;
 
  116         if (!isset($this->keys[1])) $this->keys[1] = null;
 
  121         return implode(
"\n", $this->error);
 
  133         return (count($this->error) > 0);
 
  140     private function setError($code, 
$args = null)
 
  146             $nargs = func_num_args();
 
  147             for ($ip = 1; $ip < $nargs; $ip++) {
 
  148                 $tArgs[] = func_get_arg($ip);
 
  151             $this->error[] = call_user_func_array(
"ErrorCode::getError", $tArgs);
 
  152             $this->tcr[
"err"] = $this->
getError();
 
  153             $this->tcr[
"action"] = 
"ignored";
 
  174             "values" => array() ,
 
  182         $this->famId = isset(
$data[1]) ? trim(
$data[1]) : 
'';
 
  183         $this->specId = isset(
$data[2]) ? trim(
$data[2]) : 
'';
 
  184         $this->folderId = isset(
$data[3]) ? trim(
$data[3]) : 
'';
 
  190             $this->tcr[
"action"] = 
"ignored";
 
  191             $this->tcr[
"err"] = sprintf(_(
"Not a family [%s]") , $this->famId);
 
  194         $tmpDoc = 
createDoc($this->dbaccess, $fromid);
 
  197             $this->tcr[
"action"] = 
"ignored";
 
  198             $this->tcr[
"err"] = sprintf(_(
"cannot create from family [%s]") , $this->famId);
 
  203         $tmpDoc->fromid = $fromid;
 
  204         $this->tcr[
"familyid"] = $tmpDoc->fromid;
 
  205         $this->tcr[
"familyname"] = $tmpDoc->getTitle($tmpDoc->fromid);
 
  206         if ($this->specId > 0) {
 
  209         } elseif (trim($this->specId) != 
"") {
 
  210             if (!is_numeric(trim($this->specId))) {
 
  211                 $tmpDoc->name = trim($this->specId); 
 
  220         if ($tmpDoc->id > 0) {
 
  221             $this->doc = new_doc($tmpDoc->dbaccess, $tmpDoc->id, 
true);
 
  222             if (!$this->doc->isAffected()) $this->doc = $tmpDoc;
 
  224             $this->doc = $tmpDoc;
 
  227         if ((intval($this->doc->id) == 0) || (!$this->doc->isAffected())) {
 
  229             $this->tcr[
"action"] = 
"added";
 
  231             if ($this->doc->fromid != $fromid) {
 
  233                 $this->tcr[
"id"] = $this->doc->id;
 
  234                 $this->setError(
"DOC0008", $this->doc->getTitle() , $this->doc->fromname, 
getNameFromId($this->dbaccess, $fromid));
 
  237             if ($this->doc->doctype == 
'Z') {
 
  238                 if (!$this->analyze) $this->doc->undelete();
 
  239                 $this->tcr[
"msg"].= _(
"restore document") . 
"\n";
 
  242             if ($this->doc->locked == - 1) {
 
  243                 $this->tcr[
"id"] = $this->doc->id;
 
  244                 $this->setError(
"DOC0009", $this->doc->getTitle() , $this->doc->fromname);
 
  248             $this->tcr[
"action"] = 
"updated";
 
  249             $this->tcr[
"id"] = $this->doc->id;
 
  250             $msg.= sprintf(_(
"update id [%d] ") , $this->doc->id);
 
  257         if (!$this->verifyAttributeAccess) {
 
  260         if (count($this->orders) == 0) {
 
  261             $lattr = $this->doc->GetImportAttributes();
 
  262             $this->orders = array_keys($lattr);
 
  264             $lattr = $this->doc->GetNormalAttributes();
 
  268         foreach ($this->orders as $attrid) {
 
  269             if (isset($lattr[$attrid])) {
 
  270                 $attr = $lattr[$attrid];
 
  271                 if (isset(
$data[$iattr]) && (
$data[$iattr] != 
"")) {
 
  273                     if (!
isUTF8($dv)) $dv = utf8_encode($dv);
 
  274                     if (($attr->type == 
"file") || ($attr->type == 
"image")) {
 
  277                         $this->tcr[
"filename"] = $dv;
 
  279                         if (!$this->analyze) {
 
  280                             if ($attr->inArray()) {
 
  281                                 $tabsfiles = $this->doc->rawValueToArray($dv);
 
  283                                 foreach ($tabsfiles as $fi) {
 
  286                                     } elseif (preg_match(
'/^http:/', $fi, $reg)) {
 
  289                                         $absfile = 
"$this->importFilePath/$fi";
 
  292                                             $this->setError(
"DOC0101", 
$err, $fi, $attrid, $this->doc->name);
 
  300                                 $err.= $this->doc->setValue($attr->id, $tvfids);
 
  304                                     $this->doc->setValue($attr->id, $dv);
 
  305                                     $this->tcr[
"values"][$attr->getLabel() ] = $dv;
 
  306                                 } elseif (preg_match(
'/^http:/', $dv, $reg)) {
 
  310                                     $absfile = 
"$this->importFilePath/$dv";
 
  314                                         $this->setError(
"DOC0102", 
$err, $dv, $attrid, $this->doc->name);
 
  316                                         $err = $this->doc->setValue($attr->id, $vfid);
 
  317                                         if (
$err) $this->setError(
"DOC0103", 
$err, $dv, $attrid, $this->doc->name);
 
  323                             $this->tcr[
"values"][$attr->getLabel() ] = $dv;
 
  326                         if ($attr->type == 
"htmltext" && !$this->analyze) {
 
  327                             $this->currentAttrid = $attrid;
 
  328                             $dv = preg_replace_callback(
'/(<img.*?src=")file:\/\/(.*?)(".*?\/>)/', 
function ($matches)
 
  334                         if ($attr->type == 
"docid" || $attr->type == 
"account" || $attr->type == 
"thesaurus") {
 
  338                             if (is_string($dv)) {
 
  339                                 $dv = str_replace(
"\\n", 
"\n", $dv);
 
  343                             if (count($unknownLogicalNames) > 0) {
 
  345                                 foreach ($unknownLogicalNames as $logicalName) {
 
  346                                     $warnMsg = sprintf(_(
"Unknown logical name '%s' in attribute '%s'.") , $logicalName, $attr->id);
 
  347                                     $this->doc->log->warning($warnMsg);
 
  348                                     $this->tcr[
'specmsg'].= (($this->tcr[
'specmsg'] != 
'') ? 
"\n" . $warnMsg : $warnMsg);
 
  352                         $errv = $this->doc->setValue($attr->id, $dv);
 
  354                             $this->setError(
"DOC0100", $attr->id, $errv);
 
  356                         $this->tcr[
"values"][$attr->getLabel() ] = $dv;
 
  359             } 
else if (strpos($attrid, 
"extra:") === 0) {
 
  360                 $attr = substr($attrid, strlen(
"extra:"));
 
  361                 if (isset(
$data[$iattr]) && (
$data[$iattr] != 
"")) {
 
  362                     $dv = str_replace(array(
 
  369                     if (!
isUTF8($dv)) $dv = utf8_encode($dv);
 
  375         if ((!$this->
hasError()) && (!$this->analyze)) {
 
  376             if (($this->doc->id > 0) || ($this->policy != 
"update")) {
 
  377                 $err = $this->doc->preImport($extra);
 
  378                 if (
$err) $this->setError(
"DOC0104", $this->doc->name, 
$err);
 
  382         if (!$this->analyze) $this->doc->refresh(); 
 
  388         if (($this->doc->id == 
"") && ($this->doc->name == 
"")) {
 
  389             switch ($this->policy) {
 
  391                     $this->tcr[
"action"] = 
"added"; # 
N_(
"added")
 
  392                     if (!$this->analyze) {
 
  394                         if ($this->doc->id == 
"") {
 
  396                             foreach ($this->preValues as $k => $v) {
 
  397                                 $this->doc->setValue($k, $v);
 
  399                             $err = $this->doc->preImport($extra);
 
  402                                     $this->setError(
"DOC0105", $this->doc->name, 
$err);
 
  406                             $err = $this->doc->Add();
 
  409                                 $this->setError(
"DOC0107", $this->doc->name, 
$err);
 
  413                             $this->tcr[
"id"] = $this->doc->id;
 
  414                             $msg.= 
$err . sprintf(_(
"add %s id [%d]  ") , $this->doc->title, $this->doc->id);
 
  415                             $this->tcr[
"msg"] = sprintf(_(
"add %s id [%d]  ") , $this->doc->title, $this->doc->id);
 
  417                             $this->tcr[
"action"] = 
"ignored";
 
  420                         $this->doc->RefreshTitle();
 
  421                         $this->tcr[
"msg"] = sprintf(_(
"%s to be add") , $this->doc->title);
 
  426                     $this->doc->RefreshTitle();
 
  427                     $lsdoc = $this->doc->GetDocWithSameTitle($this->keys[0], $this->keys[1]);
 
  429                     if (count($lsdoc) == 0) {
 
  430                         $this->tcr[
"action"] = 
"added";
 
  431                         if (!$this->analyze) {
 
  432                             if ($this->doc->id == 
"") {
 
  434                                 foreach ($this->preValues as $k => $v) {
 
  435                                     if ($this->doc->getRawValue($k) == 
"") {
 
  436                                         $this->doc->setValue($k, $v);
 
  439                                 $err = $this->doc->preImport($extra);
 
  443                                         $this->setError(
"DOC0106", $this->doc->name, 
$err);
 
  448                                 $err = $this->doc->Add();
 
  451                                     $this->setError(
"DOC0108", $this->doc->name, 
$err);
 
  455                                 $this->tcr[
"id"] = $this->doc->id;
 
  456                                 $this->tcr[
"action"] = 
"added";
 
  457                                 $this->tcr[
"msg"] = sprintf(_(
"add id [%d] ") , $this->doc->id);
 
  459                                 $this->tcr[
"action"] = 
"ignored";
 
  462                             $this->tcr[
"msg"] = sprintf(_(
"%s to be add") , $this->doc->title);
 
  464                     } elseif (count($lsdoc) == 1) {
 
  466                         $this->tcr[
"action"] = 
"updated"; # 
N_(
"updated")
 
  472                         if (!$this->analyze) {
 
  473                             $err = $doc->preImport($extra);
 
  476                                     $this->setError(
"DOC0109", $this->doc->name, 
$err);
 
  482                         $err = $doc->transfertValuesFrom($this->doc);
 
  484                             $this->setError(
"DOC0113", $this->doc->name, 
$err);
 
  489                         $this->tcr[
"id"] = $this->doc->id;
 
  490                         if (!$this->analyze) {
 
  491                             if (($this->specId != 
"") && (!is_numeric(trim($this->specId))) && ($this->doc->name == 
"")) {
 
  494                             $this->tcr[
"msg"] = sprintf(_(
"update %s [%d] ") , $this->doc->title, $this->doc->id);
 
  496                             $this->tcr[
"msg"] = sprintf(_(
"to be update %s [%d] ") , $this->doc->title, $this->doc->id);
 
  500                         $this->tcr[
"action"] = 
"ignored"; # 
N_(
"ignored")
 
  501                         $this->setError(
"DOC0110", $this->doc->getTitle());
 
  509                     $this->doc->RefreshTitle();
 
  510                     $lsdoc = $this->doc->GetDocWithSameTitle($this->keys[0], $this->keys[1]);
 
  511                     if (count($lsdoc) == 0) {
 
  512                         $this->tcr[
"action"] = 
"added";
 
  513                         if (!$this->analyze) {
 
  514                             if ($this->doc->id == 
"") {
 
  516                                 foreach ($this->preValues as $k => $v) {
 
  517                                     if ($this->doc->getRawValue($k) == 
"") {
 
  518                                         $this->doc->setValue($k, $v);
 
  521                                 $err = $this->doc->Add();
 
  523                             $this->tcr[
"id"] = $this->doc->id;
 
  524                             $msg.= 
$err . sprintf(_(
"add id [%d] ") , $this->doc->id);
 
  526                             $this->tcr[
"msg"] = sprintf(_(
"%s to be add") , $this->doc->title);
 
  530                         $this->tcr[
"action"] = 
"ignored";
 
  531                         $this->tcr[
"msg"] = sprintf(_(
"similar document %s found. keep similar") , $this->doc->title);
 
  540             if (!$this->doc->isAffected()) {
 
  541                 $this->tcr[
"action"] = 
"added";
 
  542                 if (!$this->analyze) {
 
  544                     foreach ($this->preValues as $k => $v) {
 
  545                         if ($this->doc->getRawValue($k) == 
"") {
 
  546                             $this->doc->setValue($k, $v);
 
  549                     $err = $this->doc->preImport($extra);
 
  551                         $this->setError(
"DOC0111", $this->doc->name, 
$err);
 
  554                     $err = $this->doc->Add();
 
  556                         $this->setError(
"DOC0111", $this->doc->name, 
$err);
 
  559                     $this->tcr[
"id"] = $this->doc->id;
 
  560                     $msg.= 
$err . sprintf(_(
"add %s id [%d]  ") , $this->doc->title, $this->doc->id);
 
  561                     $this->tcr[
"msg"] = sprintf(_(
"add %s id [%d]  ") , $this->doc->title, $this->doc->id);
 
  563                     $this->doc->RefreshTitle();
 
  564                     $this->tcr[
"id"] = $this->doc->id;
 
  565                     $this->tcr[
"msg"] = sprintf(_(
"%s to be add") , $this->doc->title);
 
  569         $this->tcr[
"title"] = $this->doc->title;
 
  573         if (!$this->analyze) {
 
  574             if ($this->doc->isAffected()) {
 
  575                 $warnMsg = $this->doc->Refresh();
 
  576                 $this->tcr[
"specmsg"].= (($this->tcr[
"specmsg"] != 
'') ? 
"\n" . $warnMsg : $warnMsg); 
 
  577                 $msg.= $this->doc->postStore(); 
 
  578                 $err = $this->doc->modify();
 
  581                     $this->doc->addHistoryEntry(sprintf(_(
"updated by import")));
 
  582                     $msg.= $this->doc->postImport($extra);
 
  584                     $this->setError(
"DOC0112", $this->doc->name, 
$err);
 
  587                 $this->tcr[
"msg"].= $msg;
 
  595         if ($this->folderId != 
"-") {
 
  596             if ($this->folderId) {
 
  597                 $this->addIntoFolder($this->folderId);
 
  598             } elseif ($this->dirid) {
 
  599                 $this->addIntoFolder($this->dirid);
 
  602         if ($this->folderIds) {
 
  603             foreach ($this->folderIds as $fid) {
 
  604                 if ($fid) $this->addIntoFolder($fid);
 
  607         if ($this->doc->id) {
 
  616         foreach ($oas as $oa) {
 
  617             if ($oa->mvisibility === 
"I") {
 
  618                 $oa->setVisibility(
"H");
 
  625         $dvCahnged = $matches[0];
 
  626         $absfile = 
"$this->importFilePath/$matches[2]";
 
  628         if (
$err != 
"" || $this->analyze) {
 
  629             $this->setError(
"DOC0102", 
$err, $matches[2], $this->currentAttrid, $this->doc->name);
 
  631             $fileImgAttrid = 
"img_file";
 
  637             if (is_object($imgDoc)) {
 
  638                 $imgDoc->setAttributeValue($fileImgAttrid, $vfid);
 
  639                 $err = $imgDoc->store();
 
  640                 if (
$err) $this->setError(
"DOC0100", $this->currentAttrid, 
$err);
 
  641                 else $dvCahnged = $matches[1] . htmlspecialchars($imgDoc->getFileLink($fileImgAttrid)) . $matches[3];
 
  650     protected function addIntoFolder(
$folderId)
 
  657             if (
$dir->isAlive()) {
 
  658                 $this->tcr[
"folderid"] = 
$dir->id;
 
  659                 $this->tcr[
"foldername"] = dirname($this->importFilePath) . 
"/" . 
$dir->title;
 
  660                 if (!$this->analyze) {
 
  661                     if (method_exists(
$dir, 
"insertDocument")) {
 
  662                         $err = 
$dir->insertDocument($this->doc->id);
 
  663                         if (
$err) $this->setError(
"DOC0200", $this->doc->name, 
$dir->getTitle() , 
$err);
 
  665                         $this->setError(
"DOC0202", 
$dir->getTitle() , 
$dir->fromname, $this->doc->name);
 
  668                 $this->tcr[
"msg"].= 
" " . sprintf(_(
"and add in %s folder ") , 
$dir->title);
 
  670                 $this->setError(
"DOC0201", 
$folderId, ($this->doc->name) ? $this->doc->name : $this->doc->getTitle());
 
  689         if ($oattr->repeat) {
 
  694         foreach ($tvalues as $kvalue => $avalue) {
 
  695             if (($avalue != 
"") && ($avalue != 
"\t")) {
 
  696                 $unresolvedLogicalNames = array();
 
  697                 $tvalues[$kvalue] = $doc->
resolveDocIdLogicalNames($oattr, $avalue, $unresolvedLogicalNames, $this->knownLogicalNames);
 
  698                 if (count($unresolvedLogicalNames) > 0) {
 
  699                     $res = array_merge($res, $unresolvedLogicalNames);
 
  712         if (!is_array($knownLogicalNames)) {
 
  715         $old = $this->knownLogicalNames;
 
  716         $this->knownLogicalNames = $knownLogicalNames;
 
getNormalAttributes($onlyopt=false)
if(substr($wsh, 0, 1)!= '/') $args
importHtmltextFiles($matches)
static rawValueToArray($v)
setTargetDirectories(array $dirid)
getUnknownDocIdLogicalNames(Doc &$doc, NormalAttribute &$oattr, $value)
setVerifyAttributeAccess($verifyAttributeAccess)
createDoc($dbaccess, $fromid, $control=true, $defaultvalues=true, $temporary=false)
setTargetDirectory($dirid)
AddVaultFile($dbaccess, $path, $analyze, &$vid)
getFamIdFromName($dbaccess, $name)
setKnownLogicalNames($knownLogicalNames=array())
new_Doc($dbaccess, $id= '', $latest=false)
getNameFromId($dbaccess, $id)
resolveDocIdLogicalNames(NormalAttribute &$oattr, $avalue, &$unknownLogicalNames=array(), &$knownLogicalNames=array())
getIdFromName($dbaccess, $name)
if($file) if($subject==""&&$file) if($subject=="") $err
setPreValues(array $preValues)
inhibitInvisibleAttributes(Doc $doc)