Beispiel #1
0
function buy_ticket($id_user, $number, $ticket_price)
{
    $pdo = PDO2::getInstance();
    //Change usr_id column in number row in the table tbl_numbers
    $query = $pdo->prepare("UPDATE tbl_numbers SET usr_id = :usr_id WHERE id = :number");
    $query->bindValue(":usr_id", $id_user);
    $query->bindValue(":number", $number);
    $query->execute();
    print_r($query->errorInfo());
    //Update the balance of the account
    $query = $pdo->prepare("UPDATE tbl_user SET user_balance = :new_balance WHERE user_id = :id_user");
    $query->bindValue(":new_balance", user_balance($id_user) - $ticket_price);
    $query->bindValue(":id_user", $id_user);
    $query->execute();
    print_r($query->errorInfo());
    update_jackpot();
}
Beispiel #2
0
        <?php 
//Display Errors
if (!empty($error_bingo)) {
    echo '<ul id = "ul_error">' . "\n";
    foreach ($error_bingo as $e) {
        echo '	<li>' . $e . '</li>' . "\n";
    }
    echo '</ul>';
}
?>
        <p>Sélectionnez votre numéro pour jouer au tirage de la semaine et peut-être gagner le gros lot.</p>
        <p>Solde de votre compte : <img src="<?php 
echo PATH_IMAGE_RESSOURCE . "donate.png";
?>
"><?php 
echo user_balance($_SESSION['id']);
?>
 nab$z</p>
        
        <p>Prix d'un ticket : <?php 
echo $price;
?>
 nab$z</p>
        <p>Jackpot : <?php 
echo $jackpot;
?>
 nab$z</p>
    </td>
    <td id="game_bingo">
        
            <table id='table_game_bingo'><tbody>
Beispiel #3
0
function add_product_incart($prdct_id, $usr_id)
{
    $pdo = PDO2::getInstance();
    //Find initial quantity
    $query = $pdo->prepare("SELECT product_quantity FROM tbl_cart WHERE user_id = :id_user AND product_id = :id_product");
    $query->bindValue(":id_user", $usr_id);
    $query->bindValue(":id_product", $prdct_id);
    $query->execute();
    $result = $query->fetch(PDO::FETCH_ASSOC);
    $prdct_qty = $result['product_quantity'];
    //Soustract a element in the store
    $query = $pdo->prepare("UPDATE tbl_products SET product_quantity = IF( (product_quantity -1)<0,0,(product_quantity - 1)) WHERE product_id = :id_product");
    $query->bindValue(":id_product", $prdct_id);
    $query->execute();
    //Add new quantity of product in the cart
    $query = $pdo->prepare("UPDATE tbl_cart SET product_quantity = :new_quantity WHERE user_id = :id_user AND product_id = :id_product");
    $infos_product_tobuy = infos_product($prdct_id);
    $query->bindValue(":id_user", $usr_id);
    $query->bindValue(":id_product", $prdct_id);
    $query->bindValue(":new_quantity", $infos_product_tobuy['product_portion'] + $prdct_qty);
    $query->execute();
    //Update the balance of the account
    $query = $pdo->prepare("UPDATE tbl_user SET user_balance = :new_balance WHERE user_id = :id_user");
    $query->bindValue(":new_balance", user_balance($usr_id) - $infos_product_tobuy['product_price']);
    $query->bindValue(":id_user", $usr_id);
    $query->execute();
}
Beispiel #4
0
                $form_buy[$index]->method('POST');
                $form_buy[$index]->add('Submit', 'submit')->value("Ajouter au panier");
                $form_buy[$index]->bound($_POST);
                //construct a array with the product_id
                array_push($tbx_index, $index);
            }
        }
        //end of for loop in cat
        $error_buy = array();
        $msg_confirm = array();
        foreach ($tbx_index as $value) {
            //which product user wants to buy
            if ($form_buy[$value]->is_valid($_POST)) {
                $infos_product_tobuy = infos_product($value);
                //Dont have enough money in the account
                if (user_balance($_SESSION['id']) < $infos_product_tobuy['product_price']) {
                    $error_buy[] = "Solde insuffisant pour acheter cet objet, vous pouvez recharger votre compte dans la partie Banque";
                } elseif (uniq_prdct_in_cart($value, $_SESSION['id']) != 0) {
                    add_product_incart($value, $_SESSION['id']);
                    $msg_confirm[] = "Achat effectué avec succès, vous disposiez déjà de ce produit dans votre inventaire, votre achat s'est ajouté à votre stock déjà existant";
                } else {
                    buy_product($value, $_SESSION['id']);
                    $msg_confirm[] = "Achat effectué avec succès, le produit a été ajouté a votre inventaire.";
                }
                //end of user_balance
            }
        }
        //end of foreach
        include PATH_VIEW . 'view_store.php';
    }
}
Beispiel #5
0
<?php

