--- countdown.module	2007-01-15 15:34:37.000000000 -0800
+++ countdown_patched.module	2007-12-20 22:05:10.625000000 -0800
@@ -43,7 +43,8 @@ function countdown_block($op = 'list', $
       '#size' => 30,
       '#maxlength' => 200,
       '#description' => t("Event name you're counting to or from."),
-      '#required' => true
+      '#required' => true,
+	  '#weight' => 0
     );
 
     $form['countdown_accuracy'] = array(
@@ -51,9 +52,51 @@ function countdown_block($op = 'list', $
       '#title' => t('Accuracy'),
       '#default_value' => variable_get('countdown_accuracy', 'd'),
       '#options' => array('d' => t('days'), 'h' => t('hours'), 'm' => t('minutes'), 's' => 'seconds'),
-      '#description' => t('Select the smallest amount of detail to display. For example, selecting "days" will display only days, selecting "hours" will display the number of days and hours.')
+      '#description' => t('Select the smallest amount of detail to display. For example, selecting "days" will display only days, selecting "hours" will display the number of days and hours.'),
+	  '#weight' => 1
     );
 
+	$form['countdown_locksite'] = array(
+	  '#type' => 'checkbox',
+	  '#title' => t('Automatically lock site on timer expiration'),
+	  '#return_value' => 1,
+	  '#default_value' => variable_get('countdown_locksite', 0),
+	  '#weight' => 2
+	);
+	
+	$form['countdown_showcountdown'] = array(
+	  '#type' => 'checkbox',
+	  '#title' => t('Show countdown to all users'),
+	  '#default_value' => variable_get('countdown_showcountdown', 0),
+	  '#weight' => 3
+	);
+
+    $form['countdown_hidewhendone'] = array(
+      '#type' => 'checkbox',
+	  '#title' => t('Hide countdown when finished'),
+	  '#default_value' => variable_get('countdown_hidewhendone', 0),
+	  '#weight' => 4
+    );
+
+	$form['countdown_email_notification'] = array(
+	  '#type' => 'checkbox',
+	  '#title' => t('Send EMail Notification when completed?'),
+	  '#default_value' => variable_get('countdown_email_notification', 0),
+	  '#weight' => 5
+	);
+	
+	$form['countdown_notification_email_address'] = array(
+	  '#type' => 'textfield',
+	  '#title' => t('Notification Email Address'),
+	  '#description' => t('Enter the notification email address:'),
+	  '#default_value' => variable_get('countdown_notification_email_address'),
+	  '#max_length' => 256,
+	  '#required' => FALSE,
+	  '#size' => 80,
+	  '#weight' => 6
+	);
+	
+	
     $time = time();
     $timestamp = variable_get('countdown_timestamp', $time);
 
@@ -122,7 +165,18 @@ function countdown_block($op = 'list', $
     variable_set('countdown_event_name', $edit['countdown_event_name']);
     variable_set('countdown_accuracy', $edit['countdown_accuracy']);
     variable_set('countdown_timestamp', mktime((int)$edit['hour'], (int)$edit['min'], (int)$edit['sec'], (int)$edit['month'], (int)$edit['day'], (int)$edit['year']));
-
+	variable_set('countdown_locksite', $edit['countdown_locksite']);
+    variable_set('countdown_showcountdown', $edit['countdown_showcountdown']);
+    variable_set('countdown_hidewhendone', $edit['countdown_hidewhendone']);
+	variable_set('countdown_email_notification', $edit['countdown_email_notification']);
+	
+	if (valid_email_address($edit['countdown_notification_email_address'])) {
+	  variable_set('countdown_notification_email_address', $edit['countdown_notification_email_address']);
+	} else {
+	  form_set_error('countdown_notification_email_address',
+	    t('Notification email address is not valid.'));
+	}
+	
   case 'view':
     if (user_access('access content')) {
       $block['subject'] = variable_get('countdown_block_title', t('Countdown'));
@@ -131,25 +185,66 @@ function countdown_block($op = 'list', $
       if ($difference < 0) {
         $passed = 1;
         $difference = abs($difference);
+		$locksite = variable_get('countdown_locksite', 0);
+		$countdown_hidewhendone = variable_get('countdown_hidewhendone', 0);
+		if ($locksite) {
+		  variable_set('site_offline',1);
+		  if (variable_get('countdown_notification_email')) {
+		    $message[] = "The site has gone offline.";
+		    // Tidy up the body:
+		    foreach ($message as $key => $value) {
+		    	$message[$key] = wordwrap($value);
+		    }
+			
+		    // Prepare all fields:
+		    $to = variable_get('countdown_notification_email_address');
+
+			// Format the subject:
+			$subject = 'Countdown notification email';
+
+			// Prepare the body:
+			$body = implode("\n\n", $message);
+			
+			drupal_mail('countdown-notification-mail', variable_get('countdown_notification_email_address'), 'Shutdown has completed.', $body);
+		  }
+		  watchdog('countdown','The site has gone offline automatically for maintenance.',WATCHDOG_NOTICE);
+		}
       } else {
         $passed = 0;
       }
-
-      $accuracy  = variable_get('countdown_accuracy', 'd');
+      $countdown_showcountdown = variable_get('countdown_showcountdown', 1);
+      
+	  $accuracy  = variable_get('countdown_accuracy', 'd');
       $days_left = floor($difference/60/60/24);
       $hrs_left  = floor(($difference - $days_left*60*60*24)/60/60);
       $min_left  = floor(($difference - $days_left*60*60*24 - $hrs_left*60*60)/60);
       $secs_left = floor(($difference - $days_left*60*60*24 - $hrs_left*60*60 - $min_left*60));
 
-      $block['content'] .= t('%i days', array('%i' => $days_left));
+	  if($days_left <> 1) {
+        $block['content'] .= t('%i days', array('%i' => $days_left));
+      } else {
+	    $block['content'] .= t('%i day', array('%i' => $days_left));
+	  }
       if($accuracy == 'h' || $accuracy == 'm' || $accuracy == 's') {
-        $block['content'] .= t(', %i hours', array('%i' => $hrs_left));
+	    if($hrs_left <> 1) {
+          $block['content'] .= t(', %i hours', array('%i' => $hrs_left));
+		} else {
+		  $block['content'] .= t(', %i hour', array('%i' => $hrs_left));
+		}
       }
       if($accuracy == 'm' || $accuracy == 's') {
-        $block['content'] .= t(', %i minutes', array('%i' => $min_left));
+	    if($min_left <> 1) {
+          $block['content'] .= t(', %i minutes', array('%i' => $min_left));
+		} else {
+		  $block['content'] .= t(', %i minute', array('%i' => $min_left));
+		}
       }
       if($accuracy == 's') {
-        $block['content'] .= t(', %i seconds', array('%i' => $secs_left));
+	    if($secs_left <> 1) {
+          $block['content'] .= t(', %i seconds', array('%i' => $secs_left));
+		} else {
+		  $block['content'] .= t(', %i second', array('%i' => $secs_left));
+		}
       }
       $block['content'] .= t(($passed) ? ' since %s.' : ' until %s.', array('%s' => variable_get('countdown_event_name', '')));
 /*
@@ -167,7 +262,18 @@ function countdown_block($op = 'list', $
       $block['content'] .= t("%i minutes ", array('%i' => $min_left));
       $block['content'] .= t("%i seconds ", array('%i' => $secs_left));
 */
+	  // Show an empty block if event has passed, or if countdown_showcountdown is false.
+	  if (($passed && $countdown_hidewhendone) || !$countdown_showcountdown) {
+	    
+      // This is necessary so the site won't keep locking itself after it is brought back online.
+        if ($passed) {
+		  variable_set('countdown_locksite', 0);
+		}
+	    return $emptyblock;
+	  }
+	  else {
       return $block;
+	  }
     }
     break;
   }
