Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include("config.php");
- $currentRowCount = 5;
- echo $nik;
- //function random
- function randomArrayIndex($startIndex, $endIndex, $howMany){
- $allocated = array();
- $result = array();
- for($i=$startIndex; $i<=$endIndex; $i++){
- array_push($allocated, $i);
- }
- for($i=0; $i<$howMany; $i++){
- $randIndex = rand(0, count($allocated)-1);
- array_push($result, $allocated[$randIndex]);
- array_splice($allocated, $randIndex, 1);
- //echo $result[$i];
- //echo "<br>";
- }
- return $result;
- }
- ?>
- <html>
- <head>
- <script language="JavaScript">
- var TimeOver = false;
- function getJam(Tanggal)
- {
- Jam = (Tanggal.getHours() < 10) ? "0" + Tanggal.getHours() + ":" : Tanggal.getHours() + ":"
- Jam += (Tanggal.getMinutes() < 10) ? "0" + Tanggal.getMinutes() + ":" : Tanggal.getMinutes() + ":"
- Jam += (Tanggal.getSeconds() < 10) ? "0" + Tanggal.getSeconds() : Tanggal.getSeconds()
- return Jam
- }
- function dispJam()
- {
- TglCur = new Date()
- document.User.Watch.value = getJam(TglCur)
- if (Difference <= 0)
- {
- TimeOverWarn()
- document.User.TimeLeft.value = "Habis2"
- } else
- document.User.TimeLeft.value = getWaktu()
- setTimeout("dispJam()",1000)
- }
- function getWaktu()
- {
- Difference = Difference - 1000
- TmLfHours = Math.floor(Difference/3600000)
- TmLfMinutes = Math.floor((Difference%3600000)/60000)
- TmLfSeconds = Math.round((Difference%60000)/1000)
- TmLfStr = (TmLfHours < 10) ? "0" + TmLfHours + ":" : TmLfHours + ":"
- TmLfStr += (TmLfMinutes < 10) ? "0" + TmLfMinutes + ":" : TmLfMinutes + ":"
- TmLfStr += (TmLfSeconds < 10) ? "0" + TmLfSeconds : TmLfSeconds
- return TmLfStr
- }
- function goSubmit(){
- //document.f1.submit();
- }
- function TimeOverWarn()
- {
- window.alert("\nWaktu Anda habis!!")
- //document.CheckQuestions.submit()
- TimeOver = true;
- //goSubmit();
- return true;
- }
- Tanggal = new Date()
- Tgl= new Date()
- TglStart = new Date()
- Tgl.setTime(Tgl.getTime() + 1 * 60 * 1000)
- var Difference=Tgl.getTime() - TglStart.getTime()
- ArrayBulan = new Array("Januari","Pebruari","Maret","April","Mei","Juni","Juli","Agustus","September","Oktober","Nopember","Desember")
- Tahun = (Tanggal.getYear() <= 99) ? "19" + Tanggal.getYear() : Tanggal.getYear()+1900
- TglStr = Tanggal.getDate() + " " + ArrayBulan[Tanggal.getMonth()] + " " + Tahun
- </SCRIPT>
- </head>
- <?php
- if(isset($_POST['btn'])){
- echo "Hasil :<br>";
- //$currentNik = 40;
- for($i=0;$i<$currentRowCount; $i++){
- //echo $_POST[lvl][$i];
- if($_POST[lvl][$i]==$_POST[jawab][$i]){
- $b1 = 'Benar';
- //echo $i;
- //echo $b1;
- }else{
- $b1='Salah';
- //echo $i;
- //echo $b1;
- }
- $id_soal = $_POST[id_soal][$i];
- //echo $id_soal;
- $user_jawab = $_POST[lvl][$i];
- $q="Insert into jawab (nik,id_soal,jawab_user,status_jawab,jawab_esai,periode) values ('$nik', '$id_soal', '$user_jawab','$b1', '$tx','1')";
- mysql_query($q) or die(mysql_error());
- echo $q ;
- //echo "<br>";
- }
- }else{
- ?>
- <body onload=dispJam()>
- <p align=center>Kuisioner</p>
- <form name=User><p align="center"><input size=8 name=Watch type="text"></p>
- <TABLE width="27%" align=center border=0>
- <tr><td width="21%">Tanggal</td><td width="3%">:</td><td width="33%"><SCRIPT>document.write(TglStr)</SCRIPT></td></tr>
- <tr><td width="21%">Mulai</td><td width="3%">:</td><td width="33%"><SCRIPT>document.write(getJam(TglStart))</SCRIPT></td></tr>
- <tr><td width="21%">Selesai</td><td width="3%">:</td><td width="33%"><SCRIPT>document.write(getJam(Tgl))</SCRIPT></TD></tr>
- <tr><td width="21%">Waktu</td><td width="3%">:</td><td width="33%">10 menit</td></tr>
- <tr><td width="21%">Sisa</td><td width="3%">:</td><td width="33%"><input size=8 name=TimeLeft class="textbox" type="text"></tr>
- </table>
- </form>
- <a href="javascript:TimeOverWarn()">TESTESTES</a>
- <form name="f1" method="POST" action="q_index6.php">
- <table border="0" width="548" height="94" align=center>
- <?php
- $realRowCount = mysql_num_rows(mysql_query("select * from tanya"));
- for($i=0;$i<$currentRowCount; $i++){
- php?>
- <?php
- $distance = floor($realRowCount/$currentRowCount);
- if(!isset($_POST[lvl][$i])){
- $randomedIndex = randomArrayIndex($distance*$i + 1, $distance*($i+1), 1 );
- /*echo "Random antara ";
- echo $distance*$i + 1;
- echo "-";
- echo $distance*($i+1) ;
- echo "<br>";*/
- $varRand=$randomedIndex[0];
- $query1 = "select * from tanya where ID_SOAL=$varRand";
- $result1 = mysql_query($query1);
- //echo $query;
- while($row = mysql_fetch_array($result1)){
- $id1=$row['ID_SOAL'];
- $soal1=$row['SOAL'];
- $kunci=$row['jawaban'];
- ?>
- <tr>
- <td height="26" colspan="2"><?php echo ($i+1);?>. <?php echo $soal1;?></td>
- </tr>
- <tr>
- <td height="28" width="269">
- <input type="radio" value="op1" name="lvl[<?php echo$i;?>]"> <?php echo $row['OP1'];?></td>
- <td height="28" width="269">
- <input type="radio" value="op3" name="lvl[<?php echo$i;?>]"> <?php echo $row['OP2'];?></td>
- </tr>
- <tr>
- <td height="29" width="269">
- <input type="radio" value="op2" name="lvl[<?php echo$i;?>]"> <?php echo $row['OP3'];?></td>
- <td height="29" width="269">
- <input type="radio" value="op4" name="lvl[<?php echo$i;?>]"> <?php echo $row['OP4'];?></td>
- <input type="hidden" value="<?php echo $kunci; ?>" name="jawab[<?php echo$i;?>]"> </td>
- <input type="hidden" value="<?php echo $row['ID_SOAL']; ?>" name="id_soal[<?php echo$i;?>]"> </td>
- <?php
- }
- }
- ?>
- </tr>
- <?php
- }
- ?>
- </table>
- <table width="561" height="103" align="center">
- <tr>
- <td width="553" height="38">6.<?php echo $row['SOAL'];?></td>
- </tr>
- <tr>
- <td height="57"><label for="tx"></label>
- <textarea name="tx" id="tx" cols="60" rows="5"></textarea></td>
- </tr>
- </table>
- <table border="0" width="153" height="37" align=center>
- <tr>
- <td height="33" width="147" align=center>
- <input type="submit" name="btn" value="Submit" onClick="goSubmit()">
- </td>
- </tr>
- </table>
- <p> </p>
- </form>
- </body>
- <?php };?>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement