Location: PHPKode > projects > Homeless Mangement Information System > hmis/include/client_report_class.inc
<?php
//*Client Data System, Copyright (C) 2000, 2001, 2002 Tedd Kelleher.  This is free software, subject to the 
//*GNU GENERAL PUBLIC LICENSE, Version 2, June 1991 (in file named gpl.txt), which should accompany 
//*any distribution of this file.  Tedd Kelleher can be contacted at hide@address.com

class Client_report
{

    var $copy_number;
    var $questions_client_report;
    var $question_elements_client_report;
    var $share_questions;
    var $share_question_elements;
    var $share_question_answer;
    var $validation;
    var $vetted_frm_ans;
    var $vetted_vals;

	var $report_id;




    function assemble_client_report_questions ($copy_num, $questions, $question_elements)
	{
        $this->copy_number = $copy_num;
        
        for ($u = 0; $u < $this->copy_number; $u++)
		{
            foreach ($questions AS $key => $current_question)
            {
                //Build the modified client-specific id
                $modified_id = $current_question["question_id"]."_".$u;
                //Assign the current question to that id              
                $this->questions_client_report[$u][$modified_id] = $current_question;
                //Modify the internal question id field to match the modified question id
                $this->questions_client_report[$u][$modified_id]["question_id"] = $modified_id;
                
                //Assign the related question elements to the newly mofied question
                $this->question_elements_client_report[$u][$modified_id] = $question_elements[$current_question["question_id"]];
                
                //display_value ($this->question_elements_client_report[$modified_id]);
                
                //$this->assemble_client_report_sharing_question($u);   
            }
        }
    }






    function validate_submitted_client_reports ($form_answers)
	{
        GLOBAL $message;
        GLOBAL $message_type;
        
        for ($u = 0; $u < $this->copy_number; $u++) //copy_number is number of client forms submitted...
		{
			//echo " u:$u ";
            if ( $form_answers["submitfor_".$u] == "yes" )
			{
                //echo "<p>Filled in: ".$u."</p>";
                $at_least_one_client_report++;
				
                $x = new Questions_answers_validation( $this->questions_client_report[$u],
                                                       $this->question_elements_client_report[$u],
													   $form_answers  );
                $this->vetted_frm_ans[$u] = $x->vetted_form_answer;
                $this->vetted_vals[$u] = $x->vetted_value;
                //echo "Share status is :".$form_answers["share_".$u]."<br>";
                if( $form_answers["share_".$u] == "no" )
				{
                    $this->share_question_answer[$u] = "no";
                }
                else
				{
                    $this->share_question_answer[$u] = "yes";
                }
				//echo '<table border=2 bordercolor=green><tr><td>q:' . pretty_var_dump($this->questions_client_report[$u]) . '</td><td>qe:' . pretty_var_dump($this->vetted_vals[$u]) . '</td><td>a:' . pretty_var_dump($form_answers) . '</td></tr></table>';
            }
        
        }
        if (!$at_least_one_client_report)
		{
            $message .= "You must check at least one \"Submit Report for\" checkbox below. ";
            $message_type = "error";
        }
		
		//echo '<hr>this-share_q_a:'.pretty_var_dump($this->share_question_answer).'<hr>this-vetted_vals:'.pretty_var_dump($this->vetted_vals);
    }






