public static function validate($values, $exclude = false)
 {
     global $wpdb;
     FrmEntry::sanitize_entry_post($values);
     $errors = array();
     if (!isset($values['form_id']) || !isset($values['item_meta'])) {
         $errors['form'] = __('There was a problem with your submission. Please try again.', 'formidable');
         return $errors;
     }
     if (FrmAppHelper::is_admin() && is_user_logged_in() && (!isset($values['frm_submit_entry_' . $values['form_id']]) || !wp_verify_nonce($values['frm_submit_entry_' . $values['form_id']], 'frm_submit_entry_nonce'))) {
         $errors['form'] = __('You do not have permission to do that', 'formidable');
     }
     if (!isset($values['item_key']) || $values['item_key'] == '') {
         $_POST['item_key'] = $values['item_key'] = FrmAppHelper::get_unique_key('', $wpdb->prefix . 'frm_items', 'item_key');
     }
     $where = apply_filters('frm_posted_field_ids', array('fi.form_id' => $values['form_id']));
     // Don't get subfields
     $where['fr.parent_form_id'] = array(null, 0);
     // Don't get excluded fields (like file upload fields in the ajax validation)
     if (!empty($exclude)) {
         $where['fi.type not'] = $exclude;
     }
     $posted_fields = FrmField::getAll($where, 'field_order');
     // Pass exclude value to validate_field function so it can be used for repeating sections
     $args = array('exclude' => $exclude);
     foreach ($posted_fields as $posted_field) {
         self::validate_field($posted_field, $errors, $values, $args);
         unset($posted_field);
     }
     // check for spam
     self::spam_check($exclude, $values, $errors);
     $errors = apply_filters('frm_validate_entry', $errors, $values, compact('exclude'));
     return $errors;
 }
 /**
  * @covers FrmField::getAll
  */
 function test_getAll()
 {
     $form_id = $this->factory->form->get_id_by_key($this->contact_form_key);
     $fields = FrmField::getAll(array('fi.form_id' => (int) $form_id));
     $this->assertNotEmpty($fields);
     $this->assertTrue(count($fields) >= 7);
     foreach ($fields as $field) {
     }
 }
 /**
  * @covers FrmField::getAll
  */
 function test_getAll()
 {
     $forms = array($this->contact_form_key => 8, $this->all_fields_form_key => 33);
     foreach ($forms as $form_key => $expected_count) {
         $form_id = $this->factory->form->get_id_by_key($form_key);
         $fields = FrmField::getAll(array('fi.form_id' => (int) $form_id));
         $this->assertNotEmpty($fields);
         $this->assertEquals($expected_count, count($fields), 'An incorrect number of fields are retrieved with FrmField::getAll.');
     }
 }
 public static function csv($form_id = false, $search = '', $fid = '')
 {
     FrmAppHelper::permission_check('frm_view_entries');
     if (!$form_id) {
         $form_id = FrmAppHelper::get_param('form', '', 'get', 'sanitize_text_field');
         $search = FrmAppHelper::get_param(isset($_REQUEST['s']) ? 's' : 'search', '', 'get', 'sanitize_text_field');
         $fid = FrmAppHelper::get_param('fid', '', 'get', 'sanitize_text_field');
     }
     if (!ini_get('safe_mode')) {
         set_time_limit(0);
         //Remove time limit to execute this function
         $mem_limit = str_replace('M', '', ini_get('memory_limit'));
         if ((int) $mem_limit < 256) {
             ini_set('memory_limit', '256M');
         }
     }
     global $wpdb;
     $form = FrmForm::getOne($form_id);
     $form_id = $form->id;
     $where = array('fi.type not' => FrmField::no_save_fields());
     $where[] = array('or' => 1, 'fi.form_id' => $form->id, 'fr.parent_form_id' => $form->id);
     $csv_fields = apply_filters('frm_csv_field_ids', '', $form_id, array('form' => $form));
     if ($csv_fields) {
         if (!is_array($csv_fields)) {
             $csv_fields = explode(',', $csv_fields);
         }
         if (!empty($csv_fields)) {
             $where['fi.id'] = $csv_fields;
         }
     }
     $form_cols = FrmField::getAll($where, 'field_order');
     $item_id = FrmAppHelper::get_param('item_id', false, 'get', 'sanitize_text_field');
     if (!empty($item_id)) {
         $item_id = explode(',', $item_id);
     }
     $query = array('form_id' => $form_id);
     if ($item_id) {
         $query['id'] = $item_id;
     }
     if (!empty($search) && !$item_id) {
         $query = FrmProEntriesHelper::get_search_str($query, $search, $form_id, $fid);
     }
     /**
      * Allows the query to be changed for fetching the entry ids to include in the export
      *
      * $query is the array of options to be filtered. It includes form_id, and maybe id (array of entry ids),
      * and the search query. This should return an array, but it can be handled as a string as well.
      */
     $query = apply_filters('frm_csv_where', $query, compact('form_id'));
     $entry_ids = FrmDb::get_col($wpdb->prefix . 'frm_items it', $query);
     unset($query);
     if (empty($entry_ids)) {
         esc_html_e('There are no entries for that form.', 'formidable');
     } else {
         FrmProCSVExportHelper::generate_csv(compact('form', 'entry_ids', 'form_cols'));
     }
     wp_die();
 }
Esempio n. 5
0
 /**
  * Switch repeating section forms to published and give them names
  */
 private static function migrate_to_29()
 {
     // Get all section fields
     $dividers = FrmField::getAll(array('fi.type' => 'divider'));
     // Update the form name and status for repeating sections
     foreach ($dividers as $d) {
         if (!FrmField::is_repeating_field($d)) {
             continue;
         }
         $form_id = $d->field_options['form_select'];
         $new_name = $d->name;
         if ($form_id && is_numeric($form_id)) {
             FrmForm::update($form_id, array('name' => $new_name, 'status' => 'published'));
         }
     }
 }
 public static function sortable_columns()
 {
     $form_id = FrmProAppHelper::get_current_form_id();
     $frm_field = new FrmField();
     $fields = $frm_field->getAll(array('fi.form_id' => $form_id));
     unset($frm_field);
     $columns = array($form_id . '_id' => 'id', $form_id . '_created_at' => 'created_at', $form_id . '_updated_at' => 'updated_at', $form_id . '_ip' => 'ip', $form_id . '_item_key' => 'item_key', $form_id . '_is_draft' => 'is_draft');
     foreach ($fields as $field) {
         if ($field->type != 'checkbox' && (!isset($field->field_options['post_field']) || $field->field_options['post_field'] == '')) {
             // Can't sort on checkboxes because they are stored serialized, or post fields
             $columns[$form_id . '_' . $field->field_key] = 'meta_' . $field->id;
         }
     }
     return $columns;
 }
