Пример #1
1
 /**
  * Constructor for the base resource class
  *
  * Constructor for the base resource class.
  * If cmid is set create the cm, course, resource objects.
  * and do some checks to make sure people can be here, and so on.
  *
  * @param cmid   integer, the current course module id - not set for new resources
  */
 function resource_base($cmid = 0)
 {
     global $CFG, $COURSE;
     $this->navlinks = array();
     if ($cmid) {
         if (!($this->cm = get_coursemodule_from_id('resource', $cmid))) {
             error("Course Module ID was incorrect");
         }
         if (!($this->course = get_record("course", "id", $this->cm->course))) {
             error("Course is misconfigured");
         }
         if (!($this->resource = get_record("resource", "id", $this->cm->instance))) {
             error("Resource ID was incorrect");
         }
         $this->strresource = get_string("modulename", "resource");
         $this->strresources = get_string("modulenameplural", "resource");
         if (!$this->cm->visible and !has_capability('moodle/course:viewhiddenactivities', get_context_instance(CONTEXT_MODULE, $this->cm->id))) {
             $pagetitle = strip_tags($this->course->shortname . ': ' . $this->strresource);
             $navigation = build_navigation($this->navlinks, $this->cm);
             print_header($pagetitle, $this->course->fullname, $navigation, "", "", true, '', navmenu($this->course, $this->cm));
             notice(get_string("activityiscurrentlyhidden"), "{$CFG->wwwroot}/course/view.php?id={$this->course->id}");
         }
     } else {
         $this->course = $COURSE;
     }
 }
Пример #2
1
/**
 * Serves assignment feedback and other files.
 *
 * @param mixed $course course or id of the course
 * @param mixed $cm course module or id of the course module
 * @param context $context
 * @param string $filearea
 * @param array $args
 * @param bool $forcedownload
 * @return bool false if file not found, does not return if found - just send the file
 */
function assignfeedback_editpdf_pluginfile($course, $cm, context $context, $filearea, $args, $forcedownload)
{
    global $USER, $DB, $CFG;
    if ($context->contextlevel == CONTEXT_MODULE) {
        require_login($course, false, $cm);
        $itemid = (int) array_shift($args);
        if (!($assign = $DB->get_record('assign', array('id' => $cm->instance)))) {
            return false;
        }
        $record = $DB->get_record('assign_grades', array('id' => $itemid), 'userid,assignment', MUST_EXIST);
        $userid = $record->userid;
        if ($assign->id != $record->assignment) {
            return false;
        }
        // Check is users feedback or has grading permission.
        if ($USER->id != $userid and !has_capability('mod/assign:grade', $context)) {
            return false;
        }
        $relativepath = implode('/', $args);
        $fullpath = "/{$context->id}/assignfeedback_editpdf/{$filearea}/{$itemid}/{$relativepath}";
        $fs = get_file_storage();
        if (!($file = $fs->get_file_by_hash(sha1($fullpath))) or $file->is_directory()) {
            return false;
        }
        // Download MUST be forced - security!
        send_stored_file($file, 0, 0, true);
        // Check if we want to retrieve the stamps.
    }
}
 /**
  * Search a list of modules.
  *
  * @param $modulecode
  * @return array [string]
  * @throws \invalid_parameter_exception
  */
 public static function get_submission_status($submissionid)
 {
     global $DB, $USER;
     $params = self::validate_parameters(self::get_submission_status_parameters(), array('submissionid' => $submissionid));
     $submissionid = $params['submissionid'];
     $submission = $DB->get_record('turnitintooltwo_submissions', array('id' => $submissionid));
     if (!$submission) {
         return array('status' => 'error');
     }
     // Grab more data.
     $turnitintooltwo = $DB->get_record('turnitintooltwo', array('id' => $submission->turnitintooltwoid));
     list($course, $cm) = get_course_and_cm_from_instance($turnitintooltwo, 'turnitintooltwo');
     // Check this is our submission.
     if ($USER->id !== $submission->userid && !has_capability('mod/turnitintooltwo:grade', \context_module::instance($cm->id))) {
         return array('status' => 'nopermission');
     }
     // What is the status?
     $status = $DB->get_record('turnitintooltwo_sub_status', array('submissionid' => $submissionid));
     if (!$status) {
         return array('status' => 'queued');
     }
     // Decode the receipt.
     $digitalreceipt = (array) json_decode($status->receipt);
     // Woo!
     if ($status->status == \mod_turnitintooltwo\task\submit_assignment::STATUS_SUCCESS) {
         $turnitintooltwoview = new \turnitintooltwo_view();
         $digitalreceipt = $turnitintooltwoview->show_digital_receipt($digitalreceipt);
         $digitalreceipt = \html_writer::tag("div", $digitalreceipt, array("id" => "box_receipt"));
         return array('status' => 'success', 'message' => $digitalreceipt);
     }
     return array('status' => 'failed', 'message' => \html_writer::tag("div", $digitalreceipt["message"], array("class" => "alert alert-danger")));
 }
 function definition()
 {
     global $CFG, $USER;
     $mform =& $this->_form;
     $course = $this->_customdata['course'];
     $cm = $this->_customdata['cm'];
     $modcontext = $this->_customdata['modcontext'];
     $mform->addElement('header', 'general', get_string('export', 'quiz'));
     $mform->setHelpButton('general', array('export', get_string('export', 'quiz'), 'attforblock'));
     $groupmode = groups_get_activity_groupmode($cm);
     $groups = groups_get_activity_allowed_groups($cm, $USER->id);
     if ($groupmode == VISIBLEGROUPS or has_capability('moodle/site:accessallgroups', $modcontext)) {
         $grouplist[0] = get_string('allparticipants');
     }
     if ($groups) {
         foreach ($groups as $group) {
             $grouplist[$group->id] = $group->name;
         }
     }
     $mform->addElement('select', 'group', get_string('group'), $grouplist);
     $ident = array();
     $ident[] =& MoodleQuickForm::createElement('checkbox', 'id', '', get_string('studentid', 'attforblock'));
     $ident[] =& MoodleQuickForm::createElement('checkbox', 'uname', '', get_string('username'));
     $mform->addGroup($ident, 'ident', get_string('identifyby', 'attforblock'), array('<br />'), true);
     $mform->setDefaults(array('ident[id]' => true, 'ident[uname]' => true));
     $mform->addElement('checkbox', 'includenottaken', get_string('includenottaken', 'attforblock'), get_string('yes'));
     $mform->addElement('date_selector', 'sessionenddate', get_string('endofperiod', 'attforblock'));
     $mform->disabledIf('sessionenddate', 'includenottaken', 'notchecked');
     $mform->addElement('select', 'format', get_string('format'), array('excel' => get_string('downloadexcel', 'attforblock'), 'ooo' => get_string('downloadooo', 'attforblock'), 'text' => get_string('downloadtext', 'attforblock')));
     // buttons
     $submit_string = get_string('ok');
     $this->add_action_buttons(false, $submit_string);
     $mform->addElement('hidden', 'id', $cm->id);
     //        $mform->addElement('hidden', 'action', 'add');
 }
