-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanage_ufmember.php
1411 lines (1155 loc) · 41.8 KB
/
manage_ufmember.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 include "php/inc/header.inc.php" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?=$language;?>" lang="<?=$language;?>">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo $Text['global_title'] . " - " . $Text['head_ti_manage'] . " " . $Text['head_ti_manage_uf'] ;?></title>
<link rel="stylesheet" type="text/css" media="screen" href="css/aixada_main.css" />
<link rel="stylesheet" type="text/css" media="print" href="css/print.css" />
<link rel="stylesheet" type="text/css" media="screen" href="js/fgmenu/fg.menu.css" />
<link rel="stylesheet" type="text/css" media="screen" href="css/ui-themes/<?=$default_theme;?>/jqueryui.css"/>
<script type="text/javascript" src="js/jquery/jquery.js"></script>
<script type="text/javascript" src="js/jqueryui/jqueryui.js"></script>
<?php echo aixada_js_src(); ?>
<script type="text/javascript" src="js/aixadautilities/jquery.aixadaExport.js" ></script>
<script type="text/javascript">
$(function(){
$.ajaxSetup({ cache: false });
//loading Spinner
$('.loadSpinner').attr('src', "img/ajax-loader-<?=$default_theme;?>.gif").hide();
//saves selected uf row
var gSelUfRow = null;
//saves currently selecte member row
var gSelMemberRow = null;
//var gEmptyMemberForm = $('#uf_detail_member_list').children(':first').clone();
//set to true once theme and lang select have been loaded
var gFormComplete = false;
//should be changed to non-global
var gMentorUf = -1;
//show/hide reset pwd.
var isAdmin = "<?php
echo get_current_role();
?>";
isAdmin = (isAdmin == "Hacker Commission")? true:false;
$('#member_listing').tabs();
//load available languages
$("#languageSelect")
.xml2html("init", {
url: "php/ctrl/SmallQ.php",
params : "oper=getExistingLanguages",
rowName : "language",
loadOnInit: false,
complete : function(s){
//insert the language and theme select into the create member form.
prepareAddMemberForm(true);
}
});
//load available themes
$("#themeSelect")
.xml2html("init", {
url: "php/ctrl/SmallQ.php",
params : "oper=getExistingThemes",
rowName : "theme",
loadOnInit: true,
complete : function(s){
$("#languageSelect").xml2html("reload");
}
});
/*******************************************
* UFS LISTING
*******************************************/
//init the uf listing
$('#uf_list tbody').xml2html('init',{
url: 'php/ctrl/UserAndUf.php',
params : 'oper=getUfListing&all=1',
loadOnInit: true,
beforeLoad: function(){
$('.loadSpinner').show();
},
rowComplete: function(index, row){
var ckbx = row.children().first().find('input');
if (ckbx.val() == "1") ckbx.attr('checked',true); //set the checkbox if uf is active or not
},
complete : function(){
$('.loadSpinner').hide();
$('#uf_list tbody tr:even').addClass('rowHighlight');
}
});
//handle events on uf list
$('#uf_list tbody tr')
.live('mouseenter', function(){
var uf_id = $(this).attr('ufId');
$(this).addClass('ui-state-hover');
//$('#member_list tbody tr.memberOfUf_'+uf_id).addClass('ui-state-hover');
})
.live('mouseleave',function(){
var uf_id = $(this).attr('ufId');
$(this).removeClass('ui-state-hover');
//$('#member_list tbody tr.memberOfUf_'+uf_id).removeClass('ui-state-hover');
})
//click on uf table row
.live('click',function(e){
if (gSelUfRow != null) gSelUfRow.removeClass('ui-state-highlight');
$(this).addClass('ui-state-highlight');
gSelUfRow = $(this);
//only load fresh ones. otherwise use cash
//if (!$.inArray(gSelUfRow.attr('ufid'), gUfMemberViewCache))
$('#uf_detail_member_list').xml2html('reload',{
params: "oper=getMemberInfo&uf_id="+gSelUfRow.attr('ufid')
});
//}
switchTo('ufMemberView');
});
//load mentor uf select listing
$('#mentor_uf').xml2html('init',{
url: 'php/ctrl/UserAndUf.php',
params : 'oper=getUfListing&all=0',
loadOnInit:true,
offSet : 1,
complete:function(rowCount){
var sel = $('#mentor_uf').clone();
$('.mentor_uf').append(sel);
}
}).change(function(){
gMentorUf = $("option:selected", this).val();
});
//new uf
$("#btn_new_uf")
.button({
icons : {primary:"ui-icon-plus"}
})
.click(function(e){
$('#create_uf_name').val('');
//$('#mentor_uf').val("-1").attr('selected','selected')
//$('#mentor_uf').xml2html('reload');
$('#dialog-uf').dialog( "open" );
});
//edit uf
$("#btn_edit_uf")
.button({
icons : {primary:"ui-icon-pencil"}
})
.click(function(e){
$('#uf_info').find('input').removeAttr('disabled');
$('#mentor_uf').removeAttr('disabled');
$(this).hide();
$('#btn_edit_uf_save').show();
});
$("#btn_edit_uf_save")
.button({
icons : {secondary:"ui-icon-disk"}
})
.click(function(e){
submitUF(gSelUfRow.attr('ufid'));
})
.hide();
//create new uf
$("#dialog-uf").dialog({
autoOpen: false,
height: 330,
width: 450,
modal: true,
buttons: {
"<?=$Text['btn_create'];?>": function() {
submitUF(0);
},
"<?php echo $Text['btn_cancel'];?>": function() {
$( this ).dialog( "close" );
}
}
});
//activate / deactive uf
$('input[name=uf_active]')
.live('click',function(e){
var is_active = $(this).attr('checked')? 1:0;
var uf_id = $(this).parents('tr').attr('ufid');
$('.loadSpinner').show();
//toggle active state of uf.
$.ajax({
type: "POST",
url: 'php/ctrl/UserAndUf.php?oper=editUF&is_active='+is_active+'&uf_id='+$(this).parents('tr').attr('ufid')+'&name='+$(this).parents('tr').attr('ufname')+'&mentor_uf='+$(this).parents('tr').attr('mentoruf'),
success : function(msg){
$.showMsg({
msg: '<?php echo $Text['active_changed_uf']; ?>'+uf_id,
autoclose: 1000,
type: 'success'
});
},
error : function(XMLHttpRequest, textStatus, errorThrown){
$.showMsg({
msg: XMLHttpRequest.responseText,
type: 'error'
});
},
complete: function(){
$('.loadSpinner').hide();
}
});
e.stopPropagation();
});
/**
* export ufs
*/
$('#dialog_export_options').dialog({
autoOpen:false,
width:520,
height:500,
buttons: {
"<?=$Text['btn_ok'];?>" : function(){
exportUfs();
},
"<?=$Text['btn_close'];?>" : function(){
$( this ).dialog( "close" );
}
}
});
$('#btn_export')
.button({
icons: {
primary: "ui-icon-transferthick-e-w"
}
})
.click(function(e){
$('#dialog_export_options')
.dialog("open");
})
.hide();
function checkExportForm(){
var frmData = $('#frm_export_options').serialize();
if (!$.checkFormLength($('input[name=exportName]'),1,150)){
$.showMsg({
msg:"File name cannot be empty!",
type: 'error'});
return false;
}
return frmData;
}
//initially hide authenticate and specific uf stuff.
$('#export_authentication').hide();
/**
* EXPORT ufs
*/
function exportUfs(){
var frmData = checkExportForm();
if (frmData){
var urlStr = "php/ctrl/ImportExport.php?oper=exportMembers&" + frmData;
//load the stuff through the export channel
$('#exportChannel').attr('src',urlStr);
}
}
/**
* submits create/edit uf data
*/
function submitUF(ufId){
var mentorUf = $('#mentor_uf option:selected').val();
var stupidHack;
mentorUf = (mentorUf == -1)? gMentorUf:mentorUf;
if (ufId > 0){
var isActive = $('#uf_info').find('input:checkbox').attr('checked')? 1:0;
var ufName = $('#uf_info').find('input:text').val();
var urlStr = 'php/ctrl/UserAndUf.php?oper=editUF&uf_id='+ufId+'&is_active='+isActive+'&name='+ufName+'&mentor_uf='+mentorUf;
stupidHack = 's9328820398023948';
if (ufId == mentorUf){
$.showMsg({
msg: "<?php echo $Text['msg_err_mentoruf']; ?>",
type: 'error'
});
return false;
}
//create
} else {
var ufName = $('#create_uf_name').val();
var urlStr = 'php/ctrl/UserAndUf.php?oper=createUF&name='+ufName+'&mentor_uf='+mentorUf;
stupidHack = '';
}
//$('.loadSpinner').show();
$.ajax({
type: "POST",
url: 'php/ctrl/UserAndUf.php?oper=checkFormField&table=aixada_uf&field=name&value='+ufName+stupidHack,
success : function(msg){
//check if uf name exists
if (msg == 1){
$.showMsg({
msg: "<?php echo $Text['msg_err_ufexists']; ?> ",
type: 'error'
});
} else {
//create/edit uf
$.ajax({
type: "POST",
url : urlStr,
success : function(msg){
$.showMsg({
msg: "<?php echo $Text['msg_edit_success'] ; ?>",
autoclose: 1000,
type: 'success'
});
$("#dialog-uf").dialog( "close" );
$('#uf_list tbody').xml2html("reload");
},
error : function(XMLHttpRequest, textStatus, errorThrown){
$.showMsg({
msg: XMLHttpRequest.responseText,
type: 'error'
});
},
complete: function(){
$('#dialog_uf .loadAnim').hide();
$('#uf_info')
.find('input').attr('disabled', 'disabled')
.find('select').attr('disabled', 'disabled');
$('#btn_edit_uf_save').hide();
$('#btn_edit_uf').show();
}
});
}
},
error : function(XMLHttpRequest, textStatus, errorThrown){
$.showMsg({
msg: XMLHttpRequest.responseText,
type: 'error'
});
}
});
}
/*******************************************
* MEMBER LISTING
*******************************************/
//init the uf member listing
$('#member_list tbody').xml2html('init',{
url : "php/ctrl/UserAndUf.php",
params: "oper=getMemberListing&all=1",
loadOnInit:true,
beforeLoad : function(){
$('.loadSpinner').show();
},
rowComplete : function(rowIndex, row){
var tds = $(row).children();
//active
if (tds.eq(2).children('p:first').text() == "1"){
tds.eq(2).children('p:first').html('<span class="ui-icon ui-icon-check"></span>').addClass('aix-style-ok-green ui-corner-all');
} else {
tds.eq(2).children('p:first').html('<span class="ui-icon ui-icon-closethick"></span>').addClass('noRed ui-corner-all');
}
},
complete : function(){
$('.loadSpinner').hide();
$('#member_list tbody tr:even').addClass('rowHighlight');
}
});
//handle events on uf list
$('#member_list tbody tr, #member_list_search tbody tr')
.live('mouseenter', function(){
$(this).addClass('ui-state-hover');
})
.live('mouseleave',function(){
$(this).removeClass('ui-state-hover');
})
//click on uf table row
.live('click',function(e){
if (gSelMemberRow != null) gSelMemberRow.removeClass('ui-state-highlight');
$(this).addClass('ui-state-highlight');
gSelMemberRow = $(this);
$('#uf_detail_member_list').xml2html('reload',{
params: "oper=getMemberInfo&member_id="+gSelMemberRow.attr('memberId')
});
switchTo('memberView');
});
//init the non / new member listing
$('#member_list_unassigned tbody').xml2html('init',{
url : "php/ctrl/UserAndUf.php",
params : "oper=getMembersWithoutUF",
loadOnInit:true,
beforeLoad: function(){
$('.loadSpinner').show();
},
complete : function(){
$('#member_list_unassigned tbody tr:even').addClass('rowHighlight');
$('.loadSpinner').hide();
}
});
//init search listing
$('#member_list_search tbody').xml2html('init',{
url : "php/ctrl/UserAndUf.php",
params : "oper=searchMember",
beforeLoad: function(){
$('.loadSpinner').show();
},
rowComplete : function(rowIndex, row){
var tds = $(row).children();
//active
if (tds.eq(2).children('p:first').text() == "1"){
tds.eq(2).children('p:first').html('<span class="ui-icon ui-icon-check"></span>').addClass('aix-style-ok-green ui-corner-all');
} else {
tds.eq(2).children('p:first').html('<span class="ui-icon ui-icon-closethick"></span>').addClass('noRed ui-corner-all');
}
},
complete : function(){
$('#member_list_search tbody tr:even').addClass('rowHighlight');
$('.loadSpinner').hide();
}
});
//member search function
$("#search").keyup(function(e){
var minLength = 3; //search with min of X characters
var searchStr = $("#search").val();
if (searchStr.length >= minLength){
//$('.loadAnimShop').show();
$('#member_list_search tbody').xml2html('reload',{
url : "php/ctrl/UserAndUf.php",
params : "oper=searchMember&like="+searchStr
});
} else {
$('#member_list_search tbody').xml2html("removeAll"); //delete all product entries in the table if we are below minLength;
}
e.preventDefault(); //prevent default event propagation. once the list is build, just stop here.
}); //end autocomplete
//load assign member uf select listing
$('#sel_assign_uf').xml2html('init',{
url: 'php/ctrl/UserAndUf.php',
params : 'oper=getUfListing&all=0',
loadOnInit:false,
offSet : 1
});
//assign un-assigned members to UF
$('.btn_assign')
.live('click', function(e){
var member_id = $(this).parents('tr').attr('memberId');
$('#sel_assign_uf').xml2html('reload');
$('#dialog_assign_uf').dialog('option','memberId',member_id).dialog('open');
});
//delete unassigned member from database; throws error if member has existing references
//i.e. can only delete members that never really got active.
$('.btn_delete')
.live('click', function(e){
var member_id = $(this).parents('tr').attr('memberId');
$.showMsg({
msg: "<?php echo $Text['msg_confirm_del_mem']; ?>",
buttons: {
"<?=$Text['btn_ok'];?>":function(){
var $this = $(this);
var urlStr = 'php/ctrl/UserAndUf.php?oper=delMember&member_id='+member_id;
$.ajax({
url: urlStr,
type: 'POST',
success: function(msg){
//reload all members listing on overiew.
$('#member_list_unassigned tbody').xml2html('reload');
$this.dialog( "close" );
},
error : function(XMLHttpRequest, textStatus, errorThrown){
if (XMLHttpRequest.responseText.indexOf("ERROR 10") != -1){
$this.dialog("close");
$.showMsg({
msg: "<?=$Text['msg_err_del_member'];?>" + XMLHttpRequest.responseText,
type: 'error'});
}
}
}); //end ajax
},
"<?=$Text['btn_cancel'];?>" : function(){
$( this ).dialog( "close" );
}
},
type: 'confirm'});
});
//create new uf
$("#dialog_assign_uf").dialog({
autoOpen: false,
height: 330,
width: 450,
modal: true,
buttons: {
"<?=$Text['btn_assign'];?>": function() {
var uf_id = $('#sel_assign_uf option:selected').val();
if (uf_id < 0) {
alert("<?php echo $Text['sel_uf']; ?>");
return false;
}
var member_id = $(this).dialog('option','memberId');
var urlStr = "php/ctrl/UserAndUf.php?oper=assignUF&member_id="+member_id+"&uf_id="+uf_id;
$.post(urlStr, function(ok){
if (ok == '1'){
$("#dialog_assign_uf").dialog( "close" );
$('#member_list_unassigned tbody').xml2html('reload');
}
})
},
"<?php echo $Text['btn_cancel'];?>": function() {
$( this ).dialog( "close" );
}
}
});
/*******************************************
* UF & MEMBER EDIT
*******************************************/
$('#uf_detail_member_list').xml2html('init',{
url : "php/ctrl/UserAndUf.php",
params: "oper=getMemberInfo&uf_id=",
loadOnInit:false,
beforeLoad : function(){
//$('#member_listing .loadAnim').show();
},
rowComplete: function(rowIndex, row){
//copy the language select with the right option selected
var selectedLang = $('.memberLanguageSelect', row).prev().text();
var langSelect = $('#languageSelect').clone();
$(langSelect).val(selectedLang).attr('selected','selected');
$('.memberLanguageSelect', row).append(langSelect);
//copy the theme select with the right option selected
var selectedTheme = $('.memberThemeSelect', row).prev().text();
var themeSelect = $('#themeSelect').clone();
$(themeSelect).val(selectedTheme).attr('selected','selected');
$('.memberThemeSelect', row).append(themeSelect);
//set the checkboxes
$('.tblForms input:checkbox', row).each(function(){
var bool = $(this).val();
if (bool == "1") $(this).attr('checked',true);
});
},
complete : function(){
//each member gets an edit button
$('.btn_save_edit_member').button({
icons: {primary: "ui-icon-disk"}
}).live('click', function(e){
submitMember('update','#detail_member_'+$(this).attr('memberid'));
return false;
});
//if admin is logged user, show reset pwd button.
if (isAdmin){
$('.btn_reset_pwd')
.button({
icons: {primary: "ui-icon-locked"}
}).live('click', function(e){
$.ajax({
url: 'php/ctrl/UserAndUf.php?oper=resetPassword&user_id='+$(this).attr('userId'),
beforeSend: function(){
$('.loadSpinner').show();
},
success: function(new_pwd_msg){
$.showMsg({
msg: new_pwd_msg,
type: 'success'});
},
error : function(XMLHttpRequest, textStatus, errorThrown){
$.showMsg({
msg: XMLHttpRequest.responseText,
type: 'error'});
},
complete : function(msg){
$('.loadSpinner').hide();
$('.btn_reset_pwd').hide();
}
}); //end ajax
return false;
}).show();
}
//remove member from uf: member is now listed in the un-assigned members tab.
$('.ibtn_remove_member')
.live('mouseover', function(e){
$(this).addClass('ui-state-hover');
})
.live('mouseout', function(e){
$(this).removeClass('ui-state-hover');
})
.live('click',function(e){
var $this = $(this);
$.showMsg({
msg: "<?php echo $Text['msg_confirm_del']; ?>",
buttons: {
"<?=$Text['btn_ok'];?>":function(){
var dlog = $(this);
var urlStr = 'php/ctrl/UserAndUf.php?oper=removeMember&member_id='+$this.attr('memberId');
$.post(urlStr, function(ok){
if (ok == '1'){
$('#detail_member_'+$this.attr('memberId')).fadeOut(1000, function(){$(this).remove()});
dlog.dialog( "close" );
$('#member_list_unassigned tbody').xml2html('reload');
$('#member_list tbody').xml2html('reload');
}
})
},
"<?=$Text['btn_cancel'];?>" : function(){
$( this ).dialog( "close" );
}
},
type: 'confirm'});
//switchTo('ufMemberView');
return false;
});
}
});
//create new member button
$("#btn_add_member")
.button({
icons:{primary:'ui-icon-plus'}
})
.click(function(e){
prepareAddMemberForm(false);
switchTo('createMemberView');
});
//remove all eventual error styles on input fields.
$('input')
.live('focus', function(e){
$(this).removeClass('ui-state-error');
});
/**
* initializes and resets the add new member form.
*/
function prepareAddMemberForm(firstTime){
if (firstTime){
//add language and theme select
var langSelect = $('#languageSelect').clone();
var themeSelect = $('#themeSelect').clone();
$('#add_member_div .memberLanguageSelect').append(langSelect);
$('#add_member_div .memberThemeSelect').append(themeSelect);
//save button
$('#frm_add_member .btn_save_new_member').button({
icons: {primary: "ui-icon-check"}
})
.bind('click', function(e){
submitMember('create', '#add_member_div');
return false;
});
//new member cancel
$('#frm_add_member .btn_cancel_new_member')
.button({
icons: {secondary:'ui-icon-cancel'}
})
.bind('click',function(e){
switchTo('ufMemberView');
return false;
});
//header close icon
$('#add_member_div .ibtn_cancel_new_member')
.bind('mouseover', function(e){
$(this).addClass('ui-state-hover');
})
.bind('mouseout', function(e){
$(this).removeClass('ui-state-hover');
})
.bind('click',function(e){
switchTo('ufMemberView');
return false;
});
gFormComplete = true;
} else {
$('#frm_add_member input:text, input:hidden').val('');
//set the checkboxes
$('#frm_add_member input:checkbox').each(function(){
$(this).attr('checked','checked');
});
//set the uf_id in the form and heading.
$('.setUfId').text(gSelUfRow.attr('ufid'));
$('#frm_add_member input[name=uf_id]').val(gSelUfRow.attr('ufid'));
}
}
/**
* submits the create/edit member data
* urlStr : either updateMember or createNewMember
* mi: is the selector string of the layer that contains the whole member form and info
*/
function submitMember(action, mi){
var urlStr = 'php/ctrl/UserAndUf.php?oper=updateMember';
var isValid = true;
var isValidItem = true;
var err_msg = '';
//run some local checks
if (action == 'create'){
urlStr = "php/ctrl/UserAndUf.php?oper=createUserMember";
isValidItem = $.checkFormLength($(mi +' input[name=login]'),3,50);
if (!isValidItem){
isValid = false;
err_msg += "<?=$Text['msg_err_usershort'];?>" + "<br/><br/>";
}
isValidItem = $.checkFormLength($(mi+' input[name=password]'),4,15);
if (!isValidItem){
isValid = false;
err_msg += "<?=$Text['msg_err_passshort'];?>" + "<br/><br/>";
}
isValidItem = $.checkPassword($(mi+' input[name=password]'), $('input[name=password_ctrl]'));
if (!isValidItem){
isValid = false;
err_msg += "<?=$Text['msg_err_pwdctrl']; ?>"+ "<br/><br/>";
}
}
isValidItem = $.checkFormLength($(mi+' input[name="name"]'),2,150);
if (!isValidItem){
isValid = false;
err_msg += "<?php echo $Text['msg_err_namelength']; ?>"+ "<br/><br/>";
}
isValidItem = $.checkRegexp($(mi+' input[name="phone1"]'),/^([0-9\s\+])+$/);
if (!isValidItem){
isValid = false;
err_msg += "<?php echo $Text['phone1'] . $Text['msg_err_only_num']; ?>"+ "<br/><br/>";
}
isValidItem = $.checkRegexp($(mi+' input[name="email"]'),/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i);
if (!isValidItem){
isValid = false;
err_msg += "<?=$Text['msg_err_email'] ?>"+ "<br/><br/>";
}
if (isValid){
var sdata = $(mi + ' form').serialize();
$.ajax({
url: urlStr,
type: 'POST',
data: sdata,
beforeSend: function(){
$('.loadSpinner').show();
$('.btn_save_new_member').button('disable');
//$('button',mi).button('disable');
//myButton.button('disable');
},
success: function(msg){
$.showMsg({
msg: "<?php echo $Text['msg_edit_success']; ?>",
autoclose: 1000,
type: 'success'});
//reload all members of this uf
$('#uf_detail_member_list').xml2html('reload',{
params: "oper=getMemberInfo&uf_id="+gSelUfRow.attr('ufid')
});
//show them
switchTo('ufMemberView');
//reload all members listing on overiew.
$('#member_list tbody').xml2html('reload');
},
error : function(XMLHttpRequest, textStatus, errorThrown){
$.showMsg({
msg: XMLHttpRequest.responseText,
type: 'error'});
},
complete : function(msg){
$('.loadSpinner').hide();
$('.btn_save_new_member').button('enable');
}
}); //end ajax
//form is not valid
} else {
$.showMsg({
msg:err_msg,
type: 'error'});
}
}
/**
* pages contained in one: uf list/edit, members list/edit,
*/
function switchTo(section){
switch(section){
case 'overview':
$('.viewMemberElements, .ufDetailElements, .createMemberElements').hide();
$('.btn_save_edit_member').button('destroy');
$('.btn_save_edit_member').die('click'); //otherwise, save edits will duplicate, triplicate...
$('.btn_reset_pwd').button('destroy');
$('.btn_reset_pwd').die('click'); //otherwise, reset pwd will duplicate, triplicate...
$('.overviewElements').show();
break;
//show single member
case 'memberView':
$('.overviewElements, .ufDetailElements, .createMemberElements').hide();
$('.viewMemberElements').fadeIn(1000, function(){$('.loadSpinner').hide();});
break;
//show uf info and list all members
case 'ufMemberView':
$('.overviewElements, .createMemberElements').hide();
$('.setUfId').text(gSelUfRow.attr('ufid')); //indicate uf id + name
$('#uf_info input:text')
.val(gSelUfRow.attr('ufname'))
.attr('disabled','disabled');
if (gSelUfRow.children(':first').find('input:checkbox').attr('checked')){ //copy active state of uf to the info window
$('#uf_info input:checkbox').attr('checked','checked')
}
$('#uf_info input:checkbox').attr('disabled','disabled');
var selMentorUf = (gSelUfRow.attr('mentoruf') > 0)? gSelUfRow.attr('mentoruf'):-1; //copy mentor uf and disable select
$('#mentor_uf')
.val(selMentorUf)
.attr('selected','selected')
.attr('disabled','disabled');
$('.ufDetailElements, viewMemberElements').fadeIn(1000, function(){$('.loadSpinner').hide();});
break;
//show create form for new member
case 'createMemberView':
if (!gFormComplete){
$.showMsg({
msg: "<?php echo $Text['msg_err_form_init']; ?>",
type: 'error'
});
return false;
}
$('.viewMemberElements').hide();
$('.createMemberElements').fadeIn(2000, function(){$('.loadSpinner').hide();});
break;
}
}
/**
* returns to order overview
*/
$("#btn_overview").button({
icons: {
primary: "ui-icon-circle-arrow-w"
}
})
.click(function(e){
switchTo('overview');
});
switchTo('overview');
}); //close document ready
</script>
</head>
<body>