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 types of 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_quota_user_cat ($uid, $name)
 
 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_sum_user ($u)
 
 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)
 show a progress-bar color_type : 0 = No colo change 1 = Progress from green to red depending on percentage 2 = Progress from red to green depending on percentage More...
 
 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
 
 $disk_quota_not_blocking
 
 $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 34 of file m_quota.php.

Member Function Documentation

m_quota::_get_count_sql (   $sql)

Definition at line 444 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().

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

Definition at line 457 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().

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

Definition at line 431 of file m_quota.php.

References $db, and $r.

Referenced by get_quota_user_cat(), get_size_db_sum_all(), get_size_db_sum_user(), get_size_mail_sum_all(), get_size_mail_sum_user(), 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().

431  {
432  global $db;
433  $db->query($sql);
434  if ($db->num_rows() == 0) {
435  return -1;
436  } else {
437  $db->next_record();
438  $r = $db->Record;
439  return $r['sum'];
440  }
441  }
global $db
Definition: bootstrap.php:22
$r
Definition: aws_add.php:75
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 389 of file m_quota.php.

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

Referenced by hook_admin_add_member().

389  {
390  global $db, $msg, $cuid;
391  $msg->log("quota", "addquota");
392  $ql = $this->qlist();
393  reset($ql);
394 
395  $db->query("SELECT type,quota FROM defquotas WHERE type='default'");
396  if (!$db->next_record()) {
397  $this->addtype('default');
398  }
399  $db->query("SELECT type FROM membres WHERE uid= ?;", array($cuid));
400  $db->next_record();
401  $t = $db->f("type");
402 
403  foreach ($ql as $res => $val) {
404  $db->query("SELECT value FROM defquotas WHERE quota= ? AND type= ? ;", array($res, $t));
405  $q = $db->next_record() ? $db->f("value") : 0;
406  $this->setquota($res, $q);
407  }
408  return true;
409  }
$val
Definition: tempovars.php:15
addtype($type)
Add an account type for quotas.
Definition: m_quota.php:335
setquota($ressource, $size)
Set the quota for a user (and for a ressource)
Definition: m_quota.php:249
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:118
$res
Definition: index.php:125
$msg
Definition: config.php:155
foreach($domaines_user as $domaine) $t
$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 335 of file m_quota.php.

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

Referenced by addquotas(), and getdefaults().

335  {
336  global $db, $msg;
337  $qlist = $this->qlist();
338  if (empty($type)) {
339  return false;
340  }
341  $type = strtolower($type);
342  if (!preg_match("#^[a-z0-9]*$#", $type)) {
343  $msg->raise("ERROR", "quota", _("Type can only contains characters a-z and 0-9"));
344  return false;
345  }
346  while (list($key, $val) = each($qlist)) {
347  if (!$db->query("INSERT IGNORE INTO defquotas (quota,type) VALUES(?, ?);", array($key, $type)) || $db->affected_rows() == 0) {
348  return false;
349  }
350  }
351  return true;
352  }
$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:118
$msg
Definition: config.php:155
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 655 of file m_quota.php.

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

655  {
656  global $msg;
657  $msg->log("quota", "export");
658  $str = " <quota>";
659 
660  $q = $this->getquota();
661  foreach ($q as $k => $v) {
662  $str.=" <$k>\n";
663  $str.=" <used>" . ($v["u"]) . "</used>\n";
664  $str.=" <total>" . ($v["t"]) . "</total>\n";
665  $str.=" </$k>\n";
666  }
667  $str.="</quota>\n";
668  return $str;
669  }
$msg
Definition: config.php:155
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 109 of file m_quota.php.

References $t, and getquota().

109  {
110  $t = $this->getquota($ressource);
111  return $t["u"] < $t["t"];
112  }
foreach($domaines_user as $domaine) $t
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 156 of file m_quota.php.

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

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

Erase all quota information about the user.

Definition at line 280 of file m_quota.php.

References $cuid, $db, and $msg.

Referenced by hook_admin_del_member().

280  {
281  global $db, $msg, $cuid;
282  $msg->log("quota", "delquota");
283  $db->query("DELETE FROM quotas WHERE uid= ?;", array($cuid));
284  return true;
285  }
global $db
Definition: bootstrap.php:22
$msg
Definition: config.php:155
$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 374 of file m_quota.php.

References $db.

374  {
375  global $db;
376 
377  if ($db->query("UPDATE membres SET type='default' WHERE type= ? ;", array($type)) &&
378  $db->query("DELETE FROM defquotas WHERE type= ?;", array($type))) {
379  return true;
380  } else {
381  return false;
382  }
383  }
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 418 of file m_quota.php.

