<?php 
    $sql = "SELECT * FROM h_members"; 
    $res = $sql_engine->exec_query($sql); 
    $columns = array(); 
    $count = 0; 
    if ($row = $sql_engine->next($res)) { 
        foreach ($row as $key => $val) if ($count++ <6) continue; else $columns[] = $key; 
    } 
     
    $sql = "SELECT DISTINCT(rec_id) FROM h_members"; 
    $res = $sql_engine->exec_query($sql); 
    $agent_list = array(); 
    $count = 0; 
    while ($row = $sql_engine->next($res)) { 
        $rec_id = $row['rec_id']; 
        $sql = "SELECT * FROM h_members WHERE rec_id=$rec_id ORDER BY k__date"; 
        $res2 = $sql_engine->exec_query($sql); 
        $last_row = ''; 
        while ($row2 = $sql_engine->next($res2)) { 
            $agent_list[$count]['fullname'] = "$row2[fullname]"; 
            if (!$last_row) { 
                $agent_list[$count]['change'][] = "New user."; 
            } else { 
                foreach($columns as $key) { 
                    if ($last_row[$key] != $row2[$key]) { 
                        switch ($key) { 
                        case 'password': 
                            $agent_list[$count]['change'][] = "New Password"; 
                        default: 
                            $agent_list[$count]['change'][] = str_replace("_", " ", $key)." = ".str_replace("_", " ", $row2[$key]); 
                            break; 
                        } 
                    } 
                } 
            } 
            if ($row2['k__del']) $agent_list[$count]['change'][] = "Deleted"; 
            $agent_list[$count]['date'] = date("Y/m/d H:i:s", strtotime($row2['k__date'])); 
            if (!DB_ENGINE_MYSQL) { 
                $res3 = $sql_engine->exec_query("SELECT TO_CHAR(k__date, 'DD/MM/YYYY HH24:MI:SS') as k__date FROM sa_h_agent_users WHERE h_id=$row2[h_id]"); 
                $row3 = $sql_engine->next($res3); 
                $agent_list[$count]['date'] = $row3['k__date']; 
            } 
            $res3 = $sql_engine->exec_query("SELECT fullname, username FROM h_members WHERE rec_id=$row2[k__author]"); 
            if (!$row3 = $sql_engine->next($res3)) { 
                $res3 = $sql_engine->exec_query("SELECT fullname, username FROM members WHERE rec_id=$row2[k__author]"); 
                $row3 = $sql_engine->next($res3); 
            } 
            if ($row3) $agent_list[$count]['by'] = "$row3[fullname] ($row3[username])"; 
            else $agent_list[$count]['by'] = "op system"; 
            $last_row = $row2; 
            $count++; 
        } 
    } 
     
    // SMARTY is the best choice to handle this. But for now, demo using echo... 
    echo "<style type=\"text/css\"> * {font-size: 10pt} </style>\n"; 
    echo '<table border="0" cellspacing="0" cellpadding="5">'; 
    foreach ($agent_list as $user) { 
        echo "<tr><td valign=top>$user[fullname]</td><td valign=top><ul>"; 
        foreach ($user['change'] as $change) echo "<li>$change</li>"; 
        echo "</ul><td valign=top> by $user[by] </td><td valign=top> on $user[date] </td></tr>"; 
    } 
    echo "</table>"; 
?>
 
 |