• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

classes/class.ilObjLanguageFolder.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003         +-----------------------------------------------------------------------------+
00004         | ILIAS open source                                                           |
00005         +-----------------------------------------------------------------------------+
00006         | Copyright (c) 1998-2001 ILIAS open source, University of Cologne            |
00007         |                                                                             |
00008         | This program is free software; you can redistribute it and/or               |
00009         | modify it under the terms of the GNU General Public License                 |
00010         | as published by the Free Software Foundation; either version 2              |
00011         | of the License, or (at your option) any later version.                      |
00012         |                                                                             |
00013         | This program is distributed in the hope that it will be useful,             |
00014         | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
00015         | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
00016         | GNU General Public License for more details.                                |
00017         |                                                                             |
00018         | You should have received a copy of the GNU General Public License           |
00019         | along with this program; if not, write to the Free Software                 |
00020         | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. |
00021         +-----------------------------------------------------------------------------+
00022 */
00023 
00024 
00037 require_once "class.ilObject.php";
00038 
00039 class ilObjLanguageFolder extends ilObject
00040 {
00047         var $lang_default;
00048 
00057         var $lang_user;
00058 
00067         var $lang_path;
00068 
00074         var $separator;
00075 
00082         var $languages;
00083 
00090         function ilObjLanguageFolder($a_id,$a_call_by_reference = true)
00091         {
00092                 $this->type = "lngf";
00093                 $this->ilObject($a_id,$a_call_by_reference);
00094 
00095                 // init language support
00096                 global $lng;
00097 
00098                 $this->lang_path = $lng->lang_path;
00099                 $this->lang_default = $lng->lang_default;
00100                 $this->lang_user = $lng->lang_user;
00101                 $this->separator = $lng->separator;
00102         }
00103 
00118         function getLanguages ()
00119         {
00120                 global $lng;
00121 
00122                 // set path to directory where lang-files reside
00123                 $d = dir($this->lang_path);
00124                 $tmpPath = getcwd();
00125                 chdir ($this->lang_path);
00126 
00127                 // get available lang-files
00128                 while ($entry = $d->read())
00129                 {
00130                         if (is_file($entry) && (ereg ("(^ilias_.{2}\.lang$)", $entry)))
00131                         {
00132                                 $lang_key = substr($entry,6,2);
00133                                 $languages[$lang_key] = ""; // long names will be set in class Out
00134                         }
00135                 }
00136 
00137                 // ensure that arrays are initiated when no lang file was found
00138                 if (!array($languages))
00139                 {
00140                         $language = array();
00141                         $tmp_array = array();
00142                 }
00143 
00144                 $tmp_array = array_keys($languages);
00145                 $lang_keys = array();
00146 
00147                 // now get languages from database
00148                 if ($lang_db = getObjectList("lng"))
00149                 {
00150                         foreach ($lang_db as $lang)
00151                         {
00152                                 // set values
00153                                 $lang_key = $lang["title"];
00154                                 $languages[$lang_key] = $lang;
00155                                 $lang_keys[] = $lang_key;
00156 
00157                                 // determine default language and language of current user
00158                                 if ($lang_key == $this->lang_user)
00159                                 {
00160                                         $languages[$lang_key]["status"] = "in_use";
00161                                 }
00162 
00163                                 if ($lang_key == $this->lang_default)
00164                                 {
00165                                         $languages[$lang_key]["status"] = "system_language";
00166                                 }
00167 
00168                                 // check if files are missing
00169                                 if ((count($tmp_array) > 0) && (!in_array($lang_key,$tmp_array)))
00170                                 {
00171                                         $languages[$lang_key]["info"] = "file_not_found";
00172                                 }
00173                         }
00174                 }
00175 
00176                 // compute new languages
00177                 foreach ($languages as $lang_key => $lang_data)
00178                 {
00179                         if (!in_array($lang_key,$lang_keys))
00180                         {
00181                                 $languages[$lang_key]["info"] = "new_language";
00182                                 //$languages[$lang_key]["desc"] = "not_installed";
00183                         }
00184                 }
00185 
00186                 chdir($tmpPath);
00187                 // Insert languages with files new found into table language
00188                 $languages = $this->addNewLanguages($languages);
00189 
00190                 // Remove from array & db languages which are not installed and no lang-files
00191                 $languages = $this->removeLanguages($languages);
00192 
00193                 // setting language's full names
00194                 foreach ($languages as $lang_key => $lang_data)
00195                 {
00196                         $languages[$lang_key]["name"] = $lng->txt("lang_".$lang_key);
00197                 }
00198 
00199                 $this->languages = $languages;
00200 
00201                 return $this->languages;
00202         }
00203 
00214         function addNewLanguages($a_languages)
00215         {
00216                 if (count($a_languages) > 0)
00217                 {
00218                         foreach ($a_languages as $lang_key => $lang_data)
00219                         {
00220                                 if ($lang_data["info"] == "new_language")
00221                                 {
00222                                         include_once("./classes/class.ilObjLanguage.php");
00223                                         $lngObj =& new ilObjLanguage();
00224                                         $lngObj->setTitle($lang_key);
00225                                         $lngObj->setDescription("not_installed");
00226                                         $lngObj->create();
00227 
00228                                         // must get OOP through the whole class some time
00229                                         // (no arrays with db fields! this class doesn't know anything about table object!)
00230                                         $a_languages[$lang_key] = array("obj_id" => $lngObj->getId(),
00231                                                                                                         "type" => $lngObj->getType(),
00232                                                                                                         "description" => $lngObj->getDescription(),
00233                                                                                                         "desc" => $lngObj->getDescription(),
00234                                                                                                         "owner" => $lngObj->getOwner(),
00235                                                                                                         "create_date" => $lngObj->getCreateDate(),
00236                                                                                                         "last_update" => $lngObj->getLastUpdateDate());
00237 
00238                                         $a_languages[$lang_key]["info"] = "new_language";
00239                                         unset($lngObj);                 // better: the objects should be resident in an member array of this class
00240                                 }
00241                         }
00242                 }
00243 
00244                 return $a_languages;
00245         }
00246 
00257         function removeLanguages($a_languages)
00258         {
00259                 foreach ($a_languages as $lang_key => $lang_data)
00260                 {
00261                         if ($lang_data["desc"] == "not_installed" && $lang_data["info"] == "file_not_found")
00262                         {
00263                                 // update languages array
00264                                 unset($a_languages[$lang_key]);
00265 
00266                                 // update object_data table
00267                                 $query = "DELETE FROM object_data ".
00268                                                  "WHERE type = 'lng' ".
00269                                                  "AND title = '".$lang_key."'";
00270                                 $this->ilias->db->query($query);
00271                         }
00272                 }
00273 
00274                 return $a_languages;
00275         }
00276 
00285         function checkAllLanguages()
00286         {
00287                 // TODO: lng object should not be used in this class
00288                 global $lng;
00289 
00290                 // set path to directory where lang-files reside
00291                 $d = dir($this->lang_path);
00292                 $tmpPath = getcwd();
00293                 chdir ($this->lang_path);
00294 
00295                 // for giving a message when no lang-file was found
00296                 $found = false;
00297 
00298                 // get available lang-files
00299                 while ($entry = $d->read())
00300                 {
00301                         if (is_file($entry) && (ereg ("(^ilias_.{2}\.lang$)", $entry)))
00302                         {
00303                                 // textmeldung, wenn langfile gefunden wurde
00304                                 $output .= "<br/><br/>".$lng->txt("langfile_found").": ".$entry;
00305                                 $content = file ($entry);
00306 
00307                                 $found = true;
00308                                 $error = false;
00309 
00310                                 if ($content = ilObjLanguage::cut_header($content))
00311                                 {
00312                                         foreach ($content as $key => $val)
00313                                         {
00314                                                 $separated = explode ($this->separator,trim($val));
00315                                                 $num = count($separated);
00316 
00317                                                 if ($num != 3)
00318                                                 {
00319                                                         $error = true;
00320 
00321                         $output .= "<br/><b/>".$lng->txt("err_in_line")." ".$key." !</b>&nbsp;&nbsp;";
00322                         $output .= $lng->txt("module").": ".$separated[0];
00323                         $output .= ", ".$lng->txt("identifier").": ".$separated[1];
00324                         $output .= ", ".$lng->txt("value").": ".$separated[2];
00325 
00326                                                         switch ($num)
00327                                                         {
00328                                                                 case 1:
00329                                                                         if (empty($separated[0]))
00330                                                                         {
00331                                                                                 $output .= "<br/>".$lng->txt("err_no_param")." ".$lng->txt("check_langfile");
00332                                                                         }
00333                                                                         else
00334                                                                         {
00335                                                                                 $output .= "<br/>".$lng->txt("err_1_param")." ".$lng->txt("check_langfile");
00336                                                                         }
00337                                                                 break;
00338 
00339                                                                 case 2:
00340                                                                         $output .= "<br/>".$lng->txt("err_2_param")." ".$lng->txt("check_langfile");
00341                                                                 break;
00342 
00343                                                                 default:
00344                                                                         $output .= "<br/>".$lng->txt("err_over_3_param")." ".$lng->txt("check_langfile");
00345                                                                 break;
00346                                                         }
00347                                                 }
00348                                         }
00349 
00350                                         if ($error) {
00351                                                 $output .= "<br/>".$lng->txt("file_not_valid")." ".$lng->txt("err_count_param");
00352                                         }
00353                                         else {
00354                                                 $output .= "<br/>".$lng->txt("file_valid");
00355                                         }
00356                                 }
00357                                 else {
00358                                         $output .= "<br/>".$lng->txt("file_not_valid")." ".$lng->txt("err_wrong_header");
00359                                 }
00360                         }
00361                 }
00362 
00363                 $d->close();
00364 
00365                 if (!$found) {
00366                         $output .= "<br/>".$lng->txt("err_no_langfile_found");
00367                 }
00368 
00369                 chdir($tmpPath);
00370                 return $output;
00371         }
00372 } // END class.LanguageFolderObject
00373 ?>

Generated on Fri Dec 13 2013 09:06:34 for ILIAS Release_3_4_x_branch .rev 46804 by  doxygen 1.7.1