Location: PHPKode > projects > Homeless Mangement Information System > hmis/include/report_client_form_class.inc
<?php
//*Client Data System, Copyright (C) 2000, 2001, 2002, 2003 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 Report_client_form
{
    var $rpt_type_profile_array; 
    var $group_id; 
    var $org_id; 
    var $user_id; 
    var $referred_to_org;
    var $form_status;
    var $client_info;
    var $form_answer;
    var $edit_report_id;
    var $tag_values;
    var $vetted_form_answers;
	var $number_of_clients;
    
	var $client_rpt_quests;
    var $client_rptt;
	var $report_header;
	var $plural;
    var	$date_quest;
    var	$date_html;
    var $form_type;
    
    function Report_client_form (
							        $report_type_id, 
							        $group_id, 
							        $org_id, 
							        $user_id, 
							        $referred_to_org,
							        $form_status,
							        $client_info,
							        $form_answer,
							        $edit_report_id )
	{
		global $client_info;
		
	    //bugbug: I'm thoroughly confused as to what changed, why both arrays and scalers are passed to this page...
		//Also, since we only open one form at a time (though post copies of it for each client) why on earth is this
		//passed as an array value with such a goofy index... in one case and as a scaler in another...?
		if (is_array($report_type_id))
			$this->report_type_id = $report_type_id;
		else
			$this->report_type_id[$report_type_id] = $report_type_id;
	    
        $this->group_id = $group_id;
        $this->org_id = $org_id;
        $this->user_id = $user_id;
        $this->referred_to_org = $referred_to_org;
        $this->form_status = $form_status;
        $this->client_info = $client_info;
        $this->form_answer = $form_answer;
		$this->number_of_clients = count ( $client_info );
	    //bugbug: I'm thoroughly confused as to what changed, why both arrays and scalers are passed to this page...
		if (is_array($edit_report_id))
		{
			$this->edit_report_id = $edit_report_id;
		}
		else
		{
			if ($edit_report_id)
				$this->edit_report_id[$edit_report_id] = $edit_report_id;
			else
				$this->edit_report_id = null;
		}
		//$this->edit_report_id = $edit_report_id;
        
        include_once($include_root."Questions_into_array_class.inc");
        include_once($include_root."questions_display.inc");
        include_once($include_root."Questions_answers_validation_class.inc");
        //include($include_root."question_set_validation_function.inc");
        include_once($include_root."questions_into_tags_function.inc");
        include_once($include_root."head.inc");
        include_once($include_root."template_parser.inc");
        include_once($include_root."page_elements_display.inc");
        include_once($include_root."client_id_class.inc");
        include_once($include_root.'client_report_class.inc');
        //include($include_root."insert_household_report_class.inc");
        include_once($include_root."insert_client_report_class.inc");
        include_once($include_root."client_profile_class.inc");//
        include_once($include_root.'client_lookup_class.inc');
        include_once($include_root."reports_class.inc");//
        include_once($include_root."report_date_questions_class.inc");
        include_once($include_root."relationships_class.inc");
        include_once($include_root."user_info_functions.inc");
        //include($include_root."referrals_class.inc");
        include_once($include_root."encryption_class.inc");
        include_once($include_root."date_encrypted_functions.inc");
        
        //Request for a empty referral form (NYI)
        /*if ( $this->form_status == 'not_submitted' && !$this->edit_report_id && $this->referred_to_org )
		{
            //echo '<p>Presenting Empty referral form... (NYI)</p>';
            $this->display_form_empty_referral ();
        }*/
        
		//this value gets overwritten if an existing income form is pulled up
		$this->tag_values['{TOTAL HH INCOME}'] = ' ';
		
        //Request for a totally empty form
        if ( $this->form_status == 'not_submitted' && !$this->edit_report_id )
		{
            //echo '<p>Presenting Empty form</p>';
            $this->display_form_empty ();
        }
        
        //Process a submitted blank form
        elseif ( $this->form_status == 'submitted' && !$this->edit_report_id )
		{
            //echo '<p>processing submitted new form</p>';
            $this->display_form_submitted ();
        }
        
        //Display an existing report to edit 
        elseif ( $this->form_status == 'not_submitted' && $this->edit_report_id )
		{
            //echo '<p>display for edit</p>';
            $this->display_form_edit ();
        }
        
        //Process an edited report 
        elseif ( $this->form_status == 'submitted' && $this->edit_report_id )
		{
            //echo '<p>process edited form</p>';
			$this->display_form_edit_submitted ();
        }
        
        elseif ( $this->form_status == 'delete' && $this->edit_report_id )
		{
            //echo '<p>process delete request</p>';
			$this->process_delete_request ();
        }
        
        else
		{
            echo '<p>unknown request</p>';
            exit;
        }
    }






/********************************************************************************************
 * Name: load_and_init_form():
 * Description: Loads and prepares data before client forms (reports) along with client info are displayed.
 * 
 * Details and Notes:
 * @param: None
 * @return: Nothing returned
 * 
 * History: Created 1/25/04 by Jeff.
 ********************************************************************************************/
function load_and_init_form ( )
{
    //echo "In display client report<p>";
    GLOBAL $page_id, $html_template, $form_submitted, $question_validation_error, $access_level;
	GLOBAL $user_id, $org_id, $instructions, $group_id, $client_info, $client_rptt, $validation_date, $date_quest, $page_title, $this_page;
    GLOBAL $user_name, $org_name, $unix_date; //$client_rptt, $access_level;
    $i = 0;
	
	foreach ( $this->report_type_id AS $cur_rpt_type_id )
	{
		//this likely needs to be in a foreach loop for each form...   'client_assessment' etc...
		//echo '<table><tr><td>rep_type_id'.pretty_var_dump($this->report_type_id).'</td><td>edit_type_id'.pretty_var_dump($this->edit_report_id).'</td></tr></table>';
		
		$this->rpt_type_profile_array = pull_report_type_profile( $cur_rpt_type_id ); 
		
	    //Establish the class; Because this function loops back on itself, don't make new class (erasing existing values) if it exists 
	    if ( !$client_rptt )
		{
	        $client_rptt = new Client_report;
	    }
	    
	    //Since this can loop back on itself, don't re-establish (thus erasing existing values)
	    if ( $this->rpt_type_profile_array["report_on_timeperiod"] != 'no' && !$date_quest )
        {
	        $date_quest = new Report_date_questions( '', '', $this->rpt_type_profile_array["report_on_timeperiod"] );
            $this->date_html = $date_quest->build_report_date_table ($valid_date_form_answers);
	    }
        
	    //Pull client profile questions to pass to Client Form
	    $this->client_rpt_quests = new Questions_into_array ( 
									$this->rpt_type_profile_array['report_type_id'],
									40, //access_level
									$this->org_id, 
									$this->group_id, 
									'display' );
	    
        $this->tag_values['{FORM_END}'] .= display_hidden_form_values ( 
		                                      'report_type_id[0]', 
											  $this->rpt_type_profile_array['report_type_id']    );
		
		//Modify the title to tell user if they are editing the report
	    if ( $this->edit_report_id )
		{
	        $title_type = "Edit ";
	        $instructions = "Edit this client's ".$this->rpt_type_profile_array["report_title"]." form.";
	    }
	    else
		{
	        $title_type = "Submit new ";
	        $instructions = "Submit a new ".$this->rpt_type_profile_array["report_title"]." form for this client.";
	    }
	    
	    if ( $this->number_of_clients > 1 )
		{
	        $this->plural = "s";
	    }
	    
		$this->tag_values['{FORM_END}'] .= display_hidden_form_values ( 
		                                      'report_type_id['.$i.']', 
											  $this->rpt_type_profile_array['report_type_id']    );
		
	    $page_title = $title_type.$this->rpt_type_profile_array["report_title"]." Form".$this->plural;
	    //End Modify title code block
		
        $questions_to_display = $this->client_rpt_quests->questions;
        
        //if a client_profile form we need to remove the identifier questions
        if ( $this->rpt_type_profile_array['report_type_id'] == 'client_profile' )
        {
                unset($questions_to_display['98']);  //status
                unset($questions_to_display['100']); //year born
                unset($questions_to_display['101']); //gender
        }
        
        //Assemble the questions
	    $client_rptt->assemble_client_report_questions ( $this->number_of_clients, 
		                                                 $questions_to_display, 
														 $this->client_rpt_quests->question_elements );
		
		$reports = new Reports;
        
        
		//REPORT/FORM HEADER ~ This value is overwritten later if existing report is being edited/viewed...
		//value is written to $this->tag_values["{CLIENT IDENTIFIER ENTRY TABLE}"]
		$this->report_header = $reports->display_report_profile (
                                                                      $this->rpt_type_profile_array['report_title'],
                                                                      $user_name,
                                                                      $org_name,
                                                                      $unix_date );
		
		$i++;
		
		break; //for now assume only one report_type_id.
	}
}








    function display_form_empty ()
	{
        GLOBAL $instructions, $date_quest;
        
	    $this->load_and_init_form ();
		
        //$instructions = 'Submit a new client report by entering information below. ';
        
        $this->tag_values['{FORM_END}'] .= display_hidden_form_values ( 'form_status', 'submitted' );
        $this->tag_values['{FORM_END}'] .= form_end ( 'Click here to submit new client form'.$this->plural, 1 );
        $this->commom_form_elements ();
    }



/*NYI:    function display_form_empty_referral ()
	{
        GLOBAL $instructions;
		
        $this->load_and_init_form ();
        
		$instructions .= ' Submit a new referral report by entering information below. ';
        
        $this->tag_values['{FORM_END}'] .= display_hidden_form_values ( 'referred_to_org', $this->referred_to_org );
        $this->tag_values['{FORM_END}'] .= display_hidden_form_values ( 'form_status', 'submitted' );
        $this->tag_values['{FORM_END}'] .= form_end ( 'Click here to submit new client form'.$this->plural, 1 );
        $this->commom_form_elements ();
    }*/



/*    function display_form_with_errors ()
	{
        GLOBAL $instructions, $date_quest;
        
		echo 'Display form with errors...';
        $this->load_and_init_form ();
		
		$instructions .= ' Correct errors below. ';
        
        $this->tag_values['{FORM_END}'] .= display_hidden_form_values ( 'form_status', 'submitted' );
        
		$this->tag_values['{FORM_END}'] .= form_end ( 'Click here to submit corrected client form'.$this->plural, 1 );
        $this->commom_form_elements ();
    }*/



    function display_form_edit_submitted ()
	{
		GLOBAL  $question_validation_error;
		
		$this->load_and_init_form ( );
		$instructions .= ' Edit report by changing values below. ';
		
        $this->process_submitted_form ();
        
        $this->tag_values['{FORM_END}'] .= display_hidden_form_values ( 'form_status', 'submitted' );
		
		//TODO: fix all this, its wack to pass around scalers and arrays...
	     if ($this->edit_report_id)
		 {
			$edit_id_values = array_values( $this->edit_report_id);
		 }
		 else
		 {
			$edit_id_values[0] = null;
		 }
		
	    $this->tag_values['{FORM_END}'] .= display_hidden_form_values ( 'edit_report_id[0]', $edit_id_values[0] );
		$this->tag_values['{FORM_END}'] .= form_end ( 'Click here to submit corrected client form'.$this->plural, 1 );
		if ( !$question_validation_error )
			$this->tag_values['{FORM_END}'] .= edit_button (1);
		
		//Pull permissions for this report we are looking at
        $perms = report_permissions_client ( $edit_id_values[0], $this->org_id, $this->user_id );
		//echo 'edit_id'.pretty_var_dump($edit_id_values[0]).'rpt_type_id'.pretty_var_dump($this->rpt_type_profile_array["report_type_id"]);
        if ( $perms['edit_rpt'] == 1 )
		{
            $this->tag_values["{FORM_END}"] .= "<p/>".list_previous_versions_of_client_report ($edit_id_values[0], $this->rpt_type_profile_array["report_type_id"]);
            
            if ( $this->rpt_type_profile_array["report_type_id"] != 'client_profile' )
            {
                $this->tag_values["{FORM_END}"] .= "<a href=\"#\" onclick=\"javascript:confirm_action('Are you sure you want to delete this form?','".
                                            $this_page."?empty_form=delete&edit_report_id=".
                                            $edit_id_values[0]."&report_type_id=".$this->report_type_id[0]."');\">Click here to DELETE this form</a>";
            }
        }
        else//report_unit=client&
		{
               $this->tag_values["{FORM_END}"] .= "<p/>".list_previous_versions_of_client_report ($edit_id_values[0], $this->rpt_type_profile_array["report_type_id"]); 
               $this->tag_values["{FORM_END}"] .= 'You are not allowed to edit this form';
        }
		
        $this->commom_form_elements ();
    }



    function display_form_submitted ()
	{
		GLOBAL $question_validation_error;
		
		$this->load_and_init_form ( );
		
		$instructions .= ' Edit report by changing values below. ';
        
		$this->process_submitted_form ();
        
		//$this->tag_values['{FORM_END}'] .= display_hidden_form_values ( 'edit_report_id['.$rpt_prof['report_type'].']', $cur_edit_rpt_id );
        $this->tag_values['{FORM_END}'] .= display_hidden_form_values ( 'form_status', 'submitted' );
		
        $this->tag_values['{FORM_END}'] .= form_end ( 'Click here to submit new client form'.$this->plural, 1 );
		if ( !$question_validation_error )
			$this->tag_values['{FORM_END}'] .= edit_button (1);
        $this->commom_form_elements ();
    }


    //util
	function client_form_validation_setup ($answered, $clients)
	{
	    $i=0;
		
	    //loop through each item in answered
	    foreach( $answered AS $key => $answer)
	    {
		  $newkey = str_replace( ('_'.$i), '', $key);
		  if ( strstr( $key, '_'.($i+1) ) )
		  {
			$i++;
			$newkey = str_replace( ('_'.$i), '', $key);
		  }
		  $new[$i][$newkey] = $answer;
	    }
		
		//echo "<br>client_form_validation_setup():".pretty_var_dump($new);
		return $new;
	}



    function display_form_edit ()
	{
        GLOBAL $instructions, $client_rptt, $page_id, $date_quest, $question_validation_error;
        
		//echo '<br>display_form_edit(): this->edit_report_id:'.pretty_var_dump($this->edit_report_id);
		
		$this->load_and_init_form ( ); //??? or should this be last...
        $instructions .= ' Edit report by changing values below. ';
        
		//TODO: Though this code looks like it could handle editing multiple reports at once, its unlikely it would really work.  
		//In the case of edit... What actually is passed in is just two scalers edit_report_id and report_type_id that get converted into arrays...
        if ( is_array ( $this->edit_report_id ) )
		{
			//should use report_type_id again.  What's with using edit_report_id?  Need the type id not the report id and should iterate on this!
            foreach ( $this->edit_report_id AS $cur_edit_rpt_id )
			{
	            $replace = new Insert_client_report;
	            $newest_rpt = $replace->find_newest_report_in_series ($cur_edit_rpt_id);
	            $this->tag_values["{FORM_END}"] .= display_hidden_form_values("edit_report_id", $newest_rpt);
	            $this->tag_values["{FORM_END}"] .= display_hidden_form_values("report_unit", "client");
	            $rpt_c = new Reports;
				
				//echo "rpt_type_profile_array:".pretty_var_dump($this->rpt_type_profile_array)."exist_rpt_prof:".pretty_var_dump($exist_rpt_prof);
				
	            $exist_rpt_prof = $rpt_c->pull_existing_client_rpt_profile ($cur_edit_rpt_id);
				$repid = $exist_rpt_prof['report_type']; //16
				$rpt_type_profile = pull_report_type_profile ( $repid );
	            
				//REPORT/FORM HEADER
	            //$this->tag_values["{CLIENT IDENTIFIER ENTRY TABLE}"]
				$this->report_header = 
				                  $rpt_c->display_report_profile ( "Edit ".$rpt_type_profile['report_title'],
	                                                               $exist_rpt_prof["user_name_first"]." ".$exist_rpt_prof["user_name_last"],
									                               $exist_rpt_prof["org_name"],
	                                                               $exist_rpt_prof["report_timestamp"]  );
				
                //Pull permissions for this report we are looking at
        		$perms = report_permissions_client ( $cur_edit_rpt_id, $this->org_id, $this->user_id );
		        
                if ( $perms['read_rpt'] == 1 )
				{
                    $report_profile = $client_rptt->pull_client_report_profile_array ($cur_edit_rpt_id);
                    
                    $prof = new Client_profile;
                    $prof->put_client_profile_associated_with_client_report_into_client_info_session_variable ($report_profile["client_id"]);
                    
                    //...and pull out the form answers
                    $client_rptt->pull_existing_client_report_answers (
			                $cur_edit_rpt_id, 
							$this->client_rpt_quests->questions,
                            $this->client_rpt_quests->question_elements);
                    
                    //...and pull the date answers if needed
                    if ( $rpt_type_profile["report_on_timeperiod"] != "no" )
			        {
                        $date_quest = new Report_date_questions ( '', '', $rpt_type_profile['report_on_timeperiod'] );
                        $pulled_dates = $date_quest->pull_existing_report_dates ($cur_edit_rpt_id, "client");
                        $validation_date = new Questions_answers_validation(
                            $date_quest->questions,
                            $date_quest->question_elements,
                            $pulled_dates
                        );
                        $valid_date_form_answers = $validation_date->vetted_form_answer;
                        $this->date_html = $date_quest->build_report_date_table ($valid_date_form_answers);
                    }
                    
					$page_id = $repid;  //todo: global used in below function but should be passed.
                    $end .= "<p/>".list_previous_versions_of_client_report ( $cur_edit_rpt_id, $repid );
                    
                    if ( $report_profile["report_type"] != 'client_profile' )
                    {
                        $end .= "<a href=\"#\" onclick=\"javascript:confirm_action('Are you sure you want to delete this form?','".
					        $this_page."?form_status=delete&report_type_id=".
							$repid."&edit_report_id=".
							$cur_edit_rpt_id."');\">Click here to DELETE this form</a>";
                    }
                }
                else
				{
				    echo "Not allowed to view form"; //exit;
                    //echo 'No permission to edit this client form';
                }
				break; //lets not iterate through the edit reports since currently you can only do one at a time...
            }
        }
        else
		{
            echo '<p>No reports to edit.</p>';
        }
        
        $this->tag_values['{FORM_END}'] .= display_hidden_form_values ( 'form_status', 'submitted' );
        
		$this->tag_values["{FORM_END}"] .= form_end ("Click here to submit edited client form".$this->plural, 1);  //todo: should never be plural as currently only a single form can be edited at a time.
		if ( !$question_validation_error )
			$this->tag_values['{FORM_END}'] .= edit_button (1);
        $this->tag_values['{FORM_END}'] .= $end;
        
        $this->commom_form_elements ();
    }






//Function is missnamed, handles both new and edited forms!
    function process_submitted_form ()
	{
        GLOBAL $question_validation_error, $client_rptt, $form_answer, $form_submitted;
		
	    //Put into array for validation only the questions from subform where the first initial was filled out, 
		//so that totally empty forms are not marked with errors for being incomplete
	    $answered_questions = $this->client_form_validation_setup ($this->form_answer, $this->number_of_clients);
		
        foreach ( $this->report_type_id AS $cur_rpt_type_id )
		{
			$form_submitted = $cur_rpt_type_id; //bugbug: hack to ensure date values persist in form which renders again if errors...
            $rpt_type_profile = pull_report_type_profile ( $cur_rpt_type_id );
			$repid = $rpt_type_profile['report_type_id'];
            
			$pull_questions[$repid] = 
                    new Questions_into_array ( 
                    $repid,
                    40,
                    $this->org_id,
                    $this->group_id,
                    'display' );
            
			if (!$client_rptt)
				$client_rptt = new Client_report;
			
			$client_rptt->validate_submitted_client_reports ($this->form_answer);
			
            $this->vetted_form_answers[$repid] =
                             $validation[$repid]->vetted_form_answer;
			
			$client_rptt->report_id = $repid;
            
            //If dates are included in report validate dates...
            if ( $rpt_type_profile['report_on_timeperiod'] != 'no' )
			{
                $date_quest = new Report_date_questions ( '', '', $rpt_type_profile['report_on_timeperiod'] );
                $validation_date = new Questions_answers_validation(
                    $date_quest->questions,
                    $date_quest->question_elements,
                    $this->form_answer
                );
                $date_quest->validate_dates_exist ( true );
            }
			
			/*DEBUG
			echo '<table border=1 bordercolor=green><tr><td valign=top>'.pretty_var_dump ( $client_rptt->questions_client_report[0] ).'</td><td valign=top>'.pretty_var_dump ( $client_rptt->question_elements_client_report[0] ).'</td>';
			for ($i=0; $i<$this->number_of_clients; $i++)  //DEBUG
			{
                echo "<td valign=top>vetted form answers:".pretty_var_dump ( $client_rptt->vetted_frm_ans[$i] );
				echo "</td><td valign=top>vetted values:".pretty_var_dump ( $client_rptt->vetted_vals[$i] );
				echo "</td><td valign=top>valuation:".pretty_var_dump ( $client_rptt->validation );
                echo "</td>";
			}
			echo '</tr></table>';
			*///END DEBUG
            
			break;  //for now just assume one report_type_id
			
        } //END FOREACH report_type_id
        
        if ( $this->rpt_type_profile_array["report_on_timeperiod"] != 'no' )
        {
            if ($date_quest->existing_report_dates)
            {
                $valid_date_form_answers = $date_quest->existing_report_dates;
            }
            else
            {
                $valid_date_form_answers = $validation_date->vetted_form_answer;
            }
            
            $this->date_html = $date_quest->build_report_date_table ($valid_date_form_answers);
        }
        
        //Check that this is not a form that has aleady been submitted
        duplicate_form_submission_check ( $_POST['fsig'] );
        
        if ( !$question_validation_error )
		{
		    //echo "<br>NO ERRORS<br>";
			
            foreach ( $this->report_type_id AS $cur_rpt_type_id )
			{
                 //If no form error, and a fresh form was not requested, insert the data, give a OK message, and go to next page/form
                 $rpt_type_profile = pull_report_type_profile ( $cur_rpt_type_id );
			     $repid = $rpt_type_profile['report_type_id'];
		         
				 if ($this->edit_report_id)
				 {
					$edit_id_values = array_values( $this->edit_report_id);
				 }
				 else
				 {
					$edit_id_values[0] = null;
				 }
                 
		         //Loop through the clients... 
				 //echo "<hr color=black>clients to process:".$this->number_of_clients;
		         for ($k=0; $k < $this->number_of_clients; $k++)
				 {
					 $insert = new Insert_client_report;
                     
					 if ( $rpt_type_profile["report_on_timeperiod"] != "no" )
				     {
		                $insert_dates = $date_quest->translate_report_dates_to_unix_time($validation_date->vetted_value);
		             }
					 
		             //...if they submitted a report for a client, insert them
		             if ( $client_rptt->vetted_vals[$k] )
				     {
		                 //echo "<br>Inserting report, edit id is ".$client_rptt->report_id."<p>";
		                 $new_report_id = $insert->insert_client_report_answers ( $rpt_type_profile['report_type_id'],
		                                                                          $this->client_info[$k]['client_id'], 
																				  $client_rptt->questions_client_report[$k],
		                                                                          $client_rptt->vetted_vals[$k],
																				  $client_rptt->share_question_answer[$k],
		                                                                          $edit_id_values[0], //$this->edit_report_id,
																				  $insert_dates );
		             }
					 //Note the report we have inserted for later editing
                     $this->tag_values['{FORM_END}'] .= display_hidden_form_values ( 'edit_report_id['.$k.']', $new_report_id );
		         }
		         
				 //TODO: following page functionality is totally unimplemented...
		         //If we are editing a report, send the new report id into the direct to page function
		         if ( $edit_id_values[0] || $rpt_type_profile["report_that_follows"] == "none")
			     {
		             $return_to_this_report = $new_report_id;
		         }
				 
				break; //for now just assume one report_type_id
            }
        }
        else  //There is an error, or fresh form indicator, return report entry form
		{
			//echo "<P>ERRORS FOUND IN SUBMIT</P>";
            //foreach ( $this->report_type_id AS $cur_rpt_type_id )
			//{
		        $page_id = $this->rpt_type_profile_array["report_type_id"];
	            
		        $this->tag_values["{FORM_END}"] .= display_hidden_form_values("report_name", $this->rpt_type_profile_array["report_type_id"]);
		        
				//echo '<br>edit_report_id:'.pretty_var_dump($this->edit_report_id);
		        //If viewing/editing a report, place the report id of the report we are editing as a hidden post value,
		        // and give a button to submit with if we are allowed to submit edits
		        if ($this->edit_report_id[0]) // || (!is_array($this->edit_report_id) && $this->edit_report_id) )
				{
                    //echo ' if edit_report_id[0]... '.$this->edit_report_id[0];
		            $replace = new Insert_client_report;
                    //echo " find_newest_report_in_series (".$edit_id_values[0].")";
		            $newest_rpt = $replace->find_newest_report_in_series ($edit_id_values[0]);
                    
		            $this->tag_values["{FORM_END}"] .= display_hidden_form_values("edit_report_id", $newest_rpt);
		            $this->tag_values["{FORM_END}"] .= display_hidden_form_values("report_unit", "client");
		            
		            $rpt_c = new Reports;
					//echo "rpt_type_profile_array:".pretty_var_dump($this->rpt_type_profile_array)."exist_rpt_prof:".pretty_var_dump($exist_rpt_prof);
					
                    //echo "calling pull_existing_client_rpt_profile()<br>";
		            $exist_rpt_prof = $rpt_c->pull_existing_client_rpt_profile ($edit_id_values[0]);
                    
                    //bugbug, todo: $edit_id_values[0] may be 0 or some decremented value which results in no no existing reports returned.
                    if ($exist_rpt_prof)
                    {
	                    echo "rpt_c-pull_existing_client_rpt_profile() called and timestamp is:".$exist_rpt_prof["report_timestamp"];
		                $this->tag_values["{CLIENT IDENTIFIER ENTRY TABLE}"] .=  
					                              $rpt_c->display_report_profile ( "Edit ".$this->rpt_type_profile_array["report_title"],
		                                                                           $exist_rpt_prof["user_name_first"]." ".$exist_rpt_prof["user_name_last"],
																				   $exist_rpt_prof["org_name"],
		                                                                           $exist_rpt_prof["report_timestamp"]  );
                    }
                    else
                    {
                        $this->tag_values["{CLIENT IDENTIFIER ENTRY TABLE}"] .=  ' ';
                    }
		            
		            //if (is_allowed_to_edit_client_report ($this->edit_report_id[0], $this->org_id) == 1)    {
					//Pull permissions for this report we are looking at
        		    $perms = report_permissions_client ( $edit_id_values[0], $this->org_id, $this->user_id );
					
		            if ( $perms['edit_rpt'] == 1 )
					{
		                //$this->tag_values["{FORM_END}"] .= form_end ("9Click here to submit edited client form", 1);
		                //Delete the form if empty form indicates it  
		                if ( $this->form_status == "delete" )
						{
		                    //$del= new Insert_client_report;
		                    $replace->delete_client_report ($newest_rpt);
		                }
		                /*$this->tag_values["{FORM_END}"] .= "<p/>".list_previous_versions_of_client_report ($this->edit_report_id, $this->rpt_type_profile_array["report_type_id"]);
		                $this->tag_values["{FORM_END}"] .= "<a href=\"".
						                                    $this_page."?empty_form=delete&report_unit=client&edit_report_id=".
						                                    $this->edit_report_id."&report_type_id=".$page_id."\">Click here to DELETE this form</a>";*/
		            }
		            /*else
					{
					    
		                $this->tag_values["{FORM_END}"] .= "<p/>".list_previous_versions_of_client_report ($this->edit_report_id[0], $this->rpt_type_profile_array["report_type_id"]); 
		                $this->tag_values["{FORM_END}"] .= 'You are not allowed to edit this form';
		            }*/
		        }
		        
		        //Build the html for the client id entry page
		        //$this->tag_values["{CLIENT IDENTIFIER ENTRY TABLE}"] .= 
				//            $client_rptt->assemble_client_report_entry_table( $this->rpt_type_profile_array["report_title"], 
					//														  $date_html    );
	    }
        //echo ' exit process_submitted_form() ... ';
    }
    
    
    function process_delete_request ( )
    {
        $delete_report = new Insert_client_report;
        foreach ( $this->edit_report_id AS $cur_del )
        {
            $delete_report->delete_client_report ( $cur_del );
        }
        
        $this->display_form_edit ();
    }
    
    
    function commom_form_elements ()
	{
        GLOBAL $head_page_specific, $head_dynamic_style, $client_rptt, $client_info;
        
		$this->tag_values["{CLIENT IDENTIFIER ENTRY TABLE}"] = $this->report_header;
		
		//Get household income if viewing client_income
		if ($this->rpt_type_profile_array['report_type_id']=='client_income' || $this->rpt_type_profile_array['report_type_id']=='client_income_exit_followup')
		{
			$this->form_type = 'client_income_forms';
		}
		else
		{
			$this->form_type = 'client_forms';
		}
		
        $this->tag_values["{CLIENT IDENTIFIER ENTRY TABLE}"] .= $client_rptt->assemble_client_report_entry_table ($this->rpt_type_profile_array["report_title"], $this->date_html, $this->form_type);
		
		//Profile "view" table is not displayed on CLIENT forms page... so this html is lost...
        //$profile = new Client_profile;
        //$this->tag_values['{CLIENT PROFILE}'] = $profile->display_client_profile_table ( $this->client_info, '', 'client_forms' );
        
        //$relationships = new Relationships ( $this->client_info['0']['client_id']);
        //$this->tag_values['{RELATIONSHIPS}'] = $relationships->display_other_related_clients_table ();
		$this->tag_values['{RELATIONSHIPS}'] = " "; //no longer makes sense to display this info...
        
        $reports = new Reports;
		
        $this->tag_values["{FORM_START}"] = form_start ();
        
        $this->tag_values["{PAGE TITLE}"] = page_title_table();
        $this->tag_values["{MENU}"] = menu();
        $this->tag_values["{HEAD}"] = head ( $page_title, $head_page_specific, $head_dynamic_style );
        $this->tag_values["{FOOTER}"] = footer();
        
        $html_template = 'client_report_forms.html';
        
        template_parser ( $html_template, $this->tag_values );
    }




} //END of Report_client_form class.
?>
Return current item: Homeless Mangement Information System