References $value, and format_size().

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

Definition at line 56 of file m_quota.php.

56  {
57  _("quota_web");
58  }
m_quota::get_quota_user_cat (   $uid,
  $name 
)

Definition at line 473 of file m_quota.php.

References _get_sum_sql().

Referenced by getquota().

473  {
474  return $this->_get_sum_sql("SELECT SUM(total) AS sum FROM quotas WHERE uid='$uid' AND name='$name';");
475  }
_get_sum_sql($sql)
Definition: m_quota.php:431
m_quota::get_size_db_count_all ( )

Definition at line 576 of file m_quota.php.

References _get_count_sql().

576  {
577  return $this->_get_count_sql("SELECT COUNT(*) AS count FROM size_db;");
578  }
_get_count_sql($sql)
Definition: m_quota.php:444
m_quota::get_size_db_count_user (   $u)

Definition at line 582 of file m_quota.php.

References _get_count_sql().

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

Definition at line 588 of file m_quota.php.

References _get_size_and_record_sql().

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

Definition at line 564 of file m_quota.php.

References _get_sum_sql().

564  {
565  return $this->_get_sum_sql("SELECT SUM(size) AS sum FROM size_db;");
566  }
_get_sum_sql($sql)
Definition: m_quota.php:431
m_quota::get_size_db_sum_user (   $u)

Definition at line 570 of file m_quota.php.

References _get_sum_sql().

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

Definition at line 510 of file m_quota.php.

References _get_count_sql().

510  {
511  return $this->_get_count_sql("SELECT COUNT(*) AS count FROM dovecot_quota;");
512  }
_get_count_sql($sql)
Definition: m_quota.php:444
m_quota::get_size_mail_count_domain (   $dom)

Definition at line 516 of file m_quota.php.

References _get_count_sql().

516  {
517  return $this->_get_count_sql("SELECT COUNT(*) AS count FROM dovecot_quota WHERE user LIKE '%@{$dom}'");
518  }
_get_count_sql($sql)
Definition: m_quota.php:444
m_quota::get_size_mail_details_domain (   $dom)

Definition at line 522 of file m_quota.php.

References _get_size_and_record_sql().

522  {
523  return $this->_get_size_and_record_sql("SELECT user as alias,quota_dovecot as size FROM dovecot_quota WHERE user LIKE '%@{$dom}' ORDER BY alias;");
524  }
_get_size_and_record_sql($sql)
Definition: m_quota.php:457
m_quota::get_size_mail_sum_all ( )

Definition at line 491 of file m_quota.php.

References _get_sum_sql().

491  {
492  return $this->_get_sum_sql("SELECT SUM(quota_dovecot) AS sum FROM dovecot_quota ;");
493  }
_get_sum_sql($sql)
Definition: m_quota.php:431
m_quota::get_size_mail_sum_domain (   $dom)

Definition at line 497 of file m_quota.php.

References $dom.

497  {
498  global $mail;
499  return $mail->get_total_size_for_domain($dom);
500  }
$dom
Definition: whois_test.php:10
m_quota::get_size_mail_sum_user (   $u)

Definition at line 504 of file m_quota.php.

References _get_sum_sql().

504  {
505  return $this->_get_sum_sql("SELECT SUM(quota_dovecot) as sum FROM dovecot_quota WHERE user IN (SELECT CONCAT(a.address, '@', d.domaine) as mail FROM `address` as a INNER JOIN domaines as d ON a.domain_id = d.id WHERE d.compte = '$u' AND a.type ='')");
506  }
_get_sum_sql($sql)
Definition: m_quota.php:431
m_quota::get_size_mailman_count_all ( )

Definition at line 546 of file m_quota.php.

References _get_count_sql().

546  {
547  return $this->_get_count_sql("SELECT COUNT(*) AS count FROM size_mailman;");
548  }
_get_count_sql($sql)
Definition: m_quota.php:444
m_quota::get_size_mailman_count_user (   $u)

Definition at line 552 of file m_quota.php.

References _get_count_sql().

552  {
553  return $this->_get_count_sql("SELECT COUNT(*) AS count FROM size_mailman WHERE uid = '{$u}'");
554  }
_get_count_sql($sql)
Definition: m_quota.php:444
m_quota::get_size_mailman_details_user (   $u)

Definition at line 558 of file m_quota.php.

References _get_size_and_record_sql().

