require "include/invoice_menu.php"; echo '<h1>Opprett faktura - feilmelding</h1>' . chr(10); echo 'Problemer med faktura. Vennligst ta kontakt.'; echo '<br><br>'; echo 'Feilmelding:<br>'; echo $invoice->error(); exit; } else { $error_msg = $invoice->error(); $error = $invoice->inndata_error; // array $preview = false; } } } elseif (!count($warning)) { if (!$invoice->create($TMP_invoice_extra_content['invoice_time_due'], $TMP_invoice_extra_content['invoice_time'], $TMP_invoice_content, $TMP_invoice_extra_content)) { if ($invoice->error_code != '100') { require "include/invoice_menu.php"; echo '<h1>Opprett faktura - feilmelding</h1>' . chr(10); echo 'Problemer med faktura. Vennligst ta kontakt.'; echo '<br><br>'; echo 'Feilmelding:<br>'; echo $invoice->error(); exit; } else { $error_msg = $invoice->error(); $error = $invoice->inndata_error; // array } } else { // Redirect
private function create_invoice() { $this->invoice_id = invoice::create($this->order_id, $this->lang_ui); }
public function cron() { global $dbh, $postvar, $getvar, $instance; $packages_query = $dbh->select("packages", array("type" => "paid"), 0, 0, 1); $packages_num_rows = $dbh->num_rows($packages_query); //Do we have paid packages? if ($packages_num_rows) { while ($packages_data = $dbh->fetch_array($packages_query)) { $i++; //Do we have multiple packages and aren't on the last one? if ($packages_data < $i) { //Did we already pull one package? If so, we don't set the flag for the parenthesis. if ($pulled_one) { $where[] = array("pid", "=", $packages_data['id'], "OR"); //We are on the first listing of the paid packages, so we set the flag for the opening parenthesis and mark it that we pulled one already. } else { $where[] = array("pid", "=", $packages_data['id'], "OR", 1); $pulled_one = 1; } } else { //Are we on the last listing of paid listings? If so, we close the parenthesis by setting that flag. if ($pulled_one) { $where[] = array("pid", "=", $packages_data['id'], "", 1); //We only had one listing, so we don't use parenthesis and we don't use "OR." } else { $where[] = array("pid", "=", $packages_data['id']); } } //So we can later grab the package's information without needing to repull this data. $packages_info[$packages_data['id']] = $packages_data; } $time = time(); //Look at every last invoice. $invoices_query = $dbh->select("invoices"); while ($invoices_data = $dbh->fetch_array($invoices_query)) { $uid = $invoices_data['uid']; $client = $dbh->client($uid); //Skip this invoice if it belongs to a user marked as a free user. if ($client['freeuser']) { continue; } //If the invoice is older than 30 days and we haven't issued a new invoice yet... (This makes sure the user is still on the package //before issuing a new invoice for it.) if ($time > $invoices_data['created'] + 2592000 && !in_array($uid, $invoiced_to) && $invoices_data['pid'] == $client['pid']) { $pack_additional = type::additional($client['pid']); $amount = coupons::get_discount("paid", $pack_additional['monthly'], $client['user']); invoice::create($uid, $amount, $time, "Your hosting package invoice for this billing cycle. Package: " . $packages_info[$client['pid']]['name']); $invoiced_to[] = $uid; //Track what clients have been sent a new invoice. } $lastmonth = $time - 2592000; $suspenddays = $dbh->config('suspensiondays'); $terminationdays = $suspenddays + $dbh->config('terminationdays'); $suspendseconds = $suspenddays * 24 * 60 * 60; $terminateseconds = $dbh->config('terminationdays') * 24 * 60 * 60; //If we have an unpaid bill that's greater than $0 and it's past it's due date... if ($invoices_data['due'] < $time and $invoices_data['is_paid'] == 0 && $invoices_data['amount'] > 0) { //If we have a bill that's overdue by $terminationdays + $suspenddays, then we terminate the account... if ($time - $suspendseconds - $terminateseconds > $invoices_data['due']) { server::terminate($uid, "Your account was overdue for more than " . $terminationdays . " days."); $checked_term = 1; //If we have a bill that's overdue by $suspenddays and the client is active, then we suspend them... //Just an FYI, if I start(ed) charging for this script, check The Pirate Bay for this script as I always upload my payware stuff there since I know not everyone can afford to pay me. } elseif ($time - $suspendseconds > $invoices_data['due'] && $client['status'] == '1') { server::suspend($uid, "Your account is overdue. Please log in and pay your invoice to bring your account out of suspension."); } } } //If the user does not have an invoice yet and never had one, this will create one for them. The portion above //handles creating NEW invoices. (It checks for outdated ones and such.) $users_query = $dbh->select("users", $where, 0, 0, 1); while ($users_data = $dbh->fetch_array($users_query)) { //Skip this user if its marked as a free user. if ($users_data['freeuser']) { continue; } $invoice_data = $dbh->select("invoices", array("pid", "=", $users_data['pid'])); if (!$invoice_data['id']) { $monthly = type::additional($users_data['pid']); $amount = $monthly['monthly']; $amount = coupons::get_discount("paid", $amount, $users_data['id']); invoice::create($users_data['id'], $amount, $time + 30 * 24 * 60 * 60, "Your hosting package invoice for this billing cycle. Package: " . $packages_info[$users_data['pid']]['name']); // Create Invoice +30 Days } } } }
public function do_upgrade($upgradeid, $mode, $no_errors_out = 0) { global $dbh, $postvar, $getvar, $instance; //$mode // //Init - When the upgrade info is added, we call this function. //Update - When cron or an admin does something with this function, we check to see if various tasks are ready to be performed. //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. // $upgrade_data = $dbh->select("upgrade", array("id", "=", $upgradeid)); $userid = $upgrade_data['uid']; $newpack = $upgrade_data['newpack']; $flags = $upgrade_data['flags']; $created = $upgrade_data['created']; $coupcode = $upgrade_data['coupcode']; $user_data = main::uidtopack($userid); $current_pack_type = $user_data['packages']['type']; $current_pack_name = $user_data['packages']['name']; $current_pack_id = $user_data['packages']['id']; $user_info = $dbh->select("users", array("id", "=", $userid)); $user_email = $user_info['email']; $username = $user_info['user']; $new_plan_data = $dbh->select("packages", array("id", "=", $newpack)); $newpack_name = $new_plan_data['name']; $new_plan_additional = type::additional($newpack); $new_server_data = $dbh->select("servers", array("id", "=", $new_plan_data['server'])); $new_server_name = $new_server_data['name']; $old_server_data = $dbh->select("servers", array("id", "=", $user_data['packages']['server'])); $old_server_name = $old_server_data['name']; switch ($flags) { case "0": $upgrade = 1; break; case "1": $upgrade_today = self::upgrade_today($current_pack_type, $userid); if ($upgrade_today) { $upgrade = 1; } break; case "2": if ($mode = "Init") { $admin_approval = 1; } else { //If its already the day for the upgrade, then we can do the upgrade now. $upgrade_today = self::upgrade_today($current_pack_type, $userid); if ($upgrade_today) { $upgrade = 1; } if (!$upgrade) { $dbh->update("upgrade", array("flags" => "1"), array("id", "=", $upgradeid), "1"); } } break; case "3": if ($mode = "Init") { $admin_approval = 1; $new_server = 1; } else { //If its already the day for the upgrade, then we can do the upgrade now. $upgrade_today = self::upgrade_today($current_pack_type, $userid); if ($upgrade_today) { $upgrade = 1; $new_server = 1; } if (!$upgrade) { $dbh->update("upgrade", array("flags", "=", "4"), array("id", "=", $upgradeid), "1"); } } break; case "4": //If its already the day for the upgrade, then we can do the upgrade now. $upgrade_today = self::upgrade_today($current_pack_type, $userid); if ($upgrade_today) { $upgrade = 1; $new_server = 1; $admin_inform = 1; } break; case "5": if ($mode = "Init") { $admin_approval = 1; $immediate = 1; } else { $upgrade = 1; } break; case "6": if ($mode = "Init") { $admin_approval = 1; $new_server = 1; $immediate = 1; } else { $upgrade = 1; $new_server = 1; } break; case "7": $upgrade = 1; $new_server = 1; $admin_inform = 1; break; } $adminmsg_array['USER'] = $username; $adminmsg_array['NEWPLAN'] = $newpack_name; $adminmsg_array['OLDPLAN'] = $current_pack_name; $adminmsg_array['NEWSERVER'] = $new_server_name; $adminmsg_array['OLDSERVER'] = $old_server_name; if ($immediate) { $adminmsg_array['NEXTMONTH_IMMEDIATELY'] = "immediately"; } else { $adminmsg_array['NEXTMONTH_IMMEDIATELY'] = "next billing cycle"; } $url = $dbh->config("url"); if (ADMINDIR) { $admin_dir = ADMINDIR; } else { $admin_dir = "admin"; } $adminmsg_array['APPROVE_LINK'] = $url . $admin_dir . "/?page=users&sub=upgrade"; if ($upgrade) { if ($new_plan_data['type'] == "paid") { $new_invoice_text = " A new invoice has been generated."; if ($current_pack_type == "paid" && $user_data['additional']['monthly'] >= $new_plan_additional['monthly']) { unset($new_invoice_text); } } $serverfile = server::createServer($newpack); if ($new_server) { $new_serv_pass_for_email = time(); $domsub = "sub"; //Checks to see if the domain contains 3 or more segments and fails if there are more than 3 and if the last one two aren't TLD portions, it fails, //so we can see if this is a subdomain this way. if (check::domain($user_data['user_data']['domain'])) { $domsub = "dom"; } $done = $serverfile->signup(type::packageserver($newpack), $new_plan_data['reseller'], $username, $user_email, $new_serv_pass_for_email, $user_data['user_data']['domain'], type::packageBackend($newpack), $domsub); if ($done === true) { if ($new_plan_data['reseller']) { $uemaildata = email::emailTemplate("upgrade-newserv-resell-welcome"); } else { $uemaildata = email::emailTemplate("upgrade-newserv-welcome"); } $change_tht = 1; main::errors("Your upgrade request has been completed. An email has been sent to you detailing your upgraded account on the new server." . $new_invoice_text); } else { return false; } } else { if ($serverfile->canupgrade) { $done = $serverfile->do_upgrade($new_plan_data['server'], type::packageBackend($newpack), $username); if ($done === true) { if ($new_plan_data['reseller']) { $uemaildata = email::emailTemplate("upgrade-resell-welcome"); } else { $uemaildata = email::emailTemplate("upgrade-welcome"); } $change_tht = 1; main::errors("Your upgrade request has been completed. An email has been sent to you detailing your upgraded account." . $new_invoice_text); } else { return false; } } else { $emaildata = email::emailTemplate("manual-upgrade-request"); main::errors("Your upgrade request has been added and the administrator has been emailed."); } } if ($uemaildata) { $welcomeemail_array['USER'] = $username; $welcomeemail_array['EMAIL'] = $user_email; $welcomeemail_array['PACKAGE'] = $newpack_name; $welcomeemail_array['SERVERIP'] = $new_server_data['ip']; $welcomeemail_array['LNAME'] = $user_info['lastname']; $welcomeemail_array['FNAME'] = $user_info['firstname']; $welcomeemail_array['CPPORT'] = $new_server_data['port']; $welcomeemail_array['PASS'] = $new_serv_pass_for_email; $welcomeemail_array['RESELLERPORT'] = $new_server_data['resellerport']; $welcomeemail_array['NAMESERVERS'] = nl2br($new_server_data['nameservers']); $welcomeemail_array['DOMAIN'] = $user_data['user_data']['domain']; email::send($user_email, $uemaildata['subject'], $uemaildata['content'], $welcomeemail_array); } } else { main::errors("Your upgrade request has been added."); } //Now we need to send the admin a dozen emails. lol FIRE! Nah, we'll only ever send them one email at a time. ;) if ($admin_approval) { if ($new_server) { $emaildata = email::emailTemplate("upgrade-newserv-adminval"); } else { $emaildata = email::emailTemplate("upgrade-adminval"); } } if ($admin_inform) { $emaildata = email::emailTemplate("notify-upgrade-new-server"); } if (!$emaildata && $change_tht) { $emaildata = email::emailTemplate("notify-upgrade"); } if ($emaildata) { email::staff($emaildata['subject'], $emaildata['content'], $adminmsg_array); } if ($change_tht) { main::thtlog("Client Upgraded", "Upgraded from " . $current_pack_name . " to " . $newpack_name, $userid, ""); if ($current_pack_type == "paid") { unset($where); $where[] = array("uid", "=", $userid, "AND"); $where[] = array("pid", "=", ""); $dbh->update("invoices", array("pid" => $current_pack_id), $where); } if ($new_plan_data['type'] != "p2h") { $dbh->delete("coupons_p2h", array("uid", "=", $userid)); } $user_pack_data = $user_data['user_data']; $users_update = array("pid" => $newpack, "domain" => $user_pack_data['domain'], "additional" => $user_pack_data['additional']); $dbh->update("users", $users_update, array("id", "=", $userid), "1"); $dbh->update("users_bak", $users_update, array("id", "=", $userid), "1"); if ($current_pack_type == "paid") { unset($where); $where[] = array("user", "=", $userid, "AND"); $where[] = array("disabled", "=", "0"); $coupons_used_query = $dbh->select("coupons_used", $where, 0, 0, 1); while ($coupons_used_data = $dbh->fetch_array($coupons_used_query)) { $had_coupons .= $coupons_used_data['coupcode'] . ","; $couponvals .= $coupons_used_data['paiddisc'] . ","; } $had_coupons = substr($had_coupons, 0, strlen($had_coupons) - 1); $couponvals = substr($couponvals, 0, strlen($couponvals) - 1); if (!$had_coupons) { $had_coupons = "0"; $couponvals = "0"; } $invoices_update = array("changed_plan" => "1", "hadcoupons" => $had_coupons, "couponvals" => $couponvals); unset($where); $where[] = array("uid", "=", $userid, "AND"); $where[] = array("hadcoupons", "=", ""); $dbh->update("invoices", $invoices_update, $where); } $multi_coupons = $dbh->config("multicoupons"); if ($coupcode || $new_plan_data['type'] == "free") { if (!$multi_coupons || $new_plan_data['type'] == "free") { $coupons_used_update = array("disabled" => "2", "datedisabled" => time()); $dbh->update("coupons_used", $coupons_used_update, array("user", "=", $userid)); } } if ($new_plan_data['type'] != "free") { if ($new_plan_data['type'] == "paid") { unset($where); $where[] = array("uid", "=", $userid, "AND"); $where[] = array("pid", "=", $current_pack_id); $last_invoice = $dbh->select("invoices", $where, array("id", "DESC"), "1"); if ($user_data['additional']['monthly'] < $new_plan_additional['monthly'] && $current_pack_type == "paid" && $last_invoice) { unset($where); $where[] = array("uid", "=", $userid, "AND"); $where[] = array("pid", "=", $current_pack_id); $last_invoice = $dbh->select("invoices", $where, array("id", "DESC"), "1"); if (!$multi_coupons) { unset($where); $where[] = array("user", "=", $userid, "AND"); $where[] = array("disabled", "=", "0"); $current_coupon = $dbh->select("coupons_used", $where); $coupcode = $current_coupon['coupcode']; coupons::remove_coupon($current_coupon['id'], $newpack, $last_invoice['id'], $userid); } else { unset($where); $where[] = array("user", "=", $userid, "AND"); $where[] = array("disabled", "=", "0"); $coupons_used_query = $dbh->select("coupons_used", $where, 0, 0, 1); while ($coupons_used_data = $dbh->fetch_array($coupons_used_query)) { $use_coupons[] = $coupons_used_data['coupcode']; coupons::remove_coupon($coupons_used_data['id'], $newpack, $last_invoice['id'], $userid); } } unset($where); $where[] = array("uid", "=", $userid, "AND"); $where[] = array("pid", "=", $current_pack_id); $last_invoice = $dbh->select("invoices", $where, array("id", "DESC"), "1"); $invoice_update_array = array("amount" => $new_plan_additional['monthly'], "due" => $last_invoice['due'] + 7 * 24 * 60 * 60, "pid" => $newpack, "hadcoupons" => "", "couponvals" => "", "changed_plan" => "0", "is_paid" => "0"); $where[] = array("id", "=", $last_invoice['id']); $dbh->update("invoices", $invoice_update_array, $where); } else { $amount = $new_plan_additional['monthly']; if (!$coupcode) { unset($where); $where[] = array("user", "=", $userid, "AND"); $where[] = array("disabled", "=", "0"); $coupcode = $dbh->select("coupons_used", $where); $coupcode = $coupcode['coupcode']; } $coupon_data = coupons::coupon_data($coupcode); $coupon_data['paiddisc'] = coupons::percent_to_value("paid", "paidtype", "paiddisc", $amount); if ($multi_coupons) { $amount = coupons::get_discount("paid", $amount, $userid) - $coupon_data['paiddisc']; } else { $amount = max(0, $amount - $coupon_data['paiddisc']); } $due = time() + 2592000; $notes = "Your hosting package invoice for this billing cycle. Package: " . $newpack_name; invoice::create($userid, $amount, $due, $notes); $last_invoice = $dbh->select("invoices", array("uid", "=", $userid), array("id", "DESC"), "1"); $dbh->update("invoices", array("pid" => $newpack), array("id", "=", $last_invoice['id']), "1"); unset($where); $where[] = array("uid", "=", $userid, "AND"); $where[] = array("pid", "=", $newpack); $last_invoice = $dbh->select("invoices", $where, array("id", "DESC"), "1"); if (!$multi_coupons) { unset($where); $where[] = array("user", "=", $userid, "AND"); $where[] = array("disabled", "=", "0"); $current_coupon = $dbh->select("coupons_used", $where); coupons::remove_coupon($current_coupon['id'], $newpack, $last_invoice['id'], $userid); } else { unset($where); $where[] = array("user", "=", $userid, "AND"); $where[] = array("disabled", "=", "0"); $coupons_used_query = $dbh->select("coupons_used", $where, 0, 0, 1); while ($coupons_used_data = $dbh->fetch_array($coupons_used_query)) { $use_coupons[] = $coupons_used_data['coupcode']; coupons::remove_coupon($coupons_used_data['id'], $newpack, $last_invoice['id'], $userid); } } } } unset($where); $where[] = array("uid", "=", $userid, "AND"); $where[] = array("pid", "=", $newpack); $last_invoice = $dbh->select("invoices", $where, array("id", "DESC"), "1"); if ($coupcode) { $coupon_data = $dbh->select("coupons", array("coupcode", "=", $coupcode)); coupons::use_coupon($coupon_data['id'], $newpack, $last_invoice['id'], $userid, "orders"); } if ($multi_coupons && $use_coupons) { for ($i = 0; $i < count($use_coupons); $i++) { $coupcode = $use_coupons[$i]; $coupon_data = $dbh->select("coupons", array("coupcode", "=", $coupcode)); coupons::use_coupon($coupon_data['id'], $newpack, $last_invoice['id'], $userid, "orders"); } } } //We now remove the upgrade stub. $dbh->delete("upgrade", array("uid", "=", $userid)); } unset($where); $where[] = array("amount", "=", "0", "OR"); $where[] = array("amount", "=", "0.00"); $dbh->update("invoices", array("is_paid" => "1"), $where); if (!$no_errors_out) { echo "<ERRORS>"; } }
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; } }