Exemplo n.º 1
0
function processRegoSubmission()
{
    // $out = new OUTPUTj(0,"","Registration currently not available");
    // echo $out->toJSON();
    // return false;
    $json = $_POST["json"];
    if ($json || $_POST["reference"]) {
        if ($json != "") {
            //create new object with json data
            $rego = new Registration($json);
            //check if json data exists
            if ($rego->exists()) {
                $out = new OUTPUTj(0, "", "This registration information already exists!");
                echo $out->toJSON();
                return false;
            }
            //json to objects
            $rego->parseJSON();
            //make sure the json converted is valid
            if ($rego->isValid() == false) {
                $out = new OUTPUTj(0, "", $rego->errMsg);
                echo $out->toJSON();
                return false;
            }
            //$out = new OUTPUTj(0,"","Registration is temporarily unavailable!");
            //echo $out->toJSON();
            //return false;
            //$rego->toString();
            if ($rego->commitDB()) {
                $ref = $rego->Reference;
                //send sms
                try {
                    //we try this as we dont want to show error if sms fails
                    //we still want to show the registration information
                    //check for aussie mobile prefix
                    if (substr($rego->Phone, 0, 5) == "+6104" || substr($rego->Phone, 0, 4) == "+614") {
                        $sms = new SMS();
                        if ($sms->access_token) {
                            $messageId = $sms->send($rego->Phone, 'Hi ' . $rego->Firstname . ', your ref: ' . $ref . '. View your rego @ http://tinyurl.com/h4glqrk?ref=' . $ref . '\\n\\nDaiHoi Melbourne2016 Team.');
                            if ($messageId) {
                                $rego->updateSMSMessageId($rego->Reference, $messageId);
                            }
                        }
                    }
                } catch (Exception $e) {
                    //should log error in db
                }
                //we send email
                try {
                    //we try this as we dont want to show error if email fails
                    //we still want to show the registration information
                    $show_viet_section = 0;
                    if (startsWith($rego->Phone, "+84") || startsWith($rego->Phone, "84") || endsWith($rego->Church, "Vietnam")) {
                        $show_viet_section = 1;
                    }
                    $message = $rego->getRego($ref);
                    $email = new Mailer();
                    $email->sendMail($rego->Email, 'DaiHoi 2016 Registration [' . $ref . '] for: ' . $rego->FullName(), $message, $show_viet_section);
                } catch (Exception $e) {
                    //should log error in db
                }
                $out = new OUTPUTj(1, $ref, $rego->errMsg);
                echo $out->toJSON();
            } else {
                $out = new OUTPUTj(0, "", $rego->errMsg);
                echo $out->toJSON();
            }
        }
    }
}