    function assemble_client_report_entry_table ($report_title, $date_html="", $form_type='client_forms')
	{
        GLOBAL $head_dynamic_style, $client_info, $form_answer, $form_submitted;
        $head_dynamic_style .= ".clienttop {color: #FFFFFF; font-size: 12; background-color: #000099; font-weight: bolder}"; 
        if ( $date_html )
		{
            $final_html .=  $date_html;
        }
		for($i = 0; $i < $this->copy_number; $i++)
		{
            //$id_string = assemble_client_id_string ($i, $client_info);
            
            $profile = new Client_profile;
            $current_client[0] = $client_info[$i];
            $id_string = $profile->display_client_profile_table ($current_client, '', $form_type);
            
            $final_html .= "<table border=0><tr><td class=\"clienttop\"><input type=\"checkbox\" name=\"form_answer[submitfor_".$i."]\"
             value=\"yes\" ".build_tabindex_html(1000);
            if ( $form_submitted && $form_answer["submitfor_".$i] == "yes" || !$form_submitted )
			{
                $final_html .= "checked=\"checked\"";
            }
            $final_html .= "> Submit <span class=\"yellow\">".$report_title."</span> &nbsp;Form for:<td></tr></table> ";
            $final_html .= $id_string;
            //display_value($client_info);
            
            $final_html .= "<table>";
            $td_count = 0;
            
            foreach ($this->questions_client_report[$i] AS $key => $current_question)
			{
                //Make rows two questions long using <tr> and </tr>
			    if ($td_count == 2)	{$final_html .= "</tr>\n<tr><td class=\"bottomline\" colspan=\"2\">&nbsp;</td></tr>"; $td_count = 0; }
			    if ($td_count == 0) {$final_html .= "<tr>\n"; }
                //echo "Current_question id is: ".$current_question["question_id"]."</br>";
                
                $final_html .= question_display($current_question,
                   $this->question_elements_client_report[$i][$current_question["question_id"]],
                      $this->vetted_frm_ans[$i]);
                $td_count++;
            }
            
			//Make rows two questions long using <tr> and </tr>
			if ($td_count == 2)	{$final_html .= "</tr>\n<tr><td class=\"bottomline\" colspan=\"2\">&nbsp;</td></tr>"; $td_count = 0; }
			if ($td_count == 0) {$final_html .= "<tr>\n"; }
            //Add sharing report question
            if ( $this->share_question_answer[$i] == "yes" )
			{
                $share_checked["yes"] = " checked=\"checked\"";
                $share_checked["no"] = "";
            }
            else
			{
                $share_checked["no"] = " checked=\"checked\"";
                $share_checked["yes"] = "";
            }
            $final_html .= "<td>Client Info Shared?<br/>Yes<input type=\"radio\" name=\"form_answer[share_".$i."]\" value=\"yes\" ".build_tabindex_html(103)
                            .$share_checked["yes"].">&nbsp;No<input type=\"radio\" name=\"form_answer[share_".$i."]\" value=\"no\" ".build_tabindex_html(103)
                            .$share_checked["no"]."><td>";
            $share_checked = "";
            
            $td_count++;
            
            if($td_count == "1"){$final_html .= "<td>&nbsp;</td></tr>\n";}
			if($td_count == "2"){$final_html .= "</tr>\n";}
			$final_html .= "</table><p></p>";
		}
        
    	return $final_html;
	}







    function pull_client_report_profile_array ($report_id)
	{
        $report_id += 0;
		$this->report_id = $report_id;
        $sql = "SELECT * FROM client_rpt_profile
         WHERE client_rpt_id = '".$report_id."'";
		
        $report_result = run_query( $sql, "Pulling client report profile array" );
        if ( num_rows ($report_result) < 1 )
        {
            echo "No matching client reports"; exit;
        }
        else
		{
            $return_array = fetch_array ( $report_result, 'Pulling array of existing household report profile', 0 );
            return $return_array;
        }
        //display_value($return_array);
    }







