/
class.enquiry-admin.php
187 lines (160 loc) · 5.05 KB
/
class.enquiry-admin.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
<?php
class Enquiryadmin{
private static $initiated = false;
private static $settings = [];
public static function init() {
if ( ! self::$initiated ) {
self::init_hooks();
self::$settings=json_decode(get_option('anv_setting'),true);
}
}
public function getSettings(){
return self::$settings;
}
public static function init_hooks() {
self::$initiated = true;
add_action( 'admin_init', array( 'Enquiryadmin', 'admin_init' ) );
add_action( 'admin_menu', array( 'Enquiryadmin', 'admin_menu' ) );
add_action( 'admin_enqueue_scripts', array( 'Enquiryadmin', 'load_resources' ) );
add_action('wp_ajax_enq_update_options', array('Enquiryadmin','enq_update_options'));
add_action('wp_ajax_enquiry_list', array('Enquiryadmin','enquiry_list'));
add_action('wp_ajax_enquiry_trash', array('Enquiryadmin','enquiry_trash'));
}
private static function enquirytable(){
global $wpdb;
return $wpdb->prefix . 'anvitaenq';
}
public static function admin_init() {
load_plugin_textdomain( 'anvita-enquiry-form' );
}
public static function admin_menu() {
add_menu_page('Enquiry', 'Enquiry', 'manage_options','anvita-enquiry-form/admin/index.php','','dashicons-backup', 4.55);
}
public static function load_resources(){
wp_register_style( 'anv-enq-admin', ANVITA_ENQUIRY_PLUGIN_URL . 'admin/style.css', array(), ANVITA_ENQUIRY_VERSION );
wp_register_style( 'jqueryui', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.21/themes/redmond/jquery-ui.css', array(), 1.8 );
wp_enqueue_style( 'anv-enq-admin');
wp_enqueue_style( 'jqueryui');
}
public static function load_enquiry($isdeleted=0){
$f=0;
global $wpdb;
if(isset($_POST['p'])){
$f=$_POST['p']*10;
}
$c=10;
$return['no'] = $wpdb->get_var("SELECT COUNT(*) FROM ".self::enquirytable()."
WHERE isdeleted = ".$isdeleted);
$q="SELECT * FROM ".self::enquirytable()."
WHERE isdeleted = '".$isdeleted."' order by enqid desc LIMIT ".$f.",".$c;
$return['result'] = $wpdb->get_results($q);
$return['f']=$f;
$return['c']=$c;
return $return;
}
public static function load_pagination($f,$c,$n,$isdeleted=0){
$nop=$n/$c;
$i=0;
echo "<div class='enq_pagination'>";
while($i<$nop){
$class="";
if($i==$f) $class="enq_current";
echo '<a href="#" data-isdeleted="'.$isdeleted.'" class="enq_page '.$class.'" data-page="'.$i.'">'.($i+1).'</a>';
$i++;
}
echo "</div>";
}
public static function enquiry_list($res=""){
$val=$_POST;
if($res==""){
$res=self::load_enquiry($_POST['d']);
}
$html[0]='<table class="enq-schedule">
<tbody>
<tr>
<th>Name</th>
<th>Email</th>
<th>Country</th>
<th>City</th>
<th>Message</th>
<th>Enquiry Date</th>
</tr>';
$remove=['name',
'email',
'country',
'time',
'city',
'var',
'captcha',
'msg',
'isdeleted',
'type',
'enqid',
'attachment'
];
$class="odd";
foreach($res['result'] as $r){
if($r->isdeleted==1) {
$isdeleted="dashicons-undo";
$deltitle="Restore";
}
else{
$isdeleted="dashicons-trash";
$deltitle="Delete";
}
array_push($html, '<tr class="'.$class.'">');
array_push($html, "<td>".$r->name."</td>");
array_push($html, "<td>".$r->email."</td>");
array_push($html, "<td>".$r->country."</td>");
array_push($html, "<td>".$r->city."</td>");
array_push($html, "<td>".$r->msg."</td>");
array_push($html, "<td>".date('d-m-Y H:i:s',strtotime($r->time))."</td>");
array_push($html,"<td><a title='$deltitle' class='enq_trash_app dashicons $isdeleted' data-isdeleted='".$r->isdeleted."' data-id='".$r->enqid."' href='#'></a></td>");
array_push($html,"</tr>");
array_push($html,'<tr class="'.$class.'">');
array_push($html,"<td colspan='6'>");
foreach ($r as $dk=>$dv){
if(!in_array($dk, $remove)){
array_push($html, "<span class='enq_more'>".str_replace("enq-", "", $dk)." : ". $dv."</span>");
}
}
array_push($html,"</td>");
array_push($html,"</tr>");
if($class=="odd") $class="even";
else $class="odd";
}
array_push($html,"</tbody></table>");
echo join($html);
return "";
}
public static function enquiry_trash(){
if(isset($_POST['id'])){
global $wpdb;
if($_POST['d']==0) $wpdb->query("UPDATE ".self::enquirytable()." SET isdeleted = 1 WHERE enqid = ".$_POST['id']);
else $wpdb->query("UPDATE ".self::enquirytable()." SET isdeleted = 0 WHERE enqid = ".$_POST['id']);
echo $_POST['id'];
}
}
public static function enq_update_options(){
$response = array();
$response['resp']="";
if(!empty($_POST['field'])){
$opt=json_decode(get_option('anv_setting'),true);
if($_POST['field']=="alertdetails"){
$opt['email']['to']=$_POST['to'];
$opt['email']['cc']=$_POST['cc'];
$opt['email']['bcc']=$_POST['bcc'];
$opt['crm']=$_POST['crm'];
$opt['phone']=$_POST['phone'];
update_option('anv_setting', json_encode($opt));
$response['resp']=true;
}
} else {
$response['resp'] = "You didn't send the param";
}
header( "Content-Type: application/json" );
echo json_encode($response);
wp_die();
}
}
?>