Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
freedom_ana_tar.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @package FDL
5 */
6 /**
7  * View imported tar
8  *
9  * @author Anakeen
10  * @version $Id: freedom_ana_tar.php,v 1.9 2008/06/10 07:07:39 eric Exp $
11  * @package FDL
12  * @subpackage GED
13  */
14 /**
15  */
16 
17 include_once ("FREEDOM/freedom_import_tar.php");
18 
20 {
21 
22  global $_FILES;
24 
25  $analyze = GetHttpVars("analyze", "Y"); // just analyze
26  $filename = GetHttpVars("filename"); // the select filename
27  $ldir = getTarUploadDir($action);
28  $selfile = '';
29  if ($handle = opendir($ldir)) {
30  while (false !== ($file = readdir($handle))) {
31  if ($file[0] != ".") {
32  $ttar[] = array(
33  "filename" => $file,
34  "selected" => ($file == $filename) ? "selected" : ""
35  );
36  if ($file == $filename) {
37  $selfile = $file;
38  }
39  }
40  }
41  }
42  if ($selfile == "") {
43  // try the first
44  $ttar[0]["selected"] = "selected";
45  $selfile = $ttar[0]["filename"];
46  }
47 
48  $nbdoc = analyze_tar($action, $selfile);
49 
50  if ($analyze == "Y") $action->lay->setBlockData("AFORM", array(
51  array(
52  "zou"
53  )
54  ));
55 
56  $action->lay->set("huge", ($action->Read("navigator", "") == "EXPLORER") ? "" : "huge");
57 
58  $action->lay->Set("nbdoc", "$nbdoc");
59  $action->lay->Set("importtext", sprintf(_("proceed background import of %d documents") , $nbdoc));
60 }
61 
62 function analyze_tar(Action & $action, $selfile)
63 {
64  $dirid = GetHttpVars("dirid"); // directory to place imported doc
65  $famid = GetHttpVars("famid", 7); // default import family
66  $dfldid = GetHttpVars("dfldid", 2); // default import folder family
67  $onlycsv = GetHttpVars("onlycsv"); // only files described in fdl.csv files
68  $topfld = (GetHttpVars("topfld") != ""); // add a root folder
69  $analyze = (GetHttpVars("analyze", "Y") == "Y"); // just analyze
70  $filename = GetHttpVars("filename"); // the select filename
71  $dbaccess = $action->dbaccess;
72  $selectclass = array();
73 
74  $tclassdoc = GetClassesDoc($dbaccess, $action->user->id, 0, "TABLE");
75 
76  foreach ($tclassdoc as $k => $cdoc) {
77  $selectclass[$k]["idcdoc"] = $cdoc["initid"];
78  $selectclass[$k]["classname"] = $cdoc["title"];
79  if ($cdoc["initid"] == $famid) $selectclass[$k]["selected"] = "selected";
80  else $selectclass[$k]["selected"] = "";
81  }
82  $action->lay->SetBlockData("SELECTCLASS", $selectclass);
83 
84  $tclassdoc = GetClassesDoc($dbaccess, $action->user->id, 2, "TABLE");
85  $selectfld = array();
86  foreach ($tclassdoc as $k => $cdoc) {
87  $selectfld[$k]["idcdoc"] = $cdoc["initid"];
88  $selectfld[$k]["classname"] = $cdoc["title"];
89  if ($cdoc["initid"] == $dfldid) $selectfld[$k]["selected"] = "selected";
90  else $selectfld[$k]["selected"] = "";
91  }
92 
93  $action->lay->SetBlockData("SELECTDFLD", $selectfld);
94 
95  $untardir = getTarExtractDir($action, $selfile);
96 
98  $dirtitle = $dir->title;
99  if (!method_exists($dir, "addfile")) {
100  $action->AddWarningMsg(sprintf(_("The document <%s> is not a folder") , $dirtitle));
101  /*
102  * @var Dir $dir
103  */
104  $dir = createDoc($dbaccess, "DIR");
105  $dir = $dir->getHome();
106  $dirtitle = $dir->title;
107  $dirid = $dir->id;
108  $action->AddWarningMsg(sprintf(_("Use your home folder instead <%s>") , $dirtitle));
109  }
110  if ($topfld) {
111  if ($analyze) {
112  $dirtitle = $dirtitle . "/" . $filename;
113  } else {
114  // add a father
115  $pdir = createDoc($dbaccess, "DIR");
116  $pdir->setValue("BA_TITLE", $filename);
117  $err = $pdir->Add();
118  if ($err != "") $action->exitError($err);
119  $err = $dir->insertDocument($pdir->id);
120  if ($err != "") $action->exitError($err);
121  $dirid = $pdir->id;
122  $dirtitle = $dirtitle . "/" . $pdir->title;
123  }
124  }
125  if (!$onlycsv) $onlycsv = hasfdlpointcsv($untardir);
126  else $onlycsv = ($onlycsv != "2");
127  $tr = import_directory($action, $untardir, $dirid, $famid, $dfldid, $onlycsv, $analyze);
128 
129  if ($tr) {
130  foreach ($tr as $k => $v) {
131  if ($v["familyid"] > 0) {
132  $f = new_Doc($dbaccess, $v["familyid"]);
133  $tr[$k]["familyname"] = $f->title;
134  $tr[$k]["foldername"] = $dirtitle . '/' . substr($v["foldername"], strposn($v["foldername"], '/', 6));
135  } else {
136  $tr[$k]["familyname"] = "";
137  $tr[$k]["foldername"] = "";
138  }
139  }
140  }
141 
142  $action->lay->eSet("dirid", $dirid);
143  $action->lay->SetBlockCorresp("ADDEDDOC", "filename");
144  $action->lay->SetBlockCorresp("ADDEDDOC", "err");
145  $action->lay->SetBlockCorresp("ADDEDDOC", "anaclass");
146  $action->lay->SetBlockData("ADDEDDOC", $tr);
147  $action->lay->eSet("selfile", $selfile);
148  $action->lay->Set("oselected", $onlycsv ? "checked" : "");
149  $action->lay->Set("notoselected", $onlycsv ? "" : "checked");
150  $action->lay->Set("tselected", $topfld ? "checked" : "");
151  $action->lay->Set("fdisabled", $onlycsv ? "disabled" : "");
152  $action->lay->eSet("mailaddr", getMailAddr($action->user->id));
153  $action->lay->Set("bgdisabled", (count($tr) > 0) ? "" : "disabled");
154 
155  return count($tr);
156 }
157 /**
158  * get position of $i th character $c in $s string
159  */
160 function strposn($s, $c, $i)
161 {
162  $p = 0; // begin
163  for ($j = 0; $j < $i; $j++) {
164  $p = strpos($s, $c, $p);
165  $p++;
166  }
167  if ($p == 0) $p = strlen($s);
168  return $p;
169 }
170 
172 {
173  $found = file_exists("$dir/fdl.csv");
174  if (!$found) {
175  if ($handle = opendir($dir)) {
176  while ((!$found) && (false !== ($file = readdir($handle)))) {
177  if (is_dir("$dir/$file")) {
178  $found = file_exists("$dir/$file/fdl.csv");
179  }
180  }
181  closedir($handle);
182  }
183  }
184  return $found;
185 }
global $action
getMailAddr($userid, $full=false)
Definition: Lib.Common.php:133
$ldir
Definition: resizeimg.php:145
analyze_tar(Action &$action, $selfile)
$filename
freedom_ana_tar(Action &$action)
getTarExtractDir(Action &$action, $tar)
Definition: import_tar.php:34
$file
if($famId) $s
Set($name, &$parent)
exitError($texterr, $exit=true, $code="")
GetClassesDoc($dbaccess, $userid, $classid=0, $qtype="LIST", $extraFilters=array())
Definition: Lib.Dir.php:906
getTarUploadDir(Action &$action)
Definition: import_tar.php:24
Read($k, $d="")
createDoc($dbaccess, $fromid, $control=true, $defaultvalues=true, $temporary=false)
hasfdlpointcsv($dir)
strposn($s, $c, $i)
new_Doc($dbaccess, $id= '', $latest=false)
$dir
Definition: resizeimg.php:144
setMaxExecutionTimeTo($limit)
Definition: Lib.Common.php:121
$dbaccess
Definition: checkVault.php:17
if($file) if($subject==""&&$file) if($subject=="") $err
$analyze
import_directory(&$action, $ldir, $dirid=0, $famid=7, $dfldid=2, $onlycsv=false, $analyze=false, $csvLinebreak= '\n')
Definition: import_tar.php:64
← centre documentaire © anakeen