From 4bd6ed58a02d61fbd0c7fd9e704c1aec167906f1 Mon Sep 17 00:00:00 2001
From: "Igor Barkov [iwork]" <lopar.4ever@gmail.com>
Date: Tue, 12 Feb 2019 20:31:23 +0200
Subject: [PATCH] main inventory shown as class, not function

---
 classes/InventoryItem.php |  2 +-
 fshop.php                 |  8 ++---
 gotzamok.php              |  4 +--
 main.php                  | 72 +++++++++++++++++++++++++++++++++++----
 4 files changed, 72 insertions(+), 14 deletions(-)

diff --git a/classes/InventoryItem.php b/classes/InventoryItem.php
index c7c1667..04f126f 100644
--- a/classes/InventoryItem.php
+++ b/classes/InventoryItem.php
@@ -34,7 +34,7 @@ NAME;
     }
 
     /**
-     * Для кнопок управления под картинкой прелмета в зависимости от ситуации.
+     * Для кнопок управления под картинкой предмета в зависимости от ситуации.
      */
     public function printControls()
     {
diff --git a/fshop.php b/fshop.php
index 27ae2d1..98b7a7b 100644
--- a/fshop.php
+++ b/fshop.php
@@ -973,8 +973,8 @@ if ($_POST['docompare']) {
                                             букет</A>
                                         </TD>
                                         <?php
-                                        echo "<TD valign=top>";
-                                        showitem($row);
+                                        echo "<TD valign=top> Тут был showitem($row);";
+
                                         echo "</TD></TR>";
                                     }
                                 }
@@ -986,8 +986,8 @@ if ($_POST['docompare']) {
                                         <BR><A HREF="fshop.php?otdel=<?= $_GET['otdel'] ?>&set=<?= $row['id'] ?>&sid=">купить</A>
                                         </TD>
                                         <?php
-                                        echo "<TD valign=top>";
-                                        showitem($row);
+                                        echo "<TD valign=top> Тут был showitem($row);";
+
                                         echo "</TD></TR>";
                                     }
                                 }