Esempio n. 7
0
    function form($instance)
    {
        $pages = get_posts(array('post_type' => 'page', 'post_status' => 'publish', 'numberposts' => 999, 'order_by' => 'post_title', 'order' => 'ASC'));
        $displays = FrmProDisplay::getAll(array('meta_key' => 'frm_show_count', 'meta_value' => 'dynamic'));
        //Defaults
        $instance = wp_parse_args((array) $instance, array('title' => false, 'display_id' => false, 'post_id' => false, 'title_id' => false, 'cat_list' => false, 'cat_name' => false, 'cat_count' => false, 'cat_id' => false, 'limit' => false));
        if ($instance['display_id']) {
            $selected_display = FrmProDisplay::getOne($instance['display_id']);
            if ($selected_display) {
                $selected_form_id = get_post_meta($selected_display->ID, 'frm_form_id', true);
                $title_opts = FrmField::getAll(array('fi.form_id' => (int) $selected_form_id, 'type not' => FrmField::no_save_fields()), 'field_order');
                $instance['display_id'] = $selected_display->ID;
            }
        }
        ?>
	<p><label for="<?php 
        echo $this->get_field_id('title');
        ?>
"><?php 
        _e('Title', 'formidable');
        ?>
:</label>
	<input type="text" class="widefat" id="<?php 
        echo $this->get_field_id('title');
        ?>
" name="<?php 
        echo $this->get_field_name('title');
        ?>
" value="<?php 
        echo esc_attr(stripslashes($instance['title']));
        ?>
" /></p>

	<p><label for="<?php 
        echo $this->get_field_id('display_id');
        ?>
"><?php 
        _e('Use Settings from View', 'formidable');
        ?>
:</label>
	    <select name="<?php 
        echo $this->get_field_name('display_id');
        ?>
" id="<?php 
        echo $this->get_field_id('display_id');
        ?>
" class="widefat frm_list_items_display_id">
	        <option value=""> </option>
            <?php 
        foreach ($displays as $display) {
            echo '<option value="' . esc_attr($display->ID) . '" ' . selected($instance['display_id'], $display->ID, false) . '>' . FrmAppHelper::kses($display->post_title) . '</option>';
        }
        ?>
        </select>
	</p>
	<p class="description"><?php 
        _e('Views with a "Both (Dynamic)" format will show here.', 'formidable');
        ?>
</p>

	<p><label for="<?php 
        echo $this->get_field_id('post_id');
        ?>
"><?php 
        _e('Page if not specified in View settings', 'formidable');
        ?>
:</label>
        <select name="<?php 
        echo $this->get_field_name('post_id');
        ?>
" id="<?php 
        echo $this->get_field_id('post_id');
        ?>
" class="widefat">
	        <option value=""> </option>
            <?php 
        foreach ($pages as $page) {
            echo '<option value="' . esc_attr($page->ID) . '" ' . selected($instance['post_id'], $page->ID, false) . '>' . $page->post_title . '</option>';
        }
        ?>
        </select>
    </p>

    <p><label for="<?php 
        echo $this->get_field_id('title_id');
        ?>
"><?php 
        _e('Title Field', 'formidable');
        ?>
:</label>
        <select name="<?php 
        echo $this->get_field_name('title_id');
        ?>
" id="<?php 
        echo $this->get_field_id('title_id');
        ?>
" class="widefat frm_list_items_title_id">
	        <option value=""> </option>
            <?php 
        if (isset($title_opts) && $title_opts) {
            foreach ($title_opts as $title_opt) {
                if ($title_opt->type != 'checkbox') {
                    ?>
                        <option value="<?php 
                    echo $title_opt->id;
                    ?>
" <?php 
                    selected($instance['title_id'], $title_opt->id);
                    ?>
><?php 
                    echo $title_opt->name;
                    ?>
</option>
                        <?php 
                }
            }
        }
        ?>
        </select>
	</p>

    <p><label for="<?php 
        echo $this->get_field_id('cat_list');
        ?>
"><input class="checkbox frm_list_items_cat_list" type="checkbox" <?php 
        checked($instance['cat_list'], true);
        ?>
 id="<?php 
        echo $this->get_field_id('cat_list');
        ?>
" name="<?php 
        echo $this->get_field_name('cat_list');
        ?>
" value="1" />
	<?php 
        _e('List Entries by Category', 'formidable');
        ?>
</label></p>

    <div id="<?php 
        echo $this->get_field_id('hide_cat_opts');
        ?>
" class="frm_list_items_hide_cat_opts <?php 
        echo $instance['cat_list'] ? '' : 'frm_hidden';
        ?>
">
    <p><label for="<?php 
        echo $this->get_field_id('cat_id');
        ?>
"><?php 
        _e('Category Field', 'formidable');
        ?>
:</label>
	    <select name="<?php 
        echo $this->get_field_name('cat_id');
        ?>
" id="<?php 
        echo $this->get_field_id('cat_id');
        ?>
" class="widefat frm_list_items_cat_id">
	        <option value=""> </option>
	        <?php 
        if (isset($title_opts) && $title_opts) {
            foreach ($title_opts as $title_opt) {
                if (in_array($title_opt->type, array('select', 'radio', 'checkbox'))) {
                    echo '<option value="' . esc_attr($title_opt->id) . '"' . selected($instance['cat_id'], $title_opt->id, false) . '>' . FrmAppHelper::kses($title_opt->name) . '</option>';
                }
            }
        }
        ?>
        </select>
	</p>

	<p><label for="<?php 
        echo $this->get_field_id('cat_count');
        ?>
"><input class="checkbox" type="checkbox" <?php 
        checked($instance['cat_count'], true);
        ?>
 id="<?php 
        echo $this->get_field_id('cat_count');
        ?>
" name="<?php 
        echo $this->get_field_name('cat_count');
        ?>
" value="1" />
	<?php 
        _e('Show Entry Counts', 'formidable');
        ?>
</label></p>

	<p><input class="checkbox" type="radio" <?php 
        checked($instance['cat_name'], 1);
        ?>
 id="<?php 
        echo $this->get_field_id('cat_name');
        ?>
" name="<?php 
        echo $this->get_field_name('cat_name');
        ?>
" value="1" />
	<label for="<?php 
        echo $this->get_field_id('cat_name');
        ?>
"><?php 
        _e('Show Only Category Name', 'formidable');
        ?>
</label><br/>

	<input class="checkbox" type="radio" <?php 
        checked($instance['cat_name'], 0);
        ?>
 id="<?php 
        echo $this->get_field_id('cat_name');
        ?>
" name="<?php 
        echo $this->get_field_name('cat_name');
        ?>
" value="0" />
	<label for="<?php 
        echo $this->get_field_id('cat_name');
        ?>
"><?php 
        _e('Show Entries Beneath Categories', 'formidable');
        ?>
</label></p>
	</div>

	<p><label for="<?php 
        echo $this->get_field_id('limit');
        ?>
"><?php 
        _e('Entry Limit (leave blank to list all)', 'formidable');
        ?>
:</label>
	<input type="text" class="widefat" id="<?php 
        echo $this->get_field_id('limit');
        ?>
" name="<?php 
        echo $this->get_field_name('limit');
        ?>
" value="<?php 
        echo esc_attr($instance['limit']);
        ?>
" /></p>

<?php 
    }
