Alternc  latest
Alternc logiel libre pour l'hébergement
 All Classes Namespaces Files Functions Variables Pages
m_quota Class Reference

Class for hosting quotas management. More...

Public Member Functions

 m_quota ()
 Constructor. More...
 
 hook_menu ()
 
 hook_homepageblock ()
 
 cancreate ($ressource="")
 Check if a user can use a ressource. More...
 
 qlist ()
 List the quota-managed services in the server array the quota names and description (translated) More...
 
 synchronise_user_profile ()
 Synchronise the quotas of the users with the quota of the user's profile. More...
 
 create_missing_quota_profile ()
 
 getquota ($ressource="", $recheck=false)
 Return a ressource usage (u) and total quota (t) More...
 
 setquota ($ressource, $size)
 Set the quota for a user (and for a ressource) More...
 
 delquotas ()
 Erase all quota information about the user. More...
 
 getdefaults ()
 Get the default quotas as an associative array. More...
 
 setdefaults ($newq)
 Set the default quotas. More...
 
 addtype ($type)
 Add an account type for quotas. More...
 
 listtype ()
 List for quotas. More...
 
 deltype ($type)
 Delete an account type for quotas. More...
 
 addquotas ()
 Create default quotas entries for a new user. More...
 
 display_val ($type, $value)
 Return a quota value with its unit (when it is a space quota) in MB, GB, TB ... More...
 
 _get_sum_sql ($sql)
 
 _get_count_sql ($sql)
 
 _get_size_and_record_sql ($sql)
 
 get_size_web_sum_all ()
 
 get_size_web_sum_user ($u)
 
 get_size_mail_sum_all ()
 
 get_size_mail_sum_domain ($dom)
 
 get_size_mail_count_all ()
 
 get_size_mail_count_domain ($dom)
 
 get_size_mail_details_domain ($dom)
 
 get_size_mailman_sum_all ()
 
 get_size_mailman_sum_domain ($dom)
 
 get_size_mailman_sum_user ($u)
 
 get_size_mailman_count_all ()
 
 get_size_mailman_count_user ($u)
 
 get_size_mailman_details_user ($u)
 
 get_size_db_sum_all ()
 
 get_size_db_sum_user ($u)
 
 get_size_db_count_all ()
 
 get_size_db_count_user ($u)
 
 get_size_db_details_user ($u)
 
 get_size_unit ($size)
 
 quota_displaybar ($usage, $color_type=1)
 
 hook_admin_del_member ()
 Hook function call when a user is deleted AlternC's standard function called when a user is deleted globals $cuid is the appropriate user. More...
 
 hook_admin_add_member ()
 Hook function called when a user is created This function initialize the user's quotas. More...
 
 alternc_export_conf ()
 Exports all the quota related information for an account. More...
 

Public Attributes

 $disk = Array()
 
 $disk_quota_enable
 
 $quotas
 
 $clquota
 

Private Member Functions

 dummy_for_translation ()
 

Detailed Description

Class for hosting quotas management.

This class manages services' quotas for each user of AlternC. The available quotas for each service is stored in the system.quotas mysql table. The used value is computed by the class using a callback function alternc_quota_check($uid) that may by exported by each service class.
each class may also export a function alternc_quota_names() that returns an array with the quotas names managed by this class.

Definition at line 39 of file m_quota.php.

Member Function Documentation

m_quota::_get_count_sql (   $sql)

Definition at line 440 of file m_quota.php.

References $db, and $r.

Referenced by get_size_db_count_all(), get_size_db_count_user(), get_size_mail_count_all(), get_size_mail_count_domain(), get_size_mailman_count_all(), and get_size_mailman_count_user().

440  {
441  global $db;
442  $db->query($sql);
443  if ($db->num_rows() == 0) {
444  return 0;
445  } else {
446  $db->next_record();
447  $r = $db->Record;
448  return $r['count'];
449  }
450  }
global $db
Definition: bootstrap.php:22
$r
Definition: aws_add.php:77
m_quota::_get_size_and_record_sql (   $sql)

Definition at line 452 of file m_quota.php.

References $db.

