This repository has been archived by the owner on Apr 4, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
ajax_gettopic.php
155 lines (127 loc) · 7.08 KB
/
ajax_gettopic.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<?php
/**
* Ajax Get Topic
*
* Renders an individual topic also known as section
* @author Jeremy FitzPatrick
* @copyright (C) 2011 Jeremy FitzPatrick
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @package slides
* @category course
*/
// need to get moodle root as this can be included or standalone
$root_path = str_replace("course/format/slides", "", dirname(__FILE__));
require_once($root_path . "config.php");
require_once($root_path . 'course/lib.php');
require_once('lib.php');
$id = required_param('id', PARAM_INT);
$topic = optional_param('topic', 0, PARAM_INT);
$mode = optional_param('mode', 0, PARAM_INT);
$PAGE->set_context(context_course::instance($id));
$isediting = $PAGE->user_is_editing() || $mode;
$section = isset($section) ? $section : $topic;
$streditsummary = get_string('editsummary');
$streditsettings = get_string('editsettings', 'format_slides');
if ($isediting) {
$strtopichide = get_string('hidetopicfromothers');
$strtopicshow = get_string('showtopicfromothers');
$strmarkthistopic = get_string('markthistopic');
$strmarkedthistopic = get_string('markedthistopic');
$strmoveup = get_string('moveup');
$strmovedown = get_string('movedown');
}
if(!isset($course)) {
if (! ($course = $DB->get_record('course', array('id'=>$id)))) {
print_error('invalidcourseid', 'error');
}
}
if(!isset($context)) $context = get_context_instance(CONTEXT_COURSE, $course->id);
// require_capability('moodle/course:view', $context);
require_login() ;
if(!isset($sections)) {
$thissection = $DB->get_record('course_sections', array('course'=>$course->id, 'section'=>$topic));
} else {
$thissection = $sections[$section];
}
$numcolumns = $DB->get_record('format_slides', array('course_id'=>$course->id, 'topic_id'=>$thissection->id), 'layout_columns');
get_all_mods($course->id, $mods, $modnames, $modnamesplural, $modnamesused);
$sectionstyle = !$thissection->visible ? ' hidden' : ($course->marker == $section ? ' current' : '');
$sectionstyle .= " cols-" . $numcolumns->layout_columns;
$showsection = (has_capability('moodle/course:viewhiddensections', $context) or $thissection->visible or !$course->hiddensections);
if (!$showsection) return;
echo '<li id="section-'.$section.'" class="section main clearfix ui-widget-content ui-corner-all'.$sectionstyle.'" >';
/*
* EDITING ICONS
*/
echo '<div class="left side"> </div>' . "\n";
echo '<div class="right side controls">';
// echo '<a />';
if ($isediting && has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $course->id)) && $section > 0) {
$icon = $course->marker == $section ? $OUTPUT->pix_url('i/marked') : $OUTPUT->pix_url('i/marker');
$title = $course->marker == $section ? get_string('markedthistopic') : get_string('markthistopic');
$href = $course->marker == $section ? "marker=0" : "marker=" . $section;
echo '<a href="view.php?id='.$course->id.'&'.$href . '&sesskey='.sesskey().'" class="highlight" title="'.$title.'">'.
'<img src="'.$icon. '" alt="'.$title.'" /></a> ';
$icon = $thissection->visible ? $OUTPUT->pix_url('i/hide') : $OUTPUT->pix_url('i/show');
$title = $thissection->visible ? get_string('hidetopicfromothers') : get_string('showtopicfromothers');
$href = $thissection->visible ? "hide=".$section : 'show='.$section;
echo '<a href="view.php?id='.$course->id.'&'.$href.'&sesskey='.sesskey().'#section-'.$section.'" title="'.$title.'">'.
'<img src="'.$icon. '" class="icon" alt="'.$title.'" /></a> ';
if ($section > 1) { // Add a arrow to move section up
echo '<a href="view.php?id='.$course->id.'&random='.rand(1,10000).'&section='.$section.'&move=-1&sesskey='.sesskey().'#section-'.($section-1).'" title="'.$strmoveup.'" class="move up">'.
'<img src="'.$OUTPUT->pix_url('t/up') . '" class="icon up" alt="'.$strmoveup.'" /></a> ';
}
if ($section < $course->numsections) { // Add a arrow to move section down
echo '<a href="view.php?id='.$course->id.'&random='.rand(1,10000).'&section='.$section.'&move=1&sesskey='.sesskey().'#section-'.($section+1).'" title="'.$strmovedown.'" class="move down">'.
'<img src="'.$OUTPUT->pix_url('t/down') . '" class="icon down" alt="'.$strmovedown.'" /></a> ';
}
}
echo '</div>' . "\n";
// Match topics format behaviour where help is hidden if there is no completion activities
// But do this per section.
$completioninfo = new completion_info($course);
$activitieswithcompletion = $completioninfo->get_activities();
$hasCompletionActivites = false;
foreach($activitieswithcompletion as $activity){
if($activity->section == $thissection->id){
$hasCompletionActivites = true;
}
}
if ($hasCompletionActivites)
$completioninfo->print_help_icon();
/*
* CONTENT
*/
echo '<div class="content">';
if (!has_capability('moodle/course:viewhiddensections', $context) and !$thissection->visible) { // Hidden for students
echo get_string('notavailable');
} else {
if (!is_null($thissection->name)) {
echo $OUTPUT->heading($thissection->name, 3, 'sectionname');
}
echo "<div class='summary'>" . "\n";
if ($isediting && has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $course->id))) {
echo ' <a title="'.$streditsummary.'" href="editsection.php?id='.$thissection->id.'">'.
'<img src="'.$OUTPUT->pix_url('t/edit') . '" class="icon edit" alt="'.$streditsummary.'" /></a>';
echo ' <a title="'.$streditsettings.'" href="format/slides/choose_background.php?topic='.$thissection->id.'">'.
'<img src="format/slides/pix/i/icon.png" class="icon edit" alt="'.$streditsettings.'" /></a>';
}
if ($thissection->summary) {
$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
$summarytext = file_rewrite_pluginfile_urls($thissection->summary, 'pluginfile.php', $coursecontext->id, 'course', 'section', $thissection->id);
$summaryformatoptions = new stdClass();
$summaryformatoptions->noclean = true;
$summaryformatoptions->overflowdiv = true;
echo format_text($summarytext, $thissection->summaryformat, $summaryformatoptions);
} else {
echo ' ';
}
echo "</div>" . "\n";
ss_print_section($course, $thissection, $mods, $modnamesused);
echo '<br />';
if ($isediting) {
print_section_add_menus($course, $section, $modnames);
}
}
echo '</div>';
echo "</li>\n";