* @copyright (c) 2014, OnePress Ltd
*
* @package core
* @since 1.0.0
*/
/**
* Common Settings
*/
class OPanda_LeadsPage extends OPanda_AdminPage {
public function __construct( $plugin ) {
$this->menuPostType = OPANDA_POST_TYPE;
$this->id = "leads";
if( !current_user_can('administrator') )
$this->capabilitiy = "manage_opanda_leads";
require_once OPANDA_BIZPANDA_DIR . '/admin/includes/leads.php';
$count = OPanda_Leads::getCount();
if ( empty( $count ) ) $count = '0';
$this->menuTitle = sprintf( __('Leads (%d)', 'bizpanda'), $count );
parent::__construct( $plugin );
}
public function assets($scripts, $styles) {
$this->styles->add(OPANDA_BIZPANDA_URL . '/assets/admin/css/leads.010008.css');
$this->scripts->add(OPANDA_BIZPANDA_URL . '/assets/admin/js/leads.010008.js');
$this->scripts->request('jquery');
$this->scripts->request( array(
'control.checkbox',
'control.dropdown'
), 'bootstrap' );
$this->styles->request( array(
'bootstrap.core',
'bootstrap.form-group',
'bootstrap.separator',
'control.dropdown',
'control.checkbox',
), 'bootstrap' );
}
public function indexAction() {
if(!class_exists('WP_List_Table')){
require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
}
require_once( OPANDA_BIZPANDA_DIR . '/admin/includes/classes/class.leads.table.php' );
$table = new OPanda_LeadsListTable( array('screen' => 'bizpanda-leads') );
$table->prepare_items();
?>
Sign-In Locker.', 'bizpanda'), opanda_get_help_url('what-is-signin-locker') ); ?>
search_box(__('Search Leads', 'mymail'), 's');
$table->views();
?>
lead_email;
$name = $lead->lead_name;
$family = $lead->lead_family;
if ( !empty( $name) || !empty( $family) ) {
$displayName = $name . ' ' . $family;
} else {
$displayName = !empty( $lead->lead_display_name )? $lead->lead_display_name : $lead->lead_email;
}
$emailConfirmed = empty( $lead->lead_email_confirmed ) ? 0 : 1;
$subscriptionConfirmed = empty( $lead->lead_subscription_confirmed ) ? 0 : 1;
if ( isset( $_POST['submit'] ) ) {
$data = array();
$email = $_POST['email'];
if ( !filter_var($email, FILTER_VALIDATE_EMAIL) || !preg_match('/@.+\./', $email) ) {
$error = __('Please enter a valid email.', 'bizpanda');
} else {
$name = $_POST['name'];
$family = $_POST['family'];
if ( !empty( $name) || !empty( $family) ) {
$displayName = $name . ' ' . $family;
} else {
$displayName = !empty( $lead->lead_display_name )? $lead->lead_display_name : $lead->lead_email;
}
$data['email'] = $email;
$data['displayName'] = $displayName;
$data['name'] = $name;
$data['family'] = $family;
$emailConfirmed = empty( $_POST['email_confirmed'] ) ? 0 : 1;
$subscriptionConfirmed = empty( $_POST['subscription_confirmed'] ) ? 0 : 1;
$customValues = isset( $_POST['opanda_values'] ) ? $_POST['opanda_values'] : array();
$customNames = isset( $_POST['opanda_names'] ) ? $_POST['opanda_names'] : array();
$index = 0;
foreach( $customNames as $customName ) {
$data['{' . $customName . '}'] = $customValues[$index];
$customFields[$customName] = $customValues[$index];
$index++;
}
OPanda_Leads::save($lead, $data, array(), $emailConfirmed, $subscriptionConfirmed);
$url = admin_url('/edit.php?post_type=opanda-item&page=leads-bizpanda&action=leadDetails&leadID=' . $lead->ID . '&opanda_success=1');
wp_redirect($url);
exit;
}
}
$avatar = OPanda_Leads::getAvatar( $leadId, $lead->lead_email, 150 );
$postUrl = admin_url('/edit.php?post_type=opanda-item&page=leads-bizpanda&action=leadDetails&leadID=' . $lead->ID);
$cancelUrl = admin_url('/edit.php?post_type=opanda-item&page=leads-bizpanda');
?>
Edit
Well done! The lead data updated successfully.', 'bizpanda') ?>
get_results(
"SELECT l.lead_item_id AS locker_id, COUNT(l.ID) AS count, p.post_title AS locker_title "
. "FROM {$wpdb->prefix}opanda_leads AS l "
. "LEFT JOIN {$wpdb->prefix}posts AS p ON p.ID = l.lead_item_id "
. "GROUP BY l.lead_item_id", ARRAY_A );
$lockerList = array(
array('all', __('Mark All', 'bizpanda') )
);
foreach( $data as $items ) {
$lockerList[] = array( $items['locker_id'], $items['locker_title'] . ' (' . $items['count'] . ')');
$lockerIds[] = $items['locker_id'];
}
// default values
$status = 'all';
$fields = array('lead_email', 'lead_name', 'lead_family');
$delimiter = ',';
// custom fields
$customFields = OPanda_Leads::getCustomFields();
$selectedCustomFields = array();
$customFieldsForList = array();
foreach( $customFields as $customField ) {
$customFieldsForList[] = array( $customField->field_name, $customField->field_name );
}
// exporting
if ( isset( $_POST['opanda_export'] ) ) {
// - delimiter
$delimiter = isset( $_POST['opanda_delimiter'] ) ? $_POST['opanda_delimiter'] : ',';
if ( !in_array( $status, array(',', ';') ) ) $status = ',';
// - channels
$lockers = isset( $_POST['opanda_lockers'] ) ? $_POST['opanda_lockers'] : array();
$lockerIds = array();
foreach( $lockers as $lockerId ) {
if ( 'all' == $lockerId ) continue;
$lockerIds[] = intval( $lockerId );
}
// - status
$status = isset( $_POST['opanda_status'] ) ? $_POST['opanda_status'] : 'all';
if ( !in_array( $status, array('all', 'confirmed', 'not-confirmed') ) ) $status = 'all';
// - fields
$rawFields = isset( $_POST['opanda_fields'] ) ? $_POST['opanda_fields'] : array();
$fields = array();
foreach( $rawFields as $field ) {
if ( !in_array( $field, array('lead_email', 'lead_display_name', 'lead_name', 'lead_family', 'lead_ip') ) ) continue;
$fields[] = $field;
}
// - custom fields
$rawCustomFields = isset( $_POST['opanda_custom_fields'] ) ? $_POST['opanda_custom_fields'] : array();
$selectedCustomFields = array();
foreach( $rawCustomFields as $customField ) {
$selectedCustomFields[] = $customField;
}
if ( in_array('custom_facebook_id', $rawFields) ) {
$selectedCustomFields[] = 'facebookId';
}
if ( empty( $lockers) || ( empty( $fields ) && empty( $selectedCustomFields ) ) ) {
$error = __('Please make sure that you selected at least one channel and field.', 'bizpanda');
} else {
$sql = 'SELECT leads.ID,';
$fields[] = 'ID';
$sqlFields = array();
foreach( $fields as $field ) $sqlFields[] = 'leads.' . $field;
$sql .= implode(',', $sqlFields);
if ( !empty( $selectedCustomFields ) ) {
$sql .= ',fields.field_name,fields.field_value';
}
$sql .= ' FROM ' . $wpdb->prefix . 'opanda_leads AS leads ';
if ( !empty( $selectedCustomFields ) ) {
$sql .= 'LEFT JOIN ' . $wpdb->prefix . 'opanda_leads_fields AS fields ON fields.lead_id = leads.ID ';
}
$sql .= 'WHERE leads.lead_item_id IN (' . implode(',', $lockerIds) . ')';
if ( 'all' != $status ) {
$sql .= ' AND leads.lead_email_confirmed = '. ( ( 'confirmed' == $status ) ? '1' : '0' );
}
$result = $wpdb->get_results( $sql, ARRAY_A );
$leads = array();
foreach( $result as $item ) {
$id = $item['ID'];
if ( !isset( $leads[$id] ) ) {
$leads[$id] = array();
foreach( $fields as $field ) {
if ( $field === 'ID' ) continue;
$leads[$id][$field] = $item[$field];
}
foreach( $selectedCustomFields as $field ) $leads[$id][$field] = null;
}
if ( !empty( $item['field_name'] ) && in_array($item['field_name'], $selectedCustomFields) ) {
$leads[$id][$item['field_name']] = $item['field_value'];
}
}
if ( empty( $leads ) ) {
$warning = __('No leads found. Please try to change the settings of exporting.', 'bizpanda');
} else {
$filename = 'leads-' . date('Y-m-d-H-i-s') . '.csv';
header("Content-Type: text/csv");
header("Content-Disposition: attachment; filename=" . $filename);
header("Cache-Control: no-cache, no-store, must-revalidate");
header("Pragma: no-cache");
header("Expires: 0");
$output = fopen("php://output", "w");
foreach( $leads as $row ) {
fputcsv($output, $row, $delimiter);
}
fclose($output);
exit;
}
}
}
// creating a form
$form = new FactoryForms328_Form(array(
'scope' => 'opanda',
'name' => 'exporting'
), $bizpanda );
$form->setProvider( new FactoryForms328_OptionsValueProvider(array(
'scope' => 'opanda'
)));
$options = array(
array(
'type' => 'separator'
),
array(
'type' => 'radio',
'name' => 'format',
'title' => __('Format', 'bizpanda'),
'hint' => __('Only the CSV format is available currently.'),
'data' => array(
array('csv', __('CSV File', 'bizpanda') )
),
'default' => 'csv'
),
array(
'type' => 'radio',
'name' => 'delimiter',
'title' => __('Delimiter', 'bizpanda'),
'hint' => __('Choose a delimiter for a CSV document.'),
'data' => array(
array(',', __('Comma', 'bizpanda') ),
array(';', __('Semicolon', 'bizpanda') )
),
'default' => $delimiter
),
array(
'type' => 'separator'
),
array(
'type' => 'list',
'way' => 'checklist',
'name' => 'lockers',
'title' => __('Channels', 'bizpanda'),
'hint' => __('Mark lockers which attracted leads you wish to export.'),
'data' => $lockerList,
'default' => implode(',', $lockerIds)
),
array(
'type' => 'radio',
'name' => 'status',
'title' => __('Email Status', 'bizpanda'),
'hint' => __('Choose the email status of leads to export.'),
'data' => array(
array('all', __('All', 'bizpanda') ),
array('confirmed', __('Only Confirmed Emails', 'bizpanda') ),
array('not-confirmed', __('Only Not Confirmed', 'bizpanda') )
),
'default' => $status
),
array(
'type' => 'separator'
),
array(
'type' => 'list',
'way' => 'checklist',
'name' => 'fields',
'title' => __('Fields To Export', 'bizpanda'),
'data' => array(
array('lead_email', __('Email', 'bizpanda') ),
array('lead_display_name', __('Display Name', 'bizpanda') ),
array('lead_name', __('Firstname', 'bizpanda') ),
array('lead_family', __('Lastname', 'bizpanda') ),
array('lead_ip', __('IP', 'bizpanda') ),
array('custom_facebook_id', __('Facebook App Scoped Id', 'bizpanda') )
),
'default' => implode(',', $fields)
)
);
if ( !empty( $customFieldsForList ) ) {
$options[] = array(
'type' => 'list',
'way' => 'checklist',
'name' => 'custom_fields',
'title' => __('Custom Fields', 'bizpanda'),
'data' => $customFieldsForList,
'default' => implode(',', $selectedCustomFields)
);
}
$options[] = array(
'type' => 'separator'
);
$form->add($options);
?>