예제 #1
0
function elluminate_add_instance($elluminate, $facilitatorid = false)
{
    global $CFG;
    global $USER;
    global $COURSE;
    global $DB;
    if (!$facilitatorid) {
        $facilitatorid = $USER->id;
    }
    /// The start and end times don't make sense.
    if ($elluminate->timestart > $elluminate->timeend) {
        $a = new stdClass();
        $a->timestart = userdate($elluminate->timestart);
        $a->timeend = userdate($elluminate->timeend);
        redirect($CFG->wwwroot . '/course/mod.php?id=' . $elluminate->course . '&section=' . $elluminate->section . '&sesskey=' . $USER->sesskey . '&add=elluminate', get_string('invalidsessiontimes', 'elluminate', $a), 5);
    }
    if ($elluminate->timestart == $elluminate->timeend) {
        $a = new stdClass();
        $a->timestart = userdate($elluminate->timestart);
        $a->timeend = userdate($elluminate->timeend);
        redirect($CFG->wwwroot . '/course/mod.php?id=' . $elluminate->course . '&section=' . $elluminate->section . '&sesskey=' . $USER->sesskey . '&add=elluminate', get_string('samesessiontimes', 'elluminate', $a), 5);
    }
    $timenow = time();
    if ($elluminate->timestart < $timenow) {
        $a = new stdClass();
        $a->timestart = userdate($elluminate->timestart);
        $a->timeend = userdate($elluminate->timeend);
        redirect($CFG->wwwroot . '/course/mod.php?id=' . $elluminate->course . '&amp;section=' . $elluminate->section . '&amp;sesskey=' . $USER->sesskey . '&amp;add=elluminate', get_string('starttimebeforenow', 'elluminate', $a), 5);
    }
    $yearinseconds = 31536000;
    $timedif = $elluminate->timeend - $elluminate->timestart;
    if ($timedif > $yearinseconds) {
        $a = new stdClass();
        $a->timestart = userdate($elluminate->timestart);
        $a->timeend = userdate($elluminate->timeend);
        redirect($CFG->wwwroot . '/course/mod.php?id=' . $elluminate->course . '&amp;section=' . $elluminate->section . '&amp;sesskey=' . $USER->sesskey . '&amp;add=elluminate', get_string('meetinglessthanyear', 'elluminate', $a), 5);
    }
    $year_later = $timenow + $yearinseconds;
    if ($elluminate->timestart > $year_later) {
        $a = new stdClass();
        $a->timestart = userdate($elluminate->timestart);
        $a->timeend = userdate($elluminate->timeend);
        redirect($CFG->wwwroot . '/course/mod.php?id=' . $elluminate->course . '&amp;section=' . $elluminate->section . '&amp;sesskey=' . $USER->sesskey . '&amp;add=elluminate', get_string('meetingstartoverayear', 'elluminate', $a), 5);
    }
    if (empty($elluminate->sessionname)) {
        $elluminate->sessionname = $elluminate->name;
    }
    $originalname = $elluminate->sessionname;
    $search = array("<", "&", "\"", "#", "%");
    $replace = '';
    $strippedname = str_replace($search, $replace, $elluminate->sessionname);
    if (empty($strippedname)) {
        redirect($CFG->wwwroot . '/course/mod.php?id=' . $elluminate->course . '&amp;section=' . $elluminate->section . '&amp;sesskey=' . $USER->sesskey . '&amp;add=elluminate', get_string('meetingnameempty', 'elluminate'), 5);
    }
    if (empty($elluminate->creator)) {
        $elluminate->creator = $USER->id;
    }
    if (empty($elluminate->boundarytimedisplay)) {
        $elluminate->boundarytimedisplay = 0;
    }
    if (empty($elluminate->maxtalkers)) {
        $elluminate->maxtalkers = 1;
    }
    if ($elluminate->sessiontype == 0 || $elluminate->sessiontype == 1) {
        $elluminate->groupmode = 0;
        $elluminate->groupingid = 0;
    } else {
        if ($elluminate->sessiontype == 2) {
            $elluminate->groupingid = 0;
        } else {
            if ($elluminate->sessiontype == 3) {
                $elluminate->groupingid = $elluminate->grouping_id;
            }
        }
    }
    if ($COURSE->groupmodeforce > 0) {
        $elluminate->groupmode = $COURSE->groupmode;
    }
    $elluminate->timemodified = time();
    $elluminate->seats = 0;
    $elluminate->chairlist = $USER->id;
    $elluminate->sessionname = $strippedname;
    $elluminate->groupparentid = '0';
    $elluminate->meetinginit = 0;
    if (!($elluminate->id = $DB->insert_record('elluminate', $elluminate))) {
        return false;
    }
    $mod = new stdClass();
    $mod->course = $elluminate->course;
    $mod->module = $elluminate->module;
    $mod->instance = $elluminate->id;
    $mod->idnumber = null;
    $mod->added = time();
    $mod->score = 0;
    $mod->indent = 0;
    $mod->visible = 1;
    $mod->visibleold = 1;
    $mod->groupmode = $elluminate->groupmode;
    if ($elluminate->grouping_id == NULL) {
        $mod->groupingid = 0;
    } else {
        $mod->groupingid = $elluminate->grouping_id;
    }
    $mod->groupmembersonly = 0;
    $sql = "SELECT cs.* FROM {course_sections} cs WHERE cs.course = :course AND cs.section = :section";
    $sql_params = array('course' => $elluminate->course, 'section' => $elluminate->section);
    $course_sections = $DB->get_records_sql($sql, $sql_params);
    foreach ($course_sections as $course_section) {
        $mod->section = $course_section->id;
    }
    if (!($mod->id = add_course_module($mod))) {
        return false;
    }
    if ($elluminate->sessiontype == 0 || $elluminate->sessiontype == 1) {
        if ($elluminate->groupmode == 0) {
            $create_result = elluminate_create_meeting($elluminate->timestart, $elluminate->timeend, stripslashes($strippedname), '', '', $elluminate->sessiontype, $elluminate->seats, $elluminate->boundarytime, $elluminate->maxtalkers, $elluminate->recordingmode, $mod->id, $USER->id);
            $meetingid = $create_result->DefaultAdapterMeetingResponseShort->meetingId;
            if ($meetingid > 0) {
                $elluminate->meetingid = $meetingid;
                if (!empty($elluminate->meetingid)) {
                    $elluminate->meetinginit = 2;
                }
                $elluminate->chairlist = $create_result->DefaultAdapterMeetingResponseShort->chairList;
                $DB->update_record('elluminate', $elluminate);
            } else {
                elluminate_delete_instance($elluminate->id);
            }
        }
    }
    if (!empty($elluminate->meetingid)) {
        $elluminate->meetinginit = 2;
    }
    $parentsessionid = $elluminate->id;
    elluminate_grade_item_update($elluminate);
    if ($elluminate->sessiontype == 2 || $elluminate->sessiontype == 3) {
        if ($elluminate->groupmode != 0) {
            elluminate_insert_group_records($elluminate);
        } else {
            elluminate_update_events($elluminate);
        }
    } else {
        elluminate_update_events($elluminate);
    }
    $DB->delete_records('course_modules', array('id' => $mod->id));
    return $parentsessionid;
}
function elluminate_add_instance($elluminate, $facilitatorid = false)
{
    global $CFG;
    global $USER;
    global $COURSE;
    if (!$facilitatorid) {
        $facilitatorid = $USER->id;
    }
    /// The start and end times don't make sense.
    if ($elluminate->timestart > $elluminate->timeend) {
        $a = new stdClass();
        $a->timestart = userdate($elluminate->timestart);
        $a->timeend = userdate($elluminate->timeend);
        redirect($CFG->wwwroot . '/course/mod.php?id=' . $elluminate->course . '&amp;section=' . $elluminate->section . '&amp;sesskey=' . $USER->sesskey . '&amp;add=elluminate', get_string('invalidsessiontimes', 'elluminate', $a), 5);
    }
    if ($elluminate->timestart == $elluminate->timeend) {
        $a = new stdClass();
        $a->timestart = userdate($elluminate->timestart);
        $a->timeend = userdate($elluminate->timeend);
        redirect($CFG->wwwroot . '/course/mod.php?id=' . $elluminate->course . '&amp;section=' . $elluminate->section . '&amp;sesskey=' . $USER->sesskey . '&amp;add=elluminate', get_string('samesessiontimes', 'elluminate', $a), 5);
    }
    $timenow = time();
    if ($elluminate->timestart < $timenow) {
        $a = new stdClass();
        $a->timestart = userdate($elluminate->timestart);
        $a->timeend = userdate($elluminate->timeend);
        redirect($CFG->wwwroot . '/course/mod.php?id=' . $elluminate->course . '&amp;section=' . $elluminate->section . '&amp;sesskey=' . $USER->sesskey . '&amp;add=elluminate', get_string('starttimebeforenow', 'elluminate', $a), 5);
    }
    $yearinseconds = 31536000;
    $timedif = $elluminate->timeend - $elluminate->timestart;
    if ($timedif > $yearinseconds) {
        $a = new stdClass();
        $a->timestart = userdate($elluminate->timestart);
        $a->timeend = userdate($elluminate->timeend);
        redirect($CFG->wwwroot . '/course/mod.php?id=' . $elluminate->course . '&amp;section=' . $elluminate->section . '&amp;sesskey=' . $USER->sesskey . '&amp;add=elluminate', get_string('meetinglessthanyear', 'elluminate', $a), 5);
    }
    $year_later = $timenow + $yearinseconds;
    if ($elluminate->timestart > $year_later) {
        $a = new stdClass();
        $a->timestart = userdate($elluminate->timestart);
        $a->timeend = userdate($elluminate->timeend);
        redirect($CFG->wwwroot . '/course/mod.php?id=' . $elluminate->course . '&amp;section=' . $elluminate->section . '&amp;sesskey=' . $USER->sesskey . '&amp;add=elluminate', get_string('meetingstartoverayear', 'elluminate', $a), 5);
    }
    if (empty($elluminate->sessionname)) {
        $elluminate->sessionname = $elluminate->name;
    }
    $originalname = $elluminate->sessionname;
    $search = array("<", ">", "&", "#", "%", "\"", "\\", "|");
    $replace = '';
    $strippedname = str_replace($search, $replace, $elluminate->sessionname);
    $databasesafe = array("'");
    $replacedb = '\\\'';
    $strippedname = str_replace($databasesafe, $replacedb, $strippedname);
    $elluminate->description = str_replace($databasesafe, $replacedb, $elluminate->description);
    if (empty($strippedname)) {
        redirect($CFG->wwwroot . '/course/mod.php?id=' . $elluminate->course . '&amp;section=' . $elluminate->section . '&amp;sesskey=' . $USER->sesskey . '&amp;add=elluminate', get_string('meetingnameempty', 'elluminate'), 5);
    } else {
        if (!ctype_alnum(substr($strippedname, 0, 1))) {
            redirect($CFG->wwwroot . '/course/mod.php?id=' . $elluminate->course . '&amp;section=' . $elluminate->section . '&amp;sesskey=' . $USER->sesskey . '&amp;add=elluminate', get_string('meetingnamemustbeginwithalphanumeric', 'elluminate'), 5);
        }
    }
    if (empty($elluminate->creator)) {
        $elluminate->creator = $USER->id;
    }
    if (empty($elluminate->boundarytimedisplay)) {
        $elluminate->boundarytimedisplay = 0;
    }
    if ($elluminate->sessiontype == 0 || $elluminate->sessiontype == 1) {
        $elluminate->groupmode = 0;
        $elluminate->groupingid = 0;
    } else {
        if ($elluminate->sessiontype == 2) {
            $elluminate->groupingid = 0;
        }
    }
    if ($COURSE->groupmodeforce > 0) {
        $elluminate->groupmode = $COURSE->groupmode;
    }
    $elluminate->timemodified = time();
    $elluminate->seats = 0;
    $elluminate->chairlist = $USER->id;
    $elluminate->sessionname = $strippedname;
    $elluminate->groupparentid = '0';
    $elluminate->meetinginit = 0;
    $elluminate->name = htmlentities($elluminate->name);
    if (!($elluminate->id = insert_record('elluminate', $elluminate))) {
        return false;
    }
    $mod = new stdClass();
    $mod->course = $elluminate->course;
    $mod->module = $elluminate->module;
    $mod->instance = $elluminate->id;
    $mod->idnumber = null;
    $mod->added = time();
    $mod->score = 0;
    $mod->indent = 0;
    $mod->visible = 1;
    $mod->visibleold = 1;
    $mod->groupmode = $elluminate->groupmode;
    $mod->groupingid = $elluminate->groupingid;
    $mod->groupmembersonly = 0;
    $sql = "SELECT cs.* FROM {$CFG->prefix}course_sections cs" . " WHERE cs.course = {$elluminate->course} AND cs.section = {$elluminate->section}";
    $course_sections = get_records_sql($sql);
    foreach ($course_sections as $course_section) {
        $mod->section = $course_section->id;
    }
    if (!($mod->id = add_course_module($mod))) {
        return false;
    }
    if ($elluminate->sessiontype == 0 || $elluminate->sessiontype == 1) {
        if ($elluminate->groupmode == 0) {
            $create_result = elluminate_create_meeting($elluminate->timestart, $elluminate->timeend, stripslashes($strippedname), '', '', $elluminate->sessiontype, $elluminate->seats, $elluminate->boundarytime, $elluminate->recordingmode, $mod->id);
            $meetingid = $create_result->DefaultAdapterMeetingResponseShort->meetingId;
            if ($meetingid > 0) {
                $elluminate->meetingid = $meetingid;
                if (!empty($elluminate->meetingid)) {
                    $elluminate->meetinginit = 2;
                }
                $elluminate->chairlist = $create_result->DefaultAdapterMeetingResponseShort->chairList;
                update_record('elluminate', $elluminate);
            } else {
                elluminate_delete_instance($elluminate->id);
                error('An error occured while attempting to initialize your session.<br><br> A likely cause is your Moodle server time and the Elluminate scheduling server time is out of sync.<br><br>Please try again in a few minutes.');
            }
        }
    }
    if (!empty($elluminate->meetingid)) {
        $elluminate->meetinginit = 2;
    }
    $parentsessionid = $elluminate->id;
    elluminate_grade_item_update($elluminate);
    if ($elluminate->sessiontype == 2 || $elluminate->sessiontype == 3) {
        if ($elluminate->groupmode != 0) {
            elluminate_insert_group_records($elluminate);
        }
    }
    delete_records('course_modules', 'id', $mod->id);
    return $parentsessionid;
}