Esempio n. 1
0
 function delQ()
 {
     //pr($_POST);
     $myid = 0;
     $qid = addslashes($_POST['qid']);
     $q = new QuizQuestion();
     if ($qid != "" && $qid != 0) {
         $q->getByID($qid);
         $myid = $q->qid;
     }
     $json = array();
     $json['bool'] = 0;
     $json['aktif'] = 0;
     $json['cnt'] = 0;
     //cek apa miliknya
     $ul = new QuizUlangan();
     $ul->getByID(addslashes($_POST['ul_id']));
     //pr($ul);
     if ($ul->ulangan_creator_id != Account::getMyID()) {
         die('not allowed');
     }
     $scc = $q->delete($qid);
     //echo "Sukses save question : ".$scc." \n<br>";
     if ($scc) {
         if ($myid == 0) {
             $myid = $scc;
         }
         //echo "Sukses question ID : ".$myid." \n<br>";
         //echo "Penyimpanan Sukses";
         $json['bool'] = 1;
         $a = new QuizAnswer();
         $arrAns = $a->getWhere("answer_qid = '{$myid}'");
         foreach ($arrAns as $n) {
             $a->delete($n->answer_id);
         }
         //cek apa jumlahnya sdh 10, kalo 10 aktif
         $cnt = $q->getJumlah("q_ulangan_id = '{$ul->ulangan_id}' AND q_aktif = 1");
         $json['cnt'] = $cnt;
         if ($cnt >= 10) {
             $json['aktif'] = 1;
             $ul->ulangan_aktif = 1;
             $ul->save();
         } else {
             $json['aktif'] = 0;
             $ul->ulangan_aktif = 0;
             $ul->save();
         }
     }
     echo json_encode($json);
     //echo "end";
     exit;
 }
Esempio n. 2
0
 function saveQ()
 {
     //pr($_POST);
     $myid = 0;
     $qid = addslashes($_POST['qid']);
     $q = new QuizQuestion();
     if ($qid != "" && $qid != 0) {
         $q->getByID($qid);
         $myid = $q->qid;
     }
     $q->q_title = addslashes($_POST['q_title']);
     $q->q_image = addslashes($_POST['q_img']);
     $q->q_ulangan_id = addslashes($_POST['ul_id']);
     $q->q_aktif = addslashes($_POST['q_aktif']);
     $scc = $q->save();
     //echo "Sukses save question : ".$scc." \n<br>";
     if ($scc) {
         if ($myid == 0) {
             $myid = $scc;
         }
         //echo "Sukses question ID : ".$myid." \n<br>";
         echo "Penyimpanan Sukses";
         $a = new QuizAnswer();
         $arrAns = $a->getWhere("answer_qid = '{$myid}'");
         foreach ($arrAns as $n) {
             $a->delete($n->answer_id);
         }
         //sekarang save baru
         for ($x = 0; $x < 4; $x++) {
             $checked = 0;
             if ($x == $_POST['radio']) {
                 $checked = 1;
             }
             $ans = addslashes($_POST['answer_' . $x]);
             $ans_img = addslashes($_POST['answer_' . $x . '_img']);
             $an = new QuizAnswer();
             $an->answer_qid = $myid;
             $an->answer_image = $ans_img;
             $an->answer_text = $ans;
             $an_id = $an->save();
             //echo "Sukses save answer $x : ".$an_id." \n<br>";
             if ($checked) {
                 $q1 = new QuizQuestion();
                 $q1->getByID($myid);
                 $q1->q_correct_answer_id = $an_id;
                 $q1->load = 1;
                 $q1->save();
             }
         }
     }
     //echo "end";
     exit;
 }