Esempio n. 8
0
 public static function validate_embedded_form(&$errors, $field, $exclude = array())
 {
     // Check if this section is conditionally hidden before validating the nested fields
     self::validate_no_input_fields($errors, $field);
     $subforms = array();
     FrmProFieldsHelper::get_subform_ids($subforms, $field);
     if (empty($subforms)) {
         return;
     }
     $where = array('fi.form_id' => $subforms);
     if (!empty($exclude)) {
         $where['fi.type not'] = $exclude;
     }
     $subfields = FrmField::getAll($where, 'field_order');
     unset($where);
     foreach ($subfields as $subfield) {
         if (isset($_POST['item_meta'][$field->id]) && !empty($_POST['item_meta'][$field->id])) {
             foreach ($_POST['item_meta'][$field->id] as $k => $values) {
                 if (!empty($k) && in_array($k, array('form', 'id'))) {
                     continue;
                 }
                 FrmEntryValidate::validate_field($subfield, $errors, isset($values[$subfield->id]) ? $values[$subfield->id] : '', array('parent_field_id' => $field->id, 'key_pointer' => $k, 'id' => $subfield->id . '-' . $field->id . '-' . $k));
                 unset($k, $values);
             }
         } else {
             // TODO: do something if nothing was submitted
         }
     }
 }
 function _logic_row()
 {
     global $frm_ajax_url;
     $meta_name = FrmAppHelper::get_param('meta_name');
     $form_id = FrmAppHelper::get_param('form_id');
     $field_id = FrmAppHelper::get_param('field_id');
     $hide_field = '';
     $form_fields = FrmField::getAll("fi.form_id = " . $form_id . " and (type in ('select','radio','checkbox','10radio','scale','data') or (type = 'data' and (field_options LIKE '\"data_type\";s:6:\"select\"%' OR field_options LIKE '%\"data_type\";s:5:\"radio\"%' OR field_options LIKE '%\"data_type\";s:8:\"checkbox\"%') )) and fi.id != " . $field_id, " ORDER BY field_order");
     $field = FrmField::getOne($field_id);
     $field = FrmFieldsHelper::setup_edit_vars($field);
     if (!isset($field['hide_field_cond'][$meta_name])) {
         $field['hide_field_cond'][$meta_name] = '==';
     }
     include FRMPRO_VIEWS_PATH . '/frmpro-fields/_logic_row.php';
     die;
 }
    public function search_box($text, $input_id)
    {
        if (!$this->has_items() && !isset($_REQUEST['s'])) {
            return;
        }
        if (isset($this->params['form'])) {
            $form = FrmForm::getOne($this->params['form']);
        } else {
            $form = FrmForm::get_published_forms(array(), 1);
        }
        if ($form) {
            $field_list = FrmField::getAll(array('fi.form_id' => $form->id, 'fi.type not' => FrmField::no_save_fields()), 'field_order');
        }
        $fid = isset($_REQUEST['fid']) ? esc_attr(stripslashes($_REQUEST['fid'])) : '';
        $input_id = $input_id . '-search-input';
        $search_str = isset($_REQUEST['s']) ? esc_attr(stripslashes($_REQUEST['s'])) : '';
        foreach (array('orderby', 'order') as $get_var) {
            if (!empty($_REQUEST[$get_var])) {
                echo '<input type="hidden" name="' . esc_attr($get_var) . '" value="' . esc_attr($_REQUEST[$get_var]) . '" />';
            }
        }
        ?>
<div class="search-box frm_sidebar">
	<label class="screen-reader-text" for="<?php 
        echo esc_attr($input_id);
        ?>
"><?php 
        echo esc_attr($text);
        ?>
:</label>
	<input type="text" id="<?php 
        echo esc_attr($input_id);
        ?>
" name="s" value="<?php 
        echo esc_attr($search_str);
        ?>
" />
	<?php 
        if (isset($field_list) && !empty($field_list)) {
            ?>
	<select name="fid" class="hide-if-js">
		<option value="">&mdash; <?php 
            _e('All Fields', 'formidable');
            ?>
 &mdash;</option>
		<option value="created_at" <?php 
            selected($fid, 'created_at');
            ?>
><?php 
            _e('Entry creation date', 'formidable');
            ?>
</option>
		<option value="id" <?php 
            selected($fid, 'id');
            ?>
><?php 
            _e('Entry ID', 'formidable');
            ?>
</option>
		<?php 
            foreach ($field_list as $f) {
                ?>
		<option value="<?php 
                echo $f->type == 'user_id' ? 'user_id' : $f->id;
                ?>
" <?php 
                selected($fid, $f->id);
                ?>
><?php 
                echo FrmAppHelper::truncate($f->name, 30);
                ?>
</option>
		<?php 
            }
            ?>
	</select>

	<div class="button dropdown hide-if-no-js">
		<a href="#" id="frm-fid-search" class="frm-dropdown-toggle" data-toggle="dropdown"><?php 
            _e('Search', 'formidable');
            ?>
 <b class="caret"></b></a>
		<ul class="frm-dropdown-menu pull-right" id="frm-fid-search-menu" role="menu" aria-labelledby="frm-fid-search">
			<li><a href="#" id="fid-">&mdash; <?php 
            _e('All Fields', 'formidable');
            ?>
 &mdash;</a></li>
			<li><a href="#" id="fid-created_at"><?php 
            _e('Entry creation date', 'formidable');
            ?>
</a></li>
			<li><a href="#" id="fid-id"><?php 
            _e('Entry ID', 'formidable');
            ?>
</a></li>
			<?php 
            foreach ($field_list as $f) {
                ?>
			<li><a href="#" id="fid-<?php 
                echo $f->type == 'user_id' ? 'user_id' : $f->id;
                ?>
"><?php 
                echo FrmAppHelper::truncate($f->name, 30);
                ?>
</a></li>
			<?php 
                unset($f);
            }
            ?>
		</ul>
	</div>
	<?php 
            submit_button($text, 'button hide-if-js', false, false, array('id' => 'search-submit'));
        } else {
            submit_button($text, 'button', false, false, array('id' => 'search-submit'));
            if (!empty($search_str)) {
                ?>
	<a href="<?php 
                echo esc_url(admin_url('admin.php?page=formidable-entries&frm_action=list&form=' . $form->id));
                ?>
"><?php 
                _e('Reset', 'formidable');
                ?>
</a>
	<?php 
            }
        }
        ?>

</div>
<?php 
    }
Esempio n. 11
0
 public static function has_field($type, $form_id, $single = true)
 {
     global $wpdb;
     $frm_field = new FrmField();
     if ($single) {
         $included = $wpdb->get_var($wpdb->prepare("SELECT id FROM {$wpdb->prefix}frm_fields WHERE form_id=%d AND type=%s", $form_id, $type));
         if ($included) {
             $included = $frm_field->getOne($included);
         }
     } else {
         $included = $frm_field->getAll(array('type' => $type, 'fi.form_id' => $form_id));
     }
     return $included;
 }
