Ejemplo n.º 1
0
 protected function specific_definition($mform)
 {
     global $CFG;
     // Fields for editing HTML block title and contents.
     $mform->addElement('header', 'configheader', get_string('blocksettings', 'block'));
     $mform->addElement('text', 'config_title', get_string('configtitle', 'block_tags'));
     $mform->setType('config_title', PARAM_TEXT);
     $mform->setDefault('config_title', get_string('pluginname', 'block_tags'));
     $this->add_collection_selector($mform);
     $numberoftags = array();
     for ($i = 1; $i <= 200; $i++) {
         $numberoftags[$i] = $i;
     }
     $mform->addElement('select', 'config_numberoftags', get_string('numberoftags', 'blog'), $numberoftags);
     $mform->setDefault('config_numberoftags', 80);
     $defaults = array('official' => get_string('officialonly', 'block_tags'), '' => get_string('anytype', 'block_tags'));
     $mform->addElement('select', 'config_tagtype', get_string('defaultdisplay', 'block_tags'), $defaults);
     $mform->setDefault('config_tagtype', '');
     $defaults = array(0 => context_system::instance()->get_context_name());
     $parentcontext = context::instance_by_id($this->block->instance->parentcontextid);
     if ($parentcontext->contextlevel > CONTEXT_COURSE) {
         $coursecontext = $parentcontext->get_course_context();
         $defaults[$coursecontext->id] = $coursecontext->get_context_name();
     }
     if ($parentcontext->contextlevel != CONTEXT_SYSTEM) {
         $defaults[$parentcontext->id] = $parentcontext->get_context_name();
     }
     $mform->addElement('select', 'config_ctx', get_string('taggeditemscontext', 'block_tags'), $defaults);
     $mform->addHelpButton('config_ctx', 'taggeditemscontext', 'block_tags');
     $mform->setDefault('config_ctx', 0);
     $mform->addElement('advcheckbox', 'config_rec', get_string('recursivecontext', 'block_tags'));
     $mform->addHelpButton('config_rec', 'recursivecontext', 'block_tags');
     $mform->setDefault('config_rec', 1);
 }
Ejemplo n.º 2
0
 function definition()
 {
     global $CFG, $DB;
     $mform = $this->_form;
     list($instance, $plugin, $course) = $this->_customdata;
     $coursecontext = context_course::instance($course->id);
     $enrol = enrol_get_plugin('cohort');
     $groups = array(0 => get_string('none'));
     foreach (groups_get_all_groups($course->id) as $group) {
         $groups[$group->id] = format_string($group->name, true, array('context' => $coursecontext));
     }
     $mform->addElement('header', 'general', get_string('pluginname', 'enrol_cohort'));
     $mform->addElement('text', 'name', get_string('custominstancename', 'enrol'));
     $mform->setType('name', PARAM_TEXT);
     $options = array(ENROL_INSTANCE_ENABLED => get_string('yes'), ENROL_INSTANCE_DISABLED => get_string('no'));
     $mform->addElement('select', 'status', get_string('status', 'enrol_cohort'), $options);
     if ($instance->id) {
         if ($cohort = $DB->get_record('cohort', array('id' => $instance->customint1))) {
             $cohorts = array($instance->customint1 => format_string($cohort->name, true, array('context' => context::instance_by_id($cohort->contextid))));
         } else {
             $cohorts = array($instance->customint1 => get_string('error'));
         }
         $mform->addElement('select', 'customint1', get_string('cohort', 'cohort'), $cohorts);
         $mform->setConstant('customint1', $instance->customint1);
         $mform->hardFreeze('customint1', $instance->customint1);
     } else {
         $cohorts = array('' => get_string('choosedots'));
         $allcohorts = cohort_get_available_cohorts($coursecontext, 0, 0, 0);
         foreach ($allcohorts as $c) {
             $cohorts[$c->id] = format_string($c->name);
         }
         $mform->addElement('select', 'customint1', get_string('cohort', 'cohort'), $cohorts);
         $mform->addRule('customint1', get_string('required'), 'required', null, 'client');
     }
     $roles = get_assignable_roles($coursecontext);
     $roles[0] = get_string('none');
     $roles = array_reverse($roles, true);
     // Descending default sortorder.
     $mform->addElement('select', 'roleid', get_string('assignrole', 'enrol_cohort'), $roles);
     $mform->setDefault('roleid', $enrol->get_config('roleid'));
     if ($instance->id and !isset($roles[$instance->roleid])) {
         if ($role = $DB->get_record('role', array('id' => $instance->roleid))) {
             $roles = role_fix_names($roles, $coursecontext, ROLENAME_ALIAS, true);
             $roles[$instance->roleid] = role_get_name($role, $coursecontext);
         } else {
             $roles[$instance->roleid] = get_string('error');
         }
     }
     $mform->addElement('select', 'customint2', get_string('addgroup', 'enrol_cohort'), $groups);
     $mform->addElement('hidden', 'courseid', null);
     $mform->setType('courseid', PARAM_INT);
     $mform->addElement('hidden', 'id', null);
     $mform->setType('id', PARAM_INT);
     if ($instance->id) {
         $this->add_action_buttons(true);
     } else {
         $this->add_action_buttons(true, get_string('addinstance', 'enrol'));
     }
     $this->set_data($instance);
 }