Пример #5
0
/**
 * Adds module specific settings to the settings block
 *
 * @param settings_navigation $settings The settings navigation object
 * @param navigation_node $node The node to add module settings to
 */
function booktool_wordimport_extend_settings_navigation(settings_navigation $settings, navigation_node $node)
{
    global $PAGE;
    if ($PAGE->cm->modname !== 'book') {
        return;
    }
    $params = $PAGE->url->params();
    if (empty($params['id']) and empty($params['cmid'])) {
        return;
    }
    if (empty($PAGE->cm->context)) {
        $PAGE->cm->context = get_context_module::instance($PAGE->cm->instance);
    }
    if (!(has_capability('booktool/wordimport:import', $PAGE->cm->context) and has_capability('mod/book:edit', $PAGE->cm->context))) {
        return;
    }
    // Configure Import link, and pass in the current chapter in case the insert should happen here rather than at the end.
    $url1 = new moodle_url('/mod/book/tool/wordimport/index.php', array('id' => $PAGE->cm->id, 'chapterid' => $params['chapterid']));
    $node->add(get_string('importchapters', 'booktool_wordimport'), $url1, navigation_node::TYPE_SETTING, null, null, new pix_icon('f/document', '', 'moodle', array('class' => 'iconsmall', 'title' => '')));
    // Configure Export links for book and current chapter.
    $url2 = new moodle_url('/mod/book/tool/wordimport/index.php', array('id' => $PAGE->cm->id, 'action' => 'export'));
    $node->add(get_string('exportbook', 'booktool_wordimport'), $url2, navigation_node::TYPE_SETTING, null, null, new pix_icon('f/document', '', 'moodle', array('class' => 'iconsmall', 'title' => '')));
    $url3 = new moodle_url('/mod/book/tool/wordimport/index.php', array('id' => $PAGE->cm->id, 'chapterid' => $params['chapterid'], 'action' => 'export'));
    $node->add(get_string('exportchapter', 'booktool_wordimport'), $url3, navigation_node::TYPE_SETTING, null, null, new pix_icon('f/document', '', 'moodle', array('class' => 'iconsmall', 'title' => '')));
}
Пример #6
0
 function definition()
 {
     global $CFG;
     $mform =& $this->_form;
     $syscontext = get_context_instance(CONTEXT_SYSTEM);
     $actions = array(0 => get_string('choose') . '...');
     if (has_capability('moodle/user:update', $syscontext)) {
         $actions[1] = get_string('confirm');
     }
     if (has_capability('moodle/site:readallmessages', $syscontext) && !empty($CFG->messaging)) {
         $actions[2] = get_string('messageselectadd');
     }
     if (has_capability('moodle/user:delete', $syscontext)) {
         $actions[3] = get_string('delete');
     }
     $actions[4] = get_string('displayonpage');
     if (has_capability('moodle/user:update', $syscontext)) {
         $actions[5] = get_string('download', 'admin');
     }
     if (has_capability('moodle/role:assign', $syscontext)) {
         $actions[6] = get_string('enrolmultipleusers', 'admin');
     }
     $objs = array();
     $objs[] =& $mform->createElement('select', 'action', null, $actions);
     $objs[] =& $mform->createElement('submit', 'doaction', get_string('go'));
     $mform->addElement('group', 'actionsgrp', get_string('withselectedusers'), $objs, ' ', false);
 }
Пример #7
0
 /**
  * Constructor.
  *
  * @param stdClass $cohort
  */
 public function __construct($cohort)
 {
     $cohortcontext = \context::instance_by_id($cohort->contextid);
     $editable = has_capability('moodle/cohort:manage', $cohortcontext);
     $displayvalue = format_string($cohort->name, true, array('context' => $cohortcontext));
     parent::__construct('core_cohort', 'cohortname', $cohort->id, $editable, $displayvalue, $cohort->name, new lang_string('editcohortname', 'cohort'), new lang_string('newnamefor', 'cohort', $displayvalue));
 }
