From 7b64d0c49495ed4fbda90d0a39495b3e35f44383 Mon Sep 17 00:00:00 2001 From: Jonathan Rosenbaum Date: Wed, 11 Feb 2015 01:55:38 +0000 Subject: [PATCH] Spiffs up contact_and_edit, adding error correction and required waiver. 1). Next step will be an opt-in/out to mailman. 2). Originally this program was using google lists, but there are too many steps for users involved. --- Connections/database_functions.php | 9 + .../contact_add_edit_confirmation.html | 0 ...ontact_add_edit_confirmation_frameset.html | 0 ...act_add_edit_confirmation_framesetphp.html | 0 .../contact_add_edit_confirmation_iframe.php | 0 .../contact_add_edit_newsletter.php | 0 contact_add_edit.php | 220 +++++++++--------- css/contacts.css | 7 + include_header.html | 2 + js/contact.js | 122 ++++++++++ js/transaction.js | 21 +- json/transaction.php | 15 +- 12 files changed, 269 insertions(+), 127 deletions(-) rename contact_add_edit_confirmation.html => attic/contact_add_edit_confirmation.html (100%) rename contact_add_edit_confirmation_frameset.html => attic/contact_add_edit_confirmation_frameset.html (100%) rename contact_add_edit_confirmation_framesetphp.html => attic/contact_add_edit_confirmation_framesetphp.html (100%) rename contact_add_edit_confirmation_iframe.php => attic/contact_add_edit_confirmation_iframe.php (100%) rename contact_add_edit_newsletter.php => attic/contact_add_edit_newsletter.php (100%) create mode 100644 css/contacts.css create mode 100644 js/contact.js diff --git a/Connections/database_functions.php b/Connections/database_functions.php index a038c48..9f292c7 100644 --- a/Connections/database_functions.php +++ b/Connections/database_functions.php @@ -236,6 +236,15 @@ function list_distinct_shop_years($form_name = "none", $default_value = ""){ generate_list($querySQL,$list_value,$list_text,$form_name, $default_value); } + +function list_history($object) { +/* require_once('../php-console/src/PhpConsole/__autoload.php'); + $handler = PhpConsole\Handler::getInstance(); + $handler->start(); + $handler->debug($object);*/ + +} + // ##################### // Date/Time functions diff --git a/contact_add_edit_confirmation.html b/attic/contact_add_edit_confirmation.html similarity index 100% rename from contact_add_edit_confirmation.html rename to attic/contact_add_edit_confirmation.html diff --git a/contact_add_edit_confirmation_frameset.html b/attic/contact_add_edit_confirmation_frameset.html similarity index 100% rename from contact_add_edit_confirmation_frameset.html rename to attic/contact_add_edit_confirmation_frameset.html diff --git a/contact_add_edit_confirmation_framesetphp.html b/attic/contact_add_edit_confirmation_framesetphp.html similarity index 100% rename from contact_add_edit_confirmation_framesetphp.html rename to attic/contact_add_edit_confirmation_framesetphp.html diff --git a/contact_add_edit_confirmation_iframe.php b/attic/contact_add_edit_confirmation_iframe.php similarity index 100% rename from contact_add_edit_confirmation_iframe.php rename to attic/contact_add_edit_confirmation_iframe.php diff --git a/contact_add_edit_newsletter.php b/attic/contact_add_edit_newsletter.php similarity index 100% rename from contact_add_edit_newsletter.php rename to attic/contact_add_edit_newsletter.php diff --git a/contact_add_edit.php b/contact_add_edit.php index ec38eb5..2abec88 100644 --- a/contact_add_edit.php +++ b/contact_add_edit.php @@ -14,7 +14,8 @@ case 'new_error_message': //this is a sample error message. insert error case h $error_message = ''; break; default: - $error_message = 'Enter or Update Contact Information - Yellow Bike uses this information soely to support the project and it is kept entirely private. When we apply for grants it helps us to know a little bit about our shop users. Thanks for supporting The Yellow Bike Project.

'; + $error_message = 'Enter or Update Contact Information - + Thank-you for supporting Positive Spin.

