function saveNewEntryObject()
 {
     global $ilCtrl, $ilUser, $ilDB;
     $form = $this->initAddNewEntryForm();
     if ($form->checkInput()) {
         $mod = $form->getInput("mod");
         $id = $form->getInput("id");
         $lang = array();
         foreach ($this->lng->getInstalledLanguages() as $lang_key) {
             $trans = trim($form->getInput("trans_" . $lang_key));
             if ($trans) {
                 // add single entry
                 ilObjLanguage::replaceLangEntry($mod, $id, $lang_key, $trans, date("Y-m-d H:i:s"), $ilUser->getLogin());
                 // add to serialized module
                 $set = $ilDB->query("SELECT lang_array FROM lng_modules" . " WHERE lang_key = " . $ilDB->quote($lang_key, "text") . " AND module = " . $ilDB->quote($mod, "text"));
                 $row = $ilDB->fetchAssoc($set);
                 $entries = unserialize($row["lang_array"]);
                 if (is_array($entries)) {
                     $entries[$id] = $trans;
                     ilObjLanguage::replaceLangModule($lang_key, $mod, $entries);
                 }
             }
         }
         ilUtil::sendSuccess($this->lng->txt("settings_saved"), true);
         $ilCtrl->redirect($this, "view");
     }
     $form->setValuesByPost();
     $this->addNewEntryObject($form);
 }
Exemplo n.º 2
0
 /**
  * Update all languages
  */
 public final function updateLanguages()
 {
     global $ilCtrl;
     ilGlobalCache::flushAll();
     include_once "./Services/Language/classes/class.ilObjLanguage.php";
     $langs = $this->getAvailableLangFiles($this->getLanguageDirectory());
     $prefix = $this->getPrefix();
     foreach ($langs as $lang) {
         $txt = file($this->getLanguageDirectory() . "/" . $lang["file"]);
         $lang_array = array();
         // get language data
         if (is_array($txt)) {
             foreach ($txt as $row) {
                 if ($row[0] != "#" && strpos($row, "#:#") > 0) {
                     $a = explode("#:#", trim($row));
                     $lang_array[$prefix . "_" . trim($a[0])] = trim($a[1]);
                     ilObjLanguage::replaceLangEntry($prefix, $prefix . "_" . trim($a[0]), $lang["key"], trim($a[1]));
                     //echo "<br>-$prefix-".$prefix."_".trim($a[0])."-".$lang["key"]."-";
                 }
             }
         }
         ilObjLanguage::replaceLangModule($lang["key"], $prefix, $lang_array);
     }
 }
