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

classes/class.ilObjLanguageFolderGUI.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 
00035 require_once "classes/class.ilObjLanguage.php";
00036 require_once "class.ilObjectGUI.php";
00037 
00038 class ilObjLanguageFolderGUI extends ilObjectGUI
00039 {
00045         function ilObjLanguageFolderGUI($a_data,$a_id,$a_call_by_reference)
00046         {
00047                 $this->type = "lngf";
00048                 $this->ilObjectGUI($a_data,$a_id,$a_call_by_reference);
00049         }
00050 
00056         function viewObject()
00057         {
00058                 global $rbacsystem;
00059                 
00060                 if (!$rbacsystem->checkAccess("visible,read",$this->object->getRefId()))
00061                 {
00062                         $this->ilias->raiseError($this->lng->txt("permission_denied"),$this->ilias->error_obj->MESSAGE);
00063                 }
00064 
00065                 //add template for buttons
00066                 $this->tpl->addBlockfile("BUTTONS", "buttons", "tpl.buttons.html");
00067                 
00068                 $this->tpl->setCurrentBlock("btn_cell");
00069                 $this->tpl->setVariable("BTN_LINK","adm_object.php?ref_id=".$this->ref_id."&cmd=refresh");
00070                 $this->tpl->setVariable("BTN_TXT",$this->lng->txt("refresh_languages"));
00071                 $this->tpl->parseCurrentBlock();
00072                 
00073                 $this->tpl->setCurrentBlock("btn_cell");
00074                 $this->tpl->setVariable("BTN_LINK","adm_object.php?ref_id=".$this->ref_id."&cmd=checkLanguage");
00075                 $this->tpl->setVariable("BTN_TXT",$this->lng->txt("check_languages"));
00076                 $this->tpl->parseCurrentBlock();
00077 
00078                 //prepare objectlist
00079                 $this->data = array();
00080                 $this->data["data"] = array();
00081                 $this->data["ctrl"] = array();
00082                 $this->data["cols"] = array("","type","language","status","last_change", "usr_agreement");
00083 
00084                 $languages = $this->object->getLanguages();
00085                 
00086                 foreach ($languages as $lang_key => $lang_data)
00087                 {
00088                         $status = "";
00089         
00090                         // set status info (in use or systemlanguage)
00091                         if ($lang_data["status"])
00092                         {
00093                                 $status = "<span class=\"small\"> (".$this->lng->txt($lang_data["status"]).")</span>";
00094                         }
00095 
00096                         // set remark color
00097                         switch ($lang_data["info"])
00098                         {
00099                                 case "file_not_found":
00100                                         $remark = "<span class=\"smallred\"> ".$this->lng->txt($lang_data["info"])."</span>";
00101                                         break;
00102                                 case "new_language":
00103                                         $remark = "<span class=\"smallgreen\"> ".$this->lng->txt($lang_data["info"])."</span>";
00104                                         break;
00105                                 default:
00106                                         $remark = "";
00107                                         break;
00108                         }
00109 
00110                         if (file_exists(ilUtil::getWebspaceDir()."/agreement/agreement_".$lang_key.".html"))
00111                         {
00112                                 $agreement_exists_str = $this->lng->txt("available")." (".$this->lng->txt("client").")";
00113                         }
00114                         else if (file_exists("./agreement/agreement_".$lang_key.".html"))
00115                         {
00116                                 $agreement_exists_str = $this->lng->txt("available");
00117                         }
00118                         else
00119                         {
00120                                 if ($lang_data["status"] == "system_language")
00121                                 {
00122                                         $agreement_exists_str = "<b>".$this->lng->txt("missing")."</b>";
00123                                 }
00124                                 else
00125                                 {
00126                                         $agreement_exists_str = $this->lng->txt("missing");
00127                                 }
00128                         }
00129 
00130                         // visible data part
00131                         $this->data["data"][] = array(
00132                                                                         "type"                  => "lng",
00133                                                                         "language"              => $lang_data["name"].$status,
00134                                                                         "status"                => $this->lng->txt($lang_data["desc"])."<br/>".$remark,
00135                                                                         "last_change"   => $lang_data["last_update"],
00136                                                                         "obj_id"                => $lang_data["obj_id"],
00137                                                                         "agreement"             => $agreement_exists_str
00138                                                                                 );
00139 
00140                 }
00141         
00142                 $this->maxcount = count($this->data["data"]);
00143 
00144                 // sorting array
00145                 $this->data["data"] = ilUtil::sortArray($this->data["data"],$_GET["sort_by"],$_GET["sort_order"]);
00146 
00147                 // now compute control information
00148                 foreach ($this->data["data"] as $key => $val)
00149                 {
00150                         $this->data["ctrl"][$key] = array(
00151                                                                                         "obj_id"        => $val["obj_id"],
00152                                                                                         "type"          => $val["type"]
00153                                                                                         );              
00154 
00155                         unset($this->data["data"][$key]["obj_id"]);
00156                         $this->data["data"][$key]["last_change"] = ilFormat::formatDate($this->data["data"][$key]["last_change"]);
00157                 }
00158 
00159                 $this->displayList();
00160         }
00161 
00167         function displayList()
00168         {
00169                 global $tree, $rbacsystem;
00170 
00171                 require_once "./classes/class.ilTableGUI.php";
00172 
00173                 // load template for table
00174                 $this->tpl->addBlockfile("ADM_CONTENT", "adm_content", "tpl.table.html");
00175                 // load template for table content data
00176                 $this->tpl->addBlockfile("TBL_CONTENT", "tbl_content", "tpl.obj_tbl_rows.html");
00177 
00178                 $num = 0;
00179 
00180                 $this->tpl->setVariable("FORMACTION", "adm_object.php?ref_id=".$this->ref_id."$obj_str&cmd=gateway");
00181 
00182                 // create table
00183                 $tbl = new ilTableGUI();
00184                 
00185                 // title & header columns
00186                 $tbl->setTitle($this->lng->txt("obj_".$this->object->getType()),"icon_".$this->object->getType()."_b.gif",$this->lng->txt("obj_".$this->object->getType()));
00187                 $tbl->setHelp("tbl_help.php","icon_help.gif",$this->lng->txt("help"));
00188                 
00189                 foreach ($this->data["cols"] as $val)
00190                 {
00191                         $header_names[] = $this->lng->txt($val);
00192                 }
00193                 
00194                 $tbl->setHeaderNames($header_names);
00195 
00196                 $header_params = array("ref_id" => $this->ref_id);
00197                 $tbl->setHeaderVars($this->data["cols"],$header_params);
00198                 
00199                 // control
00200                 $tbl->setOrderColumn($_GET["sort_by"]);
00201                 $tbl->setOrderDirection($_GET["sort_order"]);
00202                 $tbl->setLimit(0);
00203                 $tbl->setOffset(0);
00204                 $tbl->setMaxCount($this->maxcount);
00205                 
00206                 // SHOW VALID ACTIONS
00207                 $this->tpl->setVariable("COLUMN_COUNTS",count($this->data["cols"]));
00208                 $this->showActions();
00209                 
00210                 // footer
00211                 $tbl->setFooter("tblfooter",$this->lng->txt("previous"),$this->lng->txt("next"));
00212                 //$tbl->disable("footer");
00213                 
00214                 // render table
00215                 $tbl->render();
00216 
00217                 if (is_array($this->data["data"][0]))
00218                 {
00219                         //table cell
00220                         for ($i=0; $i < count($this->data["data"]); $i++)
00221                         {
00222                                 $data = $this->data["data"][$i];
00223                                 $ctrl = $this->data["ctrl"][$i];
00224 
00225                                 // color changing
00226                                 $css_row = ilUtil::switchColor($i+1,"tblrow1","tblrow2");
00227 
00228                                 $this->tpl->setCurrentBlock("checkbox");
00229                                 $this->tpl->setVariable("CHECKBOX_ID",$ctrl["obj_id"]);
00230                                 $this->tpl->setVariable("CSS_ROW",$css_row);
00231                                 $this->tpl->parseCurrentBlock();
00232 
00233                                 $this->tpl->setCurrentBlock("table_cell");
00234                                 $this->tpl->setVariable("CELLSTYLE", "tblrow1");
00235                                 $this->tpl->parseCurrentBlock();
00236 
00237                                 foreach ($data as $key => $val)
00238                                 {
00239 
00240                                         $this->tpl->setCurrentBlock("text");
00241 
00242                                         if ($key == "type")
00243                                         {
00244                                                 $val = ilUtil::getImageTagByType($val,$this->tpl->tplPath);                                             
00245                                         }
00246 
00247                                         $this->tpl->setVariable("TEXT_CONTENT", $val);                                  
00248                                         $this->tpl->parseCurrentBlock();
00249 
00250                                         $this->tpl->setCurrentBlock("table_cell");
00251                                         $this->tpl->parseCurrentBlock();
00252 
00253                                 } //foreach
00254 
00255                                 $this->tpl->setCurrentBlock("tbl_content");
00256                                 $this->tpl->setVariable("CSS_ROW", $css_row);
00257                                 $this->tpl->parseCurrentBlock();
00258                         } //for
00259                 } //if is_array
00260         }
00261 
00265         function installObject()
00266         {
00267                 if (!isset($_POST["id"]))
00268                 {
00269                         $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
00270                 }
00271 
00272                 foreach ($_POST["id"] as $obj_id)
00273                 {
00274                         $langObj = new ilObjLanguage($obj_id);
00275                         $key = $langObj->install();
00276 
00277                         if ($key != "")
00278                         {
00279                                 $lang_installed[] = $key;
00280                         }
00281 
00282                         unset($langObj);
00283                 }
00284 
00285                 if (isset($lang_installed))
00286                 {
00287                         if (count($lang_installed) == 1)
00288                         {
00289                                 $this->data = $this->lng->txt("lang_" . $lang_installed[0]) . " " . strtolower($this->lng->txt("installed")) . ".";
00290                         }
00291                         else
00292                         {
00293                                 foreach ($lang_installed as $lang_key)
00294                                 {
00295                                         $langnames[] = $this->lng->txt("lang_" . $lang_key);
00296                                 }
00297                                 $this->data = implode(", ",$langnames) . " " . strtolower($this->lng->txt("installed")) . ".";
00298                         }
00299                 }
00300                 else
00301                 {
00302                         $this->data = $this->lng->txt("languages_already_installed");
00303                 }
00304 
00305                 $this->out();
00306         }
00307 
00308 
00312         function installLocalObject()
00313         {
00314                 if (!isset($_POST["id"]))
00315                 {
00316                         $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
00317                 }
00318 
00319                 foreach ($_POST["id"] as $obj_id)
00320                 {
00321                         $langObj = new ilObjLanguage($obj_id);
00322                         $key = $langObj->install();
00323 
00324                         if ($key != "")
00325                         {
00326                                 $lang_installed[] = $key;
00327                         }
00328 
00329                         unset($langObj);
00330 
00331                         $langObj = new ilObjLanguage($obj_id);
00332                         $key = $langObj->install('local');
00333 
00334                         if ($key != "")
00335                         {
00336                                 $local_installed[] = $key;
00337                         }
00338 
00339                         unset($langObj);
00340                 }
00341 
00342                 if (isset($lang_installed))
00343                 {
00344                         if (count($lang_installed) == 1)
00345                         {
00346                                 $this->data = $this->lng->txt("lang_" . $lang_installed[0]) . " " . strtolower($this->lng->txt("installed")) . ".";
00347                         }
00348                         else
00349                         {
00350                                 foreach ($lang_installed as $lang_key)
00351                                 {
00352                                         $langnames[] = $this->lng->txt("lang_" . $lang_key);
00353                                 }
00354                                 $this->data = implode(", ",$langnames) . " " . strtolower($this->lng->txt("installed")) . ".";
00355                         }
00356                 }
00357 
00358                 if (isset($local_installed))
00359                 {
00360                         if (count($local_installed) == 1)
00361                         {
00362                                 $this->data .= " " . $this->lng->txt("lang_" . $local_installed[0]) . " " . $this->lng->txt("local_language_file") . " " . strtolower($this->lng->txt("installed")) . ".";
00363                         }
00364                         else
00365                         {
00366                                 foreach ($local_installed as $lang_key)
00367                                 {
00368                                         $langnames[] = $this->lng->txt("lang_" . $lang_key);
00369                                 }
00370                                 $this->data .= " " . implode(", ",$langnames) . " " . $this->lng->txt("local_language_files") . " " . strtolower($this->lng->txt("installed")) . ".";
00371                         }
00372                 }
00373                 else
00374                 {
00375                         $this->data .= " " . $this->lng->txt("local_languages_already_installed");
00376                 }
00377 
00378                 $this->out();
00379         }
00380 
00381 
00385         function uninstallObject()
00386         {
00387                 if (!isset($_POST["id"]))
00388                 {
00389                         $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
00390                 }
00391 
00392                 // uninstall all selected languages
00393                 foreach ($_POST["id"] as $obj_id)
00394                 {
00395                         $langObj = new ilObjLanguage($obj_id);
00396                         if (!($sys_lang = $langObj->isSystemLanguage()))
00397                                 if (!($usr_lang = $langObj->isUserLanguage()))
00398                                 {
00399                                         $key = $langObj->uninstall();
00400                                         if ($key != "")
00401                                                 $lang_uninstalled[] = $key;
00402                                 }
00403                         unset($langObj);
00404                 }
00405 
00406                 // generate output message
00407                 if (isset($lang_uninstalled))
00408                 {
00409                         if (count($lang_uninstalled) == 1)
00410                         {
00411                                 $this->data = $this->lng->txt("lang_".$lang_uninstalled[0])." ".$this->lng->txt("uninstalled");
00412                         }
00413                         else
00414                         {
00415                                 foreach ($lang_uninstalled as $lang_key)
00416                                 {
00417                                         $langnames[] = $this->lng->txt("lang_".$lang_key);
00418                                 }
00419 
00420                                 $this->data = implode(", ",$langnames)." ".$this->lng->txt("uninstalled");
00421                         }
00422                 }
00423                 elseif ($sys_lang)
00424                 {
00425                         $this->data = $this->lng->txt("cannot_uninstall_systemlanguage");
00426                 }
00427                 elseif ($usr_lang)
00428                 {
00429                         $this->data = $this->lng->txt("cannot_uninstall_language_in_use");
00430                 }
00431                 else
00432                 {
00433                         $this->data = $this->lng->txt("languages_already_uninstalled");
00434                 }
00435 
00436                 $this->out();
00437         }
00438 
00442         function refreshObject()
00443         {
00444                 $languages = getObjectList("lng");
00445 
00446                 foreach ($languages as $lang)
00447                 {
00448                         $langObj = new ilObjLanguage($lang["obj_id"],false);
00449 
00450                         if ($langObj->isInstalled() == true)
00451                         {
00452                                 if ($langObj->check())
00453                                 {
00454                                         $langObj->flush();
00455                                         $langObj->insert();
00456                                         $langObj->setTitle($langObj->getKey());
00457                                         $langObj->setDescription($langObj->getStatus());
00458                                         $langObj->update();
00459                                         $langObj->optimizeData();
00460 
00461                                         if ($langObj->isLocal() == true)
00462                                         {
00463                                                 if ($langObj->check('local'))
00464                                                 {
00465                                                         $langObj->insert('local');
00466                                                         $langObj->setTitle($langObj->getKey());
00467                                                         $langObj->setDescription($langObj->getStatus());
00468                                                         $langObj->update();
00469                                                         $langObj->optimizeData();
00470                                                 }
00471                                         }
00472                                 }
00473                         }
00474 
00475                         unset($langObj);
00476                 }
00477 
00478                 $this->data = $this->lng->txt("languages_updated");
00479 
00480                 $this->out();
00481         }
00482 
00483 
00487         function setUserLanguageObject()
00488         {
00489                 require_once "classes/class.ilObjUser.php";
00490 
00491                 if (!isset($_POST["id"]))
00492                 {
00493                         $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
00494                 }
00495 
00496                 if (count($_POST["id"]) != 1)
00497                 {
00498                         $this->ilias->raiseError($this->lng->txt("choose_only_one_language")."<br/>".$this->lng->txt("action_aborted"),$this->ilias->error_obj->MESSAGE);
00499                 }
00500 
00501                 $obj_id = $_POST["id"][0];
00502 
00503                 $newUserLangObj = new ilObjLanguage($obj_id);
00504 
00505                 if ($newUserLangObj->isUserLanguage())
00506                 {
00507                         $this->ilias->raiseError($this->lng->txt("lang_".$newUserLangObj->getKey())." ".$this->lng->txt("is_already_your")." ".$this->lng->txt("user_language")."<br/>".$this->lng->txt("action_aborted"),$this->ilias->error_obj->MESSAGE);
00508                 }
00509 
00510                 if ($newUserLangObj->isInstalled() == false)
00511                 {
00512                         $this->ilias->raiseError($this->lng->txt("lang_".$newUserLangObj->getKey())." ".$this->lng->txt("language_not_installed")."<br/>".$this->lng->txt("action_aborted"),$this->ilias->error_obj->MESSAGE);
00513                 }
00514 
00515                 $curUser = new ilObjUser($_SESSION["AccountId"]);
00516                 $curUser->setLanguage($newUserLangObj->getKey());
00517                 $curUser->update();
00518                 //$this->setUserLanguage($new_lang_key);
00519 
00520                 $this->data = $this->lng->txt("user_language")." ".$this->lng->txt("changed_to")." ".$this->lng->txt("lang_".$newUserLangObj->getKey()).".";
00521 
00522                 $this->out();
00523         }
00524 
00525 
00529         function setSystemLanguageObject()
00530         {
00531                 if (!isset($_POST["id"]))
00532                 {
00533                         $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
00534                 }
00535 
00536                 if (count($_POST["id"]) != 1)
00537                 {
00538                         $this->ilias->raiseError($this->lng->txt("choose_only_one_language")."<br/>".$this->lng->txt("action_aborted"),$this->ilias->error_obj->MESSAGE);
00539                 }
00540 
00541                 $obj_id = $_POST["id"][0];
00542 
00543                 $newSysLangObj = new ilObjLanguage($obj_id);
00544 
00545                 if ($newSysLangObj->isSystemLanguage())
00546                 {
00547                         $this->ilias->raiseError($this->lng->txt("lang_".$newSysLangObj->getKey())." is already the system language!<br>Action aborted!",$this->ilias->error_obj->MESSAGE);
00548                 }
00549 
00550                 if ($newSysLangObj->isInstalled() == false)
00551                 {
00552                         $this->ilias->raiseError($this->lng->txt("lang_".$newSysLangObj->getKey())." is not installed. Please install that language first.<br>Action aborted!",$this->ilias->error_obj->MESSAGE);
00553                 }
00554 
00555                 $this->ilias->setSetting("language", $newSysLangObj->getKey());
00556 
00557                 // update ini-file
00558                 $this->ilias->ini->setVariable("language","default",$newSysLangObj->getKey());
00559                 $this->ilias->ini->write();
00560 
00561                 $this->data = $this->lng->txt("system_language")." ".$this->lng->txt("changed_to")." ".$this->lng->txt("lang_".$newSysLangObj->getKey()).".";
00562 
00563                 $this->out();
00564         }
00565 
00566 
00570         function checkLanguageObject()
00571         {
00572                 //$langFoldObj = new ilObjLanguageFolder($_GET["obj_id"]);
00573                 //$this->data = $langFoldObj->checkAllLanguages();
00574                 $this->data = $this->object->checkAllLanguages();
00575                 $this->out();
00576         }
00577 
00578 
00579         function out()
00580         {
00581                 sendInfo($this->data,true);
00582                 header("location: adm_object.php?ref_id=".$_GET["ref_id"]);
00583                 exit();
00584         }
00585 } // END class.LanguageFolderObjectOut
00586 ?>

Generated on Fri Dec 13 2013 10:18:28 for ILIAS Release_3_5_x_branch .rev 46805 by  doxygen 1.7.1