tiki-edit_languages.php 5.52 KB
Newer Older
redflo's avatar
redflo committed
1
<?php
changi67's avatar
changi67 committed
2 3 4
/**
 * @package tikiwiki
 */
5
// (c) Copyright 2002-2016 by authors of the Tiki Wiki CMS Groupware Project
6
//
7 8
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
changi67's avatar
changi67 committed
9
// $Id$
redflo's avatar
redflo committed
10

11
require_once ('tiki-setup.php');
12
require_once('lib/language/Language.php');
13
require_once('lib/language/LanguageTranslations.php');
redflo's avatar
redflo committed
14

15
$access->check_feature('lang_use_db');
16
$access->check_permission('tiki_p_edit_languages');
redflo's avatar
redflo committed
17

18
// Get available languages
19 20
$langLib = TikiLib::lib('language');
$languages = $langLib->list_languages();
21
$smarty->assign_by_ref('languages', $languages);
redflo's avatar
redflo committed
22 23 24

// preserving variables
if (isset($_REQUEST["edit_language"])) {
25 26
	$smarty->assign('edit_language', $_REQUEST["edit_language"]);
	$edit_language = $_REQUEST["edit_language"];
27 28
} else {
	$smarty->assign('edit_language', $prefs['language']);
29
	$edit_language = $prefs['language'];
30
}
redflo's avatar
redflo committed
31

32
$translations = new LanguageTranslations($edit_language);
33

34 35
if (!isset($_REQUEST["action"])) {
	$_REQUEST['action'] = 'edit_tran_sw';
36
}
37
$smarty->assign('action', $_REQUEST["action"]);
redflo's avatar
redflo committed
38

39
if (isset($_REQUEST['only_db_translations']) && $_REQUEST['only_db_translations'] != 'n') {
40
	$smarty->assign('only_db_translations', 'y');
41 42 43 44
} else {
	$smarty->assign('only_db_translations', 'n');
}

45
if (isset($_REQUEST['only_db_untranslated']) && $_REQUEST['only_db_untranslated'] != 'n') {
46 47 48
	$smarty->assign('only_db_untranslated', 'y');
} else {
	$smarty->assign('only_db_untranslated', 'n');
49 50
}

redflo's avatar
redflo committed
51 52
// Adding strings
if (isset($_REQUEST["add_tran"])) {
53
	check_ticket('edit-languages');
54 55
	$add_tran_source = $_REQUEST["add_tran_source"];
	$add_tran_tran = $_REQUEST["add_tran_tran"];
redflo's avatar
redflo committed
56

57
	if (strlen($add_tran_source) != 0 && strlen($add_tran_tran) != 0) {
58 59
		$add_tran_source = strip_tags($add_tran_source);
		$add_tran_tran = strip_tags($add_tran_tran);
60

61
		$translations->updateTrans($add_tran_source, $add_tran_tran);
62 63
	}
}
redflo's avatar
redflo committed
64

65 66
// Delete all db translations
if (isset($_REQUEST['delete_all']) && $tiki_p_admin) {
67
	$translations->deleteTranslations();
68 69
}

70
//Selection for untranslated Strings and edit translations
71 72
if (isset($_REQUEST["action"])) {
	$action = $_REQUEST["action"];
redflo's avatar
redflo committed
73
} else {
74
	$action = "";
redflo's avatar
redflo committed
75 76
}

