forked from anantharam/lead-marketplace
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackend_client_preferences.php
469 lines (428 loc) · 16.1 KB
/
backend_client_preferences.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
<?php
function client_preferences_page(){
global $wpdb;
$users_table = $wpdb->users;
$table_name = $wpdb->prefix.'edugorilla_client_preferences';
$iid = $_REQUEST['iid'];
if(!empty($iid) && is_numeric($iid)){
$email = $wpdb->get_var("SELECT user_email from $users_table WHERE ID = ".$iid);
//echo $email;
$_POST['client_email']=$email;
$_POST['submit']=true;
}
if(isset($_POST['submit'])){
if(empty(trim($_POST['client_email']))){
$php_empty_error = "*This field cannot be blank";
} else{
$client_email = trim($_POST['client_email']);
$check_client = $wpdb->get_var("SELECT COUNT(ut.ID) from $table_name cpt,$users_table ut WHERE cpt.id=ut.ID AND ut.user_email = '".$client_email."' ");
if($check_client == 0){
$no_client_found = "*This client does not exist in our database";
}
}
}
?>
<style>
#preference_form{
display: none;
}
</style>
<script>
function form_not_empty(){
var x = document.getElementById('client_email').value;
if(x == ""){
document.getElementById('js_empty_error').innerHTML = "*This field cannot be blank";
return false;
} else{
return true;
}
}
</script>
<div class = "wrap">
<h1>Enter the Email-Id of the subscriber whose preferences you want to know</h1>
<form method = 'post' onsubmit = 'return form_not_empty()' action = "<?php echo $_SERVER['REQUEST_URI'];?>">
<table class = "form-table">
<tr>
<th>Subscriber's Email<sup><font color="red">*</font></sup></th>
<td>
<input type = 'text' id = 'client_email' name = 'client_email' value = "<?php echo trim($_POST['client_email']); ?>" placeholder = 'Type email here...' maxlength = '100'>
<font color = "red"><span id = 'js_empty_error'></span><?php echo $php_empty_error.$no_client_found; ?></font>
</td>
</tr>
<tr>
<th>
<input type = "hidden">
</th>
<td>
<input type = 'submit' name = 'submit'>
</td>
</tr>
</table>
</form>
</div>
<br/><br/><br/>
<?php
if(isset($_POST['submit']) && !(empty(trim($_POST['client_email']))) && $check_client > 0){
$value = $wpdb->get_row("SELECT ut.display_name AS client_name,ut.user_email AS email_id,cpt.* FROM $table_name cpt,$users_table ut WHERE ut.ID=cpt.id AND ut.user_email = '$client_email' ");
$not_email = $value->unsubscribe_email;
$not_sms = $value->unsubscribe_sms;
$is_lead_unlocked = $value->unlock_lead;
if($not_email == 1){
$unsub_email_val = "checked";
} else{
$unsub_email_val = "";
}
if($not_sms == 1){
$unsub_sms_val = "checked";
} else{
$unsub_sms_val = "";
}
if($is_lead_unlocked == 1){
$unlock_val = "checked";
} else{
$unlock_val = "";
}
$categories_list = get_terms('listing_categories', array('hide_empty' => false));
$location_list = get_terms('locations', array('hide_empty' => false));
$user_id = $wpdb->get_var("SELECT ID FROM $users_table WHERE user_email = '$client_email' ");
$category_count_value =1;
$location_count_value =1;
$notification = "";
$in_val = "";
$dd_val = "";
$wd_val = "";
$md_val = "";
$current_user_data = $wpdb->get_row("SELECT * FROM $table_name WHERE id = '$user_id' ");
$notificationString = $current_user_data->preferences;
//$notificationArray = explode(",", $notificationString);
if(preg_match('/Instant_Notifications/',$notificationString))
$in_val = "checked";
if(preg_match('/Daily_Digest/',$notificationString))
$dd_val = "checked";
if(preg_match('/Weekly_Digest/',$notificationString))
$wd_val = "checked";
if(preg_match('/Monthly_Digest/',$notificationString))
$md_val = "checked";
$category_result = get_category_current_user($user_id , $current_user_data);
$more_category = $category_result[0];
$category_count_value = $category_result[1];
$location_result = get_location_current_user($user_id , $current_user_data);
$more_location = $location_result[0];
$location_count_value = $location_result[1];
}
if (isset($_POST['submit_client_pref'])) {
$categories_list = get_terms('listing_categories', array('hide_empty' => false));
$location_list = get_terms('locations', array('hide_empty' => false));
$unlock_lead_ = $_POST['unlock_lead'];
$client_email2 = $_POST['client_email2'];
$notification_all = $_POST['notification'];
if (!empty($notification_all)) {
# code...
$notification = "";
foreach ($notification_all as $value) {
# code...
$notification = $value . ", " . $notification;
if($value == "Instant_Notifications")
$in_val = "checked";
else if($value == "Daily_Digest")
$dd_val = "checked";
else if($value == "Weekly_Digest")
$wd_val = "checked";
else if($value == "Monthly_Digest")
$md_val = "checked";
}
}
$category_count = $_POST['category_count'];
$location_count = $_POST['location_count'];
$category_count_value = $category_count;
$location_count_value = $location_count;
$category = array();
$location = array();
$more_category = "";
$more_location = "";
for ($i = 0; $i < $category_count; $i++) {
# code...
$category_name = "category".$i;
$location_name = "location".$i;
if(!empty($_POST[ $category_name ]) || !empty($_POST[$location_name])){
if ($i>0) {
# code...
$categoryRowValue = '<br name="br' . $category_name . '" /><input list="categories_list" name="' . $category_name . '" size="30" value="' . $_POST[ $category_name ] . '">';
$removeButton = '<input type = "button" name = "removeCategory' . $i . '" value = " - " onclick = "removeThisRow(' . $i . ')">';
$more_category = $more_category . $categoryRowValue . $removeButton;
}else
$category_select_val = $_POST[$category_name];
array_push($category, $_POST[$category_name]);
# code...
if ($i>0) {
# code...
$more_location = $more_location.'<br/><input list="location_list" name="'.$location_name.'" size="30" value="'.$_POST[$location_name].'">';
}else
$location_select_val = $_POST[$location_name];
array_push($location, $_POST[$location_name]);
}
}
foreach ($category as $category_value) {
$category_value = str_replace("&","&",$category_value);
$temp_cat = $all_cat;
foreach ($categories_list as $cat_value) {
//echo $categoryString;
if(strcmp($cat_value->name , $category_value) == 0){
$all_cat = $cat_value->term_id . "," . $all_cat;
}
}
if(strcmp($temp_cat , $all_cat) ==0){
$all_cat = "-1,".$all_cat;
}
}
foreach ($location as $location_value) {
$location_value = str_replace("&","&",$location_value);
$location_value = str_replace("->","",$location_value);
$temp_loc = $all_loc;
foreach ($location_list as $loc_value) {
if (strcmp($location_value , $loc_value->name) == 0) {
# code...
$all_loc = $loc_value->term_id . "," . $all_loc;
}
}
if(strcmp($temp_loc , $all_loc) ==0){
$all_loc = "-1,".$all_loc;
}
}
$not_email = $_POST['not_email'];
$not_sms = $_POST['not_sms'];
if($not_email == 1){
$unsub_email_val = "checked";
} else{
$unsub_email_val = "";
$not_email = 0;
}
if($not_sms == 1){
$unsub_sms_val = "checked";
} else{
$unsub_sms_val = "";
$not_sms = 0;
}
if ($unlock_lead_ != 1) {
# code...
$unlock_val = "";
$unlock_lead_ = 0;
}else
$unlock_val = "checked";
$user_id = $wpdb->get_var("SELECT ID FROM $users_table WHERE user_email = '$client_email2' ");
$user_detail = get_user_meta($user_id);
/*not required now*/
$first_name = $user_detail['first_name'][0];
$last_name = $user_detail['last_name'][0];
$_client_name = $first_name . " " . $last_name;
$client_email = $user_detail['user_general_email'][0];
$client_contact = $user_detail['user_general_phone'][0];
if ($wpdb->get_results("SELECT * FROM $table_name WHERE id = $user_id")) {
$client_result = $wpdb->update($table_name,
array(
'preferences' => $notification,
'location' => $all_loc,
'unlock_lead' => $unlock_lead_,
'unsubscribe_email' => $not_email,
'unsubscribe_sms' => $not_sms,
'category' => $all_cat
)
,
array('id' => $user_id)
, $format = null, $where_format = null);
} else {
$client_result = $wpdb->insert(
$wpdb->prefix . 'edugorilla_client_preferences',
array(
'id' => $user_id,
'contact_no' => $client_contact,
'preferences' => $notification,
'unsubscribe_email' => $not_email,
'unsubscribe_sms' => $not_sms,
'location' => $all_loc,
'unlock_lead' => $unlock_lead_,
'category' => $all_cat
)
);
}
if ($client_result)
$client_success = "<font color = 'green'>Saved Successfully</font>";
else
$client_success = "<font color = 'red'>Please try again</font>";
}
?>
<script type="text/javascript">
function addMoreRows() {
var ctrC = parseInt(document.getElementById("category_count").value);
var ctrL = parseInt(document.getElementById("location_count").value);
var ctrB = ctrC;
//Create an input type dynamically.
var element_c = document.createElement("input");
var element_l = document.createElement("input");
var element_b = document.createElement("input");
var br1 = document.createElement("br");
var br2 = document.createElement("br");
var element_name_c = "category" + ctrC;
element_c.setAttribute("list", "categories_list");
element_c.setAttribute("size", 30);
element_c.setAttribute("name", element_name_c);
var foo1 = document.getElementById("get_category");
foo1.insertBefore(br1, foo1.childNodes[0]);
foo1.insertBefore(element_c, foo1.childNodes[0]);
ctrC++;
document.getElementById("category_count").value = ctrC;
var element_name_b = "removeCategory" + ctrB;
element_b.setAttribute("type", "button");
element_b.setAttribute("value", " - ");
element_b.setAttribute("name", element_name_b);
element_b.setAttribute("onclick", "removeThisRow('" + ctrB + "')");
var foo0 = document.getElementById("get_category");
foo0.insertBefore(element_b, foo0.childNodes[1]);
var element_name_l = "location" + ctrL;
element_l.setAttribute("list", "location_list");
element_l.setAttribute("size", 30);
element_l.setAttribute("name", element_name_l);
//Assign different attributes to the element.
var foo2 = document.getElementById("get_location");
foo2.insertBefore(br2, foo2.childNodes[0]);
foo2.insertBefore(element_l, foo2.childNodes[0]);
ctrL++;
document.getElementById("location_count").value = ctrL;
}
function removeThisRow(rowId) {
var locationElem = document.getElementsByName("location" + rowId)[0];
var categoryElem = document.getElementsByName("category" + rowId)[0];
var removeButton = document.getElementsByName("removeCategory" + rowId)[0];
var catLineBreak = document.getElementsByName("brcategory" + rowId)[0];
var locLineBreak = document.getElementsByName("brlocation" + rowId)[0];
locationElem.parentNode.removeChild(locationElem);
categoryElem.parentNode.removeChild(categoryElem);
removeButton.parentNode.removeChild(removeButton);
catLineBreak.parentNode.removeChild(catLineBreak);
locLineBreak.parentNode.removeChild(locLineBreak);
}
</script>
<div id = "preference_form">
<h2>Subscriber Preferences</h2>
<form action="" method="post">
<p><?php echo $client_success; ?></p>
<table>
<tr>
<td>Subscriber's Email</td>
<td><input type = "text" name = "client_email2" value = "<?php
if(empty($client_email2)){
echo $client_email;
}else{echo $client_email2;}?>" readonly></td>
</tr>
<tr>
<td rowspan="4">Notification Preferences<sup><font color="red">*</font></sup> :</td>
<td colspan="2"><input type="checkbox" name="notification[]" id="notification"
value="Instant_Notifications" <?php echo $in_val ?>>Instant Notification
</td>
</tr>
<tr>
<td colspan="2"><input type="checkbox" id="notification" name="notification[]" value="Daily_Digest" <?php echo $dd_val ?>>Daily
Digest
</td>
</tr>
<tr>
<td colspan="2"><input type="checkbox" id="notification" name="notification[]" value="Weekly_Digest" <?php echo $wd_val ?> >Weekly
Digest
</td>
</tr>
<tr>
<td colspan="2"><input type="checkbox" id="notification" name="notification[]" value="Monthly_Digest" <?php echo $md_val ?>>Monthly
Digest
</td>
</tr>
<tr>
<td rowspan="2">Unsubscribe Preferences<sup><font color="red">*</font></sup> :</td>
<td colspan="2"><input type="checkbox" id="notification" name="not_email"
value="1" <?php echo $unsub_email_val ?>>Unsubscribe
Email
</td>
</tr>
<tr>
<td colspan="2"><input type="checkbox" id="notification" name="not_sms"
value="1" <?php echo $unsub_sms_val ?>>Unsubscribe
SMS
</td>
</tr>
<tr>
<td rowspan="2">Subscribe for following Categories :</td>
<td>Location</td>
<td>Category</td>
</tr>
<tr>
<td>
<?php $location = get_terms('locations', array('hide_empty' => false)); ?>
<datalist id="location_list">
<option value="">Select</option>
<?php
$templocationarray = array();
foreach ($location as $clients_location) {
$templocationarray[$clients_location->parent][$clients_location->term_id] = $clients_location->name;
}
foreach ($templocationarray as $var => $vals) {
if($var!=0){
$d = get_term_by('id', $var, 'locations');
?>
<option value="<?php echo $d->name; ?>">
<?php
foreach ( $vals as $index => $val ) {
?>
<!-------Use sub locations here to expand locations------>
<?php
}
}
else {
foreach ($vals as $index => $val) {
if(!array_key_exists($index,$templocationarray)){
?>
<option value="<?php echo $val; ?>">
<?php
}}
}
}
?>
</datalist>
<div id="get_location">
<input list="location_list" name="location0" size="30" value="<?php echo $location_select_val?>">
<?php echo $more_location ?>
</div>
<input type="text" hidden name="location_count" id="location_count" value="<?php echo $location_count_value ?>">
<font color="red"><?php echo $c_errors['location']; ?></font></td>
<td>
<?php $categories = get_terms('listing_categories', array('hide_empty' => false)); ?>
<datalist id="categories_list">
<?php foreach ($categories as $value) { ?>
<option value="<?php echo $value->name; ?>">
<?php } ?>
</datalist>
<div id="get_category">
<input list="categories_list" name="category0" size="30" value="<?php
echo $category_select_val ?>"><input type="button" name="removeCategory0" value=" - "
onclick="removeThisRow(0)">
<?php echo $more_category ?>
<input type="button" value=" + " onclick="addMoreRows()">
</div>
<input type="text" hidden name="category_count" id="category_count" value="<?php echo $category_count_value ?>">
<font color="red"><?php echo $c_errors['category']; ?></font></td>
</tr>
<tr>
<td>Automatically Unlock the Lead :</td>
<td><input type="checkbox" name="unlock_lead" value="1" <?php echo $unlock_val ?>></td>
</tr>
<tr><td><input type="submit" name="submit_client_pref" value="Save"/></td></tr>
</table>
</form>
</div>
<?php
if(isset($_POST['submit']) && !(empty(trim($_POST['client_email']))) && $check_client > 0){
echo "<script>document.getElementById('preference_form').style.display = 'block';</script>";
}
if ($_POST['submit_client_pref']) {
echo "<script>document.getElementById('preference_form').style.display = 'block';</script>";
}
}
?>