Exemplo n.º 1
0
 /** assign a known asset */
 function assignKnown($serviceId, $assetId)
 {
     $fields = array('service_id' => $serviceId, 'status' => 1, 'date_last' => time());
     $db =& DB();
     $sql = sqlUpdate($db, "asset", $fields, "id = ::{$assetId}::");
     $db->Execute($sql);
 }
Exemplo n.º 2
0
 function user_search($VAR)
 {
     if (SESS_LOGGED) {
         include_once PATH_MODULES . "voip/voip.inc.php";
         $db =& DB();
         $v = new voip();
         $fdids = $v->get_fax_dids(SESS_ACCOUNT);
         #echo "<pre>".print_r($fdids,true)."</pre>";
         if (is_array($fdids)) {
             foreach ($fdids as $did) {
                 $flds['account_id'] = SESS_ACCOUNT;
                 $flds['site_id'] = DEFAULT_SITE;
                 $sql = sqlUpdate($db, "voip_fax", $flds, "dst = ::" . $did . "::");
                 $db->Execute($sql);
                 #echo $sql."<br>";
             }
         }
         unset($db);
         $VAR['voip_fax_account_id'] = SESS_ACCOUNT;
         $type = "search";
         $this->method["{$type}"] = split(",", $this->method["{$type}"]);
         $db = new CORE_database();
         $db->search($VAR, $this, $type);
     } else {
         define("FORCE_REDIRECT", "?_page=account:account");
     }
 }
 /** update system message */
 function add($VAR)
 {
     @($m = $VAR['message']);
     $db =& DB();
     $fields = array('date_orig' => time(), 'message' => $m);
     $db->Execute(sqlUpdate($db, "account_message", $fields, "id = 1"));
 }
Exemplo n.º 4
0
 function save()
 {
     if (!is_array($this->data)) {
         echo "Invalid state to save voipDID.";
         return;
     }
     $db =& DB();
     $sql = sqlUpdate($db, "voip_did", $this->data, "id=::" . $this->data['id'] . "::");
     #echo $sql."<BR />";
     $db->Execute($sql);
 }
Exemplo n.º 5
0
 function user_view($VAR)
 {
     /* validate, update to read, and view() */
     if (!SESS_LOGGED || empty($VAR['id'])) {
         return false;
     }
     /* select id for this user */
     $db =& DB();
     $rs = $db->Execute(sqlSelect($db, "email_log", "*", "id=::{$VAR['id']}:: and account_id=" . SESS_ACCOUNT));
     if ($rs && $rs->RecordCount()) {
         global $smarty;
         $smarty->assign('email_log', $rs->fields);
         if ($rs->fields['userread'] != 1) {
             /* update to read */
             $fields = array('userread' => 1);
             $db->Execute(sqlUpdate($db, "email_log", $fields, "id = {$rs->fields['id']}"));
         }
     }
 }
Exemplo n.º 6
0
 function task_area()
 {
     include_once PATH_MODULES . 'voip/voip.inc.php';
     $db =& DB();
     $didArea = new didArea();
     $sql = sqlSelect($db, "voip_pool", "*", "areacode is null or areacode=0");
     $rs = $db->Execute($sql);
     if ($rs && $rs->RecordCount()) {
         while (!$rs->EOF) {
             $n = $rs->fields['npa'] . $rs->fields['nxx'] . $rs->fields['station'];
             if (($area = $didArea->determineArea($rs->fields['country_code'], $n)) !== false) {
                 #echo "DID=".$n." has an area of $area = ".$didArea->getName($rs->fields['country_code'],$area)."<br>";
                 $f = array('areacode' => $db->qstr($area));
                 $sql = sqlUpdate($db, "voip_pool", $f, "id=" . $rs->fields['id']);
                 #echo "plugin_id=".$rs->fields['voip_did_plugin_id']."<br>";
                 #echo $sql."<br>";
                 $db->Execute($sql);
             }
             $rs->MoveNext();
         }
     }
 }
Exemplo n.º 7
0
function instAdaptPathInDB(&$session, &$message)
{
    $path = getParentDir($session, $session->fScriptBase);
    if (empty($path)) {
        $path = PATH_DELIM;
    }
    instUpdateMacro($session, 'base:BaseModule', $path . "index.php/", $message);
    instUpdateMacro($session, 'forum:ForumModule', $path . "forum.php/", $message);
    instUpdateMacro($session, 'base:ScriptBase', $path, $message);
    $count = sqlUpdate($session, 'param', " text='" . $path . "css/phpwiki.css'", "pos=152", true);
    if ($count == 0) {
        $message .= "\n<br>+++ Parameter 152 (CSS-Datei) nicht gefunden.";
    } else {
        $message .= "<br>\n" . 'CSS wurde auf ' . $path . "css/phpwiki.css gesetzt. ({$count} mal)";
    }
}
Exemplo n.º 8
0
 /** provision did */
 function provision_did_new($obj)
 {
     @($a = unserialize($obj->service['prod_attr_cart']));
     $did = $a['station'];
     // new or top-up?
     $db =& DB();
     $didrs = $db->Execute($sql = sqlSelect($db, "voip_prepaid", "id,pin,balance", "pin = ::{$did}:: AND voip_did_id is not null AND voip_did_id <> 0 "));
     if ($didrs && $didrs->RecordCount() > 0) {
         $new = false;
     } else {
         $new = true;
     }
     // the balance from the invoice line item (not including setup fee)
     $itemid = $obj->service['invoice_item_id'];
     $invoiceItem = $db->Execute(sqlSelect($db, "invoice_item", "price_base", "id = {$itemid}"));
     if ($invoiceItem && $invoiceItem->RecordCount() > 0) {
         $balance = $invoiceItem->fields['price_base'];
     } else {
         $balance = $obj->service['price'];
     }
     /*
     		echo "<BR><BR>$sql<BR><BR>";
     		
     		echo $new;
      
     		echo "$".$balance;
     		
     		#print_r($obj->service);
     */
     if ($new) {
         // include voip plugin and provision the did
         include_once PATH_PLUGINS . 'product/VOIP.php';
         $voip = new plgn_prov_VOIP();
         if (!$voip->p_one($obj->service_id)) {
             return false;
         }
         # create the prepaid record
         $didrs = $db->Execute(sqlSelect($db, "voip_did", "id,did", "service_id = ::{$obj->service_id}::"));
         if ($didrs && $didrs->RecordCount() > 0) {
             $fields = array('account_id' => $obj->account['id'], 'product_id' => $obj->service['product_id'], 'voip_did_id' => $didrs->fields['id'], 'pin' => $didrs->fields['did'], 'balance' => $balance, 'in_use' => 0);
             $pin_id = sqlGenID($db, "voip_prepaid");
             $sql = sqlInsert($db, "voip_prepaid", $fields, $pin_id);
             $rs = $db->Execute($sql);
             return true;
         } else {
             return false;
         }
     } else {
         # top-up the prepaid balance
         $fields = array('balance' => $balance + $didrs->fields['balance']);
         $db->Execute($sql = sqlUpdate($db, "voip_prepaid", $fields, "id = {$didrs->fields['id']}"));
         return true;
     }
     return true;
 }
