Location: PHPKode > projects > Homeless Mangement Information System > hmis/system_critique.php
<?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

$page_title = "System Critique";
$page_access_levels = ":10:20:30:40:";
//$page_id = "index";
//$page_profile = "Homepage";
$instructions .= "System critiques are listed below. ";

////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."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_entry_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."query_report_class.inc");
include($include_root."user_info_functions.inc");


convert_post_and_get_variable ("critique_page_url");


switch($form_submitted)	{
	
	case "default_critique":
		process_critique_new_submission ($form_answer);
		break;

	case "selected_report":
		display_selected_report ($selected_report);
		break;

	case "display_report":
		//echo "Selected report is: ".$selected_report."<br>";
		process_critique_added_comment ($selected_report, $form_answer);
		
		break;

	default:
		display_default_critique_page ($critique_page_url, "yes");
		

}

 
//Define the values for tags contained in the html template

$tag_values["{FORM_START}"] = form_start ();
$tag_values["{FORM_END}"] .= form_end ("Submit Report", 1);
$tag_values["{PAGE TITLE}"] = page_title_table();
$tag_values["{MENU}"] = menu();
$tag_values["{HEAD}"] = head ($page_title, $head_page_specific, $head_dynamic_style);
$tag_values["{FOOTER}"] = footer();


template_parser ($html_template, $tag_values);

////////////////////////////////////
//Functions

function display_default_critique_page ($critique_page_url, $fresh="")	{

	GLOBAL $tag_values, $page_id, $html_template, $validation_critique_new_questions, $validation_critique_entry_questions;

	$page_id = "default_critique";
	$html_template = "system_critique.html";

	//Pull new critique questions
	$critique_new_questions = new Critique;
	$critique_new_questions->critique_new_questions ($critique_page_url);

	//Pull new critique questions
	$critique_entry_questions = new Critique;
	$critique_entry_questions->critique_entry_questions ();
	
	if($fresh == "yes")	{
		
		$validation_critique_new_questions->vetted_form_answer = "";
		$validation_critique_entry_questions->vetted_form_answer = "";
		
						}

	//New critique questions into tags
	questions_into_tags ($critique_new_questions->questions, $critique_new_questions->question_elements, $validation_critique_new_questions->vetted_form_answer);

	//New critique entry questions into tags
	questions_into_tags ($critique_entry_questions->questions, $critique_entry_questions->question_elements, $validation_critique_entry_questions->vetted_form_answer);

	$tag_values["{MATCHING_OPEN_ENTRIES_TABLE}"] = display_table_of_entries("matching", $critique_page_url);
	$tag_values["{OPEN_ENTRIES_TABLE}"] = display_table_of_entries("open");
	$tag_values["{RECENT_CLOSED_ENTRIES_TABLE}"] = display_table_of_entries("recent_closed");
	$tag_values["{FORM_END}"] .= display_hidden_form_values ("critique_page_url", $critique_page_url);

													}

function process_critique_new_submission ($form_answer)	{
	GLOBAL $question_validation_error, $validation_critique_new_questions, $critique_page_url, $validation_critique_entry_questions, $message, $message_type;

	//Pull new critique questions
	$critique_new_questions = new Critique;
	$critique_new_questions->critique_new_questions ($critique_page_url);

	//Pull new critique questions
	$critique_entry_questions = new Critique;
	$critique_entry_questions->critique_entry_questions ();

	//Validate new critique questions
	$validation_critique_new_questions = new Questions_answers_validation($critique_new_questions->questions, $critique_new_questions->question_elements, $form_answer);

	//Validate new critique entry questions
	$validation_critique_entry_questions = new Questions_answers_validation($critique_entry_questions->questions, $critique_entry_questions->question_elements, $form_answer);

	if(!$question_validation_error)	{
		
		$inserted_critique_id = $critique_new_questions->insert_critique_new_questions ($validation_critique_new_questions->vetted_value);

		$critique_entry_questions->insert_critique_entry ($inserted_critique_id, $validation_critique_entry_questions->vetted_value);

		$message .= "New report successfully entered. ";
		$message_type = "ok";
		display_default_critique_page ($critique_page_url, "yes");

									}
	else	{
		display_default_critique_page ($critique_page_url, "no");

			}


														}





