1 | <?php |
---|
2 | require_once('common/includes/class.contract.php'); |
---|
3 | require_once('common/includes/class.http.php'); |
---|
4 | require_once('common/admin/admin_menu.php'); |
---|
5 | |
---|
6 | $page = new Page(); |
---|
7 | $page->setAdmin(); |
---|
8 | |
---|
9 | if ($_REQUEST['opt'] == 'search') |
---|
10 | { |
---|
11 | $page->setTitle('Administration - Shipvalues - Add a Shipvalue'); |
---|
12 | |
---|
13 | if ($id = intval($_REQUEST['searchid'])) |
---|
14 | { |
---|
15 | $query = 'select count(shp_id) as cnt from kb3_ships_values where shp_id='.$id; |
---|
16 | $qry = new DBQuery(); |
---|
17 | $qry->execute($query); |
---|
18 | $data = $qry->getRow(); |
---|
19 | if ($data['cnt'] >= 1) |
---|
20 | { |
---|
21 | // value already added |
---|
22 | unset($_REQUEST['opt']); |
---|
23 | $html .= 'Error: That id is already on the list.<br/>'; |
---|
24 | } |
---|
25 | else |
---|
26 | { |
---|
27 | $search = true; |
---|
28 | $searchstr = ' where ksb.shp_value is null and shp.shp_class != 17 and shp.shp_id='.$id; |
---|
29 | } |
---|
30 | } |
---|
31 | elseif ($name = slashfix($_REQUEST['searchname'])) |
---|
32 | { |
---|
33 | $search = true; |
---|
34 | $searchstr = " where ksb.shp_value is null and shp.shp_class != 17 and shp.shp_name like '%{$name}%'"; |
---|
35 | } |
---|
36 | else |
---|
37 | { |
---|
38 | unset($_REQUEST['opt']); |
---|
39 | $html .= 'Error: No id or name specified.<br/>'; |
---|
40 | } |
---|
41 | if ($search) |
---|
42 | { |
---|
43 | $query = 'select shp.shp_id as id, shp.shp_externalid as ext, shp.shp_name, shp.shp_class, |
---|
44 | shp.shp_baseprice, scl.scl_class, shp.shp_techlevel, scl.scl_value, ksb.shp_value |
---|
45 | from kb3_ships shp inner join kb3_ship_classes scl on (shp.shp_class = scl.scl_id) |
---|
46 | left join kb3_ships_values ksb on (shp.shp_id = ksb.shp_id)'; |
---|
47 | $order = ' order by shp.shp_name asc'; |
---|
48 | $qry = new DBQuery(); |
---|
49 | $qry->execute($query.$searchstr.$order); |
---|
50 | while ($data = $qry->getRow()) |
---|
51 | { |
---|
52 | if (!$c) |
---|
53 | { |
---|
54 | $html .= '<form id="search" action="?a=admin_shp_val" method=post>'; |
---|
55 | $html .= '<table class=kb-table width="99%" align=center cellspacing="1">'; |
---|
56 | $html .= '<input type="hidden" name="opt" value="add"/>'; |
---|
57 | $html .= '<tr class=kb-table-header>'; |
---|
58 | $html .= '<td class=kb-table-header align="center">Ship</td>'; |
---|
59 | $html .= '<td class=kb-table-header align="center">Ship id</td>'; |
---|
60 | $html .= '<td class=kb-table-header>Ship Name</td>'; |
---|
61 | $html .= '<td class=kb-table-header>Ship type</td>'; |
---|
62 | $html .= '<td class=kb-table-header align="center">Techlevel</td>'; |
---|
63 | $html .= '<td class=kb-table-header align="right">Baseprice</td>'; |
---|
64 | $html .= '<td class=kb-table-header align="right">Classvalue</td>'; |
---|
65 | $html .= '<td class=kb-table-header align="right">Shipvalue</td></tr>'; |
---|
66 | } |
---|
67 | $c++; |
---|
68 | if (!$odd) |
---|
69 | { |
---|
70 | $odd = true; |
---|
71 | $class = 'kb-table-row-odd'; |
---|
72 | } |
---|
73 | else |
---|
74 | { |
---|
75 | $odd = false; |
---|
76 | $class = 'kb-table-row-even'; |
---|
77 | } |
---|
78 | $html .= "<tr class=".$class." style=\"height: 66px;\">"; |
---|
79 | $html .= '<td width="64" align="center"><img src="'.IMG_URL.'/ships/64_64/'.$data['ext'].'.png"></td>'; |
---|
80 | $html .= '<td align="center">'.$data['id'].'</td>'; |
---|
81 | $html .= '<td>'.$data['shp_name'].'</td>'; |
---|
82 | $html .= '<td>'.$data['scl_class'].'</td>'; |
---|
83 | $html .= '<td width="64" align="center">'.$data['shp_techlevel'].'</td>'; |
---|
84 | $html .= '<td align="right">'.number_format($data['shp_baseprice'], 0, ',', '.').'</td>'; |
---|
85 | $html .= '<td align="right">'.number_format($data['scl_value'], 0, ',', '.').'</td>'; |
---|
86 | $html .= '<td width="180" align="right"><input type="text" name="ship['.$data['id'].']" value="'.$data['scl_value'].'"></td></tr>'; |
---|
87 | } |
---|
88 | if ($c) |
---|
89 | { |
---|
90 | $html .= '</table>'; |
---|
91 | $html .= '<br/><input type="submit" name="submit" value="Save"> Note: Only values different from classvalue and zero will be saved.'; |
---|
92 | $html .= '</form>'; |
---|
93 | } |
---|
94 | else |
---|
95 | { |
---|
96 | $html .= 'No Ships found to be added.<br/>'; |
---|
97 | unset($_REQUEST['opt']); |
---|
98 | } |
---|
99 | } |
---|
100 | } |
---|
101 | if ($_REQUEST['opt'] == 'add') |
---|
102 | { |
---|
103 | $qry = new DBQuery(); |
---|
104 | if (!isset($_POST['ship'])) |
---|
105 | { |
---|
106 | $_POST['ship'] = array(); |
---|
107 | } |
---|
108 | foreach ($_POST['ship'] as $id => $value) |
---|
109 | { |
---|
110 | $id = intval($id); |
---|
111 | // kill everything thats not a number |
---|
112 | $value = preg_replace('/[^0-9]/', '', $value); |
---|
113 | if ($value == 0 || $id == 0) |
---|
114 | { |
---|
115 | continue; |
---|
116 | } |
---|
117 | $query = 'select shp.shp_id as id, scl.scl_value |
---|
118 | from kb3_ships shp inner join kb3_ship_classes scl on (shp.shp_class = scl.scl_id) |
---|
119 | where shp.shp_id='.$id; |
---|
120 | $qry->execute($query); |
---|
121 | $data = $qry->getRow(); |
---|
122 | if ($data['scl_value'] == $value) |
---|
123 | { |
---|
124 | $qry->execute('delete from kb3_ships_values where shp_id='.$id.' limit 1'); |
---|
125 | continue; |
---|
126 | } |
---|
127 | |
---|
128 | $query = 'select count(shp_id) as cnt from kb3_ships_values where shp_id='.$id; |
---|
129 | $qry->execute($query); |
---|
130 | $data = $qry->getRow(); |
---|
131 | if ($data['cnt'] >= 1) |
---|
132 | { |
---|
133 | $qry->execute('update kb3_ships_values set shp_value=\''.$value.'\' where shp_id='.$id); |
---|
134 | } |
---|
135 | else |
---|
136 | { |
---|
137 | $qry->execute('insert into kb3_ships_values (shp_id, shp_value) values ('.$id.',\''.$value.'\')'); |
---|
138 | } |
---|
139 | } |
---|
140 | $html .= 'Shipvalues added/changed<br/>'; |
---|
141 | unset($_REQUEST['opt']); |
---|
142 | } |
---|
143 | if (!isset($_REQUEST['opt'])) |
---|
144 | { |
---|
145 | $page->setTitle("Administration - Shipvalues"); |
---|
146 | |
---|
147 | $html .= '<div class=block-header2>Add a Shipvalue</div>'; |
---|
148 | $html .= '<form id="search" action="?a=admin_shp_val" method=post>'; |
---|
149 | $html .= '<input type="hidden" name="opt" value="search"/>'; |
---|
150 | $html .= '<table class="kb-subtable"><tr>'; |
---|
151 | $html .= '<td>ShipID</td><td>or Shipname</td>'; |
---|
152 | $html .= '</tr><tr>'; |
---|
153 | $html .= '<td><input id="searchid" name="searchid" type="text" size="4"/></td>'; |
---|
154 | $html .= '<td><input id="searchname" name="searchname" type="text" size="30"/></td>'; |
---|
155 | $html .= '<td><input type="submit" name="submit" value="Search"/></td>'; |
---|
156 | $html .= '</tr></table>'; |
---|
157 | $html .= '</form><br/>'; |
---|
158 | |
---|
159 | $html .= "<div class=block-header2>View/Change Shipvalues</div>"; |
---|
160 | $qry = new DBQuery(); |
---|
161 | $query = 'select kbs.shp_id as id, shp.shp_externalid as ext, shp.shp_name, shp.shp_class, kbs.shp_value, |
---|
162 | shp.shp_baseprice, scl.scl_class, shp.shp_techlevel, scl.scl_value |
---|
163 | from kb3_ships_values kbs |
---|
164 | inner join kb3_ships shp on (kbs.shp_id = shp.shp_id) |
---|
165 | inner join kb3_ship_classes scl on (shp.shp_class = scl.scl_id) order by shp.shp_name asc'; |
---|
166 | $qry->execute($query); |
---|
167 | while ($data = $qry->getRow()) |
---|
168 | { |
---|
169 | if (!$c) |
---|
170 | { |
---|
171 | $html .= '<form id="search" action="?a=admin_shp_val" method=post>'; |
---|
172 | $html .= '<table class="kb-table" width="99%" align=center cellspacing="1">'; |
---|
173 | $html .= '<input type="hidden" name="opt" value="add"/>'; |
---|
174 | $html .= '<script language="javascript"> |
---|
175 | function geninput(object,id,value,orgval) |
---|
176 | { |
---|
177 | if (document.getElementById(\'ship_\'+id)) return; |
---|
178 | object.innerHTML = \'<input type="text" id="ship_\'+id+\'" name="ship[\'+id+\']" value="\'+value+\'" onblur="checkinput(this,\'+value+\',\\\'\'+orgval+\'\\\',\'+id+\');">\'; |
---|
179 | document.getElementById(\'ship_\'+id).focus(); |
---|
180 | } |
---|
181 | function checkinput(object,value,oldvalue,id) |
---|
182 | { |
---|
183 | if (object.value == value) |
---|
184 | { |
---|
185 | document.getElementById(\'tbrid_\'+id).innerHTML = oldvalue; |
---|
186 | } |
---|
187 | } |
---|
188 | </script>'; |
---|
189 | $html .= '<tr class=kb-table-header>'; |
---|
190 | $html .= '<td class=kb-table-header align="center">Ship</td>'; |
---|
191 | $html .= '<td class=kb-table-header align="center">Ship id</td>'; |
---|
192 | $html .= '<td class=kb-table-header>Ship Name</td>'; |
---|
193 | $html .= '<td class=kb-table-header>Ship type</td>'; |
---|
194 | $html .= '<td class=kb-table-header align="center">Techlevel</td>'; |
---|
195 | $html .= '<td class=kb-table-header align="right">Baseprice</td>'; |
---|
196 | $html .= '<td class=kb-table-header align="right">Classvalue</td>'; |
---|
197 | $html .= '<td class=kb-table-header align="right">Shipvalue</td></tr>'; |
---|
198 | } |
---|
199 | $c++; |
---|
200 | if (!$odd) |
---|
201 | { |
---|
202 | $odd = true; |
---|
203 | $class = 'kb-table-row-odd'; |
---|
204 | } |
---|
205 | else |
---|
206 | { |
---|
207 | $odd = false; |
---|
208 | $class = 'kb-table-row-even'; |
---|
209 | } |
---|
210 | $html .= "<tr class=".$class." style=\"height: 34px;\">"; |
---|
211 | $html .= '<td width="32" align="center"><img src="'.IMG_URL.'/ships/32_32/'.$data['ext'].'.png"></td>'; |
---|
212 | $html .= '<td align="center">'.$data['id'].'</td>'; |
---|
213 | $html .= '<td>'.$data['shp_name'].'</td>'; |
---|
214 | $html .= '<td>'.$data['scl_class'].'</td>'; |
---|
215 | $html .= '<td width="64" align="center">'.$data['shp_techlevel'].'</td>'; |
---|
216 | $html .= '<td align="right">'.number_format($data['shp_baseprice'], 0, ',', '.').'</td>'; |
---|
217 | $html .= '<td align="right">'.number_format($data['scl_value'], 0, ',', '.').'</td>'; |
---|
218 | $html .= '<td width="180" align="right" id="tbrid_'.$data['id'].'" onClick="geninput(this,'.$data['id'].','.$data['shp_value'].',\''.number_format($data['shp_value'], 0, ',', '.').'\');">' |
---|
219 | .number_format($data['shp_value'], 0, ',', '.').'</td></tr>'; |
---|
220 | } |
---|
221 | if ($c) |
---|
222 | { |
---|
223 | $html .= '</table>'; |
---|
224 | $html .= '<br/><input type="submit" name="submit" value="Save"> Note: Only values different from classvalue and zero will be saved. Hint: click into the Shipvalue field.'; |
---|
225 | $html .= '</form>'; |
---|
226 | } |
---|
227 | else |
---|
228 | { |
---|
229 | $html .= 'No Data.<br/>'; |
---|
230 | } |
---|
231 | } |
---|
232 | $page->addContext($menubox->generate()); |
---|
233 | $page->setContent($html); |
---|
234 | $page->generate(); |
---|
235 | ?> |
---|