source: trunk/admin/languages_installed.php @ 25279

Last change on this file since 25279 was 25018, checked in by mistic100, 11 years ago

remove all array_push (50% slower than []) + some changes missing for feature:2978

File size: 4.1 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based photo gallery                                    |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008-2009 Piwigo Team                  http://piwigo.org |
6// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
7// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
8// +-----------------------------------------------------------------------+
9// | This program is free software; you can redistribute it and/or modify  |
10// | it under the terms of the GNU General Public License as published by  |
11// | the Free Software Foundation                                          |
12// |                                                                       |
13// | This program is distributed in the hope that it will be useful, but   |
14// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
15// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
16// | General Public License for more details.                              |
17// |                                                                       |
18// | You should have received a copy of the GNU General Public License     |
19// | along with this program; if not, write to the Free Software           |
20// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
21// | USA.                                                                  |
22// +-----------------------------------------------------------------------+
23
24if( !defined("PHPWG_ROOT_PATH") )
25{
26  die ("Hacking attempt!");
27}
28
29include_once(PHPWG_ROOT_PATH.'admin/include/languages.class.php');
30
31$template->set_filenames(array('languages' => 'languages_installed.tpl'));
32
33$base_url = get_root_url().'admin.php?page='.$page['page'];
34
35$languages = new languages();
36$languages->get_db_languages();
37
38//--------------------------------------------------perform requested actions
39if (isset($_GET['action']) and isset($_GET['language']))
40{
41  $page['errors'] = $languages->perform_action($_GET['action'], $_GET['language']);
42
43  if (empty($page['errors']))
44  {
45    redirect($base_url);
46  }
47}
48
49// +-----------------------------------------------------------------------+
50// |                     start template output                             |
51// +-----------------------------------------------------------------------+
52$default_language = get_default_language();
53
54$tpl_languages = array();
55
56foreach($languages->fs_languages as $language_id => $language)
57{
58  $language['u_action'] = add_url_params($base_url, array('language' => $language_id));
59
60  if (in_array($language_id, array_keys($languages->db_languages)))
61  {
62    $language['state'] = 'active';
63    $language['deactivable'] = true;
64
65    if (count($languages->db_languages) <= 1)
66    {
67      $language['deactivable'] = false;
68      $language['deactivate_tooltip'] = l10n('Impossible to deactivate this language, you need at least one language.');
69    }
70
71    if ($language_id == $default_language)
72    {
73      $language['deactivable'] = false;
74      $language['deactivate_tooltip'] = l10n('Impossible to deactivate this language, first set another language as default.');
75    }
76  }
77  else
78  {
79    $language['state'] = 'inactive';
80  }
81
82  if ($language_id == $default_language)
83  {
84    $language['is_default'] = true;
85    array_unshift($tpl_languages, $language);
86  }
87  else
88  {
89    $language['is_default'] = false;
90    $tpl_languages[] = $language;
91  }
92}
93
94$template->assign(
95  array(
96    'languages' => $tpl_languages,
97    )
98  );
99$template->append('language_states', 'active');
100$template->append('language_states', 'inactive');
101
102
103$missing_language_ids = array_diff(
104    array_keys($languages->db_languages),
105    array_keys($languages->fs_languages)
106  );
107
108foreach($missing_language_ids as $language_id)
109{
110  $query = '
111UPDATE '.USER_INFOS_TABLE.'
112  SET language = \''.get_default_language().'\'
113  WHERE language = \''.$language_id.'\'
114;';
115  pwg_query($query);
116
117  $query = '
118DELETE
119  FROM '.LANGUAGES_TABLE.'
120  WHERE id= \''.$language_id.'\'
121;';
122  pwg_query($query);
123}
124
125$template->assign_var_from_handle('ADMIN_CONTENT', 'languages');
126?>
Note: See TracBrowser for help on using the repository browser.