Пример #8
0
 function definition_after_data()
 {
     global $CFG;
     $mform =& $this->_form;
     $courseid = $mform->getElementValue('courseid');
     if ($id = $mform->getElementValue('id')) {
         $scale = grade_scale::fetch(array('id' => $id));
         $used = $scale->is_used();
         if ($used) {
             $mform->hardFreeze('scale');
         }
         if (empty($courseid)) {
             $mform->hardFreeze('standard');
         } else {
             if (empty($scale->courseid) and !has_capability('moodle/course:managescales', get_context_instance(CONTEXT_SYSTEM))) {
                 $mform->hardFreeze('standard');
             } else {
                 if ($used and !empty($scale->courseid)) {
                     $mform->hardFreeze('standard');
                 }
             }
         }
         $usedstr = $scale->is_used() ? get_string('yes') : get_string('no');
         $used_el =& $mform->getElement('used');
         $used_el->setValue($usedstr);
     } else {
         $mform->removeElement('used');
         if (empty($courseid) or !has_capability('moodle/course:managescales', get_context_instance(CONTEXT_SYSTEM))) {
             $mform->hardFreeze('standard');
         }
     }
 }
Пример #9
0
 /**
  * Prints the tabs for the learning path type
  *
  * @param string $currenttab Tab to highlight
  * @return void
  **/
 function print_tabs($currenttab = 'layout')
 {
     global $COURSE;
     $context = get_context_instance(CONTEXT_COURSE, $COURSE->id);
     $tabs = $row = $inactive = $active = array();
     $row[] = new tabobject('view', $this->url_get_full(), get_string('editpage', 'format_page'));
     if (has_capability('format/page:addpages', $context)) {
         $row[] = new tabobject('addpage', $this->url_build('action', 'editpage'), get_string('addpage', 'format_page'));
     }
     if (has_capability('format/page:managepages', $context)) {
         $row[] = new tabobject('manage', $this->url_build('action', 'manage'), get_string('manage', 'format_page'));
     }
     if (has_capability('moodle/local:managepageactivities', $context)) {
         $row[] = new tabobject('activities', $this->url_build('action', 'activities'), get_string('managemods', 'format_page'));
     }
     if (has_capability('moodle/local:classifylearningpath', $context)) {
         $row[] = new tabobject('classify', $this->url_build('action', 'classify'), get_string('classification', 'local'));
     }
     if (has_capability('moodle/local:savelearningpathtemplate', $context)) {
         $row[] = new tabobject('backup', $this->url_build('action', 'backup'), get_string('makebackup', 'local'));
     }
     $tabs[] = $row;
     if (in_array($currenttab, array('layout', 'settings', 'view'))) {
         $active[] = 'view';
         $row = array();
         $row[] = new tabobject('layout', $this->url_get_full(), get_string('layout', 'format_page'));
         $row[] = new tabobject('settings', $this->url_get_full(array('action' => 'editpage')), get_string('settings', 'format_page'));
         $tabs[] = $row;
     }
     print_tabs($tabs, $currenttab, $inactive, $active);
 }
Пример #10
0
 /**
  * block contents
  *
  * @return object
  */
 public function get_content()
 {
     global $CFG, $COURSE, $USER, $PAGE;
     if ($this->content !== NULL) {
         return $this->content;
     }
     if ($COURSE->id == SITEID) {
         $context = context_system::instance();
     } else {
         $context = context_course::instance($COURSE->id);
     }
     $this->content = new stdClass();
     $this->content->text = '';
     $this->content->footer = '';
     $mymoodle = 0;
     if (strcmp('my-index', $PAGE->pagetype) == 0) {
         $mymoodle = 1;
     }
     if (has_capability('block/enrolsurvey:edit', $context)) {
         $editpage = get_string('editpage', 'block_enrolsurvey');
         $this->content->text .= "<a\nhref=\"{$CFG->wwwroot}/blocks/enrolsurvey/edit_survey.php?id={$this->instance->id}&courseid={$COURSE->id}&mymoodle={$mymoodle}\">{$editpage}</a><br\n/>";
     }
     if (has_capability('block/enrolsurvey:take', $context) && cm_get_crlmuserid($USER->id) !== false) {
         // MUST have ELIS user record to take survey!
         if (!empty($this->config->force_user) && !is_survey_taken($USER->id, $this->instance->id)) {
             redirect("{$CFG->wwwroot}/blocks/enrolsurvey/survey.php?id={$this->instance->id}");
         }
         $takepage = get_string('takepage', 'block_enrolsurvey');
         $this->content->text .= "<a\nhref=\"{$CFG->wwwroot}/blocks/enrolsurvey/survey.php?id={$this->instance->id}&courseid={$COURSE->id}&mymoodle={$mymoodle}\">{$takepage}</a><br\n/>";
     }
     // $this->content->text .= "<br/> crontime = {$this->config->cron_time}";
     return $this->content;
 }
Пример #11
0
/**
 * Callback function called from question_list() function (which is called from showbank())
 */