Referenced by get_size_db_details_user(), get_size_mail_details_domain(), and get_size_mailman_details_user().

452  {
453  global $db;
454  $db->query($sql);
455  if ($db->num_rows() == 0) {
456  return array();
457  } else {
458  $ret = array();
459  while ($db->next_record()) {
460  $ret[] = $db->Record;
461  }
462  return $ret;
463  }
464  }
global $db
Definition: bootstrap.php:22
m_quota::_get_sum_sql (   $sql)

Definition at line 428 of file m_quota.php.

References $db, and $r.

Referenced by get_size_db_sum_all(), get_size_db_sum_user(), get_size_mail_sum_all(), get_size_mailman_sum_all(), get_size_mailman_sum_domain(), get_size_mailman_sum_user(), get_size_web_sum_all(), and get_size_web_sum_user().

428  {
429  global $db;
430  $db->query($sql);
431  if ($db->num_rows() == 0) {
432  return -1;
433  } else {
434  $db->next_record();
435  $r = $db->Record;
436  return $r['sum'];
437  }
438  }
global $db
Definition: bootstrap.php:22
$r
Definition: aws_add.php:77
m_quota::addquotas ( )

Create default quotas entries for a new user.

The user we are talking about is in the global $cuid.

Definition at line 385 of file m_quota.php.

References $cuid, $db, $err, $q, $ql, $res, $t, $val, addtype(), qlist(), and setquota().

Referenced by hook_admin_add_member().

385  {
386  global $db, $err, $cuid;
387  $err->log("quota", "addquota");
388  $ql = $this->qlist();
389  reset($ql);
390 
391  $db->query("SELECT type,quota FROM defquotas WHERE type='default'");
392  if (!$db->next_record()) {
393  $this->addtype('default');
394  }
395  $db->query("SELECT type FROM membres WHERE uid= ?;", array($cuid));
396  $db->next_record();
397  $t = $db->f("type");
398 
399  foreach ($ql as $res => $val) {
400  $db->query("SELECT value FROM defquotas WHERE quota= ? AND type= ? ;", array($res, $t));
401  $q = $db->next_record() ? $db->f("value") : 0;
402  $this->setquota($res, $q);
403  }
404  return true;
405  }
$val
Definition: tempovars.php:15
addtype($type)
Add an account type for quotas.
Definition: m_quota.php:329
setquota($ressource, $size)
Set the quota for a user (and for a ressource)
Definition: m_quota.php:242
global $db
Definition: bootstrap.php:22
qlist()
List the quota-managed services in the server array the quota names and description (translated) ...
Definition: m_quota.php:117
$err
Definition: bootstrap.php:72
$res
Definition: index.php:127
$t
Definition: dom_editdns.php:58
$cuid
Definition: bootstrap.php:43
m_quota::addtype (   $type)

Add an account type for quotas.

Parameters
string$typeaccount type to be added
Returns
boolean true if all went ok

Definition at line 329 of file m_quota.php.

References $db, $err, $key, $qlist, $val, each(), and qlist().

Referenced by addquotas(), and getdefaults().

329  {
330  global $db, $err;
331  $qlist = $this->qlist();
332  if (empty($type)) {
333  return false;
334  }
335  $type = strtolower($type);
336  if (!preg_match("#^[a-z0-9]*$#", $type)) {
337  $err->raise("quota", "Type can only contains characters a-z and 0-9");
338  return false;
339  }
340  while (list($key, $val) = each($qlist)) {
341  if (!$db->query("INSERT IGNORE INTO defquotas (quota,type) VALUES(?, ?);", array($key, $type)) || $db->affected_rows() == 0) {
342  return false;
343  }
344  }
345  return true;
346  }
$val
Definition: tempovars.php:15
global $db
Definition: bootstrap.php:22
qlist()
List the quota-managed services in the server array the quota names and description (translated) ...
Definition: m_quota.php:117
$err
Definition: bootstrap.php:72
x each(["height","width"], function(e, n){x.cssHooks[n]={get:function(e, r, i){return r?0===e.offsetWidth &&Xt.test(x.css(e,"display"))?x.swap(e, Qt, function(){return sn(e, n, i)}):sn(e, n, i):t}, set:function(e, t, r){var i=r &&Rt(e);return on(e, t, r?an(e, n, r, x.support.boxSizing &&"border-box"===x.css(e,"boxSizing",!1, i), i):0)}}})
$qlist
if(empty($_POST['key'])||empty($_POST['val'])) $key
Definition: tempovars.php:14
m_quota::alternc_export_conf ( )

