function ct_change_types_pt_process_callback()
{
    if (!isset($_POST["wpnonce"]) || !wp_verify_nonce($_POST["wpnonce"], 'work_view_template')) {
        die("Undefined Nonce.");
    }
    global $wpdb, $WP_Views;
    $options = $WP_Views->get_options();
    $pt = $_POST["pt"];
    $sort = $_POST['sort'];
    if (isset($_POST['value'])) {
        $value = $_POST['value'];
    } else {
        $value = 0;
    }
    $options[$pt] = $value;
    $WP_Views->save_options($options);
    $out = wpv_admin_menu_content_template_listing_by_type_row($sort);
    echo $out;
    die;
}
function ct_change_types_pt_process_callback()
{
    if (!current_user_can('manage_options')) {
        die("Untrusted user");
    }
    if (!isset($_POST["wpnonce"]) || !wp_verify_nonce($_POST["wpnonce"], 'work_view_template')) {
        die("Undefined Nonce");
    }
    global $WPV_settings;
    $pt = $_POST["pt"];
    $sort = $_POST['sort'];
    if (isset($_POST['value'])) {
        $value = $_POST['value'];
        do_action('wpv_action_wpv_save_item', $value);
    } else {
        $value = 0;
    }
    $WPV_settings[$pt] = $value;
    $WPV_settings->save();
    $out = wpv_admin_menu_content_template_listing_by_type_row($sort);
    echo $out;
    die;
}
function wpv_admin_content_template_listing_usage( $usage = 'single' ) {
	?>
	<table class="wpv-views-listing widefat">

		<thead>
			<tr>
				<th class="wpv-admin-listing-col-usage"><?php _e('Used on','wpv-views') ?></th>
				<th class="wpv-admin-listing-col-used-title"><?php _e('Template used','wpv-views') ?></th>
			</tr>
		</thead>
		<tfoot>
			<tr>
				<th class="wpv-admin-listing-col-usage"><?php _e('Used on','wpv-views') ?></th>
				<th class="wpv-admin-listing-col-used-title"><?php _e('Template used','wpv-views') ?></th>
			</tr>
		</tfoot>
		<!-- / section for: sort by name -->

		<tbody class="js-wpv-views-listing-body">
			<?php
				echo wpv_admin_menu_content_template_listing_by_type_row( 'usage-' . $usage );
			?>
		</tbody>
	</table>

	<?php
	
	// Render dialog templates
	wpv_render_ct_listing_dialog_templates_arrangeby_usage();
}
function wpv_admin_content_template_listing_usage($usage = 'single')
{
    ?>
	<div class="wpv-views-listing-arrange">
		<p><?php 
    _e('Arrange by', 'wpv-views');
    ?>
: </p>
		<ul>
			<li data-sortby="name"><a href="<?php 
    echo admin_url('admin.php');
    ?>
?page=view-templates"><?php 
    _e('Name', 'wpv-views');
    ?>
</a></li>
			<?php 
    $checked = false;
    if ($usage == 'single') {
        $checked = true;
    }
    ?>
			<li data-sortby="usage-single"<?php 
    if ($checked) {
        echo '  class="active"';
    }
    ?>
><?php 
    if (!$checked) {
        ?>
<a href="<?php 
        echo admin_url('admin.php');
        ?>
?page=view-templates&amp;arrangeby=usage&amp;usage=single"><?php 
    }
    _e('Usage for single page', 'wpv-views');
    if (!$checked) {
        ?>
</a><?php 
    }
    ?>
</li>
			<?php 
    $checked = false;
    if ($usage == 'post-archives') {
        $checked = true;
    }
    ?>
			<li data-sortby="usage-post-archives"<?php 
    if ($checked) {
        echo '  class="active"';
    }
    ?>
><?php 
    if (!$checked) {
        ?>
<a href="<?php 
        echo admin_url('admin.php');
        ?>
?page=view-templates&amp;arrangeby=usage&amp;usage=post-archives"><?php 
    }
    _e('Usage for custom post archives', 'wpv-views');
    if (!$checked) {
        ?>
</a><?php 
    }
    ?>
</li>
			<?php 
    $checked = false;
    if ($usage == 'taxonomy-archives') {
        $checked = true;
    }
    ?>
			<li data-sortby="usage-taxonomy-archives"<?php 
    if ($checked) {
        echo '  class="active"';
    }
    ?>
><?php 
    if (!$checked) {
        ?>
<a href="<?php 
        echo admin_url('admin.php');
        ?>
?page=view-templates&amp;arrangeby=usage&amp;usage=taxonomy-archives"><?php 
    }
    _e('Usage for taxonomy archives', 'wpv-views');
    if (!$checked) {
        ?>
</a><?php 
    }
    ?>
</li>
		</ul>
	</div>

	<table class="wpv-views-listing widefat">

		<thead>
			<tr>
				<th class="wpv-admin-listing-col-usage"><?php 
    _e('Used on', 'wpv-views');
    ?>
</th>
				<th class="wpv-admin-listing-col-used-title"><?php 
    _e('Template used', 'wpv-views');
    ?>
</th>
				<th class="wpv-admin-listing-col-action"><?php 
    _e('Action', 'wpv-views');
    ?>
</th>
			</tr>
		</thead>
		<tfoot>
			<tr>
				<th class="wpv-admin-listing-col-usage"><?php 
    _e('Used on', 'wpv-views');
    ?>
</th>
				<th class="wpv-admin-listing-col-used-title"><?php 
    _e('Template used', 'wpv-views');
    ?>
</th>
				<th class="wpv-admin-listing-col-action"><?php 
    _e('Action', 'wpv-views');
    ?>
</th>
			</tr>
		</tfoot>
		<!-- / section for: sort by name -->

		<tbody class="js-wpv-views-listing-body">
			<?php 
    echo wpv_admin_menu_content_template_listing_by_type_row('usage-' . $usage);
    ?>
		</tbody>
	</table>
	
	<div class="popup-window-container"> <!-- placeholder for static colorbox popups -->
		
		<!-- popup: unlink Template -->

		<div class="wpv-dialog js-single-unlink-template-dialog">
			<div class="wpv-dialog-header">
				<h2><?php 
    echo sprintf(__('Clear single %s', 'wpv-views'), '<strong class="js-single-unlink-label"></strong>');
    ?>
</h2>
			</div>
			<div class="wpv-dialog-content">
				<p><?php 
    echo sprintf(__('There is no general Content Template asigned to single %s, but %s individual %s have a Content Template asigned to them.', 'wpv-views'), '<strong class="js-single-unlink-label"></strong>', '<strong class="js-single-unlink-number"></strong>', '<strong class="js-single-unlink-label"></strong>');
    ?>
</p>
				<p><?php 
    echo __('Would you like to clear them?', 'wpv-views');
    ?>
</p>
			</div>
			<div class="wpv-dialog-footer">
				<button class="button js-dialog-close"><?php 
    _e('Cancel', 'wpv-views');
    ?>
</button>
				<button class="button button-primary js-single-unlink-template-ok" data-slug="" data-nonce="<?php 
    echo wp_create_nonce('wpv_single_unlink_template_nonce');
    ?>
"><?php 
    _e('Clear', 'wpv-views');
    ?>
</button>
			</div>
		</div> <!-- .js-delete-view-dialog -->
		
	</div>
	<?php 
}