tagging as ATutor 1.5.4-release
[atutor.git] / admin / language_import.php
1 <?php
2 /****************************************************************/
3 /* ATutor                                                                                                               */
4 /****************************************************************/
5 /* Copyright (c) 2002-2007 by Greg Gay & Joel Kronenberg        */
6 /* Adaptive Technology Resource Centre / University of Toronto  */
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(AT_INCLUDE_PATH.'classes/pclzip.lib.php');
20 require_once(AT_INCLUDE_PATH.'classes/Language/LanguageEditor.class.php');
21 require_once(AT_INCLUDE_PATH.'classes/Language/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.'classes/Language/RemoteLanguageManager.class.php');
30         $remoteLanguageManager =& new RemoteLanguageManager();
31         $remoteLanguageManager->import($_POST['language']);
32
33         header('Location: language_import.php');
34         exit;
35 } else if (isset($_POST['submit']) && (!is_uploaded_file($_FILES['file']['tmp_name']) || !$_FILES['file']['size'])) {
36         $msg->addError('LANG_IMPORT_FAILED');
37 } else if (isset($_POST['submit']) && !$_FILES['file']['name']) {
38         $msg->addError('IMPORTFILE_EMPTY');
39 } else if (isset($_POST['submit']) && is_uploaded_file($_FILES['file']['tmp_name'])) {
40         $languageManager->import($_FILES['file']['tmp_name']);
41
42         header('Location: language_import.php');
43         exit;
44 }
45
46 ?>
47 <?php require(AT_INCLUDE_PATH.'header.inc.php'); ?>
48
49 <form name="form1" method="post" action="admin/language_import.php" enctype="multipart/form-data" onsubmit="openWindow('<?php echo AT_BASE_HREF; ?>tools/prog.php');">
50 <div class="input-form">
51         <div class="row">
52                 <p><?php echo _AT('import_lang_howto'); ?></p>
53         </div>
54         
55         <div class="row">
56                 <label for="file"><?php echo _AT('import_a_new_lang'); ?></label><br />
57                 <input type="file" name="file" id="file" />
58         </div>
59         
60         <div class="row buttons">
61                 <input type="submit" name="submit" value="<?php echo _AT('import'); ?>" />
62         </div>
63 </div>
64 </form>
65
66
67 <form name="form1" method="post" action="admin/language_import.php">
68 <div class="input-form">
69         <div class="row">
70                 <?php echo _AT('import_remote_language'); ?>
71         </div>
72
73         <div class="row">
74                 <?php
75                         require_once(AT_INCLUDE_PATH.'classes/Language/RemoteLanguageManager.class.php');
76                         $remoteLanguageManager =& new RemoteLanguageManager();
77                         if ($remoteLanguageManager->getNumLanguages()) {
78                                 $found = false;
79                                 foreach ($remoteLanguageManager->getAvailableLanguages() as $codes){
80                                         $language = current($codes);
81                                         if (!$languageManager->exists($language->getCode()) && ($language->getStatus() == AT_LANG_STATUS_PUBLISHED)) {
82                                                 if (!$found) {
83                                                         echo '<select name="language">';
84                                                         $found = true;
85                                                 }
86                                                 echo '<option value="'.$language->getCode().'">'.$language->getEnglishName().' - '.$language->getNativeName().'</option>';
87                                         }
88                                 }
89                                 if ($found) {
90                                         echo '</select></div>';
91                                         echo '<div class="row buttons"><input type="submit" name="submit_import" value="' . _AT('import') . '" class="button" /></div>';
92                                 } else {
93                                         echo _AT('none_found');
94                                         echo '</div>';
95                                 }
96                         } else {
97                                 echo _AT('cannot_find_remote_languages');
98                                 echo '</div>';
99                         }
100                 ?>
101 </div>
102 </form>
103
104
105 <?php require(AT_INCLUDE_PATH.'footer.inc.php'); ?>