<?php
/**
 * +-------------------------------------------------------------------+
 * |                        7t-File Manager                            |
 * |                                                                   |
 * | Copyright Ankur Sharma               http://www.7tech.co.in       |
 * |                                                                   |
 * +-------------------------------------------------------------------+
 * | The file is a part of 7T-FileManager plugin script.               |
 * +-------------------------------------------------------------------+
 */
if(!defined('NO_DIRECT_ACCESS') ){
	die();
}

?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" >
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	<title></title>
	<link rel="stylesheet" type="text/css" href="<?php echo WP_PLUGIN_URL.'/'.plugin_basename( dirname(__FILE__)); ?>/css/custom.editarea.css"  />
	<script src="<?php echo site_url(); ?>/wp-includes/js/jquery/jquery.js"></script>
	<script language="Javascript" type="text/javascript" src="<?php echo WP_PLUGIN_URL.'/'.plugin_basename( dirname(__FILE__)); ?>/js/edit_area/edit_area_full.js"></script>
	<script language="Javascript" type="text/javascript">
		filepath_for_edit="<?php echo $_REQUEST['filepath_for_edit']; ?>";
		filename="<?php echo $_REQUEST['filename']; ?>";
		// initialisation
		editAreaLoader.init({
			id: "the_editor"	// id of the textarea to transform
			,toolbar: "search, go_to_line, |, undo, redo, |, select_font, |, syntax_selection, |, change_smooth_selection, highlight, reset_highlight, word_wrap, |, reload, switch_editor, save, help"
			<?php if(isset($_REQUEST['codeedit']) && $_REQUEST['codeedit']!=1){ echo ',display: "later"'; } ?>
			,start_highlight: true	// if start with highlight
			,allow_resize: "both"
			,allow_toggle: false
			,word_wrap: true
			,language: "en"
			,syntax: "<?php echo $ext; ?>"
			//,fullscreen: true
			,switch_editor_callback:"switch_editor"
			,save_callback:"save_file"
			,reload_callback:"reload_file"
			,EA_toggle_on_callback:"toggle_on"
			,EA_toggle_off_callback:"toggle_off"
			,EA_load_callback:"ea_load"
		});	
		
		function toggle_off(id){
			jQuery("body").removeClass('toggle_on');
			jQuery(".display_path").html('<strong>Current File: </strong>'+filepath_for_edit+"/"+filename);
		}
		
		function toggle_on(id){			
			jQuery("body").addClass('toggle_on');
			jQuery(".display_path").html('<strong>Current File: </strong>'+filepath_for_edit+"/"+filename);
			jQuery(frame_the_editor.document).find('.display_path').html('<strong>Current File: </strong>'+filepath_for_edit+"/"+filename);
		}
		
		function save_file(id, content){
			jQuery.post(document.URL,{save:content},function(result){
				if(result.success==1){
					alert('Saved');
				}else{
					alert("ERROR: "+result.error);
				}
			},"json");
		}
		
		function reload_file(id){
			jQuery.post(document.URL,{reload:true},function(result){
				if(result.success==1){
					if(id=='1'){
						jQuery('#the_editor').val(result.data);
					}else{
						editAreaLoader.setValue(id, result.data);
					}
				}else{
					alert("ERROR: "+result.error);
				}
			},"json");
		}
		
		function switch_editor(id){
			eAL.toggle(id);
			resize_textbox();
		}
		function ea_load(id){
			resize_textbox();
		}
		jQuery(document).ready(function(){ resize_textbox(); jQuery(window).resize(function(){ setTimeout('resize_textbox()',500); }); return true; });
		
		function resize_textbox(){
			h=jQuery(window).height();
			w=jQuery(window).width();
			jQuery("#textbox_container").height(h-1).width(w);
			if(!jQuery("body").hasClass("toggle_on") ){
				jQuery("#the_editor").height(h-53).width(w-10);				
			}else{
				jQuery("#frame_the_editor").height(h-6).width(w);
			}
		}
	</script>
</head>
<body class="<?php echo $_REQUEST['codeedit']?"toggle_on":""; ?>">
	<div id="main_container">
		<div id="textbox_container">
			<div id="upper_strip">
				<div class="display_path"></div>
				<a href="javascript:void(0)" onclick="reload_file('1')" id="t_refresh" >&nbsp;</a>
				<a href="javascript:void(0)" onclick="switch_editor('the_editor')" id="t_codeedit" >&nbsp;</a>
				<a href="javascript:void(0)" onclick="save_file('the_editor',jQuery('#the_editor').val())"  id="t_save">&nbsp;</a>
			</div>		
			<textarea id="the_editor"  name="the_editor"><?php ob_start();	readfile($targetFile); $filedata=ob_get_contents(); ob_end_clean(); echo htmlspecialchars($filedata,ENT_COMPAT,'UTF-8'); ?></textarea>
			<div id="bottom_strip"></div>
		</div>
	</div>
		
</body>
</html>
