示例#1
0
 public function couponcheck()
 {
     global $dbh, $postvar, $getvar, $instance;
     if (empty($getvar['coupon'])) {
         echo 1;
         return;
     } else {
         $package_type = type::packagetype($getvar['package']);
         if ($package_type == "free") {
             echo 0;
             return;
         }
         $coupon_text = coupons::validate_coupon($getvar['coupon'], $getvar['location'], $getvar['username'], $getvar['package']);
         if ($coupon_text) {
             echo $coupon_text;
             return;
         } else {
             echo 0;
             return;
         }
     }
 }
示例#2
0
 public function prorate($pid, $coupcode = "", $userid = "", $admin = "")
 {
     global $dbh, $postvar, $getvar, $instance;
     if (!$userid) {
         $userid = $_SESSION['cuser'];
     }
     $upackinfo = main::uidtopack($userid);
     $umonthly = $upackinfo['additional']['monthly'];
     $usignup = $upackinfo['additional']['signup'];
     $utype = $upackinfo['packages']['type'];
     $pack_data = $dbh->select("packages", array("id", "=", $pid));
     $packinfo = type::additional($pid);
     $monthly = $packinfo['monthly'];
     $signup = $packinfo['signup'];
     $pack_type = $pack_data['type'];
     //For P2H
     $umonthly_discount = max(0, coupons::get_discount("p2hmonthly", $umonthly, $userid));
     if ($coupcode) {
         $user = main::uname($userid);
         $response = coupons::validate_coupon($coupcode, "orders", $user, $pid);
         if ($response) {
             $coup_data = coupons::coupon_data($coupcode);
             $signup = max(0, $signup - $coup_data['p2hinitdisc']);
         }
     }
     switch ($utype) {
         case "free":
             switch ($pack_type) {
                 case "free":
                     //No need to prorate it.
                     return "now";
                     break;
                 case "paid":
                     //No need to prorate it.
                     return "now";
                     break;
                 case "p2h":
                     if ($upackinfo['uadditional']['fuser']) {
                         $total_posts = coupons::totalposts($userid, $pid);
                         if ($total_posts < $signup) {
                             $inelegible = 1;
                         }
                     } else {
                         $check = 1;
                     }
                     if (!$inelegible && !$check || $admin && !$check) {
                         //They haven't paid yet, so they can get the account changed now.
                         return "now";
                     } elseif ($inelegible && !$admin) {
                         //They don't have the required number of posts made to be allowed to switch to this plan.
                         return "inelegible";
                     } elseif ($check) {
                         //We need to check if they have enough posts to be allowed to change the plan.  This means the user has to enter their credentials for the forum since we don't have it yet.
                         return "check";
                     }
                     break;
             }
             break;
         case "paid":
             unset($where);
             $where[] = array("uid", "=", $userid, "AND");
             $where[] = array("changed_plan", "=", "0");
             $invoices_query = $dbh->select("invoices", $where, 0, 0, 1);
             while ($invoices_data = $dbh->fetch_array($invoices_query)) {
                 $paid = coupons::totalpaid($invoices_data['id']);
                 if ($paid >= $invoices_data['amount'] && $paid > 0) {
                     $amt_owed = $monthly - $paid;
                     $prorate = 1;
                 }
                 if ($paid < $invoices_data['amount']) {
                     //They change to a different paid plan only.  The new plan will be added to the newest invoice anyway.
                     $owes_money = 1;
                 }
                 if ($not_first_pull) {
                     //This avoids having someone upgrade and not pay that bill, then upgrade again and not pay that bit, etc.  The system only charges
                     //the upgrade price and keeps the transactions on the last invoice.  This means that if you have a plan for $2, $3, $4, and $5, then
                     //the user can simply upgrade until they're on the highest plan and and pay only a couple bucks more than the plan they started on,
                     //all the while receiving free months of service.  Then they downgrade to the lowest plan the next month and it starts over again.
                     //So we need to know if the user paid last month's bill along with the other bills before it so they can upgrade only if they did.
                     $cant_upgrade = $owes_money;
                 }
                 $not_first_pull = 1;
             }
             switch ($pack_type) {
                 case "free":
                     if ($owes_money && !$admin) {
                         //Total paid is less than $0, so that means they've been charged for something.  We can't let then leave the paid plan system so the invoice isn't lost.
                         return "owe";
                     } else {
                         //Next month they become a free member
                         $upgrade_today = self::upgrade_today($utype, $userid);
                         if ($upgrade_today) {
                             return "now";
                         } else {
                             return "next";
                         }
                     }
                     break;
                 case "paid":
                     if ($monthly > $umonthly && $owes_money || !$owes_money && !$cant_upgrade) {
                         if ($monthly < $umonthly) {
                             //Next month they will be downgraded.
                             $upgrade_today = self::upgrade_today($utype, $userid);
                             if ($upgrade_today) {
                                 return "now";
                             } else {
                                 return "next";
                             }
                         } else {
                             //Amount they owe for their account.
                             //See comment above.
                             if ($cant_upgrade && !$admin) {
                                 return "owe";
                             } else {
                                 if ($admin) {
                                     return "now";
                                 } else {
                                     return $amt_owed;
                                 }
                             }
                         }
                     } else {
                         //Total paid is less than $0, so that means they've been charged for something.  We can't let then leave the paid plan system so the invoice isn't lost.
                         //They need to choose a higher paid package so they don't ignore the bill and use a higher plan until its payment time, then downgrade, pay that bill,
                         //then upgrade after cron sees its paid, and repeat that.  If they have a fully paid bill, they can downgrade.  If they want to upgrade, they can.
                         return "owe";
                     }
                     break;
                 case "p2h":
                     if ($upackinfo['uadditional']['fuser']) {
                         $total_posts = coupons::totalposts($userid, $pid);
                         if ($total_posts < $signup) {
                             $inelegible = 1;
                         }
                     } else {
                         $check = 1;
                     }
                     if ($owes_money && !$admin) {
                         //Total paid is less than $0, so that means they've been charged for something.  We can't let then leave the paid plan system so the invoice isn't lost.
                         return "owe";
                     } elseif ($inelegible && !$admin) {
                         //They don't have the required number of posts made to be allowed to switch to this plan.
                         return "inelegible";
                     } elseif ($check) {
                         //We need to check if they have enough posts to be allowed to change the plan.  This means the user has to enter their credentials for the forum since we don't have it yet.
                         $upgrade_today = self::upgrade_today($utype, $userid);
                         if ($upgrade_today) {
                             return "check now";
                         } else {
                             return "check next";
                         }
                     } elseif ($prorate) {
                         //Next month they become a p2h member
                         $upgrade_today = self::upgrade_today($utype, $userid);
                         if ($upgrade_today) {
                             return "now";
                         } else {
                             return "next";
                         }
                     }
                     break;
             }
             break;
         case "p2h":
             $total_posts = coupons::totalposts($userid, $pid);
             if ($total_posts < $signup) {
                 $inelegible = 1;
             }
             if ($umonthly_discount > $total_posts) {
                 //Loophole prevention.  ;)  I doubt anyone would mind that I let them upgrade to paid packages if they don't have enough posts.  Besides,
                 //it has its own loophole prevention anyway.
                 $oweposts = 1;
             }
             switch ($pack_type) {
                 case "free":
                     if ($oweposts && !$admin) {
                         return "oweposts";
                     } else {
                         return "now";
                     }
                     break;
                 case "paid":
                     //No need to prorate it.
                     return "now";
                     break;
                 case "p2h":
                     if ($inelegible && !$admin) {
                         //They don't have the required number of posts made to be allowed to switch to this plan.
                         return "inelegible";
                     } else {
                         if ($oweposts && !$admin) {
                             return "oweposts";
                         } else {
                             //They qualify, so they can upgrade.
                             return "now";
                         }
                     }
                     break;
             }
             break;
     }
 }
