Show # Users & # (Non hidden) Courses.

Show # Users & # (Non hidden) Courses.

by Paul Andrews -
Number of replies: 18
Hello.

I had a go at writing a block today - it's not very wizzy or owt.

It shows how many users you have on your Moodle & how many courses you have.

I'm still fiddling with the layout - and I'm not very good with php - but I'll post it up if anyone wants it.

I also want to add a 3rd line that shows the # hits the site has had 'today' - not sure how to do this yet so if anyone has any pointers please let me know.

If someone wants to make it more wizzy - feel free.

You can see it here - it's called "Live Stats" at the mo...

smile


Average of ratings: -
In reply to Paul Andrews

Re: Show # Users & # (Non hidden) Courses.

by Simon Williams -
Thanks - that looks quite quick and useful.

On another note how do you get the nice rounded corners on your blocks?

big grin
In reply to Simon Williams

Re: Show # Users & # (Non hidden) Courses.

by Paul Andrews -
"On another note how do you get the nice rounded corners on your blocks?"

We made an edit to weblib and then used gifs with transparent backgrounds - I can email you the changes we made if you like.

smile
In reply to Paul Andrews

Re: Show # Users & # (Non hidden) Courses.

by Simon Williams -
I am looking for a theme based solution so as not to 'hack' my moodle too much.

I would still be keen to see your solution.

Thx,
Simon big grin
In reply to Simon Williams

Gloscat's Moodle Theme (with rounded block boarders)

by Paul Andrews -

Ok - basically we added code to 2 functions in Weblib - if you want to send me your weblib.php we can add the code for you?

Once it's been added I'll you'll be able to use the attached theme.

Changes made to weblib

Our main programmer Dan Clarke added code to 2 ftns in weblib.php in order to get the rounded blocks - below I'll show the functions in full.


function print_side_block($heading='', $content='', $list=NULL, $icons=NULL, $footer='', $attributes = array()) {

    print_side_block_start($heading, $attributes);

    if ($content) {
        echo $content;
        if ($footer) {
            echo '<div class="footer">'. $footer .'</div>';
        }
    } else {
        if ($list) {
            $row = 0;
            echo '<table class="list">';
            foreach ($list as $key => $string) {
                echo '<tr class="r'.$row.'">';
                if ($icons) {
                    echo '<td class="c0" valign="top" width="16">'. $icons[$key] .'</td>';
                }
                echo '<td class="c1" valign="top">'. $string .'</td>';
                echo '</tr>';
                $row = $row ? 0:1;
            }
            echo '</table>';
        }
        if ($footer) {
            echo '<div class="footer">'. $footer .'</div>';
        }

    }

    print_side_block_end($attributes);
}

/**
 * Starts a nice side block with an optional header.
 *
 * @param string $heading ?
 * @param array $attributes ?
 * @todo Finish documenting this function
 */
function print_side_block_start($heading='', $attributes = array()) {

    global $CFG;

    // If there are no special attributes, give a default CSS class
    if (empty($attributes) || !is_array($attributes)) {
        $attributes = array('class' => 'sideblock');

    } else if(!isset($attributes['class'])) {
        $attributes['class'] = 'sideblock';

    } else if(!strpos($attributes['class'], 'sideblock')) {
        $attributes['class'] .= ' sideblock';
    }

    // OK, the class is surely there and in addition to anything
    // else, it's tagged as a sideblock

    /*

    // IE misery: if I do it this way, blocks which start hidden cannot be "unhidden"

    // If there is a cookie to hide this thing, start it hidden
    if (!empty($attributes['id']) && isset($_COOKIE['hide:'.$attributes['id']])) {
        $attributes['class'] = 'hidden '.$attributes['class'];
    }
    */

    $attrtext = '';
    foreach ($attributes as $attr => $val) {
        $attrtext .= ' '.$attr.'="'.$val.'"';
    }

    echo '<div '.$attrtext.'>';
  
 $themename = current_theme();
 if (strstr($themename, 'gloscat'))
  $isgloscat = true;
 else
  $isgloscat = false;

 if ($isgloscat)
 {
  echo '<table width="100%" cellspacing="0" cellpadding="0">
    <tr height="30">
    <td><img src="'."$CFG->wwwroot/theme/$themename".'/frametopleft.gif"></td>
    <td background="'."$CFG->wwwroot/theme/$themename".'/frametopgradiant.gif" width="100%" height="30" style="font-size: 10pt; font-weight: bold;">';
  
  if ($heading)
   echo $heading;
  
  echo '</td>
    <td><a href="#" onclick="elementToggleHide(this, true, function(el) {return findParentNode(el, 'DIV', 'sideblock'); } ); return false;"><img src="'."$CFG->wwwroot/theme/$themename".'/close.gif"></td>
    </tr>
    </table>';
 }
 else
 {
     if ($heading) {
         echo '<div class="header">'.$heading.'</div>';
  }
    }

 echo '<div class="content">';
 if ($isgloscat)
 {
  echo '<table width="100%" height="100%" cellspacing="0" cellpadding="0">
  <tr>
   <td style="background-image: url('."$CFG->wwwroot/theme/$themename".'/leftborder.gif); background-repeat: repeat-y;"><img src="'."$CFG->wwwroot/theme/$themename".'/leftborder.gif"></td><td width="100%">';
 }
       
}


Again if you send me your web lib I can add the code in for you if you like. smile

In reply to Paul Andrews

Re: Show # Users & # (Non hidden) Courses.

by Paul Andrews -
Here it is.

If anyone out there fancies modding this to include # Logins today then that would be great - need to run query on the logs table but the unix timestamps threw me a little! shy


In reply to Paul Andrews

Re: Show # Users & # (Non hidden) Courses.

by Steve Hyndman -

