コード例 #1
0
 /**
  * Test the event.
  */
 public function test_event()
 {
     $this->resetAfterTest();
     $user1 = $this->getDataGenerator()->create_user();
     $context1 = context_user::instance($user1->id);
     $user2 = $this->getDataGenerator()->create_user();
     $context2 = context_user::instance($user2->id);
     $this->setUser($user1);
     // Changing own password.
     $event = \core\event\user_password_updated::create_from_user($user1);
     $this->assertEventContextNotUsed($event);
     $this->assertEquals($user1->id, $event->relateduserid);
     $this->assertSame($context1, $event->get_context());
     $this->assertEventLegacyLogData(null, $event);
     $this->assertFalse($event->other['forgottenreset']);
     $event->trigger();
     // Changing password of other user.
     $event = \core\event\user_password_updated::create_from_user($user2);
     $this->assertEventContextNotUsed($event);
     $this->assertEquals($user2->id, $event->relateduserid);
     $this->assertSame($context2, $event->get_context());
     $this->assertEventLegacyLogData(null, $event);
     $this->assertFalse($event->other['forgottenreset']);
     $event->trigger();
     // Password reset.
     $event = \core\event\user_password_updated::create_from_user($user1, true);
     $this->assertEventContextNotUsed($event);
     $this->assertEquals($user1->id, $event->relateduserid);
     $this->assertSame($context1, $event->get_context());
     $this->assertEventLegacyLogData(array(SITEID, 'user', 'set password', 'profile.php?id=' . $user1->id, $user1->id), $event);
     $this->assertTrue($event->other['forgottenreset']);
     $event->trigger();
 }
コード例 #2
0
ファイル: mod_form.php プロジェクト: JP-Git/moodle
    function validation($data, $files) {
        global $USER;

        if ($errors = parent::validation($data, $files)) {
            return $errors;
        }

        $usercontext = context_user::instance($USER->id);
        $fs = get_file_storage();

        if (!$files = $fs->get_area_files($usercontext->id, 'user', 'draft', $data['package'], 'id', false)) {
            if (!$this->current->instance) {
                $errors['package'] = get_string('required');
                return $errors;
            }
        } else {
            $file = reset($files);
            if ($file->get_mimetype() != 'application/zip') {
                $errors['package'] = get_string('invalidfiletype', 'error', '', $file);
                // better delete current file, it is not usable anyway
                $fs->delete_area_files($usercontext->id, 'user', 'draft', $data['package']);
            }
        }

        return $errors;
    }
コード例 #3
0
    public function get_content() {
    global $CFG,$USER;    
    
    if ($this->content !== null) {
      return $this->content;
    }   
    if(!isloggedin()){
        return $this->content;
    }
    
    $this->content =  new stdClass;
    $systemcontext = context_system::instance();

    $usercontext = context_user::instance($USER->id);
      

    if(has_capability('local/gradeletter:manage', $usercontext) || is_siteadmin() ){		 
    $this->content->text=array();
    $icon = html_writer::empty_tag('img',array('src'=>$CFG->wwwroot.'/pix/i/navigationitem.png'));
    $this->content->text[]=html_writer::tag('a',$icon.get_string('addbatch','block_managebatches'),array('href' =>$CFG->wwwroot.'/local/batches/index.php'));
    //$this->content->text[]=html_writer::empty_tag('br');
    $this->content->text[]=html_writer::tag('a',$icon.get_string('assignbatch','block_managebatches'), array('href' =>$CFG->wwwroot.'/local/batches/bulk_enroll.php?mode=new'));
    //$this->content->text[]=html_writer::empty_tag('br');
    $this->content->text[]=html_writer::tag('a',$icon.get_string('enrolbatch','block_managebatches'), array('href' => $CFG->wwwroot.'/local/batches/bulk_enroll.php?mode=exists')); 
    //$this->content->text[]=html_writer::empty_tag('br');
 //   $this->content->text[]=html_writer::tag('a',$icon.get_string('reports','block_managebatches') , array('href' => $CFG->wwwroot.'/admin/index.php?cache=1')); 
    
    $this->content->text=implode('',$this->content->text);
     return $this->content;
    }    
    
    else
     return $this->content;    
   
  }
コード例 #4
0
ファイル: lib.php プロジェクト: evltuma/moodle
/**
 * Sends the parameters to JS module.
 *
 * @return array
 */
function atto_managefiles_params_for_js($elementid, $options, $fpoptions)
{
    global $CFG, $USER;
    require_once $CFG->dirroot . '/repository/lib.php';
    // Load constants.
    // Disabled if:
    // - Not logged in or guest.
    // - Files are not allowed.
    // - Only URL are supported.
    $disabled = !isloggedin() || isguestuser() || (!isset($options['maxfiles']) || $options['maxfiles'] == 0) || isset($options['return_types']) && !($options['return_types'] & ~FILE_EXTERNAL);
    $params = array('disabled' => $disabled, 'area' => array(), 'usercontext' => null);
    if (!$disabled) {
        $params['usercontext'] = context_user::instance($USER->id)->id;
        foreach (array('itemid', 'context', 'areamaxbytes', 'maxbytes', 'subdirs', 'return_types') as $key) {
            if (isset($options[$key])) {
                if ($key === 'context' && is_object($options[$key])) {
                    // Just context id is enough.
                    $params['area'][$key] = $options[$key]->id;
                } else {
                    $params['area'][$key] = $options[$key];
                }
            }
        }
    }
    return $params;
}
コード例 #5
0
/**
 * Return the js params required for this module.
 * @return array of additional params to pass to javascript init function for this module.
 */
