SVN tag for release should only contain scripts in "docs" folder without "mods",...
[atutor.git] / docs / mods / _core / languages / language_import.php
1 <?php
2 /****************************************************************/
3 /* ATutor                                                                                                               */
4 /****************************************************************/
5 /* Copyright (c) 2002-2010                                      */
6 /* Inclusive Design Institute                                   */
7 /* http://atutor.ca                                                                                             */
8 /*                                                              */
9 /* This program is free software. You can redistribute it and/or*/
10 /* modify it under the terms of the GNU General Public License  */
11 /* as published by the Free Software Foundation.                                */
12 /****************************************************************/
13 // $Id$
14
15 define('AT_INCLUDE_PATH', '../../../include/');
16 require(AT_INCLUDE_PATH.'vitals.inc.php');
17 admin_authenticate(AT_ADMIN_PRIV_LANGUAGES);
18
19 require_once(AT_INCLUDE_PATH.'classes/pclzip.lib.php');
20 require_once(AT_INCLUDE_PATH.'../mods/_core/languages/classes/LanguageEditor.class.php');
21 require_once(AT_INCLUDE_PATH.'../mods/_core/languages/classes/LanguagesParser.class.php');
22
23 /* to avoid timing out on large files */
24 @set_time_limit(0);
25
26 $_SESSION['done'] = 1;
27
28 if (isset($_POST['submit_import'])){
29         require_once(AT_INCLUDE_PATH.'../mods/_core/languages/classes/RemoteLanguageManager.class.php');
30         $remoteLanguageManager = new RemoteLanguageManager();
31         $remoteLanguageManager->import($_POST['language']);
32         header('Location: language_import.php');
33         exit;
34 } else if (isset($_POST['submit']) && (!is_uploaded_file($_FILES['file']['tmp_name']) || !$_FILES['file']['size'])) {
35         $msg->addError('LANG_IMPORT_FAILED');
36 } else if (isset($_POST['submit']) && !$_FILES['file']['name']) {
37         $msg->addError('IMPORTFILE_EMPTY');
38 } else if (isset($_POST['submit']) && is_uploaded_file($_FILES['file']['tmp_name'])) {
39         $languageManager->import($_FILES['file']['tmp_name']);
40         header('Location: ./language_import.php');
41         exit;
42 }
43
44 ?>
45 <?php require(AT_INCLUDE_PATH.'header.inc.php'); ?>
46
47 <form name="form1" method="post" action="mods/_core/languages/language_import.php" enctype="multipart/form-data" onsubmit="openWindow('<?php echo AT_BASE_HREF; ?>tools/prog.php');">
48 <div class="input-form">
49         <div class="row">
50                 <p><?php echo _AT('import_lang_howto'); ?></p>
51         </div>
52         
53         <div class="row">
54                 <label for="file"><?php echo _AT('import_a_new_lang'); ?></label><br />
55                 <input type="file" name="file" id="file" />
56         </div>
57         
58         <div class="row buttons">
59                 <input type="submit" name="submit" value="<?php echo _AT('import'); ?>" />
60         </div>
61 </div>
62 </form>
63
64
65 <form name="form1" method="post" action="mods/_core/languages/language_import.php">
66 <div class="input-form">
67         <div class="row">
68                 <?php echo _AT('import_remote_language'); ?>
69         </div>
70
71         <div class="row">
72                 <?php
73                         require_once(AT_INCLUDE_PATH.'../mods/_core/languages/classes/RemoteLanguageManager.class.php');
74                         $remoteLanguageManager = new RemoteLanguageManager();
75                         if ($remoteLanguageManager->getNumLanguages()) {
76                                 $found = false;
77                                 foreach ($remoteLanguageManager->getAvailableLanguages() as $codes){
78                                         $language = current($codes);
79                                         if (!$languageManager->exists($language->getCode()) && ($language->getStatus() == AT_LANG_STATUS_PUBLISHED)) {
80                                                 if (!$found) {
81                                                         echo '<select name="language">';
82                                                         $found = true;
83                                                 }
84                                                 echo '<option value="'.$language->getCode().'">'.$language->getEnglishName().' - '.$language->getNativeName().'</option>';
85                                         }
86                                 }
87                                 if ($found) {
88                                         echo '</select></div>';
89                                         echo '<div class="row buttons"><input type="submit" name="submit_import" value="' . _AT('import') . '" class="button" /></div>';
90                                 } else {
91                                         echo _AT('none_found');
92                                         echo '</div>';
93                                 }
94                         } else {
95                                 echo _AT('cannot_find_remote_languages');
96                                 echo '</div>';
97                         }
98                 ?>
99 </div>
100 </form>
101
102
103 <?php require(AT_INCLUDE_PATH.'footer.inc.php'); ?>