aboutsummaryrefslogtreecommitdiff
path: root/app/controllers/admin/licenses.php
blob: 2f9ff990b5fcf88c4d45a771ee199675f9db3245 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php

class Admin_LicensesController extends AuthenticatedController
{
    public function before_filter(&$action, &$args)
    {
        parent::before_filter($action, $args);
        $GLOBALS['perm']->check('root');
        PageLayout::setTitle(_('Lizenzverwaltung'));
        Navigation::activateItem('/admin/locations/licenses');
    }

    public function index_action()
    {
        $this->licenses = License::findBySQL("1 ORDER BY `default` DESC, `identifier` ASC");
    }

    public function edit_action()
    {
        $this->license = new License(Request::get("identifier"));
        PageLayout::setTitle(sprintf(_("Lizenz %s bearbeiten"), $this->license->getId()));
    }

    public function store_action()
    {
        $this->license = new License(Request::get("identifier"));
        if (Request::isPost()) {
            $this->license->setData(Request::getArray("data"));
            $this->license->store();
            if (Request::submitted("delete_avatar")) {
                $avatar = LicenseAvatar::getAvatar($this->license->getId());
                $avatar->reset();
            }
            if ($_FILES['avatar']['size'] > 0) {
                $avatar = LicenseAvatar::getAvatar($this->license->getId());
                $avatar->createFromUpload("avatar");
            }
            PageLayout::postSuccess(_("Lizenz wurde gespeichert."));
            if ($this->license['default']) {
                $other_licenses = License::findBySQL("`identifier` != ? AND `default` = '1'", [
                    $this->license->getId()
                ]);
                foreach ($other_licenses as $other_license) {
                    $other_license['default'] = 0;
                    $other_license->store();
                }
                if (count($other_licenses)) {
                    PageLayout::postInfo(_("Neue Standardlizenz wurde gesetzt."));
                }
            }
        }
        $this->redirect("admin/licenses/index");
    }

    public function delete_action()
    {
        $this->license = new License(Request::get("identifier"));
        if (Request::isPost()) {
            $this->license->delete();
            PageLayout::postSuccess(sprintf(
                _("Die Lizenz %s wurde gelöscht."), htmlReady(Request::get("identifier"))
            ));
        } else {
            throw new AccessDeniedException();
        }
        $this->redirect("admin/licenses/index");
    }
}