Index: /drupal/modules/iutilities/trunk/iutilities.module =================================================================== --- /drupal/modules/iutilities/trunk/iutilities.module (revision 24) +++ /drupal/modules/iutilities/trunk/iutilities.module (revision 25) @@ -17,4 +17,13 @@ '#required' => TRUE, ); + $form['disk_space_warnings_role'] = array( + '#type' => 'textfield', + '#title' => t('Role to receive warning emails'), + '#default_value' => variable_get('disk_space_warnings_role', 'site administrator'), + '#size' => 20, + '#maxlength' => 25, + '#description' => t("The role entered here here will receive warning messages by email should the site exceed the space limitations."), + '#required' => TRUE, + ); return system_settings_form($form); } @@ -26,4 +35,38 @@ $space_used = (int) trim($space_used_array[0]); variable_set('disk_space_used', $space_used); + $disk_space_limit = (int) variable_get('disk_space_limit',150); + //how long since a warning email was sent?? + $time_now = (int) time(); + $time_last_email = (int) variable_get('disk_space_last_emailed',0); + $time_since_email = (int) $time_now - $time_last_email; + //email if space allowance has been exceeded + // but only email if not yet emailed + // or it's more than a week since an email was sent + if ( $space_used > $disk_space_limit && ($time_last_email==0 || $time_since_email > 604799) ) { + $site_default_language = language_default(); + $disk_space_warnings_role = variable_get('disk_space_warnings_role', 'site administrator'); + $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'"; + $result = db_query(db_rewrite_sql($users_with_role_query),$disk_space_warnings_role); + while ($data = db_fetch_object($result)) { + drupal_mail('iutilities', 'warning', $data->mail, $site_default_language, $params); + } + //set a variable which notes that an email has been sent. + $time_stamp = (int) time(); + variable_set('disk_space_last_emailed',$time_stamp); + } elseif ($space_used <= $disk_space_limit) { + variable_set('disk_space_last_emailed',0); + } +} + +function iutilities_mail($key, &$message, $params) { + global $base_url; + $space_used = variable_get('disk_space_used',150); + $space_limit = variable_get('disk_space_limit',150); + switch($key) { + case 'warning': + $message['subject'] = t('Space usage warning from ' . $base_url); + $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."); + break; + } } @@ -36,5 +79,5 @@ ); $items['admin/settings/diskusage'] = array( - 'title' => 'Set Disk Usage Limit', + 'title' => 'Set Disk Usage Defaults', 'description' => 'The default 150MB space allowance set by illuminate ICT can be increased here.', 'access callback' => 'access_disk_usage_settings', @@ -45,8 +88,4 @@ return $items; } // illuminate_menu() - -function stuff() { - return "Hello"; -} function access_disk_usage_settings() {