Skip to content

Commit

Permalink
updated to include conditional session_start for moodle and other int…
Browse files Browse the repository at this point in the history
…egration

git-svn-id: https://xerteonlinetoolkits.googlecode.com/svn/branches/1.7@220 912cdd6b-5c7d-d5a7-a2ba-d0f0cdb91641
  • Loading branch information
ronm123 committed Nov 2, 2011
1 parent 133a5ce commit 3739825
Show file tree
Hide file tree
Showing 3 changed files with 181 additions and 1 deletion.
15 changes: 14 additions & 1 deletion config.php
@@ -1,5 +1,15 @@
<?php

//moodle integration (please view moodle_integration_readme.txt before use)
//The require path below is the path to the moodle installation config file
//usually found in the root of the moodle installation
//this needs to be the path from root rather than something like ../../moodle/config.php
//e.g. this might be something like require("/home/yourdomain/public_html/config.php");
//for a xampp/maxos install this should be something like require("/xampp/htdocs/moodle/config.php");
//set and uncomment this path e.g. remove the // in front of require and change the path for your install
//set this same path in moodle_integration.txt also
//require("/xampp/htdocs/moodle/config.php");

/**
*
* Config page, sets up the site variable from the database
Expand Down Expand Up @@ -45,7 +55,10 @@ function _debug($string, $up = 0) {
}

if(!isset($xerte_toolkits_site)) {
session_start();
if(empty($_SESSION)) {
session_start();
$_SESSION['xertetoolkits'] = true;
}
// create new generic object to hold all our config stuff in....
$xerte_toolkits_site = new StdClass();

Expand Down
111 changes: 111 additions & 0 deletions moodle_integration.txt
@@ -0,0 +1,111 @@
<?php
////moodle integration (please view moodle_integration_readme.txt before use)
//the following line sets a session variable so that the separate config file doesn't restart session_start and kill the moodle session
//if demo.php or switch.php is used then this session isn't set so the installation works fine without moodle integration
$_SESSION['integrate_with_moodle'] = true;

//moodle integration (please view moodle_integration_readme.txt before use)
//The require path below is the path to the moodle installation config file
//usually found in the root of the moodle installation
//this needs to be the path from root rather than something like ../../moodle/config.php
//e.g. this might be something like require("/home/yourdomain/public_html/config.php");
//for a xampp/maxos install this should be something like require("/xampp/htdocs/moodle/config.php");
//set this same path in moodleintegration.php also
require("/xampp/htdocs/moodle/config.php");

//This ensures anyone visiting thie toolkits installation and this page direct is redirected to the moodle login first
//if not already logged in to moodle
require_login();

require_once("config.php");

/**
*
* Integration page, generic framework for integrating this service into other systems.
*
* Please look below at the INSERT strings and make sure you have these sorted
* If your system is providing it's own sessions then you also need to empty the code from session.php so it is just the PHP tags and possibly session_start().
*
* @author Patrick Lockley
* @version 1.0
* @copyright Copyright (c) 2008,2009 University of Nottingham
* @package
*/

/**
* Create the basic session
*/

include $xerte_toolkits_site->php_library_path . "login_library.php";

include $xerte_toolkits_site->php_library_path . "display_library.php";

$_SESSION['toolkits_firstname'] = $USER->firstname;//moodle session firstname

$_SESSION['toolkits_surname'] = $USER->lastname;//moodle session lastname

include $xerte_toolkits_site->php_library_path . "user_library.php";

$mysql_id=database_connect("index.php database connect success","index.php database connect fail");

$_SESSION['toolkits_logon_username'] = $USER->username;//moodle session username

/*
* Check to see if this is a users' first time on the site
*/

if(check_if_first_time($_SESSION['toolkits_logon_username'])){

/*
* create the user a new id
*/

$_SESSION['toolkits_logon_id'] = create_user_id($_SESSION['toolkits_logon_username'], $_SESSION['toolkits_firstname'], $_SESSION['toolkits_surname']);

/*
* create a virtual root folder for this user
*/

create_a_virtual_root_folder();

}else{

/*
* User exists so update the user settings
*/

$_SESSION['toolkits_logon_id'] = get_user_id();

update_user_logon_time();

}

recycle_bin();

/*
* Output the main page, including the user's and blank templates
*/