77
if ($action == "edit_rec_sw" || $action == "edit_tran_sw") {
78
	check_ticket('edit-languages');
79 80 81 82 83 84 85
	
	$offset = isset($_REQUEST["offset"]) ? $_REQUEST['offset'] : 0;
	$smarty->assign('offset', $offset);
	
	$maxRecords = (isset($_REQUEST['maxRecords']) && $_REQUEST['maxRecords'] > 0) ? $_REQUEST['maxRecords'] : $prefs['maxRecords'];
	$smarty->assign('maxRecords', $maxRecords);
	
86
	//check if user has translated something
87
	for ($i = 0; $i < $maxRecords; $i++) {
88
		// Handle edits in untranslated strings
89
		if (isset($_REQUEST["edit_tran_$i"]) || isset($_REQUEST['translate_all'])) {
90
			// Handle edits in edit translations
91
			if (strlen($_REQUEST["tran_$i"]) > 0 && strlen($_REQUEST["source_$i"]) > 0) {
92
				$translations->updateTrans($_REQUEST["source_$i"], $_REQUEST["tran_$i"]);
93 94 95
			}
		} elseif (isset($_REQUEST["del_tran_$i"])) {
			// Handle deletes here
96
			if (strlen($_REQUEST["source_$i"]) > 0) {
97
				$translations->deleteTranslation($_REQUEST["source_$i"]);
98
			}
99
		}
100 101 102
	} // end of for ...
	// for resetting untranslated
	if (isset($_REQUEST["tran_reset"])) {
103
		$translations->deleteAllUntranslated();
104 105
	}

106 107 108
	// update language array with new translations
	$query = "select `source`, `tran` from `tiki_language` where `lang`=?";
	$result = $tikilib->fetchAll($query, array($edit_language));
109

110
	foreach ( $result as $row ) {
111
		${"lang_$edit_language"}[ $row['source'] ] = $row['tran'];
112
	}
113

114
	//Handle searches
115
	$find = '';
116

117 118 119
	if (isset($_REQUEST['find']) && strlen($_REQUEST['find']) > 0) {
		$find = $_REQUEST['find'];
		$smarty->assign('find', $find);
120 121
	}

marcius's avatar
marcius committed
122
	$sort_mode = "source_asc";
123

124
	$data = array();
125 126

	if ($action == "edit_rec_sw") {
127
		if (isset($_REQUEST['only_db_untranslated']) && $_REQUEST['only_db_untranslated'] != 'n') {
128 129 130 131 132 133
			// display only database stored untranslated strings
			$data = $translations->getDbUntranslated($maxRecords, $offset, $find);
		} else {
			// display all untranslated strings (language.php + db)
			$data = $translations->getAllUntranslated($maxRecords, $offset, $find);
		}
134
	} elseif ($action == "edit_tran_sw") {
135
		if (isset($_REQUEST['only_db_translations']) && $_REQUEST['only_db_translations'] != 'n') {
136
			// display only database stored translations
137
			$data = $translations->getDbTranslations($sort_mode, $maxRecords, $offset, $find);
138 139
		} else {
			// display all available translations (db + custom.php + language.php)
140
			$data = $translations->getAllTranslations($maxRecords, $offset, $find);
141 142
		}
	}
143

144 145
	$smarty->assign_by_ref('translations', $data['translations']);
	$smarty->assign('total', $data['total']);
146
	$smarty->assign('hasDbTranslations', $translations->hasDbTranslations);
147
}
148

149
$db_languages = Language::getDbTranslatedLanguages();
150
$db_languages = $langLib->format_language_list($db_languages);
151 152
$smarty->assign_by_ref('db_languages', $db_languages);

153
ask_ticket('edit-languages');
redflo's avatar
redflo committed
154

155 156 157
// disallow robots to index page:
$smarty->assign('metatag_robots', 'NOINDEX, NOFOLLOW');

158
$headerlib->add_cssfile('themes/base_files/feature_css/admin.css');
159
$headerlib->add_jsfile('lib/language/js/tiki-edit_languages.js');
160 161

$headtitle = tra('Edit languages');
162
$description = tra('Edit or export languages');
163 164 165 166 167
$crumbs[] = new Breadcrumb($headtitle, $description, '', '', '');
$headtitle = breadcrumb_buildHeadTitle($crumbs);
$smarty->assign('headtitle', $headtitle);
$smarty->assign('trail', $crumbs);

168
$smarty->assign('mid', 'tiki-edit_languages.tpl');
169
$smarty->display("tiki.tpl");