/** * */ public function get_replacements(array $patterns, $entry = null, array $options = array()) { global $CFG, $OUTPUT; $replacements = parent::get_replacements($patterns, $entry, $options); $view = $this->_view; $df = $view->get_df(); $filter = $view->get_filter(); $baseurl = new moodle_url($view->get_baseurl()); $baseurl->param('sesskey', sesskey()); foreach ($patterns as $pattern) { switch ($pattern) { case '##exportall##': $actionurl = new moodle_url($baseurl, array('pdfexportall' => true)); $label = html_writer::tag('span', get_string('exportall', 'dataformview_pdf')); $replacements[$pattern] = html_writer::link($actionurl, $label, array('class' => 'actionlink exportall')); break; case '##exportpage##': $actionurl = new moodle_url($baseurl, array('pdfexportpage' => true)); $label = html_writer::tag('span', get_string('exportpage', 'dataformview_pdf')); $replacements[$pattern] = html_writer::link($actionurl, $label, array('class' => 'actionlink exportpage')); break; case '##pagebreak##': $replacements[$pattern] = $view::PAGE_BREAK; break; } } return $replacements; }
/** * Adds module specific settings to the settings block. * * @param settings_navigation $settings The settings navigation object * @param stdClass $context The node context */ function local_loginas_extends_settings_navigation(settings_navigation $settings, $context) { global $DB, $CFG, $PAGE, $USER; // Course id and context. $courseid = !empty($PAGE->course->id) ? $PAGE->course->id : SITEID; $coursecontext = context_course::instance($courseid); // Must have the loginas capability. if (!has_capability('moodle/user:loginas', $coursecontext)) { return; } // Set the settings category. $loginas = $settings->add(get_string('loginas')); // Login as list by admin setting. if (is_siteadmin($USER)) { // Admin settings page. $url = new moodle_url('/admin/settings.php', array('section' => 'localsettingloginas')); $loginas->add(get_string('settings'), $url, $settings::TYPE_SETTING); // Users list. $loginasusers = array(); // Since 2.6, use all the required fields. $ufields = 'id, ' . get_all_user_name_fields(true); // Get users by id. if ($configuserids = get_config('local_loginas', 'loginasusers')) { $userids = explode(',', $configuserids); if ($users = $DB->get_records_list('user', 'id', $userids, '', $ufields)) { $loginasusers = $users; } } // Get users by username. if ($configusernames = get_config('local_loginas', 'loginasusernames')) { $usernames = explode(',', $configusernames); if ($users = $DB->get_records_list('user', 'username', $usernames, '', $ufields)) { $loginasusers = $loginasusers + $users; } } // Add action links for specified users. if ($loginasusers) { $params = array('id' => $courseid, 'sesskey' => sesskey()); foreach ($loginasusers as $userid => $lauser) { $url = new moodle_url('/course/loginas.php', $params); $url->param('user', $userid); $loginas->add(fullname($lauser, true), $url, $settings::TYPE_SETTING); } } } // Course users login as. if (!($configcourseusers = get_config('local_loginas', 'courseusers'))) { return; } $loggedinas = \core\session\manager::is_loggedinas(); if (!$loggedinas) { // Ajax link. $node = $loginas->add(get_string('courseusers', 'local_loginas'), 'javascript:void();', $settings::TYPE_SETTING); $node->add_class('local_loginas_setting_link'); local_loginas_require_js($PAGE); } }
/** * Constructor. * @param Command $command The Command to link to the form. * @param int $mode The form mode. */ public function __construct(Command $command, $mode) { // Checking command. if (is_null($command)) { throw new Command_Exception('commandformnotlinked'); } // Linking the command and her category. $this->command = $command; // Setting configuration. $this->mode = $mode; // Setting form action. switch ($mode) { case self::MODE_COMMAND_CHOICE: $url = new moodle_url('/local/vmoodle/view.php', array('view' => 'sadmin', 'what' => 'validateassistedcommand')); break; case self::MODE_RETRIEVE_PLATFORM: $url = new moodle_url('/local/vmoodle/view.php', array('view' => 'sadmin', 'what' => 'gettargetbyvalue')); break; case self::MODE_DISPLAY_COMMAND: $url = new moodle_url('/local/vmoodle/view.php', array('view' => 'targetchoice')); break; default: throw new Command_Exception('badformmode'); break; } // Calling parent's constructor. parent::__construct($url->out()); }
function update_questionbank() { global $USER, $FULLME; $myurl = new moodle_url($FULLME); $myurl->param('first', 'second'); //print_object($myurl->get_query_string()); //notice('die please'); $qid = optional_param('qid', null); $theQuestion = optional_param('question', null); if (empty($theQuestion)) { return; } $question = get_record('memorybank_bank', 'id', $qid); print_object($question); $question->question = optional_param('question', null); $question->answer = optional_param('answer', null); $question->reference = optional_param('reference', null); $question->initialgrade = optional_param('initialgrade', 4); $question->category = optional_param('category', 0); $question->visible = optional_param('visible', 0); $initviewtime = optional_param('initviewtime', 0); $question->initviewtime = make_timestamp($initviewtime['year'], $initviewtime['month'], $initviewtime['day'], $initviewtime['hour'], $initviewtime['minute']); $question->modifiedby = $USER->id; $question->timemodified = time(); print_object($question); update_record('memorybank_bank', $question); }
public function destination_courses_selector(moodle_url $nextstageurl, destination_courses_search $courses = null, $courseid) { $html = html_writer::start_tag('div', array('class' => 'import-course-selector backup-restore')); $html .= html_writer::start_tag('form', array('method' => 'post', 'action' => $nextstageurl->out_omit_querystring())); foreach ($nextstageurl->params() as $key => $value) { $html .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => $key, 'value' => $value)); } $html .= html_writer::start_tag('div', array('class' => 'ics-existing-group backup-section')); $html .= $this->output->heading(get_string('selectgroups', 'local_syncgroups'), 2, array('class' => 'header')); $html .= html_writer::start_tag('ul'); $groups = groups_get_all_groups($courseid, 0, 0, 'g.id, g.name'); foreach ($groups as $group) { $html .= html_writer::start_tag('li') . html_writer::checkbox('groups[]', $group->id, false, $group->name) . html_writer::end_tag('li'); } $html .= html_writer::end_tag('ul'); $html .= html_writer::end_tag('div'); // We only allow import adding for now. Enforce it here. $html .= html_writer::start_tag('div', array('class' => 'ics-existing-course backup-section')); $html .= $this->output->heading(get_string('syncgroupsto', 'local_syncgroups'), 2, array('class' => 'header')); $html .= $this->backup_detail_pair(get_string('selectacourse', 'backup'), $this->render($courses)); $html .= $this->backup_detail_pair('', html_writer::empty_tag('input', array('type' => 'submit', 'value' => get_string('continue')))); $html .= html_writer::end_tag('div'); $html .= html_writer::end_tag('form'); $html .= html_writer::end_tag('div'); return $html; }
function build_editform($item, $feedback, $cm) { global $DB; $editurl = new moodle_url('/mod/feedback/edit.php', array('id' => $cm->id)); //ther are no settings for recaptcha if (isset($item->id) and $item->id > 0) { notice(get_string('there_are_no_settings_for_recaptcha', 'feedback'), $editurl->out()); exit; } //only one recaptcha can be in a feedback if ($DB->record_exists('feedback_item', array('feedback' => $feedback->id, 'typ' => $this->type))) { notice(get_string('only_one_captcha_allowed', 'feedback'), $editurl->out()); exit; } $this->item = $item; $this->feedback = $feedback; $this->item_form = true; //dummy $lastposition = $DB->count_records('feedback_item', array('feedback' => $feedback->id)); $this->item->feedback = $feedback->id; $this->item->template = 0; $this->item->name = get_string('captcha', 'feedback'); $this->item->label = get_string('captcha', 'feedback'); $this->item->presentation = ''; $this->item->typ = $this->type; $this->item->hasvalue = $this->get_hasvalue(); $this->item->position = $lastposition + 1; $this->item->required = 1; $this->item->dependitem = 0; $this->item->dependvalue = ''; $this->item->options = ''; }
/** * Checks whether the given URL is blacklisted by checking its address and port number against the black/white lists. * The behaviour of this function can be classified as strict, as it returns true for URLs which are invalid or * could not be parsed, as well as those valid URLs which were found in the blacklist. * * @param string $urlstring the URL to check. * @return bool true if the URL is blacklisted or invalid and false if the URL is not blacklisted. */ public function url_is_blocked($urlstring) { // If no config data is present, then all hosts/ports are allowed. if (!$this->is_enabled()) { return false; } // Try to parse the URL to get the 'host' and 'port' components. try { $url = new \moodle_url($urlstring); $parsed['scheme'] = $url->get_scheme(); $parsed['host'] = $url->get_host(); $parsed['port'] = $url->get_port(); } catch (\moodle_exception $e) { // Moodle exception is thrown if the $urlstring is invalid. Treat as blocked. return true; } // The port will be empty unless explicitly set in the $url (uncommon), so try to infer it from the supported schemes. if (!$parsed['port'] && $parsed['scheme'] && isset($this->transportschemes[$parsed['scheme']])) { $parsed['port'] = $this->transportschemes[$parsed['scheme']]; } if ($parsed['port'] && $parsed['host']) { // Check the host and port against the blacklist/whitelist entries. return $this->host_is_blocked($parsed['host']) || $this->port_is_blocked($parsed['port']); } return true; }
/** * Render the badge element (message count) * * @param null $userid * @return string */ public function badge($userid = null) { global $USER, $DB, $COURSE, $PAGE; // Only for logged in folks and when we are enabled. if (!isset($USER->message_badge_disabled)) { if (mr_off('badge', 'message') or !isloggedin() or isguestuser()) { $USER->message_badge_disabled = true; } else { $USER->message_badge_disabled = $DB->record_exists('message_processors', array('name' => 'badge', 'enabled' => 0)); } } if ($USER->message_badge_disabled) { return ''; } if ($this->is_mobile()) { return $this->mobile($userid); } $repo = new message_output_badge_repository_message(); $forwardurl = new moodle_url('/message/output/badge/view.php', array('action' => 'forward', 'courseid' => $COURSE->id)); $total = $repo->count_user_unread_messages($userid); $PAGE->requires->js_init_call('M.snap_message_badge.init_badge', array($forwardurl->out(false), $COURSE->id), false, $this->get_js_module()); if (!empty($total)) { $countdiv = html_writer::tag('span', $total, array('id' => html_writer::random_id(), 'class' => 'message_badge_count')); } else { $countdiv = ''; } return $countdiv; }
/** * Sets up the edit page * * @param string $baseurl the base url of the * * @return array Array of variables that the page is set up with */ public function setup_page($baseurl) { global $PAGE, $CFG, $DB; $this->pagevars = array(); $pageurl = new \moodle_url($baseurl); $pageurl->remove_all_params(); $id = optional_param('cmid', false, PARAM_INT); $quizid = optional_param('quizid', false, PARAM_INT); // get necessary records from the DB if ($id) { $cm = get_coursemodule_from_id('activequiz', $id, 0, false, MUST_EXIST); $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST); $quiz = $DB->get_record('activequiz', array('id' => $cm->instance), '*', MUST_EXIST); } else { $quiz = $DB->get_record('activequiz', array('id' => $quizid), '*', MUST_EXIST); $course = $DB->get_record('course', array('id' => $quiz->course), '*', MUST_EXIST); $cm = get_coursemodule_from_instance('activequiz', $quiz->id, $course->id, false, MUST_EXIST); } $this->get_parameters(); // get the rest of the parameters and set them in the class if ($CFG->version < 2011120100) { $this->context = get_context_instance(CONTEXT_MODULE, $cm->id); } else { $this->context = \context_module::instance($cm->id); } // set up question lib list($this->pageurl, $this->contexts, $cmid, $cm, $quiz, $this->pagevars) = question_edit_setup('editq', '/mod/activequiz/edit.php', true); $PAGE->set_url($this->pageurl); $this->pagevars['pageurl'] = $this->pageurl; $PAGE->set_title(strip_tags($course->shortname . ': ' . get_string("modulename", "activequiz") . ': ' . format_string($quiz->name, true))); $PAGE->set_heading($course->fullname); // setup classes needed for the edit page $this->RTQ = new \mod_activequiz\activequiz($cm, $course, $quiz, $this->pagevars); $this->RTQ->get_renderer()->init($this->RTQ, $this->pageurl, $this->pagevars); }
/** * Internal function - creates htmls structure suitable for YUI tree. */ protected function htmllize_tree($tree, $dir) { global $CFG; if (empty($dir['subdirs']) and empty($dir['files'])) { return ''; } $browser = get_file_browser(); $result = '<ul>'; foreach ($dir['subdirs'] as $subdir) { $image = $this->output->pix_icon(file_folder_icon(24), $subdir['dirname'], 'moodle'); $filename = html_writer::tag('span', $image, array('class' => 'fp-icon')). html_writer::tag('span', s($subdir['dirname']), array('class' => 'fp-filename')); $filename = html_writer::tag('div', $filename, array('class' => 'fp-filename-icon')); $result .= html_writer::tag('li', $filename. $this->htmllize_tree($tree, $subdir)); } foreach ($dir['files'] as $file) { $fileinfo = $browser->get_file_info($tree->context, $file->get_component(), $file->get_filearea(), $file->get_itemid(), $file->get_filepath(), $file->get_filename()); $url = $fileinfo->get_url(true); $filename = $file->get_filename(); if ($imageinfo = $fileinfo->get_imageinfo()) { $fileurl = new moodle_url($fileinfo->get_url()); $image = $fileurl->out(false, array('preview' => 'tinyicon', 'oid' => $fileinfo->get_timemodified())); $image = html_writer::empty_tag('img', array('src' => $image)); } else { $image = $this->output->pix_icon(file_file_icon($file, 24), $filename, 'moodle'); } $filename = html_writer::tag('span', $image, array('class' => 'fp-icon')). html_writer::tag('span', $filename, array('class' => 'fp-filename')); $filename = html_writer::tag('span', html_writer::link($url, $filename), array('class' => 'fp-filename-icon')); $result .= html_writer::tag('li', $filename); } $result .= '</ul>'; return $result; }
/** * Adds the item in course settings navigation to toggle modchooser * * Theme can overwrite as an empty function to exclude it (for example if theme does not * use modchooser at all) */ protected function add_modchoosertoggle() { global $CFG; static $modchoosertoggleadded = false; // Add the module chooser toggle to the course page if ($modchoosertoggleadded || $this->page->state > moodle_page::STATE_PRINTING_HEADER || $this->page->course->id == SITEID || !$this->page->user_is_editing() || !($context = context_course::instance($this->page->course->id)) || !has_capability('moodle/course:update', $context) || !course_ajax_enabled($this->page->course) || !($coursenode = $this->page->settingsnav->find('courseadmin', navigation_node::TYPE_COURSE)) || !$coursenode->get('editsettings')) { // too late or we are on site page or we could not find the course settings node // or we are not allowed to edit return; } $modchoosertoggleadded = true; if ($this->page->url->compare(new moodle_url('/course/view.php'), URL_MATCH_BASE)) { // We are on the course page, retain the current page params e.g. section. $modchoosertoggleurl = clone $this->page->url; } else { // Edit on the main course page. $modchoosertoggleurl = new moodle_url('/course/view.php', array('id' => $this->page->course->id, 'return' => $this->page->url->out_as_local_url(false))); } $modchoosertoggleurl->param('sesskey', sesskey()); if ($usemodchooser = get_user_preferences('usemodchooser', $CFG->modchooserdefault)) { $modchoosertogglestring = get_string('modchooserdisable', 'moodle'); $modchoosertoggleurl->param('modchooser', 'off'); } else { $modchoosertogglestring = get_string('modchooserenable', 'moodle'); $modchoosertoggleurl->param('modchooser', 'on'); } $modchoosertoggle = navigation_node::create($modchoosertogglestring, $modchoosertoggleurl, navigation_node::TYPE_SETTING); $coursenode->add_node($modchoosertoggle, 'editsettings'); $modchoosertoggle->add_class('modchoosertoggle'); $modchoosertoggle->add_class('visibleifjs'); user_preference_allow_ajax_update('usemodchooser', PARAM_BOOL); }
/** * Customises the backup progress bar * * @global moodle_page $PAGE * @return array */ public function get_progress_bar() { global $PAGE; $stage = self::STAGE_COMPLETE; $currentstage = $this->stage->get_stage(); $items = array(); while ($stage > 0) { $classes = array('backup_stage'); if (floor($stage / 2) == $currentstage) { $classes[] = 'backup_stage_next'; } else { if ($stage == $currentstage) { $classes[] = 'backup_stage_current'; } else { if ($stage < $currentstage) { $classes[] = 'backup_stage_complete'; } } } $item = array('text' => strlen(decbin($stage * 2)) . '. ' . get_string('importcurrentstage' . $stage, 'backup'), 'class' => join(' ', $classes)); if ($stage < $currentstage && $currentstage < self::STAGE_COMPLETE && (!self::$skipcurrentstage || $stage * 2 != $currentstage)) { $item['link'] = new moodle_url($PAGE->url, $this->stage->get_params() + array('backup' => $this->get_backupid(), 'stage' => $stage)); } array_unshift($items, $item); $stage = floor($stage / 2); } $selectorlink = new moodle_url($PAGE->url, $this->stage->get_params()); $selectorlink->remove_params('importid'); array_unshift($items, array('text' => '1. ' . get_string('importcurrentstage0', 'backup'), 'class' => join(' ', $classes), 'link' => $selectorlink)); return $items; }
/** * Set up the columns and headers and other properties of the table and then * call flexible_table::setup() method. * * @param moodle_url $reporturl the URL to redisplay this report. * @param object $question a question with a _stats field * @param bool $hassubqs */ public function question_setup($reporturl, $questiondata, offlinequiz_statistics_response_analyser $responsestats) { $this->questiondata = $questiondata; $this->define_baseurl($reporturl->out()); $this->collapsible(false); $this->set_attribute('class', 'generaltable generalbox boxaligncenter'); // Define the table columns. $columns = array(); $headers = array(); $columns[] = 'part'; $headers[] = ''; $columns[] = 'response'; $headers[] = get_string('response', 'offlinequiz_statistics'); $columns[] = 'fraction'; $headers[] = get_string('optiongrade', 'offlinequiz_statistics'); $columns[] = 'count'; $headers[] = get_string('count', 'offlinequiz_statistics'); $columns[] = 'frequency'; $headers[] = get_string('frequency', 'offlinequiz_statistics'); $this->define_columns($columns); $this->define_headers($headers); $this->sortable(false); $this->column_class('fraction', 'numcol'); $this->column_class('count', 'numcol'); $this->column_class('frequency', 'numcol'); $this->column_suppress('part'); $this->column_suppress('responseclass'); parent::setup(); }
function get_content() { global $CFG, $OUTPUT; if ($this->content !== NULL) { return $this->content; } $this->content = new stdClass(); $this->content->items = array(); $this->content->icons = array(); $this->content->footer = ''; if (!defined('FEEDBACK_BLOCK_LIB_IS_OK')) { $this->content->items = array(get_string('missing_feedback_module', 'block_feedback')); return $this->content; } $courseid = $this->page->course->id; if ($courseid <= 0) { $courseid = SITEID; } $icon = '<img src="' . $OUTPUT->pix_url('icon', 'feedback') . '" class="icon" alt="" />'; if (empty($this->instance->pageid)) { $this->instance->pageid = SITEID; } if ($feedbacks = feedback_get_feedbacks_from_sitecourse_map($courseid)) { $baseurl = new moodle_url('/mod/feedback/view.php'); foreach ($feedbacks as $feedback) { $url = new moodle_url($baseurl); $url->params(array('id' => $feedback->cmid, 'courseid' => $courseid)); $this->content->items[] = '<a href="' . $url->out() . '">' . $icon . $feedback->name . '</a>'; } } return $this->content; }
/** * Constructor of dropbox plugin * * @param int $repositoryid * @param stdClass $context * @param array $options */ public function __construct($repositoryid, $context = SYSCONTEXTID, $options = array()) { global $CFG; $options['page'] = optional_param('p', 1, PARAM_INT); parent::__construct($repositoryid, $context, $options); $this->setting = 'dropbox_'; $this->dropbox_key = $this->get_option('dropbox_key'); $this->dropbox_secret = $this->get_option('dropbox_secret'); // one day $this->cachedfilettl = 60 * 60 * 24; if (isset($options['access_key'])) { $this->access_key = $options['access_key']; } else { $this->access_key = get_user_preferences($this->setting . '_access_key', ''); } if (isset($options['access_secret'])) { $this->access_secret = $options['access_secret']; } else { $this->access_secret = get_user_preferences($this->setting . '_access_secret', ''); } if (!empty($this->access_key) && !empty($this->access_secret)) { $this->logged = true; } $callbackurl = new moodle_url($CFG->wwwroot . '/repository/repository_callback.php', array('callback' => 'yes', 'repo_id' => $repositoryid)); $args = array('oauth_consumer_key' => $this->dropbox_key, 'oauth_consumer_secret' => $this->dropbox_secret, 'oauth_callback' => $callbackurl->out(false), 'api_root' => 'https://www.dropbox.com/1/oauth'); $this->dropbox = new dropbox($args); }
/** * Get the path to a JavaScript library. * @param $libname - the name of the library whose path we need. * @return string */ function ajax_get_lib($libname) { global $CFG, $HTTPSPAGEREQUIRED; $libpath = ''; $translatelist = array('yui_yahoo' => '/lib/yui/yahoo/yahoo-min.js', 'yui_animation' => '/lib/yui/animation/animation-min.js', 'yui_autocomplete' => '/lib/yui/autocomplete/autocomplete-min.js', 'yui_button' => '/lib/yui/button/button-min.js', 'yui_calendar' => '/lib/yui/calendar/calendar-min.js', 'yui_charts' => '/lib/yui/charts/charts-experimental-min.js', 'yui_colorpicker' => '/lib/yui/colorpicker/colorpicker-min.js', 'yui_connection' => '/lib/yui/connection/connection-min.js', 'yui_container' => '/lib/yui/container/container-min.js', 'yui_cookie' => '/lib/yui/cookie/cookie-min.js', 'yui_datasource' => '/lib/yui/datasource/datasource-min.js', 'yui_datatable' => '/lib/yui/datatable/datatable-min.js', 'yui_dom' => '/lib/yui/dom/dom-min.js', 'yui_dom-event' => '/lib/yui/yahoo-dom-event/yahoo-dom-event.js', 'yui_dragdrop' => '/lib/yui/dragdrop/dragdrop-min.js', 'yui_editor' => '/lib/yui/editor/editor-min.js', 'yui_element' => '/lib/yui/element/element-beta-min.js', 'yui_event' => '/lib/yui/event/event-min.js', 'yui_get' => '/lib/yui/get/get-min.js', 'yui_history' => '/lib/yui/history/history-min.js', 'yui_imagecropper' => '/lib/yui/imagecropper/imagecropper-beta-min.js', 'yui_imageloader' => '/lib/yui/imageloader/imageloader-min.js', 'yui_json' => '/lib/yui/json/json-min.js', 'yui_layout' => '/lib/yui/layout/layout-min.js', 'yui_logger' => '/lib/yui/logger/logger-min.js', 'yui_menu' => '/lib/yui/menu/menu-min.js', 'yui_profiler' => '/lib/yui/profiler/profiler-min.js', 'yui_profilerviewer' => '/lib/yui/profilerviewer/profilerviewer-beta-min.js', 'yui_resize' => '/lib/yui/resize/resize-min.js', 'yui_selector' => '/lib/yui/selector/selector-beta-min.js', 'yui_simpleeditor' => '/lib/yui/editor/simpleeditor-min.js', 'yui_slider' => '/lib/yui/slider/slider-min.js', 'yui_tabview' => '/lib/yui/tabview/tabview-min.js', 'yui_treeview' => '/lib/yui/treeview/treeview-min.js', 'yui_uploader' => '/lib/yui/uploader/uploader-experimental-min.js', 'yui_utilities' => '/lib/yui/utilities/utilities.js', 'yui_yuiloader' => '/lib/yui/yuiloader/yuiloader-min.js', 'yui_yuitest' => '/lib/yui/yuitest/yuitest-min.js', 'ajaxcourse_blocks' => '/lib/ajax/block_classes.js', 'ajaxcourse_sections' => '/lib/ajax/section_classes.js', 'ajaxcourse' => '/lib/ajax/ajaxcourse.js'); if (!empty($HTTPSPAGEREQUIRED)) { $wwwroot = $CFG->httpswwwroot; } else { $wwwroot = $CFG->wwwroot; } if (array_key_exists($libname, $translatelist)) { $libpath = $wwwroot . $translatelist[$libname]; } else { $libpath = $libname; } // query strings break file_exists so remove it $url = new moodle_url($libpath); $modifiedlibpath = $url->out(true); $testpath = str_replace($wwwroot, $CFG->dirroot, $modifiedlibpath); if (stripos($libpath, $CFG->wwwroot) === false && stripos($libpath, $CFG->dirroot) === false) { // offsite so just link it } elseif (!file_exists($testpath)) { error('require_js: ' . $libpath . ' - file not found.'); } return $libpath; }
/** * Add autocomplete to a form text field * * @param MoodleQuickForm $mform Moodle form * @param array|moodle_url $options Array of autocomplete options, if $hiddenfieldname is * passed, array indexes are considered record IDs * @param string $textfieldname The text field's name * @param string $hiddenfieldname The hidden field's name. If passed, * the option index will be set to this hidden * value when its option value is selected in * the text field * @param string $width The pixel width of the text field (Due to YUI, must * use width instead of size) * @return void * @link http://developer.yahoo.com/yui/examples/autocomplete/ac_basic_array.html What you get with no $hiddenfieldname * @link http://developer.yahoo.com/yui/examples/autocomplete/ac_itemselect.html What you get with $hiddenfieldname */ public function mform_autocomplete($mform, $options, $textfieldname, $hiddenfieldname = '', $width = '300') { global $PAGE; $url = NULL; $data = NULL; // Generate data source if ($options instanceof moodle_url) { $url = $options->out(false); } else { $data = array(); foreach ($options as $optionid => $option) { if (empty($hiddenfieldname)) { $data[] = $option; } else { $data[] = (object) array('text' => $option, 'id' => $optionid); } } } $fields = array('text'); if (!empty($hiddenfieldname)) { $fields[] = 'id'; } $module = array('name' => 'local_mr_framework', 'fullpath' => '/local/mr/framework/assets/javascript.js', 'requires' => array('yui2-yahoo', 'yui2-dom', 'yui2-event', 'yui2-datasource', 'yui2-json', 'yui2-connection', 'yui2-get', 'yui2-animation', 'yui2-autocomplete')); $arguments = array((object) array('fieldname' => $textfieldname, 'hiddenfieldname' => $hiddenfieldname, 'width' => $width, 'url' => $url, 'data' => $data, 'fields' => $fields)); $PAGE->requires->js_init_call('M.local_mr.init_mr_html_autocomplete', $arguments, true, $module); // $PAGE->requires->css('/lib/yui/2.8.1/build/autocomplete/assets/autocomplete-core.css'); // $PAGE->requires->css('/lib/yui/2.8.1/build/autocomplete/assets/skins/sam/autocomplete.css'); // Update form - need to force some attributes and add the javascript $mform->updateElementAttr($textfieldname, array('autocomplete' => 'off', 'style' => "width: {$width}px;")); // Add ID to hidden field so javascript can find it if (!empty($hiddenfieldname)) { $mform->updateElementAttr($hiddenfieldname, array('id' => "id_{$hiddenfieldname}")); } }
function display() { $search = trim(optional_param('search', '', PARAM_TEXT)); $alpha = optional_param('alpha', '', PARAM_ALPHA); // TODO: with a little more work, we could keep the previously selected sort here $params = $_GET; unset($params['page']); // We want to go back to the first page unset($params['search']); // And clear the search $target = $this->page->get_new_page($params); echo "<table class=\"searchbox\" style=\"margin-left:auto;margin-right:auto\" cellpadding=\"10\"><tr><td>"; echo "<form action=\"" . $target->get_url() . "\" method=\"post\">"; echo "<fieldset class=\"invisiblefieldset\">"; echo "<input type=\"text\" name=\"search\" value=\"" . s($search, true) . "\" size=\"20\" />"; echo '<input type="submit" value="' . get_string('search') . '" />'; //remove the "bare" parameter to prevent from loading only part of the page $moodleurl = new moodle_url($target->get_url()); $moodleurl->remove_params('mode'); if ($search) { echo "<input type=\"button\" onclick=\"document.location='" . $moodleurl->out() . "';\" " . "value=\"Show all items\" />"; } echo "</fieldset></form>"; echo "</td></tr></table>"; }
/** * form_start * * @param xxx $hotpotscriptname * @param xxx $params * @param xxx $attributes (optional, default=array) * @return xxx */ function form_start($hotpotscriptname, $params, $attributes = array()) { $output = ''; if (empty($attributes['method'])) { $attributes['method'] = 'post'; } if (empty($attributes['action'])) { $url = new moodle_url('/mod/hotpot/' . $hotpotscriptname); $attributes['action'] = $url->out(); } $output .= html_writer::start_tag('form', $attributes) . "\n"; $hiddenfields = ''; foreach ($params as $name => $value) { $hiddenfields .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => $name, 'value' => $value)) . "\n"; } if ($hiddenfields) { // xhtml strict requires a container for the hidden input elements $output .= html_writer::start_tag('fieldset', array('style' => 'display:none')) . "\n"; $output .= $hiddenfields; $output .= html_writer::end_tag('fieldset') . "\n"; } // xhtml strict requires a container for the contents of the <form> $output .= html_writer::start_tag('div') . "\n"; return $output; }
/** * Run all the question tests for all variants of all questions belonging to * a given context. * * Does output as we go along. * * @param context $context the context to run the tests for. * @return array with two elements: * bool true if all the tests passed, else false. * array of messages relating to the questions with failures. */ public function run_all_tests_for_context(context $context) { global $DB, $OUTPUT; // Load the necessary data. $categories = question_category_options(array($context)); $categories = reset($categories); $questiontestsurl = new moodle_url('/question/type/stack/questiontestrun.php'); if ($context->contextlevel == CONTEXT_COURSE) { $questiontestsurl->param('courseid', $context->instanceid); } else { if ($context->contextlevel == CONTEXT_MODULE) { $questiontestsurl->param('cmid', $context->instanceid); } } $allpassed = true; $failingtests = array(); foreach ($categories as $key => $category) { list($categoryid) = explode(',', $key); echo $OUTPUT->heading($category, 3); $questionids = $DB->get_records_menu('question', array('category' => $categoryid, 'qtype' => 'stack'), 'name', 'id,name'); if (!$questionids) { continue; } echo html_writer::tag('p', stack_string('replacedollarscount', count($questionids))); foreach ($questionids as $questionid => $name) { $tests = question_bank::get_qtype('stack')->load_question_tests($questionid); if (!$tests) { echo $OUTPUT->heading(html_writer::link(new moodle_url($questiontestsurl, array('questionid' => $questionid)), format_string($name)), 4); echo html_writer::tag('p', stack_string('bulktestnotests')); continue; } $question = question_bank::load_question($questionid); $questionname = format_string($name); $previewurl = new moodle_url($questiontestsurl, array('questionid' => $questionid)); if (empty($question->deployedseeds)) { $questionnamelink = html_writer::link($previewurl, $questionname); echo $OUTPUT->heading($questionnamelink, 4); list($ok, $message) = $this->qtype_stack_test_question($question, $tests); if (!$ok) { $allpassed = false; $failingtests[] = $questionnamelink . ': ' . $message; } } else { echo $OUTPUT->heading(format_string($name), 4); foreach ($question->deployedseeds as $seed) { $previewurl->param('seed', $seed); $questionnamelink = html_writer::link($previewurl, stack_string('seedx', $seed)); echo $OUTPUT->heading($questionnamelink, 4); list($ok, $message) = $this->qtype_stack_test_question($question, $tests, $seed); if (!$ok) { $allpassed = false; $failingtests[] = $questionname . ' ' . $questionnamelink . ': ' . $message; } } } } } return array($allpassed, $failingtests); }
/** * Determine output for the login column. * * @param stdClass $user The user row being worked on. * @return string The output to display. */ public function col_login($user) { if (isset($user->password)) { $pageurl = new \moodle_url('/mod/webexactivity/admin_users.php', array('action' => 'login', 'webexid' => $user->webexid)); return '<a href="' . $pageurl->out(false) . '" target=_blank>Login</a>'; } return ''; }
/** * Add question-type specific form fields. * * @param object $mform the form being built. */ function definition_inner($mform) { global $CFG; //redirct to the new ordering question type $orderingurl = new moodle_url($CFG->wwwroot . '/question/question.php', $_GET); $orderingurl->param('qtype', 'ordering'); redirect($orderingurl, 'This question type is deprecated. Redirection to new question ordering', 3); }
/** * Get URL related to the action * * @return \moodle_url */ public function get_url() { $url = new \moodle_url('/mod/twf/user.php', array('id' => $this->relateduserid, 'mode' => $this->other['reportmode'])); if ($this->courseid != SITEID) { $url->param('course', $this->courseid); } return $url; }
function memorization_print_new_verse_box() { global $CFG, $USER; print_box_start('add-verse-box generalbox box'); print_heading(get_string('newverse', 'memorization')); $biblebooks = biblebooks_array(); // create the book selector $biblebookoptions = ''; foreach ($biblebooks as $booknumber => $bookofbible) { if ($booknumber == 0) { continue; } $biblebookoptions .= '<option value="' . $booknumber . '">' . $bookofbible . '</option>'; } $startbookid = '<select name="startbookid">' . $biblebookoptions . '</select>'; $endbookid = '<select name="endbookid">' . $biblebookoptions . '</select>'; // create the chapter inputs $startchapter = '<input type="text" name="startchapter" size="5" />'; $endchapter = '<input type="text" name="endchapter" size="5"/>'; // create the verse inputs $startverse = '<input type="text" name="startverse" size="5"/>'; $endverse = '<input type="text" name="endverse" size="5"/>'; // create the version chooser $versions = get_records('memorization_version'); if (!empty($versions)) { $versionselect = '<select name="versionid">'; $lastversionid = get_field_sql("SELECT versionid FROM {$CFG->prefix}memorization_verse WHERE userid={$USER->id} ORDER BY id DESC"); foreach ($versions as $versionid => $version) { $selected = $versionid == $lastversionid ? ' SELECTED="selected" ' : ''; $versionselect .= '<option ' . $selected . ' value="' . $versionid . '">' . $version->value . '</option>'; } $versionselect .= '</select>'; } $currenturl = new moodle_url(qualified_me()); echo '<form method="POST" action="addverse.php?' . $currenturl->get_query_string() . '"> <input type="hidden" name="sesskey" value="' . sesskey() . '"> <table> <tr> <td>' . get_string('fromverse', 'memorization') . '</td> <td>' . $startbookid . ' ' . $startchapter . ':' . $startverse . '</td> </tr> <tr> <td>' . get_string('toverse', 'memorization') . '</td> <td>' . $endbookid . ' ' . $endchapter . ':' . $endverse . '</td> </tr> <tr> <td>' . get_string('version', 'memorization') . '</td> <td>' . $versionselect . '</td> </tr> </table> <input type="submit"> </form>'; print_box_end(); }
/** * Prints the respective type icon * * @global object * @return string */ function image() { global $OUTPUT; $params = array('d' => $this->data->id, 'fid' => $this->field->id, 'mode' => 'display', 'sesskey' => sesskey()); $link = new moodle_url('/mod/data/field.php', $params); $str = '<a href="' . $link->out() . '">'; $str .= '<img src="' . $OUTPUT->pix_url('linkedradiobutton', 'datafield_linkedradiobutton') . '" '; $str .= 'height="' . $this->iconheight . '" width="' . $this->iconwidth . '" alt="' . $this->type . '" title="' . $this->type . '" /></a>'; return $str; }
/** * Get URL related to the action. * * @return \moodle_url */ public function get_url() { $url = new \moodle_url("/mod/treasurehunt/view.php", array('id' => $this->contextinstanceid)); if (!empty($this->other['groupid'])) { $url->param('groupid', $this->other['groupid']); } else { $url->param('userid', $this->userid); } return $url; }
/** * Constructor * * @param int $repositoryid * @param stdClass $context * @param array $options */ public function __construct($repositoryid, $context = SYSCONTEXTID, $options = array()) { parent::__construct($repositoryid, $context, $options); $clientid = get_config('boxnet', 'clientid'); $clientsecret = get_config('boxnet', 'clientsecret'); $returnurl = new moodle_url('/repository/repository_callback.php'); $returnurl->param('callback', 'yes'); $returnurl->param('repo_id', $this->id); $returnurl->param('sesskey', sesskey()); $this->boxnetclient = new boxnet_client($clientid, $clientsecret, $returnurl, ''); }
function get_content() { global $CFG, $USER, $DB, $OUTPUT; require_once $CFG->dirroot . '/mod/elluminate/lib.php'; if ($this->content !== NULL) { return $this->content; } $this->content = new stdClass(); $this->content->items = array(); $this->content->icons = array(); $this->content->footer = ''; if (!isloggedin() || empty($this->instance)) { return $this->content; } if ($recordings = elluminate_recent_recordings()) { $this->content->items[] = '<b>' . get_string('recentrecordings', 'block_elluminate') . ':</b>'; $this->content->icons[] = ''; $baseurl = new moodle_url('/mod/elluminate/view.php'); foreach ($recordings as $recording) { $elluminate = $DB->get_record('elluminate', array('meetingid' => $recording->meetingid)); $url = new moodle_url($baseurl); $url->params(array('a' => $elluminate->id, 'group' => $elluminate->groupid)); $icon = '<img src="' . $OUTPUT->pix_url('icon', 'feedback') . '" class="icon" alt="" /> '; $this->content->text = ' <a href="' . $url->out() . '">' . $recording->name . '</a>'; } } return $this->content; }
/** * Allow a gallery to be viewed just by knowing its idnumber. * This is a helper function to jump to a gallery without going throught * the course page, simulating the case where the user knows the URL but * can't go through the course (ispublic flag is set). * * @Given /^I view the lightboxgallery with idnumber "(?P<lightboxgallery_idnumber>(?:[^"]|\\")*)"$/ * @param string $idnumber */ public function i_view_the_lightboxgallery_with_idnumber($idnumber) { global $DB; $sql = "SELECT cm.id\n FROM {course_modules} cm\n JOIN {modules} m ON m.id = cm.module\n WHERE m.name = 'lightboxgallery' AND cm.idnumber = ?"; $cm = $DB->get_record_sql($sql, [$idnumber]); $href = new moodle_url('/mod/lightboxgallery/view.php', ['id' => $cm->id]); $this->getSession()->visit($href->out()); }
/** * Return an XHTML string for the setting. * * @return string Returns an XHTML string. */ public function output_html($data, $query = '') { global $OUTPUT; $settinghtml = ''; $oidcconfig = get_config('auth_oidc'); $clientcredspresent = !empty($oidcconfig->clientid) && !empty($oidcconfig->clientsecret) ? true : false; $endpointspresent = !empty($oidcconfig->authendpoint) && !empty($oidcconfig->tokenendpoint) ? true : false; // Input + detect button. $inputattrs = ['type' => 'text', 'class' => 'maininput', 'size' => 30, 'id' => $this->get_id(), 'name' => $this->get_full_name(), 'value' => s($data)]; $input = \html_writer::empty_tag('input', $inputattrs); if ($clientcredspresent === true && $endpointspresent === true) { $buttonattrs = ['class' => 'detect']; $detectbutton = \html_writer::tag('button', 'Detect', $buttonattrs); $settinghtml .= \html_writer::div($input . $detectbutton); if (!empty($data)) { $icon = $OUTPUT->pix_icon('t/check', 'valid', 'moodle'); $strvalid = get_string('settings_serviceresourceabstract_valid', 'local_o365', $this->visiblename); $statusmessage = \html_writer::tag('span', $strvalid, ['class' => 'statusmessage']); $settinghtml .= \html_writer::div($icon . $statusmessage, 'alert-success local_o365_statusmessage'); } else { $icon = $OUTPUT->pix_icon('i/warning', 'valid', 'moodle'); $strnocreds = get_string('settings_serviceresourceabstract_empty', 'local_o365'); $statusmessage = \html_writer::tag('span', $strnocreds, ['class' => 'statusmessage']); $settinghtml .= \html_writer::div($icon . $statusmessage, 'alert-info local_o365_statusmessage'); } // Using a <script> tag here instead of $PAGE->requires->js() because using $PAGE object loads file too late. $scripturl = new \moodle_url('/local/o365/classes/adminsetting/serviceresource.js'); $settinghtml .= '<script src="' . $scripturl->out() . '"></script>'; $strvalid = get_string('settings_serviceresourceabstract_valid', 'local_o365', $this->visiblename); $strinvalid = get_string('settings_serviceresourceabstract_invalid', 'local_o365', $this->visiblename); $iconvalid = addslashes($OUTPUT->pix_icon('t/check', 'valid', 'moodle')); $iconinvalid = addslashes($OUTPUT->pix_icon('t/delete', 'invalid', 'moodle')); $iconloading = addslashes($OUTPUT->pix_icon('i/ajaxloader', 'loading', 'moodle')); $ajaxurl = new \moodle_url('/local/o365/ajax.php'); $settinghtml .= '<script> $(function() { var opts = { url: "' . $ajaxurl->out() . '", setting: "' . $this->name . '", strvalid: "' . $strvalid . '", strinvalid: "' . $strinvalid . '", iconvalid: "' . $iconvalid . '", iconinvalid: "' . $iconinvalid . '", iconloading: "' . $iconloading . '" }; $("#admin-' . $this->name . '").serviceresource(opts); }); </script>'; } else { $settinghtml .= \html_writer::div($input); $icon = $OUTPUT->pix_icon('i/warning', 'valid', 'moodle'); $strnocreds = get_string('settings_serviceresourceabstract_nocreds', 'local_o365'); $statusmessage = \html_writer::tag('span', $strnocreds, ['class' => 'statusmessage']); $settinghtml .= \html_writer::div($icon . $statusmessage, 'alert-info local_o365_statusmessage'); } return format_admin_setting($this, $this->visiblename, $settinghtml, $this->description); }