Files
2026-04-28 15:13:50 +02:00

109 lines
3.6 KiB
PHP
Raw Permalink Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
class PolkurierPackage
{
public $id;
public $height;
public $width;
public $depth;
public $weight;
public $count = 1;
public $nonstandard = false;
public $type = "paczka"; // list|paleta|paczka
public function __toString()
{
return $this->type . " (wymiary:" . $this->height . "x" . $this->width . "x" . $this->depth . "cm, waga: {$this->weight}kg, ilość: {$this->count})" . ($this->nonstandard ? " niestandardowa" : null);
}
public function asTableRow()
{
return sprintf("<td>%s</td><td>%s</td><td>%s</td><td>%d</td><td>%s</td>",
$this->type,
$this->height . "x" . $this->width . "x" . $this->depth . "cm",
$this->weight . "kg",
$this->count,
$this->nonstandard ? "tak" : "nie"
);
}
public function getType()
{
switch ($this->type) {
case "paczka":return "box";
case "koperta":return "envelope";
case "paleta":return "palette";
}
}
public static function getPackageById($id)
{
$opt = get_option('polkurier_packages');
if (isset($opt[$id])) {
$package = $opt[$id];
$package->id = $id;
return $package;
} else {
return null;
}
}
public function renderForm()
{
if ($this->id || $this->id == 0) {
echo '<input type="hidden" name="polkurier_id" value="' . $this->id . '"/>';
}
?>
<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="<?php echo $this->height ?>"> </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="<?php echo $this->width ?>"> </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="<?php echo $this->depth ?>"> </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="<?php echo $this->weight ?>"> </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="<?php echo $this->count ?>"> </td>
</tr>
<tr>
<th scope="row"><label for="polkurier_nonstandard">Niestandardowa</label></th>
<td><input type="checkbox" name="polkurier_nonstandard" id="polkurier_nonstandard" <?php if ($this->nonstandard) {
echo "checked";
}
?> 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" <?php if ($this->type == "koperta") {
echo "checked";
}
?> >
<label for="polkurier_type_1">koperta</label><br/>
<input type="radio" name="polkurier_type" id="polkurier_type_2" value="paczka" <?php if ($this->type == "paczka") {
echo "checked";
}
?> >
<label for="polkurier_type_2">paczka</label><br/>
<input type="radio" name="polkurier_type" id="polkurier_type_3" value="paleta" <?php if ($this->type == "paleta") {
echo "checked";
}
?> >
<label for="polkurier_type_3">paleta</label>
</td>
</tr>
</tbody></table><?php
}
}