Project

General

Profile

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

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

    
35
// Message to display if the session times out and an AJAX call is made
36
$timeoutmessage = gettext("The dashboard web session has timed out.\\n" .
37
	"It will not update until you refresh the page and log-in again.");
38

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

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

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

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

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

    
62
if ((g_get('disablecrashreporter') != true) && (system_has_crash_data() || system_has_php_errors())) {
63
	$savemsg = sprintf(gettext("%s has detected a crash report or programming bug."), g_get('product_label')) . " ";
64
	if (isAllowedPage("/crash_reporter.php")) {
65
		$savemsg .= sprintf(gettext('Click %1$shere%2$s for more information.'), '<a href="crash_reporter.php">', '</a>');
66
	} else {
67
		$savemsg .= sprintf(gettext("Contact a firewall administrator for more information."));
68
	}
69
	$class = "warning";
70
}
71

    
72
## Include each widget php include file.
73
## These define vars that specify the widget title and title link.
74

    
75
$directory = "/usr/local/www/widgets/include/";
76
$dirhandle = opendir($directory);
77
$filename = "";
78

    
79
while (($filename = readdir($dirhandle)) !== false) {
80
	if (strtolower(substr($filename, -4)) == ".inc" && file_exists($directory . $filename)) {
81
		include_once($directory . $filename);
82
	}
83
}
84

    
85
##build list of widgets
86
foreach (glob("/usr/local/www/widgets/widgets/*.widget.php") as $file) {
87
	$basename = basename($file, '.widget.php');
88
	// Get the widget title that should be in a var defined in the widget's inc file.
89
	$widgettitle = ${$basename . '_title'};
90

    
91
	if (empty(trim($widgettitle))) {
92
		// Fall back to constructing a title from the file name of the widget.
93
		$widgettitle = ucwords(str_replace('_', ' ', $basename));
94
	}
95

    
96
	$known_widgets[$basename . '-0'] = array(
97
		'basename' => $basename,
98
		'title' => $widgettitle,
99
		'display' => 'none',
100
		'multicopy' => ${$basename . '_allow_multiple_widget_copies'}
101
	);
102
}
103

    
104
##if no config entry found, initialize config entry
105
config_init_path('widgets');
106

    
107
if (!is_array($user_settings['widgets'])) {
108
	$user_settings['widgets'] = array();
109
}
110

    
111
if ($_POST && $_POST['sequence']) {
112

    
113
	// Start with the user's widget settings.
114
	$widget_settings = $user_settings['widgets'];
115

    
116
	$widget_sep = ',';
117
	$widget_seq_array = explode($widget_sep, rtrim($_POST['sequence'], $widget_sep));
118
	$widget_counter_array = array();
119
	$widget_sep = '';
120

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

    
125
		if ($widget_counter != 'next') {
126
			if (!is_numeric($widget_counter)) {
127
				continue;
128
			}
129
			$widget_counter_array[$basename][$widget_counter] = true;
130
			$widget_sequence .= $widget_sep . $widget_seq_data;
131
			$widget_sep = ',';
132
		}
133
	}
134

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

    
139
		if ($widget_counter == 'next') {
140
			// Construct the widget counter of the new widget instance by finding
141
			// the first non-negative integer that is not in use.
142
			// The reasoning here is that if you just deleted a widget instance,
143
			// e.g. had System Information 0,1,2 and deleted 1,
144
			// then when you add System Information again it will become instance 1,
145
			// which will bring back whatever filter selections happened to be on
146
			// the previous instance 1.
147
			$instance_num = 0;
148

    
149
			while (isset($widget_counter_array[$basename][$instance_num])) {
150
				$instance_num++;
151
			}
152

    
153
			$widget_sequence .= $widget_sep . $basename . ':' . $col . ':' . $display . ':' . $instance_num;
154
			$widget_counter_array[$basename][$instance_num] = true;
155
			$widget_sep = ',';
156
		}
157
	}
158

    
159
	$widget_settings['sequence'] = $widget_sequence;
