function portfolio_picasa_admin_upgrade_notification() { $admins = get_admins(); if (empty($admins)) { return; } $mainadmin = reset($admins); $a = new stdClass; $a->docsurl = get_docs_url('Google_OAuth_2.0_setup'); foreach ($admins as $admin) { $message = new stdClass(); $message->component = 'moodle'; $message->name = 'notices'; $message->userfrom = $mainadmin; $message->userto = $admin; $message->smallmessage = get_string('oauth2upgrade_message_small', 'portfolio_picasa'); $message->subject = get_string('oauth2upgrade_message_subject', 'portfolio_picasa'); $message->fullmessage = get_string('oauth2upgrade_message_content', 'portfolio_picasa', $a); $message->fullmessagehtml = get_string('oauth2upgrade_message_content', 'portfolio_picasa', $a); $message->fullmessageformat = FORMAT_PLAIN; $message->notification = 1; message_send($message); } }
function report_security_doc_link($issue, $name) { global $CFG; if (empty($CFG->docroot)) { return $name; } return '<a onclick="this.target=\'docspopup\'" href="' . get_docs_url('report/security/') . $issue . '">' . '<img class="iconhelp" src="' . $CFG->httpswwwroot . '/pix/docs.gif" alt="" />' . $name . '</a>'; }
/** * Display a stolen token message to the site administrator * @param object $site * @return string html code */ public function secretisstolen($site) { global $CFG; $optionsyes = array(); $optionsyes['url'] = $CFG->wwwroot; $optionsyes['token'] = $site['token']; $optionsyes['hubname'] = get_config('local_hub', 'name'); $formcontinue = new single_button(new moodle_url($site['url'] . "/admin/registration/renewregistration.php", $optionsyes), get_string('continue'), 'post'); $docurl = new moodle_url(get_docs_url(get_string('blockedsecretdocurl', 'local_hub'))); $doc = html_writer::tag('a', get_string('moreinfo', 'local_hub'), array('href' => $docurl)); return $this->output->box(get_string('secretisstolen', 'local_hub', $doc)) . $this->output->render($formcontinue); }
/** * Display page explaining proper upgrade process, * there can not be any PHP file leftovers... * * @return string HTML to output. */ public function upgrade_stale_php_files_page() { $output = ''; $output .= $this->header(); $output .= $this->heading(get_string('upgradestalefiles', 'admin')); $output .= $this->box_start('generalbox', 'notice'); $output .= format_text(get_string('upgradestalefilesinfo', 'admin', get_docs_url('Upgrading')), FORMAT_MARKDOWN); $output .= html_writer::empty_tag('br'); $output .= html_writer::tag('div', $this->single_button($this->page->url, get_string('reload'), 'get'), array('class' => 'buttons')); $output .= $this->box_end(); $output .= $this->footer(); return $output; }
/** * Set params for this plugin. * * @param string $elementid * @param stdClass $options - the options for the editor, including the context. * @param stdClass $fpoptions - unused. */ function atto_computing_params_for_js($elementid, $options, $fpoptions) { $texexample = '$$A \\cdot B$$'; // Format a string with the active filter set. // If it is modified - we assume that some sort of text filter is working in this context. $result = format_text($texexample, true, $options); $texfilteractive = $texexample !== $result; $context = $options['context']; if (!$context) { $context = context_system::instance(); } // Tex example librarys. $library = array('group1' => array('groupname' => 'librarygroup1', 'grouptitle' => 'librarygroup1_title', 'elements' => get_config('atto_computing', 'librarygroup1')), 'group2' => array('groupname' => 'librarygroup2', 'grouptitle' => 'librarygroup2_title', 'elements' => get_config('atto_computing', 'librarygroup2')), 'group3' => array('groupname' => 'librarygroup3', 'grouptitle' => 'librarygroup3_title', 'elements' => get_config('atto_computing', 'librarygroup3')), 'group4' => array('groupname' => 'librarygroup4', 'grouptitle' => 'librarygroup4_title', 'elements' => get_config('atto_computing', 'librarygroup4')), 'group5' => array('groupname' => 'librarygroup5', 'grouptitle' => 'librarygroup5_title', 'elements' => get_config('atto_computing', 'librarygroup5')), 'group6' => array('groupname' => 'librarygroup6', 'grouptitle' => 'librarygroup6_title', 'elements' => get_config('atto_computing', 'librarygroup6')), 'group7' => array('groupname' => 'librarygroup7', 'grouptitle' => 'librarygroup7_title', 'elements' => get_config('atto_computing', 'librarygroup7'))); return array('texfilteractive' => $texfilteractive, 'contextid' => $context->id, 'library' => $library, 'texdocsurl' => get_docs_url('Using_TeX_Notation')); }
/** * Add the desired form elements. */ protected function configuration_definition() { global $CFG; $form = $this->_form; $form->addElement('text', 'prefix', get_string('prefix', 'cachestore_apcu'), array('maxlength' => 5, 'size' => 5)); $form->addHelpButton('prefix', 'prefix', 'cachestore_apcu'); $form->setType('prefix', PARAM_TEXT); // We set to text but we have a rule to limit to alphanumext. $form->setDefault('prefix', $CFG->prefix); $form->addRule('prefix', get_string('prefixinvalid', 'cachestore_apcu'), 'regex', '#^[a-zA-Z0-9\\-_]+$#'); $form->addElement('header', 'apc_notice', get_string('notice', 'cachestore_apcu')); $form->setExpanded('apc_notice'); $link = get_docs_url('Caching#APC'); $form->addElement('html', nl2br(get_string('clusternotice', 'cachestore_apcu', $link))); }
public function __construct($context, $id, $roleid) { parent::__construct($context, $id); $this->allrisks = get_all_risks(); $this->risksurl = get_docs_url(s(get_string('risks', 'core_role'))); $this->allpermissions = array(CAP_INHERIT => 'inherit', CAP_ALLOW => 'allow', CAP_PREVENT => 'prevent', CAP_PROHIBIT => 'prohibit'); $this->strperms = array(); foreach ($this->allpermissions as $permname) { $this->strperms[$permname] = get_string($permname, 'core_role'); } $this->roleid = $roleid; $this->load_current_permissions(); // Fill in any blank permissions with an explicit CAP_INHERIT, and init a locked field. foreach ($this->capabilities as $capid => $cap) { if (!isset($this->permissions[$cap->name])) { $this->permissions[$cap->name] = CAP_INHERIT; } $this->capabilities[$capid]->locked = false; } }
/** * Send a message to the admin in regard with the APIv1 migration. * * @return void */ function repository_boxnet_admin_upgrade_notification() { $admins = get_admins(); if (empty($admins)) { return; } $a = new stdClass(); $a->docsurl = get_docs_url('Box.net_APIv1_migration'); foreach ($admins as $admin) { $message = new stdClass(); $message->component = 'moodle'; $message->name = 'notices'; $message->userfrom = get_admin(); $message->userto = $admin; $message->smallmessage = get_string('apiv1migration_message_small', 'repository_boxnet'); $message->subject = get_string('apiv1migration_message_subject', 'repository_boxnet'); $message->fullmessage = get_string('apiv1migration_message_content', 'repository_boxnet', $a); $message->fullmessagehtml = get_string('apiv1migration_message_content', 'repository_boxnet', $a); $message->fullmessageformat = FORMAT_PLAIN; $message->notification = 1; message_send($message); } }
/** * Inform admins about assignments that still need upgrading. */ function mod_assignment_pending_upgrades_notification($count) { $admins = get_admins(); if (empty($admins)) { return; } $a = new stdClass(); $a->count = $count; $a->docsurl = get_docs_url('Assignment_upgrade_tool'); foreach ($admins as $admin) { $message = new stdClass(); $message->component = 'moodle'; $message->name = 'notices'; $message->userfrom = \core_user::get_noreply_user(); $message->userto = $admin; $message->smallmessage = get_string('pendingupgrades_message_small', 'mod_assignment'); $message->subject = get_string('pendingupgrades_message_subject', 'mod_assignment'); $message->fullmessage = get_string('pendingupgrades_message_content', 'mod_assignment', $a); $message->fullmessagehtml = get_string('pendingupgrades_message_content', 'mod_assignment', $a); $message->fullmessageformat = FORMAT_PLAIN; $message->notification = 1; message_send($message); } }
public static function admin_config_form(&$mform) { $a = new stdClass(); $a->docsurl = get_docs_url('Google_OAuth_2.0_setup'); $a->callbackurl = (new moodle_url(self::REDIRECTURL))->out(false); $mform->addElement('static', null, '', get_string('oauthinfo', 'portfolio_googledocs', $a)); $mform->addElement('text', 'clientid', get_string('clientid', 'portfolio_googledocs')); $mform->setType('clientid', PARAM_RAW_TRIMMED); $mform->addElement('text', 'secret', get_string('secret', 'portfolio_googledocs')); $mform->setType('secret', PARAM_RAW_TRIMMED); $strrequired = get_string('required'); $mform->addRule('clientid', $strrequired, 'required', null, 'client'); $mform->addRule('secret', $strrequired, 'required', null, 'client'); }
/** * Returns a string containing a link to the user documentation. * Also contains an icon by default. Shown to teachers and admin only. * * @param string $path The page link after doc root and language, no leading slash. * @param string $text The text to be displayed for the link * @param boolean $forcepopup Whether to force a popup regardless of the value of $CFG->doctonewwindow * @return string */ public function doc_link($path, $text = '', $forcepopup = false) { global $CFG; $icon = $this->pix_icon('docs', '', 'moodle', array('class'=>'iconhelp icon-pre', 'role'=>'presentation')); $url = new moodle_url(get_docs_url($path)); $attributes = array('href'=>$url); if (!empty($CFG->doctonewwindow) || $forcepopup) { $attributes['class'] = 'helplinkpopup'; } return html_writer::tag('a', $icon.$text, $attributes); }
} } // switch the string_manager instance to stop using install/lang/ $CFG->early_install_lang = false; $CFG->langotherroot = $CFG->dataroot . '/lang'; $CFG->langlocalroot = $CFG->dataroot . '/lang'; get_string_manager(true); // make sure we are installing stable release or require a confirmation if (isset($maturity)) { if ($maturity < MATURITY_STABLE and !$options['allow-unstable']) { $maturitylevel = get_string('maturity' . $maturity, 'admin'); if ($interactive) { cli_separator(); cli_heading(get_string('notice')); echo get_string('maturitycorewarning', 'admin', $maturitylevel) . PHP_EOL; echo get_string('morehelp') . ': ' . get_docs_url('admin/versions') . PHP_EOL; echo get_string('continue') . PHP_EOL; $prompt = get_string('cliyesnoprompt', 'admin'); $input = cli_input($prompt, '', array(get_string('clianswerno', 'admin'), get_string('cliansweryes', 'admin'))); if ($input == get_string('clianswerno', 'admin')) { exit(1); } } else { cli_problem(get_string('maturitycorewarning', 'admin', $maturitylevel)); cli_error(get_string('maturityallowunstable', 'admin')); } } } // ask for db type - show only drivers available if ($interactive) { $options['dbtype'] = strtolower($options['dbtype']);
/** * Edit/Create Admin Settings Moodle form. * * @param moodleform $mform Moodle form (passed by reference). * @param string $classname repository class name. */ public static function type_config_form($mform, $classname = 'repository') { $callbackurl = new moodle_url(self::CALLBACKURL); $a = new stdClass(); $a->docsurl = get_docs_url('Google_OAuth_2.0_setup'); $a->callbackurl = $callbackurl->out(false); $mform->addElement('static', null, '', get_string('oauthinfo', 'repository_googledocs', $a)); parent::type_config_form($mform); $mform->addElement('text', 'clientid', get_string('clientid', 'repository_googledocs')); $mform->setType('clientid', PARAM_RAW_TRIMMED); $mform->addElement('text', 'secret', get_string('secret', 'repository_googledocs')); $mform->setType('secret', PARAM_RAW_TRIMMED); $strrequired = get_string('required'); $mform->addRule('clientid', $strrequired, 'required', null, 'client'); $mform->addRule('secret', $strrequired, 'required', null, 'client'); }
/** * Return a link to moodle docs for a given capability name * * @param object $capability a capability - a row from the mdl_capabilities table. * @return string the human-readable capability name as a link to Moodle Docs. */ function get_capability_docs_link($capability) { $url = get_docs_url('Capabilities/' . $capability->name); return '<a onclick="this.target=\'docspopup\'" href="' . $url . '">' . get_capability_string($capability->name) . '</a>'; }
protected function get_risks($capability) { global $OUTPUT; $allrisks = get_all_risks(); $risksurl = new moodle_url(get_docs_url(s(get_string('risks', 'core_role')))); $return = ''; foreach ($allrisks as $type => $risk) { if ($risk & (int) $capability->riskbitmask) { if (!isset($this->icons[$type])) { $pixicon = new pix_icon('/i/' . str_replace('risk', 'risk_', $type), get_string($type . 'short', 'admin')); $this->icons[$type] = $OUTPUT->action_icon($risksurl, $pixicon, new popup_action('click', $risksurl)); } $return .= $this->icons[$type]; } } return $return; }
* Settings * * This file contains settings used by tool_mobile * * @package tool_mobile * @copyright 2016 Juan Leyva * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ defined('MOODLE_INTERNAL') || die; if ($hassiteconfig) { $ADMIN->add('root', new admin_category('mobileapp', new lang_string('mobileapp', 'tool_mobile')), 'development'); $temp = new admin_settingpage('mobilesettings', new lang_string('mobilesettings', 'tool_mobile'), 'moodle/site:config', false); // We should wait to the installation to finish since we depend on some configuration values that are set once // the admin user profile is configured. if (!during_initial_install()) { $enablemobiledocurl = new moodle_url(get_docs_url('Enable_mobile_web_services')); $enablemobiledoclink = html_writer::link($enablemobiledocurl, new lang_string('documentation')); $default = is_https() ? 1 : 0; $temp->add(new admin_setting_enablemobileservice('enablemobilewebservice', new lang_string('enablemobilewebservice', 'admin'), new lang_string('configenablemobilewebservice', 'admin', $enablemobiledoclink), $default)); } $ADMIN->add('mobileapp', $temp); // Show only mobile settings if the mobile service is enabled. if (!empty($CFG->enablemobilewebservice)) { // Type of login. $temp = new admin_settingpage('mobileauthentication', new lang_string('mobileauthentication', 'tool_mobile')); $options = array(tool_mobile\api::LOGIN_VIA_APP => new lang_string('loginintheapp', 'tool_mobile'), tool_mobile\api::LOGIN_VIA_BROWSER => new lang_string('logininthebrowser', 'tool_mobile'), tool_mobile\api::LOGIN_VIA_EMBEDDED_BROWSER => new lang_string('loginintheembeddedbrowser', 'tool_mobile')); $temp->add(new admin_setting_configselect('tool_mobile/typeoflogin', new lang_string('typeoflogin', 'tool_mobile'), new lang_string('typeoflogin_desc', 'tool_mobile'), 1, $options)); $temp->add(new admin_setting_configtext('tool_mobile/forcedurlscheme', new lang_string('forcedurlscheme_key', 'tool_mobile'), new lang_string('forcedurlscheme', 'tool_mobile'), '', PARAM_NOTAGS)); $ADMIN->add('mobileapp', $temp); // Appearance related settings. $temp = new admin_settingpage('mobileappearance', new lang_string('mobileappearance', 'tool_mobile'));
$ADMIN->add('webservicesettings', $temp); $ADMIN->add('webservicesettings', new admin_externalpage('externalservice', get_string('editaservice', 'webservice'), "$CFG->wwwroot/$CFG->admin/webservice/service.php", 'moodle/site:config', true)); $ADMIN->add('webservicesettings', new admin_externalpage('externalservicefunctions', get_string('externalservicefunctions', 'webservice'), "$CFG->wwwroot/$CFG->admin/webservice/service_functions.php", 'moodle/site:config', true)); $ADMIN->add('webservicesettings', new admin_externalpage('externalserviceusers', get_string('externalserviceusers', 'webservice'), "$CFG->wwwroot/$CFG->admin/webservice/service_users.php", 'moodle/site:config', true)); $ADMIN->add('webservicesettings', new admin_externalpage('externalserviceusersettings', get_string('serviceusersettings', 'webservice'), "$CFG->wwwroot/$CFG->admin/webservice/service_user_settings.php", 'moodle/site:config', true)); /// manage protocol page link $temp = new admin_settingpage('webserviceprotocols', get_string('manageprotocols', 'webservice')); $temp->add(new admin_setting_managewebserviceprotocols()); if (empty($CFG->enablewebservices)) { $temp->add(new admin_setting_heading('webservicesaredisabled', '', get_string('disabledwarning', 'webservice'))); } // We cannot use $OUTPUT this early, doing so means that we lose the ability // to set the page layout on all admin pages. // $wsdoclink = $OUTPUT->doc_link('How_to_get_a_security_key'); $url = new moodle_url(get_docs_url('How_to_get_a_security_key')); $wsdoclink = html_writer::tag('a', get_string('supplyinfo'),array('href'=>$url)); $temp->add(new admin_setting_configcheckbox('enablewsdocumentation', get_string('enablewsdocumentation', 'admin'), get_string('configenablewsdocumentation', 'admin', $wsdoclink), false)); $ADMIN->add('webservicesettings', $temp); /// links to protocol pages $webservices_available = get_plugin_list('webservice'); $active_webservices = empty($CFG->webserviceprotocols) ? array() : explode(',', $CFG->webserviceprotocols); foreach ($webservices_available as $webservice => $location) { if (file_exists("$location/settings.php")) { $name = get_string('pluginname', 'webservice_'.$webservice); $settings = new admin_settingpage('webservicesetting'.$webservice, $name, 'moodle/site:config', !in_array($webservice, $active_webservices) or empty($CFG->enablewebservices)); include("$location/settings.php"); if ($settings) { $ADMIN->add('webservicesettings', $settings); }
public static function type_config_form($mform, $classname = 'repository') { $a = new stdClass(); $a->docsurl = get_docs_url('Google_OAuth_2.0_setup'); $a->callbackurl = google_oauth::callback_url()->out(false); $mform->addElement('static', null, '', get_string('oauthinfo', 'repository_googledocs', $a)); parent::type_config_form($mform); $mform->addElement('text', 'clientid', get_string('clientid', 'repository_googledocs')); $mform->addElement('text', 'secret', get_string('secret', 'repository_googledocs')); $strrequired = get_string('required'); $mform->addRule('clientid', $strrequired, 'required', null, 'client'); $mform->addRule('secret', $strrequired, 'required', null, 'client'); }
public function doc_link($path, $text = '', $forcepopup = false) { $attributes['href'] = new moodle_url(get_docs_url($path)); if ($text == '') { $linktext = bootstrap::icon_help(); } else { $linktext = bootstrap::icon_help() . ' ' . $text; } return html::a($attributes, $linktext); }
/** * Returns a string containing a link to the user documentation. * Also contains an icon by default. Shown to teachers and admin only. * * @param string $path The page link after doc root and language, no leading slash. * @param string $text The text to be displayed for the link * @param string $iconpath The path to the icon to be displayed */ function doc_link($path = '', $text = '', $iconpath = '') { global $CFG; if (empty($CFG->docroot)) { return ''; } $url = get_docs_url($path); $target = ''; if (!empty($CFG->doctonewwindow)) { $target = " onclick=\"window.open('{$url}'); return false;\""; } $str = "<a href=\"{$url}\"{$target}>"; if (empty($iconpath)) { $iconpath = $CFG->httpswwwroot . '/pix/docs.gif'; } // alt left blank intentionally to prevent repetition in screenreaders $str .= '<img class="iconhelp" src="' . $iconpath . '" alt="" />' . $text . '</a>'; return $str; }
public function admin_config_form(&$mform) { $a = new stdClass; $a->docsurl = get_docs_url('Google_OAuth2_Setup'); $a->callbackurl = google_oauth::callback_url()->out(false); $mform->addElement('static', null, '', get_string('oauthinfo', 'portfolio_googledocs', $a)); $mform->addElement('text', 'clientid', get_string('clientid', 'portfolio_googledocs')); $mform->addElement('text', 'secret', get_string('secret', 'portfolio_googledocs')); $strrequired = get_string('required'); $mform->addRule('clientid', $strrequired, 'required', null, 'client'); $mform->addRule('secret', $strrequired, 'required', null, 'client'); }
function report_security_check_passwordsaltmain($detailed=false) { global $CFG; $result = new stdClass(); $result->issue = 'report_security_check_passwordsaltmain'; $result->name = get_string('check_passwordsaltmain_name', 'report_security'); $result->info = null; $result->details = null; $result->status = null; $result->link = null; if (empty($CFG->passwordsaltmain)) { $result->status = REPORT_SECURITY_WARNING; $result->info = get_string('check_passwordsaltmain_warning', 'report_security'); } else if ($CFG->passwordsaltmain === 'some long random string here with lots of characters' || trim($CFG->passwordsaltmain) === '' || preg_match('/^([a-z0-9]{0,10})$/i', $CFG->passwordsaltmain)) { $result->status = REPORT_SECURITY_WARNING; $result->info = get_string('check_passwordsaltmain_weak', 'report_security'); } else { $result->status = REPORT_SECURITY_OK; $result->info = get_string('check_passwordsaltmain_ok', 'report_security'); } if ($detailed) { $result->details = get_string('check_passwordsaltmain_details', 'report_security', get_docs_url('report/security/report_security_check_passwordsaltmain')); } return $result; }
/** * Returns HTML risk icons. * * @return string */ protected function get_role_risks_info() { global $OUTPUT; if (empty($this->roleid)) { return ''; } $risks = array(); $allrisks = get_all_risks(); foreach ($this->capabilities as $capability) { $perm = $this->permissions[$capability->name]; if ($perm != CAP_ALLOW) { continue; } foreach ($allrisks as $type => $risk) { if ($risk & (int) $capability->riskbitmask) { $risks[$type] = $risk; } } } $risksurl = new moodle_url(get_docs_url(s(get_string('risks', 'core_role')))); foreach ($risks as $type => $risk) { $pixicon = new pix_icon('/i/' . str_replace('risk', 'risk_', $type), get_string($type . 'short', 'admin')); $risks[$type] = $OUTPUT->action_icon($risksurl, $pixicon, new popup_action('click', $risksurl)); } return implode(' ', $risks); }
/** * Get the value of a help string fully prepared for display in the current language. * * @param string $identifier The identifier of the string to search for. * @param string $component The module the string is associated with. * @param boolean $ajax Whether this help is called from an AJAX script. * This is used to influence text formatting and determines * which format to output the doclink in. * @param string|object|array $a An object, string or number that can be used * within translation strings * @return Object An object containing: * - heading: Any heading that there may be for this help string. * - text: The wiki-formatted help string. * - doclink: An object containing a link, the linktext, and any additional * CSS classes to apply to that link. Only present if $ajax = false. * - completedoclink: A text representation of the doclink. Only present if $ajax = true. */ function get_formatted_help_string($identifier, $component, $ajax = false, $a = null) { global $CFG, $OUTPUT; $sm = get_string_manager(); // Do not rebuild caches here! // Devs need to learn to purge all caches after any change or disable $CFG->langstringcache. $data = new stdClass(); if ($sm->string_exists($identifier, $component)) { $data->heading = format_string(get_string($identifier, $component)); } else { // Gracefully fall back to an empty string. $data->heading = ''; } if ($sm->string_exists($identifier . '_help', $component)) { $options = new stdClass(); $options->trusted = false; $options->noclean = false; $options->smiley = false; $options->filter = false; $options->para = true; $options->newlines = false; $options->overflowdiv = !$ajax; // Should be simple wiki only MDL-21695. $data->text = format_text(get_string($identifier . '_help', $component, $a), FORMAT_MARKDOWN, $options); $helplink = $identifier . '_link'; if ($sm->string_exists($helplink, $component)) { // Link to further info in Moodle docs. $link = get_string($helplink, $component); $linktext = get_string('morehelp'); $data->doclink = new stdClass(); $url = new moodle_url(get_docs_url($link)); if ($ajax) { $data->doclink->link = $url->out(); $data->doclink->linktext = $linktext; $data->doclink->class = $CFG->doctonewwindow ? 'helplinkpopup' : ''; } else { $data->completedoclink = html_writer::tag('div', $OUTPUT->doc_link($link, $linktext), array('class' => 'helpdoclink')); } } } else { $data->text = html_writer::tag('p', html_writer::tag('strong', 'TODO') . ": missing help string [{$identifier}_help, {$component}]"); } return $data; }
/** * Test get_docs_url_standard in the special case of a link relative to wwwroot. */ public function test_get_docs_url_wwwroot() { global $CFG; $this->assertSame($CFG->wwwroot . '/lib/tests/setuplib_test.php', get_docs_url('%%WWWROOT%%/lib/tests/setuplib_test.php')); }
/** * Returns detailed information about specified exception. * @param exception $ex * @return object */ function get_exception_info($ex) { global $CFG, $DB, $SESSION; if ($ex instanceof moodle_exception) { $errorcode = $ex->errorcode; $module = $ex->module; $a = $ex->a; $link = $ex->link; $debuginfo = $ex->debuginfo; } else { $errorcode = 'generalexceptionmessage'; $module = 'error'; $a = $ex->getMessage(); $link = ''; $debuginfo = ''; } // Append the error code to the debug info to make grepping and googling easier $debuginfo .= PHP_EOL . "Error code: {$errorcode}"; $backtrace = $ex->getTrace(); $place = array('file' => $ex->getFile(), 'line' => $ex->getLine(), 'exception' => get_class($ex)); array_unshift($backtrace, $place); // Be careful, no guarantee moodlelib.php is loaded. if (empty($module) || $module == 'moodle' || $module == 'core') { $module = 'error'; } // Search for the $errorcode's associated string // If not found, append the contents of $a to $debuginfo so helpful information isn't lost if (function_exists('get_string_manager')) { if (get_string_manager()->string_exists($errorcode, $module)) { $message = get_string($errorcode, $module, $a); } elseif ($module == 'error' && get_string_manager()->string_exists($errorcode, 'moodle')) { // Search in moodle file if error specified - needed for backwards compatibility $message = get_string($errorcode, 'moodle', $a); } else { $message = $module . '/' . $errorcode; $debuginfo .= PHP_EOL . '$a contents: ' . print_r($a, true); } } else { $message = $module . '/' . $errorcode; $debuginfo .= PHP_EOL . '$a contents: ' . print_r($a, true); } // Remove some absolute paths from message and debugging info. $searches = array(); $replaces = array(); $cfgnames = array('tempdir', 'cachedir', 'localcachedir', 'themedir', 'dataroot', 'dirroot'); foreach ($cfgnames as $cfgname) { if (property_exists($CFG, $cfgname)) { $searches[] = $CFG->{$cfgname}; $replaces[] = "[{$cfgname}]"; } } if (!empty($searches)) { $message = str_replace($searches, $replaces, $message); $debuginfo = str_replace($searches, $replaces, $debuginfo); } // Be careful, no guarantee weblib.php is loaded. if (function_exists('clean_text')) { $message = clean_text($message); } else { $message = htmlspecialchars($message); } if (!empty($CFG->errordocroot)) { $errordoclink = $CFG->errordocroot . '/en/'; } else { $errordoclink = get_docs_url(); } if ($module === 'error') { $modulelink = 'moodle'; } else { $modulelink = $module; } $moreinfourl = $errordoclink . 'error/' . $modulelink . '/' . $errorcode; if (empty($link)) { if (!empty($SESSION->fromurl)) { $link = $SESSION->fromurl; unset($SESSION->fromurl); } else { $link = $CFG->wwwroot . '/'; } } // When printing an error the continue button should never link offsite. // We cannot use clean_param() here as it is not guaranteed that it has been loaded yet. $httpswwwroot = str_replace('http:', 'https:', $CFG->wwwroot); if (stripos($link, $CFG->wwwroot) === 0) { // Internal HTTP, all good. } else { if (!empty($CFG->loginhttps) && stripos($link, $httpswwwroot) === 0) { // Internal HTTPS, all good. } else { // External link spotted! $link = $CFG->wwwroot . '/'; } } $info = new stdClass(); $info->message = $message; $info->errorcode = $errorcode; $info->backtrace = $backtrace; $info->link = $link; $info->moreinfourl = $moreinfourl; $info->a = $a; $info->debuginfo = $debuginfo; return $info; }
/** * Returns detailed information about specified exception. * @param exception $ex * @return object */ function get_exception_info($ex) { global $CFG, $DB, $SESSION; if ($ex instanceof moodle_exception) { $errorcode = $ex->errorcode; $module = $ex->module; $a = $ex->a; $link = $ex->link; $debuginfo = $ex->debuginfo; } else { $errorcode = 'generalexceptionmessage'; $module = 'error'; $a = $ex->getMessage(); $link = ''; $debuginfo = ''; } // Append the error code to the debug info to make grepping and googling easier $debuginfo .= PHP_EOL . "Error code: {$errorcode}"; $backtrace = $ex->getTrace(); $place = array('file' => $ex->getFile(), 'line' => $ex->getLine(), 'exception' => get_class($ex)); array_unshift($backtrace, $place); // Be careful, no guarantee moodlelib.php is loaded. if (empty($module) || $module == 'moodle' || $module == 'core') { $module = 'error'; } // Search for the $errorcode's associated string // If not found, append the contents of $a to $debuginfo so helpful information isn't lost if (function_exists('get_string_manager')) { if (get_string_manager()->string_exists($errorcode, $module)) { $message = get_string($errorcode, $module, $a); } elseif ($module == 'error' && get_string_manager()->string_exists($errorcode, 'moodle')) { // Search in moodle file if error specified - needed for backwards compatibility $message = get_string($errorcode, 'moodle', $a); } else { $message = $module . '/' . $errorcode; $debuginfo .= PHP_EOL . '$a contents: ' . print_r($a, true); } } else { $message = $module . '/' . $errorcode; $debuginfo .= PHP_EOL . '$a contents: ' . print_r($a, true); } // Be careful, no guarantee weblib.php is loaded. if (function_exists('clean_text')) { $message = clean_text($message); } else { $message = htmlspecialchars($message); } if (!empty($CFG->errordocroot)) { $errordoclink = $CFG->errordocroot . '/en/'; } else { $errordoclink = get_docs_url(); } if ($module === 'error') { $modulelink = 'moodle'; } else { $modulelink = $module; } $moreinfourl = $errordoclink . 'error/' . $modulelink . '/' . $errorcode; if (empty($link)) { if (!empty($SESSION->fromurl)) { $link = $SESSION->fromurl; unset($SESSION->fromurl); } else { $link = $CFG->wwwroot . '/'; } } // when printing an error the continue button should never link offsite if (stripos($link, $CFG->wwwroot) === false && stripos($link, $CFG->httpswwwroot) === false) { $link = $CFG->wwwroot . '/'; } $info = new stdClass(); $info->message = $message; $info->errorcode = $errorcode; $info->backtrace = $backtrace; $info->link = $link; $info->moreinfourl = $moreinfourl; $info->a = $a; $info->debuginfo = $debuginfo; return $info; }
/** * Returns a string containing a link to the user documentation. * Also contains an icon by default. Shown to teachers and admin only. * @param string $path The page link after doc root and language, no leading slash. * @param string $text The text to be displayed for the link * @return string */ public function doc_link($path, $text = '') { global $CFG; $icon = $this->pix_icon('docs', $text, 'moodle', array('class' => 'iconhelp')); $url = new moodle_url(get_docs_url($path)); $attributes = array('href' => $url); if (!empty($CFG->doctonewwindow)) { $attributes['id'] = $this->add_action_handler(new popup_action('click', $url)); } return html_writer::tag('a', $icon . $text, $attributes); }
/** * Print warning about changed grades during upgrade to 2.8. * * @param int $courseid The current course id. * @param context $context The course context. * @param string $thispage The relative path for the current page. E.g. /grade/report/user/index.php * @param boolean $return return as string * * @return nothing or string if $return true */ function print_natural_aggregation_upgrade_notice($courseid, $context, $thispage, $return = false) { global $CFG, $OUTPUT; $html = ''; // Do not do anything if they cannot manage the grades of this course. if (!has_capability('moodle/grade:manage', $context)) { return $html; } $hidesubcatswarning = optional_param('seenaggregatesubcatsupgradedgrades', false, PARAM_BOOL) && confirm_sesskey(); $showsubcatswarning = get_config('core', 'show_aggregatesubcats_upgrade_' . $courseid); $hidenaturalwarning = optional_param('seensumofgradesupgradedgrades', false, PARAM_BOOL) && confirm_sesskey(); $shownaturalwarning = get_config('core', 'show_sumofgrades_upgrade_' . $courseid); $hideminmaxwarning = optional_param('seenminmaxupgradedgrades', false, PARAM_BOOL) && confirm_sesskey(); $showminmaxwarning = get_config('core', 'show_min_max_grades_changed_' . $courseid); $useminmaxfromgradeitem = optional_param('useminmaxfromgradeitem', false, PARAM_BOOL) && confirm_sesskey(); $useminmaxfromgradegrade = optional_param('useminmaxfromgradegrade', false, PARAM_BOOL) && confirm_sesskey(); $minmaxtouse = grade_get_setting($courseid, 'minmaxtouse', $CFG->grade_minmaxtouse); $gradebookcalculationsfreeze = get_config('core', 'gradebook_calculations_freeze_' . $courseid); $acceptgradebookchanges = optional_param('acceptgradebookchanges', false, PARAM_BOOL) && confirm_sesskey(); // Hide the warning if the user told it to go away. if ($hidenaturalwarning) { hide_natural_aggregation_upgrade_notice($courseid); } // Hide the warning if the user told it to go away. if ($hidesubcatswarning) { hide_aggregatesubcats_upgrade_notice($courseid); } // Hide the min/max warning if the user told it to go away. if ($hideminmaxwarning) { grade_hide_min_max_grade_upgrade_notice($courseid); $showminmaxwarning = false; } if ($useminmaxfromgradegrade) { // Revert to the new behaviour, we now use the grade_grade for min/max. grade_upgrade_use_min_max_from_grade_grade($courseid); grade_hide_min_max_grade_upgrade_notice($courseid); $showminmaxwarning = false; } else { if ($useminmaxfromgradeitem) { // Apply the new logic, we now use the grade_item for min/max. grade_upgrade_use_min_max_from_grade_item($courseid); grade_hide_min_max_grade_upgrade_notice($courseid); $showminmaxwarning = false; } } if (!$hidenaturalwarning && $shownaturalwarning) { $message = get_string('sumofgradesupgradedgrades', 'grades'); $hidemessage = get_string('upgradedgradeshidemessage', 'grades'); $urlparams = array('id' => $courseid, 'seensumofgradesupgradedgrades' => true, 'sesskey' => sesskey()); $goawayurl = new moodle_url($thispage, $urlparams); $goawaybutton = $OUTPUT->single_button($goawayurl, $hidemessage, 'get'); $html .= $OUTPUT->notification($message, 'notifysuccess'); $html .= $goawaybutton; } if (!$hidesubcatswarning && $showsubcatswarning) { $message = get_string('aggregatesubcatsupgradedgrades', 'grades'); $hidemessage = get_string('upgradedgradeshidemessage', 'grades'); $urlparams = array('id' => $courseid, 'seenaggregatesubcatsupgradedgrades' => true, 'sesskey' => sesskey()); $goawayurl = new moodle_url($thispage, $urlparams); $goawaybutton = $OUTPUT->single_button($goawayurl, $hidemessage, 'get'); $html .= $OUTPUT->notification($message, 'notifysuccess'); $html .= $goawaybutton; } if ($showminmaxwarning) { $hidemessage = get_string('upgradedgradeshidemessage', 'grades'); $urlparams = array('id' => $courseid, 'seenminmaxupgradedgrades' => true, 'sesskey' => sesskey()); $goawayurl = new moodle_url($thispage, $urlparams); $hideminmaxbutton = $OUTPUT->single_button($goawayurl, $hidemessage, 'get'); $moreinfo = html_writer::link(get_docs_url(get_string('minmaxtouse_link', 'grades')), get_string('moreinfo'), array('target' => '_blank')); if ($minmaxtouse == GRADE_MIN_MAX_FROM_GRADE_ITEM) { // Show the message that there were min/max issues that have been resolved. $message = get_string('minmaxupgradedgrades', 'grades') . ' ' . $moreinfo; $revertmessage = get_string('upgradedminmaxrevertmessage', 'grades'); $urlparams = array('id' => $courseid, 'useminmaxfromgradegrade' => true, 'sesskey' => sesskey()); $reverturl = new moodle_url($thispage, $urlparams); $revertbutton = $OUTPUT->single_button($reverturl, $revertmessage, 'get'); $html .= $OUTPUT->notification($message); $html .= $revertbutton . $hideminmaxbutton; } else { if ($minmaxtouse == GRADE_MIN_MAX_FROM_GRADE_GRADE) { // Show the warning that there are min/max issues that have not be resolved. $message = get_string('minmaxupgradewarning', 'grades') . ' ' . $moreinfo; $fixmessage = get_string('minmaxupgradefixbutton', 'grades'); $urlparams = array('id' => $courseid, 'useminmaxfromgradeitem' => true, 'sesskey' => sesskey()); $fixurl = new moodle_url($thispage, $urlparams); $fixbutton = $OUTPUT->single_button($fixurl, $fixmessage, 'get'); $html .= $OUTPUT->notification($message); $html .= $fixbutton . $hideminmaxbutton; } } } if ($gradebookcalculationsfreeze) { if ($acceptgradebookchanges) { // Accept potential changes in grades caused by extra credit bug MDL-49257. hide_gradebook_calculations_freeze_notice($courseid); $courseitem = grade_item::fetch_course_item($courseid); $courseitem->force_regrading(); grade_regrade_final_grades($courseid); $html .= $OUTPUT->notification(get_string('gradebookcalculationsuptodate', 'grades'), 'notifysuccess'); } else { // Show the warning that there may be extra credit weights problems. $a = new stdClass(); $a->gradebookversion = $gradebookcalculationsfreeze; if (preg_match('/(\\d{8,})/', $CFG->release, $matches)) { $a->currentversion = $matches[1]; } else { $a->currentversion = $CFG->release; } $a->url = get_docs_url('Gradebook_calculation_changes'); $message = get_string('gradebookcalculationswarning', 'grades', $a); $fixmessage = get_string('gradebookcalculationsfixbutton', 'grades'); $urlparams = array('id' => $courseid, 'acceptgradebookchanges' => true, 'sesskey' => sesskey()); $fixurl = new moodle_url($thispage, $urlparams); $fixbutton = $OUTPUT->single_button($fixurl, $fixmessage, 'get'); $html .= $OUTPUT->notification($message); $html .= $fixbutton; } } if (!empty($html)) { $html = html_writer::tag('div', $html, array('class' => 'core_grades_notices')); } if ($return) { return $html; } else { echo $html; } }
/** * Render the icon for a risk. * @param string $type capability risk type. * @return string the HTML to output. */ protected function risk_icon($type) { $url = get_docs_url(s(get_string('risks', 'role'))); return $this->action_icon($url, new pix_icon('i/' . str_replace('risk', 'risk_', $type), get_string($type . 'short', 'admin')), new popup_action('click', $url, 'docspopup')); }