use moodle enrol me function in custom php application

use moodle enrol me function in custom php application

by bharathi redddy -
Number of replies: 1

I developed one custom php application..so i used moodle sessions in my application..so its working fine..

so what i did in my application is i fetch all the courses from moodle and i displayed in one data table so for each record of course there is one button called LAUNCH..so when user click on the button it open the scorm package of the particular  course..


So now my problem is if the user open the course for the first time..when they click on the LAUNCH button it redirects them to moodle page to the enrol me page..if the user click on the enrol me button it redirects to scorm package.

i dont want to show the enrol me to the user..i want that course automatically enrolled to the user  when they clicked on LAUNCH button..

can anyone help me how to do this..

thanks in advance..

Average of ratings: -
In reply to bharathi redddy

Re: use moodle enrol me function in custom php application

by Nilesh Pathade -

You can do this with help for CURL script and Moodle web Services.

Helpful Links : 

https://docs.moodle.org/34/en/Using_web_services

https://curl.haxx.se/download.html

header('Access-Control-Allow-Origin: *');
require_once('curl.php');
$token = 'd51b56be2963f4167f3702abe47972bc'; // Create token using webservice -> manage webservice -> token
$domainname = 'http://yourmoodleurldomain/';
$functionname = 'enrol_manual_enrol_users';
$user1 = new stdClass();
$user1->roleid = 5;
$user1->userid  = $user_id;
$user1->courseid  =$course_id;

$params = array($user1);

/// XML-RPC CALL
//header('Content-Type: text/plain');
$serverurl = $domainname . '/webservice/xmlrpc/server.php'. '?wstoken=' . $token;
$curl = new curl;
$post = xmlrpc_encode_request($functionname, array($params));
$resp = xmlrpc_decode($curl->post($serverurl, $post));
$curl->getResponse();