'Help', 'BANNER2' => 'Explanations and notes about the website', 'TITLE' => 'Help', 'MODULENAME' => 'help.phpx', 'NAV1' => 'HELP' ); $HELPCFG = array( 'ADMINLEVEL' => '4' ); //-------------------------------------------------------------------------- // BEGIN Field Definitions, Arrays, Variables, etc //-------------------------------------------------------------------------- $ALLFIELD = array( 'help_id', 'meta_id', 'contact_id', 'language', 'topic', 'subtopic', 'application', 'context', 'module', 'keywords', 'sequence', 'level', 'table_name', 'field_name', 'help_type', 'short_help', 'long_help', 'summary', 'last_modified' ); $SHOW = array( 'topic', 'subtopic', 'application', 'context', 'module', 'table_name', 'field_name', 'help_type', 'summary' ); // Fields that can have query drill down links on display $LINK = array( 'contact_id', 'language', 'topic', 'subtopic', 'application', 'module', 'table_name', 'field_name', 'help_type' ); // Fields that are from a Menu Picklist that can have new members $EXTEND = array( 'help_type', 'subtopic' ); // Required for New Entry $RequiredField = array( 'contact_id' => 'enter contact id', 'language' => 'enter language, default is US_English', 'topic' => 'enter topic', 'application' => 'enter application', 'context' => 'enter context', 'module' => 'enter php module name', 'summary' => 'enter help summary', 'help_type' => 'enter help type', 'short_help' => 'enter short version or quick help', 'long_help' => 'enter long version or detailed help' ); // Global query choices $InValidChoice = array( 'All', 'None', '', ' ', 'Choose' ); // Edit record fields with edit disabled $NoEdit = array( 'help_id', 'last_modified' ); $FieldType = array( 'help_type' => 'Menu', 'language' => 'Menu', 'contact_id' => 'People', 'keywords' => 'LongText', 'summary' => 'LongText', 'short_help' => 'TextArea', 'long_help' => 'TextArea' ); $MenuBase = "SELECT choice from menu where table_name = 'help' "; $Menu = array( "help_type" => "$MenuBase AND field_name = 'help_type'", "language" => "$MenuBase AND field_name = 'language'" ); // Display exceptions from default tdcs centered display table cell $JustifyCss = array( 'summary', 'tds' // small left justified ); //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ spew_header($FMT); if (array_key_exists('Action', $_REQUEST)) { echo "
\n";			// DEVONLY
		print_r($_REQUEST);		// DEVONLY
		echo "
