*/
public function modelAction($actionData = false)
{
+ $forms = false;
+ $form = false;
+ $result = false;
+ $sources = false;
+ $option2 = false;
+ $option = false;
+ $form_id = false;
+ $import_fields = false;
+ $importing = false;
+
// Grab data from the Sources table
$sources = $this->wpdb->get_results(
"SELECT *
$option2 = $_REQUEST['option2'];
}
- switch( $option ) {
+ if ( isset( $_REQUEST['form_id'] ) ) {
+ $form_id = filter_var( $_REQUEST['form_id'], FILTER_VALIDATE_INT );
+ }
+
+ if ( isset( $_REQUEST['importing'] ) ) {
+ $importing = filter_var( $_REQUEST['importing'], FILTER_VALIDATE_BOOLEAN );
+ }
+
+
+ switch( $option2 ) {
case 'import':
- $result = '<pre>$_REQUEST: ' . print_r($_REQUEST, true) . '</pre>';
+ if ( isset( $_REQUEST['form_id'] ) ) {
+ $form_id = filter_var( $_REQUEST['form_id'], FILTER_VALIDATE_INT );
+ $result = '<pre>$_REQUEST: ' . print_r( $_REQUEST, true ) . '</pre>';
+ }
+ if ( $form_id ) {
+ $form = GFAPI::get_form( $form_id );
+ $result = '<pre>$form: ' . print_r( $form, true ) . '</pre>';
+ //$result = '<pre>$_REQUEST: ' . print_r( $_REQUEST, true ) . '</pre>';
+ }
+ if ( $importing ) {
+ /*
+ * If they import-fields are being posted then save as
+ * wordpress option. Using update_option here incase the option
+ * already exists.
+ */
+ update_option( GLM_MEMBERS_LEADS_PLUGIN_IMPORT_OPTION, serialize( $_REQUEST['import_fields'] ) );
+
+ // try to get import fields options
+ $import_fields = unserialize( get_option( GLM_MEMBERS_LEADS_PLUGIN_IMPORT_OPTION, false ) );
+
+ // go through the $import_fields array and find all fields
+ // that are needed for the import
+ $import_fields = array_filter( $import_fields );
+
+
+ $search_criteria = array( 'status' => 'active' );
+ $sorting = array();
+ $paging = array( 'offset' => 0, 'page_size' => 100 );
+ $total_count = 0;
+ $entries = GFAPI::get_entries( $form_id, $search_criteria, $sorting, $paging, $total_count );
+ $result = '<pre>$import_fields: ' . print_r( $import_fields, true ) . '</pre>';
+ $result .= '<p>Total County: ' . $total_count . '</p>';
+ $result .= '<pre>$entries: ' . print_r( $entries, true ) . '</pre>';
+ if ( $entries ) {
+ foreach ( $entries as $entry ) {
+ $lead_entry = array(
+ 'fname' => '',
+ 'lname' => '',
+ 'org' => '',
+ 'addr1' => '',
+ 'addr2' => '',
+ 'city' => '',
+ 'state' => '',
+ 'zip' => '',
+ 'country' => '',
+ 'email' => '',
+ 'phone' => '',
+ 'phone2' => '',
+ 'fax' => '',
+ 'mail_ok' => '',
+ 'member_ok' => ''
+ );
+ }
+ }
+ } else {
+ // try to get import fields options
+ $import_fields = unserialize( get_option( GLM_MEMBERS_LEADS_PLUGIN_IMPORT_OPTION, false ) );
+ }
break;
+
default:
+ $forms = GFAPI::get_forms();
+ $result = '<pre>$forms: ' . print_r( $forms, true ) . '</pre>';
break;
}
// Compile template data
$templateData = array(
- 'sources' => $sources,
- 'option2' => $option2,
- 'result' => $result,
+ 'import_fields' => $import_fields,
+ 'importing' => $importing,
+ 'form' => $form,
+ 'forms' => $forms,
+ 'sources' => $sources,
+ 'option2' => $option2,
+ 'result' => $result,
);
// Return status, suggested view, and data to controller
<a id="glm-leads-import" data-show-table="glm-table-import" class="glm-settings-tab nav-tab">Gravity Forms</a>
</h2>
-<table id="glm-table-sources" class="glm-admin-table glm-settings-table{if $option2!=''} glm-hidden{/if}">
+<table id="glm-table-sources" class="glm-admin-table glm-settings-table{if $option2 != ''} glm-hidden{/if}">
<tr>
<th> Form Id </th>
<th> Source Name </th>
{/foreach}
</table>
+<form action="{$thisUrl}?page={$thisPage}&glm_action=leads&option=import&option2=import" method="post">
+ <input type="hidden" name="importing" value="1" />
+ <input type="hidden" name="glm_action" value="leads" />
+ <input type="hidden" name="option" value="import" />
+ <input type="hidden" name="option2" value="import" />
+ <input type="hidden" name="form_id" value="{$form.id}" />
<table id="glm-table-import" class="glm-admin-table glm-settings-table{if $option2 != import} glm-hidden{/if}">
+ {if $forms}
<tr>
- <td><a href="{$thisUrl}?page={$thisPage}&glm_action=leads&option=import&option2=import" class="button">Import Gravity Form</a></td>
+ <td>
+ <table>
+ <thead>
+ <th>Form Id</th>
+ <th>Title</th>
+ <th>version</th>
+ </thead>
+ <tbody>
+ {foreach $forms as $form_list}
+ <tr>
+ <td> {$form_list.id} </td>
+ <td> <a href="{$thisUrl}?page={$thisPage}&glm_action=leads&option=import&option2=import&form_id={$form_list.id}">{$form_list.title}</a> </td>
+ <td> {$form_list.version} </td>
+ </tr>
+ {/foreach}
+ <tbody>
+ </table>
+ </td>
</tr>
+ {/if}
+ {if $form && !$importing}
+ <tr>
+ <td>
+ <table>
+ <thead>
+ <tr>
+ <th>Field Id</th>
+ <th>Type</th>
+ <th>Label</th>
+ <th>Import Name</th>
+ <th> </th>
+ </tr>
+ </thead>
+ <tbody>
+ {foreach $form.fields as $field}
+ <tr>
+ <td>{$field.id}</td>
+ <td>{$field.type}</td>
+ <td>{$field.label}</td>
+ <td>{if !$fields.inputs.0.id}<input type="text" name="import_fields[{$field.id}]" value="{if $import_fields[$field.id]}{$import_fields[$field.id]}{/if}" />{else} {/if}</td>
+ <td>
+ {if $field.inputs}
+ <table>
+ <tbody>
+ {foreach $field.inputs as $input}
+ {if !$input.isHidden}
+ <tr>
+ <td>
+ <label>{$input.label}</label><br>
+ <input type="text" name="import_fields[{$input.id}]" value="{if $import_fields[$input.id]}{$import_fields[$input.id]}{/if}" />
+ </td>
+ </tr>
+ {/if}
+ {/foreach}
+ </tbody>
+ </table>
+ {/if}
+ {if $field.choices && $field.type == 'checkbox'}
+ <table>
+ <thead>
+ <tr>
+ <th>Choices</th>
+ </tr>
+ </thead>
+ <tbody>
+ {foreach $field.choices as $choice}
+ <tr>
+ <td>{$choice.text}</td>
+ </tr>
+ {/foreach}
+ </tbody>
+ </table>
+ {/if}
+ </td>
+ </tr>
+ {/foreach}
+ </tbody>
+ </table>
+ </td>
+ </tr>
+ <tr>
+ <td><input type="submit" value="Submit" /></td>
+ </tr>
+ {/if}
+ {if $import_fields}
+ {php}
+ echo '<pre>' . print_r( $import_fields, true ) . '</pre>';
+ {/php}
+ {/if}
{if $result}
<tr>
<td>{$result}</td>
</tr>
{/if}
</table>
+</form>
<script>
jQuery(document).ready(function($){