<?php

/*

  osCommRes, Services Online
  http://www.oscommres.com

  Copyright (c) 2005 osCommRes

  Released under the GNU General Public License
  
  Freeway eCommerce from ZacWare
http://www.zac-ware.com/freeway

Copyright 2007 ZacWare Pty. Ltd
*/
// Set flag that this is a parent file
	define( '_FEXEC', 1 );
	require("includes/application_top.php");
	$page = (isset($HTTP_GET_VARS['page']) ? (int)$HTTP_GET_VARS['page'] :1);
	$info=(isset($HTTP_GET_VARS["info"])?tep_db_prepare_input(urldecode($HTTP_GET_VARS["info"])):''); 
	tep_get_last_access_file();                                                                                                  
    $template_path=DIR_FS_TEMPLATES ."content/";
    $server_date = getServerDate(true);	

    $action = (isset($HTTP_GET_VARS['action']) ? $HTTP_GET_VARS['action'] : '');
	if($action!=""){
   	  if($action=='get_details'){
   	  	  echo_get_details();
     }else if($action=='edit_seo'){ 
	 	  $tag=get_tag_details($info);
		  echo 'edit';

		?>
		<table border="0" width="100%" cellspacing="0" cellpadding="2">
		  <tr>
		  		<td>
				<table border="0" cellpadding="5" cellspacing="0" >
					<tr>
						<td class="main" width="50"><?php echo TEXT_INFO_TITLE;?></td>
						<td class="main"><?php echo tep_draw_input_field('title',$tag["title"],'size=100 maxlength=255 onFocus="javascript:setCurrent(this);"');?></td>
					  	<td width="150" rowspan="3" valign="top" align="right"><?php echo tep_draw_pull_down_menu('select_list',get_fields_array($info),'','size=10, onDblClick="javascript:AddField()"');?></td>
					</tr>
					<tr>
						<td class="main" valign="top"><?php echo TEXT_INFO_DESCRIPTION;?></td>
						<td class="main" colspan="2"><?php echo tep_draw_textarea_field('description',"wrap",100,10,$tag["description"],'onFocus="javascript:setCurrent(this);"');?></td>
					</tr>
					<tr>
						<td class="main" valign="top"><?php echo TEXT_INFO_KEYWORDS;?></td>
						<td class="main" colspan="2"><?php echo tep_draw_textarea_field('keywords',"wrap",100,10,$tag["keywords"],'onFocus="javascript:setCurrent(this);"');?></td>
					</tr>
				</table>
				</td>
		  </tr>
		 </table> 
	<?php }else if($action=='update_seo'){ 
			$sql_array=array();
			$sql_array["title"]=isset($HTTP_POST_VARS["title"])?tep_db_prepare_input($HTTP_POST_VARS["title"]):'';
			$sql_array["description"]=isset($HTTP_POST_VARS["description"])?tep_db_prepare_input($HTTP_POST_VARS["description"]):'';
			$sql_array["keywords"]=isset($HTTP_POST_VARS["keywords"])?tep_db_prepare_input($HTTP_POST_VARS["keywords"]):'';
			$sql_array["date_modified"]=$server_date;
			
			$mode_sql = tep_db_query("select * from " . TABLE_META_TAGS . " where filename='" . str_replace(".tpl.php","",$info) . "'");
			$count = tep_db_num_rows($mode_sql);
			if($count > 0) $mode = "N";
			else  $mode = "Y";
			
			if ($info && $HTTP_POST_VARS['action_type']=='edit') {
			if ($mode=="Y"){
				$sql_array["filename"]=str_replace(".tpl.php","",$info);
				tep_db_perform(TABLE_META_TAGS,$sql_array);
			} else {
				tep_db_perform(TABLE_META_TAGS,$sql_array,"update","filename='" . str_replace(".tpl.php","",$info) . "'");
			}
		}	
		  echo_get_details();	  		
	 }else if($action=='delete_seo'){
		 $location_string = 'delete';
		 $location_string .="<table border='0' cellspacing='2' cellpadding='2' width='100%'><tr><td width='17' align='center'>".tep_image('images/template/img_trash.gif').'</td>';
		 $location_string .='<td width="500" align="left" class="inner_title">'.TEXT_INFO_HEADING_META_TAGS. '</td></tr>';
		 $location_string .='<tr><td></td><td width="500" align="left" class="main">'.TEXT_DELETE_INTRO. '<br></td></tr></table>';
		 echo $location_string;
	  }else if($action=='delete_confirm'){   	    
		tep_db_query("DELETE from " . TABLE_META_TAGS . " where filename='" . str_replace(".tpl.php","",$info) . "'");
		//echo "success_delete";
		echo_get_details();	  		
	 } 
	 exit;
	 }
 if($action==''){
			$error="";
			if (!is_readable($template_path)){
				$error="Failed to Read Directory " . $template_path;
			} else {
				$dir=dir($template_path);
				while($file=$dir->read()){
					if ( ($file != '.') && ($file != 'CVS') && ($file != '..') && !is_dir($file)){
						$files[]=$file;
					}
				}
				usort($files,"tep_cmp");
		 }
	 }
 
  function echo_get_details(){
  	global $info; 
	  $fetch_query=tep_db_query("SELECT date_modified,title,keywords,description from " . TABLE_META_TAGS . " where filename='" . str_replace(".tpl.php","",$info) ."'");
	  $date_modified=$title=$keywords=$description="";
		if (tep_db_num_rows($fetch_query)>0){
		  $fetch_result=tep_db_fetch_array($fetch_query);
		  $date_modified=format_date($fetch_result["date_modified"]);
		  $title=$fetch_result["title"];
		  $keywords=$fetch_result["keywords"];
		  $description=$fetch_result["description"];
		  $str_vals.= $date_modified ."||".$title."||".$keywords."||".$description;	
     }else {
		$date_modified="none";
		$keywords="none";	
		$description="none";
		$title=$info;
		$str_vals.= $date_modified ."||".$title."||".$keywords."||".$description;	
	 }
		echo 'get_details'.$str_vals;
  }
  function tep_cmp($a, $b) {
	  return strcmp( $a, $b);
	}
