Esempio n. 1
0
display_avatar_name();
display_skill($_SESSION['id_nabz']);
?>
		</td>
		<td id="td_secondcol"><!-- Second line --!>
		<?php 
if ($item_cat != NULL) {
    echo 'Pour abreuver votre lapin vous disposez de :';
} else {
    echo 'Vous ne disposez d\'aucun produit pour abreuver votre lapin :( ';
}
?>
		<?php 
//display each product as in the rabbit store
foreach ($item_cat as $value) {
    $infos_product = infos_product($value);
    echo '<table id=\'table_product_profile\'><tbody><tr>';
    echo '<td>';
    echo '<img src=' . PATH_IMAGE_STORE . $infos_product['product_image'] . '>' . '<br \\>';
    echo $infos_product['product_name'] . '<br \\>';
    echo $infos_product['product_description'] . '<br \\>';
    echo '</td>';
    echo '<td>';
    //health
    echo "<img id=\"img_skill\" src=\"" . PATH_IMAGE_RESSOURCE . "health.png\">";
    echo '&nbsp;&nbsp;' . '+' . $infos_product['prdct_health_pt'] . '<br \\>';
    //angry
    echo "<img id=\"img_skill\" src=\"" . PATH_IMAGE_RESSOURCE . "food.png\">";
    echo '&nbsp;&nbsp;' . '+' . $infos_product['prdct_angry_pt'] . '<br \\>';
    //thearth
    echo "<img id=\"img_skill\" src=\"" . PATH_IMAGE_RESSOURCE . "drink.png\">";
Esempio n. 2
0
         $index = $infos_product['product_id'][$i];
         $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);
     }
 }
 //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';
Esempio n. 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();
}
Esempio n. 4
0
function use_product($id_product, $id_nabz)
{
    $pdo = PDO2::getInstance();
    $query = $pdo->prepare("UPDATE tbl_rabbit_skill SET skill_angry = IF( (skill_angry + :skill_angry)>100,100,(skill_angry + :skill_angry)) ,skill_thirst = IF( (skill_thirst + :skill_thirst)>100,100,(skill_thirst + :skill_thirst)),skill_health = IF( (skill_health + :skill_health)>100,100,(skill_health + :skill_health)) WHERE rabbit_id = :id_nabz");
    $infos_product = infos_product($id_product);
    $pt_angry = $infos_product['prdct_angry_pt'];
    $pt_thirst = $infos_product['prdct_thirst_pt'];
    $pt_health = $infos_product['prdct_health_pt'];
    $query->bindValue(':skill_angry', $pt_angry);
    $query->bindValue(':skill_thirst', $pt_thirst);
    $query->bindValue(':skill_health', $pt_health);
    $query->bindValue(':id_nabz', $id_nabz);
    $query->execute();
    return $query->rowCount() == 1;
}