function allMyGameItems($user_id, $filter, $cat, $sort)
{
    global $config, $LANGUAGE;
    $data = array();
    $temp = array();
    $file = $config['basedir'] . '/temp/all_games.txt';
    if (file_exists($file)) {
        $temp = json_decode(file_get_contents($file), true);
    } else {
        $temp = getAllGames();
    }
    foreach ($temp as $t) {
        $all_games[$t['g_id']] = $t;
    }
    $all_bets = getAllBetsByUserId($user_id);
    $haswon = array();
    $temp = array();
    $bets_per_category = array();
    foreach ($all_bets as $ab) {
        if ($ab['ub_iswinner']) {
            $haswon[$ab['g_id']] = true;
        }
    }
    foreach ($all_bets as $ab) {
        $do_skip = false;
        $g_id = $ab['g_id'];
        $game = $all_games[$g_id];
        $suffix = getSuffix($game);
        // make sure category is equal to $cat
        $category = $game['g_categories'];
        $bets_per_category[$game['g_categories' . $suffix]] += 1;
        if ($category != $cat and $cat != 'all') {
            continue;
        }
        switch ($filter) {
            case 'all':
                break;
            case 'won':
                if (!$ab['ub_iswinner'] and !isset($haswon[$g_id])) {
                    $do_skip = true;
                }
                break;
            case 'lose':
                if (isset($haswon[$g_id])) {
                    $do_skip = true;
                } else {
                    if (!$game['g_isClosed']) {
                        $do_skip = true;
                    }
                }
                break;
            case 'judgement':
                $now = time();
                $do_skip = true;
                if ($game['g_schedTo'] < $now and !$game['g_isClosed'] and !$game['g_isCancelled']) {
                    $do_skip = false;
                }
                break;
            case 'cancelled':
                if (!$game['g_isCancelled']) {
                    $do_skip = true;
                }
                break;
            default:
                $do_skip = true;
                break;
        }
        if ($do_skip) {
            continue;
        }
        if (!isset($temp[$g_id])) {
            $temp[$g_id] = getBetItems($g_id);
            foreach ($temp[$g_id] as $t) {
                $bet_items[$t['bi_id']] = $t;
            }
            if ($game['g_isClosed'] and !$game['g_isCancelled']) {
                $key = 0;
            } else {
                $key = 'current';
            }
            $data[$g_id]['won'] = $key;
            $data[$g_id]['game_id'] = $g_id;
            $data[$g_id]['title'] = $game['g_title' . $suffix];
            $data[$g_id]['image'] = $game['g_image'];
            $data[$g_id]['from'] = $game['g_schedFrom'];
            $data[$g_id]['to'] = $game['g_schedTo'];
            $data[$g_id]['your_placed'] = 0;
            $data[$g_id]['housecom'] = $game['g_houseCom'];
            $data[$g_id]['total_placed'] = getGameTotalPlacedCoins($g_id);
        }
        if ($ab['ub_iswinner']) {
            $data[$g_id]['won'] = 1;
        }
        if (!isset($data[$g_id]['your_items'][$ab['bi_id']]['placed_coins'])) {
            $data[$g_id]['your_items'][$ab['bi_id']]['placed_coins'] = 0;
        }
        $data[$g_id]['your_placed'] += $ab['ub_coins'];
        $data[$g_id]['your_items'][$ab['bi_id']]['placed_coins'] += $ab['ub_coins'];
        $data[$g_id]['your_items'][$ab['bi_id']]['name'] = $bet_items[$ab['bi_id']]['bi_description' . $suffix];
        $data[$g_id]['your_items'][$ab['bi_id']]['winner'] = $ab['ub_iswinner'];
    }
    if ($bets_per_category) {
        arsort($bets_per_category);
    }
    $data = sortMyBets($data, $sort);
    return array('data' => $data, 'bets_per_category' => $bets_per_category);
}
예제 #2
0
<?php

