Project

General

Profile

Download (14.9 KB) Statistics
| Branch: | Tag: | Revision:
1 2cd6010c Scott Ullrich
<?php
2 5b237745 Scott Ullrich
/*
3 c5d81585 Renato Botelho
 * index.php
4
 *
5
 * part of pfSense (https://www.pfsense.org)
6 81299b5c Renato Botelho
 * Copyright (c) 2004-2016 Rubicon Communications, LLC (Netgate)
7 c5d81585 Renato Botelho
 * 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 b12ea3fb Renato Botelho
 * 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 c5d81585 Renato Botelho
 *
17 b12ea3fb Renato Botelho
 * http://www.apache.org/licenses/LICENSE-2.0
18 c5d81585 Renato Botelho
 *
19 b12ea3fb Renato Botelho
 * 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 fd9ebcd5 Stephen Beaver
 */
25 5b237745 Scott Ullrich
26 6b07c15a Matthew Grooms
##|+PRIV
27 5d916fc7 Stephen Beaver
##|*IDENT=page-system-login-logout
28 5230f468 jim-p
##|*NAME=System: Login / Logout / Dashboard
29 b7ccf315 Erik Fonnesbeck
##|*DESCR=Allow access to the 'System: Login / Logout' page and Dashboard.
30 6b07c15a Matthew Grooms
##|*MATCH=index.php*
31
##|-PRIV
32
33 acc5dd59 jim-p
// Turn on buffering to speed up rendering
34 6c07db48 Phil Davis
ini_set('output_buffering', 'true');
35 acc5dd59 jim-p
36
// Start buffering with a cache size of 100000
37
ob_start(null, "1000");
38 880637d2 Scott Ullrich
39 acc5dd59 jim-p
## Load Essential Includes
40
require_once('guiconfig.inc');
41 32e834ff Ermal LUÇI
require_once('functions.inc');
42 acc5dd59 jim-p
require_once('notices.inc');
43 7c8f3711 jim-p
require_once("pkg-utils.inc");
44 acc5dd59 jim-p
45 329a1cd5 Stephen Beaver
if (isset($_POST['closenotice'])) {
46
	close_notice($_POST['closenotice']);
47
	sleep(1);
48 005ac3ca Marcello Coutinho
	exit;
49
}
50
51 0206483d Stephen Beaver
if (isset($_GET['closenotice'])) {
52
	close_notice($_GET['closenotice']);
53
	sleep(1);
54
}
55
56 41b1ff89 Phil Davis
if ($g['disablecrashreporter'] != true) {
57 36365f49 Scott Ullrich
	// Check to see if we have a crash report
58 eac584f3 Scott Ullrich
	$x = 0;
59 41b1ff89 Phil Davis
	if (file_exists("/tmp/PHP_errors.log")) {
60 918f0a94 NewEraCracker
		$total = `/bin/cat /tmp/PHP_errors.log | /usr/bin/wc -l | /usr/bin/awk '{ print $1 }'`;
61 41b1ff89 Phil Davis
		if ($total > 0) {
62 a9ee006d Scott Ullrich
			$x++;
63 41b1ff89 Phil Davis
		}
64 a9ee006d Scott Ullrich
	}
65 60e27eb0 Stephen Beaver
66 a9ee006d Scott Ullrich
	$crash = glob("/var/crash/*");
67 36365f49 Scott Ullrich
	$skip_files = array(".", "..", "minfree", "");
68 60e27eb0 Stephen Beaver
69 41b1ff89 Phil Davis
	if (is_array($crash)) {
70
		foreach ($crash as $c) {
71
			if (!in_array(basename($c), $skip_files)) {
72 36365f49 Scott Ullrich
				$x++;
73 41b1ff89 Phil Davis
			}
74 36365f49 Scott Ullrich
		}
75 60e27eb0 Stephen Beaver
76 41b1ff89 Phil Davis
		if ($x > 0) {
77 8545adde k-paulius
			$savemsg = sprintf(gettext("%s has detected a crash report or programming bug. Click <a href='crash_reporter.php'>here</a> for more information."), $g['product_name']);
78 c8532336 Phil Davis
			$class = "warning";
79 41b1ff89 Phil Davis
		}
80 104faa07 Scott Ullrich
	}
81
}
82
83 ef325a6c Phil Davis
##build list of php include files
84
$phpincludefiles = array();
85
$directory = "/usr/local/www/widgets/include/";
86
$dirhandle = opendir($directory);
87
$filename = "";
88
89
while (false !== ($filename = readdir($dirhandle))) {
90 dffe24be NewEraCracker
	if (!stristr($filename, ".inc")) {
91
		continue;
92
	}
93 ef325a6c Phil Davis
	$phpincludefiles[] = $filename;
94
}
95
96
## Include each widget include file.
97
## These define vars that specify the widget title and title link.
98
foreach ($phpincludefiles as $includename) {
99
	if (file_exists($directory . $includename)) {
100 86573bb9 Phil Davis
		include_once($directory . $includename);
101 ef325a6c Phil Davis
	}
102
}
103
104 acc5dd59 jim-p
##build list of widgets
105 aa82505e Phil Davis
foreach (glob("/usr/local/www/widgets/widgets/*.widget.php") as $file) {
106 41ea4cf3 Sjon Hortensius
	$name = basename($file, '.widget.php');
107 ef325a6c Phil Davis
	// Get the widget title that should be in a var defined in the widget's inc file.
108
	$widgettitle = ${$name . '_title'};
109
110 dffe24be NewEraCracker
	if (empty(trim($widgettitle))) {
111 ef325a6c Phil Davis
		// Fall back to constructing a title from the file name of the widget.
112
		$widgettitle = ucwords(str_replace('_', ' ', $name));
113
	}
114
115
	$widgets[ $name ] = array('name' => $widgettitle, 'display' => 'none');
116 acc5dd59 jim-p
}
117
118
##if no config entry found, initialize config entry
119
if (!is_array($config['widgets'])) {
120
	$config['widgets'] = array();
121
}
122 5aad7323 NewEraCracker
if (!is_array($user_settings['widgets'])) {
123
	$user_settings['widgets'] = array();
124
}
125 d772ac32 Erik Kristensen
126 41ea4cf3 Sjon Hortensius
if ($_POST && $_POST['sequence']) {
127 60e27eb0 Stephen Beaver
128 2b7d0520 Phil Davis
	// Start with the user's widget settings.
129
	$widget_settings = $user_settings['widgets'];
130 236e6a54 Stephen Beaver
131 8bab524e Phil Davis
	$widget_settings['sequence'] = rtrim($_POST['sequence'], ',');
132 8191b36e Scott Ullrich
133 1c428d53 Phil Davis
	foreach ($widgets as $widgetname => $widgetconfig) {
134
		if ($_POST[$widgetname . '-config']) {
135 8bab524e Phil Davis
			$widget_settings[$widgetname . '-config'] = $_POST[$widgetname . '-config'];
136 8191b36e Scott Ullrich
		}
137
	}
138
139 8bab524e Phil Davis
	save_widget_settings($_SESSION['Username'], $widget_settings);
140 69b397dd Sjon Hortensius
	header("Location: /");
141 1180e4f0 Sjon Hortensius
	exit;
142
}
143 757733b5 Renato Botelho
144 1180e4f0 Sjon Hortensius
## Load Functions Files
145
require_once('includes/functions.inc.php');
146 d772ac32 Erik Kristensen
147 1180e4f0 Sjon Hortensius
## Check to see if we have a swap space,
148
## if true, display, if false, hide it ...
149 1c428d53 Phil Davis
if (file_exists("/usr/sbin/swapinfo")) {
150 1180e4f0 Sjon Hortensius
	$swapinfo = `/usr/sbin/swapinfo`;
151 1c428d53 Phil Davis
	if (stristr($swapinfo, '%') == true) $showswap=true;
152 1180e4f0 Sjon Hortensius
}
153
154
## User recently restored his config.
155
## If packages are installed lets resync
156 1c428d53 Phil Davis
if (file_exists('/conf/needs_package_sync')) {
157
	if ($config['installedpackages'] <> '' && is_array($config['installedpackages']['package'])) {
158 dc61252a Renato Botelho
		## If the user has logged into webGUI quickly while the system is booting then do not redirect them to
159
		## the package reinstall page. That is about to be done by the boot script anyway.
160
		## The code in head.inc will put up a notice to the user.
161
		if (!platform_booting()) {
162
			header('Location: pkg_mgr_install.php?mode=reinstallall');
163
			exit;
164 1df0159c Erik Kristensen
		}
165 1180e4f0 Sjon Hortensius
	} else {
166
		@unlink('/conf/needs_package_sync');
167 1df0159c Erik Kristensen
	}
168 1180e4f0 Sjon Hortensius
}
169 8fecad11 Scott Ullrich
170 1180e4f0 Sjon Hortensius
## If it is the first time webConfigurator has been
171
## accessed since initial install show this stuff.
172 1c428d53 Phil Davis
if (file_exists('/conf/trigger_initial_wizard')) {
173 1180e4f0 Sjon Hortensius
?>
174
<!DOCTYPE html>
175
<html lang="en">
176 702b324e Scott Ullrich
<head>
177 f0c5e7c1 Jared Dillard
	<link rel="stylesheet" href="/css/pfSense.css" />
178 5bca8df4 Stephen Beaver
	<title><?=$g['product_name']?>.localdomain - <?=$g['product_name']?> first time setup</title>
179 1180e4f0 Sjon Hortensius
	<meta http-equiv="refresh" content="1;url=wizard.php?xml=setup_wizard.xml" />
180
</head>
181
<body id="loading-wizard" class="no-menu">
182
	<div id="jumbotron">
183
		<div class="container">
184 c7d61071 Sander van Leeuwen
			<div class="col-sm-offset-3 col-sm-6 col-xs-12">
185 40547fe4 Stephen Beaver
				<font color="white">
186
				<p><h3><?=sprintf(gettext("Welcome to %s!\n"), $g['product_name'])?></h3></p>
187 1e87fb3f Phil Davis
				<p><?=gettext("One moment while the initial setup wizard starts.")?></p>
188 c7d61071 Sander van Leeuwen
				<p><?=gettext("Embedded platform users: Please be patient, the wizard takes a little longer to run than the normal GUI.")?></p>
189 1c428d53 Phil Davis
				<p><?=sprintf(gettext("To bypass the wizard, click on the %s logo on the initial page."), $g['product_name'])?></p>
190 40547fe4 Stephen Beaver
				</font>
191 c7d61071 Sander van Leeuwen
			</div>
192 1180e4f0 Sjon Hortensius
		</div>
193
	</div>
194
</body>
195
</html>
196
<?php
197
	exit;
198
}
199 bf787c0a Scott Ullrich
200 1180e4f0 Sjon Hortensius
## Find out whether there's hardware encryption or not
201
unset($hwcrypto);
202
$fd = @fopen("{$g['varlog_path']}/dmesg.boot", "r");
203
if ($fd) {
204
	while (!feof($fd)) {
205
		$dmesgl = fgets($fd);
206
		if (preg_match("/^hifn.: (.*?),/", $dmesgl, $matches)
207
			or preg_match("/.*(VIA Padlock)/", $dmesgl, $matches)
208
			or preg_match("/^safe.: (\w.*)/", $dmesgl, $matches)
209
			or preg_match("/^ubsec.: (.*?),/", $dmesgl, $matches)
210 2ce5cd33 jim-p
			or preg_match("/^padlock.: <(.*?)>,/", $dmesgl, $matches)) {
211 1180e4f0 Sjon Hortensius
			$hwcrypto = $matches[1];
212
			break;
213 5b237745 Scott Ullrich
		}
214
	}
215 1180e4f0 Sjon Hortensius
	fclose($fd);
216 aa82505e Phil Davis
	if (!isset($hwcrypto) && get_single_sysctl("dev.aesni.0.%desc")) {
217 a2e6d7f8 Luiz Otavio O Souza
		$hwcrypto = get_single_sysctl("dev.aesni.0.%desc");
218 aa82505e Phil Davis
	}
219 1180e4f0 Sjon Hortensius
}
220 45ee90ed Matthew Grooms
221 7abf7db5 Scott Dale
##build widget saved list information
222 8bab524e Phil Davis
if ($user_settings['widgets']['sequence'] != "") {
223
	$dashboardcolumns = isset($user_settings['webgui']['dashboardcolumns']) ? $user_settings['webgui']['dashboardcolumns'] : 2;
224
	$pconfig['sequence'] = $user_settings['widgets']['sequence'];
225 1180e4f0 Sjon Hortensius
	$widgetsfromconfig = array();
226 757733b5 Renato Botelho
227 aa82505e Phil Davis
	foreach (explode(',', $pconfig['sequence']) as $line) {
228 1180e4f0 Sjon Hortensius
		list($file, $col, $display) = explode(':', $line);
229
230
		// be backwards compatible
231 72eaefaf Stephen Beaver
		// If the display column information is missing, we will assign a temporary
232
		// column here. Next time the user saves the dashboard it will fix itself
233
		if ($col == "") {
234
			if ($file == "system_information") {
235
				$col = "col1";
236
			} else {
237
				$col = "col2";
238
			}
239
		}
240
241 ad51eb90 Phil Davis
		// Limit the column to the current dashboard columns.
242
		if (substr($col, 3) > $dashboardcolumns) {
243
			$col = "col" . $dashboardcolumns;
244
		}
245
246 1180e4f0 Sjon Hortensius
		$offset = strpos($file, '-container');
247 94704bc6 Phil Davis
		if (false !== $offset) {
248 1180e4f0 Sjon Hortensius
			$file = substr($file, 0, $offset);
249 94704bc6 Phil Davis
		}
250 1180e4f0 Sjon Hortensius
251 ef325a6c Phil Davis
		// Get the widget title that should be in a var defined in the widget's inc file.
252
		$widgettitle = ${$file . '_title'};
253
254 dffe24be NewEraCracker
		if (empty(trim($widgettitle))) {
255 ef325a6c Phil Davis
			// Fall back to constructing a title from the file name of the widget.
256
			$widgettitle = ucwords(str_replace('_', ' ', $file));
257
		}
258
259 1180e4f0 Sjon Hortensius
		$widgetsfromconfig[ $file ] = array(
260 ef325a6c Phil Davis
			'name' => $widgettitle,
261 1180e4f0 Sjon Hortensius
			'col' => $col,
262
			'display' => $display,
263
		);
264 1db766df Scott Dale
	}
265 757733b5 Renato Botelho
266 5c7657d6 Renato Botelho
	// add widgets that may not be in the saved configuration, in case they are to be displayed later
267 69b397dd Sjon Hortensius
	$widgets = $widgetsfromconfig + $widgets;
268 757733b5 Renato Botelho
269 019a94df Scott Dale
	##find custom configurations of a particular widget and load its info to $pconfig
270 1c428d53 Phil Davis
	foreach ($widgets as $widgetname => $widgetconfig) {
271 75ae3d1c Phil Davis
		if ($config['widgets'][$widgetname . '-config']) {
272
			$pconfig[$widgetname . '-config'] = $config['widgets'][$widgetname . '-config'];
273 757733b5 Renato Botelho
		}
274
	}
275 3e4e94ce Scott Dale
}
276
277 c05363c8 NOYB
## Get the configured options for Show/Hide available widgets panel.
278 8bab524e Phil Davis
$dashboard_available_widgets_hidden = !$user_settings['webgui']['dashboardavailablewidgetspanel'];
279 c05363c8 NOYB
280
if ($dashboard_available_widgets_hidden) {
281
	$panel_state = 'out';
282
	$panel_body_state = 'in';
283
} else {
284
	$panel_state = 'in';
285
	$panel_body_state = 'out';
286
}
287
288 1db766df Scott Dale
## Set Page Title and Include Header
289 2734d2db Jared Dillard
$pgtitle = array(gettext("Status"), gettext("Dashboard"));
290 1db766df Scott Dale
include("head.inc");
291 f6f6947e Scott Ullrich
292 41b1ff89 Phil Davis
if ($savemsg) {
293 c8532336 Phil Davis
	print_info_box($savemsg, $class);
294 41b1ff89 Phil Davis
}
295 fca795f8 Scott Ullrich
296 810a11bc Scott Ullrich
pfSense_handle_custom_code("/usr/local/pkg/dashboard/pre_dashboard");
297 c69c58e2 Vinicius Coque
298 0682e26b Colin Smith
?>
299 1180e4f0 Sjon Hortensius
300 c05363c8 NOYB
<div class="panel panel-default collapse <?=$panel_state?>" id="widget-available">
301 95fa5cce Phil Davis
	<div class="panel-heading">
