<?php

class test extends CodonModule
{
	public function index()
	{
		$this->render('test/index.php');
	}
	
	
	public function upload() {
			
			if (!$_FILES['avatar']['type']) return false;

        # Create the image so we can convert it to PNG
        if ($_FILES['avatar']['type'] == 'image/gif') {
            $img = imagecreatefromgif($_FILES['file']['tmp_name']);
        } elseif ($_FILES['avatar']['type'] == 'image/jpeg' || $_FILES['avatar']['type'] ==
        'image/pjpeg') {
            $img = imagecreatefromjpeg($_FILES['avatar']['tmp_name']);
        } elseif ($_FILES['avatar']['type'] == 'image/png') {
            $img = imagecreatefrompng($_FILES['avatar']['tmp_name']);
        }

        # Resize it
        $height = imagesy($img);
        $width = imagesx($img);

        $new_width = Config::Get('AVATAR_MAX_WIDTH');
        $new_height = floor($height * (Config::Get('AVATAR_MAX_HEIGHT') / $width));

        $avatarimg = imagecreatetruecolor($new_width, $new_height);
        imagecopyresized($avatarimg, $img, 0, 0, 0, 0, $new_width, $new_height, 
                            $width, $height /* original */
            );

        # Output the file, to /lib/avatar/pilotcode.png
        $pilotCode = PilotData::getPilotCode(Auth::$userinfo->code, Auth::$userinfo->pilotid).'_'.Auth::$userinfo->hub;
        imagepng($avatarimg, SITE_ROOT . AVATAR_PATH . '/' . $pilotCode . '.png');
        imagedestroy($img);
		
		$message = "Saved as ".$pilotCode;
			
        $this->set('message', $message);
        $this->show('core_notification.php');
        $this->render('test/index.php');
	}
	public function rfinder() {
		$this->render('test/routefinder.php');
	}
}
	
	?>