Example #1
0
 /**
  * Insert invoice_item_tax Records
  */
 function invoice_item($invoice_id, $invoice_item_id, $account_id, $tax_arr)
 {
     $db =& DB();
     if (!is_array($tax_arr)) {
         return false;
     }
     foreach ($tax_arr as $tax) {
         $sql = "INSERT INTO " . AGILE_DB_PREFIX . "invoice_item_tax SET id=" . sqlGenID($db, "invoice_item_tax") . ", site_id=" . DEFAULT_SITE . ", date_orig=" . time() . ", invoice_id={$invoice_id}, invoice_item_id={$invoice_item_id}, account_id={$account_id}, tax_id={$tax["id"]}, amount=" . $db->qstr($tax["rate"]);
         $db->Execute($sql);
     }
 }
Example #2
0
 /**
  * TODO: Accountcode based rating, Prepaid based rating
  */
 function c_task($VAR)
 {
     # set the PHP timeout and the don't abort flag
     set_time_limit(60 * 15);
     # normalize the CDR records
     if ($this->perform_normalization) {
         echo "Begin normalization...\n";
         $this->normalize($db);
         echo "Finished normalization...\n";
     }
     # Add in the prepaid rating pieces
     # Begin the postpaid rating
     $bDoCallType = false;
     if (strlen($this->voip_intrastate)) {
         $bDoCallType = true;
     }
     $db =& DB();
     $sql = "select * from " . AGILE_DB_PREFIX . "voip_cdr where \n\t\t(lastapp='Dial' or lastapp='VoiceMail' or lastapp='MeetMe' or lastapp='Hangup') \n\t\tAND disposition='ANSWERED' and rated=2 limit 1000";
     $rs = $db->Execute($sql);
     $i = 0;
     $total = 0.0;
     $st = $this->microtime_float();
     while (!$rs->EOF) {
         unset($match);
         # who does the number belong to?
         $account_id = 0;
         $service_id = 0;
         $product_id = 0;
         $callSQL = "";
         find_owner($rs->fields['src'], $account_id, $service_id, $product_id, $callSQL);
         $isInbound = 0;
         $calltype = 0;
         if ($bDoCallType) {
             $calltype = $this->isIntrastateCall($rs->fields['src'], $rs->fields['dst']);
         }
         #echo "Account: {$account_id} on src\n";
         if ($account_id === false) {
             find_owner($rs->fields['dst'], $account_id, $service_id, $product_id, $callSQL);
             $isInbound = 1;
             $calltype = 4;
             #echo "AccountL {$account_id} on dst\n";
         }
         if ($account_id !== false) {
             # echo "Account=$account_id Product=$product_id Service=$service_id<br />";
             # Retrieve the correct rate table
             $rt =& $this->c_load_rating_table($db, $product_id);
             if (is_resource($rt)) {
                 # Rate the call
                 $src = $isInbound ? $rs->fields['dst'] : $rs->fields['src'];
                 $dst = $isInbound ? $rs->fields['src'] : $rs->fields['dst'];
                 if ($match = agileco_search_rate_table($rt, strval($dst), intval($rs->fields['billsec']), intval($isInbound), strval($callSQL))) {
                     #echo "<pre>";
                     #echo "SRC=".$src."\n";
                     #echo "DST=".strval($dst)."\n";
                     #echo "BILLSEC=".intval($rs->fields['billsec'])."\n";
                     #echo "In Bound?=".intval($isInbound)."\n";
                     #echo "Call Type=".$calltype."\n";
                     #echo "callSQL=".$callSQL."\n\n";
                     #echo print_r($match,true);
                     #echo "\n";
                     #echo "</pre>";
                 } else {
                     #echo "SRC=".$src."\n";
                     #echo "DST=".strval($dst)."\n";
                     #echo "BILLSEC=".intval($rs->fields['billsec'])."\n";
                     #echo "In Bound?=".intval($isInbound)."\n";
                     #echo "Call Type=".$calltype."\n";
                     #echo 'Returned false.'."\n\n";
                     $match['amount'] = 0;
                     $match['quantity'] = 0;
                     $match['unit'] = 0;
                     $match['voip_rate_id'] = 0;
                 }
                 $rated = 1;
             } else {
                 echo "Product {$product_id} does not have a rating table.\n";
             }
         } else {
             $isInbound = 0;
             $account_id = 0;
             $calltype = 0;
             $rated = 3;
         }
         if (isset($match)) {
             $total += $match['amount'];
             $sql = "update " . AGILE_DB_PREFIX . "voip_cdr SET \n\t\t\t\t\taccount_id=" . $db->qstr($account_id) . ", \n\t\t\t\t\tamount=" . $db->qstr($match['amount']) . ", \n\t\t\t\t\tcalltype=" . $db->qstr($calltype) . ", \n\t\t\t\t\tvoip_rate_id=" . $db->qstr($match['voip_rate_id']) . ", \n\t\t\t\t\trated={$rated}, \n\t\t\t\t\tadjbillinterval=" . $db->qstr($match['quantity']) . ",\n\t\t\t\t\tsite_id=" . DEFAULT_SITE . "  \n\t\t\t\t\tWHERE id=" . $rs->fields['id'];
             #echo $sql."\n";
             if (!$db->Execute($sql)) {
                 echo $sql . "\n";
                 echo $db->ErrorMsg() . "\n";
             }
             $a = 'Source==' . $rs->fields['src'] . '\\r\\nDestination==' . $rs->fields['dst'];
             $a .= '\\r\\nvoip_cdr_id==' . $rs->fields['id'] . '\\r\\ndate_orig==' . $rs->fields['date_orig'];
             if (isset($match['connect_fee']) && $match['connect_fee']) {
                 $b = $a . '\\r\\nConnection Charge';
                 $cid = sqlGenID($db, "charge");
                 $sql = "INSERT INTO " . AGILE_DB_PREFIX . "charge SET\n\t\t\t\t\t\tid=" . $db->qstr($cid) . ",\n\t\t\t\t\t\tside_id=" . DEFAULT_SITE . ",\n\t\t\t\t\t\tdate_orig=." . $db->qstr($rs->fields['date_orig']) . ",\n\t\t\t\t\t\tstatus=0,\n\t\t\t\t\t\tsweep_type=6,\n\t\t\t\t\t\tproduct_id=" . $db->qstr($product_id) . ",\n\t\t\t\t\t\tservice_id=" . $db->qstr($service_id) . ",\n\t\t\t\t\t\tamount=" . $db->qstr($match['connect_fee']) . ",\n\t\t\t\t\t\tquantity=1,\n\t\t\t\t\t\ttaxable=0,\n\t\t\t\t\t\tattributes=" . $db->qstr($b);
                 if (!$db->Execute($sql)) {
                     echo $sql . "\n";
                     echo $db->ErrorMsg() . "\n";
                 }
             }
             if ($match['quantity'] > 0) {
                 $cid = sqlGenID($db, "charge");
                 $sql = "INSERT INTO " . AGILE_DB_PREFIX . "charge SET\n\t\t\t\t\tid=" . $db->qstr($cid) . ",\n\t\t\t\t\tsite_id=" . DEFAULT_SITE . ",\n\t\t\t\t\tdate_orig=" . $db->qstr($rs->fields['date_orig']) . ",\n\t\t\t\t\tstatus=0,\n\t\t\t\t\tsweep_type=6,\n\t\t\t\t\tproduct_id=" . $db->qstr($product_id) . ",\n\t\t\t\t\tservice_id=" . $db->qstr($service_id) . ",\n\t\t\t\t\tamount=" . $db->qstr($match['unit']) . ",\n\t\t\t\t\tquantity=" . $db->qstr($match['quantity']) . ",\n\t\t\t\t\ttaxable=0,\n\t\t\t\t\tattributes=" . $db->qstr($a);
                 if (!$db->Execute($sql)) {
                     echo $sql . "\n";
                     echo $db->ErrorMsg() . "\n";
                 }
             }
         }
         $i++;
         $rs->MoveNext();
     }
     $et = $this->microtime_float();
     $tt = $et - $st;
     echo "Rated {$i} entries in {$tt} seconds.<br><br>";
     echo "Cough up \$" . number_format($total, 4) . "!<br>";
 }
