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

////Header for every page that finds the include directory, connects to db, authenticates user access 
session_start();
include("initialize_pointer.php");
include($include_root."initialize.inc");
include($include_root."user_info_functions.inc");
$page_title = "Blog";
$page_access_levels = ":10:20:30:40:";
//$page_id = "blog";
//$page_id = "index";
//$page_profile = "Homepage";
//$instructions .= "System critiques are listed below. ";



//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");
}


//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.html";

       // }
//}

//If they are logged-in, run them through authenticate function
elseif ( $_SESSION['logged_inB'] == $db_name."yesindeed" ) {
    include_once( $include_root."authenticate.inc" );
}
elseif ( $_COOKIE["val".$unique_seq] )  {
    include_once( $include_root."authenticate.inc" );
}
else {
    include_once($include_root."authenticate_public.inc");
    //echo "No logged in";
    //echo "No criteria met"; exit;
}



//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");
//.body {font-family: Arial, Helvetica, sans-serif; color: #000099; padding: 0; background-color:#FFFBEA}
$head_dynamic_style = "
.masthead { padding:10; background-color: #FFE4AA }
.mastheadlink { font-family: Georgia, Arial, Helvetica, sans-serif; color: #000000; padding: 5; font-size: 180%; font-weight: bolder; text-decoration: none }
.mastheadlink:hover { font-family: Georgia, Arial, Helvetica, sans-serif; color: #000099; padding: 5; padding-left: 7; font-size: 180%; font-weight: bolder }

.sectiontitle {color: #FFFFCC; font-size: 16; font-family: arial; background-color: #003F5C; font-weight: bolder; padding: 10; width: 100%}
.maintable {  width: 95% }
.mainheadline { font-family: arial, helvetica; font-size: 120%; font-weight: bold; color: #000000; font-weight: bold; padding: 5; text-decoration: none; background-color: #FFFFFF }
.mainheadline:hover { font-family: arial, helvetica; font-size: 120%; font-weight: bold; color: #0000FF; font-weight:
bold; padding: 5; padding-left: 8 }
.mainheadlinestable { font-family: arial, helvetica; font-size: 120%; font-weight: bold; color: #000000; font-weight: bold; padding: 5; text-decoration: none; background-color: #FFFFFF }
.mainheadlinetd { border-width: 1px; border-style: solid; border-color: #000000; background-color: #FFFFFF; padding: 5 }
.statuschange  {font-family: arial, helvetica; font-size: 90%; color: #000000; padding-left: 15 }
.storysummary { font-family: times; font-size: 90%; background-color: #FFFFFF; padding-left: 12  }
.articleclickformore {font-size: 100%; font-weight: bold; font-family: Arial,Helvetica,sans-serif; padding-left: 12px} 
.commenttext { font-family: times, serif; font-size: 100%; font-weight: normal; background-color: #FFFFFF; color: #000000; padding: 5; padding-left: 15}
.subcommenttable { width: 75%; }
.indenttd { width: 2%; }
.subcommenttext { font-family: arial, helvetica; font-size: 90%; background-color: #FFFFFF; color: #000000; padding: 5; padding-left: 20}
.subcommenttitle { font-family: arial, helvetica; font-size: 100%; background-color: #FDFBDB; color: #000000; padding: 5; padding-left:
20; font-weight: bold}
.subcommentinfo { font-family: arial, helvetica; font-size: 70%; background-color: #FDFBDB; color: #000000; padding: 5; padding-left:
20; font-weight: bold}

"; 
convert_post_and_get_variable ("selected_report");
convert_post_and_get_variable ("form_submitted");

//Send the focus variable to the function, to se if we should focus on a part of the page
document_focus ( $_GET["focus"] );


switch($form_submitted)	{
	
	case "default_critique":
		display_default_critique_page ( $HTTP_POST_VARS["form_answer"] );
		break;

	case "selected_report":
		display_selected_report ( $selected_report );
		//echo "selected report selcted in switvh";
        break;

	case "display_report":
		//echo "Selected report is: ".$selected_report."<br>";
		process_critique_added_comment ( $selected_report, $HTTP_POST_VARS["form_answer"] );
        break;
	
    case "change_story_status":
		change_story_status ( $selected_report );
    	display_default_critique_page ( );
		break;
    
    case "edit_entry":
		edit_entry ( $selected_report );
    	
		break; 
            
    case "edit_entry_submitted":
        edit_entry_submitted ( $selected_report, $HTTP_POST_VARS["form_answer"] );
    	//echo "edit_entry submitted";
		break; 

	default:
		display_default_critique_page ( );
		//echo "in default";

}

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


//$tag_values["{PAGE TITLE}"] = page_title_table();
//$tag_values["{MENU}"] = menu();
$tag_values["{TITLE}"] = display_page_title();
$tag_values["{HEAD}"] = head ($page_title, $head_page_specific, $head_dynamic_style);

$tag_values["{FOOTER}"] = blog_footer();


template_parser ($html_template, $tag_values);

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

function display_default_critique_page ( $form_answers="")	{

	GLOBAL $tag_values, $page_id, $html_template, $question_validation_error;

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

    if ( $_SESSION['logged_inB'] )   {
       
       
        if ( $form_answers )    {
            $vetted_form_answers = process_critique_new_submission ($form_answers);    
        
        } 
    
	    $tag_values["{NEW_STORY_FORM}"] = create_new_story_submission_form ($vetted_form_answers);
        $tag_values["{RECENT_CLOSED_ENTRIES_TABLE}"] = display_table_of_entries("recent_closed");
	}
    else{
        $tag_values["{NEW_STORY_FORM}"] = " ";
        $tag_values["{RECENT_CLOSED_ENTRIES_TABLE}"] = " ";
    }

	//$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);
    
    //display_default_critique_page ();

}



function process_critique_new_submission ($form_answer)	{
	GLOBAL $question_validation_error, $message, $message_type, $html_template;
    $html_template = "blog.html";
    
	//if ( ereg ( "^a-z_" , $edit_rpt_id ) )   {
    //    $edit_rpt_id = "";
        //$form_answer = "";
    
    //}
    //Pull new critique questions
	$critique_new_questions = new Critique;
	$critique_new_questions->critique_new_questions ();

	//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);
    //$validation_critique_new_questions["critique_user_email"] = validate_email_address ( $form_answer["critique_user_email"] );
	//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);
        
        //Pull out the email/name of the logged-in user 
        $user_vars = pull_user_variables ( $_SESSION["user_id"] );
        $validation_critique_new_questions->vetted_value["critique_user_email"] = $user_vars["user_email"];
        $validation_critique_new_questions->vetted_value["critique_user_name"] =
	     $user_vars["user_name_first"]." ".$user_vars["user_name_last"];

		$critique_new_questions->insert_critique_entry ($inserted_critique_id, $validation_critique_new_questions->vetted_value);

		$message .= "New report successfully entered. ";
		$message_type = "ok";
		//display_default_critique_page ( );
        $validation_critique_new_questions->vetted_form_answer = "";

	}
    else    {
        //display_default_critique_page ( );
    
    }
    
    return $validation_critique_new_questions->vetted_form_answer;
	
}

function change_story_status ( $story_id ) {
    
    if ( !$_SESSION['logged_inB'] )   {
        echo "You do not have permission to chnage the story status";
        exit;
            
    }
    
    //Pull out the existing status of story
    $story_id += 0;
    $sql = "SELECT critique_status FROM critiques WHERE critique_id = '".$story_id."'";
    $status = run_query_return_single_row ($sql, "fetching critique status");
    
    //Change reverse the status
    if ( $status[0] == "open" ) {
        $new_status = "closed";
    }
    else {
        $new_status = "open";    
    }

    $sql = "UPDATE critiques SET critique_status = '".$new_status."' WHERE critique_id = '".$story_id."'";
    run_query ($sql, "Updating cirtique status");


}



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_status, critique_author) VALUES 
        ('".$vetted_values["critique_title"]."', 'open', '".$user_name."')";
		//echo "<p>".$sql."<p>";
        run_query($sql, "Insert new critiqueA");

		$sql = "SELECT critique_rowid FROM critiques WHERE critique_title LIKE '".$vetted_values["critique_title"]."' 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."' ";
		
        //echo $sql;
        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, $unique_seq, $use_cookie_login;

        $critique_author_info = $vetted_value["critique_user_name"]." - ".$vetted_value["critique_user_email"];
        

		$sql = "INSERT INTO critique_entries 
        (critique_id, critique_user_id, critique_comment_title, 
        critique_author_name, critique_author_email, critique_comment, critique_date) VALUES 
        ('".$critique_id."', '".$user_id."', '".$vetted_value["critique_title"]."',
        '".$vetted_value["critique_user_name"]."', '".$vetted_value["critique_user_email"]."', '".$vetted_value["critique_comment"]."', '".$unix_date."')";
		//echo $sql."<p>";
        run_query($sql, "Insert new critique entry B");
        
        if ( $use_cookie_login == "yes" )    {
            
            setcookie ( "name".$unique_seq, $vetted_value["critique_user_name"], time() + ( 60 * 60 * 24 * 365 ) );
            setcookie ( "email".$unique_seq, $vetted_value["critique_user_email"], time() + ( 60 * 60 * 24 * 365 ) );
            //echo "Setting cookie";
        }
/*

		$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 == "40")	{
		//	$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 ()	{
		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" => "Article title:",
        "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" => "yes", "report_type_id" => "critique_new", "question_default_value" => "", "question_visible" => "yes", "question_ecma" => "", "question_display_size" => "65");
        
        $this->questions["critique_comment"] = array ("question_id" => "critique_comment", "question_title" => "Article text:", "question_type"
        => "textarea", "question_owner_group_id" => "1", "question_owner_org_id" => "1", "question_field_size" => "20",
        "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" => "90", "question_special_attribute" => "50000");

		//$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");
        //$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_title"] = array ("question_id" => "critique_title", "question_title" => "Comment title:", "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" => "no", "report_type_id" => "critique_new", "question_default_value" => "", "question_visible" => "yes", "question_ecma" => "", "question_display_size" => "65");
        
        

        $this->questions["critique_user_name"] = array ("question_id" => "critique_user_name", "question_title" => "Name (optional): ",
        "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" => "no",
        "report_type_id" => "critique_new", "question_default_value" => "", "question_visible" => "yes", "question_ecma" => "",
        "question_display_size" => "40");
        
        $this->questions["critique_user_email"] = array ("question_id" => "critique_user_email", "question_title" => "Email address (optional): ",
        "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" => "no",
        "report_type_id" => "critique_new", "question_default_value" => "", "question_visible" => "yes", "question_ecma" => "",
        "question_display_size" => "30");

        

        
		//$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($_SESSION['logged_inB'])	{
			     
            
            $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");



		}
      
        $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" => "6",
        "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" => "80", "question_special_attribute" => "20000");
        				
        
			
	}

}		



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

		case "open":
			$report_select_sql = "SELECT * FROM critiques WHERE critique_status IN ('open') ORDER BY critique_score DESC LIMIT 100";
			//$header_html = "Existing Reports With the Same Page Address as the Last Page You Were Viewing";
			$status_change_label = "Close this story";
            break;

		case "recent_closed":
			$recent_past = $unix_date - 5184000; //60 days ago
			$report_select_sql = "SELECT * FROM critiques WHERE critique_status LIKE 'closed' ORDER BY critique_last_comment_date DESC
            LIMIT 200";
			$status_change_label = "Open this story";
            //$header_html = "Reports that Were Closed";
			break;

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

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

	$final_html .= "<table class=\"maintable\">";
	//$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 colspan =\"2\" class=\"genericsubtop\">Description</td></tr><tr><td>";
	//$final_html .= "<td class=\"genericsubtop\">Report Type</td>";
	//$final_html .= "<td class=\"genericsubtop\">Author</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);
        
        if ( $_SESSION['logged_inB'] )  {
            $status_change_link = "";
            //$status_change_link .= "<br/><span class=\"generictd\"><a href=\"".$this_page."?selected_report=";
            $status_change_link .= "  -  <a class=\"statuschange\" href=\"".$this_page."?selected_report=";
            $status_change_link .= $row_array["critique_id"];
            $status_change_link .= "&form_submitted=change_story_status\">$status_change_label</a>";
            //echo "yes logged in";
        }
        
	//Pull the title
	$sqlc = "SELECT critique_comment_title FROM critique_entries WHERE critique_id = '".$row_array["critique_id"]."' ORDER BY critique_date";
        $titlec = run_query_return_single_row ( $sqlc, "Pulling title of first entry" );
	
	$final_html .= "<tr><td class=\"indenttd\">&nbsp;</td>";
		//$final_html .= "<td class=\"generictd\">".$row_array["critique_id"]."</td>";
		$final_html .= "<td class=\"mainheadlinetd\"><a class=\"mainheadline\"
        href=\"".$this_page."?selected_report=".$row_array["critique_id"]."&form_submitted=selected_report\">".stripslashes($titlec[0])."</a>".$status_change_link."</td></tr><tr><td class=\"indenttd\">&nbsp;</td>";
		//$final_html .= "<td class=\"generictd\">".ucfirst($row_array["critique_type"])."</td>";
		//$final_html .= "<td class=\"generictd\">Author: ".$row_array["critique_author"]."</td></tr><tr>";
		$summary = pull_story_summary ( $row_array["critique_id"] );
        $final_html .= "<td class=\"storysummary\">".$summary;
        $final_html .= "<a class=\"articleclickformore\"
        href=\"".$this_page."?selected_report=".$row_array["critique_id"]."&form_submitted=selected_report\">Click here to read full
        story</a></td>";
        $final_html .= "</td></tr><tr><td class=\"indenttd\">&nbsp;</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><a class=\"articleclickformore\"
        //href=\"".$this_page."?selected_report=".$row_array["critique_id"]."&form_submitted=selected_report\">Click to read full story...</a></td>";
		$final_html .= "</tr>";
        $final_html .= "<td class=\"indenttd\">&nbsp;</td><td class=\"spacertd\">&nbsp;</td></tr>";
	}
	}
		else {$final_html .= "<tr><td >No Reports</td></tr>";}

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

	return $final_html;

}




function pull_story_summary ($story_id) {
    $sql = "SELECT * FROM critique_entries WHERE critique_id = '".$story_id."' ORDER BY critique_date";
    $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);
        $summary_raw = $critique_array["critique_comment"];
        //echo $summary_raw;
        //Pull first 100 words
        $summary_array = explode ( " ", $summary_raw, 100 );
        $word_count = count ( $summary_array ) - 1;
        for ( $i = 0; $i < $word_count; $i++ )  {
        //foreach ( $summary_array AS $cur_word )  {
            $summary_assembled .= $summary_array[$i]." ";
        }
        //$fin_comment = str_replace("\n", "<br/>", stripslashes( $summary_assembled ));
        $fin_comment = process_comment_for_display ( $summary_assembled );
        $summary_final = $fin_comment."...";
    }
    else {
        $summary_final = "No entries";    
    }
    return $summary_final;
}



function process_comment_for_display ( $raw_comment ) {
    //Add html returns
    $final_ht = str_replace ( "\n", "<br/>", stripslashes ( $raw_comment ) );
    //$final_ht = str_replace ( "&lt;b&gt;", "<span class='commentbold'>", $final_ht ); 
    //$final_ht = str_replace ( "&lt;/b&gt;", "</span>", $final_ht );
    
    return $final_ht;

}



function display_selected_report ( $selected_report, $vetted_form_answers="", $message="" )	{
	GLOBAL $tag_values, $page_id, $html_template, $instructions, $message, $message_type,
     $unique_seq, $this_page, $use_cookie_login, $question_validation_error, $head_dynamic_ecma;

	//Put the focues on the text box
    //$head_dynamic_ecma[1] = "onLoad=sf()";
    //$head_dynamic_ecma[0] = "function sf(){document.formid_display_report['form_answer[critique_comment]'].focus();}";
    
    $page_id = "display_report";
	$html_template = "blog_add_comment.html";
	//$instructions .= "Report Details Below. Add your comments. ";
    //echo "in selected report";
	//if ( $HTTP_SESSIONNo reports matching_VARS["logged_in"] )   {
        //Pull new critique questions
	    $critique_entry_questions = new Critique;
	    $critique_entry_questions->critique_entry_questions ();
    //}

    

    ///Find email and name from database if logged in, or from cookie if not logged in
    if ( !$vetted_form_answers )    {

        if ( $_SESSION['logged_inB'] )    {
            //$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");
            $user_vars = pull_user_variables ( $_SESSION["user_id"] );
            $vetted_form_answers["critique_user_email"] = $user_vars["user_email"];
            $vetted_form_answers["critique_user_name"] = $user_vars["user_name_first"]." ".$user_vars["user_name_last"];     
        }
        elseif ( $use_cookie_login == "yes" && $_COOKIE["email".$unique_seq] )   {
            $vetted_form_answers["critique_user_email"] = $_COOKIE["email".$unique_seq];        
            $vetted_form_answers["critique_user_name"] = $_COOKIE["name".$unique_seq];
        }
    }
    
    if ( $vetted_form_answers && !$question_validation_error )  {
        if ( $_SESSION['logged_inB'] )    {
            //$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");
            $user_vars = pull_user_variables ( $_SESSION["user_id"] );
            $vetted_form_answers["critique_user_email"] = $user_vars["user_email"];
            $vetted_form_answers["critique_user_name"] = $user_vars["user_name_first"]." ".$user_vars["user_name_last"];     
        }
        elseif ( $use_cookie_login == "yes" && $_COOKIE["email".$unique_seq] )   {
            $vetted_form_answers["critique_user_email"] = $_COOKIE["email".$unique_seq];        
            $vetted_form_answers["critique_user_name"] = $_COOKIE["name".$unique_seq];
        }
     
    } 

	

	//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."' ORDER BY critique_date";
		$result_entries = run_query($sql_entries, "Finding the matching report");
        if ( num_rows ( $result_entries ) > 0 ) {
            
            $added_comments_row = fetch_array($result_entries, "AddedD Critique Comments", 0);
            
            
            if ( $_SESSION['logged_inB'] )  {
                $edit_link = "";
                //$status_change_link .= "<br/><span class=\"generictd\"><a href=\"".$this_page."?selected_report=";
                $edit_link .= "  -  <a class=\"statuschange\" href=\"".$this_page."?selected_report=";
                $edit_link .= $added_comments_row[$unique_seq."critique_entry_rowid"];
                $edit_link .= "&form_submitted=edit_entry\">Click to edit entry</a>";
                //echo "yes logged in";
            }
            
            
            
            

		    //Table of info from the original report
		    $final_html .= "<table class=\"maintable\">";
		    $final_html .= "<tr>";
		    $final_html .= "<td colspan=\"1\" class=\"mainheadlinestable\">
            <a name=\"".$added_comments_row[$unique_seq."critique_entry_rowid"]."\">".$added_comments_row["critique_comment_title"]."</a>".$edit_link."</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>";
		    //$fin_comment = str_replace("\n", "<br/>", stripslashes( $added_comments_row["critique_comment"] ));
            $fin_comment = process_comment_for_display ( $added_comments_row["critique_comment"] );
            $final_html .= "<td class=\"commenttext\">".$fin_comment."</td>";
		    //$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=\"subcommenttable\">";
		    $comments_count = num_rows($result_entries);

            for($r = 1; $r < $comments_count; $r++)	{
		        $added_comments_row = fetch_array($result_entries, "Added Critique Comments", $r);


		        if ( $_SESSION['logged_inB'] )  {
                    $edit_link = "";
                    //$status_change_link .= "<br/><span class=\"generictd\"><a href=\"".$this_page."?selected_report=";
                    $edit_link .= "  -  <a class=\"statuschange\" href=\"".$this_page."?selected_report=";
                    $edit_link .= $added_comments_row[$unique_seq."critique_entry_rowid"];
                    $edit_link .= "&form_submitted=edit_entry\">Click to edit entry</a>";
                    //echo "yes logged in";
            	}
		//$user_info_array = pull_user_variables ($added_comments_row["critique_user_id"]);

                //Put a bookmark on the last comment so jump to if coming from a successful form submission
                if (  $message && $r == $comments_count - 1 ) {
                    $final_html .= "<tr><td class=\"message\" colspan=\"3\"><a name=\"bookmark\">".$message."</a></td></tr>";
                    //echo "yes<p>";
                }
                else {
                    //echo "no<p>";
                    
                
                }

		        $final_html .= "<tr>";
                $final_html .= "<td class=\"indenttd\">&nbsp;</td>";
			    
                
                
                
                $final_html .= "<td class=\"subcommenttitle\" colspan=\"2\">";
                $final_html .= "<a name=\"".$added_comments_row[$unique_seq."critique_entry_rowid"]."\" id=\"".$added_comments_row[$unique_seq."critique_entry_rowid"]."\">";
                $final_html .= $added_comments_row["critique_comment_title"]."</a>".$edit_link."</td></tr>";
                
                
                
                $final_html .= "<tr><td class=\"indenttd\">&nbsp;</td>";
                $final_html .= "<td class=\"subcommentinfo\">Author:";
                $final_html .= $added_comments_row["critique_author_name"]."&nbsp;-&nbsp;<a
                href=\"mailto:".$added_comments_row["critique_author_email"]."\">".$added_comments_row["critique_author_email"]."</a></td>";
			    //$final_html .= "<td class=\"genericsubtop\">Access Level: ".$user_info_array["user_access_level"]."</td>";

                $final_html .= "<td class=\"subcommentinfo\">Comment Date: ".safe_date("M - d - Y", $added_comments_row["critique_date"])."</td>";
			    $final_html .= "</tr><tr>";
			    $final_html .= "<td class=\"indenttd\">&nbsp;</td>";
                $fin_comment = str_replace("\n", "<br/>", stripslashes( $added_comments_row["critique_comment"] ));
                $final_html .= "<td class=\"subcommenttext\" colspan=\"2\">".$fin_comment."</td>";
			    $final_html .= "</tr><tr>";
                $final_html .= "<td >&nbsp;</td>";
			    $final_html .= "<td colspan=\"2\">&nbsp;</td>";
			    $final_html .= "</tr>";
		    }

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

	    }
        else {
            $final_html .= "No entries";   
        }
	//Pull out the report status to pre-fill the form for new 
	//if(!$vetted_form_answers["critique_status"])	{
		
		//$vetted_form_answers["critique_status"] = $critique_array["critique_status"];
	//}

    


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

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

	}
	//No reports were 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 ();
	}
    
    
    
    

    $tag_values["{NEW_COMMENT_FORM}"] = create_story_comment_submission_form ( $selected_report, $vetted_form_answers );

}

	
						
function process_critique_added_comment ($selected_report, $form_answer)	{
	GLOBAL $question_validation_error, $message, $message_type, $include_root, $unique_seq, $system_title;
	//echo "Processing addded comment<p><p>";
    //echo "SELECTED REPOT IS: ".$selected_report."<p>";
    //display_value ( $form_answer );
	//Make the value safe
	
    include_once ($include_root."email_class.inc");
    
    $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);
    //var_dump ( $validation_critique_entry_questions);
    //echo "The val is: ".$validation_critique_entry_questions->vetted_value["critique_user_email"]."<p>";
    //If there is an email address submitted, vet it
    if ( $validation_critique_entry_questions->vetted_value["critique_user_email"] )  {
        //var_dump ( $validation_critique_entry_questions);
        //echo "There is a email entry";
        $emv = new Email();
        if ( $emv->validate_email_address ( $validation_critique_entry_questions->vetted_value["critique_user_email"] ) == -1 )  {
            question_error_marking ( "critique_user_email", "Invalid email address. " );
            //echo "Bad EMAILLLLLLLLLLLLLLLLLL";
        }
    }
    
    //echo "ERROR is: ".display_value($question_validation_error)."<p>";

	if(!$question_validation_error)	{
		
		//Find the email of the last reply
        $sql = "SELECT critique_author_email, critique_author_name FROM critique_entries WHERE critique_id = '".$selected_report."' ORDER BY critique_date DESC";
        $last_comment_email = run_query_return_single_row ($sql, $error_message);        
        
        //Find email of first entry
        $sql = "SELECT critique_author_email, critique_author_name FROM critique_entries WHERE critique_id = '".$selected_report."' ORDER BY critique_date";
        $first_comment_email = run_query_return_single_row ($sql, $error_message);        
      
        //Insert the entry
        $critique_entry_questions->insert_critique_entry ($selected_report, $validation_critique_entry_questions->vetted_value);
		
        //Find last related critique_entry_row_id
        $sqlb = "SELECT critique_entry_rowid FROM critique_entries WHERE critique_id = '".$selected_report."' ORDER BY critique_date DESC";
        $result = run_query ( $sqlb, "Fetching result last insert id" );
        $last_inserted_id = fetch_result ( $result, "Fetchi last insert" );
        
		$message .= "Your comment below successfully added to the discussion. ";
		$message_type = "ok";
        //echo "OKKKKKKKKK<p><p>";
		display_selected_report ($selected_report, "", $message);
        
        ////Send emails to conversation participants
        
        $email_message .= "The following comment was added to the discussion at "; 
        $email_message .= "<a href=\"http://".$_SERVER["SERVER_NAME"].$_SERVER["SCRIPT_NAME"]."?selected_report=".$selected_report."&form_submitted=selected_report&focus=yes\">";
        $email_message .= $_SERVER["SERVER_NAME"]."</a><br/>";
        $email_message .= "<p><a href=\"http://".$_SERVER["SERVER_NAME"].$_SERVER["SCRIPT_NAME"]."?selected_report=".$selected_report."&form_submitted=selected_report&focus=yes\">";
        $email_message .= "Click Here</a> to view the complete discussion.</p>"; 
        $email_message .= "<p><b>".$validation_critique_entry_questions->vetted_value["critique_title"]."</b></p>";
        $email_message .= "<p>".str_replace("\n", "<br/>", stripslashes( $validation_critique_entry_questions->vetted_value["critique_comment"] ))."</p>";
        
        
        //var_dump ($validation_critique_entry_questions->vetted_value);
        //echo "<p>";
        //echo "Pre version of from name: ".$validation_critique_entry_questions->vetted_value["critique_user_name"]."<p>";
                
        $em = new Email();
        if ( $last_comment_email["critique_author_email"] != $first_comment_email["critique_author_email"] )    {
            
            if ( $em->validate_email_address ( $last_comment_email["critique_author_email"] ) != -1 ) {
                $em->email_message ( 
                 $last_comment_email["critique_author_email"], 
                  $last_comment_email["critique_author_name"],
                   $validation_critique_entry_questions->vetted_value["critique_user_email"],
                    $validation_critique_entry_questions->vetted_value["critique_user_name"], 
                     $email_message,
                      $system_title." - ".$validation_critique_entry_questions->vetted_value["critique_title"] );
                      //echo "Sending email to ".$last_comment_email["critique_author_email"]."<p>";

            }
                            
        }
        
        if ( $em->validate_email_address ( $first_comment_email["critique_author_email"] ) != -1 ) {
            $em->email_message ( 
             $first_comment_email["critique_author_email"], 
              $first_comment_email["critique_author_name"],
               $validation_critique_entry_questions->vetted_value["critique_user_email"],
                $validation_critique_entry_questions->vetted_value["critique_user_name"], 
                 $email_message,
                  $system_title." - ".$validation_critique_entry_questions->vetted_value["critique_title"] );
                  //echo "Sending email to ".$first_comment_email["critique_author_email"]."<p>";

        }
        

	}
	else	{
		//echo "NOT OKKKKKKKKK<p><p>";
        display_selected_report ($selected_report, $validation_critique_entry_questions->vetted_form_answer );

	}
    
    
}



function create_new_story_submission_form ( $vetted_form_answers ) {

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

    //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);
    $f_html .= form_start ();
    $f_html .= "<p/><p/><table class=\"maintable\"><tr>";
    $f_html .= "<td class=\"generictabletop\">To add a new article, complete the following form:</td></tr><tr>";
    $f_html .= question_display ( $critique_entry_questions->questions["critique_title"],
        $critique_entry_questions->question_elements["critique_title"], $vetted_form_answers );
    $f_html .= "</tr><tr>";
    $f_html .= question_display ( $critique_entry_questions->questions["critique_comment"],
        $critique_entry_questions->question_elements["critique_comment"], $vetted_form_answers );
    $f_html .= "</tr><tr><td>";
    //$f_html .= "<>";
    //$f_html .= question_display ( $critique_entry_questions->questions["critique_status"],
    //    $critique_entry_questions->question_elements["critique_status"], $vetted_form_answers );
    //$f_html .= "</td></tr><td>";
    $f_html .= form_end ("Submit New Story", 1);
    //$f_html .= "<>";
    $f_html .= "</td></tr></table><p/>";
    
    
    
    return $f_html;



}




function create_story_comment_submission_form ( $selected_report, $vetted_form_answers ) {
    GLOBAL $access_level;
    GLOBAL $this_page;
    //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 ();

    //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);
    $f_html .= form_start ( $this_page."#bookmark" );
    $f_html .= "<tr><td><p/><p/><table><tr>";
    $f_html .= question_display ( $critique_entry_questions->questions["critique_title"],
        $critique_entry_questions->question_elements["critique_title"], $vetted_form_answers );
    $f_html .= "</tr><tr>";
    $f_html .= question_display ( $critique_entry_questions->questions["critique_user_name"],
        $critique_entry_questions->question_elements["critique_user_name"], $vetted_form_answers );
    $f_html .= "</tr><tr>";
    $f_html .= question_display ( $critique_entry_questions->questions["critique_user_email"],
        $critique_entry_questions->question_elements["critique_user_email"], $vetted_form_answers );
    $f_html .= "</tr><tr>";
    $f_html .= question_display ( $critique_entry_questions->questions["critique_comment"],
        $critique_entry_questions->question_elements["critique_comment"], $vetted_form_answers );
    $f_html .= "</td></tr>";
    //if ( $access_level == 40 )  {
    //$f_html .= "<tr>";
    //$f_html .= question_display ( $critique_entry_questions->questions["critique_status"],
    //    $critique_entry_questions->question_elements["critique_status"], $vetted_form_answers );
    //$f_html .= "</tr>";
    //}
    $f_html .= "<tr><td>";
    //$f_html .= "<>";
    $f_html .= display_hidden_form_values("selected_report", $selected_report);
    $f_html .= form_end ("Click Here to submit new comment");
    //$f_html .= "<>";
    $f_html .= "</td></tr></table><p/></td></tr>";
    
    
    
    return $f_html;



}



function create_story_comment_edit_form ( $critique_entry_id, $vetted_form_answers ) {
    GLOBAL $access_level;
    //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 ();

    //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);
    $f_html .= form_start ();
    $f_html .= "<tr><td><p/><p/><table><tr>";
    $f_html .= question_display ( $critique_entry_questions->questions["critique_title"],
        $critique_entry_questions->question_elements["critique_title"], $vetted_form_answers );
    $f_html .= "</tr><tr>";
    $f_html .= question_display ( $critique_entry_questions->questions["critique_user_name"],
        $critique_entry_questions->question_elements["critique_user_name"], $vetted_form_answers );
    $f_html .= "</tr><tr>";
    $f_html .= question_display ( $critique_entry_questions->questions["critique_user_email"],
        $critique_entry_questions->question_elements["critique_user_email"], $vetted_form_answers );
    $f_html .= "</tr><tr>";
    $f_html .= question_display ( $critique_entry_questions->questions["critique_comment"],
        $critique_entry_questions->question_elements["critique_comment"], $vetted_form_answers );
    $f_html .= "</td></tr>";
    //if ( $access_level == 40 )  {
    //$f_html .= "<tr>";
    //$f_html .= question_display ( $critique_entry_questions->questions["critique_status"],
    //    $critique_entry_questions->question_elements["critique_status"], $vetted_form_answers );
    //$f_html .= "</tr>";
    //}
    $f_html .= "<tr><td>";
    //$f_html .= "<>";
    $f_html .= display_hidden_form_values( "selected_report", $critique_entry_id );
    $f_html .= display_hidden_form_values( "form_submitted", "edit_entry_submitted" );
    $f_html .= form_end ("Submit edited comment");
    //$f_html .= "<>";
    $f_html .= "</td></tr></table><p/></td></tr>";
    //echo $f_html;
    //echo "JUELLO";
    
    return $f_html;



}







function display_page_title ()  {
    GLOBAL $system_directory, $message, $message_type, $head_dynamic_style, $system_title, $this_page, $question_validation_error;
    $ht .= "<table width=\"100%\">
    <tr>
        <td class=\"masthead\"><a class=\"mastheadlink\" href=\"http://".$_SERVER["SERVER_NAME"].$this_page."\">".$system_title."</a></td>

    </tr>";
    
    if($question_validation_error)	{
		if(!$message)	{$message .= "ERROR: Incorrect form input, see below. ";}
		$message_type = "error";
	}

	if($message_type == "ok")	{
		$head_dynamic_style .= "\n.message {background-color: #66FF99; color: #000066; font-size: \"90%\" } "; 
	}
	elseif ($message_type == "error")	{
		$head_dynamic_style .= "\n.message {background-color: #FF0000; color: #FFCCCC; font-size: \"90%\" } "; 
	}
                                        
    $ht .= "<tr><td class=\"message\">".htmlentities($message)."</td></tr>";



    $ht .= "</table>";
    
    return $ht;



}



function edit_entry ( $critique_entry_id, $vetted_from_answer="" )  {
    GLOBAL $question_validation_error, $tag_values, $html_template;
    
    if ( ereg ( "[^0-9]", $critique_entry_id ) )    {
        echo "Invalid id submitted"; exit;
    }
    if ( !$_SESSION['logged_inB'] ) {
        echo "Not allowed to edit"; exit;
    }
    
    $html_template = "blog_edit.html";
    
    
    if ( !$vetted_from_answer ) {
        $entry_attr = pull_entry_contents ( $critique_entry_id );
    }   
    else {
         $entry_attr = $vetted_from_answer;  
    }
    $tag_values["{EDIT_ENTRY_TABLE}"] = create_story_comment_edit_form ( $critique_entry_id, $entry_attr );
    
    
    //
    
    return $ht;
}



function edit_entry_submitted ( $critique_entry_id, $form_answers )  {
    GLOBAL $question_validation_error, $tag_values, $html_template, $message, $message_type;
    
    if ( ereg ( "[^0-9]", $critique_entry_id ) )    {
        echo "Invalid id submitted"; exit;
    }
    if ( !$_SESSION['logged_inB'] ) {
        echo "Not allowed to edit"; exit;
    }
    
    
    //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_answers);
    
    if ( !$question_validation_error )  {
        //var_dump ( $validation_critique_entry_questions->vetted_value );
        insert_edited_entry ( $critique_entry_id, $validation_critique_entry_questions->vetted_value );    
        $message = "Edit successful";
        $message_type = "ok";
        //echo "No erros, sucess in submission<p>";
        $attr = pull_entry_contents ( $critique_entry_id );
        //echo "ID is: ".$attr[$unique_seq."critique_entry_rowid"]."<p>";
        display_selected_report ( $attr["critique_id"] );
        
    }
    else    {
        $message .= "Entry errors, see below.";
        $message_type = "error";
        //echo "YES erros, sucess in submission<p>";
        //var_dump ($validation_critique_entry_questions->vetted_form_answer);
        edit_entry ( $critique_entry_id, $validation_critique_entry_questions->vetted_form_answer );
    }
    
    
    
    

}



function pull_entry_contents ( $critique_entry_id )    {
    GLOBAL $unique_seq;
    $critique_entry_id += 0;
    $sql = "SELECT * FROM critique_entries WHERE critique_entry_rowid = '".$critique_entry_id."'";
    $entry_array = run_query_return_single_row ($sql, "Pulling critique entry for editing");
    //var_dump ( $entry_array );
    $entry_array["critique_title"] = $entry_array["critique_comment_title"];
    $entry_array["critique_user_name"] = $entry_array["critique_author_name"];
    $entry_array["critique_user_email"] = $entry_array["critique_author_email"];
    
    return $entry_array;
}



function insert_edited_entry ( $critique_entry_id, $vetted_value ) {
        GLOBAL $unique_seq;
        $critique_entry_id += 0;
        //var_dump ($vetted_value);
        $sql = "UPDATE critique_entries SET 
         critique_comment_title = '".$vetted_value["critique_title"]."',
          critique_author_name = '".$vetted_value["critique_user_name"]."',
           critique_comment = '".$vetted_value["critique_comment"]."', 
            critique_author_email = '".$vetted_value["critique_user_email"]."'
            WHERE critique_entry_rowid = '".$critique_entry_id."'";
        //echo $sql."<p>";
        run_query ( $sql, "Updating edited entry" );
        //$message = "Edit successful";
        //$message_type = "ok";
        
        //(critique_id, critique_user_id, critique_comment_title, 
        //, critique_author_email, , critique_date) VALUES 
        //('".$critique_id."', '".$user_id."', 
        //'".$vetted_value["critique_user_name"]."', '".$vetted_value["critique_user_email"]."', , '".$unix_date."')";

}



function blog_footer (  )   {
    GLOBAL $system_title;
    return "<a class=\"mastheadlink\" href=\"http://".$_SERVER["SERVER_NAME"].$this_page."\">To return to main page, click here</a>";  


}

function document_focus ( $focus_command )  {
    GLOBAL $head_dynamic_ecma;
    
    if ( $focus_command ) {    
        //Put the focues on the text box
        $head_dynamic_ecma[1] .= "onLoad=sf()";
        $head_dynamic_ecma[0] .= "function sf(){document.formid_display_report['form_answer[critique_comment]'].focus();} ";
        //$head_dynamic_ecma[0] .= "function sf(){document.getElementById['39'].focus();} ";
    }

}



function validate_email_address ( $emailform )  {
    GLOBAL $question_validation_error;
 
 
    if ( eregi( "^[-a-z0-9_]+[-a-z0-9_.]*@[-a-z0-9_]+.[-a-z0-9_.]+$", $emailform) && strlen ($emailform) < 51 ) {
                //Do nothing
    }    
    else {    
        $question_validation_error.= "\"Email\" must be letters, numbers, and/or the characters \".\", \"@\", \"-\", and no more than 50 characters
        long<br>"; $error_message = "yes"; $emailform="";
	}

    return $emailform;

}
?>
Return current item: Homeless Mangement Information System