session_start();
require_once "../../../include/config.php";
require_once $basedir . "/admin/include/functions.php";
include $basedir . '/admin/include/isadmin.php';
$cats = getCategories();
$gamemenu = 'active';
$game_id = isset($_GET['game_id']) ? $_GET['game_id'] : '';
if (!$game_id) {
    header('Location: ' . $baseurl . '/admin/games?lang=' . $LANGUAGE);
    exit;
} else {
    $game = getGame($game_id);
    //$game['g_categories'] = explode(",", $game['g_categories']);
    $bet_items = getBetItems($game_id);
    $reserve_time = getDateFormat($game['g_schedFrom']) . ' - ' . getDateFormat($game['g_schedTo']);
}
$total_placed_coins = getGameTotalPlacedCoins($game_id);
$location = $_SERVER['PHP_SELF'] . '?lang=' . $LANGUAGE . '&game_id=' . $game_id;
if (isset($_SESSION['error'])) {
    if ($_SESSION['error']['error'] == 0) {
        $alert_type = "alert-success";
    } else {
        $alert_type = "alert-warning";
    }
    $display = "block";
    $alert_message = $_SESSION['error']['status'];
    unset($_SESSION['error']);
} else {
    $display = "none";
예제 #3
0
function duplicateGame($game_id)
{
    global $config;
    $basedir = $config['basedir'];
    $g = getGame($game_id);
    $bet_items = getBetItems($g['g_id']);
    $title = $g['g_title'];
    $description = $g['g_description'];
    $imgfilename = $g['g_image'];
    $category = $g['g_categories'];
    $tags = $g['g_tags'];
    $bet_info = $g['g_betInfo'];
    $bet_condition = $g['g_addInfo'];
    $title_jp = $g['g_title_jp'];
    $description_jp = $g['g_description_jp'];
    $category_jp = $g['g_categories_jp'];
    $tags_jp = $g['g_tags_jp'];
    $bet_info_jp = $g['g_betInfo_jp'];
    $bet_condition_jp = $g['g_addInfo_jp'];
    $reserve_time1 = time();
    $reserve_time2 = time();
    $timezone = $g['g_timezone'];
    $coin_per_bet = $g['g_coinPerBet'];
    $house_comm = $g['g_houseCom'];
    $publish_type = 'draft';
    $is_recommend = $g['g_isRecommend'];
    $is_trial = $g['g_isTrial'];
    $jap_page = $g['g_japPage'];
    $eng_page = $g['g_engPage'];
    $bet_minimum = $g['g_betMinimum'];
    $q = "INSERT INTO games ";
    $q .= "(g_title, g_title_jp, g_description, g_description_jp, g_image, g_categories, g_categories_jp, g_tags, g_tags_jp, g_betInfo, g_betInfo_jp, g_addInfo, g_addInfo_jp, g_schedFrom, g_schedTo, g_timezone, g_coinPerBet, g_houseCom, g_publishType, g_isRecommend, g_isTrial, g_japPage, g_engPage, g_betMinimum, g_isCancelled, g_isClosed, g_isDeleted) ";
    $q .= "VALUES ";
    $q .= "('{$title}', '{$title_jp}', '{$description}', '{$description_jp}', '{$imgfilename}', '{$category}', '{$category_jp}', '{$tags}', '{$tags_jp}', '{$bet_info}', '{$bet_info_jp}', '{$bet_condition}', '{$bet_condition_jp}', '{$reserve_time1}', '{$reserve_time2}', '{$timezone}', '{$coin_per_bet}', '{$house_comm}', '{$publish_type}', '{$is_recommend}', '{$is_trial}', '{$jap_page}', '{$eng_page}', '{$bet_minimum}', '0', '0', '0')";
    mysql_query($q);
    $insert_id = mysql_insert_id();
    $cachefile = $basedir . '/temp/bet_items_active.php';
    $cachedata = false;
    if (file_exists($cachefile)) {
        $cachedata = json_decode(file_get_contents($cachefile), true);
    }
    foreach ($bet_items as $bi) {
        $description = $bi['bi_description'];
        $description_jp = $bi['bi_description_jp'];
        $bet_id = addBetItem($insert_id, $description_jp, $description);
        if ($bet_id and $cachedata) {
            $cachedata[] = array('bi_id' => $bet_id, 'bi_game_id' => $insert_id, 'bi_description' => $description, 'bi_winner' => 0);
        }
    }
    if ($cachedata) {
        file_put_contents($cachefile, json_encode($cachedata));
    }
    // erase the cache
    $filename = $basedir . '/temp/all_games.txt';
    unlink($filename);
    $games = getAllGames();
    file_put_contents($filename, json_encode($games));
    return true;
}