<?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
$page_access_levels = ":10:";
//$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."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."permissions_class.inc");
include($include_root."add_organization_class.inc");
include($include_root."add_users_class.inc");
include($include_root."passwords_class.inc");
include($include_root."services_functions.inc");
//Pull out array of existing groups
$sql = "SELECT user_id, org_id FROM user_info WHERE user_access_level = '20'";
$result = run_query ( $sql, 'Pulling end users' );
$group_users_count = num_rows ( $result ) - 1;
for ($r = 0; $r < $group_users_count + 1; $r++ ) {
$group_user_raw = fetch_array ( $result, 'Group user info', $r );
$group_users[$r]["org_id"] = $group_user_raw["org_id"];
$group_users[$r]["user_id"] = $group_user_raw["user_id"];
$sqlb = "SELECT group_id FROM organizations WHERE org_id = '".$group_user_raw["org_id"]."'";
$res = run_query ( $sqlb, 'get group id' );
$group_users[$r]["group_id"] = fetch_result ( $res, 'group user group id' );
}
//Find the number of the last inserted organization
$sql = "SELECT * FROM organizations ORDER BY org_id DESC";
$res = run_query ( $sql, 'Puling highest org num' );
$highest_raw = fetch_array ( $res, 'Pulling highest', 0 );
$highest_org_num = $highest_raw['org_id'];
$start_org_num = $highest_org_num + 1;
//|||||||||||||How many new organizations added is defined below |||||||||||||??????????????|||||||||||||||??????????????||||||||||||||?????
$end_org_num = $start_org_num + 30;
//Loop through the number of new organizations we want to create
for ( $i = $start_org_num; $i < $end_org_num; $i++ ) {
//Generate a random user/group
$group_index = rand ( 0, $group_users_count );
$org_id = $group_users[$group_index]["org_id"];
$user_id = $group_users[$group_index]["user_id"];
$group_id = $group_users[$group_index]["group_id"];
//Create new shelter organization
$org_form_vals = generate_org_form_values ( $i );
$new_org = new Add_organization ($org_form_vals, $group_id);
//$new_org->new_org_id = $new_org;
echo "<p>AAAAdded ".$organization_term.": ".$new_org->new_org_id.'<p/>';
//Create an end users associated with the above organization
for ( $z = 1; $z < 3; $z++ ) {
insert_faux_user ( $new_org->new_org_id, $new_org->new_org_id.$z );
echo " -Added user: ".$new_org->new_org_id.$z.'<p/>';
}
}
//Create simulated form info
/*
//Pull out array of end users
$sql = "SELECT user_id, org_id FROM user_info WHERE user_access_level = '40'";
$result = run_query ( $sql, 'Pulling end users' );
$end_users_count = num_rows ( $result ) - 1;
for ($r = 0; $r < $end_users_count + 1; $r++ ) {
$end_user_raw = fetch_array ( $result, 'End user info', $r );
$end_users[$r]["org_id"] = $end_user_raw["org_id"];
$end_users[$r]["user_id"] = $end_user_raw["user_id"];
$sqlb = "SELECT group_id FROM organizations WHERE org_id = '".$end_user_raw["org_id"]."'";
$res = run_query ( $sqlb, 'get group id' );
$end_users[$r]["group_id"] = fetch_result ( $res, 'End user group id' );
}
//Pull out the client questions once
$client_profile_questions = new Questions_into_array ('client_profile', 40, $end_users[1]["org_id"], $end_users[1]["group_id"], 'display');
//Pull out the hh questions once
$hh_rpt_questions = new Questions_into_array ('household_intake', 40, $end_users[1]["org_id"], $end_users[1]["group_id"], 'display');
$client_info = "";
//Loop through the number of simulated households we want to create
for ( $i = 0; $i < 300000; $i++ ) {
//Move backwards through time so not all records have same date, one hour back per set of clients
echo $i." ";
$unix_date = $unix_date - 36000;
if ( $unix_date < 1 ) {
$unix_date = time();
}
//Generate a random user/org
$user_index = rand ( 0, $end_users_count );
$org_id = $end_users[$user_index]["org_id"];
$user_id = $end_users[$user_index]["user_id"];
$group_id = $end_users[$user_index]["group_id"];
//echo $org_id." - ".$user_id." - ".$group_id.'<p/>';
//Generate random number of clients
$client_count = rand ( 1, 4 );
for ( $c = 0; $c < $client_count; $c++ ) {
$client_info[$c] = create_answers_client_identifier_report ($c);
}
//$client_info["0"]['client_relationship_to_lead'] = 'head';
//Insert the answers
$insert_new_clients = new Client_id;
$insert_new_clients->client_id_assign($org_id);
$insert_profile = new Client_profile;
$insert_profile->insert_client_profile_answers ('client_profile', $client_info, $client_profile_questions->questions);
//$hh_rpt_questions = new Questions_into_array ('household_intake', 40, $org_id, $group_id, 'display');
$report_dates['begin'] = $unix_date - 21600;
$report_dates['end'] = $unix_date;
$vetted_value = create_answers_hh_report ();
//var_dump ( $client_info );
$hh_rpt = new Insert_household_report;
$hh_rpt->insert_report_answers ('household_intake', $client_info, $hh_rpt_questions->questions, $vetted_value, $org_id,
'yes', '', $report_dates);
$client_info = "";
}
function create_answers_client_identifier_report ($clnt_num) {
GLOBAL $org_id, $group_id, $client_profile_questions;
//$client_profile_questions = new Questions_into_array ('client_profile', 40, $org_id, $group_id, 'display');
foreach ( $client_profile_questions->questions AS $cur_question ) {
switch ( $cur_question['question_type'] ) {
case 'radio':
$ind_client_info[$cur_question['question_id']] = pull_random_radio_answer ( $cur_question, $client_profile_questions->question_elements[$cur_question['question_id']] );
break;
case 'checkboxes':
$ind_client_info[$cur_question['question_id']] = pull_random_checkboxes_answer ( $cur_question, $client_profile_questions->question_elements[$cur_question['question_id']] );
break;
case 'number':
$ind_client_info[$cur_question['question_id']] = pull_random_number_answer ( $cur_question, $client_profile_questions->question_elements[$cur_question['question_id']] );
break;
default:
}
}
if ( $clnt_num == 0 ) {
$ind_client_info['client_relationship_to_lead'] = 'head';
}
else {
$ind_client_info['client_relationship_to_lead'] = 'spouse';
}
$ind_client_info['client_identifier'] = create_client_identifier ();
$ind_client_info['org_generated_client_id_insert'] = create_org_generated_id();
$ind_client_info['client_rpt_sharing_permission'] = 'yes';
$ind_client_info['100'] = rand (1920, 2003);
return $ind_client_info;
}
function create_answers_hh_report () {
GLOBAL $org_id, $group_id;
$client_profile_questions = new Questions_into_array ('household_intake', 40, $org_id, $group_id, 'display');
foreach ( $client_profile_questions->questions AS $cur_question ) {
switch ( $cur_question['question_type'] ) {
case 'radio':
$ind_client_info[$cur_question['question_id']] = pull_random_radio_answer ( $cur_question, $client_profile_questions->question_elements[$cur_question['question_id']] );
break;
case 'checkboxes':
$ind_client_info[$cur_question['question_id']] = pull_random_checkboxes_answer ( $cur_question, $client_profile_questions->question_elements[$cur_question['question_id']] );
break;
case 'number':
$ind_client_info[$cur_question['question_id']] = pull_random_number_answer ( $cur_question, $client_profile_questions->question_elements[$cur_question['question_id']] );
break;
default:
}
}
$ind_client_info['client_rpt_sharing_permission'] = 'yes';
return $ind_client_info;
}
function create_client_identifier () {
$f = chr( rand (97, 122) );
$m = chr( rand (97, 122) );
$l = chr( rand (97, 122) );
$month = rand (1, 12);
$day = rand (1, 28);
$year = rand (1925, 2003);
$gender = rand (1, 2);
if ( $gender == 1 ) {
$gender = 'male';
}
else {
$gender = 'female';
}
$fin = $f.$m.$l.$month.$day.$year.$gender;
return $fin;
}
function pull_random_radio_answer ( $cur_question, $elements ) {
//var_dump ( $cur_question );
//echo '<p/>yoohoo<p/>';
//var_dump ( $elements );
//echo '<p/>______________________________________________<p/>';
$picked = rand ( 0, count ( $elements ) - 1 );
//echo "Picked".$picked."<p/>";
$w = 0;
foreach ( $elements AS $cur_element ) {
//echo "Cre ele value: ".$cur_element['question_element_value']."<br>";
$ele_val = $cur_element['question_element_value'];
if ( $w == $picked ) {
break 1;
}
$w++;
}
//echo "The chosens value is: ".$ele_val."<p/>";
return $ele_val;
}
function pull_random_checkboxes_answer ( $cur_question, $elements ) {
//var_dump ( $cur_question );
//echo '<p/>yoohoo<p/>';
//var_dump ( $elements );
//echo '<p/>______________________________________________<p/>';
$number_of_picked_answers = rand ( 1, ((count ( $elements ) - 1) /2) );
//echo "Number of answers picked: ".$number_of_picked_answers.'<p/>';
for ( $we = 0; $we < $number_of_picked_answers; $we++ ) {
$picked = rand ( 0, count ( $elements ) - 1 );
//echo "Picked".$picked."<p/>";
$w = 0;
foreach ( $elements AS $cur_element ) {
//echo "Cre ele value: ".$cur_element['question_element_value']."<br>";
$ele_val = $cur_element['question_element_value'];
if ( $w == $picked ) {
break 1;
}
$w++;
}
//echo "The chosens value is: ".$ele_val."<p/>";
$ret_val[$picked] = $ele_val;
}
return $ret_val;
}
function pull_random_number_answer ( $cur_question, $elements ) {
//var_dump ( $cur_question );
//echo '<p/>yoohoo<p/>';
//var_dump ( $elements );
$num = rand ( $cur_question['question_range_bottom'], $cur_question['question_range_top'] );
return $ret_val;
}
function create_org_generated_id () {
$first_name_length = rand ( 3, 8 );
$last_name_length = rand ( 3, 8 );
for ( $i = 0; $i < $first_name_length; $i++ ) {
$f .= chr( rand (97, 122) );
}
for ( $i = 0; $i < $first_name_length; $i++ ) {
$l .= chr( rand (97, 122) );
}
return $f." ".$l;
}
*/
/////////////////////////////////////
function generate_org_form_values ( $org_sequence_number ) {
$ret_val['org_name'] = 'Faux Shelter Org'.$org_sequence_number;
$ret_val['first_name'] = 'John';
$ret_val['last_name'] = 'Doe'.$org_sequence_number;
$ret_val['phone_number'] = '(360) 555-55'.$org_sequence_number;
$ret_val['email_address'] = 'hide@address.com'.$org_sequence_number.'.org';
$ret_val['web_page_address'] = 'www.shelter'.$org_sequence_number.'.org';
$ret_val['login'] = 'testlogin'.$org_sequence_number;
$ret_val['password'] = 'as$8ooUt'.$org_sequence_number;
$ret_val['org_address'] = '123 Nowhere Street';
$ret_val['mailing_address'] = '123 Nowhere Street';
$ret_val['org_city'] = 'Hmisville';
$ret_val['mailing_city'] = 'Hmisville';
$ret_val['org_state'] = 'WA';
$ret_val['mailing_state'] = 'WA';
$ret_val['org_zip'] = '56734';
$ret_val['mailing_zip'] = '56734';
$ret_val['org_description'] = 'Blah blah';
$ret_val['org_services'][78] = '78';
return $ret_val;
}
function insert_faux_user ( $org_id, $append_val ) {
transaction_begin ( "Add user" );
//$group_id_insert = $this->group_id;
$org_id_insert = $org_id;
$insert_new_login = 'testuser'.$append_val;
$insert_new_password = 'testuserpass'.$append_val;
$insert_first_name = 'Jules';
$insert_last_name = 'Smith'.$append_val;
$insert_phone = '(360) 565-5434';
$insert_email = 'hide@address.com'.$append_val.'.org';
$sql = "INSERT INTO gate (gate_login, gate_password, gate_status) VALUES ('".$insert_new_login."', '".$insert_new_password."', 'active')";
run_query ($sql, "gate insertion");
$sql = "SELECT user_id FROM gate WHERE gate_login LIKE '".$insert_new_login."' AND gate_password LIKE '".$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."', '40', '".$org_id_insert."', '".$insert_first_name."', '".$insert_last_name."', '".$insert_phone."', '".$insert_email."')";
run_query ($sql, "user_info creation");
transaction_commit();
}
?>