Exports all the quota related information for an account.

private EXPERIMENTAL function ;)

Definition at line 639 of file m_quota.php.

References $err, $q, and getquota().

639  {
640  global $err;
641  $err->log("quota", "export");
642  $str = " <quota>";
643 
644  $q = $this->getquota();
645  foreach ($q as $k => $v) {
646  $str.=" <$k>\n";
647  $str.=" <used>" . ($v["u"]) . "</used>\n";
648  $str.=" <total>" . ($v["t"]) . "</total>\n";
649  $str.=" </$k>\n";
650  }
651  $str.="</quota>\n";
652  return $str;
653  }
$err
Definition: bootstrap.php:72
getquota($ressource="", $recheck=false)
Return a ressource usage (u) and total quota (t)
Definition: m_quota.php:174
m_quota::cancreate (   $ressource = "")

Check if a user can use a ressource.

Parameters
string$ressourcethe ressource name (a named quota) TRUE if the user can create a ressource (= is there any quota left ?)
Returns
boolean

Definition at line 107 of file m_quota.php.

References $t, and getquota().

107  {
108  $t = $this->getquota($ressource);
109  return $t["u"] < $t["t"];
110  }
$t
Definition: dom_editdns.php:58
getquota($ressource="", $recheck=false)
Return a ressource usage (u) and total quota (t)
Definition: m_quota.php:174
m_quota::create_missing_quota_profile ( )

Definition at line 155 of file m_quota.php.

References $db, $err, $q, and $t.

155  {
156  global $db, $quota, $err;
157  $err->log("quota", "create_missing_quota_profile");
158  $qt = $quota->getquota('', true);
159  $type = $quota->listtype();
160  foreach ($type as $t) {
161  foreach ($qt as $q => $vv) {
162  $db->query("INSERT IGNORE defquotas (value,quota,type) VALUES (0, ?, ?);", array($q, $t));
163  }
164  }
165  return true;
166  }
global $db
Definition: bootstrap.php:22
$err
Definition: bootstrap.php:72
$t
Definition: dom_editdns.php:58
m_quota::delquotas ( )

Erase all quota information about the user.

Definition at line 274 of file m_quota.php.

References $cuid, $db, and $err.

Referenced by hook_admin_del_member().

274  {
275  global $db, $err, $cuid;
276  $err->log("quota", "delquota");
277  $db->query("DELETE FROM quotas WHERE uid= ?;", array($cuid));
278  return true;
279  }
global $db
Definition: bootstrap.php:22
$err
Definition: bootstrap.php:72
$cuid
Definition: bootstrap.php:43
m_quota::deltype (   $type)

Delete an account type for quotas.

Parameters
string$typeaccount type to be deleted
Returns
boolean true if all went ok

Definition at line 369 of file m_quota.php.

References $db.

369  {
370  global $db;
371 
372  if ($db->query("UPDATE membres SET type='default' WHERE type= ? ;", array($type)) &&
373  $db->query("DELETE FROM defquotas WHERE type= ?;", array($type))) {
374  return true;
375  } else {
376  return false;
377  }
378  }
global $db
Definition: bootstrap.php:22
m_quota::display_val (   $type,
  $value 
)

Return a quota value with its unit (when it is a space quota) in MB, GB, TB ...

Parameters
string$typeThe quota type
integer$valueThe quota value
Returns
string a quota value with its unit.

Definition at line 415 of file m_quota.php.

References $value, and format_size().

415  {
416  switch ($type) {
417  case 'bw_web':
418  return format_size($value);
419  case 'web':
420  return format_size($value * 1024);
421  default:
422  return $value;
423  }
424  }
format_size($size, $html=0)
Definition: functions.php:413
$value
m_quota::dummy_for_translation ( )
private

Definition at line 58 of file m_quota.php.

