rendered paste body<?php/*************************************************************************** * scratch_card.php * ------------------------ * Version : 1.0.0 * forums : http://forums.zarath.com * website : http://www.zarath.com * ***************************************************************************//*************************************************************************** * * copyright (C) 2006 Zarath Technologies * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * http://www.gnu.org/copyleft/gpl.html * ***************************************************************************/define('IN_PHPBB', true); $phpbb_root_path = './'; $i = 0;while ( !file_exists($phpbb_root_path . 'extension.inc') && ($i++ < 4) ){ $phpbb_root_path .= '../';}if ( $i > 4 ){ message_die(CRITICAL_ERROR, 'Unable to find extension.inc, terminating. Please move this file into your main/"root" phpbb directory and try again.'); }include($phpbb_root_path . 'extension.inc');include($phpbb_root_path . 'common.' . $phpEx);$gen_simple_header = TRUE;//// Start session management//$userdata = session_pagestart($user_ip, PAGE_INDEX);init_userprefs($userdata);//// End session management////// Start page Variables//if (!(@include($phpbb_root_path . 'language/lang_' . $userdata['user_lang'] . '/lang_shop.' . $phpEx))) { include($phpbb_root_path . 'language/lang_' . $board_config['default_lang'] . '/lang_shop.' . $phpEx); }if ( isset($HTTP_GET_VARS['action']) || isset($HTTP_POST_VARS['action']) ) { $action = ( isset($HTTP_POST_VARS['action']) ) ? $HTTP_POST_VARS['action'] : $HTTP_GET_VARS['action']; }else { $action = ''; }#* *##* Scratch Card Variables! *##* *#// Percentages of winning or losing //// Default: 40, 25, 15, 10, 7, 3 -- 40% chance of loss, 25% chance of recieving cost back, 35% chance of making money //// Note: These should add up to 100... //$lose_chance = 40;$item_1_chance = 25;$item_2_chance = 16;$item_3_chance = 10;$item_4_chance = 7;$item_5_chance = 2;// Amount of points/gold etc to win on each item //$item_1_win = 10;$item_2_win = 15;$item_3_win = 20;$item_4_win = 30;$item_5_win = 50;// Item Name //$item_name = 'Scratch Card';//// Decay Time?// Set this variable to 0 for none... something else if you want it to decay after it's been "initialized"// Default of a week.//$decay_time = 604800;#* *##* End Scratch Card Variables! *##* *#//// See if user has a scratch card...//$sql = "SELECT * FROM " . USER_ITEMS_TABLE . " WHERE user_id = '{$userdata['user_id']}' AND item_name = '" . str_replace("'", "''", $item_name) . "'";if ( !($result = $db->sql_query($sql)) ){ message_die(GENERAL_ERROR, "Error getting scratch card info!", '', __LINE__, __FILE__, $sql);}if ( !($db->sql_numrows($result)) ){ message_die(GENERAL_MESSAGE, $lang['scratch_no_card']);}else{ $row = $db->sql_fetchrow($result);}// Generate Scratch Card if it hasn't been done yet... //if ( empty($row['scratch_card']) ){ $check = $lose_chance; $rand = rand(1, 100); $i = 0; $ii = 1; while ( $ii ) { if ( $rand <= $check ) { $win = $i; $ii = 0; } else { $i++; $check += ${'item_' . $i . '_chance'}; } } // Generate icon listing -- this will be difficult... $fields = ''; $fields_added = array(); for ( $i = 0; $i < 9; $i++ ) { $rand = rand(1, 5); // Check if field has been added twice and not a winning ticket OR // Check if field has been added 3 times and stop it if ( ( $fields_added[$rand] == 2 && $win != $rand ) || ( $fields_added[$rand] == 3 ) ) { $i--; } else { $fields .= ( ( !empty($fields) ) ? '|' : '' ) . $rand . ':0'; $fields_added[$rand]++; } } // // Final check, if initial creation did not create 3 of the winning icon, highly likely... // reloop over array and randomly change icons to winning icon until 3 of a kind exists // if ( ($win) && ( $fields_added[$win] != 3 ) ) { $win_array = explode('|', $fields); while ( $fields_added[$win] != 3 ) { $rand = (rand(1, 9) - 1); if ( $win_array[$rand]{0} != $win ) { $win_array[$rand] = $win . ':0'; $fields_added[$win]++; } } $fields = implode('|', $win_array); } // // Generation complete... add it to the scratch card info! // $decay_time = ( !($decay_time) ) ? 0 : (time() + $decay_time); $sql = "UPDATE " . USER_ITEMS_TABLE . " SET scratch_card = '$fields', die_time = '$decay_time' WHERE user_id = '{$userdata['user_id']}' AND id = '{$row['id']}'"; if ( !($db->sql_query($sql)) ) { message_die(GENERAL_ERROR, "Error getting synth items!", '', __LINE__, __FILE__, $sql); } $row['scratch_card'] = $fields;}## Set User's items into a variable!## Start of main displayif ( empty($action) ){ $template->set_filenames(array( 'body' => 'shop/item_scratch_card.tpl') ); $fields = explode('|', $row['scratch_card']); $fields_scratched = array(); $revealed = 0; $won = 0; // Positions for scratch panel // $x = array(165, 207, 249, 165, 207, 249, 165, 207, 249); $y = array(27, 27, 27, 69, 69, 69, 111, 111, 111); if ( substr_count($_SERVER['HTTP_USER_AGENT'], 'MSIE') ) { for ( $i = 0; $i < count($x); $i++ ) { $x[$i] += 3; $y[$i] += 6; } } for ( $i = 0; $i < count($fields); $i++ ) { if ( $fields[$i]{2} ) { $fields_scratched[$fields[$i]{0}]++; if ( $fields_scratched[$fields[$i]{0}] == 3 ) { $won = $fields[$i]{0}; } $template->assign_block_vars('list_layers', array( 'U_ACTION' => append_sid("scratch_card.$phpEx?action=scratch&field_id=" . $i), 'ICON_ID' => $fields[$i]{0}, 'SQUARE_ID' => $i, 'POS_X' => $x[$i], 'POS_Y' => $y[$i] )); $revealed++; } else { $template->assign_block_vars('list_empty', array( 'U_ACTION' => append_sid("scratch_card.$phpEx?action=scratch&field_id=" . $i), 'POS_X' => $x[$i], 'POS_Y' => $y[$i] )); } } if ( $won || $revealed > 8 ) { $message = ( $won ) ? $lang['scratch_you_won'] . '<br />' . sprintf($lang['scratch_claim'], ${'item_' . $won . '_win'}, $board_config['points_name']) : $lang['scratch_no_win'] . '<br />' . $lang['scratch_discard']; $template->assign_block_vars('switch_trade_in', array( 'U_ACTION' => append_sid("scratch_card.$phpEx?action=exchange"), 'X_POS' => ( ( substr_count($_SERVER['HTTP_USER_AGENT'], 'MSIE') ) ? 165 : 162 ), 'Y_POS' => ( ( substr_count($_SERVER['HTTP_USER_AGENT'], 'MSIE') ) ? 167 : 162 ), 'MESSAGE' => $message )); } for ( $i = 1; $i < 6; $i++ ) { $template->assign_block_vars('list_icons', array( 'Y_POS' => (( ( substr_count($_SERVER['HTTP_USER_AGENT'], 'MSIE') ) ? 106 : 103 ) + (($i - 1) * 18)), 'ICON_ID' => $i, 'PAYOUT' => ${'item_' . $i . '_win'} )); } $page_title = $item_name; $template->assign_vars(array( 'L_POINTS_NAME' => $board_config['points_name'], 'U_ACTION' => append_sid("scratch_card.$phpEx") )); $template->assign_block_vars('', array());}elseif ( $action == 'scratch' ){ if ( isset($HTTP_GET_VARS['field_id']) || isset($HTTP_POST_VARS['field_id']) ) { $field_id = ( isset($HTTP_POST_VARS['field_id']) ) ? intval($HTTP_POST_VARS['field_id']) : intval($HTTP_GET_VARS['field_id']); } else { $field_id = ''; } $fields = explode('|', $row['scratch_card']); for ( $i = 0; $i < count($fields); $i++ ) { if ( $i == $field_id ) { if ( !($fields[$i]{2}) ) { $fields[$i] = $fields[$i]{0} . ':1'; $i = 10; } elseif ( $fields[$i]{2} ) { redirect("shop/scratch_card.$phpEx"); exit; } } } $new_fields = implode('|', $fields); $sql = "UPDATE " . USER_ITEMS_TABLE . " SET scratch_card = '$new_fields' WHERE user_id = '{$userdata['user_id']}' AND id = '{$row['id']}'"; if ( !($db->sql_query($sql)) ) { message_die(GENERAL_ERROR, "Error getting synth items!", '', __LINE__, __FILE__, $sql); } redirect("shop/scratch_card.$phpEx");}elseif ( $action == 'exchange' ){ $fields = explode('|', $row['scratch_card']); $fields_scratched = array(); $not_revealed = 0; $won = 0; for ( $i = 0; $i < count($fields); $i++ ) { if ( !($fields[$i]{2}) ) { $not_revealed++; } elseif ( $fields[$i]{2} ) { $fields_scratched[$fields[$i]{0}]++; if ( $fields_scratched[$fields[$i]{0}] == 3 ) { $won = $fields[$i]{0}; } } } if ( $won ) { // Delete scratch card first // $sql = "DELETE FROM " . USER_ITEMS_TABLE . " WHERE user_id = '{$userdata['user_id']}' AND id = '{$row['id']}' LIMIT 1"; if ( !($db->sql_query($sql)) ) { message_die(GENERAL_ERROR, "Error removing scratch card!", '', __LINE__, __FILE__, $sql); } // Add the amount the user has won // $sql = "UPDATE " . USERS_TABLE . " SET user_points = (user_points + ${'item_' . $won . '_win'}) WHERE user_id = '{$userdata['user_id']}'"; if ( !($db->sql_query($sql)) ) { message_die(GENERAL_ERROR, "Error adding points!", '', __LINE__, __FILE__, $sql); } message_die(GENERAL_MESSAGE, $lang['scratch_you_won'] . '<br />' . sprintf($lang['scratch_awarded_points'], $item_name, ${'item_' . $won . '_win'}, $board_config['points_name']) . '<br /><br />' . sprintf($lang['scratch_close_window'], '<a href="javascript: window.close();" class="gen">', '</a>')); } elseif ( $not_revealed ) { redirect("shop/scratch_card.$phpEx"); } else { // Delete scratch card first // $sql = "DELETE FROM " . USER_ITEMS_TABLE . " WHERE user_id = '{$userdata['user_id']}' AND id = '{$row['id']}' LIMIT 1"; if ( !($db->sql_query($sql)) ) { message_die(GENERAL_ERROR, "Error removing scratch card!", '', __LINE__, __FILE__, $sql); } message_die(GENERAL_MESSAGE, $lang['scratch_no_win'] . '<br /><br />' . sprintf($lang['scratch_close_window'], '<a href="javascript: window.close();" class="gen">', '</a>')); }}else { message_die(GENERAL_MESSAGE, $lang['scratch_no_action']);}//// Start output of page//include($phpbb_root_path . 'includes/page_header.' . $phpEx);//// Generate the page//$template->pparse('body');include($phpbb_root_path . 'includes/page_tail.' . $phpEx);?>