/** * Prints out javascript required to track which modules have been selected */ function massaction_print_js() { global $COURSE, $CFG, $USER; if (ajaxenabled() || !$COURSE || $COURSE->id == 1) { return; } else { echo "<script type='text/javascript'>"; include "massaction.js"; echo "</script>"; } }
/** * Uses the array of user agents to test ajax_lib::ajaxenabled */ function test_ajaxenabled() { global $CFG, $USER; $this->resetAfterTest(true); $CFG->enableajax = 1; $USER->ajax = 1; // Should be true $_SERVER['HTTP_USER_AGENT'] = $this->user_agents['Firefox']['2.0']['Windows XP']; $this->assertTrue(ajaxenabled()); $_SERVER['HTTP_USER_AGENT'] = $this->user_agents['Firefox']['1.5']['Windows XP']; $this->assertTrue(ajaxenabled()); $_SERVER['HTTP_USER_AGENT'] = $this->user_agents['Safari']['2.0']['Mac OS X']; $this->assertTrue(ajaxenabled()); $_SERVER['HTTP_USER_AGENT'] = $this->user_agents['Opera']['9.0']['Windows XP']; $this->assertTrue(ajaxenabled()); $_SERVER['HTTP_USER_AGENT'] = $this->user_agents['MSIE']['6.0']['Windows XP SP2']; $this->assertTrue(ajaxenabled()); // Should be false $_SERVER['HTTP_USER_AGENT'] = $this->user_agents['Firefox']['1.0.6']['Windows XP']; $this->assertFalse(ajaxenabled()); $_SERVER['HTTP_USER_AGENT'] = $this->user_agents['Safari']['312']['Mac OS X']; $this->assertFalse(ajaxenabled()); $_SERVER['HTTP_USER_AGENT'] = $this->user_agents['Opera']['8.51']['Windows XP']; $this->assertFalse(ajaxenabled()); $_SERVER['HTTP_USER_AGENT'] = $this->user_agents['MSIE']['5.5']['Windows 2000']; $this->assertFalse(ajaxenabled()); // Test array of tested browsers $tested_browsers = array('MSIE' => 6.0, 'Gecko' => 20061111); $_SERVER['HTTP_USER_AGENT'] = $this->user_agents['Firefox']['2.0']['Windows XP']; $this->assertTrue(ajaxenabled($tested_browsers)); $_SERVER['HTTP_USER_AGENT'] = $this->user_agents['MSIE']['7.0']['Windows XP SP2']; $this->assertTrue(ajaxenabled($tested_browsers)); $_SERVER['HTTP_USER_AGENT'] = $this->user_agents['Safari']['2.0']['Mac OS X']; $this->assertFalse(ajaxenabled($tested_browsers)); $_SERVER['HTTP_USER_AGENT'] = $this->user_agents['Opera']['9.0']['Windows XP']; $this->assertFalse(ajaxenabled($tested_browsers)); $tested_browsers = array('Safari' => 412, 'Opera' => 9.0); $_SERVER['HTTP_USER_AGENT'] = $this->user_agents['Firefox']['2.0']['Windows XP']; $this->assertFalse(ajaxenabled($tested_browsers)); $_SERVER['HTTP_USER_AGENT'] = $this->user_agents['MSIE']['7.0']['Windows XP SP2']; $this->assertFalse(ajaxenabled($tested_browsers)); $_SERVER['HTTP_USER_AGENT'] = $this->user_agents['Safari']['2.0']['Mac OS X']; $this->assertTrue(ajaxenabled($tested_browsers)); $_SERVER['HTTP_USER_AGENT'] = $this->user_agents['Opera']['9.0']['Windows XP']; $this->assertTrue(ajaxenabled($tested_browsers)); }
/** * Used to include JavaScript libraries. * * When the $lib parameter is given, the function will add $lib to an * internal list of libraries. When called without any parameters, it will * return the html that is needed to load the JavaScript libraries in that * list. Libraries that are included more than once will still only get loaded * once, so this works like require_once() in PHP. * * @param $lib - string or array of strings * string(s) should be the shortname for the library or the * full path to the library file. * @return string or false or nothing. */ function require_js($lib = '') { global $CFG; static $loadlibs = array(); if (!ajaxenabled()) { //return false; } if (!empty($lib)) { // Add the lib to the list of libs to be loaded, if it isn't already // in the list. if (is_array($lib)) { array_map('require_js', $lib); } else { $libpath = ajax_get_lib($lib); if (array_search($libpath, $loadlibs) === false) { $loadlibs[] = $libpath; // If this is called after header, then we print it right away // as otherwise nothing will ever happen! if (defined('HEADER_PRINTED')) { $realloadlibs = $loadlibs; $loadlibs = array($libpath); print require_js(); $loadlibs = $realloadlibs; } } } } else { // Return the html needed to load the JavaScript files defined in // our list of libs to be loaded. $output = ''; foreach ($loadlibs as $loadlib) { $output .= '<script type="text/javascript" '; $output .= " src=\"{$loadlib}\"></script>\n"; if ($loadlib == $CFG->wwwroot . '/lib/yui/logger/logger-min.js') { // Special case, we need the CSS too. $output .= '<link type="text/css" rel="stylesheet" '; $output .= " href=\"{$CFG->wwwroot}/lib/yui/logger/assets/logger.css\" />\n"; } } return $output; } }
/** * Return contents of course_overview block * * @return stdClass contents of block */ public function get_content() { global $USER, $CFG, $DB; require_once $CFG->dirroot . '/user/profile/lib.php'; if ($this->content !== NULL) { return $this->content; } $config = get_config('block_course_overview'); $this->content = new stdClass(); $this->content->text = ''; $this->content->footer = ''; $content = array(); $updatemynumber = optional_param('mynumber', -1, PARAM_INT); if ($updatemynumber >= 0) { block_course_overview_update_mynumber($updatemynumber); } profile_load_custom_fields($USER); list($sortedcourses, $sitecourses, $totalcourses) = block_course_overview_get_sorted_courses(); $overviews = block_course_overview_get_overviews($sitecourses); $renderer = $this->page->get_renderer('block_course_overview'); if (!empty($config->showwelcomearea)) { require_once $CFG->dirroot . '/message/lib.php'; $msgcount = message_count_unread_messages(); $this->content->text = $renderer->welcome_area($msgcount); } // Number of sites to display. if ($this->page->user_is_editing() && empty($config->forcedefaultmaxcourses)) { $this->content->text .= $renderer->editing_bar_head($totalcourses); } if (empty($sortedcourses)) { $this->content->text .= get_string('nocourses', 'my'); } else { // For each course, build category cache. $this->content->text .= $renderer->course_overview($sortedcourses, $overviews); $this->content->text .= $renderer->hidden_courses($totalcourses - count($sortedcourses)); if ($this->page->user_is_editing() && ajaxenabled()) { $this->page->requires->js_init_call('M.block_course_overview.add_handles'); } } return $this->content; }
/** * Construct contents of course_overview block * * @param array $courses list of courses in sorted order * @param array $overviews list of course overviews * @return string html to be displayed in course_overview block */ public function course_overview($courses, $overviews) { $html = ''; $config = get_config('block_course_overview'); $html .= html_writer::start_tag('div', array('id' => 'course_list')); $courseordernumber = 0; $maxcourses = count($courses); // Intialize string/icon etc if user is editing. $url = null; $moveicon = null; $moveup[] = null; $movedown[] = null; if ($this->page->user_is_editing()) { if (ajaxenabled()) { $moveicon = html_writer::tag('div', html_writer::empty_tag('img', array('src' => $this->pix_url('i/move_2d')->out(false), 'alt' => get_string('move'), 'class' => 'cursor', 'title' => get_string('move'))), array('class' => 'move')); } else { $url = new moodle_url('/blocks/course_overview/move.php', array('sesskey' => sesskey())); $moveup['str'] = get_string('moveup'); $moveup['icon'] = $this->pix_url('t/up'); $movedown['str'] = get_string('movedown'); $movedown['icon'] = $this->pix_url('t/down'); } } foreach ($courses as $key => $course) { $html .= $this->output->box_start('coursebox', "course-{$course->id}"); $html .= html_writer::start_tag('div', array('class' => 'course_title')); // Ajax enabled then add moveicon html if (!is_null($moveicon)) { $html .= $moveicon; } else { if (!is_null($url)) { // Add course id to move link $url->param('source', $course->id); $html .= html_writer::start_tag('div', array('class' => 'moveicons')); // Add an arrow to move course up. if ($courseordernumber > 0) { $url->param('move', -1); $html .= html_writer::link($url, html_writer::empty_tag('img', array('src' => $moveup['icon'], 'class' => 'up', 'alt' => $moveup['str'])), array('title' => $moveup['str'], 'class' => 'moveup')); } else { // Add a spacer to keep keep down arrow icons at right position. $html .= html_writer::empty_tag('img', array('src' => $this->pix_url('spacer'), 'class' => 'movedownspacer')); } // Add an arrow to move course down. if ($courseordernumber <= $maxcourses - 2) { $url->param('move', 1); $html .= html_writer::link($url, html_writer::empty_tag('img', array('src' => $movedown['icon'], 'class' => 'down', 'alt' => $movedown['str'])), array('title' => $movedown['str'], 'class' => 'movedown')); } else { // Add a spacer to keep keep up arrow icons at right position. $html .= html_writer::empty_tag('img', array('src' => $this->pix_url('spacer'), 'class' => 'moveupspacer')); } $html .= html_writer::end_tag('div'); } } $attributes = array('title' => s($course->fullname)); if ($course->id > 0) { $link = html_writer::link(new moodle_url('/course/view.php', array('id' => $course->id)), format_string($course->shortname, true, $course->id), $attributes); $html .= $this->output->heading($link, 2, 'title'); } else { $html .= $this->output->heading(html_writer::link(new moodle_url('/auth/mnet/jump.php', array('hostid' => $course->hostid, 'wantsurl' => '/course/view.php?id=' . $course->remoteid)), format_string($course->shortname, true), $attributes) . ' (' . format_string($course->hostname) . ')', 2, 'title'); } $html .= $this->output->box('', 'flush'); $html .= html_writer::end_tag('div'); if (!empty($config->showchildren) && $course->id > 0) { // List children here. if ($children = block_course_overview_get_child_shortnames($course->id)) { $html .= html_writer::tag('span', $children, array('class' => 'coursechildren')); } } if (isset($overviews[$course->id])) { $html .= $this->activity_display($course->id, $overviews[$course->id]); } $html .= $this->output->box('', 'flush'); $html .= $this->output->box_end(); $courseordernumber++; } $html .= html_writer::end_tag('div'); return $html; }
ou_set_is_mobile(ou_get_is_mobile_from_cookies()); if (ou_get_is_mobile()) { ou_mobile_configure_theme(); } } ouwiki_print_start($ouwiki, $cm, $course, $subwiki, $pagename, $context); global $CFG; //cheeck consistency in setting Sub-wikis and group mode; $urllink = $CFG->wwwroot . '/course/view.php?id=' . $cm->course; if ($cm->groupmode == 0 && isset($subwiki->groupid)) { error("Sub-wikis is set to 'One wiki per group'. \n Please change Group mode to 'Separate groups' or 'Visible groups'.", $urllink); } if ($cm->groupmode > 0 && !isset($subwiki->groupid)) { error("Sub-wikis is NOT set to 'One wiki per group'. \n Please change Group mode to 'No groups'.", $urllink); } if (ajaxenabled() || class_exists('ouflags')) { // YUI and basic script require_js(array('yui_yahoo', 'yui_event', 'yui_connection', 'yui_dom', 'yui_animation')); // Print javascript print '<script type="text/javascript" src="ouwiki.js"></script><script type="text/javascript"> strCloseComments="' . addslashes_js(get_string('closecomments', 'ouwiki')) . '"; strCloseCommentForm="' . addslashes_js(get_string('closecommentform', 'ouwiki')) . '"; </script>'; } // Get the current page version $pageversion = ouwiki_get_current_page($subwiki, $pagename); $locked = $pageversion ? $pageversion->locked : false; ouwiki_print_tabs('view', $pagename, $subwiki, $cm, $context, $pageversion ? true : false, $locked); if (($pagename === '' || $pagename === null) && strlen(preg_replace('/\\s|<br\\s*\\/?>|<p>|<\\/p>/', '', $ouwiki->summary)) > 0) { print '<div class="ouw_summary">' . format_text($ouwiki->summary) . '</div>'; }
/** * Prints out (immediately; must be after header) script tags and JS code * for the forum's JavaScript library, and required YUI libraries. * @param int $cmid If specified, passes this through to JS * @param int $absolute If true, use absolute path to embed the JS file. Default set to false */ public function print_js($cmid = 0, $absolute = false) { $simple = get_user_preferences('forumng_simplemode', ''); if (forum_utils::is_bad_browser() || $simple) { return; } global $CFG; if (ajaxenabled() || class_exists('ouflags')) { // YUI and basic script require_js(array('yui_yahoo', 'yui_event', 'yui_connection', 'yui_dom', 'yui_animation')); if ($absolute) { print '<script type="text/javascript" src="' . $CFG->wwwroot . '/mod/forumng/forumng.js"></script>'; } else { print '<script type="text/javascript" src="forumng.js"></script>'; } // Language strings and other data for JS $strings = ''; $mainstrings = array('showadvanced' => null, 'hideadvanced' => null, 'rate' => null, 'expand' => '#', 'jserr_load' => null, 'jserr_save' => null, 'jserr_alter' => null, 'confirmdelete' => null, 'confirmundelete' => null, 'deletepostbutton' => null, 'undeletepostbutton' => null, 'js_nratings' => null, 'js_nratings1' => null, 'js_nopublicrating' => null, 'js_publicrating' => null, 'js_nouserrating' => null, 'js_userrating' => null, 'js_outof' => null, 'js_clicktosetrating' => null, 'js_clicktosetrating1' => null, 'js_clicktoclearrating' => null, 'edit_timeout' => null, 'selectlabel' => null, 'selectintro' => null, 'confirmselection' => null, 'selectedposts' => null, 'discussion' => null, 'selectorall' => null, 'flagon' => null, 'flagoff' => null, 'clearflag' => null, 'setflag' => null); if ($this->has_post_quota()) { $mainstrings['quotaleft_plural'] = (object) array('posts' => '#', 'period' => $this->get_max_posts_period(true, true)); $mainstrings['quotaleft_singular'] = (object) array('posts' => '#', 'period' => $this->get_max_posts_period(true, true)); } foreach ($mainstrings as $string => $value) { if ($strings !== '') { $strings .= ','; } $strings .= $string . ':"' . addslashes_js(get_string($string, 'forumng', $value)) . '"'; } foreach (array('cancel', 'delete', 'add', 'selectall', 'deselectall') as $string) { $strings .= ',core_' . $string . ':"' . addslashes_js(get_string($string)) . '"'; } // Use star ratings where the scale is between 2 and 5 (3 and 6 stars) $scale = $this->get_rating_scale(); if ($scale > 1 && $scale < 6) { $ratingstars = $scale; } else { $ratingstars = 0; } print '<script type="text/javascript">//<!--' . "\n" . 'forumng_pixpath="' . addslashes_js($CFG->pixpath) . '";' . 'forumng_modpixpath="' . addslashes_js($CFG->modpixpath . '/forumng') . '";' . 'forumng_strings={' . $strings . '};' . 'forumng_ratingstars=' . $ratingstars . ';' . ($cmid ? 'forumng_cmid=' . $cmid . ';' : '') . "\n" . '//--></script>'; } }
/** * Displays the reply/edit form on a discussion page. Usually this form is * hidden by CSS and only displayed when JavaScript activates it. * @param forum $forum * @return string HTMl for form */ public function display_ajax_forms($forum) { global $CFG; if (!ajaxenabled() && !class_exists('ouflags')) { return ''; } require_once $CFG->dirroot . '/mod/forumng/editpost_form.php'; // Reply form $mform = new mod_forumng_editpost_form('editpost.php', array('params' => array(), 'isdiscussion' => false, 'ispost' => true, 'islock' => false, 'forum' => $forum, 'edit' => false, 'post' => null, 'ajaxversion' => 1, 'isroot' => false)); $result = $mform->_form->toHtml(); // Edit form $mform = new mod_forumng_editpost_form('editpost.php', array('params' => array(), 'isdiscussion' => false, 'ispost' => true, 'islock' => false, 'forum' => $forum, 'edit' => true, 'post' => null, 'ajaxversion' => 2, 'isroot' => false)); $result .= $mform->_form->toHtml(); // Edit form (discussion) $mform = new mod_forumng_editpost_form('editpost.php', array('params' => array(), 'isdiscussion' => false, 'ispost' => true, 'islock' => false, 'forum' => $forum, 'edit' => true, 'post' => null, 'ajaxversion' => 3, 'isroot' => true)); $result .= $mform->_form->toHtml(); if (can_use_html_editor()) { // Kill form textarea so that TinyMCE doesn't initialise it (it doesn't // work if we let it do that) $result = preg_replace('~<textarea .*?id="(.*?)" name="(.*?)".*?</textarea>~s', '<input type="hidden" id="$1" name="$2" value="" />', $result); // Turn HTMLArea JavaScript into functions we can call to init it $result = preg_replace('~<script type="text/javascript" defer="defer">[^e]*editor.*?\\(\'(.*?)\'\\);[^;]*;([^/]*?)editor_[a-f0-9]*\\.generate[^<]*</script>~', '<script type="text/javascript"> //<![CDATA[ document.getElementById(\'$1\').form.inithtmlarea = function() { var form = document.getElementById(\'$1\').form; form.htmlarea = new HTMLArea("$1"); var config = form.htmlarea.config; $2 form.htmlarea.generate(); }; //]]> </script>', $result); } return '<div id="forumng-formhome">' . $result . '</div>'; }
$mail->action = EMAIL_REPLY; $mailform->set_data($mail); } if ($action == EMAIL_FORWARD) { $mailform->set_data($newmail); } if ($action == EMAIL_EDITDRAFT) { $mailform->set_data($mail); } if ($action == EMAIL_REPLY or $action == EMAIL_REPLYALL or $action == EMAIL_FORWARD) { $mailform->focus('body'); } else { $mailform->focus('subject'); } $mailform->display(); if ($CFG->email_enable_ajax && ajaxenabled($CFG->ajaxtestedbrowsers)) { require_once $CFG->dirroot . '/blocks/email_list/email/participants/yui_autocomplete.html'; } if ($action == EMAIL_REPLY) { if ($CFG->email_enable_ajax) { echo '<script type="text/javascript" language="JavaScript">var input = \'<input type="hidden" value="' . $user->id . '" name="to[]">\';' . 'var rand = get_random();' . 'var fullname = window.document.createElement("span");' . 'fullname.setAttribute("id", "id_nameto"+rand);' . 'fullname.setAttribute("class", "ajax_user_selected");' . 'window.document.getElementById("id_nameto").parentNode.insertBefore(fullname,window.document.getElementById("id_nameto"));' . 'var htmlimg = "<img class=\\"imgdropuser\\" src=\\"' . $wwwroot . '/blocks/email_list/email/images/cross.png\\" height=\\"11\\" width=\\"11\\" alt=\\"' . get_string('remove', 'block_email_list') . '\\" />";' . 'fullname.innerHTML = "' . fullname($user, $context) . '<a href=\\"#\\" onClick=\\"removeAJAXContact(\'id_nameto"+rand+"\');\\">"+htmlimg+input+"</a>";</script>'; } else { echo ' <script type="text/javascript" language="JavaScript"> var contacts = window.document.createElement("span"); window.document.getElementById(\'id_nameto\').parentNode.appendChild(contacts); contacts.innerHTML = \'<input type="hidden" value="' . $user->id . '" name="to[]">\';</script>'; } } if ($action == EMAIL_REPLYALL) { echo ' <script type="text/javascript" language="JavaScript">'; foreach ($selectedusersto as $selecteduser) { if ($CFG->email_enable_ajax) {
/** * */ function forum_print_discussion($course, $cm, $forum, $discussion, $post, $mode, $canreply = NULL, $canrate = false) { global $USER, $CFG; if (!empty($USER->id)) { $ownpost = $USER->id == $post->userid; } else { $ownpost = false; } if ($canreply === NULL) { $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id); $reply = forum_user_can_post($forum, $discussion, $USER, $cm, $course, $modcontext); } else { $reply = $canreply; } // $cm holds general cache for forum functions $cm->cache = new object(); $cm->cache->groups = groups_get_all_groups($course->id, 0, $cm->groupingid); $cm->cache->usersgroups = array(); $posters = array(); // preload all posts - TODO: improve... if ($mode == FORUM_MODE_FLATNEWEST) { $sort = "p.created DESC"; } else { $sort = "p.created ASC"; } $forumtracked = forum_tp_is_tracked($forum); $posts = forum_get_all_discussion_posts($discussion->id, $sort, $forumtracked); $post = $posts[$post->id]; foreach ($posts as $pid => $p) { $posters[$p->userid] = $p->userid; } // preload all groups of ppl that posted in this discussion if ($postersgroups = groups_get_all_groups($course->id, $posters, $cm->groupingid, 'gm.id, gm.groupid, gm.userid')) { foreach ($postersgroups as $pg) { if (!isset($cm->cache->usersgroups[$pg->userid])) { $cm->cache->usersgroups[$pg->userid] = array(); } $cm->cache->usersgroups[$pg->userid][$pg->groupid] = $pg->groupid; } unset($postersgroups); } $ratings = NULL; $ratingsmenuused = false; $ratingsformused = false; if ($forum->assessed and isloggedin()) { if ($scale = make_grades_menu($forum->scale)) { $ratings = new object(); $ratings->scale = $scale; $ratings->assesstimestart = $forum->assesstimestart; $ratings->assesstimefinish = $forum->assesstimefinish; $ratings->allow = $canrate; if ($ratings->allow) { echo '<form id="form" method="post" action="rate.php">'; echo '<div class="ratingform">'; echo '<input type="hidden" name="forumid" value="' . $forum->id . '" />'; echo '<input type="hidden" name="sesskey" value="' . sesskey() . '" />'; $ratingsformused = true; } // preload all ratings - one query only and minimal memory $cm->cache->ratings = array(); $cm->cache->myratings = array(); if ($postratings = forum_get_all_discussion_ratings($discussion)) { foreach ($postratings as $pr) { if (!isset($cm->cache->ratings[$pr->postid])) { $cm->cache->ratings[$pr->postid] = array(); } $cm->cache->ratings[$pr->postid][$pr->id] = $pr->rating; if ($pr->userid == $USER->id) { $cm->cache->myratings[$pr->postid] = $pr->rating; } } unset($postratings); } } } $post->forum = $forum->id; // Add the forum id to the post object, later used by forum_print_post $post->forumtype = $forum->type; $post->subject = format_string($post->subject); $postread = !empty($post->postread); if (forum_print_post($post, $discussion, $forum, $cm, $course, $ownpost, $reply, false, $ratings, '', '', $postread, true, $forumtracked)) { $ratingsmenuused = true; } switch ($mode) { case FORUM_MODE_FLATOLDEST: case FORUM_MODE_FLATNEWEST: default: if (forum_print_posts_flat($course, $cm, $forum, $discussion, $post, $mode, $ratings, $reply, $forumtracked, $posts)) { $ratingsmenuused = true; } break; case FORUM_MODE_THREADED: if (forum_print_posts_threaded($course, $cm, $forum, $discussion, $post, 0, $ratings, $reply, $forumtracked, $posts)) { $ratingsmenuused = true; } break; case FORUM_MODE_NESTED: if (forum_print_posts_nested($course, $cm, $forum, $discussion, $post, $ratings, $reply, $forumtracked, $posts)) { $ratingsmenuused = true; } break; } if ($ratingsformused) { if ($ratingsmenuused) { echo '<div class="ratingsubmit">'; echo '<input type="submit" id="forumpostratingsubmit" value="' . get_string('sendinratings', 'forum') . '" />'; if (ajaxenabled() && !empty($CFG->forum_ajaxrating)) { /// AJAX enabled, standard submission form $rate_ajax_config_settings = array("pixpath" => $CFG->pixpath, "wwwroot" => $CFG->wwwroot, "sesskey" => sesskey()); echo "<script type=\"text/javascript\">//<![CDATA[\n" . "var rate_ajax_config = " . json_encode($rate_ajax_config_settings) . ";\n" . "init_rate_ajax();\n" . "//]]></script>\n"; } if ($forum->scale < 0) { if ($scale = get_record("scale", "id", abs($forum->scale))) { print_scale_menu_helpbutton($course->id, $scale); } } echo '</div>'; } echo '</div>'; echo '</form>'; } }
} if ($showsection) { // user has rights to view this section $currentweek = $weekdate <= $timenow && $timenow < $nextweekdate; if (!$thissection->visible) { $sectionstyle = ' hidden'; } else { if ($currentweek) { $sectionstyle = ' current'; } else { $sectionstyle = ''; } } echo '<tr id="section-' . $section . '" class="section main' . $sectionstyle . '">'; echo '<td class="left side"> </td>'; if (ajaxenabled() && $editing) { // Temporarily hide the dates for the weeks. We do it this way // for now. Eventually, we'll have to modify the javascript code // to handle re-calculation of dates when sections are moved // around. For now, just hide all the dates to avoid confusion. $weekperiod = ''; } else { $weekperiod = $weekday . ' - ' . $endweekday; } echo '<td class="content">'; if (!has_capability('moodle/course:viewhiddensections', $context) and !$thissection->visible) { // Hidden for students echo '<div class="weekdates">' . $weekperiod . ' (' . get_string('notavailable') . ')</div>'; } else { echo '<div class="summary">'; echo ' <div class="heading">';
/** * Print out the header and any pre-page content information. * */ function print_header() { global $CFG, $PAGE, $USER, $COURSE, $course; // AJAX-capable course format? $CFG->useajax = false; $ajaxformatfile = $CFG->dirroot . '/course/format/' . $course->format . '/ajax.php'; $bodytags = ''; if (file_exists($ajaxformatfile)) { // Needs to exist otherwise no AJAX by default $CFG->ajaxcapable = false; // May be overridden later by ajaxformatfile $CFG->ajaxtestedbrowsers = array(); // May be overridden later by ajaxformatfile require_once $ajaxformatfile; if (!empty($USER->editing) && $CFG->ajaxcapable) { // Course-based switches if (ajaxenabled($CFG->ajaxtestedbrowsers)) { // rowser, user and site-based switches require_js(array('yui_yahoo', 'yui_dom', 'yui_event', 'yui_dragdrop', 'yui_connection', 'ajaxcourse_blocks', 'ajaxcourse_sections')); if (debugging('', DEBUG_DEVELOPER)) { require_js(array('yui_logger')); $bodytags = 'onload = "javascript: show_logger = function() { var logreader = new YAHOO.widget.LogReader(); logreader.newestOnTop = false; logreader.setTitle(\'Moodle Debug: YUI Log Console\'); }; show_logger(); "'; } // Okay, global variable alert. VERY UGLY. We need to create // this object here before the <blockname>_print_block() // function is called, since that function needs to set some // stuff in the javascriptportal object. $COURSE->javascriptportal = new jsportal(); $CFG->useajax = true; } } } $CFG->blocksdrag = $CFG->useajax; // this will add a new class to the header so we can style differently $PAGE->print_header(get_string('course') . ': %fullname%', NULL, '', $bodytags); }
/** * Print out the header and any pre-page content information. * */ function print_header() { global $CFG, $PAGE, $USER, $COURSE, $course; // AJAX-capable course format? $CFG->useajax = false; $ajaxformatfile = $CFG->dirroot . '/course/format/' . $course->format . '/ajax.php'; $bodytags = ''; if (file_exists($ajaxformatfile)) { // Needs to exist otherwise no AJAX by default $CFG->ajaxcapable = false; // May be overridden later by ajaxformatfile $CFG->ajaxtestedbrowsers = array(); // May be overridden later by ajaxformatfile require_once $ajaxformatfile; if (!empty($USER->editing) && $CFG->ajaxcapable) { // Course-based switches if (ajaxenabled($CFG->ajaxtestedbrowsers)) { // rowser, user and site-based switches require_js(array('yui_yahoo', 'yui_dom', 'yui_event', 'yui_dragdrop', 'yui_connection', 'ajaxcourse_blocks', 'ajaxcourse_sections')); if (debugging('', DEBUG_DEVELOPER)) { require_js(array('yui_logger')); $bodytags = 'onload = "javascript: show_logger = function() { var logreader = new YAHOO.widget.LogReader(); logreader.newestOnTop = false; logreader.setTitle(\'Moodle Debug: YUI Log Console\'); }; show_logger(); "'; } // Okay, global variable alert. VERY UGLY. We need to create // this object here before the <blockname>_print_block() // function is called, since that function needs to set some // stuff in the javascriptportal object. $COURSE->javascriptportal = new jsportal(); $CFG->useajax = true; } } } $CFG->blocksdrag = $CFG->useajax; // this will add a new class to the header so we can style differently /// *** The only part we are really changing is here.... $breadcrumbs = array($this->course->shortname => $CFG->wwwroot . '/course/view.php?id=' . $this->course->id); $total = count($breadcrumbs); $current = 1; $crumbtext = ''; foreach ($breadcrumbs as $text => $href) { if ($current++ == $total) { $crumbtext .= ' ' . $text; } else { $crumbtext .= ' <a href="' . $href . '">' . $text . '</a> ->'; } } // The "Editing On" button will be appearing only in the "main" course screen // (i.e., no breadcrumbs other than the default one added inside this function) $buttons = switchroles_form($this->course->id) . update_course_icon($this->course->id); $title = get_string('course') . ': ' . $this->course->fullname; if (empty($this->course->logo)) { $heading = $this->course->fullname; } else { $heading = '<img src="' . $CFG->wwwroot . '/file.php/' . $this->course->id . '/' . $this->course->logo . '" ' . 'alt="' . $this->course->fullname . '" />'; } print_header($title, $heading, $crumbtext, '', '', true, $buttons, user_login_string($this->course, $USER), false, $bodytags); echo '<div class="accesshide"><a href="#startofcontent">' . get_string('skiptomaincontent') . '</a></div>'; }
/** * Can handle rotated text. Whether it is safe to use the trickery in textrotate.js. * * @return bool True for yes, false for no */ function can_use_rotated_text() { global $USER; return ajaxenabled(array('Firefox' => 2.0)) && !$USER->screenreader; }
} else { redirect(course_get_url($course)); } } else { echo $OUTPUT->notification('An error occurred while moving a section'); } } } else { $USER->editing = 0; } $SESSION->fromdiscussion = $PAGE->url->out(false); if ($course->id == SITEID) { // This course is not a real course. redirect($CFG->wwwroot . '/'); } $ajaxenabled = ajaxenabled(); $completion = new completion_info($course); if ($completion->is_enabled() && $ajaxenabled) { $PAGE->requires->string_for_js('completion-title-manual-y', 'completion'); $PAGE->requires->string_for_js('completion-title-manual-n', 'completion'); $PAGE->requires->string_for_js('completion-alt-manual-y', 'completion'); $PAGE->requires->string_for_js('completion-alt-manual-n', 'completion'); $PAGE->requires->js_init_call('M.core_completion.init'); } // We are currently keeping the button here from 1.x to help new teachers figure out // what to do, even though the link also appears in the course admin block. It also // means you can back out of a situation where you removed the admin block. :) if ($PAGE->user_allowed_editing()) { $buttons = $OUTPUT->edit_button($PAGE->url); $PAGE->set_button($buttons); }
$PAGE->requires->string_for_js('completion-title-manual-n', 'completion'); $PAGE->requires->string_for_js('completion-alt-manual-y', 'completion'); $PAGE->requires->string_for_js('completion-alt-manual-n', 'completion'); $PAGE->requires->js_init_call('M.core_completion.init'); } // We are currently keeping the button here from 1.x to help new teachers figure out // what to do, even though the link also appears in the course admin block. It also // means you can back out of a situation where you removed the admin block. :) if ($PAGE->user_allowed_editing()) { $buttons = $OUTPUT->edit_button($PAGE->url); $PAGE->set_button($buttons); } $PAGE->set_title(get_string('course') . ': ' . $course->fullname); $PAGE->set_heading($course->fullname); echo $OUTPUT->header(); if ($completion->is_enabled() && ajaxenabled()) { // This value tracks whether there has been a dynamic change to the page. // It is used so that if a user does this - (a) set some tickmarks, (b) // go to another page, (c) clicks Back button - the page will // automatically reload. Otherwise it would start with the wrong tick // values. echo html_writer::start_tag('form', array('action' => '.', 'method' => 'get')); echo html_writer::start_tag('div'); echo html_writer::empty_tag('input', array('type' => 'hidden', 'id' => 'completion_dynamic_change', 'name' => 'completion_dynamic_change', 'value' => '0')); echo html_writer::end_tag('div'); echo html_writer::end_tag('form'); } // Course wrapper start. echo html_writer::start_tag('div', array('class' => 'course-content')); $modinfo = get_fast_modinfo($COURSE); get_all_mods($course->id, $mods, $modnames, $modnamesplural, $modnamesused);
/** * Displays the reply/edit form on a discussion page. Usually this form is * hidden by CSS and only displayed when JavaScript activates it. * @param mod_forumng $forum * @return string HTMl for form */ public function render_ajax_forms($forum) { global $CFG; if (!ajaxenabled()) { return ''; } require_once $CFG->dirroot . '/mod/forumng/editpost_form.php'; // Reply form $mform = new mod_forumng_editpost_form('editpost.php', array('params' => array(), 'isdiscussion' => false, 'ispost' => true, 'islock' => false, 'forum' => $forum, 'edit' => false, 'post' => null, 'ajaxversion' => 1, 'isroot' => false)); $result = $mform->get_html(); // Edit form $mform = new mod_forumng_editpost_form('editpost.php', array('params' => array(), 'isdiscussion' => false, 'ispost' => true, 'islock' => false, 'forum' => $forum, 'edit' => true, 'post' => null, 'ajaxversion' => 2, 'isroot' => false)); $result .= $mform->get_html(); // Edit form (discussion) $mform = new mod_forumng_editpost_form('editpost.php', array('params' => array(), 'isdiscussion' => false, 'ispost' => true, 'islock' => false, 'forum' => $forum, 'edit' => true, 'post' => null, 'ajaxversion' => 3, 'isroot' => true)); $result .= $mform->get_html(); return '<div id="forumng-formhome">' . $result . '</div>'; }
function taoview_print_artefacts($artefacts, $viewtype, $tagfilter, $userfilter, $sort, $page, $perpage) { global $CFG, $USER; //get scale $scale = get_record("scale", "name", 'TAO: Stars'); $artefacts = taoview_get_paginated_results($artefacts, $page, $perpage); foreach ($artefacts as $artefact) { if ($perpage <= 0) { //not a great way to paginate. break; } echo '<div class="taoview">'; if (!empty($artefact['thumbnail'])) { echo '<div class="taoview-thumb"><img src="' . $artefact['thumbnail'] . '"></div>'; } echo '<div class="taoview-download"><a href="' . $artefact['download'] . '" target="_blank">' . $artefact['name'] . '</a></div>'; if (!empty($artefact['uploader'])) { $user = get_record('user', 'username', $artefact['uploader']); if (!empty($user)) { echo '<div class="taoview-user">' . get_string('submittedby', 'local') . ': <a href="' . $CFG->wwwroot . '/local/mahara/taoview' . $viewtype . '.php?tag=' . $tagfilter . '&filteruser='******'uploader'] . '&sort=' . $sort . '">' . fullname($user) . '</a></div>'; } } if (!empty($artefact['ctime'])) { echo '<div class="taoview-date">' . $artefact['ctime'] . '</div>'; } if (!empty($artefact['description'])) { echo '<div class="taoview-desc">' . $artefact['description'] . '</div>'; } if (!empty($artefact['tags']) && is_array($artefact['tags'])) { echo '<div class="taoview-tags">' . get_string('tags') . ': '; foreach ($artefact['tags'] as $tag) { echo '<a href="' . $CFG->wwwroot . '/local/mahara/taoview' . $viewtype . '.php?tag=' . $tag . '&sort=' . $sort . '">' . $tag . '</a>, '; } echo '</div>'; } //now do ratings stuff echo '<div class="ratings">'; $possiblevalues = make_grades_menu(-$scale->id); echo '<span class="taoviewratingtext">'; tao_print_ratings($artefact['id'], $possiblevalues); echo '</span>'; if (!empty($user) && $user->id != $USER->id && !isguest()) { tao_print_rating_menu($artefact['id'], $USER->id, $possiblevalues); } echo '</div>'; //end of ratings stuff if (!empty($artefact['page'])) { echo '<div class="taoview-page"><a href="' . $artefact['page'] . '">' . get_string('moreinfo', 'local') . '</a></div>'; } echo '</div>'; $perpage--; } if (!empty($artefacts) && !isguest()) { echo "<div class=\"boxaligncenter\"><input id=\"taoviewratingsubmit\" type=\"submit\" value=\"" . get_string("sendinratings", "local") . "\" />"; if (ajaxenabled()) { /// AJAX enabled, standard submission form $rate_ajax_config_settings = array("pixpath" => $CFG->pixpath, "wwwroot" => $CFG->wwwroot, "sesskey" => sesskey()); echo "<script type=\"text/javascript\">//<![CDATA[\n" . "var rate_ajax_config = " . json_encode($rate_ajax_config_settings) . ";\n" . "init_rate_ajax();\n" . "//]]></script>\n"; } //print_scale_menu_helpbutton(SITEID, $scale); //no help file written yet. echo "</div>"; } }
} } } if (!$atleastonemember) { // Print an empty option to avoid the XHTML error of having an empty select element echo '<option> </option>'; } echo '</select>' . "\n"; echo '<p><input type="submit" ' . $showaddmembersform_disabled . ' name="act_showaddmembersform" ' . 'id="showaddmembersform" value="' . get_string('adduserstogroup', 'group') . '" /></p>' . "\n"; echo '</td>' . "\n"; echo '</tr>' . "\n"; echo '</table>' . "\n"; //<input type="hidden" name="rand" value="om" /> echo '</div>' . "\n"; echo '</form>' . "\n"; if (ajaxenabled()) { $PAGE->requires->js_init_call('M.core_group.init_index', array($CFG->wwwroot, $courseid)); $PAGE->requires->js_init_call('M.core_group.groupslist', array($preventgroupremoval)); } echo $OUTPUT->footer(); /** * Returns the first button action with the given prefix, taken from * POST or GET, otherwise returns false. * @see /lib/moodlelib.php function optional_param(). * @param string $prefix 'act_' as in 'action'. * @return string The action without the prefix, or false if no action found. */ function groups_param_action($prefix = 'act_') { $action = false; //($_SERVER['QUERY_STRING'] && preg_match("/$prefix(.+?)=(.+)/", $_SERVER['QUERY_STRING'], $matches)) { //b_(.*?)[&;]{0,1}/
redirect($CFG->wwwroot . '/'); } // AJAX-capable course format? $CFG->useajax = false; $ajaxformatfile = $CFG->dirroot . '/course/format/' . $course->format . '/ajax.php'; $bodytags = ''; if (file_exists($ajaxformatfile)) { // Needs to exist otherwise no AJAX by default $CFG->ajaxcapable = false; // May be overridden later by ajaxformatfile $CFG->ajaxtestedbrowsers = array(); // May be overridden later by ajaxformatfile require_once $ajaxformatfile; if (!empty($USER->editing) && $CFG->ajaxcapable) { // Course-based switches if (ajaxenabled($CFG->ajaxtestedbrowsers)) { // rowser, user and site-based switches require_js(array('yui_yahoo', 'yui_dom', 'yui_event', 'yui_dragdrop', 'yui_connection', 'ajaxcourse_blocks', 'ajaxcourse_sections')); if (debugging('', DEBUG_DEVELOPER)) { require_js(array('yui_logger')); $bodytags = 'onload = "javascript: show_logger = function() { var logreader = new YAHOO.widget.LogReader(); logreader.newestOnTop = false; logreader.setTitle(\'Moodle Debug: YUI Log Console\'); }; show_logger(); "'; } // Okay, global variable alert. VERY UGLY. We need to create // this object here before the <blockname>_print_block()
/** * Construct contents of course_overview block * * @param array $courses list of courses in sorted order * @param array $overviews list of course overviews * @return string html to be displayed in course_overview block */ public function course_overview($courses, $overviews) { $html = ''; $config = get_config('block_course_overview'); $ismovingcourse = false; $courseordernumber = 0; $maxcourses = count($courses); $userediting = false; // Intialise string/icon etc if user is editing and courses > 1 if ($this->page->user_is_editing() && count($courses) > 1) { $userediting = true; // If ajaxenabled then include DND JS and replace link with move image. if (ajaxenabled()) { $this->page->requires->js_init_call('M.block_course_overview.add_handles'); } // Check if course is moving $ismovingcourse = optional_param('movecourse', FALSE, PARAM_BOOL); $movingcourseid = optional_param('courseid', 0, PARAM_INT); } // Render first movehere icon. if ($ismovingcourse) { // Remove movecourse param from url. $this->page->ensure_param_not_in_url('movecourse'); // Show moving course notice, so user knows what is being moved. $html .= $this->output->box_start('notice'); $a = new stdClass(); $a->fullname = $courses[$movingcourseid]->fullname; $a->cancellink = html_writer::link($this->page->url, get_string('cancel')); $html .= get_string('movingcourse', 'block_course_overview', $a); $html .= $this->output->box_end(); $moveurl = new moodle_url('/blocks/course_overview/move.php', array('sesskey' => sesskey(), 'moveto' => 0, 'courseid' => $movingcourseid)); // Create move icon, so it can be used. $movetofirsticon = html_writer::empty_tag('img', array('src' => $this->output->pix_url('movehere'), 'alt' => get_string('movetofirst', 'block_course_overview', $courses[$movingcourseid]->fullname), 'title' => get_string('movehere'))); $moveurl = html_writer::link($moveurl, $movetofirsticon); $html .= html_writer::tag('div', $moveurl, array('class' => 'movehere')); } foreach ($courses as $key => $course) { // If moving course, then don't show course which needs to be moved. if ($ismovingcourse && $course->id == $movingcourseid) { continue; } $html .= $this->output->box_start('coursebox', "course-{$course->id}"); $html .= html_writer::start_tag('div', array('class' => 'course_title')); // If user is editing, then add move icons. if ($userediting && !$ismovingcourse) { $moveicon = html_writer::empty_tag('img', array('src' => $this->pix_url('t/move')->out(false), 'alt' => get_string('movecourse', 'block_course_overview', $course->fullname), 'title' => get_string('move'))); $moveurl = new moodle_url($this->page->url, array('sesskey' => sesskey(), 'movecourse' => 1, 'courseid' => $course->id)); $moveurl = html_writer::link($moveurl, $moveicon); $html .= html_writer::tag('div', $moveurl, array('class' => 'move')); } // No need to pass title through s() here as it will be done automatically by html_writer. $attributes = array('title' => $course->fullname); if ($course->id > 0) { if (empty($course->visible)) { $attributes['class'] = 'dimmed'; } $courseurl = new moodle_url('/course/view.php', array('id' => $course->id)); $coursefullname = format_string($course->fullname, true, $course->id); $link = html_writer::link($courseurl, $coursefullname, $attributes); $html .= $this->output->heading($link, 2, 'title'); } else { $html .= $this->output->heading(html_writer::link(new moodle_url('/auth/mnet/jump.php', array('hostid' => $course->hostid, 'wantsurl' => '/course/view.php?id=' . $course->remoteid)), format_string($course->shortname, true), $attributes) . ' (' . format_string($course->hostname) . ')', 2, 'title'); } $html .= $this->output->box('', 'flush'); $html .= html_writer::end_tag('div'); if (!empty($config->showchildren) && $course->id > 0) { // List children here. if ($children = block_course_overview_get_child_shortnames($course->id)) { $html .= html_writer::tag('span', $children, array('class' => 'coursechildren')); } } // If user is moving courses, then down't show overview. if (isset($overviews[$course->id]) && !$ismovingcourse) { $html .= $this->activity_display($course->id, $overviews[$course->id]); } $html .= $this->output->box('', 'flush'); $html .= $this->output->box_end(); $courseordernumber++; if ($ismovingcourse) { $moveurl = new moodle_url('/blocks/course_overview/move.php', array('sesskey' => sesskey(), 'moveto' => $courseordernumber, 'courseid' => $movingcourseid)); $a = new stdClass(); $a->movingcoursename = $courses[$movingcourseid]->fullname; $a->currentcoursename = $course->fullname; $movehereicon = html_writer::empty_tag('img', array('src' => $this->output->pix_url('movehere'), 'alt' => get_string('moveafterhere', 'block_course_overview', $a), 'title' => get_string('movehere'))); $moveurl = html_writer::link($moveurl, $movehereicon); $html .= html_writer::tag('div', $moveurl, array('class' => 'movehere')); } } // Wrap course list in a div and return. return html_writer::tag('div', $html, array('class' => 'course_list')); }
public function course_overview($courses, $overviews, $moving = 0) { global $OUTPUT; $html = ''; $config = get_config('block_my_course_overview'); $html .= html_writer::start_tag('div', array('id' => 'course_list')); $weight = 0; $keylist = array_keys($courses); if ($this->page->user_is_editing() && $moving && $keylist[0] != $moving) { $html .= $this->course_move_target($moving, $weight); $weight++; } foreach ($courses as $course) { $cursor = ajaxenabled() && !$moving ? ' cursor' : ''; $html .= $OUTPUT->box_start('coursebox', "course-{$course->id}"); $html .= html_writer::start_tag('div', array('class' => 'course_title')); if ($this->page->user_is_editing()) { // Move icon. $icon = ajaxenabled() ? 'i/move_2d' : 't/move'; $control = array('url' => new moodle_url('/my/index.php', array('course_moveid' => $course->id)), 'icon' => $icon, 'caption' => get_string('move')); if (ajaxenabled()) { $html .= html_writer::tag('div', html_writer::empty_tag('img', array('src' => $this->pix_url($control['icon'])->out(false), 'alt' => $control['caption'], 'class' => 'icon cursor', 'title' => $control['caption'])), array('class' => 'move')); } else { $html .= html_writer::tag('a', html_writer::empty_tag('img', array('src' => $this->pix_url($control['icon'])->out(false), 'alt' => $control['caption'])), array('class' => 'icon move', 'title' => $control['caption'], 'href' => $control['url'])); } } $link = html_writer::link(new moodle_url('/course/view.php', array('id' => $course->id)), $course->fullname); $html .= $OUTPUT->heading($link, 2, 'title'); $html .= $OUTPUT->box('', 'flush'); $html .= html_writer::end_tag('div'); if (isset($config->showchildren) && $config->showchildren) { //list children here if ($children = block_my_course_overview_get_child_shortnames($course->id)) { $html .= html_writer::tag('span', $children, array('class' => 'coursechildren')); } } if (isset($overviews[$course->id])) { $html .= $this->activity_display($course->id, $overviews[$course->id]); } $html .= $OUTPUT->box('', 'flush'); $html .= $OUTPUT->box_end(); if ($this->page->user_is_editing() && $moving && $course->id != $moving) { //check if next is the course we're moving $okay = true; if (isset($keylist[$weight])) { if ($courses[$keylist[$weight]]->id == $moving) { $okay = false; } } if ($okay) { $html .= $this->course_move_target($moving, $weight); } } $weight++; } $html .= html_writer::end_tag('div'); return $html; }