$("#sortby").val(''); $("#show_status").val(''); $("#show_type").val(''); $("#show_modifier").val(''); $("#show_custom").val(''); // Users custom loadData function loadData(custom) { var sortby = $("#sortby").val(); var show_status = $("#show_status").val(); var show_type = $("#show_type").val(); var show_modifier = $("#show_modifier").val(); var show_custom = $("#show_custom").val(); var custom_data = custom; if (show_custom.length > 0 && custom.length == 0) { custom_data = show_custom; } else { if (sortby.length) { custom_data += "&sortby="+sortby; } if (show_status.length) { custom_data += "&show_status="+show_status; } if (show_type.length) { custom_data += "&show_type="+show_type; } if (show_modifier.length) { custom_data += "&show_modifier="+show_modifier; } } loadDynamicData(tableName, tableAction, sequenceFlag, tableID, '', custom_data); } $(document).on('click', '.edit-student', function(e) { e.preventDefault(); var snum = $(this).attr('snum'); window.location = "/?action=students&naction=edit-student&student_num="+snum; }); $("#info-dialog").dialog({ autoOpen: false, minWidth: 750, minHeight: 650, modal: true, position: { my: 'center', at: 'center' } }); $("#orders-dialog").dialog({ autoOpen: false, minWidth: 850, minHeight: 450, modal: true, position: { my: 'center', at: 'center' } }); $("#merge-dialog").dialog({ autoOpen: false, minWidth: 550, minHeight: 450, modal: true, position: { my: 'center', at: 'center' } }); $("#trx-dialog").dialog({ autoOpen: false, minWidth: 980, maxHeight: 600, modal: true, position: { my: 'center', at: 'center' } }); $("#add-user").click(function(e) { e.preventDefault(); insertNew(); }); $("#clear-screen").click(function(e) { e.preventDefault(); $("#sortby").val(''); $("#show_status").val(''); $("#show_type").val(''); $("#show_modifier").val(''); $("#dynamic-table-div").html(""); }); $("#view-all-users").click(function(e) { e.preventDefault(); $("#sortby").val(''); $("#show_status").val(''); $("#show_type").val(''); $("#show_modifier").val(''); $("#show_custom").val(''); loadData(""); }); $("#view-admin-users").click(function(e) { e.preventDefault(); $("#show_type").val('Admin'); $("#show_modifier").val(''); $("#show_custom").val(''); loadData(""); }); $("#view-staff-users").click(function(e) { e.preventDefault(); $("#show_type").val('Staff'); $("#show_modifier").val(''); $("#show_custom").val(''); loadData(""); }); $("#view-parent-users").click(function(e) { e.preventDefault(); $("#show_type").val('Parent'); $("#show_modifier").val(''); $("#show_custom").val(''); loadData(""); }); $("#view-guest-users").click(function(e) { e.preventDefault(); $("#show_type").val('Guest'); $("#show_modifier").val(''); $("#show_custom").val(''); loadData(""); }); $("#view-supplier-users").click(function(e) { e.preventDefault(); $("#show_type").val('Supplier'); $("#show_modifier").val(''); $("#show_custom").val(''); loadData(""); }); $("#view-users-first-name-sort").click(function(e) { e.preventDefault(); $("#sortby").val('first_name'); $("#show_custom").val(''); loadData(""); }); $("#view-users-last-name-sort").click(function(e) { e.preventDefault(); $("#sortby").val('last_name'); $("#show_custom").val(''); loadData(""); }); $("#view-users-email-sort").click(function(e) { e.preventDefault(); $("#sortby").val('email'); $("#show_custom").val(''); loadData(""); }); $("#view-users-user-id-sort").click(function(e) { e.preventDefault(); $("#sortby").val('userid'); $("#show_custom").val(''); loadData(""); }); $("#view-users-no-email").click(function(e) { e.preventDefault(); // $("#show_type").val(''); $("#show_modifier").val('noemail'); $("#show_custom").val(''); loadData(""); }); $("#view-users-volunteers").click(function(e) { e.preventDefault(); $("#show_type").val(''); $("#show_modifier").val('volunteers'); $("#show_custom").val(''); loadData(""); }); $("#view-users-no-students").click(function(e) { e.preventDefault(); $("#show_type").val('Parent'); $("#show_modifier").val('nostudents'); $("#show_custom").val(''); loadData(""); }); $("#view-users-balance-owing").click(function(e) { e.preventDefault(); $("#show_modifier").val('balance-owing'); $("#show_custom").val(''); loadData(""); }); $("#view-users-balance-payable").click(function(e) { e.preventDefault(); $("#show_modifier").val('balance-payable'); $("#show_custom").val(''); loadData(""); }); $("#view-users-balance-print").click(function(e) { e.preventDefault(); var show_modifier = $("#show_modifier").val(); if (show_modifier.length == 0) show_modified = 'balance-owing'; location.href = "/?action=user-account-balances-report&show_modifier="+show_modifier; }); $("#view-users-balance-details-print").click(function(e) { e.preventDefault(); var show_modifier = $("#show_modifier").val(); if (show_modifier.length == 0) show_modified = 'balance-owing'; location.href = "/?action=user-account-balances-report&show_modifier="+show_modifier+"&mode=Students"; }); $("#view-users-balance-csv").click(function(e) { e.preventDefault(); var show_modifier = $("#show_modifier").val(); if (show_modifier.length == 0) show_modified = 'balance-owing'; location.href = "/?action=user-account-balances-csv&show_modifier="+show_modifier; }); $("#user-search-field").autocomplete({ source: "ajax.UserSearch.php", minLength: 3, width: 750, selectFirst: false, select: function( event, results ) { var user_num = results.item.user_num; $("#user-search-field").val(''); $("#show_custom").val("&record_num="+user_num); editData(user_num); } }); $("#dialog_userid").autocomplete({ source: "ajax.UserIDSearch.php", minLength: 3, width: 750, selectFirst: false, select: function( event, results ) { var user_num = results.item.user_num; $("#data-dialog").dialog('close'); editData(user_num); } }); $("#view-matching-users").click(function(e) { var match = $("#user-search-field").val(); if (match.length < 3) { $("#user-search-field").focus(); return; } $("#show_custom").val("&match="+match); loadData("&match="+match); }); $("#amount-dialog").dialog({ autoOpen: false, minWidth: 200, minHeight: 200, modal: true, position: { my: 'center', at: 'center' } }); $("#block-from-ordering").click(function(e) { e.preventDefault(); var title = ""; $("#amount-title").html(title); $("#amount").val(''); $("#naction").val('Block'); $("#amount-dialog").dialog("open"); }); $("#clear-for-ordering").click(function(e) { e.preventDefault(); var title = ""; $("#amount-title").html(title); $("#amount").val(''); $("#naction").val('Clear'); $("#amount-dialog").dialog("open"); }); $("#post-amount").click(function(e) { e.preventDefault(); var amount = $("#amount").val(); var naction = $("#naction").val(); $("#amount-dialog").dialog("close"); $.ajax({ type: 'GET', url: "ajax.UserUpdate.php", data: { amount: amount, naction: naction } }).done(function(){ alert(""); loadData(""); }); }); $(document).on("click", ".user-status", function() { var Status = $(this).attr('val'); var rnum = $(this).attr('rnum'); var spanID = $(this); var data = "table_name=users"+ "&sequence_flag=N"+ "&record_num="+rnum+ "&Validation=N"+ "&status="; switch (Status) { case 'Active': var newVal = "Inactive"; var newText = ""; break; case 'Inactive': var newVal = "Active"; var newText = ""; break; } data += newVal; $.getJSON("ajax.DataRecord.Update.php", data, function(results) { $(spanID).html(newText); $(spanID).attr('val',newVal); } ); }); $(document).on("click", ".user-can-order", function() { var Status = $(this).attr('val'); var rnum = $(this).attr('rnum'); var spanID = $(this); var newVal = 'Yes'; var newText = ""; var data = "table_name=users"+ "&sequence_flag=N"+ "&record_num="+rnum+ "&Validation=N"+ "&can_order="; switch (Status) { case 'Yes': newVal = "No"; newText = ""; break; case 'No': newVal = "Balance"; newText = ""; break; case 'Balance': newVal = "Yes"; newText = ""; break; } data += newVal; $.getJSON("ajax.DataRecord.Update.php", data, function(results) { $(spanID).html(newText); $(spanID).attr('val',newVal); } ); }); $(document).on("click", ".user-emails", function() { var Status = $(this).attr('val'); var rnum = $(this).attr('rnum'); var spanID = $(this); var data = "table_name=users"+ "&sequence_flag=N"+ "&record_num="+rnum+ "&Validation=N"+ "&receive_emails="; switch (Status) { case 'Y': var newVal = "N"; var newText = ""; break; case 'N': var newVal = "Y"; var newText = ""; break; } data += newVal; $.getJSON("ajax.DataRecord.Update.php", data, function(results) { $(spanID).html(newText); $(spanID).attr('val',newVal); } ); }); $(document).on("click", ".user-reminder", function() { var Status = $(this).attr('val'); var rnum = $(this).attr('rnum'); var spanID = $(this); var data = "table_name=users"+ "&sequence_flag=N"+ "&record_num="+rnum+ "&Validation=N"+ "&email_reminders="; switch (Status) { case 'Y': var newVal = "N"; var newText = ""; break; case 'N': var newVal = "Y"; var newText = ""; break; } data += newVal; $.getJSON("ajax.DataRecord.Update.php", data, function(results) { $(spanID).html(newText); $(spanID).attr('val',newVal); } ); }); $(document).on('click', '.email-flag', function(e) { var Flag = $(this).attr('val'); var rnum = $(this).attr('rnum'); var spanID = $(this); var data = "table_name=users"+ "&sequence_flag=N"+ "&record_num="+rnum+ "&Validation=N"+ "&email_flag="; switch (Flag) { case 'Y': var newVal = "N"; var newText = '(N)'; break; case 'N': var newVal = "Y"; var newText = '(Y)'; break; } data += newVal; $.getJSON("ajax.DataRecord.Update.php", data, function(results) { $(spanID).html(newText); $(spanID).attr('val',newVal); } ); }); $(document).on('click touch', '.account-students', function(e) { e.preventDefault(); var rnum = $(this).attr('rnum'); var nstudents = $("#nstudents_"+rnum).html(); if (nstudents == '0') { alert(""); return; } var data = "table_name=people"+ "&sequence_flag=N"+ "&action=user-account-students"+ "&user_num="+rnum+ "&table_id=students-table"; $.getJSON( "ajax.DataTable.Fetch.php",data, function(results) { $("#dynamic-info-div").html(results.content); $("#info-dialog").dialog('option', 'title', ""); $("#info-dialog").dialog('open'); } ); }); $(document).on('click touch', '.login-reminder', function(e) { e.preventDefault(); var rnum = $(this).attr('rnum'); var email = ''; if (email == '' && $("#dialog_email")) email = $("#dialog_email").val(); if (email == '' && $("#email_"+rnum)) email = $("#email_"+rnum).val(); if (email.length == 0) { alert("\n"); return; } if (!confirm("\n")) return; $.ajax({ type: 'GET', url: "ajax.sendLoginReminder.php", data: { user_num: rnum } }).done(function() { alert(""); }); }); $(document).on('click touch', '.weekly-reminder', function(e) { e.preventDefault(); var rnum = $(this).attr('rnum'); var email = ''; if (email == '' && $("#dialog_email")) email = $("#dialog_email").val(); if (email == '' && $("#email_"+rnum)) email = $("#email_"+rnum).val(); if (email.length == 0) { alert("\n"); return; } var data = "user_num="+rnum; $.getJSON("ajax.userNumberOfStudents.php", data, function(results) { if (results.number == 0) { alert(""); return; } else { var msg = "\n" + ""; if (!confirm(msg)) return; $.ajax({ type: 'GET', url: "ajax.sendWeeklyReminder.php", data: { user_num: rnum } }).done(function() { alert(""); }); } } ); }); $(document).on('click touch', '.manage-user-account', function(e) { e.preventDefault(); var rnum = $(this).attr('rnum'); window.location = "/?action=user-account&naction=add&user_num="+rnum; }); $("#users-merge-accounts").click(function(e) { e.preventDefault(); $("#source_user_account").val(''); $("#destination_user_account").val(''); $("#merge-dialog").dialog('open'); }); $("#MergeAccountsBtn").click(function(e) { e.preventDefault(); var source = $("#source_user_account").val(); var destination = $("#destination_user_account").val(); var sname = $("#source_user_account option:selected").text(); var dname = $("#destination_user_account option:selected").text(); if (source == 0 || destination == 0) { alert(""); return; } if (source == destination) { alert(""); return; } var msg = "\n\n"+ ": "+sname+"\n"+ ": "+dname; r = confirm(msg); if (r == true) { $.ajax({ type: 'GET', url: "ajax.mergeUserAccounts.php", data: { source: source, destination: destination } }).done(function() { alert(""); $("#merge-dialog").dialog('close'); editData(destination); }); } }); $("#closeInfoDialogBtn").click(function(e) { e.preventDefault(); $("#info-dialog").dialog('close'); }); $("#closeMergeDialogBtn").click(function(e) { e.preventDefault(); $("#merge-dialog").dialog('close'); }); $(document).on('click', '.student-orders', function(e) { e.preventDefault(); var num = $(this).attr('num'); var snum = $(this).attr('rnum'); if (num == 0) { alert(""); return; } var data = "table_name=hotlunch_order_header"+ "&sequence_flag=N"+ "&action=student-orders"+ "&student_num="+snum+ "&display_mode=AllSchedules"+ "&table_id=student-orders-table"; $.getJSON( "ajax.DataTable.Fetch.php",data, function(results) { $("#orders-div").html(results.content); $("#orders-dialog").dialog('option', 'title', ""); $("#orders-dialog").dialog('open'); } ); }); $("#closeOrdersDialogBtn").click(function(e) { e.preventDefault(); $("#orders-dialog").dialog('close'); }); $(document).on("click", ".user-account", function() { var user_num = $(this).attr('rnum'); var data = "table_name=user_account"+ "&sequence_flag=N"+ "&action=user-account-transactions"+ "&table_id="+ "&user_num="+user_num; // Get user account transactions $.getJSON( "ajax.DataTable.Fetch.php",data, function(results) { $("#user-account-div").html(results.content); $("#trx-dialog").dialog("open"); if (results.count > 40) window.location = '#user-account-div'; } ); }); $(document).on('click', '.trx-close-window-btn', function(e) { e.preventDefault(); $("#trx-dialog").dialog("close"); }); $(document).on('click', '#edit-user-account-transactions', function(e) { e.preventDefault(); var unum = $(this).attr('unum'); window.location = "?action=user-account&user_num="+unum; });