Ejemplo n.º 3
0
    public function __construct($repositoryid, $context = SYSCONTEXTID, $options = array()) {
        global $SESSION, $CFG, $DB, $PAGE;
        if (!is_numeric($repositoryid)) {
            // ELIS-8550: were constructing these with repositoryid = 'elisfiles'
            $sql = 'SELECT MIN(ri.id)
                      FROM {repository} r
                      JOIN {repository_instances} ri
                        ON r.id = ri.typeid
                     WHERE r.type = ?';
            $repositoryid = $DB->get_field_sql($sql, array($repositoryid));
        }
        parent::__construct($repositoryid, $context, $options);

        require_once dirname(__FILE__). '/ELIS_files_factory.class.php';

        if (is_object($context)) {
            $this->context = $context;
        } else {
            $this->context = context::instance_by_id($context);
        }

        /// ELIS files class
        $this->elis_files = repository_factory::factory();
        $this->config = get_config('elisfiles');
        $this->current_node = null;

        // jQuery files required for file picker - just for this repository
        $PAGE->requires->js('/repository/elisfiles/js/jquery-1.6.2.min.js');
        $PAGE->requires->js('/repository/elisfiles/js/jquery-ui-1.8.16.custom.min.js');
        $PAGE->requires->js('/repository/elisfiles/js/fileuploader.js');
        $PAGE->requires->js('/repository/elisfiles/lib/HTML_TreeMenu-1.2.0/TreeMenu.js', true);
    }
Ejemplo n.º 4
0
/**
 * Form for editing HTML block instances.
 *
 * @copyright 2010 Petr Skoda (http://skodak.org)
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 * @package   block_html
 * @category  files
 * @param stdClass $course course object
 * @param stdClass $birecord_or_cm block instance record
 * @param stdClass $context context object
 * @param string $filearea file area
 * @param array $args extra arguments
 * @param bool $forcedownload whether or not force download
 * @param array $options additional options affecting the file serving
 * @return bool
 */
function block_html_pluginfile($course, $birecord_or_cm, $context, $filearea, $args, $forcedownload, array $options = array())
{
    global $SCRIPT;
    if ($context->contextlevel != CONTEXT_BLOCK) {
        send_file_not_found();
    }
    require_course_login($course);
    if ($filearea !== 'content') {
        send_file_not_found();
    }
    $fs = get_file_storage();
    $filename = array_pop($args);
    $filepath = $args ? '/' . implode('/', $args) . '/' : '/';
    if (!($file = $fs->get_file($context->id, 'block_html', 'content', 0, $filepath, $filename)) or $file->is_directory()) {
        send_file_not_found();
    }
    if ($parentcontext = context::instance_by_id($birecord_or_cm->parentcontextid, IGNORE_MISSING)) {
        if ($parentcontext->contextlevel == CONTEXT_USER) {
            // force download on all personal pages including /my/
            //because we do not have reliable way to find out from where this is used
            $forcedownload = true;
        }
    } else {
        // weird, there should be parent context, better force dowload then
        $forcedownload = true;
    }
    session_get_instance()->write_close();
    send_stored_file($file, 60 * 60, 0, $forcedownload, $options);
}
 function definition()
 {
     global $CFG, $DB;
     $mform = $this->_form;
     $course = $this->_customdata;
     $coursecontext = context_course::instance($course->id);
     $enrol = enrol_get_plugin('cohort');
     $cohorts = array('' => get_string('choosedots'));
     list($sqlparents, $params) = $DB->get_in_or_equal(get_parent_contexts($coursecontext));
     $sql = "SELECT id, name, contextid\n                  FROM {cohort}\n                 WHERE contextid {$sqlparents}\n              ORDER BY name ASC";
     $rs = $DB->get_recordset_sql($sql, $params);
     foreach ($rs as $c) {
         $context = context::instance_by_id($c->contextid);
         if (!has_capability('moodle/cohort:view', $context)) {
             continue;
         }
         $cohorts[$c->id] = format_string($c->name);
     }
     $rs->close();
     $roles = get_assignable_roles($coursecontext);
     $roles[0] = get_string('none');
     $roles = array_reverse($roles, true);
     // descending default sortorder
     $mform->addElement('header', 'general', get_string('pluginname', 'enrol_cohort'));
     $mform->addElement('select', 'cohortid', get_string('cohort', 'cohort'), $cohorts);
     $mform->addRule('cohortid', get_string('required'), 'required', null, 'client');
     $mform->addElement('select', 'roleid', get_string('role'), $roles);
     $mform->addRule('roleid', get_string('required'), 'required', null, 'client');
     $mform->setDefault('roleid', $enrol->get_config('roleid'));
     $mform->addElement('hidden', 'id', null);
     $mform->setType('id', PARAM_INT);
     $this->add_action_buttons(true, get_string('addinstance', 'enrol'));
     $this->set_data(array('id' => $course->id));
 }
 /**
  * Add question-type specific form fields.
  *
  * @param MoodleQuickForm $mform the form being built.
  */
 public function __construct($submiturl, $question, $regenerate)
 {
     global $SESSION, $CFG, $DB;
     $this->regenerate = $regenerate;
     $this->question = $question;
     $this->qtypeobj = question_bank::get_qtype($this->question->qtype);
     // Validate the question category.
     if (!($category = $DB->get_record('question_categories', array('id' => $question->category)))) {
         print_error('categorydoesnotexist', 'question', $returnurl);
     }
     $this->category = $category;
     $this->categorycontext = context::instance_by_id($category->contextid);
     // Get the dataset defintions for this question.
     if (empty($question->id)) {
         $this->datasetdefs = $this->qtypeobj->get_dataset_definitions($question->id, $SESSION->calculated->definitionform->dataset);
     } else {
         if (empty($question->options)) {
             $this->get_question_options($question);
         }
         $this->datasetdefs = $this->qtypeobj->get_dataset_definitions($question->id, array());
     }
     foreach ($this->datasetdefs as $datasetdef) {
         // Get maxnumber.
         if ($this->maxnumber == -1 || $datasetdef->itemcount < $this->maxnumber) {
             $this->maxnumber = $datasetdef->itemcount;
         }
     }
     foreach ($this->datasetdefs as $defid => $datasetdef) {
         if (isset($datasetdef->id)) {
             $this->datasetdefs[$defid]->items = $this->qtypeobj->get_database_dataset_items($datasetdef->id);
         }
     }
     parent::__construct($submiturl);
 }
