Index: calendar_block.css
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/calendar_block/calendar_block.css,v
retrieving revision 1.2
diff -u -p -r1.2 calendar_block.css
--- calendar_block.css	24 Nov 2008 15:40:13 -0000	1.2
+++ calendar_block.css	10 Feb 2010 02:08:30 -0000
@@ -1,24 +1,24 @@
-#calendar_ajax {
+.calendar_ajax {
 	line-height:100%;
 	width:173px;
 }
 
-#nav {
+.calendar_ajax .nav {
 	text-align:center;
 }
 
-#nav div {
+.calendar_ajax .nav div {
 	float:left;
 }
 
-#calendar_prev, #calendar_next {
+.calendar_prev, .calendar_next {
   width:24px;
   height:20px;
   cursor:pointer;
   padding-top:4px;
 }
 
-#calendar_month {
+.calendar_month {
   width:125px;
 	margin-top:4px;
 }
@@ -54,57 +54,57 @@
   opacity:.50; 
 }
 
-#calendar_row0 .hok span {
+.calendar_row0 .hok span {
   margin-top:0px;
 }
 
-#calendar_row6 .hok {
+.calendar_row6 .hok {
   height:17px;
 }
 
-#calendar_row0 {
+.calendar_row0 {
   height:37px;
   background:url('images/header.png') repeat-x;
 }
 
-#calendar_row1 .hok {
+.calendar_row1 .hok {
   background-image:url('images/cell_row1.png');
 }
 
-#calendar_row2 .hok {
+.calendar_row2 .hok {
   background-image:url('images/cell_row2.png');
 }
 
-#calendar_row3 .hok {
+.calendar_row3 .hok {
   background-image:url('images/cell_row3.png');
 }
 
-#calendar_row4 .hok {
+.calendar_row4 .hok {
   background-image:url('images/cell_row4.png');
 }
 
-#calendar_row5 .hok {
+.calendar_row5 .hok {
   background-image:url('images/cell_row5.png');
 }
 
-#calendar_row6 .hok {
+.calendar_row6 .hok {
   background-image:url('images/cell_row6.png');
 }
 
-#calendar_row1 .hok.disabled {
+.calendar_row1 .hok.disabled {
   background-image:url('images/cell_first_row_disabled.png');
 }
 
-#calendar_row5 .hok.disabled, #calendar_row6 .hok.disabled {
+.calendar_row5 .hok.disabled, .calendar_row6 .hok.disabled {
   background-image:url('images/cell_last_row_disabled.png');
 }
 
-#calendar_row1 .hok.today,
-#calendar_row2 .hok.today,
-#calendar_row3 .hok.today,
-#calendar_row4 .hok.today,
-#calendar_row5 .hok.today,
-#calendar_row6 .hok.today {
+.calendar_row1 .hok.today,
+.calendar_row2 .hok.today,
+.calendar_row3 .hok.today,
+.calendar_row4 .hok.today,
+.calendar_row5 .hok.today,
+.calendar_row6 .hok.today {
 	background-image:url(images/today.png);
 	background-repeat:no-repeat;
 }
