public static function submit_ul()
 {
     if ($_POST['judul_ulangan'] == "" || $_POST['ulangan_file'] == "" || $_POST['deskripsi_ulangan'] == "" || !Auth::isLogged()) {
         die('no id');
     }
     $ul = new QuizUlangan();
     if ($_GET['ups']) {
         if (!isset($_POST['ul_id'])) {
             die('no id');
         } else {
             $ul->getByID(addslashes($_POST['ul_id']));
             if ($ul->ulangan_creator_id != Account::getMyID()) {
                 die('not allowed');
             }
             $ul->load = 1;
         }
     }
     $json['bool'] = 0;
     $ul->ulangan_level_id = 0;
     $ul->ulangan_aktif = 0;
     $ul->ulangan_name = addslashes($_POST['judul_ulangan']);
     $ul->ulangan_image = addslashes($_POST['ulangan_file']);
     $ul->ulangan_descr = addslashes($_POST['deskripsi_ulangan']);
     $ul->ulangan_fb_image = addslashes($_POST['ulangan_file']);
     $ul->ulangan_creator_id = Account::getMyID();
     $ul->ulangan_jumlah_soal = 10;
     $scc = $ul->save();
     if ($scc) {
         $json['bool'] = 1;
         $json['ul_id'] = $scc;
     }
     echo json_encode($json);
     exit;
 }
    function Ulangan_Full()
    {
        $id = addslashes($_GET['id']);
        if ($id == "") {
            die('no id');
        }
        $ul = new QuizUlangan();
        $ul->getByID($id);
        //pr($ul);
        $lv = new QuizLevel();
        $lv->getByID($ul->ulangan_level_id);
        ?>
<style>
    .quest{
        padding: 20px;
        border-bottom: 1px solid #dedede;
    }    
    .answer{
        padding: 20px;
        padding-left: 30px;
    }
    .choice{
        padding: 10px;
    }
</style>
<h1><?php 
        echo $ul->ulangan_name;
        ?>
</h1>    
<p><?php 
        echo $lv->level_name;
        ?>
</p>
<hr>
        <?php 
        $q = new QuizQuestion();
        $arrQ = $q->getWhere("q_ulangan_id = '{$ul->ulangan_id}'");
        $cnt = 1;
        foreach ($arrQ as $q) {
            ?>
<div id="newform_<?php 
            echo $cnt;
            ?>
">
<div class="quest">
    <form class="form-inline" id="form_q_<?php 
            echo $cnt;
            ?>
" >
        <div class="form-group">
            <label for="question_<?php 
            echo $q->qid;
            ?>
_title"><?php 
            echo $cnt;
            $cnt++;
            ?>
.</label>
            <input style="min-width: 500px;" id="question_<?php 
            echo $cnt;
            ?>
_title" class="form-control" type="text" value="<?php 
            echo $q->q_title;
            ?>
">
   
        </div>
        <div class="form-group">
            
             Active : <input id="question_<?php 
            echo $cnt;
            ?>
_aktif" class="form-control" type="text" value="<?php 
            echo $q->q_aktif;
            ?>
">
   
        </div>
        <div class="form-group">
            <?php 
            $if = new Leap\View\InputFoto("question_" . $cnt . "_file", "question_" . $cnt . "_file", $q->q_image);
            $if->p();
            ?>
            <?php 
            /*<input id="question_<?=$q->qid;?>_file" class="form-control" type="file" value="<?=$q->q_image;?>">*/
            ?>
        </div>
    
    <div class="answer">
        <?php 
            $ans = new QuizAnswer();
            $arrAns = $ans->getWhere("answer_qid = '{$q->qid}'");
            $arrAns = array_reverse($arrAns);
            for ($x = 0; $x < 4; $x++) {
                $ans = array_pop($arrAns);
                if (!isset($ans)) {
                    $ans = new QuizAnswer();
                }
                $checked = "";
                if ($ans->answer_id == $q->q_correct_answer_id) {
                    $checked = "checked";
                }
                ?>
        <div class="choice">
            
        
           <div class="form-group">
               <input <?php 
                echo $checked;
                ?>
 type="radio" name="radio_<?php 
                echo $cnt;
                ?>
" value="<?php 
                echo $x;
                ?>
"> 
           </div>
           <div class="form-group">
               <input id="answer_title_<?php 
                echo $cnt;
                ?>
_<?php 
                echo $x;
                ?>
" type="text" style="min-width: 300px;" value="<?php 
                echo $ans->answer_text;
                ?>
" class="form-control"> 
           </div>
           <div class="form-group">
                <?php 
                $if = new Leap\View\InputFoto("answer_file_{$cnt}_{$x}", "answer_file_{$cnt}_{$x}", $ans->answer_image);
                $if->p();
                ?>

           </div>
       
            
        </div>
                <?php 
            }
            ?>
    </div>
        <button class="btn btn-default" id="formbutton_q_<?php 
            echo $cnt;
            ?>
" onclick="doSave('<?php 
            echo $cnt;
            ?>
','<?php 
            echo $q->qid;
            ?>
',event);">Save Q and A</button>
    </form>
    
</div>
</div>
            <?php 
        }
        ?>
<script>
        function doSave(cnt,qid,event){
            
            event.preventDefault();
            var answer_0 = $('#answer_title_'+cnt+'_0').val();
            var answer_0_img = $('#answer_file_'+cnt+'_0').val();
            //alert(answer_1+' '+answer_1_img);
            
            var answer_1 = $('#answer_title_'+cnt+'_1').val();
            var answer_1_img = $('#answer_file_'+cnt+'_1').val();
            //alert(answer_2+' '+answer_2_img);
            
            var answer_2 = $('#answer_title_'+cnt+'_2').val();
            var answer_2_img = $('#answer_file_'+cnt+'_2').val();
            //alert(answer_3+' '+answer_3_img);
            
            var answer_3 = $('#answer_title_'+cnt+'_3').val();
            var answer_3_img = $('#answer_file_'+cnt+'_3').val();
            //alert(answer_4+' '+answer_4_img);
            
            //var qid = <?php 
        echo $q->qid;
        ?>
;
            
            var q_title = $('#question_'+cnt+'_title').val();
            var q_img = $('#question_'+cnt+'_file').val();
            
            var radio = $('input[name=radio_'+cnt+']:checked').val();
            
            var q_aktif = $('#question_'+cnt+'_aktif').val();
            //alert(radio+' '+qid+' '+q_title+' '+q_img+' '+answer_0+' '+answer_0_img+' '+answer_1+' '+answer_1_img+' '+answer_2+' '+answer_2_img+' '+answer_3+' '+answer_3_img);
            
            $.post('<?php 
        echo _SPPATH;
        ?>
UlWeb/saveQ',
            {
                radio:radio,
                qid : qid,
                q_title : q_title,
                q_img : q_img,
                q_aktif: q_aktif,
                answer_0 : answer_0,
                answer_0_img : answer_0_img,
                answer_1 : answer_1,
                answer_1_img : answer_1_img,
                answer_2 : answer_2,
                answer_2_img : answer_2_img,
                answer_3 : answer_3,
                answer_3_img : answer_3_img,
                ul_id : '<?php 
        echo $id;
        ?>
',
            }
            ,function(data){
                alert(data);
                location.reload();
            });
        }
 </script>
<div id="tambahanform"></div>
<div style="padding: 30px; text-align: center;">
    <button class="btn btn-primary btn-lg" onclick="addform();">Add more Questions</button>   
</div>
<script>
    var jumlahform = <?php 
        echo $cnt;
        ?>
;
function addform(){
    $('#tambahanform').append('<div id="newform_'+jumlahform+'"></div>');
    
    $('#newform_'+jumlahform).load('<?php 
        echo _SPPATH;
        ?>
UlWeb/newform?jml='+jumlahform);
    jumlahform++;
    
}    
</script>
         <?php 
    }
Example #3
0
 function hapus_ul($args)
 {
     list($id) = $args;
     if (!isset($id) || $id < 1) {
         die('no proper id');
     }
     $ul = new QuizUlangan();
     $ul->getByID($id);
     if ($ul->ulangan_creator_id == Account::getMyID() && !$ul->ulangan_aktif) {
         $ul->delete($id);
         //$ul->ulangan_aktif = 0;
         //$ul->save();
         $q = new QuizQuestion();
         $arr = $q->getWhere("q_ulangan_id = '{$id}'");
         foreach ($arr as $qq) {
             $q->delete($qq->qid);
             $a = new QuizAnswer();
             $arr2 = $a->getWhere("answer_qid = '{$qq->qid}'");
             foreach ($arr2 as $aa) {
                 $a->delete($aa->answer_id);
             }
         }
     }
 }
Example #4
0
 public function hitung($args)
 {
     //pr($_POST);
     $jwb = $_POST['jwb'];
     $qid = $_POST['qid'];
     if (!isset($qid)) {
         die("No ID");
     }
     $ul = new QuizUlangan();
     $ul->getByID($qid);
     //update number
     $ul->ulangan_finished = $ul->ulangan_finished + 1;
     $ul->ulangan_update_date = leap_mysqldate();
     $ul->save();
     // user gen
     $acc = new Account();
     $ucreate = 0;
     if ($ul->ulangan_creator_id != 0) {
         $ucreate = 1;
         $acc->getByID($ul->ulangan_creator_id);
     }
     $ucreate_text = "Seberapa Indonesiakah Anda";
     //campur badge
     if ($ucreate) {
         $ul->ulangan_badge_1 = $ul->ulangan_image;
         $ul->ulangan_badge_2 = $ul->ulangan_image;
         $ul->ulangan_badge_3 = $ul->ulangan_image;
         $ul->ulangan_badge_4 = $ul->ulangan_image;
         $ul->ulangan_badge_5 = $ul->ulangan_image;
         $ucreate_text_title = $ul->ulangan_name;
         $ucreate_text = $acc->admin_name . " membuat ujian '" . $ul->ulangan_name . "' untuk INDONESIA. Berani terima tantangan dia?!?";
         $ul->ulangan_desc_1 = $ucreate_text;
         $ul->ulangan_desc_2 = $ucreate_text;
         $ul->ulangan_desc_3 = $ucreate_text;
         $ul->ulangan_desc_4 = $ucreate_text;
         $ul->ulangan_desc_5 = $ucreate_text;
         $ul->ulangan_descr = $ucreate_text;
     }
     $q = new QuizQuestion();
     $arrQ = $q->getWhere("q_ulangan_id = '{$ul->ulangan_id}' AND q_aktif = 1");
     //pr($arrQ);
     $jumlah_question = $ul->ulangan_jumlah_soal;
     foreach ($arrQ as $q) {
         $qs[$q->qid] = $q;
     }
     $point = 0;
     foreach ($jwb as $o) {
         $active = $qs[$o['qid']];
         if ($active->q_correct_answer_id == $o['aid']) {
             $point++;
         }
         //echo $o['qid']." jwb ".$o['aid']."<br>";
     }
     //pilah poin ke badge
     if ($point == 0) {
         $json['badge'] = _BPATH . _PHOTOURL . "thumbnail/" . $ul->ulangan_badge_1;
     }
     if ($point > 0 && $point < 6) {
         $json['badge'] = _BPATH . _PHOTOURL . "thumbnail/" . $ul->ulangan_badge_2;
     }
     if ($point > 5 && $point < 8) {
         $json['badge'] = _BPATH . _PHOTOURL . "thumbnail/" . $ul->ulangan_badge_3;
     }
     if ($point > 7 && $point < 10) {
         $json['badge'] = _BPATH . _PHOTOURL . "thumbnail/" . $ul->ulangan_badge_4;
     }
     if ($point == 10) {
         $json['badge'] = _BPATH . _PHOTOURL . "thumbnail/" . $ul->ulangan_badge_5;
     }
     $json['points'] = $point;
     $json['saved'] = 0;
     $json['naik_level'] = 0;
     $json['total_point'] = -1;
     $qp = new QuizPoints();
     if (Auth::isLogged()) {
         $pid = $qid . "_" . Account::getMyID();
         $qp->getByID($pid);
         if ($qp->points_id == "") {
             $qp->load = 0;
         }
         $qp->points_id = $pid;
         $qp->points_acc_id = Account::getMyID();
         $qp->points_ul_id = $qid;
         $qp->points_update = leap_mysqldate();
         if ($qp->points_nilai < $point) {
             $qp->points_nilai = $point;
         }
         $json['saved'] = $qp->save();
         $pointLama = QuizPoints::myPoints();
         $lvl_lama = floor($pointLama / 36);
         //update sessions points
         $qp->getPoints();
         $pointBaru = QuizPoints::myPoints();
         $lvl_baru = floor($pointBaru / 36);
         if ($lvl_baru > $lvl_lama && $pointLama > 0) {
             $json['naik_level'] = 1;
         }
         $json['total_point'] = $pointBaru;
     } else {
         if (!isset($_SESSION['game']['unsaved'])) {
             $_SESSION['game']['unsaved'] = array();
         }
         $_SESSION['game']['unsaved'][] = array($qid, $point);
     }
     echo json_encode($json);
     exit;
 }