Ejemplo n.º 7
0
 /**
  * Returns localised name of enrol instance.
  *
  * @param stdClass $instance (null is accepted too)
  * @return string
  */
 public function get_instance_name($instance)
 {
     global $DB;
     if (empty($instance)) {
         $enrol = $this->get_name();
         return get_string('pluginname', 'enrol_' . $enrol);
     } else {
         if (empty($instance->name)) {
             $enrol = $this->get_name();
             $cohort = $DB->get_record('cohort', array('id' => $instance->customint1));
             if (!$cohort) {
                 return get_string('pluginname', 'enrol_' . $enrol);
             }
             $cohortname = format_string($cohort->name, true, array('context' => context::instance_by_id($cohort->contextid)));
             if ($role = $DB->get_record('role', array('id' => $instance->roleid))) {
                 $role = role_get_name($role, context_course::instance($instance->courseid, IGNORE_MISSING));
                 return get_string('pluginname', 'enrol_' . $enrol) . ' (' . $cohortname . ' - ' . $role . ')';
             } else {
                 return get_string('pluginname', 'enrol_' . $enrol) . ' (' . $cohortname . ')';
             }
         } else {
             return format_string($instance->name, true, array('context' => context_course::instance($instance->courseid)));
         }
     }
 }
Ejemplo n.º 8
0
 /**
  * If this block belongs to a activity context, then return that activity's id.
  * Otherwise, return 0.
  * @return stdclass the activity record.
  */
 public function get_owning_activity()
 {
     global $DB;
     // Set some defaults.
     $result = new stdClass();
     $result->id = 0;
     if (empty($this->instance->parentcontextid)) {
         return $result;
     }
     $parentcontext = context::instance_by_id($this->instance->parentcontextid);
     if ($parentcontext->contextlevel != CONTEXT_MODULE) {
         return $result;
     }
     $cm = get_coursemodule_from_id($this->page->cm->modname, $parentcontext->instanceid);
     if (!$cm) {
         return $result;
     }
     // Get the grade_items id.
     $rec = $DB->get_record('grade_items', array('iteminstance' => $cm->instance, 'itemmodule' => $this->page->cm->modname));
     if (!$rec) {
         return $result;
     }
     // See if it is a gradable activity.
     if ($rec->gradetype != GRADE_TYPE_VALUE && $rec->gradetype != GRADE_TYPE_SCALE) {
         return $result;
     }
     return $rec;
 }
Ejemplo n.º 9
0
function qtype_ddmarker_course_context_id($catcontextid)
{
    $context = context::instance_by_id($catcontextid);
    while ($context->contextlevel != CONTEXT_COURSE) {
        $context = $context->get_parent_context();
    }
    return $context->id;
}
 /**
  * Retrieves ajax parameters for content and update or delete
  * user data depending on params.
  *
  * @throws \coding_exception
  */
 public static function handle_ajax()
 {
     global $DB;
     // Query String Parameters.
     $content_id = required_param('content_id', PARAM_INT);
     $data_id = required_param('data_type', PARAM_RAW);
     $sub_content_id = required_param('sub_content_id', PARAM_INT);
     // Form Data.
     $data = optional_param('data', null, PARAM_RAW);
     $pre_load = optional_param('preload', null, PARAM_INT);
     $invalidate = optional_param('invalidate', null, PARAM_INT);
     if ($content_id === null || $data_id === null || $sub_content_id === null) {
         \H5PCore::ajaxError(get_string('missingparameters', 'hvp'));
         exit;
         // Missing parameters.
     }
     // Saving data
     if ($data !== NULL && $pre_load !== NULL && $invalidate !== NULL) {
         // Validate token
         if (!\H5PCore::validToken('contentuserdata', required_param('token', PARAM_RAW))) {
             \H5PCore::ajaxError(get_string('invalidtoken', 'hvp'));
             exit;
         }
         // Use context id if supplied
         $context_id = optional_param('contextId', null, PARAM_INT);
         if ($context_id) {
             $context = \context::instance_by_id($context_id);
         } else {
             // Otherwise try to find it from content id
             $context = \context_course::instance($DB->get_field('hvp', 'course', array('id' => $content_id)));
         }
         // Check permissions
         if (!has_capability('mod/hvp:savecontentuserdata', $context)) {
             \H5PCore::ajaxError(get_string('nopermissiontosavecontentuserdata', 'hvp'));
             http_response_code(403);
             exit;
         }
         if ($data === '0') {
             // Delete user data.
             self::delete_user_data($content_id, $sub_content_id, $data_id);
         } else {
             // Save user data.
             self::save_user_data($content_id, $sub_content_id, $data_id, $pre_load, $invalidate, $data);
         }
         \H5PCore::ajaxSuccess();
     } else {
         // Fetch user data
         $user_data = self::get_user_data($content_id, $sub_content_id, $data_id);
         if ($user_data === false) {
             // Did not find data, return nothing
             \H5PCore::ajaxSuccess();
         } else {
             // Found data, return encoded data
             \H5PCore::ajaxSuccess($user_data->data);
         }
     }
     exit;
 }