class Critique	{
var $questions;
var $question_elements;
var $critique_id;

	function insert_critique_new_questions ($vetted_values)	{
		GLOBAL $user_name, $unique_seq;

		$sql = "INSERT INTO critiques (critique_title, critique_type, critique_status, critique_page_url, critique_author) VALUES ('".$vetted_values["critique_title"]."', '".$vetted_values["critique_type"]."', 'open', '".$vetted_values["critique_page_url"]."', '".$user_name."')";
		run_query($sql, "Insert new critiqueA");

		$sql = "SELECT critique_rowid FROM critiques WHERE critique_title LIKE '".$vetted_values["critique_title"]."' AND critique_type LIKE '".$vetted_values["critique_type"]."' AND critique_status LIKE 'open' ORDER BY  critique_rowid DESC";
		
		$result = run_query($sql, "Insert new critiqueB");

		$this->critique_id = fetch_result($result, "New critique rowid");


		$sql = "UPDATE critiques SET critique_id='".$this->critique_id."' WHERE critique_rowid = '".$this->critique_id."' ";
		run_query($sql, "Insert new critique id C");

		return $this->critique_id;

															}

	function insert_critique_entry ($critique_id, $vetted_value)	{
		GLOBAL $unix_date, $user_id, $access_level;

		$sql = "INSERT INTO critique_entries (critique_id, critique_user_id, critique_priority, critique_comment, critique_date) VALUES ('".$critique_id."', '".$user_id."', '".$vetted_value["critique_priority"]."', '".$vetted_value["critique_comment"]."', '".$unix_date."')";
		run_query($sql, "Insert new critique entry B");


		$sql = "SELECT SUM(critique_priority) FROM critique_entries WHERE critique_id = '".$critique_id."'";
		$result = run_query($sql, "Sum critique entries priorities A");
		$score = fetch_result($result, "Sum critique entries priorities B");
		$sql = "UPDATE critiques SET critique_score='".$score."', critique_last_comment_date='".$unix_date."' WHERE critique_id = '".$critique_id."' ";
		run_query($sql, "Insert new critique score");

		if($access_level == "10")	{
			$sql = "UPDATE critiques SET critique_status='".$vetted_value["critique_status"]."' WHERE critique_id = '".$critique_id."' ";
			run_query($sql, "Insert new critique status");
									}
		

																	}

		





