2007-07-16 18:58:09 +00:00
|
|
|
<?php //$Id$
|
2005-03-17 16:23:28 +00:00
|
|
|
|
2007-07-17 05:52:42 +00:00
|
|
|
/**
|
|
|
|
* Print grading plugin selection popup form.
|
|
|
|
*
|
|
|
|
* @param int $courseid id of course
|
|
|
|
* @param string $active_type type of plugin on current page - import, export, report or edit
|
|
|
|
* @param string $active_plugin active plugin type - grader, user, cvs, ...
|
|
|
|
* @param boolean $return return as string
|
|
|
|
* @return nothing or string if $return true
|
|
|
|
*/
|
2007-07-16 18:58:09 +00:00
|
|
|
function print_grade_plugin_selector($courseid, $active_type, $active_plugin, $return=false) {
|
2005-03-17 16:23:28 +00:00
|
|
|
global $CFG;
|
|
|
|
|
2007-07-16 18:58:09 +00:00
|
|
|
$context = get_context_instance(CONTEXT_COURSE, $courseid);
|
2005-03-17 16:23:28 +00:00
|
|
|
|
2007-07-16 18:58:09 +00:00
|
|
|
$menu = array();
|
2005-03-17 16:23:28 +00:00
|
|
|
|
2007-07-16 18:58:09 +00:00
|
|
|
$active = '';
|
2005-03-17 16:23:28 +00:00
|
|
|
|
2007-07-16 18:58:09 +00:00
|
|
|
/// report plugins with its special structure
|
|
|
|
if ($reports = get_list_of_plugins('grade/report', 'CVS')) { // Get all installed reports
|
|
|
|
foreach ($reports as $key => $plugin) { // Remove ones we can't see
|
|
|
|
if (!has_capability('gradereport/'.$plugin.':view', $context)) {
|
|
|
|
unset($reports[$key]);
|
2005-03-17 16:23:28 +00:00
|
|
|
}
|
|
|
|
}
|
2006-05-16 06:21:49 +00:00
|
|
|
}
|
2007-07-16 18:58:09 +00:00
|
|
|
$reportnames = array();
|
|
|
|
if (!empty($reports)) {
|
|
|
|
foreach ($reports as $plugin) {
|
|
|
|
$url = 'report.php?id='.$courseid.'&report='.$plugin;
|
|
|
|
if ($active_type == 'report' and $active_plugin == $plugin ) {
|
|
|
|
$active = $url;
|
2005-03-17 16:23:28 +00:00
|
|
|
}
|
2007-07-23 08:13:59 +00:00
|
|
|
$reportnames[$url] = get_string('modulename', 'gradereport_'.$plugin, NULL, $CFG->dirroot.'/grade/report/'.$plugin.'lang/');
|
2005-03-17 16:23:28 +00:00
|
|
|
}
|
2007-07-16 18:58:09 +00:00
|
|
|
asort($reportnames);
|
2005-03-17 16:23:28 +00:00
|
|
|
}
|
2007-07-16 18:58:09 +00:00
|
|
|
if (!empty($reportnames)) {
|
|
|
|
$menu['reportgroup']='--'.get_string('reportplugins', 'grades');
|
|
|
|
$menu = $menu+$reportnames;
|
2005-03-17 16:23:28 +00:00
|
|
|
}
|
|
|
|
|
2007-07-16 18:58:09 +00:00
|
|
|
/// standard import plugins
|
2007-07-23 08:13:59 +00:00
|
|
|
if ($imports = get_list_of_plugins('grade/import', 'CVS')) { // Get all installed import plugins
|
2007-07-16 18:58:09 +00:00
|
|
|
foreach ($imports as $key => $plugin) { // Remove ones we can't see
|
|
|
|
if (!has_capability('gradeimport/'.$plugin.':view', $context)) {
|
|
|
|
unset($imports[$key]);
|
2005-03-17 16:23:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-07-16 18:58:09 +00:00
|
|
|
$importnames = array();
|
|
|
|
if (!empty($imports)) {
|
|
|
|
foreach ($imports as $plugin) {
|
|
|
|
$url = 'import/'.$plugin.'/index.php?id='.$courseid;
|
|
|
|
if ($active_type == 'impot' and $active_plugin == $plugin ) {
|
|
|
|
$active = $url;
|
|
|
|
}
|
2007-07-23 08:13:59 +00:00
|
|
|
$importnames[$url] = get_string('modulename', 'gradeimport_'.$plugin, NULL, $CFG->dirroot.'/grade/import/'.$plugin.'lang/');
|
2005-03-28 18:05:45 +00:00
|
|
|
}
|
2007-07-16 18:58:09 +00:00
|
|
|
asort($importnames);
|
2005-03-28 18:05:45 +00:00
|
|
|
}
|
2007-07-16 18:58:09 +00:00
|
|
|
if (!empty($importnames)) {
|
|
|
|
$menu['importgroup']='--'.get_string('importplugins', 'grades');
|
|
|
|
$menu = $menu+$importnames;
|
2005-03-28 18:05:45 +00:00
|
|
|
}
|
|
|
|
|
2007-07-16 18:58:09 +00:00
|
|
|
/// standard export plugins
|
2007-07-23 08:13:59 +00:00
|
|
|
if ($exports = get_list_of_plugins('grade/export', 'CVS')) { // Get all installed export plugins
|
2007-07-16 18:58:09 +00:00
|
|
|
foreach ($exports as $key => $plugin) { // Remove ones we can't see
|
|
|
|
if (!has_capability('gradeexport/'.$plugin.':view', $context)) {
|
|
|
|
unset($exports[$key]);
|
2005-03-28 18:05:45 +00:00
|
|
|
}
|
|
|
|
}
|
2005-03-17 16:23:28 +00:00
|
|
|
}
|
2007-07-16 18:58:09 +00:00
|
|
|
$exportnames = array();
|
|
|
|
if (!empty($exports)) {
|
|
|
|
foreach ($exports as $plugin) {
|
|
|
|
$url = 'export/'.$plugin.'/index.php?id='.$courseid;
|
|
|
|
if ($active_type == 'impot' and $active_plugin == $plugin ) {
|
|
|
|
$active = $url;
|
|
|
|
}
|
2007-07-23 08:13:59 +00:00
|
|
|
$exportnames[$url] = get_string('modulename', 'gradeexport_'.$plugin, NULL, $CFG->dirroot.'/grade/export/'.$plugin.'lang/');
|
2005-03-28 18:05:45 +00:00
|
|
|
}
|
2007-07-16 18:58:09 +00:00
|
|
|
asort($exportnames);
|
2005-03-17 16:23:28 +00:00
|
|
|
}
|
2007-07-16 18:58:09 +00:00
|
|
|
if (!empty($exportnames)) {
|
|
|
|
$menu['exportgroup']='--'.get_string('exportplugins', 'grades');
|
|
|
|
$menu = $menu+$exportnames;
|
2005-03-28 18:05:45 +00:00
|
|
|
}
|
2005-03-17 16:23:28 +00:00
|
|
|
|
2007-07-16 18:58:09 +00:00
|
|
|
/// editing scripts - not real plugins
|
|
|
|
if (true) { //TODO: add proper capability here
|
|
|
|
$menu['edit']='--'.get_string('edit');
|
|
|
|
$url = 'edit/tree.php?id='.$courseid;
|
|
|
|
if ($active_type == 'edit' and $active_plugin == 'tree' ) {
|
|
|
|
$active = $url;
|
2005-03-17 16:23:28 +00:00
|
|
|
}
|
2007-07-16 18:58:09 +00:00
|
|
|
$menu[$url] = get_string('edittree', 'grades');
|
2005-03-28 18:05:45 +00:00
|
|
|
}
|
|
|
|
|
2007-07-16 18:58:09 +00:00
|
|
|
/// finally print/return the popup form
|
|
|
|
return popup_form($CFG->wwwroot.'/grade/', $menu, 'choosepluginreport', $active, 'choose', '', '', $return, 'self', get_string('selectplugin', 'grades'));
|
2005-03-17 16:23:28 +00:00
|
|
|
}
|
|
|
|
|
2007-07-17 05:52:42 +00:00
|
|
|
/**
|
|
|
|
* Utility class used for return tracking when using edit and other forms from grade plubins
|
|
|
|
*/
|
2007-07-16 18:58:09 +00:00
|
|
|
class grade_plugin_return {
|
|
|
|
var $type;
|
|
|
|
var $plugin;
|
|
|
|
var $courseid;
|
|
|
|
var $userid;
|
|
|
|
var $page;
|
2005-03-28 18:05:45 +00:00
|
|
|
|
2007-07-17 05:52:42 +00:00
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
* @param array $params - associative array with return parameters, if null parameter are taken from _GET or _POST
|
|
|
|
*/
|
2007-07-16 18:58:09 +00:00
|
|
|
function grade_plugin_return ($params=null) {
|
|
|
|
if (empty($params)) {
|
|
|
|
$this->type = optional_param('gpr_type', null, PARAM_SAFEDIR);
|
|
|
|
$this->plugin = optional_param('gpr_plugin', null, PARAM_SAFEDIR);
|
|
|
|
$this->courseid = optional_param('gpr_courseid', null, PARAM_INT);
|
|
|
|
$this->userid = optional_param('gpr_userid', null, PARAM_INT);
|
|
|
|
$this->page = optional_param('gpr_page', null, PARAM_INT);
|
2005-03-29 09:12:42 +00:00
|
|
|
|
|
|
|
} else {
|
2007-07-16 18:58:09 +00:00
|
|
|
foreach ($params as $key=>$value) {
|
|
|
|
if (array_key_exists($key, $this)) {
|
|
|
|
$this->$key = $value;
|
|
|
|
}
|
2005-03-17 16:23:28 +00:00
|
|
|
}
|
|
|
|
}
|
2005-04-07 20:47:03 +00:00
|
|
|
}
|
|
|
|
|
2007-07-17 05:52:42 +00:00
|
|
|
/**
|
|
|
|
* Returns return parameters as options array suitable for buttons.
|
|
|
|
* @return array options
|
|
|
|
*/
|
2007-07-16 18:58:09 +00:00
|
|
|
function get_options() {
|
|
|
|
if (empty($this->type) or empty($this->plugin)) {
|
|
|
|
return array();
|
2006-01-05 15:49:21 +00:00
|
|
|
}
|
2005-04-07 20:47:03 +00:00
|
|
|
|
2007-07-16 18:58:09 +00:00
|
|
|
$params = array();
|
2005-04-07 20:47:03 +00:00
|
|
|
|
2007-07-16 18:58:09 +00:00
|
|
|
$params['plugin'] = $this->plugin;
|
2005-04-07 20:47:03 +00:00
|
|
|
|
2007-07-16 18:58:09 +00:00
|
|
|
if (!empty($this->courseid)) {
|
|
|
|
$params['id'] = $this->courseid;
|
2005-04-07 20:47:03 +00:00
|
|
|
}
|
2006-12-21 08:12:10 +00:00
|
|
|
|
2007-07-16 18:58:09 +00:00
|
|
|
if (!empty($this->userid)) {
|
|
|
|
$params['userid'] = $this->userid;
|
2006-12-21 08:12:10 +00:00
|
|
|
}
|
|
|
|
|
2007-07-16 18:58:09 +00:00
|
|
|
if (!empty($this->page)) {
|
|
|
|
$params['page'] = $this->page;
|
2005-03-17 16:23:28 +00:00
|
|
|
}
|
2006-01-05 15:49:21 +00:00
|
|
|
|
2007-07-16 18:58:09 +00:00
|
|
|
return $params;
|
2005-03-17 16:23:28 +00:00
|
|
|
}
|
|
|
|
|
2007-07-17 05:52:42 +00:00
|
|
|
/**
|
|
|
|
* Returns return url
|
|
|
|
* @param string $default default url when params not set
|
|
|
|
* @return string url
|
|
|
|
*/
|
2007-07-16 18:58:09 +00:00
|
|
|
function get_return_url($default) {
|
|
|
|
global $CFG;
|
2005-03-17 16:23:28 +00:00
|
|
|
|
2007-07-16 18:58:09 +00:00
|
|
|
if (empty($this->type) or empty($this->plugin)) {
|
|
|
|
return $default;
|
2005-03-17 16:23:28 +00:00
|
|
|
}
|
|
|
|
|
2007-07-16 18:58:09 +00:00
|
|
|
if ($this->type == 'report') {
|
|
|
|
$url = $CFG->wwwroot.'/grade/report.php?report='.$this->plugin;
|
|
|
|
$glue = '&';
|
2005-03-17 16:23:28 +00:00
|
|
|
|
2007-07-16 18:58:09 +00:00
|
|
|
} else {
|
|
|
|
$url = $CFG->wwwroot.'/grade/'.$this->type.'/'.$this->plugin.'/index.php';
|
|
|
|
$glue = '?';
|
2005-03-17 16:23:28 +00:00
|
|
|
}
|
|
|
|
|
2007-07-16 18:58:09 +00:00
|
|
|
if (!empty($this->courseid)) {
|
|
|
|
$url .= $glue.'id='.$this->courseid;
|
|
|
|
$glue = '&';
|
2005-03-17 16:23:28 +00:00
|
|
|
}
|
|
|
|
|
2007-07-16 18:58:09 +00:00
|
|
|
if (!empty($this->userid)) {
|
|
|
|
$url .= $glue.'userid='.$this->userid;
|
|
|
|
$glue = '&';
|
2005-03-17 16:23:28 +00:00
|
|
|
}
|
2006-08-14 08:46:44 +00:00
|
|
|
|
2007-07-16 18:58:09 +00:00
|
|
|
if (!empty($this->page)) {
|
|
|
|
$url .= $glue.'page='.$this->page;
|
2005-03-17 16:23:28 +00:00
|
|
|
}
|
|
|
|
|
2007-07-16 18:58:09 +00:00
|
|
|
return $url;
|
2005-03-17 16:23:28 +00:00
|
|
|
}
|
|
|
|
|
2007-07-17 05:52:42 +00:00
|
|
|
/**
|
|
|
|
* Returns string with hidden return tracking form elements.
|
|
|
|
* @return string
|
|
|
|
*/
|
2007-07-16 18:58:09 +00:00
|
|
|
function get_form_fields() {
|
|
|
|
if (empty($this->type) or empty($this->plugin)) {
|
|
|
|
return '';
|
2005-03-17 16:23:28 +00:00
|
|
|
}
|
|
|
|
|
2007-07-16 18:58:09 +00:00
|
|
|
$result = '<input type="hidden" name="gpr_type" value="'.$this->type.'" />';
|
|
|
|
$result .= '<input type="hidden" name="gpr_plugin" value="'.$this->plugin.'" />';
|
2006-12-22 02:23:52 +00:00
|
|
|
|
2007-07-16 18:58:09 +00:00
|
|
|
if (!empty($this->courseid)) {
|
|
|
|
$result .= '<input type="hidden" name="gpr_courseid" value="'.$this->courseid.'" />';
|
2005-03-17 16:23:28 +00:00
|
|
|
}
|
|
|
|
|
2007-07-16 18:58:09 +00:00
|
|
|
if (!empty($this->userid)) {
|
|
|
|
$result .= '<input type="hidden" name="gpr_userid" value="'.$this->userid.'" />';
|
2005-03-17 16:23:28 +00:00
|
|
|
}
|
|
|
|
|
2007-07-16 18:58:09 +00:00
|
|
|
if (!empty($this->page)) {
|
|
|
|
$result .= '<input type="hidden" name="gpr_page" value="'.$this->page.'" />';
|
2005-03-17 16:23:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-17 05:52:42 +00:00
|
|
|
/**
|
|
|
|
* Add hidden elements into mform
|
|
|
|
* @param object $mform moodle form object
|
|
|
|
* @return void
|
|
|
|
*/
|
2007-07-16 18:58:09 +00:00
|
|
|
function add_mform_elements(&$mform) {
|
|
|
|
if (empty($this->type) or empty($this->plugin)) {
|
|
|
|
return;
|
2005-03-17 16:23:28 +00:00
|
|
|
}
|
|
|
|
|
2007-07-16 18:58:09 +00:00
|
|
|
$mform->addElement('hidden', 'gpr_type', $this->type);
|
|
|
|
$mform->setType('gpr_type', PARAM_SAFEDIR);
|
2005-03-17 16:23:28 +00:00
|
|
|
|
2007-07-16 18:58:09 +00:00
|
|
|
$mform->addElement('hidden', 'gpr_plugin', $this->plugin);
|
|
|
|
$mform->setType('gpr_plugin', PARAM_SAFEDIR);
|
2005-06-23 12:37:19 +00:00
|
|
|
|
2007-07-16 18:58:09 +00:00
|
|
|
if (!empty($this->courseid)) {
|
|
|
|
$mform->addElement('hidden', 'gpr_courseid', $this->courseid);
|
|
|
|
$mform->setType('gpr_courseid', PARAM_INT);
|
2005-03-17 16:23:28 +00:00
|
|
|
}
|
|
|
|
|
2007-07-16 18:58:09 +00:00
|
|
|
if (!empty($this->userid)) {
|
|
|
|
$mform->addElement('hidden', 'gpr_userid', $this->userid);
|
|
|
|
$mform->setType('gpr_userid', PARAM_INT);
|
2005-03-17 16:23:28 +00:00
|
|
|
}
|
|
|
|
|
2007-07-16 18:58:09 +00:00
|
|
|
if (!empty($this->page)) {
|
|
|
|
$mform->addElement('hidden', 'gpr_page', $this->page);
|
|
|
|
$mform->setType('gpr_page', PARAM_INT);
|
2005-03-17 16:23:28 +00:00
|
|
|
}
|
|
|
|
}
|
2005-03-28 18:05:45 +00:00
|
|
|
|
2007-07-17 05:52:42 +00:00
|
|
|
/**
|
|
|
|
* Add return tracking params into url
|
|
|
|
* @param string $url
|
|
|
|
* @return string $url with erturn tracking params
|
|
|
|
*/
|
2007-07-16 18:58:09 +00:00
|
|
|
function add_url_params($url) {
|
|
|
|
if (empty($this->type) or empty($this->plugin)) {
|
|
|
|
return $url;
|
2005-03-17 16:23:28 +00:00
|
|
|
}
|
2006-12-22 02:34:42 +00:00
|
|
|
|
2007-07-16 18:58:09 +00:00
|
|
|
if (strpos($url, '?') === false) {
|
|
|
|
$url .= '?gpr_type='.$this->type;
|
|
|
|
} else {
|
|
|
|
$url .= '&gpr_type='.$this->type;
|
2005-03-17 16:23:28 +00:00
|
|
|
}
|
|
|
|
|
2007-07-16 18:58:09 +00:00
|
|
|
$url .= '&gpr_plugin='.$this->plugin;
|
2005-03-17 16:23:28 +00:00
|
|
|
|
2007-07-16 18:58:09 +00:00
|
|
|
if (!empty($this->courseid)) {
|
|
|
|
$url .= '&gpr_courseid='.$this->courseid;
|
2005-03-17 16:23:28 +00:00
|
|
|
}
|
|
|
|
|
2007-07-16 18:58:09 +00:00
|
|
|
if (!empty($this->userid)) {
|
|
|
|
$url .= '&gpr_userid='.$this->userid;
|
2005-03-17 16:23:28 +00:00
|
|
|
}
|
2006-08-15 08:29:29 +00:00
|
|
|
|
2007-07-16 18:58:09 +00:00
|
|
|
if (!empty($this->page)) {
|
|
|
|
$url .= '&gpr_page='.$this->page;
|
2006-08-15 08:29:29 +00:00
|
|
|
}
|
2006-10-25 08:51:26 +00:00
|
|
|
|
2007-07-16 18:58:09 +00:00
|
|
|
return $url;
|
2006-10-25 08:51:26 +00:00
|
|
|
}
|
|
|
|
}
|
2007-07-23 08:13:59 +00:00
|
|
|
?>
|