Exemplo n.º 9
0
 /**
  * Add a discount at the cart/checkout by user/admin
  *
  * @param array $VAR
  * @return bool
  */
 function add_cart_discount($VAR)
 {
     global $C_debug, $C_translate, $smarty;
     # Validate input
     if (empty($VAR["discount"])) {
         $C_debug->alert($C_translate->translate('invalid_discount', 'checkout', ''));
         return false;
     }
     $discount_code = $VAR["discount"];
     # Check the supplied discount
     $db =& DB();
     $rs = $db->Execute(sqlSelect($db, "discount", "*", "( date_start IS NULL OR date_start=0 OR date_start>" . time() . ") AND date_expire<=" . time() . " AND name=::{$discount_code}::"));
     if (!$rs || !$rs->RecordCount() || $rs->fields["status"] != '1') {
         // local check failed, attempt any discount plugins
         $plg = false;
         if ($this->plugins && is_array($this->plugins)) {
             foreach ($this->plugins as $plugin) {
                 if ($discount_code = $this->plugin_validate($plugin, $discount_code)) {
                     $plg = true;
                     break;
                 }
             }
         }
         // no plugins returned true...
         if (!$plg) {
             $C_debug->alert($C_translate->translate('invalid_discount', 'checkout', ''));
             return false;
         }
     }
     # get existing discounts:
     $arr = array();
     $rs = $db->Execute(sqlSelect($db, "session", "discounts", "id=::" . SESS . "::"));
     if ($rs && $rs->RecordCount() && !empty($rs->fields['discounts']) && is_string($rs->fields['discounts'])) {
         $arr = unserialize($rs->fields['discounts']);
     }
     # check for duplicates
     $do = true;
     if (is_array($arr)) {
         foreach ($arr as $key => $discount) {
             if ($discount == $discount_code) {
                 unset($arr[$key]);
                 $do = false;
             }
         }
     }
     # update session data
     if ($do) {
         $arr[] = $discount_code;
     }
     $rs = $db->Execute(sqlUpdate($db, "session", array('discounts' => serialize($arr)), "id=::" . SESS . "::"));
     return true;
 }
Exemplo n.º 10
0
 /** Save the configuration.
  */
 function config($VAR)
 {
     global $C_debug;
     $db =& DB();
     # define the validation class
     include_once PATH_CORE . 'validate.inc.php';
     $validate = new CORE_validate();
     $arr['min_len'] = 4;
     $arr['max_len'] = 4;
     if (is_numeric($VAR['voip_vm_passwd']) && !empty($VAR['voip_intrastate'])) {
         $fields['voip_vm_passwd'] = $VAR['voip_vm_passwd'];
         $fields['voip_intrastate'] = $VAR['voip_intrastate'];
         $fields['voip_secret_gen'] = $VAR['voip_secret_gen'];
         $fields['voip_default_prefix'] = $VAR['voip_default_prefix'];
         $fields['prepaid_low_balance'] = $VAR['prepaid_low_balance'];
         $fields['auth_domain'] = $VAR['auth_domain'];
         $fields['perform_normalization'] = $VAR['perform_normalization'];
         $fields['normalization_min_len'] = $VAR['normalization_min_len'];
         $rs = $db->Execute(sqlSelect($db, "voip", "id", "site_id=::" . DEFAULT_SITE . "::"));
         if ($rs && !$rs->EOF) {
             $db->Execute(sqlUpdate($db, "voip", $fields, "site_id=::" . DEFAULT_SITE . "::"));
         } else {
             $db->Execute(sqlInsert($db, "voip", $fields));
         }
         $C_debug->alert("Saved!");
     } else {
         $C_debug->alert("Problems while saving:" . $db->ErrorMsg());
     }
 }