function atto_panoptobutton_params_for_js($elementid, $options, $fpoptions)
{
    global $USER, $COURSE, $DB;
    //coursecontext
    $coursecontext = context_course::instance($COURSE->id);
    //Gets Panopto folder ID and for course from database on the server to which the course was provisioned.
    //If the course has not been provisioned, this will not return a value and the user will be able to select
    //folders and videos from the server specified as default during the plugin setup.
    $panoptoid = $DB->get_field('block_panopto_foldermap', 'panopto_id', array('moodleid' => $coursecontext->instanceid));
    $servername = $DB->get_field('block_panopto_foldermap', 'panopto_server', array('moodleid' => $coursecontext->instanceid));
    //usercontextid
    $usercontextid = context_user::instance($USER->id)->id;
    $disabled = false;
    //config array
    $params = array();
    $params['usercontextid'] = $usercontextid;
    $params['coursecontext'] = $panoptoid;
    $params['servename'] = $servername;
    //If they don't have permission don't show it
    if (!has_capability('atto/panoptobutton:visible', $coursecontext)) {
        $disabled = true;
    }
    //add disabled param
    $params['disabled'] = $disabled;
    //add our default server
    $params['defaultserver'] = get_config('atto_panoptobutton', 'defaultserver');
    return $params;
}
コード例 #6
0
ファイル: base_message.php プロジェクト: evltuma/moodle
 /**
  * Returns the document associated with this message record.
  *
  * @param stdClass $record
  * @param array    $options
  * @return \core_search\document
  */
 public function get_document($record, $options = array())
 {
     try {
         $usercontext = \context_user::instance($options['user1id']);
     } catch (\moodle_exception $ex) {
         // Notify it as we run here as admin, we should see everything.
         debugging('Error retrieving ' . $this->areaid . ' ' . $record->id . ' document, not all required data is available: ' . $ex->getMessage(), DEBUG_DEVELOPER);
         return false;
     }
     // Prepare associative array with data from DB.
     $doc = \core_search\document_factory::instance($record->id, $this->componentname, $this->areaname);
     $doc->set('title', content_to_text($record->subject, false));
     $doc->set('itemid', $record->id);
     $doc->set('content', content_to_text($record->smallmessage, false));
     $doc->set('contextid', $usercontext->id);
     $doc->set('courseid', SITEID);
     $doc->set('owneruserid', $options['user1id']);
     $doc->set('userid', $options['user2id']);
     $doc->set('modified', $record->timecreated);
     // Check if this document should be considered new.
     if (isset($options['lastindexedtime']) && $options['lastindexedtime'] < $record->timecreated) {
         // If the document was created after the last index time, it must be new.
         $doc->set_is_new(true);
     }
     return $doc;
 }
コード例 #7
0
/**
 * Return the js params required for this module.
 * @return array of additional params to pass to javascript init function for this module.
 */
function atto_streamings_params_for_js($elementid, $options, $fpoptions)
{
    global $USER, $COURSE;
    //coursecontext
    $coursecontext = context_course::instance($COURSE->id);
    //usercontextid
    $usercontextid = context_user::instance($USER->id)->id;
    $disabled = false;
    //config our array of data
    $params = array();
    $params['usercontextid'] = $usercontextid;
    //If they don't have permission don't show it
    if (!has_capability('atto/streamings:visible', $coursecontext)) {
        $disabled = true;
    }
    //add our disabled param
    $params['disabled'] = $disabled;
    //add our default video
    $params['defaultvideo'] = get_config('atto_streamings', 'defaultvideo');
    //add our default rtmp
    $params['defaultrtmp'] = get_config('atto_streamings', 'defaultrtmp');
    //add our default playlist
    $params['defaultplaylist'] = get_config('atto_streamings', 'defaultplaylist');
    //add our default web
    $params['defaultweb'] = get_config('atto_streamings', 'defaultweb');
    //add our default image
    $params['defaultimage'] = get_config('atto_streamings', 'defaultimage');
    return $params;
}
コード例 #8
0
 function get_content()
 {
     global $CFG, $USER;
     if ($this->content !== NULL) {
         return $this->content;
     }
     if (!isloggedin()) {
         return $this->content;
     }
     if (is_siteadmin()) {
         return $this->content;
     }
     //this block is for students
     $usercontext = context_user::instance($USER->id);
     if (!has_capability('local/clclasses:enrollclass', $usercontext)) {
         return $this->content;
     }
     // Prep the content
     $this->content = new stdClass();
     require_once 'academic_status.php';
     //$id=optional_param('id',5,PARAM_INT);
     $events = get_semslist();
     $this->content->text = $events;
     return $this->content;
     // Prepare the footer for this block
     // No footer to display
     $this->content->footer = '';
     // Return the content object
     return $this->content;
 }
コード例 #9
0
 public function test_create_instance()
 {
     global $DB, $CFG, $USER;
     $this->resetAfterTest();
     $this->setAdminUser();
     $course = $this->getDataGenerator()->create_course();
     $this->assertFalse($DB->record_exists('imscp', array('course' => $course->id)));
     $imscp = $this->getDataGenerator()->create_module('imscp', array('course' => $course));
     $records = $DB->get_records('imscp', array('course' => $course->id), 'id');
     $this->assertEquals(1, count($records));
     $this->assertTrue(array_key_exists($imscp->id, $records));
     $params = array('course' => $course->id, 'name' => 'Another imscp');
     $imscp = $this->getDataGenerator()->create_module('imscp', $params);
     $records = $DB->get_records('imscp', array('course' => $course->id), 'id');
     $this->assertEquals(2, count($records));
     $this->assertEquals('Another imscp', $records[$imscp->id]->name);
     // Examples of specifying the package file (do not validate anything, just check for exceptions).
     // 1. As path to the file in filesystem:
     $params = array('course' => $course->id, 'packagepath' => $CFG->dirroot . '/mod/imscp/tests/packages/singlescobasic.zip');
     $imscp = $this->getDataGenerator()->create_module('imscp', $params);
     // 2. As file draft area id:
     $fs = get_file_storage();
     $params = array('course' => $course->id, 'package' => file_get_unused_draft_itemid());
     $usercontext = context_user::instance($USER->id);
     $filerecord = array('component' => 'user', 'filearea' => 'draft', 'contextid' => $usercontext->id, 'itemid' => $params['package'], 'filename' => 'singlescobasic.zip', 'filepath' => '/');
     $fs->create_file_from_pathname($filerecord, $CFG->dirroot . '/mod/imscp/tests/packages/singlescobasic.zip');
     $imscp = $this->getDataGenerator()->create_module('imscp', $params);
 }
