Project

General

Profile

Download (22.9 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
 * index.php
4
 *
5
 * part of pfSense (https://www.pfsense.org)
6
 * Copyright (c) 2004-2018 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
// Message to display if the session times out and an AJAX call is made
34
$timeoutmessage = gettext("The dashboard web session has timed out.\\n" .
35
	"It will not update until you refresh the page and log-in again.");
36

    
37
// Turn on buffering to speed up rendering
38
ini_set('output_buffering', 'true');
39

    
40
// Start buffering with a cache size of 100000
41
ob_start(null, "1000");
42

    
43
## Load Essential Includes
44
require_once('guiconfig.inc');
45
require_once('functions.inc');
46
require_once('notices.inc');
47
require_once("pkg-utils.inc");
48

    
49
if (isset($_POST['closenotice'])) {
50
	close_notice($_POST['closenotice']);
51
	sleep(1);
52
	exit;
53
}
54

    
55
if (isset($_REQUEST['closenotice'])) {
56
	close_notice($_REQUEST['closenotice']);
57
	sleep(1);
58
}
59

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

    
70
	$crash = glob("/var/crash/*");
71
	$skip_files = array(".", "..", "minfree", "");
72

    
73
	if (is_array($crash)) {
74
		foreach ($crash as $c) {
75
			if (!in_array(basename($c), $skip_files)) {
76
				$x++;
77
			}
78
		}
79

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

    
92
## Include each widget php include file.
93
## These define vars that specify the widget title and title link.
94

    
95
$directory = "/usr/local/www/widgets/include/";
96
$dirhandle = opendir($directory);
97
$filename = "";
98

    
99
while (($filename = readdir($dirhandle)) !== false) {
100
	if (strtolower(substr($filename, -4)) == ".inc" && file_exists($directory . $filename)) {
101
		include_once($directory . $filename);
102
	}
103
}
104

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

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

    
116
	$known_widgets[$basename . '-0'] = array(
117
		'basename' => $basename,
118
		'title' => $widgettitle,
119
		'display' => 'none',
120
		'multicopy' => ${$basename . '_allow_multiple_widget_copies'}
121
	);
122
}
123

    
124
##if no config entry found, initialize config entry
125
if (!is_array($config['widgets'])) {
126
	$config['widgets'] = array();
127
}
128

    
129
if (!is_array($user_settings['widgets'])) {
130
	$user_settings['widgets'] = array();
131
}
132

    
133
if ($_POST && $_POST['sequence']) {
134

    
135
	// Start with the user's widget settings.
136
	$widget_settings = $user_settings['widgets'];
137

    
138
	$widget_sep = ',';
139
	$widget_seq_array = explode($widget_sep, rtrim($_POST['sequence'], $widget_sep));
140
	$widget_counter_array = array();
141
	$widget_sep = '';
142

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

    
147
		if ($widget_counter != 'next') {
148
			if (!is_numeric($widget_counter)) {
149
				continue;
150
			}
151
			$widget_counter_array[$basename][$widget_counter] = true;
152
			$widget_sequence .= $widget_sep . $widget_seq_data;
153
			$widget_sep = ',';
154
		}
155
	}
156

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

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

    
171
			while (isset($widget_counter_array[$basename][$instance_num])) {
172
				$instance_num++;
173
			}
174

    
175
			$widget_sequence .= $widget_sep . $basename . ':' . $col . ':' . $display . ':' . $instance_num;
176
			$widget_counter_array[$basename][$instance_num] = true;
177
			$widget_sep = ',';
178
		}
179
	}
180

    
181
	$widget_settings['sequence'] = $widget_sequence;
182

    
183
	foreach ($widget_counter_array as $basename => $instances) {
184
		foreach ($instances as $instance => $value) {
185
			$widgetconfigname = $basename . '-' . $instance . '-config';
186
			if ($_POST[$widgetconfigname]) {
187
				$widget_settings[$widgetconfigname] = $_POST[$widgetconfigname];
188
			}
189
		}
190
	}
191

    
192
	save_widget_settings($_SESSION['Username'], $widget_settings);
193
	header("Location: /");
194
	exit;
