first commit

This commit is contained in:
2026-04-28 15:13:50 +02:00
commit a95acc355b
63745 changed files with 9487948 additions and 0 deletions

View File

@@ -0,0 +1,724 @@
<?php
/**
* Provide a admin area view for the plugin
*
* This file is used to markup the admin-facing aspects of the plugin.
*
* @link https://polkurier.pl
* @since 1.0.0
*
* @package Polkurier
* @subpackage Polkurier/admin/partials
*/
use Polkurier\Types\CheckoutPointButtonPosition;
use Polkurier\Util\Arr;
require_once dirname(__FILE__) . '/../../includes/PolkurierPackage.php';
require_once dirname(__FILE__) . '/../../includes/PolkurierAPI.php';
$active_tab = isset($_GET['tab']) ? $_GET['tab'] : 'authorization';
$packages = get_option('polkurier_packages');
$addresses = get_option('polkurier_addresses');
$accounts = get_option('polkurier_accounts');
$coverAddresses = get_option('polkurier_cover_addresses');
if (isset($_GET['action']) && $_GET['action'] == 'delete') {
if ($active_tab == 'templates') {
unset($packages[(int) $_GET['id']]);
update_option('polkurier_packages', $packages);
}
if ($active_tab == 'addresses') {
unset($addresses[(int) $_GET['id']]);
update_option('polkurier_addresses', $addresses);
}
if ($active_tab == 'accounts') {
unset($accounts[(int) $_GET['id']]);
update_option('polkurier_accounts', $accounts);
}
if ($active_tab == 'cover_addresses') {
unset($coverAddresses[(int) $_GET['id']]);
update_option('polkurier_accounts', $coverAddresses);
}
}
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
if ($active_tab == 'templates') {
if (!isset($_POST['polkurier_id'])) {
// zapisujemy informacje o nowej templatce
$package = new PolkurierPackage();
} else {
// edytujemy templatkę
$package = PolkurierPackage::getPackageById($_POST['polkurier_id']);
}
$package->width = $_POST['polkurier_width'];
$package->height = $_POST['polkurier_height'];
$package->depth = $_POST['polkurier_depth'];
$package->weight = $_POST['polkurier_weight'];
$package->count = $_POST['polkurier_count'];
$package->nonstandard = isset($_POST['polkurier_nonstandard']);
$package->type = $_POST['polkurier_type'];
if (!isset($_POST['polkurier_id'])) {
// zapisujemy informacje o nowej templatce
$packages[] = $package;
} else {
// edytujemy templatkę
$packages[$_POST['polkurier_id']] = $package;
}
update_option('polkurier_packages', $packages);
}
if ($active_tab == 'accounts') {
// zapisujemy informacje o nowym koncie
$account = new PolkurierBankAccount();
$account->account = $_POST['polkurier_account'];
$account->alias = $_POST['polkurier_account_name'];
$accounts[] = $account;
update_option('polkurier_accounts', $accounts);
}
if ($active_tab == 'addresses') {
if (!isset($_POST['polkurier_id'])) {
// zapisujemy informacje o nowym adresie
$address = new PolkurierAddress();
} else {
$address = PolkurierAddress::getAddressById($_POST['polkurier_id']);
}
$address->address["company"] = $_POST["polkurier_company_name"];
$address->address["person"] = $_POST["polkurier_name_surname"];
$address->address["street"] = $_POST["polkurier_street"];
$address->address["housenumber"] = $_POST["polkurier_number_1"];
$address->address["flatnumber"] = $_POST["polkurier_number_2"];
$address->address["postcode"] = $_POST["polkurier_postal_code"];
$address->address["city"] = $_POST["polkurier_city"];
$address->address["phone"] = $_POST["polkurier_phone"];
$address->address["email"] = $_POST["polkurier_email"];
$address->address["account_id"] = $_POST["polkurier_polkurier_account_id"];
if (!isset($_POST['polkurier_id'])) {
$addresses[] = $address;
} else {
$addresses[$_POST['polkurier_id']] = $address;
}
update_option('polkurier_addresses', $addresses);
}
// SAVE COVER ADDRESS
if ($active_tab == 'cover_addresses') {
if (!isset($_POST['polkurier_id'])) {
// zapisujemy informacje o nowym adresie
$coverAddress = new PolkurierAddress();
} else {
$coverAddress = PolkurierAddress::getCoverAddressById($_POST['polkurier_id']);
}
$coverAddress->address["company"] = $_POST["polkurier_company_name"];
$coverAddress->address["person"] = $_POST["polkurier_name_surname"];
$coverAddress->address["street"] = $_POST["polkurier_street"];
$coverAddress->address["housenumber"] = $_POST["polkurier_number_1"];
$coverAddress->address["flatnumber"] = $_POST["polkurier_number_2"];
$coverAddress->address["postcode"] = $_POST["polkurier_postal_code"];
$coverAddress->address["city"] = $_POST["polkurier_city"];
$coverAddress->address["phone"] = $_POST["polkurier_phone"];
$coverAddress->address["email"] = $_POST["polkurier_email"];
$coverAddress->address["account_id"] = $_POST["polkurier_polkurier_account_id"];
if (!isset($_POST['polkurier_id'])) {
$coverAddresses[] = $coverAddress;
} else {
$coverAddresses[$_POST['polkurier_id']] = $coverAddress;
}
update_option('polkurier_cover_addresses', $coverAddresses);
}
// END SAVE COVER ADDRESS
}
?>
<div class="wrap">
<h2><?php echo esc_html(get_admin_page_title()); ?></h2>
<?php settings_errors();?>
<?php if (isset($_GET['action']) && ($_GET['action'] == 'view')): ?>
<h2>Szczegóły paczki:</h2>
<p>
<?php $details = $this->get_package_details();
echo $this->describe_field("orderNumber", $details["orderNumber"]);
echo $this->describe_field("size", $details["size"]);
echo $this->describe_field("status", $details["status"]);
echo "<table><tr><td style=\"vertical-align: top; padding-right: 4em\">";
echo "<h3>Nadawca:</h3>";
foreach ($details["sender"] as $key => $value) {
echo $this->describe_field($key, $value);
}
echo "</td><td style=\"vertical-align: top\">";
echo "<h3>Odbiorca:</h3>";
foreach ($details["receiver"] as $key => $value) {
echo $this->describe_field($key, $value);
}
echo "</td></tr></table>";
echo "<a href=\"?page=polkurier\" class=\"button primary-button\">Powrót</a>";
?>
</p>
<?php else: // default table and settings ?>
<h2 class="nav-tab-wrapper">
<a href="?page=polkurier&tab=authorization" class="nav-tab <?php echo $active_tab == 'authorization' ? 'nav-tab-active' : '' ?>">Autoryzacja</a>
<a href="?page=polkurier&tab=addresses" class="nav-tab <?php echo $active_tab == 'addresses' ? 'nav-tab-active' : '' ?>">Domyślne adresy</a>
<a href="?page=polkurier&tab=cover_addresses" class="nav-tab <?php echo $active_tab == 'cover_addresses' ? 'nav-tab-active' : '' ?>">Adresy na etykiecie</a>
<a href="?page=polkurier&tab=accounts" class="nav-tab <?php echo $active_tab == 'accounts' ? 'nav-tab-active' : '' ?>">Konta bankowe</a>
<a href="?page=polkurier&tab=templates" class="nav-tab <?php echo $active_tab == 'templates' ? 'nav-tab-active' : '' ?>">Szablony paczek</a>
<a href="?page=polkurier&tab=carrier" class="nav-tab <?php echo $active_tab == 'carrier' ? 'nav-tab-active' : '' ?>">Domyślny przewoźnik</a>
<a href="?page=polkurier&tab=couriers_points" class="nav-tab <?php echo $active_tab == 'couriers_points' ? 'nav-tab-active' : '' ?>">Domyślny paczkomat / punkt nadania</a>
<a href="?page=polkurier&tab=default_services" class="nav-tab <?php echo $active_tab == 'default_services' ? 'nav-tab-active' : '' ?>">Domyślne wartości</a>
<a href="?page=polkurier&tab=other" class="nav-tab <?php echo $active_tab == 'other' ? 'nav-tab-active' : '' ?>">Inne</a>
</h2><?php switch ($active_tab):
case 'authorization': ?>
<form action="options.php" method="post">
<?php
settings_fields($this->plugin_name . '_authorization');
do_settings_sections($this->plugin_name . '_authorization');
submit_button();
?>
</form>
<?php break;case 'addresses': ?>
<?php if (!(isset($_GET['action']) && $_GET['action'] == 'edit')): ?>
<h2>Dostępne adresy</h2>
<?php else: ?>
<h2>Edycja adresu</h2>
<?php endif; ?>
<table class="wp-list-table widefat fixed striped polkurier-admin-table">
<?php if ($addresses && count($addresses)>0 && (isset($_GET['action'])?($_GET['action'] != 'edit'):true) ) : ?>
<thead>
<tr>
<th>Nazwa firmy</th>
<th>Imię i nazwisko</th>
<th>Adres</th>
<th>Kod pocztowy i miasto</th>
<th>Numer telefonu</th>
<th>E-mail</th>
<th>ID Polkurier</th>
<th>Działania</th>
</tr>
</thead>
<?php endif; ?>
<?php if (!(isset($_GET['action']) && $_GET['action'] == 'edit') && $addresses) foreach ($addresses as $key => $pkg): ?>
<tr><?php echo $pkg->asTableRow() ?>
<td><a href="admin.php?page=polkurier&tab=addresses&action=edit&id=<?php echo $key ?>">edytuj</a>
<a href="admin.php?page=polkurier&tab=addresses&action=delete&id=<?php echo $key ?>" onclick="return confirm('Czy na pewno usunąć adres?')">usuń</a></td>
</tr>
<?php endforeach?></table>
<form action="admin.php?page=polkurier&tab=addresses" method="post">
<?php if (isset($_GET['action']) && $_GET['action'] == 'edit'):
$adres = PolkurierAddress::getAddressById($_GET['id']);
$adres->renderForm();
else: ?>
<table class="form-table">
<tbody>
<tr><th scope="row">
<label for="polkurier_company_name">Nazwa firmy</label></th>
<td><input required type="text" name="polkurier_company_name" id="polkurier_company_name" value=""> </td>
</tr>
<tr><th scope="row"><label for="polkurier_name_surname_cb">Imię&nbsp;i nazwisko</label></th>
<td><input required type="text" name="polkurier_name_surname" id="polkurier_name_surname" value=""> </td>
</tr>
<tr><th scope="row"><label for="polkurier_street_cb">Ulica</label></th>
<td><input required type="text" name="polkurier_street" id="polkurier_street" value=""> </td>
</tr>
<tr><th scope="row"><label for="polkurier_number_1_cb">Numer budynku</label></th>
<td><input required type="text" name="polkurier_number_1" id="polkurier_number_1" value=""> </td></tr>
<tr>
<th scope="row"><label for="polkurier_number_2_cb">Numer lokalu</label></th>
<td><input type="text" name="polkurier_number_2" id="polkurier_number_2" value=""> </td></tr>
<tr>
<th scope="row"><label for="polkurier_postal_code_cb">Kod pocztowy</label></th>
<td><input required type="text" pattern="[0-9]{2}-[0-9]{3}" title="Kod pocztowy musi być w formie xx-xxx" name="polkurier_postal_code" id="polkurier_postal_code" value=""> </td></tr>
<tr><th scope="row"><label for="polkurier_city_cb">Miasto</label></th>
<td><input required type="text" name="polkurier_city" id="polkurier_city" value=""> </td></tr>
<tr><th scope="row"><label for="polkurier_phone_cb">Numer telefonu</label></th>
<td><input required type="text" pattern="[0-9]{9}" title="Podaj dziewięciocyfrowy numer telefonu" name="polkurier_phone" id="polkurier_phone" value=""> </td></tr>
<tr><th scope="row"><label for="polkurier_email_cb">Adres e-mail</label></th>
<td><input required type="email" pattern="[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4}$" title="Podaj poprawny adres e-mail" name="polkurier_email" id="polkurier_email" value=""> </td></tr>
<tr><th scope="row"><label for="polkurier_polkurier_account_id_cb">ID konta Polkurier</label></th>
<td><input type="text" name="polkurier_polkurier_account_id" id="polkurier_polkurier_account_id" value=""> <br/><em>Opcja dostępna dla klientów nadających przesyłki za pośrednictwem przewoźnika Geis oraz posiadających aktywną opcje stałych odbiorów. ID konta należy pozyskać kontaktując się z biurem obsługi klienta serwisu polkurier.pl.</em></td></tr>
</tbody></table>
<?php endif;
submit_button(((isset($_GET['action']) && $_GET['action'] == 'edit'))?"Zapisz zmiany":"Dodaj adres");
?>
</form>
<!-- COVER ADDRESS FORM-->
<?php break;case 'cover_addresses': ?>
<?php if (!(isset($_GET['action']) && $_GET['action'] == 'edit')): ?>
<h2>Dostępne adresy</h2>
<?php else: ?>
<h2>Edycja adresu</h2>
<?php endif; ?>
<table class="wp-list-table widefat fixed striped polkurier-admin-table">
<?php if ($coverAddresses && count($coverAddresses)>0 && (isset($_GET['action'])?($_GET['action'] != 'edit'):true) ) : ?>
<thead>
<tr>
<th>Nazwa firmy</th>
<th>Imię i nazwisko</th>
<th>Adres</th>
<th>Kod pocztowy i miasto</th>
<th>Numer telefonu</th>
<th>E-mail</th>
<th>Działania</th>
</tr>
</thead>
<?php endif; ?>
<?php if (!(isset($_GET['action']) && $_GET['action'] == 'edit') && $coverAddresses) foreach ($coverAddresses as $key => $pkg): ?>
<tr><?php echo $pkg->asTableRow(['account_id'])?>
<td><a href="admin.php?page=polkurier&tab=cover_addresses&action=edit&id=<?php echo $key ?>">edytuj</a>
<a href="admin.php?page=polkurier&tab=cover_addresses&action=delete&id=<?php echo $key ?>" onclick="return confirm('Czy na pewno usunąć adres?')">usuń</a></td>
</tr>
<?php endforeach?></table>
<form action="admin.php?page=polkurier&tab=cover_addresses" method="post">
<?php if (isset($_GET['action']) && $_GET['action'] == 'edit'):
$adres = PolkurierAddress::getCoverAddressById($_GET['id']);
$adres->renderForm();
else: ?>
<table class="form-table">
<tbody>
<tr>
<th scope="row">
<label for="polkurier_company_name">Nazwa firmy</label></th>
<td><input type="text" name="polkurier_company_name" id="polkurier_company_name" value="">
</td>
</tr>
<tr>
<th scope="row"><label for="polkurier_name_surname_cb">Imię&nbsp;i nazwisko</label></th>
<td><input type="text" name="polkurier_name_surname" id="polkurier_name_surname" value="">
</td>
</tr>
<tr>
<th scope="row"><label for="polkurier_street_cb">Ulica</label></th>
<td><input type="text" name="polkurier_street" id="polkurier_street" value=""></td>
</tr>
<tr>
<th scope="row"><label for="polkurier_number_1_cb">Numer budynku</label></th>
<td><input type="text" name="polkurier_number_1" id="polkurier_number_1" value=""></td>
</tr>
<tr>
<th scope="row"><label for="polkurier_number_2_cb">Numer lokalu</label></th>
<td><input type="text" name="polkurier_number_2" id="polkurier_number_2" value=""></td>
</tr>
<tr>
<th scope="row"><label for="polkurier_postal_code_cb">Kod pocztowy</label></th>
<td><input type="text" pattern="[0-9]{2}-[0-9]{3}"
title="Kod pocztowy musi być w formie xx-xxx" name="polkurier_postal_code"
id="polkurier_postal_code" value=""></td>
</tr>
<tr>
<th scope="row"><label for="polkurier_city_cb">Miasto</label></th>
<td><input type="text" name="polkurier_city" id="polkurier_city" value=""></td>
</tr>
<tr>
<th scope="row"><label for="polkurier_phone_cb">Numer telefonu</label></th>
<td><input type="text" pattern="[0-9]{9}" title="Podaj dziewięciocyfrowy numer telefonu"
name="polkurier_phone" id="polkurier_phone" value=""></td>
</tr>
<tr>
<th scope="row"><label for="polkurier_email_cb">Adres e-mail</label></th>
<td><input type="email" pattern="[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4}$"
title="Podaj poprawny adres e-mail" name="polkurier_email" id="polkurier_email" value="">
</td>
</tr>
</tbody>
</table>
<?php endif;
submit_button(((isset($_GET['action']) && $_GET['action'] == 'edit'))?"Zapisz zmiany":"Dodaj adres");
?>
</form>
<!-- END COVER ADDRESS FORM-->
<?php break;case 'accounts': ?>
<h2>Dostępne konta bankowe</h2>
<table class="wp-list-table widefat striped polkurier-admin-table">
<?php if ($accounts && count($accounts)>0 && (isset($_GET['action'])?($_GET['action'] != 'edit'):true)): ?>
<thead>
<tr>
<th>Nazwa</th<>
<th>Numer rachunku</th>
<th>Działania</th>
</tr>
</thead>
<?php endif; ?>
<?php if ($accounts) foreach ($accounts as $key => $pkg): ?>
<tr><?php echo $pkg->asTableRow() ?>
<td><a href="admin.php?page=polkurier&tab=accounts&action=delete&id=<?php echo $key ?>" onclick="return confirm('Czy na pewno usunąć numer konta?')">usuń</a></td>
</tr>
<?php endforeach?>
</table>
<form action="admin.php?page=polkurier&tab=accounts" method="post">
<table class="form-table"><tbody>
<tr><th scope="row"><label for="polkurier_account_number_name">Nazwa konta bankowego</label></th>
<td><input required name="polkurier_account_name" id="polkurier_account_name" value=""> </td></tr>
<tr><th scope="row"><label for="polkurier_account_number_cb">Numer konta bankowego</label></th>
<td><input required pattern="[0-9]{26}" title="Należy podać 26 cyfr" name="polkurier_account" id="polkurier_account" value=""> </td></tr></tbody></table>
<?php
submit_button("Dodaj konto bankowe", "primary", "submit", true, ['onclick' => 'return fn_polkurier_validate(jQuery(\'#polkurier_account\').val())']);
?>
</form>
<?php break;case 'templates': ?>
<?php if (!(isset($_GET['action']) && $_GET['action'] == 'edit')): ?>
<h2>Dostępne szablony paczek</h2>
<table class="wp-list-table widefat fixed striped polkurier-admin-table">
<?php if ($packages && count($packages)>0 && (isset($_GET['action'])?($_GET['action'] != 'edit'):true)): ?>
<thead>
<tr>
<th>Rodzaj</th><th>Wymiary</th><th>Waga</th><th>Ilość</th><th>Niestandardowa</th><th>Działania</th>
</tr>
</thead>
<?php endif;
if ($packages) foreach ($packages as $key => $pkg): ?>
<tr><?php echo $pkg->asTableRow() ?><td><a href="admin.php?page=polkurier&tab=templates&action=edit&id=<?php echo $key ?>">edytuj</a>
<a href="admin.php?page=polkurier&tab=templates&action=delete&id=<?php echo $key ?>" onclick="return confirm('Czy na pewno usunąć szablon?')">usuń</a>
</td></tr>
<?php endforeach?>
</table>
<?php endif; ?>
<form action="admin.php?page=polkurier&tab=templates" method="post">
<?php if (isset($_GET['action']) && $_GET['action'] == 'edit'):
$paczka = PolkurierPackage::getPackageById($_GET['id']);
echo '<h2>Edycja szablonu paczki</h2>';
$paczka->renderForm();
else: ?>
<h2>Dodaj nowy szablon paczki</h2>
<table class="form-table">
<tbody>
<tr>
<th scope="row"><label for="polkurier_height">Wysokość (cm)</label></th>
<td><input required type="number" name="polkurier_height" id="polkurier_height" value=""> </td>
</tr>
<tr>
<th scope="row"><label for="polkurier_width">Szerokość (cm)</label></th>
<td><input required type="number" name="polkurier_width" id="polkurier_width" value=""> </td>
</tr>
<tr>
<th scope="row"><label for="polkurier_depth">Głębokość (cm)</label></th>
<td><input required type="number" name="polkurier_depth" id="polkurier_depth" value=""> </td>
</tr>
<tr>
<th scope="row"><label for="polkurier_weight">Waga (kg)</label></th>
<td><input required type="number" name="polkurier_weight" id="polkurier_weight" value=""> </td>
</tr>
<tr>
<th scope="row"><label for="polkurier_count">Ilość</label></th>
<td><input required type="number" name="polkurier_count" id="polkurier_count" value=""> </td>
</tr>
<tr>
<th scope="row"><label for="polkurier_nonstandard">Niestandardowa</label></th>
<td><input type="checkbox" name="polkurier_nonstandard" id="polkurier_nonstandard" value="1"> </td>
</tr>
<tr>
<th scope="row"><label for="polkurier_type">Typ przesyłki</label></th>
<td>
<input type="radio" name="polkurier_type" id="polkurier_type_1" value="koperta">
<label for="polkurier_type_1">koperta</label><br/>
<input type="radio" name="polkurier_type" id="polkurier_type_2" value="paczka" checked>
<label for="polkurier_type_2">paczka</label><br/>
<input type="radio" name="polkurier_type" id="polkurier_type_3" value="paleta">
<label for="polkurier_type_3">paleta</label>
</td>
</tr>
</tbody></table>
<?php endif; submit_button();?>
</form>
<?php break;case 'carrier': ?>
<form action="options.php" method="post">
<?php
settings_fields($this->plugin_name . '_default_carrier');
do_settings_sections($this->plugin_name . '_default_carrier');
submit_button();
?>
</form>
<?php break; ?>
<?php case 'couriers_points': ?>
<?php
$couriers = [[
'name' => 'INPOST_PACZKOMAT',
'title' => 'Paczkomaty InPost',
], [
'name' => 'POCZTEX_PUNKT',
'title' => 'Pocztex Punkt',
], [
'name' => 'DPD',
'title' => 'Punkt DPD'
], [
'name' => 'DHL_POINT',
'title' => 'Punkt DHL'
], [
'name' => 'UPS_AP_POINT_POINT',
'title' => 'UPS'
]];
$mapToken = (new \Polkurier\MapsTokenManager())->getToken();
?>
<div class="pk-flex-row">
<?php foreach ($couriers as $courier): ?>
<div class="pk-flex-col-6">
<div class="pk-card pk-mt-5 pk-mx-2 pk-shadow" style="background: white;">
<div class="pk-card-header">
<?= $courier['title'] ?>
</div>
<div class="pk-card-body">
<div id="default-courier-point-label-<?= $courier['name'] ?>" class="pk-p-2 pk-m-2 pk-border-1">
<?php if (get_option('polkurier_default_point_id_' . $courier['name'])): ?>
[<?php echo get_option('polkurier_default_point_id_' . $courier['name']) ?>]
<?php echo get_option('polkurier_default_point_label_' . $courier['name']) ?>
<?php else: ?>
BRAK
<?php endif ?>
</div>
<div style="text-align: center">
<button type="button" class="button button-primary" id="default-courier-point-map-<?= $courier['name'] ?>">Wybierz z mapy</button>
<button type="button" class="button button-primary" id="delete-default-courier-point-map-<?= $courier['name'] ?>">Wyczyść</button>
</div>
</div>
</div>
</div>
<?php endforeach ?>
</div>
<script>
var ajaxNonce = '<?php echo wp_create_nonce('polkurier-nonce') ?>';
var ajaxUrl = '<?php echo admin_url('admin-ajax.php') ?>';
var initMapAction = function (options) {
console.log(options);
options.$deleteButton.on('click', function () {
if (!confirm('Na pewno usunąć wybrany punkt?')) {
return;
}
POLKURIER.showLoadingSpinner(options.$deleteButton);
jQuery
.post(ajaxUrl, {
action: 'pk_update_default_courier_point',
nonce: ajaxNonce,
courier: options.courier,
})
.success(function () {
options.$label.text('BRAK');
})
.always(function () {
POLKURIER.hideLoadingSpinner(options.$deleteButton);
});
});
options.$button.on('click', function () {
var map = new POLKURIER.PointsMap({
token: '<?php echo $mapToken->getToken() ?>',
providers: options.providers,
functions: ['send'],
});
map.onConfirm(function (point) {
var label = point.street + ', ' + point.zip + ' ' + point.city;
options.$label.text('[' + point.id + '] ' + label);
POLKURIER.showLoadingSpinner(options.$button);
jQuery
.post(ajaxUrl, {
action: 'pk_update_default_courier_point',
nonce: ajaxNonce,
courier: options.courier,
pointId: point.id,
pointLabel: label
})
.always(function () {
POLKURIER.hideLoadingSpinner(options.$button);
});
map.closeMapDialog();
});
map.showMapDialog();
});
};
var couriers = {
INPOST_PACZKOMAT: {
providers: ['INPOST_PACZKOMAT',]
},
POCZTEX_PUNKT: {
providers: ['POCZTEX_PUNKT'],
},
DPD: {
providers: ['DPD_POINT'],
},
DHL_POINT: {
providers: ['DHL_POINT'],
},
UPS_AP_POINT_POINT: {
providers: ['UPS_AP_POINT_POINT'],
},
};
for (var name in couriers) {
initMapAction(Object.assign({
$button: jQuery('#default-courier-point-map-' + name),
$deleteButton: jQuery('#delete-default-courier-point-map-' + name),
$label: jQuery('#default-courier-point-label-' + name),
courier: name,
}, couriers[name] || {}));
}
</script>
<?php break; ?>
<?php case 'default_services': ?>
<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
update_option('polkurier_default_courierservice_SMS_NOTIFICATION_RECIPIENT', Arr::get($_POST, 'SMS_NOTIFICATION_RECIPIENT') === '1' ? '1' : '');
update_option('polkurier_default_courierservice_SMS_NOTIFICATION_RECIPIENT_WITH_NAME', Arr::get($_POST, 'SMS_NOTIFICATION_RECIPIENT_WITH_NAME') === '1' ? '1' : '');
update_option('polkurier_DEFAULT_COD_RETURN_TYPE', Arr::get($_POST, 'DEFAULT_COD_RETURN_TYPE', ''));
}
?>
<form method="POST" class="pk-card pk-mt-5 pk-mx-auto pk-w-75 pk-shadow" style="background: white;">
<div class="pk-card-header">
Usługi domyślnie włączone
</div>
<div class="pk-card-body">
<p>
Usługi te będą automatycznie włączone w formularzu wysyłki
</p>
<div class="pk-my-4">
<label>
<input type="checkbox" name="SMS_NOTIFICATION_RECIPIENT" <?php echo get_option('polkurier_default_courierservice_SMS_NOTIFICATION_RECIPIENT') === '1' ? 'checked' : '' ?> value="1" />
<strong>Powiadomienie SMS dla odbiorcy</strong>
</label>
<div class="pk-ml-5">
<small>Powiadomienie zostanie wysłane po odebraniu przesyłki od nadawcy</small>
</div>
</div>
<div class="pk-my-4">
<label>
<input type="checkbox" name="SMS_NOTIFICATION_RECIPIENT_WITH_NAME" <?php echo get_option('polkurier_default_courierservice_SMS_NOTIFICATION_RECIPIENT_WITH_NAME') === '1' ? 'checked' : '' ?> value="1" />
<strong>Powiadomienie SMS dla odbiorcy z własną nazwą nadawcy</strong>
</label>
<div class="pk-ml-5">
<small>
Powiadomienie zostanie wysłane po odebraniu przesyłki od nadawcy<br>
Jako nadawca wiadomości będzie widnieć Twoja nazwa.<br>
Wymagane jest ustawienie domyślnej nazwy nadawcy w panelu klienta na portalu
<a href="https://polkurier.pl">Polkurier.pl</a> w zakładce "Ustawienia" &rarr; "Powiadomienia"
</small>
</div>
</div>
<hr>
<div class="pk-my-4">
<label>
<div>
<strong>Domyślny rodzaj zwrotu pobrania</strong>
</div>
<?php
$DEFAULT_COD_RETURN_TYPE = get_option('polkurier_DEFAULT_COD_RETURN_TYPE');
if (empty($DEFAULT_COD_RETURN_TYPE)) {
$DEFAULT_COD_RETURN_TYPE === 'BA';
}
?>
<select name="DEFAULT_COD_RETURN_TYPE">
<option value="BA" <?php echo $DEFAULT_COD_RETURN_TYPE === 'BA' ? 'selected' : '' ?> >Przelew na konto bankowe</option>
<option value="PO" <?php echo $DEFAULT_COD_RETURN_TYPE === 'PO' ? 'selected' : '' ?> >Przekaz pocztowy na adres nadawcy</option>
<option value="MB" <?php echo $DEFAULT_COD_RETURN_TYPE === 'MB' ? 'selected' : '' ?> >Do skarbonki </option>
</select>
</label>
</div>
<div style="text-align: center" class="pk-mt-4">
<button type="submit" class="button button-primary" id="delete-default-courier-point-map-INPOST_PACZKOMAT">Zapisz</button>
</div>
</div>
</form>
<script>
(function () {
var $smsNotificationRecipient = jQuery('[name="SMS_NOTIFICATION_RECIPIENT"]');
var $smsNotificationRecipientWithName = jQuery('[name="SMS_NOTIFICATION_RECIPIENT_WITH_NAME"]');
$smsNotificationRecipient.on('change', function () {
$smsNotificationRecipientWithName.prop('checked', false);
});
$smsNotificationRecipientWithName.on('change', function () {
$smsNotificationRecipient.prop('checked', false);
});
}) ();
</script>
<?php break; ?>
<?php case 'other': ?>
<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
update_option('polkurier_layout_checkout_full_row', Arr::get($_POST, 'polkurier_layout_checkout_full_row') === '1' ? '1' : '');
update_option('polkurier_layout_checkout_point_button_position', (string)Arr::get($_POST, 'polkurier_layout_checkout_point_button_position'));
}
?>
<form method="POST" class="pk-card pk-mt-5 pk-mx-auto pk-w-75 pk-shadow" style="background: white;">
<div class="pk-card-header">
Wygląd
</div>
<div class="pk-card-body">
<div class="pk-my-4">
<label>
<input type="checkbox" name="polkurier_layout_checkout_full_row" <?php echo get_option('polkurier_layout_checkout_full_row') === '1' ? 'checked' : '' ?> value="1" />
<strong>Przycisk "Wybierz paczkomat" / "Wybierz punkt" w jednej komórce</strong>
</label>
<div class="pk-ml-5">
<small>
Szablon HTML WooCommerce wykorzystuje tabelki w ostatnim kroku zamówienia,
gdzie w lewej komórce zawarty jest tytuł wiersza, a w prawej treść lub opcje do wyboru.
Po zaznaczeniu tej opcji komórki zostaną scalone w jedną na całą szerokość wiersza.
</small>
</div>
</div>
<div class="pk-my-4">
<label>
<div>
<strong>Pozycja przycisku "Wybierz paczkomat" / "Wybierz punkt"</strong>
</div>
<?php
$LAYOUT_CHECKOUT_POINT_BUTTON_POSITION = (string)get_option('polkurier_layout_checkout_point_button_position');
?>
<select name="polkurier_layout_checkout_point_button_position">
<?php foreach (CheckoutPointButtonPosition::NAMES as $id => $name): ?>
<option value="<?= $id ?>" <?= $LAYOUT_CHECKOUT_POINT_BUTTON_POSITION === $id ? 'selected' : '' ?>>
<?= $name ?>
</option>
<?php endforeach; ?>
</select>
</label>
</div>
<hr>
<div style="text-align: center" class="pk-mt-4">
<button type="submit" class="button button-primary" id="delete-default-courier-point-map-INPOST_PACZKOMAT">Zapisz</button>
</div>
</div>
</form>
<?php break; ?>
<?php
endswitch;
endif;
?>
</div>
<script type="text/javascript">
function fn_polkurier_validate(input)
{
input = "PL" + input;
var iban = String(input).toUpperCase().replace(/[^A-Z0-9]/g, ''),
code = iban.match(/^([A-Z]{2})(\d{2})([A-Z\d]+)$/),
digits;
digits = (code[3] + code[1] + code[2]).replace(/[A-Z]/g, function (letter) {
return letter.charCodeAt(0) - 55;
});
if (mod97(digits) === 1) {
return true;
}
else {
alert("Niepoprawny numer rachunku bankowego");
return false;
}
}
function mod97(string) {
var checksum = string.slice(0, 2), fragment;
for (var offset = 2; offset < string.length; offset += 7) {
fragment = String(checksum) + string.substring(offset, offset + 7);
checksum = parseInt(fragment, 10) % 97;
}
return checksum;
}
</script>

