Esempio n. 1
0
function respondusws_get_extra_capabilities()
{
    global $CFG;
    $caps = array("mod/quiz:view", "mod/quiz:preview", "mod/quiz:manage", "moodle/site:viewfullnames", "moodle/course:activityvisibility", "moodle/course:viewhiddencourses", "moodle/course:viewhiddenactivities", "moodle/course:viewhiddensections", "moodle/course:update", "moodle/course:manageactivities", "moodle/course:managefiles", "moodle/question:managecategory", "moodle/question:add", "moodle/question:editmine", "moodle/question:editall", "moodle/question:viewmine", "moodle/question:viewall", "moodle/question:usemine", "moodle/question:useall", "moodle/question:movemine", "moodle/question:moveall");
    if (respondusws_floatcompare($CFG->version, 2012062501.07, 2) >= 0) {
        $caps[] = "mod/quiz:addinstance";
    }
    return $caps;
}
Esempio n. 2
0
if ($respondusws_usesections) {
    $respondusws_table->head = array($respondusws_strsectionname, $respondusws_strname, $strintro);
    $respondusws_table->align = array("center", "left", "left");
} else {
    $respondusws_table->head = array($respondusws_strlastmodified, $respondusws_strname, $strintro);
    $respondusws_table->align = array("left", "left", "left");
}
$respondusws_modinfo = get_fast_modinfo($respondusws_course);
$respondusws_currentsection = "";
foreach ($respondusws_modules as $respondusws_module) {
    $respondusws_cm = $respondusws_modinfo->cms[$respondusws_module->coursemodule];
    if ($respondusws_usesections) {
        $respondusws_printsection = "";
        if ($respondusws_module->section !== $respondusws_currentsection) {
            if ($respondusws_module->section) {
                if (respondusws_floatcompare($CFG->version, 2012120300, 2) >= 0) {
                    $respondusws_printsection = get_section_name($respondusws_course, $respondusws_module->section);
                } else {
                    $respondusws_printsection = get_section_name($respondusws_course, $respondusws_sections[$respondusws_module->section]);
                }
            }
            if ($respondusws_currentsection !== "") {
                $respondusws_table->data[] = "hr";
            }
            $respondusws_currentsection = $respondusws_module->section;
        }
    } else {
        $respondusws_printsection = "<span class=\"smallinfo\">" . userdate($respondusws_module->timemodified) . "</span>";
    }
    $respondusws_class = "";
    if (!$respondusws_module->visible) {
function RWSADFile()
{
    global $CFG;
    global $RWSUID;
    global $RWSEDBG;
    global $RWSDBGL;
    RWSCMAuth();
    RWSCRAuth();
    RWSCMUSvc();
    RWSCMMaint();
    $r_pm = RWSGSOpt("courseid", PARAM_ALPHANUM);
    if ($r_pm === false || strlen($r_pm) == 0) {
        RWSSErr("2057");
    }
    if (strcasecmp($r_pm, "site") == 0) {
        $r_cid = SITEID;
    } else {
        $r_cid = intval($r_pm);
    }
    if (!$RWSEDBG) {
        $r_crs = RWSCMUCourse($r_cid);
    }
    $r_fmt = RWSGSOpt("format", PARAM_ALPHANUMEXT);
    if (strcasecmp($r_fmt, "base64") == 0) {
        $r_w64 = true;
    } else {
        if (strcasecmp($r_fmt, "binary") == 0) {
            $r_w64 = false;
        } else {
            RWSSErr("2051");
        }
    }
    $r_fr = RWSGSOpt("fileref", PARAM_RAW);
    if ($r_fr === false || strlen($r_fr) == 0) {
        RWSSErr("2099");
    }
    $r_st = stripos($r_fr, "/pluginfile.php");
    if ($r_st !== false) {
        $r_st = strpos($r_fr, "/", $r_st + 1);
        if ($r_st === false) {
            RWSSErr("2100");
        }
        $r_pth = substr($r_fr, $r_st);
        $r_pts = explode("/", ltrim($r_pth, '/'));
        if (count($r_pts) < 5) {
            RWSSErr("2100");
        }
        $r_ctxi = intval(array_shift($r_pts));
        if (respondusws_floatcompare($CFG->version, 2011120500.0, 2) >= 0) {
            $r_cmp = clean_param(array_shift($r_pts), PARAM_COMPONENT);
            $r_far = clean_param(array_shift($r_pts), PARAM_AREA);
        } else {
            $r_cmp = clean_param(array_shift($r_pts), PARAM_SAFEDIR);
            $r_far = clean_param(array_shift($r_pts), PARAM_SAFEDIR);
        }
        $r_iti = intval(array_shift($r_pts));
        $r_fna = clean_filename(array_pop($r_pts));
        $r_fpt = "/";
        if (count($r_pts) > 0) {
            $r_fpt = "/" . implode("/", $r_pts) . "/";
        }
        try {
            $r_fs = get_file_storage();
            $r_fex = $r_fs->file_exists($r_ctxi, $r_cmp, $r_far, $r_iti, $r_fpt, $r_fna);
            if (!$r_fex) {
                RWSSErr("2100");
            }
            $r_fl = $r_fs->get_file($r_ctxi, $r_cmp, $r_far, $r_iti, $r_fpt, $r_fna);
            if ($r_fl === false) {
                RWSSErr("2101");
            }
            $r_fdat = $r_fl->get_content();
            $r_fn = $r_fna;
        } catch (Exception $r_e) {
            RWSSErr("2101");
        }
    } else {
        if ($RWSEDBG && $r_cid == SITEID && strcmp($r_fr, $RWSDBGL) == 0) {
            $r_pth = RWSGTPath();
            $r_fn = $r_fr;
            $r_fdat = file_get_contents("{$r_pth}/{$r_fn}");
            if ($r_fdat === false) {
                RWSSErr("2101");
            }
        } else {
            $r_st = stripos($r_fr, "/draftfile.php");
            if ($r_st !== false) {
                $r_st = strpos($r_fr, "/", $r_st + 1);
                if ($r_st === false) {
                    RWSSErr("2100");
                }
                $r_pth = substr($r_fr, $r_st);
                $r_pts = explode("/", ltrim($r_pth, '/'));
                if (count($r_pts) < 5) {
                    RWSSErr("2100");
                }
                $r_ctxi = intval(array_shift($r_pts));
                if (respondusws_floatcompare($CFG->version, 2013111800, 2) >= 0) {
                    $r_ctx = context::instance_by_id($r_ctxi);
                } else {
                    $r_ctx = get_context_instance_by_id($r_ctxi);
                }
                if ($r_ctx->contextlevel != CONTEXT_USER) {
                    RWSSErr("2100");
                }
                $r_cmp = array_shift($r_pts);
                if ($r_cmp !== "user") {
                    RWSSErr("2100");
                }
                $r_far = array_shift($r_pts);
                if ($r_far !== "draft") {
                    RWSSErr("2100");
                }
                $r_drf = intval(array_shift($r_pts));
                $r_rlp = implode("/", $r_pts);
                $r_fna = array_pop($r_pts);
                $r_fph = "/{$r_ctxi}/user/draft/{$r_drf}/{$r_rlp}";
                try {
                    $r_fs = get_file_storage();
                    $r_fl = $r_fs->get_file_by_hash(sha1($r_fph));
                    if ($r_fl === false) {
                        RWSSErr("2101");
                    }
                    if ($r_fl->get_filename() == ".") {
                        RWSSErr("2101");
                    }
                    $r_fdat = $r_fl->get_content();
                    $r_fn = $r_fna;
                } catch (Exception $r_e) {
                    RWSSErr("2101");
                }
            } else {
                $r_st = stripos($r_fr, "/file.php");
                if ($r_st !== false) {
                    $r_st = strpos($r_fr, "/", $r_st + 1);
                    if ($r_st === false) {
                        RWSSErr("2100");
                    }
                    $r_pth = substr($r_fr, $r_st);
                    $r_pts = explode("/", ltrim($r_pth, '/'));
                    if (count($r_pts) < 1) {
                        RWSSErr("2100");
                    }
                    if ($r_crs->legacyfiles != 2) {
                        RWSSErr("2113");
                    }
                    $r_ci = intval(array_shift($r_pts));
                    if ($r_ci != $r_cid) {
                        RWSSErr("2100");
                    }
                    if (respondusws_floatcompare($CFG->version, 2013111800, 2) >= 0) {
                        $r_ctx = context_course::instance($r_cid);
                    } else {
                        $r_ctx = get_context_instance(CONTEXT_COURSE, $r_cid);
                    }
                    $r_ctxi = $r_ctx->id;
                    $r_rlp = implode("/", $r_pts);
                    $r_fna = array_pop($r_pts);
                    $r_fph = "/{$r_ctxi}/course/legacy/0/{$r_rlp}";
                    try {
                        $r_fs = get_file_storage();
                        $r_fl = $r_fs->get_file_by_hash(sha1($r_fph));
                        if ($r_fl === false) {
                            RWSSErr("2101");
                        }
                        $r_fdat = $r_fl->get_content();
                        $r_fn = $r_fna;
                    } catch (Exception $r_e) {
                        RWSSErr("2101");
                    }
                } else {
                    RWSSErr("2100");
                }
            }
        }
    }
    if ($r_w64) {
        RWSRHXml();
        echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n";
        echo "<dnloadfile>\r\n";
        echo "\t<filename>";
        echo utf8_encode(htmlspecialchars(trim($r_fn)));
        echo "</filename>\r\n";
        $r_ed = base64_encode($r_fdat);
        echo "\t<filedata>";
        echo utf8_encode(htmlspecialchars(trim($r_ed)));
        echo "</filedata>\r\n";
        echo "</dnloadfile>\r\n";
    } else {
        RWSRHBin($r_fn, strlen($r_fdat));
        echo $r_fdat;
    }
    exit;
}
Esempio n. 4
0
function respondusws_install()
{
    global $DB;
    global $CFG;
    $dbman = $DB->get_manager();
    if (!isset($CFG->respondusws_initialdisable)) {
        if (!$dbman->table_exists("respondusws") || $DB->count_records("respondusws") == 0) {
            $DB->set_field("modules", "visible", 0, array("name" => "respondusws"));
            set_config("respondusws_initialdisable", 1);
        }
    }
    $module = $DB->get_record("modules", array("name" => "respondusws"));
    if ($module === false) {
        throw new moodle_exception("installmodulerecord", "respondusws");
    }
    $instance = new stdClass();
    $instance->course = SITEID;
    $instance->name = get_string("sharedname", "respondusws");
    $instance->intro = get_string("sharedintro", "respondusws");
    $instance->introformat = FORMAT_HTML;
    $instance->modulename = $module->name;
    $instance->module = $module->id;
    $instance->section = 0;
    $instance->coursemodule = "";
    $instance->instance = "";
    $instance->cmidnumber = "";
    $instance->groupmode = 0;
    $instance->groupingid = 0;
    $instance->groupmembersonly = 0;
    $instance->visible = false;
    $instance_id = respondusws_add_instance($instance);
    if (is_string($instance_id)) {
        $a = (object) array("detail" => $instance_id);
        throw new moodle_exception("installaddinstancedetail", "respondusws", "", $a);
    } else {
        if ($instance_id === false) {
            throw new moodle_exception("installaddinstance", "respondusws");
        }
    }
    $instance->instance = $instance_id;
    $cmid = add_course_module($instance);
    if (!$cmid) {
        throw new moodle_exception("installcoursemodule", "respondusws");
    }
    $instance->coursemodule = $cmid;
    if (respondusws_floatcompare($CFG->version, 2012120300, 2) >= 0) {
        $section = $DB->get_record("course_sections", array("course" => $instance->course, "section" => $instance->section));
        if ($section === false) {
            $section = new stdClass();
            $section->course = $instance->course;
            $section->section = $instance->section;
            $section->summary = "";
            $section->summaryformat = FORMAT_HTML;
            $section->sequence = "";
            $section->id = $DB->insert_record("course_sections", $section);
        }
        if (empty($section->sequence)) {
            $newsequence = "{$instance->coursemodule}";
        } else {
            $newsequence = "{$section->sequence},{$instance->coursemodule}";
        }
        $DB->set_field("course_sections", "sequence", $newsequence, array("id" => $section->id));
        $section_id = $section->id;
    } else {
        $section_id = add_mod_to_section($instance);
    }
    if (!$section_id) {
        throw new moodle_exception("installmodsection", "respondusws");
    }
    $DB->set_field("course_modules", "section", $section_id, array("id" => $cmid));
    set_coursemodule_visible($cmid, $instance->visible);
    set_coursemodule_idnumber($cmid, $instance->cmidnumber);
    rebuild_course_cache(SITEID, true);
}