Add initial files and database migration for ticket pricing system
- Created new directories and index files for controls, factory, and views. - Added .htaccess files for URL rewriting in layout and images directories. - Included a logo image in the layout/images directory. - Implemented load_prices.php to load ticket prices from the database into settings. - Developed admin panel settings page for enabling ticket sales. - Created tickets management page in the admin panel to display and edit ticket prices. - Added upgrade.php for database migrations, including creating the ticket_prices table and adding weekend price column.
This commit is contained in:
54
templates/admin-panel/settings.php
Normal file
54
templates/admin-panel/settings.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
$enable_sell = $this->enable_sell;
|
||||
?>
|
||||
<div id="admin-settings">
|
||||
<div class="container">
|
||||
<div class="tickets-orders">
|
||||
<h1>Ustawienia</h1>
|
||||
<div class="card p-4 mb-3">
|
||||
<div class="form-check form-switch">
|
||||
<input class="form-check-input" type="checkbox" id="enable_sell" <?= $enable_sell == '1' ? 'checked' : '' ?>>
|
||||
<label class="form-check-label" for="enable_sell">Sprzedaz biletow wlaczona</label>
|
||||
</div>
|
||||
</div>
|
||||
<button type="button" class="btn btn-t1" id="save-settings">Zapisz ustawienia</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function() {
|
||||
$('#save-settings').on('click', function() {
|
||||
var postData = {};
|
||||
if ($('#enable_sell').is(':checked')) {
|
||||
postData['enable_sell'] = '1';
|
||||
}
|
||||
|
||||
$.ajax({
|
||||
url: '/apanel/settings_save/',
|
||||
type: 'POST',
|
||||
data: postData,
|
||||
dataType: 'json',
|
||||
success: function(res) {
|
||||
if (res.status === 'ok') {
|
||||
$.alert({
|
||||
title: 'Sukces',
|
||||
content: 'Ustawienia zapisano',
|
||||
});
|
||||
} else {
|
||||
$.alert({
|
||||
title: 'Blad',
|
||||
content: res.message || 'Wystapil blad',
|
||||
});
|
||||
}
|
||||
},
|
||||
error: function() {
|
||||
$.alert({
|
||||
title: 'Blad',
|
||||
content: 'Nie udalo sie zapisac ustawien',
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
132
templates/admin-panel/tickets.php
Normal file
132
templates/admin-panel/tickets.php
Normal file
@@ -0,0 +1,132 @@
|
||||
<?php
|
||||
$tickets = $this->tickets;
|
||||
$exclude = ['ticket-protection', 'gift-price'];
|
||||
|
||||
// Sortowanie: pary ulgowy/normalny obok siebie
|
||||
$seen_bases = [];
|
||||
foreach ($tickets as $tid => $t) {
|
||||
if (in_array($tid, $exclude)) continue;
|
||||
$base = preg_replace('/-(ulgowy|normalny)$/', '', $tid);
|
||||
if (!in_array($base, $seen_bases)) {
|
||||
$seen_bases[] = $base;
|
||||
}
|
||||
}
|
||||
$ordered = [];
|
||||
foreach ($seen_bases as $base) {
|
||||
if (isset($tickets[$base . '-ulgowy']))
|
||||
$ordered[$base . '-ulgowy'] = $tickets[$base . '-ulgowy'];
|
||||
if (isset($tickets[$base . '-normalny']))
|
||||
$ordered[$base . '-normalny'] = $tickets[$base . '-normalny'];
|
||||
if (!isset($tickets[$base . '-ulgowy']) && !isset($tickets[$base . '-normalny']) && isset($tickets[$base]))
|
||||
$ordered[$base] = $tickets[$base];
|
||||
}
|
||||
$tickets = $ordered;
|
||||
?>
|
||||
<div id="tickets-prices">
|
||||
<div class="container">
|
||||
<div class="tickets-orders">
|
||||
<h1>Cennik biletow</h1>
|
||||
<div style="overflow-x:auto;">
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Bilet</th>
|
||||
<th>Cena PN-PT</th>
|
||||
<th>Cena SB-ND</th>
|
||||
<th>Doplata: dzis</th>
|
||||
<th>Doplata: 1-2 dni</th>
|
||||
<th>Doplata: 3-7 dni</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($tickets as $tid => $t) : ?>
|
||||
<?php if (in_array($tid, $exclude)) continue; ?>
|
||||
<tr>
|
||||
<td>
|
||||
<?= htmlspecialchars($t['name']); ?>
|
||||
<br><small class="text-muted"><?= htmlspecialchars($tid); ?></small>
|
||||
</td>
|
||||
<td>
|
||||
<input type="number" step="0.01" min="0" class="form-control"
|
||||
name="tickets[<?= $tid; ?>][price]"
|
||||
value="<?= $t['price'] ?? ''; ?>">
|
||||
</td>
|
||||
<td>
|
||||
<input type="number" step="0.01" min="0" class="form-control"
|
||||
name="tickets[<?= $tid; ?>][price_weekend]"
|
||||
value="<?= $t['price_weekend'] ?? ''; ?>">
|
||||
</td>
|
||||
<td>
|
||||
<input type="number" step="0.01" min="0" class="form-control"
|
||||
name="tickets[<?= $tid; ?>][day0]"
|
||||
value="<?= $t['dynamic_prices']['day0'] ?? ''; ?>">
|
||||
</td>
|
||||
<td>
|
||||
<input type="number" step="0.01" min="0" class="form-control"
|
||||
name="tickets[<?= $tid; ?>][day1_2]"
|
||||
value="<?= $t['dynamic_prices']['day1_2'] ?? ''; ?>">
|
||||
</td>
|
||||
<td>
|
||||
<input type="number" step="0.01" min="0" class="form-control"
|
||||
name="tickets[<?= $tid; ?>][day3_7]"
|
||||
value="<?= $t['dynamic_prices']['day3_7'] ?? ''; ?>">
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<?php $tp = $this->tickets['ticket-protection'] ?? null; ?>
|
||||
<?php if ($tp) : ?>
|
||||
<h3 class="mt-4">Doplaty</h3>
|
||||
<div class="row mb-3" style="max-width:400px;">
|
||||
<label class="col-8 col-form-label"><?= htmlspecialchars($tp['name']); ?></label>
|
||||
<div class="col-4">
|
||||
<input type="number" step="0.01" min="0" class="form-control"
|
||||
name="tickets[ticket-protection][price]"
|
||||
value="<?= $tp['price'] ?? ''; ?>">
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<button type="button" class="btn btn-t1" id="save-prices">Zapisz ceny</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function() {
|
||||
$('#save-prices').on('click', function() {
|
||||
var postData = {};
|
||||
$('input[name^="tickets["]').each(function() {
|
||||
postData[$(this).attr('name')] = $(this).val();
|
||||
});
|
||||
|
||||
$.ajax({
|
||||
url: '/apanel/tickets_save/',
|
||||
type: 'POST',
|
||||
data: postData,
|
||||
dataType: 'json',
|
||||
success: function(res) {
|
||||
if (res.status === 'ok') {
|
||||
$.alert({
|
||||
title: 'Sukces',
|
||||
content: 'Ceny zapisano',
|
||||
});
|
||||
} else {
|
||||
$.alert({
|
||||
title: 'Blad',
|
||||
content: res.message || 'Wystapil blad',
|
||||
});
|
||||
}
|
||||
},
|
||||
error: function() {
|
||||
$.alert({
|
||||
title: 'Blad',
|
||||
content: 'Nie udalo sie zapisac cen',
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
@@ -69,6 +69,16 @@
|
||||
Lista zamówień
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="/apanel/tickets/">
|
||||
Cennik
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="/apanel/settings/">
|
||||
Ustawienia
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<form action="/apanel/unlogin/" method="POST" class="unlogin">
|
||||
<button type="submit" class="btn-t2">Wylogować się</button>
|
||||
|
||||
@@ -19,7 +19,12 @@
|
||||
<?php foreach ($this->cart as $ticket_id => $combinations) : ?>
|
||||
<?php foreach ($combinations as $key => $value) : ?>
|
||||
<tr>
|
||||
<td data-label="BILETY"><?= $this->settings['tickets'][$ticket_id]['name']; ?> (x<?= $value["quantity"]; ?>)</td>
|
||||
<td data-label="BILETY">
|
||||
<?= $this->settings['tickets'][$ticket_id]['name']; ?> (x<?= $value["quantity"]; ?>)
|
||||
<?php if (!empty($value['date'])) : ?>
|
||||
<br><small class="ticket-date"><?= $value['date']; ?></small>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
<td data-label="CENA"><?= $value['ticket_price']; ?> zł</td>
|
||||
<td data-label="WARTOŚĆ"><?= $value['ticket_price'] * $value["quantity"]; ?> zł</td>
|
||||
<td data-label="ZMIENIĆ ILOŚĆ">
|
||||
|
||||
@@ -35,7 +35,12 @@
|
||||
<?php foreach ($this->cart as $ticket_id => $combinations) : ?>
|
||||
<?php foreach ($combinations as $key => $value) : ?>
|
||||
<tr>
|
||||
<td data-label="BILETY"><?= $this->settings['tickets'][$ticket_id]['name']; ?> (x<?= $value["quantity"]; ?>)</td>
|
||||
<td data-label="BILETY">
|
||||
<?= $this->settings['tickets'][$ticket_id]['name']; ?> (x<?= $value["quantity"]; ?>)
|
||||
<?php if (!empty($value['date'])) : ?>
|
||||
<br><small class="ticket-date"><?= $value['date']; ?></small>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
<td data-label="CENA"><?= $value['ticket_price']; ?> zł</td>
|
||||
<td data-label="WARTOŚĆ"><?= $value['ticket_price'] * $value["quantity"]; ?> zł</td>
|
||||
<td data-label="ZMIENIĆ ILOŚĆ">
|
||||
|
||||
@@ -7,22 +7,25 @@ if (isset($_POST['selected_date'])) {
|
||||
$interval = $today->diff($selected);
|
||||
$days_diff = (int)$interval->format('%r%a');
|
||||
|
||||
function date_price($item, $days_diff) {
|
||||
$is_weekend = in_array($selected->format('N'), ['6', '7']);
|
||||
|
||||
function date_price($item, $days_diff, $is_weekend = false) {
|
||||
$base = $is_weekend ? ($item['price_weekend'] ?? $item['price']) : $item['price'];
|
||||
|
||||
if($days_diff == 0) {
|
||||
$price = $item['price'] + $item['dynamic_prices']['day0'];
|
||||
$price = $base + $item['dynamic_prices']['day0'];
|
||||
return $price . ' zł';
|
||||
}
|
||||
elseif ($days_diff == 1 || $days_diff == 2) {
|
||||
$price = $item['price'] + $item['dynamic_prices']['day1_2'];
|
||||
$price = $base + $item['dynamic_prices']['day1_2'];
|
||||
return $price . ' zł';
|
||||
}
|
||||
elseif ($days_diff >= 3 && $days_diff <= 7) {
|
||||
$price = $item['price'] + $item['dynamic_prices']['day3_7'];
|
||||
$price = $base + $item['dynamic_prices']['day3_7'];
|
||||
return $price . ' zł';
|
||||
}
|
||||
else {
|
||||
$price = $item['price'];
|
||||
return $price . ' zł';
|
||||
return $base . ' zł';
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -46,72 +49,53 @@ if (isset($_POST['selected_date'])) {
|
||||
<h2>Do 31 marca ceny na wszystkie bilety <span>-20%</span></h2>
|
||||
</div> -->
|
||||
|
||||
<!-- Bilet ulgowy -->
|
||||
<!-- Bilety indywidualne (ulgowy + normalny w parach) -->
|
||||
<?php
|
||||
$ulgowe = $this->settings['bilety-ulgowe'];
|
||||
$normalne = $this->settings['bilety-normalne'];
|
||||
$count = max(count($ulgowe), count($normalne));
|
||||
?>
|
||||
<div class="ticket-container">
|
||||
<div class="title-container">
|
||||
<h2 class="title">Bilet ulgowy</h2>
|
||||
<p class="description">do 140cm wzrostu</p>
|
||||
<h2 class="title">Bilety indywidualne</h2>
|
||||
<p class="description">ulgowy (do 140cm) / normalny (od 140cm)</p>
|
||||
</div>
|
||||
<? foreach($this -> settings['bilety-ulgowe'] as $key => $item) : ?>
|
||||
<div class="ticket">
|
||||
<div class="ticket-description ticket-description--<?= $this -> settings['tickets'][$item]['color']; ?>">
|
||||
<h3 class="ticket__name"><?= explode( '-', $this -> settings['tickets'][$item]['name'])[0]; ?></h3>
|
||||
<p class="description">bilet całodniowy</p>
|
||||
|
||||
<? if($this -> settings['tickets'][$item]['alert']) : ?>
|
||||
<p class="ticket-alert"><?= $this -> settings['tickets'][$item]['alert']; ?></p>
|
||||
<? endif; ?>
|
||||
<?php for ($i = 0; $i < $count; $i++) : ?>
|
||||
<?php if (isset($ulgowe[$i])) : $item = $ulgowe[$i]; ?>
|
||||
<div class="ticket">
|
||||
<div class="ticket-description ticket-description--<?= $this->settings['tickets'][$item]['color']; ?>">
|
||||
<h3 class="ticket__name"><?= $this->settings['tickets'][$item]['name']; ?></h3>
|
||||
<p class="description">bilet całodniowy</p>
|
||||
<? if($this->settings['tickets'][$item]['alert']) : ?>
|
||||
<p class="ticket-alert"><?= $this->settings['tickets'][$item]['alert']; ?></p>
|
||||
<? endif; ?>
|
||||
</div>
|
||||
<h3 class="price">
|
||||
<?php echo date_price($this->settings['tickets'][$item], $days_diff, $is_weekend); ?>
|
||||
</h3>
|
||||
<div class="ticket-quantity">
|
||||
<button class="add button" ticket_id="<?= $item; ?>">Dodaj do koszyka</button>
|
||||
</div>
|
||||
</div>
|
||||
<h3 class="price">
|
||||
<?php
|
||||
echo date_price(
|
||||
$this -> settings['tickets'][$item],
|
||||
$days_diff
|
||||
);
|
||||
?>
|
||||
</h3>
|
||||
<!-- <h3 class="price"><?= $this -> settings['tickets'][$item]['price']; ?> zł</h3> -->
|
||||
<div class="ticket-quantity">
|
||||
<button class="add button" ticket_id="<?= $item; ?>"><i class="fa fa-plus"></i></button>
|
||||
<span>1x</span>
|
||||
<button class="subtract button" ticket_id="<?= $item; ?>" diffdays="<?= $days_diff; ?>"><i class="fa fa-minus"></i></button>
|
||||
<?php endif; ?>
|
||||
<?php if (isset($normalne[$i])) : $item = $normalne[$i]; ?>
|
||||
<div class="ticket">
|
||||
<div class="ticket-description ticket-description--<?= $this->settings['tickets'][$item]['color']; ?>">
|
||||
<h3 class="ticket__name"><?= $this->settings['tickets'][$item]['name']; ?></h3>
|
||||
<p class="description">bilet całodniowy</p>
|
||||
<? if($this->settings['tickets'][$item]['alert']) : ?>
|
||||
<p class="ticket-alert"><?= $this->settings['tickets'][$item]['alert']; ?></p>
|
||||
<? endif; ?>
|
||||
</div>
|
||||
<h3 class="price">
|
||||
<?php echo date_price($this->settings['tickets'][$item], $days_diff, $is_weekend); ?>
|
||||
</h3>
|
||||
<div class="ticket-quantity">
|
||||
<button class="add button" ticket_id="<?= $item; ?>">Dodaj do koszyka</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<? endforeach; ?>
|
||||
</div>
|
||||
|
||||
<!-- Bilet normalny -->
|
||||
<div class="ticket-container">
|
||||
<div class="title-container">
|
||||
<h2 class="title">Bilet normalny</h2>
|
||||
<p class="description">od 140cm wzrostu</p>
|
||||
</div>
|
||||
|
||||
<? foreach($this -> settings['bilety-normalne'] as $key => $item) : ?>
|
||||
<div class="ticket">
|
||||
<div class="ticket-description ticket-description--<?= $this -> settings['tickets'][$item]['color']; ?>">
|
||||
<h3 class="ticket__name"><?= explode( '-', $this -> settings['tickets'][$item]['name'])[0]; ?></h3>
|
||||
<p class="description">bilet całodniowy</p>
|
||||
|
||||
<? if($this -> settings['tickets'][$item]['alert']) : ?>
|
||||
<p class="ticket-alert"><?= $this -> settings['tickets'][$item]['alert']; ?></p>
|
||||
<? endif; ?>
|
||||
</div>
|
||||
<h3 class="price">
|
||||
<?php
|
||||
echo date_price(
|
||||
$this -> settings['tickets'][$item],
|
||||
$days_diff
|
||||
);
|
||||
?>
|
||||
</h3>
|
||||
<div class="ticket-quantity">
|
||||
<button class="add button" ticket_id="<?= $item; ?>"><i class="fa fa-plus"></i></button>
|
||||
<span>1x</span>
|
||||
<button class="subtract button" ticket_id="<?= $item; ?>" diffdays="<?= $days_diff; ?>"><i class="fa fa-minus"></i></button>
|
||||
</div>
|
||||
</div>
|
||||
<? endforeach; ?>
|
||||
<?php endif; ?>
|
||||
<?php endfor; ?>
|
||||
</div>
|
||||
|
||||
<? if($selected >= DateTime::createFromFormat('d-m-Y', '28-06-2025')): ?>
|
||||
@@ -139,9 +123,7 @@ if (isset($_POST['selected_date'])) {
|
||||
?>
|
||||
</h3>
|
||||
<div class="ticket-quantity">
|
||||
<button class="add button" ticket_id="<?= $item; ?>"><i class="fa fa-plus"></i></button>
|
||||
<span>1x</span>
|
||||
<button class="subtract button" ticket_id="<?= $item; ?>" diffdays="<?= $days_diff; ?>"><i class="fa fa-minus"></i></button>
|
||||
<button class="add button" ticket_id="<?= $item; ?>">Dodaj do koszyka</button>
|
||||
</div>
|
||||
</div>
|
||||
<? endforeach; ?>
|
||||
@@ -169,9 +151,7 @@ if (isset($_POST['selected_date'])) {
|
||||
?>
|
||||
</h3>
|
||||
<div class="ticket-quantity">
|
||||
<button class="add button" ticket_id="<?= $item; ?>"><i class="fa fa-plus"></i></button>
|
||||
<span>1x</span>
|
||||
<button class="subtract button" ticket_id="<?= $item; ?>" diffdays="<?= $days_diff; ?>"><i class="fa fa-minus"></i></button>
|
||||
<button class="add button" ticket_id="<?= $item; ?>">Dodaj do koszyka</button>
|
||||
</div>
|
||||
</div>
|
||||
<? endforeach; ?>
|
||||
@@ -193,15 +173,14 @@ if (isset($_POST['selected_date'])) {
|
||||
<?php
|
||||
echo date_price(
|
||||
$this -> settings['tickets'][$item],
|
||||
$days_diff
|
||||
$days_diff,
|
||||
$is_weekend
|
||||
);
|
||||
?>
|
||||
</h3>
|
||||
<div class="ticket-quantity">
|
||||
<button class="add button" ticket_id="<?= $item; ?>"><i class="fa fa-plus"></i></button>
|
||||
<span>1x</span>
|
||||
<button class="subtract button" ticket_id="<?= $item; ?>" diffdays="<?= $days_diff; ?>"><i class="fa fa-minus"></i></button>
|
||||
</div>
|
||||
<button class="add button" ticket_id="<?= $item; ?>">Dodaj do koszyka</button>
|
||||
</div>
|
||||
</div>
|
||||
<? endforeach; ?>
|
||||
</div>
|
||||
@@ -305,6 +284,7 @@ $(function() {
|
||||
$('body').on('click', '.add', function() {
|
||||
var ticket_id = $(this).attr('ticket_id');
|
||||
var date = $('#flatpickr').val();
|
||||
var $btn = $(this);
|
||||
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
@@ -319,33 +299,14 @@ $(function() {
|
||||
response = jQuery.parseJSON(data);
|
||||
$('.shopping-cart-container').html(response.shopping_cart);
|
||||
|
||||
// if (!$('.shopping-cart').hasClass('shopping-cart-active'))
|
||||
// $('.shopping-cart').addClass('shopping-cart--active');
|
||||
}
|
||||
});
|
||||
// animacja przycisku
|
||||
$btn.addClass('added');
|
||||
setTimeout(function() { $btn.removeClass('added'); }, 600);
|
||||
|
||||
});
|
||||
//subtract
|
||||
$('body').on('click', '.subtract', function() {
|
||||
var ticket_id = $(this).attr('ticket_id');
|
||||
var diffdays = $(this).attr('diffdays');
|
||||
console.log(diffdays);
|
||||
|
||||
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
cache: false,
|
||||
url: '/tickets/ticket_subtract/',
|
||||
data: {
|
||||
ticket_id: ticket_id,
|
||||
diffdays: diffdays
|
||||
},
|
||||
beforeSend: function() {},
|
||||
success: function(data) {
|
||||
response = jQuery.parseJSON(data);
|
||||
$('.shopping-cart-container').html(response.shopping_cart);
|
||||
// if (response.cart_count = 0)
|
||||
// $('.shopping-cart').removeClass('shopping-cart--active');
|
||||
// bounce koszyka
|
||||
var $cartBtn = $('.mobile-cart-btn');
|
||||
$cartBtn.addClass('cart-bounce');
|
||||
setTimeout(function() { $cartBtn.removeClass('cart-bounce'); }, 600);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user