*************** function theme_availability_calendars_no
*** 313,326 ****
t('Color'),
t('Availability')
);
- $rows = array( // keystatus class used to allow better styling of the status column
- array(array('data' => ' ', 'class' => 'calavailable'),
- array('data' => t('Available'), 'class' => 'keystatus')),
- array(array('data' => ' ', 'class' => 'calnotavailable'),
- array('data' => t('Fully booked'), 'class' => 'keystatus')),
- array(array('data' => ' ', 'class' => 'calnotavailableprov'),
- array('data' => t('Provisionally booked'), 'class' => 'keystatus'))
- );
$key = theme_table($headers, $rows, array('class' => 'cal'));
$output .= '
'.$keytitle.$key.'
';
}
--- 505,522 ----
t('Color'),
t('Availability')
);
+
+ $rows = array();
+ $options = availability_calendars_options();
+
+ foreach ($options as $id => $label){
+ $css = availability_calendars_option_css($label);
+ $rows[] = array(
+ array('data' => ' ', 'class' => $css),
+ array('data' => t($label), 'class' => 'keystatus')
+ );
+ }
+
$key = theme_table($headers, $rows, array('class' => 'cal'));
$output .= ''.$keytitle.$key.'
';
}
*************** function theme_availability_calendars_mo
*** 462,477 ****
return ''.$month_title.$output.'
';
}
function availability_calendars_options() {
- // TODO: make these configurable
- return array(
- 0 => t('Available'),
- 1 => t('Fully booked'),
- 2 => t('Provisionally booked')
- );
}
/**
* Implementation of hook_form_alter();
*/
function availability_calendars_form_alter(&$form, &$form_state, $form_id) {
--- 658,731 ----
return ''.$month_title.$output.'
';
}
+ /**
+ * Get labels for calendars. If none have been defined by the administrator, return the default set.
+ *
+ * @return
+ * An array of labels, in the form array(label_id => t('label name'))
+ */
function availability_calendars_options() {
+ $labels = availability_calendars_custom_options();
+
+ if (!$labels) {
+ $labels = array(
+ 0 => t('Available'),
+ 1 => t('Fully booked'),
+ 2 => t('Provisionally booked')
+ );
+ }
+
+ return $labels;
+ }
+
+ /**
+ * Get custom labels for calendars, or an empty array if none have been set.
+ *
+ * @param $field
+ * Optionally, the field you'd like to retrieve
+ *
+ * @return
+ * An array of labels, in the form array(label_id => t('label name'))
+ * If $field is set to 'label' or 'lid', returns an array of those field values
+ */
+ function availability_calendars_custom_options($field = 'all') {
+ $result = db_query("SELECT * FROM availability_calendars_labels ORDER BY label");
+
+ $labels = array();
+ $row = NULL;
+ while ($row = db_fetch_array($result)) {
+ if ($field != 'all'){
+ $labels[] = ($field == 'label')? t($row['label']) : $row[$field];
+ } else {
+ $labels[$row['lid']] = t($row['label']);
+ }
+ }
+
+ return $labels;
}
/**
+ * Get the CSS class for this option label
+ *
+ * @param $label
+ * The label for this option
+ *
+ * @return
+ * A string representing a CSS class. For backwards compatibility, default values get their historical css class
+ */
+ function availability_calendars_option_css($label) {
+ if ($label == 'Available')
+ return 'calavailable';
+ if ($label == 'Fully booked')
+ return 'calnotavailable';
+ if ($lable == 'Provisionally booked')
+ return 'calnotavailableprov';
+
+ return str_replace(" ", "-", strtolower($label));
+ }
+
+
+ /**
* Implementation of hook_form_alter();
*/
function availability_calendars_form_alter(&$form, &$form_state, $form_id) {