Location: PHPKode > projects > Homeless Mangement Information System > hmis/include/Questions_answers_validation_class.inc
<?php
//////This class checks the inputted variables fed to it to make sure that they don't contain illegal characters, are too long, are blank when required, etc.

class Questions_answers_validation
{
	var $questions;
	var $question_elements;
	var $form_answer;
	//The value checked and returned to form
	var $vetted_form_answer;
	//The vetted value that can be inserted into a database
	var $vetted_value;
	var $head_dynamic_style;
	var $question_validation_error;
    var $x_array;
    var $y_array;
    var $table_question_attributes;




	///////////////////////////////////////////////////////////////////////////////////
	// FUNCTION: Questions_answers_validation()                                      //
	///////////////////////////////////////////////////////////////////////////////////
	function Questions_answers_validation ($questions, $question_elements, $form_answers)
    {
		//echo '<table border=1 bordercolor=purple><tr><td>Questions_answers_validation() A:'.pretty_var_dump($form_answers).'</td><td>Q:<font size=1>'.pretty_var_dump($questions).'</font></td></tr></table>';
        
		$this->question_elements = $question_elements;
		$this->form_answer = $form_answers;
		
		//Had to add settype because I was getting a warning that $questions was not an array, even though it returned the right output
		if (!is_array($questions))
			settype ( $questions, 'array' );
		
		foreach ($questions AS $current_question)	{
			//$e++;
			//echo $e." === ".$current_question["question_type"]."-".$current_question["question_title"]."<br/>";
			switch ($current_question["question_type"])	{

				case "text":
					$this->validate_text_question_answer ($current_question);
					break;

				case "number":
					$this->validate_number_question_answer ($current_question);
					break;
					
				case "checkboxes":
					$this->validate_checkboxes_question_answer ($current_question, $question_elements[$current_question["question_id"]]);
					break;

				case "radio":
					$this->validate_radio_buttons_question_answer ($current_question, $question_elements[$current_question["question_id"]]);
					break;

				case "dropdown":
					$this->validate_radio_buttons_question_answer ($current_question, $question_elements[$current_question["question_id"]]);
					break;

				case "textarea":
					if ( $current_question["question_special_attribute"] )  {
                        $current_question["question_field_size"] = $current_question["question_special_attribute"] + 0;    
                    }
                    else {
                        $current_question["question_field_size"] = $current_question["question_field_size"] * $current_question["question_display_size"];
                    }    
					
					$this->validate_text_question_answer ($current_question);
					break;
                    
                case "table":
					$this->validate_table_question_answer ($current_question, $question_elements[$current_question["question_id"]]);
					break;
                    
                case "date":
					$this->validate_date_question_answer ($current_question);
					break;
                    
                case "password":
					$this->validate_text_question_answer ($current_question);
					break;

				default:
					echo "I am default question validation switch--".htmlspecialchars($current_question["question_type"]."__ID: ".$current_question["question_id"])."<br/>"; 
					//foreach($current_question AS $key => $value)	{
					//	echo $key."&nbsp;&nbsp;".$value."<br/>";
					//												}
					//exit;
                    //echo $current_question["question_type"];
			}
		}
		//echo '<table border=1 bordercolor=purple><tr><td>Questions_answers_validation() VetAns:'.pretty_var_dump($this->vetted_form_answer).'</td><td>VetVal:'.pretty_var_dump($this->vetted_value).'</td></tr></table>';
	}




