root/drupal/modules/iutilities/trunk/iutilities.module

Revision 24, 3.1 kB (checked in by matthew, 2 years ago)

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

  • Property svn:mergeinfo set to
Line 
1 <?php
2 // $Id$
3
4 function iutilities_perm() {
5         return array('access disk usage information', 'access disk usage settings');
6 } // function illuminate_perm()
7
8 function 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 }
21
22 function iutilities_cron() {
23         $confpath = conf_path();
24         $space_used_string = `du -sm $confpath`;
25         $space_used_array = explode("\t", $space_used_string);
26         $space_used = (int) trim($space_used_array[0]);
27         variable_set('disk_space_used', $space_used);   
28 }
29
30 function iutilities_menu() {
31         $items['admin/reports/diskusage'] = array(
32                 'title' => 'Disk Usage Report',
33                 'description' => 'Dispay a disk usage report for this website. Includes the space limit for the site.',
34                 'access arguments' => array('access disk usage information'),
35                 'page callback' => 'display_diskusage_report',
36         );
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;
46 } // illuminate_menu()
47
48 function stuff() {
49         return "Hello";
50 }
51
52 function access_disk_usage_settings() {
53         global $user;
54         if ( $user->uid == 1 ) {
55                 return TRUE;
56         } else {
57                 return FALSE;
58         }
59 }
60
61 function 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
71
72 function iutilities_init() {
73   //include necessary css
74   global $user;
75   if ($user->uid > 0) {
76     $path = drupal_get_path('module', 'illuminate');
77     drupal_add_css($path . '/iutilities.css', 'module', 'all', FALSE);
78   }
79 }
80
81 function iutilities_footer($main=0) {
82   //output footer message
83   global $user;
84
85   $siteDir =   "sites/" . $_SERVER[SERVER_NAME];
86   $path = drupal_get_path('module', 'illuminate');
87   //footer message is available for all users
88   if ($user->uid == 0) {
89     $loginLink = '<a href="/user/login">[login]</a>';
90   } else {
91     $loginLink = '<a href="/logout">[logout]</a>';
92   }
93   $illuminateStuff =  $loginLink . ' <br/>Website developed in association with <a href="http://www.illuminateict.org.uk">Illuminate ICT</a>';
94  
95   return $illuminateStuff;
96 }
Note: See TracBrowser for help on using the browser.