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->parseCurrentBlock();
00148
00149 }
00150
00151
00152 function setTemplateText ($s_lang, $s_proglang) {
00153 $this->tpl->setVariable ("TXT_CREATEFILE", $this->lng->txt("create_download_link"));
00154 $this->tpl->setVariable ("TXT_DOWNLOADTITLE", $this->lng->txt("cont_download_title"));
00155 $this->tpl->setVariable ("TXT_IMPORTFILE", $this->lng->txt("import_file"));
00156 $this->tpl->setVariable ("TXT_UPLOAD_BTN", $this->lng->txt("import"));
00157 $this->tpl->setVariable ("TXT_SUBCHARACTERISTIC", $this->lng->txt("cont_src"));
00158 $this->tpl->setVariable ("TXT_LANGUAGE", $this->lng->txt("language"));
00159 $this->tpl->setVariable ("TXT_SHOWLINENUMBERS", $this->lng->txt("cont_show_line_numbers"));
00160 $this->tpl->setVariable ("TXT_AUTOINDENT", $this->lng->txt("cont_autoindent"));
00161
00162
00163 $this->tpl->setVariable ("FORMACTION", $this->ctrl->getFormAction($this));
00164
00165 require_once("classes/class.ilMetaData.php");
00166 $lang = ilMetaData::getLanguages();
00167 $select_lang = ilUtil::formSelect ($s_lang,"par_language",$lang,false,true);
00168 $this->tpl->setVariable ("SELECT_LANGUAGE", $select_lang);
00169
00170 $prog_langs = $this->readProgLangs ();
00171
00172 $select_subchar = ilUtil::formSelect ($s_proglang, "par_subcharacteristic",$prog_langs,false,true);
00173 $this->tpl->setVariable ("SELECT_SUBCHARACTERISTIC", $select_subchar);
00174
00175 }
00176
00180 function insert()
00181 {
00182 global $ilUser;
00183
00184
00185 $this->setTabs();
00186
00187
00188 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.sourcecode_edit.html", "content");
00189 $this->tpl->setVariable("TXT_ACTION", $this->lng->txt("cont_insert_src"));
00190
00191 if ($this->pg_obj->getParentType() == "lm" ||
00192 $this->pg_obj->getParentType() == "dbk")
00193 {
00194 $this->tpl->setVariable("LINK_ILINK",
00195 $this->ctrl->getLinkTargetByClass("ilInternalLinkGUI", "showLinkHelp"));
00196 $this->tpl->setVariable("TXT_ILINK", "[".$this->lng->txt("cont_internal_link")."]");
00197 }
00198
00199 $this->displayValidationError();
00200
00201
00202
00203
00204
00205 if (key($_POST["cmd"]) == "create_src")
00206 {
00207 $s_lang = $_POST["par_language"];
00208 $s_subchar = $_POST["par_subcharacteristic"];
00209 $s_downloadtitle = $_POST["par_downloadtitle"];
00210 $s_showlinenumbers = strcmp($_POST["par_showlinenumbers"],'on')==0?'checked=\"true\"':'';
00211 $s_autoindent = strcmp($_POST["par_autoindent"],'on')==0?'checked=\"true\"':'';
00212 $s_isexample = strcmp($_POST["par_isexample"],"on")==0?'checked=\"true\"':'';
00213 }
00214 else
00215 {
00216 if ($_SESSION["il_text_lang_".$_GET["ref_id"]] != "")
00217 {
00218 $s_lang = $_SESSION["il_text_lang_".$_GET["ref_id"]];
00219 }
00220 else
00221 {
00222 $s_lang = $ilUser->getLanguage();
00223 }
00224
00225 $s_showlinenumbers = 'CHECKED';
00226 $s_autoindent = 'CHECKED';
00227 $s_isexample = '';
00228 $s_subchar = '';
00229 }
00230
00231 $this->setTemplateText($s_lang, $s_subchar);
00232
00233 $this->tpl->setVariable("SHOWLINENUMBERS", $s_showlinenumbers);
00234 $this->tpl->setVariable("AUTOINDENT", $s_autoindent);
00235 $this->tpl->setVariable("DOWNLOAD_TITLE_VALUE", $s_downloadtitle);
00236 $this->tpl->setVariable("ISEXAMPLE", $s_isexample);
00237
00238
00239
00240
00241
00242
00243 $this->tpl->setVariable("PAR_TA_NAME", "par_content");
00244
00245 if (key($_POST["cmd"]) == "create_src")
00246 {
00247 $this->tpl->setVariable("PAR_TA_CONTENT", stripslashes($_POST["par_content"]));
00248 }
00249 else
00250 {
00251 $this->tpl->setVariable("PAR_TA_CONTENT", "");
00252 }
00253 $this->tpl->parseCurrentBlock();
00254
00255
00256 $this->tpl->setCurrentBlock("commands");
00257 $this->tpl->setVariable("BTN_NAME", "create_src");
00258 $this->tpl->setVariable("UPLOAD_BTN_NAME", "create_src");
00259 $this->tpl->setVariable("BTN_TEXT", $this->lng->txt("save"));
00260 $this->tpl->parseCurrentBlock();
00261
00262 }
00263
00264
00268 function update()
00269 {
00270 global $ilBench;
00271
00272 $ilBench->start("Editor","Paragraph_update");
00273
00274
00275 $this->content_obj->setLanguage($_POST["par_language"]);
00276 $this->content_obj->setCharacteristic($_POST["par_characteristic"]);
00277
00278
00279
00280
00281
00282 $this->content_obj->setLanguage($_POST["par_language"]);
00283 $this->content_obj->setSubCharacteristic($_POST["par_subcharacteristic"]);
00284 $this->content_obj->setDownloadTitle($_POST["par_downloadtitle"]);
00285 $this->content_obj->setShowLineNumbers(($_POST["par_showlinenumbers"]=="on")?"y":"n");
00286 $this->content_obj->setAutoIndent(($_POST["par_autoindent"]=="on")?"y":"n");
00287 $this->content_obj->setSubCharacteristic($_POST["par_subcharacteristic"]);
00288 $this->content_obj->setCharacteristic("Code");
00289
00290 $this->updated = $this->content_obj->setText($this->content_obj->input2xml(stripslashes($_POST["par_content"])));
00291
00292 if ($this->updated !== true)
00293 {
00294
00295 $ilBench->stop("Editor","Paragraph_update");
00296 $this->edit();
00297 return;
00298 }
00299
00300 $this->updated = $this->pg_obj->update();
00301
00302 $ilBench->stop("Editor","Paragraph_update");
00303
00304 if ($this->updated === true && $this->ctrl->getCmd () != "upload" )
00305 {
00306 $this->ctrl->returnToParent($this, "jump".$this->hier_id);
00307 }
00308 else
00309 {
00310 $this->edit();
00311 }
00312 }
00313
00317 function create()
00318 {
00319 $this->content_obj =& new ilPCParagraph($this->dom);
00320 $this->content_obj->create($this->pg_obj, $this->hier_id);
00321 $this->content_obj->setLanguage($_POST["par_language"]);
00322
00323 $_SESSION["il_text_lang_".$_GET["ref_id"]] = $_POST["par_language"];
00324
00325 $uploaded = $this->upload_source();
00326
00327 $this->content_obj->setCharacteristic ($_POST["par_characteristic"]);
00328 $this->content_obj->setSubCharacteristic($_POST["par_subcharacteristic"]);
00329 $this->content_obj->setDownloadTitle ($_POST["par_downloadtitle"]);
00330 $this->content_obj->setShowLineNumbers (($_POST["par_showlinenumbers"]=='on')?'y':'n');
00331 $this->content_obj->setCharacteristic ('Code');
00332 $this->content_obj->setAutoIndent (($_POST["par_indent"]=='on')?'y':'n');
00333
00334 if ($uploaded) {
00335 $this->insert ();
00336 return;
00337 }
00338
00339 $this->updated = $this->content_obj->setText($this->content_obj->input2xml($_POST["par_content"]));
00340
00341 if ($this->updated !== true)
00342 {
00343 $this->insert();
00344 return;
00345 }
00346
00347 $this->updated = $this->pg_obj->update();
00348
00349 if ($this->updated === true && !$uploaded)
00350 {
00351 $this->ctrl->returnToParent($this, "jump".$this->hier_id);
00352 }
00353 else
00354 {
00355 $this->insert ();
00356 }
00357 }
00358
00362 function setTabs()
00363 {
00364
00365 include_once("classes/class.ilTabsGUI.php");
00366 $tabs_gui =& new ilTabsGUI();
00367 $this->getTabs($tabs_gui);
00368 $this->tpl->setVariable("TABS", $tabs_gui->getHTML());
00369 }
00370
00376 function getTabs(&$tabs_gui)
00377 {
00378
00379 $tabs_gui->addTarget("cont_back",
00380 $this->ctrl->getParentReturn($this), "",
00381 "");
00382 }
00383
00384 function upload () {
00385 $this->upload_source();
00386 $this->update ();
00387 }
00388
00389 function upload_source () {
00390 if (isset($_FILES['userfile']['name']))
00391 {
00392 $userfile = $_FILES['userfile']['tmp_name'];
00393
00394 if ($userfile == "" || !is_uploaded_file($userfile))
00395 {
00396 $error_str = "<b>Error(s):</b><br>Upload error: file name must not be empty!";
00397 $this->tpl->setVariable("MESSAGE", $error_str);
00398 $this->content_obj->setText($this->content_obj->input2xml(stripslashes($_POST["par_content"])));
00399 return false;
00400 }
00401
00402 $_POST["par_content"] = file_get_contents($userfile);
00403 $_POST["par_downloadtitle"] = $_FILES['userfile']['name'];
00404 return true;
00405 }
00406
00407 return false;
00408 }
00409
00410
00411 function readProgLangs () {
00412 $prog_langs_ini = file ("syntax_highlight/php/admin/prog_langs.ini");
00413 $prog_langs = array ("" => $this->lng->txt("cont_src_other"));
00414 foreach ($prog_langs_ini as $prog_lang) {
00415 $prog_lang_prop = split (":", $prog_lang);
00416 if ($prog_lang_prop[2] == 1) {
00417 $prog_langs[$prog_lang_prop[0]] = $prog_lang_prop[1];
00418 }
00419 }
00420
00421 return $prog_langs;
00422 }
00423 }
00424 ?>