Skip to content

Commit

Permalink
Editing repeating events in one go works as well. Enjoy!
Browse files Browse the repository at this point in the history
  • Loading branch information
defacer committed Apr 21, 2005
1 parent 822c612 commit 98cd789
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 6 deletions.
47 changes: 42 additions & 5 deletions calendar/event.php
Expand Up @@ -102,6 +102,8 @@
case 'edit':
$title = get_string('editevent', 'calendar');
$event = get_record('event', 'id', $eventid);
$repeats = optional_param('repeats', 0, PARAM_INT);

if($event === false) {
error('Invalid event');
}
Expand All @@ -126,14 +128,41 @@
else {
$form->timeduration = 0;
}

validate_form($form, $err);

if (count($err) == 0) {
$form->timemodified = time();
update_record('event', $form);

/// Log the event update.
$form->name = stripslashes($form->name); //To avoid double-slashes
add_to_log($form->courseid, 'calendar', 'edit', 'event.php?action=edit&id='.$form->id, $form->name);
if($event->repeatid && $repeats) {
// Update all
if($form->timestart >= $event->timestart) {
$timestartoffset = 'timestart + '.($form->timestart - $event->timestart);
}
else {
$timestartoffset = 'timestart - '.($event->timestart - $form->timestart);
}

execute_sql('UPDATE '.$CFG->prefix.'event SET '.
'name = '.$db->qstr($form->name).','.
'description = '.$db->qstr($form->description).','.
'timestart = '.$timestartoffset.','.
'timeduration = '.$form->timeduration.','.
'timemodified = '.time().' WHERE repeatid = '.$event->repeatid);

/// Log the event update.
$form->name = stripslashes($form->name); //To avoid double-slashes
add_to_log($form->courseid, 'calendar', 'edit all', 'event.php?action=edit&id='.$form->id, $form->name);
}

else {
// Update this
$form->timemodified = time();
update_record('event', $form);

/// Log the event update.
$form->name = stripslashes($form->name); //To avoid double-slashes
add_to_log($form->courseid, 'calendar', 'edit', 'event.php?action=edit&id='.$form->id, $form->name);
}

// OK, now redirect to day view
redirect(CALENDAR_URL.'view.php?view=day&cal_d='.$form->startday.'&cal_m='.$form->startmon.'&cal_y='.$form->startyr);
Expand Down Expand Up @@ -307,6 +336,14 @@
$course = $site;
}

if($event->repeatid) {
$fetch = get_record_sql('SELECT 1, COUNT(id) AS repeatcount FROM '.$CFG->prefix.'event WHERE repeatid = '.$event->repeatid);
$repeatcount = $fetch->repeatcount;
}
else {
$repeatcount = 0;
}

echo '<div class="header">'.get_string('editevent', 'calendar').'</div>';
include('event_edit.html');
if ($usehtmleditor) {
Expand Down
23 changes: 22 additions & 1 deletion calendar/event_edit.html
@@ -1,5 +1,5 @@
<form method="post" action="event.php" name="edit">
<table cellpadding="5">
<table cellpadding="5" cellspacing="0">
<tr>
<td style="vertical-align: top; text-align: right;">
<?php print_string('eventname', 'calendar'); ?>:
Expand Down Expand Up @@ -58,6 +58,27 @@
</div>
</td>
</tr>
<?php if($repeatcount > 1) { ?>
<tr>
<td style="vertical-align: top; text-align: right;">
<?php print_string('eventrepeat', 'calendar'); ?>:
</td>
<td>
<div>
<input type="radio" name="repeats" value="1" id="edit_all" checked="checked" />
<label for="edit_all">
<?php print_string('repeateditall', 'calendar', $repeatcount); ?>
</label>
</div>
<div>
<input type="radio" name="repeats" value="0" id="edit_this" />
<label for="edit_this">
<?php print_string('repeateditthis', 'calendar'); ?>
</label>
</div>
</td>
</tr>
<?php } ?>
<tr>
<td align="center" colspan="2"><p><input type="submit" value="<?php print_string('savechanges') ?>" /></p></td>
</tr>
Expand Down
2 changes: 2 additions & 0 deletions lang/en/calendar.php
Expand Up @@ -55,6 +55,8 @@
$string['pref_timeformat'] = 'Time display format';
$string['preferences'] = 'Preferences';
$string['preferences_available'] = 'Your personal preferences';
$string['repeateditall'] = 'Apply changes to all $a events in this repeat series';
$string['repeateditthis'] = 'Apply changes to this event only';
$string['repeatnone'] = 'No repeats';
$string['repeatweeksl'] = 'Repeat weekly, creating altogether ';
$string['repeatweeksr'] = 'events';
Expand Down

0 comments on commit 98cd789

Please sign in to comment.