?>
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html <?php echo HTML_PARAMS; ?>>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">
<title><?php echo TITLE; ?></title>
<link rel="stylesheet" type="text/css" href="includes/stylesheet.css">
<script language="javascript" src="includes/menu.js"></script>
<script language="javascript" src="includes/general.js"></script>
<script language="javascript" src="includes/http.js"></script>
<script language="javascript">
var img_src="<?php echo HTTP_SERVER.DIR_WS_ADMIN.'images/';?>";
var max_display="<?php echo MAX_DISPLAY_SEARCH_RESULTS;?>";
var server_date="<?php echo getServerDate();?>";

  function validateForm(sfrm){
      var error_result="";
	  if(sfrm && sfrm.new1) id=sfrm.new1.value;
	  var span_details=document.getElementById("span_details");
	  var span_edit=document.getElementById("span_edit");				
	  var span_delete=document.getElementById("span_delete");
	  var loadings=document.getElementById("loading");
	  if(sfrm.action_type) var action_type=sfrm.action_type.value;
	  var ids="";	  	
	  if(span_details && span_details.style.display!="" && span_edit.style.display==""){	    	
	    span_details.innerHTML=span_delete.innerHTML="";
	  if(span_edit.style.display==""){      							
			if(sfrm.action_type && sfrm.action_type.value=='edit')  ids="&info="+id;
			if(sfrm.title.value=="" || str_trim(sfrm.title.value)=="" )
			error_result="Please enter title name";
			if(sfrm.description.value=="" || str_trim(sfrm.description.value)=="")
			error_result="Please enter description";
			if(sfrm.keywords.value=="" || str_trim(sfrm.keywords.value)=="")
			error_result="Please enter keywords";
			command="<?php echo tep_href_link(FILENAME_META_TAGS,'action=update_seo');?>"+ids;
         }
	  }else if(span_delete.style.display==""){      							
			ids="&info="+id;
			command="<?php echo tep_href_link(FILENAME_META_TAGS,'action=delete_confirm');?>"+ids;
			if(loadings) loadings.style.display="";
			if(span_delete) span_delete.style.display="none";
     }
	 if(error_result!="") {
			alert(error_result);  return false;
		} else {
	do_post_command('tags',command);
	} return false;
   
   }   
