public function modelAction($actionData = false)
{
+ $search = filter_var( $_REQUEST['search'], FILTER_VALIDATE_BOOLEAN);
if ( isset( $search ) && $search ) {
- $leads = $this->getList();
+ $search_params = filter_var_array(
+ $_POST,
+ array(
+ 'company' => FILTER_SANITIZE_STRING,
+ 'contact' => FILTER_SANITIZE_STRING,
+ 'from_date' => array(
+ 'filter' => FILTER_VALIDATE_REGEXP,
+ 'options' => array(
+ 'regexp' => '%([0-9]{2})/([0-9]{2})/([0-9]{4})%'
+ )
+ ),
+ 'to_date' => array(
+ 'filter' => FILTER_VALIDATE_REGEXP,
+ 'options' => array(
+ 'regexp' => '%([0-9]{2})/([0-9]{2})/([0-9]{4})%'
+ )
+ ),
+ 'interests' => array(
+ 'filter' => FILTER_VALIDATE_BOOLEAN,
+ 'flags' => FILTER_FORCE_ARRAY
+ )
+ )
+ );
+
+ // build the $where part
+ $where_parts = array();
+ if ( $search_params['company'] ) {
+ $where_parts[] = "org = '" . esc_sql( $search_params['company'] ) . "'";
+ }
+ if ( $search_params['contact'] ) {
+ $where_parts[] = "SOUNDEX(CONCAT_WS(' ', fname, lname)) = SOUNDEX( '" . esc_sql( $search_params['contact'] ) . "')";
+ }
+ $where = implode( ' AND ', $where_parts );
+ echo '<pre>$where: ' . print_r( $where, true ) . '</pre>';
+ $order = "T.lname, T.fname";
+ $leads = $this->getList( $where, $order );
} else {
$leads = '';
}
- $leads = $this->getList();
$groupData = new GlmDataInterestGroups( $this->wpdb, $this->config );
$groups = $groupData->getList();
if ( $groups ) {
foreach ( $groups as $group ) {
- $intData = new GlmDataInterests( $this->wpdb, $this->config );
- $grouped_interests[$group['title']] = $intData->getList(
- "group_id = " . $group['id'],
- 'title'
- );
+ $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']
+ = ( $search_params['interests'][$key] ) ? 1 : 0;
+ }
+ }
}
}
- echo '<pre>$grouped_interests: ' . print_r($grouped_interests, true) . '</pre>';
+
// Compile template data
$templateData = array(
- 'leads' => $leads,
+ 'search_params' => $search_params,
+ 'request' => print_r( $_REQUEST, true ),
+ 'leads' => $leads,
+ 'grouped_interests' => $grouped_interests,
);
// Return status, any suggested view, and any data to controller
if ( !$lead_id ) {
return;
}
+ echo '<pre>$glm_leads_entry: ' . print_r( $glm_leads_entry, true ) . '</pre>';
// create the lead entry
$lead_entry = $this->wpdb->insert(
GLM_MEMBERS_LEADS_PLUGIN_DB_PREFIX . 'lead_entry', // table
$ints[$interest['id']] = $interest['title'];
}
}
- //echo '<pre>$interests: ' . print_r($interests, true) . '</pre>';
- //echo '<pre>$ints: ' . print_r($ints, true) . '</pre>';
- //echo '<pre>$leads_fields: ' . print_r($leads_fields, true) . '</pre>';
// create the lead to interest entries
// using $leads_fields
// first delete any they current have
- //echo '<pre>$leads_fields: ' . print_r($leads_fields, true) . '</pre>';
if ( is_array( $leads_fields) && !empty( $leads_fields ) ) {
foreach ( $leads_fields as $interest_val ) {
$int_key = array_search( $interest_val, $ints );
- //echo '<pre>$int_key: ' . print_r($int_key, true) . '</pre>';
if ( $int_key ) {
$this->wpdb->insert(
GLM_MEMBERS_LEADS_PLUGIN_DB_PREFIX . 'lead_interests', // table
{include file='admin/leads/header.html'}
-<form>
- <label>Company</label><br>
- <input type="text" name="company"><br>
- <label>Contact</label><br>
- <input type="text" name="contact"><br>
- <input type="submit" value="Search">
+<form action="{$thisUrl}?page={$thisPage}" method="post">
+ <input type="hidden" name="search" value="1" />
+ <table style="width: 500px;">
+ <tr>
+ <td><label>Company</label></td>
+ <td><input type="text" 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>
+ </tr>
+ <tr>
+ <th colspan="2">Date Range</th>
+ </tr>
+ <tr>
+ <td>From</td>
+ <td><input type="text" name="from_date" value="{$search_params.from_date}"></td>
+ </tr>
+ <tr>
+ <td>To</td>
+ <td><input type="text" name="to_date" value="{$search_params.to_date}"></td>
+ </tr>
+ {foreach $grouped_interests as $group_name => $group}
+ <tr>
+ <td>{$group_name}</td>
+ <td>
+ {foreach $group as $interest}
+ <label><input type="checkbox" name="interests[{$interest.id}]" {if $interest.selected} checked{/if}>{$interest.title}</label>
+ {/foreach}
+ </td>
+ </tr>
+ {/foreach}
+ <tr>
+ <td colspan="2"><input type="submit" value="Search"></td>
+ </tr>
+ </table>
</form>
{if $leads}
{/foreach}
</table>
{/if}
+
{include file='admin/footer.html'}