Esempio n. 12
0
 public static function import_xml_forms($forms, $imported)
 {
     $frm_form = new FrmForm();
     $frm_field = new FrmField();
     foreach ($forms as $item) {
         $form = array('id' => (int) $item->id, 'form_key' => (string) $item->form_key, 'name' => (string) $item->name, 'description' => (string) $item->description, 'options' => (string) $item->options, 'logged_in' => (int) $item->logged_in, 'is_template' => (int) $item->is_template, 'default_template' => (int) $item->default_template, 'editable' => (int) $item->editable, 'status' => (string) $item->status, 'created_at' => date('Y-m-d H:i:s', strtotime((string) $item->created_at)));
         $form['options'] = FrmAppHelper::maybe_json_decode($form['options']);
         // if template, allow to edit if form keys match, otherwise, creation date must also match
         $edit_query = array('form_key' => $form['form_key'], 'is_template' => $form['is_template']);
         if (!$form['is_template']) {
             $edit_query['created_at'] = $form['created_at'];
         }
         $edit_query = apply_filters('frm_match_xml_form', $edit_query, $form);
         $this_form = $frm_form->getAll($edit_query, '', 1);
         unset($edit_query);
         if (!empty($this_form)) {
             $form_id = $this_form->id;
             $frm_form->update($form_id, $form);
             $imported['updated']['forms']++;
             $form_fields = $frm_field->getAll(array('fi.form_id' => $form_id), 'field_order');
             $old_fields = array();
             foreach ($form_fields as $f) {
                 $old_fields[$f->id] = $f;
                 $old_fields[$f->field_key] = $f->id;
                 unset($f);
             }
             $form_fields = $old_fields;
             unset($old_fields);
         } else {
             //form does not exist, so create it
             if ($form_id = $frm_form->create($form)) {
                 $imported['imported']['forms']++;
             }
         }
         foreach ($item->field as $field) {
             $f = array('id' => (int) $field->id, 'field_key' => (string) $field->field_key, 'name' => (string) $field->name, 'description' => (string) $field->description, 'type' => (string) $field->type, 'default_value' => FrmAppHelper::maybe_json_decode((string) $field->default_value), 'field_order' => (int) $field->field_order, 'form_id' => (int) $form_id, 'required' => (int) $field->required, 'options' => FrmAppHelper::maybe_json_decode((string) $field->options), 'field_options' => FrmAppHelper::maybe_json_decode((string) $field->field_options));
             if (is_array($f['default_value']) && in_array($f['type'], array('text', 'email', 'url', 'textarea', 'number', 'phone', 'date', 'time', 'image', 'hidden', 'password', 'tag'))) {
                 if (count($f['default_value']) === 1) {
                     $f['default_value'] = '[' . reset($f['default_value']) . ']';
                 } else {
                     $f['default_value'] = reset($f['default_value']);
                 }
             }
             $f = apply_filters('frm_duplicated_field', $f);
             if ($this_form) {
                 // check for field to edit by field id
                 if (isset($form_fields[$f['id']])) {
                     $frm_field->update($f['id'], $f);
                     $imported['updated']['fields']++;
                     unset($form_fields[$f['id']]);
                     //unset old field key
                     if (isset($form_fields[$f['field_key']])) {
                         unset($form_fields[$f['field_key']]);
                     }
                 } else {
                     if (isset($form_fields[$f['field_key']])) {
                         // check for field to edit by field key
                         unset($f['id']);
                         $frm_field->update($form_fields[$f['field_key']], $f);
                         $imported['updated']['fields']++;
                         unset($form_fields[$form_fields[$f['field_key']]]);
                         //unset old field id
                         unset($form_fields[$f['field_key']]);
                         //unset old field key
                     } else {
                         if ($frm_field->create($f)) {
                             // if no matching field id or key in this form, create the field
                             $imported['imported']['fields']++;
                         }
                     }
                 }
             } else {
                 if ($frm_field->create($f)) {
                     $imported['imported']['fields']++;
                 }
             }
             unset($field);
         }
         // Delete any fields attached to this form that were not included in the template
         if (isset($form_fields) && !empty($form_fields)) {
             foreach ($form_fields as $field) {
                 if (is_object($field)) {
                     $frm_field->destroy($field->id);
                 }
                 unset($field);
             }
             unset($form_fields);
         }
         // Update field ids/keys to new ones
         do_action('frm_after_duplicate_form', $form_id, $form);
         $imported['forms'][(int) $item->id] = $form_id;
         unset($form);
         unset($item);
     }
     unset($frm_form);
     unset($frm_field);
     return $imported;
 }
Esempio n. 13
0
 public static function repeat_buttons($args, $end = false)
 {
     $args['end_format'] = 'icon';
     if (!$end) {
         global $wpdb;
         // get end field
         $query = array('fi.form_id' => $args['parent_field']['form_id'], 'type' => 'end_divider', 'field_order >' => $args['parent_field']['field_order'] + 1);
         $end = (array) FrmField::getAll($query, 'field_order', 1);
         foreach (array('format', 'add_label', 'remove_label', 'classes') as $o) {
             if (isset($end['field_options'][$o])) {
                 $end[$o] = $end['field_options'][$o];
             }
         }
     }
     if ($end) {
         $args['add_label'] = $end['add_label'];
         $args['remove_label'] = $end['remove_label'];
         if (!empty($end['format'])) {
             $args['end_format'] = $end['format'];
         }
     }
     $triggers = self::repeat_button_html($args, $end);
     return apply_filters('frm_repeat_triggers', $triggers, $end, $args['parent_field'], $args['field_class']);
 }
 public static function _posttax_row()
 {
     check_ajax_referer('frm_ajax', 'nonce');
     if (isset($_POST['field_id'])) {
         $field_vars = array('meta_name' => $_POST['meta_name'], 'field_id' => $_POST['field_id'], 'show_exclude' => (int) $_POST['show_exclude'], 'exclude_cat' => (int) $_POST['show_exclude'] ? '-1' : 0);
     } else {
         $field_vars = array('meta_name' => '', 'field_id' => '', 'show_exclude' => 0, 'exclude_cat' => 0);
     }
     $tax_meta = (int) $_POST['tax_key'];
     $post_type = sanitize_text_field($_POST['post_type']);
     $action_key = (int) $_POST['action_key'];
     $action_control = FrmFormActionsController::get_form_actions('wppost');
     $action_control->_set($action_key);
     if ($post_type) {
         $taxonomies = get_object_taxonomies($post_type);
     }
     $values = array();
     if (isset($_POST['form_id'])) {
         $values['fields'] = FrmField::getAll(array('fi.form_id' => (int) $_POST['form_id'], 'fi.type' => array('checkbox', 'radio', 'select', 'tag', 'data')), 'field_order');
         $values['id'] = (int) $_POST['form_id'];
     }
     $echo = false;
     include FrmAppHelper::plugin_path() . '/pro/classes/views/frmpro-form-actions/_post_taxonomy_row.php';
     wp_die();
 }
 /**
  * Get field options.
  *
  * @see https://github.com/wp-premium/formidable-paypal/blob/3.02/models/FrmPaymentAction.php#L37-L42
  * @param int $form_id
  * @return array
  */
 private function get_field_options($form_id)
 {
     $form_fields = FrmField::getAll(array('fi.form_id' => absint($form_id), 'fi.type not' => array('divider', 'end_divider', 'html', 'break', 'captcha', 'rte', 'form')), 'field_order');
     return $form_fields;
 }
