Commit 012a71b1 authored by Petr Balga's avatar Petr Balga

Landing page showing payments by days; Bottom menu working properly; User...

Landing page showing payments by days; Bottom menu working properly; User welcome mesage done; Non-logged-in user warning + secured against unauthorized access; API doesn't throw warning anymore;
parent 8782b60b
<svg xmlns="http://www.w3.org/2000/svg" width="21" height="14" viewBox="0 0 21 14"><g><g><path fill="#fff" d="M18.44 2h-10a1 1 0 0 1-2 0h-4v2.18a3 3 0 0 1 0 5.64V12h4a1 1 0 0 1 2 0h10V9.82a3 3 0 0 1 0-5.64zm0 5a1 1 0 0 0 1 1 1 1 0 0 1 1 1v4a1 1 0 0 1-1 1h-18a1 1 0 0 1-1-1V9a1 1 0 0 1 1-1 1 1 0 0 0 0-2 1 1 0 0 1-1-1V1a1 1 0 0 1 1-1h18a1 1 0 0 1 1 1v4a1 1 0 0 1-1 1 1 1 0 0 0-1 1zm-10-1v2a1 1 0 0 1-2 0V6a1 1 0 0 1 2 0z"/></g></g></svg>
\ No newline at end of file
<svg xmlns="http://www.w3.org/2000/svg" width="25" height="25" viewBox="0 0 25 25"><g><g><path fill="#7d7d7d" d="M4.534 9.998l7.963-7.075 7.962 7.075zm15.463 12.5h-3.75v-3.75a3.75 3.75 0 0 0-7.5 0v3.75h-3.75v-10h15zm-6.25 0h-2.5v-3.75a1.25 1.25 0 0 1 2.5 0zm10.825-12.187l-11.25-10a1.25 1.25 0 0 0-1.65 0l-11.25 10a1.25 1.25 0 0 0 .825 2.187h1.25v11.25c0 .69.56 1.25 1.25 1.25h17.5c.69 0 1.25-.56 1.25-1.25v-11.25h1.25a1.25 1.25 0 0 0 .825-2.187z"/></g></g></svg>
\ No newline at end of file
<svg xmlns="http://www.w3.org/2000/svg" width="25" height="25" viewBox="0 0 25 25"><g><g><path fill="#231f20" d="M21.339 3.661A12.5 12.5 0 0 1 25 12.5a1.25 1.25 0 0 1-2.5 0A10 10 0 0 0 5.275 5.625h3a1.25 1.25 0 0 1 0 2.5H2.65c-.69 0-1.25-.56-1.25-1.25V1.25a1.25 1.25 0 0 1 2.5 0v2.212A12.5 12.5 0 0 1 12.5 0a12.5 12.5 0 0 1 8.839 3.661zM23.6 18.125v5.625a1.25 1.25 0 0 1-2.5 0v-2.212A12.5 12.5 0 0 1 0 12.5a1.25 1.25 0 0 1 2.5 0 10 10 0 0 0 17.225 6.887h-3a1.25 1.25 0 0 1 0-2.5h5.662a1.25 1.25 0 0 1 1.213 1.238z"/></g></g></svg>
\ No newline at end of file
......@@ -120,11 +120,16 @@
background-image: url(./../assets/svg/transport.svg);
background-color: #231f20; }
.main .middle .term .item .entertainment {
background-image: url(./../assets/svg/entertainment.png);
background-image: url(./../assets/svg/entertainment.svg);
background-color: #4333a6; }
.main .middle .term .item .health {
background-image: url(./../assets/svg/health.svg);
background-color: #33a63e; }
.main .middle .term .item .topup {
background-image: url(./../assets/svg/topup2.svg);
-webkit-filter: invert(100%);
filter: invert(100%);
background-color: #a56dff; }
.main .middle .term .item .category {
color: #231f20;
font-size: 18px;
......@@ -179,7 +184,7 @@ footer {
background-size: 25px auto;
background-position: 50% 50%; }
footer a .home {
background-image: url(./../assets/svg/home.svg); }
background-image: url(./../assets/svg/home2.svg); }
footer a .cards {
background-image: url(./../assets/svg/cards.svg); }
footer a .topup {
......@@ -190,6 +195,10 @@ footer {
background-image: url(./../assets/svg/settings.svg); }
footer .active {
color: #000000; }
footer .active .home {
background-image: url(./../assets/svg/home.svg); }
footer .active .topup {
background-image: url(./../assets/svg/topup2.svg); }
/* Styly pro top-up šablonu */
.top-up {
......@@ -354,4 +363,4 @@ body, html {
width: 375px;
height: 812px;
box-shadow: 0px 0px 50px 0px rgba(0, 0, 0, 0.3);
overflow-y: hidden; }
overflow: hidden; }
<footer>
<a href='<?php echo get_home_url() ?>' class='active'>
<?php $actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$landing = get_home_url() .'/';
$topup = get_home_url() . '/topup/';
?>
<a href='<?php echo get_home_url() ?>' <?php if($actual_link == $landing) {echo 'class="active"';} ?>>
<div class='icon home'></div>
<p>Home</p>
</a>
......@@ -7,7 +12,7 @@
<div class='icon cards'></div>
<p>Cards</p>
</a>
<a href='<?php echo get_home_url() . '/topup/'; ?>' >
<a href='<?php echo get_home_url() . '/topup/'; ?> ' <?php if($actual_link == $topup) {echo 'class="active"';} ?>>
<div class='icon topup'></div>
<p>Top Up</p>
</a>
......@@ -15,7 +20,7 @@
<div class='icon support'></div>
<p>Support</p>
</a>
<a href='#'>
<a href='<?php echo get_admin_url(); ?>'>
<div class='icon settings'></div>
<p>Settings</p>
</a>
......@@ -43,19 +48,16 @@
case 'health':
$randShop = $health[array_rand($health)];
break;
}
}
$user_id = get_current_user_id();
$min = 0.5;
$max = get_user_meta($user_id, 'balance', true);
$amount = mt_rand ($min*100, $max*100) / 100;
add_transaction($amount, 'account', 'pay', $randTop, $randShop);
header('Location: localhost/creepy/');
}
$category = get_category_by_slug($randTop)->term_id;
add_transaction($amount, 'account', 'pay', $category, $randShop);
echo '<script type="text/javascript">window.location.href = "'. get_home_url() .'";</script>';
}
?>
</div>
</body>
......
<?php get_header(); ?>
<!-- div container opened in header.php -->
<?php user_login_check(); ?>
<div class='main'>
<div class='top'>
<h2 id='greeting'> Welcome, Dafid </h2>
<?php
$first_name = get_user_meta( get_current_user_id(), 'first_name', true );
//print_r(get_user_meta(get_current_user_id()));
//echo $first_name;
$nicename = get_user_by('id', get_current_user_id())->user_nicename;
?>
<h2 id='greeting'> Welcome, <?php if(!empty($first_name)) {echo $first_name;} else {echo $nicename;} ?> </h2>
<div id='user__icon'></div>
<div class='clear'></div>
<p id='info__text'> Your Balance </p>
......@@ -13,61 +22,63 @@
<div class='middle'>
<h3 id='statement'>Statement</h3>
<p id='view__all'>View all</p>
<div class='clear'></div>
<div class='clear'>
<?php
<section class='term'>
<p class='day'>Today</p>
<div class='item'>
<div class='icon grocery'></div>
<div class='category'>Grocery</div>
<div class='price'>- $87.56</div>
<br>
<div class='name'>Eataly DownTown</div>
<div class='time'>5:03 PM</div>
</div>
<div class='item'>
<div class='icon transport'></div>
<div class='category'>Transport</div>
<div class='price'>- $7.23</div>
<br>
<div class='name'>Uber</div>
<div class='time'>3:30 PM</div>
</div>
<div class='item'>
<div class='icon entertainment'></div>
<div class='category'>Entertainment</div>
<div class='price'>- $200.00</div>
<br>
<div class='name'>Broadway</div>
<div class='time'>2:24 PM</div>
</div>
</section>
<section class='term'>
<p class='day'>Yesterday</p>
<div class='item'>
<div class='icon transport'></div>
<div class='category'>Transport</div>
<div class='price'>- $10.85</div>
<br>
<div class='name'>Lift</div>
<div class='time'>2:24 PM</div>
</div>
</section>
$user_id = get_current_user_id();
$args = array(
'author' => $user_id,
'numberposts' => 0,
'orderby' => 'date',
'order' => 'DESC',
'post_type' => 'transaction',
'suppress_filters' => true,
);
<section class='term'>
<p class='day'>Apr 23</p>
<div class='item'>
<div class='icon health'></div>
<div class='category'>Health</div>
<div class='price'>- $10.17</div>
<br>
<div class='name'>Walgreens 5th Ave</div>
<div class='time'>9:12 PM</div>
</div>
</section>
<div id='end'><p>This is the end.</p></div>
$posts = get_posts($args);
$metadate = 0;
$dateToday = date('M d',strtotime("+1 hours"));
foreach ($posts as $post){
$post_id = $post->ID;
$post_title = $post->post_title;
$post_date_str = strtotime($post->post_date);
$post_date = date('M d', $post_date_str);
$post_time = date('h:i A', $post_date_str);
$cat = get_the_category($post_id);
$category_slug = $cat[0]->slug;
$category_name = $cat[0]->name;
$amount = get_post_meta($post_id, 'amount', true);
if($metadate !== $post_date) {
$metadate = $post_date;
echo '</div>';
echo "<div class='term'>";
if($dateToday == $post_date) {
echo "<p class='day'>Today</p>";
}else if($post_date == date('M d',strtotime("-23 hours"))){
echo "<p class='day'>Yesterday</p>";
}else {
echo "<p class='day'>" . $post_date . "</p>";
}
}
?>
<div class='item'>
<div class='icon <?php echo $category_slug; ?>'></div>
<div class='category'><?php echo $category_name; ?></div>
<div class='price'><?php if($category_slug == 'topup') { echo '+ $' . $amount;} else {echo '- $' . $amount;} ?></div>
<br>
<div class='name'><?php echo $post_title; ?></div>
<div class='time'><?php echo $post_time; ?></div>
</div>
<?php
}
$posts_count = count($posts);
?>
<?php if($posts_count == 0) {echo "<div id='end' style='margin-top: 200px;'><p>There's nothing here, yet. 😪</p></div>";} else {echo "<div id='end'><p>That's all. 👌</p></div>";} ?>
</div>
</div>
<!-- div container closed in footer.php -->
<?php get_footer(); ?>
\ No newline at end of file
<?php
/* Loading CSS */
/* Load CSS */
function load_css() {
wp_register_style('customstyle', get_template_directory_uri() . '/css/style.css', array(), false, 'all');
wp_enqueue_style('customstyle');
......@@ -8,8 +8,7 @@ function load_css() {
add_action('wp_enqueue_scripts', 'load_css');
/* Loading JS */
/* Load JS */
function load_js() {
wp_register_script('mainjs', get_template_directory_uri() . '/js/money.js', array(), 1, true);
wp_enqueue_script('mainjs');
......@@ -28,15 +27,6 @@ function add_file_types_to_uploads($file_types){
}
add_filter('upload_mimes', 'add_file_types_to_uploads');
// Retrieves the attachment ID from the file URL
// if not in use delete
function custom_get_image_id($image_url) {
global $wpdb;
$attachment = $wpdb->get_col($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE guid='%s';", $image_url ));
return $attachment[0];
}
// Register Custom Post Type
function transactions_post_type() {
$labels = array(
......@@ -72,7 +62,7 @@ function transactions_post_type() {
'label' => 'Transaction',
'description' => 'Transaction as a post - post type',
'labels' => $labels,
'supports' => array( 'title', 'editor' ),
'supports' => array( 'title', 'editor', 'author' ),
'taxonomies' => array( 'category', 'post_tag' ),
'hierarchical' => false,
'public' => true,
......@@ -94,33 +84,49 @@ function transactions_post_type() {
add_action( 'init', 'transactions_post_type', 0 );
function add_transaction($amount, $payment, $action, $category, $title){
if(is_user_logged_in()){
if($amount > 0){
$amount = preg_replace("/[^0-9.]/", "", $amount);
$user_id = get_current_user_id();
print_r($category);
$post = array(
'post_author' => $user_id,
'post_content' => 'Transaction of $' . $amount . ' was made via ' . $payment . '.',
'post_title' => $title,
'post_status' => 'publish',
'post_type' => 'transaction',
'post_category' => array($category),
'meta_input' => array('amount' => $amount)
);
$amount = preg_replace("/[^0-9.]/", "", $amount);
$user_id = get_current_user_id();
$post = array(
'post_author' => $user_id,
'post_content' => 'Transaction of $' . $amount . ' was made.',
'post_title' => $title,
'post_status' => 'publish',
'post_type' => 'transaction',
'post_category' => array($category),
'meta_input' => array('amount' => $amount)
);
if(empty(get_user_meta($user_id, 'balance') )){
add_user_meta($user_id, 'balance', 0, true);
}
if(empty(get_user_meta($user_id, 'balance') )){
add_user_meta($user_id, 'balance', 0, true);
}
$money = get_user_meta($user_id, 'balance', true);
if($action == 'topup'){
$money += $amount;
} else {
$money -= $amount;
}
update_user_meta($user_id, 'balance', $money);
wp_insert_post($post);
$money = get_user_meta($user_id, 'balance', true);
if($action == 'topup'){
$money += $amount;
} else {
$money -= $amount;
}
update_user_meta($user_id, 'balance', $money);
wp_insert_post($post);
}
}
}
function user_login_check() {
if(!is_user_logged_in()){
?>
<div class='not_looged_in' style='width: 375px; height: 812px; background-color: rgba(0,0,0,0.9); position: absolute; z-index: 9999'>
<div class='info' style='text-align: center; color: white; margin-top: 80%;'>
<h1>Hold on!</h1>
<h2>You're not logged in!</h2>
<a href='<?php echo get_admin_url(); ?>' style='color: lightblue;'>Go to login page</a>
</div>
</div>
<?php
}
}
?>
\ No newline at end of file
$(document).ready(function(){
var parsed;
var parsed;
$.ajax({
url: "https://api.exchangeratesapi.io/latest?base=USD",
type: 'get',
dataType: 'html',
async: false,
success: function(data) {
parsed = JSON.parse(data);
}
......
......@@ -9,7 +9,8 @@
?>
<?php get_header(); ?>
<!-- div container opened in header.php -->
<!-- div container opened in header.php -->
<?php user_login_check(); ?>
<div class='top-up'>
<h2>Top Up</h2>
<h3>Amount to top up in USD</h3>
......@@ -32,12 +33,12 @@
<div class='clear'></div>
<h3>Payment method</h3>
<select class='payment__method' name='payment'>
<option value='fasttransfer'>Fast transfer – Send money with a TED Ba...</option>
<option value='fasttransfer'>Fast Transfer</option>
<option value='paypal'>PayPal</option>
<option value='eur'>Venmo</option>
<option value='usd'>Airbank</option>
</select>
<input type='submit' class='submit' value='Top Up $1,000' name='submit'>
<input type='submit' class='submit' value='Top Up $0' name='submit'>
</form>
</div>
......@@ -46,42 +47,9 @@
$payment = $_POST['payment'];
$amount = preg_replace("/[^0-9.]/", "", $_POST['usd']);
if($amount > 0) {
add_transaction($amount, $payment, 'topup', 'topup', 'Top-Up');
add_transaction($amount, $payment, 'topup', 6, 'Top-Up');
}
}
/*
if (isset($_POST['submit']) ) {
$user_id = get_current_user_id();
$payment = $_POST['payment'];
$amount = preg_replace("/[^0-9.]/", "", $_POST['usd']);
$message = $user_id . 'topped up by $' . $amount . ' using ' . $payment;
$post = array(
'post_author' => $user_id,
'post_content' => 'User ' . $user_id . ' Topped Up their account by $' . $amount . " using " . $payment,
'post_title' => 'Top-Up',
'post_status' => 'publish',
'post_type' => 'transaction',
'post_category' => array('topup'),
'meta_input' => array('amount' => $amount)
);
if(empty(get_user_meta($user_id, 'balance') )){
add_user_meta($user_id, 'balance', 0, true);
}
$money = get_user_meta($user_id, 'balance', true);
$money += $amount;
update_user_meta($user_id, 'balance', $money);
wp_insert_post($post);
}
*/
?>
<!-- div container closed in footer.php -->
......
......@@ -31,7 +31,7 @@ footer {
background-position: 50% 50%;
}
.home {
background-image: url(./../assets/svg/home.svg);
background-image: url(./../assets/svg/home2.svg);
}
.cards {
background-image: url(./../assets/svg/cards.svg);
......@@ -48,5 +48,11 @@ footer {
}
.active {
color: $black;
.home {
background-image: url(./../assets/svg/home.svg);
}
.topup {
background-image: url(./../assets/svg/topup2.svg);
}
}
}
\ No newline at end of file
......@@ -138,15 +138,19 @@
background-color: $darkgray;
}
.entertainment {
background-image: url(./../assets/svg/entertainment.png);
background-image: url(./../assets/svg/entertainment.svg);
background-color: #4333a6;
}
.health {
background-image: url(./../assets/svg/health.svg);
background-color: #33a63e;
}
.topup {
background-image: url(./../assets/svg/topup2.svg);
filter: invert(100%);
background-color: #a56dff;
}
.category {
color: $darkgray;
font-size: 18px;
font-weight: 500;
......
......@@ -24,5 +24,5 @@ body, html {
width: 375px;
height: 812px;
box-shadow: 0px 0px 50px 0px rgba(0,0,0,0.3);
overflow-y: hidden;
overflow: hidden;
}
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment