1
<?php
2
/**
3
 *   File functions:
4
 *   Potions shop in city
5
 *
6
 *   @name                 : msklep.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
 *   @version              : 1.3
10
 *   @since                : 24.02.2007
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: msklep.php 900 2007-02-24 21:25:14Z thindil $
31
32
$title = "Apteka";
33
require_once("includes/head.php");
34
35
/**
36
* Get the localization for game
37
*/
38
require_once("languages/".$player -> lang."/msklep.php");
39
40
if ($player -> location != 'Altara' && $player -> location != 'Ardulith') 
41
{
42
    error(ERROR);
43
}
44
45
/**
46
* Show list of potions in shop
47
*/
48
if (!isset($_GET['buy'])) 
49
{
50
    $objPotions = $db -> Execute("SELECT * FROM `potions` WHERE `owner`=0 AND `status`='S' AND `lang`='".$player -> lang."' ORDER BY `power` ASC");
51
    $arrName = array();
52
    $arrPower = array();
53
    $arrEfect = array();
54
    $arrAmount = array();
55
    $arrItemid = array();
56
    $arrCost = array();
57
    $i = 0;
58
    while (!$objPotions -> EOF) 
59
    {
60
        if ($objPotions -> fields['type'] == 'M')
61
        {
62
            $arrCost[$i] = ($objPotions -> fields['power'] * 3);
63
        }
64
            else
65
        {
66
            $arrCost[$i] = ((2 * $objPotions -> fields['power']) * 3);
67
        }
68
        $arrName[$i] = $objPotions -> fields['name'];
69
        $arrPower[$i] = $objPotions -> fields['power'];
70
        $arrEfect[$i] = $objPotions -> fields['efect'];
71
        $arrAmount[$i] = $objPotions -> fields['amount'];
72
        $arrItemid[$i] = $objPotions -> fields['id'];
73
        $objPotions -> MoveNext();
74
        $i++;
75
    }
76
    $objPotions -> Close();
77
    $smarty -> assign (array("Pname" => $arrName,
78
                             "Ppower" => $arrPower,
79
                             "Pefect" => $arrEfect,
80
                             "Pamount" => $arrAmount,
81
                             "Pid" => $arrItemid,
82
                             "Pcost" => $arrCost,
83
                             "Npower" => POWER,
84
                             "Abuy" => A_BUY,
85
                             "Pwelcome" => WELCOME,
86
                             "Nname" => N_NAME,
87
                             "Nefect" => N_EFECT,
88
                             "Ncost" => N_COST,
89
                             "Namount" => N_AMOUNT,
90
                             "Poption" => P_OPTION));
91
}
92
93
if (isset($_GET['buy'])) 
94
{
95
    if (!ereg("^[1-9][0-9]*$", $_GET['buy'])) 
96
    {
97
        error(ERROR);
98
    }
99
    $objName = $db -> Execute("SELECT `name` FROM `potions` WHERE `id`=".$_GET['buy']);
100
    $smarty -> assign (array("Pid" => $_GET['buy'], 
101
                             "Name" => $objName -> fields['name'],
102
                             "Abuy" => A_BUY,
103
                             "Pamount" => P_AMOUNT));
104
    $objName -> Close();
105
    if (isset ($_GET['step']) && $_GET['step'] == 'buy')
106
    {
107
        $objPotions = $db -> Execute("SELECT * FROM `potions` WHERE `id`=".$_GET['buy']);
108
        if (!isset($_POST['amount']) || !ereg("^[1-9][0-9]*$", $_GET['buy']) || !ereg("^[1-9][0-9]*$", $_POST['amount'])) 
109
        {
110
            error(ERROR);
111
        }
112
        if ($_POST['amount'] > $objPotions -> fields['amount']) 
113
        {
114
            error(TOO_MUCH);
115
        }
116
        if (!$objPotions -> fields['id']) 
117
        {
118
            error(NO_POTION);
119
        }
120
        if ($objPotions -> fields['status'] != 'S') 
121
        {
122
            error(NO_TRADE);
123
        }
124
        if ($objPotions -> fields['type'] == 'M')
125
        {
126
            $intCostone = ($objPotions -> fields['power'] * 3);
127
        }
128
            else
129
        {
130
            $intCostone = ((2 * $objPotions -> fields['power']) * 3);
131
        }
132
        $intCost = ($intCostone * $_POST['amount']);
133
        if ($intCost > $player -> credits) 
134
        {
135
            error(NO_MONEY);
136
        }
137
        $objTest = $db -> Execute("SELECT `id` FROM `potions` WHERE `name`='".$objPotions -> fields['name']."' AND `owner`=".$player -> id." AND `status`='K'");
138
        if (!$objTest -> fields['id']) 
139
        {
140
            $db -> Execute("INSERT INTO `potions` (`name`, `owner`, `efect`, `type`, `power`, `status`, `amount`) VALUES('".$objPotions -> fields['name']."',".$player -> id.",'".$objPotions -> fields['efect']."','".$objPotions -> fields['type']."',".$objPotions -> fields['power'].",'K',".$_POST['amount'].")") or error(E_DB);
141
        } 
142
            else 
143
        {
144
            $db -> Execute("UPDATE `potions` SET `amount`=`amount`+".$_POST['amount']." WHERE `id`=".$objTest -> fields['id']);
145
        }
146
        $objTest -> Close();
147
        $db -> Execute("UPDATE `players` SET `credits`=`credits`-".$intCost." WHERE `id`=".$player -> id);
148
        $db -> Execute("UPDATE `potions` SET `amount`=`amount`-".$_POST['amount']." WHERE `id`=".$objPotions -> fields['id']);
149
        error(YOU_PAY." <b>".$intCost."</b> ".P_COINS." ".$_POST['amount']." ".POTIONS." ".$objPotions -> fields['name']."</b>. <a href=\"msklep.php\">".S_BACK."</a>");
150
    }
151
}
152
153
/**
154
* Initialization of variable
155
*/
156
if (!isset($_GET['buy'])) 
157
{
158
    $_GET['buy'] = '';
159
}
160
161
/**
162
* Assign variable to template and display page
163
*/
164
$smarty -> assign ("Buy", $_GET['buy']);
165
$smarty -> display ('msklep.tpl');
166
167
require_once("includes/foot.php"); 
168
?>