Esempio n. 16
0
    /**
     * Render Formidable Pro settings section
     *
     * @since 1.6
     *
     * @author Naomi C. Bush <*****@*****.**>
     *
     * @param array $values
     */
    public static function do_settings_section($values)
    {
        if (isset($values['id'])) {
            $frm_field = new FrmField();
            $form_fields = $frm_field->getAll("fi.form_id='{$values['id']}' and fi.type not in ('divider', 'html', 'break', 'captcha', 'rte', 'form')", ' ORDER BY field_order');
            unset($frm_field);
        }
        ?>
		<style type="text/css">
			.icon-affiliatewp:before {
				font-family: 'affwp-dashicons' !important;
				content: "\e000";
			}
		</style>
		<h2><span class="icon-affiliatewp"></span><?php 
        _e(' AffiliateWP', 'affiliate-wp');
        ?>
</h2>

		<table class="form-table">
			<tr>
				<th scope="row" nowrap="nowrap">
					<label for="affiliatewp_referral_description_field"><?php 
        _e('Referral description', 'affiliate-wp');
        ?>
</label>
				</th>
				<td>
					<select name="options[affiliatewp][referral_description_field]">
						<option value="">&mdash; <?php 
        _e('Select Field', 'affiliate-wp');
        ?>
 &mdash;</option>
						<?php 
        if (isset($form_fields) and is_array($form_fields)) {
            foreach ($form_fields as $field) {
                if ('checkbox' == $field->type) {
                    continue;
                }
                ?>
								<option value="<?php 
                echo $field->id;
                ?>
" <?php 
                selected($field->id, self::get_array_values($values, 'affiliatewp/referral_description_field'));
                ?>
>
									<?php 
                echo substr(esc_attr(stripslashes($field->name)), 0, 50);
                unset($field);
                ?>
								</option>
							<?php 
            }
        }
        ?>
					</select>
				</td>
			</tr>
			<tr>
				<th scope="row" nowrap="nowrap">
					<label for="affiliatewp_purchase_amount_field"><?php 
        _e('Purchase Amount', 'affiliate-wp');
        ?>
</label>
				</th>
				<td>
					<select name="options[affiliatewp][purchase_amount_field]">
						<option value="">&mdash; <?php 
        _e('Select Field', 'affiliate-wp');
        ?>
 &mdash;</option>
						<?php 
        if (isset($form_fields) and is_array($form_fields)) {
            foreach ($form_fields as $field) {
                if ($field->type == 'checkbox') {
                    continue;
                }
                ?>
								<option value="<?php 
                echo $field->id;
                ?>
" <?php 
                selected($field->id, self::get_array_values($values, 'affiliatewp/purchase_amount_field'));
                ?>
>
									<?php 
                echo substr(esc_attr(stripslashes($field->name)), 0, 50);
                unset($field);
                ?>
								</option>
							<?php 
            }
        }
        ?>
					</select>
				</td>
			</tr>
		</table>
	<?php 
    }
 function _posttax_row()
 {
     $field_vars = array('meta_name' => '', 'field_id' => '', 'show_exclude' => 0, 'exclude_cat' => 0);
     $post_type = $_POST['post_type'];
     $tax_key = $_POST['meta_name'];
     if ($post_type and function_exists('get_object_taxonomies')) {
         $taxonomies = get_object_taxonomies($post_type);
     }
     $values = array();
     if (isset($_POST['form_id'])) {
         $values['fields'] = FrmField::getAll("fi.form_id='{$_POST['form_id']}' and fi.type in ('checkbox', 'radio', 'select', 'tag', 'data')", ' ORDER BY field_order');
         $values['id'] = $_POST['form_id'];
     }
     $echo = false;
     include FRMPRO_VIEWS_PATH . '/frmpro-forms/_post_taxonomy_row.php';
     die;
 }
Esempio n. 18
0
 /**
  * Get the parent section field
  *
  * @since 2.0
  * @return Object|false The section field object if there is one
  */
 public static function get_parent_section($field, $form_id = 0)
 {
     if (!$form_id) {
         $form_id = $field->form_id;
     }
     $query = array('fi.field_order <' => $field->field_order - 1, 'fi.form_id' => $form_id, 'fi.type' => array('divider', 'end_divider'));
     $section = FrmField::getAll($query, 'field_order', 1);
     return $section;
 }
Esempio n. 19
0
 public static function get_dfe_parent($field, $entry_values, $parent = array())
 {
     if (!isset($field->field_options['hide_field']) || empty($field->field_options['hide_field'])) {
         return $parent;
     }
     global $importing_fields;
     foreach ($field->field_options['hide_field'] as $k => $hide_field) {
         if (!is_numeric($hide_field) || !isset($importing_fields[$hide_field]) || 'data' != $importing_fields[$hide_field]->type) {
             continue;
         }
         $parent['field_id'] = $hide_field;
         $parent['value'] = empty($field->field_options['hide_opt'][$k]) ? false : $field->field_options['hide_opt'][$k];
         if (isset($entry_values['item_meta'][$hide_field]) && is_numeric($entry_values['item_meta'][$hide_field])) {
             $parent['value'] = $entry_values['item_meta'][$hide_field];
         }
         $frm_field = new FrmField();
         $parent_field = $importing_fields[$hide_field];
         if (isset($importing_fields[$field->field_options['form_select']])) {
             $join_field = $importing_fields[$field->field_options['form_select']];
         } else {
             $join_field = $frm_field->getOne($field->field_options['form_select']);
             $importing_fields[$field->field_options['form_select']] = $join_field;
         }
         if ($parent_field->form_id != $join_field->form_id) {
             if ('data' == $parent_field->type) {
                 $dependent_parent = $frm_field->getAll(array('fi.form_id' => $join_field->form_id, 'type' => 'data'));
                 foreach ($dependent_parent as $dp) {
                     if ($parent_field->field_options['form_select'] == $dp->field_options['form_select']) {
                         $parent['field_id'] = $dp->id;
                     }
                     unset($dp);
                 }
             }
         }
         unset($k, $hide_field);
         break;
     }
     return $parent;
 }
 /**
  * Get the fields that should be included in the CSV export
  *
  * @since 2.0.19
  *
  * @param int $form_id
  * @param object $form
  * @return array $csv_fields
  */
 private static function get_fields_for_csv_export($form_id, $form)
 {
     // Phase frm_csv_field_ids out by 2.01.05
     $csv_field_ids = apply_filters('frm_csv_field_ids', '', $form_id, array('form' => $form));
     if ($csv_field_ids) {
         _deprecated_function('The frm_csv_field_ids filter', '2.0.19', 'the frm_csv_columns filter');
         $where = array('fi.type not' => FrmField::no_save_fields());
         $where[] = array('or' => 1, 'fi.form_id' => $form->id, 'fr.parent_form_id' => $form->id);
         if (!is_array($csv_field_ids)) {
             $csv_field_ids = explode(',', $csv_field_ids);
         }
         if (!empty($csv_field_ids)) {
             $where['fi.id'] = $csv_field_ids;
         }
         $csv_fields = FrmField::getAll($where, 'field_order');
     } else {
         $csv_fields = FrmField::get_all_for_form($form_id, '', 'include', 'include');
         $no_export_fields = FrmField::no_save_fields();
         foreach ($csv_fields as $k => $f) {
             if (in_array($f->type, $no_export_fields)) {
                 unset($csv_fields[$k]);
             }
         }
     }
     return $csv_fields;
 }
 function update_field_ajax($entry_id, $field_id, $value)
 {
     global $frmdb, $wpdb;
     $entry_id = (int) $entry_id;
     if (!$entry_id) {
         return false;
     }
     $where = '';
     if (is_numeric($field_id)) {
         $where .= "fi.id={$field_id}";
     } else {
         $where .= "field_key='{$field_id}'";
     }
     $field = FrmField::getAll($where, '', ' LIMIT 1');
     if (!$field or !FrmProEntry::user_can_edit($entry_id, $field->form_id)) {
         return false;
     }
     $post_id = false;
     $field->field_options = maybe_unserialize($field->field_options);
     if (isset($field->field_options['post_field']) and !empty($field->field_options['post_field'])) {
         $post_id = $frmdb->get_var($frmdb->entries, array('id' => $entry_id), 'post_id');
     }
     if (!$post_id) {
         $updated = $wpdb->update($frmdb->entry_metas, array('meta_value' => $value), array('item_id' => $entry_id, 'field_id' => $field_id));
         if (!$updated) {
             $wpdb->query($wpdb->prepare("DELETE FROM {$frmdb->entry_metas} WHERE item_id = %d and field_id = %d", $entry_id, $field_id));
             $updated = FrmEntryMeta::add_entry_meta($entry_id, $field_id, '', $value);
         }
         wp_cache_delete($entry_id, 'frm_entry');
     } else {
         switch ($field->field_options['post_field']) {
             case 'post_custom':
                 $updated = update_post_meta($post_id, $field->field_options['post_custom'], maybe_serialize($value));
                 break;
             case 'post_category':
                 $taxonomy = (isset($field->field_options['taxonomy']) and !empty($field->field_options['taxonomy'])) ? $field->field_options['taxonomy'] : 'category';
                 $updated = wp_set_post_terms($post_id, $value, $taxonomy);
                 break;
             default:
                 $post = get_post($post_id, ARRAY_A);
                 $post[$field->field_options['post_field']] = maybe_serialize($value);
                 $updated = wp_insert_post($post);
         }
     }
     return $updated;
 }