302
		<h2 class="panel-title"><?=gettext("Available Widgets"); ?>
303
			<span class="widget-heading-icon">
304
				<a data-toggle="collapse" href="#widget-available_panel-body" id="widgets-available">
305
					<i class="fa fa-plus-circle"></i>
306
				</a>
307
			</span>
308
		</h2>
309 166b0099 Stephen Beaver
	</div>
310 c05363c8 NOYB
	<div id="widget-available_panel-body" class="panel-body collapse <?=$panel_body_state?>">
311 9239f765 Jared Dillard
		<div class="content">
312
			<div class="row">
313 60e27eb0 Stephen Beaver
<?php
314 e76931e2 Stephen Beaver
315
// Build the Available Widgets table using a sorted copy of the $widgets array
316
$available = $widgets;
317 dffe24be NewEraCracker
uasort($available, function($a, $b){ return strcasecmp($a['name'], $b['name']); });
318 e76931e2 Stephen Beaver
319
foreach ($available as $widgetname => $widgetconfig):
320 60e27eb0 Stephen Beaver
	if ($widgetconfig['display'] == 'none'):
321
?>
322 a508c6e4 NOYB
		<div class="col-sm-3"><a href="#" id="btnadd-<?=$widgetname?>"><i class="fa fa-plus"></i> <?=$widgetconfig['name']?></a></div>
