00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 require_once("./content/classes/Pages/class.ilPCParagraph.php");
00025 require_once("./content/classes/Pages/class.ilPageContentGUI.php");
00026
00037 class ilPCSourcecodeGUI extends ilPageContentGUI
00038 {
00039
00044 function ilPCSourcecodeGUI(&$a_pg_obj, &$a_content_obj, $a_hier_id)
00045 {
00046 parent::ilPageContentGUI($a_pg_obj, $a_content_obj, $a_hier_id);
00047 }
00048
00049
00053 function &executeCommand()
00054 {
00055
00056 $next_class = $this->ctrl->getNextClass($this);
00057
00058
00059 $cmd = $this->ctrl->getCmd();
00060
00061 switch($next_class)
00062 {
00063 default:
00064 $ret =& $this->$cmd();
00065 break;
00066 }
00067
00068 return $ret;
00069 }
00070
00074 function edit()
00075 {
00076
00077 $this->setTabs();
00078
00079 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.sourcecode_edit.html", "content");
00080
00081
00082 $this->tpl->setVariable("TXT_ACTION", $this->lng->txt("cont_edit_src"));
00083
00084 if ($this->pg_obj->getParentType() == "lm" ||
00085 $this->pg_obj->getParentType() == "dbk")
00086 {
00087 $this->tpl->setVariable("LINK_ILINK",
00088 $this->ctrl->getLinkTargetByClass("ilInternalLinkGUI", "showLinkHelp"));
00089 $this->tpl->setVariable("TXT_ILINK", "[".$this->lng->txt("cont_internal_link")."]");
00090 }
00091
00092 $this->displayValidationError();
00093
00094
00095 if (key($_POST["cmd"]) == "update")
00096 {
00097 $s_lang = $_POST["par_language"];
00098 $s_char = $_POST["par_characteristic"];
00099 $s_subchar = $_POST["par_subcharacteristic"];
00100 $s_downloadtitle = $_POST["par_downloadtitle"];
00101 $s_showlinenumbers = ($_POST["par_showlinenumbers"]=="on")?'y':'n';
00102 $s_autoindent = ($_POST["par_autoindent"]=="on")?'y':'n';
00103 }
00104 else
00105 {
00106 $s_lang = $this->content_obj->getLanguage();
00107 $s_char = $this->content_obj->getCharacteristic();
00108 $s_subchar = $this->content_obj->getSubCharacteristic();
00109 $s_downloadtitle = $this->content_obj->getDownloadTitle();
00110 $s_showlinenumbers = $this->content_obj->getShowLineNumbers();
00111 $s_autoindent = $this->content_obj->getAutoIndent ();
00112 }
00113
00114 $this->setTemplateText($s_lang, $s_subchar);
00115
00116 if (key($_POST["cmd"]) == "update")
00117 {
00118 $s_text = stripslashes($_POST["par_content"]);
00119 }
00120 else
00121 {
00122 $s_text = $this->content_obj->xml2output($this->content_obj->getText());
00123 }
00124
00125 $this->tpl->setVariable("PAR_TA_NAME", "par_content");
00126 $this->tpl->setVariable("PAR_TA_CONTENT", $s_text);
00127 $this->tpl->parseCurrentBlock();
00128
00129 if (strcmp($s_showlinenumbers,"y")==0)
00130 {
00131 $this->tpl->setVariable("SHOWLINENUMBERS", "checked=\"checked\"");
00132 }
00133
00134 if (strcmp($s_autoindent,"y") == 0)
00135 {
00136 $this->tpl->setVariable("AUTOINDENT", "checked=\"checked\"");
00137 }
00138
00139
00140 $this->tpl->setVariable("DOWNLOAD_TITLE_VALUE", $s_downloadtitle);
00141
00142
00143 $this->tpl->setCurrentBlock("commands");
00144 $this->tpl->setVariable("BTN_NAME", "update");
00145 $this->tpl->setVariable("UPLOAD_BTN_NAME", "upload");
00146 $this->tpl->setVariable("BTN_TEXT", $this->lng->txt("save"));
00147 $this->tpl->setVariable("BTN_CANCEL", "cancelUpdate");
00148 $this->tpl->setVariable("TXT_CANCEL", $this->lng->txt("cancel"));
00149 $this->tpl->parseCurrentBlock();
00150
00151 }
00152
00153
00154 function setTemplateText ($s_lang, $s_proglang) {
00155 $this->tpl->setVariable ("TXT_CREATEFILE", $this->lng->txt("create_download_link"));
00156 $this->tpl->setVariable ("TXT_DOWNLOADTITLE", $this->lng->txt("cont_download_title"));
00157 $this->tpl->setVariable ("TXT_IMPORTFILE", $this->lng->txt("import_file"));
00158 $this->tpl->setVariable ("TXT_UPLOAD_BTN", $this->lng->txt("import"));
00159 $this->tpl->setVariable ("TXT_SUBCHARACTERISTIC", $this->lng->txt("cont_src"));
00160 $this->tpl->setVariable ("TXT_LANGUAGE", $this->lng->txt("language"));
00161 $this->tpl->setVariable ("TXT_SHOWLINENUMBERS", $this->lng->txt("cont_show_line_numbers"));
00162 $this->tpl->setVariable ("TXT_AUTOINDENT", $this->lng->txt("cont_autoindent"));
00163
00164
00165 $this->tpl->setVariable ("FORMACTION", $this->ctrl->getFormAction($this));
00166
00167 require_once("classes/class.ilMetaData.php");
00168 $lang = ilMetaData::getLanguages();
00169 $select_lang = ilUtil::formSelect ($s_lang,"par_language",$lang,false,true);
00170 $this->tpl->setVariable ("SELECT_LANGUAGE", $select_lang);
00171
00172 $prog_langs = $this->readProgLangs ();
00173
00174 $select_subchar = ilUtil::formSelect ($s_proglang, "par_subcharacteristic",$prog_langs,false,true);
00175 $this->tpl->setVariable ("SELECT_SUBCHARACTERISTIC", $select_subchar);
00176
00177 }
00178
00182 function insert()
00183 {
00184 global $ilUser;
00185
00186
00187 $this->setTabs();
00188
00189
00190 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.sourcecode_edit.html", "content");
00191 $this->tpl->setVariable("TXT_ACTION", $this->lng->txt("cont_insert_src"));
00192
00193 if ($this->pg_obj->getParentType() == "lm" ||
00194 $this->pg_obj->getParentType() == "dbk")
00195 {
00196 $this->tpl->setVariable("LINK_ILINK",
00197 $this->ctrl->getLinkTargetByClass("ilInternalLinkGUI", "showLinkHelp"));
00198 $this->tpl->setVariable("TXT_ILINK", "[".$this->lng->txt("cont_internal_link")."]");
00199 }
00200
00201 $this->displayValidationError();
00202
00203
00204
00205
00206
00207 if (key($_POST["cmd"]) == "create_src")
00208 {
00209 $s_lang = $_POST["par_language"];
00210 $s_subchar = $_POST["par_subcharacteristic"];
00211 $s_downloadtitle = $_POST["par_downloadtitle"];
00212 $s_showlinenumbers = strcmp($_POST["par_showlinenumbers"],'on')==0?'checked=\"true\"':'';
00213 $s_autoindent = strcmp($_POST["par_autoindent"],'on')==0?'checked=\"true\"':'';
00214 $s_isexample = strcmp($_POST["par_isexample"],"on")==0?'checked=\"true\"':'';
00215 }
00216 else
00217 {
00218 if ($_SESSION["il_text_lang_".$_GET["ref_id"]] != "")
00219 {
00220 $s_lang = $_SESSION["il_text_lang_".$_GET["ref_id"]];
00221 }
00222 else
00223 {
00224 $s_lang = $ilUser->getLanguage();
00225 }
00226
00227 $s_showlinenumbers = 'CHECKED';
00228 $s_autoindent = 'CHECKED';
00229 $s_isexample = '';
00230 $s_subchar = '';
00231 }
00232
00233 $this->setTemplateText($s_lang, $s_subchar);
00234
00235 $this->tpl->setVariable("SHOWLINENUMBERS", $s_showlinenumbers);
00236 $this->tpl->setVariable("AUTOINDENT", $s_autoindent);
00237 $this->tpl->setVariable("DOWNLOAD_TITLE_VALUE", $s_downloadtitle);
00238 $this->tpl->setVariable("ISEXAMPLE", $s_isexample);
00239
00240
00241
00242
00243
00244
00245 $this->tpl->setVariable("PAR_TA_NAME", "par_content");
00246
00247 if (key($_POST["cmd"]) == "create_src")
00248 {
00249 $this->tpl->setVariable("PAR_TA_CONTENT", stripslashes($_POST["par_content"]));
00250 }
00251 else
00252 {
00253 $this->tpl->setVariable("PAR_TA_CONTENT", "");
00254 }
00255 $this->tpl->parseCurrentBlock();
00256
00257
00258 $this->tpl->setCurrentBlock("commands");
00259 $this->tpl->setVariable("BTN_NAME", "create_src");
00260 $this->tpl->setVariable("UPLOAD_BTN_NAME", "create_src");
00261 $this->tpl->setVariable("BTN_TEXT", $this->lng->txt("save"));
00262 $this->tpl->setVariable("BTN_CANCEL", "cancelCreate");
00263 $this->tpl->setVariable("TXT_CANCEL", $this->lng->txt("cancel"));
00264 $this->tpl->parseCurrentBlock();
00265
00266 }
00267
00268
00272 function update()
00273 {
00274 global $ilBench;
00275
00276 $ilBench->start("Editor","Paragraph_update");
00277
00278
00279 $this->content_obj->setLanguage($_POST["par_language"]);
00280 $this->content_obj->setCharacteristic($_POST["par_characteristic"]);
00281
00282
00283
00284
00285
00286 $this->content_obj->setLanguage($_POST["par_language"]);
00287 $this->content_obj->setSubCharacteristic($_POST["par_subcharacteristic"]);
00288 $this->content_obj->setDownloadTitle($_POST["par_downloadtitle"]);
00289 $this->content_obj->setShowLineNumbers(($_POST["par_showlinenumbers"]=="on")?"y":"n");
00290 $this->content_obj->setAutoIndent(($_POST["par_autoindent"]=="on")?"y":"n");
00291 $this->content_obj->setSubCharacteristic($_POST["par_subcharacteristic"]);
00292 $this->content_obj->setCharacteristic("Code");
00293
00294 $this->updated = $this->content_obj->setText($this->content_obj->input2xml(stripslashes($_POST["par_content"])));
00295
00296 if ($this->updated !== true)
00297 {
00298
00299 $ilBench->stop("Editor","Paragraph_update");
00300 $this->edit();
00301 return;
00302 }
00303
00304 $this->updated = $this->pg_obj->update();
00305
00306 $ilBench->stop("Editor","Paragraph_update");
00307
00308 if ($this->updated === true && $this->ctrl->getCmd () != "upload" )
00309 {
00310 $this->ctrl->returnToParent($this, "jump".$this->hier_id);
00311 }
00312 else
00313 {
00314 $this->edit();
00315 }
00316 }
00317
00321 function cancelUpdate()
00322 {
00323 $this->ctrl->returnToParent($this, "jump".$this->hier_id);
00324 }
00325
00329 function create()
00330 {
00331 $this->content_obj =& new ilPCParagraph($this->dom);
00332 $this->content_obj->create($this->pg_obj, $this->hier_id);
00333 $this->content_obj->setLanguage($_POST["par_language"]);
00334
00335 $_SESSION["il_text_lang_".$_GET["ref_id"]] = $_POST["par_language"];
00336
00337 $uploaded = $this->upload_source();
00338
00339 $this->content_obj->setCharacteristic ($_POST["par_characteristic"]);
00340 $this->content_obj->setSubCharacteristic($_POST["par_subcharacteristic"]);
00341 $this->content_obj->setDownloadTitle ($_POST["par_downloadtitle"]);
00342 $this->content_obj->setShowLineNumbers (($_POST["par_showlinenumbers"]=='on')?'y':'n');
00343 $this->content_obj->setCharacteristic ('Code');
00344 $this->content_obj->setAutoIndent (($_POST["par_indent"]=='on')?'y':'n');
00345
00346 if ($uploaded) {
00347 $this->insert ();
00348 return;
00349 }
00350
00351 $this->updated = $this->content_obj->setText($this->content_obj->input2xml($_POST["par_content"]));
00352
00353 if ($this->updated !== true)
00354 {
00355 $this->insert();
00356 return;
00357 }
00358
00359 $this->updated = $this->pg_obj->update();
00360
00361 if ($this->updated === true && !$uploaded)
00362 {
00363 $this->ctrl->returnToParent($this, "jump".$this->hier_id);
00364 }
00365 else
00366 {
00367 $this->insert ();
00368 }
00369 }
00370
00374 function cancelCreate()
00375 {
00376 $this->ctrl->returnToParent($this, "jump".$this->hier_id);
00377 }
00378
00379
00383 function setTabs()
00384 {
00385 global $ilTabs;
00386
00387 #include_once("classes/class.ilTabsGUI.php");
00388 #$tabs_gui =& new ilTabsGUI();
00389 $this->getTabs($ilTabs);
00390 #$this->tpl->setVariable("TABS", $tabs_gui->getHTML());
00391 }
00392
00398 function getTabs(&$tabs_gui)
00399 {
00400
00401
00402
00403
00404
00405
00406 }
00407
00408 function upload () {
00409 $this->upload_source();
00410 $this->update ();
00411 }
00412
00413 function upload_source () {
00414 if (isset($_FILES['userfile']['name']))
00415 {
00416 $userfile = $_FILES['userfile']['tmp_name'];
00417
00418 if ($userfile == "" || !is_uploaded_file($userfile))
00419 {
00420 $error_str = "<b>Error(s):</b><br>Upload error: file name must not be empty!";
00421 $this->tpl->setVariable("MESSAGE", $error_str);
00422 $this->content_obj->setText($this->content_obj->input2xml(stripslashes($_POST["par_content"])));
00423 return false;
00424 }
00425
00426 $_POST["par_content"] = file_get_contents($userfile);
00427 $_POST["par_downloadtitle"] = $_FILES['userfile']['name'];
00428 return true;
00429 }
00430
00431 return false;
00432 }
00433
00434
00435 function readProgLangs () {
00436 $prog_langs_ini = file ("syntax_highlight/php/admin/prog_langs.ini");
00437 $prog_langs = array ("" => $this->lng->txt("cont_src_other"));
00438 foreach ($prog_langs_ini as $prog_lang) {
00439 $prog_lang_prop = split (":", $prog_lang);
00440 if ($prog_lang_prop[2] == 1) {
00441 $prog_langs[$prog_lang_prop[0]] = $prog_lang_prop[1];
00442 }
00443 }
00444
00445 return $prog_langs;
00446 }
00447 }
00448 ?>