Esempio n. 22
0
 function upgrade()
 {
     global $wpdb;
     $db_version = 14;
     // this is the version of the database we're moving to
     $old_db_version = get_option('frmpro_db_version');
     if ($db_version != $old_db_version) {
         require_once ABSPATH . 'wp-admin/includes/upgrade.php';
         $charset_collate = '';
         if ($wpdb->has_cap('collation')) {
             if (!empty($wpdb->charset)) {
                 $charset_collate = "DEFAULT CHARACTER SET {$wpdb->charset}";
             }
             if (!empty($wpdb->collate)) {
                 $charset_collate .= " COLLATE {$wpdb->collate}";
             }
         }
         /* Create/Upgrade Display Table */
         $sql = "CREATE TABLE {$this->displays} (\n                id int(11) NOT NULL auto_increment,\n                display_key varchar(255) default NULL,\n                name varchar(255) default NULL,\n                description text default NULL,\n                content longtext default NULL,\n                dyncontent longtext default NULL,\n                insert_loc varchar(255) default NULL,\n                param varchar(255) default NULL,\n                type varchar(255) default NULL,\n                show_count varchar(255) default NULL,\n                options longtext default NULL,\n                form_id int(11) default NULL,\n                entry_id int(11) default NULL,\n                post_id int(11) default NULL,\n                created_at datetime NOT NULL,\n                PRIMARY KEY id (id),\n                KEY form_id (form_id),\n                KEY entry_id (entry_id),\n                KEY post_id (post_id),\n                UNIQUE KEY display_key (display_key)\n          ) {$charset_collate};";
         dbDelta($sql);
         if ($db_version >= 3 and $old_db_version < 3) {
             //migrate hidden field data into the parent field
             $wpdb->update($frmdb->fields, array('type' => 'scale'), array('type' => '10radio'));
             $fields = FrmField::getAll();
             foreach ($fields as $field) {
                 $field->field_options = maybe_unserialize($field->field_options);
                 if (isset($field->field_options['hide_field']) and is_numeric($field->field_options['hide_field']) and (isset($field->field_options['hide_opt']) and !empty($field->field_options['hide_opt']) or isset($field->field_options['form_select']) and !empty($field->field_options['form_select']))) {
                     global $frm_field;
                     //save hidden fields to parent field
                     $parent_field = FrmField::getOne($field->field_options['hide_field']);
                     if ($parent_field) {
                         $parent_options = maybe_unserialize($parent_field->field_options);
                         if (!isset($parent_options['dependent_fields'])) {
                             $parent_options['dependent_fields'] = array();
                         } else {
                             foreach ($parent_options['dependent_fields'] as $child_id => $child_opt) {
                                 if (empty($child_opt) or $child_opt == '') {
                                     unset($parent_options['dependent_fields'][$child_id]);
                                 } else {
                                     if ($child_id != $field->id) {
                                         //check to make sure this field is still dependent
                                         $check_field = FrmField::getOne($child_id);
                                         $check_options = maybe_unserialize($check_field->field_options);
                                         if (!is_numeric($check_options['hide_field']) or $check_options['hide_field'] != $parent_field->id or empty($check_options['hide_opt']) and empty($check_options['form_select'])) {
                                             unset($parent_options['dependent_fields'][$child_id]);
                                         }
                                     }
                                 }
                             }
                         }
                         $dep_fields = array();
                         if ($field->type == 'data' and isset($field->field_options['form_select']) and is_numeric($field_options['form_select'])) {
                             $dep_fields[] = $field->field_options['form_select'];
                             $dep_fields[] = $field->field_options['data_type'];
                         } else {
                             if (isset($field->field_options['hide_opt']) and !empty($field->field_options['hide_opt'])) {
                                 $dep_fields[] = $field->field_options['hide_opt'];
                             }
                         }
                         if (!empty($dep_fields)) {
                             $parent_options['dependent_fields'][$field->id] = $dep_fields;
                         }
                         $frm_field->update($parent_field->id, array('field_options' => $parent_options));
                     }
                 }
             }
         }
         /**** ADD DEFAULT TEMPLATES ****/
         FrmFormsController::add_default_templates(FRMPRO_TEMPLATES_PATH);
         update_option('frmpro_db_version', $db_version);
         global $frmpro_settings;
         $frmpro_settings->store();
         //update the styling settings
     }
 }
 public static function graph_shortcode($atts)
 {
     $defaults = array('id' => false, 'id2' => false, 'id3' => false, 'id4' => false, 'ids' => array(), 'colors' => '', 'grid_color' => '#CCC', 'is3d' => false, 'height' => 400, 'width' => 400, 'truncate_label' => 7, 'bg_color' => '#FFFFFF', 'truncate' => 40, 'response_count' => 10, 'user_id' => false, 'entry_id' => false, 'title' => '', 'type' => 'default', 'x_axis' => false, 'data_type' => 'count', 'limit' => '', 'show_key' => false, 'min' => '', 'max' => '', 'y_title' => '', 'x_title' => '', 'include_zero' => false, 'field' => false, 'title_size' => '', 'title_font' => '', 'tooltip_label' => '', 'start_date' => '', 'end_date' => '', 'x_start' => '', 'x_end' => '', 'group_by' => '', 'x_order' => 'default', 'atts' => false);
     // TODO: Remove limit from docs, add x_order='desc' and x_order='field_options'
     // Remove id from docs. Just use ids to simplify.
     // Remove either x start or start_date from docs
     // Remove either x_end or end_date from docs
     // Make sure x_order is set up to work with abc
     // If no id, stop now
     if (!$atts || !$atts['id']) {
         echo __('You must include a field id or key in your graph shortcode.', 'formidable');
         return;
     }
     if (isset($atts['type']) && $atts['type'] == 'geo') {
         $defaults['truncate_label'] = 100;
         $defaults['width'] = 600;
     }
     if (isset($atts['include_js'])) {
         unset($atts['include_js']);
     }
     // Set up array for filtering fields
     // TODO: Ask about simpler way
     $temp_atts = $atts;
     foreach ($defaults as $unset => $val) {
         unset($temp_atts[$unset], $unset, $val);
     }
     foreach ($temp_atts as $unset => $val) {
         unset($atts[$unset]);
         $atts['atts'][$unset] = $val;
         unset($unset, $val);
     }
     // User's values should override default values
     $atts = array_merge($defaults, $atts);
     global $wpdb;
     // Reverse compatibility for id2, id3, and id4
     if (!$atts['ids'] && ($atts['id2'] || $atts['id3'] || $atts['id4'])) {
         _deprecated_argument(__FUNCTION__, '1.07.05', __('id2, id3, and id4 are deprecated. Please use ids instead.', 'formidable'));
         $atts['ids'] = array($atts['id2'], $atts['id3'], $atts['id4']);
         $atts['ids'] = implode(',', $atts['ids']);
         unset($atts['id2'], $atts['id3'], $atts['id4']);
     }
     //x_start and start_date do the same thing
     // Reverse compatibility for x_start
     if ($atts['start_date'] || $atts['x_start']) {
         if ($atts['x_start']) {
             $atts['start_date'] = $atts['x_start'];
             unset($atts['x_start']);
         }
         $atts['start_date'] = FrmAppHelper::replace_quotes($atts['start_date']);
     }
     //x_end and end_date do the same thing
     // Reverse compatibility for x_end
     if ($atts['end_date'] || $atts['x_end']) {
         if ($atts['x_end']) {
             $atts['end_date'] = $atts['x_end'];
             unset($atts['x_end']);
         }
         $atts['end_date'] = FrmAppHelper::replace_quotes($atts['end_date']);
     }
     // Reverse compatibility for x_order=0
     if (!$atts['x_order']) {
         $atts['x_order'] = 'field_opts';
     }
     // If limit is set, get only the top results
     if ($atts['limit']) {
         $atts['x_order'] = 'desc';
     }
     $atts['user_id'] = FrmAppHelper::get_user_id_param($atts['user_id']);
     if ($atts['entry_id']) {
         $atts['entry_id'] = explode(',', $atts['entry_id']);
         //make sure all values are numeric
         //TODO: Make this work with entry keys
         $atts['entry_id'] = array_filter($atts['entry_id'], 'is_numeric');
         if (empty($atts['entry_id'])) {
             // don't continue if there are no entry ids
             return;
         }
         $atts['entry_id'] = implode(',', $atts['entry_id']);
     }
     // Switch to entry_ids for easier reference
     $atts['entry_ids'] = $atts['entry_id'];
     unset($atts['entry_id']);
     //Convert $tooltip_label to array
     if ($atts['tooltip_label']) {
         $atts['tooltip_label'] = explode(',', $atts['tooltip_label']);
     }
     // This will only be an object when coming from show()
     if (is_object($atts['field'])) {
         $fields = array($atts['field']);
         // If creating multiple graphs with one shortcode
     } else {
         $atts['id'] = explode(',', $atts['id']);
         foreach ($atts['id'] as $key => $id) {
             //If using field keys, retrieve the field IDs
             if (!is_numeric($id)) {
                 $atts['id'][$key] = FrmDb::get_var($wpdb->prefix . 'frm_fields', array('field_key' => $id));
             }
             unset($key, $id);
         }
         //make sure all field IDs are numeric - TODO: ask Steph if this is redundant
         $atts['id'] = array_filter($atts['id'], 'is_numeric');
         if (empty($atts['id'])) {
             // don't continue if there is nothing to graph
             return;
         }
         $fields = FrmField::getAll(array('fi.id' => $atts['id']));
         // No longer needed
         unset($atts['id']);
     }
     if (!empty($atts['colors'])) {
         $atts['colors'] = explode(',', $atts['colors']);
     }
     // Trigger js load
     global $frm_vars;
     $frm_vars['forms_loaded'][] = true;
     $html = '';
     foreach ($fields as $field) {
         $data = self::get_google_graph($field, $atts);
         if (empty($data)) {
             $html .= apply_filters('frm_no_data_graph', '<div class="frm_no_data_graph">' . __('No Data', 'formidable') . '</div>');
             continue;
         }
         $html .= '<div id="chart_' . $data['graph_id'] . '" style="height:' . $atts['height'] . ';width:' . $atts['width'] . '"></div>';
     }
     return $html;
 }