58  {
59  _("quota_web");
60  }
m_quota::get_size_db_count_all ( )

Definition at line 559 of file m_quota.php.

References _get_count_sql().

559  {
560  return $this->_get_count_sql("SELECT COUNT(*) AS count FROM size_db;");
561  }
_get_count_sql($sql)
Definition: m_quota.php:440
m_quota::get_size_db_count_user (   $u)

Definition at line 565 of file m_quota.php.

References _get_count_sql().

565  {
566  return $this->_get_count_sql("SELECT COUNT(*) AS count FROM size_db WHERE db = '{$u}' OR db LIKE '{$u}\_%'");
567  }
_get_count_sql($sql)
Definition: m_quota.php:440
m_quota::get_size_db_details_user (   $u)

Definition at line 571 of file m_quota.php.

References _get_size_and_record_sql().

571  {
572  return $this->_get_size_and_record_sql("SELECT db,size FROM size_db WHERE db='{$u}' OR db LIKE '{$u}\_%';");
573  }
_get_size_and_record_sql($sql)
Definition: m_quota.php:452
m_quota::get_size_db_sum_all ( )

Definition at line 547 of file m_quota.php.

References _get_sum_sql().

547  {
548  return $this->_get_sum_sql("SELECT SUM(size) AS sum FROM size_db;");
549  }
_get_sum_sql($sql)
Definition: m_quota.php:428
m_quota::get_size_db_sum_user (   $u)

Definition at line 553 of file m_quota.php.

References _get_sum_sql().

553  {
554  return $this->_get_sum_sql("SELECT SUM(size) AS sum FROM size_db WHERE db = '{$u}' OR db LIKE '{$u}\_%'");
555  }
_get_sum_sql($sql)
Definition: m_quota.php:428
m_quota::get_size_mail_count_all ( )

Definition at line 493 of file m_quota.php.

References _get_count_sql().

493  {
494  return $this->_get_count_sql("SELECT COUNT(*) AS count FROM mailbox WHERE delivery = 'dovecot';");
495  }
_get_count_sql($sql)
Definition: m_quota.php:440
m_quota::get_size_mail_count_domain (   $dom)

Definition at line 499 of file m_quota.php.

References _get_count_sql().

499  {
500  return $this->_get_count_sql("SELECT COUNT(*) AS count FROM dovecot_view WHERE user LIKE '%@{$dom}'");
501  }
_get_count_sql($sql)
Definition: m_quota.php:440
m_quota::get_size_mail_details_domain (   $dom)

Definition at line 505 of file m_quota.php.

References _get_size_and_record_sql().

505  {
506  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;");
507  }
_get_size_and_record_sql($sql)
Definition: m_quota.php:452
m_quota::get_size_mail_sum_all ( )

Definition at line 480 of file m_quota.php.

References _get_sum_sql().

480  {
481  return $this->_get_sum_sql("SELECT SUM(bytes) AS sum FROM mailbox WHERE delivery = 'dovecot';;");
482  }
_get_sum_sql($sql)
Definition: m_quota.php:428
m_quota::get_size_mail_sum_domain (   $dom)

Definition at line 486 of file m_quota.php.

References $dom.

486  {
487  global $mail;
488  return $mail->get_total_size_for_domain($dom);
489  }
$dom
Definition: whois_test.php:10
m_quota::get_size_mailman_count_all ( )

Definition at line 529 of file m_quota.php.

References _get_count_sql().

529  {
530  return $this->_get_count_sql("SELECT COUNT(*) AS count FROM size_mailman;");
531  }
_get_count_sql($sql)
Definition: m_quota.php:440
m_quota::get_size_mailman_count_user (   $u)

Definition at line 535 of file m_quota.php.

References _get_count_sql().

535  {
536  return $this->_get_count_sql("SELECT COUNT(*) AS count FROM size_mailman WHERE uid = '{$u}'");
537  }
_get_count_sql($sql)
Definition: m_quota.php:440
m_quota::get_size_mailman_details_user (   $u)

Definition at line 541 of file m_quota.php.

References _get_size_and_record_sql().

