Changeset 29

Show
Ignore:
Timestamp:
12/23/08 11:30:58 (2 years ago)
Author:
matthew
Message:

emailing when contract is due to expire is now almost working.
currently, it will mail on each cron run within 1 month of expiry date. this needs some tweaking.

Files:

Legend:

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

    r28 r29  
    2121                '#required' => TRUE, 
    2222        ); 
    23         $form['i-general']['illuminate_notes'] = array( 
     23        $form['i_general']['illuminate_notes'] = array( 
    2424                '#type' => 'textarea', 
    2525                '#title' => 'Notes', 
     
    126126function iutilities_cron() { 
    127127        $confpath = conf_path(); 
     128         
     129        //deal with space usage things 
    128130        $space_used_string = `du -sm $confpath`; 
    129131        $space_used_array = explode("\t", $space_used_string); 
     
    152154                variable_set('disk_space_last_emailed',0); 
    153155        } 
     156         
     157        //deal with hosting expiry things 
     158        //get the hosting expiry date & convert to UNIX time 
     159        $expiry_date = variable_get('hosting_expiry_date', time()); 
     160        if ( is_array($expiry_date) ) { 
     161                $expiry_date_timestamp = mktime(0,0,0,$expiry_date['month'],$expiry_date['day'],$expiry_date['year']); 
     162                $warnings_start_date = $expiry_date_timestamp - 2592000; 
     163                //warning messages will begin a month before contract expiry - 2592000s = 1 month. 
     164                $now = time(); 
     165                if ( $warnings_start_date < $now ) { 
     166                        //do the sending email thing, no more than once a week. 
     167                        $site_default_language = language_default(); 
     168                        $email_warnings_role = variable_get('email_warnings_role', 'site administrator'); 
     169                        $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'"; 
     170                        $result = db_query(db_rewrite_sql($users_with_role_query),$email_warnings_role); 
     171                        while ($data = db_fetch_object($result)) { 
     172                                drupal_mail('iutilities', 'hosting_expiry', $data->mail, $site_default_language, $params); 
     173                        } 
     174                        //set a variable which notes that an email has been sent. 
     175                        variable_set('hosting_expiry_last_emailed',$now); 
     176                } elseif ( $warnings_start_date >= $now ) { 
     177                        variable_set('hosting_expiry_last_emailed',0); 
     178                } 
     179        } 
     180         
    154181} 
    155182 
     
    163190                $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."); 
    164191                break; 
     192        case 'hosting_expiry': 
     193                $message['subject'] = t('Hosting expiry warning from ' . $base_url); 
     194                $message['body'] = t("You are about to run out of time."); 
    165195        } 
    166196} 
    167197 
    168198function iutilities_menu() { 
    169         $items['admin/reports/diskusage'] = array( 
    170                 'title' => 'Disk Usage Report', 
    171                 'description' => 'Dispay a disk usage report for this website. Includes the space limit for the site.', 
     199        $items['admin/reports/illuminate'] = array( 
     200                'title' => 'Illuminate Hosting Report', 
     201                'description' => 'Dispay a hosting report for this website. Includes the space limit for the site and other contract information.', 
    172202                'access arguments' => array('access disk usage information'), 
    173203                'page callback' => 'display_diskusage_report',