removed accidentally added backup file
[moodle.git] / grade / lib.php
CommitLineData
3af29899 1<?php //$Id$
cbff94ba 2
3af29899 3function print_grade_plugin_selector($courseid, $active_type, $active_plugin, $return=false) {
cbff94ba 4 global $CFG;
cbff94ba 5
3af29899 6 $context = get_context_instance(CONTEXT_COURSE, $courseid);
cbff94ba 7
3af29899 8 $menu = array();
cbff94ba 9
3af29899 10 $active = '';
cbff94ba 11
3af29899 12/// report plugins with its special structure
13 if ($reports = get_list_of_plugins('grade/report', 'CVS')) { // Get all installed reports
14 foreach ($reports as $key => $plugin) { // Remove ones we can't see
15 if (!has_capability('gradereport/'.$plugin.':view', $context)) {
16 unset($reports[$key]);
cbff94ba 17 }
18 }
04678d8e 19 }
3af29899 20 $reportnames = array();
21 if (!empty($reports)) {
22 foreach ($reports as $plugin) {
23 $url = 'report.php?id='.$courseid.'&amp;report='.$plugin;
24 if ($active_type == 'report' and $active_plugin == $plugin ) {
25 $active = $url;
cbff94ba 26 }
3af29899 27 $reportnames[$url] = get_string('modulename', 'gradereport_'.$plugin);
cbff94ba 28 }
3af29899 29 asort($reportnames);
cbff94ba 30 }
3af29899 31 if (!empty($reportnames)) {
32 $menu['reportgroup']='--'.get_string('reportplugins', 'grades');
33 $menu = $menu+$reportnames;
cbff94ba 34 }
cbff94ba 35
3af29899 36/// standard import plugins
37 if ($imports = get_list_of_plugins('grade/import', 'CVS')) { // Get all installed reports
38 foreach ($imports as $key => $plugin) { // Remove ones we can't see
39 if (!has_capability('gradeimport/'.$plugin.':view', $context)) {
40 unset($imports[$key]);
cbff94ba 41 }
42 }
43 }
3af29899 44 $importnames = array();
45 if (!empty($imports)) {
46 foreach ($imports as $plugin) {
47 $url = 'import/'.$plugin.'/index.php?id='.$courseid;
48 if ($active_type == 'impot' and $active_plugin == $plugin ) {
49 $active = $url;
50 }
51 $importnames[$url] = get_string('modulename', 'gradeimport_'.$plugin);
281ffa4a 52 }
3af29899 53 asort($importnames);
281ffa4a 54 }
3af29899 55 if (!empty($importnames)) {
56 $menu['importgroup']='--'.get_string('importplugins', 'grades');
57 $menu = $menu+$importnames;
281ffa4a 58 }
281ffa4a 59
3af29899 60/// standard export plugins
61 if ($exports = get_list_of_plugins('grade/export', 'CVS')) { // Get all installed reports
62 foreach ($exports as $key => $plugin) { // Remove ones we can't see
63 if (!has_capability('gradeexport/'.$plugin.':view', $context)) {
64 unset($exports[$key]);
281ffa4a 65 }
66 }
cbff94ba 67 }
3af29899 68 $exportnames = array();
69 if (!empty($exports)) {
70 foreach ($exports as $plugin) {
71 $url = 'export/'.$plugin.'/index.php?id='.$courseid;
72 if ($active_type == 'impot' and $active_plugin == $plugin ) {
73 $active = $url;
74 }
75 $exportnames[$url] = get_string('modulename', 'gradeexport_'.$plugin);
281ffa4a 76 }
3af29899 77 asort($exportnames);
cbff94ba 78 }
3af29899 79 if (!empty($exportnames)) {
80 $menu['exportgroup']='--'.get_string('exportplugins', 'grades');
81 $menu = $menu+$exportnames;
281ffa4a 82 }
cbff94ba 83
3af29899 84/// editing scripts - not real plugins
85 if (true) { //TODO: add proper capability here
86 $menu['edit']='--'.get_string('edit');
87 $url = 'edit/tree.php?id='.$courseid;
88 if ($active_type == 'edit' and $active_plugin == 'tree' ) {
89 $active = $url;
cbff94ba 90 }
3af29899 91 $menu[$url] = get_string('edittree', 'grades');
281ffa4a 92 }
93
3af29899 94/// finally print/return the popup form
95 return popup_form($CFG->wwwroot.'/grade/', $menu, 'choosepluginreport', $active, 'choose', '', '', $return, 'self', get_string('selectplugin', 'grades'));
cbff94ba 96}
97
3af29899 98class grade_plugin_return {
99 var $type;
100 var $plugin;
101 var $courseid;
102 var $userid;
103 var $page;
281ffa4a 104
3af29899 105 function grade_plugin_return ($params=null) {
106 if (empty($params)) {
107 $this->type = optional_param('gpr_type', null, PARAM_SAFEDIR);
108 $this->plugin = optional_param('gpr_plugin', null, PARAM_SAFEDIR);
109 $this->courseid = optional_param('gpr_courseid', null, PARAM_INT);
110 $this->userid = optional_param('gpr_userid', null, PARAM_INT);
111 $this->page = optional_param('gpr_page', null, PARAM_INT);
a983b6ec 112
a983b6ec 113 } else {
3af29899 114 foreach ($params as $key=>$value) {
115 if (array_key_exists($key, $this)) {
116 $this->$key = $value;
117 }
cbff94ba 118 }
119 }
6cd8c592 120 }
121
3af29899 122 function get_options() {
123 if (empty($this->type) or empty($this->plugin)) {
124 return array();
865e9a82 125 }
6cd8c592 126
3af29899 127 $params = array();
6cd8c592 128
3af29899 129 $params['plugin'] = $this->plugin;
6cd8c592 130
3af29899 131 if (!empty($this->courseid)) {
132 $params['id'] = $this->courseid;
6cd8c592 133 }
9c61ba4d 134
3af29899 135 if (!empty($this->userid)) {
136 $params['userid'] = $this->userid;
9c61ba4d 137 }
9c61ba4d 138
3af29899 139 if (!empty($this->page)) {
140 $params['page'] = $this->page;
cbff94ba 141 }
865e9a82 142
3af29899 143 return $params;
cbff94ba 144 }
cbff94ba 145
3af29899 146 function get_return_url($default) {
147 global $CFG;
cbff94ba 148
3af29899 149 if (empty($this->type) or empty($this->plugin)) {
150 return $default;
cbff94ba 151 }
152
3af29899 153 if ($this->type == 'report') {
154 $url = $CFG->wwwroot.'/grade/report.php?report='.$this->plugin;
155 $glue = '&amp;';
cbff94ba 156
3af29899 157 } else {
158 $url = $CFG->wwwroot.'/grade/'.$this->type.'/'.$this->plugin.'/index.php';
159 $glue = '?';
cbff94ba 160 }
cbff94ba 161
3af29899 162 if (!empty($this->courseid)) {
163 $url .= $glue.'id='.$this->courseid;
164 $glue = '&amp;';
cbff94ba 165 }
cbff94ba 166
3af29899 167 if (!empty($this->userid)) {
168 $url .= $glue.'userid='.$this->userid;
169 $glue = '&amp;';
cbff94ba 170 }
7e2d7c92 171
3af29899 172 if (!empty($this->page)) {
173 $url .= $glue.'page='.$this->page;
cbff94ba 174 }
cbff94ba 175
3af29899 176 return $url;
cbff94ba 177 }
cbff94ba 178
3af29899 179 function get_form_fields() {
180 if (empty($this->type) or empty($this->plugin)) {
181 return '';
cbff94ba 182 }
cbff94ba 183
3af29899 184 $result = '<input type="hidden" name="gpr_type" value="'.$this->type.'" />';
185 $result .= '<input type="hidden" name="gpr_plugin" value="'.$this->plugin.'" />';
0ca5abd6 186
3af29899 187 if (!empty($this->courseid)) {
188 $result .= '<input type="hidden" name="gpr_courseid" value="'.$this->courseid.'" />';
cbff94ba 189 }
cbff94ba 190
3af29899 191 if (!empty($this->userid)) {
192 $result .= '<input type="hidden" name="gpr_userid" value="'.$this->userid.'" />';
cbff94ba 193 }
cbff94ba 194
3af29899 195 if (!empty($this->page)) {
196 $result .= '<input type="hidden" name="gpr_page" value="'.$this->page.'" />';
cbff94ba 197 }
198 }
cbff94ba 199
3af29899 200 function add_mform_elements(&$mform) {
201 if (empty($this->type) or empty($this->plugin)) {
202 return;
cbff94ba 203 }
cbff94ba 204
3af29899 205 $mform->addElement('hidden', 'gpr_type', $this->type);
206 $mform->setType('gpr_type', PARAM_SAFEDIR);
cbff94ba 207
3af29899 208 $mform->addElement('hidden', 'gpr_plugin', $this->plugin);
209 $mform->setType('gpr_plugin', PARAM_SAFEDIR);
97033c86 210
3af29899 211 if (!empty($this->courseid)) {
212 $mform->addElement('hidden', 'gpr_courseid', $this->courseid);
213 $mform->setType('gpr_courseid', PARAM_INT);
cbff94ba 214 }
cbff94ba 215
3af29899 216 if (!empty($this->userid)) {
217 $mform->addElement('hidden', 'gpr_userid', $this->userid);
218 $mform->setType('gpr_userid', PARAM_INT);
cbff94ba 219 }
cbff94ba 220
3af29899 221 if (!empty($this->page)) {
222 $mform->addElement('hidden', 'gpr_page', $this->page);
223 $mform->setType('gpr_page', PARAM_INT);
cbff94ba 224 }
225 }
281ffa4a 226
3af29899 227 function add_url_params($url) {
228 if (empty($this->type) or empty($this->plugin)) {
229 return $url;
cbff94ba 230 }
5609f9e6 231
3af29899 232 if (strpos($url, '?') === false) {
233 $url .= '?gpr_type='.$this->type;
234 } else {
235 $url .= '&amp;gpr_type='.$this->type;
cbff94ba 236 }
cbff94ba 237
3af29899 238 $url .= '&amp;gpr_plugin='.$this->plugin;
cbff94ba 239
3af29899 240 if (!empty($this->courseid)) {
241 $url .= '&amp;gpr_courseid='.$this->courseid;
cbff94ba 242 }
cbff94ba 243
3af29899 244 if (!empty($this->userid)) {
245 $url .= '&amp;gpr_userid='.$this->userid;
cbff94ba 246 }
0a8a95c9 247
3af29899 248 if (!empty($this->page)) {
249 $url .= '&amp;gpr_page='.$this->page;
0a8a95c9 250 }
5a412dbf 251
3af29899 252 return $url;
5a412dbf 253 }
5a412dbf 254}
3af29899 255?>