<commit_before><?php

defined('BASEPATH') OR exit('No direct script access allowed');

class MainController extends CI_Controller {

    public function __construct() {
        parent::__construct();
    }

    public function changeStatus($rKey, $rStatus) {
        if ($rStatus == 0) {
            $sql = 'update roomdim set rStatus = 1 where rKey = ' . $rKey;
        } else {
            $sql = 'update roomdim set rStatus = 0 where rKey = ' . $rKey;
            $sql2 = 'update studentdim set rKey = NULL where rKey = ' . $rKey;
            $this->ExamModel->QueryBySQL($sql2);
        }
        $this->ExamModel->QueryBySQL($sql);
        redirect('index.php/MainController/roomDetail/' . $rKey . '/t', 'refresh');
        exit();
    }

    public function createExam($userKey) {
        if ($this->input->post('btnSave')) {
            $chapter['chapter'] = $this->input->post('chapter');
            $numOfQuestion = $this->input->post('numberOfQues');
            $numOfChapter = count($chapter, COUNT_RECURSIVE);
            $chap = '';
            $text = 'chapterKey = ';
            for ($i = 0; $i < $numOfChapter - 1; $i++) {
                $chap = $chap . $text . $chapter['chapter'][$i];
                if ($i < $numOfChapter - 2) {
                    $chap = $chap . ' or ';
                }
            }
            $condition = 'where ' . $chap;
            $sql = 'select * from questiondim ' . $condition . ' order by RAND() limit ' . $numOfQuestion;
            $result = $this->ExamModel->getData($sql);

            $quesKey = '';
            foreach ($result as $r) {
                $quesKey = $quesKey . $r['quesKey'] . ',';
            }
            $exam = array(
                'examText' => $this->input->post('examText'),
                'questionKey' => substr($quesKey, 0, -1),
                'tKey' => $userKey
            );
            $this->ExamModel->insertToExam($exam);
            redirect('index.php/MainController/manageExam/' . $userKey, 'refresh');
            exit();
        }
    }

    public function getQuestion($quesID) {
        $n = count($quesID);
        $Condition = '';
        $text = 'quesKey = ';
        for ($i = 0; $i < $n; $i++) {
            $Condition = $Condition . $text . $quesID[$i];
            if ($i != $n - 1) {
                $Condition = $Condition . ' or ';
            }
        }
        $sql = 'select quesKey,quesText from questiondim where ' . $Condition;
        return $this->ExamModel->getData($sql);
    }

