Sign-Up HTML Page

<?php
set_include_path(get_include_path() . PATH_SEPARATOR . '/home/ssp/sippy_web/lib');

/* you can find libraries included below in /home/ssp/sippy_web/lib directory */
include 'html.php';
include 'xmlrpc/xmlrpc.inc';

$currencies = array(
    'USD' => 'USD',
    'NZD' => 'NZD'
    /* ... and so on */
);

$tzs = array(
    '97' => 'Africa/Abidjan',
    '145' => 'Africa/Accra',
    '129' => 'Africa/Addis_Ababa',
    '119' => 'Africa/Algiers',
    '125' => 'Africa/Asmera',
    '213' => 'Africa/Bamako'
    /* ... and so on */
);

function createAccount() {

    $params = array(new xmlrpcval(array("username"      => new xmlrpcval('${N:[8][8][8][0-9][0-9][0-9][0-9]}', "string"),
                                    "web_password"      => new xmlrpcval('${P:8}', "string"),
                                    "authname"          => new xmlrpcval('${C:username}', "string"),
                                    "voip_password"     => new xmlrpcval('${P:7}', "string"),
                                    "i_tariff"          => new xmlrpcval("50", "int"),                             /* replace with your i_tariff */
                                    "i_time_zone"       => new xmlrpcval(get_par('i_time_zone'), "int"),
                                    "i_lang"            => new xmlrpcval("en", "string"),
                                    "balance"           => new xmlrpcval("0.0", "double"),                         /* set needed value */
                                    "credit_limit"      => new xmlrpcval("0.0", "double"),                         /* set needed value */
                                    "blocked"           => new xmlrpcval("", "int"),
                                    "max_sessions"      => new xmlrpcval("", "int"),
                                    "max_credit_time"   => new xmlrpcval("3600", "int"),
                                    "translation_rule"  => new xmlrpcval("", "string"),
                                    "cli_translation_rule"      => new xmlrpcval("", "string"),
                                    "cpe_number"        => new xmlrpcval("", "string"),
                                    "i_export_type"     => new xmlrpcval("2", "int"),
                                    "reg_allowed"       => new xmlrpcval("1", "int"),
                                    "trust_cli"         => new xmlrpcval("", "int"),
                                    "disallow_loops"    => new xmlrpcval("", "int"),
                                    "vm_password"       => new xmlrpcval('${N:[0-9][0-9][0-9][0-9][0-9][0-9]}', "string"),
                                    "vm_enabled"        => new xmlrpcval("1", "int"),
                                    "vm_notify_emails"  => new xmlrpcval(get_par('vm_notify_emails'), "string"),
                                    "vm_forward_emails" => new xmlrpcval(get_par('vm_forward_emails'), "string"),
                                    "vm_del_after_fwd"  => new xmlrpcval("", "int"),
                                    "company_name"      => new xmlrpcval(get_par('company_name'), "string"),
                                    "salutation"        => new xmlrpcval(get_par('salutation'), "string"),
                                    "first_name"        => new xmlrpcval(get_par('first_name'), "string"),
                                    "mid_init"          => new xmlrpcval("", "string"),
                                    "last_name"         => new xmlrpcval(get_par('last_name'), "string"),
                                    "street_addr"       => new xmlrpcval(get_par('street_addr'), "string"),
                                    "state"             => new xmlrpcval(get_par('state'), "string"),
                                    "postal_code"       => new xmlrpcval(get_par('postal_code'), "string"),
                                    "city"              => new xmlrpcval(get_par('city'), "string"),
                                    "country"           => new xmlrpcval(get_par('country'), "string"),
                                    "contact"           => new xmlrpcval("", "string"),
                                    "phone"             => new xmlrpcval(get_par('phone'), "string"),
                                    "fax"               => new xmlrpcval(get_par('fax'), "string"),
                                    "alt_phone"         => new xmlrpcval(get_par('alt_phone'), "string"),
                                    "alt_contact"       => new xmlrpcval("", "string"),
                                    "email"             => new xmlrpcval(get_par('email'), "string"),
                                    "cc"                => new xmlrpcval(get_par('cc'), "string"),
                                    "bcc"               => new xmlrpcval(get_par('bcc'), "string"),
                                    "payment_currency"  => new xmlrpcval(get_par('payment_currency'), "string"),
                                    "payment_method"    => new xmlrpcval("1", "int"),
                                    "on_payment_action" => new xmlrpcval("", "int"),
                                    "min_payment_amount"=> new xmlrpcval("", "double"),
                                    "lifetime"          => new xmlrpcval("-1", "int"),
                                    "preferred_codec"   => new xmlrpcval("18", "int"),
                                    "use_preferred_codec_only"  => new xmlrpcval("", "int"),
                                    "welcome_call_ivr"  => new xmlrpcval("", "int")
                                   ), 'struct'));
    $msg = new xmlrpcmsg('createAccount', $params);

    /* replace here URL  and credentials to access to the API */
    $cli = new xmlrpc_client('https://sip.your-company.com/xmlapi/xmlapi');
    $cli->setSSLVerifyPeer(false);
    $cli->setCredentials('xmlapi', 'secret', CURLAUTH_DIGEST);

    $r = $cli->send($msg, 20);       /* 20 seconds timeout */

    if ($r->faultCode()) {
      error_log("Fault. Code: " . $r->faultCode() . ", Reason: " . $r->faultString());
      return false;
    }

    return $r->value();
}

