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