// Script to view the results from feedback.php // PJ Waskiewicz, 4/15/2001 // view_feedback.php // Updated 9/30/2001 // Updated for the view comments module $filename = "/home/waskiewicz.org/www/scripts/view_feedback.html"; $mysql_connect_string = "/home/waskiewicz.org/etc/mysql_connect_string"; // Date array $date_array = array( "01" => "January", "02" => "February", "03" => "March", "04" => "April", "05" => "May", "06" => "June", "07" => "July", "08" => "August", "09" => "September", "10" => "October", "11" => "November", "12" => "December" ); $fp = fopen($mysql_connect_string, "r"); $username = fgets($fp, 4096); $password = fgets($fp, 4096); fclose($fp); $username = chop($username); $password = chop($password); // First open connection to database $link = mysql_connect("localhost", $username, $password) or die("Could not connect to MySQL!!"); // Select the database mysql_select_db("pj_web", $link); // First tally up the data from radio buttons // Helpful field $result = mysql_query("SELECT helpful FROM pj_feedback WHERE helpful='Enlightening'") or die("Bad query in _helpful_ clause"); $enlightening = mysql_num_rows($result); $result = mysql_query("SELECT helpful FROM pj_feedback WHERE helpful='Dark abyss'") or die("Bad query in _helpful_ clause"); $abyss = mysql_num_rows($result); $help_total = $enlightening + $abyss; // Global total $total_submissions = $help_total; // **** Get ratios for help **** // Prevent div 0 if($help_total == 0) $help_total = 1; $enlightening_ratio = (int)(($enlightening / $help_total) * 100); $abyss_ratio = (int)(($abyss / $help_total) * 100); // Friends field $result = mysql_query("SELECT friends FROM pj_feedback WHERE friends='Yeah right...'") or die("Bad query in _friends_ clause"); $right = mysql_num_rows($result); $result = mysql_query("SELECT friends FROM pj_feedback WHERE friends='Probably'") or die("Bad query in _friends_ clause"); $prob = mysql_num_rows($result); $friends_total = $right + $prob; // **** Get ratios for friends **** if($friends_total == 0) $friends_total = 1; $right_ratio = (int)(($right / $friends_total) * 100); $prob_ratio = (int)(($prob / $friends_total) * 100); // Idiot field $result = mysql_query("SELECT idiot FROM pj_feedback WHERE idiot='Not at all'") or die("Bad query in _idiot_ clause"); $no = mysql_num_rows($result); $result = mysql_query("SELECT idiot FROM pj_feedback WHERE idiot='Absolutely'") or die("Bad query in _idiot_ clause"); $absolutely = mysql_num_rows($result); $idiot_total = $no + $absolutely; // **** Get ratios for idiot **** if($idiot_total == 0) $idiot_total = 1; $no_ratio = (int)(($no / $idiot_total) * 100); $absolutely_ratio = (int)(($absolutely / $idiot_total) * 100); // Now load the page, and regex replace. $fp = fopen($filename, "r"); $content = fread($fp, filesize($filename)); fclose($fp); $total_submissions_str = " " . strval($total_submissions) . " "; $content = preg_replace("/NUM_SUBMISSIONS/", $total_submissions_str, $content); if($enlightening_ratio > $abyss_ratio) { $enlighten_str = "" . strval($enlightening_ratio) . "%" . ""; $abyss_str = strval($abyss_ratio) . "%"; } else if($enlightening_ratio < $abyss_ratio) { $enlighten_str = strval($enlightening_ratio) . "%"; $abyss_str = "" . strval($abyss_ratio) . "%" . ""; } else { $enlighten_str = strval($enlightening_ratio) . "%"; $abyss_str = strval($abyss_ratio) . "%"; } $content = preg_replace("/ENLIGHTENING/", $enlighten_str, $content); $content = preg_replace("/DARK_ABYSS/", $abyss_str, $content); if($right_ratio > $prob_ratio) { $right_str = "" . strval($right_ratio) . "%" . ""; $prob_str = strval($prob_ratio) . "%"; } else if($right_ratio < $prob_ratio) { $right_str = strval($right_ratio) . "%"; $prob_str = "" . strval($prob_ratio) . "%" . ""; } else { $right_str = strval($right_ratio) . "%"; $prob_str = strval($prob_ratio) . "%"; } $content = preg_replace("/YEAH_RIGHT/", $right_str, $content); $content = preg_replace("/PROBABLY/", $prob_str, $content); if($no_ratio > $absolutely_ratio) { $no_str = "" . strval($no_ratio) . "%" . ""; $absolutely_str = strval($absolutely_ratio) . "%"; } else if($no_ratio < $absolutely_ratio) { $no_str = strval($no_ratio) . "%"; $absolutely_str = "" . strval($absolutely_ratio) . "%" . ""; } else { $no_str = strval($no_ratio) . "%"; $absolutely_str = strval($absolutely_ratio) . "%"; } $content = preg_replace("/NOT_AT_ALL/", $no_str, $content); $content = preg_replace("/ABSOLUTELY/", $absolutely_str, $content); // Get the comments table in // First get the dates from the datetable $res = mysql_query("SELECT date from pj_datetable ORDER BY date") or die("SELECT query on pj_datetable died"); $comment_array = array(); while($row = mysql_fetch_array($res)) { // Read the php docs if you want to know what I'm doing... $date = $row["date"]; preg_match("/([0-9]...-[0-9].)-[0-9]./", $date, $matches); $date = $matches[1]; // Now we need to mangle it up preg_match("/([0-9]...)-([0-9].)/", $date, $matches); $year = $matches[1]; $month = $date_array[$matches[2]]; $add_str = $month . " " . $year; $element = array_pop($comment_array); if($element == "NULL") { // Push array_push($comment_array, $add_str); } else if($element == $add_str) { // Just push back on once array_push($comment_array, $element); } else { // Push both back on array_push($comment_array, $element); array_push($comment_array, $add_str); } } $comment_table = ""; while($str = array_pop($comment_array)) { $str_text = $str; $str = preg_replace("/\s/", "_", $str); $comment_table = $comment_table . "