Platform  3.1
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  * @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_view_tar.php,v 1.3 2006/06/14 16:24:31 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 
26  $analyze = GetHttpVars("analyze", "Y"); // just analyze
27  $filename = GetHttpVars("filename"); // the select filename
28  $dirid = GetHttpVars("dirid"); // directory to place imported doc
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  if ($selfile != "") {
49  foreach ($ttar as $k => $v) {
50  // need suppress slashes
51  $ttar[$k]["filename"] = stripslashes($v["filename"]);
52  }
53  $action->lay->setBlockData("SELECTFILE", $ttar);
54 
55  $untardir = getTarExtractDir($action, $selfile);
56 
57  if (!is_dir($untardir)) {
58  // need extract first
59  $uploaddir = getTarUploadDir($action);
60  $tar = $uploaddir . $selfile;
61  $status = extractTar($tar, $untardir);
62  if ($status == - 2) $action->AddWarningMsg(sprintf(_("cannot extract archive file %s.\nType %s not recognized as archive file") , $selfile, trim(shell_exec(sprintf("file -b %s", escapeshellarg($tar))))));
63  else if ($status != 0) $action->AddWarningMsg(sprintf(_("cannot extract archive file %s") , $selfile));
64  }
65 
66  $nbdoc = see_directory($action, $untardir, $tfile);
67  }
68  if ($nbdoc > 0) $action->lay->SetBlockData("ANALYZE", array(
69  array(
70  "zou"
71  )
72  ));
73 
74  $action->lay->Set("selfile", stripslashes($selfile));
75 
76  $action->lay->set("huge", ($action->Read("navigator", "") == "EXPLORER") ? "" : "huge");
77 
78  $action->lay->Set("dirid", $dirid);
79  $action->lay->Set("nbdoc", "$nbdoc");
80 }
81 
82 function see_directory(&$action, $ldir, &$tfile, $level = 0)
83 {
84 
85  if ($level == 0) $tfile = array();
86  if (is_dir($ldir)) {
87  $handle = opendir($ldir);
88  while (false !== ($file = readdir($handle))) {
89 
90  if ($file[0] != ".") {
91  $afile = "$ldir/$file";
92  $sfile = $file;
93 
94  if (!isUTF8($sfile)) $sfile = utf8_encode($sfile);
95  if (is_file($afile)) {
96  $tfile[] = array(
97  "name" => $sfile,
98  "level" => $level * 20,
99  "type" => "file"
100  );
101  } else if (is_dir($afile)) {
102  $tfile[] = array(
103  "name" => $sfile,
104  "level" => $level * 20,
105  "type" => "dir"
106  );
107  see_directory($action, $afile, $tfile, $level + 1);
108  }
109  }
110  }
111 
112  closedir($handle);
113  }
114  if ($level == 0) {
115  $action->lay->setBlockData("DIR", $tfile);
116  return count($tfile);
117  }
118 }
119 ?>
← centre documentaire © anakeen - published under CC License - Dynacase