function module_specific_controls($totalnumber, $recurse, $category, $cmid)
{
    global $QTYPES;
    $out = '';
    $catcontext = get_context_instance_by_id($category->contextid);
    if (has_capability('moodle/question:useall', $catcontext)) {
        $randomusablequestions = $QTYPES['random']->get_usable_questions_from_category($category->id, $recurse, '0');
        $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;
            }
            $out .= '<br />';
            $out .= get_string('addrandom', 'quiz', choose_from_menu($randomcount, 'randomcount', '1', '', '', '', true));
            $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('add') . '" />';
            $out .= helpbutton('random', get_string('random', 'quiz'), 'quiz', true, false, '', true);
        }
    }
    return $out;
}
Пример #12
0
 function get_content()
 {
     global $CFG, $OUTPUT;
     if (empty($this->instance)) {
         $this->content = '';
         return $this->content;
     }
     $this->content = new stdClass();
     $this->content->items = array();
     $this->content->icons = array();
     $this->content->footer = '';
     /// MDL-13252 Always get the course context or else the context may be incorrect in the user/index.php
     $currentcontext = $this->page->context;
     if ($this->page->course->id == SITEID) {
         if (!has_capability('moodle/site:viewparticipants', get_context_instance(CONTEXT_SYSTEM))) {
             $this->content = '';
             return $this->content;
         }
     } else {
         if (!has_capability('moodle/course:viewparticipants', $currentcontext)) {
             $this->content = '';
             return $this->content;
         }
     }
     $icon = '<img src="' . $OUTPUT->pix_url('i/users') . '" class="icon" alt="" />&nbsp;';
     $this->content->items[] = '<a title="' . get_string('listofallpeople') . '" href="' . $CFG->wwwroot . '/user/index.php?contextid=' . $currentcontext->id . '">' . $icon . get_string('participants') . '</a>';
     return $this->content;
 }
Пример #13
0
 /**
  * Form definition
  */
 function definition()
 {
     global $USER, $CFG, $COURSE;
     $coursecontext = context_course::instance($COURSE->id);
     $mform =& $this->_form;
     $editoroptions = $this->_customdata['editoroptions'];
     $mform->addElement('header', 'general', get_string('general', 'form'));
     $mform->addElement('text', 'name', get_string('groupingname', 'group'), 'maxlength="254" size="50"');
     $mform->addRule('name', get_string('required'), 'required', null, 'server');
     $mform->setType('name', PARAM_MULTILANG);
     $mform->addElement('text', 'idnumber', get_string('idnumbergrouping'), 'maxlength="100" size="10"');
     $mform->addHelpButton('idnumber', 'idnumbergrouping');
     $mform->setType('idnumber', PARAM_RAW);
     $mform->setAdvanced('idnumber');
     if (!has_capability('moodle/course:changeidnumber', $coursecontext)) {
         $mform->hardFreeze('idnumber');
     }
     $mform->addElement('editor', 'description_editor', get_string('groupingdescription', 'group'), null, $editoroptions);
     $mform->setType('description_editor', PARAM_RAW);
     $mform->addElement('hidden', 'id');
     $mform->setType('id', PARAM_INT);
     $mform->addElement('hidden', 'courseid');
     $mform->setType('courseid', PARAM_INT);
     $this->add_action_buttons();
 }
Пример #14
0
 protected function other_attempt_fields(MoodleQuickForm $mform) {
     if (has_capability('mod/quiz:regrade', $this->_customdata['context'])) {
         $mform->addElement('advcheckbox', 'onlyregraded', '',
                 get_string('optonlyregradedattempts', 'quiz_overview'));
         $mform->disabledIf('onlyregraded', 'attempts', 'eq', quiz_attempts_report::ENROLLED_WITHOUT);
     }
 }
Пример #15
0
 /**
  * Return guest enrolment instance information.
  *
  * @param int $instanceid instance id of guest enrolment plugin.
  * @return array warnings and instance information.
  * @since Moodle 3.1
  */
 public static function get_instance_info($instanceid)
 {
     global $DB;
     $params = self::validate_parameters(self::get_instance_info_parameters(), array('instanceid' => $instanceid));
     $warnings = array();
     // Retrieve guest enrolment plugin.
     $enrolplugin = enrol_get_plugin('guest');
     if (empty($enrolplugin)) {
         throw new moodle_exception('invaliddata', 'error');
     }
     require_login(null, false, null, false, true);
     $enrolinstance = $DB->get_record('enrol', array('id' => $params['instanceid']), '*', MUST_EXIST);
     $course = $DB->get_record('course', array('id' => $enrolinstance->courseid), '*', MUST_EXIST);
     $context = context_course::instance($course->id);
     if (!$course->visible and !has_capability('moodle/course:viewhiddencourses', $context)) {
         throw new moodle_exception('coursehidden');
     }
     $instanceinfo = $enrolplugin->get_enrol_info($enrolinstance);
     // Specific instance information.
     $instanceinfo->passwordrequired = $instanceinfo->requiredparam->passwordrequired;
     unset($instanceinfo->requiredparam);
     $result = array();
     $result['instanceinfo'] = $instanceinfo;
     $result['warnings'] = $warnings;
     return $result;
 }
Пример #16
0
    /**
     * Returns html to display the content of mod_folder
     * (Description, folder files and optionally Edit button)
     *
     * @param stdClass $folder record from 'folder' table (please note
     *     it may not contain fields 'revision' and 'timemodified')
     * @return string
     */
    public function display_folder(stdClass $folder) {
        $output = '';
        $folderinstances = get_fast_modinfo($folder->course)->get_instances_of('folder');
        if (!isset($folderinstances[$folder->id]) ||
                !($cm = $folderinstances[$folder->id]) ||
                !$cm->uservisible ||
                !($context = context_module::instance($cm->id)) ||
                !has_capability('mod/folder:view', $context)) {
            // some error in parameters or module is not visible to the user
            // don't throw any errors in renderer, just return empty string
            return $output;
        }

        if (trim($folder->intro)) {
            if ($folder->display != FOLDER_DISPLAY_INLINE) {
                $output .= $this->output->box(format_module_intro('folder', $folder, $cm->id),
                        'generalbox', 'intro');
            } else if ($cm->showdescription) {
                // for "display inline" do not filter, filters run at display time.
                $output .= format_module_intro('folder', $folder, $cm->id, false);
            }
        }

        $output .= $this->output->box($this->render(new folder_tree($folder, $cm)),
                'generalbox foldertree');

        // Do not append the edit button on the course page.
        if ($folder->display != FOLDER_DISPLAY_INLINE && has_capability('mod/folder:managefiles', $context)) {
            $output .= $this->output->container(
                    $this->output->single_button(new moodle_url('/mod/folder/edit.php',
                    array('id' => $cm->id)), get_string('edit')),
                    'mdl-align folder-edit-button');
        }
        return $output;
    }
