I would like to share some stuff in this blog that in Moodle LMS we don’t have all enrolled users’s courses and activities report so that I have developed this moodle report by writing couple of lines of code in the following.

<?php
require_once(‘../config.php’);
require_once($CFG->dirroot .’/course/lib.php’);
require_once($CFG->libdir .’/filelib.php’);
$hostname=$CFG->dbhost;
$databaseuser=$CFG->dbuser;
$databasepwd=$CFG->dbpass;
$databasename=$CFG->dbname;
mysql_connect($hostname, $databaseuser,$databasepwd);
mysql_select_db($databasename);
if(!isloggedin()){
redirect($CFG->wwwroot .’/login/index.php’);
}
$context = get_context_instance(CONTEXT_SYSTEM);
$PAGE->set_url(‘/’);
$title =’Reports';
$PAGE->navbar->add($title);
$PAGE->set_pagelayout(‘dashboard’);
echo $OUTPUT->header();
global $DB, $CFG, $context,$USER;
?>
<style type=”text/css”>
th,td{padding-left:15px;}
.thspace{padding-left:18px;}
</style>
<table border=”0″ style=”border:#B3B3B3 solid 1px;”>
<tr style=”border-bottom:#B3B3B3 solid 1px;”><td></td><td><form><select name=”uid” onChange=”this.form.submit();”><option value=””>–Select–</option><?php
$usrdata=mysql_query(“SELECT * FROM mdl_user WHERE suspended=0 and deleted=0″);
while($urecord=mysql_fetch_array($usrdata)){?><option value=”<?php echo $urecord[‘id’];?>” <?php if($urecord[‘id’]==$_REQUEST[‘uid’]){?> selected <?php }?>><?php echo $urecord[‘firstname’].” “.$urecord[‘lastname’];?></option> <?php }?></select></form></td><td></td><td></td><td></td><td></td><td></td></tr>
<tr><td>S.NO</td><td>User Full Name</td><td>Email Address</td><td>Course Name</td><td>Activity Name</td><td>Status</td><td>Completion Date</td></tr>
<?php
$datashow=”;
if(!empty($_REQUEST[‘uid’])){
$coursedata=mysql_query(“SELECT DISTINCT u.id AS userid, c.id AS courseid FROM mdl_user u JOIN mdl_user_enrolments ue ON ue.userid = u.id JOIN mdl_enrol e ON e.id = ue.enrolid JOIN mdl_role_assignments ra ON ra.userid = u.id JOIN mdl_context ct ON ct.id = ra.contextid AND ct.contextlevel = 50 JOIN mdl_course c ON c.id = ct.instanceid AND e.courseid = c.id JOIN mdl_role r ON r.id = ra.roleid AND r.shortname = ‘student’ WHERE e.status = 0 AND u.suspended = 0 AND u.deleted = 0 AND (ue.timeend = 0 OR ue.timeend > NOW()) AND ue.status = 0 AND u.id='”.$_REQUEST[‘uid’].”‘ order by c.id LIMIT 0,25″);
}else{
$coursedata=mysql_query(“SELECT DISTINCT u.id AS userid, c.id AS courseid FROM mdl_user u JOIN mdl_user_enrolments ue ON ue.userid = u.id JOIN mdl_enrol e ON e.id = ue.enrolid JOIN mdl_role_assignments ra ON ra.userid = u.id JOIN mdl_context ct ON ct.id = ra.contextid AND ct.contextlevel = 50 JOIN mdl_course c ON c.id = ct.instanceid AND e.courseid = c.id JOIN mdl_role r ON r.id = ra.roleid AND r.shortname = ‘student’ WHERE e.status = 0 AND u.suspended = 0 AND u.deleted = 0 AND (ue.timeend = 0 OR ue.timeend > NOW()) AND ue.status = 0 order by c.id LIMIT 0,25″);
}

$slno=0;
$num_repeat=0;
while($comdata=mysql_fetch_array($coursedata)){
$slno=$slno+1;
$asdsad=mysql_query(“SELECT * from mdl_course_modules where course='”.$comdata[‘courseid’].”‘”);
while($cmdata=mysql_fetch_array($asdsad))
{
$udata=mysql_fetch_array(mysql_query(“SELECT * from mdl_user where id='”.$comdata[‘userid’].”‘”));
$cdata=mysql_fetch_array(mysql_query(“SELECT * from mdl_course where id='”.$comdata[‘courseid’].”‘”));
$mdata=mysql_fetch_array(mysql_query(“SELECT * from mdl_modules where id='”.$cmdata[‘module’].”‘”));
$modulenames=mysql_fetch_array(mysql_query(“select * from mdl_”.$mdata[‘name’].” where id='”.$cmdata[‘instance’].”‘”));
$coursecompletiondata=mysql_query(“select * FROM mdl_course_modules_completion where coursemoduleid ='”.$comdata[‘courseid’].”‘ and userid='”.$comdata[‘userid’].”‘”);
$cstatusrec=mysql_fetch_array($coursecompletiondata);
if($cstatusrec[‘completionstate’]==1){
$completionstatus=’Completed';
$completionsdate=date(‘d-M-Y’,$cstatusrec[‘timemodified’]);
}else{
$completionstatus=’Registered';
$completionsdate=’–‘;
}
if($slno!=$num_repeat){
$num_repeat=$slno;
$datashow.='<tr><td>’.$num_repeat.'</td><td>’.$udata[‘firstname’].” “.$udata[‘lastname’].'</td><td>’.$udata[‘email’].'</td><td>’.$cdata[‘fullname’].'</td><td>’.$modulenames[‘name’].'</td><td>’.$completionstatus.'</td><td>’.$completionsdate.'</td></tr>';
}else{
$datashow.='<tr><td></td><td></td><td></td><td></td><td>’.$modulenames[‘name’].'</td><td>’.$completionstatus.'</td> <td>’.$completionsdate.'</td></tr>';
}
}
}
echo $datashow;
?>
</table>
<?php

echo $OUTPUT->footer();

—————————————————————

The above code you will save as index.php file or any name and just create one folder move it. That folder should be inside Moodle directory only.

314 Total Views 3 Views Today

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>