View File

@@ -0,0 +1,85 @@
<?php
use Polkurier\Util\Arr;
$order = PolkurierOrder::getOrderByNumber((string)$_GET['label']);
$statusUpdater = new PolkurierOrderStatusUpdater();
$statusUpdater->updateOrderStatus($order);
?>
<h2>Szczegóły zamówienia Polkurier <?php echo $order->params['order_number'] ?></h2>
<table class="form-table">
<tbody>
<tr>
<th scope="row"><label>Przewoźnik</label></th>
<td><?php echo $order->params['carrier'] ?></td>
</tr>
<tr>
<th scope="row"><label>Rodzaj przesyłki</label></th>
<td><?php switch($order->params['extra']['shipmenttype']) {
case "box": echo "paczka"; break;
case "envelope": echo "koperta"; break;
case "palette": echo "paleta"; break;
} ?></td>
</tr>
<tr>
<th scope="row"><label>Data nadania</label></th>
<td><?php echo $order->params['extra']['pickup']['pickupdate'] ?></td>
</tr>
<tr>
<th scope="row"><label>Paczki</label></th>
<td><?php foreach ($order->params['extra']['packs'] as $pack) {
echo "(wymiary: ".$pack['height']."x".$pack['width']."x".$pack['length']."cm, waga: ".$pack['weight']."kg, ilość: ".$pack['amount'].")".(($pack['type']=='NST')?" niestandardowa":null)."</br>";
} ?></td>
</tr>
<tr>
<th scope="row"><label>Adres nadawcy</label></th>
<td>
<?php
echo $order->params['extra']['sender']["company"] . "<br/>";
echo $order->params['extra']['sender']["person"] . "<br/>";
echo $order->params['extra']['sender']["street"] . " " . $order->params['extra']['sender']["housenumber"] . " " . $order->params['extra']['sender']["flatnumber"] . "<br/>";
echo $order->params['extra']['sender']["postcode"] . " " . $order->params['extra']['sender']["city"] . ' (' . Arr::get($order->params['extra']['sender'], "country", 'PL'). ")<br/>";
echo $order->params['extra']['sender']["phone"] . " " . $order->params['extra']['sender']["email"] . '<br>';
echo !empty($order->params['extra']['sender']["machinename"]) ? 'Punkt nadania: ' . $order->params['extra']['sender']["machinename"] : '';
?>
</td>
</tr>
<tr>
<th scope="row"><label>Adres odbiorcy</label></th>
<td>
<?php
echo $order->params['extra']['recipient']["company"] . "<br/>";
echo $order->params['extra']['recipient']["person"] . "<br/>";
echo $order->params['extra']['recipient']["street"] . " " . $order->params['extra']['recipient']["housenumber"] . " " . $order->params['extra']['recipient']["flatnumber"] . "<br/>";
echo $order->params['extra']['recipient']["postcode"] . " " . $order->params['extra']['recipient']["city"] . ' (' . $order->params['extra']['recipient']["country"] . ")<br/>";
echo $order->params['extra']['recipient']["phone"] . " " . $order->params['extra']['recipient']["email"] . '<br>';
echo !empty($order->params['extra']['recipient']["machinename"]) ? 'Punkt odbioru: ' . $order->params['extra']['recipient']["machinename"] : '';
?>
</td>
</tr>
<tr>
<th scope="row"><label>Kwota pobrania</label></th>
<td><?php echo ((isset($order->params['extra']['pobranie'])&&$order->params['extra']['pobranie'])?$order->params['extra']['pobranie']:'brak') ?></td>
</tr>
<tr>
<th scope="row"><label>Kwota ubezpieczenia</label></th>
<td><?php echo ($order->params['extra']['insurance']?$order->params['extra']['insurance']:'brak') ?></td>
</tr>
<tr>
<th scope="row"><label>Status</label></th>
<td><?php echo $order->status;
if ($order->status_code == 'D') { // dostarczona
echo ", data doręczenia: ".$order->delivery_date;
}
?></td>
</tr>
</tbody>
</table>
<?php
if( wp_get_referer() ) {
echo '<a href="'.wp_get_referer().'" >Wstecz</a>';
} else {
echo '<a href="admin.php?page=polkurier_packages">Wstecz</a>';
}

