--- C:/Documents and Settings/Sunil/Desktop/availability_calendars/availability_calendars.module Sat Oct 10 04:21:51 2009
+++ C:/Documents and Settings/Sunil/Desktop/availability_calendars.module Sun Dec 27 13:31:19 2009
@@ -1,5 +1,5 @@
'fieldset',
- '#title' => t('Week @week', array('@week' => $week)),
+ '#title' => 'Week '. $week,
);
$form['week-'. $week]['note-'. $week] = array(
'#type' => 'textfield',
- '#title' => t('Note'),
+ '#title' => 'Note',
'#default_value' => $notes[$week],
- '#description' => t('This will be displayed beside the week in the calendar. It could include, for example, a weekly price.'),
+ '#description' => 'This will be displayed beside the week in the calendar. It could include, for example, a weekly price.',
);
if ($week == 1) {
$daysinweekremaining = 7 - $month_meta['firstday'];
@@ -217,9 +204,6 @@
return $form;
}
-/**
- * Callback function for submitting a node edit form.
- */
function availability_calendars_node_edit_form_submit($form, &$form_state) {
$nid = check_plain($form_state['values']['nid']);
$year = check_plain($form_state['values']['year']);
@@ -261,7 +245,7 @@
db_query('INSERT INTO {availability_calendars_day} (nid, year, month, day, status) VALUES (%d, %d, %d, %d, %d)', $nid, $year, $month, $day, $status);
}
- drupal_set_message(t('Availability information saved.'));
+ drupal_set_message('Availability information saved.');
}
/**
@@ -287,8 +271,18 @@
*/
function theme_availability_calendars_node($node, $year = 2008, $month = 01, $monthstodisplay = 12) {
+ drupal_add_css(drupal_get_path('module', 'availability_calendars') .'/availability_calendars.css');
$rows = array();
+ // Fill availability array
+ /* foreach ($node->availability_dates as $k => $v) {
+ foreach ($v as $i) {
+ $booked[date("Y", $i['date'])][date("m", $i['date'])][date("d", $i['date'])] = 1;
+ }
+ } */
+
+
+
// Calendar code based on example at http://evolt.org/node/60673 :
$day = 1;
@@ -297,8 +291,22 @@
$firstletter = variable_get('availability_calendars_'. $node->nid .'_firstletter', 0);
// Create our key for the availability calendar if the node has it set to do so
- if($showkey == 1) {
- $output .= availability_calendars_key();
+ if($showkey == 1) { //use all the same classes for cells and table, so it styles the same as the calendars
+ $keytitle = '
'.t('Key').'
';
+ $headers = array(
+ 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.'
';
}
$monthsremaining = $monthstodisplay;
@@ -327,33 +335,9 @@
}
return $output;
-}
-/**
- * Creates a key for our calendars.
- **/
-function availability_calendars_key() {
- //use all the same classes for cells and table, so it styles the same as the calendars
- $keytitle = ''.t('Key').'
';
- $headers = array(
- 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'));
- return ''.$keytitle.$key.'
';
}
-/**
- * month_meta().
- */
function availability_calendars_month_meta($year, $month, $startofweek) {
$month_meta['daysinmonth'] = date("t", mktime(0, 0, 0, $month, 1, $year));
$month_meta['firstday'] = date("w", mktime(0, 0, 0, $month, 1, $year)) + $startofweek;
@@ -368,17 +352,14 @@
return $month_meta;
}
-/**
- * Implementation of hook_theme().
- * produces our calendars on the viewing of an availability_calendars enabled node.
- */
function theme_availability_calendars_month($node, $year, $month, $startofweek, $booked, $firstletter) {
+global $user;
$month_meta = availability_calendars_month_meta($year, $month, $startofweek);
/* here we list all the days of the week, an array of 14 (two full weeks) so that if users select monday
as the first day we still get a full week in our following loop */
$days = array(
13 => t('Mon'),
- 12 => t('Tue'),
+ 12 =>t('Tue'),
11 => t('Wed'),
10 => t('Thu'),
9 => t('Fri'),
@@ -404,7 +385,9 @@
}
}
if (user_access('edit availability calendars')) { //month_title has the edit link if permissable
- $month_title = t("@date", array('@date' => format_date(mktime(12, 0, 0, $month, 1, $year), 'custom', 'F Y'))).' '.l(t('edit'), 'availability-calendars/'. $node->nid .'/'. date('Y/m', mktime(0, 0, 0, $month, 1, $year)) .'/edit', array('query' => 'destination=node/'. $node->nid));
+if (user_access('edit own availability calendars') && ($user->uid == $node->uid)) {
+ $month_title = t("@date", array('@date' => format_date(mktime(12, 0, 0, $month, 1, $year), 'custom', 'F Y'))).' '.l('edit', 'availability-calendars/'. $node->nid .'/'. date('Y/m', mktime(0, 0, 0, $month, 1, $year)) .'/edit', array('query' => 'destination=node/'. $node->nid));
+ }
}
else { // no edit link
$month_title = t("@date", array('@date' => format_date(mktime(12, 0, 0, $month, 1, $year), 'custom', 'F Y')));
@@ -462,9 +445,6 @@
return ''.$month_title.$output.'
';
}
-/**
- * availability_calendars status options.
- */
function availability_calendars_options() {
// TODO: make these configurable
return array(
@@ -475,8 +455,7 @@
}
/**
- * Implementation of hook_form_alter().
- * All form alterations needed for the calendars.
+ * Implementation of hook_form_alter();
*/
function availability_calendars_form_alter(&$form, &$form_state, $form_id) {
global $user;
@@ -490,12 +469,15 @@
'#collapsed' => !variable_get('availability_calendars_'. $form['#node_type']->type, 0),
);
$form['availability_calendars']['availability_calendars'] = array(
- '#type' => 'checkbox',
+ '#type' => 'radios',
'#title' => t('Availability calendar support'),
'#default_value' => variable_get('availability_calendars_'. $form['#node_type']->type, 0),
+ '#options' => array(
+ 0 => t('Disabled'),
+ 1 => t('Enabled')
+ ),
'#description' => t('Enable or disable availability support for this content type. If enabled, node owner will be able to specify node availability.'),
);
- // TODO: add options for status' here
}
// Alter node edit form if availability support is enabled for that content type
@@ -590,42 +572,3 @@
function availability_calendars_enabled($node_type) {
return variable_get('availability_calendars_'. $node_type, 0);
}
-
-/**
- * All block functions
- */
-
-/**
- * Implementation of hook_block().
- *
- * Generates block for the legend to be shown in when on availability calendar nodes
- */
-function availability_calendars_block($op = 'list', $delta = 0, $edit = array()) {
- // The $op parameter determines what piece of information is being requested.
- switch ($op) {
- case 'list':
- $blocks['key']['info'] = t('Availability Calendar Key');
- return $blocks;
- case 'configure':
- break;
- case 'save':
- break;
- case 'view':
- switch ($delta) {
- case 'key':
- $block = availability_calendars_block_key();
- break;
- }
- return $block;
- }
-}
-
-/**
- * Produce the actual availabilty_calendars key for the block.
- */
-function availability_calendars_block_key() {
- $block = array();
- $block['subject'] = variable_get('availability_calendars_title', t('Availability Key'));
- $block['content'] = availability_calendars_key();
- return($block);
-}
\ No newline at end of file
--- C:/Documents and Settings/Sunil/Desktop/availability_calendars/availability_calendars.module Sat Oct 10 04:21:51 2009
+++ C:/Documents and Settings/Sunil/Desktop/availability_calendars.module Sun Dec 27 13:31:19 2009
@@ -1,5 +1,5 @@
'fieldset',
- '#title' => t('Week @week', array('@week' => $week)),
+ '#title' => 'Week '. $week,
);
$form['week-'. $week]['note-'. $week] = array(
'#type' => 'textfield',
- '#title' => t('Note'),
+ '#title' => 'Note',
'#default_value' => $notes[$week],
- '#description' => t('This will be displayed beside the week in the calendar. It could include, for example, a weekly price.'),
+ '#description' => 'This will be displayed beside the week in the calendar. It could include, for example, a weekly price.',
);
if ($week == 1) {
$daysinweekremaining = 7 - $month_meta['firstday'];
@@ -217,9 +204,6 @@
return $form;
}
-/**
- * Callback function for submitting a node edit form.
- */
function availability_calendars_node_edit_form_submit($form, &$form_state) {
$nid = check_plain($form_state['values']['nid']);
$year = check_plain($form_state['values']['year']);
@@ -261,7 +245,7 @@
db_query('INSERT INTO {availability_calendars_day} (nid, year, month, day, status) VALUES (%d, %d, %d, %d, %d)', $nid, $year, $month, $day, $status);
}
- drupal_set_message(t('Availability information saved.'));
+ drupal_set_message('Availability information saved.');
}
/**
@@ -271,11 +255,11 @@
return array('availability_calendars_node' => array(
'arguments' => array('node' => NULL, 'year' => 2008, 'month' => 01, 'monthstodisplay' => 12)
- ),
- 'availability_calendars_month' => array(
+ ),
+ 'availability_calendars_month' => array(
'arguments' => array('node' => NULL, 'year' => 2008, 'month' => 01, 'startofweek' => NULL, 'booked' => NULL, 'firstletter' => NULL)
- )
- );
+ )
+ );
}
@@ -287,8 +271,18 @@
*/
function theme_availability_calendars_node($node, $year = 2008, $month = 01, $monthstodisplay = 12) {
+ drupal_add_css(drupal_get_path('module', 'availability_calendars') .'/availability_calendars.css');
$rows = array();
+ // Fill availability array
+ /* foreach ($node->availability_dates as $k => $v) {
+ foreach ($v as $i) {
+ $booked[date("Y", $i['date'])][date("m", $i['date'])][date("d", $i['date'])] = 1;
+ }
+ } */
+
+
+
// Calendar code based on example at http://evolt.org/node/60673 :
$day = 1;
@@ -297,8 +291,22 @@
$firstletter = variable_get('availability_calendars_'. $node->nid .'_firstletter', 0);
// Create our key for the availability calendar if the node has it set to do so
- if($showkey == 1) {
- $output .= availability_calendars_key();
+ if($showkey == 1) { //use all the same classes for cells and table, so it styles the same as the calendars
+ $keytitle = ''.t('Key').'
';
+ $headers = array(
+ 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.'
';
}
$monthsremaining = $monthstodisplay;
@@ -327,33 +335,9 @@
}
return $output;
+
}
-/**
- * Creates a key for our calendars.
- **/
-function availability_calendars_key() {
- //use all the same classes for cells and table, so it styles the same as the calendars
- $keytitle = ''.t('Key').'
';
- $headers = array(
- 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'));
- return ''.$keytitle.$key.'
';
-}
-
-/**
- * month_meta().
- */
function availability_calendars_month_meta($year, $month, $startofweek) {
$month_meta['daysinmonth'] = date("t", mktime(0, 0, 0, $month, 1, $year));
$month_meta['firstday'] = date("w", mktime(0, 0, 0, $month, 1, $year)) + $startofweek;
@@ -368,17 +352,14 @@
return $month_meta;
}
-/**
- * Implementation of hook_theme().
- * produces our calendars on the viewing of an availability_calendars enabled node.
- */
function theme_availability_calendars_month($node, $year, $month, $startofweek, $booked, $firstletter) {
+global $user;
$month_meta = availability_calendars_month_meta($year, $month, $startofweek);
/* here we list all the days of the week, an array of 14 (two full weeks) so that if users select monday
as the first day we still get a full week in our following loop */
$days = array(
13 => t('Mon'),
- 12 => t('Tue'),
+ 12 =>t('Tue'),
11 => t('Wed'),
10 => t('Thu'),
9 => t('Fri'),
@@ -404,7 +385,9 @@
}
}
if (user_access('edit availability calendars')) { //month_title has the edit link if permissable
- $month_title = t("@date", array('@date' => format_date(mktime(12, 0, 0, $month, 1, $year), 'custom', 'F Y'))).' '.l(t('edit'), 'availability-calendars/'. $node->nid .'/'. date('Y/m', mktime(0, 0, 0, $month, 1, $year)) .'/edit', array('query' => 'destination=node/'. $node->nid));
+if (user_access('edit own availability calendars') && ($user->uid == $node->uid)) {
+ $month_title = t("@date", array('@date' => format_date(mktime(12, 0, 0, $month, 1, $year), 'custom', 'F Y'))).' '.l('edit', 'availability-calendars/'. $node->nid .'/'. date('Y/m', mktime(0, 0, 0, $month, 1, $year)) .'/edit', array('query' => 'destination=node/'. $node->nid));
+ }
}
else { // no edit link
$month_title = t("@date", array('@date' => format_date(mktime(12, 0, 0, $month, 1, $year), 'custom', 'F Y')));
@@ -462,9 +445,6 @@
return ''.$month_title.$output.'
';
}
-/**
- * availability_calendars status options.
- */
function availability_calendars_options() {
// TODO: make these configurable
return array(
@@ -475,8 +455,7 @@
}
/**
- * Implementation of hook_form_alter().
- * All form alterations needed for the calendars.
+ * Implementation of hook_form_alter();
*/
function availability_calendars_form_alter(&$form, &$form_state, $form_id) {
global $user;
@@ -490,12 +469,15 @@
'#collapsed' => !variable_get('availability_calendars_'. $form['#node_type']->type, 0),
);
$form['availability_calendars']['availability_calendars'] = array(
- '#type' => 'checkbox',
+ '#type' => 'radios',
'#title' => t('Availability calendar support'),
'#default_value' => variable_get('availability_calendars_'. $form['#node_type']->type, 0),
+ '#options' => array(
+ 0 => t('Disabled'),
+ 1 => t('Enabled')
+ ),
'#description' => t('Enable or disable availability support for this content type. If enabled, node owner will be able to specify node availability.'),
);
- // TODO: add options for status' here
}
// Alter node edit form if availability support is enabled for that content type
@@ -589,43 +571,4 @@
*/
function availability_calendars_enabled($node_type) {
return variable_get('availability_calendars_'. $node_type, 0);
-}
-
-/**
- * All block functions
- */
-
-/**
- * Implementation of hook_block().
- *
- * Generates block for the legend to be shown in when on availability calendar nodes
- */
-function availability_calendars_block($op = 'list', $delta = 0, $edit = array()) {
- // The $op parameter determines what piece of information is being requested.
- switch ($op) {
- case 'list':
- $blocks['key']['info'] = t('Availability Calendar Key');
- return $blocks;
- case 'configure':
- break;
- case 'save':
- break;
- case 'view':
- switch ($delta) {
- case 'key':
- $block = availability_calendars_block_key();
- break;
- }
- return $block;
- }
-}
-
-/**
- * Produce the actual availabilty_calendars key for the block.
- */
-function availability_calendars_block_key() {
- $block = array();
- $block['subject'] = variable_get('availability_calendars_title', t('Availability Key'));
- $block['content'] = availability_calendars_key();
- return($block);
}