558  {
559  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");
560  }
_get_size_and_record_sql($sql)
Definition: m_quota.php:457
m_quota::get_size_mailman_sum_all ( )

Definition at line 528 of file m_quota.php.

References _get_sum_sql().

528  {
529  return $this->_get_sum_sql("SELECT SUM(size) AS sum FROM size_mailman;");
530  }
_get_sum_sql($sql)
Definition: m_quota.php:431
m_quota::get_size_mailman_sum_domain (   $dom)

Definition at line 534 of file m_quota.php.

References _get_sum_sql().

534  {
535  return $this->_get_sum_sql("SELECT SUM(size) AS sum FROM size_mailman s INNER JOIN mailman m ON s.list = m.list AND s.uid = m.uid WHERE m.domain = '$dom'");
536  }
_get_sum_sql($sql)
Definition: m_quota.php:431
m_quota::get_size_mailman_sum_user (   $u)

Definition at line 540 of file m_quota.php.

References _get_sum_sql().

540  {
541  return $this->_get_sum_sql("SELECT SUM(size) AS sum FROM size_mailman WHERE uid = '{$u}'");
542  }
_get_sum_sql($sql)
Definition: m_quota.php:431
m_quota::get_size_unit (   $size)

Definition at line 594 of file m_quota.php.

References $units, and $value.

594  {
595  $units = array(1073741824 => _("GB"), 1048576 => _("MB"), 1024 => _("KB"), 0 => _("B"));
596  foreach ($units as $value => $unit) {
597  if ($size >= $value) {
598  $size=$size/($value?$value:1);
599  return array('size' => $size, 'unit' => $unit);
600  }
601  }
602  }
$units
$value
m_quota::get_size_web_sum_all ( )

Definition at line 479 of file m_quota.php.

References _get_sum_sql().

479  {
480  return $this->_get_sum_sql("SELECT SUM(size) AS sum FROM size_web;");
481  }
_get_sum_sql($sql)
Definition: m_quota.php:431
m_quota::get_size_web_sum_user (   $u)

Definition at line 485 of file m_quota.php.

References _get_sum_sql().

Referenced by getquota().

485  {
486  return $this->_get_sum_sql("SELECT SUM(size) AS sum FROM size_web WHERE uid='$u';");
487  }
_get_sum_sql($sql)
Definition: m_quota.php:431
m_quota::getdefaults ( )

Get the default quotas as an associative array.

Returns
array the array of the default quotas

Definition at line 292 of file m_quota.php.

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

292  {
293  global $db;
294  $c = array();
295 
296  $db->query("SELECT type,quota FROM defquotas WHERE type='default'");
297  if (!$db->next_record()) {
298  $this->addtype('default');
299  }
300  $db->query("SELECT value,quota,type FROM defquotas ORDER BY type,quota");
301  while ($db->next_record()) {
302  $type = $db->f("type");
303  $c[$type][$db->f("quota")] = $db->f("value");
304  }
305  return $c;
306  }
addtype($type)
Add an account type for quotas.
Definition: m_quota.php:335
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, $hooks, $key, $mem, $msg, $quotas, $r, $res, $val, each(), get_quota_user_cat(), get_size_web_sum_user(), and null.

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

