summaryrefslogtreecommitdiff
path: root/master_strings.php
blob: 9e922502dcee3ede419d8038fd8653d1505d1cae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<?php
/**
 * @package languages
 * @subpackage functions
 * @version $Header$
 */

// Copyright (c) 2005, bitweaver.org
// All Rights Reserved. See below for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See http://www.gnu.org/copyleft/lesser.html for details.
/**
 * Initialization
 */
require_once( '../kernel/setup_inc.php' );

$gBitSystem->verifyPermission( 'p_languages_edit_master' );

$languages = $gBitLanguage->listLanguages();
$gBitSmarty->assignByRef( 'languages', $languages );
$feedback = $masterMsg = array();

if( !empty( $_REQUEST['source_hash'] ) && !is_array( $_REQUEST['source_hash'] ) ) {
	$_REQUEST['source_hash'] = array( $_REQUEST['source_hash'] );
}

if( !empty( $_REQUEST['delete_master'] ) && !empty( $_REQUEST['source_hash'] ) ) {
	if( empty( $_REQUEST['confirm'] ) ) {
		$gBitSystem->setBrowserTitle( tra( 'Confirm Delete' ) );
		$formHash['delete_master'] = TRUE;
		$msgHash = array(
			'label' => tra( 'Delete Master Strings' ),
			'warning' => tra( 'This will remove the language master string. If you are tracking translations and the string is still used, it will be inserted again, however, any translations associated with it will be lost.' ),
			'confirm_item' => tra( "The following Master Strings will be removed" ).":",
		);
		foreach( $_REQUEST['source_hash'] as $source_hash ) {
			$gBitLanguage->loadMasterStrings( $source_hash );
			$formHash['input'][] = '<input type="hidden" name="source_hash[]" value="'.$source_hash.'"/>'.htmlentities( $gBitLanguage->mStrings['master'][$source_hash]['source'] );
		}
		$gBitSystem->confirmDialog( $formHash, $msgHash );
	} else {
		foreach( $_REQUEST['source_hash'] as $source_hash ) {
			if( $gBitLanguage->expungeMasterString( $source_hash ) ) {
				$success = TRUE;
			} else {
				$error = TRUE;
			}
		}

		if( !empty( $error ) ) {
			$feedback['error'] = 'At least one of the master strings could not be deleted.';
		} elseif( !empty( $success ) ) {
			$feedback['success'] = 'The requested master strings were successfully deleted.';
		}
	}
} elseif( !empty( $_REQUEST['save_translations'] ) ) {
	foreach( $_REQUEST['edit_trans'] as $sourceHash => $sources ) {
		foreach( $sources as $langCode => $string ) {
			$tranStrings[$sourceHash] = $gBitLanguage->getTranslatedStrings( $sourceHash );
			// store if (We had a string and it is now empty) or ( we have a new string and it is different from before)
			if( (empty( $string ) && !empty( $tranStrings[$sourceHash][$langCode] ))
				|| (!empty( $string ) && (empty( $tranStrings[$sourceHash][$langCode] ) || $string != $tranStrings[$sourceHash][$langCode]['trans']) ) ) {
				$gBitLanguage->storeTranslationString( $langCode, $string, $sourceHash );
			}
		}
		$gBitLanguage->loadMasterStrings( $sourceHash );
		if( !empty( $_REQUEST['edit_master'][$sourceHash] ) ) {
			$newSourceHash = $gBitLanguage->getSourceHash( $_REQUEST['edit_master'][$sourceHash] );
			$gBitLanguage->loadMasterStrings();
			if( $newSourceHash != $sourceHash ) {
				if( $gBitLanguage->storeMasterString( array( 'source_hash' => $sourceHash, 'new_source' => $_REQUEST['edit_master'][$sourceHash] ) ) ) {
					unset( $_REQUEST['source_hash'] );
					$_REQUEST['source_hash'][] = $newSourceHash;
					$tranStrings[$newSourceHash] = $gBitLanguage->getTranslatedStrings( $newSourceHash );
					$masterMsg['success'][] = 'Master translation string has been updated';
				} else {
					$masterMsg['error'][] = $gBitLanguage->mErrors['master'];
				}
			}
		}
	}
	$masterMsg['success'][] = 'Translation strings have been updated';
} elseif( !empty( $_REQUEST['find'] ) && !empty( $_REQUEST['search'] ) ) {
	$gBitSmarty->assignByRef( 'masterStrings', $gBitLanguage->searchMasterStrings( $_REQUEST['find'] ) );
} else {
	$gBitLanguage->loadMasterStrings(
		NULL,
		( !empty( $_REQUEST['filter'] ) ? $_REQUEST['filter'] : NULL ),
		( !empty( $_REQUEST['filter_lang'] ) ? $_REQUEST['filter_lang'] : NULL )
	);

	// work out what strings to display
	if( empty( $_REQUEST['char'] )) {
		$pattern = "/^a/i";
	} elseif ( $_REQUEST['char'] == '0-9' ) {
		$pattern = "/^\d/";
	} elseif ( $_REQUEST['char'] == '+' ) {
		$pattern = "/^[^a-zA-Z0-9]/";
	} elseif ( $_REQUEST['char'] == 'all' ) {
		$pattern = "//";
	} else {
		$pattern = "/^".$_REQUEST['char']."/i";
	}
	$masterStr = $gBitLanguage->mStrings['master'];
	foreach( $masterStr as $key => $master ) {
		if( preg_match( $pattern, $master['source'] ) ) {
			$masterStrings[$key] = $master;
		}
	}
	$gBitSmarty->assign( 'char', empty( $_REQUEST['char'] ) ? '' : $_REQUEST['char'] );
	$gBitSmarty->assignByRef( 'masterStrings', $masterStrings );
}


if( !empty( $_REQUEST['source_hash'] ) && empty( $_REQUEST['cancel'] ) ) {
	foreach( $_REQUEST['source_hash'] as $reqSourceHash ) {
		$gBitLanguage->loadMasterStrings( $reqSourceHash );
		if( strlen( $gBitLanguage->mStrings['master'][$reqSourceHash]['source'] ) > 100 ) {
			$gBitLanguage->mStrings['master'][$reqSourceHash]['textarea'] = TRUE;
		}
		$translate[$reqSourceHash] = $gBitLanguage->getTranslatedStrings( $_REQUEST['source_hash'] );
	}
	$gBitSmarty->assignByRef( 'masterStrings', $gBitLanguage->mStrings['master'] );
	$gBitSmarty->assignByRef( 'tranStrings', $translate );
	$gBitSmarty->assign( 'sources', $_REQUEST['source_hash'] );
}

// Display the template
$gBitSmarty->assign( 'masterMsg', $masterMsg );
$gBitSmarty->assign( 'feedback', $feedback );
$gBitSystem->display( 'bitpackage:languages/language_master_strings.tpl', 'Edit Master Strings' , array( 'display_mode' => 'display' ));
?>