Browse Source

Merge ../BusinessAppTemplate

Skylar Ittner 2 months ago
parent
commit
f9b6d7213e
8 changed files with 85 additions and 88 deletions
  1. 3
    15
      LICENSE.md
  2. 1
    1
      README.md
  3. 2
    0
      api/index.php
  4. 55
    21
      lib/FormBuilder.lib.php
  5. 7
    10
      mobile/index.php
  6. 0
    24
      pages/form.php
  7. 17
    1
      required.php
  8. 0
    16
      static/js/form.js

+ 3
- 15
LICENSE.md View File

@@ -1,19 +1,7 @@
1
-Copyright (c) 2018 Netsyms Technologies.
1
+Copyright (c) 2017-2019 Netsyms Technologies.  Some rights reserved.
2 2
 
3
-If you modify and redistribute this project, you must replace the branding
4
-assets with your own.
5
-
6
-The branding assets include:
7
- * the application icon
8
- * the Netsyms N punchcard logo
9
- * the Netsyms for Business graph logo
10
-
11
-If you are unsure if your usage is allowed, please contact us:
12
-https://netsyms.com/contact
13
-legal@netsyms.com
14
-
15
-All other portions of this application,
16
-unless otherwise noted (in comments, headers, etc), are licensed as follows:
3
+Licensed under the Mozilla Public License Version 2.0.  Files without MPL header
4
+comments, including third party code, may be under a different license.
17 5
 
18 6
 Mozilla Public License Version 2.0
19 7
 ==================================

+ 1
- 1
README.md View File

@@ -18,4 +18,4 @@ Setup Tips
18 18
 * Run `git submodule init` and `git submodule update` to install several other dependencies
19 19
 * Install the database using `database.mwb` or `database.sql`
20 20
 * Copy `settings.template.php` to `settings.php` and customize
21
-* You'll also need to setup [AccountHub](https://source.netsyms.com/Business/AccountHub)
21
+* You'll also need to setup [AccountHub](https://source.netsyms.com/Business/AccountHub)

+ 2
- 0
api/index.php View File

@@ -10,6 +10,8 @@ require __DIR__ . '/../required.php';
10 10
 require __DIR__ . '/functions.php';
11 11
 require __DIR__ . '/apisettings.php';
12 12
 
13
+header("Access-Control-Allow-Origin: *");
14
+
13 15
 $VARS = $_GET;
