Ejemplo n.º 1
0
 function init()
 {
     $this->course_hash = array_shift($this->param);
     $page = array_shift($this->param);
     $course = new Course();
     $training = new Training();
     $t_data = $training->get(array('course_hash' => $this->course_hash, 'user_id' => $_SESSION['user_id']));
     switch ($t_data['status_id']) {
         case Training::CREATED:
             // CREATED - ok, go on
         // CREATED - ok, go on
         case Training::STARTED:
             // STARTED - ok, go on
             $c_data = $course->get(array('id' => $t_data['course_id']));
             if ($c_data['format_id'] == Course::OFFLINE) {
                 // only Online format allowed
                 if ($c_data['exam'] == 't') {
                     $training->update($t_data['id'], array('status_id' => Training::EXAM));
                 } else {
                     $training->update($t_data['id'], array('status_id' => Training::FINISHED));
                 }
                 header('Location: /mycourses');
                 exit;
             } else {
                 $training->update($t_data['id'], array('status_id' => Training::STARTED));
             }
             break;
             break;
         case Training::DELETED:
             // DELETED - not ok
         // DELETED - not ok
         case Training::EXAM:
             // only exam, no
         // only exam, no
         case Training::FAILED:
             // try exam
         // try exam
         case Training::FINISHED:
             // register once more time
         // register once more time
         default:
             header('Location: /403');
             exit;
     }
     if (isset($page)) {
         // load iframe
         $file = preg_replace('/(\\/[a-zA-Z\\-_0-9\\.]*\\/[a-z0-9]*\\/)/', $_SERVER['DOCUMENT_ROOT'] . '/../files/courses/' . $t_data['course_id'] . '/', $_SERVER['REQUEST_URI']);
         // echo $file;
         if (file_exists($file) && is_file($file)) {
             header('Content-type:');
             readfile($file);
         } else {
             echo "Page not found";
             if ($page != 'index.html') {
                 echo "<script>window.history.back();</script>";
             }
         }
         exit;
     }
 }
Ejemplo n.º 2
0
 function init()
 {
     $this->id = array_shift($this->param);
     $course = new Course();
     $training = new Training();
     $t_data = $training->get(array('id' => $this->id, 'user_id' => $_SESSION['user_id']));
     $c_data = $course->get(array('id' => $t_data['course_id']));
     switch ($t_data['status_id']) {
         case Training::EXAM_STARTED:
             // check result for test and set status FAILED or FINISHED
             $questions = 0;
             $result = 0;
             $right_answers = 0;
             if ($t_data['finished'] < date('Y-m-d H:i', time())) {
                 $result = 0;
                 $status = Training::FAILED;
             } else {
                 $exam = new Exam();
                 $enum = $exam->enumerateResult($t_data['id']);
                 foreach ($enum as $key => $e_data) {
                     $questions++;
                     if ($e_data['result'] == 't') {
                         $right_answers++;
                     }
                 }
                 if ($questions > 0) {
                     $result = intval($right_answers * 100 / $questions);
                 }
                 if ($result >= self::MIN_RESULT_FOR_SUCCESS) {
                     $status = Training::FINISHED;
                 } else {
                     $status = Training::FAILED;
                 }
             }
             $t_data['tries'] = intval($t_data['tries']) + 1;
             $training->update($t_data['id'], array('status_id' => $status, 'result' => $result, 'answers' => $right_answers, 'questions' => $questions, 'finished' => date('Y-m-d H:i', time())));
             break;
         default:
     }
 }
