[% viewapps = dksdb.prepare("select ap.id,ap.app,ap.description,ap.name,acc.publicenabled,acc.expiration, to_char(expiration,'dd.mm.yyyy') as dspexpiration from apps ap left join appaccess acc on (ap.id=acc.id_app) where acc.id_user=? and acc.expiration >= CURRENT_DATE and ap.activated=true;")%]
+
<nav class="sidebar sidebar-offcanvas" id="sidebar">
<ul class="nav">
<!-- <li class="nav-item">
[% END %]
[% END %]
</ul>
-
- </nav>
+
+[% admcnt = dksdb.prepare("select count(*) as cnt from useringroups where id_user=?;") %]
+[% isadmin = admcnt.execute(session.id) %]
+[% IF isadmin > 0 %]
+<!-- ADMIN APPS -->
+
+ <h2>Admin</h2>
+ <ul class="nav">
+ [% adminapps = dksdb.prepare("select ap.id,ap.app,ap.name,ug.usergroup from apps ap
+join useringroups uigr on (ap.id_usergroup=uigr.id_group)
+join usergroups ug on (uigr.id_group=ug.id) where ug.usergroup='admin' and uigr.id_user=? order by name;") %]
+ [% FOREACH adm = adminapps.execute(session.id) %]
+ [% IF adm.id %]
+ <li class="nav-item">
+ <a class="nav-link" href="javascript:backoffice.loadpage('module/[% adm.app %]/index.html','[% adm.name %]');">
+ [% IF adm.icon %]
+ <i class="mdi mdi-application menu-icon"></i>
+ [% ELSE %]
+ <i class="mdi mdi-application menu-icon"></i>
+ [% END %]
+
+ <span class="menu-title">[% adm.name %]</span>
+ </a>
+ </li>
+ [% END %]
+ [% END %]
+ </ul>
+[% END %]
+</nav>
--- /dev/null
+[% userdata = dksdb.prepare("select us.id,us.username,us.prename,us.surname,us.blocked,ug.usergroup as defaultgroup,string_agg(distinct(uign.usergroup),',') as othergroups
+from users us
+join usergroups ug on (us.id_usergroup=ug.id)
+left join useringroups uig on (us.id=uig.id_user)
+left join usergroups uign on (uig.id_group=uign.id) where us.id=? group by us.id,ug.id LIMIT 1;") %]
+[% FOREACH usr = userdata.execute(params.id) %]
+<form id="frm_user" data-ident_users_id="[% usr.id %]">
+<div class="form-group">
+ <label for="usersurname">Nom</label>
+ <input type="text" class="form-control fieldsave" id="surname" name="users_surname" required value="[% usr.surname %]">
+ </div>
+ <div class="form-group">
+ <label for="userprename">Prénom</label>
+ <input type="text" class="form-control fieldsave" id="prename" name="users_prename" required value="[% usr.prename %]">
+ </div>
+ <div class="form-group">
+ <label for="username">username (email)</label>
+ <input type="email" class="form-control fieldsave" id="username" name="users_username" pattern="/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/" required value="[% usr.username %]">
+ </div>
+ <div class="form-group">
+ <label for="council">Default Group</label>
+ <select class="form-control" title="rien selectionné" id="id_usergroup" name="users_id_usergroup" >
+
+ [% FOREACH cc=dksdb.query("select id,usergroup from usergroups order by id;") %]
+ [% IF usr.defaultgroup == cc.usergroup %]
+ <option value="[cc.id]" selected>[% cc.usergroup %]</option>
+ [% ELSE %]
+ <option value="[cc.id]">[% cc.usergroup %]</option>
+ [% END %]
+
+ [% END %]
+ </select>
+ </div>
+</form>
+[% END %]
+<h2>Applications</h2>
+[% appdata = dksdb.prepare("select ap.name,ac.id_user,ac.id_app,ac.publicenabled,ac.expiration from appaccess ac join apps ap on (ac.id_app=ap.id) where ac.id_user=?;") %]
+<table class="table table-bordered table-hover table-striped" style="width: 100%; margin: 0px;" id="tbl_applications">
+ <thead class="thead-dark">
+ <tr>
+ <th>Application</th>
+ <th>Public Enabled</th>
+ <th>Expiration</th>
+ </tr>
+ </thead>
+
+ <tbody>
+ [% FOREACH uap = appdata.execute(params.id) %]
+ <tr>
+ <td>[% uap.name %]</td>
+ <td>[% uap.publicenabled %]</td>
+ <td>[% uap.expiration %]</td>
+ </tr>
+ [% END %]
+ </tbody>
+ </table>
+<h2>Invoices</h2>
+[% invdata = dksdb.prepare("select iv.id,iv.id_user,iv.reference,iv.invoicedate,iv.email,iv.status,iv.statusdate,iv.voucher,iv.payementmethod,iv.sumgrossamount,iv.payedamount,iv.pdfname from invoices iv left join apps ap on (iv.id_app=ap.id) where id_user=? order by iv.invoicedate DESC;") %]
+<table class="table table-bordered table-hover table-striped" style="width: 100%; margin: 0px;" id="tbl_invoices">
+ <thead class="thead-dark">
+ <tr>
+ <th>Reference</th>
+ <th>Invoice Date</th>
+ <th>Status</th>
+ <th>Status Date</th>
+ <th>Voucher</th>
+ <th>Method</th>
+ <th>Amount</th>
+ <th>Payed Amount</th>
+ <th>E-Mail</th>
+ <th>PDF</th>
+ </tr>
+ </thead>
+
+ <tbody>
+ [% FOREACH ivd = invdata.execute(params.id) %]
+ <tr>
+ <td>[% ivd.reference %]</td>
+ <td>[% ivd.invoicedate %]</td>
+ <td>[% ivd.status %]</td>
+ <td>[% ivd.statusdate %]</td>
+ <td>[% ivd.voucher %]</td>
+ <td>[% ivd.method %]</td>
+ <td>[% ivd.sumgrossamount %]</td>
+ <td>[% ivd.payedamount %]</td>
+ <td>[% ivd.email %]</td>
+ <td>[% IF ivd.pdfname %] <button class="btn btn-info"><i class="mdi mdi-pdf-box"></i></button> [% END %]</td>
+ </tr>
+ [% END %]
+ </tbody>
+ </table>
\ No newline at end of file
+
+
+<h1>Utilisateurs</h1>
+
+ <table class="table table-bordered table-hover table-striped" style="width: 100%; margin: 0px;" id="tbl_users">
+ <thead class="thead-dark">
+ <tr>
+ <th>Username</th>
+ <th>Prename</th>
+ <th>Surname</th>
+ <th>Is Blocked</th>
+ <th>Default Group</th>
+ <th>Applications</th>
+ <th>Other Groups</th>
+ <th> </th>
+ </tr>
+ </thead>
+
+ <tbody>
+ [% FOREACH aus = dksdb.query("select us.id,us.username,us.prename,us.surname,us.blocked,ug.usergroup as defaultgroup,string_agg(ax.name,',') as apps,string_agg(distinct(uign.usergroup),',') as othergroups
+from users us
+join usergroups ug on (us.id_usergroup=ug.id)
+left join useringroups uig on (us.id=uig.id_user)
+left join usergroups uign on (uig.id_group=uign.id)
+left join (
+select ap.name,ac.id_user,ac.id_app,ac.publicenabled,ac.expiration,row_number() over (partition by ac.id_user) from appaccess ac join apps ap on (ac.id_app=ap.id)
+) ax
+on (us.id=ax.id_user and ax.id_app is not null)
+group by us.id,ug.id") %]
+ <tr>
+ <td>[% aus.username %]</td>
+ <td>[% aus.prename %]</td>
+ <td>[% aus.surname %]</td>
+ <td>[% aus.blocked %]</td>
+ <td>[% aus.defaultgroup %]</td>
+ <td>[% aus.apps %]</td>
+ <td>[% aus.othergroups %]</td>
+ <td>
+ <button class="btn btn-info" onclick="parent.backoffice.loadpage('module/users/form_users.html?id=[% aus.id %]','App User');"><i class="mdi mdi-pencil"></i></button>
+ [% IF aus.id != session.id %]
+ <button class="btn btn-danger" onclick="delete_user('[% aus.id %]');"><i class="mdi mdi-trash-can"></i></button>
+ [% END %]
+ </td>
+ </tr>
+ [% END %]
+ </tbody>
+ </table>