Index: calendar_block.js
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/calendar_block/calendar_block.js,v
retrieving revision 1.2
diff -u -p -r1.2 calendar_block.js
--- calendar_block.js	24 Nov 2008 15:40:13 -0000	1.2
+++ calendar_block.js	10 Feb 2010 02:08:30 -0000
@@ -4,64 +4,80 @@ function calendar() {
   ref.ajax_settings = {};
 
   ref.init = function() {
-    ref.settings = Drupal.settings.calendar_block;
-    //trace(ref.settings);
+    
+    ref.deltas = Drupal.settings.calendar_block_deltas;
+    
+    for (var i=0; i < ref.deltas.length; i++) {
+      var potential_delta_key = ref.deltas[i];
+      if (Drupal.settings['calendar_block_'+potential_delta_key]) {
+        ref.settings[potential_delta_key] = Drupal.settings['calendar_block_'+potential_delta_key];
+      };
+    };
+    
+    // ref.settings = Drupal.settings.calendar_block;
+    // //trace(ref.settings);
+
+    for (var delta in ref.settings) {
+      ref.ajax_settings[delta] = {delta:delta, type: "POST", url: ref.settings[delta].ajax_response_path, success:function(result, code) { ref.ajaxResponse(result, code, this.delta);}}
+      ref.getCalendar(ref.settings[delta].calendar.month, ref.settings[delta].calendar.year, delta);
+      ref.setColors(true, delta);
+    };
 
-    ref.ajax_settings = {type: "POST", url: ref.settings.ajax_response_path, success:function(result) { ref.ajaxResponse(result)}};
-    ref.getCalandar(ref.settings.calendar.month, ref.settings.calendar.year);
-    ref.setColors(true);
   };
   
-  ref.setWidth = function() {
-    var width = parseInt(ref.settings.width);
+  ref.setWidth = function(delta) {
+    var width = parseInt(ref.settings[delta].width);
+    var cal_id = 'calendar_'+delta;
 
     // Calculate the width of the weekdays
     var hok_width = Math.round(width / 7);
     // Calculate the width of the last weekday
     var last_hok_width = width - (6 * hok_width);
     // Calculate the width of the header
-    var header_width = width - (2 * $('#calendar_prev').width());
+    var header_width = width - (2 * $('#'+cal_id+'_prev').width());
     // Calculate the font size
     var font_size = Math.floor(hok_width / 2);
     // Calculate the top padding
     var padding_top = Math.floor((((hok_width - font_size) / 2) * 1.3) -1);
 
-    $('#calendar_ajax').width(width);
-    $('#calendar_month').width(header_width);
-    $('.hok').width(hok_width);
-    $('.week .hok span').css({
+    $('#'+cal_id+'_ajax').width(width);
+    $('#'+cal_id+'_month').width(header_width);
+    $('#'+cal_id+'_ajax .hok').width(hok_width);
+    $('#'+cal_id+'_ajax .week .hok span').css({
       'margin-top':padding_top + 'px',
       'font-size':(font_size - 2)  + 'px'
     }).parent().height(hok_width);
-    $('#calendar_month').css({'font-size':font_size + 'px'});
-    $('.hok.last').width(last_hok_width);
+    $('#'+cal_id+'_month').css({'font-size':font_size + 'px'});
+    $('#'+cal_id+'_ajax .hok.last').width(last_hok_width);
   };
   
-  ref.setColors = function(init) {
+  ref.setColors = function(init, delta) {
+    var cal_id = 'calendar_'+delta;
+    
     if (init) {
-      $('#calendar_ajax').css({
-        'background-color':ref.settings.background_color
+      $('#'+cal_id+'_ajax').css({
+        'background-color':ref.settings[delta].background_color
       });
     }
     else {
-      $('#calendar_ajax').css({
-        'color':ref.settings.font_color,
-      	'border':'solid 1px ' + ref.settings.border_color
+      $('#'+cal_id+'_ajax').css({
+        'color':ref.settings[delta].font_color,
+      	'border':'solid 1px ' + ref.settings[delta].border_color
       }).find('a').css({
-        'color':ref.settings.link_color
+        'color':ref.settings[delta].link_color
       });
-      $('#nav, .hok.top').css({
-        'color':ref.settings.header_color
+      $('#'+cal_id+'_nav, #'+cal_id+'_ajax .hok.top').css({
+        'color':ref.settings[delta].header_color
       });
     };
   };
 
-  ref.getCalandar = function(month, year) {
+  ref.getCalendar = function(month, year, delta) {
     if (year && month) {
-      ref.ajax_settings.data = {month:month, year:year};
+      ref.ajax_settings[delta].data = {month:month, year:year, delta:delta};
     };
-    ref.ajax_settings.data.weekdays = Drupal.toJson(ref.settings.calendar.weekdays);
-    $.ajax(ref.ajax_settings);
+    ref.ajax_settings[delta].data.weekdays = Drupal.toJson(ref.settings[delta].calendar.weekdays);
+    $.ajax(ref.ajax_settings[delta]);
   };
   
   /**
@@ -73,31 +89,34 @@ function calendar() {
     ref.setWidth();
   };
 
-  ref.ajaxResponse = function(result) {
-    delete(ref.ajax_settings.data);
-    $("#calendar_ajax").html(result);
-    ref.setWidth();
-    ref.setColors();
-    ref.addResponseListeners();
-    ref.pngFix();
+  ref.ajaxResponse = function(result, code, delta) {
+    var cal_id = 'calendar_'+delta;
+    delete(ref.ajax_settings[delta].data);
+    $('#'+cal_id+'_ajax').html(result);
+    ref.setWidth(delta);
+    ref.setColors(false, delta);
+    ref.addResponseListeners(delta);
+    ref.pngFix(delta);
   };
   
-  ref.addResponseListeners = function(result) {
-    $("#calendar_prev, #calendar_next").click(function() {
-      var date = $(this).attr('class').split('-');
-      ref.getCalandar(date[0], date[1]);
+  ref.addResponseListeners = function(delta) {
+    var cal_id = 'calendar_'+delta;
+    $('#'+cal_id+'_prev, #'+cal_id+'_next').click(function() {
+      var date = $(this).attr('title').split('-');
+      ref.getCalendar(date[0], date[1], delta);
     });
     
     $('#edit-background-color, #edit-font-color, #edit-header-color, #edit-link-color, #edit-border-color').change(function() {
       var elem = $(this).attr('id').replace(/edit-/, '').replace(/-/, '_');
       ref.settings[elem] = $(this).val();
-      ref.setColors((elem == 'background_color'));
+      ref.setColors((elem == 'background_color'), delta);
     });
   };
   
-  ref.pngFix = function() {
+  ref.pngFix = function(delta) {
+    var cal_id = 'calendar_'.delta;
     if($.browser.msie && parseInt($.browser.version) < 7) {
-      $('#calendar_row0, .hok').each(function() {
+      $('#'+cal_id+'_row0, .hok').each(function() {
         var css_bg_img = $(this).css('background-image');
         if (css_bg_img !== 'none') {
           var bg_img = css_bg_img.substring(5, css_bg_img.length - 2);
Index: calendar_block.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/calendar_block/calendar_block.module,v
retrieving revision 1.4.2.1
diff -u -p -r1.4.2.1 calendar_block.module
--- calendar_block.module	20 Jan 2009 08:46:24 -0000	1.4.2.1
+++ calendar_block.module	10 Feb 2010 02:08:30 -0000
@@ -3,7 +3,7 @@
 
 /**
  * @file
- * This module provides a fully customizale calendar block.
+ * This module provides a fully customizable calendar block.
  *
  * You can set the actions for the dates by using hook_calendar_block(&$day, $op).
  */
@@ -22,6 +22,23 @@ function calendar_block_help($section) {
  * Implementation of hook_menu().
  */
 function calendar_block_menu() {
+  $items['admin/build/block/add-calendar-block'] = array(
+    'type' => MENU_LOCAL_TASK,
+    'title' => t('Add calendar block'),
+    'description' => t('Add a new calendar block.'),
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('calendar_block_add_block_form'),
+    'access arguments' => array('administer blocks'),
+    );
+
+  $items['admin/build/block/delete-calendar-block/%calendar_block_delta'] = array(
+    'type' => MENU_CALLBACK,
+    'title' => t('Delete calendar block'),
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('calendar_block_delete_block_form', 4),
+    'access arguments' => array('administer blocks'),
+    );
+
   $items['calendar_block_ajax'] = array(
     'page callback' => 'calendar_block_ajax',
     'access arguments' => array('access content'),
@@ -31,32 +48,48 @@ function calendar_block_menu() {
 }
 
 /**
+ * Check delta in args
+ */
+function calendar_block_delta_load($delta) {
+  $blocks = _calendar_block_block_list();
+  return (!empty($blocks[$delta])) ? $delta:FALSE;
+}
+
+/**
  * Implementation of hook_block().
  */
 function calendar_block_block($op = 'list', $delta = 0, $edit = array()) {
   switch ($op) {
     case 'list':
-      $blocks[0] = array(
-        'info' => t('Calendar'),
-      );
-      return $blocks;
+      return _calendar_block_block_list();
     case 'configure':
+
+      if (!isset($delta)) {
+        $form['delta_input'] = array(
+          '#type' => 'textfield',
+          '#title' => t('Block delta'),
+          '#description' => t('Machine-readable name for your block. You may use lowercase letters, numbers, and underscores.'),
+          '#default_value' => $delta !== 0 ? $delta:'',
+          '#required' => TRUE,
+          '#element_validate' => array('calendar_block_delta_validate'),
+          '#weight' => -19,
+          );
+      }
+
       $form['calendar_block'] = array(
         '#type' => 'fieldset',
         '#title' => t('Calendar settings'),
         '#description' => '<p>'. t('Here you can set all options for the calendar. Please refer to our !help_section for a complete guide on the module', array('!help_section' => l(t('help section'), 'admin/help/calendar_block'))) .'</p>',
       );
-      $form['elements'] = array(
-        '#type' => 'value',
-        '#value' => array('background_color' => 'FFFFFF', 'font_color' => '494949', 'header_color' => '494949', 'link_color' => '027AC6', 'border_color' => 'a5a5a5', 'width' => 173, 'first_day_of_the_week' => 'mo')
-      );
 
-      foreach ($form['elements']['#value'] as $element => $default_value) {
+      $settings = calendar_block_settings_get($delta);
+      
+      foreach ($settings as $element => $default_value) {
         if ($element == 'first_day_of_the_week') {
           $form['calendar_block'][$element] = array(
             '#type' => 'select',
             '#title' => t('First day of the week'),
-            '#default_value' => variable_get("calendar_$element", $default_value),
+            '#default_value' => calendar_block_settings_get($delta, $element),
             '#options' => array('su' => t('sunday'), 'mo' => t('monday')),
           );
         }
@@ -64,20 +97,25 @@ function calendar_block_block($op = 'lis
           $form['calendar_block'][$element] = array(
             '#type' => ($element !== 'width' && module_exists('colorpicker')) ? 'colorpicker_textfield' : (module_exists('slider_textfield') ? 'slider_textfield' : 'textfield'),
             '#title' => t(drupal_ucfirst(str_replace('_', ' ', $element))),
-            '#default_value' => variable_get("calendar_$element", $default_value),
+            '#default_value' => calendar_block_settings_get($delta, $element),
             '#size' => '7',
             '#maxlength' => '7',
           );
           if ($element !== 'width') {
-            $form['calendar_block'][$element]['#default_value'] = '#'. $form['calendar_block'][$element]['#default_value'];
+            $form['calendar_block'][$element]['#default_value'] = '#' . $form['calendar_block'][$element]['#default_value'];
+            $form['calendar_block'][$element]['#required'] = TRUE;
           }
           else {
             $form['calendar_block'][$element]['#slider_settings'] = array('min' => 120, 'max' => 200, 'slide' => 'Drupal.calendar.sliderSlide');
+            $form['calendar_block'][$element]['#required'] = TRUE;
           }
         }
       }
+
       $form['calendar_block']['submit'] = array('#type' => 'submit', '#value' => t('Save block'));
-      $form['calendar_block']['reset'] = array('#type' => 'submit', '#value' => t('Reset to defaults'));
+      if ($delta) {
+        $form['calendar_block']['reset'] = array('#type' => 'submit', '#value' => t('Reset to defaults'));
+      }
 
       if (module_exists('colorpicker')) {
         $form['calendar_block']['my_colorpicker'] = array(
@@ -88,23 +126,20 @@ function calendar_block_block($op = 'lis
         $form['calendar_block']['reset']['#suffix']  = '</div>';
       }
 
-
       return $form;
     case 'save':
-      foreach (array_keys($edit['elements']) as $element) {
         if ($edit['op'] == t('Reset to defaults')) {
-          variable_del("calendar_$element");
+          calendar_block_settings_reset($edit['delta']);
         }
         else {
-          variable_set("calendar_$element", str_replace('#', '', $edit[$element]));
+          _calendar_block_block_save($edit['delta'], $edit);
         }
-      }
       break;
     case 'view':
       $block['subject'] = t('Calendar');
-      $block['content'] = '<div id="calendar_ajax"></div>';
+      $block['content'] = '<div id="calendar_' . $delta . '_ajax" class="calendar_ajax"></div>';
 
-      if (variable_get('calendar_first_day_of_the_week', 'mo') == 'mo') {
+      if (calendar_block_settings_get($delta, 'first_day_of_the_week') == 'mo') {
         $weekdays = array('mo' => 'mo', 'tu' => 'tu', 'we' => 'we', 'th' => 'th', 'fr' => 'fr', 'sa' => 'sa', 'su' => 'su');
       }
       else {
@@ -112,35 +147,255 @@ function calendar_block_block($op = 'lis
       }
 
       $calendar = (object) array(
-        'year' => date('Y'),
-        'month' => date('m'),
+        'year' => format_date(time(), 'custom', 'Y'),
+        'month' => format_date(time(), 'custom', 'm'),
         'weekdays' => $weekdays,
+        'delta' => $delta,
       );
       $date = (object) array();
       // Give other modules the opportunity set the date for the calendar
+
       foreach (module_implements('calendar_block') as $module) {
         $function = $module .'_calendar_block';
         $function($calendar, $date, 'load');
       }
 
+      $calendar_block_settings[$delta] = array(
+        'delta' => $delta,
+        'calendar' => $calendar,
+        'ajax_response_path' => url('calendar_block_ajax'),
+        'background_color' => '#'. calendar_block_settings_get($delta, 'background_color'),
+        'font_color' => '#'. calendar_block_settings_get($delta, 'font_color'),
+        'header_color' => '#'. calendar_block_settings_get($delta, 'header_color'),
+        'link_color' => '#'. calendar_block_settings_get($delta, 'link_color'),
+        'border_color' => '#'. calendar_block_settings_get($delta, 'border_color'),
+        'width' => calendar_block_settings_get($delta, 'width'),
+      );
+
       $path = drupal_get_path('module', 'calendar_block');
       drupal_add_css("$path/calendar_block.css", 'module');
       drupal_add_js("$path/calendar_block.js");
-      drupal_add_js(array('calendar_block' => array(
-        'calendar' => $calendar,
-        'ajax_response_path' => url('calendar_block_ajax'),
-        'background_color' => '#'. variable_get('calendar_background_color', 'FFFFFF'),
-        'font_color' => '#'. variable_get('calendar_font_color', '494949'),
-        'header_color' => '#'. variable_get('calendar_header_color', '494949'),
-        'link_color' => '#'. variable_get('calendar_link_color', '027AC6'),
-        'border_color' => '#'. variable_get('calendar_border_color', 'a5a5a5'),
-        'width' => variable_get('calendar_width', 173),
-      )), 'setting');
+
+      // We need to add settings to JS for each delta, however we can't use drupal_add_js for the same
+      // settings variable more than once.  Therefore, we add specially-named settings variables and
+      // check to see which deltas are set in the JS.
+      // We could have also used one drupal_add_js in hook_exit(), but this would not be compatible with
+      // aggressive caching.
+      _calendar_block_setup();
+      drupal_add_js(array('calendar_block_' . $delta => $calendar_block_settings[$delta]), 'setting');
+
       return $block;
   }
 }
 
 /**
+ * Add list of possible deltas for JS to check for settings.
+ */
+function _calendar_block_setup() {
+  static $once;
+  if (!isset($once)) {
+    drupal_add_js(array('calendar_block_deltas' => array_keys(_calendar_block_block_list())), 'setting');
+    $once = TRUE;
+  }
+}
+
+/**
+ * Alters the block admin form to add delete links next to menu blocks.
+ */
+function calendar_block_form_block_admin_display_form_alter(&$form, $form_state) {
+  $blocks = _calendar_block_block_list();
+  foreach ($blocks as $delta => $block) {
+    $form['calendar_block_' . $delta]['delete'] = array('#value' => l(t('delete'), 'admin/build/block/delete-calendar-block/'. $delta));
+  }
+}
+
+/**
+ * @todo get caching to work somehow :)
+ */
+function _calendar_block_block_list($reset = FALSE) {
+  static $blocks;
+
+  if (!isset($blocks) || $reset) {
+    $result = db_query("SELECT delta, title FROM {blocks} WHERE module = 'calendar_block'");
+    $blocks = array();
+    while ($block = db_fetch_object($result)) {
+      $title = ($block->title) ? $block->delta . ' (' . $block->title . ')':$block->delta;
+      $blocks[$block->delta] = array(
+        'info' => t('Calendar block: @title', array('@title' => $title)),
+        'cache' => BLOCK_NO_CACHE,
+        );
+    }
+  }
+
+  return $blocks;
+}
+
+/**
+ * Save settings for the particular block delta
+ */
+function _calendar_block_block_save($delta, $edit) {
+  // save the settings
+  $keys = array_keys(calendar_block_settings_get());
+  foreach ($edit as $key => $value) {
+    if (!in_array($key, $keys)) {
+      unset($edit[$key]);
+    }
+    else {
+      // save hex color values without the # character
+      $edit[$key] = str_replace('#', '', $value);
+    }
+  }
+  calendar_block_settings_set($delta, array_map('calendar_block_remove_hash', $edit));
+}
+
+
+/**
+ * Make sure the user-input delta is the correct format and is unique
+ */
+function calendar_block_delta_validate($element, &$form_state) {
+  // Safe format
+  if (!preg_match('/^[a-z0-9_]+$/', $form_state['values']['delta_input'])) {
+    form_error($element, t('The delta value must only contain lowercase letters, numbers, and underscores'));
+  }
+  // Unique
+  if (db_result(db_query("SELECT bid FROM {blocks} WHERE module = 'calendar_block' AND delta = '%s'", $form_state['values']['delta_input']))) {
+    form_error($element, t('The delta value must be unique'));
+  }
+}
+
+/**
+ * Form to add a calendar block
+ */
+function calendar_block_add_block_form(&$form_state) {
+  include_once './' . drupal_get_path('module', 'block') . '/block.admin.inc';
+  return block_admin_configure($form_state, 'calendar_block', NULL);
+}
+
+/**
+ * _submit handler for adding calendar block
+ */
+function calendar_block_add_block_form_submit($form, &$form_state) {
+  // If we are saving a new calendar block, delta is user-set in delta_input
+  $delta = $form_state['values']['delta_input'] ? $form_state['values']['delta_input']:$form_state['values']['delta'];
+
+  // Save settings as per usual
+  _calendar_block_block_save($delta, $form_state['values']);
+
+  // Run the normal new block submission (borrowed from block_add_block_form_submit).
+  foreach (list_themes() as $key => $theme) {
+    if ($theme->status) {
+      db_query("INSERT INTO {blocks} (visibility, pages, custom, title, module, theme, status, weight, delta, cache) VALUES(%d, '%s', %d, '%s', '%s', '%s', %d, %d, '%s', %d)", $form_state['values']['visibility'], trim($form_state['values']['pages']), $form_state['values']['custom'], $form_state['values']['title'], $form_state['values']['module'], $theme->name, 0, 0, $delta, BLOCK_NO_CACHE);
+    }
+  }
+
+  foreach (array_filter($form_state['values']['roles']) as $rid) {
+    db_query("INSERT INTO {blocks_roles} (rid, module, delta) VALUES (%d, '%s', '%s')", $rid, $form_state['values']['module'], $delta);
+  }
+
+  drupal_set_message(t('The calendar block has been created.'));
+  cache_clear_all();
+
+  $form_state['redirect'] = 'admin/build/block';
+  return;
+}
+
+/**
+ * Confirm form for deletion
+ */
+function calendar_block_delete_block_form(&$form_state, $delta) {
+  $form = array();
+
+  $blocks = _calendar_block_block_list();
+  $title = $blocks[$delta]['info'];
+
+  $form['delta'] = array(
+    '#type' => 'value',
+    '#value' => $delta,
+    );
+  $form['block_title'] = array(
+    '#type' => 'value',
+    '#value' => $title,
+    );
+
+  $question = t('Are you sure you want to delete the block %title?', array('%title' => $title));
+  $path = 'admin/build/block';
+  $description = t('This action cannot be undone.');
+
+  return confirm_form($form, $question, $path, $description);
+}
+
+/**
+ * _submit handler for deletion
+ */
+function calendar_block_delete_block_form_submit($form, &$form_state) {
+  $delta = $form_state['values']['delta'];
+  $title = $form_state['values']['block_title'];
+  // delete settings
+  calendar_block_settings_reset($delta);
+  // delete block
+  db_query("DELETE FROM {blocks} WHERE module = 'calendar_block' AND delta = '%s'", $delta);
+  db_query("DELETE FROM {blocks_roles} WHERE module = 'calendar_block' AND delta = '%s'", $delta);
+  drupal_set_message(t('The "%name" block has been removed.', array('%name' => $title)));
+  cache_clear_all();
+  _calendar_block_block_list(TRUE); // clear static cache
+  $form_state['redirect'] = 'admin/build/block';
+}
+
+/**
+ * Get settings for a general calendar delta
+ */
+function calendar_block_settings_get($delta = 0, $key = NULL, $reset = FALSE) {
+  $defaults = array(
+    'background_color' => 'FFFFFF',
+    'font_color' => '494949',
+    'header_color' => '494949',
+    'link_color' => '027AC6',
+    'border_color' => 'a5a5a5',
+    'width' => 173,
+    'first_day_of_the_week' => 'mo',
+    );
+  static $all_settings;
+  if (!isset($all_settings) || $reset) {
+    $all_settings = variable_get('calendar_block_settings', array());
+  }
+  if (!$all_settings[$delta]) {
+    $all_settings[$delta] = $defaults;
+  }
+  if ($key) {
+    return $all_settings[$delta][$key];
+  }
+  else {
+    return $all_settings[$delta];
+  }
+}
+
+/**
+ * Reset calendar settings for a given delta, or all
+ */
+function calendar_block_settings_reset($delta = NULL) {
+  if (!isset($delta)) {
+    // delete all
+    variable_del('calendar_block_settings');
+  }
+  else {
+    $all_settings = variable_get('calendar_block_settings', array());
+    unset($all_settings[$delta]);
+    variable_set('calendar_block_settings', $all_settings);
+    return calendar_block_settings_get($delta, NULL, TRUE);
+  }
+}
+
+/**
+ * Set calendar settings for a given delta
+ */
+function calendar_block_settings_set($delta, $settings) {
+  $all_settings = variable_get('calendar_block_settings', $array);
+  $all_settings[$delta] = $settings;
+  variable_set('calendar_block_settings', $all_settings);
+  return calendar_block_settings_get($delta, NULL, TRUE);
+}
+
+/**
  * Implementation of hook_theme().
  */
 function calendar_block_theme() {
@@ -157,22 +412,23 @@ function calendar_block_theme() {
 function calendar_block_ajax() {
   $calendar = (object) $_POST;
 
-  $curr_date = ($calendar->year && $calendar->month) ? mktime(1, 1, 1, $calendar->month, 1, $calendar->year) : time();
+  // use the middle of the month
+  $curr_date = ($calendar->year && $calendar->month) ? gmmktime(1, 1, 1, $calendar->month, 15, $calendar->year) : gmmktime(1, 1, 1, gmdate('n'), 15, gmdate('Y'));
 
   $calendar->weekdays = json_decode($calendar->weekdays, TRUE);
   $weekdays = array_keys($calendar->weekdays);
 
-  $calendar->month = date('m', $curr_date); // The numeric current month (09)
-  $calendar->year = date('Y', $curr_date); // The numeric current year (2008)
+  $calendar->month = format_date($curr_date, 'custom', 'm'); // The numeric current month (09)
+  $calendar->year = format_date($curr_date, 'custom', 'Y'); // The numeric current year (2008)
 
   // If the month is equal to the current month, get the current day
-  if (date('Y-m', $curr_date) == date('Y-m')) {
-    $calendar->day = date('d', time()); // The numeric current day (20)
+  if (format_date($curr_date, 'custom', 'Y-m') == format_date(time(), 'custom', 'Y-m')) {
+    $calendar->day = format_date(time(), 'custom', 'd'); // The numeric current day (20)
   }
 
-  $calendar->month_str = date('F', $curr_date); // The current month (September)
+  $calendar->month_str = format_date($curr_date, 'custom', 'F'); // The current month (September)
   $calendar->days_in_month = cal_days_in_month(0, $calendar->month, $calendar->year); // The number of days in this month (31)
-  $calendar->first_day_of_month = drupal_substr(drupal_strtolower(date('D', mktime(0, 0, 0, $calendar->month, 1, $calendar->year))), 0, 2); // The first week day of this month (mo, tu, we ....)
+  $calendar->first_day_of_month = drupal_substr(drupal_strtolower(format_date(gmmktime(0, 0, 0, $calendar->month, 1, $calendar->year), 'custom', 'D')), 0, 2); // The first week day of this month (mo, tu, we ....)
 
   // If the first day of the month is not the same as the first day in the weekdays, set in the configuration settings,
   // we need to set the last days of the previous month first
@@ -225,15 +481,16 @@ function theme_calendar_block($calendar)
   $row_counter = 0;
   $num_rows = (count($calendar->dates) / 7);
   $weekdays = array_values($calendar->weekdays);
+  $cal_id = 'calendar_' . $calendar->delta;
 
-  $output[] = '  <div id="calendar">';
+  $output[] = '  <div id="' . $cal_id . '">';
 
   // Create the month and year row
-  $output[] = '    <div id="calendar_row'. $row_counter .'" class="clear-block">';
-  $output[] = '      <div id="nav" class="clear-block">';
-  $output[] = '        <div id="calendar_prev" class="'. ($calendar->month > 1 ? ($calendar->month - 1) ."-$calendar->year" : "12-". ($calendar->year - 1)) .'"><span>&lt;</span></div>';
-  $output[] = '        <div id="calendar_month">'. t($calendar->month_str) .' '. $calendar->year .'</div>';
-  $output[] = '        <div id="calendar_next" class="'. ($calendar->month < 12 ? ($calendar->month + 1) ."-$calendar->year" : "01-". ($calendar->year + 1)) .'"><span>&gt;</span></div>';
+  $output[] = '    <div id="' . $cal_id . '_row'. $row_counter .'" class="clear-block">';
+  $output[] = '      <div id="' . $cal_id . '_nav" class="nav clear-block">';
+  $output[] = '        <div id="' . $cal_id . '_prev" class="calendar_prev" title="'. ($calendar->month > 1 ? ($calendar->month - 1) ."-$calendar->year" : "12-". ($calendar->year - 1)) .'"><span>&lt;</span></div>';
+  $output[] = '        <div id="' . $cal_id . '_month" class="calendar_month">'. t($calendar->month_str) .' '. $calendar->year .'</div>';
+  $output[] = '        <div id="' . $cal_id . '_next" class="calendar_next" title="'. ($calendar->month < 12 ? ($calendar->month + 1) ."-$calendar->year" : "01-". ($calendar->year + 1)) .'"><span>&gt;</span></div>';
   $output[] = '      </div>';
 
   // Create the weekdays row
@@ -247,7 +504,7 @@ function theme_calendar_block($calendar)
   $day_counter = 0;
 
   // Create the days rows
-  $output[] = "    <div class=\"week\" id=\"calendar_row$row_counter\">";
+  $output[] = '    <div class="week calendar_row' . $row_counter . '" id="' . $cal_id . '_row' . $row_counter . '">';
   foreach ($calendar->dates as $date) {
     // Create an easy readable date for modules which use hook_calendar_block().
     $date->date = (drupal_strlen($date->month) == 1 ? "0$date->month" : $date->month) ."-$date->day-$date->year";
@@ -285,7 +542,7 @@ function theme_calendar_block($calendar)
     if ($row_counter < $num_rows && $day_counter == 0) {
       $row_counter++;
       $output[] = "    </div>";
-      $output[] = "    <div class=\"week\" id=\"calendar_row$row_counter\">";
+      $output[] = '    <div class="week calendar_row' . $row_counter . '" id="' . $cal_id . '_row' . $row_counter . '">';
     };
   }
   $output[] = "      <div class=\"clear-block\"></div>";
@@ -298,9 +555,10 @@ function theme_calendar_block($calendar)
  * The help page.
  */
 function calender_block_help_page() {
-  $output = '<p>'. t('The <em>calendar_block</em> module provides a fully customizable calendar block which can be placed in a region at the !blocks_link.', array('!blocks_link' => l(t('blocks section'), 'admin/build/block')));
-  $output .= ' '. t('In the !block_config of the calendar block, the calendar\'s layout can be fully changed. You can set the colors as well as the size of the calendar so it fits to your website\'s design.', array('!block_config' => l(t('configuration form'), 'admin/build/block/configure/calendar_block/0'))) .'</p>';
-  $output .= '<p>'. t('With this version of the calendar_block module, developers can use the hook_calendar_block() to alter the dates, as well as to set the date and the weekdays the calender has to load on a page call.') .'</p>';
+  $output = '<p>'. t('The <em>calendar_block</em> module provides multiple fully-customizable calendar blocks which can be placed in a region at the !blocks_link.', array('!blocks_link' => l(t('blocks section'), 'admin/build/block')));
+  $output .= ' '. t('To add a new calendar block, click the !add link in the !blocks_section local menu.', array('!add' => l('Add calendar block', 'admin/build/block/add-calendar-block'), '!blocks_section' => l('blocks section', 'admin/build/block')));
+  $output .= ' '. t('In the block configuration form of the calendar block, the calendar\'s layout can be fully changed. You can set the colors as well as the size of the calendar so it fits to your website\'s design.') .'</p>';
+  $output .= '<p>'. t('With this version of the calendar_block module, developers can use the hook_calendar_block() to alter the dates, as well as to set the date and the weekdays for each calendar loaded on a page call.') .'</p>';
   $output .= '<p>'. t('If the modules !colorpicker and !slider_textfield are installed, the layout of the calendar is dynamically changed when changing it in the block\'s configuration form.', array('!colorpicker' => l('Colorpicker', 'http://drupal.org/project/colorpicker'), '!slider_textfield' => l(t('Textfield to slider'), 'http://drupal.org/project/slider_textfield'))) .'</p>';
   $output .= '<h4>'. t('hook_calendar_block()') .'</h4>';
   $output .= '<p><strong>'. t('Definition') .':</strong></p>';
@@ -309,7 +567,9 @@ function calender_block_help_page() {
   $output .= '<p>'. t('Provide other modules a hook to change the data for the calendar. Modules can create links for dates, change the weekdays, or set the month the calendar has to load on page calls.') .'</p>';
   $output .= '<p><strong>'. t('Parameters') .':</strong></p>';
   $output .= '<p><code>&$calendar</code>: '. t('The calendar object which can be altered in the hook function (<code>$op == \'load\'</code>). The calendar object contains the following elements:') .'</p>';
-  $output .= '<p><ul><li><code>&$date->year</code>: '. t('The year on which the calendar is initialized (1900 - ....).') .'</li>';
+  $output .= '<ul>';
+  $output .= '<li><code>&$calendar->delta</code>: '. t('The machine-readable delta value set when then block is created.  Will only contain a-z, 0-9, and underscores.');
+  $output .= '<li><code>&$calendar->year</code>: '. t('The year on which the calendar is initialized (1900 - ....).') .'</li>';
   $output .= '<li><code>&$calendar->month</code>: '. t('The month on which the calendar is initialized (1 - 12).') .'</li>';
   $output .= '<li><code>&$calendar->weekdays</code>: '. t('An array of the week as shown on top of the calendar. This can be used to change the titles of weekdays. Note that the keys in this array should not be changed!');
   $output .= ' '. t('Both the weekdays and the month\'s title are translatable using the translate !translate_page. This is how the array is built:', array('!translate_page' => l(t('translate interface page'), 'admin/build/translate/search')));
@@ -324,26 +584,38 @@ function calender_block_help_page() {
   $output .= '      \'su\' => \'su\','."<br />";
   $output .= '    );</pre>';
   $output .= '  </li>';
-  $output .= '</ul></p>';
+  $output .= '</ul>';
   $output .= '<p><code>&$date</code>: '. t('The date object which can be altered in the hook function (<code>$op == \'alter\'</code>). The date object contains the following elements:') .'</p>';
-  $output .= '<p><ul><li><code>&$date->day</code>: '. t('The day of the current date object (1 - 31).') .'</li>';
+  $output .= '<ul>';
+  $output .= '<li><code>&$date->day</code>: '. t('The day of the current date object (1 - 31).') .'</li>';
   $output .= '<li><code>&$date->month</code>: '. t('The month of the current date object (1 - 12).') .'</li>';
   $output .= '<li><code>&$date->year</code>: '. t('The year of the current date object (1900 - ....).') .'</li>';
   $output .= '<li><code>&$date->date</code>: '. t('A string representation of the current date ("mm-dd-yy").') .'</li>';
   $output .= '<li><code>&$date->content</code>: '. t('This is the part where it gets interesting. The content of the day presented in the calendar block can be changed here. Regularly you want to set it to a link referring to a node which has been created on this date.') .'</li>';
-  $output .= '</ul></p>';
+  $output .= '</ul>';
   $output .= '<p><code>&$op</code>: '. t('What kind of action is being performed. Possible values:') .'</p>';
-  $output .= '<p><ul><li>"alter": '. t('In this operation $date->content can be changed.') .'</li>';
-  $output .= '<li>"load": '. t('In this operation you can set the month on which the calendar has to be loaded.') .'</li>';
-  $output .= '</ul></p>';
+  $output .= '<ul>';
+  $output .= '<li>"load": '. t('Called when the calendar is initially loaded. In this operation you can set the month on which the calendar has to be loaded.') .'</li>';
+  $output .= '<li>"alter": '. t('Called for every date on the calendar display, and during ajax requests. In this operation $date->content can be changed.') .'</li>';
+  $output .= '</ul>';
   $output .= '<p><strong>'. t('Code') .':</strong></p>';
   $output .= '<p><pre class="php">';
   $output .= 'function gallery_calendar_block(&$calendar, &$date, $op) {'."<br />";
   $output .= '  switch($op) {'."<br />";
   $output .= '    case \'load\':'."<br />";
-  $output .= '      // Here the date is fixed on october 1978'."<br />";
-  $output .= '      $calendar->month = 10;'."<br />";
-  $output .= '      $calendar->year = 1978;'."<br />";
+  $output .= '      switch ($calendar->delta) {'."<br />";
+  $output .= '        case \'my_calendar\':'."<br />";
+  $output .= '          // For the delta \'my_calendar\' the date is fixed on october 1978'."<br />";
+  $output .= '          $calendar->month = 10;'."<br />";
+  $output .= '          $calendar->year = 1978;'."<br />";
+  $output .= '          break;'."<br />";
+  $output .= '        case \'your_calendar\':'."<br />";
+  $output .= '          // For the delta \'your_calendar\' the date is being parsed out from arguments. '."<br />";
+  $output .= '          // This is sometimes useful with views arguments.'."<br />";
+  $output .= '          $calendar->month = arg(1);'."<br />";
+  $output .= '          $calendar->year = arg(2);'."<br />";
+  $output .= '          break;'."<br />";
+  $output .= '      }'."<br />";
   $output .= "<br />";
   $output .= '      // Change the weekday\'s format and set the first day of the week to sunday.'."<br />";
   $output .= '      $calendar->weekdays =  array('."<br />";
@@ -357,23 +629,27 @@ function calender_block_help_page() {
   $output .= '      );'."<br />";
   $output .= '      break;'."<br />";
   $output .= '    case \'alter\':'."<br />";
-  $output .= '      if ($date->date == \'10-19-1978\') {'."<br />";
-  $output .= '        // Create a link from 19 october 1978'."<br />";
-  $output .= '        $date->content = l($date->day, "node");'."<br />";
+  $output .= '      switch ($calendar->delta) {'."<br />";
+  $output .= '        case \'my_calendar\':'."<br />";
+  $output .= '          if ($date->date == \'10-19-1978\') {'."<br />";
+  $output .= '            // For the delta \'my_calendar\' create a link to node 123 from 19 october 1978'."<br />";
+  $output .= '            $date->content = l($date->day, "node/123");'."<br />";
+  $output .= '          }'."<br />";
+  $output .= '        break;'."<br />";
   $output .= '      }'."<br />";
-  $output .= '      else if ($date->year > 2008 && $date->month >= 6 && $date->weekday == \'mo\') {'."<br />";
+  $output .= "<br />";
+  $output .= '      if ($date->year > 2008 && $date->month >= 6 && $date->weekday == \'mo\') {'."<br />";
   $output .= '        // Create a tooltip for each monday after may 2008.'."<br />";
   $output .= '        $date->content = \'&lt;span class="js_tooltip"&gt;\'. $date->day .\'&lt;/span&gt;;'."<br />";
   $output .= '        $date->content .= \'&lt;div class="js_tooltip_hidden"&gt;Content for this tooltip&lt;/div&gt;\';'."<br />";
   $output .= '      }'."<br />";
-  $output .= '      break;'."<br />";
   $output .= '  }'."<br />";
   $output .= '}'."<br />";
   $output .= '</pre></p>';
   $output .= '<p><strong>'. t('TODO') .':</strong></p>';
-  $output .= '<p><ul><li><strong>Caching</strong>: '. t('Caching the calendar would be a huge performance improvement') .'</li>';
+  $output .= '<ul><li><strong>Caching</strong>: '. t('Caching the calendar would be a huge performance improvement') .'</li>';
   $output .= '<li><strong>Configuration for nodes</strong>: '. t('In the configuration options of the calendar block, users should be abled to check which nodetypes should be tracked by the calendar_block module. In the publication options of node form, users should be able to uncheck the node from being tracked.') .'</li>';
-  $output .= '</ul></p>';
+  $output .= '</ul>';
   return $output;
 }
 
@@ -390,7 +666,6 @@ if (!function_exists('cal_days_in_month'
   }
 }
 
-
 /**
  * json_decode for < PHP 5
  */
Index: images/today.png
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/calendar_block/images/today.png,v
retrieving revision 1.1
diff -u -p -r1.1 today.png
Binary files /tmp/cvsx9g3bq and today.png differ
