<?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
session_start();
$page_id = "vacancies";
$page_access_levels = ":20:30:40:";
$page_title = "Vacancy Report";
include("initialize_pointer.php");
include($include_root."initialize.inc");
include($include_root."user_info_functions.inc");
include($include_root."Questions_into_array_class.inc");
include($include_root."questions_display.inc");
include($include_root."questions_into_tags_function.inc");
include($include_root."Questions_answers_validation_class.inc");
include($include_root."template_parser.inc");
include($include_root."head.inc");
include($include_root."page_elements_display.inc");
include($include_root."reports_class.inc");
//Give them the login form is they ask for it
if ($HTTP_GET_VARS["login"] == "yes" || $HTTP_POST_VARS["form_login"]) {
include_once($include_root."authenticate.inc");
}
//Log them out if asked
if ($HTTP_GET_VARS["logoff"] == "yes") {
include_once($include_root."authenticate.inc");
}
//echo "Access level: ".$_SESSION['access_levelB']."<p/>";
if ($HTTP_GET_VARS["groupid"]){
//echo "Not logged in";
include_once($include_root."authenticate_public.inc");
//include($include_root."db_connection.inc");
//$db_link = db_generic_connect ();
if (ereg("[0-9]", $HTTP_GET_VARS["groupid"])) {
$tag_values["{VACANCY_TABLE}"] = display_vacancy_table ($HTTP_GET_VARS["groupid"]);
$html_template = "vacancies_public.html";
}
}
//If they are logged-in, run them through authenticate function
elseif ($_SESSION['logged_inB'] == $db_name."yesindeed" && $_SESSION["access_levelB"] == "30" ) {
//echo "In logged_in mode".$group_id;
include_once($include_root."authenticate.inc");
// echo "Group id is: ".$group_id."<p/>";
// echo "Org id is: ".$org_id."<p/>";
display_vacancy_info_form ($group_id, $form_answer);
$tag_values["{VACANCY_TABLE}"] = display_vacancy_table ($group_id);
$tag_values["{VACANCY_FORM_HEADLINE}"] = "<table><tr><td class=\"headlinesub\">Edit entry for ".$org_name." by changing the values below</td></tr></table>";
$tag_values["{PAGE TITLE}"] = page_title_table();
$tag_values["{MENU}"] = menu();
$tag_values["{FOOTER}"] = footer();
$tag_values["{PUBLIC_LINK}"] = "<a href=\"".$this_page."?groupid=".$group_id."\" target = \"_blank\">Link to public version of vacancy table</a>";
$html_template = "vacancies_edit.html";
}
elseif ($_SESSION['logged_inB'] == $db_name."yesindeed" && ($_SESSION['access_levelB'] == "20" || $_SESSION['access_levelB'] == "40") ) {
include_once($include_root."authenticate.inc");
$tag_values["{VACANCY_TABLE}"] = display_vacancy_table ($group_id);
$tag_values["{PAGE TITLE}"] = page_title_table();
$tag_values["{MENU}"] = menu();
$tag_values["{FOOTER}"] = footer();
$tag_values["{PUBLIC_LINK}"] = "<a href=\"".$this_page."?groupid=".$group_id."\" target = \"_blank\">Link to public version of vacancy table</a>";
$html_template = "vacancies.html";
}
//If they are not logged-in, open a generic db connection
else {
echo "No ".$group_term." selected"; exit;
}
$tag_values["{HEAD}"] = head ($page_title, $head_page_specific, $head_dynamic_style);
template_parser ($html_template, $tag_values);
/////////////////
function display_vacancy_table ($groupid)
{
GLOBAL $organization_term, $unique_seq, $head_dynamic_style, $access_level, $system_directory, $org_id, $user_id, $head_dynamic_ecma;
$head_dynamic_style .= "
.vacancyhead {font-family: Arial, Helvetica, sans-serif; font-size: 12; font-weight: bolder; color: #990033; background-color: #FFCC99}
.vacancyorg {font-family: Arial, Helvetica, sans-serif; font-size: 12; color: #000000; background-color: #99CCFF}
.vacancy {font-family: Arial, Helvetica, sans-serif; font-size: 12; color: #000000; background-color: #FFFFCC}
.vacancydate {font-family: Arial, Helvetica, sans-serif; font-size: 12; color: #000000; background-color: #CCCCFF}
";
$pull_questions = new Questions_into_array ("vacancies", "20", "9999", $groupid, "display");
//display_value($pull_questions->questions);
$group_array = pull_group_information ($groupid);
$orgs_array = pull_organizations_info_associated_with_group ($groupid);
////////////////////////////////////".'".$system_directory."report.php?' + getstring;
//Assemble table title
$head_dynamic_ecma['0'] = "
function go_to_report ( getstring ) {
var link_strrr;
link_strrr = '".$system_directory."report.php?' + getstring;
document.getElementById('referral').action = link_strrr;
document.getElementById('referral').submit();
}
";
$final_html .= "<form id=\"referral\" method=\"POST\">";
$final_html .= "<table><tr><td class=\"generictabletop\">Vacancy Report: ".$group_array[3]." County</td></tr></table>";
$final_html .= "<table>";
//Assemble colunm headers
$final_html .= "<tr>";
$final_html .= "<td class=\"vacancyhead\">Service Provider</td>";
foreach ($pull_questions->questions AS $current_question) {
$final_html .= "<td class=\"vacancyhead\">".$current_question["question_title"]."</td>";
}
$final_html .= "<td class=\"vacancyhead\">Date Updated</td>";
if ( $access_level == "40" ) {
$final_html .= "<td class=\"vacancyhead\">Refer household by selecting referral type below</td>";
}
$final_html .= "</tr>";
//Loop through the orgs
//if (is_array($orgs_array) ) {
foreach ($orgs_array AS $current_org) {
//Pull the answers for all the vacancy questions answered by this organization
//echo "The org id we are pulling answers for is: ".$current_org[$unique_seq."org_id"]."<p/>";
$this_orgs_answers = pull_vacancy_answers ($current_org["org_id"], $pull_questions->questions,
$pull_questions->question_elements);
$final_html .= "<tr>";
if($current_org["web_page_address"]) {
$final_html .= "<td class=\"vacancyorg\"><a href=\"http://".$current_org["web_page_address"].
"\" target=\"_blank\">".$current_org["org_name"]."</a></td>";
}
else {
$final_html .= "<td class=\"vacancyorg\">".$current_org["org_name"]."</td>";
}
//Loop through the questions and assemble the row
foreach ($pull_questions->questions AS $current_question) {
$final_html .= "<td class=\"vacancy\">";
//$final_html .= $current_question["question_title"];
$final_html .= display_vacancy_answers ($current_question,
$pull_questions->question_elements[$current_question["question_id"]],
$this_orgs_answers[$current_question["question_id"]]);
//$final_html .= display_vacancy_answers ($question_attributes[$current_question["question_id"]],
// $this_orgs_answers[$current_question["question_id"]]);
$final_html .= "</td>";
}
$final_html .= "<td class=\"vacancydate\">".safe_date("D, M d", $this_orgs_answers["date_updated"])."</td>";
//Updated to say "Place" for the users Organization.
if ( $access_level == '40' && $current_org["org_id"] == $org_id ) {
//$final_html .= "<td><a class=\"tiny\" href=\"".$system_directory."clients.php?ref_to_org_id=".$current_org["org_id"]."&report_name=referral_basic&empty_form=yes\">Place household within your ".$organization_term."</a></td>";
$final_html .= '<td> </td>';
}
elseif ( $access_level == '40' ) {
//$final_html .= "<td><a class=\"tiny\" href=\"".$system_directory."clients.php?ref_to_org_id=".$current_org["org_id"]."&report_name=referral_basic&empty_form=yes\">Refer household to this ".$organization_term."</a></td>";
$final_html .= '<td>';
$final_html .= build_referral_dropdown_html ( $user_id, $org_id, $current_org['org_id'] );
$final_html .= '</td>';
}
$final_html .= "</tr>";
}
//}
$final_html .= "</table>";
$final_html .= "</form>";
return $final_html;
}
function build_referral_dropdown_html ( $user_id, $user_org_id, $outside_org_id ) {
$array_of_reports = pull_other_organization_report_permissions ( $user_id, $user_org_id, $outside_org_id );
$final_html .= "<select class=\"tinytd\" name=\"form_answer[rpt]\" ";
$final_html .= "OnChange=\"go_to_report(value)\">";
$final_html .= "<option value=\"\"></option>";
if ( isset($array_of_reports) )
{
foreach ( $array_of_reports AS $cur_rpt_type )
{
if ( $cur_rpt_type['create_rpt'] == 1 ) {
$rpt_type_profile = pull_report_type_profile ( $cur_rpt_type['report_type_id'] );
//$link_string[$i] = "<a class=\"tiny\" href=\"".$system_directory.'report.php?report_type_id='.$rpt_type_profile['report_type_id'].'&referred_to_org_id='.$outside_org_id."\"";
$link_string =
'report_type_id['.$rpt_type_profile['report_type_id'].']='.$rpt_type_profile['report_type_id'].'&form_status=not_submitted&referred_to_org='.$outside_org_id;
$final_html .= "<option value=\"".$link_string."\"";
$final_html .= " >".$rpt_type_profile['report_title'].'</option>';
}
}
}
$final_html .= '</select>';
return $final_html;
}
function pull_vacancy_answers ($org_id, $questions, $question_elements) {
$sql = "SELECT * FROM vacancy_report_profile WHERE org_id = '".$org_id."'";
//echo $sql." -The pulling of answers<p/>";
$vacancy_profile = run_query_return_single_row ($sql, "Pulling existing vancy report profile");
$return_answer["date_updated"] = $vacancy_profile["vacancy_report_date"];
if ( $vacancy_profile["vacancy_report_id"] ) {
$sqlb = "SELECT * FROM vacancy_answers WHERE vacancy_report_id = '".$vacancy_profile["vacancy_report_id"]."'";
$vacancy_answers = run_query_return_array ($sqlb, "Pulling vacancy answers");
//display_value($vacancy_answers);
}
if (count($vacancy_answers) > 0) {
//echo "the count is greater than 1<p/>";
foreach ($vacancy_answers AS $current_answer) {
//If it is a checkbox question...
//echo "The question type is: ".$questions[$current_answer["question_id"]]["question_type"]."<p/>";
$quest_type = $questions[$current_answer["question_id"]]["question_type"];
if ($quest_type == "checkboxes") {
//...loop through the elements to find a matching value, and assign "yes" if it exists
foreach ($question_elements[$current_answer["question_id"]] AS $current_element) {
if ($current_element["question_element_value"] == $current_answer["answer"]) {
//$return_answer[$current_answer["question_id"]][$current_element["element_id"]] = "yes";
$return_answer[$current_answer["question_id"]][$current_element["question_element_id"]] =
$current_answer["answer"];
//echo $current_element["question_element_id"].$current_answer["answer"]."<p/>";
//break 1;
}
}
}
elseif ($quest_type == "number") {
$return_answer[$current_answer["question_id"]] = $current_answer["answer_int"];
//echo "Question_answer is: ".$return_answer[$current_answer["question_id"]]."<p/>";
}
else {
//echo "In the else<p/>";
$return_answer[$current_answer["question_id"]] = $current_answer["answer"];
//echo "Returning an answer: ".$current_answer["answer"]."<p>";
}
}
}
return $return_answer;
}
function display_vacancy_answers ($question_attributes, $question_elements, $answers) {
if (strlen($answers) > 0) {
if($question_attributes["question_type"] == "checkboxes") {
$e = 0;
foreach ($answers AS $current_answer) {
if ($e > 0) { $return_for_display .= ", ";}
foreach ($question_elements AS $key => $current_element) {
if ($current_element["question_element_value"] == $current_answer) {
$return_for_display .= $current_element["question_element_title"];
$e++;
}
}
}
}
elseif ($question_attributes["question_type"] == "radio" || $question_attributes["question_type"] == "dropdown") {
foreach ($question_elements AS $key => $current_element) {
// echo "Current element: ".$current_element["question_element_value"]." -- Current Answer: ".
if ($current_element["question_element_value"] == $answers) {
$return_for_display .= $current_element["question_element_title"];
}
}
}
else {
//$return_for_display = $question_attributes["question_title"]."jjj";
$return_for_display = $answers;
}
}
else {
$return_for_display = "00";
}
return $return_for_display;
}
function display_vacancy_info_form ($group_id, $form_answers) {
GLOBAL $tag_values, $question_validation_error, $form_submitted, $org_id;
$pull_questions = new Questions_into_array ("vacancies", "20", "9999", $group_id, "display");
if(!$form_submitted) {
$display_form_answers = pull_vacancy_answers ($org_id, $pull_questions->questions, $pull_questions->question_elements);
}
else {
$validation = new Questions_answers_validation($pull_questions->questions,
$pull_questions->question_elements, $form_answers);
$display_form_answers = $validation->vetted_form_answer;
}
//$validation = new Questions_answers_validation($pull_questions->questions,
// $pull_questions->question_elements, $display_form_answers);
questions_into_tags ($pull_questions->questions, $pull_questions->question_elements, $display_form_answers);
if (!$question_validation_error && $form_submitted) {
insert_vacancy_info ($org_id, $pull_questions->questions, $pull_questions->question_elements, $validation->vetted_value);
}
$tag_values["{FORM_START}"] = form_start();
//$final_html .= $tag_values["{REMAINING_TAGS}"];
$tag_values["{FORM_END}"] = form_end("Click Here to Submit Changes");
//return $final_html;
}
function insert_vacancy_info ($org_id, $questions, $question_elements, $vetted_values) {
GLOBAL $unix_date, $user_id;
//Pull out the existing vacancy_report_profile...
$sqlc = "SELECT * FROM vacancy_report_profile WHERE org_id = '".$org_id."'";
$existing_profile = run_query_return_single_row ($sqlc,"Pulling out existing report profile");
if ( $existing_profile ) {
//...and put in the data in the previous versions table
$sqld = "INSERT INTO vacancy_report_profile_previous
(vacancy_report_id,
org_id,
vacancy_report_date,
report_updated_by_user)
VALUES
('".$existing_profile["vacancy_report_id"]."',
'".$existing_profile["org_id"]."',
'".$existing_profile["vacancy_report_date"]."',
'".$existing_profile["report_updated_by_user"]."')";
run_query($sqld, "Inserting existing vacancy report profile data in previous versions tables");
//Pull out the existing vacancy_report_answers...
$sqlc = "SELECT * FROM vacancy_answers WHERE vacancy_report_id = '".$existing_profile["vacancy_report_id"]."'";
$existing_answers = run_query_return_array ($sqlc, "Pull out existing vacancy answers", "question_id");
//...and put in the data in the previous versions table
if($existing_answers) {
foreach($existing_answers AS $quest_id => $current_answer) {
$sqle = "INSERT INTO vacancy_answers_previous
(vacancy_report_id,
question_id,
answer,
answer_int)
VALUES
('".$current_answer["vacancy_report_id"]."',
'".$quest_id."',
'".$current_answer["answer"]."',
'".$current_answer["answer_int"]."')";
run_query($sqle, "Inserting existing vacancy report answer data in previous versions tables");
}
}
//Pull out the largest vacancy_report_id...
$sqlj = "SELECT vacancy_report_id FROM vacancy_report_profile ORDER BY vacancy_report_id DESC";
$resultj = run_query ($sqlj, "Finding largest vacancy report id");
if (num_rows ($resultj) > 0) {
$largest_id = fetch_result( $resultj, "Finding largest element id." );
}
$new_id = $largest_id + 1;
//Delete existing vacancy report profile
$sql = "DELETE FROM vacancy_report_profile WHERE org_id = '".$org_id."'";
run_query ($sql, "Deleting existing vacancy info");
//Delete existing answers
$sql = "DELETE FROM vacancy_answers WHERE vacancy_report_id = '".$existing_profile["vacancy_report_id"]."'";
run_query ($sql, "Deleting existing vacancy info");
}
else {
$new_id = 1;
}
//Insert new vacancy report profile
$sqlk = "INSERT INTO vacancy_report_profile
(vacancy_report_id,
org_id,
vacancy_report_date,
report_updated_by_user)
VALUES
('".$new_id."',
'".$org_id."',
'".$unix_date."',
'".$user_id."')";
run_query($sqlk, "Inserting new vacancy report profile data");
//Insert the new answers
foreach ($questions AS $current_question) {
if($current_question["question_type"] == "checkboxes") {
//echo "a checkbox<p/>";
//Loop through the vetted checkbox answers and insert them
foreach ($vetted_values[$current_question["question_id"]] AS $current_value) {
$sqlf = "INSERT INTO vacancy_answers
(vacancy_report_id,
question_id,
answer)
VALUES
('".$new_id."',
'".$current_question["question_id"]."',
'".$current_value."')";
//echo $sqlf;
run_query($sqlf, "Inserting new vacancy report answers data");
}
}
elseif ($current_question["question_type"] == "number") {
$sqle = "INSERT INTO vacancy_answers
(vacancy_report_id,
question_id,
answer_int)
VALUES
('".$new_id."',
'".$current_question["question_id"]."',
'".$vetted_values[$current_question["question_id"]]."')";
run_query($sqle, "Inserting new vacancy report answers data");
}
else {
$sqle = "INSERT INTO vacancy_answers
(vacancy_report_id,
question_id,
answer)
VALUES
('".$new_id."',
'".$current_question["question_id"]."',
'".$vetted_values[$current_question["question_id"]]."')";
run_query($sqle, "Inserting new vacancy report answers data");
}
}
}
//Function used to debug variables
/*
function display_value ($variable, $variable_name="") {
if($variable_name) {echo "Variable: ".$variable_name."<br/>";}
if ( is_array ($variable) ) {
foreach ($variable AS $key => $value) {
echo "Key0: ".$key." Value0: ".$value."<br/>";
if (is_array ($value) ) {
foreach ($value AS $key2 => $value2) {
echo " Key1: ".$key2."; Value1: ".$value2."<br/>";
if (is_array ($value2) ) {
foreach ($value2 AS $key3 => $value3) {
echo " Key2: ".$key3."; Value2: ".$value3."<br/>";
}
}
}
}
}
}
}
*/
?>