/Main_Page

::You must have ninja focus to complete your mission::NinjaFocus::

Printing Credit

Views:


A custom, in house, moodle block to tell the little darlings how much print credit they have remaining

/blocks/printing_credit/block_printing_credit.php:

<?PHP

// This is a simple moodle block which was written in house at Varndean College, Brighton, UK
// by Kieran Whitbread 2007

class block_printing_credit extends block_base {
    function init() {
        $this->title = 'Printing Credit';
        $this->version = 2007010901;
    }

    function applicable_formats() {
        return array('site' => true);
    }

    function get_content () {
        global $USER, $CFG;
        $wwwroot = '';
        $signup = '';

        if ($this->content !== NULL) {
            return $this->content;
        }

        $username = get_moodle_cookie() === 'nobody' ? '' : get_moodle_cookie();

        $this->content->footer = '';
        $this->content->text = '';

        if (!empty($USER->loggedin) && !isguest()) {   // Build and show the block
            $ldap_connection = ldap_connect('ldap.varndean.ac.uk');
            $ldap_binding = ldap_bind($ldap_connection);
            if ($ldap_binding) {
                $ldap_results = ldap_search($ldap_connection, 'ou=learner,o=vsfc', '(cn='.$username.')', array('accountbalance'));
                $ldap_entries = ldap_get_entries($ldap_connection, $ldap_results);
                $balance = $ldap_entries[0]['accountbalance'][0];
                if ($balance) {
                    $balance = $balance / 100.0;
                    $this->content->text = '<p>Remaining Credit: £'.$balance.'</p>';
                }
            }
        }

        return $this->content;
    }
}

?>

Main Menu

Personal tools

Toolbox