	function critique_new_questions ($critique_page_url)	{
		GLOBAL $unix_date;
		$critique_page_url = htmlspecialchars($critique_page_url);
		$critique_page_url = addslashes($critique_page_url);
						

		$this->questions["critique_title"] = array ("question_id" => "critique_title", "question_title" => "One Sentence Description:", "question_type" => "text", "question_owner_group_id" => "1", "question_owner_org_id" => "1", "question_field_size" => "100", "question_range_bottom" => "0", "question_range_top" => "0", "question_display_order" => "1019", "question_required" => "yes", "report_type_id" => "critique_new", "question_default_value" => "", "question_visible" => "yes", "question_ecma" => "", "question_display_size" => "65");

		$this->questions["critique_page_url"] = array ("question_id" => "critique_page_url", "question_title" => "Report Concerning Page Address:", "question_type" => "text", "question_owner_group_id" => "1", "question_owner_org_id" => "1", "question_field_size" => "200", "question_range_bottom" => "0", "question_range_top" => "0", "question_display_order" => "1019", "question_required" => "no", "report_type_id" => "critique_new", "question_default_value" => $critique_page_url, "question_visible" => "yes", "question_ecma" => "", "question_display_size" => "55");

		$this->questions["critique_type"] = array ("question_id" => "critique_type", "question_title" => "Report Type:", "question_type" => "radio", "question_field_size" => "0", "question_range_bottom" => "0", "question_range_top" => "0", "question_display_order" => "1019", "question_required" => "yes", "question_default_value" => "bug", "question_visible" => "yes", "question_ecma" => "");

			$this->question_elements["critique_type"]["bug"] = array ("question_element_id" => "critique_type_bug", "question_id" => "critique_type", "question_element_title" => "Bug", "question_element_value" => "bug");

			$this->question_elements["critique_type"]["feature"] = array ("question_element_id" => "critique_type_feature", "question_id" => "critique_type", "question_element_title" => "Feature", "question_element_value" => "feature");

										}

		
	function critique_entry_questions ()	{
		GLOBAL $unix_date, $access_level;
						
		$this->questions["critique_comment"] = array ("question_id" => "critique_comment", "question_title" => "Comment:", "question_type" => "textarea", "question_owner_group_id" => "1", "question_owner_org_id" => "1", "question_field_size" => "15", "question_range_bottom" => "0", "question_range_top" => "0", "question_display_order" => "1019", "question_required" => "no", "report_type_id" => "critique_new", "question_default_value" => "", "question_visible" => "yes", "question_ecma" => "", "question_display_size" => "65");

		$this->questions["critique_priority"] = array ("question_id" => "critique_priority", "question_title" => "Report Priority:", "question_type" => "radio", "question_field_size" => "0", "question_range_bottom" => "0", "question_range_top" => "0", "question_display_order" => "1019", "question_required" => "yes", "question_default_value" => "2", "question_visible" => "yes", "question_ecma" => "");

			$this->question_elements["critique_priority"]["4"] = array ("question_element_id" => "critique_priority_very_high", "question_id" => "critique_priority", "question_element_title" => "Very High: I cannot use the system if this is not addressed.", "question_element_value" => "4");

			$this->question_elements["critique_priority"]["3"] = array ("question_element_id" => "critique_priority_high", "question_id" => "critique_priority", "question_element_title" => "High: The system is hard to use if this is not addressed.", "question_element_value" => "3");

			$this->question_elements["critique_priority"]["2"] = array ("question_element_id" => "critique_priority_medium", "question_id" => "critique_priority", "question_element_title" => "Medium: I want this addressed, but I can work around it.", "question_element_value" => "2");

			$this->question_elements["critique_priority"]["1"] = array ("question_element_id" => "critique_priority_low", "question_id" => "critique_priority", "question_element_title" => "Low: It would be nice if this was addressed.", "question_element_value" => "1");

		if($access_level == "10")	{
			$this->questions["critique_status"] = array ("question_id" => "critique_status", "question_title" => "Report Status:", "question_type" => "radio", "question_field_size" => "0", "question_range_bottom" => "0", "question_range_top" => "0", "question_display_order" => "1019", "question_required" => "yes", "question_default_value" => "open", "question_visible" => "yes", "question_ecma" => "");

				$this->question_elements["critique_status"]["open"] = array ("question_element_id" => "critique_status_open", "question_id" => "critique_status", "question_element_title" => "Open", "question_element_value" => "open");

				$this->question_elements["critique_status"]["analyzed"] = array ("question_element_id" => "critique_status_analyzed", "question_id" => "critique_status", "question_element_title" => "Analyzed", "question_element_value" => "analyzed");

				$this->question_elements["critique_status"]["closed"] = array ("question_element_id" => "critique_status_closed", "question_id" => "critique_status", "question_element_title" => "Closed", "question_element_value" => "closed");



									}
			
											}

				}		