コード例 #10
0
ファイル: lib.php プロジェクト: evltuma/moodle
/**
 * Add nodes to myprofile page.
 *
 * @param \core_user\output\myprofile\tree $tree Tree object
 * @param stdClass $user user object
 * @param bool $iscurrentuser
 * @param stdClass $course Course object
 *
 * @return bool
 */
function core_badges_myprofile_navigation(\core_user\output\myprofile\tree $tree, $user, $iscurrentuser, $course)
{
    global $CFG, $PAGE, $USER, $SITE;
    require_once $CFG->dirroot . '/badges/renderer.php';
    if (empty($CFG->enablebadges) || !empty($course) && empty($CFG->badges_allowcoursebadges)) {
        // Y U NO LIKE BADGES ?
        return true;
    }
    // Add category. This node should appear after 'contact' so that administration block appears towards the end. Refer MDL-49928.
    $category = new core_user\output\myprofile\category('badges', get_string('badges', 'badges'), 'contact');
    $tree->add_category($category);
    $context = context_user::instance($user->id);
    $courseid = empty($course) ? 0 : $course->id;
    if ($USER->id == $user->id || has_capability('moodle/badges:viewotherbadges', $context)) {
        $records = badges_get_user_badges($user->id, $courseid, null, null, null, true);
        $renderer = new core_badges_renderer($PAGE, '');
        // Local badges.
        if ($records) {
            $title = get_string('localbadgesp', 'badges', format_string($SITE->fullname));
            $content = $renderer->print_badges_list($records, $user->id, true);
            $localnode = $mybadges = new core_user\output\myprofile\node('badges', 'localbadges', $title, null, null, $content);
            $tree->add_node($localnode);
        }
        // External badges.
        if ($courseid == 0 && !empty($CFG->badges_allowexternalbackpack)) {
            $backpack = get_backpack_settings($user->id);
            if (isset($backpack->totalbadges) && $backpack->totalbadges !== 0) {
                $title = get_string('externalbadgesp', 'badges');
                $content = $renderer->print_badges_list($backpack->badges, $user->id, true, true);
                $externalnode = $mybadges = new core_user\output\myprofile\node('badges', 'externalbadges', $title, null, null, $content);
                $tree->add_node($externalnode);
            }
        }
    }
}
コード例 #11
0
function xmldb_local_lae_upgrade($oldversion)
{
    global $CFG, $DB;
    $dbman = $DB->get_manager();
    if ($oldversion < 2013061200) {
        // Update course table to support display defaults
        $table = new xmldb_table('course');
        $field = new xmldb_field('filedisplaydefault', XMLDB_TYPE_INTEGER, '2', null, null, null, null, null);
        if (!$dbman->field_exists($table, $field)) {
            $dbman->add_field($table, $field);
        }
        upgrade_plugin_savepoint(true, 2013061200, 'local', 'lae');
    }
    if ($oldversion < 2014010900) {
        // Add mnethostid and email address to Anonymous User.
        $user = $DB->get_record('user', array('id' => $CFG->anonymous_userid));
        if (empty($user->email)) {
            $user->email = get_string('auser_email', 'local_lae');
        }
        $user->mnethostid = $CFG->mnet_localhost_id;
        $DB->update_record('user', $user);
        upgrade_plugin_savepoint(true, 2014010900, 'local', 'lae');
    }
    if ($oldversion < 2014041600) {
        // Set context for Anonymous User.
        $user = $DB->get_record('user', array('id' => $CFG->anonymous_userid));
        context_user::instance($user->id);
        upgrade_plugin_savepoint(true, 2014041600, 'local', 'lae');
    }
}
コード例 #12
0
ファイル: renderer.php プロジェクト: JP-Git/moodle
 public function __construct()
 {
     global $USER;
     $this->context = context_user::instance($USER->id);
     $fs = get_file_storage();
     $this->dir = $fs->get_area_tree($this->context->id, 'user', 'private', 0);
 }
コード例 #13
0
ファイル: class_delete.class.php プロジェクト: jamesmcq/elis
 /**
  * Performs class deletion
  * @throws moodle_exception If there was an error in passed parameters.
  * @throws data_object_exception If there was an error deleting the entity.
  * @param array $data The incoming data parameter.
  * @return array An array of parameters, if successful.
  */
 public static function class_delete(array $data)
 {
     global $USER, $DB;
     if (static::require_elis_dependencies() !== true) {
         throw new moodle_exception('ws_function_requires_elis', 'local_datahub');
     }
     // Parameter validation.
     $params = self::validate_parameters(self::class_delete_parameters(), array('data' => $data));
     // Context validation.
     $context = context_user::instance($USER->id);
     self::validate_context($context);
     // Initialize version1elis importplugin for utility functions.
     $importplugin = rlip_dataplugin_factory::factory('dhimport_version1elis');
     // Get the class.
     $clsid = $DB->get_field(pmclass::TABLE, 'id', array('idnumber' => $data['idnumber']));
     if (empty($clsid)) {
         throw new data_object_exception('ws_class_delete_fail_invalid_idnumber', 'local_datahub', '', $data);
     }
     // Capability checking.
     require_capability('local/elisprogram:class_delete', \local_elisprogram\context\pmclass::instance($clsid));
     // Delete the class.
     $pmclass = new pmclass($clsid);
     $pmclass->delete();
     // Verify class deleted & respond.
     if (!$DB->record_exists(pmclass::TABLE, array('id' => $clsid))) {
         return array('messagecode' => get_string('ws_class_delete_success_code', 'local_datahub'), 'message' => get_string('ws_class_delete_success_msg', 'local_datahub'));
     } else {
         throw new data_object_exception('ws_class_delete_fail', 'local_datahub');
     }
 }
