/** * Gets the content for this block */ function get_content() { global $CFG; // First check if we have already generated, don't waste cycles if ($this->contentgenerated === true) { return $this->content; } $this->content = new stdClass(); if (get_user_preferences('admin_bookmarks')) { require_once $CFG->libdir . '/adminlib.php'; $adminroot = admin_get_root(false, false); // settings not required - only pages $bookmarks = explode(',', get_user_preferences('admin_bookmarks')); /// Accessibility: markup as a list. $contents = array(); foreach ($bookmarks as $bookmark) { $temp = $adminroot->locate($bookmark); if ($temp instanceof admin_settingpage) { $contenturl = new moodle_url('/admin/settings.php', array('section' => $bookmark)); $contentlink = html_writer::link($contenturl, $temp->visiblename); $contents[] = html_writer::tag('li', $contentlink); } else { if ($temp instanceof admin_externalpage) { $contenturl = new moodle_url($temp->url); $contentlink = html_writer::link($contenturl, $temp->visiblename); $contents[] = html_writer::tag('li', $contentlink); } } } $this->content->text = html_writer::tag('ol', implode('', $contents), array('class' => 'list')); } else { $bookmarks = array(); } $this->content->footer = ''; $this->page->settingsnav->initialise(); $node = $this->page->settingsnav->get('root', navigation_node::TYPE_SITE_ADMIN); if (!$node || !$node->contains_active_node()) { return $this->content; } $section = $node->find_active_node()->key; if ($section == 'search' || empty($section)) { // the search page can't be properly bookmarked at present $this->content->footer = ''; } else { if (in_array($section, $bookmarks)) { $deleteurl = new moodle_url('/blocks/admin_bookmarks/delete.php', array('section' => $section, 'sesskey' => sesskey())); $this->content->footer = html_writer::link($deleteurl, get_string('unbookmarkthispage', 'admin')); } else { $createurl = new moodle_url('/blocks/admin_bookmarks/create.php', array('section' => $section, 'sesskey' => sesskey())); $this->content->footer = html_writer::link($createurl, get_string('bookmarkthispage', 'admin')); } } return $this->content; }
function url_get_path() { global $CFG; $adminroot = admin_get_root(); $root = $adminroot->locate($this->section); if (is_a($root, 'admin_externalpage')) { return $root->url; } else { return $CFG->wwwroot . '/' . $CFG->admin . '/settings.php'; } }
function url_get_path() { global $CFG; $adminroot =& admin_get_root(false, false); //settings not required - only pages $root =& $adminroot->locate($this->section); if (is_a($root, 'admin_externalpage')) { return $root->url; } else { return $CFG->wwwroot . '/' . $CFG->admin . '/settings.php'; } }
function get_content() { global $CFG, $USER; if ($this->content !== NULL) { return $this->content; } $this->content = new stdClass(); $this->content->text = ''; if (get_user_preferences('admin_bookmarks')) { // this is expensive! Only require when bookmakrs exist.. require_once $CFG->libdir . '/adminlib.php'; $adminroot = admin_get_root(false, false); // settings not required - only pages $bookmarks = explode(',', get_user_preferences('admin_bookmarks')); // hmm... just a liiitle (potentially) processor-intensive // (recall that $adminroot->locate is a huge recursive call... and we're calling it repeatedly here /// Accessibility: markup as a list. $this->content->text .= '<ol class="list">' . "\n"; foreach ($bookmarks as $bookmark) { $temp = $adminroot->locate($bookmark); if ($temp instanceof admin_settingpage) { $this->content->text .= '<li><a href="' . $CFG->wwwroot . '/' . $CFG->admin . '/settings.php?section=' . $bookmark . '">' . $temp->visiblename . "</a></li>\n"; } else { if ($temp instanceof admin_externalpage) { $this->content->text .= '<li><a href="' . $temp->url . '">' . $temp->visiblename . "</a></li>\n"; } } } $this->content->text .= "</ol>\n"; } else { $bookmarks = array(); } // TODO if (isset($this->page->section) and $this->page->section == 'search') { // the search page can't be properly bookmarked at present $this->content->footer = ''; } else { if (($section = isset($this->page->section) ? $this->page->section : '') && in_array($section, $bookmarks)) { $this->content->footer = '<a href="' . $CFG->wwwroot . '/blocks/admin_bookmarks/delete.php?section=' . $section . '&sesskey=' . sesskey() . '">' . get_string('unbookmarkthispage', 'admin') . '</a>'; } else { if ($section = isset($this->page->section) ? $this->page->section : '') { $this->content->footer = '<a href="' . $CFG->wwwroot . '/blocks/admin_bookmarks/create.php?section=' . $section . '&sesskey=' . sesskey() . '">' . get_string('bookmarkthispage', 'admin') . '</a>'; } else { $this->content->footer = ''; } } } return $this->content; }
/** * outputs this page as html in a table (suitable for inclusion in an admin pagetype) * returns a string of the html */ function output_html() { $adminroot =& admin_get_root(); $return = '<fieldset>' . "\n" . '<div class="clearer"><!-- --></div>' . "\n"; foreach ($this->settings as $setting) { $fullname = $setting->get_full_name(); if (array_key_exists($fullname, $adminroot->errors)) { $data = $adminroot->errors[$fullname]->data; } else { $data = $setting->get_setting(); if (is_null($data)) { $data = $setting->get_defaultsetting(); } } $return .= $setting->output_html($data); } $return .= '</fieldset>'; return $return; }
} } else { $icons = $OUTPUT->spacer() . ' '; } // Move icons. $icons .= question_type_icon_html('up', $qtypename, 't/up', get_string('up'), ''); $icons .= question_type_icon_html('down', $qtypename, 't/down', get_string('down'), ''); $row[] = $icons; // Delete link, if available. if ($needed[$qtypename]) { $row[] = ''; } else { $row[] = html_writer::link(new moodle_url($thispageurl, array('delete' => $qtypename, 'sesskey' => sesskey())), get_string('delete'), array('title' => get_string('uninstallqtype', 'question'))); } // Settings link, if available. $settings = admin_get_root()->locate('qtypesetting' . $qtypename); if ($settings instanceof admin_externalpage) { $row[] = html_writer::link($settings->url, get_string('settings')); } else { if ($settings instanceof admin_settingpage) { $row[] = html_writer::link(new moodle_url('/admin/settings.php', array('section' => 'qtypesetting' . $qtypename)), get_string('settings')); } else { $row[] = ''; } } $table->add_data($row, $rowclass); } $table->finish_output(); echo $OUTPUT->footer(); function question_types_enable_disable_icons($qtypename, $createable) {
function admin_externalpage_setup($section) { global $CFG, $PAGE, $USER; $adminroot = admin_get_root(); require_once $CFG->libdir . '/blocklib.php'; require_once $CFG->dirroot . '/' . $CFG->admin . '/pagelib.php'; page_map_class(PAGE_ADMIN, 'page_admin'); $PAGE = page_create_object(PAGE_ADMIN, 0); // there must be any constant id number $PAGE->init_extra($section); // hack alert! $root = $adminroot->locate($PAGE->section); if ($site = get_site()) { require_login(); } else { redirect($CFG->wwwroot . '/' . $CFG->admin . '/index.php'); die; } if (!is_a($root, 'admin_externalpage')) { error(get_string('sectionerror', 'admin')); die; } // this eliminates our need to authenticate on the actual pages if (!$root->check_access()) { error(get_string('accessdenied', 'admin')); die; } $adminediting = optional_param('adminedit', -1, PARAM_BOOL); if (!isset($USER->adminediting)) { $USER->adminediting = false; } if ($PAGE->user_allowed_editing()) { if ($adminediting == 1) { $USER->adminediting = true; } elseif ($adminediting == 0) { $USER->adminediting = false; } } }
// probably new installation - lets return to frontpage after this step // remove settings that we want uninitialised unset_config('registerauth'); redirect('upgradesettings.php?return=site'); } /// Check if we are returning from moodle.org registration and if so, we mark that fact to remove reminders if (!empty($id)) { if ($id == $CFG->siteidentifier) { set_config('registered', time()); } } /// setup critical warnings before printing admin tree block $insecuredataroot = is_dataroot_insecure(true); $register_globals_enabled = ini_get_bool('register_globals'); $SESSION->admin_critical_warning = $register_globals_enabled || $insecuredataroot == INSECURE_DATAROOT_ERROR; $adminroot =& admin_get_root(); /// Check if there are any new admin settings which have still yet to be set if (any_new_admin_settings($adminroot)) { redirect('upgradesettings.php'); } /// Everything should now be set up, and the user is an admin /// Print default admin page with notifications. admin_externalpage_setup('adminnotifications'); admin_externalpage_print_header(); /// Deprecated database! Warning!! if (!empty($CFG->migrated_to_new_db)) { print_box(print_string('dbmigrationdeprecateddb', 'admin'), 'generalbox adminwarning'); } /// Check for any special upgrades that might need to be run if (!empty($CFG->upgrade)) { print_box(get_string("upgrade{$CFG->upgrade}", "admin", "{$CFG->wwwroot}/{$CFG->admin}/upgrade{$CFG->upgrade}.php"));
// check that site is properly customized $site = get_site(); if (empty($site->shortname)) { // probably new installation - lets return to frontpage after this step // remove settings that we want uninitialised unset_config('registerauth'); redirect('upgradesettings.php?return=site'); } // Check if we are returning from moodle.org registration and if so, we mark that fact to remove reminders if (!empty($id) and $id == $CFG->siteidentifier) { set_config('registered', time()); } // setup critical warnings before printing admin tree block $insecuredataroot = is_dataroot_insecure(true); $SESSION->admin_critical_warning = $insecuredataroot == INSECURE_DATAROOT_ERROR; $adminroot = admin_get_root(); // Check if there are any new admin settings which have still yet to be set if (any_new_admin_settings($adminroot)) { redirect('upgradesettings.php'); } // Everything should now be set up, and the user is an admin // Print default admin page with notifications. $errorsdisplayed = defined('WARN_DISPLAY_ERRORS_ENABLED'); $lastcron = $DB->get_field_sql('SELECT MAX(lastcron) FROM {modules}'); $cronoverdue = $lastcron < time() - 3600 * 24; $dbproblems = $DB->diagnose(); $maintenancemode = !empty($CFG->maintenance_enabled); $updateschecker = available_update_checker::instance(); $availableupdates = $updateschecker->get_update_info('core', array('minmaturity' => $CFG->updateminmaturity, 'notifybuilds' => $CFG->updatenotifybuilds)); $availableupdatesfetch = $updateschecker->get_last_timefetched(); admin_externalpage_setup('adminnotifications');
if ($data = data_submitted() and confirm_sesskey()) { if (admin_write_settings($data)) { $statusmsg = get_string('changessaved'); } if (empty($adminroot->errors)) { switch ($return) { case 'site': redirect("{$CFG->wwwroot}/"); case 'admin': redirect("{$CFG->wwwroot}/{$CFG->admin}/"); } } else { $errormsg = get_string('errorwithsettings', 'admin'); $firsterror = reset($adminroot->errors); } $adminroot = admin_get_root(true); //reload tree $settingspage = $adminroot->locate($section, true); } if ($PAGE->user_allowed_editing() && $adminediting != -1) { $USER->editing = $adminediting; } /// print header stuff ------------------------------------------------------------ if (empty($SITE->fullname)) { $PAGE->set_title($settingspage->visiblename); $PAGE->set_heading($settingspage->visiblename); echo $OUTPUT->header(); echo $OUTPUT->box(get_string('configintrosite', 'admin')); if ($errormsg !== '') { echo $OUTPUT->notification($errormsg); } else {
function get_content() { global $CFG; if ($this->content !== NULL) { return $this->content; } if (isguestuser() or !isloggedin()) { // these users can not change any settings $this->content = ''; return ''; } require_once $CFG->libdir . '/adminlib.php'; $adminroot =& admin_get_root(false, false); // settings not required - only pages if ($current = $adminroot->locate($this->section, true)) { $this->pathtosection = $current->path; array_pop($this->pathtosection); } // we need to do this instead of $this->build_tree($adminroot) because the top-level folder // is redundant (and ideally ignored). (the top-level folder is "administration".) $entries = array_keys($adminroot->children); asort($entries); foreach ($entries as $entry) { $this->build_tree($adminroot->children[$entry]); } if ($this->tempcontent !== '') { $closedimg = '<img src="' . $CFG->pixpath . '/i/closed.gif" alt="' . s(get_string('folderclosed')) . '" />'; $openedimg = '<img src="' . $CFG->pixpath . '/i/open.gif" alt="' . s(get_string('folderopened')) . '" />'; $this->content = new object(); $this->content->text = ' <script type="text/javascript"> //<![CDATA[ var vh_numdivs = ' . ($this->divcounter - 1) . '; var parkplatz = new Array(); for (var i=1; i<=vh_numdivs; i++) { parkplatz[i] = null; } function menu_toggle(i) { i = parseInt(i); if (parkplatz[i] === null) { collapse(i); } else { expand(i); } } function collapse(i) { if (parkplatz[i] !== null) { return; } var obj = document.getElementById("vh_div"+String(i)); if (obj === null) { return; } var nothing = document.createElement("span"); nothing.setAttribute("id", "vh_div"+String(i)); parkplatz[i] = obj; obj.parentNode.replaceChild(nothing, obj); var icon = document.getElementById("vh_div"+String(i)+"indicator"); icon.innerHTML = "' . addslashes_js($closedimg) . '"; } function expand(i) { if (parkplatz[i] === null) { return; } var nothing = document.getElementById("vh_div"+String(i)); var obj = parkplatz[i]; parkplatz[i] = null; nothing.parentNode.replaceChild(obj, nothing); var icon = document.getElementById("vh_div"+String(i)+"indicator"); icon.innerHTML = "' . addslashes_js($openedimg) . '"; } function expandall() { for (i=1; i<=vh_numdivs; i++) { expand(i); } } function collapseall() { for (var i=vh_numdivs; i>0; i--) { collapse(i); } } //]]> </script> <div class="admintree"> ' . $this->tempcontent . ' </div> <script type="text/javascript"> //<![CDATA[ collapseall(); ' . $this->expandjavascript . '; //]]> </script>'; // only do search if you have moodle/site:config if (has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM))) { $this->content->footer = '<div class="adminsearchform">' . '<form action="' . $CFG->wwwroot . '/' . $CFG->admin . '/search.php" method="get"><div>' . '<label for="query" class="accesshide">' . get_string('searchinsettings', 'admin') . '</label>' . '<input type="text" name="query" id="query" size="8" value="' . s($adminroot->search) . '" />' . '<input type="submit" value="' . get_string('search') . '" /></div>' . '</form></div>'; } else { $this->content->footer = ''; } } else { $this->content = new object(); $this->content->text = ''; } return $this->content; }
} else { $plugin = new stdClass(); $plugin->version = '???'; if (file_exists("{$CFG->dirroot}/blocks/{$blockname}/version.php")) { include "{$CFG->dirroot}/blocks/{$blockname}/version.php"; } if (!($blockobject = block_instance($block->name))) { $incompatible[] = $block; continue; } } $delete = '<a href="blocks.php?delete=' . $blockid . '&sesskey=' . sesskey() . '">' . $strdelete . '</a>'; $settings = ''; // By default, no configuration if ($blockobject and $blockobject->has_config()) { $blocksettings = admin_get_root()->locate('blocksetting' . $block->name); if ($blocksettings instanceof admin_externalpage) { $settings = '<a href="' . $blocksettings->url . '">' . get_string('settings') . '</a>'; } else { if ($blocksettings instanceof admin_settingpage) { $settings = '<a href="' . $CFG->wwwroot . '/' . $CFG->admin . '/settings.php?section=blocksetting' . $block->name . '">' . $strsettings . '</a>'; } else { $settings = '<a href="block.php?block=' . $blockid . '">' . $strsettings . '</a>'; } } } // MDL-11167, blocks can be placed on mymoodle, or the blogs page // and it should not show up on course search page $totalcount = $DB->count_records('block_instances', array('blockname' => $blockname)); $count = $DB->count_records('block_instances', array('blockname' => $blockname, 'pagetypepattern' => 'course-view-*')); if ($count > 0) {
/** * Gets a string with PHP code to inject default values to the upgrade processes * * @todo Try to respect DRY and unify part of package_ingredients with settings_to_php * @uses flavours_php_writer * @param array $selectedsettings * @returns array PHP code, one line per array element, the caller will make a string or a file */ public function settings_to_php($selectedsettings) { $phparray = array(); $adminroot = admin_get_root(); $this->get_branch_settings($adminroot->children, $this, true); foreach ($selectedsettings as $settingspage) { // Settings page path $namespace = explode('/', $settingspage); // The admin settingspage is the last one $page = array_pop($namespace); if (!($settings = $this->get_settingspage_settings($namespace, $page, $this))) { continue; } $settingspagetagname = str_replace('/', '.', $settingspage); // Adding settings foreach ($settings as $setting) { // Can\'t refactor the whole 'core' code to 'moodle' to maintain // backward compatibility with flavours packages if ($setting->plugin == 'core') { $setting->plugin = 'moodle'; } // Restore slashes $setting->plugin = str_replace('.', '/', $setting->plugin); // Valu with addslashes only in the single qoute $value = $this->get_setting_value($setting->name, $setting->plugin); $value = str_replace("'", "\\'", $value); $phparray[] = $this->add_setting_php($setting->plugin, $setting->name, $value); // Adding the extra values of the setting (if present) to the attributes array if (!empty($setting->attrs)) { foreach ($setting->attrs as $attrname => $value) { $phparray[] = $this->add_setting_php($setting->plugin, $attrname, $value); } } } } return $phparray; }
function get_content() { global $CFG; if ($this->content !== NULL) { return $this->content; } if (isguestuser() or !isloggedin()) { // these users can not change any settings $this->content = ''; return ''; } require_once $CFG->libdir . '/adminlib.php'; $adminroot = admin_get_root(false, false); // settings not required - only pages if ($current = $adminroot->locate($this->section, true)) { $this->pathtosection = $current->path; array_pop($this->pathtosection); } // we need to do this instead of $this->build_tree($adminroot) because the top-level folder // is redundant (and ideally ignored). (the top-level folder is "administration".) $entries = array_keys($adminroot->children); asort($entries); foreach ($entries as $entry) { $this->build_tree($adminroot->children[$entry]); } if ($this->tempcontent !== '') { require_js(array('yui_yahoo', 'yui_event')); require_js('blocks/admin_tree/admintree.js'); $this->content = new object(); $this->content->text = '<div class="admintree">' . $this->tempcontent . "</div>\n"; $this->content->text .= print_js_call('admin_tree.init', array($this->divcounter - 1, $this->expandnodes, $CFG->pixpath, get_string('folderopened'), get_string('folderclosed')), true); // only do search if you have moodle/site:config if (has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM))) { $this->content->footer = '<div class="adminsearchform">' . '<form action="' . $CFG->wwwroot . '/' . $CFG->admin . '/search.php" method="get"><div>' . '<label for="query" class="accesshide">' . get_string('searchinsettings', 'admin') . '</label>' . '<input type="text" name="query" id="query" size="8" value="' . s($adminroot->search) . '" />' . '<input type="submit" value="' . get_string('search') . '" /></div>' . '</form></div>'; } else { $this->content->footer = ''; } } else { $this->content = new object(); $this->content->text = ''; } return $this->content; }
function upgrade_group_db($continueto) { /// This function upgrades the group tables, if necessary /// It's called from admin/index.php. global $CFG, $db; $group_version = ''; // Get code versions require "{$CFG->dirroot}/group/version.php"; if (empty($CFG->group_version)) { // New 1.8 groups have never been installed... $strdatabaseupgrades = get_string('databaseupgrades'); print_header($strdatabaseupgrades, $strdatabaseupgrades, $strdatabaseupgrades, '', upgrade_get_javascript(), false, " ", " "); upgrade_log_start(); //initialize default group settings now install_group_db(); $adminroot = admin_get_root(); print_continue($continueto); print_footer('none'); exit; } /// Upgrading code starts here if ($group_version > $CFG->group_version) { // Upgrade tables $strdatabaseupgrades = get_string('databaseupgrades'); print_header($strdatabaseupgrades, $strdatabaseupgrades, $strdatabaseupgrades, '', upgrade_get_javascript()); upgrade_log_start(); print_heading('group'); $db->debug = true; $status = xmldb_group_upgrade($CFG->group_version); $db->debug = false; /// Now analyze upgrade results if ($status) { // No upgrading failed if (set_config('group_version', $group_version)) { notify(get_string('databasesuccess'), 'green'); notify(get_string('databaseupgradegroups', '', $group_version), 'green'); print_continue($continueto); print_footer('none'); exit; } else { error("Error: Upgrade of group system failed! (Could not update version in config table)"); } } else { error("Error: Upgrade failed! See group/upgrade.php"); } } else { if ($group_version < $CFG->group_version) { error("Error: The code you are using is OLDER than the version that made these databases!"); } } }
/** * Gets the content for this block */ function get_content() { global $CFG, $PAGE; // First check if we have already generated, don't waste cycles if ($this->contentgenerated === true) { return $this->content; } $this->content = new stdClass(); if (get_user_preferences('user_bookmarks')) { require_once $CFG->libdir . '/adminlib.php'; $adminroot = admin_get_root(false, false); // settings not required - only pages $tempbookmarks = explode(',', get_user_preferences('user_bookmarks')); /// Accessibility: markup as a list. $contents = array(); foreach ($tempbookmarks as $bookmark) { //the bookmarks are in the following format- url;title //so exploading the bookmark by ";" to get the url and title $tempBookmark = explode(';', $bookmark); //making the url for bookmark $contenturl = new moodle_url($CFG->wwwroot . $tempBookmark[0]); //now making a link $contentlink = html_writer::link($contenturl, $tempBookmark[1]); //this is the url to delete bookmark $bookmarkdeleteurl = new moodle_url('/blocks/user_bookmarks/delete.php', array('bookmarkurl' => $tempBookmark[0], 'sesskey' => sesskey())); //this has the link to delete the bookmark $deleteLink = "<a href='{$bookmarkdeleteurl}'><img alt='Delete Bookmark' title='Delete Bookmark' src='{$CFG->wwwroot}/blocks/user_bookmarks/pix/delete.gif'></a>"; //creating the link to update the title for bookmark $editLink = '<script type="text/javascript"> function updateBookmark(bookmarkURL, defaultTitle, sesskey, wwwroot) { var newBookmarkTitle = prompt(\'Edit Bookmark title\',defaultTitle); if (newBookmarkTitle == "" || newBookmarkTitle == null) { newBookmarkTitle = defaultTitle; }else { var redirectPage = wwwroot + "/blocks/user_bookmarks/update.php?bookmarkurl=" + escape(bookmarkURL) + "&title=" + escape(newBookmarkTitle) + "&sesskey=" + sesskey; window.location = redirectPage; } } </script> <a style="cursor: pointer;" onClick="updateBookmark(\'' . $tempBookmark[0] . '\', \'' . $tempBookmark[1] . '\', \'' . sesskey() . '\', \'' . $CFG->wwwroot . '\');"> <img alt="Delete Bookmark" title="Delete Bookmark" src="' . $CFG->wwwroot . '/blocks/user_bookmarks/pix/edit.gif"> </a>'; //setting layout for the bookmark and its delete and edit buttons $contents[] = html_writer::tag('li', $contentlink . " " . $editLink . " " . $deleteLink); $bookmarks[] = htmlspecialchars_decode($tempBookmark[0]); } $this->content->text = html_writer::tag('ol', implode('', $contents), array('class' => 'list')); } else { $bookmarks = array(); } $this->content->footer = ''; $this->page->settingsnav->initialise(); $node = $this->page->settingsnav->get('root', navigation_node::TYPE_SETTING); $bookmarkurl = htmlspecialchars_decode(str_replace($CFG->wwwroot, '', $PAGE->url)); $bookmarktitle = $PAGE->title; if (in_array($bookmarkurl, $bookmarks)) { //this prints out the link to unbookmark a page $this->content->footer = '<script type="text/javascript"> function deleteBookmark(bookmarkURL, sesskey, wwwroot) { var redirectPage = wwwroot + "/blocks/user_bookmarks/delete.php?bookmarkurl=" + escape(bookmarkURL) + "&sesskey=" + sesskey; window.location = redirectPage; } </script> <form style="cursor: hand;"> <a style="cursor: pointer;" onClick="deleteBookmark(\'' . $bookmarkurl . '\', \'' . sesskey() . '\', \'' . $CFG->wwwroot . '\');">Unbookmark this page</a> </form>'; } else { //this prints out link to bookmark a page $this->content->footer = '<script type="text/javascript"> function addBookmark(bookmarkURL, defaultTitle, sesskey, wwwroot) { var newBookmarkTitle = prompt(\'Enter a title for the Bookmark\',defaultTitle); if (newBookmarkTitle == "" || newBookmarkTitle == null) { newBookmarkTitle = defaultTitle; } else { var redirectPage = wwwroot + "/blocks/user_bookmarks/create.php?bookmarkurl=" + escape(bookmarkURL) + "&title=" + newBookmarkTitle + "&sesskey=" + sesskey; window.location = redirectPage; } } </script> <form> <a style="cursor: pointer;" onClick="addBookmark(\'' . $bookmarkurl . '\', \'' . $bookmarktitle . '\', \'' . sesskey() . '\', \'' . $CFG->wwwroot . '\');">bookmark this page</a> </form>'; } return $this->content; }
// page is loaded (i.e. both when we're displaying the form and then when we process the form's input). // if the return values don't match, we could potentially lose changes that the admin is making. $newsettingshtml = output_new_settings_by_page(admin_get_root()); // first we deal with the case where there are no new settings to be set if ($newsettingshtml == '') { if ($return == 'site') { redirect("{$CFG->wwwroot}/"); } else { redirect("{$CFG->wwwroot}/{$CFG->admin}/index.php"); } } // now we'll deal with the case that the admin has submitted the form with new settings if ($data = data_submitted()) { $unslashed = (array) stripslashes_recursive($data); if (confirm_sesskey()) { $newsettings = find_new_settings(admin_get_root()); $errors = ''; foreach ($newsettings as $newsetting) { if (isset($unslashed['s_' . $newsetting->name])) { $errors .= $newsetting->write_setting($unslashed['s_' . $newsetting->name]); } else { $errors .= $newsetting->write_setting($newsetting->defaultsetting); } } if (empty($errors)) { // there must be either redirect without message or continue button or else upgrade would be sometimes broken if ($return == 'site') { redirect("{$CFG->wwwroot}/"); } else { redirect("{$CFG->wwwroot}/{$CFG->admin}/index.php"); }
<?php require '../../config.php'; require_once $CFG->libdir . '/adminlib.php'; require_login(); $context = get_context_instance(CONTEXT_SYSTEM); $PAGE->set_context($context); $adminroot = admin_get_root(false, false); // settings not required - only pages if ($section = optional_param('section', '', PARAM_SAFEDIR) and confirm_sesskey()) { if (get_user_preferences('admin_bookmarks')) { $bookmarks = explode(',', get_user_preferences('admin_bookmarks')); if (in_array($section, $bookmarks)) { print_error('bookmarkalreadyexists', 'admin'); die; } } else { $bookmarks = array(); } $temp = $adminroot->locate($section); if ($temp instanceof admin_settingpage || $temp instanceof admin_externalpage) { $bookmarks[] = $section; $bookmarks = implode(',', $bookmarks); set_user_preference('admin_bookmarks', $bookmarks); } else { print_error('invalidsection', 'admin'); die; } if ($temp instanceof admin_settingpage) { redirect($CFG->wwwroot . '/' . $CFG->admin . '/settings.php?section=' . $section); } elseif ($temp instanceof admin_externalpage) {
function get_content() { global $CFG, $ADMIN; require_once $CFG->libdir . '/adminlib.php'; $adminroot = admin_get_root(); if ($this->content !== NULL) { return $this->content; } if ($this->pathtosection = $adminroot->path($this->section)) { $this->pathtosection = array_reverse($this->pathtosection); array_pop($this->pathtosection); } // we need to do this instead of $this->build_tree($adminroot) because the top-level folder // is redundant (and ideally ignored). (the top-level folder is "administration".) $entries = array_keys($adminroot->children); asort($entries); foreach ($entries as $entry) { $this->build_tree($adminroot->children[$entry]); } if ($this->tempcontent !== '') { $strfolderopened = s(get_string('folderopened')); $strfolderclosed = s(get_string('folderclosed')); $this->content = new stdClass(); $this->content->text = '<script type="text/javascript">' . "\n"; $this->content->text .= '//<![CDATA[' . "\n"; $this->content->text .= 'var vh_numspans = ' . ($this->spancounter - 1) . ';' . "\n"; $this->content->text .= 'var vh_content = new Array();' . "\n"; $this->content->text .= 'function getspan(spanid) {' . "\n"; $this->content->text .= ' if (document.getElementById) {' . "\n"; $this->content->text .= ' return document.getElementById(spanid);' . "\n"; $this->content->text .= ' } else if (window[spanid]) {' . "\n"; $this->content->text .= ' return window[spanid];' . "\n"; $this->content->text .= ' }' . "\n"; $this->content->text .= ' return null;' . "\n"; $this->content->text .= '}' . "\n"; $this->content->text .= 'function toggle(spanid) {' . "\n"; $this->content->text .= ' if (getspan(spanid).innerHTML == "") {' . "\n"; $this->content->text .= ' getspan(spanid).innerHTML = vh_content[spanid];' . "\n"; $this->content->text .= ' getspan(spanid + "indicator").innerHTML = \'<img src="' . $CFG->pixpath . '/i/open.gif" alt="' . $strfolderopened . '" />\';' . "\n"; $this->content->text .= ' } else {' . "\n"; $this->content->text .= ' vh_content[spanid] = getspan(spanid).innerHTML;' . "\n"; $this->content->text .= ' getspan(spanid).innerHTML = "";' . "\n"; $this->content->text .= ' getspan(spanid + "indicator").innerHTML = \'<img src="' . $CFG->pixpath . '/i/closed.gif" alt="' . $strfolderclosed . '" />\';' . "\n"; $this->content->text .= ' }' . "\n"; $this->content->text .= '}' . "\n"; $this->content->text .= 'function collapse(spanid) {' . "\n"; $this->content->text .= ' if (getspan(spanid).innerHTML !== "") {' . "\n"; $this->content->text .= ' vh_content[spanid] = getspan(spanid).innerHTML;' . "\n"; $this->content->text .= ' getspan(spanid).innerHTML = "";' . "\n"; $this->content->text .= ' getspan(spanid + "indicator").innerHTML = \'<img src="' . $CFG->pixpath . '/i/closed.gif" alt="' . $strfolderclosed . '" />\';' . "\n"; $this->content->text .= ' }' . "\n"; $this->content->text .= '}' . "\n"; $this->content->text .= 'function expand(spanid) {' . "\n"; $this->content->text .= ' getspan(spanid).innerHTML = vh_content[spanid];' . "\n"; $this->content->text .= ' getspan(spanid + "indicator").innerHTML = \'<img src="' . $CFG->pixpath . '/i/open.gif" alt="' . $strfolderopened . '" />\';' . "\n"; $this->content->text .= '}' . "\n"; $this->content->text .= 'function expandall() {' . "\n"; $this->content->text .= ' for (i = 1; i <= vh_numspans; i++) {' . "\n"; $this->content->text .= ' expand("vh_span" + String(i));' . "\n"; $this->content->text .= ' }' . "\n"; $this->content->text .= '}' . "\n"; $this->content->text .= 'function collapseall() {' . "\n"; $this->content->text .= ' for (i = vh_numspans; i > 0; i--) {' . "\n"; $this->content->text .= ' collapse("vh_span" + String(i));' . "\n"; $this->content->text .= ' }' . "\n"; $this->content->text .= '}' . "\n"; $this->content->text .= '//]]>' . "\n"; $this->content->text .= '</script>' . "\n"; $this->content->text .= '<div class="admintree">' . "\n"; $this->content->text .= $this->tempcontent; $this->content->text .= '</div>' . "\n"; $this->content->text .= '<script type="text/javascript">' . "\n"; $this->content->text .= '//<![CDATA[' . "\n"; $this->content->text .= 'collapseall();' . "\n"; $this->content->text .= $this->expandjavascript; $this->content->text .= '//]]>' . "\n"; $this->content->text .= '</script>' . "\n"; $searchcontent = isset($CFG->adminsearchquery) ? $CFG->adminsearchquery : ''; $this->content->footer = '<div class="adminsearchform">' . '<form action="' . $CFG->wwwroot . '/' . $CFG->admin . '/search.php" method="get"><div>' . '<label for="query" class="accesshide">' . get_string('searchinsettings', 'admin') . '</label>' . '<input type="text" name="query" id="query" size="8" value="' . s($searchcontent) . '" />' . '<input type="submit" value="' . get_string('search') . '" /></div>' . '</form></div>'; } else { $this->content = new stdClass(); $this->content->text = ''; } return $this->content; }
admin_get_root(true, false); // settings not required - only pages } if (!empty($show) and confirm_sesskey()) { if (!($module = $DB->get_record("modules", array("name" => $show)))) { print_error('moduledoesnotexist', 'error'); } $DB->set_field("modules", "visible", "1", array("id" => $module->id)); // Show main module $DB->set_field('course_modules', 'visible', '1', array('visibleold' => 1, 'module' => $module->id)); // Get the previous saved visible state for the course module. // clear the course modinfo cache for courses // where we just made something visible $sql = "UPDATE {course}\n SET modinfo = ''\n WHERE id IN (SELECT DISTINCT course\n FROM {course_modules}\n WHERE visible=1 AND module=?)"; $DB->execute($sql, array($module->id)); admin_get_root(true, false); // settings not required - only pages } if (!empty($delete) and confirm_sesskey()) { echo $OUTPUT->header(); echo $OUTPUT->heading($stractivities); if (get_string_manager()->string_exists('modulename', $delete)) { $strmodulename = get_string('modulename', $delete); } else { $strmodulename = $delete; } if (!$confirm) { echo $OUTPUT->confirm(get_string("moduledeleteconfirm", "", $strmodulename), "modules.php?delete={$delete}&confirm=1", "modules.php"); echo $OUTPUT->footer(); exit; } else {
function html_header($course, $wdir, $formfield = "") { # HU, CS Repository plugin support global $repository, $scheme; global $CFG, $ME, $choose; if ($course->id == SITEID) { $strfiles = get_string("sitefiles"); } else { $strfiles = get_string("files"); } if ($wdir == "/") { $fullnav = "{$strfiles}"; } else { $dirs = explode("/", $wdir); $numdirs = count($dirs); $link = ""; $navigation = ""; for ($i = 1; $i < $numdirs - 1; $i++) { $navigation .= " -> "; $link .= "/" . urlencode($dirs[$i]); # HU, CS Repository plugin support $navigation .= "<a href=\"" . $ME . "?id={$course->id}&wdir={$link}&choose={$choose}" . $repository->get_arg() . "\">" . $dirs[$i] . "</a>"; } # HU, CS Repository plugin support $fullnav = "<a href=\"" . $ME . "?id={$course->id}&wdir=/&choose={$choose}" . $repository->get_arg() . "\">{$strfiles}</a> {$navigation} -> " . $dirs[$numdirs - 1]; } # HU, CS Repository plugin support $page = podcaster_page::create_page($c = null); $csslink = $page->get_stylesheet(); if ($choose) { # HU, CS Repository plugin support print_header('', '', '', '', $csslink); $chooseparts = explode('.', $choose); if (count($chooseparts) == 2) { ?> <script type="text/javascript"> //<![CDATA[ function set_value(txt) { opener.document.forms['<?php echo $chooseparts[0] . "']." . $chooseparts[1]; ?> .value = txt; window.close(); } //]]> </script> <?php } elseif (count($chooseparts) == 1) { ?> <script type="text/javascript"> //<![CDATA[ function set_value(txt) { opener.document.getElementById('<?php echo $chooseparts[0]; ?> ').value = txt; window.close(); } //]]> </script> <?php } $fullnav = str_replace('->', '»', format_string($course->shortname) . " -> {$fullnav}"); # HU, CS Repository plugin support echo '<div id="nav-bar"><img src="' . $CFG->pixpath . '/mod/podcaster/icon.gif" alt="podcaster"> ' . $fullnav . '</div>'; if ($course->id == SITEID and $wdir != "/backupdata") { print_heading(get_string("publicsitefileswarning"), "center", 2); } } else { if ($course->id == SITEID) { if ($wdir == "/backupdata") { $adminroot = admin_get_root(); admin_externalpage_setup('frontpagerestore', $adminroot); admin_externalpage_print_header($adminroot); } else { $adminroot = admin_get_root(); admin_externalpage_setup('sitefiles', $adminroot); admin_externalpage_print_header($adminroot); print_heading(get_string("publicsitefileswarning"), "center", 2); } } else { print_header("{$course->shortname}: {$strfiles}", $course->fullname, "<a href=\"../../../course/view.php?id={$course->id}\">{$course->shortname}" . "</a> -> {$fullnav}", $formfield, $csslink); } } echo "<table border=\"0\" style=\"margin-left:auto;margin-right:auto\" cellspacing=\"3\" cellpadding=\"3\" width=\"640\">"; echo "<tr>"; echo "<td colspan=\"2\">"; # HU, CS Repository plugin support echo '<div id="mod-podcaster-upload-headline">' . podcaster_util::get_string('repository_' . $repository->name . '_desc') . '</div>'; echo '</tr><tr><td colspan="2">'; }
/** * Returns default setting if exists * @return mixed array or string depending on instance; NULL means no default, user must supply */ public function get_defaultsetting() { $adminroot = admin_get_root(false, false); if (!empty($adminroot->custom_defaults)) { $plugin = is_null($this->plugin) ? 'moodle' : $this->plugin; if (isset($adminroot->custom_defaults[$plugin])) { if (array_key_exists($this->name, $adminroot->custom_defaults[$plugin])) { // null is valid value here ;-) return $adminroot->custom_defaults[$plugin][$this->name]; } } } return $this->defaultsetting; }
function upgrade_backup_db($continueto) { /// This function upgrades the backup tables, if necessary /// It's called from admin/index.php, also backup.php and restore.php global $CFG, $db; require_once "{$CFG->dirroot}/backup/version.php"; // Get code versions if (empty($CFG->backup_version)) { // Backup has never been installed. $strdatabaseupgrades = get_string("databaseupgrades"); $navlinks = array(); $navlinks[] = array('name' => $strdatabaseupgrades, 'link' => null, 'type' => 'misc'); $navigation = build_navigation($navlinks); print_header($strdatabaseupgrades, $strdatabaseupgrades, $navigation, "", upgrade_get_javascript(), false, " ", " "); upgrade_log_start(); print_heading('backup'); $db->debug = true; /// Both old .sql files and new install.xml are supported /// but we priorize install.xml (XMLDB) if present $status = false; if (file_exists($CFG->dirroot . '/backup/db/install.xml')) { $status = install_from_xmldb_file($CFG->dirroot . '/backup/db/install.xml'); //New method } else { if (file_exists($CFG->dirroot . '/backup/db/' . $CFG->dbtype . '.sql')) { $status = modify_database($CFG->dirroot . '/backup/db/' . $CFG->dbtype . '.sql'); //Old method } } $db->debug = false; if ($status) { if (set_config("backup_version", $backup_version) and set_config("backup_release", $backup_release)) { //initialize default backup settings now $adminroot = admin_get_root(); apply_default_settings($adminroot->locate('backups')); notify(get_string("databasesuccess"), "green"); notify(get_string("databaseupgradebackups", "", $backup_version), "green"); print_continue($continueto); print_footer('none'); exit; } else { error("Upgrade of backup system failed! (Could not update version in config table)"); } } else { error("Backup tables could NOT be set up successfully!"); } } /// Upgrading code starts here $oldupgrade = false; $newupgrade = false; if (is_readable($CFG->dirroot . '/backup/db/' . $CFG->dbtype . '.php')) { include_once $CFG->dirroot . '/backup/db/' . $CFG->dbtype . '.php'; // defines old upgrading function $oldupgrade = true; } if (is_readable($CFG->dirroot . '/backup/db/upgrade.php')) { include_once $CFG->dirroot . '/backup/db/upgrade.php'; // defines new upgrading function $newupgrade = true; } if ($backup_version > $CFG->backup_version) { // Upgrade tables $strdatabaseupgrades = get_string("databaseupgrades"); $navigation = array(array('name' => $strdatabaseupgrades, 'link' => null, 'type' => 'misc')); print_header($strdatabaseupgrades, $strdatabaseupgrades, build_navigation($navigation), '', upgrade_get_javascript()); upgrade_log_start(); print_heading('backup'); /// Run de old and new upgrade functions for the module $oldupgrade_function = 'backup_upgrade'; $newupgrade_function = 'xmldb_backup_upgrade'; /// First, the old function if exists $oldupgrade_status = true; if ($oldupgrade && function_exists($oldupgrade_function)) { $db->debug = true; $oldupgrade_status = $oldupgrade_function($CFG->backup_version); } else { if ($oldupgrade) { notify('Upgrade function ' . $oldupgrade_function . ' was not available in ' . '/backup/db/' . $CFG->dbtype . '.php'); } } /// Then, the new function if exists and the old one was ok $newupgrade_status = true; if ($newupgrade && function_exists($newupgrade_function) && $oldupgrade_status) { $db->debug = true; $newupgrade_status = $newupgrade_function($CFG->backup_version); } else { if ($newupgrade) { notify('Upgrade function ' . $newupgrade_function . ' was not available in ' . '/backup/db/upgrade.php'); } } $db->debug = false; /// Now analyze upgrade results if ($oldupgrade_status && $newupgrade_status) { // No upgrading failed if (set_config("backup_version", $backup_version) and set_config("backup_release", $backup_release)) { notify(get_string("databasesuccess"), "green"); notify(get_string("databaseupgradebackups", "", $backup_version), "green"); print_continue($continueto); print_footer('none'); exit; } else { error("Upgrade of backup system failed! (Could not update version in config table)"); } } else { error("Upgrade failed! See backup/version.php"); } } else { if ($backup_version < $CFG->backup_version) { upgrade_log_start(); notify("WARNING!!! The code you are using is OLDER than the version that made these databases!"); } } upgrade_log_finish(); }
/** * Returns the URL of the plugin settings screen * * Null value means that the plugin either does not have the settings screen * or its location is not available via this library. * * @return null|moodle_url */ public function get_settings_url() { $section = $this->get_settings_section_name(); if ($section === null) { return null; } $settings = admin_get_root()->locate($section); if ($settings && $settings instanceof \admin_settingpage) { return new moodle_url('/admin/settings.php', array('section' => $section)); } else { if ($settings && $settings instanceof \admin_externalpage) { return new moodle_url($settings->url); } else { return null; } } }
$statusmsg = get_string('errorwithsettings', 'admin') . ' <br />' . $errors; } } else { error(get_string('confirmsesskeybad', 'error')); } // now update $SITE - it might have been changed $SITE = get_record('course', 'id', $SITE->id); $COURSE = clone $SITE; } // and finally, if we get here, then there are matching settings and we have to print a form // to modify them admin_externalpage_print_header($adminroot); if ($statusmsg != '') { notify($statusmsg); } $resultshtml = search_settings_html(admin_get_root(), $query); echo '<form action="search.php" method="post" id="adminsettings">'; echo '<div>'; echo '<input type="hidden" name="sesskey" value="' . sesskey() . '" />'; echo '<input type="hidden" name="query" value="' . s($query) . '" />'; echo '</div>'; echo '<fieldset>'; echo '<div class="clearer"><!-- --></div>'; if ($resultshtml != '') { echo $resultshtml; echo '<div class="form-buttons"><input class="form-submit" type="submit" value="' . get_string('savechanges', 'admin') . '" /></div>'; } else { echo get_string('noresults', 'admin'); } echo '</fieldset>'; echo '</form>';
/** * Load the site administration tree * * This function loads the site administration tree by using the lib/adminlib library functions * * @param navigation_node $referencebranch A reference to a branch in the settings * navigation tree * @param part_of_admin_tree $adminbranch The branch to add, if null generate the admin * tree and start at the beginning * @return mixed A key to access the admin tree by */ protected function load_administration_settings(navigation_node $referencebranch = null, part_of_admin_tree $adminbranch = null) { global $CFG; // Check if we are just starting to generate this navigation. if ($referencebranch === null) { // Require the admin lib then get an admin structure if (!function_exists('admin_get_root')) { require_once $CFG->dirroot . '/lib/adminlib.php'; } $adminroot = admin_get_root(false, false); // This is the active section identifier $this->adminsection = $this->page->url->param('section'); // Disable the navigation from automatically finding the active node navigation_node::$autofindactive = false; $referencebranch = $this->add(get_string('administrationsite'), null, self::TYPE_SETTING, null, 'root'); foreach ($adminroot->children as $adminbranch) { $this->load_administration_settings($referencebranch, $adminbranch); } navigation_node::$autofindactive = true; // Use the admin structure to locate the active page if (!$this->contains_active_node() && ($current = $adminroot->locate($this->adminsection, true))) { $currentnode = $this; while (($pathkey = array_pop($current->path)) !== null && $currentnode) { $currentnode = $currentnode->get($pathkey); } if ($currentnode) { $currentnode->make_active(); } } else { $this->scan_for_active_node($referencebranch); } return $referencebranch; } else { if ($adminbranch->check_access()) { // We have a reference branch that we can access and is not hidden `hurrah` // Now we need to display it and any children it may have $url = null; $icon = null; if ($adminbranch instanceof admin_settingpage) { $url = new moodle_url('/' . $CFG->admin . '/settings.php', array('section' => $adminbranch->name)); } else { if ($adminbranch instanceof admin_externalpage) { $url = $adminbranch->url; } else { if (!empty($CFG->linkadmincategories) && $adminbranch instanceof admin_category) { $url = new moodle_url('/' . $CFG->admin . '/category.php', array('category' => $adminbranch->name)); } } } // Add the branch $reference = $referencebranch->add($adminbranch->visiblename, $url, self::TYPE_SETTING, null, $adminbranch->name, $icon); if ($adminbranch->is_hidden()) { if (($adminbranch instanceof admin_externalpage || $adminbranch instanceof admin_settingpage) && $adminbranch->name == $this->adminsection) { $reference->add_class('hidden'); } else { $reference->display = false; } } // Check if we are generating the admin notifications and whether notificiations exist if ($adminbranch->name === 'adminnotifications' && admin_critical_warnings_present()) { $reference->add_class('criticalnotification'); } // Check if this branch has children if ($reference && isset($adminbranch->children) && is_array($adminbranch->children) && count($adminbranch->children) > 0) { foreach ($adminbranch->children as $branch) { // Generate the child branches as well now using this branch as the reference $this->load_administration_settings($reference, $branch); } } else { $reference->icon = new pix_icon('i/settings', ''); } } } }
function html_header($course, $wdir, $formfield = "") { global $CFG, $ME, $choose; if ($course->id == SITEID) { $strfiles = get_string("sitefiles"); } else { $strfiles = get_string("files"); } if ($wdir == "/") { $fullnav = "{$strfiles}"; } else { $dirs = explode("/", $wdir); $numdirs = count($dirs); $link = ""; $navigation = ""; for ($i = 1; $i < $numdirs - 1; $i++) { $navigation .= " -> "; $link .= "/" . urlencode($dirs[$i]); $navigation .= "<a href=\"" . $ME . "?id={$course->id}&wdir={$link}&choose={$choose}\">" . $dirs[$i] . "</a>"; } $fullnav = "<a href=\"" . $ME . "?id={$course->id}&wdir=/&choose={$choose}\">{$strfiles}</a> {$navigation} -> " . $dirs[$numdirs - 1]; } if ($choose) { print_header(); $chooseparts = explode('.', $choose); if (count($chooseparts) == 2) { ?> <script type="text/javascript"> //<![CDATA[ function set_value(txt) { opener.document.forms['<?php echo $chooseparts[0] . "']." . $chooseparts[1]; ?> .value = txt; window.close(); } //]]> </script> <?php } elseif (count($chooseparts) == 1) { ?> <script type="text/javascript"> //<![CDATA[ function set_value(txt) { opener.document.getElementById('<?php echo $chooseparts[0]; ?> ').value = txt; window.close(); } //]]> </script> <?php } $fullnav = str_replace('->', '»', format_string($course->shortname) . " -> {$fullnav}"); echo '<div id="nav-bar">' . $fullnav . '</div>'; if ($course->id == SITEID and $wdir != "/backupdata") { print_heading(get_string("publicsitefileswarning"), "center", 2); } } else { if ($course->id == SITEID) { if ($wdir == "/backupdata") { $adminroot = admin_get_root(); admin_externalpage_setup('frontpagerestore', $adminroot); admin_externalpage_print_header($adminroot); } else { $adminroot = admin_get_root(); admin_externalpage_setup('sitefiles', $adminroot); admin_externalpage_print_header($adminroot); print_heading(get_string("publicsitefileswarning"), "center", 2); } } else { print_header("{$course->shortname}: {$strfiles}", $course->fullname, "<a href=\"../course/view.php?id={$course->id}\">{$course->shortname}" . "</a> -> {$fullnav}", $formfield); } } echo "<table border=\"0\" style=\"margin-left:auto;margin-right:auto\" cellspacing=\"3\" cellpadding=\"3\" width=\"640\">"; echo "<tr>"; echo "<td colspan=\"2\">"; }