<?php


function a3p_extended_user_tabs_html($user)
{	
	?><div style="float:right;width:96px;height:96px;margin:10px;vertical-align:absmiddle;border:1px solid #ccc;"><?php echo get_avatar( $user->ID, 96); ?></div>

	<?php
	echo '<div class="wrap"><div id="icon-users" class="icon32"><br /></div>';
	echo '<h2>'.__('Tracking','ainia').' : '.$user->display_name.'</h2>';
		
	echo '<p>Este usuario tiene un perfil de: <strong>';
	global $wp_roles;
	foreach ( $wp_roles->role_names as $role => $name ) :
		if ( user_can( $user, $role ) )
			echo ' ' . $role ; 
	endforeach;
	echo "</strong></p>";

	$testListTable = new Extended_User_Relations_List_Table($user->ID);
    $testListTable->prepare_items();
   
    echo '<div style="display:none">';
	echo $testListTable->dialog_html(array('relationship_id'=>'_add_note'		,'user_id'=>$user->ID,'user_ip'=>0,'object_id'=>0,'object_type'=>'note'));
	echo $testListTable->dialog_html(array('relationship_id'=>'_add_meeting'	,'user_id'=>$user->ID,'user_ip'=>0,'object_id'=>0,'object_type'=>'meeting'));
	echo $testListTable->dialog_html(array('relationship_id'=>'_add_phone_call'	,'user_id'=>$user->ID,'user_ip'=>0,'object_id'=>0,'object_type'=>'phone_call'));
	echo '</div>';
	?>
	<div class="wrap" id="user_history">   
        <form id="history-filter" method="get">
            <input type="hidden" name="page" value="<?php echo $_REQUEST['page'] ?>" />
			<input type="hidden" name="user_id" value="<?php echo $_REQUEST['user_id'] ?>" />
			<?php //$testListTable->search_box(__('Search'),'search_id') ?>
			
			<?php $testListTable->display(); ?>		
        </form>
	</div>
	
	
	<div id="ok_message" class="ui-state-highlight ui-corner-all"><strong>Hey!</strong> Sample ui-state-highlight style.</div>	
	<div id="ko_message" class="ui-state-error ui-corner-all"><strong>Hey!</strong> Sample ui-state-highlight style.</div>	
	
	
	<a href="#dialog_add_note" 			title="<?php echo __( 'Add Note','wp-extended-users' )?>" class="dialog_link add-user-relation-h2 add-user-relation-first add-new-h2"><?php echo __( 'Add Note','wp-extended-users' )?></a>
	<a href="#dialog_add_meeting" 		title="<?php echo __( 'Add Note','wp-extended-users' )?>" class="dialog_link add-user-relation-h2 add-new-h2"><?php echo __( 'Add Meeting','wp-extended-users' )?></a>
	<a href="#dialog_add_phone_call" 	title="<?php echo __( 'Add Note','wp-extended-users' )?>" class="dialog_link add-user-relation-h2 add-new-h2"><?php echo __( 'Add Phone Call','wp-extended-users' )?></a>

	
	</div>
	<div style="clear:both"/>
	
<?php   
}

function a3p_extended_user_tabs_css()
{
?>
	<style type="text/css">
		
		.nav-tab:focus {outline: none;}
		
		table.user_relations  th.column-user {width:200px;}
		table.user_relations  th.column-type {width:150px;}
		table.user_relations  th.column-date {width:200px;}
		table.user_relations  th.column-content {width:auto;}
		
		.relation_icon {width:16px;height:16px;display:inline-block;vertical-align:middle;margin-right:10px;background: url('<?php  echo plugins_url("images/relation_icons.png", plugin_basename(__FILE__) )?>');}
		.left-icon { float:left;margin-right:5px;margin-top:2px;}
		
		.relation_textarea {width:100%;height:100%;}
		.loading_image {position:relative;top:50%;left:50%;margin-left:-16px;margin-top:-16px;display:none;}
		.add-user-relation-h2 {margin:0 6px}
		.add-user-relation-first {margin-left:30px!important;}
		.user-relations-filters {clear:both;}
		.ui-icon-phone { background-position: -160px 0; }
			
		#ok_message, #ko_message {padding:1em;display:none;margin-bottom:20px;}
		
	</style>	
<?php
}

function a3p_extended_user_tabs_js()
{
?>
<script type="text/javascript">
    
	jQuery(document).ready(function($) {       
		
		// Read-only Dialog		
		$('.dialog').dialog({
			autoOpen: false,
			width: 600,
			height: 500,
			modal: false,
			buttons: {
				"<?php echo __('Close');?>": function() {
					//alert($(this).find('textarea').html());
					$(this).dialog("close");					
				},				
			}
		});
				
		//Read-Write Dialog		
		$('.dialog_note,.dialog_phone_call,.dialog_meeting').dialog({
			autoOpen: false,
			width: 600,
			height: 500,
			modal:false,
			buttons: {
				"<?php echo __('Save');?>": function() {				
					$(this).find('.loading_image').show();
					$(this).parent().find('.ui-button').hide();
					dialog_id = $(this).attr('id');
					var data = {
						dialog: dialog_id,
						action: 'save_note_meeting_call',
						relationship_id		: $(this).parent().find('#'+dialog_id+'_relationship_id').val(),
						user_id				: $(this).parent().find('#'+dialog_id+'_user_id').val(),
						user_ip				: $(this).parent().find('#'+dialog_id+'_user_ip').val(),
						object_id			: $(this).parent().find('#'+dialog_id+'_object_id').val(),
						object_type			: $(this).parent().find('#'+dialog_id+'_object_type').val(),
						date				: $(this).parent().find('#'+dialog_id+'_date').val(),						
						text				: $(this).parent().find('textarea').val(),
					};		
					$.post(ajaxurl, data, function(response) {						
						data = eval('('+response+')');
						$("#"+data.dialog).dialog("close");
						$("#"+data.dialog).find('.loading_image').hide();
						$("#"+data.dialog).parent().find('.ui-button').show();						
						if(data.reload)document.location.reload(true);
						if(data.result)
						{
							 $("#ok_message").html(data.message).show();
							 $("#content"+data.dialog).html(data.content);
						}
						else $("#ko_message").html(data.message).show();						
						
					});
				},				
				"<?php echo __('Cancel');?>": function() {					
					$(this).dialog("close");
				},				
			}
		});
		
	//Mover botones arriba de todo
	$('.add-user-relation-h2').remove().appendTo($('h2:first'));
	
	//Open Dialog actions
	$('.dialog_link').click(function(){
			$("#ok_message").hide();
			$("#ko_message").hide();
			$($(this).attr('href')).dialog('open');
			return false;
			});
		
	});
	
  </script>
  
 <?php
 }
 ?>