Location: PHPKode > projects > Homeless Mangement Information System > hmis/include/Insert_setup_group_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  Insert_setup_group	{
	
	var $questions;
	var $form_answer;
	var $group_name;
	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;
		
	function Insert_setup_group ($questions, $form_answer, $user_access_level )	{
		GLOBAL $group_term, $question_validation_error, $message, $message_type, $unique_seq;
		$this->questions = $questions;
		//$this->form_answer = $form_answer;
		$this->user_access_level = $user_access_level;

		$sql = "SELECT * FROM organizations WHERE org_name LIKE '".$form_answer["org_name"]."'";
		$duplicate_check = run_query ($sql, "org table setup org insert");
		if ( num_rows ($duplicate_check) > 0 )	{
			question_error_marking ("org_name", "Duplicate Organization Name. ");
		}

        $pass = new Passwords ();
        $pass->check_login_and_password ( $form_answer['login'], $form_answer['password'] );
        
        if ( $pass->login_error )   {
            question_error_marking ( 'login', $pass->login_error );
        }
        
        if ( $pass->password_error )   {
            question_error_marking ( 'password', $pass->password_error );
        }

		//secondary_form_answer_validation ("Login", "login", $form_answer["login"], "8");

		//secondary_form_answer_validation ("Password", "password", $form_answer["password"], "8");
		

	    //If no errors, insert the new group (and group administrator) information
	    if (!$question_validation_error)	{
		    //Set-up Group
		    $sql = "INSERT INTO groups (group_name, group_contract_num, county_served) VALUES ('".$form_answer["org_name"]."', '".$form_answer["contract_number"]."', '".$form_answer["county_served"]."')";
		    run_query ($sql, "groups table setup group insert");

		    //Set-up organizations
		    $sql = "SELECT group_name FROM groups WHERE group_name LIKE '".$form_answer["org_name"]."' AND group_contract_num LIKE '".$form_answer["contract_number"]."'";
		    $last_insert = run_query ($sql, "gate insert id select");
		    $group_name_display = fetch_result ($last_insert, "gate user id");

            $sql = "SELECT group_id FROM groups WHERE group_name LIKE '".$form_answer["org_name"]."' AND group_contract_num LIKE '".$form_answer["contract_number"]."'";
		    $last_insert = run_query ($sql, "gate insert id select");
		    $group_id_insert = fetch_result ($last_insert, "gate user id");

		    $sql = "INSERT INTO organizations (org_name, group_id, org_type, org_system_type, web_page_address, account_status) VALUES ('".$form_answer["org_name"]."', '".$group_id_insert."', 'group', 'client', '".$form_answer["web_page_address"]."', 'active')";
		    run_query ($sql, "organizations creation");

		    //Set-up gate
		    $sql = "SELECT org_id FROM organizations WHERE group_id LIKE '".$group_id_insert."'";
		    $last_insert = run_query ($sql, "gate insert id select");

		    $org_id_insert = fetch_result ($last_insert, "gate user id");

		    $sql = "INSERT INTO gate (gate_login, gate_password, gate_status) VALUES ('".$form_answer["login"]."', '".md5 ( $form_answer["password"] )."', 'pending')";
		    run_query ($sql, "gate insertion");

		    $sql = "SELECT user_id FROM gate WHERE gate_login LIKE '".$form_answer["login"]."' AND gate_password LIKE '".md5 ( $form_answer["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."',
              '".$form_answer["first_name"]."', '".$form_answer["last_name"]."', '".$form_answer["phone_number"]."',
               '".$form_answer["email_address"]."')";
		    run_query ($sql, "user_info creation");

		    $message .= $group_term." ".$group_name_display." successfully added. ";
		    $message_type = "ok";
	    }
	}
}

	


					


?>
Return current item: Homeless Mangement Information System