Location: PHPKode > projects > Homeless Mangement Information System > hmis/household.php
<?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


$page_access_levels = ':40:';
//$page_profile = "View Client Information";

////Header for every page that finds the include directory, connects to db, authenticates user access 
include("initialize_pointer.php");
if(!include($include_root."authenticate.inc")){echo "No Authentication"; exit; };

include($include_root."Questions_into_array_class.inc");
include($include_root."questions_display.inc");
include($include_root."Questions_answers_validation_class.inc");
include($include_root."question_set_validation_function.inc");
include($include_root."questions_into_tags_function.inc");
include($include_root."head.inc");
include($include_root."template_parser.inc");
include($include_root."page_elements_display.inc");
include($include_root."client_id_class.inc");
include($include_root."client_report_class.inc");
include($include_root."insert_household_report_class.inc");
include($include_root."insert_client_report_class.inc");
include($include_root."client_profile_class.inc");
include($include_root.'client_lookup_class.inc');
include($include_root."reports_class.inc");
include($include_root."report_date_questions_class.inc");
include($include_root."relationships_class.inc");
include($include_root."user_info_functions.inc");
include($include_root."referrals_class.inc");
include($include_root."encryption_class.inc");
include($include_root."date_encrypted_functions.inc");
include($include_root."services_functions.inc");

convert_post_and_get_variable ('report_name');
convert_post_and_get_variable ('report_unit');
convert_post_and_get_variable ('form_answer_added_client');
convert_post_and_get_variable ('empty_form');
convert_post_and_get_variable ('ref_to_org_id');
convert_post_and_get_variable ('form_submitted');
$ref_to_org_id += 0;

$page_title = 'Households';
//echo "household.php:<br>form_submitted: " .$form_submitted. "<br>form_status" . pretty_var_dump( $form_status ) ."report_type_id:". pretty_var_dump ( $report_type_id ) ."report_unit:". pretty_var_dump ( $report_unit ) ."report_name:". pretty_var_dump ( $report_name ) ."edit_report_id:". pretty_var_dump ( $edit_report_id );

if ($_GET['clear_results'])
{
	$message = '';
	$message_type = 'ok';
	$matching_clients_identifier_array = null;
}

if (!$cli_prof)
{
	$cli_prof = new Client_profile();
}

//MUST REMOVE OR ADD CLIENTS TO SESSION BEFORE CALLING SHOW REPORT OPTIONS...

if ( ereg ( '[0-9]', $_GET['remove_client_from_household_session'] ) )
{
	$message = '';
	$message_type = 'ok';
	$start_count_in_view = count($client_info);
	$id_to_remove = $_GET['remove_client_from_household_session'];
	
	if ($client_info[0]['client_id'] == $id_to_remove)
	{
		$client_info = '';
		
		//TODO: its possible to get the below commented out code to work.  Basically when removing a household from view the next UNRELATED client
		//would id the household to pull into view.  But this is buggy currently and actually, it looks odd to see three clients removed from view
		//only to be replaces by three others.  Likely this behavior would confuse users so best to just remove ALL clients in view when remove
		//household from view is selected...
		/*$message = 'By removing the lead client in view, all related clients were removed, and the next unrelated client in view becomes the lead.';
		$message_type = 'ok';*/
		$cli_prof->remove_client_from_household_session ( $id_to_remove, 'remove_all_in_household' );
		//$client_info = $cli_prof->enforce_h_view_rules();
	}
	else
	{
		$cli_prof->remove_client_from_household_session ( $id_to_remove );
	}
}
elseif ( ereg ( '[0-9]', $_GET['add_client_to_household_session'] ) )
{
	$message = '';
	$message_type = 'ok';
    $cli_prof->add_client_to_household_session ( $_GET['add_client_to_household_session'] );
}

if (($_GET['add_client_to_household_session'] && count($client_info)==1) || $_GET['clear_results']) // )
{
	//echo '<br>2.ENFORCE VIEW RULES<br>';
	$client_info = $cli_prof->enforce_h_view_rules();
}

//Lookup Prep

