-
Notifications
You must be signed in to change notification settings - Fork 0
/
admin_main.cgi
executable file
·289 lines (254 loc) · 9.29 KB
/
admin_main.cgi
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
#!/usr/bin/perl
# Copyright (C) 2004-2019
# Emmanuel Saracco <emmanuel@esaracco.fr>
#
# GNU GENERAL PUBLIC LICENSE
require './translator-lib.pl';
my ($_success, $_error, $_info) = ('', '', '');
my $app = $in{'app'};
my $old_app = $in{'old_app'};
my $lang = ($in{'lang'} eq '') ? $ref_lang : $in{'lang'};
my $search_type = $in{'search_type'};
my $target = $in{'target'};
my $path = &trans_get_path ($app, 'lang/');
my $interface_selected = ($search_type eq 'interface') ? ' selected="selected"' : '';
my $config_selected = ($search_type eq 'config') ? ' selected="selected"' : '';
my $default_tab = $in{'tab'}||'archives';
# init_msg ()
#
# Set success or error message.
#
sub init_msg ()
{
# creation of the new translation was ok
if ($in{'o'} eq 'new_trans')
{
$_success = sprintf ($text{'MSG_NEW_TRANSLATION'}, $in{'t'});
}
# translation already exists
elsif ($in{'o'} eq 'new_trans_exist')
{
$_error = sprintf ($text{'MSG_NEW_TRANSLATION_EXIST'}, $in{'t'}, $app);
}
# no language
elsif ($in{'o'} eq 'new_trans_bad_no_language')
{
$_error = sprintf ($text{'MSG_NEW_TRANSLATION_BAD_NO_LANGUAGE'}, $in{'t'});
}
# language does not exists
elsif ($in{'o'} eq 'new_trans_bad_not_exists')
{
$_error = sprintf ($text{'MSG_NEW_TRANSLATION_BAD_NOT_EXISTS'}, $in{'t'});
}
# new language is not compatible with current
elsif ($in{'o'} eq 'new_trans_bad_compat')
{
$_error = sprintf ($text{'MSG_NEW_TRANSLATION_BAD_COMPAT'},
$in{'t'}, $current_lang);
}
# problem when created translation
elsif ($in{'o'} eq 'new_trans_bad')
{
$_error = sprintf ($text{'MSG_NEW_TRANSLATION_BAD'}, $in{'t'}, $app);
}
# added new items from ref translation to translation
elsif ($in{'o'} eq 'add_new')
{
$_success = sprintf ($text{'MSG_ADDED_ITEMS'}, $in{'t'});
}
# removed items that do not exists in the ref translation
elsif ($in{'o'} eq 'remove')
{
$_success = sprintf (text{'MSG_REMOVED_ITEMS'}, $in{'t'});
}
# removed all this translation
elsif ($in{'o'} eq 'remove_trans')
{
$_success = sprintf ($text{'MSG_REMOVED_TRANSLATION'}, $in{'t'}, $app);
}
# removed all unused items
elsif ($in{'o'} eq 'remove_unused')
{
$_success = sprintf ($text{'MSG_REMOVED_UNUSED'}, $in{'t'}, $app);
}
# remove selected archives
elsif ($in{'o'} eq 'delete_archives')
{
$_success = $text{'MSG_DELETED_SELECTED_FILES'};
}
# archive was sent without problem
elsif ($in{'o'} eq 'sent_archive')
{
$_success = $text{'MSG_SEND_EMAIL_OK'};
}
}
##### POST actions #####
#
# create new translation if requested
if (defined ($in{'new_translation'}))
{
if (!$in{'new_trans_code'})
{
$in{'o'} = 'new_trans_bad_no_language';
}
else
{
my $lang_infos = &get_languages_infos ($in{'new_trans_code'});
$in{'t'} = $in{'new_trans_code'};
if (!$lang_infos)
{
$in{'o'} = 'new_trans_bad_not_exists';
}
elsif (!$lang_infos->{'current_compat'})
{
$in{'o'} = 'new_trans_bad_compat';
}
else
{
my $ret = &trans_create_translation ($in{'new_trans_code'}, $app);
$in{'o'} =
($ret == 1) ? 'new_trans_exist' :
($ret == 2) ? 'new_trans_bad' :
'new_trans';
}
}
}
# Remove a translation
elsif (defined ($in{'remove'}))
{
&redirect ("remove.cgi?referer=admin_main&app=$app&t=$lang&tab=$default_tab&c=".urlize($target));
exit;
}
else
{
foreach my $item (keys %in)
{
# Download archive
if ($item =~ /^download_(.*)/)
{
&trans_archive_send_browser ($1);
exit;
}
# Delete archive
elsif ($item =~ /^delete_(.*)/)
{
&trans_archive_delete ($1);
$in{'o'} = 'delete_archives';
}
}
}
#
########################
&trans_header ($text{'ADMIN_TITLE'}, $app, $lang);
&trans_get_menu_icons_panel ('admin_main', $app);
print qq(<br/>$text{'ADMIN_DESCRIPTION1'});
print qq(<p/>);
print qq(<form action="admin_main.cgi" method="post">);
print qq(<input type="hidden" name="tab" value="$default_tab">);
print qq(<input type="hidden" name="old_app" value="$app">);
&trans_modules_list_get_options ([$app], '');
if (my $msg = &trans_monitor_panel ($app, $in{'monitor'}))
{
$_success = $msg;
}
# Set success or error msg
&init_msg ();
# Tabs management
my @tabs = (['archives', $text{'ADMIN_TAB_TITLE_ARCHIVES'}]);
if ($app ne '')
{
push @tabs, (
['create_delete', $text{'ADMIN_TAB_TITLE_CREATE_DELETE'}],
['search', $text{'ADMIN_TAB_TITLE_SEARCH'}]);
}
print ui_tabs_start(\@tabs, 'admin', $default_tab);
print ui_tabs_start_tab('admin', 'archives');
&_archives ();
print ui_tabs_end_tab('admin', 'archives');
if ($app ne '')
{
print ui_tabs_start_tab('admin', 'create_delete');
&_create_delete ();
print ui_tabs_end_tab('admin', 'create_delete');
print ui_tabs_start_tab('admin', 'search');
&_search ();
print ui_tabs_end_tab('admin', 'search');
}
print ui_tabs_end();
# Tab 1 "Archives"
sub _archives ()
{
print qq(<h2>$text{'ADMIN_ARCHIVES_TITLE'}</h2>);
print qq(<p>$text{'ADMIN_DESCRIPTION3'}</p>);
print qq(<div><button type="button" onclick="location.href='archive_main.cgi?app=$app'" class="btn btn-default btn-tiny"><i class="fa fa-fw fa-plus-square"></i> <span>$text{'CREATE_ARCHIVE'}</span></button></div>);
# Read archives directory
opendir (DIR, "/$config{'trans_working_path'}/.translator/$remote_user/archives/");
@dir = readdir (DIR);
closedir (DIR);
if (scalar (@dir) - 2)
{
print qq(<p><table class="trans header">);
print qq(<tr><td>$text{'FILENAME'}</td><td>$text{'ACTION'}</td></tr>);
foreach my $name (sort @dir)
{
next if ($name =~ /^\./);
print qq(<tr><td>$name</td><td><button type="button" class="btn btn-tiny" onclick="location.href='admin_main.cgi?download_$name=1'"><i class="fa fa-fw fa-download"></i> <span>$text{'DOWNLOAD'}</span></button> <input type="checkbox" name="delete_$name" value="on" onchange="updateActionsChecked(this.form,document.getElementById('delete-archive'), 'delete_')"></td></tr>);
}
print qq(</table></p>);
print qq(<div><button type="submit" onclick="document.querySelector('[name=tab]').value='archives'" id="delete-archive" name="action_delete_trans" class="disabled btn btn-danger ui_form_end_submit"><i class="fa fa-fw fa-trash"></i> <span>$text{'DELETE_SELECTED_FILES'}</span></button></div>);
}
}
# Tab 2 "Create / delete"
sub _create_delete ()
{
print qq(<h2>$text{'CREATE_DELETE_TITLE'}</h2>);
print qq(<p>$text{'ADMIN_DESCRIPTION2'}</p>);
# Create new translation panel
print qq(<p/><div><button type="submit" onclick="document.querySelector('[name=tab]').value='create_delete'" name="new_translation" class="btn btn-success ui_form_end_submit"><i class="fa fa-fw fa-bolt"></i> <span>$text{'CREATE'}</span></button> $text{'NEW_TRANSLATION'} <input type="text" name="new_trans_code" size="5" value=""/></div>);
if (my @trans = &trans_get_existing_translations ([$app]))
{
my $select = qq(<select name="lang">);
foreach my $m (sort @trans)
{
$select .= qq(<option value="$m">$m</option>\n);
}
$select .= qq(</select>);
my $target_select = qq(
<select name="target">
<option value="all">$text{'ALL'}</option>
<option value="all_webmin">$text{'ALL_WEBMIN_TRANSLATION'}</option>
<option value="lang">$text{'ONLY_LANG'}</option>
<option value="module_info">$text{'ONLY_MODULE_INFO'}</option>
<option value="config_info">$text{'ONLY_CONFIG_INFO'}</option>
<option value="all_usermin">$text{'ALL_USERMIN_TRANSLATION'}</option>
<option value="ulang">$text{'ONLY_ULANG'}</option>
<option value="umodule_info">$text{'ONLY_UMODULE_INFO'}</option>
<option value="uconfig_info">$text{'ONLY_UCONFIG_INFO'}</option>
</select>
);
# Create remove translation panel
printf (qq(<p/><div><button type="submit" onclick="document.querySelector('[name=tab]').value='create_delete'" name="remove" class="btn btn-danger ui_form_end_submit"><i class="fa fa-fw fa-trash"></i> <span>$text{'DELETE'}</span></button> %s $text{'DELETE_TRANSLATION1'}</div>), $target_select, $select);
}
}
# Tab 3 "Unused items"
sub _search ()
{
print qq(<h2>$text{'SEARCH_UNUSED_ITEMS_TITLE'}</h2>);
print qq(<p>$text{'ADMIN_DESCRIPTION_SEARCH'}</p>);
# Search for unused items panel
print qq(<button class="btn btn-success ui_form_end_submit" type="submit" onclick="document.querySelector('[name=tab]').value='search'" name="search_unused"><i class="fa fa-fw fa-search"></i> <span>$text{'SEARCH'}</span></button> $text{'IN'} <select name="search_type"><option value="interface"$interface_selected>$text{'WEB_INTERFACE'}</option><option value="config"$config_selected>$text{'MODULE_CONFIGURATION'}</option></select>);
# if "search for unused items" button clicked
if (defined($in{'search_unused'}))
{
my %tmp = &trans_get_unused ($search_type, $ref_lang, $app);
my $unused = scalar (keys (%tmp));
$_success = sprintf ($text{'FOUND_UNUSED_ITEMS'}, $unused);
if ($unused > 0)
{
$_success .= qq( <a href="admin_view_unused.cgi?search_type=$search_type&referer=admin_main&app=$app&tab=$default_tab"><img src="images/view.png" alt="$text{'VIEW'}" title="$text{'VIEW_UNUSED'}"></a>);
}
}
}
print qq(</form>);
print qq(</p>);
&trans_footer ('', $text{'MODULE_INDEX'}, $_success, $_error, $_info);