1
<?php
2
/**
3
 *   File functions:
4
 *   Jeweller shop
5
 *
6
 *   @name                 : jewellershop.php                            
7
 *   @copyright            : (C) 2006 Vallheru Team based on Gamers-Fusion ver 2.5
8
 *   @author               : thindil <thindil@users.sourceforge.net>
9
 *   @version              : 1.2
10
 *   @since                : 19.07.2006
11
 *
12
 */
13
14
//
15
//
16
//       This program is free software; you can redistribute it and/or modify
17
//   it under the terms of the GNU General Public License as published by
18
//   the Free Software Foundation; either version 2 of the License, or
19
//   (at your option) any later version.
20
//
21
//   This program is distributed in the hope that it will be useful,
22
//   but WITHOUT ANY WARRANTY; without even the implied warranty of
23
//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24
//   GNU General Public License for more details.
25
//
26
//   You should have received a copy of the GNU General Public License
27
//   along with this program; if not, write to the Free Software
28
//   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
29
//
30
// $Id: jewellershop.php 499 2006-07-19 19:35:14Z thindil $
31
32
$title = "Jubiler";
33
require_once("includes/head.php");
34
35
/**
36
* Get the localization for game
37
*/
38
require_once("languages/".$player -> lang."/jewellershop.php");
39
40
if ($player -> location != 'Altara' && $player -> location != 'Ardulith') 
41
{
42
    error (ERROR);
43
}
44
45
$strMessage = '';
46
47
$objRings = $db -> Execute("SELECT `id`, `name`, `amount` FROM `rings`");
48
$i = 0;
49
$arrId = array();
50
$arrName = array();
51
$arrAmount = array();
52
while (!$objRings -> EOF)
53
{
54
    $arrId[$i] = $objRings -> fields['id'];
55
    $arrName[$i] = $objRings -> fields['name'];
56
    $arrAmount[$i] = $objRings -> fields['amount'];
57
    $i ++;
58
    $objRings -> MoveNext();
59
}
60
$objRings -> Close();
61
62
/**
63
 * Buy rings
64
 */
65
if (isset($_GET['buy']))
66
{
67
    if (!ereg("^[1-6]*$", $_GET['buy'])) 
68
    {
69
        error(ERROR);
70
    }
71
    if ($player -> credits < 500)
72
    {
73
        error(NO_MONEY);
74
    }
75
    $intKey = $_GET['buy'] - 1;
76
    if (!$arrAmount[$intKey])
77
    {
78
        error(NO_RING);
79
    }
80
    $db -> Execute("UPDATE `rings` SET `amount`=`amount`-1 WHERE `id`=".$_GET['buy']);
81
    $objTest = $db -> Execute("SELECT `id` FROM `equipment` WHERE `owner`=".$player -> id." AND `name`='".$arrName[$intKey]."' AND `status`='U' AND `cost`=50");
82
    if (!$objTest -> fields['id'])
83
    {
84
        $db -> Execute("INSERT INTO `equipment` (`owner`, `name`, `power`, `status`, `type`, `cost`, `minlev`, `amount`) VALUES(".$player -> id.", '".$arrName[$intKey]."', '1', 'U', 'I', '50', '1', '1')");
85
    }
86
        else
87
    {
88
        $db -> Execute("UPDATE `equipment` SET `amount`=`amount`+1 WHERE `id`=".$objTest -> fields['id']);
89
    }
90
    $objTest -> Close();
91
    $db -> Execute("UPDATE `players` SET `credits`=`credits`-500 WHERE `id`=".$player -> id);
92
    $strMessage = YOU_BUY.$arrName[$intKey].FOR_A." <a href=\"jewellershop.php\">".A_REFRESH."</a>";
93
}
94
95
/**
96
 * Initialization of variable
97
 */
98
if (!isset($_GET['buy']))
99
{
100
    $_GET['buy'] = '';
101
}
102
103
/**
104
* Assign variables to template and display page
105
*/
106
$smarty -> assign(array("Shopinfo" => SHOP_INFO,
107
                        "Rid" => $arrId,
108
                        "Rname" => $arrName,
109
                        "Ramount" => $arrAmount,
110
                        "Tname" => T_NAME,
111
                        "Tamount" => T_AMOUNT,
112
                        "Tbonus" => T_BONUS,
113
                        "Tcost" => T_COST,
114
                        "Taction" => T_ACTION,
115
                        "Abuy" => A_BUY,
116
                        "Message" => $strMessage));
117
$smarty -> display ('jewellershop.tpl');
118
119
require_once("includes/foot.php");
120
?>