160

    
161
	foreach ($widget_counter_array as $basename => $instances) {
162
		foreach ($instances as $instance => $value) {
163
			$widgetconfigname = $basename . '-' . $instance . '-config';
164
			if ($_POST[$widgetconfigname]) {
165
				$widget_settings[$widgetconfigname] = $_POST[$widgetconfigname];
166
			}
167
		}
168
	}
169

    
170
	save_widget_settings($_SESSION['Username'], $widget_settings);
171
	header("Location: /");
172
	exit;
173
}
174

    
175
## Load Functions Files
176
require_once('includes/functions.inc.php');
177

    
178
## Check to see if we have a swap space,
179
## if true, display, if false, hide it ...
180
if (file_exists("/usr/sbin/swapinfo")) {
181
	$swapinfo = `/usr/sbin/swapinfo`;
182
	if (stristr($swapinfo, '%') == true) $showswap=true;
183
}
184

    
185
## If it is the first time webConfigurator has been
186
## accessed since initial install show this stuff.
187
if (file_exists('/conf/trigger_initial_wizard')) {
188
?>
189
<!DOCTYPE html>
190
<html lang="en">
191
	<head>
192
		<link rel="stylesheet" href="/css/pfSense.css" />
193
		<title><?=g_get('product_label')?>.home.arpa - <?=g_get('product_label')?> first time setup</title>
194
		<meta http-equiv="refresh" content="1;url=wizard.php?xml=setup_wizard.xml" />
195
	</head>
196
	<body id="loading-wizard" class="no-menu">
197
		<div id="jumbotron">
198
			<div class="container">
199
				<div class="col-sm-offset-3 col-sm-6 col-xs-12">
200
					<font color="white">
201
					<p><h3><?=sprintf(gettext("Welcome to %s!") . "\n", g_get('product_label'))?></h3></p>
202
					<p><?=gettext("One moment while the initial setup wizard starts.")?></p>
203
					<p><?=gettext("Embedded platform users: Please be patient, the wizard takes a little longer to run than the normal GUI.")?></p>
204
					<p><?=sprintf(gettext("To bypass the wizard, click on the %s logo on the initial page."), g_get('product_label'))?></p>
205
					</font>
206
				</div>
207
			</div>
208
		</div>
209
	</body>
210
</html>
211
<?php
212
	exit;
213
}
214

    
215
##build widget saved list information
216
if ($user_settings['widgets']['sequence'] != "") {
217
	$dashboardcolumns = isset($user_settings['webgui']['dashboardcolumns']) ? (int) $user_settings['webgui']['dashboardcolumns'] : 2;
218
	$pconfig['sequence'] = $user_settings['widgets']['sequence'];
219
	$widgetsfromconfig = array();
220

    
221
	foreach (explode(',', $pconfig['sequence']) as $line) {
222
		$line_items = explode(':', $line);
223
		if (count($line_items) == 3) {
224
			// There can be multiple copies of a widget on the dashboard.
225
			// Default the copy number if it is not present (e.g. from old configs)
226
			$line_items[] = 0;
227
		}
228

    
229
		list($basename, $col, $display, $copynum) = $line_items;
230
		if (!is_numeric($copynum)) {
231
			continue;
232
		}
233

    
234
		// be backwards compatible
235
		// If the display column information is missing, we will assign a temporary
236
		// column here. Next time the user saves the dashboard it will fix itself
237
		if ($col == "") {
238
			if ($basename == "system_information") {
239
				$col = "col1";
240
			} else {
241
				$col = "col2";
242
			}
243
		}
244

    
245
		// Limit the column to the current dashboard columns.
246
		if (substr($col, 3) > $dashboardcolumns) {
247
			$col = "col" . $dashboardcolumns;
248
		}
249

    
250
		$offset = strpos($basename, '-container');
251
		if (false !== $offset) {
252
			$basename = substr($basename, 0, $offset);
253
		}
254
		$widgetkey = $basename . '-' . $copynum;
255

    
256
		if (isset($user_settings['widgets'][$widgetkey]['descr'])) {
257
			$widgettitle = htmlentities($user_settings['widgets'][$widgetkey]['descr']);
258
		} else {
259
			// Get the widget title that should be in a var defined in the widget's inc file.
260
			$widgettitle = ${$basename . '_title'};
261

    
262
			if (empty(trim($widgettitle))) {
263
				// Fall back to constructing a title from the file name of the widget.
264
				$widgettitle = ucwords(str_replace('_', ' ', $basename));
265
			}
266
		}
267

    
268
		$widgetsfromconfig[$widgetkey] = array(
269
			'basename' => $basename,
270
			'title' => $widgettitle,
271
			'col' => $col,
272
			'display' => $display,
273
			'copynum' => $copynum,
274
			'multicopy' => ${$basename . '_allow_multiple_widget_copies'}
275
		);
276

    
277
		// Update the known_widgets entry so we know if any copy of the widget is being displayed
278
		$known_widgets[$basename . '-0']['display'] = $display;
279
	}
280

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

    
284
	##find custom configurations of a particular widget and load its info to $pconfig
285
	$widgets_config = config_get_path('widgets');
286
	foreach ($widgets as $widgetname => $widgetconfig) {
287
		if ($widgets_config["{$widgetname}-config"]) {
288
			$pconfig["{$widgetname}-config"] = $widgets_config["{$widgetname}-config"];
289
		}
290
	}
291
}
292

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

    
296
if ($dashboard_available_widgets_hidden) {
297
	$panel_state = 'out';
298
	$panel_body_state = 'in';
299
} else {
300
	$panel_state = 'in';
301
	$panel_body_state = 'out';
302
}
303

    
304
## Set Page Title and Include Header
305
$pgtitle = array(gettext("Status"), gettext("Dashboard"));
306
include("head.inc");
307

    
308
if ($savemsg) {
309
	print_info_box($savemsg, $class);
310
}
311

    
312
pfSense_handle_custom_code("/usr/local/pkg/dashboard/pre_dashboard");
313

    
314
?>
315

    
316
<div class="panel panel-default collapse <?=$panel_state?>" id="widget-available">
317
	<div class="panel-heading">