Exemplo n.º 11
0
 /**
  * Change the quantity of an item 
  */
 function changeqty($VAR)
 {
     if (empty($this->account_id)) {
         $this->account_id = SESS_ACCOUNT;
     }
     if (empty($this->session_id)) {
         $this->session_id = SESS;
     }
     @($id = $VAR['id']);
     @($qty = $VAR['qty']);
     if ($id <= 0) {
         return;
     }
     $db =& DB();
     if ($qty == '0') {
         # Product Plugin Level deletion
         $cartid =& $db->Execute($sql = sqlSelect($db, "cart", "*", "id=::{$id}:: AND session_id = ::{$this->session_id}::"));
         if ($cartid) {
             $product =& $db->Execute($sql = sqlSelect($db, "product", "*", "id=::{$cartid->fields['product_id']}::"));
         }
         if (!empty($product->fields['prod_plugin']) && !empty($product->fields['prod_plugin_data'])) {
             $prodplgfile = PATH_PLUGINS . 'product/' . $product->fields['prod_plugin_file'] . '.php';
             if (is_file($prodplgfile)) {
                 include_once PATH_PLUGINS . 'product/' . $product->fields['prod_plugin_file'] . '.php';
                 eval('$prodplg = new plgn_prov_' . $product->fields['prod_plugin_file'] . ';');
                 if (is_object($prodplg)) {
                     if (is_callable(array($prodplg, 'delete_cart'))) {
                         $prodplg->delete_cart($VAR, $cartid->fields);
                     }
                 }
             }
         }
         # delete main cart items & subitems:
         $sql = '';
         if (empty($this->admin)) {
             $sql = "AND session_id = ::{$this->session_id}::";
         }
         $rs =& $db->Execute($sql = sqlDelete($db, "cart", "(id=::{$id}:: OR cart_parent_id=::{$id}:: ) {$sql}"));
         global $smarty;
         $smarty->assign('js', false);
         return false;
     }
     # update the quantity:
     if (!eregi("^[0-9]{1,5}\$", $qty)) {
         $qty = 1;
     }
     if ($qty < 1) {
         $qty = 1;
     }
     if (!$this->admin) {
         $sql_extra = " AND session_id=::{$this->session_id}::";
     } else {
         $sql_extra = '';
     }
     if ($VAR["type"] == 1) {
         $fields = array('quantity' => $qty);
         $db->Execute($sql = sqlUpdate($db, "cart", $fields, "id=::{$id}:: {$sql_extra}"));
     } else {
         if ($VAR["type"] == 2) {
             $fields = array('recurr_schedule' => $VAR["schedule"]);
             $db->Execute($sql = sqlUpdate($db, "cart", $fields, "id=::{$id}:: {$sql_extra}"));
         } else {
             if ($VAR["type"] == 3) {
                 # change domain term
                 $fields = array('domain_term' => $VAR["term"]);
                 $db->Execute($sql = sqlUpdate($db, "cart", $fields, "id=::{$id}:: {$sql_extra}"));
             }
         }
     }
     # get the product id:
     $result = $db->Execute(sqlSelect($db, "cart", "*", "id={$id} {$sql_extra}", "cart_type,date_orig"));
     # get the product details:
     $product = $db->Execute(sqlSelect($db, "product", "*", "id={$result->fields["product_id"]}"));
     if ($result->fields["cart_type"] == "2") {
         # domain name, get pricing
         include_once PATH_MODULES . 'host_tld/host_tld.inc.php';
         $tldObj = new host_tld();
         $tldprice = $tldObj->price_tld_arr($result->fields["domain_tld"], $result->fields["host_type"], false, false, false, $this->account_id);
         $qty = $result->fields["domain_term"];
         $base_price = $tldprice[$qty];
         $setup_price = 0;
     } else {
         if ($result->fields["cart_type"] == "3") {
             # ad-hoc, get price
             $base_price = $result->fields["ad_hoc_amount"] * $result->fields["quantity"];
             $setup_price = $result->fields["ad_hoc_setup"] * $result->fields["quantity"];
         } else {
             include_once PATH_MODULES . 'product/product.inc.php';
             $productObj = new product();
             # get pricing for this product:
             $prod_price = $productObj->price_prod($product->fields, $result->fields["recurr_schedule"], $this->account);
             $setup_price = $prod_price["setup"] * $result->fields["quantity"];
             $base_price = $prod_price["base"] * $result->fields["quantity"];
             # get pricing for any attributes:
             $attr_price = $productObj->price_attr($product->fields, $result->fields["product_attr"], $result->fields["recurr_schedule"], $this->account);
             $setup_price += $attr_price["setup"] * $result->fields["quantity"];
             $base_price += $attr_price["base"] * $result->fields["quantity"];
             # get the qty
             $qty = $result->fields["quantity"];
         }
     }
     # set the smarty fields:
     global $smarty;
     $smarty->assign('qty', $qty);
     $smarty->assign('base', $base_price);
     $smarty->assign('setup', $setup_price);
     $smarty->assign('js', true);
     return;
 }
