moodle-block_mytreestudyplan/globallevels.php

75 lines
2.2 KiB
PHP
Raw Normal View History

<?php
if(isset($_SERVER['SCRIPT_FILENAME']))
{
// If SCRIPT_FILENAME is set, use that so the symlinked directories the developmen environment uses are handled correctly
$root = dirname(dirname(dirname($_SERVER['SCRIPT_FILENAME'])));
require_once($root."/config.php");
}
else
{
// If not, assume the cwd is not symlinked and proceed as we are used to
require_once("../../config.php");
}
// HOW DID WE ENSURE ONLY ADMINS CAN VIEW THIS PAGE?
require_once($CFG->libdir.'/adminlib.php');
admin_externalpage_setup("block_gradelevel_default_levels");
$action = optional_param('action', null, PARAM_ALPHA);
$data = optional_param('data', null, PARAM_ALPHA);
if(!empty($data))
{
$data = json_decode($data);
}
if(!empty($action) && confirm_sesskey())
{
switch($action) {
case 'submitchanges':
print_r($data);
redirect($PAGE->url);
break;
}
}
else
{
$PAGE->requires->js_call_amd('block_gradelevel/leveleditor', 'init');
print $OUTPUT->header();
print $OUTPUT->heading(get_string('cfgpage_globallevels', 'block_gradelevel'));
$global_levels = $DB->get_records('block_gradelevel_levels', array('levelset_id' => 0));
usort( $global_levels, function( $a, $b) {
return ( $a->points < $b->points ) ? -1 : 1;
} );
$skill_id = 0;
print "<p>".get_string('levelcfg_description','block_gradelevel')."</p>";
print "<table id='level_config' data-skill='{$skill_id}'>";
print "<thead><tr><th>".get_string('levelcfg_head_points','block_gradelevel')."</th><th>".get_string('levelcfg_head_color','block_gradelevel')."</th></tr></thead>";
print "<tbody>";
foreach($global_levels as $lvl)
{
$color = ltrim($lvl->badgecolor,"#");
print "<tr data-rowid='{$lvl->id}'><td><input data-name='points' type='number' class='uint' value='{$lvl->points}'></td><td><input type='text' data-name='color' class='jscolor' value='{$color}'></td></tr>";
}
print "</tbody>";
print "<tfoot><tr><td class='block_gradelevel_addlevel' colspan='2'><a data-action='addlevel' href='#' onclick='return false;'>".get_string("levelcfg_addlevel",'block_gradelevel')."</a></td></td></tfoot>";
print "</table>";
print "<p><button data-action='savechanges'>".get_string('savechanges','core')."</button></p>";
print $OUTPUT->footer();
}