Source for file TMPL_CHAPTER.phpclass

Documentation is available at TMPL_CHAPTER.phpclass

  1. <?php
  2. /**
  3.   * Class file TMPL_CHAPTER.phpclass
  4.   *
  5.   * @project    Open CSP-Management
  6.   * @package    cms
  7.   * @category   templates-chapter
  8.   *
  9.   * @author     Peter Krebs <p.krebs@lvus.at>
  10.   * @copyright  (c) 2002-2003 by Peter Krebs and Landesverlag Unternehmensservice
  11.   * @license    http://opensource.org/licenses/gpl-license.php GNU Public License
  12.   *
  13.   ***/
  14.  
  15. require_once $GLOBALS['OCSP']['DEFAULTCONFPATH']."cms.conf.phpinc";
  16. require_once $GLOBALS['OCSP']['PHPINCPATH']."common/pcf.phpinc";
  17. require_once $GLOBALS['OCSP']['PHPINCPATH']."common/pcf_templates.phpinc";
  18. require_once $GLOBALS['OCSP']['PHPFORMPATH']."forms.phpinc";
  19. require_once $GLOBALS['OCSP_CMS']['PHPINCPATH']."cms_tableobj.phpclass"// <pk-06-11-09/> CMS -> OCSP_CMS
  20.  
  21. /**
  22.   * Handels chapter templates
  23.   *
  24.   * @project    Open CSP-Management
  25.   * @package    cms
  26.   * @category   templates-chapter
  27.   *
  28.   * @author     Peter Krebs <p.krebs@lvus.at>
  29.   * @copyright  (c) 2002-2003 by Peter Krebs and Landesverlag Unternehmensservice
  30.   * @license    http://opensource.org/licenses/gpl-license.php GNU Public License
  31.   *
  32.   * @version pk-03-10-21
  33.   *
  34.   ***/
  35. class TMPL_CHAPTER extends CMS_TABLEOBJ {
  36.     /**
  37.       * @staticvar  string  $myTable 
  38.       ***/
  39.     var $myTable        = "T_CMS_TMPL_CHAPTER";
  40.     /**
  41.       * @staticvar  string  $ptmplFld   the column name for the page template foreign key
  42.       ***/
  43.     var $ptmplFld       = "PTMP_ID";
  44.     /**
  45.       * @staticvar  string  $colPrevix   the column name for the chapter columns
  46.       ***/
  47.     var $colPrevix      = "CTMP_";
  48.     /**
  49.       * @staticvar  string  $contTable   the table holding the content
  50.       ***/
  51.     var $contTable      = "T_CMS_CHAPTER";
  52.  
  53.     /**
  54.       * @var array $tmplFields      db columns with template code to extract
  55.       ***/
  56.     var $tmplFields     = array("CTMP_HTMLCODE");
  57.     /**
  58.       * @var array $inputFields     array of DBMS_FIELD objects for the input form
  59.       ***/
  60.     var $inputFields    = array();
  61.  
  62.     /**
  63.       * @var string $myFrmFldTableName (table name set in dbms_formfields)
  64.       ***/
  65.     var $myFrmFldTableName="CHAPTER";
  66.  
  67.     /**
  68.       * @var string $classSrcFile source file of the class
  69.       * @since pk-05-02-02
  70.       ***/
  71.     var $myClassSrcFile=__FILE__;
  72.  
  73.     /**
  74.       * @var array $myFldValTypes array of allowed db types
  75.       * @since pk-05-02-02
  76.       ***/
  77.     var $myFldValTypes=array('string'=>'String','int'=>'Integer','float'=>'Number','blob'=>'Text');
  78.  
  79.     /**
  80.       * creates and inits and populates if all keys are set the object
  81.       *
  82.       * @param int      $projId     ID of the project - db foreign key
  83.       * @param int      $ptmpId     ID of the Page Template - db foreign key
  84.       * @param int      $aId        ID of the db COLUMN
  85.       * @param bool     $issep      is the chapter a layout element with no input
  86.       * @param int      $langId     language Id
  87.       *
  88.       * @version pk-05-02-02
  89.       ***/
  90.     function TMPL_CHAPTER($projId=0,$ptmpId=0,$aId=0,$issep=FALSE,$langId=0,$gDBIDX="USRDB"{
  91.         if ($GLOBALS['DEBUGMODE']echo "<p><b>TMPL_CHAPTER::TMPL_CHAPTER($projId,$ptmpId,$aId,$issep,$langId,$gDBIDX)</b>(".get_class($this).")</p>";
  92.         $this->init($gDBIDX);
  93.  
  94.         $this->db_SetKey('PROJ_ID',$projId);
  95.         $this->db_SetKey($this->ptmplFld,$ptmpId);
  96.         $this->db_SetKey('LANG_ID',intval($langId));
  97.  
  98.         if ($aId{
  99.             $this->db_SetKey($this->colPrevix."ID",$aId);
  100.             $this->dbPopulateDB($this->gDBIDX,$GLOBALS['DEBUGMODE']);
  101.         else {
  102.             $this->{$this->colPrevix."ISSEP"}=intval($issep);
  103.         }
  104.  
  105.     }
  106.  
  107.     /**
  108.       * returns the db ID-column value
  109.       *
  110.       * @return int 
  111.       *
  112.       * @version pk-03-10-19
  113.       *
  114.       ***/
  115.     function getId({
  116.         return intval($this->{$this->colPrevix."ID"});
  117.     }
  118.  
  119.     /**
  120.       * sets the db ID-column value
  121.       *
  122.       * @param int $aId 
  123.       *
  124.       * @version pk-03-12-14
  125.       * @since pk-03-12-14
  126.       *
  127.       ***/
  128.     function setId($aId{
  129.         $this->{$this->colPrevix."ID"}=intval($aId);
  130.     }
  131.  
  132.  
  133.     /**
  134.       * returns the page template id
  135.       *
  136.       * @retrun int
  137.       *
  138.       * @version pk-03-10-24
  139.       ***/
  140.     function getPTMPId({
  141.         return intval($this->{$this->ptmplFld});
  142.     }
  143.  
  144.     /**
  145.       * sets the page template id
  146.       *
  147.       * @param int $aId 
  148.       *
  149.       * @version pk-03-12-14
  150.       * @since pk-03-12-14
  151.       *
  152.       ***/
  153.     function setPTMPId($aId{
  154.         $this->{$this->ptmplFld$aId;
  155.     }
  156.  
  157.     /**
  158.       * returns a database form and hides some system fields
  159.       *
  160.       * @param int $mode 
  161.       * @param string $frmName 
  162.       * @param boolean $debug 
  163.       *
  164.       * @return DBMS_FORM 
  165.       *
  166.       * @since pk-05-03-20
  167.       *
  168.       ***/
  169.     function &dbGetForm($mode,$frmName="",$debug=FALSE)  {
  170.         if ($debugecho "<p><b>TMPL_CHAPTER::dbGetForm($mode,$frmName,...)</b> (".get_class($this).")</p>";
  171.  
  172.         if ($frmObj=parent::dbGetForm($mode,$frmName,$debug)) {
  173.             $frmObj->hideField($this->colPrevix."FIELDS");
  174.             $frmObj->hideField($this->colPrevix."FIELDSV2");
  175.             $frmObj->hideField($this->colPrevix."FIELDCLASSES");
  176.         }
  177.         return $frmObj;
  178.  
  179.     }
  180.  
  181.     /**
  182.       * sets the objects field data vars FIELD,FIELDCLASSES
  183.       *
  184.       * @param boolean $debug 
  185.       *
  186.       * @since pk-05-03-21
  187.       *
  188.       ***/
  189.     function setDBFieldDataCols($debug=FALSE{
  190.         if ($debugecho "<p><b>TMPL_CHAPTER::setDBFieldDataCols()</b> (".get_class($this).")</p><blockquote><div style=\"font-size:75%;line-height 1em;background-color: #c0c0c0;\">";
  191.  
  192.         $this->p_extractFields(FALSE,$debug);                               // check if all fields defined in the
  193.                                                                             // template(s) are in $this->inputFields
  194.  
  195.         $this->{$this->colPrevix."FIELDS"}=serialize($this->inputFields);   // serialize $this-inputFields
  196.  
  197.         $fldClasses=array();                                                // generate imploded field class list
  198.         if (is_array($this->inputFields)) {
  199.             foreach($this->inputFields as $fld$fldClasses[strtoupper(get_class($fld))]=TRUE;
  200.         }
  201.         $this->{$this->colPrevix."FIELDCLASSES"}="";
  202.         foreach($fldClasses as $key => $count$this->{$this->colPrevix."FIELDCLASSES"}.=$key.";";
  203.         if ($debugecho "</div></blockquote>";
  204.     }
  205.  
  206.     /**
  207.       * sets a database row to the object fields
  208.       * and extract fields from
  209.       *
  210.       * sets each key (=columname) value
  211.       *
  212.       * @param  array   $row            the row form a select * from DBMS_TABLEOBJ::myTable
  213.       * @param  bool    $asPopulated    set populateTS as if the object has been populated
  214.       * @param  bool    $debug 
  215.       *
  216.       * @since   pk-03-12-14
  217.       * @version pk-03-12-14
  218.       * @version pk-05-03-21
  219.       *
  220.       ***/
  221.     function setDBRow($row,$asPopulated=TRUE,$debug=FALSE{
  222.         if ($debugecho "<p><b>TMPL_CHAPTER::setDBRow($row,$asPopulated,$debug)</b> (".get_class($this).")</p><blockquote>";
  223.         parent::setDBrow($row,$asPopulated,$debug);
  224.  
  225.         if (!empty($row[$this->colPrevix."FIELDCLASSES"])) {
  226.             // we have table version > 16 with field classes -> ensure the class source is loaded
  227.             $fldClasses=explode(";",$row[$this->colPrevix."FIELDCLASSES"]);
  228.             if (is_array($fldClasses)) {
  229.                 foreach($fldClasses as $fldClass{
  230.                     if (!empty($fldClass)) {
  231.                         DBMS_field_IncludeSrc($fldClass,$debug);
  232.                     }
  233.                 }
  234.             }
  235.         }
  236.  
  237.         if (!empty($row[$this->colPrevix."FIELDS"])) $this->inputFields=@unserialize($row[$this->colPrevix."FIELDS"]);
  238.         $this->p_extractFields(FALSE,$debug);   // check for new fields in code
  239.  
  240.         $this->setDBFieldDataCols($debug);      // make sure db column values are a repesentation of the row
  241.  
  242.         if ($debugecho "</blockquote><hr>";
  243.     }
  244.  
  245.     /**
  246.       * sets the object field from $_POST[$arrName] and extracts fields
  247.       *
  248.       * note populates the template first to get all fields.
  249.       *
  250.       * @param string $arrName  name of the post array
  251.       * @param bool   $debug    show debug info
  252.       *
  253.       * @version pk-03-12-14    as DBMS_TBLOBJ::setPOSTVAL() calls setDBRow no more need to overwrite
  254.       *
  255.       ***/
  256.     function setPOSTVAL($arrName="DBVAL",$debug=FALSE{
  257.         if ($debug{
  258.             echo "<hr><blockquote><p><b>TMPL_CHAPTER::setPOSTVAL($arrName,$debug)</b> (".get_class($this).")</p>";
  259.             echo "<pre>";print_r($_POST[$arrName]);echo "</pre>";
  260.         }
  261.         if (!$this->populateTS$this->dbPopulate($debug);
  262.         // $this->populateTS=time();
  263.         parent::setPOSTVAL($arrName,$debug);
  264.         if ($debugecho "</blockquote>";
  265.     }
  266.  
  267.  
  268.  
  269.     /**
  270.       * saves the object to the database
  271.       *
  272.       * if getId()  dbReplace is called
  273.       * else        dbInsert is called
  274.       *
  275.       * @param string $gDBIDX Index of $GLOBALS to the db object
  276.       * @param bool   $debug  show debug info
  277.       *
  278.       * @version pk-03-10-19
  279.       *
  280.       ***/
  281.     function dbSave($gDBIDX="USRDB",$debug=FALSE{
  282.         if ($debugecho "<hr><p><b>TMPL_CHAPTER::dbSave($gDBIDX,$debug)</b></p>";
  283.         if (!is_object($GLOBALS[$gDBIDX])) $gDBIDX="USRDB";     // old usage without params
  284.         if ($this->getId()) {
  285.             return $this->dbReplace($gDBIDX,$debug);
  286.         else {
  287.             return $this->dbInsert($gDBIDX,$debug);
  288.         }
  289.     }
  290.  
  291.     /**
  292.       * inserts a new row to the table
  293.       *
  294.       * we have to serialize the inputFields before saving
  295.       *
  296.       * @param string $gDBIDX Index of $GLOBALS to the db object
  297.       * @param bool   $debug  show debug info
  298.       *
  299.       * @return int   returns the autoIncFld ID if exists or 1 on success
  300.       *
  301.       ***/
  302.     function dbInsert($gDBIDX="USRDB",$debug=FALSE{
  303.         if ($debugecho "<hr><p><b>TMPL_CHAPTER::dbInsert($gDBIDX,$debug)</b></p>";
  304.         $this->setDBFieldDataCols($debug);      // make sure db column values are a repesentation of the object
  305.         return parent::dbInsert($gDBIDX,$debug);
  306.     }
  307.  
  308.     /**
  309.       * replaces a row in the table
  310.       *
  311.       * serialize $this->inputFields and calls parent::dbReplace()
  312.       *
  313.       * @param string $gDBIDX Index of $GLOBALS to the db object
  314.       * @param bool   $debug  show debug info
  315.       *
  316.       * @return bool 
  317.       *
  318.       ***/
  319.     function dbReplace($gDBIDX="USRDB",$debug=FALSE{
  320.         if ($debugecho "<hr><p><b>TMPL_CHAPTER::dbReplace($gDBIDX,$debug)</b></p>";
  321.         $this->setDBFieldDataCols($debug);      // make sure db column values are a repesentation of the object
  322.         return parent::dbReplace($gDBIDX,$debug);
  323.     }
  324.  
  325.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  326.     // fieldlist methods
  327.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  328.  
  329.     /**
  330.       * returns the table head row for the fieldlist
  331.       *
  332.       * @returns string
  333.       *
  334.       * @since pk-05-02-02
  335.       *
  336.       ***/
  337.     function fldLstRow_Header($debug{
  338.         if ($debugecho "<p><b>DBMS_fldLstHeader(...)</b> (".__FILE__.")</p>";
  339.  
  340.         $ret="
  341.         <tr>
  342.             <th align=\"center\">#</th>
  343.             <th align=\"center\">Field</th>
  344.             <th align=\"center\">Label</th>
  345.             <th align=\"center\">Input-Type</th>
  346.             <th align=\"center\">ShowClass</th>
  347.             <th colspan=\"6\">&nbsp;</th>
  348.         </tr>
  349.         ";
  350.         return $ret;
  351.     }
  352.  
  353.     /**
  354.       * returns the htmlcode for a field row in the fieldlist
  355.       *
  356.       * @param DBMS_FIELD $fld the field object
  357.       * @param string $editUrl link to the field editor
  358.       * @param string $tdStyle column stylesheet (add ; at the end)
  359.       * @param boolean $debug 
  360.       *
  361.       * @return string 
  362.       *
  363.       * @since pk-05-02-02
  364.       *
  365.       ***/
  366.     function fldLstRow(&$fld,$editUrl="",$funcUrl="",$tdStyle="",$debug=FALSE{
  367.         if ($debugecho "<p><b>DBMS_fldLstRow(...)</b> (".__FILE__.")</p>";
  368.  
  369.         if (!pcf_is_instance_of($fld,"DBMS_FIELD")) return NULL;    // $fld is from wrong class
  370.  
  371.         if (empty($editUrl)) $editUrl=$_SERVER['REQUEST_URI'];
  372.         $editUrl=str_replace("&TMPLFIELD=".$_GET['TMPLFIELD'],"",$editUrl);
  373.         $editUrl=str_replace("&TMPLFLDCMD=".$_GET['TMPLFLDCMD'],"",$editUrl);
  374.         $editUrl=str_replace("&NEWTYPE=".$_GET['NEWTYPE'],"",$editUrl);
  375.         $editUrl.="&TMPLFIELD=".$fld->myName."&TMPLFLDCMD=EDIT";
  376.  
  377.         $eLink="<a href=\"".$editUrl."&FIELD=".$fld->myName."\">";
  378.  
  379.         if (empty($funcUrl)) $funcUrl=$_SERVER['REQUEST_URI'];
  380.         $funcUrl=str_replace("&TMPLFIELD=".$_GET['TMPLFIELD'],"",$funcUrl);
  381.         $funcUrl=str_replace("&TMPLFLDCMD=".$_GET['TMPLFLDCMD'],"",$funcUrl);
  382.         $funcUrl=str_replace("&NEWTYPE=".$_GET['NEWTYPE'],"",$funcUrl);
  383.         $funcUrl.="&TMPLFIELD=".$fld->myName;
  384.  
  385.         if ($fld->isHidden)                                $tdstyle.="background: #c0c0c0;";
  386.         if ((!$fld->enableNew&& (!$fld->enableEdit))     $tdstyle.="color: #FF0000;";
  387.         else if (!$fld->enableNew)                         $tdstyle.="color: #FFFF00;";
  388.         else if (!$fld->enableEdit)                        $tdstyle.="color: #FF00FF;";
  389.  
  390.         $style="style=\"".$tdstyle."\"";
  391.         $ret="<tr>\n";
  392.         $ret.="\t<td $style>$eLink".$fld->sortOrder."</a></td>\n";
  393.         $ret.="\t<td $style>$eLink".$fld->myName."</a></td>\n";
  394.         $ret.="\t<td $style>$eLink".$fld->label."</a></td>\n";
  395.  
  396.         $ret.="\t<td $style><select name=\"ChangeType\" onChange=\"";
  397.         $ret.="if (confirm('Change Class To: '+this.options[this.selectedIndex].value)) { ";
  398.         $ret.="   editLoc='".$funcUrl."&TMPLFLDCMD=CHANGETYPE';";
  399.         $ret.="   editLoc=editLoc+'&NEWTYPE='+this.options[this.selectedIndex].value;";
  400.         $ret.="   document.location.href=editLoc;";
  401.         $ret.="} \">\n";
  402.  
  403.         foreach($this->myFldValTypes as $type => $name{
  404.             $ret.="\t\t<option value=\"".$type."\" ";
  405.             if ($fld->dbDesc['TYPE']==$type$ret.="selected";
  406.             $ret.=">".$name."</option>\n";
  407.         }
  408.         $ret.="</select></td>\n";
  409.  
  410.         $ret.="\t<td $style>";
  411.         $ret.=$fld->editLst_getClassSelect($editUrl."&TMPLFLDCMD=CHANGECLASS",$selName="ChangeClass",$style="",$debug=FALSE);
  412.         $ret.="</td>";
  413.  
  414.         // ~~~~~~~~~~~~~~~ BUTTONS ~~~~~~~~~~~~~~~~~~~~
  415.  
  416.         $ret.="\t<td width=\"17\" align=\"center\" class=\"button\">";
  417.         if ($fld->sortOrder 1{
  418.             $ret.="<a href=\"".$funcUrl."&TMPLFLDCMD=UP\"><img src=\"".$GLOBALS['OCSP']['SYSIMGURL']."buttons/up.gif\" border=\"0\" alt=\"move up\"></a></td>";
  419.         else {
  420.             $ret.="&nbsp;</td>";
  421.         }
  422.  
  423.         $ret.="\t<td width=\"17\" align=\"center\" class=\"button\">";
  424.         if ($count sizeof($this->inputFields)) {
  425.             $ret.="<a href=\"".$funcUrl."&TMPLFLDCMD=DOWN\"><img src=\"".$GLOBALS['OCSP']['SYSIMGURL']."buttons/down.gif\" border=\"0\" alt=\"move down\"></a></td>";
  426.         else {
  427.             $ret.="&nbsp;</td>";
  428.         }
  429.  
  430.         $ret.="\t<td width=\"2\" style=\"font-size:1px;\">&nbsp;</td>";
  431.         $ret.="\t<td width=\"17\" align=\"center\" class=\"button\">";
  432.         if ($fld->isHidden{
  433.             $ret.="<a href=\"".$funcUrl."&TMPLFLDCMD=SHOW\"><img src=\"".$GLOBALS['OCSP']['SYSIMGURL']."buttons/ishidden.gif\" border=\"0\" alt=\"show\"></a></td>";
  434.         else {
  435.             $ret.="<a href=\"".$funcUrl."&TMPLFLDCMD=HIDE\"><img src=\"".$GLOBALS['OCSP']['SYSIMGURL']."buttons/isshown.gif\" border=\"0\" alt=\"hide\"></a></td>";
  436.         }
  437.  
  438.         $ret.="\t<td width=\"2\" style=\"font-size:1px;\">&nbsp;</td>";
  439.         $ret.="\t<td width=\"17\" align=\"center\" class=\"button\">";
  440.         $ret.="<a href=\"javascript:{if (confirm('Feld: ".$fld->myName." l&ouml;schen?')) ";
  441.         $ret.="     document.location.href='".$funcUrl."&TMPLFLDCMD=DELETE';";
  442.         $ret.="}\"><img src=\"".$GLOBALS['OCSP']['SYSIMGURL']."buttons/delete.gif\" border=\"0\" alt=\"delete\"></a></td>\n";
  443.  
  444.  
  445.         $ret.="</tr>\n";
  446.         return $ret;
  447.     }
  448.  
  449.  
  450.     #####################################
  451.  
  452.     /**
  453.       * checks the sortorder of the input fields
  454.       *
  455.       * @param boolean $debug 
  456.       *
  457.       * @version pk-05-03-21
  458.       *
  459.       ***/
  460.     function p_checkSort($debug=FALSE{
  461.         if ($debugecho "<p><b>TMPL_CHAPTER::p_checkSort(...)</b> (".get_class($this).")</p><blockquote>";
  462.  
  463.         $fldArr=array();
  464.         $orderNr=1;
  465.         if (is_array($this->inputFields)) {
  466.             // first put the DBMS fields into a new array other objects will be deleted
  467.             foreach($this->inputFields as $fld{
  468.                 if (pcf_is_instance_of($fld,"DBMS_FIELD")) {
  469.                     // find the first free orderNr
  470.                     if (intval($fld->sortOrder)) {
  471.                         // for objects where it is set
  472.                         while(isset($fldArr[$fld->sortOrder])) $fld->sortOrder++;
  473.                     else {
  474.                         // for objects where it is not set
  475.                         while(isset($fldArr[$orderNr])) $orderNr++;
  476.                         $fld->sortOrder=$orderNr;
  477.                     }
  478.                     if ($debugecho "<p>".$fld->sortOrder.": getting Field: ".$fld->getName()."</p>";
  479.                     $fldArr[$fld->sortOrder]=$fld;
  480.                 else {
  481.                     if ($debugecho "<p>WRONG OBJECT: ".print_r($fld)."</p>";
  482.                 }
  483.             }
  484.             // secound sort $fldArr and clear inputFields
  485.             $this->inputFields=array();
  486.             ksort($fldArr);
  487.  
  488.             // third set the new inputFields
  489.             $orderNr=1;
  490.             foreach($fldArr as $fld{
  491.                 $fld->sortOrder=$orderNr++;
  492.                 $this->inputFields[$fld->getName()]=$fld;
  493.                 if ($debugecho "<p>setting Field: ".$fld->getName()." as Nr: ".$fld->sortOrder."</p>";
  494.             }
  495.         else {
  496.             if ($debugecho "<p>No Fields in \$this->inputFields</p>";
  497.         }
  498.         if ($debugecho "</blockquote>";
  499.     }
  500.  
  501.     /**
  502.       * PRIVATE extracts template fields from code fields
  503.       *
  504.       * @param bool $clearFirst call $this->inputFields =array(); ?
  505.       * @param bool $debug      show debug info
  506.       *
  507.       * @return bool 
  508.       *
  509.       * @private
  510.       *
  511.       * @version pk-05-02-08
  512.       *
  513.       ***/
  514.     function p_extractFields($clearFirst=FALSE,$debug=FALSE{
  515.         if ($debugecho "<hr><p><b>TMPL_CHAPTER::p_extractFields($clearFirst,$debug)</b></p><blockquote>";
  516.  
  517.         if (!$this->populateTS$this->dbPopulate($debug);
  518.         if ($clearFirst{
  519.             $this->inputFields =array();
  520.         }
  521.  
  522.         $code="";
  523.         foreach($this->tmplFields as $fld{
  524.             if ($debugecho "<p>INPUTFIELD$fld</p><p style=\"font-familycourierfont-size: 10px;\">".nl2br(htmlspecialchars($this->{$fld}))."</p>";
  525.             $code.=$this->{$fld};
  526.         }
  527.  
  528.         $orderNr=1;
  529.         if ($codeArr=pcf_tmpl_getVars($code,$debug)) {
  530.             foreach($codeArr as $key => $fld{
  531.                 if (!empty($key)) /* <pk-05-02-08 /> */
  532.                     if ($debugecho "<p>checking$key </p><blockquote>";
  533.                     switch($fld['TYPE']{
  534.                         case PCF_TMPLVAR_ARR:
  535.                         case PCF_TMPLVAR_IF:
  536.                             if ($debugecho "<p style=\"font-size:80%\"><b>is Form Field</b> (".print_r($fld,TRUE)."</p>";
  537.                             if (!is_object($this->inputFields[$key])) {
  538.                                 require_once $GLOBALS['OCSP']['DBMSFLD_PATH']."DBMS_FIELD.phpclass";
  539.                                 $this->inputFields[$key]=new DBMS_FIELD($this->myFrmFldTableName,$key,array('LEN'=>256,'TYPE'=>'string'),$orderNr);
  540.                             }
  541.                             $orderNr++;
  542.                             break;
  543.                         default:
  544.                             if ($debugecho "<p style=\"font-size:80%\">no Form Field (".print_r($fld,TRUE)."</p>";
  545.  
  546.                     }
  547.                     if ($debugecho "</blockquote>";
  548.                 else {
  549.                     if ($debugecho "<p>EMPTY FIELD</p>";
  550.                 }
  551.             }
  552.         }
  553.  
  554.         /* <pk-05-02-10 remove fields with illegal chars in key > */
  555.         $illegalchars=array(" ","\n","<",">","&","?");
  556.         if ($debugecho "<p><b><u>Input Fields:</u></b></p>";
  557.         if (is_array($this->inputFields)) {
  558.             foreach($this->inputFields as $key => $fld{
  559.                 reset($illegalchars);
  560.                 $found=FALSE;
  561.                 while (!$found && list($idx,$iChar)=each($illegalchars)) {
  562.                     if (strstr($key,$iChar)) $found=TRUE;
  563.                 }
  564.  
  565.                 if ($found{
  566.                     if ($debugecho "<p><b>REMOVING:</b>".htmlspecialchars($key).": ".get_class($fld)."</p>";
  567.                     unset($this->inputFields[$key]);
  568.                 else {
  569.                     if ($debugecho "<p>$key".get_class($fld)."</p>";
  570.                 }
  571.             }
  572.         }
  573.         /* </pk-05-02-10> */
  574.         if ($debugecho "</blockquote>";
  575.         $this->p_checkSort($debug);
  576.         return TRUE;
  577.     }
  578.  
  579.  
  580.     // #################################
  581.  
  582.     /**
  583.       * sets the db datatype of a field
  584.       *
  585.       * @param string $fldName Name of the field
  586.       * @param string $dbType Name of the DB col type
  587.       * @param boolean $autosave save object after change
  588.       * @param boolean $debug 
  589.       *
  590.       * @return boolean 
  591.       *
  592.       * @since pk-05-03-21
  593.       *
  594.       ***/
  595.     function setFieldDBType($fldName,$dbType,$autoSave=TRUE,$debug=FALSE{
  596.         if ($debugecho "<p><b>TMPL_CHAPTER::setFieldDBType($fldName,$dbType,...)</b> (".get_class($this).")</p>";
  597.  
  598.         require_once $GLOBALS['OCSP']['PHPINCPATH']."common/pcf.phpinc";
  599.  
  600.         if (pcf_is_instance_of($this->inputFields[$fldName],"DBMS_FIELD")) {
  601.             $this->inputFields[$fldName]->dbDesc['TYPE']=$dbType;
  602.             if ($autoSave$this->dbSave($this->get_gDBIDX(),$debug);
  603.         }
  604.  
  605.     }
  606.  
  607.     function deleteField($fldName,$debug=FALSE{
  608.         if ($debug{
  609.             echo "<pre>$fldName:\n";print_r($this->inputFields[$fldName]);echo "</pre>";
  610.             if (!isset($this->inputFields[$fldName])) echo "<pre>";print_r($this->inputFields);echo "</pre>";
  611.         }
  612.         unset($this->inputFields[$fldName]);
  613.         $this->p_checkSort($debug);
  614.     }
  615.  
  616.  
  617.     // #################################
  618.  
  619.  
  620.     /**
  621.       * returns an array with pointers to the template fields
  622.       *
  623.       * @param boolean $debug 
  624.       *
  625.       ***/
  626.     function getFieldList($debug=FALSE{
  627.         if (!$this->populateTS$this->dbPopulate($debug);
  628.         if (!$this->inputFields{
  629.             $this->p_extractFields(FALSE,$debug);
  630.             $this->dbSave($this->get_gDBIDX(),$debug);
  631.         }
  632.         $ret=array();
  633.         if (is_array($this->inputFields)) {
  634.             reset($this->inputFields);
  635.             while(list($key,$obj)=each($this->inputFields)) {
  636.                 if (empty($obj->myName)) $obj->myName=$key;
  637.                 if ($debugecho $obj->sortOrder.": ".$key." ".$obj->label;
  638.                 if (isset($ret[$obj->sortOrder])) {
  639.                     echo "<p>DUPLICATE ORDERNR</p>";
  640.                 }
  641.                 $ret[$obj->sortOrder]=&$this->inputFields[$key];
  642.             }
  643.         }
  644.         return $ret;
  645.     }
  646.  
  647.     function storeFields($debug=FALSE{
  648.         $this->dbSave($this->get_gDBIDX(),$debug);
  649.     }
  650.  
  651.  
  652.     // #################################
  653.  
  654.     /**
  655.       * returns the form object for the chapter
  656.       *
  657.       * @param string $aForm Name of a DMBS_FORM if empty TABLENAME is used
  658.       * @param boolean $inputFieldsOnly hide all other fields
  659.       * @param boolean $debug 
  660.       *
  661.       * @returns DBMS_FORM
  662.       *
  663.       * @version pk-04-07-30
  664.       *
  665.       ***/
  666.     function &getChapterForm($aForm="",$debug=FALSE,$inputFieldsOnly=FALSE{
  667.         require_once $GLOBALS['OCSP']['PHPFORMPATH']."forms.phpinc";
  668.         if (empty($aForm)) $aForm=$this->contTable;
  669.         if (!($frmObj=&DBMS_form_loadName($aForm))) {
  670.             $ERR="FORM_NOT_FOUND ".$aForm;
  671.             include $GLOBALS['PROJECT']['PHPINCPATH']."io/errors.phpinc";
  672.             die();
  673.         }
  674.  
  675.         $frmObj->removeTableFields($this->myFrmFldTableName,$debug);
  676.  
  677.         if ($inputFieldsOnly{
  678.             $frmObj->hideAllTblFields($this->contTable);
  679.         }
  680.  
  681.         if (is_array($this->inputFields)) {
  682.             reset($this->inputFields);
  683.             $maxSortOrder=sizeof($frmObj->frmFields);
  684.             while(list($key,$obj)=each($this->inputFields)) {
  685.                 if ($debugprint_r($obj);
  686.                 $obj->sortOrder=$obj->sortOrder+$maxSortOrder;
  687.                 $frmObj->addNoDBFieldObj($obj);
  688.             }
  689.         }
  690.  
  691.         return $frmObj;
  692.     }
  693.  
  694.  
  695.     /**
  696.       * returns a serialized array of the input fields in $postArr
  697.       *
  698.       * if $fldArr is an array the fields are added/replaced
  699.       * otherwise a new array is created
  700.       *
  701.       * @param array $postArr 
  702.       * @param boolean $keepServerName (replace http://SERVER_NAME/ with / ?)
  703.       * @param boolean $debug 
  704.       * @param array $fldArr 
  705.       *
  706.       * @returns string
  707.       *
  708.       * @version pk-04-08-05
  709.       ***/
  710.     function getFieldValues($postArr,$keepServerName=FALSE$debug=FALSE,$fldArr=NULL{
  711.         if ($debugecho "<p><b>TMPL_CHAPTER::getFieldValues(\$postArr array(".sizeof($postArr)."),$keepServerName,$debug,\$fldArr array(".sizeof($fldArr)."))</b> (".get_class($this).")</p>";
  712.         if (is_array($fldArr)) {
  713.             $retArr=$fldArr;
  714.         else {
  715.             $retArr=array();
  716.         }
  717.         // if ($debug) echo "<blockquote><pre>".htmlspecialchars(print_r($postArr,TRUE))."</pre></blockquote>";
  718.         if (is_array($this->inputFields)) {
  719.             reset($this->inputFields);
  720.             while(list($key,$obj)=each($this->inputFields)) {
  721.                 if ($debugecho "<blockquote>Object$key<pre>".pcf_print_r($obj,TRUE,3)."</pre>";
  722.                 if (stristr($obj->className,"HTML")) {
  723.                     if ((!$keepServerName|| ($obj->getSetting("replaceServer"))) {
  724.                         // replace http://servername/ with / to allow more systems
  725.                         $retArr[$obj->myName]=str_replace("http://".$_SERVER['SERVER_NAME']."/","/",$postArr[$obj->myName]);
  726.                     else {
  727.                         $retArr[$obj->myName]=$postArr[$obj->myName];
  728.                     }
  729.                 else {
  730.                     $retArr[$obj->myName]=$postArr[$obj->myName];
  731.                 }
  732.             }
  733.         else {
  734.             if ($debugecho "<blockquote>returns NULL</blockquote><hr>";
  735.             return "";
  736.         }
  737.         if ($debugecho "<blockquote>getFieldValues returns serialize of <pre>".htmlspecialchars(print_r($retArr,TRUE))."</pre></blockquote><hr>";
  738.         return serialize($retArr);
  739.     }
  740.  
  741.  
  742.     /**
  743.       * returns the html code for the template
  744.       *
  745.       * @param array $vals 
  746.       * @param string $var 
  747.       * @param boolean $debug 
  748.       *
  749.       * @since pk-04-07-30
  750.       * @version pk-04-11-15
  751.       *
  752.       ***/
  753.     function getTag($vals=array(),$var="HTMLCODE",$debug=FALSE{
  754.         $arrName="tmplValArr_".$this->getId;
  755.         global ${$arrName};
  756.  
  757.         if ($debug{
  758.             echo "<p><b>TMPL_CHAPTER::getTag(\$vals (".sizeof($vals)."),$var,...)</b".get_class($this)."</p>";
  759.             echo htmlspecialchars($this->{$this->colPrevix.$var});
  760.             echo "<pre>";print_r($vals);echo "</pre>";
  761.             echo "</blockquote>";
  762.         }
  763.  
  764.         $frmObj=$this->getChapterForm("",$debug,TRUE);
  765.         $tag=$this->{$this->colPrevix.$var};
  766.  
  767.  
  768.         if ((!empty($tag)) && (is_array($vals))) {
  769.             /* <pk-04-08-02 >
  770.             reset($vals);
  771.             while(list($fld,$val)=each($vals)) {
  772.                 $tag=str_replace("\$*".$fld."\$",$val,$tag);
  773.             }
  774.             */
  775.             /* <pk-04-08-10> */
  776.             $tmplVals=array();
  777.             $fldLst=$frmObj->getFieldArr();
  778.             if (is_array($fldLst)) {
  779.                 foreach($fldLst as $fld{
  780.                     $tmplVals[$fld->myName]=$fld->getHtmlTag($vals[$fld->myName],$arrName,$debug);
  781.                     /*
  782.                     if ($debug) echo "<blockquote>Replace Field: ".$fld->myName."<br /><pre>".print_r($vals[$fld->myName],TRUE)."</pre></blockquote>";
  783.                     $tag=str_replace("\$*".$fld->myName."\$",$fld->getHtmlTag($vals[$fld->myName],$arrName,$debug),$tag);
  784.                     */
  785.                 }
  786.                 $tag=pcf_tmpl_parse($tag,$tmplVals,$debug);
  787.             }
  788.         }
  789.         /* <pk-04-08-30> */
  790.         if (is_array($GLOBALS['CMS']['LINKREPLACE'])) {
  791.             if ($debugecho "<p>['CMS']['LINKREPLACE']: </p><pre>".print_r($GLOBALS['CMS']['LINKREPLACE'],TRUE)."</pre>";
  792.             $linkPattern="/(<a *)(href=\")([^\"]*)([^>]*)(>)/i";
  793.             if (preg_match_all($linkPattern,$tag,$links,PREG_PATTERN_ORDER)) {
  794.                 if ($debugecho "<hr /><p>LINKS: </p><pre>".htmlspecialchars(print_r($links,TRUE))."</pre>";
  795.                 foreach($links[3as $lIdx => $repluri{
  796.                     $rplTarget=FALSE;
  797.                     if (strtoupper(substr(trim($links[3][$lIdx]),0,4)) == "HTTP"{
  798.                         // if ($debug) echo "<p>".trim($links[3][$lIdx])." -- ".$links[4][$lIdx]."</p>";
  799.                         if (
  800.                             (!empty($GLOBALS['CMS']['EXLINKDFLTTRG'])) &&
  801.                             (!strstr("TARGET",strtoupper($links[4][$lIdx]))) &&
  802.                             (!strstr(strtoupper($_SERVER['SERVER_NAME']),strtoupper($links[3][$lIdx])))
  803.                            {
  804.                             $rplTarget =$links[4][$lIdx]." target=\"".$GLOBALS['CMS']['EXLINKDFLTTRG']."\"";
  805.                             if ($debugecho "<p>TARGETREPLACE: ".$links[4][$lIdx]."<br />.".$rplTarget."</p>";
  806.                         }
  807.                     }
  808.                     if ($debugecho("<p><b>Link $lIdx</b></p>");
  809.                     foreach($GLOBALS['CMS']['LINKREPLACE'as $rIdx => $rLinkArr{
  810.                         if (strstr($repluri,$rLinkArr['SRC'])) {
  811.                             $replWith    $links[1][$lIdx];
  812.                             $replWith   .= $links[2][$lIdx];
  813.  
  814.                             $dst=$rLinkArr['DST'];
  815.                             $dst=str_replace("\$*SRC\$",$repluri,$dst);
  816.                             $dst=str_replace("\$*B64_SRC\$",base64_encode($repluri),$dst);
  817.  
  818.                             $replWith   .= $dst;
  819.  
  820.                             if (!empty($GLOBALS['CMS']['LINKREPLACE'][$rIdx]['TARGET'])) {
  821.                                 $replWith   .= $links[4][$lIdx]." target=\"".$GLOBALS['CMS']['LINKREPLACE'][$rIdx]['TARGET']."\" ";
  822.                             else {
  823.                                 if ($rplTarget$replWith.=$rplTarget;
  824.                                 else $replWith .= $links[4][$lIdx];
  825.                             }
  826.                             $replWith   .= $links[5][$lIdx];
  827.  
  828.                             if ($debugecho "<pre>\n Replace URL: \n".htmlspecialchars($links[0][$lIdx])."\n with \n".htmlspecialchars($replWith)."\n </pre>";
  829.                             $tag=str_replace($links[0][$lIdx],$replWith,$tag);
  830.                             // echo "<pre>\n".htmlspecialchars($repluri."\n".$dst."\n".$tag)."</pre>";
  831.                             $rplTarget=FALSE;
  832.                         }
  833.                     }
  834.                     if ($rplTarget{
  835.                         $replWith=$links[1][$lIdx].$links[2][$lIdx].$links[3][$lIdx].$rplTarget.$links[5][$lIdx];
  836.                         if ($debugecho "<pre>\n Replace Target URL: \n".htmlspecialchars($links[0][$lIdx])."\n with \n".htmlspecialchars($replWith)."\n </pre>";
  837.                         $tag=str_replace($links[0][$lIdx],$replWith,$tag);
  838.                     }
  839.                 }
  840.             }
  841.         }
  842.         /* </ pk-04-08-30> */
  843.  
  844.         return pcf_tmpl_parse($tag,$vals,$debug)/* <pk-04-11-15 /> to replace values defined in the template values (forms for example) */
  845.     }
  846. }
  847.  
  848. ?>

Documentation generated on Thu, 08 Jan 2009 17:48:47 +0100 by phpDocumentor 1.4.0a2