public function save_as_template()
 {
     if (!isset($_POST['title']) || !isset($_POST['product_id'])) {
         die;
     }
     check_ajax_referer('fpd_ajax_nonce', '_ajax_nonce');
     $fancy_product = new Fancy_Product($_POST['product_id']);
     $views = $fancy_product->get_views();
     foreach ($views as $view) {
         unset($view->ID);
         unset($view->product_id);
         unset($view->view_order);
         unset($view->options);
         $view->elements = @unserialize($view->elements);
     }
     $views = json_encode($views);
     //create new template
     $template_id = FPD_Admin_Template::create($_POST['title'], $views);
     //send answer
     header('Content-Type: application/json');
     if ($template_id) {
         echo json_encode(array('id' => $template_id, 'views' => $views, 'html' => FPD_Admin_Manage_Fancy_Products::get_template_link_html($template_id, $_POST['title'], $views), 'message' => __('Template successfully created.', 'radykal')));
     } else {
         echo json_encode(array('error' => 1, 'message' => __('Template could not be stored. Please try again!', 'radykal')));
     }
     die;
 }
<div class="fpd-modal-wrapper" id="fpd-modal-load-template">
	<div class="fpd-modal-dialog">
		<a href="#" class="fpd-close-modal">&times;</a>
		<h3><?php 
_e('Load a template', 'radykal');
?>
</h3>
		<div class="fpd-modal-content">
			<?php 
$no_templates_info = '<p>' . __('No templates created. You can create a template via the action bar in a product list item.', 'radykal') . '</p>';
if (fpd_table_exists(FPD_TEMPLATES_TABLE)) {
    $templates = $wpdb->get_results("SELECT * FROM " . FPD_TEMPLATES_TABLE . " ORDER BY title ASC");
    if (sizeof($templates) == 0) {
        echo $no_templates_info;
    }
    echo '<ul>';
    foreach ($templates as $template) {
        // double quotes required
        echo FPD_Admin_Manage_Fancy_Products::get_template_link_html($template->ID, $template->title);
    }
    echo '</ul>';
} else {
    echo $no_templates_info;
}
?>
			</ul>
		</div>
	</div>
</div>