public function processAction()
    { 
    	$request = $this->getRequest();
    	

        // Check if we have a POST request
        if (!$request->isPost()) {
            return $this->_helper->redirector('index');
        }
        

        // Get our form and validate it
        $form = $this->getForm();
        
        
        // Validate username and password for matching criteria
        if (!$form->isValid($request->getPost())) 
        {
            // Invalid entries
            $this->view->form = $form;
            return $this->render('index'); // re-render the login form
        }
        echo "valid";

        // Get our authentication adapter and check credentials
        
        /*$adapter = $this->getAuthAdapter($form->getValues());
        $auth    = Zend_Auth::getInstance();
        $result  = $auth->authenticate($adapter);
        
        if (!$result->isValid()) 
        {
            // Invalid credentials
            $form->setDescription('Invalid credentials provided');
            $this->view->form = $form;
            return $this->render('index'); // re-render the login form
        }*/
        
        // Validate against LDAP 
        
        // Validate against matrix database
        $username = $form->getValue('username');
        print_r($username);
        $password = $form->getValue('password');
        
        $userService = new App_UserService();
        $valid = $userService->ValidUserPassword($username, $password);
        
        if ($valid)
        {
	 //echo"sdfasdf";
        	//$this->error_flag = FALSE;
        	//$this->view->error_flag = $this->error_flag;
        	$userRole = $userService->GetUserRole($username);
       		
        	if ($userRole == 'U' || $userRole == 'L' || $userRole == 'G')
        	{
        		$this->_helper->redirector('index', 'student');
        	}
        	else if ($userRole == 'F')
        	{
        		$this->_helper->redirector('index', 'faculty');
        	}
        	
        	//$this->_helper->redirector('index', 'index');
        }
        else
        {
        	// Redirect to the login page
        	//$this->view->error_flag = TRUE;
        	//$this->view->error_flag = $this->error_flag;
        	
        	$this->_helper->redirector('index', 'user');
        }
        
        /*
        $dbAdapter = Zend_Db_Table::getDefaultAdapter();
        /*$authAdapter = new Zend_Auth_Adapter_DbTable($dbAdapter);
        
        $authAdapter->setTableName('user');
        $authAdapter->setIdentityColumn('username');
		$authAdapter->setCredentialColumn('password');
        $authAdapter->setCredentialTreatment('MDS(?');
        
        // Pass to the adapter the submitted username and password
        $authAdapter->setIdentity($username);
        $authAdapter->setCredential($password);*/
        
        // We're authenticated! Redirect to the home page
        //$this->_helper->redirector('index', 'index');	
        //echo 'hi';
    }
    /**
     * KG and PA
     * Log the user in and display the correct homepage
     * This function is called when the login button is pressed.
     * 
     * First it checks the eneered username and password to determine 
     * whether the inputs could be considered valid (long enough username and password,
     * only alpha-numeric characters, etc...)
     * If not, it informs the user and stops executing
     * 
     * Then it queries the matrix user database to determine if the user is actually
     * in the database. If the user was found, it verifies their password with LDAP
     *
     * If the username/password combination was correct, the function queries the user database
     * to determine whether to display the student or faculty page. Otherwise, 
     * take the user back to the login screen and inform them of error.
     */
    
    public function processAction()
    { 
    	$request = $this->getRequest();
    	
        // Check if we have a POST request
        if (!$request->isPost()) {
            return $this->_helper->redirector('login_start');
        }
        
        // Get our form and validate it
        $form = $this->getForm();
        
        
        // Validate username and password for matching criteria
        if (!$form->isValid($request->getPost())) 
        {
            // Redirect to the login page and set error flag	
			$this->_redirect('/index/index/error_flag/TRUE');
        	exit();
        }
        
        //Get username and password
        $username = $form->getValue('username');
        $password = $form->getValue('password');
        
        //check whether user exists in the user table
        $userService = new App_UserService();
        $valid = $userService->ValidUser($username);
        
        
        //If the user exists, validate password with LDAP
        if($valid)
        {
	        $auth = Zend_Auth::getInstance();
	        $authAdapter = new Zend_Auth_Adapter_Ldap(
	                                   array(
	                                           'server' => array(
	                                           'host' => 'ldap.nccnet.noctrl.edu',
	                                           'baseDn' => 'OU=Napvil,O=NCC',
	                                           'bindRequiresDn' => true,
	                                                                   ),
	                                   ), $username, $password
	                           );
	      	$authResult = $auth->authenticate($authAdapter);
	      	if ($authResult->isValid())
	       	{
	       		$valid = TRUE;
	       	} 
	       	else
	       	{
	       		$valid = FALSE;
	       	}
        }
        
        
        if ($valid)
        {
        	$this->view->error_flag = FALSE;
        	$userRole = $userService->GetUserRole($username);
       		
        	if ($userRole == 'U' || $userRole == 'L' || $userRole == 'G')
        	//user is a student
        	{
        		$this->_helper->redirector('index', 'student');
        	}
        	else
        	//user is faculty
        	{
        		$this->_helper->redirector('index', 'faculty');
        	}
        	
        }
        else
        {
        	// Redirect to the login page and set error flag	
			$this->_redirect('/index/index/error_flag/TRUE');
        	exit();
        }
        
    }