<commit_before><?php
/**
 * This is the defualt view for the UserList class
 */

//TODO: use editable YuiDatatable
//XXX TODO: lista användare online

require_once('UserList.php');

if (!$session->isAdmin)
    return;

if ($session->isSuperAdmin && !empty($_GET['del'])) {
    $user = new User($_GET['del']);
    $user->remove();
}

echo '<h1>Manage users</h1>';
echo 'All users: '.ahref('coredev/admin/userlist', UserList::getCount()).'<br/>';
echo 'Users online: '.ahref('coredev/admin/userlist/0/online', UserList::onlineCount()).'<br/>';

$filter = '';
if (!empty($_POST['usearch'])) $filter = $_POST['usearch'];

//process updates
if ($session->isSuperAdmin && !empty($_POST))
{
    if (!empty($_POST['u_name']) && !empty($_POST['u_pwd']))
    {
        $username = trim($_POST['u_name']);
        $pwd      = trim($_POST['u_pwd']);

        $user = new User();
        $user->create($username);
        if (!$user->getId())
            $error->add('Failed to create user');

        if ($error->getErrorCount()) {
            echo $error->render(true);
            return;
        }

        $user->setPassword($pwd);

        if (!empty($_POST['u_grp']))
            $user->addToGroup($_POST['u_grp']);

        echo '<div class="good">New user created. '.ahref('coredev/admin/useredit/'.$user->getId(), $username).'</div>';
    }
}

echo '<br/>';
echo xhtmlForm('usearch_frm');
echo 'Username filter: '.xhtmlInput('usearch');
echo xhtmlSubmit('Search');
echo xhtmlFormClose();
echo '<br/>';

if ($session->isSuperAdmin)
    echo xhtmlForm('add_user');

echo '<table border="1">';
echo '<tr>';
echo '<th>Username</th>';
echo '<th>E-mail</th>';
echo '<th>Last active</th>';
echo '<th>Last Ip</th>';
echo '<th>Created</th>';
echo '<th>User level</th>';
echo '<th>Groups</th>';
echo '</tr>';

foreach (UserList::getUsers($filter) as $user)
{
    echo '<tr>';
    echo '<td>'.ahref('coredev/admin/useredit/'.$user->getId(), $user->getName()).'</a></td>';
    echo '<td>'.$user->getEmail().'</td>';
    echo '<td>'.$user->getTimeLastActive().'</td>';
    echo '<td>'.$user->getLastIp().'</td>';
    echo '<td>'.$user->getTimeCreated().'</td>';
    echo '<td>'.$user->getUserLevelName().'</td>';

    $grps = array();
    foreach ($user->getGroups() as $g)
        $grps[] = $g->getName();

    echo '<td>'.implode(', ', $grps).'</td>';

    echo '</tr>';
}
echo '<tr>';
echo '<td colspan="6">';
echo 'Add user: '.xhtmlInput('u_name').' - pwd: '.xhtmlInput('u_pwd');

$grp = new UserGroupList();
<commit_msg>added "email" field on "create new user"<commit_after><?php
/**
 * This is the defualt view for the UserList class
 */

//TODO: use editable YuiDatatable
//XXX TODO: lista användare online

require_once('UserList.php');

if (!$session->isAdmin)
    return;

if ($session->isSuperAdmin && !empty($_GET['del'])) {
    $user = new User($_GET['del']);
    $user->remove();
}

echo '<h1>Manage users</h1>';
echo 'All users: '.ahref('coredev/admin/userlist', UserList::getCount()).'<br/>';
echo 'Users online: '.ahref('coredev/admin/userlist/0/online', UserList::onlineCount()).'<br/>';

$filter = '';
if (!empty($_POST['usearch'])) $filter = $_POST['usearch'];

//process updates
if ($session->isSuperAdmin && !empty($_POST))
{
    if (!empty($_POST['u_name']) && !empty($_POST['u_pwd']))
    {
        $username = trim($_POST['u_name']);
        $pwd      = trim($_POST['u_<PASSWORD>']);

        $user = new User();
        $user->create($username);
        if (!$user->getId())
            $error->add('Failed to create user');

        if ($error->getErrorCount()) {
            echo $error->render(true);
            return;
        }

        $user->setPassword($pwd);
        $user->saveSetting('email', $_POST['u_email']);

        if (!empty($_POST['u_grp']))
            $user->addToGroup($_POST['u_grp']);

        echo '<div class="good">New user created. '.ahref('coredev/admin/useredit/'.$user->getId(), $username).'</div>';
    }
}

echo '<br/>';
echo xhtmlForm('usearch_frm');
echo 'Username filter: '.xhtmlInput('usearch');
echo xhtmlSubmit('Search');
echo xhtmlFormClose();
echo '<br/>';

if ($session->isSuperAdmin)
    echo xhtmlForm('add_user');

echo '<table border="1">';
echo '<tr>';
echo '<th>Username</th>';
echo '<th>E-mail</th>';
echo '<th>Last active</th>';
echo '<th>Last Ip</th>';
echo '<th>Created</th>';
echo '<th>User level</th>';
echo '<th>Groups</th>';
echo '</tr>';

foreach (UserList::getUsers($filter) as $user)
{
    echo '<tr>';
    echo '<td>'.ahref('coredev/admin/useredit/'.$user->getId(), $user->getName()).'</a></td>';
    echo '<td>'.$user->getEmail().'</td>';
    echo '<td>'.$user->getTimeLastActive().'</td>';
    echo '<td>'.$user->getLastIp().'</td>';
    echo '<td>'.$user->getTimeCreated().'</td>';
    echo '<td>'.$user->getUserLevelName().'</td>';

    $grps = array();
    foreach ($user->getGroups() as $g)
        $grps[] = $g->getName();

    echo '<td>'.implode(', ', $grps).'</td>';

    echo '</tr>';
}
echo '<tr>';
echo '<td colspan="7">';
echo 'Add user: '.xhtmlInput('u_name').' - pwd: '.xhtmlInput('<PASSWORD>').' - email: '.xhtmlInput('u_email');

$grp = new UserGroupList();

{'fraction_non_alphanumeric': 0.2544677544677545, 'fraction_numerical': 0.0019425019425019425, 'mean_word_length': 3.7325367647058822, 'pattern_counts': {'":': 0, '<': 95, '<?xml version=': 0, '>': 138, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4219611', 'n_tokens_mistral': 1782, 'n_tokens_neox': 1792, 'n_words': 358}