var previous_id='';  
function expand_category(id,category){
		if(category==3 && document.getElementById('head_'+id) && document.getElementById('head_'+id).style.display!='none' && document.getElementById("span_edit") && document.getElementById("span_edit").style.display=='none' && document.getElementById("span_delete") && document.getElementById("span_delete").style.display=='none') return;
		var frm=document.tags;
 	 	var res_display=document.getElementById("res_display"); 	 	 	 	 	 	 	 	 	 		 	  	 	
 	 	if(res_display) res_display.style.display="none"; 	 		 	 	
 	 	 if(frm && frm.new1 && frm.new1.value)  {
			var old_ids=frm.new1.value;			
			var pre_data_id=document.getElementById("data_"+old_ids);
			var pre_head=document.getElementById("head_"+old_ids);			
			var loadings=document.getElementById("loading");
			if(loadings) loadings.style.display="none";
		 }		 	 
			if(id && frm.new1.value && frm.new1.value!=id){			   
			   if(pre_head && pre_head.style.display=="") pre_head.style.display="none";
			   if(pre_data_id && pre_data_id.style.display=="none") pre_data_id.style.display="";
			   frm.new1.value=id;			   
			}							
		if(category!=1 && frm && frm.new1 && frm.new1.value=="") frm.new1.value=id;		 								 	 	 	 
 	 	if(category){
 	 		var span_details=document.getElementById("span_details");
 	 		var span_edit=document.getElementById("span_edit");			
			var span_delete=document.getElementById("span_delete");								
			var data_id=document.getElementById("data_"+id);						
			var head=document.getElementById("head_"+id);
			var img_save=document.getElementById("img_save");			
			var command="";																		 
			
			switch(category){
 	 			case 3:
 	 			   if(head && head.style.display==""){
 	 			   	  if(span_details.style.display==""){
 	 			   	    head.style.display="none"; 	 			   	    
 	 			   	  	data_id.style.display=""; 	 			   	  	
 	 			   	  }else {
 	 			   	  	if(span_edit.style.display=="") span_edit.style.display="none";
 	 			   	  	if(span_delete.style.display=="") span_delete.style.display="none"; 
						span_details.style.display="";
 	 			   	  	if(img_save) img_save.style.display="none"; 
 	 			   	  	if(document.getElementById("img_ids")){
 	 			   	  		var tr_obj=document.getElementById("img_ids");
 	 			   	  		if(tr_obj.childNodes[1].childNodes[0].src==img_src+'template/img_edit_hover.gif')	
 	 			   	  			tr_obj.childNodes[1].childNodes[0].src=img_src+'template/img_edit.gif';
 	 			   	  		if(tr_obj.childNodes[2].childNodes[0].src==img_src+'template/img_trash_hover.gif')	
 	 			   	  			tr_obj.childNodes[2].childNodes[0].src=img_src+'template/img_trash.gif';
 	 			   	  	}	 			   	  	  	 			   	  	 	 			   	  	
 	 			   	  }	 	 			    			   	   	 			   
 	 			 }else { 
					if(previous_id!='') 
						if(document.getElementById('head_'+previous_id))
							document.getElementById('head_'+previous_id).innerHTML='';
 	 			 	
					if(data_id && data_id.style.display=="") data_id.style.display="none";
 	 			 	if(pre_head && pre_head.style.display=="") pre_head.style.display="none"; 	 			 	
 	 			 	if(head) {
 	 			 	 	head.style.display=""; 	 
 	 			 		head.innerHTML="<img src='images/24-1.gif' alt='Loading...' title='Loading...'>";	 			 		
 	 			 	}
 	 			 	command="<?php echo tep_href_link(FILENAME_META_TAGS,'action=get_details');?>&info="+id;
				   previous_id=id;	
				 }
 	 			break;
 	 			case 4:
 	 					span_edit.style.display=""; 	 					
 	 					span_details.style.display=span_delete.style.display="none";
 	 					span_edit.innerHTML="<img src='images/24-1.gif' alt='Loading...' title='Loading...'>";
 	 					if(frm.action_type) frm.action_type.value='edit'; 	 					
 	 					command="<?php echo tep_href_link(FILENAME_META_TAGS,'action=edit_seo');?>&info="+id; 
 	 			break; 	 			
 	 			case 5:	 	 				 	 				 	 		 	 				
 	 					span_delete.style.display="";
 	 					span_edit.style.display=span_details.style.display="none";
						span_delete.innerHTML="<img src='images/24-1.gif' alt='Loading...' title='Loading...'>";
 	 					command="<?php echo tep_href_link(FILENAME_META_TAGS,'action=delete_seo');?>&info="+id; 	 	 	 					 	 					 	 			
				break; 					
 	 		}
		   if(command!="") do_get_command(command);
 	 	}	
 	 }
	 
 	function do_result(result){ 
		 if(result.substr(0,11)=='get_details'){ 
		 print_details('get_details',result.substr(11));}
		 else if(result.substr(0,14)=='success_delete') print_details('success_delete',result.substr(14));
	     else  if(result.substr(0,4)=='edit') print_details('edit',result.substr(4));
		 else if(result.substr(0,6)=='delete') print_details('delete',result.substr(6));
 	}
   function print_details(category,result){  	 	 	 	 	 	 	 	 	
 	 	var no_result="";
 	 	var frm=document.tags;
 	    if(result!='' && result.length>0 && category!='edit'){
			splt_str=result.split("||"); 			  	 		
 			var date_modified="";
			var title = "";
			var keywords="";
			var description="";						
 	 		date_modified=splt_str[0];
			title = splt_str[1];	 		
 	 		keywords=splt_str[2];
 	 		description=splt_str[3]; 
 	 	}	  	 		  	 		 	 	 	  	 		 	  	 
 		if(frm && frm.new1) var id=frm.new1.value; 		
 		var span_details=document.getElementById("span_details");	
 		var span_edit=document.getElementById("span_edit"); 	 		 	 		
 		var span_delete=document.getElementById("span_delete");				 	
 		var head=document.getElementById("head_"+id); 		 		 		  
 		var data_id=document.getElementById("data_"+id);
 		var res_display=document.getElementById("res_display");
 		var equip=document.getElementById("equip");
 		var img_save=document.getElementById("img_save");
		if(img_save && category!='get_details') img_save.style.display="";	
		switch(category){ 	 		 	 		 	 		 	 		
 	 		case 'get_details':
 	 	    if(head && no_result==""){	 	 		
	 	 		head.style.display="";
				if(data_id){		 	 		
		 	 		data_id.innerHTML='<table border="0" cellpadding="0" cellspacing="0" width="100%">'+
						         '<tbody><tr>'+
						         	'<td class="dataTableContent" width="30%" align="left">'+title+'</td>'+
						         '</tr>'+
						      '</tbody></table>';	
	 	 		} 	 	 			
	 	 		include ="<table width='100%' border='0' cellspacing='0' cellpadding='0'>"+
				"<tr heigth='40' class='openContent_top'>"+				  				  							  
				  "<td width='40' valign='top' align='center'>&nbsp;</td>"+ 
				  "<td align='left' valign='middle' width='250' class='inner_title'>"+title+"</td>"+
				  "<td align='left' valign='middle' width='100'></td>"+
				  "<td width='470' align='left' class='main' valign='top'>"+
				  	"<table border='0' cellspacing='0' cellpadding='0' style='width:100;height:30px;display:inline;position:relative;'>"+
				  	  "<tr class='img_move' id='img_ids'>"+
				  	  	"<td class='cell_bg_popm_left' width='10'>&nbsp;</td>"+
				  	    "<td width='10%' onclick=javascript:change_class(this,1);expand_category('"+id+"',4); onmouseover='javascript:change_class(this,2);' onmouseout='javascript:change_class(this,3);'><img alt='Edit' title='Edit' src='images/template/img_edit.gif'></td>"+
				  	    "<td width='10%' onclick=javascript:change_class(this,1);expand_category('"+id+"',5); onmouseover='javascript:change_class(this,2);' onmouseout='javascript:change_class(this,3);'><img alt='Delete' title='Delete' src='images/template/img_trash.gif'></td>"+				  	    
						"<td class='cell_bg_popm_right' width='10'>&nbsp;</td>"+
				  	  "</tr>"+
				  	"</table>"+
				  "</td>"+
				 "<td width='240' align='right' id='img_save' style='display:none'><input type='image' src='images/template/img_savel.gif' alt='save' title='save' border='0'>&nbsp;&nbsp;<a href=javascript:expand_category('"+id+"',3);><img src='images/template/img_closel.gif' alt='close' title='close' border='0'></a>&nbsp;&nbsp;</td>"+
				"</tr>"+
				"<tr style='height:10'><td id='loading' style='display:none' colspan='5'><img src='images/24-1.gif' alt='Loading...' title='Loading...'></td></tr>"+				
				"<tr>"+
				  "<td colspan='8' class='main'><span style='display:none' id='span_edit'></span><span style='display:none' id='span_delete'></span><span id='span_details'>"+	"<table width='100%' border='0' cellspacing='0' cellpadding='0'>"+
				  		"<tr>"+
				  			"<td width='100'>&nbsp;</td>"+				  							  			
							"<td width='100%'>"+			  							  			
				  				"<table width='100%' border='0' cellspacing='0' cellpadding='2' class='main'>";				  														
									include+="<tr>"+
											"<td align='left' width='10%'></td>"+	
											"<td align='left' width='10%'><b><?php echo TEXT_LAST_MODIFIED.":";?></b></td>"+
											"<td align='left' width='20%'>"+date_modified+"</td>"+
										"</tr>";
										include+="<tr>"+
											"<td align='left' width='10%'></td>"+
											"<td align='left' width='10%'><b><?php echo TEXT_INFO_TITLE.":";?></b></td>"+
											"<td align='left' width='20%'>"+title+"</td>"+
										"</tr>";
										include+="<tr>"+
											"<td align='left' width='10%'></td>"+
											"<td align='left' width='10%'><b><?php echo TEXT_INFO_KEYWORDS.":";?></b></td>"+
											"<td align='left' width='20%'>"+keywords+"</td>"+
										"</tr>";
										include+="<tr>"+
											"<td align='left' width='10%'></td>"+
											"<td align='left' width='10%'><b><?php echo TEXT_INFO_DESCRIPTION.":";?></b></td>"+
											"<td align='left' width='20%'>"+description+"</td>"+
										"</tr><tr><td><img src='images/pixel_trans.gif' border='0' alt='' width='5' height='15'></td></tr>";

				  			  include+="</table></td>"+
							  "</tr>"+
							  "<tr height='15'></tr>"+
							 "</table>"; 
					"</span>"+
				  "</td>"+
				"</tr>"+
			"</table>";
			head.innerHTML=include;
 	 		} 	 			 	 		
 	 	break;
 	 	case 'edit': 	 		 	 		 	 		 	 		
			if(span_edit) span_edit.style.display="";			
 	 		if(span_edit && span_details){
 	 			span_edit.innerHTML=result; 	 			
 	 			span_details.style.display='none';
 	 		}									  
 	// 	toggle_panel('Equipment:_','false','','0');	     					 		  												
 	 	break;
 	 	case 'delete': 	 				 	 	
 	 		if(span_delete) span_delete.style.display="";
 	 		if(span_delete){ 	 			
 	 			span_delete.innerHTML=result; 	 			
 	 			span_details.style.display=span_edit.style.display='none';
 	 		} 	 								   			   
 	 	break; 	 	
 	 	case 'success_delete':			 
			 if(head && data_id) {
			 	var tbl_obj=head.parentNode.parentNode.parentNode.parentNode;			 				 				 	
			 	if(tbl_obj) tbl_obj.deleteRow(head.parentNode.parentNode.rowIndex);
			 	data_id.innerHTML=head.innerHTML="";
			 	data_id.style.display=head.style.display="none";			 				 			
			 } 
			 if(res_display){
	    	 	res_display.innerHTML="<?php echo TEXT_DELETE_SUCCESS;?>";
 	    	 	res_display.style.display="";
			 }
 	 	break;  	
	  } 
 	 	if(res_display.style.display=="") setTimeout("res_display.style.display='none'",2000); 	 	 	 	
 	 	clearTimeout();
	  }
	
	 function change_class(obj,eve){ 		 	 	
		 var span_details=document.getElementById("span_details"); 
		 var span_edit=document.getElementById("span_edit");
		 var span_delete=document.getElementById("span_delete");				 		 			 
		 if(obj){		   		    		    
		    var img_get_src=obj.childNodes[0];
			if(img_get_src){
			    if(img_get_src.src==img_src+'template/img_edit.gif') {
					if(span_edit && span_edit.style.display=="" && eve==1 || eve==2){ 
					 	img_get_src.src=img_src+'template/img_edit_hover.gif';
					}  		   		 	 			 	 			
			    }else if(eve==3 && img_get_src.src==img_src+'template/img_edit_hover.gif' && span_edit && span_edit.style.display=="none") img_get_src.src=img_src+'template/img_edit.gif';
			    if(img_get_src.src==img_src+'template/img_trash.gif') {
					if(span_delete && span_delete.style.display=="" && eve==1 || eve==2){ 
					 	img_get_src.src=img_src+'template/img_trash_hover.gif';
					}  		   		 	 			 	 			
			    }else if(eve==3 && img_get_src.src==img_src+'template/img_trash_hover.gif' && span_delete && span_delete.style.display=="none") img_get_src.src=img_src+'template/img_trash.gif';		    		    		     		   	
		    }
		 }		 
	  }