Пример #17
0
/**
 * Is current user allowed to access this report
 *
 * @private defined in lib.php for performance reasons
 *
 * @param stdClass $user
 * @param stdClass $course
 * @return bool
 */
function report_comments_can_access_user_report($user, $course)
{
    global $USER, $CFG;
    if (empty($CFG->enablecomments)) {
        return false;
    }
    if ($course->id != SITEID and !$course->enablecomments) {
        return false;
    }
    $coursecontext = context_course::instance($course->id);
    if (has_capability('report/comments:view', $coursecontext)) {
        return true;
    }
    $personalcontext = context_user::instance($user->id);
    if (has_capability('moodle/user:viewuseractivitiesreport', $personalcontext)) {
        if ($course->showreports and (is_viewing($coursecontext, $user) or is_enrolled($coursecontext, $user))) {
            return true;
        }
    } else {
        if ($user->id == $USER->id) {
            if ($course->showreports and (is_viewing($coursecontext, $USER) or is_enrolled($coursecontext, $USER))) {
                return true;
            }
        }
    }
    return false;
}
Пример #18
0
/**
 * Check the grades available for the request activity
 * @param int $rcontentid -> ID of the rcontent
 * @param int $groupingid -> ID of the group
 * @return int -> count of grades
 */
function rcontent_get_count_users($rcontentid, $groupingid = null, $context, $filter = '')
{
    global $CFG, $USER, $DB;
    // Test when the user role is studen and just count his grades
    if (has_capability('mod/rcontent:viewreport', $context)) {
        if (!has_capability('mod/rcontent:viewresult', $context)) {
            $sql = "SELECT count(st.id) FROM {rcontent_grades} st\r\n                    WHERE st.rcontentid = {$rcontentid} AND st.userid={$USER->id}";
            // Filter by status
            if ($filter != '') {
                $sql .= " AND st.status = '{$filter}'";
            }
            if ($DB->count_records_sql($sql) > 0) {
                return 1;
            }
        } else {
            if (!empty($CFG->enablegroupings) && !empty($groupingid)) {
                $sql = "SELECT COUNT(DISTINCT st.userid)\r\n                    FROM {rcontent_grades} st\r\n                        INNER JOIN {groups_members} gm ON st.userid = gm.userid\r\n                        INNER JOIN {groupings_groups} gg ON gm.groupid = gg.groupid\r\n                    WHERE st.rcontentid = {$rcontentid} AND gg.groupingid = {$groupingid}";
                // Filter by status
                if ($filter != '') {
                    $sql .= " AND st.status = '{$filter}'";
                }
            } else {
                $sql = "SELECT COUNT(DISTINCT st.userid)\r\n                    FROM {rcontent_grades} st\r\n                    WHERE st.rcontentid = {$rcontentid}";
                // Filter by status
                if ($filter != '') {
                    $sql .= " AND st.status = '{$filter}'";
                }
            }
            return $DB->count_records_sql($sql);
        }
    }
    return 0;
}
 private function init()
 {
     if (!$this->isInit) {
         $this->isInit = true;
         // Discover location of editor plugin.
         $editor_plugin = WIRISpluginWrapper::get_wiris_plugin();
         $this->installed = !empty($editor_plugin);
         // Return if editor plugin is not installed.
         if (!$this->installed) {
             global $COURSE, $PAGE;
             $coursecontext = context_course::instance($COURSE->id);
             if (has_capability('moodle/site:config', $coursecontext)) {
                 // Display missing WIRIS editor plugin dependency error
                 $PAGE->requires->js('/filter/wiris/js/message.js', false);
             }
             return null;
         }
         // Init haxe environment.
         if (!class_exists('com_wiris_system_CallWrapper')) {
             require_once $editor_plugin->path . '/integration/lib/com/wiris/system/CallWrapper.class.php';
         }
         com_wiris_system_CallWrapper::getInstance()->init($editor_plugin->path . '/integration');
         // Start haxe environment.
         $this->begin();
         // Create PluginBuilder with Moodle specific configuration.
         require_once 'MoodleConfigurationUpdater.php';
         $this->moodleConfig = new com_wiris_plugin_configuration_MoodleConfigurationUpdater($editor_plugin);
         $this->instance = com_wiris_plugin_api_PluginBuilder::getInstance();
         $this->instance->addConfigurationUpdater($this->moodleConfig);
         $this->instance->addConfigurationUpdater(new com_wiris_plugin_web_PhpConfigurationUpdater());
         // Stop haxe environment.
         $this->end();
     }
 }
 function view()
 {
     global $USER;
     $context = get_context_instance(CONTEXT_MODULE, $this->cm->id);
     require_capability('mod/assignment:view', $context);
     add_to_log($this->course->id, "assignment-embedded", "view", "view-embedded.php?id={$this->cm->id}", $this->assignment->id, $this->cm->id);
     // $this->view_header();
     echo "<center>";
     $this->view_intro();
     echo "Hands-on exams will be graded within 10 business days. Results will be provided via email. If you do not receive your results within 10 business days of submitting your answer file, please open a ticket with Kaseya University at helpdesk.kaseya.com.";
     echo "</center>";
     $this->view_dates();
     $filecount = $this->count_user_files($USER->id);
     if ($submission = $this->get_submission()) {
         if ($submission->timemarked) {
             $this->view_feedback();
         }
         if ($filecount) {
             print_simple_box($this->print_user_files($USER->id, true), 'center');
         }
     }
     if (has_capability('mod/assignment:submit', $context) && $this->isopen() && (!$filecount || $this->assignment->resubmit || !$submission->timemarked)) {
         $this->view_upload_form();
     }
     // $this->view_footer();
 }
 public function get_children()
 {
     global $DB;
     $children = array();
     if ($child = $this->browser->get_file_info($this->context, 'coursecat_intro', 0)) {
         $children[] = $child;
     }
     $course_cats = $DB->get_records('course_categories', array('parent' => $this->category->id), 'sortorder');
     foreach ($course_cats as $category) {
         $context = get_context_instance(CONTEXT_COURSECAT, $category->id);
         if (!$category->visible and !has_capability('moodle/course:viewhiddencourses', $context)) {
             continue;
         }
         if ($child = $this->browser->get_file_info($context)) {
             $children[] = $child;
         }
     }
     $courses = $DB->get_records('course', array('category' => $this->category->id), 'sortorder');
     foreach ($courses as $course) {
         $context = get_context_instance(CONTEXT_COURSE, $course->id);
         if (!$course->visible and !has_capability('moodle/course:viewhiddencourses', $context)) {
             continue;
         }
         if ($child = $this->browser->get_file_info($context)) {
             $children[] = $child;
         }
     }
     return $children;
 }
