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

$userID = $_GET['id'];
if (!isset($userID) || !is_numeric($userID))
  die("no user ID set");

$newName = $_GET['name'];
if (!isset($newName))
  die("no new name set");

  
$lst = Listopia::getInstance();

if ($lst->isLoggedIn() && $lst->isAdminUser())
{
  $data = array(
          'user_name'    => $newName
        );
  $ok = $lst->Database()->update('users', $data, 'users.user_id = ' . ((int)$userID) );
  
  if ($ok !== false)
  {
    echo "[done]";
  }
  else
  {
    echo "[update failed]";
  }  
  
  
  $data = array(
          'disc_username'    => $newName
        );
  $ok = $lst->Database()->update('t_discussion', $data, 't_discussion.disc_user = ' . ((int)$userID) );
 
  if ($ok !== false)
  {
    echo "[done]";
  }
  else
  {
    echo "[update failed]";
  }  
  
}