</script>	  	
</head>
<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" bgcolor="#FFFFFF">
<!-- header //-->
<?php require(DIR_WS_INCLUDES . 'header.php'); ?>
<!-- header_eof //-->

<!-- body //-->
<table border="0" width="100%" cellspacing="2" cellpadding="2">
  <tr> 
<!-- body_text //-->
    <td width="100%" valign="top">
		  <?php echo tep_draw_form("tags",FILENAME_META_TAGS,'' ,'post','onsubmit="return validateForm(this);"');
		  ?>
	<table border="0" width="100%" cellspacing="0" cellpadding="2">	 
	  <tr>
		<td id="res_display" class="main" style="display:none"></td></tr>	
		<tr>
<td colspan="2" class="dataTableHeadingRow">&nbsp;&nbsp;<?php echo 'SEO'; ?></td>
</tr>	 
	  <tr>
         <td colspan="3" id="ajax_details">		
		   <table border="0" cellpadding="0" cellspacing="0" width="100%">

		  <?php $class_name="dataTableRowEven";
			  for ($i=0, $n=sizeof($files); $i<$n; $i++) {
				if ((!isset($HTTP_GET_VARS['info']) || (isset($HTTP_GET_VARS['info']) && ($HTTP_GET_VARS['info'] == $files[$i]))) && !isset($fInfo)) {
				  $fInfo =$files[$i];
				}
			$class_name=($class_name=='dataTableRowEven')?'dataTableRowOdd':'dataTableRowOdd';
			 echo '  <tr style="height:25" class="'.$class_name.'" onmouseover="rowOverEffect(this);" onmouseout="rowOutEffect(this);" onclick="javascript:if(document.getElementById(\'head_'.$files[$i].'\').style.display==\'none\') expand_category(\''.$files[$i] .'\',3)">' . "\n"; 

			?>
		    <td colspan="4" width="100%">
				<div id="data_<?php echo $files[$i];?>">
				 <table border="0" cellspacing="0" cellpadding="0" width="100%">
					<tr>
						<td class="dataTableContent"><?php echo $files[$i]; ?> </td>
					</tr>
				</table>
			   </div>
			   <div class="openContent" id="head_<?php echo $files[$i];?>" style="display:none"></div>
			 </td>					      
			</tr>
			
				</tr>
			<?php } 
	      ?>
				</table>
				</td>
		 		</tr>        
       		<tr><td><?php echo tep_draw_separator('pixel_trans.gif', '2', '10'); ?></td></tr>	
        </table>
        <input type="hidden" name="new1" id="new1">
	    <input type="hidden" name="action_type" id="action_type">
	     <input type="hidden" name="icnt" id="icnt"> 
        </form>
        </td>      
