| | 37 | $disk_space_limit = (int) variable_get('disk_space_limit',150); |
|---|
| | 38 | //how long since a warning email was sent?? |
|---|
| | 39 | $time_now = (int) time(); |
|---|
| | 40 | $time_last_email = (int) variable_get('disk_space_last_emailed',0); |
|---|
| | 41 | $time_since_email = (int) $time_now - $time_last_email; |
|---|
| | 42 | //email if space allowance has been exceeded |
|---|
| | 43 | // but only email if not yet emailed |
|---|
| | 44 | // or it's more than a week since an email was sent |
|---|
| | 45 | if ( $space_used > $disk_space_limit && ($time_last_email==0 || $time_since_email > 604799) ) { |
|---|
| | 46 | $site_default_language = language_default(); |
|---|
| | 47 | $disk_space_warnings_role = variable_get('disk_space_warnings_role', 'site administrator'); |
|---|
| | 48 | $users_with_role_query = "select u.mail from {users} u inner join {users_roles} ur on u.uid=ur.uid inner join {role} r on r.rid=ur.rid where r.name='%s'"; |
|---|
| | 49 | $result = db_query(db_rewrite_sql($users_with_role_query),$disk_space_warnings_role); |
|---|
| | 50 | while ($data = db_fetch_object($result)) { |
|---|
| | 51 | drupal_mail('iutilities', 'warning', $data->mail, $site_default_language, $params); |
|---|
| | 52 | } |
|---|
| | 53 | //set a variable which notes that an email has been sent. |
|---|
| | 54 | $time_stamp = (int) time(); |
|---|
| | 55 | variable_set('disk_space_last_emailed',$time_stamp); |
|---|
| | 56 | } elseif ($space_used <= $disk_space_limit) { |
|---|
| | 57 | variable_set('disk_space_last_emailed',0); |
|---|
| | 58 | } |
|---|
| | 59 | } |
|---|
| | 60 | |
|---|
| | 61 | function iutilities_mail($key, &$message, $params) { |
|---|
| | 62 | global $base_url; |
|---|
| | 63 | $space_used = variable_get('disk_space_used',150); |
|---|
| | 64 | $space_limit = variable_get('disk_space_limit',150); |
|---|
| | 65 | switch($key) { |
|---|
| | 66 | case 'warning': |
|---|
| | 67 | $message['subject'] = t('Space usage warning from ' . $base_url); |
|---|
| | 68 | $message['body'] = t("An information message from your website host, ILLUMINATE ICT\n------------------------------------------------\n\nYou are listed as being a site administrator for $base_url.\n\nThis email is to inform you that you are currently exceeding your space allocation on our webserver. You have been allocated " . $space_limit . "MB and you are using " . $space_used . "MB.\n\nWe are not about to discontinue your service, but we would appreciate it if you would get in touch to discuss how we could help you. Contact us at http://www.illuminateict.org.uk.\n\nYou will receive this email weekly until we can help you to reduce the amount of space you are using, or increase your space allowance on the server."); |
|---|
| | 69 | break; |
|---|
| | 70 | } |
|---|