New block - online user with Google Map

New block - online user with Google Map

by Alex Little -
Number of replies: 86
I've just posted a new block (onlien_users_map) up to Moodle contrib which displays the online users on a Google map (rather than a straight list) - you can download from: http://moodle.org/mod/data/view.php?d=13&rid=890

All comments/feedback/suggestions welcome smile

Alex
Average of ratings: -
In reply to Alex Little

Re: New block - online user with Google Map

by Chad Outten -
Hi Alex, thanks for sharing your work. what version(s) of moodle is the block compatible with?

I was able to locate the block in contrib but it is not (yet) accessible from your link above > i'm presuming it requires approval before becoming available in moodle mod & plugins database.

sort of along the same lines, can you pls tell us where we can access OU plugins, updates for compendium & MSG? i couldn't find these in cvs contrib or moodle mod, plugins db.

cheers, Chad big grin
In reply to Chad Outten

Re: New block - online user with Google Map

by Alex Little -
Hi Chad, apologies for the delay getting back to you - I've been away on holiday the last 2 weeks.

The block needs at least Moodle 1.8 and should be available from the link: http://moodle.org/mod/data/view.php?d=13&rid=890

As for the other OU plugins, MSG & Compendium, as they existed as seperate projects before being integrated into Moodle (and can be used independently from Moodle), they can be obtained from their own websites:

MSG: http://kmi.open.ac.uk/technologies/msg/ (see the developer section for downloading and installing on your own servers)

Compendium: http://www.compendiuminstitute.org/

Hope that helps,
Alex
In reply to Alex Little

Re: New block - online user with Google Map

