Location: PHPKode > scripts > Ajax Availability Calendar > ac-v3.03.07/ac-admin/languages.admin.php
	//$warning="go through db to find lang fields.....";

	1	-	get all tables
	2	-	get all fields in table
	3	-	IF field LIKE "_en" then we have lang column
	4	-	get column name substr(field_name,0,-3) - removing last 3 chars
	5	-	add new column with this name and NEW lang code
	6	-	copy data from lang defined col to new col - NO

	//	 vars to be sent in form
	$new_lang	=	$_POST["new_code"];	# new code for lang#
	//	 get all tables
	$res_db = mysql_query($sql_db) or die("Error getting DB TABLES");
	while ($row_db = mysql_fetch_row($res_db)) {
		//echo "Table: {$row[0]}\n";
	   	// now get fields within tables
		$sql_tables="SHOW COLUMNS FROM ".$row_db[0]."";
	  	$res_table = mysql_query($sql_tables) or die("Error getting TABLE COLUMNS");
		if (mysql_num_rows($res_table) > 0) {
			while ($row_table= mysql_fetch_assoc($res_table)) {
				//	 check if column looks like a lang column
		  		$this_field	=	$row_table["Field"];
				$this_type	=	$row_table["Type"];
					//	 is a lang column, now get name (without lang code)
					$this_lang_desc		=	substr($this_field,0,-2);		#	remove lang to get get base col desc
					$new_lang_col		=	$this_lang_desc.$new_lang;		#	define new col name
					//	 check if column exist allready
					$sql_check="SELECT ".$new_lang_col." FROM ".$this_table." LIMIT 1";
						// if it returns a result that means it is already there
						$warning="<br><span class='warning'>COLUMN ".$new_lang_col." already existe in table ".$this_table."</span>";
						//	 now add new lang to db
						$add="ALTER TABLE `".$this_table."` ADD `".$new_lang_col."` ".$this_type."  NOT NULL";
						//echo "<br>ADD NEW COLUMN - ".$add;
						mysql_query($add) or die("Error ADDING AC_LANGUAGE");
						$warning.="New language field \"".$new_lang_col."\" added to the \"".$this_table."\" table<br>";
					}		#	if column exists
		   		}			#	detect if lang col (use _en)
			}				#	while table fields
		}					#	if results
	}						#	while tables
	//	 now copy lang file with new lang extension
	$file 		= 	AC_DIR_AC_LANG."en.lang.php";
	$newfile 	= 	AC_DIR_AC_LANG.$new_lang.".lang.php";	
	if (!copy($file, $newfile)){
		$warning.="failed to copy $file...<br>";
		$error	=true;
	//else							//$warning.="Lang file <strong>".$new_lang."</strong> created<br>";
	//	 set file permisions for writing
	if(!chmod($newfile, 0777)){
		$warning.="Unable to change file permisions<br>";
		$error	=true;
	//else		$warning.="File permisions modified.<br>";
	if(!isset($error)) header("Location:index.php?page=".ADMIN_PAGE."&id_added=".$new_lang."&msg=add_OK");

//	modify item

	//	remove slashes added by php settings
	function stripslashes_deep($value){
	   return (is_array($value) ? array_map('stripslashes_deep', $value) : stripslashes($value));
	if (get_magic_quotes_gpc()){
	   $_GET    = array_map('stripslashes_deep', $_GET);
	   $_POST  = array_map('stripslashes_deep', $_POST);
	   $_COOKIE = array_map('stripslashes_deep', $_COOKIE);

	$filename =AC_DIR_AC_LANG.$_REQUEST["code"].'.lang.php';
	// open file and rewrite
	$mod_page="<?php\n \$lang=array();\n";
	foreach($_POST["new_value"] as $key=>$val){
		//$mod_page.="\"".$key."\" => \"".addslashes(trim($val))."\",\n";
		$val	=	trim($val);
		$val	=	str_replace('"','\"',$val);
		$val	=	str_replace('$','\$',$val);
		$val	=	htmlspecialchars($val,ENT_QUOTES);
		$val	=	str_replace("'","\'",$val);
		$mod_page.="\$lang[\"".$key."\"] = \"".$val."\";\n";
	// remove last ","
	$mod_page .= "\n?>";
	//echo $mod_page;
	if(!$handle = @fopen($filename, "w"))	die ("<br>Cannot open lang file ".$filename."");
	if(!@fwrite($handle, $mod_page)) 	die("<br>CAN'T WRITE FILE - NO PERMISSION");
	else	$warning="AC_LANGUAGE FILE ".$_REQUEST["lang_file"]." MODIFIED";

//	delete item
	//	delete lang file and db fields
		//	we should remove the language fields from the database at this point - TO DO

		case "new":
			$xtra_moo		.=	'new FormCheck("item_form")';
			<form method="post" id="item_form" onSubmit="return confirm(\''.$lang["warning_new_lang_confirm"].'\');">
					<td class="side">'.$lang["new_lang_code"].'</td>
					<td style="width:80px;"><input type="text" name="new_code" size="3" maxlength="3" class="validate[\'required\'] text-input">
					<td><input type="submit" value="'.$lang["bt_add"].'"> </td>
					<td colspan="3" class="note">'.$lang["note_add_language"].'</td>
		case "edit":
			<script type="text/javascript" src="js/mootools-flext.js"></script>
			//	open lang file AND english version (for reference)
			//	texts for this page - var conflict
		//	$file_to_open	= 	$lang["lang_to_modify"];
		//	$translate		=	$lang["translation"];
		//	$finish			=	$lang["finish"];
			//	define lang file to open
			$filename = AC_DIR_AC_LANG.$_REQUEST["code"];
			$this_lang	=	$_REQUEST["code"];
			$orig_lang	=	"en";
			//	include english version for reference
			//if(AC_LANG!="en") include(DIR_AC_LANG.$orig_lang."lang.php");
			//	temp save user lang as it will be overwritten when we get the lang file to modify
			//	check lang file is writable
				<div class="warning">
					Unable to modifiy the language file that you have chosen as you do not have "write" permissions.<br>
					To be able to modify the language files you most change the permissions to chmod 777.
				//	get lang file to modify
				//	rename lang var (array) for editing
				//	reset user lang var
				foreach($lang_to_modify as $key=>$val){
					$val	=	str_replace("\'","&lsquo;",$val);	# convert chars to html asci;
					if(strlen($val)>60)	$input="<textarea name='new_value[".$key."]' style='width:99%;height:60px;' class='flext growme'>".$val."</textarea>";
					else				$input="<input type='text' style=' width:99%;' name='new_value[".$key."]' value='".$val."' >";
						<td class="side">'.$key.'</td>
						<td class="spacer">'.$input.'</td>
					 //<td class='data'><em>".$lang_en[$key]."</em></td><td class='data'><em>".$lang_en[$key]."</em></td>
				$page_title_add	= ' - '.$lang["title_mod"].' - '.strtoupper($_REQUEST["code"]);
				<form method="post" id="item_form">
				<input type="hidden" name="code" value="'.$_REQUEST["code"].'"> 
				<input type="hidden" name="modify_it" value="1">
				<table class="data">
						<td>'.$lang["language"].': '.$this_lang.'</td>
						<td><input type="submit" value="'.$lang["bt_save_changes"].'"></td>
		case "delete":
			$page_title_add	= ' - '.$lang["title_delete"].' - '.strtoupper($_REQUEST["code"]);
			<form method="post" onSubmit="return confirm(\''.$lang["warning_delete_confirm"].'\');">
			<input type="hidden" name="delete_it" value="1">
			<input type="hidden" name="code" value="'.$_REQUEST["code"].'"> 
					<td class="side">'.$lang["language"].'</td>
					<td class="data"><strong>'.$_REQUEST["code"].'</strong></td>
					<td><input type="submit" value="'.$lang["bt_delete"].'"></td>

	//	list current languages to be edited via admin
	foreach($languages AS $code=>$i){
		if($code==$_REQUEST["id_modified"]) 	$item_modified='<span class="modified">'.$lang["item_modified"].'</span>';
		if($code==$_REQUEST["id_added"]) 		$item_modified='<span class="modified">'.$lang["item_added"].'</span>';
			<td>'.$code.' '.$item_modified.'</td>
			<td class="options">
				<a href="?page='.ADMIN_PAGE.'&action=edit&code='.$code.'" title="'.$lang["tip_edit_item"].'">'.$icons["edit"].'</a>
				<a href="?page='.ADMIN_PAGE.'&action=delete&code='.$code.'" title="'.$lang["tip_delete_item"].'">'.$icons["delete"].'</a>
	$bt_add='<a href="?page='.ADMIN_PAGE.'&action=new" title="'.$lang["tip_add_new_item"].'">'.$icons["add"].'</a>';
	<table class="list">
			<td class="options">'.$lang["options"].'</td>
			<td colspan="'.($cols-1).'" class="spacer">&nbsp;</td>
			<td class="center">'.$bt_add.'</td>
Return current item: Ajax Availability Calendar