You are here

hosting_quota.admin.inc in Hosting 7.3

Same filename and directory in other branches
  1. 6.2 quota/hosting_quota.admin.inc
  2. 7.4 quota/hosting_quota.admin.inc

hosting_quota.admin.inc Admin forms for the quota module.

File

quota/hosting_quota.admin.inc
View source
<?php

/**
 * @file hosting_quota.admin.inc
 * Admin forms for the quota module.
 */

/**
 * Page callback for admin/hosting/quotas
 */
function hosting_quota_admin_client_list() {
  $items_per_page = 25;
  $all_resources = module_invoke_all('hosting_quota_resource');
  $result = db_select('hosting_client_quota', 'q');
  $result
    ->join('node', 'n', 'q.client = n.nid');
  $result
    ->fields('q')
    ->fields('n');
  $result = $result
    ->extend('PagerDefault')
    ->limit($items_per_page)
    ->execute();
  $output = array();
  while ($row = $result
    ->fetchObject()) {
    $resource = array(
      $row->resource => $all_resources[$row->resource],
    );

    // Pass in raw limit and usage
    $output[$row->client][$row->resource]['limit'] = $row->value;
    $output[$row->client][$row->resource]['usage'] = hosting_quota_get_usage($row->client, $resource);

    // Render limit and usage
    $output[$row->client][$row->resource]['rendered usage'] = hosting_quota_resource_render($resource, $output[$row->client][$row->resource]['usage']);
    $output[$row->client][$row->resource]['rendered limit'] = hosting_quota_resource_render($resource, $row->value);

    // Set client identifier
    $output[$row->client]['name'] = $row->title;
  }
  return theme('hosting_quota_admin_list', array(
    'client_quotas' => $output,
    'resources' => $all_resources,
    'items_per_page' => $items_per_page,
  ));
}

/**
 * Callback for admin/hosting/quotas/defaults
 */
function hosting_quota_admin_defaults_form($form, $form_state) {
  $form = array();
  $all_resources = module_invoke_all('hosting_quota_resource');
  $form['info'] = array(
    '#type' => 'markup',
    '#prefix' => '<p>',
    '#value' => t('Set default limits for each resource. This value will be used as the default value when new clients are created and to set quota limits for all clients currently without limits'),
    '#suffix' => '</p>',
  );
  $form['quota'] = array(
    '#type' => 'fieldset',
    '#title' => t('Client quota settings'),
    '#access' => user_access('edit all quotas'),
    '#collapsible' => FALSE,
    '#collapsed' => FALSE,
  );
  foreach ($all_resources as $resource => $quota) {
    $form['quota'][$resource] = array(
      '#title' => check_plain($quota['title']),
      '#description' => check_plain($quota['description']),
      '#type' => 'textfield',
      '#default_value' => variable_get("hosting_quota_default_{$resource}", 0),
    );
  }
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Submit'),
  );
  $form['#tree'] = TRUE;
  return $form;
}

/**
 * Submit function for hosting_quota_admin_defaults_form
 */
function hosting_quota_admin_defaults_form_submit($form, &$form_state) {
  foreach ($form_state['values']['quota'] as $resource => $quota) {

    // Set the default quota
    variable_set("hosting_quota_default_{$resource}", $quota);

    // Set quotas for clients that don't already have them
    $client_result = db_query('SELECT nid FROM {hosting_client} WHERE nid not in (SELECT client FROM {hosting_client_quota})');
    while ($row = $client_result
      ->fetch()) {
      hosting_quota_set_limit($row->nid, $resource, $quota);
    }
  }
}

Functions

Namesort descending Description
hosting_quota_admin_client_list Page callback for admin/hosting/quotas
hosting_quota_admin_defaults_form Callback for admin/hosting/quotas/defaults
hosting_quota_admin_defaults_form_submit Submit function for hosting_quota_admin_defaults_form