Exemplo n.º 3
0
 /**
  * insert language data from file into database
  * 
  * @param   string  $scope  empty (global) or "local"
  */
 function insert($scope = '')
 {
     global $ilDB;
     if (!empty($scope)) {
         if ($scope == 'global') {
             $scope = '';
         } else {
             $scopeExtension = '.' . $scope;
         }
     }
     $path = $this->lang_path;
     if ($scope == "local") {
         $path = $this->cust_lang_path;
     }
     $tmpPath = getcwd();
     chdir($path);
     $lang_file = "ilias_" . $this->key . ".lang" . $scopeExtension;
     if ($lang_file) {
         // initialize the array for updating lng_modules below
         $lang_array = array();
         $lang_array["common"] = array();
         // remove header first
         if ($content = $this->cut_header(file($lang_file))) {
             if (empty($scope)) {
                 // reset change date for a global file
                 // get all local changes for a global file
                 $change_date = null;
                 $local_changes = $this->getLocalChanges();
             } else {
                 if ($scope == 'local') {
                     // set the change date to import time for a local file
                     // get the modification date of the local file
                     // get the newer local changes for a local file
                     $change_date = date("Y-m-d H:i:s", time());
                     $min_date = date("Y-m-d H:i:s", filemtime($lang_file));
                     $local_changes = $this->getLocalChanges($min_date);
                 }
             }
             foreach ($content as $key => $val) {
                 // split the line of the language file
                 // [0]:	module
                 // [1]:	identifier
                 // [2]:	value
                 // [3]:	comment (optional)
                 $separated = explode($this->separator, trim($val));
                 $pos = strpos($separated[2], $this->comment_separator);
                 if ($pos !== false) {
                     $separated[3] = substr($separated[2], $pos + strlen($this->comment_separator));
                     $separated[2] = substr($separated[2], 0, $pos);
                 }
                 // check if the value has a local change
                 $local_value = $local_changes[$separated[0]][$separated[1]];
                 if (empty($scope)) {
                     // import of a global language file
                     if ($local_value != "" and $local_value != $separated[2]) {
                         // keep an existing and different local calue
                         $lang_array[$separated[0]][$separated[1]] = $local_value;
                     } else {
                         // check for double entries in global file
                         if ($double_checker[$separated[0]][$separated[1]][$this->key]) {
                             $this->ilias->raiseError("Duplicate Language Entry: " . $separated[0] . "-" . $separated[1] . "-" . $this->key, $this->ilias->error_obj->MESSAGE);
                         }
                         $double_checker[$separated[0]][$separated[1]][$this->key] = true;
                         // insert a new value if no local value exists
                         // reset local change date if the values are equal
                         ilObjLanguage::replaceLangEntry($separated[0], $separated[1], $this->key, $separated[2], $change_date, $separated[3]);
                         $lang_array[$separated[0]][$separated[1]] = $separated[2];
                     }
                 } else {
                     if ($scope == 'local') {
                         // import of a local language file
                         if ($local_value != "") {
                             // keep a locally changed value that is newer than the file
                             $lang_array[$separated[0]][$separated[1]] = $local_value;
                         } else {
                             // insert a new value if no global value exists
                             // (local files may have additional entries for customizations)
                             // set the change date to the import date
                             ilObjLanguage::replaceLangEntry($separated[0], $separated[1], $this->key, $separated[2], $change_date, $separated[3]);
                             $lang_array[$separated[0]][$separated[1]] = $separated[2];
                         }
                     }
                 }
             }
             $ld = "";
             if (empty($scope)) {
                 $ld = "installed";
             } else {
                 if ($scope == 'local') {
                     $ld = "installed_local";
                 }
             }
             if ($ld) {
                 $query = "UPDATE object_data SET " . "description = " . $ilDB->quote($ld, "text") . ", " . "last_update = " . $ilDB->now() . " " . "WHERE title = " . $ilDB->quote($this->key, "text") . " " . "AND type = 'lng'";
                 $ilDB->manipulate($query);
             }
         }
         foreach ($lang_array as $module => $lang_arr) {
             if ($scope == "local") {
                 $q = "SELECT * FROM lng_modules WHERE " . " lang_key = " . $ilDB->quote($this->key, "text") . " AND module = " . $ilDB->quote($module, "text");
                 $set = $ilDB->query($q);
                 $row = $ilDB->fetchAssoc($set);
                 $arr2 = unserialize($row["lang_array"]);
                 if (is_array($arr2)) {
                     $lang_arr = array_merge($arr2, $lang_arr);
                 }
             }
             ilObjLanguage::replaceLangModule($this->key, $module, $lang_arr);
         }
     }
     chdir($tmpPath);
 }
 /**
  * Delete a set of translation in the database
  *
  * @access   static
  * @param    string      language key
  * @param    array       module.separator.topic => value
  */
 public static function _deleteValues($a_lang_key, $a_values = array())
 {
     global $ilDB, $lng;
     if (!is_array($a_values)) {
         return;
     }
     $delete_array = array();
     // save the single translations in lng_data
     foreach ($a_values as $key => $value) {
         $keys = explode($lng->separator, $key);
         if (count($keys) == 2) {
             $module = $keys[0];
             $topic = $keys[1];
             $delete_array[$module][$topic] = $value;
             ilObjLanguage::deleteLangEntry($module, $topic, $a_lang_key);
         }
     }
     // save the serialized module entries in lng_modules
     foreach ($delete_array as $module => $entries) {
         $set = $ilDB->query(sprintf("SELECT * FROM lng_modules " . "WHERE lang_key = %s AND module = %s", $ilDB->quote($a_lang_key, "text"), $ilDB->quote($module, "text")));
         $row = $ilDB->fetchAssoc($set);
         $arr = unserialize($row["lang_array"]);
         if (is_array($arr)) {
             $entries = array_diff_key($arr, $entries);
         }
         ilObjLanguage::replaceLangModule($a_lang_key, $module, $entries);
     }
 }