<?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();

if (isset($_POST['add'])) {


    /* check whether langage 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");
    $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 && $language_code_flag == 0) {

        $insert_language = "INSERT INTO " . $tableprefix . "language_master(languageName,langActive,langDeleteStatus)
						  	VALUES(" . GetSQLValueString($_POST['txtLanguageName'], "text") . ",
						  	'0','1')";
        mysql_query($insert_language) or die(mysql_error());


        $select_language = "SELECT languageName FROM " . $tableprefix . "language_master LIMIT 0,1";
        $result_language = mysql_query($select_language) or die(mysql_error());

        $dest_folder_name = '../language/'.strtolower($_POST['txtLanguageName']);
        $source_folder_name =  '../language/'.strtolower(mysql_result($result_language,0));
        
        if(file_exists($source_folder_name)){
            if (!recurse_copy($source_folder_name,$dest_folder_name)) {
                header('Location:language.php?msg=language_failed');
            }
        }
        else{
            die("does not exist");
        }
      
        header('Location:language.php?msg=add');
    }
}
?>
<script>
    function checkAddLanguageForm()
    {

        var form_name = new Array('txtLanguageName');
        var display_name = new Array('Language Name');
        var count = 1;

        if(check_fields('frmAddLanguage',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 ADD_NEW_LANG;?></div>
                            <div align="center" class="text_information grey_tr"><?php echo $message ?></div>
                            <br>

                            <div align="left">			

                                <form name="frmAddLanguage" action="#" method="POST" enctype="" onSubmit="return checkAddLanguageForm();">

                                    <table width="100%" border="0" cellpadding="0" cellspacing="0" class="manage_table">
                                       
                                       <tr><td colspan="3" align="right"><span class="required">*</span>&nbsp;<?php echo FIELDS_ARE_MANDATORY;?></td></tr>
                                        <tr><td width="30%" align="left" valign=top><?php echo LANG_NAME;?>&nbsp;<span class="required">*</span></td><td width="2%" >&nbsp;</td>
                                            <td width="70%" align="left" valign=top><input class="textbox" type="text" name="txtLanguageName" value="" size="25" maxlength="50" ></td>
                                        </tr>
                                        
                                        <tr>
                                            <td>&nbsp; </td>
                                            <td colspan="2" align="left" style="padding-left: 25px;">
                                                <input type="submit" value="&nbsp;<?php echo ADD_TEXT;?>&nbsp;" name="add" class="button">
                                                <input type="button" name="back" class="button" value="<?php echo BACKBTN;?>" onClick="window.location='language.php'">
                                            </td>
                                            
                                        </tr>
                                        <tr><td colspan="3">&nbsp;</td></tr>

                                         <tr>

                                             <td colspan="3"> <b>Steps to add a new language:</b><br>
1. For your new language, a copy of 'english' folder will be created inside the language folder with new language name as folder name.<br>
2. Inside the new folder, translate the content of all the files to new language and save it.<br>
3. Add the new language contents for all the section like CMS,faq,email,Help etc. <br>
4. Add turn the Language Status(active to yes)</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();
        ?>
       