public function _validate($data, $rules_array = array()) { $val = new validation(); $val->addSource($data); $val->AddRules($rules_array); $val->run(); // exit(); if (sizeof($val->errors) > 0) { $this->valid = false; return $val->errors; } else { $this->valid = true; return $val->sanitized; } }
$error_course_add = $tr->__("Please select at least one category"); } } } else { $error_course_add = $tr->__("Please select a category"); } } if (isset($_POST['remove'])) { if (isset($_POST['id']) && !empty($_POST['id'])) { $v1 = new validation(); $rules = array(); $v1->addSource($_POST['id']); for ($i = 0; $i < count($_POST['id']); ++$i) { $rules[] = array('type' => 'numeric', "required" => true, 'min' => '0', 'max' => '10000', 'trim' => true); } $v1->AddRules($rules); $v1->run(); foreach ($v1->sanitized as $id) { if ($managerCourse->hasActivities($id)) { $v1->errors['HasLesson'] = $tr->__('The course you want to remove is attached to one or more lessons. Please, first delete these lessons'); break; } } if (sizeof($v1->errors) > 0) { $error_course_remove = $v1->getMessageErrors(); } else { foreach ($v1->sanitized as $id) { $managerCourse->delete($id); } } } else {
} } } else { if (!defined('ABSPATH')) { exit; } global $tr; $managerDomain = new DomainManager(); $error_domain_add = ""; $error_domain_remove = ""; if (isset($_POST)) { $validation = new validation(); } if (isset($_POST['add'])) { $validation->addSource($_POST); $validation->AddRules(array('name' => array('type' => 'string', "required" => true, 'min' => '1', 'max' => '200', 'trim' => true), 'desc' => array('type' => 'string', "required" => true, 'min' => '0', 'max' => '999999', 'trim' => true))); $validation->run(); if (sizeof($validation->errors) > 0) { $error_domain_add = $validation->getMessageErrors(); } else { $managerDomain->add(new Domain(array('name' => $validation->sanitized['name'], 'description' => $validation->sanitized['desc']))); if ($managerDomain->isError()) { $error_domain_add = $tr->__("This name already exist"); } } } if (isset($_POST['remove'])) { if (isset($_POST['id']) && !empty($_POST['id'])) { $rules = array(); $validation->addSource($_POST['id']); for ($i = 0; $i < count($_POST['id']); ++$i) {
$course->setGroupsBP($v4->sanitized); } if (isset($v1->sanitized['pictureId'])) { $course->setPictureId($v1->sanitized['pictureId']); } $managerCourse->update($course->getId(), $course); } } } else { $error_course_update = $tr->__("Please select at least one author") . "<br/>" . $tr->__("Please select at least one category") . "<br/>" . $tr->__("Please enter a valid name"); } } else { // if is an author $v = new validation(); $v->addSource($_POST['course']); $v->AddRules(array('id' => array('type' => 'numeric', "required" => true, 'min' => '1', 'max' => '999999', 'trim' => true), 'description' => array('type' => 'string', "required" => true, 'min' => '0', 'max' => '999999', 'trim' => true))); if (isset($_POST['course']['pictureId']) && !empty($_POST['course']['pictureId'])) { $v->addRule('pictureId', 'numeric', true, 1, 999999, true); } $v->run(); if (sizeof($v->errors)) { $error_course_update = $v->getMessageErrors(); } else { if ($course = $managerCourse->getById($v->sanitized['id'])) { $course->setDescription($v->sanitized['description']); if (isset($v->sanitized['pictureId'])) { $course->setPictureId($v->sanitized['pictureId']); } $managerCourse->update($course->getId(), $course); } }
} $spConfiguration = new Configuration(); $spConfiguration = $spConfiguration->getConfig(); global $tr; function slide_presentation_quiz(Quiz $quiz, $name) { 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();
$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(); } else { $currentUser = new StudyPressUserWP(); if ($managerCourse->getCoursesByAuthor($currentUser->id())) { $quiz = $managerQuiz->getById($v->sanitized['id']); $quiz->setName($v->sanitized['name']); $quiz->setCourseId($v->sanitized['courseId']); $quiz->setDescription($v->sanitized['description']); $quiz->setDuration($v->sanitized['duree']); $quiz->setPictureUrl($v->sanitized['pictureurl']); $quiz->setTags($notes);
$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) { if (preg_match('/^[0-9]{1,}$/', $key)) { if ($value === "false") { $checked[] = "false"; } else { $checked[] = "true"; } }
if ($lesson && $slide) { $slide->setContent($_POST['content']); $slide->setName($v->sanitized['name']); $managerSlide->update($v->sanitized['id_slide'], $slide); echo "true"; } } } } //Ajouter une note if (isset($_POST['type']) && $_POST['type'] === "add-note") { if (isset($_POST['note']) && isset($_POST['id_lesson'])) { $managerLesson = new LessonManager(); $v = new validation(); $v->addSource($_POST); $v->AddRules(array('id_lesson' => array('type' => 'numeric', 'required' => 'true', 'min' => '1', 'max' => '999999', 'trim' => 'true'), 'note' => array('type' => 'string', 'required' => 'true', 'min' => '1', 'max' => '200', 'trim' => 'true'))); $v->run(); if (sizeof($v->errors) > 0) { header("HTTP/1.0 400 Bad Request"); echo $v->getMessageErrors(); } else { $lesson = $managerLesson->getById($v->sanitized['id_lesson']); $notes = $lesson->getTags(); } } } if (isset($_POST['type']) && $_POST['type'] === "order-slide") { if (isset($_POST['order']) && !empty($_POST['order'])) { $managerSlide = new SlideManager(); $v = new validation(); $v->addSource($_POST['order']);