1<!-- test -->
2<h4 style='margin-top:30px;'><?php print _('Widgets'); ?></h4>
3<hr>
4<span class="info2"><?php print _("Select widgets to be displayed on dashboard"); ?></span>
5
6
7<script>
8$(document).ready(function() {
9	// initialize sortable
10	$( "#sortable" ).sortable({
11		start: function( event, ui ) {
12			var iid = $(ui.item).attr('id');
13			$('li#'+ iid).addClass('alert alert-success');
14		},
15		stop: function( event, ui ) {
16			var iid = $(ui.item).attr('id');
17			$('li#'+ iid).removeClass('alert alert-success');
18		}
19	});
20
21	//get items
22	$('#submitWidgets').click(function() {
23		//get all ids that are checked
24		var lis = $('#sortable li').map(function(i,n) {
25			//only checked
26			if($(this).find('input').is(':checked')) {
27			return $(n).attr('id');
28			}
29		}).get().join(';');
30
31		//post
32		$.post('app/tools/user-menu/user-widgets-set.php', {widgets: lis, csrf_cookie: '<?php print $csrf; ?>'}, function(data) {
33			$('.userModSelfResultW').html(data).fadeIn('fast');
34		});
35	});
36});
37</script>
38
39
40<?php
41# show all widgets, sortable
42
43//user widgets form database
44$user_widgets = explode(";",$User->user->widgets);	//selected
45$user_widgets = array_filter($user_widgets);
46
47print "<ul id='sortable' class='sortable'>";
48
49# get all widgets
50if($User->user->role=="Administrator") 	{ $widgets = $Tools->fetch_widgets(true, false); }
51else 									{ $widgets = $Tools->fetch_widgets(false, false); }
52
53# first selected widgets already in user database
54if(sizeof($user_widgets)>0) {
55	foreach($user_widgets as $k) {
56		print "<li id='$k'><i class='icon icon-move'></i><input type='checkbox' name='widget-".$widgets[$k]->wfile."' value='on' checked> ".$widgets[$k]->wtitle."</li>";
57	}
58}
59# than others, based on admin or normal user
60foreach($widgets as $k=>$w) {
61	if(!in_array($k, $user_widgets))	{
62	$wtmp = $widgets[$k];
63		print "<li id='$k'><i class='icon icon-move'></i><input type='checkbox' name='widget-".$widgets[$k]->wfile."' value='on'> ".$widgets[$k]->wtitle."</li>";
64	}
65}
66
67print "</ul>";
68?>
69
70<button class='btn btn-sm btn-default' id="submitWidgets"><i class="fa fa-check"></i> <?php print _('Save order'); ?></button>
71
72<!-- result -->
73<div class="userModSelfResultW" style="margin-bottom:90px;display:none"></div>