<?php
class WPF_Form_CT {
protected $plugin_name;
protected $version;
protected $themplate_id = false;
public function __construct($plugin_name, $version, $themplate_id = false) {
$this->plugin_name = $plugin_name;
$this->version = $version;
$this->themplate_id = $themplate_id;
}
public function form() {
$sort_cmb = array_merge(WPF_Utils_CT::get_wc_attributes(), WPF_Utils_CT::get_default_fields());
$languages = array(
'en' => array(
'name' => '',
'selected' => true,
),
);
natcasesort($sort_cmb);
$layout = $data = array();
$this->add_fields($data);
?>
<input type="hidden" value="" name="layout" id="wpf_layout" />
<input type="hidden" value="<?php echo $this->themplate_id ?>" id="wpf_themplate_id" name="themplate_id" />
<div class="wpf_ct_back_builder">
<div class="wpf_ct_back_module_panel">
<?php foreach ($sort_cmb as $type => $name): ?>
<div <?php if (!empty($layout[$type])): ?>style="display:none;"<?php endif; ?> data-type="<?php echo $type ?>" id="wpf_ct_cmb_<?php echo $type ?>" class="wpf_ct_back_module">
<?php $this->module($type, $name, array(), $languages); ?>
</div>
<?php endforeach; ?>
</div>
<div class="wpf_ct_back_row_content" id="wpf_ct_module_content">
<div class="wpf_ct_module_holder">
<div class="wpf_empty_holder_text"><?php _e('Drop module here', 'wpf') ?></div>
</div>
</div>
</div>
<?php
}
private function module($type, $name, array $module = array(), array $languages = array()) {
?>
<strong class="wpf_ct_module_name"><?php echo $name ?></strong>
<div class="wpf_ct_back_module_top">
<div class="wpf_left">
<span class="wpf_back_active_module_title"><?php echo $name ?></span>
</div>
<div class="wpf_right">
<a href="#" class="wpf_module_btn wpf_toggle_module"></a>
<a href="#" class="wpf_module_btn wpf_delete_module"></a>
</div>
</div>
<div class="wpf_active_module">
<?php WPF_Utils_CT::module_multi_text($type, $module, $languages, 'field_title', __('Field Title', 'wpf_ct')); ?>
<div data-type="<?php echo $type ?>" class="wpf_back_active_module_content">
<div class="wpf_back_active_module_row wpf_back_active_module_hide_field">
</div>
</div>
</div>
<?php
}
private function add_fields($data = array()) {
$layouts = array(
'vertical' => __('Vertical Layout', 'wpf'),
'horizontal' => __('Horizontal Layout', 'wpf')
);
?>
<div class="wpf_lightbox_row">
<div class="wpf_lightbox_label"><label for="wpf_name"><?php _e('Form Title', 'wpf'); ?></label></div>
<div class="wpf_lightbox_input">
<input id="wpf_name" class="wpf_towidth" type="text" value="<?php echo !empty($data['name']) ? $data['name'] : '' ?>" name="name" />
</div>
</div>
<div class="wpf_lightbox_row ">
<div class="wpf_lightbox_label"><?php _e('Layout', 'wpf'); ?></div>
<div class="wpf_lightbox_input wpf_grid wpf_changed">
<?php foreach ($layouts as $id => $ch): ?>
<input id="wpf_<?php echo $id ?>" type="radio" value="<?php echo $id; ?>" name="type" <?php if ((!$data && $id === 'vertical' ) || ( isset($data['type']) && $data['type'] == $id )): ?>checked="checked"<?php endif; ?>/>
<label title="<?php echo $ch ?>" for="wpf_<?php echo $id ?>" class="wpf_grid_<?php echo $id; ?>"></label>
<?php endforeach; ?>
</div>
</div>
<?php
}
public function save_themplate(array $post) {
$result = false;
if (!empty($post['layout'])) {
$option = WPF_Options_CT::get_option($this->plugin_name, $this->version);
if (empty($post['name'])) {
$post['name'] = uniqid($this->plugin_name . '_');
}
$themplate_id = !empty($post['themplate_id']) ? $post['themplate_id'] : $option->unique_name($post['name']);
$layout = stripslashes_deep($post['layout']);
}
echo '<pre>';
var_export($themplate_id);
echo '</pre>';
die('aaaaaaa');
return $result;
}
}
?>