Ejemplo n.º 3
0
 /**
  * Update person score in training
  */
 public static function updateScore($ptt_id, $label, $value)
 {
     if (!is_numeric($ptt_id)) {
         return false;
     }
     $scoreTable = new Training(array('name' => 'score'));
     $select = $scoreTable->select()->from('score')->setIntegrityCheck(false);
     $select->where("person_to_training_id = {$ptt_id} AND score_label = ?", $label);
     $row = $scoreTable->fetchAll($select)->toArray();
     // update
     if ($row) {
         $scoreTable->update(array('score_value' => $value), $scoreTable->getAdapter()->quoteInto("person_to_training_id = {$ptt_id} AND score_label = ?", $label));
     } else {
         $scoreTable->insert(array('person_to_training_id' => $ptt_id, 'score_label' => $label, 'score_value' => $value));
     }
 }
 /**
  * editTable ajax
  */
 private function ajaxeditTable()
 {
     if (!$this->hasACL('edit_course')) {
         $this->doNoAccessError();
     }
     $training_id = $this->_getParam('id');
     $do = $this->_getParam('edittable');
     if (!$training_id) {
         // user is adding a new session (which does not have an id yet)
         $this->sendData(array('0' => 0));
         return;
     }
     $action = $this->_getParam('a');
     $row_id = $this->_getParam('row_id');
     if ($do == 'trainer') {
         // update trainer table
         require_once 'models/table/Training.php';
         if ($action == 'add') {
             $days = $this->_getParam('days');
             $result = TrainingToTrainer::addTrainerToTraining($row_id, $training_id, $days);
             $sendRay['insert'] = $result;
             if ($result == -1) {
                 $sendRay['error'] = t('This') . ' ' . t('trainer') . ' ' . t('is already in this training session.');
             }
             $this->sendData($sendRay);
         } elseif ($action == 'del') {
             $tableObj = new TrainingToTrainer();
             $result = $tableObj->delete("id={$row_id}", true);
             $this->sendData(array('delete' => $result));
         } else {
             // update a row?
             $days = $this->_getParam('duration_days');
             if ($days) {
                 $tableObj = new TrainingToTrainer();
                 $result = $tableObj->update(array("duration_days" => $days), "id={$row_id}");
                 $sendRay['update'] = $result;
                 if (!$result) {
                     $sendRay['error'] = t('Could not update this record.');
                 }
                 $this->sendData($sendRay);
             }
         }
     } else {
         if ($do == 'persons') {
             // update person table
             require_once 'models/table/PersonToTraining.php';
             $tableObj = new PersonToTraining();
             if ($action == 'add') {
                 $result = $tableObj->addPersonToTraining($row_id, $training_id);
                 $sendRay['insert'] = $result;
                 if ($result == -1) {
                     $sendRay['error'] = t('This') . ' ' . t('participant') . ' ' . t('is already in this training session.');
                 }
                 $this->sendData($sendRay);
             } elseif ($action == 'del') {
                 $result = $tableObj->delete("id={$row_id}", true);
                 $this->sendData(array('delete' => $result));
             } else {
                 // update a row?
                 $days = $this->getSanParam('duration_days');
                 if ($days !== "") {
                     $tableObj = new PersonToTraining();
                     $result = $tableObj->update(array("duration_days" => $days), "id={$row_id}");
                     $sendRay['update'] = $result;
                     if (!$result) {
                         $sendRay['error'] = t('Could not update this record.');
                     }
                     $this->sendData($sendRay);
                 }
                 $award_id = $this->getSanParam('award_phrase');
                 if ($award_id !== "") {
                     $tableObj = new PersonToTraining();
                     $result = $tableObj->update(array("award_id" => $award_id), "id={$row_id}");
                     $sendRay['update'] = $result;
                     if (!$result) {
                         $sendRay['error'] = t('Could not update this record.');
                     }
                     $this->sendData($sendRay);
                 }
                 $viewing_loc_option_id = $this->getSanParam('location_phrase');
                 if ($viewing_loc_option_id !== "") {
                     $tableObj = new PersonToTraining();
                     $result = $tableObj->update(array("viewing_location_option_id" => $viewing_loc_option_id), "id={$row_id}");
                     $sendRay['update'] = $result;
                     if (!$result) {
                         $sendRay['error'] = t('Could not update this record.');
                     }
                     $this->sendData($sendRay);
                 }
                 $budget_code_option_id = $this->getSanParam('budget_code_phrase');
                 if ($budget_code_option_id !== "") {
                     $tableObj = new PersonToTraining();
                     $result = $tableObj->update(array("budget_code_option_id" => $budget_code_option_id), "id={$row_id}");
                     $sendRay['update'] = $result;
                     if (!$result) {
                         $sendRay['error'] = t('Could not update this record.');
                     }
                     $this->sendData($sendRay);
                 }
             }
         }
     }
     // update "modified_by" field in training table
     $tableObj = new Training();
     $tableObj->update(array(), "id = {$training_id}");
 }