Пример #22
0
 /**
  * Returns course details in an array ready to be printed.
  *
  * @global \moodle_database $DB
  * @param \course_in_list $course
  * @return array
  */
 public static function get_course_detail_array(\course_in_list $course)
 {
     global $DB;
     $canaccess = $course->can_access();
     $format = \course_get_format($course->id);
     $modinfo = \get_fast_modinfo($course->id);
     $modules = $modinfo->get_used_module_names();
     $sections = array();
     if ($format->uses_sections()) {
         foreach ($modinfo->get_section_info_all() as $section) {
             if ($section->uservisible) {
                 $sections[] = $format->get_section_name($section);
             }
         }
     }
     $category = \coursecat::get($course->category);
     $categoryurl = new \moodle_url('/course/management.php', array('categoryid' => $course->category));
     $categoryname = $category->get_formatted_name();
     $details = array('fullname' => array('key' => \get_string('fullname'), 'value' => $course->get_formatted_fullname()), 'shortname' => array('key' => \get_string('shortname'), 'value' => $course->get_formatted_shortname()), 'idnumber' => array('key' => \get_string('idnumber'), 'value' => s($course->idnumber)), 'category' => array('key' => \get_string('category'), 'value' => \html_writer::link($categoryurl, $categoryname)));
     if (has_capability('moodle/site:accessallgroups', $course->get_context())) {
         $groups = \groups_get_course_data($course->id);
         $details += array('groupings' => array('key' => \get_string('groupings', 'group'), 'value' => count($groups->groupings)), 'groups' => array('key' => \get_string('groups'), 'value' => count($groups->groups)));
     }
     if ($canaccess) {
         $names = \role_get_names($course->get_context());
         $sql = 'SELECT ra.roleid, COUNT(ra.id) AS rolecount
                   FROM {role_assignments} ra
                  WHERE ra.contextid = :contextid
               GROUP BY ra.roleid';
         $rolecounts = $DB->get_records_sql($sql, array('contextid' => $course->get_context()->id));
         $roledetails = array();
         foreach ($rolecounts as $result) {
             $a = new \stdClass();
             $a->role = $names[$result->roleid]->localname;
             $a->count = $result->rolecount;
             $roledetails[] = \get_string('assignedrolecount', 'moodle', $a);
         }
         $details['roleassignments'] = array('key' => \get_string('roleassignments'), 'value' => join('<br />', $roledetails));
     }
     if ($course->can_review_enrolments()) {
         $enrolmentlines = array();
         $instances = \enrol_get_instances($course->id, true);
         $plugins = \enrol_get_plugins(true);
         foreach ($instances as $instance) {
             if (!isset($plugins[$instance->enrol])) {
                 // Weird.
                 continue;
             }
             $plugin = $plugins[$instance->enrol];
             $enrolmentlines[] = $plugin->get_instance_name($instance);
         }
         $details['enrolmentmethods'] = array('key' => \get_string('enrolmentmethods'), 'value' => join('<br />', $enrolmentlines));
     }
     if ($canaccess) {
         $details['format'] = array('key' => \get_string('format'), 'value' => \course_get_format($course)->get_format_name());
         $details['sections'] = array('key' => \get_string('sections'), 'value' => join('<br />', $sections));
         $details['modulesused'] = array('key' => \get_string('modulesused'), 'value' => join('<br />', $modules));
     }
     return $details;
 }
Пример #23
0
/**
 * Serves assignment submissions and other files.
 *
 * @param mixed $course course or id of the course
 * @param mixed $cm course module or id of the course module
 * @param context $context
 * @param string $filearea
 * @param array $args
 * @param bool $forcedownload
 * @return bool false if file not found, does not return if found - just send the file
 */
