Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
freedom_view_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_view_tar.php,v 1.3 2006/06/14 16:24:31 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;
23 
24  $analyze = GetHttpVars("analyze", "Y"); // just analyze
25  $filename = GetHttpVars("filename"); // the select filename
26  $dirid = GetHttpVars("dirid"); // directory to place imported doc
27  $ldir = getTarUploadDir($action);
28  $selfile = '';
29  $ttar = array();
30  $nbdoc = 0;
31  if ($handle = opendir($ldir)) {
32  while (false !== ($file = readdir($handle))) {
33  if ($file[0] != ".") {
34  $ttar[] = array(
35  "filename" => $file,
36  "selected" => ($file == $filename) ? "selected" : ""
37  );
38  if ($file == $filename) {
39  $selfile = $file;
40  }
41  }
42  }
43  }
44  if ($selfile == "") {
45  // try the first
46  $ttar[0]["selected"] = "selected";
47  $selfile = $ttar[0]["filename"];
48  }
49  if ($selfile != "") {
50  foreach ($ttar as $k => $v) {
51  // need suppress slashes
52  $ttar[$k]["filename"] = $v["filename"];
53  }
54  $action->lay->setBlockData("SELECTFILE", $ttar);
55 
56  $untardir = getTarExtractDir($action, $selfile);
57 
58  if (!is_dir($untardir)) {
59  // need extract first
60  $uploaddir = getTarUploadDir($action);
61  $tar = $uploaddir . $selfile;
62  $err = extractTar($tar, $untardir);
63  if ($err !== '') {
64  $action->AddWarningMsg(sprintf(_("cannot extract archive file %s: %s") , $selfile, $err));
65  }
66  }
67 
68  $nbdoc = see_directory($action, $untardir, $tfile);
69  }
70  if ($nbdoc > 0) $action->lay->SetBlockData("ANALYZE", array(
71  array(
72  "zou"
73  )
74  ));
75 
76  $action->lay->Set("selfile", urlencode($selfile));
77 
78  $action->lay->set("huge", ($action->Read("navigator", "") == "EXPLORER") ? "" : "huge");
79 
80  $action->lay->eSet("dirid", $dirid);
81  $action->lay->Set("nbdoc", "$nbdoc");
82 }
83 
84 function see_directory(&$action, $ldir, &$tfile, $level = 0)
85 {
86 
87  if ($level == 0) $tfile = array();
88  if (is_dir($ldir)) {
89  $handle = opendir($ldir);
90  while (false !== ($file = readdir($handle))) {
91 
92  if ($file[0] != ".") {
93  $afile = "$ldir/$file";
94  $sfile = $file;
95 
96  if (!isUTF8($sfile)) $sfile = utf8_encode($sfile);
97  if (is_file($afile)) {
98  $tfile[] = array(
99  "name" => $sfile,
100  "level" => $level * 20,
101  "type" => "file"
102  );
103  } else if (is_dir($afile)) {
104  $tfile[] = array(
105  "name" => $sfile,
106  "level" => $level * 20,
107  "type" => "dir"
108  );
109  see_directory($action, $afile, $tfile, $level + 1);
110  }
111  }
112  }
113 
114  closedir($handle);
115  }
116  if ($level == 0) {
117  $action->lay->setBlockData("DIR", $tfile);
118  return count($tfile);
119  }
120  return 0;
121 }
122 ?>
global $action
$ldir
Definition: resizeimg.php:145
$filename
getTarExtractDir(Action &$action, $tar)
Definition: import_tar.php:34
$file
isUTF8($string)
Definition: Lib.Common.php:748
Set($name, &$parent)
see_directory(&$action, $ldir, &$tfile, $level=0)
getTarUploadDir(Action &$action)
Definition: import_tar.php:24
Read($k, $d="")
extractTar($tar, $untardir, $mime="")
freedom_view_tar(Action &$action)
if($file) if($subject==""&&$file) if($subject=="") $err
$analyze
← centre documentaire © anakeen