Location: PHPKode > projects > Homeless Mangement Information System > hmis/edit_user_info.php
<?php
//*Client Data System, Copyright (C) 2000, 2001 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

////Variables used to set-up the page
//Used by many elements, including the questions in general, "menu()", and help links
$page_id = "edit_user_info";
//Used by "authenticate.inc" to check against the user session variable $access_level 
$page_access_levels = ":10:20:30:";

////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."head.inc");	
include($include_root."template_parser.inc");
//include($include_root."Insert_setup_group_class.inc");
include($include_root."questions_into_tags_function.inc");
include($include_root."page_elements_display.inc");
include($include_root.'passwords_class.inc');
//include($include_root."update_password_class.inc");
include($include_root."user_info_functions.inc");
include($include_root."services_functions.inc");

//Convert submitted form answer into user-space answer
$form_answer["gate_status"] = $HTTP_POST_VARS["form_answer"]["gate_status"];

//display_value($HTTP_POST_VARS["extra_form_answer[1]"]);


//Define what set of questions to use depending on $access_level
$quest = new Load_new_entity_questions();
switch ($access_level)
{
	case "10":
        $page_title = "Edit ".$group_term;
        $submit_term = "Submit ".$group_term." Info";
        $instructions = "Change this ".$group_term."'s information and then press \"".$submit_term."\" below. ";
        $temp_instruct = "Select an ".$group_term." below to edit their information. ";
        $quest->load_new_group_questions(FALSE);
	    break;
    
	case "20":
        $page_title = "Edit ".$organization_term;
        $submit_term = "Submit ".$organization_term." Info";
        $instructions = "Change this ".$organization_term."'s information and then press \"".$submit_term."\" below. ";
        $temp_instruct = "Select a ".$organization_term." below to edit their information. ";
        $quest->load_new_org_questions(FALSE);
	    break;
    
	case "30":
        $page_title = "Edit Users";
        $submit_term = "Submit User Info";
        $instructions = "Change this User's information and then press \"".$submit_term."\" below. ";
        $temp_instruct = "Select a User below to edit their information. ";
        $quest->load_new_user_questions(FALSE);
	    break;
}

//Used by "head()" to list instructions for using the page


//If not from a get-link that includes the variable $edit_user_id AND no form submitted, 
//use the page template and build a table listing all the users administered by the current user
if(!$HTTP_GET_VARS["edit_user_id"] && $form_submitted != $page_id)
{
    $instructions = $temp_instruct;
	$use_template = "edit_user_info";
	$tag_values["{EDIT USER TABLE}"] = display_edit_user_info_table($user_id, $access_level);
}

//echo "Form submitted is: ".$form_submitted."<p>";
//echo "Page id is: ".$page_id."<p>";
if ($form_submitted == $page_id)
{
	//echo "Form was submitted<p>";
	//Check that the current user is allowed to edit the user defined by $hidden_user_id 
	$error_check = edit_id_validation ($HTTP_POST_VARS["hidden_user_id"], $access_level, $org_id, $group_id);
	if($error_check == "error")
	{
		echo "Illegal Edit Attempt, IP Logged";
		exit;
	}
    
	//Put the relevant question attributes into an array
	//$pull_questions = new Questions_into_array ($question_set, $access_level, $org_id, $group_id, "display");
    
	//Validate the answers against the questions attributes pulled into an array above
	//$validation = new Questions_answers_validation($pull_questions->questions, $pull_questions->question_elements, $form_answer);
	//echo 'form_ans_b4_validation:'.pretty_var_dump($form_answer);
    $validation = new Questions_answers_validation( $quest->questions, $quest->question_elements, $form_answer );
    
	//If no validation errors in the questions, run the page specific insert date class
	if (!$question_validation_error)
	{
		//Pull the user variables assoicated with the user whose info is being edited 
		$edit_user_variables = pull_user_variables ($HTTP_POST_VARS["hidden_user_id"]);	
		//Insert the updated user variables into the database
		//edit_organization ($pull_questions->questions, $validation->form_answer, $extra_form_answer["1"], $HTTP_POST_VARS["hidden_user_id"], $edit_user_variables["org_id"], $edit_user_variables["group_id"]);
        
        $z_org_id = "org_id";
        
		//echo ' edit_organization():'.pretty_var_dump($edit_user_variables[$z_org_id]).' form_ans:'.pretty_var_dump($validation->form_answer);
        edit_organization ( $quest->questions,
		                    $validation->form_answer,
							$form_answer["gate_status"],
							$HTTP_POST_VARS["hidden_user_id"],
							$edit_user_variables[$z_org_id],
							$edit_user_variables["group_id"] );
        
		//bugbug: this conditional is redundant unless the above call resets this value somehow...?
		if (!$question_validation_error)
		{
            //Reset the form blanks, define the template, signal the neeed to revert to the list of users, build the user list table
            $validation->vetted_form_answer = "";
            $use_template = "edit_user_info";
            $revert_to_user_list = "yes";
            $tag_values["{EDIT USER TABLE}"] = display_edit_user_info_table( $user_id, $access_level );
            $message .= 'Changes Successfully Submitted. ';
            $message_type = 'ok';
        }
        else
		{
            //Since there was a validation error, insert the hidden value for the user_id that is being edited
            $tag_values["{FORM_END}"] .= display_hidden_form_values	("hidden_user_id", 	$HTTP_POST_VARS["hidden_user_id"]);
        }
        
        //also redundant but...
        /*if (!$question_validation_error && ($form_answer['new_password'] || $form_answer['verify_password']))
        {
            //include_once($include_root.'passwords_class.inc');
            //echo "<table border=1 bordercolor=blue><tr><td valign=top>".pretty_var_dump($quest->questions)."</td><td valign=top>".pretty_var_dump($validation->form_answer)."</td><td valign=top>".$user_id."</td></tr></table>";
			$update_password = new Update_password ($quest->questions, $validation->form_answer, $user_id);
            
			if (!$question_validation_error) {$validation->vetted_form_answer = "";}
		}*/
    }
    else
	{
        //Since there was a validation error, insert the hidden value for the user_id that is being edited
        $tag_values["{FORM_END}"] .= display_hidden_form_values	("hidden_user_id", 	$HTTP_POST_VARS["hidden_user_id"]);
    }
}