diff --git a/gotzamok.php b/gotzamok.php
index 2cc53ca..285b9e0 100644
--- a/gotzamok.php
+++ b/gotzamok.php
@@ -154,7 +154,7 @@ if ($castleOwners['id'] == $user['klan']) { ?>
                                         <?php else: $status = 'Вы не можете забрать эту вещь из арсенала.';
                                         endif; ?>
                                     </TD>
-                                    <TD valign=top> <?php showitem($row); ?> </TD>
+                                    <TD valign=top> Тут был showitem($row); </TD>
                                 </TR>
                             <?php endwhile; ?>
                         </table>
@@ -168,7 +168,7 @@ if ($castleOwners['id'] == $user['klan']) { ?>
                                         <IMG SRC="i/sh/<?= $row['img'] ?>">
                                         <BR><A HREF="?add=<?= $row['id'] ?>&sid=&sale=1">сдать в арсенал</A>
                                     </TD>
-                                    <TD valign=top> <?php showitem($row); ?> </TD>
+                                    <TD valign=top> Тут был showitem($row); </TD>
                                 </TR>
                             <?php endwhile; ?>
                         </table>
diff --git a/main.php b/main.php
index 5bf6c62..b8312c4 100644
--- a/main.php
+++ b/main.php
@@ -2167,29 +2167,87 @@ if (input::get('edit')) {
                         </tr>
                     <?php endif;
                     if ($_SESSION['razdel'] == null) {
-                        $data = db::c()->query('SELECT * FROM `inventory` WHERE `owner` = ?i AND `dressed` = 0 AND (`type` < 12 OR `type` = 22 OR `type` = 23 OR `type` = 24) AND `setsale` = 0 ORDER BY `update` DESC', $user['id']);
+                        $data = db::c()->query('SELECT `inventory`.*,
+       `magic`.`name` AS `magic_name`,
+       `magic`.`chanse` AS `magic_chanse`,
+       `magic`.`time` AS `magic_time`,
+       `magic`.`file` AS `magic_file`,
+       `magic`.`targeted` AS `magic_targeted`,
+       `magic`.`needcharge` AS `magic_needcharge`,
+       `magic`.`img` AS `magic_img` FROM `inventory` LEFT JOIN `magic` ON `magic` = `magic`.`id` WHERE `owner` = ?i AND `dressed` = 0 AND (`type` < 12 OR `type` = 22 OR `type` = 23 OR `type` = 24) AND `setsale` = 0 ORDER BY `update` DESC', $user['id']);
                     }
                     if ($_SESSION['razdel'] == 1) {
-                        $data = db::c()->query('SELECT * FROM `inventory` WHERE `owner` = ?i AND `dressed` = 0 AND `type` = 12 AND `setsale` = 0 ORDER BY `update` DESC', $user['id']);
+                        $data = db::c()->query('SELECT `inventory`.*,
+       `magic`.`name` AS `magic_name`,
+       `magic`.`chanse` AS `magic_chanse`,
+       `magic`.`time` AS `magic_time`,
+       `magic`.`file` AS `magic_file`,
+       `magic`.`targeted` AS `magic_targeted`,
+       `magic`.`needcharge` AS `magic_needcharge`,
+       `magic`.`img` AS `magic_img` FROM `inventory` LEFT JOIN `magic` ON `magic` = `magic`.`id` WHERE `owner` = ?i AND `dressed` = 0 AND `type` = 12 AND `setsale` = 0 ORDER BY `update` DESC', $user['id']);
                     }
                     if ($_SESSION['razdel'] == 2) {
-                        $data = db::c()->query('SELECT * FROM `inventory` WHERE `owner` = ?i AND `dressed` = 0 AND (`type` > 12 OR `type` != 22 OR `type` != 23 OR `type` != 24) AND `setsale` = 0 ORDER BY `update` DESC', $user['id']);
+                        $data = db::c()->query('SELECT `inventory`.*,
+       `magic`.`name` AS `magic_name`,
+       `magic`.`chanse` AS `magic_chanse`,
+       `magic`.`time` AS `magic_time`,
+       `magic`.`file` AS `magic_file`,
+       `magic`.`targeted` AS `magic_targeted`,
+       `magic`.`needcharge` AS `magic_needcharge`,
+       `magic`.`img` AS `magic_img` FROM `inventory` LEFT JOIN `magic` ON `magic` = `magic`.`id` WHERE `owner` = ?i AND `dressed` = 0 AND (`type` > 12 OR `type` != 22 OR `type` != 23 OR `type` != 24) AND `setsale` = 0 ORDER BY `update` DESC', $user['id']);
                     }
                     if ($_SESSION['razdel'] == 3) {
-                        $data = db::c()->query('SELECT * FROM `inventory` WHERE `owner` = ?i AND `dressed` = 0 AND `type` >= 80 AND `type` <= 89 AND `setsale` = 0 ORDER BY `update` ASC', $user['id']);
+                        $data = db::c()->query('SELECT `inventory`.*,
+       `magic`.`name` AS `magic_name`,
+       `magic`.`chanse` AS `magic_chanse`,
+       `magic`.`time` AS `magic_time`,
+       `magic`.`file` AS `magic_file`,
+       `magic`.`targeted` AS `magic_targeted`,
+       `magic`.`needcharge` AS `magic_needcharge`,
+       `magic`.`img` AS `magic_img` FROM `inventory` LEFT JOIN `magic` ON `magic` = `magic`.`id` WHERE `owner` = ?i AND `dressed` = 0 AND `type` >= 80 AND `type` <= 89 AND `setsale` = 0 ORDER BY `update` ASC', $user['id']);
                     }
                     if ($_SESSION['razdel'] == 4) {
-                        $data = db::c()->query('SELECT * FROM `inventory` WHERE `owner` = ?i AND `dressed` = 0 AND `type` = 200 AND `setsale` = 0 ORDER BY `update` ASC', $user['id']);
+                        $data = db::c()->query('SELECT `inventory`.*,
+       `magic`.`name` AS `magic_name`,
+       `magic`.`chanse` AS `magic_chanse`,
+       `magic`.`time` AS `magic_time`,
+       `magic`.`file` AS `magic_file`,
+       `magic`.`targeted` AS `magic_targeted`,
+       `magic`.`needcharge` AS `magic_needcharge`,
+       `magic`.`img` AS `magic_img` FROM `inventory` LEFT JOIN `magic` ON `magic` = `magic`.`id` WHERE `owner` = ?i AND `dressed` = 0 AND `type` = 200 AND `setsale` = 0 ORDER BY `update` ASC', $user['id']);
                     }
                     if ($_SESSION['razdel'] == 5) {
-                        $data = db::c()->query('SELECT * FROM `inventory` WHERE `owner` = ?i AND `dressed` = 0 AND `type` = 199 AND `setsale` = 0 ORDER BY `update` ASC', $user['id']);
+                        $data = db::c()->query('SELECT `inventory`.*,
+       `magic`.`name` AS `magic_name`,
+       `magic`.`chanse` AS `magic_chanse`,
+       `magic`.`time` AS `magic_time`,
+       `magic`.`file` AS `magic_file`,
+       `magic`.`targeted` AS `magic_targeted`,
+       `magic`.`needcharge` AS `magic_needcharge`,
+       `magic`.`img` AS `magic_img` FROM `inventory` LEFT JOIN `magic` ON `magic` = `magic`.`id` WHERE `owner` = ?i AND `dressed` = 0 AND `type` = 199 AND `setsale` = 0 ORDER BY `update` ASC', $user['id']);
                     }
+
                     $groupNum = [];
                     $viewInventory = [];
                     $getItems = [];
                     $row = [];
+                    $iteminfo =[];
                     #while ($row = $data->fetch_assoc()) showitem($row, null, "edit=1&razdel=$_SESSION[razdel]");
-                    while ($row = $data->fetch_assoc()) showitem($row);
+                    #while ($row = $data->fetch_assoc()) showitem($row);
+                    while ($row = $data->fetch_assoc()) $iteminfo[] = new InventoryItem($row);
+
+                    echo "<table width='100%'>";
+                    foreach ($iteminfo as $ii) {
+                        echo "<tr><td bgcolor='#d3d3d3'>";
+                        $ii->printImage();
+                        $ii->printControls();
+                        echo "</td>";
+                        echo "<td bgcolor='#d3d3d3'>";
+                        $ii->printInfo();
+                        echo "</td></tr>";
+                    }
+                    echo "</table>";
+
                     if ($viewInventory and $getItems) {
                         foreach ($viewInventory as $viewCategiryes) {
                             echo $viewCategiryes['header'];