Beispiel #1
0
 $currency = getCurrency($userid);
 run_hook("PreServiceEdit", array("serviceid" => $id));
 run_hook("PreAdminServiceEdit", array("serviceid" => $id));
 $configoptions = getCartConfigOptions($packageid, $configoption, $billingcycle);
 $configoptionsrecurring = 0;
 foreach ($configoptions as $configoption) {
     $configoptionsrecurring += $configoption['selectedrecurring'];
     $result = select_query("tblhostingconfigoptions", "COUNT(*)", array("relid" => $id, "configid" => $configoption['id']));
     $data = mysql_fetch_array($result);
     if (!$data[0]) {
         insert_query("tblhostingconfigoptions", array("relid" => $id, "configid" => $configoption['id']));
     }
     update_query("tblhostingconfigoptions", array("optionid" => $configoption['selectedvalue'], "qty" => $configoption['selectedqty']), array("relid" => $id, "configid" => $configoption['id']));
 }
 $newamount = $autorecalcrecurringprice ? recalcRecurringProductPrice($id, $userid, $packageid, $billingcycle, $configoptionsrecurring, $promoid) : "-1";
 migrateCustomFieldsBetweenProducts($id, $packageid, true);
 $changelog = array();
 $logchangefields = array("regdate" => "Registration Date", "packageid" => "Product/Service", "server" => "Server", "domain" => "Domain", "dedicatedip" => "Dedicated IP", "paymentmethod" => "Payment Method", "firstpaymentamount" => "First Payment Amount", "amount" => "Recurring Amount", "billingcycle" => "Billing Cycle", "nextduedate" => "Next Due Date", "domainstatus" => "Status", "username" => "Username", "password" => "Password", "subscriptionid" => "Subscription ID");
 foreach ($logchangefields as $fieldname => $displayname) {
     $newval = $whmcs->get_req_var($fieldname);
     $oldval = $service_data[$fieldname];
     if ($fieldname == "regdate" || $fieldname == "nextduedate") {
         $newval = toMySQLDate($newval);
     } else {
         if ($fieldname == "password") {
             $oldval = decrypt($oldval);
         } else {
             if ($fieldname == "amount" && 0 <= $newamount) {
                 $newval = $newamount;
             }
         }
Beispiel #2
0
function doUpgrade($upgradeid)
{
    $result = select_query("tblupgrades", "", array("id" => $upgradeid));
    $data = mysql_fetch_array($result);
    $orderid = $data['orderid'];
    $type = $data['type'];
    $relid = $data['relid'];
    $originalvalue = $data['originalvalue'];
    $newvalue = $data['newvalue'];
    $upgradeamount = $data['amount'];
    $recurringchange = $data['recurringchange'];
    $result = select_query("tblorders", "promocode", array("id" => $orderid));
    $data = mysql_fetch_array($result);
    $promocode = $data['promocode'];
    if ($type == "package") {
        $newvalue = explode(",", $newvalue);
        $newpackageid = $newvalue[0];
        $newbillingcycle = $newvalue[1];
        $changevalue = "amount";
        if ($newbillingcycle == "free") {
            $newbillingcycle = "Free Account";
        } else {
            if ($newbillingcycle == "onetime") {
                $newbillingcycle = "One Time";
                $changevalue = "firstpaymentamount";
                $recurringchange = $upgradeamount;
            } else {
                if ($newbillingcycle == "monthly") {
                    $newbillingcycle = "Monthly";
                } else {
                    if ($newbillingcycle == "quarterly") {
                        $newbillingcycle = "Quarterly";
                    } else {
                        if ($newbillingcycle == "semiannually") {
                            $newbillingcycle = "Semi-Annually";
                        } else {
                            if ($newbillingcycle == "annually") {
                                $newbillingcycle = "Annually";
                            } else {
                                if ($newbillingcycle == "biennially") {
                                    $newbillingcycle = "Biennially";
                                } else {
                                    if ($newbillingcycle == "triennially") {
                                        $newbillingcycle = "Triennially";
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        $result = select_query("tblhosting", "billingcycle", array("id" => $relid));
        $data = mysql_fetch_array($result);
        $billingcycle = $data['billingcycle'];
        if ($billingcycle == "Free Account") {
            $newnextdue = getInvoicePayUntilDate(date("Y-m-d"), $newbillingcycle, true);
            update_query("tblhosting", array("nextduedate" => $newnextdue, "nextinvoicedate" => $newnextdue), array("id" => $relid));
        }
        if (!function_exists("migrateCustomFieldsBetweenProducts")) {
            require ROOTDIR . "/includes/customfieldfunctions.php";
        }
        migrateCustomFieldsBetweenProducts($relid, $newpackageid);
        update_query("tblhosting", array("packageid" => $newpackageid, "billingcycle" => $newbillingcycle, "" . $changevalue => "+=" . $recurringchange), array("id" => $relid));
        $result = full_query("SELECT tblinvoiceitems.id,tblinvoiceitems.invoiceid FROM tblinvoices INNER JOIN tblinvoiceitems ON tblinvoiceitems.invoiceid=tblinvoices.id INNER JOIN tblhosting ON tblhosting.id=tblinvoiceitems.relid WHERE tblinvoices.status='Unpaid' AND tblinvoiceitems.type='Hosting' AND tblhosting.id=" . (int) $relid . " ORDER BY tblinvoiceitems.duedate DESC");
        $data = mysql_fetch_array($result);
        $invitemid = $data['id'];
        $inviteminvoiceid = $data['invoiceid'];
        if ($invitemid) {
            update_query("tblinvoices", array("status" => "Cancelled"), array("id" => $inviteminvoiceid));
            update_query("tblinvoiceitems", array("duedate" => "0000-00-00"), array("id" => $invitemid));
            full_query("UPDATE tblhosting SET nextinvoicedate=nextduedate WHERE id=" . (int) $relid);
        }
        if (!function_exists("getCartConfigOptions")) {
            require ROOTDIR . "/includes/configoptionsfunctions.php";
        }
        $configoptions = getCartConfigOptions($newpackageid, "", $newbillingcycle);
        foreach ($configoptions as $configoption) {
            $result = select_query("tblhostingconfigoptions", "COUNT(*)", array("relid" => $relid, "configid" => $configoption['id']));
            $data = mysql_fetch_array($result);
            if (!$data[0]) {
                insert_query("tblhostingconfigoptions", array("relid" => $relid, "configid" => $configoption['id'], "optionid" => $configoption['selectedvalue']));
                continue;
            }
        }
        run_hook("AfterProductUpgrade", array("upgradeid" => $upgradeid));
    } else {
        if ($type == "configoptions") {
            $tempvalue = explode("=>", $originalvalue);
            $configid = $tempvalue[0];
            $result = select_query("tblproductconfigoptions", "", array("id" => $configid));
            $data = mysql_fetch_array($result);
            $optiontype = $data['optiontype'];
            $result = select_query("tblhostingconfigoptions", "COUNT(*)", array("relid" => $relid, "configid" => $configid));
            $data = mysql_fetch_array($result);
            if (!$data[0]) {
                insert_query("tblhostingconfigoptions", array("relid" => $relid, "configid" => $configid));
            }
            if ($optiontype == 1 || $optiontype == 2) {
                update_query("tblhostingconfigoptions", array("optionid" => $newvalue), array("relid" => $relid, "configid" => $configid));
            } else {
                if ($optiontype == 3 || $optiontype == 4) {
                    update_query("tblhostingconfigoptions", array("qty" => $newvalue), array("relid" => $relid, "configid" => $configid));
                }
            }
            update_query("tblhosting", array("amount" => "+=" . $recurringchange), array("id" => $relid));
            run_hook("AfterConfigOptionsUpgrade", array("upgradeid" => $upgradeid));
        }
    }
    if ($promocode) {
        $result = select_query("tblpromotions", "id,type,recurring,value", array("code" => $promocode));
        $data = mysql_fetch_array($result);
        $promoid = $data[0];
        $promotype = $data[1];
        $promorecurring = $data[2];
        $promovalue = $data[3];
        if ($promorecurring) {
            $recurringamount = recalcRecurringProductPrice($relid);
            if ($promotype == "Percentage") {
                $discount = $recurringamount * ($promovalue / 100);
                $recurringamount = $recurringamount - $discount;
            } else {
                $recurringamount = $recurringamount < $promovalue ? "0" : $recurringamount - $promovalue;
            }
            update_query("tblhosting", array("amount" => $recurringamount, "promoid" => $promoid), array("id" => $relid));
        } else {
            update_query("tblhosting", array("promoid" => "0"), array("id" => $relid));
        }
    } else {
        update_query("tblhosting", array("promoid" => "0"), array("id" => $relid));
    }
    if ($type == "package" || $type == "configoptions") {
        $data = get_query_vals("tblhosting", "userid,packageid", array("id" => $relid));
        $userid = $data['userid'];
        $pid = $data['packageid'];
        $result = select_query("tblproducts", "servertype,upgradeemail", array("id" => $pid));
        $data = mysql_fetch_array($result);
        $servertype = $data['servertype'];
        $upgradeemail = $data['upgradeemail'];
        if ($servertype) {
            if (!function_exists("getModuleType")) {
                require dirname(__FILE__) . "/modulefunctions.php";
            }
            $result = ServerChangePackage($relid);
            if ($result != "success") {
                logActivity("Automatic Product/Service Upgrade Failed - Service ID: " . $relid, $userid);
            } else {
                logActivity("Automatic Product/Service Upgrade Successful - Service ID: " . $relid, $userid);
                if ($upgradeemail) {
                    $result = select_query("tblemailtemplates", "name", array("id" => $upgradeemail));
                    $data = mysql_fetch_array($result);
                    $emailtplname = $data[0];
                    sendMessage($emailtplname, $relid);
                }
            }
        } else {
            insert_query("tbltodolist", array("date" => "now()", "title" => "Manual Upgrade Required", "description" => "Manual Upgrade Required for Service ID: " . $relid, "admin" => "", "status" => "Pending", "duedate" => date("Y-m-d")));
        }
    }
    update_query("tblupgrades", array("status" => "Completed"), array("id" => $upgradeid));
}