function go_task_shortcode($atts, $content = null) { extract(shortcode_atts(array('id' => '', 'cats' => ''), $atts)); global $wpdb; $user_ID = get_current_user_id(); // User ID $page_id = get_the_ID(); if ($id && !empty($user_ID)) { // If the shortcode has an attribute called id, run this code $today = date('Y-m-d'); $custom_fields = get_post_custom($id); // Just gathering some data about this task with its post id $rewards = unserialize($custom_fields['go_presets'][0]); $mastery_active = !$custom_fields['go_mta_task_mastery'][0]; // whether or not the mastery stage is active $repeat = $custom_fields['go_mta_task_repeat'][0]; // Whether or not you can repeat the task $e_admin_lock = unserialize($custom_fields['go_mta_encounter_admin_lock'][0]); $e_is_locked = $e_admin_lock[0]; if ($e_is_locked === 'true') { $e_pass_lock = $e_admin_lock[1]; } $a_admin_lock = unserialize($custom_fields['go_mta_accept_admin_lock'][0]); $a_is_locked = $a_admin_lock[0]; if ($a_is_locked === 'true') { $a_pass_lock = $a_admin_lock[1]; } $c_admin_lock = unserialize($custom_fields['go_mta_completion_admin_lock'][0]); $c_is_locked = $c_admin_lock[0]; if ($c_is_locked === 'true') { $c_pass_lock = $c_admin_lock[1]; } $m_admin_lock = unserialize($custom_fields['go_mta_mastery_admin_lock'][0]); $m_is_locked = $m_admin_lock[0]; if ($m_is_locked === 'true') { $m_pass_lock = $m_admin_lock[1]; } $r_admin_lock = unserialize($custom_fields['go_mta_repeat_admin_lock'][0]); $r_is_locked = $r_admin_lock[0]; if ($r_is_locked === 'true') { $r_pass_lock = $r_admin_lock[1]; } $test_e_active = $custom_fields['go_mta_test_encounter_lock'][0]; $test_a_active = $custom_fields['go_mta_test_accept_lock'][0]; $test_c_active = $custom_fields['go_mta_test_completion_lock'][0]; $number_of_stages = 4; if ($test_e_active) { $test_e_returns = $custom_fields['go_mta_test_encounter_lock_loot'][0]; $test_e_array = $custom_fields['go_mta_test_lock_encounter'][0]; $test_e_uns = unserialize($test_e_array); $test_e_num = $test_e_uns[3]; $test_e_all_questions = $test_e_uns[0]; $test_e_all_types = $test_e_uns[2]; $test_e_all_inputs = $test_e_uns[1]; $test_e_all_input_num = $test_e_uns[4]; $test_e_all_answers = array(); $test_e_all_keys = array(); for ($i = 0; $i < count($test_e_all_inputs); $i++) { if (!empty($test_e_all_inputs[$i][0])) { $answer_e_temp = implode("###", $test_e_all_inputs[$i][0]); $test_e_all_answers[] = $answer_e_temp; } if (!empty($test_e_all_inputs[$i][1])) { $key_e_temp = implode("###", $test_e_all_inputs[$i][1]); $test_e_all_keys[] = $key_e_temp; } } } $encounter_upload = $custom_fields['go_mta_encounter_upload'][0]; if ($test_a_active) { $test_a_returns = $custom_fields['go_mta_test_accept_lock_loot'][0]; $test_a_array = $custom_fields['go_mta_test_lock_accept'][0]; $test_a_uns = unserialize($test_a_array); $test_a_num = $test_a_uns[3]; $test_a_all_questions = $test_a_uns[0]; $test_a_all_types = $test_a_uns[2]; $test_a_all_inputs = $test_a_uns[1]; $test_a_all_input_num = $test_a_uns[4]; $test_a_all_answers = array(); $test_a_all_keys = array(); for ($i = 0; $i < count($test_a_all_inputs); $i++) { if (!empty($test_a_all_inputs[$i][0])) { $answer_a_temp = implode("###", $test_a_all_inputs[$i][0]); $test_a_all_answers[] = $answer_a_temp; } if (!empty($test_a_all_inputs[$i][1])) { $key_a_temp = implode("###", $test_a_all_inputs[$i][1]); $test_a_all_keys[] = $key_a_temp; } } } $accept_upload = $custom_fields['go_mta_accept_upload'][0]; if ($test_c_active) { $test_c_returns = $custom_fields['go_mta_test_completion_lock_loot'][0]; $test_c_array = $custom_fields['go_mta_test_lock_completion'][0]; $test_c_uns = unserialize($test_c_array); $test_c_num = $test_c_uns[3]; $test_c_all_questions = $test_c_uns[0]; $test_c_all_types = $test_c_uns[2]; $test_c_all_inputs = $test_c_uns[1]; $test_c_all_input_num = $test_c_uns[4]; $test_c_all_answers = array(); $test_c_all_keys = array(); for ($i = 0; $i < count($test_c_all_inputs); $i++) { if (!empty($test_c_all_inputs[$i][0])) { $answer_c_temp = implode("###", $test_c_all_inputs[$i][0]); $test_c_all_answers[] = $answer_c_temp; } if (!empty($test_c_all_inputs[$i][1])) { $key_c_temp = implode("###", $test_c_all_inputs[$i][1]); $test_c_all_keys[] = $key_c_temp; } } } $completion_message = $custom_fields['go_mta_complete_message'][0]; // Completion Message $completion_upload = $custom_fields['go_mta_completion_upload'][0]; if ($mastery_active) { $test_m_active = $custom_fields['go_mta_test_mastery_lock'][0]; $test_m_returns = $custom_fields['go_mta_test_mastery_lock_loot'][0]; if ($test_m_active) { $test_m_array = $custom_fields['go_mta_test_lock_mastery'][0]; $test_m_uns = unserialize($test_m_array); $test_m_num = $test_m_uns[3]; $test_m_all_questions = $test_m_uns[0]; $test_m_all_types = $test_m_uns[2]; $test_m_all_inputs = $test_m_uns[1]; $test_m_all_input_num = $test_m_uns[4]; $test_m_all_answers = array(); $test_m_all_keys = array(); for ($i = 0; $i < count($test_m_all_inputs); $i++) { if (!empty($test_m_all_inputs[$i][0])) { $answer_m_temp = implode("###", $test_m_all_inputs[$i][0]); $test_m_all_answers[] = $answer_m_temp; } if (!empty($test_m_all_inputs[$i][1])) { $key_m_temp = implode("###", $test_m_all_inputs[$i][1]); $test_m_all_keys[] = $key_m_temp; } } } $mastery_message = $custom_fields['go_mta_mastery_message'][0]; // Mastery Message $mastery_upload = $custom_fields['go_mta_mastery_upload'][0]; if ($repeat == 'on') { // Checks if the task is repeatable and if it has a repeat limit if ($custom_fields['go_mta_repeat_amount'][0]) { $repeat_amount = $custom_fields['go_mta_repeat_amount'][0]; // Sets the limit equal to the meta field value decalred in the task creation page } else { $repeat_amount = 0; } $repeat_message = $custom_fields['go_mta_repeat_message'][0]; $repeat_upload = $custom_fields['go_mta_repeat_upload'][0]; $number_of_stages = 5; } } else { $number_of_stages = 3; } // Checks if the task has a bonus currency filter // Sets the filter equal to the meta field value declared in the task creation page, if none exists defaults to 0 $bonus_currency_required = $custom_fields['go_mta_bonus_currency_filter'][0]; // Checks if the task has a penalty filter $penalty_filter = $custom_fields['go_mta_penalty_filter'][0]; if ($custom_fields['go_mta_focus_category_lock'][0]) { $focus_category_lock = true; } $description = $custom_fields['go_mta_quick_desc'][0]; // Description $req_rank = $custom_fields['go_mta_req_rank'][0]; // Required Rank to accept task if (!empty($req_rank)) { $ranks = get_option('go_ranks'); if (!empty($ranks['name']) && !empty($ranks['points'])) { $index = array_search($req_rank, $ranks['name']); $req_points = $ranks['points'][$index]; } else { $req_points = null; } } else { $req_points = null; } $currency_array = $rewards['currency']; // Makes an array out of currency values for each stage $points_array = $rewards['points']; //Makes an array out of currency values for each stage $bonus_currency_array = $rewards['bonus_currency']; $current_bonus_currency = go_return_bonus_currency($user_ID); $current_penalty = go_return_penalty($user_ID); $go_admin_email = get_option('go_admin_email'); if ($go_admin_email) { $admin = get_user_by('email', $go_admin_email); $admin_name = addslashes($admin->display_name); } $is_admin = false; $user_obj = get_user_by('id', $user_ID); $user_roles = $user_obj->roles; if (!empty($user_roles)) { foreach ($user_roles as $role) { if ($role === "administrator") { $is_admin = true; break; } } } $content_post = get_post($id); // Grabs content of a task from the post table in your wordpress database where post_id = id in the shortcode. $task_content = $content_post->post_content; // Grabs what the task actually says in the body of it if ($task_content == '') { // If the task is empty, run this code $accept_message = $custom_fields['go_mta_accept_message'][0]; // Accept message meta field exists, set accept message equal to the meta field's content } elseif ($task_content != '' && !$custom_fields['go_mta_accept_message']) { // If content is returned from the post table, and the post doesn't have an accept message meta field, run this code add_post_meta($id, 'go_mta_accept_message', $task_content); // Add accept message meta field with value of the post's content from post table } else { // If the task has content in the post table, and has a meta field, run this code $accept_message = $custom_fields['go_mta_accept_message'][0]; // Set value of accept message equal to the task's accept message meta field value } // If there are dates in the nerf date picker if ($custom_fields['go_mta_date_picker'] && $custom_fields['go_mta_date_picker'][0] != "") { // Initialize arrays to be filled w/ values $temp_array = array(); $dates = array(); $percentages = array(); // Loops through array of dates set in task creation page foreach ($custom_fields['go_mta_date_picker'] as $key => $value) { $temp_array[$key] = unserialize($value); } $temp_array2 = $temp_array[0]; if (empty($temp_array2['date']) || empty($temp_array2['percent'])) { $update_percent = 0; } $temp_array2 = array_filter($temp_array2); // Loops through condensed array of dates if (!empty($temp_array2) && is_array($temp_array2)) { foreach ($temp_array2 as $key => $value) { if ($key == 'date') { foreach (array_values($value) as $date_val) { array_push($dates, $date_val); } } elseif ($key == 'percent') { foreach (array_values($value) as $percent_val) { array_push($percentages, $percent_val); } } } // Loops through dates to check which is closest foreach ($dates as $key => $val) { // Checks numerical distance from today and the date in the array $interval[] = abs(strtotime($today) - strtotime($val)); // If current date is in the future, set its value to be large number so that when sorting it can't appear first and mess up setting the update percentage below if (strtotime($today) < strtotime($val)) { $interval[$key] = PHP_INT_MAX; } } if ($interval) { // Sorts array from least to greatest asort($interval); // Sets percent equal to the percent paired with the closest date from today // Prioritizes past dates over future dates $update_percent = $percentages[key($interval)] / 100; } } } else { $update_percent = 0; } global $current_points; if ($is_admin === false && !empty($req_points) && $current_points < $req_points) { $points = $req_points - $current_points; $points_name = strtolower(go_return_options('go_points_name')); $task_name = strtolower(go_return_options('go_tasks_name')); echo "You need {$points} more {$points_name} to begin this {$task_name}."; } else { $go_table_ind = $wpdb->prefix . 'go'; $task_count = $wpdb->get_var("SELECT `count` FROM " . $go_table_ind . " WHERE post_id = {$id} AND uid = {$user_ID}"); $status = (int) $wpdb->get_var("SELECT `status` FROM " . $go_table_ind . " WHERE post_id = {$id} AND uid = {$user_ID}"); switch ($status) { case 0: $db_task_stage_upload_var = 'e_uploaded'; break; case 1: $db_task_stage_upload_var = 'a_uploaded'; break; case 2: $db_task_stage_upload_var = 'c_uploaded'; break; case 3: $db_task_stage_upload_var = 'm_uploaded'; break; case 4: $db_task_stage_upload_var = 'r_uploaded'; break; } if (!empty($db_task_stage_upload_var)) { $is_uploaded = $wpdb->get_var("SELECT {$db_task_stage_upload_var} FROM {$go_table_ind} WHERE uid = {$user_ID} AND post_id = {$id}"); } else { $is_uploaded = 0; } if (get_the_terms($id, 'task_focus_categories') && $focus_category_lock) { $categories = get_the_terms($id, 'task_focus_categories'); $category_names = array(); foreach ($categories as $category) { array_push($category_names, $category->name); } } if (get_user_meta($user_ID, 'go_focus', true) != '') { $user_focus = (array) get_user_meta($user_ID, 'go_focus', true); } if ($category_names && $user_focus) { $go_ahead = array_intersect($user_focus, $category_names); } go_display_rewards($points_array, $currency_array, $number_of_stages); echo ' <script type="text/javascript"> jQuery(".entry-title").after(jQuery(".go_task_rewards")); </script>'; ?> <div id="go_description"><div class="go_stage_message"><?php echo do_shortcode(wpautop($description)); ?> </div></div> <?php // If current post in a chain and user logged in if ($custom_fields['chain'][0] != null) { $current_position_in_chain = get_post_meta($id, 'chain_position', true); $chain_tax = get_the_terms($id, 'task_chains'); //Grab chain object for this post $chain = array_shift(array_values($chain_tax)); //Grab all posts in the current chain in order $posts_in_chain = get_posts(array('post_type' => 'tasks', 'taxonomy' => 'task_chains', 'term' => $chain->name, 'order' => 'ASC', 'meta_key' => 'chain_position', 'orderby' => 'meta_value_num', 'posts_per_page' => '-1')); // Loop through each one and make array of their ids foreach ($posts_in_chain as $post_in_chain) { $post_ids_in_chain[] = $post_in_chain->ID; } // Setup next task in chain if ($id != end($post_ids_in_chain)) { $next_post_id_in_chain = $post_ids_in_chain[array_search($id, $post_ids_in_chain) + 1]; $next_post_in_chain = '<a href="' . get_permalink($next_post_id_in_chain) . '">' . get_the_title($next_post_id_in_chain) . '</a>'; } $post_ids_in_chain_string = join(',', $post_ids_in_chain); // Grab all posts in chain statuses $list = $wpdb->get_results("\n\t\t\tselect post_id,status\n\t\t\tfrom " . $go_table_ind . "\n\t\t\twhere uid = {$user_ID}\n\t\t\tand post_id in ({$post_ids_in_chain_string})\n\t\t\torder by field(post_id, {$post_ids_in_chain_string})\n\t\t\t"); // Make array of statuses in chain indexed by post id foreach ($list as $post_obj) { $post_status_in_chain[$post_obj->post_id] = $post_obj->status; } foreach ($post_ids_in_chain as $post_id_in_chain) { if ($post_id_in_chain == $id) { break; } $post_custom_in_chain = get_post_custom($post_id_in_chain); $post_mastery_active_in_chain = !$post_custom_in_chain['go_mta_task_mastery'][0]; // $post_number_of_stages_in_chain will later be designated by an admin option that will be toggleable per task chain. if ($post_mastery_active_in_chain) { $post_number_of_stages_in_chain = 3; } else { $post_number_of_stages_in_chain = 3; } // Check if current post in loop has been completed/mastered, depending on the number of stages in the task that needs to be completed if ($post_status_in_chain[$post_id_in_chain] < $post_number_of_stages_in_chain) { $previous_task = '<a href="' . get_permalink($post_id_in_chain) . '">' . get_the_title($post_id_in_chain) . '</a>'; echo 'You must finish ' . $previous_task . ' to do this ' . strtolower(go_return_options('go_tasks_name')); return false; } } if ($current_position_in_chain == $chain->count) { $last_in_chain = true; } else { $last_in_chain = false; } } if ($is_admin === true || $go_ahead || !isset($focus_category_lock) || empty($category_names)) { if ($current_bonus_currency >= $bonus_currency_required && !empty($bonus_currency_required) || $current_penalty < $penalty_filter && !empty($penalty_filter) || empty($bonus_currency_required) && empty($penalty_filter)) { switch ($status) { // First time a user encounters a task case 0: // sending go_add_post the $repeat var was the problem, that is why it is now sending a null value. go_add_post($user_ID, $id, 0, floor($points_array[0] + $update_percent * $points_array[0]), floor($currency_array[0] + $update_percent * $currency_array[0]), floor($currency_array[0] + $update_percent * $currency_array[0]), $page_id, null, 0, 0, 0, $c_passed, $m_passed); ?> <div id="go_content"> <?php if ($test_e_active) { echo "<p id='go_test_error_msg' style='color: red;'></p>"; if ($test_e_num > 1) { for ($i = 0; $i < $test_e_num; $i++) { echo do_shortcode("[go_test type='" . $test_e_all_types[$i] . "' question='" . $test_e_all_questions[$i] . "' possible_answers='" . $test_e_all_answers[$i] . "' key='" . $test_e_all_keys[$i] . "' test_id='" . $i . "' total_num='" . $test_e_num . "']"); } echo "<div class='go_test_submit_div' style='display: none;'><button class='go_test_submit'>Submit</button></div>"; } else { echo do_shortcode("[go_test type='" . $test_e_all_types[0] . "' question='" . $test_e_all_questions[0] . "' possible_answers='" . $test_e_all_answers[0] . "' key='" . $test_e_all_keys[0] . "' test_id='0']") . "<div class='go_test_submit_div' style='display: none;'><button class='go_test_submit'>Submit</button></div>"; } } if ($encounter_upload) { echo do_shortcode("[go_upload is_uploaded={$is_uploaded} status={$status} user_id={$user_ID} post_id={$id}]") . "<br/>"; } ?> <p id='go_stage_error_msg' style='display: none; color: red;'></p> <?php if ($e_is_locked === 'true' && !empty($e_pass_lock)) { echo "<input id='go_pass_lock' type='password' placeholder='Enter Password'/></br>"; } ?> <button id="go_button" status= "2" onclick="task_stage_change(this);" <?php if ($e_is_locked === 'true' && empty($e_pass_lock)) { echo "admin_lock='true'"; } ?> ><?php echo go_return_options('go_second_stage_button'); ?> </button> </div> <?php break; // Encountered // Encountered case 1: ?> <div id="go_content"> <?php if ($test_e_active) { echo "<p id='go_test_error_msg' style='color: red;'></p>"; if ($test_e_num > 1) { for ($i = 0; $i < $test_e_num; $i++) { echo do_shortcode("[go_test type='" . $test_e_all_types[$i] . "' question='" . $test_e_all_questions[$i] . "' possible_answers='" . $test_e_all_answers[$i] . "' key='" . $test_e_all_keys[$i] . "' test_id='" . $i . "' total_num='" . $test_e_num . "']"); } echo "<div class='go_test_submit_div' style='display: none;'><button class='go_test_submit'>Submit</button></div>"; } else { echo do_shortcode("[go_test type='" . $test_e_all_types[0] . "' question='" . $test_e_all_questions[0] . "' possible_answers='" . $test_e_all_answers[0] . "' key='" . $test_e_all_keys[0] . "' test_id='0']") . "<div class='go_test_submit_div' style='display: none;'><button class='go_test_submit'>Submit</button></div>"; } } if ($encounter_upload) { echo do_shortcode("[go_upload is_uploaded={$is_uploaded} status={$status} user_id={$user_ID} post_id={$id}]") . "<br/>"; } ?> <p id='go_stage_error_msg' style='display: none; color: red;'></p> <?php if ($e_is_locked === 'true' && !empty($e_pass_lock)) { echo "<input id='go_pass_lock' type='password' placeholder='Enter Password'/></br>"; } ?> <button id="go_button" status= "2" onclick="task_stage_change(this);" <?php if ($e_is_locked === 'true' && empty($e_pass_lock)) { echo "admin_lock='true'"; } ?> ><?php echo go_return_options('go_second_stage_button'); ?> </button> </div> <?php break; // Accepted // Accepted case 2: echo '<div id="go_content"><div class="go_stage_message">' . do_shortcode(wpautop($accept_message)) . '</div>'; if ($test_a_active) { echo "<p id='go_test_error_msg' style='color: red;'></p>"; if ($test_a_num > 1) { for ($i = 0; $i < $test_a_num; $i++) { echo do_shortcode("[go_test type='" . $test_a_all_types[$i] . "' question='" . $test_a_all_questions[$i] . "' possible_answers='" . $test_a_all_answers[$i] . "' key='" . $test_a_all_keys[$i] . "' test_id='" . $i . "' total_num='" . $test_a_num . "']"); } echo "<div class='go_test_submit_div' style='display: none;'><button class='go_test_submit'>Submit</button></div>"; } else { echo do_shortcode("[go_test type='" . $test_a_all_types[0] . "' question='" . $test_a_all_questions[0] . "' possible_answers='" . $test_a_all_answers[0] . "' key='" . $test_a_all_keys[0] . "' test_id='0']") . "<div class='go_test_submit_div' style='display: none;'><button class='go_test_submit'>Submit</button></div>"; } } if ($accept_upload) { echo do_shortcode("[go_upload is_uploaded={$is_uploaded} status={$status} user_id={$user_ID} post_id={$id}]") . "<br/>"; } echo "<p id='go_stage_error_msg' style='display: none; color: red;'></p>"; if ($a_is_locked === 'true' && !empty($a_pass_lock)) { echo "<input id='go_pass_lock' type='password' placeholder='Enter Password'/></br>"; } echo "<button id='go_button' status='3' onclick='task_stage_change(this);'"; if ($a_is_locked === 'true' && empty($a_pass_lock)) { echo "admin_lock='true'"; } echo '>' . go_return_options('go_third_stage_button') . '</button> <button id="go_back_button" onclick="task_stage_change(this);" undo="true">Undo</button> </div>'; break; // Completed // Completed case 3: echo '<div id="go_content"><div class="go_stage_message">' . do_shortcode(wpautop($accept_message)) . '</div><div class="go_stage_message"> ' . do_shortcode(wpautop($completion_message)) . '</div>'; if ($mastery_active) { if ($test_c_active) { echo "<p id='go_test_error_msg' style='color: red;'></p>"; if ($test_c_num > 1) { for ($i = 0; $i < $test_c_num; $i++) { echo do_shortcode("[go_test type='" . $test_c_all_types[$i] . "' question='" . $test_c_all_questions[$i] . "' possible_answers='" . $test_c_all_answers[$i] . "' key='" . $test_c_all_keys[$i] . "' test_id='" . $i . "' total_num='" . $test_c_num . "']"); } echo "<div class='go_test_submit_div' style='display: none;'><button class='go_test_submit'>Submit</button></div>"; } else { echo do_shortcode("[go_test type='" . $test_c_all_types[0] . "' question='" . $test_c_all_questions[0] . "' possible_answers='" . $test_c_all_answers[0] . "' key='" . $test_c_all_keys[0] . "' test_id='0']") . "<div class='go_test_submit_div' style='display: none;'><button class='go_test_submit'>Submit</button></div>"; } } if ($completion_upload) { echo do_shortcode("[go_upload is_uploaded={$is_uploaded} status={$status} user_id={$user_ID} post_id={$id}]") . "<br/>"; } echo "<p id='go_stage_error_msg' style='display: none; color: red;'></p>"; if ($c_is_locked === 'true' && !empty($c_pass_lock)) { echo "<input id='go_pass_lock' type='password' placeholder='Enter Password'/></br>"; } echo "<button id='go_button' status='4' onclick='task_stage_change(this);'"; if ($c_is_locked === 'true' && empty($c_pass_lock)) { echo "admin_lock='true'"; } echo '>' . go_return_options('go_fourth_stage_button') . '</button> <button id="go_back_button" onclick="task_stage_change(this);" undo="true">Undo</button>'; if ($next_post_in_chain && !$last_in_chain) { echo '<div class="go_chain_message">Next ' . strtolower(go_return_options('go_tasks_name')) . ' in ' . $chain->name . ': ' . $next_post_in_chain . '</div>'; } else { echo '<div class="go_chain_message">' . $custom_fields['go_mta_final_chain_message'][0] . '</div>'; } echo "</div>"; } else { if ($test_c_active) { echo "<p id='go_test_error_msg' style='color: red;'></p>"; if ($test_c_num > 1) { for ($i = 0; $i < $test_c_num; $i++) { echo do_shortcode("[go_test type='" . $test_c_all_types[$i] . "' question='" . $test_c_all_questions[$i] . "' possible_answers='" . $test_c_all_answers[$i] . "' key='" . $test_c_all_keys[$i] . "' test_id='" . $i . "' total_num='" . $test_c_num . "']"); } echo "<div class='go_test_submit_div' style='display: none;'><button class='go_test_submit'>Submit</button></div>"; } else { echo do_shortcode("[go_test type='" . $test_c_all_types[0] . "' question='" . $test_c_all_questions[0] . "' possible_answers='" . $test_c_all_answers[0] . "' key='" . $test_c_all_keys[0] . "' test_id='0']") . "<div class='go_test_submit_div' style='display: none;'><button class='go_test_submit'>Submit</button></div>"; } } if ($completion_upload) { echo do_shortcode("[go_upload is_uploaded={$is_uploaded} status={$status} user_id={$user_ID} post_id={$id}]") . "<br/>"; } echo '<span id="go_button" status="4" style="display:none;"></span><button id="go_back_button" onclick="task_stage_change(this);" undo="true">Undo</button>'; if ($next_post_in_chain && !$last_in_chain) { echo '<div class="go_chain_message">Next ' . strtolower(go_return_options('go_tasks_name')) . ' in ' . $chain->name . ': ' . $next_post_in_chain . '</div>'; } else { echo '<div class="go_chain_message">' . $custom_fields['go_mta_final_chain_message'][0] . '</div>'; } echo "</div>"; } break; // Mastered // Mastered case 4: echo '<div id="go_content"><div class="go_stage_message">' . do_shortcode(wpautop($accept_message)) . '</div>' . '<div class="go_stage_message">' . do_shortcode(wpautop($completion_message)) . '</div><div class="go_stage_message">' . do_shortcode(wpautop($mastery_message)) . '</div>'; if ($repeat == 'on') { if ($task_count < $repeat_amount || $repeat_amount == 0) { // Checks if the amount of times a user has completed a task is less than the amount of times they are allowed to complete a task. If so, outputs the repeat button to allow the user to repeat the task again. if ($task_count == 0) { if ($test_m_active) { echo "<p id='go_test_error_msg' style='color: red;'></p>"; if ($test_m_num > 1) { for ($i = 0; $i < $test_m_num; $i++) { echo do_shortcode("[go_test type='" . $test_m_all_types[$i] . "' question='" . $test_m_all_questions[$i] . "' possible_answers='" . $test_m_all_answers[$i] . "' key='" . $test_m_all_keys[$i] . "' test_id='" . $i . "' total_num='" . $test_m_num . "']"); } echo "<div class='go_test_submit_div' style='display: none;'><button class='go_test_submit'>Submit</button></div>"; } else { echo do_shortcode("[go_test type='" . $test_m_all_types[0] . "' question='" . $test_m_all_questions[0] . "' possible_answers='" . $test_m_all_answers[0] . "' key='" . $test_m_all_keys[0] . "' test_id='0']") . "<div class='go_test_submit_div' style='display: none;'><button class='go_test_submit'>Submit</button></div>"; } } if ($mastery_upload) { echo do_shortcode("[go_upload is_uploaded={$is_uploaded} status={$status} user_id={$user_ID} post_id={$id}]") . "<br/>"; } echo ' <div id="repeat_quest"> <div id="go_repeat_clicked" style="display:none;"><div class="go_stage_message">' . do_shortcode(wpautop($repeat_message)) . "</div><p id='go_stage_error_msg' style='display: none; color: red;'></p>"; if ($m_is_locked === 'true' && !empty($m_pass_lock)) { echo "<input id='go_pass_lock' type='password' placeholder='Enter Password'/></br>"; } echo "<button id='go_button' status='4' onclick='go_repeat_hide(this);' repeat='on'"; if ($m_is_locked === 'true' && empty($m_pass_lock)) { echo "admin_lock='true'"; } echo '>' . go_return_options('go_fourth_stage_button') . " Again" . '</button> <button id="go_back_button" onclick="task_stage_change(this);" undo="true">Undo</button> </div> <div id="go_repeat_unclicked"> <button id="go_button" status="4" onclick="go_repeat_replace();"> See ' . get_option('go_fifth_stage_name') . '</button> <button id="go_back_button" onclick="task_stage_change(this);" undo="true">Undo</button> </div> </div> '; } else { if ($repeat_upload) { echo do_shortcode("[go_upload is_uploaded={$is_uploaded} status={$status} user_id={$user_ID} post_id={$id}]") . "<br/>"; } echo ' <div id="repeat_quest"> <div id="go_repeat_clicked" style="display:none;"><div class="go_stage_message">' . do_shortcode(wpautop($repeat_message)) . "</div><p id='go_stage_error_msg' style='display: none; color: red;'></p>"; if ($r_is_locked === 'true' && !empty($r_pass_lock)) { echo "<input id='go_pass_lock' type='password' placeholder='Enter Password'/></br>"; } echo "<button id='go_button' status='4' onclick='go_repeat_hide(this);' repeat='on'"; if ($r_is_locked === 'true' && empty($r_pass_lock)) { echo "admin_lock='true'"; } echo '>' . go_return_options('go_fourth_stage_button') . " Again" . '</button> <button id="go_back_button" onclick="task_stage_change(this);" undo="true">Undo</button> </div> <div id="go_repeat_unclicked"> <button id="go_button" status="4" onclick="go_repeat_replace();">' . get_option('go_fifth_stage_button') . '</button> <button id="go_back_button" onclick="task_stage_change(this);" undo="true">Undo</button> </div> </div> '; } } else { echo '<span id="go_button" status="4" repeat="on" style="display:none;"></span><button id="go_back_button" onclick="task_stage_change(this);" undo="true">Undo</button>'; } } else { if ($test_m_active) { echo "<p id='go_test_error_msg' style='color: red;'></p>"; if ($test_m_num > 1) { for ($i = 0; $i < $test_m_num; $i++) { echo do_shortcode("[go_test type='" . $test_m_all_types[$i] . "' question='" . $test_m_all_questions[$i] . "' possible_answers='" . $test_m_all_answers[$i] . "' key='" . $test_m_all_keys[$i] . "' test_id='" . $i . "' total_num='" . $test_m_num . "']"); } echo "<div class='go_test_submit_div' style='display: none;'><button class='go_test_submit'>Submit</button></div>"; } else { echo do_shortcode("[go_test type='" . $test_m_all_types[0] . "' question='" . $test_m_all_questions[0] . "' possible_answers='" . $test_m_all_answers[0] . "' key='" . $test_m_all_keys[0] . "' test_id='0']") . "<div class='go_test_submit_div' style='display: none;'><button class='go_test_submit'>Submit</button></div>"; } } if ($mastery_upload) { echo do_shortcode("[go_upload is_uploaded={$is_uploaded} status={$status} user_id={$user_ID} post_id={$id}]") . "<br/>"; } echo '<span id="go_button" status="4" repeat="on" style="display:none;"></span><button id="go_back_button" onclick="task_stage_change(this);" undo="true">Undo</button>'; } if ($next_post_in_chain && !$last_in_chain) { echo '<div class="go_chain_message">Next ' . strtolower(go_return_options('go_tasks_name')) . ' in ' . $chain->name . ': ' . $next_post_in_chain . '</div>'; } else { echo '<div class="go_chain_message">' . $custom_fields['go_mta_final_chain_message'][0] . '</div>'; } echo '</div>'; } if (get_post_type() == 'tasks') { comments_template(); } } else { if ($current_bonus_currency < $bonus_currency_required && !empty($bonus_currency_required) && ($current_penalty > $penalty_filter && !empty($penalty_filter))) { echo "You require more than {$bonus_currency_required} " . go_return_options('go_bonus_currency_name') . " and less than {$penalty_filter} " . go_return_options('go_penalty_name') . " to view this " . go_return_options('go_tasks_name') . "."; } else { if ($current_bonus_currency < $bonus_currency_required && !empty($bonus_currency_required)) { echo "You require more than {$bonus_currency_required} " . go_return_options('go_bonus_currency_name') . " to view this " . go_return_options('go_tasks_name') . "."; } else { if ($current_penalty > $penalty_filter && !empty($penalty_filter)) { echo "You require less than {$penalty_filter} " . go_return_options('go_penalty_name') . " to view this " . go_return_options('go_tasks_name') . "."; } } } } } else { // If user can't access quest because they aren't part of the specialty, echo this $category_name = implode(',', $category_names); $focus_name = get_option('go_focus_name', 'Profession'); $task_name = strtolower(get_option('go_tasks_name', 'Quest')); echo "This {$task_name} is only available to the \"{$category_name}\" {$focus_name}."; } if ($test_e_active && $test_e_returns) { $db_test_encounter_fail_count = $wpdb->get_var("SELECT `e_fail_count` FROM " . $go_table_ind . " WHERE post_id = {$id} AND uid = {$user_ID}"); $_SESSION['test_encounter_fail_count'] = $db_test_encounter_fail_count; $db_test_encounter_passed = $wpdb->get_var("SELECT `e_passed` FROM " . $go_table_ind . " WHERE post_id = {$id} AND uid = {$user_ID}"); $_SESSION['test_encounter_passed'] = $db_test_encounter_passed; } if ($test_a_active && $test_a_returns) { $db_test_accept_fail_count = $wpdb->get_var("SELECT `a_fail_count` FROM " . $go_table_ind . " WHERE post_id = {$id} AND uid = {$user_ID}"); $_SESSION['test_accept_fail_count'] = $db_test_accept_fail_count; $db_test_accept_passed = $wpdb->get_var("SELECT `a_passed` FROM " . $go_table_ind . " WHERE post_id = {$id} AND uid = {$user_ID}"); $_SESSION['test_accept_passed'] = $db_test_accept_passed; } if ($test_c_active && $test_c_returns) { $db_test_completion_fail_count = $wpdb->get_var("SELECT `c_fail_count` FROM " . $go_table_ind . " WHERE post_id = {$id} AND uid = {$user_ID}"); $_SESSION['test_completion_fail_count'] = $db_test_completion_fail_count; $db_test_completion_passed = $wpdb->get_var("SELECT `c_passed` FROM " . $go_table_ind . " WHERE post_id = {$id} AND uid = {$user_ID}"); $_SESSION['test_completion_passed'] = $db_test_completion_passed; } if ($test_m_active && $test_m_returns) { $db_test_mastery_fail_count = $wpdb->get_var("SELECT `m_fail_count` FROM " . $go_table_ind . " WHERE post_id = {$id} AND uid = {$user_ID}"); $_SESSION['test_mastery_fail_count'] = $db_test_mastery_fail_count; $test_mastery_passed = $wpdb->get_var("SELECT `m_passed` FROM " . $go_table_ind . " WHERE post_id = {$id} AND uid = {$user_ID}"); $_SESSION['test_mastery_passed'] = $test_mastery_passed; } ?> <script language="javascript"> jQuery(document).ready(function() { jQuery.ajaxSetup({ url: '<?php echo get_site_url(); ?> /wp-admin/admin-ajax.php' }); check_locks(); }); function check_locks() { if (jQuery(".go_test_list").length != 0) { jQuery('.go_test_submit_div').show(); } var is_uploaded = jQuery('#go_upload_form').attr('uploaded'); if (jQuery(".go_test_list").length != 0 && jQuery('#go_upload_form').length != 0) { if (jQuery('#go_pass_lock').length == 0 && jQuery('#go_button').attr('admin_lock') !== 'true') { jQuery('#go_button').attr('disabled', 'true'); } jQuery('.go_test_submit').click(function() { var test_list = jQuery(".go_test_list"); var current_error_msg = jQuery('#go_test_error_msg').text(); if (test_list.length > 1) { var checked_ans = 0; for (var i = 0; i < test_list.length; i++) { var obj_str = "#"+test_list[i].id+" input:checked"; var chosen_answers = jQuery(obj_str); if (chosen_answers.length >= 1) { checked_ans++; } else { if (current_error_msg != "Please answer all questions!") { jQuery('#go_test_error_msg').text("Please answer all questions!"); } else { flash_error_msg('#go_test_error_msg'); } } } if (checked_ans >= test_list.length && is_uploaded == 1) { task_unlock(); } else { if (checked_ans < test_list.length && is_uploaded != 1) { var error = "Please answer all questions and upload a file!"; } else if (checked_ans < test_list.length) { var error = "Please answer all questions!"; } else if (is_uploaded != 1) { var error = "Please upload a file!"; } if (typeof(error) != null) { if (current_error_msg != error) { jQuery('#go_test_error_msg').text(error); } else { flash_error_msg('#go_test_error_msg'); } } } } else { if (jQuery(".go_test_list input:checked").length >= 1 && is_uploaded == 1) { task_unlock(); } else { if (jQuery(".go_test_list input:checked").length == 0 && is_uploaded != 1) { var error = "Please answer the question and upload a file!"; } else if (jQuery(".go_test_list input:checked").length == 0) { var error = "Please answer the question!"; } else if (is_uploaded != 1) { var error = "Please upload a file!"; } if (typeof(error) != null) { if (current_error_msg != error) { jQuery('#go_test_error_msg').text(error); } else { flash_error_msg('#go_test_error_msg'); } } } } }); jQuery('#go_upload_submit').click(function() { var test_list = jQuery(".go_test_list"); var current_error_msg = jQuery('#go_test_error_msg').text(); if (test_list.length > 1) { var checked_ans = 0; for (var i = 0; i < test_list.length; i++) { var obj_str = "#"+test_list[i].id+" input:checked"; var chosen_answers = jQuery(obj_str); if (chosen_answers.length >= 1) { checked_ans++; } else { if (current_error_msg != "Please answer all questions!") { jQuery('#go_test_error_msg').text("Please answer all questions!"); } else { flash_error_msg('#go_test_error_msg'); } } } if (checked_ans >= test_list.length && is_uploaded == 1) { task_unlock(); } else { if (checked_ans < test_list.length && is_uploaded != 1) { var error = "Please answer all questions and upload a file!"; } else if (checked_ans < test_list.length) { var error = "Please answer all questions!"; } else if (is_uploaded != 1) { var error = "Please upload a file!"; } if (typeof(error) != null) { if (current_error_msg != error) { jQuery('#go_test_error_msg').text(error); } else { flash_error_msg('#go_test_error_msg'); } } } } else { if (jQuery(".go_test_list input:checked").length >= 1 && is_uploaded == 1) { task_unlock(); } else { if (jQuery(".go_test_list input:checked").length == 0 && is_uploaded != 1) { var error = "Please answer the question and upload a file!"; } else if (jQuery(".go_test_list input:checked").length == 0) { var error = "Please answer the question!"; } else if (is_uploaded != 1) { var error = "Please upload a file!"; } if (typeof(error) != null) { if (current_error_msg != error) { jQuery('#go_test_error_msg').text(error); } else { flash_error_msg('#go_test_error_msg'); } } } } }); } else if (jQuery(".go_test_list").length != 0) { if (jQuery('#go_pass_lock').length == 0 && jQuery('#go_button').attr('admin_lock') !== 'true') { jQuery('#go_button').attr('disabled', 'true'); } jQuery('.go_test_submit').click(function() { var test_list = jQuery(".go_test_list"); if (test_list.length > 1) { var checked_ans = 0; for (var i = 0; i < test_list.length; i++) { var obj_str = "#"+test_list[i].id+" input:checked"; var chosen_answers = jQuery(obj_str); if (chosen_answers.length >= 1) { checked_ans++; } } if (checked_ans >= test_list.length) { task_unlock(); } else { if (jQuery('#go_test_error_msg').text() != "Please answer all questions!") { jQuery('#go_test_error_msg').text("Please answer all questions!"); } else { flash_error_msg('#go_test_error_msg'); } } } else { if (jQuery(".go_test_list input:checked").length >= 1) { task_unlock(); } else { if (jQuery('#go_test_error_msg').text() != "Please answer the question!") { jQuery('#go_test_error_msg').text("Please answer the question!"); } else { flash_error_msg('#go_test_error_msg'); } } } }); } else if (jQuery('#go_upload_form').length != 0 && is_uploaded == 0) { if (jQuery('#go_pass_lock').length == 0 && jQuery('#go_button').attr('admin_lock') !== 'true') { jQuery('#go_button').attr('disabled', 'true'); } jQuery('#go_upload_submit').click(function() { if (jQuery('#go_pass_lock').length > 0 && jQuery('#go_pass_lock').attr('value').length == 0) { var error = "Retrieve the password from <?php echo $admin_name ? $admin_name : 'an administrator'; ?> ."; if (jQuery('#go_stage_error_msg').text() != error) { jQuery('#go_stage_error_msg').text(error); } else { flash_error_msg('#go_stage_error_msg'); } } else { task_unlock(); } }); } if ((jQuery('#go_pass_lock').length > 0 && jQuery('#go_pass_lock').attr('value').length == 0) && (jQuery('#go_upload_form').length != 0 && is_uploaded == 0) || jQuery(".go_test_list").length != 0) { if (jQuery('#go_stage_error_msg').is(":visible")) { var error = "Retrieve the password from <?php echo $admin_name ? $admin_name : 'an administrator'; ?> ."; if (jQuery('#go_stage_error_msg').text() != error) { jQuery('#go_stage_error_msg').text(error); } else { flash_error_msg('#go_stage_error_msg'); } } } } function flash_error_msg(elem) { var bg_color = jQuery(elem).css('background-color'); if (typeof(bg_color) === undefined) { bg_color = "white"; } jQuery(elem).animate({ color: bg_color }, 200, function() { jQuery(elem).animate({ color: "red" }, 200); }); } function task_unlock() { if (jQuery(".go_test_list").length != 0) { var test_list = jQuery(".go_test_list"); var list_size = test_list.length; if (jQuery('.go_test_list :checked').length >= list_size) { var test_list = jQuery(".go_test_list"); var list_size = test_list.length; var type_array = []; if (jQuery(".go_test_list").length > 1) { var choice_array = []; for (var x = 0; x < list_size; x++) { // figure out the type of each test var test_type = test_list[x].children[1].children[0].type; type_array.push(test_type); // get the checked inputs of each test var obj_str = "#"+test_list[x].id+" :checked"; var chosen_answers = jQuery(obj_str); if (test_type == 'radio') { // push indiviudal answers to the choice_array if (chosen_answers[0] != undefined) { choice_array.push(chosen_answers[0].value); } } else if (test_type == 'checkbox') { var t_array = []; for (var i = 0; i < chosen_answers.length; i++) { t_array.push(chosen_answers[i].value); } var choice_str = t_array.join("### "); choice_array.push(choice_str); } } var choice = choice_array.join("#### "); var type = type_array.join("### "); } else { var chosen_answer = jQuery('.go_test_list li input:checked'); var type = jQuery('.go_test_list li input').first().attr("type"); if (type == 'radio') { var choice = chosen_answer[0].value; } else if (type == 'checkbox') { var choice = []; for (var i = 0; i < chosen_answer.length; i++) { choice.push(chosen_answer[i].value); } choice = choice.join("### "); } } } else { jQuery('#go_test_error_msg').text("Answer all questions!"); } } var is_repeating = jQuery('#go_button').attr('repeat'); if (is_repeating !== 'on') { var status = jQuery('#go_button').attr('status') - 2; } else { var status = jQuery('#go_button').attr('status') - 1; } jQuery.ajax({ type: "POST", data:{ action: 'unlock_stage', task: <?php echo $id; ?> , list_size: list_size, chosen_answer: choice, type: type, status: status, points: "<?php $points_str = implode(" ", $points_array); echo $points_str; ?> ", }, success: function(response) { if (response === 1 || response === '1') { jQuery('.go_test_container').hide('slow'); jQuery('#test_failure_msg').hide('slow'); jQuery('.go_test_submit_div').hide('slow'); jQuery('.go_wrong_answer_marker').hide(); if (!jQuery('#go_button').attr('admin_lock')) { jQuery('#go_button').removeAttr('disabled'); jQuery('#go_test_error_msg').attr('style', 'color:green'); jQuery('#go_test_error_msg').text("Well done, continue!"); } else { jQuery('#go_test_error_msg').text("This stage can only be unlocked by <?php echo $admin_name ? $admin_name : 'an administrator'; ?> ."); } var test_e_returns = "<?php echo $test_e_returns; ?> "; var test_a_returns = "<?php echo $test_a_returns; ?> "; var test_c_returns = "<?php echo $test_c_returns; ?> "; var test_m_returns = "<?php echo $test_m_returns; ?> "; if ((status == 0 && test_e_returns == 'on') || (status == 1 && test_a_returns == 'on') || (status == 2 && test_c_returns == 'on') || (status == 3 && test_m_returns == 'on')) { test_point_update(); } } else { if (typeof(response) === 'string' && list_size > 1) { var failed_questions = response.split(", "); for (var x = 0; x < test_list.length; x++) { var test_id = "#"+test_list[x].id; if (jQuery.inArray(test_id, failed_questions) === -1) { if (jQuery(test_id+" .go_wrong_answer_marker").is(":visible")) { jQuery(test_id+" .go_wrong_answer_marker").hide(); } if (!jQuery(test_id+" .go_correct_answer_marker").is(":visible")) { jQuery(test_id+" .go_correct_answer_marker").show(); } } else { if (jQuery(test_id+" .go_correct_answer_marker").is(":visible")) { jQuery(test_id+" .go_correct_answer_marker").hide(); } if (!jQuery(test_id+" .go_wrong_answer_marker").is(":visible")) { jQuery(test_id+" .go_wrong_answer_marker").show(); } } } } var error_msg_val = jQuery('#go_test_error_msg').text(); if (error_msg_val != "Wrong answer, try again!") { jQuery('#go_test_error_msg').text("Wrong answer, try again!"); } else { flash_error_msg('#go_test_error_msg'); } } // console.log(response); } }); } function test_point_update() { var is_repeating = jQuery('#go_button').attr('repeat'); if (is_repeating !== 'on') { var status = jQuery('#go_button').attr('status') - 2; } else { var status = jQuery('#go_button').attr('status') - 1; } jQuery.ajax({ type: "POST", data: { action: "test_point_update", points: "<?php $points_str = implode(" ", $points_array); echo $points_str; ?> ", status: status, page_id: <?php echo $page_id; ?> , user_ID: <?php echo $user_ID; ?> , post_id: <?php echo $id; ?> , update_percent: <?php echo $update_percent; ?> }, success: function (response) { // the three following lines are required for the go_notification to work var color = jQuery('#go_admin_bar_progress_bar').css("background-color"); jQuery('#go_content').append(response); jQuery('#go_admin_bar_progress_bar').css({"background-color": color}); // console.log("\n"+response); } }); } function go_repeat_hide(target) { // hides the div#repeat_quest to create the repeat cycle. // jQuery("#repeat_quest").hide('slow'); setTimeout(function() { // passes the jQuery object received in the parameter of the go_repeat_hide function // as an argument for the task_stage_change function, after 500 milliseconds (1.5 seconds). task_stage_change(target); }, 500); } function go_repeat_replace() { jQuery('#go_repeat_unclicked').remove(); jQuery('#go_repeat_clicked').show('slow'); } function task_stage_change(target) { var undoing = jQuery(target).attr('undo'); if (undoing !== 'true' && jQuery('#go_button').length > 0) { var perma_locked = jQuery('#go_button').attr('admin_lock'); if (perma_locked === 'true') { jQuery('#go_stage_error_msg').show(); jQuery('#go_button').removeAttr('disabled'); jQuery('#go_stage_error_msg').text("This stage can only be unlocked by <?php echo $admin_name ? $admin_name : 'an administrator'; ?> ."); return; } } if (undoing !== 'true' && jQuery('#go_pass_lock').length > 0) { var pass_entered = jQuery('#go_pass_lock').attr('value').length > 0 ? true : false; if (!pass_entered) { jQuery('#go_stage_error_msg').show(); var error = "Retrieve the password from <?php echo $admin_name ? $admin_name : 'an administrator'; ?> ."; if (jQuery('#go_stage_error_msg').text() != error) { jQuery('#go_stage_error_msg').text(error); } else { flash_error_msg('#go_stage_error_msg'); } return; } } var color = jQuery('#go_admin_bar_progress_bar').css("background-color"); // redeclare (also called "overloading") the variable $task_count to the value of the 'count' var on the database. <?php $task_count = $wpdb->get_var("select `count` from " . $go_table_ind . " where post_id = {$id} and uid = {$user_ID}"); ?> // if the button#go_button exists, set var 'task_status' to the value of the 'status' attribute on the current button#go_button. if (jQuery('#go_button').length != 0) { var task_status = jQuery('#go_button').attr('status'); } else { var task_status = 5; } // if 'target' (if an argument is sent to task_stage_change, it is stored as a parameter in the 'target' variable) // is assigned the value of jQuery('#go_back_button'), AND the div#new_content exists... if (jQuery(target).is('#go_back_button') && jQuery('#new_content').length != 0) { jQuery('#new_content p').hide('slow'); jQuery(target).remove(); } // if the button#go_back_button has the attribute of repeat... if (jQuery('#go_back_button').attr('repeat') != 'on') { // set repeat_attr equal to the value of the attribute of button#go_button. var repeat_attr = jQuery('#go_button').attr('repeat'); } else { // set repeat_attr equal to the value of the attribute of button#go_back_button. var repeat_attr = jQuery('#go_back_button').attr('repeat'); } // send the following data to the function 'task_change_stage' and use the POST method to do so... // when it succeeds update the content of the page: update the admin bar; set the css display attribute to none for // div#new_content; then slowly display div#new_content; if the button#go_button 'status' attribute is equal to 2 // and remove the first child element of div#new_content. jQuery.ajax({ type: "POST", data: { action: 'task_change_stage', post_id: <?php echo $id; ?> , user_id: <?php echo $user_ID; ?> , admin_name: '<?php echo $admin_name; ?> ', task_count: <?php if ($task_count == null) { echo '0'; } else { echo $task_count; } ?> , status: task_status, repeat: repeat_attr, undo: undoing, pass: (pass_entered ? jQuery('#go_pass_lock').attr('value') : ''), page_id: <?php echo $page_id; ?> , update_percent: <?php echo $update_percent; ?> , chain_name: '<?php if ($chain->name) { echo $chain->name; } else { echo ''; } ?> ', next_post_id_in_chain: <?php if ($next_post_id_in_chain) { echo $next_post_id_in_chain; } else { echo 0; } ?> , last_in_chain: <?php if ($last_in_chain) { echo 'true'; } else { echo 'false'; } ?> }, success: function(html){ if (html === '0') { jQuery('#go_stage_error_msg').show(); var error = "Retrieve the password from <?php echo $admin_name ? $admin_name : 'an administrator'; ?> ."; if (jQuery('#go_stage_error_msg').text() != error) { jQuery('#go_stage_error_msg').text(error); } else { flash_error_msg('#go_stage_error_msg'); } } else { jQuery('#go_content').html(html); jQuery('#go_admin_bar_progress_bar').css({"background-color": color}); jQuery("#new_content").css("display", "none"); jQuery("#new_content").show('slow'); if(jQuery('#go_button').attr('status') == 2){ jQuery('#new_content').children().first().remove(); } jQuery('#go_button').ready(function() { check_locks(); }); } } }); } </script> <?php echo $the_stage; // Just for Testing Purposes // this is an edit link. edit_post_link('Edit ' . go_return_options('go_tasks_name'), '<br /> <p>', '</p>', $id); } // Ends else statement } else { $custom_fields = get_post_custom($id); $encounter_message = $custom_fields['go_mta_quick_desc'][0]; $accept_message = $custom_fields['go_mta_accept_message'][0]; $complete_message = $custom_fields['go_mta_complete_message'][0]; $mastery_active = !$custom_fields['go_mta_task_mastery'][0]; if ($mastery_active) { $mastery_privacy = !$custom_fields['go_mta_mastery_privacy'][0]; if ($mastery_privacy) { $mastery_message = $custom_fields['go_mta_mastery_message'][0]; $repeat_active = $custom_fields['go_mta_task_repeat'][0]; if ($repeat_active && $mastery_privacy) { $repeat_privacy = !$custom_fields['go_mta_repeat_privacy'][0]; if ($repeat_privacy) { $repeat_message = $custom_fields['go_mta_repeat_message'][0]; } else { $repeat_message = "This stage has been hidden by the administrator."; } } } else { $mastery_message = "This stage has been hidden by the administrator."; } } echo "<div id='go_content'>"; if (!empty($encounter_message)) { echo "<div id='go_stage_encounter_message' class='go_stage_message'>" . do_shortcode(wpautop($encounter_message)) . "</div>"; } if (!empty($accept_message)) { echo "<div id='go_stage_accept_message' class='go_stage_message'>" . do_shortcode(wpautop($accept_message)) . "</div>"; } if (!empty($complete_message)) { echo "<div id='go_stage_complete_message' class='go_stage_message'>" . do_shortcode(wpautop($complete_message)) . "</div>"; } if (!empty($mastery_message)) { echo "<div id='go_stage_mastery_message' class='go_stage_message'>" . do_shortcode(wpautop($mastery_message)) . "</div>"; if (!empty($repeat_message)) { echo "<div id='go_stage_repeat_message' class='go_stage_message'>" . do_shortcode(wpautop($repeat_message)) . "</div>"; } } } }
function go_task_shortcode($atts, $content = null) { $atts = shortcode_atts(array('id' => '', 'cats' => ''), $atts); $id = $atts['id']; global $wpdb; $user_ID = get_current_user_id(); // User ID $page_id = get_the_ID(); if ($id && !empty($user_ID)) { // If the shortcode has an attribute called id, run this code $task_pods = get_option('go_task_pod_globals'); $pods_array = wp_get_post_terms(get_the_id(), 'task_pods'); if (!empty($pods_array)) { $pod_slug = $pods_array[0]->slug; $pod_link = !empty($task_pods[$pod_slug]['go_pod_link']) ? $task_pods[$pod_slug]['go_pod_link'] : ''; } $today = date('Y-m-d'); $task_name = strtolower(go_return_options('go_tasks_name')); $custom_fields = get_post_custom($id); // Just gathering some data about this task with its post id $rewards = !empty($custom_fields['go_presets'][0]) ? unserialize($custom_fields['go_presets'][0]) : null; $mastery_active = !empty($custom_fields['go_mta_task_mastery'][0]) ? !$custom_fields['go_mta_task_mastery'][0] : true; // whether or not the mastery stage is active $repeat = !empty($custom_fields['go_mta_task_repeat'][0]) ? $custom_fields['go_mta_task_repeat'][0] : ''; // Whether or not you can repeat the task $unix_now = current_time('timestamp'); // Current unix timestamp $go_table_name = "{$wpdb->prefix}go"; $task_count = $wpdb->get_var("SELECT `count` FROM {$go_table_name} WHERE post_id = {$id} AND uid = {$user_ID}"); $status = (int) $wpdb->get_var("SELECT `status` FROM {$go_table_name} WHERE post_id = {$id} AND uid = {$user_ID}"); $e_admin_lock = !empty($custom_fields['go_mta_encounter_admin_lock'][0]) ? unserialize($custom_fields['go_mta_encounter_admin_lock'][0]) : null; if (!empty($e_admin_lock)) { $e_is_locked = $e_admin_lock[0]; if ($e_is_locked === 'true') { $e_pass_lock = $e_admin_lock[1]; } } $a_admin_lock = !empty($custom_fields['go_mta_accept_admin_lock'][0]) ? unserialize($custom_fields['go_mta_accept_admin_lock'][0]) : null; if (!empty($a_admin_lock)) { $a_is_locked = $a_admin_lock[0]; if ($a_is_locked === 'true') { $a_pass_lock = $a_admin_lock[1]; } } $c_admin_lock = !empty($custom_fields['go_mta_completion_admin_lock'][0]) ? unserialize($custom_fields['go_mta_completion_admin_lock'][0]) : null; if (!empty($c_admin_lock)) { $c_is_locked = $c_admin_lock[0]; if ($c_is_locked === 'true') { $c_pass_lock = $c_admin_lock[1]; } } $m_admin_lock = !empty($custom_fields['go_mta_mastery_admin_lock'][0]) ? unserialize($custom_fields['go_mta_mastery_admin_lock'][0]) : null; if (!empty($m_admin_lock)) { $m_is_locked = $m_admin_lock[0]; if ($m_is_locked === 'true') { $m_pass_lock = $m_admin_lock[1]; } } $r_admin_lock = !empty($custom_fields['go_mta_repeat_admin_lock'][0]) ? unserialize($custom_fields['go_mta_repeat_admin_lock'][0]) : null; if (!empty($r_admin_lock)) { $r_is_locked = $r_admin_lock[0]; if ($r_is_locked === 'true') { $r_pass_lock = $r_admin_lock[1]; } } $e_url_is_locked = !empty($custom_fields['go_mta_encounter_url_key'][0]) ? true : false; $a_url_is_locked = !empty($custom_fields['go_mta_accept_url_key'][0]) ? true : false; $c_url_is_locked = !empty($custom_fields['go_mta_completion_url_key'][0]) ? true : false; $m_url_is_locked = !empty($custom_fields['go_mta_mastery_url_key'][0]) ? true : false; $test_e_active = !empty($custom_fields['go_mta_test_encounter_lock'][0]) ? $custom_fields['go_mta_test_encounter_lock'][0] : false; $test_a_active = !empty($custom_fields['go_mta_test_accept_lock'][0]) ? $custom_fields['go_mta_test_accept_lock'][0] : false; $test_c_active = !empty($custom_fields['go_mta_test_completion_lock'][0]) ? $custom_fields['go_mta_test_completion_lock'][0] : false; $number_of_stages = 4; if ($test_e_active) { $test_e_array = go_get_test_meta_content($custom_fields, 'encounter'); $test_e_returns = $test_e_array[0]; $test_e_num = $test_e_array[1]; $test_e_all_questions = $test_e_array[2][0]; $test_e_all_types = $test_e_array[2][1]; $test_e_all_answers = $test_e_array[2][2]; $test_e_all_keys = $test_e_array[2][3]; } $encounter_upload = !empty($custom_fields['go_mta_encounter_upload'][0]) ? $custom_fields['go_mta_encounter_upload'][0] : false; if ($test_a_active) { $test_a_array = go_get_test_meta_content($custom_fields, 'accept'); $test_a_returns = $test_a_array[0]; $test_a_num = $test_a_array[1]; $test_a_all_questions = $test_a_array[2][0]; $test_a_all_types = $test_a_array[2][1]; $test_a_all_answers = $test_a_array[2][2]; $test_a_all_keys = $test_a_array[2][3]; } $accept_upload = !empty($custom_fields['go_mta_accept_upload'][0]) ? $custom_fields['go_mta_accept_upload'][0] : false; if ($test_c_active) { $test_c_array = go_get_test_meta_content($custom_fields, 'completion'); $test_c_returns = $test_c_array[0]; $test_c_num = $test_c_array[1]; $test_c_all_questions = $test_c_array[2][0]; $test_c_all_types = $test_c_array[2][1]; $test_c_all_answers = $test_c_array[2][2]; $test_c_all_keys = $test_c_array[2][3]; } $completion_message = !empty($custom_fields['go_mta_complete_message'][0]) ? $custom_fields['go_mta_complete_message'][0] : ''; // Completion Message $completion_upload = !empty($custom_fields['go_mta_completion_upload'][0]) ? $custom_fields['go_mta_completion_upload'][0] : false; if ($mastery_active) { $test_m_active = !empty($custom_fields['go_mta_test_mastery_lock'][0]) ? $custom_fields['go_mta_test_mastery_lock'][0] : false; if ($test_m_active) { $test_m_array = go_get_test_meta_content($custom_fields, 'mastery'); $test_m_returns = $test_m_array[0]; $test_m_num = $test_m_array[1]; $test_m_all_questions = $test_m_array[2][0]; $test_m_all_types = $test_m_array[2][1]; $test_m_all_answers = $test_m_array[2][2]; $test_m_all_keys = $test_m_array[2][3]; } $mastery_message = !empty($custom_fields['go_mta_mastery_message'][0]) ? $custom_fields['go_mta_mastery_message'][0] : ''; // Mastery Message $mastery_upload = !empty($custom_fields['go_mta_mastery_upload'][0]) ? $custom_fields['go_mta_mastery_upload'][0] : false; if ($repeat == 'on') { // Checks if the task is repeatable and if it has a repeat limit $repeat_amount = !empty($custom_fields['go_mta_repeat_amount'][0]) ? $custom_fields['go_mta_repeat_amount'][0] : 0; $repeat_message = !empty($custom_fields['go_mta_repeat_message'][0]) ? $custom_fields['go_mta_repeat_message'][0] : ''; $repeat_upload = !empty($custom_fields['go_mta_repeat_upload'][0]) ? $custom_fields['go_mta_repeat_upload'][0] : false; $number_of_stages = 5; } } else { $number_of_stages = 3; } // Checks if the task has a bonus currency filter // Sets the filter equal to the meta field value declared in the task creation page, if none exists defaults to 0 $bonus_currency_required = !empty($custom_fields['go_mta_bonus_currency_filter'][0]) ? $custom_fields['go_mta_bonus_currency_filter'][0] : 0; // Checks if the task has a penalty filter $penalty_filter = !empty($custom_fields['go_mta_penalty_filter'][0]) ? $custom_fields['go_mta_penalty_filter'][0] : null; $locked_by_category = !empty($custom_fields['go_mta_focus_category_lock'][0]) ? $custom_fields['go_mta_focus_category_lock'][0] : null; $focus_category_lock = !empty($locked_by_category) ? true : false; $description = !empty($custom_fields['go_mta_quick_desc'][0]) ? $custom_fields['go_mta_quick_desc'][0] : ''; // Description $req_rank = !empty($custom_fields['go_mta_req_rank'][0]) ? $custom_fields['go_mta_req_rank'][0] : null; // Required Rank to accept task if (!empty($req_rank)) { $ranks = get_option('go_ranks'); if (!empty($ranks['name']) && !empty($ranks['points'])) { $index = array_search($req_rank, $ranks['name']); $req_points = $ranks['points'][$index]; } else { $req_points = null; } } else { $req_points = null; } $points_array = !empty($rewards['points']) ? $rewards['points'] : array(); $points_str = implode(' ', $points_array); $currency_array = !empty($rewards['currency']) ? $rewards['currency'] : array(); $currency_str = implode(' ', $currency_array); $bonus_currency_array = !empty($rewards['bonus_currency']) ? $rewards['bonus_currency'] : array(); $bonus_currency_str = implode(' ', $bonus_currency_array); $current_bonus_currency = go_return_bonus_currency($user_ID); $current_penalty = go_return_penalty($user_ID); $go_admin_email = get_option('go_admin_email'); if ($go_admin_email) { $admin = get_user_by('email', $go_admin_email); } // use display name of admin with store email, or use default name if (!empty($admin)) { $admin_name = addslashes($admin->display_name); } else { $admin_name = 'an administrator'; } $is_admin = false; $user_obj = get_user_by('id', $user_ID); $user_roles = $user_obj->roles; if (!empty($user_roles)) { foreach ($user_roles as $role) { if ($role === "administrator") { $is_admin = true; break; } } } $content_post = get_post($id); // Grabs content of a task from the post table in your wordpress database where post_id = id in the shortcode. $task_content = $content_post->post_content; // Grabs what the task actually says in the body of it if ($task_content != '' && empty($custom_fields['go_mta_accept_message'])) { // If content is returned from the post table, and the post doesn't have an accept message meta field, run this code add_post_meta($id, 'go_mta_accept_message', $task_content); // Add accept message meta field with value of the post's content from post table } else { // If the task has content in the post table, and has a meta field, run this code $accept_message = !empty($custom_fields['go_mta_accept_message'][0]) ? $custom_fields['go_mta_accept_message'][0] : ''; // Set value of accept message equal to the task's accept message meta field value } $start_filter_info = !empty($custom_fields['go_mta_start_filter'][0]) ? unserialize($custom_fields['go_mta_start_filter'][0]) : null; if (!empty($start_filter_info)) { $start_filter = $start_filter_info[0]; if (!empty($start_filter)) { $start_date = $start_filter_info[1]; $start_time = $start_filter_info[2]; // storing the unix timestamp by concatenating start date and time strings $start_unix = strtotime($start_date . $start_time); if ($unix_now < $start_unix) { $time_string = date('g:i A', $start_unix) . " on " . date('D, F j, Y', $start_unix); return "<span id='go_future_notification'>Will be available at {$time_string}.</span>"; } } } $future_switches = !empty($custom_fields['go_mta_time_filters'][0]) ? unserialize($custom_fields['go_mta_time_filters'][0]) : null; // Array of future modifier switches, determines whether the calendar option or time after stage one option is chosen $date_picker = !empty($custom_fields['go_mta_date_picker'][0]) && unserialize($custom_fields['go_mta_date_picker'][0]) ? array_filter(unserialize($custom_fields['go_mta_date_picker'][0])) : false; $sounded_array = (array) get_user_meta($user_ID, 'go_sounded_tasks', true); // If there are dates in the date picker if (!empty($date_picker) && (!empty($future_switches['calendar']) && $future_switches['calendar'] == 'on')) { $dates = $date_picker['date']; $times = $date_picker['time']; $percentages = $date_picker['percent']; // Setup empty array to house which dates are closest, in unix timestamp $past_dates = array(); echo "<span id='go_future_notification'><span id='go_future_notification_task_name'>Time Sensitive " . ucfirst($task_name) . ":</span><br/>"; foreach ($dates as $key => $date) { // If current date in loop is in the past, add its key to the array of date modifiers $english_date = date("D, F j, Y", strtotime($date)); $correct_time = date("g:i A", strtotime($times[$key])); echo "After {$correct_time} on {$english_date} the rewards will be irrevocably reduced by {$percentages[$key]}%.<br/>"; if ($unix_now >= strtotime($date) + strtotime($times[$key], 0)) { $past_dates[$key] = abs($unix_now - strtotime($date)); } } echo "</span>"; if (!empty($past_dates)) { // Sorts array from least to greatest // Should pust most recent PAST date as first key in array, making grabbing the percentage associated with that day easy asort($past_dates); $update_percent = (double) ((100 - $percentages[key($past_dates)]) / 100); $sounded_date = $sounded_array['date'][$id]; if (!$sounded_date) { ?> <script type='text/javascript'> go_sounds( 'timer' ); </script> <?php $sounded_array['date'][$id] = true; update_user_meta($user_ID, 'go_sounded_tasks', $sounded_array); } } else { $update_percent = 1; } } else { $update_percent = 1; } $date_update_percent = $update_percent; $future_modifier = !empty($custom_fields['go_mta_time_modifier'][0]) ? unserialize($custom_fields['go_mta_time_modifier'][0]) : null; $future_timer = false; if (!empty($future_modifier) && (!empty($future_switches['future']) && $future_switches['future'] == 'on') && !($future_modifier['days'] == 0 && $future_modifier['hours'] == 0 && $future_modifier['minutes'] == 0 && $future_modifier['seconds'] == 0)) { $user_timers = get_user_meta($user_ID, 'go_timers'); $accept_timestamp = !empty($user_timers[0][$id]) ? $user_timers[0][$id] : strtotime(str_replace('@', ' ', $wpdb->get_var("SELECT timestamp FROM {$wpdb->prefix}go WHERE uid='{$user_ID}' AND post_id='{$id}'"))); $days = (int) $future_modifier['days']; $hours = (int) $future_modifier['hours']; $minutes = (int) $future_modifier['minutes']; $seconds = (int) $future_modifier['seconds']; $future_time = strtotime("{$days} days", 0) + strtotime("{$hours} hours", 0) + strtotime("{$minutes} minutes", 0) + strtotime("{$seconds} seconds", 0) + $accept_timestamp; if ($status == 2 || !empty($accept_timestamp) && $status < 3) { go_task_timer($id, $user_ID, $future_modifier); } if ($future_time != $accept_timestamp && ($unix_now >= $future_time && $status >= 2 || $unix_now >= $future_time && !empty($accept_timestamp))) { $future_update_percent = (double) ((100 - $future_modifier['percentage']) / 100); $future_timer = true; } else { $future_update_percent = 1; } if ($status < 3) { $time_string = (!empty($days) ? "{$days} day" . ($days > 1 ? 's' : '') . (!empty($hours) || !empty($minutes) || !empty($seconds) ? ', ' : '') : '') . (!empty($hours) ? "{$hours} hour" . ($hours > 1 ? 's' : '') . (!empty($minutes) || !empty($seconds) ? ', ' : '') : '') . (!empty($minutes) ? "{$minutes} minute" . ($minutes > 1 ? 's' : '') . (!empty($seconds) ? ', ' : '') : '') . (!empty($seconds) ? "{$seconds} second" . ($seconds > 1 ? 's' : '') : ''); } echo "<span id='go_future_notification'><span id='go_future_notification_task_name'>Time Sensitive " . ucfirst($task_name) . ":</span><br/> After accepting you will have {$time_string} to " . strtolower(go_return_options('go_third_stage_button')) . " the {$task_name} or the rewards will be irrevocably reduced by {$future_modifier['percentage']}%.</span>"; } else { $future_update_percent = 1; } if (!empty($future_switches['calendar']) && $future_switches['calendar'] == 'on') { $update_percent = $date_update_percent; } elseif (!empty($future_switches['future']) && $future_switches['future'] == 'on') { $update_percent = $future_update_percent; } else { $update_percent = 1; } global $current_points; if ($is_admin === false && !empty($req_points) && $current_points < $req_points) { $points = $req_points - $current_points; $points_name = strtolower(go_return_options('go_points_name')); echo "You need {$points} more {$points_name} to begin this {$task_name}."; } else { switch ($status) { case 0: $db_task_stage_upload_var = 'e_uploaded'; break; case 1: $db_task_stage_upload_var = 'a_uploaded'; break; case 2: $db_task_stage_upload_var = 'c_uploaded'; break; case 3: $db_task_stage_upload_var = 'm_uploaded'; break; case 4: $db_task_stage_upload_var = 'r_uploaded'; break; } if (!empty($db_task_stage_upload_var)) { $is_uploaded = $wpdb->get_var("SELECT {$db_task_stage_upload_var} FROM {$go_table_name} WHERE uid = {$user_ID} AND post_id = {$id}"); } else { $is_uploaded = 0; } if (get_the_terms($id, 'task_focus_categories') && $focus_category_lock) { $categories = get_the_terms($id, 'task_focus_categories'); $category_names = array(); foreach ($categories as $category) { array_push($category_names, $category->name); } } if (get_user_meta($user_ID, 'go_focus', true) != '') { $user_focus = get_user_meta($user_ID, 'go_focus', true); } if (!empty($category_names) && $user_focus) { $go_ahead = array_intersect($user_focus, $category_names); } go_display_rewards($user_ID, $points_array, $currency_array, $bonus_currency_array, $update_percent, $number_of_stages, $future_timer); ?> <script type="text/javascript"> <?php if (!empty($future_switches['calendar']) && $future_switches['calendar'] == 'on' && $update_percent != 1) { ?> var num_of_stages = parseInt( <?php echo $number_of_stages; ?> ); for ( i = 1; i <= num_of_stages; i++ ) { var stage_points = jQuery( '#go_stage_' + i + '_points' ); var stage_currency = jQuery( '#go_stage_' + i + '_currency' ); var stage_bonus_currency = jQuery( '#go_stage_' + i + '_bonus_currency' ); if ( stage_points.length && ! stage_points.hasClass( 'go_updated' ) ) { stage_points.addClass( 'go_updated' ); } if ( stage_currency.length && ! stage_currency.hasClass( 'go_updated' ) ) { stage_currency.addClass( 'go_updated' ); } if ( stage_bonus_currency.length && ! stage_bonus_currency.hasClass( 'go_updated' ) ) { stage_bonus_currency.addClass( 'go_updated' ); } } <?php } ?> var timers = []; jQuery( '.entry-title' ).after( jQuery( '.go_task_rewards' ) ); <?php if ($update_percent != 1 && (!empty($future_switches['future']) && $future_switches['future'] == 'on')) { ?> jQuery( '#go_stage_3_points' ).addClass( 'go_updated' ); jQuery( '#go_stage_3_currency' ).addClass( 'go_updated' ); <?php } if ($status >= 3 && (!empty($future_switches['future']) && $future_switches['future'] == 'on')) { ?> jQuery( '#go_future_notification' ).hide(); <?php } ?> if ( jQuery( '#go_task_timer' ).length ) { jQuery( '.go_task_rewards' ).after( jQuery( '#go_task_timer' ) ); } </script> <div id="go_description"><div class="go_stage_message"><?php echo do_shortcode(wpautop($description)); ?> </div></div> <?php if (!empty($future_switches['future']) && $future_switches['future'] == 'on' && $status < 2) { $update_percent = 1; } // If current post in a chain and user logged in if (!empty($custom_fields['chain'][0])) { $final_chain_message = !empty($custom_fields['go_mta_final_chain_message'][0]) ? $custom_fields['go_mta_final_chain_message'][0] : null; $current_position_in_chain = get_post_meta($id, 'chain_position', true); $chain_tax = get_the_terms($id, 'task_chains'); //Grab chain object for this post $chain_tax_array = array_values($chain_tax); $chain = array_shift($chain_tax_array); //Grab all posts in the current chain in order $posts_in_chain = get_posts(array('post_type' => 'tasks', 'taxonomy' => 'task_chains', 'term' => $chain->name, 'order' => 'ASC', 'meta_key' => 'chain_position', 'orderby' => 'meta_value_num', 'posts_per_page' => '-1')); // Loop through each one and make array of their ids foreach ($posts_in_chain as $post_in_chain) { $post_ids_in_chain[] = $post_in_chain->ID; } // Setup next task in chain if ($id != end($post_ids_in_chain)) { $next_post_id_in_chain = $post_ids_in_chain[array_search($id, $post_ids_in_chain) + 1]; $next_post_in_chain = '<a href="' . get_permalink($next_post_id_in_chain) . '">' . get_the_title($next_post_id_in_chain) . '</a>'; } $post_ids_in_chain_string = join(',', $post_ids_in_chain); // Grab all posts in chain statuses $list = $wpdb->get_results("\n\t\t\t\tSELECT post_id,status\n\t\t\t\tFROM {$go_table_name}\n\t\t\t\tWHERE uid = {$user_ID}\n\t\t\t\tAND post_id IN ( {$post_ids_in_chain_string} )\n\t\t\t\tORDER BY FIELD( post_id, {$post_ids_in_chain_string} )\n\t\t\t"); // Make array of statuses in chain indexed by post id foreach ($list as $post_obj) { $post_status_in_chain[$post_obj->post_id] = $post_obj->status; } foreach ($post_ids_in_chain as $post_id_in_chain) { if ($post_id_in_chain == $id) { break; } $post_custom_in_chain = get_post_custom($post_id_in_chain); $post_mastery_active_in_chain = !empty($post_custom_in_chain['go_mta_task_mastery'][0]) ? !$post_custom_in_chain['go_mta_task_mastery'][0] : true; // $post_number_of_stages_in_chain will later be designated by an admin option that will be toggleable per task chain. if ($post_mastery_active_in_chain) { $post_number_of_stages_in_chain = 3; } else { $post_number_of_stages_in_chain = 3; } // Check if current post in loop has been completed/mastered, depending on the number of stages in the task that needs to be completed if ($post_status_in_chain[$post_id_in_chain] < $post_number_of_stages_in_chain) { $previous_task = '<a href="' . get_permalink($post_id_in_chain) . '">' . get_the_title($post_id_in_chain) . '</a>'; echo "You must finish {$previous_task} to do this {$task_name}"; return false; } } if ($current_position_in_chain == $chain->count) { $last_in_chain = true; } else { $last_in_chain = false; } } if ($is_admin === true || $go_ahead || !isset($focus_category_lock) || empty($category_names)) { if ($current_bonus_currency >= $bonus_currency_required && !empty($bonus_currency_required) && ($current_penalty < $penalty_filter && !empty($penalty_filter)) || empty($bonus_currency_required) && empty($penalty_filter)) { switch ($status) { // First time a user encounters a task case 0: // sending go_add_post the $repeat var was the problem, that is why it is now sending a null value. go_add_post($user_ID, $id, 0, floor($update_percent * $points_array[0]), floor($update_percent * $currency_array[0]), floor($update_percent * $bonus_currency_array[0]), null, $page_id, null, 0, 0, 0, 0, 0); go_record_stage_time($page_id, 1); ?> <div id="go_content"> <?php if ($test_e_active) { echo "<p id='go_test_error_msg' style='color: red;'></p>"; if ($test_e_num > 1) { for ($i = 0; $i < $test_e_num; $i++) { echo do_shortcode("[go_test type='" . $test_e_all_types[$i] . "' question='" . $test_e_all_questions[$i] . "' possible_answers='" . $test_e_all_answers[$i] . "' key='" . $test_e_all_keys[$i] . "' test_id='" . $i . "' total_num='" . $test_e_num . "']"); } echo "<div class='go_test_submit_div' style='display: none;'><button class='go_test_submit'>Submit</button></div>"; } else { echo do_shortcode("[go_test type='" . $test_e_all_types[0] . "' question='" . $test_e_all_questions[0] . "' possible_answers='" . $test_e_all_answers[0] . "' key='" . $test_e_all_keys[0] . "' test_id='0']") . "<div class='go_test_submit_div' style='display: none;'><button class='go_test_submit'>Submit</button></div>"; } } if ($encounter_upload) { echo do_shortcode("[go_upload is_uploaded={$is_uploaded} status={$status} user_id={$user_ID} post_id={$id}]") . "<br/>"; } ?> <p id='go_stage_error_msg' style='display: none; color: red;'></p> <?php if ($e_is_locked === 'true' && !empty($e_pass_lock)) { echo "<input id='go_pass_lock' type='password' placeholder='Enter Password'/></br>"; } elseif ($e_url_is_locked === true) { echo "<input id='go_url_key' type='url' placeholder='Enter Url'/></br>"; } ?> <button id="go_button" status= "2" onclick="task_stage_change( this );" <?php if ($e_is_locked === 'true' && empty($e_pass_lock)) { echo "admin_lock='true'"; } ?> ><?php echo go_return_options('go_second_stage_button'); ?> </button> <button id="go_abandon_task" onclick="go_task_abandon();this.disabled = true;"><?php echo get_option('go_abandon_stage_button', 'Abandon'); ?> </button> </div> <?php echo !empty($task_pods) && !empty($pods_array) ? "<br/><a href='{$pod_link}'>Return to Pod Page</a>" : ""; break; // Encountered // Encountered case 1: ?> <div id="go_content"> <?php if ($test_e_active) { echo "<p id='go_test_error_msg' style='color: red;'></p>"; if ($test_e_num > 1) { for ($i = 0; $i < $test_e_num; $i++) { echo do_shortcode("[go_test type='" . $test_e_all_types[$i] . "' question='" . $test_e_all_questions[$i] . "' possible_answers='" . $test_e_all_answers[$i] . "' key='" . $test_e_all_keys[$i] . "' test_id='" . $i . "' total_num='" . $test_e_num . "']"); } echo "<div class='go_test_submit_div' style='display: none;'><button class='go_test_submit'>Submit</button></div>"; } else { echo do_shortcode("[go_test type='" . $test_e_all_types[0] . "' question='" . $test_e_all_questions[0] . "' possible_answers='" . $test_e_all_answers[0] . "' key='" . $test_e_all_keys[0] . "' test_id='0']") . "<div class='go_test_submit_div' style='display: none;'><button class='go_test_submit'>Submit</button></div>"; } } if ($encounter_upload) { echo do_shortcode("[go_upload is_uploaded={$is_uploaded} status={$status} user_id={$user_ID} post_id={$id}]") . "<br/>"; } ?> <p id='go_stage_error_msg' style='display: none; color: red;'></p> <?php if ($e_is_locked === 'true' && !empty($e_pass_lock)) { echo "<input id='go_pass_lock' type='password' placeholder='Enter Password'/></br>"; } elseif ($e_url_is_locked === true) { echo "<input id='go_url_key' type='url' placeholder='Enter Url'/></br>"; } ?> <button id="go_button" status= "2" onclick="task_stage_change( this );" <?php if ($e_is_locked === 'true' && empty($e_pass_lock)) { echo "admin_lock='true'"; } ?> ><?php echo go_return_options('go_second_stage_button'); ?> </button> <button id="go_abandon_task" onclick="go_task_abandon();this.disabled = true;"><?php echo get_option('go_abandon_stage_button', 'Abandon'); ?> </button> </div> <?php echo !empty($task_pods) && !empty($pods_array) ? "<br/><a href='{$pod_link}'>Return to Pod Page</a>" : ""; break; // Accepted // Accepted case 2: echo '<div id="go_content"><div class="go_stage_message">' . do_shortcode(wpautop($accept_message)) . '</div>'; if ($test_a_active) { echo "<p id='go_test_error_msg' style='color: red;'></p>"; if ($test_a_num > 1) { for ($i = 0; $i < $test_a_num; $i++) { echo do_shortcode("[go_test type='" . $test_a_all_types[$i] . "' question='" . $test_a_all_questions[$i] . "' possible_answers='" . $test_a_all_answers[$i] . "' key='" . $test_a_all_keys[$i] . "' test_id='" . $i . "' total_num='" . $test_a_num . "']"); } echo "<div class='go_test_submit_div' style='display: none;'><button class='go_test_submit'>Submit</button></div>"; } else { echo do_shortcode("[go_test type='" . $test_a_all_types[0] . "' question='" . $test_a_all_questions[0] . "' possible_answers='" . $test_a_all_answers[0] . "' key='" . $test_a_all_keys[0] . "' test_id='0']") . "<div class='go_test_submit_div' style='display: none;'><button class='go_test_submit'>Submit</button></div>"; } } if ($accept_upload) { echo do_shortcode("[go_upload is_uploaded={$is_uploaded} status={$status} user_id={$user_ID} post_id={$id}]") . "<br/>"; } echo "<p id='go_stage_error_msg' style='display: none; color: red;'></p>"; if ($a_is_locked === 'true' && !empty($a_pass_lock)) { echo "<input id='go_pass_lock' type='password' placeholder='Enter Password'/></br>"; } elseif ($a_url_is_locked === true) { echo "<input id='go_url_key' type='url' placeholder='Enter Url'/></br>"; } echo "<button id='go_button' status='3' onclick='task_stage_change( this );'"; if ($a_is_locked === 'true' && empty($a_pass_lock)) { echo "admin_lock='true'"; } echo '>' . go_return_options('go_third_stage_button') . '</button> <button id="go_back_button" onclick="task_stage_change( this );" undo="true">Undo</button> </div>' . (!empty($task_pods) && !empty($pods_array) ? "<br/><a href='{$pod_link}'>Return to Pod Page</a>" : ""); break; // Completed // Completed case 3: echo '<div id="go_content"><div class="go_stage_message">' . do_shortcode(wpautop($accept_message)) . '</div><div class="go_stage_message"> ' . do_shortcode(wpautop($completion_message)) . '</div>'; if ($mastery_active) { if ($test_c_active) { echo "<p id='go_test_error_msg' style='color: red;'></p>"; if ($test_c_num > 1) { for ($i = 0; $i < $test_c_num; $i++) { echo do_shortcode("[go_test type='" . $test_c_all_types[$i] . "' question='" . $test_c_all_questions[$i] . "' possible_answers='" . $test_c_all_answers[$i] . "' key='" . $test_c_all_keys[$i] . "' test_id='" . $i . "' total_num='" . $test_c_num . "']"); } echo "<div class='go_test_submit_div' style='display: none;'><button class='go_test_submit'>Submit</button></div>"; } else { echo do_shortcode("[go_test type='" . $test_c_all_types[0] . "' question='" . $test_c_all_questions[0] . "' possible_answers='" . $test_c_all_answers[0] . "' key='" . $test_c_all_keys[0] . "' test_id='0']") . "<div class='go_test_submit_div' style='display: none;'><button class='go_test_submit'>Submit</button></div>"; } } if ($completion_upload) { echo do_shortcode("[go_upload is_uploaded={$is_uploaded} status={$status} user_id={$user_ID} post_id={$id}]") . "<br/>"; } echo "<p id='go_stage_error_msg' style='display: none; color: red;'></p>"; if ($c_is_locked === 'true' && !empty($c_pass_lock)) { echo "<input id='go_pass_lock' type='password' placeholder='Enter Password'/></br>"; } elseif ($c_url_is_locked === true) { echo "<input id='go_url_key' type='url' placeholder='Enter Url'/></br>"; } echo "<button id='go_button' status='4' onclick='task_stage_change( this );'"; if ($c_is_locked === 'true' && empty($c_pass_lock)) { echo "admin_lock='true'"; } echo '>' . go_return_options('go_fourth_stage_button') . '</button> <button id="go_back_button" onclick="task_stage_change( this );" undo="true">Undo</button>'; if (!empty($next_post_in_chain) && !$last_in_chain) { echo "<div class='go_chain_message'>Next {$task_name} in {$chain->name}: {$next_post_in_chain}</div>"; } elseif (!empty($final_chain_message)) { echo '<div class="go_chain_message">' . $final_chain_message . '</div>'; } echo "</div>" . (!empty($task_pods) && !empty($pods_array) ? "<br/><a href='{$pod_link}'>Return to Pod Page</a>" : ""); } else { if ($test_c_active) { echo "<p id='go_test_error_msg' style='color: red;'></p>"; if ($test_c_num > 1) { for ($i = 0; $i < $test_c_num; $i++) { echo do_shortcode("[go_test type='" . $test_c_all_types[$i] . "' question='" . $test_c_all_questions[$i] . "' possible_answers='" . $test_c_all_answers[$i] . "' key='" . $test_c_all_keys[$i] . "' test_id='" . $i . "' total_num='" . $test_c_num . "']"); } echo "<div class='go_test_submit_div' style='display: none;'><button class='go_test_submit'>Submit</button></div>"; } else { echo do_shortcode("[go_test type='" . $test_c_all_types[0] . "' question='" . $test_c_all_questions[0] . "' possible_answers='" . $test_c_all_answers[0] . "' key='" . $test_c_all_keys[0] . "' test_id='0']") . "<div class='go_test_submit_div' style='display: none;'><button class='go_test_submit'>Submit</button></div>"; } } if ($completion_upload) { echo do_shortcode("[go_upload is_uploaded={$is_uploaded} status={$status} user_id={$user_ID} post_id={$id}]") . "<br/>"; } echo '<span id="go_button" status="4" style="display:none;"></span><button id="go_back_button" onclick="task_stage_change( this );" undo="true">Undo</button>'; if ($next_post_in_chain && !$last_in_chain) { echo "<div class='go_chain_message'>Next {$task_name} in {$chain->name}: {$next_post_in_chain}</div>"; } else { echo '<div class="go_chain_message">' . $final_chain_message . '</div>'; } echo "</div>" . (!empty($task_pods) && !empty($pods_array) ? "<br/><a href='{$pod_link}'>Return to Pod Page</a>" : ""); } break; // Mastered // Mastered case 4: echo '<div id="go_content"><div class="go_stage_message">' . do_shortcode(wpautop($accept_message)) . '</div>' . '<div class="go_stage_message">' . do_shortcode(wpautop($completion_message)) . '</div><div class="go_stage_message">' . do_shortcode(wpautop($mastery_message)) . '</div>'; if ($repeat == 'on') { if ($task_count < $repeat_amount || $repeat_amount == 0) { // Checks if the amount of times a user has completed a task is less than the amount of times they are allowed to complete a task. If so, outputs the repeat button to allow the user to repeat the task again. if ($task_count == 0) { if ($test_m_active) { echo "<p id='go_test_error_msg' style='color: red;'></p>"; if ($test_m_num > 1) { for ($i = 0; $i < $test_m_num; $i++) { echo do_shortcode("[go_test type='" . $test_m_all_types[$i] . "' question='" . $test_m_all_questions[$i] . "' possible_answers='" . $test_m_all_answers[$i] . "' key='" . $test_m_all_keys[$i] . "' test_id='" . $i . "' total_num='" . $test_m_num . "']"); } echo "<div class='go_test_submit_div' style='display: none;'><button class='go_test_submit'>Submit</button></div>"; } else { echo do_shortcode("[go_test type='" . $test_m_all_types[0] . "' question='" . $test_m_all_questions[0] . "' possible_answers='" . $test_m_all_answers[0] . "' key='" . $test_m_all_keys[0] . "' test_id='0']") . "<div class='go_test_submit_div' style='display: none;'><button class='go_test_submit'>Submit</button></div>"; } } if ($mastery_upload) { echo do_shortcode("[go_upload is_uploaded={$is_uploaded} status={$status} user_id={$user_ID} post_id={$id}]") . "<br/>"; } echo ' <div id="repeat_quest"> <div id="go_repeat_clicked" style="display:none;"><div class="go_stage_message">' . do_shortcode(wpautop($repeat_message)) . "</div><p id='go_stage_error_msg' style='display: none; color: red;'></p>"; if ($m_is_locked === 'true' && !empty($m_pass_lock)) { echo "<input id='go_pass_lock' type='password' placeholder='Enter Password'/></br>"; } elseif ($m_url_is_locked === true) { echo "<input id='go_url_key' type='url' placeholder='Enter Url'/></br>"; } echo "<button id='go_button' status='4' onclick='go_repeat_hide( this );' repeat='on'"; if ($m_is_locked === 'true' && empty($m_pass_lock)) { echo "admin_lock='true'"; } echo '>' . go_return_options('go_fourth_stage_button') . " Again" . '</button> <button id="go_back_button" onclick="task_stage_change( this );" undo="true">Undo</button> </div>' . (!empty($task_pods) && !empty($pods_array) ? "<br/><a href='{$pod_link}'>Return to Pod Page</a>" : "") . '<div id="go_repeat_unclicked"> <button id="go_button" status="4" onclick="go_repeat_replace();"> See ' . get_option('go_fifth_stage_name') . '</button> <button id="go_back_button" onclick="task_stage_change( this );" undo="true">Undo</button> </div>' . (!empty($task_pods) && !empty($pods_array) ? "<br/><a href='{$pod_link}'>Return to Pod Page</a>" : "") . '</div> '; } else { if ($repeat_upload) { echo do_shortcode("[go_upload is_uploaded={$is_uploaded} status={$status} user_id={$user_ID} post_id={$id}]") . "<br/>"; } echo ' <div id="repeat_quest"> <div id="go_repeat_clicked" style="display:none;"><div class="go_stage_message">' . do_shortcode(wpautop($repeat_message)) . "</div><p id='go_stage_error_msg' style='display: none; color: red;'></p>"; if ($r_is_locked === 'true' && !empty($r_pass_lock)) { echo "<input id='go_pass_lock' type='password' placeholder='Enter Password'/></br>"; } echo "<button id='go_button' status='4' onclick='go_repeat_hide( this );' repeat='on'"; if ($r_is_locked === 'true' && empty($r_pass_lock)) { echo "admin_lock='true'"; } echo '>' . go_return_options('go_fourth_stage_button') . " Again" . '</button> <button id="go_back_button" onclick="task_stage_change( this );" undo="true">Undo</button> </div>' . (!empty($task_pods) && !empty($pods_array) ? "<br/><a href='{$pod_link}'>Return to Pod Page</a>" : "") . '<div id="go_repeat_unclicked"> <button id="go_button" status="4" onclick="go_repeat_replace();">' . get_option('go_fifth_stage_button') . '</button> <button id="go_back_button" onclick="task_stage_change( this );" undo="true">Undo</button> </div>' . (!empty($task_pods) && !empty($pods_array) ? "<br/><a href='{$pod_link}'>Return to Pod Page</a>" : "") . '</div> '; } } else { echo '<span id="go_button" status="4" repeat="on" style="display:none;"></span><button id="go_back_button" onclick="task_stage_change( this );" undo="true">Undo</button>' . (!empty($task_pods) && !empty($pods_array) ? "<br/><a href='{$pod_link}'>Return to Pod Page</a>" : ""); } } else { if ($test_m_active) { echo "<p id='go_test_error_msg' style='color: red;'></p>"; if ($test_m_num > 1) { for ($i = 0; $i < $test_m_num; $i++) { echo do_shortcode("[go_test type='" . $test_m_all_types[$i] . "' question='" . $test_m_all_questions[$i] . "' possible_answers='" . $test_m_all_answers[$i] . "' key='" . $test_m_all_keys[$i] . "' test_id='" . $i . "' total_num='" . $test_m_num . "']"); } echo "<div class='go_test_submit_div' style='display: none;'><button class='go_test_submit'>Submit</button></div>"; } else { echo do_shortcode("[go_test type='" . $test_m_all_types[0] . "' question='" . $test_m_all_questions[0] . "' possible_answers='" . $test_m_all_answers[0] . "' key='" . $test_m_all_keys[0] . "' test_id='0']") . "<div class='go_test_submit_div' style='display: none;'><button class='go_test_submit'>Submit</button></div>"; } } if ($mastery_upload) { echo do_shortcode("[go_upload is_uploaded={$is_uploaded} status={$status} user_id={$user_ID} post_id={$id}]") . "<br/>"; } echo '<span id="go_button" status="4" repeat="on" style="display:none;"></span><button id="go_back_button" onclick="task_stage_change( this );" undo="true">Undo</button>'; } if (!empty($next_post_in_chain) && !$last_in_chain) { echo "<div class='go_chain_message'>Next {$task_name} in {$chain->name}: {$next_post_in_chain}</div>"; } elseif (!empty($final_chain_message)) { echo '<div class="go_chain_message">' . $final_chain_message . '</div>'; } echo '</div>' . (!empty($task_pods) && !empty($pods_array) ? "<br/><a href='{$pod_link}'>Return to Pod Page</a>" : ""); } if (get_post_type() == 'tasks') { comments_template(); wp_list_comments(); } } else { if ($current_bonus_currency < $bonus_currency_required && !empty($bonus_currency_required) && ($current_penalty > $penalty_filter && !empty($penalty_filter))) { echo "You require more than {$bonus_currency_required} " . go_return_options('go_bonus_currency_name') . " and less than {$penalty_filter} " . go_return_options('go_penalty_name') . " to view this " . go_return_options('go_tasks_name') . "."; } elseif ($current_bonus_currency < $bonus_currency_required && !empty($bonus_currency_required)) { echo "You require more than {$bonus_currency_required} " . go_return_options('go_bonus_currency_name') . " to view this " . go_return_options('go_tasks_name') . "."; } elseif ($current_penalty > $penalty_filter && !empty($penalty_filter)) { echo "You require less than {$penalty_filter} " . go_return_options('go_penalty_name') . " to view this " . go_return_options('go_tasks_name') . "."; } } } else { // If user can't access quest because they aren't part of the specialty, echo this $category_name = implode(',', $category_names); $focus_name = get_option('go_focus_name', 'Profession'); $task_name = strtolower(get_option('go_tasks_name', 'Quest')); echo "This {$task_name} is only available to the \"{$category_name}\" {$focus_name}."; } if ($test_e_active && $test_e_returns) { $db_test_encounter_fail_count = $wpdb->get_var("SELECT `e_fail_count` FROM {$go_table_name} WHERE post_id = {$id} AND uid = {$user_ID}"); $_SESSION['test_encounter_fail_count'] = $db_test_encounter_fail_count; $db_test_encounter_passed = $wpdb->get_var("SELECT `e_passed` FROM {$go_table_name} WHERE post_id = {$id} AND uid = {$user_ID}"); $_SESSION['test_encounter_passed'] = $db_test_encounter_passed; } if ($test_a_active && $test_a_returns) { $db_test_accept_fail_count = $wpdb->get_var("SELECT `a_fail_count` FROM {$go_table_name} WHERE post_id = {$id} AND uid = {$user_ID}"); $_SESSION['test_accept_fail_count'] = $db_test_accept_fail_count; $db_test_accept_passed = $wpdb->get_var("SELECT `a_passed` FROM {$go_table_name} WHERE post_id = {$id} AND uid = {$user_ID}"); $_SESSION['test_accept_passed'] = $db_test_accept_passed; } if ($test_c_active && $test_c_returns) { $db_test_completion_fail_count = $wpdb->get_var("SELECT `c_fail_count` FROM {$go_table_name} WHERE post_id = {$id} AND uid = {$user_ID}"); $_SESSION['test_completion_fail_count'] = $db_test_completion_fail_count; $db_test_completion_passed = $wpdb->get_var("SELECT `c_passed` FROM {$go_table_name} WHERE post_id = {$id} AND uid = {$user_ID}"); $_SESSION['test_completion_passed'] = $db_test_completion_passed; } if ($test_m_active && $test_m_returns) { $db_test_mastery_fail_count = $wpdb->get_var("SELECT `m_fail_count` FROM {$go_table_name} WHERE post_id = {$id} AND uid = {$user_ID}"); $_SESSION['test_mastery_fail_count'] = $db_test_mastery_fail_count; $test_mastery_passed = $wpdb->get_var("SELECT `m_passed` FROM {$go_table_name} WHERE post_id = {$id} AND uid = {$user_ID}"); $_SESSION['test_mastery_passed'] = $test_mastery_passed; } ?> <script language="javascript"> jQuery( document ).ready( function() { jQuery.ajaxSetup({ url: '<?php echo get_site_url(); ?> /wp-admin/admin-ajax.php' }); check_locks(); }); function go_task_abandon() { jQuery.ajax({ type: "POST", data: { action: "go_task_abandon", post_id: "<?php echo $id; ?> ", encounter_points: <?php echo floor($points_array[0] * $update_percent); ?> , encounter_currency: <?php echo floor($currency_array[0] * $update_percent); ?> , encounter_bonus: <?php echo floor($bonus_currency_array[0] * $update_percent); ?> }, success: function() { window.location = "<?php echo home_url(); ?> "; } }); } function check_locks() { if ( jQuery( ".go_test_list" ).length != 0 ) { jQuery( '.go_test_submit_div' ).show(); } var is_uploaded = jQuery( '#go_upload_form' ).attr( 'uploaded' ); if ( jQuery( ".go_test_list" ).length != 0 && jQuery( '#go_upload_form' ).length != 0 ) { if ( jQuery( '#go_pass_lock' ).length == 0 && jQuery( '#go_button' ).attr( 'admin_lock' ) !== 'true' ) { jQuery( '#go_button' ).attr( 'disabled', 'true' ); } jQuery( '.go_test_submit' ).click( function() { var test_list = jQuery( '.go_test_list' ); var current_error_msg = jQuery( '#go_test_error_msg' ).text(); if ( test_list.length > 1 ) { var checked_ans = 0; for (var i = 0; i < test_list.length; i++ ) { var obj_str = "#" + test_list[ i ].id + " input:checked"; var chosen_answers = jQuery( obj_str ); if ( chosen_answers.length >= 1 ) { checked_ans++; } else { if ( current_error_msg != "Please answer all questions!" ) { jQuery( '#go_test_error_msg' ).text( "Please answer all questions!" ); } else { flash_error_msg( '#go_test_error_msg' ); } } } if ( checked_ans >= test_list.length && is_uploaded == 1 ) { task_unlock(); } else { if ( checked_ans < test_list.length && is_uploaded != 1 ) { var error = "Please answer all questions and upload a file!"; } else if ( checked_ans < test_list.length ) { var error = "Please answer all questions!"; } else if ( is_uploaded != 1 ) { var error = "Please upload a file!"; } if ( typeof error != null ) { if ( current_error_msg != error ) { jQuery( '#go_test_error_msg' ).text( error ); } else { flash_error_msg( '#go_test_error_msg' ); } } } } else { if ( jQuery( ".go_test_list input:checked" ).length >= 1 && is_uploaded == 1 ) { task_unlock(); } else { if ( jQuery( ".go_test_list input:checked" ).length == 0 && is_uploaded != 1 ) { var error = "Please answer the question and upload a file!"; } else if ( jQuery( ".go_test_list input:checked" ).length == 0 ) { var error = "Please answer the question!"; } else if ( is_uploaded != 1 ) { var error = "Please upload a file!"; } if ( typeof error != null ) { if ( current_error_msg != error ) { jQuery( '#go_test_error_msg' ).text( error ); } else { flash_error_msg( '#go_test_error_msg' ); } } } } }); jQuery( '#go_upload_submit' ).click( function() { var test_list = jQuery( ".go_test_list" ); var current_error_msg = jQuery( '#go_test_error_msg' ).text(); if ( test_list.length > 1 ) { var checked_ans = 0; for (var i = 0; i < test_list.length; i++ ) { var obj_str = "#" + test_list[ i ].id + " input:checked"; var chosen_answers = jQuery( obj_str ); if ( chosen_answers.length >= 1 ) { checked_ans++; } else { if ( current_error_msg != "Please answer all questions!" ) { jQuery( '#go_test_error_msg' ).text( "Please answer all questions!" ); } else { flash_error_msg( '#go_test_error_msg' ); } } } if ( checked_ans >= test_list.length && is_uploaded == 1 ) { task_unlock(); } else { if ( checked_ans < test_list.length && is_uploaded != 1 ) { var error = "Please answer all questions and upload a file!"; } else if ( checked_ans < test_list.length ) { var error = "Please answer all questions!"; } else if ( is_uploaded != 1 ) { var error = "Please upload a file!"; } if ( typeof error != null ) { if ( current_error_msg != error ) { jQuery( '#go_test_error_msg' ).text( error ); } else { flash_error_msg( '#go_test_error_msg' ); } } } } else { if ( jQuery( ".go_test_list input:checked" ).length >= 1 && is_uploaded == 1 ) { task_unlock(); } else { if ( jQuery( ".go_test_list input:checked" ).length == 0 && is_uploaded != 1 ) { var error = "Please answer the question and upload a file!"; } else if ( jQuery( ".go_test_list input:checked" ).length == 0 ) { var error = "Please answer the question!"; } else if (is_uploaded != 1) { var error = "Please upload a file!"; } if ( typeof error != null ) { if ( current_error_msg != error ) { jQuery( '#go_test_error_msg' ).text( error ); } else { flash_error_msg( '#go_test_error_msg' ); } } } } }); } else if ( jQuery( ".go_test_list" ).length != 0 ) { if ( jQuery( '#go_pass_lock' ).length == 0 && jQuery( '#go_button' ).attr( 'admin_lock' ) !== 'true' ) { jQuery( '#go_button' ).attr( 'disabled', 'true' ); } jQuery( '.go_test_submit' ).click( function() { var test_list = jQuery( ".go_test_list" ); if ( test_list.length > 1 ) { var checked_ans = 0; for ( var i = 0; i < test_list.length; i++ ) { var obj_str = "#" + test_list[ i ].id + " input:checked"; var chosen_answers = jQuery( obj_str ); if ( chosen_answers.length >= 1 ) { checked_ans++; } } if ( checked_ans >= test_list.length ) { task_unlock(); } else { if ( jQuery( '#go_test_error_msg' ).text() != "Please answer all questions!" ) { jQuery( '#go_test_error_msg' ).text( "Please answer all questions!" ); } else { flash_error_msg( '#go_test_error_msg' ); } } } else { if ( jQuery( ".go_test_list input:checked" ).length >= 1 ) { task_unlock(); } else { if ( jQuery( '#go_test_error_msg' ).text() != "Please answer the question!" ) { jQuery( '#go_test_error_msg' ).text( "Please answer the question!" ); } else { flash_error_msg( '#go_test_error_msg' ); } } } }); } else if ( jQuery( '#go_upload_form' ).length != 0 && is_uploaded == 0 ) { if ( jQuery( '#go_pass_lock' ).length == 0 && jQuery( '#go_button' ).attr( 'admin_lock' ) !== 'true' ) { jQuery( '#go_button' ).attr( 'disabled', 'true' ); } jQuery( '#go_upload_submit' ).click( function() { if ( jQuery( '#go_pass_lock' ).length > 0 && jQuery( '#go_pass_lock' ).attr( 'value' ).length == 0 ) { var error = "Retrieve the password from <?php echo $admin_name; ?> ."; if ( jQuery( '#go_stage_error_msg' ).text() != error ) { jQuery( '#go_stage_error_msg' ).text( error ); } else { flash_error_msg( '#go_stage_error_msg' ); } } else { task_unlock(); } }); } if ( ( jQuery( '#go_pass_lock' ).length > 0 && jQuery( '#go_pass_lock' ).attr( 'value' ).length == 0 ) && ( jQuery( '#go_upload_form' ).length != 0 && is_uploaded == 0 ) || jQuery( ".go_test_list" ).length != 0 ) { if ( jQuery( '#go_stage_error_msg' ).is( ":visible" ) ) { var error = "Retrieve the password from <?php echo $admin_name; ?> ."; if ( jQuery( '#go_stage_error_msg' ).text() != error ) { jQuery( '#go_stage_error_msg' ).text( error ); } else { flash_error_msg( '#go_stage_error_msg' ); } } } } function flash_error_msg( elem ) { var bg_color = jQuery( elem ).css( 'background-color' ); if ( typeof bg_color === undefined ) { bg_color = "white"; } jQuery( elem ).animate({ color: bg_color }, 200, function() { jQuery( elem ).animate({ color: "red" }, 200 ); }); } function task_unlock() { if ( jQuery( ".go_test_list" ).length != 0) { var test_list = jQuery( ".go_test_list" ); var list_size = test_list.length; if ( jQuery( '.go_test_list :checked' ).length >= list_size ) { var test_list = jQuery( ".go_test_list" ); var list_size = test_list.length; var type_array = []; if ( jQuery( ".go_test_list" ).length > 1) { var choice_array = []; for ( var x = 0; x < list_size; x++ ) { // figure out the type of each test var test_type = test_list[ x ].children[1].children[0].type; type_array.push( test_type ); // get the checked inputs of each test var obj_str = "#" + test_list[ x ].id + " :checked"; var chosen_answers = jQuery( obj_str ); if ( test_type == 'radio' ) { // push indiviudal answers to the choice_array if ( chosen_answers[0] != undefined ) { choice_array.push( chosen_answers[0].value ); } } else if ( test_type == 'checkbox' ) { var t_array = []; for ( var i = 0; i < chosen_answers.length; i++ ) { t_array.push( chosen_answers[ i ].value ); } var choice_str = t_array.join( "### " ); choice_array.push( choice_str ); } } var choice = choice_array.join( "#### " ); var type = type_array.join( "### " ); } else { var chosen_answer = jQuery( '.go_test_list li input:checked' ); var type = jQuery( '.go_test_list li input' ).first().attr( "type" ); if ( type == 'radio' ) { var choice = chosen_answer[0].value; } else if ( type == 'checkbox' ) { var choice = []; for (var i = 0; i < chosen_answer.length; i++ ) { choice.push( chosen_answer[ i ].value ); } choice = choice.join( "### " ); } } } else { jQuery( '#go_test_error_msg' ).text( "Answer all questions!" ); } } var is_repeating = jQuery( '#go_button' ).attr( 'repeat' ); if ( is_repeating !== 'on' ) { var status = jQuery( '#go_button' ).attr( 'status' ) - 2; } else { var status = jQuery( '#go_button' ).attr( 'status' ) - 1; } jQuery.ajax({ type: "POST", data:{ action: 'unlock_stage', task: <?php echo $id; ?> , list_size: list_size, chosen_answer: choice, type: type, status: status, points: "<?php echo $points_str; ?> ", }, success: function( response ) { if ( response === 1 || response === '1' ) { jQuery( '.go_test_container' ).hide( 'slow' ); jQuery( '#test_failure_msg' ).hide( 'slow' ); jQuery( '.go_test_submit_div' ).hide( 'slow' ); jQuery( '.go_wrong_answer_marker' ).hide(); if ( ! jQuery( '#go_button' ).attr( 'admin_lock' ) ) { jQuery( '#go_button' ).removeAttr( 'disabled' ); jQuery( '#go_test_error_msg' ).attr( 'style', 'color:green' ); jQuery( '#go_test_error_msg' ).text( "Well done, continue!" ); } else { jQuery( '#go_test_error_msg' ).text( "This stage can only be unlocked by <?php echo $admin_name; ?> ." ); } var test_e_returns = "<?php echo !empty($test_e_returns) ? $test_e_returns : ''; ?> "; var test_a_returns = "<?php echo !empty($test_a_returns) ? $test_a_returns : ''; ?> "; var test_c_returns = "<?php echo !empty($test_c_returns) ? $test_c_returns : ''; ?> "; var test_m_returns = "<?php echo !empty($test_m_returns) ? $test_m_returns : ''; ?> "; if ( ( status == 0 && test_e_returns == 'on' ) || ( status == 1 && test_a_returns == 'on' ) || ( status == 2 && test_c_returns == 'on' ) || ( status == 3 && test_m_returns == 'on' ) ) { test_point_update(); } } else { if ( typeof response === 'string' && list_size > 1 ) { var failed_questions = response.split( ', ' ); for ( var x = 0; x < test_list.length; x++ ) { var test_id = "#" + test_list[ x ].id; if ( jQuery.inArray( test_id, failed_questions ) === -1) { if ( jQuery(test_id + " .go_wrong_answer_marker" ).is( ":visible" ) ) { jQuery(test_id + " .go_wrong_answer_marker" ).hide(); } if ( ! jQuery(test_id + " .go_correct_answer_marker" ).is( ":visible" ) ) { jQuery(test_id + " .go_correct_answer_marker" ).show(); } } else { if ( jQuery(test_id + " .go_correct_answer_marker" ).is( ":visible" ) ) { jQuery(test_id + " .go_correct_answer_marker" ).hide(); } if ( ! jQuery(test_id + " .go_wrong_answer_marker" ).is( ":visible" ) ) { jQuery(test_id + " .go_wrong_answer_marker" ).show(); } } } } var error_msg_val = jQuery( '#go_test_error_msg' ).text(); if ( error_msg_val != "Wrong answer, try again!" ) { jQuery( '#go_test_error_msg' ).text( "Wrong answer, try again!" ); } else { flash_error_msg( '#go_test_error_msg' ); } } // console.log(response); } }); } function test_point_update() { var is_repeating = jQuery( '#go_button' ).attr( 'repeat' ); if (is_repeating !== 'on' ) { var status = jQuery( '#go_button' ).attr( 'status' ) - 2; } else { var status = jQuery( '#go_button' ).attr( 'status' ) - 1; } jQuery.ajax({ type: "POST", data: { action: "test_point_update", points: "<?php echo $points_str; ?> ", currency: "<?php echo $currency_str; ?> ", bonus_currency: "<?php echo $bonus_currency_str; ?> ", status: status, page_id: <?php echo $page_id; ?> , user_ID: <?php echo $user_ID; ?> , post_id: <?php echo $id; ?> , update_percent: <?php echo $date_update_percent; ?> }, success: function( response ) { // the three following lines are required for the go_notification to work var color = jQuery( '#go_admin_bar_progress_bar' ).css( "background-color" ); jQuery( '#go_content' ).append( response ); jQuery( '#go_admin_bar_progress_bar' ).css({ "background-color": color }); // console.log( "\n" +response); } }); } function go_repeat_hide( target ) { // hides the div#repeat_quest to create the repeat cycle. // jQuery( "#repeat_quest" ).hide( 'slow' ); setTimeout( function() { // passes the jQuery object received in the parameter of the go_repeat_hide function // as an argument for the task_stage_change function, after 500 milliseconds (1.5 seconds). task_stage_change( target ); }, 500 ); } function go_repeat_replace() { jQuery( '#go_repeat_unclicked' ).remove(); jQuery( '#go_repeat_clicked' ).show( 'slow' ); } function task_stage_change( target ) { var undoing = jQuery( target ).attr( 'undo' ); if ( typeof( undoing ) === 'undefined' ) { undoing = 'false'; } if ( 'true' !== undoing && jQuery( '#go_button' ).length > 0 ) { var perma_locked = jQuery( '#go_button' ).attr( 'admin_lock' ); if ( perma_locked === 'true' ) { jQuery( '#go_stage_error_msg' ).show(); jQuery( '#go_button' ).removeAttr( 'disabled' ); jQuery( '#go_stage_error_msg' ).text( "This stage can only be unlocked by <?php echo $admin_name; ?> ." ); return; } } if ( 'true' !== undoing && jQuery( '#go_pass_lock' ).length > 0 ) { var pass_entered = jQuery( '#go_pass_lock' ).attr( 'value' ).length > 0 ? true : false; if ( ! pass_entered ) { jQuery( '#go_stage_error_msg' ).show(); var error = "Retrieve the password from <?php echo $admin_name; ?> ."; if ( jQuery( '#go_stage_error_msg' ).text() != error ) { jQuery( '#go_stage_error_msg' ).text( error ); } else { flash_error_msg( '#go_stage_error_msg' ); } return; } } else if ( 'true' !== undoing && jQuery( '#go_url_key' ).length > 0 ) { var the_url = jQuery( '#go_url_key' ).attr( 'value' ).replace(/\s+/, '' ); if ( the_url.length > 0 ) { if ( the_url.match(/^(http:\/\/|https:\/\/).*\..*$/) && ! ( the_url.lastIndexOf( 'http://' ) > 0 ) && ! ( the_url.lastIndexOf( 'https://' ) > 0 ) ) { var url_entered = true; } else { jQuery( '#go_stage_error_msg' ).show(); var error = "Enter a valid URL."; if ( jQuery( '#go_stage_error_msg' ).text() != error ) { jQuery( '#go_stage_error_msg' ).text( error ); } else { flash_error_msg( '#go_stage_error_msg' ); } return; } } else { jQuery( '#go_stage_error_msg' ).show(); var error = "Enter a valid URL."; if ( jQuery( '#go_stage_error_msg' ).text() != error ) { jQuery( '#go_stage_error_msg' ).text( error ); } else { flash_error_msg( '#go_stage_error_msg' ); } return; } } var color = jQuery( '#go_admin_bar_progress_bar' ).css( "background-color" ); // redeclare (also called "overloading" ) the variable $task_count to the value of the 'count' var on the database. <?php $task_count = $wpdb->get_var("SELECT `count` FROM {$go_table_name} WHERE post_id = {$id} AND uid = {$user_ID}"); ?> // if the button#go_button exists, set var 'task_status' to the value of the 'status' attribute on the current button#go_button. if ( jQuery( '#go_button' ).length != 0 ) { var task_status = jQuery( '#go_button' ).attr( 'status' ); } else { var task_status = 5; } // if 'target' (if an argument is sent to task_stage_change, it is stored as a parameter in the 'target' variable) // is assigned the value of jQuery( '#go_back_button' ), AND the div#new_content exists... if ( jQuery( target ).is( '#go_back_button' ) && jQuery( '#new_content' ).length != 0 ) { jQuery( '#new_content p' ).hide( 'slow' ); jQuery( target ).remove(); } // if the button#go_back_button has the attribute of repeat... if ( jQuery( '#go_back_button' ).attr( 'repeat' ) != 'on' ) { // set repeat_attr equal to the value of the attribute of button#go_button. var repeat_attr = jQuery( '#go_button' ).attr( 'repeat' ); } else { // set repeat_attr equal to the value of the attribute of button#go_back_button. var repeat_attr = jQuery( '#go_back_button' ).attr( 'repeat' ); } if ( typeof( repeat_attr ) === 'undefined' ) { repeat_attr = ''; } // send the following data to the function 'task_change_stage' and use the POST method to do so... // when it succeeds update the content of the page: update the admin bar; set the css display attribute to none for // div#new_content; then slowly display div#new_content; if the button#go_button 'status' attribute is equal to 2 // and remove the first child element of div#new_content. jQuery.ajax({ type: "POST", data: { action: 'task_change_stage', post_id: <?php echo $id; ?> , user_id: <?php echo $user_ID; ?> , admin_name: '<?php echo $admin_name; ?> ', task_count: <?php echo !empty($task_count) ? $task_count : 0; ?> , status: task_status, repeat: repeat_attr, undo: undoing, pass: ( pass_entered ? jQuery( '#go_pass_lock' ).attr( 'value' ) : '' ), url: ( url_entered ? jQuery( '#go_url_key' ).attr( 'value' ) : '' ), page_id: <?php echo $page_id; ?> , points: <?php echo json_encode($points_array); ?> , currency: <?php echo json_encode($currency_array); ?> , bonus_currency: <?php echo json_encode($bonus_currency_array); ?> , date_update_percent: <?php echo $date_update_percent; ?> , chain_name: '<?php echo !empty($chain) ? $chain->name : ''; ?> ', next_post_id_in_chain: <?php echo !empty($next_post_id_in_chain) ? $next_post_id_in_chain : 0; ?> , last_in_chain: <?php echo !empty($last_in_chain) ? 'true' : 'false'; ?> , final_chain_message: '<?php echo !empty($final_chain_message) ? $final_chain_message : ''; ?> ', number_of_stages: <?php echo $number_of_stages; ?> }, success: function( html ) { if ( html === '0' ) { jQuery( '#go_stage_error_msg' ).show(); var error = "Retrieve the password from <?php echo $admin_name; ?> ."; if ( jQuery( '#go_stage_error_msg' ).text() != error ) { jQuery( '#go_stage_error_msg' ).text( error ); } else { flash_error_msg( '#go_stage_error_msg' ); } } else { jQuery( '#go_content' ).html( html ); jQuery( '#go_admin_bar_progress_bar' ).css({ "background-color": color }); jQuery( "#new_content" ).css( "display', 'none" ); jQuery( "#new_content" ).show( 'slow' ); if ( jQuery( '#go_button' ).attr( 'status' ) == 2 ) { jQuery( '#new_content' ).children().first().remove(); } jQuery( '#go_button' ).ready( function() { check_locks(); }); } } }); } </script> <?php // this is an edit link. edit_post_link('Edit ' . go_return_options('go_tasks_name'), '<br/><p>', '</p>', $id); } // Ends else statement } else { $custom_fields = get_post_custom($id); $encounter_message = !empty($custom_fields['go_mta_quick_desc'][0]) ? $custom_fields['go_mta_quick_desc'][0] : ''; $accept_message = !empty($custom_fields['go_mta_accept_message'][0]) ? $custom_fields['go_mta_accept_message'][0] : ''; $complete_message = !empty($custom_fields['go_mta_complete_message'][0]) ? $custom_fields['go_mta_complete_message'][0] : ''; $mastery_active = !empty($custom_fields['go_mta_task_mastery'][0]) ? !$custom_fields['go_mta_task_mastery'][0] : true; if ($mastery_active) { $mastery_privacy = !empty($custom_fields['go_mta_mastery_privacy'][0]) ? !$custom_fields['go_mta_mastery_privacy'][0] : true; if ($mastery_privacy) { $mastery_message = !empty($custom_fields['go_mta_mastery_message'][0]) ? $custom_fields['go_mta_mastery_message'][0] : ''; $repeat_active = !empty($custom_fields['go_mta_task_repeat'][0]) ? $custom_fields['go_mta_task_repeat'][0] : false; if ($repeat_active && $mastery_privacy) { $repeat_privacy = !empty($custom_fields['go_mta_repeat_privacy'][0]) ? !$custom_fields['go_mta_repeat_privacy'][0] : true; if ($repeat_privacy) { $repeat_message = !empty($custom_fields['go_mta_repeat_message'][0]) ? $custom_fields['go_mta_repeat_message'][0] : ''; } else { $repeat_message = "This stage has been hidden by the administrator."; } } } else { $mastery_message = "This stage has been hidden by the administrator."; } } echo "<div id='go_content'>"; if (!empty($encounter_message)) { echo "<div id='go_stage_encounter_message' class='go_stage_message'>" . do_shortcode(wpautop($encounter_message)) . "</div>"; } if (!empty($accept_message)) { echo "<div id='go_stage_accept_message' class='go_stage_message'>" . do_shortcode(wpautop($accept_message)) . "</div>"; } if (!empty($complete_message)) { echo "<div id='go_stage_complete_message' class='go_stage_message'>" . do_shortcode(wpautop($complete_message)) . "</div>"; } if (!empty($mastery_message)) { echo "<div id='go_stage_mastery_message' class='go_stage_message'>" . do_shortcode(wpautop($mastery_message)) . "</div>"; if (!empty($repeat_message)) { echo "<div id='go_stage_repeat_message' class='go_stage_message'>" . do_shortcode(wpautop($repeat_message)) . "</div>"; } } } }