	///////////////////////////////////////////////////////////////////////////////////
	// FUNCTION: validate_text_question_answer()                                     //
	///////////////////////////////////////////////////////////////////////////////////
	function validate_text_question_answer ($question_attributes_array)
    {
		$question_id = $question_attributes_array['question_id'];
		
		if(ereg("[^A-Za-z0-9\)\[:space:]\(\.\?\,\"\!\#\%\'\&\$\@\/\=\:\_\>\<\*\}\{\+\-]", $this->form_answer[$question_id]))
        {
        //if(ereg("[^A-Za-z0-9\)\(\.\?\,\@\/\=\:\_\[:space:]\>\<\#\-]", $this->form_answer[$question_id]))	{
			question_error_marking ($question_id, "Only Letters, Numbers, and the Characters \".\", \"?\", \")\", \"(\", \"-\", \"/\", \"=\", \":\", \"_\" and \",\" Allowed. ");
		}
		
		$this->vetted_form_answer[$question_id] = trim($this->form_answer[$question_id]);
         
        
		if(strlen ($this->vetted_form_answer[$question_id]) > $question_attributes_array["question_field_size"])
        {
            $adjusted_length = $question_attributes_array["question_field_size"];
        
			question_error_marking ($question_id, "Answer too Long. Overflow cut off. ");
			$this->vetted_form_answer[$question_id] = substr ($this->vetted_form_answer[$question_id], 0, $adjusted_length);
	    }
        
        //if magic quotes is turned on 
        if ( get_magic_quotes_gpc() )
        {
            //...assign the value to be put in the database 
            $this->vetted_value[$question_id] = $this->vetted_form_answer[$question_id];
            $this->vetted_form_answer[$question_id] = stripslashes($this->vetted_form_answer[$question_id]);
        }
        //..no slashes added, so add them for insertion into database
        else
        {
            $this->vetted_value[$question_id] = addslashes($this->vetted_value[$question_id]);
        }
        
        
        $this->vetted_form_answer[$question_id] = htmlentities($this->vetted_form_answer[$question_id]);
        
        //echo $this->vetted_form_answer[$question_id];
        //Replace certain html entities with specific html
        if ( $question_attributes_array["question_type"] == "textarea" )
        {
            //Convert <b>...</b> to a style
            $this->vetted_form_answer[$question_id] = str_replace ( "&lt;b&gt;", "<span class=\"txtareabold\">", $this->vetted_form_answer[$question_id] );
            $this->vetted_form_answer[$question_id] = str_replace ( "&lt;/b&gt;", "</span>", $this->vetted_form_answer[$question_id] );
            
            //Replace htmlentitied span with real span
            $this->vetted_form_answer[$question_id] = str_replace ( "&lt;span class=\&quot;", "<span class=\"", $this->vetted_form_answer[$question_id] );
            $this->vetted_form_answer[$question_id] = str_replace ( "&lt;/span&gt;", "</span>", $this->vetted_form_answer[$question_id] );
            
            //Replace htmlentitied <a href... with real link
            $this->vetted_form_answer[$question_id] = str_replace ( "&lt;a href=\&quot;", "<a href=\"", $this->vetted_form_answer[$question_id] ); 
            $this->vetted_form_answer[$question_id] = str_replace ( "\&quot;&gt;", "\">", $this->vetted_form_answer[$question_id] );
            $this->vetted_form_answer[$question_id] = str_replace ( "&lt;/a&gt;", "</a>", $this->vetted_form_answer[$question_id] );
            //$this->vetted_form_answer[$question_id] = str_replace ( "&gt;", ">", $this->vetted_form_answer[$question_id] );
        }
        
		if ( $question_attributes_array["question_type"] == "textarea" )
        {
            $db_field_size = 500000;
        }
        else
        {
            $db_field_size = 500;
        }
        
        //Make sure that the answer is not larger than the database field allows after adding HTML entitities, etc
        if ( strlen ( $this->vetted_form_answer[$question_id] ) > $db_field_size )	{
			
            question_error_marking ( $question_id, 'Answer too long after cleaning punctuation. Overflow cut off. ' );
			$this->vetted_form_answer[$question_id] = substr ( $this->vetted_form_answer[$question_id], 0, 500 );
	    }
        
        
		if ( 
            strlen ( $this->vetted_form_answer[$question_id] ) < 1 
            && $question_attributes_array['question_required'] == 'yes'
            && !$this->form_answer['noan'][$question_id] 
        )
        {
			question_error_marking ( $question_id, 'Answer Required. ' );
        }
        
        //If there is one of the reasons for not giving an answer given, process it
        if ( $this->form_answer['noan'][$question_id] )  {
            //echo 'Noan is: '.$this->form_answer['noan'][$question_id].'<p/>';
            $this->process_no_answer_reason ( $question_attributes_array, $this->form_answer['noan'][$question_id], $this->vetted_form_answer[$question_id] );
        
        }
        
	}