    public function joinToRoom($rKey, $sKey) {
        $sql1 = 'select rKey from studentdim where sKey = ' . $sKey;
        $result = $this->ExamModel->getData($sql1);
        $sql2 = 'select rStatus from roomdim where rKey = ' . $rKey;
        $rs = $this->ExamModel->getData($sql2);
        $sql3 = 'select questionKey from examinationdim where examKey = (select examKey from roomDim where rKey = ' . $rKey . ')';
        $questionKey = $this->ExamModel->getData($sql3);
        //test again by noy use github in desktop
        $quesID = explode(',', $questionKey[0]['questionKey']);

        // $data['rs'] = $this->getQuestion($quesID);
        $data['rs'] = $quesID;
        if ($result[0]['rKey'] == NULL) {
            if ($rs[0]['rStatus'] == 1) {
                $sql = 'update studentdim set rKey = ' . $rKey . ' where sKey = ' . $sKey;
                $this->ExamModel->QueryBySQL($sql);

                $data['page'] = 'roomPageStudent';
                $this->load->view('Template/template', $data);
            } else {
                redirect('index.php/MainController/roomDetail/' . $sKey . '/s', 'refresh');
                exit();
            }
        } else if ($result[0]['rKey'] == $rKey) {
            $data['page'] = 'roomPageStudent';
            $this->load->view('Template/template', $data);
        } else {
            redirect('index.php/MainController/roomDetail/' . $sKey . '/s', 'refresh');
            exit();
        }<commit_msg>add ajax to do exam<commit_after><?php

defined('BASEPATH') OR exit('No direct script access allowed');

class MainController extends CI_Controller {

    public function __construct() {
        parent::__construct();
    }

    public function changeStatus($rKey, $rStatus) {
        if ($rStatus == 0) {
            $sql = 'update roomdim set rStatus = 1 where rKey = ' . $rKey;
        } else {
            $sql = 'update roomdim set rStatus = 0 where rKey = ' . $rKey;
            $sql2 = 'update studentdim set rKey = NULL where rKey = ' . $rKey;
            $this->ExamModel->QueryBySQL($sql2);
        }
        $this->ExamModel->QueryBySQL($sql);
        redirect('index.php/MainController/roomDetail/' . $rKey . '/t', 'refresh');
        exit();
    }

    public function createExam($userKey) {
        if ($this->input->post('btnSave')) {
            $chapter['chapter'] = $this->input->post('chapter');
            $numOfQuestion = $this->input->post('numberOfQues');
            $numOfChapter = count($chapter, COUNT_RECURSIVE);
            $chap = '';
            $text = 'chapterKey = ';
            for ($i = 0; $i < $numOfChapter - 1; $i++) {
                $chap = $chap . $text . $chapter['chapter'][$i];
                if ($i < $numOfChapter - 2) {
                    $chap = $chap . ' or ';
                }
            }
            $condition = 'where ' . $chap;
            $sql = 'select * from questiondim ' . $condition . ' order by RAND() limit ' . $numOfQuestion;
            $result = $this->ExamModel->getData($sql);

            $quesKey = '';
            foreach ($result as $r) {
                $quesKey = $quesKey . $r['quesKey'] . ',';
            }
            $exam = array(
                'examText' => $this->input->post('examText'),
                'questionKey' => substr($quesKey, 0, -1),
                'tKey' => $userKey
            );
            $this->ExamModel->insertToExam($exam);
            redirect('index.php/MainController/manageExam/' . $userKey, 'refresh');
            exit();
        }
    }

    public function getQuestion($quesID) {
        $n = count($quesID);
        $Condition = '';
        $text = 'quesKey = ';
        for ($i = 0; $i < $n; $i++) {
            $Condition = $Condition . $text . $quesID[$i];
            if ($i != $n - 1) {
                $Condition = $Condition . ' or ';
            }
        }
        $sql = 'select quesKey,quesText from questiondim where ' . $Condition;
        return $this->ExamModel->getData($sql);
    }

    public function joinToRoom($rKey, $sKey) {
        $sql1 = 'select rKey from studentdim where sKey = ' . $sKey;
        $result = $this->ExamModel->getData($sql1);
        $sql2 = 'select rStatus from roomdim where rKey = ' . $rKey;
        $rs = $this->ExamModel->getData($sql2);

        $sql3 = 'select questionKey from examinationdim where examKey = (select examKey from roomDim where rKey = ' . $rKey . ')';
        $questionKey = $this->ExamModel->getData($sql3);
        //test again by noy use github in desktop
        if (count($questionKey) != 0) {
            $quesID = explode(',', $questionKey[0]['questionKey']);
            // $data['rs'] = $this->getQuestion($quesID);
            $data['rs'] = $quesID;
            $data['numOfQues'] = count($quesID);
      
        }
        if ($result[0]['rKey'] == NULL) {
            if ($rs[0]['rStatus'] == 1) {
                $sql = 'update studentdim set rKey = ' . $rKey . ' where sKey = ' . $sKey;
                $this->ExamModel->QueryBySQL($sql);
                $data['page'] = 'testDoExam';
                //$data['page'] = 'roomPageStudent';
                $this->load->view('Template/template', $data);
            } else {
                redirect('index.php/MainController/roomDetail/' . $sKey . '/s', 'refresh');
                exit();
            }
        } else if ($result[0]['rKey'] == $rKey) {
            $data['page'] = 'testDoExam';
            //$data['page'] = 'roomPageStudent';
            $this->load->view('Template/template', $data);
        } else {
            redirect('index.php/MainController/roomDetail/' . $sKey . '/s', 'refresh');
            exit();
        }
{'fraction_non_alphanumeric': 0.17089305402425578, 'fraction_numerical': 0.005757687124831557, 'mean_word_length': 1.7806539509536785, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 71, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2128088', 'n_tokens_mistral': 2515, 'n_tokens_neox': 2429, 'n_words': 529}