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: 470: 471: 472: 473: 474: 475: 476: 477: 478: 479: 480: 481: 482: 483: 484: 485: 486: 487: 488: 489: 490: 491: 492: 493: 494: 495: 496: 497: 498: 499: 500: 501: 502: 503: 504: 505: 506: 507: 508: 509: 510: 511: 512: 513: 514: 515: 516: 517: 518: 519: 520: 521: 522: 523: 524: 525: 526: 527: 528: 529: 530: 531: 532: 533: 534: 535: 536: 537: 538: 539: 540: 541: 542: 543: 544: 545: 546: 547: 548: 549: 550: 551: 552: 553: 554: 555: 556: 557: 558: 559: 560: 561: 562: 563: 564: 565: 566: 567: 568: 569: 570: 571: 572: 573: 574: 575: 576: 577: 578: 579: 580: 581: 582: 583: 584: 585: 586: 587: 588: 589: 590: 591: 592: 593: 594: 595: 596: 597: 598: 599: 600: 601: 602: 603: 604: 605: 606: 607: 608: 609: 610: 611: 612: 613: 614: 615: 616: 617: 618: 619: 620: 621: 622: 623: 624: 625: 626: 627: 628: 629: 630: 631: 632: 633: 634: 635: 636: 637: 638: 639: 640: 641: 642: 643: 644: 645: 646: 647: 648: 649: 650: 651: 652: 653: 654: 655: 656: 657: 658: 659: 660: 661: 662: 663: 664: 665: 666: 667: 668: 669: 670: 671: 672: 673: 674: 675: 676: 677: 678: 679: 680: 681: 682: 683: 684: 685: 686: 687: 688: 689: 690: 691: 692: 693: 694: 695: 696: 697: 698: 699: 700: 701: 702: 703: 704: 705: 706: 707: 708: 709: 710: 711: 712: 713: 714: 715: 716: 717: 718: 719: 720: 721: 722: 723: 724: 725: 726: 727: 728: 729: 730: 731: 732: 733: 734: 735: 736: 737: 738: 739: 740: 741: 742: 743: 744: 745: 746: 747: 748: 749: 750: 751: 752: 753: 754: 755: 756: 757: 758: 759: 760: 761: 762: 763: 764: 765: 766: 767: 768: 769: 770: 771: 772: 773: 774: 775: 776: 777: 778: 779: 780: 781: 782: 783: 784: 785: 786: 787: 788: 789: 790: 791: 792: 793: 794: 795: 796: 797: 798: 799: 800: 801: 802: 803: 804: 805: 806: 807: 808: 809: 810: 811: 812: 813: 814: 815: 816: 817: 818: 819: 820: 821: 822: 823: 824: 825: 826: 827: 828: 829: 830: 831: 832: 833: 834: 835: 836: 837: 838: 839: 840: 841: 842: 843: 844: 845: 846: 847: 848: 849: 850: 851: 852: 853: 854: 855: 856: 857: 858: 859: 860: 861: 862: 863: 864: 865: 866: 867: 868: 869: 870: 871: 872: 873: 874: 875: 876: 877: 878: 879: 880: 881: 882: 883: 884: 885: 886: 887: 888: 889: 890: 891: 892: 893: 894: 895: 896: 897: 898: 899: 900: 901: 902: 903: 904: 905: 906: 907: 908: 909: 910: 911: 912: 913: 914: 915: 916: 917: 918: 919: 920: 921: 922: 923: 924: 925: 926: 927: 928: 929: 930: 931: 932: 933: 934: 935: 936: 937: 938: 939: 940: 941: 942: 943: 944: 945: 946: 947: 948: 949: 950: 951: 952: 953: 954: 955: 956: 957: 958: 959: 960: 961: 962: 963: 964: 965: 966: 967: 968: 969: 970: 971: 972: 973: 974: 975: 976: 977: 978: 979: 980: 981: 982: 983: 984: 985: 986: 987: 988: 989: 990: 991: 992: 993: 994: 995: 996: 997: 998: 999: 1000: 1001: 1002: 1003: 1004: 1005: 1006: 1007: 1008: 1009: 1010: 1011: 1012: 1013: 1014: 1015: 1016: 1017: 1018: 1019: 1020: 1021: 1022: 1023: 1024: 1025: 1026: 1027: 1028: 1029: 1030: 1031: 1032: 1033: 1034: 1035: 1036: 1037: 1038: 1039: 1040: 1041: 1042: 1043: 1044: 1045: 1046: 1047: 1048: 1049: 1050: 1051: 1052: 1053: 1054: 1055: 1056: 1057: 1058: 1059: 1060: 1061: 1062: 1063: 1064: 1065: 1066: 1067: 1068: 1069: 1070: 1071: 1072: 1073: 1074: 1075: 1076: 1077: 1078: 1079: 1080: 1081: 1082: 1083: 1084: 1085: 1086: 1087: 1088: 1089: 1090: 1091: 1092: 1093: 1094: 1095: 1096: 1097: 1098: 1099: 1100: 1101: 1102: 1103: 1104: 1105: 1106: 1107: 1108: 1109: 1110: 1111: 1112: 1113: 1114: 1115: 1116: 1117: 1118: 1119: 1120: 1121: 1122: 1123: 1124:
<?php
class Leads_Manager {
static $relation;
static $page;
static $per_page;
static $paged;
static $order;
static $orderby;
static $orderbys;
static $orderbys_flip;
static $num;
static $on;
static $what;
static $tag;
static $keyword;
static $query;
static $taxonomies;
static $statuses;
public function __construct() {
self::load_static_vars();
self::load_hooks();
}
public static function load_hooks() {
add_action('admin_init', array(__CLASS__, 'load_static_vars'));
add_action('admin_enqueue_scripts', array(__CLASS__, 'enqueue_admin_scripts'));
add_action('wp_ajax_perform_actions', array(__CLASS__, 'ajax_perform_actions'));
add_action('wp_ajax_leads_ajax_load_more_leads', array(__CLASS__, 'ajax_load_more_leads'));
add_action('wp_ajax_leads_delete_from_list', array(__CLASS__, 'ajax_delete_from_list'));
add_action('wp_ajax_leads_export_list', array(__CLASS__, 'ajax_leads_export_list'));
}
public static function load_static_vars() {
if (!isset($_REQUEST['page']) || $_REQUEST['page'] != 'lead_management') {
return;
}
$_POST = stripslashes_deep($_POST);
$_REQUEST = stripslashes_deep($_REQUEST);
self::$per_page = 60;
self::$page = empty($_REQUEST['pull_page']) ? 1 : intval($_REQUEST['pull_page']);
self::$paged = empty($_REQUEST['paged']) ? 1 : intval($_REQUEST['paged']);
self::$orderby = (isset($_REQUEST['orderby'])) ? sanitize_text_field($_REQUEST['orderby']) : '';
self::$order = (isset($_REQUEST['order'])) ? strtoupper(sanitize_text_field($_REQUEST['order'])) : 'ASC';
self::$orderbys = array(
__('Date First Created', 'inbound-pro' ) => 'date',
__('Date Last Modified', 'inbound-pro' ) => 'modified',
__('Alphabetical Sort', 'inbound-pro' ) => 'title',
__('Status', 'inbound-pro' ) => 'post_status'
);
self::$orderbys_flip = array_flip(self::$orderbys);
self::$num = (isset($_REQUEST['num'])) ? intval($_REQUEST['num']) : 0;
self::$what = (isset($_REQUEST['what'])) ? sanitize_text_field($_REQUEST['what']) : "";
self::$relation = (isset($_REQUEST['relation'])) ? sanitize_text_field($_REQUEST['relation']) : "AND";
self::$tag = (isset($_REQUEST['t'])) ? sanitize_text_field($_REQUEST['t']) : '';
self::$keyword = (isset($_REQUEST['s'])) ? sanitize_text_field($_REQUEST['s']) : '';
self::$taxonomies = get_object_taxonomies('wp-lead', 'objects');
self::$statuses = Inbound_Leads::get_lead_statuses();
}
public static function enqueue_admin_scripts() {
$screen = get_current_screen();
if ($screen->id != 'wp-lead_page_lead_management') {
return;
}
wp_enqueue_script(array('jquery', 'jqueryui', 'jquery-ui-selectable', 'editor', 'thickbox', 'media-upload'));
wp_enqueue_script('selectjs', INBOUNDNOW_SHARED_URLPATH . 'assets/includes/Select2/select2.min.js', array() , null , false );
wp_enqueue_style('selectjs', INBOUNDNOW_SHARED_URLPATH . 'assets/includes/Select2/select2.min.css');
wp_enqueue_script('tablesort', WPL_URLPATH . 'assets/js/management/tablesort.min.js');
wp_enqueue_script('light-table-filter', WPL_URLPATH . 'assets/js/management/light-table-filter.min.js');
wp_enqueue_script('modernizr', WPL_URLPATH . 'assets/js/management/modernizr.custom.js');
wp_enqueue_script('tablesort', WPL_URLPATH . 'assets/js/management/tablesort.min.js');
wp_enqueue_script('jquery-dropdown', WPL_URLPATH . 'assets/js/management/jquery.dropdown.js');
wp_enqueue_script('jquery-ui', WPL_URLPATH . 'assets/js/management/jquery-ui.js');
wp_enqueue_script('bulk-manage-leads', WPL_URLPATH . 'assets/js/management/admin.js' );
wp_localize_script('bulk-manage-leads', 'bulk_manage_leads', array('admin_url' => admin_url('admin-ajax.php'), 'taxonomies' => self::$taxonomies ));
wp_enqueue_style('wpleads-list-css', WPL_URLPATH . '/assets/css/admin-management.css');
wp_enqueue_style('jquery-ui-css', WPL_URLPATH . '/assets/css/jquery-ui.css');
wp_admin_css('thickbox');
add_thickbox();
}
public static function display_ui() {
global $wpdb;
self::display_notifications();
self::display_headers();
self::display_filters();
self::build_query();
self::display_pagination();
self::display_results_message();
self::display_results_table();
self::display_row_actions();
}
public static function display_notifications() {
if (!isset($_REQUEST['done'])) {
return;
}
switch ($_REQUEST['done']) {
case 'add':
$message = sprintf(__("Added %d posts to the list '%s'", 'inbound-pro' ), self::$num, self::$what);
break;
case 'remove':
$message = sprintf(__("Removed %d posts from the list '%s'.", 'inbound-pro' ), self::$num, self::$what);
break;
case 'tag':
$message = sprintf(__("Tagged %d posts with “ %s ”", 'inbound-pro' ), self::$num, self::$what);
break;
case 'untag':
$message = sprintf(__("Untagged %d posts with '%s'", 'inbound-pro' ), self::$num, self::$what);
break;
case 'delete_leads':
$message = sprintf(__("%d leads permanently deleted", 'inbound-pro' ), self::$num);
break;
}
?>
<div id='message' class='updated'>
<p><strong><?php echo $message; ?></strong></p>
</div>
<?php
}
public static function display_headers() {
?>
<div class="wrap">
<h2><?php _e('Lead Bulk Management', 'inbound-pro' ); ?></h2>
<?php
if (!isset($_REQUEST['submit'])) {
echo '<p class="starter-text">' . __('To get started, select the lead criteria below to see all matching leads.', 'inbound-pro' ) . '</p>';
}
echo "<div id='paged-current'>" . self::$paged . "</div>";
}
public static function display_filters() {
?>
<div id="filters" class="inbound-lead-filters">
<form id="lead-management-form" method="get" action="edit.php">
<input type="hidden" name="page" value="lead_management"/>
<input type="hidden" name="post_type" value="wp-lead"/>
<div id="top-filters"><?php
foreach (self::$taxonomies as $key => $taxonomy) {
if (!$taxonomy->hierarchical) {
}
?>
<div id="inbound-filter">
<div class="filter-label">
<label for="taxonomy"><?php _e(sprintf('Select by %s:', $taxonomy->labels->singular_name), 'inbound-pro' ); ?></label>
</div>
<?php echo self::build_taxonomy_select($taxonomy, 'multiple'); ?>
</div>
<?php
}
?>
<div id="inbound-filter">
<div class="filter-label">
<label for="wp_lead_status"><?php _e('Select by Status:', 'inbound-pro' ); ?>
</label>
</div>
<?php echo self::build_lead_status_select(); ?>
</div>
<div id="inbound-filter">
<div class="filter-label">
<label for="orderby"><?php _e('Match Condition:', 'inbound-pro' ); ?></label></div>
<select name="relation" id="relation">
<option value="AND" <?php echo(self::$relation == 'AND' ? ' selected="selected"' : ''); ?>><?php _e('Match All', 'inbound-pro' ); ?></option>
<option value="OR" <?php echo(self::$relation == 'OR' ? ' selected="selected"' : 'test'); ?>><?php _e('Match Any', 'inbound-pro' ); ?></option>
</select>
</div>
</div>
<div id="bottom-filters">
<div class="filter" id="lead-sort-by">
<div class="filter-label"><label for="orderby"><?php _e('Sort by:', 'inbound-pro' ); ?></label>
</div>
<select name="orderby" id="orderby">
<?php
foreach (self::$orderbys as $title => $value) {
$selected = (self::$orderby == $value) ? ' selected="selected"' : '';
echo "<option value='$value'$selected>$title</option>\n";
}
?>
</select>
<select name="order" id="order">
<option value="asc" <?php (self::$order == 'ASC' ? ' selected="selected"' : ''); ?>><?php _e('Ascending', 'inbound-pro' ); ?></option>
<option value="desc" <?php (self::$order == 'DESC' ? ' selected="selected"' : ''); ?>><?php _e('Descending', 'inbound-pro' ); ?></option>
</select>
</div>
<div class="filter" id="lead-keyword-filter">
<label for="s"><?php _e('Keyword:', 'inbound-pro' ); ?></label>
<input type="text" name="s" id="s" value="<?php echo htmlentities(self::$keyword); ?>" title="<?php _e('Use % for wildcards.', 'inbound-pro' ); ?>"/>
</div>
<div class="filter" id="lead-tag-filter">
<label for="s"><?php _e('Tag:', 'inbound-pro' ); ?></label>
<input type="text" name="t" id="t" value="<?php echo htmlentities(self::$tag); ?>" title="'foo, bar': posts tagged with 'foo' or 'bar'. 'foo+bar': posts tagged with both 'foo' and 'bar'"/>
</div>
<div class="filter">
<input type="submit" class="button-primary" value="<?php _e('Search Leads', 'inbound-pro' ); ?>" name="submit"/>
</div>
</div>
</form>
</div>
<?php
}
public static function display_hidden_action_fields() {
wp_nonce_field('lead_management-edit');
if (isset($_REQUEST['s']) && !empty($_REQUEST['s'])) {
echo '<input type="hidden" name="s" value="' . urlencode($_REQUEST['s']) . '" />';
}
if (isset($_REQUEST['t']) && !empty($_REQUEST['t'])) {
echo '<input type="hidden" name="t" value="' . urlencode($_REQUEST['t']) . '" />';
}
}
public static function display_pagination() {
$pagination = '';
if (isset($query) && $query->max_num_pages > 1) {
$current = preg_replace('/&?paged=[0-9]+/i', '', strip_tags($_SERVER['REQUEST_URI']));
$pagination .= "<div class='tablenav-pages'>";
if (self::$paged > 1) {
$prev = self::$paged - 1;
$pagination .= "<a class='prev page-numbers' href='$current&paged=$prev'>« " . __('Previous', 'inbound-pro' ) . "</a>";
}
for ($i = 1; $i <= $query->max_num_pages; $i++) {
if ($i == self::$paged) {
$pagination .= "<span class='page-numbers current'>$i</span>";
} else {
$pagination .= "<a class='page-numbers' href='$current&paged=$i'>$i</a>";
}
}
if (self::$paged < $query->max_num_pages) {
$next = self::$paged + 1;
$pagination .= "<a class='next page-numbers' href='$current&paged=$next'>" . __('Next', 'inbound-pro' ) . " »</a>";
}
$pagination .= "</div>";
}
echo $pagination;
}
public static function display_results_message() {
if (empty(self::$query->posts)) {
echo '<p>' . __('No posts matched that criteria, sorry! Try again with something different.', 'inbound-pro' ) . '</p>';
return;
}
echo '<div style="margin-top:20px;font-style:italic">';
echo ' <div id="display-lead-total">';
echo ' ' . __('search returned ', 'inbound-pro' ) . '<strong><span id="lead-total-found">' . self::$query->found_posts . ' </span></strong>' . __('results', 'inbound-pro' );
echo ' </div>';
echo ' <div id="display-lead-count">';
echo ' <i class="lead-spinner"></i>';
echo ' <span id="lead-count-text">' . __('Grabbing Matching Leads', 'inbound-pro' ) . '</span>';
echo ' </div>';
echo ' <div class="table-search">';
echo ' <input type="search" class="light-table-filter" data-table="widefat" placeholder="' . __('Filter Results Below', 'inbound-pro' ) . '" /><span id="search-icon"></span>';
echo ' </div>';
echo '</div>';
}
public static function display_results_table() {
if (!isset(self::$query->posts)) {
return;
}
?>
<form method="post" id="man-table" action="<?php echo admin_url('admin.php'); ?>">
<input type="hidden" name="action" value="lead_action"/>
<?php
if (isset($_GET['wplead_list_category'])){
foreach($_GET['wplead_list_category'] as $list_id) {
echo '<input type="hidden" name="wplead_list_category[]" value="'. (int) $list_id.'"/>';
}
}
?>
<div id="posts">
<table class="widefat" id="lead-manage-table">
<thead>
<tr>
<th class="checkbox-header no-sort" scope="col">
<input type="checkbox" id="toggle" title="Select all posts"/></th>
<th class="count-sort-header" scope="col">
<th scope="col"><?php _e('Date', 'inbound-pro' ); ?></th>
<th scope="col"><?php _e('Email', 'inbound-pro' ); ?></th>
<th scope="col"><?php _e('Current Lists', 'inbound-pro' ); ?></th>
<th scope="col"><?php _e('Current Tags', 'inbound-pro' ); ?></th>
<th scope="col" class="no-sort"><?php _e('View', 'inbound-pro' ); ?></th>
<th scope="col"><?php _e('ID', 'inbound-pro' ); ?></th>
<?php do_action('inbound_bulk_lead_action_list_header');?>
</tr>
</thead>
<tbody id="the-list">
<?php
$loop_count = 1;
$i = 0;
foreach (self::$query->posts as $post) {
echo '<tr' . ($i++ % 2 == 0 ? ' class="alternate"' : '') . '>';
echo '<td><input class="lead-select-checkbox" type="checkbox" name="ids[]" value="' . $post->ID . '" /></td>';
echo '<td class="count-sort"><span>' . $loop_count . '</span></td>';
echo '<td>';
if ('0000-00-00 00:00:00' == $post->post_date) {
_e('Unpublished', 'inbound-pro' );
} else {
echo date(__('Y/m/d'), strtotime($post->post_date));
}
echo '</td>';
echo '<td>';
echo ' <span class="lead-email">' . sanitize_text_field($post->post_title) . '</span>';
echo '</td>';
echo '<td class="list-column-row">';
$terms = wp_get_post_terms($post->ID, 'wplead_list_category', 'id');
foreach ($terms as $term) {
echo '<span class="list-pill">' . $term->name . ' <i title="Remove This lead from the ' . $term->name . ' list" class="remove-from-list" data-lead-id="' . $post->ID . '" data-list-id="' . $term->term_id . '"></i></span> ';
}
echo '</td>';
echo '<td class="tags-column-row">';
$tags = wp_get_post_terms($post->ID, 'lead-tags', 'id');
if ($tags) {
foreach ($tags as $tag) {
echo "<a title='Click to Edit Lead Tag Name' target='_blank' href='" . admin_url('edit-tags.php?action=edit&taxonomy=lead-tags&tag_ID=' . $tag->term_id . '&post_type=wp-lead') . "'>$tag->name</a>, ";
}
} else {
_e('No tags', 'inbound-pro' );
}
echo '</td>';
echo '<td>';
echo ' <a class="thickbox inbound-thickbox" href="post.php?action=edit&post=' . $post->ID . '&small_lead_preview=true&TB_iframe=true&width=1345&height=244">' . __('View', 'inbound-pro' ) . '</a>';
echo '</td>';
echo '<td>' . $post->ID . '</td>';
do_action('inbound_bulk_lead_action_list_item', $post);
echo '</tr>';
$loop_count++;
}
echo '</tbody>';
echo '</table>';
}
public static function display_row_actions() {
?>
</tbody>
</table>
</div>
<div id="all-actions" class="tablenav">
<div id="inbound-lead-management">
<span class="lead-actions-title"><?php _e('What do you want to do with the selected leads?', 'inbound-pro' ); ?></span>
<div id="controls">
<?php
self::display_action_controls();
?>
</div>
<div id="lead-action-triggers">
<div class="action" id="lead-export">
<a href="#lead-export-process" class="manage-remove button-primary button export-leads-csv button-primary button" title="<?php _e('Exports selected leads into a CSV format.', 'inbound-pro' ); ?>"> <?php _e('Exports selected as CSV', 'inbound-pro' ); ?></a>
<a style="visibility: hidden;" id="export-leads" href="#lead-export-process"> <?php _e('Exports selected as CSV', 'inbound-pro' ); ?></a>
</div>
<div class="action" id="lead-update-lists">
<label for="lead-update-lists"><?php _e('Choose List:', 'inbound-pro' ); ?></label>
<?php
$terms = get_terms('wplead_list_category', array('hide_empty' => false));
echo '<select name="wplead_list_category_action">';
echo '<option class="" value="" selected="selected">' . __('Select lead list ', 'inbound-pro' ) . '</option>';
foreach ($terms as $term) {
echo '<option class="" value="' . $term->term_id . '" >' . $term->name . ' (' . $term->count . ')</option>';
}
echo '</select>';
?>
<input type="submit" class="button-primary button" name="add" value="<?php _e('Add to', 'inbound-pro' ) ?>" title="<?php _e('Add the selected posts to this category.', 'inbound-pro' ); ?>"/>
<input type="submit" class="manage-remove button-primary button" name="remove" value="<?php _e('Remove from', 'inbound-pro' ) ?>" title="<?php _e('Remove the selected posts from this category.', 'inbound-pro' ); ?>"/>
</div>
<div class="action" id="lead-update-tags">
<label for="lead-update-tags"><?php _e('Tags:', 'inbound-pro' ); ?></label>
<input type="text" id="inbound-lead-tags-input" name="tags" placeholder="<?php _e('Separate multiple tags with commas. ', 'inbound-pro' ); ?>" title="<?php _e('Separate multiple tags with commas.', 'inbound-pro' ); ?>"/>
<input type="submit" name="replace_tags" class="manage-tag-replace button-primary button" value="<?php _e('Replace', 'inbound-pro' ); ?>" title="<?php _e('Replace the selected leads\'s current tags with these ones. Warning this will delete current tags and replace them ', 'inbound-pro' ); ?>"/>
<input type="submit" name="tag" class="manage-tag-add button-primary button" value="<?php _e('Add', 'inbound-pro' ) ?>" title="<?php _e('Add tags to the selected leads without altering the leads\' existing tags', 'inbound-pro' ); ?>"/>
<input type="submit" name="untag" class="manage-remove button-primary button" value="<?php _e('Remove', 'inbound-pro' ) ?>" title="<?php _e('Remove these tags from the selected leads.', 'inbound-pro' ); ?>"/>
</div>
<div class="action" id="lead-update-meta">
<label for="lead-update-meta"><?php _e('Meta:', 'inbound-pro' ); ?></label>
<input type="text" name="meta_val" title="<?php _e('Separate multiple tags with commas.', 'inbound-pro' ); ?>"/>
<input type="submit" name="replace_meta" value="<?php _e('Replace', 'inbound-pro' ); ?>" title="<?php _e('Replace the selected posts\' current meta values with these ones.', 'inbound-pro' ); ?>"/>
<input type="submit" name="meta" value="<?php _e('Add', 'inbound-pro' ); ?>" title="<?php _e('Add these meta values to the selected posts without altering the posts\' existing tags.', 'inbound-pro' ); ?>"/>
<input type="submit" name="unmeta" value="<?php _e('Remove', 'inbound-pro' ); ?>" title="<?php _e('Remove these meta values from the selected posts.', 'inbound-pro' ); ?>"/>
</div>
<div class="action" id="lead-delete">
<label for="lead-delete" id="del-label"><span style="color:red;"><?php _e('Delete Selected Leads (Warning! There is no UNDO):', 'inbound-pro' ); ?></span></label>
<input type="submit" class="manage-remove button-primary button" name="delete_leads" value="<?php _e('Permanently Delete Selected Leads', 'inbound-pro' ) ?>" title="<?php _e('This will delete the selected leads from your database. There is no undo.', 'inbound-pro' ); ?>"/>
</div>
<?php do_action('inbound_bulk_lead_action_triggers');?>
</div>
</div>
<?php
self::display_hidden_action_fields();
?>
</div>
</form>
<div id="lead-export-process" style="display: none;">
<table id="progress-table" class="widefat">
<thead>
<tr>
<th width="50%" scope="col" class="">Count</th>
<th width="50%" scope="col" class="">Progress</th>
</tr>
</thead>
<tbody id="the-progress-list" class="ui-selectable">
</tbody>
</table>
<div class="download-leads-csv"></div>
</div>
</div>
<?php
}
public static function display_action_controls() {
?>
<section id="set-3">
<div class="fleft">
<select id="cd-dropdown" class="cd-select">
<option value="-1" selected class="db-drop-label"><?php _e('Choose action to apply to selected leads', 'inbound-pro' ); ?></option>
<option value="lead-export" class="action-symbol lead-export-symbol db-drop-label"><?php _e('Export Selected Leads as CSV', 'inbound-pro' ); ?></option>
<option value="lead-update-lists" class="action-symbol lead-update-lists-symbol db-drop-label"><?php _e('Add or Remove Selected Leads from Lists', 'inbound-pro' ); ?></option>
<option value="lead-update-tags" class="action-symbol lead-update-tags-symbol db-drop-label"><?php _e('Add or Remove Tags to Selected Leads', 'inbound-pro' ); ?></option>
<option value="lead-delete" class="action-symbol lead-update-delete-symbol db-drop-label"><?php _e('Permanently Delete Selected Leads', 'inbound-pro' ); ?></option>
<?php do_action('inbound_bulk_lead_action_controls');?>
</select>
</div>
</section>
<script>
jQuery(document).ready(function ($) {
jQuery(function () {
jQuery('#cd-dropdown').dropdown();
});
jQuery("body").on('click', '.cd-dropdown li', function () {
var value = jQuery(this).attr('data-value');
console.log(value);
if (value) {
jQuery(".action").hide();
jQuery("#" + value).show();
}
return false;
});
});
</script>
<?php
}
public static function build_query() {
if (!isset($_REQUEST['submit']) && !defined('DOING_AJAX')) {
self::$query = null;
return;
}
$args = array(
'post_type' => 'wp-lead',
'order' => self::$order,
'orderby' => self::$orderby,
'posts_per_page' => self::$per_page,
);
$tax_query = array('relation' => $_REQUEST['relation']);
foreach (self::$taxonomies as $key => $taxonomy) {
if (!$taxonomy->hierarchical) {
}
if (!isset($_REQUEST[$taxonomy->name]) || !$_REQUEST[$taxonomy->name] || $_REQUEST[$taxonomy->name][0] == 'all') {
continue;
}
foreach ($_REQUEST[$taxonomy->name] as $values) {
$tax_query[] = array(
'taxonomy' => $taxonomy->name,
'field' => 'id',
'terms' => array($values)
);
}
}
if (count($tax_query) > 1) {
$args['tax_query'] = $tax_query;
}
if ((isset($_REQUEST['t'])) && $_REQUEST['t'] != "") {
$args['tag'] = $_REQUEST['t'];
}
if (isset($_REQUEST['wp_lead_status']) && $_REQUEST['wp_lead_status'] ) {
$meta_query = array('relation' => $_REQUEST['relation']);
foreach ($_REQUEST['wp_lead_status'] as $status) {
if ($status == 'all') {
continue;
} else {
$meta_query[] = array(
'key' => 'wp_lead_status',
'value' => $status,
'meta_compare' => '='
);
}
}
$args['meta_query'] = $meta_query;
}
if ((isset($_REQUEST['paged'])) && $_REQUEST['paged'] != "1") {
$args['paged'] = self::$paged;
}
self::$query = new WP_Query($args);
}
public static function build_taxonomy_select($taxonomy) {
echo '<select name="' . $taxonomy->name . '[]" id="' . $taxonomy->name . '" multiple class="select2 form-control">';
$list_array = (isset($_REQUEST[$taxonomy->name])) ? $_REQUEST[$taxonomy->name] : array();
echo '<option class="" value="all" ' . (isset($_REQUEST[$taxonomy->name]) && $_REQUEST[$taxonomy->name][0] === 'all' ? 'selected="selected"' : '') . '>' . __('All ', 'inbound-pro' ) . '</option>';
$terms = get_terms($taxonomy->name, array('hide_empty' => false));
foreach ($terms as $term) {
echo '<option class="" value="' . $term->term_id . '" ' . (isset($_REQUEST[$taxonomy->name]) && in_array($term->term_id, $list_array) ? 'selected="selected"' : '') . '>' . $term->name . ' (' . $term->count . ')</option>';
}
echo '</select>';
?>
<script type='text/javascript'>
jQuery("#<?php echo $taxonomy->name; ?>").select2({
allowClear: true,
placeholder: '<?php _e(sprintf('Select %s From List', $taxonomy->labels->singular_name), 'inbound-pro' ); ?>'
});
</script>
<?php
}
public static function build_lead_status_select() {
echo '<select name="wp_lead_status[]" id="wp_lead_status" multiple class="select2 form-control">';
$status_array = (isset($_REQUEST['wp_lead_status'])) ? $_REQUEST['wp_lead_status'] : array();
echo '<option class="" value="all" ' . (isset($_REQUEST['wp_lead_status']) && $_REQUEST['wp_lead_status'][0] === 'all' ? 'selected="selected"' : '') . '>' . __('All ', 'inbound-pro' ) . '</option>';
foreach (self::$statuses as $key=>$status) {
echo '<option class="" value="' . $key . '" ' . (isset($_REQUEST['wp_lead_status']) && in_array($key, $status_array) ? 'selected="selected"' : '') . '>' . $status['label'] . ' (' . Inbound_Leads::get_status_lead_count($key) . ')</option>';
}
echo '</select>';
?>
<script type='text/javascript'>
jQuery("#wp_lead_status").select2({
allowClear: true,
placeholder: '<?php _e('Select Status From List', 'inbound-pro' ); ?>'
});
</script>
<?php
}
public static function ajax_perform_actions() {
if (!current_user_can('level_9')) {
die (__('User does not have admin level permissions.'));
}
if(empty($_POST) || empty($_POST['data']['action'])){
die();
}
$action = $_POST['data']['action'];
$limit = $_POST['data']['limit'];
$offset = $_POST['data']['offset'];
$total = $_POST['data']['total'];
$ids = json_decode(stripslashes($_POST['data']['ids']));
$lead_list_id = $_POST['data']['lead_list_id'];
$tags = $_POST['data']['tags'];
if($action == 'add'){
for($offset; $offset < $limit; $offset++) {
Inbound_Leads::add_lead_to_list(intval($ids[$offset]), $lead_list_id);
}
} elseif($action == 'remove'){
for($offset; $offset < $limit; $offset++) {
Inbound_Leads::remove_lead_from_list(intval($ids[$offset]), $lead_list_id);
}
} elseif($action == 'tag'){
$tags = explode(',', $tags);
for($offset; $offset < $limit; $offset++) {
Inbound_Leads::add_tag_to_lead(intval($ids[$offset]), $tags);
}
} elseif($action == 'untag'){
$tags = explode(',', $tags);
for($offset; $offset < $limit; $offset++) {
Inbound_Leads::remove_tag_from_lead(intval($ids[$offset]), $tags);
}
} elseif($action == 'replace_tags'){
$tags = explode(',', $tags);
for($offset; $offset < $limit; $offset++) {
wp_set_object_terms($ids[$offset], $tags, 'lead-tags');
}
} elseif($action == 'delete_leads'){
for($offset; $offset < $limit; $offset++) {
wp_delete_post(intval($ids[$offset]), true);
}
} else{
die(__('ERROR: unknown action'));
}
$err = print_r(error_get_last(), true);
echo json_encode($err);
die();
}
public static function ajax_leads_export_list(){
$returnArray = array();
if(!isset($_POST) || empty($_POST)){
$returnArray = array(
'status' => 0,
'error' => 'Empty post values!!.',
'url' => ''
);
die(json_encode($returnArray));
}
if(empty($_POST['data']['ids'])){
$returnArray = array(
'status' => 0,
'error' => 'Please select leads to export!!.',
'url' => ''
);
die(json_encode($returnArray));
}
$ids = json_decode(stripslashes($_POST['data']['ids']));
$limit = $_POST['data']['limit'];
$offset = $_POST['data']['offset'];
$total = $_POST['data']['total'];
$is_first = (!isset($_POST['data']['is_first']) || !$_POST['data']['is_first'] ) ? 0 : 1;
$fields = Leads_Field_Map::build_map_array( false );
$fields['wp_lead_status'] = __("Lead Status","inbound-pro");
$fields['wpleads_last_updated'] = __("Last Updated","inbound-pro");
$fields['wpleads_date_created'] = __("Date Created","inbound-pro");
$fields['wpleads_ip_address'] = __("IP Address","inbound-pro");
$fields['sources'] = __("Sources","inbound-pro");
$upload_dir = wp_upload_dir();
$uploads_path = 'leads/csv';
$path = $upload_dir['path'].'/'.$uploads_path.'/';
$url = $upload_dir['url'].'/'.$uploads_path.'/';
$blogtime = current_time( 'mysql' );
$hash = md5(serialize($ids));
$filename = date("y.m.d.") . $hash ;
list( $today_year, $today_month, $today_day, $hour, $minute, $second ) = preg_split( '([^0-9])', $blogtime );
$path = str_replace($today_year.'/'.$today_month.'/','',$path);
$url = str_replace($today_year.'/'.$today_month.'/','',$url);
if(file_exists($path)){
if($is_first == 1){
@unlink($path.$filename.".csv");
}
} else {
mkdir($path, 0755, true);
}
$exported = 0;
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header('Content-Description: File Transfer');
header("Content-type: text/csv");
header("Content-Disposition: attachment; filename=".$path."/".$filename.".csv");
header("Expires: 0");
header("Pragma: public");
$file = @fopen($path.$filename.".csv","a");
if(!$file){
$returnArray = array(
'status' => 0,
'error' => 'Unable to create file. Please check you uploads folder permission!!.',
'url' => ''
);
die(json_encode($returnArray));
}
if($is_first == 1){
fputcsv($file, array_keys($fields));
$headerDisplayed = true;
}
for($j = $offset; $j < $limit; $j++)
{
unset($this_row_data);
if (!isset($ids[$j])) {
continue;
}
$lead = get_post($ids[$j]);
$this_lead_data = get_post_custom($ids[$j]);
foreach ($fields as $key => $val) {
if (isset($this_lead_data[$key])) {
$val = $this_lead_data[$key];
if (is_array($val)) {
$val = implode(';', $val);
}
} else {
$val = "";
}
if ($key == 'wpleads_date_created') {
$val = $lead->post_date;
} else if ($key == 'wpleads_last_updated') {
$val = $lead->post_modified;
}
$this_row_data[$key] = $val;
}
$this_row_data['sources'] = json_encode(Inbound_Events::get_lead_sources($ids[$j]));
fputcsv($file, $this_row_data);
$exported++;
}
fclose($file);
if($limit >= $total){
$url = $url.$filename.'.csv';
$returnArray = array(
'status' => 1,
'error' => '',
'url' => $url
);
}else{
$returnArray = array(
'status' => 1,
'error' => '',
'url' => ''
);
}
die(json_encode($returnArray));
}
public static function ajax_load_more_leads() {
self::build_query();
$i = 0;
$loop_page = self::$paged - 1;
$loop_count = $loop_page * 60;
$loop_count = $loop_count + 1;
foreach (self::$query->posts as $post) {
echo '<tr' . ($i++ % 2 == 0 ? ' class="alternate"' : '') . '>';
echo '<td><input class="lead-select-checkbox" type="checkbox" name="ids[]" value="' . $post->ID . '" /></td>';
echo '<td class="count-sort"><span>' . $loop_count . '</span></td>';
echo '<td>';
if ('0000-00-00 00:00:00' == $post->post_date) {
_e('Unpublished', 'inbound-pro' );
} else {
echo date(__('Y/m/d'), strtotime($post->post_date));
}
echo '</td>';
echo '<td>';
echo ' <span class="lead-email">' . $post->post_title . '</span>';
echo '</td>';
echo '<td class="list-column-row">';
$terms = wp_get_post_terms($post->ID, 'wplead_list_category', 'id');
foreach ($terms as $term) {
echo '<span class="list-pill">' . $term->name . ' <i title="Remove This lead from the ' . $term->name . ' list" class="remove-from-list" data-lead-id="' . $post->ID . '" data-list-id="' . $term->term_id . '"></i></span> ';
}
echo '</td>';
echo '<td class="tags-column-row">';
$_tags = wp_get_post_terms($post->ID, 'lead-tags', 'id');
if ($_tags) {
foreach ($_tags as $tag) {
echo "<a title='Click to Edit Lead Tag Name' target='_blank' href='" . admin_url('edit-tags.php?action=edit&taxonomy=lead-tags&tag_ID=' . $tag->term_id . '&post_type=wp-lead') . "'>$tag->name</a>, ";
}
} else {
_e('No tags', 'inbound-pro' );
}
echo '</td>';
echo '<td>';
echo ' <a class="thickbox" href="post.php?action=edit&post=' . $post->ID . '&small_lead_preview=true&TB_iframe=true&width=1345&height=244">' . __('View', 'inbound-pro' ) . '</a>';
echo '</td>';
echo '<td>' . $post->ID . '</td>';
do_action('inbound_bulk_lead_action_list_item', $post);
echo '</tr>';
$loop_count++;
}
}
public static function ajax_delete_from_list() {
$lead_id = (isset($_POST['lead_id'])) ? $_POST['lead_id'] : '';
$list_id = (isset($_POST['list_id'])) ? $_POST['list_id'] : '';
$id = $lead_id;
$current_terms = wp_get_post_terms($id, 'wplead_list_category', 'id');
$current_terms_count = count($terms);
$all_remove_terms = '';
foreach ($current_terms as $term) {
$add = $term->term_id;
$all_remove_terms .= $add . ' ,';
}
$final = explode(' ,', $all_remove_terms);
$final = array_filter($final, 'strlen');
if (in_array($list_id, $final)) {
$new = array_flip($final);
unset($new[$list_id]);
$save = array_flip($new);
wp_set_object_terms($id, $save, 'wplead_list_category');
}
}
}
add_action('init', 'inbound_load_lead_manager', 1);
function inbound_load_lead_manager() {
new Leads_Manager;
}