Example #3
0
 function invoiceItemToService($invoice_item_id, $invoice, $service_id = false)
 {
     include_once PATH_MODULES . 'product/product.inc.php';
     $product = new product();
     $trial = false;
     $db =& DB();
     # Get the invoice_item record
     $item =& $db->Execute(sqlSelect($db, "invoice_item", "*", "id = {$invoice_item_id}"));
     # Get the product details
     $prod =& $db->Execute(sqlSelect($db, "product", "*", "id = {$item->fields['product_id']}"));
     # Determine Price, Price Type, and Next Invoice Date:
     if ($item->fields['price_type'] == '2') {
         ### Item is trial for another item:
         $trial = true;
         # Determine trial length.
         $tl = $prod->fields['price_trial_length_type'];
         if ($tl == 0) {
             $this->next_invoice = time() + $prod->fields['price_trial_length'] * 86400;
         } elseif ($tl == 1) {
             $this->next_invoice = time() + $prod->fields['price_trial_length'] * 86400 * 7;
         } elseif ($tl == 2) {
             $this->next_invoice = mktime(0, 0, 0, date('m') + $prod->fields['price_trial_length'], date('d'), date('Y'));
         } else {
             $this->next_invoice = time() + 365 * 86400;
         }
         # get the details of the permanent item
         $q = "SELECT * FROM " . AGILE_DB_PREFIX . "product WHERE\n\t\t        \t  id \t\t=  " . $db->qstr($prod->fields['price_trial_prod']) . " AND\n\t\t        \t  site_id \t=  " . $db->qstr(DEFAULT_SITE);
         $prod = $db->Execute($q);
         /* set the product id to the perm item */
         $item->fields['product_id'] = $prod->fields['id'];
         $this->recurring_schedule = $item->fields['recurring_schedule'];
         ### Get the price
         $price = $product->price_prod($prod->fields, $prod->fields['price_recurr_default'], $invoice->fields['account_id'], false);
         $this->price = @$price['base'] / $item->fields['quantity'];
         $this->bind = '1';
         $item->fields['sku'] = $prod->fields['sku'];
     } elseif ($item->fields['price_type'] == '1') {
         # Recurring Item
         $this->recurring_schedule = $item->fields['recurring_schedule'];
         $this->price = $item->fields['price_base'] / $item->fields['quantity'];
         $this->bind = '1';
         # Determine the next invoice date:
         $this->next_invoice = $this->calcNextInvoiceDate($invoice->fields['due_date'], $this->recurring_schedule, $prod->fields['price_recurr_type'], $prod->fields['price_recurr_weekday'], $prod->fields['price_recurr_week']);
     } elseif ($item->fields['price_type'] == '0') {
         # One-time charge
         $this->recurring_schedule = '';
         $this->next_invoice = '';
         $this->price = $item->fields['price_base'] / $item->fields['quantity'];
         $this->bind = '0';
     } else {
         return false;
     }
     # If set-date type recurring transaction, determine full price:
     if (!$trial && $prod->fields['price_type'] == '1' && $prod->fields['price_recurr_type'] == '1') {
         # Get the base product price:
         $price = $product->price_prod($prod->fields, $this->recurring_schedule, $invoice->fields['account_id'], false);
         $this->price = $price['base'] / $item->fields['quantity'];
         # Get the price of any attributes:
         $price = $product->price_attr($prod->fields, $item->fields['product_attr_cart'], $this->recurring_schedule, $invoice->fields['account_id'], false);
         $this->price += $price['base'] / $item->fields['quantity'];
     }
     # Service settings:
     $this->active = '1';
     $this->queue = 'new';
     $this->host_ip = '';
     $this->host_username = '';
     $this->host_password = '';
     $this->domain_host_tld_id = '';
     $this->domain_host_registrar_id = '';
     $this->domain_date_expire = '';
     # Parent ID
     $this->parent_id = $service_id;
     # determine if groups defined:
     $groups_defined = false;
     if (!empty($prod->fields['assoc_grant_group'])) {
         // type > 0 or num of days defined?
         if ($prod->fields['assoc_grant_group_type'] > 0 || $prod->fields['assoc_grant_group_days'] > 0) {
             // actual groups defined?
             $grant_groups = unserialize($prod->fields['assoc_grant_group']);
             if (is_array($grant_groups) && count($grant_groups) > 0) {
                 foreach ($grant_groups as $key => $group_id) {
                     if ($group_id > 0) {
                         $groups_defined = true;
                         break;
                     }
                 }
             }
         }
         if (!$groups_defined) {
             $prod->fields['assoc_grant_group'] = false;
             $prod->fields['assoc_grant_group_type'] = false;
             $prod->fields['assoc_grant_group_days'] = false;
         }
     }
     # Determine the Service Type:
     $this->type = 'none';
     if ($item->fields['item_type'] == '0') {
         # NONE, GROUP, PRODUCT, OR PRODUCT_GROUP:
         if (!$groups_defined && empty($prod->fields['prod_plugin'])) {
             $this->type = 'none';
         } else {
             if ($groups_defined && !empty($prod->fields['prod_plugin'])) {
                 $this->type = 'product_group';
             } elseif (!empty($prod->fields['prod_plugin'])) {
                 $this->type = 'product';
             } elseif ($groups_defined) {
                 $this->type = 'group';
             }
         }
     } elseif ($item->fields['item_type'] == '1') {
         # HOSTING:
         $this->type = 'host';
         $this->host_ip = '';
         $this->host_username = '';
         $this->host_password = '';
         # Is group access also defined?
         if (!empty($prod->fields['assoc_grant_group'])) {
             $this->type = 'host_group';
         }
     } elseif ($item->fields['item_type'] == '2') {
         # DOMAIN:
         $this->type = 'domain';
         $this->domain_date_expire = time() + $item->fields['domain_term'] * (86400 * 365);
         # Get the host_tld_id
         $q = "SELECT id, registrar_plugin_id FROM " . AGILE_DB_PREFIX . "host_tld WHERE\n\t\t        \t  name \t\t=  " . $db->qstr($item->fields['domain_tld']) . " AND\n\t\t        \t  site_id \t=  " . $db->qstr(DEFAULT_SITE);
         $tld = $db->Execute($q);
         $this->domain_host_tld_id = $tld->fields['id'];
         $this->domain_host_registrar_id = $tld->fields['registrar_plugin_id'];
     }
     if ($this->type == "none" && $this->recurring_schedule == "") {
         # do not create service for one-time charge with no hosting,domain, or group settings
     } else {
         # Create the service record(s):
         for ($iii = 0; $iii < $item->fields['quantity']; $iii++) {
             $this->id = sqlGenID($db, "service");
             $fields = array('date_orig' => time(), 'date_orig' => time(), 'parent_id' => $this->parent_id, 'invoice_id' => $item->fields['invoice_id'], 'invoice_item_id' => $invoice_item_id, 'account_id' => $invoice->fields['account_id'], 'account_billing_id' => $invoice->fields['account_billing_id'], 'product_id' => $item->fields['product_id'], 'sku' => $item->fields['sku'], 'active' => $this->active, 'bind' => $this->bind, 'type' => $this->type, 'queue' => $this->queue, 'price' => $this->price, 'price_type' => $item->fields['price_type'], 'taxable' => $prod->fields['taxable'], 'date_last_invoice' => $invoice->fields['date_orig'], 'date_next_invoice' => $this->next_invoice, 'recur_schedule' => $this->recurring_schedule, 'recur_type' => $prod->fields['price_recurr_type'], 'recur_weekday' => $prod->fields['price_recurr_weekday'], 'recur_week' => $prod->fields['price_recurr_week'], 'recur_schedule_change' => $prod->fields['price_recurr_schedule'], 'recur_cancel' => $prod->fields['price_recurr_cancel'], 'recur_modify' => $prod->fields['price_recurr_modify'], 'group_grant' => $prod->fields['assoc_grant_group'], 'group_type' => $prod->fields['assoc_grant_group_type'], 'group_days' => $prod->fields['assoc_grant_group_days'], 'host_server_id' => $prod->fields['host_server_id'], 'host_provision_plugin_data' => $prod->fields['host_provision_plugin_data'], 'host_ip' => $this->host_ip, 'host_username' => $this->host_username, 'host_password' => $this->host_password, 'domain_name' => $item->fields['domain_name'], 'domain_tld' => $item->fields['domain_tld'], 'domain_term' => $item->fields['domain_term'], 'domain_type' => $item->fields['domain_type'], 'domain_date_expire' => $this->domain_date_expire, 'domain_host_tld_id' => $this->domain_host_tld_id, 'domain_host_registrar_id' => $this->domain_host_registrar_id, 'prod_attr' => $item->fields['product_attr'], 'prod_attr_cart' => $item->fields['product_attr_cart'], 'prod_plugin_name' => @$prod->fields["prod_plugin_file"], 'prod_plugin_data' => @$prod->fields["prod_plugin_data"]);
             $rs =& $db->Execute(sqlInsert($db, "service", $fields, $this->id));
             if ($rs === false) {
                 global $C_debug;
                 $C_debug->error('service.inc.php', 'invoiceItemToService', $q . " | " . @$db->ErrorMsg());
             } else {
                 # Run the queue on this item:
                 $arr['id'] = $this->id;
                 $this->queue($arr, $this);
             }
         }
     }
     # Create any discount codes:
     if ($prod->fields['discount'] == '1' && !empty($prod->fields['discount_amount'])) {
         $id = $db->GenID(AGILE_DB_PREFIX . 'discount_id');
         $q = "INSERT INTO " . AGILE_DB_PREFIX . "discount SET\n\t        \tid\t\t\t\t\t= " . $db->qstr($id) . ",\n\t        \tsite_id\t\t\t\t= " . $db->qstr(DEFAULT_SITE) . ",\n\t        \tdate_orig\t\t\t= " . $db->qstr(time()) . ",\n\t        \tdate_start\t\t\t= " . $db->qstr(time()) . ",\n\t        \tstatus\t\t\t\t= " . $db->qstr('1') . ",\n\t        \tname\t\t\t\t= " . $db->qstr('DISCOUNT-' . $id) . ",\n\t        \tnotes\t\t\t\t= " . $db->qstr('Autogenerated for Invoice Number ' . $item->fields['invoice_id'] . ', SKU ' . $item->fields['sku']) . ",\n\t        \tmax_usage_account \t= " . $db->qstr('1') . ",\n\t        \tmax_usage_global\t= " . $db->qstr('1') . ",\n\t        \tavail_account_id\t= " . $db->qstr($invoice->fields['account_id']) . ",\n\t        \tnew_status\t\t\t= " . $db->qstr('1') . ",\n\t        \tnew_type\t\t\t= " . $db->qstr('1') . ",\n\t        \tnew_rate\t\t\t= " . $db->qstr($prod->fields['discount_amount']) . ",\n\t        \trecurr_status\t\t= " . $db->qstr('1') . ",\n\t        \trecurr_type\t\t\t= " . $db->qstr('1') . ",\n\t        \trecurr_rate\t\t\t= " . $db->qstr($prod->fields['discount_amount']);
         $db->Execute($q);
     }
     return true;
 }
