"New Song Suggestion/Request", 'TITLE' => "New Song Suggestion/Request", 'MODULENAME' => "newsong.phpx", 'NAV1' => "INFO" // Level 1 menu navigation group ); //------------------------------------------------------------------------ // Local configuration parameters //------------------------------------------------------------------------ global $SONGCFG; //------------------------------------------------------------------------ // Database Fields //------------------------------------------------------------------------ $ALLFIELD = array( 'song_title', 'song_artist', 'song_status', 'song_bpm', 'song_location', 'song_performer', 'song_year', 'youtube_url', 'song_notes', ); $NEWFIELD = array( 'song_title', 'song_artist', 'song_status', 'song_performer', 'song_year', 'youtube_url', 'song_notes', ); // Fields that are from a Menu Picklist that can have new members // $EXTEND = array( ); // // Required for New Entry // $RequiredField = array( 'song_title' => 'enter song name', ); // // Global query choices // $InValidChoice = array( 'All', '', ' ', 'None', 'Choose' ); $FieldType = array( 'song_artist' => 'LongText', 'song_title' => 'LongText', 'song_performer' => 'LongText', 'youtube_url' => 'LongText', 'song_notes' => 'TextArea' ); $BASE = "SELECT choice, description FROM menu WHERE table_name = 'song' AND "; $Menu = array( "gender" => "$BASE field_name = 'gender' ORDER BY choice", ); //------------------------------------------------------------------------ // BEGIN Program //------------------------------------------------------------------------ spew_header($FMT); // // Set default screen to entry form // if (!array_key_exists('Action', $_REQUEST)) { $_REQUEST['Action'] = 'New'; } if (array_key_exists('Action', $_REQUEST)) { //---------------------------------------------------------------------- // Submit Suggestion //---------------------------------------------------------------------- if ( $_REQUEST['Action'] == "Submit Suggestion" ) { $dbh = jjn_pdo_connect(); echo "
\n";			// DEVONLY
			echo "
Submit Suggestion:\n"; // DEVONLY print_r($_REQUEST); // DEVONLY echo "
\n"; // DEVONLY $pcnt = count($_POST); $rcnt = count($_REQUEST); echo "

Request Count is greater that one, $rcnt

\n"; // DEVONLY echo "

Post Count is greater that one, $pcnt

\n"; // DEVONLY echo "

Session of captcha_keystring is $_SESSION[captcha_keystring]

\n"; // DEVONLY echo "

Post of keystring is $_POST[keystring]

\n"; // DEVONLY echo "

Request of keystring is $_REQUEST[keystring]

\n"; // DEVONLY // // CAPTCHA // if( count($_REQUEST) > 1 ){ if(isset($_SESSION['captcha_keystring']) && $_SESSION['captcha_keystring'] === $_REQUEST['keystring']){ echo "

Excellent, you are a human!

"; }else{ echo "

The numbers from the captcha box do match those in the image."; echo "
Please press the back button and try again.\n"; echo "

"; } }else{ echo "

No Data

"; spew_footer($FMT); exit; } // // Get list of fields for this table // $fieldlabel = get_field_labels('song','song',$JJNCFG['DBNAME']); $fields = array_keys($fieldlabel); $fieldlabel['song_notes'] = 'Types of Dances I Do to This Song'; // // Define default values // $Default = array ( 'song_status' => 'Suggested', ); echo "
\n";		// DEVONLY
			echo "Default:\n";	// DEVONLY
			print_r($Default);	// DEVONLY
			echo "
\n"; // DEVONLY $NoEntry = array( ); // // Setup default values // foreach ($Default as $key => $val ) { if ( ! isset( $_REQUEST[$key]) ) { $_REQUEST[$key] = $val; echo "
Setting default of $key to $val\n"; // DEVONLY } } // // Eliminate all keys that have invalid answers // foreach ($fields as $f) { if (in_array($_REQUEST[$f], $InValidChoice)) { echo "

Unsetting invalid entry for $f, $_REQUEST[$f]

\n"; // DEVONLY unset ($_REQUEST[$f]); } } // // Required fields gauntlet on input // foreach ( $RequiredField as $key => $val) { if (! array_key_exists($key, $_REQUEST)) { $err .= '
  • Please ' . $RequiredField[$key] . '.
  • '; } } if ( $err ) { echo "
    \n"; echo "

    Incomplete Information

    \n"; echo "\n"; echo "
    "; echo "Please click the back button of the browser and ensure\n"; echo " all the information requested below is provided,\n"; echo " then fill out the captcha image field and hit Submit Suggestion\n"; echo " button at the bottom of the form.\n"; echo "
      $err
    \n"; echo "\n"; echo "
    \n"; spew_footer($FMT); exit; } $Data = array(); foreach ($ALLFIELD as $f) { echo "

    NewField Index: $f

    \n"; // DEVONLY if ( array_key_exists($f, $_REQUEST)) { $val = $_REQUEST[$f]; if (isset($val)){ $Data[$f] = $dbh->quote($val); } } } echo "
    \n";					// DEVONLY
    			echo "
    Data:\n"; // DEVONLY print_r($Data); // DEVONLY echo "
    \n"; // DEVONLY //--------------------------------------- // INSERT Into Song //--------------------------------------- // $sql = "INSERT INTO song ("; $sql .= implode(', ', array_keys($Data) ); $sql .= ") VALUES ("; $sql .= implode(', ', array_values($Data) ); $sql .= ")"; echo "

    $sql

    \n"; // DEVONLY $dbh->query($sql); $_REQUEST['song_id'] = $song_id = $dbh->lastInsertId() ; echo "

    Returned Song ID of $_REQUEST[song_id]\n"; // DEVONLY echo "

    \n"; echo "

    Thank you for your song suggestion!

    \n"; echo "

    I appreciate your input to improve music and dancing for my community.

    \n"; echo "
    \n"; spew_footer($FMT); exit; } //---------------------------------------------------------------------- // New Entry Form //---------------------------------------------------------------------- if ($_REQUEST['Action'] == "New") { $menulist = array(); $dbh = jjn_pdo_connect(); $Default = array ( 'song_type' => 'Subscriber', 'home_state' => 'CA', ); // Blurb echo "
    \n"; echo "\n"; echo "\n"; echo "
    \n"; echo "
      \n"; echo "
    1. Fill out desired fields in below form.
    2. \n"; echo "
    3. Enter any notes about what dances you like for that song or groups/places that play it in the notes section.
    4. \n"; echo "
    5. Enter the four digits from the colored image into the field below it.
    6. \n"; echo "
    7. Click Submit Suggestion button at bottom.
    8. \n"; echo "
    \n"; echo "
    \n"; $fieldlabel = get_field_labels('song','song',$JJNCFG['DBNAME']); echo "
    \n"; echo "\n"; echo "\n"; foreach ($NEWFIELD as $fieldname ) { $val = $fieldlabel[$fieldname]; echo "\n"; echo "\n"; echo "\n"; } echo "
    What Is Your Song Suggestion?
    "; echo ""; echo "$val"; if ( isset($RequiredField[$fieldname]) ){ echo ' * '; } echo ""; $what = $Default[$fieldname]; $choose = 'Choose'; if (!empty($_REQUEST[$fieldname])) { // Exists if (!in_array($_REQUEST[$fieldname], $InValidChoice)) { // Exists and Valid $what = $_REQUEST[$fieldname]; $choose = $what; }else{ // Exists and InValid if (isset($Default[$fieldname])){ $what = $Default[$fieldname]; $choose = $what; } } } if (array_key_exists($fieldname, $FieldType)) { if ( $FieldType[$fieldname] == "Menu" ) { $menusql = $Menu[$fieldname]; $menulist = get_menu($menusql); sort($menulist); spew_select_menu($fieldname, $what,$choose,$menulist); if (in_array($fieldname, $EXTEND)) { echo "-OR- "; } } if ($FieldType[$fieldname] == "MenuArray" ) { $menusql = $Menu[$fieldname]; $menulist = get_menu_array($menusql); $menulist['Choose'] = 'Choose'; spew_select_hash_menu($fieldname, $what,$choose,$menulist); } if ($FieldType[$fieldname] == "TextArea" ) { echo "\n"; } if ($FieldType[$fieldname] == "LongText" ) { echo ""; } }else{ echo ""; } echo "
    \n"; echo "

    I prefer to work with humans,"; echo "
    please enter the numbers shown in the below 'captcha' image into the box below:

    \n"; echo "

    \"Captcha

    \n"; echo "

    \n"; echo "\n"; echo "
    \n"; echo "
    \n"; }//End if ($_REQUEST['Action'] == "New" ) //---------------------------------------------------------------------- // END 'Action' Processing Options //---------------------------------------------------------------------- } spew_footer($FMT); //---------------------------------------------------------------- // END FUNCTIONS //---------------------------------------------------------------- ?>