"Subscribe to Jumping Jerry Productions", 'TITLE' => "Subscribe to Jumping Jerry Productions", 'MODULENAME' => "subscribe.phpx", 'NAV1' => "INFO" // Level 1 menu navigation group ); //------------------------------------------------------------------------ // Local configuration parameters //------------------------------------------------------------------------ $PEOPLECFG = array ( 'PW_VALID_DAYS' => '5', // Password expiration horizon ); global $PEOPLECFG; //------------------------------------------------------------------------ // Database Fields //------------------------------------------------------------------------ $NEWFIELD = array( 'first_name', 'last_name', 'email_1', 'birth_year', 'home_zip', ); // Fields that are from a Menu Picklist that can have new members // $EXTEND = array( ); // // Required for New Entry // $RequiredField = array( 'first_name' => 'enter your first name', 'last_name' => 'enter your last name', 'email_1' => 'enter your primary email', ); // // Global query choices // $InValidChoice = array( 'All', '', ' ', 'None', 'Choose' ); $FieldType = array( 'gender' => 'MenuArray', ); $BASE = "SELECT choice, description FROM menu WHERE table_name = 'people' 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)) { //---------------------------------------------------------------------- // Subscribe Me // Data Integrity check for initial form // Check database and list possible duplicates and ask for confirmation //---------------------------------------------------------------------- if ( $_REQUEST['Action'] == "Subscribe Me" ) { $dbh = jjn_pdo_connect(); echo "
\n";			// DEVONLY
			echo "
Subscribe Me:\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 // // Get list of fields for this table // $fieldlabel = get_field_labels('people','people',$JJNCFG['DBNAME']); $fields = array_keys($fieldlabel); $fieldlabel['email_1'] = 'Email'; // // Define default values // $Default = array ( 'home_country' => 'US', 'home_state' => 'CA', 'people_type' => 'Subscriber', ); echo "
\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 } } // // Unsloppy name entry so login is spaceless // $_REQUEST['last_name'] = trim($_REQUEST['last_name']); $_REQUEST['first_name'] = trim($_REQUEST['first_name']); $_REQUEST['nickname'] = trim($_REQUEST['nickname']); // // Unsloppy proper noun entries to be mixed case // $_REQUEST['last_name'] = ucfirst($_REQUEST['last_name'] ); $_REQUEST['first_name'] = ucfirst($_REQUEST['first_name']); $_REQUEST['nickname'] = ucfirst($_REQUEST['nickname']); $_REQUEST['home_city'] = ucfirst($_REQUEST['home_city']); // // 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]); } } // // No redundant email addresses (exception: 'tbd') // $_REQUEST['email_1'] = strtolower($_REQUEST['email_1']); $sql = "SELECT distinct email_1 from people WHERE email_1 != 'tbd'"; echo "

$sql

\n"; // DEVONLY $ExistingEmails = array(); $ExistingEmails = get_menu($sql); if (in_array($_REQUEST['email_1'], $ExistingEmails)) { echo "

Deleting existing duplicate email $_REQUEST[email_1]

\n"; // DEVONLY unset($_REQUEST['email_1']); $RequiredField['email_1'] = "enter a unique email, this email has already been registered"; } // // 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; } $Data = array(); foreach ($NEWFIELD as $f) { echo "

NewField Index: $f

\n"; // DEVONLY // Default set to input, run gauntlet to kill $val = $_REQUEST[$f]; if ( array_key_exists($f, $_REQUEST)) { // // Pretty-ize phone number // if (preg_match('/_phone$/', $f)){ $val = format_phone_number($_REQUEST[$f]); } // // Unset $val if email invalid unless it is 'tbd' // if (preg_match('/^email/', $f)){ echo "

Field [$f] matches email...

\n"; // DEVONLY if (preg_match("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$^", $_REQUEST[$f])){ echo "

Field [$f] matches valid email...

\n"; // DEVONLY }else{ if ( $val == 'TBD' || $val == 'tbd' ){ echo "

Field [$f] fails valid email and has tbd exemption

\n"; // DEVONLY }else{ echo "

Field [$f] fails valid email...

\n"; // DEVONLY unset($_REQUEST[$f]); unset($val); $RequiredField[$f] = "enter valid email address"; } } } echo "

Data for index [$f] is [$val]

