$lastlog_input = 'not available';
         }
         $lastlog_output = $row['acctoutputoctets'];
         if ($lastlog_output) {
             $lastlog_output = bytes2str($lastlog_output);
         } else {
             $lastlog_output = 'not available';
         }
     }
 } else {
     echo "<b>Database query failed: " . da_sql_error($link, $config) . "</b><br>\n";
 }
 if (!$logged_now) {
     $search = @da_sql_query($link, $config, "SELECT " . da_sql_limit(1, 0, $config) . " * FROM {$config['sql_accounting_table']}\n\t\tWHERE username = '{$login}' AND acctsessiontime != '0' " . da_sql_limit(1, 1, $config) . "\n\t\t ORDER BY acctstoptime DESC " . da_sql_limit(1, 2, $config) . " ;");
     if ($search) {
         if (@da_sql_num_rows($search, $config)) {
             $row = @da_sql_fetch_array($search, $config);
             $lastlog_time = $row['acctstarttime'];
             $lastlog_server_ip = $row['nasipaddress'];
             $lastlog_server_port = $row['nasportid'];
             $lastlog_session_time = time2str($row['acctsessiontime']);
             $lastlog_client_ip = $row['framedipaddress'];
             $lastlog_server_name = $lastlog_server_ip != '' ? @gethostbyaddr($lastlog_server_ip) : '-';
             $lastlog_client_name = $lastlog_client_ip != '' ? @gethostbyaddr($lastlog_client_ip) : '-';
             $lastlog_callerid = $row['callingstationid'];
             if ($lastlog_callerid == '') {
                 $lastlog_callerid = 'not available';
             }
             $lastlog_input = $row['acctinputoctets'];
             $lastlog_input = bytes2str($lastlog_input);
             $lastlog_output = $row['acctoutputoctets'];
        foreach ($del_members as $del) {
            $del = da_sql_escape_string($del);
            $res = @da_sql_query($link, $config, "DELETE FROM {$config['sql_usergroup_table']} WHERE username = '{$del}' AND groupname = '{$login}';");
            if (!$res) {
                echo "<b>Could not delete user {$del} from group: " . da_sql_error($link, $config) . "</b><br>\n";
            }
        }
    }
    if ($new_members != '') {
        $Members = preg_split("/[\n\\s]+/", $new_members, -1, PREG_SPLIT_NO_EMPTY);
        if (!empty($Members)) {
            foreach ($Members as $new_member) {
                $new_member = da_sql_escape_string($new_member);
                $res = @da_sql_query($link, $config, "SELECT username FROM {$config['sql_usergroup_table']} WHERE\n\t\t\t\tusername = '{$new_member}' AND groupname = '{$login}';");
                if ($res) {
                    if (@da_sql_num_rows($res, $config)) {
                        echo "<b>User {$new_member} already is a member of the group</b><br>\n";
                    } else {
                        $res = @da_sql_query($link, $config, "INSERT INTO {$config['sql_usergroup_table']} (groupname,username)\n\t\t\t\t\t\tVALUES ('{$login}','{$new_member}');");
                        if (!$res) {
                            echo "<b>Error while adding user {$new_member} to group: " . da_sql_error($link, $config) . "</b><br>\n";
                        }
                    }
                } else {
                    echo "<b>Could not add new member {$new_member}: " . da_sql_error($link, $config) . "</b><br>\n";
                }
            }
        }
    }
} else {
    echo "<b>Could not connect to SQL database</b><br>\n";