Advertisement
cdsatrian

daftar_nilai_ujian.php

Jun 3rd, 2014
284
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.76 KB | None | 0 0
  1. <?php
  2. // current time
  3. $mtime = microtime();
  4. // split seconds and microseconds
  5. $mtime = explode(" ",$mtime);
  6. // create a single value for statr time
  7. $mtime = $mtime[1] + $mtime[0];
  8. $tstart = $mtime;
  9. include_once "include/koneksi.php";
  10. $id_mp = $_REQUEST['id_mp'];
  11. $jml_lulus=isset($_REQUEST['jml'])?$_REQUEST['jml']:10;
  12. $nama_mp = mysql_result(mysql_query("SELECT nama_mp FROM mapel WHERE id_mp='".$id_mp."'"),0);
  13. //ambil data ujian pada id_mp ini sebagai header
  14. $sql_head = "SELECT id_ujian,nama_ujian FROM ujian where id_mp='".$id_mp."'";
  15. $sql_head_exe = mysql_query($sql_head);
  16. $head_id_ujian = array();
  17. $nama_ujian=array();
  18. $sql_nilai='';
  19. while($head = mysql_fetch_assoc($sql_head_exe)){
  20.   array_push($head_id_ujian,$head['id_ujian']);
  21.   $sql_nilai.="SUM(IF(d.id_ujian=".$head['id_ujian'].",d.nilai,0)) AS nilai_".$head['id_ujian'].",";
  22.   array_push($nama_ujian,$head['nama_ujian']);
  23. }
  24. ?>
  25. <div style="width:80%;margin:0 auto" class="daftar_pelajaran">
  26. <fieldset>
  27. <legend>Daftar Nilai Ujian Mata Pelajaran <?php echo ucwords($nama_mp) ?></legend>
  28. <div style="margin-bottom:10px"><span onclick="download_ini()" class="tombol">Download as xls</span></div>
  29. <div>Jumlah diterima <input type='text' name='jml' id='jml' value='<?php echo $jml_lulus;?>' onchange="lihat_nilai_ujian(<?php echo $id_mp;?>,this.value);"></div>
  30. <table class='listing' cellpadding='0' cellspacing='0' align='center'>
  31. <thead>
  32. <tr>
  33. <th>No</th><th>NIS</th><th>Nama</th><th><?php echo implode("</th><th>",$nama_ujian);?></th><th>Rerata</th><th>Status</th><th>Aksi</th>
  34. </tr>
  35. </thead>
  36. <tbody>
  37. <?php
  38. if(count($head_id_ujian) > 0){
  39.   $sql="SELECT s.*,@curRank := @curRank + 1 AS rank
  40.        FROM
  41.          (SELECT
  42.           a.nis,
  43.           a.nama,"
  44.             .$sql_nilai
  45.            ."SUM(IF(ISNULL(d.nilai),0,d.nilai))/".count($head_id_ujian)." as rerata
  46.         FROM siswa a
  47.           LEFT JOIN (
  48.             SELECT b.*
  49.             FROM nilai b
  50.             LEFT JOIN ujian c ON b.id_ujian=c.id_ujian
  51.             WHERE c.id_mp='".$id_mp."'
  52.           ) d  ON a.nis=d.id_user
  53.         GROUP BY a.nis
  54.         ORDER BY rerata DESC) s,
  55.         (SELECT @curRank := 0) r
  56.         ORDER BY s.rerata DESC";
  57.   $result = mysql_query($sql);
  58.   $no=1;
  59.   while($data = mysql_fetch_assoc($result)){
  60.     echo "<tr>";
  61.     echo "<td>".$no++."</td>";
  62.     echo "<td class='nis'>".$data['nis']."</td>";
  63.     echo "<td>".$data['nama']."</td>";
  64.     for($i = 0;$i < count($head_id_ujian); $i++){        
  65.       echo "<td class='nilai' title='".$head_id_ujian[$i]."'>"
  66.            .(empty($data['nilai_'.$head_id_ujian[$i]])?"--":number_format($data['nilai_'.$head_id_ujian[$i]],1))
  67.            ."</td>";
  68.     }
  69.     echo "<td>".number_format($data['rerata'],3)."</td>";
  70.     echo "<td>".($data['rank']<=$jml_lulus?'LULUS':'TIDAK LULUS')."</td>";
  71.     echo "<td><span class='tombol_mini edit' onclick='edit_nilai(this)'>Nilai</span></td>";
  72.     echo "</tr>";
  73.   }
  74. }
  75. else {
  76.   echo "<tr><td colspan='5'>Belum ada ujian yang dibuat</td></tr>";
  77. }
  78. ?>
  79. </tbody>
  80. </table>
  81. <div style='color:#1717BF;font-size:90%;font-weight:bolder;font-style:italic'>--- &nbsp;&nbsp;berarti belum dikerjakan</div>
  82. <?php
  83. // current time
  84. $mtime = microtime();
  85. // split seconds and microseconds
  86. $mtime = explode(" ",$mtime);
  87. // create a single value for statr time
  88. $mtime = $mtime[1] + $mtime[0];
  89. $tend = $mtime;
  90. // hitung waktu eksekusi
  91. $totaltime = ($tend - $tstart);
  92. // Output the result
  93. printf ("This page was generated in %f seconds.", $totaltime);
  94. ?>
  95. <div class="kembali" onclick="kembali_lagi()">Kembali</div>
  96. <script >      
  97. function kembali_lagi(){
  98.   $("#content").html(info_loading).load("daftar_nilai_mp.php");
  99. }
  100. function download_ini(){
  101.   var id_mp = "<?php echo $id_mp ?>";
  102.   window.open("daftar_nilai_ujian_xls.php?id_mp="+id_mp);
  103. }
  104. function edit_nilai(elm){
  105.   var tmb_reset = "<span style='margin-left:5px' class='hapus' onclick='reset_nilai(this)'></span>";
  106.   $(elm).parent().parent().find("td.nilai").each(function(){
  107.     if($(this).text() != "--"){
  108.       $(tmb_reset).appendTo(this);
  109.     }
  110.   })
  111. }
  112. function reset_nilai(elm){
  113.   var nis = $(elm).parent().parent().find("td.nis").eq(0).text();
  114.   var id_ujian = $(elm).parent().attr("title");
  115.   // hapus nilai siswa pada ujian tersebut
  116.   var url = "hapus_nilai_ujian.php";
  117.   $.post(url,{nis:nis,id_ujian:id_ujian},function(hasil){
  118.     if(hasil == 1){
  119.       $(elm).parent().css({"background":"#BBEEBB"}).text("---");
  120.     }
  121.     else {
  122.       alert("gagal dihapus .......");
  123.     }      
  124.   })
  125. }              
  126. function lihat_nilai_ujian(id_mp,jml){
  127.     // load content dengan data dari daftar_ujian.php
  128.     $("#content").html(info_loading).load("daftar_nilai_ujian.php?id_mp="+id_mp+"&jml="+jml);
  129. }
  130. </script>
  131. </script>
  132. <style>
  133. .hapus:hover{
  134.   cursor:pointer;
  135. }
  136. </style>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement