"Jumping Jerry Productions FAQ", 'BANNER2' => "Frequently asked questions (and answers!)", 'TITLE' => "Jumping Jerry Productions FAQ", 'MODULENAME' => "faq.phpx", 'NAV1' => "INFO" // Level 1 menu navigation group ); //------------------------------------------------------------------------ // Local configuration parameters //------------------------------------------------------------------------ $FAQCFG = array ( 'EDITLEVEL' => '5' // Access level to get edit screen ); //------------------------------------------------------------------------ // Database Fields //------------------------------------------------------------------------ $ALLFIELD = array( 'faq_id', 'faq_class', 'faq_topic', 'faq_category', 'faq_state', 'faq_type', 'faq_subcategory', 'faq_audience', 'faq_keywords', 'faq_summary', 'assignee_id', 'shelf_life', 'more_info', 'last_modified', 'faq_content' ); // // Fields visible in query output list // $SHOW = array( 'faq_topic', 'faq_category', 'faq_class', 'faq_audience', //'last_modified', //'faq_type' 'faq_summary', ); // // Fields that can have query drill down links on display // $LINK = array( 'faq_type', 'faq_class', 'faq_audience', 'faq_category', 'faq_topic' ); // // Fields that are from a Menu Picklist that can have new members // $EXTEND = array( 'faq_type', 'faq_category', 'faq_topic' ); // // Required for New Entry // $RequiredField = array( 'faq_summary' => 'enter faq summary', 'faq_content' => 'enter faq content in html', 'assignee_id' => 'choose name of author or maintainer', 'faq_class' => 'select class from list', 'faq_type' => 'select type from list or enter new faq type' ); // // Global query choices // $InValidChoice = array( 'All', '', ' ', 'None', 'Choose' ); // // Edit record fields with edit disabled // $NoEdit = array( 'faq_id', 'last_modified' ); $FieldType = array( 'assignee_id' => 'MenuArray', 'faq_audience' => 'Menu', 'faq_category' => 'Menu', 'faq_class' => 'Menu', 'faq_content' => 'TextArea', 'faq_keywords' => 'LongText', 'faq_state' => 'Menu', 'faq_summary' => 'LongText', 'faq_topic' => 'Menu', 'faq_type' => 'Menu', 'shelf_life' => 'MenuArray' ); $BASE = "SELECT choice FROM menu WHERE table_name = 'faq' AND "; $LBASE = "SELECT choice, description FROM menu WHERE table_name = 'faq' AND "; $Menu = array( "assignee_id" => "SELECT people_id, full_name from people order by last_name, first_name", "faq_type" => "SELECT DISTINCT faq_type from faq order by faq_type", "faq_state" => "$BASE field_name = 'faq_state' order by choice", "faq_topic" => "SELECT distinct faq_topic from faq order by faq_topic", "faq_category" => "SELECT distinct faq_category from faq order by faq_category", "faq_audience" => "$BASE field_name = 'faq_audience' order by choice", "shelf_life" => "$LBASE field_name = 'shelf_life' order by choice", "faq_class" => "$BASE field_name = 'faq_class' order by choice" ); // // Display exceptions from default tdcs centered display table cell // $JustifyCss = array( 'faq_audience' => 'tds', 'faq_summary' => 'tds', 'faq_topic' => 'tds', 'faq_category' => 'tds', 'faq_type' => 'tds', 'faq_class' => 'tds', ); //------------------------------------------------------------------------ // BEGIN Program //------------------------------------------------------------------------ spew_header($FMT); if (!array_key_exists('Action', $_REQUEST)) { //$dbh = jjn_pdo_connect(); //$sql = "SELECT count(*) from faq"; //$faq_count = get_value($sql); //if ( $faq_count > 12) { //$_REQUEST['Action'] = 'List'; //}else{ $_REQUEST['Action'] = 'ShowAll'; //} } if (array_key_exists('Action', $_REQUEST)) { echo "
\n"; // DEVONLY print_r($_REQUEST); // DEVONLY echo "\n"; // DEVONLY if ($_SESSION['access_level'] >=5 ){ spew_query_form(); } //---------------------------------------------------------------------- // Show: User read version //---------------------------------------------------------------------- if ($_REQUEST['Action'] == "Show") { if (! array_key_exists('faq_id', $_REQUEST)) { die ("No FAQ Id Set in Show function") ; }else{ $faq_id = $_REQUEST['faq_id']; } if (! is_numeric( $faq_id ) ) { die ("ERROR: Attempt to update Faq requires faq_id to be integer. It is not."); } $dbh = jjn_pdo_connect(); $fieldlabel = array (); $fieldlabel = get_field_labels('faq','faq',$JJNCFG['DBNAME']); $sql = "SELECT f.*, p.full_name FROM faq f, people p "; $sql .= " WHERE faq_id = '$faq_id'"; $sql .= " AND f.assignee_id = p.people_id "; echo "
$sql
\n"; // DEVONLY $result = $dbh->query($sql); $row = array(); $row = $result->fetch(PDO::FETCH_ASSOC); echo "\n"; echo "
| Categorization Summary | \n"; $viewlist = array ( 'faq_class', 'faq_category', //'faq_subcategory', 'faq_type' //'faq_type', //'faq_audience', //'last_modified' ); foreach ($viewlist as $f) { echo "$fieldlabel[$f] | \n"; } echo "
|---|
| $display | \n"; } }//Endforeach ($viewlist as $f) { echo "
\n"; echo "
| $row[faq_summary] | \n"; echo "|
|---|---|
| \n"; echo "$row[faq_content]"; echo " | \n"; echo "
|
$finalsql
\n"; //DEBUG DEVONLY //$result = $dbh->query($finalsql); //$_REQUEST['faq_id'] = $dbh->lastInsertId() ; $_REQUEST['Action'] = 'View'; $_REQUEST['faq_id'] = insertArray('faq',$InsertArray); echo "Returned Faq ID of $_REQUEST[faq_id]\n"; // DEVONLY echo "
'; // DEBUG DEVONLY echo "Incoming Updated Fields\n"; // DEBUG DEVONLY print htmlspecialchars(print_r($fieldlabel), ENT_QUOTES); // DEBUG DEVONLY print ''; // DEBUG DEVONLY $fields = array_keys($fieldlabel); // // Eliminate all keys that have invalid answers // Overwrite entries with NEW_... entries for Open Menus // foreach ($fields as $f) { $altkey = "NEW_" . $f; if (isset($_REQUEST[$altkey])) { if (in_array($_REQUEST[$altkey], $InValidChoice)) { unset ($_REQUEST[$altkey]); }else{ $_REQUEST[$f] = $_REQUEST[$altkey]; unset ($_REQUEST[$altkey]); } } if (in_array($_REQUEST[$f], $InValidChoice)) { unset ($_REQUEST[$f]); } } // // Update only the fields that have changed // $sql = 'UPDATE faq SET '; $sqlentry = array (); foreach ($fields as $f) { if ( array_key_exists($f, $_REQUEST)) { $val = $_REQUEST[$f]; if ( $_REQUEST[$f] != $Original[$f] ) { $val = $dbh->quote($_REQUEST[$f]); $sqlentry[] = $f . " = " . $val ; } } } if (count($sqlentry) > 0){ $sql .= implode (', ', $sqlentry); $sql .= " WHERE faq_id = '$faq_id'"; echo "
$sql
\n"; // DEVONLY DEBUG $result = $dbh->query($sql); echo "\n"; // DEBUG DEVONLY print_r($_SESSION); // DEBUG DEVONLY echo "\n"; // DEBUG DEVONLY $Where = array(); $dbh = jjn_pdo_connect(); $sql = "SELECT * from faq "; if ( isset($_SESSION['access_level']) ){ if ( $_SESSION['access_level'] < $FAQCFG['EDITLEVEL']){ $Where[] = "faq_audience != 'BOD'" ; } }else{ $Where[] = "faq_access = 'Public'"; } if (sizeof($Where) > 0) { $sql .= ' WHERE ' . implode(' AND ', $Where); } $sql .= " order by faq_audience, faq_id"; echo "
$sql
\n"; // DEVONLY $result = $dbh->query($sql); //--------------------------------------------------- // Spew table //--------------------------------------------------- echo "\n";
$old_audience = 'All';
echo "General\n"; echo "
$row[faq_audience]\n"; echo "
| \n";
echo "
\n";
$old_audience = '';
while ($row = $result->fetch(PDO::FETCH_ASSOC)){
if ( $old_audience != $row['faq_audience'] ){
echo "$row[faq_audience]\n"; $cnt=0; $old_audience = $row['faq_audience']; } $faqid = $row['faq_id']; $cnt++; echo "${cnt}. " . "$row[faq_summary] \n"; echo "$row[faq_content]\n"; } echo " | \n";
echo "
\n"; // DEBUG DEVONLY print_r($_SESSION); // DEBUG DEVONLY echo "\n"; // DEBUG DEVONLY $dbh = jjn_pdo_connect(); $fieldlabel = array(); $fieldlabel = get_field_labels('faq','faq',$JJNCFG['DBNAME']); $fields = array_keys($fieldlabel); //---------------------------------------------------------- // Capture previous selection criteria and append to links // To enable drill down subqueries //---------------------------------------------------------- foreach(explode( '&', $_SERVER['QUERY_STRING']) as $entry ) { list($key, $val) = explode( '=', $entry); if ( ! empty( $val ) ) { if (! in_array($val, $InValidChoice)) { if (in_array($key, $ALLFIELD) ) { $parameters[$key] = $val; } } } } $parameters['Action'] = $_REQUEST['Action']; //---------------------------------------------------------- // Uniquify for duplicate entries //---------------------------------------------------------- $validentries = array(); foreach ($parameters as $key => $val ) { $val = preg_replace('/\s+/', '+', $val); $validentries[] = $key . '=' . $val; } if (count($validentries)) { $drilldown = implode('&', $validentries); } // // Base sql query // $What = array( 'f.*', 'p.full_name' ); $WhereVal = array(); $Where = array( 'f.assignee_id = p.people_id' ); $From = array( 'faq' => 'f', 'people' => 'p' ); // // Construct where clause into an array // foreach ($fields as $f) { if (array_key_exists($f, $_REQUEST)) { $val = $_REQUEST[$f]; if (in_array( $val, $InValidChoice ) ){ unset($val) ; }else{ $Where[] = "f." . $f . '= ' . $dbh->quote($_REQUEST[$f]) ; } } } // // SECURITY // if ( isset($_SESSION['access_level'] )){ if ( $_SESSION['access_level'] < $FAQCFG['EDITLEVEL']){ $Where[] = "faq_audience != 'BOD'" ; } }else{ $Where[] = "faq_access = 'Public'"; } $sql = "SELECT DISTINCT " . implode(',', $What); $Fromsql = array(); foreach ($From as $table => $abbr) { $Fromsql[] = $table . ' ' . $abbr; } $Fromsql = array_unique($Fromsql); $sql .= ' FROM ' . implode(', ', $Fromsql); if ( count($Where) ) { $sql .= ' WHERE ' . implode(' AND ', $Where); } //--------------------------------------------------- // ORDER BY //--------------------------------------------------- $OrderBy = array( 'Author' => 'p.nickname, f.faq_summary', 'Category' => 'f.faq_category, f.faq_summary', 'Audience' => 'f.faq_audience, f.faq_summary', 'Name' => 'f.faq_summary', 'Topic' => 'f.faq_topic, f.faq_summary', 'Type' => 'f.faq_type, f.faq_summary' ); $sortby = $_REQUEST['Sortmeby']; $sby = $OrderBy[$sortby]; if (empty ($sby)){ $sql .= ' ORDER BY f.faq_summary'; }else{ $sql .= ' ORDER BY ' . $sby; } echo "
$sql
\n"; // DEVONLY $result = $dbh->query($sql); // Blurb echo "\n";
echo "Column entry links will "drill down" to refine your query.\n";
echo "
Click on summary link to see entire FAQ.\n";
echo "
| Edit | \n"; // SECURITY echo "View | \n"; } foreach ($ALLFIELD as $f) { if (in_array($f, $SHOW)) { echo "$fieldlabel[$f] | \n"; } } while ($row = $result->fetch(PDO::FETCH_ASSOC)){ $css = "tdc"; echo "
|---|---|---|
";
echo "";
echo " ";
echo " | \n";
// View
echo "";
echo "";
echo " ";
echo " | \n";
}
foreach ($ALLFIELD as $f) {
$css = "tdc";
$display = stripslashes($row[$f]);
//
// Display Exceptions (lookup)
//
if ( $f == 'faq_summary' ) {
$display = "";
$display .= "$row[$f]\n";
}
if ( $f == 'maintainer_id' ) {
$display = $row['full_name'];
}
if (in_array($f, $SHOW)) {
if (array_key_exists($f, $JustifyCss)) {
$css = $JustifyCss[$f];
}
echo "";
if (in_array($f, $LINK)) {
echo "";
echo "$display\n";
}else{
echo "$display\n";
}
echo " | \n";
}
}
}
echo "
Not logged in or sufficiently privileged to edit
\n"; spew_footer($FMT); exit; } }else{ echo "Not logged in. Edit functions require login.
\n"; spew_footer($FMT); exit; } $menulist = array(); $dbh = jjn_pdo_connect(); // Blurb echo "\n"; echo "Enter entries. Details on meanings and choice details available via help links in left column.\n"; echo "Asterisk (*) indicates field is required.\n"; echo "
\n"; echo "Not logged in or privileged to edit
\n"; spew_footer($FMT); exit; } }else{ echo "Not logged in. Edit functions require login.
\n"; spew_footer($FMT); exit; } if ( array_key_exists('faq_id', $_REQUEST)) { if ( isset($_REQUEST['faq_id'] ) ) { $faq_id = stripslashes( $_REQUEST['faq_id']); }else{ die ("NO Faq ID in edit function.") ; } if ( ! is_numeric($faq_id) ) { die ("Faq ID ($faq_id) is not an integer.") ; } }else{ die ("No Faq Id Set") ; } $dbh = jjn_pdo_connect(); // // People Rosterselect // $People = array(); $sql = "SELECT people_id, full_name from people order by last_name, first_name"; $People = get_menu_array(); $menulist = array(); $sql = "SELECT * FROM faq WHERE faq_id = '$faq_id'"; $result = $dbh->query($sql); $row = $result->fetch(PDO::FETCH_ASSOC); $fieldlabel = get_field_labels('faq','faq',$JJNCFG['DBNAME']); // Blurb echo "\n"; echo "Change desired entries and click Update at bottom of form.\n"; echo "
\n"; echo "\n"; echo "Field explanation available via link in left column field labels.\n"; echo "
\n"; echo ""; echo "Help and explanations available at "; echo "Overview."; echo "
\n"; echo "