Platform  3.1
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
vault_view.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 Vault
9  *
10  * @author Anakeen 2006
11  * @version $Id: vault_view.php,v 1.9 2008/11/24 16:10:23 eric Exp $
12  * @license http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Anakeen - licence CC
13  * @package FDL
14  * @subpackage
15  */
16 /**
17  */
18 
19 include_once ("VAULT/Class.VaultDiskStorage.php");
20 include_once ("VAULT/Class.VaultDiskFsStorage.php");
21 include_once ("FDL/Class.DocVaultIndex.php");
22 // -----------------------------------
23 function vault_view(&$action)
24 {
25  // GetAllParameters
26  $docid = GetHttpVars("id", 0);
27  $classid = GetHttpVars("classid");
28  $arrayid = strtolower(GetHttpVars("arrayid"));
29  $vid = GetHttpVars("vid"); // special controlled view
30  // Set the globals elements
31  $dbaccess = $action->GetParam("FREEDOM_DB");
32 
33  $q = new QueryDb($dbaccess, "VaultDiskFsStorage");
34  // SELECT count(id_file), sum(size) from vaultdiskstorage where id_file in (select vaultid from docvaultindex where docid in (select id from doc where doctype='Z')); // trash files
35  // SELECT count(id_file), sum(size) from vaultdiskstorage where id_file not in (select vaultid from docvaultindex); //Orphean
36  $q->order_by = "id_fs";
37  $l = $q->Query(0, 0, "TABLE");
38 
39  if (!is_array($l) || count($l) < 1) {
40 
41  $action->lay->setBlockData("FS", $tfs);
42  echo _("no vault initialised.");
43  } else {
44 
45  foreach ($l as $k => $fs) {
46 
47  $sqlfs = "id_fs=" . intval($fs["id_fs"]) . " and ";
48 
49  $q = new QueryDb($dbaccess, "VaultDiskStorage");
50 
51  $nf = $q->Query(0, 0, "TABLE", "select count(id_file),sum(size) from vaultdiskstorage where id_fs='" . $fs["id_fs"] . "'");
52  $nf0 = $nf[0];
53  $used_size = $nf0["sum"];
54  $q = new QueryDb($dbaccess, "VaultDiskFsStorage");
55 
56  $no = $q->Query(0, 0, "TABLE", "SELECT count(id_file), sum(size) from vaultdiskstorage where $sqlfs id_file not in (select vaultid from docvaultindex where docid>0)"); //Orphean
57  $nt = $q->Query(0, 0, "TABLE", "SELECT count(id_file), sum(size) from vaultdiskstorage where $sqlfs id_file in (select vaultid from docvaultindex where docid in (select id from docread where doctype='Z'))"); //trash files
58  $free = doubleval($fs["free_size"]);
59  $max = doubleval($fs["max_size"]);
60  $free = $max - $used_size;
61  $pci_used = (($max - $free) / $max * 100);
62  $pcused = humanreadpc($pci_used);
63  $effused = ($max - $free - $no[0]["sum"] - $nt[0]["sum"]);
64  $realused = ($max - $free);
65  $pci_realused = ($realused / $max * 100);
66  $pci_effused = ($effused / $max * 100);
67  $pceffused = sprintf("%d%%", $pci_effused);
68  $pci_free = (100 - $pci_used);
69  $pcfree = humanreadpc($pci_free);
70  $tfs[$k] = array(
71  "pcoccuped" => humanreadpc($pci_effused) ,
72  "pcfree" => $pcfree,
73  "fsid" => $fs["id_fs"],
74  "free" => humanreadsize($free) ,
75  "total" => humanreadsize($max) ,
76  "used" => humanreadsize($effused) ,
77  "realused" => humanreadsize($realused) ,
78  "pcrealused" => humanreadpc($pci_realused) ,
79  "path" => $fs["r_path"]
80  );
81 
82  $tfs[$k]["count"] = sprintf(_("%d stored files") , $nf0["count"]);
83  $tfs[$k]["orphan"] = ($no[0]["count"] > 0);
84  $tfs[$k]["orphean_count"] = $no[0]["count"];
85  $tfs[$k]["orphean_size"] = humanreadsize($no[0]["sum"]);
86  $pci_orphean = (($no[0]["sum"] / $max) * 100);
87  //if (($pci_orphean<1) && ($no[0]["count"]>0)) $pci_orphean=1;
88  $tfs[$k]["trash_count"] = $nt[0]["count"];
89  $tfs[$k]["trash_size"] = humanreadsize($nt[0]["sum"]);
90  $pci_trash = (($nt[0]["sum"] / $max) * 100);
91  $tfs[$k]["pctrash"] = humanreadpc($pci_trash);
92  $tfs[$k]["pcminfree"] = ($pci_free > 1) ? sprintf("%.02f%%", $pci_free) : 1;
93  $tfs[$k]["pcminoccuped"] = ($pci_effused > 1) ? sprintf("%.02f%%", $pci_effused) : 1;
94  $tfs[$k]["pcmintrash"] = ($pci_trash > 1) ? sprintf("%.02f%%", $pci_trash) : 1;
95  $tfs[$k]["pcorphean"] = humanreadpc($pci_orphean);
96  $tfs[$k]["pcminorphean"] = ($pci_orphean > 1) ? sprintf("%.02f%%", $pci_orphean) : 1;
97  $tfs[$k]["pcoccupedandpctrash"] = sprintf("%.02f%%", ($pci_free + $pci_orphean));
98  }
99  $action->lay->setBlockData("FS", $tfs);
100  }
101 }
102 
103 function humanreadsize($bytes)
104 {
105  if ($bytes < 1024) return sprintf(_("%d bytes") , $bytes);
106  if ($bytes < 10240) return sprintf(_("%.02f Kb") , $bytes / 1024);
107  if ($bytes < 1048576) return sprintf(_("%d Kb") , $bytes / 1024);
108  if ($bytes < 10485760) return sprintf(_("%.02f Mb") , $bytes / 1048576);
109  if ($bytes < 1048576 * 1024) return sprintf(_("%d Mb") , $bytes / 1048576);
110  if ($bytes < 1048576 * 10240) return sprintf(_("%.02f Gb") , $bytes / 1048576 / 1024);
111  if ($bytes < 1048576 * 1048576) return sprintf(_("%d Gb") , $bytes / 1048576 / 1024);
112  return sprintf(_("%d Tb") , $bytes / 1048576 / 1048576);
113 }
114 function humanreadpc($pc)
115 {
116  if ($pc < 1) return sprintf("%.02f%%", $pc);
117  return sprintf("%d%%", $pc);
118 }
119 ?>
← centre documentaire © anakeen - published under CC License - Dynacase