コード例 #14
0
ファイル: upgradelib_test.php プロジェクト: rushi963/moodle
 public function test_upgrade_fix_missing_root_folders_draft()
 {
     global $DB, $SITE;
     $this->resetAfterTest(true);
     $user = $this->getDataGenerator()->create_user();
     $usercontext = context_user::instance($user->id);
     $this->setUser($user);
     $resource1 = $this->getDataGenerator()->get_plugin_generator('mod_resource')->create_instance(array('course' => $SITE->id));
     $context = context_module::instance($resource1->cmid);
     $draftitemid = 0;
     file_prepare_draft_area($draftitemid, $context->id, 'mod_resource', 'content', 0);
     $queryparams = array('component' => 'user', 'contextid' => $usercontext->id, 'filearea' => 'draft', 'itemid' => $draftitemid);
     // Make sure there are two records in files for the draft file area and one of them has filename '.'.
     $records = $DB->get_records_menu('files', $queryparams, '', 'id, filename');
     $this->assertEquals(2, count($records));
     $this->assertTrue(in_array('.', $records));
     $originalhash = $DB->get_field('files', 'pathnamehash', $queryparams + array('filename' => '.'));
     // Delete record with filename '.' and make sure it does not exist any more.
     $DB->delete_records('files', $queryparams + array('filename' => '.'));
     $records = $DB->get_records_menu('files', $queryparams, '', 'id, filename');
     $this->assertEquals(1, count($records));
     $this->assertFalse(in_array('.', $records));
     // Run upgrade script and make sure the record is restored.
     upgrade_fix_missing_root_folders_draft();
     $records = $DB->get_records_menu('files', $queryparams, '', 'id, filename');
     $this->assertEquals(2, count($records));
     $this->assertTrue(in_array('.', $records));
     $newhash = $DB->get_field('files', 'pathnamehash', $queryparams + array('filename' => '.'));
     $this->assertEquals($originalhash, $newhash);
 }
コード例 #15
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;
}
コード例 #16
0
 /**
  * Generates the message object for a give subscription and event.
  *
  * @param int $subscriptionid Subscription instance
  * @param \stdClass $eventobj Event data
  *
  * @return false|\stdClass message object
  */
 protected function generate_message($subscriptionid, \stdClass $eventobj)
 {
     try {
         $subscription = subscription_manager::get_subscription($subscriptionid);
     } catch (\dml_exception $e) {
         // Race condition, someone deleted the subscription.
         return false;
     }
     $user = \core_user::get_user($subscription->userid);
     $context = \context_user::instance($user->id, IGNORE_MISSING);
     if ($context === false) {
         // User context doesn't exist. Should never happen, nothing to do return.
         return false;
     }
     $template = $subscription->template;
     $template = $this->replace_placeholders($template, $subscription, $eventobj, $context);
     $msgdata = new \stdClass();
     $msgdata->component = 'tool_monitor';
     // Your component name.
     $msgdata->name = 'notification';
     // This is the message name from messages.php.
     $msgdata->userfrom = \core_user::get_noreply_user();
     $msgdata->userto = $user;
     $msgdata->subject = $subscription->get_name($context);
     $msgdata->fullmessage = format_text($template, $subscription->templateformat, array('context' => $context));
     $msgdata->fullmessageformat = $subscription->templateformat;
     $msgdata->fullmessagehtml = format_text($template, $subscription->templateformat, array('context' => $context));
     $msgdata->smallmessage = '';
     $msgdata->notification = 1;
     // This is only set to 0 for personal messages between users.
     return $msgdata;
 }
コード例 #17
0
 /**
  * Performs program delete
  * @throws moodle_exception If there was an error in passed parameters.
  * @throws data_object_exception If there was an error creating the entity.
  * @param array $data The incoming data parameter.
  * @return array An array of parameters, if successful.
  */
 public static function program_delete(array $data)
 {
     global $USER, $DB;
     if (static::require_elis_dependencies() !== true) {
         throw new moodle_exception('ws_function_requires_elis', 'local_datahub');
     }
     // Parameter validation.
     $params = self::validate_parameters(self::program_delete_parameters(), array('data' => $data));
     // Context validation.
     $context = context_user::instance($USER->id);
     self::validate_context($context);
     $data = (object) $data;
     // Validate program exists
     if (!($curid = $DB->get_field(curriculum::TABLE, 'id', array('idnumber' => $data->idnumber)))) {
         throw new data_object_exception('ws_program_delete_fail_invalid_idnumber', 'local_datahub', '', $data);
     }
     // Capability checking.
     require_capability('local/elisprogram:program_delete', \local_elisprogram\context\program::instance($curid));
     $prg = new curriculum($curid);
     $prg->delete();
     // Confirm delete & respond.
     if (!$DB->record_exists(curriculum::TABLE, array('id' => $curid))) {
         return array('messagecode' => get_string('ws_program_delete_success_code', 'local_datahub'), 'message' => get_string('ws_program_delete_success_msg', 'local_datahub'));
     } else {
         throw new data_object_exception('ws_program_delete_fail', 'local_datahub');
     }
 }
コード例 #18
0
/**
 * Suspend the old user, by suspending its account, and updating the profile picture
 * to a generic one.
 * @param object $event stdClass with all event data.
 * @global moodle_database $DB
 */
