1 | <?php |
---|
2 | define('DGM_TECHLEVEL', 422); |
---|
3 | |
---|
4 | class Item |
---|
5 | { |
---|
6 | function Item($id = 0) |
---|
7 | { |
---|
8 | $this->id_ = $id; |
---|
9 | } |
---|
10 | |
---|
11 | function getID() |
---|
12 | { |
---|
13 | return $this->id_; |
---|
14 | } |
---|
15 | |
---|
16 | function getName() |
---|
17 | { |
---|
18 | $this->execQuery(); |
---|
19 | if (DB_USE_CCP) |
---|
20 | { |
---|
21 | return $this->row_['typeName']; |
---|
22 | } |
---|
23 | return $this->row_['itm_name']; |
---|
24 | } |
---|
25 | |
---|
26 | function getIcon($size = 32) |
---|
27 | { |
---|
28 | $this->execQuery(); |
---|
29 | global $smarty; |
---|
30 | |
---|
31 | // cat 18 are combat drones |
---|
32 | if ($this->row_['itt_cat'] == 18) |
---|
33 | { |
---|
34 | $img = IMG_URL.'/drones/'.$size.'_'.$size.'/'.$this->row_['itm_externalid'].'.png'; |
---|
35 | } |
---|
36 | // cat 6 are ships (destroyed in cargo) |
---|
37 | elseif ($this->row_['itt_cat'] == 6) |
---|
38 | { |
---|
39 | $img = IMG_URL.'/ships/'.$size.'_'.$size.'/'.$this->row_['itm_externalid'].'.png'; |
---|
40 | } |
---|
41 | else |
---|
42 | { |
---|
43 | // fix for new db structure, just make sure old clients dont break |
---|
44 | if (!strstr($this->row_['itm_icon'], 'icon')) |
---|
45 | { |
---|
46 | $this->row_['itm_icon'] = 'icon'.$this->row_['itm_icon']; |
---|
47 | } |
---|
48 | $img = IMG_URL.'/items/'.$size.'_'.$size.'/'.$this->row_['itm_icon'].'.png'; |
---|
49 | } |
---|
50 | |
---|
51 | if (substr($this->getName(), strlen($this->getName()) - 2, 2) == "II" || $this->row_['itm_techlevel'] == 2) |
---|
52 | { |
---|
53 | $icon .= IMG_URL.'/items/32_32/t2.gif'; |
---|
54 | } |
---|
55 | else |
---|
56 | { |
---|
57 | $icon = IMG_URL.'/items/32_32/blank.gif'; |
---|
58 | } |
---|
59 | |
---|
60 | $smarty->assign('img', $img); |
---|
61 | $smarty->assign('icon', $icon); |
---|
62 | return $smarty->fetch(get_tpl('icon')); |
---|
63 | } |
---|
64 | |
---|
65 | function getSlot() |
---|
66 | { |
---|
67 | $this->execQuery(); |
---|
68 | return $this->row_['itt_slot']; |
---|
69 | } |
---|
70 | |
---|
71 | function execQuery() |
---|
72 | { |
---|
73 | if (!isset($this->qry_)) |
---|
74 | { |
---|
75 | $this->qry_ = new DBQuery(); |
---|
76 | } |
---|
77 | |
---|
78 | if (!$this->qry_->executed_) |
---|
79 | { |
---|
80 | if (!$this->id_) |
---|
81 | { |
---|
82 | return false; |
---|
83 | } |
---|
84 | $this->sql_ = "select * |
---|
85 | from kb3_items |
---|
86 | left join kb3_item_types on itm_type = itt_id |
---|
87 | where itm_id = '".$this->id_."'"; |
---|
88 | |
---|
89 | if (DB_USE_CCP) |
---|
90 | { |
---|
91 | // new |
---|
92 | $this->sql_ = "select inv.*, kb3_item_types.*, dga.value as techlevel, itp.price |
---|
93 | from kb3_invtypes inv |
---|
94 | left join kb3_dgmtypeattributes dga on dga.typeID=inv.typeID and dga.attributeID=".DGM_TECHLEVEL." |
---|
95 | left join kb3_item_price itp on itp.typeID=inv.typeID |
---|
96 | left join kb3_item_types on groupID=itt_id |
---|
97 | where inv.typeID = '".$this->id_."'"; |
---|
98 | } |
---|
99 | $this->qry_->execute($this->sql_); |
---|
100 | $this->row_ = $this->qry_->getRow(); |
---|
101 | if (DB_USE_CCP) |
---|
102 | { |
---|
103 | $this->row_['itm_icon'] = $this->row_['icon']; |
---|
104 | $this->row_['itm_techlevel'] = $this->row_['techlevel']; |
---|
105 | $this->row_['itm_externalid'] = $this->row_['typeID']; |
---|
106 | $this->row_['itm_value'] = $this->row_['price']; |
---|
107 | } |
---|
108 | } |
---|
109 | } |
---|
110 | |
---|
111 | function lookup($name) |
---|
112 | { |
---|
113 | $name = trim($name); |
---|
114 | $qry = new DBQuery(); |
---|
115 | $query = "select * from kb3_items itm |
---|
116 | where itm_name = '".slashfix($name)."'"; |
---|
117 | if (DB_USE_CCP) |
---|
118 | { |
---|
119 | $query = "select *,typeID as itm_id from kb3_invtypes itm |
---|
120 | where typeName = '".slashfix($name)."'"; |
---|
121 | } |
---|
122 | $qry->execute($query); |
---|
123 | $row = $qry->getRow(); |
---|
124 | if (!isset($row['itm_id'])) |
---|
125 | { |
---|
126 | if (config::get('adapt_items') && DB_USE_CCP !== true) |
---|
127 | { |
---|
128 | // if the item is a tec2 we likely have the tec1 |
---|
129 | if (substr($name, -2, 2) == 'II') |
---|
130 | { |
---|
131 | $qry->execute("select * from kb3_items itm |
---|
132 | where itm_name = '".slashfix(substr($name,0,-1))."'"); |
---|
133 | $row = $qry->getRow(); |
---|
134 | if (!$row['itm_type']) |
---|
135 | { |
---|
136 | return false; |
---|
137 | } |
---|
138 | $qry->execute("INSERT INTO kb3_items (itm_name,itm_volume,itm_type,itm_externalid,itm_techlevel,itm_icon) |
---|
139 | VALUES ('".slashfix($name)."','".$row['itm_volume']."','".$row['itm_type']."','".$row['itm_externalid']."','2','".$row['itm_icon']."')"); |
---|
140 | } |
---|
141 | else |
---|
142 | { |
---|
143 | // no idea what this is, insert as 'Temp' |
---|
144 | $qry->execute("INSERT INTO kb3_items (itm_name,itm_type) |
---|
145 | VALUES ('".slashfix($name)."','721')"); |
---|
146 | } |
---|
147 | $row['itm_id'] = $qry->getInsertID(); |
---|
148 | } |
---|
149 | else |
---|
150 | { |
---|
151 | // that item doesnt exist or is misspelled |
---|
152 | return false; |
---|
153 | } |
---|
154 | } |
---|
155 | $this->id_ = $row['itm_id']; |
---|
156 | } |
---|
157 | |
---|
158 | function get_item_id($name) |
---|
159 | { |
---|
160 | $qry = new DBQuery(); |
---|
161 | $query = "select * |
---|
162 | from kb3_items |
---|
163 | where itm_name = '".slashfix($name)."'"; |
---|
164 | if (DB_USE_CCP) |
---|
165 | { |
---|
166 | $query = "select *,typeID as itm_id |
---|
167 | from kb3_items |
---|
168 | where typeName = '".slashfix($name)."'"; |
---|
169 | } |
---|
170 | $qry->execute($query); |
---|
171 | |
---|
172 | $row = $qry->getRow(); |
---|
173 | if ($row['itm_id']) return $row['itm_id']; |
---|
174 | } |
---|
175 | } |
---|
176 | ?> |
---|