Index: scheduler.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/scheduler/scheduler.module,v
retrieving revision 1.34
diff -u -r1.34 scheduler.module
--- scheduler.module 17 Mar 2006 21:08:39 -0000 1.34
+++ scheduler.module 5 May 2006 06:17:13 -0000
@@ -27,7 +27,19 @@
}
function scheduler_settings() {
- return form_radios(t('Form display mode'), 'scheduler_form_mode', variable_get('scheduler_form_mode', 0), array(t('Allow post and hide scheduling'), t('Only allow post scheduling'), t('Only allow hide scheduling')), t('What options should the scheduler form offer?'));
+ $form['scheduler_form_mode'] = array(
+ '#type' => 'radios',
+ '#title' => t('Form display mode'),
+ '#default_value' => variable_get('scheduler_form_mode', 0),
+ '#options' => array(
+ '0' => t('Allow post and hide scheduling'),
+ '1' => t('Only allow post scheduling'),
+ '2' => t('Only allow hide scheduling'),
+ ),
+ '#description' => t('What options should the scheduler form offer?'),
+ );
+
+ return $form;
}
function scheduler_write($node, $op, $arg) {
@@ -131,84 +143,115 @@
case 'delete':
scheduler_remove_schedule($node);
break;
- case 'form pre':
- if (user_access('schedule nodes')) {
+ }
+}
- // Build up date components array
- $month_names = array(1 => t('January'), t('February'), t('March'), t('April'), t('May'), t('June'), t('July'), t('August'), t('September'), t('October'), t('November'), t('December'));
- $date_components = array(
- 'year' => array('Y', scheduler_range(date('Y'), date('Y') + 5)),
- 'month' => array('m', $month_names),
- 'day' => array('d', scheduler_range(1, 31)),
- 'hour' => array('H', scheduler_range(0, 23)),
- 'minute' => array('i', scheduler_range(0, 59))
- );
+/**
+ * Implementation of hook_form_alter().
+ */
+function scheduler_form_alter($form_id, &$form) {
+ if (isset($form['type']) && $form['type']['#value'] .'_node_form' == $form_id) {
+ if (user_access('schedule nodes')) {
+ // Build up date components array
+ $month_names = array(1 => t('January'), t('February'), t('March'), t('April'), t('May'), t('June'), t('July'), t('August'), t('September'), t('October'), t('November'), t('December'));
+ $date_components = array(
+ 'year' => array('Y', drupal_map_assoc(range(date('Y'), date('Y')+5))),
+ 'month' => array('m', $month_names),
+ 'day' => array('d', drupal_map_assoc(range(1, 31))),
+ 'hour' => array('H', drupal_map_assoc(range(0, 23))),
+ 'minute' => array('i', drupal_map_assoc(range(0, 59)))
+ );
+
+ // Form element specs (time, enabled, title, description)
+ $form_elements = array(
+ 'scheduler_post' => array(time(), FALSE, t('Automatically post document'), t('The date at which your document will be automatically posted.
Do not check the enabling checkbox unless you want to schedule this document.')),
+ 'scheduler_hide' => array(time(), FALSE, t('Automatically hide document'), t('The date at which your document will be automatically hidden.
Do not check the enabling checkbox unless you want to schedule this document.'))
+ );
+
+ // Get edit information from post if possible
+ $node = isset($form['#node']) ? $form['#node'] : NULL;
+ if (isset($_POST['edit']) && count($_POST['edit'])) {
+ $edit = (object) $_POST['edit'];
+ if ($edit->scheduler_post) {
+ $form_elements['scheduler_post'][0] = scheduler_nodetime($edit, 'post');
+ $form_elements['scheduler_post'][1] = TRUE;
+ }
+ if ($edit->scheduler_hide) {
+ $form_elements['scheduler_hide'][0] = scheduler_nodetime($edit, 'hide');
+ $form_elements['scheduler_hide'][1] = TRUE;
+ }
+ }
+ elseif ($node->nid) {
+ $result = db_query('SELECT timestamp_hidden, timestamp_posted FROM {scheduler} WHERE nid = %d', $node->nid);
+ $schedule = db_fetch_object($result);
+ if ($schedule->timestamp_posted) {
+ $form_elements['scheduler_post'][0] = $schedule->timestamp_posted;
+ $form_elements['scheduler_post'][1] = TRUE;
+ }
+ if ($schedule->timestamp_hidden) {
+ $form_elements['scheduler_hide'][0] = $schedule->timestamp_hidden;
+ $form_elements['scheduler_hide'][1] = TRUE;
+ }
+ }
+
+ // Hide controls if admin requested
+ switch (variable_get('scheduler_form_mode', 0)) {
+ case 0:
+ // Allow both controls
+ break;
+ case 1:
+ // Allow post control
+ unset($form_elements['scheduler_hide']);
+ break;
+ case 2:
+ // Allow hide control
+ unset($form_elements['scheduler_post']);
+ break;
+ }
- // Form element specs (time, enabled, title, description)
- $form_elements = array(
- 'scheduler_post' => array(time(), FALSE, t('Automatically post document'), t('The date at which your document will be automatically posted.
Do not check the enabling checkbox unless you want to schedule this document.')),
- 'scheduler_hide' => array(time(), FALSE, t('Automatically hide document'), t('The date at which your document will be automatically hidden.
Do not check the enabling checkbox unless you want to schedule this document.'))
+ // Compose form to post and hide nodes
+ $form['scheduler'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Scheduling'),
+ '#weight' => 26,
+ '#collapsible' => TRUE,
+ '#collapsed' => TRUE,
+ );
+ foreach ($form_elements as $fname => $felem) {
+ $form['scheduler'][$fname]['begin'] = array(
+ '#type' => 'markup',
+ '#value' => '