function display_table_of_entries ($table_type, $critique_page_url="")	{
	GLOBAL $this_page, $unix_date;
			
	switch ($table_type)	{

		case "matching":
			$report_select_sql = "SELECT * FROM critiques WHERE critique_status IN ('open', 'analyzed') AND critique_page_url LIKE '".$critique_page_url."' ORDER BY critique_score DESC";
			$header_html = "Existing Reports With the Same Page Address as the Last Page You Were Viewing";
			break;

		case "recent_closed":
			$recent_past = $unix_date - 5184000; //60 days ago
			$report_select_sql = "SELECT * FROM critiques WHERE critique_status LIKE 'closed' AND critique_last_comment_date > $recent_past ORDER BY critique_last_comment_date DESC";
			$header_html = "Reports that Were Recently Closed";
			break;

		default:
			$report_select_sql = "SELECT * FROM critiques WHERE critique_status IN ('open', 'analyzed') ORDER BY critique_score DESC";
			$header_html = "All Open Reports";
			
							}
	

	$result = run_query($report_select_sql, "Display Critiques");

	$final_html .= "<table class=\"generictable\">";
	$final_html .= "<tr><td colspan=\"8\" class=\"generictabletop\">".$header_html."</td></tr>";

	$final_html .= "<tr>";
	$final_html .= "<td class=\"genericsubtop\">Report ID#</td>";
	$final_html .= "<td class=\"genericsubtop\">Short&nbsp;Description</td>";
	$final_html .= "<td class=\"genericsubtop\">Report Type</td>";
	$final_html .= "<td class=\"genericsubtop\">Report Originator</td>";
	$final_html .= "<td class=\"genericsubtop\">Status</td>";
	$final_html .= "<td class=\"genericsubtop\">Report Page Address</td>";
	$final_html .= "<td class=\"genericsubtop\">Report Score</td>";
	$final_html .= "<td class=\"genericsubtop\">Click Below to View/Add Comment</td>";
	$final_html .= "</tr>";

	$row_count = num_rows($result);

	if($row_count > 0)	{ 
	for($c = 0; $c < $row_count; $c++)	{

		$row_array = fetch_array($result, "Display critique table B", $c);

		$final_html .= "<tr>";
		$final_html .= "<td class=\"generictd\">".$row_array["critique_id"]."</td>";
		$final_html .= "<td class=\"generictd\">".$row_array["critique_title"]."</td>";
		$final_html .= "<td class=\"generictd\">".ucfirst($row_array["critique_type"])."</td>";
		$final_html .= "<td class=\"generictd\">".$row_array["critique_author"]."</td>";
		$final_html .= "<td class=\"generictd\">".ucfirst($row_array["critique_status"])."</td>";
		$final_html .= "<td  class=\"generictd\"><span class\"smaller\">".$row_array["critique_page_url"]."</span></td>";
		$final_html .= "<td class=\"generictd\">".$row_array["critique_score"]."</td>";
		$final_html .= "<td class=\"generictd\"><a href=\"".$this_page."?selected_report=".$row_array["critique_id"]."&form_submitted=selected_report\">View/Add Comment</a></td>";
		$final_html .= "</tr>";
										}
						}
		else {$final_html .= "<tr><td  class=\"generictd\" colspan=\"8\">No Reports</td></tr>";}

	$final_html .= "</table><p></p>";

	return $final_html;

											}

