Project

General

Profile

Download (22.3 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
 * index.php
4
 *
5
 * part of pfSense (https://www.pfsense.org)
6
 * Copyright (c) 2004-2016 Rubicon Communications, LLC (Netgate)
7
 * All rights reserved.
8
 *
9
 * originally based on m0n0wall (http://m0n0.ch/wall)
10
 * Copyright (c) 2003-2004 Manuel Kasper <mk@neon1.net>.
11
 * All rights reserved.
12
 *
13
 * Licensed under the Apache License, Version 2.0 (the "License");
14
 * you may not use this file except in compliance with the License.
15
 * You may obtain a copy of the License at
16
 *
17
 * http://www.apache.org/licenses/LICENSE-2.0
18
 *
19
 * Unless required by applicable law or agreed to in writing, software
20
 * distributed under the License is distributed on an "AS IS" BASIS,
21
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22
 * See the License for the specific language governing permissions and
23
 * limitations under the License.
24
 */
25

    
26
##|+PRIV
27
##|*IDENT=page-system-login-logout
28
##|*NAME=System: Login / Logout / Dashboard
29
##|*DESCR=Allow access to the 'System: Login / Logout' page and Dashboard.
30
##|*MATCH=index.php*
31
##|-PRIV
32

    
33
// Turn on buffering to speed up rendering
34
ini_set('output_buffering', 'true');
35

    
36
// Start buffering with a cache size of 100000
37
ob_start(null, "1000");
38

    
39
## Load Essential Includes
40
require_once('guiconfig.inc');
41
require_once('functions.inc');
42
require_once('notices.inc');
43
require_once("pkg-utils.inc");
44

    
45
if (isset($_POST['closenotice'])) {
46
	close_notice($_POST['closenotice']);
47
	sleep(1);
48
	exit;
49
}
50

    
51
if (isset($_REQUEST['closenotice'])) {
52
	close_notice($_REQUEST['closenotice']);
53
	sleep(1);
54
}
55

    
56
if ($g['disablecrashreporter'] != true) {
57
	// Check to see if we have a crash report
58
	$x = 0;
59
	if (file_exists("/tmp/PHP_errors.log")) {
60
		$total = `/bin/cat /tmp/PHP_errors.log | /usr/bin/wc -l | /usr/bin/awk '{ print $1 }'`;
61
		if ($total > 0) {
62
			$x++;
63
		}
64
	}
65

    
66
	$crash = glob("/var/crash/*");
67
	$skip_files = array(".", "..", "minfree", "");
68

    
69
	if (is_array($crash)) {
70
		foreach ($crash as $c) {
71
			if (!in_array(basename($c), $skip_files)) {
72
				$x++;
73
			}
74
		}
75

    
76
		if ($x > 0) {
77
			$savemsg = sprintf(gettext("%s has detected a crash report or programming bug."), $g['product_name']) . " ";
78
			if (isAllowedPage("/crash_reporter.php")) {
79
				$savemsg .= sprintf(gettext('Click %1$shere%2$s for more information.'), '<a href="crash_reporter.php">', '</a>');
80
			} else {
81
				$savemsg .= sprintf(gettext("Contact a firewall administrator for more information."));
82
			}
83
			$class = "warning";
84
		}
85
	}
86
}
87

    
88
## Include each widget php include file.
89
## These define vars that specify the widget title and title link.
90

    
91
$directory = "/usr/local/www/widgets/include/";
92
$dirhandle = opendir($directory);
93
$filename = "";
94

    
95
while (($filename = readdir($dirhandle)) !== false) {
96
	if (strtolower(substr($filename, -4)) == ".inc" && file_exists($directory . $filename)) {
97
		include_once($directory . $filename);
98
	}
99
}
100

    
101
##build list of widgets
102
foreach (glob("/usr/local/www/widgets/widgets/*.widget.php") as $file) {
103
	$basename = basename($file, '.widget.php');
104
	// Get the widget title that should be in a var defined in the widget's inc file.
105
	$widgettitle = ${$basename . '_title'};
106

    
107
	if (empty(trim($widgettitle))) {
108
		// Fall back to constructing a title from the file name of the widget.
109
		$widgettitle = ucwords(str_replace('_', ' ', $basename));
110
	}
111

    
112
	$known_widgets[$basename . '-0'] = array(
113
		'basename' => $basename,
114
		'title' => $widgettitle,
115
		'display' => 'none',
116
		'multicopy' => ${$basename . '_allow_multiple_widget_copies'}
117
	);
118
}
119

    
120
##if no config entry found, initialize config entry
121
if (!is_array($config['widgets'])) {
122
	$config['widgets'] = array();
123
}
124

    
125
if (!is_array($user_settings['widgets'])) {
126
	$user_settings['widgets'] = array();
127
}
128

    
129
if ($_POST && $_POST['sequence']) {
130

    
131
	// Start with the user's widget settings.
132
	$widget_settings = $user_settings['widgets'];
133

    
134
	$widget_sep = ',';
135
	$widget_seq_array = explode($widget_sep, rtrim($_POST['sequence'], $widget_sep));
136
	$widget_counter_array = array();
137
	$widget_sep = '';
138

    
139
	// Make a record of the counter of each widget that is in use.
140
	foreach ($widget_seq_array as $widget_seq_data) {
141
		list($basename, $col, $display, $widget_counter) = explode(':', $widget_seq_data);
142

    
143
		if ($widget_counter != 'next') {
144
			$widget_counter_array[$basename][$widget_counter] = true;
145
			$widget_sequence .= $widget_sep . $widget_seq_data;
146
			$widget_sep = ',';
147
		}
148
	}
149

    
150
	// Find any new entry (and do not assume there is only 1 new entry)
151
	foreach ($widget_seq_array as $widget_seq_data) {
152
		list($basename, $col, $display, $widget_counter) = explode(':', $widget_seq_data);
153

    
154
		if ($widget_counter == 'next') {
155
			// Construct the widget counter of the new widget instance by finding
156
			// the first non-negative integer that is not in use.
157
			// The reasoning here is that if you just deleted a widget instance,
158
			// e.g. had System Information 0,1,2 and deleted 1,
159
			// then when you add System Information again it will become instance 1,
160
			// which will bring back whatever filter selections happened to be on
161
			// the previous instance 1.
162
			$instance_num = 0;
163

    
164
			while (isset($widget_counter_array[$basename][$instance_num])) {
165
				$instance_num++;
166
			}
167

    
168
			$widget_sequence .= $widget_sep . $basename . ':' . $col . ':' . $display . ':' . $instance_num;
169
			$widget_counter_array[$basename][$instance_num] = true;
170
			$widget_sep = ',';
171
		}
172
	}
173

    
174
	$widget_settings['sequence'] = $widget_sequence;
175

    
176
	foreach ($widget_counter_array as $basename => $instances) {
177
		foreach ($instances as $instance => $value) {
178
			$widgetconfigname = $basename . '-' . $instance . '-config';
179
			if ($_POST[$widgetconfigname]) {
180
				$widget_settings[$widgetconfigname] = $_POST[$widgetconfigname];
181
			}
182
		}
183
	}
184

    
185
	save_widget_settings($_SESSION['Username'], $widget_settings);
186
	header("Location: /");
187
	exit;
188
}
189

    
190
## Load Functions Files
191
require_once('includes/functions.inc.php');
192

    
193
## Check to see if we have a swap space,
194
## if true, display, if false, hide it ...
195
if (file_exists("/usr/sbin/swapinfo")) {
196
	$swapinfo = `/usr/sbin/swapinfo`;
197
	if (stristr($swapinfo, '%') == true) $showswap=true;
198
}
199

    
200
## User recently restored his config.
201
## If packages are installed lets resync
202
if (file_exists('/conf/needs_package_sync')) {
203
	if ($config['installedpackages'] <> '' && is_array($config['installedpackages']['package'])) {
204
		## If the user has logged into webGUI quickly while the system is booting then do not redirect them to
205
		## the package reinstall page. That is about to be done by the boot script anyway.
206
		## The code in head.inc will put up a notice to the user.
207
		if (!platform_booting()) {
208
			header('Location: pkg_mgr_install.php?mode=reinstallall');
209
			exit;
210
		}
211
	} else {
212
		@unlink('/conf/needs_package_sync');
213
	}
214
}
215

    
216
## If it is the first time webConfigurator has been
217
## accessed since initial install show this stuff.
218
if (file_exists('/conf/trigger_initial_wizard')) {
219
?>
220
<!DOCTYPE html>
221
<html lang="en">
222
<head>
223
	<link rel="stylesheet" href="/css/pfSense.css" />
224
	<title><?=$g['product_name']?>.localdomain - <?=$g['product_name']?> first time setup</title>
225
	<meta http-equiv="refresh" content="1;url=wizard.php?xml=setup_wizard.xml" />
226
</head>
227
<body id="loading-wizard" class="no-menu">
228
	<div id="jumbotron">
229
		<div class="container">
230
			<div class="col-sm-offset-3 col-sm-6 col-xs-12">
231
				<font color="white">
232
				<p><h3><?=sprintf(gettext("Welcome to %s!") . "\n", $g['product_name'])?></h3></p>
233
				<p><?=gettext("One moment while the initial setup wizard starts.")?></p>
234
				<p><?=gettext("Embedded platform users: Please be patient, the wizard takes a little longer to run than the normal GUI.")?></p>
235
				<p><?=sprintf(gettext("To bypass the wizard, click on the %s logo on the initial page."), $g['product_name'])?></p>
236
				</font>
237
			</div>
238
		</div>
239
	</div>
240
</body>
241
</html>
242
<?php
243
	exit;
244
}
245

    
246
## Find out whether there's hardware encryption or not
247
unset($hwcrypto);
248
$fd = @fopen("{$g['varlog_path']}/dmesg.boot", "r");
249
if ($fd) {
250
	while (!feof($fd)) {
251
		$dmesgl = fgets($fd);
252
		if (preg_match("/^hifn.: (.*?),/", $dmesgl, $matches)
253
			or preg_match("/.*(VIA Padlock)/", $dmesgl, $matches)
254
			or preg_match("/^safe.: (\w.*)/", $dmesgl, $matches)
255
			or preg_match("/^ubsec.: (.*?),/", $dmesgl, $matches)
256
			or preg_match("/^padlock.: <(.*?)>,/", $dmesgl, $matches)) {
257
			$hwcrypto = $matches[1];
258
			break;
259
		}
260
	}
261
	fclose($fd);
262
	if (!isset($hwcrypto) && get_single_sysctl("dev.aesni.0.%desc")) {
263
		$hwcrypto = get_single_sysctl("dev.aesni.0.%desc");
264
	}
265
}
266

    
267
##build widget saved list information
268
if ($user_settings['widgets']['sequence'] != "") {
269
	$dashboardcolumns = isset($user_settings['webgui']['dashboardcolumns']) ? $user_settings['webgui']['dashboardcolumns'] : 2;
270
	$pconfig['sequence'] = $user_settings['widgets']['sequence'];
271
	$widgetsfromconfig = array();
272

    
273
	foreach (explode(',', $pconfig['sequence']) as $line) {
274
		$line_items = explode(':', $line);
275
		if (count($line_items) == 3) {
276
			// There can be multiple copies of a widget on the dashboard.
277
			// Default the copy number if it is not present (e.g. from old configs)
278
			$line_items[] = 0;
279
		}
280

    
281
		list($basename, $col, $display, $copynum) = $line_items;
282

    
283
		// be backwards compatible
284
		// If the display column information is missing, we will assign a temporary
285
		// column here. Next time the user saves the dashboard it will fix itself
286
		if ($col == "") {
287
			if ($basename == "system_information") {
288
				$col = "col1";
289
			} else {
290
				$col = "col2";
291
			}
292
		}
293

    
294
		// Limit the column to the current dashboard columns.
295
		if (substr($col, 3) > $dashboardcolumns) {
296
			$col = "col" . $dashboardcolumns;
297
		}
298

    
299
		$offset = strpos($basename, '-container');
300
		if (false !== $offset) {
301
			$basename = substr($basename, 0, $offset);
302
		}
303
		$widgetkey = $basename . '-' . $copynum;
304

    
305
		if (isset($user_settings['widgets'][$widgetkey]['descr'])) {
306
			$widgettitle = htmlentities($user_settings['widgets'][$widgetkey]['descr']);
307
		} else {
308
			// Get the widget title that should be in a var defined in the widget's inc file.
309
			$widgettitle = ${$basename . '_title'};
310

    
311
			if (empty(trim($widgettitle))) {
312
				// Fall back to constructing a title from the file name of the widget.
313
				$widgettitle = ucwords(str_replace('_', ' ', $basename));
314
			}
315
		}
316

    
317
		$widgetsfromconfig[$widgetkey] = array(
318
			'basename' => $basename,
319
			'title' => $widgettitle,
320
			'col' => $col,
321
			'display' => $display,
322
			'copynum' => $copynum,
323
			'multicopy' => ${$basename . '_allow_multiple_widget_copies'}
324
		);
325

    
326
		// Update the known_widgets entry so we know if any copy of the widget is being displayed
327
		$known_widgets[$basename . '-0']['display'] = $display;
328
	}
329

    
330
	// add widgets that may not be in the saved configuration, in case they are to be displayed later
331
	$widgets = $widgetsfromconfig + $known_widgets;
332

    
333
	##find custom configurations of a particular widget and load its info to $pconfig
334
	foreach ($widgets as $widgetname => $widgetconfig) {
335
		if ($config['widgets'][$widgetname . '-config']) {
336
			$pconfig[$widgetname . '-config'] = $config['widgets'][$widgetname . '-config'];
337
		}
338
	}
339
}
340

    
341
## Get the configured options for Show/Hide available widgets panel.
342
$dashboard_available_widgets_hidden = !$user_settings['webgui']['dashboardavailablewidgetspanel'];
343

    
344
if ($dashboard_available_widgets_hidden) {
345
	$panel_state = 'out';
346
	$panel_body_state = 'in';
347
} else {
348
	$panel_state = 'in';
349
	$panel_body_state = 'out';
350
}
351

    
352
## Set Page Title and Include Header
353
$pgtitle = array(gettext("Status"), gettext("Dashboard"));
354
include("head.inc");
355

    
356
if ($savemsg) {
357
	print_info_box($savemsg, $class);
358
}
359

    
360
pfSense_handle_custom_code("/usr/local/pkg/dashboard/pre_dashboard");
361

    
362
?>
363

    
364
<div class="panel panel-default collapse <?=$panel_state?>" id="widget-available">
365
	<div class="panel-heading">
366
		<h2 class="panel-title"><?=gettext("Available Widgets"); ?>
367
			<span class="widget-heading-icon">
368
				<a data-toggle="collapse" href="#widget-available_panel-body" id="widgets-available">
369
					<i class="fa fa-plus-circle"></i>
370
				</a>
371
			</span>
372
		</h2>
373
	</div>
374
	<div id="widget-available_panel-body" class="panel-body collapse <?=$panel_body_state?>">
375
		<div class="content">
376
			<div class="row">
377
<?php
378

    
379
// Build the Available Widgets table using a sorted copy of the $known_widgets array
380
$available = $known_widgets;
381
uasort($available, function($a, $b){ return strcasecmp($a['title'], $b['title']); });
382

    
383
foreach ($available as $widgetkey => $widgetconfig):
384
	// If the widget supports multiple copies, or no copies are displayed yet, then it is available to add
385
	if (($widgetconfig['multicopy']) || ($widgetconfig['display'] == 'none')):
386
?>
387
		<div class="col-sm-3"><a href="#" id="btnadd-<?=$widgetconfig['basename']?>"><i class="fa fa-plus"></i> <?=$widgetconfig['title']?></a></div>
388
	<?php endif; ?>
389
<?php
390
endforeach;
391
?>
392
			</div>
393
<p style="text-align:center"><?=sprintf(gettext('Other dashboard settings are available from the <a href="%s">General Setup</a> page.'), '/system.php')?></p>
394
		</div>
395
	</div>
396
</div>
397

    
398
<div class="hidden" id="widgetSequence">
399
	<form action="/" method="post" id="widgetSequence_form" name="widgetForm">
400
		<input type="hidden" name="sequence" value="" />
401
	</form>
402
</div>
403

    
404
<?php
405
$widgetColumns = array();
406
foreach ($widgets as $widgetkey => $widgetconfig) {
407
	if ($widgetconfig['display'] != 'none' && file_exists("/usr/local/www/widgets/widgets/{$widgetconfig['basename']}.widget.php")) {
408
		if (!isset($widgetColumns[$widgetconfig['col']])) {
409
			$widgetColumns[$widgetconfig['col']] = array();
410
		}
411
		$widgetColumns[$widgetconfig['col']][$widgetkey] = $widgetconfig;
412
	}
413
}
414
?>
415

    
416
<div class="row">
417
<?php
418
	$columnWidth = (int) (12 / $numColumns);
419

    
420
	for ($currentColumnNumber = 1; $currentColumnNumber <= $numColumns; $currentColumnNumber++) {
421

    
422

    
423
		//if col$currentColumnNumber exists
424
		if (isset($widgetColumns['col'.$currentColumnNumber])) {
425
			echo '<div class="col-md-' . $columnWidth . '" id="widgets-col' . $currentColumnNumber . '">';
426
			$columnWidgets = $widgetColumns['col'.$currentColumnNumber];
427

    
428
			foreach ($columnWidgets as $widgetkey => $widgetconfig) {
429
				// Construct some standard names for the ids this widget will use for its commonly-used elements.
430
				// Included widget.php code can rely on and use these, so the format does not have to be repeated in every widget.php
431
				$widget_panel_body_id = 'widget-' . $widgetkey . '_panel-body';
432
				$widget_panel_footer_id = 'widget-' . $widgetkey . '_panel-footer';
433
				$widget_showallnone_id = 'widget-' . $widgetkey . '_showallnone';
434

    
435
				// Compose the widget title and include the title link if available
436
				$widgetlink = ${$widgetconfig['basename'] . '_title_link'};
437

    
438
				if ((strlen($widgetlink) > 0)) {
439
					$wtitle = '<a href="' . $widgetlink . '"> ' . $widgetconfig['title'] . '</a>';
440
				} else {
441
					$wtitle = $widgetconfig['title'];
442
				}
443
				?>
444
				<div class="panel panel-default" id="widget-<?=$widgetkey?>">
445
					<div class="panel-heading">
446
						<h2 class="panel-title">
447
							<?=$wtitle?>
448
							<span class="widget-heading-icon">
449
								<a data-toggle="collapse" href="#<?=$widget_panel_footer_id?>" class="config hidden">
450
									<i class="fa fa-wrench"></i>
451
								</a>
452
								<a data-toggle="collapse" href="#<?=$widget_panel_body_id?>">
453
									<!--  actual icon is determined in css based on state of body -->
454
									<i class="fa fa-plus-circle"></i>
455
								</a>
456
								<a data-toggle="close" href="#widget-<?=$widgetkey?>">
457
									<i class="fa fa-times-circle"></i>
458
								</a>
459
							</span>
460
						</h2>
461
					</div>
462
					<div id="<?=$widget_panel_body_id?>" class="panel-body collapse<?=($widgetconfig['display'] == 'close' ? '' : ' in')?>">
463
						<?php
464
							// For backward compatibility, included *.widget.php code needs the var $widgetname
465
							$widgetname = $widgetkey;
466
							// Determine if this is the first instance of this particular widget.
467
							// Provide the $widget_first_instance var, to make it easy for the included widget code
468
							// to be able to know if it is being included for the first time.
469
							if ($widgets_found[$widgetconfig['basename']]) {
470
								$widget_first_instance = false;
471
							} else {
472
								$widget_first_instance = true;
473
								$widgets_found[$widgetconfig['basename']] = true;
474
							}
475
							include('/usr/local/www/widgets/widgets/' . $widgetconfig['basename'] . '.widget.php');
476
						?>
477
					</div>
478
				</div>
479
				<?php
480
			}
481
			echo "</div>";
482
		} else {
483
			echo '<div class="col-md-' . $columnWidth . '" id="widgets-col' . $currentColumnNumber . '"></div>';
484
		}
485

    
486
	}
487
?>
488

    
489
</div>
490

    
491
<script type="text/javascript">
492
//<![CDATA[
493

    
494
dirty = false;
495
function updateWidgets(newWidget) {
496
	var sequence = '';
497

    
498
	$('.container .col-md-<?=$columnWidth?>').each(function(idx, col) {
499
		$('.panel', col).each(function(idx, widget) {
500
			var isOpen = $('.panel-body', widget).hasClass('in');
501
			var widget_basename = widget.id.split('-')[1];
502

    
503
			// Only save details for panels that have id's like'widget-*'
504
			// Some widgets create other panels, so ignore any of those.
505
			if ((widget.id.split('-')[0] == 'widget') && (typeof widget_basename !== 'undefined')) {
506
				sequence += widget_basename + ':' + col.id.split('-')[1] + ':' + (isOpen ? 'open' : 'close') + ':' + widget.id.split('-')[2] + ',';
507
			}
508
		});
509
	});
510

    
511
	if (typeof newWidget !== 'undefined') {
512
		// The system_information widget is always added to column one. Others go in column two
513
		if (newWidget == "system_information") {
514
			sequence += newWidget.split('-')[0] + ':' + 'col1:open:next';
515
		} else {
516
			sequence += newWidget.split('-')[0] + ':' + 'col2:open:next';
517
		}
518
	}
519

    
520
	$('input[name=sequence]', $('#widgetSequence_form')).val(sequence);
521
}
522

    
523
// Determine if all the checkboxes are checked
524
function are_all_checked(checkbox_panel_ref) {
525
	var allBoxesChecked = true;
526
	$(checkbox_panel_ref).each(function() {
527
		if ((this.type == 'checkbox') && !this.checked) {
528
			allBoxesChecked = false;
529
		}
530
	});
531
	return allBoxesChecked;
532
}
533

    
534
// If the checkboxes are all checked, then clear them all.
535
// Otherwise set them all.
536
function set_clear_checkboxes(checkbox_panel_ref) {
537
	checkTheBoxes = !are_all_checked(checkbox_panel_ref);
538

    
539
	$(checkbox_panel_ref).each(function() {
540
		$(this).prop("checked", checkTheBoxes);
541
	});
542
}
543

    
544
// Set the given id to All or None button depending if the checkboxes are all checked.
545
function set_all_none_button(checkbox_panel_ref, all_none_button_id) {
546
	if (are_all_checked(checkbox_panel_ref)) {
547
		text = "<?=gettext('None')?>";
548
	} else {
549
		text = "<?=gettext('All')?>";
550
	}
551

    
552
	$("#" + all_none_button_id).html('<i class="fa fa-undo icon-embed-btn"></i>' + text);
553
}
554

    
555
// Setup the necessary events to manage the All/None button and included checkboxes
556
// used for selecting the items to show on a widget.
557
function set_widget_checkbox_events(checkbox_panel_ref, all_none_button_id) {
558
		set_all_none_button(checkbox_panel_ref, all_none_button_id);
559

    
560
		$(checkbox_panel_ref).change(function() {
561
			set_all_none_button(checkbox_panel_ref, all_none_button_id);
562
		});
563

    
564
		$("#" + all_none_button_id).click(function() {
565
			set_clear_checkboxes(checkbox_panel_ref);
566
			set_all_none_button(checkbox_panel_ref, all_none_button_id);
567
		});
568
}
569

    
570
// --------------------- EXPERIMENTAL centralized widget refresh system ------------------------------
571
// These need to live outsie of the events.push() function to enable the widgets to see them
572
var ajaxspecs = new Array();	// Array to hold widget refresh specifications (objects )
573
var ajaxidx = 0;
574
var ajaxmutex = false;
575
var ajaxcntr = 0;
576

    
577
// Add a widget refresh object to the array list
578
function register_ajax(ws) {
579
  ajaxspecs.push(ws);
580
}
581
// ---------------------------------------------------------------------------------------------------
582

    
583
events.push(function() {
584
	// Make panels destroyable
585
	$('.container .panel-heading a[data-toggle="close"]').each(function (idx, el) {
586
		$(el).on('click', function(e) {
587
			$(el).parents('.panel').remove();
588
			updateWidgets();
589
			// Submit the form save/display all selected widgets
590
			$('[name=widgetForm]').submit();
591
		})
592
	});
593

    
594
	// Make panels sortable
595
	$('.container .col-md-<?=$columnWidth?>').sortable({
596
		handle: '.panel-heading',
597
		cursor: 'grabbing',
598
		connectWith: '.container .col-md-<?=$columnWidth?>',
599
		update: function(){
600
			dirty = true;
601
			$('#btnstore').removeClass('invisible');
602
		}
603
	});
604

    
605
	// On clicking a widget to install . .
606
	$('[id^=btnadd-]').click(function(event) {
607
		// Add the widget name to the list of displayed widgets
608
		updateWidgets(this.id.replace('btnadd-', ''));
609

    
610
		// Submit the form save/display all selected widgets
611
		$('[name=widgetForm]').submit();
612
	});
613

    
614

    
615
	$('#btnstore').click(function() {
616
		updateWidgets();
617
		dirty = false;
618
		$(this).addClass('invisible');
619
		$('[name=widgetForm]').submit();
620
	});
621

    
622
	// provide a warning message if the user tries to change page before saving
623
	$(window).bind('beforeunload', function(){
624
		if (dirty) {
625
			return ("<?=gettext('One or more widgets have been moved but have not yet been saved')?>");
626
		} else {
627
			return undefined;
628
		}
629
	});
630

    
631
	// Show the fa-save icon in the breadcrumb bar if the user opens or closes a panel (In case he/she wants to save the new state)
632
	// (Sometimes this will cause us to see the icon when we don't need it, but better that than the other way round)
633
	$('.panel').on('hidden.bs.collapse shown.bs.collapse', function (e) {
634
	    if (e.currentTarget.id != 'widget-available') {
635
			$('#btnstore').removeClass("invisible");
636
		}
637
	});
638

    
639
	// --------------------- EXPERIMENTAL centralized widget refresh system ------------------------------
640
	function make_ajax_call(wd) {
641
		ajaxmutex = true;
642

    
643
		$.ajax({
644
			type: 'POST',
645
			url: wd.url,
646
			dataType: 'html',
647
			data: wd.parms,
648

    
649
			success: function(data){
650
				wd.callback(data);
651
				ajaxmutex = false;
652
			},
653

    
654
			error: function(e){
655
//				alert("Error: " + e);
656
				ajaxmutex = false;
657
			}
658
		});
659
	}
660

    
661
	// Loop through each AJAX widget refresh object, make the AJAX call and pass the
662
	// results back to the widget's callback function
663
	function executewidget() {
664
		if (ajaxspecs.length > 0) {
665
			var freq = ajaxspecs[ajaxidx].freq;	// widget can specifify it should be called freq times around hte loop
666

    
667
			if (!ajaxmutex) {
668
				if (((ajaxcntr % freq) === 0) && (typeof ajaxspecs[ajaxidx].callback === "function" )) {
669
				    make_ajax_call(ajaxspecs[ajaxidx]);
670
				}
671

    
672
			    if (++ajaxidx >= ajaxspecs.length) {
673
					ajaxidx = 0;
674

    
675
					if (++ajaxcntr >= 4096) {
676
						ajaxcntr = 0;
677
					}
678
			    }
679
			}
680

    
681
		    setTimeout(function() { executewidget(); }, 1000);
682
	  	}
683
	}
684

    
685
	// Kick it off
686
	executewidget();
687

    
688
	//----------------------------------------------------------------------------------------------------
689
});
690
//]]>
691
</script>
692

    
693
<?php
694
//build list of javascript include files
695
foreach (glob('widgets/javascript/*.js') as $file) {
696
	$mtime = filemtime("/usr/local/www/{$file}");
697
	echo '<script src="'.$file.'?v='.$mtime.'"></script>';
698
}
699

    
700
include("foot.inc");
(69-69/228)