14 16
 if ($_SERVER['REQUEST_METHOD'] != "GET") {
15 17
     $VARS = array_merge($VARS, $_POST);

+ 55
- 21
lib/FormBuilder.lib.php View File

@@ -173,33 +173,65 @@ HTMLTOP;
173 173
             $required = $item["required"] ? "required" : "";
174 174
             $id = empty($item["id"]) ? "" : "id=\"$item[id]\"";
175 175
             $pattern = empty($item["pattern"]) ? "" : "pattern=\"$item[pattern]\"";
176
-
176
+            if (empty($item['type'])) {
177
+                $item['type'] = "text";
178
+            }
177 179
             $itemhtml = "";
180
+            $itemlabel = "";
181
+
182
+            if ($item['type'] == "textarea") {
183
+                $itemlabel = "<label class=\"mb-0\"><i class=\"$item[icon]\"></i> $item[label]:</label>";
184
+            } else if ($item['type'] != "checkbox") {
185
+                $itemlabel = "<label class=\"mb-0\">$item[label]:</label>";
186
+            }
187
+            $strippedlabel = strip_tags($item['label']);
178 188
             $itemhtml .= <<<ITEMTOP
179 189
 \n\n                <div class="col-12 col-md-$item[width]">
180 190
                     <div class="form-group mb-3">
181
-                        <label class="mb-0">$item[label]:</label>
182
-                        <div class="input-group">
191
+                        $itemlabel
192
+ITEMTOP;
193
+            $inputgrouptop = <<<INPUTG
194
+\n                            <div class="input-group">
183 195
                             <div class="input-group-prepend">
184 196
                                 <span class="input-group-text"><i class="$item[icon]"></i></span>
185 197
                             </div>
186
-ITEMTOP;
187
-            if (empty($item['type']) || $item['type'] != "select") {
188
-                $itemhtml .= <<<INPUT
189
-\n                            <input type="$item[type]" name="$item[name]" $id class="form-control" aria-label="$item[label]" minlength="$item[minlength]" maxlength="$item[maxlength]" $pattern value="$item[value]" $required />
190
-INPUT;
191
-            } else {
192
-                $itemhtml .= <<<SELECT
193
-\n                            <select class="form-control" name="$item[name]" aria-label="$item[label]" $required>
198
+INPUTG;
199
+            switch ($item['type']) {
200
+                case "select":
201
+                    $itemhtml .= $inputgrouptop;
202
+                    $itemhtml .= <<<SELECT
203
+\n                            <select class="form-control" name="$item[name]" aria-label="$strippedlabel" $required>
194 204
 SELECT;
195
-                foreach ($item['options'] as $value => $label) {
196
-                    $selected = "";
197
-                    if (!empty($item['value']) && $value == $item['value']) {
198
-                        $selected = " selected";
205
+                    foreach ($item['options'] as $value => $label) {
206
+                        $selected = "";
207
+                        if (!empty($item['value']) && $value == $item['value']) {
208
+                            $selected = " selected";
209
+                        }
210
+                        $itemhtml .= "\n                                <option value=\"$value\"$selected>$label</option>";
199 211
                     }
200
-                    $itemhtml .= "\n                                <option value=\"$value\"$selected>$label</option>";
201
-                }
202
-                $itemhtml .= "\n                            </select>";
212
+                    $itemhtml .= "\n                            </select>";
213
+                    break;
214
+                case "checkbox":
215
+                    $itemhtml .= $inputgrouptop;
216
+                    $itemhtml .= <<<CHECKBOX
217
+\n                            <div class="form-group form-check">
218
+                                <input type="checkbox" name="$item[name]" $id class="form-check-input" value="$item[value]" $required aria-label="$strippedlabel">
219
+                                <label class="form-check-label">$item[label]</label>
220
+                              </div>
221
+CHECKBOX;
222
+                    break;
223
+                case "textarea":
224
+                    $val = htmlentities($item['value']);
225
+                    $itemhtml .= <<<TEXTAREA
226
+\n                            <textarea class="form-control" id="info" name="$item[name]" aria-label="$strippedlabel" minlength="$item[minlength]" maxlength="$item[maxlength]" $required>$val</textarea>
227
+TEXTAREA;
228
+                    break;
229
+                default:
230
+                    $itemhtml .= $inputgrouptop;
231
+                    $itemhtml .= <<<INPUT
232
+\n                            <input type="$item[type]" name="$item[name]" $id class="form-control" aria-label="$strippedlabel" minlength="$item[minlength]" maxlength="$item[maxlength]" $pattern value="$item[value]" $required />
233
+INPUT;
234
+                    break;
203 235
             }
204 236
 
205 237
             if (!empty($item["error"])) {
@@ -209,9 +241,11 @@ SELECT;
209 241
                             </div>
210 242
 ERROR;
211 243
             }
244
+            if ($item["type"] != "textarea") {
245
+                $itemhtml .= "\n                                </div>";
246
+            }
212 247
             $itemhtml .= <<<ITEMBOTTOM
213
-\n                        </div>
214
-                    </div>
248
+\n                    </div>
215 249
                 </div>\n
216 250
 ITEMBOTTOM;
217 251
             $html .= $itemhtml;
@@ -224,7 +258,7 @@ ITEMBOTTOM;
224 258
 HTMLBOTTOM;
225 259
 
226 260
         if (!empty($this->buttons)) {
227
-            $html .= "\n        <div class=\"card-footer\">";
261
+            $html .= "\n        <div class=\"card-footer d-flex\">";
228 262
             foreach ($this->buttons as $btn) {
229 263
                 $btnhtml = "";
230 264
                 $inner = "<i class=\"$btn[icon]\"></i> $btn[text]";

+ 7
- 10
mobile/index.php View File

@@ -8,10 +8,6 @@
8 8
  * Mobile app API
9 9
  */
10 10
 
11
-// The name of the permission needed to log in.
12
-// Set to null if you don't need it.
13
-$access_permission = null;
14
-
15 11
 require __DIR__ . "/../required.php";
16 12
 
17 13
 header('Content-Type: application/json');
@@ -70,13 +66,14 @@ switch ($VARS['action']) {
70 66
         if ($user->exists()) {
71 67
             if ($user->getStatus()->getString() == "NORMAL") {
72 68
                 if ($user->checkPassword($VARS['password'])) {
73
-                    if (is_null($access_permission) || $user->hasPermission($access_permission)) {
74
-                        Session::start($user);
75
-                        $_SESSION['mobile'] = true;
76
-                        exit(json_encode(["status" => "OK"]));
77
-                    } else {
78
-                        exit(json_encode(["status" => "ERROR", "msg" => $Strings->get("no admin permission", false)]));
69
+                    foreach ($SETTINGS['permissions'] as $perm) {
70
+                        if (!$user->hasPermission($perm)) {
71
+                            exit(json_encode(["status" => "ERROR", "msg" => $Strings->get("no permission", false)]));
72
+                        }
79 73
                     }
74
+                    Session::start($user);
75
+                    $_SESSION['mobile'] = true;
76
+                    exit(json_encode(["status" => "OK"]));
80 77
                 }
81 78
             }
82 79
         }

+ 0
- 24
pages/form.php View File

@@ -1,24 +0,0 @@
1
-<?php
2
-
3
-/*
4
- * This Source Code Form is subject to the terms of the Mozilla Public
5
- * License, v. 2.0. If a copy of the MPL was not distributed with this
6
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7
- */
8
-
9
-/*
10
- * This file demonstrates creating a form with the FormBuilder class.
11
- */
12
-
13
-$form = new FormBuilder("Sample Form", "fas fa-code", "", "GET");
14
-
15
-$form->setID("sampleform");
16
-
17
-$form->addHiddenInput("page", "form");
18
-
19
-$form->addInput("name", "John", "text", true, null, null, "Your name", "fas fa-user", 6, 5, 20, "John(ny)?|Steve", "Invalid name, please enter John, Johnny, or Steve.");
20
-$form->addInput("location", "", "select", true, null, ["1" => "Here", "2" => "There"], "Location", "fas fa-map-marker");
21
-
22
-$form->addButton("Submit", "fas fa-save", null, "submit", "savebtn");
23
-
24
-$form->generate();

+ 17
- 1
required.php View File

@@ -131,11 +131,18 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
131 131
     define("GET", true);
132 132
 }
133 133
 
134
-
135 134
 function dieifnotloggedin() {
135
+    global $SETTINGS;
136 136
     if ($_SESSION['loggedin'] != true) {
137 137
         sendError("Session expired.  Please log out and log in again.");
138 138
     }
139
+    $user = new User($_SESSION['uid']);
140
+    foreach ($SETTINGS['permissions'] as $perm) {
141
+        if (!$user->hasPermission($perm)) {
142
+            session_destroy();
143
+            die("You don't have permission to be here.");
144
+        }
145
+    }
139 146
 }
140 147
 
141 148
 /**
@@ -156,8 +163,17 @@ function checkDBError($specials = []) {
156 163
 }
157 164
 
158 165
 function redirectIfNotLoggedIn() {
166
+    global $SETTINGS;
159 167
     if ($_SESSION['loggedin'] !== TRUE) {
160 168
         header('Location: ' . $SETTINGS['url'] . '/index.php');
161 169
         die();
162 170
     }
171
+    $user = new User($_SESSION['uid']);
172
+    foreach ($SETTINGS['permissions'] as $perm) {
173
+        if (!$user->hasPermission($perm)) {
174
+            session_destroy();
175
+            header('Location: ./index.php');
176
+            die("You don't have permission to be here.");
177
+        }
178
+    }
163 179
 }

+ 0
- 16
static/js/form.js View File

@@ -1,16 +0,0 @@
1
-/*
2
- * This Source Code Form is subject to the terms of the Mozilla Public
3
- * License, v. 2.0. If a copy of the MPL was not distributed with this
4
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
5
- */
6
-
7
-
8
-$("#savebtn").click(function (event) {
9
-    var form = $("#sampleform");
10
-
11
-    if (form[0].checkValidity() === false) {
12
-        event.preventDefault();
13
-        event.stopPropagation();
14
-    }
15
-    form.addClass('was-validated');
16
-});

Loading…
Cancel
Save