174  {
175  global $db, $msg, $cuid, $get_quota_cache, $hooks, $mem;
176  $msg->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']; // retrocompatibility
189  if (isset($r['sizeondisk']))
190  $this->quotas[$r['name']]['s'] = $r['sizeondisk'];
191  $this->quotas[$r['name']]['t'] = 0; // Default quota = 0
192  }
193  reset($this->disk);
194 
195  if (!empty($this->disk)) { // Check if there are some disk quota to check
196  // Look if there are some cached value
197  $disk_cached = $mem->session_tempo_params_get('quota_cache_disk');
198 
199  while (list($key, $val) = each($this->disk)) {
200  $a = array();
201  if (
202  isset($disk_cached[$val]) && !empty($disk_cached[$val]) && $disk_cached[$val]['uid'] == $cuid && $disk_cached[$val]['timestamp'] > ( time() - (90) ) // Cache, en seconde
203  ) {
204  // If there is a cached value
205  $a = $disk_cached[$val];
206  } else {
207  if ($this->disk_quota_not_blocking) {
208  $a['u'] = $this->get_size_web_sum_user($cuid);
209  $a['t'] = $this->get_quota_user_cat($cuid, 'web');
210  } else {
211  exec("/usr/lib/alternc/quota_get " . intval($cuid), $ak);
212  $a['u'] = intval($ak[0]);
213  $a['t'] = @intval($ak[1]);
214  }
215  $a['sizeondisk'] = $a['u'];
216  $a['timestamp'] = time();
217  $a['uid'] = $cuid;
218  $disk_cached = $mem->session_tempo_params_set('quota_cache_disk', array($val => $a));
219  }
220  $this->quotas[$val] = array("name" => "$val", 'description' => _("Web disk space"), "s" => $a['sizeondisk'], "t" => $a['t'], "u" => $a['u']);
221  }
222  }
223 
224  // Get the allowed quota from database.
225  $db->query("select name, total from quotas where uid= ? ;", array($cuid));
226  while ($db->next_record()) {
227  $this->quotas[$db->f('name')]['t'] = $db->f('total');
228  }
229 
230  $get_quota_cache[$cuid] = $this->quotas;
231  }
232 
233  if ($ressource) {
234  if (isset($this->quotas[$ressource])) {
235  return $this->quotas[$ressource];
236  } else {
237  return 0;
238  }
239  } else {
240  return $this->quotas;
241  }
242  }
get_size_web_sum_user($u)
Definition: m_quota.php:485
$hooks
Definition: bootstrap.php:74
$val
Definition: tempovars.php:15
global $db
Definition: bootstrap.php:22
$r
Definition: aws_add.php:75
PR null
Definition: lang-css.js:1
$res
Definition: index.php:125
$msg
Definition: config.php:155
$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)}}})
get_quota_user_cat($uid, $name)
Definition: m_quota.php:473
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 643 of file m_quota.php.

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

643  {
644  global $msg;
645  $msg->log("quota", "hook_admin_add_member");
646  $this->addquotas();
647  $this->getquota('', true); // actualise quota
648  }
addquotas()
Create default quotas entries for a new user.
Definition: m_quota.php:389
$msg
Definition: config.php:155
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 634 of file m_quota.php.

References delquotas().

634  {
635  $this->delquotas();
636  }
delquotas()
Erase all quota information about the user.
Definition: m_quota.php:280
m_quota::hook_homepageblock ( )

Definition at line 93 of file m_quota.php.

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

Definition at line 61 of file m_quota.php.

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

61  {
62  global $cuid, $mem, $quota;
63 
64  $obj = array(
65  'title' => _("Show my quotas"),
66  'ico' => 'images/quota.png',
67  'link' => 'toggle',
68  'pos' => 5,
69  'divclass' => 'menu-quota',
70  'links' => array(),
71  );
72 
73  $q = $this->getquota();
74 
75  foreach ($q as $key=>$value)
76  if (($key=="web")||(isset($value['in_menu'])&&$value['in_menu'])) {
77  if (!isset($q[$key]["u"]) || empty($q[$key]["t"])) {
78  continue;
79  }
80 
81  $totalsize_used = $quota->get_size_web_sum_user($cuid) + $quota->get_size_mailman_sum_user($cuid) + ($quota->get_size_db_sum_user($mem->user["login"]) + $quota->get_size_mail_sum_user($cuid))/1024;
82  $usage_percent = (int) ($totalsize_used / $q[$key]["t"] * 100);
83  $obj['links'][] = array('txt' => _("quota_" . $key) . " " . sprintf(_("%s%% of %s"), $usage_percent, format_size($q[$key]["t"] * 1024)), 'url' => 'quota_show.php');
84  $obj['links'][] = array('txt' => 'progressbar', 'total' => $q[$key]["t"], 'used' => $totalsize_used);
85  }
86 
87  // do not return menu item if there is no quota
88  if (!count($obj['links'])) return false;
89  return $obj;
90  }
format_size($size, $html=0)
Definition: functions.php:430
$value
$cuid
Definition: bootstrap.php:43
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
$mem
Definition: bootstrap.php:71
m_quota::listtype ( )

List types of quotas.

Returns
array

Definition at line 359 of file m_quota.php.

References $db, and $t.

359  {
360  global $db;
361  $db->query("SELECT distinct(type) FROM defquotas ORDER by type");
362  $t = array();
363  while ($db->next_record()) {
364  $t[] = $db->f("type");
365  }
366  return $t;
367  }
global $db
Definition: bootstrap.php:22
foreach($domaines_user as $domaine) $t
m_quota::m_quota ( )

Constructor.

Definition at line 46 of file m_quota.php.

References variable_get().