示例#3
0
 public function coupon($coupon, $user, $package)
 {
     if (empty($coupon)) {
         return true;
     }
     if (type::packagetype($package) == "free") {
         return false;
     }
     $coupon_text = coupons::validate_coupon($coupon, "orders", $user, $package);
     if ($coupon_text) {
         return $coupon_text;
     }
     return false;
 }
示例#4
0
 public function content()
 {
     global $dbh, $postvar, $getvar, $instance;
     $upackinfo = main::uidtopack();
     $currentpack = $upackinfo['user_data']['pid'];
     $packsid = $postvar['packs'];
     if (!$packsid) {
         $packsid = $getvar['package'];
     }
     unset($where);
     if (is_numeric($packsid)) {
         $where[] = array("id", "=", $packsid, "AND");
     } else {
         $where[] = array("is_hidden", "=", "0", "AND");
     }
     $where[] = array("is_disabled", "=", "0", "AND");
     $where[] = array("id", "!=", $currentpack);
     $packages_order[] = array("type", "ASC");
     $packages_order[] = array("name", "ASC");
     $packages_query = $dbh->select("packages", $where, $packages_order, 0, 1);
     $upgrade_array['PACK'] = "";
     while ($packages_data = $dbh->fetch_array($packages_query)) {
         $additional = type::additional($packages_data['id']);
         $monthly = $additional['monthly'];
         $signup = $additional['signup'];
         unset($info);
         if ($packages_data['type'] == "p2h") {
             $info = "[Signup Posts: " . $signup . ", Monthly Posts: " . $monthly . "] ";
             $contribution = "<strong>Signup Posts:</strong> " . $signup . "<br><strong>Monthly Posts:</strong> " . $monthly;
         } elseif ($packages_data['type'] == "paid") {
             $info = "[" . main::money($monthly) . "] ";
             $contribution = main::money($monthly);
         } else {
             $contribution = "Free";
         }
         $packages[] = array("[" . $packages_data['type'] . "] " . $info . $packages_data['name'], $packages_data['id']);
         if ($packsid && $packsid == $packages_data['id']) {
             $prorate = upgrade::prorate($packages_data['id'], $postvar['coupon']);
             $package_array['DISABLED'] = "";
             if ($prorate == "inelegible") {
                 main::errors("You are currently not elegible for the plan selected because you do not have enough posts.<br><br>");
                 $package_array['DISABLED'] = "disabled";
             }
             if ($prorate == "owe") {
                 main::errors("You have outstanding charges on your account and can only upgrade your paid package.  Your charges are outstanding!  Keep up the good work.  lol<br><br>");
                 $package_array['DISABLED'] = "disabled";
             }
             if ($prorate == "oweposts") {
                 main::errors("You still owe your required monthly posts and can only upgrade to a paid plan until you finish your posting quota.  Our forum is a lot of fun, so come join us!  =)<br><br>");
                 $package_array['DISABLED'] = "disabled";
             }
             if ($prorate == "next" || $prorate == "check next") {
                 main::errors("If you choose this package, you'll be upgraded at the start of your next billing cycle.  If you do not wish to wait, please contact us.<br><br>");
                 $next_month = 1;
             }
             if (is_numeric($prorate) && $prorate > 0) {
                 $contribution .= " (You pay only <font color = '#FF0055'>" . main::money($prorate) . "</font> more today to upgrade.)";
             }
             if ($prorate == "check" || $prorate == "check next" || $prorate == "check now") {
                 $fuser = $postvar['fuser'];
                 $fpass = $postvar['fpass'];
                 $forum_credentials_array['FUSER'] = $fuser;
                 $forum_credentials_array['FPASS'] = $fpass;
                 $package_array['FORUMINFO'] = style::replaceVar("tpl/upgrade/forum-credentials.tpl", $forum_credentials_array);
             } else {
                 if ($packages_data['type'] == "p2h") {
                     $fuser = $upackinfo['uadditional']['fuser'];
                     $fpass = $upackinfo['uadditional']['fpass'];
                     $no_fcheck = 1;
                 }
                 $package_array['FORUMINFO'] = "";
             }
             $coupon_entry_array['COUPCODE'] = "";
             $coupon_entry_array['COUPTEXT'] = "";
             $coupon_entry_array['COUPCODEVALID'] = "";
             if ($packages_data['type'] == "p2h" && $prorate != "owe") {
                 //Paid users can enter them when they pay the invoice and free users don't need coupons.
                 $coupcode = $postvar['coupon'];
                 $validcoupon = $postvar['validcoupon'];
                 if ($postvar['addcoupon']) {
                     $uname = main::uname($_SESSION['cuser']);
                     if ($coupcode) {
                         $response = coupons::validate_coupon($coupcode, "orders", $uname, $packsid);
                         if ($response) {
                             $coup_data = coupons::coupon_data($coupcode);
                             $discount = $coup_data['p2hinitdisc'];
                             $multi_coupons = $dbh->config("multicoupons");
                             if ($multi_coupons) {
                                 $discount = $discount + upgrade::get_init_discount();
                             }
                             $total_posts = coupons::totalposts($_SESSION['cuser'], $packages_data['id']) + $discount;
                             if ($total_posts < $signup) {
                                 $error = 1;
                                 main::errors("You are currently not elegible for the plan selected because you do not have enough posts.<br><br>");
                                 $package_array['DISABLED'] = "disabled";
                                 $coupon_entry_array['COUPCODEVALID'] = "";
                             } else {
                                 $prorate = upgrade::prorate($packages_data['id'], $coupcode);
                                 if ($prorate == "next" || $prorate == "check next" || $prorate == "inelegible") {
                                     //We know they're eligible or they wouldn't be at this stage.  It just doesn't check existing coupons.
                                     main::errors("If you choose this package, you'll be upgraded at the start of your next billing cycle.  If you do not wish to wait, please contact us.<br><br>");
                                     $next_month = 1;
                                 } else {
                                     unset($_SESSION['errors']);
                                 }
                                 $package_array['DISABLED'] = "";
                                 $coupon_entry_array['COUPCODEVALID'] = $coupcode;
                             }
                             $coupon_entry_array['COUPTEXT'] = $response;
                             $coupon_entry_array['COUPCODE'] = $coupcode;
                         } else {
                             $coupon_entry_array['COUPTEXT'] = "<font color = '#FF0055'>The code entered was invalid.</font>";
                             $coupon_entry_array['COUPCODEVALID'] = "invalid";
                         }
                     } else {
                         $coupon_entry_array['COUPTEXT'] = "<font color = '#FF0055'>The code entered was invalid.</font>";
                         $coupon_entry_array['COUPCODEVALID'] = "invalid";
                     }
                 } else {
                     $coupon_entry_array['COUPTEXT'] = "";
                     $coupon_entry_array['COUPCODE'] = $coupcode;
                     $coupon_entry_array['COUPCODEVALID'] = $validcoupon;
                 }
                 $package_array['COUPONS'] = style::replaceVar("tpl/upgrade/coupon-entry.tpl", $coupon_entry_array);
             } else {
                 $package_array['COUPONS'] = "";
             }
             $package_array['CONTRIBUTION'] = $contribution;
             $package_array['PACKID'] = $packages_data['id'];
             $package_array['PACKNAME'] = $packages_data['name'];
             $package_array['PACKDESC'] = $packages_data['description'];
             $package_array['ADMIN'] = $packages_data['admin'] == "1" ? "Yes" : "No";
             $package_array['RESELLER'] = $packages_data['reseller'] == "1" ? "Yes" : "No";
             $package_array['SERVER'] = $packages_data['server'] != $upackinfo['packages']['server'] ? "Yes" : "No";
             $package_array['TYPE'] = $packages_data['type'] == "p2h" ? strtoupper($packages_data['type']) : ucfirst($packages_data['type']);
             if ($postvar['submitchange']) {
                 //Someone cheated and modified the code to re-enable the button.  This stops all that.
                 if ($package_array['DISABLED'] == "disabled") {
                     main::redirect("?page=upgrade");
                     return;
                 }
                 if ((!$fuser || !$fpass) && $packages_data['type'] == "p2h" && !$no_fcheck) {
                     $error = 1;
                     main::errors("Please enter your forum username and password to continue.<br><br>");
                 }
                 if ($fuser && $fpass && $packages_data['type'] == "p2h" && !$no_fcheck) {
                     $p2h = $instance->packtypes["p2h"];
                     $response = $p2h->checkSignup($fuser, $fpass, $postvar['packs'], $postvar['validcoupon']);
                     switch ($response) {
                         case "3":
                             $error = 1;
                             main::errors("The username, " . $fuser . ", does not exist.<br><br>");
                             break;
                         case "4":
                             $error = 1;
                             main::errors("Invalid password.<br><br>");
                             break;
                         default:
                             //We add this now so the post checks can use it and it also tacks it to the user's account for future reference.
                             $new_additional = "fuser="******",fpass=0";
                             $dbh->update("users", array("additional" => $new_additional), array("id", "=", $upackinfo['user_data']['id']), "1");
                             break;
                     }
                 }
                 if (!$error) {
                     if ($validcoupon && $validcoupon != "invalid") {
                         $coup_data = coupons::coupon_data($validcoupon);
                         $discount = $coup_data['p2hinitdisc'];
                         $db_coupcode = $validcoupon;
                     }
                     $multi_coupons = $dbh->config("multicoupons");
                     if ($multi_coupons) {
                         $discount = $discount + upgrade::get_init_discount();
                     }
                     if ($packages_data['type'] == "p2h") {
                         $total_posts = coupons::totalposts($_SESSION['cuser'], $packages_data['id']) + $discount;
                         if ($total_posts < $signup) {
                             $error = 1;
                             main::errors("You are currently not elegible for the plan selected because you do not have enough posts.<br><br>");
                         }
                     }
                     if (!$error) {
                         //The user is elegible to upgrade and all checks have passed.
                         if ($packages_data['admin']) {
                             $admin = 1;
                         }
                         if ($packages_data['server'] != $upackinfo['packages']['server']) {
                             $different_server = 1;
                         }
                         //Flag meaning:
                         //
                         //IMMEDIATE UPGRADE FLAGS
                         //
                         //0 - Upgrade is immediate.
                         //5 - If admin approves the upgrade, then the upgrade will be immediate.
                         //
                         //6 - If admin approves the upgrade, then the new account will be created on the new server and the
                         //    admin will know that they are moving to a new server so they can manually close the old account
                         //    when they're ready.
                         //
                         //7 - The new account on the new server will be immediately created and the admin will be notified that
                         //    the user is switching servers.
                         //
                         //NEXT MONTH UPGRADE FLAGS
                         //
                         //1 - Cron will upgrade them next month.
                         //2 - If admin approves this, then it will be set to 1 for cron to upgrade them next month.
                         //3 - The admin will be notified that the user wishes to be upgraded and if they approve it,
                         //    then an account on the new server will be created so they can migrate to the new server.
                         //    the admin can opt to switch the account over before next month if they both agree and the
                         //    switch will be made in the admin area manually.
                         //
                         //4 - Cron will create a new account on the new server next month and inform the admin that the
                         //    user is changing to the new server.
                         //
                         if ($next_month) {
                             $flags = "1";
                             if ($admin) {
                                 $flags = "2";
                                 if ($different_server) {
                                     $flags = "3";
                                 }
                             } else {
                                 if ($different_server) {
                                     $flags = "4";
                                 }
                             }
                         } else {
                             $flags = "0";
                             if ($admin) {
                                 $flags = "5";
                                 if ($different_server) {
                                     $flags = "6";
                                 }
                             } else {
                                 if ($different_server) {
                                     $flags = "7";
                                 }
                             }
                         }
                         $pending_upgrade = $dbh->select("upgrade", array("uid", "=", $_SESSION['cuser']));
                         //When the upgrade is finished, the entry is removed.
                         if ($pending_upgrade['id']) {
                             $upgrade_update = array("uid" => $_SESSION['cuser'], "newpack" => $packsid, "flags" => $flags, "created" => time(), "coupcode" => $db_coupcode);
                             $dbh->update("upgrade", $upgrade_update, array("id", "=", $pending_upgrade['id']), "1");
                         } else {
                             $upgrade_insert = array("uid" => $_SESSION['cuser'], "newpack" => $packsid, "flags" => $flags, "created" => time(), "coupcode" => $db_coupcode);
                             $dbh->insert("upgrade", $upgrade_insert);
                         }
                         $pending_upgrade = $dbh->select("upgrade", array("uid", "=", $_SESSION['cuser']));
                         $response = upgrade::do_upgrade($pending_upgrade['id'], "Init");
                         if ($response === false) {
                             echo "Your upgrade could not be completed as dialed.  Please check with your admin and try your upgrade again later.  The following tones are for the deaf community in hopes that they'll be able to hear again.  BEEEEEEEEEEEEEEEEEEEEEEEEP!!!!!!!!";
                         } else {
                             echo $response;
                         }
                         return;
                     }
                 }
             }
         }
     }
     if ($packsid) {
         $upgrade_array['PACK'] = style::replaceVar("tpl/upgrade/package.tpl", $package_array);
     } else {
         $select_package_array['PACKS'] = main::dropDown("packs", $packages, '', 0);
         $upgrade_array['PACK'] = style::replaceVar("tpl/upgrade/select-package.tpl", $select_package_array);
     }
     echo style::replaceVar("tpl/upgrade/upgrade.tpl", $upgrade_array);
     $page_shown = 1;
     //The page doesn't show if they refresh it after the upgrade since the loop checks if they're upgrading to the same package they are on and fails if they are.
     if (!$page_shown) {
         main::redirect("?page=upgrade");
     }
 }
