<?php
  /**************************************************************************\
  * phpGroupWare - Translation Editor                                        *
  * http://www.phpgroupware.org                                              *
  * --------------------------------------------                             *
  *  This program is free software; you can redistribute it and/or modify it *
  *  under the terms of the GNU General Public License as published by the   *
  *  Free Software Foundation; either version 2 of the License, or (at your  *
  *  option) any later version.                                              *
  \**************************************************************************/

	/* $Id: generatelangfile.php,v 1.16.2.2 2001/07/10 11:49:09 milosch Exp $ */

	if ($submit)
	{
		Header('Content-type: text/plain');
		$phpgw_flags = Array(
			'currentapp' =>	'transy',
			'nonavbar'   => True,
			'noheader'   => True,
			'enable_browser_class' => True
		);
	}
	else
	{
		$phpgw_flags = Array(
			'currentapp' =>	'transy'
		);
	}

	$phpgw_info['flags'] = $phpgw_flags;
	include('../header.inc.php');

	if ($submit)
	{
		$filter = '';
		if ($app_selected != 'all' || $app_lang != 'any')
		{
			$filter .= 'where ';
		}

		if ($app_selected != 'all')
		{
			$filter .= "app_name='$app_selected' ";
		}

		if ($app_lang != 'any')
		{
			if ($app_selected != 'all')
			{
				$filter .= 'AND ';
			}
			$filter .= "lang='$app_lang' ";
		}
		$phpgw->db->query('SELECT * FROM lang '.$filter.'ORDER BY message_id');

		if ($download)
		{
			$filename = 'phpgw_'.$app_lang.'.lang';
			$phpgw->browser->content_header($filename);
			/*
			header('Content-disposition: attachment; filename="'.$filename.'"');
			header('Content-type: application/octetstream');
			header('Pragma: no-cache');
			header('Expires: 0');
			*/
		}

		while ($phpgw->db->next_record())
		{
			echo strtolower($phpgw->db->f('message_id')) . "\t" . $phpgw->db->f('app_name') . "\t" . $phpgw->db->f('lang')
				. "\t" . $phpgw->db->f('content') . "\n";
		}
		$phpgw->common->phpgw_exit();
	}
?>
  <p><b><?php echo lang('Generate new lang.sql file'); ?></b><hr><p>

 <form method="POST" action="<?php echo $phpgw->link('/transy/generatelangfile.php'); ?>">
  <table border="0">
   <tr>
    <td><?php echo lang('Select application'); ?></td>
    <td>
     <select name="app_selected">
      <option value="all"><?php echo lang('all'); ?></option>
      <option value="common"><?php echo lang('common'); ?></option>
<?php
	$apps = CreateObject('phpgwapi.applications');
	$applist = $apps->read_installed_apps();
	@reset($phpgw_info['apps']);
	$availableApps = $phpgw_info['apps'];
	@asort($availableApps);
	@reset($availableApps);
	while ($app = each($availableApps))
	{
		if ($app[1]['enabled'])
		{
			echo '<option value="' . $app[0] . '">' . $app[1]['title'] . '</option>';
		}
	}
?>
     </select>
   </tr>
   <tr>
    <td><?php echo lang('Select language to generate for'); ?></td>
    <td>
     <select name="app_lang">
      <option value="any"><?php echo lang('any'); ?></option>
<?php
	$phpgw->db->query('select lang,languages.lang_name,languages.lang_id from lang,languages where lang.lang='
		. 'languages.lang_id group by lang,languages.lang_name,languages.lang_id order by lang');
	while ($phpgw->db->next_record())
	{
		echo '<option value="' . $phpgw->db->f('lang') . '">' . $phpgw->db->f('lang_id') . ' - ' . $phpgw->db->f('lang_name')
			. '</option>';
	}
?>
     </select>
   </tr>

   <tr>
    <td></td>
    <td><input type="checkbox" name="download"><?php echo lang('Download output as a lang file'); ?></td>
   </tr>
   <tr>
    <td colspan="2" align="center"><input type="submit" name="submit" value="<?php echo lang('submit'); ?>"></td>
   </tr>

  </table>
 </form>
<?php
	$phpgw->common->phpgw_footer();
?>