Ejemplo n.º 11
0
 /**
  * Decides which content types the editor should have.
  *
  * Two usecases:
  * 1. No input, will list all the available content types.
  * 2. Libraries supported are specified, load additional data and verify
  * that the content types are available. Used by e.g. the Presentation Tool
  * Editor that already knows which content types are supported in its
  * slides.
  *
  * @param array $libraries List of library names + version to load info for
  * @return array List of all libraries loaded
  */
 public function getLibraries($libraries = null)
 {
     global $DB;
     $context_id = required_param('contextId', PARAM_RAW);
     $super_user = has_capability('mod/hvp:userestrictedlibraries', \context::instance_by_id($context_id));
     if ($libraries !== null) {
         // Get details for the specified libraries only.
         $librarieswithdetails = array();
         foreach ($libraries as $library) {
             // Look for library
             $details = $DB->get_record_sql("SELECT title,\n                                runnable,\n                                restricted,\n                                tutorial_url\n                           FROM {hvp_libraries}\n                          WHERE machine_name = ?\n                            AND major_version = ?\n                            AND minor_version = ?\n                            AND semantics IS NOT NULL\n                        ", array($library->name, $library->majorVersion, $library->minorVersion));
             if ($details) {
                 // Library found, add details to list
                 $library->tutorialUrl = $details->tutorial_url;
                 $library->title = $details->title;
                 $library->runnable = $details->runnable;
                 $library->restricted = $super_user ? false : ($details->restricted === '1' ? true : false);
                 $librarieswithdetails[] = $library;
             }
         }
         // Done, return list with library details
         return $librarieswithdetails;
     }
     // Load all libraries
     $libraries = array();
     $librariesresult = $DB->get_records_sql("SELECT id,\n                        machine_name AS name,\n                        title,\n                        major_version,\n                        minor_version,\n                        tutorial_url,\n                        restricted\n                   FROM {hvp_libraries}\n                  WHERE runnable = 1\n                    AND semantics IS NOT NULL\n               ORDER BY title");
     foreach ($librariesresult as $library) {
         // Remove unique index
         unset($library->id);
         // Convert snakes to camels
         $library->majorVersion = (int) $library->major_version;
         unset($library->major_version);
         $library->minorVersion = (int) $library->minor_version;
         unset($library->minor_version);
         if (!empty($library->tutorial_url)) {
             $library->tutorialUrl = $library->tutorial_url;
         }
         unset($library->tutorial_url);
         // Make sure we only display the newest version of a library.
         foreach ($libraries as $key => $existinglibrary) {
             if ($library->name === $existinglibrary->name) {
                 // Found library with same name, check versions
                 if ($library->majorVersion === $existinglibrary->majorVersion && $library->minorVersion > $existinglibrary->minorVersion || $library->majorVersion > $existinglibrary->majorVersion) {
                     // This is a newer version
                     $existinglibrary->isOld = true;
                 } else {
                     // This is an older version
                     $library->isOld = true;
                 }
             }
         }
         // Check to see if content type should be restricted
         $library->restricted = $super_user ? false : ($library->restricted === '1' ? true : false);
         // Add new library
         $libraries[] = $library;
     }
     return $libraries;
 }
Ejemplo n.º 12
0
 /**
  * Returns a string describing the rule.
  *
  * @return string
  */
 public function get_description()
 {
     $context = context::instance_by_id($this->value, IGNORE_MISSING);
     $contextname = get_string('errorunknownmodule', 'block_xp');
     if ($context) {
         $contextname = $context->get_context_name();
     }
     return get_string('rulecmdesc', 'block_xp', (object) array('contextname' => $contextname));
 }
/**
 * Calculates capability data organised by context for the given roles.
 *
 * @param string $capability The capability to get data for.
 * @param array $roles An array of roles to get data for.
 * @return context[] An array of contexts.
 */
