Ejemplo n.º 1
0
 function add($VAR)
 {
     $this->construct();
     global $C_debug, $C_translate;
     $validate = true;
     ## Set type:
     if (!empty($VAR['service_none'])) {
         $VAR['service_type'] = 'none';
     } elseif (!empty($VAR['service_domain'])) {
         $VAR['service_type'] = 'domain';
     } elseif (!empty($VAR['service_group'])) {
         if (!empty($VAR['service_hosting'])) {
             $VAR['service_type'] = 'host_group';
         } elseif (!empty($VAR['service_product'])) {
             $VAR['service_type'] = 'product_group';
         } else {
             $VAR['service_type'] = 'group';
         }
     } elseif (!empty($VAR['service_hosting'])) {
         $VAR['service_type'] = 'host';
     } elseif (!empty($VAR['service_product'])) {
         $VAR['service_type'] = 'product';
     }
     ## Set Price Type
     if (!empty($VAR['billing_type'])) {
         $VAR['service_price_type'] = "1";
     } else {
         $VAR['service_price_type'] = "0";
     }
     ### loop through the field list to validate the required fields
     $type = 'add';
     $this->method["{$type}"] = explode(",", $this->method["{$type}"]);
     $arr = $this->method["{$type}"];
     include_once PATH_CORE . 'validate.inc.php';
     $validate = new CORE_validate();
     $this->validated = true;
     while (list($key, $value) = each($arr)) {
         # get the field value
         $field_var = $this->module . '_' . $value;
         $field_name = $value;
         # check if this value is unique
         if (isset($this->field["{$value}"]["unique"]) && isset($VAR["{$field_var}"])) {
             if (!$validate->validate_unique($this->table, $field_name, "record_id", $VAR["{$field_var}"])) {
                 $this->validated = false;
                 $this->val_error[] = array('field' => $this->table . '_' . $field_name, 'field_trans' => $C_translate->translate('field_' . $field_name, $this->module, ""), 'error' => $C_translate->translate('validate_unique', "", ""));
             }
         }
         if (isset($this->field["{$value}"]["validate"])) {
             if (isset($VAR["{$field_var}"])) {
                 if ($VAR["{$field_var}"] != '') {
                     if (!$validate->validate($field_name, $this->field["{$value}"], $VAR["{$field_var}"], $this->field["{$value}"]["validate"])) {
                         $this->validated = false;
                         $this->val_error[] = array('field' => $this->module . '_' . $field_name, 'field_trans' => $C_translate->translate('field_' . $field_name, $this->module, ""), 'error' => $validate->error["{$field_name}"]);
                     }
                 } else {
                     $this->validated = false;
                     $this->val_error[] = array('field' => $this->module . '_' . $field_name, 'field_trans' => $C_translate->translate('field_' . $field_name, $this->module, ""), 'error' => $C_translate->translate('validate_any', "", ""));
                 }
             } else {
                 $this->validated = false;
                 $this->val_error[] = array('field' => $this->module . '_' . $field_name, 'field_trans' => $C_translate->translate('field_' . $field_name, $this->module, ""), 'error' => $C_translate->translate('validate_any', "", ""));
             }
         }
     }
     # If recurring, validate & set defaults
     if ($VAR['service_price_type'] == 1) {
         if (!empty($VAR['date_last_invoice'])) {
             $last_invoice = $validate->DateToEpoch(DEFAULT_DATE_FORMAT, $VAR['date_last_invoice']);
         } else {
             $last_invoice = time();
         }
         # Determine the next invoice date:
         $next_invoice = $this->calcNextInvoiceDate($last_invoice, @$VAR['product_price_recurr_default'], @$VAR['product_price_recurr_type'], @$VAR['product_price_recurr_weekday'], @$VAR['product_price_recurr_week']);
     }
     $active = 1;
     $queue = 'new';
     # Product details
     if (!empty($VAR['service_sku'])) {
         $product_id = @$VAR['product_id'];
         $product_sku = @$VAR['service_sku'];
     }
     # Hosting Details:
     if (@$VAR['service_type'] == 'host' || @$VAR['service_type'] == 'host_group') {
         # validate domain/tld set
         if (empty($VAR['host_domain_name']) || empty($VAR['host_domain_tld'])) {
             $this->validated = false;
             $this->val_error[] = array('field' => 'service_domain_name', 'field_trans' => $C_translate->translate('field_domain_name', 'service', ""), 'error' => $C_translate->translate('validate_any', "", ""));
         } else {
             $domain_name = $VAR['host_domain_name'];
             $domain_tld = $VAR['host_domain_tld'];
         }
     } else {
         if (@$VAR['service_type'] == 'domain') {
             # validate domain/tld set
             if (empty($VAR['domain_name']) || empty($VAR['domain_tld']) || empty($VAR['domain_type'])) {
                 $this->validated = false;
                 $this->val_error[] = array('field' => 'service_domain_name', 'field_trans' => $C_translate->translate('field_domain_name', 'service', ""), 'error' => $C_translate->translate('validate_any', "", ""));
             } else {
                 $domain_name = $VAR['domain_name'];
                 $domain_tld = $VAR['domain_tld'];
                 $domain_type = $VAR['domain_type'];
                 # Get the host_tld_id
                 $db =& DB();
                 $q = "SELECT id,default_term_new,registrar_plugin_id FROM " . AGILE_DB_PREFIX . "host_tld WHERE\n\t\t\t        \t  name \t\t=  " . $db->qstr($domain_tld) . " AND site_id \t=  " . $db->qstr(DEFAULT_SITE);
                 $tld = $db->Execute($q);
                 $domain_host_tld_id = $tld->fields['id'];
                 $domain_host_registrar_id = $tld->fields['registrar_plugin_id'];
                 $domain_term = $tld->fields['default_term_new'];
                 $domain_date_expire = time() + $domain_term * (86400 * 365);
             }
         }
     }
     if (!$this->validated) {
         # errors...
         global $smarty;
         $smarty->assign('form_validation', $this->val_error);
         global $C_vars;
         $C_vars->strip_slashes_all();
         return;
     } else {
         # Generate the SQL:
         $db =& DB();
         $id = $db->GenID(AGILE_DB_PREFIX . 'service_id');
         $q = "INSERT INTO " . AGILE_DB_PREFIX . "service SET\n\t\t        id\t\t\t\t\t\t= " . $db->qstr($id) . ",\n\t\t        site_id\t\t\t\t\t= " . $db->qstr(DEFAULT_SITE) . ",\n\t\t        date_orig\t\t\t\t= " . $db->qstr(time()) . ",\n\t\t        date_last\t\t\t\t= " . $db->qstr(time()) . ",  \n\t\t        account_id\t\t\t\t= " . $db->qstr($VAR['service_account_id']) . ",\n\t\t        account_billing_id \t\t= " . $db->qstr(@$VAR['ccnum']) . ",\n\t\t        product_id\t\t\t\t= " . $db->qstr(@$product_id) . ",\n\t\t        sku\t\t\t\t\t\t= " . $db->qstr(@$product_sku) . ",\n\t\t        active\t\t\t\t\t= " . $db->qstr('1') . ", \n\t\t        type\t\t\t\t\t= " . $db->qstr($VAR['service_type']) . ",\n\t\t        queue\t\t\t\t\t= " . $db->qstr('new') . ", \n\t\t        price\t\t\t\t\t= " . $db->qstr(@$VAR['product_price_base']) . ",\n\t\t        price_type\t\t\t\t= " . $db->qstr(@$VAR['service_price_type']) . ",\n\t\t        taxable\t\t\t\t\t= " . $db->qstr(@$VAR['product_taxable']) . ", \n\t\t        date_last_invoice\t\t= " . $db->qstr(@$last_invoice) . ",\n\t\t        date_next_invoice\t\t= " . $db->qstr(@$next_invoice) . ",\n\t\t        recur_schedule\t\t\t= " . $db->qstr(@$VAR['product_price_recurr_default']) . ",\n\t\t        recur_type\t\t\t\t= " . $db->qstr(@$VAR['product_price_recurr_type']) . ",\n\t\t        recur_weekday\t\t\t= " . $db->qstr(@$VAR['product_price_recurr_weekday']) . ", \n\t\t        recur_schedule_change \t= " . $db->qstr(@$VAR['product_price_recurr_schedule']) . ",\n\t\t        recur_cancel\t\t\t= " . $db->qstr(@$VAR['product_price_recurr_cancel']) . ", \n\t\t        recur_modify\t\t\t= " . $db->qstr(@$VAR['product_price_recurr_modify']) . ", \n\t\t        group_grant\t\t\t\t= " . $db->qstr(serialize(@$VAR['product_assoc_grant_group'])) . ",\n\t\t        group_type\t\t\t\t= " . $db->qstr(@$VAR['product_assoc_grant_group_type']) . ",\n\t\t        group_days\t\t\t\t= " . $db->qstr(@$VAR['product_assoc_grant_group_days']) . ", \n\t\t        host_server_id\t\t\t= " . $db->qstr(@$VAR['product_host_server_id']) . ",\n\t\t        host_provision_plugin_data=" . $db->qstr(serialize(@$VAR['product_host_provision_plugin_data'])) . ",\n\t\t        host_ip\t\t\t\t\t= " . $db->qstr(@$VAR['host_ip']) . ",\n\t\t        host_username\t\t\t= " . $db->qstr(@$VAR['host_username']) . ",\n\t\t        host_password\t\t\t= " . $db->qstr(@$VAR['host_password']) . ", \n\t\t        domain_name\t\t\t\t= " . $db->qstr(@$domain_name) . ",\n\t\t        domain_tld\t\t\t\t= " . $db->qstr(@$domain_tld) . ",\n\t\t        domain_term\t\t\t\t= " . $db->qstr(@$domain_term) . ",\n\t\t        domain_type\t\t\t\t= " . $db->qstr(@$domain_type) . ",\n\t\t        domain_date_expire\t\t= " . $db->qstr(@$domain_date_expire) . ",\n\t\t        domain_host_tld_id\t\t= " . $db->qstr(@$domain_host_tld_id) . ",\n\t\t        domain_host_registrar_id= " . $db->qstr(@$domain_host_registrar_id) . ",\n\t\t        prod_plugin_name\t\t= " . $db->qstr(@$VAR["product_prod_plugin_file"]) . ",\n\t\t        prod_plugin_data\t\t= " . $db->qstr(serialize(@$VAR["product_prod_plugin_data"]));
         $rs = $db->Execute($q);
         if ($VAR['service_type'] == 'group' || ($VAR['service_type'] = 'product' || ($VAR['service_type'] = 'product_group'))) {
             $this->queue_one($id, false);
         }
         global $VAR;
         $VAR["id"] = $id;
         define('FORCE_PAGE', 'service:view');
         return;
     }
 }