function tool_mergeusers_old_user_suspend($event)
{
    global $DB, $CFG;
    if ($CFG->branch < 26) {
        $oldid = $event->oldid;
    } else {
        $oldid = $event->other['usersinvolved']['fromid'];
    }
    // Check configuration to see if the old user gets suspended
    $enabled = (int) get_config('tool_mergeusers', 'suspenduser');
    if ($enabled !== 1) {
        return true;
    }
    // 1. update auth type
    $olduser = new stdClass();
    $olduser->id = $oldid;
    $olduser->suspended = 1;
    $olduser->timemodified = time();
    $DB->update_record('user', $olduser);
    // 2. update profile picture
    // get source, common image
    $fullpath = dirname(dirname(__DIR__)) . "/pix/suspended.jpg";
    if (!file_exists($fullpath)) {
        return;
        //do nothing; aborting, given that the image does not exist
    }
    // put the common image as the profile picture.
    $context = context_user::instance($oldid);
    if ($newrev = process_new_icon($context, 'user', 'icon', 0, $fullpath)) {
        $DB->set_field('user', 'picture', $newrev, array('id' => $oldid));
    }
    return true;
}
コード例 #19
0
/**
 * Is current user allowed to access this report
 *
 * @access private defined in lib.php for performance reasons
 * @global stdClass $USER
 * @param stdClass $user
 * @param stdClass $course
 * @return array with two elements $all, $today
 */
function report_courselog_can_access_user_report($user, $course)
{
    global $USER;
    $coursecontext = context_course::instance($course->id);
    $personalcontext = context_user::instance($user->id);
    $today = false;
    $all = false;
    if (has_capability('report/log:view', $coursecontext)) {
        $today = true;
    }
    if (has_capability('report/log:viewtoday', $coursecontext)) {
        $all = true;
    }
    if ($today and $all) {
        return array(true, true);
    }
    if (has_capability('moodle/user:viewuseractivitiesreport', $personalcontext)) {
        if ($course->showreports and (is_viewing($coursecontext, $user) or is_enrolled($coursecontext, $user))) {
            return array(true, true);
        }
    } else {
        if ($user->id == $USER->id) {
            if ($course->showreports and (is_viewing($coursecontext, $USER) or is_enrolled($coursecontext, $USER))) {
                return array(true, true);
            }
        }
    }
    return array($all, $today);
}
コード例 #20
0
 /**
  * Performs userset delete
  * @throws moodle_exception If there was an error in passed parameters.
  * @throws data_object_exception If there was an error creating the entity.
  * @param array $data The incoming data parameter.
  * @return array An array of parameters, if successful.
  */
 public static function userset_delete(array $data)
 {
     global $USER, $DB;
     if (static::require_elis_dependencies() !== true) {
         throw new moodle_exception('ws_function_requires_elis', 'local_datahub');
     }
     // Parameter validation.
     $params = self::validate_parameters(self::userset_delete_parameters(), array('data' => $data));
     // Context validation.
     $context = context_user::instance($USER->id);
     self::validate_context($context);
     $data = (object) $data;
     // Validate
     if (empty($data->name) || !($usid = $DB->get_field(userset::TABLE, 'id', array('name' => $data->name)))) {
         throw new data_object_exception('ws_userset_delete_fail_invalid_name', 'local_datahub', '', $data);
     }
     // Capability checking.
     require_capability('local/elisprogram:userset_delete', \local_elisprogram\context\userset::instance($usid));
     $userset = new userset($usid);
     if (!empty($data->recursive)) {
         $userset->deletesubs = true;
     }
     $userset->delete();
     // Verify deletion & respond.
     if (!$DB->record_exists(userset::TABLE, array('name' => $data->name))) {
         return array('messagecode' => get_string('ws_userset_delete_success_code', 'local_datahub', empty($data->recursive) ? '' : get_string('ws_userset_delete_recursive', 'local_datahub')), 'message' => get_string('ws_userset_delete_success_msg', 'local_datahub', empty($data->recursive) ? '' : get_string('ws_userset_delete_subsets', 'local_datahub')));
     } else {
         throw new data_object_exception('ws_userset_delete_fail', 'local_datahub');
     }
 }
コード例 #21
0
ファイル: lib.php プロジェクト: covex-nn/moodle
 /**
  * Adjusts TinyMCE init parameters for tinymce_managefiles
  *
  * Adds file area restrictions parameters and actual 'managefiles' button
  *
  * @param array $params TinyMCE init parameters array
  * @param context $context Context where editor is being shown
  * @param array $options Options for this editor
  */
 protected function update_init_params(array &$params, context $context, array $options = null)
 {
     global $USER;
     // Add parameters for filemanager
     $params['managefiles'] = array('usercontext' => context_user::instance($USER->id)->id);
     foreach (array('itemid', 'context', 'areamaxbytes', 'maxbytes', 'subdirs', 'return_types') as $key) {
         if (isset($options[$key])) {
             if ($key === 'context' && is_object($options[$key])) {
                 // Just context id is enough
                 $params['managefiles'][$key] = $options[$key]->id;
             } else {
                 $params['managefiles'][$key] = $options[$key];
             }
         }
     }
     if ($row = $this->find_button($params, 'moodlemedia')) {
         // Add button after 'moodlemedia' button.
         $this->add_button_after($params, $row, 'managefiles', 'moodlemedia');
     } else {
         if ($row = $this->find_button($params, 'image')) {
             // If 'moodlemedia' is not found add after 'image'.
             $this->add_button_after($params, $row, 'managefiles', 'image');
         } else {
             // OTherwise add button in the end of the last row.
             $this->add_button_after($params, $this->count_button_rows($params), 'managefiles');
         }
     }
     // Add JS file, which uses default name.
     $this->add_js_plugin($params);
 }
コード例 #22
0
 /**
  * Create event for user password changing and resetting.
  *
  * @param \stdClass $user
  * @param bool $forgottenreset true if reset via recovery link
  * @return user_password_updated
  */
 public static function create_from_user(\stdClass $user, $forgottenreset = false)
 {
     $data = array('context' => \context_user::instance($user->id), 'relateduserid' => $user->id, 'other' => array('forgottenreset' => $forgottenreset));
     $event = self::create($data);
     $event->add_record_snapshot('user', $user);
     return $event;
 }
