Esempio n. 1
0
 if (!check::human($postvar['human'])) {
     main::errors(nl2br("You're not human.  Neither am I for that matter.  =P  lol  Check the code you entered for the captcha."));
 }
 $coupon_chk = check::coupon($postvar['coupon'], $postvar['username'], $getvar['package']);
 //Can return text as well.  Text is seen as true unless it's "0"
 $getvar['coupon'] = $postvar['coupon'];
 //For any types (Ex. p2h) that might need to grab a coupon.
 if (!$coupon_chk) {
     main::errors(nl2br("The coupon code entered was invalid."));
 }
 $domain = $postvar['cdom'];
 if (!check::domain($postvar['cdom']) && $postvar['cdom']) {
     main::errors(nl2br("Your domain is in the wrong format.  Domains must be alphanumerical and have a valid TLD.  (Domain suffix)"));
 }
 if ($postvar['csub2'] || $postvar['csub']) {
     if (!check::domain($postvar['csub2'])) {
         main::errors(nl2br("Your domain is in the wrong format.  Domains must be alphanumerical and have a valid TLD.  (Domain suffix)"));
     } else {
         if (!ctype_alnum($postvar['csub'])) {
             main::errors(nl2br("Your chosen subdomain must be alphanumerical."));
         }
         $domain = $postvar['csub2'];
         $subdomain = $postvar['csub'];
     }
 }
 if (!check::extra_fields()) {
     main::errors(nl2br("The fields in step 4 contain invalid characters.  (>, <, or #)"));
 }
 if (main::errors()) {
     $order_form_array['ERRORS'] = style::replaceVar("tpl/order/errors.tpl", array()) . "<br><br>";
 } else {
Esempio n. 2
0
 public function getTransferDataProvider()
 {
     $result = ['success' => null, 'error' => null];
     $this->domains = trim($this->domains);
     $list = ArrayHelper::csplit($this->domains, "\n");
     foreach ($list as $key => $value) {
         $strCheck .= "\n{$value}";
         $strCheck = trim($strCheck);
         preg_match("/^([a-z0-9][0-9a-z.-]+)( +|\t+|,|;)(.*)/i", $value, $matches);
         if ($matches) {
             $domain = check::domain(trim(strtolower($matches[1])));
             if ($domain) {
                 $password = check::password(trim($matches[3]));
                 if ($password) {
                     $doms[$domain] = compact('domain', 'password');
                 } else {
                     $dom2err[$domain] = 'wrong input password';
                 }
             } else {
                 $dom2err[$value] = 'unknown error';
             }
         } else {
             $dom2err[$value] = 'empty code';
         }
     }
     return $result;
 }
Esempio n. 3
0
 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>";
     }
 }