by Alex Little -
A few people have contacted me with problems they've had getting this block to work, so here's a list of things to check if your installation isn't working...
  1. Version of Moodle - 1.8+ is required
  2. Database table - when the block is installed is should create a new table in your Moodle database called prefix_block_online_users_map_coords
  3. Google API key - you need to register for a Google Maps API key (see: http://www.google.com/apis/maps/signup.html). Once you have the key this needs to be entered into the block settings. Note that the key should be registered for the root of your Moodle installation
  4. Block table - check that in the table prefix_block, the entry for "online_users_map" has a non zero entry in the cron field
  5. Proxy server - if your Moodle server requires a proxy to access the internet, then the proxy settings need to be entered in Moodle -> Admin -> Server -> HTTP
  6. Cron - check that your cron is running regularly
If it is all set up and running ok, then after cron has run, entries for users locations should appear in the prefix_block_online_users_map_coords table.

Hopefully this checklist should help solve some of the problems, but if you're still stuck then please post a message here - or email me smile

Alex
In reply to Alex Little

Re: New block - online user with Google Map

by Chad Outten -
Thanks for the info, Alex. Time to play. You guys rock!

Cheers, Chad big grin
In reply to Chad Outten

Re: New block - online user with Google Map

by Alison Wright -
Hi there

This block looks great.

I'm having a few difficulties though. The map loads but no green pins seem to appear for my users.

I've got Moodle 1.8+, php 5 and I've set the google API key relative to the root of my moodle install.

I have noticed that the coordinates don't seem to write themselves to the table in the database. Any ideas?

Would love to get this working.
Ali
In reply to Alison Wright

Re: New block - online user with Google Map

by Alex Little -
Hi Ali,

There are probably a couple of things to check - when your cron task runs, does it generate any errors whien it gets to the online_users_map_block? If so please can you let me know what the errors are.

The other problem might be that you need to set up the proxy server for your Moodle server to access the interenet - in whch case you'll need to add the proxy setting in the Moodle admin pages (under Moodle -> Admin -> Server -> HTTP).

Hope that helps.
Alex
In reply to Alex Little

Re: New block - online user with Google Map

by Tieku Bortei-Doku -

I am running Moodle cron for a windows server. Where do I look up the error messages?

Tieku

In reply to Alison Wright

Re: New block - online user with Google Map

by Fernando Oliveira -
Picture of Plugin developers

I'm having a similar problem.  Here's a copy of an error message that shows up in the cron:

<!--StartFragment-->Processing cron function for online_users_map....<br />
<b>Fatal error</b>:  Call to undefined function simplexml_load_string() in <b>/home/g8/public_html/g8moodle1/blocks/online_users_map/lib.php</b> on line <b>47</b><br />

BTW, the server is running PHP 5.2.3

Thanks,

Fernando

In reply to Fernando Oliveira

Re: New block - online user with Google Map

by Alex Little -
Hi Fernando,

It looks like the PHP that you're running doesn't have the SimpleXML extension running. Although it's enabled by default, perhaps yours has been turned off for some reason? You can check if that's the problem by running phpinfo() to find if it's running or not.

Hope that helps, and maybe this is the problem with others who are having the same issue?
Alex
In reply to Alex Little

Re: New block - online user with Google Map

by Fernando Oliveira -
Picture of Plugin developers

Thanks Alex,

The SimpleXML extention took care of the cron errors... but I still can't seem to get it working. I'm wondering... virtually all of the communities listing in our Moodle installation are small remote Aboriginal communities in Northern Canada. As far as I can tell, these communties seem to be listed in geonames.org but I noticed other communties often share the same name.

For example: "Poplar Hill" First Nation is listed here in 4 provinces:    http://www.geonames.org/search.html?q=Poplar+Hill&country=CA

 Since the profiles don't use any state/province field, how would this mod handle this location? Would it just use the first one on the list?

Fernando

In reply to Fernando Oliveira

version.php

by Jürgen Heym -

Hello Fernando,

I tried to install the online users map and it seems that the file version.php is not in the package. Isn't it?

Would be glad if you could add version.php ...

Thanks

Juergen

In reply to Jürgen Heym

Re: version.php

by Alex Little -
Hi Jürgen,
No, there isn't a version.php file in the online_users_map code - this is because it's a Moodle block rather than a Mooodle module and as far as I can tell only the modules have version.php files. The version information for the block is in the init() function in the block class.

Hope that helps.
Alex
In reply to Fernando Oliveira

Re: New block - online user with Google Map

by Alex Little -
Hi Fernando,

When you say it's still not working is this becuase of the location problem you mention or is there something else (eg are the locations not getting into the database)?

For the locations, at the moment if there were more than one match, then yes it would just take the first one. Not really ideal I know. A possible way of getting around this might be to specify "Poplar Hill, Ontario" but there could be problems doing this as Moodle (I think) only accepts up to 20 characters in the town/city field, so even the short example above would only just fit. I guess the real way to fix it is to allow people to amend their location in a more flexible/granular level - but that'll have to wait till I've got some more time - unless omeone else wants to take it on?!

HTH,
Alex
In reply to Alex Little

Re: New block - online user with Google Map

by Monico Briseño -
Hi, Alex. Great job, congratulations. I verified your checklist block and it is running properly. I attached the image.

I'm running Moodle 1.8.2 on Mac server.


Cheers
Attachment googlemap.jpg
In reply to Alex Little

Re: New block - online user with Google Map

by Ben Steeples -
Is it easy to show a specific area of the world, rather than the whole globe?

All our users are UK based, so it's likely that all the indicators would be grouped together, unless we pre-zoomed the map/.

Thanks.
In reply to Ben Steeples

Re: New block - online user with Google Map

by Alex Little -
Hi Ben,

Yes - it should be easy enough to do & will be easier when I get around to making these block settings rather than hard coded... but until I get that done you can just edit online_users_map.php line 61:

map.setCenter(new GLatLng(17.383,11.183), 0);

Change the lat/lng to be whereever you'd like the map centred and change the 0 to be the Google maps zoom level (can be from 0 to something like 13/14) - you may just want to have a play with the numbers to get it displaying how you like.

Hope that helps smile

Alex
In reply to Alex Little

Re: New block - online user with Google Map

by P Keyse -
Hi Alex,

I'm not certain if it's a problem at my end but when I attempt to download this tasty block from http://moodle.org/mod/data/view.php?d=13&rid=890 I get these errors.

Warning: main(wp-includes/functions-compat.php): failed to open stream: No such file or directory in /web/kmi.open.ac.uk/people/alex/download.php on line 22

Fatal error: main(): Failed opening required 'wp-includes/functions-compat.php' (include_path='.:/usr/share/pear') in /web/kmi.open.ac.uk/people/alex/download.php on line 22

(weep)
In reply to P Keyse

Re: New block - online user with Google Map

by Alex Little -
Hi Peter

It's my fault - I 'upgraded' my website last week and have had a few teething issues to get sorted out wink

The link (http://kmi.open.ac.uk/people/alex/download.php?file=online_users_map_latest.zip) to download the block code should now be working ok...

Apologies for this (and to anyone else who's had the same problem!),

Alex
In reply to Alex Little

Re: New block - online user with Google Map

by unformatted :) -
I´m running moodle 1.9

I can see the map centered in my country, but with no pins!
The chron job has run beacuse I see some notifications mail from the moodle

I don´t know if I need to set up the proxy and what I have to put there...


In reply to unformatted :)

Re: New block - online user with Google Map

by Alex Little -
Hi,

There are several things that could be going wrong. What's probably worth doing is to run cron.php directly in your browser - so that you can see any error messages it may be generating.

After cron.php has run you should see records entered in the (mdl_)_block_online_users_map table. If there are no errors displaying when you run cron.php, but there aren't any records in the database either, then it's likely you need the proxy settting (it's set in Moodle admin pages -> Server -> HTTP). What this actually is depends on your organisation - your sys admin or IT support should be able to tell you what the setting should be.

You may also want to have a look at the comments on this page as it answers some of the common problems.

HTH,
Alex


In reply to Alex Little

Re: New block - online user with Google Map

by unformatted :) -
Hi

On the cron job there are nothing about block_online_users_map table.

My host provider says that is not necessary nothing in proxy


What else can I try?

thanks
In reply to unformatted :)

Re: New block - online user with Google Map