コード例 #23
0
ファイル: import_form.php プロジェクト: evltuma/moodle
 function validation($data, $files)
 {
     global $USER;
     if ($errors = parent::validation($data, $files)) {
         return $errors;
     }
     $usercontext = context_user::instance($USER->id);
     $fs = get_file_storage();
     if (!($files = $fs->get_area_files($usercontext->id, 'user', 'draft', $data['importfile'], 'id', false))) {
         $errors['importfile'] = get_string('required');
         return $errors;
     } else {
         $file = reset($files);
         if ($file->get_mimetype() != 'application/zip') {
             $errors['importfile'] = get_string('invalidfiletype', 'error', $file->get_filename());
             // better delete current file, it is not usable anyway
             $fs->delete_area_files($usercontext->id, 'user', 'draft', $data['importfile']);
         } else {
             if (!($chpterfiles = toolbook_importhtml_get_chapter_files($file, $data['type']))) {
                 $errors['importfile'] = get_string('errornochapters', 'booktool_importhtml');
             }
         }
     }
     return $errors;
 }
コード例 #24
0
ファイル: lib.php プロジェクト: EmmanuelYupit/educursos
 public function create_instance($record = null, array $options = null)
 {
     global $CFG, $USER;
     require_once $CFG->dirroot . '/mod/scorm/lib.php';
     require_once $CFG->dirroot . '/mod/scorm/locallib.php';
     $cfgscorm = get_config('scorm');
     // Add default values for scorm.
     $record = (array) $record + array('scormtype' => SCORM_TYPE_LOCAL, 'packagefile' => '', 'packagefilepath' => $CFG->dirroot . '/mod/scorm/tests/packages/singlescobasic.zip', 'packageurl' => '', 'updatefreq' => SCORM_UPDATE_NEVER, 'popup' => 0, 'width' => $cfgscorm->framewidth, 'height' => $cfgscorm->frameheight, 'skipview' => $cfgscorm->skipview, 'hidebrowse' => $cfgscorm->hidebrowse, 'displaycoursestructure' => $cfgscorm->displaycoursestructure, 'hidetoc' => $cfgscorm->hidetoc, 'nav' => $cfgscorm->nav, 'navpositionleft' => $cfgscorm->navpositionleft, 'navpositiontop' => $cfgscorm->navpositiontop, 'displayattemptstatus' => $cfgscorm->displayattemptstatus, 'timeopen' => 0, 'timeclose' => 0, 'grademethod' => GRADESCOES, 'maxgrade' => $cfgscorm->maxgrade, 'maxattempt' => $cfgscorm->maxattempt, 'whatgrade' => $cfgscorm->whatgrade, 'forcenewattempt' => $cfgscorm->forcenewattempt, 'lastattemptlock' => $cfgscorm->lastattemptlock, 'forcecompleted' => $cfgscorm->forcecompleted, 'auto' => $cfgscorm->auto);
     // The 'packagefile' value corresponds to the draft file area ID. If not specified, create from packagefilepath.
     if (empty($record['packagefile']) && $record['scormtype'] === SCORM_TYPE_LOCAL) {
         if (!isloggedin() || isguestuser()) {
             throw new coding_exception('Scorm generator requires a current user');
         }
         if (!file_exists($record['packagefilepath'])) {
             throw new coding_exception("File {$record['packagefilepath']} does not exist");
         }
         $usercontext = context_user::instance($USER->id);
         // Pick a random context id for specified user.
         $record['packagefile'] = file_get_unused_draft_itemid();
         // Add actual file there.
         $filerecord = array('component' => 'user', 'filearea' => 'draft', 'contextid' => $usercontext->id, 'itemid' => $record['packagefile'], 'filename' => basename($record['packagefilepath']), 'filepath' => '/');
         $fs = get_file_storage();
         $fs->create_file_from_pathname($filerecord, $record['packagefilepath']);
     }
     return parent::create_instance($record, (array) $options);
 }
コード例 #25
0
ファイル: edit_form.php プロジェクト: EmmanuelYupit/educursos
 function definition_after_data()
 {
     global $CFG, $DB, $OUTPUT;
     $mform =& $this->_form;
     $userid = $mform->getElementValue('id');
     // if language does not exist, use site default lang
     if ($langsel = $mform->getElementValue('lang')) {
         $lang = reset($langsel);
         // check lang exists
         if (!get_string_manager()->translation_exists($lang, false)) {
             $lang_el =& $mform->getElement('lang');
             $lang_el->setValue($CFG->lang);
         }
     }
     if ($user = $DB->get_record('user', array('id' => $userid))) {
         // remove description
         if (empty($user->description) && !empty($CFG->profilesforenrolledusersonly) && !$DB->record_exists('role_assignments', array('userid' => $userid))) {
             $mform->removeElement('description_editor');
         }
         // print picture
         $context = context_user::instance($user->id, MUST_EXIST);
         $fs = get_file_storage();
         $hasuploadedpicture = $fs->file_exists($context->id, 'user', 'icon', 0, '/', 'f2.png') || $fs->file_exists($context->id, 'user', 'icon', 0, '/', 'f2.jpg');
         if (!empty($user->picture) && $hasuploadedpicture) {
             $imagevalue = $OUTPUT->user_picture($user, array('courseid' => SITEID, 'size' => 64));
         } else {
             $imagevalue = get_string('none');
         }
         $imageelement = $mform->getElement('currentpicture');
         $imageelement->setValue($imagevalue);
         if ($mform->elementExists('deletepicture') && !$hasuploadedpicture) {
             $mform->removeElement('deletepicture');
         }
         /// disable fields that are locked by auth plugins
         $fields = get_user_fieldnames();
         $authplugin = get_auth_plugin($user->auth);
         foreach ($fields as $field) {
             if (!$mform->elementExists($field)) {
                 continue;
             }
             $configvariable = 'field_lock_' . $field;
             if (isset($authplugin->config->{$configvariable})) {
                 if ($authplugin->config->{$configvariable} === 'locked') {
                     $mform->hardFreeze($field);
                     $mform->setConstant($field, $user->{$field});
                 } else {
                     if ($authplugin->config->{$configvariable} === 'unlockedifempty' and $user->{$field} != '') {
                         $mform->hardFreeze($field);
                         $mform->setConstant($field, $user->{$field});
                     }
                 }
             }
         }
         /// Next the customisable profile fields
         profile_definition_after_data($mform, $user->id);
     } else {
         profile_definition_after_data($mform, 0);
     }
 }
