*/
// Load Leads data abstract
+require_once(GLM_MEMBERS_LEADS_PLUGIN_CLASS_PATH.'/data/dataLeads.php');
require_once(GLM_MEMBERS_LEADS_PLUGIN_CLASS_PATH.'/data/dataLeadEntry.php');
require_once GLM_MEMBERS_LEADS_PLUGIN_CLASS_PATH.'/data/dataInterests.php';
require_once GLM_MEMBERS_LEADS_PLUGIN_CLASS_PATH.'/data/dataInterestGroups.php';
public function modelAction($actionData = false)
{
+ $where = ' true ';
$option = false;
$user_can_edit_leads = false;
$wpUser = $this->config['loggedInUser']['wpUser'];
$search_id = false;
+ $numbDisplayed = false;
+ $lastDisplayed = false;
+ $paging = true;
+ $prevStart = false;
+ $nextStart = false;
+ $start = 1;
+ $limit = 20; // Set to the number of listings per page
+ $haveLeads = false;
+ $leadCount = 0;
+ $addingLead = false;
// Get any provided option
if ( isset( $_REQUEST['option'] ) ) {
'regexp' => '%([0-9]{2})/([0-9]{2})/([0-9]{4})%'
)
),
- 'mail_ok' => FILTER_VALIDATE_BOOLEAN,
+ 'mail_ok' => FILTER_VALIDATE_BOOLEAN,
+ 'member_ok' => FILTER_VALIDATE_BOOLEAN,
'interests' => array(
'filter' => FILTER_VALIDATE_BOOLEAN,
'flags' => FILTER_FORCE_ARRAY
)
);
}
+ // checking the booleans for empty or false
+ if ( isset( $_REQUEST['mail_ok'] ) && $_REQUEST['mail_ok'] === '0' ) {
+ $search_params['mail_ok'] = (int)0;
+ }
+ if ( isset( $_REQUEST['member_ok'] ) && $_REQUEST['member_ok'] === '0' ) {
+ $search_params['member_ok'] = (int)0;
+ }
if ( $wpUser['ID'] ) {
$search_data = array(
// build the $where part
$where_parts = array();
- if ( $search_params['mail_ok'] ) {
+ if ( isset( $search_params['member_ok'] ) && $search_params['member_ok'] !== false ) {
+ $member_ok = ( $search_params['member_ok'] === true ) ? 'true' : 'false';
+ $where_parts[] = "T.lead_id IN (
+ SELECT id
+ FROM " . GLM_MEMBERS_LEADS_PLUGIN_DB_PREFIX . "leads
+ WHERE member_ok = $member_ok)";
+ }
+ if ( isset( $search_params['mail_ok'] ) && $search_params['mail_ok'] !== false ) {
+ $mail_ok = ( $search_params['mail_ok'] === true ) ? 'true' : 'false';
$where_parts[] = "T.lead_id IN (
SELECT id
FROM " . GLM_MEMBERS_LEADS_PLUGIN_DB_PREFIX . "leads
- WHERE mail_ok = true)";
+ WHERE mail_ok = $mail_ok)";
}
if ( $this->config['loggedInUser']['contactUser'] ) {
$where_parts[] = "T.lead_id IN (
$where_parts[] = "T.date_submitted <= STR_TO_DATE('{$search_params['to_date']}', '%m/%d/%Y')";
}
if ( isset( $search ) && $search ) {
- $where = implode( ' AND ', $where_parts );
+ if ( isset( $where_parts ) && !empty( $where_parts ) ) {
+ $where .= ' AND ' . implode( ' AND ', $where_parts );
+ }
$order = "T.lname, T.fname";
- $leads = $this->getList( $where, $order );
+
+ // Check if we're doing paging
+ if (isset($_REQUEST['pageSelect'])) {
+
+ // If request is for Next
+ if ($_REQUEST['pageSelect'][0] == 'N') {
+ $newStart = $_REQUEST['nextStart'] - 0;
+
+ // Otherwise it must be Previous
+ } else {
+ $newStart = $_REQUEST['prevStart'] - 0;
+ }
+
+ if ($newStart > 0) {
+ $start = $newStart;
+ }
+ }
+
+ // Get count of members listed
+ $leadCount = $this->getStats($where);
+
+ // If the number of members is less than a page, don't do paging
+ if ($leadCount <= $limit) {
+ $paging = false;
+ }
+
+ //$leads = $this->getList( $where, $order );
+ $listResult = $this->getSimpleEntriesList( $where, $order, true, 'id', $start, $limit );
+
+ // Get paging results
+ $numbDisplayed = $listResult['returned'];
+ $lastDisplayed = $listResult['last'];
+ if ($start == 1) {
+ $prevStart = false;
+ } else {
+ $prevStart = $start - $limit;
+ if ($start < 1) {
+ $start = 1;
+ }
+ }
+ if ($listResult['returned'] == $limit) {
+ $nextStart = $start + $limit;
+ }
+
+ // since we're doing paging, we have to break out just the member data
+ $leads = $listResult['list'];
+ unset($listResult);
+
+ // If we have list entries - even if it's an empty list
+ $success = true;
+ $haveLeads = false;
+ if ($leads !== false) {
+
+ $success = true;
+
+ // If we have any entries
+ if (count($leads) > 0) {
+ $haveLeads = true;
+ }
+ }
+
} else {
$leads = false;
}
// Get the record for this Entry.
$entry = $this->editEntry( $this->entryId );
+ // get the field from the leads table
+ $leadData = new GlmDataLeads( $this->wpdb, $this->config );
+ $lead = $leadData->getEntry( $entry['fieldData']['lead_id']['value'] );
+ if ( $lead ) {
+ $entry['fieldData']['mail_ok'] = $lead['mail_ok'];
+ $entry['fieldData']['member_ok'] = $lead['member_ok'];
+ }
+ //echo '<pre>$entry: ' . print_r($entry, true) . '</pre>';
+
// Use the edit view file.
$view = 'edit.html';
}
// Compile template data
$templateData = array(
+ 'addingLead' => $addingLead,
+ 'entry' => $entry,
+ 'lead_interests' => $lead_interests,
+ );
+ break;
+
+ case 'add':
+ if ( $this->config['loggedInUser']['contactUser'] ) {
+ break;
+ }
+ $entry = $this->newEntry();
+ $addingLead = true;
+
+ $lead_interests = array();
+
+ // Use the edit view file.
+ $view = 'edit.html';
+
+ // Setup the $grouped_interests array for the edit page.
+ if ( $groups ) {
+ foreach ( $groups as $group ) {
+ $intData = new GlmDataInterests( $this->wpdb, $this->config );
+ $group_parts = explode( '_', $group['title'] );
+ $group_parts = array_map( function($item){ return ucfirst( $item ); }, $group_parts );
+ $group_title = implode( ' ', $group_parts );
+ $grouped_interests[$group_title] = $intData->getList( "group_id = " . $group['id'], 'title' );
+ }
+ if ( $grouped_interests ) {
+ foreach ( $grouped_interests as $group_name => $interests ) {
+ foreach ( $interests as $key => $interest ) {
+ $grouped_interests[$group_name][$key]['selected'] = 0;
+ }
+ }
+ }
+ }
+
+ // Compile template data
+ $templateData = array(
+ 'addingLead' => $addingLead,
'entry' => $entry,
'lead_interests' => $lead_interests,
);
// Common things to place into the $templateData array
$templateData['sources'] = $sources;
$templateData['grouped_interests'] = $grouped_interests;
+ $templateData['haveLeads'] = $haveLeads;
+ $templateData['leadCount'] = $leadCount;
+ $templateData['numbDisplayed'] = $numbDisplayed;
+ $templateData['lastDisplayed'] = $lastDisplayed;
+ $templateData['prevStart'] = $prevStart;
+ $templateData['nextStart'] = $nextStart;
+ $templateData['start'] = $start;
+ $templateData['limit'] = $limit;
+ $templateData['paging'] = $paging;
+
// Return status, any suggested view, and any data to controller
return array(
padding: 5px;
}
</style>
-
+{if $user_can_edit_leads}
+ <a class="button button-primary glm-button glm-right" href="{$thisUrl}?page={$thisPage}&option=add">Add New Lead</a>
+{/if}
<form action="{$thisUrl}?page={$thisPage}" method="post">
<input type="hidden" name="search" value="1" />
+ <input type="hidden" name="prevStart" value="{$prevStart}" />
+ <input type="hidden" name="nextStart" value="{$nextStart}" />
+ <input type="hidden" name="limit" value="{$limit}" />
<table style="width: 500px;" id="lead-search-form">
<tr>
<td style="text-align: right;"><label for="glm-form-source_id">Source</label></td>
</tr>
<tr>
<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>
+ <td>
+ <select id="glm-form-mail_ok" name="mail_ok">
+ <option value="">Choose</option>
+ <option value="1" {if $search_params.mail_ok == '1'}selected{/if}>Yes</option>
+ <option value="0" {if $search_params.mail_ok === 0}selected{/if}>No</option>
+ </select>
+ </td>
</tr>
+ {if $user_can_edit_leads}
+ <tr>
+ <td style="text-align: right;"><label>Member Ok</label></td>
+ <td>
+ <select id="glm-form-member_ok" name="member_ok">
+ <option value="">Choose</option>
+ <option value="1" {if $search_params.member_ok == '1'}selected{/if}>Yes</option>
+ <option value="0" {if $search_params.member_ok === 0}selected{/if}>No</option>
+ </select>
+ </td>
+ </tr>
+ {/if}
{foreach $grouped_interests as $group_name => $group}
<tr>
<td style="text-align: right;"><strong>{$group_name}</strong></td>
<td colspan="2"><input class="button" type="submit" value="Search"></td>
</tr>
</table>
-</form>
{if $leads}
<h4>Search Results:</h4>
- <form action="{$thisUrl}?page={$thisPage}">
- <a href="{$ajaxUrl}?action=glm_members_admin_ajax&glm_action=csvExport" class="button">Download as CSV File</a>
- </form>
- <table class="glm-admin-table">
- <tr>
- <th>Contact</th>
- <th>Source</th>
- <th>Company</th>
- <th>Submitted</th>
- </tr>
- {foreach $leads as $lead}
- <tr>
- <td>
- {if $user_can_edit_leads}<a href="{$thisUrl}?page={$thisPage}&glm_action=index&option=edit&entry={$lead.id}">{/if}
- {$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>
- {/foreach}
+ <a href="{$ajaxUrl}?action=glm_members_admin_ajax&glm_action=csvExport" class="button">Download as CSV File</a>
+
+ <br clear="all">
+ <p><b>Total found:</b> {$leadCount} </p>
+ {if $paging}
+ <input type="Submit" name="pageSelect" value="Previous {$limit} Leads" class="button button-secondary glm-button"{if !$prevStart} disabled{/if}>
+ <input type="Submit" name="pageSelect" value="Next {$limit} Leads" class="button button-secondary glm-button"{if !$nextStart} disabled{/if}>
+ {/if}
+ <table class="wp-list-table striped glm-admin-table">
+ <thead>
+ <tr>
+ <th>Contact</th>
+ <th>Source</th>
+ <th>Company</th>
+ <th>Submitted</th>
+ </tr>
+ </thead>
+ <tbody>
+ {if $haveLeads}
+ {assign var="i" value="0"}
+ {foreach $leads as $lead}
+ {if $i++ is odd by 1}<tr>{else}<tr class="alternate">{/if}
+ <td>
+ {if $user_can_edit_leads}
+ <a href="{$thisUrl}?page={$thisPage}&glm_action=index&option=edit&entry={$lead.id}">
+ {/if}
+ {$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>
+ {/foreach}
+ {/if}
+ <tbody>
</table>
+ {if $paging}
+ <input type="Submit" name="pageSelect" value="Previous {$limit} {$terms.term_member_plur_cap}" class="button button-secondary glm-button"{if !$prevStart} disabled{/if}>
+ <input type="Submit" name="pageSelect" value="Next {$limit} {$terms.term_member_plur_cap}" class="button button-secondary glm-button"{if !$nextStart} disabled{/if}>
+ {/if}
{/if}
+</form>
+
<script>
jQuery(document).ready(function($){
$('#glm-form-from_date').datepicker();