Hi All,
I am trying to create a php script to automatically enroll a user into a course. We have a Drupal website with a Drupal/Moodle SSO plugin. Drupal is handling payment processing, but from what I know I can only have the user click on a link to go to the course in Moodle. So far I have tried automatically posting all of the variables in the self enrollment form, but to no avail. Here is the code I have so far:
<?php
$course = htmlspecialchars($_GET['course']);
switch ($course) {
case "theCourseTheUserWantsToTake":
$curlConnection = curl_init('http://ourmoodlesite.com/enrol/index.php?id=2');
curl_setopt($curlConnection, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($curlConnection, CURLOPT_USERAGENT,'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)');
curl_setopt($curlConnection, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curlConnection, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curlConnection, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curlConnection, CURLOPT_POSTFIELDS, 'id=2&instance=3&sesskey=' . $USER->sesskey . '&_qf__3_enrol_self_enrol_form=1&mform_isexpanded_id_selfheader=1&enrolpassword=selfEnrollPassword&enrolpasswordunmask=0');
$result = curl_exec($curlConnection);
curl_close($curlConnection);
echo $result;
header('Location: http://ourmoodlesite.com/course/view.php?id=2');
break;
default:
echo 'no course found';
}
?>
The $result variable isn't outputting anything and I haven't been able to find any logs indicating why this isn't working. Any ideas on why this isn't working or another method for automatically enrolling a user into a course? I am also looking at the IMS Enterprise plugin where I would write the necessary information to the file and run the cronjob to update the enrollments.
Any help on this would be greatly appreciated.
-Michael