<?php

include("../includes/site_config.php");
include('../session_handler.inc');
include('../message.php');
include('../readenglish.php');
include("../includes/functions.php");

/*if ($Sess_UserType != "A") {
	exit;
}*/
include('../pop_lists.inc');
include('../error.php');

//$langs=formGet('langs');
//$langs=$_REQUEST['langs'];
//$mode=formGet('mode');
//$mode=$_REQUEST['mode'];
# retrieve the template
$area = 'member';
$lang_id=strtoupper($_REQUEST['lang_id']);
$lang_name=form_get('lang_name');
$lang_charset=form_get('lang_charset');
$flag=form_get('flag')."."."png";
$mode=$_GET['mode'];
$msg=$_GET['msg'];
$active_lange = $_REQUEST['langs'];


if($lang_name!="" && $lang_name!="english")
{

	$lowename = strtolower($lang_name);
	
	$file2 = "../languages/english.php";
	$newfile2 =$SITE_ROOT. "languages/$lowename.php"; 
	
	if (!copy($file2,$newfile2)) 
	{
	   echo "failed to copy $file...\n";
	}
	
	$file1 = "../languages/english_js.php";
	$newfile1 =$SITE_ROOT. "languages/".$lowename."_js.php"; 
	
	if (!copy($file1,$newfile1)) 
	{
	   echo "failed to copy $file...\n";
	}
	
	$file3 = "../languages/english_admin.php";
	$newfile3 =$SITE_ROOT. "languages/".$lowename."_admin.php"; 
	
	if (!copy($file3,$newfile3)) 
	{
	   echo "failed to copy $file...\n";
	}
}

$rdoquery = mysql_query("SELECT count(*) as ifExists from langfile where lang_name = '".$lang_name."'");
$rsstock = mysql_fetch_array($rdoquery);
if($rsstock["ifExists"] > 0)
{
	echo "<script> location.href='$CONST_LINK_ROOT/admin/language.php?msg=inv?PHPSESSID=.session_id()</script>";
}
else
{
		if(isset($_REQUEST['ins_language']))
		{
		$ins=mysql_query("insert into langfile(lang_id, lang_name, lang_filename,lang_imagename, lang_charset) values('$lang_id','$lang_name','$lang_name','$flag', '$lang_charset')");
		unset($_REQUEST['ins_language']);
		compile_lang($lang_id);
		
		}
}

if(isset($_REQUEST['rem']) && $_REQUEST['rem']!='EN')
{
$str_Query=mysql_fetch_object(mysql_query("select * from langfile where md5(lang_id)='".form_get('rem')."'"));
$lang_name=strtolower($str_Query->lang_name);
$file1 = "$lang_name.php";
unlink($SITE_ROOT. "languages/$file1");
$file2 = $lang_name."_js.php";
unlink($SITE_ROOT. "languages/$file2");
$file3 = $lang_name."_admin.php";
unlink($SITE_ROOT. "languages/$file3");
$del=mysql_query("delete from langfile where md5(lang_id)='".form_get('rem')."'");
$dell=mysql_query("delete from language where md5(language_id)='".form_get('rem')."'");

}

switch ($mode) {
	case 'save':
		restrict_demo();
        $language->DeactivateAll();
        $language->Activate($CONST_DEFAULT_LANGUAGE);
        if (!in_array($CONST_DEFAULT_LANGUAGE,$langs)) error_page("You can't deactivate default language [$CONST_DEFAULT_LANGUAGE]",GENERAL_USER_ERROR);
		foreach ((array)$langs as $lang) {
			$language->Activate($lang);
		}
        if (count($language->error)) error_page(join("<br>",$language->error),GENERAL_USER_ERROR);
		break;
}

###################
#  Check Box Value
###################

if(isset($_REQUEST['langs']))
{
mysql_query("UPDATE langfile SET lang_active = 0");
 foreach($active_lange as $key =>$lang_id)
  {
    mysql_query("UPDATE langfile SET lang_active = 1 WHERE lang_id = '$lang_id'");
   }
}
############################

$search_key=form_get('search_key');
$search_text=form_get('search_text');

if(isset($_REQUEST['del'])){

$del=mysql_query("delete from language where lan_id='".form_get('del')."'");

}

$ret_key=mysql_query("select * from language where title LIKE '%$search_text%' OR value LIKE '%$search_text%'");



?>
<?php include("include/header.php"); ?>

<script language="JavaScript" type="text/JavaScript">
<!--
function MM_openBrWindow(theURL,winName,features) { //v2.0

  window.open(theURL,winName,features);
  return false;
}
//-->
</script>
<script language="JavaScript" type="text/JavaScript">
function validation()
{
	if(document.Frmlanguage.lang_name.value.length=="")
	{
	alert("The Language Name Field can not be left blank");
	document.Frmlanguage.lang_name.focus();
	return(false);
	}
    
	if(document.Frmlanguage.lang_charset.value.length=="")
	{
	alert("The Charset Field can not be left blank");
	document.Frmlanguage.lang_charset.focus();
	return(false);
	}
	
	if(document.Frmlanguage.lang_id.value.length!=2)
	{
	alert("The Id Field should be 2 characters long");
	document.Frmlanguage.lang_id.focus();
	return(false);
	}
}


