<?php
$fronttabs_meta_boxes = 
array(

"select-icon" => array(
"name" => "select-icon",
"type" => "select",
"std" => 1,
"options" => array (array( "value" => "none", "text" => "none"),
array('value' => 'accessibility', 'text' => 'accessibility'),

array('value' => 'add', 'text' => 'add'),

array('value' => 'agenda', 'text' => 'agenda'),

array('value' => 'airplane', 'text' => 'airplane'),

array('value' => 'alarm', 'text' => 'alarm'),

array('value' => 'album', 'text' => 'album'),

array('value' => 'alert', 'text' => 'alert'),

array('value' => 'announcement', 'text' => 'announcement'),

array('value' => 'archive', 'text' => 'archive'),

array('value' => 'arrow-down', 'text' => 'arrow-down'),

array('value' => 'arrow-left', 'text' => 'arrow-left'),

array('value' => 'arrow-right', 'text' => 'arrow-right'),

array('value' => 'arrow-up', 'text' => 'arrow-up'),

array('value' => 'art-brush', 'text' => 'art-brush'),

array('value' => 'auction', 'text' => 'auction'),

array('value' => 'award', 'text' => 'award'),

array('value' => 'battery-charge', 'text' => 'battery-charge'),

array('value' => 'battery-full', 'text' => 'battery-full'),

array('value' => 'battery-half', 'text' => 'battery-half'),

array('value' => 'battery-low', 'text' => 'battery-low'),

array('value' => 'bell', 'text' => 'bell'),

array('value' => 'bicycle', 'text' => 'bicycle'),

array('value' => 'blackberry', 'text' => 'blackberry'),

array('value' => 'bluetooth', 'text' => 'bluetooth'),

array('value' => 'boat', 'text' => 'boat'),

array('value' => 'book', 'text' => 'book'),

array('value' => 'bookmark', 'text' => 'bookmark'),

array('value' => 'briefcase', 'text' => 'briefcase'),

array('value' => 'brightness', 'text' => 'brightness'),

array('value' => 'bug', 'text' => 'bug'),

array('value' => 'bus', 'text' => 'bus'),

array('value' => 'calculator', 'text' => 'calculator'),

array('value' => 'calendar', 'text' => 'calendar'),

array('value' => 'calendar-add', 'text' => 'calendar-add'),

array('value' => 'calendar-delete', 'text' => 'calendar-delete'),

array('value' => 'calendar-edit', 'text' => 'calendar-edit'),

array('value' => 'calendar-na', 'text' => 'calendar-na'),

array('value' => 'calendar-time', 'text' => 'calendar-time'),

array('value' => 'camera', 'text' => 'camera'),

array('value' => 'car', 'text' => 'car'),

array('value' => 'cd', 'text' => 'cd'),

array('value' => 'chart', 'text' => 'chart'),

array('value' => 'check', 'text' => 'check'),

array('value' => 'check-box', 'text' => 'check-box'),

array('value' => 'clipboard', 'text' => 'clipboard'),

array('value' => 'clock', 'text' => 'clock'),

array('value' => 'coffee-cup', 'text' => 'coffee-cup'),

array('value' => 'coffee-mug', 'text' => 'coffee-mug'),

array('value' => 'collapse', 'text' => 'collapse'),

array('value' => 'comment', 'text' => 'comment'),

array('value' => 'comment-add', 'text' => 'comment-add'),

array('value' => 'comment-check', 'text' => 'comment-check'),

array('value' => 'comment-delete', 'text' => 'comment-delete'),

array('value' => 'comment-disable', 'text' => 'comment-disable'),

array('value' => 'comment-write', 'text' => 'comment-write'),

array('value' => 'compass', 'text' => 'compass'),

array('value' => 'connect', 'text' => 'connect'),

array('value' => 'connection-signal', 'text' => 'connection-signal'),

array('value' => 'construction', 'text' => 'construction'),

array('value' => 'construction-hat', 'text' => 'construction-hat'),

array('value' => 'contact-book', 'text' => 'contact-book'),

array('value' => 'contact-card', 'text' => 'contact-card'),

array('value' => 'contrast', 'text' => 'contrast'),

array('value' => 'controller-eject', 'text' => 'controller-eject'),

array('value' => 'controller-forward', 'text' => 'controller-forward'),

array('value' => 'controller-next', 'text' => 'controller-next'),

array('value' => 'controller-pause', 'text' => 'controller-pause'),

array('value' => 'controller-play', 'text' => 'controller-play'),

array('value' => 'controller-previous', 'text' => 'controller-previous'),

array('value' => 'controller-record', 'text' => 'controller-record'),

array('value' => 'controller-rewind', 'text' => 'controller-rewind'),

array('value' => 'controller-stop', 'text' => 'controller-stop'),

array('value' => 'cool', 'text' => 'cool'),

array('value' => 'copy', 'text' => 'copy'),

array('value' => 'credit-card', 'text' => 'credit-card'),

array('value' => 'cursor', 'text' => 'cursor'),

array('value' => 'cut', 'text' => 'cut'),

array('value' => 'dashboard', 'text' => 'dashboard'),

array('value' => 'database', 'text' => 'database'),

array('value' => 'database-add', 'text' => 'database-add'),

array('value' => 'database-check', 'text' => 'database-check'),

array('value' => 'database-delete', 'text' => 'database-delete'),

array('value' => 'database-edit', 'text' => 'database-edit'),

array('value' => 'database-error', 'text' => 'database-error'),

array('value' => 'database-export', 'text' => 'database-export'),

array('value' => 'database-import', 'text' => 'database-import'),

array('value' => 'database-lock', 'text' => 'database-lock'),

array('value' => 'database-na', 'text' => 'database-na'),

array('value' => 'database-reload', 'text' => 'database-reload'),

array('value' => 'database-save', 'text' => 'database-save'),

array('value' => 'database-search', 'text' => 'database-search'),

array('value' => 'database-start', 'text' => 'database-start'),

array('value' => 'database-stop', 'text' => 'database-stop'),

array('value' => 'database-user', 'text' => 'database-user'),

array('value' => 'delete', 'text' => 'delete'),

array('value' => 'delivery-truck', 'text' => 'delivery-truck'),

array('value' => 'disconnect', 'text' => 'disconnect'),

array('value' => 'discussion', 'text' => 'discussion'),

array('value' => 'download', 'text' => 'download'),

array('value' => 'earth', 'text' => 'earth'),

array('value' => 'edit-disable', 'text' => 'edit-disable'),

array('value' => 'email', 'text' => 'email'),

array('value' => 'email-delete', 'text' => 'email-delete'),

array('value' => 'email-forward', 'text' => 'email-forward'),

array('value' => 'email-new', 'text' => 'email-new'),

array('value' => 'email-open', 'text' => 'email-open'),

array('value' => 'email-reply', 'text' => 'email-reply'),

array('value' => 'email-write', 'text' => 'email-write'),

array('value' => 'employee-id', 'text' => 'employee-id'),

array('value' => 'exchange', 'text' => 'exchange'),

array('value' => 'expand', 'text' => 'expand'),

array('value' => 'eye', 'text' => 'eye'),

array('value' => 'eyedropper', 'text' => 'eyedropper'),

array('value' => 'fan', 'text' => 'fan'),

array('value' => 'favorite', 'text' => 'favorite'),

array('value' => 'favorite-add', 'text' => 'favorite-add'),

array('value' => 'favorite-delete', 'text' => 'favorite-delete'),

array('value' => 'favorite-edit', 'text' => 'favorite-edit'),

array('value' => 'fever-chart', 'text' => 'fever-chart'),

array('value' => 'filter', 'text' => 'filter'),

array('value' => 'financial', 'text' => 'financial'),

array('value' => 'first-aid-box', 'text' => 'first-aid-box'),

array('value' => 'flag', 'text' => 'flag'),

array('value' => 'flash', 'text' => 'flash'),

array('value' => 'folder', 'text' => 'folder'),

array('value' => 'folder-add', 'text' => 'folder-add'),

array('value' => 'folder-delete', 'text' => 'folder-delete'),

array('value' => 'folder-edit', 'text' => 'folder-edit'),

array('value' => 'folder-search', 'text' => 'folder-search'),

array('value' => 'font-decrease', 'text' => 'font-decrease'),

array('value' => 'font-increase', 'text' => 'font-increase'),

array('value' => 'fullscreen', 'text' => 'fullscreen'),

array('value' => 'fullscreen-enter', 'text' => 'fullscreen-enter'),

array('value' => 'fullscreen-exit', 'text' => 'fullscreen-exit'),

array('value' => 'game-controller', 'text' => 'game-controller'),

array('value' => 'gift', 'text' => 'gift'),

array('value' => 'gift-card', 'text' => 'gift-card'),

array('value' => 'go-to-bottom', 'text' => 'go-to-bottom'),

array('value' => 'go-to-top', 'text' => 'go-to-top'),

array('value' => 'gym', 'text' => 'gym'),

array('value' => 'hammer', 'text' => 'hammer'),

array('value' => 'hand', 'text' => 'hand'),

array('value' => 'hand-pointer', 'text' => 'hand-pointer'),

array('value' => 'headphone', 'text' => 'headphone'),

array('value' => 'help', 'text' => 'help'),

array('value' => 'highlighter', 'text' => 'highlighter'),

array('value' => 'history', 'text' => 'history'),

array('value' => 'home', 'text' => 'home'),

array('value' => 'hot', 'text' => 'hot'),

array('value' => 'hourglass', 'text' => 'hourglass'),

array('value' => 'infinite', 'text' => 'infinite'),

array('value' => 'info', 'text' => 'info'),

array('value' => 'iphone', 'text' => 'iphone'),

array('value' => 'ipod', 'text' => 'ipod'),

array('value' => 'key', 'text' => 'key'),

array('value' => 'lab', 'text' => 'lab'),

array('value' => 'laptop', 'text' => 'laptop'),

array('value' => 'light-bulb', 'text' => 'light-bulb'),

array('value' => 'link', 'text' => 'link'),

array('value' => 'location', 'text' => 'location'),

array('value' => 'location-pin', 'text' => 'location-pin'),

array('value' => 'lock', 'text' => 'lock'),

array('value' => 'login', 'text' => 'login'),

array('value' => 'logout', 'text' => 'logout'),

array('value' => 'luggage', 'text' => 'luggage'),

array('value' => 'magic-wand', 'text' => 'magic-wand'),

array('value' => 'mailbox', 'text' => 'mailbox'),

array('value' => 'mailbox-in', 'text' => 'mailbox-in'),

array('value' => 'mailbox-out', 'text' => 'mailbox-out'),

array('value' => 'martini-glass', 'text' => 'martini-glass'),

array('value' => 'merge', 'text' => 'merge'),

array('value' => 'microphone', 'text' => 'microphone'),

array('value' => 'minus', 'text' => 'minus'),

array('value' => 'monitor', 'text' => 'monitor'),

array('value' => 'mouse', 'text' => 'mouse'),

array('value' => 'move', 'text' => 'move'),

array('value' => 'museum', 'text' => 'museum'),

array('value' => 'music', 'text' => 'music'),

array('value' => 'network', 'text' => 'network'),

array('value' => 'newspaper', 'text' => 'newspaper'),

array('value' => 'notepad', 'text' => 'notepad'),

array('value' => 'office-chair', 'text' => 'office-chair'),

array('value' => 'orbit', 'text' => 'orbit'),

array('value' => 'package-box', 'text' => 'package-box'),

array('value' => 'page', 'text' => 'page'),

array('value' => 'page-add', 'text' => 'page-add'),

array('value' => 'page-check', 'text' => 'page-check'),

array('value' => 'page-delete', 'text' => 'page-delete'),

array('value' => 'page-edit', 'text' => 'page-edit'),

array('value' => 'page-error', 'text' => 'page-error'),

array('value' => 'page-lock', 'text' => 'page-lock'),

array('value' => 'page-new', 'text' => 'page-new'),

array('value' => 'page-not-found', 'text' => 'page-not-found'),

array('value' => 'page-save', 'text' => 'page-save'),

array('value' => 'page-search', 'text' => 'page-search'),

array('value' => 'page-user', 'text' => 'page-user'),

array('value' => 'paint-brush', 'text' => 'paint-brush'),

array('value' => 'paper-clip', 'text' => 'paper-clip'),

array('value' => 'paste', 'text' => 'paste'),

array('value' => 'pen', 'text' => 'pen'),

array('value' => 'pencil', 'text' => 'pencil'),

array('value' => 'phone', 'text' => 'phone'),

array('value' => 'phone-classic', 'text' => 'phone-classic'),

array('value' => 'phone-mobile', 'text' => 'phone-mobile'),

array('value' => 'picture', 'text' => 'picture'),

array('value' => 'pie-chart', 'text' => 'pie-chart'),

array('value' => 'pin', 'text' => 'pin'),

array('value' => 'plugin', 'text' => 'plugin'),

array('value' => 'podcast', 'text' => 'podcast'),

array('value' => 'power', 'text' => 'power'),

array('value' => 'presentation', 'text' => 'presentation'),

array('value' => 'print', 'text' => 'print'),

array('value' => 'puzzle', 'text' => 'puzzle'),

array('value' => 'quote', 'text' => 'quote'),

array('value' => 'radio', 'text' => 'radio'),

array('value' => 'recycle', 'text' => 'recycle'),

array('value' => 'redo', 'text' => 'redo'),

array('value' => 'reload', 'text' => 'reload'),

array('value' => 'remote-control', 'text' => 'remote-control'),

array('value' => 'repeat', 'text' => 'repeat'),

array('value' => 'replay', 'text' => 'replay'),

array('value' => 'restrict', 'text' => 'restrict'),

array('value' => 'rocket', 'text' => 'rocket'),

array('value' => 'rss', 'text' => 'rss'),

array('value' => 'satellite', 'text' => 'satellite'),

array('value' => 'save', 'text' => 'save'),

array('value' => 'script', 'text' => 'script'),

array('value' => 'search', 'text' => 'search'),

array('value' => 'security', 'text' => 'security'),

array('value' => 'setting', 'text' => 'setting'),

array('value' => 'share', 'text' => 'share'),

array('value' => 'shopping-bag', 'text' => 'shopping-bag'),

array('value' => 'shopping-basket', 'text' => 'shopping-basket'),

array('value' => 'shopping-cart', 'text' => 'shopping-cart'),

array('value' => 'shovel', 'text' => 'shovel'),

array('value' => 'shuffle', 'text' => 'shuffle'),

array('value' => 'shutter', 'text' => 'shutter'),

array('value' => 'sign', 'text' => 'sign'),

array('value' => 'sitemap', 'text' => 'sitemap'),

array('value' => 'slice', 'text' => 'slice'),

array('value' => 'sofa-chair', 'text' => 'sofa-chair'),

array('value' => 'split', 'text' => 'split'),

array('value' => 'sport', 'text' => 'sport'),

array('value' => 'sprayer', 'text' => 'sprayer'),

array('value' => 'star', 'text' => 'star'),

array('value' => 'stock-chart', 'text' => 'stock-chart'),

array('value' => 'stop', 'text' => 'stop'),

array('value' => 'zoom-in', 'text' => 'zoom-in'),

array('value' => 'zoom-out', 'text' => 'zoom-out'),

array('value' => 'tag', 'text' => 'tag'),

array('value' => 'tag-cloud', 'text' => 'tag-cloud'),

array('value' => 'thumb-down', 'text' => 'thumb-down'),

array('value' => 'thumb-up', 'text' => 'thumb-up'),

array('value' => 'ticket', 'text' => 'ticket'),

array('value' => 'timer', 'text' => 'timer'),

array('value' => 'tool', 'text' => 'tool'),

array('value' => 'tool-box', 'text' => 'tool-box'),

array('value' => 'train', 'text' => 'train'),

array('value' => 'trash', 'text' => 'trash'),

array('value' => 'trophy', 'text' => 'trophy'),

array('value' => 'tv', 'text' => 'tv'),

array('value' => 'umbella', 'text' => 'umbella'),

array('value' => 'undo', 'text' => 'undo'),

array('value' => 'unlock', 'text' => 'unlock'),

array('value' => 'upload', 'text' => 'upload'),

array('value' => 'usb', 'text' => 'usb'),

array('value' => 'user', 'text' => 'user'),

array('value' => 'user-add', 'text' => 'user-add'),

array('value' => 'user-comment', 'text' => 'user-comment'),

array('value' => 'user-delete', 'text' => 'user-delete'),

array('value' => 'user-disable', 'text' => 'user-disable'),

array('value' => 'user-edit', 'text' => 'user-edit'),

array('value' => 'user-group', 'text' => 'user-group'),

array('value' => 'walk', 'text' => 'walk'),

array('value' => 'wallet', 'text' => 'wallet'),

array('value' => 'weather', 'text' => 'weather'),

array('value' => 'web', 'text' => 'web'),

array('value' => 'webcam', 'text' => 'webcam'),

array('value' => 'video-camera', 'text' => 'video-camera'),

array('value' => 'video-clapper', 'text' => 'video-clapper'),

array('value' => 'video-film', 'text' => 'video-film'),

array('value' => 'video-reel', 'text' => 'video-reel'),

array('value' => 'wine-glass', 'text' => 'wine-glass'),

array('value' => 'wireless', 'text' => 'wireless'),

array('value' => 'voice-command', 'text' => 'voice-command'),

array('value' => 'voice-command-disable', 'text' => 'voice-command-disable'),

array('value' => 'volume-high', 'text' => 'volume-high'),

array('value' => 'volume-low', 'text' => 'volume-low'),

array('value' => 'volume-mute', 'text' => 'volume-mute'),

array('value' => 'write-note', 'text' => 'write-note')),
"description" => "select an icon for tab",
"title" => "Select Icon")

);

