course = sloodle_get_record('course', 'id', $id)) error('Could not find course.');
$this->sloodle_course = new SloodleCourse();
if (!$this->sloodle_course->load($this->course)) error(s(get_string('failedcourseload', 'sloodle')));
}
function process_form() {
//mode is for the different editing tasks of the currency screen (add, modify, delete)
$mode = optional_param('mode', "view", PARAM_TEXT);
if ( ($mode != 'view') && (!$this->can_edit) ) {
print_error('Permission denied');
}
switch($mode) {
case "modify":
//get vars
$currencyid = required_param('currencyid', PARAM_INT);
$currencyname = required_param('currencyname', PARAM_TEXT);
$imageurl = required_param('imageurl', PARAM_URL);
$displayorder = required_param('displayorder', PARAM_INT);
//create update object
$currency = new stdClass();
$currency->id = $currencyid;
$currency->name = $currencyname;
$currency->displayorder = $displayorder;
$currency->imageurl = ($imageurl != "") ? $imageurl : null;
//update
$result = sloodle_update_record('sloodle_currency_types',$currency);
if (!$result) {
$errorlink = $CFG->wwwroot."/mod/sloodle/view.php?_type=currency&id={$id}";
print_error(get_string('general:fail','sloodle'),$errorlink);
}
break;
case "add":
//get vars
$currencyname = required_param('currencyname', PARAM_TEXT);
$imageurl = optional_param('imageurl', '', PARAM_URL);
$displayorder = optional_param('displayorder', 0, PARAM_INT);
//create update object
$currency = new stdClass();
$currency->name=$currencyname;
$currency->displayorder = $displayorder;
$currency->imageurl = $imageurl;
//update
$result = sloodle_insert_record('sloodle_currency_types',$currency);
if (!$result) {
$errorlink = $CFG->wwwroot."/mod/sloodle/view.php?_type=currency&id={$id}";
print_error(get_string('general:fail','sloodle'),$errorlink);
}
break;
case "confirmdelete":
$currencyid= required_param('currencyid', PARAM_INT);
$result = sloodle_delete_records('sloodle_currency_types','id',$currencyid);
if (!$result) {
$errorlink = $CFG->wwwroot."/mod/sloodle/view.php?_type=currency&id={$id}";
print_error(get_string('general:fail','sloodle'),$errorlink);
}
break;
default:
break;
}
}
/**
* Check that the user is logged-in and has permission to alter course settings.
*/
function check_permission() {
// Ensure the user logs in
require_login($this->course->id);
if (isguestuser()) error(get_string('noguestaccess', 'sloodle'));
add_to_log($this->course->id, 'course', 'view sloodle data', '', "{$this->course->id}");
// Ensure the user is allowed to update information on this course
$this->course_context = get_context_instance(CONTEXT_COURSE, $this->course->id);
if (has_capability('moodle/course:update', $this->course_context)) $this->can_edit = true;
}
/**
* Print the course settings page header.
*/
function sloodle_print_header() {
global $CFG;
$id = required_param('id', PARAM_INT);
$navigation = "wwwroot}/mod/sloodle/view.php?&_type=currency&mode=allcurrencies&id={$id}\">".get_string('currencies:view', 'sloodle')."";
sloodle_print_header_simple(get_string('backpack','sloodle'), " ", $navigation, "", "", true, '', false);
}
/**
* Render the view of the module or feature.
* This MUST be overridden to provide functionality.
*/
function render() {
$view = optional_param('view', "", PARAM_TEXT);
$mode= optional_param('mode', "allcurrencies", PARAM_TEXT);
switch ($mode){
case "allcurrencies":
$this->render_all_currencies();
break;
case "editcurrency":
$this->render_edit_currency();
break;
case "deletecurrency":
$this->delete_currency();
break;
default:
$this->render_all_currencies();
break;
}
}
function render_all_currencies() {
global $CFG;
global $COURSE;
$id = required_param('id', PARAM_INT);
// Display instrutions for this page
echo "
";
sloodle_print_box_start('generalbox boxaligncenter center boxheightnarrow leftpara');
echo '