/** * Test the update user profile image function. */ public function test_update_user_profile_image() { global $DB, $CFG; // Set the profile image. \enrol_lti\helper::update_user_profile_image($this->user1->id, $this->getExternalTestFileUrl('/test.jpg')); // Get the new user record. $this->user1 = $DB->get_record('user', array('id' => $this->user1->id)); // Set the page details. $page = new moodle_page(); $page->set_url('/user/profile.php'); $page->set_context(context_system::instance()); $renderer = $page->get_renderer('core'); $usercontext = context_user::instance($this->user1->id); // Get the user's profile picture and make sure it is correct. $userpicture = new user_picture($this->user1); $this->assertSame($CFG->wwwroot . '/pluginfile.php/' . $usercontext->id . '/user/icon/clean/f2?rev=' . $this->user1->picture, $userpicture->get_url($page, $renderer)->out(false)); }
if ($reset and confirm_sesskey()) { theme_reset_all_caches(); } else if ($choose && $device && !$unsettheme && confirm_sesskey()) { // Load the theme to make sure it is valid. $theme = theme_config::load($choose); // Get the config argument for the chosen device. $themename = get_device_cfg_var_name($device); set_config($themename, $theme->name); // Create a new page for the display of the themes readme. // This ensures that the readme page is shown using the new theme. $confirmpage = new moodle_page(); $confirmpage->set_context($PAGE->context); $confirmpage->set_url($PAGE->url); $confirmpage->set_pagelayout($PAGE->pagelayout); $confirmpage->set_pagetype($PAGE->pagetype); $confirmpage->set_title($PAGE->title); $confirmpage->set_heading($PAGE->heading); // Get the core renderer for the new theme. $output = $confirmpage->get_renderer('core'); echo $output->header(); echo $output->heading(get_string('themesaved')); echo $output->box_start(); echo format_text(get_string('choosereadme', 'theme_'.$theme->name), FORMAT_MOODLE); echo $output->box_end(); echo $output->continue_button($CFG->wwwroot . '/theme/index.php'); echo $output->footer();
public function test_qualified_me() { global $PAGE, $FULLME, $CFG; $this->resetAfterTest(); $PAGE = new moodle_page(); $FULLME = $CFG->wwwroot . '/course/view.php?id=1&xx=yy'; $this->assertSame($FULLME, qualified_me()); $PAGE->set_url('/course/view.php', array('id' => 1)); $this->assertSame($CFG->wwwroot . '/course/view.php?id=1', qualified_me()); }
/** * Handle showing/processing the submission from the block editing form. * @return boolean true if the form was submitted and the new config saved. Does not * return if the editing form was displayed. False otherwise. */ public function process_url_edit() { global $CFG, $DB, $PAGE, $OUTPUT; $blockid = optional_param('bui_editid', null, PARAM_INT); if (!$blockid) { return false; } require_sesskey(); require_once $CFG->dirroot . '/blocks/edit_form.php'; $block = $this->find_instance($blockid); if (!$block->user_can_edit() && !$this->page->user_can_edit_blocks()) { throw new moodle_exception('nopermissions', '', $this->page->url->out(), get_string('editblock')); } $editpage = new moodle_page(); $editpage->set_pagelayout('admin'); $editpage->set_course($this->page->course); //$editpage->set_context($block->context); $editpage->set_context($this->page->context); if ($this->page->cm) { $editpage->set_cm($this->page->cm); } $editurlbase = str_replace($CFG->wwwroot . '/', '/', $this->page->url->out_omit_querystring()); $editurlparams = $this->page->url->params(); $editurlparams['bui_editid'] = $blockid; $editpage->set_url($editurlbase, $editurlparams); $editpage->set_block_actions_done(); // At this point we are either going to redirect, or display the form, so // overwrite global $PAGE ready for this. (Formslib refers to it.) $PAGE = $editpage; //some functions like MoodleQuickForm::addHelpButton use $OUTPUT so we need to replace that to $output = $editpage->get_renderer('core'); $OUTPUT = $output; $formfile = $CFG->dirroot . '/blocks/' . $block->name() . '/edit_form.php'; if (is_readable($formfile)) { require_once $formfile; $classname = 'block_' . $block->name() . '_edit_form'; if (!class_exists($classname)) { $classname = 'block_edit_form'; } } else { $classname = 'block_edit_form'; } $mform = new $classname($editpage->url, $block, $this->page); $mform->set_data($block->instance); if ($mform->is_cancelled()) { redirect($this->page->url); } else { if ($data = $mform->get_data()) { $bi = new stdClass(); $bi->id = $block->instance->id; // This may get overwritten by the special case handling below. $bi->pagetypepattern = $data->bui_pagetypepattern; $bi->showinsubcontexts = (bool) $data->bui_contexts; if (empty($data->bui_subpagepattern) || $data->bui_subpagepattern == '%@NULL@%') { $bi->subpagepattern = null; } else { $bi->subpagepattern = $data->bui_subpagepattern; } $systemcontext = context_system::instance(); $frontpagecontext = context_course::instance(SITEID); $parentcontext = context::instance_by_id($data->bui_parentcontextid); // Updating stickiness and contexts. See MDL-21375 for details. if (has_capability('moodle/site:manageblocks', $parentcontext)) { // Check permissions in destination // Explicitly set the default context $bi->parentcontextid = $parentcontext->id; if ($data->bui_editingatfrontpage) { // The block is being edited on the front page // The interface here is a special case because the pagetype pattern is // totally derived from the context menu. Here are the excpetions. MDL-30340 switch ($data->bui_contexts) { case BUI_CONTEXTS_ENTIRE_SITE: // The user wants to show the block across the entire site $bi->parentcontextid = $systemcontext->id; $bi->showinsubcontexts = true; $bi->pagetypepattern = '*'; break; case BUI_CONTEXTS_FRONTPAGE_SUBS: // The user wants the block shown on the front page and all subcontexts $bi->parentcontextid = $frontpagecontext->id; $bi->showinsubcontexts = true; $bi->pagetypepattern = '*'; break; case BUI_CONTEXTS_FRONTPAGE_ONLY: // The user want to show the front page on the frontpage only $bi->parentcontextid = $frontpagecontext->id; $bi->showinsubcontexts = false; $bi->pagetypepattern = 'site-index'; // This is the only relevant page type anyway but we'll set it explicitly just // in case the front page grows site-index-* subpages of its own later break; } } } $bits = explode('-', $bi->pagetypepattern); // hacks for some contexts if ($parentcontext->contextlevel == CONTEXT_COURSE && $parentcontext->instanceid != SITEID) { // For course context // is page type pattern is mod-*, change showinsubcontext to 1 if ($bits[0] == 'mod' || $bi->pagetypepattern == '*') { $bi->showinsubcontexts = 1; } else { $bi->showinsubcontexts = 0; } } else { if ($parentcontext->contextlevel == CONTEXT_USER) { // for user context // subpagepattern should be null if ($bits[0] == 'user' or $bits[0] == 'my') { // we don't need subpagepattern in usercontext $bi->subpagepattern = null; } } } $bi->defaultregion = $data->bui_defaultregion; $bi->defaultweight = $data->bui_defaultweight; $DB->update_record('block_instances', $bi); if (!empty($block->config)) { $config = clone $block->config; } else { $config = new stdClass(); } foreach ($data as $configfield => $value) { if (strpos($configfield, 'config_') !== 0) { continue; } $field = substr($configfield, 7); $config->{$field} = $value; } $block->instance_config_save($config); $bp = new stdClass(); $bp->visible = $data->bui_visible; $bp->region = $data->bui_region; $bp->weight = $data->bui_weight; $needbprecord = !$data->bui_visible || $data->bui_region != $data->bui_defaultregion || $data->bui_weight != $data->bui_defaultweight; if ($block->instance->blockpositionid && !$needbprecord) { $DB->delete_records('block_positions', array('id' => $block->instance->blockpositionid)); } else { if ($block->instance->blockpositionid && $needbprecord) { $bp->id = $block->instance->blockpositionid; $DB->update_record('block_positions', $bp); } else { if ($needbprecord) { $bp->blockinstanceid = $block->instance->id; $bp->contextid = $this->page->context->id; $bp->pagetype = $this->page->pagetype; if ($this->page->subpage) { $bp->subpage = $this->page->subpage; } else { $bp->subpage = ''; } $DB->insert_record('block_positions', $bp); } } } redirect($this->page->url); } else { $strheading = get_string('blockconfiga', 'moodle', $block->get_title()); $editpage->set_title($strheading); $editpage->set_heading($strheading); $bits = explode('-', $this->page->pagetype); if ($bits[0] == 'tag' && !empty($this->page->subpage)) { // better navbar for tag pages $editpage->navbar->add(get_string('tags'), new moodle_url('/tag/')); $tag = tag_get('id', $this->page->subpage, '*'); // tag search page doesn't have subpageid if ($tag) { $editpage->navbar->add($tag->name, new moodle_url('/tag/index.php', array('id' => $tag->id))); } } $editpage->navbar->add($block->get_title()); $editpage->navbar->add(get_string('configuration')); echo $output->header(); echo $output->heading($strheading, 2); $mform->display(); echo $output->footer(); exit; } } }
public function test_get_url() { global $DB, $CFG; $this->resetAfterTest(); // Force SVG on so that we have predictable URL's. $CFG->svgicons = true; // verify new install contains expected defaults $this->assertEquals('standard', $CFG->theme); $this->assertEquals(1, $CFG->slasharguments); $this->assertEquals(1, $CFG->themerev); $this->assertEquals(0, $CFG->themedesignermode); $this->assertEquals('http://www.example.com/moodle', $CFG->wwwroot); $this->assertEquals($CFG->wwwroot, $CFG->httpswwwroot); $this->assertEquals(0, $CFG->enablegravatar); $this->assertEquals('mm', $CFG->gravatardefaulturl); // create some users $page = new moodle_page(); $page->set_url('/user/profile.php'); $page->set_context(context_system::instance()); $renderer = $page->get_renderer('core'); $user1 = $this->getDataGenerator()->create_user(array('picture' => 11, 'email' => '*****@*****.**')); $context1 = context_user::instance($user1->id); $user2 = $this->getDataGenerator()->create_user(array('picture' => 0, 'email' => '*****@*****.**')); $context2 = context_user::instance($user2->id); $user3 = $this->getDataGenerator()->create_user(array('picture' => 1, 'deleted' => 1, 'email' => '*****@*****.**')); $context3 = context_user::instance($user3->id, IGNORE_MISSING); $this->assertEquals($user3->picture, 0); $this->assertNotEquals($user3->email, '*****@*****.**'); $this->assertFalse($context3); // try legacy picture == 1 $user1->picture = 1; $up1 = new user_picture($user1); $this->assertEquals($CFG->wwwroot . '/pluginfile.php/' . $context1->id . '/user/icon/standard/f2?rev=1', $up1->get_url($page, $renderer)->out(false)); $user1->picture = 11; // try valid user with picture when user context is not cached - 1 query expected context_helper::reset_caches(); $reads = $DB->perf_get_reads(); $up1 = new user_picture($user1); $this->assertEquals($reads, $DB->perf_get_reads()); $this->assertEquals($CFG->wwwroot . '/pluginfile.php/' . $context1->id . '/user/icon/standard/f2?rev=11', $up1->get_url($page, $renderer)->out(false)); $this->assertEquals($reads + 1, $DB->perf_get_reads()); // try valid user with contextid hint - no queries expected $user1->contextid = $context1->id; context_helper::reset_caches(); $reads = $DB->perf_get_reads(); $up1 = new user_picture($user1); $this->assertEquals($reads, $DB->perf_get_reads()); $this->assertEquals($CFG->wwwroot . '/pluginfile.php/' . $context1->id . '/user/icon/standard/f2?rev=11', $up1->get_url($page, $renderer)->out(false)); $this->assertEquals($reads, $DB->perf_get_reads()); // try valid user without image - no queries expected context_helper::reset_caches(); $reads = $DB->perf_get_reads(); $up2 = new user_picture($user2); $this->assertEquals($reads, $DB->perf_get_reads()); $this->assertEquals($CFG->wwwroot . '/theme/image.php/standard/core/1/u/f2', $up2->get_url($page, $renderer)->out(false)); $this->assertEquals($reads, $DB->perf_get_reads()); // try guessing of deleted users - no queries expected unset($user3->deleted); context_helper::reset_caches(); $reads = $DB->perf_get_reads(); $up3 = new user_picture($user3); $this->assertEquals($reads, $DB->perf_get_reads()); $this->assertEquals($CFG->wwwroot . '/theme/image.php/standard/core/1/u/f2', $up3->get_url($page, $renderer)->out(false)); $this->assertEquals($reads, $DB->perf_get_reads()); // try incorrectly deleted users (with valid email and pciture flag) - some DB reads expected $user3->email = '*****@*****.**'; $user3->picture = 1; $reads = $DB->perf_get_reads(); $up3 = new user_picture($user3); $this->assertEquals($reads, $DB->perf_get_reads()); $this->assertEquals($CFG->wwwroot . '/theme/image.php/standard/core/1/u/f2', $up3->get_url($page, $renderer)->out(false)); $this->assertTrue($reads < $DB->perf_get_reads()); // test gravatar set_config('enablegravatar', 1); // deleted user can not have gravatar $user3->email = 'deleted'; $user3->picture = 0; $up3 = new user_picture($user3); $this->assertEquals($CFG->wwwroot . '/theme/image.php/standard/core/1/u/f2', $up3->get_url($page, $renderer)->out(false)); // verify defaults to misteryman (mm) $up2 = new user_picture($user2); $this->assertEquals('http://www.gravatar.com/avatar/ab53a2911ddf9b4817ac01ddcd3d975f?s=35&d=mm', $up2->get_url($page, $renderer)->out(false)); // without gravatardefaulturl, verify we pick own file set_config('gravatardefaulturl', ''); $up2 = new user_picture($user2); $this->assertEquals('http://www.gravatar.com/avatar/ab53a2911ddf9b4817ac01ddcd3d975f?s=35&d=http%3A%2F%2Fwww.example.com%2Fmoodle%2Fpix%2Fu%2Ff2.png', $up2->get_url($page, $renderer)->out(false)); // uploaded image takes precedence before gravatar $up1 = new user_picture($user1); $this->assertEquals($CFG->wwwroot . '/pluginfile.php/' . $context1->id . '/user/icon/standard/f2?rev=11', $up1->get_url($page, $renderer)->out(false)); // https version $CFG->httpswwwroot = str_replace('http:', 'https:', $CFG->wwwroot); $up1 = new user_picture($user1); $this->assertEquals($CFG->httpswwwroot . '/pluginfile.php/' . $context1->id . '/user/icon/standard/f2?rev=11', $up1->get_url($page, $renderer)->out(false)); $up3 = new user_picture($user3); $this->assertEquals($CFG->httpswwwroot . '/theme/image.php/standard/core/1/u/f2', $up3->get_url($page, $renderer)->out(false)); $up2 = new user_picture($user2); $this->assertEquals('https://secure.gravatar.com/avatar/ab53a2911ddf9b4817ac01ddcd3d975f?s=35&d=https%3A%2F%2Fwww.example.com%2Fmoodle%2Fpix%2Fu%2Ff2.png', $up2->get_url($page, $renderer)->out(false)); // now test gravatar with one theme having own images (afterburner) $CFG->httpswwwroot = $CFG->wwwroot; $this->assertTrue(file_exists("{$CFG->dirroot}/theme/afterburner/config.php")); set_config('theme', 'afterburner'); $page = new moodle_page(); $page->set_url('/user/profile.php'); $page->set_context(context_system::instance()); $renderer = $page->get_renderer('core'); $up2 = new user_picture($user2); $this->assertEquals('http://www.gravatar.com/avatar/ab53a2911ddf9b4817ac01ddcd3d975f?s=35&d=http%3A%2F%2Fwww.example.com%2Fmoodle%2Ftheme%2Fafterburner%2Fpix_core%2Fu%2Ff2.png', $up2->get_url($page, $renderer)->out(false)); // https version $CFG->httpswwwroot = str_replace('http:', 'https:', $CFG->wwwroot); $up2 = new user_picture($user2); $this->assertEquals('https://secure.gravatar.com/avatar/ab53a2911ddf9b4817ac01ddcd3d975f?s=35&d=https%3A%2F%2Fwww.example.com%2Fmoodle%2Ftheme%2Fafterburner%2Fpix_core%2Fu%2Ff2.png', $up2->get_url($page, $renderer)->out(false)); // end of gravatar tests // test themed images set_config('enablegravatar', 0); $this->assertTrue(file_exists("{$CFG->dirroot}/theme/formal_white/config.php")); // use any other theme set_config('theme', 'formal_white'); $CFG->httpswwwroot = $CFG->wwwroot; $page = new moodle_page(); $page->set_url('/user/profile.php'); $page->set_context(context_system::instance()); $renderer = $page->get_renderer('core'); $up1 = new user_picture($user1); $this->assertEquals($CFG->wwwroot . '/pluginfile.php/' . $context1->id . '/user/icon/formal_white/f2?rev=11', $up1->get_url($page, $renderer)->out(false)); $up2 = new user_picture($user2); $this->assertEquals($CFG->wwwroot . '/theme/image.php/formal_white/core/1/u/f2', $up2->get_url($page, $renderer)->out(false)); // test non-slashargument images set_config('theme', 'standard'); $CFG->httpswwwroot = $CFG->wwwroot; $CFG->slasharguments = 0; $page = new moodle_page(); $page->set_url('/user/profile.php'); $page->set_context(context_system::instance()); $renderer = $page->get_renderer('core'); $up3 = new user_picture($user3); $this->assertEquals($CFG->wwwroot . '/theme/image.php?theme=standard&component=core&rev=1&image=u%2Ff2', $up3->get_url($page, $renderer)->out(false)); }
public function test_navbar_prepend_and_add() { global $PAGE; // Unfortunate hack needed because people use global $PAGE around the place. $PAGE->set_url('/'); // We need to reset after this test because we using the generator. $this->resetAfterTest(); $generator = self::getDataGenerator(); $cat1 = $generator->create_category(); $cat2 = $generator->create_category(array('parent' => $cat1->id)); $course = $generator->create_course(array('category' => $cat2->id)); $page = new moodle_page(); $page->set_course($course); $page->set_url(new moodle_url('/course/view.php', array('id' => $course->id))); $page->navbar->prepend('test 1'); $page->navbar->prepend('test 2'); $page->navbar->add('test 3'); $page->navbar->add('test 4'); $items = $page->navbar->get_items(); foreach ($items as $item) { $this->assertInstanceOf('navigation_node', $item); } $i = 0; $this->assertSame('test 1', $items[$i++]->text); $this->assertSame('test 2', $items[$i++]->text); $this->assertSame('home', $items[$i++]->key); $this->assertSame('courses', $items[$i++]->key); $this->assertSame($cat1->id, $items[$i++]->key); $this->assertSame($cat2->id, $items[$i++]->key); $this->assertSame($course->id, $items[$i++]->key); $this->assertSame('test 3', $items[$i++]->text); $this->assertSame('test 4', $items[$i++]->text); return $page; }
// print all users foreach ($students as $student) { ?> <li id="student_<?php echo $student->id; ?> " data-prof="<?php echo $student->roleid == 5 ? 'b' : 'a'; ?> " data-order="<?php echo $studentNum++; ?> "> <?php $page = new moodle_page(); $page->set_url('/user/profile.php'); $page->set_context(context_system::instance()); $renderer = $page->get_renderer('core'); $up3 = new user_picture($student); $up3->size = 100; $image = $up3->get_url($page, $renderer)->out(false); ?> <img src="<?php echo $image; ?> " alt="<?php echo $student->firstname; ?> "> <span class="user-name no-text"><?php echo fullname($student);
/** * Handle showing/processing the submission from the block editing form. * @return boolean true if the form was submitted and the new config saved. Does not * return if the editing form was displayed. False otherwise. */ public function process_url_edit() { global $CFG, $DB, $PAGE; $blockid = optional_param('bui_editid', null, PARAM_INTEGER); if (!$blockid) { return false; } confirm_sesskey(); require_once $CFG->dirroot . '/blocks/edit_form.php'; $block = $this->find_instance($blockid); if (!$block->user_can_edit() && !$this->page->user_can_edit_blocks()) { throw new moodle_exception('nopermissions', '', $this->page->url->out(), get_string('editblock')); } $editpage = new moodle_page(); $editpage->set_generaltype('form'); $editpage->set_course($this->page->course); $editpage->set_context($block->context); $editurlbase = str_replace($CFG->wwwroot . '/', '', $this->page->url->out(true)); $editurlparams = $this->page->url->params(); $editurlparams['bui_editid'] = $blockid; $editpage->set_url($editurlbase, $editurlparams); $editpage->_block_actions_done = true; // At this point we are either going to redirect, or display the form, so // overwrite global $PAGE ready for this. (Formslib refers to it.) $PAGE = $editpage; $formfile = $CFG->dirroot . '/blocks/' . $block->name() . '/edit_form.php'; if (is_readable($formfile)) { require_once $formfile; $classname = 'block_' . $block->name() . '_edit_form'; } else { $classname = 'block_edit_form'; } $mform = new $classname($editpage->url, $block, $this->page); $mform->set_data($block->instance); if ($mform->is_cancelled()) { redirect($this->page->url); } else { if ($data = $mform->get_data()) { $bi = new stdClass(); $bi->id = $block->instance->id; $bi->showinsubcontexts = $data->bui_showinsubcontexts; $bi->pagetypepattern = $data->bui_pagetypepattern; if (empty($data->bui_subpagepattern) || $data->bui_subpagepattern == '%@NULL@%') { $bi->subpagepattern = null; } else { $bi->subpagepattern = $data->bui_subpagepattern; } $bi->defaultregion = $data->bui_defaultregion; $bi->defaultweight = $data->bui_defaultweight; $DB->update_record('block_instances', $bi); if (!empty($block->config)) { $config = clone $block->config; } else { $config = new stdClass(); } foreach ($data as $configfield => $value) { if (strpos($configfield, 'config_') !== 0) { continue; } $field = substr($configfield, 7); $config->{$field} = $value; } $block->instance_config_save($config); $bp = new stdClass(); $bp->visible = $data->bui_visible; $bp->region = $data->bui_region; $bp->weight = $data->bui_weight; $needbprecord = !$data->bui_visible || $data->bui_region != $data->bui_defaultregion || $data->bui_weight != $data->bui_defaultweight; if ($block->instance->blockpositionid && !$needbprecord) { $DB->delete_records('block_positions', array('id' => $block->instance->blockpositionid)); } else { if ($block->instance->blockpositionid && $needbprecord) { $bp->id = $block->instance->blockpositionid; $DB->update_record('block_positions', $bp); } else { if ($needbprecord) { $bp->blockinstanceid = $block->instance->id; $bp->contextid = $this->page->context->id; $bp->pagetype = $this->page->pagetype; if ($this->page->subpage) { $bp->subpage = $this->page->subpage; } else { $bp->subpage = ''; } $DB->insert_record('block_positions', $bp); } } } redirect($this->page->url); } else { $strheading = get_string('editinga', $block->name()); if (strpos($strheading, '[[') === 0) { $strheading = get_string('blockconfiga', 'moodle', $block->get_title()); } $editpage->set_title($strheading); $editpage->set_heading($strheading); $output = $editpage->theme->get_renderer('core', $editpage); echo $output->header(); echo $output->heading($strheading, 2); $mform->display(); echo $output->footer(); exit; } } }
/** * Handle showing/processing the submission from the block editing form. * @return boolean true if the form was submitted and the new config saved. Does not * return if the editing form was displayed. False otherwise. */ public function process_url_edit() { global $CFG, $DB, $PAGE; $blockid = optional_param('bui_editid', null, PARAM_INTEGER); if (!$blockid) { return false; } require_sesskey(); require_once $CFG->dirroot . '/blocks/edit_form.php'; $block = $this->find_instance($blockid); if (!$block->user_can_edit() && !$this->page->user_can_edit_blocks()) { throw new moodle_exception('nopermissions', '', $this->page->url->out(), get_string('editblock')); } $editpage = new moodle_page(); $editpage->set_pagelayout('admin'); $editpage->set_course($this->page->course); $editpage->set_context($block->context); if ($this->page->cm) { $editpage->set_cm($this->page->cm); } $editurlbase = str_replace($CFG->wwwroot . '/', '/', $this->page->url->out_omit_querystring()); $editurlparams = $this->page->url->params(); $editurlparams['bui_editid'] = $blockid; $editpage->set_url($editurlbase, $editurlparams); $editpage->set_block_actions_done(); // At this point we are either going to redirect, or display the form, so // overwrite global $PAGE ready for this. (Formslib refers to it.) $PAGE = $editpage; $formfile = $CFG->dirroot . '/blocks/' . $block->name() . '/edit_form.php'; if (is_readable($formfile)) { require_once $formfile; $classname = 'block_' . $block->name() . '_edit_form'; if (!class_exists($classname)) { $classname = 'block_edit_form'; } } else { $classname = 'block_edit_form'; } $mform = new $classname($editpage->url, $block, $this->page); $mform->set_data($block->instance); if ($mform->is_cancelled()) { redirect($this->page->url); } else { if ($data = $mform->get_data()) { $bi = new stdClass(); $bi->id = $block->instance->id; $bi->pagetypepattern = $data->bui_pagetypepattern; if (empty($data->bui_subpagepattern) || $data->bui_subpagepattern == '%@NULL@%') { $bi->subpagepattern = null; } else { $bi->subpagepattern = $data->bui_subpagepattern; } $parentcontext = get_context_instance_by_id($data->bui_parentcontextid); $systemcontext = get_context_instance(CONTEXT_SYSTEM); // Updating stickiness and contexts. See MDL-21375 for details. if (has_capability('moodle/site:manageblocks', $parentcontext)) { // Check permissions in destination // Explicitly set the context $bi->parentcontextid = $parentcontext->id; // If the context type is > 0 then we'll explicitly set the block as sticky, otherwise not $bi->showinsubcontexts = (int) (!empty($data->bui_contexts)); // If the block wants to be system-wide, then explicitly set that if ($data->bui_contexts == 2) { // Only possible on a frontpage or system page $bi->parentcontextid = $systemcontext->id; } else { // The block doesn't want to be system-wide, so let's ensure that if ($parentcontext->id == $systemcontext->id) { // We need to move it to the front page $frontpagecontext = get_context_instance(CONTEXT_COURSE, SITEID); $bi->parentcontextid = $frontpagecontext->id; $bi->pagetypepattern = '*'; // Just in case } } } $bi->defaultregion = $data->bui_defaultregion; $bi->defaultweight = $data->bui_defaultweight; $DB->update_record('block_instances', $bi); if (!empty($block->config)) { $config = clone $block->config; } else { $config = new stdClass(); } foreach ($data as $configfield => $value) { if (strpos($configfield, 'config_') !== 0) { continue; } $field = substr($configfield, 7); $config->{$field} = $value; } $block->instance_config_save($config); $bp = new stdClass(); $bp->visible = $data->bui_visible; $bp->region = $data->bui_region; $bp->weight = $data->bui_weight; $needbprecord = !$data->bui_visible || $data->bui_region != $data->bui_defaultregion || $data->bui_weight != $data->bui_defaultweight; if ($block->instance->blockpositionid && !$needbprecord) { $DB->delete_records('block_positions', array('id' => $block->instance->blockpositionid)); } else { if ($block->instance->blockpositionid && $needbprecord) { $bp->id = $block->instance->blockpositionid; $DB->update_record('block_positions', $bp); } else { if ($needbprecord) { $bp->blockinstanceid = $block->instance->id; $bp->contextid = $this->page->context->id; $bp->pagetype = $this->page->pagetype; if ($this->page->subpage) { $bp->subpage = $this->page->subpage; } else { $bp->subpage = ''; } $DB->insert_record('block_positions', $bp); } } } redirect($this->page->url); } else { $strheading = get_string('blockconfiga', 'moodle', $block->get_title()); $editpage->set_title($strheading); $editpage->set_heading($strheading); $editpage->navbar->add($strheading); $output = $editpage->get_renderer('core'); echo $output->header(); echo $output->heading($strheading, 2); $mform->display(); echo $output->footer(); exit; } } }
if (!empty($CFG->debug) and $CFG->debug >= DEBUG_DEVELOPER) { print_error('notlocalisederrormessage', 'error', '', $ex->__toString()); } else { print_error('unexpectederror', 'block_sharing_cart', $returnurl); } } } $orderby = 'tree,weight,modtext'; if ($DB->get_dbfamily() == 'mssql' || $DB->get_dbfamily() == 'oracle') { // SQL Server and Oracle do not support ordering by TEXT field. $orderby = 'tree,weight,CAST(modtext AS VARCHAR(255))'; } $items = $DB->get_records(sharing_cart\record::TABLE, array('userid' => $USER->id), $orderby); $title = get_string('bulkdelete', 'block_sharing_cart'); $PAGE->set_pagelayout('standard'); $PAGE->set_url('/blocks/sharing_cart/bulkdelete.php', array('course' => $courseid)); $PAGE->set_title($title); $PAGE->set_heading($title); $PAGE->navbar->add(get_string('pluginname', 'block_sharing_cart'))->add($title, ''); echo $OUTPUT->header(); echo $OUTPUT->heading($title); echo ' <div style="width:100%; text-align:center;">'; if (empty($items)) { echo ' <div> <input type="button" onclick="history.back();" value="', get_string('back'), '" /> </div>'; } else { echo ' <script type="text/javascript">