/* meta_boxes
================================================== */
function fronttabs_meta_boxes() {
global $post, $fronttabs_meta_boxes;
	
	foreach($fronttabs_meta_boxes as $meta_box) {
		
        if($meta_box['name']){
    		echo'<input type="hidden" name="'.$meta_box['name'].'_noncename" id="'.$meta_box['name'].'_noncename" value="'.wp_create_nonce( plugin_basename(__FILE__) ).'" />';
    		
    		echo'<div style="display:block;"><h4 style="display:inline-block;">'.$meta_box['title'].'</h4>';
            if($meta_box['description']){
               echo'<p style="font-size:90%;display:inline-block;">&nbsp;('.$meta_box['description'].')</p></div>'; 
            }else{
               echo'</div>'; 
            }
        }
		
		if( $meta_box['type'] == "input" ) { 
		
			$meta_box_value = get_post_meta($post->ID, $meta_box['name'].'_value', true);
		
			if($meta_box_value == "")
				$meta_box_value = $meta_box['std'];
		
			echo'<input type="text" name="'.$meta_box['name'].'_value" value="'.$meta_box_value.'" style="width:90%"/><br />';
            
		} elseif ( $meta_box['type'] == "select" ) {
			
			echo'<select name="'.$meta_box['name'].'_value">';
			
			foreach ($meta_box['options'] as $option) {
                
				echo'<option value="';
                echo $option['value'];
                echo'"';
				if ( get_post_meta($post->ID, $meta_box['name'].'_value', true) == $option['value'] ) { 
					echo ' selected="selected"'; 
				} elseif ( $option == $meta_box['std'] ) { 
					echo ' selected="selected"'; 
				} 
				echo'>'. $option['text'] .'</option>';
			
			} 
			
			echo'</select>';
        }
	}

}

