ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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 */
3require_once("./Services/Object/classes/class.ilObjectTranslationTableGUI.php");
17 protected $ctrl;
21 public $tpl;
25 protected $ilAccess;
29 protected $lng;
38
39
40 function __construct(ilObjOrgUnitGUI $ilObjOrgUnitGUI)
41 {
42 global $tpl, $ilCtrl, $ilDB, $lng, $ilAccess;
48 $this->tpl = $tpl;
49 $this->ctrl = $ilCtrl;
50 $this->lng = $lng;
51 $this->ilObjOrgUnitGui = $ilObjOrgUnitGUI;
52 $this->ilObjectOrgUnit = $ilObjOrgUnitGUI->object;
53 $this->ilAccess = $ilAccess;
54
55
56
57 if(!$ilAccess->checkAccess('write', '',$this->ilObjectOrgUnit->getRefId()))
58 {
59 ilUtil::sendFailure($this->lng->txt("permission_denied"), true);
60 $this->ctrl->redirect($this->parent_gui, "");
61 }
62 }
63
64 public function executeCommand()
65 {
66 $cmd = $this->ctrl->getCmd();
67 $this->$cmd();
68 }
69
70
71 public function editTranslations($a_get_post_values = false, $a_add = false)
72 {
73 $this->lng->loadLanguageModule($this->ilObjectOrgUnit->getType());
74
75 $table = new ilObjectTranslationTableGUI($this, "editTranslations", true,
76 "Translation");
77 if ($a_get_post_values)
78 {
79 $vals = array();
80 foreach($_POST["title"] as $k => $v)
81 {
82 $vals[] = array("title" => $v,
83 "desc" => $_POST["desc"][$k],
84 "lang" => $_POST["lang"][$k],
85 "default" => ($_POST["default"] == $k));
86 }
87 $table->setData($vals);
88 }
89 else
90 {
91 $data = $this->ilObjectOrgUnit->getTranslations();
92 foreach($data["Fobject"] as $k => $v)
93 {
94 $data["Fobject"][$k]["default"] = ($k == $data["default_language"]);
95 }
96 if($a_add)
97 {
98 $data["Fobject"][++$k]["title"] = "";
99 }
100 $table->setData($data["Fobject"]);
101 }
102 $this->tpl->setContent($table->getHTML());
103 }
104
105
110 {
111 // default language set?
112 if (!isset($_POST["default"]))
113 {
114 ilUtil::sendFailure($this->lng->txt("msg_no_default_language"));
115 return $this->editTranslations(true);
116 }
117
118 // all languages set?
119 if (array_key_exists("",$_POST["lang"]))
120 {
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 {
128 ilUtil::sendFailure($this->lng->txt("msg_multi_language_selected"));
129 return $this->editTranslations(true);
130 }
131
132 // save the stuff
133 $this->ilObjectOrgUnit->removeTranslations();
134 foreach($_POST["title"] as $k => $v)
135 {
136 // update object data if default
137 $is_default = ($_POST["default"] == $k);
138 if($is_default)
139 {
140 $this->ilObjectOrgUnit->setTitle(ilUtil::stripSlashes($v));
141 $this->ilObjectOrgUnit->setDescription(ilUtil::stripSlashes($_POST["desc"][$k]));
142 $this->ilObjectOrgUnit->update();
143 }
144
145 $this->ilObjectOrgUnit->addTranslation(
147 ilUtil::stripSlashes($_POST["desc"][$k]),
148 ilUtil::stripSlashes($_POST["lang"][$k]),
149 $is_default);
150 }
151
152 ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
153 $this->ctrl->redirect($this, "editTranslations");
154 }
155
159 function addTranslation()
160 {
161
162 if($_POST["title"])
163 {
164 $k = max(array_keys($_POST["title"]));
165 $k++;
166 $_POST["title"][$k] = "";
167 $this->editTranslations(true);
168 }
169 else
170 {
171 $this->editTranslations(false, true);
172 }
173 }
174
179 {
180 foreach($_POST["title"] as $k => $v)
181 {
182 if ($_POST["check"][$k])
183 {
184 // default translation cannot be deleted
185 if($k != $_POST["default"])
186 {
187 unset($_POST["title"][$k]);
188 unset($_POST["desc"][$k]);
189 unset($_POST["lang"][$k]);
190 }
191 else
192 {
193 ilUtil::sendFailure($this->lng->txt("msg_no_default_language"));
194 return $this->editTranslations();
195 }
196 }
197 }
198 $this->saveTranslations();
199 }
200}
201?>
Class ilObjOrgUnit GUI class.
TableGUI class for title/description translations.
Class ilTranslationGUI.
editTranslations($a_get_post_values=false, $a_add=false)
addTranslation()
Add a translation.
deleteTranslations()
Remove translation.
saveTranslations()
Save title and translations.
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
$_POST['username']
Definition: cron.php:12
$data
global $ilCtrl
Definition: ilias.php:18
$cmd
Definition: sahs_server.php:35
global $ilDB