function sendEMail($a) {
    $body = "  Welcome to Sippy!

  Please keep this email for your records. Your account information is as follows:

        SIP Login: ${a['authname']}
        SIP Password: ${a['voip_password']}
        Web Login: ${a['username']}
        Web Password: ${a['web_password']}
        SIP Proxy: sip.your-company.com

  Please do not forget your password as it has been encrypted in our database and
we cannot retrieve it for you. However, should you forget your password you can
request a password reset and a new one will be sent to you.

  To login to your account area please visit http://www.your-company.com/your-account.html

  When you login for the first time, the system will request a web login password change,
please make sure you change your password.

  To make Toll calls you will need to make on-line payments.

  Thank you for registering!

  Sippy Team.";

$params = array(new xmlrpcval(array("from"      => new xmlrpcval('signup@your-company.com', "string"),
                                    "to"        => new xmlrpcval(get_par('email'), "string"),
                                    "cc"        => new xmlrpcval('', "string"),
                                    "bcc"       => new xmlrpcval('', "string"),
                                    "subject"   => new xmlrpcval('Signup confirmation', "string"),
                                    "body"      => new xmlrpcval($body, "string")
                                   ), 'struct'));
    $msg = new xmlrpcmsg('sendEMail', $params);

    /* replace here URL  and credentials to access to the API */
    $cli = new xmlrpc_client('https://sip.your-company.com/xmlapi/xmlapi');
    $cli->setSSLVerifyPeer(false);
    $cli->setCredentials('xmlapi', 'secret', CURLAUTH_DIGEST);

    $r = $cli->send($msg, 20);       /* 20 seconds timeout */

    if ($r->faultCode()) {
      error_log("Fault. Code: " . $r->faultCode() . ", Reason: " . $r->faultString());
    }
}

