Source for file ibank.php
Documentation is available at ibank.php
* Defines a class for viewing the SLOODLE iBank module in Moodle.
* Derived from the module view base class.
* @copyright Copyright (c) 2008 Sloodle (various contributors)
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU GPL v3
* @see http://slisweb.sjsu.edu/sl/index.php/Sloodle_Stipend_Giver
* @contributer Paul G. Preibisch - aka Fire Centaur
/** The base module view class */
require_once(SLOODLE_DIRROOT.
'/view/base/base_view_module.php');
/** SLOODLE course data structure */
require_once(SLOODLE_LIBROOT.
'/course.php');
/** SLOODLE course object data structure */
require_once(SLOODLE_LIBROOT.
'/sloodlecourseobject.php');
/** SLOODLE course object data structure */
require_once(SLOODLE_LIBROOT.
'/ipointbank_object.php');
/** SLOODLE stipendgiver object data structure */
require_once(SLOODLE_DIRROOT.
'/mod/ibank-1.0/stipendgiver_object.php');
/** Sloodle Session code. */
require_once(SLOODLE_LIBROOT.
'/sloodle_session.php');
/** General Sloodle functionality. */
require_once(SLOODLE_LIBROOT.
'/general.php');
* Class for rendering a view of a Distributor module in Moodle.
* SLOODLE course object, retrieved directly from database.
* The result number to start displaying from
* A List of records of the transactions for this stipend
* A List of all users avatar UUID's who have collected a stipend
* A List of usrs moodle id's who have collected a stipend
* A List of all the students in this course
* sloodleId The instance of this moodle module
* session is a dummy session object to be used as a parameter when creating a sloodleUser object
* @var SloodleSession Object
* @var $iPb a pointer to the iPoint bank object base class;
* @var $sCourseObj - a pointer to the sloodleCourseObject with useful functions to access course data
* @var $iPts are the number of iPoints
* if iPoints were selected as icurrency
* @var $icurrency - currency of this stopend - can be Lindens, or iPoints
* @var $stipendGiverObj - a pointer to the stipendGiverObject with useful functions to access the stipendGiver
* The course module instance, retrieved directly from the database (table: course_modules)
* The main SLOODLE module instance, retreived directly from the database (table: sloodle)
* The VLE course object, retrieved directly from the database (table: course)
* The SLOODLE course object.
* Context object for permissions in the Moodle course.
* Context object for permissions in the Moodle module.
* This constructor creates a sloodleCourseObject which gives us useful functions to access course data
* Also creats a stipendGiver Object which gives us useful functions to access stipendGiver data
$sloodleid =
required_param('id', PARAM_INT);
//set Sloodle Course Obj - this object will give us things like: userlist of the course, sloodle id etc.
* Check that the user has permission to view this module, and check if they can edit it too.
// Make sure the user is logged-in
require_course_login($this->course, true, $this->cm);
add_to_log($this->course->id, 'sloodle', 'view sloodle module', "view.php?id={$this->cm->id}", "{
$this->sloodle->id}", $this->cm->id);
// If the module is hidden, then can the user still view it?
if (empty($this->cm->visible) &&
!has_capability('moodle/course:viewhiddenactivities', $this->module_context)) notice(get_string('activityiscurrentlyhidden'));
* Check and process the request parameters.
//====================== Get all course related information
$sloodleid =
required_param('id', PARAM_INT);
$this->start =
optional_param('start', 0, PARAM_INT);
//get stipendGiver Object (iBank Object)
//get icurrency type of points
//get users in this course
* Process any form data which has been submitted.
//STEP 1 - HAS THE DEFAULT STIPEND AMOUNT BEEN ALLOCATED TO EVERY USER?
//======================== creates initial default stipend records for all users
//if no transactions exist
//create stipend transactions for each student!
//for each user in the class insert a transaction record with following values:
//avuuid,userid,avname,amount,type,timemodified
//Ipoints can be various types - ie: real lindens, or just points.
$iTransaction =
new stdClass();
$iTransaction->userid =
$u->id;
$iTransaction->itype =
"stipend";
$iTransaction->timemodified =
time();
//insert iTransaction into db
//STEP 2 - Transactions exist for this stipend already, check to see if new students have been added
//========================= HAVE NEW STUDENTS BEEN ADDED
//============== STEP 3 - CHECK TO SEE IF THERE ARE PENDING UPDATES TO EXISTING STUDENTS
//check if we need to update allocations
//if "update" param exists, that means someone submitted a form using the update butotn in printUserTable function
$update=
optional_param("update");
//check each allotment value from form, and compare against db. change where necessary
$newBudgets=
optional_param("newbudgets");
$userIds =
optional_param("userIds");
$userNames =
optional_param("usernames");
foreach ($userIds as $userId) {
//retreive saved budget for this user from the database
//compare saved budget with the budget submitted in the form field for this user
if ((int)
$newBudgets[$currIndex] !==
$savedBudget){
//The user has submited a new stipend allotment for this user, because the new budget
//from the form differs from what has been saved in the db.
//so we must update the alloted amount in db
//STEP 1 First we should check if the user has already withdrawn any stipends
if ($withdrawnAmount >
$newBudgets[$currIndex]){
$errorString =
"<br>".
$userNames[$currIndex].
" ".
get_string('stipendgiver:alreadywd','stipendgiver') .
$withdrawnAmount;
$errorString =
get_string('stipendgiver:alreadywd2','stipendgiver');
//STEP 2 - get id of transaction to update
$transactionUpdate =
new stdClass();
$transactionUpdate->id=
$stipendRec->id;
$transactionUpdate->amount=
$newBudgets[$currIndex];
$transactionUpdate->timemodified=
time();
$updatedRecs[]=
$userNames[$currIndex];
//create and print confirmation message to the user
$confirmedMessage =
get_string("stipendgiver:successfullupdate","sloodle");
$confirmedMessage .=
$this->addCommas($updatedRecs);
//send confirmation Message
//updater stipendgier ibank
* Override the base_view_module print_header for formatting reasons
// Offer the user an 'update' button if they are allowed to edit the module
$editbuttons =
update_module_button($this->cm->id, $this->course->id, get_string('modulename', 'sloodle'));
// Display the header: Sloodle with edit buttons
$navigation =
"<a href=\"index.php?{$this->course->id}\">
".
get_string('modulenameplural','sloodle').
"</a> ->";
print_header_simple(format_string($this->sloodle->name), "", "{
$navigation} ".
format_string($this->sloodle->name, "", "", true, $editbuttons, navmenu($this->course, $this->cm)));
// Display the module name: Sloodle StipendGiver
$img =
'<img src="'.
$CFG->wwwroot.
'/mod/sloodle/icon.gif" width="16" height="16" alt=""/> ';
print_heading($img.
$this->sloodle->name, 'center');
// Display the module type and description
$fulltypename =
get_string("moduletype:{$this->sloodle->type}", 'sloodle');
echo
'<h4 style="text-align:center;">'.
get_string('moduletype', 'sloodle').
': '.
$fulltypename;
echo
helpbutton("moduletype_{$this->sloodle->type}", $fulltypename, 'sloodle', true, false, '', true).
'</h4>';
* printUserTable function
* @desc This function will display an HTML table of the users transactions
* Columns displayed will be: UserName | Avatar | Amount Alloted | Balance Remaining
* @param $userData - an array of users
* @link http://sloodle.googlecode.com
//===================== Build table with headers, set alignment and width of cells
//Create HTML table object
$sloodletable =
new stdClass();
//Create Sloodle Table Column Labels
//User | Avatar | Amount Alloted | Balance Remaining
$allotedString =
get_string('stipendgiver:alloted', 'sloodle');
$allotedString =
get_string('stipendgiver:iPoints', 'sloodle');
$allotedString .=
' <input type="submit"';
$allotedString .=
' name="update" ';
$allotedString .=
' value="'.
get_string("stipendgiver:update","sloodle") .
'">';
$sloodletable->head =
array('',
get_string('stipendgiver:username', 'sloodle'),
// get_string('user', 'sloodle'),
get_string('stipendgiver:avatars', 'sloodle'),
get_string('stipendgiver:debits', 'sloodle'),
get_string('stipendgiver:balance', 'sloodle'));
$sloodletable->head =
array('',
get_string('stipendgiver:username', 'sloodle'),
//get_string('user', 'sloodle'),
get_string('stipendgiver:avatars', 'sloodle'),
get_string('stipendgiver:totalipoints', 'sloodle'));
//set alignment of table cells
$sloodletable->align =
array('left', 'center', 'left','right','center');
//set size of table cells
$sloodletable->size =
array('2%','15%', '5%','45%','3%');
foreach ($userData as $u){
// Construct URLs to this user's Moodle and SLOODLE profile pages
$url_moodleprofile =
$this->sCourseObj->get_moodleUserProfile($u);
$url_sloodleprofile =
$this->sCourseObj->get_sloodleprofile($u);
//==========print check box
//if ($this->sCourseObj->is_teacher($USER->id)){
// $rowData[]= '<input type="checkbox" id="cb'.$checkBoxId++.' name="cid[]" value="'.$u->id.'" checked>';
//==========print hidden user id for form processing
$userIdFormElement =
'<input type="hidden" name="userIds[]" value="'.
$u->id.
'">';
$userIdFormElement .=
'<input type="hidden" name="usernames[]" value="'.
$u->username.
'">';
//========= print url link to Moodle name
$rowData[]=
$userIdFormElement .
"<a href=\"{$url_moodleprofile}\">{$u->firstname} {
$u->lastname}</a>
";
//$rowData[]= "<a href=\"{$url_moodleprofile}\">{$u->username}</a>";
// Construct URLs to this user's Moodle and SLOODLE profile pages
// Get the Sloodle data for this Moodle user
$ownedAvatars =
get_records('sloodle_users', 'userid', $u->id,'avname DESC','userid,uuid,avname');
//=========*** print stipend amount alloted for this moodle user (Prints 0 if no stipend alloted
$editField =
'<input style="text-align:right;" type="text" size="6" name="newbudgets[]" value="'.
$budget.
'">';
}else $editField=
$budget;
//========= print names of avatars this moodle user has, and the amount's they've withdrawn and the dates
//===== build inner Avatar names table
//===== BUILD Avatar table if user has avatars
//initialize Av table data;
//if this user has an avatar associated with the accound
foreach ($ownedAvatars as $userAvatar) {
// If this entry is empty, then skip it
if (empty($userAvatar->avname) ||
ctype_space($userAvatar->avname)) {
// ========= print avatar name
$avs =
"<a href=\"{$url_sloodleprofile}\">{$userAvatar->avname}</a><br>
";
//========== print amount withdrawn by this avatar
//search transactions to see if this user made a debit and return amount. If they havent withdrew any, 0 will be returned
$debits .=
$this->stipendGiverObj->getAvatarDebits($userAvatar->uuid) .
"<br>";
//======= build an empty avatars names table if no avatars
//Build Avatar names table
//even though this user has no avatars associated with account, check to see if transactions
//have been made with this moodle user id.
//if they have, notify teacher that transaction has been made
//search transaction records and find out which avatar was used
foreach ($transRecs as $t){
if ($u->id ==
$t->userid)
$deletedAvs[]=
$t->avname;
//print avs that made transactions, but no longer are registered to this user
$avs =
get_string('stipendgiver:noneregistered','sloodle');
//========= now print Inner AvTable
//add the collective RowData to inner avTable that will sit in this cell of the bigger user html table
//now place this inner avTable inside the bigger user html table
// the "true" in print_table($table,true) returns the html rather than print it
//===== NOW print the actual User table
$sloodletable->data[] =
$rowData;
print
('<form action="" method="POST">');
print_table($sloodletable);
* Render the view of the Stipend Giver.
$this->courseid =
$this->course->id;
// Print a Table Intro / Amount / Purpose
print_box_start('generalbox boxaligncenter boxwidthnormal leftpara');
$iTable =
new stdClass();
//********* PRINT DESCRIPTION
print
('<b style="color:Black;text-align:left;">'.
get_string('stipendgiver:description','sloodle').
':</b>'.
$this->sloodle->intro.
'<br> ');
$iRow[] =
'<b style="color:green;text-align:left;">'.
get_string('stipendgiver:totalallocations','sloodle').
'</b>:';
$iRow[] =
'<b style="color:green;text-align:left;">'.
get_string('stipendgiver:totalawarded','sloodle').
'</b>:';
//********* PRINT TOTAL DEBITS
$iRow[] =
'<b style="color:red;text-align:left;">'.
get_string('stipendgiver:totaldebits','sloodle').
'</b>:  ';
//********* PRINT STARTING BALANCE
$iRow[] =
'<b style="color:blue;text-align:left;">'.
get_string('stipendgiver:startingbalance','sloodle').
'</b>:  ';
//==================================================================================================================
print_box_start('generalbox boxaligncenter boxwidthnarrow leftpara');
//print_box_start('generalbox boxaligncenter boxwidthnarrow leftpara');
//======Print TRANSACTIONS TITLE
print
('<h3 style="color:black;text-align:center;">'.
get_string('stipendgiver:transactions','sloodle')).
'</h3> ';
print
('<h3 style="color:black;text-align:center;">'.
get_string('stipendgiver:scoreboard','sloodle')).
'</h3> ';
//======Print STUDENT TRANSACTIONS
else print
"no student transaction";
//==================================================================================================================
* addCommas takes an array of strings and add commas between elements except at the last element, or if there is only one element
$runTwice=
false; //for the comma to print correctly
foreach ($arrList as $arr){
if ($runTwice) $newList.=
",";
* @desc Simply sets up the inner avatar table, alignment, and sizes
* @staticvar object $avTable
* @link http://sloodle.googlecode.com
//create inter avatar table
$avTable =
new stdClass();
$avTable->align =
array('left','right');
$avTable->size =
array('70%','30%');
//test file to access db and play with forms
$dbname =
'eslteach_moodle';
$dbuser =
'eslteach_moodle';
$dbpass =
'evkingmoodle555';
$result =
mysql_query("TRUNCATE TABLE `mdl_sloodle_stipendgiver_trans`");
Documentation generated on Fri, 17 Jul 2009 11:01:21 +0100 by phpDocumentor 1.4.0