<?php

/**
 *
 * INDEXU
 * Copyright(C), Nicecoder, 2000-2006, All Rights Reserved.
 *
 * INDEXU(tm) is protected by Indonesia and International copyright laws.
 * Unauthorized use or distribution of INDEXU(tm) is strictly prohibited,
 * violators will be prosecuted. To obtain a license for using INDEXU(tm),
 * please register at Nicecoder home page at http://www.nicecoder.com
 *
 * Author:
 *    Dody Rachmat Wicaksono (dody@nicecoder.com)
 *    M. Zuber (zubby@nicecoder.com)
 *
 */

  /*===================================================
    ShowWhosOnline()
  ===================================================*/

  function ShowWhosOnline() {
    global $dbConn,$admin_template_path,$cookie_admin_last_visit;
    global $whosonline,$username,$ip,$location,$expiry,$tbl_class,$whosonline_listing;

    if(!empty($whosonline)) $exp = $whosonline;
    else $exp = 600;

    $expired = time() - $exp;

    // get total users online

    $query = "select data, expiry from idx_sessions where expiry > $expired
              order by expiry desc";
    $result = $dbConn->Execute($query);

    $i = 0;
    $ip_arr = array();
    while (!$result->EOF) {
      $data = $result->Fields(data);
      $data = urldecode($data);

      // parse session data
      $data = substr($data,0,strlen($data)-1);
      $str = explode(";",$data);
      $dump = array();

      foreach($str as $key => $val) {
        $str1 = explode("|",$val);
        foreach($str1 as $key1 => $val1) {
          if(preg_match("/s:/i",$val1)) $dump[$vkey] = unserialize($val1);
          else $vkey = $val1;
        }
      }

      if (!in_array($dump[indexu_session_ip], $ip_arr)) {
        $ip_arr[] = $dump[indexu_session_ip];
        $ip = $dump[indexu_session_ip];
        $location = $dump[indexu_session_location];
        $username = $dump[indexu_session_username];
        if(empty($username))
          $username = "guest";
        else
          $username = "<a href=user_edit.php?username=$username>$username</a>";

        $expiry = date("d.m.Y H:i",$result->Fields(expiry));

        if($i%2) $tbl_class = "tbl_light";
        else $tbl_class = "tbl_light2";

        $whosonline_listing .= EvalTemplate($admin_template_path . "whos_rows.html",
          "\$ip,\$location,\$username,\$expiry,\$tbl_class");

        $i++;
      }
      $result->MoveNext();
    }

    DisplayTemplate($admin_template_path . "whos.html", "\$whosonline_listing");
  }


  /*===================================================
    main
  ===================================================*/

  include "../application.php";
  
  RunPreFilter(__FILE__);

  DisplayTemplate($admin_template_path . "header.html");
  ShowWhosOnline();
  DisplayTemplate($admin_template_path . "footer.html");

  RunPostFilter(__FILE__);

?>