Exemplo n.º 12
0
 /** Invoice expiring domains p2 
  */
 function generatedomaininvoice($VAR)
 {
     include_once PATH_MODULES . 'tax/tax.inc.php';
     $taxObj = new tax();
     $db =& DB();
     if (is_array($VAR)) {
         $expire = time();
         $rs = $db->Execute(sqlSelect($db, 'service', '*', " id = ::{$VAR['id']}:: AND active=1\n\t        \t\t\t\tAND type = 'domain' AND queue = 'none' AND\n\t        \t\t\t\t( domain_type = 'register' OR domain_type = 'transfer' OR domain_type = 'renew'  ) AND\n\t        \t\t\t\t( suspend_billing = 0 OR suspend_billing IS NULL ) "));
         $service = $rs->fields;
     } else {
         $service = $VAR;
     }
     if (empty($service['id'])) {
         global $C_debug;
         $C_debug->alert("Unable to generate domain renweal invoice due to domain status.");
         return false;
     }
     # Get the parent invoice details:
     if (!empty($service['invoice_id'])) {
         $rs = $db->Execute(sqlSelect($db, 'invoice', '*', " id = {$service['invoice_id']} ", ""));
         $invoice = $rs->fields;
     } else {
         $invoice = false;
     }
     # Get the account details:
     $rs = $db->Execute(sqlSelect($db, 'account', '*', " id = {$service['account_id']} ", ""));
     $account = $rs->fields;
     # Get the account price
     include_once PATH_MODULES . 'host_tld/host_tld.inc.php';
     $tldObj = new host_tld();
     $tld_arr = $tldObj->price_tld_arr($service['domain_tld'], 'renew', false, false, false, $service['account_id']);
     foreach ($tld_arr as $term => $price) {
         break;
     }
     # Calculate taxes:
     $rs = $db->Execute($sql = sqlSelect($db, "host_tld", "taxable", "name = ::{$service['domain_tld']}::"));
     if ($service['taxable'] || @$rs->fields['taxable']) {
         $tax_arr = $taxObj->calculate($price, $account["country_id"], $account["state"]);
     } else {
         $tax_arr = false;
     }
     $total = $price;
     $tax_amt = 0;
     if (is_array($tax_arr)) {
         foreach ($tax_arr as $tx) {
             $tax_amt += $tx['rate'];
         }
         $total += $tax_amt;
     }
     # calculate the dates
     $expire = $service['domain_date_expire'] + $term * 86400;
     $due_date = $service['domain_date_expire'] - 86400 * 3;
     # Create the invoice
     $id = sqlGenID($db, "invoice");
     $insert = $db->Execute($sql = sqlInsert($db, "invoice", array('date_orig' => time(), 'date_last' => time(), 'type' => 2, 'process_status' => 0, 'billing_status' => 0, 'suspend_billing' => 0, 'print_status' => 0, 'parent_id' => $service['invoice_id'], 'account_id' => $service['account_id'], 'account_billing_id' => $service['account_billing_id'], 'affiliate_id' => @$invoice['affiliate_id'], 'campaign_id' => @$invoice['campaign_id'], 'reseller_id' => @$invoice['reseller_id'], 'checkout_plugin_id' => @$invoice['checkout_plugin_id'], 'tax_amt' => $tax_amt, 'discount_arr' => serialize(@$discount_arr), 'discount_amt' => @$discount_amt, 'total_amt' => $total, 'billed_amt' => 0, 'billed_currency_id' => DEFAULT_CURRENCY, 'actual_billed_amt' => 0, 'actual_billed_currency_id' => @$invoice['actual_billed_currency_id'], 'notice_count' => 0, 'notice_next_date' => time(), 'notice_max' => MAX_BILLING_NOTICE, 'grace_period' => 0, 'due_date' => $due_date), $id));
     # create the invoice item:
     if ($insert) {
         $db->Execute($idx = sqlInsert($db, "invoice_item", array('date_orig' => time(), 'invoice_id' => $id, 'account_id' => $service['account_id'], 'service_id' => $service['id'], 'sku' => 'DOMAIN-RENEW', 'quantity' => 1, 'item_type' => 2, 'price_type' => 0, 'price_base' => $price, 'price_setup' => 0, 'domain_type' => 'renew', 'date_start' => $service['domain_date_expire'], 'date_stop' => $expire, 'domain_name' => $service['domain_name'], 'domain_tld' => $service['domain_tld'], 'domain_term' => $term, 'tax_amt' => $tax_amt, 'total_amt' => $price)));
         # Insert tax records
         $taxObj->invoice_item($id, $idx, $service['account_id'], @$item_tax_arr);
         # Update the service record
         $fields = array('active' => 0);
         $db->Execute(sqlUpdate($db, "service", $fields, "id = {$service['id']}"));
         global $C_debug;
         $C_debug->alert("Generated domain renewal invoice for {$service['domain_name']}.{$service['domain_tld']}");
         return $id;
     }
 }
Exemplo n.º 13
0
 /**
  * Activate a radius account 
  */
 function p_active()
 {
     $db =& DB();
     $db->Execute(sqlUpdate($db, "radius", array("active" => 1), "service_id={$this->service['id']}"));
     return true;
 }
