• Main Page
  • Related Pages
  • Modules
  • 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                 $lng->loadLanguageModule("meta");
00123 
00124                 // set path to directory where lang-files reside
00125                 $d = dir($this->lang_path);
00126                 $tmpPath = getcwd();
00127                 chdir ($this->lang_path);
00128 
00129                 // get available lang-files
00130                 while ($entry = $d->read())
00131                 {
00132                         if (is_file($entry) && (ereg ("(^ilias_.{2}\.lang$)", $entry)))
00133                         {
00134                                 $lang_key = substr($entry,6,2);
00135                                 $languages[$lang_key] = ""; // long names will be set in class Out
00136                         }
00137                 }
00138 
00139                 // ensure that arrays are initiated when no lang file was found
00140                 if (!array($languages))
00141                 {
00142                         $language = array();
00143                         $tmp_array = array();
00144                 }
00145 
00146                 $tmp_array = array_keys($languages);
00147                 $lang_keys = array();
00148 
00149                 // now get languages from database
00150                 if ($lang_db = getObjectList("lng"))
00151                 {
00152                         foreach ($lang_db as $lang)
00153                         {
00154                                 // set values
00155                                 $lang_key = $lang["title"];
00156                                 $languages[$lang_key] = $lang;
00157                                 $lang_keys[] = $lang_key;
00158 
00159                                 // determine default language and language of current user
00160                                 if ($lang_key == $this->lang_user)
00161                                 {
00162                                         $languages[$lang_key]["status"] = "in_use";
00163                                 }
00164 
00165                                 if ($lang_key == $this->lang_default)
00166                                 {
00167                                         $languages[$lang_key]["status"] = "system_language";
00168                                 }
00169 
00170                                 // check if files are missing
00171                                 if ((count($tmp_array) > 0) && (!in_array($lang_key,$tmp_array)))
00172                                 {
00173                                         $languages[$lang_key]["info"] = "file_not_found";
00174                                 }
00175                         }
00176                 }
00177 
00178                 // compute new languages
00179                 foreach ($languages as $lang_key => $lang_data)
00180                 {
00181                         if (!in_array($lang_key,$lang_keys))
00182                         {
00183                                 $languages[$lang_key]["info"] = "new_language";
00184                                 //$languages[$lang_key]["desc"] = "not_installed";
00185                         }
00186                 }
00187 
00188                 chdir($tmpPath);
00189                 
00190                 // Insert languages with files new found into table language
00191                 $languages = $this->addNewLanguages($languages);
00192 
00193                 // Remove from array & db languages which are not installed and no lang-files
00194                 $languages = $this->removeLanguages($languages);
00195 
00196                 // setting language's full names
00197                 foreach ($languages as $lang_key => $lang_data)
00198                 {
00199                         $languages[$lang_key]["name"] = $lng->txt("meta_l_".$lang_key);
00200                 }
00201 
00202                 $this->languages = $languages;
00203 
00204                 return $this->languages;
00205         }
00206 
00217         function addNewLanguages($a_languages)
00218         {
00219                 if (count($a_languages) > 0)
00220                 {
00221                         foreach ($a_languages as $lang_key => $lang_data)
00222                         {
00223                                 if ($lang_data["info"] == "new_language")
00224                                 {
00225                                         include_once("./classes/class.ilObjLanguage.php");
00226                                         $lngObj =& new ilObjLanguage();
00227                                         $lngObj->setTitle($lang_key);
00228                                         $lngObj->setDescription("not_installed");
00229                                         $lngObj->create();
00230 
00231                                         // must get OOP through the whole class some time
00232                                         // (no arrays with db fields! this class doesn't know anything about table object!)
00233                                         $a_languages[$lang_key] = array("obj_id" => $lngObj->getId(),
00234                                                                                                         "type" => $lngObj->getType(),
00235                                                                                                         "description" => $lngObj->getDescription(),
00236                                                                                                         "desc" => $lngObj->getDescription(),
00237                                                                                                         "owner" => $lngObj->getOwner(),
00238                                                                                                         "create_date" => $lngObj->getCreateDate(),
00239                                                                                                         "last_update" => $lngObj->getLastUpdateDate());
00240 
00241                                         $a_languages[$lang_key]["info"] = "new_language";
00242                                         unset($lngObj);                 // better: the objects should be resident in an member array of this class
00243                                 }
00244                         }
00245                 }
00246 
00247                 return $a_languages;
00248         }
00249 
00260         function removeLanguages($a_languages)
00261         {
00262                 foreach ($a_languages as $lang_key => $lang_data)
00263                 {
00264                         if ($lang_data["desc"] == "not_installed" && $lang_data["info"] == "file_not_found")
00265                         {
00266                                 // update languages array
00267                                 unset($a_languages[$lang_key]);
00268 
00269                                 // update object_data table
00270                                 $query = "DELETE FROM object_data ".
00271                                                  "WHERE type = 'lng' ".
00272                                                  "AND title = '".$lang_key."'";
00273                                 $this->ilias->db->query($query);
00274                         }
00275                 }
00276 
00277                 return $a_languages;
00278         }
00279 
00288         function checkAllLanguages()
00289         {
00290                 // TODO: lng object should not be used in this class
00291                 global $lng;
00292 
00293                 // set path to directory where lang-files reside
00294                 $d = dir($this->lang_path);
00295                 $tmpPath = getcwd();
00296                 chdir ($this->lang_path);
00297 
00298                 // for giving a message when no lang-file was found
00299                 $found = false;
00300 
00301                 // get available lang-files
00302                 while ($entry = $d->read())
00303                 {
00304                         if (is_file($entry) && (ereg ("(^ilias_.{2}\.lang$)", $entry)))
00305                         {
00306                                 // textmeldung, wenn langfile gefunden wurde
00307                                 $output .= "<br/><br/>".$lng->txt("langfile_found").": ".$entry;
00308                                 $content = file ($entry);
00309 
00310                                 $found = true;
00311                                 $error = false;
00312 
00313                                 if ($content = ilObjLanguage::cut_header($content))
00314                                 {
00315                                         foreach ($content as $key => $val)
00316                                         {
00317                                                 $separated = explode ($this->separator,trim($val));
00318                                                 $num = count($separated);
00319 
00320                                                 if ($num != 3)
00321                                                 {
00322                                                         $error = true;
00323                                                         $line = $key + 37;
00324 
00325                                 $output .= "<br/><b/>".$lng->txt("err_in_line")." ".$line." !</b>&nbsp;&nbsp;";
00326                                 $output .= $lng->txt("module").": ".$separated[0];
00327                                 $output .= ", ".$lng->txt("identifier").": ".$separated[1];
00328                                 $output .= ", ".$lng->txt("value").": ".$separated[2];
00329 
00330                                                         switch ($num)
00331                                                         {
00332                                                                 case 1:
00333                                                                         if (empty($separated[0]))
00334                                                                         {
00335                                                                                 $output .= "<br/>".$lng->txt("err_no_param")." ".$lng->txt("check_langfile");
00336                                                                         }
00337                                                                         else
00338                                                                         {
00339                                                                                 $output .= "<br/>".$lng->txt("err_1_param")." ".$lng->txt("check_langfile");
00340                                                                         }
00341                                                                 break;
00342 
00343                                                                 case 2:
00344                                                                         $output .= "<br/>".$lng->txt("err_2_param")." ".$lng->txt("check_langfile");
00345                                                                 break;
00346 
00347                                                                 default:
00348                                                                         $output .= "<br/>".$lng->txt("err_over_3_param")." ".$lng->txt("check_langfile");
00349                                                                 break;
00350                                                         }
00351                                                 }
00352                                         }
00353 
00354                                         if ($error) {
00355                                                 $output .= "<br/>".$lng->txt("file_not_valid")." ".$lng->txt("err_count_param");
00356                                         }
00357                                         else {
00358                                                 $output .= "<br/>".$lng->txt("file_valid");
00359                                         }
00360                                 }
00361                                 else {
00362                                         $output .= "<br/>".$lng->txt("file_not_valid")." ".$lng->txt("err_wrong_header");
00363                                 }
00364                         }
00365                 }
00366 
00367                 $d->close();
00368 
00369                 if (!$found) {
00370                         $output .= "<br/>".$lng->txt("err_no_langfile_found");
00371                 }
00372 
00373                 chdir($tmpPath);
00374                 return $output;
00375         }
00376 } // END class.LanguageFolderObject
00377 ?>

Generated on Fri Dec 13 2013 13:52:07 for ILIAS Release_3_7_x_branch .rev 46817 by  doxygen 1.7.1