52 $this->disk_quota_enable =
variable_get(
'disk_quota_enable', 1,
'Are disk quota enabled for this server', array(array(
'desc'=>
'Enabled',
'type'=>
'boolean')));
53 if ( $this->disk_quota_enable ) {
54 $this->disk = Array(
"web"=>
"web" );
65 'title' => _(
"Show my quotas"),
66 'ico' =>
'images/quota.png',
69 'divclass' =>
'menu-quota',
75 foreach ( array(
'web',
'bw_web') as
$key ) {
76 if ( !
isset(
$q[$key][
"u"]) || empty(
$q[$key][
"t"]))
continue;
77 $usage_percent = (int) (
$q[$key][
"u"] /
$q[$key][
"t"] * 100);
78 $obj[
'links'][] = array(
'txt'=>_(
"quota_".$key) .
" " . sprintf(_(
"%s%% of %s"),$usage_percent,
format_size(
$q[$key][
"t"]*1024)),
'url'=>($key ==
'bw_web' ?
'stats_show_per_month.php' :
'quota_show.php') );
79 $obj[
'links'][] = array(
'txt'=>
'progressbar',
'total' =>
$q[$key][
"t"],
'used' =>
$q[$key][
"u"]);
92 return $t[
"u"]<
$t[
"t"];
104 while (list(
$key,
$val)=each($this->disk)) {
109 if (
isset($qq[
'name'])) {
110 $qlist[$qq[
'name']]=$qq[
'description'];
126 $err->log(
"quota",
"synchronise_user_profile");
127 $q=
"insert into quotas select m.uid as uid, d.quota as name, d.value as total from membres m, defquotas d left join quotas q on q.name=d.quota where m.type=d.type ON DUPLICATE KEY UPDATE total = greatest(d.value, quotas.total);";
128 if (!$db->query(
$q))
return false;
139 $err->log(
"quota",
"create_missing_quota_profile");
140 $qt=$quota->getquota(
'',
true);
141 $type=$quota->listtype();
142 foreach($type as
$t) {
143 foreach($qt as
$q=>$vv) {
144 $db->query(
"INSERT IGNORE defquotas (value,quota,type) VALUES (0,'$q','$t');");
157 $err->log(
"quota",
"getquota",$ressource);
159 $get_quota_cache=null;
160 $this->quota=array();
162 if (! empty($get_quota_cache[$cuid]) ) {
164 $this->quotas = $get_quota_cache[
$cuid];
166 $res=$hooks->invoke(
"hook_quota_get");
168 $this->quotas[$r[
'name']]=
$r;
169 $this->quotas[$r[
'name']][
'u']=$r[
'used'];
170 $this->quotas[$r[
'name']][
't']=0;
174 if (!empty ($this->disk)) {
176 $disk_cached = $mem->session_tempo_params_get(
'quota_cache_disk');
178 while (list(
$key,
$val)=each($this->disk)) {
182 && !empty($disk_cached[$val])
183 && $disk_cached[$val][
'uid'] == $cuid
184 && $disk_cached[$val][
'timestamp'] > ( time() - (90) )
187 $a = $disk_cached[
$val];
189 exec(
"/usr/lib/alternc/quota_get ".$cuid ,$ak);
190 $a[
'u']=intval($ak[0]);
191 $a[
't']=@intval($ak[1]);
192 $a[
'timestamp'] = time();
194 $disk_cached = $mem->session_tempo_params_set(
'quota_cache_disk', array($val=>$a));
196 $this->quotas[
$val]=array(
"name"=>
"$val",
'description'=>_(
"quota_".$val),
"t"=>$a[
't'],
"u"=>$a[
'u']);
201 $db->query(
"select name, total from quotas where uid='$cuid';");
202 while ( $db->next_record() ) {
203 $this->quotas[$db->f(
'name')][
't']=$db->f(
'total');
210 if (
isset($this->quotas[$ressource]) ) {
211 return $this->quotas[$ressource];
228 $err->log(
"quota",
"setquota",$ressource.
"/".$size);
229 if (floatval($size)==0) $size=
"0";
230 if (
isset($this->disk[$ressource])) {
232 exec(
"sudo /usr/lib/alternc/quota_edit $cuid $size &> /dev/null &");
234 exec(
"sudo /usr/lib/alternc/quota_get $cuid &> /dev/null &",$a);
235 if (!
isset($a[1]) || $size!=$a[1]) {
236 $err->raise(
"quota",_(
"Error writing the quota entry!"));
241 $db->query(
"SELECT * FROM quotas WHERE uid='$cuid' AND name='$ressource'");
242 if ($db->num_rows()) {
243 $db->query(
"UPDATE quotas SET total='$size' WHERE uid='$cuid' AND name='$ressource';");
245 $db->query(
"INSERT INTO quotas (uid,name,total) VALUES ('$cuid','$ressource','$size');");
257 $err->log(
"quota",
"delquota");
258 $db->query(
"DELETE FROM quotas WHERE uid='$cuid';");
271 $db->query(
"SELECT type,quota FROM defquotas WHERE type='default'");
272 if(!$db->next_record())
275 $db->query(
"SELECT value,quota,type FROM defquotas ORDER BY type,quota");
276 while($db->next_record()) {
277 $type = $db->f(
"type");
278 $c[$type][$db->f(
"quota")] = $db->f(
"value");
292 foreach($newq as $type =>
$quotas) {
294 if(array_key_exists($qname,
$qlist)) {
295 if(!$db->query(
"REPLACE INTO defquotas (value,quota,type) VALUES ($value,'$qname','$type');"))
312 if(empty($type))
return false;
313 $type=strtolower($type);
314 if (!preg_match(
"#^[a-z0-9]*$#",$type)) {
315 $err->raise(
"quota",
"Type can only contains characters a-z and 0-9");
319 if(!$db->query(
"INSERT IGNORE INTO defquotas (quota,type) VALUES('$key', '$type');")
320 || $db->affected_rows() == 0)
333 $db->query(
"SELECT distinct(type) FROM defquotas ORDER by type");
335 while ($db->next_record()) {
336 $t[] = $db->f(
"type");
351 if($db->query(
"UPDATE membres SET type='default' WHERE type='$type'") &&
352 $db->query(
"DELETE FROM defquotas WHERE type='$type'")) {
366 $err->log(
"quota",
"addquota");
370 $db->query(
"SELECT type,quota FROM defquotas WHERE type='default'");
371 if(!$db->next_record())
374 $db->query(
"SELECT type FROM membres WHERE uid='$cuid'");
379 $db->query(
"SELECT value FROM defquotas WHERE quota='$res' AND type='$t'");
380 $q = $db->next_record() ? $db->f(
"value") : 0;
410 if ($db->num_rows() == 0) {
422 if ($db->num_rows() == 0) {
434 if ($db->num_rows() == 0) {
438 while ($db->next_record()) {
439 $ret[] = $db->Record;
447 return $this->
_get_sum_sql(
"SELECT SUM(size) AS sum FROM size_web;");
452 return $this->
_get_sum_sql(
"SELECT SUM(size) AS sum FROM size_web WHERE uid='$u';");
457 return $this->
_get_sum_sql(
"SELECT SUM(bytes) AS sum FROM mailbox;");
463 return $mail->get_total_size_for_domain(
$dom);
468 return $this->
_get_count_sql(
"SELECT COUNT(*) AS count FROM mailbox;");
473 return $this->
_get_count_sql(
"SELECT COUNT(*) AS count FROM dovecot_view WHERE user LIKE '%@{$dom}'");
478 return $this->
_get_size_and_record_sql(
"SELECT user as alias,quota_dovecot as size FROM dovecot_view WHERE user LIKE '%@{$dom}' ORDER BY alias;");
483 return $this->
_get_sum_sql(
"SELECT SUM(size) AS sum FROM size_mailman;");
488 return $this->
_get_sum_sql(
"SELECT SUM(size) AS sum FROM size_mailman WHERE list LIKE '%@{$dom}'");
493 return $this->
_get_sum_sql(
"SELECT SUM(size) AS sum FROM size_mailman WHERE uid = '{$u}'");
498 return $this->
_get_count_sql(
"SELECT COUNT(*) AS count FROM size_mailman;");
503 return $this->
_get_count_sql(
"SELECT COUNT(*) AS count FROM size_mailman WHERE uid = '{$u}'");
508 return $this->
_get_size_and_record_sql(
"SELECT s.size,CONCAT(m.list,'@',m.domain) as list FROM size_mailman s LEFT JOIN mailman m ON s.list=m.name WHERE s.uid='{$u}' ORDER BY s.list ASC");
513 return $this->
_get_sum_sql(
"SELECT SUM(size) AS sum FROM size_db;");
518 return $this->
_get_sum_sql(
"SELECT SUM(size) AS sum FROM size_db WHERE db = '{$u}' OR db LIKE '{$u}\_%'");
523 return $this->
_get_count_sql(
"SELECT COUNT(*) AS count FROM size_db;");
528 return $this->
_get_count_sql(
"SELECT COUNT(*) AS count FROM size_db WHERE db = '{$u}' OR db LIKE '{$u}\_%'");
538 $units=array(1073741824=>_(
"GB"), 1048576=>_(
"MB"), 1024=>_(
"KB"), 0=>_(
"B"));
541 $size=str_pad(round($size/(
$value ?
$value : 1), 1), 5,
' ', STR_PAD_LEFT);
542 return array(
'size'=>$size,
'unit'=>$unit);
553 if ($color_type == 1) {
554 $csscolor =
" background-color:".PercentToColor($usage);
555 } elseif ($color_type == 2) {
556 $csscolor =
" background-color:".PercentToColor(100-$usage);
562 echo
'<div class="progress-bar">';
563 echo
'<div class="barre" style="width:'.$usage.
'%;'.$csscolor.
'" ></div>';
564 echo
'<div class="txt">'.$usage.
'%</div>';
588 $err->log(
"quota",
"hook_admin_add_member");
601 $err->log(
"quota",
"export");
605 foreach (
$q as $k=>$v) {
607 $str.=
" <used>".($v[
"u"]).
"</used>\n";
608 $str.=
" <total>".($v[
"t"]).
"</total>\n";