function valid_key(){

if(document.FrmListbox.search_text.value.length<2)
	{
	alert("The Serch Field can not be left blank");
	document.FrmListbox.search_text.focus();
	return(false);
	}
}


//function validate_lang(){
//
//if(document.Frmlanguage.lang_name.value.length<2)
//	{
//	alert("The Serch Field can not be left blank");
//	document.Frmlanguage.search_text.focus();
//	return(false);
//	}
//}
</script>
<style type="text/css">
<!--
.style1 {color: #FF0000}
-->
</style>
<div class="mainwidth">
<div class="admin-page-header"><div class="admin-page-heading">&nbsp;&nbsp;Language Admin</div></div>
<div class="clear"></div>
<div class="admin-page">
<table cellpadding="0" cellspacing="0" border=0 width="650px">
  <!--DWLayoutTable-->
<tr><td width="650" height="211" valign="top">
  <table cellpadding="0" cellspacing="0" border=0 width="650px">
    <!--DWLayoutTable-->
    <tr>
      <td width="650" height="211" valign="top"><table width="650" border="0" cellspacing="0" cellpadding="0">
        <!--DWLayoutTable-->
        <form action='<?php echo $CONST_LINK_ROOT?>/admin/language.php<?php print("?PHPSESSID=".session_id()); ?>' method='post' enctype='multipart/form-data' name="FrmListbox" id="FrmListbox">
          <tr>
            <td height="19" colspan="2" align="right" class="pageheader"><div align="left"><strong>Search for Text</strong></div></td>
                  </tr>
          <tr>
            <td width="385" height="46" align="right" valign="top"><div style="border:1px solid #dcdcdc; padding:10px" align="left">Look for: 
              <input type="text" name="search_text" />
              
              <input type="submit" name="search_key" value="Search" onclick="return valid_key()" />
              
            </div></td>
                  <td width="265" align="right" valign="middle"><p><a href="javascript:;" 
onclick="MM_openBrWindow('ins_lang.php?mode=create','','width=500,height=400');">
                    <?=ADD_LANGUAGE_KEY?></a><br />
                  <strong>Use for New Pages Only</strong><br /><br />
                  <a href="add_language.php">Add New Language</a></p>
                    </td>
          </tr> </form>
                  <tr>
                    <td height="19" colspan="2" align="right" class="pageheader"><div align="left"><strong><br />Search Results </strong></div></td>
                  </tr>
        <tr>
          <td height="94" colspan="2" align="right"><div style="border:1px solid #dcdcdc; padding:10px" align="left">
           
  
            <table width="90%" border="1" cellspacing="0" cellpadding="3">
              <tr>
                <td bgcolor="#F1F1F1" class="normal"><strong>Lang Text Code</strong> </td>
                    <td bgcolor="#F1F1F1" class="normal"><strong>Language Text</strong> </td>
                    <td bgcolor="#F1F1F1" class="normal"><strong>Language</strong></td>
                    <td colspan="2" bgcolor="#F1F1F1" class="normal"><div align="center" class="normal"><strong>Modify</strong></div></td>
                    </tr>
              
              <? if(isset($_REQUEST['search_key'])){  
while($search=mysql_fetch_object($ret_key)){?>
              
              <tr>
                <td><?=$search->title?></td>
                    <td><?=$search->value?></td>
                    <td><?=$search->language_id?></td>
                    <td><? if($DEMO!=true){?><a href="javascript:;" 
onclick="MM_openBrWindow('ins_lang.php?mode=edit&tit=<?=$search->lan_id?>','','width=500,height=400');"><?=KEY_EDIT?></a><? }else{echo "Disabled";}?></td>
                    <td><? if($DEMO!=true){?><a href="<?=$_SERVER['PHP_SELF']?>?del=<?=$search->lan_id?>&search_key=<?=$search_key?>&search_text=<?=$search_text?>" onclick="javascript:return confirm('Are you sure you want to DELETE this language key?')"><?=KEY_DELETE?></a><? }else{echo "Disabled";}?></td>
                  </tr> <? } }?>
              </table>
                
    </div></td>
                  </tr>
        
        
                </table></td>
      </tr>
    </table></td>
  </tr>
<tr>
  <td height="38" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0">
    <!--DWLayoutTable-->
    <tr>
      <td width="650" height="38" valign="top"><p><strong><br />Note: </strong>When changing text in the site, you simply search for the text that you see on the page. For example, if you want to change the Site Tour page, simply search for Site Tour. You will get two results. One is for the Site Tour title which you don't need to change and the other result is the Site Tour text. It says &quot;Site tour text goes here. HTML Allowed.&quot;. So, you only want to change the second one because that is exactly what you see on the page. So, click Edit to the right of it and it will open a window for you to change the text. Do NOT change the Code section, only change the Text section. Then click Update and that text on the Site Tour page will change to your new text. You can copy HTML to that window if you want.</p>
        <p><strong><span class="style1">PLEASE READ</span> - Do NOT add a new language key unless you are adding a new page to the site.</strong></p>
        <p>For more information on how to search for text and change it, follow these instructions on our <a href="http://www.wazzum.com/2008/12/13/helpful-tips/">Helpful Tips Page</a> at Wazzum.com</p></td>
      </tr>
  </table></td>
</tr>
</table>
</div></div></div><div class="admin-page-bottom"></div></div>

<?php include("include/footer.php"); ?>