Example #4
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;
 }
Example #5
0
function sqlInsert(&$db, $table, $fields, $id = false)
{
    if (!$id) {
        $id = sqlGenID($db, $table);
    }
    $fields['id'] = $id;
    if (empty($fields['site_id'])) {
        $fields['site_id'] = DEFAULT_SITE;
    }
    $tab = AGILE_DB_PREFIX . '' . $table;
    return $db->GetInsertSQL($tab, $fields, get_magic_quotes_gpc());
}
Example #6
0
 /**
  * Commit current discounts to the database (call after creating an invoice_item record)
  */
 function invoice_item($invoice_id, $invoice_item_id, $account_id, $discount_arr = false)
 {
     if ($discount_arr && is_array($discount_arr)) {
         $this->discount_arr = $discount_arr;
     }
     if (is_array($this->discount_arr)) {
         $db =& DB();
         foreach ($this->discount_arr as $dsc) {
             $sql = "INSERT INTO " . AGILE_DB_PREFIX . "invoice_item_discount SET id=" . sqlGenID($db, "invoice_item_discount") . ", site_id=" . DEFAULT_SITE . ", invoice_id={$invoice_id}, account_id={$account_id}, invoice_item_id={$invoice_item_id}, discount=" . $db->qstr($dsc["discount"]) . ", amount=" . $db->qstr($dsc["amount"]);
             $db->Execute($sql);
         }
     }
 }
