1 These files represent a snapshot of the offline moodle project on Sept 2, 2008. This is a project in development and what
2 is described here is the development test environment. Any connection between this snapshot and a working capability may prove
3 to be embarassingly coincidental.
7 This project is based on (Google) Gears to enable a student to work on Moodle course material while not connected to the server.
8 Gears uses a manifest file (manifest.json) to cache course pages and resources on the local computer (XO). This manifest file is
9 currently created by a python program which scans the course and subsidiary pages to identify the needed resources. This list must be
10 supplemented by some manual entries (based on trial and error). Gears then provides a localserver which intercepts requests for pages and resources
11 and responds using the cached data. If the requested data is not found, an error is shown. [for example, if view.php?id=37&page=21 is requested, a page with exactly that url must be in the local store or there is an error]. In addition, a set of javascript scripts (fetch_db.js, cache_db.js, and
12 (for debugging) display_db.js are used to cache information from the moodle database needed for navigation in the lesson module. The
13 web page go_offline.html provides buttons: capture (cause Gears to copy the files listed in manifest.json to a local database (the managed
14 store)), erase (to remove the data stored locally when reconnecting to the server - currently no attempt is made to update Moodle based on
15 the offline activity), fetch (invokes a php script (offlinemoodle.php) which gets information from the Moodle MySQL database on the server and stores it in
16 the Gears local SQLLite database), cache (finishes the job started by fetch, and display which shows the data stored in the local database
17 as needed for debugging. Fetch stores the data in a 'hidden' html div on the go_offline.html page and Cache reads that data and stores it in the Gears local db. Finally, a Greasemonkey javascript (offlinemoodle.user.js) is used to modify the Moodle pages so that calls to server-side php routines call instead client-side javascripts which perform the same functions. (Yes, you are right. This architecture owes a heavy debt to the work of Rube Goldberg!).
21 1. The resource requests are based on files in the moodledata folder. For security reasons, this folder should not be in the moodle folder. In this case, an unauthorized request will fail because it is asking for data in a different domain. However, for exactly this reason, Gears also fails. Currently, the moodledata folder is in the moodle directory. What is needed is a server side php script (e.g. offlinemoodle.php) which can get the resources from the moodledata and supply them to Gears. However, Gears is based on the idea that it can intercept exactly the same 'url' as would be supplied online - because it targets the moodle domain. How to get over this is to be determined.
23 2. The navigation of the lesson module depends on (1) going to the same page, (2) going to the next page, (3) going to a specified 'jumpto' page when the next page has no 'answer' and no 'response' in the Moodle mdl_lesson_answers table, (4) going to a previous page when the next page is an end of branch page (one that has an 'empty' entry in the mdl_lesson_pages table), and (5) going to the course page when the end of lesson (next page is page 0) is reached. In the snapshot some of this works. It's a bit like 'whack a mole'. Which work and which don't depends on the last one I tried to fix. Soon I hope to have all of it right.
27 1. You must have your own moodle install on 'your own' server. There are two required changes to moodle/lib/javascript.php which add script references to each page:
29 <script type="text/javascript" src="<?php echo $CFG->httpswwwroot ?>/lib/dropdown.js"></script>
30 <script type="text/javascript" src="<?php echo $CFG->httpswwwroot ?>/lib/offline/offlinemoodle.js"></script>
31 <script type="text/javascript" src="<?php echo $CFG->httpswwwroot ?>/gears_init.js"></script>
33 The second and third lines were added after the first line (which is line 28 of the original). The second line provides a javascript script which processes XMLHTTPRequests (aka XHR or Ajax requests). This substitutes client-side javascript processing for (unavailable) server-side php processing.
34 The third line provides a javascript file to initialize Gears (needed on each page because I haven't found a way for javascript to remember how to refer to gears from one page to the next).
36 2. You must install: gears_init.js, go_offline.html, and go_offline.js files to the moodle folder. These files are provided by the Gears example code.
38 3. You must create an offline folder in the Moodle lib folder and put the offlinemoodle.js file there.
40 4. The offline_manifest.json also goes in the Moodle folder. The one in the snapshot defines the pages and resources to be cached from the
41 Moodle Features Demo course. Naturally, when installing Moodle, you need to get the Moodle Features Demo course backup zip and install it on
42 your private Moodle. My 'private' server is named tony-desktop. Naturally, the relevant names in the json file need to be changed for your server name.
44 5. The files fetch_db.js and fetch_db.php also need to be in the Moodle folder.
46 6. In Firefox, install the Gears and Greasemonkey plugins. Installing 'firebug' can certainly help also.
49 7. In Firefox, under tools/Greasemonkey, install new user script. Give it the name 'offlinemoodle.user.js'. In the includes - show only the url of
50 your Moodle (in my case: http://tony-desktop/moodle/*). The final '/*' means that the greasemonkey script will be applied to every moodle page (and no other pages). Hit OK. This will open the file in gedit (or your Firefox designated editor). Replace everything with the complete contents of the 'offlinemoodle.user.js' file in this package (and save). To make further changes, go to the Firefox/Tools/Greasemonkey/Manage User Scripts, select 'offlinemoodle.user.js', and hit edit on the lower left. This will reopen the page in gedit (or designated editor). It is actually saved somewhere in the bowels of Firefox.
52 This is the procedure for testing the 'Features Demo' course offline:
54 1. Login to the course online. I log in as admin and change role to student. This is essential as Gears must cache the pages created for a logged-in user.
56 2. Fetch the 'go_offline.html' page.
58 3. Go to Firefox/tools/clear private data. Clear the web page cache to ensure what you are seeing is really 'offline' Moodle.
60 4. Press the 'capture' button. It will take some minutes to complete the cache process. The current snapshot does not provide a 'progress'
61 indicator. If it fails, it may be because you were not logged in to the course first.
63 5. Press the 'fetch' button. It displays an alert when done.
65 6. Press the 'cache' button. It displays an alert when done (currently saying the last line was 29).
67 7. Go to Firefox/File and click on 'Work Offline'. I am not sure what happens if you don't do that and just try to test with the LAN/wifi link disabled.
70 8. Go to Firefox/Tools/Greasemonkey and make sure it is enabled.
72 9. Go back to Firefox and reload the course (the results this time are from the Gears cache). Try the activities to see what works.
74 10. When the situation is hopeless, go to Firefox/File and return to online mode. Go to the 'go_offline.html' page. Hit the 'erase' button.
76 11. Before starting another test make sure that (1) you reload the go_offline.html page so that it says again 'Yeah ...' and (2) clear the private data.
77 Note: except for the offlinemoodle.user.js (Greasemonkey) script, the other files are downloaded by Gears. This means that to test changes to these files, you must go back on line and do the 'capture' again to get the modified file. If the problem is in the Greasemonkey script, it can be changed and the results will be seen when the relevant (offline) web page is reloaded.
90 (gears_init.js and go_offline.js should be obtained from the Gears site).