3 * Project Admin page to manage quotas disk and database
\r
6 * Fabio Bertagnin November 2005
\r
8 * @version $Id: 08_IMPROVQUOTA_90_quota_management.dpatch,v 1.1 2006/01/11 17:02:45 fabio Exp $
\r
10 * This file is part of GForge.
\r
12 * GForge is free software; you can redistribute it and/or modify
\r
13 * it under the terms of the GNU General Public License as published by
\r
14 * the Free Software Foundation; either version 2 of the License, or
\r
15 * (at your option) any later version.
\r
17 * GForge is distributed in the hope that it will be useful,
\r
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
20 * GNU General Public License for more details.
\r
22 * You should have received a copy of the GNU General Public License
\r
23 * along with GForge; if not, write to the Free Software
\r
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\r
28 require_once('pre.php');
\r
29 require_once('www/admin/admin_utils.php');
\r
32 $_quota_block_size = 1024;
\r
33 $_quota_block_size = trim(shell_exec("echo $BLOCK_SIZE")) + 0;
\r
34 if ($_quota_block_size == 0) $_quota_block_size = 1024;
\r
36 // session_require(array('group'=>$group_id,'admin_flags'=>'A'));
\r
38 site_admin_header(array('title'=>_('Site Admin')));
\r
43 <a href="quota.php"><?php echo _('Ressources usage and quota'); ?></a>
\r
45 <?php echo _('Quota Manager Admin'); ?>
\r
49 // echo "<pre>".print_r($_POST, true)."</pre>";
\r
52 if ($_POST["cmd"] == "maj")
\r
54 $qs = $_POST["qs"] * $_quota_block_size;
\r
55 $qh = $_POST["qh"] * $_quota_block_size;
\r
58 $message = utf8_encode(_('Input error : Hard quota must be greater than soft quota'));
\r
59 echo "<h3 style=\"color:red\">$message</h3>";
\r
63 $SQL = "UPDATE groups SET quota_soft = $qs, quota_hard = $qh WHERE group_id = $_POST[group_id] ";
\r
65 $message = utf8_encode(_('Successfully updated quota'));
\r
66 echo "<h3 style=\"color:red\">$message</h3>";
\r
71 // stock projects infos in array
\r
74 // all projects list
\r
75 $SQL = "SELECT group_id, group_name, unix_group_name, quota_soft, quota_hard FROM groups ORDER BY group_id ";
\r
76 $res_db = db_query($SQL);
\r
77 if (db_numrows($res_db) > 0)
\r
79 while($e = db_fetch_array($res_db))
\r
81 $qh = $e["quota_hard"] / $_quota_block_size;
\r
82 $qs = $e["quota_soft"] / $_quota_block_size;
\r
83 $quotas["$e[group_id]"]["group_id"] = $e["group_id"];
\r
84 $quotas["$e[group_id]"]["name"] = $e["group_name"];
\r
85 $quotas["$e[group_id]"]["unix_name"] = $e["unix_group_name"];
\r
86 $quotas["$e[group_id]"]["database_size"] = 0;
\r
87 $quotas["$e[group_id]"]["disk_size"] = 0;
\r
88 $quotas["$e[group_id]"]["quota_hard"] = $qh;
\r
89 $quotas["$e[group_id]"]["quota_soft"] = $qs;
\r
96 <table width="700px" cellpadding="2" cellspacing="0" border="0">
\r
97 <tr style="font-weight:bold">
\r
98 <td style="border-top:thick solid #808080" colspan="6"><?php echo _('Projects disk quota'); ?></td>
\r
101 <td style="border-top:thin solid #808080"><?php echo _('id'); ?></td>
\r
102 <td style="border-top:thin solid #808080"><?php echo _('name'); ?></td>
\r
103 <td style="border-top:thin solid #808080"><br /></td>
\r
104 <td style="border-top:thin solid #808080" align="right"><?php echo _('disk quota soft'); ?></td>
\r
105 <td style="border-top:thin solid #808080" align="right"><?php echo _('disk quota hard'); ?></td>
\r
106 <td style="border-top:thin solid #808080"><br /></td>
\r
109 $total_database = 0;
\r
111 foreach ($quotas as $q)
\r
113 $total_database += $q["database_size"];
\r
114 $total_disk += $q["disk_size"];
\r
116 <form action="quota_admin.php" method="POST">
\r
117 <input type="hidden" name="cmd" value="maj" />
\r
118 <input type="hidden" name="group_id" value="<?php echo $q["group_id"]; ?>" />
\r
120 <td style="border-top:thin solid #808080"><?php echo $q["group_id"]; ?></td>
\r
121 <td style="border-top:thin solid #808080"><a href="/project/admin/quota.php?group_id=<?php echo $q["group_id"]; ?>">
\r
122 <?php echo $q["unix_name"]; ?>
\r
124 <td style="border-top:thin solid #808080"><?php echo $q["name"]; ?></td>
\r
125 <td style="border-top:thin solid #808080" align="right">
\r
126 <input type="text" name="qs"
\r
128 value="<?php echo $q["quota_soft"]; ?>"
\r
129 style="background:#ffffd0;text-align:right" />
\r
130 <?php echo _('Mb'); ?>
\r
132 <td style="border-top:thin solid #808080" align="right">
\r
133 <input type="text" name="qh"
\r
135 value="<?php echo $q["quota_hard"]; ?>"
\r
136 style="background:#ffffd0;text-align:right" />
\r
137 <?php echo _('Mb'); ?>
\r
139 <td style="border-top:thin solid #808080" align="right">
\r
140 <input type="submit" value="<?php echo _('Modify'); ?>" />
\r
147 <tr style="font-weight:bold">
\r
148 <td style="border-top:thick solid #808080;border-bottom:thick solid #808080"><br /></td>
\r
149 <td style="border-top:thick solid #808080;border-bottom:thick solid #808080"><br /></td>
\r
150 <td style="border-top:thick solid #808080;border-bottom:thick solid #808080"><br /></td>
\r
151 <td style="border-top:thick solid #808080;border-bottom:thick solid #808080"><br /></td>
\r
152 <td style="border-top:thick solid #808080;border-bottom:thick solid #808080"><br /></td>
\r
153 <td style="border-top:thick solid #808080;border-bottom:thick solid #808080"><br /></td>
\r
161 print_debug(print_r($quotas, true));
\r
162 print_debug(print_r($users, true));
\r
164 site_admin_footer(array());
\r
168 function print_debug ($text)
\r
170 // echo "<pre>$text</pre>";
\r
172 function add_numbers_separator ($val, $sep=' ')
\r
175 $size = strrev($size);
\r
176 $size = wordwrap($size, 3, $sep, 1);
\r
177 $size = strrev($size);
\r
180 function get_dir_size ($dir)
\r
183 $cmd = "/usr/bin/du -bs $dir";
\r
184 $res = shell_exec ($cmd);
\r
185 $a = explode("\t", $res);
\r
186 if (isset($a[1])) $size = $a[0];
\r