Exemplo n.º 1
0
/* Output */
data_print_header($course, $cm, $data, 'presets');
switch ($action) {
    /***************** Deleting *****************/
    case 'confirmdelete':
        if (!confirm_sesskey()) {
            // GET request ok here
            error("Sesskey Invalid");
        }
        if ($userid > 0 and $userid == $USER->id || has_capability('mod/data:manageuserpresets', $context)) {
            //ok can delete
        } else {
            error("Invalid request");
        }
        $path = data_preset_path($course, $userid, $shortname);
        $strwarning = get_string('deletewarning', 'data') . '<br />' . data_preset_name($shortname, $path);
        $options = new object();
        $options->fullname = $userid . '/' . $shortname;
        $options->action = 'delete';
        $options->d = $data->id;
        $options->sesskey = sesskey();
        $optionsno = new object();
        $optionsno->d = $data->id;
        notice_yesno($strwarning, 'preset.php', 'preset.php', $options, $optionsno, 'post', 'get');
        print_footer($course);
        exit;
        break;
    case 'delete':
        if (!data_submitted() and !confirm_sesskey()) {
            error("Invalid request");
        }
Exemplo n.º 2
0
function data_get_available_presets($context)
{
    global $CFG, $USER;
    $presets = array();
    if ($dirs = get_list_of_plugins('mod/data/preset')) {
        foreach ($dirs as $dir) {
            $fulldir = $CFG->dirroot . '/mod/data/preset/' . $dir;
            if (is_directory_a_preset($fulldir)) {
                $preset = new object();
                $preset->path = $fulldir;
                $preset->userid = 0;
                $preset->shortname = $dir;
                $preset->name = data_preset_name($dir, $fulldir);
                if (file_exists($fulldir . '/screenshot.jpg')) {
                    $preset->screenshot = $CFG->wwwroot . '/mod/data/preset/' . $dir . '/screenshot.jpg';
                } else {
                    if (file_exists($fulldir . '/screenshot.png')) {
                        $preset->screenshot = $CFG->wwwroot . '/mod/data/preset/' . $dir . '/screenshot.png';
                    } else {
                        if (file_exists($fulldir . '/screenshot.gif')) {
                            $preset->screenshot = $CFG->wwwroot . '/mod/data/preset/' . $dir . '/screenshot.gif';
                        }
                    }
                }
                $presets[] = $preset;
            }
        }
    }
    if ($userids = get_list_of_plugins('data/preset', '', $CFG->dataroot)) {
        foreach ($userids as $userid) {
            $fulldir = $CFG->dataroot . '/data/preset/' . $userid;
            if ($userid == 0 || $USER->id == $userid || has_capability('mod/data:viewalluserpresets', $context)) {
                if ($dirs = get_list_of_plugins('data/preset/' . $userid, '', $CFG->dataroot)) {
                    foreach ($dirs as $dir) {
                        $fulldir = $CFG->dataroot . '/data/preset/' . $userid . '/' . $dir;
                        if (is_directory_a_preset($fulldir)) {
                            $preset = new object();
                            $preset->path = $fulldir;
                            $preset->userid = $userid;
                            $preset->shortname = $dir;
                            $preset->name = data_preset_name($dir, $fulldir);
                            if (file_exists($fulldir . '/screenshot.jpg')) {
                                $preset->screenshot = $CFG->wwwroot . '/mod/data/preset/' . $dir . '/screenshot.jpg';
                            } else {
                                if (file_exists($fulldir . '/screenshot.png')) {
                                    $preset->screenshot = $CFG->wwwroot . '/mod/data/preset/' . $dir . '/screenshot.png';
                                } else {
                                    if (file_exists($fulldir . '/screenshot.gif')) {
                                        $preset->screenshot = $CFG->wwwroot . '/mod/data/preset/' . $dir . '/screenshot.gif';
                                    }
                                }
                            }
                            $presets[] = $preset;
                        }
                    }
                }
            }
        }
    }
    return $presets;
}
Exemplo n.º 3
0
/**
 * Returns an array of all the available presets.
 *
 * @return array
 */
function data_get_available_presets($context) {
    global $CFG, $USER;

    $presets = array();

    // First load the ratings sub plugins that exist within the modules preset dir
    if ($dirs = get_list_of_plugins('mod/data/preset')) {
        foreach ($dirs as $dir) {
            $fulldir = $CFG->dirroot.'/mod/data/preset/'.$dir;
            if (is_directory_a_preset($fulldir)) {
                $preset = new stdClass();
                $preset->path = $fulldir;
                $preset->userid = 0;
                $preset->shortname = $dir;
                $preset->name = data_preset_name($dir, $fulldir);
                if (file_exists($fulldir.'/screenshot.jpg')) {
                    $preset->screenshot = $CFG->wwwroot.'/mod/data/preset/'.$dir.'/screenshot.jpg';
                } else if (file_exists($fulldir.'/screenshot.png')) {
                    $preset->screenshot = $CFG->wwwroot.'/mod/data/preset/'.$dir.'/screenshot.png';
                } else if (file_exists($fulldir.'/screenshot.gif')) {
                    $preset->screenshot = $CFG->wwwroot.'/mod/data/preset/'.$dir.'/screenshot.gif';
                }
                $presets[] = $preset;
            }
        }
    }
    // Now add to that the site presets that people have saved
    $presets = data_get_available_site_presets($context, $presets);
    return $presets;
}
Exemplo n.º 4
0
 function action_confirmdelete($params)
 {
     global $CFG, $USER;
     $html = '';
     $course = $params['course'];
     $shortname = $params['shortname'];
     if (!confirm_sesskey()) {
         // GET request ok here
         print_error('confirmsesskeybad');
     }
     $this->user_id = $params['userid'];
     if (!($cm = get_coursemodule_from_instance('data', $this->data->id, $course->id))) {
         print_error('invalidrequest');
     }
     $context = get_context_instance(COURSE_MODULE, $cm->id);
     if ($this->user_id > 0 and $this->user_id == $USER->id || has_capability('mod/data:manageuserpresets', $context)) {
         //ok can delete
     } else {
         print_error('invalidrequest');
     }
     $path = $this->get_path();
     $strwarning = get_string('deletewarning', 'data') . '<br />' . data_preset_name($shortname, $path);
     $options = new object();
     $options->fullname = $this->user_id . '/' . $shortname;
     $options->action = 'delete';
     $options->d = $this->data->id;
     $options->sesskey = sesskey();
     $optionsno = new object();
     $optionsno->d = $this->data->id;
     notice_yesno($strwarning, 'preset.php', 'preset.php', $options, $optionsno, 'post', 'get');
     $html .= print_footer($course, null, true);
     echo $html;
     exit;
 }