Example #7
0
    function upgrade($VAR)
    {
        if (!isset($VAR['module_name']) || !isset($VAR['module_group'])) {
            echo "You must select both the module(s) to upgrade and the groups to grant access to new methods to.";
            return;
        }
        $module_count = 0;
        $method_count = 0;
        $fields_count = 0;
        $method_new_count = 0;
        $fields_new_count = 0;
        # loop through each module
        $modules = $VAR['module_name'];
        for ($i = 0; $i < count($modules); $i++) {
            # increment module count
            $module_count++;
            # get the module details
            $db =& DB();
            $db_module = $db->Execute(sqlSelect($db, "module", "*", "id=::{$modules[$i]}:: or name=::{$modules[$i]}::"));
            $module_name = $db_module->fields['name'];
            $module_id = $db_module->fields['id'];
            #########################################################################
            # Update the Methods from the <module>_install.xml file
            # get the install xml file
            #########################################################################
            $install_xml = PATH_MODULES . $module_name . '/' . $module_name . '_install.xml';
            if (is_file($install_xml)) {
                $C_xml = new CORE_xml();
                @($methods = $C_xml->xml_to_array($install_xml));
                @($methods = $methods['install']['sql_inserts']['module_method']);
                # loop through the methods
                if (is_array($methods)) {
                    while (list($key, $value) = each($methods)) {
                        # increment method count
                        $method_count++;
                        # see if this method exists
                        $sql = 'SELECT * FROM ' . AGILE_DB_PREFIX . 'module_method WHERE
								   name         =  ' . $db->qstr($key) . ' AND
								   module_id    =  ' . $db->qstr($module_id) . ' AND
								   site_id      =  ' . $db->qstr(DEFAULT_SITE);
                        $method_db = $db->Execute($sql);
                        if ($method_db === false) {
                            global $C_debug;
                            $C_debug->error('module.inc.php', 'upgrade', $db->ErrorMsg());
                        }
                        if ($method_db->RecordCount() == 0) {
                            # increment method count
                            $method_new_count++;
                            ### add this method
                            @($notes = $methods[$key]["notes"]);
                            @($page = $methods[$key]["page"]);
                            @($menu_display = $methods[$key]["menu_display"]);
                            $method_id = sqlGenID($db, 'module_method');
                            $fields = array('name' => $key, 'module_id' => $module_id, 'notes' => $notes, 'page' => $page, 'menu_display' => $menu_display);
                            $db->Execute(sqlInsert($db, "module_method", $fields, $method_id));
                            if ($result === false) {
                                global $C_debug;
                                $C_debug->error('module.inc.php', 'upgrade', $db->ErrorMsg());
                            }
                            ### Create the group_method records, with the ID from each
                            for ($ii = 0; $ii < count($VAR["module_group"]); $ii++) {
                                $group_method_id = $db->GenID(AGILE_DB_PREFIX . "" . 'group_method_id');
                                $q = 'INSERT INTO ' . AGILE_DB_PREFIX . 'group_method SET
									  id        = ' . $db->qstr($group_method_id) . ',
									  site_id   = ' . $db->qstr(DEFAULT_SITE) . ',
									  method_id = ' . $db->qstr($method_id) . ',
									  module_id = ' . $db->qstr($module_id) . ',
									  group_id  = ' . $db->qstr($VAR["module_group"][$ii]);
                                $result = $db->Execute($q);
                                if ($result === false) {
                                    global $C_debug;
                                    $C_debug->error('module.inc.php', 'upgrade', $db->ErrorMsg());
                                }
                            }
                        }
                    }
                }
            }
            #########################################################################
            # Update the DB Fields from the <module>_construct.xml file
            # get the install xml file
            #########################################################################
            $construct_xml = PATH_MODULES . $module_name . '/' . $module_name . '_construct.xml';
            if (is_file($construct_xml)) {
                $C_xml = new CORE_xml();
                $construct = $C_xml->xml_to_array($construct_xml);
                @($fields = $construct['construct']['field']);
                ### Check that this Module has any db installation required...
                if (!empty($construct["construct"]["table"]) && $construct["construct"]["table"] == $module_name) {
                    ### Create the module DB table
                    $table = $construct["construct"]["table"];
                    $db =& DB();
                    $db_fields = $db->MetaColumns(AGILE_DB_PREFIX . $table, true);
                    ### Create the module DB fields
                    $arr_field = $construct["construct"]["field"];
                    ### Loop through the fields to build the list:
                    while (list($key, $value) = each($arr_field)) {
                        $field = $key;
                        $FIELD = strtoupper($key);
                        if (!isset($db_fields[$FIELD])) {
                            # increment field count
                            $fields_new_count++;
                            $t_s = $arr_field["{$key}"]["type"];
                            if (ereg('[(]', $t_s)) {
                                $ts = split('[(]', $t_s);
                                $type = $ts[0];
                                $size = ereg_replace(')', '', $ts[1]);
                                $flds[] = array($field, $type, $size);
                            } else {
                                $flds[] = array($field, $t_s);
                            }
                        }
                    }
                    ### Add any new columns:
                    if (is_array(@$flds)) {
                        $dict = NewDataDictionary($db);
                        $sqlarray = $dict->AddColumnSQL(AGILE_DB_PREFIX . $table, $flds);
                        $result = $db->Execute($sqlarray[0]);
                        if ($result === false) {
                            global $C_debug;
                            $C_debug->error('module.inc.php', 'install_db', $db->ErrorMsg());
                            echo $db->ErrorMsg();
                        }
                        unset($flds);
                    }
                    ### Remove any unused columns
                    while (list($key, $value) = each($db_fields)) {
                        $fieldname = strtolower($key);
                        if (!isset($construct["construct"]["field"][$fieldname])) {
                            $flds[] = $key;
                        }
                    }
                    if (is_array(@$flds)) {
                        $dict = NewDataDictionary($db);
                        $sqlarray = $dict->DropColumnSQL(AGILE_DB_PREFIX . $table, $flds);
                        $sqlarray[0];
                        $result = $db->Execute($sqlarray[0]);
                        if ($result === false) {
                            global $C_debug;
                            $C_debug->error('module.inc.php', 'install_db', $db->ErrorMsg());
                            echo $db->ErrorMsg();
                        }
                        unset($flds);
                    }
                    ####################################################
                    ### Update Indexes:
                    # Get old database indexes
                    $dict = NewDataDictionary($db);
                    $oldindex = $dict->MetaIndexes(AGILE_DB_PREFIX . $table);
                    # check if the 'site_id' index exists:
                    if (!empty($oldindex['site_id']) && ($oldindex['site_id'] = 'id,site_id')) {
                        $dict = NewDataDictionary($db);
                        $sqlarray = $dict->DropIndexSQL('site_id', AGILE_DB_PREFIX . $table);
                        $db->Execute($sqlarray[0]);
                    }
                    # check that that UNIQUE index for site_id,id exists
                    if (empty($oldindex['IDS']) || $oldindex['IDS']['unique'] != 1) {
                        $db =& DB();
                        $db->Execute("alter table " . AGILE_DB_PREFIX . "{$table} drop primary key");
                        $db->Execute("CREATE UNIQUE INDEX IDS on " . AGILE_DB_PREFIX . "{$table} (site_id, id)");
                    }
                    $dict = NewDataDictionary($db);
                    $oldindex = $dict->MetaIndexes(AGILE_DB_PREFIX . $table);
                    # Current construct invoices
                    if (@($new_indexes = $construct["construct"]["index"])) {
                        while (list($index, $fields) = each($new_indexes)) {
                            if (is_array(@$oldindex[$index])) {
                                # already exists - compare fields:
                                $oldfields = implode(",", $oldindex[$index]['columns']);
                                if ($oldfields != $fields) {
                                    # index changed - drop:
                                    $dict = NewDataDictionary($db);
                                    $sqlarray = $dict->DropIndexSQL($index, AGILE_DB_PREFIX . $table);
                                    $db->Execute($sqlarray[0]);
                                    # create index
                                    $dict = NewDataDictionary($db);
                                    if (eregi("fulltext", $index) && AGILE_DB_TYPE == 'mysql') {
                                        $sqlarray = $dict->CreateIndexSQL($index, AGILE_DB_PREFIX . $table, $fields, array('FULLTEXT'));
                                    } else {
                                        $sqlarray = $dict->CreateIndexSQL($index, AGILE_DB_PREFIX . $table, $fields);
                                    }
                                    $db->Execute($sqlarray[0]);
                                }
                            } else {
                                # index does not exist - create!
                                $dict = NewDataDictionary($db);
                                if (eregi("fulltext", $index) && AGILE_DB_TYPE == 'mysql') {
                                    $sqlarray = $dict->CreateIndexSQL($index, AGILE_DB_PREFIX . $table, $fields, array('FULLTEXT'));
                                } else {
                                    $sqlarray = $dict->CreateIndexSQL($index, AGILE_DB_PREFIX . $table, $fields);
                                }
                                $db->Execute($sqlarray[0]);
                            }
                            $verify_index[] = $index;
                        }
                        # Check for removed indexes:
                        if (!empty($oldindex)) {
                            reset($oldindex);
                            while (list($index, $fields) = each($oldindex)) {
                                if (!isset($new_indexes[$index]) && $index != 'IDS') {
                                    $dict = NewDataDictionary($db);
                                    $sqlarray = $dict->DropIndexSQL($index, AGILE_DB_PREFIX . $table);
                                    $db->Execute($sqlarray[0]);
                                }
                            }
                        }
                    } else {
                        # remove all old indexes
                        if (!empty($oldindex)) {
                            reset($oldindex);
                            while (list($index, $fields) = each($oldindex)) {
                                if ($index != 'IDS') {
                                    $dict = NewDataDictionary($db);
                                    $sqlarray = $dict->DropIndexSQL($index, AGILE_DB_PREFIX . $table);
                                    $db->Execute($sqlarray[0]);
                                }
                            }
                        }
                    }
                }
            }
        }
        $msg = "Successfully checked {$module_count} module(s), {$method_count} method(s), " . "and {$fields_count} db fields. <BR>" . "Added {$method_new_count} method(s) and {$fields_new_count} db field(s).";
        if (!empty($fields_new_count) > 0) {
            $js = '<script language="javascript">document.getElementById("module_add").submit();</script>';
            global $smarty;
            if (is_object($smarty)) {
                $smarty->assign('js', $js);
            } else {
                echo '<script language="javascript">document.refresh();</script>';
            }
        }
        # Display the message.
        global $C_debug;
        if (is_object($C_debug)) {
            $C_debug->alert($msg);
        } else {
            echo $msg;
        }
        # update the current user's authentication so the update group access applies
        # to them
        global $C_auth;
        if (is_object($C_auth)) {
            $C_auth->auth_update();
        }
    }
