-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata.js
More file actions
163 lines (118 loc) · 4.17 KB
/
data.js
File metadata and controls
163 lines (118 loc) · 4.17 KB
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
var database=firebase.database();
/////////////////////////////////////////////////////////////////////
// Initialize the FirebaseUI Widget using Firebase.
var email_id;
firebase.auth().onAuthStateChanged(function(user) {
if (user) {
// User is signed in.
document.getElementById("user_div").style.display = "block";
document.getElementById("login_div").style.display = "none";
var user = firebase.auth().currentUser;
if(user != null){
email_id = user.email;
document.getElementById("user_para").innerHTML = "Welcome to Quiz Data Entry Portal.You are welcome: " + email_id;
}
} else {
// No user is signed in.
document.getElementById("user_div").style.display = "none";
document.getElementById("login_div").style.display = "block";
}
});
function login(){
var userEmail = document.getElementById("email_field").value;
var userPass = document.getElementById("password_field").value;
firebase.auth().signInWithEmailAndPassword(userEmail, userPass).catch(function(error) {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
window.alert("Error : " + errorMessage);
// ...
});
}
function logout(){
firebase.auth().signOut();
}
//////////////////////////////////////////////////////////////////////
/////////////////////////////////////////
let className = sessionStorage.getItem("className");
let subjectName = sessionStorage.getItem("subjectName");
////////////////////////////////////////////////////////
var clas=document.getElementById("clas").innerHTML=className;
var sub=document.getElementById("sub").innerHTML="Subject: "+subjectName;
////////////////////////////////////////////////////////
while(className==""||subjectName=="")
{
alert("Please go back and choose the class and the subject to proceed");
}
console.log(className+"\n"+subjectName);
function disableQuiz()
{
// var key=firebase.database().ref('Quiz/').push().key;
var Condition={
Value:false
}
firebase.database().ref(`Condition/${className}/${subjectName}`).set(Condition);
}
function enableQuiz()
{
// var key=firebase.database().ref('Quiz/').push().key;
var Condition={
Value:true
}
firebase.database().ref(`Condition/${className}/${subjectName}`).set(Condition);
}
/////////////////////////////////////////
function sendMesssage()
{
// var text1=document.getElementById("prima");
// var text2;
// console.log(text1.childNodes)
var today = new Date();
var date = today.getFullYear()+'-'+(today.getMonth()+1)+'-'+today.getDate();
var time = today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds();
var dateTime = date+' '+time;
dateTime=dateTime.toString();
//getting the question
var question=document.getElementById("question").value;
//getting the options
var option1=document.getElementById("option1").value;
var option2=document.getElementById("option2").value;
var option3=document.getElementById("option3").value;
var option4=document.getElementById("option4").value;
//getting the right answer
var answer=document.getElementById("answer").value;
if(question==""||option1==""||option2==""||option3==""||option4==""||answer=="")
{
alert("Please fill all the fields to submit for the quiz");
return;
}
else if(option1!=answer&&option2!=answer&&option3!=answer&&option4!=answer)
{
alert("Please check One of the options of four must be an answer");
return;
}
//console.log(question+"\n"+option1+option2+option3+option4+answer+dateTime);
var key=firebase.database().ref('Quiz/').push().key;
var Quiz={
Question:question,
Option1:option1,
Option2:option2,
Option3:option3,
Option4:option4,
author:email_id,
Answer:answer,
}
firebase.database().ref(`Quiz/${className}/${subjectName}/`).push(Quiz);
}
// Listen for form submit
document.getElementById('submit').addEventListener('click', submitForm);
// Submit form
function submitForm(e){
e.preventDefault();
// Show alert
//document.querySelector('.alert').style.display = 'block';
// Hide alert after 3 seconds
setTimeout(function(){
document.querySelector('.alert').style.display = 'none';
},3000);
}