product_form.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php /** @noinspection PhpUnhandledExceptionInspection */
  2. namespace App;
  3. use App\Helpers\HtmlHelper;
  4. /**
  5. * @var string $title
  6. * @var Product $product
  7. */
  8. $core = Core::getInstance();
  9. $user = $core->getUser();
  10. $suppliers = Supplier::getAll();
  11. $request = Request::fromRequest();
  12. if($product->isNew()) {
  13. $supplier_id = $request->int("supplier_id");
  14. }
  15. else {
  16. $supplier_id = $product->supplier_id;
  17. }
  18. ?>
  19. <h3><?=htmlspecialchars($title)?></h3>
  20. <form method="post" enctype="multipart/form-data">
  21. <?php
  22. $user->insertCsrfToken();
  23. ?>
  24. <div class="mb-3">
  25. <label class="form-label" for="supplier-id"><?=htmlspecialchars(__("Supplier"))?></label>
  26. <select class="form-select" name="supplier_id" id="supplier-id" required>
  27. <option value=""><?=htmlspecialchars(__("Select Supplier"))?></option>
  28. <?php
  29. HtmlHelper::renderOptions(Supplier::getOptions(), $supplier_id);
  30. ?>
  31. </select>
  32. </div>
  33. <div class="mb-3">
  34. <label class="form-label" for="name"><?=htmlspecialchars(__("Name"))?></label>
  35. <input class="form-control" type="text" id="name" name="name" placeholder="<?=htmlspecialchars(__("Type name"))?>" value="<?=htmlspecialchars($product->name)?>" maxlength="255" required />
  36. </div>
  37. <div class="mb-3">
  38. <label class="form-label" for="sku"><?=htmlspecialchars(__("SKU"))?></label>
  39. <input class="form-control" type="text" id="sku" name="sku" placeholder="<?=htmlspecialchars(__("Type SKU"))?>" value="<?=htmlspecialchars($product->sku)?>" maxlength="255" required />
  40. </div>
  41. <div class="row">
  42. <div class="col-6">
  43. <div class="mb-3">
  44. <label class="form-label" for="type"><?=htmlspecialchars(__("Type"))?></label>
  45. <select class="form-select" name="type" id="type" required>
  46. <?php
  47. foreach(Product::getTypeOptions() as $value => $display) {
  48. ?>
  49. <option value="<?=$value?>" <?=Html::selected($value, $product->type)?>>
  50. <?=htmlspecialchars($display)?>
  51. </option>
  52. <?php
  53. }
  54. ?>
  55. </select>
  56. </div>
  57. </div>
  58. <div class="col-6">
  59. <div class="mb-3">
  60. <label class="form-label" for="price"><?=htmlspecialchars(__("Price"))?></label>
  61. <input class="form-control" type="number" id="price" name="price" placeholder="<?=htmlspecialchars(__("Type price"))?>" value="<?=htmlspecialchars($product->price)?>" min="0" max="999999.99" step="any" required />
  62. </div>
  63. </div>
  64. </div>
  65. <div class="mb-3">
  66. <label class="form-label" for="url"><?=htmlspecialchars(__("URL"))?></label>
  67. <input class="form-control" type="url" name="url" id="url" placeholder="<?=htmlspecialchars(__("Type URL"))?>" value="<?=htmlspecialchars($product->url)?>" />
  68. </div>
  69. <div class="mb-3">
  70. <label class="form-label" for="brochure">
  71. <?=htmlspecialchars(__("Upload Brochure (PDF)"))?>
  72. </label>
  73. <input class="form-control" type="file" name="brochure" id="brochure" accept="application/pdf" />
  74. <?php
  75. if($product->hasBrochure()) {
  76. ?>
  77. <div class="form-check">
  78. <input class="form-check-input" type="checkbox" name="delete_brochure" id="delete-brochure" value="1" />
  79. <label class="form-check-label" for="delete-brochure"><?=htmlspecialchars(__("Delete Brochure"))?></label>
  80. </div>
  81. <?php
  82. }
  83. ?>
  84. </div>
  85. <div class="mb-3">
  86. <button class="btn btn-primary" type="submit" name="submit" value="1">
  87. <?=htmlspecialchars(__("Submit"))?>
  88. </button>
  89. </div>
  90. </form>