Example #8
0
 /**
  * Add a radius entry
  */
 function add_radius($service_id, $radius_service_id, $username, $password = false)
 {
     // determine type of auth
     if (!$password) {
         $auth = 'wireless';
     } else {
         $auth = 'login';
     }
     // get the associated service
     $db =& DB();
     $rs = $db->Execute(sqlSelect($db, "service", "*", "id=::{$service_id}::"));
     if (!$rs || !$rs->RecordCount()) {
         return false;
     }
     $f['service_id'] = $service_id;
     $f['username'] = $username;
     $f['password'] = $password;
     $f['account_id'] = $rs->fields['account_id'];
     $f['sku'] = $rs->fields['sku'];
     $f['active'] = 1;
     // insert radius record
     $arr = unserialize($rs->fields['prod_plugin_data']);
     foreach ($arr as $a => $b) {
         if ($a != 'max') {
             $f[$a] = $b;
         }
     }
     $id = sqlGenID($db, "radius");
     $db->Execute($sql = sqlInsert($db, "radius", $f, $id));
     // update radius_service table
     $db->Execute(sqlUpdate($db, "radius_service", array('radius_id' => $id), "id = {$radius_service_id}"));
     return true;
 }
 function invoices()
 {
     global $VAR, $C_debug;
     $p = AGILE_DB_PREFIX;
     $s = DEFAULT_SITE;
     ### Connect to the remote Db;
     $dbr =& NewADOConnection($this->type);
     $dbr->Connect($this->host, $this->user, $this->pass, $this->db);
     ### Determine the offset for the account
     if (empty($VAR['offset'])) {
         $VAR['offset'] = 0;
     }
     @($offset = $VAR['offset'] . "," . $this->select_limit);
     # select each invoice
     $sql = "SELECT * FROM invoice";
     $rs = $dbr->SelectLimit($sql, $offset);
     if ($rs === false) {
         $C_debug->alert("Query to the table 'invoice' failed!");
         return false;
     }
     $db =& DB();
     ### Get the default checkout plugin id:
     $sql = "SELECT id FROM {$p}checkout WHERE\n\t\t\t\tsite_id = {$s} AND\n\t\t\t\tcheckout_plugin = '{$this->gateway}'";
     $ch = $db->Execute($sql);
     $checkout_plugin_id = $ch->fields['id'];
     ### Get the server
     $sql = "SELECT id FROM {$p}host_server WHERE site_id = {$s} AND  name = 'WHM'";
     $rshost = $db->Execute($sql);
     $host_server_id = $rshost->fields['id'];
     if ($rs->RecordCount() == 0) {
         $C_debug->alert("No more records to process!");
         echo "<script language=javascript>setTimeout('document.location=\\'?_page=import:import&plugin={$VAR['plugin']}\\'', 1500); </script>";
         return;
     }
     $msg = "Processing " . $rs->RecordCount() . " Records...<BR>";
     # loop through each remote account
     while (!$rs->EOF) {
         # get the process & billing status
         $process_status = 0;
         $billing_status = 0;
         $billed_amt = 0;
         # get the account id
         $p = AGILE_DB_PREFIX;
         $dbn =& DB();
         $sql = "SELECT ab_id FROM {$p}import WHERE site_id = 1 AND\n\t\t\t\t\t\tab_table = 'account' AND\n\t\t\t\t\t\tplugin = '{$this->plugin}' AND\n\t\t\t\t\t\tremote_id = '{$rs->fields['uid']}'";
         $account = $dbn->Execute($sql);
         if ($account && $account->RecordCount()) {
             $msg .= "<BR>Processing Invoice: {$rs->fields['iid']}...";
             $account_id = $account->fields['ab_id'];
             # get the billing id
             $dba =& DB();
             $sql = "SELECT id FROM {$p}account_billing WHERE site_id = {$s} AND account_id = {$account_id}";
             $billing = $dba->Execute($sql);
             $billing_id = $billing->fields['id'];
             if ($rs->fields['status'] != 1) {
                 $billed_amt = 0;
             } else {
                 $billed_amt = $rs->fields['total_due_today'];
             }
             if ($rs->fields['due_date'] > 1) {
                 $due_date = $rs->fields['due_date'];
             } else {
                 $due_date = $rs->fields['created'];
             }
             # Get a local id
             $id = $db->GenID($p . 'invoice_id');
             $invoice_id = $id;
             # Insert the record
             $sql = "INSERT INTO {$p}invoice SET\n\t\t\t\t\t\tid \t\t\t\t\t= {$id},\n\t\t\t\t\t\tsite_id\t\t\t\t= 1, \n\t\t\t\t\t\tdate_orig\t\t\t= " . $db->qstr($rs->fields['created']) . ",\n\t\t\t\t\t\tdate_last\t\t\t= " . $db->qstr(time()) . ", \n\t\t\t\t\t\t\n\t\t\t\t\t\tprocess_status\t\t= " . $db->qstr($rs->fields['status']) . ",\n\t\t\t\t\t\tbilling_status\t\t= " . $db->qstr($rs->fields['status']) . ",\n\t\t\t\t\t\t\n\t\t\t\t\t\taccount_id\t\t\t= " . $db->qstr(@$account_id) . ",\n\t\t\t\t\t\taccount_billing_id \t= " . $db->qstr(@$billing_id) . ", \n\t\t\t\t\t\tcheckout_plugin_id \t= " . $db->qstr(@$checkout_plugin_id) . ", \n\t\t\t\t\t\t\n\t\t\t\t\t\ttax_amt\t\t\t\t= " . $db->qstr(@$rs->fields['charge_tax']) . ", \n\t\t\t\t\t\ttotal_amt\t\t\t= " . $db->qstr(@$rs->fields['total_due_today']) . ",\n\t\t\t\t\t\tbilled_amt\t\t\t= " . $db->qstr(@$billed_amt) . ",\n\t\t\t\t\t\tbilled_currency_id \t= " . $db->qstr(DEFAULT_CURRENCY) . ",\n\t\t\t\t\t\tactual_billed_amt \t= " . $db->qstr(@$billed_amt) . ",\n\t\t\t\t\t\tactual_billed_currency_id = " . $db->qstr(DEFAULT_CURRENCY) . ",\n\t\t\t\t\t\t\n\t\t\t\t\t\tnotice_count\t\t= 0,\n\t\t\t\t\t\tnotice_max \t\t\t= 1,\n\t\t\t\t\t\tnotice_next_date\t= " . $db->qstr(time()) . ",\n\t\t\t\t\t\tgrace_period\t\t= 7,\n\t\t\t\t\t\tdue_date \t\t\t= " . $db->qstr($due_date);
             $db->Execute($sql);
             # Insert the import record
             $this->import_transaction($this->plugin, $VAR['action'], 'invoice', $id, 'order_list', $rs->fields['iid'], &$db);
             ### Get / Insert Invoice Items:
             $dbr =& NewADOConnection($this->type);
             $dbr->Connect($this->host, $this->user, $this->pass, $this->db);
             $sql = "SELECT * FROM hosting_order WHERE oid = " . $dbr->qstr($rs->fields['oid']);
             $rs2 = $dbr->Execute($sql);
             if ($rs2 === false) {
                 $C_debug->alert("Query to the table 'hosting_order' failed!");
                 return false;
             }
             while (!$rs2->EOF) {
                 # Determine the domain type (DOMAIN-REGISTER or DOMAIN-TRANSFER or DOMAIN-PARK)
                 if (!empty($rs2->fields['domain_registration'])) {
                     $sku = 'DOMAIN-REGISTER';
                     $domain_type = 'register';
                 } else {
                     $sku = "DOMAIN-TRANSFER";
                     $domain_type = 'ns_transfer';
                 }
                 $domain_sku = $sku;
                 $domain = preg_replace("/^www\\./", "", $rs2->fields['domain_name']);
                 $parking = preg_replace("/(\\.)([a-zA-Z0-9.-]+)/", $domain, $ret);
                 $tld = preg_replace("/^\\./", "", $ret[0]);
                 $domain = preg_replace(",{$tld}\$,", "", $domain);
                 $domain = preg_replace("/\\./", "", $domain);
                 $domain_host_tld_id = 0;
                 $tldrs = $db->Execute(sqlSelect($db, "host_tld", "id", "name='{$tld}'"));
                 if ($tldrs && $tldrs->recordCount) {
                     $domain_host_tld_id = $tldrs->fields['id'];
                 }
                 // get product details
                 $pid = $rs2->fields['pid'];
                 $sql = "SELECT ab_id FROM {$p}import WHERE site_id = {$s} AND\n\t\t\t\t\t\t\t\tab_table = 'product' AND\n\t\t\t\t\t\t\t\tplugin = '{$this->plugin}' AND\n\t\t\t\t\t\t\t\tremote_id = '{$pid}'";
                 $produrs = $dba->Execute($sql);
                 if ($produrs && $produrs->RecordCount() && !empty($product_id)) {
                     $product_id = $produrs->fields['ab_id'];
                     $product = $db->Execute(sqlSelect($db, "product", "*", "id={$product_id}"));
                     if ($product && $product->RecordCount()) {
                         $sku = $product->fields['sku'];
                     }
                 }
                 // insert invoice item
                 $dbo =& DB();
                 $idx = sqlGenID($dbo, "invoice_item");
                 $sql = "INSERT INTO {$p}invoice_item SET\n\t\t\t\t\t\t\t\tid \t\t\t\t\t= {$idx},\n\t\t\t\t\t\t\t\tsite_id\t\t\t\t= 1,  \n\t\t\t\t\t\t\t\tparent_id\t\t\t= 0,\n\t\t\t\t\t\t\t\tinvoice_id\t\t\t= " . $db->qstr(@$invoice_id) . ", \n\t\t\t\t\t\t\t\tproduct_id\t\t\t= " . $db->qstr(@$product_id) . ",\n\t\t\t\t\t\t\t\tdate_orig\t\t\t= " . $db->qstr($rs->fields['created']) . ",  \n\t\t\t\t\t\t\t\tsku\t\t\t\t\t= " . $db->qstr($sku) . ",\n\t\t\t\t\t\t\t\tquantity\t\t\t= 1,\n\t\t\t\t\t\t\t\titem_type\t\t\t= 1,  \n\t\t\t\t\t\t\t\tprice_type\t\t\t= 1,\n\t\t\t\t\t\t\t\tprice_base\t\t\t= " . $db->qstr($rs->fields['total_due_today']) . ", \n\t\t\t\t\t\t\t\tdomain_name \t\t= " . $db->qstr($domain) . ", \n\t\t\t\t\t\t\t\tdomain_tld  \t\t= " . $db->qstr($tld);
                 $dbo->Execute($sql);
                 # Insert the import record
                 $this->import_transaction($this->plugin, $VAR['action'], 'invoice_item', $idx, 'hosting_order', $rs2->fields['oid'], &$db);
                 // SERVICE: insert domain record
                 if ($rs->fields['status'] == 1 && empty($rs2->fields['domain_registration'])) {
                     if (!empty($rs2->fields['domain_expire'])) {
                         $d = explode("/", $rs2->fields['domain_expire']);
                         @($anniversary_date = mktime(0, 0, 0, $d[0], $d[1], $d[2]));
                     } else {
                         $anniversary_date = $rs2->fields['ogcreate'] + 86400 * 1;
                     }
                     $dby =& DB();
                     $s_id = sqlGenID($dby, "service");
                     $sql = "INSERT INTO {$p}service SET\n\t\t\t\t\t\t\t\tid \t\t\t\t\t= {$s_id},\n\t\t\t\t\t\t\t\tsite_id\t\t\t\t= 1, \n\t\t\t\t\t\t\t\tqueue\t\t\t\t= 'none',\n\t\t\t\t\t\t\t\tdate_orig\t\t\t= " . $db->qstr($rs->fields['created']) . ",\n\t\t\t\t\t\t\t\tdate_last\t\t\t= " . $db->qstr(time()) . ",  \n\t\t\t\t\t\t\t\tinvoice_id\t\t\t= " . $db->qstr(@$invoice_id) . ", \n\t\t\t\t\t\t\t\taccount_id\t\t\t= " . $db->qstr(@$account_id) . ",\n\t\t\t\t\t\t\t\taccount_billing_id\t= " . $db->qstr(@$billing_id) . ", \n\t\t\t\t\t\t\t\tsku\t\t\t\t\t= " . $db->qstr($domain_sku) . ", \n\t\t\t\t\t\t\t\ttype\t\t\t\t= " . $db->qstr('domain') . ", \n\t\t\t\t\t\t\t\tactive\t\t\t\t= 1,  \n\t\t\t\t\t\t\t\tprice\t\t\t\t= " . $db->qstr($rs->fields['total_due_today']) . ",\n\t\t\t\t\t\t\t\tprice_type\t\t\t= " . $db->qstr('0') . ",\n\t\t\t\t\t\t\t\ttaxable\t\t\t\t= " . $db->qstr('0') . ",\n\t\t\t\t\t\t\t\t \n\t\t\t\t\t\t\t\tdomain_date_expire\t= " . $db->qstr($anniversary_date) . ",\n\t\t\t\t\t\t\t\tdomain_host_tld_id\t= " . $db->qstr($domain_host_tld_id) . ",\n\t\t\t\t\t\t\t\tdomain_host_registrar_id = 1,\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\tdomain_name \t\t= " . $db->qstr($domain) . ",\n\t\t\t\t\t\t\t\tdomain_term\t\t  \t= " . $db->qstr(1) . ",\n\t\t\t\t\t\t\t\tdomain_tld  \t\t= " . $db->qstr($tld) . ",\n\t\t\t\t\t\t\t\tdomain_type\t\t\t= " . $db->qstr($domain_type);
                     $dby->Execute($sql);
                     # Insert the import record
                     $this->import_transaction($this->plugin, $VAR['action'], 'service', $s_id, 'hosting_order', $rs2->fields['oid'], &$db);
                 }
                 //	SERVICE: Insert hosting record
                 if ($rs->fields['status'] == 1) {
                     $recur_schedule = 1;
                     switch ($rs2->fields['payment_term']) {
                         case "Monthly":
                             $recur_schedule = 1;
                             break;
                         case "Quarterly":
                             $recur_schedule = 2;
                             break;
                         case "Semi-Annual":
                             $recur_schedule = 3;
                             break;
                         case "Annual":
                             $recur_schedule = 4;
                             break;
                     }
                     $dbx =& DB();
                     $s2_id = sqlGenID($dbx, "service");
                     $sql = "INSERT INTO {$p}service SET\n\t\t\t\t\t\t\t\t\tid \t\t\t\t\t= {$s2_id},\n\t\t\t\t\t\t\t\t\tsite_id\t\t\t\t= 1, \n\t\t\t\t\t\t\t\t\tqueue\t\t\t\t= 'active',\n\t\t\t\t\t\t\t\t\tdate_orig\t\t\t= " . $db->qstr($rs->fields['created']) . ",\n\t\t\t\t\t\t\t\t\tdate_last\t\t\t= " . $db->qstr(time()) . ",  \n\t\t\t\t\t\t\t\t\tinvoice_id\t\t\t= " . $db->qstr(@$invoice_id) . ", \n\t\t\t\t\t\t\t\t\taccount_id\t\t\t= " . $db->qstr(@$account_id) . ",\n\t\t\t\t\t\t\t\t\taccount_billing_id\t= " . $db->qstr(@$billing_id) . ",\n\t\t\t\t\t\t\t\t\tproduct_id\t\t\t= " . $db->qstr(@$product_id) . ", \n\t\t\t\t\t\t\t\t\tsku\t\t\t\t\t= " . $db->qstr('HOSTING') . ",  \n\t\t\t\t\t\t\t\t\ttype\t\t\t\t= " . $db->qstr('host') . ", \n\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\tactive\t\t\t\t= 1, \n\t\t\t\t\t\t\t\t\tsuspend_billing\t\t= 0, \n\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\tdate_last_invoice\t= " . $db->qstr($rs->fields['created']) . ",\n\t\t\t\t\t\t\t\t\tdate_next_invoice\t= " . $db->qstr($rs2->fields['next_due_date']) . ",\n\t\t\t\t\t\t\t\t\t \n\t\t\t\t\t\t\t\t\tprice\t\t\t\t= " . $db->qstr($rs2->fields['total_due_reoccur']) . ",\n\t\t\t\t\t\t\t\t\tprice_type\t\t\t= 1,\n\t\t\t\t\t\t\t\t\ttaxable\t\t\t\t= 1,\t\n\t\t\t\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\trecur_type\t\t\t= " . $db->qstr(@$product->fields['price_recurr_type']) . ",\n\t\t\t\t\t\t\t\t\trecur_schedule\t\t= " . $db->qstr($recur_schedule) . ",\n\t\t\t\t\t\t\t\t\trecur_weekday\t\t= " . $db->qstr(@$product->fields['price_recurr_weekday']) . ",\n\t\t\t\t\t\t\t\t\trecur_week\t\t\t= " . $db->qstr(@$product->fields['price_recurr_week']) . ",\n\t\t\t\t\t\t\t\t\trecur_cancel\t\t= " . $db->qstr(@$product->fields['price_recurr_cancel']) . ",\n\t\t\t\t\t\t\t\t\trecur_schedule_change = " . $db->qstr(@$product->fields['price_recurr_modify']) . ",\n\t\t\t\n\t\t\t\t\t\t\t\t\thost_username\t\t= " . $db->qstr($rs2->fields['whm_username']) . ",\n\t\t\t\t\t\t\t\t\thost_password\t\t= " . $db->qstr($rs2->fields['whm_password']) . ",\n\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\thost_server_id\t\t\t= " . $db->qstr(@$product->fields['host_server_id']) . ",\n\t\t\t\t\t\t\t\t\thost_provision_plugin_data \t= " . $db->qstr(@$product->fields['host_provision_plugin_data']) . ",\n\t\t\t\t\t\t\t\t\thost_ip\t\t\t\t\t= " . $db->qstr($rs2->fields['ip']) . ",\n\t\t\t\t\t\t\t\t\t \n\t\t\t\t\t\t\t\t\tdomain_host_tld_id\t\t= " . $db->qstr($domain_host_tld_id) . ",\n\t\t\t\t\t\t\t\t\tdomain_host_registrar_id = 1,\n\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\tdomain_name \t\t\t= " . $db->qstr($domain) . ", \n\t\t\t\t\t\t\t\t\tdomain_tld  \t\t\t= " . $db->qstr($tld);
                     $dbx->Execute($sql);
                     # Insert the import record
                     $this->import_transaction($this->plugin, $VAR['action'], 'service', $s2_id, 'hosting_order', $rs2->fields['oid'], &$db);
                 }
                 $rs2->MoveNext();
             }
         } else {
             echo "<BR><BR> No Account: <BR> {$sql}";
         }
         $rs->MoveNext();
     }
     $C_debug->alert($msg);
     $offset = $VAR['offset'] + $this->select_limit;
     echo "<script language=javascript> \n\t\t\t  setTimeout('document.location=\\'?_page=core:blank&offset={$offset}&action={$VAR['action']}&plugin={$VAR['plugin']}&do[]=import:do_action\\'', 1200);\n\t\t\t </script>";
 }