<!-- body_text_eof //-->
<!-- body_eof //-->
	</tr>
  </table>
<?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
<!-- footer_eof //-->

		<script language="javascript">
			var selected_field;
			var currentField;
			var intervalId;
			function AddField(){
			 var select_field;
			 var select_id;
			 if (!selected_field) return;
			 if (document.tags.select_list.selectedIndex<=-1) return;
			 select_text="%%" + document.tags.select_list.options[document.tags.select_list.selectedIndex].text + "%%";
				selected_field.focus();
				if (document.selection){
					sRange  = document.selection.createRange();
					var sText   = sRange.text;
					sRange.text = select_text;
				} else if (selected_field.selectionStart || selected_field.selectionStart == "0") {
					var startPos = selected_field.selectionStart;
					var endPos = selected_field.selectionEnd;
					selected_field.value = selected_field.value.substring(0, startPos)
							+ select_text + selected_field.value.substring(endPos, selected_field.value.length);
				} else {
					selected_field.value += select_text;
				}
			}
			function setCurrent(field){
				selected_field=field;
			}
		</script>

</body>
</html>
<?php require(DIR_WS_INCLUDES . 'application_bottom.php'); 

	function get_tag_details($filename){
		// check for current details present in the 
		$filename=str_replace(".tpl.php","",$filename);
		$fetch_query=tep_db_query("SELECT title,description,keywords from " . TABLE_META_TAGS . " where filename='" . tep_db_input($filename) . "'");
		if (tep_db_num_rows($fetch_query)){
			$result=tep_db_fetch_array($fetch_query);
			$result["new"]="N";
			return $result;
		}
		
		switch($filename){
			case "session_details":
			case "product_info":
			case "product_reviews":
			case "subscription_info":
			case "subscription_trial_confirm":
				$title="%%Item_Name%% - %%Item_Price%% : " . STORE_NAME;
				$description=STORE_NAME . " : %%Item_Name%% - %%Item_Description%%";
				$keywords="%%Categories_Name%% ";
				break;
			case "product_reviews_info":
				$title="%%Item_Name%% - %%Item_Price%% : " . STORE_NAME . ", Reviews";
				$description=STORE_NAME . " %%Item_Description%% : Reviews Info  - %%Item_Name%% - %%Customer_Name%% - %%Reviews_Text%% ... - %%Reviews_Ratings%% ";
				$keywords="%%Categories_Name%% %%Item_Name%% %%Item_Price%% %%Customer_Name%% %%Reviews_Rating%%";
				break;
			case "index_products":
			case "index_products_all":
			case "index_events":
			case "events_day_view":
			case "events_month_view":
			case "events_week_view":
			case "events_view1":
			case "events_view2":
			case "events_view3":
			case "index_products":
			case "index_subscriptions":
				$title="%%Category_Name%% : " . STORE_NAME;
				$description=STORE_NAME . " : %%Category_Name%% - %%Category_Description%%";
				$keywords="%%Categories_Name%% ";
				break;
			case "wallet_uploads":
			case "wallet_checkout_payment":
			case "wallet_checkout_process":
			case "wallet_checkout_success":
			case "wallet_checkout_confirmation":
				$title=TEXT_WALLET_CHECKOUT . " : " . STORE_NAME;
				$description=STORE_NAME . " : " . TEXT_WALLET_CHECKOUT;
				$keywords="%%Categories_Name%% ";
				break;
			default:
				$file_splt=split("_",$filename);
				$check_part=strtoupper($file_splt[0]);
				if (defined("TEXT_" . $check_part)){
					$mes_text=constant("TEXT_" .$check_part);
					$title=$mes_text . " : " . STORE_NAME;
					$description=STORE_NAME . " : " . $mes_text . " - %%Categories_Name%%";
					$keywords=" %%Categories_Name%% " . $mes_text;
				} else {
					$filename=str_replace("_"," ",$filename);
					$title=$filename . " : " . STORE_NAME;
					$description=STORE_NAME . " : " . $mes_text . " - %%Categories_Name%%";
					$keywords=" %%Categories_Name%%" . $mes_text;
				}
		}
		$result=array(	"title"=>$title,
						"description"=>$description,
						"keywords"=>$keywords,
						"new"=>"Y"
						);
		return $result;
	}
	function get_fields_array($filename){
		$result=array();
		$filename=str_replace(".tpl.php","",$filename);
		switch($filename){
			case "session_details":
			case "product_info":
			case "product_reviews":
			case "subscription_info":
			case "subscription_trial_confirm":
				$result[]=array('id'=>"Item_Name","text"=>"Item_Name");
				$result[]=array('id'=>"Item_Price","text"=>"Item_Price");
				$result[]=array('id'=>"Item_Description","text"=>"Item_Description");
				$result[]=array('id'=>"Categories_Name","text"=>"Categories_Name");
				break;
			case "product_reviews_info":
				$result[]=array('id'=>"Item_Name","text"=>"Item_Name");
				$result[]=array('id'=>"Item_Price","text"=>"Item_Price");
				$result[]=array('id'=>"Item_Description","text"=>"Item_Description");
				$result[]=array('id'=>"Categories_Name","text"=>"Categories_Name");
				$result[]=array('id'=>"Customer_Name","text"=>"Customer_Name");
				$result[]=array('id'=>"Reviews_Rating","text"=>"Reviews_Rating");
				$result[]=array('id'=>"Reviews_Text","text"=>"Reviews_Text");
				break;
			case "index_products":
			case "index_products_all":
			case "index_events":
			case "index_products":
			case "events_day_view":
			case "events_month_view":
			case "events_week_view":
			case "events_view1":
			case "events_view2":
			case "events_view3":
			case "index_subscriptions":
			case "index_nested":
				$result[]=array('id'=>"Category_Name","text"=>"Category_Name");
				$result[]=array('id'=>"Category_Description","text"=>"Category_Description");
				$result[]=array('id'=>"Categories_Name","text"=>"Categories_Name");
				break;
			default:
				$result[]=array('id'=>"Categories_Name","text"=>"Categories_Name");
		}
		return $result;
	}
?>
