-
Notifications
You must be signed in to change notification settings - Fork 8
/
group_view.php
1735 lines (1622 loc) · 79.7 KB
/
group_view.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/*
All Emoncms code is released under the GNU Affero General Public License.
See COPYRIGHT.txt and LICENSE.txt.
---------------------------------------------------------------------
Emoncms - open source energy visualisation
Part of the OpenEnergyMonitor project:
http://openenergymonitor.org
Group module has been developed by Carbon Co-op
https://carbon.coop/
*/
defined('EMONCMS_EXEC') or die('Restricted access');
global $path, $session, $appname;
global $groups_email_subject, $groups_email_body;
$v = 1;
?>
<link href="<?php echo $path; ?>Modules/group/group.css?v=<?php echo $v ?>" rel="stylesheet">
<script language="javascript" type="text/javascript" src="<?php echo $path; ?>Modules/group/group.js?v=<?php echo $v ?>"></script>
<link href="<?php echo $path; ?>Lib/bootstrap-datetimepicker-0.0.11/css/bootstrap-datetimepicker.min.css" rel="stylesheet">
<script type="text/javascript" src="<?php echo $path; ?>Lib/bootstrap-datetimepicker-0.0.11/js/bootstrap-datetimepicker.min.js"></script>
<script type="text/javascript" src="<?php echo $path; ?>Modules/user/user.js"></script>
<?php if ($task_support === true) { ?>
<script language="javascript" type="text/javascript" src="<?php echo $path; ?>Modules/task/task.js"></script>
<script type="text/javascript" src="<?php echo $path; ?>Lib/tablejs/table.js"></script>
<script type="text/javascript" src="<?php echo $path; ?>Lib/tablejs/custom-table-fields.js"></script>
<script type="text/javascript" src="<?php echo $path; ?>Modules/task/task-custom-table-fields.js"></script>
<?php } ?>
<!-------------------------------------------------------------------------------------------
MAIN
-------------------------------------------------------------------------------------------->
<div class="page-content" style="padding-top:15px">
<div style="padding-bottom:15px">
<button class="btn" id="sidebar-open" style="display:none"><i class="icon-list"></i></button>
<!--<div id="create-inputs-feeds" class="if-admin groupselected"><i class="icon-trash"></i>Update inputs/feeds</div>-->
<button id="deletegroup" class="btn if-admin groupselected"><i class="icon-trash"></i> Delete group</button>
<button id="editgroup" class="btn if-admin groupselected"><i class="icon-edit"></i> Edit Group</button>
<button id="createuseraddtogroup" class="btn if-admin groupselected"><i class="icon-plus"></i> Create User</button>
<button id="addmember" class="btn if-admin groupselected"><i class="icon-plus"></i> Add Member</button>
<div class="userstitle"><span id="groupname">Users</span></div>
<div id="groupdescription"></div>
</div>
<div class="table-headers hide groupselected">
<div class="user-name">Username</div>
<div class="user-active-feeds">Feeds <i title="- Green: update time < 25s
- Amber: 25s < update time < 60s
- Orange: 60s < update time < 2h
- Redr: 2h < update time" class=" icon-question-sign"></i></div>
<div class="user-role">Role <i title="- Administrator: full access (create users, add member, create group feeds, dashboards graphs, etc) - Sub-administrator: view access to the list of members, write access to group graphs - Passive member: no access to group. The aim of the user is to be managed by the group administrator" class=" icon-question-sign"></i></div>
<div class="multiple-feeds-actions">
<button class="btn feed-graph hide" title="Graph view"><i class="icon-eye-open"></i></button>
<button class="btn multiple-feed-download hide" title="Download feeds" type="multiple"><i class="icon-download"></i></button>
<button class="btn create-task hide if-admin" title="Create task"><i class="icon-list"></i></button>
</div>
</div>
<div id="userlist-div" class="hide"></div>
<div id="userlist-alert" class="alert alert-block hide">
<h4 class="alert-heading"></h4>
<p></p>
</div>
<div id="nogroupselected" class="alert alert-block">
<h4 class="alert-heading">No Group Selected</h4>
<p>Select or create group from sidebar</p>
</div>
</div>
<!-------------------------------------------------------------------------------------------
MODALS
-------------------------------------------------------------------------------------------->
<div id="snackbar"></div>
<!-- GROUP CREATE -->
<div id="group-create-modal" class="modal hide" tabindex="-1" role="dialog" aria-labelledby="group-create-modal-label" aria-hidden="true" data-backdrop="static">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="group-create-modal-label">Create New Group</h3>
</div>
<div class="modal-body">
<p>Group Name:<br>
<input id="group-create-name" type="text" maxlength="64"></p>
<p>Group Description:<br>
<input id="group-create-description" type="text" maxlength="256"></p>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true">Cancel</button>
<button id="group-create-action" class="btn btn-primary">Create</button>
</div>
</div>
<!-- ADD MEMBER TO GROUP -->
<div id="group-addmember-modal" class="modal hide" tabindex="-1" role="dialog" aria-labelledby="group-addmember-modal-label" aria-hidden="true" data-backdrop="static">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="group-addmember-modal-label">Add member to group</h3>
</div>
<div class="modal-body">
<p>Username:<br>
<input id="group-addmember-username" type="text"></p>
<p>Password:<br>
<input id="group-addmember-password" type="password">
<button class="generate-password btn" style="margin-bottom: 10px"><i class="icon-eye-open show-password"></i> Generate pasword</button></p>
<p>Role <i title="- Administrator: full access (create users, add member, create group feeds, dashboards graphs, etc) - Sub-administrator: view access to the list of members, write access to group graphs - Passive member: no access to group. The aim of the user is to be managed by the group administrator" class=" icon-question-sign"></i>:</p>
<select id="group-addmember-access">
<option value=1>Administrator</option>
<option value=2>Sub-administrator</option>
<!--<option value=3>Member</option>-->
<option value=0 selected>Passive member</option>
</select>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true">Cancel</button>
<button id="group-addmember-action" class="btn btn-primary">Add</button>
</div>
</div>
<!-- CREATE USER AND ADD MEMBER TO GROUP -->
<div id="group-createuseraddtogroup-modal" class="modal hide" tabindex="-1" role="dialog" aria-labelledby="group-createuseraddtogroup-modal-label" aria-hidden="true" data-backdrop="static">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="group-addmember-modal-label">Create user and add to group</h3>
</div>
<div class="modal-body">
<p>Name:<br>
<input id="group-createuseraddtogroup-name" type="text"></p>
<p>Email:<br>
<input id="group-createuseraddtogroup-email" type="email"></p>
<p>Username:<br>
<input id="group-createuseraddtogroup-username" type="text"></p>
<p>Password:<br>
<input id="group-createuseraddtogroup-password" type="password">
<button class="generate-password btn" style="margin-bottom: 10px"><i class="icon-eye-open show-password"></i> Generate pasword</button></p>
<p>Confirm password:<br>
<input id="group-createuseraddtogroup-password-confirm" type="password"></p>
<p>Role <i title="- Administrator: full access (create users, add member, create group feeds, dashboards graphs, etc) - Sub-administrator: view access to the list of members, write access to group graphs - Passive member: no access to group. The aim of the user is to be managed by the group administrator" class=" icon-question-sign"></i>:</p>
<select id="group-createuseraddtogroup-role">
<option value=1>Administrator</option>
<option value=2>Sub-administrator</option>
<!--<option value=3>Member</option>-->
<option value=0 selected>Passive member</option>
</select>
<p style='margin-left:5px'>
<input type="checkbox" id="group-createuseraddtogroup-send-email" class="toogle-email-div" style="margin-bottom: 8px; width: 20px; height: 20px">
<label for="group-createuseraddtogroup-send-email" style="display: inline-block">Send login details to user's email</label>
</p>
<div id="group-createuseraddtogroup-email-div" class="email-div" style="display:none">
<p>Subject</p>
<input type="text" id="group-createuseraddtogroup-email-subject" />
<p>Body (in html)</p>
<textarea id="group-createuseraddtogroup-email-body"></textarea>
<input type="checkbox" id="group-createuseraddtogroup-send-copy" /><label for="group-createuseraddtogroup-send-copy" style="display: inline-block">Send me a copy</label>
<p>You can use the following wildcards: {{name}}, {{username}}, {{password}}, {{role}}, {{appname}}<i class="icon-question-sign" title="<?php echo $appname ?>" /></i> and {{path}}<i class="icon-question-sign" title="<?php echo $path ?>"> </i></p>
</div>
<div id="createuseraddtogroup-message"></div>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true">Cancel</button>
<button id="group-createuseraddtogroup-action" class="btn btn-primary">Create and add to group</button>
</div>
</div>
<!-- REMOVE USER -->
<div id="remove-user-modal" class="modal hide" tabindex="-1" role="dialog" aria-labelledby="remove-user-modal-label" aria-hidden="true" data-backdrop="static">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="remove-user-modal-label">Remove user</h3>
</div>
<div class="modal-body">
<span id="remove-user-modal-step-1">
<p>What do you want to do?</p>
<div class="radio"><input type="radio" name="removeuser-whattodo" id="removeuser-from-group" value="remove-from-group" /><label for="removeuser-from-group">Remove user from group</label></div>
<div class="radio"><input type="radio" name="removeuser-whattodo" id="removeuser-delete" value="delete" /><label for="removeuser-delete">Completely remove user from database</label></div>
</span>
<span id="remove-user-modal-step-2" style="display:none"></span>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true">Cancel</button>
<button id="remove-user-action" action="next" class="btn btn-danger">Next</button>
</div>
</div>
<!-- EDIT USER -->
<div id="edit-user-modal" class="modal hide" tabindex="-1" role="dialog" aria-labelledby="edit-user-modal-label" aria-hidden="true" data-backdrop="static">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="edit-user-modal-label">Edit user</h3>
</div>
<div class="modal-body">
<table class="table">
<tr><td>Username</td><td><input class="edit-user-username" type="text"></input></td></tr>
<tr><td>Name</td><td><input class="edit-user-name" type="text"></input></td></tr>
<tr><td>Email</td><td><input class="edit-user-email" type="text"></input></td></tr>
<tr><td>Location</td><td><input class="edit-user-location" type="text"></input></td></tr>
<tr><td>Bio</td><td><input class="edit-user-bio" type="text"></input></td></tr>
<tr><td>Timezome</td><td><input class="edit-user-timezone" type="text"></input></td></tr>
<tr>
<td>Password <i class="icon-question-sign" title="Leave it blank if you don't wish to change it"></i></td>
<td>
<input class="edit-user-password" type="password">
<button class="generate-password btn" style="margin-bottom: 10px">
<i class="icon-eye-open"></i> Generate new
</button>
</td>
</tr>
<tr><td>Confirm password</td><td><input class="edit-user-confirm-password" type="password"></input></td></tr>
<tr><td>Role in group <i title="- Administrator: full access (create users, add member, create group feeds, dashboards graphs, etc) - Sub-administrator: view access to the list of members, write access to group graphs - Passive member: no access to group. The aim of the user is to be managed by the group administrator" class=" icon-question-sign"></i>:</td>
<td><select id="edit-user-role">
<option value=1>Administrator</option>
<option value=2>Sub-administrator</option>
<!--<option value=3>Member</option>-->
<option value=0 selected>Passive member</option>
</select>
</td>
</tr>
<tr>
<td>Tags</td>
<td><div id="edit-user-tags-wrapper">
Name <input class="edit-user-tag-name" type="text" style="width:75px;margin-right:15px"></input><div id="edit-user-matching-tags" class="hide"></div> <button class="btn edit-user-tag-add" style="margin-bottom:10px"><i class="icon-plus"></i>Add</button><br />
Value <input class="edit-user-tag-value" type="text" style="width:165px"></input>
<div id="edit-user-tagslist"></div>
</div>
</td>
</tr>
</table>
<p style='margin-left:5px'>
<input type="checkbox" id="edit-user-send-email" class="toogle-email-div" style="margin-bottom: 8px; width: 20px; height: 20px">
<label for="edit-user-send-email" style="display: inline-block">Send login details to user's email</label>
</p>
<div id="edit-user-email-div" class="email-div" style="display:none">
<p>Subject</p>
<input type="text" id="edit-user-email-subject" />
<p>Body (in html)</p>
<textarea id="edit-user-email-body"></textarea>
<input type="checkbox" id="edit-user-send-copy" /><label for="edit-user-send-copy" style="display: inline-block">Send me a copy</label>
<p>You can use the following wildcards: {{name}}, {{username}}, {{password}}<i class="icon-question-sign" title="Password can only be sent when you are updating it" /></i>, {{role}}, {{appname}}<i class="icon-question-sign" title="<?php echo $appname ?>" /></i> and {{path}}<i class="icon-question-sign" title="<?php echo $path ?>"> </i></p>
</div>
<div id="edit-user-modal-message" class="hide"><div class="alert alert-error">Passwords do not match</div></div>
<div id="edit-user-modal-message-tag" class="hide alert alert-error"></div>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true">Cancel</button>
<button id="edit-user-action" action="next" class="btn btn-primary">Ok</button>
</div>
</div>
<!-- DELETE GROUP -->
<div id="delete-group-modal" class="modal hide" tabindex="-1" role="dialog" aria-labelledby="delete-group-modal-label" aria-hidden="true" data-backdrop="static">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="delete-group-modal-label">Delete group</h3>
</div>
<div class="modal-body">
<p>Are you sure you wish to delete this group?</p>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true">Cancel</button>
<button id="delete-group-action" class="btn btn-danger">Delete</button>
</div>
</div>
<!-- EDIT GROUP -->
<div id="edit-group-modal" class="modal hide" tabindex="-1" role="dialog" aria-labelledby="edit-group-modal-label" aria-hidden="true" data-backdrop="static">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="edit-group-modal-label">Edit group</h3>
</div>
<div class="modal-body">
<p>Group Name:<br>
<input id="edit-group-name" type="text" maxlength="64"></p>
<p>Group Description:<br>
<input id="edit-group-description" type="text" maxlength="256"></p>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true">Cancel</button>
<button id="edit-group-action" class="btn btn-primary">Done</button>
</div>
</div>
<!-- FEED EXPORT -->
<div id="feedExportModal" class="modal hide" tabindex="-1" role="dialog" aria-labelledby="feedExportModalLabel" aria-hidden="true" data-backdrop="static">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="feedExportModalLabel"><b><span id="SelectedExport"></span></b></h3>
</div>
<div class="modal-body">
<p>Select the time range and interval that you wish to export: </p>
<table class="table">
<tr>
<td>
<p><b>Start date & time</b></p>
<div id="datetimepicker1" class="input-append date">
<input id="export-start" data-format="dd/MM/yyyy hh:mm:ss" type="text" />
<span class="add-on"> <i data-time-icon="icon-time" data-date-icon="icon-calendar"></i></span>
</div>
</td>
<td>
<p><b>End date & time</b></p>
<div id="datetimepicker2" class="input-append date">
<input id="export-end" data-format="dd/MM/yyyy hh:mm:ss" type="text" />
<span class="add-on"> <i data-time-icon="icon-time" data-date-icon="icon-calendar"></i></span>
</div>
</td>
</tr>
<tr>
<td>
<p><b>Interval</b></p>
<select id="export-interval" >
<option value=1>Auto</option>
<option value=5>5s</option>
<option value=10>10s</option>
<option value=30>30s</option>
<option value=60>1 min</option>
<option value=300>5 mins</option>
<option value=600>10 mins</option>
<option value=900>15 mins</option>
<option value=1800>30 mins</option>
<option value=3600>1 hour</option>
<option value=21600>6 hour</option>
<option value=43200>12 hour</option>
<option value=86400>Daily</option>
<option value=604800>Weekly</option>
<option value=2678400>Monthly</option>
<option value=31536000>Annual</option>
</select>
</td>
<td>
<p><b>Date time format</b></p>
<div class="checkbox">
<label><input type="checkbox" id="export-timeformat" value="" checked>Excel (d/m/Y H:i:s)</label>
</div>
<label>Offset secs (for daily) <input id="export-timezone-offset" type="text" class="input-mini" disabled=""></label>
</td>
</tr>
</table>
<div class="alert alert-info">
<p>Selecting an interval shorter than the feed interval (or Auto) will use the feed interval instead. Averages are only returned for feed engines with built in averaging.</p>
<p>Date time in excel format is in user timezone. Offset can be set if exporting in Unix epoch time format.</p>
</div>
</div>
<div class="modal-footer">
<div id="downloadsizeplaceholder" style="float: left">Estimated download size: <span id="downloadsize">0</span>MB</div>
<button class="btn" data-dismiss="modal" aria-hidden="true"><?php echo _('Close'); ?></button>
<button class="btn" id="export">Export</button>
</div>
</div>
<!-- CREATE TASK -->
<div id="taskCreateModal" class="modal hide" tabindex="-1" role="dialog" aria-labelledby="taskCreateModalLabel" aria-hidden="true" data-backdrop="static">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="taskCreateModalLabel"><?php echo _('Create task'); ?></h3>
</div>
<div class="modal-body">
<p><?php echo _('Once a task is created you will need to set up the Process List and enable it'); ?></p>
<table>
<tr>
<td style="width:125px"><?php echo _('Task belongs to'); ?></td>
<td id="task-create-belongs-to">
<input name="belongs-to" type="radio" value="session-user" /><?php echo _('Current user') ?>
<br /><input name="belongs-to" type="radio" value="feed-user" checked /><?php echo _("Feed owner") ?>
</td></tr>
<tr><td><?php echo _('Name*'); ?></td><td><input id="task-create-name" type="text" /></td></tr>
<tr><td><?php echo _('Description'); ?></td><td><input id="task-create-description" type="text" /></td></tr>
<tr><td><?php echo _('Tag'); ?></td><td><input id="task-create-tag" type="text" /></td></tr>
<tr><td><?php echo _('Frequency'); ?></td><td id="task-create-frequency"></td></tr>
<tr><td><?php echo _('Start date'); ?></td><td><div class="input-append date" id="task-create-run-on" data-format="dd/MM/yyyy hh:mm"><input data-format="dd/MM/yyyy hh:mm" type="text" /><span class="add-on"> <i data-time-icon="icon-time" data-date-icon="icon-calendar"></i></span></div></td></tr>
</table>
<div id="task-create-message" class="alert alert-block hide"></div>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true"><?php echo _('Cancel'); ?></button>
<button id="taskCreate-confirm" class="btn btn-primary"><?php echo _('Create task'); ?></button>
</div>
</div>
<!-- DELETE TASK -->
<div id="delete-task-modal" class="modal hide" tabindex="-1" role="dialog" aria-labelledby="delete-task-modal-label" aria-hidden="true" data-backdrop="static">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="delete-task-modal-label">Delete task</h3>
</div>
<div class="modal-body">
<p>Are you sure you wish to delete this task?</p>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true">Cancel</button>
<button id="delete-task-action" class="btn btn-danger">Delete</button>
</div>
</div>
<?php if ($task_support === true) require "Modules/process/Views/process_ui.php"; ?>
<!-------------------------------------------------------------------------------------------
JAVASCRIPT
-------------------------------------------------------------------------------------------->
<script>
var my_userid = <?php echo $session["userid"]; ?>;
var selected_groupid = 0;
var selected_groupindex = 0;
var grouplist = [];
var my_role = 0;
var userlist = [];
var tags_used_in_group = [];
var summary_for_search = [];
var task_support = <?php echo $task_support === false ? 0 : 1; ?> === 1 ? true : false;
<?php if (isset($groups_email_subject) && isset($groups_email_body)) { ?>
var EMAIL_SUBJECT = <?= json_encode($groups_email_subject) ?>;
var EMAIL_BODY = <?= json_encode($groups_email_body) ?>;
<?php
}
else {
?>
var EMAIL_SUBJECT = "Your {{appname}} login";
var EMAIL_BODY = "<p>Username: {{username}}<br>\nPassword: {{password}}</p>\n<p>Login at <a href='{{path}}'>{{path}}</a>";
<?php } ?>
// All in seconds
var AGE_NEW = 0;
var AGE_RECENT = 25;
var AGE_STALE = 60;
var AGE_ANCIENT = 60 * 60 * 2; // 2 hours
// ----------------------------------------------------------------------------------------
// Task: ini
// ---------------------------------------------------------------------e-------------------
if (task_support == true) {
load_custom_table_fields();
processlist_ui.init(2); // 2 means that contexttype is task (1 for feeds and virtual feeds, 1 for input)
}
// ----------------------------------------------------------------------------------------
// Draw: grouplist
// ----------------------------------------------------------------------------------------
refresh_grouplist();
// ----------------------------------------------------------------------------------------
// Startup group
// ----------------------------------------------------------------------------------------
var selected_group = decodeURIComponent(window.location.hash).substring(1);
// console.log("Selectedgroup:" + selected_group)
if (selected_group != "") {
setTimeout(function () { // We need some extra time to let processlist_ui.init(1) to finish
for (var gindex in grouplist) {
if (grouplist[gindex].name == selected_group) {
$(".group[gindex=" + gindex + "]").parent().addClass('active');
select_group(gindex);
}
}
}, 100);
}
else {
$('.groupselected').hide();
$("#nogroupselected").show(); // Hide no group selected alert
}
// ----------------------------------------------------------------------------------------
// Functions
// ----------------------------------------------------------------------------------------
function snackbar(text) {
var snackbar = document.getElementById("snackbar");
snackbar.innerHTML = text;
snackbar.className = "show";
setTimeout(function () {
snackbar.className = snackbar.className.replace("show", "");
}, 3000);
}
function refresh_grouplist() {
group.grouplist(function (groups) {
grouplist = groups
draw_grouplist()
})
}
function select_group(index) {
selected_groupindex = index;
selected_groupid = grouplist[index].groupid;
draw_group();
refresh_userlist(selected_groupid);
}
function draw_grouplist() {
var out = '<ul class="nav sidebar-menu sub-nav">';
for (var z in grouplist) {
out += "<li><a href='#"+ grouplist[z].name + "' class='group' gindex=" + z + " gid=" + grouplist[z].groupid + ">" + grouplist[z].name + "</a></li>";
}
out += "</ul>";
$("#grouplist").html(out);
}
function draw_group() {
var group = grouplist[selected_groupindex];
$("#groupname").html(group.name); // Place group name in title
$("#groupdescription").html(group.description); // Place group description in title
$('.groupselected').show();
$("#nogroupselected").hide(); // Hide no group selected alert
if (group.role != 1)
$('.if-admin').hide();
}
function refresh_userlist(groupid) {
// Get session user role in group
group.getsessionuserrole(groupid, function (result) {
my_role = result
// Load list of members
group.userlist(groupid, draw_userlist, function fail(message) {
$('#userlist-div').hide();
$('#userlist-table').hide();
$('#userlist-alert h4').html('No users to show');
$('#userlist-alert p').html(userlist.message);
$('#userlist-alert').show();
});
});
}
function draw_userlist(userlist) {
// pass new data to global variable
window.userlist=userlist
// Sort userlist
userlist.sort(function (a, b) {
var nameA = a.username.toLowerCase(), nameB = b.username.toLowerCase();
if (nameA < nameB) //sort string ascending
return -1;
if (nameA > nameB)
return 1;
return 0; //default return value (no sorting)
});
// Fill tags_used_in_group
for (var z in userlist)
for (var tag in userlist[z].tags)
if (!tags_used_in_group.includes(tag))
tags_used_in_group.push(tag);
// Replace feeds available for processes - processlist_ui.init(1) has loaded current user's ones, we are goin to add feeds of all users in the group
if (task_support == true)
processlist_load_group_users_feeds();
// Html
// Hide alert message
$('#userlist-alert').hide();
var out = "";
for (var z in userlist) {
// Role
var role;
switch (userlist[z].role) {
case 0:
role = 'Passive member';
break;
case 1:
role = 'Administrator';
break;
case 2:
role = 'Sub-administrator';
break;
/*case 3:
role = 'Member';
break;*/
default:
role = "Invalid role";
break;
}
// Active feeds colors
var green = 0, amber = 0, orange = 0, red = 0;
var color_green = "rgb(50,200,50)", color_amber = "rgb(240,180,20)", color_orange = "rgb(255,125,20)", color_red = "rgb(255,0,0)";
var now = Date.now() / 1000;
var diff = 0;
userlist[z].feedslist.forEach(function (feed) {
diff = now - feed.time;
if (diff < 25)
green++;
else if (diff < 60)
amber++;
else if (diff < 7200)
orange++;
else
red++;
});
green = green > 0 ? green : '';
amber = amber > 0 ? amber : '';
orange = orange > 0 ? orange : '';
red = red > 0 ? red : '';
// html user
out += "<div class='user' uid='" + userlist[z].userid + "'>";
out += "<div class='user-info'>";
out += "<div class='user-name'>" + userlist[z].username + "</div>";
out += "<div class='user-active-feeds'><b> <span style='color:" + color_green + "'>" + green + "</span>" + " <span style='color:" + color_amber + "'>" + amber + "</span>" + " <span style='color:" + color_orange + "'>" + orange + "</span>" + " <span style='color:" + color_red + "'>" + red + "</span>" + "</b></div>";
out += "<div class='user-role'>" + role + "</div>";
out += "<div class='user-actions'>";
if (userlist[z].userid != my_userid) {
if (userlist[z].admin_rights == 'full') {
if (my_role == 1) {
out += "<button title='Log in as user'" +
" class='btn setuser if-admin'" +
" gid=" + selected_groupid +
" uid=" + userlist[z].userid +
" username='" + userlist[z].username + "'>" +
" <i class='icon-user'></i>" +
"</button>";
}
out += "<button title='Edit user' class='btn edit-user if-admin' uid=" + userlist[z].userid + " uindex=" + z + "><i class='icon-edit'></i></button>";
}
out += "<button title='Remove user' class='btn removeuser if-admin' uid=" + userlist[z].userid + " admin-rights=" + userlist[z].admin_rights + "><i class='icon-trash'></i></button>";
}
out += "</div>"; // user-actions
out += "</div>"; // user-info
// html feeds and tasks
out += "<div class='user-feeds-inputs hide' uid='" + userlist[z].userid + "'>";
// Feeds
out += "<div class='user-feedslist'>";
out += "<div class='user-feedslist-inner'>";
// Add tags
var tags_list = [];
userlist[z].feedslist.forEach(function (feed) {
if (tags_list.indexOf(feed.tag) == -1) {
tags_list.push(feed.tag);
out += "<div class='feed-tag' tag='" + feed.tag + "'>";
out += "<input class='feed-tag-checkbox' type='checkbox' tag='" + feed.tag + "' uid='" + userlist[z].userid + "' />" + feed.tag;
// Add feed tah have the current tag
userlist[z].feedslist.forEach(function (feed_again) {
if (feed_again.tag == feed.tag) {
out += "<div class='feed hide' tag='" + feed_again.tag + "' uid='" + userlist[z].userid + "'>";
out += "<input type='checkbox' fid='" + feed_again.id + "' tag='" + feed_again.tag + "' uid='" + userlist[z].userid + "' />";
out += "<div class='feed-name'>" + feed_again.name + "</div>";
out += "<div class='feed-download' fid='" + feed_again.id + "' tag='" + feed_again.tag + "' name='" + feed_again.name + "'><i class='icon-download'style='cursor:pointer' title='Download csv'> </i></div>";
out += "<div class='feed-value'>" + list_format_value(feed_again.value) + "</div>";
out += "<div class='feed-time'>" + list_format_updated(feed_again.time) + "</div>";
out += "</div>"; // feed
}
});
out += "</div>";
}
});
out += "</div>"; // user-feedslist-inner
out += "</div>"; // user-feedslist
// Tasks div
if (task_support === true && userlist[z].taskslist.length > 0) {
out += "<div class='user-tasks' groupid='" + groupid + "' userid='" + userlist[z].userid + "'>";
out += "<div class='user-taskslist-inner'>";
// Add tags
var tags_list = [];
table.data = userlist[z].taskslist; // we use it to draw some task fields
userlist[z].taskslist.forEach(function (task) {
if (tags_list.indexOf(task.tag) == -1) {
tags_list.push(task.tag);
out += "<div class='task-tag' tag='" + task.tag + "'>";
out += "Tasks - " + (task.tag === '' ? 'NoGroup' : task.tag);
// Add tasks tah have the current tag
userlist[z].taskslist.forEach(function (task_again, row) {
if (task_again.tag == task.tag) {
out += "<div class='task hide' tag='" + task.tag + "' uid='" + userlist[z].userid + "' taskid='" + task_again.id + "'>";
out += "<div class='task-name' title='Name'>" + task_again.name + "</div>";
out += "<div class='task-processlist' title='Process list'>" + table.fieldtypes.processlist.draw(table, row, '', 'processList') + "</div>";
out += "<div class='task-frequency' title='Frequency'>" + table.fieldtypes.frequency.draw(table, row, '', 'frequency') + "</div>";
out += "<div class='task-enabled' style='cursor:pointer' title='Enabled' uindex=" + z + " taskid=" + task_again.id + ">" + (task_again.enabled == 1 ? 'On' : 'Off') + "</div>";
if (userlist[z].admin_rights == 'full') {
out += '<div id="task-actions">';
out += "<div class='task-delete' title='Delete task' uid=" + userlist[z].userid + " taskid=" + task_again.id + "><i class='icon-trash if-admin' style='cursor:pointer'> </i></div> ";
out += "<div class='task-view setuser'"
' title="Edit task in user\'s account"' +
" gid=" + selected_groupid +
" uid=" + userlist[z].userid +
" username='" + userlist[z].username + "'" +
" extra='&view=tasks&tag=" + (task.tag === '' ? 'NoGroup' : task.tag) + "'>" +
" <i class='icon-eye-open' style='cursor:pointer'></i>" +
"</div>";
out += "<div class='task-edit-processlist' title='Edit process list' uindex=" + z + " taskid=" + task_again.id + " ><i style='cursor:pointer' class='icon-wrench' /></div>";
out += "</div>"; // task-actions
}
out += "</div>"; // task
}
});
out += "</div>"; // task-tag
}
});
out += "</div>"; // user-taskslist-inner
out += "</div>"; // .user-tasks
}
// Close divs
out += "</div>"; // user-feeds-inputs
out += "</div>"; // user
}
$("#userlist-div").html(out); // Place userlist html in userlist table
// Show
$('#userlist-div').show();
}
// Format value dynamically (copied from feedlist_view.php)
function list_format_value(value) {
if (value == null)
return 'NULL';
value = parseFloat(value);
if (value >= 1000)
value = parseFloat((value).toFixed(0));
else if (value >= 100)
value = parseFloat((value).toFixed(1));
else if (value >= 10)
value = parseFloat((value).toFixed(2));
else if (value <= -1000)
value = parseFloat((value).toFixed(0));
else if (value <= -100)
value = parseFloat((value).toFixed(1));
else if (value < 10)
value = parseFloat((value).toFixed(2));
return value;
}
// Calculate and color updated time (copied from feedlist_view.php)
function list_format_updated(time) {
time = time * 1000;
var servertime = (new Date()).getTime(); // - table.timeServerLocalOffset;
var update = (new Date(time)).getTime();
var secs = (servertime - update) / 1000;
var mins = secs / 60;
var hour = secs / 3600;
var day = hour / 24;
var updated = secs.toFixed(0) + "s";
if ((update == 0) || (!$.isNumeric(secs)))
updated = "n/a";
else if (secs < 0)
updated = secs.toFixed(0) + "s"; // update time ahead of server date is signal of slow network
else if (secs.toFixed(0) == 0)
updated = "now";
else if (day > 7)
updated = "inactive";
else if (day > 2)
updated = day.toFixed(1) + " days";
else if (hour > 2)
updated = hour.toFixed(0) + " hrs";
else if (secs > 180)
updated = mins.toFixed(0) + " mins";
secs = Math.abs(secs);
var ageClass;
if (secs < AGE_RECENT)
ageClass = "age-new";
else if (secs < AGE_STALE)
ageClass = "age-recent";
else if (secs < AGE_ANCIENT)
ageClass = "age-stale";
else
ageClass = "age-ancient";
return "<span class=" + ageClass + ">" + updated + "</span>";
}
// Loads into processlist_ui.feedlist array feeds from all the users in the groups
function processlist_load_group_users_feeds() {
processlist_ui.feedlist = {};
userlist.forEach(function (user) {
user.feedslist.forEach(function (feed) {
processlist_ui.feedlist[feed.id] = JSON.parse(JSON.stringify(feed));
processlist_ui.feedlist[feed.id].name = user.username + ": " + feed.name;
});
});
}
// Generate random password
function generatePassword() {
var length = 8,
charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",
retVal = "";
for (var i = 0, n = charset.length; i < length; ++i) {
retVal += charset.charAt(Math.floor(Math.random() * n));
}
return retVal;
}
// ----------------------------------------------------------------------------------------
// Action: click on group
// ----------------------------------------------------------------------------------------
$("body").on("click", "#grouplist .group", function (event) {
// event.preventDefault();
// Group selection CSS
$('#grouplist li.active').removeClass('active');
$(this).parent().addClass('active');
// Get selected group from attributes
var gindex = $(this).attr("gindex");
select_group(gindex);
// document.location.hash = grouplist[gindex].name
});
// ----------------------------------------------------------------------------------------
// Action: Group creation
// ----------------------------------------------------------------------------------------
$("body").on('click', '#groupcreate', function () {
$('#group-create-modal input').val('');
$('#group-create-modal').modal('show');
});
$("body").on('click', "#group-create-action", function () {
var data = {
name: $("#group-create-name").val(),
description: $("#group-create-description").val(),
organization: $("#group-create-organization").val() || 'N/A',
area: $("#group-create-area").val() || 'N/A',
visibility: $("#group-create-visibility").val() || 'private',
access: $("#group-create-access").val() || 'closed'
};
group.create(data, function (result) {
$('#group-create-modal').modal('hide');
refresh_grouplist();
});
});
// ----------------------------------------------------------------------------------------
// Action: Edit group
// ----------------------------------------------------------------------------------------
$("body").on('click', "#editgroup", function () {
var group = grouplist[selected_groupindex];
$("#edit-group-name").val(group.name);
$("#edit-group-description").val(group.description);
$("#edit-group-organization").val(group.organization);
$("#edit-group-area").val(group.area);
$("#edit-group-visibility").val(group.visibility);
$("#edit-group-access").val(group.access);
$('#edit-group-modal').modal('show');
});
$("body").on('click', '#edit-group-action', function () {
var data = {
groupid: selected_groupid,
name: $("#edit-group-name").val(),
description: $("#edit-group-description").val(),
organization: $("#edit-group-organization").val() || 'N/A',
area: $("#edit-group-area").val() || 'N/A',
visibility: $("#edit-group-visibility").val() || 'private',
access: $("#edit-group-access").val() || 'closed',
}
group.editgroup(data, function (result) {
refresh_grouplist();
setTimeout(draw_group, 100);
$('#edit-group-modal').modal('hide');
})
});
// ----------------------------------------------------------------------------------------
// Action: Add member
// ----------------------------------------------------------------------------------------
$("body").on('click', "#addmember", function () {
$('#group-addmember-modal input').val('');
$("#group-addmember-access").val(0);
$('#group-addmember-modal').modal('show');
$('#group-addmember-username').focus();
});
$("body").on('keydown', '#group-addmember-username', function (evt) {
if (evt.which === 13) {
$("#group-addmember-action").click();
}
});
$("body").on('click', "#group-addmember-action", function () {
var data = {
groupid: selected_groupid,
username: $("#group-addmember-username").val(),
password: $("#group-addmember-password").val(),
role: $("#group-addmember-access").val(),
};
group.addmemberauth(data, function () {
$('#group-addmember-modal').modal('hide');
refresh_userlist(selected_groupid);
});
});
// ----------------------------------------------------------------------------------------
// Action: Create user and add to group
// ----------------------------------------------------------------------------------------
$("body").on('click', "#createuseraddtogroup", function () {
$('#group-createuseraddtogroup-modal input').val('');
$("#group-createuseraddtogroup-role").val(0);
$('#group-createuseraddtogroup-modal input[type=checkbox]').prop('checked', false);
$('#group-createuseraddtogroup-email-subject').val(EMAIL_SUBJECT);
$('#group-createuseraddtogroup-email-body').val(EMAIL_BODY);
$('#group-createuseraddtogroup-modal').modal('show');
});
$("body").on('click', "#group-createuseraddtogroup-action", function () {
var data = {
groupid: selected_groupid,
email: $("#group-createuseraddtogroup-email").val(),
username: $("#group-createuseraddtogroup-username").val(),
password: $("#group-createuseraddtogroup-password").val(),
role: $("#group-createuseraddtogroup-role").val(),
name: $("#group-createuseraddtogroup-name").val(),
};
var send_email = $('#group-createuseraddtogroup-send-email').prop('checked');
var confirm_password = $("#group-createuseraddtogroup-password-confirm").val();
if (data.password != confirm_password) {
$("#createuseraddtogroup-message").html("<div class='alert alert-error'>Passwords do not match</div>");
return;
}
group.createuseraddtogroup(data, function (result) {
if (send_email) {
var emailData = {
groupid: selected_groupid,
userid: result.userid,
password: data.password,
emailsubject: $('#group-createuseraddtogroup-email-subject').val(),
template: $('#group-createuseraddtogroup-email-body').val(),
sendcopy: $('#group-createuseraddtogroup-send-copy').prop('checked'),
}
group.sendlogindetails(emailData, function () {}, function fail(msg) {
alert("User created but there was a problem sending the email:\n\n" + msg);
})
}
$('#group-createuseraddtogroup-modal').modal('hide');
refresh_userlist(selected_groupid);
});
});
// ----------------------------------------------------------------------------------------
// Action: Show feeds of a user
// ----------------------------------------------------------------------------------------
$('body').on('click', '.user', function () {
var userid = $(this).attr('uid');
$('.user-feeds-inputs[uid="' + userid + '"]').toggle();
});
$('body').on('click', '.feed-tag', function (e) {
e.stopPropagation();
var tag = $(this).attr('tag');
$(this).find('.feed[tag="' + tag + '"]').toggle();
});
$('body').on('click', '.feed-tag-checkbox', function (e) {
e.stopPropagation();
var tag = $(this).attr('tag');
var uid = $(this).attr('uid');
if ($(this).is(':checked')) {
$('.feed[tag="' + tag + '"][uid="' + uid + '"] input').prop('checked', 'checked');
}
else
$('.feed[tag="' + tag + '"][uid="' + uid + '"] input').prop('checked', '');
});
$('body').on('click', '.feed', function (e) {
e.stopPropagation();
});
// ----------------------------------------------------------------------------------------
// Action: Show tasks of a user
// ----------------------------------------------------------------------------------------
$('body').on('click', '.task-tag', function (e) {
e.stopPropagation();
var tag = $(this).attr('tag');
$(this).find('.feed[tag="' + tag + '"]').toggle();
});
$('body').on('click', '.task', function (e) {
e.stopPropagation();
});
// ----------------------------------------------------------------------------------------
// Action: Remove user
// ----------------------------------------------------------------------------------------
$("body").on('click', ".removeuser", function (e) {
e.stopPropagation();
$('#remove-user-modal-step-1').show();
$('#remove-user-modal-step-2').hide();
$('#remove-user-action').html('Next');
$('#remove-user-action').attr('action', 'next');
var userid = $(this).attr("uid");
$('#remove-user-modal').attr("uid", userid);
var admin_rights = $(this).attr("admin-rights");
$('[name="removeuser-whattodo"][value="delete"]').attr('disabled', admin_rights !== "full");
$('#remove-user-modal').modal('show');
});
$("body").on('click', "#remove-user-action", function () {
var action = $(this).attr('action');
if (action == 'next') {
$('#remove-user-modal-step-1').hide();
var what_to_do = $('input[name="removeuser-whattodo"]:checked').val();
if (what_to_do == 'remove-from-group') {
$('#remove-user-modal-step-2').html('<p>Are you sure you want to remove this user from group?</p>');
$(this).attr('action', 'remove-from-group');
}
else {
$('#remove-user-modal-step-2').html('<p>Are you sure you wish to completely delete this user from the database?</p><p>All the data will be lost</p>');
$(this).attr('action', 'delete-from-database');