I sent a mail to Cas Nuy, the developer of the Drupal/Moodle Integration module and requested him to update it to work with Drupal 4.7.3.

Guess what he does? He takes 2 days but sends me an email with the updated code. I am attaching it to this post.

I have seen several posts where people have been asking for an updated module. Please donate to Cas Nuy (cas@nuy.info) if you find this module useful.

I am sure, some of us will have our own wishlists which you may want Cas to incorporate in this module. Donations will ensure that this module remains updated.

Regards
Asad

Comments

syedasad’s picture

How do I add the updated module as an attachment to this forum topic?
Till I am able to, please email me and I will email you the updated module.

Thanks
Asad

agsedu’s picture

hayesr’s picture

Instead of bombarding Asad with emails I'm hosting the file here.

loutcholycos’s picture

erichayes,
I had installed the module you host and i had to change a line in the moodle.module file.

Line 20 -
Before - $access = user_access('access Moodle');

After modify - $access = user_access('access moodle');

Just this 'M' in place of 'm' caused that i couldn't reach my Moodle install between Drupal

Excuse me for my English but i'm french speaker and school is very far,

Loutcholycos

victorkane’s picture

I made some quick modifications to get this module working for Drupal 5.0 beta. This is a tarball of the module actually working.

I find that relative URL's for the (possibly local) moodle installation do not work, and require a full http://... URL.

You can get it here . Please note that this should only be a temporary expedient until drupal/moodle integration or other solutions are more thoroughly developed. See the DrupalEd Distribution Group at http://groups.drupal.org/drupaled-distro .

Please feel free to put it up next to the 4.7.4 version.

Victor Kane
http://awebfactory.com.ar

bberretta’s picture

Will either of these modules work with Moodle 1.7 and Drupal 4.7.3? I've tried the Cas Nuy's module and I'm running into some issues (only Drupal Admin has login access, access goes straight to edit profile, and Moodle keeps opening outside of i-frame when I click on classes.) Any help would be GREATLY appreciated!

Edit- It was an error on my part. I re-installed the module and it works fine now. The only issue is that it will step out of the i-frame every now and then.

victorkane’s picture

Hi.
I have used the module with Moodle 1.7 and have used it successfully with Drupal 4.7.3 (as well as 5.0).

In my installs, regular users are able to "moodle over". And the author sent me an update which includes opening Moodle in a pop-up window instead of an iframe.

Contact me if you like and we can test the step-by-step instruction list on clean installs if you like, which we could publish here.

Victor Kane
http://awebfactory.com.ar

Steven Mansour’s picture

Hello,

I installed this on a Drupal 4.7.4 install, with a clean moodle install in the Drupal dir, /moodle.

After applying the above fix changing uppercase M to lowercase m, the Moodle link appears in the navigation block for all users... but that's all.

Clicking on it brings you to the Moodle install, but not in an iFrame. It just leaves my Drupal site and brings me to the default Moodle page. It doesn't even log the user in.

I made the changes to the Moodle authentication options as outlined in the INSTALL.txt.

Am I missing something here? Do users need to create accounts on both sites, and then log into both? If so, what is the purpose of the Module?

If not, what can I do to help debug this?

Cheers and thanks in advance,

s.

Steven Mansour’s picture

In the moodle database, under mdl_users,

I get email@address.com.1166842626

For every drupal user who tries to moodle through from drupal.