Ejemplo n.º 2
0
 function update_account_groups($VAR)
 {
     global $C_auth;
     $ii = 0;
     @($groups = $VAR['groups']);
     @($account = $VAR['account_admin_id']);
     # admin accounts groups cannot be altered
     # user cannot modify their own groups
     if ($account == "1" || SESS_ACCOUNT == $account) {
         return false;
     }
     ### Drop the current groups for this account:
     # generate the full query
     $dba =& DB();
     $q = "DELETE FROM " . AGILE_DB_PREFIX . "account_group\n\t\t\t  WHERE\n\t\t\t  service_id IS NULL AND\n\t\t\t  account_id  = " . $dba->qstr($account) . " AND \n\t\t\t  site_id     = " . $dba->qstr(DEFAULT_SITE);
     # execute the query
     $result = $dba->Execute($q);
     #loop through the array to add each account_group record
     for ($i = 0; $i < count($groups); $i++) {
         # verify the admin adding this account is authorized
         # for this group themselves, otherwise skip
         if ($C_auth->auth_group_by_id($groups[$i])) {
             # add the account to the selected groups...
             $dba =& DB();
             # determine the record id:
             $this->new_id = $dba->GenID(AGILE_DB_PREFIX . "" . 'account_group_id');
             # determine the expiration
             if (!empty($VAR['account_admin_date_expire'])) {
                 include_once PATH_CORE . 'validate.inc.php';
                 $validate = new CORE_validate();
                 $expire = $validate->DateToEpoch(DEFAULT_DATE_FORMAT, $VAR['account_admin_date_expire']);
             } else {
                 $expire = 0;
             }
             # generate the full query
             $q = "INSERT INTO " . AGILE_DB_PREFIX . "account_group\n\t\t\t\t\t  SET\n\t\t\t\t\t  id          = " . $dba->qstr($this->new_id) . ",\n\t\t\t\t\t  date_orig   = " . $dba->qstr(time()) . ",\n\t\t\t\t\t  date_expire = " . $dba->qstr($expire) . ",\n\t\t\t\t\t  group_id    = " . $dba->qstr($groups[$i]) . ",\n\t\t\t\t\t  account_id  = " . $dba->qstr($account) . ",\n\t\t\t\t\t  active      = " . $dba->qstr('1') . ",\n\t\t\t\t\t  site_id     = " . $dba->qstr(DEFAULT_SITE);
             # execute the query
             $result = $dba->Execute($q);
             $ii++;
             # error reporting:
             if ($result === false) {
                 global $C_debug;
                 $C_debug->error('account_admin.inc.php', 'update_account_groups', $dba->ErrorMsg());
             }
         }
     }
     ### Add default group
     if ($ii == 0) {
         # add the account to the selected groups...
         $dba =& DB();
         # determine the record id:
         $this->new_id = $dba->GenID(AGILE_DB_PREFIX . "" . 'account_group_id');
         # generate the full query
         $q = "INSERT INTO " . AGILE_DB_PREFIX . "account_group\n\t\t\t\t\tSET\n\t\t\t\t\tid          = " . $dba->qstr($this->new_id) . ",\n\t\t\t\t\tdate_orig   = " . $dba->qstr(time()) . ",\n\t\t\t\t\tdate_expire = " . $dba->qstr(@$expire) . ",\n\t\t\t\t\tgroup_id    = " . $dba->qstr(DEFAULT_GROUP) . ",\n\t\t\t\t\taccount_id  = " . $dba->qstr($account) . ",\n\t\t\t\t\tactive      = " . $dba->qstr('1') . ",\n\t\t\t\t\tsite_id     = " . $dba->qstr(DEFAULT_SITE);
         $result = $dba->Execute($q);
         if ($result === false) {
             global $C_debug;
             $C_debug->error('account_admin.inc.php', 'update_account_groups', $dba->ErrorMsg());
         }
     }
     ### Remove the user's session_auth_cache so it is regenerated on user's next pageview
     $db =& DB();
     $q = "SELECT id FROM " . AGILE_DB_PREFIX . "session WHERE\n\t\t\t  account_id  = " . $db->qstr($account) . " AND\n\t\t\t  site_id     = " . $db->qstr(DEFAULT_SITE);
     $rss = $db->Execute($q);
     while (!$rss->EOF) {
         $q = "DELETE FROM " . AGILE_DB_PREFIX . "session_auth_cache WHERE\n\t\t\t\t  session_id = " . $db->qstr($rss->fields['id']) . " AND \n\t\t\t\t  site_id \t = " . $db->qstr(DEFAULT_SITE);
         $db->Execute($q);
         $rss->MoveNext();
     }
     ### Do any db_mapping
     global $C_list;
     if ($C_list->is_installed('db_mapping')) {
         include_once PATH_MODULES . 'db_mapping/db_mapping.inc.php';
         $db_map = new db_mapping();
         $db_map->account_group_sync($account);
     }
 }