<?php

/**
* CopyRight Information
*
* @FileName 	langs.config.php
* @Package 		BackLogics Package
* @Author 		Ing. Miguel Zamora Serrano <mzamoras@backlogics.com>
* @CopyRights	BackLogics Technologies 2007 <http://www.backlogics.com>
* @DateCreated	May 1st 2007
* @DateModified May 1st 2007
*
* @Licenced		Internet Sourcing México S.A. de C.V <http://www.e-sourcing.com.mx>
*
*/

	/**
	* Lang Selector
	* This function selects the right language
	*/

	function _lang($errorKind,$phraseToFind,$complement="",$specificModule="",$secondOption="",$info = "",$info2 = "",$lang = ""){


		if($lang != ""){
        	    $theLangPath = _PATH_LANG.$lang;
		}else{
			if(isset($_SESSION['lang']) && $_SESSION['lang'] != ""){
            	$theLangPath = _PATH_LANG.$_SESSION['lang'];
			}else{
        	    $theLangPath = _PATH_LANG._SYSLANG;
        	}
    	}

		//if($complement=="system"){
		if($complement=="system" || $specificModule =="system"){
			$complement = $complement;
			include(includeFile($theLangPath."/system.lang.php"));
		}
		//else if($complement=="blMails"){
		else if($complement=="blMails" || $specificModule =="blMails"){
			$complement = $complement;
			include(includeFile($theLangPath."/mailsBL.lang.php"));
		}
		else{

			if($specificModule==""){

				if(file_exists(includeFile($theLangPath."/".(isset($_SESSION['_alternLang']) ? $_SESSION['_alternLang'] : LANGFILE)))){
					include(includeFile($theLangPath."/".(isset($_SESSION['_alternLang']) ? $_SESSION['_alternLang'] : LANGFILE)));
				}
				else{
					$_lang[$errorKind][$phraseToFind]=$phraseToFind;
				}
			}
			else{

				if(file_exists($theLangPath."/".$specificModule."Module.lang.php") || file_exists($theLangPath."/baseFiles/".$specificModule."Module.lang.php")){
					include(includeFile($theLangPath."/".$specificModule."Module.lang.php"));
				}
				else{
					$_lang[$errorKind][$phraseToFind]=$phraseToFind;
				}
			}
		}

		if(isset($_lang[$errorKind][$phraseToFind])){
			if(mb_detect_encoding($_lang[$errorKind][$phraseToFind],'UTF-8, ISO-8859-1') != "UTF-8"){
				return utf8_encode($_lang[$errorKind][$phraseToFind]);
			}
			else{
				return $_lang[$errorKind][$phraseToFind];
			}
		}
		else{
			if($secondOption!=""){
				if(isset($_lang[$errorKind][$secondOption])){
					if(mb_detect_encoding($_lang[$errorKind][$secondOption],'UTF-8, ISO-8859-1') != "UTF-8"){
						return utf8_encode($_lang[$errorKind][$secondOption]);
					}
					else{
						return $_lang[$errorKind][$secondOption];
					}
				}
				else{
					return "Warning: ".$errorKind." <b> ".$phraseToFind." && ".$secondOption." </b> has not defined translation on ".$theLangPath."/".LANGFILE;
				}

			}
			else{
				return "Warning: ".$errorKind." <b> ".$phraseToFind."</b> has not defined translation on ".$theLangPath."/".LANGFILE;
			}
		}
	}

	function _langArray($errorKind){

		if(isset($_SESSION['lang']) && $_SESSION['lang'] != ""){
            $theLangPath = _PATH_LANG.$_SESSION['lang'];
		}
        else{
            $theLangPath = _PATH_LANG._SYSLANG;
        }

		include(includeFile($theLangPath."/".LANGFILE));
		$result = $_lang[$errorKind];
		return $result;
	}
