function process()
 {
     $form = $this->get_form();
     $entry = $this->get_entry();
     $feed_add_ons = gravity_flow()->get_supported_feed_add_ons();
     foreach ($feed_add_ons as $feed_add_on) {
         $feeds = $this->get_feeds($feed_add_on);
         $slug = $feed_add_on['slug'];
         foreach ($feeds as $feed) {
             $setting_key = $slug . '_feed_' . $feed['id'];
             if ($this->{$setting_key}) {
                 if (gravity_flow()->is_feed_condition_met($feed, $form, $entry)) {
                     $this->process_add_on_feed($feed_add_on, $feed);
                     $label = $this->get_add_on_feed_label($feed_add_on, $feed);
                     $note = sprintf(esc_html__('Feed processed: %s', 'gravityflow'), $label);
                     $this->add_note($note, 0, $slug);
                     gravity_flow()->log_debug('Feed processed');
                 } else {
                     gravity_flow()->log_debug('Feed condition not met');
                 }
             }
         }
     }
     return true;
 }
 /**
  * Convert the status key with the full status label. Uses custom labels, if set.
  *
  * @uses Gravity_Flow::translate_status_label()
  *
  * @param string $output HTML value output
  * @param array  $entry The GF entry array
  * @param  array $field_settings Settings for the particular GV field
  * @param array $field Current field being displayed
  *
  * @since 1.17
  *
  * @return string If Gravity Flow not found, or entry not processed yet, returns initial value. Otherwise, returns name of workflow step.
  */
 function modify_entry_value_workflow_final_status($output, $entry, $field_settings, $field)
 {
     if (!empty($output)) {
         $output = gravity_flow()->translate_status_label($output);
     }
     return $output;
 }
 public function get_settings()
 {
     $form = $this->get_form();
     $notfications = $form['notifications'];
     $choices = array();
     foreach ($notfications as $notfication) {
         $choices[] = array('label' => $notfication['name'], 'name' => 'notification_id_' . $notfication['id']);
     }
     $account_choices = gravity_flow()->get_users_as_choices();
     return array('title' => 'Notification', 'fields' => array(array('name' => 'notification', 'label' => esc_html__('Gravity Forms Notifications', 'gravityflow'), 'type' => 'checkbox', 'required' => false, 'choices' => $choices), array('name' => 'workflow_notification_enabled', 'label' => __('Workflow notification', 'gravityflow'), 'tooltip' => __('Enable this setting to send an email.', 'gravityflow'), 'type' => 'checkbox', 'choices' => array(array('label' => __('Enabled', 'gravityflow'), 'name' => 'workflow_notification_enabled', 'default_value' => false))), array('name' => 'workflow_notification_type', 'label' => __('Send To', 'gravityflow'), 'type' => 'radio', 'default_value' => 'select', 'horizontal' => true, 'choices' => array(array('label' => __('Select', 'gravityflow'), 'value' => 'select'), array('label' => __('Configure Routing', 'gravityflow'), 'value' => 'routing'))), array('id' => 'workflow_notification_users', 'name' => 'workflow_notification_users[]', 'label' => __('Select User', 'gravityflow'), 'size' => '8', 'multiple' => 'multiple', 'type' => 'select', 'choices' => $account_choices), array('name' => 'workflow_notification_routing', 'label' => __('Routing', 'gravityflow'), 'type' => 'user_routing'), array('name' => 'workflow_notification_from_name', 'class' => 'fieldwidth-2 merge-tag-support mt-hide_all_fields mt-position-right ui-autocomplete-input', 'label' => __('From Name', 'gravityflow'), 'type' => 'text'), array('name' => 'workflow_notification_from_email', 'class' => 'fieldwidth-2 merge-tag-support mt-hide_all_fields mt-position-right ui-autocomplete-input', 'label' => __('From Email', 'gravityflow'), 'type' => 'text', 'default_value' => '{admin_email}'), array('name' => 'workflow_notification_reply_to', 'class' => 'fieldwidth-2 merge-tag-support mt-hide_all_fields mt-position-right ui-autocomplete-input', 'label' => __('Reply To', 'gravityflow'), 'type' => 'text'), array('name' => 'workflow_notification_bcc', 'class' => 'fieldwidth-2 merge-tag-support mt-hide_all_fields mt-position-right ui-autocomplete-input', 'label' => __('BCC', 'gravityflow'), 'type' => 'text'), array('name' => 'workflow_notification_subject', 'class' => 'fieldwidth-1 merge-tag-support mt-hide_all_fields mt-position-right ui-autocomplete-input', 'label' => __('Subject', 'gravityflow'), 'type' => 'text'), array('name' => 'workflow_notification_message', 'label' => __('Message', 'gravityflow'), 'type' => 'visual_editor')));
 }
 function install()
 {
     $gravityflow = gravity_flow();
     $settings = $gravityflow->get_app_settings();
     $settings['background_updates'] = $this->background_updates !== 'disabled';
     gravity_flow()->update_app_settings($settings);
 }
