<?php defined('SYSPATH') or die('No direct script access.'); 

        class Controller_Player extends Controller { 
    
            public function action_playerstatus() 
            {
             
               $me = Session::instance()->get("fbUserId");


              // throw new exception($me);
           $player = ORM::factory("player")->where('teamid','=',$me)->find_all()->as_array();


	    //throw new Exception($team[0]->id);
		$data = array("player" => $player);
                
                //$view = View::factory("player",$data);
	
               
                $view = View::factory("player",$data);  
                $this->request->response = $view;  // 
            

            }
public function action_changetrainingtype()
        {
        $me = Session::instance()->get("fbUserId");

        $player = ORM::factory("player")->where('id','=',$me)->find();
        $training = ORM::factory("training")->where('id','=',$me)->find();
       
        if($_POST){
            $new = $_POST["type"];
            if($new == "Goalkeeping")
            {
            $training->training_type = 1;
            }
            elseif($new == "Passing")
            {
            $training->training_type = 2;
            }
            elseif($new == "Playmaking")
            {
            $training->training_type = 3;
            }
            elseif($new == "Scoring")
            {
            $training->training_type = 4;
            }
            elseif($new == "Defending")
            {
            $training->training_type = 5;
            }
            elseif($new == "Winger")
            {
            $training->training_type = 6;
            }
            elseif($new == "Technique")
            {
            $training->training_type = 7;
            }
            $training->save();
        }
       
        $data = array("training" => $training, "player" => $player);
       
        $view = View::factory("player",$data);  //viewin çaðrýldýðý yer
                $this->request->response = $view;  // .= eklenmesini saðlýyor.
        }
       
        public function action_changetrainingeffect()
        {
        $me = Session::instance()->get("fbUserId");
        $player = ORM::factory("player")->where('id','=',$me)->find();
        $training = ORM::factory("training")->where('id','=',$me)->find();
       
        if($_POST){
            $new = $_POST["intensity"];
            if($new<101)
            $training->training_effect = $new;
            $training->save();
        }
       
        $data = array("training" => $training, "player" => $player);
       
        $view = View::factory("player",$data);  //viewin çaðrýldýðý yer
                $this->request->response = $view;  // .= eklenmesini saðlýyor.
        }
       
        public function action_training()
        {
        $me = Session::instance()->get("fbUserId");
        $player = ORM::factory("player")->where('teamid','=',$me)->find();
        $training = ORM::factory("training")->where('id','=',$me)->find();
       
        $data = array("training" => $training, "player" => $player);
       
        $view = View::factory("player",$data);  //viewin çaðrýldýðý yer
                $this->request->response = $view;  // .= eklenmesini saðlýyor.
        }


	    public function action_sell($sellid=0) 
            {
		$me = Session::instance()->get("fbUserId");
		$player = ORM::factory("player")->where('id','=',$sellid)
						->find();
		$player->sale = TRUE;
                $player->searchid=$player->id;
$player->value = $player->goalkeeping + $player->defending + $player->playmaking + $player->winger + $player->scoring + $player->technique + $player->passing;
                                if($player->goalkeeping>$player->playmaking && $player->goalkeeping > $player->scoring && $player->goalkeeping > $player->defending)
                                $player->value = $player->value * $player->goalkeeping * 100 + $player->value * $player->passing * 10 + $player->value * $player->winger * 10 + $player->value * $player->technique * 10;
                                elseif($player->playmaking >= $player->goalkeeping && $player->playmaking >= $player->scoring && $player->playmaking >= $player->defending)
                                $player->value = $player->value * $player->playmaking * 100 + $player->value * $player->passing * 10 + $player->value * $player->winger * 10 + $player->value * $player->technique * 10;
                                elseif($player->scoring >= $player->playmaking && $player->scoring >= $player->goalkeeping && $player->scoring >= $player->defending)
                                $player->value = $player->value * $player->scoring * 100 + $player->value * $player->passing * 10 + $player->value * $player->winger * 10 + $player->value * $player->technique * 10;
                                elseif($player->defending >= $player->playmaking && $player->defending >= $player->goalkeeping && $player->defending >= $player->scoring)
                                $player->value = $player->value * $player->defending* 100 + $player->value * $player->passing * 10 + $player->value * $player->winger * 10 + $player->value * $player->technique * 10;
                                else
                                $player->value = $player->value * 100 + $player->value * $player->passing * 10 + $player->value * $player->winger * 10 + $player->value * $player->technique * 10;
		//playerin satis degeri ve alinacak vergi hesaplanacak
		$player->save();
		$player = ORM::factory("player")->where('teamid','=',$me)->find_all()->as_array();
		$data = array("player" => $player);
                
                $view = View::factory("player",$data); 
                $this->request->response = $view;  
            

            }
	    public function action_dismiss($dismissid)
            {
		$me = Session::instance()->get("fbUserId");
		$player = ORM::factory("player")->where('id','=',$dismissid)
						->find();
		$player->teamid = 0;
		$player->value = 1000; //aciga cikan oyuncunun degeri hesaplanacak
		$player->sale = TRUE;
                $player->searchid=$player->id;
		$player->save();
		$player = ORM::factory("player")->where('teamid','=',$me)->find_all()->as_array();
		$data = array("player" => $player);
                
                $view = View::factory("player",$data);  
                $this->request->response = $view;  
            

            }
        
    
        }

?>