1 | <?php |
---|
2 | require_once("db.php"); |
---|
3 | |
---|
4 | class Item |
---|
5 | { |
---|
6 | function Item($id = 0) |
---|
7 | { |
---|
8 | $this->id_ = $id; |
---|
9 | $this->qry_ = new DBQuery(); |
---|
10 | } |
---|
11 | |
---|
12 | function getID() |
---|
13 | { |
---|
14 | return $this->id_; |
---|
15 | } |
---|
16 | |
---|
17 | function getName() |
---|
18 | { |
---|
19 | $this->execQuery(); |
---|
20 | // if (!$this->row_['itm_name']) |
---|
21 | // { |
---|
22 | // return $this->id_; |
---|
23 | // } |
---|
24 | return $this->row_['itm_name']; |
---|
25 | } |
---|
26 | |
---|
27 | |
---|
28 | |
---|
29 | function getIcon($size = 32) |
---|
30 | { |
---|
31 | $this->execQuery(); |
---|
32 | global $smarty; |
---|
33 | |
---|
34 | // slot 6 is dronebay |
---|
35 | if ($this->row_['itt_slot'] == 6) |
---|
36 | { |
---|
37 | $img = IMG_URL.'/drones/'.$size.'_'.$size.'/'.$this->row_['itm_externalid'].'.png'; |
---|
38 | } |
---|
39 | else |
---|
40 | { |
---|
41 | // fix for new db structure, just make sure old clients dont break |
---|
42 | if (!strstr($this->row_['itm_icon'], 'icon')) |
---|
43 | { |
---|
44 | $this->row_['itm_icon'] = 'icon'.$this->row_['itm_icon']; |
---|
45 | } |
---|
46 | $img = IMG_URL.'/items/'.$size.'_'.$size.'/'.$this->row_['itm_icon'].'.png'; |
---|
47 | } |
---|
48 | |
---|
49 | if (substr($this->getName(), strlen($this->getName()) - 2, 2) == "II") |
---|
50 | { |
---|
51 | $icon .= IMG_URL.'/items/32_32/t2.gif'; |
---|
52 | } |
---|
53 | else |
---|
54 | { |
---|
55 | $icon= IMG_URL.'/items/32_32/blank.gif'; |
---|
56 | } |
---|
57 | |
---|
58 | $smarty->assign('img', $img); |
---|
59 | $smarty->assign('icon', $icon); |
---|
60 | return $smarty->fetch('icon.tpl'); |
---|
61 | } |
---|
62 | |
---|
63 | function getSlot() |
---|
64 | { |
---|
65 | $this->execQuery(); |
---|
66 | return $this->row_['itt_slot']; |
---|
67 | } |
---|
68 | |
---|
69 | function execQuery() |
---|
70 | { |
---|
71 | if (!$this->qry_->executed_) |
---|
72 | { |
---|
73 | $this->sql_ = "select * |
---|
74 | from kb3_items, kb3_item_types |
---|
75 | where itm_id = ".$this->id_." |
---|
76 | and itm_type = itt_id"; |
---|
77 | $this->qry_->execute($this->sql_) or die($this->qry_->getErrorMsg()); |
---|
78 | $this->row_ = $this->qry_->getRow(); |
---|
79 | } |
---|
80 | } |
---|
81 | |
---|
82 | function lookup($name) |
---|
83 | { |
---|
84 | $qry = new DBQuery(); |
---|
85 | $qry->execute("select * from kb3_items itm |
---|
86 | where itm_name = '".slashfix($name)."'"); |
---|
87 | $row = $qry->getRow(); |
---|
88 | if (!isset($row['itm_id'])) |
---|
89 | { |
---|
90 | global $config; |
---|
91 | if ($config->getConfig('adapt_items')) |
---|
92 | { |
---|
93 | // if the item is a tec2 we likely have the tec1 |
---|
94 | if (substr($name, -2, 2) == 'II') |
---|
95 | { |
---|
96 | $qry->execute("select * from kb3_items itm |
---|
97 | where itm_name = '".slashfix(substr($name,0,-1))."'"); |
---|
98 | $row = $qry->getRow(); |
---|
99 | $qry->execute("INSERT INTO kb3_items (itm_name,itm_volume,itm_type,itm_externalid,itm_techlevel, itm_icon) |
---|
100 | VALUES ('".slashfix($name)."','".$row['itm_volume']."','".$row['itm_type']."','".$row['itm_externalid']."','2','".$row['itm_icon']."')"); |
---|
101 | $this->id_ = $qry->getInsertID(); |
---|
102 | } |
---|
103 | else |
---|
104 | { |
---|
105 | // no idea what this is, insert as 'Temp' |
---|
106 | $qry->execute("INSERT INTO kb3_items (itm_name,itm_type) |
---|
107 | VALUES ('".slashfix($name)."','721')"); |
---|
108 | $this->id_ = $qry->getInsertID(); |
---|
109 | } |
---|
110 | } |
---|
111 | } |
---|
112 | $this->id_ = $row['itm_id']; |
---|
113 | } |
---|
114 | |
---|
115 | function get_item_id($name) |
---|
116 | { |
---|
117 | $qry = new DBQuery(); |
---|
118 | $qry->execute("select * |
---|
119 | from kb3_items |
---|
120 | where itm_name = '".slashfix($name)."'"); |
---|
121 | |
---|
122 | $row = $qry->getRow(); |
---|
123 | if ($row['itm_id']) return $row['itm_id']; |
---|
124 | } |
---|
125 | } |
---|
126 | ?> |
---|