diff options
-rw-r--r-- | modules/images.inc.php | 51 | ||||
-rw-r--r-- | templates/image-list.html | 51 | ||||
-rw-r--r-- | templates/main-menu.html | 1 |
3 files changed, 103 insertions, 0 deletions
diff --git a/modules/images.inc.php b/modules/images.inc.php new file mode 100644 index 0000000..f962c07 --- /dev/null +++ b/modules/images.inc.php @@ -0,0 +1,51 @@ +<?php + +class Page_Images extends Page +{ + + protected function doPreprocess() + { + User::load(); + if (!User::isShibbolethAuth()) { + Message::addError('Not {{0}}', CONFIG_IDM); + Util::redirect('?do=Main'); + } + if (!User::isAdmin()) { + Message::addError('Not admin!'); + Util::redirect('?do=Main'); + } + if (Request::post('action') === 'delete') { + $image = Request::post('image'); + $row = Database::queryFirst('SELECT filepath FROM imageversion WHERE imageversionid = :version', + ['version' => $image]); + if ($row === false) { + Message::addError('Image {{0}} nicht gefunden', $image); + } else { + // PHP process doesn't have write permissions to VM store, plus we don't have the absolute path + // for now this has to do, until someone comes along and adds an RPC method in the java app. + Message::addInfo('Vergessen Sie nicht, {{0}} vom Storage zu löschen', $row['filepath']); + Database::exec("DELETE FROM imageversion WHERE imageversionid = :version", + ['version' => $image]); + } + Util::redirect('?do=images'); + } + } + + protected function doRender() + { + $res = Database::simpleQuery('SELECT b.displayname, b.description, + v.imageversionid, v.createtime, v.expiretime, v.filesize, v.filepath + FROM imagebase b + INNER JOIN imageversion v USING (imagebaseid) + ORDER BY b.imagebaseid ASC, v.createtime ASC'); + $rows = []; + while ($row = $res->fetch(PDO::FETCH_ASSOC)) { + $row['createtime_s'] = date('d.m.Y', $row['createtime']); + $row['expiretime_s'] = date('d.m.Y', $row['expiretime']); + $row['filesize_s'] = Util::readableFileSize($row['filesize']); + $rows[] = $row; + } + Render::addTemplate('image-list', ['list' => $rows]); + } + +} diff --git a/templates/image-list.html b/templates/image-list.html new file mode 100644 index 0000000..3c4561e --- /dev/null +++ b/templates/image-list.html @@ -0,0 +1,51 @@ +<h1>Images</h1> + +<div class="alert alert-warning"> + Die Löschfunktion entfernt lediglich den Datenbankeintrag. Bitte <b>löschen Sie die zugehörige Datei</b> + aus dem Storage-Verzeichnis (Spalte Pfad) +</div> + +<form method="post" action="?do=images"> + <input type="hidden" name="token" value="{{token}}"> + <input type="hidden" name="action" value="delete"> + <table class="table"> + <thead> + <tr> + <th>Name</th> + <th>Größe</th> + <th>Erstellt</th> + <th>Läuft ab</th> + <th>Pfad</th> + <th></th> + </tr> + </thead> + <tbody> + {{#list}} + <tr> + <td title="{{description}}"> + {{displayname}} + <div class="small">{{imageversionid}}</div> + </td> + <td class="slx-nowrap"> + {{filesize_s}} + </td> + <td class="slx-nowrap"> + {{createtime_s}} + </td> + <td class="slx-nowrap"> + {{expiretime_s}} + </td> + <td class="small"> + {{filepath}} + </td> + <td> + <button type="submit" name="image" value="{{imageversionid}}" class="btn btn-xs btn-danger" + onclick="return confirm('Wirklich?')"> + <span class="glyphicon glyphicon-remove"></span> + </button> + </td> + </tr> + {{/list}} + </tbody> + </table> +</form>
\ No newline at end of file diff --git a/templates/main-menu.html b/templates/main-menu.html index e4583cc..ea32b1d 100644 --- a/templates/main-menu.html +++ b/templates/main-menu.html @@ -13,6 +13,7 @@ <ul class="nav navbar-nav"> {{#admin}} <li><a href="?do=AddUser">AddUser</a></li> + <li><a href="?do=images">Manage Images</a></li> {{/admin}} </ul> <ul class="nav navbar-nav navbar-right"> |