You are here

function hosting_quota_nodeapi in Hostmaster (Aegir) 6

Implements hook_nodeapi().

File

modules/hosting/quota/hosting_quota.module, line 258
Implement quota's for the resource used by client.

Code

function hosting_quota_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
  global $user;
  if ($node->type == 'client') {
    switch ($op) {
      case 'insert':
      case 'update':
        if (user_access('edit all quotas')) {
          foreach ($node as $field => $value) {
            if (substr($field, 0, 6) == 'quota-') {
              $quota = substr($field, 6);

              // If no value was entered use the default value for this resource
              if (!$value) {
                $value = variable_get("hosting_quota_default_{$quota}", 0);
              }
              hosting_quota_set_limit($node->nid, $quota, $value);
            }
          }
        }
        break;
      case 'load':
        $node->quota = hosting_quota_get_all_info($node->nid);
        break;
      case 'view':
        $allowed_clients = array_keys(hosting_get_client_from_user($user->uid));
        if (user_access('view all quotas') || in_array($node->nid, $allowed_clients) && user_access('view own quota')) {
          $node->content['info']['quota'] = array(
            '#type' => 'item',
            '#title' => 'Quota',
            '#value' => theme('hosting_quota_client', $node),
            '#weight' => 5,
          );
        }
        break;
    }
  }
}