541  {
542  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");
543  }
_get_size_and_record_sql($sql)
Definition: m_quota.php:452
m_quota::get_size_mailman_sum_all ( )

Definition at line 511 of file m_quota.php.

References _get_sum_sql().

511  {
512  return $this->_get_sum_sql("SELECT SUM(size) AS sum FROM size_mailman;");
513  }
_get_sum_sql($sql)
Definition: m_quota.php:428
m_quota::get_size_mailman_sum_domain (   $dom)

Definition at line 517 of file m_quota.php.

References _get_sum_sql().

517  {
518  return $this->_get_sum_sql("SELECT SUM(size) AS sum FROM size_mailman WHERE list LIKE '%@{$dom}'");
519  }
_get_sum_sql($sql)
Definition: m_quota.php:428
m_quota::get_size_mailman_sum_user (   $u)

Definition at line 523 of file m_quota.php.

References _get_sum_sql().

523  {
524  return $this->_get_sum_sql("SELECT SUM(size) AS sum FROM size_mailman WHERE uid = '{$u}'");
525  }
_get_sum_sql($sql)
Definition: m_quota.php:428
m_quota::get_size_unit (   $size)

Definition at line 577 of file m_quota.php.

References $units, and $value.

577  {
578  $units = array(1073741824 => _("GB"), 1048576 => _("MB"), 1024 => _("KB"), 0 => _("B"));
579  foreach ($units as $value => $unit) {
580  if ($size >= $value) {
581  $size=$size/($value?$value:1);
582  return array('size' => $size, 'unit' => $unit);
583  }
584  }
585  }
$units
$value
m_quota::get_size_web_sum_all ( )

Definition at line 468 of file m_quota.php.

References _get_sum_sql().

468  {
469  return $this->_get_sum_sql("SELECT SUM(size) AS sum FROM size_web;");
470  }
_get_sum_sql($sql)
Definition: m_quota.php:428
m_quota::get_size_web_sum_user (   $u)

Definition at line 474 of file m_quota.php.

References _get_sum_sql().

474  {
475  return $this->_get_sum_sql("SELECT SUM(size) AS sum FROM size_web WHERE uid='$u';");
476  }
_get_sum_sql($sql)
Definition: m_quota.php:428
m_quota::getdefaults ( )

Get the default quotas as an associative array.

Returns
array the array of the default quotas

Definition at line 286 of file m_quota.php.

References $c, $db, and addtype().

286  {
287  global $db;
288  $c = array();
289 
290  $db->query("SELECT type,quota FROM defquotas WHERE type='default'");
291  if (!$db->next_record()) {
292  $this->addtype('default');
293  }
294  $db->query("SELECT value,quota,type FROM defquotas ORDER BY type,quota");
295  while ($db->next_record()) {
296  $type = $db->f("type");
297  $c[$type][$db->f("quota")] = $db->f("value");
298  }
299  return $c;
300  }
addtype($type)
Add an account type for quotas.
Definition: m_quota.php:329
global $db
Definition: bootstrap.php:22
$c
Definition: bootstrap.php:47
m_quota::getquota (   $ressource = "",
  $recheck = false 
)

Return a ressource usage (u) and total quota (t)

Parameters
string$ressourceressource to get quota of array the quota used and total for this ressource (or for all ressource if unspecified)

Definition at line 174 of file m_quota.php.

References $cuid, $db, $err, $hooks, $key, $mem, $quotas, $r, $res, $val, each(), and null.

Referenced by alternc_export_conf(), cancreate(), hook_admin_add_member(), hook_menu(), and qlist().