コード例 #26
0
 /**
  * Process a message received and validated by the Inbound Message processor.
  *
  * @throws \core\message\inbound\processing_failed_exception
  * @param \stdClass $record The Inbound Message record
  * @param \stdClass $data The message data packet
  * @return bool Whether the message was successfully processed.
  */
 public function process_message(\stdClass $record, \stdClass $data)
 {
     global $USER, $CFG;
     $context = \context_user::instance($USER->id);
     if (!has_capability('moodle/user:manageownfiles', $context)) {
         throw new \core\message\inbound\processing_failed_exception('emailtoprivatefilesdenied', 'moodle', $data);
     }
     // Initial setup.
     $component = 'user';
     $filearea = 'private';
     $itemid = 0;
     $license = $CFG->sitedefaultlicense;
     $author = fullname($USER);
     // Determine the quota space for this user.
     $maxbytes = $CFG->userquota;
     if (has_capability('moodle/user:ignoreuserquota', $context)) {
         $maxbytes = USER_CAN_IGNORE_FILE_SIZE_LIMITS;
     }
     // Keep track of files which were uploaded, and which were skipped.
     $skippedfiles = array();
     $uploadedfiles = array();
     $failedfiles = array();
     $fs = get_file_storage();
     foreach ($data->attachments as $attachmenttype => $attachments) {
         foreach ($attachments as $attachment) {
             mtrace("--- Processing attachment '{$attachment->filename}'");
             if (file_is_draft_area_limit_reached($itemid, $maxbytes, $attachment->filesize)) {
                 // The user quota will be exceeded if this file is included.
                 $skippedfiles[] = $attachment;
                 mtrace("---- Skipping attacment. User will be over quota.");
                 continue;
             }
             // Create a new record for this file.
             $record = new \stdClass();
             $record->filearea = $filearea;
             $record->component = $component;
             $record->filepath = '/';
             $record->itemid = $itemid;
             $record->license = $license;
             $record->author = $author;
             $record->contextid = $context->id;
             $record->userid = $USER->id;
             $record->filename = $fs->get_unused_filename($context->id, $record->component, $record->filearea, $record->itemid, $record->filepath, $attachment->filename);
             mtrace("--> Attaching {$record->filename} to " . "/{$record->contextid}/{$record->component}/{$record->filearea}/" . "{$record->itemid}{$record->filepath}{$record->filename}");
             if ($fs->create_file_from_string($record, $attachment->content)) {
                 // File created successfully.
                 mtrace("---- File uploaded successfully as {$record->filename}.");
                 $uploadedfiles[] = $attachment;
             } else {
                 mtrace("---- Skipping attacment. Unknown failure during creation.");
                 $failedfiles[] = $attachment;
             }
         }
     }
     // TODO send the user a confirmation e-mail.
     // Note, some files may have failed because the user has been pushed over quota. This does not constitute a failure.
     return true;
 }
コード例 #27
0
/**
 * This function extends the navigation with the report items
 *
 * @param navigation_node $navigation The navigation node to extend
 * @param stdClass $course The course to object for the report
 * @param stdClass $context The context of the course
 */
