-
Notifications
You must be signed in to change notification settings - Fork 39
/
getdata.php
259 lines (213 loc) · 7.92 KB
/
getdata.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
<?php
/**
* @author Piyush
* @copyright 2012
* getdata.php used to get certain data from database
*/
require "header.php";
require "vanshavali/suggest.php";
global $db, $user;
//get the type of data to be extracted
switch ($_POST['action']) {
case "check_wp_login":
if (vanshavali::$wp_login) {
//Check if all the members have wordpressid
$query = $db->query("select count(*) as membercount from member where username!='' and password!='' and wordpress_user=''");
$row = mysqli_fetch_array($query);
if ($row['membercount'] > 0) {
ajaxError();
break;
} else {
ajaxSuccess();
break;
}
} else {
ajaxError();
}
break;
case "forgotpassword":
$type = $_POST['type'];
$data = $_POST['data'];
//Find the member of the given email or username
if ($type == "email") {
$query = $db->query("select id from member where emailid = '" . $data . "'");
} else if ($type == "username") {
$query = $db->query("select id from member where username = '" . $data . "'");
}
$searchedID = $db->fetch($query);
if ($searchedID == null) {
//That username/email does not exist. Tell the user
trigger_error("NO_USER");
break;
}
$searchMember = vanshavali::getmember($searchedID['id']);
//Send the forgot password link
if ($searchMember->sendForgotPassword()) {
ajaxSuccess();
} else {
trigger_error("NO_MAIL");
}
break;
//when to check whether a given username already exists or not
case "username_check":
$username = $_POST['username'];
$query = $db->query("select count(*) as no from member where username='$username'");
$row = $db->fetch($query);
$arrRet = array("yes" => 0);
//if count is >1 then there are user with that username
if ($row['no'] > 0) {
$arrRet['yes'] = 1;
}
//If the format of username not correct
if (!preg_match('/^\w{5,}$/', $username)) {
$arrRet['yes'] = -1;
}
echo json_encode($arrRet);
break;
case "email_check":
$email = $_POST['email'];
$query = $db->query("select count(*) as no from member where emailid='$email'");
$row = $db->fetch($query);
//if count is >1 then there are user with that username
if ($row['no'] > 0) {
echo json_encode(array("yes" => 1));
} else {
echo json_encode(array("yes" => 0));
}
break;
//When to get suggestions for approval
case "getsuggestions":
global $suggest_handler;
$suggest_handler->getsuggestions();
break;
case "getapprovedsuggestion":
global $suggest_handler;
$suggest_handler->getApprovedSuggestions();
break;
//When adding wife
case "operationAddSpouse":
//Get the member to be changed
$member = vanshavali::getmember($_POST['otherSpouse']);
//Add wife to the member
if ($member->addSpouse($_POST['name'], TRUE)) {
ajaxSuccess();
} else {
ajaxError();
}
break;
case "operationAddParents":
//Get the member whose parents are to be added
$member = vanshavali::getmember($_POST['parentsof']);
if ($member->addParents($_POST['fathername'], $_POST['mothername'], true)) {
ajaxSuccess();
} else {
ajaxError();
}
break;
//When to approve suggestions
case "suggestionapproval":
//Retreive the values
$suggest_id = $_POST['suggestid'];
$action = $_POST['suggest_action'];
$suggest = new suggest($suggest_id);
switch ($action) {
case 0:
//Reject the suggestion
if (!$suggest->reject()) {
trigger_error("Cannot reject suggestion. Error Executing query", E_USER_NOTICE);
} else {
//Pass the id of the suggest so that proper HTML element can be made disappear
ajaxSuccess(array("suggestid" => $suggest_id) + $suggest->checkpercent());
}
break;
case 1:
//Accept the suggestion
if (!$suggest->approve()) {
trigger_error("Cannot approved the Suggestion. Error Executing query", E_USER_NOTICE);
} else {
//Pass the id of the suggest so that proper HTML element can be made disappear
ajaxSuccess(array("suggestid" => $suggest_id) + $suggest->checkpercent());
}
break;
case 2:
//Mark the suggestion as don't know
if (!$suggest->dontknow()) {
trigger_error("Cannot reject suggestion. Error Executing query", E_USER_NOTICE);
} else {
//Pass the id of the suggest so that proper HMTL element can be made disappear
ajaxSuccess(array('suggestid' => $suggest_id) + $suggest->checkpercent());
}
break;
}
break;
case "operation_add":
//Variables should have some value
if (isset($_POST['name']) && isset($_POST['gender']) && isset($_POST['sonof'])) {
//get the member to be modified
$member = vanshavali::getmember($_POST['sonof']);
//add son suggestion to it
if (!$member->addChild($_POST['name'], $_POST['gender'], TRUE)) {
trigger_error("Cannot add member. Some error Occured.");
} else {
ajaxSuccess();
}
}
break;
case "operation_remove":
if (!empty($_POST['memberid']) && !empty($_POST['type'])) {
//get the member to be deleted
$member = vanshavali::getmember($_POST['memberid']);
//add removal suggestion
if (!$member->remove(TRUE)) {
trigger_error("Cannot add member. Some error occured");
} else {
ajaxSuccess();
}
}
break;
case "operation_edit":
if (isset($_POST['type']) && isset($_POST['name']) && isset($_POST['gender']) && isset($_POST['relationship']) && isset($_POST['dob']) && isset($_POST['alive']) && isset($_POST['memberid'])) {
//Get the member
$member = vanshavali::getmember($_POST['memberid']);
//Now add the suggestion
if (!$member->edit($_POST['name'], $_POST['gender'], $_POST['relationship'], $_POST['dob'], $_POST['alive'], $_POST["gaon"], TRUE)) {
trigger_error("Cannot Edit Member. Some error occured");
} else {
ajaxSuccess();
}
}
break;
case "feedback":
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
if (!$db->query("insert into feedback (user_name,user_emailid,feedback_text)
values ('$name','$email','$message')")
) {
trigger_error("Some error occured with the database query");
} else {
ajaxSuccess();
}
break;
case "checkregistered":
global $db;
$res = vanshavali::getmember($_POST['id']);
if (empty($res->data['username']) && empty($res->data['password'])) {
ajaxSuccess();
} else {
ajaxError();
}
break;
case "reportError":
if (vanshavali::mailAdmin("mail.apierror.tpl", array("errorText" => $_POST['errorText']), "Report: API Failed"))
{
ajaxSuccess();
}
else
{
ajaxError();
}
break;
default: //when nothing matches
break;
}