if ( $form_submitted == 'relationship_change' )
{
	$message = 'This change in relationship will not take effect until you submit a household form.';
	$message_type = 'ok';
    $cli_prof->edit_client_relationship_session ( $form_answer['rel'] );
	GLOBAL $rel_changed;
	$rel_changed=TRUE;
}

if ( $form_submitted == 'finalize_relationship_change' )
{
    $insert_hh_rpt = new Insert_household_report();
    if (!is_array($questions_atts))
		settype ( $questions_atts, 'array' );
	$inserted_hh_rpt_id = $insert_hh_rpt->insert_report_answers ( 'INTAKE', $client_info, $questions_atts, '', $org_id, 'yes' );
}


//If no client info is loaded into the session, send them to the client id entry page
//...and no client identifiers are loaded into the system, take them to the the identifier options
if ( !$client_info )
{
	if ($_GET['remove_client_from_household_session'])
	    $message = 'Household removed from view.';
	else
    	$message = 'No household forms are available because no household is defined in the View.';
    $message_type = "ok";
	$tag_values['{CLIENT PROFILE}'] = '<table class="generictable"><tr><td class="generictabletop">Clients in View</td></tr></table><table class="generictable"><tr><td class="smalltd">None</td></tr></table><i><br>To access a household form at least one client household must be in view.  You can add an existing client household to the view from the lookup query results below or by adding new client(s) to the system.</i>';
    $tag_values["{REPORT_OPTIONS}"] = " ";
	//header ( 'Location: '.$system_directory.'createclients.php?report_name=options_identifier&empty_form=yes' );
}
else
{
    //$rel = new Relationships ( $client_info[0]['client_id'] );
    //$tag_values['{RELATIONSHIPS}'] = 'g<br>g<br>g'.$rel->display_other_related_clients_table().'<br>g';
    show_household_report_options();
}






//Client Lookup Form
   if ( $form_answer && $form_submitted=='client_lookup' )
{
	$message = '';
	$message_type = 'ok';
	$id_quests = new Client_id;
    $id_quests->pull_client_id_entry_questions_array ( '0', 'yes' );
    
    $validated_iden_ans = new Questions_answers_validation ( $id_quests->questions, $id_quests->question_elements, $form_answer ); 
    
	//Ensure all client names submitted for search are cased just as they are entered into the database.
	//That is, first letter of first, middle, and last name are capetalized and rest is lowercase.  This
	//is done because search, queries are all case sensative on encrypted values.  Note hardcoded 0!
	if (strlen($validated_iden_ans->vetted_value["name_first0"])>0)
		$validated_iden_ans->vetted_value["name_first0"] = 
		     ucfirst(strtolower(trim($validated_iden_ans->vetted_value["name_first0"])));
	if (strlen($validated_iden_ans->vetted_value["name_middle0"])>0)
		$validated_iden_ans->vetted_value["name_middle0"] =
		     ucfirst(strtolower(trim($validated_iden_ans->vetted_value["name_middle0"])));
	if (strlen($form_answer["name_last0"])>0)
		$validated_iden_ans->vetted_value["name_last0"] = 
		     ucfirst(strtolower(trim($validated_iden_ans->vetted_value["name_last0"])));
    
	//Display Lookup Form with submitted data
    display_client_lookup_entry_form ( $validated_iden_ans->vetted_form_answer );
    $clup = new Client_lookup;
    
    $matching_clients_identifier_array = $clup->lookup_client_using_identifiers ( $id_quests->questions, $validated_iden_ans->vetted_value );
    //echo 'matchin array<p>'; var_dump ( $matching_clients_identifier_array ); echo '<p>';
	$_SESSION['matching_clients_identifier_arrayB'] = $matching_clients_identifier_array;
    $tag_values['{MATCHING_CLIENTS}'] = display_client_identifiers_table ( $matching_clients_identifier_array, 'Clients matching query' );
    
    $tag_values['{FORM_END}'] .= form_end ($button_label, 2);
  	//echo '<hr color=purple>';
}
else //no client lookup
{
    //$rel = new Relationships ( $client_info[0]['client_id'] );
    //$tag_values['{RELATIONSHIPS}'] = $rel->display_other_related_clients_table();
	//$tag_values['{RELATIONSHIPS}'] = " ";  //we no longer display relationships on this page as it does not make sense...
	
	//Display Lookup Form
    display_client_lookup_entry_form ();
	if ($matching_clients_identifier_array)
	{
		$tag_values['{MATCHING_CLIENTS}'] = display_client_identifiers_table ( $matching_clients_identifier_array, 'Clients matching query' );
		$tag_values["{FORM_END}"] .= form_end ($button_label, 2); //submit_button ( 'list', 'Return list of matching clients' );
	}
	else
	{
        //$tag_values["{FORM_END}"] .= display_hidden_form_values("results", 'FALSE');
		$tag_values["{FORM_END}"] .= submit_button ( 'list', 'Return list of matching clients' );
	}
    
    $tag_values["{FORM_END}"] .= "</form>";
}
//End Client Lookup Form



