| 1 | <?php |
|---|
| 2 | if (!defined('ABSPATH')) exit; // Exit if accessed directly |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | /* |
|---|
| 7 | * Save Lead collecting method |
|---|
| 8 | */ |
|---|
| 9 | function lfb_save_lead_settings() |
|---|
| 10 | { |
|---|
| 11 | $nonce = $_REQUEST['lrv_nonce_verify']; |
|---|
| 12 | // Get all the user roles as an array. |
|---|
| 13 | if (isset($_POST['action-lead-setting']) && current_user_can('manage_options') && wp_verify_nonce($nonce, 'lrv-nonce')) { |
|---|
| 14 | |
|---|
| 15 | $data_recieve_method = intval($_POST['data-recieve-method']); |
|---|
| 16 | $this_form_id = intval($_POST['action-lead-setting']); |
|---|
| 17 | global $wpdb; |
|---|
| 18 | $table_name = LFB_FORM_FIELD_TBL; |
|---|
| 19 | $update_query = "update " . LFB_FORM_FIELD_TBL . " set storeType='" . $data_recieve_method . "' where id='" . $this_form_id . "'"; |
|---|
| 20 | $th_save_db = new LFB_SAVE_DB($wpdb); |
|---|
| 21 | $update_leads = $th_save_db->lfb_update_form_data($update_query); |
|---|
| 22 | if ($update_leads) { |
|---|
| 23 | esc_html_e('updated', 'lead-form-builder'); |
|---|
| 24 | } |
|---|
| 25 | |
|---|
| 26 | die(); |
|---|
| 27 | |
|---|
| 28 | } |
|---|
| 29 | } |
|---|
| 30 | |
|---|
| 31 | add_action('wp_ajax_SaveLeadSettings', 'lfb_save_lead_settings'); |
|---|
| 32 | |
|---|
| 33 | /* |
|---|
| 34 | * Save Email Settings |
|---|
| 35 | */ |
|---|
| 36 | |
|---|
| 37 | function lfb_save_email_settings() |
|---|
| 38 | { |
|---|
| 39 | |
|---|
| 40 | $nonce = $_REQUEST['aes_nonce']; |
|---|
| 41 | // Get all the user roles as an array. |
|---|
| 42 | if (isset($_POST['email_setting']['form-id']) && current_user_can('manage_options') && wp_verify_nonce($nonce, 'aes-nonce')) { |
|---|
| 43 | |
|---|
| 44 | global $wpdb; |
|---|
| 45 | $email_setting = array(); |
|---|
| 46 | $this_form_id = intval($_POST['email_setting']['form-id']); |
|---|
| 47 | $email_setting['email_setting'] = isset($_POST['email_setting']) ? $_POST['email_setting'] : ''; |
|---|
| 48 | $serialize = maybe_serialize($email_setting); |
|---|
| 49 | $table_name = LFB_FORM_FIELD_TBL; |
|---|
| 50 | $update_query = "update " . LFB_FORM_FIELD_TBL . " set mail_setting='" . $serialize . "' where id='" . $this_form_id . "'"; |
|---|
| 51 | $th_save_db = new LFB_SAVE_DB($wpdb); |
|---|
| 52 | $update_leads = $th_save_db->lfb_update_form_data($update_query); |
|---|
| 53 | if ($update_leads) { |
|---|
| 54 | esc_html_e('updated', 'lead-form-builder'); |
|---|
| 55 | } |
|---|
| 56 | die(); |
|---|
| 57 | } |
|---|
| 58 | } |
|---|
| 59 | |
|---|
| 60 | add_action('wp_ajax_SaveEmailSettings', 'lfb_save_email_settings'); |
|---|
| 61 | |
|---|
| 62 | /* |
|---|
| 63 | * Save captcha Keys |
|---|
| 64 | */ |
|---|
| 65 | |
|---|
| 66 | function lfb_save_captcha_settings() |
|---|
| 67 | { |
|---|
| 68 | $nonce = $_POST['captcha_nonce']; |
|---|
| 69 | |
|---|
| 70 | if (isset($_POST['captcha-keys']) && current_user_can('manage_options') && wp_verify_nonce($nonce, 'captcha-nonce')) { |
|---|
| 71 | |
|---|
| 72 | $captcha_setting_sitekey = sanitize_text_field($_POST['captcha-setting-sitekey']); |
|---|
| 73 | $captcha_setting_secret = sanitize_text_field($_POST['captcha-setting-secret']); |
|---|
| 74 | |
|---|
| 75 | if (get_option('captcha-setting-sitekey') !== false) { |
|---|
| 76 | update_option('captcha-setting-sitekey', $captcha_setting_sitekey); |
|---|
| 77 | update_option('captcha-setting-secret', $captcha_setting_secret); |
|---|
| 78 | } else { |
|---|
| 79 | add_option('captcha-setting-sitekey', $captcha_setting_sitekey); |
|---|
| 80 | add_option('captcha-setting-secret', $captcha_setting_secret); |
|---|
| 81 | } |
|---|
| 82 | } |
|---|
| 83 | die(); |
|---|
| 84 | } |
|---|
| 85 | |
|---|
| 86 | add_action('wp_ajax_SaveCaptchaSettings', 'lfb_save_captcha_settings'); |
|---|
| 87 | |
|---|
| 88 | /* |
|---|
| 89 | * Delete Leads From Back-end |
|---|
| 90 | */ |
|---|
| 91 | function lfb_delete_leads_backend() |
|---|
| 92 | { |
|---|
| 93 | |
|---|
| 94 | $nonce = $_REQUEST['_lfbnonce']; |
|---|
| 95 | // Get all the user roles as an array. |
|---|
| 96 | |
|---|
| 97 | $check = false; |
|---|
| 98 | if (isset($_POST['lead_id']) && current_user_can('manage_options') && wp_verify_nonce($nonce, 'lfb-nonce-rm')) { |
|---|
| 99 | $check = true; |
|---|
| 100 | |
|---|
| 101 | $this_lead_id = intval($_POST['lead_id']); |
|---|
| 102 | global $wpdb; |
|---|
| 103 | $table_name = LFB_FORM_DATA_TBL; |
|---|
| 104 | |
|---|
| 105 | $update_query = $wpdb->prepare(" DELETE FROM $table_name WHERE id = %d ", $this_lead_id); |
|---|
| 106 | |
|---|
| 107 | $th_save_db = new LFB_SAVE_DB($wpdb); |
|---|
| 108 | $update_leads = $th_save_db->lfb_delete_form($update_query); |
|---|
| 109 | echo esc_html($update_leads); |
|---|
| 110 | } |
|---|
| 111 | |
|---|
| 112 | echo $check; |
|---|
| 113 | } |
|---|
| 114 | |
|---|
| 115 | add_action('wp_ajax_delete_leads_backend', 'lfb_delete_leads_backend'); |
|---|
| 116 | |
|---|
| 117 | /* |
|---|
| 118 | * Save captcha status for form ON/OFF |
|---|
| 119 | */ |
|---|
| 120 | |
|---|
| 121 | function lfb_save_captcha_option() |
|---|
| 122 | { |
|---|
| 123 | $nonce = $_POST['captcha_nonce']; |
|---|
| 124 | if (isset($_POST['captcha_on_off_form_id']) && current_user_can('manage_options') && wp_verify_nonce($nonce, 'captcha-nonce')) { |
|---|
| 125 | |
|---|
| 126 | $captcha_option = sanitize_text_field($_POST['captcha-on-off-setting']); |
|---|
| 127 | $this_form_id = intval($_POST['captcha_on_off_form_id']); |
|---|
| 128 | global $wpdb; |
|---|
| 129 | $table_name = LFB_FORM_FIELD_TBL; |
|---|
| 130 | $update_query = "update " . LFB_FORM_FIELD_TBL . " set captcha_status='" . $captcha_option . "' where id='" . $this_form_id . "'"; |
|---|
| 131 | $th_save_db = new LFB_SAVE_DB($wpdb); |
|---|
| 132 | $update_leads = $th_save_db->lfb_update_form_data($update_query); |
|---|
| 133 | if ($update_leads) { |
|---|
| 134 | esc_html_e('updated', 'lead-form-builder'); |
|---|
| 135 | } |
|---|
| 136 | } |
|---|
| 137 | die(); |
|---|
| 138 | } |
|---|
| 139 | |
|---|
| 140 | add_action('wp_ajax_SaveCaptchaOption', 'lfb_save_captcha_option'); |
|---|
| 141 | |
|---|
| 142 | /* |
|---|
| 143 | * Show all Leads column on Lead Page Based on form selection |
|---|
| 144 | */ |
|---|
| 145 | |
|---|
| 146 | function lfb_ShowAllLeadThisForm() |
|---|
| 147 | { |
|---|
| 148 | if ((isset($_POST['form_id']) && ($_POST['form_id'] != '')) || (isset($_GET['form_id']) && ($_GET['form_id'] != ''))) { |
|---|
| 149 | |
|---|
| 150 | global $wpdb; |
|---|
| 151 | $table_name = LFB_FORM_DATA_TBL; |
|---|
| 152 | $th_save_db = new LFB_SAVE_DB($wpdb); |
|---|
| 153 | $nonce = wp_create_nonce('lfb-nonce-rm'); |
|---|
| 154 | $showLeadsObj = new LFB_Show_Leads(); |
|---|
| 155 | $start = 0; |
|---|
| 156 | $limit = 10; |
|---|
| 157 | $detail_view = ''; |
|---|
| 158 | $slectleads = false; |
|---|
| 159 | |
|---|
| 160 | if (isset($_GET['id'])) { |
|---|
| 161 | $id = intval($_GET['id']); |
|---|
| 162 | $start = ($id - 1) * $limit; |
|---|
| 163 | $form_id = intval($_GET['form_id']); |
|---|
| 164 | $sn_counter = $start; |
|---|
| 165 | } else { |
|---|
| 166 | $id = 1; |
|---|
| 167 | $form_id = intval($_POST['form_id']); |
|---|
| 168 | $sn_counter = 0; |
|---|
| 169 | } |
|---|
| 170 | if (isset($_GET['detailview'])) { |
|---|
| 171 | $detail_view = sanitize_text_field($_GET['detailview']); |
|---|
| 172 | } |
|---|
| 173 | |
|---|
| 174 | if (isset($_POST['slectleads'])) { |
|---|
| 175 | $slectleads = sanitize_text_field($_POST['slectleads']); |
|---|
| 176 | } |
|---|
| 177 | |
|---|
| 178 | $getArray = $th_save_db->lfb_get_all_view_leads_db($form_id, $start); |
|---|
| 179 | $posts = $getArray['posts']; |
|---|
| 180 | $rows = $getArray['rows']; |
|---|
| 181 | $limit = $getArray['limit']; |
|---|
| 182 | $fieldData = $getArray['fieldId']; |
|---|
| 183 | $tableHead = ''; |
|---|
| 184 | $headcount = 1; |
|---|
| 185 | $leadscount = 5; |
|---|
| 186 | |
|---|
| 187 | foreach ($fieldData as $fieldkey => $fieldvalue) { |
|---|
| 188 | // Html Field removed |
|---|
| 189 | $pos = strpos($fieldkey, 'htmlfield_'); |
|---|
| 190 | if ($pos !== false) { |
|---|
| 191 | continue; |
|---|
| 192 | } |
|---|
| 193 | |
|---|
| 194 | if ($headcount < 6 && $slectleads) { |
|---|
| 195 | $tableHead .= '<th>' . $fieldvalue . '</th>'; |
|---|
| 196 | } elseif (!$slectleads) { |
|---|
| 197 | |
|---|
| 198 | $tableHead .= '<th>' . $fieldvalue . '</th>'; |
|---|
| 199 | |
|---|
| 200 | $leadscount = $headcount; |
|---|
| 201 | } |
|---|
| 202 | $fieldIdNew[] = $fieldkey; |
|---|
| 203 | $headcount++; |
|---|
| 204 | |
|---|
| 205 | // } else{ break; } |
|---|
| 206 | } |
|---|
| 207 | |
|---|
| 208 | if (!empty($posts)) { |
|---|
| 209 | $entry_counter = 0; |
|---|
| 210 | $table_body = ''; |
|---|
| 211 | $table_head = ''; |
|---|
| 212 | $popupTab = ''; |
|---|
| 213 | |
|---|
| 214 | if ($headcount >= 6 && $leadscount == 5) { |
|---|
| 215 | $table_head .= '<th></th><th> . . . </th><th><input type="button" onclick="show_all_leads(' . intval($id) . ',' . intval($form_id) . ')" value="Show all Columns"></th>'; |
|---|
| 216 | } |
|---|
| 217 | |
|---|
| 218 | foreach ($posts as $results) { |
|---|
| 219 | $table_row = ''; |
|---|
| 220 | // $table_head = ''; |
|---|
| 221 | $sn_counter++; |
|---|
| 222 | $row_size_limit = 0; |
|---|
| 223 | $form_data = $results->form_data; |
|---|
| 224 | $lead_id = $results->id; |
|---|
| 225 | $lead_date = date("jS F Y", strtotime($results->date)); |
|---|
| 226 | $form_data = maybe_unserialize($form_data); |
|---|
| 227 | unset($form_data['hidden_field']); |
|---|
| 228 | unset($form_data['action']); |
|---|
| 229 | $entry_counter++; |
|---|
| 230 | $complete_data = ''; |
|---|
| 231 | $popup_data_val = ''; |
|---|
| 232 | $date_td = '<td><b>' . $lead_date . '</b></td>'; |
|---|
| 233 | |
|---|
| 234 | |
|---|
| 235 | $returnData = $th_save_db->lfb_lead_form_value($form_data, $fieldIdNew, $fieldData, $leadscount); |
|---|
| 236 | $table_row .= $returnData['table_row']; |
|---|
| 237 | $table_row .= $date_td; |
|---|
| 238 | |
|---|
| 239 | foreach ($form_data as $form_data_key => $form_data_value) { |
|---|
| 240 | $row_size_limit++; |
|---|
| 241 | |
|---|
| 242 | if (($detail_view != 1) && ($row_size_limit == 6) && $leadscount == 5) { |
|---|
| 243 | $table_row .= '<td>. . .</td><td><a href="#lf-openModal-' . $lead_id . '" value="view">view</a></td>'; |
|---|
| 244 | } |
|---|
| 245 | } |
|---|
| 246 | |
|---|
| 247 | $complete_data .= "<table><tr><th>Field</th><th>Value</th></tr>" . $returnData['table_popup'] . "</table>"; |
|---|
| 248 | |
|---|
| 249 | /****/ |
|---|
| 250 | $popupTab .= '<div id="lf-openModal-' . $lead_id . '" class="lf-modalDialog"> |
|---|
| 251 | <div class="lfb-popup-leads" ><a href="#lf-close" title="Close" class="lf-close">X</a>' . $complete_data . ' |
|---|
| 252 | </div> |
|---|
| 253 | </div>'; |
|---|
| 254 | |
|---|
| 255 | // $complete_data .=$returnData['table_popup']."</table>"; |
|---|
| 256 | |
|---|
| 257 | $table_body .= '<tbody id="lead-id-' . $lead_id . '">'; |
|---|
| 258 | |
|---|
| 259 | $table_body .= '<tr><td><span class="lead-count">' . $sn_counter . '</span><a class="lead-remove" onclick="delete_this_lead(' . $lead_id . ',\'' . $nonce . '\')" ><i class="fa fa-trash" aria-hidden="true"></i></a></td>' . $table_row . '</tr>'; |
|---|
| 260 | } |
|---|
| 261 | |
|---|
| 262 | $thHead = '<div class="wrap" id="form-leads-show"><table class="show-leads-table wp-list-table widefat fixed" id="show-leads-table" ><thead><tr><th>Action</th>' . $tableHead . '<th>Date</th>' . $table_head . '</tr></thead>'; |
|---|
| 263 | |
|---|
| 264 | echo wp_kses($thHead . $table_body . '</tbody></table>' . $popupTab, $showLeadsObj->expanded_alowed_tags()); |
|---|
| 265 | |
|---|
| 266 | $total = ceil($rows / $limit); |
|---|
| 267 | if ($headcount >= 6 && $leadscount == 5) { |
|---|
| 268 | |
|---|
| 269 | if ($id > 1) { |
|---|
| 270 | echo "<a href='' onclick='lead_pagi_view(" . intval($id - 1) . "," . intval($form_id) . ")' class='button'><i class='fa fa-chevron-right'></i></a>"; |
|---|
| 271 | } |
|---|
| 272 | if ($id != $total) { |
|---|
| 273 | echo "<a href='' onclick='lead_pagi_view(" . intval($id + 1) . "," . intval($form_id) . ")' class='button'><i class='fa fa-chevron-left'></i></a>"; |
|---|
| 274 | } |
|---|
| 275 | echo "<ul class='page'>"; |
|---|
| 276 | for ($i = 1; $i <= $total; $i++) { |
|---|
| 277 | if ($i == $id) { |
|---|
| 278 | echo "<li class='lf-current'><a href='#'>" . intval($i) . "</a></li>"; |
|---|
| 279 | } else { |
|---|
| 280 | echo "<li><a href='' onclick='lead_pagi_view(" . intval($i) . "," . intval($form_id) . ")'>" . intval($i) . "</a></li>"; |
|---|
| 281 | } |
|---|
| 282 | } |
|---|
| 283 | echo '</ul>'; |
|---|
| 284 | } else { |
|---|
| 285 | |
|---|
| 286 | if ($id > 1) { |
|---|
| 287 | echo "<a href='' onclick='lead_pagination(" . intval($id - 1) . "," . intval($form_id) . ")' class='button'><i class='fa fa-chevron-right'></i></a>"; |
|---|
| 288 | } |
|---|
| 289 | if ($id != $total) { |
|---|
| 290 | echo "<a href='' onclick='lead_pagination(" . intval($id + 1) . "," . intval($form_id) . ")' class='button'><i class='fa fa-chevron-left'></i></a>"; |
|---|
| 291 | } |
|---|
| 292 | echo "<ul class='page'>"; |
|---|
| 293 | for ($i = 1; $i <= $total; $i++) { |
|---|
| 294 | if ($i == $id) { |
|---|
| 295 | echo "<li class='lf-current'><a href='#'>" . intval($i) . "</a></li>"; |
|---|
| 296 | } else { |
|---|
| 297 | echo "<li><a href='' onclick='lead_pagination(" . intval($i) . "," . intval($form_id) . ")'>" . intval($i) . "</a></li>"; |
|---|
| 298 | } |
|---|
| 299 | } |
|---|
| 300 | echo '</ul>'; |
|---|
| 301 | } |
|---|
| 302 | } else { |
|---|
| 303 | esc_html_e('Opps No lead...!!', 'lead-form-builder'); |
|---|
| 304 | } |
|---|
| 305 | die(); |
|---|
| 306 | } |
|---|
| 307 | } |
|---|
| 308 | |
|---|
| 309 | add_action('wp_ajax_ShowAllLeadThisForm', 'lfb_ShowAllLeadThisForm'); |
|---|
| 310 | |
|---|
| 311 | |
|---|
| 312 | |
|---|
| 313 | function lfb_ShowLeadPagi() |
|---|
| 314 | { |
|---|
| 315 | if ((isset($_POST['form_id']) && ($_POST['form_id'] != '')) || (isset($_GET['form_id']) && ($_GET['form_id'] != ''))) { |
|---|
| 316 | global $wpdb; |
|---|
| 317 | $table_name = LFB_FORM_DATA_TBL; |
|---|
| 318 | $th_save_db = new LFB_SAVE_DB($wpdb); |
|---|
| 319 | $showLeadsObj = new LFB_Show_Leads(); |
|---|
| 320 | $nonce = wp_create_nonce('lfb-nonce-rm'); |
|---|
| 321 | $start = 0; |
|---|
| 322 | $limit = 10; |
|---|
| 323 | $detail_view = ''; |
|---|
| 324 | |
|---|
| 325 | if (isset($_GET['id'])) { |
|---|
| 326 | $id = intval($_GET['id']); |
|---|
| 327 | $start = ($id - 1) * $limit; |
|---|
| 328 | $form_id = intval($_GET['form_id']); |
|---|
| 329 | $sn_counter = $start; |
|---|
| 330 | } else { |
|---|
| 331 | $id = 1; |
|---|
| 332 | $form_id = intval($_POST['form_id']); |
|---|
| 333 | $sn_counter = 0; |
|---|
| 334 | } |
|---|
| 335 | if (isset($_GET['detailview'])) { |
|---|
| 336 | $detail_view = isset($_GET['detailview']); |
|---|
| 337 | } |
|---|
| 338 | |
|---|
| 339 | $getArray = $th_save_db->lfb_get_all_view_leads_db($form_id, $start); |
|---|
| 340 | $posts = $getArray['posts']; |
|---|
| 341 | $rows = $getArray['rows']; |
|---|
| 342 | $limit = $getArray['limit']; |
|---|
| 343 | $fieldData = $getArray['fieldId']; |
|---|
| 344 | $tableHead = ''; |
|---|
| 345 | $headcount = 1; |
|---|
| 346 | |
|---|
| 347 | foreach ($fieldData as $fieldkey => $fieldvalue) { |
|---|
| 348 | if ($headcount < 6) { |
|---|
| 349 | $tableHead .= '<th>' . $fieldvalue . '</th>'; |
|---|
| 350 | } |
|---|
| 351 | $fieldIdNew[] = $fieldkey; |
|---|
| 352 | // } else{ break; } |
|---|
| 353 | $headcount++; |
|---|
| 354 | } |
|---|
| 355 | if (!empty($posts)) { |
|---|
| 356 | $entry_counter = 0; |
|---|
| 357 | $table_body = ''; |
|---|
| 358 | $table_head = ''; |
|---|
| 359 | $popupTab = ''; |
|---|
| 360 | |
|---|
| 361 | if ($headcount >= 6) { |
|---|
| 362 | $table_head .= '<th> . . . </th><th><input type="button" onclick="show_all_leads(' . $id . ',' . $form_id . ')" value="Show all Columns"></th>'; |
|---|
| 363 | } |
|---|
| 364 | |
|---|
| 365 | foreach ($posts as $results) { |
|---|
| 366 | $table_row = ''; |
|---|
| 367 | $sn_counter++; |
|---|
| 368 | $row_size_limit = 0; |
|---|
| 369 | $form_data = $results->form_data; |
|---|
| 370 | $lead_id = $results->id; |
|---|
| 371 | $form_data = maybe_unserialize($form_data); |
|---|
| 372 | unset($form_data['hidden_field']); |
|---|
| 373 | unset($form_data['action']); |
|---|
| 374 | $entry_counter++; |
|---|
| 375 | $complete_data = ''; |
|---|
| 376 | $popup_data_val = ''; |
|---|
| 377 | |
|---|
| 378 | $returnData = $th_save_db->lfb_lead_form_value($form_data, $fieldIdNew, $fieldData, 5); |
|---|
| 379 | $table_row .= $returnData['table_row']; |
|---|
| 380 | |
|---|
| 381 | foreach ($form_data as $form_data_key => $form_data_value) { |
|---|
| 382 | $row_size_limit++; |
|---|
| 383 | |
|---|
| 384 | if (($detail_view != 1) && ($row_size_limit == 6)) { |
|---|
| 385 | $table_row .= '<td>. . .</td><td><a href="#lf-openModal-' . $lead_id . '" value="view">view</a></td>'; |
|---|
| 386 | } |
|---|
| 387 | } |
|---|
| 388 | |
|---|
| 389 | $complete_data .= "<table><tr><th>Field</th><th>Value</th></tr>" . $returnData['table_popup'] . "</table>"; |
|---|
| 390 | |
|---|
| 391 | /****/ |
|---|
| 392 | $popupTab .= '<div id="lf-openModal-' . $lead_id . '" class="lf-modalDialog"> |
|---|
| 393 | <div class="lfb-popup-leads" ><a href="#lf-close" title="Close" class="lf-close">X</a>' . $complete_data . ' |
|---|
| 394 | </div> |
|---|
| 395 | </div>'; |
|---|
| 396 | /****/ |
|---|
| 397 | $table_body .= '<tbody id="lead-id-' . $lead_id . '">'; |
|---|
| 398 | |
|---|
| 399 | $table_body .= '<tr><td><span class="lead-count">' . $sn_counter . '</span><a class="lead-remove" onclick="delete_this_lead(' . $lead_id . ',\'' . $nonce . '\')" ><i class="fa fa-trash" aria-hidden="true"></i></a></td>' . $table_row . '</tr>'; |
|---|
| 400 | } |
|---|
| 401 | |
|---|
| 402 | $thHead = '<div class="wrap" id="form-leads-show"><table class="show-leads-table wp-list-table widefat fixed" id="show-leads-table" ><thead><tr><th>Action</th>' . $tableHead . $table_head . '</tr></thead>'; |
|---|
| 403 | |
|---|
| 404 | echo wp_kses($thHead . $table_body . '</tbody></table>' . $popupTab, $showLeadsObj->expanded_alowed_tags()); |
|---|
| 405 | |
|---|
| 406 | $total = ceil($rows / $limit); |
|---|
| 407 | if ($id > 1) { |
|---|
| 408 | echo "<a href='' onclick='lead_pagi_view(" . intval($id - 1) . "," . intval($form_id) . ")' class='button'><i class='fa fa-chevron-right'></i></a>"; |
|---|
| 409 | } |
|---|
| 410 | if ($id != $total) { |
|---|
| 411 | echo "<a href='' onclick='lead_pagi_view(" . intval($id + 1) . "," . intval($form_id) . ")' class='button'><i class='fa fa-chevron-left'></i></a>"; |
|---|
| 412 | } |
|---|
| 413 | echo "<ul class='page'>"; |
|---|
| 414 | for ($i = 1; $i <= $total; $i++) { |
|---|
| 415 | if ($i == $id) { |
|---|
| 416 | echo "<li class='lf-current'><a href='#'>" . intval($i) . "</a></li>"; |
|---|
| 417 | } else { |
|---|
| 418 | echo "<li><a href='' onclick='lead_pagi_view(" . intval($i) . "," . intval($form_id) . ")'>" . intval($i) . "</a></li>"; |
|---|
| 419 | } |
|---|
| 420 | } |
|---|
| 421 | echo '</ul>'; |
|---|
| 422 | } else { |
|---|
| 423 | esc_html_e('Opps No lead...!!', 'lead-form-builder'); |
|---|
| 424 | } |
|---|
| 425 | die(); |
|---|
| 426 | } |
|---|
| 427 | } |
|---|
| 428 | add_action('wp_ajax_ShowLeadPagi', 'lfb_ShowLeadPagi'); |
|---|
| 429 | |
|---|
| 430 | /* |
|---|
| 431 | * Show Leads on Lead Page Based on form selection |
|---|
| 432 | */ |
|---|
| 433 | |
|---|
| 434 | function lfb_ShowAllLeadThisFormDate() |
|---|
| 435 | { |
|---|
| 436 | if ((isset($_POST['form_id']) && ($_POST['form_id'] != '')) || (isset($_GET['form_id']) && ($_GET['form_id'] != ''))) { |
|---|
| 437 | global $wpdb; |
|---|
| 438 | $nonce = wp_create_nonce('lfb-nonce-rm'); |
|---|
| 439 | $table_name = LFB_FORM_DATA_TBL; |
|---|
| 440 | $th_save_db = new LFB_SAVE_DB($wpdb); |
|---|
| 441 | $showLeadsObj = new LFB_Show_Leads(); |
|---|
| 442 | $start = 0; |
|---|
| 443 | $limit = 10; |
|---|
| 444 | $detail_view = ''; |
|---|
| 445 | |
|---|
| 446 | if (isset($_GET['id'])) { |
|---|
| 447 | $id = intval($_GET['id']); |
|---|
| 448 | $datewise = sanitize_text_field($_GET['datewise']); |
|---|
| 449 | $start = ($id - 1) * $limit; |
|---|
| 450 | $form_id = intval($_GET['form_id']); |
|---|
| 451 | $sn_counter = $start; |
|---|
| 452 | } else { |
|---|
| 453 | $id = 1; |
|---|
| 454 | $datewise = ''; |
|---|
| 455 | $sn_counter = 0; |
|---|
| 456 | } |
|---|
| 457 | if (isset($_GET['detailview'])) { |
|---|
| 458 | $detail_view = sanitize_text_field($_GET['detailview']); |
|---|
| 459 | } |
|---|
| 460 | $getArray = $th_save_db->lfb_get_all_view_date_leads_db($form_id, $datewise, $start); |
|---|
| 461 | |
|---|
| 462 | $posts = $getArray['posts']; |
|---|
| 463 | $rows = $getArray['rows']; |
|---|
| 464 | $limit = $getArray['limit']; |
|---|
| 465 | $fieldData = $getArray['fieldId']; |
|---|
| 466 | $fieldIdNew = array(); |
|---|
| 467 | $headcount = 1; |
|---|
| 468 | |
|---|
| 469 | $tableHead = ''; |
|---|
| 470 | |
|---|
| 471 | |
|---|
| 472 | foreach ($fieldData as $fieldkey => $fieldvalue) { |
|---|
| 473 | if ($headcount < 6) { |
|---|
| 474 | $tableHead .= '<th>' . $fieldvalue . '</th>'; |
|---|
| 475 | } |
|---|
| 476 | $fieldIdNew[] = $fieldkey; |
|---|
| 477 | // } else{ break; } |
|---|
| 478 | $headcount++; |
|---|
| 479 | } |
|---|
| 480 | |
|---|
| 481 | if (!empty($posts)) { |
|---|
| 482 | $entry_counter = 0; |
|---|
| 483 | $value1 = 0; |
|---|
| 484 | $table_body = ''; |
|---|
| 485 | $table_head = ''; |
|---|
| 486 | $popupTab = ''; |
|---|
| 487 | |
|---|
| 488 | |
|---|
| 489 | if ($headcount >= 6) { |
|---|
| 490 | $table_head .= '<th><input type="button" onclick="show_all_leads(' . $id . ',' . $form_id . ')" value="Show all fields"></th>'; |
|---|
| 491 | } |
|---|
| 492 | |
|---|
| 493 | foreach ($posts as $results) { |
|---|
| 494 | $table_row = ''; |
|---|
| 495 | $sn_counter++; |
|---|
| 496 | $row_size_limit = 0; |
|---|
| 497 | $form_data = $results->form_data; |
|---|
| 498 | $lead_id = $results->id; |
|---|
| 499 | $form_data = maybe_unserialize($form_data); |
|---|
| 500 | unset($form_data['hidden_field']); |
|---|
| 501 | unset($form_data['action']); |
|---|
| 502 | $entry_counter++; |
|---|
| 503 | $complete_data = ''; |
|---|
| 504 | $popup_data_val = ''; |
|---|
| 505 | |
|---|
| 506 | $returnData = $th_save_db->lfb_lead_form_value($form_data, $fieldIdNew, $fieldData, 5); |
|---|
| 507 | $table_row .= $returnData['table_row']; |
|---|
| 508 | |
|---|
| 509 | |
|---|
| 510 | |
|---|
| 511 | foreach ($form_data as $form_data_key => $form_data_value) { |
|---|
| 512 | $row_size_limit++; |
|---|
| 513 | |
|---|
| 514 | if (($detail_view != 1) && ($row_size_limit == 6)) { |
|---|
| 515 | $table_row .= '<td>. . . . .</td><td><a href="#lf-openModal-' . $lead_id . '" value="view">view</a></td>'; |
|---|
| 516 | } |
|---|
| 517 | } |
|---|
| 518 | |
|---|
| 519 | $complete_data .= "<table><tr><th>Field</th><th>Value</th></tr>" . $returnData['table_popup'] . "</table>"; |
|---|
| 520 | |
|---|
| 521 | /****/ |
|---|
| 522 | $popupTab .= '<div id="lf-openModal-' . $lead_id . '" class="lf-modalDialog"> |
|---|
| 523 | <div class="lfb-popup-leads" ><a href="#lf-close" title="Close" class="lf-close">X</a>' . $complete_data . ' |
|---|
| 524 | </div> |
|---|
| 525 | </div>'; |
|---|
| 526 | /****/ |
|---|
| 527 | $table_body .= '<tbody id="lead-id-' . $lead_id . '">'; |
|---|
| 528 | |
|---|
| 529 | $table_body .= '<tr><td><span class="lead-count">' . $sn_counter . '</span><a class="lead-remove" onclick="delete_this_lead(' . $lead_id . ',\'' . $nonce . '\')" ><i class="fa fa-trash" aria-hidden="true"></i></a></td>' . $table_row . '</tr>'; |
|---|
| 530 | } |
|---|
| 531 | |
|---|
| 532 | $thHead = '<div class="wrap" id="form-leads-show"><table class="show-leads-table wp-list-table widefat fixed" id="show-leads-table" ><thead><tr><th>Action</th>' . $tableHead . $table_head . '</tr></thead>'; |
|---|
| 533 | |
|---|
| 534 | echo wp_kses($thHead . $table_body . '</tbody></table>' . $popupTab, $showLeadsObj->expanded_alowed_tags()); |
|---|
| 535 | |
|---|
| 536 | $rows = count($rows); |
|---|
| 537 | $total = ceil($rows / $limit); |
|---|
| 538 | if ($id > 1) { |
|---|
| 539 | echo "<a href='' onclick='lead_pagination_datewise(" . intval($id - 1) . "," . intval($form_id) . ",\"" . $datewise . "\");' class='button'><i class='fa fa-chevron-right'></i></a>"; |
|---|
| 540 | } |
|---|
| 541 | if ($id != $total) { |
|---|
| 542 | echo "<a href='' onclick='lead_pagination_datewise(" . intval($id + 1) . "," . intval($form_id) . ",\"" . $datewise . "\");' class='button'><i class='fa fa-chevron-left'></i></a>"; |
|---|
| 543 | } |
|---|
| 544 | echo "<ul class='page'>"; |
|---|
| 545 | for ($i = 1; $i <= $total; $i++) { |
|---|
| 546 | if ($i == $id) { |
|---|
| 547 | echo "<li class='lf-current'><a>" . intval($i) . "</a></li>"; |
|---|
| 548 | } else { |
|---|
| 549 | echo "<li><a href='' onclick='lead_pagination_datewise(" . intval($i) . "," . intval($form_id) . ",\"" . $datewise . "\");'>" . intval($i) . "</a></li>"; |
|---|
| 550 | } |
|---|
| 551 | } |
|---|
| 552 | echo '</ul>'; |
|---|
| 553 | } else { |
|---|
| 554 | esc_html_e('Opps No lead...!!', 'lead-form-builder'); |
|---|
| 555 | } |
|---|
| 556 | die(); |
|---|
| 557 | } |
|---|
| 558 | } |
|---|
| 559 | add_action('wp_ajax_ShowAllLeadThisFormDate', 'lfb_ShowAllLeadThisFormDate'); |
|---|
| 560 | |
|---|
| 561 | /* |
|---|
| 562 | * Save from Data from front-end |
|---|
| 563 | */ |
|---|
| 564 | |
|---|
| 565 | function lfb_form_name_email_filter($form_data) |
|---|
| 566 | { |
|---|
| 567 | $name_email = array(); |
|---|
| 568 | $e = false; |
|---|
| 569 | $n = false; |
|---|
| 570 | foreach ($form_data as $key => $value) { |
|---|
| 571 | $email = strpos($key, 'email_'); |
|---|
| 572 | $name = strpos($key, 'name_'); |
|---|
| 573 | if ($email !== false) { |
|---|
| 574 | $name_email['email'] = $value; |
|---|
| 575 | $e = true; |
|---|
| 576 | } elseif ($name !== false) { |
|---|
| 577 | $name_email['name'] = $value; |
|---|
| 578 | $n = true; |
|---|
| 579 | } |
|---|
| 580 | if ($e === true && $n === true) { |
|---|
| 581 | break; |
|---|
| 582 | } |
|---|
| 583 | } |
|---|
| 584 | return $name_email; |
|---|
| 585 | } |
|---|
| 586 | |
|---|
| 587 | function lfb_lead_sanitize($leads) |
|---|
| 588 | { |
|---|
| 589 | if (is_array($leads)) { |
|---|
| 590 | foreach ($leads as $key => $value) { |
|---|
| 591 | $rKey = preg_replace("/[^a-zA-Z]+/", "", $key); |
|---|
| 592 | if ($rKey === 'name' || $rKey === 'text' || $rKey === 'radio' || $rKey === 'option') { |
|---|
| 593 | $leads[$key] = sanitize_text_field($value); |
|---|
| 594 | } elseif ($rKey === 'email') { |
|---|
| 595 | $leads[$key] = sanitize_email($value); |
|---|
| 596 | } elseif ($rKey === 'number') { |
|---|
| 597 | $leads[$key] = intval($value); |
|---|
| 598 | } elseif ($rKey === 'message' || $rKey === 'textarea') { |
|---|
| 599 | $leads[$key] = sanitize_textarea_field($value); |
|---|
| 600 | } elseif ($rKey === 'date' || $rKey === 'dob') { |
|---|
| 601 | $leads[$key] = sanitize_text_field($value); |
|---|
| 602 | } elseif ($rKey === 'url') { |
|---|
| 603 | $leads[$key] = esc_url_raw($value); |
|---|
| 604 | } elseif ($rKey === 'checkbox') { |
|---|
| 605 | |
|---|
| 606 | foreach ($value as $ckey => $cvalue) { |
|---|
| 607 | $value[$ckey] = sanitize_text_field($cvalue); |
|---|
| 608 | } |
|---|
| 609 | $leads[$key] = $value; |
|---|
| 610 | } |
|---|
| 611 | } // end foreach |
|---|
| 612 | |
|---|
| 613 | return $leads; |
|---|
| 614 | } |
|---|
| 615 | } |
|---|
| 616 | |
|---|
| 617 | function lfb_Save_Form_Data() |
|---|
| 618 | { |
|---|
| 619 | |
|---|
| 620 | if (isset($_POST['fdata']) && wp_verify_nonce($_POST['_wpnonce'], 'lfb_front_nonce' )) { |
|---|
| 621 | wp_parse_str($_POST['fdata'], $fromData); |
|---|
| 622 | |
|---|
| 623 | $form_id = intval($fromData['hidden_field']); |
|---|
| 624 | unset($fromData['g-recaptcha-response']); |
|---|
| 625 | unset($fromData['action']); |
|---|
| 626 | unset($fromData['hidden_field']); |
|---|
| 627 | |
|---|
| 628 | $en = lfb_form_name_email_filter($fromData); |
|---|
| 629 | |
|---|
| 630 | |
|---|
| 631 | if ((isset($en['email'])) && ($en['email'] != '')) { |
|---|
| 632 | $user_emailid = sanitize_email($en['email']); |
|---|
| 633 | } else { |
|---|
| 634 | $user_emailid = esc_html__('invalid_email', 'lead-form-builder'); |
|---|
| 635 | } |
|---|
| 636 | $sanitize_leads = lfb_lead_sanitize($fromData); |
|---|
| 637 | $form_data = maybe_serialize($sanitize_leads); |
|---|
| 638 | |
|---|
| 639 | $lf_store = new LFB_LeadStoreType(); |
|---|
| 640 | $th_save_db = new LFB_SAVE_DB(); |
|---|
| 641 | |
|---|
| 642 | $lf_store->lfb_mail_type($form_id, $form_data, $th_save_db, $user_emailid); |
|---|
| 643 | }else{ |
|---|
| 644 | echo esc_html__('INVAILD','lead-form-builder'); |
|---|
| 645 | } |
|---|
| 646 | die(); |
|---|
| 647 | } |
|---|
| 648 | |
|---|
| 649 | add_action('wp_ajax_Save_Form_Data', 'lfb_Save_Form_Data'); |
|---|
| 650 | add_action('wp_ajax_nopriv_Save_Form_Data', 'lfb_Save_Form_Data'); |
|---|
| 651 | |
|---|
| 652 | function lfb_verifyFormCaptcha() |
|---|
| 653 | { |
|---|
| 654 | if ((isset($_POST['captcha_res'])) && (!empty($_POST['captcha_res']))) { |
|---|
| 655 | $captcha = stripslashes($_POST['captcha_res']); |
|---|
| 656 | $secret_key = get_option('captcha-setting-secret'); |
|---|
| 657 | $response = wp_remote_post( |
|---|
| 658 | 'https://www.google.com/recaptcha/api/siteverify', |
|---|
| 659 | array( |
|---|
| 660 | 'method' => 'POST', |
|---|
| 661 | 'body' => array( |
|---|
| 662 | 'secret' => $secret_key, |
|---|
| 663 | 'response' => $captcha |
|---|
| 664 | ) |
|---|
| 665 | ) |
|---|
| 666 | ); |
|---|
| 667 | $reply_obj = json_decode(wp_remote_retrieve_body($response)); |
|---|
| 668 | if (isset($reply_obj->success) && $reply_obj->success == 1) { |
|---|
| 669 | esc_html_e('Yes', 'lead-form-builder'); |
|---|
| 670 | } else { |
|---|
| 671 | esc_html_e('No', 'lead-form-builder'); |
|---|
| 672 | } |
|---|
| 673 | } else { |
|---|
| 674 | esc_html_e('Invalid', 'lead-form-builder'); |
|---|
| 675 | } |
|---|
| 676 | die(); |
|---|
| 677 | } |
|---|
| 678 | add_action('wp_ajax_verifyFormCaptcha', 'lfb_verifyFormCaptcha'); |
|---|
| 679 | add_action('wp_ajax_nopriv_verifyFormCaptcha', 'lfb_verifyFormCaptcha'); |
|---|
| 680 | |
|---|
| 681 | function lfb_RememberMeThisForm() |
|---|
| 682 | { |
|---|
| 683 | $nonce = $_POST['rem_nonce']; |
|---|
| 684 | |
|---|
| 685 | if (isset($_POST['form_id']) && current_user_can('manage_options') && wp_verify_nonce($nonce, 'rem-nonce')) { |
|---|
| 686 | |
|---|
| 687 | $remember_me = intval($_POST['form_id']); |
|---|
| 688 | if (get_option('lf-remember-me-show-lead') !== false) { |
|---|
| 689 | update_option('lf-remember-me-show-lead', $remember_me); |
|---|
| 690 | } else { |
|---|
| 691 | add_option('lf-remember-me-show-lead', $remember_me); |
|---|
| 692 | } |
|---|
| 693 | echo esc_html(get_option('lf-remember-me-show-lead')); |
|---|
| 694 | die(); |
|---|
| 695 | } |
|---|
| 696 | } |
|---|
| 697 | add_action('wp_ajax_RememberMeThisForm', 'lfb_RememberMeThisForm'); |
|---|
| 698 | |
|---|
| 699 | |
|---|
| 700 | /* |
|---|
| 701 | * Save Email Settings |
|---|
| 702 | */ |
|---|
| 703 | |
|---|
| 704 | |
|---|
| 705 | |
|---|
| 706 | function lfb_emailsettings_sanitize($email_settings) |
|---|
| 707 | { |
|---|
| 708 | |
|---|
| 709 | $email_settings['from'] = sanitize_email($email_settings['from']); |
|---|
| 710 | $email_settings['header'] = sanitize_text_field($email_settings['header']); |
|---|
| 711 | $email_settings['subject'] = sanitize_text_field($email_settings['subject']); |
|---|
| 712 | $email_settings['message'] = sanitize_textarea_field($email_settings['message']); |
|---|
| 713 | $email_settings['user-email-setting-option'] = sanitize_text_field($email_settings['user-email-setting-option']); |
|---|
| 714 | $email_settings['form-id'] = intval($email_settings['form-id']); |
|---|
| 715 | return $email_settings; |
|---|
| 716 | } |
|---|
| 717 | |
|---|
| 718 | function lfb_SaveUserEmailSettings() |
|---|
| 719 | { |
|---|
| 720 | unset($_POST['action']); |
|---|
| 721 | $mailArr = array(); |
|---|
| 722 | |
|---|
| 723 | $nonce = $_REQUEST['ues_nonce']; |
|---|
| 724 | // Get all the user roles as an array. |
|---|
| 725 | if (isset($_POST['user_email_setting']) && current_user_can('manage_options') && wp_verify_nonce($nonce, 'ues-nonce')) { |
|---|
| 726 | |
|---|
| 727 | $mailArr['user_email_setting'] = lfb_emailsettings_sanitize($_POST['user_email_setting']); |
|---|
| 728 | |
|---|
| 729 | $email_setting = maybe_serialize($mailArr); |
|---|
| 730 | $this_form_id = intval($_POST['user_email_setting']['form-id']); |
|---|
| 731 | global $wpdb; |
|---|
| 732 | $table_name = LFB_FORM_FIELD_TBL; |
|---|
| 733 | $update_query = "update " . LFB_FORM_FIELD_TBL . " set usermail_setting='" . $email_setting . "' where id='" . $this_form_id . "'"; |
|---|
| 734 | $th_save_db = new LFB_SAVE_DB($wpdb); |
|---|
| 735 | $update_leads = $th_save_db->lfb_update_form_data($update_query); |
|---|
| 736 | if ($update_leads) { |
|---|
| 737 | echo esc_html("updated"); |
|---|
| 738 | } |
|---|
| 739 | } |
|---|
| 740 | die(); |
|---|
| 741 | } |
|---|
| 742 | add_action('wp_ajax_SaveUserEmailSettings', 'lfb_SaveUserEmailSettings'); |
|---|