Esempio n. 24
0
 public static function get_shortcodes($content, $form_id)
 {
     if (FrmAppHelper::pro_is_installed()) {
         return FrmProDisplaysHelper::get_shortcodes($content, $form_id);
     }
     $fields = FrmField::getAll(array('fi.form_id' => (int) $form_id, 'fi.type not' => FrmField::no_save_fields()));
     $tagregexp = self::allowed_shortcodes($fields);
     preg_match_all("/\\[(if )?({$tagregexp})\\b(.*?)(?:(\\/))?\\](?:(.+?)\\[\\/\\])?/s", $content, $matches, PREG_PATTERN_ORDER);
     return $matches;
 }
 public static function duplicate_section($section_field, $form_id)
 {
     check_ajax_referer('frm_ajax', 'nonce');
     global $wpdb;
     if (isset($_POST['children'])) {
         $children = array_filter((array) $_POST['children'], 'is_numeric');
         $fields = FrmField::getAll(array('fi.id' => $children), 'field_order');
     } else {
         $fields = array();
     }
     array_unshift($fields, $section_field);
     $field_count = FrmDb::get_count($wpdb->prefix . 'frm_fields fi LEFT JOIN ' . $wpdb->prefix . 'frm_forms fr ON (fi.form_id = fr.id)', array('or' => 1, 'fr.id' => $form_id, 'fr.parent_form_id' => $form_id));
     $ended = false;
     if (isset($section_field->field_options['repeat']) && $section_field->field_options['repeat']) {
         // create the repeatable form
         $new_form_id = FrmProField::create_repeat_form(0, array('parent_form_id' => $form_id, 'field_name' => $section_field->name));
     } else {
         $new_form_id = $form_id;
     }
     foreach ($fields as $field) {
         // keep the current form id or give it the id of the newly created form
         $this_form_id = $field->form_id == $form_id ? $form_id : $new_form_id;
         $values = array();
         FrmFieldsHelper::fill_field($values, $field, $this_form_id);
         if (FrmField::is_repeating_field($field)) {
             $values['field_options']['form_select'] = $new_form_id;
         }
         $field_count++;
         $values['field_order'] = $field_count;
         $field_id = FrmField::create($values);
         if (!$field_id) {
             continue;
         }
         if ('end_divider' == $field->type) {
             $ended = true;
         }
         $values['id'] = $this_form_id;
         FrmFieldsController::include_single_field($field_id, $values);
     }
     if (!$ended) {
         //make sure the section is ended
         self::create_multiple_fields((array) $section_field, $form_id);
     }
     // Prevent the function in the free version from completing
     wp_die();
 }
