wwwroot . '/mod/sloodle/lib/jquery/jquery-1.3.2.min.js');
sloodle_require_js($CFG->wwwroot . '/mod/sloodle/lib/js/backpack.js');
/**
* Class for rendering a view of SLOODLE course information.
* @package sloodle
*/
class sloodle_view_backpack extends sloodle_base_view {
/**
* The Moodle course object, retrieved directly from database.
* @var object
* @access private
*/
var $course = 0;
/**
* SLOODLE course object, retrieved directly from database.
* @var object
* @access private
*/
var $sloodle_course = null;
/**
* Constructor.
*/
function sloodle_view_backpack()
{
}
/**
* Check the request parameters to see which course was specified.
*/
function process_request()
{
global $USER;
$id = required_param('id', PARAM_INT);
//check if valid course
if (!$this->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(get_string('failedcourseload', 'sloodle'));
}
function process_form() {
$id = required_param('id', PARAM_INT);
//has itemAdd forum been submitted?
$isItemAdd= optional_param('isItemAdd',0, PARAM_INT);
$userIds = optional_param('userIds', 0, PARAM_INT);
//itemAdd form has been submitted
if ($isItemAdd) {
if (!$this->can_edit) {
print_error("Permission denied");
}
$controllerid = required_param('controllerid', PARAM_INT);
//fetch all currencies
$all_currencies = SloodleCurrency::FetchIDNameHash();
//create controller so we can fetch active round
$controller = new SloodleController();
if(!$controller->load_by_course_module_id($controllerid)) {
print_error('Could not load controller for '.$controllerid);
}
$roundid = $controller->get_active_roundid(true);
//go through each currency and see if it has been set, if it has, we have to update each user who
//has been checked
foreach($all_currencies as $currencyid => $currencyname) {
//check if a currency update is necessary for this currency
//build the currencyname field for this currency
$fieldname="currency_".$currencyid;
//now see if it was submitted
$fieldvalue= optional_param($fieldname,0,PARAM_INT);
//if no value has been submitted for this currency, we can skip adding this currency to the users!
if ($fieldvalue==0) {
continue;
}
foreach ($userIds as $u) {
//go through each user which was checked and give them the selected currency and amount
//create backpack item
$backpack_item = new stdClass();
$backpack_item->currencyid=intval($currencyid);
$backpack_item->userid=intval($u);
$backpack_item->amount=intval($fieldvalue);
$backpack_item->timeawarded=time();
$backpack_item->roundid=$roundid;
$backpack_item->description="moodle add by ". $USER->username;
//add it to the users backpack
sloodle_insert_record('sloodle_award_points',$backpack_item);
}
}
}
}
/**
* 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;
//print breadcrumbs
$navigation = "wwwroot}/mod/sloodle/view.php?_type=backpack&id={$this->course->id}\">";
$navigation .= get_string('backpack:view', 'sloodle');
$navigation .= "";
//print the header
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() {
global $CFG;
global $COURSE;
$view = optional_param('view', "", PARAM_TEXT);
// Setup our list of tabs
// We will always have a view option
$action = optional_param('action', "", PARAM_TEXT);
$context = get_context_instance(CONTEXT_COURSE,$this->course->id);
echo "
";
//print titles
sloodle_print_box_start('generalbox boxaligncenter center boxheightnarrow leftpara');
echo '