Source for file DBMS_FIELD_TREESELECT.phpclass

Documentation is available at DBMS_FIELD_TREESELECT.phpclass

  1. <?php
  2. /**
  3.   * Class file DBMS_FIELD_TREESELECT.phpclass
  4.   *
  5.   * @project    Open CSP-Management
  6.   * @package    dbms_field
  7.   * @category   int
  8.   *
  9.   * @author     Peter Krebs <pitlinz@users.sourceforge.net>
  10.   * @license    http://opensource.org/licenses/gpl-license.php GNU Public License
  11.   *
  12.   * @version $Id: DBMS_FIELD_TREESELECT.phpclass,v 1.9 2008/09/26 15:00:21 pitlinz Exp $
  13.   */
  14.  
  15. /**
  16.   * requirements
  17.   */
  18.  
  19. pcf_require_class('DBMS_FIELD_DBLOOKUPSELECTLIST',dirname(__FILE__"/");
  20.  
  21. /**
  22.   * Class DBMS_FIELD_TREESELECT
  23.   *
  24.   * @project    Open CSP-Management
  25.   * @package    dbms_field
  26.   * @category   int
  27.   *
  28.   * @author     Peter Krebs <pitlinz@users.sourceforge.net>
  29.   * @license    http://opensource.org/licenses/gpl-license.php GNU Public License
  30.   *
  31.   * @version pk-05-09-27
  32.   * @version $Id: DBMS_FIELD_TREESELECT.phpclass,v 1.9 2008/09/26 15:00:21 pitlinz Exp $
  33.   * @todo avoid enless loop if input data are wrog
  34.   * 
  35.   ***/
  36.     
  37.     // ---------------------------------------------------------------------------
  38.     // constants
  39.     // ---------------------------------------------------------------------------
  40.     
  41.     /**
  42.      * @constant string CLASS_SRC_FILE
  43.      */
  44.     const CLASS_SRC_FILE = __FILE__;
  45.  
  46.     // ---------------------------------------------------------------------------
  47.     // class (static)
  48.     // ---------------------------------------------------------------------------
  49.     
  50.     /*** class vars ------------------------------------------------------ */
  51.  
  52.     /*** class methods --------------------------------------------------- */    
  53.     
  54.     // ---------------------------------------------------------------------------
  55.     // object vars
  56.     // ---------------------------------------------------------------------------
  57.     
  58.     /*** compostion --------------------------------------------------- */
  59.     
  60.     /*** attributes  -------------------------------------------------- */    
  61.     
  62.     /**
  63.      * @deprecated
  64.      */
  65.     protected $classSrcFile=__FILE__;
  66.  
  67.       
  68.     // tree definition 
  69.     
  70.     /**
  71.      * parent column in the table
  72.      *
  73.      * @var string $parentField 
  74.      */    
  75.     protected $parentField        = "";
  76.  
  77.     /**
  78.      * tree root key
  79.      *
  80.      * @var int $treeROOTKey 
  81.      */
  82.     protected $treeROOTKey        = "0";
  83.  
  84.     /**
  85.       * @var string $treeROOTShowVal 
  86.       * @since pk-05-09-27
  87.       ***/
  88.     protected $treeROOTShowVal    = "Wurzel";
  89.  
  90.     /**
  91.       * rootCheckOff
  92.       * @var boolean $rootCheckOff 
  93.       * @since pk-05-01-26
  94.       ***/
  95.     protected $rootCheckOff;
  96.     
  97.     /**
  98.      * allow root select
  99.      * @var boolean $disableROOTSelect 
  100.      * @since pk-08-04-18
  101.      */
  102.     protected $disableROOTSelect     = False;
  103.     
  104.     /*** layout attributes ----------------------------------- */
  105.     
  106.     /**
  107.      * show full tree (multi selects)
  108.      *
  109.      * @var boolean $showFullTree 
  110.      */
  111.     protected $showFullTree       = False;
  112.     
  113.     /**
  114.      * show path (parents) in RO mode
  115.      *
  116.      * @var boolean $showPathRO 
  117.      */
  118.     protected $showPathRO         = False;
  119.  
  120.     /**
  121.      * number of levels to go down from the root
  122.      *
  123.      * @var int $nofLevel 
  124.      */
  125.     protected $nofLevels          = 25;    
  126.  
  127.  
  128.     /**
  129.       * @var string $intendString 
  130.       * @access protected
  131.       */
  132.     protected $intendString="&nbsp;&nbsp;";
  133.     
  134.     // ---------------------------------------------------------------------------
  135.     // factory / construct
  136.     // ---------------------------------------------------------------------------
  137.     
  138.     // ---------------------------------------------------------------------------
  139.     // getter / setter
  140.     // ---------------------------------------------------------------------------    
  141.  
  142.     protected function getClassCacheKey()
  143.     {
  144.         $str_key $this->parentField . $this->lookupTable . $this->lookupField . $this->lookupShowField . $this->lookupShowLstField . $this->lookupSort . $this->lookupWhere;
  145.         //echoDebugLine(__FILE__,__LINE__,"Class Key values " . $str_key . "<br />" . md5($str_key));
  146.         return md5($str_key);
  147.     }    
  148.     
  149.  
  150.     // ---------------------------------------------------------------------------
  151.     // OBJECT SETTINGS METHODS
  152.     // ---------------------------------------------------------------------------
  153.  
  154.     /**
  155.       * returns an array of field to bie shown in the edit form
  156.       * by using editTbl_echoForm
  157.       *
  158.       * the array is in the form:
  159.       *
  160.       * <code>
  161.       * [_sectionName_]
  162.       *      [TITLE] -> string
  163.       *      [_rowName_]
  164.       *         [FLDLAB]  (complete html code with <td></td>)
  165.       *         [FLDVAL] (complete html code with <td></td>)
  166.       * </code>
  167.       *
  168.       * @param boolean $debug 
  169.       *
  170.       * @returns array
  171.       *
  172.       * @since pk-06-07-04
  173.       *
  174.       ***/
  175.     function editTbl_getFieldEditArr($debug=False
  176.     {
  177.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_FIELD_TREESELECT::editTbl_getFieldEditArr","",0);
  178.         $a_ret=parent::editTbl_getFieldEditArr($debug);
  179.  
  180.         $a_ret['DBLOOKUP']['FLD_LSTADDVALUES']=Null;
  181.         
  182.         $a_ret['DBLOOKUP']['TREEROOTKEY']=array(
  183.             'FLDLAB'=>"TREE ROOT KEY/SHOW Value:",
  184.             'FLDVAL'=>"
  185.                         <input name=\"TREEROOTKEY\" value=\"".$this->treeROOTKey."\" size=\"10\" />
  186.                         <input name=\"treeROOTShowVal\" value=\"".$this->treeROOTShowVal."\" size=\"20\" /><br />
  187.                         <input name=\"rootCheckOff\" type=\"checkbox\" ".($this->rootCheckOff ? "checked=\"checked\"" "")." value=\"1\" /> Root nicht in DB
  188.                         <input name=\"disableROOTSelect\" type=\"checkbox\" ".($this->disableROOTSelect ? "checked=\"checked\"" """ value=\"1\" />Root <strong>nicht</strong> w&auml;hlbar
  189.                     "
  190.         );
  191.         $a_ret['DBLOOKUP']['PARENTFIELD']=array(
  192.             'FLDLAB'=>"PARENT Field:",
  193.             'FLDVAL'=>"<input name=\"PARENTFIELD\" value=\"".$this->parentField."\" size=\"40\" />"
  194.         );
  195.  
  196.         $a_ret['LAYOUT']['showFullTree']=array(
  197.             'FLDLAB'=>"Vollst&auml;ndiger Baum:",
  198.             'FLDVAL'=>"<input name=\"showFullTree\" type=\"checkbox\" ".($this->showFullTree ? "checked=\"checked\"" "")." value=\"1\" /> ALLE Werte anzeigen"
  199.         );
  200.         $a_ret['LAYOUT']['NOFLEVELS']=array(
  201.             'FLDLAB'=>"Max Anzahl Ebenen:",
  202.             'FLDVAL'=>"<input name=\"NOFLEVELS\" type=\"text\" value=\"".(intval($this->nofLevelsintval($this->nofLevels25 )."\" />"
  203.         );
  204.         $a_ret['LAYOUT']['showPathRO']=array(
  205.             'FLDLAB'=>"Pfad bei ReadOnly:",
  206.             'FLDVAL'=>'
  207.                     <select name="showPathRO" size="1">
  208.                         <option value="0" '.(($this->showPathRO==0"selected" "").' >nein nur gew&auml;hlte Werte</option>
  209.                         <option value="1" '.(($this->showPathRO==1"selected" "").' >ja in einer Zeile</option>
  210.                         <option value="2" '.(($this->showPathRO==2"selected" "").' >ja eine Zeile/Ebene</option>
  211.                     </select>
  212.                       '
  213.         );
  214.  
  215.         return $a_ret;
  216.     }
  217.  
  218.     /**
  219.       * saves the field definition
  220.       *
  221.       * @returns boolean
  222.       *
  223.       * @version pk-05-06-26
  224.       * @version pk-05-09-27
  225.       * @version pk-07-09-26 E_ALL
  226.       ***/
  227.     function save(
  228.     {
  229.         if (isset($this->treeTbl)) unset($this->treeTbl);
  230.  
  231.         // save the parent first to be sure to have the table in DBcheckEditInput
  232.         $ret=parent::save();
  233.  
  234.         $this->showAsCheckRadio =     False;
  235.                 
  236.         $this->parentField          =(isset($_POST['PARENTFIELD']$this->DBcheckEditInput($_POST['PARENTFIELD']$this->parentField);
  237.         $this->treeROOTKey          =(isset($_POST['TREEROOTKEY']$_POST['TREEROOTKEY'$this->treeROOTKey);               // pk-05-06-26 templates allowed
  238.         $this->treeROOTShowVal      =(isset($_POST['treeROOTShowVal']$_POST['treeROOTShowVal'$this->treeROOTShowVal);   // <pk-05-09-27>
  239.         $this->showFullTree         =((isset($_POST['showFullTree']&& intval($_POST['showFullTree'])) TRUE False );
  240.         $this->showPathRO           =(isset($_POST['showPathRO']intval($_POST['showPathRO']$this->showPathRO);
  241.         $this->nofLevels            =(isset($_POST['NOFLEVELS']intval($_POST['NOFLEVELS']$this->nofLevels);
  242.         $this->rootCheckOff         =((isset($_POST['rootCheckOff']&& intval($_POST['rootCheckOff'])) TRUE False);
  243.         $this->disableROOTSelect    =((isset($_POST['disableROOTSelect']&& intval($_POST['disableROOTSelect'])) TRUE False);
  244.         
  245.         if (!$this->showFullTree)   $this->reloadFormOnChange=TRUE;
  246.  
  247.         return $ret;
  248.     }
  249.  
  250.     // -----------------------------------------------------------
  251.     // DB value methods
  252.     // -----------------------------------------------------------
  253.     
  254.     /**
  255.       * returns the database query
  256.       *
  257.       * @param boolean $debug 
  258.       *
  259.       * @return string 
  260.       *
  261.       * @since pk-07-09-03
  262.       * @version pk-08-08-01
  263.       * 
  264.       */
  265.     function getMyValueQuery($debug=False)
  266.     {
  267.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_FIELD_TREESELECT::getMyValueQuery()");
  268.  
  269.         $str_query ="SELECT ".$this->lookupField . " AS KEYFIELD";
  270.         $str_query.="," .$this->lookupShowField . " AS SHOWFIELD";
  271.         if (!empty($this->lookupShowLstField))
  272.         {
  273.             $str_query.="," .$this->lookupShowLstField . " AS SHOWLIST";
  274.         else {
  275.              $str_query.="," .$this->lookupShowField . " AS SHOWLIST";
  276.         }
  277.         $str_query.="," .$this->parentField . " AS PARENTFIELD";
  278.         $str_query.=" FROM ".$this->lookupTable;
  279.  
  280.         if (!empty($this->lookupWhere)) // <pk-05-08-10>
  281.             require_once __OCSP_PHPINCPATH__."common/pcf_templates.phpinc";
  282.             $str_query.=" WHERE ".$this->lookupWhere;
  283.         }
  284.  
  285.         if (empty($this->lookupSort)) {
  286.             $str_query.=" ORDER BY ".$this->parentField.",".$this->lookupField;
  287.         else {
  288.             $str_query.=" ORDER BY ".$this->parentField.",".$this->lookupSort;
  289.         }
  290.  
  291.         if ($debugechoDebugLine(__FILE__,__LINE__,"getMyValueQuery: <br/>".$str_query);
  292.         return $str_query;
  293.      }
  294.  
  295.     /**
  296.       * sets populates $this->myValues array from the database
  297.       *
  298.       * @param string $arrName 
  299.       * @param boolean $debug 
  300.       *
  301.       * @return int size of $this->myValues
  302.       *
  303.       * @since pk-07-09-03
  304.       * @version pk-08-08-01
  305.       */
  306.     function setMyValues($arrName="DBVAL",$debug=False
  307.     {              
  308.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_FIELD_TREESELECT::setMyValues($arrName,...)");        
  309.         global ${$arrName};
  310.         
  311.         if (empty($this->myDataArrName)) $this->myDataArrName=$arrName;
  312.         $str_cacheId $this->getClassCacheKey();
  313.         
  314.         if (
  315.             !isset(self::$classValPopulateTs[$str_cacheId|| 
  316.             self::$classValPopulateTs[$str_cacheId(time(ini_get('max_execution_time'))
  317.         )
  318.         {
  319.             // load the values from the db
  320.             $str_query OCSP_TEMPLATE::parse($this->getMyValueQuery(),${$arrName});
  321.             if ($debugechoDebugLine(__FILE__,__LINE__,"query: "$str_query);
  322.             if ($obj_cursor OCSP_OBJ::defaultReadDBObj()->query($str_query))
  323.             {
  324.                 while($arr_row $obj_cursor->fetchArrayFld())
  325.                 {
  326.                     self::$classCache[$str_cacheId]['ROWS'][$arr_row['KEYFIELD']] $arr_row;
  327.                     $mix_parentKey (empty($arr_row['PARENTFIELD']$arr_row['PARENTFIELD']);
  328.                     self::$classCache[$str_cacheId]['CHILDREN'][$mix_parentKey][$arr_row['KEYFIELD'];
  329.                 }
  330.                 self::$classValPopulateTs=time();
  331.             }
  332.         }        
  333.  
  334.         $this->myValues = array();
  335.         if (empty($this->treeROOTKey)) $this->treeROOTKey=0;
  336.  
  337.         if (isset(self::$classCache[$str_cacheId]['ROWS'][$this->treeROOTKey]))
  338.         {
  339.             $this->myValues[$this->treeROOTKeyself::$classCache[$str_cacheId]['ROWS'][$this->treeROOTKey];
  340.         }
  341.  
  342.         if (is_array(self::$classCache[$str_cacheId]['CHILDREN'][$this->treeROOTKey]))
  343.         {
  344.             foreach(self::$classCache[$str_cacheId]['CHILDREN'][$this->treeROOTKeyas $mix_childKey)
  345.             {
  346.                 if (!isset($this->myValues[$mix_childKey])) // to avoid miss configured tree errors
  347.                 {
  348.                     if (isset(self::$classCache[$str_cacheId]['ROWS'][$mix_childKey]))
  349.                     {
  350.                         $this->myValues[$mix_childKey$this->intendString . self::$classCache[$str_cacheId]['ROWS'][$mix_childKey]['SHOWFIELD'];
  351.                         $this->setMyChildValues($str_cacheId,$mix_childKey,$this->intendString,1,$debug);
  352.                     }
  353.                 
  354.             }
  355.         }
  356.  
  357.         return sizeof($this->myValues);
  358.     }
  359.  
  360.     
  361.     /**
  362.      * adds children of $key to $this->myValues
  363.      *
  364.      * @param mixed $key 
  365.      * @param string $intend 
  366.      * @param int $level 
  367.      * @param string showCol
  368.      * @param boolean $debug 
  369.      * 
  370.      * @since pk-08-04-15
  371.      * @version pk-08-09-26
  372.      */
  373.     protected function setMyChildValues($cacheId,$key,$intend,$level=0,$debug=False)
  374.     {
  375.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_FIELD_TREESELECT::setMyChildValues({$cacheId},{$key}, ,{$level})");
  376.         
  377.         if ($level <= $this->nofLevels)
  378.         {
  379.             if (isset(self::$classCache[$cacheId]['CHILDREN'][$key]&& is_array(self::$classCache[$cacheId]['CHILDREN'][$key]))
  380.             {
  381.                 foreach(self::$classCache[$cacheId]['CHILDREN'][$keyas $mix_childKey)
  382.                 {
  383.                     if (!isset($this->myValues[$mix_childKey]))
  384.                     {
  385.                         if (isset(self::$classCache[$cacheId]['ROWS'][$mix_childKey]))
  386.                         {
  387.                             $this->myValues[$mix_childKey$intend $this->intendString . self::$classCache[$cacheId]['ROWS'][$mix_childKey]['SHOWFIELD'];
  388.                             $this->setMyChildValues($cacheId,$mix_childKey,$intend $this->intendString,($level 1));
  389.                         else {
  390.                             echoDebugLine(__FILE__,__LINE__,$mix_childKey " has no row set");
  391.                         }
  392.                     else if($debug{
  393.                         echoDebugLine(__FILE__,__LINE__,$mix_childKey "already set");
  394.                     }
  395.                 }
  396.             else if($debug{
  397.                 echoDebugLine(__FILE__,__LINE__,$key " has no children");
  398.             }
  399.         else {
  400.             if ($debugechoDebugLine(__FILE__,__LINE__,"Max levels reached");
  401.         }
  402.      
  403.     }
  404.     
  405.     /**
  406.       * returns the html-code for a level select
  407.       *
  408.       * @param array $childArr 
  409.       * @param int $countSelects 
  410.       * @param int $level 
  411.       * @param mixed $aValue 
  412.       * @param string $arrName 
  413.       * @param boolean $debug 
  414.       *
  415.       * @returns string
  416.       *
  417.       * @since pk-04-08-31
  418.       *
  419.       ***/
  420.     function getLevelSelect($childArr,$countSelects,$level,$aValue,$arrName="DBVAL",$debug=False{
  421.         $debug=($debug || $this->fldDebug);
  422.         if ($debugecho "<p><b>DBMS_FIELD_TREESELECT::getLevelSelect(\$childArr (".sizeof($childArr)."),$countSelects,$level,$aValue,$arrName,..</b> (".get_class($this).")</p>";
  423.  
  424.         $selName=$arrName."_".$this->myName."_".$level;
  425.         $df="document.forms['".$this->getMyFormName()."']";
  426.         $ret ="\n\t<select name=\"".$selName."\" onChange=\"\n";
  427.         $ret.="\n\t         setElemValByName($df,'".$arrName."[".$this->myName."]',$df.$selName.options[$df.$selName.selectedIndex].value);";
  428.         $ret.="\n\t         $df.action='".$_SERVER['REQUEST_URI']."#".$this->myName."';";
  429.         $ret.="\n\t         $df.submit();";
  430.         $ret.="\n\t     \" size=\"1\">\n";
  431.  
  432.         if ($level==0{
  433.             if ($this->allowNullSelect{
  434.                 $ret.="\t\t<option value=\"".$this->treeROOTKey."\">".$this->nullLabel."</option>\n";
  435.             }
  436.         else {
  437.             $ret.="\t\t<option value=\"".$childArr[0]['PARENTFIELD']."\">--- ??? ---</option>\n";
  438.         }
  439.         if (is_array($childArr)) {
  440.             reset($childArr);
  441.             while(list($key,$row)=each($childArr)) {
  442.                 $ret.=$this->getNotIntendedOption($row,$aValue);
  443.             }
  444.         }
  445.  
  446.         $ret.="\n\t</select>\n";
  447.         return $ret;
  448.     }
  449.  
  450.     /**
  451.       * returns the html code for level select fields
  452.       *
  453.       * @param mixed $aValue 
  454.       * @param string $arrName 
  455.       * @param boolean $debug 
  456.       *
  457.       * @returns string
  458.       *
  459.       * @since pk-04-08-31
  460.       *
  461.       ***/
  462.     function getLevelSelectFields($aValue="",$arrName="DBVAL",$debug=False{
  463.         $debug=($debug || $this->fldDebug);
  464.         if ($debugecho "<p><b>DBMS_FIELD_TREESELECT::getLevelSelectFields($aValue,$arrName,...)</b> (".get_class($this).")</p>";
  465.  
  466.         $level=0;
  467.         $ret="";
  468.         if (($treeDesc=$this->getPCF_TreeDesc($arrName,$debug)) && ($treePath=pcf_getTreePath($treeDesc,$aValue,$debug))) {
  469.             $countSelects=sizeof($treePath);
  470.             while($level $countSelects{
  471.                 if ($childArr=pcf_getTreeChildArray($treeDesc,$treePath[$level]['PARENTFIELD'],$debug)) {
  472.                     $ret.=$this->getLevelSelect($childArr,$countSelects,$level,$treePath[$level]['KEYFIELD'],$arrName,$debug);
  473.                 else {
  474.                     // ERROR -> go out
  475.                     break;
  476.                 }
  477.                 $level++;
  478.             }
  479.  
  480.             if ($childArr=pcf_getTreeChildArray($treeDesc,$treePath[($level-1)]['KEYFIELD'],$debug)) {
  481.                 $m_key=(isset($treePath[($level-1)]['KEYFIELD']$treePath[($level-1)]['KEYFIELD'NULL)// <pk-06-08-03 /> E_ALL
  482.                 $ret.=$this->getLevelSelect($childArr,$countSelects,$level++,$m_key,$arrName,$debug);
  483.             }
  484.         else if ($childArr=pcf_getTreeChildArray($treeDesc,$this->treeROOTKey,$debug)) {
  485.             $countSelects=0;
  486.             $ret.=$this->getLevelSelect($childArr,$countSelects,$level++,$aValue,$arrName,$debug);
  487.         else if ($this->allowNullSelect{
  488.             $ret.= $this->nullLabel;
  489.         else if (empty($this->newUrl)) {
  490.             $ret.= "ERROR NO VALUES IN TREE";
  491.         else {
  492.             $ret.= "Sie mssen eine Datensatz einf&uuml;gen";
  493.         }
  494.  
  495.         $ret.= "<input type='hidden' name='".$arrName."[".$this->myName."]' value=\"".htmlspecialchars($aValue)."\">";
  496.         $ret.= $this->getAddButton($arrName);
  497.         $ret.= $this->getReloadButton($arrName);
  498.  
  499.         unset($treePath);
  500.  
  501.         return $ret;
  502.     }
  503.  
  504.     /**
  505.       * returns the html code
  506.       *
  507.       * @param string $aValue 
  508.       * @param array $arrName 
  509.       * @param boolean $debug 
  510.       *
  511.       * @returns string
  512.       *
  513.       * @version pk-04-08-31 $debug added
  514.       * @version pk-05-09-16
  515.       *
  516.       ***/
  517.     function getInputTag($aValue,$arrName="DBVAL",$debug=False)
  518.     {
  519.         if (!empty($arrName)) $this->myDataArrName=$arrName;
  520.         $debug=($debug || $this->fldDebug)// <pk-04-08-31>
  521.         if ($debugechoDebugMethod(__FILE__,get_class($this),__CLASS__."::getInputTag(\$aValue,\$arrName,...) [".$this->myName."]",print_r($aValue,TRUE));
  522.  
  523.         if ($this->showFullTree{
  524.             return parent::getInputTag($aValue,$arrName,$debug);
  525.         else {
  526.             $str_ret .= "TODO levelselect";
  527.             /*
  528.              * @todo
  529.              
  530.             $str_ret = $this->getLevelSelectFields($aValue,$this->myDataArrName,$debug);
  531.             $str_ret.= $this->getAddTag($this->myDataArrName);
  532.               */
  533.             return $str_ret;
  534.         }
  535.     }
  536.  
  537.     /**
  538.       * returns the field value if the referenzed row exists
  539.       *
  540.       * @param  string  $aValue     the value
  541.       * @param  array   $err        error array
  542.       * @param  string  $arrName    name of the array to access fieldsarray  gloabl ${$arrName}
  543.       * @param  bool    $debug 
  544.       *
  545.       * @return string 
  546.       *
  547.       * @since   pk-05-01-26
  548.       * @version pk-05-10-05
  549.       *
  550.       ***/
  551.     function getValue($aValue,&$err,$arrName="DBVAL",$debug=False{
  552.         $debug=($debug || $this->fldDebug);
  553.         if ($debugecho "<hr><p><b>DBMS_FIELD_TREESELECT::getValue($aValue,$err,$arrName,$debug)</b> (".get_class($this)." | ".$this->myName.")</p>";
  554.  
  555.         if (($aValue == $this->treeROOTKey&& ($this->rootCheckOff))
  556.         {
  557.             if ($this->disableROOTSelect)
  558.             {
  559.                 return parent::getValue(Null,$err,$arrName,$debug);
  560.             else {
  561.                 return $aValue;
  562.             }
  563.         }
  564.         return parent::getValue($aValue,$err,$arrName,$debug);
  565.     }
  566.  
  567.  
  568.     /**
  569.       * returns the screen value
  570.       *
  571.       * @param mixed $aValue 
  572.       * @param string $arrname 
  573.       * @param boolean $debug 
  574.       *
  575.       * @returns string
  576.       *
  577.       * @todo DBMS_FIELD_TREESELECT::getScreenValue showPathRO
  578.       ***/
  579.     function getScreenValue($aValue=NULL,$arrName="DBVAL",$debug=False{
  580.         if ($this->showPathRO{
  581.             return parent::getScreenValue($aValue,$arrName,$debug);
  582.             /*
  583.             $ret="";
  584.             if ($treePath=pcf_getTreePath($this->getPCF_TreeDesc($arrName),$aValue,$debug)) {
  585.                 reset($treePath);
  586.                 $sep="";
  587.                 while(list($key,$row)=each($treePath)) {
  588.                     switch ($this->showPathRO) {
  589.                         case 1:
  590.                             $ret.= $sep.$row['SHOWFIELD'];
  591.                             $sep = htmlspecialchars(" -> ");
  592.                             break;
  593.                         case 2:
  594.                             $intend=htmlspecialchars($row['_INTEND']);
  595.                             $intend=str_replace(" ","&nbsp;",$intend);
  596.                             $ret.= $sep.$intend.$row['SHOWFIELD'];
  597.                             $sep = "<br />";
  598.                             break;
  599.                         default:
  600.                             $ret.= $row['SHOWFIELD']." ";
  601.                     }
  602.                 }
  603.             }
  604.             */
  605.             return $ret;
  606.         else {
  607.             return parent::getScreenValue($aValue,$arrName,$debug);
  608.         }
  609.     }
  610.  
  611.     /**
  612.       * returns a html select with all values (distinct) where $aValue
  613.       * is selected
  614.       *
  615.       * NOTE only works on database fields
  616.       *
  617.       * @param mixed $aValue 
  618.       * @param string $arrName 
  619.       * @param string $selTagAdd added into <select ...>
  620.       * @param string $whereCond added to query ($s_query="SELECT ... FROM TABLE ".$whereCond)
  621.       *
  622.       * @return string 
  623.       *
  624.       * @since pk-05-10-18
  625.       *
  626.       * @todo object value tables
  627.       *
  628.       * @var array $a_treeDesc 
  629.       * @var array $a_treeArr 
  630.       ***/
  631.     function getTableValSelect(&$aValue,$arrName="",$selTagAdd="",$whereCond="",$nullLabel="",$debug=False{
  632.         $debug=($debug || $this->fldDebug);
  633. $debug=TRUE;
  634.         if ($debugecho "<p><b>DBMS_FIELD::getTableValSelect(aValue=".$aValue.",arrName=".$arrName.")</b> (".get_class($this).")</p>\n";
  635.  
  636.         $a_treeDesc=$this->getPCF_TreeDesc($arrName);
  637.  
  638.         if ($a_treeArr=pcf_getTreeArray($a_treeDesc,$this->treeROOTKey,"","",$this->nofLevels,$debug)) {
  639.             if ($debugecho "<pre>".print_r($a_treeArr,TRUE)."</pre>";
  640.             if (!empty($arrName)) {
  641.                 $s_selName=$arrName."[".$this->myName."]";
  642.             else {
  643.                 $s_selName=$this->myName;
  644.             }
  645.             $ret="\n<select name=\"".$s_selName."\" ".$selTagAdd.">\n";
  646.             if (!empty($nullLabel)) {
  647.                 $ret.="\t<option value=\"\">".$nullLabel."</option>\n";
  648.             else if ($this->searchGroup_allowAll{
  649.                 $ret.="\t<option value=\"\">--- ??? ---</option>\n";
  650.             }
  651.  
  652.  
  653.             foreach($a_treeArr as $a_treeNode{
  654.                 if ($debugecho "<p>Value$aValue Row".$a_treeNode['KEYFIELD'];
  655.                 $s_query ="SELECT COUNT(*) FROM ".$this->myTable;
  656.                 if (!empty($whereCond)) {
  657.                     $s_query.=$whereCond;
  658.                     $s_query.=" AND ".$this->myName."=".$GLOBALS['USRDB']->qs_getSlashedValue($a_treeNode['KEYFIELD']);
  659.                 else {
  660.                     $s_query.=" WHERE ".$this->myName."=".$GLOBALS['USRDB']->qs_getSlashedValue($a_treeNode['KEYFIELD']);
  661.                 }
  662.                 if ($debugecho "<p>".$s_query."</p>";
  663.  
  664.                 $i_nofEntries=intval($GLOBALS['USRDB']->quickQuery($s_query,0));
  665.  
  666.                 $ret.= "\t<option value=\"".$a_treeNode['KEYFIELD']."\"";
  667.                 if ((empty($nullLabel)) && (!$this->searchGroup_allowAll&& (empty($aValue))) {
  668.                     // no null Label -> we have to set the $aValue called by ref
  669.                     $aValue=$a_treeNode['KEYFIELD'];
  670.                 }
  671.  
  672.                 if (strval($aValue)===($a_treeNode['KEYFIELD'])) {
  673.                     if ($debugecho " <b>SELECTED</b>";
  674.                     $ret.= " selected";
  675.                 else if (!$i_nofEntries{
  676.                     $ret.= " disabled";
  677.                 }
  678.  
  679.                 if ($debugecho "</p>";
  680.                 $ret.= ">&nbsp;&nbsp;".$a_treeNode['_INTEND'].$a_treeNode['SHOWFIELD']." (".$i_nofEntries.")</option>\n";
  681.             }
  682.             $ret.="\n</select>";
  683.         }
  684.  
  685.         return $ret;
  686.     }
  687.  
  688. }
  689. ?>

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