Platform  3.1
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
vault_generatefs.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  * Generate new vault file system
9  *
10  * @author Anakeen 2006
11  * @version $Id: vault_generatefs.php,v 1.1 2006/11/28 18:28:16 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 // -----------------------------------
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  $q->dbaccess = $dbaccess;
35  $q->basic_elem->dbaccess = $dbaccess; // correct for special constructor
36  // 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
37  // SELECT count(id_file), sum(size) from vaultdiskstorage where id_file not in (select vaultid from docvaultindex); //Orphean
38  $l = $q->Query(0, 0, "TABLE");
39 
40  foreach ($l as $k => $fs) {
41 
42  $q = new QueryDb($dbaccess, "VaultDiskStorage");
43  $q->dbaccess = $dbaccess;
44  $q->basic_elem->dbaccess = $dbaccess; // correct for special constructor
45  $nf = $q->Query(0, 0, "TABLE", "select count(id_file),sum(size) from vaultdiskstorage where id_fs='" . $fs["id_fs"] . "'");
46  $used_size = $nf[0]["sum"];
47  $q = new QueryDb($dbaccess, "VaultDiskFsStorage");
48  $q->dbaccess = $dbaccess;
49  $q->basic_elem->dbaccess = $dbaccess; // correct for special constructor
50  $no = $q->Query(0, 0, "TABLE", "SELECT count(id_file), sum(size) from vaultdiskstorage where id_file not in (select vaultid from docvaultindex)"); //Orphean
51  $nt = $q->Query(0, 0, "TABLE", "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
52  $free = intval($fs["free_size"]);
53  $max = intval($fs["max_size"]);
54  $free = $max - $used_size;
55  $pci_used = (($max - $free) / $max * 100);
56  $pcused = humanreadpc($pci_used);
57  $effused = ($max - $free - $no[0]["sum"] - $nt[0]["sum"]);
58  $realused = ($max - $free);
59  $pci_realused = ($realused / $max * 100);
60  $pci_effused = ($effused / $max * 100);
61  $pceffused = sprintf("%d%%", $pci_effused);
62  $pci_free = (100 - $pci_used);
63  $pcfree = humanreadpc($pci_free);
64  $tfs[$k] = array(
65  "pcoccuped" => $pceffused,
66  "pcfree" => $pcfree,
67  "fsid" => $fs["id_fs"],
68  "free" => humanreadsize($free) ,
69  "total" => humanreadsize($max) ,
70  "used" => humanreadsize($effused) ,
71  "realused" => humanreadsize($realused) ,
72  "pcrealused" => humanreadpc($pci_realused) ,
73  "path" => $fs["r_path"]
74  );
75 
76  $tfs[$k]["count"] = sprintf(_("%d stored files") , $nf[0]["count"]);
77  $tfs[$k]["orphean_count"] = $no[0]["count"];
78  $tfs[$k]["orphean_size"] = humanreadsize($no[0]["sum"]);
79  $pci_orphean = (($no[0]["sum"] / $max) * 100);
80  //if (($pci_orphean<1) && ($no[0]["count"]>0)) $pci_orphean=1;
81  $tfs[$k]["trash_count"] = $nt[0]["count"];
82  $tfs[$k]["trash_size"] = humanreadsize($nt[0]["sum"]);
83  $pci_trash = (($nt[0]["sum"] / $max) * 100);
84  $tfs[$k]["pctrash"] = humanreadpc($pci_trash);
85  $tfs[$k]["pcminfree"] = ($pci_free > 1) ? sprintf("%.02f%%", $pci_free) : 1;
86  $tfs[$k]["pcminoccuped"] = ($pci_effused > 1) ? sprintf("%.02f%%", $pci_effused) : 1;
87  $tfs[$k]["pcmintrash"] = ($pci_trash > 1) ? sprintf("%.02f%%", $pci_trash) : 1;
88  $tfs[$k]["pcorphean"] = humanreadpc($pci_orphean);
89  $tfs[$k]["pcminorphean"] = ($pci_orphean > 1) ? sprintf("%.02f%%", $pci_orphean) : 1;
90  $tfs[$k]["pcoccupedandpctrash"] = sprintf("%.02f%%", ($pci_free + $pci_orphean));
91  }
92  $action->lay->setBlockData("FS", $tfs);
93 }
94 
95 function humanreadsize($bytes)
96 {
97  if ($bytes < 1024) return sprintf(_("%d bytes") , $bytes);
98  if ($bytes < 1048576) return sprintf(_("%d Kb") , $bytes / 1024);
99  return sprintf(_("%d Mb") , $bytes / 1048576);
100 }
101 function humanreadpc($pc)
102 {
103  if ($pc < 1) return sprintf("%.02f%%", $pc);
104  return sprintf("%d%%", $pc);
105 }
106 ?>
← centre documentaire © anakeen - published under CC License - Dynacase