<?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()); } } } }
<?php if (!defined('ABSPATH')) { exit; } 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();
public function getActivitiesOfCourse($courseId) { $activities = array(); $result = $this->_access->getResults($this->_access->prepare("SELECT * FROM " . StudyPressDB::getTableNameActivity() . " WHERE " . StudyPressDB::COL_ID_COURSE_ACTIVITY . " = '%d' ORDER BY " . StudyPressDB::COL_ORDER_ACTIVITY . " ASC", $courseId)); foreach ($result as $row) { $activity = array(); if ($row[StudyPressDB::COL_TYPE_ACTIVITY] === "lesson") { $activity = LessonManager::returnedLesson($row); } else { $activity = QuizManager::returnedQuiz($row); } if ($activity) { $activities[] = $activity; } } return $activities; }
if (isset($_POST['type']) && $_POST['type'] === "share-groups") { if (isset($_POST['quizId']) && !empty($_POST['quizId']) && isset($_POST['groups'])) { 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") {
<?php global $tr; if (isset($_POST['type']) && $_POST['type'] === "post") { if (isset($_POST['id'])) { require_once '_AutoLoadClassAjax.php'; $managerQuiz = new QuizManager(); $v = new validation(); $v->addSource($_POST); $v->AddRules(array('id' => 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 { $quiz = $managerQuiz->getById($v->sanitized['id']); if ($quiz) { $btn_post = "<button type='button' id='post-quiz' data-id='" . $quiz->getId() . "' class='btn btn-primary'>" . $tr->__("Publish") . "</button>"; $btn_remove = "<button type='button' id='post-quiz' data-id='" . $quiz->getId() . "' class='btn btn-danger'>" . $tr->__("Remove") . "</button>"; if ($quiz->getPostId() === 0) { $postId = $managerQuiz->post($quiz); if (AbstractActivityManager::isBuddyPressActive()) { $permalink = get_permalink($postId); $action = $quiz->getAuthor() . " " . $tr->__("shared a quiz") . " : " . "<a href='{$permalink}'>" . $quiz->getName() . "</a>"; $imageUrl = $quiz->getPicture(); $content = "<a href='{$permalink}'><img src='{$imageUrl}' width='150' height='150' /></a>"; $managerQuiz->shareOnGroupsBP($quiz, $action, $content); } $result['result'] = "true"; $result['value'] = $btn_remove; echo json_encode($result); } else {
{ 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') {
$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"; } } }
<?php if (!defined('ABSPATH')) { exit; } wp_enqueue_media(); global $tr; $user = new StudyPressUserWP(); $managerQuiz = new QuizManager(); $managerCourse = new CourseManager(); $quiz = null; $error_quiz_update = ""; $error_quiz_add_question = ""; if (isset($_GET['id']) && !empty($_GET['id'])) { $v = new validation(); $v->addSource($_GET); $v->addRule('id', 'numeric', true, 1, 9999999, true); $v->run(); if (!sizeof($v->errors) > 0) { $quiz = $managerQuiz->getById($v->sanitized['id']); if ($quiz) { if (isset($_POST['update'])) { //var_dump($_POST); $v = new validation(); $v->addSource($_POST['quiz']); $v->AddRules(array('id' => array('type' => 'numeric', "required" => true, 'min' => '1', 'max' => '999999', 'trim' => true), 'name' => array('type' => 'string', "required" => true, 'min' => '1', 'max' => '400', 'trim' => true), 'description' => array('type' => 'string', "required" => true, 'min' => '0', 'max' => '999999', 'trim' => true), 'duree' => array('type' => 'numeric', "required" => true, 'min' => '0', 'max' => '999999', 'trim' => true), 'pictureurl' => array('type' => 'numeric', "required" => false, 'min' => '0', 'max' => '999999', 'trim' => true), 'courseId' => array('type' => 'numeric', "required" => false, 'min' => '0', 'max' => '999999', 'trim' => true))); $v->run(); $notes = isset($_POST['quiz']['note']) ? json_encode($_POST['quiz']['note']) : ""; $glossaires = isset($_POST['quiz']['glossary']) ? json_encode($_POST['quiz']['glossary']) : ""; if (sizeof($v->errors) > 0) { $error_quiz_update = $v->getMessageErrors();
foreach ($question->getPropositions() as $key => $prop) { $result['propositions'][$key]['content'] = $prop->getContent(); $result['propositions'][$key]['true'] = $prop->getType(); } $result['result'] = "true"; echo json_encode($result); } else { $result['result'] = "false"; echo json_encode($result); } } } } if (isset($_POST['type']) && $_POST['type'] === "update-question") { if (isset($_POST['id_quiz']) && isset($_POST['value']) && isset($_POST['checked']) && isset($_POST['question']) && isset($_POST['id_question'])) { $managerQuiz = new QuizManager(); $managerQuestion = new QuestionManager(); $managerProp = new PropositionManager(); $vq = new validation(); $vv = new validation(); $vq->addSource($_POST); $vv->addSource($_POST['value']); $vq->AddRules(array('question' => array('type' => 'string', 'required' => 'true', 'min' => '1', 'max' => '9999', 'trim' => 'true'), 'id_quiz' => array('type' => 'numeric', 'required' => 'true', 'min' => '1', 'max' => '999999', 'trim' => 'true'), 'id_question' => array('type' => 'numeric', 'required' => 'true', 'min' => '1', 'max' => '999999', 'trim' => 'true'))); foreach ($_POST['value'] as $key => $value) { if (preg_match('/^[0-9]{1,}$/', $key)) { $vv->addRule($key . "", 'string', true, 1, 99999, true); } } $checked = array(); //rules checked foreach ($_POST['checked'] as $key => $value) {
<?php /** * Created by PhpStorm. * User: Salim * Date: 25/02/2015 * Time: 13:37 */ if (isset($_POST['id_quiz'])) { require_once '_AutoLoadClassAjax.php'; global $tr; $managerQuiz = new QuizManager(); $v = new validation(); $v->addSource($_POST); $v->AddRules(array('id_quiz' => array('type' => 'numeric', 'required' => 'true', 'min' => '1', 'max' => '999999', 'trim' => 'true'))); $v->run(); /* * Si un/des champs ne est/sont pas valide(s)... * */ if (sizeof($v->errors) > 0) { header("HTTP/1.0 400 Bad Request"); } else { $quiz = $managerQuiz->getById($v->sanitized['id_quiz']); if ($quiz) { $result = ""; if (count($quiz->getQuestions())) { foreach ($quiz->getQuestions() as $question) { ?> <li id="li-sotable" class="ui-state-default btn btn-default"
<?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); } } }