forked from mgage/wwassignment
-
Notifications
You must be signed in to change notification settings - Fork 7
/
view.php
120 lines (91 loc) · 4.11 KB
/
view.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
<?php
/**
* @desc Prints an actual wwassignment with an iframe to WeBWorK.
*/
// global database object
global $DB,$OUTPUT,$PAGE;
require_once("../../config.php");
require_once("locallib.php");
$id = optional_param('id', 0, PARAM_INT); // Course Module ID, or
$a = optional_param('a', 0, PARAM_INT); // NEWMODULE ID
$cm = get_coursemodule_from_id('wwassignment', $id, 0, false, MUST_EXIST);
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
if($id) {
if (! $cm = $DB->get_record("course_modules", array( "id"=>$id ))) {
print_error("Course Module ID was incorrect");
}
if (! $course = $DB->get_record("course", array( "id"=>$cm->course ))) {
print_error("Course is misconfigured");
}
if (! $wwassignment = $DB->get_record("wwassignment", array( "id"=>$cm->instance ))) {
print_error("Course module is incorrect");
}
} else {
if (! $wwassignment = $DB->get_record("wwassignment", array( "id"=>$a ))) {
print_error("Course module is incorrect");
}
if (! $course = $DB->get_record("course", array("id"=>$wwassignment->course ))) {
print_error("Course is misconfigured");
}
if (! $cm = get_coursemodule_from_instance("wwassignment", $wwassignment->id, $course->id)) {
print_error("Course Module ID was incorrect");
}
}
//catch the guests
global $USER, $OUTPUT;
if($USER->username == 'guest') { # this allows guests to view webwork (signed in as user guest)
#FIXME -- replace this with a method that uses the automatic guest sign in on webwork.
// print_error('Guests cannot view WeBWorK Problem Sets');
}
//force login
$courseid = $course->id;
$wwassignmentid = $wwassignment->id;
require_login($courseid );
// set page values
$strwwassignments = get_string("modulenameplural", "wwassignment");
$strwwassignment = get_string("modulename", "wwassignment");
$PAGE->set_url('/mod/wwassignment/view.php',array('id'=>$cm->id));
$PAGE->set_pagelayout('login');
$PAGE->set_heading("$course->fullname");
$PAGE->set_title("$course->shortname: $wwassignment->name");
$PAGE->set_cacheable(true);
$PAGE->set_focuscontrol("");
//$PAGE->set_button(update_module_button($cm->id, $course->id, $strwwassignment));
$PAGE->set_button($OUTPUT->update_module_button($cm->id, 'wwassignment'));
//$PAGE->navbar->add($strwwassignments,"index.php?id=$course->id");
//$PAGE->navbar->add($wwassignment->name);
$context = context_module::instance( $cm->id); // should this be module context or course context?
$PAGE->set_context($context);
$PAGE->set_cm($cm);
//webwork code
$wwcoursename = _wwassignment_mapped_course($courseid,false);
$wwusername = $USER->username;
$wwsetname = $wwassignment->webwork_set;
_wwassignment_mapcreate_user($wwcoursename,$wwusername);
_wwassignment_mapcreate_user_set($wwcoursename,$wwusername,$wwsetname);
$wwkey = _wwassignment_login_user($wwcoursename,$wwusername);
$wwsetlink = _wwassignment_link_to_set_auto_login($wwcoursename,$wwsetname,$wwusername,$wwkey);
//add_to_log($course->id, "wwassignment", "view", "view.php?id=$cm->id", "$wwassignmentid",_wwassignment_cmid());
$event = \mod_wwassignment\event\course_module_viewed::create(array(
'objectid' => $PAGE->cm->instance,
'context' => $PAGE->context,
));
$event->add_record_snapshot('course', $PAGE->course);
//$event->add_record_snapshot($PAGE->cm->modname, $activityrecord);
$event->trigger();
/// Print the page header
echo $OUTPUT->header();
/// Print the main part of the page
// Print webwork in iframe and link to escape to have webwork in a single window
print("<p style='font-size: smaller; color: #aaa;'>" . get_string("iframeNoShow-1", "wwassignment")
. "<a href='$wwsetlink'>" . get_string("iframeNoShow-2", "wwassignment")
."</a><p align='center'></iframe></p>\n"
);
print("<iframe id='wwPage' src='$wwsetlink' frameborder='0' "
. "width='".$CFG->wwassignment_iframewidth."' "
. "height='".$CFG->wwassignment_iframeheight."'>"
);
print("<script>ww.Init(".has_capability('moodle/course:manageactivities',context_course::instance($course->id) ).")</script></iframe>");
/// Finish the page
echo $OUTPUT->footer();
?>