$ok = true;
if (isset_par('task')) {
    if (!get_par('first_name') || !get_par('last_name') ||
        !get_par('street_addr') || !get_par('state') ||
        !get_par('postal_code') || !get_par('city') ||
        !get_par('country') || !get_par('phone') ||
        !get_par('email') || !get_par('payment_currency') ||
        !get_par('i_time_zone')) {
        $ok = false;
    }
    if ($ok) {
        $r = createAccount();
        if ($r) {
            $a = Array();

            $v = $r->structmem('username');
            $a['username'] = $v->scalarval();

            $v = $r->structmem('web_password');
            $a['web_password'] = $v->scalarval();

            $v = $r->structmem('authname');
            $a['authname'] = $v->scalarval();

            $v = $r->structmem('voip_password');
            $a['voip_password'] = $v->scalarval();

            $v = $r->structmem('vm_password');
            $a['vm_password'] = $v->scalarval();

            sendEMail($a);
        } else {
            $ok = false;
        }
    }
} else {
    $par['i_time_zone'] = 140;          /* Europe/London */
    $par['payment_currency'] = 'USD';
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
        <head>
        <meta http-equiv="content-type" content="text/html" />
        <title>Sign Up</title>
        <style type="text/css">
        body {
                margin: 0px;
                padding: 0px;
                border: 0px;
                background-color: white;
        }
        form {
                margin: 0px;
                padding: 0px;
                border: 0px;
        }
        .page {
                margin-left: auto;
                margin-right: auto;
                margin-top: 10px;
                margin-bottom: 10px;
                padding: 5px;
                width:80%;
                background-color: #FFFFDD;
                text-align: left;
                font-family: Verdana, Arial, Helvetica, sans-serif;
                font-size: 11px;
                border: 1px solid #DDDDBB;
        }
        td {
                font-size: 11px;
                color: #000000;
                text-decoration: none;
                line-height: 14px;
        }
        input, select {
                border: 1px solid #41884C;
                background-color: #fff;
                padding: 2px;
        }
        .int_h1 {
                font-family: verdana;
                font-size: 18px;
                font-weight: bold;
                padding: 3px 0 8px 5px;
        }
        .notice {
                font-family: verdana;
                font-size: 14px;
                color: 000;
                padding: 3px 0 8px 5px;
        }
        .error {
                font-family: verdana;
                font-size: 14px;
                color: red;
                padding: 3px 0 8px 5px;
        }
        .section_colour_bar{
                height: 2px;
                background-color:#41884C;
        }
        .ctr {
                text-align: center;
        }
        </style>
        </head>
        <body>
            <div class="ctr" align="center">
                <div class="page" align="center">
                    <div style="background-color:#fff">
                        <div class="int_h1">Sign Up</div>
                    </div>
                    <div class="section_colour_bar"></div>
<?php if (!$ok) { ?>
                    <div style="background-color:#fff">
                        <div class="error">Please fill in all required fields.</div>
                    </div>
                    <div class="section_colour_bar"></div>
<?php } ?>
<?php if (isset_par('task') && $ok) { ?>
                    <div style="background-color:#fff">
                        <div class="notice">Thank you for registering with Sippy! All your account credentials have been emailed to you on <?php echo get_par('email'); ?>.</div>
                    </div>
                    <div class="section_colour_bar"></div>
<?php } else { ?>
                    <form method="post">
                    <table>
                        <tr>
                            <td>Company Name</td>
                            <td>
                                <input name="company_name" type="text" size="50" value="<?php echo get_par('company_name'); ?>" />
                            </td>
                        </tr>
                        <tr>
                            <td>Mr./Ms...</td>
                            <td>
                                <input name="salutation" type="text" size="50" value="<?php echo get_par('salutation'); ?>" />
                            </td>
                        </tr>
                        <tr>
                            <td><b>First Name</b></td>
                            <td>
                                <input name="first_name" type="text" size="50" value="<?php echo get_par('first_name'); ?>" />
                            </td>
                        </tr>
                        <tr>
                            <td><b>Last Name</b></td>
                            <td>
                                <input name="last_name" type="text" size="50" value="<?php echo get_par('last_name'); ?>" />
                            </td>
                        </tr>
                        <tr>
                            <td><b>Address</b></td>
                            <td>
                                <input name="street_addr" type="text" size="50" value="<?php echo get_par('street_addr'); ?>" />
                            </td>
                        </tr>
                        <tr>
                            <td><b>State</b></td>
                            <td>
                                <input name="state" type="text" size="50" value="<?php echo get_par('state'); ?>" />
                            </td>
                        </tr>
                        <tr>
                            <td><b>Postal Code</b></td>
                            <td>
                                <input name="postal_code" type="text" size="50" value="<?php echo get_par('postal_code'); ?>" />
                            </td>
                        </tr>
                        <tr>
                            <td><b>City</b></td>
                            <td>
                                <input name="city" type="text" size="50" value="<?php echo get_par('city'); ?>" />
                            </td>
                        </tr>
                        <tr>
                            <td><b>Country</b></td>
                            <td>
                                <input name="country" type="text" size="50" value="<?php echo get_par('country'); ?>" />
                            </td>
                        </tr>
                        <tr>
                            <td><b>Phone</b></td>
                            <td>
                                <input name="phone" type="text" size="50" value="<?php echo get_par('phone'); ?>" />
                            </td>
                        </tr>
                        <tr>
                            <td>Fax</td>
                            <td>
                                <input name="fax" type="text" size="50" value="<?php echo get_par('fax'); ?>" />
                            </td>
                        </tr>
                        <tr>
                            <td>Alt. Phone</td>
                            <td>
                                <input name="alt_phone" type="text" size="50" value="<?php echo get_par('alt_phone'); ?>" />
                            </td>
                        </tr>
                        <tr>
                            <td><b>Email</b></td>
                            <td>
                                <input name="email" type="text" size="50" value="<?php echo get_par('email'); ?>" />
                            </td>
                        </tr>
                        <tr>
                            <td>CC</td>
                            <td>
                                <input name="cc" type="text" size="50" value="<?php echo get_par('cc'); ?>" />
                            </td>
                        </tr>
                        <tr>
                            <td>BCC</td>
                            <td>
                                <input name="bcc" type="text" size="50" value="<?php echo get_par('bcc'); ?>" />
                            </td>
                        </tr>
                        <tr>
                            <td>E-mail Forwarding</td>
                            <td>
                                <input name="vm_forward_emails" type="text" size="50" value="<?php echo get_par('vm_forward_emails'); ?>" />
                            </td>
                        </tr>
                        <tr>
                            <td>E-mail Notification</td>
                            <td>
                                <input name="vm_notify_emails" type="text" size="50" value="<?php echo get_par('vm_notify_emails'); ?>" />
                            </td>
                        </tr>
                        <tr>
                            <td><b>Currency</b></td>
                            <td>
                                <select name="payment_currency">
<?php
    foreach ($currencies as $k => $v) {
        $selected = (get_par('payment_currency') == $k) ? ' selected' : '';
        print "<option value=\"$k\" label=\"$v\"$selected>$v</option>\n";
    }
?>
                                </select>
                            </td>
                        </tr>
                        <tr>
                            <td><b>Time Zone</b></td>
                            <td>
                                <select name="i_time_zone">
<?php
    foreach ($tzs as $k => $v) {
        $selected = (get_par('i_time_zone') == $k) ? ' selected' : '';
        print "<option value=\"$k\" label=\"$v\"$selected>$v</option>\n";
    }
?>
                                </select>
                            </td>
                        </tr>
                        <tr>
                            <td>&nbsp;</td>
                            <td>
                                <input id="enableSignUp" name="enableSignUp" type="submit" value="I have read and agreed to Sippy's Terms & Conditions" onClick="this.disabled = true; b = document.getElementById('task'); b.disabled = false; return false;"/>
                            </td>
                        </tr>
                        <tr>
                            <td>&nbsp;</td>
                            <td>
                                <input id="task" name="task" type="submit" disabled value="Sign Up" />
                            </td>
                        </tr>
                    </table>
                    </form>
<?php } ?>
                </div>
            </div>
        </body>
</html>

Attachments