"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 "\n"; // DEVONLY $pcnt = count($_POST); $rcnt = count($_REQUEST); echo "
Subscribe Me:\n"; // DEVONLY print_r($_REQUEST); // DEVONLY 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 "
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 "
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 .= '";
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 "
|
\n"; // 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 "
Data:\n"; // DEVONLY print_r($Data); // DEVONLY 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 "
$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"; $fieldlabel = get_field_labels('people','people',$JJNCFG['DBNAME']); $fieldlabel['email_1'] = 'Email'; echo "\n"; echo "
\n";
echo "Thank your for subscribing!\n";
echo "\n";
echo "(Each email will have unsubscribe instructions.)\n";
echo " |