public static function user_can_edit($entry, $form = false)
 {
     if (empty($form)) {
         FrmEntry::maybe_get_entry($entry);
         if (is_object($entry)) {
             $form = $entry->form_id;
         }
     }
     FrmForm::maybe_get_form($form);
     self::maybe_get_parent_form_and_entry($form, $entry);
     $allowed = self::user_can_edit_check($entry, $form);
     return apply_filters('frm_user_can_edit', $allowed, compact('entry', 'form'));
 }
 public static function get_form_nav($form, $show_nav = false, $title = 'show')
 {
     $show_nav = FrmAppHelper::get_param('show_nav', $show_nav, 'get', 'absint');
     if (empty($show_nav) || !$form) {
         return;
     }
     FrmForm::maybe_get_form($form);
     if (!is_object($form)) {
         return;
     }
     $id = $form->id;
     $current_page = self::get_current_page();
     $nav_items = self::get_form_nav_items($form);
     include FrmAppHelper::plugin_path() . '/classes/views/shared/form-nav.php';
 }
 public static function get_form_nav($form, $show_nav = '', $title = 'show')
 {
     global $pagenow, $frm_vars;
     $show_nav = FrmAppHelper::get_param('show_nav', $show_nav, 'get', 'absint');
     if (empty($show_nav)) {
         return;
     }
     $current_page = isset($_GET['page']) ? FrmAppHelper::simple_get('page', 'sanitize_title') : FrmAppHelper::simple_get('post_type', 'sanitize_title', 'None');
     if ($form) {
         FrmForm::maybe_get_form($form);
         if (is_object($form)) {
             $id = $form->id;
         }
     }
     if (!isset($id)) {
         $form = $id = false;
     }
     include FrmAppHelper::plugin_path() . '/classes/views/shared/form-nav.php';
 }
 /**
  * @param string $table
  */
 private static function fill_form_opts($record, $table, $post_values, array &$values)
 {
     if ($table == 'entries') {
         $form = $record->form_id;
         FrmForm::maybe_get_form($form);
     } else {
         $form = $record;
     }
     if (!$form) {
         return;
     }
     $values['form_name'] = isset($record->form_id) ? $form->name : '';
     $values['parent_form_id'] = isset($record->form_id) ? $form->parent_form_id : 0;
     if (!is_array($form->options)) {
         return;
     }
     foreach ($form->options as $opt => $value) {
         $values[$opt] = isset($post_values[$opt]) ? maybe_unserialize($post_values[$opt]) : $value;
     }
     self::fill_form_defaults($post_values, $values);
 }
 /**
  * @param string $event
  */
 public static function trigger_actions($event, $form, $entry, $type = 'all', $args = array())
 {
     $form_actions = FrmFormAction::get_action_for_form(is_object($form) ? $form->id : $form, $type);
     if (empty($form_actions)) {
         return;
     }
     FrmForm::maybe_get_form($form);
     $link_settings = self::get_form_actions($type);
     if ('all' != $type) {
         $link_settings = array($type => $link_settings);
     }
     $stored_actions = $action_priority = array();
     foreach ($form_actions as $action) {
         if (!in_array($event, $action->post_content['event'])) {
             continue;
         }
         if (!is_object($entry)) {
             $entry = FrmEntry::getOne($entry, true);
         }
         if (empty($entry) || $entry->is_draft) {
             continue;
         }
         $child_entry = $form && is_numeric($form->parent_form_id) && $form->parent_form_id || $entry && ($entry->form_id != $form->id || $entry->parent_item_id) || isset($args['is_child']) && $args['is_child'];
         if ($child_entry) {
             //don't trigger actions for sub forms
             continue;
         }
         // check conditional logic
         $stop = FrmFormAction::action_conditions_met($action, $entry);
         if ($stop) {
             continue;
         }
         // store actions so they can be triggered with the correct priority
         $stored_actions[$action->ID] = $action;
         $action_priority[$action->ID] = $link_settings[$action->post_excerpt]->action_options['priority'];
         unset($action);
     }
     if (!empty($stored_actions)) {
         asort($action_priority);
         // make sure hooks are loaded
         new FrmNotification();
         foreach ($action_priority as $action_id => $priority) {
             $action = $stored_actions[$action_id];
             do_action('frm_trigger_' . $action->post_excerpt . '_action', $action, $entry, $form, $event);
             do_action('frm_trigger_' . $action->post_excerpt . '_' . $event . '_action', $action, $entry, $form);
             // If post is created, get updated $entry object
             if ($action->post_excerpt == 'wppost' && $event == 'create') {
                 $entry = FrmEntry::getOne($entry->id, true);
             }
         }
     }
 }
 public static function maybe_get_form(&$form)
 {
     _deprecated_function(__FUNCTION__, '2.0.9', 'FrmForm::maybe_get_form');
     FrmForm::maybe_get_form($form);
 }
 /**
  * @param string $event
  */
 public static function trigger_actions($event, $form, $entry, $type = 'all', $args = array())
 {
     $form_actions = FrmFormAction::get_action_for_form(is_object($form) ? $form->id : $form, $type);
     if (empty($form_actions)) {
         return;
     }
     FrmForm::maybe_get_form($form);
     $link_settings = self::get_form_actions($type);
     if ('all' != $type) {
         $link_settings = array($type => $link_settings);
     }
     $stored_actions = $action_priority = array();
     $importing = in_array($event, array('create', 'update')) && defined('WP_IMPORTING') && WP_IMPORTING;
     foreach ($form_actions as $action) {
         $trigger_on_import = $importing && in_array('import', $action->post_content['event']);
         $skip_this_action = !in_array($event, $action->post_content['event']) && !$trigger_on_import;
         $skip_this_action = apply_filters('frm_skip_form_action', $skip_this_action, compact('action', 'entry', 'form', 'event'));
         if ($skip_this_action) {
             continue;
         }
         if (!is_object($entry)) {
             $entry = FrmEntry::getOne($entry, true);
         }
         if (empty($entry) || $entry->is_draft && $event != 'draft') {
             continue;
         }
         $child_entry = $form && is_numeric($form->parent_form_id) && $form->parent_form_id || $entry && ($entry->form_id != $form->id || $entry->parent_item_id) || isset($args['is_child']) && $args['is_child'];
         if ($child_entry) {
             // maybe trigger actions for sub forms
             $trigger_children = apply_filters('frm_use_embedded_form_actions', false, compact('form', 'entry'));
             if (!$trigger_children) {
                 continue;
             }
         }
         // check conditional logic
         $stop = FrmFormAction::action_conditions_met($action, $entry);
         if ($stop) {
             continue;
         }
         // store actions so they can be triggered with the correct priority
         $stored_actions[$action->ID] = $action;
         $action_priority[$action->ID] = $link_settings[$action->post_excerpt]->action_options['priority'];
         unset($action);
     }
     if (!empty($stored_actions)) {
         asort($action_priority);
         // make sure hooks are loaded
         new FrmNotification();
         foreach ($action_priority as $action_id => $priority) {
             $action = $stored_actions[$action_id];
             do_action('frm_trigger_' . $action->post_excerpt . '_action', $action, $entry, $form, $event);
             do_action('frm_trigger_' . $action->post_excerpt . '_' . $event . '_action', $action, $entry, $form);
             // If post is created, get updated $entry object
             if ($action->post_excerpt == 'wppost' && $event == 'create') {
                 $entry = FrmEntry::getOne($entry->id, true);
             }
         }
     }
 }
 public static function repeat_field_set($field_name, $args = array())
 {
     $defaults = array('i' => 0, 'entry_id' => false, 'form' => false, 'fields' => array(), 'errors' => array(), 'parent_field' => 0, 'repeat' => 0, 'row_count' => false, 'value' => '', 'field_name' => '');
     $args = wp_parse_args($args, $defaults);
     if (empty($args['parent_field'])) {
         return;
     }
     if (is_numeric($args['parent_field'])) {
         $args['parent_field'] = (array) FrmField::getOne($args['parent_field']);
         $args['parent_field']['format'] = isset($args['parent_field']['field_options']['format']) ? $args['parent_field']['field_options']['format'] : '';
     }
     FrmForm::maybe_get_form($args['form']);
     if (empty($args['fields'])) {
         $args['fields'] = FrmField::get_all_for_form($args['form']->id);
     }
     $values = array();
     if ($args['fields']) {
         // Get the ID of the form that houses the embedded form or repeating section
         $parent_form_id = $args['parent_field']['form_id'];
         if (empty($args['entry_id'])) {
             $values = FrmEntriesHelper::setup_new_vars($args['fields'], $args['form'], false, array('parent_form_id' => $parent_form_id));
         } else {
             $entry = FrmEntry::getOne($args['entry_id'], true);
             if ($entry && $entry->form_id == $args['form']->id) {
                 $values = FrmAppHelper::setup_edit_vars($entry, 'entries', $args['fields'], false, array(), array('parent_form_id' => $parent_form_id));
             } else {
                 return;
             }
         }
     }
     $format = isset($args['parent_field']['format']) ? $args['parent_field']['format'] : '';
     $end = false;
     $count = 0;
     foreach ($values['fields'] as $subfield) {
         if ('end_divider' == $subfield['type']) {
             $end = $subfield;
         } else {
             if (!in_array($subfield['type'], array('hidden', 'user_id'))) {
                 if (isset($subfield['conf_field']) && $subfield['conf_field']) {
                     $count = $count + 2;
                 } else {
                     $count++;
                 }
             }
         }
         unset($subfield);
     }
     if ($args['repeat']) {
         $count++;
     }
     $classes = array(2 => 'half', 3 => 'third', 4 => 'fourth', 5 => 'fifth', 6 => 'sixth', 7 => 'seventh', 8 => 'eighth');
     $field_class = !empty($format) && isset($classes[$count]) ? $classes[$count] : '';
     echo '<div id="frm_section_' . $args['parent_field']['id'] . '-' . $args['i'] . '" class="frm_repeat_' . (empty($format) ? 'sec' : $format) . ' frm_repeat_' . $args['parent_field']['id'] . ($args['row_count'] === 0 ? ' frm_first_repeat' : '') . '">' . "\n";
     self::add_hidden_repeat_entry_id($args);
     self::add_default_item_meta_field($args);
     $label_pos = 'top';
     $field_num = 1;
     foreach ($values['fields'] as $subfield) {
         $subfield_name = $field_name . '[' . $args['i'] . '][' . $subfield['id'] . ']';
         $subfield_plus_id = '-' . $args['i'];
         $subfield_id = $subfield['id'] . '-' . $args['parent_field']['id'] . $subfield_plus_id;
         if ($args['parent_field'] && !empty($args['parent_field']['value']) && isset($args['parent_field']['value']['form']) && isset($args['parent_field']['value'][$args['i']]) && isset($args['parent_field']['value'][$args['i']][$subfield['id']])) {
             // this is a posted value from moving between pages, so set the POSTed value
             $subfield['value'] = $args['parent_field']['value'][$args['i']][$subfield['id']];
         }
         if (!empty($field_class)) {
             if (1 == $field_num) {
                 $subfield['classes'] .= ' frm_first frm_' . $field_class;
             } else {
                 $subfield['classes'] .= ' frm_' . $field_class;
             }
         }
         $field_num++;
         if ('top' == $label_pos && in_array($subfield['label'], array('top', 'hidden', ''))) {
             // add placeholder label if repeating
             $label_pos = 'hidden';
         }
         $field_args = array('field_name' => $subfield_name, 'field_id' => $subfield_id, 'field_plus_id' => $subfield_plus_id, 'section_id' => $args['parent_field']['id']);
         if (apply_filters('frm_show_normal_field_type', true, $subfield['type'])) {
             echo FrmFieldsHelper::replace_shortcodes($subfield['custom_html'], $subfield, $args['errors'], $args['form'], $field_args);
         } else {
             do_action('frm_show_other_field_type', $subfield, $args['form'], $field_args);
         }
         unset($subfield_name, $subfield_id);
         do_action('frm_get_field_scripts', $subfield, $args['form'], $args['parent_field']['form_id']);
     }
     if (!$args['repeat']) {
         // Close frm_repeat div
         echo '</div>' . "\n";
         return;
     }
     $args['format'] = $format;
     $args['label_pos'] = $label_pos;
     $args['field_class'] = $field_class;
     echo self::repeat_buttons($args, $end);
     // Close frm_repeat div
     echo '</div>' . "\n";
 }