我试图获取用户尝试2次的课程尝试细节,因此每当我尝试显示2个结果时,其显示2个结果是相同的。
例如,如果第一次尝试失败,第二次尝试,如果我通过它显示2条记录数据通过,我不知道为什么会发生这种情况。
以下是该页面的代码:
<?php
global $DB, $USER, $CFG;
include("include/header.php");
date_default_timezone_set('Asia/Kolkata');
?>
<body>
<div style="
margin: 50px 30px 5px 0px;
float: right;
">
<?php
if ($_SESSION['idnumber'] == 3) {
?>
<a href="link_courses.php"><button type="submit" name="linkcourses" value="linkcourses" class="btn btn-primary">Link Exam</button></a>
<a href="createaccesscode.php"><button type="submit" name="accesscode" value="accesscode" class="btn btn-primary">Access Code</button></a>
<a href="createsingleuser.php"><button type="submit" name="accesscode" value="accesscode" class="btn btn-primary">Create Single User</button></a>
<button data-toggle="modal" data-target="#contact_dialog" type="submit" name="accesscode" value="accesscode" class="btn btn-primary" style="cursor: pointer;">Max No. of Users</button>
<button data-toggle="modal" data-target="#bulk_upload" type="submit" name="accesscode" value="accesscode" class="btn btn-primary" style="cursor: pointer;">Bulk User Upload</button>
<a href="report.php"><button type="submit" name="accesscode" value="accesscode" class="btn btn-primary">Report</button></a>
<a href="creategroup.php"><button type="submit" name="accesscode" value="accesscode" class="btn btn-primary">Groups</button></a>
<?php
}
if ($_SESSION['idnumber'] == 2) {
?>
<a href="report.php"><button type="submit" name="accesscode" value="accesscode" class="btn btn-primary">Report</button></a>
<?php
}
?>
</div>
<div class="container-fluid"style="background: #dddadd">
<div style="
margin: 50px 15px 5px 0px;
float: right;
">
<?php
if ($_SESSION['idnumber'] == 3) {
?>
<?php
}
?>
</div>
<div class="row" style=" margin-top: 20px;">
<div class="col-lg-12">
<div class="panel panel-default">
<div class="panel-body" id="report_grid">
<div class="table-responsive" style="font-family: myFirstFont;">
<table id="datatable2" class="table">
<thead>
<tr>
<th style="color: #005EB8">Course</th>
<th style="color: #005EB8">Username</th>
<th style="color: #005EB8">First Name</th>
<th style="color: #005EB8">Last Name</th>
<th style="color: #005EB8">Total Time</th>
<th style="color: #005EB8">Start Date</th>
<th style="color: #005EB8">Completion Date</th>
<th style="color: #005EB8">Attempt</th>
<th style="color: #005EB8">Status</th>
<th style="color: #005EB8">Exam score</th>
</tr>
</thead>
<tbody>
<?php
require_once($CFG->dirroot . '/mod/scorm/lib.php');
require_once($CFG->dirroot . '/mod/scorm/locallib.php');
require_once($CFG->dirroot . '/course/lib.php');
global $DB;
//course table fetch
$sql1 = "SELECT cm.id as cmid,c.id,c.fullname,c.startdate,c.startdate,instance FROM {course} c LEFT JOIN {course_modules} cm ON c.id=cm.course where c.category != 0 and requested='0' AND cm.id!=''";
$courses = $DB->get_records_sql($sql1);
if (sizeof($courses)) {
foreach ($courses as $row) {
$scorm = $DB->get_record("scorm", array("id" => $row->instance));
$scoid = 0;
$orgidentifier = '';
if ($sco = scorm_get_sco($scorm->launch, SCO_ONLY)) {
if (($sco->organization == '') && ($sco->launch == '')) {
$orgidentifier = $sco->identifier;
} else {
$orgidentifier = $sco->organization;
}
$scoid = $sco->id;
}
$cmid = $row->cmid;
$coursename = $row->fullname;
$useridQry = '';
$userIds = '';
$login_id = $_SESSION['USER']->id;
if ($_SESSION['idnumber'] == 3) {
} elseif ($_SESSION['idnumber'] == 2) {
$records = $DB->get_records_sql("select * from {user} where maildigest=$login_id");
if (count($records)) {
foreach ($records as $row) {
$userIds[] = "'" . $row->id . "'";
}
if ($userIds != '') {
$userIds = implode(',', $userIds);
$useridQry = " and st.userid IN ($userIds)";
}
}
} else {
$useridQry = "and st.userid = $login_id";
}
$scom_id = $row->cmid;
$cm = get_coursemodule_from_id('scorm', $scom_id, 0, false, MUST_EXIST);
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
$scorm = $DB->get_record('scorm', array('id' => $cm->instance), '*', MUST_EXIST);
$query = "SELECT DISTINCT CONCAT(u.id, '#', COALESCE(st.attempt,0)) AS uniqueid, st.scormid AS scormid,st.value, st.attempt AS attempt, u.id AS userid,u.picture,u.firstname,u.lastname,u.username,u.firstnamephonetic,u.lastnamephonetic,u.middlename,u.alternatename,u.imagealt,u.email,u.idnumber FROM mdl_user u LEFT JOIN mdl_scorm_scoes_track st ON st.userid = u.id AND st.scormid = $scorm->id WHERE (st.userid IS NOT NULL) and idnumber != 0 $useridQry";
$attempts = 0;
$attempts = $DB->get_records_sql($query);
//print_r($attempts);
$row = array();
if (isset($attempts)) {
foreach ($attempts as $scouser) {
//print_r($scouser);
$type = '';
$status = '';
$totaltime = '';
$score = '';
if (!empty($scouser->attempt)) {
$timetracks = scorm_get_sco_runtime($scorm->id, false, $scouser->userid, $scouser->attempt);
} else {
$timetracks = '';
}
//echo $timetracks;
global $DB;
$tracks = $DB->get_records_sql("SELECT id, element, value FROM {scorm_scoes_track} WHERE scormid = ? AND userid = ? AND element IN('cmi.core.lesson_status','cmi.core.total_time','cmi.core.score.raw')", array($scorm->id, $scouser->userid));
foreach ($tracks as $trac) {
if ($trac->element == 'cmi.core.lesson_status') {
$status = $trac->value;
}
if ($trac->element == 'cmi.core.total_time') {
$totaltime = $trac->value;
}
if ($trac->element == 'cmi.core.score.raw') {
$score = $trac->value;
}
$scouser->times = $timetracks;
$scouser->status = $status;
$scouser->totaltime = $totaltime;
$scouser->score = $score;
$row[] = $scouser;
$start_date = $finish_date = '';
if (isset($scouser->times)) {
if (isset($scouser->times->start))
$start_date = date('Y-M-d H-i-s', $scouser->times->start);
if (isset($scouser->times->finish))
$finish_date = date('Y-M-d H-i-s', $scouser->times->finish);
}
} //foreach score track ends
?>
<tr class="gradeX">
<td ><?php echo $coursename; ?></td>
<td ><?php echo $scouser->username; ?></td>
<td ><?php echo $scouser->firstname; ?></td>
<td ><?php echo $scouser->lastname; ?></td>
<td ><?php echo $totaltime; ?></td>
<td ><?php echo $start_date; ?></td>
<td ><?php echo $finish_date; ?></td>
<td ><?php echo $scouser->attempt; ?></td>
<td>
<?php
//print_r($tracks);
//echo $status;
if (trim($status) == "completed") {
echo " Completed";
} elseif (trim($status) == "incomplete") {
echo "Incomplete";
} elseif (trim($status) == "failed") {
echo "Failed";
} elseif (trim($status) == "passed") {
echo "Passed";
} else {
echo "Not Started";
}
?>
</td>
<td>
<?php
if ($score == "") {
} else {
echo $score;
echo '%';
}
//echo $score;
?>
</td>
</tr>
<?php
} //foreach 104 ends
}//attempts if ends
} //course foreach ends
}//course if ends
?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</body>
<?php
include("include/footer.php");
?>
</html>