<?php /* * *********************************************** * PluginLotto.com * * Copyrights (c) 2005-2011. iZAP * * All rights reserved * * ************************************************* * @author iZAP Team "<*****@*****.**>" * @link http://www.izap.in/ * Under this agreement, No one has rights to sell this script further. * For more information. Contact "Tarun Jangra<*****@*****.**>" * For discussion about corresponding plugins, visit http://www.pluginlotto.com/forum/ * Follow us on http://facebook.com/PluginLotto and http://twitter.com/PluginLotto */ // this page accepts the selected challlenge of the user izapbase::gatekeeper(); global $CONFIG; $challenge_form = get_input('challenge'); $challenge_entity = new IzapChallenge($challenge_form['guid']); Izapbase::getAllAccess(); $user_array = (array) $challenge_entity->accepted_by; $user_array[] = elgg_get_logged_in_user_guid(); $user_array = array_unique($user_array); $challenge_entity->accepted_by = array(); $challenge_entity->accepted_by = $user_array; IzapBase::removeAccess(); // session gets start when user accepts a challenge and playing a challenge $_SESSION['proper_started'][$challenge_entity->guid] = true; forward(Izapbase::setHref(array('context' => GLOBAL_IZAP_CONTEST_CHALLENGE_PAGEHANDLER, 'action' => 'play', 'page_owner' => false, 'vars' => array($challenge_entity->guid, elgg_get_friendly_title($challenge_entity->title)))));
// get all access from the system to user Izapbase::getAllAccess(); // all answers $answers_array = unserialize($quiz_entity->options); $answer_var = elgg_get_logged_in_user_entity()->username . '_answer'; $correct_var = elgg_get_logged_in_user_entity()->username . '_is_correct'; if ($quiz_form['answer'] == 'Answer' && $quiz_entity->correct_option == $quiz_form['correct_option']) { $quiz_entity->{$correct_var} = 'yes'; $_SESSION['challenge'][$challenge_entity->guid]['answers'][$quiz_entity->guid]['is_correct'] = TRUE; $_SESSION['challenge'][$challenge_entity->guid]['totals']++; $_SESSION['challenge'][$challenge_entity->guid]['total_correct_answers']++; } else { $quiz_entity->{$correct_var} = 'no'; $_SESSION['challenge'][$challenge_entity->guid]['answers'][$quiz_entity->guid]['is_correct'] = FALSE; if ($quiz_form['answer'] == 'Answer') { if ($challenge_entity->negative_marking) { $_SESSION['challenge'][$challenge_entity->guid]['totals']--; } } elseif ($quiz_form['skip'] == 'Skip') { } } $quiz_entity->{$answer_var} = $quiz_form['correct_option']; // remove access from the user Izapbase::removeAccess(); $_SESSION['challenge'][$challenge_entity->guid]['answers'][$quiz_entity->guid]['question'] = $quiz_entity->title; $_SESSION['challenge'][$challenge_entity->guid]['answers'][$quiz_entity->guid]['description'] = $quiz_entity->description; $_SESSION['challenge'][$challenge_entity->guid]['answers'][$quiz_entity->guid]['solution'] = $quiz_entity->solution; $_SESSION['challenge'][$challenge_entity->guid]['answers'][$quiz_entity->guid]['answer'] = $answers_array[$quiz_form['correct_option']]; $_SESSION['challenge'][$challenge_entity->guid]['answers'][$quiz_entity->guid]['correct_answer'] = $answers_array[$quiz_entity->correct_option]; $_SESSION['challenge'][$challenge_entity->guid]['qc']++; forward(izapbase::setHref(array('context' => GLOBAL_IZAP_CONTEST_CHALLENGE_PAGEHANDLER, 'action' => 'play', 'page_owner' => FALSE, 'vars' => array($challenge_entity->guid, elgg_get_friendly_title($challenge_entity->title), false))));
/** * saves the results of the contest as elggObject * @param <boolean> $complete_status * @return ElggObject $result */ public function save_results($complete_status = true) { $_SESSION['challenge'][$this->guid]['completed'] = $complete_status; $challenge = $_SESSION['challenge'][$this->guid]; $result = new ElggObject(); $result->subtype = 'izap_challenge_results'; $result->access_id = ACCESS_PUBLIC; $result->container_guid = $this->guid; $result->title = $this->title; $result->description = serialize($challenge['answers']); $result->total_score = (int) $challenge['totals']; $result->total_correct_answers = (int) $challenge['total_correct_answers']; $result->total_attemped_questions = (int) $challenge['qc']; $result->total_questions = (int) count($challenge['questions']); $result->required_percentage = $this->required_correct; $total_percentage = round($result->total_score / $result->total_questions * 100, 0); $result->total_percentage = (int) ($total_percentage ? $total_percentage : 0); $result->status = (int) $result->total_percentage < (int) $this->required_correct ? 'failed' : 'passed'; $result->challenge_guid = $this->guid; $result->is_completed = $complete_status ? 'yes' : 'no'; $result->total_time_taken = time() - $challenge['start_time']; IzapBase::getAllAccess(); // force save $user_var = elgg_get_logged_in_user_entity()->username . '_last_attempt'; $this->{$user_var} = time(); $this->total_attempted = (int) $this->total_attempted + 1; $user_var = elgg_get_logged_in_user_entity()->username . '_total_attempted'; $this->{$user_var} = (int) $this->{$user_var} + 1; if ($result->status == 'passed') { $pass_var = elgg_get_logged_in_user_entity()->username . '_total_passed'; $this->total_passed = (int) $this->total_passed + 1; $this->{$pass_var} = (int) $this->{$pass_var} + 1; } $result->save(); Izapbase::removeAccess(); //unset($_SESSION['challenge'][$this->guid]['active']); return $result; }