318
		<h2 class="panel-title"><?=gettext("Available Widgets"); ?>
319
			<span class="widget-heading-icon">
320
				<a data-toggle="collapse" href="#widget-available_panel-body" id="widgets-available">
321
					<i class="fa-solid fa-plus-circle"></i>
322
				</a>
323
			</span>
324
		</h2>
325
	</div>
326
	<div id="widget-available_panel-body" class="panel-body collapse <?=$panel_body_state?>">
327
		<div class="content">
328
			<div class="row">
329
<?php
330

    
331
// Build the Available Widgets table using a sorted copy of the $known_widgets array
332
$available = $known_widgets;
333
uasort($available, function($a, $b){ return strcasecmp($a['title'], $b['title']); });
334

    
335
foreach ($available as $widgetconfig):
336
	// If the widget supports multiple copies, or no copies are displayed yet, then it is available to add
337
	if (($widgetconfig['multicopy']) || ($widgetconfig['display'] == 'none')):
338
?>
339
		<div class="col-sm-3"><a href="#" id="btnadd-<?=$widgetconfig['basename']?>"><i class="fa-solid fa-plus"></i> <?=$widgetconfig['title']?></a></div>
340
	<?php endif; ?>
341
<?php
342
endforeach;
343
?>
344
			</div>
345
<p style="text-align:center"><?=sprintf(gettext('Other dashboard settings are available from the <a href="%s">General Setup</a> page.'), '/system.php')?></p>
346
		</div>
347
	</div>
348
</div>
349

    
350
<div class="hidden" id="widgetSequence">
351
	<form action="/" method="post" id="widgetSequence_form" name="widgetForm">
352
		<input type="hidden" name="sequence" value="" />
353
	</form>
354
</div>
355

    
356
<?php
357
$widgetColumns = array();
358
foreach ($widgets as $widgetkey => $widgetconfig) {
359
	if ($widgetconfig['display'] != 'none' && file_exists("/usr/local/www/widgets/widgets/{$widgetconfig['basename']}.widget.php")) {
360
		if (!isset($widgetColumns[$widgetconfig['col']])) {
361
			$widgetColumns[$widgetconfig['col']] = array();
362
		}
363
		$widgetColumns[$widgetconfig['col']][$widgetkey] = $widgetconfig;
364
	}
365
}
366
?>
367

    
368
<div class="row">
369
<?php
370
	$columnWidth = (int) (12 / $numColumns);