View File

@@ -0,0 +1,83 @@
<?php
/**
* Provide a admin area view for the plugin
*
* This file is used to markup the admin-facing aspects of the plugin.
*
* @link https://polkurier.pl
* @since 1.0.0
*
* @package Polkurier
* @subpackage Polkurier/admin/partials
*/
require_once (dirname(__FILE__).'/../../includes/PolkurierPackage.php');
$packages = get_option('polkurier_packages');
if ($_SERVER['REQUEST_METHOD']=='POST') {
// zapisujemy informacje o nowej templatce
$package = new PolkurierPackage();
$package->width = $_POST['polkurier_width'];
$package->height = $_POST['polkurier_height'];
$package->depth = $_POST['polkurier_depth'];
$package->weight = $_POST['polkurier_weight'];
$package->count = $_POST['polkurier_count'];
$package->nonstandard = isset($_POST['polkurier_nonstandard']);
$package->type = $_POST['polkurier_type'];
$api = $this->get_polkurier_api();
$data = $api->orderValuation($package);
?><h2>Wycena - <?php echo $package ?></h2>
<ul>
<?php if (empty($data)): ?>
<li><?php echo $api->lastError ?></li>
<?php endif; ?>
<?php foreach ($data as $carrier): ?>
<li><strong><?php echo $carrier["serviceName"] ?></strong> - netto: <?php echo $carrier["netprice"] ?>, brutto <?php echo $carrier["grossprice"] ?></li>
<?php endforeach; ?>
<?php
if( wp_get_referer() )
echo '<a href="'.wp_get_referer().'" >Wstecz</a>';
} else {
?>
<form action="admin.php?page=polkurier_valuation" method="post">
<h2>Wycena paczki</h2>
<table class="form-table">
<tbody>
<tr>
<th scope="row"><label for="polkurier_height">Wysokość (cm)</label></th>
<td><input required type="number" name="polkurier_height" id="polkurier_height" value=""> </td>
</tr>
<tr>
<th scope="row"><label for="polkurier_width">Szerokość (cm)</label></th>
<td><input required type="number" name="polkurier_width" id="polkurier_width" value=""> </td>
</tr>
<tr>
<th scope="row"><label for="polkurier_depth">Głębokość (cm)</label></th>
<td><input required type="number" name="polkurier_depth" id="polkurier_depth" value=""> </td>
</tr>
<tr>
<th scope="row"><label for="polkurier_weight">Waga (kg)</label></th>
<td><input required type="number" name="polkurier_weight" id="polkurier_weight" value=""> </td>
</tr>
<tr>
<th scope="row"><label for="polkurier_count">Ilość</label></th>
<td><input required type="number" name="polkurier_count" id="polkurier_count" value=""> </td>
</tr>
<tr>
<th scope="row"><label for="polkurier_nonstandard">Niestandardowa</label></th>
<td><input type="checkbox" name="polkurier_nonstandard" id="polkurier_nonstandard" value="1"> </td>
</tr>
<tr>
<th scope="row"><label for="polkurier_type">Typ przesyłki</label></th>
<td>
<input type="radio" name="polkurier_type" id="polkurier_type_1" value="koperta">
<label for="polkurier_type_1">koperta</label><br/>
<input type="radio" name="polkurier_type" id="polkurier_type_2" value="paczka" checked>
<label for="polkurier_type_2">paczka</label><br/>
<input type="radio" name="polkurier_type" id="polkurier_type_3" value="paleta">
<label for="polkurier_type_3">paleta</label>
</td>
</tr>
</tbody></table>
<?php submit_button("Wyceń"); ?>
</form>
<?php } ?>