$option = 'csv';
}
-
// Get entry ID if supplied
if (isset($_REQUEST['entry'])) {
}
}
+
// Check for a search being done.
if ( isset( $_REQUEST['search'] ) ) {
$search = filter_var( $_REQUEST['search'], FILTER_VALIDATE_BOOLEAN);
}
+
// See if they have a saved search to use.
$result = $this->wpdb->get_row(
$this->wpdb->prepare(
$search_params = filter_var_array(
$_POST,
array(
+ 'source_id' => FILTER_VALIDATE_INT,
'company' => FILTER_SANITIZE_STRING,
'contact' => FILTER_SANITIZE_STRING,
'from_date' => array(
'regexp' => '%([0-9]{2})/([0-9]{2})/([0-9]{4})%'
)
),
+ 'mail_ok' => FILTER_VALIDATE_BOOLEAN,
'interests' => array(
'filter' => FILTER_VALIDATE_BOOLEAN,
'flags' => FILTER_FORCE_ARRAY
// build the $where part
$where_parts = array();
+ if ( $search_params['mail_ok'] ) {
+ $where_parts[] = "T.lead_id IN (
+ SELECT id
+ FROM " . GLM_MEMBERS_LEADS_PLUGIN_DB_PREFIX . "leads
+ WHERE mail_ok = true)";
+ }
if ( $this->config['loggedInUser']['contactUser'] ) {
$where_parts[] = "T.lead_id IN (
SELECT id
} else {
$user_can_edit_leads = true;
}
+ if ( $search_params['source_id'] ) {
+ $where_parts[] = "source_id = {$search_params['source_id']}";
+ }
if ( $search_params['company'] ) {
$where_parts[] = "org = '" . esc_sql( $search_params['company'] ) . "'";
}
);
}
+ // Initialize the interests array
$interests = array();
+
+ // Fetch the groupData.
$groupData = new GlmDataInterestGroups( $this->wpdb, $this->config );
$groups = $groupData->getList();
+ // Initialize the grouped_interests array
$grouped_interests = array();
switch ( $option ) {
// Initialize.
$out = array();
$csv_file_output = '';
- // First line should be the header line
- $out = array(
- 'fname', 'lname', 'email', 'org',
- 'addr1', 'addr2', 'city', 'state', 'zip', 'country',
- 'phone', 'phone2', 'fax',
- 'date_submitted',
- );
- $csv_file_output = implode( ',', array_map( function($str){return sprintf( '"%s"', $str );}, $out ) ) . "\n";
// Generate the output for the csv file
if ( isset( $leads ) && is_array( $leads ) && !empty( $leads ) ) {
+ $lead_counter = 0;
foreach ( $leads as $entry_id => $lead ) {
$out = array(
'fname' => $lead['fname'],
'phone2' => $lead['phone2'],
'fax' => $lead['fax'],
'date_submitted' => $lead['date_submitted'],
+ 'source' => $lead['source_id']['name'],
+ );
+ $interest_by_groups = array();
+ /*
+ * Setup the interests so they are comma separated into a
+ * grouped field. Group name will be the field name header.
+ */
+ $lead_interests = $this->wpdb->get_results(
+ $this->wpdb->prepare(
+ "SELECT li.interest_id, g.title as 'group', i.title
+ FROM " . GLM_MEMBERS_LEADS_PLUGIN_DB_PREFIX . "lead_interests li
+ LEFT OUTER JOIN " . GLM_MEMBERS_LEADS_PLUGIN_DB_PREFIX . "interests i ON (i.id = li.interest_id)
+ LEFT OUTER JOIN " . GLM_MEMBERS_LEADS_PLUGIN_DB_PREFIX . "interest_groups g ON (i.group_id = g.id)
+ WHERE lead_entry_id = %d",
+ $lead['id']
+ ),
+ ARRAY_A
);
+ if ( $lead_interests ) {
+ foreach ( $lead_interests as $interest ) {
+ $interest_by_groups[$interest['group']][] = $interest['title'];
+ }
+ if ( $interest_by_groups ) {
+ foreach ( $interest_by_groups as $group_name => $group_interest ) {
+ $out[$group_name] = implode( ';', $group_interest );
+ }
+ }
+ }
+ // First line should be the header line
+ if ( $lead_counter === 0 ) {
+ $csv_file_output = implode( ',', array_map( function($str){return sprintf( '"%s"', $str );}, array_keys( $out ) ) ) . "\n";
+ }
/*
* remove any double quotes from the values and add double
* quotes around all values.
*/
$csv_file_output .= implode( ',', array_map( function($str){return sprintf( '"%s"', str_replace( '"', '', $str ) );}, $out ) ) . "\n";
+ ++$lead_counter;
}
}
var_dump( $this->wpdb->insert_id );
}
}
- echo '<pre>$_POST: ' . print_r($_POST, true) . '</pre>';
case 'edit':
if ( $this->config['loggedInUser']['contactUser'] ) {
$templateData = array(
'entry' => $entry,
'lead_interests' => $lead_interests,
- 'grouped_interests' => $grouped_interests,
);
break;
- case 'download':
- echo '<pre>$_REQUEST: ' . print_r($_REQUEST, true) . '</pre>';
- exit;
- break;
-
default:
if ( $groups ) {
foreach ( $groups as $group ) {
$templateData = array(
'user_can_edit_leads' => $user_can_edit_leads,
'search_params' => $search_params,
- 'request' => print_r( $_REQUEST, true ),
'leads' => $leads,
- 'grouped_interests' => $grouped_interests,
);
break;
}
+ // Fetch the sources
+ $sources = $this->wpdb->get_results(
+ "SELECT * FROM " . GLM_MEMBERS_LEADS_PLUGIN_DB_PREFIX . "sources ORDER BY title",
+ ARRAY_A
+ );
+
+ if ( $sources ) {
+ foreach ( $sources as &$source ) {
+ $source['selected'] = ( isset( $search_params['source_id'] ) && $source['id'] == $search_params['source_id'] )
+ ? 1
+ : 0;
+ }
+ }
+
+ // Common things to place into the $templateData array
+ $templateData['sources'] = $sources;
+ $templateData['grouped_interests'] = $grouped_interests;
+
// Return status, any suggested view, and any data to controller
return array(
'status' => true,
{include file='admin/leads/header.html'}
+<style>
+ #lead-search-form td {
+ padding: 5px;
+ }
+</style>
+
<form action="{$thisUrl}?page={$thisPage}" method="post">
<input type="hidden" name="search" value="1" />
- <table style="width: 500px;">
+ <table style="width: 500px;" id="lead-search-form">
+ <tr>
+ <td style="text-align: right;"><label for="glm-form-source_id">Source</label></td>
+ <td>
+ {if $sources}
+ <select id="glm-form-source_id" name="source_id">
+ <option value=""></option>
+ {foreach $sources as $source}
+ <option value="{$source.id}" {if $source.selected} selected{/if}>{$source.title}</option>
+ {/foreach}
+ </select>
+ {/if}
+ </td>
+ </tr>
<tr>
- <td><label>Company</label></td>
- <td><input type="text" name="company" value="{$search_params.company}"></td>
+ <td style="text-align: right;"><label for="glm-form-company">Company</label></td>
+ <td><input type="text" id="glm-form-company" name="company" value="{$search_params.company}"></td>
</tr>
<tr>
- <td><label>Contact</label></td>
- <td><input type="text" name="contact" value="{$search_params.contact}"></td>
+ <td style="text-align: right;"><label for="glm-form-contact">Contact</label></td>
+ <td><input type="text" id="glm-form-contact" name="contact" value="{$search_params.contact}"></td>
</tr>
<tr>
<th colspan="2">Date Range</th>
</tr>
<tr>
- <td>From</td>
- <td><input type="text" id="from_date" name="from_date" value="{$search_params.from_date}"></td>
+ <td style="text-align: right;"><label for="glm-form-from_date">From</label></td>
+ <td><input type="text" id="glm-form-from_date" name="from_date" value="{$search_params.from_date}"></td>
+ </tr>
+ <tr>
+ <td style="text-align: right;"><label for="glm-form-to_date">To</label></td>
+ <td><input type="text" id="glm-form-to_date" name="to_date" value="{$search_params.to_date}"></td>
</tr>
<tr>
- <td>To</td>
- <td><input type="text" id="to_date" name="to_date" value="{$search_params.to_date}"></td>
+ <td style="text-align: right;"><label>Mail Ok</label></td>
+ <td><label><input type="checkbox" id="glm-form-mail_ok" name="mail_ok" value="1" {if $search_params.mail_ok}checked{/if}> Yes</label></td>
</tr>
{foreach $grouped_interests as $group_name => $group}
<tr>
- <td>{$group_name}</td>
+ <td style="text-align: right;"><strong>{$group_name}</strong></td>
<td>
{foreach $group as $interest}
- <label><input type="checkbox" name="interests[{$interest.id}]" {if $interest.selected} checked{/if}>{$interest.title}</label>
+ <label style="display: block;width: 90%;">
+ <input type="checkbox" name="interests[{$interest.id}]" {if $interest.selected} checked{/if}>{$interest.title}
+ </label>
{/foreach}
</td>
</tr>
<table class="glm-admin-table">
<tr>
<th>Contact</th>
+ <th>Source</th>
<th>Company</th>
<th>Submitted</th>
</tr>
{$lead.fname} {$lead.lname}
{if $user_can_edit_leads}</a>{/if}
</td>
+ <td> {$lead.source_id.name} </td>
<td> {$lead.org} </td>
<td> {$lead.date_submitted} </td>
</tr>
<script>
jQuery(document).ready(function($){
- $('#from_date').datepicker();
- $('#to_date').datepicker();
+ $('#glm-form-from_date').datepicker();
+ $('#glm-form-to_date').datepicker();
});
</script>