<?php
//session_start();
/* This controller renders  the home page */

class TryLoginController{
	public function handleRequest(){
            //session_start();
            global $defaultHomeLink;
            $test = Login::find(array('comnum'=>$_POST['companies'],'uname'=>$_POST['name'],
            'pword'=>$_POST['pass']));
            $y=0;
            foreach($test as $arx){
                foreach($arx as $zxz){
                $zx2[$y]=$zxz;
                //echo $zx2[$y].'--'.$y.'_-';
                $y++;    
                }
                     
            }
                   
             if ($test){
                $ttts1 = bill_get_company($zx2[1]);
                $_SESSION['auth'] = 'true';
                $_POST['login'] = 'true';
                $_SESSION['user'] = ''.$zx2[3].'';
                $_SESSION['masterid'] = ''.$zx2[0].'';
                $_SESSION['account'] = ''.$zx2[2].'';
                $_SESSION['companyname'] = ''.$ttts1['0']['name'].'';
                $_SESSION['comnum'] = ''.$zx2[1].'';
                $_SESSION['logged'] = true;
                $_SESSION['wrongt'] = 0;
                } else {
                $_POST['login']=false;
                $_SESSION = array();
            echo '<script type=text/javascript>
alert("You have entered the Wrong Username or Password!");</script>';
            //print_r($test);
            }
    	echo '<script type=text/javascript>parent.location.href = "'.$defaultHomeLink.'";</script>';
        }    
            
}
?>
