summaryrefslogtreecommitdiffstats
path: root/app/view/settings.php
blob: 21b75bae96847522a45df8dc8cfe3a32e1699081 (plain) (blame)
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
<?php

/*
 * SCROTT IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 *
 * For more information, please refer to UNLICENSE
 */

namespace settings;

require_once "model/settings.php";
require_once "view/formctrl.php";
require_once "view/datalsts.php";
require_once "class/settings.class.php";
require_once "class/obj.class.php";
require_once "class/user.class.php";

?>
<?php function settings() : void { ?>

    <div id="settingsModal" class="modal fade" tabindex="-1" role="dialog">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal">
                        <span aria-hidden="true">&times;</span>
                    </button>

                    <h4 class="modal-title">
                        <span class="glyphicon glyphicon-cog"></span> Settings
                    </h4>
                </div>

                <div class="modal-body">
                    <?php $s = false; ?>
                    <?php $u = \user::getCurrent(); ?>

                    <ul class="nav nav-tabs" role="tablist">
                        <li class="<?=oneStr("active", $s)?>">
                            <a href="#settingsUserTab" data-toggle="tab">
                                <span class="glyphicon glyphicon-user"></span> <?=$u->getDisplayName()?>
                            </a>
                        </li>

                        <?php if ($u->admin == 1) { ?>
                            <li class="<?=oneStr("active", $s)?>">
                                <a href="#settingsAdminTab" data-toggle="tab">
                                    <span class="glyphicon glyphicon-sunglasses"></span> Admin
                                </a>
                            </li>
                        <?php } ?>
                    </ul>

                    <?php $s = false; ?>

                    <div class="tab-content">
                        <div class="tab-pane fade <?=oneStr("in active", $s)?>" id="settingsUserTab">
                            <?=userTab($u)?>
                        </div>

                        <?php if ($u->admin == 1) { ?>
                            <div class="tab-pane fade <?=oneStr("in active", $s)?>" id="settingsAdminTab">
                                <?=adminTab()?>
                            </div>
                        <?php } ?>
                    </div>
                </div>
            </div>
        </div>
    </div>

<?php } ?>
<?php function image(\obj $obj, string $type, string $label) : void { ?>

    <div class="col-md-6 text-center">
        <?php if ($type == "head") { ?>
            <?=\datalsts\objHeadCircle($obj, 100)?>
            <?php $d = (!$obj->hasHeadImg() ? "disabled" : ""); ?>
        <?php } else { ?>
            <?=\datalsts\objBgPrev($obj, 100)?>
            <?php $d = (!$obj->getBgImg() ? "disabled" : ""); ?>
        <?php } ?>

        <br />
        <br />

        <button type="button" class="btn btn-default btn-xs" data-toggle="collapse" data-target="#setimgCollapse-<?=$obj->guid?>-<?=$type?>">
            <span class="glyphicon glyphicon-camera"></span> Upload new image
        </button>

        <br />

        <button type="submit" name="input[rmImg-<?=$type?>]" class="btn btn-danger btn-xs" <?=$d?> onclick="return assertconfirm()">
            <span class="glyphicon glyphicon-remove"></span> Remove image
        </button>

        <br />
        <br />

        <div class="collapse" id="setimgCollapse-<?=$obj->guid?>-<?=$type?>">
            <?=\formctrl\file($label, "img-".$type)?>
        </div>
    </div>

<?php } ?>
<?php function userTab(\user $u) : void { ?>

    <form method="post" action="<?=ap()?>" enctype="multipart/form-data">
        <?=\formctrl\formname( "settings-user" )?>
        <?=\formctrl\hidden( "guid", $u->guid )?>

        <p>&nbsp;</p>

        <div class="row">
            <?=image($u, "head", "User Image")?>
            <?=image($u, "bg", "Background Image")?>
        </div>

        <p>&nbsp;</p>

        <?php if ($u->admin == 1) { ?>
            <p class="pull-right">
                <span class="glyphicon glyphicon-sunglasses"></span> <?=$u->getDisplayName()?> is a Scrott Administrator
            </p>
        <?php } ?>

        <?=\formctrl\text( "Username", "", $u->name, "", false, true )?>
        <?=\formctrl\checkbox( "Change Password", "setpasswd", false, false, "#setpasswdCollapse-".$u->guid )?>

        <div class="collapse" id="setpasswdCollapse-<?=$u->guid?>">
            <?=\formctrl\password( "Current Password", "curpasswd", false )?>
            <?=\formctrl\password( "New Password", "passwd", false )?>
            <?=\formctrl\password( "Confirm Password", "cpasswd", false )?>
        </div>

        <?=\formctrl\text( "Alias", "alias", $u->alias, "", false )?>
        <?=\formctrl\text( "Email", "email", $u->email, "", false, false, ($u->emailConf == 1 ? "has-success" : "") )?>

        <?php if ($u->email != "" && $u->emailConf == 0) { ?>
            <?=\formctrl\text( "Email Verification Key", "emailVer", "", "", false, false, "has-warning", "You have not confirmed ownership of your email address" )?>
        <?php } ?>

        <div class="btn-group pull-right">
            <button type="submit" class="btn btn-success">
                <span class="glyphicon glyphicon-ok"></span> Save Changes
            </button>

            <a href="<?=ar()?>/deleteaccount" class="btn btn-danger">
                <span class="glyphicon glyphicon-trash"></span> Delete Account
            </a>
        </div>

        <h6>Created <?=$u->created?></h6>
        <h6>Updated <?=$u->updated?></h6>
    </form>

<?php } ?>
<?php function adminTab() : void { ?>

    <form method="post" action="<?=ap()?>">
        <?=\formctrl\formname( "settings-admin" )?>

        <p>&nbsp;</p>

        <div class="well well-sm">
            See detailed statistics, manage users and other objects in the <a href="<?=ar()?>/admin">Administration Panel</a>
        </div>

        <legend><h4>General Settings</h4></legend>
        <?=\formctrl\checkbox( "Require SSL", "sslOnly", \settings::sslOnly() )?>
        <?=\formctrl\checkbox( "Allow anyone to create an account", "allowPublicSignup", \settings::allowPublicSignup() )?>

        <p>&nbsp;</p>

        <legend><h4>SMTP Settings</h4></legend>

        <?php $res = \settings::smtpResult(); ?>

        <?php if ($res == "true") { ?>
            <p class="text-success pull-right">Last mail attempt was successful</p>
        <?php } else if ($res == "false") { ?>
            <p class="text-danger pull-right">Last mail attempt failed</p>
        <?php } else { ?>
            <p class="text-warning pull-right">No mail has been attempted yet</p>
        <?php } ?>

        <?=\formctrl\text( "From Address", "smtpEmailAddress", \settings::smtpEmailAddress(), "", false )?>
        <?=\formctrl\text( "From Name", "smtpFrom", \settings::smtpFrom(), "", false )?>
        <?=\formctrl\text( "SMTP Server", "smtpServer", \settings::smtpServer(), "", false )?>
        <?=\formctrl\text( "Server Port", "smtpPort", \settings::smtpPort() )?>

        <div class="form-group">
            <label>SMTP Security</label>

            <?php $sec = \settings::smtpSecurity(); ?>
            <select name="input[smtpSecurity]" class="form-control selectpicker">
                <option value="" <?=($sec == "" ? "selected" : "")?>>None</option>
                <option value="ssl" <?=($sec == "ssl" ? "selected" : "")?>>SSL</option>
                <option value="tls" <?=($sec == "tls" ? "selected" : "")?>>TLS</option>
            </select>
        </div>

        <?=\formctrl\text( "Username", "smtpUname", \settings::smtpUname(), "", false )?>
        <?=\formctrl\password( "Password", "smtpPasswd", false )?>

        <button type="submit" class="btn btn-success pull-right">
            <span class="glyphicon glyphicon-ok"></span> Save Changes
        </button>

        <p>&nbsp;</p>
    </form>

<?php } ?>