<%pre>

#include <users.h>
#include <setup.h>

using namespace vdrlive;

</%pre>
<%args>
  // input parameters
  std::string userid;
  std::string action;
</%args>
<%session scope="global">
bool logged_in(false);
</%session>
<%include>page_init.eh</%include>
<%cpp>
if (!logged_in && LiveSetup().UseAuth()) {
  cToSvConcat targetUrl = "/login.html?redirect=";
  targetUrl.appendUrlEscaped(request.getQuery());
  return reply.redirect(targetUrl.data());
}
</%cpp>
<%cpp>
  pageTitle = tr("Users");
  if ( !userid.empty() ) {
    if (action == "delete")
    {
      cUser* user = Users.GetByUserId( userid );
      if (user) {
        // invalid userid may occur if page is reloaded
        Users.Del(user);
        Users.Save();
      }
    }
  }
</%cpp>
<& pageelems.doc_type &>
<html>
  <head>
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>VDR-Live - <$ pageTitle $></title>
    <& pageelems.stylesheets &>
    <& pageelems.ajax_js &>
  </head>
  <body onpagehide="saveScrollPosition('content')" onpageshow="restoreScrollPosition()">
    <& pageelems.logo &>
    <& menu active=("users") component=("users.user_actions")>
    <div id="content">
      <div class="spacebar"><# spacer with fade-out effect #></div>
      <table class="listing users" cellspacing="0" cellpadding="0">
        <tr class="head">
          <td colspan="3">
            <div class="boxheader"><div class="caption"><$ pageTitle $></div></div>
          </td>
        </tr>
%       if (Users.Count() > 0) {
        <tr class="description">
          <td class="action leftcol" ><div class="withmargin"><$ tr("Name") $></div></td>
          <td class="rightcol" colspan="2"/>
        </tr>
<%cpp>
          cUser* user = Users.First();
          while (user)
          {
            bool bottom = (Users.Next(user) == NULL);
            if (user)
            {
</%cpp>
          <tr class="account">
            <td class="leftcol <? bottom ? "bottomrow" ?>"><div class="withmargin"><$ user->Name() $></div></td>
            <td class="rightcol <? bottom ? "bottomrow" ?>">
              <div class="user_actions">
                <a href="edit_user.html?userid=<$ user->Id() $>"><img class="icon" src="<$ LiveSetup().GetThemedLink("img", "edit.png") $>" alt="" <& tooltip.hint text=(tr("Edit user")) &> /></a>
                <a href="users.html?userid=<$ user->Id() $>&action=delete"><img class="icon" src="<$ LiveSetup().GetThemedLink("img", "del.png") $>" alt="" <& tooltip.hint text=(tr("Delete user")) &> /></a>
              </div></td>
            </td>
          </tr>
<%cpp>
            }
            user = Users.Next(user);
          }
        } else {
</%cpp>
          <tr class="account">
            <td class="message leftcol bottomrow"><div class="withmargin"><$ tr("No users configured") $></div></td>
            <td class="bottomrow"></td>
            <td class="rightcol bottomrow"></td>
          </tr>
%       }
      </table>
      <div class="spacebar"><# spacer with fade-out effect #></div>
    </div>
  </body>
</html>
<%include>page_exit.eh</%include>

<%def user_actions>
<a href="edit_user.html"><$ tr("New user") $></a>
</%def>
