public function modelAction($actionData = false)
{
- $search = filter_var( $_REQUEST['search'], FILTER_VALIDATE_BOOLEAN);
+ // Check for a search being done.
+ if ( isset( $_REQUEST['search'] ) ) {
+ $search = filter_var( $_REQUEST['search'], FILTER_VALIDATE_BOOLEAN);
+ }
if ( isset( $search ) && $search ) {
+ // Filter the $_POST variables from the search form.
+ // Verlify mm/dd/YYYY date format for the from and to dates.
$search_params = filter_var_array(
$_POST,
array(
$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'] ) . "')";
+ // Search for name.
+ // Could be in these formats:
+ // fname lname
+ // lname, fname
+ // lname fname
+ // lname
+ // fname
+ $name_parts = array();
+ $name_parts[] = "SOUNDEX(CONCAT_WS(' ', fname, lname)) = SOUNDEX( '" . esc_sql( $search_params['contact'] ) . "')";
+ $name_parts[] = "SOUNDEX(CONCAT_WS(' ', lname, fname)) = SOUNDEX( '" . esc_sql( $search_params['contact'] ) . "')";
+ $name_parts[] = "SOUNDEX(fname) = SOUNDEX( '" . esc_sql( $search_params['contact'] ) . "')";
+ $name_parts[] = "SOUNDEX(lname) = SOUNDEX( '" . esc_sql( $search_params['contact'] ) . "')";
+ $where_parts[] = implode( ' OR ', $name_parts );
+ }
+ if ( $search_params['interests'] ) {
+ // Search for the interest.
+ // Checks the tables for lead_interests.
+ $where_parts[] = " T.id IN (
+ SELECT lead_entry_id
+ FROM " . GLM_MEMBERS_LEADS_PLUGIN_DB_PREFIX . "lead_interests
+ WHERE interest_id IN ( " . implode( ", ", array_keys( $search_params['interests'] ) ) . " ) ) ";
+ }
+ if ( $search_params['from_date'] && $search_params['to_date'] ) {
+ // We get a date from the form in mm/dd/YYYY format.
+ // Here in mysql we reformat the date using STR_TO_DATE function.
+ $where_parts[] = "T.date_submitted BETWEEN STR_TO_DATE('{$search_params['from_date']}', '%m/%d/%Y') "
+ . "AND STR_TO_DATE('{$search_params['to_date']}', '%m/%d/%Y')";
+ } else if ( $search_params['from_date'] ) {
+ } else if ( $search_params['to_date'] ) {
}
$where = implode( ' AND ', $where_parts );
echo '<pre>$where: ' . print_r( $where, true ) . '</pre>';
$leads = $this->getList( $where, $order );
} else {
$leads = '';
+ $search_params = array(
+ 'company' => '',
+ 'contact' => '',
+ 'from_date' => '',
+ 'to_date' => '',
+ 'interests' => array(),
+ );
}
$groupData = new GlmDataInterestGroups( $this->wpdb, $this->config );
foreach ( $grouped_interests as $group_name => &$interests ) {
foreach ( $interests as $key => &$interest ) {
$grouped_interests[$group_name][$key]['selected']
- = ( $search_params['interests'][$key] ) ? 1 : 0;
+ = ( isset( $search_params['interests'][$key] ) && $search_params['interests'][$key] ) ? 1 : 0;
}
}
}
// Return status, any suggested view, and any data to controller
return array(
- 'status' => true,
+ 'status' => true,
'modelRedirect' => false,
- 'view' => 'admin/leads/index.html',
- 'data' => $templateData
+ 'view' => 'admin/leads/index.html',
+ 'data' => $templateData
);
}
-
}