//If coming from the list of users, OR the form submitted, AND there is not a flag calling for reversion to the list of users, 
//display the fill-in form for editing
if ( ($HTTP_GET_VARS["edit_user_id"] || $form_submitted == $page_id) && !$revert_to_user_list )
{
	//If coming from the list of users, check that they are allowed to edit the user and put the edited users id in a hidden form field
	if($HTTP_GET_VARS["edit_user_id"])
	{
		$error_check = edit_id_validation ($HTTP_GET_VARS["edit_user_id"], $access_level, $org_id, $group_id);
		if($error_check == "error"){echo "Illegal Edit Attempt, IP Logged"; exit;}
		$tag_values["{FORM_END}"] .= display_hidden_form_values	("hidden_user_id", $HTTP_GET_VARS["edit_user_id"]);
    }
    
	$use_template = "add_groups";
	//Pull appropriate questions attributes into an array (based on page, user, org, and access level) for display
	//$pull_questions_display = new Questions_into_array ($question_set, $access_level, $org_id, $group_id, "display");
	
	//If no coming from a submittted form, pull out the existing users form values to fill in the form blanks
	if(!$form_submitted)
	{
		$existing_user_answers = pull_user_variables ($HTTP_GET_VARS["edit_user_id"]);
		$input_form_answers = assign_user_values_to_questions_form_blanks ($quest->questions, $quest->question_elements, $existing_user_answers);
		$form_answer["gate_status"] = $existing_user_answers["gate_status"];
	}
	else //If coming from a submited form, use the just submitted/vetted form answers to fill in the form blanks
	{
	    $input_form_answers = $validation->vetted_form_answer;
	}
    
	//Convert the page-specific database questions into HTML, and assign them to "$tag_values"
	questions_into_tags ($quest->questions, $quest->question_elements, $input_form_answers);
    
	//Create a tag containg HTML for the radio button defining if the user account is active or inactive
	$tag_values["{EXTRA QUEST_1999}"] = 
		"Account Status<br>Active<input type=\"radio\" name=\"form_answer[gate_status]\" value=\"active\" ".build_tabindex_html(1098);
	if($form_answer["gate_status"] == "active"){$tag_values["{EXTRA QUEST_1999}"] .= " CHECKED "; }
    //if($form_answer["gate_status"] == "pending"){$tag_values["{EXTRA QUEST_1999}"] .= " DISABLED "; }
	$tag_values["{EXTRA QUEST_1999}"] .= ">";
	$tag_values["{EXTRA QUEST_1999}"] .= "&nbsp;  Inactive<input type=\"radio\" name=\"form_answer[gate_status]\" value=\"inactive\" ".build_tabindex_html(1098);
	if($form_answer["gate_status"] == "inactive"){$tag_values["{EXTRA QUEST_1999}"] .= " CHECKED "; }
    //if($form_answer["gate_status"] == "pending"){$tag_values["{EXTRA QUEST_1999}"] .= " DISABLED "; }
    $tag_values["{EXTRA QUEST_1999}"] .= ">";
	$tag_values["{EXTRA QUEST_1999}"] .= "&nbsp;  Pending<input type=\"radio\" name=\"form_answer[gate_status]\" value=\"pending\" ".build_tabindex_html(1098);
	if($form_answer["gate_status"] == "pending"){$tag_values["{EXTRA QUEST_1999}"] .= " CHECKED "; }
	$tag_values["{EXTRA QUEST_1999}"] .= ">";
}

//Define the values for tags contained in the html template
$tag_values["{FORM_START}"] = form_start ();
$tag_values["{FORM_END}"] .= form_end ($submit_term, 1);
$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();

//Parse the template for this page, replacing the tags with the HTML defined above.
template_parser ($use_template.".html", $tag_values);

?>
Return current item: Homeless Mangement Information System