<?php 
require("common_begin.php");

$lst = Listopia::getInstance();

$result = array();

if ($lst->isLoggedIn())
{
  $query = $lst->Database()->select(array(
                      'fields'      => 'user_id, user_name',
                      'table'       => 'users',
                      'condition'   => 'user_name like "'.$_GET['term'].'%"'
                      ));
  if (!empty($query[0]))
  {
    foreach ($query as &$user)
    {
      array_push($result, array(
        'id' => $user['users']['user_id'],
        'label' => $user['users']['user_name'],
        'value' => $user['users']['user_name'],
        ));
    }
  }
}

echo json_encode($result);

require("common_end.php");