function display_selected_report ($selected_report)	{
	GLOBAL $tag_values, $page_id, $html_template, $instructions, $message, $message_type, $validation_critique_entry_questions;

	$page_id = "display_report";
	$html_template = "system_critique_add_comment.html";
	$instructions .= "Report Details Below. Add your comments. ";

	//Pull new critique questions
	$critique_entry_questions = new Critique;
	$critique_entry_questions->critique_entry_questions ();

	

	//Make the value safe
	$selected_report += 0; 
	$tag_values["{FORM_END}"] .= display_hidden_form_values ("selected_report", $selected_report);

	////////Pull out exisiting report data
		
	$sql = "SELECT * FROM critiques WHERE critique_id = '".$selected_report."'";
	$result_critiques = run_query($sql, "Finding the matching report");
	
	if(num_rows($result_critiques) > 0)	{
		$critique_array = fetch_array($result_critiques, "Array of critique", "0");
		$sql_entries = "SELECT * FROM critique_entries WHERE critique_id = '".$selected_report."'";
		$result_entries = run_query($sql_entries, "Finding the matching report");

		//Table of info from the original report
		$final_html .= "<table class=\"generictable\">";
		$final_html .= "<tr>";
		$final_html .= "<td colspan=\"3\" class=\"generictabletop\">Short Description:<br/> ".$critique_array["critique_title"]."</td>";
		$final_html .= "</tr><tr>";
		$final_html .= "<td class=\"generictd\">Report Status: ".ucfirst($critique_array["critique_status"])."</td>";
		$final_html .= "<td class=\"generictd\">Report Type: ".ucfirst($critique_array["critique_type"])."</td>";
		$final_html .= "<td class=\"generictd\">Report Score: ".$critique_array["critique_score"]."</td>";
		$final_html .= "</tr class=\"generictd\"><tr>";
		
		$final_html .= "<td class=\"generictd\" colspan=\"3\">Page Address: ".$critique_array["critique_page_url"]."</td>";
		$final_html .= "</tr></table>";

		//Table of comments added to initial report
		$final_html .= "<table class=\"generictable\">";
		$comments_count = num_rows($result_entries);
		for($r = 0; $r < $comments_count; $r++)	{
			$added_comments_row = fetch_array($result_entries, "Added Critique Comments", $r);
			
			$user_info_array = pull_user_variables ($added_comments_row["critique_user_id"]);

			$final_html .= "<tr>";
			$final_html .= "<td class=\"genericsubtop\">Author: ".$user_info_array["user_name_first"]."&nbsp;".$user_info_array["user_name_last"]."</td>";
			$final_html .= "<td class=\"genericsubtop\">Access Level: ".$user_info_array["user_access_level"]."</td>";
			$final_html .= "<td class=\"genericsubtop\">Comment Date: ".safe_date("M - d - Y", $added_comments_row["critique_date"])."</td>";
			$final_html .= "</tr><tr>";
			$final_html .= "<td class=\"generictd\" colspan=\"3\">Comment:<br/>".$added_comments_row["critique_comment"]."</td>";
			$final_html .= "</tr><tr>";
			$final_html .= "<td class=\"generictd\" colspan=\"3\">&nbsp;</td>";
			$final_html .= "</tr>";
												}
		
		$final_html .= "</tr></table>";

										


	
	//Pull out the report status to pre-fill the form for new 
	if(!$validation_critique_entry_questions->vetted_form_answer["critique_status"])	{
		
		$validation_critique_entry_questions->vetted_form_answer["critique_status"] = $critique_array["critique_status"];
																						}


	//New critique entry questions into tags
	questions_into_tags ($critique_entry_questions->questions, $critique_entry_questions->question_elements, $validation_critique_entry_questions->vetted_form_answer);

	$tag_values["{EXISTING_REPORT}"] = $final_html;

											}
	//No reports wer found matching above, so sent back to the blank defautl page
	else	{
		$final_html .= "No reports matching that number found. ";
		$message .= "No reports matching that number found. ";
		$message_type = "error";
		display_default_critique_page ($critique_page_url, "yes");
			}


														}
	
						
function process_critique_added_comment ($selected_report, $form_answer)	{
	GLOBAL $question_validation_error, $critique_page_url, $validation_critique_entry_questions, $message, $message_type;
	
	//Make the value safe
	$selected_report += 0;
	
	//Pull new critique questions
	$critique_entry_questions = new Critique;
	$critique_entry_questions->critique_entry_questions ();

	//Validate new critique entry questions
	$validation_critique_entry_questions = new Questions_answers_validation($critique_entry_questions->questions, $critique_entry_questions->question_elements, $form_answer);

	if(!$question_validation_error)	{
		
		$critique_entry_questions->insert_critique_entry ($selected_report, $validation_critique_entry_questions->vetted_value);
		
		$message .= "Your Comment Successfully Added to the Report. ";
		$message_type = "ok";

		display_default_critique_page ($critique_page_url, "yes");

									}
	else	{
		display_selected_report ($selected_report);

			}
																			}

?>
Return current item: Homeless Mangement Information System