示例#5
0
 public function signup($data)
 {
     global $dbh, $postvar, $getvar, $instance;
     $domain = $data['domain'];
     $username = $data['username'];
     $password = $data['password'];
     $user_email = $data['user_email'];
     $firstname = $data['firstname'];
     $lastname = $data['lastname'];
     $address = $data['address'];
     $city = $data['city'];
     $state = $data['state'];
     $zip = $data['zip'];
     $country = $data['country'];
     $phone = $data['phone'];
     $tzones = $data['tzones'];
     $coupon = $data['coupon'];
     $package = $data['package'];
     $domsub = $data['domsub'];
     $additional = $data['additional'];
     $subdomain = empty($data['subdomain']) ? 0 : $data['subdomain'];
     //Let's make sure we're actually receiving an integer as a string.
     if (!is_numeric($package) || strpos($package, ".") !== false) {
         return "The package specified is invalid.";
     }
     //Check to see if we have a valid domain type.
     if ($domsub != "dom" && $domsub != "sub") {
         return "The domain/subdomain type is unspecified in the URL.";
     }
     if ($domsub == "dom") {
         $cdom = $domain;
     } else {
         $csub2 = $domain;
         $csub = $subdomain;
     }
     unset($where);
     $where[] = array("id", "=", $package, "AND");
     $where[] = array("is_disabled", "=", "0");
     $packages_data = $dbh->select("packages", $where);
     if (!$packages_data['id']) {
         return "This package is disabled or doesn't exist.";
     }
     $package_server = $packages_data['server'];
     if ($domsub == "dom") {
         $use_dom = $cdom;
     }
     if ($domsub == "sub") {
         unset($where);
         $where[] = array("server", "=", $package_server, "AND");
         $where[] = array("domain", "=", $csub2);
         $subdomains_data = $dbh->select("subdomains", $where, 0, "1");
         if (!$subdomains_data['id']) {
             return "The chosen domain for your subdomain is not in the allowed list of domains.";
         }
         $use_dom = $csub . "." . $csub2;
     }
     if ($coupon && $packages_data['type'] != 'free') {
         $coupon_response = coupons::validate_coupon($coupon, "orders", $username, $package);
         if (!$coupon_response) {
             return "Please enter a valid coupon.";
         } else {
             $coupon_info = coupons::coupon_data($coupon);
         }
     }
     $packtype_instance = $instance->packtypes[$packages_data['type']];
     if (method_exists($packtype_instance, "signup")) {
         $packtype_signup = $packtype_instance->signup();
         //If this gives any response, it means it failed to validate the signup.
         if ($packtype_signup) {
             return $packtype_signup;
         }
     }
     $server_package_name = type::packageBackend($package);
     $serverfile = self::createServer($package);
     $packages_data = $dbh->select("packages", array("id", "=", $package));
     $extra['firstname'] = $firstname;
     $extra['lastname'] = $lastname;
     $extra['address'] = $address;
     $extra['city'] = $city;
     $extra['state'] = $state;
     $extra['zip'] = $zip;
     $extra['country'] = strtoupper($country);
     $extra['phone'] = $phone;
     $server_response = $serverfile->signup(type::packageserver($package), $packages_data['reseller'], $username, $user_email, $password, $use_dom, $server_package_name, $extra, $use_dom);
     if ($server_response !== true) {
         return $server_response;
     } else {
         $time = time();
         $ip = $_SERVER['REMOTE_ADDR'];
         $salt = crypto::salt();
         $password_hash = crypto::passhash($password, $salt);
         if ($packages_data['admin'] == "1") {
             $status = "3";
         } else {
             if ($packages_data['type'] == "paid") {
                 $status = "4";
             } else {
                 $status = "1";
             }
         }
         $users_insert = array("user" => $username, "email" => $user_email, "password" => $password_hash, "salt" => $salt, "signup" => $time, "ip" => $ip, "firstname" => $firstname, "lastname" => $lastname, "address" => $address, "city" => $city, "state" => $state, "zip" => $zip, "country" => $country, "phone" => $phone, "status" => $status, "tzadjust" => $tzones, "domain" => $use_dom, "pid" => $package, "additional" => $additional);
         $dbh->insert("users", $users_insert);
         $users_data = $dbh->select("users", array("user", "=", $username), 0, "1");
         $users_bak_insert = array("uid" => $users_data['id'], "user" => $username, "email" => $user_email, "password" => $password_hash, "salt" => $salt, "signup" => $time, "ip" => $ip, "firstname" => $firstname, "lastname" => $lastname, "address" => $address, "city" => $city, "state" => $state, "zip" => $zip, "country" => $country, "phone" => $phone, "status" => $status, "tzadjust" => $tzones, "domain" => $use_dom, "pid" => $package, "additional" => $additional);
         $dbh->insert("users_bak", $users_bak_insert);
         main::thtlog("Client Registered", 'Registered.', $users_data['id']);
         if (!$users_data['id']) {
             $return = "Your account could not be created.  Please contact your system administrator.";
         } else {
             if (!empty($coupon_info)) {
                 main::thtlog("Coupon Used", "Coupon used (" . $coupon_info['coupcode'] . ")", $users_data['id']);
                 $package_info = type::additional($package);
                 $packmonthly = $package_info['monthly'];
                 if ($packages_data['type'] == "paid") {
                     $coupon_info['p2hmonthlydisc'] = "0";
                     $coupon_info['paiddisc'] = coupons::percent_to_value("paid", $coupon_info['paidtype'], $coupon_info['paiddisc'], $packmonthly);
                 } else {
                     $coupon_info['paiddisc'] = "0";
                     $coupon_info['p2hmonthlydisc'] = coupons::percent_to_value("p2h", $coupon_info['p2hmonthlytype'], $coupon_info['p2hmonthlydisc'], $packmonthly);
                 }
                 $insert_array = array("user" => $users_data['id'], "coupcode" => $coupon_info['coupcode'], "timeapplied" => time(), "packages" => $package, "goodfor" => $coupon_info['goodfor'], "monthsgoodfor" => $coupon_info['monthsgoodfor'], "paiddisc" => $coupon_info['paiddisc'], "p2hmonthlydisc" => $coupon_info['p2hmonthlydisc']);
                 $dbh->insert("coupons_used", $insert_array);
             }
             $servers_data = $dbh->select("servers", array("id", "=", $package_server), 0, "1");
             $server_host = $servers_data['host'];
             $server_ip = $servers_data['ip'];
             $server_nameservers = $servers_data['nameservers'];
             $server_port = $servers_data['port'];
             $server_resellerport = $servers_data['resellerport'];
             $url = $dbh->config("url");
             $new_acc_email_array['CPPORT'] = $server_port;
             $new_acc_email_array['RESELLERPORT'] = $server_resellerport;
             $new_acc_email_array['SERVERIP'] = $server_ip;
             $new_acc_email_array['NAMESERVERS'] = nl2br($server_nameservers);
             $new_acc_email_array['USER'] = $username;
             $new_acc_email_array['PASS'] = $password;
             $new_acc_email_array['EMAIL'] = $user_email;
             $new_acc_email_array['FNAME'] = $firstname;
             $new_acc_email_array['LNAME'] = $lastname;
             $new_acc_email_array['DOMAIN'] = $use_dom;
             $new_acc_email_array['CONFIRM'] = $url . "client/confirm.php?u=" . $username . "&c=" . $time;
             $new_acc_email_array['PACKAGE'] = $packages_data['name'];
             if ($packages_data['admin'] == 0) {
                 if ($packages_data['reseller'] == "1") {
                     $new_acc_email = email::emailTemplate("new-reseller-account");
                 } else {
                     $new_acc_email = email::emailTemplate("new-account");
                 }
                 $return = "<strong>Your account has been created!</strong><br />You may now <a href = '../client'>login</a> to see your client area or proceed to your <a href = 'http://" . $server_host . ":" . $server_port . "'>control panel</a>. An email has been dispatched to the address on file.";
                 if (type::packagetype($package) == "paid") {
                     //Set the user up for when they finish their payment.
                     $_SESSION['clogged'] = 1;
                     $_SESSION['cuser'] = $users_data['id'];
                 }
                 $donecorrectly = true;
             } else {
                 if ($serverfile->suspend($username, type::packageserver($package), 1) == false) {
                     $return = "We could not suspend your account!  Please contact the admin to suspend it until they validate it.  lol";
                 } else {
                     $dbh->update("users", array("status" => "3"), array("id", "=", $users_data['id']));
                     if ($packages_data['reseller'] == "1") {
                         $new_acc_email = email::emailTemplate("new-reseller-account-adminval");
                     } else {
                         $new_acc_email = email::emailTemplate("new-account-adminval");
                     }
                     $admin_val_email = email::emailTemplate("admin-validation-requested");
                     $valarray['LINK'] = $dbh->config("url") . ADMINDIR . "/?page=users&sub=search&do=" . $users_data['id'];
                     email::staff($admin_val_email['subject'], $admin_val_email['content'], $valarray);
                     $return = "<strong>Your account is awaiting admin validation!</strong><br />An email has been dispatched to the address on file. You will recieve another email when the admin has looked over your account.";
                     $donecorrectly = true;
                 }
             }
             email::send($new_acc_email_array['EMAIL'], $new_acc_email['subject'], $new_acc_email['content'], $new_acc_email_array);
         }
         if ($donecorrectly && type::packagetype($package) == "paid") {
             $amountinfo = type::additional($package);
             $amount = $amountinfo['monthly'];
             $due = time() + 2592000;
             $notes = "Your hosting package invoice for this billing cycle. Package: " . $packages_data['name'];
             if (!empty($coupon_info)) {
                 $amount = max(0, $amount - $coupon_info['paiddisc']);
             }
             invoice::create($users_data['id'], $amount, $due, $notes);
             $serverfile->suspend($username, type::packageserver($package), 0, 1);
             $dbh->update("users", array("status" => $status), array("id", "=", $users_data['id']));
             if ($packages_data['admin'] != "1") {
                 $return = '<div class="errors"><b>You are being redirected to payment! It will load in a couple of seconds.</b></div>';
                 return true;
             }
         }
         return $return;
     }
 }