(I'm using the latest version of Moodle).

Cheers,

s.

victorkane’s picture

0. You only create authenticated users (with moodle module access in access control) within Drupal, not within Moodle; change Moodle authentication method to external database, in general, follow the directions (points 1-7 in the bundled install help text file). Directions included below as a PS, just in case.

1. As stated in http://drupal.org/node/80982 you have to change 'access Moodle' to 'access moodle' in line 20 of moodle.module:
$access = user_access('access moodle');

2. Had to give access to authenticated user only; if I give access to more than one role, it doesn't work (unconfirmed, but try it if all else fails).

3. Step 7 (putting /moodle/ into the config field) didn't work for me: if I put '/moodle/' it took it as '/drupal/moodle/'; the settings instructions misguide when they say relative path (suppose they put moodle under drupal); so I put full path for it to work, for example:
http://example.com/moodle/
I also suspect that this is needed for the drupal and moodle session management to work, so on some machines I put in localhost, and on others the actual domain in order for the automatic login to work.

4. The first time you go into Moodle from Droodle, you are taken to your profile page; for future seamless logins to work, you must fill in First Name, Last Name, City, Country, Description, etcétera. These fields could be copied in automatically from somewhere specified in the moodle: Administration » Users » Authentication, but I haven't tried that.

After that it was smooth for me.

Please respond if you continue having trouble, and we can try it step my step.

Victor Kane
http://awebfactory.com.ar

PS The original bundled install help text:

INSTALLATION
======================
0. Install Moodle stand alone and verify it is working correct.
1. copy moodle.module to your /modules directory.
2. Copy index_dr.php to the root of your Moodle directory
3. Go to the admin section of Moodle (Stand alone mode), users
4. Set the authorisation module to External Database and fill in the credentials from your Drupal database
- auth_dbname => Database name of the Drupal database
- auth_dbuser => Database user you used when setting up Drupal
- auth_dbpass => Database password you used when setting up Drupal
- auth_dbtable => Usertable from Drupal , most likely 'users'
- auth_dbfielduser => Thefieldname containing the username most likley 'name'
- auth_dbfieldpass => Thefieldname containing the password most likley 'pass'
5. Keep the password format to PLAIN.
6. Initialise & activate the Moodle module within Drupal
7. Set the path to the moodle directory containing a final forward slash, so something like "/moodle/".

Existing users will have their authorisation method still set to the previous way of authorising.
Most likley this will be manual.
In order to adjust, you need to go to the Moodle Database, table mdl_user and change the field 'auth'of those users to 'db'.

amrit09’s picture

Hello to all

I have just installed the Moodle module with help from this forum page.

However, is there a way of passing the access rights of a new user into moodle i.e. If you create a new administrator in Drupal, to make the same user in moodle an administartor??

Thanks

AMRIT

amrit09’s picture

Also, i have just started getting this message:-

Sorry, you have exceeded the allowed number of login attempts. Restart your browser.

It works when you restart the browser, but i dont want this to happen when other users are using it. Any ideas?

AMRIT

victorkane’s picture

We are investigating other more standards conformant single sign on options, supported by both Drupal and Moodle. There are three which bear investigation (depends on your network):

1. CAS from Yale University (requires Java server or at least Tomcat). Supported through modules by both Drupal and Moodle.
2. LDAP, supported by both.
3. OpenID, which is well on its way to being supported by both: this looks the most promising.

The "restart your browser" has to do with the sessions, I have seen it, but mainly in the debugging stages. Will report on workaround, or way to impede this problem.

Victor Kane
http://awebfactory.com.ar

wvd_vegt’s picture

Hi,

I have extended the original module so it becomes a real node (taxonomy & filtering now works).
It is tested against Drupal 1.8.2+ and Drupal 6.4.

It support more parameters to be passed from the users profile (including images) then the original code.
For this it expects a number of Drupal User profile fields:

profile_firstname
profile_lastname
profile_city
profile_country

User pictures/avatars are transferred and resized too.

It allows one to jump straight into a moodle course (just edit the Course nodes courseid).
This way every course could be wrapped in an individual Drupal node.

If you edit the node you can also add a short course description that Drupal also uses
to generate its teasers.

course.info:

; $Id: course.info,v 6.x 2008/08/27 10:15:0 wvd_vegt Exp $

name = Moodle Courses
description = "Manages configuration of the COURSE page."
version = "$Name: DRUPAL-6 $"
core = 6.x

; Information added by drupal.org packaging script on 2007-06-05
version = "6.x"
project = "Course"
datestamp = "1181045137"

course.install:

// $Id: course.install,v 6.x 2008/08/27 10:15:0 wvd_vegt Exp $

/**
 * @file
 * The Course Node type shows a Moodle Course embedded in Drupal
 * and performs a SSO with Moodle (Single Signon). When a Drupal 
 * user views a Course Node it's Moodle User Account is automatically
 * created or updated.
 *
 * Database definition:
 * @code
 *   CREATE TABLE course (
 *     vid int(10) unsigned NOT NULL default '0',
 *     nid int(10) unsigned NOT NULL default '0',
 *     courseid varchar(100) NOT NULL default '',
 *     PRIMARY KEY (vid, nid)
 *   )
 * @endcode
 * 
 * veg:27-08-2008 - completed port to Drupal 6.x.
 *                  passed code review.
 *                  converted course.install to schema.
 *                  corrected documentation.    
 */
function course_schema() {
  $schema['course'] = array(
    'fields' => array(
      'vid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'disp-width' => '10'),
      'nid' => array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'disp-width' => '10'),
      'weight' => array('type' => 'int', 'size' => 'tiny', 'not null' => TRUE, 'default' => 0, 'disp-width' => '4'),
      'courseid' => array('type' => 'varchar', 'length' => '100', 'not null' => TRUE, 'default' => '')),
      'primary key' => array('vid', 'nid'),
  );
  return $schema;        
}

function course_install() {
  // Create my tables.
  drupal_install_schema('course');
}

function course_uninstall() {
  // Drop my tables.
  drupal_uninstall_schema('course');
  variable_del('moodle_dir');
}

