<?php
$name = $config->items['name'];
$names = $config->items['names'];
$product = $config->settings['product'];
?>
<?PHP

                $_OPTIMIZATION["title"] = sprintf($lang['farm']['title'],$name);
                $usid = $_SESSION["user_id"];
                $refid = $_SESSION["referer_id"];
                $usname = $_SESSION["user"];
                $db->Query("SELECT * FROM db_users_b WHERE id = '$usid' LIMIT 1");
                $user_data = $db->FetchArray();
                $db->Query("SELECT * FROM db_config WHERE id = '1' LIMIT 1");
                $sonfig_site = $db->FetchArray();
                # Покупка нового дерева
                if(isset($_POST["item"])){
                    $array_items = array(1 => "a_t", 2 => "b_t", 3 => "c_t", 4 => "d_t", 5 => "e_t", 6 => "f_t");
					
                    $array_name = array(1 => $config->items['item1'], 2 => $config->items['item2'], 3 => $config->items['item3'], 4 => $config->items['item4'], 5 => $config->items['item5'], 6 => $config->items['item6']);
                    $item = intval($_POST["item"]);
					if ($item&1){
                      $money_b="money_b";
				      $metal="Silver";
					}
                    else {
                       $money_b="money_b1";
				       $metal="Gold";
					}
                    $citem = $array_items[$item];
                    if(strlen($citem) >= 3){
                        # Проверяем средства пользователя
                        $need_money = $sonfig_site["amount_".$citem];
                        if($need_money <= $user_data[$money_b]){
                            if($user_data["last_sbor"] == 0 OR $user_data["last_sbor"] > ( time() - 60*20) ){
                                # Добавляем дерево и списываем деньги
                                $db->Query("UPDATE db_users_b SET $money_b = $money_b - $need_money, $citem = $citem + 1, last_sbor = IF(last_sbor > 0, last_sbor, '".time()."') WHERE id = '$usid'");
                                # Вносим запись о покупке
                                $db->Query("INSERT INTO db_stats_btree (user_id, user, tree_name, amount, date_add, date_del) VALUES ('$usid','$usname','".$array_name[$item]."','$need_money','".time()."','".(time()+60*60*24*15)."')");
                                $message = 'Building purchased with success!';
                                echo "<script type='text/javascript'>$(document).ready(function(){show_message('{$message}',1,6000); }); </script>";
                                $db->Query("SELECT * FROM db_users_b WHERE id = '$usid' LIMIT 1");
                                $user_data = $db->FetchArray();
                            }else {
                                $error_message = sprintf($lang['farm']['alert'],$config->settings['coins']);
                                echo "<script type='text/javascript'>$(document).ready(function(){show_message('{$error_message}',3,6000); }); </script>";
                            }
                        }else{
                            $error_message = 'There is not enough '.$metal.' to buy this item!';
                            echo "<script type='text/javascript'>$(document).ready(function(){show_message('{$error_message}',3,6000); }); </script>";
                        }
                    }
                }
            ?>
         



        <section class="main races">
		
            <div class="wrapper-constrained">
                <div class="content-wrapper flex">
				
                    <div class="perfpage">
                        <div class="pinfo">
                            <div class="picon"></div>
                            <div class="pcont">
                                You can buy different buildings which will bring you permanent income! The more expensive is the building - the more income you receive.   
								<p>To buy Gold or Silver, go to Marketplace!</p>
								</div>
                        </div>
                        <div class="container elven">
                            <div class="decor big"></div>
                            <h3><span>Cash Empire Shop</span></h3>
                            <div class="container-inner">
                                <h2>Buildings never Stop</h2>
								<h3>Earnings for life</h3>

                                <div class="buy_objects">
								<div class="msg-type sm-success"></div>
								
                                                                                 

                                                                    <div class="object elven animated slideExpandUp" objID="1">
                                            
                                            <div class="obj_img" style="background: url('../images/objects/us1.png') center no-repeat; background-size: contain !important;"></div>
                                                                                        <div class="cl-info pointercursor"></div>
                                            <div class="cl-info-info" objID="1">
                                                <div class="content">
                                                    It is the Main habitat of the elves, as well as the center of your city.                                                    <!--<small>Нажмите, чтобы скрыть</small>-->
                                                </div>
                                            </div>

                                            <div class="obj_inf" objID="1">
                                                <div class="obj_name"><div>The Main Hall</div></div>
                                                <div class="obj_price">
                                                    Price: <?php echo $sonfig_site["amount_a_t"]; ?> <span class="ic-gold1"></span>
                                                                                                    </div>
                                                <div class="obj_price">
                                                   <?php echo $sonfig_site["a_in_h"]; ?> <span class="ic-emerald"></span> / hour                                                                                                      
                                                </div>
												
												 <div class="obj_price">
                                                    <span><?php echo $user_data["a_t"]; ?> in your Empire</span>                                                                                
                                                </div>
												<form action="" method="post">
                                                           <input type="hidden" name="item" value="1" />                                                                                                                                             
														<button type="submit" type="submit" class="btn-small buy-obj-btn" objID="2" smsg="<b>Congratulations! You have successfully purchased  'The Hut'.<br/>Place the building on the game field to start gain income </b>">Buy</button>
                                                </form>
                                                   <script>$('.object[objID=1]').addClass('disabled');</script>
                                                                                             </div>
                                            <div class="decor middle"></div>

                                        </div>
                                                                                                                                                                <div class="object elven animated slideExpandUp" objID="2">
                                            
                                            <div class="obj_img" style="background: url('../images/objects/hiz1.png') center no-repeat; background-size: contain !important;"></div>
                                                                                        <div class="cl-info pointercursor"></div>
                                            <div class="cl-info-info" objID="2">
                                                <div class="content">
                                                    This is the dwelling place of the elven elders, masters of the water. With their help You are to enclose the greatest knowledge of this world, you are also to enclose the secrets of such legendary buildings as Earth Spirit or Magic Tree.                                                    <!--<small>Нажмите, чтобы скрыть</small>-->
                                                </div>
                                            </div>

                                            <div class="obj_inf" objID="2">
                                                <div class="obj_name"><div>The Hut</div></div>
                                                <div class="obj_price">
                                                    Price: <?php echo $sonfig_site["amount_b_t"]; ?> <span class="ic-gold2"></span>
                                                                                                    </div>
                                                <div class="obj_price">
                                                    <?php echo $sonfig_site["b_in_h"]; ?> <span class="ic-ruby"></span> / hour                                                                                                        
                                                </div>
												<div class="obj_price">
                                                    <span><?php echo $user_data["b_t"]; ?> in your Empire</span>                                                                                
                                                </div>
												                            

                                                <!--<div class="abilities">
                                                                                                    </div>-->
																									<form action="" method="post">
																									<input type="hidden" name="item" value="2" />
                                                                                                <button type="submit" class="btn-small buy-obj-btn" objID="2" smsg="<b>Congratulations! You have successfully purchased  'The Hut'.<br/>Place the building on the game field to start gain income </b>">Buy</button>
                                                                                            </form>
																							</div>
                                            <div class="decor middle"></div>

                                        </div>
                                                                                                                                                                <div class="object elven animated slideExpandUp" objID="3">
                                            
                                            <div class="obj_img" style="background: url('../images/objects/rez1.png') center no-repeat; background-size: contain !important;"></div>
                                                                                        <div class="cl-info pointercursor"></div>
                                            <div class="cl-info-info" objID="3">
                                                <div class="content">
                                                    The House of elves. It is the place for elves of the middle rank. Using the residence you may increase the population of the city.                                                    <!--<small>Нажмите, чтобы скрыть</small>-->
                                                </div>
                                            </div>

                                            <div class="obj_inf" objID="3">
                                                <div class="obj_name"><div>The Residence</div></div>
                                                <div class="obj_price">
                                                    Price: <?php echo $sonfig_site["amount_c_t"]; ?> <span class="ic-gold1"></span>
                                                                                                    </div>
                                                <div class="obj_price">
                                                    <?php echo $sonfig_site["c_in_h"]; ?> <span class="ic-emerald"></span> / hour                                                                                                      
                                                </div>
                                                <div class="obj_price">
                                                    <span><?php echo $user_data["c_t"]; ?> in your Empire</span>                                                                                
                                                </div>
																									<form action="" method="post">
																									<input type="hidden" name="item" value="3" />
                                                                                                <button type="submit" class="btn-small buy-obj-btn" objID="3" smsg="<b>Congratulations! You have successfully purchased  'The Residence'.<br/>Place the building on the game field to start gain income </b>">Buy</button>
                                                                                            </form>
																							</div>
                                            <div class="decor middle"></div>

                                        </div>
                                                                                                                                                                <div class="object elven animated slideExpandUp" objID="4">
                                            
                                            <div class="obj_img" style="background: url('../images/objects/erez1.png') center no-repeat; background-size: contain !important;"></div>
                                                                                        <div class="cl-info pointercursor"></div>
                                            <div class="cl-info-info" objID="4">
                                                <div class="content">
                                                    This is the High house of elves. It is the place for elves of high rank. Your city gets more prestigious status.                                                    <!--<small>Нажмите, чтобы скрыть</small>-->
                                                </div>
                                            </div>

                                            <div class="obj_inf" objID="4">
                                                <div class="obj_name"><div>The Elite Residence</div></div>
                                                <div class="obj_price">
                                                    Price: <?php echo $sonfig_site["amount_d_t"]; ?> <span class="ic-gold2"></span>
                                                                                                    </div>
                                                <div class="obj_price">
                                                    <?php echo $sonfig_site["d_in_h"]; ?> <span class="ic-ruby"></span> / hour                                                                                                       
                                                </div>
                                                <div class="obj_price">
                                                    <span><?php echo $user_data["d_t"]; ?> in your Empire</span>                                                                                
                                                </div>
																									<form action="" method="post">
																									<input type="hidden" name="item" value="4" />
                                                                                                <button type="submit" class="btn-small buy-obj-btn" objID="4" smsg="<b>Congratulations! You have successfully purchased  'The Elite Residence'.<br/>Place the building on the game field to start gain income </b>">Buy</button>
                                                                                            </form>
																							</div>
                                            <div class="decor middle"></div>

                                        </div>
                                                                                                                                                                <div class="object elven animated slideExpandUp" objID="5">
                                            
                                            <div class="obj_img" style="background: url('../images/objects/academy1.png') center no-repeat; background-size: contain !important;"></div>
                                                                                        <div class="cl-info pointercursor"></div>
                                            <div class="cl-info-info" objID="5">
                                                <div class="content">
                                                    This is the Place where young elves learn science, the basics of martial arts and of the magic. It is an integral part of the city that raises its level of education and prestige.                                                    <!--<small>Нажмите, чтобы скрыть</small>-->
                                                </div>
                                            </div>
											

                                            <div class="obj_inf" objID="5">
                                                <div class="obj_name"><div>The Elf Academy</div></div>
                                                <div class="obj_price">
                                                    Price: <?php echo $sonfig_site["amount_e_t"]; ?> <span class="ic-gold1"></span>
                                                                                                    </div>
                                                <div class="obj_price">
                                                    <?php echo $sonfig_site["e_in_h"]; ?> <span class="ic-emerald"></span> / hour                                                                                                        
                                                </div>
                                                <div class="obj_price">
                                                    <span><?php echo $user_data["e_t"]; ?> in your Empire</span>                                                                                
                                                </div>
																									<form action="" method="post">
																									<input type="hidden" name="item" value="5" />
                                                                                                <button type="submit" class="btn-small buy-obj-btn" objID="5" smsg="<b>Congratulations! You have successfully purchased  'The Elf Academy'.<br/>Place the building on the game field to start gain income </b>">Buy</button>
                                                                                            </form>
																							</div>
                                            <div class="decor middle"></div>

                                        </div>
                                                                                                                                                                <div class="object elven animated slideExpandUp" objID="6">
                                            
                                            <div class="obj_img" style="background: url('../images/objects/zeml1.png') center no-repeat; background-size: contain !important;"></div>
                                                                                        <div class="cl-info pointercursor"></div>
                                            <div class="cl-info-info" objID="6">
                                                <div class="content">
                                                    This is the preserved monument that praises the powerful elf, who ever lived - Thingol, courage and strength that amazed even the Gods.                                                    <!--<small>Нажмите, чтобы скрыть</small>-->
                                                </div>
                                            </div>

                                            <div class="obj_inf" objID="6">
                                                <div class="obj_name"><div>The Earth Spirit</div></div>
                                                <div class="obj_price">
                                                    Price: <?php echo $sonfig_site["amount_f_t"]; ?> <span class="ic-gold2"></span>
                                                                                                    </div>
                                                <div class="obj_price">
                                                    <?php echo $sonfig_site["f_in_h"]; ?> <span class="ic-ruby"></span>/ hour                                                                                                        
                                                                                                      
                                                </div>
                                                <div class="obj_price">
                                                    <span><?php echo $user_data["f_t"]; ?> in your Empire</span>                                                                                
                                                </div>
                                                                                                                                                                                                    
																					<form action="" method="post">																												
														<input type="hidden" name="item" value="6" />															
																																																
																<button type="submit" class="btn-small buy-obj-btn" objID="2" smsg="<b>Congratulations! You have successfully purchased  'The Hut'.<br/>Place the building on the game field to start gain income </b>">Buy</button>

                                                                                                                                              </form>

                                                                                            </div>
                                            <div class="decor middle"></div>

                                        </div>
                                                                                                                                                                <div class="object elven animated slideExpandUp" objID="7">
                                            
                                            <div class="obj_img" style="background: url('../images/objects/mast1.png') center no-repeat; background-size: contain !important;"></div>
                                                                                        <div class="cl-info pointercursor"></div>
                                            <div class="cl-info-info" objID="7">
                                                <div class="content">
                                                    Here works the craftsmen. They do not use any weapon or any power: either astral, or marine, or flaming. 
