TCF - Concept Wise Report

<?php require_once('../../config.php'); if (!isloggedin()) { header('Location: '.$CFG->wwwroot); die(); } $PAGE->set_context(get_system_context()); $PAGE->set_pagelayout('admin'); $PAGE->set_title($SITE->shortname.": Teacher Concept Wise Report"); $PAGE->set_heading("Teacher Concept Wise Report"); $PAGE->set_url($CFG->wwwroot.'/teacher_concept_wise_report_copy.php'); $conn = mysql_connect($CFG->dbhost, $CFG->dbuser, $CFG->dbpass); $db = mysql_select_db($CFG->dbname); $errors = array(); $success = array(); /* GRADE LEVEL DROPDOWN */ $grade_levels_sql = mysql_query("SELECT * FROM `mdl_question_category_grades`"); $grade_levels = array(); while($grade_level = mysql_fetch_array($grade_levels_sql)) { $grade_levels[$grade_level['id']] = $grade_level['name']; } $selected_regions_sql = mysql_query("SELECT * FROM `mdl_region` ") or die(mysql_error()); $selected_regions = array(); while($selected_region = mysql_fetch_array($selected_regions_sql)) { $selected_regions[$selected_region['id']] = $selected_region['name']; } // Admin Check global $USER; $admins = get_admins(); $is_admin = false; foreach($admins as $admin) { if ($USER->id == $admin->id) { $is_admin = true; break; } } if ( !$is_admin ) { echo $OUTPUT->header(); echo '<legend class="ftoggler" >Custom Reports</legend>'; echo 'You must be an administrator to access this area.'; echo $OUTPUT->footer(); die(); } if ( !$is_admin ) { echo $OUTPUT->header(); echo '<legend class="ftoggler" >Teacher Concept Wise Report</legend>'; echo 'You must be an administrator to access this area.'; echo $OUTPUT->footer(); die(); } ?> <!-- MAIN GRID --> <?php echo $OUTPUT->header(); ?> <link rel="stylesheet" type="text/css" href="<?php echo $CFG->wwwroot; ?>/assets/css/site.css"> <link rel="stylesheet" type="text/css" href="<?php echo $CFG->wwwroot; ?>/assets/js/DataTables/datatables.min.css"> <script type="text/javascript" language="javascript" src="<?php echo $CFG->wwwroot; ?>/assets/js/jquery-1.11.1.min.js"></script> <script src="<?php echo $CFG->wwwroot; ?>/assets/js/jquery-ui.js"></script> <script type="text/javascript" language="javascript" src="<?php echo $CFG->wwwroot; ?>/assets/js/DataTables/datatables.min.js"></script> <script type="text/javascript" language="javascript" src="<?php echo $CFG->wwwroot; ?>/assets/js/jquery.blockUI.js"></script> <script type="text/javascript" language="javascript" src="<?php echo $CFG->wwwroot; ?>/assets/js/site.js"></script> <script type="text/javascript" src="<?php echo $CFG->wwwroot; ?>/assets/granular_report/canvasjs/canvasjs.min.js"></script> <script type="text/javascript" language="javascript" src="<?php echo $CFG->wwwroot; ?>/assets/js/dataTables.tableTools.min.js"></script> <link rel="stylesheet" type="text/css" href="<?php echo $CFG->wwwroot; ?>/assets/css/dataTables.tableTools.min.css"> <!-- Magnific Popup core CSS file --> <link rel="stylesheet" href="<?php echo $CFG->wwwroot; ?>/assets/css/magnific-popup.css"> <!-- Magnific Popup core JS file --> <script src="<?php echo $CFG->wwwroot; ?>/assets/js/jquery.magnific-popup.js"></script> <?php error_reporting(0); $mega_array = array(); $slo_array = array(); if (isset($_POST['selected_region'])) { if ($_POST['selected_region'] != 0) { /* MEGA ARRAYS */ mysql_query ("set character_set_results='utf8'"); $mega_question_categories_sql = mysql_query("select * from mdl_question_categories") or die(mysql_error()); $mega_question_categories = array(); while($mega_question_category = mysql_fetch_assoc($mega_question_categories_sql)) { $mega_question_categories[$mega_question_category['id']] = $mega_question_category; } mysql_query ("set character_set_results='utf8'"); $query_scss = "select distinct cr.id as relation_id, cg.name as 'grade', cc.name as 'class', cs.name as 'subject', (select name from mdl_question_categories where id = cr.category_id) as 'subject_classification', cr.category_id as 'subject_classification_id', (select info from mdl_question_categories where id = cr.category_id) as 'info' from `mdl_question_category_relations` cr inner join `mdl_question_category_grades` cg on cg.id = cr.grade_id inner join `mdl_question_category_subjects` cs on cs.id = cr.subject_id inner join `mdl_question_category_classes` cc on cc.id = cr.class_id "; if (!empty($_POST)) { if ($_POST['grade_level']!=0) { $query_scss .= " where cg.id = ".$_POST['grade_level']." "; if ($_POST['grade']!=0) { $query_scss .= " and cc.id = ".$_POST['grade']." "; if ($_POST['subject']!=0) { $query_scss .= " and cs.id = ".$_POST['subject']." "; } } } } $mega_subject_classifications_sql = mysql_query($query_scss) or die(mysql_error()); $mega_subject_classifications = array(); while($mega_subject_classification = mysql_fetch_assoc($mega_subject_classifications_sql)) { $mega_subject_classifications[$mega_subject_classification['subject_classification_id']] = $mega_subject_classification; } mysql_query ("set character_set_results='utf8'"); $mega_questions_sql = mysql_query("select distinct u.id as userid, q.id, q.name, u.id as userid, u.firstname, q.category from `mdl_question` q inner join mdl_quiz_slots qs on q.id=qs.questionid inner join mdl_quiz quiz on quiz.id=qs.quizid inner join mdl_quiz_attempts qa on qa.quiz = quiz.id inner join mdl_user u on u.id = qa.userid") or die(mysql_error()); $mega_questions = array(); while($mega_question = mysql_fetch_assoc($mega_questions_sql)) { $mega_questions[] = $mega_question; } mysql_query ("set character_set_results='utf8'"); $mega_attemptquestions_sql = mysql_query("select distinct mqa.questionid as id, mqas.userid as userid from `mdl_question_attempts` mqa inner join `mdl_question_attempt_steps` mqas on mqas.questionattemptid = mqa.id where state = 'complete'") or die(mysql_error()); $mega_attemptquestions = array(); while($mega_attemptquestion = mysql_fetch_assoc($mega_attemptquestions_sql)) { $mega_attemptquestions[] = $mega_attemptquestion; } /* MEGA ARRAYS */ mysql_query ("set character_set_results='utf8'"); $regions = mysql_query("select distinct name from mdl_region where id = ".$_POST['selected_region']); while($region = mysql_fetch_assoc($regions)) { $areas = mysql_query("select distinct uid2.data as 'name' from mdl_user ul inner join mdl_user_info_data uid1 on uid1.userid = ul.id inner join mdl_user_info_field uif1 on uif1.id = uid1.fieldid inner join mdl_user_info_data uid2 on uid2.userid = ul.id inner join mdl_user_info_field uif2 on uif2.id = uid2.fieldid where uid1.data = '".$region['name']."' and uif1.shortname = 'region' and uif2.shortname = 'area' order by uid1.data"); while($area = mysql_fetch_assoc($areas)){ $user_ids = mysql_query("select distinct uid1.userid as 'id' from mdl_user_info_data uid1 inner join mdl_user_info_field uif1 on uif1.id = uid1.fieldid where uid1.data = '".$area['name']."' and uif1.name = 'Area' order by uid1.data"); $ids = array(); while($user_id = mysql_fetch_assoc($user_ids)){ $ids[] = $user_id['id']; } if (!empty($ids)) { $ids = implode(',', $ids); $attemptquestions = array_filter( $mega_attemptquestions, array( new DataClosure(array(), explode(',',$ids)), "where_in_match_attemptquestions" ) ); $question_array = array(); foreach ($attemptquestions as $attemptquestion){ $question_array[] = $attemptquestion['id']; } if (!empty($question_array)) { $question_array = implode(',', $question_array); $question_users = array_filter( $mega_questions, array( new DataClosure(explode(',',$question_array), explode(',',$ids)), "where_in_match_question_users" ) ); foreach ($question_users as $question_user) { $slo = $mega_question_categories[$question_user['category']]; if (!empty($slo)) { if(count($slo_area)<1){ $slo_area[$slo['id']] = $area['name']; } if($slo_area[$slo['id']] != $area['name']){ $slo_area[$slo['id']] = $area['name']; $topic = $mega_question_categories[$slo['parent']]; if (!empty($topic)) { $fundamental_concept = $mega_question_categories[$topic['parent']]; if (!empty($fundamental_concept)) { $subject_classification = $mega_subject_classifications[$fundamental_concept["parent"]]; if (!empty($subject_classification)) { $percentage_current_exam = calculate_correct_answer($slo['id'], $question_user['userid'], '', 'student'); $percentage_your_area = calculate_correct_answer($slo['id'], $question_user['userid'], $area['name'], 'area'); $percentage_avg_tcf = calculate_correct_answer($slo['id'], $question_user['userid'], '', 'tcf'); $mega_array[] = array ( 'relation_id' => $subject_classification['relation_id'], 'grade' => $subject_classification['grade'], 'class' => $subject_classification['class'], 'subject' => $subject_classification['subject'], 'subject_classification' => $subject_classification['subject_classification'], 'fundamental_concept' => $fundamental_concept['name'], 'topic' => $topic['name'], 'student_learning_outcome' => $slo['name'], 'slo_id' => $slo['id'], 'student' => $question_user["firstname"], 'percentage_current_exam' => $percentage_current_exam, 'percentage_your_area' => $percentage_your_area, 'percentage_avg_tcf' => $percentage_avg_tcf, 'region' => $region['name'], 'area' => $area['name'] ); } // foreach($subject_classifications) } // while ($fundamental_concept) } // while ($topic) } // if($slo_area[$slo['id']]) } // while ($slo) } // while ($question_user) } // if (!empty($question_array)) } // if(!empty($ids)) } // while($area) } // while($region) } } // if (isset($_POST['selected_region'])) ?> <legend class="ftoggler" >Teacher Concept Wise Report</legend> <?php if(!empty($success)) { ?> <div class="success"><ul> <?php foreach($success as $succ) { ?> <li><?php echo $succ; ?></li> <?php } ?> </ul></div> <?php } ?> <?php if(!empty($errors)) { ?> <div class="error"><ul> <?php foreach($errors as $error) { ?> <li><?php echo $error; ?></li> <?php } ?> </ul></div> <?php } ?> <form name="frm" method="post" action=""> <select name="selected_region" style="width:315px !important;"> <option value="0">Select Region</option> <?php foreach($selected_regions as $k_cat => $v_cat) { ?> <option value="<?php echo $k_cat; ?>" <?php echo $k_cat == $_POST['selected_region'] ? 'selected="selected"' : ''; ?>> <?php echo $v_cat; ?> </option> <?php } ?> </select> <br /> <select name="grade_level" style="width:315px !important;" onChange="get_grade_level_dropdown('grade_level_class_id', this.value, this);"> <option value="0">All Grade Levels</option> <?php foreach($grade_levels as $grade_level_id => $grade_level_name) { ?> <option value="<?php echo $grade_level_id; ?>"> <?php echo $grade_level_name; ?> </option> <?php } ?> </select> <br /><br /> <input type="submit" name="generate_report" value="Generate Report" /> </form> <?php if (!empty($_POST)) { ?> <?php if (!empty($mega_array)) { ?> <br /><br /> <legend class="ftoggler" >Report</legend> <!-- export buttons --> <div id="example1_wrapper"></div> <div style="clear:both"></div> <br /><br /> <div style="overflow:auto;"> <table class="example1" cellspacing="0" width="100%"> <thead> <tr> <th>Region</th> <th>Area</th> <th>Grade Level</th> <th>Grade</th> <th>Subject</th> <th>Subject Classification</th> <th>Fundamental Concept</th> <th>Topic</th> <th>Student Learning Outcome</th> <th>APR in Current Exam</th> <th>Highest % in your Area</th> <th>Average % in TCF</th> </tr> </thead> <tbody> <?php $i =0; foreach($mega_array as $row) { ?> <tr> <td><?php echo $row['region']; ?></td> <td><?php echo $row['area']; ?></td> <td><?php echo $row['grade']; ?></td> <td><?php echo $row['class']; ?></td> <td><?php echo $row['subject']; ?></td> <td><?php echo $row['subject_classification']; ?></td> <td><?php echo $row['fundamental_concept']; ?></td> <td><?php echo $row['topic']; ?></td> <td><?php echo $row['student_learning_outcome'] ? $row['student_learning_outcome'] : '--'; ?></td> <td><?php echo $row['percentage_current_exam'].'%'; ?></td> <td><?php echo $row['percentage_your_area'].'%'; ?></td> <td><?php echo $row['percentage_avg_tcf'].'%'; ?></td> </tr> <?php $i++; } ?> </tbody> </table> </div> <?php } else { ?> <br /><br /> <legend class="ftoggler" >Report</legend> No records found against this region. <?php } ?> <?php } ?> <script> $(document).ready(function() { var grade_level = '<?php echo isset($_POST['grade_level']) ? $_POST['grade_level'] : '0'; ?>'; var grade = '<?php echo isset($_POST['grade']) ? $_POST['grade'] : '0'; ?>'; var subject = '<?php echo isset($_POST['subject']) ? $_POST['subject'] : '0'; ?>'; if (grade_level != 0) { $('select[name="grade_level"]').val(grade_level); $('select[name="grade_level"]').change(); } if (grade != 0) { setTimeout(function(){ $('select[name="grade"]').val(grade); $('select[name="grade"]').change(); }, 1000); } if (subject != 0) { setTimeout(function(){ $('select[name="subject"]').val(subject); }, 2000); } /*var table = $('table.example1').DataTable({ "aaSorting": [], buttons: true //,"bPaginate": false }); table.buttons().container().appendTo( '#example1_wrapper' );*/ var table = $('table.example1').dataTable({ "aaSorting": [] }); var tableTools = new $.fn.dataTable.TableTools(table, { "buttons": [ "copy", "csv", "xls", "pdf",{ "type": "print", "buttonText": "Print me!" } ], "sSwfPath": "<?php echo $CFG->wwwroot; ?>/assets/swf/copy_csv_xls_pdf.swf" }); $(tableTools.fnContainer()).prependTo('#example1_wrapper'); }); function get_grade_level_dropdown(context, grade_level_id, elem) { $(elem).nextAll( "select" ).remove(); var oform = $(elem).parents('form:first'); oform.find('div.error').remove(); $.ajax({ type: "POST", url : "<?php echo $CFG->wwwroot; ?>/assets/granular_report/ajax.php?context="+context+"&grade_level_id="+grade_level_id, cache : false, beforeSend : function (){ _waiting_screen("show"); }, complete : function(response, status){ _waiting_screen("hide"); if (status != "error" && status != "timeout") { if (grade_level_id != 0) { if (response.responseText != '-') { $(elem).after(response.responseText); } } } }, error : function (responseObj){ alert("Something went wrong while processing your request.\n\nError => " + responseObj.responseText); } }); } function get_grade_subject_dropdown(context, grade_id, elem) { $(elem).nextAll( "select" ).remove(); var oform = $(elem).parents('form:first'); oform.find('div.error').remove(); $.ajax({ type: "POST", url : "<?php echo $CFG->wwwroot; ?>/assets/granular_report/ajax.php?context="+context+"&grade_id="+grade_id, cache : false, beforeSend : function (){ _waiting_screen("show"); }, complete : function(response, status){ _waiting_screen("hide"); if (status != "error" && status != "timeout") { if (grade_id != 0) { if (response.responseText != '-') { $(elem).after(response.responseText); } } } }, error : function (responseObj){ alert("Something went wrong while processing your request.\n\nError => " + responseObj.responseText); } }); } </script> <?php /* Custom PHP Function - Start */ function calculate_correct_answer($slo_id, $student_id, $area, $report_type){ if ($report_type == 'tcf') { $question_sql = mysql_query("select distinct qa.id, q.name, replace(concat(u.firstname, ' ', u.lastname), '-', '') as student_name, u.id as student_id, q.category, (select qas.fraction from mdl_question_attempt_steps qas where qas.questionattemptid = qa.id and (qas.state = 'gradedright' or qas.state = 'gradedwrong')) as 'Correct Answer' from `mdl_question` q LEFT join mdl_question_attempts qa on q.id = qa.questionid LEFT join mdl_question_attempt_steps qas on qa.id = qas.questionattemptid LEFT join mdl_user u on u.id = qas.userid where q.category=".$slo_id. " group by student_name "); $students_array = array(); $question_i = 0; while($question = mysql_fetch_assoc($question_sql)) { if (!array_key_exists($question['student_id'], $students_array)) { $question_i = 0; $students_array[$question['student_id']] = array(); } if ($question['Correct Answer'] == '1.0000000') { $students_array[$question['student_id']]['questions'][$question_i] = 1; } else { $students_array[$question['student_id']]['questions'][$question_i] = 0; } $question_i++; } $percentages = array(); foreach($students_array as $s_key => $student) { $correct_answers = 0; $total_question = 0; foreach($student['questions'] as $q) { if ($q == 1) { $correct_answers++; } $total_question++; } $percentage = ($correct_answers / $total_question) * 100; $percentage = number_format($percentage, 2); $percentages[$s_key] = $percentage; } $average_percentage = array_sum($percentages) / count($percentages); $average_percentage = number_format($average_percentage, 2); return $average_percentage; } else if ($report_type == 'area') { $question_sql = mysql_query("select distinct qa.id, q.name, replace(concat(u.firstname, ' ', u.lastname), '-', '') as student_name, u.id as student_id, q.category, (select qas.fraction from mdl_question_attempt_steps qas where qas.questionattemptid = qa.id and (qas.state = 'gradedright' or qas.state = 'gradedwrong')) as 'Correct Answer' from `mdl_question` q LEFT join mdl_question_attempts qa on q.id = qa.questionid LEFT join mdl_question_attempt_steps qas on qa.id = qas.questionattemptid LEFT join mdl_user u on u.id = qas.userid LEFT join mdl_user_info_data uid on uid.userid = u.id LEFT join mdl_user_info_field uif on uif.id = uid.fieldid where q.category=".$slo_id. " and uif.shortname = 'area' and uid.data = '".$area."' group by student_name order by student_id asc "); $students_array = array(); $question_i = 0; while($question = mysql_fetch_assoc($question_sql)) { if (!array_key_exists($question['student_id'], $students_array)) { $question_i = 0; $students_array[$question['student_id']] = array(); } if ($question['Correct Answer'] == '1.0000000') { $students_array[$question['student_id']]['questions'][$question_i] = 1; } else { $students_array[$question['student_id']]['questions'][$question_i] = 0; } $question_i++; } $percentages = array(); foreach($students_array as $s_key => $student) { $total_question = 0; $correct_answers = 0; foreach($student['questions'] as $q) { if ($q == 1) { $correct_answers++; } $total_question++; } $percentage = ($correct_answers / $total_question) * 100; $percentage = number_format($percentage, 2); $percentages[$s_key] = $percentage; } return max($percentages); } else if ($report_type == 'student') { $question_sql = mysql_query("select distinct qa.id, q.name, replace(concat(u.firstname, ' ', u.lastname), '-', '') as student_name, u.id as student_id, q.category, (select qas.fraction from mdl_question_attempt_steps qas where qas.questionattemptid = qa.id and (qas.state = 'gradedright' or qas.state = 'gradedwrong')) as 'Correct Answer' from `mdl_question` q LEFT join mdl_question_attempts qa on q.id = qa.questionid LEFT join mdl_question_attempt_steps qas on qa.id = qas.questionattemptid LEFT join mdl_user u on u.id = qas.userid where q.category=".$slo_id. " and u.id=".$student_id ); $correct_answers = 0; $total_questions = 0; while($question = mysql_fetch_assoc($question_sql)) { $total_questions++; if ($question['Correct Answer'] == '1.0000000') { $correct_answers++; } } $percentage = ($correct_answers / $total_questions) * 100; $percentage = number_format($percentage, 2); return $percentage; } } function array_contains_key( array $input_array, $search_value, $case_sensitive = false) { if($case_sensitive) $preg_match = '/'.$search_value.'/'; else $preg_match = '/'.$search_value.'/i'; $return_array = array(); $keys = array_keys( $input_array ); foreach ( $keys as $k ) { if ( preg_match($preg_match, $k) ) $return_array[$k] = $input_array[$k]; } return $return_array; } class DataClosure{ public $qids; public $uids; function __construct($qids, $uids) { $this->uids = $uids; $this->qids = $qids; } function where_in_match_question_users($value) { return in_array($value["id"], $this->qids) && //question match? in_array($value["userid"], $this->uids); //user match? } function where_in_match_attemptquestions($value) { return in_array($value["userid"], $this->uids); //user match? } } /* Custom PHP Function - End */ ?> <?php echo $OUTPUT->footer(); ?>

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.