[kronolith] Possible workaround for dayless weekly new-event crash.

Daniel Gordon dan@env.leeds.ac.uk
Mon, 5 Aug 2002 16:28:54 +0100 (BST)


This is a probably rather ameteurish workaround for a problem we found with
kronolith, but we hope it may be of some interest.  Here are some details.

The problem occured when creating a new event in kronolith:  if we clicked
the "recur weekly" button, but didn't choose a day of the week for it to 
recur on, then pressed "Save Event", we became locked out of kronolith 
altogether until we went into the mysql database and manually removed the
offending event.  This appeared to be consistent behaviour on our system.

Before attempting to address this problem directly (which we have not done
yet), it occured to us that:

1.  It would be good if the day of the week for recurrence would default to
the day of the week of the date in the "Start on" section of the form;

2.  That even with the above, we should still guard against the possibility
that a user could (inadvertently, we hope!) uncheck the defaulted day of
the week for recurrence, so that the form would then be sent without a
day of the week checked.

To achieve this, we made the following changes:

===========================================
To $KRONOLITH/templates/edit/javascript.inc:
===========================================
Function "setinterval()" now looks like:
-------------------------------------
function setInterval(field)
{
    var i_to_choose = -1;
    var form = document.event;
    elt = eval("document.event." + field);
    if (elt.value == "") {
				 //  DRHG-comment:  this is where the weekly  //
				//  ..interval is set, not in "setRecur ()":  //
        elt.value = 1;
    }
							    //  DRHG/JL-add:  //
		//  This appears to return seconds, rather than milliseconds  //
			  //  ..as the manual (developer.netscape.com) says:  //

    var startDate_millis = Date.UTC
		(form.start_year[form.start_year.selectedIndex].value,
		form.start_month[form.start_month.selectedIndex].value,
		form.start_day[form.start_day.selectedIndex].value,
		form.start_hour[form.start_hour.selectedIndex].value,
		form.start_min[form.start_min.selectedIndex].value);

       //  This line was found by trial and error:  here "start_day_of_week"  //
	  //  ..is aimed at the index of "document.event.elements[i]", which  //
	 //  ..appears to go backwards through the days of the week.  So the  //
	       //  ..order is the reverse of the KRONOLITH_MASK definitions?  //

    var start_day_of_week = 6 - ((3 + (startDate_millis / 86400)) % 7);

    document.event.elements["weekly[]"][start_day_of_week].checked = true;

						     //  END of DRHG/JL-add.  //

    if (field == 'recur_daily_interval') clearFields(1);
    else if (field == 'recur_weekly_interval') clearFields(2);
    else if (field == 'recur_day_of_month_interval') clearFields(3);
    else if (field == 'recur_week_of_month_interval') clearFields(4);
    else if (field == 'recur_yearly_interval') clearFields(5);
}

===========================
To $KRONOLITH/lib/Event.php:
===========================

In function "readForm()", within "switch ($recur)", edited the following case:
-----------------------------------------
    case KRONOLITH_RECUR_WEEKLY:
      $weekly = Horde::getFormData('weekly');
      if (is_array($weekly)) {
        $weekdays = 0;
        foreach ($weekly as $day) {
          $weekdays |= $day;
        }
        $this->setRecurInterval(Horde::getFormData('recur_weekly_interval', 1));

			   //  JL/DRHG:  Added clauses to set the day of the  //
				//  ..week even if it's not set on the form:  //
				//  We expected the "2" in the third line to  //
					      //  ..be a "4", but "2" works:  //
		     //  "perl -e 'printf "%d\n", ((4+(time()/86400)) % 7);'  //
						//  ..gives "1" on a Monday:  //
        if ($weekdays == 0) {
          $start_day_of_week = $this->getStartTimestamp(1);
          $start_day_of_week = (2 + ($start_day_of_week / 86400)) % 7;
          $weekdays = 1 << $start_day_of_week;
        }
        $this->setRecurOnDay($weekdays);
      }else{
        $start_day_of_week = $this->getStartTimestamp(1);
        $start_day_of_week = (2 + ($start_day_of_week / 86400)) % 7;
        $weekdays = 1 << $start_day_of_week;
        $this->setRecurOnDay($weekdays);
      }
      break;
-------------------------------

Some of this was rather trial and error, and no doubt better/more accurate
workarounds are possible.

We are running:

Horde 2.1;
Kronolith 1.0;
IMP 3.1;  Turba 1.1;  Mnemo 1.0;
PHP 4.2.1;
mysql ver 11.18 distrib 3-23-51
Apache 1.3;
Linux version 2.0.36 (root@porky.redhat.com).

I hope this is enough information to be of use.

Thank you for your attention.

With best regards,

Daniel Gordon and Jason Lander.
School of the Environment,
University of Leeds,
Leeds.
LS2 9JT.
United Kingdom.