ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 */
3 require_once("./Services/Object/classes/class.ilObjectTranslationTableGUI.php");
17  protected $ctrl;
21  public $tpl;
25  protected $ilAccess;
29  protected $lng;
33  protected $ilObjOrgUnitGui;
37  protected $ilObjectOrgUnit;
38 
39 
40  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  {
64  ilUtil::sendFailure($this->lng->txt("permission_denied"), true);
65  $this->ctrl->redirect($this->parent_gui, "");
66  }
67  }
68 
69  public function executeCommand()
70  {
71  $cmd = $this->ctrl->getCmd();
72  $this->$cmd();
73  }
74 
75 
76  public function editTranslations($a_get_post_values = false, $a_add = false)
77  {
78  $this->lng->loadLanguageModule($this->ilObjectOrgUnit->getType());
79 
80  $table = new ilObjectTranslationTableGUI($this, "editTranslations", true,
81  "Translation");
82  if ($a_get_post_values)
83  {
84  $vals = array();
85  foreach($_POST["title"] as $k => $v)
86  {
87  $vals[] = array("title" => $v,
88  "desc" => $_POST["desc"][$k],
89  "lang" => $_POST["lang"][$k],
90  "default" => ($_POST["default"] == $k));
91  }
92  $table->setData($vals);
93  }
94  else
95  {
96  $data = $this->ilObjectOrgUnit->getTranslations();
97  foreach($data["Fobject"] as $k => $v)
98  {
99  $data["Fobject"][$k]["default"] = ($k == $data["default_language"]);
100  }
101  if($a_add)
102  {
103  $data["Fobject"][++$k]["title"] = "";
104  }
105  $table->setData($data["Fobject"]);
106  }
107  $this->tpl->setContent($table->getHTML());
108  }
109 
110 
114  function saveTranslations()
115  {
116  // default language set?
117  if (!isset($_POST["default"]))
118  {
119  ilUtil::sendFailure($this->lng->txt("msg_no_default_language"));
120  return $this->editTranslations(true);
121  }
122 
123  // all languages set?
124  if (array_key_exists("",$_POST["lang"]))
125  {
126  ilUtil::sendFailure($this->lng->txt("msg_no_language_selected"));
127  return $this->editTranslations(true);
128  }
129 
130  // no single language is selected more than once?
131  if (count(array_unique($_POST["lang"])) < count($_POST["lang"]))
132  {
133  ilUtil::sendFailure($this->lng->txt("msg_multi_language_selected"));
134  return $this->editTranslations(true);
135  }
136 
137  // save the stuff
138  $this->ilObjectOrgUnit->removeTranslations();
139  foreach($_POST["title"] as $k => $v)
140  {
141  // update object data if default
142  $is_default = ($_POST["default"] == $k);
143  if($is_default)
144  {
145  $this->ilObjectOrgUnit->setTitle(ilUtil::stripSlashes($v));
146  $this->ilObjectOrgUnit->setDescription(ilUtil::stripSlashes($_POST["desc"][$k]));
147  $this->ilObjectOrgUnit->update();
148  }
149 
150  $this->ilObjectOrgUnit->addTranslation(
152  ilUtil::stripSlashes($_POST["desc"][$k]),
153  ilUtil::stripSlashes($_POST["lang"][$k]),
154  $is_default);
155  }
156 
157  ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
158  $this->ctrl->redirect($this, "editTranslations");
159  }
160 
164  function addTranslation()
165  {
166 
167  if($_POST["title"])
168  {
169  $k = max(array_keys($_POST["title"]));
170  $k++;
171  $_POST["title"][$k] = "";
172  $this->editTranslations(true);
173  }
174  else
175  {
176  $this->editTranslations(false, true);
177  }
178  }
179 
184  {
185  foreach($_POST["title"] as $k => $v)
186  {
187  if ($_POST["check"][$k])
188  {
189  // default translation cannot be deleted
190  if($k != $_POST["default"])
191  {
192  unset($_POST["title"][$k]);
193  unset($_POST["desc"][$k]);
194  unset($_POST["lang"][$k]);
195  }
196  else
197  {
198  ilUtil::sendFailure($this->lng->txt("msg_no_default_language"));
199  return $this->editTranslations();
200  }
201  }
202  }
203  $this->saveTranslations();
204  }
205 }
206 ?>
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
saveTranslations()
Save title and translations.
$cmd
Definition: sahs_server.php:35
editTranslations($a_get_post_values=false, $a_add=false)
Class ilObjOrgUnit GUI class.
deleteTranslations()
Remove translation.
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
Create styles array
The data for the language used.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
TableGUI class for title/description translations.
global $ilDB
global $DIC
$_POST["username"]