function tool_capability_calculate_role_data($capability, array $roles)
{
    global $DB;
    $systemcontext = context_system::instance();
    $roleids = array_keys($roles);
    // Work out the bits needed for the SQL WHERE clauses.
    $params = array($capability);
    list($sqlroletest, $roleparams) = $DB->get_in_or_equal($roleids);
    $params = array_merge($params, $roleparams);
    $sqlroletest = 'AND roleid ' . $sqlroletest;
    // Get all the role_capabilities rows for this capability - that is, all
    // role definitions, and all role overrides.
    $sql = 'SELECT id, roleid, contextid, permission
              FROM {role_capabilities}
             WHERE capability = ? ' . $sqlroletest;
    $rolecaps = $DB->get_records_sql($sql, $params);
    // In order to display a nice tree of contexts, we need to get all the
    // ancestors of all the contexts in the query we just did.
    $sql = 'SELECT DISTINCT con.path, 1
              FROM {context} con
              JOIN {role_capabilities} rc ON rc.contextid = con.id
             WHERE capability = ? ' . $sqlroletest;
    $relevantpaths = $DB->get_records_sql_menu($sql, $params);
    $requiredcontexts = array($systemcontext->id);
    foreach ($relevantpaths as $path => $notused) {
        $requiredcontexts = array_merge($requiredcontexts, explode('/', trim($path, '/')));
    }
    $requiredcontexts = array_unique($requiredcontexts);
    // Now load those contexts.
    list($sqlcontexttest, $contextparams) = $DB->get_in_or_equal($requiredcontexts);
    $contexts = get_sorted_contexts('ctx.id ' . $sqlcontexttest, $contextparams);
    // Prepare some empty arrays to hold the data we are about to compute.
    foreach ($contexts as $conid => $con) {
        $contexts[$conid]->children = array();
        $contexts[$conid]->rolecapabilities = array();
    }
    // Put the contexts into a tree structure.
    foreach ($contexts as $conid => $con) {
        $context = context::instance_by_id($conid);
        $parentcontext = $context->get_parent_context();
        if ($parentcontext) {
            $contexts[$parentcontext->id]->children[] = $conid;
        }
    }
    // Put the role capabilities into the context tree.
    foreach ($rolecaps as $rolecap) {
        $contexts[$rolecap->contextid]->rolecapabilities[$rolecap->roleid] = $rolecap->permission;
    }
    // Fill in any missing rolecaps for the system context.
    foreach ($roleids as $roleid) {
        if (!isset($contexts[$systemcontext->id]->rolecapabilities[$roleid])) {
            $contexts[$systemcontext->id]->rolecapabilities[$roleid] = CAP_INHERIT;
        }
    }
    return $contexts;
}
Ejemplo n.º 14
0
 /**
  * Generate the name column.
  *
  * @param \stdClass $tool event data.
  * @return string
  */
 public function col_name($tool)
 {
     if (empty($tool->name)) {
         $toolcontext = \context::instance_by_id($tool->contextid);
         $name = $toolcontext->get_context_name();
     } else {
         $name = $tool->name;
     }
     return $this->get_display_text($tool, $name);
 }
Ejemplo n.º 15
0
/**
 * Form for editing Information Spot  block instances.
 *
 * @copyright 2014 Roberto Pinna
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 * @package   block_informationspot
 * @category  files
 * @param stdClass $course course object
 * @param stdClass $birecord_or_cm block instance record
 * @param stdClass $context context object
 * @param string $filearea file area
 * @param array $args extra arguments
 * @param bool $forcedownload whether or not force download
 * @param array $options additional options affecting the file serving
 * @return bool
 */
function block_informationspot_pluginfile($course, $birecord_or_cm, $context, $filearea, $args, $forcedownload, array $options = array())
{
    global $DB, $CFG, $USER;
    if ($context->contextlevel != CONTEXT_BLOCK) {
        send_file_not_found();
    }
    // If block is in course context, then check if user has capability to access course.
    if ($context->get_course_context(false)) {
        require_course_login($course);
    } else {
        if ($CFG->forcelogin) {
            require_login();
        } else {
            // Get parent context and see if user have proper permission.
            $parentcontext = $context->get_parent_context();
            if ($parentcontext->contextlevel === CONTEXT_COURSECAT) {
                // Check if category is visible and user can view this category.
                $category = $DB->get_record('course_categories', array('id' => $parentcontext->instanceid), '*', MUST_EXIST);
                if (!$category->visible) {
                    require_capability('moodle/category:viewhiddencategories', $parentcontext);
                }
            } else {
                if ($parentcontext->contextlevel === CONTEXT_USER && $parentcontext->instanceid != $USER->id) {
                    // The block is in the context of a user, it is only visible to the user who it belongs to.
                    send_file_not_found();
                }
            }
            // At this point there is no way to check SYSTEM context, so ignoring it.
        }
    }
    if ($filearea != 'image') {
        send_file_not_found();
    }
    $fs = get_file_storage();
    $imageid = array_shift($args);
    $filename = array_pop($args);
    $filepath = $args ? '/' . implode('/', $args) . '/' : '/';
    if (!($file = $fs->get_file($context->id, 'block_informationspot', $filearea, $imageid, $filepath, $filename)) or $file->is_directory()) {
        send_file_not_found();
    }
    if ($parentcontext = context::instance_by_id($birecord_or_cm->parentcontextid, IGNORE_MISSING)) {
        if ($parentcontext->contextlevel == CONTEXT_USER) {
            // force download on all personal pages including /my/
            //because we do not have reliable way to find out from where this is used
            $forcedownload = true;
        }
    } else {
        // weird, there should be parent context, better force dowload then
        $forcedownload = true;
    }
    // NOTE: it woudl be nice to have file revisions here, for now rely on standard file lifetime,
    //       do not lower it because the files are dispalyed very often.
    \core\session\manager::write_close();
    send_stored_file($file, null, 0, $forcedownload, $options);
}
Ejemplo n.º 16
0
 /**
  * Updates cohort name and returns instance of this object
  *
  * @param int $cohortid
  * @param string $newvalue
  * @return static
  */
 public static function update($cohortid, $newvalue)
 {
     global $DB;
     $cohort = $DB->get_record('cohort', array('id' => $cohortid), '*', MUST_EXIST);
     $cohortcontext = \context::instance_by_id($cohort->contextid);
     require_capability('moodle/cohort:manage', $cohortcontext);
     $record = (object) array('id' => $cohort->id, 'idnumber' => $newvalue, 'contextid' => $cohort->contextid);
     cohort_update_cohort($record);
     $cohort->idnumber = $newvalue;
     return new static($cohort);
 }