46  {
47  $this->disk_quota_enable = variable_get('disk_quota_enable', 1, 'Are disk quota enabled for this server', array('desc' => 'Enabled', 'type' => 'boolean'));
48  if ($this->disk_quota_enable) {
49  $this->disk = Array("web" => "web");
50 
51  $this->disk_quota_not_blocking = variable_get('disk_quota_not_blocking', 1, "0 - Block data when quota are exceeded (you need a working quota system) | 1 - Just show quota but don't block anything", array('desc' => 'Enabled', 'type' => 'boolean'));
52  }
53  }
variable_get($name, $default=null, $createit_comment=null)
Return a persistent variable.
Definition: variables.php:85
m_quota::qlist ( )

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

Definition at line 118 of file m_quota.php.

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

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

118  {
119  $qlist = array();
120  reset($this->disk);
121  while (list($key, $val) = each($this->disk)) {
122  $qlist[$key] = _("quota_" . $key); // those are specific disks quotas.
123  }
124 
125  foreach ($this->getquota() as $qq) {
126  if (isset($qq['name'])) {
127  $qlist[$qq['name']] = $qq['description'];
128  }
129  }
130  return $qlist;
131  }
$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 
)

show a progress-bar color_type : 0 = No colo change 1 = Progress from green to red depending on percentage 2 = Progress from red to green depending on percentage

Definition at line 611 of file m_quota.php.

References elseif, and PercentToColor().

611  {
612  if ($color_type == 1) {
613  $csscolor = " background-color:" . PercentToColor($usage);
614  } elseif ($color_type == 2) {
615  $csscolor = " background-color:" . PercentToColor(100 - $usage);
616  } else {
617  $csscolor = "";
618  }
619 
620  echo '<div class="progress-bar">';
621  echo '<div class="barre" style="width:' . $usage . '%;' . $csscolor . '" ></div>';
622  echo '<div class="txt">' . $usage . '%</div>';
623  echo '</div>';
624  }
PercentToColor($p=0)
Definition: functions.php:1094
if(empty($site_name)) elseif($piwik->site_add($site_name, $site_urls))
m_quota::setdefaults (   $newq)

Set the default quotas.

Parameters
arrayassociative array of quota (key=>val)

Definition at line 313 of file m_quota.php.

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

313  {
314  global $db;
315  $qlist = $this->qlist();
316 
317  foreach ($newq as $type => $quotas) {
318  foreach ($quotas as $qname => $value) {
319  if (array_key_exists($qname, $qlist)) {
320  if (!$db->query("REPLACE INTO defquotas (value,quota,type) VALUES ( ?, ?, ?); ", array($value, $qname, $type))) {
321  return false;
322  }
323  }
324  }
325  }
326  return true;
327  }
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:118
$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 249 of file m_quota.php.

References $cuid, $db, and $msg.

Referenced by addquotas().

249  {
250  global $msg, $db, $cuid;
251  $msg->log("quota", "setquota", $ressource . "/" . $size);
252  if (floatval($size) == 0) {
253  $size = "0";
254  }
255  if (!$this->disk_quota_not_blocking && isset($this->disk[$ressource])) {
256  // It's a disk resource, update it with shell command
257  exec("sudo /usr/lib/alternc/quota_edit " . intval($cuid) . " " . intval($size) . " &> /dev/null &");
258  // Now we check that the value has been written properly :
259  $a = array();
260  exec("sudo /usr/lib/alternc/quota_get " . intval($cuid) . " &> /dev/null &", $a);
261  if (!isset($a[1]) || $size != $a[1]) {
262  $msg->raise("ERROR", "quota", _("Error writing the quota entry!"));
263  return false;
264  }
265  }
266  // We check that this ressource exists for this client :
267  $db->query("SELECT * FROM quotas WHERE uid= ? AND name= ? ", array($cuid, $ressource));
268  if ($db->num_rows()) {
269  $db->query("UPDATE quotas SET total= ? WHERE uid= ? AND name= ?;", array($size, $cuid, $ressource));
270  } else {
271  $db->query("INSERT INTO quotas (uid,name,total) VALUES (?, ?, ?);", array($cuid, $ressource, $size));
272  }
273  return true;
274  }
global $db
Definition: bootstrap.php:22
$msg
Definition: config.php:155
$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 141 of file m_quota.php.

References $db, $msg, and $q.

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

Member Data Documentation

m_quota::$clquota

Definition at line 40 of file m_quota.php.

m_quota::$disk = Array()

Definition at line 36 of file m_quota.php.

m_quota::$disk_quota_enable

Definition at line 37 of file m_quota.php.

m_quota::$disk_quota_not_blocking

Definition at line 38 of file m_quota.php.

m_quota::$quotas

Definition at line 39 of file m_quota.php.

Referenced by getquota().


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