by Alex Little -
Hi,
It ought to say something about the online-users-block, if it's sucessfully run it ought to report:
"Processing cron function for online_users_map....done."
You'll need to bear in mind that the online_users_map code will only run once an hour - so it would appear once and then if you just refresh the page it won't run (so you won't get any messages). To force the code to run, just update the mdl_block and set the lastcron to 0 for the online_users_map and then re-run the cron.

If the cron is running sucessfully, but you're still not getting any users appearing in the mdl_block_online_users_map then you may need to look at what is actually being passed to the geocoding service - you can either do this by running a packet sniffer on your server (I suspect your host wouldn't allow you to do this) or add some debug code to the block code (in the update_users_locations() function).

HTH,
Alex
In reply to Alex Little

Re: New block - online user with Google Map

by Alex Little -
Hi,

I've just updated the block so you can opt to show debugging in the cron script. You'd need to download and install the latest verison of the block (or get it from Moodle Contrib) and then go to the block settings to turn debug on.

Then when you run cron it will show you which users it's updated the location for - so should help in fixing any problems.
Alex
In reply to Alex Little

Re: New block - online user with Google Map

by unformatted :) -
Thanks!

with debug on says for all users this:

 But all the useres have country and city. It's a mandatory field. Bu I have a little problem: I choose the default country, but in registration don´t show that country I selected. I post that here: http://moodle.org/mod/forum/discuss.php?d=83198#p385560 But no solution for now. I don´t know if that is related with my problem with location not found... thanks :) 

In reply to unformatted :)

Re: New block - online user with Google Map

by Alex Little -
I think it's quite likely to be related. You need to find what it's actually passing as the country & city - I've updated the block code again (get from Moodle Contrib or download) so that it includes this info in the debug output.

Even if the fields aren't empty, it doesn't necessarily mean that the location will be found - it depends on exactly what has been entered and whether the geocoding service (http://www.geonames.org) has data for this location.

HTH,
Alex


In reply to Alex Little

Re: New block - online user with Google Map

by unformatted :) -
Thanks again smile

now I have for all users this kind:

Finding location (porto,PT) for utilizador 1...location not found



But he map is still without pins :(

In reply to unformatted :)

Re: New block - online user with Google Map

by Alex Little -
I suspect the problem is that the simplexml_load_string function is failing then (line 54 in lib.php) - can you confirm which verison of PHP you're using?

You can check whether this is the case by slightly editing lib.php... replace line 54:

if($xml = simplexml_load_string($response,'',LIBXML_NOERROR)){

with these 2 lines:

echo "\n".$response;
if($xml = simplexml_load_string($response)){

and then run cron.php. You should see the XML returned from call to the geocoding service appear in the output. The output for each location should look something like:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<geonames style="MEDIUM">
<totalResultsCount>1496</totalResultsCount>
<geoname>
<name>Porto</name>
<lat>41.15</lat>
<lng>-8.6166667</lng>
<geonameId>2735943</geonameId>
<countryCode>PT</countryCode>
<countryName>Portugal</countryName>
<fcl>P</fcl>
<fcode>PPLA</fcode>
</geoname>
</geonames>
HTH,
Alex
In reply to Alex Little

Re: New block - online user with Google Map

by unformatted :) -
That works!
Many thanks smile

very nice block
In reply to unformatted :)

Re: New block - online user with Google Map

by Alex Little -
Good to know it's working now!

Did you figure out what the actual problem was? As would be useful for me to know in case others come across a similar issue.
Cheers
Alex
In reply to Alex Little

Re: New block - online user with Google Map

by unformatted :) -
Hi

I don´t know What was the problem...
I have moodle 1.9 with some blocks and filters installed and that problem with default coutry not working. But when creating an account in admin panel the default contry works
In reply to unformatted :)

Re: New block - online user with Google Map

by Vitor Rocio -
Hi all,

I had the same problem. Cron gives this warning:

PHP Warning: simplexml_load_string() expects parameter 2 to be a class name derived from SimpleXMLElement, '' given in /var/www/html/moodle/blocks/online_users_map/lib.php on line 54

Replacing line 54 with