Moodle's index_dr.php:

       // $Id: index.php,v 1.97 2003/08/12 16:44:22 moodler Exp $
       // index.php - the front page.

//veg:21-06-2007 - Added first/lastname + calculated description to SSO.
//veg:22-06-2007 - Added city/country/email to SSO.

$reqVar = '_' . $_SERVER['REQUEST_METHOD'];
$form_vars = $$reqVar;

$parm = $form_vars['parm'] ;
$url = explode("|", $parm);

//sample: ?parm=id|user|pass|firstname|lastname|city|country|email              //veg:20-09-2007 - changed

$f_id = $url[0];								//veg:20-09-2007 - added	
$f_username = $url[1];
$f_userpw = $url[2];
$f_firstname = $url[3];                                                        	//veg:21-06-2007 - added
$f_lastname = $url[4];							       	//veg:21-06-2007 - added
$f_city = $url[5];							       	//veg:22-06-2007 - added
$f_country = $url[6];						       		//veg:22-06-2007 - added
$f_email = $url[7];							       	//veg:22-06-2007 - added
if (sizeof($url) == 9) {							//veg:05-11-2007 - added
	$f_redir = $url[8];		
} else {
	$f_redir = "";
}	
$f_description = $f_firstname." ".$f_lastname;                                 	//veg:21-06-2007 - added

require_once("config.php");
require_once("lib/gdlib.php");

$username = trim(moodle_strtolower($f_username));
$password = $f_userpw ;

//veg:05-09-2007 - Prevent host mismatch between portal and moodle.
//		   It would lead to autmatically loggin-in with a cookie from 
//		   possibly someone else! Redirect if there is a mismatch!
$here  = "http://".$_SERVER['SERVER_NAME']."/";
$there = substr($CFG->wwwroot."/index_dr.php", 0, -(strlen($_SERVER['SCRIPT_NAME'])-1));
if (strcasecmp($there, $here)!=0) {
	redirect($CFG->wwwroot."/index_dr.php?".$_SERVER['QUERY_STRING']);
}

$user = authenticate_user_login($username, $password);

update_login_count();

if ($user) {
    if (! $user->confirmed ) {       // they never confirmed via email
        print_header(get_string("mustconfirm"), get_string("mustconfirm") );
        print_heading(get_string("mustconfirm"));
        print_simple_box(get_string("emailconfirmsent", "", $user->email), "center");
        print_footer();
        die;
    }

    $USER = $user;
    //if (!empty($USER->description)) {                                         //veg:11-06-2007 - added (see login.php)
    //    $USER->description = true;   // No need to cart all of it around
    //}
    $USER->loggedin = true;
    $USER->site = $CFG->wwwroot;   // for added security
    sesskey();                                                                  //veg:11-06-2007 - added (see login.php)

    if (!update_user_login_times()) {
        error("Wierd error: could not update login records");
    }

    set_login_session_preferences();                                           	//veg:11-06-2007 - added (see login.php)

    set_moodle_cookie($USER->username);
	
    unset($SESSION->lang);
    $SESSION->justloggedin = true;                                             	//veg:11-06-2007 - added (see login.php)

    $dirty=false;
    if ($USER->username == "guest") {
        $USER->lang       = $CFG->lang;               // Guest language always same as site
        $USER->firstname  = get_string("guestuser");  // Name always in current language
        $USER->lastname   = " ";                                               	//veg:11-06-2007 - added (see login.php)
    } else {
       if ($USER->firstname!=$f_firstname) {	            			//veg:21-06-2007 - added
           $USER->firstname=$f_firstname;                                      	
	   $dirty=true;							
        } 								       	
        if ($USER->lastname!=$f_lastname) {		                        //veg:21-06-2007 - added
           $USER->lastname=$f_lastname;                                        	
	   $dirty=true;						       	
	}							       		
        if ($dirty) {	               					        //veg:21-06-2007 - added, The compare of the text itself fails!
           $USER->description=trim($f_description);                            	
	}								
        if ($USER->city!=$f_city) {		  		                //veg:22-06-2007 - added
           $USER->city=$f_city;          		                        
	   $dirty=true;						       	
	}							       		
        if ($USER->country!=$f_country) {		  		        //veg:22-06-2007 - added
           $USER->country=$f_country;      
	   $dirty=true;			
	}				
        if ($USER->email!=$f_email) {		  		                //veg:22-06-2007 - added
           $USER->email=$f_email;       
	   $dirty=true;		
	}	

//Moodle Avatar: http://localhost/moodle/user/pix.php/2/f1.jpg
//	                                              ^ Moodle UserId
//               C:\Program Files\EasyPHP 2.0b1\tmp\moodledata\users\2
//
//Drupal Avatar: http://127.0.0.1/drupal/?q=system/files/pictures/picture-1.jpg
//               http://127.0.0.1/drupal/?q=system/files/pictures/picture-2.jpg
//					                                  ^ Drupal UserId 
//               C:\Program Files\EasyPHP 2.0b1\www\drupal\files\pictures
//
        $copy_to="{$CFG->dataroot}\\users\\".$USER->id;
	
  	//$copy_from="{$CFG->dirroot}\\..\\drupal\\files\\pictures\\picture-".$f_id.".jpg";
  	$copy_from="{$CFG->wwwroot}/../drupal/?q=system/files/pictures/picture-".$f_id.".jpg";
  	
  	//echo $copy_from."<br />";
  	//echo $copy_to."<br />";
  	if (check_dir_exists($copy_to, true) /*&& file_exists($copy_from) && is_readable($copy_from)*/) {
           if (copy($copy_from, $copy_to."/f1.jpg")) {
           	//veg: Works only for 100x100 images!!!!!
           	upgrade_profile_image($USER->id);
        if ($USER->picture!=1) {		  		        //veg:25-09-2007 - added
			$USER->picture = 1;
			$dirty=true;
		}
           } else {
           	echo "error copying";
           }
        }
    }

    if (user_not_fully_set_up($USER)) {
        $site = get_site();
        redirect("$CFG->wwwroot/user/edit.php?id=$USER->id&course=$site->id");
    }

    reset_login_count();                                                       	//veg:11-06-2007 - added (see login.php)

    load_all_capabilities();                                                   	//veg:11-06-2007 - added (see login.php)

    if ($dirty==true) {							       	//veg:21-06-2007 - added, set time of profile modification
	$USER->timemodified = time();	   					
        if (!update_record('user', $USER)) {				
            error('Error updating user record');		  	
	}							
    }									
} else {
    require_logout();								//veg:06-09-2007 - added to prevent non sso users from loggin in
    set_moodle_cookie($username);						//		   as that's not possible due to md5 encryption.
    										//		   plain text passwords seem to be gone...
    redirect("$CFG->wwwroot/login/index.php");
    exit;
}