Example #10
0
 /**
  * Add a product to the cart 
  */
 function product_add_host($VAR)
 {
     if (!empty($VAR["attr"])) {
         @($attr = serialize($VAR["attr"]));
     } else {
         $attr = serialize(array(""));
     }
     $db =& DB();
     $fields = array('date_orig' => time(), 'session_id' => $this->session_id, 'account_id' => @$VAR['account_id'], 'product_attr' => $attr, 'cart_type' => 1, 'quantity' => 1, 'product_id' => $VAR["product_id"], 'recurr_schedule' => @$VAR["recurr_schedule"], 'service_id' => @$VAR["service_id"], 'host_type' => $VAR["domain_type"], 'domain_name' => $VAR["domain_name"], 'domain_tld' => $VAR["domain_tld"]);
     $id = sqlGenID($db, "cart");
     $db->Execute(sqlInsert($db, "cart", $fields, $id));
     // Get the default domain registration length:
     if ($VAR["domain_type"] == "transfer" || $VAR["domain_type"] == "register") {
         $domain_term = 1;
         $result = $db->Execute(sqlSelect($db, "host_tld", "default_term_new", "name=::{$VAR["domain_tld"]}::"));
         if (!empty($result->fields["default_term_new"])) {
             $domain_term = $result->fields["default_term_new"];
         }
     }
     // add child domain if register or transfer
     if ($VAR["domain_type"] == "transfer" || $VAR['domain_type'] == "register") {
         $fields = array('date_orig' => time(), 'session_id' => $this->session_id, 'account_id' => @$VAR['account_id'], 'product_attr' => $attr, 'cart_type' => 2, 'quantity' => 1, 'host_type' => $VAR["domain_type"], 'domain_name' => $VAR["domain_name"], 'domain_tld' => $VAR["domain_tld"], 'domain_term' => $domain_term, 'cart_parent_id' => $id);
         $db->Execute(sqlInsert($db, "cart", $fields));
     }
 }