    function pull_existing_client_report_answers ($report_id, $questions_attributes, $question_elements, $do_not_modify="")
	{
        GLOBAL $form_answer;
        $report_id += 0;
        
        $en = new Encryption();
        
        $rpt_profile = $this->pull_client_report_profile_array ($report_id);
        //echo "<br>Here is the report profile<p>";
        //echo pretty_var_dump ($rpt_profile);
        
        $form_answer['submitfor_0'] = 'yes';
        
        if ( $rpt_profile['client_rpt_sharing_permission'] == 'no' )
		{
            //echo "No is the sharing answer<p>";
            $form_answer['share_0'] = 'no';
            $this->share_question_answer[0] = 'no'; //$rpt_profile['client_rpt_sharing_permission'];
        }
        else
		{
            //echo "Yes is the answer<p>";
            $form_answer['share_0'] = 'yes';
            $this->share_question_answer[0] = 'yes'; //$rpt_profile['client_rpt_sharing_permission'];
        }
        
        if (!$do_not_modify)
		{
            $modifier = '_0';
        }
        
        $sql = "SELECT * FROM client_rpt_answers WHERE client_rpt_id = '".$report_id."'";
        $answers = run_query_return_array ($sql, 'Pulling existing client report answers');
        
        foreach ( $answers AS $current_answer )
		{
            $q_id = $current_answer['client_rpt_question_id'];
            $modified_q_id = $q_id.$modifier;
            
            //If encrypted, decrypt
            if ( $questions_attributes[$q_id]['question_encrypted'] == 1 )
			{
                if ( $questions_attributes[$q_id]['question_type'] == 'number' || $questions_attributes[$q_id]['question_type'] == 'date' )
				{
                    $current_answer['client_rpt_answer_int'] = stripslashes( $en->decrypt_data( $current_answer['client_rpt_answer_int'] ) );
                }
                else
				{
                    $current_answer['client_rpt_answer'] = stripslashes( $en->decrypt_data( $current_answer['client_rpt_answer'] ) );
                }
            }
            
            
            switch ( $questions_attributes[$q_id]['question_type'] )
			{
                case 'radio':
                    
                    foreach ( $question_elements[$q_id] AS $key => $current_element )
					{
                        if ( $current_answer['client_rpt_answer'] == $current_element['question_element_value'] )
						{
                            $frm_ans[$modified_q_id] = $current_element['question_element_id'];
                            break 1;
                        }
                    }
                    break;
                    
                case 'dropdown':
                    
                    foreach ( $question_elements[$q_id] AS $key => $current_element )
					{
                        if ( $current_answer['client_rpt_answer'] == $current_element['question_element_value'] )
						{
                            $frm_ans[$modified_q_id] = $current_element["question_element_id"];
                            break 1;
                        }
                    }
                    break;
                    
                case 'checkboxes':
                    
                    foreach ( $question_elements[$q_id] AS $key => $current_element )
					{
                        if ( $current_answer['client_rpt_answer'] == $current_element['question_element_value'] )
						{
                            $frm_ans[$modified_q_id][$current_element['question_element_id']] = 'yes';
                            break 1;
                        }
                    }
                    break;
                    
                case 'table':
                    
                    if ($current_answer['client_rpt_answer_int'])
					{
                        $ans = $current_answer['client_rpt_answer_int'];
                    }
                    else
					{
                        $ans = stripslashes( $current_answer['client_rpt_answer'] ) ;
                    }
                    
                    $frm_ans[$modified_q_id][$current_answer['axis_x']][$current_answer['axis_y']] = $ans;
                    break;
                
                case 'text':
                    
                    $frm_ans[$modified_q_id] = stripslashes( $current_answer['client_rpt_answer']  );
                    //If a 'no answer' explanation, put the answer in the 'noan' value
                    if ( $current_answer['client_rpt_answer'] == '#88#' 
                        || $current_answer['client_rpt_answer'] == '#98#' 
                        || $current_answer['client_rpt_answer'] == '#99#' )
					{
                        $frm_ans['noan'][$modified_q_id] = $current_answer['client_rpt_answer'];
                        //Unset the question type so we don't return a value
                        $frm_ans[$modified_q_id] = '';
                    }
                    
                    break;
                    
                case 'textarea':
                    
                    $frm_ans[$modified_q_id] =  $current_answer['client_rpt_answer'];
                    
				    $sqlta = "
                    SELECT textarea_answer FROM textarea_answers 
                        WHERE textarea_unique LIKE '".$frm_ans[$modified_q_id]."'";
                    $res = run_query ( $sqlta, 'Pulling tex ans c' );
                    $frm_ans[$modified_q_id] = fetch_result ( $res, 'Txtarea ans c' );
                                        
                    $frm_ans[$modified_q_id] = stripslashes( $frm_ans[$modified_q_id] );
                    
                    //If a 'no answer' explanation, put the answer in the 'noan' value
                    if ( $frm_ans[$modified_q_id] == '#88#' 
                        || $frm_ans[$modified_q_id] == '#98#' 
                        || $frm_ans[$modified_q_id] == '#99#' )
					{
                        $frm_ans['noan'][$modified_q_id] = $frm_ans[$modified_q_id];
                        //Unset the question type so we don't return a value
                        $frm_ans[$modified_q_id] = '';
                    }
                    
                    break;
                
                case 'number':
                    
                    $frm_ans[$modified_q_id] = $current_answer['client_rpt_answer_int'];
                    //If a 'no answer' explanation, put the answer in the 'noan' value
                    if ( $current_answer['client_rpt_answer'] == '#88#' 
                        || $current_answer['client_rpt_answer'] == '#98#' 
                        || $current_answer['client_rpt_answer'] == '#99#' )
					{
                        $frm_ans['noan'][$modified_q_id] = $current_answer['client_rpt_answer'];
                        //Unset the question type so we don't return a value
                        $frm_ans[$modified_q_id] = '';
                    }
                
                    break;
                
                case 'date':
                    
                    $frm_ans[$modified_q_id] = $current_answer['client_rpt_answer_int'];
                    //If a 'no answer' explanation, put the answer in the 'noan' value
                    if ( $current_answer['client_rpt_answer'] == '#88#' 
                        || $current_answer['client_rpt_answer'] == '#98#' 
                        || $current_answer['client_rpt_answer'] == '#99#' )
					{
                        $frm_ans['noan'][$modified_q_id] = $current_answer['client_rpt_answer'];
                        //Unset the question type so we don't return a value
                        $frm_ans[$modified_q_id] = '';
                    }
                
                    break;
                  
                default:
                
                    echo 'Question type not found when pulling existing client report answers. Question id is:
                    '.$q_id.$questions_attributes[$q_id]['question_type']; exit;
            
            }
            
            //echo "ID: ".$modified_q_id. " - ".$questions_attributes[$q_id]["question_type"]." - ".$current_answer["client_rpt_answer"]." - ".
			//$frm_ans[$modified_q_id][$current_element["question_element_id"]]."<p>";
        
        }
        
        
        $this->vetted_frm_ans[0] = $frm_ans;
    }


}
?>
Return current item: Homeless Mangement Information System