Thanks for this block Paul. After seeing your block, I wanted to show this information on my site, but didn't really want a separate block for it, so I looked at your code in the block and experimented with printing this information in my footer and header. I decided to put it in my site header. I've tried it in IE and Firefox and it seems to display correctly. I'm using the college15 theme from ballisticlearning.

I'm sure there is a much better way to code this, but it seems to work...you can see it here: www.ekuprofessor.com  Here is relevant part of the header code if anyone else is interested in displaying it outside of a block.


<?php if ($home) {  // This is what gets printed on the home page only 
?>
    <div id="header-home">
        <div class="headermain">
          <table width="100%" border="0" cellpadding="0" cellspacing="0" background="<?php echo "$CFG->wwwroot/theme/$CFG->theme" ?>/campus_blue_02.gif">
  <tr>
    <td width="4%" scope="row"><img src='<?php echo "$CFG->wwwroot/theme/$CFG->theme" ?>/campus_blue_01.gif' /></td>
    <td width="94%" align="center" class="headermenu">
    <p align="right"><font size="2" color="#FFFFFF">Number of Courses: <?php echo count_records('course','visible',1) ?> || Number of Registered Users: <?php echo count_records('user','deleted',0,'confirmed',1) ?>
      <br /></font>
      <br />
      <br />
      <?php echo $menu ?>
      </td>
    <td width="2%" align="center" valign="top">
      &nbsp;</td>
  </tr>
</table>

In reply to Steve Hyndman

Re: Show # Users & # (Non hidden) Courses.

by Kevin Linna -

Steve,

New to Moodle and I have looked over this post and am interested in doing much of the same as you did here.  I would just simply like to be able to grab some of the variables and display them in a php document that is linked as a reference.  when user clicks on the page, I would like to be able to display the following:

username, first name, last name, current class enrolled in

Is there a way to do this without creating a block...I would rather just use some loose php code.

Thanks,

Kevin Linna

In reply to Kevin Linna

Re: Show # Users & # (Non hidden) Courses.

by Steve Hyndman -

Kevin,

I'm sure that wouldn't be too difficult to do, but most of the information you are wanting to display is already available to the user via the profile (with the exception of the username).

When a user logs in and enters a course, if they click on their name (usually displayed at the top/right where it reads "You are logged in as NAME") then they will see all the classes they are enrolled in. Of course, if they click on the edit tab, then they will see their username as well....unless you are using some sort of external authentication.

I'm not sure I would want to do a hack that shows the username unless I was confident that it didn't result in a security issue. I consider the username to be 1/2 of a users security...the other half is the password.

If you wanted, you could enter a course, click on your name like described above, copy the url that is displayed in your browser address bar, then create a resource that links to that url anywhere in your course. Then when a user logs in and enters the course, they could simply click on that resource link to display their profile information.

Steve

In reply to Steve Hyndman

Re: Show # Users & # (Non hidden) Courses.

by Kevin Linna -

I understand where you are coming from...What I am looking to do is this:

I built a PHP data entry form and have it included as a resourse of the course.  When a user uses this form, fills in data and submits.  I want to include their username, firstname, lastname, and email, with the data submission as locked or hidden fields.  Since this form is a resourse and NOT part of the moodle application, I don't know how to grab the variables username, firstname, lastname and email and include them into my form.

Hopefully this clears up why I am looking to do it.

Kevin-

In reply to Kevin Linna

Re: Show # Users & # (Non hidden) Courses.

by Steve Hyndman -

I see...I'm looking to do something like that as well to allow professors to evaluate eportfolios built in Moodle, but haven't worked on that part yet. Since I haven't tried doing it yet, I can't tell you how to do it...I'm one of those "just in time learners"...learn it when I need it smile

I'm sure someone in these forums could tell you how to do this...identifying the variables to pull that information from won't be difficult...having your form recognize who is logged in and filling out the form so you can pull that persons information will be the tricky part.

Moodle 1.6 has a database module built in that should make this pretty easy once it's complete...hopefully.

Steve 

In reply to Steve Hyndman

Re: Show # Users & # (Non hidden) Courses.

by Paul Andrews -
Hello - I've updated the block so it now shows # logins today.

You can see it in action here.

If you want the mod let me know - it will require you to input the database connection settings of your mySQL server - it's a bit of a rough hack.

thoughtful




In reply to Paul Andrews

Re: Show # Users & # (Non hidden) Courses - Updated.

by Paul Andrews -
Hello - I've updated the Live stats block so it's easy to install if you want # Logins today - just unzip the folder into your blocks dir.

You can see it in action here.

smile
In reply to Paul Andrews

Re: Show # Users & # (Non hidden) Courses - Updated.

by Just H -
Hi Paul

Nice block and nice looking site.

FYI though, thought I'd let you know about a layout "problem" on your front page (see below).

I'm running Firefox 1.5.0.1 at a resolution of 1400 x 1050.

Regards
H

Attachment GloscatVLE.jpg
In reply to Just H

Re: Show # Users & # (Non hidden) Courses - Updated.

by Paul Andrews -
Cheers!

Yeah - that happens sometimes - if you hit F5 it shoul sort itself out.

But let me know if it's still borked after the refresh.

big grin

In reply to Paul Andrews

Re: Show # Users & # (Non hidden) Courses - Updated.

by Just H -
Hi Paul

No luck, forced a refresh a few times, wandered around a bit, refreshed a few more times . . . text still too big.

Still a very nice site though!

Later
H
In reply to Paul Andrews

Re: Show # Users & # (Non hidden) Courses - Updated.

by Mark Little -
Hi,

I have added this block to our site and I was wondering whether I could change the coding so that it would show how many people logged in yesterday and the day before that too.

Any ideas...

Thanks