195
}
196

    
197
## Load Functions Files
198
require_once('includes/functions.inc.php');
199

    
200
## Check to see if we have a swap space,
201
## if true, display, if false, hide it ...
202
if (file_exists("/usr/sbin/swapinfo")) {
203
	$swapinfo = `/usr/sbin/swapinfo`;
204
	if (stristr($swapinfo, '%') == true) $showswap=true;
205
}
206

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

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

    
258
##build widget saved list information
259
if ($user_settings['widgets']['sequence'] != "") {
260
	$dashboardcolumns = isset($user_settings['webgui']['dashboardcolumns']) ? (int) $user_settings['webgui']['dashboardcolumns'] : 2;
261
	$pconfig['sequence'] = $user_settings['widgets']['sequence'];
262
	$widgetsfromconfig = array();
263

    
264
	foreach (explode(',', $pconfig['sequence']) as $line) {
265
		$line_items = explode(':', $line);
266
		if (count($line_items) == 3) {
267
			// There can be multiple copies of a widget on the dashboard.
268
			// Default the copy number if it is not present (e.g. from old configs)
269
			$line_items[] = 0;
270
		}
271

    
272
		list($basename, $col, $display, $copynum) = $line_items;
273
		if (!is_numeric($copynum)) {
274
			continue;
275
		}
276

    
277
		// be backwards compatible
278
		// If the display column information is missing, we will assign a temporary
279
		// column here. Next time the user saves the dashboard it will fix itself
280
		if ($col == "") {
281
			if ($basename == "system_information") {
282
				$col = "col1";
283
			} else {
284
				$col = "col2";
285
			}
286
		}
287

    
288
		// Limit the column to the current dashboard columns.
289
		if (substr($col, 3) > $dashboardcolumns) {
290
			$col = "col" . $dashboardcolumns;
291
		}
292

    
293
		$offset = strpos($basename, '-container');
294
		if (false !== $offset) {
295
			$basename = substr($basename, 0, $offset);
296
		}
297
		$widgetkey = $basename . '-' . $copynum;
298

    
299
		if (isset($user_settings['widgets'][$widgetkey]['descr'])) {
300
			$widgettitle = htmlentities($user_settings['widgets'][$widgetkey]['descr']);
301
		} else {
302
			// Get the widget title that should be in a var defined in the widget's inc file.
303
			$widgettitle = ${$basename . '_title'};
304

    
305
			if (empty(trim($widgettitle))) {
306
				// Fall back to constructing a title from the file name of the widget.
307
				$widgettitle = ucwords(str_replace('_', ' ', $basename));
308
			}
309
		}
310

    
311
		$widgetsfromconfig[$widgetkey] = array(
312
			'basename' => $basename,
313
			'title' => $widgettitle,
314
			'col' => $col,
315
			'display' => $display,
316
			'copynum' => $copynum,
317
			'multicopy' => ${$basename . '_allow_multiple_widget_copies'}
318
		);
319

    
320
		// Update the known_widgets entry so we know if any copy of the widget is being displayed
321
		$known_widgets[$basename . '-0']['display'] = $display;
322
	}
323

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

    
327
	##find custom configurations of a particular widget and load its info to $pconfig
328
	foreach ($widgets as $widgetname => $widgetconfig) {
329
		if ($config['widgets'][$widgetname . '-config']) {
330
			$pconfig[$widgetname . '-config'] = $config['widgets'][$widgetname . '-config'];
331
		}
332
	}
333
}
334

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

    
338
if ($dashboard_available_widgets_hidden) {
339
	$panel_state = 'out';
340
	$panel_body_state = 'in';
341
} else {
342
	$panel_state = 'in';
343
	$panel_body_state = 'out';
344
}
345

    
346
## Set Page Title and Include Header
347
$pgtitle = array(gettext("Status"), gettext("Dashboard"));
348
include("head.inc");
349

    
350
if ($savemsg) {
351
	print_info_box($savemsg, $class);
352
}
353

    
354
pfSense_handle_custom_code("/usr/local/pkg/dashboard/pre_dashboard");
355

    
356
?>
357

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

    
373
// Build the Available Widgets table using a sorted copy of the $known_widgets array
374
$available = $known_widgets;
375
uasort($available, function($a, $b){ return strcasecmp($a['title'], $b['title']); });
376

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

    
392
<div class="hidden" id="widgetSequence">
393
	<form action="/" method="post" id="widgetSequence_form" name="widgetForm">
394
		<input type="hidden" name="sequence" value="" />
395
	</form>
396
</div>
397

    
398
<?php
399
$widgetColumns = array();
400
foreach ($widgets as $widgetkey => $widgetconfig) {
401
	if ($widgetconfig['display'] != 'none' && file_exists("/usr/local/www/widgets/widgets/{$widgetconfig['basename']}.widget.php")) {
402
		if (!isset($widgetColumns[$widgetconfig['col']])) {
403
			$widgetColumns[$widgetconfig['col']] = array();
404
		}
405
		$widgetColumns[$widgetconfig['col']][$widgetkey] = $widgetconfig;
406
	}
407
}
408
?>
409

    
410
<div class="row">
411
<?php
412
	$columnWidth = (int) (12 / $numColumns);