	///////////////////////////////////////////////////////////////////////////////////
	// FUNCTION: validate_number_question_answer()                                   //
	///////////////////////////////////////////////////////////////////////////////////
	function validate_number_question_answer ($question_attributes_array)
    {
		$question_id = $question_attributes_array["question_id"];
	    
		//If there is a form answer, test to see if it is valid
		if($this->form_answer[$question_id])
        {
            $this->vetted_form_answer[$question_id] = trim($this->form_answer[$question_id]);
            
			if(ereg("[^0-9\-]", $this->form_answer[$question_id]))
            {
				question_error_marking ($question_id, "Only Numbers Allowed. ");
				$error = "yes";
				
				$this->vetted_form_answer[$question_id] = htmlentities($this->vetted_form_answer[$question_id]);
            }
		    
			if(strlen ($this->vetted_form_answer[$question_id]) > $question_attributes_array["question_field_size"])
            {
				question_error_marking ($question_id, "Overflow, Illegal Entry. ");
				$this->vetted_form_answer[$question_id] = "";
				$error = "yes";
		    }
            
			if ($this->vetted_form_answer[$question_id] < $question_attributes_array["question_range_bottom"]
                || $this->vetted_form_answer[$question_id] > $question_attributes_array["question_range_top"] )
            {
				question_error_marking ($question_id, "Answer must be between "
                .$question_attributes_array["question_range_bottom"]." and ".$question_attributes_array["question_range_top"].". ");
				$error = "yes";
			}
            elseif ($this->vetted_form_answer[$question_id] < -999999 || $this->vetted_form_answer[$question_id] > 999999 )
            {
				question_error_marking ($question_id, "Answer must be between -999,999 and 999,999. ");
				$error = "yes";
			}
		}
        
        //Since PHP returns a "0" in a form as thought it were "", put in a str "0".
        if(!$this->vetted_form_answer[$question_id] && strlen($this->form_answer[$question_id]) > 0)
        {
            $this->vetted_form_answer[$question_id] = "0";
        }
        
        
        if ( strlen($this->vetted_form_answer[$question_id] ) < 1 
            && $question_attributes_array['question_required'] == 'yes' 
            && !$this->form_answer['noan'][$question_id] )
        {
		    question_error_marking ( $question_id, 'Answer Required. ' );
            
			$error = 'yes';
		}
        
        if ( !$error )
        {
			//settype($this->vetted_value[$question_id], "string");
            $this->vetted_value[$question_id] = $this->vetted_form_answer[$question_id];
            //echo "The validated number answer is: ".$this->vetted_value[$question_id]."<br/>";
		}
        else
        {
           $this->vetted_value[$question_id] = "0"; 
        }
        
        //If there is one of the reasons for not giving an answer given, process it
        if ( $this->form_answer['noan'][$question_id] )
        {
            //echo 'Noan is: '.$this->form_answer['noan'][$question_id].'<p/>';
            $this->process_no_answer_reason ( $question_attributes_array, $this->form_answer['noan'][$question_id], $this->vetted_form_answer[$question_id] );
        }
        //echo "The question id is: ".$question_id." --- The validated number answer is: ".$this->vetted_value[$question_id]."<br/>";
    }





	///////////////////////////////////////////////////////////////////////////////////
	// FUNCTION: validate_checkboxes_question_answer()                               //
	///////////////////////////////////////////////////////////////////////////////////
	function validate_checkboxes_question_answer ( $question_attributes_array, $question_elements_array )
    {
		$question_id = $question_attributes_array['question_id'];
        $ans_count = 0;
        $no_answer_option_chosen = 0;
		foreach ( $question_elements_array AS $element_key => $current_element )
        {
			//echo $question_id."--".$element_key."==".$this->form_answer[$question_id]."<br>";
			switch ( $this->form_answer[$question_id][$element_key] )
            {
				case '': 
					$this->vetted_form_answer[$question_id][$element_key] = '';
					break;
                
				case 'yes': 
					$this->vetted_form_answer[$question_id][$element_key] = 'yes';
					$this->vetted_value[$question_id][$element_key] = $current_element['question_element_value'];
					$ans_count++;
                    break;
                
				default:
					question_error_marking ( $question_id, 'Illegal Entry for Question#'.$question_id.'. ' );
			}
            
            //If a 'no_answer_option' is chosen, note it
            if (   $this->vetted_value[$question_id][$element_key] == '#88#'
                || $this->vetted_value[$question_id][$element_key] == '#98#'
                || $this->vetted_value[$question_id][$element_key] == '#99#' )
            {
                $no_answer_option_chosen++;
            }
		}
        
		if ( !$this->form_answer[$question_id] 
            && $question_attributes_array['question_required'] == 'yes' 
            && $no_answer_option_chosen < 1 )
        {
			question_error_marking ( $question_id, 'Answer Required. ' );
		}
        
        if ( $no_answer_option_chosen > 1 )
        {
            question_error_marking ( $question_id, "Only one \"No answer\" option allowed. " );
        }
        
        if ( $no_answer_option_chosen && $ans_count - $no_answer_option_chosen > 0 )
        {
            question_error_marking ( $question_id, "Cannot choose a \"No answer\" option and a regular answer. " );
        }
        
        //If there is one of the reasons for not giving an answer given, process it
        //if ( $this->form_answer['noan'][$question_id] )  {
        //    $this->process_no_answer_reason ( $question_attributes_array, $this->form_answer['noan'][$question_id], $this->vetted_value[$question_id] );
        //}
	}