'; break; } @@ -45,40 +46,37 @@ if($_GET['contact_id'] == 'new_contact'){ $contact_id_entry = -1; } -$editFormAction = $_SERVER['PHP_SELF'] . "?contact_id={$contact_id}&shop_id={$shop_id}"; +$editFormAction = "?contact_id={$contact_id}&shop_id={$shop_id}"; if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) { - $updateSQL = sprintf("UPDATE contacts SET first_name=%s, middle_initial=%s, last_name=%s, email=%s, DOB=%s, receive_newsletter=%s, phone=%s, address1=%s, address2=%s, city=%s, `state`=%s, zip=%s, pass=ENCODE(%s,'yblcatx') WHERE contact_id=%s", - GetSQLValueString($_POST['first_name'], "text"), - GetSQLValueString($_POST['middle_initial'], "text"), - GetSQLValueString($_POST['last_name'], "text"), - GetSQLValueString($_POST['email'], "text"), - GetSQLValueString($_POST['DOB'], "date"), - GetSQLValueString($_POST['list_yes_no'], "int"), - GetSQLValueString($_POST['phone'], "text"), - GetSQLValueString($_POST['address1'], "text"), - GetSQLValueString($_POST['address2'], "text"), - GetSQLValueString($_POST['city'], "text"), - GetSQLValueString($_POST['state'], "text"), - GetSQLValueString($_POST['zip'], "text"), - GetSQLValueString($_POST['password'], "text"), - GetSQLValueString($_POST['contact_id'], "int")); - - mysql_select_db($database_YBDB, $YBDB); - $Result1 = mysql_query($updateSQL, $YBDB) or die(mysql_error()); + + $updateSQL = sprintf("UPDATE contacts SET first_name=%s, middle_initial=%s, last_name=%s, email=%s, + DOB=%s, receive_newsletter=%s, phone=%s, address1=%s, address2=%s, city=%s, + `state`=%s, zip=%s, pass=ENCODE(%s,'yblcatx') WHERE contact_id=%s", + GetSQLValueString($_POST['first_name'], "text"), + GetSQLValueString($_POST['middle_initial'], "text"), + GetSQLValueString($_POST['last_name'], "text"), + GetSQLValueString($_POST['email'], "text"), + GetSQLValueString($_POST['DOB'], "date"), + GetSQLValueString($_POST['list_yes_no'], "int"), + GetSQLValueString($_POST['phone'], "text"), + GetSQLValueString($_POST['address1'], "text"), + GetSQLValueString($_POST['address2'], "text"), + GetSQLValueString($_POST['city'], "text"), + GetSQLValueString($_POST['state'], "text"), + GetSQLValueString($_POST['zip'], "text"), + GetSQLValueString($_POST['password'], "text"), + GetSQLValueString($_POST['contact_id'], "int")); + + mysql_select_db($database_YBDB, $YBDB); + $Result1 = mysql_query($updateSQL, $YBDB) or die(mysql_error()); if ($_POST['contact_id_entry'] == 'new_contact'){ + //navigate back to shop that it came from - - //if there is an email address submitted pass this to google groups signup. Otherwise redirect to shop log. - if ((strpos($_POST['email'], '@') > 0) && ($_POST['list_yes_no'] == 1)) { - $email = $_POST['email']; - $pagegoto = "contact_add_edit_confirmation_iframe.php" . "?shop_id={$shop_id}&new_user_id={$contact_id}&email=$email"; - } else { - $pagegoto = PAGE_SHOP_LOG . "?shop_id={$shop_id}&new_user_id={$contact_id}"; - } - + $pagegoto = PAGE_SHOP_LOG . "?shop_id={$shop_id}&new_user_id={$contact_id}"; header(sprintf("Location: %s", $pagegoto)); + } } @@ -96,100 +94,104 @@ $totalRows_Recordset1 = mysql_num_rows($Recordset1); -
- - - +
Contact_id:
+ + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + - - - + + + - - - + + + - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + +
+ + + + +
First_name:
Middle_initial:
Last_name:
Email:
Date of Birth: - (YYYY-MM-DD)
Phone:
Address1:
+
+
+
Address2:
City:
State:
ZIP:
New Password: -
- Your password keeps others from viewing your personal information.
 
+ +
+

+ I, and my heirs, in consideration of my participation in the Positive Spin Community + Bike Project's Open Workshop hereby release Positive Spin, + its officers, employees and agents, and any other people officially connected with this + organization, from any and all liability for damage to or loss of personal + property, sickness, or injury from whatever source, legal entanglements, imprisonment, + death, or loss of money, which might occur while participating in said event/activity/class. + Specifically, I release Positive Spin from any liability or + responsibility for my personal well-being, condition of tools and equipment provided + and produced thereof, including, but not limited to, bicycles and modes of transportation + produced by participants. The Positive Spin Community Bike Project is a working, + mechanical environment and I am aware of the risks of participation. I hereby state + that I am in sufficient physical condition to accept a rigorous level of physical + activity and exertion, as is sometimes the case when working in a mechanical environment. + I understand that participation in this program is strickly voluntary and I + freely chose to participate. I understand Positive Spin does not provide medical coverage for me. + I verify that I will be responsible for any medical costs I incur as a result of my participation. +

