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);
     }
 }
 function dbmap()
 {
     global $C_list;
     if (!is_object($C_list)) {
         include_once PATH_CORE . 'list.inc.php';
         $C_list = new CORE_list();
     }
     if ($C_list->is_installed('db_mapping')) {
         # Update the db_mapping accounts
         include_once PATH_MODULES . 'db_mapping/db_mapping.inc.php';
         $db_map = new db_mapping();
         $db_map->account_group_sync($this->rs['account_id']);
     }
 }