if ($f_redir!="") {
        //echo $f_redir;
        if (! ($course = get_record('course', 'idnumber', $f_redir)) ) {
            error('Invalid course idnumber');
        }
	redirect($CFG->wwwroot."/course/view.php?id=".$course->id);
} else {
	redirect("$CFG->wwwroot/index.php");
}
exit;

readme.txt:

A Module to show Moodle Courses embedded in Drupal v 1.9

Besides showing the course it also performs a SSO with Moodle and 
silently creates or updates user accounts. 

In Drupal create the following custom fields in the user's profile:

 * 1 - firstname: a string
 * 2 - lastname : a string
 * 3 - city     : a string
 * 4 - country  : a picklist of 2 letter counrty codes as known by Moodle

In Moodle:

Copy the 'index_dr.php.txt' as index_dr.php to the Moodle root directoy.

You may have to adjust the path used to retrieve the avatar images from 
Drupal or just disable this code all together.

Moodle must be setup to authenticate against Drupal with a plain text password.
Don't worry about the plain text password as it is a MD5 hash.

install.txt:

Tested with :
Drupal 6.4
Moodle 1.8.2+
Windows

Location of the Moodle installation is not important.


INSTALLATION
======================
0.  Install Moodle stand alone and verify it is working correct.
1.  copy moodle.module to your /modules directory.
2.  Copy index_dr.php to the root of your Moodle directory
3.  Go to the admin section of Moodle (Stand alone mode), users
4.  Set the authorisation module to External Database and fill in the credentials from your Drupal database
        - auth_dbname      => Database name of the Drupal database
        - auth_dbuser      => Database user you used when setting up Drupal
        - auth_dbpass      => Database password you used when setting up Drupal
        - auth_dbtable     => Usertable from Drupal , most likely 'users'
        - auth_dbfielduser => Thefieldname containing the username most likley 'name'
        - auth_dbfieldpass => Thefieldname containing the password most likley 'pass'
5.  Keep the password format to PLAIN.
6.  Initialise & activate the Moodle module within Drupal
7.  Set the path to the moodle directory containing a final forward slash, so something like "/moodle/".


Existing users will have their authorisation method still set to the previous way of authorising.
Most likley this will be manual.
In order to adjust, you need to go to the Moodle Database, table mdl_user and change the field 'auth'of those users to 'db'.

wvd_vegt

doknet’s picture

hi, your very good article
How can I get the module integration
moodle and drupal 6. Only to find drupal 5

Excuse my English

Summit’s picture

Subscirbing, also looking for moodle/drupal integration on D6 out of the box..:)
greetings, Martijn