Location: PHPKode > projects > Homeless Mangement Information System > hmis/include/add_organization_class.inc
<?php

class  Add_organization	{
	
    //Note: the variable $questions does not appear to be needed as input to this function.
    
	//var $questions;
	//var $form_answer;
	var $group_name;
	var $group_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;
    var $new_org_id;
		
	function Add_organization ( $vetted_value, $group_id )  	{
		GLOBAL $question_validation_error, $message, $message_type, $unique_seq, $organization_term;
		
		//$this->questions = $questions;
		//$this->form_answer = $form_answer;
		$this->group_id = $group_id;
		$this->user_access_level = "30";
		
        //echo "Adding: ".$vetted_value['login']."<p>";
        
		$sql = "SELECT * FROM organizations WHERE org_name LIKE '".$vetted_value["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 ( $vetted_value['login'], $vetted_value['password'] );
        
        if ( $pass->login_error )   {
            question_error_marking ( 'login', $pass->login_error );
        }
        
        if ( $pass->password_error )   {
            question_error_marking ( 'password', $pass->password_error );
        }

	    //If no errors, insert the new group (and group administrator) information
	    if (!$question_validation_error)	{
		    transaction_begin ( "Add org" );
            
            //Set-up organizations
		    $group_id_insert = $this->group_id;

		    $sql = "INSERT INTO organizations (org_name, group_id, org_type, org_system_type, web_page_address, org_address, org_city, org_state, org_zip, mailing_address, mailing_city, mailing_state, mailing_zip, org_description, org_user_id, account_status) VALUES ('".$vetted_value["org_name"]."', '".$group_id_insert."', 'org', 'client', '".$vetted_value["web_page_address"]."', '".$vetted_value["org_address"]."', '".$vetted_value["org_city"]."', '".$vetted_value["org_state"]."', '".$vetted_value["org_zip"]."', '".$vetted_value["mailing_address"]."', '".$vetted_value["mailing_city"]."', '".$vetted_value["mailing_state"]."', '".$vetted_value["mailing_zip"]."', '".$vetted_value["org_description"]."', '".$vetted_value["org_user_id"]."', 'active')";
		    run_query ($sql, "organizations creation");

		    $sql = "SELECT org_name FROM organizations WHERE org_name LIKE '".$vetted_value["org_name"]."'";
		    $last_insert = run_query ($sql, "gate insert id select");
		    $org_name_display = fetch_result ($last_insert, "gate user id");

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

		    $org_id_insert = fetch_result ($last_insert, "gate user id");
            $this->new_org_id = $org_id_insert;
            //echo 'THE NEW ORG ID IS '.$this->new_org_id.'<p/>';
            
		    $sql = "INSERT INTO gate (gate_login, gate_password, gate_status) VALUES ('".$vetted_value["login"]."',
             '".md5 ( $vetted_value["password"] )."', 'pending')";
		    run_query ($sql, "gate insertion");

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

		    //Add default permission group settings
            //echo "Org id insert is: ".$org_id_insert."<p/>";
            $perms = new Permissions ( $org_id_insert ); 
            $report_type_array[0]["report_type_id"] = 'ALL';

            //Setting the default to ALL users can NOT do anything.  Causes Organization to set permissions. 
            //Temporary allowance of permisive permissions for generating faux organizations for testing
            $rpt_perms['ALL']["create"] = 'yes';
            $rpt_perms['ALL']["read"] = 'yes';
            $rpt_perms['ALL']["edit"] = 'yes';
            
            //$new_perm_group_id = $perms->process_new_group_creation ( $org_id_insert, $_SESSION["user_id"], "DEFAULT SETTINGS" );
            $new_perm_group_id = $perms->process_new_group_creation ( $org_id_insert, $last_user_id_insert, "DEFAULT SETTINGS" );
            
            $perms->process_group_report_permission_changes ( $new_perm_group_id, $report_type_array, $rpt_perms );
            $user_per_ans[1] = 'yes'; 
            $perms->process_group_user_permission_changes ( $last_user_id_insert, $new_perm_group_id, $user_per_ans );
            
            update_org_services($org_id_insert ,$vetted_value['org_services']);

            transaction_commit ();
		    $message = $organization_term." ".$org_name_display." sucessfully added. ";
		    $message_type = "ok";

	    }
        else {
            //echo "ORGG ERROROROR<p>";
            //var_dump ( $question_validation_error );
        }
        
        
        //return $org_id_insert;
    }
}

	

			


?>
Return current item: Homeless Mangement Information System