Exemplo n.º 14
0
 /**
  * Create the Invoice Record and send user to checkout	 
  */
 function checkoutnow($VAR)
 {
     global $C_translate, $C_list, $smarty;
     $db =& DB();
     // Validate user is logged in:
     if (!SESS_LOGGED) {
         echo '<script language="JavaScript">alert("You must be logged in to complete this purchase! Please refresh this page in your browser to login now...");</script>';
         return false;
     }
     // check for admin
     if (!$this->admin_checkout && !empty($VAR['account_id'])) {
         global $C_auth;
         if (!empty($VAR['account_id']) && $C_auth->auth_method_by_name('checkout', 'admin_checkoutnow')) {
             $this->account_id = $VAR['account_id'];
             $this->admin_checkout = true;
         } else {
             $this->account_id = SESS_ACCOUNT;
         }
     }
     if (empty($this->session_id)) {
         $this->session_id = SESS;
     }
     if (empty($this->account_id)) {
         $this->account_id = SESS_ACCOUNT;
     }
     include_once PATH_MODULES . '/cart/cart.inc.php';
     $cartObj = new cart();
     $cartObj->account_id = $this->account_id;
     $cartObj->session_id = $this->session_id;
     $result = $cartObj->get_contents($db);
     if ($result->RecordCount() == 0) {
         return false;
     }
     // load invoice object
     include_once PATH_MODULES . 'invoice/invoice.inc.php';
     $invoice = new invoice();
     $invoice->account_id = $this->account_id;
     $invoice->initNew(0);
     // Get the account details:
     $account = $db->Execute(sqlSelect($db, "account", "*", "id=::{$this->account_id}::"));
     $invoice->country_id = $account->fields['country_id'];
     $invoice->state = $account->fields['state'];
     // load tax object for tax calculation
     include_once PATH_MODULES . 'tax/tax.inc.php';
     $taxObj = new tax();
     // load discount object for discount calculation
     include_once PATH_MODULES . 'discount/discount.inc.php';
     $discountObj = new discount();
     $discountObj->available_discounts($invoice->account_id);
     // put cart contents into invoice format
     $cartObj->put_contents_invoice($db, $result, $invoice, $smart, $taxObj, $discountObj);
     // Validate and init a checkout plugin
     $checkout = false;
     if ($this->admin_checkout_option) {
         // admin checkout option specified
         include_once PATH_MODULES . 'checkout/checkout_admin.inc.php';
         $PLG = new checkout_admin();
         $checkout = true;
         $invoice->checkout_plugin_id = false;
     } else {
         // get available checkout options and check against the one provided
         $invoice->checkout_plugin_id = $VAR['option'];
         foreach ($invoice->invoice_item as $item) {
             if (!empty($item['product_id'])) {
                 $product_arr[] = $item['product_id'];
             }
         }
         $checkout_options = $this->get_checkout_options($this->account_id, $invoice->total_amt, @$product_arr, $invoice->country_id, $invoice->any_new, $invoice->any_trial, $invoice->any_recurring);
         if ($checkout_options) {
             foreach ($checkout_options as $a) {
                 if ($a['fields']['id'] == $invoice->checkout_plugin_id) {
                     // load the selected checkout plugin and run pre-validation
                     $checkout_plugin = $a['fields']['checkout_plugin'];
                     $plugin_file = PATH_PLUGINS . 'checkout/' . $checkout_plugin . '.php';
                     include_once $plugin_file;
                     eval('$PLG = new plg_chout_' . $checkout_plugin . '("' . $invoice->checkout_plugin_id . '");');
                     $plugin_validate = $PLG->validate($VAR, $this);
                     if ($plugin_validate != true) {
                         echo $plugin_validate;
                         return false;
                     }
                     $checkout = true;
                     break;
                 }
             }
         }
     }
     if (!$checkout) {
         echo '<script language=Javascript> alert("Unable to checkout with the selected method, please select another."); </script> ';
         return false;
     }
     // validate credit card on file details
     global $VAR;
     if (!empty($VAR['account_billing_id']) && @$VAR['new_card'] == 2) {
         $invoice->account_billing_id = $VAR['account_billing_id'];
         /* validate credit card on file details */
         if (!$PLG->setBillingFromDB($this->account_id, $invoice->account_billing_id, $invoice->checkout_plugin_id)) {
             global $C_debug;
             $C_debug->alert("Sorry, we cannot use that billing record for this purchase.");
             return false;
         }
     } else {
         /* use passed in vars */
         $PLG->setBillingFromParams($VAR);
     }
     // validate recurring processing options
     if ($PLG->recurr_only) {
         if ($invoice->recur_amt <= 0) {
             echo '<script language=Javascript> alert("Cannot process non-recurring charges with this payment option, please select another payment option."); </script> ';
             return false;
         }
         if (is_array($invoice->recur_arr) && count($invoice->recur_arr) > 1) {
             $recurring = true;
             // validate recur day and recurring schedule are the same for both products
             foreach ($invoice->recur_arr as $a) {
                 foreach ($invoice->recur_arr as $b) {
                     foreach ($b as $key => $val) {
                         if ($key != 'price' && $key != 'recurr_week' && $a[$key] != $val) {
                             $recurring = false;
                             break;
                         }
                     }
                 }
             }
             if (!$recurring) {
                 echo '<script language=Javascript> alert("This payment option cannot be used when ordering both prorated and non-prorated subscriptions, or when ordering two or more subscriptions with different billing schedules selected. Please make sure all your subscriptions have the same billing schedule selected, try another payment option, or order one subscription at a time. We apologize for any inconvenience."); </script> ';
                 return false;
             }
         }
     }
     # Affiliate
     if (empty($this->affiliate_id)) {
         if (!empty($account->fields['affiliate_id'])) {
             $invoice->affiliate_id = $account->fields['affiliate_id'];
         } else {
             $invoice->affiliate_id = SESS_AFFILIATE;
         }
     }
     # Campaign
     if (empty($this->campaign_id)) {
         if (!empty($account->fields['campaign_id'])) {
             $invoice->campaign_id = $account->fields['campaign_id'];
         } else {
             $invoice->campaign_id = SESS_CAMPAIGN;
         }
     }
     $invoice->record_id = sqlGenID($db, "invoice");
     $invoice->actual_billed_currency_id = SESS_CURRENCY;
     $invoice->billed_currency_id = DEFAULT_CURRENCY;
     $invoice->checkout_type = $PLG->type;
     // initial invoice status
     if ($invoice->total_amt == 0 || $PLG->type == 'gateway') {
         $invoice->billing_status = 1;
         $invoice->actual_billed_amt = $C_list->format_currency_decimal($invoice->total_amt, SESS_CURRENCY);
         $invoice->billed_amt = $invoice->total_amt;
     }
     // Currency conversion:
     if (SESS_CURRENCY != DEFAULT_CURRENCY) {
         $bill_amt = $C_list->format_currency_decimal($invoice->total_amt, SESS_CURRENCY);
         $recur_amt = $C_list->format_currency_decimal($invoice->recur_amt, SESS_CURRENCY);
     } else {
         $bill_amt = round($invoice->total_amt, 2);
         $recur_amt = round($invoice->recur_amt, 2);
     }
     // Get currency ISO (three_digit) for checkout plugin
     $currrs = $db->Execute(sqlSelect($db, "currency", "three_digit", "id=" . SESS_CURRENCY));
     if ($currrs && $currrs->RecordCount()) {
         $currency_iso = $currrs->fields['three_digit'];
     }
     // Run the plugin bill_checkout() method:
     $currency_iso = $C_list->currency_iso(SESS_CURRENCY);
     $invoice->checkout_plugin_data = $PLG->bill_checkout($bill_amt, $invoice->record_id, $currency_iso, $account->fields, $recur_amt, $invoice->recur_arr);
     if ($invoice->checkout_plugin_data === false || $invoice->checkout_plugin_data == '') {
         if (!empty($PLG->redirect)) {
             echo $PLG->redirect;
         }
         return false;
     } elseif ($PLG->type == "gateway" || empty($PLG->redirect)) {
         $VAR['id'] = $invoice->record_id;
         if (!$this->admin_checkout) {
             $VAR['_page'] = "invoice:thankyou";
         }
         $invoice->checkout_plugin_data = false;
     } elseif (!$this->admin_checkout) {
         echo "<html><head></head><body><center>\n\t\t\t\tPlease wait while we redirect you to the secure payment site....\n\t\t\t\t{$PLG->redirect}</center></body></html>";
     }
     // Call the Plugin method for storing the checkout data:
     $invoice->account_billing_id = $PLG->store_billing($VAR, $invoice->account_id);
     // clear user discounts
     $fields = array('discounts' => "");
     $db->Execute(sqlUpdate($db, "session", $fields, "id = ::" . SESS . "::"));
     // admin options
     $email = true;
     if ($this->admin_checkout) {
         if (empty($VAR['send_email']) || $VAR['send_email'] == 'false') {
             $email = false;
         } else {
             $email = true;
         }
         if (!empty($VAR['due_date'])) {
             $invoice->due_date = $this->getInputDate($VAR['due_date']);
         }
         if (!empty($VAR['grace_period'])) {
             $invoice->grace_period = $VAR['grace_period'];
         }
         if (!empty($VAR['notice_max'])) {
             $invoice->notice_max = $VAR['notice_max'];
         }
     }
     if ($invoice->commitNew($taxObj, $discountObj, $email)) {
         // delete all cart items
         $db->Execute(sqlDelete($db, "cart", "(session_id=::" . SESS . ":: OR account_id={$invoice->account_id})"));
         // admin redirect
         if ($this->admin_checkout) {
             $url = URL . 'admin.php?_page=invoice:view&id=' . $invoice->record_id;
             echo '<script language="javascript"> parent.location.href=\'' . $url . '\';</script>';
         }
     }
     return false;
 }
