ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjLanguageFolder.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU 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, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 
36 require_once "./classes/class.ilObject.php";
37 
39 {
47 
57 
67 
74 
82 
89  function ilObjLanguageFolder($a_id,$a_call_by_reference = true)
90  {
91  $this->type = "lngf";
92  $this->ilObject($a_id,$a_call_by_reference);
93 
94  // init language support
95  global $lng;
96 
97  $this->lang_path = $lng->lang_path;
98  $this->lang_default = $lng->lang_default;
99  $this->lang_user = $lng->lang_user;
100  $this->separator = $lng->separator;
101  }
102 
117  function getLanguages ()
118  {
119  global $lng;
120 
121  $lng->loadLanguageModule("meta");
122 
123  // set path to directory where lang-files reside
124  $d = dir($this->lang_path);
125  $tmpPath = getcwd();
126  chdir ($this->lang_path);
127 
128  // get available lang-files
129  while ($entry = $d->read())
130  {
131  if (is_file($entry) && (ereg ("(^ilias_.{2}\.lang$)", $entry)))
132  {
133  $lang_key = substr($entry,6,2);
134  $languages[$lang_key] = ""; // long names will be set in class Out
135  }
136  }
137 
138  // ensure that arrays are initiated when no lang file was found
139  if (!array($languages))
140  {
141  $language = array();
142  $tmp_array = array();
143  }
144 
145  $tmp_array = array_keys($languages);
146  $lang_keys = array();
147 
148  // now get languages from database
149  if ($lang_db = ilObject::_getObjectsByType("lng"))
150  {
151  foreach ($lang_db as $lang)
152  {
153  // set values
154  $lang_key = $lang["title"];
155  $languages[$lang_key] = $lang;
156  $lang_keys[] = $lang_key;
157 
158  // determine default language and language of current user
159  if ($lang_key == $this->lang_user)
160  {
161  $languages[$lang_key]["status"] = "in_use";
162  }
163 
164  if ($lang_key == $this->lang_default)
165  {
166  $languages[$lang_key]["status"] = "system_language";
167  }
168 
169  // check if files are missing
170  if ((count($tmp_array) > 0) && (!in_array($lang_key,$tmp_array)))
171  {
172  $languages[$lang_key]["info"] = "file_not_found";
173  }
174  }
175  }
176 
177  // compute new languages
178  foreach ($languages as $lang_key => $lang_data)
179  {
180  if (!in_array($lang_key,$lang_keys))
181  {
182  $languages[$lang_key]["info"] = "new_language";
183  //$languages[$lang_key]["desc"] = "not_installed";
184  }
185  }
186 
187  chdir($tmpPath);
188 
189  // Insert languages with files new found into table language
191 
192  // Remove from array & db languages which are not installed and no lang-files
194 
195  // setting language's full names
196  foreach ($languages as $lang_key => $lang_data)
197  {
198  $languages[$lang_key]["name"] = $lng->txt("meta_l_".$lang_key);
199  }
200 
201  $this->languages = $languages;
202 
203  return $this->languages;
204  }
205 
216  function addNewLanguages($a_languages)
217  {
218  if (count($a_languages) > 0)
219  {
220  foreach ($a_languages as $lang_key => $lang_data)
221  {
222  if ($lang_data["info"] == "new_language")
223  {
224  include_once("./Services/Language/classes/class.ilObjLanguage.php");
225  $lngObj =& new ilObjLanguage();
226  $lngObj->setTitle($lang_key);
227  $lngObj->setDescription("not_installed");
228  $lngObj->create();
229 
230  // must get OOP through the whole class some time
231  // (no arrays with db fields! this class doesn't know anything about table object!)
232  $a_languages[$lang_key] = array("obj_id" => $lngObj->getId(),
233  "type" => $lngObj->getType(),
234  "description" => $lngObj->getDescription(),
235  "desc" => $lngObj->getDescription(),
236  "owner" => $lngObj->getOwner(),
237  "create_date" => $lngObj->getCreateDate(),
238  "last_update" => $lngObj->getLastUpdateDate());
239 
240  $a_languages[$lang_key]["info"] = "new_language";
241  unset($lngObj); // better: the objects should be resident in an member array of this class
242  }
243  }
244  }
245 
246  return $a_languages;
247  }
248 
259  function removeLanguages($a_languages)
260  {
261  global $ilDB;
262 
263  foreach ($a_languages as $lang_key => $lang_data)
264  {
265  if ($lang_data["desc"] == "not_installed" && $lang_data["info"] == "file_not_found")
266  {
267  // update languages array
268  unset($a_languages[$lang_key]);
269 
270  // update object_data table
271  $query = "DELETE FROM object_data ".
272  "WHERE type = 'lng' ".
273  "AND title = ".$ilDB->quote($lang_key);
274  $this->ilias->db->query($query);
275  }
276  }
277 
278  return $a_languages;
279  }
280 
289  function checkAllLanguages()
290  {
291  // TODO: lng object should not be used in this class
292  global $lng;
293 
294  // set path to directory where lang-files reside
295  $d = dir($this->lang_path);
296  $tmpPath = getcwd();
297  chdir ($this->lang_path);
298 
299  // for giving a message when no lang-file was found
300  $found = false;
301 
302  // get available lang-files
303  while ($entry = $d->read())
304  {
305  if (is_file($entry) && (ereg ("(^ilias_.{2}\.lang$)", $entry)))
306  {
307  // textmeldung, wenn langfile gefunden wurde
308  $output .= "<br/><br/>".$lng->txt("langfile_found").": ".$entry;
309  $content = file ($entry);
310 
311  $found = true;
312  $error = false;
313 
314  if ($content = ilObjLanguage::cut_header($content))
315  {
316  foreach ($content as $key => $val)
317  {
318  $separated = explode ($this->separator,trim($val));
319  $num = count($separated);
320 
321  if ($num != 3)
322  {
323  $error = true;
324  $line = $key + 37;
325 
326  $output .= "<br/><b/>".$lng->txt("err_in_line")." ".$line." !</b>&nbsp;&nbsp;";
327  $output .= $lng->txt("module").": ".$separated[0];
328  $output .= ", ".$lng->txt("identifier").": ".$separated[1];
329  $output .= ", ".$lng->txt("value").": ".$separated[2];
330 
331  switch ($num)
332  {
333  case 1:
334  if (empty($separated[0]))
335  {
336  $output .= "<br/>".$lng->txt("err_no_param")." ".$lng->txt("check_langfile");
337  }
338  else
339  {
340  $output .= "<br/>".$lng->txt("err_1_param")." ".$lng->txt("check_langfile");
341  }
342  break;
343 
344  case 2:
345  $output .= "<br/>".$lng->txt("err_2_param")." ".$lng->txt("check_langfile");
346  break;
347 
348  default:
349  $output .= "<br/>".$lng->txt("err_over_3_param")." ".$lng->txt("check_langfile");
350  break;
351  }
352  }
353  }
354 
355  if ($error) {
356  $output .= "<br/>".$lng->txt("file_not_valid")." ".$lng->txt("err_count_param");
357  }
358  else {
359  $output .= "<br/>".$lng->txt("file_valid");
360  }
361  }
362  else {
363  $output .= "<br/>".$lng->txt("file_not_valid")." ".$lng->txt("err_wrong_header");
364  }
365  }
366  }
367 
368  $d->close();
369 
370  if (!$found) {
371  $output .= "<br/>".$lng->txt("err_no_langfile_found");
372  }
373 
374  chdir($tmpPath);
375  return $output;
376  }
377 } // END class.LanguageFolderObject
378 ?>