diff --git a/src/www/fbegin.inc b/src/www/fbegin.inc
index daaae9490..99d7ee9d7 100644
--- a/src/www/fbegin.inc
+++ b/src/www/fbegin.inc
@@ -194,7 +194,7 @@ if($need_alert_display == true) {
=$button['label'];?>
-
+
=gettext("Save Settings");?>
diff --git a/src/www/foot.inc b/src/www/foot.inc
index 6bd6f4b29..b35e25a72 100644
--- a/src/www/foot.inc
+++ b/src/www/foot.inc
@@ -11,51 +11,44 @@
-
+ foreach($widgetCollection as $widgetItem):
+ $widgettitle = $widgetItem['name'] . "_title";
+ $widgettitlelink = $widgetItem['name'] . "_title_link";
+ if (isset($$widgettitle)):?>
- | =$$widgettitle; ?> |
+ ")'>=$$widgettitle; ?> |
+ elseif (!empty($widgetItem['display_name'])): ?>
- | =$nicename; ?> |
+ ")'>=$widgetItem['display_name']; ?> |
+ endif;
+ endforeach; ?>
diff --git a/src/www/index.php b/src/www/index.php
index 7a810b1bb..efb4149c4 100644
--- a/src/www/index.php
+++ b/src/www/index.php
@@ -35,240 +35,79 @@ ini_set('output_buffering', 'true');
ob_start(null, "1000");
-## Load Essential Includes
+// Load Essential Includes
require_once('guiconfig.inc');
+// closing should be $_POST, but the whole notice handling needs more attention. Leave it as is for now.
if (isset($_REQUEST['closenotice'])) {
close_notice($_REQUEST['closenotice']);
echo get_menu_messages();
exit;
}
-##build list of widgets
-$directory = "/usr/local/www/widgets/widgets/";
-$dirhandle = opendir($directory);
-$filename = "";
-$widgetnames = array();
-$widgetfiles = array();
-$widgetlist = array();
-
-while (false !== ($filename = readdir($dirhandle))) {
- $periodpos = strpos($filename, ".");
- /* Ignore files not ending in .php */
- if (substr($filename, -4, 4) != ".php") {
- continue;
- }
- $widgetname = substr($filename, 0, $periodpos);
- $widgetnames[] = $widgetname;
- if ($widgetname != "system_information") {
- $widgetfiles[] = $filename;
- }
-}
-
-##sort widgets alphabetically
-sort($widgetfiles);
-
-##insert the system information widget as first, so as to be displayed first
-array_unshift($widgetfiles, "system_information.widget.php");
-
##if no config entry found, initialize config entry
if (empty($config['widgets']) || !is_array($config['widgets'])) {
$config['widgets'] = array();
}
-if ($_POST && $_POST['sequence']) {
- $config['widgets']['sequence'] = $_POST['sequence'];
-
- foreach ($widgetnames as $widget) {
- if ($_POST[$widget . '-config']) {
- $config['widgets'][$widget . '-config'] = $_POST[$widget . '-config'];
- }
+if ($_SERVER['REQUEST_METHOD'] === 'GET') {
+ $pconfig = $config['widgets'];
+ if (empty($pconfig['sequence'])) {
+ // set default dashboard view
+ $pconfig['sequence'] = 'system_information-container:col1:show,interface_list-container:col1:show,traffic_graphs-container:col1:show';
+ }
+ ##build list of widgets
+ $widgetCollection = array();
+ $widgetSeqParts = explode(",", $pconfig['sequence']);
+ foreach (glob('/usr/local/www/widgets/widgets/*.widget.php') as $php_file) {
+ $widgetItem = array();
+ $widgetItem['name'] = basename($php_file, '.widget.php');
+ $widgetItem['display_name'] = ucwords(str_replace("_", " ", $widgetItem['name']));
+ $widgetItem['filename'] = $php_file;
+ $widgetItem['state'] = "none";
+ $widgetItem['sortKey'] = $widgetItem['name'] == 'system_information' ? "" : $widgetItem['name'];
+ foreach ($widgetSeqParts as $seqPart) {
+ $tmp = explode(':', $seqPart);
+ if (count($tmp) == 3 && explode('-', $tmp[0])[0] == $widgetItem['name']) {
+ $widgetItem['state'] = $tmp[2];
+ }
+ }
+ $widgetCollection[] = $widgetItem;
+ }
+ // sort widgets
+ usort($widgetCollection, function ($item1, $item2) {
+ return strcmp(strtolower($item1['sortKey']), strtolower($item2['sortKey']));
+ });
+} elseif ($_SERVER['REQUEST_METHOD'] === 'POST') {
+ if (!empty($_POST['sequence'])) {
+ $config['widgets']['sequence'] = $_POST['sequence'];
+ write_config(gettext("Widget configuration has been changed."));
}
-
- write_config(gettext("Widget configuration has been changed."));
header("Location: index.php");
exit;
}
-## Check to see if we have a swap space,
-## if true, display, if false, hide it ...
-if (file_exists('/usr/sbin/swapinfo')) {
- $swapinfo = `/usr/sbin/swapinfo`;
- if (stristr($swapinfo, '%')) {
- $showswap = true;
- }
-}
-
-##build widget saved list information
-if ($config['widgets'] && $config['widgets']['sequence'] != "") {
- $pconfig['sequence'] = $config['widgets']['sequence'];
-
- $widgetlist = $pconfig['sequence'];
- $colpos = array();
- $savedwidgetfiles = array();
- $widgetname = "";
- $widgetlist = explode(",", $widgetlist);
-
- ##read the widget position and display information
- foreach ($widgetlist as $widget) {
- $dashpos = strpos($widget, "-");
- $widgetname = substr($widget, 0, $dashpos);
- if (!in_array($widgetname, $widgetnames)) {
- continue;
- }
- $colposition = strpos($widget, ":");
- $displayposition = strrpos($widget, ":");
- $colpos[] = substr($widget, $colposition+1, $displayposition - $colposition-1);
- $displayarray[] = substr($widget, $displayposition+1);
- $savedwidgetfiles[] = $widgetname . ".widget.php";
- }
-
- ##add widgets that may not be in the saved configuration, in case they are to be displayed later
- foreach ($widgetfiles as $defaultwidgets) {
- if (!in_array($defaultwidgets, $savedwidgetfiles)) {
- $savedwidgetfiles[] = $defaultwidgets;
- }
- }
-
- ##find custom configurations of a particular widget and load its info to $pconfig
- foreach ($widgetnames as $widget) {
- if (isset($config['widgets'][$widget . '-config'])) {
- $pconfig[$widget . '-config'] = $config['widgets'][$widget . '-config'];
- }
- }
-
- $widgetlist = $savedwidgetfiles;
-} else {
- // no saved widget sequence found, build default list.
- $widgetlist = $widgetfiles;
-}
-
-
-
-##build list of php include files
-$phpincludefiles = array();
-$directory = "/usr/local/www/widgets/include/";
-$dirhandle = opendir($directory);
-$filename = "";
-while (false !== ($filename = readdir($dirhandle))) {
- $phpincludefiles[] = $filename;
-}
-foreach ($phpincludefiles as $includename) {
- if (!stristr($includename, ".inc")) {
- continue;
- }
- include($directory . $includename);
+// handle widget includes
+foreach (glob("/usr/local/www/widgets/include/*.inc") as $filename) {
+ include($filename);
}
include("head.inc");
-
?>
-
-
+include("fbegin.inc");?>
+ ## If it is the first time webConfigurator has been
+ ## accessed since initial install show this stuff.
+ if (isset($config['trigger_initial_wizard'])) :?>
+
= gettext("Starting initial configuration!") ?>
@@ -298,10 +137,68 @@ if (isset($config['trigger_initial_wizard'])) :
-
+ // normal dashboard
+ else:?>
+
+
@@ -311,104 +208,46 @@ endif; ?>
print_info_box($crash_report);
}
- $totalwidgets = count($widgetfiles);
- $halftotal = $totalwidgets / 2 - 2;
- $widgetcounter = 0;
- $directory = "/usr/local/www/widgets/widgets/";
- $printed = false;
- $firstprint = false;
-
- foreach ($widgetlist as $widget) {
- if (!stristr($widget, "widget.php")) {
- continue;
- }
- $periodpos = strpos($widget, ".");
- $widgetname = substr($widget, 0, $periodpos);
- if ($widgetname != "") {
- $nicename = $widgetname;
- $nicename = str_replace("_", " ", $nicename);
-
- //make the title look nice
- $nicename = ucwords($nicename);
- }
-
- if (isset($config['widgets']) && isset($pconfig['sequence'])) {
- if (isset($displayarray[$widgetcounter])) {
- $disparr = $displayarray[$widgetcounter];
- } else {
- $disparr = null;
- }
- switch($disparr){
- case "show":
- $divdisplay = "block";
- $display = "block";
- $inputdisplay = "show";
- $showWidget = "none";
- $mindiv = "inline";
- break;
- case "hide":
- $divdisplay = "block";
- $display = "none";
- $inputdisplay = "hide";
- $showWidget = "inline";
- $mindiv = "none";
- break;
- case "close":
- $divdisplay = "none";
- $display = "block";
- $inputdisplay = "close";
- $showWidget = "none";
- $mindiv = "inline";
- break;
- default:
- $divdisplay = "none";
- $display = "block";
- $inputdisplay = "none";
- $showWidget = "none";
- $mindiv = "inline";
- break;
- }
- } else {
- if ($firstprint == false) {
+ foreach ($widgetCollection as $widgetItem):
+ $widgettitle = $widgetItem['name'] . "_title";
+ $widgettitlelink = $widgetItem['name'] . "_title_link";
+ switch ($widgetItem['state']) {
+ case "show":
$divdisplay = "block";
$display = "block";
$inputdisplay = "show";
- $showWidget = "none";
$mindiv = "inline";
- $firstprint = true;
- } else {
- switch ($widget) {
- case "interface_list.widget.php":
- case "traffic_graphs.widget.php":
- $divdisplay = "block";
- $display = "block";
- $inputdisplay = "show";
- $showWidget = "none";
- $mindiv = "inline";
- break;
- default:
- $divdisplay = "none";
- $display = "block";
- $inputdisplay = "close";
- $showWidget = "none";
- $mindiv = "inline";
- break;
- }
- }
+ break;
+ case "hide":
+ $divdisplay = "block";
+ $display = "none";
+ $inputdisplay = "hide";
+ $mindiv = "none";
+ break;
+ case "close":
+ $divdisplay = "none";
+ $display = "block";
+ $inputdisplay = "close";
+ $mindiv = "inline";
+ break;
+ default:
+ $divdisplay = "none";
+ $display = "block";
+ $inputdisplay = "none";
+ $mindiv = "inline";
+ break;
}?>
-