Index: event.php =================================================================== RCS file: /cvsroot/moodle/moodle/calendar/event.php,v retrieving revision 1.57 diff -u -r1.57 event.php --- event.php 11 Oct 2006 05:24:33 -0000 1.57 +++ event.php 20 Oct 2006 11:46:22 -0000 @@ -42,9 +42,9 @@ require_once($CFG->dirroot.'/calendar/lib.php'); require_once($CFG->dirroot.'/course/lib.php'); require_once($CFG->dirroot.'/mod/forum/lib.php'); - + include('event_new_form.php'); require_login(); - + if(isguest()) { // Guests cannot do anything with events redirect(CALENDAR_URL.'view.php?view=upcoming'); @@ -70,13 +70,7 @@ $mon = intval($now['mon']); $yr = intval($now['year']); - if ($usehtmleditor = can_use_richtext_editor()) { - $defaultformat = FORMAT_HTML; - } else { - $defaultformat = FORMAT_MOODLE; - } - - // If a course has been supplied in the URL, change the filters to show that one + // If a course has been supplied in the URL, change the filters to show that one if($urlcourse > 0 && record_exists('course', 'id', $urlcourse)) { if($urlcourse == SITEID) { // If coming from the site page, show all courses @@ -179,43 +173,42 @@ break; case 'new': + // TO DO - TIMESTAMP VALUE IS NOT GETTING STORED IN DB AND THERE IS AN ERROR OF 'MANAGE CAPABILITIES' $title = get_string('newevent', 'calendar'); - $form = data_submitted(); - if(!empty($form) && $form->type == 'defined') { - - $form->name = clean_text(strip_tags($form->name, '')); - - $form->timestart = make_timestamp($form->startyr, $form->startmon, $form->startday, $form->starthr, $form->startmin); - if($form->duration == 1) { - $form->timeduration = make_timestamp($form->endyr, $form->endmon, $form->endday, $form->endhr, $form->endmin) - $form->timestart; - if($form->timeduration < 0) { + //$form = data_submitted(); + if ($form = data_submitted()){ + if(!empty($form) && $form->type == 'defined') { + if(empty($form->courseid)) { + $form->courseid=0; + } + $form->name = clean_text(strip_tags($form->name, '')); + $form->timestart = $form->startdate; + //make_timestamp($form->startyr, $form->startmon, $form->startday, $form->starthr, $form->startmin); + if($form->duration == 1) { + //$form->timeduration = make_timestamp($form->endyr, $form->endmon, $form->endday, $form->endhr, $form->endmin) - $form->timestart; + $form->timeduration = $form->duration; + if($form->timeduration < 0) { + $form->timeduration = 0; + } + } + else if ($form->duration == 2) { + $form->timeduration = $form->minutes * MINSECS; + } + else { $form->timeduration = 0; } - } - else if ($form->duration == 2) { - $form->timeduration = $form->minutes * MINSECS; - } - else { - $form->timeduration = 0; - } - if(!calendar_add_event_allowed($form->courseid, $form->groupid, $form->userid)) { - error('You are not authorized to do this'); - } - validate_form($form, $err); - if (count($err) == 0) { - $form->timemodified = time(); + if(!calendar_add_event_allowed($form->courseid, $form->groupid, $form->userid)) { + error('You are not authorized to do this'); + } + // if ($form->repeat) { $fetch = get_record_sql('SELECT 1, MAX(repeatid) AS repeatid FROM '.$CFG->prefix.'event'); $form->repeatid = empty($fetch) ? 1 : $fetch->repeatid + 1; } - - /// Get the event id for the log record. $eventid = insert_record('event', $form, true); - - /// Log the event entry. add_to_log($form->courseid, 'calendar', 'add', 'event.php?action=edit&id='.$eventid, stripslashes($form->name)); - + $form->timemodified = time(); if ($form->repeat) { for($i = 1; $i < $form->repeats; $i++) { // What's the DST offset for the previous repeat? @@ -233,23 +226,58 @@ add_to_log($form->courseid, 'calendar', 'add', 'event.php?action=edit&id='.$eventid, stripslashes($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); + + redirect(CALENDAR_URL.'view.php?view=day'); + } + /* validate_form($form, $err); + if (count($err) == 0) { + $form->timemodified = time(); + + if ($form->repeat) { + $fetch = get_record_sql('SELECT 1, MAX(repeatid) AS repeatid FROM '.$CFG->prefix.'event'); + $form->repeatid = empty($fetch) ? 1 : $fetch->repeatid + 1; + } + + /// Get the event id for the log record. + $eventid = insert_record('event', $form, true); + + /// Log the event entry. + add_to_log($form->courseid, 'calendar', 'add', 'event.php?action=edit&id='.$eventid, stripslashes($form->name)); + + if ($form->repeat) { + for($i = 1; $i < $form->repeats; $i++) { + // What's the DST offset for the previous repeat? + $dst_offset_prev = dst_offset_on($form->timestart); + + $form->timestart += WEEKSECS; + + // If the offset has changed in the meantime, update this repeat accordingly + $form->timestart += $dst_offset_prev - dst_offset_on($form->timestart); + + /// Get the event id for the log record. + $eventid = insert_record('event', $form, true); + + /// Log the event entry. + add_to_log($form->courseid, 'calendar', 'add', 'event.php?action=edit&id='.$eventid, stripslashes($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); } else { - foreach ($err as $key => $value) { - $focus = 'form.'.$key; - } + foreach ($err as $key => $value) { + $focus = 'form.'.$key; } + }*/ } - break; + break; } if(empty($focus)) $focus = ''; // Let's see if we are supposed to provide a referring course link // but NOT for the "main page" course if($SESSION->cal_course_referer != SITEID && - ($shortname = get_field('course', 'shortname', 'id', $SESSION->cal_course_referer)) !== false) { + ($shortname = get_field('course', 'shortname', 'id', $SESSION->cal_course_referer)) !== false) { // If we know about the referring course, show a return link $nav = ''.$shortname.' -> '.$nav; } @@ -262,7 +290,7 @@ } print_header($site->shortname.': '.$strcalendar.': '.$title, $strcalendar, $nav.' -> '.$title, - $focus, '', true, '', user_login_string($site)); + $focus, '', true, '', user_login_string($site)); echo calendar_overlib_html(); @@ -367,6 +395,7 @@ break; case 'new': + if($cal_y && $cal_m && $cal_d && checkdate($cal_m, $cal_d, $cal_y)) { $form->timestart = make_timestamp($cal_y, $cal_m, $cal_d, 0, 0, 0); } @@ -476,12 +505,12 @@ error('Unsupported event type'); } - $form->format = $defaultformat; + //$mform->format = $defaultformat; if(!empty($header)) { $header = ' ('.$header.')'; } - echo '
'.get_string('newevent', 'calendar').$header.'
'; + //echo '
'.get_string('newevent', 'calendar').$header.'
'; if($eventtype == 'select') { $courseid = optional_param('courseid', $SESSION->cal_course_referer, PARAM_INT); @@ -504,10 +533,10 @@ echo ''; } else { - include('event_new.html'); - if ($usehtmleditor) { - use_html_editor("description"); - } + + $mform = new calendar_event_form('event.php',compact('form')); + $mform->display(); + } break; @@ -546,7 +575,7 @@ function validate_form(&$form, &$err) { - $form->name = trim($form->name); + $form->name = trim($form->name); $form->description = trim($form->description); if(empty($form->name)) { @@ -555,9 +584,9 @@ if(empty($form->description)) { $err['description'] = get_string('errornodescription', 'calendar'); } - if(!checkdate($form->startmon, $form->startday, $form->startyr)) { - $err['timestart'] = get_string('errorinvaliddate', 'calendar'); - } + //if(!checkdate($form->startmon, $form->startday, $form->startyr)) { + // $err['timestart'] = get_string('errorinvaliddate', 'calendar'); + // } if($form->duration == 2 and !checkdate($form->endmon, $form->endday, $form->endyr)) { $err['timeduration'] = get_string('errorinvaliddate', 'calendar'); } @@ -589,7 +618,7 @@ $sitecontext = get_context_instance(CONTEXT_SYSTEM, SITEID); // if user has manageentries at site level, return true - if (has_capability('manageentries', $sitecontext)) { + if (has_capability('moodle/calendar:manageentries', $sitecontext)) { return true; }