<?php
ob_start();
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
// +----------------------------------------------------------------------+
// | PHP version 4/5                                                      |
// +----------------------------------------------------------------------+
// | This source file is a part of iScripts Multicart                     |
// +----------------------------------------------------------------------+
// | Authors: Programmer<programmer@armia.com>        		              |
// +----------------------------------------------------------------------+
// | Copyrights Armia Systems, Inc and iScripts.com © 2005                |
// | All rights reserved                                                  |
// +----------------------------------------------------------------------+
// | This script may not be distributed, sold, given away for free to     |
// | third party, or used as a part of any internet services such as      |
// | webdesign etc.                                                       |
// +----------------------------------------------------------------------+
?>
<?php

include "../includes/config.php";
include "../includes/session.php";
include "../includes/functions.php";


if (get_magic_quotes_gpc()) {
    $_POST = array_map('stripslashes_deep', $_POST);
    $_GET = array_map('stripslashes_deep', $_GET);
    $_COOKIE = array_map('stripslashes_deep', $_COOKIE); 
} 

if(isset( $_SESSION["sess_adminname"]) and $_SESSION["sess_adminname"]!= ""){
	$adminname = $_SESSION["sess_adminname"];
}else{
	header("Location:login.php");
	exit;
}


include "../includes/htmltop.php";

$language_name_flag = 0;
$language_code_flag = 0;

$adminLanguage	= GetAdminLanguage();

$select_language_edit = "SELECT * FROM ".$tableprefix."language_master WHERE  nlanguageId = ".$_GET['edit_id'];
$result_language_edit = mysql_query($select_language_edit) or die(mysql_error());
$language_row = mysql_fetch_assoc($result_language_edit);
			
if(isset($_POST['update']))
{


	/*check whether language name and language code with the same name exists in the database*/
		
	$select_language = "SELECT * FROM ".$tableprefix."language_master
						WHERE LOWER(languageName) = ".GetSQLValueString(strtolower($_POST['txtLanguageName']),"text").
						" AND nlanguageId != ".$_GET['edit_id'];
	$result_language = mysql_query($select_language) or die(mysql_error());
	
	
			
	if(mysql_num_rows($result_language)>0)
	{
	
		$message = LANG_NAME_EXIST."<br>";
		$language_name_flag = 1;
		
	}
	if($language_name_flag == 0)
	{

            $dest_folder_name = '../language/'.strtolower($_POST['txtLanguageName']);

            $source_folder_name =  '../language/'.strtolower($language_row['languageName']);

            if(file_exists($source_folder_name) && $dest_folder_name != $source_folder_name){
                if (!rename($source_folder_name,$dest_folder_name)) {
                    header('Location:language.php?msg=language_rename_failed');
                }
            }
            
             $update_language = "UPDATE ".$tableprefix."language_master
							SET languageName = ".GetSQLValueString($_POST['txtLanguageName'],"text")."							
							WHERE nlanguageId = ".$_GET['edit_id'];

                 
							
            mysql_query($update_language) or die(mysql_error());
		
		
								  
/*---------Patch-----------*/

	header("Location:language.php?".$_GET['qstring']."&txtSearch=".$_GET['txtSearch']."&msg=update");
	
/*---------Patch-----------*/			
							  
	}						  

}
?>
<script>
function checkEditLanguageForm()
{

  var form_name = new Array('txtLanguageName');
  var display_name = new Array('<?php echo LANGUAGE_NAME;?>');
  var count = 1;	

  if(check_fields('frmEditLanguage',form_name,display_name,count))
  {
    ;
  }
  else
  {
  	return false;
  }
   
}

</script>
		
		<body>
		
		<center>
		
		<div align="left" id="layout">
		
		
				
				
				<!--header area start -->
<?php

	include_once("../includes/topheader_admin.php")

?>
				
				<!--header area end -->
				
				
				
				
				<div align="left" class="main_body">
				<!--main body start -->
				
				
				
<?php
		include_once("../includes/admintopmenu.php")
?>		
																					
								
					<div align="left" class="content_area">
					
					<!--content area start -->
				
					<table cellpadding="0" cellspacing="0" border="0" width="100%">
				<tr><td height="35"><?php include_once("../includes/languagemenu.php")?></td>
				</tr>
				<tr>
				<td>			
					<div align="left" class="page_title"><?php echo EDIT_LANG;?></div>
					<div align="center" class="text_information grey_tr"><?php echo $message?></div>
            		<br>
											
					<div align="left">			

		
			<form name="frmEditLanguage" action="#" method="POST" enctype="" onSubmit="return checkEditLanguageForm();">
		
			<table width="100%" border="0" cellpadding="2" cellspacing="2" class="manage_table">
			
				<tr><td colspan="3" align="right"><span class="required">*</span>&nbsp;<?php echo FIELDS_ARE_MANDATORY;?></td></tr>
				<tr><td width="43%" align="left" valign=top><?php echo LANGUAGE_NAME;?>&nbsp;<span class="required">*</span></td><td width="1%" >&nbsp;</td>
					<td width="56%" align="left" valign=top><input class="textarea2" type="text" name="txtLanguageName" value="<?php echo $language_row['languageName']?>" size="25" maxlength="50" ></td>
				</tr>
				
				
				<tr>
					<td colspan="3" align="center">
						
						<input type="button" name="back" class="button" value="<?php echo BACKBTN;?>" onClick="window.location='language.php'">
                                                <input type="submit" value="<?php echo UPDATE;?>" name="update" class="button">
                                        </td>
				</tr>
				<tr><td colspan="3">&nbsp;</td></tr>
			</table>
			
		</form>
		
		</div>
						
	</td></tr></table>			
		<!--content area end-->
						
		</div>
		
						
			<div align="left" class="clear_float"><img src="<?php echo $imagefolder;?>/clear.gif" alt="" width="1" height="1" /></div>
		<!--main body end -->
		</div>
				
				
<?php
	include "../includes/footer.php";
	ob_end_flush();
?>
