From e0622f800afd662f842df5624b946839c3ba3909 Mon Sep 17 00:00:00 2001
From: Robert Sesek <rsesek@bluestatic.org>
Date: Thu, 26 Feb 2009 13:11:22 -0500
Subject: [PATCH] Update the admin/language.php to use templates

* admin/language.php
* admin/templates/language.html: New file
* admin/templates/language_edit.html: New file
* admin/templates/nav.html: Link up the nav page
---
 admin/language.php                 | 99 +++++-------------------------
 admin/templates/language.html      | 48 +++++++++++++++
 admin/templates/language_edit.html | 70 +++++++++++++++++++++
 admin/templates/nav.html           |  2 +-
 4 files changed, 136 insertions(+), 83 deletions(-)
 create mode 100644 admin/templates/language.html
 create mode 100644 admin/templates/language_edit.html

diff --git a/admin/language.php b/admin/language.php
index 6c32068..91348ec 100644
--- a/admin/language.php
+++ b/admin/language.php
@@ -19,14 +19,13 @@
 || ###################################################################
 \*=====================================================================*/
 
+$fetchtemplates = array(
+	'language'
+);
+
 require_once('./global.php');
 require_once('./includes/api_language.php');
 
-APIError(array(new API_Error_Handler($admin), 'admin_error'));
-
-NavLinks::optionsPages();
-$navigator->set_focus('tab', 'options', null);
-
 if (!can_perform('canadmintools'))
 {
 	admin_login();
@@ -45,10 +44,10 @@ if ($_REQUEST['do'] == 'kill')
 {
 	$language = new LanguageAPI();
 	$language->set('languageid',	$input->in['languageid']);
-	$language->set_condition();
+	$language->setCondition();
 	$language->delete();
 	
-	$admin->redirect('language.php?do=modify');
+	admin_flash_redirect('language.php?do=modify');
 }
 
 // ###################################################################
@@ -70,35 +69,14 @@ if ($_POST['do'] == 'insert')
 	$language->set('langcode',		$input->in['langcode']);
 	$language->insert();
 	
-	$admin->redirect('language.php?do=modify');
+	admin_flash_redirect('language.php?do=modify');
 }
 
 // ###################################################################
 
 if ($_REQUEST['do'] == 'add')
 {
-	NavLinks::languagesAdd();
-	$navigator->set_focus('link', 'options-languages-add', 'options-languages');
-	
-	$admin->page_start(T('New Language'));
-	
-	$admin->form_start('language.php', 'insert');
-	$admin->table_start();
-	$admin->table_head(T('New Language'));
-	
-	$admin->row_input(T('Title'), 'title');
-	$admin->row_input(T('Gettext Language Code (<em><a href="http://www.gnu.org/software/gettext/manual/html_chapter/gettext_15.html">language</a></em>_<em><a href="http://www.gnu.org/software/gettext/manual/html_chapter/gettext_16.html">COUNTRY</a></em>)'), 'langcode');
-	$admin->row_input(T('Character Set'), 'charset', 'utf-8');
-	$admin->list_item(T('Left-to-Right'), 'ltr', true);
-	$admin->list_item(T('Right-to-Left'), 'rtl');
-	$admin->row_list(T('Direction'), 'direction');
-	$admin->row_yesno(T('User Selectable'), 'userselect', true);
-	
-	$admin->row_submit();
-	$admin->table_end();
-	$admin->form_end();
-	
-	$admin->page_end();
+	BSTemplate::fetch('language_edit')->evaluate()->flush();
 }
 
 // ###################################################################
