ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilTranslationGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
13 {
17  protected $ctrl;
21  public $tpl;
25  protected $ilAccess;
29  protected $lng;
33  protected $ilObjOrgUnitGui;
37  protected $ilObjectOrgUnit;
38 
39 
40  public function __construct(ilObjOrgUnitGUI $ilObjOrgUnitGUI)
41  {
42  global $DIC;
43  $tpl = $DIC['tpl'];
44  $ilCtrl = $DIC['ilCtrl'];
45  $ilDB = $DIC['ilDB'];
46  $lng = $DIC['lng'];
47  $ilAccess = $DIC['ilAccess'];
53  $this->tpl = $tpl;
54  $this->ctrl = $ilCtrl;
55  $this->lng = $lng;
56  $this->ilObjOrgUnitGui = $ilObjOrgUnitGUI;
57  $this->ilObjectOrgUnit = $ilObjOrgUnitGUI->object;
58  $this->ilAccess = $ilAccess;
59 
60 
61 
62  if (!$ilAccess->checkAccess('write', '', $this->ilObjectOrgUnit->getRefId())) {
63  ilUtil::sendFailure($this->lng->txt("permission_denied"), true);
64  $this->ctrl->redirect($this->parent_gui, "");
65  }
66  }
67 
68  public function executeCommand()
69  {
70  $cmd = $this->ctrl->getCmd();
71  $this->$cmd();
72  }
73 
74 
75  public function editTranslations($a_get_post_values = false, $a_add = false)
76  {
77  $this->lng->loadLanguageModule($this->ilObjectOrgUnit->getType());
78 
80  $this,
81  "editTranslations",
82  true,
83  "Translation"
84  );
85  if ($a_get_post_values) {
86  $vals = array();
87  foreach ($_POST["title"] as $k => $v) {
88  $vals[] = array("title" => $v,
89  "desc" => $_POST["desc"][$k],
90  "lang" => $_POST["lang"][$k],
91  "default" => ($_POST["default"] == $k));
92  }
93  $table->setData($vals);
94  } else {
95  $data = $this->ilObjectOrgUnit->getTranslations();
96  foreach ($data["Fobject"] as $k => $v) {
97  $data["Fobject"][$k]["default"] = ($k == $data["default_language"]);
98  }
99  if ($a_add) {
100  $data["Fobject"][++$k]["title"] = "";
101  }
102  $table->setData($data["Fobject"]);
103  }
104  $this->tpl->setContent($table->getHTML());
105  }
106 
107 
111  public function saveTranslations()
112  {
113  // default language set?
114  if (!isset($_POST["default"])) {
115  ilUtil::sendFailure($this->lng->txt("msg_no_default_language"));
116  return $this->editTranslations(true);
117  }
118 
119  // all languages set?
120  if (array_key_exists("", $_POST["lang"])) {
121  ilUtil::sendFailure($this->lng->txt("msg_no_language_selected"));
122  return $this->editTranslations(true);
123  }
124 
125  // no single language is selected more than once?
126  if (count(array_unique($_POST["lang"])) < count($_POST["lang"])) {
127  ilUtil::sendFailure($this->lng->txt("msg_multi_language_selected"));
128  return $this->editTranslations(true);
129  }
130 
131  // save the stuff
132  $this->ilObjectOrgUnit->removeTranslations();
133  foreach ($_POST["title"] as $k => $v) {
134  // update object data if default
135  $is_default = ($_POST["default"] == $k);
136  if ($is_default) {
137  $this->ilObjectOrgUnit->setTitle(ilUtil::stripSlashes($v));
138  $this->ilObjectOrgUnit->setDescription(ilUtil::stripSlashes($_POST["desc"][$k]));
139  $this->ilObjectOrgUnit->update();
140  }
141 
142  $this->ilObjectOrgUnit->addTranslation(
144  ilUtil::stripSlashes($_POST["desc"][$k]),
145  ilUtil::stripSlashes($_POST["lang"][$k]),
146  $is_default
147  );
148  }
149 
150  ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
151  $this->ctrl->redirect($this, "editTranslations");
152  }
153 
157  public function addTranslation()
158  {
159  if ($_POST["title"]) {
160  $k = max(array_keys($_POST["title"]));
161  $k++;
162  $_POST["title"][$k] = "";
163  $this->editTranslations(true);
164  } else {
165  $this->editTranslations(false, true);
166  }
167  }
168 
172  public function deleteTranslations()
173  {
174  foreach ($_POST["title"] as $k => $v) {
175  if ($_POST["check"][$k]) {
176  // default translation cannot be deleted
177  if ($k != $_POST["default"]) {
178  unset($_POST["title"][$k]);
179  unset($_POST["desc"][$k]);
180  unset($_POST["lang"][$k]);
181  } else {
182  ilUtil::sendFailure($this->lng->txt("msg_no_default_language"));
183  return $this->editTranslations();
184  }
185  }
186  }
187  $this->saveTranslations();
188  }
189 }
global $DIC
Definition: saml.php:7
saveTranslations()
Save title and translations.
editTranslations($a_get_post_values=false, $a_add=false)
Class ilObjOrgUnit GUI class.
deleteTranslations()
Remove translation.
Class ilAccessHandler.
global $ilCtrl
Definition: ilias.php:18
Class ilTranslationGUI.
addTranslation()
Add a translation.
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
TableGUI class for title/description translations.
global $ilDB
if(empty($password)) $table
Definition: pwgen.php:24
$_POST["username"]
$data
Definition: bench.php:6