+
I agree + + +

-
+ -

 

-
- Waiver of Liability -
-
-

I, and my heirs, in consideration of my participation in the New Orleans Community - Bike Project's Open Workshop hereby release the New Orleans Community Bike Project, - its officers, employees and agents, and any other people officially connected with this - organization, from any and all liability for damage to or loss of personal - property, sickness, or injury from whatever source, legal entanglements, imprisonment, - death, or loss of money, which might occur while participating in said event/activity/class. - Specifically, I release The New Orleans Community Bike Project from any liability or - responsibility for my personal well-being, condition of tools and equipment provided - and produced thereof, including, but not limited to, bicycles and modes of transportation - produced by participants. The New Orleans Community Bike Project is a working, - mechanical environment and I am aware of the risks of participation. I hereby state - that I am in sufficient physical condition to accept a rigorous level of physical - activity and exertion, as is sometimes the case when working in a mechanical environment. - I understand that participation in this program is strickly voluntary and I - freely chose to participate. I understand that The New Orleans Community Bike Project - does not provide medical coverage for me. I verify that I will be responsible - for any medical costs I incur as a result of my participation.

-
+ + + diff --git a/css/contacts.css b/css/contacts.css new file mode 100644 index 0000000..9d8757e --- /dev/null +++ b/css/contacts.css @@ -0,0 +1,7 @@ + +/* errors */ +#waiver_error, #phone_error, #email_error, +#first_name_error, #last_name_error + { + color: red; +} \ No newline at end of file diff --git a/include_header.html b/include_header.html index 3a55f9f..99432e9 100644 --- a/include_header.html +++ b/include_header.html @@ -23,12 +23,14 @@ function resetTimer() YBDB + + diff --git a/js/contact.js b/js/contact.js new file mode 100644 index 0000000..f9ad59c --- /dev/null +++ b/js/contact.js @@ -0,0 +1,122 @@ +$(function(){ + + "use strict"; + + var birth_date = $("#birth_date"); + var waiver_checkbox = $("#waiver_checkbox"), waiver_error = $("#waiver_error"); + var first_name = $("#first_name"), first_name_error = $("#first_name_error"); + var last_name = $("#last_name"), last_name_error = $("#last_name_error"); + var phone = $("#phone"), phone_error = $("#phone_error"); + var email = $("#email"), email_error = $("#email_error"); + var zip = $("#zip"); + var state_abbreviation = $("#state_abbreviation"); + + // sensible defaults + first_name.mask('#',{placeholder: "first", translation: {"#": {pattern: /[A-Za-z0-9@.]/, recursive: true} } }); + last_name.mask('#',{placeholder: "last", translation: {"#": {pattern: /[A-Za-z0-9@.]/, recursive: true} } }); + birth_date.mask("0000-00-00", {placeholder: "yyyy-mm-dd" }); + phone.mask('(000) 000-0000', {placeholder: "(000) 000-0000"}); + email.mask('#',{placeholder: "_@_", translation: {"#": {pattern: /[A-Za-z0-9@.]/, recursive: true} } }); + zip.mask('00000-0000', {placeholder: "00000-0000"}); + state_abbreviation.mask('AA',{placeholder: "WV", translation: {"A": {pattern: /[A-Za-z]/, recursive: false} } }); + $("#submit_contact").on("click keypress", function(e) { + + // check for errors + //error_handler(input,error_span,error,error_text,event); + + var err0 = 0, err1 = 0; + + // first name & last name input + error_handler(first_name.val(), first_name_error, "","*Required",e); + error_handler(last_name.val(), last_name_error, "","*Required",e); + + // email and phone input + if (email.val() === "" && phone.val() === "") { + + error_handler(email.val(), email_error, "","*Required - email address and/or phone number",e); + error_handler(phone.val(), phone_error, "","*Required - email address and/or phone number",e); + + } else if ( (email.val() === "" && phone.val() !== "") ) { + + email_error.hide(); + phone_error.hide(); + phone_validator(phone.val(),e); + + } else if ( (email.val() !== "" && phone.val() === "") ) { + + email_error.hide(); + phone_error.hide(); + email_validator(email.val(),e); + + } else if ( email.val() && phone.val() ) { + + email_error.hide(); + phone_error.hide(); + phone_validator(phone.val(),e); + email_validator(email.val(),e); + + } + + // waiver checkbox + error_handler(waiver_checkbox.prop("checked"),waiver_error,false,"*Required",event); + + } ); + + + // waiver slideup/slidedown + $('#waiver').hide(); + var c=0; + $('#waiver_button').click(function(e){ + e.preventDefault(); + if (c == 0) { + $('#waiver').slideDown(); + $(this).attr("value","Hide Waiver"); + c++; + } else { + $('#waiver').slideUp(); + $(this).attr("value","Show Waiver"); + c--; + } }); + + + function phone_validator(val, e) { + var re = /^\(\d{3}\)\s?\d{3}-\d{4}$/; + if ( !re.test(val) ) { + console.log("hello"); + error_handler(false, phone_error, false,"*Enter a correct phone number",e); + } + } + + + function email_validator(val, e) { + // https://fightingforalostcause.net/content/misc/2006/compare-email-regex.php + var re = /^[-a-z0-9~!$%^&*_=+}{\'?]+(\.[-a-z0-9~!$%^&*_=+}{\'?]+)*@([a-z0-9_][-a-z0-9_]*(\.[-a-z0-9_]+)*\.(aero|arpa|biz|com|coop|edu|gov|info|int|mil|museum|name|net|org|pro|travel|mobi|[a-z][a-z])|([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}))(:[0-9]{1,5})?$/i; + if ( !re.test(val) ) { + error_handler(false, email_error, false,"*Enter a correct email address",e); + } + } + + + // error handler for contacts + function error_handler(input,error_span,error,error_text,event) { + var trans_error = 0; + if ( input == error ) { + if ( !error_span.is(":visible") ) { + error_span.show(); + } + error_span.html(error_text); + trans_error = 1; + } else { + trans_error = 0; + error_span.hide(); + } + + if (trans_error) { + event.preventDefault(); + } + + return trans_error; + + } // end error_handling function + +}); \ No newline at end of file diff --git a/js/transaction.js b/js/transaction.js index 67113d9..304c868 100644 --- a/js/transaction.js +++ b/js/transaction.js @@ -617,7 +617,6 @@ $(function() { date = "0000-00-00"; } - // find new transaction_id if date has changed for a storage transaction // this is the most recent transaction_id if ($("#date_startstorage").val() && date !== "0000-00-00") { @@ -695,29 +694,19 @@ $(function() { transaction_history.push(current_transaction); $.post("json/transaction.php",{ history_update: 1, transaction_id: transaction_id, - history: transaction_history }); - - + history: transaction_history, + more_than_one: 1 }); + } // more than 1 transaction in the history - } ); - - + } ); // check for prior transactions + } // End Save History }) // end function save_and_close - // show history if more than 1 transaction can also be done within transactions.php & - // choosen dis-activating active trans. - $.post("json/transaction.php",{ history_select: 1, transaction_id: transaction_id }, function(data) { - - if (data !== "First Transaction") { - var transaction_history = $.parseJSON(data); - } - } ); - // On reload if patron isn't logged in replace pull-down with patrons name if (sold_to.val() == "no_selection") { $.post("json/transaction.php",{ not_logged_in: 1, transaction_id: transaction_id }, function(data) { diff --git a/json/transaction.php b/json/transaction.php index 5097030..cccd522 100644 --- a/json/transaction.php +++ b/json/transaction.php @@ -97,17 +97,28 @@ $change_fund = CHANGE_FUND; if ($result['history'] == "") { echo "First Transaction"; } else { - echo $result['history']; + // Description may have newlines + $history_result = str_replace("\n", "\\n",$result['history']); + echo $history_result; } } // Transaction history - update transaction history + // Note: This could easily be turned into its own table with a foreign key + // referencing transaction_log.transaction_id, but most transactions + // will probably only occur 1 time, and there probably isn't that much + // need to do many things with this data other than rollback a transaction, or + // research what happened on a particular shop day. if(isset($_POST['history_update'])) { $json = json_encode($_POST['history']); $query = "UPDATE transaction_log SET history='$json'" . ' WHERE transaction_id="' . $_POST['transaction_id'] . '";'; $result = mysql_query($query, $YBDB) or die(mysql_error()); - //echo ; + + // show history + if(isset($_POST['more_than_one'])) { + list_history($_POST['history']); + } } // Check for most recent transaction_id if transaction_id has changed