	///////////////////////////////////////////////////////////////////////////////////
	// FUNCTION: validate_radio_buttons_question_answer()                            //
	///////////////////////////////////////////////////////////////////////////////////
	function validate_radio_buttons_question_answer ( $question_attributes_array, $question_elements_array )
	{
		$question_id = $question_attributes_array['question_id'];
	    //echo "<hr color=blue><font color=blue>validate_radio_buttons_question_answer(): $question_id<br>";
        
		//Loop through the elements in the questions from the DB
		foreach ($question_elements_array AS $element_key => $current_element)
		{
			//echo $question_id."--".$element_key."==".$this->form_answer[$question_id]."<br>";
			//If an answer element matches one in the database, pass on the answer
			if($this->form_answer[$question_id] == $element_key)
			{
				$this->vetted_form_answer[$question_id] = $element_key;
                //echo $this->vetted_form_answer[$question_id]." Validated Answer<br/>";
				$this->vetted_value[$question_id]= $current_element['question_element_value'];
				break 1;
			}
		}
		
		if (  ( !$this->form_answer[$question_id] || $this->vetted_value[$question_id] == 'BLANK' ) 
              && $question_attributes_array['question_required'] == 'yes' 
              && !$this->form_answer['noan'][$question_id]   )
        {
			//echo "<p>NO ANSWER GIVEN ON DROPDOWN<p>";
            question_error_marking ( $question_id, 'Answer Required. ' );
            //$this->vetted_value[$question_id] = '';
		}
        
        //Do not pass BLANK as a value
        if ( $this->vetted_value[$question_id] == 'BLANK' )
		{
            $this->vetted_value[$question_id] = '';
        }
        
        //If there is one of the reasons for not giving an answer given, process it
        if ( $this->form_answer['noan'][$question_id] )
		{
            $this->process_no_answer_reason ( $question_attributes_array, $this->form_answer['noan'][$question_id], $this->vetted_value[$question_id] );
        }
		//echo "<br>RETURN...</font><hr color=blue>";
	}





	///////////////////////////////////////////////////////////////////////////////////
	// FUNCTION: validate_date_question_answer()                                     //
	///////////////////////////////////////////////////////////////////////////////////
    function validate_date_question_answer ( $question_attributes_array )
    {
        //echo "Validate Date:".pretty_var_dump($this->form_answer);
        
        $q_id = $question_attributes_array['question_id'];
        $month_qid = $q_id.'_month';
        $day_qid = $q_id.'_day_of_month';
        $year_qid = $q_id.'_year';
        
        if ( $question_attributes_array['question_special_attribute'] )
        {
            $elements = $question_attributes_array['question_special_attribute'];
        }
        else
        {
            $elements = 'FjY';
        }
        
        $length = strlen ( $elements );
        
        for ($y = 0; $y < $length; $y++)
		{
            switch ($elements[$y])
			{
                case 'F':
                    $this->validate_date_month_question_answer ($month_qid, $question_attributes_array);
                    break;
                
                case 'm':
                    $this->validate_date_month_question_answer ($month_qid, $question_attributes_array);
                    break;
                
                case 'j':
                    $this->validate_date_day_of_month_question_answer ($day_qid, $question_attributes_array);
                    break;
                
                case 'Y':
                    $this->validate_date_year_question_answer ($year_qid, $question_attributes_array);
                    break;
                
                default:
                    echo 'Illegal date definition';
            }
        }
        
        //echo pretty_var_dump($this->vetted_value);
        
        //If any query fields are filled-in, validate that the date exists, and return the value
        if ( $this->vetted_value[$day_qid] || $this->vetted_value[$year_qid] || $this->vetted_value[$month_qid] )
		{
            $this->validate_dates_exist ( $q_id );
            //echo '<br>year='.$this->vetted_value[$year_qid].' month='.$this->vetted_value[$month_qid].' day='. $this->vetted_value[$day_qid];
            
            $this->vetted_value[$q_id] = 
                   safe_mktime(0, 0, 0, $this->vetted_value[$month_qid], $this->vetted_value[$day_qid], $this->vetted_value[$year_qid]);
        }
    }