/* enable meta_boxes
================================================== */
function create_fronttabs_meta_box() {
global $theme_name, $fronttabs_meta_boxes;
	if (function_exists('add_meta_box') ) {
	add_meta_box( 'fronttabs-meta-boxes', __('Front Tabs Options', GETTEXT_DOMAIN), 'fronttabs_meta_boxes', 'front_tabs', 'normal', 'high' );
	}
}

/* update meta_boxes
================================================== */
function save_fronttabs_postdata( $post_id ) {
	global $post, $fronttabs_meta_boxes;  
		foreach($fronttabs_meta_boxes as $meta_box) {  
 
    /*if (isset($_POST[$meta_box['name'].'_noncename'])){
		if ( !wp_verify_nonce( $_POST[$meta_box['name'].'_noncename'], plugin_basename(__FILE__) )) {  
			return $post_id;  
		}  
    }*/
    
	if ( !wp_verify_nonce( $_POST[$meta_box['name'].'_noncename'], plugin_basename(__FILE__) )) {  
		return $post_id;  
	}  
	
	if ( 'page' == $_POST['post_type'] ) {  
		if ( !current_user_can( 'edit_page', $post_id ))  
		return $post_id;  
	} else {  
		if ( !current_user_can( 'edit_post', $post_id ))  
	return $post_id;
	}  

    $data = $_POST[$meta_box['name'].'_value']; 
	
	if(get_post_meta($post_id, $meta_box['name'].'_value') == "")  
		add_post_meta($post_id, $meta_box['name'].'_value', $data, true);  
		elseif($data != get_post_meta($post_id, $meta_box['name'].'_value', true))  
	update_post_meta($post_id, $meta_box['name'].'_value', $data);  
		elseif($data == "")  
	delete_post_meta($post_id, $meta_box['name'].'_value', get_post_meta($post_id, $meta_box['name'].'_value', true));  
	}
	
}
add_action('admin_menu', 'create_fronttabs_meta_box');
add_action('save_post', 'save_fronttabs_postdata');
?>