They do not study any mysterious spell or the sacred book. However, even the greatest people turn to their assistance. They create the stuff that enables to reach the heights.                                                    <!--<small>Нажмите, чтобы скрыть</small>-->
                                                </div>
                                            </div>

                                            <div class="obj_inf" objID="7">
                                                <div class="obj_name"><div>The Workshop</div></div>
                                                
                                                <div class="obj_price">
                                                     <img src="/img/coming.png" >
                                                                                                
                                                                                            </div>
                                           </div> 
										   <div class="decor middle"></div>

                                        </div>
                                                                                                                                                                <div class="object elven animated slideExpandUp" objID="8">
                                            
                                            <div class="obj_img" style="background: url('../images/objects/trader1.png') center no-repeat; background-size: contain !important;"></div>
                                                                                        <div class="cl-info pointercursor"></div>
                                            <div class="cl-info-info" objID="8">
                                                <div class="content">
                                                    It is an informal centre of the city. At this, it is an economical centre. The vivacity here draws to a head.                                                    <!--<small>Нажмите, чтобы скрыть</small>-->
                                                </div>
                                            </div>

                                            <div class="obj_inf" objID="8">
                                                <div class="obj_name"><div>The Marketplace</div></div>
                                                
                                               <div class="obj_price">
                                                     <img src="/img/coming.png" >
                                                                                                
                                                                                            </div>

                                                <!--<div class="abilities">
                                                    <p>Приносит увеличенный доход. Требуется Усадьба эльфов 7 уровень, Резиденция 3 уровня.</p>
                                                </div>-->
                                                                                                    
                                                   <script>$('.object[objID=8]').addClass('disabled');</script>
                                                                                            </div>
                                            <div class="decor middle"></div>

                                        </div>
                                           </div>
                            
                        </div>
                    </div>
                </div>
            </div>
			<?PHP echo "<script type='text/javascript'>$(document).ready(function(){show_message({'hi',1,6000); });</script>"; ?>
          <div class="pc-message elven" id="msgw1">								
	        <div class="msg-type sm-success"></div>
	        <div class="content">Simple Text Message</div> 
	        <div class="decor middle"></div>
            <div class="decor left"></div>
            <div class="decor right"></div>
	    </div>
		  <div class="devider bottom"></div>
        </section> 