Exemplo n.º 15
0
 function p_active()
 {
     $db =& DB();
     $rs = $db->Execute(sqlSelect($db, "voip_did", "id,did", "service_id = {$this->service_id}"));
     $did_id = $rs->fields['id'];
     $fields = array('in_use' => 0);
     $db->Execute(sqlUpdate($db, "voip_prepaid", $fields, "voip_did_id = {$did_id}"));
     return true;
 }
Exemplo n.º 16
0
 function task($VAR)
 {
     require_once PATH_MODULES . 'email_template/email_template.inc.php';
     require_once PATH_MODULES . 'invoice/invoice.inc.php';
     $invoice = new invoice();
     # get active net terms
     $db =& DB();
     $rs =& $db->Execute($sql = sqlSelect($db, "net_term", "*", "status=1"));
     if ($rs && $rs->RecordCount() > 0) {
         // loop through net terms
         while (!$rs->EOF) {
             $id = $rs->fields['id'];
             $last_interval = mktime(0, 0, 0, date('m'), date('d') - $rs->fields['terms'], date('Y'));
             $i =& $db->Execute($sql = sqlSelect($db, "invoice", "id,account_id,total_amt,billed_amt,due_date,net_term_date_last,net_term_intervals", "net_term_id = {$id} AND\n\t\t\t\t\t (suspend_billing = 0 OR suspend_billing IS NULL) AND\n\t\t\t\t\t (billing_status = 0 OR billing_status IS NULL) AND \n\t\t\t\t\t due_date <= {$last_interval} AND\n\t\t\t\t\t net_term_date_last <= {$last_interval}"));
             if ($i && $i->RecordCount() > 0) {
                 // loop through invoices
                 while (!$i->EOF) {
                     $terms = $rs->fields['terms'];
                     echo "<BR>" . ($start_interval = $i->fields['net_term_date_last']);
                     echo "<BR>" . ($stop_interval = $start_interval + 86400 * $terms);
                     echo "<BR>" . date(UNIX_DATE_FORMAT, $start_interval);
                     // charge or suspend?
                     if (!empty($i->fields['net_term_intervals']) && $rs->fields['suspend_intervals'] < $i->fields['net_term_intervals']) {
                         // suspend invoice
                         $arr['id'] = $i->fields['id'];
                         $na =& $invoice->voidInvoice($arr, $invoice);
                         // suspend billing status
                         $fields = array('suspend_billing' => 1);
                         $db->Execute($sql = sqlUpdate($db, "invoice", $fields, "id = {$i->fields['id']}"));
                         // send suspend e-mail
                         if ($rs->fields['enable_emails']) {
                             $email = new email_template();
                             $email->send('net_term_suspend', $i->fields['account_id'], $i->fields['id'], $rs->fields['suspend_intervals'], $i->fields['net_term_intervals']);
                         }
                     } else {
                         // calc late fee
                         if ($rs->fields['fee_type'] == 1) {
                             $fee = $rs->fields['fee'];
                         } else {
                             $fee = ($i->fields['total_amt'] - $i->fields['billed_amt']) * $rs->fields['fee'];
                         }
                         // create late charge
                         if ($fee > 0) {
                             $fields = array('date_orig' => time(), 'status' => 0, 'account_id' => $i->fields['account_id'], 'amount' => $fee, 'sweep_type' => $rs->fields['sweep_type'], 'taxable' => $this->taxable, 'quantity' => 1, 'attributes' => "Name=={$rs->fields['name']}\r\nInterval==" . date(UNIX_DATE_FORMAT, $start_interval) . " - " . date(UNIX_DATE_FORMAT, $stop_interval), 'description' => $rs->fields['sku']);
                             $db->Execute($sql = sqlInsert($db, "charge", $fields));
                             // update invoice
                             $_fields['net_term_intervals'] = $i->fields['net_term_intervals'] + 1;
                             $_fields['net_term_date_last'] = $stop_interval;
                             $db->Execute($sql = sqlUpdate($db, "invoice", $_fields, "id={$i->fields['id']}"));
                             echo "<BR><BR>{$sql}";
                         }
                         // send late fee/payment reminder e-mail:
                         if ($rs->fields['enable_emails']) {
                             $email = new email_template();
                             $email->send('net_term_late_notice', $i->fields['account_id'], $i->fields['id'], number_format($fee, 2), number_format($rs->fields['suspend_intervals'] - $i->fields['net_term_intervals']));
                         }
                     }
                     $i->MoveNext();
                 }
             }
             $rs->MoveNext();
         }
     }
 }