323 a2faa388 Sander van Leeuwen
	<?php endif; ?>
324
<?php endforeach; ?>
325 9239f765 Jared Dillard
			</div>
326
		</div>
327 1db766df Scott Dale
	</div>
328
</div>
329
330 a2faa388 Sander van Leeuwen
<div class="hidden" id="widgetSequence">
331 a508c6e4 NOYB
	<form action="/" method="post" id="widgetSequence_form" name="widgetForm">
332 41ea4cf3 Sjon Hortensius
		<input type="hidden" name="sequence" value="" />
333
	</form>
334
</div>
335
336 1180e4f0 Sjon Hortensius
<?php
337 41ea4cf3 Sjon Hortensius
$widgetColumns = array();
338 aa82505e Phil Davis
foreach ($widgets as $widgetname => $widgetconfig) {
339
	if ($widgetconfig['display'] == 'none') {
340 41ea4cf3 Sjon Hortensius
		continue;
341 aa82505e Phil Davis
	}
342 41ea4cf3 Sjon Hortensius
343 e8bd1464 Renato Botelho
	if (!file_exists('/usr/local/www/widgets/widgets/'. $widgetname.'.widget.php')) {
344
		continue;
345
	}
346
347 aa82505e Phil Davis
	if (!isset($widgetColumns[ $widgetconfig['col'] ])) {
348 41ea4cf3 Sjon Hortensius
		$widgetColumns[ $widgetconfig['col'] ] = array();
349 aa82505e Phil Davis
	}
350 41ea4cf3 Sjon Hortensius
351
	$widgetColumns[ $widgetconfig['col'] ][ $widgetname ] = $widgetconfig;
352
}
353 1180e4f0 Sjon Hortensius
?>
354 41ea4cf3 Sjon Hortensius
355 a2faa388 Sander van Leeuwen
<div class="row">
356 2063a534 Jared Dillard
<?php
357 477db933 Jared Dillard
	$columnWidth = 12 / $numColumns;