if($xml = simplexml_load_string($response,SimpleXMLObject,LIBXML_NOERROR)){

works for me (Moodle 1.9; php 5.2.4; SimpleXML $Revision: 1.151.2.22.2.35 $)
In reply to Alex Little

Re: New block - online user with Google Map

by Hugh Morrow -
the code change at line 54 worked for me too (php 5.2)

thanks for the block
In reply to Alex Little

Re: New block - online user with Google Map

by John Fitchett -

Hi Alex

I have checked my PHPinfo  (version 5.2.5) and it says:

SimpleXML

Simplexml support enabled
Revision $Revision: 1.151.2.22.2.35 $
Schema support enabled

(so I guess Simplexml is running?)

I have also changed the lib.php file line 54 as you suggested.

I now get the following error in my chron:

Updating location for Admin User...
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<geonames style="MEDIUM">
<totalResultsCount>142</totalResultsCount>
<geoname>
<name>Sydney</name>
<lat>-33.8678499639382</lat>
<lng>151.207323074341</lng>
<geonameId>2147714</geonameId>
<countryCode>AU</countryCode>
<countryName>Australia</countryName>
<fcl>P</fcl>
<fcode>PPLA</fcode>
</geoname>
</geonames>
<br />
<b>Fatal error</b>: Call to undefined function: simplexml_load_string() in <b>/home/content/a/s/k/askjohn/html/ASKJOHNENGLISH/learn/blocks/online_users_map/lib.php</b> on line <b>53</b><br />

Needlesss to say, the online users map block still come up blank... what can i do?

Many thanks! I look forward to getting this working.

In reply to John Fitchett

Re: New block - online user with Google Map

by Alex Little -
Hi John,

hmmm... that's a bit puzzling as it looks like you have got the simplexml extension installed correctly on your PHP server. I found this forum post which might help (see reply #8) - it might be worth just popping this code at the beginning of the cron() function in blocks\online_users_map\block_online_users_maps.php just to double check that it's loading correctly.

Please let me know how you get on with this.

cheers,
Alex
In reply to Alex Little

Re: New block - online user with Google Map

by John Fitchett -

Thanks for the reply Alex! Much appreciated!

By 'popping this code at the beginning of the cron() function', do you mean the code in blocks\online_users_map\block_online_users_maps.php should be like this:

<?php

/**

* Online Users Map block - reworking of the standard Moodle online users

* block, but this displays the users on a Google map - using the location

* given in the Moodle profile.

* @author Alex Little

* @license http://www.gnu.org/copyleft/gpl.html GNU Public License

* @package block_online_users_map

*/

include_once($CFG->dirroot.'/blocks/online_users_map/lib.php');

class block_online_users_map extends block_base {

function init() {

$this->title = get_string('blockname','block_online_users_map');

$this->version = 2008030600;

$this->cron = 3600;

}

function instance_allow_config() {

return false;

}

function has_config() {

return true;

}

function get_content() {

global $USER, $CFG, $COURSE;

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

return $this->content;

}

$this->content = new stdClass;

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

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

if (empty($this->instance)) {

return $this->content;

}

//Calculate minutes

$minutes = floor(getTimeToShowUsers()/60);

$this->content->text = "<div class=\"info\">(".get_string("periodnminutes","block_online_users_map",$minutes).")</div>";

$this->content->text .= get_html_googlemap();

return $this->content;

}

 

function cron(){

 if(!extension_loaded('simplexml')
    
// Nope, not loaded
else
    
// Already been loaded ;)


if(!extension_loaded('simplexml')
{
    if(
strtoupper(substr(PHP_OS, 0, 3)) === 'WIN')
        
dl('php_simplexml.dll');
    else
        
dl('simplexml.so');
}

// NOw that it should be loaded, we'll check again:
if(extension_loaded('simplexml'))
    echo
'simpleXML was included properly!!';
else
    echo
'simpleXML still wasn't included sad';
}

update_users_locations();

return true;

}

function preferred_width(){

return 210;

}

}

?>

Many thanks for any help you may be able to give!

In reply to John Fitchett

Re: New block - online user with Google Map

by Alex Little -
Hi John,

yes - that's exactly what I meant smile

Alex
In reply to Alex Little

Re: New block - online user with Google Map

by John Fitchett -

Hi Alex

I did as you suggested and the chron now reads:

<b>Parse error</b>: parse error, unexpected T_ELSE in <b>/home/content/a/s/k/askjohn/html/ASKJOHNENGLISH/learn/blocks/online_users_map/block_online_users_map.php</b> on line <b>60</b><br />

Also the content of my page has disappeared.

You can see the page here: http://askjohnenglish.com/learn/course/view.php?id=5

I know that if I change the file back the page will return, so that is not a problem.

Is all very strange...

Any ideas?

Thanks again

John

In reply to John Fitchett

Re: New block - online user with Google Map

by Alex Little -
Just had closer look at the code on that forum posting and it seems there are couple of typos in it, so the cron function should be:

function cron(){
if(!extension_loaded('simplexml')){
if(strtoupper(substr(PHP_OS, 0, 3)) === 'WIN'){
dl('php_simplexml.dll');
} else {
dl('simplexml.so');
}
}

// Now that it should be loaded, we'll check again:
if(extension_loaded('simplexml')){
echo '<br/>simpleXML was included properly!!';
} else {
echo '<br/>simpleXML still wasn\'t included sad';
}

update_users_locations();
return true;
}

Whilst you're trying to get this to work, it's worth turning on debugging messages (go to MoodleAdmin->server-debugging and set debugging level to at least 'normal') then you ought to see error messages rather than just a blank screen wink

A
In reply to Alex Little

Re: New block - online user with Google Map

by John Fitchett -

Thank you Alex.

I have done as you said. The chron now reads:

Processing cron function for online_users_map....<br />
<b>Warning</b>: dl(): Unable to load dynamic library './simplexml.so' - ./simplexml.so: cannot open shared object file: No such file or directory in <b>/home/content/a/s/k/askjohn/html/ASKJOHNENGLISH/learn/blocks/online_users_map/block_online_users_map.php</b> on line <b>61</b><br />
<br/>simpleXML still wasn't included sad
Updating location for Admin User...
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML><HEAD><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<TITLE>ERROR: The requested URL could not be retrieved</TITLE>
<STYLE type="text/css"><!--BODY{background-color:#ffffff;font-family:verdana,sans-serif}PRE{font-family:sans-serif}--></STYLE>
</HEAD><BODY>
<H1>ERROR</H1>
<H2>The requested URL could not be retrieved</H2>
<HR noshade size="1px">
<P>
While trying to retrieve the URL:
<A HREF="http://ws.geonames.org/search?">http://ws.geonames.org/search?</A>
<P>
The following error was encountered:
<UL>
<LI>
<STRONG>
Connection to 78.46.47.166 Failed
</STRONG>
</UL>

<P>
The system returned:
<PRE><I> (110) Connection timed out</I></PRE>

<P>
The remote host or network may be down. Please try the request again.
<P>Your cache administrator is <A HREF="mailto:webmaster">webmaster</A>.

<BR clear="all">
<HR noshade size="1px">
<ADDRESS>
Generated Mon, 19 May 2008 11:38:09 GMT by wc04.shr.phx3.gdg (squid/2.6.STABLE12)
</ADDRESS>
</BODY></HTML>
<br />
<b>Fatal error</b>: Call to undefined function: simplexml_load_string() in <b>/home/content/a/s/k/askjohn/html/ASKJOHNENGLISH/learn/blocks/online_users_map/lib.php</b> on line <b>52</b><br />

Any ideas?

In reply to John Fitchett

Re: New block - online user with Google Map

by Alex Little -
Hi John,

You may need to speak to your server admin (or your hosting provider) to see if they'll activate the simplexml library for you, or give you the path to where it;s located on the server - so you can change the line dl('simplexml.so'); to point to whereever the library is on their server.

But (maybe a better alternative?) would be to look at the code Tommy Wonkium posted (scrooll a bit down the page) to be able to use this block with PHP4 - it essentially is just a replacement for the update_user_locations() function. Just note that there is a typo in this code, so the line which starts:

$response = getURLContent("city)."&country....

should read:

$response = getURLContent("
http://ws.geonames.org","/search?maxRows=1&q=".urlencode($user->city)."&country=".urlencode($user->country));

(this is mentioned on the page - but you might miss it if you don't read all the messages!)

HTH,
Alex
In reply to Alex Little

Re: New block - online user with Google Map

by John Fitchett -

Thank you Alex.

I checked with my host, who says:

'SimpleXML Library' is currently enabled. The SimpleXML library is readily accessible when using PHP5 on your hosting account. There is no need to specify a path, you can place any references to SimpleXML in your PHP5 code and it will be parsed accordingly.

I also tried the code Tommy Wonkium posted, but am still getting that error message in the cron...

Is all quite bizzare! I have every confidence that this block works... Not sure what I am doing wrong!


In reply to John Fitchett

Re: New block - online user with Google Map

by Alex Little -
hmmm... yes - quite odd! There might be something up with the simple_xml library which is why the simplexml_load_string functions isn't working. I guess you could write to check to see whether this is where the problem is.

When you try Tommy's code you can remove the edits you made to the cron() function in block_online_users_map.php and you shouldn't get the error any more. Tommy's code isn't dependent on the simpleXML library - so you shouldn;t get any errors related to that.

Alex
In reply to Alex Little

Re: New block - online user with Google Map

by John Fitchett -

Hi alex

I downloaded the block again to make sure i hadn't botched the code up. When I installed it, I got this message in my notifications:

New version of Online Users Map (online_users_map) exists


(mysql): SELECT * FROM mdl_config WHERE id = '-1'  



(mysql): INSERT INTO mdl_config ( NAME, VALUE ) VALUES ( 'block_online_users_map_centre_user', '0' )  


1062: Duplicate entry 'block_online_users_map_centre_user' for key 2

                  
Upgrading block online_users_map from 2008030600 to 2008052700 FAILED!

I then uploaded the full original new block (since you added the ability to center on the user) and still got the same error.

Thanks so much for all your help!

I now have found there are problems with my cron jobs (host problem perhaps? they are not being very helpful!) So will try and fix that, then do as you have suggested above.

In reply to John Fitchett

Re: New block - online user with Google Map

by Alex Little -
Seems like the install has got a bit mixed up (not sure why) - best thing to do would be to manually delete the records for 'block_online_users_map_centre_user' and 'block_online_users_map_centre_user_zoom' (if they exist) then visit the notifications page again.

Hopefully that should get it sorted out smile

Alex
In reply to Alex Little

Re: New block - online user with Google Map

by John Fitchett -

Thank you! that fixed the block error message.

I also reinstalled the latest version of the block. This had the sample simplexml error in the cron, so I made changes to the lib.php file (only) as Tommy suggested.

The cron now reads:

Processing module function Online_Users_Map...done.

but the block still doesn't work... http://askjohnenglish.com/learn/course/view.php?id=5

(I have debugging set to 'developer' and no error messages are coming up...)

BTW the cron only read: Processing module function Online_Users_Map...done., the first time the cron ran after reinstalling the block. Thereafter it is not even mentioned in the cron. Is this normal?

Sorry for so many messages! I really appreciate all the help you have given!!


In reply to John Fitchett

Re: New block - online user with Google Map

by John Fitchett -

BTW the latest cron now reads:

Processing cron function for online_users_map....<div class="notifytiny" style="text-align:center">MySQL server has gone away<br /><br />UPDATE mdl_block SET lastcron = '1212095102' WHERE id = '47'<ul style="text-align:left"><li>line 1328 of lib/dmllib.php: call to debugging()</li><li>line 1254 of lib/dmllib.php: call to set_field_select()</li><li>line 149 of admin/cron.php: call to set_field()</li></ul></div>
Error: could not update timestamp for online_users_map
done.

In reply to John Fitchett

Re: New block - online user with Google Map

by Alex Little -
Hi John,

I'm not sure what's up with the "MySQL server has gone away" message - that seems like a problem with the connection between your PHP and MySQL rather than this block (that error message is a new one on me). So unsure where to start with that one

Going back to the cron... the cron for this block will only run once an hour - but you can reset the lastcron time the mdl_block table or change the cron value in this table to make it run more regularly.

To figure out whats going wrong with the cron - you could put some debugging code in the upadte_users_location function just to output where it's got up to.

I'm going to look at updating the block so it detects if people haven't got simplexml or running PHP4 and use the appropriate function .

Alex


In reply to Alex Little

Re: New block - online user with Google Map

by John Fitchett -
Just want to thank you for all your help!
In reply to John Fitchett

Re: New block - online user with Google Map

by Alex Little -
No worries John.

Have you got it up and running now?

Alex
In reply to Alex Little

Re: New block - online user with Google Map

by John Fitchett -

Actually, I am having some trouble with my host, so have been focusing on that instead. I suspect that is the cause of my troubles...

Many thanks for all your time!

In reply to Alex Little

Re: New block - online user with Google Map

by Ken Gibson -

Alex,

Installed the block, database tables written without issue. Cron has run successfully, but when I enable the block on our site's homepage, the block itself is blank (other than "online users last 5 minutes" ) There is no map image or pins displayed....just whitespace.

Any suggestions?

Ken  

In reply to Ken Gibson

Re: New block - online user with Google Map

by Alex Little -
Hi Ken,

Not really sure what the problem might be, can you check that the Google API key is correct (in the block settings) - though usually if this is wrong (and so the map doesn't display) a warning message about an incorrect Google API key usually pops up. Alternatively can you send me a link to your site as I might be able to see whats up from looking at the html of you page.

Cheers,

Alex
In reply to Alex Little

Re: New block - online user with Google Map

by Ken Gibson -

Hey Alex,

The "blank block" can be seen at www.justicedegree.org (right hand column) - just turned it back on so that you can view .  The API key is correct in settings, and like I mentioned earlier the cron appears to have run fine.  Question (excuse the ignorance here) - could this somehow be related to how the student's location information (city,state) in their profile is formatted?  We have a number of students with city,states that are listed as "Please Update" - as we encourage students to update this information on their own.  Just a thought.

Thanks for the help.

Ken        

In reply to Alex Little

Re: New block - online user with Google Map

by Ken Gibson -

Alex,

Think I found the issue (although don't know how to fix),  Load page in firefox and get this error on the bottom of the page:

missing ) after argument list
map.setCenter(new GLatLng(39.5N,119.8W), 50);\n

Looks like I need to add a ) in the php code somewhere.  This error doesn't show itself in IE

Ken

In reply to Ken Gibson

Re: New block - online user with Google Map

by Alex Little -
Hi Ken,
Yes - I can see that error too - fortunately it's very easy to fix wink Just go to the online_user_map block settings page and remove the 'N' and 'W' from the centre lat/lng - as GLatLng takes simple numeric values as arguments.

For the users who have 'Please Update' as their location, it'll just mean that they won't appear on the map, until they update their location to a real one and cron has run.

Hope that helps smile
Alex
In reply to Alex Little

Re: New block - online user with Google Map

by Ken Gibson -

Alex,
ahh....yee old user error smile
Thanks for the input...map is now working like a charm!

Ken

In reply to Alex Little

Re: New block - online user with Google Map

by Ken Gibson -

Alex,

New question (problem?).
It appears that we need users to input their location data in their profile in the following format: City,State.  Messing around a bit, I updated mine profile as: City/State.  The result did not work obviously (I am floating off the coast of Africa on the map smile ) .

I then went in and update my profile to the correct format and have re-run cron, but the location database appears not to be updating (not seeing it in cron).  Could this be a function of the cron only running X percentage of all cron tasks each run (moodle default to save horsepower) or am i missing something?

As always, thanks for the help!

Ken      

In reply to Ken Gibson

Re: New block - online user with Google Map

by Ken Gibson -

Alex,

Ignore above ^^^^^^^^^^^^^^^^^, as the cron ran again and things have been updated properly.

Ken

In reply to Ken Gibson

Re: New block - online user with Google Map

by Alex Little -
Hi Ken,

Glad to hear it's working for you now smile
For info, the cron for the block will only run once an hour (exactly for the performance reasons you mention) - if you want to change this to run more ro less regularly, then you can edit the 'cron' field for the the online_users_map record in mdl_block table.
Alex
In reply to Alex Little

Re: New block - online user with Google Map

by Nigel Osborne -

Alex - a great block, and very easy to install. I had only a couple of issues to deal with which I thought might be worth considereing as mods:

1 - GoogleMaps now include a Map Data copyright statement on the map which overflows to the left of the small map in this block. It is sort of corrected by adding 'overflow:hidden' to the DIV tag in lib.php (see my example here). I'm sure just cutting it off like this might upset GMs Terms of Use, but I don't see an alternative.

2 - I have a wider than standard right column in my theme, and so wanted to make the map slightly larger. Easy to do in lib.php, but perhaps the map dimension could either by a variable based on the column width (perhaps), or a config option? My prefernce would be the former.

Image1.jpg

In reply to Nigel Osborne

Re: New block - online user with Google Map

by Alex Little -
Cheers Nigel, I'd noticed the copyright statement overflowing too sometimes (it depends where your map is centred). I think I can get away with your overflow:hidden trick - I'm sure Google could figure a way to wrap the text !! wink

Also, should be easy enough to make the map fit the column width - so will get that done too.

Alex
In reply to Nigel Osborne

Re: New block - online user with Google Map

by Alex Little -
I've made these changes now - for 2 the map width is set to be 100% wdith of it's parent (the block) so whatever width the block, the map will scale to fit the available space.

I've also implemented another change - and that's the option to show offline users too - more info

Alex
In reply to Alex Little

Re: New block - online user with Google Map

by Nigel Singleton -
I've reinstalled this on Moodle 1.9 without attending to the where to centre the blocks (do I need to do this?) but I get this error message even with my Google API input.

host ws.geonames.org: 111: Connection refuse

have you seen this before. Shall I see if it works with a new API?

Thanks.

In reply to Nigel Singleton

Re: New block - online user with Google Map

by Alex Little -
Hi Nigel,

That error message won't be to do with the Google API - I think it's becuase you're moodle server needs a proxy to be able to access the web (and the geonames website which provides the geocoding of users locations). Whereabouts do you see this error? Is it when you run the moodle cron.php?

To set the proxy have a look at: http://moodle.org/mod/forum/discuss.php?d=75667#p342322

Alex
In reply to Alex Little

Re: New block - online user with Google Map

by Rad Rad -
Hi Alex,

This is a really nice block. On my Moodle plateform, I have many different regional Group (Africa, South Asia, Latin America).

So I was wondering if it could be possible to have different sitting for different group.

For example, for the Africa group, I would like to have the map "zoom" on the African continent.

Thanks!

Rad


In reply to Rad Rad

Re: New block - online user with Google Map

by Alex Little -
Cheers Rad,

At the moment it's not possible to have different settings for different groups. I think the best way around this would be to have the option to centre the map on the current users location (at a particular zoom level) - I assume this would then achieve what you're looking for? It also doesn't then have the complexity of having to set up coordinates for every group.

Alex
In reply to Alex Little

Re: New block - online user with Google Map

by Alex Little -
I've updated the block now so you have the option of setting the map to centre on the current users location.

Alex
In reply to Alex Little

Re: New block - online user with Google Map

by Ben Christopher -

Hi there,

this looks great but i'm having some basic probs uploading it. after downloading latest version, do i just upload load entire contents to my blocks directory (via cpanel)?

Thanks

ben

In reply to Ben Christopher

Re: New block - online user with Google Map

by Alex Little -
Hi Ben,

You need to create a directory in /blocks called 'online_users_map' and then put the contents of the downloaded zip into there. (Note to self: I should change the zip so it includes this directory)

Then just follow the instructions in the README.txt - please let me know if you get stuck and need any help smile

Cheers,
Alex
In reply to Alex Little

Re: New block - online user with Google Map

by Ben Christopher -

thanks alex,

maybe im just being dumb here, when i selct all downloaded files and folders and zip them and then upload zip via cpanel to blocks folder, only the files and not the directories are there. can you only zip files and then the directories and their contents are uploaded individually?

In reply to Ben Christopher

Re: New block - online user with Google Map

by Alex Little -
hmmm... it might be that when you're zipping up the folder you've not selected the option to include the directories - I think in winzip including all the dirs is optional (but ought to be on by default?). You could just upload the online_users_map zip file that you've downloaded, rather than unzipping and then rezipping? Or have I misunderstood what you're doing?

Alternatively, cpanel isn't creating the dirs correctly when you upload? I suspect this isn't the case though as you'd have had problems with other zips too.

Hope that helps,
Alex
In reply to Alex Little

Re: New block - online user with Google Map

by Ben Christopher -

OK Alex,

i finally managed to upload all files/folders. then confirmed set up of tables via notifications and added the API in block settings and then tried to add the block. i get a blank block. This is very frustarting. as you can see the online user block works just fine - do they need to be linked up maybe?

any ideas

thanks

ben

Attachment blankblock.gif
In reply to Ben Christopher

Re: New block - online user with Google Map

by Alex Little -
Hi Ben,

I think it's likely that there's a javascript error or something occuring which is preventing the map being displayed - can you see if your browser javascript console is showing any messages and what they are.

Also, if you go back to the block settings please check that an integer value (non-null) is entered in each of the centre_lat, centre_lng and init_zoom settings. For info I have mine set to 50, 1 and 3 respectively.

If it is a javascript problem then it's likely that this is also stopped your calendar showing too (your posting at: http://moodle.org/mod/forum/discuss.php?d=99784) - update just seen the screen shot you posted there and yes - it;s because you need to have values entered in the setting I mentioned above.
HTH,
Alex
In reply to Alex Little

Re: New block - online user with Google Map

by Ben Christopher -

brilliant alex, i love ya - it works! problem was with the integers. (still no calendar tho.

Thanks

ben

In reply to Alex Little

Re: New block - online user with Google Map

by Ben Christopher -

Alex - re calendar

at top of manage blocks page it says this:

Block calendar_month is not compatible with the current version of Moodle and needs to be updated by a programmer....strange

havent got access to browser javascript console as am at school...

thx

ben

In reply to Alex Little

show nick and not name and first name

by hiperion hiperion -
Hello, How can I show only the nick (username) and not the name and first name? Some people don´t like to see their personal information.
Thanks.
In reply to hiperion hiperion

Re: show nick and not name and first name

by Alex Little -
Hi,
The block uses the Moodle site policy for display of names - so you can change this by going to Moodle Admin-> Security -> Site Policies and changing the fullname format. However this doesn't seem to offer the ability to use the nickname - but it just fits with what is displayed in the rest of Moodle.

Hope that helps,

Alex
In reply to Alex Little

Re: show nick and not name and first name

by ray s. -
Hello,

Thanks Alex for sharing this block, it definitely is a great idea. I was able to successfully install this block on 1.9. I can see the map, but no nodes appear for the online users. I turned on debugging and no error appeared. I was curious if you could give some insight into the potential problem.

Regards
In reply to ray s.

Re: show nick and not name and first name

by ray s. -
I have recently installed this block on 1.9+, and while I can see the map no pins have appeared for the users. I have gone through the complete discussion from January 11, 2008 on down, making the necessary changes referred to in this discussion. I still have no pins. My chron seems to be reading the block, but it never updates the locations. Does anyone have any suggestions?

Regards
In reply to ray s.

Re: show nick and not name and first name

by ray s. -
Here is a copy of my chron

Processing cron function for online_users_map....
SimpleXML extension is loaded
There are no locations to update.done.
Finished blocks

Has anyone else seen this?

In reply to Alex Little

Re: New block - online user with Google Map

by Marty Jacobs -
Firstly, this block rocks! However, we did have a problem with it caused by the fact that some of the SQL in getusers.php was causing an invalid error message (we're using MS SQL, not MySQL).

A fellow Moodler at work (Ben) fixed the SQL by adding a GROUP BY clause to the $groupby variable (see attached getusers.php file for fix).

I also added an if statement to hide the block unless the current user is logged in (this was done for obvious privacy reasons). See below (code in bold is addition):

//Calculate minutes
$minutes = floor(getTimeToShowUsers()/60);

if (isloggedin()) {
$this->content->text = "<div class=\"info\">(".get_string("periodnminutes","block_online_users_map",$minutes).")</div>";

$this->content->text .= get_html_googlemap();

return $this->content;
}
}

Thanks again for a great block.

Marty
In reply to Alex Little

Re: New block - online user with Google Map

by Nichole Bryant -
Hello Alex,
I have to say that this is a wonderful idea! However, I was wondering if it was possible to tweak the block from displaying online users, to all users and their registered locations?

Thanks!
Nichole
In reply to Alex Little

Re: New block - online user with Google Map

by Christoffer Larsson -
Pins are not showing in the block.

The cron is returning this message when updating each user:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>Bad Gateway!</title>
<link rev="made" href="mailto:%5bno%20address%20given%5d" />
<style type="text/css"><!--/*--><![CDATA[/*><!--*/
 body { color: #000000; background-color: #FFFFFF; }
 a:link { color: #0000CC; }
 p, address {margin-left: 3em;}
 span {font-size: smaller;}
/*]]>*/--></style>
</head>

<body>
<h1>Bad Gateway!</h1>
<p>
 The proxy server received an invalid
 response from an upstream server.
</p>
<p>
If you think this is a server error, please contact
the <a href="mailto:%5bno%20address%20given%5d">webmaster</a>.
</p>
<h2>Error 502</h2>
<address>
 <a href="/">ws.geonames.org</a><br />
 <span>Mon Dec 14 10:47:10 2009<br />
 Apache/2.2.10 (Linux/SUSE)</span>
</address>
</body>
</html>
I'm using Siteground to host Moodle in. Anybody else got this problem?
In reply to Christoffer Larsson

Re: New block - online user with Google Map

by Raul Mellado -
Yepp, same problem for me. No clue about how to solve it...
In reply to Raul Mellado

Re: New block - online user with Google Map

by Larry Elchuck -
Same problem ... using GoDaddy and Moodle 1.9.7 (Build: 20091126)