diff --git a/game-on.php b/game-on.php index cd7000c6..4ae89faf 100644 --- a/game-on.php +++ b/game-on.php @@ -5,7 +5,7 @@ Description: Gamification tools for teachers. Authors: Semar Yousif, Vincent Astolfi, Ezio Ballarin, Forest Hoffman, Austin Vuong, Spencer Nussbaum, Isaac Canada, Charles Leon Author URI: http://maclab.guhsd.net/ -Version: 2.2.4 +Version: 2.2.5 */ include('go_datatable.php'); include('types/types.php'); diff --git a/go_pnc.php b/go_pnc.php index 469ef8db..9cb900a9 100644 --- a/go_pnc.php +++ b/go_pnc.php @@ -182,17 +182,11 @@ function go_update_admin_bar ($type, $title, $value, $status = null) { $display = go_display_points($value); $rng = ($current_rank_points -$value) * -1; $dom = ($next_rank_points - $current_rank_points); - if ($status == 0) { - echo ""; - } else { - echo ""; - } + echo ""; } else if ($type == 'currency') { $display = go_display_currency($value); } else if ($type == 'bonus_currency') { @@ -206,8 +200,10 @@ function go_update_admin_bar ($type, $title, $value, $status = null) { } $percentage = go_get_level_percentage(get_current_user_id()); echo ""; } diff --git a/go_stats.php b/go_stats.php index 9567ffcf..76313b85 100644 --- a/go_stats.php +++ b/go_stats.php @@ -171,15 +171,42 @@ function go_stats_move_stage () { $count = $_POST['count']; $message = $_POST['message']; $custom_fields = get_post_custom($task_id); + $date_picker = ((unserialize($custom_fields['go_mta_date_picker'][0]))?array_filter(unserialize($custom_fields['go_mta_date_picker'][0])):false); $rewards = unserialize($custom_fields['go_presets'][0]); $current_status = $wpdb->get_var($wpdb->prepare("SELECT status FROM {$go_table_name} WHERE uid=%d AND post_id=%d",$user_id, $task_id)); $page_id = $wpdb->get_var($wpdb->prepare("SELECT page_id FROM {$go_table_name} WHERE uid=%d AND post_id=%d", $user_id, $task_id)); $changed = array('type' => 'json', 'points' => 0, 'currency' => 0, 'bonus_currency' => 0); + if (!empty($date_picker)) { + $dates = $date_picker['date']; + $percentages = $date_picker['percent']; + $unix_today = strtotime(date('Y-m-d')); + + $past_dates = array(); + + foreach ($dates as $key => $date) { + if ($unix_today >= strtotime($date)) { + $past_dates[$key] = abs($unix_today - strtotime($date)); + } + } + + if (!empty($past_dates)) { + asort($past_dates); + $update_percent = (float)(($percentages[key($past_dates)])/100); + } else { + $update_percent = 1; + } + } else { + $update_percent = 1; + } + if ($status == 1){ $current_rewards = $wpdb->get_results($wpdb->prepare("SELECT points, currency, bonus_currency FROM {$go_table_name} WHERE uid=%d AND post_id=%d", $user_id, $task_id)); - go_task_abandon($user_id, $task_id, $current_rewards[0]->points, $current_rewards[0]->currency, $current_rewards[0]->bonus_currency); + go_task_abandon($user_id, $task_id, + $current_rewards[0]->points, + $current_rewards[0]->currency, + $current_rewards[0]->bonus_currency * $update_percent); $changed['points'] = -$current_rewards[0]->points; $changed['currency'] = -$current_rewards[0]->currency; @@ -198,38 +225,55 @@ function go_stats_move_stage () { } else { for ($count; $count > 0; $count--) { - go_add_post($user_id, $task_id, $current_status, -$rewards['points'][$current_status], -$rewards['currency'][$current_status], -$rewards['bonus_currency'][$current_status], null, $page_id, 'on', -1, null, null, null, null); + go_add_post($user_id, $task_id, $current_status, + floor(-$rewards['points'][$current_status] * $update_percent), + floor(-$rewards['currency'][$current_status] * $update_percent), + floor(-$rewards['bonus_currency'][$current_status] * $update_percent), + null, $page_id, 'on', -1, null, null, null, null); - $changed['points'] += -$rewards['points'][$current_status]; - $changed['currency'] += -$rewards['currency'][$current_status]; - $changed['bonus_currency'] += -$rewards['bonus_currency'][$current_status]; + $changed['points'] += floor(-$rewards['points'][$current_status] * $update_percent); + $changed['currency'] += floor(-$rewards['currency'][$current_status] * $update_percent); + $changed['bonus_currency'] += floor(-$rewards['bonus_currency'][$current_status] * $update_percent); } while ($current_status != $status) { if ($current_status > $status) { $current_status--; - go_add_post($user_id, $task_id, $current_status, -$rewards['points'][$current_status], -$rewards['currency'][$current_status], -$rewards['bonus_currency'][$current_status], null, $page_id, null, null, null, null, null, null); + go_add_post($user_id, $task_id, $current_status, + floor(-$rewards['points'][$current_status] * $update_percent), + floor(-$rewards['currency'][$current_status] * $update_percent), + floor(-$rewards['bonus_currency'][$current_status] * $update_percent), + null, $page_id, null, null, null, null, null, null); - $changed['points'] += -$rewards['points'][$current_status]; - $changed['currency'] += -$rewards['currency'][$current_status]; - $changed['bonus_currency'] += -$rewards['bonus_currency'][$current_status]; + $changed['points'] += floor(-$rewards['points'][$current_status] * $update_percent); + $changed['currency'] += floor(-$rewards['currency'][$current_status] * $update_percent); + $changed['bonus_currency'] += floor(-$rewards['bonus_currency'][$current_status] * $update_percent); } elseif ($current_status < $status) { $current_status++; $current_count = $wpdb->get_var($wpdb->prepare("SELECT count FROM {$go_table_name} WHERE uid=%d AND post_id=%d", $user_id, $task_id)); if ($current_status == 5 && $current_count == 0) { - go_add_post($user_id, $task_id, $current_status-1, $rewards['points'][$current_status-1], $rewards['currency'][$current_status-1], $rewards['bonus_currency'][$current_status-1], null, $page_id, 'on', 1, null, null, null, null); + go_add_post($user_id, $task_id, $current_status-1, + floor($rewards['points'][$current_status-1] * $update_percent), + floor($rewards['currency'][$current_status-1] * $update_percent), + floor($rewards['bonus_currency'][$current_status-1] * $update_percent), + null, $page_id, 'on', 1, null, null, null, null); + + $changed['points'] += floor($rewards['points'][$current_status-1] * $update_percent); + $changed['currency'] += floor($rewards['currency'][$current_status-1] * $update_percent); + $changed['bonus_currency'] += floor($rewards['bonus_currency'][$current_status-1] * $update_percent); - $changed['points'] += $rewards['points'][$current_status-1]; - $changed['currency'] += $rewards['currency'][$current_status-1]; - $changed['bonus_currency'] += $rewards['bonus_currency'][$current_status-1]; } elseif ($current_status < 5) { - go_add_post($user_id, $task_id, $current_status, $rewards['points'][$current_status-1], $rewards['currency'][$current_status-1], $rewards['bonus_currency'][$current_status-1], null, $page_id, null, null, null, null, null, null); + go_add_post($user_id, $task_id, $current_status, + floor($rewards['points'][$current_status-1] * $update_percent), + floor($rewards['currency'][$current_status-1] * $update_percent), + floor($rewards['bonus_currency'][$current_status-1] * $update_percent), + null, $page_id, null, null, null, null, null, null); - $changed['points'] += $rewards['points'][$current_status-1]; - $changed['currency'] += $rewards['currency'][$current_status-1]; - $changed['bonus_currency'] += $rewards['bonus_currency'][$current_status-1]; + $changed['points'] += floor($rewards['points'][$current_status-1] * $update_percent); + $changed['currency'] += floor($rewards['currency'][$current_status-1] * $update_percent); + $changed['bonus_currency'] += floor($rewards['bonus_currency'][$current_status-1] * $update_percent); } } } @@ -247,6 +291,7 @@ function go_stats_move_stage () { $changed['next_rank_points'] = $updated_rank[1][1]; } } + echo json_encode($changed); die(); } @@ -296,7 +341,7 @@ function go_stats_item_list () { ?>
  • ".get_the_title($item_id)." ({$count_before} of {$item_count_total}) {$purchase_date}"; + echo "".get_the_title($item_id)." ({$count_before} of {$item_count_total}) {$purchase_date}"; ?>
  • get_var('SELECT id FROM '.$wpdb->users.' WHERE display_name="'.$recipient.'"'); - $recipient_purchase_count = $wpdb->get_var("SELECT count FROM {$table_name_go} WHERE post_id={$post_id} AND uid={$recipient_id} LIMIT 1"); + $recipient_purchase_count = $wpdb->get_var("SELECT count FROM {$go_table_name} WHERE post_id={$post_id} AND uid={$recipient_id} LIMIT 1"); } $user_id = get_current_user_id(); @@ -57,6 +57,7 @@ function go_buy_item() { $exchange_currency = $store_exchange[1]; $exchange_points = $store_exchange[2]; $exchange_bonus_currency = $store_exchange[3]; + $exchange_minutes = $store_exchange[4]; } $item_url = $custom_fields['go_mta_store_item_url'][0]; $badge_id = $custom_fields['go_mta_badge_id'][0]; @@ -97,8 +98,8 @@ function go_buy_item() { if ($recipient_id) { go_message_user($recipient_id, get_userdata($user_id)->display_name." has purchased {$qty} ".get_the_title($post_id)." for you."); - if ($exchange_currency || $exchange_points || $exchange_bonus_currency) { - go_add_post($recipient_id, $post_id, -1, $exchange_points, $exchange_currency, $exchange_bonus_currency, null, null, $repeat); + if ($exchange_currency || $exchange_points || $exchange_bonus_currency || $exchange_minutes) { + go_add_post($recipient_id, $post_id, -1, $exchange_points, $exchange_currency, $exchange_bonus_currency, $exchange_minutes, null, $repeat); go_add_bonus_currency($recipient_id, $exchange_bonus_currency, get_userdata($user_id)->display_name." purchase of {$qty} ".get_the_title($post_id)."."); } else { go_add_post($recipient_id, $post_id, -1, 0, 0, 0, null, $repeat); diff --git a/types/tasks/task_shortcode.php b/types/tasks/task_shortcode.php index 82e911e2..7e125e0d 100644 --- a/types/tasks/task_shortcode.php +++ b/types/tasks/task_shortcode.php @@ -244,61 +244,39 @@ function go_task_shortcode($atts, $content = null) { $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(); + $date_picker = ((unserialize($custom_fields['go_mta_date_picker'][0]))?array_filter(unserialize($custom_fields['go_mta_date_picker'][0])):false); + + // If there are dates in the date picker + if (!empty($date_picker)) { - // 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); - } + $dates = $date_picker['date']; + $percentages = $date_picker['percent']; + $unix_today = strtotime($today); - $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; - } + // Setup empty array to house which dates are closest, in unix timestamp + $past_dates = array(); + + foreach ($dates as $key => $date) { + // If current date in loop is in the past, add its key to the array of date modifiers + if ($unix_today >= strtotime($date)) { + $past_dates[$key] = abs($unix_today - strtotime($date)); } + } + + if (!empty($past_dates)) { - 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; - } + // 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 = (float)(($percentages[key($past_dates)])/100); + } else { + $update_percent = 1; } - }else { - $update_percent = 0; + } else { + $update_percent = 1; } + global $current_points; if ($is_admin === false && !empty($req_points) && $current_points < $req_points) { $points = $req_points - $current_points; @@ -446,9 +424,9 @@ function go_task_shortcode($atts, $content = null) { $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])), + floor(($update_percent * $points_array[0])), + floor(($update_percent * $currency_array[0])), + floor(($update_percent * $bonus_currency_array[0])), null, $page_id, null, @@ -786,9 +764,9 @@ function go_task_abandon () { data: { action: "go_task_abandon", post_id: "", - encounter_points: , - encounter_currency: , - encounter_bonus: + encounter_points: , + encounter_currency: , + encounter_bonus: }, success: function () { window.location = ""; } @@ -1891,12 +1869,14 @@ function task_change_stage() { if ($undo == 'true' || $undo === true) { if ($task_count > 0) { go_add_post($user_id, $post_id, $status, - -floor($points_array[$status-1] + ($update_percent * $points_array[$status-1])), - -floor($currency_array[$status-1] + ($update_percent * $currency_array[$status-1])), -floor($bonus_currency[$status-1] + ($update_percent * $bonus_currency[$status-1])), null, $page_id, $repeat_button, -1, $e_fail_count, $a_fail_count, $c_fail_count, $m_fail_count, $e_passed, $a_passed, $c_passed, $m_passed); + -floor(($update_percent * $points_array[$status-1])), + -floor(($update_percent * $currency_array[$status-1])), + -floor(($update_percent * $bonus_currency[$status-1])), null, $page_id, $repeat_button, -1, $e_fail_count, $a_fail_count, $c_fail_count, $m_fail_count, $e_passed, $a_passed, $c_passed, $m_passed); } else { go_add_post($user_id, $post_id, ($status-1), - -floor($points_array[$status-1] + ($update_percent * $points_array[$status-1])), - -floor($currency_array[$status-1] + ($update_percent * $currency_array[$status-1])), -floor($bonus_currency[$status-1] + ($update_percent * $bonus_currency[$status-1])), null, $page_id, $repeat_button, 0, $e_fail_count, $a_fail_count, $c_fail_count, $m_fail_count, $e_passed, $a_passed, $c_passed, $m_passed); + -floor(($update_percent * $points_array[$status-1])), + -floor(($update_percent * $currency_array[$status-1])), + -floor(($update_percent * $bonus_currency[$status-1])), null, $page_id, $repeat_button, 0, $e_fail_count, $a_fail_count, $c_fail_count, $m_fail_count, $e_passed, $a_passed, $c_passed, $m_passed); if ($stage_badges[$status][0] == 'true') { foreach ($stage_badges[$status][1] as $badge_id) { go_remove_badge($user_id, $badge_id); @@ -1906,8 +1886,9 @@ function task_change_stage() { } else { // if repeat is on and undo is not hit... go_add_post($user_id, $post_id, $status, - floor($points_array[$status-1] + ($update_percent * $points_array[$status-1])), - floor($currency_array[$status-1] + ($update_percent * $currency_array[$status-1])), floor($bonus_currency[$status-1] + ($update_percent * $bonus_currency[$status-1])), null, $page_id, $repeat_button, 1, $e_fail_count, $a_fail_count, $c_fail_count, $m_fail_count, $e_passed, $a_passed, $c_passed, $m_passed, $url); + floor(($update_percent * $points_array[$status-1])), + floor(($update_percent * $currency_array[$status-1])), + floor(($update_percent * $bonus_currency[$status-1])), null, $page_id, $repeat_button, 1, $e_fail_count, $a_fail_count, $c_fail_count, $m_fail_count, $e_passed, $a_passed, $c_passed, $m_passed, $url); if ($stage_badges[$status][0] == 'true') { foreach ($stage_badges[$status][1] as $badge_id) { do_shortcode("[go_award_badge id='{$badge_id}' repeat='off' uid='{$user_id}']"); @@ -1921,12 +1902,13 @@ function task_change_stage() { if ($undo == 'true' || $undo === true) { if ($task_count > 0) { go_add_post($user_id, $post_id, $status, - -floor($points_array[$status-1] + ($update_percent * $points_array[$status-1])), - -floor($currency_array[$status-1] + ($update_percent * $currency_array[$status-1])), -floor($bonus_currency[$status-1] + ($update_percent * $bonus_currency[$status-1])), null, $page_id, $repeat_button, -1, $e_fail_count, $a_fail_count, $c_fail_count, $m_fail_count, $e_passed, $a_passed, $c_passed, $m_passed); + -floor(($update_percent * $points_array[$status-1])), + -floor(($update_percent * $currency_array[$status-1])), + -floor(($update_percent * $bonus_currency[$status-1])), null, $page_id, $repeat_button, -1, $e_fail_count, $a_fail_count, $c_fail_count, $m_fail_count, $e_passed, $a_passed, $c_passed, $m_passed); } else { go_add_post($user_id, $post_id, ($status-2), - -floor($points_array[$status-2] + ($update_percent * $points_array[$status-2])), - -floor($currency_array[$status-2] + ($update_percent * $currency_array[$status-2])), -floor($bonus_currency[$status-2] + ($update_percent * $bonus_currency[$status-2])), null, $page_id, $repeat_button, 0, $e_fail_count, $a_fail_count, $c_fail_count, $m_fail_count, $e_passed, $a_passed, $c_passed, $m_passed); + -floor(($update_percent * $points_array[$status-2])), + -floor(($update_percent * $currency_array[$status-2])), -floor(($update_percent * $bonus_currency[$status-2])), null, $page_id, $repeat_button, 0, $e_fail_count, $a_fail_count, $c_fail_count, $m_fail_count, $e_passed, $a_passed, $c_passed, $m_passed); if ($stage_badges[$status-2][0] == 'true') { foreach ($stage_badges[$status-2][1] as $badge_id) { go_remove_badge($user_id, $badge_id); @@ -1935,8 +1917,9 @@ function task_change_stage() { } } else { go_add_post($user_id, $post_id, $status, - floor($points_array[$status-1] + ($update_percent * $points_array[$status - 1])), - floor($currency_array[$status-1] + ($update_percent * $currency_array[$status-1])), floor($bonus_currency[$status-1] + ($update_percent * $bonus_currency[$status-1])), null, $page_id, $repeat_button, 0, $e_fail_count, $a_fail_count, $c_fail_count, $m_fail_count, $e_passed, $a_passed, $c_passed, $m_passed, $url); + floor(($update_percent * $points_array[$status - 1])), + floor(($update_percent * $currency_array[$status-1])), + floor(($update_percent * $bonus_currency[$status-1])), null, $page_id, $repeat_button, 0, $e_fail_count, $a_fail_count, $c_fail_count, $m_fail_count, $e_passed, $a_passed, $c_passed, $m_passed, $url); if ($stage_badges[$status-1][0] == 'true') { foreach ($stage_badges[$status-1][1] as $badge_id) { do_shortcode("[go_award_badge id='{$badge_id}' repeat='off' uid='{$user_id}']"); @@ -2231,4 +2214,4 @@ function go_display_rewards($points_array, $currency_array, $number_of_stages){ } echo ''; } -?> \ No newline at end of file +?> diff --git a/types/tasks/tsk-admin-footer.php b/types/tasks/tsk-admin-footer.php index 927179f4..f7a64b47 100644 --- a/types/tasks/tsk-admin-footer.php +++ b/types/tasks/tsk-admin-footer.php @@ -198,23 +198,26 @@ function go_toggle_settings_rows(stage_settings, condensed) { var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1; jQuery(document).ready(function(){ if(!is_chrome){ - if(jQuery('.datepicker').length){ - jQuery('.datepicker').datepicker({dateFormat: "yy-mm-dd"}); + if(jQuery('input.go_datepicker').length){ + jQuery('input.go_datepicker').each( function () { + jQuery(this).datepicker({dateFormat: "yy-mm-dd"}); + }); } } }); -var count = 1; + function go_add_decay_table_row(){ - jQuery('#go_list_of_decay_dates tbody').last().append(''); + jQuery('#go_list_of_decay_dates tbody').last().append(''); if(!is_chrome){ - if(jQuery('.datepicker').length){ - jQuery('.datepicker').datepicker({dateFormat: "yy-mm-dd"}); + if(jQuery('input.go_datepicker').length){ + jQuery('input.go_datepicker').each( function () { + jQuery(this).datepicker({dateFormat: "yy-mm-dd"}); + }); } } - count++; } function go_remove_decay_table_row(){ - jQuery('#go_list_of_decay_dates tbody tr').last('.datepicker').remove(); + jQuery('#go_list_of_decay_dates tbody tr').last('.go_datepicker').remove(); } //////////////////////////////////// diff --git a/types/types.php b/types/types.php index 49d841ba..ca7c48bc 100644 --- a/types/types.php +++ b/types/types.php @@ -699,16 +699,16 @@ function go_decay_table() { foreach($dates as $key => $date){ ?> - - + + - - + + - - - + + + + "; } @@ -3014,7 +3016,8 @@ function go_validate_store_exchange() { $c_exchange = $_POST['go_store_exchange_currency']; $p_exchange = $_POST['go_store_exchange_points']; $b_exchange = $_POST['go_store_exchange_bonus_currency']; - return (array($is_checked, $c_exchange, $p_exchange, $b_exchange)); + $t_exchange = $_POST['go_store_exchange_time']; + return (array($is_checked, $c_exchange, $p_exchange, $b_exchange, $t_exchange)); } add_action('cmb_render_go_badge_input', 'go_badge_input', 10, 1);