Source for file DBMS_FIELD_SELECTLIST.phpclass

Documentation is available at DBMS_FIELD_SELECTLIST.phpclass

  1. <?php
  2. /**
  3.   * Class file DBMS_FIELD_SELECTLIST.phpclass
  4.   *
  5.   * @project    Open CSP-Management
  6.   * @package    dbms_field
  7.   * @category   any
  8.   *
  9.   * @author     Peter Krebs <pitlinz@sourceforge.net>
  10.   * @license    http://opensource.org/licenses/gpl-license.php GNU Public License
  11.   *
  12.   * @version $Id: DBMS_FIELD_SELECTLIST.phpclass,v 1.33 2008/11/24 23:30:31 pitlinz Exp $
  13.   *  
  14.   */
  15.  
  16. if (!class_exists('DBMS_FIELD'))
  17. {
  18.     require_once dirname(__FILE___OCSP_DIRSEP_ "DBMS_FIELD.phpclass";
  19. }
  20.  
  21. if (!interface_exists('INFA_DBMS_FIELD_SELECTLIST'))
  22. {
  23.     require_once dirname(__FILE___OCSP_DIRSEP_ "INFA_DBMS_FIELD_SELECTLIST.phpclass";    
  24. }
  25.  
  26.  
  27. /**
  28.   * Class DBMS_FIELD_SELECTLIST
  29.   *
  30.   * handels select fields (&lt;SELECT&gt;)
  31.   * the class holds all values available in $this->myValues
  32.   *
  33.   *
  34.   * in case of multiselect
  35.   * serialization is done with expolde and implode functions
  36.   * the default seperator is "\n" make sure the database column
  37.   * is big enough to hold all the values.
  38.   *
  39.   *
  40.   * @project    Open CSP-Management
  41.   * @package    dbms_field
  42.   * @category   any
  43.   *
  44.   * @author     Peter Krebs <pitlinz@sourceforge.net>
  45.   * @license    http://opensource.org/licenses/gpl-license.php GNU Public License
  46.   *
  47.   * @version pk-06-02-10
  48.   * @version $Id: DBMS_FIELD_SELECTLIST.phpclass,v 1.33 2008/11/24 23:30:31 pitlinz Exp $
  49.   */
  50.     extends DBMS_FIELD
  51.     implements INFA_DBMS_FIELD_SELECTLIST
  52. {
  53.     /**
  54.       * source file of the class
  55.       *
  56.       * @var string $classSrcFile 
  57.       * @since pk-04-10-05
  58.       ***/
  59.     protected $classSrcFile=__FILE__;
  60.  
  61.     // ###########################################################
  62.     // OBJECT (CONST) VAR DECLARATION
  63.     // ###########################################################
  64.  
  65.     /**
  66.       * @var array $myValues 
  67.       * @access protected
  68.       */
  69.     protected $myValues      = array();
  70.  
  71.     /**
  72.       * @var boolean $multiselect 
  73.       * @access protected
  74.       */
  75.     protected $multiselect   = False;
  76.  
  77.     /**
  78.       * @var boolean $showListNullEntry 
  79.       * @since pk-04-08-31
  80.       * @access protected
  81.       ***/
  82.     protected $showNullOption     = False;
  83.  
  84.     /**
  85.       * @var string $nullLabel 
  86.       * @access protected
  87.       */
  88.     protected $nullLabel          = "--- ??? ---";
  89.  
  90.     /**
  91.       * @var boolean $nullToZero set the NullOptionValue to 0
  92.       * @since pk-05-12-12
  93.       * @access protected
  94.       ***/
  95.     protected $nullToZero         = False;
  96.  
  97.     /**
  98.       * @var int $selectsize (added into &lt;select ... size=&quote;$this->selectsize&quote; ... &gt;)
  99.       * @access protected
  100.       */
  101.     protected $selectsize    = 1;
  102.  
  103.     /**
  104.       * @var string $selectAddTag (additional html tag attributes for &lt;select ...&gt;)
  105.       * @access protected
  106.       */
  107.     protected $selectAddTag       = "";
  108.  
  109.     /**
  110.       * @var int $reloadFormOnChange (if >0 a onChange event forces to reload the form)
  111.       * @since pk-04-09-15
  112.       ***/
  113.     protected $reloadFormOnChange = 0;
  114.  
  115.  
  116.     /**
  117.       * @staticvar boolean $static_fixedSelSize 
  118.       * @since pk-05-08-29
  119.       * @access protected
  120.       ***/
  121.     protected $static_fixedSelSize=False;
  122.  
  123.     /**
  124.       * use a table of checkboxes or radio boxes instead of
  125.       * a select
  126.       * @var boolean $showAsCheckRadio 
  127.       * @since pk-05-09-16
  128.       * @access protected
  129.       ***/
  130.     protected $showAsCheckRadio=False;
  131.  
  132.  
  133.     /**
  134.       * show not in list values
  135.       * if true all values of $valArr are added to the list
  136.       * even if the are not in myValues
  137.       * @var boolean $notInLstValues 
  138.       * @since pk-05-12-01
  139.       * @access protected
  140.       ***/
  141.     protected $notInLstValues=False;
  142.  
  143.     /**
  144.       * seperator used in multiselect mode
  145.       * NOTE: this::save() sets this too
  146.       * @var char $mySeperator 
  147.       * @since pk-06-02-10
  148.       * @access protected
  149.       ***/
  150.     protected $mySeperator="\n";
  151.  
  152.     /**
  153.       * do not htmlspecialchars list values
  154.       * @var boolean $lstValueIsHtml 
  155.       * @since pk-06-05-29
  156.       * @access protected
  157.       ***/
  158.     protected $lstValueIsHtml=False;
  159.  
  160.     /**
  161.       * wether to lookup in the select list for the representation of a value
  162.       * or just output the value in list view
  163.       * @var boolean $showValuesInList 
  164.       * @since pk-06-07-22
  165.       * @access protected
  166.       ***/
  167.     protected $showValuesInList=False;
  168.  
  169.     /**
  170.       * @var boolean $ajax_onChange_FuncName 
  171.       * @since pk-07-03-07
  172.       * @access protected
  173.       ***/
  174.     protected $ajax_onChange_FuncName=NULL;
  175.  
  176.     /**
  177.      * xtype to use in the extJS framework for the field
  178.      * 
  179.      * @var string $extJSxType 
  180.      */
  181.     protected $extJSxType = 'combo';     
  182.     
  183.     // ###########################################################
  184.     // OBJECT SETTINGS METHODS
  185.     // ###########################################################
  186.  
  187.  
  188.     // ###########################################################
  189.     // OBJECT DATA METHODS
  190.     // ###########################################################
  191.  
  192.     /**
  193.       * extracts the array out of the input string
  194.       * where it is inter like
  195.       * <code>
  196.       *     key:value\n
  197.       * </code>
  198.       *
  199.       * @param string $str 
  200.       *
  201.       * @returns array
  202.       *
  203.       ***/
  204.     function getArrayFromString($str{
  205.         $str_ret=NULL;
  206.         if ($arr=explode("\n",$str)) {
  207.             $str_ret=array();
  208.             while(list($line,$keyVal)=each($arr)) {
  209.                 if ($keyVal != "\n"{
  210.                     $tmp=explode(":",$keyVal,2);
  211.                     if ((!empty($tmp[0])) || ($tmp[0=== "0")) {
  212.                         if (isset($tmp[1]&& !empty($tmp[1]))
  213.                         {
  214.                             $str_ret[$tmp[0]]=$tmp[1];
  215.                         else {
  216.                             $str_ret[$tmp[0]]=$tmp[0];
  217.                         }
  218.                     }
  219.                 }
  220.             }
  221.         }
  222.         foreach($str_ret as $key => $val{
  223.             $str_ret[$key]=str_replace("\n","",$val);
  224.             $str_ret[$key]=str_replace("\r","",$val);
  225.         }
  226.         return $str_ret;
  227.     }
  228.  
  229.  
  230.     /**
  231.       * does nothing in this class becaus $this->myValues
  232.       * is stored internal. Is redefined in descendants
  233.       * make sure this is called once before accessing
  234.       * $this->myValues
  235.       *
  236.       * @param string $arrName 
  237.       * @param bool $debug 
  238.       *
  239.       * @version pk-03-12-18
  240.       *
  241.       ***/
  242.     function setMyValues($arrName="DBVAL",$debug=False
  243.     {
  244.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_FIELD_SELECTLIST::setMyValues()","<pre>" print_r($this->myValues,True."</pre>");
  245.         //overwrite in subclasses if needed
  246.     }
  247.  
  248.     // -----------------------------------------------------------
  249.     // ajax
  250.     // -----------------------------------------------------------
  251.  
  252.     
  253.     /**
  254.       * returns the html select tag onChange statement to reload the form
  255.       *
  256.       * @param array $arrName 
  257.       *
  258.       * @since pk-04-08-18
  259.       *
  260.       ***/
  261.     function getOnChangedTag(
  262.     {
  263.         return " onChange=\"ocsp_from_fieldChanged('".$this->myForm->getHTMLName()."','".$this->getJsName()."',this.value);\"";
  264.     }
  265.  
  266.  
  267.     // ###########################################################
  268.     // OBJECT HTML FORM METHODS
  269.     // ###########################################################
  270.  
  271.     /**
  272.       * returns the html code
  273.       *
  274.       * @param string $aValue 
  275.       * @param array $arrName 
  276.       * @param boolean $debug 
  277.       *
  278.       * @returns string
  279.       *
  280.       * @version pk-04-08-31 $debug added
  281.       * @version pk-05-09-16
  282.       *
  283.       ***/
  284.     function getInputTag($aValue,$arrName="DBVAL",$debug=False)
  285.     {
  286.         if (!empty($arrName)) $this->myDataArrName=$arrName;
  287.         $debug=($debug || $this->fldDebug)// <pk-04-08-31>
  288.  
  289.         if ($debugechoDebugMethod(__FILE__,get_class($this),__CLASS__."::getInputTag(\$aValue,\$arrName,...) [".$this->getKey()."]","\$aValue=".print_r($aValue,TRUE));
  290.  
  291.         if (intval($this->showAsCheckRadio)) {
  292.             return $this->getCheckRadio($aValue,$arrName,$debug);
  293.         else {
  294.             return $this->getSelectTag($aValue,$arrName,$debug);
  295.         }
  296.     }
  297.  
  298.     /**
  299.       * returns the html code for the select
  300.       *
  301.       * @param string $aValue 
  302.       * @param array $arrName 
  303.       * @param boolean $debug 
  304.       *
  305.       * @returns string
  306.       *
  307.       * @since pk-05-05-16
  308.       * @version pk-06-02-10
  309.       *
  310.       * @deprecated since pk-08-02-06
  311.       */
  312.     protected function getSelectTag($aValue,$arrName="DBVAL",$debug=False{
  313.         $debug=($debug || $this->fldDebug)// <pk-04-08-31>
  314.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_FIELD_SELECTLIST::getSelectTag()","\$aValue=".print_r($aValue,TRUE)."<br />\n\$arrName$arrName");
  315.  
  316.         $str_tag "";
  317.         
  318.         //$s_tag = $this->js_getFieldScript($debug);
  319.         $str_tag .= $this->getFormFieldSelect($aValue,$debug);
  320.         
  321.         return $str_tag;
  322.  
  323.     }
  324.  
  325.     /**
  326.       * returns the html code for the checkbox or radiobox table
  327.       *
  328.       * @param string $aValue 
  329.       * @param array $arrName 
  330.       * @param boolean $debug 
  331.       *
  332.       * @returns string
  333.       *
  334.       * @since pk-05-05-16
  335.       * @version pk-06-02-10
  336.       *
  337.       * @var string $s_tag 
  338.       * @var string $s_input 
  339.       * @var string $s_onChange 
  340.       * @var int $i_colNr 
  341.       *
  342.       * @todo notInLstValues
  343.       *
  344.       * @version pk-06-10-30 bugfix 1 entry uses 2 columsn
  345.       *
  346.       ***/
  347.     function getCheckRadio($aValue,$arrName="DBVAL",$debug=False{
  348.         $debug=($debug || $this->fldDebug)// <pk-04-08-31>
  349.         if ($debug{
  350.             echoDebugMethod(__FILE__,get_class($this),"DBMS_FIELD_SELECTLIST::getCheckRadio()",$aValue."\n Size: ".$this->selectsize);
  351.         }
  352.  
  353.         if ($this->multiselect{
  354.             $s_input="<input type=\"checkbox\" name=\"".$arrName."[".$this->myName."][]"."\" ";
  355.         else {
  356.             $s_input="<input type=\"radio\" name=\"".$arrName."[".$this->myName."]"."\" ";
  357.         }
  358.  
  359.         if ($this->reloadFormOnChange{
  360.             $s_input.=$this->getOnChangedTag($arrName);
  361.         }
  362.  
  363.         if (!($a_ValArr=explode($this->mySeperator,$aValue))) // <pk-06-02-10 />
  364.             $a_ValArr=array();
  365.             $a_ValArr[]=$aValue;
  366.         }
  367.  
  368.         if ($debugechoDebug(__FILE__,"<pre>Values: \n".print_r($a_ValArr,TRUE)."</pre>");
  369.         if ($debugechoDebug(__FILE__,"<p>SelectSize: ".intval($this->selectsize)."</p>");
  370.  
  371.  
  372.         $s_tag "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" style=\"border:none;margin:0px;padding:0px\" align=\"center\">";
  373.         $s_tag.="<tr>\n";
  374.         $i_colNr=0;
  375.         // null value
  376.         if (($this->showNullOption&& (!$this->multiselect)) {
  377.             if ($this->nullToZero$s_nullValue="0"else $s_nullValue="";
  378.             $s_tag.="\t<td align=\"right\" valign=\"top\">".$s_input." value=\"".$s_nullValue."\" ".(empty($aValue"checked" "")."></td><td>".$this->nullLabel."</td>\n";
  379.             $i_colNr++;
  380.         }
  381.  
  382.         $this->setMyValues($this->myDataArrName,$debug);
  383.         if (!intval($this->selectsize)) $this->selectsize=1;
  384.  
  385.  
  386.         if (is_array($this->myValues)) {
  387.             if ($debugecho "<pre>getCheckRadio::myValues\n".print_r($this->myValues,TRUE)."</pre>";
  388.             foreach($this->myValues as $key => $s_val{
  389.                 if ($i_colNr >= $this->selectsize{
  390.                     $s_tag.="</tr>\n";
  391.                     $s_tag.="<tr>\n";
  392.                     $i_colNr=0;
  393.                 }
  394.                 $s_tag.="\t<td align=\"right\" valign=\"top\">".$s_input ."value=\"".htmlspecialchars($key)."\" ";
  395.                 // if ((!empty($key) || ($key==="0")) && in_array($key,$a_ValArr)) $s_tag.="checked"; // <pk-06-07-28 />
  396.                 if (in_array($key,$a_ValArr)) $s_tag.="checked"// <pk-06-08-19 /> a array key can't be NULL
  397.                 $s_tag.=" ></td><td>".$s_val."</td>";
  398.                 $i_colNr++;
  399.             }
  400.         }
  401.  
  402.         while ($i_colNr++ < $this->selectsize$s_tag.="\t<td colspan=\"2\">&nbsp;</td>\n"// <pk-06-10-30 />
  403.  
  404.         $s_tag.="</tr>\n";
  405.         $s_tag.="</table>\n";
  406.  
  407.         if ($this->reloadFormOnChange{
  408.             $s_tag.=$this->getReloadButton($arrName);
  409.         }
  410.         $s_tag.="\n";
  411.         return $s_tag;
  412.     }
  413.  
  414.  
  415.  
  416.     /**
  417.       *
  418.       * returns the html code for the readonly field
  419.       *
  420.       * @param mixed $aValue 
  421.       * @param string $arrName 
  422.       * @param boolean $debug 
  423.       *
  424.       * @returns string
  425.       *
  426.       * @version pk-04-09-08
  427.       * @version pk-06-02-10
  428.       *
  429.       ***/
  430.     function getScreenValue($aValue,$arrName="DBVAL",$debug=False{
  431.         $debug=($debug || $this->fldDebug);
  432.         if ($debugecho "<hr /><p><b>DBMS_FIELD_SELECTLIST::getScreenValue($aValue,$arrName,...)</b></p>";
  433.  
  434.         $this->setMyValues($arrName,$debug);
  435.  
  436.         $str_ret="";
  437.         if ($this->multiselect$str_ret"<ul>";
  438.         if ($valArr=explode($this->mySeperator,$aValue)) // <pk-06-02-10 />
  439.             while(list($key,$val)=each($valArr)) {
  440.                 if (!empty($val|| isset($this->myValues[intval($val)])) // <pk-06-05-15> // <pk-07-02-28 />
  441.                     if ($this->multiselect$str_ret.= "<li>";
  442.                     if (!empty($this->myValues[$val])) {
  443.                         $str_ret .= $this->myValues[$val];
  444.                     else {
  445.                         $str_ret .= $val;
  446.                     }
  447.                     if ($this->multiselect$str_ret.= "</li>\n";
  448.                 }
  449.             }
  450.             if ($this->multiselect$str_ret .= "</ul>";
  451.             return $str_ret;
  452.  
  453.         else if (!empty($aValue)) {
  454.             return $aValue;
  455.         }
  456.         return "";
  457.     }
  458.  
  459.     /**
  460.       * returns the html code to show the value(s) in a list (table column)
  461.       *
  462.       * @param mixed $aValue 
  463.       * @param string $arrName 
  464.       * @param boolean $debug 
  465.       *
  466.       * @returns string
  467.       *
  468.       * @since pk-06-07-22
  469.       * @version pk-06-10-09
  470.       *
  471.       ***/
  472.     function getListValue($aValue,$arrName="DBVAL",$debug=False{
  473.         $debug=($debug || $this->fldDebug);
  474.         if ($debugecho "<hr /><p><b>DBMS_FIELD_SELECTLIST::getListValue($aValue,$arrName,...)</b></p>";
  475.  
  476.         if (empty($aValue&& ($this->nullToZero)) // <pk-06-10-09>
  477.             return $this->nullLabel;
  478.         }
  479.  
  480.         if (!$this->showValuesInList// use show representation of the value
  481.             return $this->getScreenValue($aValue,$arrName,$debug);
  482.         }
  483.  
  484.         $str_ret="";
  485.         if ($this->multiselect$str_ret"<ul>";
  486.         if ($valArr=explode($this->mySeperator,$aValue)) // <pk-06-02-10 />
  487.             while(list($key,$val)=each($valArr)) {
  488.                 if (!empty($val)) // <pk-06-05-15>
  489.                     if ($this->multiselect$str_ret.= "<li>";
  490.                     $str_ret .= $val;
  491.                     if ($this->multiselect$str_ret.= "</li>\n";
  492.                 }
  493.             }
  494.             if ($this->multiselect$str_ret .= "</ul>";
  495.             return $str_ret;
  496.  
  497.         else if (!empty($aValue)) {
  498.             return $aValue;
  499.         }
  500.         return "";
  501.     }
  502.  
  503.     // ################################################
  504.     // SEARCH FORM METHODS
  505.     // ################################################
  506.  
  507.  
  508.     /**
  509.       * returns the html code for the search comp types
  510.       *
  511.       * @param string $arrName 
  512.       *
  513.       * @returns string
  514.       *
  515.       ***/
  516.     function getSearchCompTypes($arrName{
  517.         return "<input type=\"hidden\" name=\"".$arrName."[".$this->myName."][COMPTYPE]\" value=\"=\"> = &nbsp;";
  518.     }
  519.  
  520.     /**
  521.       * returns the html code for a searchformular element
  522.       *
  523.       * @param mixed $aValue the value to set
  524.       * @param string $arrName 
  525.       * @param string $nameAdd @see DBMS_FIELD::getInputTag()
  526.       *
  527.       * @returns string
  528.       *
  529.       * @version pk-06-02-10
  530.       *
  531.       ***/
  532.     function getSearchInputTag($aValue,$arrName="DBVAL"{
  533.         $s_tag  "<select name='".$arrName."[".$this->myName."][VALUE]' size=\"1\" ";
  534.         $s_tag .= $this->selectAddTag;
  535.         $s_tag.=" size=\"".(intval($this->selectsize)+1)."\" ";
  536.         $s_tag .= ">\n";
  537.         if (!empty($aValue)) {
  538.             if (!($valArr=explode($this->mySeperator,$aValue))) // <pk-06-02-10 />
  539.                 $valArr=array();
  540.                 $valArr[]=$aValue;
  541.             }
  542.         else $valArr=array(NULL);
  543.         $s_tag.=$this->getOptionList($valArr,TRUE);
  544.         $s_tag.="</select>\n";
  545.         return $s_tag;
  546.     }
  547.  
  548.  
  549.  
  550.     // ###########################################################
  551.     // OBJECT VALUE CHECK/RETURN METHODS
  552.     // ###########################################################
  553.  
  554.  
  555.  
  556.  
  557.     /**
  558.       * add slashes to the value from getValue to add it to a sql command
  559.       *
  560.       * @param  string  $aValue     the value
  561.       * @param  array   $err        error array
  562.       * @param  string  $arrName    name of the global array to access field gloabl ${$arrName}
  563.       * @param  bool    $debug 
  564.       *
  565.       * @returns string
  566.       *
  567.       * @version pk-03-12-14
  568.       *
  569.       * @deprecated since pk-08-08-11
  570.       * 
  571.       */
  572.     function slashedValue($aValue,&$err,$arrName="DBVAL",$debug=False
  573.     {
  574.         $debug=($debug || $this->fldDebug);
  575.         if ($debugecho "<hr><p><b>DBMS_FIELD_SELECTLIST::slashedValue($aValue,$err,$arrName,$debug)</b> (".get_class($this)."/".$this->myName.")</p>";
  576.         $val $this->getValue($aValue,$err,$arrName,$debug);
  577.         if ($val !== False{
  578.             if ($debugecho "<p>slashedValue: returned "$GLOBALS[$this->getGlobalDBObjIdx()]->qs_getSlashedValue($val)." for $aValue</p>";
  579.             return $GLOBALS[$this->getGlobalDBObjIdx()]->qs_getSlashedValue($val);
  580.         else if ($val === False{
  581.             return False;
  582.         else {
  583.             if ($debugecho "<p>slashedValueNULL returned for $aValue</p>";
  584.             return $GLOBALS[$this->getGlobalDBObjIdx()]->qs_getNullStmt();
  585.         }
  586.     }
  587.     
  588.     
  589.     // ###########################################################
  590.     // ###########################################################
  591.     // ###########################################################
  592.     // 
  593.     // rewrite 
  594.     // implementation of INFA_DBMS_FIELD
  595.     //
  596.     // ###########################################################
  597.     // ###########################################################
  598.     // ###########################################################
  599.  
  600.     // --------------------------------------------------------
  601.     // getter / setter
  602.     // --------------------------------------------------------
  603.  
  604.     /**
  605.       * returns the input name
  606.       *
  607.       * @return string 
  608.       *
  609.       * @version pk-08-02-06
  610.       */
  611.     function getInputName()
  612.     {
  613.         $str_ret $this->myDataArrName."[".$this->myName."]";
  614.         if ($this->multiselect)
  615.         {
  616.             $str_ret .= "[]";
  617.         }
  618.         
  619.         return $str_ret;
  620.     }    
  621.     
  622.     // --------------------------------------------------------
  623.     // field configuration
  624.     // --------------------------------------------------------
  625.  
  626.     /**
  627.       * returns an array of field to bie shown in the edit form
  628.       * by using editTbl_echoForm
  629.       *
  630.       * the array is in the form:
  631.       *
  632.       * <code>
  633.       * [_sectionName_]
  634.       *      [TITLE] -> string
  635.       *      [_rowName_]
  636.       *         [FLDLAB]  (complete html code with <td></td>)
  637.       *         [FLDVAL] (complete html code with <td></td>)
  638.       * </code>
  639.       *
  640.       * @param boolean $debug 
  641.       *
  642.       * @returns array
  643.       *
  644.       * @since pk-06-04-26
  645.       * @version pk-08-02-06
  646.       *
  647.       ***/
  648.     protected function editTbl_getFieldEditArr($debug=False{
  649.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_FIELD_SELECTLIST::editTbl_getFieldEditArr","",0);
  650.         $a_ret=parent::editTbl_getFieldEditArr($debug);
  651.  
  652.         include __OCSP_PHPINCPATH__."db/forms/languages/DBMS_FIELD_SELECTLIST_FieldEditArr.de.phpinc";
  653.  
  654.         return $a_ret;
  655.     }    
  656.     
  657.     /**
  658.       * save the filed definition form
  659.       *
  660.       * @param boolean $debug 
  661.       * 
  662.       * @global array $_POST 
  663.       * 
  664.       * @returns boolean
  665.       *
  666.       */
  667.     public function editTabl_save($debug=False)
  668.     {    
  669.         $bol_ret parent::editTabl_save();
  670.  
  671.         $this->nullLabel        = (isset($_POST['nullLabel']$_POST['nullLabel'"");
  672.         $this->showNullOption   = ((isset($_POST['showNullOption']&& intval($_POST['showNullOption'])) TRUE False );
  673.         if (stristr($this->dbDesc['TYPE'],"int")) // <pk-05-12-10>
  674.             $this->nullToZero   = ((isset($_POST['nullToZero']&& intval($_POST['nullToZero'])) TRUE False );
  675.         else {
  676.             $this->nullToZero=False;
  677.         }
  678.  
  679.         if (!$this->allowNull && (isset($_POST['allowNull']&& intval($_POST['allowNull'])))
  680.         {
  681.             // we have not null db column check if we should use 0 for the null value
  682.             $this->allowNull=$this->nullToZero;
  683.         }
  684.  
  685.         $this->multiselect      = ((isset($_POST['MULTISELECT']&& intval($_POST['MULTISELECT'])) TRUE False );        
  686.         $this->showAsCheckRadio = ((isset($_POST['showAsCheckRadio']&& intval($_POST['showAsCheckRadio'])) TRUE False)// <pk-05-09-16 />
  687.         $this->notInLstValues   = ((isset($_POST['notInLstValues']&& intval($_POST['notInLstValues'])) TRUE False)// <pk-05-12-01 />
  688.  
  689.         if (!$this->showAsCheckRadio)
  690.         {
  691.             $this->extJSxType = 'combo';
  692.         }
  693.         
  694.         if (isset($_POST['SELECTSIZE']&& intval($_POST['SELECTSIZE'])) {
  695.             $this->selectsize = intval($_POST['SELECTSIZE']);
  696.         else {
  697.             $this->selectsize=1;
  698.         }
  699.         if (isset($_POST['VALUES']&& !empty($_POST['VALUES'])) {
  700.             $this->myValues=$this->getArrayFromString($_POST['VALUES']);
  701.         }
  702.         $this->selectAddTag         =(isset($_POST['selectAddTag']$_POST['selectAddTag'"");
  703.         $this->reloadFormOnChange   =(isset($_POST['RELOADONCHANGE']intval($_POST['RELOADONCHANGE']0);
  704.  
  705.         $this->mySeperator="\n"// <pk-06-02-10 /> set to the default seperator
  706.                                  // if a derived class uses a different one you have to overwrite this
  707.  
  708.         $this->lstValueIsHtml=  ((isset($_POST['lstValueIsHtml']&& intval($_POST['lstValueIsHtml'])) TRUE False)// <pk-06-05-29 /> <pk-07-5-17 /> E_ALL
  709.         $this->showValuesInList=((isset($_POST['showValuesInList']&& intval($_POST['showValuesInList'])) TRUE False)// <pk-06-07-22 /> <pk-07-5-17 /> E_ALL
  710.  
  711.              
  712.         return $bol_ret;
  713.     }  
  714.     
  715.        // --------------------------------------------------------
  716.     // jOCSP
  717.     // -------------------------------------------------------- 
  718.     
  719.     /**
  720.      * returns an array of jOCSP/jQuery Modules which are required
  721.      * 
  722.      * $arr_ret[]="script url";
  723.      *
  724.      * @param boolean $debug 
  725.      * 
  726.      * @return string 
  727.      * 
  728.      * @version pk-08-06-02
  729.      */
  730.     public function jOCSP_getRequiredModules($debug=False)
  731.     {        
  732.         if ($debugechoDebugMethod(__FILE__,get_classe($this),"DBMS_FIELD::jOCSP_getRequiredModules()");
  733.         
  734.         $arr_ret parent::jOCSP_getRequiredModules($debug);
  735.         
  736.         $arr_ret[array(
  737.             'CLASS'    => 'jOCSP.FLDOBJ_SelectList',
  738.             'SRC'     => OCSP_OBJ::getConf('SYSTEMURL')."jOCSP/formFields/jOCSP_FLDOBJ_SelectList.js"
  739.         );
  740.         $arr_ret[array(
  741.             'CLASS'    => 'jQuery.fn.ajaxSubmit',
  742.             'SRC'    => OCSP_OBJ::getConf('SYSTEMURL')."javascript/jquery/jquery.form.js"
  743.         );        
  744.         return $arr_ret;
  745.     }  
  746.     
  747.     
  748.     /**
  749.      * returns additional object elements of the field object
  750.      * 
  751.      * array definition: [elemName] = value
  752.      * 
  753.      * NOTE: do not js_escapte value this is done when building the json object
  754.      *
  755.      * @param boolean $debug 
  756.      * 
  757.      * @return array 
  758.      * 
  759.      * @since pk-08-02-06
  760.      * @version pk-08-06-02
  761.      */
  762.     protected function jOCSP_getAdditonalFieldObjElems($debug=False)
  763.     {        
  764.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_FIELD_SELECTLIST::jOCSP_getAdditonalFieldObjElems();");                
  765.  
  766.         $arr_ret parent::jOCSP_getAdditonalFieldObjElems($debug);
  767.         
  768.         switch($this->reloadFormOnChange)
  769.         {
  770.             case "0"
  771.                 $arr_ret['reloadOnChange'"false";
  772.                 break;
  773.             case "1"
  774.                 $arr_ret['reloadUrl'"'" pcf_js_escape($_SERVER['REQUEST_URI']"'";
  775.                 $arr_ret['reloadOnChange'"true";
  776.                 break;
  777.             case "2":                
  778.                 if (!($str_reloadUrl $this->getControl()->getReloadUrl()) || empty($str_reloadUrl))
  779.                 {
  780.                     $str_reloadUrl OCSP_OBJ::getConf('SYSTEMURL'"jOCSP/formRPC.php";
  781.                 }
  782.                 $arr_ret['reloadUrl'"'" pcf_js_escape($str_reloadUrl"'";
  783.                 $arr_ret['reloadOnChange'"true";
  784.                 break
  785.             default
  786.                 $arr_ret['reloadOnChange'"false";                
  787.                 $arr_ret['doReload'"function(aValue) {alert('reload type not defined');}";
  788.         }
  789.         
  790.         $arr_ret['fldClass'"'FLDOBJ_SelectList'";
  791.         if ($this->ajaxDebug// <pk-08-05-21 />
  792.         {
  793.             $arr_ret['debug'True;
  794.         }
  795.         
  796.         return $arr_ret;
  797.     }
  798.    
  799.     // form reloading 
  800.     
  801.     /**
  802.      * returns a javascript to be called for reloading the form
  803.      *
  804.      * @param boolean $debug 
  805.      * 
  806.      * @return string 
  807.      * 
  808.      * @todo could sometimes not get the controll
  809.      */
  810.     public function jOCSP_getReloadScript($debug=False)
  811.     {
  812.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_FIELD_SELECTLIST::JOCSP_getReloadScript()");
  813.         
  814.         $debug ($debug || $this->ajaxDebug);
  815.         
  816.         if ($debug)
  817.         {            
  818.             $str_ret "try {
  819.                 alert('Reload: " $this->myName . "');";
  820.         else {
  821.             $str_ret "";
  822.         }
  823.         
  824.         if (!pcf_is_instance_of($this->getControl(),'OCSP_FRMCONTR'))
  825.         {
  826.             try {                            
  827.                 $this->setControl($this->getMyForm()->getControl())
  828.                 if (!pcf_is_instance_of($this->getControl(),'OCSP_FRMCONTR'))
  829.                 {
  830.                     pcf_js_alert("no control: " get_class($this"\n" basename(__FILE__"L: " . __LINE__);
  831.                 }
  832.             catch(Exception $e{
  833.                 pcf_js_alert($e->getMessage());
  834.                 return "";
  835.             }
  836.         }
  837.         
  838.         if (method_exists($this->getControl(),"jOCSP_getfrmHash"))
  839.         {
  840.             $str_ret .= "
  841.                     if (obj_form = jOCSP.getFormByHash('" $this->getControl()->jOCSP_getfrmHash("'))
  842.                     {
  843.                         obj_form.fieldChanged('" $this->getDOMId("',this.value);
  844.                     }
  845.                 ";
  846.             if ($debug{
  847.                 $str_ret .= " else { alert('Form: " $this->getControl()->jOCSP_getfrmHash(" not found\\nField: " $this->myName . "\\n" basename(__FILE__" L: " . __LINE__ ."');}";
  848.             }
  849.             
  850.         else {
  851.             $str_ret .= "alert('Fehler: wrong controll " get_class($this->myControll"\\nField: " $this->myName . "\\n" basename(__FILE__" L: " . __LINE__ ."');";        
  852.         }
  853.         
  854.         if ($debug)
  855.         {
  856.             $str_ret .= "} catch(e) {alert('Field: " $this->myName . ": ' + e);}"
  857.         }
  858.         
  859.         return $str_ret;
  860.     }    
  861.     
  862.     
  863.     /**
  864.      * returns options of an ext js field config object
  865.      * 
  866.      * NOTE the return string is NOT enclosed by {}
  867.      * 
  868.      * @param boolean $debug 
  869.      * 
  870.      * @return string (json)
  871.      * 
  872.      * @since pk-08-09-09
  873.      */
  874.     public function getExtJSConfigOptions($debug=False)
  875.     {
  876.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_FIELD_SELECTLIST::getExtJSConfigOptions()");
  877.  
  878.         $arr_ret parent::getExtJSConfigOptions($debug);
  879.         $arr_ret['name']         "'" $this->myName . "_showField'";
  880.         $arr_ret['id']             "'" $this->getJsName("_showField'";
  881.         $arr_ret['hiddenName']     "'" $this->getInputName("'";
  882.         $arr_ret['hiddenId']    "'" $this->getJsName("'";
  883.         
  884.         $this->setMyValues($this->myDataArrName,$debug);        
  885.         $arr_ret['store'"new Ext.data.SimpleStore({
  886.                 fields: [{name: 'optVal'}, {name: 'optLabel'}],
  887.                 data : [";
  888.         
  889.         if (is_array($this->myValues)) 
  890.         {
  891.             foreach($this->myValues as $m_key => $m_val)
  892.             {
  893.                    $arr_ret['store'.= $cha_sep "['" pcf_js_escape($m_key"','" pcf_js_escape($m_val"']";
  894.                    $cha_sep ",";
  895.             }
  896.         }
  897.         $arr_ret['store'.= "]})";
  898.  
  899.         $arr_ret['displayField'"'optLabel'";
  900.         $arr_ret['valueField'"'optVal'";
  901.         
  902.         $arr_ret['forceSelection'"true";
  903.         $arr_ret['mode']     "'local'";
  904.         $arr_ret['typeAhead']"true";
  905.         
  906.         $arr_ret['triggerAction'"'all'";
  907.         $arr_ret['selectOnFocus'"true";
  908.  
  909.            //$arr_ret['editable'] = "false";
  910.         //$arr_ret['disableKeyFilter'] = "true";
  911.         
  912.         return $arr_ret;
  913.     }
  914.     
  915.     // --------------------------------------------------------
  916.     // html form output
  917.     // --------------------------------------------------------
  918.     
  919.     /**
  920.      * returns an array of &lt;select&gt; attributes
  921.      * 
  922.      * @see http://www.w3schools.com/tags/tag_select.asp
  923.      * 
  924.      *  array('Attribute' => "\"Value\"");
  925.      * 
  926.      *  NOTE: the output of value is done as is.
  927.      *  Ensure values are in " if needed
  928.      * 
  929.      *  <code>
  930.      *  echo $attribute . "=" . $value;
  931.      *  </code>
  932.      *
  933.      * @param boolean $debug 
  934.      * 
  935.      * @return array 
  936.      * 
  937.      * @since pk-08-02-06
  938.      */
  939.     protected function getFormFieldSelectAttributes($debug)
  940.     {
  941.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_FIELD_SELECTLIST::getFormFieldSelectAttributes");
  942.         
  943.         $arr_ret array();
  944.         if ($this->multiselect)
  945.         {
  946.             $arr_ret['multiple']="\"multiple\"";
  947.         }
  948.         
  949.         if (intval($this->selectsize))
  950.         {
  951.             $arr_ret['size'intval($this->selectsize);
  952.         }
  953.         
  954.            $arr_ret['onchange'"\"" $this->jOCSP_getReloadScript($debug"\"";
  955.         
  956.         if (intval($this->tabIndex))
  957.         {
  958.             $arr_ret['tabindex'intval($this->tabIndex)
  959.         }
  960.                         
  961.         return $arr_ret;
  962.     }
  963.     
  964.     /**
  965.      * returns the html code for the &lt;select&gt field
  966.      *
  967.      * @param mixed $aValue 
  968.      * @param boolean $debug 
  969.      */
  970.     protected function getFormFieldSelect($aValue,$debug=False)
  971.     {
  972.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_FIELD_SELECTLIST::getFormFieldSelect");
  973.  
  974.         $arr_attributes $this->getFormFieldSelectAttributes($debug);
  975.                 
  976.         $str_tag "<select name=\"" $this->getInputName(."\" id=\"" $this->getDOMId("\"";
  977.         if (is_array($arr_attributes))
  978.         {
  979.             foreach($arr_attributes as $str_att => $str_val)
  980.             {
  981.                 $str_tag .= " " $str_att "=" $str_val;
  982.             }
  983.         }
  984.         
  985.         $str_tag .= ">";
  986.         
  987.         // options ------------------------------
  988.         
  989.         if (!is_array($aValue))
  990.         {
  991.             if (!($arr_val explode($this->mySeperator,$aValue))) 
  992.             {
  993.                 $arr_val array();
  994.             }
  995.         else {
  996.             $arr_val $aValue;
  997.         }
  998.         $str_tag .= $this->getOptionList($arr_val,$this->showNullOption,$debug);
  999.                 
  1000.         $str_tag .= "</select>";
  1001.         
  1002.         if (intval($this->reloadFormOnChange)) {
  1003.             $str_tag .= $this->getReloadButton($debug);
  1004.         }
  1005.         
  1006.         return $str_tag;
  1007.     }
  1008.     
  1009.     /**
  1010.      * returns a string with the options
  1011.      *
  1012.      * calls setMyValues to be sure $this->myValues is set correkt
  1013.      * 
  1014.      * @param array $aValArr 
  1015.      * @param bool $addNull 
  1016.      * @param bool $debug 
  1017.      * @return string 
  1018.      * 
  1019.      * 
  1020.      */
  1021.     protected function getOptionList($aValArr,$addNull=False,$debug=False{
  1022.         $debug=($debug || $this->fldDebug)// <pk-04-08-31>
  1023.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_FIELD_SELECTLIST::getOptionList(\$aValArr,\$addNull=$addNull)",print_r($aValArr,TRUE));
  1024.  
  1025.         $this->setMyValues($this->myDataArrName,$debug)// <pk-05-08-02 />
  1026.         $str_ret="";
  1027.  
  1028.         /* <pk-05-01-11 /> */
  1029.         //  if (($this->allowNull) || ($addNull)) {
  1030.         if ($addNull/* <pk-05-02-08 addNull -> addNULL /> */
  1031.             $str_ret.="\t<option value=\"\">".$this->nullLabel."</option>\n";
  1032.         }
  1033.         if ($debugechoDebugLine(__FILE__,__LINE__,"<pre style=\"font-size:80%;padding-left: 100px;\">".print_r($this->myValues,TRUE)."</pre>");
  1034.  
  1035.         if (is_array($aValArr&& sizeof($aValArr)) // <pk-07-01-15>
  1036.             $a_flipVal=@array_flip($aValArr);
  1037.         else {
  1038.             $a_flipVal=array();
  1039.         }
  1040.         if ($debugechoDebugLine(__FILE__,__LINE__,"flippedValues=<pre style=\"font-size:80%;padding-left: 100px;\">".print_r($a_flipVal,TRUE)."</pre>");
  1041.  
  1042.         // <pk-07-09-26>
  1043.         if (is_array($this->myValues)) {
  1044.             foreach($this->myValues as $m_key => $m_val)
  1045.             {
  1046.                 $str_ret.="<option value=\"".$m_key."\"";
  1047.                 if (isset($a_flipVal[$m_key]))
  1048.                 {
  1049.                     $str_ret.=" selected=\"selected\"";
  1050.                     unset($a_flipVal[$m_key]);
  1051.                 }
  1052.                 
  1053.                 // <pk-08-09-26>
  1054.                 if (is_array($m_val))
  1055.                 {
  1056.                     $str_ret.=">".strip_tags($m_val['SHOWFIELD'])."</option>\n";    
  1057.                 else {                
  1058.                     $str_ret.=">".strip_tags($m_val)."</option>\n";
  1059.                 }
  1060.             }
  1061.         }
  1062.         if (sizeof($a_flipVal)) {
  1063.             if ($debugechoDebugLine(__FILE__,__LINE__,"flippedValues=<pre style=\"font-size:80%;padding-left: 100px;\">".print_r($a_flipVal,TRUE)."</pre>");
  1064.             foreach($aValArr as $s_value{
  1065.                 if (!empty($s_value)) $str_ret.="<option value=\"$s_value\" selected=\"selected\">$s_value</option>\n";
  1066.             }
  1067.         else if ($debug{
  1068.             echoDebugLine(__FILE__,__LINE__,"all values found in array");
  1069.         }
  1070.         // </pk-07-09-26>
  1071.         return $str_ret;
  1072.     }
  1073.         
  1074.     /**
  1075.       * returns the html code for a button to reload the form
  1076.       * 
  1077.       * @param boolean $debug 
  1078.       *
  1079.       * @global $OCSP_CONF 
  1080.       *
  1081.       * @return string 
  1082.       *
  1083.       * @since pk-04-08-18
  1084.       * 
  1085.       * @version pk-06-10-10 link name added
  1086.       * @version pk-07-08-31
  1087.       * @version pk-08-02-12
  1088.       * 
  1089.       */
  1090.     protected function getReloadButton($debug=False
  1091.     {
  1092.         
  1093.         if ($this->getView())
  1094.         {
  1095.             $str_ret $this->myView->getButton('RELOAD',$debug);            
  1096.             $str_ret str_replace("/>"," onclick=\"" pcf_js_escapeOnEventCmd($this->jOCSP_getReloadScript($debug),'"'"\"/>",$str_ret);    
  1097.             return $str_ret;
  1098.         }
  1099.         
  1100.         /*        
  1101.         global $OCSP_CONF;
  1102.  
  1103.         $str_ret="";
  1104.         $str_ret.="<img src=\"{$OCSP_CONF['SYSIMGURL']}icons-16x16/reload.gif\" border=\"0\" alt=\"refresh form\"  class=\"button\"
  1105.                     onClick=\"ocsp_from_fieldChanged('".$this->myForm->getHTMLName()."','".$this->getJsName()."');\" title=\"Formular aktualisieren\"
  1106.                />";
  1107.  
  1108.         return $str_ret;
  1109.         */
  1110.     }    
  1111.     
  1112.     // --------------------------------------------------------
  1113.     // data validation
  1114.     // --------------------------------------------------------
  1115.     
  1116.     /**
  1117.       * returns the field value if its an array,
  1118.       * it is imploded with $this->mySeperator as seperator
  1119.       *
  1120.       * @param  string  $aValue     the value
  1121.       * @param  array   $err        error array
  1122.       * @param  string  $arrName    name of the array to access fieldsarray  gloabl ${$arrName}
  1123.       * @param  bool    $debug 
  1124.       *
  1125.       * @returns string
  1126.       *
  1127.       * @since   pk-03-12-13
  1128.       * @version pk-03-12-01
  1129.       * @version pk-05-12-10
  1130.       *
  1131.       ***/
  1132.     function getValue($aValue,&$err,$arrName="DBVAL",$debug=False{
  1133.         $debug=($debug || $this->fldDebug);
  1134.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_FIELD_SELECTLIST::getValue({$aValue}, ...)</p>",$this->getName());
  1135.         if (is_array($aValue)) {
  1136.             $aValue implode($this->mySeperator,$aValue);
  1137.         }
  1138.         if (empty($aValue&& ($this->nullToZero)) $aValue="0"//<pk-05-12-10 />
  1139.         return parent::getValue($aValue,$err,$arrName,$debug);
  1140.     }    
  1141.     
  1142.     
  1143. // end class DBMS_FIELD_SELECTLIST
  1144. ?>

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