Source for file DBMS_FIELD_GLOBALARRSELECTLIST.phpclass

Documentation is available at DBMS_FIELD_GLOBALARRSELECTLIST.phpclass

  1. <?php
  2. /**
  3.   * Class file DBMS_FIELD_GLOBALARRSELECTLIST.phpclass
  4.   *
  5.   * @project    Open CSP-Management
  6.   * @package    dbms_field
  7.   * @category   any
  8.   *
  9.   * @author     Peter Krebs <p.krebs@lvus.at>
  10.   * @copyright  (c) 2002-2005 by LVUS <http://www.lvus.at>
  11.   * @license    http://opensource.org/licenses/gpl-license.php GNU Public License
  12.   *
  13.   ***/
  14.  
  15. require_once dirname(__FILE__)."/DBMS_FIELD_SELECTLIST.phpclass";
  16.  
  17.  
  18. $GLOBALS['DBMS']['GLOBALARRMODULES']=array("PROJECT","CMS","DBMS")// pk-05-07-18
  19.  
  20. /**
  21.   * Class DBMS_FIELD_GLOBALARRSELECTLIST
  22.   *
  23.   * @project    Open CSP-Management
  24.   * @package    dbms_field
  25.   * @category   any
  26.   *
  27.   * @author     Peter Krebs <p.krebs@lvus.at>
  28.   * @copyright  (c) 2002-2005 by LVUS <http://www.lvus.at>
  29.   * @license    http://opensource.org/licenses/gpl-license.php GNU Public License
  30.   *
  31.   * @version pk-06-07-22
  32.   *
  33.   ***/
  34.  
  35.     /**
  36.       * source file of the class
  37.       *
  38.       * @var string $classSrcFile 
  39.       * @since pk-05-01-20
  40.       ***/
  41.     var $classSrcFile=__FILE__;
  42.  
  43.     /**
  44.       * @var string $className 
  45.       ***/
  46.     var $className       = "SelectGlobalArr";
  47.     /**
  48.       * @var boolean $allowNullSelect 
  49.       ***/
  50.     var $allowNullSelect = FALSE;
  51.  
  52.     // ###########################################################
  53.     // OBJECT (CONST) VAR DECLARATION
  54.     // ###########################################################
  55.  
  56.     /**
  57.       * @var string $module 
  58.       ***/
  59.     var $module          = "PROJECT";
  60.     /**
  61.       * @var string $arrName 
  62.       ***/
  63.     var $arrName         = "";
  64.     /**
  65.       * @var string $subKey 
  66.       ***/
  67.     var $subKey          = "";
  68.     /**
  69.       * @var string $lstKey 
  70.       * @since pk-06-09-08
  71.       ***/
  72.     var $lstKey          = "";
  73.  
  74.     /**
  75.       * @var boolean $valueIsKey the value of the array is the key and shown as option text
  76.       * @since pk-05-02-17
  77.       ***/
  78.     var $valueIsKey=FALSE;
  79.  
  80.  
  81.     // ###########################################################
  82.     // OBJECT SETTINGS METHODS
  83.     // ###########################################################
  84.  
  85.     // ###########################################################
  86.     // FIELD DEFINITION DATA METHODS
  87.     // ###########################################################
  88.  
  89.     /**
  90.       * returns an array of field to bie shown in the edit form
  91.       * by using editTbl_echoForm
  92.       *
  93.       * the array is in the form:
  94.       *
  95.       * <code>
  96.       * [_sectionName_]
  97.       *      [TITLE] -> string
  98.       *      [_rowName_]
  99.       *         [FLDLAB]  (complete html code with <td></td>)
  100.       *         [FLDVAL] (complete html code with <td></td>)
  101.       * </code>
  102.       *
  103.       * @param boolean $debug 
  104.       *
  105.       * @returns array
  106.       *
  107.       * @since pk-06-04-26
  108.       *
  109.       ***/
  110.     function editTbl_getFieldEditArr($debug=FALSE{
  111.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_FIELD_DBSELECTLIST::editTbl_getFieldEditArr","",0);
  112.         $a_ret=parent::editTbl_getFieldEditArr($debug);
  113.  
  114.         unset($a_ret['SELECT']['FLD_LSTVALS'])// unset parent field as it is of no use here
  115.  
  116.         $a_ret['GLOBALARR']=array(
  117.             'TITLE'=>"Array Einstellungen",
  118.  
  119.             'FLD_GLOBALARR'=>array(
  120.                 'FLDLAB'=>"Werte ARRAY",
  121.             ),
  122.             'FLD_VALUES'=>array(
  123.                 'FLDLAB'=>"Werte:",
  124.                 'FLDVAL'=>"
  125.                         <input type=\"radio\" name=\"valueIsKey\" value=\"1\" ".($this->valueIsKey ? "checked" "").">Array Wert auch als DB Wert speichern<br />
  126.                         <input type=\"radio\" name=\"valueIsKey\" value=\"0\" ".($this->valueIsKey ? "" "checked")."> Array Index als DB Wert speichern
  127.                     "
  128.             ),
  129.             'FLD_SHOWINDEX'=>array(
  130.                 'FLDLAB'=>"Anzeige Index: (Arrays)",
  131.                 'FLDVAL'=>"<input name=\"subKey\" value=\"".$this->subKey."\" size=\"40\">"
  132.             ),
  133.             'FLD_LSTINDEX'=>array(                          // <pk-06-09-08 />
  134.                 'FLDLAB'=>"List Index: (Arrays)",
  135.                 'FLDVAL'=>"<input name=\"lstKey\" value=\"".$this->lstKey."\" size=\"40\">"
  136.             )
  137.         );
  138.  
  139.         /*
  140.         $a_ret['GLOBALARR']['FLD_GLOBALARR']['FLDVAL']="
  141.                 <select name=\"SEL_GLOBALARRAY\" onchange=\"document.frmEdit.GLOBALARRAY.value=this.value;\">
  142.                     <option value=\"\">Eingabe: </option>
  143.                 ";
  144.         foreach($GLOBALS['DBMS']['GLOBALARRMODULES'] as $key) {
  145.             if (is_array($GLOBALS[$key])) {
  146.                 $a_ret['GLOBALARR']['FLD_GLOBALARR']['FLDVAL']="";
  147.                 foreach($GLOBALS[$key] as $subKey => $subVal) {
  148.                     if (is_array($subVal)) {
  149.                         $a_ret['GLOBALARR']['FLD_GLOBALARR']['FLDVAL'].="\t\t<option value=\"$key|$subKey\"";
  150.                         if ($key."|".$subKey == $this->arrName) $a_ret['GLOBALARR']['FLD_GLOBALARR']['FLDVAL'].= " selected";
  151.                         if ($subKey == $this->arrName) $a_ret['SELECT']['FLD_GLOBALARR']['FLDVAL'].= " selected"; // old style
  152.                         $a_ret['GLOBALARR']['FLD_GLOBALARR']['FLDVAL'].= ">$key $subKey</option>\n";
  153.                     }
  154.                 }
  155.             }
  156.         }
  157.         $a_ret['GLOBALARR']['FLD_GLOBALARR']['FLDVAL'].= "
  158.                 </select>";
  159.         */
  160.         $a_ret['GLOBALARR']['FLD_GLOBALARR']['FLDVAL'.= "                
  161.                 <input name=\"GLOBALARRAY\" value=\"".$this->arrName."\" size=\"40\">
  162.         ";
  163.  
  164.         return $a_ret;
  165.     }
  166.  
  167.     /**
  168.       * echos the field edit form field cols
  169.       *
  170.       * @param boolean $showSize show size fields
  171.       * @param boolean $showNull show List Null-Option
  172.       * @param boolean $showValueList show a textfield to input a value list
  173.       *
  174.       * @deprecated since pk-06-07-23
  175.       *
  176.       ***/
  177.     function editTblForm($showSize=FALSE,$showNull=TRUE,$showValueList=FALSE{
  178.         parent::editTblForm($showSize,$showNull,$showValueList);
  179.     }
  180.  
  181.     /**
  182.       * save the field definiton from $_POST
  183.       *
  184.       * @return boolean 
  185.       *
  186.       ***/
  187.     function save({
  188.         $ret parent::save();
  189.  
  190.         $this->arrName          =$_POST['GLOBALARRAY'];
  191.         $this->allowNullSelect  =$this->allowNull();
  192.         $this->subKey           =$_POST['subKey'];
  193.         $this->lstKey           =$_POST['lstKey']// <pk-06-09-08 />
  194.         $this->valueIsKey       =(intval($_POST['valueIsKey']TRUE FALSE);
  195.  
  196.         return $ret;
  197.     }
  198.  
  199.     ###################################
  200.  
  201.     /**
  202.       * returns the global array
  203.       *
  204.       * @param boolen $debug 
  205.       *
  206.       * @returns array
  207.       *
  208.       * @since pk-04-09-08
  209.       * @version pk-05-02-17
  210.       *
  211.       ***/
  212.     function getGlobalValArr($debug=FALSE{
  213.         $debug=($debug || $this->fldDebug);
  214.         if ($debugecho "<p><b>DBMS_FIELD_GLOBALARRSELECTLIST::getGlobalValArr()</b></p>";
  215.  
  216.         if (!strstr($this->arrName,"|")) {
  217.             /*<pk-05-02-17>*/
  218.             if (is_array($GLOBALS[$this->arrName])) {
  219.                 $a_keys[0]=$this->arrName;
  220.             else {
  221.                 /*</pk-05-02-17>*/
  222.                 $a_keys[0]="PROJECT";$a_keys[1]=$this->arrName;
  223.             }
  224.         else {
  225.             $a_keys=explode("|",$this->arrName);
  226.         }
  227.  
  228.         $s_gVar="\$GLOBALS";
  229.         foreach($a_keys as $s_key{
  230.             $s_gVar.="['".$s_key."']";
  231.         }
  232.         if ($debugecho "<p>getGlobalValArr CMD: ".htmlspecialchars($s_gVar)."</p>";
  233.         @eval("\$this->myValues=".$s_gVar.";");
  234.         if ($debugecho "<pre>Values: \n".print_r($this->myValues,TRUE)."</pre>";
  235.         return $this->myValues;
  236.     }
  237.  
  238.     /**
  239.       * sets $this->myValues
  240.       *
  241.       * @param string $arrName 
  242.       * @param boolean $debug 
  243.       *
  244.       * @version pk-04-09-08
  245.       * @version pk-05-02-17
  246.       *
  247.       ***/
  248.     function setMyValues($arrName="DBVAL",$debug=FALSE{
  249.         $debug=($debug || $this->fldDebug);
  250.         if ($debugecho "<p><b>DBMS_FIELD_GLOBALARRSELECTLIST::setMyValues($arrName,...,$mode)</b></p><blockquote>";
  251.  
  252.         if ($this->allowNull()) {
  253.             $this->myValues=array(0=>$this->nullLabel);
  254.         else {
  255.             $this->myValues=array();
  256.         }
  257.  
  258.         $arr=$this->getGlobalValArr($debug);
  259.  
  260.         if (is_array($arr)) {
  261.             foreach($arr as $key => $val{
  262.                 if ($this->valueIsKey$key=$val/* <pk-05-02-17> */
  263.                 if (is_array($val)) {
  264.                     if (!empty($this->subKey)) {
  265.                         if ($this->valueIsKey$key=$val[$this->subKey]/* <pk-05-02-17> */
  266.                         $this->myValues[$key]=$val[$this->subKey];
  267.                     }else {
  268.                         if ($this->valueIsKey)
  269.                             $this->myValues[substr(implode("/",$val),0,32)]=implode("/",$val);
  270.                         else
  271.                             $this->myValues[$key]=implode("/",$val);
  272.                    }
  273.                 else {
  274.                     if ($this->valueIsKey$key=$val/* <pk-05-02-17> */
  275.                     $this->myValues[$key]=$val;
  276.                 }
  277.             }
  278.         }
  279.         if ($debugecho "<pre style=\"font-size:75%\">myValues:\n".print_r($this->myValues,TRUE)."</pre>";
  280.         if ($debugecho "</blockquote>";
  281.     }
  282.     
  283.     
  284.  
  285.     /**
  286.       * returns a string with the options
  287.       * if
  288.       *
  289.       * calls setMyValues to be sure $this->myValues is set correkt
  290.       *
  291.       * @param array $aValArr   array of selected values
  292.       * @param bool $addNULL    add the null option (for search)
  293.       * @param bool $debug 
  294.       *
  295.       * @return string 
  296.       *
  297.       * @since pk-05-02-17
  298.       *
  299.       *
  300.     function getOptionList($aValArr,$addNULL=FALSE,$debug=FALSE) {
  301.         $debug=($debug || $this->fldDebug); // <pk-04-08-31>
  302.         if ($debug) echo "<p><b>DBMS_FIELD_GLOBALARRSELECTLIST::getOptionList(\$aValArr,$addNULL,...)</b> (".get_class($this)."/".$this->myName.")</p><blockquote>";
  303.  
  304.         $ret=parent::getOptionList($aValArr,$addNULL,$debug);
  305.         foreach($aValArr as $val) {
  306.             if (!strstr($ret,"value=\"$val\"")) {
  307.                 $ret.="\t<option value=\"$val\" selected>$val</option>\n";
  308.             }
  309.         }
  310.         if ($debug) echo "</blockquote>";
  311.         return $ret;
  312.     }
  313.         */
  314.  
  315.     /**
  316.       * returns the html representation of the field
  317.       *
  318.       * @param mixed    $aValue     the falue
  319.       * @param string $arrName  name of the global array holding data values
  320.       * @param bool     $debug      show debug info
  321.       *
  322.       * @returns mixed   the html representation of the field
  323.       *
  324.       * @since pk-06-09-08
  325.       *
  326.       ***/
  327.     function getScreenValue($aValue=NULL,$arrName="DBVAL",$debug=FALSE{
  328.         $debug=($debug || $this->fldDebug);
  329.         if ($debugecho "<hr /><p><b>DBMS_FIELD_GLOBALARRSELECTLIST::getScreenValue($aValue,$arrName,...)</b></p>";
  330.  
  331.         if (empty($aValue)) parent::getScreenValue($aValue,$arrName,$debug);
  332.         if (empty($this->subKey)) {
  333.             $a_gValArr=$this->getGlobalValArr($debug);
  334.             // we only have to return the values
  335.             if ($this->multiselect{
  336.                 $a_valArr=explode($this->mySeperator,$aValue);
  337.                 $s_ret="<ul>";
  338.                 foreach($a_valArr as $s_val{
  339.                     if (isset($a_gValArr[$s_val]&& (!empty($a_gValArr[$s_val]))) {
  340.                         $s_ret.="<li>".$a_gValArr[$s_val]."</li>";
  341.                     else {
  342.                         $s_ret.="<li>".$s_val."</li>";
  343.                     }
  344.                 }
  345.                 $s_ret.="</li></ul>";
  346.                 return $s_ret;
  347.             else {
  348.                 if (isset($a_gValArr[$aValue]&& (!empty($a_gValArr[$aValue]))) {
  349.                     return $a_gValArr[$aValue];
  350.                 else {
  351.                     return $aValue;
  352.                 }
  353.             }
  354.         }
  355.  
  356.         $a_gValArr=$this->getGlobalValArr($debug);
  357.         if (!is_array($a_gValArr)) {
  358.             if ($debugreturn "ERROR: global array net set (".$this->myName.")";
  359.             else        return "";
  360.         }
  361.  
  362.         $a_valArr=explode($this->mySeperator,$aValue);
  363.         if ($this->multiselect{
  364.             $ret="<ul>";
  365.             foreach ($a_valArr as $s_val{
  366.                 $ret.="<li>".(!empty($a_gValArr[$s_val][$this->subKey]$a_gValArr[$s_val][$this->subKey$s_val)."</li>";
  367.             }
  368.             $ret="</ul>";
  369.             return $ret;
  370.         else {
  371.             return (!empty($a_gValArr[$a_valArr[0]][$this->subKey]$a_gValArr[$a_valArr[0]][$this->subKey$a_valArr[0]);
  372.         }
  373.  
  374.     }
  375.  
  376.     /**
  377.       * returns the html representation of the field in a list (table col)
  378.       *
  379.       * @param mixed    $aValue     the falue
  380.       * @param string $arrName  name of the global array holding data values
  381.       * @param bool     $debug      show debug info
  382.       *
  383.       * @returns mixed   the html representation of the field
  384.       *
  385.       * @since pk-06-09-08
  386.       *
  387.       ***/
  388.     function getListValue($aValue=NULL,$arrName="DBVAL",$debug=FALSE{
  389.         $debug=($debug || $this->fldDebug);
  390.         if ($debugecho "<hr /><p><b>DBMS_FIELD_GLOBALARRSELECTLIST::getListValue($aValue,$arrName,...)</b></p>";
  391.  
  392.         if (empty($aValue)) $this->getScreenValue($aValue,$arrName,$debug);
  393.         if (empty($this->lstKey|| $this->lstKey==$this->subKey{
  394.             return $this->getScreenValue($aValue,$arrName,$debug);
  395.         }
  396.  
  397.         $a_gValArr=$this->getGlobalValArr($debug=FALSE);
  398.  
  399.  
  400.         if (!is_array($a_gValArr)) {
  401.             if ($debugreturn "ERROR: global array net set (".$this->myName.")";
  402.             else        return "";
  403.         else {
  404.             $a_valArr=explode($this->mySeperator,$aValue);
  405.  
  406.             if ($debug{
  407.                 echo "<hr /><p><b>\$a_valArr:</b></p><pre>".print_r($a_valArr,TRUE)."</pre>";
  408.                 echo "<p><b>\$a_gValArr:</b></p><pre>".print_r($a_gValArr,TRUE)."</pre><hr />";
  409.             }
  410.  
  411.             if ($this->multiselect{
  412.                 $ret="<ul>";
  413.                 foreach ($a_valArr as $s_val{
  414.                     $ret.="<li>".(!empty($a_gValArr[$s_val][$this->lstKey]$a_gValArr[$s_val][$this->lstKey$s_val)."</li>";
  415.                 }
  416.                 $ret="</ul>";
  417.                 return $ret;
  418.             else {
  419.                 return (!empty($a_gValArr[$a_valArr[0]][$this->lstKey]$a_gValArr[$a_valArr[0]][$this->lstKey$a_valArr[0]);
  420.             }
  421.         }
  422.     }
  423.  
  424. // end class DBMS_FIELD_GLOBALARRSELECTLIST
  425. ?>

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