Browse Source

Add appid column to notifications table, remove unused code

tags/v2.0
Skylar Ittner 10 months ago
parent
commit
1a01f67662
4 changed files with 8 additions and 110 deletions
  1. 0
    105
      apps/sync_mobile.php
  2. BIN
      database.mwb
  3. 2
    0
      database.sql
  4. 6
    5
      database_upgrade/1.0.1_2.0.sql

+ 0
- 105
apps/sync_mobile.php View File

@@ -1,105 +0,0 @@
1
-<?php
2
-
3
-/* This Source Code Form is subject to the terms of the Mozilla Public
4
- * License, v. 2.0. If a copy of the MPL was not distributed with this
5
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
-
7
-dieifnotloggedin();
8
-
9
-use Endroid\QrCode\ErrorCorrectionLevel;
10
-use Endroid\QrCode\QrCode;
11
-
12
-if (MOBILE_ENABLED) {
13
-
14
-    $APPS["sync_mobile"]["title"] = $Strings->get("sync mobile", false);
15
-    $APPS["sync_mobile"]["icon"] = "mobile";
16
-
17
-    if (!is_empty($_GET['delsynccode'])) {
18
-        if ($database->has("mobile_codes", ["AND" => ["uid" => $_SESSION['uid'], "codeid" => $_GET['delsynccode']]])) {
19
-            $database->delete("mobile_codes", ["AND" => ["uid" => $_SESSION['uid'], "codeid" => $_GET['delsynccode']]]);
20
-        }
21
-    }
22
-
23
-    if ($_GET['mobilecode'] == "generate") {
24
-        if (!is_empty($_GET['showsynccode']) && $database->has("mobile_codes", ["AND" => ["uid" => $_SESSION['uid'], "codeid" => $_GET['showsynccode']]])) {
25
-            $code = $database->get("mobile_codes", 'code', ["AND" => ["uid" => $_SESSION['uid'], "codeid" => $_GET['showsynccode']]]);
26
-        } else {
27
-            $code = strtoupper(substr(md5(mt_rand() . uniqid("", true)), 0, 20));
28
-            $database->insert('mobile_codes', ['uid' => $_SESSION['uid'], 'code' => $code]);
29
-        }
30
-        if (strpos(URL, "http") !== FALSE) {
31
-            $url = URL . "mobile/index.php";
32
-        } else {
33
-            $url = (isset($_SERVER['HTTPS']) ? "https" : "http") . "://" . $_SERVER['HTTP_HOST'] . (($_SERVER['SERVER_PORT'] != 80 && $_SERVER['SERVER_PORT'] != 443) ? ":" . $_SERVER['SERVER_PORT'] : "") . URL . "mobile/index.php";
34
-        }
35
-        $encodedurl = str_replace("/", "\\", $url);
36
-        $codeuri = "bizsync://" . $encodedurl . "/" . $_SESSION['username'] . "/" . $code;
37
-        $qrCode = new QrCode($codeuri);
38
-        $qrCode->setWriterByName('svg');
39
-        $qrCode->setSize(550);
40
-        $qrCode->setErrorCorrectionLevel(ErrorCorrectionLevel::HIGH);
41
-        $qrcode = $qrCode->writeDataUri();
42
-        $chunk_code = trim(chunk_split($code, 5, ' '));
43
-        $lang_done = $Strings->get("done adding sync code", false);
44
-        $APPS["sync_mobile"]["content"] = '<div class="alert alert-info"><i class="fa fa-info-circle"></i> '
45
-                . $Strings->get("scan sync qrcode", false)
46
-                . '</div>'
47
-                . <<<END
48
-<style nonce="$SECURE_NONCE">
49
-.margintop-15px {
50
-    margin-top: 15px;
51
-}
52
-.mono-chunk {
53
-    text-align: center;
54
-    font-size: 110%;
55
-    font-family: monospace;
56
-}
57
-</style>
58
-<img src="$qrcode" class="img-responsive qrcode" />
59
-<div class="panel panel-default margintop-15px">
60
-<div class="panel-body">
61
-END
62
-                . "<b>" . $Strings->get("manual setup", false) . "</b><br /><label>" . $Strings->get("username", false) . ":</label>"
63
-                . '<div class="well well-sm mono-chunk">' . $_SESSION['username'] . '</div>'
64
-                . "<label>" . $Strings->get("sync key", false) . "</label>"
65
-                . <<<END
66
-<div class="well well-sm mono-chunk">$chunk_code</div>
67
-END
68
-                . "<label>" . $Strings->get("url", false) . "</label>"
69
-                . <<<END
70
-<div class="well well-sm mono-chunk">$url</div>
71
-</div>
72
-</div>
73
-<a class="btn btn-success btn-sm btn-block" href="home.php?page=sync">$lang_done</a>
74
-END;
75
-    } else {
76
-        $activecodes = $database->select("mobile_codes", ["codeid", "code"], ["uid" => $_SESSION['uid']]);
77
-        $content = '<div class="alert alert-info"><i class="fa fa-info-circle"></i> ' . $Strings->get("sync explained", false) . '</div>'
78
-                . '<a class="btn btn-success btn-sm btn-block" href="home.php?page=sync&mobilecode=generate">'
79
-                . $Strings->get("generate sync", false) . '</a>';
80
-        $content .= "<br /><b>" . $Strings->get("active sync codes", false) . ":</b><br />";
81
-        $content .= "<div class='list-group'>";
82
-        if (count($activecodes) > 0) {
83
-            foreach ($activecodes as $c) {
84
-                $content .= "<div class='list-group-item mobilekey'><span id=\"mobilecode\">" . trim(chunk_split($c['code'], 5, ' ')) . "</span> <span class='tinybuttons'><a class='btn btn-primary btn-sm' href='home.php?page=sync&mobilecode=generate&showsynccode=" . $c['codeid'] . "'><i class='fa fa-qrcode'></i></a> <a class='btn btn-danger btn-sm' href='home.php?page=sync&delsynccode=" . $c['codeid'] . "'><i class='fa fa-trash'></i></a></span></div>";
85
-            }
86
-        } else {
87
-            $content .= "<div class='list-group-item'>" . $Strings->get("no active codes", false) . "</div>";
88
-        }
89
-        $content .= "</div>";
90
-        $content .= <<<END
91
-            <style nonce="$SECURE_NONCE">
92
-                .mobilekey {
93
-                    display: flex;
94
-                    flex-wrap: wrap;
95
-                    justify-content: space-between;
96
-                }
97
-                .mobilekey #mobilecode {
98
-                    font-family: Ubuntu Mono,monospace;
99
-                    flex-shrink: 0;
100
-                }
101
-            </style>
102
-END;
103
-        $APPS["sync_mobile"]["content"] = $content;
104
-    }
105
-}

BIN
database.mwb View File


+ 2
- 0
database.sql View File

@@ -1,5 +1,5 @@
1 1
 -- MySQL Script generated by MySQL Workbench
2
+-- Sat 28 Jul 2018 03:55:27 PM MDT
2 3
 -- Model: New Model    Version: 1.0
3 4
 -- MySQL Workbench Forward Engineering
4 5
 
@@ -301,6 +301,7 @@ CREATE TABLE IF NOT EXISTS `notifications` (
301 301
   `url` VARCHAR(255) NOT NULL,
302 302
   `seen` TINYINT(1) NOT NULL DEFAULT 0,
303 303
   `sensitive` TINYINT(1) NOT NULL,
304
+  `appid` VARCHAR(255) NULL,
304 305
   PRIMARY KEY (`notificationid`, `uid`),
305 306
   UNIQUE INDEX `notificationid_UNIQUE` (`notificationid` ASC),
306 307
   INDEX `fk_notifications_accounts1_idx` (`uid` ASC),

+ 6
- 5
database_upgrade/1.0.1_2.0.sql View File

@@ -14,24 +14,25 @@ ENGINE = InnoDB
14 14
 DEFAULT CHARACTER SET = utf8;
15 15
 
16 16
 CREATE TABLE IF NOT EXISTS `notifications` (
17
-  `notificationid` INT(11) NOT NULL AUTO_INCREMENT,
18
-  `uid` INT(11) NOT NULL,
17
+  `notificationid` INT NOT NULL AUTO_INCREMENT,
18
+  `uid` INT NOT NULL,
19 19
   `timestamp` DATETIME NOT NULL,
20 20
   `title` VARCHAR(255) NOT NULL,
21 21
   `content` TINYTEXT NOT NULL,
22 22
   `url` VARCHAR(255) NOT NULL,
23 23
   `seen` TINYINT(1) NOT NULL DEFAULT 0,
24
-  `sensitive` TINYINT(1) NOT NULL DEFAULT 0,
24
+  `sensitive` TINYINT(1) NOT NULL,
25
+  `appid` VARCHAR(255) NULL,
25 26
   PRIMARY KEY (`notificationid`, `uid`),
26 27
   UNIQUE INDEX `notificationid_UNIQUE` (`notificationid` ASC),
27 28
   INDEX `fk_notifications_accounts1_idx` (`uid` ASC),
28 29
   CONSTRAINT `fk_notifications_accounts1`
29 30
     FOREIGN KEY (`uid`)
30
-    REFERENCES `accounthub`.`accounts` (`uid`)
31
+    REFERENCES `accounts` (`uid`)
31 32
     ON DELETE NO ACTION
32 33
     ON UPDATE NO ACTION)
33 34
 ENGINE = InnoDB
34
-DEFAULT CHARACTER SET = utf8
35
+DEFAULT CHARACTER SET = utf8;
35 36
 
36 37
 
37 38
 SET FOREIGN_KEY_CHECKS = 0;

Loading…
Cancel
Save