	///////////////////////////////////////////////////////////////////////////////////
	// FUNCTION: validate_date_month_question_answer()                               //
	///////////////////////////////////////////////////////////////////////////////////
    function validate_date_month_question_answer ($q_id, $question_attributes_array)
    {
        //echo "form answer is: ".$this->form_answer[$q_id].", requore is: ".$question_attributes_array["question_required"]."<p>"; 
        if ( $this->form_answer[$q_id] == "BLANK" && $question_attributes_array["question_required"] == "yes" )
        {
                    question_error_marking ($q_id, "Answer Required. ");
                    $this->vetted_form_answer[$q_id] = "BLANK";
                    $this->vetted_value[$q_id] = "0";
        }
        elseif ( $this->form_answer[$q_id] == "BLANK" )
        {
            $this->vetted_form_answer[$q_id] = "BLANK";
            $this->vetted_value[$q_id] = "0";
        }
        else
        {
            $q_def = array ("question_id" => $q_id, "question_title" => "Month:",
             "question_type" => "number", "question_field_size" => "2", "question_range_bottom" => "1",
              "question_range_top" => "12", "question_display_order" => "103",
               "question_required" => $question_attributes_array["question_required"]);
            $this->validate_number_question_answer ($q_def);
        }
        //echo "q_id is: ".$q_id."<p>";
        //echo "form answer: ".$this->vetted_form_answer[$q_id]."<p>";
        //echo $this->vetted_value[$q_id]."<p>";
    }




	///////////////////////////////////////////////////////////////////////////////////
	// FUNCTION: validate_date_day_of_month_question_answer()                        //
	///////////////////////////////////////////////////////////////////////////////////
    function validate_date_day_of_month_question_answer ($q_id, $question_attributes_array)
	{
        $q_def = array ("question_id" => $q_id, "question_title" => "Day:",
             "question_type" => "number", "question_field_size" => "2", "question_range_bottom" => "1",
              "question_range_top" => "31", "question_display_order" => "103",
               "question_required" => $question_attributes_array["question_required"]);
        
        $this->validate_number_question_answer ($q_def);
    }





	///////////////////////////////////////////////////////////////////////////////////
	// FUNCTION: validate_date_year_question_answer()                                //
	///////////////////////////////////////////////////////////////////////////////////
    function validate_date_year_question_answer ($q_id, $question_attributes_array)
	{
        //echo 'q_id:'.pretty_var_dump ($q_id).' question_attributes_array:'.pretty_var_dump($question_attributes_array);
        $q_def = array ("question_id" => $q_id, "question_title" => "Year:",
             "question_type" => "number", "question_field_size" => "4", "question_range_bottom" => "1900",
              "question_range_top" => "2038", "question_display_order" => "103",
               "question_required" => $question_attributes_array["question_required"]);
        //echo "<h1>validate_date_year_question_answer:".$question_attributes_array["question_required"]."</h1>";
        $this->validate_number_question_answer ($q_def);
    }





	///////////////////////////////////////////////////////////////////////////////////
	// FUNCTION: validate_dates_exist()                                              //
	///////////////////////////////////////////////////////////////////////////////////
    function validate_dates_exist ($q_id)
    {
		//Put this function in Questions_answers_validation, and use in client report submission also. ($month_id, $day_id, $year_id)
		//echo "<br>validate_dates_exist ($q_id)<br>";
        
		GLOBAL $question_validation_error, $message, $message_type;
		
        //Shouldn't dates be fixed by the user rather than changed by the system!
        //This validation occurs on form submit and if form validates data posts as changed.  I doubt we want this.  ~Jeff
		/*while(!checkdate ($this->vetted_value[$q_id."_month"], $this->vetted_value[$q_id."_day_of_month"], $this->vetted_value[$q_id."_year"]))
        {
			$this->vetted_form_answer[$q_id."_day_of_month"]--;
            $this->vetted_value[$q_id."_day_of_month"]--;
            
			$u++;
		    if ($u > 3)
            {
                break;
            }
 	    }
        
        if ($u > 3)*/
        if (!checkdate ($this->vetted_value[$q_id."_month"], $this->vetted_value[$q_id."_day_of_month"], $this->vetted_value[$q_id."_year"]))
        {
				$this->vetted_form_answer[$q_id."_day_of_month"] = $this->form_answer[$q_id."_day_of_month"]; 
				question_error_marking ($q_id."_month", "This month-day-year combination is invalid.");
				question_error_marking ($q_id."_day_of_month", "This month-day-year combination is invalid.");
				question_error_marking ($q_id."_year", "This month-day-year combination is invalid.");
		}
        /*elseif ( $u > 0 )
        {
			    $message .= "Date adjusted because the entered day was not valid. ";
			    $message_type = "error";
			    $message_set = "yes";
        }*/
	}