@@ -107,7 +85,7 @@ if ($_POST['do'] == 'update')
 {
 	$language = new LanguageAPI();
 	$language->set('languageid',	$input->in['languageid']);
-	$language->set_condition();
+	$language->setCondition();
 	$language->set('title',			$input->in['title']);
 	$language->set('charset',		$input->in['charset']);
 	$language->set('direction',		$input->in['direction']);
@@ -115,73 +93,30 @@ if ($_POST['do'] == 'update')
 	$language->set('langcode',		$input->in['langcode']);
 	$language->update();
 	
-	$admin->redirect('language.php?do=modify');
+	admin_flash_redirect('language.php?do=modify');
 }
 
 // ###################################################################
 
 if ($_REQUEST['do'] == 'edit')
 {
-	NavLinks::languagesEdit($input->in['languageid']);
-	$navigator->set_focus('link', 'options-languages-edit', 'options-languages');
-	
 	$languageapi = new LanguageAPI();
 	$languageapi->set('languageid', $input->in['languageid']);
-	$languageapi->set_condition();
+	$languageapi->setCondition();
 	$languageapi->fetch();
 	
-	$language =& $languageapi->record;
-	
-	$admin->page_start(T('Edit Language'));
-	
-	$admin->form_start('language.php', 'update');
-	$admin->table_start();
-	$admin->table_head(sprintf(T('Edit Language - %1$s'), $language['title']));
-	
-	$admin->form_hidden_field('languageid', $language['languageid']);
-	
-	$admin->row_input(T('Title'), 'title', $language['title']);
-	$admin->row_input(T('Gettext Language Code (<em><a href="http://www.gnu.org/software/gettext/manual/html_chapter/gettext_15.html">language</a></em>_<em><a href="http://www.gnu.org/software/gettext/manual/html_chapter/gettext_16.html">COUNTRY</a></em>)'), 'langcode', $language['langcode']);
-	$admin->row_input(T('Character Set'), 'charset', $language['charset']);
-	$admin->list_item(T('Left-to-Right'), 'ltr', (($language['direction'] == 'ltr') ? true : false));
-	$admin->list_item(T('Right-to-Left'), 'rtl', (($language['direction'] == 'rtl') ? true : false));
-	$admin->row_list(T('Direction'), 'direction');
-	$admin->row_yesno(T('User Selectable'), 'userselect', $language['userselect']);
-	
-	$admin->row_submit();
-	$admin->table_end();
-	$admin->form_end();
-	
-	$admin->page_end();
+	$admin = new BSTemplate('language_edit');
+	$admin->vars['language'] = $language->record;
+	$admin->evaluate()->flush();
 }
 
 // ###################################################################
 
 if ($_REQUEST['do'] == 'modify')
 {
-	NavLinks::languagesAdd();
-	$navigator->set_focus('link', 'options-pages-languages', 'options-pages');
-	
-	$admin->page_start(T('Manage Languages'));
-		
-	$admin->table_start();
-	$admin->table_head(T('Manage Languages'), 3, 'language_manage');
-	
-	$admin->table_column_head(array(T('Title'), T('Language Code / Charset'), T('Options')));
-	
-	$languages = $db->query("SELECT * FROM " . TABLE_PREFIX . "language ORDER BY languageid ASC");
-	foreach ($languages as $language)
-	{
-		$admin->row_multi_item(array(
-			"<a href=\"language.php?do=edit&amp;languageid=$language[languageid]\">$language[title]</a>" => 'l',
-			$language['langcode'] . ' / ' . $language['charset'] => 'c',
-			((bugdar::$options['defaultlanguage'] == $language['languageid']) ? '<strong>' . T('DEFAULT LANGUAGE') . '</strong> / ' : '') . ($language['userselect'] ? T('User Selectable') : T('Private')) => 'c'
-		));
-	}
-	
-	$admin->table_end();
-	
-	$admin->page_end();
+	$admin = new BSTemplate('language');
+	$admin->vars['languages'] = $db->query("SELECT * FROM " . TABLE_PREFIX . "language ORDER BY languageid ASC");
+	$admin->evaluate()->flush();
 }
 
 ?>