function assignsubmission_onlinepoodll_pluginfile($course, $cm, context $context, $filearea, $args, $forcedownload)
{
    global $USER, $DB;
    if ($context->contextlevel != CONTEXT_MODULE) {
        return false;
    }
    require_login($course, false, $cm);
    $itemid = (int) array_shift($args);
    //back image is a special case
    if (!($itemid == 0 && ($filearea = "onlinepoodll_backimage"))) {
        $record = $DB->get_record('assign_submission', array('id' => $itemid), 'userid, assignment', MUST_EXIST);
        $userid = $record->userid;
        if (!($assign = $DB->get_record('assign', array('id' => $cm->instance)))) {
            return false;
        }
        if ($assign->id != $record->assignment) {
            return false;
        }
        // check is users submission or has grading permission
        if ($USER->id != $userid and !has_capability('mod/assign:grade', $context)) {
            return false;
        }
    }
    $relativepath = implode('/', $args);
    $fullpath = "/{$context->id}/assignsubmission_onlinepoodll/{$filearea}/{$itemid}/{$relativepath}";
    $fs = get_file_storage();
    if (!($file = $fs->get_file_by_hash(sha1($fullpath))) or $file->is_directory()) {
        return false;
    }
    send_stored_file($file, 0, 0, true);
    // download MUST be forced - security!
}
Пример #24
0
 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 = get_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));
 }
 public function get_content()
 {
     global $COURSE, $USER;
     if ($this->content !== null) {
         return $this->content;
     }
     $this->content = new stdClass();
     $this->content->text = var_export($this->context, true);
     $coursecontext = context_course::instance($COURSE->id);
     if (has_capability('block/demostudent:addinstance', $coursecontext)) {
         // If DemoStudent has not yet been enrolled, allow user to create/enrol one.
         $demostudentusername = generate_demostudent_name($USER->username);
         $demostudentuser = get_complete_user_data('username', $demostudentusername);
         if (!$demostudentuser || !is_enrolled($coursecontext, $demostudentuser)) {
             $this->render_view('firstuse');
         } else {
             $this->render_view('instructor');
         }
     } else {
         if (has_capability('block/demostudent:seedemostudentblock', $coursecontext)) {
             $this->render_view('demostudent');
         } else {
             // If the user does not need to see the block, do not display it at all.
             $this->content->text = '';
             $this->content->footer = '';
         }
     }
     return $this->content;
 }
Пример #26
0
/**
 * Serves the message attachments. Implements needed access control ;-)
 *
 * @param object $course
 * @param object $cm
 * @param object $context
 * @param string $filearea
 * @param array $args
 * @param bool $forcedownload
 * @return bool false if file not found, does not return if found - justsend the file
 */