echo file_get_contents($xerte_toolkits_site->website_code_path . "management_headers");

echo "<script type=\"text/javascript\"> // JAVASCRIPT library for fixed variables\n // management of javascript is set up here\n // SITE SETTINGS\n";

echo "var site_url = \"" . $xerte_toolkits_site->site_url . "\";\n";

echo "var site_apache = \"" . $xerte_toolkits_site->apache . "\";\n";

echo "var properties_ajax_php_path = \"website_code/php/properties/\";\n var management_ajax_php_path = \"website_code/php/management/\";\n var ajax_php_path = \"website_code/php/\";\n";

echo logged_in_page_format_top(file_get_contents($xerte_toolkits_site->website_code_path . "management_top"));

list_users_projects("data_down");

echo logged_in_page_format_middle(file_get_contents($xerte_toolkits_site->website_code_path . "management_middle"));

list_blank_templates();

echo file_get_contents($xerte_toolkits_site->website_code_path . "management_bottom");

?>
</body>
</html>
56 changes: 56 additions & 0 deletions readme_moodlepatch.txt
@@ -0,0 +1,56 @@
moodle patch for Xerte toolkits updated for use with this version of XOT 1.7 only
later versions will have these files included in the XOT download
updated 2/11/11
Author: Ron Mitchell
Use at your own risk - no responsibility accepted etc etc

This patch has been tested with XOT 1.7 and enables authentication integration with the moodle installation on the same server. Specifically it enables integration with the moodle authentication system allowing seamless login from moodle to toolkits. This is achieved by using the moodle session data so at the moment this will not work if moodle and toolkits are installed on separate servers.

/////////////////////////////////////////////////////
How this works
Once applied and configured this patch works in the following ways:

1. A user logs in to moodle and then follows a link from that moodle to an installation of toolkits on the same server. The user is automatically logged in to their own workspace in toolkits seeing any previous LO's they have created. If this is their first visit to the toolkits installation their firstname, lastname and username are added to the xerte toolkits database. (This then also allows other users to share learning objects with the new toolkits user via properties > shared settings or to give learning objects via properties > give this project ) This also means that any existing moodle user, or new users registering on moodle, also has access to the linked toolkits installation.

2. A user visits the toolkits installation without first logging in to moodle. They are automatically redirected to login to moodle.

If the toolkits installation is installed as a subdirectory of the moodle directory the user is then automatically redirected back to their own workspace in toolkits.

If the toolkits installation is installed in a separate directory to the moodle directory the user will not be automatically directed back to toolkits but can follow a link to toolkits from the moodle installation or revisit the toolkits url with the same browser to be automatically logged in.

/////////////////////////////////////////////////////
Installation
Please follow these steps carefully.

Step 1.
Test your XOT installation before trying to use the moodle integration e.g. install toolkits and use demo.txt or switch.txt to make sure everything is working - creating, viewing, exporting an LO etc

Step 2.
Edit the top of moodle_integration.txt and config.php and add the path to your moodle config file so that it points to the config.php in your moodle directory
This needs to be the path from root rather than something like ../../moodle/config.php
e.g. this might be something like the following:
require("/home/youraccountname/public_html/config.php");
For a xampp/maxos install this should be something like:
require("/xampp/htdocs/moodle/config.php");

Step 3 rename moodle_integration.txt to moodle_integration.php

Step 4. view http://yourmoodle/yourxot/moodle_integration.php and ensure everything still works. You should be forced to login to Moodle and then returned back to XOT if installed inside the moodle directory. (see how this works above)

Step 5. If everything is working rename or remove demo.php or switch.php used in step 1

Step 6. If you are only using moodle for authentication you may wish to rename moodle_integration.php to index.php so that you can just use http://yourmoodle/yourxot/

/////////////////////////////////////////////////////

After installation/configuration
You can verify you have configured the moodle path correctly by visiting your toolkits installation which should redirect you to login to moodle. (see the 'how this works' info above)

Notes:

moodle_integration.txt in this patch can be used in place of the ldap enabled index.php. To restore ldap access replace index.php with your original index.php

/////////////////////////////////////////////////////

Bugs/feedback
Please send reports of bugs, success or any other feedback to the Xerte mailing list: xerte@lists.nottingham.ac.uk

0 comments on commit 3739825

Please sign in to comment.