/********************************************************************************************
 * Name: show_household_report_options: 
 * Description: Return all report forms for household.
 * 
 * Details and Notes: 
 * 
 * @param: Several global params
 * @return: html written to global $tag_values
 * 
 * History: Updated 1/17/03 by Jeff.
 ********************************************************************************************/
function show_household_report_options ()
{
    GLOBAL $tag_values, $html_template, $page_id, $instructions, $user_id, $org_id, $client_info, $page_title, $message, $message_type, $this_page;
	
    $page_id = "report_options";
    $instructions = "Choose from a form below";
    
    $report_type = "options_household";
	$report_types = "household";
	
    $report_list_array = pull_names_of_reports_user_can_create ( $user_id, $org_id, $report_types );
	
    //if ($current_report['report_on_unit'] == 'household' || $current_report['report_on_unit'] == 'household_services')
	//{
	    $formtype = 'household';
	//}
	
    $final_html .= '<br><table cellpadding=0 cellspacing=0><tr><td colspan=3>Select a ' .$formtype. ' form below for the above clients.</td></tr>';
	$final_html .= '<tr><td> </td><td> <table>';
	
    if ( is_array ( $report_list_array ) )  {
        foreach ( $report_list_array AS $current_report )
		{
            $final_html .= '<tr><td>
              <a href="'.$system_directory.'report.php?report_type_id='.$current_report['report_type_id'].'&empty_form=yes">'.
                $current_report['report_title'].'</a></td></tr>';
        }
    }
    else
	{
        $final_html .= "<tr><td>You do not have permission to create any forms.</td></tr>";
    }
    
    $final_html .= '</td></tr></table></td><td> </td></tr></table>';
    
    $tag_values["{REPORT_OPTIONS}"] = $final_html;
}

//Shows the client currently in view.
if ( $client_info )
{
  $profile = new Client_profile;
  //echo "<br>Should be display_client_profile_table($client_info, 'Clients in View', $profile_table_type, $this_page, $page_id) ";   //$form_submitted  $form_status
  //echo 'yoyoyo'.pretty_var_dump($client_info);
  $tag_values["{CLIENT PROFILE}"] = $profile->display_client_profile_table ($client_info, 'Clients in View', 'households'); //, $formtype);
}
//The following are also in the client_lookup_class.inc
//Sharing_permissions_question class
//display_client_lookup_entry_form()
//display_client_identifiers_table()

//ensure client_info persists
$_SESSION['client_infoB'] = $client_info;
//Set template
$html_template = "report_options.html";
//Define the values for tags contained in the html template
$tag_values['{RELATIONSHIPS}'] = ' ';
$tag_values["{FORM_START}"] = form_start ($this_page);
$tag_values["{PAGE TITLE}"] = page_title_table();
$tag_values["{MENU}"] = menu();
$tag_values["{HEAD}"] = head ($page_title, $head_page_specific, $head_dynamic_style);
$tag_values["{FOOTER}"] = footer();
template_parser ($html_template, $tag_values);

?>
Return current item: Homeless Mangement Information System