ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilPCSourceCodeGUI.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
4
5require_once("./Services/COPage/classes/class.ilPCSourceCode.php");
6require_once("./Services/COPage/classes/class.ilPageContentGUI.php");
7
19{
20
25 function ilPCSourceCodeGUI($a_pg_obj, $a_content_obj, $a_hier_id, $a_pc_id = "")
26 {
27 parent::ilPageContentGUI($a_pg_obj, $a_content_obj, $a_hier_id, $a_pc_id);
28 }
29
30
34 function &executeCommand()
35 {
36 // get next class that processes or forwards current command
37 $next_class = $this->ctrl->getNextClass($this);
38
39 // get current command
40 $cmd = $this->ctrl->getCmd();
41
42 switch($next_class)
43 {
44 default:
45 $ret =& $this->$cmd();
46 break;
47 }
48
49 return $ret;
50 }
51
55 function edit()
56 {
57 $form = $this->initPropertyForm($this->lng->txt("cont_edit_src"), "update", "cancelCreate");
58
59 if ($this->pg_obj->getParentType() == "lm" ||
60 $this->pg_obj->getParentType() == "dbk")
61 {
62 $this->tpl->setVariable("LINK_ILINK",
63 $this->ctrl->getLinkTargetByClass("ilInternalLinkGUI", "showLinkHelp"));
64 $this->tpl->setVariable("TXT_ILINK", "[".$this->lng->txt("cont_internal_link")."]");
65 }
66
68
69 if (key($_POST["cmd"]) == "update")
70 {
71 $form->setValuesByPost();
72
73 }
74 else{
75 $form->getItemByPostVar("par_language")->setValue($this->content_obj->getLanguage());
76 $form->getItemByPostVar("par_subcharacteristic")->setValue($this->content_obj->getSubCharacteristic());
77 $form->getItemByPostVar("par_downloadtitle")->setValue( $this->content_obj->getDownloadTitle());
78 $form->getItemByPostVar("par_showlinenumbers")->setChecked(
79 $this->content_obj->getShowLineNumbers()=="y"?true:false);
80 $form->getItemByPostVar("par_autoindent")->setChecked(
81 $this->content_obj->getAutoIndent()=="y"?true:false);
82
83 $par_content = $this->content_obj->xml2output($this->content_obj->getText());
84
85 //TODO: Find a better way to convert back curly brackets
86 $par_content = str_replace("&#123;","{", $par_content);
87 $par_content = str_replace("&#125;","}", $par_content);
88
89 $form->getItemByPostVar("par_content")->setValue($par_content);
90 }
91
92
93 $this->tpl->setContent($form->getHTML());
94 }
95
99 function insert()
100 {
101 global $ilUser;
102
103 $form = $this->initPropertyForm($this->lng->txt("cont_insert_src"), "create_src", "cancelCreate");
104
105 if ($this->pg_obj->getParentType() == "lm" ||
106 $this->pg_obj->getParentType() == "dbk")
107 {
108 $this->tpl->setVariable("LINK_ILINK",
109 $this->ctrl->getLinkTargetByClass("ilInternalLinkGUI", "showLinkHelp"));
110 $this->tpl->setVariable("TXT_ILINK", "[".$this->lng->txt("cont_internal_link")."]");
111 }
112
113 $this->displayValidationError();
114
115 if (key($_POST["cmd"]) == "create_src")
116 {
117 $form->setValuesByPost();
118
119 }
120 else{
121 if ($_SESSION["il_text_lang_".$_GET["ref_id"]] != "")
122 {
123 $form->getItemByPostVar("par_language")->setValue($_SESSION["il_text_lang_".$_GET["ref_id"]]);
124 }
125 else
126 {
127 $form->getItemByPostVar("par_language")->setValue($ilUser->getLanguage());
128 }
129
130 $form->getItemByPostVar("par_showlinenumbers")->setChecked(true);
131 $form->getItemByPostVar("par_autoindent")->setChecked(true);
132 $form->getItemByPostVar("par_subcharacteristic")->setValue("");
133 $form->getItemByPostVar("par_content")->setValue("");
134 }
135
136 $this->tpl->setContent($form->getHTML());
137 }
138
139
143 function update()
144 {
145 global $ilBench;
146
147 $this->upload_source();
148
149 $ilBench->start("Editor","Paragraph_update");
150 // set language and characteristic
151
152 $this->content_obj->setLanguage($_POST["par_language"]);
153 $this->content_obj->setCharacteristic($_POST["par_characteristic"]);
154
155 //echo "PARupdate:".htmlentities($this->content_obj->input2xml($_POST["par_content"])).":<br>"; exit;
156
157
158 // set language and characteristic
159 $this->content_obj->setLanguage($_POST["par_language"]);
160 $this->content_obj->setSubCharacteristic($_POST["par_subcharacteristic"]);
161 $this->content_obj->setDownloadTitle(str_replace('"', '', ilUtil::stripSlashes($_POST["par_downloadtitle"])));
162 $this->content_obj->setShowLineNumbers($_POST["par_showlinenumbers"]?"y":"n");
163 $this->content_obj->setAutoIndent($_POST["par_autoindent"]?"y":"n");
164 $this->content_obj->setSubCharacteristic($_POST["par_subcharacteristic"]);
165 $this->content_obj->setCharacteristic("Code");
166
167 $this->updated = $this->content_obj->setText(
168 $this->content_obj->input2xml($_POST["par_content"], 0, false));
169
170 if ($this->updated !== true)
171 {
172 //echo "Did not update!";
173 $ilBench->stop("Editor","Paragraph_update");
174 $this->edit();
175 return;
176 }
177
178 $this->updated = $this->pg_obj->update();
179
180 $ilBench->stop("Editor","Paragraph_update");
181
182 if ($this->updated === true && $this->ctrl->getCmd () != "upload" )
183 {
184 $this->ctrl->returnToParent($this, "jump".$this->hier_id);
185 }
186 else
187 {
188 $this->edit();
189 }
190 }
191
195 function cancelUpdate()
196 {
197 $this->ctrl->returnToParent($this, "jump".$this->hier_id);
198 }
199
203 function create()
204 {
205 $this->content_obj = new ilPCSourceCode($this->getPage());
206 $this->content_obj->create($this->pg_obj, $this->hier_id, $this->pc_id);
207 $this->content_obj->setLanguage($_POST["par_language"]);
208
209 $_SESSION["il_text_lang_".$_GET["ref_id"]] = $_POST["par_language"];
210
211 $uploaded = $this->upload_source();
212
213 $this->content_obj->setCharacteristic ($_POST["par_characteristic"]);
214 $this->content_obj->setSubCharacteristic($_POST["par_subcharacteristic"]);
215 $this->content_obj->setDownloadTitle (str_replace('"', '', ilUtil::stripSlashes($_POST["par_downloadtitle"])));
216 $this->content_obj->setShowLineNumbers ($_POST["par_showlinenumbers"]?'y':'n');
217 $this->content_obj->setCharacteristic ('Code');
218 $this->content_obj->setAutoIndent ($_POST["par_autoindent"]?'y':'n');
219
220 if ($uploaded) {
221 $this->insert ();
222 return;
223 }
224
225 $this->updated = $this->content_obj->setText(
226 $this->content_obj->input2xml($_POST["par_content"], 0, false));
227
228 if ($this->updated !== true)
229 {
230 $this->insert();
231 return;
232 }
233
234 $this->updated = $this->pg_obj->update();
235
236 if ($this->updated === true && !$uploaded)
237 {
238 $this->ctrl->returnToParent($this, "jump".$this->hier_id);
239 }
240 else
241 {
242 $this->insert ();
243 }
244 }
245
249 function cancelCreate()
250 {
251 $this->ctrl->returnToParent($this, "jump".$this->hier_id);
252 }
253
254 function upload_source () {
255 if (isset($_FILES['userfile']['name']))
256 {
257 $userfile = $_FILES['userfile']['tmp_name'];
258
259 if ($userfile == "" || !is_uploaded_file($userfile))
260 {
261 $error_str = "<b>Error(s):</b><br>Upload error: file name must not be empty!";
262 $this->tpl->setVariable("MESSAGE", $error_str);
263 $this->content_obj->setText($this->content_obj->input2xml(stripslashes($_POST["par_content"]), 0, false));
264 return false;
265 }
266
267 $_POST["par_content"] = file_get_contents($userfile);
268 $_POST["par_downloadtitle"] = $_FILES['userfile']['name'];
269 return true;
270 }
271
272 return false;
273 }
274
275
276 function readProgLangs () {
277 $prog_langs_ini = file ("Services/COPage/syntax_highlight/php/admin/prog_langs.ini");
278 $prog_langs = array ("" => $this->lng->txt("cont_src_other"));
279 foreach ($prog_langs_ini as $prog_lang) {
280 $prog_lang_prop = split (":", $prog_lang);
281 if ($prog_lang_prop[2] == 1) {
282 $prog_langs[$prog_lang_prop[0]] = $prog_lang_prop[1];
283 }
284 }
285
286 return $prog_langs;
287 }
288
297 function initPropertyForm($a_title, $a_cmd, $a_cmd_cancel)
298 {
299
300 include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
301 $form = new ilPropertyFormGUI();
302 $form->setTitle($a_title);
303 $form->setFormAction($this->ctrl->getFormAction($this, $a_cmd));
304 $form->addCommandButton($a_cmd_cancel,$this->lng->txt("cancel"));
305 $form->addCommandButton($a_cmd,$this->lng->txt("save"));
306
307 require_once("Services/MetaData/classes/class.ilMDLanguageItem.php");
309 include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
310 $lang = new ilSelectInputGUI($this->lng->txt("language"),"par_language");
311 $lang->setOptions($lang_var);
312 $form->addItem($lang);
313
314 $prog_langs = $this->readProgLangs ();
315 $code_style = new ilSelectInputGUI( $this->lng->txt("cont_src"), "par_subcharacteristic");
316 $code_style->setOptions($prog_langs);
317 $form->addItem($code_style);
318 include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
319 $line_number = new ilCheckboxInputGUI($this->lng->txt("cont_show_line_numbers"), "par_showlinenumbers");
320 $form->addItem($line_number);
321 $indent = new ilCheckboxInputGUI($this->lng->txt("cont_autoindent"), "par_autoindent");
322 $form->addItem($indent);
323
324
325 include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
326 $code = new ilTextAreaInputGUI("", "par_content");
327 $code->setRows(12);
328 $form->addItem($code);
329
330 include_once("./Services/Form/classes/class.ilTextInputGUI.php");
331 $downlaod_title = new ilTextInputGUI($this->lng->txt("cont_download_title"), "par_downloadtitle");
332 $downlaod_title->setSize(40);
333 $form->addItem($downlaod_title);
334
335 include_once("./Services/Form/classes/class.ilFileInputGUI.php");
336 $file = new ilFileInputGUI($this->lng->txt("import_file"), "userfile");
337 $form->addItem($file);
338
339 return $form;
340 }
341}
print $file
$_GET["client_id"]
$_SESSION["AccountId"]
This class represents a checkbox property in a property form.
This class represents a file property in a property form.
Class ilPCSourcecodeGUI.
initPropertyForm($a_title, $a_cmd, $a_cmd_cancel)
initiates property form GUI class
insert()
insert paragraph form
create()
create new paragraph in dom and update page in db
update()
update paragraph in dom and update page in db
edit()
edit paragraph form
& executeCommand()
execute command
ilPCSourceCodeGUI($a_pg_obj, $a_content_obj, $a_hier_id, $a_pc_id="")
Constructor @access public.
cancelCreate()
cancel creating paragraph
Class ilPCSourceCode.
User Interface for Editing of Page Content Objects (Paragraphs, Tables, ...)
displayValidationError()
display validation errors
This class represents a property form user interface.
This class represents a selection list property in a property form.
This class represents a text area property in a property form.
This class represents a text property in a property form.
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
$_POST['username']
Definition: cron.php:12
$code
Definition: example_050.php:99
global $ilBench
Definition: ilias.php:18
$cmd
Definition: sahs_server.php:35
global $ilUser
Definition: imgupload.php:15