Source for file DBMS_FIELD_DBCOLSELECTLIST.phpclass
Documentation is available at DBMS_FIELD_DBCOLSELECTLIST.phpclass
  * Class file DBMS_FIELD_DBCOLSELECTLIST.phpclass  
  * @project    Open CSP-Management  
  * @author     Peter Krebs <pitlinz@users.sourceforge.net>  
  * @license    http://opensource.org/licenses/gpl-license.php GNU Public License  
require_once dirname(__FILE__
).
_OCSP_DIRSEP_.
"DBMS_FIELD_SELECTLIST.phpclass";  
  * Class DBMS_FIELD_DBCOLSELECTLIST  
  * @author     Peter Krebs <pitlinz@users.sourceforge.net>  
  * @author     Christian Gaisberger <c.gaisberger@lvus.at>  
  * @license    http://opensource.org/licenses/gpl-license.php GNU Public License  
  * @version pk-06-09-11 $this->tblFilter as cvs  
  * @version pk-07-03-05 ajax  
  * @todo DBMS_FIELD_DBCOLSELECTLIST use $myForm->getDBObj for database handle  
      * source file of the class  
      * @var string $classSrcFile   
      * filter of the table names  
      * @var string $myTblField formfield contains the table  
      * @var string $defaultTbl   
      * user is allowed to change table  
      * @var boolean $allowChangeTbl   
      * return tableNAME.columnNAME if true else columnNAME  
      * @var boolean $addTblName   
    // ###########################################################  
    // FIELD DEFINITION DATA METHODS  
    // ###########################################################  
      * returns an array of field to bie shown in the edit form  
      * by using editTbl_echoForm  
      * the array is in the form:  
      *         [FLDLAB]  (complete html code with <td></td>)  
      *         [FLDVAL] (complete html code with <td></td>)  
        unset
($a_ret['SELECT']['FLD_LSTVALISHTML']); 
        unset
($a_ret['SELECT']['FLD_LSTVALS']); 
        $a_ret['DB_TABLE']=