Ejemplo n.º 5
0
    function displayBody()
    {
        parent::displayBody();
        $translator = new Translator();
        $course = new Course();
        $training = new Training();
        $t_data = $training->get(array('exam_hash' => $this->exam_hash, 'user_id' => $_SESSION['user_id']));
        $c_data = $course->get(array('id' => $t_data['course_id']));
        foreach ($c_data as $key => $val) {
            $c_data[$key] = htmlspecialchars($val, ENT_QUOTES);
        }
        echo <<<EOF
<div class="container-fluid">
<div class="col-lg-10 col-lg-offset-1" id="window">
\t<div class="row" >
\t<div class="col-xs-10">
\t    <h4>{$c_data[category_name]}</h4>
\t    <h2>{$c_data[name]}</h2>
\t</div>
\t<div class="col-xs-2 text-right" id="top_buttons">
\t    <a href="#" id="fullscreen"><span class="glyphicon glyphicon-fullscreen"></span></a>
\t    <a href="#" id="inscreen" class="collapse"><span class="glyphicon glyphicon-remove"></span></a>
\t</div>
\t</div>

EOF;
        try {
            $d2 = new DateTime('now');
            $diff = $d2->diff(new DateTime($t_data['finished']));
            $diff = $diff->format('%r%i');
            if ($diff < 0) {
                throw new Exception("Time out", self::TIMEOUT);
            }
            $exam = new Exam();
            $enum = $exam->enumerate(array('training_id' => $t_data['id']), intval($this->page), 1, 'id');
            $cnt = $exam->getCount(array('training_id' => $t_data['id']));
            $current = $this->page + 1;
            $back = $this->page > 0 ? $this->page - 1 : 0;
            $next = $this->page + 1;
            if (!$enum) {
                throw new Exception("Not found", self::NOTFOUND);
            }
            $e_data = $enum->current();
            $question = new Question();
            $q_data = $question->get(array('id' => $e_data['question_id']));
            echo <<<EOF
\t<div class="embed-responsive embed-responsive-16by9" id="fullscreen_media">
\t<p>{$translator->Question}: {$current} / {$cnt}</p>
\t<p> {$translator->Time_remain}: {$diff}</p>
\t{$q_data[data]}
\t<hr>
\t{$translator->Answer}: 
\t    <form action="?" method="post">
\t    <input type="hidden" name="id" value="{$e_data[id]}">
EOF;
            switch ($q_data['type_id']) {
                case Question::SINGLE:
                    echo "<ol>";
                    for ($i = 1; $i <= $q_data['count']; $i++) {
                        echo "<li><input type=\"radio\" name=\"answer\" value=\"{$i}\" " . ($i == $e_data['answer'] ? 'checked' : '') . "></li>" . NL;
                    }
                    echo "</ol>";
                    break;
                case Question::MULTI:
                    echo "<ol>";
                    $e_data['answer'] = explode(',', $e_data['answer']);
                    for ($i = 1; $i <= $q_data['count']; $i++) {
                        echo "<li><input type=\"checkbox\" name=\"answer[]\" value=\"{$i}\" " . (in_array($i, $e_data['answer']) ? 'checked' : '') . "></li>" . NL;
                    }
                    echo "</ol>";
                    break;
                case Question::TEXT:
                    echo "<input type=\"text\" name=\"answer\" value=\"{$e_data['answer']}\">" . NL;
                    break;
                default:
            }
            $back = $this->page > 0 ? $this->page - 1 : 0;
            $next = $this->page + 1;
            echo <<<EOF
\t    <input type="submit" class="btn btn-primary">
\t    </form>
\t</div>

EOF;
        } catch (Exception $e) {
            switch ($e->getCode()) {
                case self::TIMEOUT:
                    echo <<<EOF
    <div class="bs-callout bs-callout-danger" id="callout-type-b-i-elems">
    <h4>{$translator->Timeout}</h4>
    <p>{$translator->Timeout_Desc}</p>
    <p class="text-muted">{$translator->BackCourses}</p>
    </div>

EOF;
                    $training->update($t_data['id'], array('status_id' => Training::FAILED));
                    break;
                case self::NOTFOUND:
                    echo <<<EOF
    <div class="embed-responsive embed-responsive-16by9" id="fullscreen_media">
    <div class="bs-callout bs-callout-info" id="callout-type-b-i-elems">
    <h4>{$translator->Not_found}</h4>
    <p>{$translator->Not_found_Desc}</p>
    <p class="text-muted">{$translator->BackExam}</p>
    </div>
    </div>

EOF;
                    break;
                default:
                    echo $e;
                    echo <<<EOF
    <div class="bs-callout bs-callout-danger" id="callout-type-b-i-elems">
    <h4>{$translator->Error}</h4>
    <p>{$translator->Error_Desc}</p>
    <p class="text-muted">{$translator->BackExam}</p>
    </div>

EOF;
            }
            // echo "<script>window.history.back();</script>";
        }
        echo <<<EOF
\t<nav id="bottom_buttons">
\t  <ul class="pager">
\t    <li class="previous"><a href="{$back}" id="back"><span aria-hidden="true">&larr;</span> {$translator->Back}</a></li>
\t    <li class="top"><a href="0" id="top">{$translator->Top}</a>|
\t\t<a href="/result/{$t_data[id]}" onclick='return confirm("{$translator->AreYouSure}");'>{$translator->Finish}</a></li>
\t    <li class="next"><a href="{$next}" id="next">{$translator->Next} <span aria-hidden="true">&rarr;</span></a></li>
\t  </ul>
\t</nav>
</div>
</div> <!-- /container -->

EOF;
    }
Ejemplo n.º 6
0
 function dismiss($id)
 {
     $training = new Training();
     try {
         $t_data = $training->get(array('id' => $id, 'user_id' => $_SESSION['user_id']));
         $training->update($id, array('status_id' => Training::DELETED));
         header('Location: /mycourses');
         exit;
     } catch (Exception $e) {
         echo $e;
         exit;
     }
 }