index.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  1. <?php
  2. /*
  3. FusionPBX
  4. Version: MPL 1.1
  5. The contents of this file are subject to the Mozilla Public License Version
  6. 1.1 (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.mozilla.org/MPL/
  9. Software distributed under the License is distributed on an "AS IS" basis,
  10. WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  11. for the specific language governing rights and limitations under the
  12. License.
  13. The Original Code is FusionPBX
  14. The Initial Developer of the Original Code is
  15. Mark J Crane <[email protected]>
  16. Portions created by the Initial Developer are Copyright (C) 2022-2023
  17. the Initial Developer. All Rights Reserved.
  18. Contributor(s):
  19. Mark J Crane <[email protected]>
  20. */
  21. //includes files
  22. require_once dirname(__DIR__, 2) . "/resources/require.php";
  23. //if config.conf file does not exist then redirect to the install page
  24. if (file_exists("/usr/local/etc/fusionpbx/config.conf")){
  25. //BSD
  26. }
  27. elseif (file_exists("/etc/fusionpbx/config.conf")){
  28. //Linux
  29. }
  30. else {
  31. header("Location: /core/install/install.php");
  32. exit;
  33. }
  34. //additional includes
  35. require_once "resources/check_auth.php";
  36. //disable login message
  37. if (isset($_GET['msg']) && $_GET['msg'] == 'dismiss') {
  38. unset($_SESSION['login']['message']['text']);
  39. $sql = "update v_default_settings ";
  40. $sql .= "set default_setting_enabled = 'false' ";
  41. $sql .= "where ";
  42. $sql .= "default_setting_category = 'login' ";
  43. $sql .= "and default_setting_subcategory = 'message' ";
  44. $sql .= "and default_setting_name = 'text' ";
  45. $database = new database;
  46. $database->execute($sql);
  47. unset($sql);
  48. }
  49. //build a list of groups the user is a member of to be used in a SQL in
  50. if (is_array($_SESSION['user']['groups'])) {
  51. foreach($_SESSION['user']['groups'] as $group) {
  52. $group_uuids[] = $group['group_uuid'];
  53. }
  54. }
  55. if (is_array($group_uuids)) {
  56. $group_uuids_in = "'".implode("','", $group_uuids)."'";
  57. }
  58. //get the list
  59. $sql = "select \n";
  60. $sql .= "dashboard_uuid, \n";
  61. $sql .= "dashboard_name, \n";
  62. $sql .= "dashboard_path, \n";
  63. $sql .= "dashboard_column_span, \n";
  64. $sql .= "dashboard_details_state, \n";
  65. $sql .= "dashboard_order, \n";
  66. $sql .= "cast(dashboard_enabled as text), \n";
  67. $sql .= "dashboard_description \n";
  68. $sql .= "from v_dashboard as d \n";
  69. $sql .= "where dashboard_enabled = 'true' \n";
  70. $sql .= "and dashboard_uuid in (\n";
  71. $sql .= " select dashboard_uuid from v_dashboard_groups where group_uuid in (\n";
  72. $sql .= " ".$group_uuids_in." \n";
  73. $sql .= " )\n";
  74. $sql .= ")\n";
  75. $sql .= "order by dashboard_order asc \n";
  76. $database = new database;
  77. $dashboard = $database->select($sql, $parameters ?? null, 'all');
  78. unset($sql, $parameters);
  79. //get http post variables and set them to php variables
  80. if (count($_POST) > 0 && permission_exists('dashboard_edit')) {
  81. //set the variables from the http values
  82. if (isset($_POST["widget_order"])) {
  83. $widgets = explode(",", $_POST["widget_order"]);
  84. $dashboard_order = '0';
  85. $x = 0;
  86. foreach($widgets as $widget) {
  87. foreach($dashboard as $row) {
  88. $dashboard_name = strtolower($row['dashboard_name']);
  89. $dashboard_name = str_replace(" ", "_", $dashboard_name);
  90. if ($widget == $dashboard_name) {
  91. $dashboard_order = $dashboard_order + 10;
  92. $array['dashboard'][$x]['dashboard_name'] = $row['dashboard_name'];
  93. $array['dashboard'][$x]['dashboard_uuid'] = $row['dashboard_uuid'];
  94. $array['dashboard'][$x]['dashboard_order'] = $dashboard_order;
  95. $x++;
  96. }
  97. }
  98. }
  99. //save the data
  100. $database = new database;
  101. $database->app_name = 'dashboard';
  102. $database->app_uuid = '55533bef-4f04-434a-92af-999c1e9927f7';
  103. $database->save($array);
  104. //redirect the browser
  105. message::add($text['message-update']);
  106. header("Location: /core/dashboard/index.php");
  107. return;
  108. }
  109. }
  110. //add multi-lingual support
  111. $language = new text;
  112. $text = $language->get();
  113. //load the header
  114. $document['title'] = $text['title-dashboard'];
  115. require_once "resources/header.php";
  116. //include sortablejs
  117. echo "<script src='/resources/sortablejs/sortable.min.js'></script>";
  118. //include chart.js
  119. echo "<script src='/resources/chartjs/chart.min.js'></script>";
  120. //chart variables
  121. ?>
  122. <script>
  123. var chart_text_font = 'arial';
  124. var chart_text_size = '<?php echo $_SESSION['dashboard']['chart_text_size']['text']; ?>';
  125. var chart_text_color = '<?php echo $_SESSION['dashboard']['chart_text_color']['text']; ?>';
  126. var chart_cutout = '75%';
  127. const chart_counter = {
  128. id: 'chart_counter',
  129. beforeDraw(chart, args, options){
  130. const {ctx, chartArea: {top, right, bottom, left, width, height} } = chart;
  131. ctx.font = chart_text_size + 'px ' + chart_text_font;
  132. ctx.textBaseline = 'middle';
  133. ctx.textAlign = 'center';
  134. ctx.fillStyle = chart_text_color;
  135. ctx.fillText(options.chart_text, width / 2, top + (height / 2));
  136. ctx.save();
  137. }
  138. };
  139. const chart_counter_2 = {
  140. id: 'chart_counter_2',
  141. beforeDraw(chart, args, options){
  142. const {ctx, chartArea: {top, right, bottom, left, width, height} } = chart;
  143. ctx.font = (chart_text_size - 7) + 'px ' + chart_text_font;
  144. ctx.textBaseline = 'middle';
  145. ctx.textAlign = 'center';
  146. ctx.fillStyle = chart_text_color;
  147. ctx.fillText(options.chart_text + '%', width / 2, top + (height / 2) + 35);
  148. ctx.save();
  149. }
  150. };
  151. </script>
  152. <?php
  153. // determine initial state all button to display
  154. if (is_array($dashboard) && @sizeof($dashboard) != 0) {
  155. $expanded_all = true;
  156. foreach ($dashboard as $row) {
  157. if ($row['dashboard_details_state'] == 'contracted' || $row['dashboard_details_state'] == 'hidden') { $expanded_all = false; }
  158. }
  159. }
  160. //show the content
  161. echo "<form id='dashboard' method='post' _onsubmit='setFormSubmitting()'>\n";
  162. echo "<div class='action_bar' id='action_bar'>\n";
  163. echo " <div class='heading'><b>".$text['title-dashboard']."</b></div>\n";
  164. echo " <div class='actions'>\n";
  165. if ($_SESSION['theme']['menu_style']['text'] != 'side') {
  166. echo " ".$text['label-welcome']." <a href='".PROJECT_PATH."/core/users/user_edit.php?id=user'>".$_SESSION["username"]."</a>&nbsp; &nbsp;";
  167. }
  168. if (permission_exists('dashboard_edit')) {
  169. echo button::create(['type'=>'button','label'=>$text['button-back'],'icon'=>$_SESSION['theme']['button_icon_back'],'id'=>'btn_back','name'=>'btn_back','style'=>'display: none;','onclick'=>"edit_mode('off');"]);
  170. echo button::create(['type'=>'submit','label'=>$text['button-save'],'icon'=>$_SESSION['theme']['button_icon_save'],'id'=>'btn_save','name'=>'btn_save','style'=>'display: none; margin-left: 15px;']);
  171. }
  172. echo "<span id='expand_contract'>\n";
  173. echo button::create(['type'=>'button','label'=>$text['button-expand_all'],'icon'=>$_SESSION['theme']['button_icon_expand'],'id'=>'btn_expand','name'=>'btn_expand','style'=>($expanded_all ? 'display: none;' : null),'onclick'=>"$('.hud_details').slideDown('fast'); $(this).hide(); $('#btn_contract').show();"]);
  174. echo button::create(['type'=>'button','label'=>$text['button-collapse_all'],'icon'=>$_SESSION['theme']['button_icon_contract'],'id'=>'btn_contract','name'=>'btn_contract','style'=>(!$expanded_all ? 'display: none;' : null),'onclick'=>"$('.hud_details').slideUp('fast'); $(this).hide(); $('#btn_expand').show();"]);
  175. echo "</span>\n";
  176. if (permission_exists('dashboard_edit')) {
  177. echo button::create(['type'=>'button','label'=>$text['button-edit'],'icon'=>$_SESSION['theme']['button_icon_edit'],'id'=>'btn_edit','name'=>'btn_edit','style'=>'margin-left: 15px;','onclick'=>"edit_mode('on');"]);
  178. echo button::create(['type'=>'button','label'=>$text['button-settings'],'icon'=>$_SESSION['theme']['button_icon_add'],'id'=>'btn_add','name'=>'btn_add','link'=>'dashboard.php']);
  179. }
  180. echo " </div>\n";
  181. echo " <div style='clear: both; text-align: left;'>".$text['description-dashboard']."</div>\n";
  182. echo "</div>\n";
  183. echo "<input type='hidden' id='widget_order' name='widget_order' value='' />\n";
  184. echo "</form>\n";
  185. //display login message
  186. if (if_group("superadmin") && isset($_SESSION['login']['message']['text']) && $_SESSION['login']['message']['text'] != '') {
  187. echo "<div class='login_message' width='100%'><b>".$text['login-message_attention']."</b>&nbsp;&nbsp;".$_SESSION['login']['message']['text']."&nbsp;&nbsp;(<a href='?msg=dismiss'>".$text['login-message_dismiss']."</a>)</div>\n";
  188. }
  189. ?>
  190. <style>
  191. * {
  192. box-sizing: border-box;
  193. padding: 0;
  194. margin: 0;
  195. }
  196. .widget {
  197. /*background-color: #eee;*/
  198. cursor: pointer;
  199. }
  200. .widgets {
  201. max-width: 100%;
  202. margin: 0 auto;
  203. display: grid;
  204. grid-gap: 1rem;
  205. grid-column: auto;
  206. }
  207. /* Screen smaller than 575px? 1 columns */
  208. @media (max-width: 575px) {
  209. .widgets { grid-template-columns: repeat(1, minmax(100px, 1fr)); }
  210. .col-num { grid-column: span 1; }
  211. <?php
  212. foreach($dashboard as $row) {
  213. $dashboard_name = strtolower($row['dashboard_name']);
  214. $dashboard_name = str_replace(" ", "_", $dashboard_name);
  215. if (isset($dashboard_column_span) && is_numeric($dashboard_column_span)) {
  216. echo "#".$dashboard_name." {\n";
  217. echo " grid-column: span 1;\n";
  218. echo "}\n";
  219. }
  220. }
  221. ?>
  222. }
  223. /* Screen larger than 575px? 2 columns */
  224. @media (min-width: 575px) {
  225. .widgets { grid-template-columns: repeat(2, minmax(100px, 1fr)); }
  226. .col-num { grid-column: span 2; }
  227. <?php
  228. foreach($dashboard as $row) {
  229. $dashboard_name = strtolower($row['dashboard_name']);
  230. $dashboard_name = str_replace(" ", "_", $dashboard_name);
  231. $dashboard_column_span = 1;
  232. if (is_numeric($dashboard_column_span)) {
  233. if ($row['dashboard_column_span'] > 2) {
  234. $dashboard_column_span = 2;
  235. }
  236. echo "#".$dashboard_name." {\n";
  237. echo " grid-column: span ".$dashboard_column_span.";\n";
  238. echo "}\n";
  239. }
  240. if ($row['dashboard_details_state'] == "contracted") {
  241. echo "#".$dashboard_name." .hud_box .hud_details {\n";
  242. echo " display: none;\n";
  243. echo "}\n";
  244. }
  245. if ($row['dashboard_details_state'] == "hidden") {
  246. echo "#".$dashboard_name." .hud_box .hud_expander, \n";
  247. echo "#".$dashboard_name." .hud_box .hud_details {\n";
  248. echo " display: none;\n";
  249. echo "}\n";
  250. }
  251. }
  252. ?>
  253. }
  254. /* Screen larger than 1300px? 3 columns */
  255. @media (min-width: 1300px) {
  256. .widgets { grid-template-columns: repeat(3, minmax(100px, 1fr)); }
  257. .col-num { grid-column: span 2; }
  258. <?php
  259. foreach($dashboard as $row) {
  260. $dashboard_name = strtolower($row['dashboard_name']);
  261. $dashboard_name = str_replace(" ", "_", $dashboard_name);
  262. $dashboard_column_span = $row['dashboard_column_span'];
  263. if (is_numeric($dashboard_column_span)) {
  264. echo "#".$dashboard_name." {\n";
  265. echo " grid-column: span ".$dashboard_column_span.";\n";
  266. echo "}\n";
  267. }
  268. }
  269. ?>
  270. }
  271. /* Screen larger than 1500px? 4 columns */
  272. @media (min-width: 1500px) {
  273. .widgets { grid-template-columns: repeat(4, minmax(100px, 1fr)); }
  274. .col-num { grid-column: span 2; }
  275. }
  276. /* Screen larger than 2000px? 5 columns */
  277. @media (min-width: 2000px) {
  278. .widgets { grid-template-columns: repeat(5, minmax(100px, 1fr)); }
  279. .col-num { grid-column: span 2; }
  280. }
  281. </style>
  282. <?php
  283. //include the dashboards
  284. echo "<div class='widgets' id='widgets' style='padding: 0 5px;'>\n";
  285. $x = 0;
  286. foreach($dashboard as $row) {
  287. $dashboard_name = strtolower($row['dashboard_name']);
  288. $dashboard_name = str_replace(" ", "_", $dashboard_name);
  289. echo "<div class='widget' id='".$dashboard_name."' draggable='false'>\n";
  290. include($row['dashboard_path']);
  291. echo "</div>\n";
  292. $x++;
  293. }
  294. echo "</div>\n";
  295. //begin edit
  296. if (permission_exists('dashboard_edit')) {
  297. ?>
  298. <style>
  299. /*To prevent user selecting inside the drag source*/
  300. [draggable] {
  301. -moz-user-select: none;
  302. -khtml-user-select: none;
  303. -webkit-user-select: none;
  304. user-select: none;
  305. }
  306. div.widget.editable {
  307. cursor: move;
  308. }
  309. .hud_box.editable {
  310. transition: 0.2s;
  311. border: 1px dashed rgba(0,0,0,0.4);
  312. }
  313. .hud_box.editable:hover {
  314. box-shadow: 0 5px 10px rgba(0,0,0,0.2);
  315. border: 1px dashed rgba(0,0,0,0.4);
  316. transform: scale(1.03, 1.03);
  317. transition: 0.2s;
  318. }
  319. .hud_box .hud_box.editable:hover {
  320. box-shadow: none;
  321. transform: none;
  322. }
  323. .ghost {
  324. border: 2px dashed rgba(0,0,0,1);
  325. <?php $br = format_border_radius($_SESSION['theme']['dashboard_border_radius']['text'] ?? null, '5px'); ?>
  326. -webkit-border-radius: <?php echo $br['tl']['n'].$br['tl']['u']; ?> <?php echo $br['tr']['n'].$br['tr']['u']; ?> <?php echo $br['br']['n'].$br['br']['u']; ?> <?php echo $br['bl']['n'].$br['bl']['u']; ?>;
  327. -moz-border-radius: <?php echo $br['tl']['n'].$br['tl']['u']; ?> <?php echo $br['tr']['n'].$br['tr']['u']; ?> <?php echo $br['br']['n'].$br['br']['u']; ?> <?php echo $br['bl']['n'].$br['bl']['u']; ?>;
  328. border-radius: <?php echo $br['tl']['n'].$br['tl']['u']; ?> <?php echo $br['tr']['n'].$br['tr']['u']; ?> <?php echo $br['br']['n'].$br['br']['u']; ?> <?php echo $br['bl']['n'].$br['bl']['u']; ?>;
  329. <?php unset($br); ?>
  330. opacity: 0.2;
  331. }
  332. </style>
  333. <script>
  334. var widgets = document.getElementById('widgets');
  335. var sortable;
  336. //make widgets draggable
  337. function edit_mode(state) {
  338. if (state == 'on') {
  339. $('span#expand_contract, #btn_edit, #btn_add').hide();
  340. $('.hud_box').addClass('editable');
  341. $('#btn_back, #btn_save').show();
  342. $('div.widget').attr('draggable',true).addClass('editable');
  343. sortable = Sortable.create(widgets, {
  344. animation: 150,
  345. draggable: ".widget",
  346. preventOnFilter: true,
  347. ghostClass: 'ghost',
  348. onSort: function (evt) {
  349. let widget_ids = document.querySelectorAll("#widgets > div[id]");
  350. let widget_ids_list = [];
  351. for (let i = 0; i < widget_ids.length; i++) {
  352. widget_ids_list.push(widget_ids[i].id);
  353. }
  354. document.getElementById('widget_order').value = widget_ids_list;
  355. },
  356. });
  357. // set initial widget order
  358. let widget_ids = document.querySelectorAll("#widgets > div[id]");
  359. let widget_ids_list = [];
  360. for (let i = 0; i < widget_ids.length; i++) {
  361. widget_ids_list.push(widget_ids[i].id);
  362. }
  363. document.getElementById('widget_order').value = widget_ids_list;
  364. }
  365. else { // off
  366. $('div.widget').attr('draggable',false).removeClass('editable');
  367. $('.hud_box').removeClass('editable');
  368. $('#btn_back, #btn_save').hide();
  369. $('span#expand_contract, #btn_edit, #btn_add').show();
  370. sortable.option('disabled', true);
  371. }
  372. }
  373. </script>
  374. <?php
  375. } //end edit
  376. //show the footer
  377. require_once "resources/footer.php";
  378. ?>