Ejemplo n.º 17
0
 private function context_info($contextid)
 {
     global $DB;
     $context = \context::instance_by_id($contextid, MUST_EXIST);
     $out = '';
     //var_dump($context);
     if (is_a($context, "context_module")) {
         /** @var \context_module $context */
         $out .= "{$contextid}, module: " . $context->get_context_name();
     }
     return $out;
 }
Ejemplo n.º 18
0
 /**
  * @param string $name control name
  * @param array $options should have two elements with keys groupid and courseid.
  */
 public function __construct($name, $options)
 {
     global $CFG;
     if (isset($options['context'])) {
         $this->context = $options['context'];
     } else {
         $this->context = context::instance_by_id($options['contextid']);
     }
     $options['accesscontext'] = $this->context;
     parent::__construct($name, $options);
     $this->roleid = $options['roleid'];
     require_once $CFG->dirroot . '/group/lib.php';
 }
Ejemplo n.º 19
0
 /**
  * Add question-type specific form fields.
  *
  * @param MoodleQuickForm $mform the form being built.
  */
 public function __construct($submiturl, $question) {
     global $DB;
     $this->question = $question;
     $this->qtypeobj = question_bank::get_qtype($this->question->qtype);
     // Validate the question category.
     if (!$category = $DB->get_record('question_categories',
             array('id' => $question->category))) {
         print_error('categorydoesnotexist', 'question', $returnurl);
     }
     $this->category = $category;
     $this->categorycontext = context::instance_by_id($category->contextid);
     parent::__construct($submiturl);
 }
Ejemplo n.º 20
0
 /**
  * Updates cohort name and returns instance of this object
  *
  * @param int $cohortid
  * @param string $newvalue
  * @return static
  */
 public static function update($cohortid, $newvalue)
 {
     global $DB;
     $cohort = $DB->get_record('cohort', array('id' => $cohortid), '*', MUST_EXIST);
     $cohortcontext = \context::instance_by_id($cohort->contextid);
     require_capability('moodle/cohort:manage', $cohortcontext);
     $newvalue = clean_param($newvalue, PARAM_TEXT);
     if (strval($newvalue) !== '') {
         $record = (object) array('id' => $cohort->id, 'name' => $newvalue, 'contextid' => $cohort->contextid);
         cohort_update_cohort($record);
         $cohort->name = $newvalue;
     }
     return new static($cohort);
 }
Ejemplo n.º 21
0
 /**
  * If this block belongs to a course context, then return that course id.
  * Otherwise, return 0.
  *
  * @return int the course id.
  */
 public function get_owning_course()
 {
     if (empty($this->instance->parentcontextid)) {
         return 0;
     }
     $parentcontext = context::instance_by_id($this->instance->parentcontextid);
     if ($parentcontext->contextlevel != CONTEXT_COURSE) {
         return 0;
     }
     $coursecontext = $parentcontext->get_course_context(true);
     if (!$coursecontext) {
         return 0;
     }
     return $coursecontext->instanceid;
 }
 /**
  * If this block belongs to a quiz context, then return that quiz's id.
  * Otherwise, return 0.
  * @return integer the quiz id.
  */
 public function get_owning_quiz()
 {
     if (empty($this->instance->parentcontextid)) {
         return 0;
     }
     $parentcontext = context::instance_by_id($this->instance->parentcontextid);
     if ($parentcontext->contextlevel != CONTEXT_MODULE) {
         return 0;
     }
     $cm = get_coursemodule_from_id('quiz', $parentcontext->instanceid);
     if (!$cm) {
         return 0;
     }
     return $cm->instance;
 }