Example #11
0
 /**
  * Preview checkout of multiple invoices
  */
 function checkout_multiple_preview($VAR)
 {
     global $smarty, $C_list;
     if (!SESS_LOGGED) {
         return false;
     }
     $db =& DB();
     $total = $this->multiple_invoice_total(@$VAR['id'], SESS_ACCOUNT);
     if ($total > 0 && count($this->invoice) > 1) {
         // get country id for checkout options
         $account = sqlSelect($db, "account", "country_id", "id=" . SESS_ACCOUNT);
         // get payment options
         include_once PATH_MODULES . 'checkout/checkout.inc.php';
         $checkout = new checkout();
         $checkoutoptions = $checkout->get_checkout_options(SESS_ACCOUNT, $total, false, $account->fields['country_id'], true);
         // get a temporary id (48 hours)
         $id = sqlGenID($db, "temporary_data");
         $invoice["id"] = "MULTI-{$id}";
         $invoice["total"] = $total;
         $fields = array('date_orig' => time(), 'date_expire' => time() + 86400 * 3, 'field2' => $invoice['id'], 'field1' => $total, 'data' => serialize($this->invoice));
         $id =& $db->Execute(sqlInsert($db, "temporary_data", $fields));
         $smarty->assign('invoice', $invoice);
         $smarty->assign('total', $C_list->format_currency_num($total, SESS_CURRENCY));
         $smarty->assign('checkoutoptions', $checkoutoptions);
     } elseif (count($this->invoice) == 1) {
         $id = $this->invoice[0];
         echo "<script language=javascript>document.location.href='?_page=invoice:user_view&id=" . $id . "';</script>";
     } else {
         echo "No due invoices selected for payment.";
     }
 }
Example #12
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;
 }