array(  
            'FLD_TBLFIELD'=>
array('ISHIDDEN'=>
TRUE),  
                'FLDLAB'=>
"Default Tabelle",  
                'FLDVAL'=>
"<input name=\"tblFilter\" value=\"".
$this->tblFilter.
"\" size=\"40\" />"  
                'FLDLAB'=>
"Tabellenfilter (durch Komma getrennt)"  
            'FLD_ALLOWCHGTBL'=>
array(  
                'FLDLAB'=>
"Tabelle wechseln",  
                'FLDVAL'=>
"<input type=\"checkbox\" name=\"allowChangeTbl\" value=\"1\" ".
($this->allowChangeTbl ? 
"checked" : 
"").
" /> erlauben"  
                'FLDLAB'=>
"Tabellenname mitspiechern",  
                        <input type=\"radio\" value=\"1\" name=\"addTblName\" ".
($this->addTblName ? 
"checked=\"checked\"" : 
"").
" /> ja (TABLE.COLUMN speichern)<br />  
                        <input type=\"radio\" value=\"0\" name=\"addTblName\" ".
($this->addTblName ? 
"" : 
"checked=\"checked\"").
" /> nein (COLUMN speichern)<br />  
        // <pk-07-03-05> get table fields   
        $a_flds=
$this->myForm->getFieldArr(TRUE);  
        foreach($a_flds as &$o_fld) {  
            if ($debug) echo 
"<p>".
get_class($o_fld).
"</p>";  
                if ($debug) echo 
"<p><b>Feld gefunden: ".
$o_fld->getKey().
"</b></p>";  
            $a_ret['DB_TABLE']['FLD_TBLFIELD']['ISHIDDEN']=
FALSE;  
            $a_ret['DB_TABLE']['FLD_TBLFIELD']['FLDLAB']=
"Tabellenfeld";  
            $s_tag =
"<select name=\"myTblField\" onChange=\"if (this.options[this.options.selectedIndex].value != '') {";  
            $s_tag.=
"this.form.tblFilter.defaultValue=this.form.tblFilter.value;";  
            $s_tag.=
"this.form.tblFilter.value='-- vom Tabellen Feld --';";  
            $s_tag.=
"this.form.defaultTbl.defaultIndex=this.form.defaultTbl.options[this.form.defaultTbl.options.selectedIndex];";  
            $s_tag.=
"this.form.defaultTbl.options[0].text='-- Tabellen Feld verwenden --';";  
            $s_tag.=
"this.form.defaultTbl.options.selectedIndex=0;";  
            $s_tag.=
"this.form.tblFilter.value=this.form.tblFilter.defaultValue;";  
            $s_tag.=
"this.form.defaultTbl.options[0].text='-- ??? --';";  
            $s_tag.=
"this.form.defaultTbl.options.selectedIndex=this.form.defaultTbl.defaultIndex;";  
            $s_tag.=
"<option value=\"\">--- ??? ---</option>\n";  
            foreach($a_tblFields as $o_fld) {  
                $s_tag.=
"<option value=\"".
$o_fld->getKey().
"\" ".
(($this->myTblField == 
$o_fld->getKey()) ? 
" selected=\"selected\"" : 
"").
">".
$o_fld->getLabel().
" (".
$o_fld->getName().
")</option>\n";  
            $a_ret['DB_TABLE']['FLD_TBLFIELD']['FLDVAL']=
$s_tag;  
        $a_ret['DB_TABLE']['FLD_DEFAULTTBL']['FLDVAL'] =
"<select name=\"defaultTbl\" size=\"1\">\n";  
        $a_ret['DB_TABLE']['FLD_DEFAULTTBL']['FLDVAL'].=
"<option value=\"\">--- ??? ---</option>\n";  
        $a_tables=
$GLOBALS['USRDB']->getDBTblList();  
        foreach($a_tables as $s_tbl) {  
            $s_opt=
"<option value=\"".
$s_tbl.
"\"";  
            if ($this->defaultTbl==
$s_tbl) $s_opt.=
" selected=\"selected\"";  
            $s_opt.=
">$s_tbl</option>\n";  
            $a_ret['DB_TABLE']['FLD_DEFAULTTBL']['FLDVAL'].=
$s_opt;  
        $a_ret['DB_TABLE']['FLD_DEFAULTTBL']['FLDVAL'].=
"</select>\n";  
      * saves the fld definition  
            $this->getMyForm(); // ensure we have the right form object  
                $o_tblfld->ajax_registerFldToNotify('onChange',$this->getKey(),'ajax_setColLst',$debug);  
    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  
    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  
      * returns the js code to update the column select list  
      * NOTE: the axCURVAL is the table  
        $s_arrName=
((isset
($_GET['axARRNAME']) && 
(!empty($_GET['axARRNAME']))) ? 
$_GET['axARRNAME'] : 
$this->getDataArrName());  
        $s_tblName=
(isset
($_GET['axCURVAL']) ? 
$_GET['axCURVAL'] : 
"");  
            if (fld_colSel=searchElement(document,\"".
$this->getColSelName().
"\"))   
                var str_curCol=fld_colSel.options[fld_colSel.options.selectedIndex].value;  
                fld_colSel.options.length=0;  
            foreach($a_optlst as $a_option)   
                $s_ret.=
"bol_selected=(str_curCol==\"".
$a_option['VALUE'].
"\");\n";  
                $s_ret.=
"fld_colSel.options[fld_colSel.options.length]=new Option(";  
                $s_ret.=
"\"".
$a_option['NAME'].
"\",\"".
$a_option['VALUE'].
"\",".
($a_option['DEFAULTSELECT'] ? 
"true" : 
"false").
",".
($a_option['SELECTED'] ? 
"true" : 
"bol_selected").
");\n";                  
      * returns the js code to update the table list select  
        $s_arrName=
((isset
($_GET['axARRNAME']) && 
(!empty($_GET['axARRNAME']))) ? 
$_GET['axARRNAME'] : 
$this->getDataArrName());  
        $s_value=
(isset
($_GET['axCURVAL']) ? 
$_GET['axCURVAL'] : 
"");  
        return "alert(\"TODO ".__CLASS__.
"::".__METHOD__.
"()\");";  
    // ###########################################################  
    // ###########################################################  
    // -----------------------------------------------------------  
    // -----------------------------------------------------------  
      * returns the table name out of $aValue or the global ${$this->getDataArrName()}  
      * NOTE: does not check if the table exists  
        global $
{$this->getDataArrName()};  
            if (is_array($aValue) && 
!empty($aValue['TBL'])) {  
                if ($a_TblCol=
explode('.',$aValue,2) && 
!empty($a_TblCol[0])) {  
            // return the default table to avoid an endless loop when recalling the function for empty values below  
      * returns an array of tables as options which can be used (in a js) to populate the list  
      * @param string $aTblName   
      * @returns array array(string [NAME], string [VALUE],boolean [DEFAULTSELECT],boolean [SELECTED])  
        if ($a_tables=
$GLOBALS['USRDB']->getDBTblList()) {  
                foreach($a_tables as $s_tbl)   
                    $b_selected=
(($s_tbl == 
$aTblName) ? 
TRUE : 
FALSE);  
                        reset($a_filter); $b_found=
FALSE;  
                        while(!$b_found && 
(list
($i_dx, $s_tbl) = 
each($a_tblFlter))) {  
                                $s_ret[]=
array('NAME'=>
$s_tbl,'VALUE'=>
$s_tag,'DEFAULTSELECT'=>
FALSE,'SELECTED'=>
$b_selected);  
                        $s_ret[]=
array('NAME'=>
$s_tbl,'VALUE'=>
$s_tag,'DEFAULTSELECT'=>
FALSE,'SELECTED'=>
$b_selected);  
    // -----------------------------------------------------------  
    // -----------------------------------------------------------  
      * returns the name of the column select element  
      * reads the table columns  
      * and adds all entries to $this->myValues  
      * @param string $arrName index of the data array in $GLOBALS  
        if ($debug) echo 
"<p><b>DBMS_FIELD_DBCOLSELECTLIST::setMyValues($arrName,$debug)</b> (".
get_class($this).
")</p>";  
            foreach($a_optlst as $a_option) {  
                $this->myValues[$a_option['VALUE']]=
$a_option['NAME'];  
      * returns an array of tables columns as options which can be used (in a js) to populate the list  
      * @param string $aTblName   
      * @returns array array(string [NAME], string [VALUE],boolean [DEFAULTSELECT],boolean [SELECTED])  
            $obj_myDB=
$this->myForm->getDBObj(); // <pk-07-11-28 />  
            $a_tblDesc=
$obj_myDB->getDBTblDesc($aTblName);   
                     $s_ret[]=
array('NAME'=>
$this->nullLabel,'VALUE'=>
"",'DEFAULTSELECT'=>
FALSE,'SELECTED'=>
FALSE);  
                foreach($a_tblDesc as $s_colName => 
$a_colDesc)   
                    if ($a_colDesc['PRIMARY_KEY'])   
                    $a_opt['NAME'].=
" (".
$a_colDesc['TYPE'];  
                    $a_opt['VALUE']=
$s_colName;  
                        $a_opt['VALUE']=
$aTblName.
".".
$s_colName;  
                    $a_opt['DEFAULTSELECT']=
FALSE;  
                    $a_opt['SELECTED']=
($aValue==
$a_opt['VALUE']);  
                $s_ret[]=
array('NAME'=>
"Wählen Sie bitte eine Tabelle aus!",'VALUE'=>
"",'DEFAULTSELECT'=>
FALSE,'SELECTED'=>
FALSE);  
            $s_ret[]=
array('NAME'=>
"Wählen Sie bitte eine Tabelle aus!",'VALUE'=>
"",'DEFAULTSELECT'=>
FALSE,'SELECTED'=>
FALSE);  
    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  
      * returns the html code for the select  
    function getInputTag($aValue,$arrName=
"DBVAL",$debug=
FALSE) {  
        $this->getMyForm(); // ensure the object is loaded  
        $s_tag=
"<a name=\"".
$this->myName.
"\"></a>";  
        if ($this->myForm->isReloaded($arrName,$debug)) {  
            if (isset($_POST[$arrName][$this->myName]['TBL'])) {  
                $s_tbl=$_POST[$arrName][$this->myName]['TBL'];  
                $s_col=(isset($_POST[$arrName][$this->myName]['COL']) ? $_POST[$arrName][$this->myName]['COL'] : "");  
        if (strstr($s_col,".")) { // value is TABLE.COLUMN  
        if ($debug) $s_tag.=
"Table: $s_tbl<br/>Value: $s_col<br />";          
        $o_ajax=
$this->myForm->ajax_getObj();  
            $s_ret.=
"TODO change Table ..".
substr(__FILE__
,-
20).
" LINE: ".__LINE__
;  
        foreach($a_optlst as $a_opt) {  
            $s_tag.=
"<option value=\"".
$a_opt['VALUE'].
"\"".
($a_opt['SELECTED'] ? 
" selected" : 
"").
">".
$a_opt['NAME'].
"</option>\n";  
      * returns the field value  
      * @param  string  $aValue     the value  
      * @param  array   $err        error array  
      * @param  string  $arrName    name of the array to access fieldsarray  gloabl ${$arrName}  
    function getValue($aValue,&$err,$arrName=
"DBVAL",$debug=
FALSE) {  
        if ($debug) echoDebug(__FILE__
,"<p><b>DBMS_FIELD_DBCOLSELECTLIST::getValue($aValue,$err,$arrName,$debug)</b> (".
get_class($this).
" | ".
$this->myName.
")</p>",0);  
            if (!empty($aValue['COL'])) {  
                    $col=
$aValue['TBL'].
".".
$aValue['COL'];  
        return parent::getValue($col,$err,$arrName,$debug);  
} // end class DBMS_FIELD_DBCOLSELECTLIST  
 
 
	
		Documentation generated on Thu, 08 Jan 2009 17:40:58 +0100 by phpDocumentor 1.4.0a2