\n"; // DEVONLY //---------------------------------------------------------------------- // Insert New Entry //---------------------------------------------------------------------- if ($_REQUEST['Action'] == "Insert New Entry" ) { // Get list of fields for this table $fieldlabels = get_field_labels('help','help',$JJNCFG['DBNAME']); $fields = array_keys($fieldlabels); // Eliminate all keys that have invalid answers foreach ($fields as $f) { $altkey = "NEW_" . $f; if (in_array($_REQUEST[$f], $InValidChoice)) { unset ($_REQUEST[$f]); } if (in_array($_REQUEST[$altkey], $InValidChoice)) { unset ($_REQUEST[$altkey]); }else{ if ( isset($_REQUEST[$altkey])){ $_REQUEST[$key] = $_REQUEST[$altkey]; unset ($_REQUEST[$altkey]); } } } // Delete auto_increment primary keys unset ($goodfields['help_id']); // Requred fields gauntlet foreach ($RequiredField as $key => $val) { if (! array_key_exists($key, $goodfields)) { $err .= '
  • Please ' . $RequiredField[$key] . '.
  • '; } } if ( $err ) { echo "
    \n"; echo "

    Incomplete Information

    \n"; echo "\n"; echo "
      $err
    \n"; echo "\n"; echo "
    \n"; spew_footer($FMT); exit; } $sql = 'INSERT INTO help ('; foreach ($fields as $f) { if (isset($_REQUEST[$f] )){ $sql .= $f . ','; } } foreach ($fields as $f) { if (isset($_REQUEST[$f] )){ $val = $dbh->quote($_REQUEST[$f]); $sql2 .= $val . ','; } } //chop($sql); $finalsql = rtrim($sql, ",") . ') VALUES (' . rtrim($sql2, ",") . ")"; echo "

    $finalsql

    \n"; //DEBUG $result = $dbh->query($finalsql); echo "
    \n"; echo "

    Record successfully added

    \n"; echo "
    \n"; } //---------------------------------------------------------------------- // Update Existing Entry //---------------------------------------------------------------------- if ($_REQUEST['Action'] == "Update" ) { if (! array_key_exists('help_id', $_REQUEST)) { die ("No Help record Id Set") ; }else{ $help_id = $_REQUEST['help_id']; } if (! is_numeric($help_id)){ die ("No Help record id is non numeric in update function") ; } $dbh = jjn_pdo_connect(); // Get list of fields for this table $fieldlabels = get_field_labels('help','help',$JJNCFG['DBNAME']); $fields = array_keys($fieldlabels); print '
    ';	// DEBUG DEVONLY
    			print htmlspecialchars(print_r($fieldlabels), ENT_QUOTES);	// DEBUG DEVONLY
    			print '
    '; // DEBUG DEVONLY // // Query Original for comparision, only update deltas // $sql = "SELECT * from help WHERE help_id = " . $dbh->quote($help_id); $result = $dbh->query($sql); echo "

    $sql

    \n"; // DEVONLY $Original = array(); $Original = $result->fetch(PDO::FETCH_ASSOC); // // Eliminate all keys that have invalid answers // foreach ($fields as $f) { $altkey = "NEW_" . $f; if ( isset($_REQUEST[$altkey])){ if (!in_array($_REQUEST[$altkey], $InValidChoice)) { $_REQUEST[$key] = $_REQUEST[$altkey]; unset($_REQUEST[$altkey]); } } if ( in_array($_REQUEST[$f], $InValidChoice) ) { unset ($_REQUEST[$f]); } } $sql = 'UPDATE help SET '; $sqlentry = array (); $modcnt = count($sqlentry); echo "

    Initial modcount: $modcnt

    \n"; //DEBUG foreach ($fields as $f) { if ( isset($_REQUEST[$f]) ){ if ( $Original[$f] != $_REQUEST[$f] ){ echo "
    Different in $f: $_REQUEST[$f]\n"; // DEVONLY $val = $dbh->quote($_REQUEST[$f]); $sqlentry[] = $f . " = " . $val ; } } } $modcnt = count($sqlentry); echo "

    Final modcount: $modcnt

    \n"; //DEBUG if ( $modcnt != 0) { $sql .= implode (', ', $sqlentry); $sql .= " WHERE help_id = " . $dbh->quote($help_id); echo "

    $sql

    \n"; //DEBUG $result = $dbh->query($sql); echo "

    Update successful

    \n"; }else{ echo "

    No changes detected.

    \n"; } $_REQUEST['Action'] = "View"; $_REQUEST['help_id'] = $help_id; } //---------------------------------------------------------------------- // Targeted Help Display //---------------------------------------------------------------------- if ($_REQUEST['Action'] == "Help") { global $JJNCFG; $dbh = jjn_pdo_connect(); // // Get Field Labels // $fieldlabels = get_field_labels('help','help',$JJNCFG['DBNAME']); $fields = array_keys($fieldlabels); // // Build Query // $sql = 'SELECT * FROM help '; $where = array(); foreach ($fields as $f) { if (array_key_exists($f, $_REQUEST)) { if (isset($_REQUEST[$f])) { if (!in_array($_REQUEST[$f], $InValidChoice)) { $where[] = $f . " = " . $dbh->quote($_REQUEST[$f]); } } } } if ( count($where) ) { $sql .= ' WHERE ' . implode(' AND ', $where); } echo "

    Help: $sql

    \n"; // DEVONLY $result = $dbh->query($sql); $count = $result->rowCount(); echo "

    Count is $count

    \n"; // DEVONLY if ( $count == 1 ) { $row = $result->fetch(PDO::FETCH_ASSOC); echo "
    \n"; // DEVONLY
                    print_r($row);  // DEVONLY
                    echo "
    \n"; // DEVONLY echo "
    \n"; echo "

    $row[summary]

    \n"; echo "\n"; echo "\n"; echo "\n"; //echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "
    Quick Help
    "; echo ""; echo "$row[short_help]
    "; echo "
    Detailed Help
    "; echo "$row[long_help]
    "; echo "
    \n"; echo "
    \n"; }else{ $_REQUEST['Action'] = "Query"; } }//if ($_REQUEST['Action'] == "Help")) { //---------------------------------------------------------------------- // Query or List //---------------------------------------------------------------------- if ($_REQUEST['Action'] == "Query" || $_REQUEST['Action'] == "List") { if ( $_SESSION['access'] >= $HELPCFG['ADMINLEVEL'] ) { spew_query_form(); } $dbh = jjn_pdo_connect(); $fieldlabels = get_field_labels('help','help',$JJNCFG['DBNAME']); $fields = array_keys($fieldlabels); $sql = 'SELECT * FROM help '; $where = array(); foreach ($fields as $f) { if (array_key_exists($f, $_REQUEST)) { $val = $_REQUEST[$f]; if (in_array($val, $InValidChoice)){ unset($val) ; } if ( isset($val) ) { $val = $dbh->quote($_REQUEST[$f]); if ( isset($val) ) { $where[] = $f . " = " . $val ; } } } } if ( count($where) ) { $sql .= ' WHERE ' . implode(' AND ', $where); } echo "

    $sql

    \n"; //DEBUG DEVONLY $result = $dbh->query($sql); $count = $result->rowCount(); echo "

    Record count is $count

    \n"; // DEVONLY $COLCOUNT = count($SHOW); echo "

    Default Col count is $COLCOUNT

    \n"; // DEVONLY $COLCOUNT += 2; echo "

    Col count is $COLCOUNT

    \n"; // DEVONLY echo "
    \n"; echo "\n"; echo "\n"; echo "\n"; foreach ($ALLFIELD as $f) { if (in_array($f, $SHOW)) { echo "\n"; } } while ($row = $result->fetch(PDO::FETCH_ASSOC)){ echo "\n"; // Edit echo "\n"; // Show echo "\n"; // Record entry row foreach ($ALLFIELD as $f) { $display = $row[$f]; // Re-Map foreign key table lookups //if ($f == 'contact_id'){ //$contact_id = $row[$f]; //$display = $People[$contact_id]; //} if (in_array($f, $SHOW)) { $css = "tdcs"; if (array_key_exists($f, $JustifyCss)) { $css = $JustifyCss[$f]; } echo "\n"; } } } echo "
    EditView$fieldlabels[$f]
    "; echo ""; echo ""; echo ""; echo ""; if (in_array($f, $LINK)) { echo ""; echo "$display\n"; }else{ echo "$display\n"; } echo "
    \n"; echo "
    \n"; echo "


    \n"; }//if ($_REQUEST['Action'] == "Query")) { //---------------------------------------------------------------------- // New Entry Form //---------------------------------------------------------------------- if ($_REQUEST['Action'] == "New" ) { $People = array(); $peoplesql = " SELECT people_id, full_name FROM people "; if (isset($_SESSION['organization_id'] ) ){ $peoplesql .= " WHERE organization_id = '$_SESSION[organization_id]'"; } echo "

    $peoplesql

    \n"; // DEVONLY $People = get_menu_array($peoplesql); echo "
    \n"; echo "
    \n"; echo "\n"; $fieldlabels = get_field_labels('help','help',$JJNCFG['DBNAME']); unset($fieldlabels['help_id']); foreach ($fieldlabels as $fieldname => $val) { echo "\n"; echo "\n"; } echo "
    $val"; if (array_key_exists($fieldname, $FieldType)) { if ( $FieldType[$fieldname] == "Menu" ) { $menusql = $Menu[$fieldname]; $menuitems = get_menu($menusql); sort($menuitems); spew_select_menu($fieldname, $_REQUEST[$fieldname],$_REQUEST[$fieldname],$menuitems); if (in_array($fieldname, $EXTEND)) { echo "-OR- "; } } if ($FieldType[$fieldname] == "People" ) { spew_select_hash_menu($fieldname, $_REQUEST[$fieldname],$_REQUEST[$fieldname],$People); } if ($FieldType[$fieldname] == "MenuArray" ) { $menusql = $Menu[$fieldname]; $menuitems = get_menu_array($menusql); spew_select_hash_menu($fieldname, $_REQUEST[$fieldname],$_REQUEST[$fieldname],$menulist); if (in_array($fieldname, $EXTEND)) { echo "-OR- "; } } if ($FieldType[$fieldname] == "LongText" ) { echo ""; } if ($FieldType[$fieldname] == "TextArea" ) { echo ""; } }else{ echo ""; } echo "
    \n"; if ($_SESSION['access'] >= $HELPCFG['ADMINLEVEL'] ) { echo "\n"; }else{ echo "

    You must have access level of $HELPCFG[ADMINLEVEL] to add or update

    \n"; } echo "
    \n"; echo "
    \n"; } //---------------------------------------------------------------------- // Edit //---------------------------------------------------------------------- if ($_REQUEST['Action'] == "Edit") { if (! array_key_exists('help_id', $_REQUEST)) { die ("No help record Id Set") ; }else{ $help_id = $_REQUEST['help_id']; if (! is_numeric($help_id)){ die ("Help Id is non numeric for edit function, exiting.") ; } } $People = array(); $peoplesql = " SELECT people_id, full_name FROM people "; if (isset($_SESSION['organization_id'] ) ){ $peoplesql .= " WHERE organization_id = '$_SESSION[organization_id]'"; } echo "

    $peoplesql

    \n"; // DEVONLY $People = get_menu_array($peoplesql); $dbh = jjn_pdo_connect(); echo "
    \n"; $sql = 'SELECT * FROM help WHERE help_id = ' . $dbh->quote($_REQUEST[help_id]); echo "

    $sql

    \n"; // DEVONLY $result = $dbh->query($sql); $count = $result->rowCount(); echo "

    RowCount: $count

    \n"; // DEVONLY $row = $result->fetch(PDO::FETCH_ASSOC); echo "
    \n"; echo "
    \n"; echo "\n"; $fieldlabels = get_field_labels('help','help',$JJNCFG['DBNAME']); foreach ($fieldlabels as $fieldname => $val) { echo "\n"; echo "\n"; } echo "
    $val"; if (array_key_exists($fieldname, $FieldType)) { if ( $FieldType[$fieldname] == "Menu" ) { $menusql = $Menu[$fieldname]; $menuitems = get_menu($menusql); sort($menuitems); spew_select_menu($fieldname, $val,'All',$menuitems); if (in_array($fieldname, $EXTEND)) { echo "-OR- "; } } if ($FieldType[$fieldname] == "MenuArray" ) { $menusql = $Menu[$fieldname]; $menuitems = get_menu_array($menusql); spew_select_hash_menu($fieldname, $row[$fieldname],'All',$menulist); } if ($FieldType[$fieldname] == "People" ) { spew_select_hash_menu($fieldname, $_REQUEST[$fieldname],$_REQUEST[$fieldname],$People); } if ($FieldType[$fieldname] == "LongText" ) { echo "
    "; } if ($FieldType[$fieldname] == "TextArea" ) { echo ""; } }else{ if (in_array($fieldname, $NoEdit)) { echo "$row[$fieldname]
    "; }else{ echo "
    "; } } echo "
    \n"; echo "\n"; echo "\n"; echo "
    \n"; echo "
    \n"; }//if ($_REQUEST['Action'] == "Edit") //---------------------------------------------------------------------- // View //---------------------------------------------------------------------- if (($_REQUEST['Action'] == "View" )) { if (! array_key_exists('help_id', $_REQUEST)) { die ("No help record Id Set") ; }else{ $help_id = $_REQUEST['help_id']; if (! is_numeric($help_id)){ die ("Help Id is non numeric for edit function, exiting.") ; } } $dbh = jjn_pdo_connect(); $sql = "SELECT h.*, p.full_name FROM help h, people p "; $sql .= " WHERE help_id = " . $dbh->quote($help_id); $sql .= " AND h.contact_id = p.people_id "; echo "

    View: $sql

    \n"; // DEVONLY $result = $dbh->query($sql); $row = $result->fetch(PDO::FETCH_ASSOC); echo "
    \n"; echo "
    \n"; echo "\n"; $fieldlabels = get_field_labels('help','help',$JJNCFG['DBNAME']); foreach ($fieldlabels as $fieldname => $val) { $display = $row[$fieldname]; if ($fieldname == 'contact_id'){ $display = $row['full_name']; } echo "\n"; echo "\n"; echo "\n"; } echo "
    $val"; echo "$display
    "; echo "
    \n"; echo "\n"; // SECURITY echo "\n"; echo "\n"; echo "
    \n"; echo "
    \n"; }//if ($_REQUEST['Action'] == "View" ) //---------------------------------------------------------------------- // End of Action Routing //---------------------------------------------------------------------- }else{ spew_query_form(); } spew_footer($FMT); //---------------------------------------------------------------- // Function spew_query_form //---------------------------------------------------------------- function spew_query_form() { global $JJNCFG; $dbh = jjn_pdo_connect(); $list = array(); echo "
    \n"; echo "
    \n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; // Category echo "\n"; // Table Name echo "\n"; // Application echo "\n"; // Module echo "\n"; // End Table echo "\n"; echo "
    TopicTableApplicationModule
    \n"; $sql = "SELECT DISTINCT topic from help"; $list = get_menu($sql); sort ($list); spew_select_menu('topic','','All',$list); echo "\n"; $sql = "SELECT DISTINCT table_name from help"; $list = get_menu($sql); sort ($list); spew_select_menu('table_name','','All',$list); echo "\n"; $sql = "SELECT distinct application from help"; $list = get_menu($sql); sort ($list); spew_select_menu('application','','All',$list); echo "\n"; $sql = "SELECT distinct module from help"; $list = get_menu($sql); sort ($list); spew_select_menu('module','','All',$list); echo "
    \n"; // End Form echo "\n"; echo "
    \n"; echo "
    \n"; } ?>