	///////////////////////////////////////////////////////////////////////////////////
	// FUNCTION: validate_table_question_answer()                                    //
	///////////////////////////////////////////////////////////////////////////////////
    function validate_table_question_answer ($question_attributes_array, $question_elements_array)	{
		
		$question_id = $question_attributes_array["question_id"];
		$this->x_array = $question_elements_array["x"];
        $this->y_array = $question_elements_array["y"];
        $this->table_question_attributes = $question_attributes_array;
        $this->at_least_one_value_entered;
        $this->all_cells_have_value;
         
        //Loop through the y axis
        foreach($this->y_array AS $current_y)    {
            //If this is no a total or subtotal, test the cell
                        
            $this->validate_table_x_axis($question_id, $current_y);
            
            //If no answer is provided, and at least one is required, make an error.
            if ($current_y["axis_required"] == "one" && $this->at_least_one_value_entered["y"][$current_y["axis_id"]] != "yes")   {
                question_error_marking ($question_id, "Answer required for at least one ".$current_y["axis_label"]." cell. ");
            }
            //If any axis cell is empty, and all are required to be filled-in, mark error
            if ($current_y["axis_required"] == "all" && $this->all_cells_have_value["y"][$current_y["axis_id"]] == "empty_cell")   {
                question_error_marking ($question_id, "Answer required for all ".$current_y["axis_label"]." cells. ");
            }            
        }
        
        //Loop through the x to see if an answer was given
        foreach ($this->x_array AS $current_x)  {
            
            if ($current_x["axis_required"] == "one" && $this->at_least_one_value_entered["x"][$current_x["axis_id"]] != "yes")   {
                question_error_marking ($question_id, "Answer required for at least one ".$current_x["axis_label"]." cell. ");  
            }
            //If any axis cell is empty, and all are required to be filled-in, mark error
            if ($current_x["axis_required"] == "all" && $this->all_cells_have_value["x"][$current_x["axis_id"]] == "empty_cell")   {
                question_error_marking ($question_id, "Answer required for all ".$current_x["axis_label"]." cells. ");
            } 
         
        }
    }