358 a54d69c8 Stephen Beaver
359 e3843a08 Phil Davis
	for ($currentColumnNumber = 1; $currentColumnNumber <= $numColumns; $currentColumnNumber++) {
360 cee365e6 Stephen Beaver
361 2063a534 Jared Dillard
362 e3843a08 Phil Davis
		//if col$currentColumnNumber exists
363
		if (isset($widgetColumns['col'.$currentColumnNumber])) {
364 caf897c8 Jared Dillard
			echo '<div class="col-md-' . $columnWidth . '" id="widgets-col' . $currentColumnNumber . '">';
365 e3843a08 Phil Davis
			$columnWidgets = $widgetColumns['col'.$currentColumnNumber];
366 2063a534 Jared Dillard
367
			foreach ($columnWidgets as $widgetname => $widgetconfig) {
368
				// Compose the widget title and include the title link if available
369
				$widgetlink = ${$widgetname . '_title_link'};
370
371
				if ((strlen($widgetlink) > 0)) {
372
					$wtitle = '<a href="' . $widgetlink . '"> ' . $widgetconfig['name'] . '</a>';
373
				} else {
374
					$wtitle = $widgetconfig['name'];
375
				}
376
				?>
377
					<div class="panel panel-default" id="widget-<?=$widgetname?>">
378
					<div class="panel-heading">
379 95fa5cce Phil Davis
						<h2 class="panel-title">
380
							<?=$wtitle?>
381
							<span class="widget-heading-icon">
382
								<a data-toggle="collapse" href="#widget-<?=$widgetname?>_panel-footer" class="config hidden">
383
									<i class="fa fa-wrench"></i>
384
								</a>
385
								<a data-toggle="collapse" href="#widget-<?=$widgetname?>_panel-body">
386
									<!--  actual icon is determined in css based on state of body -->
387
									<i class="fa fa-plus-circle"></i>
388
								</a>
389
								<a data-toggle="close" href="#widget-<?=$widgetname?>">
390
									<i class="fa fa-times-circle"></i>
391
								</a>
392
							</span>
393
						</h2>
394 2063a534 Jared Dillard
					</div>
395
					<div id="widget-<?=$widgetname?>_panel-body" class="panel-body collapse<?=($widgetconfig['display'] == 'close' ? '' : ' in')?>">
396 86573bb9 Phil Davis
						<?php include_once('/usr/local/www/widgets/widgets/'. $widgetname.'.widget.php'); ?>
397 2063a534 Jared Dillard
					</div>
398
				</div>
399
				<?php
400
			}
401 6fefbd48 Jared Dillard
			echo "</div>";
402 a54d69c8 Stephen Beaver
		} else {
403 caf897c8 Jared Dillard
			echo '<div class="col-md-' . $columnWidth . '" id="widgets-col' . $currentColumnNumber . '"></div>';
404 a54d69c8 Stephen Beaver
		}
405 cee365e6 Stephen Beaver
406 477db933 Jared Dillard
	}