\n"; // DEVONLY } if (isset($val)){ $Data[$f] = $dbh->quote($val); } } if ( isset($_REQUEST['nickname']) && $_REQUEST['nickname'] != ''){ $Data['full_name'] = $dbh->quote($_REQUEST['nickname'] . ' ' . $_REQUEST['last_name']); }else{ $Data['full_name'] = $dbh->quote($_REQUEST['first_name'] . ' ' . $_REQUEST['last_name']); } // // Post processing Required fields gauntlet // foreach ( $RequiredField as $key => $val) { if (! array_key_exists($key, $Data)) { $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 Subscribe Me\n"; echo " button at the bottom of the form.\n"; echo "
      $err
    \n"; echo "\n"; echo "
    \n"; spew_footer($FMT); exit; } echo "
    \n";					// DEVONLY
    			echo "
    Data:\n"; // DEVONLY print_r($Data); // DEVONLY echo "
    \n"; // DEVONLY //--------------------------------------- // INSERT Into People //--------------------------------------- // $sql = "INSERT INTO people ("; $sql .= implode(', ', array_keys($Data) ); $sql .= ") VALUES ("; $sql .= implode(', ', array_values($Data) ); $sql .= ")"; echo "

    $sql

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

    Returned People ID of $_REQUEST[people_id]\n"; // DEVONLY echo "

    \n"; echo "

    You're subscribed!

    \n"; echo "
    \n"; // // What dances // foreach ( $_REQUEST as $key => $val) { if ( preg_match('/^X_/', $key) ){ list($junk, $id) = explode('_', $key); $sql = "INSERT INTO mydance (dance_id, people_id) VALUES ("; $sql .= " $id, $people_id)"; echo "

    $sql

    \n"; // DEVONLY run_sql($sql); } } $_REQUEST['Action'] = 'Thank You'; } //---------------------------------------------------------------------- // New Entry Form //---------------------------------------------------------------------- if ($_REQUEST['Action'] == "New") { $menulist = array(); $dbh = jjn_pdo_connect(); $Default = array ( 'people_type' => 'Subscriber', 'home_state' => 'CA', ); // Blurb echo "
    \n"; echo "\n"; echo "\n"; echo "
    \n"; echo "
      \n"; echo "
    1. Fill out all fields in left side of form.
    2. \n"; echo "
    3. Enter the four digits in the colored image into the field below it
    4. \n"; echo "
    5. Click Subscribe Me button at bottom.
    6. \n"; echo "
    \n"; echo "
    \n"; //echo "

     

    \n"; $fieldlabel = get_field_labels('people','people',$JJNCFG['DBNAME']); $fieldlabel['email_1'] = 'Email'; echo "
    \n"; // Outer Table echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "$row[dance_name]
    \n"; } echo "\n"; echo "
    Register YourselfCheck Your Favorite Dances
    \n"; // Column 1 echo "

    Asterix (*) designates required entry

    \n"; echo "\n"; foreach ($NEWFIELD as $fieldname ) { $val = $fieldlabel[$fieldname]; echo "\n"; echo "\n"; echo "\n"; } echo "
    "; 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 "
    \n"; // Right Column $sql = "SELECT * from dance"; $sql .= " ORDER BY dance_style desc, dance_name"; $result = $dbh->query($sql); while ($row = $result->fetch(PDO::FETCH_ASSOC) ) { $did = $row['dance_id']; $style = $row['dance_style']; if ( isset ($oldstyle) && $style != $oldstyle){ echo "
    \n"; } $oldstyle = $style; //echo "
    $row[dance_name]
    \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" ) //---------------------------------------------------------------------- // Thank You //---------------------------------------------------------------------- if ($_REQUEST['Action'] == "Thank You") { echo "
    \n"; echo "\n"; echo "\n"; echo "
    \n"; echo "

    Thank your for subscribing!\n"; echo "
    We will send you emails about
    dance events your may be interested in.\n"; echo "

    \n"; echo "(Each email will have unsubscribe instructions.)\n"; echo "
    \n"; echo "
    \n"; echo "\n"; spew_footer($FMT); exit; }//if ($_REQUEST['Action'] == "Thank You") //---------------------------------------------------------------------- // END 'Action' Processing Options //---------------------------------------------------------------------- } spew_footer($FMT); //---------------------------------------------------------------- // END FUNCTIONS //---------------------------------------------------------------- ?>