Source for file TMPL_CHAPTER_V3.phpclass

Documentation is available at TMPL_CHAPTER_V3.phpclass

  1. <?php
  2. /**
  3.   * Class file TMPL_CHAPTER_V3.phpclass
  4.   *
  5.   * @project    Open CSP-Management
  6.   * @package    cms
  7.   * @category   templates-chapter
  8.   *
  9.   * @author     Peter Krebs <pitlinz@users.sourceforge.net>
  10.   * @license    http://opensource.org/licenses/gpl-license.php GNU Public License
  11.   *
  12.   * @version pk-07-05-31
  13.   * @version $Id: TMPL_CHAPTER_V3.phpclass,v 1.16 2008/10/18 12:18:39 pitlinz Exp $
  14.   * 
  15.   * @deprecated since pk-08-08-07
  16.   */
  17.  
  18. pcf_require_class('TMPL_CHAPTER',dirname(__FILE__"/");
  19.  
  20. /**
  21.  * @staticvar string OCSP_TMPL_FRMVALUE_ALIAS
  22.  */
  23. if (!defined('OCSP_TMPL_FRMVALUE_ALIAS')) define('OCSP_TMPL_FRMVALUE_ALIAS','CHAPTER')
  24.  
  25. /**
  26.   * Handels chapter templates
  27.   *
  28.   * @project    Open CSP-Management
  29.   * @package    cms
  30.   * @category   templates-chapter
  31.   *
  32.   * @author     Peter Krebs <pitlinz@users.sourceforge.net>
  33.   * @license    http://opensource.org/licenses/gpl-license.php GNU Public License
  34.   *
  35.   * @since pk-05-07-20
  36.   * @version pk-05-08-30
  37.   * @version pk-06-02-16 pageTmpl methods added
  38.   * @version pk-06-03-08
  39.   * @version pk-07-05-31
  40.   * @version pk-07-08-22
  41.   * @version $Id: TMPL_CHAPTER_V3.phpclass,v 1.16 2008/10/18 12:18:39 pitlinz Exp $
  42.   * 
  43.   * @deprecated since pk-08-08-07
  44.   */
  45. class TMPL_CHAPTER_V3 extends TMPL_CHAPTER {
  46.     
  47.     /**
  48.       * @constant string CLASS_SRC_FILE
  49.       */
  50.     const CLASS_SRC_FILE = __FILE__;
  51.     
  52.  
  53.     /**
  54.       * @staticvar  string  $ptmplFld   the column name for the page template foreign key
  55.       */
  56.     protected $ptmplFld       = "PTMP_ID";
  57.  
  58.     /**
  59.       * @staticvar string $ptmplTable 
  60.       * @since pk-06-02-16
  61.       */
  62.     protected $ptmplTable     = "T_CMS_TMPL_PAGE";
  63.     /**
  64.       * @staticvar string $ptmplClass 
  65.       * @since pk-06-02-16
  66.       */
  67.     protected $ptmplClass    = "CMS_PAGE_TEMPLATE";
  68.     /**
  69.       * @var string $myPageTmpl 
  70.       * @since pk-06-02-16
  71.       */
  72.     protected $myPageTmpl    = NULL;
  73.  
  74.  
  75.     /**
  76.       * @staticvar  string  $colPrevix   the column name for the chapter columns
  77.       */
  78.     protected $colPrevix      = "CTMP_";
  79.     
  80.     
  81.     /**
  82.       * @var array $inputFields     array of DBMS_FIELD objects for the input form
  83.       */
  84.     protected $inputFields    = array();
  85.  
  86.     /**
  87.       * @var string $myFrmFldTableName (table name set in dbms_formfields)
  88.       */
  89.     protected $myFrmFldTableName="CHAPTER";
  90.  
  91.     /**
  92.       * @var string $classSrcFile source file of the class
  93.       * @since pk-05-02-02
  94.       */
  95.     protected $myClassSrcFile=__FILE__;
  96.  
  97.     /**
  98.       * @var array $myFldValTypes array of allowed db types
  99.       * @since pk-05-02-02
  100.       */
  101.     protected $myFldValTypes=array('string'=>'String','int'=>'Integer','float'=>'Number','blob'=>'Text');
  102.  
  103.     /**
  104.      * @var OCSP_FORM (dummy) formObject for the fields
  105.      */
  106.     protected $myFldFormObj = Null;
  107.     
  108.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  109.     // constructor, var access methods
  110.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  111.  
  112.     /**
  113.       * creates and inits and populates if all keys are set the object
  114.       *
  115.       * @param int $aId ID of the db COLUMN
  116.       * @param boolen $issep is the chapter a layout element with no input
  117.       * @param boolean $debug 
  118.       *
  119.       * @version pk-07-08-22
  120.       *
  121.       ***/
  122.     function TMPL_CHAPTER_V3($aId=0,$issep=FALSE,$debug=FALSE{
  123.         if ($debugecho "<p><b>TMPL_CHAPTER_V3::TMPL_CHAPTER_V3($aId,$issep)</b>(".get_class($this).")</p>";
  124.         $this->init();
  125.  
  126.         if ($aId{
  127.             $this->db_SetKey($this->colPrevix."ID",$aId);
  128.             $this->dbPopulate($debug);
  129.         else {
  130.             $this->setDBField($this->colPrevix."ISSEP",(intval($issepTRUE FALSE));
  131.         }
  132.  
  133.     }
  134.  
  135.     /**
  136.      * returns a chapter template object from an id
  137.      *
  138.      * @param int $aId 
  139.      * @param boolean $debug 
  140.      * 
  141.      * @return TMPL_CHAPTER_V3 
  142.      * 
  143.      * @since pk-08-01-15
  144.      */
  145.     static public function TMPL_CHAPTER_FROM_ID($aId,$debug=FALSE)
  146.     {
  147.         return new TMPL_CHAPTER_V3(intval($aId))
  148.     }
  149.     
  150.     /**
  151.       * @return int 
  152.       */
  153.     function getId({
  154.         return intval($this->{$this->colPrevix."ID"});
  155.     }
  156.  
  157.     /**
  158.       * @param int $aId 
  159.       */
  160.     function setId($aId{
  161.         $this->{$this->colPrevix."ID"}=intval($aId);
  162.     }
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  171.     // database methods
  172.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  173.  
  174.     /**
  175.       * returns a database form and hides some system fields
  176.       * also sets CTMP_ALLOWED_SHOWMODE to
  177.       *
  178.       * @param int $mode 
  179.       * @param string $frmName 
  180.       * @param boolean $debug 
  181.       *
  182.       * @return DBMS_FORM 
  183.       *
  184.       * @since pk-05-03-20
  185.       * @version pk-06-02-16
  186.       */
  187.     function &dbGetForm($mode,$frmName="",$debug=FALSE)  {
  188.         if ($debugecho "<p><b>TMPL_CHAPTER_V3::dbGetForm($mode,$frmName,...)</b> (".get_class($this).")</p>";
  189.  
  190.         if ($frmObj=parent::dbGetForm($mode,$frmName,$debug)) {
  191.             $frmObj->hideField($this->colPrevix."FIELDS");
  192.             $frmObj->hideField($this->colPrevix."FIELDSV2");
  193.             $frmObj->hideField($this->colPrevix."FIELDCLASSES");
  194.             $frmObj->hideField($this->colPrevix."VERSION")// <pk-05-07-20 />
  195.  
  196.             // <pk-06-02-17> set field CTMP_ALLOWED_SHOWMODE values
  197.             if ($this->loadPageTemplate($debug)) {
  198.                 $s_showModes=$this->myPageTmpl->getDBField("PTMP_CHASHOWMODES");
  199.                 if (!empty($s_showModes)) {
  200.                     require_once $GLOBALS['OCSP']['DBMSFLD_PATH']."DBMS_FIELD_DBLOOKUPMULTISELECTLIST.phpclass";
  201.                     $o_fld=&$frmObj->getField("CTMP_ALLOWED_SHOWMODE",$this->myTable,$debug);
  202.                     if (!pcf_is_instance_of($o_fld,"DBMS_FIELD_DBLOOKUPMULTISELECTLIST")) {
  203.                         $o_fld=pcf_castObject($o_fld,"DBMS_FIELD_DBLOOKUPMULTISELECTLIST",$debug);
  204.                     }
  205.                     $o_fld->lookupTable "T_LOOKUP_CHA_SHOWMODE";
  206.                     $o_fld->lookupShowField "CONCAT(LUP_VALUE,' (',LUP_KEY,')')";
  207.                     $o_fld->lookupField "LUP_KEY";
  208.                     $o_fld->lookupWhere "LUP_KEY IN (".$this->myPageTmpl->PTMP_CHASHOWMODES.")";
  209.                 }
  210.             }
  211.         else {
  212.             if ($debugechoDebug(__FILE__,"<p>ERROR: no FORM</p>",1);
  213.         }
  214.  
  215.         return $frmObj;
  216.  
  217.     }
  218.     
  219.     
  220.     /**
  221.       * replaces dbGetForm and returns a OCSP_FORM
  222.       *
  223.       * @param int $mode 
  224.       * @param mixed $form (string) form name (int) form id
  225.       * @param boolean $debug 
  226.       *
  227.       * @return OCSP_FORM 
  228.       *
  229.       *  __OCSP_PHPINCPATH__
  230.       * @requires db/forms/OCSP_FORM.phpclass
  231.       *
  232.       * @since pk-07-08-16
  233.       *
  234.       */
  235.     function &getForm($mode=FRM_MODE_READONLY,$form='',$frmClass='OCSP_FORM',$debug=FALSE)
  236.     {
  237.         if ($debugechoDebugMethod(__FILE__,get_class($this),"TMPL_CHAPTER_V3::getForm($mode,$form,$frmClass)");
  238.         
  239.         if ($objForm=parent::getForm($mode,$form,$frmClass,$debug))
  240.         {        
  241.             $objForm->hideField($this->colPrevix."FIELDS");
  242.             $objForm->hideField($this->colPrevix."FIELDSV2");
  243.             $objForm->hideField($this->colPrevix."FIELDCLASSES");
  244.             $objForm->hideField($this->colPrevix."VERSION")// <pk-05-07-20 />            
  245.         
  246.         return $objForm;
  247.     }
  248.  
  249.  
  250.  
  251.     /**
  252.       * clears $this->inputFields and populates it from the database
  253.       * returns the size of the input field array
  254.       *
  255.       * @param boolean $extractFlds 
  256.       * @param boolean $debug 
  257.       * @param string $gDBIDX 
  258.       * @param boolean $autoUpdate update to version 3 if not already is in this version
  259.       *
  260.       * @return int 
  261.       *
  262.       * @since pk-05-08-02
  263.       * @version pk-05-10-12
  264.       *
  265.       */
  266.     function populateInputFields($extractFlds=TRUE,$debug=FALSE,$autoUpdate=TRUE{
  267.         if ($debugechoDebugMethod(__FILE__,get_class($this),"TMPL_CHAPTER_V3::populateInputFields()");
  268.         
  269.         return parent::populateInputFields($extractFlds,$debug,$autoUpdate);
  270.         
  271.         /*
  272.         if (intval($this->getId())) {
  273.             if (!$this->isConnected(TRUE))
  274.             {
  275.                 ocsp_logError(__FILE__,__LINE__,"no database connection",E_ERROR);
  276.                 return FALSE;
  277.             }
  278.             $this->inputFields=array(); // reset inputFields
  279.             if ($debug) echo "<blockquote><p>Loding fields ......</p>";
  280.             if (empty($this->moduleKey)) $this->moduleKey=$this->getClass();
  281.             $s_Query ="SELECT * FROM ".$this->myFldTable;
  282.             $s_Query.=" WHERE ".$this->colPrevix."ID = ".$this->getId();
  283.             $s_Query.="   AND FRM_MODULE='".$this->moduleKey."'";
  284.             $s_Query.=" ORDER BY FLD_SORTORDER";
  285.             if ($debug) echo "<p>inputFields Query: <br />$s_Query</p>";
  286.             if ($o_Cursur=$this->myDBObj->query($s_Query)) {
  287.                 while($a_fldRow = $o_Cursur->fetchArrayFld()) {
  288.                     if ($debug) echo "<p>FIELD: ".$a_fldRow['FLD_KEY']."</p><blockquote style=\"background-color: #C0C0C0;\">";
  289.                     $a_fldDesc=unserialize(base64_decode($a_fldRow['FLD_B64OBJECT']));
  290.                     if ($debug) echo "<pre style=\"font-size:75%\">".print_r($a_fldDesc,TRUE)."</pre>";
  291.                     $this->unserFldRow($a_fldRow['FLD_KEY'],$a_fldDesc,$debug);
  292.                     if ($debug) echo "</blockquote>";
  293.                 }
  294.             }
  295.  
  296.             if (!sizeof($this->inputFields) && (!empty($this->{$this->colPrevix."FIELDS"}))) {
  297.                 if ($debug) echo "<blockquote style=\"background-color: #D24843\"><h2><b>LOADING TMPL_CHAPTER_V2 FIELDS</b></h2>";
  298.                 // we have an older version -> convert it to the new one
  299.                 if (!empty($this->{$this->colPrevix."FIELDCLASSES"})) {
  300.                     // we have table version > 16 with field classes -> ensure the class source is loaded
  301.                     $fldClasses=explode(";",$this->{$this->colPrevix."FIELDCLASSES"});
  302.                     if (is_array($fldClasses)) {
  303.                         foreach($fldClasses as $fldClass) {
  304.                             if (!empty($fldClass)) {
  305.                                 DBMS_field_IncludeSrc($fldClass,$debug);
  306.                             }
  307.                         }
  308.                     }
  309.                 } else {
  310.                     // we have a very old version
  311.                     DBMS_field_IncludeAllSrc($debug);
  312.                 }
  313.                 $this->inputFields=@unserialize($this->{$this->colPrevix."FIELDS"});
  314.                 // <pk-05-10-12>
  315.                 if (sizeof($this->inputFields)) {
  316.                     $s_cmd ="UPDATE ".$this->myTable." SET ".$this->colPrevix."VERSION=3";
  317.                     $s_cmd.=" WHERE ".$this->colPrevix."ID=".$this->getId();
  318.                     $this->myDBObj->executeCmd($s_cmd);
  319.                     $this->saveInputFields(TRUE,$debug,FALSE); // ([boolean $clearFirst = FALSE], [boolean $debug = FALSE], [boolean $extractFlds = TRUE])
  320.                 }
  321.                 if ($debug) echo "</blockquote>";
  322.             }
  323.  
  324.             if ($extractFlds) {
  325.                 $this->p_extractFields(FALSE,$debug);   // check if all fields defined in the
  326.                                                         // template(s) are in $this->inputFields
  327.             }
  328.             if ($debug) echo "</blockquote>";
  329.         }
  330.         return sizeof($this->inputFields);
  331.         */
  332.     }
  333.  
  334.  
  335.     /**
  336.       * unserializes a fieldRow (array element)
  337.       *
  338.       * @param string $key 
  339.       * @param array $fldDesc 
  340.       * @param bool $debug 
  341.       *
  342.       * @since pk-05-07-14
  343.       * @version pk-05-12-01
  344.       *
  345.       * @var string $classFile 
  346.       *
  347.       */
  348.     function unserFldRow($key,$fldDesc,$debug=FALSE{
  349.         if ($debugecho "<p><b>DBMS_FORM::unserFldRow($key,...)</b> (".get_class($this).")</p><blockquote>";
  350.  
  351.         if (!class_exists($fldDesc['OBJDESC']['CLASS'])) {
  352.  
  353.             $classFile=__OCSP_PROJECTPATH__.$fldDesc['OBJDESC']['SRCFILE']// <pk-05-12-01 />
  354.  
  355.             if (file_exists($classFile)) {
  356.                 require_once $classFile;
  357.                 if ($debugecho "<p>CLASSFILE$classFile included</p>";
  358.             else // <pk-05-12-01>
  359.                 $classFile=__OCSP_PHPINCPATH__.$fldDesc['OBJDESC']['SRCFILE'];
  360.                 if (file_exists($classFile)) {
  361.                     require_once $classFile;
  362.                     if ($debugecho "<p>CLASSFILE$classFile included</p>";
  363.                 else if (file_exists(__OCSP_PHPINCPATH__."db/frmClasses/".basename($fldDesc['OBJDESC']['SRCFILE']))) {
  364.                     require_once __OCSP_PHPINCPATH__."db/frmClasses/".basename($fldDesc['OBJDESC']['SRCFILE']);
  365.                     if ($debugecho "<p>CLASSFILE: ".__OCSP_PHPINCPATH__."db/frmClasses/".basename($fldDesc['OBJDESC']['SRCFILE'])." included</p>";
  366.                 else if (file_exists($fldDesc['OBJDESC']['SRCFILE'])) {
  367.                     require_once $fldDesc['OBJDESC']['SRCFILE'];
  368.                     if ($debugecho "<p>CLASSFILE: ".$fldDesc['OBJDESC']['SRCFILE']." included</p>";
  369.                 else {
  370.                     $fldDesc['OBJDESC']['CLASS']="DBMS_FIELD";
  371.                     if ($debugecho "<p>CLASSFILE NOT FOUND -> CHANGED TO DBMS_FIELD</p>";
  372.                 }
  373.             }
  374.         }
  375.  
  376.         $cmd="\$this->inputFields['".$key."']=new ".$fldDesc['OBJDESC']['CLASS']."();";
  377.         if ($debugecho "<p><br />$cmd</p></blockquote>";
  378.         eval($cmd);
  379.         if (is_object($this->inputFields[$key])) {
  380.             if ($debug{echo "<blockquote>ObjectData: <p style=\"font-size:75%\">";print_r($fldDesc['OBJVAL'],TRUE);echo "</p></blockquote>";}
  381.             $this->inputFields[$key]->setObjectVars($fldDesc['OBJVAL']);
  382.             return TRUE;
  383.         else {
  384.             unset($this->inputFields[$key]);
  385.             if ($debugecho "<p><b>NO OBJECT CREATED</b></p></blockquote>";
  386.             return FALSE;
  387.         }
  388.     }
  389.  
  390.  
  391.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  392.     // page template methods
  393.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  394.  
  395.     /**
  396.       * @return string 
  397.       * @since pk-05-08-29
  398.       */
  399.     function getPTMPColName({
  400.         return $this->ptmplFld;
  401.     }
  402.  
  403.     /**
  404.       * returns the page template id
  405.       * @return int 
  406.       */
  407.     function getPTMPId($debug=FALSE{
  408.         if ($debugecho "<p><b>TMPL_CHAPTER_V3::getPTMPId()</b> (".get_class($this).")</p>";
  409.         if ($debugecho "<blockquote>returning Field: ".$this->ptmplFld.": ".intval($this->getPTMPId())."</blockquote>";
  410.         return intval($this->{$this->getPTMPColName()});
  411.     }
  412.  
  413.     /**
  414.       * sets the page template id
  415.       *
  416.       * @param int $aId 
  417.       * @param boolean $debug 
  418.       *
  419.       * @since pk-03-12-14
  420.       * @version pk-06-02-16
  421.       *
  422.       */
  423.     function setPTMPId($aId,$debug=FALSE{
  424.         $this->{$this->getPTMPColName()$aId;
  425.         // <pk-06-02-16> check $this->myPageTmpl
  426.         if (is_object($this->myPageTmpl&& ($this->myPageTmpl->getId(!= $aId)) {
  427.             // reload page template
  428.             $this->loadPageTemplate($debug);
  429.         }
  430.     }
  431.  
  432.  
  433.     /**
  434.       * loads the page template object if $this->myTmpl is not set or has a different ID
  435.       *
  436.       * uses $GLOBALS['OCSP']['CACHE'][$this->moduleKey.'PAGE_TEMPLATES'] as memory cache
  437.       *
  438.       *
  439.       * @param boolean $debug show debug information
  440.       * @param boolean $enableEmpty 
  441.       *
  442.       * @returns boolean succeed ?
  443.       *
  444.       * @since pk-06-02-16
  445.       *
  446.       */
  447.  
  448.       function loadPageTemplate($debug=FALSE{
  449.         if ($debugecho "<p><b>TMPL_CHAPTER_V3::loadPageTemplate()</b> (".get_class($this).")</p>\n";
  450.  
  451.  
  452.         if (!$this->getPTMPId()) {
  453.             return FALSE;
  454.         }
  455.  
  456.         if ((is_object($this->myPageTmpl)) && ($this->myPageTmpl->getId()==$this->getPTMPId())) {
  457.             // we already loaded the template
  458.             return TRUE;
  459.         }
  460.  
  461.         if (
  462.             isset($GLOBALS['OCSP']['CACHE'][$this->moduleKey.'PAGE_TEMPLATES'][$this->getPTMPId()]&&
  463.             is_object($GLOBALS['OCSP']['CACHE'][$this->moduleKey.'PAGE_TEMPLATES'][$this->getPTMPId()])
  464.            {
  465.             // use memory chached template
  466.             $this->myPageTmpl=&$GLOBALS['OCSP']['CACHE'][$this->moduleKey.'PAGE_TEMPLATES'][$this->getPTMPId()];
  467.             return TRUE;
  468.         }
  469.  
  470.         // <pk-06-02-17>
  471.         if ((empty($this->ptmplClass)) || (!class_exists($this->ptmplClass))) {
  472.             $this->ptmplClass="CMS_PAGE_TEMPLATE";
  473.         }
  474.  
  475.         $i_tmplId=intval($this->{$this->ptmplFld});
  476.         $s_cmd="\$this->myPageTmpl=new ".$this->ptmplClass."(\$i_tmplId);";
  477.         eval($s_cmd);
  478.         if (!is_object($this->myPageTmpl)) {
  479.             return FALSE;
  480.         }
  481.  
  482.         if (intval($this->myPageTmpl->getId())) {
  483.             $GLOBALS['OCSP']['CACHE'][$this->moduleKey.'PAGE_TEMPLATES'][$this->{$this->ptmplFld}]=&$this->myPageTmpl;
  484.             return TRUE;
  485.         else {
  486.             return FALSE;
  487.         }
  488.     }
  489.  
  490.  
  491.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  492.     // fieldlist methods
  493.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  494.  
  495.     /**
  496.       * returns the table head row for the fieldlist
  497.       *
  498.       * @returns string
  499.       *
  500.       * @since pk-05-02-02
  501.       *
  502.       */
  503.     function fldLstRow_Header($debug{
  504.         if ($debugecho "<p><b>DBMS_fldLstHeader(...)</b> (".__FILE__.")</p>";
  505.  
  506.         $ret="
  507.         <tr>
  508.             <th align=\"center\">#</th>
  509.             <th align=\"center\">Field</th>
  510.             <th align=\"center\">Label</th>
  511.             <th align=\"center\">Input-Type</th>
  512.             <th align=\"center\">ShowClass</th>
  513.             <th colspan=\"6\">&nbsp;</th>
  514.         </tr>
  515.         ";
  516.         return $ret;
  517.     }
  518.  
  519.     /**
  520.       * returns the htmlcode for a field row in the fieldlist
  521.       *
  522.       * @param DBMS_FIELD $fld the field object
  523.       * @param string $editUrl link to the field editor
  524.       * @param string $tdStyle column stylesheet (add ; at the end)
  525.       * @param boolean $debug 
  526.       *
  527.       * @return string 
  528.       *
  529.       * @since pk-05-02-02
  530.       *
  531.       */
  532.     function fldLstRow(&$fld,$editUrl="",$funcUrl="",$tdStyle="",$debug=FALSE{
  533.         if ($debugecho "<p><b>DBMS_fldLstRow(...)</b> (".__FILE__.")</p>";
  534.  
  535.         if (!pcf_is_instance_of($fld,"DBMS_FIELD")) return NULL;    // $fld is from wrong class
  536.  
  537.         if (empty($editUrl)) $editUrl=$_SERVER['REQUEST_URI'];
  538.         $editUrl=pcf_HTML_changeURI_GetValue($editUrl,'TMPLFIELD',$fld->getName());
  539.         $editUrl=pcf_HTML_changeURI_GetValue($editUrl,'TMPLFLDCMD',"EDIT");
  540.         $editUrl=pcf_HTML_changeURI_GetValue($editUrl,'NEWTYPE',"");
  541.  
  542.         $eLink="<a href=\"".$editUrl."&FIELD=".$fld->getName()."\">";
  543.  
  544.         if (empty($funcUrl)) $funcUrl=$_SERVER['REQUEST_URI'];
  545.         $funcUrl=pcf_HTML_changeURI_GetValue($funcUrl,'TMPLFIELD',$fld->getName());
  546.         $funcUrl=pcf_HTML_changeURI_GetValue($funcUrl,'TMPLFLDCMD',"");
  547.         $funcUrl=pcf_HTML_changeURI_GetValue($funcUrl,'NEWTYPE',"");
  548.  
  549.         $tdstyle="";
  550.         if ($fld->isHidden('all'))                      $tdstyle.="background: #c0c0c0;";
  551.         if (
  552.             (!$fld->isEnabled(FRM_MODE_NEW)) && 
  553.             (!$fld->isEnabled(FRM_MODE_EDIT))
  554.            )                                             $tdstyle.="color: #FF0000;";
  555.         else if (!$fld->isEnabled(FRM_MODE_NEW))        $tdstyle.="color: #FFFF00;";
  556.         else if (!$fld->isEnabled(FRM_MODE_EDIT))       $tdstyle.="color: #FF00FF;";
  557.  
  558.         $style="style=\"".$tdstyle."\"";
  559.         $ret="<tr>\n";
  560.         $ret.="\t<td $style>$eLink".$fld->getOrderNr()."</a></td>\n";
  561.         $ret.="\t<td $style>$eLink".$fld->getName()."</a></td>\n";
  562.         $ret.="\t<td $style>$eLink".$fld->getLabel()."</a></td>\n";
  563.  
  564.         $ret.="\t<td $style><select name=\"ChangeType\" onChange=\"";
  565.         $ret.="if (confirm('Change Class To: '+this.options[this.selectedIndex].value)) { ";
  566.         $ret.="   editLoc='".$funcUrl."&TMPLFLDCMD=CHANGETYPE';";
  567.         $ret.="   editLoc=editLoc+'&NEWTYPE='+this.options[this.selectedIndex].value;";
  568.         $ret.="   document.location.href=editLoc;";
  569.         $ret.="} \">\n";
  570.  
  571.         foreach($this->myFldValTypes as $type => $name{
  572.             $ret.="\t\t<option value=\"".$type."\" ";
  573.             if ($fld->getDBColType()==$type$ret.="selected";
  574.             $ret.=">".$name."</option>\n";
  575.         }
  576.         $ret.="</select></td>\n";
  577.  
  578.         
  579.         $ret.="\t<td $style>";
  580.         if (method_exists($fld,"editLst_getClassSelect"))
  581.         {
  582.             $ret.=$fld->editLst_getClassSelect($editUrl."&TMPLFLDCMD=CHANGECLASS",$selName="ChangeClass",$style="",$debug=FALSE);
  583.         else {
  584.             $ret.="TMPL_CHAPTER_V3 no method (Line: ".__LINE__.")";
  585.         }
  586.         $ret.="</td>";
  587.  
  588.         // ~~~~~~~~~~~~~~~ BUTTONS ~~~~~~~~~~~~~~~~~~~~
  589.  
  590.         $ret.="\t<td width=\"17\" align=\"center\" class=\"button\">";
  591.         if ($fld->getOrderNr(1{
  592.             $ret.="<a href=\"".$funcUrl."&TMPLFLDCMD=UP\"><img src=\"".$GLOBALS['OCSP']['SYSIMGURL']."buttons/up.gif\" border=\"0\" alt=\"move up\"></a></td>";
  593.         else {
  594.             $ret.="&nbsp;</td>";
  595.         }
  596.  
  597.         $ret.="\t<td width=\"17\" align=\"center\" class=\"button\">";
  598.         if (!isset($count)) $count=1;
  599.         if ($count sizeof($this->inputFields)) {
  600.             $ret.="<a href=\"".$funcUrl."&TMPLFLDCMD=DOWN\"><img src=\"".$GLOBALS['OCSP']['SYSIMGURL']."buttons/down.gif\" border=\"0\" alt=\"move down\"></a></td>";
  601.         else {
  602.             $ret.="&nbsp;</td>";
  603.         }
  604.  
  605.         $ret.="\t<td width=\"2\" style=\"font-size:1px;\">&nbsp;</td>";
  606.         $ret.="\t<td width=\"17\" align=\"center\" class=\"button\">";
  607.         if ($fld->isHidden('all')) {
  608.             $ret.="<a href=\"".$funcUrl."&TMPLFLDCMD=SHOW\"><img src=\"".$GLOBALS['OCSP']['SYSIMGURL']."buttons/ishidden.gif\" border=\"0\" alt=\"show\"></a></td>";
  609.         else {
  610.             $ret.="<a href=\"".$funcUrl."&TMPLFLDCMD=HIDE\"><img src=\"".$GLOBALS['OCSP']['SYSIMGURL']."buttons/isshown.gif\" border=\"0\" alt=\"hide\"></a></td>";
  611.         }
  612.  
  613.         $ret.="\t<td width=\"2\" style=\"font-size:1px;\">&nbsp;</td>";
  614.         $ret.="\t<td width=\"17\" align=\"center\" class=\"button\">";
  615.         $ret.="<a href=\"javascript:{if (confirm('Feld: ".$fld->getName()." l&ouml;schen?')) ";
  616.         $ret.="     document.location.href='".$funcUrl."&TMPLFLDCMD=DELETE';";
  617.         $ret.="}\"><img src=\"".$GLOBALS['OCSP']['SYSIMGURL']."buttons/delete.gif\" border=\"0\" alt=\"delete\"></a></td>\n";
  618.  
  619.  
  620.         $ret.="</tr>\n";
  621.         return $ret;
  622.     }
  623.  
  624.     /**
  625.       * checks the field command ($_GET['TMPLFLDCMD'] if $fldCmd is empty) and
  626.       * do the required action
  627.       *
  628.       * @param string $fldCmd 
  629.       * @param boolean $debug 
  630.       *
  631.       * @return boolean 
  632.       *
  633.       */
  634.     function fldDoTmplFldCmd($fldCmd="",$debug=FALSE{
  635.         if (empty($fldCmd&& isset($_GET['TMPLFLDCMD'])) $fldCmd=$_GET['TMPLFLDCMD'];
  636.         if ($debugechoDebugMethod(__FILE__,get_class($this),"TMPL_CHAPTER_V3::fldDoTmplFldCmd(CMD$fldCmd)");
  637.  
  638.         switch($fldCmd{
  639.             case "CHANGETYPE":
  640.                     $valTypes=array('string'=>'String','int'=>'Integer','float'=>'Number','blob'=>'Text');
  641.                     if (($_GET['NEWTYPE']&& (!empty($valTypes[$_GET['NEWTYPE']]))) {
  642.                         $this->setFieldDBType($_GET['TMPLFIELD'],$_GET['NEWTYPE'],TRUE,$debug);
  643.                     }
  644.                 break;
  645.             case "CHANGECLASS":
  646.                     if ($debugecho "<p>Field: ".$_GET['TMPLFIELD']."<pre>".print_r($this->getField($_GET['TMPLFIELD']),TRUE)."</pre>";
  647.                     if (!($o_Fld=DBMS_field_ChangeClass($this->getField($_GET['TMPLFIELD']),$_GET['NEWCLASS'],$debug))) {
  648.                         $ERR="Change class of field: <b>".$fld->getName()."</b> to <b>".$_GET['NEWCLASS']."</b";
  649.                         include $PROJECT['PHPINCPATH']."io/errors.phpinc";
  650.                         exit;
  651.                     else {
  652.                         $this->inputFields[$_GET['TMPLFIELD']]=$o_Fld;
  653.                         $this->saveInpField($_GET['TMPLFIELD'],$o_Fld,$debug);
  654.                     }
  655.                 break;
  656.             case "SAVE":
  657.                     if ($o_Fld=$this->getField($_GET['TMPLFIELD'])) {
  658.                         $o_Fld->save();
  659.                         $this->saveInpField($_GET['TMPLFIELD'],$o_Fld,$debug);
  660.                     }
  661.                 break;
  662.             case "HIDE":
  663.                     if ($o_Fld=$this->getField($_GET['TMPLFIELD'])) {
  664.                         $o_Fld->setHidden();
  665.                         $this->saveInpField($_GET['TMPLFIELD'],$o_Fld,$debug);
  666.                     }
  667.                 break;
  668.             case "SHOW":
  669.                     if ($o_Fld=$this->getField($_GET['TMPLFIELD'])) {
  670.                         $o_Fld->setShown();
  671.                         $this->saveInpField($_GET['TMPLFIELD'],$o_Fld,$debug);
  672.                     }
  673.                 break;
  674.             case "DOWN":
  675.                     if ($debugecho "<p>Moving Fld ".$_GET['TMPLFIELD']." Down</p>";
  676.                     if ($o_Fld=$this->getField($_GET['TMPLFIELD'])) {
  677.                         if ($o_Fld->sortOrder sizeof($a_Flds)) // this is not the last element
  678.                             $a_Flds=$this->getFieldList($debug);
  679.                             if ($debug{foreach($a_Flds as $i => $oecho "<p>$i".$o->getName()." (ORDNR: ".$o->sortOrder.")</p>\n";echo "<hr>";}
  680.                             if ($o_NxtFld=$a_Flds[($o_Fld->sortOrder+1)]{
  681.                                 // we have a next field
  682.                                 $o_NxtFld->sortOrder=$o_Fld->sortOrder;
  683.                                 if ($debugecho "<p>NextField: ".$o_NxtFld->getName()." (ORDNR: ".$o_NxtFld->sortOrder.")</p>\n";
  684.                                 $this->saveInpField($o_NxtFld->getName(),$o_NxtFld,$debug);
  685.                                 $o_Fld->sortOrder++;
  686.                                 if ($debugecho "<p>Field: ".$o_Fld->getName()." (ORDNR: ".$o_Fld->sortOrder.")</p>\n";
  687.                                 $this->saveInpField($o_Fld->getName(),$o_Fld,$debug);
  688.                             }
  689.                         }
  690.                     }
  691.                 break;
  692.             case "UP":
  693.                     if ($debugecho "<p>Moving Fld ".$_GET['TMPLFIELD']." Up</p>";
  694.                     if ($o_Fld=$this->getField($_GET['TMPLFIELD'])) {
  695.                         if ($o_Fld->sortOrder 1// this is not the last element
  696.                             $a_Flds=$this->getFieldList($debug);
  697.                             if ($debug{foreach($a_Flds as $i => $oecho "<p>$i".$o->getName()." (ORDNR: ".$o->sortOrder.")</p>\n";echo "<hr>";}
  698.                             if ($o_PrevFld=$a_Flds[($o_Fld->sortOrder-1)]{
  699.                                 // we have a next field
  700.                                 $o_PrevFld->sortOrder=$o_Fld->sortOrder;
  701.                                 if ($debugecho "<p>PrevField: ".$o_PrevFld->getName()." (ORDNR: ".$o_PrevFld->sortOrder.")</p>\n";
  702.                                 $this->saveInpField($o_PrevFld->getName(),$o_PrevFld,$debug);
  703.                                 $o_Fld->sortOrder--;
  704.                                 if ($debugecho "<p>Field: ".$o_Fld->getName()." (ORDNR: ".$o_Fld->sortOrder.")</p>\n";
  705.                                 $this->saveInpField($o_Fld->getName(),$o_Fld,$debug);
  706.                             }
  707.                         }
  708.                     }
  709.                 break;
  710.             case "DELETE":
  711.                     $this->deleteField($_GET['TMPLFIELD'],$debug,TRUE);
  712.                 break;
  713.  
  714.         }
  715.         $this->populateInputFields(FALSE)// ($extractFlds=TRUE,$debug=FALSE,$gDBIDX="USRDB")
  716.  
  717.     }
  718.  
  719.  
  720.     
  721.     #####################################
  722.  
  723.     /**
  724.       * checks the sortOrder of the input fields
  725.       *
  726.       * @param boolean $debug 
  727.       *
  728.       * @version pk-05-03-21
  729.       *
  730.       */
  731.     protected function p_checkSort($debug=FALSE{
  732.         if ($debugecho "<p><b>TMPL_CHAPTER_V3::p_checkSort(...)</b> (".get_class($this).")</p><blockquote>";
  733.  
  734.         $fldArr=array();
  735.         $orderNr=1;
  736.         if (is_array($this->inputFields)) {
  737.             // first put the DBMS fields into a new array other objects will be deleted
  738.             foreach($this->inputFields as $fld{
  739.                 if (pcf_is_instance_of($fld,"DBMS_FIELD")) {
  740.                     // find the first free orderNr
  741.                     if (intval($fld->getOrderNr())) {
  742.                         // for objects where it is set
  743.                         while(isset($fldArr[$fld->getOrderNr()])) $fld->incOrderNr();
  744.                     else {
  745.                         // for objects where it is not set
  746.                         while(isset($fldArr[$orderNr])) $orderNr++;
  747.                         $fld->setOrderNr($orderNr);
  748.                     }
  749.                     if ($debugecho "<p>".$fld->getOrderNr().": getting Field: ".$fld->getName()."</p>";
  750.                     $fldArr[$fld->getOrderNr()]=$fld;
  751.                 else {
  752.                     if ($debugecho "<p>WRONG OBJECT: ".print_r($fld)."</p>";
  753.                 }
  754.             }
  755.             // secound sort $fldArr and clear inputFields
  756.             $this->inputFields=array();
  757.             ksort($fldArr);
  758.  
  759.             // third set the new inputFields
  760.             $orderNr=1;
  761.             foreach($fldArr as $fld{
  762.                 $fld->incOrderNr();
  763.                 $this->inputFields[$fld->getName()]=$fld;
  764.                 if ($debugecho "<p>setting Field: ".$fld->getName()." as Nr: ".$fld->getOrderNr()."</p>";
  765.             }
  766.         else {
  767.             if ($debugecho "<p>No Fields in \$this->inputFields</p>";
  768.         }
  769.         if ($debugecho "</blockquote>";
  770.     }
  771.  
  772.     /**
  773.       * PRIVATE extracts template fields from code fields
  774.       *
  775.       * @param bool $clearFirst call $this->inputFields =array(); ?
  776.       * @param bool $debug      show debug info
  777.       *
  778.       * @return bool 
  779.       *
  780.       * @private
  781.       *
  782.       * @version pk-05-02-08
  783.       * @version pk-05-08-26
  784.       * @version pk-06-03-08 avoid adding chapter fields
  785.       *
  786.       */
  787.     function p_extractFields($clearFirst=FALSE,$debug=FALSE{
  788.         if ($debug{
  789.             echoDebugMethod(__FILE__,get_class($this),"TMPL_CHAPTER_V3::p_extractFields(".($clearFirst "CLEARFIRST" "ADDONLY").")");
  790.             echoDebug(__FILE__,"<blockquote style=\"font-size:90%\">");
  791.         }
  792.  
  793.         if (!$this->populateTS$this->dbPopulate($debug);
  794.         if ($clearFirst{
  795.             $this->inputFields =array();
  796.         }
  797.  
  798.         $code="";
  799.         foreach($this->tmplFields as $fld{
  800.             if ($debugecho "<p>INPUTFIELD$fld</p><p style=\"font-familycourierfont-size: 10px;\">".nl2br(htmlspecialchars($this->{$fld}))."</p>";
  801.             $code.=$this->{$fld};
  802.         }
  803.  
  804.         if (empty($code)) {
  805.             echoDebug(__FILE__,"<p>\$code is empty</p></blockquote>");
  806.             return FALSE// <pk-05-08-26 />
  807.         }
  808.  
  809.         // <pk-06-12-01>
  810.         if ($a_varArr=pcf_tmpl_getVars($code)) {
  811.             if ($debugechoDebug(__FILE__,"<p>Vars found in code: </p><pre>".htmlspecialchars(print_r($a_varArr,TRUE))."</pre>");
  812.  
  813.             foreach($a_varArr as $s_key => $a_fld{
  814.                 if (!empty($s_key)) // <pk-05-02-08 />
  815.                     if ($debugechoDebug(__FILE__,"<p>checking$s_key </p><blockquote style=\"font-size:90%;\">");
  816.                     switch($a_fld['TYPE']{
  817.                         case PCF_TMPLVAR_ARR:
  818.                         case PCF_TMPLVAR_IF:
  819.                             if ($debugechoDebug(__FILE__,"<p style=\"font-size:80%\"><b>is Form Field</b> (".print_r($a_fld,TRUE)."</p>");
  820.                             if (!pcf_is_instance_of($this->inputFields[$s_key],'DBMS_FIELD')) {
  821.                                 require_once __OCSP_PHPINCPATH__."/db/frmClasses/DBMS_FIELD.phpclass";
  822.                                 $this->inputFields[$s_key]=new DBMS_FIELD($this->myFrmFldTableName,$s_key,array('LEN'=>256,'TYPE'=>'string'),sizeof($this->inputFields)+1)//<pk 05-08-02 />
  823.                             }
  824.                             break;
  825.                         default:
  826.                             if ($debugechoDebug(__FILE__,"<p style=\"font-size:80%\">no Form Field (".print_r($fld,TRUE)."</p>");
  827.  
  828.                     }
  829.                     if ($debugechoDebug(__FILE__,"</blockquote>");
  830.                 else {
  831.                     if ($debugechoDebug(__FILE__,"<p>EMPTY FIELD</p>");
  832.                 }
  833.             }
  834.         }
  835.         // </pk-06-12-01>
  836.  
  837.         // <pk-05-02-10 remove fields with illegal chars in key >
  838.         $illegalchars=array(" ","\n","<",">","&","?");
  839.         if ($debugechoDebug(__FILE__,"<p><b><u>Input Fields:</u></b></p>");
  840.         if (!is_array($this->inputFields)) $this->inputFields=array();  // <pk-05-08-26 />
  841.         foreach($this->inputFields as $key => $fld{
  842.             reset($illegalchars);
  843.             $found=FALSE;
  844.             while (!$found && list($idx,$iChar)=each($illegalchars)) {
  845.                 if (strstr($key,$iChar)) $found=TRUE;
  846.             }
  847.  
  848.             if ($found{
  849.                 if ($debugechoDebug(__FILE__,"<p><b>REMOVING:</b>".htmlspecialchars($key).": ".get_class($fld)."</p>");
  850.                 unset($this->inputFields[$key]);
  851.             else {
  852.                 if ($debugechoDebug(__FILE__,"<p>$key".get_class($fld)."</p>");
  853.             }
  854.         }
  855.         // </pk-05-02-10>
  856.  
  857.         // <pk-06-03-08>
  858.         if (!$this->isConnected(TRUE))
  859.         {
  860.             ocsp_logError(__FILE__,__LINE__,"no database connection",E_ERROR);
  861.             return FALSE;
  862.         }
  863.         if ($a_DBFields=$this->myDBObj->getDBTblColNames($this->contTable,FALSE)) {
  864.             foreach($a_DBFields as $s_colName{
  865.                 if (isset($this->inputFields[$s_colName])) {
  866.                     // remove database field
  867.                     if ($debugechoDebug(__FILE__,"<p><b>REMOVING:</b>".htmlspecialchars($s_colName)." because it's a table column</p>");
  868.                     unset($this->inputFields[$s_colName]);
  869.                 }
  870.             }
  871.         }
  872.         // </pk-06-03-08>
  873.         $this->p_checkSort($debug);
  874.         if ($debugechoDebug(__FILE__,"</blockquote>");
  875.         return TRUE;
  876.     }
  877.  
  878.  
  879.     // #################################
  880.  
  881.  
  882.     /**
  883.       * deletes a field
  884.       *
  885.       * @param string $fldName 
  886.       * @param boolean $debug 
  887.       * @param boolean $forceDB 
  888.       *
  889.       * @return boolean 
  890.       *
  891.       * @version pk-05-07-29
  892.       *
  893.       * @var string $s_Cmd 
  894.       *
  895.       ***/
  896.     function deleteField($fldName,$debug=FALSE,$forceDB=TRUE{
  897.         if ($debugecho "<p><b>TMPL_CHAPTER_V3::deleteField($fldName,...)</b> (".get_class($this).")</p>";
  898.  
  899.         unset($this->inputFields[$fldName]);
  900.         if ($forceDB && $this->getId()) {
  901.             $s_Cmd ="DELETE FROM ".$this->myFldTable;
  902.             $s_Cmd.=" WHERE ".$this->colPrevix."ID = ".$this->getId();
  903.             $s_Cmd.="   AND FRM_MODULE='".$this->moduleKey."'";
  904.             $s_Cmd.="   AND FLD_NAME=".$this->myDBObj->qs_getSlashedValue($fldName);
  905.             $this->myDBObj->executeCmd($s_Cmd);
  906.         }
  907.         $this->p_checkSort($debug);
  908.     }
  909.  
  910.  
  911.     // #################################
  912.  
  913.  
  914.     /**
  915.       * returns an array with pointers to the template fields
  916.       * also checks orderNr
  917.       *
  918.       * @param boolean $debug 
  919.       * @param boolean $autoSave 
  920.       *
  921.       * @return array 
  922.       *
  923.       * @version pk-05-07-25
  924.       * @version pk-06-12-01
  925.       * @version pk-08-01-15
  926.       *
  927.       ***/
  928.     function getFieldList($debug=FALSE,$autoSave=TRUE{
  929.         if ($debug{
  930.             echoDebugMethod(__FILE__,get_class($this),"TMPL_CHAPTER_V3::getFieldList()");
  931.             echoDebug(__FILE__,"<blockquote style=\"font-size:80%\">\n");
  932.         }
  933.  
  934.         if (!$this->populateTS$this->dbPopulate($debug);
  935.         if (!is_array($this->inputFields)) {
  936.             $this->p_extractFields(FALSE,$debug);
  937.             if ($autoSave$this->dbSave($debug);
  938.         }
  939.  
  940.         $a_ret=array();         // the return array
  941.         $a_orderNrFlds=array()// temp array with sortOrder as index inputFields key as value
  942.                                 // to check sortOrder
  943.  
  944.         if ((is_array($this->inputFields)) && ($a_fldKeys=array_keys($this->inputFields))) {
  945.             $b_saveInputFields=FALSE;
  946.             foreach($a_fldKeys as $s_key{
  947.                 if ($debugechoDebug(__FILE__,"<p>checking Field$s_key</p>");
  948.  
  949.                 // loop throug input fields and create $a_orderNrFlds
  950.                 // this array is the result if we use sortOrder of the fields
  951.                 // douplicated values of sortOrder are increased
  952.                 // no ensurance that the array has gaps in order numbers
  953.                 // this will be checked later on
  954.                 $str_name=$this->inputFields[$s_key]->getName();
  955.                 if (empty($str_name)) {
  956.                     // no name set for the field -> set key as name
  957.                     $this->inputFields[$s_key]->setName($s_key);
  958.                     $b_saveInputFields=TRUE;
  959.                 }
  960.  
  961.                 if (!intval($this->inputFields[$s_key]->getOrderNr())) {
  962.                     $this->inputFields[$s_key]->setOrderNr(sizeof($a_orderNrFlds)+1);
  963.                     // ensure we have set a sortOrder
  964.                 }
  965.  
  966.                 while(isset($a_orderNrFlds[$this->inputFields[$s_key]->getOrderNr()])) {
  967.                     if ($debugecho "<p>ups DUPLICATE ORDERNR</p>";
  968.                     $this->inputFields[$s_key]->incOrderNr();
  969.                     $b_saveInputFields=TRUE;
  970.                 }
  971.  
  972.                 $a_orderNrFlds[$this->inputFields[$s_key]->getOrderNr()]=$s_key;
  973.             }
  974.  
  975.             // ok we now have an array but are there gaps in the index?
  976.             ksort($a_orderNrFlds)//sort the array by sortOrder
  977.             $i_orderNr=1;
  978.             foreach($a_orderNrFlds as $s_key{
  979.                 if ($debugecho $this->inputFields[$s_key]->getOrderNr().": ".$s_key." ".$this->inputFields[$s_key]->getLabel()."; ";
  980.                 if ($this->inputFields[$s_key]->getOrderNr <> $i_orderNr{
  981.                     $this->inputFields[$s_key]->setOrderNr($i_orderNr);
  982.                     if ($autoSave{
  983.                         // update the field to the database
  984.                         $this->saveInpField($s_key,$this->inputFields[$s_key],$debug);
  985.                     }
  986.                 else if ($b_saveInputFields && $autoSave{
  987.                     // update the field to the database
  988.                     $this->saveInpField($s_key,$this->inputFields[$s_key],$debug);
  989.                 }
  990.                 $a_ret[$i_orderNr++]=&$this->inputFields[$s_key];
  991.             }
  992.         }
  993.         if ($debugecho "</blockquote>";
  994.         return $a_ret;
  995.     }
  996.  
  997.  
  998.  
  999.  
  1000.     // #################################
  1001.  
  1002.  
  1003.  
  1004.  
  1005.  
  1006.  
  1007.     /**
  1008.       * returns a serialized array of the input fields in $postArr
  1009.       *
  1010.       * if $fldArr is an array the fields are added/replaced
  1011.       * otherwise a new array is created
  1012.       *
  1013.       * @param array $postArr 
  1014.       * @param boolean $keepServerName (replace http://SERVER_NAME/ with / ?)
  1015.       * @param boolean $debug 
  1016.       * @param array $fldArr 
  1017.       *
  1018.       * @returns string
  1019.       *
  1020.       * @version pk-04-08-05
  1021.       ***/
  1022.     function getFieldValues($postArr,$keepServerName=FALSE$debug=FALSE,$fldArr=NULL{
  1023.         if ($debugecho "<p><b>TMPL_CHAPTER_V3::getFieldValues(\$postArr array(".sizeof($postArr)."),$keepServerName,$debug,\$fldArr array(".sizeof($fldArr)."))</b> (".get_class($this).")</p>";
  1024.         if (is_array($fldArr)) {
  1025.             $retArr=$fldArr;
  1026.         else {
  1027.             $retArr=array();
  1028.         }
  1029.         // if ($debug) echo "<blockquote><pre>".htmlspecialchars(print_r($postArr,TRUE))."</pre></blockquote>";
  1030.         if (is_array($this->inputFields)) {
  1031.             reset($this->inputFields);
  1032.             while(list($key,$obj)=each($this->inputFields)) {
  1033.                 if ($debugecho "<blockquote>Object$key<pre>".pcf_print_r($obj,TRUE,3)."</pre>";
  1034.                 if (stristr($obj->className,"HTML")) {
  1035.                     if ((!$keepServerName|| ($obj->getSetting("replaceServer"))) {
  1036.                         // replace http://servername/ with / to allow more systems
  1037.                         $retArr[$obj->myName]=str_replace("http://".$_SERVER['SERVER_NAME']."/","/",$postArr[$obj->myName]);
  1038.                     else {
  1039.                         $retArr[$obj->myName]=$postArr[$obj->myName];
  1040.                     }
  1041.                 else {
  1042.                     $retArr[$obj->myName]=$postArr[$obj->myName];
  1043.                 }
  1044.             }
  1045.         else {
  1046.             if ($debugecho "<blockquote>returns NULL</blockquote><hr>";
  1047.             return "";
  1048.         }
  1049.         if ($debugecho "<blockquote>getFieldValues returns serialize of <pre>".htmlspecialchars(print_r($retArr,TRUE))."</pre></blockquote><hr>";
  1050.         return serialize($retArr);
  1051.     }
  1052.  
  1053.  
  1054.     /**
  1055.       * returns the html code for the template
  1056.       *
  1057.       * @param array $vals 
  1058.       * @param string $var 
  1059.       * @param boolean $debug 
  1060.       * @param boolean $wysiwygPreView since pk-05-08-02
  1061.       *
  1062.       * @since pk-04-07-30
  1063.       * @version pk-04-11-15
  1064.       * @version pk-05-08-02
  1065.       * @version pk-05-09-16
  1066.       *
  1067.       ***/
  1068.     function getTag($vals=array(),$var="HTMLCODE",$debug=FALSE,$wysiwygPreView=FALSE{
  1069.         if ($debugechoDebugMethod(__FILE__,get_class($this),"TMPL_CHAPTER_V3::getTag(\$vals,$var,...)");
  1070.         $arrName="tmplValArr_".$this->getId();
  1071.         global ${$arrName};
  1072.  
  1073.         if ($debug{
  1074.             echo "<blockquote><hr><p>Template: <br />".htmlspecialchars($this->{$this->colPrevix.$var})."</p>";
  1075.             echo "<p><b>Chapter Values:</b></p><pre style=\"font-size: 75%\">";print_r($vals);echo "</pre>";
  1076.             echo "<hr></blockquote>";
  1077.         }
  1078.  
  1079.         // <pk-05-08-02>
  1080.         if ($wysiwygPreView{
  1081.             $tag=$this->getPreviewPrepend()// <pk-05-09-16 /> bugfix;
  1082.         else {
  1083.             $tag="";
  1084.         }
  1085.         // </pk-05-08-02>
  1086.  
  1087.         $tag.=$this->{$this->colPrevix.$var};
  1088.  
  1089.         if ((!empty($tag)) && (is_array($vals))) {
  1090.             $tmplVals=array();
  1091.             if (is_array($this->inputFields)) {
  1092.                 foreach($this->inputFields as $fld{
  1093.                     if (isset($vals[$fld->getName()])) {
  1094.                         $tmplVals[$fld->getName()]=$fld->getHtmlTag($vals[$fld->getName()],$arrName,$debug);
  1095.                     else {
  1096.                         $tmplVals[$fld->getName()]="";
  1097.                     }
  1098.                 }
  1099.                 $tag=pcf_tmpl_parse($tag,$tmplVals,$debug);
  1100.             }
  1101.         }
  1102.         /* <pk-04-08-30> */
  1103.         if (isset($GLOBALS['OCSP_CMS']['LINKREPLACE']&& is_array($GLOBALS['OCSP_CMS']['LINKREPLACE'])) {
  1104.             if ($debugecho "<p>['CMS']['LINKREPLACE']: </p><pre>".print_r($GLOBALS['OCSP_CMS']['LINKREPLACE'],TRUE)."</pre>";
  1105.             $linkPattern="/(<a *)(href=\")([^\"]*)([^>]*)(>)/i";
  1106.             if (preg_match_all($linkPattern,$tag,$links,PREG_PATTERN_ORDER)) {
  1107.                 if ($debugecho "<hr /><p>LINKS: </p><pre>".htmlspecialchars(print_r($links,TRUE))."</pre>";
  1108.                 foreach($links[3as $lIdx => $repluri{
  1109.                     $rplTarget=FALSE;
  1110.                     if (strtoupper(substr(trim($links[3][$lIdx]),0,4)) == "HTTP"{
  1111.                         // if ($debug) echo "<p>".trim($links[3][$lIdx])." -- ".$links[4][$lIdx]."</p>";
  1112.                         if (
  1113.                             (!empty($GLOBALS['OCSP_CMS']['EXLINKDFLTTRG'])) &&
  1114.                             (!strstr("TARGET",strtoupper($links[4][$lIdx]))) &&
  1115.                             (!strstr(strtoupper($_SERVER['SERVER_NAME']),strtoupper($links[3][$lIdx])))
  1116.                            {
  1117.                             $rplTarget =$links[4][$lIdx]." target=\"".$GLOBALS['OCSP_CMS']['EXLINKDFLTTRG']."\"";
  1118.                             if ($debugecho "<p>TARGETREPLACE: ".$links[4][$lIdx]."<br />.".$rplTarget."</p>";
  1119.                         }
  1120.                     }
  1121.                     if ($debugecho("<p><b>Link $lIdx</b></p>");
  1122.                     foreach($GLOBALS['OCSP_CMS']['LINKREPLACE'as $rIdx => $rLinkArr{
  1123.                         if (strstr($repluri,$rLinkArr['SRC'])) {
  1124.                             $replWith    $links[1][$lIdx];
  1125.                             $replWith   .= $links[2][$lIdx];
  1126.  
  1127.                             $dst=$rLinkArr['DST'];
  1128.                             $dst=str_replace("\$*SRC\$",$repluri,$dst);
  1129.                             $dst=str_replace("\$*B64_SRC\$",base64_encode($repluri),$dst);
  1130.  
  1131.                             $replWith   .= $dst;
  1132.  
  1133.                             if (!empty($GLOBALS['OCSP_CMS']['LINKREPLACE'][$rIdx]['TARGET'])) {
  1134.                                 $replWith   .= $links[4][$lIdx]." target=\"".$GLOBALS['OCSP_CMS']['LINKREPLACE'][$rIdx]['TARGET']."\" ";
  1135.                             else {
  1136.                                 if ($rplTarget$replWith.=$rplTarget;
  1137.                                 else $replWith .= $links[4][$lIdx];
  1138.                             }
  1139.                             $replWith   .= $links[5][$lIdx];
  1140.  
  1141.                             if ($debugecho "<pre>\n Replace URL: \n".htmlspecialchars($links[0][$lIdx])."\n with \n".htmlspecialchars($replWith)."\n </pre>";
  1142.                             $tag=str_replace($links[0][$lIdx],$replWith,$tag);
  1143.                             // echo "<pre>\n".htmlspecialchars($repluri."\n".$dst."\n".$tag)."</pre>";
  1144.                             $rplTarget=FALSE;
  1145.                         }
  1146.                     }
  1147.                     if ($rplTarget{
  1148.                         $replWith=$links[1][$lIdx].$links[2][$lIdx].$links[3][$lIdx].$rplTarget.$links[5][$lIdx];
  1149.                         if ($debugecho "<pre>\n Replace Target URL: \n".htmlspecialchars($links[0][$lIdx])."\n with \n".htmlspecialchars($replWith)."\n </pre>";
  1150.                         $tag=str_replace($links[0][$lIdx],$replWith,$tag);
  1151.                     }
  1152.                 }
  1153.             }
  1154.         }
  1155.         /* </ pk-04-08-30> */
  1156.  
  1157.         // <pk-05-08-02>
  1158.         if ($wysiwygPreView{
  1159.             $tag.=$this->getPreviewAppend();
  1160.         }
  1161.         // </pk-05-08-02>
  1162.  
  1163.         $tag=pcf_tmpl_parse($tag,$vals)// <pk-04-11-15 /> to replace values defined in the template values (forms for example)
  1164.         return $tag;
  1165.     }
  1166.  
  1167.     /**
  1168.       * @return string 
  1169.       * @since pk-05-09-01
  1170.       ***/
  1171.     function getPreviewPrepend({
  1172.         return $this->getDBField($this->colPrevix."PREV_PREPAND");
  1173.     }
  1174.  
  1175.     /**
  1176.       * @return string 
  1177.       * @since pk-05-09-01
  1178.       ***/
  1179.     function getPreviewAppend({
  1180.         return $this->getDBField($this->colPrevix."PREV_APPEND");
  1181.     }
  1182.  
  1183. }
  1184.  
  1185. ?>

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