\ No newline at end of file
diff --git a/admin/templates/language.html b/admin/templates/language.html
new file mode 100644
index 0000000..8dd8739
--- /dev/null
+++ b/admin/templates/language.html
@@ -0,0 +1,48 @@
+<%- $templates['doctype'] %>
+<html xmlns="http://www.w3.org/1999/xhtml" lang="<%- $stylevar['lang'] %>" xml:lang="<%- $stylevar['lang'] %>" dir="<%- $stylevar['lang_dir'] %>">
+<head>
+	<%- $templates['headinclude'] %>
+	<title><%- $templates['title'] %> - <%- T('Manage Languages') %></title>
+</head>
+
+<body>
+
+<%- $templates['nav'] %>
+
+<div id="title"><%- T('Manage Languages') %></div>
+
+<div id="body">
+
+<%- admin_flash() %>
+
+<table>
+<thead>
+	<tr><td colspan="3"><%- T('Manage Languages') %></td></tr>
+	<tr class="headings">
+		<td><%- T('Title') %></td>
+		<td><%- T('Language Code / Charset') %></td>
+		<td><%- T('Options') %></td>
+	</tr>
+</thead>
+<% foreach ($languages as $language): %><% BSFunctions::swap_css_classes() %>
+<tr class="<%- BSFunctions::$cssClass %>">
+	<td><a href="language.php?do=edit&amp;languageid=<%- $language['languageid'] %>"><%- $language['title'] %></a></td>
+	<td><%- $language['langcode'] %> / <%- $language['charset'] %></td>
+	<td>
+		<% if (bugdar::$options['defaultlanguage'] == $language['languageid']): %><strong><%- T('DEFAULT LANGUAGE') %></strong> /<% endif %>
+		<% if ($language['userselect']): %><%- T('User Selectable') %><% else: %><%- T('Private') %><% endif %>
+	</td>
+</tr>
+<% endforeach %>
+<tr class="submit"><td colspan="3"><a href="language.php?do=add"><%- T('Add New Language') %></a></tr>
+</table>
+
+<%- admin_footer() %>
+
+</div>
+
+<script type="text/javascript"> nav_init("system", "system_language"); </script>
+
+</body>
+
+</html>
\ No newline at end of file
diff --git a/admin/templates/language_edit.html b/admin/templates/language_edit.html
new file mode 100644
index 0000000..12ed9fe
--- /dev/null
+++ b/admin/templates/language_edit.html
@@ -0,0 +1,70 @@
+<%- $templates['doctype'] %>
+<html xmlns="http://www.w3.org/1999/xhtml" lang="<%- $stylevar['lang'] %>" xml:lang="<%- $stylevar['lang'] %>" dir="<%- $stylevar['lang_dir'] %>">
+<head>
+	<%- $templates['headinclude'] %>
+	<title><%- $templates['title'] %> - <%- T('Manage Languages') %></title>
+</head>
+
+<body>
+
+<%- $templates['nav'] %>
+
+<div id="title"><%- T('Manage Languages') %></div>
+
+<div id="body">
+
+<%- admin_flash() %>
+
+<form action="language.php" method="post">
+<input type="hidden" name="do" value="<%- ($language ? 'update' : 'insert') %>" />
+<% if ($language): %><input type="hidden" name="languageid" value="<%- $language['languageid'] %>" /><% endif %>
+
+<fieldset>
+	<legend><%- ($language ? T('Edit Language') : T('New Language')) %></legend>
+	
+	<dl>
+	
+	<dt><label for="l_title"><%- T('Title') %></label></dt>
+	<dd><input type="text" name="title" value="<%- $language['title'] %>" id="l_title" /></dd>
+	
+	<dt>
+		<label for="langcode">
+			<%- T('Gettext Language Code') %>
+			<dfn><strong><%- T('Format') %>:</strong> <em><a href="http://www.gnu.org/software/gettext/manual/html_chapter/gettext_15.html">language</a></em>_<em><a href="http://www.gnu.org/software/gettext/manual/html_chapter/gettext_16.html">COUNTRY</a></em></dfn>
+		</label>
+	</dt>
+	<dd><input type="text" name="langcode" value="<%- $language['langcode'] %>" id="langcode" /></dd>
+	
+	<dt><label for="charset"><%- T('Character Set') %></label></dt>
+	<dd><input type="text" name="charset" value="<%- $language['charset'] %>" id="charset" /></dd>
+	
+	<dt><label for="direction"><%- T('Text Direction') %></label></dt>
+	<dd>
+		<select name="direction" id="direction">
+			<option value="ltr"<%- ($language['direction'] == 'ltr' ? BSDecorator::HTML_SELECTED : '') %>><%- T('Left-to-Right') %></option>
+			<option value="rtl"<%- ($language['direction'] == 'rtl' ? BSDecorator::HTML_SELECTED : '') %>><%- T('Right-to-Left') %></option>
+		</select>
+	</dd>
+	
+	<dt><label for="userselect"><%- T('User Selectable') %></label></dt>
+	<dd><%- BSDecorator::yesno('userselect', $language['userselect']) %></dd>
+	
+	</dl>
+</fieldset>
+
+<div class="submit">
+	<input type="submit" value="<%- T('Save') %>" />
+	<input type="reset" value="<%- T('Reset') %>" />
+</div>
+
+<%- admin_footer() %>
+
+</div>
+
+</body>
+
+<script type="text/javascript"> nav_init("system", "system_language"); </script>
+
+</body>
+
+</html>
\ No newline at end of file
diff --git a/admin/templates/nav.html b/admin/templates/nav.html
index e007bca..15d32bc 100644
--- a/admin/templates/nav.html
+++ b/admin/templates/nav.html
@@ -14,7 +14,7 @@
 		<li>
 			<ul>
 				<li id="nav_system_settings"><a href="settings.php"><%- T('Bugdar Settings') %></a></li>
-				<li><a href="language.php"><%- T('Languages') %></a></li>
+				<li id="nav_system_language"><a href="language.php"><%- T('Languages') %></a></li>
 				<li><a href="userhelp.php"><%- T('User Help Items') %></a></li>
 			</ul>
 		</li>
-- 
2.43.5