Add gravity flow demo
This commit is contained in:
@@ -0,0 +1,177 @@
|
||||
<?php
|
||||
/**
|
||||
* Gravity Flow Activity List
|
||||
*
|
||||
* @package GravityFlow
|
||||
* @subpackage Classes/Gravity_Flow
|
||||
* @copyright Copyright (c) 2015-2018, Steven Henty S.L.
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
|
||||
*/
|
||||
|
||||
if ( ! class_exists( 'GFForms' ) ) {
|
||||
die();
|
||||
}
|
||||
|
||||
/**
|
||||
* Class Gravity_Flow_Activity_List
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
class Gravity_Flow_Activity_List {
|
||||
|
||||
/**
|
||||
* Displays the activity list.
|
||||
*
|
||||
* @param array $args The page arguments.
|
||||
*/
|
||||
public static function display( $args ) {
|
||||
|
||||
$defaults = array(
|
||||
'check_permissions' => true,
|
||||
'detail_base_url' => admin_url( 'admin.php?page=gravityflow-inbox&view=entry' ),
|
||||
);
|
||||
|
||||
$args = array_merge( $defaults, $args );
|
||||
|
||||
if ( $args['check_permissions'] && ! GFAPI::current_user_can_any( 'gravityflow_activity' ) ) {
|
||||
esc_html_e( "You don't have permission to view this page", 'gravityflow' );
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @since 2.0.2
|
||||
*
|
||||
* Allows the limit for events to be modified before events are displayed on the activity page.
|
||||
*
|
||||
* @param int $limit The limit of events.
|
||||
*/
|
||||
$limit = (int) apply_filters( 'gravityflow_event_limit_activity_page', 400 );
|
||||
|
||||
$events = Gravity_Flow_Activity::get_events( $limit );
|
||||
|
||||
if ( sizeof( $events ) > 0 ) {
|
||||
?>
|
||||
|
||||
<table id="gravityflow-activity" class="widefat" cellspacing="0" style="border:0px;">
|
||||
<thead>
|
||||
<tr>
|
||||
<th data-label="<?php esc_html_e( 'Event ID', 'gravityflow' ); ?>"><?php esc_html_e( 'Event ID', 'gravityflow' ); ?></th>
|
||||
<th><?php esc_html_e( 'Date', 'gravityflow' ); ?></th>
|
||||
<th><?php esc_html_e( 'Form', 'gravityflow' ); ?></th>
|
||||
<th><?php esc_html_e( 'Entry ID', 'gravityflow' ); ?></th>
|
||||
<th><?php esc_html_e( 'Type', 'gravityflow' ); ?></th>
|
||||
<th><?php esc_html_e( 'Event', 'gravityflow' ); ?></th>
|
||||
<th><?php esc_html_e( 'Step', 'gravityflow' ); ?></th>
|
||||
<th><?php esc_html_e( 'Duration', 'gravityflow' ); ?></th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody class="list:user user-list">
|
||||
<?php
|
||||
foreach ( $events as $event ) {
|
||||
$form = GFAPI::get_form( $event->form_id );
|
||||
$base_url = $args['detail_base_url'];
|
||||
$url_entry = $base_url . sprintf( '&id=%d&lid=%d', $event->form_id, $event->lead_id );
|
||||
$url_entry = esc_url_raw( $url_entry );
|
||||
$link = "<a href='%s'>%s</a>";
|
||||
?>
|
||||
<tr>
|
||||
<td data-label="<?php esc_html_e( 'ID', 'gravityflow' ); ?>">
|
||||
<?php
|
||||
echo esc_html( $event->id );
|
||||
?>
|
||||
</td>
|
||||
<td data-label="<?php esc_html_e( 'Date', 'gravityflow' ); ?>">
|
||||
<?php
|
||||
echo esc_html( GFCommon::format_date( $event->date_created ) );
|
||||
?>
|
||||
</td>
|
||||
<td data-label="<?php esc_html_e( 'Form', 'gravityflow' ); ?>">
|
||||
<?php
|
||||
printf( $link, $url_entry, $form['title'] );
|
||||
?>
|
||||
</td>
|
||||
<td data-label="<?php esc_html_e( 'Entry ID', 'gravityflow' ); ?>">
|
||||
<?php
|
||||
printf( $link, $url_entry, $event->lead_id );
|
||||
?>
|
||||
</td>
|
||||
<td data-label="<?php esc_html_e( 'Type', 'gravityflow' ); ?>">
|
||||
<?php
|
||||
echo esc_html( $event->log_object );
|
||||
?>
|
||||
</td>
|
||||
<td data-label="<?php esc_html_e( 'Event', 'gravityflow' ); ?>">
|
||||
<?php
|
||||
switch ( $event->log_object ) {
|
||||
case 'workflow' :
|
||||
echo $event->log_event;
|
||||
break;
|
||||
case 'step' :
|
||||
echo esc_html( $event->log_event );
|
||||
break;
|
||||
case 'assignee' :
|
||||
echo esc_html( $event->display_name ) . ' <i class="fa fa-arrow-right"></i> ' . esc_html( $event->log_value );
|
||||
break;
|
||||
default :
|
||||
echo esc_html( $event->log_value );
|
||||
}
|
||||
|
||||
?>
|
||||
</td>
|
||||
<td data-label="<?php esc_html_e( 'Step', 'gravityflow' ); ?>">
|
||||
<?php
|
||||
if ( $event->feed_id ) {
|
||||
$step = gravity_flow()->get_step( $event->feed_id );
|
||||
if ( $step ) {
|
||||
$step_name = $step->get_name();
|
||||
echo esc_html( $step_name );
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
</td>
|
||||
<td data-label="<?php esc_html_e( 'Event', 'gravityflow' ); ?>">
|
||||
<?php
|
||||
if ( ! empty( $event->duration ) ) {
|
||||
|
||||
echo self::format_duration( $event->duration );
|
||||
}
|
||||
?>
|
||||
</td>
|
||||
|
||||
</tr>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<?php
|
||||
} else {
|
||||
?>
|
||||
<div id="gravityflow-no-activity-container">
|
||||
|
||||
<div id="gravityflow-no-activity-content">
|
||||
<i class="fa fa-spinner fa-pulse fa-3x fa-fw"></i>
|
||||
<br /><br />
|
||||
<?php esc_html_e( 'Waiting for workflow activity', 'gravityflow' ); ?>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats the duration for display.
|
||||
*
|
||||
* @param int $seconds The event duration.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function format_duration( $seconds ) {
|
||||
return gravity_flow()->format_duration( $seconds );
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,844 @@
|
||||
<?php
|
||||
/**
|
||||
* Gravity Flow Entry Editor
|
||||
*
|
||||
* @package GravityFlow
|
||||
* @subpackage Classes/Gravity_Flow_Entry_Editor
|
||||
* @copyright Copyright (c) 2015-2018, Steven Henty S.L.
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
|
||||
* @since 1.2.0.30
|
||||
*/
|
||||
|
||||
if ( ! class_exists( 'GFForms' ) ) {
|
||||
die();
|
||||
}
|
||||
|
||||
/**
|
||||
* Class Gravity_Flow_Entry_Editor
|
||||
*/
|
||||
class Gravity_Flow_Entry_Editor {
|
||||
|
||||
/**
|
||||
* The Gravity Forms form array.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $form;
|
||||
|
||||
/**
|
||||
* The Gravity Forms Entry array.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $entry;
|
||||
|
||||
/**
|
||||
* The current step.
|
||||
*
|
||||
* @var Gravity_Flow_Step $step
|
||||
*/
|
||||
public $step;
|
||||
|
||||
/**
|
||||
* Used to help determine whether to display the order summary.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $has_product_fields = false;
|
||||
|
||||
/**
|
||||
* Flag set in the constructor to control the visibility of empty fields.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $display_empty_fields;
|
||||
|
||||
/**
|
||||
* Indicates if dynamic conditional logic is enabled.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $_is_dynamic_conditional_logic_enabled;
|
||||
|
||||
/**
|
||||
* An array of field IDs which the user can edit.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $_editable_fields;
|
||||
|
||||
/**
|
||||
* An array of field IDs of display fields.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $_display_fields = array();
|
||||
|
||||
/**
|
||||
* An array of field IDs required for use with calculations.
|
||||
*
|
||||
* @since 1.7.1-dev
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $_calculation_dependencies = array();
|
||||
|
||||
/**
|
||||
* The content to be displayed for the display fields.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $_non_editable_field_content = array();
|
||||
|
||||
/**
|
||||
* The init scripts to be deregistered.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $_non_editable_field_script_names = array();
|
||||
|
||||
/**
|
||||
* The Form Object after the non-editable and non-display fields have been removed.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $_modified_form;
|
||||
|
||||
/**
|
||||
* Used to help determine whether the gform_product_total script should be output for the coupon field.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $_has_editable_product_field = false;
|
||||
|
||||
/**
|
||||
* Gravity_Flow_Entry_Editor constructor.
|
||||
*
|
||||
* @param array $form The current form.
|
||||
* @param array $entry The current entry.
|
||||
* @param Gravity_Flow_Step $step The current step.
|
||||
* @param bool $display_empty_fields Indicates if empty fields should be displayed.
|
||||
*/
|
||||
public function __construct( $form, $entry, $step, $display_empty_fields ) {
|
||||
$this->form = $form;
|
||||
$this->entry = $entry;
|
||||
$this->step = $step;
|
||||
$this->display_empty_fields = $display_empty_fields;
|
||||
$this->_is_dynamic_conditional_logic_enabled = $this->is_dynamic_conditional_logic_enabled();
|
||||
$this->_editable_fields = $step->get_editable_fields();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Renders the form. Uses GFFormDisplay::get_form() to display the fields.
|
||||
*/
|
||||
public function render_edit_form() {
|
||||
$this->add_hooks();
|
||||
|
||||
// Impersonate front-end form.
|
||||
unset( $_GET['page'] );
|
||||
|
||||
require_once( GFCommon::get_base_path() . '/form_display.php' );
|
||||
|
||||
$html = GFFormDisplay::get_form( $this->form['id'], false, false, true, $this->entry );
|
||||
|
||||
$this->remove_hooks();
|
||||
|
||||
echo $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the filters and actions required to modify the form markup for this step.
|
||||
*/
|
||||
public function add_hooks() {
|
||||
add_filter( 'gform_pre_render', array( $this, 'filter_gform_pre_render' ), 999 );
|
||||
add_filter( 'gform_submit_button', '__return_empty_string' );
|
||||
add_filter( 'gform_disable_view_counter', '__return_true' );
|
||||
add_filter( 'gform_field_input', array( $this, 'filter_gform_field_input' ), 10, 2 );
|
||||
add_filter( 'gform_form_tag', '__return_empty_string' );
|
||||
add_filter( 'gform_get_form_filter', array( $this, 'filter_gform_get_form_filter' ) );
|
||||
add_filter( 'gform_field_container', array( $this, 'filter_gform_field_container' ), 10, 2 );
|
||||
add_filter( 'gform_has_conditional_logic', array( $this, 'filter_gform_has_conditional_logic' ), 10, 2 );
|
||||
add_filter( 'gform_field_css_class', array( $this, 'filter_gform_field_css_class' ), 10, 2 );
|
||||
|
||||
add_action( 'gform_register_init_scripts', array( $this, 'deregsiter_init_scripts' ), 11 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the filters and actions.
|
||||
*/
|
||||
public function remove_hooks() {
|
||||
remove_filter( 'gform_pre_render', array( $this, 'filter_gform_pre_render' ), 999 );
|
||||
remove_filter( 'gform_submit_button', '__return_empty_string' );
|
||||
remove_filter( 'gform_disable_view_counter', '__return_true' );
|
||||
remove_filter( 'gform_field_input', array( $this, 'filter_gform_field_input' ), 10 );
|
||||
remove_filter( 'gform_form_tag', '__return_empty_string' );
|
||||
remove_filter( 'gform_get_form_filter', array( $this, 'filter_gform_get_form_filter' ) );
|
||||
remove_filter( 'gform_field_container', array( $this, 'filter_gform_field_container' ), 10 );
|
||||
remove_filter( 'gform_has_conditional_logic', array( $this, 'filter_gform_has_conditional_logic' ), 10 );
|
||||
remove_filter( 'gform_field_css_class', array( $this, 'filter_gform_field_css_class' ), 10 );
|
||||
|
||||
remove_action( 'gform_register_init_scripts', array( $this, 'deregsiter_init_scripts' ), 11 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Target of the gform_pre_render filter.
|
||||
* Removes the page fields from the form.
|
||||
*
|
||||
* @param array $form The current form.
|
||||
*
|
||||
* @return array The filtered form.
|
||||
*/
|
||||
public function filter_gform_pre_render( $form ) {
|
||||
|
||||
if( $form['id'] != rgget( 'id' ) ) {
|
||||
return $form;
|
||||
}
|
||||
|
||||
$form = $this->remove_page_fields( $form );
|
||||
$fields = array();
|
||||
$dynamic_conditional_logic_enabled = $this->_is_dynamic_conditional_logic_enabled;
|
||||
|
||||
/**
|
||||
* Process all other field types.
|
||||
*
|
||||
* @var GF_Field $field
|
||||
*/
|
||||
foreach ( $form['fields'] as $field ) {
|
||||
if ( $field->type == 'section' ) {
|
||||
// Unneeded section fields will be removed via filter_gform_field_container().
|
||||
$field->adminOnly = false;
|
||||
$fields[] = $field;
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( $dynamic_conditional_logic_enabled ) {
|
||||
$conditional_logic_fields = GFFormDisplay::get_conditional_logic_fields( $form, $field->id );
|
||||
$field->conditionalLogicFields = $conditional_logic_fields;
|
||||
}
|
||||
|
||||
$field->gravityflow_is_display_field = $this->is_display_field( $field );
|
||||
|
||||
// Remove unneeded fields from the form to prevent JS errors resulting from scripts expecting fields to be present and visible.
|
||||
if ( $this->can_remove_field( $field ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$is_product_field = GFCommon::is_product_field( $field->type );
|
||||
|
||||
if ( ! $this->has_product_fields && $is_product_field ) {
|
||||
$this->has_product_fields = true;
|
||||
}
|
||||
|
||||
if ( ! $this->is_editable_field( $field ) ) {
|
||||
$content = $this->get_non_editable_field( $field );
|
||||
|
||||
if ( empty( $content ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->_non_editable_field_content[ $field->id ] = $content;
|
||||
$this->_non_editable_field_script_names[] = $field->type . '_' . $field->id;
|
||||
|
||||
if ( $field->type == 'tos' ) {
|
||||
$field->gwtermsofservice_require_scroll = false;
|
||||
}
|
||||
|
||||
$field->description = null;
|
||||
$field->maxLength = null;
|
||||
} else {
|
||||
$field->gravityflow_is_editable = true;
|
||||
if ( ! $this->_has_editable_product_field && $is_product_field && $field->type != 'total' ) {
|
||||
$this->_has_editable_product_field = true;
|
||||
}
|
||||
}
|
||||
|
||||
if ( empty( $field->label ) ) {
|
||||
$field->label = $field->adminLabel;
|
||||
}
|
||||
|
||||
$field->adminOnly = false;
|
||||
$field->adminLabel = '';
|
||||
|
||||
if ( $field->type === 'hidden' ) {
|
||||
// Render hidden fields as text fields.
|
||||
$field = new GF_Field_Text( $field );
|
||||
$field->type = 'text';
|
||||
}
|
||||
|
||||
$fields[] = $field;
|
||||
}
|
||||
|
||||
$form['fields'] = $fields;
|
||||
$this->_modified_form = $form;
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the form button logic and page fields so they are not taken into account when processing conditional logic for other fields.
|
||||
* Also disables save and continue.
|
||||
*
|
||||
* @param array $form The form currently being processed.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function remove_page_fields( $form ) {
|
||||
unset( $form['save'] );
|
||||
unset( $form['button']['conditionalLogic'] );
|
||||
|
||||
$dynamic_conditional_logic_enabled = $this->_is_dynamic_conditional_logic_enabled;
|
||||
|
||||
/* @var GF_Field $field */
|
||||
foreach ( $form['fields'] as $key => $field ) {
|
||||
if ( $field->type == 'page' ) {
|
||||
unset( $form['fields'][ $key ] );
|
||||
continue;
|
||||
}
|
||||
|
||||
$is_applicable_field = $this->is_editable_field( $field );
|
||||
|
||||
if ( $is_applicable_field && $field->has_calculation() ) {
|
||||
$this->set_calculation_dependencies( $field->calculationFormula );
|
||||
}
|
||||
|
||||
if ( ! $is_applicable_field ) {
|
||||
// Populate the $_display_fields array.
|
||||
$is_applicable_field = $this->is_display_field( $field, true );
|
||||
}
|
||||
|
||||
if ( ! $dynamic_conditional_logic_enabled || ! $is_applicable_field ) {
|
||||
// Clear the field conditional logic properties as conditional logic is not enabled for the step or the field is not for display or editable.
|
||||
$field->conditionalLogicFields = null;
|
||||
$field->conditionalLogic = null;
|
||||
}
|
||||
}
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the IDs of any fields in the formula to the $_calculation_dependencies array.
|
||||
*
|
||||
* @since 1.7.1-dev
|
||||
*
|
||||
* @param string $formula The calculation formula to be evaluated.
|
||||
*/
|
||||
public function set_calculation_dependencies( $formula ) {
|
||||
if ( empty( $formula ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
preg_match_all( '/{[^{]*?:(\d+).*?}/mi', $formula, $matches, PREG_SET_ORDER );
|
||||
if ( ! empty( $matches ) ) {
|
||||
foreach ( $matches as $match ) {
|
||||
$field_id = rgar( $match, 1 );
|
||||
if ( $field_id && ! $this->is_calculation_dependency( $field_id ) ) {
|
||||
$this->_calculation_dependencies[] = $field_id;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether a field is required for calculations.
|
||||
*
|
||||
* @since 1.7.1-dev
|
||||
*
|
||||
* @param GF_Field|string $field The field object or field ID to be checked.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_calculation_dependency( $field ) {
|
||||
$field_id = is_object( $field ) ? $field->id : $field;
|
||||
|
||||
return in_array( $field_id, $this->_calculation_dependencies );
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the field can be removed from the form object.
|
||||
*
|
||||
* Fields involved in conditional logic must always be added to the form.
|
||||
*
|
||||
* @param GF_Field $field The current field.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function can_remove_field( $field ) {
|
||||
$can_remove_field = ! ( $this->is_editable_field( $field ) || $this->is_display_field( $field ) || $this->is_calculation_dependency( $field ) ) && empty( $field->conditionalLogicFields );
|
||||
|
||||
return $can_remove_field;
|
||||
}
|
||||
|
||||
/**
|
||||
* Target for the gform_field_input filter.
|
||||
*
|
||||
* Handles the construction of the field input. Returns markup for the editable field or the display value.
|
||||
*
|
||||
* @param string $html The field input markup.
|
||||
* @param GF_Field $field The current field.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function filter_gform_field_input( $html, $field ) {
|
||||
|
||||
if ( ! $this->is_editable_field( $field ) ) {
|
||||
return rgar( $this->_non_editable_field_content, $field->id );
|
||||
}
|
||||
|
||||
if ( ! empty( $html ) ) {
|
||||
// the field input has already been set via the gform_field_input filter. e.g. the Signature Add-On < v3.
|
||||
return $html;
|
||||
}
|
||||
|
||||
$posted_form_id = rgpost( 'gravityflow_submit' );
|
||||
if ( $posted_form_id == $this->form['id'] && rgpost( 'step_id' ) == $this->step->get_id() ) {
|
||||
// Updated or failed validation.
|
||||
$value = GFFormsModel::get_field_value( $field );
|
||||
} else {
|
||||
$value = GFFormsModel::get_lead_field_value( $this->entry, $field );
|
||||
if ( $field->get_input_type() == 'email' && $field->emailConfirmEnabled ) {
|
||||
$_POST[ 'input_' . $field->id . '_2' ] = $value;
|
||||
}
|
||||
|
||||
if ( $field->get_input_type() == 'multiselect' && $field->storageType === 'json' ) {
|
||||
$value = json_decode( $value, true );
|
||||
}
|
||||
}
|
||||
|
||||
if ( $field->get_input_type() == 'fileupload' ) {
|
||||
$field->_is_entry_detail = true;
|
||||
}
|
||||
|
||||
$value = apply_filters( 'gravityflow_field_value_entry_editor', $value, $field, $this->form, $this->entry, $this->step );
|
||||
|
||||
$value = $this->get_post_image_value( $value, $field );
|
||||
$value = $this->get_post_category_value( $value, $field );
|
||||
|
||||
$html = $field->get_field_input( $this->form, $value, $this->entry );
|
||||
$html .= $this->maybe_get_coupon_script( $field );
|
||||
|
||||
if ( $field->type === 'chainedselect' && function_exists( 'gf_chained_selects' ) ) {
|
||||
if ( ! wp_script_is( 'gform_chained_selects' ) ) {
|
||||
wp_enqueue_script( 'gform_chained_selects' );
|
||||
gf_chained_selects()->localize_scripts();
|
||||
}
|
||||
|
||||
if ( ! $this->_is_dynamic_conditional_logic_enabled && wp_script_is( 'gform_conditional_logic' ) ) {
|
||||
$script = "if ( typeof window.gf_form_conditional_logic === 'undefined' ) { window.gf_form_conditional_logic = []; }";
|
||||
GFFormDisplay::add_init_script( $field->formId, 'conditional_logic', GFFormDisplay::ON_PAGE_RENDER, $script );
|
||||
}
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures the post image field value is in the correct format for populating the field.
|
||||
*
|
||||
* @since 2.1.2-dev
|
||||
*
|
||||
* @param string|array $value The field value.
|
||||
* @param GF_Field $field The current field object.
|
||||
*
|
||||
* @return string|array
|
||||
*/
|
||||
public function get_post_image_value( $value, $field ) {
|
||||
if ( $field->type !== 'post_image' || empty( $value ) || ! is_string( $value ) || strpos( $value, '|:|' ) === false ) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
$array = explode( '|:|', $value );
|
||||
$value = array(
|
||||
$field->id . '.1' => rgar( $array, 1 ), // Title.
|
||||
$field->id . '.4' => rgar( $array, 2 ), // Caption.
|
||||
$field->id . '.7' => rgar( $array, 3 ), // Description.
|
||||
);
|
||||
|
||||
$path_info = pathinfo( rgar( $array, 0 ) );
|
||||
if ( ! isset( GFFormsModel::$uploaded_files[ $field->formId ]["input_{$field->id}"] ) ) {
|
||||
GFFormsModel::$uploaded_files[ $field->formId ]["input_{$field->id}"] = $path_info['basename'];
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures the post category field value is in the correct format for populating the field.
|
||||
*
|
||||
* @since 2.1.1-dev
|
||||
*
|
||||
* @param string|array $value The field value.
|
||||
* @param GF_Field $field The current field object.
|
||||
*
|
||||
* @return string|array
|
||||
*/
|
||||
public function get_post_category_value( $value, $field ) {
|
||||
if ( $field->type !== 'post_category' || empty( $value ) ) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
if ( is_array( $value ) ) {
|
||||
foreach ( $value as $key => $item ) {
|
||||
if ( ! empty( $item ) ) {
|
||||
$value[ $key ] = $this->get_post_category_id( $item );
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$value = $this->get_post_category_id( $value );
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the post category id from the supplied value.
|
||||
*
|
||||
* The entry value will be in the format "category_name:category_id".
|
||||
*
|
||||
* @since 2.1.1-dev
|
||||
*
|
||||
* @param string $value The field value.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_post_category_id( $value ) {
|
||||
$parts = explode( ':', $value );
|
||||
|
||||
return isset( $parts[1] ) ? $parts[1] : $parts[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the gform_product_total script for the coupon field when there aren't any editable product fields.
|
||||
*
|
||||
* @param GF_Field $field The field currently being processed.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function maybe_get_coupon_script( $field ) {
|
||||
if ( $field->type != 'coupon' || $this->_has_editable_product_field ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$total = GFCommon::get_order_total( $this->form, $this->entry );
|
||||
|
||||
return "<script type='text/javascript'>gform.addFilter('gform_product_total', function (total, formId) {return {$total};}, 49);</script>";
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether dynamic conditional logic is enabled.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_dynamic_conditional_logic_enabled() {
|
||||
return $this->step && $this->step->conditional_logic_editable_fields_enabled && $this->step->conditional_logic_editable_fields_mode != 'page_load' && gravity_flow()->fields_have_conditional_logic( $this->form );
|
||||
}
|
||||
|
||||
/**
|
||||
* Target for the gform_get_form_filter filter.
|
||||
* Strips the closing form tag and replaces the Gravity Forms token for Gravity Flow's token.
|
||||
*
|
||||
* @param string $form_string The form markup.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function filter_gform_get_form_filter( $form_string ) {
|
||||
$form_string = str_replace( 'gform_submit', 'gravityflow_submit', $form_string );
|
||||
$form_string = str_replace( '</form>', '', $form_string );
|
||||
|
||||
return $form_string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates and returns the markup for a display field.
|
||||
*
|
||||
* @param GF_Field $field The current field object.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_non_editable_field( $field ) {
|
||||
|
||||
if ( $field->type == 'html' ) {
|
||||
$html = GFCommon::replace_variables( $field->content, $this->form, $this->entry, false, true, false, 'html' );
|
||||
$html = do_shortcode( $html );
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
$html = '';
|
||||
|
||||
$value = RGFormsModel::get_lead_field_value( $this->entry, $field );
|
||||
|
||||
$conditional_logic_dependency = $this->_is_dynamic_conditional_logic_enabled && ! empty( $field->conditionalLogicFields );
|
||||
|
||||
if ( $conditional_logic_dependency || $this->is_calculation_dependency( $field ) ) {
|
||||
$html = $field->get_field_input( $this->form, $value, $this->entry );
|
||||
}
|
||||
|
||||
if ( ! $this->is_display_field( $field ) ) {
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
if ( $html ) {
|
||||
$html = '<div style="display:none;">' . $html . '</div>';
|
||||
}
|
||||
|
||||
$value = $this->maybe_get_product_calculation_value( $value, $field );
|
||||
|
||||
$input_type = $field->get_input_type();
|
||||
if ( $input_type == 'hiddenproduct' ) {
|
||||
$display_value = $value[ $field->id . '.2' ];
|
||||
} else {
|
||||
$display_value = GFCommon::get_lead_field_display( $field, $value, $this->entry['currency'] );
|
||||
}
|
||||
|
||||
$display_value = apply_filters( 'gform_entry_field_value', $display_value, $field, $this->entry, $this->form );
|
||||
|
||||
if ( $this->display_empty_fields ) {
|
||||
if ( empty( $display_value ) || $display_value === '0' ) {
|
||||
$display_value = ' ';
|
||||
}
|
||||
$display_value = sprintf( '<div class="gravityflow-field-value">%s<div>', $display_value );
|
||||
} else {
|
||||
if ( empty( $display_value ) || $display_value === '0' ) {
|
||||
$display_value = '';
|
||||
} else {
|
||||
$display_value = sprintf( '<div class="gravityflow-field-value">%s<div>', $display_value );
|
||||
}
|
||||
}
|
||||
|
||||
$html .= $display_value;
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* If this is a calculated product field ensure the input values are set.
|
||||
*
|
||||
* @param mixed $value The field value.
|
||||
* @param GF_Field $field The current field object.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function maybe_get_product_calculation_value( $value, $field ) {
|
||||
if ( $field->type == 'product' && $field->has_calculation() ) {
|
||||
$product_name = trim( $value[ $field->id . '.1' ] );
|
||||
$price = trim( $value[ $field->id . '.2' ] );
|
||||
$quantity = trim( $value[ $field->id . '.3' ] );
|
||||
|
||||
if ( empty( $product_name ) ) {
|
||||
$value[ $field->id . '.1' ] = $field->get_field_label( false, $value );
|
||||
}
|
||||
|
||||
if ( empty( $price ) ) {
|
||||
$value[ $field->id . '.2' ] = '0';
|
||||
}
|
||||
|
||||
if ( empty( $quantity ) ) {
|
||||
$value[ $field->id . '.3' ] = '0';
|
||||
}
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the given field is a display field and whether it should be displayed.
|
||||
*
|
||||
* @param GF_Field $field The field to be checked.
|
||||
* @param bool $is_init Return after checking the $_display_fields array? Default is false.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_display_field( $field, $is_init = false ) {
|
||||
if ( in_array( $field->id, $this->_display_fields ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( ! $is_init ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$display_field = Gravity_Flow_Common::is_display_field( $field, $this->step, $this->form, $this->entry );
|
||||
|
||||
if ( $display_field ) {
|
||||
$this->_display_fields[] = $field->id;
|
||||
}
|
||||
|
||||
return $display_field;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether a field is an editable field.
|
||||
*
|
||||
* @param GF_Field $field The field to be checked.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_editable_field( $field ) {
|
||||
return Gravity_Flow_Common::is_editable_field( $field, $this->step );
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the current field is hidden.
|
||||
*
|
||||
* @param GF_Field $field The field to be checked.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_hidden_field( $field ) {
|
||||
|
||||
return ! $this->is_editable_field( $field ) && ! $this->is_display_field( $field ) && isset( $this->_non_editable_field_content[ $field->id ] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the display mode is selected_fields and that all this sections fields are hidden.
|
||||
*
|
||||
* @param GF_Field[] $section_fields The fields located in the current section.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function section_fields_hidden( $section_fields ) {
|
||||
if ( $this->step->display_fields_mode == 'selected_fields' ) {
|
||||
foreach ( $section_fields as $field ) {
|
||||
if ( ! $this->is_hidden_field( $field ) ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the section should be hidden for the given section field.
|
||||
*
|
||||
* Hidden sections contain no editable fields and no non-empty display fields.
|
||||
*
|
||||
* @param GF_Field_Section $section_field The current section field.
|
||||
* @param GF_Field[] $section_fields The fields located in the current section.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_section_hidden( $section_field, $section_fields ) {
|
||||
if ( ! empty( $section_fields ) ) {
|
||||
foreach ( $section_fields as $field ) {
|
||||
if ( $this->is_editable_field( $field ) || $this->is_display_field( $field ) ) {
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if ( $this->step->display_fields_mode == 'all_fields' ) {
|
||||
|
||||
return GFCommon::is_section_empty( $section_field, $this->_modified_form, $this->entry ) || ! $this->display_empty_fields;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve an array of fields located within the specified section.
|
||||
*
|
||||
* @param int $section_field_id The ID of the current section field.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_section_fields( $section_field_id ) {
|
||||
$section_fields = GFCommon::get_section_fields( $this->_modified_form, $section_field_id );
|
||||
if ( count( $section_fields ) >= 1 ) {
|
||||
// Remove the section field.
|
||||
unset( $section_fields[0] );
|
||||
}
|
||||
|
||||
return $section_fields;
|
||||
}
|
||||
|
||||
/**
|
||||
* Target for the gform_field_container filter.
|
||||
*
|
||||
* Removes the markup completely for section fields that are hidden.
|
||||
*
|
||||
* Fields with conditional logic remain on the form to avoid JS errors.
|
||||
*
|
||||
* @param string $field_container The field container HTML.
|
||||
* @param GF_Field $field The current field object.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function filter_gform_field_container( $field_container, $field ) {
|
||||
if ( $field->type == 'section' ) {
|
||||
$section_fields = $this->get_section_fields( $field->id );
|
||||
|
||||
if ( $this->section_fields_hidden( $section_fields )
|
||||
|| ( $this->is_section_hidden( $field, $section_fields ) && empty( $field->conditionalLogic ) ) // Section fields with conditional logic must be added to the form so fields inside the section can be hidden or displayed dynamically.
|
||||
) {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
if ( $this->is_hidden_field( $field ) ) {
|
||||
$field_container = sprintf( '<li id="field_%s_%s" style="display:none;">%s</li>', $field->formId, $field->id, $this->_non_editable_field_content[ $field->id ] );
|
||||
}
|
||||
|
||||
return $field_container;
|
||||
}
|
||||
|
||||
/**
|
||||
* Target for the gform_has_conditional_logic filter.
|
||||
*
|
||||
* Checks the conditional logic setting and configures the form accordingly.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function filter_gform_has_conditional_logic() {
|
||||
|
||||
return $this->_is_dynamic_conditional_logic_enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Target for the gform_field_css_class filter.
|
||||
*
|
||||
* Checks the step settings and adds the appropriate classes.
|
||||
*
|
||||
* @param string $classes The field classes.
|
||||
* @param GF_Field $field The current field object.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function filter_gform_field_css_class( $classes, $field ) {
|
||||
$is_editable = $this->is_editable_field( $field );
|
||||
$class = $is_editable ? 'gravityflow-editable-field' : 'gravityflow-display-field';
|
||||
if ( $is_editable && $this->step->highlight_editable_fields_enabled ) {
|
||||
$class .= ' ' . $this->step->highlight_editable_fields_class;
|
||||
}
|
||||
|
||||
$classes .= ' ' . $class;
|
||||
|
||||
return $classes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deregister init scripts for any non-editable fields to prevent js errors.
|
||||
*
|
||||
* @param array $form The filtered form object.
|
||||
*/
|
||||
public function deregsiter_init_scripts( $form ) {
|
||||
$script_names = $this->_non_editable_field_script_names;
|
||||
if ( ! empty( $script_names ) ) {
|
||||
$init_scripts = GFFormDisplay::$init_scripts[ $form['id'] ];
|
||||
if ( ! empty( $init_scripts ) ) {
|
||||
$location = GFFormDisplay::ON_PAGE_RENDER;
|
||||
foreach ( $script_names as $name ) {
|
||||
unset( $init_scripts[ $name . '_' . $location ] );
|
||||
}
|
||||
GFFormDisplay::$init_scripts[ $form['id'] ] = $init_scripts;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
/**
|
||||
* Gravity Flow Help
|
||||
*
|
||||
* @package GravityFlow
|
||||
* @subpackage Classes/Gravity_Flow
|
||||
* @copyright Copyright (c) 2015-2018, Steven Henty S.L.
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
|
||||
*/
|
||||
|
||||
if ( ! class_exists( 'GFForms' ) ) {
|
||||
die();
|
||||
}
|
||||
|
||||
/**
|
||||
* Class Gravity_Flow_Help
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
class Gravity_Flow_Help {
|
||||
|
||||
/**
|
||||
* Displays the help page content.
|
||||
*/
|
||||
public static function display() {
|
||||
|
||||
?>
|
||||
<div class="wrap gf_entry_wrap">
|
||||
|
||||
<h2 class="gf_admin_page_title">
|
||||
<span><?php esc_html_e( 'Help', 'gravityflow' ); ?></span>
|
||||
</h2>
|
||||
|
||||
<p>
|
||||
First, draw your workflow. If you plan your workflow well, the rest will be straightforward. I can't stress this enough - if you don't plan, you'll very likely find the whole experience very frustrating.
|
||||
</p>
|
||||
<p>
|
||||
List the users or roles involved and identify what each one needs to do and at which stage. Try to separate the process into distinct steps involving approval and user input. You may find it useful to draw the process using a
|
||||
<a href="http://en.wikipedia.org/wiki/Swim_lane">swim lane diagram</a>.
|
||||
</p>
|
||||
<p>
|
||||
Create a form to use for your workflow. This form must contain all the fields used at every step of the process but don't worry if you need to add fields later.
|
||||
</p>
|
||||
<p>
|
||||
Take a look at the
|
||||
<a href="http://docs.gravityflow.io/category/34-walkthroughs">walkthroughs</a> and then dive deeper into the <a href="http://docs.gravityflow.io/category/21-user-guides">user guides</a>.
|
||||
</p>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,462 @@
|
||||
<?php
|
||||
/**
|
||||
* Gravity Flow Inbox
|
||||
*
|
||||
* @package GravityFlow
|
||||
* @subpackage Classes/Gravity_Flow_Inbox
|
||||
* @copyright Copyright (c) 2015-2018, Steven Henty S.L.
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
|
||||
* @since 1.0
|
||||
*/
|
||||
|
||||
if ( ! class_exists( 'GFForms' ) ) {
|
||||
die();
|
||||
}
|
||||
|
||||
/**
|
||||
* Class Gravity_Flow_Inbox
|
||||
*/
|
||||
class Gravity_Flow_Inbox {
|
||||
|
||||
/**
|
||||
* Displays the inbox page.
|
||||
*
|
||||
* @param array $args The inbox page arguments.
|
||||
*/
|
||||
public static function display( $args ) {
|
||||
|
||||
$args = array_merge( self::get_defaults(), $args );
|
||||
|
||||
/**
|
||||
* Allow the inbox page arguments to be overridden.
|
||||
*
|
||||
* @param array $args The inbox page arguments.
|
||||
*/
|
||||
$args = apply_filters( 'gravityflow_inbox_args', $args );
|
||||
|
||||
if ( has_filter( 'gravityflow_inbox_args' ) ) {
|
||||
gravity_flow()->log_debug( __METHOD__ . '(): Executing functions hooked to gravityflow_inbox_args.' );
|
||||
}
|
||||
|
||||
$total_count = 0;
|
||||
$entries = self::get_entries( $args, $total_count );
|
||||
|
||||
gravity_flow()->log_debug( __METHOD__ . "(): {$total_count} pending tasks." );
|
||||
|
||||
if ( sizeof( $entries ) > 0 ) {
|
||||
$columns = self::get_columns( $args );
|
||||
?>
|
||||
|
||||
<table id="gravityflow-inbox" class="widefat gravityflow-inbox" cellspacing="0" style="border:0px;">
|
||||
|
||||
<?php
|
||||
self::display_table_head( $columns );
|
||||
?>
|
||||
|
||||
<tbody class="list:user user-list">
|
||||
<?php
|
||||
foreach ( $entries as $entry ) {
|
||||
self::display_entry_row( $args, $entry, $columns );
|
||||
}
|
||||
?>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<?php
|
||||
if ( $total_count > 150 ) {
|
||||
echo '<br />';
|
||||
echo '<div class="excess_entries_indicator">';
|
||||
printf( '(Showing 150 of %d)', absint( $total_count ) );
|
||||
echo '</div>';
|
||||
}
|
||||
} else {
|
||||
?>
|
||||
<div id="gravityflow-no-pending-tasks-container">
|
||||
<div id="gravityflow-no-pending-tasks-content">
|
||||
<i class="fa fa-check-circle-o gravityflow-inbox-check"></i>
|
||||
<br/><br/>
|
||||
<?php esc_html_e( 'No pending tasks', 'gravityflow' ); ?>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default arguments used when rendering the inbox page.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_defaults() {
|
||||
$field_ids = apply_filters( 'gravityflow_inbox_fields', array() );
|
||||
$filter = apply_filters( 'gravityflow_inbox_filter', array(
|
||||
'form_id' => 0,
|
||||
'start_date' => '',
|
||||
'end_date' => '',
|
||||
) );
|
||||
|
||||
return array(
|
||||
'display_empty_fields' => true,
|
||||
'id_column' => true,
|
||||
'submitter_column' => true,
|
||||
'actions_column' => false,
|
||||
'step_column' => true,
|
||||
'check_permissions' => true,
|
||||
'form_id' => absint( rgar( $filter, 'form_id' ) ),
|
||||
'field_ids' => $field_ids,
|
||||
'detail_base_url' => admin_url( 'admin.php?page=gravityflow-inbox&view=entry' ),
|
||||
'last_updated' => false,
|
||||
'step_highlight' => true,
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the filter key for the current user.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_filter_key() {
|
||||
global $current_user;
|
||||
|
||||
$filter_key = '';
|
||||
|
||||
if ( $current_user->ID > 0 ) {
|
||||
$filter_key = 'workflow_user_id_' . $current_user->ID;
|
||||
} elseif ( $token = gravity_flow()->decode_access_token() ) {
|
||||
$filter_key = gravity_flow()->parse_token_assignee( $token )->get_status_key();
|
||||
}
|
||||
|
||||
return $filter_key;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the entries to be displayed.
|
||||
*
|
||||
* @param array $args The inbox page arguments.
|
||||
* @param int $total_count The total number of entries.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_entries( $args, &$total_count ) {
|
||||
$entries = array();
|
||||
$filter_key = self::get_filter_key();
|
||||
|
||||
gravity_flow()->log_debug( __METHOD__ . '(): $filter_key => ' . $filter_key );
|
||||
|
||||
if ( ! empty( $filter_key ) ) {
|
||||
$field_filters = array();
|
||||
$field_filters[] = array(
|
||||
'key' => $filter_key,
|
||||
'value' => 'pending',
|
||||
);
|
||||
|
||||
$user_roles = gravity_flow()->get_user_roles();
|
||||
foreach ( $user_roles as $user_role ) {
|
||||
$field_filters[] = array(
|
||||
'key' => 'workflow_role_' . $user_role,
|
||||
'value' => 'pending',
|
||||
);
|
||||
}
|
||||
|
||||
$field_filters['mode'] = 'any';
|
||||
|
||||
$search_criteria = array();
|
||||
$search_criteria['field_filters'] = $field_filters;
|
||||
$search_criteria['status'] = 'active';
|
||||
|
||||
$form_ids = $args['form_id'] ? $args['form_id'] : gravity_flow()->get_workflow_form_ids();
|
||||
|
||||
/**
|
||||
* Allows form id(s) to be adjusted to define which forms' entries are displayed in inbox table.
|
||||
*
|
||||
* Return an array of form ids for use with GFAPI.
|
||||
*
|
||||
* @since 2.2.2-dev
|
||||
*
|
||||
* @param array $form_ids The form ids
|
||||
* @param array $search_criteria The search criteria
|
||||
*/
|
||||
$form_ids = apply_filters( 'gravityflow_form_ids_inbox', $form_ids, $search_criteria);
|
||||
|
||||
gravity_flow()->log_debug( __METHOD__ . '(): $form_ids => ' . print_r( $form_ids, 1 ) );
|
||||
gravity_flow()->log_debug( __METHOD__ . '(): $search_criteria => ' . print_r( $search_criteria, 1 ) );
|
||||
|
||||
if ( ! empty( $form_ids ) ) {
|
||||
$paging = array(
|
||||
'page_size' => 150,
|
||||
);
|
||||
|
||||
/**
|
||||
*
|
||||
* @since 2.0.2
|
||||
*
|
||||
* Allows the paging criteria to be modified before entries are searched for the inbox.
|
||||
*
|
||||
* @param array $paging The paging criteria.
|
||||
*/
|
||||
$paging = apply_filters( 'gravityflow_inbox_paging', $paging );
|
||||
|
||||
$sorting = array();
|
||||
|
||||
/**
|
||||
* Allows the sorting criteria to be modified before entries are searched for the inbox.
|
||||
*
|
||||
* @param array $sorting The sorting criteria.
|
||||
*/
|
||||
$sorting = apply_filters( 'gravityflow_inbox_sorting', $sorting );
|
||||
|
||||
/**
|
||||
* Allows the search criteria to be modified before entries are searched for the inbox.
|
||||
*
|
||||
* @since 2.1
|
||||
*
|
||||
* @param array $sorting The search criteria.
|
||||
*/
|
||||
$search_criteria = apply_filters( 'gravityflow_inbox_search_criteria', $search_criteria );
|
||||
|
||||
$entries = GFAPI::get_entries( $form_ids, $search_criteria, $sorting, $paging, $total_count );
|
||||
}
|
||||
}
|
||||
|
||||
return $entries;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the columns to be displayed.
|
||||
*
|
||||
* @param array $args The inbox page arguments.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_columns( $args ) {
|
||||
$columns = array();
|
||||
if ( $args['step_highlight'] ) {
|
||||
$columns['step_highlight'] = 'step_highlight';
|
||||
}
|
||||
|
||||
if ( $args['id_column'] ) {
|
||||
$columns['id'] = __( 'ID', 'gravityflow' );
|
||||
}
|
||||
|
||||
if ( $args['actions_column'] ) {
|
||||
$columns['actions'] = '';
|
||||
}
|
||||
|
||||
if ( empty( $args['form_id'] ) || is_array( $args['form_id']) ) {
|
||||
$columns['form_title'] = __( 'Form', 'gravityflow' );
|
||||
}
|
||||
|
||||
if ( $args['submitter_column'] ) {
|
||||
$columns['created_by'] = __( 'Submitter', 'gravityflow' );
|
||||
}
|
||||
|
||||
if ( $args['step_column'] ) {
|
||||
$columns['workflow_step'] = __( 'Step', 'gravityflow' );
|
||||
}
|
||||
|
||||
$columns['date_created'] = __( 'Submitted', 'gravityflow' );
|
||||
$columns = Gravity_Flow_Common::get_field_columns( $columns, $args['form_id'], $args['field_ids'] );
|
||||
|
||||
if ( $args['last_updated'] ) {
|
||||
$columns['last_updated'] = __( 'Last Updated', 'gravityflow' );
|
||||
}
|
||||
|
||||
return $columns;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the table header.
|
||||
*
|
||||
* @param array $columns The column properties.
|
||||
*/
|
||||
public static function display_table_head( $columns ) {
|
||||
echo '<thead><tr>';
|
||||
|
||||
foreach ( $columns as $label ) {
|
||||
|
||||
if ( $label !== 'step_highlight' ) {
|
||||
echo sprintf( '<th data-label="%s">%s</th>', esc_attr( $label ), esc_html( $label ) );
|
||||
}
|
||||
}
|
||||
|
||||
echo '</tr></thead>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the row for the current entry.
|
||||
*
|
||||
* @param array $args The inbox page arguments.
|
||||
* @param array $entry The entry currently being processed.
|
||||
* @param array $columns The column properties.
|
||||
*/
|
||||
public static function display_entry_row( $args, $entry, $columns ) {
|
||||
$form = GFAPI::get_form( $entry['form_id'] );
|
||||
$url_entry = esc_url_raw( sprintf( '%s&id=%d&lid=%d', $args['detail_base_url'], $entry['form_id'], $entry['id'] ) );
|
||||
$link = "<a href='%s'>%s</a>";
|
||||
|
||||
/**
|
||||
* Allows the entry link to be modified for each of the entries in the inbox table.
|
||||
*
|
||||
* @since 1.9.2
|
||||
*
|
||||
* @param string $link The entry link HTML.
|
||||
* @param string $url_entry The entry URL.
|
||||
* @param string $entry The current entry.
|
||||
* @param string $args The inbox page arguments.
|
||||
*/
|
||||
$link = apply_filters( 'gravityflow_entry_link_inbox_table', $link, $url_entry, $entry, $args );
|
||||
|
||||
$step_highlight_color = '';
|
||||
if ( array_key_exists( 'step_highlight', $columns ) && isset( $entry['workflow_step'] ) ) {
|
||||
$step = gravity_flow()->get_step( $entry['workflow_step'] );
|
||||
if ( $step ) {
|
||||
$meta = $step->get_feed_meta();
|
||||
|
||||
if ( $meta && isset( $meta['step_highlight'] ) && $meta['step_highlight'] ) {
|
||||
if ( isset( $meta['step_highlight_type'] ) && $meta['step_highlight_type'] == 'color' ) {
|
||||
if ( isset( $meta['step_highlight_color'] ) && preg_match( '/^#[a-f0-9]{6}$/i', $meta['step_highlight_color'] ) ) {
|
||||
$step_highlight_color = $meta['step_highlight_color'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Allow the Step Highlight colour to be overridden.
|
||||
*
|
||||
* @since 1.9.2
|
||||
*
|
||||
* @param string $highlight The highlight color (hex value) of the row currently being processed.
|
||||
* @param int $form['id'] The ID of form currently being processed.
|
||||
* @param array $entry The entry object for the row currently being processed.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
$step_highlight_color = apply_filters( 'gravityflow_step_highlight_color_inbox', $step_highlight_color, $form['id'], $entry );
|
||||
|
||||
if ( strlen( $step_highlight_color ) > 0 ) {
|
||||
echo '<tr style="border-left-color: ' . $step_highlight_color . ';">';
|
||||
} else {
|
||||
echo '<tr>';
|
||||
}
|
||||
|
||||
unset( $columns['step_highlight'] );
|
||||
|
||||
foreach ( $columns as $id => $label ) {
|
||||
$value = self::get_column_value( $id, $form, $entry, $columns );
|
||||
$html = $id == 'actions' ? $value : sprintf( $link, $url_entry, $value );
|
||||
echo sprintf( '<td data-label="%s">%s</td>', esc_attr( $label ), $html );
|
||||
}
|
||||
|
||||
echo '</tr>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value for display in the current column for the entry being processed.
|
||||
*
|
||||
* @param string $id The column id, the key to the value in the entry or form.
|
||||
* @param array $form The form object for the current entry.
|
||||
* @param array $entry The entry currently being processed for display.
|
||||
* @param array $columns The columns to be displayed.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_column_value( $id, $form, $entry, $columns ) {
|
||||
$value = '';
|
||||
switch ( strtolower( $id ) ) {
|
||||
case 'form_title':
|
||||
$value = rgar( $form, 'title' );
|
||||
break;
|
||||
case 'created_by':
|
||||
$user = get_user_by( 'id', (int) $entry['created_by'] );
|
||||
$submitter_name = $user ? $user->display_name : $entry['ip'];
|
||||
|
||||
/**
|
||||
* Allow the value displayed in the Submitter column to be overridden.
|
||||
*
|
||||
* @param string $submitter_name The display_name of the logged-in user who submitted the form or the guest ip address.
|
||||
* @param array $entry The entry object for the row currently being processed.
|
||||
* @param array $form The form object for the current entry.
|
||||
*/
|
||||
$value = apply_filters( 'gravityflow_inbox_submitter_name', $submitter_name, $entry, $form );
|
||||
break;
|
||||
case 'date_created':
|
||||
$value = GFCommon::format_date( $entry['date_created'] );
|
||||
break;
|
||||
case 'last_updated':
|
||||
$last_updated = date( 'Y-m-d H:i:s', $entry['workflow_timestamp'] );
|
||||
|
||||
$value = $entry['date_created'] != $last_updated ? GFCommon::format_date( $last_updated, true, 'Y/m/d' ) : '-';
|
||||
break;
|
||||
case 'workflow_step':
|
||||
if ( isset( $entry['workflow_step'] ) ) {
|
||||
$step = gravity_flow()->get_step( $entry['workflow_step'] );
|
||||
if ( $step ) {
|
||||
return $step->get_name();
|
||||
}
|
||||
}
|
||||
|
||||
$value = '';
|
||||
break;
|
||||
case 'actions':
|
||||
$api = new Gravity_Flow_API( $form['id'] );
|
||||
$step = $api->get_current_step( $entry );
|
||||
if ( $step ) {
|
||||
$value = self::format_actions( $step );
|
||||
}
|
||||
break;
|
||||
default:
|
||||
$field = GFFormsModel::get_field( $form, $id );
|
||||
|
||||
if ( is_object( $field ) ) {
|
||||
$value = $field->get_value_entry_list( rgar( $entry, $id ), $entry, $id, $columns, $form );
|
||||
} else {
|
||||
$value = rgar( $entry, $id );
|
||||
}
|
||||
|
||||
$value = apply_filters( 'gform_entries_field_value', $value, $form['id'], $id, $entry );
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats the actions for the action column.
|
||||
*
|
||||
* @param Gravity_Flow_Step $step The current step.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function format_actions( $step ) {
|
||||
$html = '';
|
||||
$actions = $step->get_actions();
|
||||
$entry_id = $step->get_entry_id();
|
||||
foreach ( $actions as $action ) {
|
||||
$show_workflow_note_field = (bool) $action['show_note_field'];
|
||||
$html .= sprintf( '<span id="gravityflow-action-%s-%d" data-entry_id="%d" data-action="%s" data-rest_base="%s" data-note_field="%d" class="gravityflow-action" role="link">%s</span>', $action['key'], $entry_id, $entry_id, $action['key'], $step->get_rest_base(), $show_workflow_note_field, $action['icon'] );
|
||||
}
|
||||
if ( ! empty( $html ) ) {
|
||||
$html = sprintf( '<div id="gravityflow-actions-%d" class="gravityflow-actions gravityflow-actions-locked">
|
||||
<i class="gravityflow-actions-lock fa fa-lock" aria-hidden="true"></i>
|
||||
<i class="gravityflow-actions-unlock fa fa-unlock-alt" aria-hidden="true"></i>
|
||||
%s
|
||||
<span class="gravityflow-actions-spinner">
|
||||
<i class="fa fa-spinner fa-spin" aria-hidden="true"></i>
|
||||
</span>
|
||||
|
||||
<div class="gravityflow-actions-note-field-container" style="display:none;">
|
||||
<label>%s:</label>
|
||||
<div>
|
||||
<textarea></textarea>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
', $entry_id, $html, __( 'Note', 'gravityflow' ) );
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,231 @@
|
||||
<?php
|
||||
/**
|
||||
* Gravity Flow Print Entries
|
||||
*
|
||||
* @package GravityFlow
|
||||
* @subpackage Classes/Gravity_Flow_Print_Entries
|
||||
* @copyright Copyright (c) 2015-2018, Steven Henty S.L.
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
|
||||
* @since 1.0
|
||||
*/
|
||||
|
||||
if ( ! class_exists( 'GFForms' ) ) {
|
||||
die();
|
||||
}
|
||||
|
||||
/**
|
||||
* Class Gravity_Flow_Print_Entries
|
||||
*/
|
||||
class Gravity_Flow_Print_Entries {
|
||||
|
||||
/**
|
||||
* Output the entries to be printed.
|
||||
*/
|
||||
public static function render() {
|
||||
|
||||
$entry_ids = self::get_entry_ids();
|
||||
|
||||
if ( empty( $entry_ids ) ) {
|
||||
die( esc_html__( 'Form ID and Lead ID are required parameters.', 'gravityflow' ) );
|
||||
}
|
||||
|
||||
self::get_header( $entry_ids );
|
||||
|
||||
?>
|
||||
<body>
|
||||
|
||||
<div id="view-container">
|
||||
<?php
|
||||
|
||||
$page_break = rgget( 'page_break' ) ? 'print-page-break' : false;
|
||||
|
||||
require_once( GFCommon::get_base_path() . '/entry_detail.php' );
|
||||
|
||||
foreach ( $entry_ids as $entry_id ) {
|
||||
|
||||
$entry = RGFormsModel::get_lead( $entry_id );
|
||||
$form = GFAPI::get_form( $entry['form_id'] );
|
||||
|
||||
do_action( 'gravityflow_print_entry_header', $form, $entry );
|
||||
|
||||
// Separate each entry inside a form element so radio buttons don't get treated as a single group across multiple entries.
|
||||
echo '<form>';
|
||||
$gravity_flow = gravity_flow();
|
||||
$current_step = $gravity_flow->get_current_step( $form, $entry );
|
||||
|
||||
// Check view permissions.
|
||||
$entry = GFAPI::get_entry( $entry_id );
|
||||
|
||||
require_once( $gravity_flow->get_base_path() . '/includes/pages/class-entry-detail.php' );
|
||||
|
||||
$permission_granted = Gravity_Flow_Entry_Detail::is_permission_granted( $entry, $form, $current_step );
|
||||
|
||||
/**
|
||||
* Allows the the permission check to be overridden for the workflow entry detail page.
|
||||
*
|
||||
* @param bool $permission_granted Whether permission is granted to open the entry.
|
||||
* @param array $entry The current entry.
|
||||
* @param array $form The form for the current entry.
|
||||
* @param Gravity_Flow_Step $current_step The current step.
|
||||
*/
|
||||
$permission_granted = apply_filters( 'gravityflow_permission_granted_entry_detail', $permission_granted, $entry, $form, $current_step );
|
||||
|
||||
if ( ! $permission_granted ) {
|
||||
esc_attr_e( "You don't have permission to view this entry.", 'gravityflow' );
|
||||
continue;
|
||||
}
|
||||
|
||||
Gravity_Flow_Entry_Detail::entry_detail_grid( $form, $entry, false, array(), $current_step );
|
||||
|
||||
echo '</form>';
|
||||
|
||||
if ( rgget( 'timelines' ) ) {
|
||||
Gravity_Flow_Entry_Detail::timeline( $entry, $form );
|
||||
}
|
||||
|
||||
// Output entry divider/page break.
|
||||
if ( array_search( $entry_id, $entry_ids ) < count( $entry_ids ) - 1 ) {
|
||||
echo '<div class="print-hr ' . $page_break . '"></div>';
|
||||
}
|
||||
|
||||
do_action( 'gravityflow_print_entry_footer', $form, $entry );
|
||||
}
|
||||
|
||||
?>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an array of entry IDs to be printed.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_entry_ids() {
|
||||
$entries = rgget( 'lid' );
|
||||
if ( 0 == $entries ) {
|
||||
// Get all the entry ids for the current filter/search.
|
||||
$form_id = 0;
|
||||
$search_criteria = self::get_search_criteria();
|
||||
$entry_ids = GFFormsModel::search_lead_ids( $form_id, $search_criteria );
|
||||
} else {
|
||||
$entry_ids = explode( ',', $entries );
|
||||
}
|
||||
|
||||
// Sort lead IDs numerically.
|
||||
sort( $entry_ids );
|
||||
|
||||
return $entry_ids;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the search criteria to use when getting the entry ids.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_search_criteria() {
|
||||
$search_criteria = array();
|
||||
$filter = rgget( 'filter' );
|
||||
$star = $filter == 'star' ? 1 : null;
|
||||
$read = $filter == 'unread' ? 0 : null;
|
||||
$status = in_array( $filter, array( 'trash', 'spam' ) ) ? $filter : 'active';
|
||||
$search_criteria['status'] = $status;
|
||||
|
||||
if ( $star !== null ) {
|
||||
$search_criteria['field_filters'][] = array( 'key' => 'is_starred', 'value' => (bool) $star );
|
||||
}
|
||||
if ( ! is_null( $read ) ) {
|
||||
$search_criteria['field_filters'][] = array( 'key' => 'is_read', 'value' => (bool) $read );
|
||||
}
|
||||
|
||||
$search_field_id = rgget( 'field_id' );
|
||||
if ( isset( $_GET['field_id'] ) && $_GET['field_id'] !== '' ) {
|
||||
$key = $search_field_id;
|
||||
$val = rgget( 's' );
|
||||
$strpos_row_key = strpos( $search_field_id, '|' );
|
||||
if ( $strpos_row_key !== false ) { // Multi-row.
|
||||
$key_array = explode( '|', $search_field_id );
|
||||
$key = $key_array[0];
|
||||
$val = $key_array[1] . ':' . $val;
|
||||
}
|
||||
$search_criteria['field_filters'][] = array(
|
||||
'key' => $key,
|
||||
'operator' => rgempty( 'operator', $_GET ) ? 'is' : rgget( 'operator' ),
|
||||
'value' => $val,
|
||||
);
|
||||
}
|
||||
|
||||
return $search_criteria;
|
||||
}
|
||||
|
||||
/**
|
||||
* Output the print header.
|
||||
*
|
||||
* @param array $entry_ids The IDs of the entries to be included in this printout.
|
||||
*/
|
||||
public static function get_header( $entry_ids ) {
|
||||
$min = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG || isset( $_GET['gform_debug'] ) ? '' : '.min';
|
||||
|
||||
?>
|
||||
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
|
||||
<meta name="keywords" content=""/>
|
||||
<meta name="description" content=""/>
|
||||
<meta name="MSSmartTagsPreventParsing" content="true"/>
|
||||
<meta name="Robots" content="noindex, nofollow"/>
|
||||
<meta http-equiv="Imagetoolbar" content="No"/>
|
||||
<title>
|
||||
<?php
|
||||
$entry_count = count( $entry_ids );
|
||||
$title = $entry_count > 1 ? esc_html__( 'Bulk Print', 'gravityflow' ) : esc_html__( 'Entry # ', 'gravityflow' ) . absint( $entry_ids[0] );
|
||||
$title = apply_filters( 'gravityflow_page_title_print_entry', $title, $entry_count );
|
||||
echo esc_html( $title );
|
||||
?>
|
||||
</title>
|
||||
<link rel='stylesheet' href='<?php echo GFCommon::get_base_url() ?>/css/print<?php echo $min; ?>.css' type='text/css'/>
|
||||
<link rel='stylesheet' href='<?php echo gravity_flow()->get_base_url() ?>/css/entry-detail<?php echo $min; ?>.css' type='text/css'/>
|
||||
<link rel='stylesheet' href='<?php echo gravity_flow()->get_base_url() ?>/css/discussion-field<?php echo $min; ?>.css' type='text/css'/>
|
||||
<?php
|
||||
$styles = apply_filters( 'gravityflow_print_styles', false );
|
||||
if ( ! empty( $styles ) ) {
|
||||
wp_print_styles( $styles );
|
||||
}
|
||||
|
||||
?>
|
||||
</head>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the status for the current user.
|
||||
*
|
||||
* @param Gravity_Flow_Step $current_step The current step for the entry being processed.
|
||||
*
|
||||
* @return bool|mixed
|
||||
*/
|
||||
public static function get_user_status( $current_step ) {
|
||||
$user_status = false;
|
||||
if ( $current_step ) {
|
||||
$user_status = $current_step->get_user_status();
|
||||
gravity_flow()->log_debug( __METHOD__ . '() - user status = ' . $user_status );
|
||||
|
||||
if ( ! $user_status ) {
|
||||
$user_roles = gravity_flow()->get_user_roles();
|
||||
foreach ( $user_roles as $user_role ) {
|
||||
$user_status = $current_step->get_role_status( $user_role );
|
||||
if ( $user_status ) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $user_status;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,672 @@
|
||||
<?php
|
||||
/**
|
||||
* Gravity Flow Reports
|
||||
*
|
||||
* @package GravityFlow
|
||||
* @subpackage Classes/Gravity_Flow_Reports
|
||||
* @copyright Copyright (c) 2015-2018, Steven Henty S.L.
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
|
||||
* @since 1.0
|
||||
*/
|
||||
|
||||
if ( ! class_exists( 'GFForms' ) ) {
|
||||
die();
|
||||
}
|
||||
|
||||
/**
|
||||
* Class Gravity_Flow_Reports
|
||||
*/
|
||||
class Gravity_Flow_Reports {
|
||||
|
||||
/**
|
||||
* Display of the reports page
|
||||
*
|
||||
* @param array $args The reports page arguments.
|
||||
*/
|
||||
public static function display( $args ) {
|
||||
|
||||
$assignee_key = sanitize_text_field( rgget( 'assignee' ) );
|
||||
list( $assignee_type, $assignee_id ) = rgexplode( '|', $assignee_key, 2 );
|
||||
|
||||
$range = sanitize_key( rgget( 'range' ) );
|
||||
switch ( $range ) {
|
||||
case 'last-6-months' :
|
||||
$start_date = date( 'Y-m-d', strtotime( '-6 months' ) );
|
||||
break;
|
||||
case 'last-3-months' :
|
||||
$start_date = date( 'Y-m-d', strtotime( '-3 months' ) );
|
||||
break;
|
||||
default :
|
||||
$start_date = date( 'Y-m-d', strtotime( '-1 year' ) );
|
||||
}
|
||||
|
||||
$defaults = array(
|
||||
'view' => rgget( 'view' ),
|
||||
'form_id' => absint( rgget( 'form-id' ) ),
|
||||
'step_id' => absint( rgget( 'step-id' ) ),
|
||||
'category' => sanitize_key( rgget( 'category' ) ),
|
||||
'range' => $range,
|
||||
'start_date' => $start_date,
|
||||
'assignee' => $assignee_key,
|
||||
'assignee_type' => $assignee_type,
|
||||
'assignee_id' => $assignee_id,
|
||||
'check_permissions' => true,
|
||||
'base_url' => admin_url( 'admin.php?page=gravityflow-reports' ),
|
||||
);
|
||||
|
||||
$args = array_merge( $defaults, $args );
|
||||
|
||||
if ( $args['check_permissions'] && ! GFAPI::current_user_can_any( 'gravityflow_reports' ) ) {
|
||||
esc_html_e( "You don't have permission to view this page", 'gravityflow' );
|
||||
return;
|
||||
}
|
||||
|
||||
$filter_vars['config'] = self::get_filter_config_vars();
|
||||
$filter_vars['selected'] = array(
|
||||
'formId' => $args['form_id'],
|
||||
'category' => $args['category'],
|
||||
'stepId' => empty( $args['step_id'] ) ? '' : $args['step_id'],
|
||||
'assignee' => $args['assignee'],
|
||||
);
|
||||
|
||||
?>
|
||||
<script>var gravityflowFilterVars = <?php echo json_encode( $filter_vars ); ?>;</script>
|
||||
|
||||
<div id="gravityflow-reports-filter" style="margin:10px 0;">
|
||||
<form method="GET" action="<?php echo esc_url( $args['base_url'] );?>">
|
||||
<input type="hidden" value="gravityflow-reports" name="page" />
|
||||
<?php self::range_drop_down( $args['range'] ); ?>
|
||||
<?php self::form_drop_down( $args['form_id'] ); ?>
|
||||
<?php self::category_drop_down( $args['category'] ); ?>
|
||||
<select id="gravityflow-reports-steps" style="display:none;" name="step-id"></select>
|
||||
<select id="gravityflow-reports-assignees" style="display:none;" name="assignee"></select>
|
||||
<input type="submit" value="<?php esc_html_e( 'Filter', 'gravityflow' )?>" class="button-secondary" />
|
||||
</form>
|
||||
</div>
|
||||
<?php
|
||||
|
||||
|
||||
if ( empty( $args['form_id'] ) ) {
|
||||
|
||||
self::report_all_forms( $args );
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$form_id = $args['form_id'];
|
||||
|
||||
if ( $args['category'] == 'assignee' ) {
|
||||
if ( empty( $args['assignee_key'] ) ) {
|
||||
self::report_form_by_assignee( $form_id, $args );
|
||||
}
|
||||
} elseif ( $args['category'] == 'step' ) {
|
||||
if ( empty( $args['step_id'] ) ) {
|
||||
self::report_form_by_step( $form_id, $args );
|
||||
} else {
|
||||
$step_id = $args['step_id'];
|
||||
if ( empty( $args['assignee_id'] ) ) {
|
||||
self::report_step_by_assignee( $step_id, $args );
|
||||
} else {
|
||||
$assignee_type = $args['assignee_type'];
|
||||
$assignee_id = $args['assignee_id'];
|
||||
self::report_assignee_by_month( $assignee_type, $assignee_id, $args );
|
||||
}
|
||||
}
|
||||
} else {
|
||||
self::report_form_by_month( $form_id, $args );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Output the report for all forms.
|
||||
*
|
||||
* @param array $args The reports page arguments.
|
||||
*/
|
||||
public static function report_all_forms( $args ) {
|
||||
|
||||
$defaults = array(
|
||||
'start_date' => date( 'Y-m-d', strtotime( '-1 year' ) ),
|
||||
'check_permissions' => true,
|
||||
'base_url' => admin_url(),
|
||||
);
|
||||
|
||||
$args = array_merge( $defaults, $args );
|
||||
|
||||
$rows = Gravity_Flow_Activity::get_report_data_for_all_forms( $args['start_date'] );
|
||||
|
||||
if ( empty( $rows ) ) {
|
||||
esc_html_e( 'No data to display', 'gravityflow' );
|
||||
return;
|
||||
}
|
||||
|
||||
$chart_data = array();
|
||||
|
||||
$chart_data[] = array( esc_html__( 'Form', 'gravityflow' ), esc_html__( 'Workflows Completed', 'gravityflow' ), esc_html__( 'Average Duration (hours)', 'gravityflow' ) );
|
||||
|
||||
foreach ( $rows as $row ) {
|
||||
$form = GFAPI::get_form( $row->form_id );
|
||||
$title = esc_html( $form['title'] );
|
||||
$chart_data[] = array( $title, absint( $row->c ), absint( $row->av ) / HOUR_IN_SECONDS );
|
||||
}
|
||||
|
||||
$chart_options = array(
|
||||
'chart' => array(
|
||||
'title' => esc_html__( 'Forms', 'gravityflow' ),
|
||||
'subtitle' => esc_html__( 'Workflows completed and average duration', 'gravityflow' ),
|
||||
),
|
||||
'bars' => 'horizontal',
|
||||
'height' => 200 + count( $rows ) * 100,
|
||||
'series' => array(
|
||||
array( 'axis' => 'count' ),
|
||||
array( 'axis' => 'average_duration' ),
|
||||
),
|
||||
'axes' => array(
|
||||
'x' => array(
|
||||
'count' => array( 'side' => 'top',
|
||||
'label' => esc_html__( 'Workflows Completed', 'gravityflow' )
|
||||
),
|
||||
'average_duration' => array( 'label' => esc_html__( 'Average Duration (hours)', 'gravityflow' ) ),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
$data_table_json = htmlentities( json_encode( $chart_data ), ENT_QUOTES, 'UTF-8', true );
|
||||
$options_json = htmlentities( json_encode( $chart_options ), ENT_QUOTES, 'UTF-8', true );
|
||||
|
||||
echo '<div id="gravityflow_chart_top_level" style="padding:20px;background-color:white;" class="gravityflow_chart" data-type="Bar" data-table="' . $data_table_json . '" data-options="' . $options_json . '""></div>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Output the report for a specific form by month.
|
||||
*
|
||||
* @param int $form_id The form ID.
|
||||
* @param array $args The reports page arguments.
|
||||
*/
|
||||
public static function report_form_by_month( $form_id, $args ) {
|
||||
|
||||
$defaults = array(
|
||||
'start_date' => date( 'Y-m-d', strtotime( '-1 year' ) ),
|
||||
'check_permissions' => true,
|
||||
'base_url' => admin_url(),
|
||||
);
|
||||
|
||||
$args = array_merge( $defaults, $args );
|
||||
|
||||
$rows = Gravity_Flow_Activity::get_report_data_for_form( $form_id, $args['start_date'] );
|
||||
|
||||
if ( empty( $rows ) ) {
|
||||
esc_html_e( 'No data to display', 'gravityflow' );
|
||||
return;
|
||||
}
|
||||
|
||||
$chart_data = array();
|
||||
|
||||
$chart_data[] = array( esc_html__( 'Month', 'gravityflow' ), esc_html__( 'Workflows Completed', 'gravityflow' ), esc_html__( 'Average Duration (hours)', 'gravityflow' ) );
|
||||
global $wp_locale;
|
||||
foreach ( $rows as $row ) {
|
||||
$chart_data[] = array( $wp_locale->get_month( $row->month ), absint( $row->c ), absint( $row->av ) / HOUR_IN_SECONDS );
|
||||
}
|
||||
|
||||
$form = GFAPI::get_form( $form_id );
|
||||
|
||||
$chart_options = array(
|
||||
'chart' => array(
|
||||
'title' => esc_html( $form['title'] ),
|
||||
'subtitle' => esc_html__( 'Workflows completed and average duration', 'gravityflow' ),
|
||||
),
|
||||
'bars' => 'horizontal',
|
||||
'height' => 200 + count( $rows ) * 100,
|
||||
'series' => array(
|
||||
array( 'axis' => 'count' ),
|
||||
array( 'axis' => 'average_duration' ),
|
||||
),
|
||||
'axes' => array(
|
||||
'x' => array(
|
||||
'count' => array( 'side' => 'top',
|
||||
'label' => esc_html__( 'Workflows Completed', 'gravityflow' )
|
||||
),
|
||||
'average_duration' => array( 'label' => esc_html__( 'Average Duration (hours)', 'gravityflow' ) ),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
$data_table_json = htmlentities( json_encode( $chart_data ), ENT_QUOTES, 'UTF-8', true );
|
||||
$options_json = htmlentities( json_encode( $chart_options ), ENT_QUOTES, 'UTF-8', true );
|
||||
|
||||
echo '<div id="gravityflow_chart_top_level" style="padding:20px;background-color:white;" class="gravityflow_chart" data-type="Bar" data-table="' . $data_table_json . '" data-options="' . $options_json . '""></div>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Output the report for a specific form by step.
|
||||
*
|
||||
* @param int $form_id The form ID.
|
||||
* @param array $args The reports page arguments.
|
||||
*/
|
||||
public static function report_form_by_step( $form_id, $args ) {
|
||||
|
||||
$defaults = array(
|
||||
'start_date' => date( 'Y-m-d', strtotime( '-1 year' ) ),
|
||||
'check_permissions' => true,
|
||||
'base_url' => admin_url(),
|
||||
);
|
||||
|
||||
$args = array_merge( $defaults, $args );
|
||||
|
||||
$rows = Gravity_Flow_Activity::get_report_data_for_form_by_step( $form_id, $args['start_date'] );
|
||||
|
||||
if ( empty( $rows ) ) {
|
||||
esc_html_e( 'No data to display', 'gravityflow' );
|
||||
return;
|
||||
}
|
||||
|
||||
$chart_data = array();
|
||||
|
||||
$chart_data[] = array( esc_html__( 'Step', 'gravityflow' ), esc_html__( 'Completed', 'gravityflow' ), esc_html__( 'Average Duration (hours)', 'gravityflow' ) );
|
||||
|
||||
foreach ( $rows as $row ) {
|
||||
$step = gravity_flow()->get_step( $row->feed_id );
|
||||
if ( empty( $step ) ) {
|
||||
continue;
|
||||
}
|
||||
$name = esc_html( $step->get_name() );
|
||||
$chart_data[] = array( $name, absint( $row->c ), absint( $row->av ) / HOUR_IN_SECONDS );
|
||||
}
|
||||
|
||||
$form = GFAPI::get_form( $form_id );
|
||||
|
||||
$chart_options = array(
|
||||
'chart' => array(
|
||||
'title' => esc_html( $form['title'] ),
|
||||
'subtitle' => esc_html__( 'Step completed and average duration', 'gravityflow' ),
|
||||
),
|
||||
'bars' => 'horizontal',
|
||||
'height' => 200 + count( $rows ) * 100,
|
||||
'series' => array(
|
||||
array( 'axis' => 'count' ),
|
||||
array( 'axis' => 'average_duration' ),
|
||||
),
|
||||
'axes' => array(
|
||||
'x' => array(
|
||||
'count' => array( 'side' => 'top', 'label' => esc_html__( 'Completed', 'gravityflow' ) ),
|
||||
'average_duration' => array( 'label' => esc_html__( 'Average Duration (hours)', 'gravityflow' ) ),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
$data_table_json = htmlentities( json_encode( $chart_data ), ENT_QUOTES, 'UTF-8', true );
|
||||
$options_json = htmlentities( json_encode( $chart_options ), ENT_QUOTES, 'UTF-8', true );
|
||||
|
||||
echo '<div id="gravityflow_chart_top_level" style="padding:20px;background-color:white;" class="gravityflow_chart" data-type="Bar" data-table="' . $data_table_json . '" data-options="' . $options_json . '""></div>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Output the report for a specific step by assignee.
|
||||
*
|
||||
* @param int $step_id The step ID.
|
||||
* @param array $args The reports page arguments.
|
||||
*/
|
||||
public static function report_step_by_assignee( $step_id, $args ) {
|
||||
|
||||
$defaults = array(
|
||||
'start_date' => date( 'Y-m-d', strtotime( '-1 year' ) ),
|
||||
'check_permissions' => true,
|
||||
'base_url' => admin_url( 'admin.php?page=gravityflow-reports' ),
|
||||
);
|
||||
|
||||
$args = array_merge( $defaults, $args );
|
||||
|
||||
$step = gravity_flow()->get_step( $step_id );
|
||||
if ( empty( $step ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$rows = Gravity_Flow_Activity::get_report_data_for_step_by_assignee( $step_id, $args['start_date'] );
|
||||
|
||||
if ( empty( $rows ) ) {
|
||||
esc_html_e( 'No data to display', 'gravityflow' );
|
||||
return;
|
||||
}
|
||||
|
||||
$chart_data = array();
|
||||
|
||||
$chart_data[] = array( esc_html__( 'Assignee', 'gravityflow' ), esc_html__( 'Completed', 'gravityflow' ), esc_html__( 'Average Duration (hours)', 'gravityflow' ) );
|
||||
|
||||
foreach ( $rows as $row ) {
|
||||
if ( $row->assignee_type == 'user_id' ) {
|
||||
$user = get_user_by( 'id', $row->assignee_id );
|
||||
$display_name = $user->display_name;
|
||||
} else {
|
||||
$display_name = $row->assignee_id;
|
||||
}
|
||||
|
||||
$chart_data[] = array( $display_name, absint( $row->c ), absint( $row->av ) / HOUR_IN_SECONDS );
|
||||
}
|
||||
|
||||
$chart_options = array(
|
||||
'chart' => array(
|
||||
'title' => esc_html( $step->get_name() ),
|
||||
'subtitle' => esc_html__( 'Step completed and average duration by assignee', 'gravityflow' ),
|
||||
),
|
||||
'bars' => 'horizontal',
|
||||
'height' => 200 + count( $rows ) * 100,
|
||||
'series' => array(
|
||||
array( 'axis' => 'count' ),
|
||||
array( 'axis' => 'average_duration' ),
|
||||
),
|
||||
'axes' => array(
|
||||
'x' => array(
|
||||
'count' => array( 'side' => 'top', 'label' => esc_html__( 'Completed', 'gravityflow' ) ),
|
||||
'average_duration' => array( 'label' => esc_html__( 'Average Duration (hours)', 'gravityflow' ) ),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
$data_table_json = htmlentities( json_encode( $chart_data ), ENT_QUOTES, 'UTF-8', true );
|
||||
$options_json = htmlentities( json_encode( $chart_options ), ENT_QUOTES, 'UTF-8', true );
|
||||
|
||||
echo '<div id="gravityflow_chart_top_level" style="padding:20px;background-color:white;" class="gravityflow_chart" data-type="Bar" data-table="' . $data_table_json . '" data-options="' . $options_json . '""></div>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Output the report for a specific form by assignee.
|
||||
*
|
||||
* @param int $form_id The form ID.
|
||||
* @param array $args The reports page arguments.
|
||||
*/
|
||||
public static function report_form_by_assignee( $form_id, $args ) {
|
||||
|
||||
$defaults = array(
|
||||
'start_date' => date( 'Y-m-d', strtotime( '-1 year' ) ),
|
||||
'check_permissions' => true,
|
||||
'base_url' => admin_url( 'admin.php?page=gravityflow-reports' ),
|
||||
);
|
||||
|
||||
$args = array_merge( $defaults, $args );
|
||||
|
||||
|
||||
$rows = Gravity_Flow_Activity::get_report_data_for_form_by_assignee( $form_id, $args['start_date'] );
|
||||
|
||||
if ( empty( $rows ) ) {
|
||||
esc_html_e( 'No data to display', 'gravityflow' );
|
||||
return;
|
||||
}
|
||||
|
||||
$chart_data = array();
|
||||
|
||||
$chart_data[] = array( esc_html__( 'Assignee', 'gravityflow' ), esc_html__( 'Completed', 'gravityflow' ), esc_html__( 'Average Duration (hours)', 'gravityflow' ) );
|
||||
|
||||
foreach ( $rows as $row ) {
|
||||
if ( $row->assignee_type == 'user_id' ) {
|
||||
$user = get_user_by( 'id', $row->assignee_id );
|
||||
$display_name = $user->display_name;
|
||||
} else {
|
||||
$display_name = $row->assignee_id;
|
||||
}
|
||||
|
||||
$chart_data[] = array( $display_name, absint( $row->c ), absint( $row->av ) / HOUR_IN_SECONDS );
|
||||
}
|
||||
|
||||
$form = GFAPI::get_form( $form_id );
|
||||
|
||||
$chart_options = array(
|
||||
'chart' => array(
|
||||
'title' => esc_html( $form['title'] ),
|
||||
'subtitle' => esc_html__( 'Step completed and average duration by assignee', 'gravityflow' ),
|
||||
),
|
||||
'bars' => 'horizontal',
|
||||
'height' => 200 + count( $rows ) * 100,
|
||||
'series' => array(
|
||||
array( 'axis' => 'count' ),
|
||||
array( 'axis' => 'average_duration' ),
|
||||
),
|
||||
'axes' => array(
|
||||
'x' => array(
|
||||
'count' => array( 'side' => 'top', 'label' => esc_html__( 'Completed', 'gravityflow' ) ),
|
||||
'average_duration' => array( 'label' => esc_html__( 'Average Duration (hours)', 'gravityflow' ) ),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
$data_table_json = htmlentities( json_encode( $chart_data ), ENT_QUOTES, 'UTF-8', true );
|
||||
$options_json = htmlentities( json_encode( $chart_options ), ENT_QUOTES, 'UTF-8', true );
|
||||
|
||||
echo '<div id="gravityflow_chart_top_level" style="padding:20px;background-color:white;" class="gravityflow_chart" data-type="Bar" data-table="' . $data_table_json . '" data-options="' . $options_json . '""></div>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Output the report for a specific assignee by month.
|
||||
*
|
||||
* @param string $assignee_type The assignee type.
|
||||
* @param string $assignee_id The assignee ID.
|
||||
* @param array $args The reports page arguments.
|
||||
*/
|
||||
public static function report_assignee_by_month( $assignee_type, $assignee_id, $args ) {
|
||||
|
||||
$defaults = array(
|
||||
'start_date' => date( 'Y-m-d', strtotime( '-1 year' ) ),
|
||||
'check_permissions' => true,
|
||||
'base_url' => admin_url( 'admin.php?page=gravityflow-reports' ),
|
||||
);
|
||||
|
||||
$args = array_merge( $defaults, $args );
|
||||
|
||||
$rows = Gravity_Flow_Activity::get_report_data_for_assignee_by_month( $assignee_type, $assignee_id, $args['start_date'] );
|
||||
|
||||
if ( empty( $rows ) ) {
|
||||
esc_html_e( 'No data to display', 'gravityflow' );
|
||||
return;
|
||||
}
|
||||
|
||||
$chart_data = array();
|
||||
|
||||
$chart_data[] = array( esc_html__( 'Month', 'gravityflow' ), esc_html__( 'Workflows Completed', 'gravityflow' ), esc_html__( 'Average Duration (hours)', 'gravityflow' ) );
|
||||
global $wp_locale;
|
||||
foreach ( $rows as $row ) {
|
||||
$chart_data[] = array( $wp_locale->get_month( $row->month ) . ' ' . $row->year, absint( $row->c ), absint( $row->av ) / HOUR_IN_SECONDS );
|
||||
}
|
||||
|
||||
if ( $assignee_type == 'user_id' ) {
|
||||
$user = get_user_by( 'id', $assignee_id );
|
||||
$display_name = $user->display_name;
|
||||
} else {
|
||||
$display_name = $assignee_id;
|
||||
}
|
||||
|
||||
$chart_options = array(
|
||||
'chart' => array(
|
||||
'title' => esc_html( $display_name ),
|
||||
'subtitle' => esc_html__( 'Workflows completed and average duration by month', 'gravityflow' ),
|
||||
),
|
||||
'bars' => 'horizontal',
|
||||
'height' => 200 + count( $rows ) * 100,
|
||||
'series' => array(
|
||||
array( 'axis' => 'count' ),
|
||||
array( 'axis' => 'average_duration' ),
|
||||
),
|
||||
'axes' => array(
|
||||
'x' => array(
|
||||
'count' => array( 'side' => 'top',
|
||||
'label' => esc_html__( 'Workflows Completed', 'gravityflow' )
|
||||
),
|
||||
'average_duration' => array( 'label' => esc_html__( 'Average Duration (hours)', 'gravityflow' ) ),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
$data_table_json = htmlentities( json_encode( $chart_data ), ENT_QUOTES, 'UTF-8', true );
|
||||
$options_json = htmlentities( json_encode( $chart_options ), ENT_QUOTES, 'UTF-8', true );
|
||||
|
||||
echo '<div id="gravityflow_chart_top_level" style="padding:20px;background-color:white;" class="gravityflow_chart" data-type="Bar" data-table="' . $data_table_json . '" data-options="' . $options_json . '""></div>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Format the duration for output.
|
||||
*
|
||||
* @param int $seconds The duration in seconds.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function format_duration( $seconds ) {
|
||||
return gravity_flow()->format_duration( $seconds );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the HTML for the form drop down.
|
||||
*
|
||||
* @param string|int $selected_value The selected form.
|
||||
* @param bool $echo Indicates if the content should be echoed.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function form_drop_down( $selected_value, $echo = true ) {
|
||||
$m = array();
|
||||
|
||||
$m[] = '<select id="gravityflow-form-drop-down" name="form-id">';
|
||||
$m[] = sprintf( '<option value="" %s>%s</option>', selected( $selected_value, '', false ) , esc_html__( 'Select A Workflow Form', 'gravityflow' ) );
|
||||
$form_ids = self::get_form_ids();
|
||||
foreach ( $form_ids as $form_id ) {
|
||||
$form = GFAPI::get_form( $form_id );
|
||||
$m[] = sprintf( '<option value="%s" %s>%s</option>', $form_id, selected( $selected_value, $form_id, false ), $form['title'] );
|
||||
}
|
||||
|
||||
$m[] = '</select>';
|
||||
$html = join( '', $m );
|
||||
if ( $echo ) {
|
||||
echo $html;
|
||||
}
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the HTML for the range drop down.
|
||||
*
|
||||
* @param string|int $selected_value The selected range.
|
||||
* @param bool $echo Indicates if the content should be echoed.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function range_drop_down( $selected_value, $echo = true ) {
|
||||
$m = array();
|
||||
$m[] = '<select id="gravityflow-reports-range" name="range">';
|
||||
$m[] = sprintf( '<option value="last-12-months" %s>%s</option>', selected( $selected_value, 'last-12-months', false ), esc_html__( 'Last 12 months', 'gravityflow' ) );
|
||||
$m[] = sprintf( '<option value="last-6-months" %s>%s</option>', selected( $selected_value, 'last-6-months', false ), esc_html__( 'Last 6 months', 'gravityflow' ) );
|
||||
$m[] = sprintf( '<option value="last-3-months" %s>%s</option>', selected( $selected_value, 'last-3-months', false ), esc_html__( 'Last 3 months', 'gravityflow' ) );
|
||||
$m[] = '</select>';
|
||||
|
||||
$html = join( '', $m );
|
||||
|
||||
if ( $echo ) {
|
||||
echo $html;
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the HTML for the category drop down.
|
||||
*
|
||||
* @param string|int $selected_value The selected category.
|
||||
* @param bool $echo Indicates if the content should be echoed.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function category_drop_down( $selected_value, $echo = true ) {
|
||||
$m = array();
|
||||
$m[] = '<select id="gravityflow-reports-category" name="category" style="display:none;">';
|
||||
$m[] = sprintf( '<option value="month" %s>%s</option>', selected( $selected_value, 'month', false ), esc_html__( 'Month', 'gravityflow' ) );
|
||||
$m[] = sprintf( '<option value="assignee" %s >%s</option>', selected( $selected_value, 'assignee', false ), esc_html__( 'Assignee', 'gravityflow' ) );
|
||||
$m[] = sprintf( '<option value="step" %s >%s</option>', selected( $selected_value, 'step', false ), esc_html__( 'Step', 'gravityflow' ) );
|
||||
$m[] = '</select>';
|
||||
|
||||
$html = join( '', $m );
|
||||
|
||||
if ( $echo ) {
|
||||
echo $html;
|
||||
}
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Output the step filter.
|
||||
*
|
||||
* @param array $args The reports page arguments.
|
||||
*/
|
||||
public static function step_filter( $args ) {
|
||||
?>
|
||||
<form method="GET" action="<?php echo esc_url( $args['base_url'] );?>">
|
||||
<input type="hidden" value="step" name="view"/>
|
||||
<input type="hidden" value="gravityflow-reports" name="page" />
|
||||
<?php self::step_drop_down( $args['form_id'] ); ?>
|
||||
<input type="submit" value="<?php esc_html_e( 'Filter', 'gravityflow' )?>" />
|
||||
</form>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the HTML for the step drop down.
|
||||
*
|
||||
* @param int $form_id The form ID.
|
||||
* @param bool $echo Indicates if the content should be echoed.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function step_drop_down( $form_id, $echo = true ) {
|
||||
$m = array();
|
||||
|
||||
$m[] = '<select id="gravityflow-step-drop-down" name="step-id">';
|
||||
$m[] = sprintf( '<option value="">%s</option>', esc_html__( 'All Steps', 'gravityflow' ) );
|
||||
$steps = gravity_flow()->get_steps( $form_id );
|
||||
foreach ( $steps as $step ) {
|
||||
$m[] = sprintf( '<option value="%s">%s</option>', $step->get_id(), $step->get_name() );
|
||||
}
|
||||
|
||||
$m[] = '</select>';
|
||||
$html = join( '', $m );
|
||||
if ( $echo ) {
|
||||
echo $html;
|
||||
}
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an array of form IDs which have workflows.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_form_ids() {
|
||||
return gravity_flow()->get_workflow_form_ids();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns step and assignee properties to be used when rendering the filters.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_filter_config_vars() {
|
||||
$form_ids = self::get_form_ids();
|
||||
$steps_vars = array();
|
||||
foreach ( $form_ids as $form_id ) {
|
||||
$steps = gravity_flow()->get_steps( $form_id );
|
||||
$steps_vars[ $form_id ] = array();
|
||||
foreach ( $steps as $step ) {
|
||||
$assignees = $step->get_assignees();
|
||||
$assignee_vars = array();
|
||||
foreach ( $assignees as $assignee ) {
|
||||
$assignee_id = $assignee->get_id();
|
||||
if ( ! empty( $assignee_id ) ) {
|
||||
$assignee_vars[] = array( 'key' => $assignee->get_key(),
|
||||
'name' => $assignee->get_display_name()
|
||||
);
|
||||
}
|
||||
}
|
||||
$steps_vars[ $form_id ][ $step->get_id() ] = array( 'id' => $step->get_id(),
|
||||
'name' => $step->get_name(),
|
||||
'assignees' => $assignee_vars
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return $steps_vars;
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
/**
|
||||
* Gravity Flow Submit
|
||||
*
|
||||
* @package GravityFlow
|
||||
* @subpackage Classes/Gravity_Flow_Submit
|
||||
* @copyright Copyright (c) 2015-2018, Steven Henty S.L.
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
|
||||
*/
|
||||
|
||||
if ( ! class_exists( 'GFForms' ) ) {
|
||||
die();
|
||||
}
|
||||
|
||||
/**
|
||||
* Class Gravity_Flow_Submit
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
class Gravity_Flow_Submit {
|
||||
|
||||
/**
|
||||
* Displays the content for the submit page.
|
||||
*
|
||||
* @param array $form_ids The forms which should be available for submissions.
|
||||
* @param bool $is_admin Indicates if this is the admin page.
|
||||
*/
|
||||
public static function list_page( $form_ids, $is_admin ) {
|
||||
|
||||
if ( empty( $form_ids ) ) {
|
||||
esc_html_e( "You haven't submitted any workflow forms yet.", 'gravityflow' );
|
||||
return;
|
||||
}
|
||||
|
||||
$items = array();
|
||||
foreach ( $form_ids as $form_id ) {
|
||||
$form = GFAPI::get_form( $form_id );
|
||||
if ( ! $form ) {
|
||||
continue;
|
||||
}
|
||||
$title = sprintf( '<div class="gravityflow-initiate-form-title">%s</div>', rgar( $form, 'title' ) );
|
||||
$description = sprintf( '<div class="gravityflow-initiate-form-description">%s</div>', rgar( $form, 'description' ) );
|
||||
$form_id = absint( $form_id );
|
||||
$url = $is_admin ? admin_url( 'admin.php?page=gravityflow-submit&id=' . $form_id ) : add_query_arg( array(
|
||||
'page' => 'gravityflow-submit',
|
||||
'id' => $form_id,
|
||||
) );
|
||||
|
||||
|
||||
$block = sprintf( '<a href="%s"><div class="panel">%s%s</div></a>', $url, $title, $description );
|
||||
$items[] = sprintf( '<li id="gravityflow-initiate-form-%d">%s</li>', $form_id, $block );
|
||||
}
|
||||
|
||||
$list = sprintf( '<ul id="gravityflow-initiate-list">%s</a></ul>', join( '', $items ) );
|
||||
|
||||
echo $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs the specified form.
|
||||
*
|
||||
* @param int $form_id The form ID.
|
||||
*/
|
||||
public static function form( $form_id ) {
|
||||
gravity_form_enqueue_scripts( $form_id );
|
||||
gravity_form( $form_id );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,271 @@
|
||||
<?php
|
||||
/**
|
||||
* Gravity Flow Support
|
||||
*
|
||||
* @package GravityFlow
|
||||
* @subpackage Classes/Gravity_Flow_Support
|
||||
* @copyright Copyright (c) 2015-2018, Steven Henty S.L.
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
|
||||
*/
|
||||
|
||||
if ( ! class_exists( 'GFForms' ) ) {
|
||||
die();
|
||||
}
|
||||
|
||||
/**
|
||||
* Class Gravity_Flow_Support
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
class Gravity_Flow_Support {
|
||||
|
||||
/**
|
||||
* Displays the support page content.
|
||||
*/
|
||||
public static function display() {
|
||||
|
||||
$license_message = '';
|
||||
|
||||
$license_key = gravity_flow()->get_app_setting( 'license_key' );
|
||||
|
||||
if ( empty( $license_key ) ) {
|
||||
$activate_url = admin_url( 'admin.php?page=gravityflow_settings' );
|
||||
/* Translators: the placeholders are link tags pointing to the Gravity Flow settings page */
|
||||
$license_message = sprintf( esc_html__( 'Please %1$sactivate%2$s your license to access this page.', 'gravityflow' ), "<a href=\"{$activate_url}\">", '</a>' );
|
||||
} else {
|
||||
$response = gravity_flow()->perform_edd_license_request( 'check_license', $license_key );
|
||||
if ( is_wp_error( $response ) ) {
|
||||
$license_message = esc_html__( 'A valid license key is required to access support but there was a problem validating your license key. Please log in to GravityFlow.io and open a support ticket.', 'gravityflow' );
|
||||
} else {
|
||||
$license_data = json_decode( wp_remote_retrieve_body( $response ) );
|
||||
|
||||
$valid = null;
|
||||
if ( empty( $license_data ) || $license_data->license == 'invalid' ) {
|
||||
$license_message = esc_html__( 'Invalid license key. A valid license key is required to access support. Please check the status of your license key in your account area on GravityFlow.io.', 'gravityflow' );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! empty( $license_message ) ) {
|
||||
GFCommon::add_message( $license_message, true );
|
||||
?>
|
||||
<div class="wrap gf_entry_wrap">
|
||||
<h2 class="gf_admin_page_title">
|
||||
<span><?php esc_html_e( 'Gravity Flow Support', 'gravityflow' ); ?></span>
|
||||
</h2>
|
||||
<?php
|
||||
GFCommon::display_admin_message();
|
||||
?>
|
||||
</div>
|
||||
<?php
|
||||
return;
|
||||
}
|
||||
|
||||
$message = '';
|
||||
|
||||
if ( isset( $_POST['gravityflow_send_feedback'] ) ) {
|
||||
check_admin_referer( 'gravityflow_feedback' );
|
||||
|
||||
$system_info = isset( $_POST['gravityflow_debug_info'] ) ? self::get_site_info() : '';
|
||||
|
||||
$body = array(
|
||||
'input_values' => array(
|
||||
'input_1' => rgpost( 'gravityflow_name' ),
|
||||
'input_2' => rgpost( 'gravityflow_email' ),
|
||||
'input_4' => rgpost( 'gravityflow_subject' ),
|
||||
'input_3' => rgpost( 'gravityflow_description' ),
|
||||
'input_5' => $system_info,
|
||||
),
|
||||
);
|
||||
$body_json = json_encode( $body );
|
||||
|
||||
$options = array(
|
||||
'method' => 'POST',
|
||||
'timeout' => 30,
|
||||
'redirection' => 5,
|
||||
'blocking' => true,
|
||||
'sslverify' => false,
|
||||
'headers' => array(),
|
||||
'body' => $body_json,
|
||||
'cookies' => array(),
|
||||
);
|
||||
|
||||
$raw_response = wp_remote_post( 'https://gravityflow.io/gravityformsapi/forms/3/submissions/', $options );
|
||||
|
||||
if ( is_wp_error( $raw_response ) ) {
|
||||
$message = '<div class="error notice notice-error is-dismissible below-h2"><p>' . esc_html__( 'There was a problem submitting your request. Please open a support ticket on GravityFlow.io', 'gravityflow' ) . '</p></div>';
|
||||
}
|
||||
$response_json = wp_remote_retrieve_body( $raw_response );
|
||||
|
||||
$response = json_decode( $response_json, true );
|
||||
|
||||
if ( rgar( $response, 'status' ) == '200' ) {
|
||||
$message = '<div class="updated notice notice-success is-dismissible below-h2"><p>' . esc_html__( 'Thank you! We\'ll be in touch soon.', 'gravityflow' ) . '</p></div>';
|
||||
}
|
||||
}
|
||||
|
||||
$user = wp_get_current_user();
|
||||
|
||||
?>
|
||||
<style>
|
||||
.gravityflow_feedback_form label {
|
||||
padding: 20px 0 10px;
|
||||
display: block;
|
||||
font-weight: bold;
|
||||
}
|
||||
</style>
|
||||
<div class="wrap gf_entry_wrap">
|
||||
<h2 class="gf_admin_page_title">
|
||||
<span><?php esc_html_e( 'Gravity Flow Support', 'gravityflow' ); ?></span>
|
||||
|
||||
</h2>
|
||||
<p>
|
||||
<?php esc_html_e( 'Please check the documentation before submitting a support request', 'gravityflow' ); ?>
|
||||
</p>
|
||||
<p>
|
||||
<a href="http://docs.gravityflow.io">http://docs.gravityflow.io</a>
|
||||
</p>
|
||||
<hr />
|
||||
|
||||
<?php echo $message; ?>
|
||||
<form action="" method="POST">
|
||||
<?php
|
||||
wp_nonce_field( 'gravityflow_feedback' );
|
||||
?>
|
||||
<div class="gravityflow_feedback_form">
|
||||
|
||||
<label for="gravityflow_name">
|
||||
<?php esc_html_e( 'Name', 'gravityflow' ); ?>
|
||||
</label>
|
||||
|
||||
<input id="gravityflow_name" type="text" class="regular-text" name="gravityflow_name" value="<?php echo $user->display_name; ?>"/>
|
||||
|
||||
<label for="gravityflow_email">
|
||||
<?php esc_html_e( 'Email', 'gravityflow' ); ?>
|
||||
</label>
|
||||
|
||||
<input id="gravityflow_email" type="email" class="regular-text" name="gravityflow_email" value="<?php echo self::get_email(); ?>"/>
|
||||
|
||||
<label for="gravityflow_subject_suggestion">
|
||||
<input id="gravityflow_subject_suggestion" type="radio" name="gravityflow_subject" value="suggestion" checked="checked"/>
|
||||
<?php esc_html_e( 'General comment or suggestion', 'gravityflow' ); ?>
|
||||
</label>
|
||||
|
||||
<label for="gravityflow_subject_feature_request">
|
||||
<input id="gravityflow_subject_feature_request" type="radio" name="gravityflow_subject" value="feature request"/>
|
||||
<?php esc_html_e( 'Feature request', 'gravityflow' ); ?>
|
||||
</label>
|
||||
|
||||
|
||||
<label for="gravityflow_subject_bug_report">
|
||||
<input id="gravityflow_subject_bug_report" type="radio" name="gravityflow_subject" value="bug report"/>
|
||||
<?php esc_html_e( 'Bug report', 'gravityflow' ); ?>
|
||||
</label>
|
||||
|
||||
<label for="gravityflow_description">
|
||||
<?php esc_html_e( 'Suggestion or steps to reproduce the issue.', 'gravityflow' ); ?>
|
||||
</label>
|
||||
|
||||
<textarea id="gravityflow_description" name="gravityflow_description" class="widefat" cols="50" rows="10"></textarea>
|
||||
<label>
|
||||
<input type="checkbox" name="gravityflow_debug_info" value="1" checked="checked"/>
|
||||
<?php esc_html_e( 'Send debugging information. (This includes some system information and a list of active plugins. No forms or entry data will be sent.)', 'gravityflow' ); ?>
|
||||
</label>
|
||||
<br /><br />
|
||||
<input id="gravityflow_send" type="submit" class="button button-primary button-large" name="gravityflow_send_feedback" value="<?php esc_html_e( 'Send', 'gravityflow' ); ?>" />
|
||||
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<?php
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the debug info which will appear as a note on the Help Scout ticket.
|
||||
*
|
||||
* @since 1.6.1-dev-2 Use the system report available with Gravity Forms 2.2+.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_site_info() {
|
||||
if ( gravity_flow()->is_gravityforms_supported( '2.2' ) ) {
|
||||
require_once( GFCommon::get_base_path() . '/includes/system-status/class-gf-system-report.php' );
|
||||
$sections = GF_System_Report::get_system_report();
|
||||
$system_report_text = GF_System_Report::get_system_report_text( $sections );
|
||||
|
||||
return $system_report_text;
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'get_plugins' ) ) {
|
||||
require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
|
||||
}
|
||||
$plugin_list = get_plugins();
|
||||
$site_url = get_bloginfo( 'url' );
|
||||
$plugins = array();
|
||||
|
||||
$active_plugins = get_option( 'active_plugins' );
|
||||
|
||||
foreach ( $plugin_list as $key => $plugin ) {
|
||||
$is_active = in_array( $key, $active_plugins );
|
||||
if ( $is_active ) {
|
||||
$name = substr( $key, 0, strpos( $key, '/' ) );
|
||||
$plugins[] = $name . 'v' . $plugin['Version'];
|
||||
}
|
||||
}
|
||||
$plugins = join( ', ', $plugins );
|
||||
|
||||
// Get theme info.
|
||||
$theme = wp_get_theme();
|
||||
$theme_name = $theme->get( 'Name' );
|
||||
$theme_uri = $theme->get( 'ThemeURI' );
|
||||
$theme_version = $theme->get( 'Version' );
|
||||
$theme_author = $theme->get( 'Author' );
|
||||
$theme_author_uri = $theme->get( 'AuthorURI' );
|
||||
|
||||
$form_counts = GFFormsModel::get_form_count();
|
||||
$active_count = $form_counts['active'];
|
||||
$inactive_count = $form_counts['inactive'];
|
||||
$fc = abs( $active_count ) + abs( $inactive_count );
|
||||
$entry_count = GFFormsModel::get_lead_count_all_forms( 'active' );
|
||||
$im = is_multisite() ? 'yes' : 'no';
|
||||
|
||||
global $wpdb;
|
||||
|
||||
$info = array(
|
||||
'site: ' . $site_url,
|
||||
'GF version' . GFCommon::$version,
|
||||
'Gravity Flow version' . gravity_flow()->_version,
|
||||
'WordPress version: ' . get_bloginfo( 'version' ),
|
||||
'php version' . phpversion(),
|
||||
'mysql version: ' . $wpdb->db_version(),
|
||||
'theme name:' . $theme_name,
|
||||
'theme url' . $theme_uri,
|
||||
'theme version:' . $theme_version,
|
||||
'theme author: ' . $theme_author,
|
||||
'theme author URL:' . $theme_author_uri,
|
||||
'is multisite' . $im,
|
||||
'form count: ' . $fc,
|
||||
'entry count: ' . $entry_count,
|
||||
'plugins: ' . $plugins,
|
||||
);
|
||||
|
||||
return join( PHP_EOL, $info );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default value for the email field.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_email() {
|
||||
$license_data = gravity_flow()->check_license();
|
||||
$email = rgobj( $license_data, 'customer_email' );
|
||||
|
||||
if ( empty( $email ) ) {
|
||||
$email = get_option( 'admin_email' );
|
||||
}
|
||||
|
||||
return $email;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
<?php
|
||||
//Nothing to see here
|
||||
Reference in New Issue
Block a user