11 <script src="https://www.gstatic.com/firebasejs/8.10.0/firebase-app.js"></script>
12 <script src="https://www.gstatic.com/firebasejs/8.10.0/firebase-auth.js"></script>
13 <script src="https://www.gstatic.com/firebasejs/8.10.0/firebase-database.js"></script>
14 <style>
15 @keyframes float {
562 apiKey: "AIzaSyD6EXA7D77rQDQEohB52BvTYimFeTEaAho",
563 authDomain: "rn-gfx-tool.firebaseapp.com",
564 databaseURL: "https://rn-gfx-tool-default-rtdb.asia-southeast1.firebasedatabase.app",
565 projectId: "rn-gfx-tool",
566 storageBucket: "rn-gfx-tool.appspot.com",
572 firebase.initializeApp(firebaseConfig);
573 const auth = firebase.auth();
574 const database = firebase.database();
575
576 // DOM Elements
666 // Check if user is admin
667 function checkAdmin(userId) {
668 database.ref('admins/' + userId).once('value', snapshot => {
669 if (snapshot.exists()) {
670 document.getElementById('admin-link').style.display = 'block';
677 function loadUserData(userId) {
678 // Load balance and tasks
679 database.ref('users/' + userId).on('value', snapshot => {
680 const userData = snapshot.val();
681 if (userData) {
687
688 // Load tasks
689 database.ref('tasks').on('value', snapshot => {
690 const tasksContainer = document.getElementById('tasks-list');
691 tasksContainer.innerHTML = '';
727
728 // Load offers
729 database.ref('offers').on('value', snapshot => {
730 const offersContainer = document.getElementById('offers-list');
731 offersContainer.innerHTML = '';
750
751 // Load withdrawal history
752 database.ref('withdrawals').orderByChild('userId').equalTo(userId).on('value', snapshot => {
753 const historyContainer = document.getElementById('withdrawal-history');
754 historyContainer.innerHTML = '';
776
777 // Load recent activity
778 database.ref('userActivities/' + userId).limitToLast(5).on('value', snapshot => {
779 const activityContainer = document.getElementById('recent-activity');
780 activityContainer.innerHTML = '';
800
801 // Load admin stats
802 database.ref('users').once('value', snapshot => {
803 document.getElementById('total-users').textContent = snapshot.numChildren();
804 });
805
806 database.ref('withdrawals').once('value', snapshot => {
807 let total = 0;
808 snapshot.forEach(withdrawalSnapshot => {
812 });
813
814 database.ref('withdrawals').orderByChild('status').equalTo('pending').once('value', snapshot => {
815 document.getElementById('pending-requests').textContent = snapshot.numChildren();
816 });
844 displayName: username
845 }).then(() => {
846 // Create user in database
847 return database.ref('users/' + userCredential.user.uid).set({
848 username: username,
849 email: email,
850 balance: 0,
851 tasksCompleted: 0,
852 createdAt: firebase.database.ServerValue.TIMESTAMP
853 });
854 });
867 const userId = auth.currentUser.uid;
868
869 database.ref('tasks/' + taskId).once('value', taskSnapshot => {
870 const task = taskSnapshot.val();
871
872 // Update user balance
873 database.ref('users/' + userId).transaction(user => {
874 if (user) {
875 user.balance = (user.balance || 0) + task.reward;
880
881 // Record activity
882 database.ref('userActivities/' + userId).push().set({
883 type: 'task',
884 description: `Completed task: ${task.title}`,
885 amount: task.reward,
886 timestamp: firebase.database.ServerValue.TIMESTAMP
887 });
888
894 const userId = auth.currentUser.uid;
895
896 database.ref('offers/' + offerId).once('value', offerSnapshot => {
897 const offer = offerSnapshot.val();
898
900 setTimeout(() => {
901 // Update user balance
902 database.ref('users/' + userId).transaction(user => {
903 if (user) {
904 user.balance = (user.balance || 0) + offer.reward;
908
909 // Record activity
910 database.ref('userActivities/' + userId).push().set({
911 type: 'offer',
912 description: `Completed offer: ${offer.title}`,
913 amount: offer.reward,
914 timestamp: firebase.database.ServerValue.TIMESTAMP
915 });
916
938
939 // Check balance
940 database.ref('users/' + userId).once('value', snapshot => {
941 const user = snapshot.val();
942 if (user.balance < amount) {
946
947 // Deduct from balance
948 database.ref('users/' + userId).update({
949 balance: user.balance - amount
950 });
951
952 // Create withdrawal request
953 database.ref('withdrawals').push().set({
954 userId: userId,
955 amount: amount,
957 details: details,
958 status: 'pending',
959 timestamp: firebase.database.ServerValue.TIMESTAMP
960 });
961
962 // Record activity
963 database.ref('userActivities/' + userId).push().set({
964 type: 'withdrawal',
965 description: `Withdrawal request: โน${amount.toFixed(2)} via ${method}`,
966 amount: -amount,
967 timestamp: firebase.database.ServerValue.TIMESTAMP
968 });
969
984 }
985
986 database.ref('tasks').push().set({
987 title: title,
988 description: description,
989 reward: reward,
990 createdAt: firebase.database.ServerValue.TIMESTAMP
991 });
992
1001 function deleteTask(taskId) {
1002 if (confirm('Are you sure you want to delete this task?')) {
1003 database.ref('tasks/' + taskId).remove();
1004 }
1005 }
1007 // Initialize sample data if empty
1008 function initializeSampleData() {
1009 database.ref('tasks').once('value', snapshot => {
1010 if (!snapshot.exists()) {
1011 const sampleTasks = [
1028
1029 sampleTasks.forEach(task => {
1030 database.ref('tasks').push().set(task);
1031 });
1032 }
1033 });
1034
1035 database.ref('offers').once('value', snapshot => {
1036 if (!snapshot.exists()) {
1037 const sampleOffers = [
1054
1055 sampleOffers.forEach(offer => {
1056 database.ref('offers').push().set(offer);
1057 });
1058 }
1060
1061 // Make first user admin
1062 database.ref('users').limitToFirst(1).once('value', snapshot => {
1063 snapshot.forEach(userSnapshot => {
1064 database.ref('admins/' + userSnapshot.key).set(true);
1065 });
1066 });