1 | <? |
---|
2 | require_once( "db.php" ); |
---|
3 | |
---|
4 | class Ship { |
---|
5 | |
---|
6 | function Ship( $id = 0 ) |
---|
7 | { |
---|
8 | $this->id_ = $id; |
---|
9 | } |
---|
10 | |
---|
11 | function getID() |
---|
12 | { |
---|
13 | return $this->id_; |
---|
14 | } |
---|
15 | |
---|
16 | function getName() |
---|
17 | { |
---|
18 | if ( $this->shipname_ == "" ) $this->execQuery(); |
---|
19 | return $this->shipname_; |
---|
20 | } |
---|
21 | |
---|
22 | function getClass() |
---|
23 | { |
---|
24 | if ( !$this->shipclass_ ) $this->execQuery(); |
---|
25 | return $this->shipclass_; |
---|
26 | } |
---|
27 | |
---|
28 | function getTechLevel() |
---|
29 | { |
---|
30 | $this->execQuery(); |
---|
31 | return $this->row_['shp_techlevel']; |
---|
32 | } |
---|
33 | |
---|
34 | function getImage( $size ) |
---|
35 | { |
---|
36 | if ( !$this->externalid_ ) $this->execQuery(); |
---|
37 | return IMG_URL."/ships/".$size."_".$size."/" |
---|
38 | .$this->externalid_.".png"; |
---|
39 | } |
---|
40 | |
---|
41 | function setName( $shipname ) |
---|
42 | { |
---|
43 | $this->shipname_ = $shipname; |
---|
44 | } |
---|
45 | |
---|
46 | function setClass( $shipclass ) |
---|
47 | { |
---|
48 | $this->shipclass_ = $shipclass; |
---|
49 | } |
---|
50 | |
---|
51 | function execQuery() |
---|
52 | { |
---|
53 | if ( !$this->qry_ ) { |
---|
54 | $this->qry_ = new DBQuery(); |
---|
55 | |
---|
56 | $this->sql_ = "select * |
---|
57 | from kb3_ships shp, kb3_ship_classes scl |
---|
58 | where shp_id = ".$this->id_." |
---|
59 | and shp.shp_class = scl.scl_id"; |
---|
60 | |
---|
61 | $this->qry_->execute( $this->sql_ ); |
---|
62 | $row = $this->qry_->getRow(); |
---|
63 | $this->shipname_ = $row['shp_name']; |
---|
64 | $this->shipclass_ = new ShipClass( $row['scl_id'] ); |
---|
65 | $this->shiptechlevel_ = $row['shp_techlevel']; |
---|
66 | $this->externalid_ = $row['shp_externalid']; |
---|
67 | } |
---|
68 | } |
---|
69 | |
---|
70 | function lookup( $name ) |
---|
71 | { |
---|
72 | $qry = new DBQuery(); |
---|
73 | $qry->execute( "select * |
---|
74 | from kb3_ships |
---|
75 | where shp_name = '".slashfix( $name )."'" ); |
---|
76 | |
---|
77 | $row = $qry->getRow(); |
---|
78 | if ( $row['shp_id'] ) $this->id_ = $row['shp_id']; |
---|
79 | } |
---|
80 | } |
---|
81 | |
---|
82 | class ShipClass |
---|
83 | { |
---|
84 | function ShipClass( $id = 0 ) |
---|
85 | { |
---|
86 | if ( !$id ) $id = 0; |
---|
87 | $this->id_ = $id; |
---|
88 | |
---|
89 | $this->qry_ = new DBQuery(); |
---|
90 | } |
---|
91 | |
---|
92 | function getID() |
---|
93 | { |
---|
94 | return $this->id_; |
---|
95 | } |
---|
96 | |
---|
97 | function getName() |
---|
98 | { |
---|
99 | if ( $this->name_ == "" ) $this->execQuery(); |
---|
100 | return $this->name_; |
---|
101 | } |
---|
102 | |
---|
103 | function getValue() |
---|
104 | { |
---|
105 | if ( !$this->value_ ) $this->execQuery(); |
---|
106 | return round( $this->value_ / 1000000, 2 ); |
---|
107 | } |
---|
108 | |
---|
109 | function getPoints() |
---|
110 | { |
---|
111 | if ( !$this->points_ ) $this->execQuery(); |
---|
112 | return $this->points_; |
---|
113 | } |
---|
114 | |
---|
115 | function setName( $name ) |
---|
116 | { |
---|
117 | $this->name_ = $name; |
---|
118 | } |
---|
119 | |
---|
120 | function setValue( $value ) |
---|
121 | { |
---|
122 | $this->value_ = $value; |
---|
123 | } |
---|
124 | |
---|
125 | function getValueIndicator() |
---|
126 | { |
---|
127 | $value = $this->getValue(); |
---|
128 | |
---|
129 | if ( $value >= 0 && $value <= 1 ) |
---|
130 | $color = "gray"; |
---|
131 | elseif ( $value > 1 && $value <= 15 ) |
---|
132 | $color = "blue"; |
---|
133 | elseif ( $value > 15 && $value <= 25 ) |
---|
134 | $color = "green"; |
---|
135 | elseif ( $value > 25 && $value <= 40 ) |
---|
136 | $color = "yellow"; |
---|
137 | elseif ( $value > 40 && $value <= 80 ) |
---|
138 | $color = "red"; |
---|
139 | elseif ( $value > 80 && $value <= 250 ) |
---|
140 | $color = "orange"; |
---|
141 | elseif ( $value > 250 ) |
---|
142 | $color = "purple"; |
---|
143 | |
---|
144 | return IMG_URL."/ships/ship-".$color.".gif"; |
---|
145 | } |
---|
146 | |
---|
147 | function execQuery() |
---|
148 | { |
---|
149 | if ( !$this->qry_->executed_ ) { |
---|
150 | |
---|
151 | $sql = "select * |
---|
152 | from kb3_ship_classes |
---|
153 | where scl_id = ".$this->id_; |
---|
154 | |
---|
155 | $this->qry_->execute( $sql ); |
---|
156 | $row = $this->qry_->getRow(); |
---|
157 | |
---|
158 | $this->name_ = $row['scl_class']; |
---|
159 | $this->value_ = $row['scl_value']; |
---|
160 | $this->points_ = $row['scl_points']; |
---|
161 | } |
---|
162 | } |
---|
163 | } |
---|
164 | ?> |
---|