Пример #1
0
<?php

require_once '_AutoLoadClassAjax.php';
if (isset($_POST['id']) && !empty($_POST['id'])) {
    $v = new validation();
    $v->addSource($_POST);
    $v->addRule('id', 'numeric', true, 1, 99999, true);
    $v->run();
    if (sizeof($v->errors) === 0) {
        $managerLesson = new LessonManager();
        $managerQuiz = new QuizManager();
        $activity = $managerLesson->getById($v->sanitized['id']);
        if (!$activity) {
            $activity = $managerQuiz->getById($v->sanitized['id']);
        }
        if ($activity) {
            if (StudyPressUserWP::isLoggedIn()) {
                $currentUserId = new StudyPressUserWP();
                $currentUserId = $currentUserId->id();
                $managerLesson->setVisitedActivity($currentUserId, $activity->getId());
            }
        }
    }
}
Пример #2
0
}
wp_enqueue_media();
global $tr;
$managerQuiz = new QuizManager();
$managerCourse = new CourseManager();
$error_quiz_add = "";
$error_quiz_remove = "";
if (isset($_GET['type']) && $_GET['type'] === "delete" && isset($_GET['id'])) {
    $validation = new validation();
    $validation->addSource(array('id' => $_GET['id']));
    $validation->addRule('id', 'numeric', true, 0, 1000000, true);
    $validation->run();
    if (sizeof($validation->errors) > 0) {
        $error_quiz_remove = $validation->getMessageErrors();
    } else {
        $quiz = $managerQuiz->getById($validation->sanitized['id']);
        if ($quiz != null) {
            $managerQuiz->delete($validation->sanitized['id']);
            if ($managerQuiz->isError()) {
                $error_quiz_remove = $managerQuiz->getMessageError();
            }
        }
    }
}
if (isset($_POST['add'])) {
    if (isset($_POST['quiz']) && !empty($_POST['quiz'])) {
        $v = new validation();
        $v->addSource($_POST['quiz']);
        //rule Name
        $v->addRule('name', 'string', true, 1, 200, true);
        //rule Image
Пример #3
0
 require_once "_AutoLoadClassAjax.php";
 global $tr;
 $c = new Configuration();
 $c = $c->getConfig();
 if ($c['bp_shareResult'] = 'true') {
     $v = new validation();
     $v->addSource($_POST);
     $v->addRule('quizId', 'numeric', true, 1, 9999999, true);
     $v->run();
     if (sizeof($v->errors) > 0) {
         header("HTTP/1.0 400 Bad Request");
         echo $v->getMessageErrors();
     } else {
         $manager = new QuizManager();
         $type = "quiz";
         $activity = $manager->getById($v->sanitized['quizId']);
         if (!$activity) {
             $manager = new LessonManager();
             $type = "lesson";
             $activity = $manager->getById($v->sanitized['quizId']);
         }
         if ($activity) {
             if (StudyPressUserWP::isLoggedIn()) {
                 $user = new StudyPressUserWP();
                 if ($manager->isDone($v->sanitized['quizId'], $user->id())) {
                     if (function_exists('bp_is_active') && bp_is_active('groups')) {
                         $permalink = get_permalink($activity->getPostId());
                         $med_image_url = $activity->getPicture();
                         if ($type === "quiz") {
                             $resultQuiz = $manager->getResultOfQuizByUser($v->sanitized['quizId'], $user->id());
                             if (!$resultQuiz) {
Пример #4
0
    global $tr;
    $manageCourse = new CourseManager();
    $c = $manageCourse->getById($quiz->getCourseId());
    return "<div class='sp-presentation-content'>\r\n            <div>\r\n                <h4><strong>" . $tr->__("Author") . "</strong>: " . $name . "</h4>\r\n                <h4><strong>" . $tr->__("Course") . "</strong>: " . $c->getName() . "</h4>\r\n                <h4><strong>" . $tr->__("Duration") . "</strong>: " . $quiz->getDuration() . " min</h4>\r\n            </div>\r\n            <h2>" . $quiz->getName() . "</h2>\r\n\r\n        </div>";
}
if ($id !== null) {
    $currentUser = new StudyPressUserWP();
    $v = new validation();
    $v->addSource(array('id' => $id));
    $v->AddRules(array('id' => array('type' => 'numeric', 'required' => 'true', 'min' => '1', 'max' => '999999', 'trim' => 'true')));
    $v->run();
    if (sizeof($v->errors) > 0) {
        $tr->_e("The value of the identifier of the shortcode is incorrect");
    } else {
        $managerQuiz = new QuizManager();
        $quiz = $managerQuiz->getById($v->sanitized['id']);
        if ($quiz) {
            $sp_btn_share = "<button class='btn-share' title='" . $tr->__("Share") . "'>" . $tr->__("Share") . "</button>";
            $btn_buddypress_share = "";
            $btn_social_share = "";
            $v = $currentUser->isLoggedIn() ? sha1($currentUser->id()) : "";
            $path_json = "Public/Quiz/" . $quiz->getId() . $v . ".json";
            $json_file = __ROOT_PLUGIN__ . $path_json;
            $sp_user = new StudyPressUserWP($quiz->getAuthorId());
            $sp_userName = $sp_user->firstName() . ' ' . $sp_user->lastName();
            $sp_userLink = StudyPressUserWP::getUserPostsLink($quiz->getAuthorId());
            $items = array();
            $owl['items'][] = array('name' => $tr->__('Presentation'), 'content' => slide_presentation_quiz($quiz, $sp_userName));
            $resultContent = "";
            if ($spConfiguration['share_socialNetwork'] === 'true') {
                $btn_social_share = "<button class='btn-facebook' id='btn-social' title='Facebook'> <span>facebook</span ></button>";
Пример #5
0
                $responseHtml = "";
                foreach ($questionsNoConnected as $q) {
                    $responseHtml[] = $q->getContentSlideWithErrors();
                }
                $result['qcm'] = $responseHtml;
            }
            $class = (int) $poucentage >= 50 ? "green" : "red";
            $result['content'] = "<div class='sp-postit'><p>" . $tr->__("You obtained") . ":</p><strong class='" . $class . "'>" . $poucentage . "% </strong></div>";
            $result['result'] = 'true';
            echo json_encode($result);
        }
    }
}
if (isset($_POST['type']) && $_POST['type'] === "start") {
    if (isset($_POST['quizId']) && isset($_POST['date'])) {
        require_once '_AutoLoadClassAjax.php';
        global $tr;
        if (StudyPressUserWP::isLoggedIn()) {
            $date = $_POST['date'];
            $quizId = (int) $_POST['quizId'];
            $managerQuiz = new QuizManager();
            if ($quiz = $managerQuiz->getById($quizId)) {
                $user = new StudyPressUserWP();
                $managerQuiz->saveResult($quizId, $user->id(), null, null, null, null, $date, "false");
                echo "true";
            }
        } else {
            echo "true";
        }
    }
}
Пример #6
0
             }
         }
     }
     $vq->run();
     $vv->run();
     if (sizeof($vv->errors) > 0 || sizeof($vq->errors) > 0) {
         header("HTTP/1.0 400 Bad Request");
         $tr->_e("Please fill in all fields");
         exit;
     }
     if (count($vv->sanitized) !== count($checked) || count($vv->sanitized) < 2 || !in_array("true", $checked, true)) {
         header("HTTP/1.0 400 Bad Request");
         $tr->_e("Please select at least one correct answer");
         exit;
     }
     if ($managerQuiz->getById($vq->sanitized['id_quiz']) && ($question = $managerQuestion->getById($vq->sanitized['id_question']))) {
         $question->setContent($vq->sanitized['question']);
         $managerQuestion->update($vq->sanitized['id_question'], $question);
         foreach ($question->getPropositions() as $prop) {
             $managerProp->delete($prop->getId());
         }
         foreach ($vv->sanitized as $key => $value) {
             $managerProp->add(new Proposition(array('content' => $vv->sanitized[$key], 'questionId' => $question->getId(), 'type' => $checked[$key])));
         }
         echo "true";
     }
 } else {
     header("HTTP/1.0 400 Bad Request");
     $tr->_e("Please fill in all fields");
 }
 exit;
Пример #7
0
<?php

if (isset($_POST['type']) && $_POST['type'] === "get-responses") {
    if (isset($_POST['quizId']) && isset($_POST['userId'])) {
        require_once '_AutoLoadClassAjax.php';
        global $tr;
        $v = new validation();
        $v->addSource($_POST);
        $v->AddRules(array('quizId' => array('type' => 'numeric', 'required' => 'true', 'min' => '1', 'max' => '999999', 'trim' => 'true'), 'userId' => array('type' => 'numeric', 'required' => 'true', 'min' => '1', 'max' => '999999', 'trim' => 'true')));
        $v->run();
        if (sizeof($v->errors) > 0) {
            header("HTTP/1.0 400 Bad Request");
        } else {
            $managerQuiz = new QuizManager();
            if ($quiz = $managerQuiz->getById($v->sanitized['quizId'])) {
                $resultQuiz = $managerQuiz->getResultOfQuizByUser($quiz->getId(), $v->sanitized['userId']);
                if ($resultQuiz) {
                    $result['body'] = "";
                    foreach ($resultQuiz->getQuestions() as $q) {
                        $result['body'] .= $q->getContentSlideWithErrors();
                    }
                    $classe = $resultQuiz->getNote() > 50 ? "green" : "red";
                    $result['pourcentage'] = $tr->__("Note") . " : <span class='" . $classe . "'>" . $resultQuiz->getNote() . "%</span>";
                    $result['quiz'] = $tr->__("Name of quiz") . " : " . $quiz->getName();
                    $user = new StudyPressUserWP($v->sanitized['userId']);
                    $result['user'] = $tr->__("User") . " : " . $user->displayName();
                    $result['result'] = "true";
                    echo json_encode($result);
                }
            }
        }