371

    
372
	for ($currentColumnNumber = 1; $currentColumnNumber <= $numColumns; $currentColumnNumber++) {
373

    
374

    
375
		//if col$currentColumnNumber exists
376
		if (isset($widgetColumns['col'.$currentColumnNumber])) {
377
			echo '<div class="col-md-' . $columnWidth . '" id="widgets-col' . $currentColumnNumber . '">';
378
			$columnWidgets = $widgetColumns['col'.$currentColumnNumber];
379

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

    
387
				// Compose the widget title and include the title link if available
388
				$widgetlink = ${$widgetconfig['basename'] . '_title_link'};
389

    
390
				if ((strlen($widgetlink) > 0)) {
391
					$wtitle = '<a href="' . $widgetlink . '"> ' . $widgetconfig['title'] . '</a>';
392
				} else {
393
					$wtitle = $widgetconfig['title'];
394
				}
395
				?>
396
				<div class="panel panel-default" id="widget-<?=$widgetkey?>">
397
					<div class="panel-heading">
398
						<h2 class="panel-title">
399
							<?=$wtitle?>
400
							<span class="widget-heading-icon">
401
								<a data-toggle="collapse" href="#<?=$widget_panel_footer_id?>" class="config hidden">
402
									<i class="fa-solid fa-wrench"></i>
403
								</a>
404
								<a data-toggle="collapse" href="#<?=$widget_panel_body_id?>">
405
									<!--  actual icon is determined in css based on state of body -->
406
									<i class="fa-solid fa-plus-circle"></i>
407
								</a>
408
								<a data-toggle="close" href="#widget-<?=$widgetkey?>">
409
									<i class="fa-solid fa-times-circle"></i>
410
								</a>
411
							</span>
412
						</h2>
413
					</div>
414
					<div id="<?=$widget_panel_body_id?>" class="panel-body collapse<?=($widgetconfig['display'] == 'close' ? '' : ' in')?>">
415
						<?php
416
							// For backward compatibility, included *.widget.php code needs the var $widgetname
417
							$widgetname = $widgetkey;
418
							// Determine if this is the first instance of this particular widget.
419
							// Provide the $widget_first_instance var, to make it easy for the included widget code
420
							// to be able to know if it is being included for the first time.
421
							if ($widgets_found[$widgetconfig['basename']]) {
422
								$widget_first_instance = false;
423
							} else {
424
								$widget_first_instance = true;
425
								$widgets_found[$widgetconfig['basename']] = true;
426
							}
427
							include('/usr/local/www/widgets/widgets/' . $widgetconfig['basename'] . '.widget.php');
428
						?>
429
					</div>
430
				</div>
431
				<?php
432
			}
433
			echo "</div>";
434
		} else {
435
			echo '<div class="col-md-' . $columnWidth . '" id="widgets-col' . $currentColumnNumber . '"></div>';
436
		}
437

    
438
	}
439
?>
440

    
441
</div>
442

    
443
<?php
444
/*
445
 * Import the modal form used to display the copyright/usage information
446
 * when trigger file exists. Trigger file is created during upgrade process
447
 * when /etc/version changes
448
 */
449
require_once("copyget.inc");
450

    
451
if (file_exists("{$g['cf_conf_path']}/copynotice_display")) {
452
	require_once("copynotice.inc");
453
	@unlink("{$g['cf_conf_path']}/copynotice_display");
454
}
455

    
456
/*
457
 * Import the modal form used to display any HTML text a package may want to display
458
 * on installation or removal
459
 */
