Спасибо
alexdjachenko за наводку, сделал функцию, вот исходники
$userid = $_GET['userid']; //id студента
$courseid = $_GET['courseid']; //id курса
require_once('config.php');
require_once('lib/setup.php');
function enroll_to_course($courseid, $userid, $roleid, $extendbase, $extendperiod) {
global $DB;
$instance = $DB->get_record('enrol', array('courseid'=>$courseid, 'enrol'=>'manual'), '*', MUST_EXIST);
$course = $DB->get_record('course', array('id'=>$instance->courseid), '*', MUST_EXIST);
$today = time();
$today = make_timestamp(date('Y', $today), date('m', $today), date('d', $today), 0, 0, 0);
if(!$enrol_manual = enrol_get_plugin('manual')) { throw new coding_exception('Can not instantiate enrol_manual'); }
switch($extendbase) {
case 2:
$timestart = $course->startdate;
break;
case 3:
default:
$timestart = $today;
break;
}
if ($extendperiod <= 0) { $timeend = 0; } // extendperiod are seconds
else { $timeend = $timestart + $extendperiod; }
$enrolled = $enrol_manual->enrol_user($instance, $userid, $roleid, $timestart, $timeend);
add_to_log($course->id, 'course', 'enrol', '../enrol/users.php?id='.$course->id, $course->id);
return $enrolled;
}
enroll_to_course($courseid, $userid, 5, 3, 0); // 5,3,0 - $roleid, $extendbase, $extendperiod