if (!user_admin()) {
    include PATH_GLOBAL_VIEW . 'error_not_admin.php';
} else {
    include PATH_LIB . 'form.php';
    require_once PATH_MODEL . 'admin.php';
    require_once PATH_MODEL . 'members.php';
    //include the two models to not rewrite functions that already exist
    require_once PATH_MODEL . 'nabz.php';
    $id_user = $_GET['uid'];
    $infos_user = read_infos_user($id_user);
    $user_balance = user_balance($id_user);
    $infos_nabz = read_infos_nabz($id_user);
    $form_edit_user = new Form('form_edit_user');
    $form_edit_user->method('POST');
    $form_edit_user->add('Text', 'login')->label('Login')->value($infos_user['user_pseudo']);
    $form_edit_user->add('Text', 'password')->label('Mot de passe')->value($infos_user['user_pass']);
    $form_edit_user->add('Text', 'email_addr')->label('Email')->value($infos_user['user_mail']);
    $form_edit_user->add('Text', 'balance')->label('Solde')->value($user_balance);
    if (empty($infos_user['hash_validation'])) {
        $valid_opt = 0;
    } else {
        $valid_opt = 1;
    }
    $form_edit_user->add('Checkbox', 'valid_account')->label('Compte validé')->value($valid_opt)->required('false');
    /*Nabz Infos Part*/
    //modify an existing nabz or add it to an account user
    if ($infos_nabz !== false) {
        //Load infos about the nabz associated to this user account
        $nabz_serial = $infos_nabz['rabbit_serial'];
Beispiel #6
0
<?php

if (!user_connected() || !verify_get_id($_GET['id'], $_SESSION['id'])) {
    include PATH_GLOBAL_VIEW . 'error_not_connected.php';
} else {
    include_once PATH_MODEL . 'members.php';
    include PATH_MODEL . 'bank.php';
    $id_user = $_SESSION['id'];
    $number = $_GET['number'];
    //read info about the bingo
    $bingo_info = fopen('global/bingo.txt', 'r+');
    //price of a ticket is on the first line
    $price = fgets($bingo_info);
    $price = (int) str_replace("price:", "", $price);
    //Only if the balance is enough
    if ($price < user_balance($id_user)) {
        buy_ticket($id_user, $number, $price);
    }
    header("Location: index.php?module=bank&action=bingo&id=" . $_SESSION['id']);
}
Beispiel #7
0
            $form_buy[$index] = new Form('form_buy' . $index);
            $form_buy[$index]->method('POST');
            $form_buy[$index]->add('Submit', 'submit')->value("Ajouter au panier");
            $form_buy[$index]->bound($_POST);
            //construct a array with the product_id
            array_push($tbx_index, $index);
        }
        include PATH_VIEW . 'view_table.php';
    }
    //end of for loop in cat
    $error_buy = array();
    foreach ($tbx_index as $value) {
        //which product user wants to buy
        if ($form_buy[$value]->is_valid($_POST)) {
            $infos_product_tobuy = infos_product($value);
            //Dont have enough money in the account
            if (user_balance($_GET['id']) < $infos_product_tobuy['product_price']) {
                $error_buy[] = "Solde insuffisant pour acheter cet objet, vous pouvez recharger votre compte dans la partie Banque";
            } elseif (uniq_prdct_in_cart($value, $_GET['id']) != 0) {
                buy_product($value, $_GET['id']);
            } else {
                add_product($value, $_GET['id'], uniq_prdct_in_cart($value, $_GET['id']));
            }
            //end of user_balance
            //echo print_r(infos_product($value));
            //buy_product($value,$_GET['id'],nbr_portion_prdct($value));
            include PATH_VIEW . 'view_store.php';
        }
    }
}
//end of user_connected
Beispiel #8
0
<?php

if (!user_connected()) {
    include PATH_GLOBAL_VIEW . 'error_not_connected.php';
} else {
    $balance = user_balance($_SESSION['id']);
    include PATH_VIEW . 'view_bank.php';
}
Beispiel #9
0
if (!user_connected()) {
    include PATH_GLOBAL_VIEW . 'error_not_connected.php';
} else {
    include PATH_MODEL . 'bank.php';
    $id_user = $_SESSION['id'];
    //read info about the bingo
    $bingo_info = fopen('global/bingo.txt', 'r+');
    //price of a ticket is on the first line
    $price = fgets($bingo_info);
    $price = (int) str_replace("price:", "", $price);
    //total jackpot is on the second
    $jackpot = fgets($bingo_info);
    $jackpot = (int) str_replace("jackpot:", "", $jackpot);
    fclose($bingo_info);
    //last 5 winners are in the last 5lines of the file
    $bingo_winners = fopen('global/bingo_winners.txt', 'r+');
    $array_winners = array();
    $i = 0;
    while ($i < 5) {
        array_push($array_winners, str_replace(CHR(13) . CHR(10), "", fgets($bingo_winners)));
        //without breaklines
        $i++;
    }
    fclose($bingo_winners);
    //Display error if the balance of the user is not enough to buy a ticket
    if (user_balance($id_user) < $price) {
        $error_bingo[] = "Vous ne disposez pas d'assez de nab\$z pour acheter un ticket.";
    }
    $tbx = list_all_numbers();
    include PATH_VIEW . 'view_bingo.php';
}