/**
  * insert language data from file in database
  *
  * @param    string  $lang_key   international language key (2 digits)
  * @param    string  $scope      empty (global) or "local"
  * @return   void
  */
 function insertLanguage($lang_key, $scope = '')
 {
     $ilDB =& $this->db;
     $lang_array = array();
     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_" . $lang_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))) {
             // get the local changes from the database
             if (empty($scope)) {
                 $local_changes = $this->getLocalChanges($lang_key);
             } else {
                 if ($scope == 'local') {
                     $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($lang_key, $min_date);
                 }
             }
             foreach ($content as $key => $val) {
                 $separated = explode($this->separator, trim($val));
                 //get position of the comment_separator
                 $pos = strpos($separated[2], $this->comment_separator);
                 if ($pos !== false) {
                     //cut comment of
                     $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)) {
                     if ($local_value != "" and $local_value != $separated[2]) {
                         // keep the locally changed value
                         $lang_array[$separated[0]][$separated[1]] = $local_value;
                     } else {
                         // insert a new value if no local value exists
                         // reset local_change if the values are equal
                         ilLanguage::replaceLangEntry($separated[0], $separated[1], $lang_key, $separated[2]);
                         $lang_array[$separated[0]][$separated[1]] = $separated[2];
                     }
                 } else {
                     if ($scope == 'local') {
                         if ($local_value != "") {
                             // keep a locally changed value that is newer than the local file
                             $lang_array[$separated[0]][$separated[1]] = $local_value;
                         } else {
                             // UPDATE because the global values have already been INSERTed
                             ilLanguage::updateLangEntry($separated[0], $separated[1], $lang_key, $separated[2], $change_date);
                             $lang_array[$separated[0]][$separated[1]] = $separated[2];
                         }
                     }
                 }
             }
         }
         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);
                 }
             }
             ilLanguage::replaceLangModule($lang_key, $module, $lang_arr);
         }
     }
     chdir($tmpPath);
 }