private function get_product_html($product_id)
        {
            $fancy_product = new Fancy_Product($product_id);
            $views_data = $fancy_product->get_views();
            $output = '';
            if (!empty($views_data)) {
                $first_view = $views_data[0];
                $product_options = fpd_convert_obj_string_to_array($fancy_product->get_options());
                $view_options = fpd_convert_obj_string_to_array($first_view->options);
                $view_options = array_merge((array) $product_options, (array) $view_options);
                $view_options = Fancy_View::options_to_string($view_options);
                ob_start();
                echo "<div class='fpd-product' title='" . esc_attr($first_view->title) . "' title='" . esc_attr($first_view->title) . "' data-thumbnail='" . esc_attr($first_view->thumbnail) . "' data-options='" . $view_options . "'>";
                echo $this->get_element_anchors_from_view($first_view->elements);
                //sub views
                if (sizeof($views_data) > 1) {
                    for ($i = 1; $i < sizeof($views_data); $i++) {
                        $sub_view = $views_data[$i];
                        $view_options = fpd_convert_obj_string_to_array($sub_view->options);
                        $view_options = array_merge((array) $product_options, (array) $view_options);
                        $view_options = Fancy_View::options_to_string($view_options);
                        ?>
							<div class="fpd-product" title="<?php 
                        echo esc_attr($sub_view->title);
                        ?>
" data-thumbnail="<?php 
                        echo esc_attr($sub_view->thumbnail);
                        ?>
" data-options='<?php 
                        echo $view_options;
                        ?>
'>
								<?php 
                        echo $this->get_element_anchors_from_view($sub_view->elements);
                        ?>
							</div>
							<?php 
                    }
                }
                echo '</div>';
                //product
                $output = ob_get_contents();
                ob_end_clean();
            }
            return $output;
        }
        public function output()
        {
            ?>
			<div class="wrap" id="fpd-product-builder">

				<h2 class="fpd-clearfix">
					<?php 
            _e('Fancy Product Builder', 'radykal');
            ?>
					<?php 
            fpd_admin_display_version_info();
            ?>
				</h2>
				<?php 
            global $wpdb, $woocommerce;
            $request_view_id = isset($_GET['view_id']) ? $_GET['view_id'] : NULL;
            //get all fancy products
            $fancy_products = array();
            if (fpd_table_exists(FPD_PRODUCTS_TABLE)) {
                $fancy_products = $wpdb->get_results("SELECT * FROM " . FPD_PRODUCTS_TABLE . " ORDER BY title ASC");
            }
            if (sizeof($fancy_products) == 0) {
                echo '<div class="updated"><p><strong>' . __('There are no fancy products!', 'radykal') . '</strong></p></div></div>';
                exit;
            }
            //save elements of view
            if (isset($_POST['save_elements'])) {
                check_admin_referer('fpd_save_elements');
                $request_view_id = $_POST['view_id'];
                $elements = array();
                for ($i = 0; $i < sizeof($_POST['element_types']); $i++) {
                    $element = array();
                    $element['type'] = $_POST['element_types'][$i];
                    $element['title'] = $_POST['element_titles'][$i];
                    $element['source'] = $_POST['element_sources'][$i];
                    $parameters = array();
                    parse_str($_POST['element_parameters'][$i], $parameters);
                    if (is_array($parameters)) {
                        foreach ($parameters as $key => $value) {
                            if ($value == '') {
                                $parameters[$key] = NULL;
                            } else {
                                $parameters[$key] = preg_replace('/\\s+/', '', $value);
                            }
                        }
                    }
                    $element['parameters'] = $parameters;
                    array_push($elements, $element);
                }
                $fancy_view = new Fancy_View($request_view_id);
                $fancy_view->update(array('elements' => serialize($elements)));
                $requested_view_elements = $elements;
                echo '<div class="updated"><p><strong>' . __('Elements saved.', 'radykal') . '</strong></p></div>';
            }
            ?>
				<br class="clear" />
				<p class="description"><?php 
            _e('Select the view of your Fancy Product:', 'radykal');
            ?>
</p>
				<select id="fpd-view-switcher" class="radykal-select2" style="width: 38%;">
					<?php 
            if (is_array($fancy_products)) {
                foreach ($fancy_products as $fancy_product) {
                    $fancy_product_id = $fancy_product->ID;
                    echo '<optgroup label="' . $fancy_product->title . '" id="' . $fancy_product_id . '">';
                    $fancy_product = new Fancy_Product($fancy_product_id);
                    $views = $fancy_product->get_views();
                    if (is_array($views)) {
                        for ($i = 0; $i < sizeof($views); ++$i) {
                            $view = $views[$i];
                            //get first view
                            if ($request_view_id == NULL) {
                                $request_view_id = $view->ID;
                            }
                            //get requested view
                            if ($request_view_id == $view->ID && !isset($requested_view_elements)) {
                                $requested_view_elements = unserialize($view->elements);
                            }
                            echo '<option value="' . $view->ID . '" ' . selected($request_view_id, $view->ID, false) . '>' . $view->title . '</option>';
                        }
                    }
                    echo '</optgroup>';
                }
            }
            ?>
				</select>
				<?php 
            //create instance of selected fancy view
            $fancy_view = new Fancy_View($request_view_id);
            $product_id = $fancy_view->get_product_id();
            //get stage dimensions
            $fancy_product = new Fancy_Product($product_id);
            $stage_width = $fancy_product->get_option('stage_width');
            $stage_height = $fancy_product->get_option('stage_height');
            ?>
				<a href="#" id="fpd-save-layers" class="button-primary fpd-right"><?php 
            _e('Save Layers', 'radykal');
            ?>
</a>
				<div id="fpd-layers-container" class="fpd-clearfix">

					<!-- Manage elements -->
					<div id="fpd-manage-elements" class="fpd-panel">
						<form method="post" id="fpd-submit">
							<input type="submit" class="fpd-hidden" name="save_elements" />
							<?php 
            wp_nonce_field('fpd_save_elements');
            ?>
							<h3 class="fpd-clearfix">
								<span><?php 
            _e('Layers', 'radykal');
            ?>
</span>

							</h3>
							<div id="fpd-add-element">
								<a href="#" class="add-new-h2" id="fpd-add-image-element"><?php 
            _e('Add Image', 'radykal');
            ?>
</a>
								<a href="#" class="add-new-h2" id="fpd-add-text-element"><?php 
            _e('Add Text', 'radykal');
            ?>
</a>
								<a href="#" class="add-new-h2" id="fpd-add-curved-text-element"><?php 
            _e('Add Curved Text', 'radykal');
            ?>
</a>
								<a href="#" class="add-new-h2" id="fpd-add-upload-zone"><?php 
            _e('Add Upload Zone', 'radykal');
            ?>
</a>
							</div>

							<input type="hidden" value="<?php 
            echo $request_view_id;
            ?>
" name="view_id" />
							<p class="description"><?php 
            _e('Change the layer order by dragging elements up or down.', 'radykal');
            ?>
</p>
							<ul id="fpd-elements-list">
								<?php 
            $index = 0;
            if (is_array($requested_view_elements)) {
                foreach ($requested_view_elements as $view_element) {
                    echo self::get_element_list_item($index, $view_element['title'], $view_element['type'], stripslashes($view_element['source']), http_build_query($view_element['parameters']));
                    $index++;
                }
            }
            ?>
							</ul>

						</form>

					</div>

					<!-- Edit Parameters -->
					<div id="fpd-edit-parameters" class="fpd-panel">

						<h3><?php 
            _e('Layer Options', 'radykal');
            ?>
: <span id="fpd-edit-parameters-for"></span></h3>
						<?php 
            require_once FPD_PLUGIN_ADMIN_DIR . '/views/html-product-builder-parameters-form.php';
            ?>

					</div>

				</div><!-- Manage Layers Box -->


				<!-- Product Stage -->
				<div id="fpd-product-stage" class="fpd-panel">
					<h3 class="fpd-clearfix"><?php 
            _e('Product Stage', 'radykal');
            ?>
						<span class="description"><?php 
            echo $stage_width;
            ?>
px * <?php 
            echo $stage_height;
            ?>
px</span>
					</h3>
					<div id="fpd-element-toolbar">
						<a href="#" class="button button-secondary fpd-center-horizontal"><?php 
            _e('Center Horizontal', 'radykal');
            ?>
</a>
						<a href="#" class="button button-secondary fpd-center-vertical"><?php 
            _e('Center Vertical', 'radykal');
            ?>
</a>
						<a href="#" class="button button-secondary fpd-dupliacte-layer"><?php 
            _e('Duplicate Layer', 'radykal');
            ?>
</a>
					</div>
					<div id="fpd-fabric-stage-wrapper">
						<canvas id="fpd-fabric-stage" width="<?php 
            echo $stage_width;
            ?>
" height="<?php 
            echo $stage_height;
            ?>
"></canvas>
					</div>
				</div>
			</div>
			<?php 
        }
 public function remove_view()
 {
     if (!isset($_POST['id'])) {
         exit;
     }
     check_ajax_referer('fpd_ajax_nonce', '_ajax_nonce');
     $id = trim($_POST['id']);
     header('Content-Type: application/json');
     $fancy_view = new Fancy_View($id);
     $result = $fancy_view->delete();
     echo json_encode($result);
     die;
 }