1
<?php
2
/**
3
 *   File functions:
4
 *   Tribe armor - weapons and armors
5
 *
6
 *   @name                 : tribearmor.php                            
7
 *   @copyright            : (C) 2004,2005,2006,2007 Vallheru Team based on Gamers-Fusion ver 2.5
8
 *   @author               : thindil <thindil@users.sourceforge.net>
9
 *   @author               : eyescream <tduda@users.sourceforge.net>
10
 *   @version              : 1.3
11
 *   @since                : 03.03.2007
12
 *
13
 */
14
15
//
16
//
17
//       This program is free software; you can redistribute it and/or modify
18
//   it under the terms of the GNU General Public License as published by
19
//   the Free Software Foundation; either version 2 of the License, or
20
//   (at your option) any later version.
21
//
22
//   This program is distributed in the hope that it will be useful,
23
//   but WITHOUT ANY WARRANTY; without even the implied warranty of
24
//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25
//   GNU General Public License for more details.
26
//
27
//   You should have received a copy of the GNU General Public License
28
//   along with this program; if not, write to the Free Software
29
//   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
30
//
31
// 
32
// $Id: tribearmor.php 918 2007-03-03 17:55:42Z thindil $
33
34
$title = "Zbrojownia klanu";
35
require_once("includes/head.php");
36
37
/**
38
* Get the localization for game
39
*/
40
require_once("languages/".$player -> lang."/tribearmor.php");
41
42
/**
43
* Check if player is in clan
44
*/
45
if (!$player -> tribe) 
46
{
47
    error (NO_CLAN);
48
}
49
50
/**
51
* Check if player is in town
52
*/
53
if ($player -> location != 'Altara' && $player -> location != 'Ardulith') 
54
{
55
    error (ERROR);
56
}
57
58
/**
59
* Assign variable to template
60
*/
61
$smarty -> assign("Message", '');
62
63
/**
64
* Check permission who have ability to give items
65
*/
66
$perm = $db -> Execute("SELECT `armory` FROM `tribe_perm` WHERE `tribe`=".$player -> tribe." AND `player`=".$player -> id);
67
$owner = $db -> Execute("SELECT `owner` FROM `tribes` WHERE `id`=".$player -> tribe);
68
69
$arrType = array('W', 'A', 'H', 'L', 'S', 'B', 'T', 'C', 'R', 'I');
70
71
/**
72
* Main menu
73
*/
74
if (!isset($_GET['step']) && !isset($_GET['daj']) && !isset($_GET['step2']) && !isset($_GET['step3'])) 
75
{
76
    $arrLink = array(A_SHOW_W, A_SHOW_A, A_SHOW_H, A_SHOW_L, A_SHOW_D, A_SHOW_B, A_SHOW_S, A_SHOW_C, A_SHOW_R, A_SHOW_I);
77
    $smarty -> assign(array("Armorinfo" => ARMOR_INFO,
78
                            "Armortype" => $arrType,
79
                            "Armorlink" => $arrLink,
80
                            "Aadd" => A_ADD));
81
}
82
83
/**
84
* List of items in tribe armor
85
*/
86
if (isset($_GET['step']) && $_GET['step'] == 'zobacz') 
87
{
88
    $arrList = array('id', 'name', 'power', 'wt', 'zr', 'szyb', 'minlev');
89
    if (isset($_GET['type']) && !in_array($_GET['type'], $arrType)) 
90
    {
91
        error (ERROR);
92
    }
93
    if (isset($_GET['lista']) && !in_array($_GET['lista'], $arrList)) 
94
    {
95
        error (ERROR);
96
    }
97
    if (!isset($_GET['type'])) 
98
    {
99
        error(WHAT_YOU);
100
    }
101
    $arrItem = array(T_WEAPONS, T_ARMORS, T_HELMETS, T_LEGS, T_SHIELDS, T_BOWS, T_STAFFS, T_CAPES, T_ARROWS, T_RINGS);
102
    $intKey = array_search($_GET['type'], $arrType);
103
    $item = $arrItem[$intKey];
104
    $amount = $db -> Execute("SELECT amount FROM tribe_zbroj WHERE klan=".$player -> tribe." AND type='".$_GET['type']."'");
105
    if (!$amount -> fields['amount']) 
106
    {
107
        error(NO_ITEMS.$item.IN_ARMOR);
108
    }
109
    $przed = 0;
110
    while (!$amount -> EOF) 
111
    {
112
        $przed = $przed + $amount -> fields['amount'];
113
        $amount -> MoveNext();
114
    }
115
    $amount -> Close();
116
    $smarty -> assign(array("Amount1" => $przed, 
117
                            "Name1" => $item));
118
    if ($_GET['lista'] == 'zr')
119
    {
120
        $strOrder = ' ASC';
121
    }
122
        else
123
    {
124
        $strOrder = ' DESC';
125
    }
126
    if (isset($_GET['levels']) && $_GET['levels'] == 'yes')
127
    {
128
        if (!ereg("^[1-9][0-9]*$", $_POST['min']) || !ereg("^[1-9][0-9]*$", $_POST['max']))
129
        {
130
            error(ERROR);
131
        }
132
        if ($_POST['max'] < $_POST['min'])
133
        {
134
            error(ERROR);
135
        }
136
        $arritem = $db -> Execute("SELECT * FROM `tribe_zbroj` WHERE `klan`=".$player -> tribe." AND `type`='".$_GET['type']."' AND `minlev`>=".$_POST['min']." AND `minlev`<=".$_POST['max']." ORDER BY ".$_GET['lista'].$strOrder);
137
    }
138
        else
139
    {
140
        $arritem = $db -> Execute("SELECT * FROM tribe_zbroj WHERE klan=".$player -> tribe." AND type='".$_GET['type']."' ORDER BY ".$_GET['lista'].$strOrder);
141
    }
142
    $arragi = array();
143
    $arrpower = array();
144
    $arrname = array();
145
    $arrdur = array();
146
    $arrmaxdur = array();
147
    $arrspeed = array();
148
    $arramount = array();
149
    $arraction = array();
150
    $arrLevel = array();
151
    $i = 0;
152
    while (!$arritem -> EOF) 
153
    {
154
        if ($arritem -> fields['zr'] < 1) 
155
        {
156
            $arragi[$i] = str_replace("-","",$arritem -> fields['zr']);
157
        } 
158
            else 
159
        {
160
            $arragi[$i] = "-".$arritem -> fields['zr'];
161
        }
162
        $arrpower[$i] = $arritem -> fields['power'];
163
        if ($arritem -> fields['poison'] > 0) 
164
        {
165
            $arrpower[$i] = $arritem -> fields['power'] + $arritem -> fields['poison'];
166
        }
167
        $arrname[$i] = $arritem -> fields['name'];
168
        $arrdur[$i] = $arritem -> fields['wt'];
169
        $arrmaxdur[$i] = $arritem -> fields['maxwt'];
170
        $arrspeed[$i] = $arritem -> fields['szyb'];
171
        $arramount[$i] = $arritem -> fields['amount'];
172
        $arrLevel[$i] = $arritem -> fields['minlev'];
173
        if ($player -> id == $owner -> fields['owner'] || $perm -> fields['armory']) 
174
        {
175
           $arraction[$i] = "<td>- <a href=tribearmor.php?daj=".$arritem -> fields['id'].">".A_GIVE."</a></td>";
176
        } 
177
            else 
178
        {
179
            $arraction[$i] = "<td></td>";
180
        }
181
        $arritem -> MoveNext();
182
        $i ++;
183
    }
184
    $arritem -> Close();
185
    if ($_GET['type'] == 'I')
186
    {
187
        $arrInfos = array(T_NAME, T_POWER, T_LEVEL);
188
        $arrList = array('id', 'name', 'power', 'minlev');
189
    }
190
        else
191
    {
192
        $arrInfos = array(T_NAME, T_POWER, T_DUR, T_AGI, T_SPEED, T_LEVEL);
193
        $arrList2 = array('id', 'name', 'power', 'wt', 'zr', 'szyb', 'minlev');
194
    }
195
    $strId = array_shift($arrList);
196
    $smarty -> assign(array("Name" => $arrname, 
197
                            "Agility" => $arragi, 
198
                            "Power" => $arrpower, 
199
                            "Durability" => $arrdur, 
200
                            "Maxdurability" => $arrmaxdur, 
201
                            "Speed" => $arrspeed, 
202
                            "Amount" => $arramount, 
203
                            "Action" => $arraction,
204
                            "Ilevel" => $arrLevel,
205
                            "Type" => $_GET['type'],
206
                            "Tinfos" => $arrInfos,
207
                            "Ttypes" => $arrList,
208
                            "Inarmor2" => IN_ARMOR2,
209
                            "Tamount2" => T_AMOUNT2,
210
                            "Toptions" => T_OPTIONS,
211
                            "Tor" => T_OR,
212
                            "Tseek" => T_SEEK,
213
                            "Titems" => T_ITEMS,
214
                            "Tto" => T_TO));
215
}
216
217
/**
218
* Give players items from armor
219
*/
220
if (isset ($_GET['daj'])) 
221
{
222
    if (!isset ($_GET['step3'])) 
223
    {
224
        $name = $db -> Execute("SELECT * FROM tribe_zbroj WHERE id=".$_GET['daj']);
225
        $smarty -> assign(array("Id" => $_GET['daj'], 
226
                                "Amount" => $name -> fields['amount'], 
227
                                "Name" => $name -> fields['name'],
228
                                "Agive" => A_GIVE,
229
                                "Tamount" => T_AMOUNT,
230
                                "Playerid" => PLAYER_ID));
231
        $name -> Close();
232
    }
233
    if (isset ($_GET['step3']) && $_GET['step3'] == 'add') 
234
    {
235
        integercheck($_POST['amount']);
236
        if (!ereg("^[1-9][0-9]*$", $_POST['did']) || !ereg("^[1-9][0-9]*$", $_POST['amount'])) 
237
        {
238
            error (ERROR);
239
        }
240
        $zbroj = $db -> Execute("SELECT * FROM tribe_zbroj WHERE id=".$_GET['daj']);
241
        if ($zbroj -> fields['amount'] < $_POST['amount']) 
242
        {
243
            error (NO_ITEMS);
244
        }
245
        $dtrib = $db -> Execute("SELECT tribe FROM players WHERE id=".$_POST['did']);
246
        if ($dtrib -> fields['tribe'] != $player -> tribe) 
247
        {
248
            error (NOT_IN_CLAN);
249
        }
250
        $dtrib -> Close();
251
        $test = $db -> Execute("SELECT `id` FROM `equipment` WHERE `name`='".$zbroj -> fields['name']."' AND `owner`=".$_POST['did']." AND `wt`=".$zbroj -> fields['wt']." AND `type`='".$zbroj -> fields['type']."' AND `power`=".$zbroj -> fields['power']." AND `szyb`=".$zbroj -> fields['szyb']." AND `zr`=".$zbroj -> fields['zr']." AND `maxwt`=".$zbroj -> fields['maxwt']." AND `poison`=".$zbroj -> fields['poison']." AND `status`='U' AND `ptype`='".$zbroj -> fields['ptype']."' AND `cost`=1");
252
        if (!$test -> fields['id']) 
253
        {
254
            $db -> Execute("INSERT INTO equipment (owner, name, power, type, cost, zr, wt, minlev, maxwt, amount, magic, poison, szyb, twohand, ptype, repair) VALUES(".$_POST['did'].",'".$zbroj -> fields['name']."',".$zbroj -> fields['power'].",'".$zbroj -> fields['type']."',1,".$zbroj -> fields['zr'].",".$zbroj -> fields['wt'].",".$zbroj -> fields['minlev'].",".$zbroj -> fields['maxwt'].",".$_POST['amount'].",'".$zbroj -> fields['magic']."',".$zbroj -> fields['poison'].",".$zbroj -> fields['szyb'].",'".$zbroj -> fields['twohand']."','".$zbroj -> fields['ptype']."', ".$zbroj -> fields['repair'].")");
255
        } 
256
            else 
257
        {
258
            if ($zbroj -> fields['type'] != 'R')
259
            {
260
                $db -> Execute("UPDATE equipment SET amount=amount+".$_POST['amount']." WHERE id=".$test -> fields['id']);
261
            }
262
                else
263
            {
264
                $db -> Execute("UPDATE `equipment` SET `wt`=`wt`+".$zbroj -> fields['wt']." WHERE `id`=".$test -> fields['id']);
265
            }
266
        }
267
        $test -> Close();
268
        if ($_POST['amount'] < $zbroj -> fields['amount']) 
269
        {
270
            $db -> Execute("UPDATE tribe_zbroj SET amount=amount-".$_POST['amount']." WHERE id=".$zbroj -> fields['id']);
271
        } 
272
            else 
273
        {
274
            $db -> Execute("DELETE FROM tribe_zbroj WHERE id=".$zbroj -> fields['id']);
275
        }
276
        // Get name of the person that receives armour.
277
        $objGetName = $db -> Execute("SELECT `user` FROM `players` WHERE `id`=".$_POST['did'].';');
278
        $strReceiversName = $objGetName -> fields['user'];
279
        $objGetName -> Close();
280
        unset( $objGetName );
281
282
        $smarty -> assign ("Message", YOU_GIVE1.'<b><a href="view.php?view='.$_POST['did'].'">'.$strReceiversName.'</a></b>'.YOU_GIVE2.'<b>'.$_POST['did']."</b> ".$_POST['amount'].T_AMOUNT.$zbroj -> fields['name'].'.');
283
        $db -> Execute("INSERT INTO log (owner,log, czas) VALUES(".$_POST['did'].", '".YOU_GET.$_POST['amount'].T_AMOUNT.$zbroj -> fields['name'].".','".$newdate."')");
284
        $objPerm = $db -> Execute("SELECT player FROM tribe_perm WHERE tribe=".$player -> tribe." AND armory=1");
285
        while (!$objPerm -> EOF)
286
        {
287
            $db -> Execute("INSERT INTO log (owner,log, czas) VALUES(".$objPerm -> fields['player'].", '".YOU_GIVE1.'<b><a href="view.php?view='.$_POST['did'].'">'.$strReceiversName.'</a></b>'.YOU_GIVE2.'<b>'.$_POST['did']."</b> ".$_POST['amount'].T_AMOUNT.$zbroj -> fields['name'].".','".$newdate."')");
288
            $objPerm -> MoveNext();
289
        }
290
        $objPerm -> Close();
291
        $zbroj -> Close();
292
    }
293
}
294
295
/**
296
* Add items to armor
297
*/
298
if (isset ($_GET['step']) && $_GET['step'] == 'daj') 
299
{
300
    if (isset ($_GET['step2']) && $_GET['step2'] == 'add') 
301
    {
302
        if (!isset($_POST['przedmiot'])) 
303
        {
304
            error(SELECT_ITEM);
305
        }
306
        integercheck($_POST['amount']);
307
        if (!ereg("^[1-9][0-9]*$", $_POST['przedmiot']) || !ereg("^[1-9][0-9]*$", $_POST['amount'])) 
308
        {
309
            error (ERROR);
310
        }
311
        $przed = $db -> Execute("SELECT * FROM equipment WHERE id=".$_POST['przedmiot']);
312
        if (!$przed -> fields['name']) 
313
        {
314
            error (ERROR);
315
        }
316
        if ($przed -> fields['amount'] < $_POST['amount']) 
317
        {
318
            error (NO_AMOUNT);
319
        }
320
        $test = $db -> Execute("SELECT id FROM tribe_zbroj WHERE name='".$przed -> fields['name']."' AND klan=".$player -> tribe." AND wt=".$przed -> fields['wt']." AND type='".$przed -> fields['type']."' AND power=".$przed -> fields['power']." AND szyb=".$przed -> fields['szyb']." AND zr=".$przed -> fields['zr']." AND maxwt=".$przed -> fields['maxwt']." AND poison=".$przed -> fields['poison']." AND ptype='".$przed -> fields['ptype']."'");
321
        if (!$test -> fields['id']) 
322
        {
323
            $db -> Execute("INSERT INTO tribe_zbroj (klan, name, power, type, zr, wt, minlev, maxwt, amount, magic, poison, szyb, twohand, ptype, repair) VALUES(".$player -> tribe.",'".$przed -> fields['name']."',".$przed -> fields['power'].",'".$przed -> fields['type']."',".$przed -> fields['zr'].",".$przed -> fields['wt'].",".$przed -> fields['minlev'].",".$przed -> fields['maxwt'].",".$_POST['amount'].",'".$przed -> fields['magic']."',".$przed -> fields['poison'].",".$przed -> fields['szyb'].",'".$przed -> fields['twohand']."','".$przed -> fields['ptype']."', ".$przed -> fields['repair'].")");
324
        } 
325
            else 
326
        {
327
            if ($przed -> fields['type'] != 'R')
328
            {
329
                $db -> Execute("UPDATE tribe_zbroj SET amount=amount+".$_POST['amount']." WHERE id=".$test -> fields['id']);
330
            }
331
                else
332
            {
333
                $db -> Execute("UPDATE `tribe_zbroj` SET `wt`=`wt`+".$przed -> fields['wt']." WHERE `id`=".$test -> fields['id']);
334
            }
335
        }
336
        $test -> Close();
337
        if ($_POST['amount'] < $przed -> fields['amount']) 
338
        {
339
            $db -> Execute("UPDATE equipment SET amount=amount-".$_POST['amount']." WHERE id=".$przed -> fields['id']);
340
        } 
341
            else 
342
        {
343
            $db -> Execute("DELETE FROM equipment WHERE id=".$przed -> fields['id']);
344
        }
345
        $smarty -> assign ("Message", YOU_ADD.$_POST['amount'].T_AMOUNT.$przed -> fields['name']."</b> ".TO_ARMOR);
346
        $db -> Execute("INSERT INTO log (owner,log, czas) VALUES(".$owner -> fields['owner'].", '".L_PLAYER."<a href=view.php?view=".$player -> id.">".$player -> user.L_ID.$player -> id.ADD_TO.$_POST['amount'].T_AMOUNT.$przed -> fields['name'].".','".$newdate."')");
347
        $objPerm = $db -> Execute("SELECT player FROM tribe_perm WHERE tribe=".$player -> tribe." AND armory=1");
348
        while (!$objPerm -> EOF)
349
        {
350
            $db -> Execute("INSERT INTO log (owner,log, czas) VALUES(".$objPerm -> fields['player'].", '".L_PLAYER."<a href=view.php?view=".$player -> id.">".$player -> user.L_ID.$player -> id.ADD_TO.$_POST['amount'].T_AMOUNT.$przed -> fields['name'].".','".$newdate."')");
351
            $objPerm -> MoveNext();
352
        }
353
        $objPerm -> Close();
354
        $przed -> Close();
355
    }
356
    $arritem = $db -> Execute("SELECT * FROM equipment WHERE status='U' AND owner=".$player -> id);
357
    $arrname = array();
358
    $arrid = array();
359
    $arramount = array();
360
    $i = 0;
361
    while (!$arritem -> EOF) 
362
    {
363
        $arrname[$i] = $arritem -> fields['name'];
364
        $arrid[$i] = $arritem -> fields['id'];
365
        $arramount[$i] = $arritem -> fields['amount'];
366
        $arritem -> MoveNext();
367
        $i = $i + 1;
368
    }
369
    $arritem -> Close();
370
    $smarty -> assign(array("Name" => $arrname, 
371
                            "Itemid" => $arrid, 
372
                            "Amount" => $arramount,
373
                            "Additem" => ADD_ITEM,
374
                            "Item" => ITEM,
375
                            "Amount2" => AMOUNT2,
376
                            "Aadd" => A_ADD));
377
}
378
379
/**
380
* Initialization of variables
381
*/
382
if (!isset($_GET['step'])) 
383
{
384
    $_GET['step'] = '';
385
}
386
if (!isset($_GET['step2'])) 
387
{
388
    $_GET['step2'] = '';
389
}
390
if (!isset($_GET['step3'])) 
391
{
392
    $_GET['step3'] = '';
393
}
394
if (!isset($_GET['daj'])) 
395
{
396
    $_GET['daj'] = '';
397
}
398
399
/**
400
* Assign variables to template and display page
401
*/
402
$smarty -> assign(array("Step" => $_GET['step'], 
403
                        "Step2" => $_GET['step2'], 
404
                        "Give" => $_GET['daj'], 
405
                        "Step3" => $_GET['step3'],
406
                        "Amain" => A_MAIN,
407
                        "Adonate" => A_DONATE,
408
                        "Amembers" => A_MEMBERS,
409
                        "Apotions" => A_POTIONS,
410
                        "Aminerals" => A_MINERALS,
411
                        "Aherbs" => A_HERBS,
412
                        "Aleft" => A_LEFT,
413
                        "Aleader" => A_LEADER,
414
                        "Aforums" => A_FORUMS,
415
                        "Aarmor" => A_ARMOR,
416
                        "Aastral" => A_ASTRAL));
417
$smarty -> display ('tribearmor.tpl');
418
419
require_once("includes/foot.php");
420
?>