407
?>
408 2063a534 Jared Dillard
409 a2faa388 Sander van Leeuwen
</div>
410 561d55ff Erik Kristensen
411 8fd9052f Colin Fleming
<script type="text/javascript">
412
//<![CDATA[
413 eae6b58d Stephen Beaver
414
dirty = false;
415 aa82505e Phil Davis
function updateWidgets(newWidget) {
416 7f8f8808 Sjon Hortensius
	var sequence = '';
417
418 aa82505e Phil Davis
	$('.container .col-md-<?=$columnWidth?>').each(function(idx, col) {
419
		$('.panel', col).each(function(idx, widget) {
420 7f8f8808 Sjon Hortensius
			var isOpen = $('.panel-body', widget).hasClass('in');
421
422 94704bc6 Phil Davis
			sequence += widget.id.split('-')[1] + ':' + col.id.split('-')[1] + ':' + (isOpen ? 'open' : 'close') + ',';
423 7f8f8808 Sjon Hortensius
		});
424
	});
425
426 aa82505e Phil Davis
	if (typeof newWidget !== 'undefined') {
427 b5ff58cf Stephen Beaver
		// The system_information widget is always added to column one. Others go in column two
428
		if (newWidget == "system_information") {
429
			sequence += newWidget + ':' + 'col1:open';
430
		} else {
431 f4a15d29 Stephen Beaver
		sequence += newWidget + ':' + 'col2:open';
432 b5ff58cf Stephen Beaver
		}
433 aa82505e Phil Davis
	}
434 60e27eb0 Stephen Beaver
435 a508c6e4 NOYB
	$('input[name=sequence]', $('#widgetSequence_form')).val(sequence);
436 7f8f8808 Sjon Hortensius
}
437
438 dc58b7b3 Sjon Hortensius
events.push(function() {
439
440
	// Make panels destroyable
441 aa82505e Phil Davis
	$('.container .panel-heading a[data-toggle="close"]').each(function (idx, el) {
442
		$(el).on('click', function(e) {
443 7f8f8808 Sjon Hortensius
			$(el).parents('.panel').remove();
444
			updateWidgets();
445 eae6b58d Stephen Beaver
			// Submit the form save/display all selected widgets
446
			$('[name=widgetForm]').submit();
447 dc58b7b3 Sjon Hortensius
		})
448
	});
449
450
	// Make panels sortable
451 477db933 Jared Dillard
	$('.container .col-md-<?=$columnWidth?>').sortable({
452 dc58b7b3 Sjon Hortensius
		handle: '.panel-heading',
453
		cursor: 'grabbing',
454 477db933 Jared Dillard
		connectWith: '.container .col-md-<?=$columnWidth?>',
455 91d59881 NOYB
		update: function(){
456
			dirty = true;
457
			$('#btnstore').removeClass('invisible');
458
		}
459 dc58b7b3 Sjon Hortensius
	});
460 60e27eb0 Stephen Beaver
461
	// On clicking a widget to install . .
462 a508c6e4 NOYB
	$('[id^=btnadd-]').click(function(event) {
463 f4a15d29 Stephen Beaver
		// Add the widget name to the list of displayed widgets
464 a508c6e4 NOYB
		updateWidgets(this.id.replace('btnadd-', ''));
465 60e27eb0 Stephen Beaver
466
		// Submit the form save/display all selected widgets
467
		$('[name=widgetForm]').submit();
468
	});
469
470 eae6b58d Stephen Beaver
471 e94f260c Stephen Beaver
	$('#btnstore').click(function() {
472
		updateWidgets();
473
		dirty = false;
474 91d59881 NOYB
		$(this).addClass('invisible');
475 e94f260c Stephen Beaver
		$('[name=widgetForm]').submit();
476
	});
477 eae6b58d Stephen Beaver
478
	// provide a warning message if the user tries to change page before saving
479
	$(window).bind('beforeunload', function(){
480
		if (dirty) {
481 530c7ccf NOYB
			return ("<?=gettext('One or more widgets have been moved but have not yet been saved')?>");
482 eae6b58d Stephen Beaver
		} else {
483
			return undefined;
484
		}
485
	});
486 cee365e6 Stephen Beaver
487
	// 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)
488
	// (Sometimes this will cause us to see the icon when we don't need it, but better that than the other way round)
489
	$('.panel').on('hidden.bs.collapse shown.bs.collapse', function (e) {
490
	    if (e.currentTarget.id != 'widget-available') {
491
			$('#btnstore').removeClass("invisible");
492
		}
493
	});
494 dc58b7b3 Sjon Hortensius
});
495 8fd9052f Colin Fleming
//]]>
496 dc58b7b3 Sjon Hortensius
</script>
497 41ea4cf3 Sjon Hortensius
<?php
498 1180e4f0 Sjon Hortensius
//build list of javascript include files
499 aa82505e Phil Davis
foreach (glob('widgets/javascript/*.js') as $file) {
500 1180e4f0 Sjon Hortensius
	echo '<script src="'.$file.'"></script>';
501 aa82505e Phil Davis
}
502 927ea6e1 jim-p
503 1c428d53 Phil Davis
include("foot.inc");