Пример #1
0
function redeemed($code, $user)
{
    if (!RedeemedCode::exists($code->id, $user->id)) {
        if ($code->item != "") {
            if ($code->item == "life") {
                $user->lives += $code->value;
            } else {
                if ($code->item == "bullet") {
                    $user->bullets += $code->value;
                } else {
                    if ($code->item == "coin") {
                        $user->coins += $code->value;
                    } else {
                        if ($code->item == "shield") {
                            $user->shields += $code->value;
                        } else {
                            if ($code->item == "slowmo") {
                                $user->slowmos += $code->value;
                            }
                        }
                    }
                }
            }
        }
        $user->update();
        $redeemed_code = new RedeemedCode();
        $redeemed_code->code_id = $code->id;
        $redeemed_code->user_id = $user->id;
        $redeemed_code->create();
        return false;
    } else {
        return true;
    }
}
<?php

require_once "../../includes/initialize.php";
global $session;
if (!$session->is_logged_in()) {
    redirect_to("../../index.php");
}
if ($_POST['oper'] == 'add') {
    $redeemed_code = new RedeemedCode();
    $redeemed_code->code_id = $_POST['code_id'];
    $redeemed_code->user_id = $_POST['user_id'];
    $redeemed_code->create();
} else {
    if ($_POST['oper'] == 'edit') {
        $redeemed_code = RedeemedCode::get_by_id($_POST['id']);
        $redeemed_code->code_id = $_POST['code_id'];
        $redeemed_code->user_id = $_POST['user_id'];
        $redeemed_code->update();
    } else {
        if ($_POST['oper'] == 'del') {
            RedeemedCode::get_by_id($_POST['id'])->delete();
        }
    }
}