413

    
414
	for ($currentColumnNumber = 1; $currentColumnNumber <= $numColumns; $currentColumnNumber++) {
415

    
416

    
417
		//if col$currentColumnNumber exists
418
		if (isset($widgetColumns['col'.$currentColumnNumber])) {
419
			echo '<div class="col-md-' . $columnWidth . '" id="widgets-col' . $currentColumnNumber . '">';
420
			$columnWidgets = $widgetColumns['col'.$currentColumnNumber];
421

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

    
429
				// Compose the widget title and include the title link if available
430
				$widgetlink = ${$widgetconfig['basename'] . '_title_link'};
431

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

    
480
	}
481
?>
482

    
483
</div>
484

    
485
<?php
486
/*
487
 * Import the modal form used to display the copyright/usage information
488
 * when trigger file exists. Trigger file is created during upgrade process
489
 * when /etc/version changes
490
 */
491
require_once("copyget.inc");
492

    
493
if (file_exists("{$g['cf_conf_path']}/copynotice_display")) {
494
	require_once("copynotice.inc");
495
	@unlink("{$g['cf_conf_path']}/copynotice_display");
496
}
497

    
498
/*
499
 * Import the modal form used to display any HTML text a package may want to display
500
 * on installation or removal
501
 */
502
$ui_notice = "/tmp/package_ui_notice";
503
if (file_exists($ui_notice)) {
504
	require_once("{$g['www_path']}/upgrnotice.inc");
505
}
506
?>
507

    
508
<script type="text/javascript">
509
//<![CDATA[
510

    
511
dirty = false;
512
function updateWidgets(newWidget) {
513
	var sequence = '';
514

    
515
	$('.container .col-md-<?=$columnWidth?>').each(function(idx, col) {
516
		$('.panel', col).each(function(idx, widget) {
517
			var isOpen = $('.panel-body', widget).hasClass('in');
518
			var widget_basename = widget.id.split('-')[1];
519

    
520
			// Only save details for panels that have id's like'widget-*'
521
			// Some widgets create other panels, so ignore any of those.
522
			if ((widget.id.split('-')[0] == 'widget') && (typeof widget_basename !== 'undefined')) {
523
				sequence += widget_basename + ':' + col.id.split('-')[1] + ':' + (isOpen ? 'open' : 'close') + ':' + widget.id.split('-')[2] + ',';
524
			}
525
		});
526
	});
527

    
528
	if (typeof newWidget !== 'undefined') {
529
		// The system_information widget is always added to column one. Others go in column two
530
		if (newWidget == "system_information") {
531
			sequence += newWidget.split('-')[0] + ':' + 'col1:open:next';
532
		} else {
533
			sequence += newWidget.split('-')[0] + ':' + 'col2:open:next';
534
		}
535
	}
536

    
537
	$('input[name=sequence]', $('#widgetSequence_form')).val(sequence);
538
}
539

    
540
// Determine if all the checkboxes are checked
541
function are_all_checked(checkbox_panel_ref) {
542
	var allBoxesChecked = true;
543
	$(checkbox_panel_ref).each(function() {
544
		if ((this.type == 'checkbox') && !this.checked) {
545
			allBoxesChecked = false;
546
		}
547
	});
548
	return allBoxesChecked;
549
}
550

    
551
// If the checkboxes are all checked, then clear them all.
552
// Otherwise set them all.
553
function set_clear_checkboxes(checkbox_panel_ref) {
554
	checkTheBoxes = !are_all_checked(checkbox_panel_ref);
555

    
556
	$(checkbox_panel_ref).each(function() {
557
		$(this).prop("checked", checkTheBoxes);
558
	});
559
}
560

    
561
// Set the given id to All or None button depending if the checkboxes are all checked.
562
function set_all_none_button(checkbox_panel_ref, all_none_button_id) {
563
	if (are_all_checked(checkbox_panel_ref)) {
564
		text = "<?=gettext('None')?>";
565
	} else {
566
		text = "<?=gettext('All')?>";
567
	}
568

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

    
572
// Setup the necessary events to manage the All/None button and included checkboxes
573
// used for selecting the items to show on a widget.
574
function set_widget_checkbox_events(checkbox_panel_ref, all_none_button_id) {
575
		set_all_none_button(checkbox_panel_ref, all_none_button_id);
576

    
577
		$(checkbox_panel_ref).change(function() {
578
			set_all_none_button(checkbox_panel_ref, all_none_button_id);
579
		});
580

    
581
		$("#" + all_none_button_id).click(function() {
582
			set_clear_checkboxes(checkbox_panel_ref);
583
			set_all_none_button(checkbox_panel_ref, all_none_button_id);
584
		});
585
}
586

    
587
// ---------------------Centralized widget refresh system -------------------------------------------
588
// These need to live outsie of the events.push() function to enable the widgets to see them
589
var ajaxspecs = new Array();	// Array to hold widget refresh specifications (objects )
590
var ajaxidx = 0;
591
var ajaxmutex = false;
592
var ajaxcntr = 0;
593

    
594
// Add a widget refresh object to the array list
595
function register_ajax(ws) {
596
  ajaxspecs.push(ws);
597
}
598
// ---------------------------------------------------------------------------------------------------
599

    
600
events.push(function() {
601
	// Make panels destroyable
602
	$('.container .panel-heading a[data-toggle="close"]').each(function (idx, el) {
603
		$(el).on('click', function(e) {
604
			$(el).parents('.panel').remove();
605
			updateWidgets();
606
			// Submit the form save/display all selected widgets
607
			$('[name=widgetForm]').submit();
608
		})
609
	});
610

    
611
	// Make panels sortable
612
	$('.container .col-md-<?=$columnWidth?>').sortable({
613
		handle: '.panel-heading',
614
		cursor: 'grabbing',
615
		connectWith: '.container .col-md-<?=$columnWidth?>',
616
		update: function(){
617
			dirty = true;
618
			$('#btnstore').removeClass('invisible');
619
		}
620
	});
621

    
622
	// On clicking a widget to install . .
623
	$('[id^=btnadd-]').click(function(event) {
624
		// Add the widget name to the list of displayed widgets
625
		updateWidgets(this.id.replace('btnadd-', ''));
626

    
627
		// Submit the form save/display all selected widgets
628
		$('[name=widgetForm]').submit();
629
	});
630

    
631

    
632
	$('#btnstore').click(function() {
633
		updateWidgets();
634
		dirty = false;
635
		$(this).addClass('invisible');
636
		$('[name=widgetForm]').submit();
637
	});
638

    
639
	// provide a warning message if the user tries to change page before saving
640
	$(window).bind('beforeunload', function(){
641
		if (dirty) {
642
			return ("<?=gettext('One or more widgets have been moved but have not yet been saved')?>");
643
		} else {
644
			return undefined;
645
		}
646
	});
647

    
648
	// 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)
649
	// (Sometimes this will cause us to see the icon when we don't need it, but better that than the other way round)
650
	$('.panel').on('hidden.bs.collapse shown.bs.collapse', function (e) {
651
	    if (e.currentTarget.id != 'widget-available') {
652
			$('#btnstore').removeClass("invisible");
653
		}
654
	});
655

    
656
	// --------------------- Centralized widget refresh system ------------------------------
657
	ajaxtimeout = false;
658

    
659
	function make_ajax_call(wd) {
660
		ajaxmutex = true;
661

    
662
		$.ajax({
663
			type: 'POST',
664
			url: wd.url,
665
			dataType: 'html',
666
			data: wd.parms,
667

    
668
			success: function(data){
669
				if (data.length > 0 ) {
670
					// If the session has timed out, display a pop-up
671
					if (data.indexOf("SESSION_TIMEOUT") === -1) {
672
						wd.callback(data);
673
					} else {
674
						if (ajaxtimeout === false) {
675
							ajaxtimeout = true;
676
							alert("<?=$timeoutmessage?>");
677
						}
678
					}
679
				}
680

    
681
				ajaxmutex = false;
682
			},
683

    
684
			error: function(e){
685
//				alert("Error: " + e);
686
				ajaxmutex = false;
687
			}
688
		});
689
	}
690

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

    
697
			if (!ajaxmutex) {
698
				if (((ajaxcntr % freq) === 0) && (typeof ajaxspecs[ajaxidx].callback === "function" )) {
699
				    make_ajax_call(ajaxspecs[ajaxidx]);
700
				}
701

    
702
			    if (++ajaxidx >= ajaxspecs.length) {
703
					ajaxidx = 0;
704

    
705
					if (++ajaxcntr >= 4096) {
706
						ajaxcntr = 0;
707
					}
708
			    }
709
			}
710

    
711
		    setTimeout(function() { executewidget(); }, 1000);
712
	  	}
713
	}
714

    
715
	// Kick it off
716
	executewidget();
717

    
718
	//----------------------------------------------------------------------------------------------------
719
});
720
//]]>
721
</script>
722

    
723
<?php
724
//build list of javascript include files
725
foreach (glob('widgets/javascript/*.js') as $file) {
726
	$mtime = filemtime("/usr/local/www/{$file}");
727
	echo '<script src="'.$file.'?v='.$mtime.'"></script>';
728
}
729

    
730
include("foot.inc");
(70-70/234)