Source for file DBMS_FIELD_FOREIGNKEY.phpclass
Documentation is available at DBMS_FIELD_FOREIGNKEY.phpclass
* Class file DBMS_FIELD_FOREIGNKEY.phpclass
* @project Open CSP-Management
* @author Peter Krebs (pk) <pitlinz@users.sourceforge.net>
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
* @version $Id: DBMS_FIELD_FOREIGNKEY.phpclass,v 1.18 2008/12/03 21:32:40 pitlinz Exp $
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
* handles foreign key fields
* @project Open CSP-Management
* @author Peter Krebs (pk) <pitlinz@users.sourceforge.net>
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
* @version pk-06-10-05 nullToZero added
* @version $Id: DBMS_FIELD_FOREIGNKEY.phpclass,v 1.18 2008/12/03 21:32:40 pitlinz Exp $
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
* @constant string CLASS_SRC_FILE
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
/*** class vars ------------------------------------------------------ */
/*** class methods --------------------------------------------------- */
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
/*** compostion --------------------------------------------------- */
/*** attributes --------------------------------------------------- */
* source file of the class
* @var string $classSrcFile
* @var boolean $checkWhereAnd
* url to popup for a new entry
* edit or insert data with ajax or open an popup
* width of the popup window
* @var int $popupWndWidth
* hight of the popup window
* @var int popupWndHeight
* @var string $editUrl url to the field editor
* @todo add tags to input field link new
* @var int $editEnableInList link List field with edit url
* @var string $myURIQueryArrgs semicolon seperated list of url arguments
* css class of the detail layer div
* @var string $myLayerDivClass
* css style of the detail layer div
* @var string $myLayerDivStyle
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
* convert old object vars to DBMS_FIELD_DBLOOKUPSELECTLIST
* and then calls the parent method
foreach($varArr as $str_name =>
$m_val)
if (!empty($varArr['lookupTable'])) $varArr['lookupTable']=
$m_val;
unset
($varArr['foreignTbl']);
if (!empty($varArr['lookupShowField'])) $varArr['lookupShowField']=
$m_val;
unset
($varArr['foreignTbl']);
if (!empty($varArr['lookupShowLstField'])) $varArr['lookupShowLstField']=
$m_val;
unset
($varArr['lst_showFld']);
if (!empty($varArr['lookupField'])) $varArr['lookupField']=
$m_val;
unset
($varArr['keyField']);
if (!empty($varArr['lookupWhere'])) $varArr['lookupWhere']=
$m_val;
unset
($varArr['whereAnd']);
if (!empty($varArr['lookupSort'])) $varArr['lookupSort']=
$m_val;
unset
($varArr['whereAnd']);
$varArr['showNullOption']=
$m_val;
unset
($varArr['allowNullSelect']);
parent::setObjectVars($varArr,$debug);
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
* 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>)
if (empty($this->keyField)) $this->keyField=
$this->myName; // <pk-06-11-29 />
$a_ret['LAYOUT']['FLD_SIZE']=
NULL; // unset parent field
$a_ret['LAYOUT']['FLD_INPUTADD']=
NULL; // unset parent field
$a_ret['SELECT']['FLD_MULTISEL']=
NULL; // unset parent field
//$a_ret['DBLOOKUP']['FLD_LSTADDVALUES']['FLDVAL']="<input name=\"allowAddValues\" type=\"checkbox\"".($this->allowAddValues ? " checked=\"checked\"" : "")." value=\"1\" />ja";
unset
($a_ret['DBLOOKUP']['FLD_LSTADDVALUES']); // unset parent field
$a_ret['DBLOOKUP']['FLD_WHEREFLD']['FLDVAL'].=
"<input name=\"checkWhereAnd\" type=\"checkbox\"".
($this->checkWhereAnd ?
" checked=\"checked\"" :
"").
" value=\"1\" /> beim speichern überprüfen.";
$a_ret['FTBL_POPUPS']=array(
'TITLE'=>"Bearbeiten/Hinzufügen",
'FLDLAB'=>"Neuer Datensatz",
<input name=\"allowAddValues\" type=\"checkbox\" value=\"1\" " . ($this->allowAddValues ? "checked=\"checked\"" : "") . " /> hinzufügen von Daten erlauben<br />
URL: <input name=\"newUrl\" value=\"" . $this->newUrl . "\" size=\"50\" /><br />
Form: <select name=\"newFormId\" id=\"" . str_replace(".","_",$this->getKey()) . "_newForm\" >
<option value=\"\">[Formular wählen]</option>
" . OCSP_FORM::findForm_getHTMLOptionList($this->lookupTable,$this->newFormId,$debug) ."
'FLDLAB'=>"Datensatz bearbeiten URL",
<input name=\"allowEditValues\" type=\"checkbox\" value=\"1\" " . ($this->allowEditValues ? "checked=\"checked\"" : "") . " /> bearbeiten von Details ermöglichen<br />
URL: <input name=\"editUrl\" value=\"".$this->editUrl."\" size=\"50\" /><br />
Form: <select name=\"editFormId\" id=\"" . str_replace(".","_",$this->getKey()) . "_editForm\" >
<option value=\"\">[Formular wählen]</option>
" . OCSP_FORM::findForm_getHTMLOptionList($this->lookupTable,$this->editFormId,$debug) ."
<input type=\"checkbox\" name=\"newEditAsAjax\" value=\"1\" " . ($this->newEditAsAjax ? "" : "checked=\"checked\" ") . " /> als Popup öffnen <hr />
width=<input name=\"popupWndWidth\" value=\"".$this->popupWndWidth."\" size=\"4\" />
height=<input name=\"popupWndHeight\" value=\"".$this->popupWndHeight."\" size=\"4\" /> <hr />
Popup Arguments: <input name=\"myURIQueryArrgs\" value=\"" .$this->myURIQueryArrgs ."\" size=\"40\" /><br />(durch Semicolon \";\" getrennte Feldnamen)
'FLDLAB'=>"Layer div class",
'FLDVAL'=>"<div class=\"<input name=\"myLayerDivClass\" value=\"" . $this->myLayerDivClass . "\" size=\"15\" />\"
style=\"<input name=\"myLayerDivStyle\" value=\"" . $this->myLayerDivStyle . "\" />\" >"
* update editTbl_getFieldEditArr fields after change of the table
$str_options =
"var i=1;\n"; // one to not overwrite the empty option
foreach($arr_forms as $arr_row)
$str_options .=
"obj_opt = new Option('" .
$arr_row['FRM_NAME'] .
" (ID: " .
$arr_row['FRM_ID'] .
")','" .
$arr_row['FRM_ID'] .
"');";
$str_options .=
"obj_sel.options[i++] = obj_opt;\n";
$str_options =
"var i=1;";
if (obj_sel = document.getElementById('" .
str_replace(".","_",$this->getKey()) .
"_newForm'))
obj_sel.selectedIndex = 0;
obj_sel.options.length = 1;
if (obj_sel = document.getElementById('" .
str_replace(".","_",$this->getKey()) .
"_editForm'))
obj_sel.selectedIndex = 0;
obj_sel.options.length = 1;
$str_ret =
"try {" .
$str_ret .
"} catch(e) { alert(e); }";
* save the filed definition form
* @returns bool <code>parent::save()</code>
function save($debug=
FALSE) {
$ret=
parent::save($debug);
if (isset
($this->foreignTbl)) unset
($this->foreignTbl);
if (isset
($this->showField)) unset
($this->showField);
if (isset
($this->lst_showFld)) unset
($this->lst_showFld);
if (isset
($this->keyField)) unset
($this->keyField);
if (isset
($this->sortField)) unset
($this->sortField);
if (isset
($this->allowNullSelect)) unset
($this->allowNullSelect);
$this->popupWndWidth =
((isset
($_POST['popupWndWidth']) &&
(intval($_POST['popupWndWidth']) >
10)) ?
intval($_POST['popupWndWidth']) :
600);
$this->popupWndHeight =
((isset
($_POST['popupWndHeight']) &&
(intval($_POST['popupWndHeight']) >
10)) ?
intval($_POST['popupWndHeight']) :
380);
$this->newEditAsAjax =
((isset
($_POST['newEditAsAjax']) &&
intval($_POST['newEditAsAjax'])) ?
FALSE :
TRUE);
$this->newUrl =
(isset
($_POST['newUrl']) ?
$_POST['newUrl'] :
$this->newUrl);
$this->newFormId =
(isset
($_POST['newFormId']) ?
intval($_POST['newFormId']) :
0);
$this->editUrl =
(isset
($_POST['editUrl']) ?
$_POST['editUrl'] :
$this->editUrl);
$this->editFormId =
(isset
($_POST['editFormId']) ?
intval($_POST['editFormId']) :
0);
$this->myLayerDivClass =
(isset
($_POST['myLayerDivClass']) ?
$_POST['myLayerDivClass'] :
"");
$this->myLayerDivStyle =
(isset
($_POST['myLayerDivStyle']) ?
$_POST['myLayerDivStyle'] :
"");
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
* returns the html code for the new button
* @global array $OCSP_CONF
function getNewBtn($arrName=
"DBVAL",$debug=
FALSE)
if ($debug) echoDebugMethod(__FILE__
,get_class($this),"DBMS_FIELD_DBLOOKUPSELECTLIST::getNewBtn","arrName: $arrName",0);
alert('add new Detail: " .
$this->myName .
"');";
if (obj_form = jOCSP.getFormByHash('" .
$this->myControll->jOCSP_getfrmHash() .
"'))
if (obj_fld = obj_form.getFieldByDomId('" .
$this->getDOMId() .
"'))
$str_onClick .=
"} catch(e) {alert('Field: " .
$this->myName .
": ' + e);}";
return "<a onclick=\"" .
pcf_js_escapeOnEventCmd($str_onClick) .
"\"><img src=\"" .
$OCSP_CONF['SYSIMGURL'] .
"icons-16x16/filenew.gif\" border=\"0\" alt=\"neuer Eintrag\" align=\"middle\" class=\"button\" /></a>";
* returns the html code for a button to zoom to the foreign record
* @param boolean $debug (pk-05-10-23)
* @version pk-05-02-22 parse url as template using ${$arrName} as value array
* @version pk-05-03-17 getPopupLinkJs added -> rewrite
* @version pk-05-10-23 param $debug added
if ($debug) echoDebugMethod(__FILE__
,get_class($this),"DBMS_FIELD_DBLOOKUPSELECTLIST::getZoomButton","arrName: $arrName",0);
alert('edit Detail: " .
$this->myName .
"');";
if (obj_form = jOCSP.getFormByHash('" .
$this->myControll->jOCSP_getfrmHash() .
"'))
if (obj_fld = obj_form.getFieldByDomId('" .
$this->getDOMId() .
"'))
$str_onClick .=
"} catch(e) {alert('Field: " .
$this->myName .
": ' + e);}";
return "<a onclick=\"" .
pcf_js_escapeOnEventCmd($str_onClick) .
"\"><img src=\"" .
$OCSP_CONF['SYSIMGURL'] .
"icons-16x16/" .
($this->allowEditValues ?
"edit.gif" :
"viewmag.gif") .
"\" border=\"0\" alt=\"Details\" align=\"middle\" class=\"button\" /></a>";
// -------------------------------------------------
// OBJECT VALUE CHECK/RETURN METHODS
// -------------------------------------------------
* returns the field value if the referenzed row exists
* @param string $aValue the value
* @param array $err error array
* @param string $arrName name of the array to access fieldsarray gloabl ${$arrName}
* @version pk-04-12-31 $this->label added to NULL ERROR MSG
* @version pk-05-06-16 debug due to fieldsettings
* @version pk-07-09-10 null handling
function getValue($aValue,&$err,$arrName=
"DBVAL",$debug=
False) {
if ($debug) echoDebugLine(__FILE__
,__LINE__
,"Returning $aValue");
if ($debug) echoDebugLine(__FILE__
,__LINE__
,"Returning ERROR <pre>".
print_r($err,TRUE).
" with value: $aValue");
$arr_parentError=
array();
$aValue=
parent::getValue($aValue,$arr_parentError,$arrName,$debug);
if (!isset
($arr_parentError['ERROR']) ||
!$arr_parentError['ERROR'])
if (!($obj_myDB=
$this->myForm->getDBObj()))
$err[$this->myName]['MSG']=
"ROW_NOT_FOUND";
// -------------------------------------------------
// -------------------------------------------------
* creates an layer for the detail record
$obj_ajax =
$this->myForm->ajax_getObj(TRUE);
$obj_form->ajax_setObj($options['AJAXOBJ']);
$obj_form->setFrmMode($mode);
$obj_controll =
$obj_form->getControllObj('OCSP_FRMCONTR_JQUERY');
$obj_controll->setBackCmd("document.getElementById('" .
$options['domId'] .
"').closeDetail();");
if (isset
($options['FRMARRAYNAME']))
$obj_controll->setValuesFromArray($options[$options['FRMARRAYNAME']]);
if (isset
($optons['foreignKey']) &&
(!empty($optons['foreignKey'])))
if ($mix_lookupValue =
$this->getValue($optons['foreignKey'],$arr_errors))
$obj_controll->addFilter($this->lookupField,$mix_lookupValue);
} else if (isset
($options['FRMARRAYNAME']) &&
is_array($options[$options['FRMARRAYNAME']])) {
if ($mix_lookupValue =
$this->getValue($options[$options['FRMARRAYNAME']][$this->getName()],$arr_errors))
$obj_controll->addFilter($this->lookupField,$mix_lookupValue);
$obj_controll->setNextUrl("js:document.getElementById('" .
$options['domId'] .
"').closeDetail('\$*" .
$this->lookupField .
"\$');");
$obj_view =
$obj_form->getViewObj('OCSP_FRMVIEW_FORM');
$str_frmContent =
$obj_view->getForm($mode);
if (obj_fld = document.getElementById('" .
$options['domId'] .
"'))
obj_fld.closeDetail = function(aValue)
this.det_shadow.parentNode.removeChild(this.det_shadow);
this.detLayer.parentNode.removeChild(this.detLayer);
this.jOCSPFldObj.addOption(aValue,aValue,false,true);
this.jOCSPFldObj.reloadOptionLst(aValue);
alert('Field: ' + typeof(obj_fld) + 'Cur Value: ' + obj_fld.value);
obj_form = jOCSP.getFormByHash(dom_form.jOCSP_frmHash);
obj_fld.det_shadow = obj_form.disableWithShadow();
obj_fld.detLayer = jOCSP.dom.formLayerCreate(obj_form.getDomObj().parentNode.id);
obj_fld.detLayer.innerHTML = '".
pcf_js_escape($str_frmContent).
"';
" .
jOCSP_registerError("DBMS_FIELD_FOREIGNKEY::jOCSP_detailFormLayer() field id: " .
$options['domId'] .
" not found",FALSE,print_r($_REQUEST,TRUE)) .
"
* shows the form or url to add a new record in the foreign table
* @return string (javascript)
* shows the form or url to edit a record in the foreign table
* @return string (javascript)
* shows the form or url to edit a record in the foreign table
* @return string (javascript)
Documentation generated on Thu, 08 Jan 2009 17:41:42 +0100 by phpDocumentor 1.4.0a2