Changeset 24 for drupal

Show
Ignore:
Timestamp:
12/18/08 12:05:45 (3 years ago)
Author:
matthew
Message:

uthorised user can now view disk usage. Site root user (uid=1) can set disk space allowance.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • drupal/modules/iutilities/trunk/iutilities.module

    r23 r24  
    33 
    44function iutilities_perm() { 
    5         return array('access disk usage information'); 
     5        return array('access disk usage information', 'access disk usage settings'); 
    66} // function illuminate_perm() 
     7 
     8function iutilities_admin() { 
     9        $form['disk_space_limit'] = array( 
     10                '#type' => 'textfield', 
     11                '#title' => t('Maximum space allowed'), 
     12                '#default_value' => variable_get('disk_space_limit', 150), 
     13                '#size' => 5, 
     14                '#maxlength' => 4, 
     15                '#field_suffix' => t('MB'), 
     16                '#description' => t("Each illuminate ict website is permitted a certain amount of space. By default this is 150MB. This can be increased here."), 
     17                '#required' => TRUE, 
     18        ); 
     19        return system_settings_form($form); 
     20} 
    721 
    822function iutilities_cron() { 
    923        $confpath = conf_path(); 
    10         $space_used_string = `du -sh $confpath`; 
     24        $space_used_string = `du -sm $confpath`; 
    1125        $space_used_array = explode("\t", $space_used_string); 
    12         print_r($space_used_array); 
    13         $space_used = trim($space_used_array[0]); 
     26        $space_used = (int) trim($space_used_array[0]); 
    1427        variable_set('disk_space_used', $space_used);    
    1528} 
     
    1730function iutilities_menu() { 
    1831        $items['admin/reports/diskusage'] = array( 
    19                 'title' => 'Disk Usage', 
     32                'title' => 'Disk Usage Report', 
     33                'description' => 'Dispay a disk usage report for this website. Includes the space limit for the site.', 
    2034                'access arguments' => array('access disk usage information'), 
     35                'page callback' => 'display_diskusage_report', 
    2136        ); 
     37        $items['admin/settings/diskusage'] = array( 
     38                'title' => 'Set Disk Usage Limit', 
     39                'description' => 'The default 150MB space allowance set by illuminate ICT can be increased here.', 
     40                'access callback' => 'access_disk_usage_settings', 
     41                'access arguments' => array('access disk usage settings'), 
     42                'page callback' => 'drupal_get_form', 
     43                'page arguments' => array(iutilities_admin), 
     44        ); 
     45        return $items; 
    2246} // illuminate_menu() 
     47 
     48function stuff() { 
     49        return "Hello"; 
     50} 
     51 
     52function access_disk_usage_settings() { 
     53        global $user; 
     54        if ( $user->uid == 1 ) { 
     55                return TRUE; 
     56        } else { 
     57                return FALSE; 
     58        } 
     59} 
     60 
     61function display_diskusage_report() { 
     62        $space_used = variable_get('disk_space_used',150); 
     63        $space_limit = variable_get('disk_space_limit',150); 
     64        $space_percentage = ( $space_used / $space_limit ) * 100; 
     65        $output = '<p>Your hosting account with illuminate ICT allows a maximum of <strong>'. $space_limit . 'MB</strong>.</p>'; 
     66        $output .= '<p>You are currently using <strong>' . $space_used . 'MB</strong> of your allowance.</p>'; 
     67        $output .= '<p>This is <strong>' . $space_percentage . '&#37;</strong> of the available space.</p>'; 
     68        return $output; 
     69} 
     70 
    2371 
    2472function iutilities_init() {