The base template for building the Netsyms Apps.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

app.php 9.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. <?php
  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. require_once __DIR__ . "/required.php";
  6. // If the SVG/JavaScript version of FontAwesome is needed
  7. // Increases overhead by a notable amount
  8. define("FONTAWESOME_USEJS", true);
  9. if ($_SESSION['loggedin'] != true) {
  10. header('Location: index.php');
  11. die("Session expired. Log in again to continue.");
  12. }
  13. require_once __DIR__ . "/pages.php";
  14. $pageid = "home";
  15. if (!empty($_GET['page'])) {
  16. $pg = strtolower($_GET['page']);
  17. $pg = preg_replace('/[^0-9a-z_]/', "", $pg);
  18. if (array_key_exists($pg, PAGES) && file_exists(__DIR__ . "/pages/" . $pg . ".php")) {
  19. $pageid = $pg;
  20. } else {
  21. $pageid = "404";
  22. }
  23. }
  24. header("Link: <static/img/logo.svg>; rel=preload; as=image", false);
  25. header("Link: <static/fonts/Roboto.css>; rel=preload; as=style", false);
  26. header("Link: <static/css/bootstrap.min.css>; rel=preload; as=style", false);
  27. header("Link: <static/css/material-color/material-color.min.css>; rel=preload; as=style", false);
  28. header("Link: <static/css/app.css>; rel=preload; as=style", false);
  29. if (FONTAWESOME_USEJS) {
  30. header("Link: <static/css/svg-with-js.min.css>; rel=preload; as=style", false);
  31. header("Link: <static/js/fontawesome-all.min.js>; rel=preload; as=script", false);
  32. } else {
  33. header("Link: <static/css/fontawesome-all.min.css>; rel=preload; as=style", false);
  34. }
  35. header("Link: <static/js/jquery-3.3.1.min.js>; rel=preload; as=script", false);
  36. header("Link: <static/js/bootstrap.bundle.min.js>; rel=preload; as=script", false);
  37. ?>
  38. <!DOCTYPE html>
  39. <html>
  40. <head>
  41. <meta charset="UTF-8">
  42. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  43. <meta name="viewport" content="width=device-width, initial-scale=1">
  44. <title><?php echo $SETTINGS['site_title']; ?></title>
  45. <link rel="icon" href="static/img/logo.svg" type="image/svg+xml">
  46. <link href="static/css/bootstrap.min.css" rel="stylesheet">
  47. <link href="static/css/material-color/material-color.min.css" rel="stylesheet">
  48. <link href="static/css/app.css" rel="stylesheet">
  49. <?php
  50. if (FONTAWESOME_USEJS) {
  51. ?>
  52. <link href="static/css/svg-with-js.min.css" rel="stylesheet">
  53. <script nonce="<?php echo $SECURE_NONCE; ?>">
  54. FontAwesomeConfig = {autoAddCss: false}
  55. </script>
  56. <script src="static/js/fontawesome-all.min.js"></script>
  57. <?php
  58. } else {
  59. ?>
  60. <link href="static/css/fontawesome-all.min.css" rel="stylesheet">
  61. <?php
  62. }
  63. ?>
  64. <?php
  65. // custom page styles
  66. if (isset(PAGES[$pageid]['styles'])) {
  67. foreach (PAGES[$pageid]['styles'] as $style) {
  68. echo "<link href=\"$style\" rel=\"stylesheet\">\n";
  69. header("Link: <$style>; rel=preload; as=style", false);
  70. }
  71. }
  72. ?>
  73. </head>
  74. <body>
  75. <?php
  76. // Alert messages
  77. if (!empty($_GET['msg'])) {
  78. if (array_key_exists($_GET['msg'], MESSAGES)) {
  79. // optional string generation argument
  80. if (empty($_GET['arg'])) {
  81. $alertmsg = $Strings->get(MESSAGES[$_GET['msg']]['string'], false);
  82. } else {
  83. $alertmsg = $Strings->build(MESSAGES[$_GET['msg']]['string'], ["arg" => strip_tags($_GET['arg'])], false);
  84. }
  85. $alerttype = MESSAGES[$_GET['msg']]['type'];
  86. $alerticon = "square-o";
  87. switch (MESSAGES[$_GET['msg']]['type']) {
  88. case "danger":
  89. $alerticon = "times";
  90. break;
  91. case "warning":
  92. $alerticon = "exclamation-triangle";
  93. break;
  94. case "info":
  95. $alerticon = "info-circle";
  96. break;
  97. case "success":
  98. $alerticon = "check";
  99. break;
  100. }
  101. } else {
  102. // We don't have a message for this, so just assume an error and escape stuff.
  103. $alertmsg = htmlentities($Strings->get($_GET['msg'], false));
  104. $alerticon = "times";
  105. $alerttype = "danger";
  106. }
  107. echo <<<END
  108. <div class="row justify-content-center" id="msg-alert-box">
  109. <div class="col-11 col-sm-6 col-md-5 col-lg-4 col-xl-4">
  110. <div class="alert alert-dismissible alert-$alerttype mt-2 p-0 border-0 shadow">
  111. <div class="p-2 pl-3">
  112. <button type="button" class="close">&times;</button>
  113. <i class="fas fa-$alerticon"></i> $alertmsg
  114. </div>
  115. <div class="progress">
  116. <div class="progress-bar bg-$alerttype w-0" id="msg-alert-timeout-bar"></div>
  117. </div>
  118. </div>
  119. </div>
  120. </div>
  121. END;
  122. }
  123. ?>
  124. <?php
  125. // Adjust as needed
  126. $navbar_breakpoint = "sm";
  127. // For mobile app
  128. echo "<script nonce=\"$SECURE_NONCE\">var navbar_breakpoint = \"$navbar_breakpoint\";</script>"
  129. ?>
  130. <nav class="navbar navbar-expand-<?php echo $navbar_breakpoint; ?> navbar-dark bg-blue fixed-top">
  131. <button class="navbar-toggler my-0 py-0" type="button" data-toggle="collapse" data-target="#navbar-collapse" aria-controls="navbar-collapse" aria-expanded="false" aria-label="Toggle navigation">
  132. <!--<i class="fas fa-bars"></i>-->
  133. <span class="navbar-toggler-icon"></span>
  134. </button>
  135. <a class="navbar-brand py-0 mr-auto" href="app.php">
  136. <img src="static/img/logo.svg" alt="" class="d-none d-<?php echo $navbar_breakpoint; ?>-inline brand-img py-0" />
  137. <?php echo $SETTINGS['site_title']; ?>
  138. </a>
  139. <div class="collapse navbar-collapse py-0" id="navbar-collapse">
  140. <div class="navbar-nav mr-auto py-0">
  141. <?php
  142. $curpagefound = false;
  143. foreach (PAGES as $id => $pg) {
  144. if (isset($pg['navbar']) && $pg['navbar'] === TRUE) {
  145. if ($pageid == $id) {
  146. $curpagefound = true;
  147. ?>
  148. <span class="nav-item py-<?php echo $navbar_breakpoint; ?>-0 active">
  149. <?php
  150. } else {
  151. ?>
  152. <span class="nav-item py-<?php echo $navbar_breakpoint; ?>-0">
  153. <?php
  154. }
  155. ?>
  156. <a class="nav-link py-<?php echo $navbar_breakpoint; ?>-0" href="app.php?page=<?php echo $id; ?>">
  157. <?php
  158. if (isset($pg['icon'])) {
  159. ?><i class="<?php echo $pg['icon']; ?> fa-fw"></i> <?php
  160. }
  161. $Strings->get($pg['title']);
  162. ?>
  163. </a>
  164. </span>
  165. <?php
  166. }
  167. }
  168. ?>
  169. </div>
  170. <div class="navbar-nav ml-auto py-0" id="navbar-right">
  171. <span class="nav-item py-<?php echo $navbar_breakpoint; ?>-0">
  172. <a class="nav-link py-<?php echo $navbar_breakpoint; ?>-0" href="<?php echo $SETTINGS['accounthub']['home']; ?>">
  173. <i class="fas fa-user fa-fw"></i><span>&nbsp;<?php echo $_SESSION['realname'] ?></span>
  174. </a>
  175. </span>
  176. <span class="nav-item mr-auto py-<?php echo $navbar_breakpoint; ?>-0">
  177. <a class="nav-link py-<?php echo $navbar_breakpoint; ?>-0" href="action.php?action=signout">
  178. <i class="fas fa-sign-out-alt fa-fw"></i><span>&nbsp;<?php $Strings->get("sign out") ?></span>
  179. </a>
  180. </span>
  181. </div>
  182. </div>
  183. </nav>
  184. <div class="container" id="main-content">
  185. <div>
  186. <?php
  187. include_once __DIR__ . '/pages/' . $pageid . ".php";
  188. ?>
  189. </div>
  190. <div class="footer">
  191. <?php echo $SETTINGS['footer_text']; ?><br />
  192. Copyright &copy; <?php echo date('Y'); ?> <?php echo $SETTINGS['copyright']; ?>
  193. </div>
  194. </div>
  195. <script src="static/js/jquery-3.3.1.min.js"></script>
  196. <script src="static/js/bootstrap.bundle.min.js"></script>
  197. <script src="static/js/app.js"></script>
  198. <?php
  199. // custom page scripts
  200. if (isset(PAGES[$pageid]['scripts'])) {
  201. foreach (PAGES[$pageid]['scripts'] as $script) {
  202. echo "<script src=\"$script\"></script>\n";
  203. header("Link: <$script>; rel=preload; as=script", false);
  204. }
  205. }
  206. ?>
  207. </body>
  208. </html>