Ejemplo n.º 23
0
/**
 * Simple slider block for Moodle
 *
 * @package   block_slider
 * @copyright 2015 Kamil Łuczak    www.limsko.pl     kamil@limsko.pl
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
function block_slider_pluginfile($course, $birecord_or_cm, $context, $filearea, $args, $forcedownload, array $options = array())
{
    global $DB, $CFG;
    if ($context->contextlevel != CONTEXT_BLOCK) {
        send_file_not_found();
    }
    // If block is in course context, then check if user has capability to access course.
    if ($context->get_course_context(false)) {
        require_course_login($course);
    } else {
        if ($CFG->forcelogin) {
            require_login();
        } else {
            // Get parent context and see if user have proper permission.
            $parentcontext = $context->get_parent_context();
            if ($parentcontext->contextlevel === CONTEXT_COURSECAT) {
                // Check if category is visible and user can view this category.
                $category = $DB->get_record('course_categories', array('id' => $parentcontext->instanceid), '*', MUST_EXIST);
                if (!$category->visible) {
                    require_capability('moodle/category:viewhiddencategories', $parentcontext);
                }
            }
            // At this point there is no way to check SYSTEM or USER context, so ignoring it.
        }
    }
    if ($filearea !== 'content') {
        send_file_not_found();
    }
    $fs = get_file_storage();
    $filename = array_pop($args);
    $filepath = $args ? '/' . implode('/', $args) . '/' : '/';
    if (!($file = $fs->get_file($context->id, 'block_slider', 'content', 0, $filepath, $filename)) or $file->is_directory()) {
        send_file_not_found();
    }
    if ($parentcontext = context::instance_by_id($birecord_or_cm->parentcontextid, IGNORE_MISSING)) {
        if ($parentcontext->contextlevel == CONTEXT_USER) {
            // force download on all personal pages including /my/
            //because we do not have reliable way to find out from where this is used
            $forcedownload = true;
        }
    } else {
        // weird, there should be parent context, better force dowload then
        $forcedownload = true;
    }
    session_get_instance()->write_close();
    send_stored_file($file, 60 * 60, 0, $forcedownload, $options);
}
Ejemplo n.º 24
0
 public function poll_user_eligible()
 {
     global $COURSE, $USER;
     $parents = $this->context->get_parent_context_ids();
     $parentctx = context::instance_by_id($parents[0]);
     $switched = false;
     if ($this->poll->eligible == 'students') {
         $switched = is_role_switched($COURSE->id);
         if (isset($USER->access['rsw'][$parentctx->path])) {
             $switched = $switched && !role_context_capabilities($USER->access['rsw'][$parentctx->path], $this->context, 'block/poll:editpoll');
         } else {
             $switched = false;
         }
     }
     // TODO: Proper roles & capabilities.
     return $this->poll->eligible == 'all' || $this->poll->eligible == 'students' && !$this->poll_can_edit() || $switched || $this->poll->eligible == 'teachers' && $this->poll_can_edit();
 }
 /**
  * Return the correct role for a user, given a context.
  */
 private function get_role_from_context($contextid, $userid)
 {
     $context = \context::instance_by_id($contextid);
     $role = "Viewer";
     if (has_capability('block/panopto:provision_aspublisher', $context, $userid)) {
         if (has_capability('block/panopto:provision_asteacher', $context, $userid)) {
             $role = "Creator/Publisher";
         } else {
             $role = "Publisher";
         }
     } else {
         if (has_capability('block/panopto:provision_asteacher', $context, $userid)) {
             $role = "Creator";
         }
     }
     return $role;
 }
Ejemplo n.º 26
0
/**
 * Callback function called from question_list() function
 * (which is called from showbank())
 */
function module_specific_controls($totalnumber, $recurse, $category, $cmid, $cmoptions) {
    global $OUTPUT;
    $out = '';
    $catcontext = context::instance_by_id($category->contextid);
    if (has_capability('moodle/question:useall', $catcontext)) {
        if ($cmoptions->hasattempts) {
            $disabled = ' disabled="disabled"';
        } else {
            $disabled = '';
        }
        $randomusablequestions =
                question_bank::get_qtype('random')->get_available_questions_from_category(
                        $category->id, $recurse);
        $maxrand = count($randomusablequestions);
        if ($maxrand > 0) {
            for ($i = 1; $i <= min(10, $maxrand); $i++) {
                $randomcount[$i] = $i;
            }
            for ($i = 20; $i <= min(100, $maxrand); $i += 10) {
                $randomcount[$i] = $i;
            }
        } else {
            $randomcount[0] = 0;
            $disabled = ' disabled="disabled"';
        }

        $out = '<strong><label for="menurandomcount">'.get_string('addrandomfromcategory', 'quiz').
                '</label></strong><br />';
        $attributes = array();
        $attributes['disabled'] = $disabled ? 'disabled' : null;
        $select = html_writer::select($randomcount, 'randomcount', '1', null, $attributes);
        $out .= get_string('addrandom', 'quiz', $select);
        $out .= '<input type="hidden" name="recurse" value="'.$recurse.'" />';
        $out .= '<input type="hidden" name="categoryid" value="' . $category->id . '" />';
        $out .= ' <input type="submit" name="addrandom" value="'.
                get_string('addtoquiz', 'quiz').'"' . $disabled . ' />';
        $out .= $OUTPUT->help_icon('addarandomquestion', 'quiz');
    }
    return $out;
}
Ejemplo n.º 27
0
 /**
  * Observer for role_assigned event.
  *
  * @param \core\event\role_assigned $event
  * @return void
  */
 public static function role_assigned(\core\event\role_assigned $event)
 {
     global $CFG, $DB;
     $context = context::instance_by_id($event->contextid, MUST_EXIST);
     // If contextlevel is course then only subscribe user. Role assignment
     // at course level means user is enroled in course and can subscribe to anonymous forum.
     if ($context->contextlevel != CONTEXT_COURSE) {
         return;
     }
     // Anonymous Forum lib required for the constant used below.
     require_once $CFG->dirroot . '/mod/anonforum/lib.php';
     $userid = $event->relateduserid;
     $sql = "SELECT f.id, cm.id AS cmid\n                  FROM {anonforum} f\n                  JOIN {course_modules} cm ON (cm.instance = f.id)\n                  JOIN {modules} m ON (m.id = cm.module)\n             LEFT JOIN {anonforum_subscriptions} fs ON (fs.anonforum = f.id AND fs.userid = :userid)\n                 WHERE f.course = :courseid\n                   AND f.forcesubscribe = :initial\n                   AND m.name = 'anonforum'\n                   AND fs.id IS NULL";
     $params = array('courseid' => $context->instanceid, 'userid' => $userid, 'initial' => ANONFORUM_INITIALSUBSCRIBE);
     $anonforums = $DB->get_records_sql($sql, $params);
     foreach ($anonforums as $anonforum) {
         // If user doesn't have allowforcesubscribe capability then don't subscribe.
         if (has_capability('mod/anonforum:allowforcesubscribe', context_module::instance($anonforum->cmid), $userid)) {
             anonforum_subscribe($userid, $anonforum->id);
         }
     }
 }
