Exemplo n.º 1
0
function drawRenewalTables()
{
    global $pro_mysql_product_table;
    global $pro_mysql_admin_table;
    global $pro_mysql_ssl_ips_table;
    global $pro_mysql_product_table;
    global $pro_mysql_vps_table;
    global $pro_mysql_dedicated_table;
    global $pro_mysql_ssl_ips_table;
    global $pro_mysql_client_table;
    global $pro_mysql_domain_table;
    global $pro_mysql_completedorders_table;
    global $pro_mysql_pay_table;
    global $pro_mysql_spent_type_table;
    global $pro_mysql_spent_providers_table;
    global $pro_mysql_spent_moneyout_table;
    global $pro_mysql_companies_table;
    global $pro_mysql_spent_bank_table;
    global $pro_mysql_client_table;
    global $pro_mysql_new_admin_table;
    global $secpayconf_currency_letters;
    global $rub;
    global $conf_vps_renewal_shutdown;
    get_secpay_conf();
    if (!isset($_REQUEST["sousrub"]) || $_REQUEST["sousrub"] == "") {
        $sousrub = "renewalreport";
    } else {
        $sousrub = $_REQUEST["sousrub"];
    }
    $out = '<ul class="box_wnb_content_nb">';
    if ($sousrub == "renewalreport") {
        $out .= "<li class=\"box_wnb_content_nb_item_select\"><a href=\"?rub={$rub}\"><img width=\"16\" height=\"16\" src=\"gfx/skin/bwoup/gfx/tabs/p_clientinterface.gif\" align=\"absmiddle\" border=\"0\"> " . _("Renewal report") . "</a></li>";
    } else {
        $out .= "<li class=\"box_wnb_content_nb_item\"><a href=\"?rub={$rub}\"><img width=\"16\" height=\"16\" src=\"gfx/skin/bwoup/gfx/tabs/p_clientinterface.gif\" align=\"absmiddle\" border=\"0\"> " . _("Renewal repport") . "</a></li>";
    }
    $out .= '<li class="box_wnb_content_nb_item_vsep"></li>';
    if ($sousrub == "spent") {
        $out .= "<li class=\"box_wnb_content_nb_item_select\"><a href=\"?rub={$rub}&sousrub=spent\"><img width=\"16\" height=\"16\" src=\"gfx/skin/bwoup/gfx/config-icon/box_wnb_nb_picto-payementgateway.gif\" align=\"absmiddle\" border=\"0\">" . _("Money spent") . "</a></li>";
    } else {
        $out .= "<li class=\"box_wnb_content_nb_item\"><a href=\"?rub={$rub}&sousrub=spent\"><img width=\"16\" height=\"16\" src=\"gfx/skin/bwoup/gfx/config-icon/box_wnb_nb_picto-payementgateway.gif\" align=\"absmiddle\" border=\"0\">" . _("Money spent") . "</a></li>";
    }
    $out .= '<li class="box_wnb_content_nb_item_vsep"></li>';
    if ($sousrub == "bank") {
        $out .= "<li class=\"box_wnb_content_nb_item_select\"><a href=\"?rub={$rub}&sousrub=bank\"><img width=\"16\" height=\"16\" src=\"gfx/skin/bwoup/gfx/config-icon/box_wnb_nb_picto-payementgateway.gif\" align=\"absmiddle\" border=\"0\">" . _("Bank accounts & payments") . "</a></li>";
    } else {
        $out .= "<li class=\"box_wnb_content_nb_item\"><a href=\"?rub={$rub}&sousrub=bank\"><img width=\"16\" height=\"16\" src=\"gfx/skin/bwoup/gfx/config-icon/box_wnb_nb_picto-payementgateway.gif\" align=\"absmiddle\" border=\"0\">" . _("Bank accounts & payments") . "</a></li>";
    }
    $out .= '<li class="box_wnb_content_nb_item_vsep"></li>';
    if ($sousrub == "provideredit") {
        $out .= "<li class=\"box_wnb_content_nb_item_select\"><a href=\"?rub={$rub}&sousrub=provideredit\"><img width=\"16\" height=\"16\" src=\"gfx/skin/bwoup/gfx/tabs/p_admineditor.gif\" align=\"absmiddle\" border=\"0\">" . _("Upstream provider editor") . "</a></li>";
    } else {
        $out .= "<li class=\"box_wnb_content_nb_item\"><a href=\"?rub={$rub}&sousrub=provideredit\"><img width=\"16\" height=\"16\" src=\"gfx/skin/bwoup/gfx/tabs/p_admineditor.gif\" align=\"absmiddle\" border=\"0\">" . _("Upstream provider editor") . "</a></li>";
    }
    $out .= "</ul>";
    switch ($sousrub) {
        case "spent":
            $ret = dateSelector("spent_moneyout", "invoice_date", "date_selector");
            $out .= $ret["text"];
            $where_condition = $ret["where_condition"];
            $q = "SELECT * FROM {$pro_mysql_spent_providers_table} ";
            $r = mysql_query($q) or die("Cannot query {$q} line " . __LINE__ . " file " . __FILE__ . " sql said: " . mysql_error());
            $n = mysql_num_rows($r);
            $prov_popup_id = array();
            $prov_popup_names = array();
            for ($i = 0; $i < $n; $i++) {
                $a = mysql_fetch_array($r);
                $prov_popup_id[] = $a["id"];
                $prov_popup_names[] = $a["quick_name"];
            }
            $q = "SELECT * FROM {$pro_mysql_spent_type_table} ";
            $r = mysql_query($q) or die("Cannot query {$q} line " . __LINE__ . " file " . __FILE__ . " sql said: " . mysql_error());
            $n = mysql_num_rows($r);
            $spent_type_popup_id = array();
            $spent_type_names = array();
            for ($i = 0; $i < $n; $i++) {
                $a = mysql_fetch_array($r);
                $spent_type_popup_id[] = $a["id"];
                $spent_type_names[] = $a["label"];
            }
            $q = "SELECT * FROM {$pro_mysql_companies_table} ";
            $r = mysql_query($q) or die("Cannot query {$q} line " . __LINE__ . " file " . __FILE__ . " sql said: " . mysql_error());
            $n = mysql_num_rows($r);
            $company_paying_popup_id = array();
            $company_paying_names = array();
            for ($i = 0; $i < $n; $i++) {
                $a = mysql_fetch_array($r);
                $company_paying_popup_id[] = $a["id"];
                $company_paying_names[] = $a["name"];
            }
            $q = "SELECT * FROM {$pro_mysql_spent_bank_table} ";
            $r = mysql_query($q) or die("Cannot query {$q} line " . __LINE__ . " file " . __FILE__ . " sql said: " . mysql_error());
            $n = mysql_num_rows($r);
            $bank_popup_id = array();
            $bank_names = array();
            for ($i = 0; $i < $n; $i++) {
                $a = mysql_fetch_array($r);
                $bank_popup_id[] = $a["id"];
                $bank_names[] = $a["acct_name"];
            }
            $dsc = array("title" => _("List of payments done by your hosting company"), "table_name" => $pro_mysql_spent_moneyout_table, "action" => "money_out_editor", "forward" => array("rub", "sousrub"), "print_where_condition" => $where_condition, "order_by" => "invoice_date", "cols" => array("id" => array("type" => "id", "display" => "no", "legend" => "id"), "label" => array("type" => "text", "size" => "10", "legend" => _("Label")), "id_company_spending" => array("legend" => _("Company paying"), "type" => "popup", "values" => $company_paying_popup_id, "display_replace" => $company_paying_names), "id_provider" => array("legend" => _("Company paid"), "type" => "popup", "values" => $prov_popup_id, "display_replace" => $prov_popup_names), "expenditure_type" => array("legend" => _("Expenditure type"), "type" => "popup", "values" => $spent_type_popup_id, "display_replace" => $spent_type_names), "payment_type" => array("legend" => _("Means of payment"), "type" => "popup", "values" => array("none", "credit_card", "wire_transfer", "paypal", "check", "cash"), "display_replace" => array(_("Unknown"), _("Credit card"), _("Wire transfer"), _("Paypal"), _("Check"), _("Cash"))), "payment_total" => array("type" => "text", "size" => 6, "legend" => _("Total cost")), "vat_rate" => array("type" => "text", "size" => 4, "legend" => _("Tax rate")), "vat_total" => array("type" => "text", "size" => 4, "legend" => _("Total tax")), "currency_type" => array("type" => "text", "size" => 4, "legend" => _("Currency")), "bank_acct_id" => array("type" => "popup", "values" => $bank_popup_id, "display_replace" => $bank_names, "legend" => _("Bank account")), "amount" => array("type" => "text", "size" => 6, "legend" => _("Bank amount")), "invoice_date" => array("type" => "text", "size" => 10, "legend" => _("Invoice date")), "paid_date" => array("type" => "text", "size" => 10, "legend" => _("Payment date"))));
            if (isset($_REQUEST["date_selector"])) {
                $dsc["forward"][] = "date_selector";
            }
            $out .= dtcDatagrid($dsc);
            break;
        case "bank":
            $q = "SELECT * FROM {$pro_mysql_companies_table} ";
            $r = mysql_query($q) or die("Cannot query {$q} line " . __LINE__ . " file " . __FILE__ . " sql said: " . mysql_error());
            $n = mysql_num_rows($r);
            $company_paying_popup_id = array();
            $company_paying_names = array();
            for ($i = 0; $i < $n; $i++) {
                $a = mysql_fetch_array($r);
                $company_paying_popup_id[] = $a["id"];
                $company_paying_names[] = $a["name"];
            }
            $dsc = array("title" => _("Bank accounts edition"), "table_name" => $pro_mysql_spent_bank_table, "action" => "bank_account_editor", "forward" => array("rub", "sousrub"), "cols" => array("id" => array("type" => "id", "display" => "no", "legend" => "id"), "acct_name" => array("type" => "text", "legend" => _("Account name")), "id_company" => array("legend" => _("Company"), "type" => "popup", "values" => $company_paying_popup_id, "display_replace" => $company_paying_names), "sort_code" => array("legend" => _("Sort code"), "type" => "text", "size" => "8"), "acct_number" => array("legend" => _("Account number"), "type" => "text"), "swift" => array("legend" => _("SWIFT"), "type" => "text", "size" => "8"), "bank_addr" => array("legend" => _("Bank address"), "type" => "text"), "currency_type" => array("legend" => _("Currency"), "type" => "text", "size" => "4")));
            $out .= dtcDatagrid($dsc);
            // Payment type
            $dsc = array("title" => _("Payment type edition"), "table_name" => $pro_mysql_spent_type_table, "action" => "payment_type_editor", "forward" => array("rub", "sousrub"), "cols" => array("id" => array("type" => "id", "display" => "no", "legend" => "id"), "label" => array("legend" => _("Type of payment"), "type" => "text", "size" => "32")));
            $out .= dtcDatagrid($dsc);
            break;
        case "provideredit":
            $dsc = array("title" => _("Upstream provider list edition"), "table_name" => $pro_mysql_spent_providers_table, "action" => "provider_list_editor", "forward" => array("rub", "sousrub"), "id_fld" => "id", "list_fld_show" => "quick_name", "new_item_title" => _("New upstream provider") . ":", "new_item_link" => _("New upsream provider"), "edit_item_title" => _("Edit upstream provider") . ":", "check_unique" => array("quick_name"), "where_list" => array("always_yes" => "yes"), "cols" => array("id" => array("type" => "id", "display" => "no", "legend" => "id"), "quick_name" => array("type" => "text", "disable_edit" => "yes", "check" => "dtc_login_or_email", "legend" => _("Short name:")), "company_name" => array("legend" => _("Company name:"), "type" => "text"), "is_company" => array("type" => "checkbox", "values" => array("yes", "no"), "default" => "yes", "legend" => _("Is it a company:")), "familyname" => array("legend" => _("First name:"), "type" => "text"), "christname" => array("legend" => _("Familly name:"), "type" => "text"), "addr1" => array("legend" => _("Address:"), "type" => "text"), "addr2" => array("legend" => _("Address (line2):"), "type" => "text"), "addr3" => array("legend" => _("Address (line3):"), "type" => "text"), "city" => array("legend" => _("City:"), "type" => "text"), "zipcode" => array("legend" => _("Zipcode:"), "type" => "text"), "state" => array("legend" => _("State:"), "type" => "text"), "country" => array("legend" => _("Country:"), "type" => "text"), "phone" => array("legend" => _("Phone:"), "type" => "text"), "fax" => array("legend" => _("Fax:"), "type" => "text"), "email" => array("legend" => _("Email:"), "type" => "text"), "special_note" => array("legend" => _("Note:"), "type" => "textarea")));
            $out .= dtcListItemsEdit($dsc);
            break;
        default:
        case "renewalreport":
            // Allow shutdown of expired VPS
            if (isset($_REQUEST["action"])) {
                switch ($_REQUEST["action"]) {
                    case "shutdown_expired_vps":
                        // Perform a clean shutdown
                        remoteVPSAction($_REQUEST["server_hostname"], $_REQUEST["vps_name"], "shutdown_vps");
                        break;
                    case "kill_vps_and_owner":
                        // Do a brutal kill of the running instance
                        deleteVPS($_REQUEST["vps_id"]);
                        remoteVPSAction($_REQUEST["server_hostname"], $_REQUEST["vps_name"], "destroy_vps");
                        remoteVPSAction($_REQUEST["server_hostname"], $_REQUEST["vps_name"], "kill_vps_disk");
                        // Delete the admin
                        $q = "DELETE FROM {$pro_mysql_admin_table} WHERE adm_login='******';";
                        $r = mysql_query($q) or die("Cannot querry {$q} line " . __LINE__ . " file " . __FILE__ . " sql said: " . mysql_error());
                        // And the client
                        $q = "DELETE FROM {$pro_mysql_client_table} WHERE id='" . $_REQUEST["client_id"] . "';";
                        $r = mysql_query($q) or die("Cannot querry {$q} line " . __LINE__ . " file " . __FILE__ . " sql said: " . mysql_error());
                        break;
                    default:
                        break;
                }
            }
            // Display of each month payment list
            if (isset($_REQUEST["date"])) {
                $ret = dateSelector($pro_mysql_pay_table, "date", "date");
                $out .= $ret["text"];
                $where_condition = $ret["where_condition"];
                $q = "SELECT id,name FROM {$pro_mysql_product_table} ";
                $r = mysql_query($q) or die("Cannot querry {$q} line " . __LINE__ . " file " . __FILE__ . " sql said: " . mysql_error());
                $n = mysql_num_rows($r);
                $prod_ids = array();
                $prod_names = array();
                for ($i = 0; $i < $n; $i++) {
                    $a = mysql_fetch_array($r);
                    $prod_ids[] = $a["id"];
                    $prod_names[] = $a["name"];
                }
                $out .= "<h3>" . _("Payements for the period: ") . $_REQUEST["date"] . "</h3>";
                $dsc = array("title" => _("Payment history"), "table_name" => $pro_mysql_pay_table, "action" => "payment_history_list_editor", "forward" => array("rub", "sousrub", "date"), "order_by" => "date", "skip_deletion" => "yes", "skip_creation" => "yes", "print_where_condition" => $where_condition, "cols" => array("id" => array("type" => "id", "display" => "no", "legend" => "id"), "date" => array("type" => "text", "size" => "8", "legend" => _("Date")), "id_client" => array("type" => "forkey", "forkey_type" => "info", "table" => $pro_mysql_client_table, "other_table_fld" => "CONCAT(company_name,': ',familyname,', ',christname)", "other_table_key" => "id", "this_table_field" => "id_client", "link" => "?rub=crm&id=", "bk_table" => $pro_mysql_new_admin_table, "bk_other_table_fld" => "CONCAT(comp_name,': ',family_name,', ',first_name)", "bk_other_table_key" => "id", "bk_this_table_field" => "id_client", "legend" => _("Customer name")), "product_id" => array("type" => "popup", "values" => $prod_ids, "display_replace" => $prod_names, "legend" => _("Product")), "refund_amount" => array("type" => "text", "size" => "8", "legend" => _("Refund amount")), "paiement_cost" => array("type" => "text", "size" => "4", "legend" => _("Gate cost")), "vat_rate" => array("type" => "text", "size" => "4", "legend" => _("VAT rate")), "vat_total" => array("type" => "text", "size" => "4", "legend" => _("VAT total")), "paiement_total" => array("type" => "text", "size" => "6", "legend" => _("Grand total")), "paiement_type" => array("type" => "text", "size" => "6", "legend" => _("Type")), "secpay_site" => array("type" => "text", "size" => "4", "legend" => _("Gate type")), "new_account" => array("type" => "popup", "values" => array("no", "yes"), "display_replace" => array(_("New account"), _("Renewal")), "legend" => _("Is renewal")), "valid" => array("type" => "popup", "values" => array("no", "pending", "yes"), "display_replace" => array(_("No"), _("Pending"), _("Yes")), "legend" => _("Validated")), "pending_reason" => array("type" => "text", "size" => "6", "legend" => _("Pending reason"))));
                $out .= dtcDatagrid($dsc);
                return $out;
                $ret = dateSelector($pro_mysql_completedorders_table, "date", "date");
                // Allow nuke of bad payment (hackers?) to have accounting done correctly
                if (isset($_REQUEST["action"]) && $_REQUEST["action"] == "nuke_payment") {
                    $q = "DELETE FROM {$pro_mysql_completedorders_table} WHERE id='" . $_REQUEST["completedorders_id"] . "';";
                    $r = mysql_query($q) or die("Cannot querry {$q} line " . __LINE__ . " file " . __FILE__ . " sql said: " . mysql_error());
                }
                $r = mysql_query($q) or die("Cannot querry {$q} line " . __LINE__ . " file " . __FILE__ . " sql said: " . mysql_error());
                $n = mysql_num_rows($r);
                if ($n < 1) {
                    $out .= _("No past payments for this period") . "<br>";
                } else {
                    $out .= "<table cellspacing=\"0\" cellpadding=\"2\" border=\"1\">\n\t\t\t\t<tr><td>" . _("Product") . "</td><td>" . _("Client ID") . "</td><td>" . _("Client") . "</td><td>" . _("Service country") . "</td>\n\t\t\t\t<td>" . _("Client country") . "</td>\n\t\t\t\t<td>" . _("VAT collected") . "</td><td>" . _("Period") . "</td><td>" . _("Payment date") . "</td><td>" . _("Total") . "</td><td>" . _("Payment method") . "</td>\n\t\t\t\t<td>" . _("Action") . "</td></tr>";
                    for ($i = 0; $i < $n; $i++) {
                        $a = mysql_fetch_array($r);
                        if ($a["id_client"] == 0) {
                            $client_name = _("No client id");
                            $client_id_txt = _("No client id");
                        } else {
                            $q2 = "SELECT * FROM {$pro_mysql_client_table} WHERE id='" . $a["id_client"] . "';";
                            $r2 = mysql_query($q2) or die("Cannot querry {$q2} line " . __LINE__ . " file " . __FILE__ . " sql said: " . mysql_error());
                            $n2 = mysql_num_rows($r2);
                            if ($n2 != 1) {
                                $client_name = _("N/A");
                                $client_id_txt = _("N/A");
                                $client_country = _("N/A");
                            } else {
                                $a2 = mysql_fetch_array($r2);
                                $client_name = $a2["company_name"] . ":" . $a2["christname"] . ", " . $a2["familyname"];
                                $client_id_txt = $a["id_client"];
                                $client_country = $a2["country"];
                            }
                        }
                        $q2 = "SELECT * FROM {$pro_mysql_product_table} WHERE id='" . $a["product_id"] . "';";
                        $r2 = mysql_query($q2) or die("Cannot querry {$q2} line " . __LINE__ . " file " . __FILE__ . " sql said: " . mysql_error());
                        $n2 = mysql_num_rows($r2);
                        if ($n2 != 1) {
                            $product_txt = _("Product not found");
                        } else {
                            $a2 = mysql_fetch_array($r2);
                            $product_txt = $a2["name"];
                            $product_period_size = $a2["period"];
                        }
                        $q2 = "SELECT * FROM {$pro_mysql_pay_table} WHERE id='" . $a["payment_id"] . "';";
                        $r2 = mysql_query($q2) or die("Cannot querry {$q2} line " . __LINE__ . " file " . __FILE__ . " sql said: " . mysql_error());
                        $n2 = mysql_num_rows($r2);
                        if ($n2 != 1) {
                            $payment_txt = _("Payment not found");
                            $payment_type = _("Payment not found");
                            $vat_collected = _("VAT not found");
                        } else {
                            $a2 = mysql_fetch_array($r2);
                            $payment_txt = $a2["paiement_total"] . " " . $a2["currency"];
                            $payment_type = $a2["paiement_type"];
                            if ($payment_type == "online") {
                                $payment_type .= ": " . $a2["secpay_site"];
                            }
                            $vat_collected = $a2["paiement_total"] * $a2["vat_rate"] / 100;
                        }
                        if ($a["last_expiry_date"] == "0000-00-00") {
                            $last_expiry_date = $a["date"];
                        } else {
                            $last_expiry_date = $a["last_expiry_date"];
                        }
                        if ($payment_type == 'wire') {
                            $pay = _("Wire");
                        } else {
                            if ($payment_type == 'cheque') {
                                $pay = _("cheque");
                            } else {
                                if ($payment_type == 'online: none') {
                                    $pay = _("online: none");
                                } else {
                                    $pay = $payment_type;
                                }
                            }
                        }
                        $new_expiry_date = calculateExpirationDate($last_expiry_date, $product_period_size);
                        $out .= "<tr><td>{$product_txt}</td><td>{$client_id_txt}</td><td>{$client_name}</td><td>" . $a["country_code"] . "</td>\n\t\t\t\t\t<td>{$client_country}</td>\n\t\t\t\t\t<td>{$vat_collected}</td><td>{$last_expiry_date} -> {$new_expiry_date}</td><td>" . $a["date"] . "</td><td>{$payment_txt}</td>\n\t\t\t\t\t<td>{$pay}</td>\n\t\t\t\t\t<td><a href=\"" . $_SERVER["PHP_SELF"] . "?rub={$rub}&date=" . $_REQUEST["date"] . "&action=nuke_payment&completedorders_id=" . $a["id"] . "\">" . _("Delete") . "</a></tr>";
                    }
                    $out .= "</table>";
                }
                return $out;
            }
            // Calculation of recuring totals
            $out .= "<h3>" . _("Total recurring incomes per month:") . "</h3>";
            // Monthly recurring for shared hosting:
            $q = "SELECT {$pro_mysql_product_table}.price_dollar,{$pro_mysql_product_table}.period,{$pro_mysql_product_table}.id\n\t\tFROM {$pro_mysql_product_table},{$pro_mysql_admin_table}\n\t\tWHERE {$pro_mysql_product_table}.id = {$pro_mysql_admin_table}.prod_id\n\t\tAND {$pro_mysql_product_table}.heb_type='shared'\n\t\tAND {$pro_mysql_admin_table}.expire != '0000-00-00'";
            $r = mysql_query($q) or die("Cannot querry {$q} line " . __LINE__ . " file " . __FILE__ . " sql said: " . mysql_error());
            $n = mysql_num_rows($r);
            $total_shared = 0;
            for ($i = 0; $i < $n; $i++) {
                $a = mysql_fetch_array($r);
                $period = $a["period"];
                $price = $a["price_dollar"];
                $id = $a["id"];
                if ($period == '0001-00-00') {
                    $total_shared += $price / 12;
                } else {
                    $papoum = explode('-', $period);
                    $months = $papoum[1];
                    if ($months == 0) {
                        echo "Product {$id} has zero month.<br>";
                    } else {
                        $total_shared += $price / $months;
                    }
                }
            }
            // Calculate how much SSL IPs have been taken
            $q = "SELECT count(id) as num_ssl FROM {$pro_mysql_ssl_ips_table} WHERE available='no'";
            $r = mysql_query($q) or die("Cannot querry {$q} line " . __LINE__ . " file " . __FILE__ . " sql said: " . mysql_error());
            $n = mysql_num_rows($r);
            $total_ssl = 0;
            if ($n != 0) {
                $a = mysql_fetch_array($r);
                $q = "SELECT price_dollar FROM {$pro_mysql_product_table} WHERE heb_type='ssl'";
                $r = mysql_query($q) or die("Cannot querry {$q} line " . __LINE__ . " file " . __FILE__ . " sql said: " . mysql_error());
                $n = mysql_num_rows($r);
                if ($n != 0) {
                    $b = mysql_fetch_array($r);
                    $total_ssl = $a["num_ssl"] * $b["price_dollar"] / 12;
                }
            }
            // Monthly recurring for VPS:
            $q = "SELECT {$pro_mysql_product_table}.price_dollar,{$pro_mysql_product_table}.period,{$pro_mysql_product_table}.id\n\t\tFROM {$pro_mysql_product_table},{$pro_mysql_vps_table}\n\t\tWHERE {$pro_mysql_product_table}.id = {$pro_mysql_vps_table}.product_id";
            $r = mysql_query($q) or die("Cannot querry {$q} line " . __LINE__ . " file " . __FILE__ . " sql said: " . mysql_error());
            $n = mysql_num_rows($r);
            $total_vps = 0;
            for ($i = 0; $i < $n; $i++) {
                $a = mysql_fetch_array($r);
                $period = $a["period"];
                $price = $a["price_dollar"];
                $id = $a["id"];
                if ($period == '0001-00-00') {
                    $total_shared += $price / 12;
                } else {
                    $papoum = explode('-', $period);
                    $months = $papoum[1];
                    if ($months != 0) {
                        $total_vps += $price / $months;
                    } else {
                        echo "Product {$id} has zero month.<br>";
                    }
                }
            }
            // Monthly recurring for dedicated servers:
            $q = "SELECT {$pro_mysql_product_table}.price_dollar,{$pro_mysql_product_table}.period,{$pro_mysql_product_table}.id\n\t\tFROM {$pro_mysql_product_table},{$pro_mysql_dedicated_table}\n\t\tWHERE {$pro_mysql_product_table}.id = {$pro_mysql_dedicated_table}.product_id";
            $r = mysql_query($q) or die("Cannot querry {$q} line " . __LINE__ . " file " . __FILE__ . " sql said: " . mysql_error());
            $n = mysql_num_rows($r);
            $total_dedicated = 0;
            for ($i = 0; $i < $n; $i++) {
                $a = mysql_fetch_array($r);
                $period = $a["period"];
                $price = $a["price_dollar"];
                $id = $a["id"];
                if ($period == '0001-00-00') {
                    $total_shared += $price / 12;
                } else {
                    $papoum = explode('-', $period);
                    $months = $papoum[1];
                    if ($months == 0) {
                        echo _("Dedicated server product ID {$id} has zero for the number of month to renew") . "<br>";
                    } else {
                        $total_dedicated += $price / $months;
                    }
                }
            }
            $p_renewal = "";
            $p_renewal .= _("Shared hosting: ") . round($total_shared, 2) . " {$secpayconf_currency_letters}<br>";
            $p_renewal .= _("SSL IPs renewals: ") . round($total_ssl, 2) . " {$secpayconf_currency_letters}<br>";
            $p_renewal .= _("VPS: ") . round($total_vps, 2) . " {$secpayconf_currency_letters}<br>";
            $p_renewal .= _("Dedicated servers: ") . round($total_dedicated, 2) . " {$secpayconf_currency_letters}<br>";
            $big_total = $total_shared + $total_vps + $total_dedicated + $total_ssl;
            $p_renewal .= "<b>" . _("Total: ") . round($big_total, 2) . " {$secpayconf_currency_letters}</b>";
            // Show a quick history of payments
            $year = date("Y");
            $month = date("m");
            $cur_year = $year - 2;
            $cur_month = $month;
            $p_history = "";
            $p_history .= "<table cellspacing=\"1\" cellpadding=\"1\" border=\"1\">\n\t\t<tr><td>" . _("Period") . "</td><td>" . _("Amount") . "</td><td>" . _("VAT collected") . "</td><td>" . _("Payment gateway cost") . "</td><td>" . _("Profit") . "</td></tr>";
            for ($i = 0; $i < 25; $i++) {
                $q2 = "SELECT {$pro_mysql_pay_table}.paiement_total,{$pro_mysql_pay_table}.vat_rate,{$pro_mysql_pay_table}.paiement_cost\n\t\t\tFROM {$pro_mysql_pay_table},{$pro_mysql_completedorders_table}\n\t\t\tWHERE {$pro_mysql_pay_table}.vat_rate!='0.00'\n\t\t\tAND {$pro_mysql_completedorders_table}.payment_id = {$pro_mysql_pay_table}.id\n\t\t\tAND {$pro_mysql_completedorders_table}.date LIKE '" . $cur_year . "-" . $cur_month . "-%';";
                $r2 = mysql_query($q2) or die("Cannot querry {$q2} line " . __LINE__ . " file " . __FILE__ . " sql said: " . mysql_error());
                $n2 = mysql_num_rows($r2);
                $vat_collected = 0;
                $month_total = 0;
                $cost_total = 0;
                for ($j = 0; $j < $n2; $j++) {
                    $a2 = mysql_fetch_array($r2);
                    $tt = $a2["paiement_total"];
                    $vat = $a2["vat_rate"];
                    $vat_collected += $tt * $vat / 100;
                    $month_total += $tt;
                    $cost_total += $a2["paiement_cost"];
                }
                $q2 = "SELECT sum(paiement_total) as paiement_total, sum(paiement_cost) as paiement_cost FROM {$pro_mysql_completedorders_table},{$pro_mysql_pay_table}\n\t\t\tWHERE {$pro_mysql_completedorders_table}.date LIKE '" . $cur_year . "-" . $cur_month . "%'\n\t\t\tAND {$pro_mysql_completedorders_table}.payment_id = {$pro_mysql_pay_table}.id\n\t\t\tAND {$pro_mysql_pay_table}.vat_rate = '0.00';";
                $r2 = mysql_query($q2) or die("Cannot querry {$q2} line " . __LINE__ . " file " . __FILE__ . " sql said: " . mysql_error());
                $n2 = mysql_num_rows($r2);
                if ($n2 > 0) {
                    $a2 = mysql_fetch_array($r2);
                    $cost_total += $a2["paiement_cost"];
                    $month_total += $a2["paiement_total"];
                    $profit = $month_total - $cost_total - $vat_collected;
                    $p_history .= "<tr><td style=\"text-align:right;\"><a href=\"" . $_SERVER["PHP_SELF"] . "?rub={$rub}&date=" . $cur_year . "-" . $cur_month . "\">" . $cur_year . "-" . $cur_month . "</a></td>\n\t\t\t\t<td style=\"text-align:right;\">" . $month_total . " {$secpayconf_currency_letters}</td>\n\t\t\t\t<td style=\"text-align:right;\">" . round($vat_collected, 2) . " {$secpayconf_currency_letters}</td>\n\t\t\t\t<td style=\"text-align:right;\">" . round($cost_total, 2) . " {$secpayconf_currency_letters}</td>\n\t\t\t\t<td style=\"text-align:right;\">" . round($profit, 2) . " {$secpayconf_currency_letters}</td></tr>";
                }
                $cur_month++;
                if ($cur_month > 12) {
                    $cur_month = 1;
                    $cur_year++;
                }
                if ($cur_month < 10) {
                    $cur_month = "0" . $cur_month;
                }
            }
            $p_history .= "</table>";
            $p_active_prods = "<img src=\"active_prods_graph.php?graph=year\"><br>\n<img src=\"active_prods_graph.php?graph=month\">";
            // Layout the recuring stat and the effective payment statistics
            $out .= "<table cellspacing=\"1\" cellpadding=\"4\" border=\"0\" width=\"100%\">\n\t\t<tr valign=\"top\"><td valign=\"top\" width=\"50%\">{$p_history}</td>\n\t\t<td valign=\"top\">{$p_renewal}</td>\n\t\t<td valign=\"top\">{$p_active_prods}</td></tr></table>";
            $out .= "<h3>" . _("Shared hosting renewals:") . "</h3>";
            $q = "SELECT * FROM {$pro_mysql_admin_table} WHERE expire < '" . date("Y-m-d") . "' AND id_client!='0' AND expire !='0000-00-00' ORDER BY expire;";
            $r = mysql_query($q) or die("Cannot querry {$q} line " . __LINE__ . " file " . __FILE__);
            $n = mysql_num_rows($r);
            if ($n < 1) {
                $out .= _("No shared account expired.") . "<br>";
            } else {
                $out .= "<table cellspacing=\"0\" cellpadding=\"2\" border=\"1\">\n\t\t\t<tr><td>" . _("Login") . "</td><td>" . _("Client") . "</td><td>" . _("Email") . "</td><td>" . _("Expiration date") . "</td></tr>";
                for ($i = 0; $i < $n; $i++) {
                    $a = mysql_fetch_array($r);
                    $q2 = "SELECT * FROM {$pro_mysql_client_table} WHERE id='" . $a["id_client"] . "';";
                    $r2 = mysql_query($q2) or die("Cannot querry {$q2} line " . __LINE__ . " file " . __FILE__ . " sql said: " . mysql_error());
                    $n2 = mysql_num_rows($r2);
                    if ($n2 != 1) {
                        $client_name = _("Client name not found!");
                    } else {
                        $a2 = mysql_fetch_array($r2);
                        $client_name = $a2["company_name"] . ":" . $a2["christname"] . ", " . $a2["familyname"];
                    }
                    $q2 = "SELECT * FROM {$pro_mysql_domain_table} WHERE owner='" . $a["adm_login"] . "';";
                    $r2 = mysql_query($q2) or die("Cannot querry {$q2} line " . __LINE__ . " file " . __FILE__);
                    $n2 = mysql_num_rows($r2);
                    if ($n2 > 0) {
                        $out .= "<tr><td>" . $a["adm_login"] . "</td><td>{$client_name}</td><td>" . $a2["email"] . "</td><td>" . $a["expire"] . "</td></tr>";
                    }
                }
                $out .= "</table>";
            }
            // List of expired expired SSL IPs
            $out .= "<h3>" . _("SSL IPs renewals") . "</h3>";
            $q = "SELECT * FROM {$pro_mysql_ssl_ips_table} WHERE expire < '" . date("Y-m-d") . "' AND available='no' ORDER BY expire";
            $r = mysql_query($q) or die("Cannot querry {$q} line " . __LINE__ . " file " . __FILE__ . " sql said: " . mysql_error());
            $n = mysql_num_rows($r);
            if ($n < 1) {
                $out .= _("No SSL IP expired") . "<br>";
            } else {
                $out .= "<table cellspacing=\"0\" cellpadding=\"2\" border=\"1\">\n\t\t\t<tr><td>" . _("Login") . "</td><td>" . _("Client") . "</td><td>" . _("Email") . "</td><td>" . _("Expiration date") . "</td></tr>";
                for ($i = 0; $i < $n; $i++) {
                    $a = mysql_fetch_array($r);
                    $q2 = "SELECT * FROM {$pro_mysql_admin_table} WHERE adm_login='******';";
                    $r2 = mysql_query($q2) or die("Cannot querry {$q2} line " . __LINE__ . " file " . __FILE__ . " sql said: " . mysql_error());
                    $n2 = mysql_num_rows($r2);
                    if ($n2 != 1) {
                        die("Cannot find admin name " . $a["adm_login"] . " line " . __LINE__ . " file " . __FILE__);
                    } else {
                        $admin = mysql_fetch_array($r2);
                    }
                    $q2 = "SELECT * FROM {$pro_mysql_client_table} WHERE id='" . $admin["id_client"] . "';";
                    $r2 = mysql_query($q2) or die("Cannot querry {$q2} line " . __LINE__ . " file " . __FILE__ . " sql said: " . mysql_error());
                    $n2 = mysql_num_rows($r2);
                    if ($n2 != 1) {
                        $client_name = _("Client name not found!");
                    } else {
                        $a2 = mysql_fetch_array($r2);
                        $client_name = $a2["company_name"] . ":" . $a2["christname"] . ", " . $a2["familyname"];
                    }
                    $out .= "<tr><td>" . $a["adm_login"] . "</td><td>{$client_name}</td><td>" . $a2["email"] . "</td><td>" . $a["expire"] . "</td></tr>";
                }
                $out .= "</table>";
            }
            // List if expired VPS
            $out .= "<h3>" . _("VPS renewals:") . "</h3>";
            $q = "SELECT * FROM {$pro_mysql_vps_table} WHERE expire_date < '" . date("Y-m-d") . "' ORDER BY expire_date";
            $r = mysql_query($q) or die("Cannot querry {$q} line " . __LINE__ . " file " . __FILE__ . " sql said: " . mysql_error());
            $n = mysql_num_rows($r);
            if ($n < 1) {
                $out .= _("No VPS expired") . "<br>";
            } else {
                $out .= "<table cellspacing=\"0\" cellpadding=\"2\" border=\"1\">\n\t\t\t<tr><td>" . _("Login") . "</td><td>" . _("VPS") . "</td>\n\t\t\t<td>" . _("Client") . "</td>\n\t\t\t<td>" . _("Email") . "</td>\n\t\t\t<td>" . _("Expiration date") . "</td>\n\t\t\t<td>" . _("Days of expiration") . "</td>\n\t\t\t<td>" . _("Action") . "</td>\n\t\t\t</tr>";
                for ($i = 0; $i < $n; $i++) {
                    $a = mysql_fetch_array($r);
                    $q2 = "SELECT * FROM {$pro_mysql_admin_table} WHERE adm_login='******';";
                    $r2 = mysql_query($q2) or die("Cannot querry {$q2} line " . __LINE__ . " file " . __FILE__ . " sql said: " . mysql_error());
                    $n2 = mysql_num_rows($r2);
                    if ($n2 != 1) {
                        die("Cannot find admin name " . $a["owner"] . " line " . __LINE__ . " file " . __FILE__);
                    } else {
                        $admin = mysql_fetch_array($r2);
                    }
                    $q2 = "SELECT * FROM {$pro_mysql_client_table} WHERE id='" . $admin["id_client"] . "';";
                    $r2 = mysql_query($q2) or die("Cannot querry {$q2} line " . __LINE__ . " file " . __FILE__ . " sql said: " . mysql_error());
                    $n2 = mysql_num_rows($r2);
                    if ($n2 != 1) {
                        $client_name = _("Client name not found!");
                    } else {
                        $a2 = mysql_fetch_array($r2);
                        $client_name = $a2["company_name"] . ":" . $a2["christname"] . ", " . $a2["familyname"];
                    }
                    $q2 = "SELECT adm_login FROM {$pro_mysql_admin_table} WHERE id_client='" . $admin["id_client"] . "'";
                    $r2 = mysql_query($q2) or die("Cannot querry {$q2} line " . __LINE__ . " file " . __FILE__ . " sql said: " . mysql_error());
                    $n2 = mysql_num_rows($r2);
                    if ($n2 == 1) {
                        $q2 = "SELECT * FROM {$pro_mysql_vps_table} WHERE owner='" . $admin["adm_login"] . "'";
                        $r2 = mysql_query($q2) or die("Cannot querry " . $q2 . " line " . __LINE__ . " file " . __FILE__ . " sql said: " . mysql_error());
                        $n2 = mysql_num_rows($r2);
                        if ($n2 == 1) {
                            $q2 = "SELECT * FROM {$pro_mysql_dedicated_table} WHERE owner='" . $admin["adm_login"] . "'";
                            $r2 = mysql_query($q2) or die("Cannot querry " . $q2 . " line " . __LINE__ . " file " . __FILE__ . " sql said: " . mysql_error());
                            $n2 = mysql_num_rows($r2);
                            if ($n2 == 0) {
                                $q2 = "SELECT * FROM {$pro_mysql_domain_table} WHERE owner='" . $admin["adm_login"] . "'";
                                $r2 = mysql_query($q2) or die("Cannot querry " . $q2 . " line " . __LINE__ . " file " . __FILE__ . " sql said: " . mysql_error());
                                $n2 = mysql_num_rows($r2);
                                if ($n2 == 0) {
                                    $kill_owner_txt = "<a href=\"" . $_SERVER["PHP_SELF"] . "?action=kill_vps_and_owner&adm_login="******"adm_login"] . "&client_id=" . $admin["id_client"] . "&vps_name=" . $a["vps_xen_name"] . "&server_hostname=" . $a["vps_server_hostname"] . "&vps_id=" . $a["id"] . "\">" . _("Kill VPS and owner") . "</a>";
                                } else {
                                    $kill_owner_txt = _("Has some domains");
                                }
                            } else {
                                $kill_owner_txt = _("Has a dedicated");
                            }
                        } else {
                            $kill_owner_txt = _("More than one VPS");
                        }
                    } else {
                        $kill_owner_txt = _("More than one login");
                    }
                    if (numOfDays($a["expire_date"]) >= $conf_vps_renewal_shutdown) {
                        $bgcolor = " bgcolor=\"#FF8888\" ";
                    } else {
                        $bgcolor = " ";
                    }
                    $out .= "<tr><td>" . $a["owner"] . "</td>\n\t\t\t\t<td>" . $a["vps_xen_name"] . ":" . $a["vps_server_hostname"] . "</td>\n\t\t\t\t<td>{$client_name}</td>\n\t\t\t\t<td>" . $a2["email"] . "</td>\n\t\t\t\t<td {$bgcolor}>" . $a["expire_date"] . "</td>\n\t\t\t\t<td {$bgcolor}>" . calculateAge($a["expire_date"], "00:00:00") . "</td>\n\t\t\t\t<td><a href=\"" . $_SERVER["PHP_SELF"] . "?rub={$rub}&action=shutdown_expired_vps&server_hostname=" . $a["vps_server_hostname"] . "&vps_name=" . $a["vps_xen_name"] . "\">" . _("Shutdown") . "</a> - {$kill_owner_txt}</td></tr>";
                }
                $out .= "</table>";
            }
            // List expired dedicated servers
            $out .= "<h3>" . _("Dedicated servers renewals") . "</h3>";
            $q = "SELECT * FROM {$pro_mysql_dedicated_table} WHERE expire_date < '" . date("Y-m-d") . "' ORDER BY expire_date";
            $r = mysql_query($q) or die("Cannot querry {$q} line " . __LINE__ . " file " . __FILE__ . " sql said: " . mysql_error());
            $n = mysql_num_rows($r);
            if ($n < 1) {
                $out .= _("No dedicated server expired") . "<br>";
            } else {
                $out .= "<table cellspacing=\"0\" cellpadding=\"2\" border=\"1\">\n\t\t\t<tr><td>" . _("Login") . "</td><td>" . _("Server") . "</td><td>" . _("Client") . "</td><td>" . _("Email") . "</td><td>" . _("Expiration date") . "</td></tr>";
                for ($i = 0; $i < $n; $i++) {
                    $a = mysql_fetch_array($r);
                    $q2 = "SELECT * FROM {$pro_mysql_admin_table} WHERE adm_login='******';";
                    $r2 = mysql_query($q2) or die("Cannot querry {$q2} line " . __LINE__ . " file " . __FILE__ . " sql said: " . mysql_error());
                    $n2 = mysql_num_rows($r2);
                    if ($n2 != 1) {
                        die("Cannot find admin name " . $a["owner"] . " line " . __LINE__ . " file " . __FILE__);
                    } else {
                        $admin = mysql_fetch_array($r2);
                    }
                    $q2 = "SELECT * FROM {$pro_mysql_client_table} WHERE id='" . $admin["id_client"] . "';";
                    $r2 = mysql_query($q2) or die("Cannot querry {$q2} line " . __LINE__ . " file " . __FILE__ . " sql said: " . mysql_error());
                    $n2 = mysql_num_rows($r2);
                    if ($n2 != 1) {
                        $client_name = _("Client name not found!");
                    } else {
                        $a2 = mysql_fetch_array($r2);
                        $client_name = $a2["company_name"] . ":" . $a2["christname"] . ", " . $a2["familyname"];
                    }
                    $out .= "<tr><td>" . $a["owner"] . "</td><td>" . $a["server_hostname"] . "</td><td>{$client_name}</td><td>" . $a2["email"] . "</td><td>" . $a["expire_date"] . "</td></tr>";
                }
                $out .= "</table>";
            }
            break;
    }
    return $out;
}
Exemplo n.º 2
0
    }
    $vps = mysql_fetch_array($r);
    $q = "UPDATE {$pro_mysql_vps_ip_table} SET available='yes' WHERE vps_server_hostname='" . $vps["vps_server_hostname"] . "' AND vps_xen_name='" . $vps["vps_xen_name"] . "';";
    $r = mysql_query($q) or die("Cannot execute query \"{$q}\" line " . __LINE__ . " file " . __FILE__ . " sql said: " . mysql_error());
    $q = "DELETE FROM {$pro_mysql_vps_table} WHERE id='" . $_REQUEST["id"] . "';";
    $r = mysql_query($q) or die("Cannot execute query \"{$q}\" line " . __LINE__ . " file " . __FILE__ . " sql said: " . mysql_error());
    $q = "DELETE FROM {$pro_mysql_vps_stats_table} WHERE vps_server_hostname='" . $vps["vps_server_hostname"] . "' AND vps_xen_name='xen" . $vps["vps_xen_name"] . "';";
    $r = mysql_query($q) or die("Cannot execute query \"{$q}\" line " . __LINE__ . " file " . __FILE__ . " sql said: " . mysql_error());
    remoteVPSAction($vps["vps_server_hostname"], $vps["vps_xen_name"], "destroy_vps");
    remoteVPSAction($vps["vps_server_hostname"], $vps["vps_xen_name"], "kill_vps_disk");
    VPS_Server_Subscribe_To_Lists($vps["vps_server_hostname"]);
    $adm_query = "UPDATE {$pro_mysql_cronjob_table} SET gen_nagios='yes' WHERE 1;";
    mysql_query($adm_query);
}
if (isset($_REQUEST["action"]) && $_REQUEST["action"] == "delete_a_vps") {
    deleteVPS($_REQUEST["id"]);
}
if (isset($_REQUEST["action"]) && $_REQUEST["action"] == "vps_server_list_remove") {
    $q = "SELECT * FROM {$pro_mysql_vps_server_table} WHERE id='" . $_REQUEST["edithost"] . "';";
    $r = mysql_query($q) or die("Cannot execute query \"{$q}\" line " . __LINE__ . " file " . __FILE__ . " sql said: " . mysql_error());
    $a = mysql_fetch_array($r);
    $q = "DELETE FROM {$pro_mysql_vps_server_lists_table} WHERE hostname='" . $a["hostname"] . "' AND list_name='" . $_REQUEST["list_name"] . "';";
    $r = mysql_query($q) or die("Cannot execute query \"{$q}\" line " . __LINE__ . " file " . __FILE__ . " sql said: " . mysql_error());
    resubscribe_VPS_server_list_users($_REQUEST["list_name"]);
}
if (isset($_REQUEST["action"]) && $_REQUEST["action"] == "vps_server_list_add") {
    $q = "SELECT * FROM {$pro_mysql_vps_server_table} WHERE id='" . $_REQUEST["edithost"] . "';";
    $r = mysql_query($q) or die("Cannot execute query \"{$q}\" line " . __LINE__ . " file " . __FILE__ . " sql said: " . mysql_error());
    $a = mysql_fetch_array($r);
    $q = "INSERT INTO {$pro_mysql_vps_server_lists_table} (id,hostname,list_name) VALUES ('','" . $a["hostname"] . "','" . $_REQUEST["name"] . "');";
    $r = mysql_query($q) or die("Cannot execute query \"{$q}\" line " . __LINE__ . " file " . __FILE__ . " sql said: " . mysql_error());