/
view.php
130 lines (112 loc) · 4.19 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
121
122
123
124
125
126
127
128
129
130
<?php
/**
* This page prints a particular instance of praxe
*
* @author Your Name <your@email.address>
* @version
* @package mod/praxe
*/
require_once(dirname(dirname(dirname(__FILE__))).'/config.php');
require_once(dirname(__FILE__).'/locallib.php');
$id = optional_param('id', 0, PARAM_INT); // course_module ID, or
$a = optional_param('a', 0, PARAM_INT); // praxe instance ID
$mode = optional_param('mode', '', PARAM_ALPHA); // value depends on $tabview(resp. user role)
if ($id) {
if (! $cm = get_coursemodule_from_id('praxe', $id)) {
print_error('Course Module ID was incorrect');
}
if (! $course = $DB->get_record('course', array('id' => $cm->course))) {
print_error('Course is misconfigured');
}
if (! $praxe = $DB->get_record('praxe', array('id' => $cm->instance))) {
print_error('Course module is incorrect');
}
} else if ($a) {
if (! $praxe = $DB->get_record('praxe', array('id' => $a))) {
print_error('Course module is incorrect');
}
if (! $course = $DB->get_record('course', array('id' => $praxe->course))) {
print_error('Course is misconfigured');
}
if (! $cm = get_coursemodule_from_instance('praxe', $praxe->id, $course->id)) {
print_error('Course Module ID was incorrect');
}
} else {
echo('you must specify ID of course');
}
require_login($course, true, $cm);
/// Print the page header
$strpraxes = get_string('modulenameplural', 'praxe');
$strpraxe = get_string('modulename', 'praxe');
$PAGE->set_url('/mod/praxe/view.php', array('id'=>$cm->id));
$PAGE->set_title(format_string($praxe->name));
$PAGE->set_heading(format_string($course->fullname));
$context = context_module::instance($cm->id);
/// user record of praxe - for users as student in praxe_records. set info of praxe in this course ///
$oPraxeRecord = new praxe_record($USER->id);
$praxeaction = optional_param('praxeaction', null, PARAM_ALPHAEXT);
/// extra praxe action ///
if(!is_null($praxeaction)) {
require_once($CFG->dirroot . '/mod/praxe/praxeaction.php');
}
/// rights to all actions in this module ///
if(has_capability('mod/praxe:manageallincourse',$context) || has_capability('mod/praxe:assignselftoinspection',$context)) {
$viewrole = 'EDITTEACHER';
$role_title = get_string('teacher','praxe');
/// rights to create or manage own record of praxe - for students ///
}else if(has_capability('mod/praxe:editownrecord',$context)) {
$viewrole = 'STUDENT';
$role_title = get_string('student','praxe');
}else {
foreach(get_roles_used_in_context($context) as $role) {
if(user_has_role_assignment($USER->id, $role->id, $context->id)) {
if($role->shortname == 'extheadmaster') {
$viewrole = 'HEADM';
$role_title = get_string('headmaster','praxe');
}else if($role->shortname == 'extteacher') {
$viewrole = 'EXTTEACHER';
$role_title = get_string('extteacher','praxe');
}
break;
}
}
}
$post_form = optional_param('post_form', null, PARAM_ALPHAEXT);
/// post data sent ///
if(!is_null($post_form)) {
require_once($CFG->dirroot . '/mod/praxe/post.php');
}
/** $sentForm can be set in post.php if the form was sent with errors - in view_... there is no more created instance of custom mform.
* It has to be set as global var in c_classes.
* @see c_makeschedule for example
*/
if(!isset($sentForm)) {
$sentForm = null;
}
echo $OUTPUT->header();
/// Print the main part of the page
echo "<script type=\"text/javascript\" src=\"praxe.js\"></script>";
if(isset($viewrole) && is_null($praxeaction)) {
/// set type of tabs to view ///
$tabview = constant('PRAXE_TAB_VIEW_'.$viewrole);
if(false === ($tab = array_search($mode,$tab_modes[strtolower($viewrole)]))) {
if(count($tab_modes[strtolower($viewrole)])) {
$tab = 0;
$mode = $tab_modes[strtolower($viewrole)][0]; /// string value for/from url
}
}
if($tab !== false) {
require_once('tabs.php');
}
require_once($CFG->dirroot . '/mod/praxe/view_'.strtolower($viewrole).'.php');
$class = 'praxe_view_'.strtolower($viewrole);
$praxe_view_role = new $class;
/// display inner content of tab///
$praxe_view_role->display_content();
if($tab !== false) {
praxe_print_tab_footer();
}
}
/// Finish the page
echo $OUTPUT->footer($course);
?>