Exemplo n.º 17
0
 function renewDomain($item, $billing_id)
 {
     $db =& DB();
     $dbm = new CORE_database();
     # Get the current service details:
     $service = $db->Execute($dbm->sql_select('service', '*', "id = {$item->fields['service_id']}", '', $db));
     # Get new dates
     $term = $service->fields['domain_term'] + $item->fields['domain_term'];
     $expire = $service->fields['domain_date_expire'] + 86400 * 365 * $item->fields['domain_term'];
     $rs = $db->Execute($sql = sqlUpdate($db, 'service', array('date_last_invoice' => $service->fields['domain_date_expire'], 'domain_date_expire' => $expire, 'domain_term' => $term, 'domain_type' => 'renew', 'queue' => 'new', 'account_billing_id' => $billing_id), " id = {$item->fields['service_id']} "));
     if ($rs) {
         return true;
     }
     return false;
 }
Exemplo n.º 18
0
 /**
  * Update password list 
  */
 function do_update($VAR)
 {
     global $smarty, $C_debug, $C_translate;
     $db =& DB();
     $msg = false;
     # Validate logged in:
     if (!SESS_LOGGED) {
         $C_debug->alert("You must be logged in!");
         return;
     }
     # Loop through the submitted passwords for update:
     if (!empty($VAR['username']) && is_array($VAR['username'])) {
         foreach ($VAR['username'] as $id => $val) {
             $user = $VAR['username'][$id];
             @($pass = $VAR['password'][$id]);
             $result = $db->Execute(sqlSelect($db, "radius", "*", "id=::{$id}:: AND account_id=::" . SESS_ACCOUNT . "::"));
             if ($result && $result->RecordCount()) {
                 if ($result->fields['auth'] == 'login') {
                     if (!$this->validate_login($user, $pass) || !$this->validate_unique($id, $user)) {
                         $C_translate->value["radius"]["user"] = $user;
                         $C_translate->value["radius"]["pass"] = $pass;
                         $msg .= $C_translate->translate("err_login", "radius") . "<br>";
                     } else {
                         // update login record
                         $db->Execute(sqlUpdate($db, "radius", array('password' => $pass, 'username' => $user), "id={$id}"));
                         #$used_login++;
                     }
                 } elseif ($result->fields['auth'] == 'wireless') {
                     // validate mac id
                     $user = strtoupper($user);
                     $user = str_replace("-", " ", $user);
                     if (!$this->validate_wireless($user) || !$this->validate_unique($id, $user)) {
                         $C_translate->value["radius"]["user"] = $user;
                         $msg .= $C_translate->translate("err_wireless", "radius") . "<br>";
                     } else {
                         $db->Execute(sqlUpdate($db, "radius", array('username' => $user), "id={$id}"));
                     }
                 }
             }
         }
     }
     # Loop through the submitted passwords for additions:
     if (!empty($VAR['new_username']) && is_array($VAR['new_username'])) {
         foreach ($VAR['new_username'] as $id => $val) {
             if (!empty($VAR['new_username'][$id])) {
                 $user = $VAR['new_username'][$id];
                 @($pass = $VAR['new_password'][$id]);
                 // validation
                 $rsRS = $db->Execute(sqlSelect($db, "radius_service", "*", "id=::{$id}:: AND account_id=::" . SESS_ACCOUNT . "::"));
                 $service_id = $rsRS->fields['service_id'];
                 $radius_service_id = $rsRS->fields['id'];
                 if ($rsRS->fields['auth'] == 'login') {
                     if (!$this->validate_login($user, $pass) || !$this->validate_unique(false, $user)) {
                         $C_translate->value["radius"]["user"] = $user;
                         $C_translate->value["radius"]["pass"] = $pass;
                         $msg .= $C_translate->translate("err_login", "radius") . "<br>";
                     } else {
                         // add login record
                         $this->add_radius($service_id, $radius_service_id, $user, $pass);
                     }
                 } elseif ($rsRS->fields['auth'] == 'wireless') {
                     // validate mac id
                     $user = strtoupper($user);
                     $user = str_replace("-", " ", $user);
                     if (!$this->validate_wireless($user) || !$this->validate_unique(false, $user)) {
                         $C_translate->value["radius"]["user"] = $user;
                         $msg .= $C_translate->translate("err_wireless", "radius") . "<br>";
                     } else {
                         // add mac id record
                         $this->add_radius($service_id, $radius_service_id, $user);
                     }
                 }
             }
         }
     }
     if (!empty($msg)) {
         $C_debug->alert($msg);
     }
 }
 /**
  * Task to detect credit cards that are expiring soon and e-mail the user a notice to update the card
  */
 function task($VAR)
 {
     include_once PATH_MODULES . 'email_template/email_template.inc.php';
     $sql = '';
     for ($i = 1; $i < 3; $i++) {
         $exp = mktime(0, 0, 0, date('m') + $i, date('d'), date('Y'));
         $month = date("m", $exp);
         $year = preg_replace("/^20/", "", date("Y", $exp));
         if (!empty($sql)) {
             $sql .= " OR ";
         }
         $sql .= " ( card_exp_month = '{$month}' AND card_exp_year = '{$year}' ) ";
     }
     $db =& DB();
     $rs = $db->Execute($qq = sqlSelect($db, "account_billing", "id,account_id,notify_count", " ( {$sql} ) AND notify_count < 4"));
     if ($rs && $rs->RecordCount()) {
         while (!$rs->EOF) {
             $email = new email_template();
             $email->send('account_billing_exp_soon', $rs->fields['account_id'], $rs->fields['id'], '', '');
             $fields = array('notify_count' => $rs->fields["notify_count"] + 1);
             $db->Execute(sqlUpdate($db, "account_billing", $fields, "id = {$rs->fields['id']}"));
             $rs->MoveNext();
         }
     }
 }
 /**
  * Store the billing credit card entered
  */
 function saveCreditCardDetails($VAR)
 {
     global $C_auth;
     if (!empty($VAR['account_id']) && $C_auth->auth_method_by_name('checkout', 'admin_checkoutnow')) {
         $account_id = $VAR['account_id'];
     } else {
         $account_id = SESS_ACCOUNT;
     }
     # Check if this card is already on file:
     $last_four = substr($this->billing['cc_no'], strlen($this->billing['cc_no']) - 4, 4);
     $db =& DB();
     $q = "SELECT id,card_exp_month,card_exp_year FROM " . AGILE_DB_PREFIX . "account_billing WHERE\n\t\t\tsite_id \t\t= " . $db->qstr(DEFAULT_SITE) . " AND \n\t\t\taccount_id \t\t= " . $db->qstr($account_id) . " AND\n\t\t\tcard_num4 \t\t= " . $db->qstr($last_four) . " AND\n\t\t\tcheckout_plugin_id = " . $db->qstr($this->checkout_id) . " AND\n\t\t\tcard_type\t \t= " . $db->qstr($this->billing['card_type']);
     $rs = $db->Execute($q);
     if ($rs && $rs->RecordCount()) {
         $fields = array('card_exp_month' => $this->billing['exp_month'], 'card_exp_year' => $this->billing['exp_year']);
         $db->Execute(sqlUpdate($db, "account_billing", $fields, "id = {$rs->fields['id']}"));
         return $rs->fields['id'];
     }
     include_once PATH_CORE . 'crypt.inc.php';
     $card_num = CORE_encrypt($this->billing['cc_no']);
     $id = $db->GenID(AGILE_DB_PREFIX . 'account_billing_id');
     $sql = "INSERT INTO " . AGILE_DB_PREFIX . "account_billing SET\n\t\t\tid \t\t\t\t\t= " . $db->qstr($id) . ",\n\t\t\tsite_id\t\t\t\t= " . $db->qstr(DEFAULT_SITE) . ",\n\t\t\taccount_id\t\t\t= " . $db->qstr(@$account_id) . ",\n\t\t\tcheckout_plugin_id\t= " . $db->qstr(@$this->checkout_id) . ", \n\t\t\tcard_type\t\t\t= " . $db->qstr(@$this->billing['card_type']) . ",\n\t\t\tcard_num\t\t\t= " . $db->qstr(@$card_num) . ",\n\t\t\tcard_num4\t\t\t= " . $db->qstr(@$last_four) . ",\n\t\t\tcard_exp_month\t\t= " . $db->qstr(@$this->billing['exp_month']) . ",\n\t\t\tcard_exp_year\t\t= " . $db->qstr(@$this->billing['exp_year']) . ",\n\t\t\tcard_start_month\t= " . $db->qstr(@$this->billing['start_month']) . ",\n\t\t\tcard_start_year\t\t= " . $db->qstr(@$this->billing['start_year']) . ",  \n\t\t\tfirst_name\t\t\t= " . $db->qstr(@$this->account['first_name']) . ",\n\t\t\tlast_name\t\t\t= " . $db->qstr(@$this->account['last_name']) . ",\n\t\t\taddress1\t\t\t= " . $db->qstr(@$this->account['address1']) . ",\n\t\t\taddress2\t\t\t= " . $db->qstr(@$this->account['address2']) . ",\n\t\t\tcity\t\t\t\t= " . $db->qstr(@$this->account['city']) . ",\n\t\t\tstate\t\t\t\t= " . $db->qstr(@$this->account['state']) . ",\n\t\t\tzip\t\t\t\t\t= " . $db->qstr(@$this->account['zip']) . ",\n\t\t\tcountry_id\t\t\t= " . $db->qstr(@$this->account['country_id']) . ",\n\t\t\tphone\t\t\t\t= " . $db->qstr(@$this->account['phone']) . ",\n\t\t\temail\t\t\t\t= " . $db->qstr(@$this->account['email']) . ",\n\t\t\tcompany\t\t\t\t= " . $db->qstr(@$this->account['company']);
     $result = $db->Execute($sql);
     if ($result) {
         return $id;
     }
     return false;
 }