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