Вход Регистрация
Файл: wenr.online/app/user/bagCat.php
Строк: 46
<?php

if (!$user->isAuth()) {
    
redirect('/');
    exit;
}


    
$cat = $db->prepare('select * from `catBag` where `id` = ?');
    
$cat -> execute([Clean :: int($_GET['id'])]);
    
$cat = $cat -> fetch(PDO :: FETCH_OBJ);
            if(!isset(
$cat->id)){
                
redirect('/bag');
                exit;
            }
            
            

    
$all = $db->prepare('select * from `bag` where user = ? and type = ? order by name');
    
$all -> execute([$user->get()->user_id,$cat->table]);
    
$all = $all->fetchAll();
    function 
plus($id){
        global 
$db;
        
$item = $db->prepare('select * from bag where id = ?');
        
$item -> execute([$id]);
        
$item = $item -> fetch(PDO :: FETCH_OBJ);
        
$type = false;
        if(
$item->force > 0) $type .= '+ '.$item->force.' к силе ';
        if(
$item->dex > 0) $type .= '+ '.$item->dex.' к ловкости ';
        if(
$item->hp > 0) $type .= '+ '.$item->hp.' к жизни ';
        if(
$item->max_hp > 0) $type .= '+ '.$item->max_hp.' к жизни ';
        if(
$item->mana > 0) $type .= '+ '.$item->mana.' к мане ';
        if(
$item->mana_max > 0) $type .= '+ '.$item->mana_max.' к мане ';
        if(
$item->type == 'rolls') $type = $item->force.' урона. Требует '.$item->mana.' <img src="/public/assets/images/mana.png">';
        return 
$type;
        
    }
 
 
    function 
type($id){
        global 
$db;
        
$item = $db->prepare('select * from `bag` where `id` = ?');
        
$item -> execute([$id]);
        
$item = $item -> fetch(PDO :: FETCH_OBJ);
        
        if(
$item ->status == 1) $return = 'Снять';
        if(
$item ->status == 0) $return = 'Надеть';
        if(
$item->type == 'potion') $return = 'Использовать';
        
        if(
$item->type == 'drop') $return = 'Продать за '.$item->bonus.' <img src="/public/assets/images/zoloto.png">';
        return 
$return;
    }
 
    function 
array_unique_key($array, $key) { 
    
$tmp = $key_array = array(); 
    
$i = 0; 
 
    foreach(
$array as $val) { 
        if (!
in_array($val[$key], $key_array)) { 
            
$key_array[$i] = $val[$key]; 
            
$tmp[$i] = $val; 
        } 
        
$i++; 
    } 
    return 
$tmp; 
    }
  
    function 
count_item($item){
        global 
$db,$user;
    
    
$sql = $db->prepare('select `id` from bag where name = ? and user = ?');
    
$sql -> execute([$item,$user->get()->user_id]);
    return 
$sql ->rowCount();
    }
 
    if(
$cat->table == 'drop' or $cat->table == 'potion') $all = array_unique_key($all,'name');
 
     
$peger = new ArrayPaginator('/bag/cat?id='.$cat->id, 10); 
    
$items = $peger->getItems($all);
    
    
    
$sell = $db->prepare('select SUM(`bonus`) as gold  from `bag` where `type` = ? and `user` = ?');
    
$sell -> execute(['drop',$user->get()->user_id]);
    
$sell = $sell -> fetch(PDO :: FETCH_OBJ);
    

echo 
$template->render('user.bagCat',
                                [
'peger'  =>  $peger,
                                 
'item'    => $items,
                                 
'cat'  =>  $cat,
                                 
'sell' => $sell
                                                            
]    
                                    );
Онлайн: 2
Реклама