Admin notification of Moodle badge award

One of the Moodle platforms I have been working on was set up by a previous administrator who is no longer acting as the administrator (but is still a staff member. The site role of administrator has been updated to the new administrator which appears to be working as expected except in one area – badges. The previous administrator set up some great site badges during their time which are being used for chemical management inductions and are still required. The catch is, the old admin is still getting the notification when a badge is awarded, not the new administrator.

I’ve done some digging and poking and worked out why this is happening and how to fix it. It’s an easy fix but it does require access to the Moodle database.

The clue that lead to the answer was in the badge settings:

So for what ever reason, a site level badge is linked to the creator, not the main administrator. The only way I have worked out how to change this (without creating a new badge) is to edit the Moodle database directly.

To update the badge creator, open the badge (or mdl_badge) table and update the uesrcreated record to the use.id of the person requiring the notification; e.g. the current administrator.

Moodle site home and dashboard course image

It’s been a while since I posted but that’s because I’ve been out of the Moodle loop.  Finally have an opportunity to be part of it again so I’ve jumped in and installed the latest version of Moodle (currently 3.5).  I’ve been itching to get using the Boost theme and so far I love it.

One of the feature I like is having an course image that displays on the site home page and the dashboard but it came with an annoyance – making it look good in both, especially if you are using an icon style image.

I wanted a round icon as it ties in with other imagery on my courses and with badges. The problem with using a round image (well, effectively a square) is that on the dashboard the image is stretched out to 433 pixels by 150.  This chops the height down to almost a third (doesn’t look great) but if you place your round icon on an image of those dimensions then, when viewed on the site home page, it’s resized down to something tiny as it has a maximum width of 100 pixels. I’ve found a workaround that works for me so I thought I’d share.

I went with a canvas size for my image of 433×150 pixels to suit the dashboard image. I placed the my circular icon 10 pixels down and 20 pixels in, thus lining it up with the progress chart and not have it squashed up against the top border, making the icon 140×140 pixels.  I was going to place it 20 pixels down and 130 pixels square but I decided it was getting on the too small size when viewed on the site home page.

I then added a small snippet to the raw SCSS section (Site Administration > Appearance > Themes > Boost > Advanced settings):

.coursebox .content .courseimage img {
max-width: none;
}

This kept the height restriction on the site home page but allowing the image to be wider.

It gave me the following results which was a good compromise for an image that is used very differently in two places.

Site home:

icon-sitehome

Dashbaord:

icon_dashbaord

Ideally it would be better if the image was handled the same way on each page or two images could be used.  I sure this is currently not possible (I searched and found nothing) but please let me know if I am wrong.

 

Missing the move icon on Mahara 16.04?

Not sure if it’s a bug or a feature but my user-testing revealed people were not a fan of the select icon showing when clicking and drag files around the content > files section of Mahara.

I’ve registered the ‘bug’ on the Mahara tracker but in the mean time we’re testing a quick fix into our style sheet.

.icon-drag {
  cursor: move;
}

We’re running Mahara on Windows with IIS 8.5.  We tested for the missing move cursor on four different browsers (IE10 and 11, Firefox, Chrome and Safari) and two operating systems (Windows 7, Windows 8 and Mac OS El Capitan).

Update: this has now been fixed with the next update.

MNet on Windows

This set up ended up not being too much of a trial as it often can be when making anything Moodle or Mahara related work on Windows, just a couple of things to be aware of.

1. Check the details in your database are correct, especially if you had previously set up the site on another server and migrated it.  Look at the first entry in the mnet_host table.  If it has a local address (http://localhost/moodle), update it to your external domain name, such as https://yourmoodlesite.ac.nz.  The IP address stays local.

2.  Check there is a public key with the same record or check from within your site.  You’ll find it at http://yourmoodlesite.ac.nz/admin/mnet/index.php and http://yourmoodlesite.ac.nz/mnet/publickey.php.  If the key is missing as mine was, the first page will be show no key and an expiry of 1970 and the second page will just be blank.

This is a Windows/Moodle not knowing how to play nice issue.  The public key was automatically created in Mahara without any additional work but not for Moodle.  The simple fix was just a matter of pointing Moodle in the direction of your Open SSL configuration file from within your config file, in my example:

$CFG->opensslcnf='C:\Program Files (x86)\PHP\v5.5\extras\ssl\openssl.cnf';

Everything else was straightforward, pretty much following the instructions on the Moodle docs.

 

PHP upload temp files not deleting

As you may be aware my blog primarily deals with running Mahara and Moodle on a Windows system and the solutions for challenges I have encountered.  Today’s problem had been happening for a while but I didn’t realised there was a problem for a long while or what was causing it.

The symptoms

My server’s C drive was slowly filling up, in fact I worked out once I  had found the problem and its cause there was approximately 35GB of unwanted data on the drive.  I knew it wasn’t the web root, backups or Moodle and Mahara data as these are located on other drives.  Basically the C drive is only for running Windows server and associated applications.

I’m not sure if this stuff is common knowledge to others but I really had no idea what was causing the excessive drive usage.  I cleaned out my SAML logs (there’s a whole ‘nother story) but that made little difference. I did a search of the drive for ‘gigantic’ (greater than 128MB) and found the C:/Windows/Temp drive had thousands of temp files of varying size.  These all had file names starting with php…

The cause

Turns out these files are uploaded in the Windows Temp directory (as per the settings in my php.ini file) until they are fully uploaded then copied to their required location.  Once the process is complete the temporary file is deleted; however, in my case they were not and an unnecessary copy of every file uploaded remained in the temp directory.

The solution

I did some research into the problem and found very little in the way of solutions.  some of the solutions I tested didn’t work.  I realised it was a permissions problem the solutions were suggesting changed to accounts that made no difference.  I worked out the correct account and the lowest amount of permissions required to fix the problem.

So it’s an easy fix, just change your IIS_IUSRS permissions to modify and below for your temp drive.

temp files

 

temp files2
Don’t forget to delete those old temp files

 

Moodle users with upper case letters

A quick one this time.  Unfortunately our AD is not as consistent as it could be with account creation and we get the odd username containing a capital letter or two (BlogsJ rather than blogsj).  This works fine for logging in etc. but bulk user uploads of cohorts will fall over if the usernames in the CVS file has any upper case letters or it trying to match with users already in Moodle with upper case letters in the username.

The easiest way to do it is convert any users supplied to you in an Excel file to lower case using the formula =lower(A1) before saving as a CSV file.  You will need to convert this list to values before deleting the original column. Don’t forget to put  your users under the heading of ‘username’ and the cohort names under ‘cohort1’.

Our usernames are in two groups; students with a numerical id and staff with a text based usernames.  I found the quickest way to look for users with upper case characters in their username was with the following query:

SELECT * FROM `user` WHERE username REGEXP BINARY ‘[A-Z]’

I (lazily) didn’t bother to write a query to update them because there weren’t that many.

Ain't nobody got time for that

CSS formatting and Microsoft Exchange

Have you found that despite your php html based mail() having the correct headers for CSS formatting Microsoft Exchange is stripping away the styles and displaying the body of your beautiful emails in default Times New Roman?

Old design habits die hard and I’m not a fan of the stark contrast of black text on a white background and serif fonts for text expect for headings.  Also I’m not a fan of Times New Roman, though it’s not nearly as bad as Comic Sans, Tempus Sans, Papyrus, etc. but that’s a topic for another. Back to the point…

First off make sure you have the correct headers for CSS formatting.  The two I use are as follows:

$headers = 'MIME-Version: 1.0'. "\r\n";
$headers .= 'Content-Type: text/html; charset=iso-8859-1'."\r\n";

don’t use:

$header = 'Content-Type: text/html; charset=utf-8';

I still set the CSS styling in the head so it covers the entire email but if you style the <body> element, MS Exchange will ignore it; therefore, the easiest way to style is to create an id, for example:

$message = "<html><head>
  <style type=\"text/css\">
    #email {
      font-family: Segoe, 'DejaVu Sans', 'Trebuchet MS', sans-serif;
      color: #404040;
      }
  </style></head>";

The use the id as an attribute of the body element:

$message .= "<body id=\"email\">";

Continue your php email coding as usual.  Don’t forget to close the body and html tags.

That’s it! A quick work around that keeps your custom style when users receive emails through Microsoft Exchange.

Dates not displaying in Mahara on Windows

In my previous post I wrote about a bug I submitted to the Mahara bug tracker regarding the %z warning and my dates not displaying. That post gives a ‘fix’ for the time zone offset and removal of the warning but at that stage I had not had a chance to fix the second problem of many of Mahara post dates not displaying.

I’ve spent some time this morning and have sorted the problem. Turns out it is the same php strftime Windows issue. I understand that the powers that be work in a Linux environment but I don’t think it would be too difficult to Window’s supported parameters and then if required run a small fix as in Moodle’s calendar structure.php file.

So just as %e and %z are not supported parameters, turns out neither is %l (lower case L) or %k. Interestingly it’s not mentioned on the php manual for strftime. I ended up checking all the strftime parameters used in Mahara just to make sure but %e, %l, %k and %z were the only ones I found not compatible.

There are four instances of %l and two instances of %k in the langconfig.php file. The lower case L parameter (hour in 12-hour format, with a space preceding single digits) can be replaced with I (upper case i) which is the same 12 hour format but with a leading zero for single digits. It’s not as pretty but it works.

$string['strftimedatetime'] = '%%d %%B %%Y, %%l:%%M %%p';
$string['strftimedaydatetime'] = '%%A, %%d %%B %%Y, %%l:%%M %%p';
$string['strftimerecentfull'] = '%%a, %%d %%b %%Y, %%l:%%M %%p';
$string['strftimetime'] = '%%l:%%M %%p';
$string['strftimerecent'] = '%%d %%b, %%H:%%M';
$string['strftimerecentyear'] = '%%d %%b %%Y, %%H:%%M';

Update your /local/lang/en.utf8/langconfig.php file (as per the previous post) swapping the lower case L for an upper case i.

Edit…

I ended up testing all the available parameters.  Here is a list of those that worked in my Windows environment”

working not working
A C
B D
H F
I G
M P
S R
U T
W V
X e
Y g
Z h
a k
b l
c n
d q
j r
m s
p t
w u
x
y
z

Time zone offset in the php strftime function on Windows

Yes, that old chestnut! Always a hot topic around the morning tea table. OK, not really but I am sick of that warning in Mahara; a warning for something I cannot fix or something that was not my causing.

Mahara warning

Anyhoo, I have posted it to the bug tracker combined with none of my dates displaying (last login, post dates, journal dates, etc.). The bug has been (understandably) triaged with low importance; however,I did get some ideas form the helpful Aaron. I have also found scraps of help online but nothing complete so again I’m sharing my findings in the love for all things open source.

There are in fact two problems with php’s stftime when used in Mahara – %e and %z. %e (day of the month with leading space for single digit) doesn’t work in Windows but can be replaced with %d (day of the month with leading zeros for single digits). %z in Windows displays time zone offset as ‘New Zealand Standard Time’ rather than +1200.

It’s the /lang/en.utf8/langconfig.php file that requires editing however it is good practice to leave the original and make changes to a copy saved in the local directory. Therefore copy the file and save local directory but mimic the files directory structure, i.e. /local/lang/en.utf8/langconfig.php.

Here in lies the first problem. As soon as you upload this file your Mahara site will crash and die (until you fix it) with a fatal error:

fatal error message

It’s an easy fix if your error messages are not hidden. Remove the last two declarations and the function from your /local/lang/en.utf8/langconfig.php file:

remove this code

Change

$string['strftimedate'] = '%%e %%B %%Y';

to

$string['strftimedate'] = '%%d %%B %%Y';

With the next change there are two options with the problem line:

$string['strftimew3cdatetime'] = '%%Y-%%m-%%dT%%H:%%M:%%S%%z';

The first option is just to remove the %%z, the second option is to hard code a replacement with your UTC offset, for example, +1200 (with no colon). This is my preference (I’ll explain below) but if you live in a country with daylight savings (like me in New Zealand) you will need to update it when daylight savings starts and ends.

I trialled all three options and could not find any reference to the time zone in the database regardless of the %z options I used. Also independent of the changes, the warning will continue to appear as it does its own test on the time zone offset. Once you’ve made the changes you’re happy with you could comment out the offset test from /lib/upgrade.php (but I’m not responsible for your code hacking).

remove it if you dare. I did

As Aaron suggested I found the time zone offset issue came in to play when exporting a portfolio using Leap2A. The three options and their outputs are below:

the original

$string['strftimew3cdatetime'] = '%%Y-%%m-%%dT%%H:%%M:%%S%%z';

Original code

The time zone offset removed

$string['strftimew3cdatetime'] = '%%Y-%%m-%%dT%%H:%%M:%%S';

timezone-nothing

hardcoding it to +1200 (or +1300 during daylight savings)

$string['strftimew3cdatetime'] = '%%Y-%%m-%%dT%%H:%%M:%%S+1200';

timezone-hardcode

As you can see all have had the string edited to add a colon before the last two characters. The original code has the text-based New Zealand Daylight time (plus additional colon) which I pick would render it flawed when importing into another portfolio (I’ll test it when I have a chance). The same can be said for when removing the %%z, leaving it with an additional colon before the seconds part of the date/time.

So I’m going with hard coding my time zone offset until hopefully the problem is fixed. Tomorrow I try solve the mystery of the disappearing dates.