Hi,
I made some small additions/ changes to this really nice module so that I could use it for my website.
Now I wonder if they could be useful for the original module...? (I'm not a big developer, so please forgive my dilettante efforts.) ;o)

I attached my modified version of scheduler.module as a text file.

1.) First of all, I added a basic validation function with two helper functions to make sure that
- publication and expiration date aren't in the past,
- the expiration date lies ahead of the publication date and
- the dates entered are valid.

/**
* Implementation of hook_form_validate()
* Validate the input of the publish and unpublish date fields. Uses the helper function 'timediff_date' (or alternatively 'timediff_timestamp') to make sure that the actual or a future date is entered.
*/
function _scheduler_form_validate($form_id, $form_values) {
   $publishtime ='';
   $unpublishtime = '';
   if (is_array($form_values) && isset($form_values['publish_on'])) {
      $publishtime = strtotime($form_values['publish_on']);
      $timediff_pub = timediff_date($form_values['publish_on']);
      if ($publishtime === false) {
         form_set_error('publish_on', t('The entered publication date is invalid.'));
      }
      else if ($timediff_pub < 0) {
         form_set_error('publish_on', t('The entered publication date occurs in the past.'));
      }
   }

   if (is_array($form_values) && isset($form_values['unpublish_on'])) {
      $unpublishtime = strtotime($form_values['unpublish_on']);
      $timediff_unpub = timediff_date($form_values['unpublish_on']);
      if ($unpublishtime === false) {
         form_set_error('unpublish_on', t('The entered expiration date is invalid.'));
      }
      else if ($timediff_unpub < 0) {
         form_set_error('unpublish_on', t('The entered expiration date occurs in the past.'));
      }
      else if (isset($form_values['publish_on']) && $unpublishtime < $publishtime) {
         form_set_error('unpublish_on', t('The expiration date can\'t lie ahead of the publication date.'));
      }
   }
}


/**
* Function checks the time difference between a specified date to now in days. 
* @param $date
* @return Positive value for number of days in the future, negative value for number of days in the past.
* A date in standard english format 'Y-m-d'.
*/
function timediff_date($date){
    $date_diff = round( (strtotime($date)-strtotime(date('Y-m-d'))) / 86400, 0 );
   return $date_diff;
}

/**
* Function checks the time difference between a specified timestamp to now in days. 
* @param $date
* @return Positive value for number of days in the future, negative value for number of days in the past.
* A timestamp.
*/
function timediff_timestamp($timestamp){
   $date_diff = round( ($timestamp-strtotime(date('Y-m-d'))) / 86400, 0 );
   return $date_diff;
}

2.) I also added three jscalender properties to the form_alter function so I could change the format of the date display (I didn't want the time to be displayed)

  '#jscalendar_ifFormat' => $jscalendar ? '%d.%m.%Y' : array(),
  // Don't show time.
  '#jscalendar_showsTime' => $jscalendar ? 'false' : array(),
  // Show 24-hour clock.
  '#jscalendar_timeFormat' => $jscalendar ? '24' : '',
CommentFileSizeAuthor
scheduler.module.modified.txt14.26 KBolio

Comments

AjK’s picture

Status: Active » Needs work

You attached the entire module, you need to send a patch, see http://drupal.org/patch

eric-alexander schaefer’s picture

Status: Needs work » Fixed

No response from the original poster for 31 weeks. Most of it is fixed now anyways.

eric-alexander schaefer’s picture

Status: Fixed » Closed (fixed)