174  {
175  global $db, $err, $cuid, $get_quota_cache, $hooks, $mem;
176  $err->log("quota", "getquota", $ressource);
177  if ($recheck) { // rebuilding quota
178  $get_quota_cache = null;
179  $this->quotas = array();
180  }
181  if (!empty($get_quota_cache[$cuid])) {
182  // This function is called many time each webpage, so I cache the result
183  $this->quotas = $get_quota_cache[$cuid];
184  } else {
185  $res = $hooks->invoke("hook_quota_get");
186  foreach ($res as $r) {
187  $this->quotas[$r['name']] = $r;
188  $this->quotas[$r['name']]['u'] = $r['used']; // retrocompatibilit√©
189  $this->quotas[$r['name']]['t'] = 0; // Default quota = 0
190  }
191  reset($this->disk);
192 
193  if (!empty($this->disk)) { // Check if there are some disk quota to check
194  // Look if there are some cached value
195  $disk_cached = $mem->session_tempo_params_get('quota_cache_disk');
196 
197  while (list($key, $val) = each($this->disk)) {
198  $a = array();
199  if (
200  isset($disk_cached[$val]) && !empty($disk_cached[$val]) && $disk_cached[$val]['uid'] == $cuid && $disk_cached[$val]['timestamp'] > ( time() - (90) ) // Cache, en seconde
201  ) {
202  // If there is a cached value
203  $a = $disk_cached[$val];
204  } else {
205  exec("/usr/lib/alternc/quota_get " . intval($cuid), $ak);
206  $a['u'] = intval($ak[0]);
207  $a['t'] = @intval($ak[1]);
208  $a['timestamp'] = time();
209  $a['uid'] = $cuid;
210  $disk_cached = $mem->session_tempo_params_set('quota_cache_disk', array($val => $a));
211  }
212  $this->quotas[$val] = array("name" => "$val", 'description' => _("quota_" . $val), "t" => $a['t'], "u" => $a['u']);
213  }
214  }
215 
216  // Get the allowed quota from database.
217  $db->query("select name, total from quotas where uid= ? ;", array($cuid));
218  while ($db->next_record()) {
219  $this->quotas[$db->f('name')]['t'] = $db->f('total');
220  }
221 
222  $get_quota_cache[$cuid] = $this->quotas;
223  }
224 
225  if ($ressource) {
226  if (isset($this->quotas[$ressource])) {
227  return $this->quotas[$ressource];
228  } else {
229  return 0;
230  }
231  } else {
232  return $this->quotas;
233  }
234  }
$hooks
Definition: bootstrap.php:74
$val
Definition: tempovars.php:15
global $db
Definition: bootstrap.php:22
$r
Definition: aws_add.php:77
$err
Definition: bootstrap.php:72
PR null
Definition: lang-css.js:1
$res
Definition: index.php:127
$cuid
Definition: bootstrap.php:43
x each(["height","width"], function(e, n){x.cssHooks[n]={get:function(e, r, i){return r?0===e.offsetWidth &&Xt.test(x.css(e,"display"))?x.swap(e, Qt, function(){return sn(e, n, i)}):sn(e, n, i):t}, set:function(e, t, r){var i=r &&Rt(e);return on(e, t, r?an(e, n, r, x.support.boxSizing &&"border-box"===x.css(e,"boxSizing",!1, i), i):0)}}})
if(empty($_POST['key'])||empty($_POST['val'])) $key
Definition: tempovars.php:14
$mem
Definition: bootstrap.php:71
m_quota::hook_admin_add_member ( )

Hook function called when a user is created This function initialize the user's quotas.

globals $cuid is the appropriate user

Definition at line 626 of file m_quota.php.

References $err, addquotas(), and getquota().

626  {
627  global $err;
628  $err->log("quota", "hook_admin_add_member");
629  $this->addquotas();
630  $this->getquota('', true); // actualise quota
631  }
addquotas()
Create default quotas entries for a new user.
Definition: m_quota.php:385
$err
Definition: bootstrap.php:72
getquota($ressource="", $recheck=false)
Return a ressource usage (u) and total quota (t)
Definition: m_quota.php:174
m_quota::hook_admin_del_member ( )

Hook function call when a user is deleted AlternC's standard function called when a user is deleted globals $cuid is the appropriate user.

Definition at line 616 of file m_quota.php.

References delquotas().

616  {
617  $this->delquotas();
618  }
delquotas()
Erase all quota information about the user.
Definition: m_quota.php:274
m_quota::hook_homepageblock ( )

Definition at line 90 of file m_quota.php.

90  {
91  return (object)Array(
92  'pos' => 20,
93  'call'=> function() {
94  define("QUOTASONE","1");
95  },
96  'include' => "quotas_oneuser.php"
97  );
98  }
m_quota::hook_menu ( )

