• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

content/classes/Pages/class.ilPCSourcecodeGUI.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003         +-----------------------------------------------------------------------------+
00004         | ILIAS open source                                                           |
00005         +-----------------------------------------------------------------------------+
00006         | Copyright (c) 1998-2001 ILIAS open source, University of Cologne            |
00007         |                                                                             |
00008         | This program is free software; you can redistribute it and/or               |
00009         | modify it under the terms of the GNU General Public License                 |
00010         | as published by the Free Software Foundation; either version 2              |
00011         | of the License, or (at your option) any later version.                      |
00012         |                                                                             |
00013         | This program is distributed in the hope that it will be useful,             |
00014         | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
00015         | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
00016         | GNU General Public License for more details.                                |
00017         |                                                                             |
00018         | You should have received a copy of the GNU General Public License           |
00019         | along with this program; if not, write to the Free Software                 |
00020         | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. |
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                 // get next class that processes or forwards current command
00056                 $next_class = $this->ctrl->getNextClass($this);
00057 
00058                 // get current command
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                 // set tabs
00077                 $this->setTabs();
00078 
00079                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.sourcecode_edit.html", "content");
00080                 //$content = $this->pg_obj->getContent();
00081                 //$cnt = 1;
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                 // language and characteristic selection
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                 // operations
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                 // set tabs
00187                 $this->setTabs();
00188 
00189                 // add paragraph edit template
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                 // get values from new object (repeated form display on error)
00204                 
00205                 //echo key ($_POST["cmd"]);
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                 // content is in utf-8, todo: set globally
00242                 // header('Content-type: text/html; charset=UTF-8');
00243 
00244                 // input text area
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                 // operations
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                 // set language and characteristic
00278                 
00279                 $this->content_obj->setLanguage($_POST["par_language"]);
00280                 $this->content_obj->setCharacteristic($_POST["par_characteristic"]);
00281 
00282                 //echo "PARupdate:".htmlentities($this->content_obj->input2xml($_POST["par_content"])).":<br>"; exit;
00283 
00284                  
00285                 // set language and characteristic
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                         //echo "Did not update!";
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                 // catch feedback message
00386                 include_once("classes/class.ilTabsGUI.php");
00387                 $tabs_gui =& new ilTabsGUI();
00388                 $this->getTabs($tabs_gui);
00389                 $this->tpl->setVariable("TABS", $tabs_gui->getHTML());
00390         }
00391 
00397         function getTabs(&$tabs_gui)
00398         {
00399                 // back to upper context
00400                 /*
00401                 $tabs_gui->addTarget("cont_back",
00402                         $this->ctrl->getParentReturn($this), "",
00403                         "");
00404                 */
00405         }
00406 
00407         function upload () {
00408                 $this->upload_source();
00409                 $this->update ();
00410         }
00411                 
00412         function upload_source () {             
00413                 if (isset($_FILES['userfile']['name']))
00414                 {
00415                         $userfile = $_FILES['userfile']['tmp_name'];
00416                         
00417                         if ($userfile == "" || !is_uploaded_file($userfile))
00418                         {
00419                                 $error_str = "<b>Error(s):</b><br>Upload error: file name must not be empty!";
00420                                 $this->tpl->setVariable("MESSAGE", $error_str);
00421                                 $this->content_obj->setText($this->content_obj->input2xml(stripslashes($_POST["par_content"])));
00422                                 return false;
00423                         }
00424 
00425                         $_POST["par_content"] = file_get_contents($userfile);                                                           
00426                         $_POST["par_downloadtitle"] = $_FILES['userfile']['name'];                      
00427                         return true;
00428                 }                               
00429                 
00430                 return false;
00431         } 
00432         
00433         
00434         function readProgLangs () {
00435                 $prog_langs_ini = file ("syntax_highlight/php/admin/prog_langs.ini");
00436                 $prog_langs = array ("" => $this->lng->txt("cont_src_other"));
00437                 foreach ($prog_langs_ini as $prog_lang) {
00438                         $prog_lang_prop = split (":", $prog_lang);
00439                         if ($prog_lang_prop[2] == 1) {
00440                                 $prog_langs[$prog_lang_prop[0]] = $prog_lang_prop[1];
00441                         }
00442                 }
00443                 
00444                 return $prog_langs;
00445         }       
00446 }
00447 ?>

Generated on Fri Dec 13 2013 10:18:30 for ILIAS Release_3_5_x_branch .rev 46805 by  doxygen 1.7.1