Location: PHPKode > projects > Homeless Mangement Information System > hmis/include/add_users_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  Add_user
{
	var $questions;
	var $form_answer;
	var $group_name;
	var $group_id;
	var $org_id;
	var $group_contract_num;
	var $group_org_name;
	var $org_system_type;
	var $user_access_level;
	var $user_name_first;
	var $user_name_last;
	var $user_phone;
	var $user_email;
	var $question_validation_error_add_org_class;
	
	function Add_user ($questions, $form_answer, $group_id, $org_id)
    {
		GLOBAL $question_validation_error, $message, $message_type, $unique_seq;
		
		$this->questions = $questions;
		$this->form_answer = $form_answer;
		$this->group_id = $group_id;
		$this->org_id = $org_id;
		$this->user_access_level = "40";
		
		foreach ($this->questions as $question_value)
        {
			//echo "title is:".$question_value["question_title"]."<br>";
			switch ($question_value["question_id"])
            {
				case "first_name":
					$insert_first_name = $form_answer[$question_value["question_id"]];
					break;
				
				case "last_name":
					$insert_last_name = $form_answer[$question_value["question_id"]];
					break;
                
				case "email_address":
					$insert_email = $form_answer[$question_value["question_id"]];
					break;
                
				case "phone_number":
					$insert_phone = $form_answer[$question_value["question_id"]];
					break;
                
				case "login":
					$insert_new_login = $form_answer[$question_value["question_id"]];
					$login_question_id = $question_value["question_id"];
					break;
                
				case "password":
					$insert_new_password = $form_answer[$question_value["question_id"]];
					$password_question_id = $question_value["question_id"];
					break;
                
				case "verify_password":
					$verify_password = $form_answer[$question_value["question_id"]];
					$verify_password_question_id = $question_value["question_id"];
					break;
                
				default:
					echo "Question title could not be matched to question in insert_setup_group_class: ".$question_value["question_title"]."<br>";
                    exit;
		    }
	    }
        
        /*//Check for duplicate logins
		$sql = "SELECT * FROM gate WHERE gate_login LIKE '".$insert_new_login."'";
		$duplicate_check = run_query ($sql, "org table setup org insert");
		if(num_rows ($duplicate_check) > 0)
        {
		    question_error_marking ($login_question_id, "Duplicate Login Entry. ");
		}
        */
        
        if ( $insert_new_password != $verify_password )
        {
            question_error_marking ( $password_question_id, 'Password and Verify password MUST match. ' );
            question_error_marking ( $verify_password_question_id, 'Password and Verify password MUST match. ' );
        }
        
        $pass = new Passwords ();
        $pass->check_login_and_password ( $insert_new_login, $insert_new_password );
        
        //secondary_form_answer_validation ("Login", $login_question_id, $insert_new_login, "8");
        
		//secondary_form_answer_validation ("Password", $password_question_id, $insert_new_password, "8");
        
        if ( $pass->login_error )
        {
            question_error_marking ( $login_question_id, $pass->login_error );
        }
        
        if ( $pass->password_error )
        {
            question_error_marking ( $password_question_id, $pass->password_error );
        }
        
	    //If no errors, insert the new group (and group administrator) information
	    if ( !$question_validation_error )
        {
		    //Set-up organizations
		    transaction_begin ( 'Add user' );
            $group_id_insert = $this->group_id;
		    $org_id_insert = $this->org_id;
            
		    $sql = "INSERT INTO gate (gate_login, gate_password, gate_status) VALUES ('".$insert_new_login."',
                   '".md5 ( $insert_new_password )."', 'pending')";
		    run_query ($sql, "gate insertion");
            
		    $sql = "SELECT user_id FROM gate WHERE gate_login LIKE '".$insert_new_login."' 
            AND gate_password LIKE '".md5 ( $insert_new_password )."'";
		    $last_insert = run_query ($sql, "gate insert id select");
            
		    $last_user_id_insert = fetch_result ($last_insert, "gate user id");
            
		    $sql = "INSERT INTO user_info (user_id, user_access_level, org_id, user_name_first, user_name_last, user_phone, user_email) VALUES ('".$last_user_id_insert."', '".$this->user_access_level."', '".$org_id_insert."', '".$insert_first_name."', '".$insert_last_name."', '".$insert_phone."', '".$insert_email."')";
            run_query ($sql, "user_info creation");
            
            transaction_commit();
		    $message .= "User \"".stripslashes($insert_first_name)." ".stripslashes($insert_last_name)."\" sucessfully added. ";
		    $message_type = "ok";
	    }
	}
}


?>
Return current item: Homeless Mangement Information System