Definition at line 62 of file m_quota.php.

References $key, $q, $value, format_size(), and getquota().

62  {
63  $obj = array(
64  'title' => _("Show my quotas"),
65  'ico' => 'images/quota.png',
66  'link' => 'toggle',
67  'pos' => 110,
68  'divclass' => 'menu-quota',
69  'links' => array(),
70  );
71 
72  $q = $this->getquota();
73 
74  foreach ($q as $key=>$value)
75  if (($key=="web")||(isset($value['in_menu'])&&$value['in_menu'])) {
76  if (!isset($q[$key]["u"]) || empty($q[$key]["t"])) {
77  continue;
78  }
79 
80  $usage_percent = (int) ($q[$key]["u"] / $q[$key]["t"] * 100);
81  $obj['links'][] = array('txt' => _("quota_" . $key) . " " . sprintf(_("%s%% of %s"), $usage_percent, format_size($q[$key]["t"] * 1024)), 'url' => 'quota_show.php');
82  $obj['links'][] = array('txt' => 'progressbar', 'total' => $q[$key]["t"], 'used' => $q[$key]["u"]);
83  }
84 
85  // do not return menu item if there is no quota
86  if (!count($obj['links'])) return false;
87  return $obj;
88  }
format_size($size, $html=0)
Definition: functions.php:413
$value
if(empty($_POST['key'])||empty($_POST['val'])) $key
Definition: tempovars.php:14
getquota($ressource="", $recheck=false)
Return a ressource usage (u) and total quota (t)
Definition: m_quota.php:174
m_quota::listtype ( )

List for quotas.

Returns
array

Definition at line 353 of file m_quota.php.

References $db, and $t.

353  {
354  global $db;
355  $db->query("SELECT distinct(type) FROM defquotas ORDER by type");
356  $t = array();
357  while ($db->next_record()) {
358  $t[] = $db->f("type");
359  }
360  return $t;
361  }
global $db
Definition: bootstrap.php:22
$t
Definition: dom_editdns.php:58
m_quota::m_quota ( )

Constructor.

Definition at line 51 of file m_quota.php.

References variable_get().

51  {
52  $this->disk_quota_enable = variable_get('disk_quota_enable', 1, 'Are disk quota enabled for this server', array('desc' => 'Enabled', 'type' => 'boolean'));
53  if ($this->disk_quota_enable) {
54  $this->disk = Array("web" => "web");
55  }
56  }
variable_get($name, $default=null, $createit_comment=null)
Return a persistent variable.
Definition: variables.php:90
m_quota::qlist ( )

List the quota-managed services in the server array the quota names and description (translated)

Definition at line 117 of file m_quota.php.

References $key, $qlist, $val, each(), and getquota().

Referenced by addquotas(), addtype(), and setdefaults().

117  {
118  $qlist = array();
119  reset($this->disk);
120  while (list($key, $val) = each($this->disk)) {
121  $qlist[$key] = _("quota_" . $key); // those are specific disks quotas.
122  }
123 
124  foreach ($this->getquota() as $qq) {
125  if (isset($qq['name'])) {
126  $qlist[$qq['name']] = $qq['description'];
127  }
128  }
129  return $qlist;
130  }
$val
Definition: tempovars.php:15
x each(["height","width"], function(e, n){x.cssHooks[n]={get:function(e, r, i){return r?0===e.offsetWidth &&Xt.test(x.css(e,"display"))?x.swap(e, Qt, function(){return sn(e, n, i)}):sn(e, n, i):t}, set:function(e, t, r){var i=r &&Rt(e);return on(e, t, r?an(e, n, r, x.support.boxSizing &&"border-box"===x.css(e,"boxSizing",!1, i), i):0)}}})
$qlist
if(empty($_POST['key'])||empty($_POST['val'])) $key
Definition: tempovars.php:14
getquota($ressource="", $recheck=false)
Return a ressource usage (u) and total quota (t)
Definition: m_quota.php:174
m_quota::quota_displaybar (   $usage,
  $color_type = 1 
)

Definition at line 592 of file m_quota.php.

References PercentToColor().

