*/
public $config;
+ public $entryId = false;
/*
* Constructor
*
public function modelAction($actionData = false)
{
+ $option = false;
+
+ // Get any provided option
+ if ( isset( $_REQUEST['option'] ) ) {
+ $option = $_REQUEST['option'];
+ }
+
+ // Get event ID if supplied
+ if (isset($_REQUEST['entry'])) {
+
+ // Make sure it's numeric
+ $this->entryId = ( $_REQUEST['entry'] - 0 );
+
+ if ( $this->entryId <= 0 ) {
+ $this->entryId = false;
+ }
+
+ }
// Check for a search being done.
if ( isset( $_REQUEST['search'] ) ) {
$search = filter_var( $_REQUEST['search'], FILTER_VALIDATE_BOOLEAN);
$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'] ) {
+ $where_parts[] = "T.date_submitted >= STR_TO_DATE('{$search_params['from_date']}', '%m/%d/%Y')";
} else if ( $search_params['to_date'] ) {
+ $where_parts[] = "T.date_submitted <= STR_TO_DATE('{$search_params['to_date']}', '%m/%d/%Y')";
}
$where = implode( ' AND ', $where_parts );
//echo '<pre>$where: ' . print_r( $where, true ) . '</pre>';
);
}
+ $interests = array();
$groupData = new GlmDataInterestGroups( $this->wpdb, $this->config );
$groups = $groupData->getList();
$grouped_interests = array();
- 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' );
+ switch ( $option ) {
+ case 'update':
+ $entry = $this->updateEntry( $this->entryId );
+
+ // Update the Entries Interests. First remove them.
+ $this->wpdb->delete(
+ GLM_MEMBERS_LEADS_PLUGIN_DB_PREFIX . "lead_interests",
+ array( 'lead_entry_id' => $this->entryId ),
+ array( '%d' )
+ );
+ // then add the ones needed.
+ if ( isset( $_POST['interests'] ) && !empty( $_POST['interests'] ) ) {
+ foreach ( $_POST['interests'] as $interest_id => $new_interest ) {
+ $this->wpdb->insert(
+ GLM_MEMBERS_LEADS_PLUGIN_DB_PREFIX . "lead_interests",
+ array(
+ 'lead_entry_id' => $this->entryId,
+ 'interest_id' => $interest_id
+ ),
+ array( '%d', '%d' )
+ );
+ }
}
- if ( $grouped_interests ) {
- foreach ( $grouped_interests as $group_name => &$interests ) {
- foreach ( $interests as $key => &$interest ) {
- $grouped_interests[$group_name][$key]['selected']
- = ( isset( $search_params['interests'][$key] ) && $search_params['interests'][$key] ) ? 1 : 0;
+ echo '<pre>$_POST: ' . print_r($_POST, true) . '</pre>';
+
+ case 'edit':
+ $entry = $this->editEntry( $this->entryId );
+
+ $view = 'edit.html';
+
+ $lead_ints = array();
+ $sql = "
+ SELECT *
+ FROM " . GLM_MEMBERS_LEADS_PLUGIN_DB_PREFIX . "lead_interests
+ WHERE lead_entry_id = " . $this->entryId;
+ $lead_interests = $this->wpdb->get_results( $sql, ARRAY_A );
+ if ( $lead_interests ) {
+ foreach ( $lead_interests as $interest ) {
+ $lead_ints[] = $interest['id'];
+ }
+ }
+ 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']
+ = ( isset( $lead_ints[$key] ) ) ? 1 : 0;
+ }
+ }
+ }
+ }
+ // Compile template data
+ $templateData = array(
+ 'entry' => $entry,
+ 'lead_interests' => $lead_interests,
+ 'grouped_interests' => $grouped_interests,
+ );
+ break;
+
+ default:
+ 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']
+ = ( isset( $search_params['interests'][$key] ) && $search_params['interests'][$key] ) ? 1 : 0;
+ }
}
}
}
+ $view = 'index.html';
+ // Compile template data
+ $templateData = array(
+ 'search_params' => $search_params,
+ 'request' => print_r( $_REQUEST, true ),
+ 'leads' => $leads,
+ 'grouped_interests' => $grouped_interests,
+ );
+ break;
}
- // Compile template data
- $templateData = array(
- '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
return array(
'status' => true,
'modelRedirect' => false,
- 'view' => 'admin/leads/index.html',
+ 'view' => 'admin/leads/' . $view,
'data' => $templateData
);
--- /dev/null
+{include file='admin/leads/header.html'}
+
+{if $entry.status}
+<form action="{$thisUrl}?page={$thisPage}" method="post">
+ <input type="hidden" name="glm_action" value="{$thisAction}" />
+ <input type="hidden" name="option" value="update" />
+ <input type="hidden" name="entry" value="{$entry.fieldData.id}" />
+ <input type="hidden" name="lead_id" value="{$entry.fieldData.lead_id.value}" />
+ <table class="glm-admin-table glm-lead-table">
+ <tr>
+ <th>Company</th>
+ <td><input type="text" name="org" value="{$entry.fieldData.org}" /></td>
+ </tr>
+ <tr>
+ <th>First Name</th>
+ <td><input type="text" name="fname" value="{$entry.fieldData.fname}" /></td>
+ </tr>
+ <tr>
+ <th>Last Name</th>
+ <td><input type="text" name="lname" value="{$entry.fieldData.lname}" /></td>
+ </tr>
+ <tr>
+ <th>Address 1</th>
+ <td><input type="text" name="addr1" value="{$entry.fieldData.addr1}" /></td>
+ </tr>
+ <tr>
+ <th>Address 2</th>
+ <td><input type="text" name="addr2" value="{$entry.fieldData.addr2}" /></td>
+ </tr>
+ <tr>
+ <th>City</th>
+ <td><input type="text" name="city" value="{$entry.fieldData.city}" /></td>
+ </tr>
+ <tr>
+ <th>State</th>
+ <td><input type="text" name="state" value="{$entry.fieldData.state}" /></td>
+ </tr>
+ <tr>
+ <th>ZIP</th>
+ <td><input type="text" name="zip" value="{$entry.fieldData.zip}" /></td>
+ </tr>
+ <tr>
+ <th>Country</th>
+ <td><input type="text" name="country" value="{$entry.fieldData.country}" /></td>
+ </tr>
+ <tr>
+ <th>Phone</th>
+ <td><input type="text" name="phone" value="{$entry.fieldData.phone}" /></td>
+ </tr>
+ <tr>
+ <th>Phone 2</th>
+ <td><input type="text" name="phone2" value="{$entry.fieldData.phone2}" /></td>
+ </tr>
+ <tr>
+ <th>Fax</th>
+ <td><input type="text" name="fax" value="{$entry.fieldData.fax}" /></td>
+ </tr>
+ <tr>
+ <td colspan="2">
+ {foreach $grouped_interests as $group_name => $group}
+ <div>
+ <strong>{$group_name}</strong>
+ {foreach $group as $interest}
+ <div>
+ <label><input type="checkbox" name="interests[{$interest.id}]" {if $interest.selected} checked{/if}>{$interest.title}</label>
+ </div>
+ {/foreach}
+ </div>
+ {/foreach}
+ </td>
+ </tr>
+ <tr>
+ <td colspan="2"><input type="submit" value="Update Lead"></td>
+ </tr>
+ </table>
+</form>
+{/if}
+
+{include file='admin/footer.html'}