Esempio n. 26
0
            $repeat_field = $f->id;
        }
        if (FrmField::is_no_save_field($f->type)) {
            continue;
        }
        if ($f->type == 'data' && (!isset($f->field_options['data_type']) || $f->field_options['data_type'] == 'data' || $f->field_options['data_type'] == '')) {
            continue;
        }
        FrmAppHelper::insert_opt_html(array('id' => $f->id, 'key' => $f->field_key, 'name' => $f->name, 'type' => $f->type));
        if ($f->type == 'data') {
            //get all fields from linked form
            if (isset($f->field_options['form_select']) && is_numeric($f->field_options['form_select'])) {
                $linked_form = FrmDb::get_var($wpdb->prefix . 'frm_fields', array('id' => $f->field_options['form_select']), 'form_id');
                if (!in_array($linked_form, $linked_forms)) {
                    $linked_forms[] = $linked_form;
                    $linked_fields = FrmField::getAll(array('fi.type not' => FrmField::no_save_fields(), 'fi.form_id' => $linked_form));
                    $ldfe = '';
                    if ($linked_fields) {
                        foreach ($linked_fields as $linked_field) {
                            FrmAppHelper::insert_opt_html(array('id' => $f->id . ' show=' . $linked_field->id, 'key' => $f->field_key . ' show=' . $linked_field->field_key, 'name' => $linked_field->name, 'type' => $linked_field->type));
                            $ldfe = $linked_field->id;
                            unset($linked_field);
                        }
                    }
                }
            }
            $dfe = $f->id;
        }
        unset($f);
    }
}
Esempio n. 27
0
 public static function map_csv_fields()
 {
     $name = 'frm_import_file';
     if (!isset($_FILES) || !isset($_FILES[$name]) || empty($_FILES[$name]['name']) || (int) $_FILES[$name]['size'] < 1) {
         return;
     }
     $file = $_FILES[$name]['tmp_name'];
     // check if file was uploaded
     if (!is_uploaded_file($file)) {
         return;
     }
     if (empty($_POST['form_id'])) {
         $errors = array(__('All Fields are required', 'formidable'));
         FrmXMLController::form($errors);
         return;
     }
     //upload
     $media_id = isset($_POST[$name]) && !empty($_POST[$name]) && is_numeric($_POST[$name]) ? $_POST[$name] : FrmProAppHelper::upload_file($name);
     if ($media_id && !is_wp_error($media_id)) {
         $filename = get_attached_file($media_id);
     }
     if (empty($filename)) {
         $errors = array(__('That CSV was not uploaded. Are CSV files allowed on your site?', 'formidable'));
         FrmXMLController::form($errors);
         return;
     }
     $row = 1;
     $headers = $example = '';
     $csv_del = FrmAppHelper::get_param('csv_del', ',');
     $form_id = FrmAppHelper::get_param('form_id');
     setlocale(LC_ALL, get_locale());
     if (($f = fopen($filename, "r")) !== FALSE) {
         $row = 0;
         while (($data = fgetcsv($f, 100000, $csv_del)) !== FALSE) {
             //while (($raw_data = fgets($f, 100000))){
             $row++;
             if ($row == 1) {
                 $headers = $data;
             } else {
                 if ($row == 2) {
                     $example = $data;
                 } else {
                     continue;
                 }
             }
         }
         fclose($f);
     } else {
         $errors = array(__('CSV cannot be opened.', 'formidable'));
         FrmXMLController::form($errors);
         return;
     }
     $frm_field = new FrmField();
     $fields = $frm_field->getAll(array('fi.form_id' => (int) $form_id), 'field_order');
     include FrmAppHelper::plugin_path() . '/pro/classes/views/xml/map_csv_fields.php';
 }
Esempio n. 28
0
 public static function include_logic_row($atts)
 {
     $defaults = array('meta_name' => '', 'condition' => array('hide_field' => '', 'hide_field_cond' => '==', 'hide_opt' => ''), 'key' => '', 'type' => 'form', 'form_id' => 0, 'id' => '', 'name' => '', 'names' => array(), 'showlast' => '', 'onchange' => '');
     extract(wp_parse_args($atts, $defaults));
     if (empty($id)) {
         $id = 'frm_logic_' . $key . '_' . $meta_name;
     }
     if (empty($name)) {
         $name = 'notification[' . $key . '][conditions][' . $meta_name . ']';
     }
     if (empty($names)) {
         $names = array('hide_field' => $name . '[hide_field]', 'hide_field_cond' => $name . '[hide_field_cond]', 'hide_opt' => $name . '[hide_opt]');
     }
     if ($onchange == '') {
         $onchange = "frmGetFieldValues(this.value,'{$key}','{$meta_name}','" . (isset($field['type']) ? $field['type'] : '') . "','" . $names['hide_opt'] . "')";
     }
     $frm_field = new FrmField();
     $form_fields = $frm_field->getAll(array('fi.form_id' => (int) $form_id), 'field_order');
     include FrmAppHelper::plugin_path() . '/pro/classes/views/frmpro-forms/_logic_row.php';
 }
Esempio n. 29
0
 public static function translate($message = '')
 {
     if (!function_exists('icl_t')) {
         _e('You do not have WPML installed', 'formidable');
         return;
     }
     global $wpdb, $sitepress, $sitepress_settings;
     $id = FrmAppHelper::get_param('id', false);
     $frm_form = new FrmForm();
     $form = $frm_form->getOne($id);
     unset($frm_form);
     $langs = $sitepress->get_active_languages();
     $default_language = $sitepress->get_default_language();
     ksort($langs);
     $lang_count = count($langs) - 1;
     self::get_translatable_items(array(), 'formidable', '');
     $strings = $wpdb->get_results("SELECT id, name, value, language FROM {$wpdb->prefix}icl_strings\n            WHERE context='formidable' AND name LIKE '{$id}_%' ORDER BY name DESC", OBJECT_K);
     if ($strings) {
         $translations = $wpdb->get_results("SELECT id, string_id, value, status, language \n                FROM {$wpdb->prefix}icl_string_translations WHERE string_id in (" . implode(',', array_keys($strings)) . ") \n                ORDER BY language ASC");
         $col_order = array($default_language);
     }
     $frm_field = new FrmField();
     $fields_array = $frm_field->getAll(array('fi.form_id' => $id), 'field_order');
     unset($frm_field);
     $fields = array();
     foreach ($fields_array as $f) {
         $fields[$f->id] = $f;
         unset($f);
     }
     unset($fields_array);
     include dirname(__FILE__) . '/translate.php';
 }