function block_jmail_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload)
{
    global $SCRIPT;
    if ($context->contextlevel != CONTEXT_BLOCK) {
        //send_file_not_found();
    }
    require_course_login($course);
    $coursecontext = block_jmail_get_context(CONTEXT_COURSE, $course->id, MUST_EXIST);
    // The mailbox constructor does the permission validation
    if (!($mailbox = new block_jmail_mailbox($course, $coursecontext, $context))) {
        return;
    }
    $messageid = (int) array_shift($args);
    $message = block_jmail_message::get_from_id($messageid);
    // We check if we are the senders or the receivers
    if (!$message) {
        send_file_not_found();
    }
    $pendingaprobal = !$message->approved and has_capability('block/jmail:approvemessages', $context);
    if (!$message->is_mine() and !$pendingaprobal) {
        send_file_not_found();
    }
    $fs = get_file_storage();
    $relativepath = implode('/', $args);
    $fullpath = "/{$context->id}/block_jmail/{$filearea}/{$messageid}/{$relativepath}";
    if (!($file = $fs->get_file_by_hash(sha1($fullpath))) or $file->is_directory()) {
        send_file_not_found();
    }
    $forcedownload = true;
    send_stored_file($file, 60 * 60, 0, $forcedownload);
}
Пример #27
0
 /**
  * Constructor
  *
  * @param array $tagset array of core_tag or stdClass elements, each of them must have attributes:
  *              name, rawname, tagcollid
  *              preferrably also have attributes:
  *              tagtype, count, flag
  * @param int $totalcount total count of tags (for example to indicate that there are more tags than the count of tagset)
  *            leave 0 if count of tagset is the actual count of tags
  * @param int $fromctx context id where this tag cloud is displayed
  * @param int $ctx context id for tag view link
  * @param int $rec recursive argument for tag view link
  */
 public function __construct($tagset, $totalcount = 0, $fromctx = 0, $ctx = 0, $rec = 1)
 {
     $canmanagetags = has_capability('moodle/tag:manage', \context_system::instance());
     $maxcount = 1;
     foreach ($tagset as $tag) {
         if (isset($tag->count) && $tag->count > $maxcount) {
             $maxcount = $tag->count;
         }
     }
     $this->tagset = array();
     foreach ($tagset as $idx => $tag) {
         $this->tagset[$idx] = new stdClass();
         $this->tagset[$idx]->name = core_tag_tag::make_display_name($tag, false);
         if ($canmanagetags && !empty($tag->flag)) {
             $this->tagset[$idx]->flag = 1;
         }
         $viewurl = core_tag_tag::make_url($tag->tagcollid, $tag->rawname, 0, $fromctx, $ctx, $rec);
         $this->tagset[$idx]->viewurl = $viewurl->out(false);
         if (!empty($tag->tagtype)) {
             $this->tagset[$idx]->tagtype = $tag->tagtype;
         }
         if (!empty($tag->count)) {
             $this->tagset[$idx]->count = $tag->count;
             $this->tagset[$idx]->size = (int) ($tag->count / $maxcount * 20);
         }
     }
     $this->totalcount = $totalcount ? $totalcount : count($this->tagset);
 }
 function get_content()
 {
     global $CFG, $DB, $OUTPUT, $COURSE;
     if ($this->content !== null) {
         return $this->content;
     }
     $this->content = new stdClass();
     $this->content->text = '';
     $this->content->footer = '';
     if (empty($this->instance)) {
         return $this->content;
     }
     if (!has_capability('block/course_files_license:viewlist', context_course::instance($COURSE->id))) {
         return $this->content;
     }
     $context = context_course::instance($COURSE->id);
     $contextcheck = $context->path . '/%';
     // Get the top file files used on the course by size.
     $filelist = block_course_files_license_get_coursefilelist();
     if ($filelist) {
         $this->content->text = '<p class="justify">' . get_string('files_to_idenfity', 'block_course_files_license') . '</p>';
         $this->content->text .= '<a class="btn btn-block btn-danger btn-sm" href="';
         $this->content->text .= new moodle_url('/blocks/course_files_license/view.php', array('courseid' => $COURSE->id)) . '">';
         $this->content->text .= '<i class="fa fa-exclamation-triangle"></i> ';
         $this->content->text .= get_string('filelist', 'block_course_files_license') . '</a>';
     } else {
         $this->content->text = '<p class="justify">' . get_string('all_files_idenfitied', 'block_course_files_license') . '</p>';
         $this->content->text = '<a class="btn btn-block btn-success btn-sm" href="';
         $this->content->text .= new moodle_url('/blocks/course_files_license/view.php', array('courseid' => $COURSE->id)) . '">';
         $this->content->text .= '<i class="fa fa-info-circle"></i> ';
         $this->content->text .= get_string('filelist', 'block_course_files_license') . '</a>';
     }
     return $this->content;
 }
 function definition()
 {
     global $CFG;
     $mform =& $this->_form;
     $syscontext = get_context_instance(CONTEXT_SYSTEM);
     $actions = array(0 => get_string('choose') . '...');
     if (has_capability('moodle/user:update', $syscontext)) {
         $actions[1] = get_string('confirm');
     }
     if (has_capability('moodle/site:readallmessages', $syscontext) && !empty($CFG->messaging)) {
         $actions[2] = get_string('messageselectadd');
     }
     if (has_capability('moodle/user:delete', $syscontext)) {
         $actions[3] = get_string('delete');
     }
     $actions[4] = get_string('displayonpage');
     if (has_capability('moodle/user:update', $syscontext)) {
         $actions[5] = get_string('download', 'admin');
     }
     if (has_capability('moodle/user:update', $syscontext)) {
         $actions[6] = get_string('forcepasswordchange');
     }
     if (has_capability('moodle/user:update', $syscontext)) {
         // nadavkav
         $actions[7] = get_string('enrollintocourses', 'user_bulk_actions', '', $CFG->dirroot . '/admin/user/lang/');
     }
     if (has_capability('moodle/site:readallmessages', $syscontext) && !empty($CFG->messaging)) {
         // nadavkav
         $actions[8] = get_string('sendemail', 'user_bulk_actions', '', $CFG->dirroot . '/admin/user/lang/');
     }
     $objs = array();
     $objs[] =& $mform->createElement('select', 'action', null, $actions);
     $objs[] =& $mform->createElement('submit', 'doaction', get_string('choose'));
     $mform->addElement('group', 'actionsgrp', get_string('withselectedusers'), $objs, ' ', false);
 }
Пример #30
0
 /**
  * Definition of the form
  */
 function definition()
 {
     global $USER, $CFG, $COURSE;
     $coursecontext = context_course::instance($COURSE->id);
     $mform =& $this->_form;
     $editoroptions = $this->_customdata['editoroptions'];
     $mform->addElement('header', 'general', get_string('general', 'form'));
     $mform->addElement('text', 'name', get_string('groupname', 'group'), 'maxlength="254" size="50"');
     $mform->addRule('name', get_string('required'), 'required', null, 'client');
     $mform->setType('name', PARAM_TEXT);
     $mform->addElement('text', 'idnumber', get_string('idnumbergroup'), 'maxlength="100" size="10"');
     $mform->addHelpButton('idnumber', 'idnumbergroup');
     $mform->setType('idnumber', PARAM_RAW);
     $mform->setAdvanced('idnumber');
     if (!has_capability('moodle/course:changeidnumber', $coursecontext)) {
         $mform->hardFreeze('idnumber');
     }
     $mform->addElement('editor', 'description_editor', get_string('groupdescription', 'group'), null, $editoroptions);
     $mform->setType('description_editor', PARAM_RAW);
     $mform->addElement('passwordunmask', 'enrolmentkey', get_string('enrolmentkey', 'group'), 'maxlength="254" size="24"', get_string('enrolmentkey', 'group'));
     $mform->addHelpButton('enrolmentkey', 'enrolmentkey', 'group');
     $mform->setType('enrolmentkey', PARAM_RAW);
     if (!empty($CFG->gdversion)) {
         $options = array(get_string('no'), get_string('yes'));
         $mform->addElement('select', 'hidepicture', get_string('hidepicture'), $options);
         $mform->addElement('filepicker', 'imagefile', get_string('newpicture', 'group'));
         $mform->addHelpButton('imagefile', 'newpicture', 'group');
     }
     $mform->addElement('hidden', 'id');
     $mform->setType('id', PARAM_INT);
     $mform->addElement('hidden', 'courseid');
     $mform->setType('courseid', PARAM_INT);
     $this->add_action_buttons();
 }