<?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: addsingle.php,v 1.8.2.1 2001/07/06 19:01:39 milosch Exp $ */

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

	$phpgw->template->set_file(array('form' => 'singleform.tpl'));

	if ($submit)
	{
		$phpgw->db->query("select count(*) from lang where lang='" . addslashes($new_lang)
			 . "' and message_id='" . addslashes(strtolower($new_message_id)) . "' and "
			 . "app_name='$new_application'");
		$phpgw->db->next_record();

		$totalerrors = 0;
		if ($phpgw->db->f(0) != 0)
		{
			$errors[$totalerrors++] = lang('That phrase already exists');
		}

		if (!$totalerrors)
		{
			$phpgw->db->query("insert into lang (message_id, app_name, lang, content) VALUES ('"
				. addslashes(strtolower($new_message_id)) . "','" . $new_application . "','"
				. addslashes($new_lang) . "','" . addslashes($new_trans) . "')");
			$phpgw->template->set_var('lang_error_messages',"<center>" . lang("New phrase has been added") . "</center>");
		}
	}
	else
	{
		$phpgw->template->set_var('lang_error_messages','');
	}

	if ($totalerrors)
	{
		$phpgw->template->set_var('lang_error_messages',"<center>" . $phpgw->common->error_list($errors) . "</center>");
		$phpgw->template->set_var('message_id_field','<input name="new_message_id" value="' . $new_message_id . '">');
		$phpgw->template->set_var('translation_field','<input name="new_trans" value="' . $new_trans . '">');
	}
	else
	{
		$phpgw->template->set_var('message_id_field','<input name="new_message_id">');
		$phpgw->template->set_var('translation_field','<input name="new_trans">');
	}

	if ($new_lang)
	{
		$lang_selected[$new_lang] = " selected";
	}
	if ($new_application)
	{
		$app_selected[$new_application] = " selected";
	}

	$phpgw->template->set_var('lang_message',lang('Add new phrase'));
	$phpgw->template->set_var('form_action',$phpgw->link('/transy/addsingle.php'));

	$phpgw->template->set_var('lang_select',lang('select which language for this phrase'));
	$phpgw->template->set_var('lang_application',lang('select which application for this phrase'));
	$phpgw->template->set_var('lang_message_id',lang('Phrase in English'));
	$phpgw->template->set_var('lang_translation',lang('Phrase in new language'));

	$phpgw->template->set_var('lang_button',lang('add'));

	$phpgw->db->query("select app_name, app_title from phpgw_applications where "
		. "app_enabled='1' and app_name !='cron_apps' order by app_name");

	$html_select  = '<select name="new_application">';
	$html_select .= '<option value="common">Common</option>';
	while ($phpgw->db->next_record())
	{
		$html_select .= '<option value="' . $phpgw->db->f("app_name") . '"'
			. $app_selected[$phpgw->db->f("app_name")] . '>' . $phpgw->db->f("app_title")
			. '</option>';
	}
	$html_select .= "</select>";
	$phpgw->template->set_var('select_application',$html_select);

	$phpgw->db->query("select lang_id,lang_name from languages order by lang_name");
	$html_select = '<select name="new_lang">';
	while ($phpgw->db->next_record())
	{
		$html_select .= '<option value="' . $phpgw->db->f("lang_id") . '"'
			. $lang_selected[$phpgw->db->f("lang_id")] . '>' . $phpgw->db->f("lang_name")
			. '</option>';
	}
	$html_select .= "</select>";
	$phpgw->template->set_var('select_lang',$html_select);

	$phpgw->template->pparse('out','form');
	$phpgw->common->phpgw_footer();
?>