Example #5
0
    public static function display($args)
    {
        global $current_user;
        $filter = apply_filters('gravityflow_inbox_filter', array('form_id' => 0, 'start_date' => '', 'end_date' => ''));
        $field_ids = apply_filters('gravityflow_inbox_fields', array());
        $defaults = array('display_empty_fields' => true, 'id_column' => true, 'submitter_column' => true, '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);
        $args = array_merge($defaults, $args);
        if ($current_user->ID > 0) {
            $filter_key = 'user_id_' . $current_user->ID;
        } elseif ($token = gravity_flow()->decode_access_token()) {
            $filter_key = 'email_' . gravity_flow()->parse_token_assignee($token)->get_id();
        }
        $entries = array();
        $form_id = $args['form_id'];
        $total_count = 0;
        if (!empty($filter_key)) {
            $field_filters[] = array('key' => 'workflow_' . $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['field_filters'] = $field_filters;
            $search_criteria['status'] = 'active';
            $form_ids = $args['form_id'] ? $args['form_id'] : gravity_flow()->get_workflow_form_ids();
            if (!empty($form_ids)) {
                $paging = array('page_size' => 150);
                $entries = GFAPI::get_entries($form_ids, $search_criteria, null, $paging, $total_count);
            }
        }
        if (sizeof($entries) > 0) {
            $id_style = $args['id_column'] ? '' : 'style="display:none;"';
            $submitter_style = $args['submitter_column'] ? '' : 'style="display:none;"';
            $step_style = $args['step_column'] ? '' : 'style="display:none;"';
            ?>

			<table id="gravityflow-inbox" class="widefat gravityflow-inbox" cellspacing="0" style="border:0px;">
				<thead>
				<tr>
					<th <?php 
            echo $id_style;
            ?>
 data-label="<?php 
            esc_html_e('ID', 'gravityflow');
            ?>
"><?php 
            esc_html_e('ID', 'gravityflow');
            ?>
</th>
					<?php 
            if (empty($form_id)) {
                ?>
						<th><?php 
                esc_html_e('Form', 'gravityflow');
                ?>
</th>
					<?php 
            }
            ?>
					<th <?php 
            echo $submitter_style;
            ?>
><?php 
            esc_html_e('Submitter', 'gravityflow');
            ?>
</th>
					<th <?php 
            echo $step_style;
            ?>
><?php 
            esc_html_e('Step', 'gravityflow');
            ?>
</th>
					<th><?php 
            esc_html_e('Submitted', 'gravityflow');
            ?>
</th>
					<?php 
            if ($args['form_id'] && is_array($args['field_ids'])) {
                $columns = RGFormsModel::get_grid_columns($args['form_id'], true);
                $field_ids = array_keys($columns);
                foreach ($args['field_ids'] as $field_id) {
                    $field_id = trim($field_id);
                    if (in_array($field_id, $field_ids)) {
                        $field_info = $columns[$field_id];
                        echo '<th>' . esc_html($field_info['label']) . '</th>';
                    }
                }
            }
            if ($args['last_updated']) {
                echo '<th>' . esc_html__('Last Updated', 'gravityflow') . '</th>';
            }
            ?>
				</tr>
				</thead>

				<tbody class="list:user user-list">
				<?php 
            foreach ($entries as $entry) {
                $form = GFAPI::get_form($entry['form_id']);
                $user = get_user_by('id', (int) $entry['created_by']);
                $name = $user ? $user->display_name : $entry['ip'];
                $base_url = $args['detail_base_url'];
                $url_entry = $base_url . sprintf('&id=%d&lid=%d', $entry['form_id'], $entry['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 $id_style;
                ?>
>
							<?php 
                printf($link, $url_entry, $entry['id']);
                ?>
						</td>
						<?php 
                if (empty($form_id)) {
                    ?>
							<td data-label="<?php 
                    esc_html_e('Form', 'gravityflow');
                    ?>
">
								<?php 
                    printf($link, $url_entry, $form['title']);
                    ?>
							</td>
						<?php 
                }
                ?>
						<td data-label="<?php 
                esc_html_e('Submitter', 'gravityflow');
                ?>
" <?php 
                echo $submitter_style;
                ?>
>
							<?php 
                printf($link, $url_entry, $name);
                ?>
						</td>
						<td data-label="<?php 
                esc_html_e('Step', 'gravityflow');
                ?>
" <?php 
                echo $step_style;
                ?>
>
							<?php 
                if (isset($entry['workflow_step'])) {
                    $step = gravity_flow()->get_step($entry['workflow_step']);
                    if ($step) {
                        printf($link, $url_entry, $step->get_name());
                    }
                }
                ?>
						</td>
						<td data-label="<?php 
                esc_html_e('Submitted', 'gravityflow');
                ?>
">
							<?php 
                printf($link, $url_entry, GFCommon::format_date($entry['date_created']));
                ?>
						</td>

						<?php 
                if ($args['form_id'] && is_array($args['field_ids'])) {
                    if (isset($form['fields']) && is_array($form['fields'])) {
                        $field_ids = array_keys($columns);
                        foreach ($args['field_ids'] as $field_id) {
                            /* @var GF_Field $field */
                            if (!in_array($field_id, $field_ids)) {
                                continue;
                            }
                            $field_id = trim($field_id);
                            $field_info = $columns[$field_id];
                            $value = rgar($entry, $field_id);
                            $field = GFFormsModel::get_field($form, $field_id);
                            ?>
									<td data-label="<?php 
                            echo esc_attr($field_info['label']);
                            ?>
">
										<?php 
                            printf($link, $url_entry, $field->get_value_entry_list($value, $entry, $field_id, $columns, $form));
                            ?>
									</td>
								<?php 
                        }
                    }
                }
                if ($args['last_updated']) {
                    ?>
							<td data-label="<?php 
                    esc_html_e('Last_Updated', 'gravityflow');
                    ?>
">
								<?php 
                    $last_updated = date('Y-m-d H:i:s', $entry['workflow_timestamp']);
                    if ($entry['date_created'] != $last_updated) {
                        echo esc_html(GFCommon::format_date($last_updated, true, 'Y/m/d'));
                    } else {
                        echo '-';
                    }
                    ?>
							</td>
							<?php 
                }
                ?>
					</tr>
				<?php 
            }
            ?>
				</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 
        }
    }
 public function log_event($status, $duration = 0)
 {
     gravity_flow()->log_event('assignee', 'status', $this->step->get_form_id(), $this->step->get_entry_id(), $status, $this->step->get_id(), $duration, $this->get_id(), $this->get_type(), $this->get_display_name());
 }
 public function save_entry($form, &$lead, $editable_fields)
 {
     global $wpdb;
     gravity_flow()->log_debug(__METHOD__ . '(): Saving entry.');
     $lead_detail_table = GFFormsModel::get_lead_details_table_name();
     $is_new_lead = $lead == null;
     // Bailing if null
     if ($is_new_lead) {
         return;
     }
     $current_fields = $wpdb->get_results($wpdb->prepare("SELECT id, field_number FROM {$lead_detail_table} WHERE lead_id=%d", $lead['id']));
     $total_fields = array();
     /* @var $calculation_fields GF_Field[] */
     $calculation_fields = array();
     $recalculate_total = false;
     GFCommon::log_debug(__METHOD__ . '(): Saving entry fields.');
     foreach ($form['fields'] as &$field) {
         /* @var $field GF_Field */
         //Ignore fields that are marked as display only
         if ($field->displayOnly && $field->type != 'password') {
             continue;
         }
         //ignore pricing fields in the entry detail
         if (RG_CURRENT_VIEW == 'entry' && GFCommon::is_pricing_field($field->type)) {
             //continue;
         }
         //process total field after all fields have been saved
         if ($field->type == 'total') {
             $total_fields[] = $field;
             continue;
         }
         // process calculation fields after all fields have been saved (moved after the is hidden check)
         if ($field->has_calculation()) {
             $calculation_fields[] = $field;
             continue;
         }
         if (!in_array($field->id, $editable_fields)) {
             continue;
         }
         if (!$this->conditional_logic_editable_fields_enabled) {
             $field->conditionalLogic = null;
         }
         gravity_flow()->log_debug(__METHOD__ . "(): Saving field {$field->label}(#{$field->id} - {$field->type}).");
         if ($field->type == 'post_category') {
             $field = GFCommon::add_categories_as_choices($field, '');
         }
         $inputs = $field->get_entry_inputs();
         if (is_array($inputs)) {
             foreach ($inputs as $input) {
                 GFFormsModel::save_input($form, $field, $lead, $current_fields, $input['id']);
             }
         } else {
             GFFormsModel::save_input($form, $field, $lead, $current_fields, $field->id);
         }
     }
     if (!empty($calculation_fields)) {
         foreach ($calculation_fields as $calculation_field) {
             gravity_flow()->log_debug(__METHOD__ . "(): Saving calculated field {$calculation_field->label}(#{$calculation_field->id} - {$calculation_field->type}).");
             // Make sure that the value gets recalculated
             $calculation_field->conditionalLogic = null;
             $inputs = $calculation_field->get_entry_inputs();
             if (is_array($inputs)) {
                 if (!in_array($calculation_field->id, $editable_fields)) {
                     // Make sure calculated product names and quantities are saved as if they're submitted.
                     $value = array($calculation_field->id . '.1' => $lead[$calculation_field->id . '.1']);
                     $_POST['input_' . $calculation_field->id . '_1'] = $calculation_field->get_field_label(false, $value);
                     $quantity = trim($lead[$calculation_field->id . '.3']);
                     if ($calculation_field->disableQuantity && empty($quantity)) {
                         $_POST['input_' . $calculation_field->id . '_3'] = 1;
                     } else {
                         $_POST['input_' . $calculation_field->id . '_3'] = $quantity;
                     }
                 }
                 foreach ($inputs as $input) {
                     GFFormsModel::save_input($form, $calculation_field, $lead, $current_fields, $input['id']);
                     GFFormsModel::refresh_lead_field_value($lead['id'], $input['id']);
                 }
             } else {
                 GFFormsModel::save_input($form, $calculation_field, $lead, $current_fields, $calculation_field->id);
                 GFFormsModel::refresh_lead_field_value($lead['id'], $calculation_field->id);
             }
         }
     }
     GFFormsModel::refresh_product_cache($form, $lead = RGFormsModel::get_lead($lead['id']));
     //saving total field as the last field of the form.
     if (!empty($total_fields)) {
         foreach ($total_fields as $total_field) {
             gravity_flow()->log_debug(__METHOD__ . '(): Saving total field.');
             GFFormsModel::save_input($form, $total_field, $lead, $current_fields, $total_field->id);
             GFFormsModel::refresh_lead_field_value($lead['id'], $total_field->id);
         }
     }
 }
    public static function notes_grid($notes, $is_editable, $emails = null, $subject = '')
    {
        if (empty($notes)) {
            return;
        }
        foreach ($notes as $note) {
            ?>

			<div id="gravityflow-note-<?php 
            echo $note->id;
            ?>
" class="gravityflow-note gravityflow-note-<?php 
            echo $note->user_name;
            ?>
">
				<div class="gravityflow-note-avatar">
					<div>
						<?php 
            if (empty($note->user_id)) {
                $img_url = '';
                if ($note->user_name !== 'gravityflow') {
                    $step = Gravity_Flow_Steps::get($note->user_name);
                    if ($step) {
                        $img_url = $step->get_icon_url();
                    }
                }
                if (empty($img_url)) {
                    $img_url = gravity_flow()->get_base_url() . '/images/gravityflow-icon-blue.svg';
                }
                if (strpos($img_url, 'http') !== false) {
                    printf('<img class="avatar avatar-65 photo" src="%s" style="width:65px;height:65px;" />', $img_url);
                } else {
                    printf('<span class="avatar avatar-65 photo">%s</span>', $img_url);
                }
            } else {
                echo get_avatar($note->user_id, 65);
            }
            ?>
					</div>
					<div></div>
				</div>

				<div class="gravityflow-note-body-wrap">
					<div class="gravityflow-note-body">
						<div class="gravityflow-note-header">

							<div class="gravityflow-note-title">
								<?php 
            if (empty($note->user_id)) {
                if ($note->user_name == 'gravityflow') {
                    echo esc_html(gravity_flow()->translate_navigation_label('Workflow'));
                } else {
                    $step = Gravity_Flow_Steps::get($note->user_name);
                    if ($step) {
                        echo $step->get_label();
                    } else {
                        echo esc_html($note->user_name);
                    }
                }
            } else {
                echo esc_html($note->user_name);
            }
            ?>
							</div>
							<div class="gravityflow-note-meta">
								<?php 
            echo esc_html(GFCommon::format_date($note->date_created, false, 'd M Y g:i a', false));
            ?>
							</div>
						</div>

						<div class="gravityflow-note-body">
							<?php 
            echo nl2br(esc_html($note->value));
            ?>
						</div>

					</div>
				</div>

			</div>
		<?php 
        }
    }
 public static function format_duration($seconds)
 {
     return gravity_flow()->format_duration($seconds);
 }
Example #10
0
 /**
  * Registers activity event in the activity log. The activity log is used to generate reports.
  *
  * @param string $log_type The object of the event. 'workflow', 'step', 'assignee'
  * @param string $event 'started', 'ended', 'status'
  * @param int $form_id The form ID.
  * @param int $entry_id The Entry ID.
  * @param string $log_value The value to log.
  * @param int $step_id The Step ID.
  * @param int $duration The duration in seconds - if applicable.
  * @param int $assignee_id The assignee ID - if applicable.
  * @param string $assignee_type - The Assignee type - if applicable
  * @param string $display_name - The display name of the User.
  */
 public function log_activity($log_type, $event, $form_id = 0, $entry_id = 0, $log_value = '', $step_id = 0, $duration = 0, $assignee_id = 0, $assignee_type = '', $display_name = '')
 {
     gravity_flow()->log_event($log_type, $event, $form_id, $entry_id, $log_value, $step_id, $duration, $assignee_id, $assignee_type, $display_name);
 }
 function install()
 {
     if ($this->license_key) {
         $gravityflow = gravity_flow();
         $settings = $gravityflow->get_app_settings();
         $settings['license_key'] = $this->license_key;
         gravity_flow()->update_app_settings($settings);
     }
 }
 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;
 }
 /**
  * Target for the gform_pre_replace_merge_tags filter. Replaces the workflow_timeline and created_by merge tags.
  *
  *
  * @param string $text
  * @param array $form
  * @param array $entry
  * @param bool $url_encode
  * @param bool $esc_html
  * @param bool $nl2br
  * @param string $format
  *
  * @return string
  */
 function replace_variables($text, $form, $entry, $url_encode, $esc_html, $nl2br, $format)
 {
     preg_match_all('/{workflow_timeline(:(.*?))?}/', $text, $timeline_matches, PREG_SET_ORDER);
     if (is_array($timeline_matches) && isset($timeline_matches[0])) {
         $full_tag = $timeline_matches[0][0];
         require_once gravity_flow()->get_base_path() . '/includes/pages/class-entry-detail.php';
         $notes = Gravity_Flow_Entry_Detail::get_timeline_notes($entry);
         $html = '';
         foreach ($notes as $note) {
             $html .= '<br />';
             $html .= GFCommon::format_date($note->date_created, false, 'd M Y g:i a', false);
             $html .= ': ';
             if (empty($note->user_id)) {
                 if ($note->user_name !== 'gravityflow') {
                     $step = Gravity_Flow_Steps::get($note->user_name);
                     if ($step) {
                         $html .= $step->get_label();
                     }
                 } else {
                     $html .= esc_html(gravity_flow()->translate_navigation_label('Workflow'));
                 }
             } else {
                 $html .= esc_html($note->user_name);
             }
             $html .= '<br />';
             $html .= nl2br(esc_html($note->value));
             $html .= '<br />';
         }
         $text = str_replace($full_tag, $html, $text);
     }
     preg_match_all('/{created_by(:(.*?))?}/', $text, $created_by_matches, PREG_SET_ORDER);
     if (is_array($created_by_matches)) {
         if (!empty($entry['created_by'])) {
             $entry_creator = new WP_User($entry['created_by']);
             foreach ($created_by_matches as $created_by_match) {
                 if (!isset($created_by_match[2])) {
                     continue;
                 }
                 $full_tag = $created_by_match[0];
                 $property = $created_by_match[2];
                 if ($property == 'roles') {
                     $value = implode(', ', $entry_creator->roles);
                 } else {
                     $value = $entry_creator->get($property);
                 }
                 $value = esc_html($value);
                 $text = str_replace($full_tag, $value, $text);
             }
         }
     }
     return $text;
 }
 public static function get_form_ids()
 {
     return gravity_flow()->get_workflow_form_ids();
 }
Example #15
0
function gravityflow_edd_plugin_updater()
{
    $gravity_flow = gravity_flow();
    if ($gravity_flow) {
        if (defined('GRAVITY_FLOW_LICENSE_KEY')) {
            $license_key = GRAVITY_FLOW_LICENSE_KEY;
        } else {
            $settings = gravity_flow()->get_app_settings();
            $license_key = trim(rgar($settings, 'license_key'));
        }
        $edd_updater = new Gravity_Flow_EDD_SL_Plugin_Updater(GRAVITY_FLOW_EDD_STORE_URL, __FILE__, array('version' => GRAVITY_FLOW_VERSION, 'license' => $license_key, 'item_name' => GRAVITY_FLOW_EDD_ITEM_NAME, 'author' => 'Steven Henty'));
    }
}
 /**
  * @param $text
  * @param Gravity_Flow_Assignee $assignee
  *
  * @return mixed
  */
 public function replace_variables($text, $assignee)
 {
     $text = parent::replace_variables($text, $assignee);
     $comment = rgpost('gravityflow_note');
     $text = str_replace('{workflow_note}', $comment, $text);
     $expiration_days = apply_filters('gravityflow_approval_token_expiration_days', 2);
     $expiration_str = '+' . (int) $expiration_days . ' days';
     $expiration_timestamp = strtotime($expiration_str);
     $scopes = array('pages' => array('inbox'), 'step_id' => $this->get_id(), 'entry_timestamp' => $this->get_entry_timestamp(), 'entry_id' => $this->get_entry_id(), 'action' => 'approve');
     $approve_token = '';
     if ($assignee) {
         $approve_token = gravity_flow()->generate_access_token($assignee, $scopes, $expiration_timestamp);
         $text = str_replace('{workflow_approve_token}', $approve_token, $text);
     }
     preg_match_all('/{workflow_approve_url(:(.*?))?}/', $text, $matches, PREG_SET_ORDER);
     if (is_array($matches)) {
         foreach ($matches as $match) {
             $full_tag = $match[0];
             $options_string = isset($match[2]) ? $match[2] : '';
             $options = shortcode_parse_atts($options_string);
             $a = shortcode_atts(array('page_id' => 'admin'), $options);
             $approve_url = $this->get_entry_url($a['page_id'], $assignee, $approve_token);
             $approve_url = esc_url_raw($approve_url);
             $text = str_replace($full_tag, $approve_url, $text);
         }
     }
     preg_match_all('/{workflow_approve_link(:(.*?))?}/', $text, $matches, PREG_SET_ORDER);
     if (is_array($matches)) {
         foreach ($matches as $match) {
             $full_tag = $match[0];
             $options_string = isset($match[2]) ? $match[2] : '';
             $options = shortcode_parse_atts($options_string);
             $a = shortcode_atts(array('page_id' => 'admin', 'text' => esc_html__('Approve', 'gravityflow')), $options);
             $approve_url = $this->get_entry_url($a['page_id'], $assignee, $approve_token);
             $approve_url = esc_url_raw($approve_url);
             $approve_link = sprintf('<a href="%s">%s</a>', $approve_url, esc_html($a['text']));
             $text = str_replace($full_tag, $approve_link, $text);
         }
     }
     $scopes['action'] = 'reject';
     $reject_token = '';
     if ($assignee) {
         $reject_token = gravity_flow()->generate_access_token($assignee, $scopes, $expiration_timestamp);
         $text = str_replace('{workflow_reject_token}', $reject_token, $text);
     }
     preg_match_all('/{workflow_reject_url(:(.*?))?}/', $text, $matches, PREG_SET_ORDER);
     if (is_array($matches)) {
         foreach ($matches as $match) {
             $full_tag = $match[0];
             $options_string = isset($match[2]) ? $match[2] : '';
             $options = shortcode_parse_atts($options_string);
             $a = shortcode_atts(array('page_id' => 'admin'), $options);
             $reject_url = $this->get_entry_url($a['page_id'], $assignee, $reject_token);
             $reject_url = esc_url_raw($reject_url);
             $text = str_replace($full_tag, $reject_url, $text);
         }
     }
     preg_match_all('/{workflow_reject_link(:(.*?))?}/', $text, $matches, PREG_SET_ORDER);
     if (is_array($matches)) {
         foreach ($matches as $match) {
             $full_tag = $match[0];
             $options_string = isset($match[2]) ? $match[2] : '';
             $options = shortcode_parse_atts($options_string);
             $a = shortcode_atts(array('page_id' => 'admin', 'text' => esc_html__('Reject', 'gravityflow')), $options);
             $reject_url = $this->get_entry_url($a['page_id'], $assignee, $reject_token);
             $reject_url = esc_url_raw($reject_url);
             $reject_link = sprintf('<a href="%s">%s</a>', $reject_url, esc_html($a['text']));
             $text = str_replace($full_tag, $reject_link, $text);
         }
     }
     return $text;
 }
Example #17
0
 public function export()
 {
     $export = '';
     $rows = array();
     $columns = $this->get_columns();
     $column_keys = array_keys($columns);
     foreach ($this->items as $item) {
         $row_values = array();
         foreach ($column_keys as $column_key) {
             if (array_key_exists($column_key, $item)) {
                 switch ($column_key) {
                     case 'created_by':
                         $user_id = $item['created_by'];
                         if ($user_id) {
                             $user = get_user_by('id', $user_id);
                             $col_val = $user->display_name;
                         } else {
                             $col_val = $item['ip'];
                         }
                         break;
                     case 'workflow_step':
                         $step_id = rgar($item, 'workflow_step');
                         if ($step_id > 0) {
                             $step = gravity_flow()->get_step($step_id);
                             $col_val = $step->get_name();
                         } else {
                             $col_val = $step_id;
                         }
                         break;
                     default:
                         $col_val = $item[$column_key];
                 }
                 $row_values[] = '"' . addslashes($col_val) . '"';
             }
         }
         $rows[] = join(',', $row_values);
     }
     $export .= join("\r\n", $rows);
     return $export . "\r\n";
 }
Example #18
0
 /**
  * Removes assignees from and/or adds assignees to a step. Call after updating entry values.
  * Make sure you call get_assignees() before you update the entry or the previous assignees may not get removed.
  *
  * @param Gravity_Flow_Assignee[] $previous_assignees The previous assign
  */
 public function maybe_adjust_assignment($previous_assignees)
 {
     gravity_flow()->log_debug(__METHOD__ . '(): Starting');
     $new_assignees = $this->get_assignees();
     $new_assignees_keys = array();
     foreach ($new_assignees as $new_assignee) {
         $new_assignees_keys[] = $new_assignee->get_key();
     }
     $previous_assignees_keys = array();
     foreach ($previous_assignees as $previous_assignee) {
         $previous_assignees_keys[] = $previous_assignee->get_key();
     }
     $assignee_keys_to_add = array_diff($new_assignees_keys, $previous_assignees_keys);
     $assignee_keys_to_remove = array_diff($previous_assignees_keys, $new_assignees_keys);
     foreach ($assignee_keys_to_add as $assignee_key_to_add) {
         $assignee_to_add = new Gravity_Flow_Assignee($assignee_key_to_add, $this);
         $assignee_to_add->update_status('pending');
     }
     foreach ($assignee_keys_to_remove as $assignee_key_to_remove) {
         $assignee_to_remove = new Gravity_Flow_Assignee($assignee_key_to_remove, $this);
         $assignee_to_remove->remove();
     }
 }
Example #19
0
 function test_assignee_field()
 {
     $form = GFAPI::get_form($this->form_id);
     $assignee_field_properties_json = '{"type":"workflow_assignee_select","id":6,"label":"Assignee","adminLabel":"","isRequired":false,"size":"medium","errorMessage":"","inputs":null,"formId":93,"pageNumber":1,"choices":"","conditionalLogic":"","displayOnly":"","labelPlacement":"","descriptionPlacement":"","subLabelPlacement":"","placeholder":"","multipleFiles":false,"maxFiles":"","calculationFormula":"","calculationRounding":"","enableCalculation":"","disableQuantity":false,"displayAllCategories":false,"inputMask":false,"inputMaskValue":"","allowsPrepopulate":false,"gravityflowAssigneeFieldShowUsers":true,"gravityflowAssigneeFieldShowRoles":true,"gravityflowAssigneeFieldShowFields":true,"cssClass":""}';
     $assignee_field_properties = json_decode($assignee_field_properties_json, true);
     $assignee_field_properties['id'] = 999;
     $assignee_field = new Gravity_Flow_Field_Assignee_Select($assignee_field_properties);
     $form['fields'][] = $assignee_field;
     GFAPI::update_form($form);
     $step_settings = array('assignees' => array('assignee_field|999'));
     $step1_id = $this->_add_user_input_step($step_settings);
     $this->_create_entries();
     $entries = GFAPI::get_entries($this->form_id);
     $entry = $entries[0];
     $entry_id = $entry['id'];
     $entry[999] = 'user_id|1';
     GFAPI::update_entry($entry);
     // simulate submission
     gravity_flow()->maybe_process_feed($entry, $form);
     $this->api->process_workflow($entry_id);
     $entry = GFAPI::get_entry($entry_id);
     // Check status
     $status = $this->api->get_status($entry);
     $this->assertEquals('pending', $status);
     // Complete
     $step1 = $this->api->get_step($step1_id, $entry);
     $step1->update_user_status(1, 'complete');
     $this->api->process_workflow($entry_id);
     // Refresh entry
     $entry = GFAPI::get_entry($entry_id);
     // Check status
     $status = $this->api->get_status($entry);
     $this->assertEquals('complete', $status);
 }
 public static function get_site_info()
 {
     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[] = array($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);
 }
Example #21
0
if (!class_exists('RGForms')) {
    require GRAVITYFORMS_BASE_PATH . 'gravityforms.php';
}
//require ABSPATH . 'wp-content/plugins/gravityflow/gravityflow.php';
require dirname(__FILE__) . '/testcase.php';
require dirname(__FILE__) . '/gravityforms-testcase.php';
require dirname(__FILE__) . '/testcase-xmlrpc.php';
require dirname(__FILE__) . '/testcase-ajax.php';
require dirname(__FILE__) . '/exceptions.php';
require dirname(__FILE__) . '/utils.php';
// Update array with plugins to include ...
$plugins_to_active = array('gravityforms/gravityforms.php', 'gravityflow/gravityflow.php');
update_option('active_plugins', $plugins_to_active);
GFForms::setup(true);
GFForms::loaded();
gravity_flow()->setup();
/**
 * A child class of the PHP test runner.
 *
 * Not actually used as a runner. Rather, used to access the protected
 * longOptions property, to parse the arguments passed to the script.
 *
 * If it is determined that phpunit was called with a --group that corresponds
 * to an @ticket annotation (such as `phpunit --group 12345` for bugs marked
 * as #WP12345), then it is assumed that known bugs should not be skipped.
 *
 * If WP_TESTS_FORCE_KNOWN_BUGS is already set in wp-tests-config.php, then
 * how you call phpunit has no effect.
 */
class WP_PHPUnit_TextUI_Command extends PHPUnit_TextUI_Command
{
    public static function render()
    {
        $form_id = 0;
        $entries = rgget('lid');
        if (0 == $entries) {
            // get all the entry ids for the current filter / search
            $filter = rgget('filter');
            $search = rgget('search');
            $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) {
                $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');
            $search_operator = rgget('operator');
            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);
            }
            $entry_ids = GFFormsModel::search_lead_ids($form_id, $search_criteria);
        } else {
            $entry_ids = explode(',', $entries);
        }
        $page_break = rgget('page_break') ? 'print-page-break' : false;
        // sort lead IDs numerically
        sort($entry_ids);
        if (empty($entry_ids)) {
            die(esc_html__('Form Id and Lead Id are required parameters.', 'gravityflow'));
        }
        $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') . $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' />
			<?php 
        $styles = apply_filters('gravityflow_print_styles', false);
        if (!empty($styles)) {
            wp_print_styles($styles);
        }
        ?>
		</head>
		<body>

		<div id="view-container">
			<?php 
        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
            global $current_user;
            if ($entry['created_by'] != $current_user->ID) {
                $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;
                            }
                        }
                    }
                }
                $full_access = GFAPI::current_user_can_any(array('gform_full_access', 'gravityflow_status_view_all'));
                if (!($user_status || $full_access)) {
                    esc_attr_e("You don't have permission to view this entry.", 'gravityflow');
                    continue;
                }
            }
            require_once $gravity_flow->get_base_path() . '/includes/pages/class-entry-detail.php';
            Gravity_Flow_Entry_Detail::entry_detail_grid($form, $entry, false, array(), $current_step);
            echo '</form>';
            if (rgget('notes')) {
                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 
    }