	///////////////////////////////////////////////////////////////////////////////////
	// FUNCTION: validate_table_x_axis()                                             //
	///////////////////////////////////////////////////////////////////////////////////
    function validate_table_x_axis ($question_id, $current_y)   {

        foreach($this->x_array AS $current_x)    {
 	        
            //Shorten the variables for clarity
                $x = $current_x["axis_id"];
                $y = $current_y["axis_id"]; 
		                
            //If there is a form answer, test to see if it is valid
		    if($this->form_answer[$question_id][$x][$y])	{
                //echo "Form _nswer is".$this->form_answer[$question_id][$x][$y]."<p>";
                //Note that an answer was given for the axis'
                $this->at_least_one_value_entered["x"][$x] = "yes";
                $this->at_least_one_value_entered["y"][$y] = "yes";
                                
                $this->vetted_form_answer[$question_id][$x][$y] =
                 trim($this->form_answer[$question_id][$x][$y]);
                
			    if(ereg("[^0-9\-]", $this->vetted_form_answer[$question_id][$x][$y]))	{
				    question_error_marking ($question_id, "Only Whole Numbers Allowed. ");
				    $error = "yes";
                    $this->vetted_form_answer[$question_id][$x][$y] = htmlentities($this->vetted_form_answer[$question_id][$x][$y]);
                    
				}
  

			    if(strlen ($this->vetted_form_answer[$question_id][$x][$y]) > $this->table_question_attributes["question_field_size"])
                {
				    question_error_marking ($question_id, "Overflow, Illegal Entry. ");
				    $this->vetted_form_answer[$question_id][$x][$y] = "";
				    $error = "yes";
				}

			    if($this->vetted_form_answer[$question_id][$x][$y] < $current_x["axis_range_bottom"] 
                || $this->vetted_form_answer[$question_id][$x][$y] > $current_x["axis_range_top"])	
                {
				  
                    question_error_marking ($question_id, "Answers must be between ".
                    $current_x["axis_range_bottom"]." and ".
                    $current_x["axis_range_top"].". ");
				    $error = "yes";
			    }
												    
                elseif($this->vetted_form_answer[$question_id][$x][$y] < $current_y["axis_range_bottom"] 
                || $this->vetted_form_answer[$question_id][$x][$y] > $current_y["axis_range_top"] )	
                {
				    question_error_marking ($question_id, "Answers must be between ".
                    $current_y["axis_range_bottom"]." and ".
                    $current_y["axis_range_top"].". ");
				    $error = "yes";
			    }


                
		        //if(!$this->vetted_form_answer[$question_id] && $this->table_question_attributes["question_required"] == "yes")	{
			    //    question_error_marking ($question_id, "Answer Required. ");
			    //    $error = "yes";
		        //}

		        if(!$error)	{
			        $this->vetted_value[$question_id][$x][$y] = $this->vetted_form_answer[$question_id][$x][$y];
                    //echo "The validated number answer is: ".$this->vetted_value[$question_id]."<br/>";
			    }
                else    {
                   $this->vetted_value[$question_id][$x][$y] = "0"; 
                }
                //echo "The question id is: ".$question_id." --- 
                //The validated number answer is: ".$this->vetted_value[$question_id][$x][$y]."<br/>";
            }
            
            //Note empty cells of cells that are not "default" (i.e., not total|subtotal|test) for future evaluation
            elseif ($current_x["axis_special_type"] == "default" && $current_y["axis_special_type"] == "default")   {
                $this->all_cells_have_value["x"][$x] = "empty_cell";
                $this->all_cells_have_value["y"][$y] = "empty_cell";
            }  
            
            
        }
    }





	///////////////////////////////////////////////////////////////////////////////////
	// FUNCTION: process_no_answer_reason()                                          //
	///////////////////////////////////////////////////////////////////////////////////
    function process_no_answer_reason ( $question_attributes_array, $no_answer_option, $vetted_answer )  {
        //echo 'noan in final validation is: '.$no_answer_option.'<p/>';
        $ops = $question_attributes_array['question_no_answer_options'];
        //echo "the no ans iption is ".$ops."<p>";

        if ( $no_answer_option == '#88#' && ( $ops & 1 ) ) {
            $this->vetted_form_answer['noan'][$question_attributes_array['question_id']] = '#88#';    
            //echo "yes 88 slecetd<p>";
        }
        elseif ( $no_answer_option == '#98#' && ( $ops & 2 ) ) {
            $this->vetted_form_answer['noan'][$question_attributes_array['question_id']] = '#98#';    
        }
        elseif ( $no_answer_option == '#99#' && ( $ops & 4 ) ) {
            $this->vetted_form_answer['noan'][$question_attributes_array['question_id']] = '#99#';    
        }
        elseif ( $no_answer_option == '#77#' && ( $ops & 8 ) ) {
            $this->vetted_form_answer['noan'][$question_attributes_array['question_id']] = '#77#';    
        }
        
        //echo 'vetted form answer is '.$vetted_answer.' --  '.$this->vetted_form_answer['noan'][$question_attributes_array['question_id']]
        //.'<p/>';        
        if ( $vetted_answer && $this->vetted_form_answer['noan'][$question_attributes_array['question_id']] ) {
            //echo 'Yes and error<p>';
            question_error_marking ( $question_attributes_array['question_id'], 'Cannot answer question and provide a reason why it is
            blank. ' );
        }
        else {
            //$this->vetted_value['noan'][$question_attributes_array['question_id']] =
            $this->vetted_value[$question_attributes_array['question_id']] =
            $this->vetted_form_answer['noan'][$question_attributes_array['question_id']];
        }
        //echo 'IIIin quest ans validation '.$this->vetted_form_answer['noan'][$question_attributes_array['question_id']].'<p>';
        //echo 'vetted value '.$this->vetted_value[$question_attributes_array['question_id']].'<p>';
   
    }
    
    
}
?>
Return current item: Homeless Mangement Information System