592  {
593  if ($color_type == 1) {
594  $csscolor = " background-color:" . PercentToColor($usage);
595  } elseif ($color_type == 2) {
596  $csscolor = " background-color:" . PercentToColor(100 - $usage);
597  } else {
598  $csscolor = "";
599  }
600 
601 
602  echo '<div class="progress-bar">';
603  echo '<div class="barre" style="width:' . $usage . '%;' . $csscolor . '" ></div>';
604  echo '<div class="txt">' . $usage . '%</div>';
605  echo '</div>';
606  }
PercentToColor($p=0)
Definition: functions.php:1042
m_quota::setdefaults (   $newq)

Set the default quotas.

Parameters
arrayassociative array of quota (key=>val)

Definition at line 307 of file m_quota.php.

References $db, $qlist, $value, and qlist().

307  {
308  global $db;
309  $qlist = $this->qlist();
310 
311  foreach ($newq as $type => $quotas) {
312  foreach ($quotas as $qname => $value) {
313  if (array_key_exists($qname, $qlist)) {
314  if (!$db->query("REPLACE INTO defquotas (value,quota,type) VALUES ( ?, ?, ?); ", array($value, $qname, $type))) {
315  return false;
316  }
317  }
318  }
319  }
320  return true;
321  }
global $db
Definition: bootstrap.php:22
qlist()
List the quota-managed services in the server array the quota names and description (translated) ...
Definition: m_quota.php:117
$value
$qlist
m_quota::setquota (   $ressource,
  $size 
)

Set the quota for a user (and for a ressource)

Parameters
string$ressourceressource to set quota of
integersize of the quota (available or used)

Definition at line 242 of file m_quota.php.

References $cuid, $db, and $err.

Referenced by addquotas().

242  {
243  global $err, $db, $cuid;
244  $err->log("quota", "setquota", $ressource . "/" . $size);
245  if (floatval($size) == 0) {
246  $size = "0";
247  }
248  if (isset($this->disk[$ressource])) {
249  // It's a disk resource, update it with shell command
250  exec("sudo /usr/lib/alternc/quota_edit " . intval($cuid) . " " . intval($size) . " &> /dev/null &");
251  // Now we check that the value has been written properly :
252  $a = array();
253  exec("sudo /usr/lib/alternc/quota_get " . intval($cuid) . " &> /dev/null &", $a);
254  if (!isset($a[1]) || $size != $a[1]) {
255  $err->raise("quota", _("Error writing the quota entry!"));
256  return false;
257  }
258  }
259  // We check that this ressource exists for this client :
260  $db->query("SELECT * FROM quotas WHERE uid= ? AND name= ? ", array($cuid, $ressource));
261  if ($db->num_rows()) {
262  $db->query("UPDATE quotas SET total= ? WHERE uid= ? AND name= ?;", array($size, $cuid, $ressource));
263  } else {
264  $db->query("INSERT INTO quotas (uid,name,total) VALUES (?, ?, ?);", array($cuid, $ressource, $size));
265  }
266  return true;
267  }
global $db
Definition: bootstrap.php:22
$err
Definition: bootstrap.php:72
$cuid
Definition: bootstrap.php:43
m_quota::synchronise_user_profile ( )

Synchronise the quotas of the users with the quota of the user's profile.

If the user have a greater quota than the profile, no change. If the quota entry doesn't exist for the user, create it with the defaults value.

Definition at line 139 of file m_quota.php.

References $db, $err, and $q.

139  {
140  global $db, $err;
141  $err->log("quota", "synchronise_user_profile");
142  $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);";
143  if (!$db->query($q)) {
144  return false;
145  }
146  return true;
147  }
global $db
Definition: bootstrap.php:22
$err
Definition: bootstrap.php:72

Member Data Documentation

m_quota::$clquota

Definition at line 44 of file m_quota.php.

m_quota::$disk = Array()

Definition at line 41 of file m_quota.php.

m_quota::$disk_quota_enable

Definition at line 42 of file m_quota.php.

m_quota::$quotas

Definition at line 43 of file m_quota.php.

Referenced by getquota().


The documentation for this class was generated from the following file: