public static function pagination(html_link $link, $total, $current, $size = 25, $prefix = '') { if ($total <= $size) { return false; } $pages = ceil($total / $size); $links = array(); for ($i = 0; $i < $pages; $i++) { $links[$i + 1] = $link->pure(array($prefix . 'page' => $i)); } return template('iv.pagination')->render(array('total' => $total, 'current' => $current, 'pages' => $pages, 'size' => $size, 'links' => $links)); }
/** * Print the multiple ratings on a entry given to the current user by others. * Scale is an array of ratings * * @param int $entryid * @param array $scale */ function glossary_print_ratings_mean($entryid, $scale) { global $OUTPUT; static $strrate; $mean = glossary_get_ratings_mean($entryid, $scale); if ($mean !== "") { if (empty($strratings)) { $strratings = get_string("ratings", "glossary"); } echo "{$strratings}: "; $link = html_link::make("/mod/glossary/report.php?id={$entryid}", $mean); $link->add_action(new popup_action('click', $link->url, "ratings")); echo $OUTPUT->link($link); } }
/** * Display all the submissions ready for grading * * @global object * @global object * @global object * @global object * @param string $message * @return bool|void */ function display_submissions($message = '') { global $CFG, $DB, $USER, $DB, $OUTPUT; require_once $CFG->libdir . '/gradelib.php'; /* first we check to see if the form has just been submitted * to request user_preference updates */ if (isset($_POST['updatepref'])) { $perpage = optional_param('perpage', 10, PARAM_INT); $perpage = $perpage <= 0 ? 10 : $perpage; set_user_preference('assignment_perpage', $perpage); set_user_preference('assignment_quickgrade', optional_param('quickgrade', 0, PARAM_BOOL)); } /* next we get perpage and quickgrade (allow quick grade) params * from database */ $perpage = get_user_preferences('assignment_perpage', 10); $quickgrade = get_user_preferences('assignment_quickgrade', 0); $grading_info = grade_get_grades($this->course->id, 'mod', 'assignment', $this->assignment->id); if (!empty($CFG->enableoutcomes) and !empty($grading_info->outcomes)) { $uses_outcomes = true; } else { $uses_outcomes = false; } $page = optional_param('page', 0, PARAM_INT); $strsaveallfeedback = get_string('saveallfeedback', 'assignment'); /// Some shortcuts to make the code read better $course = $this->course; $assignment = $this->assignment; $cm = $this->cm; $tabindex = 1; //tabindex for quick grading tabbing; Not working for dropdowns yet add_to_log($course->id, 'assignment', 'view submission', 'submissions.php?id=' . $this->cm->id, $this->assignment->id, $this->cm->id); $navigation = build_navigation($this->strsubmissions, $this->cm); print_header_simple(format_string($this->assignment->name, true), "", $navigation, '', '', true, update_module_button($cm->id, $course->id, $this->strassignment), navmenu($course, $cm)); $course_context = get_context_instance(CONTEXT_COURSE, $course->id); if (has_capability('gradereport/grader:view', $course_context) && has_capability('moodle/grade:viewall', $course_context)) { echo '<div class="allcoursegrades"><a href="' . $CFG->wwwroot . '/grade/report/grader/index.php?id=' . $course->id . '">' . get_string('seeallcoursegrades', 'grades') . '</a></div>'; } if (!empty($message)) { echo $message; // display messages here if any } $context = get_context_instance(CONTEXT_MODULE, $cm->id); /// Check to see if groups are being used in this assignment /// find out current groups mode $groupmode = groups_get_activity_groupmode($cm); $currentgroup = groups_get_activity_group($cm, true); groups_print_activity_menu($cm, 'submissions.php?id=' . $this->cm->id); /// Get all ppl that are allowed to submit assignments if ($users = get_users_by_capability($context, 'mod/assignment:submit', 'u.id', '', '', '', $currentgroup, '', false)) { $users = array_keys($users); } // if groupmembersonly used, remove users who are not in any group if ($users and !empty($CFG->enablegroupings) and $cm->groupmembersonly) { if ($groupingusers = groups_get_grouping_members($cm->groupingid, 'u.id', 'u.id')) { $users = array_intersect($users, array_keys($groupingusers)); } } $tablecolumns = array('picture', 'fullname', 'grade', 'submissioncomment', 'timemodified', 'timemarked', 'status', 'finalgrade'); if ($uses_outcomes) { $tablecolumns[] = 'outcome'; // no sorting based on outcomes column } $tableheaders = array('', get_string('fullname'), get_string('grade'), get_string('comment', 'assignment'), get_string('lastmodified') . ' (' . get_string('submission', 'assignment') . ')', get_string('lastmodified') . ' (' . get_string('grade') . ')', get_string('status'), get_string('finalgrade', 'grades')); if ($uses_outcomes) { $tableheaders[] = get_string('outcome', 'grades'); } require_once $CFG->libdir . '/tablelib.php'; $table = new flexible_table('mod-assignment-submissions'); $table->define_columns($tablecolumns); $table->define_headers($tableheaders); $table->define_baseurl($CFG->wwwroot . '/mod/assignment/submissions.php?id=' . $this->cm->id . '&currentgroup=' . $currentgroup); $table->sortable(true, 'lastname'); //sorted by lastname by default $table->collapsible(true); $table->initialbars(true); $table->column_suppress('picture'); $table->column_suppress('fullname'); $table->column_class('picture', 'picture'); $table->column_class('fullname', 'fullname'); $table->column_class('grade', 'grade'); $table->column_class('submissioncomment', 'comment'); $table->column_class('timemodified', 'timemodified'); $table->column_class('timemarked', 'timemarked'); $table->column_class('status', 'status'); $table->column_class('finalgrade', 'finalgrade'); if ($uses_outcomes) { $table->column_class('outcome', 'outcome'); } $table->set_attribute('cellspacing', '0'); $table->set_attribute('id', 'attempts'); $table->set_attribute('class', 'submissions'); $table->set_attribute('width', '100%'); //$table->set_attribute('align', 'center'); $table->no_sorting('finalgrade'); $table->no_sorting('outcome'); // Start working -- this is necessary as soon as the niceties are over $table->setup(); if (empty($users)) { echo $OUTPUT->heading(get_string('nosubmitusers', 'assignment')); return true; } /// Construct the SQL if ($where = $table->get_sql_where()) { $where .= ' AND '; } if ($sort = $table->get_sql_sort()) { $sort = ' ORDER BY ' . $sort; } $select = 'SELECT u.id, u.firstname, u.lastname, u.picture, u.imagealt, s.id AS submissionid, s.grade, s.submissioncomment, s.timemodified, s.timemarked, COALESCE(SIGN(SIGN(s.timemarked) + SIGN(s.timemarked - s.timemodified)), 0) AS status '; $sql = 'FROM {user} u ' . 'LEFT JOIN {assignment_submissions} s ON u.id = s.userid AND s.assignment = ' . $this->assignment->id . ' ' . 'WHERE ' . $where . 'u.id IN (' . implode(',', $users) . ') '; $table->pagesize($perpage, count($users)); ///offset used to calculate index of student in that particular query, needed for the pop up to know who's next $offset = $page * $perpage; $strupdate = get_string('update'); $strgrade = get_string('grade'); $grademenu = make_grades_menu($this->assignment->grade); if (($ausers = $DB->get_records_sql($select . $sql . $sort, null, $table->get_page_start(), $table->get_page_size())) !== false) { $grading_info = grade_get_grades($this->course->id, 'mod', 'assignment', $this->assignment->id, array_keys($ausers)); foreach ($ausers as $auser) { $final_grade = $grading_info->items[0]->grades[$auser->id]; $grademax = $grading_info->items[0]->grademax; $final_grade->formatted_grade = round($final_grade->grade, 2) . ' / ' . round($grademax, 2); $locked_overridden = 'locked'; if ($final_grade->overridden) { $locked_overridden = 'overridden'; } /// Calculate user status $auser->status = $auser->timemarked > 0 && $auser->timemarked >= $auser->timemodified; $picture = $OUTPUT->user_picture(moodle_user_picture::make($auser, $course->id)); if (empty($auser->submissionid)) { $auser->grade = -1; //no submission yet } if (!empty($auser->submissionid)) { ///Prints student answer and student modified date ///attach file or print link to student answer, depending on the type of the assignment. ///Refer to print_student_answer in inherited classes. if ($auser->timemodified > 0) { $studentmodified = '<div id="ts' . $auser->id . '">' . $this->print_student_answer($auser->id) . userdate($auser->timemodified) . '</div>'; } else { $studentmodified = '<div id="ts' . $auser->id . '"> </div>'; } ///Print grade, dropdown or text if ($auser->timemarked > 0) { $teachermodified = '<div id="tt' . $auser->id . '">' . userdate($auser->timemarked) . '</div>'; if ($final_grade->locked or $final_grade->overridden) { $grade = '<div id="g' . $auser->id . '" class="' . $locked_overridden . '">' . $final_grade->formatted_grade . '</div>'; } else { if ($quickgrade) { $select = html_select::make(make_grades_menu($this->assignment->grade), 'menu[' . $auser->id . ']', $auser->grade, get_string('nograde')); $select->nothingvalue = '-1'; $select->tabindex = $tabindex++; $menu = $OUTPUT->select($select); $grade = '<div id="g' . $auser->id . '">' . $menu . '</div>'; } else { $grade = '<div id="g' . $auser->id . '">' . $this->display_grade($auser->grade) . '</div>'; } } } else { $teachermodified = '<div id="tt' . $auser->id . '"> </div>'; if ($final_grade->locked or $final_grade->overridden) { $grade = '<div id="g' . $auser->id . '" class="' . $locked_overridden . '">' . $final_grade->formatted_grade . '</div>'; } else { if ($quickgrade) { $select = html_select::make(make_grades_menu($this->assignment->grade), 'menu[' . $auser->id . ']', $auser->grade, get_string('nograde')); $select->nothingvalue = '-1'; $select->tabindex = $tabindex++; $menu = $OUTPUT->select($select); $grade = '<div id="g' . $auser->id . '">' . $menu . '</div>'; } else { $grade = '<div id="g' . $auser->id . '">' . $this->display_grade($auser->grade) . '</div>'; } } } ///Print Comment if ($final_grade->locked or $final_grade->overridden) { $comment = '<div id="com' . $auser->id . '">' . shorten_text(strip_tags($final_grade->str_feedback), 15) . '</div>'; } else { if ($quickgrade) { $comment = '<div id="com' . $auser->id . '">' . '<textarea tabindex="' . $tabindex++ . '" name="submissioncomment[' . $auser->id . ']" id="submissioncomment' . $auser->id . '" rows="2" cols="20">' . $auser->submissioncomment . '</textarea></div>'; } else { $comment = '<div id="com' . $auser->id . '">' . shorten_text(strip_tags($auser->submissioncomment), 15) . '</div>'; } } } else { $studentmodified = '<div id="ts' . $auser->id . '"> </div>'; $teachermodified = '<div id="tt' . $auser->id . '"> </div>'; $status = '<div id="st' . $auser->id . '"> </div>'; if ($final_grade->locked or $final_grade->overridden) { $grade = '<div id="g' . $auser->id . '">' . $final_grade->formatted_grade . '</div>'; } else { if ($quickgrade) { // allow editing $select = html_select::make(make_grades_menu($this->assignment->grade), 'menu[' . $auser->id . ']', $auser->grade, get_string('nograde')); $select->nothingvalue = '-1'; $select->tabindex = $tabindex++; $menu = $OUTPUT->select($select); $grade = '<div id="g' . $auser->id . '">' . $menu . '</div>'; } else { $grade = '<div id="g' . $auser->id . '">-</div>'; } } if ($final_grade->locked or $final_grade->overridden) { $comment = '<div id="com' . $auser->id . '">' . $final_grade->str_feedback . '</div>'; } else { if ($quickgrade) { $comment = '<div id="com' . $auser->id . '">' . '<textarea tabindex="' . $tabindex++ . '" name="submissioncomment[' . $auser->id . ']" id="submissioncomment' . $auser->id . '" rows="2" cols="20">' . $auser->submissioncomment . '</textarea></div>'; } else { $comment = '<div id="com' . $auser->id . '"> </div>'; } } } if (empty($auser->status)) { /// Confirm we have exclusively 0 or 1 $auser->status = 0; } else { $auser->status = 1; } $buttontext = $auser->status == 1 ? $strupdate : $strgrade; ///No more buttons, we use popups ;-). $popup_url = '/mod/assignment/submissions.php?id=' . $this->cm->id . '&userid=' . $auser->id . '&mode=single' . '&offset=' . $offset++; $link = html_link::make($popup_url, $buttontext); $link->add_action(new popup_action('click', $link->url, 'grade' . $auser->id, array('height' => 600, 'width' => 700))); $link->title = $buttontext; $button = $OUTPUT->link($link); $status = '<div id="up' . $auser->id . '" class="s' . $auser->status . '">' . $button . '</div>'; $finalgrade = '<span id="finalgrade_' . $auser->id . '">' . $final_grade->str_grade . '</span>'; $outcomes = ''; if ($uses_outcomes) { foreach ($grading_info->outcomes as $n => $outcome) { $outcomes .= '<div class="outcome"><label>' . $outcome->name . '</label>'; $options = make_grades_menu(-$outcome->scaleid); if ($outcome->grades[$auser->id]->locked or !$quickgrade) { $options[0] = get_string('nooutcome', 'grades'); $outcomes .= ': <span id="outcome_' . $n . '_' . $auser->id . '">' . $options[$outcome->grades[$auser->id]->grade] . '</span>'; } else { $outcomes .= ' '; $select = html_select::make($options, 'outcome_' . $n . '[' . $auser->id . ']', $outcome->grades[$auser->id]->grade, get_string('nooutcome', 'grades')); $select->nothingvalue = '0'; $select->tabindex = $tabindex++; $select->id = 'outcome_' . $n . '_' . $auser->id; $outcomes .= $OUTPUT->select($select); } $outcomes .= '</div>'; } } $userlink = '<a href="' . $CFG->wwwroot . '/user/view.php?id=' . $auser->id . '&course=' . $course->id . '">' . fullname($auser) . '</a>'; $row = array($picture, $userlink, $grade, $comment, $studentmodified, $teachermodified, $status, $finalgrade); if ($uses_outcomes) { $row[] = $outcomes; } $table->add_data($row); } } /// Print quickgrade form around the table if ($quickgrade) { echo '<form action="submissions.php" id="fastg" method="post">'; echo '<div>'; echo '<input type="hidden" name="id" value="' . $this->cm->id . '" />'; echo '<input type="hidden" name="mode" value="fastgrade" />'; echo '<input type="hidden" name="page" value="' . $page . '" />'; echo '</div>'; } $table->print_html(); /// Print the whole table if ($quickgrade) { $lastmailinfo = get_user_preferences('assignment_mailinfo', 1) ? 'checked="checked"' : ''; echo '<div class="fgcontrols">'; echo '<div class="emailnotification">'; echo '<label for="mailinfo">' . get_string('enableemailnotification', 'assignment') . '</label>'; echo '<input type="hidden" name="mailinfo" value="0" />'; echo '<input type="checkbox" id="mailinfo" name="mailinfo" value="1" ' . $lastmailinfo . ' />'; echo $OUTPUT->help_icon(moodle_help_icon::make('emailnotification', get_string('enableemailnotification', 'assignment'), 'assignment')) . '</p></div>'; echo '</div>'; echo '<div class="fastgbutton"><input type="submit" name="fastg" value="' . get_string('saveallfeedback', 'assignment') . '" /></div>'; echo '</div>'; echo '</form>'; } /// End of fast grading form /// Mini form for setting user preference echo '<div class="qgprefs">'; echo '<form id="options" action="submissions.php?id=' . $this->cm->id . '" method="post"><div>'; echo '<input type="hidden" name="updatepref" value="1" />'; echo '<table id="optiontable">'; echo '<tr><td>'; echo '<label for="perpage">' . get_string('pagesize', 'assignment') . '</label>'; echo '</td>'; echo '<td>'; echo '<input type="text" id="perpage" name="perpage" size="1" value="' . $perpage . '" />'; echo $OUTPUT->help_icon(moodle_help_icon::make('pagesize', get_string('pagesize', 'assignment'), 'assignment')); echo '</td></tr>'; echo '<tr><td>'; echo '<label for="quickgrade">' . get_string('quickgrade', 'assignment') . '</label>'; echo '</td>'; echo '<td>'; $checked = $quickgrade ? 'checked="checked"' : ''; echo '<input type="checkbox" id="quickgrade" name="quickgrade" value="1" ' . $checked . ' />'; echo $OUTPUT->help_icon(moodle_help_icon::make('quickgrade', get_string('quickgrade', 'assignment'), 'assignment')) . '</p></div>'; echo '</td></tr>'; echo '<tr><td colspan="2">'; echo '<input type="submit" value="' . get_string('savepreferences') . '" />'; echo '</td></tr></table>'; echo '</div></form></div>'; ///End of mini form echo $OUTPUT->footer(); }
/** * Print history of responses * * Used by print_question() */ function history($question, $state, $number, $cmoptions, $options) { global $DB, $OUTPUT; $history = ''; if (isset($options->history) and $options->history) { if ($options->history == 'all') { // show all states $states = $DB->get_records_select('question_states', "attempt = ? AND question = ? AND event > '0'", array($state->attempt, $question->id), 'seq_number ASC'); } else { // show only graded states $states = $DB->get_records_select('question_states', "attempt = ? AND question = ? AND event IN (" . QUESTION_EVENTS_GRADED . ")", array($state->attempt, $question->id), 'seq_number ASC'); } if (count($states) > 1) { $strreviewquestion = get_string('reviewresponse', 'quiz'); $table = new html_table(); $table->width = '100%'; if ($options->scores) { $table->head = array(get_string('numberabbr', 'quiz'), get_string('action', 'quiz'), get_string('response', 'quiz'), get_string('time'), get_string('score', 'quiz'), get_string('grade', 'quiz')); } else { $table->head = array(get_string('numberabbr', 'quiz'), get_string('action', 'quiz'), get_string('response', 'quiz'), get_string('time')); } foreach ($states as $st) { $st->responses[''] = $st->answer; $this->restore_session_and_responses($question, $st); $b = $state->id == $st->id ? '<b>' : ''; $be = $state->id == $st->id ? '</b>' : ''; if ($state->id == $st->id) { $link = '<b>' . $st->seq_number . '</b>'; } else { if (isset($options->questionreviewlink)) { $link = html_link::make("{$options->questionreviewlink}?state={$st->id}&question={$question->id}", $st->seq_number); $link->add_action(new popup_action('click', $link->url, 'reviewquestion', array('height' => 450, 'width' => 650))); $link->title = $strreviewquestion; $link = $OUTPUT->link($link); } else { $link = $st->seq_number; } } if ($options->scores) { $table->data[] = array($link, $b . get_string('event' . $st->event, 'quiz') . $be, $b . $this->response_summary($question, $st) . $be, $b . userdate($st->timestamp, get_string('timestr', 'quiz')) . $be, $b . question_format_grade($cmoptions, $st->raw_grade) . $be, $b . question_format_grade($cmoptions, $st->grade) . $be); } else { $table->data[] = array($link, $b . get_string('event' . $st->event, 'quiz') . $be, $b . $this->response_summary($question, $st) . $be, $b . userdate($st->timestamp, get_string('timestr', 'quiz')) . $be); } } $history = $OUTPUT->table($table); } } return $history; }
} } if ($screenshotpath) { $infoitems['screenshot'] = '<a href="' . $CFG->themewww . '/' . $screenshotpath . '">' . get_string('screenshot') . '</a>'; } // Link to the themes's readme. $readmeurl = ''; if (file_exists($theme->dir . '/README.html')) { $readmeurl = $CFG->themewww . '/' . $themename . '/README.html'; } else { if (file_exists($theme->dir . '/README.txt')) { $readmeurl = $CFG->themewww . '/' . $themename . '/README.txt'; } } if ($readmeurl) { $link = html_link::make($readmeurl, get_string('info')); $link->add_action(new popup_action('click', $link->url, $themename)); $infoitems['readme'] = $OUTPUT->link($link); } // Contents of the first screenshot/preview cell. if ($screenshotpath) { $row[] = '<object type="text/html" data="' . $CFG->themewww . '/' . $screenshotpath . '" height="200" width="400">' . $themename . '</object>'; } else { $row[] = '<object type="text/html" data="preview.php?preview=' . $themename . '" height="200" width="400">' . $themename . '</object>'; } // Contents of the second cell. $infocell = $OUTPUT->heading($themename, 3); if ($infoitems) { $infocell .= "<ul>\n<li>" . implode("</li>\n<li>", $infoitems) . "</li>\n</ul>\n"; } if ($themename != $CFG->theme) {
/** * Print the specified user's avatar. * * This method can be used in two ways: * <pre> * // Option 1: * $userpic = new moodle_user_picture(); * // Set properties of $userpic * $OUTPUT->user_picture($userpic); * * // Option 2: (shortcut for simple cases) * // $user has come from the DB and has fields id, picture, imagealt, firstname and lastname * $OUTPUT->user_picture($user, $COURSE->id); * </pre> * * @param object $userpic Object with at least fields id, picture, imagealt, firstname, lastname * If any of these are missing, or if a userid is passed, the database is queried. Avoid this * if at all possible, particularly for reports. It is very bad for performance. * A moodle_user_picture object is a better parameter. * @param int $courseid courseid Used when constructing the link to the user's profile. Required if $userpic * is not a moodle_user_picture object * @return string HTML fragment */ public function user_picture($userpic, $courseid = null) { // Instantiate a moodle_user_picture object if $user is not already one if (!$userpic instanceof moodle_user_picture) { if (empty($courseid)) { throw new coding_exception('Called $OUTPUT->user_picture with a $user object but no $courseid.'); } $user = $userpic; $userpic = new moodle_user_picture(); $userpic->user = $user; $userpic->courseid = $courseid; } else { $userpic = clone $userpic; } $userpic->prepare(); $output = $this->image($userpic->image); if (!empty($userpic->url)) { $actions = $userpic->get_actions(); if ($userpic->popup && !empty($actions)) { $link = new html_link(); $link->url = $userpic->url; $link->text = fullname($userpic->user); $link->title = fullname($userpic->user); foreach ($actions as $action) { $link->add_action($action); } $output = $this->link_to_popup($link, $userpic->image); } else { $output = $this->link(prepare_url($userpic->url), $output); } } return $output; }
$ensrc = "{$CFG->dirroot}/{$origlocation}/{$origplugin}/lang/en_utf8/help/{$currentfile}"; } else { // core help file $ensrc = "{$enlangdir}/{$currentfile}"; } if (is_readable($ensrc)) { echo '<fieldset><legend>' . $strlangmasterenglish; echo $OUTPUT->help_icon(moodle_help_icon::make('langpackages', $strlangmasterenglish)); echo '</legend>'; echo "<div class='mdl-align'>\n<textarea rows=\"{$fileeditorrows}\" cols=\"{$fileeditorcols}\" name=\"\">"; echo htmlspecialchars(file_get_contents($ensrc)); echo "</textarea>\n</div>\n"; $preview_url = lang_help_preview_url($currentfile, true, 'en_utf8'); // do not display en_utf8_local if ($preview_url) { $link = html_link::make($preview_url, get_string('preview')); $link->add_action(new popup_action('click', $link->url)); echo $OUTPUT->link($link); } echo '</fieldset>'; } echo '</div>'; // translator box error_reporting($CFG->debug); } if (false && $CFG->debugdisplay && debugging('', DEBUG_DEVELOPER)) { echo '<hr />'; echo $OUTPUT->heading('Debugging info'); echo '<pre class="notifytiny">'; print_r($dbg); print_r("\n\$currentfile = {$currentfile}");
/** * Returns a string of html with an image of a help icon linked to a help page on a number of help topics. * Should be used only with htmleditor or textarea. * * @global object * @global object * @param mixed $helptopics variable amount of params accepted. Each param may be a string or an array of arguments for * helpbutton. * @return string Link to help button */ function editorhelpbutton() { global $CFG, $SESSION, $OUTPUT; $items = func_get_args(); $i = 1; $urlparams = array(); $titles = array(); foreach ($items as $item) { if (is_array($item)) { $urlparams[] = "keyword{$i}=" . urlencode($item[0]); $urlparams[] = "title{$i}=" . urlencode($item[1]); if (isset($item[2])) { $urlparams[] = "module{$i}=" . urlencode($item[2]); } $titles[] = trim($item[1], ". \t"); } else { if (is_string($item)) { $urlparams[] = "button{$i}=" . urlencode($item); switch ($item) { case 'reading': $titles[] = get_string("helpreading"); break; case 'writing': $titles[] = get_string("helpwriting"); break; case 'questions': $titles[] = get_string("helpquestions"); break; case 'emoticons2': $titles[] = get_string("helpemoticons"); break; case 'richtext2': $titles[] = get_string('helprichtext'); break; case 'text2': $titles[] = get_string('helptext'); break; default: print_error('unknownhelp', '', '', $item); } } } $i++; } if (count($titles) > 1) { //join last two items with an 'and' $a = new object(); $a->one = $titles[count($titles) - 2]; $a->two = $titles[count($titles) - 1]; $titles[count($titles) - 2] = get_string('and', '', $a); unset($titles[count($titles) - 1]); } $alttag = join(', ', $titles); $paramstring = join('&', $urlparams); $linkobject = '<img alt="' . $alttag . '" class="iconhelp" src="' . $OUTPUT->old_icon_url('help') . '" />'; $link = html_link::make(s('/lib/form/editorhelp.php?' . $paramstring), $linkobject); $link->add_action(new popup_action('click', $link->url, 'popup', array('height' => 400, 'width' => 500))); $link->title = $alttag; return $OUTPUT->link($link); }
function print_user_files($userid, $return = false) { global $OUTPUT; if (!($submission = $this->get_submission($userid))) { return ''; } $link = html_link::make("/mod/assignment/type/online/file.php?id={$this->cm}->id&userid={$submission->userid}", shorten_text(trim(strip_tags(format_text($submission->data1, $submission->data2))), 15)); $link->add_action(new popup_action('click', $link->url, 'file' . $userid, array('height' => 450, 'width' => 580))); $link->title = get_string('submission', 'assignment'); $popup = $OUTPUT->link($link); $output = '<div class="files">' . '<img align="middle" src="' . $OUTPUT->old_icon_url('f/html') . '" height="16" width="16" alt="html" />' . $popup . '</div>'; ///Stolen code from file.php echo $OUTPUT->box_start('generalbox boxaligncenter', 'wordcount'); /// Decide what to count if ($CFG->assignment_itemstocount == ASSIGNMENT_COUNT_WORDS) { echo ' (' . get_string('numwords', '', count_words(format_text($submission->data1, $submission->data2))) . ')'; } else { if ($CFG->assignment_itemstocount == ASSIGNMENT_COUNT_LETTERS) { echo ' (' . get_string('numletters', '', count_letters(format_text($submission->data1, $submission->data2))) . ')'; } } echo $OUTPUT->box_end(); echo $OUTPUT->box(format_text($submission->data1, $submission->data2), 'generalbox boxaligncenter boxwidthwide'); ///End of stolen code from file.php if ($return) { //return $output; } //echo $output; }
/** * Creates and displays (or returns) a link to a popup window * * @deprecated since Moodle 2.0 * * @param string $url Web link. Either relative to $CFG->wwwroot, or a full URL. * @param string $name Name to be assigned to the popup window (this is used by * client-side scripts to "talk" to the popup window) * @param string $linkname Text to be displayed as web link * @param int $height Height to assign to popup window * @param int $width Height to assign to popup window * @param string $title Text to be displayed as popup page title * @param string $options List of additional options for popup window * @param bool $return If true, return as a string, otherwise print * @param string $id id added to the element * @param string $class class added to the element * @return string html code to display a link to a popup window. */ function link_to_popup_window($url, $name = null, $linkname = null, $height = 400, $width = 500, $title = null, $options = null, $return = false) { global $OUTPUT; debugging('link_to_popup_window() has been deprecated. Please change your code to use $OUTPUT->link().'); if ($options == 'none') { $options = null; } if (empty($linkname)) { throw new coding_exception('A link must have a descriptive text value! See $OUTPUT->link_to_popup() for usage.'); } // Create a html_link object $link = html_link::make($url, $linkname); $link->title = $title; // Parse the $options string $popupparams = array(); if (!empty($options)) { $optionsarray = explode(',', $options); foreach ($optionsarray as $option) { if (strstr($option, '=')) { $parts = explode('=', $option); if ($parts[1] == '0') { $popupparams[$parts[0]] = false; } else { $popupparams[$parts[0]] = $parts[1]; } } else { $popupparams[$option] = true; } } } $popupaction = new popup_action('click', $url, $name, $popupparams); $link->add_action($popupaction); // Call the output method $output = $OUTPUT->link($link); if ($return) { return $output; } else { echo $output; } }
/** * Prints the category info in indented fashion * This function is only used by print_whole_category_list() above */ function print_category_info($category, $depth, $showcourses = false) { global $CFG, $DB, $OUTPUT; static $strallowguests, $strrequireskey, $strsummary; if (empty($strsummary)) { $strallowguests = get_string('allowguests'); $strrequireskey = get_string('requireskey'); $strsummary = get_string('summary'); } $catlinkcss = $category->visible ? '' : ' class="dimmed" '; static $coursecount = null; if (null === $coursecount) { // only need to check this once $coursecount = $DB->count_records('course') <= FRONTPAGECOURSELIMIT; } if ($showcourses and $coursecount) { $catimage = '<img src="' . $OUTPUT->old_icon_url('i/course') . '" alt="" />'; } else { $catimage = " "; } echo "\n\n" . '<table class="categorylist">'; $courses = get_courses($category->id, 'c.sortorder ASC', 'c.id,c.sortorder,c.visible,c.fullname,c.shortname,c.password,c.summary,c.guest,c.cost,c.currency'); if ($showcourses and $coursecount) { echo '<tr>'; if ($depth) { $indent = $depth * 30; $rows = count($courses) + 1; echo '<td class="category indentation" rowspan="' . $rows . '" valign="top">'; $spacer = new html_image(); $spacer->height = 10; $spacer->width = $indent; echo $OUTPUT->spacer($spacer) . '<br />'; echo '</td>'; } echo '<td valign="top" class="category image">' . $catimage . '</td>'; echo '<td valign="top" class="category name">'; echo '<a ' . $catlinkcss . ' href="' . $CFG->wwwroot . '/course/category.php?id=' . $category->id . '">' . format_string($category->name) . '</a>'; echo '</td>'; echo '<td class="category info"> </td>'; echo '</tr>'; // does the depth exceed maxcategorydepth // maxcategorydepth == 0 or unset meant no limit $limit = !(isset($CFG->maxcategorydepth) && $depth >= $CFG->maxcategorydepth - 1); if ($courses && ($limit || $CFG->maxcategorydepth == 0)) { foreach ($courses as $course) { $linkcss = $course->visible ? '' : ' class="dimmed" '; echo '<tr><td valign="top"> '; echo '</td><td valign="top" class="course name">'; echo '<a ' . $linkcss . ' href="' . $CFG->wwwroot . '/course/view.php?id=' . $course->id . '">' . format_string($course->fullname) . '</a>'; echo '</td><td align="right" valign="top" class="course info">'; if ($course->guest) { echo '<a title="' . $strallowguests . '" href="' . $CFG->wwwroot . '/course/view.php?id=' . $course->id . '">'; echo '<img alt="' . $strallowguests . '" src="' . $OUTPUT->old_icon_url('i/guest') . '" /></a>'; } else { echo '<img alt="" style="width:18px;height:16px;" src="' . $OUTPUT->old_icon_url('spacer') . '" />'; } if ($course->password) { echo '<a title="' . $strrequireskey . '" href="' . $CFG->wwwroot . '/course/view.php?id=' . $course->id . '">'; echo '<img alt="' . $strrequireskey . '" src="' . $OUTPUT->old_icon_url('i/key') . '" /></a>'; } else { echo '<img alt="" style="width:18px;height:16px;" src="' . $OUTPUT->old_icon_url('spacer') . '" />'; } if ($course->summary) { $link = html_link::make('/course/info.php?id=' . $course->id, '<img alt="' . $strsummary . '" src="' . $OUTPUT->old_icon_url('i/info') . '" />'); $link->add_action(new popup_action('click', $link->url, 'courseinfo', array('height' => 400, 'width' => 500))); $link->title = $strsummary; echo $OUTPUT->link($link); } else { echo '<img alt="" style="width:18px;height:16px;" src="' . $OUTPUT->old_icon_url('spacer') . '" />'; } echo '</td></tr>'; } } } else { echo '<tr>'; if ($depth) { $indent = $depth * 20; echo '<td class="category indentation" valign="top">'; $spacer = new html_image(); $spacer->height = 10; $spacer->width = $indent; echo $OUTPUT->spacer($spacer) . '<br />'; echo '</td>'; } echo '<td valign="top" class="category name">'; echo '<a ' . $catlinkcss . ' href="' . $CFG->wwwroot . '/course/category.php?id=' . $category->id . '">' . format_string($category->name) . '</a>'; echo '</td>'; echo '<td valign="top" class="category number">'; if (count($courses)) { echo count($courses); } echo '</td></tr>'; } echo '</table>'; }
function displaydir($file_info) { global $CFG, $OUTPUT; $children = $file_info->get_children(); $parent_info = $file_info->get_parent(); $strname = get_string('name'); $strsize = get_string('size'); $strmodified = get_string('modified'); $strfolder = get_string('folder'); $strfile = get_string('file'); $strdownload = get_string('download'); $strdelete = get_string('delete'); $straction = get_string('action'); $path = array(); $params = $file_info->get_params_rawencoded(); $params = implode('&', $params); $path[] = $file_info->get_visible_name(); $level = $parent_info; while ($level) { $params = $level->get_params_rawencoded(); $params = implode('&', $params); $path[] = '<a href="index.php?' . $params . '">' . $level->get_visible_name() . '</a>'; $level = $level->get_parent(); } $path = array_reverse($path); $path = implode(' / ', $path); echo $path . ' /'; echo "<div>"; echo "<hr/>"; echo "<table border=\"0\" cellspacing=\"2\" cellpadding=\"2\" width=\"740\" class=\"files\">"; echo "<tr>"; echo "<th class=\"header\" scope=\"col\"></th>"; echo "<th class=\"header name\" scope=\"col\">{$strname}</th>"; echo "<th class=\"header size\" scope=\"col\">{$strsize}</th>"; echo "<th class=\"header date\" scope=\"col\">{$strmodified}</th>"; echo "<th class=\"header commands\" scope=\"col\">{$straction}</th>"; echo "</tr>\n"; $parentwritable = $file_info->is_writable(); if ($parent_info) { $params = $parent_info->get_params_rawencoded(); $params = implode('&', $params); echo "<tr class=\"folder\">"; print_cell(); print_cell('left', '<a href="index.php?' . $params . '"><img src="' . $OUTPUT->old_icon_url('f/parent') . '" class="icon" alt="" /> ' . get_string('parentfolder') . '</a>', 'name'); print_cell(); print_cell(); print_cell(); echo "</tr>"; } if ($children) { foreach ($children as $child_info) { $filename = $child_info->get_visible_name(); $filesize = $child_info->get_filesize(); $filesize = $filesize ? display_size($filesize) : ''; $filedate = $child_info->get_timemodified(); $filedate = $filedate ? userdate($filedate) : ''; $mimetype = $child_info->get_mimetype(); $params = $child_info->get_params_rawencoded(); $params = implode('&', $params); if ($child_info->is_directory()) { echo "<tr class=\"folder\">"; print_cell(); print_cell("left", "<a href=\"index.php?{$params}\"><img src=\"" . $OUTPUT->old_icon_url('f/folder') . "\" class=\"icon\" alt=\"{$strfolder}\" /> " . s($filename) . "</a>", 'name'); print_cell("right", $filesize, 'size'); print_cell("right", $filedate, 'date'); if ($parentwritable) { print_cell("right", "<a href=\"index.php?{$params}&sesskey=" . sesskey() . "&delete=1\"><img src=\"" . $OUTPUT->old_icon_url('t/delete') . "\" class=\"iconsmall\" alt=\"{$strdelete}\" /></a>", 'command'); } else { print_cell(); } echo "</tr>"; } else { if ($downloadurl = $child_info->get_url(true)) { $downloadurl = " <a href=\"{$downloadurl}\" title=\"" . get_string('downloadfile') . "\"><img src=\"" . $OUTPUT->old_icon_url('t/down') . "\" class=\"iconsmall\" alt=\"{$strdownload}\" /></a>"; } else { $downloadurl = ''; } if ($viewurl = $child_info->get_url()) { $link = html_link::make($viewurl, "display", "<img src=\"" . $OUTPUT->old_icon_url('t/preview') . "\" class=\"iconsmall\" alt=\"{$strfile}\" /> "); $link->add_action(new popup_action('click', $link->url, 'display', array('height' => 480, 'width' => 640))); $viewurl = " " . $OUTPUT->link($link); } else { $viewurl = ''; } echo "<tr class=\"file\">"; print_cell(); print_cell("left", "<img src=\"" . $OUTPUT->old_icon_url(file_mimetype_icon($mimetype)) . "\" class=\"icon\" alt=\"{$strfile}\" /> " . s($filename) . $downloadurl . $viewurl, 'name'); print_cell("right", $filesize, 'size'); print_cell("right", $filedate, 'date'); if ($parentwritable) { print_cell("right", "<a href=\"index.php?{$params}&sesskey=" . sesskey() . "&delete=1\"><img src=\"" . $OUTPUT->old_icon_url('t/delete') . "\" class=\"iconsmall\" alt=\"{$strdelete}\" /></a>", 'command'); } else { print_cell(); } echo "</tr>"; } } } echo "</table>"; echo "</div>"; echo "<hr/>"; }
/** * Either prints a "Export" box, which will redirect the user to the download page, * or prints the URL for the published data. * @return void */ public function print_continue() { global $CFG, $OUTPUT; $params = $this->get_export_params(); echo $OUTPUT->heading(get_string('export', 'grades')); echo $OUTPUT->container_start('gradeexportlink'); if (!$this->userkey) { // this button should trigger a download prompt echo $OUTPUT->button(html_form::make_button($CFG->wwwroot . '/grade/export/' . $this->plugin . '/export.php', $params, get_string('download', 'admin'))); } else { $paramstr = ''; $sep = '?'; foreach ($params as $name => $value) { $paramstr .= $sep . $name . '=' . $value; $sep = '&'; } $link = $CFG->wwwroot . '/grade/export/' . $this->plugin . '/dump.php' . $paramstr . '&key=' . $this->userkey; echo get_string('download', 'admin') . ': ' . $OUTPUT->link(html_link::make($link, $link)); } echo $OUTPUT->container_end(); }
function print_student_answer($userid, $return = false) { global $CFG, $OUTPUT; $submission = $this->get_submission($userid); $output = ''; if ($this->drafts_tracked() and $this->isopen() and !$this->is_finalized($submission)) { $output .= '<strong>' . get_string('draft', 'assignment') . ':</strong> '; } if ($this->notes_allowed() and !empty($submission->data1)) { $link = html_link::make("/mod/assignment/type/upload/notes.php?id={$this->cm}->id&userid={$userid}", get_string('notes', 'assignment')); $link->add_action(new popup_action('click', $link->url, 'notes', array('height' => 500, 'width' => 780))); $link->title = get_string('notes', 'assignment'); $output .= $OUTPUT->link($link); $output .= ' '; } $fs = get_file_storage(); $browser = get_file_browser(); if ($files = $fs->get_area_files($this->context->id, 'assignment_submission', $userid, "timemodified", false)) { foreach ($files as $file) { $filename = $file->get_filename(); $found = true; $mimetype = $file->get_mimetype(); $path = file_encode_url($CFG->wwwroot . '/pluginfile.php', '/' . $this->context->id . '/assignment_submission/' . $userid . '/' . $filename); $output .= '<a href="' . $path . '" ><img class="icon" src="' . $OUTPUT->old_icon_url(file_mimetype_icon($mimetype)) . '" alt="' . $mimetype . '" />' . s($filename) . '</a> '; } } $output = '<div class="files">' . $output . '</div>'; $output .= '<br />'; return $output; }
$links[] = html_link::make(new moodle_url($CFG->wwwroot . '/blog/index.php?userid=' . $user->id), get_string('blogs', 'blog')); } if (!empty($CFG->enablenotes) and has_capability('moodle/notes:manage', $context) || has_capability('moodle/notes:view', $context)) { $links[] = html_link::make(new moodle_url($CFG->wwwroot . '/notes/index.php?course=' . $course->id . '&user='******'notes', 'notes')); } if (has_capability('moodle/site:viewreports', $context) or has_capability('moodle/user:viewuseractivitiesreport', $usercontext)) { $links[] = html_link::make(new moodle_url($CFG->wwwroot . '/course/user.php?id=' . $course->id . '&user='******'activity')); } if (has_capability('moodle/role:assign', $context) and get_user_roles($context, $user->id, false)) { // I can unassign and user has some role $links[] = html_link::make(new moodle_url($CFG->wwwroot . '/course/unenrol.php?id=' . $course->id . '&user='******'unenrol')); } if ($USER->id != $user->id && !session_is_loggedinas() && has_capability('moodle/user:loginas', $context) && !has_capability('moodle/site:doanything', $context, $user->id, false)) { $links[] = html_link::make(new moodle_url($CFG->wwwroot . '/course/loginas.php?id=' . $course->id . '&user='******'&sesskey=' . sesskey()), get_string('loginas')); } $links[] = html_link::make(new moodle_url($CFG->wwwroot . '/user/view.php?id=' . $user->id . '&course=' . $course->id), get_string('fullprofile') . '...'); foreach ($links as $link) { $row->cells[2]->text .= $OUTPUT->link($link); } if (!empty($messageselect)) { $row->cells[2]->text .= '<br /><input type="checkbox" name="user' . $user->id . '" /> '; } $table->data = array($row); echo $OUTPUT->table($table); } } else { echo $OUTPUT->heading(get_string('nothingtodisplay')); } } } else { $countrysort = strpos($sort, 'country') !== false;
/** * Print a risk icon, as a link to the Risks page on Moodle Docs. * * @param string $type the type of risk, will be one of the keys from the * get_all_risks array. Must start with 'risk'. */ function get_risk_icon($type) { global $OUTPUT; if (!isset($this->riskicons[$type])) { $iconurl = $OUTPUT->old_icon_url('i/' . str_replace('risk', 'risk_', $type)); $link = html_link::make($this->risksurl, 'docspopup', '<img src="' . $iconurl . '" alt="' . get_string($type . 'short', 'admin') . '" />'); $link->add_action(new popup_action('click', $link->url, 'docspopup')); $link->title = get_string($type, 'admin'); $this->riskicons[$type] = $OUTPUT->link($link); } return $this->riskicons[$type]; }
/** * If there is a media file associated with this * lesson, return a block_contents that displays it. * * @param int $cmid Course Module ID for this lesson * @param object $lesson Full lesson record object * @return block_contents **/ function lesson_mediafile_block_contents($cmid, $lesson) { global $OUTPUT; if (empty($lesson->mediafile)) { return null; } $url = '/mod/lesson/mediafile.php?id=' . $cmid; $options = 'menubar=0,location=0,left=5,top=5,scrollbars,resizable,width=' . $lesson->mediawidth . ',height=' . $lesson->mediaheight; $name = 'lessonmediafile'; $link = html_link::make($url, get_string('mediafilepopup', 'lesson')); $link->add_action(new popup_action('click', $link->url, $name, $options)); $link->title = get_string('mediafilepopup', 'lesson'); $content .= $OUTPUT->link($link); $content .= $OUTPUT->help_icon(moodle_help_icon::make("mediafilestudent", get_string("mediafile", "lesson"), "lesson")); $bc = new block_contents(); $bc->title = get_string('linkedmedia', 'lesson'); $bc->set_classes('mediafile'); $bc->content = $content; return $bc; }
/** * Print the multiple ratings on a post given to the current user by others. * Scale is an array of ratings * * @staticvar string $strrate * @param int $recordid * @param array $scale * @param bool $link */ function data_print_ratings_mean($recordid, $scale, $link = true) { global $OUTPUT; static $strrate; $mean = data_get_ratings_mean($recordid, $scale); if ($mean !== "") { if (empty($strratings)) { $strratings = get_string("ratings", "data"); } echo "{$strratings}: "; if ($link) { $link = html_link::make("/mod/data/report.php?id={$recordid}", $mean); $link->add_action(new popup_action('click', $link->url, 'ratings', array('height' => 400, 'width' => 600))); echo $OUTPUT->link($link); } else { echo "{$mean} "; } } }
/** * This function print formated users to send mail ( This had choosed before ) * * @uses $CFG * @param Array $users Users to print. * @param boolean $nosenders No users choose (error log) * @todo Finish documenting this function */ function email_print_users_to_send($users, $nosenders = false, $options = NULL) { global $CFG, $DB, $OUTPUT; $url = ''; if ($options) { $url = email_build_url($options); } echo '<tr valign="middle"> <td class="legendmail"> <b>' . get_string('for', 'block_email_list') . ' : </b> </td> <td class="inputmail">'; if (!empty($users)) { echo '<div id="to">'; foreach ($users as $userid) { echo '<input type="hidden" value="' . $userid . '" name="to[]" />'; } echo '</div>'; echo '<textarea id="textareato" class="textareacontacts" name="to" cols="65" rows="3" disabled="true" multiple="multiple">'; foreach ($users as $userid) { echo fullname($DB->get_record('user', array('id' => $userid))) . ', '; } echo '</textarea>'; } echo '</td><td class="extrabutton">'; $link = html_link::make('/blocks/email_list/email/participants.php?' . $url, get_string('participants', 'block_email_list') . ' ...'); $link->title = get_string('participants', 'block_email_list'); // optional $options['height'] = 470; // optional $options['width'] = 520; // optional $link->add_action(new popup_action('click', '/blocks/email_list/email/participants.php?' . $url, 'participants', $options)); echo $OUTPUT->link($link); echo '</td></tr>'; echo '<tr valign="middle"> <td class="legendmail"> <div id="tdcc"></div> </td> <td><div id="fortextareacc"></div><div id="cc"></div><div id="url">' . $urltoaddcc . '<span id="urltxt"> | </span>' . $urltoaddbcc . '</div></td><td><div id="buttoncc"></div></td></tr>'; echo '<tr valign="middle"><td class="legendmail"><div id="tdbcc"></div></td><td><div id="fortextareabcc"></div><div id="bcc"></div></td><td><div id="buttonbcc"></div></td>'; }
/** * @see lib/moodle_html_component#prepare() * @return void */ public function prepare() { $this->image->add_class('action-icon'); if (!empty($this->actions)) { foreach ($this->actions as $action) { $this->link->add_action($action); } unset($this->actions); } parent::prepare(); if (empty($this->image->src)) { throw new coding_exception('moodle_action_icon->image->src must not be empty'); } if (empty($this->image->alt) && !empty($this->linktext)) { $this->image->alt = $this->linktext; } else { if (empty($this->image->alt)) { debugging('moodle_action_icon->image->alt should not be empty.', DEBUG_DEVELOPER); } } }
echo $spacer, $spacer; } echo '</td>'; echo '<td align="center">'; echo '<input type="checkbox" name="c' . $acourse->id . '" />'; echo '</td>'; } else { echo '<td align="right">'; if (!empty($acourse->guest)) { echo '<a href="view.php?id=' . $acourse->id . '"><img title="' . $strallowguests . '" class="icon" src="' . $OUTPUT->old_icon_url('i/guest') . '" alt="' . $strallowguests . '" /></a>'; } if (!empty($acourse->password)) { echo '<a href="view.php?id=' . $acourse->id . '"><img title="' . $strrequireskey . '" class="icon" src="' . $OUTPUT->old_icon_url('i/key') . '" alt="' . $strrequireskey . '" /></a>'; } if (!empty($acourse->summary)) { $link = html_link::make("/course/info.php?id={$acourse->id}", '<img alt="' . get_string('info') . '" class="icon" src="' . $OUTPUT->old_icon_url('i/info') . '" />'); $link->add_action(new popup_action('click', $link->url, 'courseinfo')); $link->title = $strsummary; echo $OUTPUT->link($link); } echo "</td>"; } echo "</tr>"; } if ($abletomovecourses) { $movetocategories = array(); $notused = array(); make_categories_list($movetocategories, $notused, 'moodle/category:manage'); $movetocategories[$category->id] = get_string('moveselectedcoursesto'); echo '<tr><td colspan="3" align="right">'; $select = new html_select();
/** * @param string $colname the name of the column. * @param object $attempt the row of data - see the SQL in display() in * mod/quiz/report/overview/report.php to see what fields are present, * and what they are called. * @return string the contents of the cell. */ function other_cols($colname, $attempt) { global $OUTPUT; if (preg_match('/^qsgrade([0-9]+)$/', $colname, $matches)) { $questionid = $matches[1]; $question = $this->questions[$questionid]; if (isset($this->gradedstatesbyattempt[$attempt->attemptuniqueid][$questionid])) { $stateforqinattempt = $this->gradedstatesbyattempt[$attempt->attemptuniqueid][$questionid]; } else { $stateforqinattempt = false; } if ($stateforqinattempt && question_state_is_graded($stateforqinattempt)) { $grade = quiz_rescale_grade($stateforqinattempt->grade, $this->quiz, 'question'); if (!$this->is_downloading()) { if (isset($this->regradedqs[$attempt->attemptuniqueid][$questionid])) { $gradefromdb = $grade; $newgrade = quiz_rescale_grade($this->regradedqs[$attempt->attemptuniqueid][$questionid]->newgrade, $this->quiz, 'question'); $oldgrade = quiz_rescale_grade($this->regradedqs[$attempt->attemptuniqueid][$questionid]->oldgrade, $this->quiz, 'question'); $grade = '<del>' . $oldgrade . '</del><br />' . $newgrade; } $link = html_link::make("/mod/quiz/reviewquestion.php?attempt={$attempt->attempt}&question={$question->id}", $grade); $link->add_action(new popup_action('click', $link->url, 'reviewquestion', array('height' => 450, 'width' => 650))); $link->title = get_string('reviewresponsetoq', 'quiz', $question->formattedname); $linktopopup = $OUTPUT->link($link); if ($this->questions[$questionid]->maxgrade != 0) { $fractionofgrade = $stateforqinattempt->grade / $this->questions[$questionid]->maxgrade; $qclass = question_get_feedback_class($fractionofgrade); $feedbackimg = question_get_feedback_image($fractionofgrade); $questionclass = "que"; return "<span class=\"{$questionclass}\"><span class=\"{$qclass}\">" . $linktopopup . "</span></span>{$feedbackimg}"; } else { return $linktopopup; } } else { return $grade; } } else { return '--'; } } else { return NULL; } }
/** * Print a row of contactlist displaying user picture, messages waiting and * block links etc * @param $contact contact object containing all fields required for $OUTPUT->user_picture() * @param $incontactlist is the user a contact of ours? */ function message_print_contactlist_user($contact, $incontactlist = true) { global $OUTPUT; $fullname = fullname($contact); $fullnamelink = $fullname; /// are there any unread messages for this contact? if ($contact->messagecount > 0) { $fullnamelink = '<strong>' . $fullnamelink . ' (' . $contact->messagecount . ')</strong>'; } if ($incontactlist) { $strcontact = message_contact_link($contact->id, 'remove', true); $strblock = ''; } else { $strcontact = message_contact_link($contact->id, 'add', true); $strblock = ' ' . message_contact_link($contact->id, 'block', true); } $strhistory = message_history_link($contact->id, 0, true, '', '', 'icon'); echo '<tr><td class="pix">'; $userpic = moodle_user_picture::make($contact, SITEID); $userpic->size = 20; $userpic->link = true; echo $OUTPUT->user_picture($userpic); echo '</td>'; echo '<td class="contact">'; $popupoptions = array('height' => 500, 'width' => 500, 'menubar' => false, 'location' => false, 'status' => true, 'scrollbars' => true, 'resizable' => true); $link = html_link::make("/message/discussion.php?id={$contact->id}", $fullnamelink); $link->add_action(new popup_action('click', $link->url, "message_{$contact->id}", $popupoptions)); $link->title = get_string('sendmessageto', 'message', $fullname); echo $OUTPUT->link($link); echo '</td>'; echo '<td class="link"> ' . $strcontact . $strblock . ' ' . $strhistory . '</td>'; echo '</tr>'; }
$link->title = get_string('modulename', 'chat'); echo $OUTPUT->link($link); echo '</p>'; if ($CFG->enableajax) { echo '<p>'; $link = html_link::make("/mod/chat/gui_ajax/index.php?id={$chat->id}{$groupparam}", get_string('ajax_gui', 'message')); $link->add_action(new popup_action('click', $link->url, "chat{$course->id}{$chat->id}{$groupparam}", array('height' => 500, 'width' => 700))); $link->title = get_string('modulename', 'chat'); echo $OUTPUT->link($link); echo '</p>'; } // if user is using screen reader, then there is no need to display this link again if ($CFG->chat_method == 'header_js' && empty($USER->screenreader)) { // show frame/js-less alternative echo '<p>('; $link = html_link::make("/mod/chat/gui_basic/index.php?id={$chat->id}{$groupparam}", get_string('noframesjs', 'message')); $link->add_action(new popup_action('click', $link->url, "chat{$course->id}{$chat->id}{$groupparam}", array('height' => 500, 'width' => 700))); $link->title = get_string('modulename', 'chat'); echo $OUTPUT->link($link); echo ')</p>'; } echo $OUTPUT->box_end(); } else { echo $OUTPUT->box_start('generalbox', 'notallowenter'); echo '<p>' . get_string('notallowenter', 'chat') . '</p>'; echo $OUTPUT->box_end(); } if ($chat->chattime and $chat->schedule) { // A chat is scheduled echo "<p class=\"nextchatsession\">{$strnextsession}: " . userdate($chat->chattime) . ' (' . usertimezone($USER->timezone) . ')</p>'; } else {
/** * @param object $quiz the quiz * @param object $question the question * @param boolean $label if true, show the previewquestion label after the icon * @return the HTML for a preview question icon. */ function quiz_question_preview_button($quiz, $question, $label = false) { global $CFG, $COURSE, $OUTPUT; if (!question_has_capability_on($question, 'use', $question->category)) { return ''; } // Minor efficiency saving. Only get strings once, even if there are a lot of icons on one page. static $strpreview = null; static $strpreviewquestion = null; if ($strpreview === null) { $strpreview = get_string('preview', 'quiz'); $strpreviewquestion = get_string('previewquestion', 'quiz'); } // Do we want a label? $strpreviewlabel = ""; if ($label) { $strpreviewlabel = $strpreview; } // Build the icon. $image = new html_image(); $image->src = $OUTPUT->old_icon_url('t/preview'); $image->add_class('iconsmall'); $image->alt = $strpreviewquestion; $link = html_link::make("/question/preview.php?id={$question->id}&quizid={$quiz->id}", $strpreviewlabel); parse_str(QUESTION_PREVIEW_POPUP_OPTIONS, $options); $link->add_action(new popup_action('click', $link->url, 'questionpreview', $options)); $link->title = $strpreviewquestion; return $OUTPUT->link_to_popup($link, $image); }
public function test_link_to_popup() { $link = new html_link(); $link->text = 'Click here'; $link->url = 'http://test.com'; $link->title = 'Popup window'; $popupaction = new popup_action('click', 'http://test.com', 'my_popup'); $link->add_action($popupaction); $html = $this->renderer->link_to_popup($link); $expectedattributes = array('title' => 'Popup window', 'href' => 'http://test.com'); $this->assert(new ContainsTagWithAttributes('a', $expectedattributes), $html); $this->assert(new ContainsTagWithContents('a', 'Click here'), $html); // Try a different url for the link than for the popup $link->url = 'http://otheraddress.com'; $html = $this->renderer->link_to_popup($link); $this->assert(new ContainsTagWithAttribute('a', 'title', 'Popup window'), $html); $this->assert(new ContainsTagWithAttribute('a', 'href', 'http://otheraddress.com'), $html); $this->assert(new ContainsTagWithContents('a', 'Click here'), $html); // Give it a moodle_url object instead of a string $link->url = new moodle_url('http://otheraddress.com'); $html = $this->renderer->link_to_popup($link); $this->assert(new ContainsTagWithAttribute('a', 'title', 'Popup window'), $html); $this->assert(new ContainsTagWithAttribute('a', 'href', 'http://otheraddress.com'), $html); $this->assert(new ContainsTagWithContents('a', 'Click here'), $html); }
require_once '../../../config.php'; require_once '../../lib.php'; require_once 'lib.php'; require_once $CFG->libdir . '/adminlib.php'; $id = optional_param('id', 0, PARAM_INT); // Course ID if (!($course = $DB->get_record('course', array('id' => $id)))) { print_error('invalidcourseid'); } require_login($course); $context = get_context_instance(CONTEXT_COURSE, $course->id); require_capability('coursereport/log:viewlive', $context); $strlogs = get_string('logs'); $strreports = get_string('reports'); if ($course->id == SITEID) { admin_externalpage_setup('reportloglive'); admin_externalpage_print_header(); } else { $navlinks = array(); $navlinks[] = array('name' => $strreports, 'link' => "{$CFG->wwwroot}/course/report.php?id={$course->id}", 'type' => 'misc'); $navlinks[] = array('name' => $strlogs, 'link' => null, 'type' => 'misc'); $navigation = build_navigation($navlinks); print_header($course->shortname . ': ' . $strlogs, $course->fullname, $navigation, ''); } echo $OUTPUT->heading(get_string('loglive', 'coursereport_log')); echo $OUTPUT->container_start('info'); $link = html_link::make('/course/report/log/live.php?id=' . $course->id, get_string('livelogs')); $link->add_action(new popup_action('click', $link->url, 'livelog', array('height' => 500, 'width' => 800))); echo $OUTPUT->link($link); echo $OUTPUT->container_end(); echo $OUTPUT->footer();
function _createElements() { global $CFG, $OUTPUT; $this->_elements = array(); // Official tags. $showingofficial = $this->_options['display'] != MoodleQuickForm_tags::NOOFFICIAL; if ($showingofficial) { $this->_load_official_tags(); // If the user can manage official tags, give them a link to manage them. $label = get_string('otags', 'tag'); if (has_capability('moodle/tag:manage', get_context_instance(CONTEXT_SYSTEM))) { $link = html_link::make($CFG->wwwroot . '/tag/manage.php', get_string('manageofficialtags', 'tag')); $link->add_action(new popup_action('click', $link->url, 'managetags')); $link->title = get_string('newwindow'); $label .= ' (' . $OUTPUT->link($link) . ')'; } // Get the list of official tags. $noofficial = false; if (empty($this->_officialtags)) { $officialtags = array('' => get_string('none')); $noofficial = true; } else { $officialtags = array_combine($this->_officialtags, $this->_officialtags); } // Create the element. $size = min(5, count($officialtags)); $officialtagsselect = MoodleQuickForm::createElement('select', 'officialtags', $label, $officialtags, array('size' => $size)); $officialtagsselect->setMultiple(true); if ($noofficial) { $officialtagsselect->updateAttributes(array('disabled' => 'disabled')); } $this->_elements[] = $officialtagsselect; } // Other tags. if ($this->_options['display'] != MoodleQuickForm_tags::ONLYOFFICIAL) { if ($showingofficial) { $label = get_string('othertags', 'tag'); } else { $label = get_string('entertags', 'tag'); } $othertags = MoodleQuickForm::createElement('textarea', 'othertags', $label, array('cols' => '40', 'rows' => '5')); $this->_elements[] = $othertags; } // Paradoxically, the only way to get labels output is to ask for 'hidden' // labels, and then override the .accesshide class in the CSS! foreach ($this->_elements as $element) { if (method_exists($element, 'setHiddenLabel')) { $element->setHiddenLabel(true); } } }
function other_cols($colname, $attempt) { global $QTYPES, $OUTPUT; static $states = array(); if (preg_match('/^qsanswer([0-9]+)$/', $colname, $matches)) { if ($attempt->uniqueid == 0) { return '-'; } $questionid = $matches[1]; if (isset($this->gradedstatesbyattempt[$attempt->uniqueid][$questionid])) { $stateforqinattempt = $this->gradedstatesbyattempt[$attempt->uniqueid][$questionid]; } else { return '-'; } $question = $this->questions[$questionid]; restore_question_state($question, $stateforqinattempt); if (!$this->is_downloading() || $this->is_downloading() == 'xhtml') { $formathtml = true; } else { $formathtml = false; } $summary = $QTYPES[$question->qtype]->response_summary($question, $stateforqinattempt, QUIZ_REPORT_RESPONSES_MAX_LEN_TO_DISPLAY, $formathtml); if (!$this->is_downloading()) { if ($summary) { $link = html_link::make("/mod/quiz/reviewquestion.php?attempt={$attempt->attempt}&question={$question->id}", $summary); $link->add_action(new popup_action('click', $link->url, 'reviewquestion', array('height' => 450, 'width' => 650))); $link->title = $question->formattedname; $summary = $OUTPUT->link($link); if (question_state_is_graded($stateforqinattempt) && $question->maxgrade > 0) { $grade = $stateforqinattempt->grade / $question->maxgrade; $qclass = question_get_feedback_class($grade); $feedbackimg = question_get_feedback_image($grade); $questionclass = "que"; return "<span class=\"{$questionclass}\"><span class=\"{$qclass}\">" . $summary . "</span></span>{$feedbackimg}"; } else { return $summary; } } else { return ''; } } else { return $summary; } } else { return NULL; } }
/** * Print the multiple ratings on a post given to the current user by others. * Forumid prevents the double lookup of the forumid in discussion to determine the aggregate type * Scale is an array of ratings * * @uses FORUM_AGGREGATE_AVG * @uses FORUM_AGGREGATE_COUNT * @uses FORUM_AGGREGATE_MAX * @uses FORUM_AGGREGATE_MIN * @uses FORUM_AGGREGATE_SUM * @param int $postid * @param array $scale * @param int $aggregatetype * @param bool $link * @param array $ratings * @param bool $return * @return string|void */ function forum_print_ratings($postid, $scale, $aggregatetype, $link = true, $ratings = null, $return = false) { global $OUTPUT; $strratings = ''; switch ($aggregatetype) { case FORUM_AGGREGATE_AVG: $agg = forum_get_ratings_mean($postid, $scale, $ratings); $strratings = get_string("aggregateavg", "forum"); break; case FORUM_AGGREGATE_COUNT: $agg = forum_get_ratings_count($postid, $scale, $ratings); $strratings = get_string("aggregatecount", "forum"); break; case FORUM_AGGREGATE_MAX: $agg = forum_get_ratings_max($postid, $scale, $ratings); $strratings = get_string("aggregatemax", "forum"); break; case FORUM_AGGREGATE_MIN: $agg = forum_get_ratings_min($postid, $scale, $ratings); $strratings = get_string("aggregatemin", "forum"); break; case FORUM_AGGREGATE_SUM: $agg = forum_get_ratings_sum($postid, $scale, $ratings); $strratings = get_string("aggregatesum", "forum"); break; } if ($agg !== "") { if (empty($strratings)) { $strratings = get_string("ratings", "forum"); } $strratings .= ': '; if ($link) { $link = html_link::make("/mod/forum/report.php?id={$postid}", $agg); $link->add_action(new popup_action('click', $link->url, 'ratings', array('height' => 400, 'width' => 600))); $strratings .= $OUTPUT->link($link); } else { $strratings .= "{$agg} "; } if ($return) { return $strratings; } else { echo $strratings; } } }