460
$ui_notice = "/tmp/package_ui_notice";
461
if (file_exists($ui_notice)) {
462
	require_once("{$g['www_path']}/upgrnotice.inc");
463
}
464
?>
465

    
466
<script type="text/javascript">
467
//<![CDATA[
468

    
469
dirty = false;
470
function updateWidgets(newWidget) {
471
	var sequence = '';
472

    
473
	$('.container .col-md-<?=$columnWidth?>').each(function(idx, col) {
474
		$('.panel', col).each(function(idx, widget) {
475
			var isOpen = $('.panel-body', widget).hasClass('in');
476
			var widget_basename = widget.id.split('-')[1];
477

    
478
			// Only save details for panels that have id's like 'widget-*'
479
			// Some widgets create other panels, so ignore any of those.
480
			if ((widget.id.split('-')[0] == 'widget') && (typeof widget_basename !== 'undefined')) {
481
				sequence += widget_basename + ':' + col.id.split('-')[1] + ':' + (isOpen ? 'open' : 'close') + ':' + widget.id.split('-')[2] + ',';
482
			}
483
		});
484
	});
485

    
486
	if (typeof newWidget !== 'undefined') {
487
		// The system_information widget is always added to column one. Others go in column two
488
		if (newWidget == "system_information") {
489
			sequence += newWidget.split('-')[0] + ':' + 'col1:open:next';
490
		} else {
491
			sequence += newWidget.split('-')[0] + ':' + 'col2:open:next';
492
		}
493
	}
494

    
495
	$('input[name=sequence]', $('#widgetSequence_form')).val(sequence);
496
}
497

    
498
// Determine if all the checkboxes are checked
499
function are_all_checked(checkbox_panel_ref) {
500
	var allBoxesChecked = true;
501
	$(checkbox_panel_ref).each(function() {
502
		if ((this.type == 'checkbox') && !this.checked) {
503
			allBoxesChecked = false;
504
		}
505
	});
506
	return allBoxesChecked;
507
}
508

    
509
// If the checkboxes are all checked, then clear them all.
510
// Otherwise set them all.
511
function set_clear_checkboxes(checkbox_panel_ref) {
512
	checkTheBoxes = !are_all_checked(checkbox_panel_ref);
513

    
514
	$(checkbox_panel_ref).each(function() {
515
		$(this).prop("checked", checkTheBoxes);
516
	});
517
}
518

    
519
// Set the given id to All or None button depending if the checkboxes are all checked.
520
function set_all_none_button(checkbox_panel_ref, all_none_button_id) {
521
	if (are_all_checked(checkbox_panel_ref)) {
522
		text = "<?=gettext('None')?>";
523
	} else {
524
		text = "<?=gettext('All')?>";
525
	}
526

    
527
	$("#" + all_none_button_id).html('<i class="fa-solid fa-undo icon-embed-btn"></i>' + text);
528
}
529

    
530
// Setup the necessary events to manage the All/None button and included checkboxes
531
// used for selecting the items to show on a widget.
532
function set_widget_checkbox_events(checkbox_panel_ref, all_none_button_id) {
533
		set_all_none_button(checkbox_panel_ref, all_none_button_id);
534

    
535
		$(checkbox_panel_ref).change(function() {
536
			set_all_none_button(checkbox_panel_ref, all_none_button_id);
537
		});
538

    
539
		$("#" + all_none_button_id).click(function() {
540
			set_clear_checkboxes(checkbox_panel_ref);
541
			set_all_none_button(checkbox_panel_ref, all_none_button_id);
542
		});
543
}
544

    
545
// ---------------------Centralized widget refresh system -------------------------------------------
546
// These need to live outside of the events.push() function to enable the widgets to see them
547
var ajaxspecs = new Array();	// Array to hold widget refresh specifications (objects )
548
var ajaxidx = 0;
549
var ajaxmutex = false;
550
var ajaxcntr = 0;
551

    
552
// Add a widget refresh object to the array list
553
function register_ajax(ws) {
554
  ajaxspecs.push(ws);
555
}
556
// ---------------------------------------------------------------------------------------------------
557

    
558
events.push(function() {
559
	// Make panels destroyable
560
	$('.container .panel-heading a[data-toggle="close"]').each(function (idx, el) {
561
		$(el).on('click', function(e) {
562
			$(el).parents('.panel').remove();
563
			updateWidgets();
564
			// Submit the form save/display all selected widgets
565
			$('[name=widgetForm]').submit();
566
		})
567
	});
568

    
569
	// Make panels sortable
570
	$('.container .col-md-<?=$columnWidth?>').sortable({
571
		handle: '.panel-heading',
572
		cursor: 'grabbing',
573
		connectWith: '.container .col-md-<?=$columnWidth?>',
574
		update: function(){
575
			dirty = true;
576
			$('#btnstore').removeClass('invisible');
577
		}
578
	});
579

    
580
	// On clicking a widget to install . .
581
	$('[id^=btnadd-]').click(function(event) {
582
		// Add the widget name to the list of displayed widgets
583
		updateWidgets(this.id.replace('btnadd-', ''));
584

    
585
		// Submit the form save/display all selected widgets
586
		$('[name=widgetForm]').submit();
587
	});
588

    
589

    
590
	$('#btnstore').click(function() {
591
		updateWidgets();
592
		dirty = false;
593
		$(this).addClass('invisible');
594
		$('[name=widgetForm]').submit();
595
	});
596

    
597
	// provide a warning message if the user tries to change page before saving
598
	$(window).bind('beforeunload', function(){
599
		if (dirty) {
600
			return ("<?=gettext('One or more widgets have been moved but have not yet been saved')?>");
601
		} else {
602
			return undefined;
603
		}
604
	});
605

    
606
	// 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)
607
	// (Sometimes this will cause us to see the icon when we don't need it, but better that than the other way round)
608
	$('.panel').on('hidden.bs.collapse shown.bs.collapse', function (e) {
609
	    if (e.currentTarget.id != 'widget-available') {
610
			$('#btnstore').removeClass("invisible");
611
		}
612
	});
613

    
614
	// --------------------- Centralized widget refresh system ------------------------------
615
	ajaxtimeout = false;
616

    
617
	function make_ajax_call(wd) {
618
		ajaxmutex = true;
619

    
620
		$.ajax({
621
			type: 'POST',
622
			url: wd.url,
623
			dataType: 'html',
624
			data: wd.parms,
625

    
626
			success: function(data){
627
				if (data.length > 0 ) {
628
					// If the session has timed out, display a pop-up
629
					if (data.indexOf("SESSION_TIMEOUT") === -1) {
630
						wd.callback(data);
631
					} else {
632
						if (ajaxtimeout === false) {
633
							ajaxtimeout = true;
634
							alert("<?=$timeoutmessage?>");
635
						}
636
					}
637
				}
638

    
639
				ajaxmutex = false;
640
			},
641

    
642
			error: function(e){
643
//				alert("Error: " + e);
644
				ajaxmutex = false;
645
			}
646
		});
647
	}
648

    
649
	// Loop through each AJAX widget refresh object, make the AJAX call and pass the
650
	// results back to the widget's callback function
651
	function executewidget() {
652
		if (ajaxspecs.length > 0) {
653
			var freq = ajaxspecs[ajaxidx].freq;	// widget can specify it should be called freq times around the loop
654

    
655
			if (!ajaxmutex) {
656
				if (((ajaxcntr % freq) === 0) && (typeof ajaxspecs[ajaxidx].callback === "function" )) {
657
				    make_ajax_call(ajaxspecs[ajaxidx]);
658
				}
659

    
660
			    if (++ajaxidx >= ajaxspecs.length) {
661
					ajaxidx = 0;
662

    
663
					if (++ajaxcntr >= 4096) {
664
						ajaxcntr = 0;
665
					}
666
			    }
667
			}
668

    
669
		    setTimeout(function() { executewidget(); }, 1000);
670
	  	}
671
	}
672

    
673
	// Kick it off
674
	executewidget();
675

    
676
	//----------------------------------------------------------------------------------------------------
677
});
678
//]]>
679
</script>
680

    
681
<?php
682
//build list of javascript include files
683
foreach (glob('widgets/javascript/*.js') as $file) {
684
	$mtime = filemtime("/usr/local/www/{$file}");
685
	echo '<script src="'.$file.'?v='.$mtime.'"></script>';
686
}
687

    
688
include("foot.inc");
(72-72/232)