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

Services/Language/classes/class.ilObjLanguageExtGUI.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 define("ILIAS_LANGUAGE_MODULE", "Services/Language");
00025 
00026 require_once("classes/class.ilObjectGUI.php");
00027 require_once("Services/Language/classes/class.ilObjLanguageAccess.php");
00028 
00029 
00044 class ilObjLanguageExtGUI extends ilObjectGUI
00045 {
00052         var $module = ILIAS_LANGUAGE_MODULE;
00053 
00054 
00061         var $inputsize = 40;
00062 
00063 
00075         function ilObjLanguageExtGUI($a_data, $a_id = 0, $a_call_by_reference = false)
00076         {
00077                 global $lng, $ilCtrl;
00078 
00079                 // language maintenance strings are defined in administration
00080         $lng->loadLanguageModule("administration");
00081         $lng->loadLanguageModule("meta");
00082 
00083                 //  view mode ('translate' or empty) needed for prepareOutput()
00084                 $ilCtrl->saveParameter($this, "view_mode");
00085 
00086                 // type and id of get the bound object
00087                 $this->type = "lng";
00088                 if (! $this->id = $_GET['obj_id'])
00089                 {
00090                         $this->id = ilObjLanguageAccess::_lookupId($lng->getUserLanguage());
00091                 }
00092                 
00093                 // do all generic GUI initialisations
00094                 $this->ilObjectGUI($a_data, $this->id, false, true);
00095                 
00096                 // initialize the array to store GUI session variables
00097                 if (!is_array($_SESSION[get_class($this)]))
00098                 {
00099                         $_SESSION[get_class($this)] = array();
00100                 }
00101                 $this->session =& $_SESSION[get_class($this)];
00102         }
00103 
00104 
00111         function assignObject()
00112         {
00113                 require_once("Services/Language/classes/class.ilObjLanguageExt.php");
00114                 $this->object =& new ilObjLanguageExt($this->id);
00115         }
00116 
00117 
00121         function &executeCommand()
00122         {
00123                 if (!ilObjLanguageAccess::_checkTranslate())
00124                 {
00125              $this->ilErr->raiseError($this->lng->txt("permission_denied"),$this->ilErr->MESSAGE);
00126                 }
00127                 
00128                 $cmd = $this->ctrl->getCmd("view")."Object";
00129                 $this->$cmd();
00130                 exit;
00131         }
00132 
00133         
00137         function cancelObject()
00138         {
00139                 ilUtil::sendInfo($this->lng->txt("action_aborted"), false);
00140                 $this->viewObject();
00141         }
00142 
00146         function viewObject()
00147         {
00148                 global $ilUser;
00149                 
00150                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.lang_edit_items.html", "Services/Language");
00151 
00152                 // set the language to compare with
00153         $compare = $this->getPar('compare', $this->lng->getDefaultLanguage());
00154                 if ($compare == $this->object->key)
00155                 {
00156                         $defaults_read = true;
00157                         $this->object->readLanguageFile();
00158                         $compare_content = $this->object->getLangFileContent();
00159                         $compare_comments = $this->object->getLangFileComments();
00160                         $compare_note = " ". $this->lng->txt("language_default_entries");
00161                 }
00162 
00163                 // page translation mode:
00164                 // - the table is filtered by a list of modules and topics
00165                 // - all found entries are shown on the same page
00166                 if ($this->_isPageTranslation())
00167                 {
00168                         $offset = 0;
00169                         $limit = 0;
00170 
00171                         $modules = $this->getPar("page_modules", array());
00172                         $topics = $this->getPar("page_topics", array());
00173 
00174                         if (!isset($compare_content))
00175                         {
00176                                 $compare_content = $this->object->_getTranslations(
00177                                                                         $compare, $modules, $topics);
00178                         }
00179 
00180                         $translations = $this->object->_getTranslations(
00181                                                         $this->object->key,
00182                                                         $modules, $topics);
00183                 }
00184                 // normal view mode:
00185                 // - the table is filtered manually by module, mode and pattern
00186                 // - found entries are paged by maximum list length
00187                 // - the filter selection is shown
00188                 else
00189                 {
00190                         $offset = $this->getPar('offset','0');
00191                         $limit = $ilUser->getPref("hits_per_page");
00192 
00193                         $filter_mode = $this->getPar('filter_mode','all');
00194                         $filter_pattern = $this->getPar('filter_pattern','');
00195                         $filter_module = $this->getPar('filter_module','administration');
00196                         $filter_modules = $filter_module ? array($filter_module) : array();
00197 
00198                         if (!isset($compare_content))
00199                         {
00200                                 $compare_content = $this->object->_getTranslations(
00201                                                         $compare, $filter_modules);
00202                         }
00203 
00204                         switch ($filter_mode)
00205                         {
00206                                 case "changed":
00207                                     if (!$defaults_read)
00208                                     {
00209                                         $this->object->readLanguageFile();
00210                                     }
00211                                     
00212                                         $translations = $this->object->getChangedTranslations(
00213                                                                 $filter_modules, $filter_pattern);
00214                                         break;
00215                                                     
00216                                 case "unchanged":
00217                                     if (!$defaults_read)
00218                                     {
00219                                         $this->object->readLanguageFile();
00220                                     }
00221 
00222                                         $translations = $this->object->getUnchangedTranslations(
00223                                                         $filter_modules, $filter_pattern);
00224                                         break;
00225                                         
00226                                 case "commented":
00227                                     if (!$defaults_read)
00228                                     {
00229                                         $this->object->readLanguageFile();
00230                                     }
00231                     $translations = $this->object->getCommentedTranslations(
00232                                                         $filter_modules, $filter_pattern);
00233                                         break;
00234 
00235                                 case "equal":
00236                     $translations = $this->object->getAllTranslations(
00237                                                         $filter_modules, $filter_pattern);
00238 
00239                                         $translations = array_intersect_assoc($translations, $compare_content);
00240                                         break;
00241 
00242                                 case "different":
00243                     $translations = $this->object->getAllTranslations(
00244                                                         $filter_modules, $filter_pattern);
00245 
00246                                         $translations = array_diff_assoc($translations, $compare_content);
00247                                         break;
00248 
00249                                 case "all":
00250                                 default:
00251                                 
00252                                         $translations = $this->object->getAllTranslations(
00253                                                         $filter_modules, $filter_pattern);
00254                         }
00255 
00256                         // show the filter section
00257                         $this->tpl->setCurrentBlock("filter");
00258 
00259                         // filter by language module
00260                         $options = array();
00261                         $options[""] = $this->lng->txt("language_all_modules");
00262                         $modules = $this->object->_getModules($this->object->key);
00263                         foreach ($modules as $mod)
00264                         {
00265                                 $options[$mod] = $mod;
00266                         }
00267                         $this->tpl->setVariable("SELECT_MODULE",
00268                                 ilUtil::formSelect($filter_module, "filter_module", $options, false, true));
00269                                 
00270                         // filter by mode
00271                         $options = array();
00272                         $options["all"] = $this->lng->txt("language_scope_global");
00273                         $options["changed"] = $this->lng->txt("language_scope_local");
00274                         $options["unchanged"] = $this->lng->txt("language_scope_unchanged");
00275                         $options["equal"] = $this->lng->txt("language_scope_equal");
00276                         $options["different"] = $this->lng->txt("language_scope_different");
00277                         $options["commented"] = $this->lng->txt("language_scope_commented");
00278                         $this->tpl->setVariable("SELECT_MODE",
00279                                 ilUtil::formSelect($filter_mode, "filter_mode", $options, false, true));
00280                         
00281                         // filter by pattern
00282                         $this->tpl->setVariable("PATTERN_NAME", "filter_pattern");
00283                         $this->tpl->setVariable("PATTERN_VALUE", ilUtil::prepareFormOutput($filter_pattern));
00284 
00285                         // and general filter variables
00286                         $this->tpl->setVariable("FILTER_ACTION", $this->ctrl->getFormAction($this));
00287                         $this->tpl->setVariable("TXT_FILTER", $this->lng->txt("filter"));
00288                         $this->tpl->setVariable("OFFSET_NAME", "offset");
00289                         $this->tpl->setVariable("OFFSET_VALUE", "0");
00290                         $this->tpl->setVariable("TXT_APPLY_FILTER", $this->lng->txt("apply_filter"));
00291                         $this->tpl->setVariable("CMD_FILTER", "view");
00292                         $this->tpl->parseCurrentBlock();
00293                 }
00294                 
00295                 // show the compare section
00296                 $this->tpl->setCurrentBlock("compare");
00297                 $this->tpl->setVariable("COMPARE_ACTION", $this->ctrl->getFormAction($this));
00298                 $this->tpl->setVariable("TXT_COMPARE", $this->lng->txt("language_compare"));
00299                 $this->tpl->setVariable("TXT_CHANGE", $this->lng->txt("change"));
00300                 $options = array();
00301                 $langlist = $this->lng->getInstalledLanguages();
00302                 foreach ($langlist as $lang_key)
00303                 {
00304                 $options[$lang_key] = $this->lng->txt("meta_l_".$lang_key);
00305                 }
00306                 $this->tpl->setVariable("SELECT_COMPARE",
00307                         ilUtil::formSelect($compare, "compare", $options, false, true,1));
00308                 $this->tpl->setVariable("CMD_COMPARE", "view");
00309                 $this->tpl->parseCurrentBlock();
00310 
00311                 // prepare the dataset for the output table
00312                 $sort_by = $this->getPar('sort_by','translation');
00313                 $sort_order = $this->getPar('sort_order','asc');
00314 
00315                 $list = array();
00316                 foreach($translations as $name => $translation)
00317                 {
00318                         $keys = explode("#:#", $name);
00319                         $data = array();
00320                         
00321                         $data["module"] = $keys[0];
00322                         $data["topic"] = str_replace('_', ' ', $keys[1]);
00323                         $data["name"] = $name;
00324                         $data["translation"] = $translation;
00325                         $data["default"] = $compare_content[$name];
00326                         $data["comment"] = $compare_comments[$name];
00327 
00328                         $list[] = $data;
00329                 }
00330                 $list = ilUtil::sortArray($list, $sort_by, $sort_order);
00331                 if ($limit > 0)
00332                 {
00333                         $list = array_slice($list, $offset, $limit);
00334                 }
00335 
00336                 // create and configure the table object
00337                 include_once 'Services/Table/classes/class.ilTableGUI.php';
00338                 $tbl = new ilTableGUI();
00339 
00340                 $tbl->disable('title');
00341  
00342                 $tbl->setHeaderNames(array($this->lng->txt("module"),
00343                                                                    $this->lng->txt("identifier"),
00344                                                                    $this->lng->txt("meta_l_".$this->object->key),
00345                                                                    $this->lng->txt("meta_l_".$compare).$compare_note));
00346 
00347                 $tbl->setHeaderVars(array("module",
00348                                                                   "topic",
00349                                                                   "translation",
00350                                                                   "default"),
00351                                                         $this->ctrl->getParameterArray($this));
00352 
00353 
00354                 $tbl->setColumnWidth(array( "10%",
00355                                                                         "20%",
00356                                                                         "40%",
00357                                                                         "30%"));
00358 
00359                 $tbl->setOrderColumn($sort_by);
00360                 $tbl->setOrderDirection($sort_order);
00361                 $tbl->setLimit($limit);
00362                 $tbl->setOffset($offset);
00363                 $tbl->setMaxCount(count($translations));
00364 
00365 
00366                 // prepare the table template
00367                 $tpl =& new ilTemplate("tpl.table.html", true, true);
00368                 $tpl->setCurrentBlock("tbl_form_header");
00369                 $tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
00370                 $tpl->parseCurrentBlock();
00371 
00372                 $tpl->setCurrentBlock("tbl_action_btn");
00373                 $tpl->setVariable("BTN_NAME",'save');
00374                 $tpl->setVariable("BTN_VALUE",$this->lng->txt('save'));
00375                 $tpl->parseCurrentBlock();
00376  
00377                 $tpl->setCurrentBlock("tbl_action_row");
00378                 $tpl->setVariable("COLUMN_COUNTS","4");
00379                 $tpl->parseCurrentBlock();
00380 
00381                 // render the table rows
00382         $tpl->addBlockfile("TBL_CONTENT", "tbl_content", "tpl.lang_items_row.html", "Services/Language");
00383                 foreach ($list as $data)
00384                 {
00385                         if (strlen($data["translation"]) <= $this->inputsize)
00386                         {
00387                                 $tpl->setCurrentBlock("input");
00388                                 $tpl->setVariable("I_NAME", ilUtil::prepareFormOutput($data["name"]));
00389                                 $tpl->setVariable("I_SIZE", $this->inputsize);
00390                                 $tpl->setVariable("I_USER_VALUE", ilUtil::prepareFormOutput($data["translation"]));
00391                         }
00392                         else
00393                         {
00394                                 $tpl->setCurrentBlock("textarea");
00395                                 $tpl->setVariable("T_ROWS", ceil(strlen($data["translation"]) / $this->inputsize));
00396                                 $tpl->setVariable("T_SIZE", $this->inputsize);
00397                                 $tpl->setVariable("T_NAME", ilUtil::prepareFormOutput($data["name"]));
00398                                 $tpl->setVariable("T_USER_VALUE", ilUtil::prepareFormOutput($data["translation"]));
00399                                 $tpl->parseCurrentBlock();
00400                         }
00401 
00402                         $tpl->setCurrentBlock("row");
00403                         $tpl->setVariable("MODULE", ilUtil::prepareFormOutput($data["module"]));
00404                         $tpl->setVariable("TOPIC", ilUtil::prepareFormOutput($data["topic"]));
00405                         $tpl->setVariable("DEFAULT_VALUE", ilUtil::prepareFormOutput($data["default"]));
00406                         $tpl->setVariable("COMMENT", ilUtil::prepareFormOutput($data["comment"]));
00407                         $tpl->parseCurrentBlock();
00408                 }
00409 
00410                 // render and show the table
00411                 $tbl->setTemplate($tpl);
00412                 $tbl->render();
00413                 $this->tpl->setVariable("TRANSLATION_TABLE", $tpl->get());
00414                 $this->tpl->show();
00415         }
00416         
00417 
00421         function saveObject()
00422         {
00423                 // permission check
00424                 if (!ilObjLanguageAccess::_checkTranslate())
00425                 {
00426              $this->ilErr->raiseError($this->lng->txt("permission_denied"),$this->ilErr->MESSAGE);
00427                 }
00428 
00429                 // prepare the values to be saved
00430                 $save_array = array();
00431                 foreach ($_POST as $key => $value)
00432                 {
00433                         $keys = explode("#:#", ilUtil::stripSlashes($key, false));
00434                         if (count($keys) == 2)
00435                         {
00436                                 // avoid line breaks
00437                                 $value = preg_replace("/(\015\012)|(\015)|(\012)/","<br />",$value);
00438                                 $value = ilUtil::stripSlashes($value, false);
00439                                 $save_array[$key] = $value;
00440                         }
00441                 }
00442                 
00443                 // save the translations
00444                 $this->object->_saveTranslations($this->object->key, $save_array);
00445 
00446                 // view the list
00447                 $this->viewObject();
00448         }
00449         
00450 
00454         function importObject()
00455         {
00456                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.lang_file_import.html", "Services/Language");
00457 
00458                 $this->tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
00459                 $this->tpl->setVariable("TXT_HEADER",$this->lng->txt("language_import_file"));
00460                 $this->tpl->setVariable("TXT_FILE",$this->lng->txt("file"));
00461                 
00462                 $this->tpl->setVariable("TXT_MODE",$this->lng->txt("language_mode_existing"));
00463                 $this->tpl->setVariable("TXT_MODE_KEEPALL",$this->lng->txt("language_mode_existing_keepall"));
00464                 $this->tpl->setVariable("TXT_MODE_KEEPNEW",$this->lng->txt("language_mode_existing_keepnew"));
00465                 $this->tpl->setVariable("TXT_MODE_REPLACE",$this->lng->txt("language_mode_existing_replace"));
00466                 $this->tpl->setVariable("TXT_MODE_DELETE",$this->lng->txt("language_mode_existing_delete"));
00467 
00468                 $this->tpl->setVariable("TXT_UPLOAD",$this->lng->txt("upload"));
00469                 $this->tpl->setVariable("CMD_UPLOAD","upload");
00470                 $this->tpl->show();
00471         }
00472         
00473         
00477         function uploadObject()
00478         {
00479                 // permission check
00480                 if (!ilObjLanguageAccess::_checkMaintenance())
00481                 {
00482              $this->ilErr->raiseError($this->lng->txt("permission_denied"),$this->ilErr->MESSAGE);
00483                 }
00484 
00485                 if ($_POST['cmd']['upload'])
00486                 {
00487                         $file = $_FILES['userfile']['tmp_name'].'x';
00488                         
00489                         if (ilUtil::moveUploadedFile($_FILES['userfile']['tmp_name'],
00490                                                                                  $_FILES['userfile']['name'],
00491                                                                                  $file))
00492                         {
00493                                 $this->object->importLanguageFile($file,$_POST['mode_existing']);
00494                                 ilUtil::sendInfo(sprintf($this->lng->txt("language_file_imported"), $_FILES['userfile']['name']) , false);
00495                                 $this->importObject();
00496                         }
00497                         else
00498                         {
00499                                 $this->importObject();
00500                         }
00501                 }
00502                 else
00503                 {
00504                         $this->cancelObject();
00505                 }
00506         }
00507 
00508         
00512         function exportObject()
00513         {
00514                 $scope = $_POST["scope"] ? $_POST["scope"] : "global";
00515                 
00516                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.lang_file_export.html", "Services/Language");
00517 
00518                 $this->tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
00519                 $this->tpl->setVariable("TXT_HEADER",$this->lng->txt("language_export_file"));
00520 
00521                 $this->tpl->setVariable("TXT_SCOPE",$this->lng->txt("language_file_scope"));
00522                 $this->tpl->setVariable("TXT_SCOPE_GLOBAL",$this->lng->txt("language_scope_global"));
00523                 $this->tpl->setVariable("TXT_SCOPE_LOCAL",$this->lng->txt("language_scope_local"));
00524                 $this->tpl->setVariable("TXT_SCOPE_UNCHANGED",$this->lng->txt("language_scope_unchanged"));
00525                 $this->tpl->setVariable("TXT_SCOPE_TRANSLATE",$this->lng->txt("language_scope_translate"));
00526 
00527                 $this->tpl->setVariable("CHECKED_GLOBAL",$scope == 'global' ? 'checked="checked"' : '');
00528                 $this->tpl->setVariable("CHECKED_LOCAL",$scope == 'local' ? 'checked="checked"' : '');
00529                 $this->tpl->setVariable("CHECKED_UNCHANGED",$scope == 'unchanged' ? 'checked="checked"' : '');
00530                 $this->tpl->setVariable("CHECKED_TRANSLATE",$scope == 'translate' ? 'checked="checked"' : '');
00531 
00532                 $this->tpl->setVariable("TXT_DOWNLOAD",$this->lng->txt("download"));
00533                 $this->tpl->setVariable("CMD_DOWNLOAD","download");
00534                 $this->tpl->show();
00535         }
00536 
00537         
00541         function downloadObject()
00542         {
00543                 global $ilUser;
00544                 
00545                 $this->object->readLanguageFile();
00546         $tpl = new ilTemplate("tpl.lang_file_header.html",true,true, "Services/Language");
00547 
00548                 $version = "_"
00549                         . str_replace(".", "_", substr(ILIAS_VERSION, 0, strpos(ILIAS_VERSION, " ")))
00550                 . "-" . date('Y-m-d');
00551         
00552                 if ($_POST["scope"] == 'global')
00553                 {
00554                         $translations = $this->object->getAllTranslations();
00555                         $filename = 'ilias_' . $this->object->key . $version . '.lang';
00556 
00557                         $tpl->setCurrentBlock('global');
00558                         $tpl->setVariable('AUTHOR', $this->object->getLangFileParam('author'));
00559                         $tpl->setVariable('VERSION', $this->object->getLangFileParam('version'));
00560                         $tpl->parseCurrentBlock();
00561                         $tpl->setVariable('SCOPE', $this->lng->txtlng('administration','language_scope_global','en'));
00562                 }
00563                 elseif ($_POST["scope"] == 'local')
00564                 {
00565                         $translations = $this->object->getChangedTranslations();
00566                         $filename = 'ilias_' . $this->object->key . $version . '.lang.local';
00567 
00568                         $tpl->setCurrentBlock('local');
00569                         $tpl->setVariable('BASED_ON', $this->object->getLangFileParam('version'));
00570                         $tpl->parseCurrentBlock();
00571                         $tpl->setVariable('SCOPE', $this->lng->txtlng('administration','language_scope_local','en'));
00572                 }
00573                 elseif ($_POST["scope"] == 'unchanged')
00574                 {
00575                         $translations = $this->object->getUnchangedTranslations();
00576                         $filename = 'ilias_' . $this->object->key . $version . '.lang.unchanged';
00577 
00578                         $tpl->setCurrentBlock('global');
00579                         $tpl->setVariable('AUTHOR', $this->object->getLangFileParam('author'));
00580                         $tpl->setVariable('VERSION', $this->object->getLangFileParam('version'));
00581                         $tpl->parseCurrentBlock();
00582                         $tpl->setVariable('SCOPE', $this->lng->txtlng('administration','language_scope_unchanged','en'));
00583 
00584                         $tpl->parseCurrentBlock();
00585                 }
00586                 elseif ($_POST["scope"] == 'translate')
00587                 {
00588                         $translations = $this->object->getAllTranslations();
00589                         $filename = 'ilias_' . $this->object->key . $version .  '.lang';
00590 
00591                         $tpl->setCurrentBlock('global');
00592                         $tpl->setVariable('AUTHOR', $this->object->getLangFileParam('author'));
00593                         $tpl->setVariable('VERSION', $this->object->getLangFileParam('version'));
00594                         $tpl->parseCurrentBlock();
00595                         $tpl->setVariable('SCOPE', $this->lng->txtlng('administration','language_scope_translate','en'));
00596                 }
00597 
00598 
00599                 $tpl->setVariable('LANGUAGE', $this->lng->txtlng('common','lang_'.$this->object->key,'en'));
00600                 $tpl->setVariable('ILIAS_HTTP_PATH',ILIAS_HTTP_PATH);
00601                 $tpl->setVariable('ILIAS_VERSION',ILIAS_VERSION);
00602                 $tpl->setVariable('CREATE_DATE',date('Y-m-d H:i:s'));
00603                 $tpl->setVariable('USER',$ilUser->getFullname());
00604                 $tpl->setVariable('EMAIL',$ilUser->getEmail());
00605                 
00606                 $data = $tpl->get();
00607                 
00608                 if ($_POST["scope"] == 'translate')
00609                 {
00610                         foreach ($translations as $key => $value)
00611                         {
00612                                 $data .= $key . $this->lng->separator . "\n";
00613                         }
00614                 }
00615                 else
00616                 {
00617                         foreach ($translations as $key => $value)
00618                         {
00619                                 $data .= $key . $this->lng->separator . $value . "\n";
00620                         }
00621                 }
00622                 ilUtil::deliverData($data, $filename);
00623         }
00624 
00625 
00629         function maintainObject()
00630         {
00631                 global $ilUser;
00632                 
00633                 // permission check
00634                 if (!ilObjLanguageAccess::_checkMaintenance())
00635                 {
00636              $this->ilErr->raiseError($this->lng->txt("permission_denied"),$this->ilErr->MESSAGE);
00637                 }
00638 
00639                 switch ($_POST["maintain"])
00640                 {
00641                         // save the local changes to the local language file
00642                         case "save":
00643                                 $lang_file = $this->object->getCustLangPath() . '/ilias_' . $this->object->key . '.lang.local';
00644 
00645                                 if ((is_file($lang_file) and is_writable($lang_file))
00646                                 or (!file_exists($lang_file) and is_writable($this->object->getCustLangPath())))
00647                                 {
00648                                         $this->object->readLanguageFile();
00649                                         $translations = $this->object->getChangedTranslations();
00650 
00651                                 $tpl = new ilTemplate("tpl.lang_file_header.html",true,true, "Services/Language");
00652                                         $tpl->setCurrentBlock('local');
00653                                         $tpl->setVariable('BASED_ON', $this->object->getLangFileParam('version'));
00654                                         $tpl->parseCurrentBlock();
00655                                         $tpl->setVariable('SCOPE', $this->lng->txtlng('administration','language_scope_local','en'));
00656                                         $tpl->setVariable('LANGUAGE', $this->lng->txtlng('common','lang_'.$this->object->key,'en'));
00657                                         $tpl->setVariable('ILIAS_HTTP_PATH',ILIAS_HTTP_PATH);
00658                                         $tpl->setVariable('ILIAS_VERSION',ILIAS_VERSION);
00659                                         $tpl->setVariable('CREATE_DATE',date('Y-m-d H:i:s'));
00660                                         $tpl->setVariable('USER',$ilUser->getFullname());
00661                                         $tpl->setVariable('EMAIL',$ilUser->getEmail());
00662 
00663                                         @rename($lang_file, $lang_file.".bak");
00664                                         $fp = fopen($lang_file, "w");
00665                                         fwrite($fp, $tpl->get());
00666                                         foreach ($translations as $key => $value)
00667                                         {
00668                                                 fwrite($fp, $key . $this->lng->separator . $value . "\n");
00669                                         }
00670                                         fclose($fp);
00671                                         $this->object->setLocal(true);
00672                                         ilUtil::sendInfo($this->lng->txt("language_saved_local") , false);
00673                                 }
00674                                 else
00675                                 {
00676                                         ilUtil::sendInfo($this->lng->txt("language_error_write_local") , false);
00677                                 }
00678                                 break;
00679                                 
00680                         // load the content of the local language file
00681                         case "load":
00682                                 $lang_file = $this->object->getCustLangPath() . '/ilias_' . $this->object->key . '.lang.local';
00683                             if (is_file($lang_file) and is_readable($lang_file))
00684                             {
00685                                         $this->object->importLanguageFile($lang_file, 'replace');
00686                                         $this->object->setLocal(true);
00687                                         ilUtil::sendInfo($this->lng->txt("language_loaded_local") , false);
00688                                 }
00689                                 else
00690                                 {
00691                                         ilUtil::sendInfo($this->lng->txt("language_error_read_local") , false);
00692                                 }
00693                                 break;
00694 
00695                         // revert the database to the default language file
00696                         case "clear":
00697                             $lang_file = $this->object->getLangPath() . '/ilias_' . $this->object->key . '.lang';
00698                             if (is_file($lang_file) and is_readable($lang_file))
00699                             {
00700                                         $this->object->importLanguageFile($lang_file, 'delete');
00701                                         $this->object->setLocal(false);
00702                                         ilUtil::sendInfo($this->lng->txt("language_cleared_local") , false);
00703                                 }
00704                                 else
00705                                 {
00706                                         ilUtil::sendInfo($this->lng->txt("language_error_clear_local") , false);
00707                                 }
00708                                 break;
00709                 }
00710                 
00711                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.lang_maintenance.html", "Services/Language");
00712                 $this->tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
00713                 $this->tpl->setVariable("TXT_MAINTENANCE",$this->lng->txt("language_maintenance"));
00714                 $this->tpl->setVariable("TXT_MAINTAIN_LOCAL",$this->lng->txt("language_maintain_local_changes"));
00715                 $this->tpl->setVariable("TXT_SELECT",$this->lng->txt("please_select"));
00716                 $this->tpl->setVariable("TXT_SAVE",$this->lng->txt("language_save_local_changes"));
00717                 $this->tpl->setVariable("TXT_LOAD",$this->lng->txt("language_load_local_changes"));
00718                 $this->tpl->setVariable("TXT_CLEAR",$this->lng->txt("language_clear_local_changes"));
00719                 $this->tpl->setVariable("TXT_NOTE_SAVE",$this->lng->txt("language_note_save_local"));
00720                 $this->tpl->setVariable("TXT_MAINTAIN",$this->lng->txt("language_process_maintenance"));
00721                 $this->tpl->setVariable("VAR_MAINTAIN", "maintain");
00722                 $this->tpl->setVariable("CMD_MAINTAIN", "maintain");
00723                 $this->tpl->show();
00724         }
00725 
00729         function settingsObject()
00730         {
00731                 global $ilSetting;
00732 
00733                 // permission check
00734                 if (!ilObjLanguageAccess::_checkMaintenance())
00735                 {
00736              $this->ilErr->raiseError($this->lng->txt("permission_denied"),$this->ilErr->MESSAGE);
00737                 }
00738 
00739                 $translate_key = "lang_translate_". $this->object->key;
00740 
00741                 // save and get the page translation setting
00742                 switch ($_POST["translation"])
00743                 {
00744                         case "enable":
00745                                 $ilSetting->set($translate_key, true);
00746                                 break;
00747                         case "disable":
00748                                 $ilSetting->set($translate_key, false);
00749                 }
00750                 $translate = $ilSetting->get($translate_key, false);
00751                 
00752                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.lang_settings.html", "Services/Language");
00753 
00754                 $this->tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
00755                 $this->tpl->setVariable("TXT_SETTINGS",$this->lng->txt("language_settings"));
00756                 $this->tpl->setVariable("TXT_TRANSLATION",$this->lng->txt("language_translation_mode"));
00757                 $this->tpl->setVariable("TXT_TRANSLATION_ENABLED",$this->lng->txt("language_translation_enabled"));
00758                 $this->tpl->setVariable("TXT_TRANSLATION_DISABLED",$this->lng->txt("language_translation_disabled"));
00759                 $this->tpl->setVariable("CHECKED_ENABLE", $translate ? 'checked="checked"': '');
00760                 $this->tpl->setVariable("CHECKED_DISABLE", $translate ? '' : 'checked="checked"');
00761                 $this->tpl->setVariable("TXT_NOTE_TRANSLATION",$this->lng->txt("language_note_translation"));
00762                 $this->tpl->setVariable("TXT_CHANGE_SETTINGS",$this->lng->txt("language_change_settings"));
00763                 $this->tpl->setVariable("CMD_SETTINGS", "settings");
00764                 $this->tpl->show();
00765         }
00766 
00770         function statisticsObject()
00771         {
00772                 $this->object->readLanguageFile();
00773                 $modules = $this->object->_getModules($this->object->key);
00774                 
00775                 $data = array();
00776                 $total = array("",0,0,0);
00777                 foreach($modules as $module)
00778                 {
00779                         $row = array();
00780                         $row[0] = $module;
00781                         $row[1] = count($this->object->getAllTranslations(array($module)));
00782                         $row[2] = count($this->object->getChangedTranslations(array($module)));
00783                         $row[3] = count($this->object->getUnchangedTranslations(array($module)));
00784                         $total[1] += $row[1];
00785                         $total[2] += $row[2];
00786                         $total[3] += $row[3];
00787                         $data[] = $row;
00788                 }
00789                 $total[0] = "<b>".$this->lng->txt("language_all_modules")."</b>";
00790                 $total[1] = "<b>".$total[1]."</b>";
00791                 $total[2] = "<b>".$total[2]."</b>";
00792                 $total[3] = "<b>".$total[3]."</b>";
00793                 $data[] = $total;
00794 
00795                 // prepare the templates for output
00796                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.lang_statistics.html", "Services/Language");
00797                 $this->tpl->addBlockFile("TABLE_STATISTICS", "table_statistics", "tpl.table.html");
00798                 $this->tpl->addBlockFile("TBL_CONTENT", "tbl_content", "tpl.obj_tbl_rows.html");
00799 
00800                 // create and configure the table object
00801                 include_once 'Services/Table/classes/class.ilTableGUI.php';
00802                 $tbl = new ilTableGUI();
00803                 $tbl->disable('title');
00804                 $tbl->disable('sort');
00805                 $tbl->disable('numinfo');
00806                 
00807                 $tbl->setHeaderNames(array($this->lng->txt("module"),
00808                                                                    $this->lng->txt("language_scope_global"),
00809                                                                    $this->lng->txt("language_scope_local"),
00810                                                                    $this->lng->txt("language_scope_unchanged")));
00811                 $tbl->setColumnWidth(array( "25%", "25%", "25%", "25%"));
00812                 $tbl->setLimit(count($data));
00813                 $tbl->setData($data);
00814                 
00815                 // show the table
00816                 $tbl->render();
00817                 $this->tpl->show();
00818         }
00819         
00820 
00830         function getPar($a_request_name, $a_default_value)
00831         {
00832                 // get the parameter value
00833                 if (isset($_GET[$a_request_name]))
00834                 {
00835                         $param = $_GET[$a_request_name];
00836                         $from_request = true;
00837                 }
00838                 elseif (isset($_POST[$a_request_name]))
00839                 {
00840                         $param = $_POST[$a_request_name];
00841                         $from_request = true;
00842                 }
00843                 elseif (isset($this->session[$a_request_name]))
00844                 {
00845                         $param = $this->session[$a_request_name];
00846                         $from_request = false;
00847                 }
00848                 else
00849                 {
00850                         $param = $a_default_value;
00851                         $from_request = false;
00852                 }
00853                 
00854                 // strip slashes from request parameters
00855                 if ($from_request)
00856                 {
00857                         if (is_array($param))
00858                         {
00859                                 foreach ($param as $key => $value)
00860                                 {
00861                                         $param[$key] = ilUtil::stripSlashes($value);
00862                                 }
00863                         }
00864                         else
00865                         {
00866                                 $param = ilUtil::stripSlashes($param);
00867                         }
00868                 }
00869                 
00870                 // make the parameter available to further requests
00871                 $this->session[$a_request_name] = $param;
00872 
00873                 return $param;
00874         }
00875 
00880         function getAdminTabs(&$tabs_gui)
00881         {
00882                 global $rbacsystem;
00883 
00884                 $tabs_gui->addTarget("edit",
00885                         $this->ctrl->getLinkTarget($this, "view"),
00886                         array("","view","cancel","save"));
00887 
00888                 $tabs_gui->addTarget("export",
00889                         $this->ctrl->getLinkTarget($this, "export"),
00890                         array("export","download"));
00891 
00892                 if (ilObjLanguageAccess::_checkMaintenance())
00893                 {
00894                         $tabs_gui->addTarget("import",
00895                                 $this->ctrl->getLinkTarget($this, "import"),
00896                                 array("import","upload"));
00897 
00898                         $tabs_gui->addTarget("language_maintain",
00899                                 $this->ctrl->getLinkTarget($this, "maintain"),
00900                                 array("maintain"));
00901 
00902                         $tabs_gui->addTarget("settings",
00903                                 $this->ctrl->getLinkTarget($this, "settings"),
00904                                 array("settings"));
00905                 }
00906                 
00907                 $tabs_gui->addTarget("language_statistics",
00908                         $this->ctrl->getLinkTarget($this, "statistics"),
00909                         array("statistics"));
00910         }
00911 
00912 
00917         function prepareOutput()
00918         {
00919                 if ($this->_isPageTranslation())
00920                 {
00921                         // show the pure translation page without menu, tabs etc.
00922                         $this->tpl->addBlockFile("CONTENT","content","tpl.adm_translate.html","Services/Language");
00923                         $this->tpl->setHeaderPageTitle($this->lng->txt("translation"));
00924                         $this->tpl->setTitle($this->lng->txt("translation"). " "
00925                                                                         .$this->lng->txt("meta_l_".$this->object->key));
00926                         $this->tpl->setTitleIcon(ilUtil::getImagePath("icon_lng_b.gif"),
00927                                                                          $this->lng->txt("obj_" . $this->object->getType()));
00928                 }
00929                 else
00930                 {
00931                         // show the full page framework
00932                         parent::prepareOutput();
00933                 }
00934         }
00935         
00936         
00941         function addAdminLocatorItems()
00942         {
00943                 global $ilLocator, $tpl;
00944 
00945                 $ilLocator->addItem($this->lng->txt("administration"),
00946                         $this->ctrl->getLinkTargetByClass("iladministrationgui", "frameset"),
00947                         ilFrameTargetInfo::_getFrame("MainContent"));
00948 
00949                 $ilLocator->addItem($this->lng->txt("languages"),
00950                         $this->ctrl->getLinkTargetByClass("ilobjlanguagefoldergui", ""));
00951 
00952                 $ilLocator->addItem($this->lng->txt("meta_l_". $this->object->getTitle()),
00953                         $this->ctrl->getLinkTarget($this, "view"));
00954         }
00955 
00956 
00961         function setTitleAndDescription()
00962         {
00963                 $this->tpl->setTitle($this->lng->txt("meta_l_".$this->object->getTitle()));
00964                 // $this->tpl->setDescription($this->object->getLongDescription());
00965                 $this->tpl->setTitleIcon(ilUtil::getImagePath("icon_".$this->object->getType()."_b.gif"), $this->lng->txt("obj_" . $this->object->getType()));
00966         }
00967 
00968 
00969         //
00970         // STATIC FUNCTIONS
00971         //
00972 
00985         function _isPageTranslation()
00986         {
00987                 return ($_GET['view_mode'] == "translate");
00988         }
00989 
00990 
00999         function _getTranslationLink()
01000         {
01001                 global $ilSetting, $lng;
01002 
01003                 // prevent translation link on translation screen
01004                 // check setting of translation mode
01005                 if (ilObjLanguageExtGUI::_isPageTranslation()
01006                         or !$ilSetting->get("lang_translate_".$lng->getLangKey()))
01007                 {
01008                         return "";
01009                 }
01010 
01011                 // set the target for translation
01012                 // ref id must be given to prevent params being deleted by ilAdministrtionGUI
01013                 $action = "ilias.php"
01014                         ."?ref_id=".ilobjLanguageAccess::_lookupLangFolderRefId()
01015                         ."&baseClass=ilAdministrationGUI"
01016                         ."&cmdClass=ilobjlanguageextgui"
01017                         ."&view_mode=translate";
01018 
01019                 $tpl = new ilTemplate("tpl.translation_link.html",true,true, "Services/Language");
01020 
01021                 foreach($lng->getUsedModules() as $module => $dummy)
01022                 {
01023                         $tpl->setCurrentBlock("hidden");
01024                         $tpl->setVariable("NAME", "page_modules[]");
01025                         $tpl->setVariable("VALUE", ilUtil::prepareFormOutput($module));
01026                         $tpl->parseCurrentBlock();
01027                 }
01028 
01029                 foreach($lng->getUsedTopics() as $topic => $dummy)
01030                 {
01031                         $tpl->setCurrentBlock("hidden");
01032                         $tpl->setVariable("NAME", "page_topics[]");
01033                         $tpl->setVariable("VALUE", ilUtil::prepareFormOutput($topic));
01034                         $tpl->parseCurrentBlock();
01035                 }
01036                 
01037                 $tpl->setVariable("ACTION", $action);
01038                 $tpl->setVariable("TXT_TRANSLATE",$lng->txt("translation"));
01039 
01040                 return $tpl->get();
01041         }
01042 
01043         
01044 } // END class.ilObjLanguageExtGUI
01045 ?>

Generated on Fri Dec 13 2013 17:56:57 for ILIAS Release_3_9_x_branch .rev 46835 by  doxygen 1.7.1