View Single Post
  #16  
Old 02-17-2016, 09:13 PM
Kyttias's Avatar
Kyttias Kyttias is offline
Premium Member
 
Join Date: Jan 2014
Posts: 857
Gender: Unknown/Other
Credits: 88,134
Kyttias is on a distinguished road
Default

Aaack, I meant to mention this on the original thread but now I can't even find the if statement I wrote up. This can definitely be easily fixed.

Here's the file with changes:
PHP Code:
<?php

use Resource\Native\Integer;
use 
Resource\Native\String;
use 
Resource\Native\Arrays;
use 
Resource\Native\Null;

class 
NAMEController extends AppController{

    public function 
__construct(){
        
parent::__construct("member");
        
$mysidia Registry::get("mysidia");
        if(
$mysidia->usergroup->getpermission("canadopt") != "yes"){
            throw new 
NoPermissionException("permission");
        }    
    }
    
    public function 
index(){ 
        
$mysidia Registry::get("mysidia");         
        if(
$mysidia->input->post("submit")){ 
            
$this->access "member"
            
$this->handleAccess(); 
            
$id $mysidia->input->post("id"); 
            if(
$mysidia->session->fetch("adopt") != or !$id) throw new InvalidIDException("global_id");             
             
            
$adopt = new Adoptable($id); 
            
$conditions $adopt->getConditions(); 
            if(!
$conditions->checkConditions()) throw new NoPermissionException("condition"); 
             
            
$name = (!$mysidia->input->post("name"))?"Unnamed":$mysidia->input->post("name"); 
            
$alts $adopt->getAltStatus(); 
            
$code $adopt->getCode(); 
            
$gender $adopt->getGender(); 


            
$cost $mysidia->db->select("adoptables", array("cost"), "type='{$adopt->getType()}'")->fetchColumn();
            
$moneyleft $mysidia->user->money $cost;

            if(
$moneyleft >= 0){ 
                
$mysidia->user->changecash(-$cost);
                
$mysidia->db->insert("owned_adoptables", array("aid" => NULL"type" => $adopt->getType(), "name" => $name"owner" => $mysidia->user->username"currentlevel" => 0"totalclicks" => 0"code" => $code,  
                                                                   
"imageurl" => NULL"usealternates" => $alts"tradestatus" => 'notfortrade'"isfrozen" => 'no'"gender" => $gender"offsprings" => 0  )); 
                    
                
$aid $mysidia->db->select("owned_adoptables", array("aid"), "code='{$code}' and owner='{$mysidia->user->username}'")->fetchColumn(); 
                
$this->setField("aid", new Integer($aid)); 
                
$this->setField("name", new String($name));             
                
$this->setField("eggImage", new String($adopt->getEggImage()));  

                 return 
TRUE;           
            }
          else throw new 
InvalidActionException("Sorry, you cannot afford this transaction.");
        }  
        
        
$mysidia->session->assign("adopt"1TRUE);
        
$ids $mysidia->db->select("adoptables", array("id"), "shop='NAME'")->fetchAll(PDO::FETCH_COLUMN);
        
$total = ($ids)?count($ids):0;
        
        if(
$total == 0$adopts = new Null;
        else{        
            
$adopts = new Arrays($total);
            
$available 0;
            
            foreach(
$ids as $id){
                
$adopt = new Adoptable($id);
                
$conditions $adopt->getConditions();    
                  if(
$conditions->checkConditions()) $adopts[$available++] = $adopt;    
            }
            
            if(
$available == 0$adopts = new Null;
            else 
$adopts->setSize($available);            
        }        
        if(
$adopts instanceof Null) throw new InvalidActionException("adopt_none");
        
$this->setField("adopts"$adopts);
    }
}
?>
(*Remember to change the two instances of NAME.)

What I modified specifically:
PHP Code:
$cost $mysidia->db->select("adoptables", array("cost"), "type='{$adopt->getType()}'")->fetchColumn();
$moneyleft $mysidia->user->money $cost;

if(
$moneyleft >= 0){ 
    
$mysidia->user->changecash(-$cost);
    
$mysidia->db->insert("owned_adoptables", array("aid" => NULL"type" => $adopt->getType(), "name" => $name"owner" => $mysidia->user->username"currentlevel" => 0"totalclicks" => 0"code" => $code,  
                                                       
"imageurl" => NULL"usealternates" => $alts"tradestatus" => 'notfortrade'"isfrozen" => 'no'"gender" => $gender"offsprings" => 0  )); 
        
    
$aid $mysidia->db->select("owned_adoptables", array("aid"), "code='{$code}' and owner='{$mysidia->user->username}'")->fetchColumn(); 
    
$this->setField("aid", new Integer($aid)); 
    
$this->setField("name", new String($name));             
    
$this->setField("eggImage", new String($adopt->getEggImage()));  

     return 
TRUE;           
}
else throw new 
InvalidActionException("Sorry, you cannot afford this transaction."); 
__________________
Please do not contact me directly outside of Mysidia.
I also cannot troubleshoot code more than two years old - I legit don't remember it.

Last edited by Kyttias; 02-17-2016 at 09:24 PM.
Reply With Quote