Moodle is an open source lms which allows us to customize the coding and create any kind of report. Here I am making new kind of report which suppose to give an idea to you how can you write a code with logically.

Here you have to follow the below steps

Step 1.  First create folder like coursereport in your moodle root folder which should bnase level of config.php file.

Step 2. inside  coursereport folder you have to create index.php file.

Step 3. Just copy the below code and paste inside index.php file.

<?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;

/*user(id,email)
course(id,fullname)
mgl_course_modules(course,id,idnumber)
mgl_course_modules_completion(userid,coursemoduleid,completionstate,timemodified)

*/

echo “<table align=’center’ border=’1′ width=’500px’ style=’border:#ccc solid 1px;’>”;
echo “<tr bgcolor=’#0A8C91′ style=’color:#FFF;’>
<td width=’100′>Course name</td>
<td width=’100′>Topic name</td>
<td width=’100′>Name</td>
<td width=’100′>Email address</td>
<td width=’50’>Course completion date</td>
<td width=’50’>Total access time(HH:MM)</td></tr>”;
$coursedata=mysql_query(“select * from mgl_course where id !=1 and visible=’1′”);
while($allcourses=mysql_fetch_array($coursedata))
{
/*echo “select cm.course as CourseName,cm.id as TopicName,cm.idnumber as Minutes,cmc.userid as UserId
FROM mgl_course_modules cm JOIN mgl_course_modules_completion cmc ON cm.id=cmc.coursemoduleid where cm.course='”.$allcourses[‘id’].”‘”;
*/
$finaldata=mysql_query(“select m.name as mname, cm.module as module,cm.instance as instance, u.email as email,u.lastname as lastname,u.firstname as firstname,cmc.timemodified as completiondate,cm.course as CourseName,cm.id as TopicName,cm.idnumber as Minutes,cmc.userid as UserId
FROM mgl_modules m JOIN mgl_user u JOIN mgl_course_modules cm JOIN mgl_course_modules_completion cmc ON cm.id=cmc.coursemoduleid and u.id=cmc.userid and m.id=cm.module where cm.course='”.$allcourses[‘id’].”‘”);
//print_r($finalrec);

echo “<tr><td width=’100′>”.$allcourses[‘fullname’].”</td><td colspan=’5′>”;
while($finalrec=mysql_fetch_array($finaldata))
{

$modulenames=mysql_fetch_array(mysql_query(“select * from mgl_”.$finalrec[‘mname’].” where id='”.$finalrec[‘instance’].”‘”));
echo “<table border=1 width=’100%’><tr>
<td width=’100′>”.$modulenames[‘name’].”</td>
<td width=’100′>”.$finalrec[‘firstname’].” “.$finalrec[‘lastname’].”</td>
<td width=’100′>”.$finalrec[‘email’].”</td>
<td width=’50’>”.date(‘d-M-Y’,$finalrec[‘completiondate’]).”</td>
<td width=’50’>”.$finalrec[‘Minutes’].”</td></tr></table>”;
}
echo “</td></tr>”;
}
echo “</table>”;
echo $OUTPUT->footer();

5117 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>