Ejemplo n.º 28
0
/**
 * Outputs a matrix of roles and capabilities.
 *
 * @param int $contextid The context we are displaying for.
 * @param array $capabilities An array of capabilities to show.
 * @param array $roles An array of roles to show.
 */
function capability_matrix($contextid, array $capabilities, array $roles)
{
    $strpermissions = get_permission_strings();
    if ($contextid === context_system::instance()->id) {
        $strpermissions[CAP_INHERIT] = new lang_string('notset', 'role');
    }
    // Start the list item.
    $context = context::instance_by_id($contextid);
    echo "\n" . $context->get_context_name() . "\t";
    // Display the role names as headings.
    foreach ($roles as $role) {
        echo $role->localname . "\t";
    }
    echo "\n\n";
    $matrix = array();
    foreach ($capabilities as $capability) {
        $contexts = tool_capability_calculate_role_data($capability, $roles);
        echo get_capability_string($capability) . "\t";
        foreach ($roles as $role) {
            if (isset($contexts[$contextid]->rolecapabilities[$role->id])) {
                $permission = $contexts[$contextid]->rolecapabilities[$role->id];
            } else {
                $permission = CAP_INHERIT;
            }
            echo $strpermissions[$permission] . "\t";
            $matrix[$role][$capability] = $permission;
            // for comparison matrix !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        }
        echo "\n";
    }
    // If there are any child contexts, print them recursively.
    if (!empty($contexts[$contextid]->children)) {
        foreach ($contexts[$contextid]->children as $childcontextid) {
            capability_comparison_table($capabilities, $childcontextid, $roles, true);
        }
    }
    return;
}
Ejemplo n.º 29
0
 function get_content()
 {
     global $CFG, $OUTPUT, $USER;
     $coursecontext = context::instance_by_id($this->instance->parentcontextid);
     if (!has_capability('moodle/community:add', $coursecontext) or $this->content !== NULL) {
         return $this->content;
     }
     $this->content = new stdClass();
     $this->content->items = array();
     $this->content->icons = array();
     $this->content->footer = '';
     if (!isloggedin()) {
         return $this->content;
     }
     $icon = html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('i/group'), 'class' => 'icon', 'alt' => ""));
     $addcourseurl = new moodle_url('/blocks/community/communitycourse.php', array('add' => true, 'courseid' => $this->page->course->id));
     $searchlink = html_writer::tag('a', $icon . get_string('addcourse', 'block_community'), array('href' => $addcourseurl->out(false)));
     $this->content->items[] = $searchlink;
     require_once $CFG->dirroot . '/blocks/community/locallib.php';
     $communitymanager = new block_community_manager();
     $courses = $communitymanager->block_community_get_courses($USER->id);
     if ($courses) {
         $this->content->items[] = html_writer::empty_tag('hr');
         $this->content->icons[] = '';
         $this->content->items[] = get_string('mycommunities', 'block_community');
         $this->content->icons[] = '';
         foreach ($courses as $course) {
             //delete link
             $deleteicon = html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('t/delete'), 'alt' => get_string('removecommunitycourse', 'block_community')));
             $deleteurl = new moodle_url('/blocks/community/communitycourse.php', array('remove' => true, 'courseid' => $this->page->course->id, 'communityid' => $course->id, 'sesskey' => sesskey()));
             $deleteatag = html_writer::tag('a', $deleteicon, array('href' => $deleteurl));
             $courselink = html_writer::tag('a', $course->coursename, array('href' => $course->courseurl));
             $this->content->items[] = $courselink . ' ' . $deleteatag;
             $this->content->icons[] = '';
         }
     }
     return $this->content;
 }
Ejemplo n.º 30
0
 */
require('../../config.php');
require_once($CFG->dirroot.'/local/batches/assignuserlib.php');
require_once($CFG->dirroot.'/local/batches/lib.php');
require_once($CFG->dirroot . '/cohort/lib.php');
//require_once($CFG->dirroot . '/cohort/locallib.php');
require_once($CFG->dirroot . '/user/selector/lib.php');

$id = required_param('id', PARAM_INT);
$costid = optional_param('costid', 0, PARAM_INT);
global $OUTPUT;

require_login();

$cohort = $DB->get_record('cohort', array('id'=>$id), '*', MUST_EXIST);
$context = context::instance_by_id($cohort->contextid, MUST_EXIST);

require_capability('moodle/cohort:assign', $context);

$PAGE->set_context($context);
$PAGE->set_url('/local/batches/assignusers.php', array('id'=>$id));
$PAGE->set_pagelayout('admin');

$returnurl = new moodle_url('/local/batches/index.php');

$batches = new local_batches($id);

if (!empty($cohort->component)) {
    // We can not manually edit cohorts that were created by external systems, sorry.
    redirect($returnurl);
}