function report_teacherreport_extend_navigation_user($navigation, $user, $course)
{
    global $CFG, $DB, $PAGE, $USER;
    $context = context_user::instance($USER->id);
    if (has_capability('report/teacherreport:view', $context)) {
        $url = new moodle_url('/report/teacherreport/index.php', array('userid' => $USER->id));
        $navigation->add(get_string('pluginname', 'report_teacherreport'), $url, navigation_node::TYPE_SETTING, null, null, null);
    }
}
コード例 #28
0
 /**
  * Returns an XHTML string for the editor
  *
  * @param string $data
  * @param string $query
  * @return string XHTML string for the editor
  */
 public function output_html($data, $query = '')
 {
     global $USER;
     $default = $this->get_defaultsetting();
     $defaultinfo = $default;
     if (!is_null($default) and $default !== '') {
         $defaultinfo = "\n" . $default;
     }
     $ctx = context_user::instance($USER->id);
     $editor = editors_get_preferred_editor(FORMAT_HTML);
     $options = $this->get_options();
     $draftitemid = file_get_unused_draft_itemid();
     $component = is_null($this->plugin) ? 'core' : $this->plugin;
     $data = file_prepare_draft_area($draftitemid, $options['context']->id, $component, $this->get_full_name() . '_draftitemid', $draftitemid, $options, $data);
     $fpoptions = array();
     $args = new stdClass();
     // need these three to filter repositories list
     $args->accepted_types = array('web_image');
     $args->return_types = $options['return_types'];
     $args->context = $ctx;
     $args->env = 'filepicker';
     // advimage plugin
     $image_options = initialise_filepicker($args);
     $image_options->context = $ctx;
     $image_options->client_id = uniqid();
     $image_options->maxbytes = $options['maxbytes'];
     $image_options->areamaxbytes = $options['areamaxbytes'];
     $image_options->env = 'editor';
     $image_options->itemid = $draftitemid;
     // moodlemedia plugin
     $args->accepted_types = array('video', 'audio');
     $media_options = initialise_filepicker($args);
     $media_options->context = $ctx;
     $media_options->client_id = uniqid();
     $media_options->maxbytes = $options['maxbytes'];
     $media_options->areamaxbytes = $options['areamaxbytes'];
     $media_options->env = 'editor';
     $media_options->itemid = $draftitemid;
     // advlink plugin
     $args->accepted_types = '*';
     $link_options = initialise_filepicker($args);
     $link_options->context = $ctx;
     $link_options->client_id = uniqid();
     $link_options->maxbytes = $options['maxbytes'];
     $link_options->areamaxbytes = $options['areamaxbytes'];
     $link_options->env = 'editor';
     $link_options->itemid = $draftitemid;
     $fpoptions['image'] = $image_options;
     $fpoptions['media'] = $media_options;
     $fpoptions['link'] = $link_options;
     $editor->use_editor($this->get_id(), $options, $fpoptions);
     return format_admin_setting($this, $this->visiblename, '<div class="form-textarea"><textarea rows="' . $this->rows . '" cols="' . $this->cols . '" id="' . $this->get_id() . '" name="' . $this->get_full_name() . '" spellcheck="true">' . s($data) . '</textarea></div>
     <input value="' . $draftitemid . '" name="' . $this->get_full_name() . '_draftitemid" type="hidden" />', $this->description, true, '', $defaultinfo, $query);
 }
コード例 #29
0
 /**
  * Returns success or failure
  *
  * @return bool success or failure
  */
 public static function process_magento_request($order_number, $customer, $moodle_courses)
 {
     global $USER, $DB;
     if (get_config('magentoconnector', 'magentoconnectorenabled') == 0) {
         return false;
     }
     $params = self::validate_parameters(self::process_magento_request_parameters(), array('order_number' => $order_number, 'customer' => $customer, 'moodle_courses' => $moodle_courses));
     $context = context_user::instance($USER->id);
     self::validate_context($context);
     if (!($user = $DB->get_record('user', array('email' => $customer['email'])))) {
         $user = new stdClass();
         $user->firstname = $customer['firstname'];
         $user->lastname = $customer['lastname'];
         $user->email = $customer['email'];
         $user->city = $customer['city'];
         $user->country = $customer['country'];
         $user->confirmed = 1;
         $user->policyagreed = 1;
         $user->mnethostid = 1;
         $user->username = local_magentoconnector_generate_username($customer['firstname'], $customer['lastname']);
         $user->timecreated = time();
         $password = generate_password();
         $user->password = hash_internal_user_password($password);
         $userid = $DB->insert_record('user', $user);
     } else {
         $userid = $user->id;
     }
     $roleid = $DB->get_field('role', 'id', array('shortname' => LOCAL_MAGENTOCONNECTOR_STUDENT_SHORTNAME));
     $enrol = enrol_get_plugin('magento');
     foreach ($moodle_courses as $moodle_course) {
         if ($course = $DB->get_record('course', array('idnumber' => $moodle_course['course_id']))) {
             $enrolinstance = $DB->get_record('enrol', array('courseid' => $course->id, 'enrol' => 'magento'), '*', MUST_EXIST);
             $enrol->enrol_user($enrolinstance, $userid, $roleid);
             $record = new stdClass();
             $record->userid = $userid;
             $record->ordernum = $order_number;
             $record->courseid = $course->id;
             $record->timestamp = time();
             $DB->insert_record('local_magentoconnector_trans', $record);
         } else {
             // no such course ... ?
         }
     }
     if (isset($password)) {
         $enrolinstance->newusername = $user->username;
         $enrolinstance->newaccountpassword = $password;
     }
     $customer = $DB->get_record('user', array('id' => $userid));
     $enrol->email_welcome_message($enrolinstance, $customer);
     return true;
 }
コード例 #30
0
 /**
  * Performs userset_enrolment deletion
  * @throws moodle_exception If there was an error in passed parameters.
  * @throws data_object_exception If there was an error deleting the association.
  * @param array $data The incoming data parameter.
  * @return array An array of parameters, if successful.
  */
 public static function userset_enrolment_delete(array $data)
 {
     global $DB, $USER;
     if (static::require_elis_dependencies() !== true) {
         throw new moodle_exception('ws_function_requires_elis', 'local_datahub');
     }
     // Parameter validation.
     $params = self::validate_parameters(self::userset_enrolment_delete_parameters(), array('data' => $data));
     // Context validation.
     $context = context_user::instance($USER->id);
     self::validate_context($context);
     $data = (object) $data;
     // Parse Userset
     if (empty($data->userset_name) || !($clstid = $DB->get_field(userset::TABLE, 'id', array('name' => $data->userset_name)))) {
         throw new data_object_exception('ws_userset_enrolment_delete_fail_invalid_userset', 'local_datahub', '', $data);
     }
     if (empty($data->plugin)) {
         $data->plugin = 'manual';
     }
     // Capability checking.
     require_capability('local/elisprogram:userset_enrol', \local_elisprogram\context\userset::instance($clstid));
     // Initialize version1elis importplugin for utility functions.
     $importplugin = rlip_dataplugin_factory::factory('dhimport_version1elis');
     $userparams = array();
     $userid = $importplugin->get_userid_from_record($data, '', $userparams);
     if ($userid == false) {
         $a = new stdClass();
         if (empty($userparams)) {
             $a->userparams = '{empty}';
         } else {
             $a->userparams = '';
             foreach ($userparams as $userfield => $uservalue) {
                 $subfield = strpos($userfield, '_');
                 $userfield = substr($userfield, $subfield === false ? 0 : $subfield + 1);
                 if (!empty($a->userparams)) {
                     $a->userparams .= ', ';
                 }
                 $a->userparams .= "{$userfield}: '{$uservalue}'";
             }
         }
         throw new data_object_exception('ws_userset_enrolment_delete_fail_invalid_user', 'local_datahub', '', $a);
     }
     $id = $DB->get_field(clusterassignment::TABLE, 'id', array('clusterid' => $clstid, 'userid' => $userid, 'plugin' => $data->plugin));
     // Respond.
     if (!empty($id) && ($clstass = new clusterassignment($id))) {
         $clstass->delete();
         return array('messagecode' => get_string('ws_userset_enrolment_delete_success_code', 'local_datahub'), 'message' => get_string('ws_userset_enrolment_delete_success_msg', 'local_datahub'));
     } else {
         throw new data_object_exception('ws_userset_enrolment_delete_fail', 'local_datahub');
     }
 }