<?php ob_start(); ?> <div class="box"> <?php $buttonsSnackIds = get_buttons_preferences_by_user($client['uid']); ?> <?php for ($i = get_nb_buttons() - 1; $i >= 0; $i--) { $snack = get_snack_by_id($buttonsSnackIds[$i]); ?> <a href=<?php echo "shortButton?uid=" . $client['uid'] . "&snackId=" . $snack['id']; ?> ><button class="ink-button push-right"><i class="icon-beer"></i><?php echo $snack['description_' . getenv('LANG')] . ' ' . money_format('%!n€', $snack['price']); ?> </button></a> <?php } ?> <!--<a href="soda?uid=<?php echo $client['uid']; ?> "><button class="ink-button push-right"><i class="icon-beer"></i> <?php $soda = get_snack_by_id(10); echo _("Coca-Cola Zero") . ' ' . money_format('%!n€', $soda['price']); ?> </button></a> <a href="coffee?uid=<?php
function get_buttons_preferences_by_user($uid) { $link = open_database_connection(); $snackIds = array(); for ($buttonId = 0; $buttonId < get_nb_buttons(); $buttonId++) { $query = "SELECT * FROM usersPreferences WHERE uid = '" . mysqli_real_escape_string($link, $uid) . "' AND buttonId = '{$buttonId}' LIMIT 1"; if ($result = mysqli_query($link, $query)) { $snackId = mysqli_fetch_assoc($result); } if (!$snackId) { $snackId = get_default_snackid_per_buttonid($buttonId); } else { $snackId = $snackId['snackId']; } $snackIds[] = $snackId; // free result set mysqli_free_result($result); } // close connection mysqli_close($link); return $snackIds; }
function usersPreferences_action($post) { //needed to hide the menu $dashboard_active = true; $uid = $post['uid']; for ($buttonId = 0; $buttonId < get_nb_buttons(); $buttonId++) { $id = "snackId{$buttonId}"; if (isset($post[$id])) { $snackId = $post[$id]; update_userPreferences($uid, $buttonId, $snackId); } } // Redirect browser header("Location: http://" . $_SERVER['SERVER_NAME'] . "/dashboard?uid=" . $uid); exit; }