if (!empty($_POST['honeypot'])) {
     // bad - honeypot
     $resultArray["HONEYPOT_FILLED"] = 1;
     $resultArray["MESSAGE"] = "There was a problem verifying that you are human. If a field says to leave it blank, please do so.";
     // success - honeypot
 } else {
     // good - honeypot
     $resultArray["HONEYPOT_FILLED"] = 0;
     $inputValues = array("name" => $_POST["name"], "email" => $_POST["email"], "message" => $_POST["message"]);
     /* ******************************** */
     /* 		Test For Empty Inputs		*/
     /* ******************************** */
     // count empty inputs
     $emptyInputs = 0;
     foreach ($inputValues as $k => $v) {
         if ($v == null || empty($v) || $v == "" || removeWhiteSpace($v) == "") {
             $emptyInputs++;
         }
     }
     // test - empty inputs
     if ($emptyInputs != 0) {
         // bad - empty inputs
         $resultArray["EMPTY_INPUTS"] = 1;
         $resultArray["MESSAGE"] = "There was a problem with your registration.  Please check to make sure you have the required information entered in the form.";
         // success - empty inputs
     } else {
         // good - empty inputs
         $resultArray["EMPTY_INPUTS"] = 0;
         // send email
         $result = EmailHelperClass::createAndSendEmail_SponsorEmail($inputValues["name"], $inputValues["email"], $inputValues["message"]);
         $resultMessage = $result ? "Success!" : "There was a problem sending a email.  Please resubmit the form.";
Beispiel #2
0
 // get all the data from the post
 $numErrors = 0;
 $email = $_POST["email"];
 $email = removeWhiteSpace(strtolower($email));
 if ($email == "" || empty($email)) {
     $numErrors++;
     $error .= " Email was empty. ";
 }
 $first_name = $_POST["first_name"];
 $first_name = removeWhiteSpace(strtolower($first_name));
 if ($first_name == "" || empty($first_name)) {
     $numErrors++;
     $error .= " First name was empty. ";
 }
 $last_name = $_POST["last_name"];
 $last_name = removeWhiteSpace(strtolower($last_name));
 if ($last_name == "" || empty($last_name)) {
     $numErrors++;
     $error .= " Last name was empty. ";
 }
 $type = $_POST["type"];
 if ($type == "" || empty($type) || $type != "Mentor" && $type != "Participant") {
     $numErrors++;
     $error .= " Type was not filled out. ";
 }
 if (array_key_exists('success', $_GET)) {
     $numErrors++;
 }
 if ($numErrors == 0) {
     //echo "no errors<br/>";
     // post data
function registerPerson($db, $resultArray, $errorMessages, $inputs, $key, $typeCode)
{
    // create index keys for result array
    include 'resultArrayIndex.php';
    // get type
    $isParticipant = false;
    $isMentor = false;
    $isFriend = false;
    $isParticipantFriend = false;
    $isMentorFriend = false;
    $isFriend1 = false;
    $isFriend2 = false;
    $isFriend3 = false;
    if ($typeCode == 1) {
        $isParticipant = true;
    } else {
        if ($typeCode == 2) {
            $isMentor = true;
        } else {
            if ($typeCode >= 3) {
                $isFriend = true;
                if ($typeCode >= 6) {
                    $isMentorFriend = true;
                } else {
                    $isParticipantFriend = true;
                }
                if ($typeCode == 3 || $typeCode == 6) {
                    $isFriend1 = true;
                } else {
                    if ($typeCode == 4 || $typeCode == 7) {
                        $isFriend2 = true;
                    } else {
                        if ($typeCode == 5 || $typeCode == 8) {
                            $isFriend3 = true;
                        }
                    }
                }
            }
        }
    }
    // get inputs
    $inputNames = $inputs['inputNames'];
    $numReqFilledInputs = $inputs['numReqFilledInputs'];
    $numReqPresentInputs = $inputs['numReqPresentInputs'];
    // set initial keys
    if ($isParticipant) {
        $resultArray[$PARTICIPANT_KEY] = $key;
    } else {
        if ($isMentor) {
            $resultArray[$MENTOR_KEY] = $key;
        } else {
            if ($isFriend1) {
                $resultArray[$FRIEND_1_KEY] = $key;
            } else {
                if ($isFriend2) {
                    $resultArray[$FRIEND_2_KEY] = $key;
                } else {
                    if ($isFriend3) {
                        $resultArray[$FRIEND_3_KEY] = $key;
                    }
                }
            }
        }
    }
    /* ************************************ */
    /* 		Test For Remaining Inputs		*/
    /* ************************************ */
    // add to counter if does not exist
    $doesNotExist = 0;
    $doesNotExistNames = "";
    $i = 0;
    foreach ($inputNames as $name) {
        if ($i < $numReqPresentInputs && !array_key_exists($name, $_POST)) {
            $doesNotExist++;
            $doesNotExistNames .= $name;
        }
        $i++;
    }
    // test - missing inputs
    if ($doesNotExist != 0) {
        // bad - missing inputs
        if ($isParticipant || $isMentor) {
            $resultArray[$SELF_INPUTS_MISSING] = 1;
            $resultArray[$MESSAGE] = $errorMessages[$SELF_INPUTS_MISSING];
        } else {
            if ($isFriend) {
                $resultArray[$FRIEND_INPUTS_MISSING] = 1;
                $resultArray[$MESSAGE] = $errorMessages[$FRIEND_INPUTS_MISSING];
            }
        }
        $resultArray[$DETAIL_MESSAGE] = $doesNotExistNames;
        // success - missing inputs
    } else {
        // good - missing participant inputs
        if ($isParticipant || $isMentor) {
            $resultArray[$SELF_INPUTS_MISSING] = 0;
        } else {
            if ($isFriend) {
                $resultArray[$FRIEND_INPUTS_MISSING] = 0;
            }
        }
        /* ******************************** */
        /* 		Get Inputs from Names		*/
        /* ******************************** */
        // get form input values
        $inputValues = array();
        if ($isParticipant || $isFriend) {
            foreach ($inputNames as $name) {
                // agreement
                if ($name == "agree") {
                    $inputValues[$name] = 1;
                } else {
                    $inputValues[$name] = $_POST[$name];
                }
            }
        } else {
            if ($isMentor) {
                $i = 0;
                foreach ($inputNames as $name) {
                    if ($name == "agree") {
                        $inputValues[$name] = 1;
                    } else {
                        if ($i < $numReqPresentInputs) {
                            $inputValues[$name] = $_POST[$name];
                        } else {
                            $inputValues[$name] = array_key_exists($name, $_POST) ? 1 : 0;
                        }
                    }
                    $i++;
                }
            }
        }
        /*printArray($_POST);
        		printArray($inputNames);
        		printArray($inputValues);*/
        // set level of complete
        $isNew = $key == -1;
        $isComplete = !$isNew;
        /* ******************************** */
        /* 		Test For Empty Inputs		*/
        /* ******************************** */
        // count empty inputs
        $emptyInputs = 0;
        $i = 0;
        if (!empty($inputValues)) {
            foreach ($inputValues as $k => $v) {
                if ($i < $numReqFilledInputs) {
                    if ($v == null || empty($v) || $v == "" || removeWhiteSpace($v) == "") {
                        $emptyInputs++;
                    }
                }
                $i++;
            }
        }
        // test - empty inputs
        if ($emptyInputs != 0) {
            // bad - empty inputs
            if ($isParticipant || $isMentor) {
                $resultArray[$SELF_INPUTS_EMPTY] = 1;
                $resultArray[$MESSAGE] = $errorMessages[$SELF_INPUTS_EMPTY];
            } else {
                if ($isFriend) {
                    $resultArray[$FRIEND_INPUTS_EMPTY] = 1;
                    $resultArray[$MESSAGE] = $errorMessages[$FRIEND_INPUTS_EMPTY];
                }
            }
            // success - empty inputs
        } else {
            // good - empty inputs
            if ($isParticipant || $isMentor) {
                $resultArray[$SELF_INPUTS_EMPTY] = 0;
            } else {
                if ($isFriend) {
                    $resultArray[$FRIEND_INPUTS_EMPTY] = 0;
                }
            }
            /* ******************************** */
            /* 		Process Input Values		*/
            /* ******************************** */
            // process email for mentor and participant
            if ($isParticipant || $isMentor) {
                $inputValues['email'] = strtolower(removeWhiteSpace($inputValues['email']));
            } else {
                if ($isFriend) {
                    $inputValues['friendName'] = $inputValues['name'];
                    if ($isFriend1) {
                        $inputValues['name'] = $inputValues['friendName1'];
                        $inputValues['email'] = strtolower(removeWhiteSpace($inputValues['friendEmail1']));
                    } else {
                        if ($isFriend2) {
                            $inputValues['name'] = $inputValues['friendName2'];
                            $inputValues['email'] = strtolower(removeWhiteSpace($inputValues['friendEmail2']));
                        } else {
                            if ($isFriend3) {
                                $inputValues['name'] = $inputValues['friendName3'];
                                $inputValues['email'] = strtolower(removeWhiteSpace($inputValues['friendEmail3']));
                            }
                        }
                    }
                }
            }
            /* ******************************************** */
            /* 		Test For Email Already Registered		*/
            /* ******************************************** */
            $email = $inputValues['email'];
            $numEmailUsed = 0;
            // test only id new
            if ($isNew) {
                // test - participant email used
                if ($db->participantEmailRegistered($email)) {
                    $numEmailUsed++;
                    // bad - participant email used
                    $resultArray[$PARTICIPANT_EMAIL_USED] = 1;
                    $resultArray[$MESSAGE] = $errorMessages[$PARTICIPANT_EMAIL_USED];
                }
                // test - participant email used
                if ($db->mentorEmailRegistered($email)) {
                    $numEmailUsed++;
                    // bad - participant email used
                    $resultArray[$MENTOR_EMAIL_USED] = 1;
                    $resultArray[$MESSAGE] = $errorMessages[$MENTOR_EMAIL_USED];
                }
            }
            // test - any email used
            if ($numEmailUsed == 0) {
                // good - any email used
                $resultArray[$PARTICIPANT_EMAIL_USED] = 0;
                $resultArray[$MENTOR_EMAIL_USED] = 0;
                /* **************************************** */
                /* 		Participant Upload File Script		*/
                /* **************************************** */
                $fileUploadErrors = 0;
                if ($isParticipant) {
                    if (empty($_FILES["resume"]["name"])) {
                        $inputValues['resume'] = $inputValues['resumeName'];
                    } else {
                        //echo "uploading resume";
                        // get unique date
                        $date = date("YmdHis");
                        $fileNameAddition = "___" . $date;
                        // get names and extensions
                        $defaultFileName = basename($_FILES["resume"]["name"]);
                        $tmpFileName = $_FILES["resume"]["tmp_name"];
                        $fileType = pathinfo($defaultFileName, PATHINFO_EXTENSION);
                        $extensionPos = strrpos($defaultFileName, '.');
                        // find position of the last dot, so where the extension starts
                        // test - file size
                        $maxsize = 2097152;
                        if ($_FILES['resume']['size'] >= $maxsize || $_FILES["resume"]["size"] == 0) {
                            // bad - file size
                            $fileUploadErrors++;
                            $resultArray[$FILE_SIZE_TOO_LARGE] = 1;
                            $resultArray[$MESSAGE] = $errorMessages[$FILE_SIZE_TOO_LARGE];
                            // success - file size
                        } else {
                            // good - file size
                            $resultArray[$FILE_SIZE_TOO_LARGE] = 0;
                        }
                        // get updated name
                        $updatedFileName = substr($defaultFileName, 0, $extensionPos) . $fileNameAddition . substr($defaultFileName, $extensionPos);
                        $inputValues['resume'] = $updatedFileName;
                        // test - successful upload
                        $targetFile = "../hidden/resumes/" . $updatedFileName;
                        if (!move_uploaded_file($tmpFileName, $targetFile)) {
                            // bad - successful upload
                            $fileUploadErrors++;
                            $resultArray[$FILE_UPLOAD_ERROR] = 1;
                            $resultArray[$MESSAGE] = $errorMessages[$FILE_UPLOAD_ERROR];
                            // success - successful upload
                        } else {
                            // good - successful upload
                            $resultArray[$FILE_UPLOAD_ERROR] = 0;
                        }
                    }
                    // end else not empty resume -> so upload it
                }
                // end if participant
                // test - file upload
                if ($fileUploadErrors == 0) {
                    // good - file upload
                    /* **************************** */
                    /* 		Create Record Test		*/
                    /* **************************** */
                    // create key
                    if ($isNew) {
                        $keyPrefix = $isParticipant || $isParticipantFriend ? "P-" : "M-";
                        $key = $keyPrefix . substr(str_shuffle("abcdefghjkmnpqrstuvwxyzABCDEFGHJKMNPQRSTUVWXYZ23456789"), 0, 6);
                        // set new keys
                        if ($isParticipant) {
                            $resultArray[$PARTICIPANT_KEY] = $key;
                        } else {
                            if ($isMentor) {
                                $resultArray[$MENTOR_KEY] = $key;
                            } else {
                                if ($isFriend1) {
                                    $resultArray[$FRIEND_1_KEY] = $key;
                                } else {
                                    if ($isFriend2) {
                                        $resultArray[$FRIEND_2_KEY] = $key;
                                    } else {
                                        if ($isFriend3) {
                                            $resultArray[$FRIEND_3_KEY] = $key;
                                        }
                                    }
                                }
                            }
                        }
                    }
                    //printArray($inputValues); die();
                    // add record
                    $insertResult = false;
                    if ($isParticipant) {
                        $insertResult = $db->addParticipant($inputValues, $key, $isNew);
                    } else {
                        if ($isMentor) {
                            $insertResult = $db->addMentor($inputValues, $key, $isNew);
                        } else {
                            if ($isParticipantFriend) {
                                $insertResult = $db->addParticipantFriend($inputValues, $key);
                            } else {
                                if ($isMentorFriend) {
                                    $insertResult = $db->addMentorFriend($inputValues, $key);
                                }
                            }
                        }
                    }
                    // test - insert record
                    if (!$insertResult) {
                        // bad - insert record
                        if ($isParticipant || $isMentor) {
                            $resultArray[$SELF_RECORD_ERROR] = 1;
                            $resultArray[$MESSAGE] = $errorMessages[$SELF_RECORD_ERROR];
                        } else {
                            $resultArray[$FRIEND_RECORD_ERROR] = 1;
                            $resultArray[$MESSAGE] = $errorMessages[$FRIEND_RECORD_ERROR];
                        }
                        // success - insert record
                    } else {
                        // good - insert record
                        if ($isParticipant || $isMentor) {
                            $resultArray[$SELF_RECORD_ERROR] = 0;
                        } else {
                            if ($isFriend) {
                                $resultArray[$FRIEND_RECORD_ERROR] = 0;
                            }
                        }
                        /* ******************************** */
                        /* 		Send Self Email Test		*/
                        /* ******************************** */
                        $emailSuccess = false;
                        // send email
                        $emailResult = false;
                        if ($isNew) {
                            if ($isParticipant || $isMentor) {
                                $emailResult = EmailHelperClass::createAndSendEmail_Confirmation($inputValues, $key, $isParticipant);
                            } else {
                                if ($isFriend) {
                                    $emailResult = EmailHelperClass::createAndSendEmail_RegistrationNotice($inputValues, $key, $isParticipant);
                                }
                            }
                        } else {
                            $emailResult = true;
                        }
                        // test - send self email
                        if (!$emailResult) {
                            // bad - send self email
                            if ($isParticipant || $isMentor) {
                                $resultArray[$SELF_EMAIL_ERROR] = 1;
                                $resultArray[$MESSAGE] = $errorMessages[$SELF_EMAIL_ERROR];
                            } else {
                                if ($isFriend) {
                                    $resultArray[$FRIEND_EMAIL_ERROR] = 1;
                                    $resultArray[$MESSAGE] = $errorMessages[$FRIEND_EMAIL_ERROR];
                                }
                            }
                            // success - send self email
                        } else {
                            // good - send self email
                            if ($isParticipant || $isMentor) {
                                $resultArray[$SELF_EMAIL_ERROR] = 0;
                            } else {
                                if ($isFriend) {
                                    $resultArray[$FRIEND_EMAIL_ERROR] = 0;
                                }
                            }
                            $emailSuccess = true;
                        }
                        // test - email success - final test?
                        if ($emailSuccess) {
                            // good - complete registration !!!
                            if ($isParticipant) {
                                $resultArray[$PARTICIPANT_SUCCESS] = 1;
                            } else {
                                if ($isMentor) {
                                    $resultArray[$MENTOR_SUCCESS] = 1;
                                } else {
                                    if ($isFriend1) {
                                        $resultArray[$FRIEND_1_SUCCESS] = 1;
                                    } else {
                                        if ($isFriend2) {
                                            $resultArray[$FRIEND_2_SUCCESS] = 1;
                                        } else {
                                            if ($isFriend3) {
                                                $resultArray[$FRIEND_3_SUCCESS] = 1;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        // end else for send self email
                    }
                    // end else for insert self record test
                }
                // end else file upload test
            }
            // end else for participant and mentor email already used test
        }
        // end else for empty inputs test
    }
    // end else for missing inputs test
    return array("resultArray" => $resultArray, "inputValues" => $inputValues);
}