예제 #1
0
     $mform = new mod_attforblock_add_form($url, $formparams);
     if ($formdata = $mform->get_data()) {
         $sessions = construct_sessions_data_for_add($formdata);
         $att->add_sessions($sessions);
         redirect($url, get_string('sessionsgenerated', 'attforblock'));
     }
     break;
 case att_sessions_page_params::ACTION_UPDATE:
     $sessionid = required_param('sessionid', PARAM_INT);
     $url = $att->url_sessions(array('action' => att_sessions_page_params::ACTION_UPDATE, 'sessionid' => $sessionid));
     $formparams['sessionid'] = $sessionid;
     $mform = new mod_attforblock_update_form($url, $formparams);
     if ($mform->is_cancelled()) {
         redirect($att->url_manage());
     }
     if ($formdata = $mform->get_data()) {
         $att->update_session_from_form_data($formdata, $sessionid);
         redirect($att->url_manage(), get_string('sessionupdated', 'attforblock'));
     }
     break;
 case att_sessions_page_params::ACTION_DELETE:
     $sessionid = required_param('sessionid', PARAM_INT);
     $confirm = optional_param('confirm', NULL, PARAM_INT);
     if (isset($confirm)) {
         $att->delete_sessions(array($sessionid));
         att_update_all_users_grades($att->id, $att->course, $att->context);
         redirect($att->url_manage(), get_string('sessiondeleted', 'attforblock'));
     }
     $sessinfo = $att->get_session_info($sessionid);
     $message = get_string('deletecheckfull', '', get_string('session', 'attforblock'));
     $message .= str_repeat(html_writer::empty_tag('br'), 2);
                error(get_string('errorinaddingsession', 'attforblock'), "sessions.php?id={$id}&action=add");
            }
        }
    }
    $mform_add->display();
}
//////////////////////////////////////////////////////////
// Updating sessions
//////////////////////////////////////////////////////////
if ($action === 'update') {
    $sessionid = required_param('sessionid');
    $mform_update = new mod_attforblock_update_form('sessions.php', array('course' => $course, 'cm' => $cm, 'modcontext' => $context, 'sessionid' => $sessionid));
    if ($mform_update->is_cancelled()) {
        redirect('manage.php?id=' . $id);
    }
    if ($fromform = $mform_update->get_data()) {
        if (!($att = get_record('attendance_sessions', 'id', $sessionid))) {
            error('No such session in this course');
        }
        //update session
        $att->sessdate = $fromform->sessiondate;
        $att->duration = $fromform->durtime['hours'] * HOURSECS + $fromform->durtime['minutes'] * MINSECS;
        $startdate = $fromform->sessiondate;
        $duration = $fromform->durtime['hours'] * HOURSECS + $fromform->durtime['minutes'] * MINSECS;
        $att->sessionend = $startdate + $duration;
        $att->description = $fromform->sdescription;
        // check for new session title in text box and choose whether to use from dropdown or text box
        if ($fromform->hsessiontitle > '') {
            $att->sessiontitle = $fromform->hsessiontitle;
            $newsessiontitle->sessiontitle = $fromform->hsessiontitle;
            $addsessiontitle = insert_record('attendance_sessiontitles', $newsessiontitle);