Source for file DBMS_FORM.phpclass
Documentation is available at DBMS_FORM.phpclass
* Class file DBMS_FORM.phpclass
* I splitted the old php/db/forms.phpclass into
* 2 files php/db/forms.phpinc and this to be
* more flexible with own styled forms
* now you can simply copy the php/db/forms/ dir
* to your own project path and set $GLOBALS['PRJOECT']['PHPFORMPATH']
* tho the new directory where you can change the classes to fit
* @project Open CSP-Management
* @author Peter Krebs (pk) <pitlinz@users.sourceforge.net>
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
require_once dirname(__FILE__
).
_OCSP_DIRSEP_.
"forms.phpinc";
* Databese Formulars / Lists
* this class can be used to handel all kind of forms needed
* it is administrated through the admin link: /admin/dbms
* - the fields are no longer stored just by serialize
* DBMS_FORM::fieldLst instead a seralized are is stored
* therefore the classes need not to be preloaded
* - each field requieres the a DBMS_FIELD::getObjectData()
* function returning a 2 dimensional array:
* -- $fldData['OBJDESC'] -> discription of the object
* -- $fldData['OBJVAL'] -> get_object_vars($this)
* @see DBMS_FORM::fieldLst_ToTxt()
* - before the fieldObject is created by evaluating
* <code>eval("\$fld=new ".$fldData['OBJDESC']['SRCFILE']."()");</code>
* the object class source is included with
* <code>require_once $GLOBALS['PROJECT']['PATH'].$fldData['OBJDESC']['SRCFILE']; </code>
* @see DBMS_FORM::fieldLst_FromTxt()
* @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-07-02-27 ajax
* @var string $frmName unique name of the form
* @var string $frmRevsion fore future use
* @var longstring $frmDesc Beschreibungstext
* @var array $frmTables array with db tablenames used in the form
* @var boolean $isTblDefault the form is the default form for the one and only table it uses
* @var array $frmKeys array of the db key colum names
* @var array $frmFields array of field objects DBMS_FIELD or child classes
* @var array $frmJoin array of identifing foreign key COLUMNS
* key is the DB column name
* value is an array of DB columns (TABLENAME.COLNAME)
* @var array $frmRights array of groups and access rights
* @todo form rights are not implemented jet
* @var linuxTimestamp $lastDBCheck timestamp when db-columns/fields has been checked
* with the database tables
* @var boolean $debugMode
* [FLD] array [LABEL],[MSG]
* @var string $myDBMS_TABLEOBJ_include table object class include
* @var string $myDBMS_TABLEOBJ_class table object class
* @var array $buttons definition
* @todo add to dbms admin to customize buttons per form
* @var string $gDBIDX $GLOBALS[] index of db object
* @deprecated since pk-07-06-28
* @var string $FRMLST_THADD list header th add tag
* @var boolean $debugInsert
* @var boolean $debugUpdate
* @var boolean $debugDelete
* @var array $layoutFields
* @var boolean $lstShowRowNr
* @var string $myHTMLName
* @var string $FRMEDITURL
* @var string $FRMDELETEURL
* @var string HTMLFORM_arrayName
* @var string HTMLFORM_URL_back if empty history.back()
* @var int FRMLST_LIMIT number of lines per list (0=no limit)
* @var string $myClassSrcFile sourcefile of the class
* the ajax object for the form
* NOTE: the class source is not automaticaly implemented
* @var AJAX_FORM $myAjaxObj
// ###############################
* @param int $aId FRM_ID in the database if !0 the form is loaded from the database
* @param boolean $debug since pk-05-01-12
* returns the value of an object variable
if (isset
($this->{$varName})) return $this->{$varName};
* sets the value of an object variable
if (!empty($varName)) $this->{$varName} =
$value;
* @deprecated since pk-07-06-28
* @deprecated since pk-07-06-28
if (empty($this->gDBIDX)) return "USRDB";
* returns the db ojbect of the form and ensures the db object is connected
* @requires __OCSP_PHPINCPATH__."db/OCSP_DB.phpclass"
* @param boolean $withoutOCSPPath
* @version pk-06-12-17 // use of $this->myClassSrcFile instead of __FILE__
* marks the form as new it will be inserted on $this::storeToDb
function setAsNew($frmName=
NULL,$frmDesc=
"",$debug=
"0") {
if ($debug) echoDebug(__FILE__
,"<p><b>DBMS_FORM::setAsNew($frmName)</b> (".
get_class($this).
")</p>",0);
if (!empty($frmName)) $this->frmName=
$frmName;
if (!empty($frmDesc)) $this->frmDesc=
$frmDesc;
* returns the name of the form
* @returns string unique name of the form
* returns the name of the form in the html form
* sets the name of the form in the html form
if (empty($this->frmTitle)) return $this->getName();
* returns the name of the form
* @returns int ID of the form
* @returns boolean $this->debugMode
* @param string $aName name of the form
* @param string $tbls comma seperated list of tables used
* @param boolean $asDefault it's the default form ($aName equal $tbls)
function create($aName,$tbls=
"",$asDefault=
0) {
if (!$GLOBALS['USRDB']->isConnected) return FALSE;
* unserializes a fieldRow (array element)
* @param array $fldRow the database row since pk-06-07-28
function unserFldRow($key,$fldDesc,$debug=
FALSE,$fldRow=
NULL) {
if ($debug) echo
"<p><b>DBMS_FORM::unserFldRow($key,...)</b> (".
get_class($this).
")</p><blockquote>";
if (!isset
($fldDesc['OBJDESC']['CLASS']) ||
empty($fldDesc['OBJDESC']['CLASS'])) { // <pk-07-03-05>
$fldDesc['OBJDESC']['CLASS']=
$fldRow['FLD_CLASS'];
if ($debug) echo
"<p>unserFldRow $key:</p><pre>".
print_r($fldDesc,TRUE).
"</pre><p>\$fldRow: </p><pre>".
print_r($fldRow,TRUE).
"</pre>";
$a_incFile[]=
$GLOBALS['PROJECT']['PATH'].
$fldDesc['OBJDESC']['SRCFILE'];
if (isset
($fldRow['FLD_CLASS_SRC']) &&
(!empty($fldRow['FLD_CLASS_SRC']))) {
$a_incFile[]=
$GLOBALS['PROJECT']['PATH'].
$fldRow['FLD_CLASS_SRC'];
$a_incFile[]=
$GLOBALS['PROJECT']['PHPINCPATH'].
$fldRow['FLD_CLASS_SRC'];
$a_incFile[]=
$GLOBALS['PROJECT']['PHPINCPATH'].
$fldDesc['OBJDESC']['SRCFILE'];
$a_incFile[]=
$fldDesc['OBJDESC']['SRCFILE'];
while(!$b_found && list
($s_classFile)=
each($a_incFile)) {
require_once $s_classFile;
$fldDesc['OBJDESC']['CLASS']=
"DBMS_FIELD";
if ($debug) echo
"<p>CLASSFILE NOT FOUND -> CHANGED TO DBMS_FIELD</p>";
$cmd=
"\$this->frmFields[\$key]=new ".
$fldDesc['OBJDESC']['CLASS'].
";";
if ($debug) echo
"<p><br />$cmd</p></blockquote>";
$this->frmFields[$key]->setObjectVars($fldDesc['OBJVAL']);
if (isset
($fldRow['FLD_SORTORDER']) &&
intval($fldRow['FLD_SORTORDER'])) { // <pk-06-07-28> get sortorder from DB
* generates frmFields out of a string
* generated with DBMS_FORM::db_setFieldLst
* @returns boolean TRUE if succeed
if ($debug) echo
"<p><b>DBMS_FORM::fieldLst_FromTxt(...)</b> (".
get_class($this).
")</p>";
if ($debug) echo
"<p>\$serTxt<br />$serTxt</p><pre>".
print_r($fldDescArr,TRUE).
"</pre>";
if ($debug) echo
"<blockquote>";
foreach($fldDescArr as $key =>
$fldDesc) {
if ($debug) echo
"<p>DONE fieldLst_FromTxt</p></blockquote>";
return ($hasError ?
FALSE :
TRUE);
if ($debug) echo
"<blockquote>\$fldDescArr<pre>".
print_r($fldDescArr).
"</pre></blockquote>";
* generates a string to store the fieldlist
* into a blob (text) field
if ($debug) echo
"<p><b>DBMS_FORM::fieldLst_ToTxt(...)</b> (".
get_class($this).
")</p><blockquote>";
if ($debug) echo
"</blockquote>";
* returns an array representing the table row of the
* @param boolean $withoutNull
* @param int $srcVersion (pk-05-07-14)
* @version pk-05-03-23 debugMode changed
function getDBRow($withoutNull=
FALSE,$debug=
FALSE,$srcVersion=
3) {
if ($debug) echo
"<p><b>DBMS_FORM::getDBRow($withoutNull,$debug)</b> (".
get_class($this).
")</p><blockquote><hr />";
$dbValues['FRM_ID'] =
$this->frmId;
$dbValues['FRM_REVISION'] =
$this->getObjectVar('frmRevision');
$dbValues['FRM_NAME'] =
$this->frmName;
$dbValues['FRM_TITLE'] =
$this->getObjectVar('frmTitle'); // <pk-05-08-25 />
$dbValues['FRM_QUERY'] =
$this->frmQuery;
if (empty($this->serFieldsV0)) { /* <pk-05-01-12> */
$dbValues['FRM_FIELDS'] =
$this->serFieldsV0;
if ($debug) echo
"<p>fldStr:</p><blockquote><pre>".
print_r(unserialize($fldStr),TRUE).
"</pre></blockquote>";
$dbValues['FRM_FIELDSV2'] =
$fldStr;
$dbValues['FRM_SRCVERSION'] =
2;
$dbValues['FRM_SRCVERSION'] =
$srcVersion;
$dbValues['FRM_FIELDS'] =
"";
$dbValues['FRM_FIELDSV2'] =
"";
// add the fields in a none db array used in cache
if ($debug) echo
"<p>fldStr:</p><blockquote><pre>".
print_r(unserialize($fldStr),TRUE).
"</pre></blockquote>";
$dbValues['_NODB_FIELDS_'] =
$fldStr;
$dbValues['FRM_DEBUG'] =
$debugMode;
$dbValues['FRM_UTIMESTAMP'] =
time();
$dbValues['FRM_LNK_AFTERINSERT'] =
$this->getObjectVar('FRM_LNK_AFTERINSERT');
$dbValues['FRM_LNK_AFTEREDIT'] =
$this->getObjectVar('FRM_LNK_AFTEREDIT');
$dbValues['FRM_LNK_AFTERDELETE'] =
$this->getObjectVar('FRM_LNK_AFTERDELETE');
foreach($dbValues as $key =>
$val) {
if (!empty($val) ||
($val ===
0) ||
($val ===
"0")) $tmp[$key]=
$val;
if ($debug) echo
"<hr /><p><b>END</b>DBMS_FORM::getDBRow()</p></blockquote>";
* sets the object values from a data array
* @param boolean $asPopulated not used
function setDBRow($dbVal,$asPopulated=
TRUE,$debug=
FALSE) {
if ($debug) echo
"<p><b>DBMS_FORM::setDBRow($row,$asPopulated,$debug)</b> (".
get_class($this).
")</p>";
$this->frmId =
$dbVal['FRM_ID'];
$this->frmName =
$dbVal['FRM_NAME'];
$this->frmTitle =
$dbVal['FRM_TITLE']; // <pk-05-08-25 />
$this->frmDesc =
$dbVal['FRM_DESC'];
if (!isset
($dbVal['FRM_JOIN']) ||
!empty($dbVal['FRM_JOIN']))
if (isset
($dbVal['FRM_KEYS']) &&
!empty($dbVal['FRM_KEYS']))
if ($debug) echo
"<p>FRM_SRCVERSION: ".
$dbVal['FRM_SRCVERSION'].
"</p>";
if (intval($dbVal['FRM_SRCVERSION']) <
2) {
if ($debug) echo
"<p>SOURCEVERSION < 2 set fields</p>";
$this->serFieldsV0 =
$dbVal['FRM_FIELDS'];
if ($dbVal['FRM_SRCVERSION'] <
3) {
$fldStr=
$dbVal['FRM_FIELDSV2'];
$fldStr=
(isset
($dbVal['_NODB_FIELDS_']) ?
$dbVal['_NODB_FIELDS_'] :
"");
if ($debug) echo
"<p>SOURCEVERSION 2 set fields</p>";
if (substr($fldStr,0,8)==
"~~BA64~~") {
if ($debug) echo
"<p>fldStr:<br />$fldStr</p>";
// $this->frmFields = unserialize($dbVal['FRM_FIELDS']);
$this->serFieldsV0 =
$dbVal['FRM_FIELDS'];
echo
"<p><b>ERROR LOADING FORM</b></p>";
$debugMode=
intval($dbVal['FRM_DEBUG']);
$this->FRM_LNK_AFTERINSERT =
$dbVal['FRM_LNK_AFTERINSERT'];
$this->FRM_LNK_AFTEREDIT =
$dbVal['FRM_LNK_AFTEREDIT'];
$this->FRM_LNK_AFTERDELETE =
$dbVal['FRM_LNK_AFTERDELETE'];
$query=
"SELECT * FROM T_DBMS_FORMRIGHTS WHERE FRM_ID=".
$this->frmId;
while($row =
$cursor->fetchArrayFld()) {
foreach($row as $key =>
$val) {
if (intval($dbVal['FRM_SRCVERSION']) <
3) {
if ($debug) echo
"<p>UPDATING FORM</p><blockquote>";
if ($debug) echo
"</blockquote>";
* stores a form object to database table T_DBMS_FORM
* uses $GLOBALS['USRDB'] as database object calls
* return $GLOBALS['USRDB']->replace("T_DBMS_FORM",$dbValues,$debug);
* INSERT FORM -> update fields -> UPDATE FROM
* @version pk-05-01-13 update fields after insert
* @version pk-05-07-11 T_DBMS_FORMFIELDS added
* @version pk-07-06-10 FRM_CLASS added
$dbValues=
$this->getDBRow(FALSE,$debug,3);
$dbValues['FRM_SRCVERSION']=
3;
if ($debug) {echo
"<p>\$dbValues</p><pre>".
print_r($dbValues,TRUE).
"</pre>";}
if (!($GLOBALS['USRDB']->replace("T_DBMS_FORM",$dbValues,$debug))) {
echo
"<p>ERROR SAVING FORM (replace)</p>";
if ($this->frmId=
$GLOBALS['USRDB']->insertArray("T_DBMS_FORM",$dbValues,$debug)) {
if ($debug) echo
"<blockquote><p>Setting new frmId to fields</p>";
foreach($this->frmFields as $key =>
$fldObj) {
$this->frmFields[$key]->setFrmId($this->frmId); // sets the form id to the fields
if ($debug) echo
"<hr width=\"75%\" align=\"center\"></blockquote><p>storeToDb return TRUE</p>";
if ($debug) echo
"<hr width=\"75%\" align=\"center\"></blockquote><p style=\"color:red;font-weight:bold;\">storeToDb return TRUE</p>";
// Delete all fields (as we don't know if some has been deleted)
$GLOBALS['USRDB']->executeCmd("DELETE FROM T_DBMS_FORMFIELDS WHERE FRM_ID=".
intval($this->frmId).
" AND FRM_MODULE='DBMS'");
'FRM_ID' =>
$this->frmId,
'FLD_TABLE' =>
$fld->getTable(),
'FLD_IS_HIDDEN' =>
intval($fld->isHidden()),
'FLD_SHOW_IN_LIST' =>
intval($fld->isHidden('list')),
'FLD_SORTORDER' =>
intval($fld->getOrderNr()),
'FLD_CLASS_SRC' =>
$fld->getSourceFile($debug),
'FLD_LABEL' =>
$fld->getLabel() // <pk-05-10-04 />
$GLOBALS['USRDB']->replace("T_DBMS_FORMFIELDS",$a_fldRow,$debug);
* loads the form form the database
* returns true if a row with $this->id is fetched from the db
* NOTE: table columns are hard coded changes to the database table
* @returns boolean succeed?
* @var DBCURSOR $o_Cursor
if ($debug) echo
"<p><b>DBMS_FORM::loadFromDb(...)</b> (".
get_class($this).
")</p>";
$query=
"SELECT * FROM T_DBMS_FORM WHERE FRM_ID=".
intval($this->frmId);
if ($this->setDBRow($dbVal,TRUE,$debug)) {
if (intval($dbVal['FRM_SRCVERSION']) >
2) {
$s_Query =
"SELECT * FROM T_DBMS_FORMFIELDS ";
$s_Query.=
" AND FRM_MODULE='DBMS'";
$s_Query.=
" ORDER BY FLD_SORTORDER";
if ($debug) echo
"<p>".
$s_Query.
"</p>";
while ($a_fldRow=
$o_Cursor->fetchArrayFld()) {
if ($debug) echo
"<p>FIELD: ".
$a_fldRow['FLD_KEY'].
"</p><blockquote>";
$this->unserFldRow($a_fldRow['FLD_KEY'],$a_fldDesc,$debug,$a_fldRow);
if ($debug) echo
"</blockquote>";
echo
"<p>ERROR IN QUERY: $o_Query</p>";
* removes the cache files of the form
* @param boolean $clear_tblcache
if (!empty($GLOBALS['PROJECT']['OBJCACHEPATH'])) {
@unlink($GLOBALS['PROJECT']['OBJCACHEPATH'].
"dbms_forms/".
$this->frmId.
".cache");
@unlink($GLOBALS['PROJECT']['OBJCACHEPATH'].
"dbms_forms/".
$this->frmName.
".cache");
foreach (glob($GLOBALS['PROJECT']['OBJCACHEPATH'].
$tbl.
"*.cache") as $s_fileName) {
* merges the fields of an other form to $this
* if ($prepend) is true the fields will be prepended
* else appended to the fieldlist
* @param DBMS_FORM $frmMerge
* @param boolean $prepend
if ($debug) echoDebug(__FILE__
,"<p><b>DBMS_FORM::mergeForm(...)</b> (".
get_class($this).
")</p>",0);
// get sorted fieldlists from both
// determin sortindex ot the new fields
else $i_sort=
sizeof($a_myflds)+
1;
foreach($a_addflds as $key =>
$o_fld) {
// add the form form fields to
if ($debug) echoDebug(__FILE__
,"<p>".
$o_fld->getName().
" TBL ".
$o_fld->getTable().
"</p>",1);
$o_fld->sortOrder=
$i_sort++
; // at position
// move the already existing fields behind the new ones
foreach($a_myflds as $key =>
$o_fld) {
$a_myflds[$key]->sortOrder=
$i_sort++
;
// finaly add the tables of the merge form to myTable
// adding tables to $aktForm
if ($debug) echoDebug(__FILE__
,"<p>Adding Table: $s_tbl</p>",1);
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
* private method checks right from table T_DBMS_FORMRIGHTS
* @param string $col right column name
* @param int $usrId user id (if !intval($GLBOALS['USER'] is used)
* @version pk-06-03-06 memory cache $GLOBALS['OCSP']['CACHE']['FRMRIGHTS'][$this->getId()][$usrId][$col] added
function p_userCan($col,$usrId=
NULL,$debug=
FALSE) {
// no check for admins required
if ($debug) echo
"<p>No check for admin return TRUE</p>";
$usrId=
$GLOBALS['USER']->getId(); // check against current user
if ($GLOBALS['OCSP']['CACHE']['FRMRIGHTS'][$this->getId()][$usrId][$col]) return TRUE; // </pk-06-03-06> memory cached value
if ($GLOBALS['OCSP']['FRMDEFAULTRIGHT']) { // <pk-06-03-06>
$s_query=
"SELECT COUNT(*) FROM T_DBMS_FORMRIGHTS WHERE FRM_ID=".
$this->getId();
if (!intval($GLOBALS['USRDB']->quickQuery($s_query,0))) {
$GLOBALS['OCSP']['CACHE']['FRMRIGHTS'][$this->getId()][$usrId][$col]=
TRUE;
if (!intval($usrId)) { // we have a public user -> check against group id 0
$query =
"SELECT * FROM T_DBMS_FORMRIGHTS ";
$query.=
" WHERE FRM_ID=".
$this->getId();
$query.=
" AND ".
$col.
"<>0";
if ($debug) echo
"<p>Checking Public</p>";
if ($GLOBALS['USRDB']->quickQuery($query)) {
$GLOBALS['OCSP']['CACHE']['FRMRIGHTS'][$this->getId()][$usrId][$col]=
TRUE;
return TRUE; // the query returned a result -> public can do
return FALSE; // no row found -> public can not do
$query =
"SELECT GRP_ID FROM T_DBMS_FORMRIGHTS WHERE FRM_ID=".
$this->getId();
$query.=
" AND $col<>0 ORDER BY GRP_ID";
if ($debug) echoDebug(__FILE__
,"<p>NOT PUBLIC: $query</p>",1);
if (!($allowedGrps=
$GLOBALS['USRDB']->queryArray($query))) {
$query =
"SELECT GRP_ID FROM T_SYS_GROUPMEMBER WHERE USR_ID=".
intval($usrId);
$query.=
" AND GRP_ID IN (";
foreach($allowedGrps as $grpId) {
// public no more need to check
$GLOBALS['OCSP']['CACHE']['FRMRIGHTS'][$this->getId()][$usrId][$col]=
TRUE;
if (($grpId==-
1) &&
($usrId==
$GLOBALS['USER']->getId())) {
$GLOBALS['OCSP']['CACHE']['FRMRIGHTS'][$this->getId()][$usrId][$col]=
TRUE;
return TRUE; // only logged in users and user is logged in
if ($debug) echo
"<p>$query</p>";
$GLOBALS['OCSP']['CACHE']['FRMRIGHTS'][$this->getId()][$usrId][$col]=
$GLOBALS['USRDB']->quickQuery($query);
return $GLOBALS['OCSP']['CACHE']['FRMRIGHTS'][$this->getId()][$usrId][$col];
* checks if a user is allowed to edit (update) the data
* @param int $usrId the user id if (!isset $GLOBALS['USER']->getId() is used)
if ($debug) echo
"<p><b>DBMS_FORM::userCanEdit($usrId)</b> (".
get_class($this).
"/".
$this->myName.
")</p>";
return $this->p_userCan("FRI_UPDATE",$usrId,$debug);
* checks if a user is allowed to add (insert) new data
* @param int $usrId the user id if (!isset $GLOBALS['USER']->getId() is used)
if ($debug) echo
"<p><b>DBMS_FORM::userCanInsert($usrId)</b> (".
get_class($this).
"/".
$this->myName.
")</p>";
return $this->p_userCan("FRI_INSERT",$usrId,$debug);
* checks if a user is allowed to delete the data
* @param int $usrId the user id if (!isset $GLOBALS['USER']->getId() is used)
if ($debug) echo
"<p><b>DBMS_FORM::userCanDelete($usrId)</b> (".
get_class($this).
"/".
$this->myName.
")</p>";
return $this->p_userCan("FRI_DELETE",$usrId,$debug);
* checks if a user is allowed to show the data
* @param int $usrId the user id if (!isset $GLOBALS['USER']->getId() is used)
if ($debug) echo
"<p><b>DBMS_FORM::userCanShow($usrId)</b> (".
get_class($this).
"/".
$this->myName.
")</p>";
return $this->p_userCan("FRI_SHOW",$usrId,$debug);
* checks if a user is allowed to export the data
* @param int $usrId the user id if (!isset $GLOBALS['USER']->getId() is used)
if ($debug) echo
"<p><b>DBMS_FORM::userCanExport($usrId)</b> (".
get_class($this).
"/".
$this->myName.
")</p>";
return $this->p_userCan("FRI_EXPORT",$usrId,$debug);
* returns a html statement for no rights errors
function getHTMLFormNoRights($usrId=
0,$mode=
FRM_READONLY,$dbVal=
NULL,$txtInfo=
"",$debug=
FALSE) {
$ret=
"\n\n<!-- ____________________FORMULAR START___________________________ -->\n\n";
$s_ret =
"<form name=\"".
$this->getHTMLName().
"\" ".
$this->FRMTAGADD.
" >\n"; // use form to have the right table layout if css and form id is used
$ret.=
"<table ".
$this->FRMTBLTAG.
">\n";
$ret.=
$this->FRMTBLHEADERROW;
$ret.=
"\t<tr><td class=\"frmErrorLabel\">Fehler</td><td class=\"frmErrorText\"><br /><br />Sie sind nicht berechtigt hier ";
$ret.=
"neue Daten anzulgen.";
$ret.=
"Daten zu bearbeiten.";
$ret.=
"Daten zu kopieren";
$ret.=
"<br /><br /> </td></tr>\n";
$ret =
"\n\t<!-- _______ BUTTONS ______ -->\n\n";
$ret.=
"\t<tr><td class=\"frmButtons\" colspan=\"2\">\n";
if (!empty($_GET['OPENERURL'])) {
// we are in a popup add close button
$ret.=
"\t\t<a href=\"#\" onClick=\"javascript:{top.close();}\">";
$ret.=
"<img src=\"".
$this->HTMLFORM_button_src['CLOSE'].
"\" alt=\"schliessen\" border=\"0\" class=\"button\">";
$ret.=
"\t\t<a href=\"".
$s_link.
"\">";
$ret.=
"<img src=\"".
$this->HTMLFORM_button_src['BACK'].
"\" class=\"button\" alt=\"abbrechen\" border=\"0\" class=\"button\">";
$ret.=
"\t\t<a name=\"btnBack\" onClick=\"history.back()\">";
$ret.=
"<img src=\"".
$this->HTMLFORM_button_src['BACK'].
"\" class=\"button\" alt=\"abbrechen\" border=\"0\" class=\"button\">";
$ret.=
"\n\n<!-- __________________FORMULAR ".
$this->getName().
" END_________________________ -->\n\n";
* returns if the user is allowed in mode
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
* checks if a field with $fldName exists for table $tbl (if not empty)
* @param string $fldName name of the field
* @param string $tbl name of the table (only checked if not empty)
if ($fld->getKey() ==
$tbl.
".".
$fldName) return TRUE;
if ($fld->getName()==
$fldName) return TRUE;
* transform a key to a dbusable column name
* (only letters, numbers and underscore)
* returns if the form has a sortcolumn (DBMS_FIELD_ORDERNR)
* @param boolean $withArrowOnly
function hasSortFld($withArrowOnly=
FALSE,$debug=
FALSE) {
if ($debug) echoDebug(__FILE__
,"<p><b>DBMS_FORM::hasSortColumn()</b> (".
get_class($this).
")</p>",0);
foreach($this->frmFields as $key =>
$o_fld) {
if ($withArrowOnly &&
$o_fld->showArrows) {
} else if (!$withArrowOnly) {
* @param string $class class name
* @param string $key column name
* @param string $tbl table name
function &newField($class,$key,$tbl=
DBMS_NO_DBFIELD,$orderNr=
0,$label=
"",$dbDesc=
NULL,$debug=
FALSE) {
if ($debug) echo
"<p><b>DBMS_FORM::newField($class,$key,$tbl,$orderNr,.....)</b> (".
get_class($this).
")</p>";
if (empty($class)) $class=
"DBMS_FIELD";
$dbDesc['TYPE']=
"unknown";
if (!isset
($dbDesc['FLAGS']) ||
!is_array($dbDesc['FLAGS'])) {
$dbDesc['FLAGS']=
array();
if ($obj->sortOrder >=
$orderNr) $obj->sortOrder++
;
if (!isset
($GLOBALS['PROJECT']['DBMSFLDCLASS_SRC'][$class])) {
if (isset
($GLOBALS['DBMD_FLDCLASS_DESC'][$class])) {
$GLOBALS['PROJECT']['DBMSFLDCLASS_SRC'][$class]=
$GLOBALS['PROJECT']['PHPINCPATH'].
$GLOBALS['DBMD_FLDCLASS_DESC'][$class]['FLD_CLASS_SRC'];
if (file_exists($GLOBALS['PROJECT']['DBMSFLDCLASS_SRC'][$class])) {
require_once $GLOBALS['PROJECT']['DBMSFLDCLASS_SRC'][$class];
} else if (file_exists($GLOBALS['OCSP']['DBMSFLD_PATH'].
$class.
".phpclass")) { // <pk-05-11-14>
require_once $GLOBALS['OCSP']['DBMSFLD_PATH'].
$class.
".phpclass";
echo
"<p>Error Loding class: $class</p>";
echo
"<pre>".
print_r($GLOBALS['OCSP'],TRUE).
"</pre>";
$cmd=
"\$fld=new ".
$class;
$cmd .=
"(\$tbl,\$key,\$dbDesc,\$orderNr,\$label);";
if (($debug)) echo
"<pre>$cmd</pre>";
if ($debug) {echo
"<p>Field: ".
$fld->getKey().
" Class: ".
get_class($fld).
" created</p>";}
$fld->setFrmId($this->frmId); /* <pk-04-02-23 /> */
* adds a new field and get the class out of type
* @param string $class class name
* @param string $key column name
* @param array $dbDesc db field description array
* @param string $tbl table name
function &addClassField($class,$key,$dbDesc=
NULL,$label=
"",$tbl=
DBMS_NO_DBFIELD,$debug=
FALSE) {
if ($debug) echoDebug(__FILE__
,"<p><b>DBMS_FORM::addClassField($class,$key,$dbDesc,$label,$tbl,$debug)</b> (".
get_class($this).
")</p>",0);
$this->frmFields[$tbl.
".".
$key]=
&$this->newField($class,$key,$tbl,0,$label,$dbDesc,$debug);
$this->frmFields[$tbl.
".".
$key]->setFrmId($this->frmId); // <pk-04-02-23 />
* adds a new field and get the class out of type
* if the class could not derived from
* $GLOBALS['DBMS_FIELD_CLASSES'][$type] DBMS_FIELD is used
* @param string $key column name
* @param string $type column db type
function &addField($key,$type=
"unknown",$dbDesc=
NULL,$label=
"",$tbl=
DBMS_NO_DBFIELD,$debug=
FALSE) {
if ($debug) echo
"<p><b>DBMS_FORM::addField($class,$key,$dbDesc,$label,$tbl,$debug)</b> (".
get_class($this).
")</p><blockquote>";
$dbDesc['NULL']=
TRUE; // <pk-05-07-14>
if (!isset
($dbDesc['FLAGS']) ||
!is_array($dbDesc['FLAGS'])) $dbDesc['FLAGS']=
array(); // <pk-06-07-27 /> E_ALL
if (isset
($GLOBALS['DBMS_FIELD_CLASSES'][$type]) &&
$GLOBALS['DBMS_FIELD_CLASSES'][$type]) {
$class=
$GLOBALS['DBMS_FIELD_CLASSES'][$type];
return $this->addClassField($class,$key,$dbDesc,$label,$tbl,$debug);
function &addPKField($key,$label=
"",$type=
"unknown",$dbDesc=
NULL,$tbl=
DBMS_NO_DBFIELD,$debug=
FALSE) {
$dbDesc['PRIMARY_KEY']=
TRUE;
$fld=
$this->addField($key,$type,$dbDesc,$label,$tbl,$debug);
function &addNoDbField($key,$label=
"",$type=
"unknown",$tbl=
DBMS_NO_DBFIELD,$debug=
FALSE) {
if ($debug) echo
"<p><b>DBMS_FORM::addNoDbField($key,$label,$type,$tbl,...)</b> (".
get_class($this).
")</p>";
return $this->addField($key,$type,NULL,$label,$tbl,$debug);
function &addNoDbClassField($class,$key,$label=
"",$tbl=
DBMS_NO_DBFIELD,$debug=
FALSE) {
if ($debug) echo
"<p><b>DBMS_FORM::addNoDbClassField($class,$key,$label,$tbl,...)</b> (".
get_class($this).
")</p>";
return $this->addClassField($class,$key,array("NULL" =>
TRUE),$label,$tbl,$debug);
* adds afield object to the form
* @param DBMS_FIELD $field
* @param boolean $keepTable
* @param boolean $keepSort
function &addFieldObj($field,$keepTable=
TRUE,$debug=
FALSE,$keepSort=
FALSE) {
} else { // <pk-06-07-14 />
$i_sortNr=
$field->sortOrder;$i_idx=
$i_sortNr;
$a_fldLst[$i_idx]->sortOrder=++
$i_sortNr;
$field->myFrmId=
$this->getId();
* adds a field object to the form
* @param DBMS_FIELD $field
* @returns &DBMS_FIELD pointer to the copy of the field inserted to the form
$field->setFrmId($this->getId());
* creates a db column out of a field
* @version pk-06-04-23 clearCache added
if ($debug) echo
"<p><b>DBMS_FORM::createDBColumn($fldName,$debug)</b> (".
get_class($this).
")</p>";
// check if we have a table
if ($GLOBALS[$this->get_gDBIDX()]->tblExists($s_tbl)) {
if (($fld->dbDesc['TYPE'] !=
"layout") &&
(substr($fld->myTableAlias,0,8) !=
"OBJVALS_")) {
// ok we have no layout field and no object value field -> we can alter the table
// adjust fields db description
$dbDesc=
$fld->getdbDesc();
if (!intval($dbDesc['LEN'])) {
$dbDesc['LEN']=
$fld->maxlength; // set field length to max input length
$dbDesc['NULL']=
1; // always allow null to avoid errors if the table is used
// for other forms which do not use the column
// -> use the form to check null values
$s_cmd =
"ALTER TABLE ".
$s_tbl.
" ADD ".
$fld->getName();
$s_cmd.=
$GLOBALS[$this->gDBIDX]->getColumnDef($dbDesc,$debug);
if ($debug) echo
"<p>CMD: <b>$cmd</b></p>\n";
$GLOBALS[$this->get_gDBIDX()]->executeCmd($s_cmd);
if ($fld->setTable($s_tbl,"",TRUE,$debug)) {
// #########################################
if ($debug) echo
"deleteing field: $field<br />";
if ($obj->sortOrder >=
$ordNr) $obj->sortOrder--
;
// #########################################
* checks if the table has changed
* @version pk-06-08-02 hide new fields by default
if ($debug) echo
"<p><b>DBMS_FORM::updateFields($debug)</b> (".
get_class($this).
") </p><blockquote>";
if (!$GLOBALS['USRDB']->isConnected) return FALSE;
$b_hide =
((sizeof($this->frmFields)>
1) ?
TRUE :
FALSE); // <pk-06-08-02> we alread have fields -> hide by default
foreach($this->frmTables as $tbl) { // <pk-06-08-09> bugfix
if ($debug) echo
"<p>checking Table: $tbl</p>";
if ($fields=
$GLOBALS['USRDB']->getDBTblDesc($tbl)) {
foreach($fields as $key =>
$a_fldDesc) {
if ($debug) echo
"<pre>$key: \n".
print_r($a_fldDesc,TRUE).
"</p>";
if (empty($this->frmFields[$tbl.
".".
$key])) {
$o_fld=
$this->addField($key,$a_fldDesc['TYPE'],$a_fldDesc,"",$tbl,$debug);
if ($b_hide) { // <pk-06-08-02>
$this->frmFields[$tbl.
".".
$key]->check($a_fldDesc);
$this->frmFields[$tbl.
".".
$key]->setFrmId($this->frmId); /* <pk-04-02-23 /> */
if ((is_object($fld) &&
$fld->isPrimaryKey()) ||
intval($a_fldDesc['PRIMARY_KEY'])) { // <pk-06-08-07 /> bugfix
if ($debug) echo
"<p>frmKeys:</p><pre>".
print_r($this->frmKeys,TRUE).
"</pre></blockquote>";
* sets myForm in each field
if ($debug) echo
"<p><b>DBMS_FORM::setFldFrmObj()</b> (".
get_class($this).
")</p>";
foreach($a_fldKeys as $s_fldKey) {
$this->frmFields[$s_fldKey]->setMyForm($this);
* returns the number of fields
// ###############################
* populates the join array $frmJoin
* first find all primary keys
* if a primary key COLNAME occures more then 1 time
* an array with field names (TABLENAME.COLNAME) as value is
* added to $frmJoin[COLNAME]
* @param boolean $debug show debug info
if ($debug) echoDebug(__FILE__
,"<p><b>DBMS_FORM::generateJoin()</b> ".
get_class($this).
"</p>",0);
$a_joinCandidates=
array(); // <pk-06-01-25 />
if (sizeof($this->frmTables) >
1) { // we have 2 or more table we need a join
if ($this->lastDBCheck+
600 <
time()) { // check if the object is sync with the database
while(list
($key,$field)=
each($this->frmFields)) { // note $key is TABLENAME.COLNAME
if ($field->dbDesc['PRIMARY_KEY']) { // its a primary key
$a_joinFlds[$field->myName][]=
$key; // add it to a COLNAME array
} else if (!empty($field->dbDesc['KEY'])) { // <pk-06-01-25>
$a_joinCandidates[$field->myName][]=
$key; // add key fields to joinCandidates
if ($debug) echo
"<pre>PK's:\n".
print_r($a_joinFlds,TRUE).
"\nKEYS:\n".
print_r($a_joinCandidates,TRUE).
"</pre>";
while(list
($key,$val)=
each($a_joinFlds)) {
if (sizeof($val) >
1) { // we found more then one COLNAME as pk in the form
} else if ($a_joinCandidates[$key]) { // we found a Primary key and a key with same colname in
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
* adds a table to the form
* @param string $aTable name of the tablename
* @param boolean $isDefaultFrm the form is default for the table
* @param boolean $debug since pk-05-02-22
function addTable($aTable,$isDefaultFrm=
FALSE,$debug=
FALSE){
if ($debug) echoDebug(__FILE__
,"<p><b>DBMS_FORM::addTable($aTable,$isDefaultFrm,...)</b> (".
get_class($this).
")</p>",0);
if (!$GLOBALS['USRDB']->isConnected) return FALSE;
// if ($this->isTblDefault && !empty($this->frmTables)) return FALSE; <pk-06-01-11 />
if (!($arr=
$GLOBALS['USRDB']->getDBTblDesc($aTable))) {
if ($debug) echoDebug(__FILE__
,"<p>Could not get DBTblDesc for $aTable</p>\n",1);
* removes a table from the form
* @param string $aTable name of the tablename
if ($debug) echo
"<p><b>DBMS_FORM::removeTable($aTable,...)</b> (".
get_class($this).
")</p>";
while(list
($key,$val)=
each($aArr)) {
* removes all fields of a Table
if ($field->getTable() ==
$aTable)
unset
($this->fileds[$key]);
* check if the form uses $aTable
if (empty($aTable)) return FALSE;
// ###############################
if (!empty($aSelectName)) {
* @param boolean $nameToIndex set the array index to the column name
* @param boolean $withoutTable don't use table names in array index (see the TABLES field in value array)
function getKeyArray($nameToIndex=
FALSE,$withoutTable=
TRUE) {
foreach($this->frmKeys as $a_key) {
$s_idx=
$a_key['TABLE'].
".".
$a_key['NAME'];
$a_ret[$s_idx]['TABLES'][]=
$a_key['TABLE'];
* returns an array with the key column names
foreach($this->frmKeys as $a_key) {
$a_ret[$a_key['NAME']]=
$a_key['NAME'];
foreach ($this->frmFields as $key =>
$fldObj) {
$retArr[$key] =
$fldObj->dbDesc;
$retArr['NAME'] =
$fldObj->myName;
* generates a sql from statement
* @param boolean $debug (since pk-06-07-31)
* @todo currently only mysql join is implemented
if ($debug) echoDebug(__FILE__
,"<p>returning stored query: <br />".
$this->frmQuery.
"</p>");
$ret=
""; // <pk-06-09-11 /> E_ALL
if ($debug) echoDebug(__FILE__
,"<p>Generating Join</p>");
foreach($this->frmJoin as $col =>
$tblLst) {
foreach($tblLst as $tblCol) {
list
($tbl,$col)=
explode(".",$tblCol);
foreach($tbls[$tbl] as $col) $keys.=
":".
$col.
":";
$ret.=
" LEFT JOIN ".
$tbl.
" USING(";
foreach($tbls[$tbl] as $col) {
if (strstr($keys,":".
$col.
":")) {
$ret.=
$sep.
$col; $sep=
",";
//$ret.="<br />keys: $keys<br />";
$ret.= $this->frmTables[0];
$ret.=" LEFT JOIN ".$this->frmTables[1];
foreach($this->frmJoin as $key => $val) {
// ###############################
* returns a pointer to a field object
* @param string $name (COLUMN) name of the field or the field key (table.name) where $table is empty
* @param string $table table name the field belongs to if empty fields are checked for name fit
* @param boolean $debug show debug info
function &getField($name,$table=
"",$debug=
FALSE) {
echo
"<hr /><p><b>DBMS_FORM::getField($name,$table,$debug)</b></p><blockquote>";
// foreach($this->frmFields as $key => $obj) {echo $key."<br />";}
// quick version if a table is specified
if ($debug) echo
"<p style=\"font-size:10px\">FOUND frmFields[\$table.\$name]</p></blockquote>";
if ($debug) echo
"<p style=\"font-size:10px\">FOUND frmFields[\$name]</p></blockquote>";
} else if (!empty($table)) {
// we do not have a field for this table
if ($debug) echo
"<p style=\"font-size:10px\">NO OBJECT frmFields[\$table.\$name]</p></blockquote>";
$o_retNull=
NULL;return $o_retNull; // <pk-06-08-01 /> E_ALL
if ($debug) echo
"<p style=\"font-size:8px\">";
foreach($this->frmFields as $key =>
&$fld) { // <pk-07-02-27 /> & ptr to fld to save memory
if ($debug) echo
"frmFields[$key] named: ".
$fld->getName().
"<br />";
if ($debug) echo
"</p><p style=\"font-size:10px\">FOUND frmFields[\$table.\$name]</p></blockquote>";
// do not return $fld here
// as it is a copy of the field (PHP Version 4.2.x)
if ($debug) echo
"</p><p style=\"font-size:10px\">NOTHING FOUND</p></blockquote>";
$o_retNull=
NULL; // <pk-06-08-01 /> E_ALL
$fld->setTable($sTbl,"",TRUE,$debug);
* returns the form field array
* @param boolean $withoutTable include table name in the key
* returns an array of pointers to the form fields
* @param boolean sorted array index is field order nr
* @returns array of &DBMS_FIELDS
$this->frmFields[$str_key]->setMyForm($this);
$int_sortKey=
(($obj_fld->getOrderNr() >
0) ?
$obj_fld->getOrderNr() :
1); // <pk-07-05-04 />
while(isset
($arr_ret[$int_sortKey]) &&
(is_object($arr_ret[$int_sortKey]))) {
$arr_ret[$int_sortKey]=
&$this->frmFields[$str_key];
$this->frmFields[$str_key]->setOrderNr($int_sortKey); // <pk-07-05-04 />
if ($sorted) ksort($arr_ret);
* returns an array of fields (for compatibility with new version (OCSP_FORM)
* @param string $aTable (empty to get all fields)
foreach($arr_fields as &$obj_field)
if (empty($aTable) ||
($obj_field->getTable()==
$aTable))
$arr_ret[$obj_field->getKey()]=
&$obj_field;
* returns an array with all auto_inc fields
if ($debug) echoDebug(__FILE__
,"<p><b>DBMS_FORM::getAutoIncFields()</b> (".
get_class($this).
")</p>",0);
if ($obj->dbDesc['AUTO_INCREMENT']) {
$a_ret[]=
$obj->dbDesc['COLNAME'];
foreach($fldLst as $key =>
$fld) {
* disables or enables a field in a FRM_MODE_NEW or FRM_MODE_EDIT
* if (mode == -1) FRM_MODE_NEW and FRM_MODE_EDIT are used
* @param boolean $enabled
* @var boolean $b_IsToChange
function en_disAbleField($enabled,$fldName,$mode=-
1,$tbl=
"",$debug=
FALSE) {
if ($debug) echo
"<p><b>DBMS_FORM::en_disAbleField(".
($enabled ?
"enable" :
"disable").
",$fldName,$tbl,$debug)</b> (".
get_class($this).
")</p>";
if ($debug) echo
"<li style=\"font-size:9px;\">FLD: $key (".
$fld->getKey().
" / ".
$fld->getName().
")";
$b_IsToChange =
($fld->getKey() ==
$tbl.
".".
$fldName);
$b_IsToChange =
($fld->getName()==
$fldName);
if ($debug) echo
" <b>FOUND</b>";
if ($debug) echo
"</li>";
* disables a field in a FRM_MODE_NEW or FRM_MODE_EDIT
* if (mode == -1) FRM_MODE_NEW and FRM_MODE_EDIT are used
function enableField($fldName,$mode=-
1,$tbl=
"",$debug=
FALSE) {
if ($debug) echo
"<p><b>DBMS_FORM::enableField($fldName,$tbl,$debug)</b> (".
get_class($this).
")</p>";
* disables a field in a FRM_MODE_NEW or FRM_MODE_EDIT
* if (mode == -1) FRM_MODE_NEW and FRM_MODE_EDIT are used
function disableField($fldName,$mode=-
1,$tbl=
"",$debug=
FALSE) {
if ($debug) echo
"<p><b>DBMS_FORM::disableField($fldName,$tbl,$debug)</b> (".
get_class($this).
")</p>";
function hideField($fldName,$tbl=
"",$debug=
FALSE) {
if ($debug) echo
"<p><b>DBMS_FORM::hideField($fldName,$tbl,$debug)</b> (".
get_class($this).
")</p>";
if ($debug) echo
"<li style=\"font-size:9px;\">FLD: $key (".
$fld->getKey().
" / ".
$fld->getName().
")";
if ($fld->getKey() ==
$tbl.
".".
$fldName) {
if ($debug) echo
" <b>FOUND</b>";
if ($debug) echo
" <b>FOUND</b>";
if ($debug) echo
"</li>";
if ($debug) echo
"<p><b>DBMS_FORM::hideField($fldName,$tbl,$debug)</b> (".
get_class($this).
")</p>";
if ($debug) echo
"<li style=\"font-size:9px;\">FLD: $key (".
$fld->getKey().
" / ".
$fld->getName().
")";
if ($fld->getKey() ==
$tbl.
".".
$fldName) {
if ($debug) echo
" <b>FOUND</b>";
if ($debug) echo
" <b>FOUND</b>";
if ($debug) echo
"</li>";
function showField($fldName,$tbl=
"",$debug=
FALSE) {
if ($debug) echo
"<p><b>DBMS_FORM::hideField($fldName,$tbl,$debug)</b> (".
get_class($this).
")</p>";
if ($debug) echo
"<li style=\"font-size:9px;\">FLD: $key (".
$fld->getKey().
" / ".
$fld->getName().
")";
if ($fld->getKey() ==
$tbl.
".".
$fldName) {
if ($debug) echo
" <b>FOUND</b>";
if ($debug) echo
" <b>FOUND</b>";
if ($debug) echo
"</li>";
* hides all fields of a table
if ($debug) echo
"<p><b>DBMS_FORM::hideAllTblFields($tbl,$debug)</b> (".
get_class($this).
")</p>";
if ($fld->getTblAlias() ==
$tbl ||
$fld->getTable() ==
$tbl) {
* returns an array with the field default values;
* @param string $table if not empty only fields of $table are returned
* @returns array an array with field name as key and default value
* pk-04-08-31: param $debug added
if ($debug) echo
"<p><b>DBMS_FORM::getDefaultValArr($table,$debug)</b> (".
get_class($this).
"/".
$this->getId().
")</p>";
if ((empty($table)) ||
($obj->myTable==
$table))
$ret[$obj->getName()]=
$obj->getDefaultValue();
if ($debug) echo
"<blockquote><p>Default Values:</p><pre style=\"font-size:75%\">".
print_r($ret,TRUE).
"</pre></blockquote>";
if (!empty($this->HTMLFORM_URL_reload)) {
$s_ret=
$this->HTMLFORM_URL_reload;
$s_ret=
$_SERVER['REQUEST_URI'];
if ($debug) echoDebug(__FILE__
,"<p style=\"padding-left: 20px\">Returns: ".
$s_ret.
"</p>");
* returns if the form is reloaded
* @param string $postArrName
if (isset
($GLOBALS['FORCERELOAD']) &&
$GLOBALS['FORCERELOAD']) return TRUE;
if (!empty($postArrName) && isset
($_POST[$postArrName]) &&
(is_array($_POST[$postArrName]))) {
if (isset
($_SERVER['HTTP_REFERER'])) {
$s_refUrl=
ereg_replace("https?://([^/]+)", "", $_SERVER['HTTP_REFERER']);
$s_aktUrl=
$_SERVER['REQUEST_URI'];
// remove the reload get param (rldFRM)
return ($s_refUrl==
$s_aktUrl);
* check if the form is relaoded
* and we have to use the posted values instead of $aktRow
* if $aktRow is not an array the form default values are used
* @param boolean $pArrName
* @version pk-05-11-17 debug infos
* @version pk-05-11-25 debug info
* @version pk-05-11-29 bugfix
* @version pk-06-10-25 bugfix regex http? -> https?
* @var string $s_frmAction
function reloadCheck($aktRow=
NULL,$debug=
FALSE,$pArrName=
"") {
if ($debug) echo
"<p><b>DBMS_FORM::reloadCheck(...)</b> (".
get_class($this).
")</p><blockquote>\n";
if ($debug) echo
"<p>\$aktRow:</p><pre>".
print_r($aktRow,TRUE).
"</pre>";
// no array -> load form default values
if ($debug) echo
"<p>Loading default values</p><blockquote><hr>"; // <pk-05-11-29 />
if ($debug) echo
"<hr></blockquote>"; // <pk-05-11-29 />
// extract URL's to compare
if (!isset
($_SERVER['HTTP_REFERER']) ||
(!($s_refUrl=
ereg_replace("https?://([^/]+)", "", $_SERVER['HTTP_REFERER'])))) { // <pk-06-10-26 /> // <pk-07-02-28 /> E_ALL
// we do not have a referer -> the form could not be reloaded
if ($debug) echo
"<p>EREG: <br />".
$_SERVER['HTTP_REFERER'].
"<br />".
$s_refUrl.
"<br />".
$_SERVER['REQUEST_URI'].
"</p></blockquote>";
$s_aktUrl=
$_SERVER['REQUEST_URI'];
$s_aktion=
(isset
($_POST['FRMACTION']) ?
$_POST['FRMACTION'] :
"");
$s_frmAction=
substr($s_aktUrl,(strlen($s_aktion)*-
1)); // remove server (http://server.domain.ttl)
// now check the post values
} else if (isset
($_POST['FRMARRAYNAME']) &&
!empty($_POST['FRMARRAYNAME'])) {
$s_arrName=
$_POST['FRMARRAYNAME'];
if ($debug) echo
"<p>no FRMARRAYNAME posted</p></blockquote>";
if ((!isset
($_POST[$s_arrName])) ||
(!is_array($_POST[$s_arrName]))) { // <pk-06-07-22 />
// we do not have a form post
if ($debug) echo
"<p>no POST array</p></blockquote>";
// we do not check form Id as forms could also change
// now check if we have the same urls
// <pk-06-10-05 > but first remove the reload get param (rldFRM)
if (substr($s_aktUrl,-
1)==
"?") $s_aktUrl=
substr($s_aktUrl,0,-
1);
if (substr($s_refUrl,-
1)==
"?") $s_refUrl=
substr($s_refUrl,0,-
1);
if ($debug) echo
"<p>Ref: $s_refUrl<br />Akt: $s_aktUrl</p>";
if (!isset
($GLOBALS['FORCERELOAD'])) $GLOBALS['FORCERELOAD']=
FALSE; // <pk-06-09-14 /> E_ALL
if (($s_refUrl ==
$s_aktUrl) ||
($GLOBALS['FORCERELOAD']) ||
($s_frmAction ==
$_POST['FRMACTION'])) {
// the url is identical (each form is submited to itself in case of reload)
$aktRow=
array_merge($aktRow,$_POST[$s_arrName]); // array_merge is used to have fields
// which are not posted but set outside
$
{$s_arrName}=
$_POST[$s_arrName];
$i_frmMode=
$_POST['FRMMODE'];
foreach($a_fldLst as $o_fld) {
if (isset
($_POST[$s_arrName][$o_fld->getName()])) {
if ($debug) echo
"<p style=\"font-size:75%\"><b>un</b>setting field: ".
$o_fld->getName().
"</p>"; // <pk-05-11-17 />
if ($debug) echo
"</blockquote>";
/* **************************************************************** */
/* **************************************************************** */
/* **************************************************************** */
* gets the html (javaScriptCode) for the formular start
* @param boolean $withJSInc @deprecated since pk-07-02-28 (allways check for includes)
* @version pk-06-11-22 usage of html_includes
* @version pk-07-02-28 use pcf_get_htmlJsInclude
function getJavaCode($mode=
FRM_MODE_READONLY,$withJSInc=
FALSE,$debug=
FALSE) {
if ($debug) echo
"<p><b>DBMS_FORM::getJavaStart($mode,$withJSInc,...)</b> (".
get_class($this).
")</p>";
$ret=
"\n<!-- _____________________ DBMS_FORM HEADER _________________ -->\n";
$s_ret.=
pcf_get_htmlJsInclude("/system/javascript/window.js.php");
$s_ret.=
pcf_get_htmlJsInclude("/system/javascript/forms.js.php");
$ret .=
"\n<script language=\"javascript\">\n";
$ret .=
" var ".
$this->frmName.
"_mode=".
$mode.
";\n\n";
$ret .=
" function ".
$this->frmName.
"_onSubmit() {\n";
$ret .=
" return true;\n";
$ret .=
" /* NO CODE AVALABLE */\n";
* writes a field and sets the fields form Id
* @param string $name index in $this->frmFields
function writeField($name,$mode,$val,$arrName=
"DBVAL",$debug=
FALSE) {
* writes a form table from a query
function writeTableFromQuery($DBOBJ,$query,$mode=
FRM_MODE_READONLY,$arrName=
"DBVAL",$debug=
FALSE) {
if (empty($query)) return FALSE;
if (!$DBVAL=
$DBOBJ->quickQuery($query)) return FALSE;
* writes a form table from a query
if ($debug) echo
"NO ARRAY ".
$this->frmName.
"<br />";
// if ($_SERVER['REMOTE_ADDR']=="10.8.8.22") $debug=TRUE;
$GLOBALS['TMP_FROMDATAARRAY_'.
$this->frmId]=
&$DBVAL; /* <pk-04-02-03 /> */
while(list
($fld,$obj)=
each($fldLst)) {
if ($debug) $obj->fldDebug=
$debug;
$obj->setDataArrName($arrName); /* <pk-04-09-08 /> */
// if ($debug){echo "<tr><td colspan=\"2\"><pre>";print_r($obj);echo "</pre></td></tr>"; }
unset
($GLOBALS['TMP_GRPFIELDS_'.
$this->frmId]);
if ($obj->writeFieldRow($mode,$DBVAL[$obj->myName],$arrName,"","","",$debug)) {
if (!empty($GLOBALS['TMP_GRPFIELDS_'.
$this->frmId])) {
$fields.=
$sep.
$GLOBALS['TMP_GRPFIELDS_'.
$this->frmId];
$fields.=
$sep.
$obj->myName;
echo
"\n<input name=\"".
$arrName.
"[_DBMS_FIELDS]\" type=\"hidden\" value=\"$fields\">\n";
* returns the form table rows
* @version pk-06-04-02 add foreign keyfields as hidden input if they do have values in $DBVAL
* @version pk-06-11-19 set the form object to the field
function getTableFromArray($DBVAL,$mode=
FRM_MODE_READONLY,$arrName=
"DBVAL",$debug=
FALSE) {
if ($debug) echo
"<p><b>DBMS_FORM::getTableFromArray(\$DBVAL,$mode,$arrName,...)</b> (".
get_class($this).
")</p>";
$DBVAL['_DBMS_FIELDS']=
""; // <pk-05-12-05 />
echo
"<p>DATA:</p><blockquote>";
foreach ($DBVAL as $key =>
$val) {
echo
"<p>\$DBVAL IS NOT AN ARRAY</p><pre style=\"font-size:75%;\">\$DBVAL:\n".
print_r($DBVAL,TRUE).
"</pre>";
$GLOBALS['TMP_FROMDATAARRAY_'.
$this->frmId]=
&$DBVAL; /* <pk-04-02-03 /> */
$a_hiddenFKFlds=
array(); // <pk-06-04-02 />
$a_hiddenFields=
array(); // <pk-06-11-15 />
foreach($fldLst as $fld =>
&$obj) { // <pk-07-02-15 ref $obj instead of new var mainly to save memory
$obj->setDataArrName($arrName);
$obj->setMyForm($this); // <pk-06-11-19 />
if ($debug) echo
"<blockquote><p>NAME: |".
$obj->getName().
"| VALUE: |".
substr($DBVAL[$obj->getName()],0,30).
"| HIDDEN: |".
$obj->isToShow($mode,$DBVAL).
"|</p>";
if ($obj->isToShow($mode,$DBVAL,$debug)) {
$ret.=
$obj->getFieldRow($mode,(isset
($DBVAL[$obj->getName()]) ?
$DBVAL[$obj->getName()] :
NULL),$debug);
if (!empty($DBVAL[$obj->myName])) $a_hiddenFKFlds[]=
$obj;
if (!empty($DBVAL[$obj->myName])) $a_hiddenFields[]=
$obj;
if ($debug) echo
"<hr /></blockquote>";
if (sizeof($a_hiddenFields)) {
foreach($a_hiddenFields as $obj) {
$ret_pre.=
"\n<!-- hidden value fields -->\n";
$ret_pre.=
"<!-- /hidden value fields -->\n\n";
foreach($a_hiddenFKFlds as $obj) {
$ret_pre.=
"\n<!-- hidden foreign keys -->\n";
$ret_pre.=
$obj->getFieldTag(FRM_MODE_HIDDEN,$DBVAL[$obj->myName],$debug).
"\n";
$ret_pre.=
"<!-- /hidden foreign keys -->\n\n";
$ret=
$ret_pre.
$ret; // have the auto added hidden fields at the beginning to avoid overwriting when the field names
// exists twice (in joins for example)
if (isset
($
{$arrName}['_DBMS_FIELDS'])) { // <pk-06-09-14 /> E_ALL
$ret.=
"\n<input name=\"".
$arrName.
"[_DBMS_FIELDS]\" type=\"hidden\" value=\"".$
{$arrName}['_DBMS_FIELDS'].
"\">\n";
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
* @version pk-05-08-08 png -> gif
if ($debug) echo
"<p><b>DBMS_FORM::setHTMLFORM_BtnSource(...)</b> (".
get_class($this).
")</p>";
'BACK' =>
$GLOBALS['PROJECT']['SYSIMGURL'].
"icons-22x22/back1.gif",
'CLOSE' =>
$GLOBALS['PROJECT']['SYSIMGURL'].
"icons-22x22/exit.gif",
'EDIT' =>
$GLOBALS['PROJECT']['SYSIMGURL'].
"icons-22x22/edit.gif",
'FIND' =>
$GLOBALS['PROJECT']['SYSIMGURL'].
"icons-22x22/filter.gif",
'SAVE' =>
$GLOBALS['PROJECT']['SYSIMGURL'].
"icons-22x22/filesave.gif",
'COPY' =>
$GLOBALS['PROJECT']['SYSIMGURL'].
"icons-22x22/filesaveas.gif",
'STOP' =>
$GLOBALS['PROJECT']['SYSIMGURL'].
"icons-22x22/stop_hand.gif",
'TRASH' =>
$GLOBALS['PROJECT']['SYSIMGURL'].
"icons-22x22/edittrash.gif",
'UNDO' =>
$GLOBALS['PROJECT']['SYSIMGURL'].
"icons-22x22/undo.gif"
* sets object HTMLFORM variables:
* @param string $frmAction
* @version pk-06-03-07 HTMLFORM_arrayName added
function setHTMLFORM_objectVar($DBVAL,$mode=
FRM_MODE_READONLY,$frmAction=
"",$nextURI=
"",$arrName=
"DBVAL",$debug=
FALSE) {
if ($debug) echo
"<p><b>DBMS_FORM::setHTMLFORM_objectVar(\$DBVAL,$mode,$frmAction,$nextURI,$arrName,...)</b> (".
get_class($this).
")</p>";
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// setting HTMLFORM object vars
$this->HTMLFORM_mode=
$mode;
$this->HTMLFORM_URL_action=
$GLOBALS['PROJECT']['SYSTEMURL'].
"forms/insert.php?".
$_SERVER['QUERY_STRING'];
$this->HTMLFORM_URL_action=
$GLOBALS['PROJECT']['SYSTEMURL'].
"forms/update.php?".
$_SERVER['QUERY_STRING'];
$this->HTMLFORM_URL_action=
$GLOBALS['PROJECT']['SYSTEMURL'].
"forms/delete.php?".
$_SERVER['QUERY_STRING'];
$this->HTMLFORM_URL_action=
$frmAction;
if (empty($_POST['FRMRELOADURL'])) {
if (empty($this->HTMLFORM_URL_reload)) { // <pk-05-07-20>
$this->HTMLFORM_URL_reload=
$_SERVER['REQUEST_URI'];
$this->HTMLFORM_URL_reload=
$_POST['FRMRELOADURL'];
if (!strstr($this->HTMLFORM_URL_reload,"?")) $this->HTMLFORM_URL_reload.=
"FRMID=".
$this->getId(); // <pk-05-07-06 />
// <pk-05-06-22> only set backurl if not set
else $this->HTMLFORM_URL_back=
(isset
($_SERVER['HTTP_REFERER']) ?
$_SERVER['HTTP_REFERER'] :
"");
if (strstr($nextURI,"/system/forms/") &&
(!empty($_POST[$this->getName().
"_NEXT"]))) { // <pk-05-10-26>
} else if (!empty($nextURI)) $this->HTMLFORM_URL_next =
$nextURI;
else if (!empty($_SERVER['HTTP_REFERER'])) $this->HTMLFORM_URL_next =
$_SERVER['HTTP_REFERER'];
else $this->HTMLFORM_URL_next =
$nextURI=
dirname($_SERVER['SCRIPT_FILENAME']).
"/index.php?".
$_SERVER['QUERY_STRING'];
* returns the html form statement
if (empty($this->HTMLFORM_URL_action)) {
switch(intval($this->HTMLFORM_mode)) {
$s_action=
$GLOBALS['PROJECT']['SYSTEMURL'].
"forms/insert.php?".
$_SERVER['QUERY_STRING'];
$s_action=
$GLOBALS['PROJECT']['SYSTEMURL'].
"forms/update.php?".
$_SERVER['QUERY_STRING'];
$s_action=
$GLOBALS['PROJECT']['SYSTEMURL'].
"forms/delete.php?".
$_SERVER['QUERY_STRING'];
$s_action=
$_SERVER['REQUEST_URI'];
$this->HTMLFORM_URL_action=
$s_action;
$s_action=
$this->HTMLFORM_URL_action;
$s_ret =
"\n<form name=\"".
$this->getHTMLName().
"\" method=\"post\" action=\"".
$s_action.
"\" ".
$this->FRMTAGADD.
" >\n";
* returns the html code for the hidden form fields
* beside the method parameters the HTMLFORM object:
* @version pk-06-09-11 FRMRELOADFLD added
if ($debug) echo
"<p><b>DBMS_FORM::getHTMLFormHiddenFields(...)</b> (".
get_class($this).
")</p>";
global $
{$arrName}; // <pk-05-09-13>
$ret =
"\n\t<!-- _______ HIDDEN COMMAND FIELDS ______ -->\n";
$ret.=
"\t\t<input type=\"hidden\" name=\"FRMMODE\" value=\"".
$this->HTMLFORM_mode.
"\">\n";
$ret.=
"\t\t<input type=\"hidden\" name=\"FRMACTION\" value=\"".
$this->HTMLFORM_URL_action.
"\">\n";
$ret.=
"\t\t<input type=\"hidden\" name=\"DBMSFORMID\" value=\"".
$this->getId().
"\">\n";
$ret.=
"\t\t<input type=\"hidden\" name=\"FRMARRAYNAME\" value=\"".
$arrName.
"\">\n";
$ret.=
"\t\t<input type=\"hidden\" name=\"FRMRELOADFLD\" value=\"\">\n"; // <pk-06-09-11 />
// infos about the table object (if not of class DBMS_TABLEOBJ)
// we only have the class
// check if can get the source
// the class source is included
@eval
("\$obj=new ".
$valClass.
"();");
// the class has the method getClassFile no check if it reaturns a value
// see DBMS_TABLEOBJ how to implement this class
} else if (!empty($_POST['DBMS_TABLEOBJ_class'])) {
// we already have post values by form reload
// ensure not to get values from a previous form here.
$valClass=
$_POST['DBMS_TABLEOBJ_class'];
$valInc =
$_POST['DBMS_TABLEOBJ_include'];
$ret.=
"\t\t<input type=\"hidden\" name=\"DBMS_TABLEOBJ_include\" value=\"".
$valInc.
"\">\n";
$ret.=
"\t\t<input type=\"hidden\" name=\"DBMS_TABLEOBJ_class\" value=\"".
$valClass.
"\">\n";
$ret.=
"\t\t<input type=\"hidden\" name=\"FRMQUERYSTRING\" value=\"";
if (empty($_POST['FRMQUERYSTRING'])) $ret.=
$_SERVER['QUERY_STRING'].
"\">\n";
else $ret.=
$_POST['FRMQUERYSTRING'].
"\">\n";
$ret.=
"\t\t<input type=\"hidden\" name=\"FRMSCRIPTFILENAMECRYPT\" value=\"";
if (empty($_POST['FRMSCRIPTFILENAMECRYPT'])) $ret.=
pcfmd5_encrypt($_SERVER['SCRIPT_FILENAME']).
"\">\n";
else $ret.=
$_POST['FRMSCRIPTFILENAMECRYPT'].
"\">\n";
$ret.=
"\t\t<input type=\"hidden\" name=\"FRMRELOADURL\" value=\"".
$this->HTMLFORM_URL_reload.
"\">\n";
$ret.=
"\t\t<input type=\"hidden\" name=\"".
$this->getName().
"_NEXT\" value=\"".
base64_encode($this->HTMLFORM_URL_next).
"\">\n";
if (empty($_POST[$this->getName().
'_FRMKEYS'])) {
if (is_array($a_keys)) { // <pk-06-08-08 >
foreach($a_keys as $a_keyData) {
$a_keyData['VALUE']=$
{$arrName}[$a_keyData['NAME']];
$a_postKeys[]=
$a_keyData;
if ($debug) echo
"<pre>".
print_r($a_postKeys,TRUE).
"</pre>";
$ret.=
"\t\t<input type=\"hidden\" name=\"".
$this->getName().
"_FRMKEYS\" value=\"".
$_POST[$this->getName().
'_FRMKEYS'].
"\">\n";
$ret.=
"\t<!-- _______ END HIDDEN COMMAND FIELDS ______ -->\n\n";
* returns the html code for the form buttons row (colspan=2)
* beside the method parameters the HTMLFORM object:
* - FRMADDBUTTONS html code to add in the button line
* button images are derived from $this->HTMLFORM_button_src[] array
* if userCanEdit editbutton is added
* link is $this::FRMEDITURL or $this::HTMLFORM_URL_reload?FRMCMD=EDIT
* if userCanDelete delete button is added
* only if not emtpy $this::FRMDELETEURL
* @version pk-06-02-13 class=\"button\" added to img-tages
* @version pk-06-09-11 remove _DBMS_FIELDS from MD5DELVALKEY
if ($debug) echo
"<p><b>DBMS_FORM::getHTMLFormButtons(...)</b> (".
get_class($this).
")</p>";
$ret =
"\n\t<!-- _______ BUTTONS ______ -->\n\n";
$ret.=
"\t<tr><td class=\"frmButtons\" colspan=\"2\">\n";
$ret.=
"<div style=\"padding:0px;margin:0px;display:inline;float:right;\">";
$ret.=
"<a href=\"".
$GLOBALS['PROJECT']['ADMINURL'].
"dbms/editframe.php?FRM_ID=".
$this->getId().
"\" target=\"_blank\" title=\"Formular bearbeiten\">";
$ret.=
"<img src=\"".
$GLOBALS['PROJECT']['SYSIMGURL'].
"/icons-22x22/editConstruct.gif\" border=\"0\" alt=\"Formular bearbeiten\" class=\"button\"></a>\n";
if (!empty($_GET['OPENERURL'])) {
// we are in a popup add close button
$ret.=
"\t\t<a href=\"#\" onClick=\"javascript:{top.close();}\">";
$ret.=
"<img src=\"".
$this->HTMLFORM_button_src['CLOSE'].
"\" alt=\"schliessen\" border=\"0\" class=\"button\">";
$ret.=
"\t\t<a href=\"$this->HTMLFORM_URL_back\">";
$ret.=
"<img src=\"".
$this->HTMLFORM_button_src['BACK'].
"\" class=\"button\" alt=\"abbrechen\" border=\"0\" class=\"button\">";
$ret.=
"\t\t<input type=\"hidden\" name=\"SEARCH\">\n";
$ret.=
"\t\t<a href=\"#\" onClick=\"document.forms['".
$this->getHTMLName().
"'].SEARCH.value='".
$this->getName().
"';document.forms['".
$this->getHTMLName().
"'].submit()\">";
$ret.=
"<img src=\"".
$this->HTMLFORM_button_src['FIND'].
"\" class=\"button\" alt=\"filtern\" border=\"0\" class=\"button\">";
if ($debug) echo
"\n<h2 style=\"color: red;font-weight:bold\">ERROR</h2><p>global var \$".
$arrName.
" is not an array</p>\n";
foreach($DBVAL as $key =>
$val) {
$ret.=
"\t\t\t<input type=\"hidden\" name=\"".
$arrName.
"[".
$key.
"]\" value=\"".
htmlspecialchars($val).
"\">\n";
$ret.=
"\t\t<a href=\"#\" onClick=\"javascript:{history.back()}\">";
$ret.=
"<img src=\"".
$this->HTMLFORM_button_src['BACK'].
"\" class=\"button\" alt=\"abbrechen\" border=\"0\">";
unset
($a_dbVal['_DBMS_FIELDS']);
$ret.=
"\t\t<a href=\"#\" onClick=\"document.forms['".
$this->getHTMLName().
"'].submit()\">";
$ret.=
"<img src=\"".
$this->HTMLFORM_button_src['TRASH'].
"\" class=\"button\" alt=\"l�chen\" border=\"0\">";
$ret.=
"\t\t<a href=\"#\" onClick=\"javascript:{history.back()}\">";
$ret.=
"<img src=\"".
$this->HTMLFORM_button_src['BACK'].
"\" class=\"button\" alt=\"abbrechen\" border=\"0\">";
$ret.=
"\t\t<a href=\"#\" onClick=\"document.forms['".
$this->getHTMLName().
"'].submit()\" title=\"speichern\">";
$ret.=
"<img src=\"".
$this->HTMLFORM_button_src['SAVE'].
"\" class=\"button\" alt=\"speichern\" border=\"0\">";
$ret.=
"\t\t<a href=\"#\" onClick=\"document.forms['".
$this->getHTMLName().
"'].submit()\" title=\"Kopie speichern\">";
$ret.=
"<img src=\"".
$this->HTMLFORM_button_src['COPY'].
"\" class=\"button\" alt=\"speichern\" border=\"0\">";
// we assume here that if the user is allowed to edit the form data he will also be allowed to delete the row
// this can be done here because normale $this->FRMDELETEURL should lead to a page were the user is asked
// if he realy wants to delete the data and here you should also check if he is allowed to
$ret.=
"<img src=\"".
$this->HTMLFORM_button_src['TRASH'].
"\" class=\"button\" alt=\"löschen\" border=\"0\">";
$ret.=
"\t\t<a href=\"#\" onClick=\"{document.forms['".
$this->getHTMLName().
"'].reset();}\">";
$ret.=
"<img src=\"".
$this->HTMLFORM_button_src['UNDO'].
"\" class=\"button\" alt=\"reset\" border=\"0\" class=\"button\">";
$s_editUrl=
$this->HTMLFORM_URL_reload;
if (!strstr($s_editUrl,"&FRMCMD=EDIT")) $s_editUrl.=
"&FRMCMD=EDIT";
$ret.=
"\t\t<a href=\"#\" onClick=\"document.location.href='".
$s_editUrl.
"';\">";
$ret.=
"<img src=\"".
$this->HTMLFORM_button_src['EDIT'].
"\" class=\"button\" alt=\"reset\" border=\"0\" class=\"button\">";
$ret.=
"<img src=\"".
$this->HTMLFORM_button_src['TRASH'].
"\" class=\"button\" alt=\"löschen\" border=\"0\" class=\"button\">";
$ret.=
"\n\t<!-- _______ END BUTTONS ______ -->\n\n";
* returns the html code for the complete form
* you can set them to change layout or enlarge functionality
* - FRMTAGADD (<form ..... FRMTAGADD>)
* - FRMTBLTAG (<table .... FRMTBLTAG>)
* - FRMTBLHEADERROW (1st row in the table example: <tr><td colspan="2">.....</td></tr>);
* - FRMDELETEURL (<a href=\"$this->FRMDELETEURL\">...)
* - FRMADDBUTTONS (html code to add in the button line)
* - FRMNOBUTTONS do not add buttons in read only mode
* @param string $frmAction
* @version pk-05-02-08 if $frmAction != "" don't append $_SERVER['QUERY_STRING']
* @version pk-06-02-06 call of getHTMLFormStatement()
* @version pk-07-02-28 pcf_get_htmlJsInclude
* @todo BUG DBMSFORMID sometimes DBMSFORMID is 0 workaround with $_POST is done now
function getHTMLFormFromArray($DBVAL,$mode=
FRM_MODE_READONLY,$frmAction=
"",$nextURI=
"",$arrName=
"DBVAL",$debug=
FALSE) {
if ($debug) echoDebugMethod(__FILE__
,get_class($this),"DBMS_FORM::getTableFromArray(\$DBVAL,$mode,$frmAction,$nextURI,$arrName,...)");
if (empty($nextURI)) $nextURI=
$_SERVER['SCRIPT_NAME'];
$s_ret=
"\n\n<!-- ____________________FORMULAR START___________________________ -->\n\n";
// $s_ret.=pcf_get_htmlJsInclude($GLOBALS['PROJECT']['JAVASCRIPTURL']."forms.js.php"); // <pk-07-02-28 />
$s_ret.=
"<table ".
(isset
($this->FRMTBLTAG) ?
$this->FRMTBLTAG :
"").
">\n"; // <pk-06-08-09 /> E_ALL
if (isset
($this->FRMTBLHEADERROW) &&
(!empty($this->FRMTBLHEADERROW))) { // <pk-06-08-09 /> E_ALL
$s_ret.=
$this->FRMTBLHEADERROW;
$s_ret.=
"\t<tr><td class=\"frmErrorLabel\">Fehler</td><td class=\"frmErrorText\">".
$this->getErrors("<br />").
"</td></tr>\n";
$s_ret.=
"\n\t<!-- ____________________ FORM DATA ____________________ -->\n";
$s_ret.=
"\t<!-- ____________________ END FORM DATA ____________________ -->\n\n";
$s_ret.=
"\n\n<!-- __________________FORMULAR ".
$this->getName().
" END_________________________ -->\n\n";
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* returns an array with links to use in a tab
* NOTE templates are not parsed
foreach($a_fields as &$o_fld) {
if (isset
($o_fld->lstLink['ASTAB']) &&
$o_fld->lstLink['ASTAB'] &&
$o_fld->isToShow($mode,$debug)) {
$a_ret[$o_fld->getName()]=
$o_fld->lstLink;
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* checks if all required (NOT NULL FIELDS) are set
* @param array $postArr Array with values
* @param string $table Name of the table if empty all tabels are checked
* @param string $arrName Name of the global data array (${$arrName})
* @param boolean $debug show debug information
* @returns boolean TRUE if all fields are set else FALSE
* @version pk-03-12-13 getValue instead of slashedValue
* @version pk-04-08-03 use $obj->allow NULL
function checkForNVL($postArr,$table=
"",$arrName=
"DBVAL",$debug=
FALSE) {
echoDebug(__FILE__
,"<pre style=\"background-color:#C0C0C0;border: solid 1px blue;\">".
print_r($postArr,TRUE).
"</pre>");
$fldLst=
$this->getFieldArr(TRUE); // to have the error messages in same order as fields
foreach($fldLst as $key =>
$obj) {
if (!$obj->isHidden &&
!$obj->allowNull &&
((empty($table)) ||
($obj->myTable ==
$table) ||
($obj->myTableAlias ==
$table))) {
if ($debug) echoDebug(__FILE__
,"<blockquote style=\"font-size: 80%\"><p>Testing: ".
$obj->myName.
" Value: ".
htmlspecialchars($postArr[$obj->myName]).
"</p>");
if ($obj->getValue($postArr[$obj->myName],$this->errors,$arrName,$debug) ===
FALSE) {
if ($debug) echoDebug(__FILE__
,"<p style='color:red;font-weight:bolder;'> error in field: ".
$obj->myName.
"</p>");
if ($debug) echoDebug(__FILE__
,"</blockquote>\n");
if ($debug) echoDebug(__FILE__
,"<p style=\"font-size: 120%;\">DBMS_FORM::checkForNVL() returns: ".
($ret ?
"TREU" :
"FALSE ").
"</p><hr />");
* generates a sql update statement key = value pares
* NOTE $cmd call by reference!!
* as this only APPENDS key=value pares to seperated with a ","
* to the command you have to take care for a valid sql statement
* ATTANTION: the , is only set between key=value
* $cmd="UPDATE mytable SET myNotPostedField=1,";
* // append http posted fields
* if (!$frmObj->getUpdateValues($DBVAL,$cmd,"mytable","DBVAL") {
* $cmd .= " WHERE myKey=1";
* $DBOBJ->executeCmd($cmd)
* @param array $postArr array with key=>value
* @param string &$cmd IN-OUT first part of the sql statement includeing key word SET
* @param string $table use only this table if set
* @param string $arrName name of the global key=>value (${$arrName})
* @param boolean $debug show debug option
function getUpdateValues($postArr,&$cmd,$table=
"",$arrName=
"DBVAL",$debug=
FALSE) {
if ($debug) echo
"<hr /><p><b>DBMS_FORM::getUpdateValues($postArr,$cmd,$table,$arrName,$debug)</b></p><blockquote>";
if (isset
($postArr['_DBMS_FIELDS'])) {
$fieldLst=
explode(",",$postArr['_DBMS_FIELDS']);
$ERR=
"DBMS_FORM_NO_POST_ARRAY";
include $PROJECT['PHPINCPATH'].
"io/errors.phpinc";
while(list
($key,$val) =
each($postArr)) {
if ($debug) echo
"checking Field: ".
$obj->myName.
": ";
if ($debug) echo
" FOUND ";
if ((empty($table)) ||
($obj->myTable ==
$table) ||
($obj->myTableAlias ==
$table)) {
if ($debug) echo
"\n<br />";
return ($this->errors['ERROR'] ?
FALSE :
TRUE);
* returns an array with values checked against the form
* sets the form errors in case of array but always returns the array
* check the form for errors with this::hasErrors() before proceeding
* @param array $postArr array with key=>value
* @param string $table use only this table if set
* @param string $arrName name of the global key=>value (${$arrName})
* @param boolean $debug show debug option
* @version pk-05-02-22 don't check hidden fields (leads to errors in joins)
* @version pk-05-12-05 debuging
* @version pk-05-12-29 handling hidden auto_inc fields
* @version pk-06-01-13 auto_inc fields are always NULL in FRM_MODE_NEW and FRM_MODE_COPY
* @version pk-06-02-16 handling of sortorder fields (DBMS_FIELD_ORDERNR)
function getValueArray($postArr,$table=
"",$arrName=
"DBVAL",$debug=
FALSE) {
echoDebug(__FILE__
,"<p><b>DBMS_FORM::getValueArray(\$postArr,$table,$arrName,$debug)</b> (".
get_class($this).
"/".
$this->frmName.
")</p>",0);
'LABEL'=>
'FORMULAR: '.
$this->frmName,
'MSG' =>
'keine Daten bermittelt'
if (isset
($postArr['_DBMS_FIELDS'])) {
$fieldLst=
explode(",",$postArr['_DBMS_FIELDS']);
foreach($postArr as $key =>
$val) {
$fieldLst[$key]=
$key; // to avoid multiple entries for fields with more then one input
echoDebug(__FILE__
,"<blockquote style=\"color:red\"><p>Checking for fields: ".
implode(",",$fieldLst).
"</p>",0);
// do not check empty AUTO_INCREMENT fields as the will be set if the data is stored
// if they are set we have to check them they could be of an other table
if (!$obj->isHidden()) { /* <pk-05-02-22> */
if ((empty($table)) ||
(trim($obj->getTable()) ==
trim($table)) ||
(trim($obj->getTblAlias()) ==
trim($table)))
$s_value=
(isset
($postArr[$obj->getName()]) ?
$postArr[$obj->getName()] :
NULL);
if ($this->hasErrors()) echoDebug(__FILE__
,"<p style=\"background-color:red\">FORM HAS ERRORS --- FORM HAS ERRORS</p>",0);
if ($debug) echoDebug(__FILE__
," but in ".
$obj->myTable.
" and not in ".
$table,0); // <pk-05-12-05 />
} else { // <pk-06-08-18 />
if ($debug) echoDebug(__FILE__
," FOUND BUT HIDDEN",0);
// we have a hidden auto_inc field is the value set?
// handling of hidden disabled sortfields
if (!$obj->dbDesc['NULL']) {
// not null column -> get a value to avoid errors
if ((empty($table)) ||
(trim($obj->getTable()) ==
trim($table)) ||
(trim($obj->getTblAlias()) ==
trim($table)))
if (isset
($postArr[$obj->getName()]) &&
intval($postArr[$obj->getName()])) { // <pk-07-01-16 /> E_ALL
// we have a value set somewhere else use it
$retArr[$obj->getName()]=
$obj->getValue($postArr[$obj->getName()],$s_tmp,$arrName,$debug); // use $s_tmp to avoid form errors
$retArr[$obj->getName()]=
1; // set to 1 in case of no new value could be found by the field
} else if (isset
($postArr[$obj->getName()]) &&
(!empty($postArr[$obj->getName()]))) { // <pk-06-08-18 />
// check fields which are posted with values and not hidden but not in $fieldLst
// this happens when one field turns on or off another during getValue
// so you are able to add fields from another one you only have to look the the field changes the other
if ($debug) echoDebug(__FILE__
," FOUND IN POSTARRAY ",0);
if ((empty($table)) ||
(trim($obj->myTable) ==
trim($table)) ||
(trim($obj->myTableAlias) ==
trim($table))) {
if ($debug) echoDebug(__FILE__
," AND HAS VALUES for the table",0);
$retArr[$obj->getName()]=
$obj->getValue($postArr[$obj->getName()],$s_tmp,$arrName,$debug); // use $s_tmp to avoid form errors
* returns an 2 dimensional array of all form data [table][col]
* @param array $postArr array with key=>value
* @param boolean $debug show debug option
echo
"<hr><p><b>DBMS_FORM::getTableValueArrays(\$postArr,$arrName,$debug)</b> (".
get_class($this).
"/".
$this->frmName.
")</p>";
'LABEL'=>
'FORMULAR: '.
$this->frmName,
'MSG' =>
'keine Daten bermittelt'
if (isset
($postArr['_DBMS_FIELDS'])) {
$fieldLst=
explode(",","::DUMMY::,".
$postArr['_DBMS_FIELDS']);
$fieldLst=
array(0=>
"::DUMMY::");
foreach($postArr as $key =>
$val) {
$fieldLst[$key]=
$key; // to avoid multiple entries for fields with more then one input
$s_arrName=
"GTVA_DBVAL".
time();
echo
"<p>Checking for fields: ".
implode(",",$fieldLst).
"</p>";
if ($debug) {echo
"<p>checking Field: <b>".
$obj->myName.
"</b>: (".
get_class($obj).
") \n";flush();}
// do not check empty AUTO_INCREMENT fields as the will be set if the data is stored
// if they are set we have to check them they could be of an other table if the form consists of more than one
$retArr[$obj->myTable][$obj->myName]=
NULL;
} else if (($obj->isToShow($this->getFrmMode(),$postArr)) &&
(intval($a_fldLst[$obj->myName]))) { // in_array($obj->myName,$fieldLst))) {
if ($debug) echo
" FOUND ";
$retArr[$obj->myTable][$obj->myName]=
$obj->getValue($postArr[$obj->myName],$this->errors,$s_arrName,FALSE); // no debug can be set in the field
if ($this->hasErrors()) echo
"<p style=\"background-color:red\">FORM HAS ERRORS --- FORM HAS ERRORS";
// we have a hidden auto_inc field is the value set?
if (intval($postArr[$obj->myName])) {
$retArr[$obj->myTable][$obj->myName]=
intval($postArr[$obj->myName]);
unset
($a_fldLst[$obj->myName]);
if ($debug) {echo
"\n</p>";flush();}
if ($debug) echo
"<p>NOT PROCESSED Fields:</p><pre>".
print_r($a_fldLst,TRUE).
"</pre>";
if ($debug) echo
"<p>DBMS_FORM::getTableValueArrays() Returns:</p><pre>".
htmlspecialchars(print_r($retArr,TRUE)).
"</pre></blockquote>";
* appends the values set in postArr to $cmd to use in SQL Where
* $cmd .= [AND] DBMS_FIELD::getAssignment()
function getWhereValues($postArr,&$cmd,$table=
"",$arrName=
"DBVAL",$debug=
FALSE) {
if ($debug) { echo
"<pre> getWhereValues($postArr,$cmd,$table,$arrName):\n\n";print_r($postArr);echo
"</pre>";}
if ($debug) echo
"checking Field: ".
$val['NAME'].
": ";
if (isset
($postArr[$val['NAME']])) {
if ($debug) echo
" FOUND ";
if ((empty($table)) ||
($val['TABLE'] ==
$table) ||
($val['TABLE'] ==
$table)) {
$obj=
&$this->frmFields[$val['TABLE'].
".".
$val['NAME']];
$this->errors[$val['NAME']]=
"KEY_NOT_SET";
if ($debug) echo
"\n<br />";
* returns a query string for the row in $rowArr
if ($debug) echo
"<p><b>DBMS_FORM::getRowQueryString(\$dataArr (".
sizeof($dataArr).
" Elements),$table..)</b> (".
get_class($this).
")</p>";
if (empty($table) ||
($key['TABLE']==
$table)) {
$ret .=
$sep.
$key['NAME'].
"=".
$dataArr[$key['NAME']];
* generates a string with the column names to use in an insert statement
* appends a comma seperated list to $cmd
* @see DBMS_FORM::getInsertValues for code example
* @param array $postArr array of fields posted by the form
* @param string &$cmd the return string
* @param string $table name of the table if set only oolumns of $table are added
* @returns boolean DBMS_FORM::hasErrors()
if ($debug) echo
"<hr><p><b>DBMS_FORM::getInsertCols($postArr,$cmd,$table,$debug)</b> (".
get_class($this).
" | ".
$this->frmName.
")</p><blockquote>";
if (isset
($postArr['_DBMS_FIELDS'])) {
$fieldLst=
explode(",",$postArr['_DBMS_FIELDS']);
$ERR=
"DBMS_FORM_NO_POST_ARRAY";
include $PROJECT['PHPINCPATH'].
"io/errors.phpinc";
while(list
($key,$val) =
each($postArr)) {
if ($debug) echo
"checking Field: ".
$obj->myName.
": ";
if ($debug) echo
" FOUND ";
if ((!$obj->isAutoInc()) &&
((empty($table)) ||
($obj->myTable ==
$table) ||
($obj->myTableAlias ==
$table))) {
if ($debug) echo
"<pre>".
print_r($obj->dbDesc,TRUE).
"</pre>";
$cmd .=
$sep.
$obj->myName;
if ($debug) echo
"\n<br />";
if ($debug) echo
"</blockquote>";
* generates a string with comma seperated slashed
* field values to use in an insert statement together
* with DMBS_FORM::getInsertCols()
* $frmObj->clearErrors();
* $query="INSERT INTO T_CMS_MENU (";
* if (!($frmObj->getInsertCols($DBVAL,$query))) break;
* if (!($frmObj->getInsertValues($DBVAL,$query))) break;
* @param array $postArr array of fields posted by the form
* @param string &$cmd the return string
* @param string $table name of the table if set only oolumns of $table are added
* @return boolean DBMS_FORM::hasErrors()
function getInsertValues($postArr,&$cmd,$table=
"",$arrName=
"DBVAL",$debug=
FALSE) {
if ($debug) echo
"<hr><p><b>DBMS_FORM::getInsertCols($postArr,$cmd,$table,$debug)</b> (".
get_class($this).
" | ".
$this->frmName.
")</p><blockquote>";
if (isset
($postArr['_DBMS_FIELDS'])) {
$fieldLst=
explode(",",$postArr['_DBMS_FIELDS']);
$ERR=
"DBMS_FORM_NO_POST_ARRAY";
include $PROJECT['PHPINCPATH'].
"io/errors.phpinc";
while(list
($key,$val) =
each($postArr)) {
if ($debug) echo
"<p>checking Field: ".
$obj->myName.
": </p><blockquote>";
if ($debug) echo
" FOUND ";
if ((empty($table)) ||
($obj->myTable ==
$table) ||
($obj->myTableAlias ==
$table)) {
if ($debug) echo
"\n</blockquote>";
if ($debug) {echo
"<pre>ERRORS:\n";print_r($this->errors);echo
"</pre></blockquote>";}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* @param boolean $withLabel
echo
"<p style=\"background-color:red;\">";
if ($wihtLabel) echo
$err['LABEL'].
": ";
* returns the error in a string
* @param boolean $withoutLabel
function getErrors($sep=
"\n",$debug=
FALSE,$withoutLabel=
TRUE) {
foreach($this->errors as $fld =>
$arr) {
if ($debug) echo
"<blockquote>$fld:<pre>".
print_r($arr,TRUE).
"</pre></blockquote>";
$ret.=
$arr['LABEL'].
": ".
$arr['MSG'].
$sep;
* adds an error to this::errors
* @param array $aError with LABEL und MSG values
else $this->errors[$fld]['MSG']=
$aError;
if (isset
($this->errors['ERROR']))
return ($this->errors['ERROR']);
* returns the error array
if (!is_array($errArr)) return FALSE; // no array -> do nothing
// ##########################################################################################
// ##########################################################################################
// ##########################################################################################
// ##########################################################################################
* returns the number of cols the list table has
while(list
($key,$val)=
each($fields)) {
if ((!$val->isHidden) &&
($val->showInList)) {
if ($val->lstColSpan >
1) $cols =
$cols+
$val->lstColSpan;
* returns the link url for a row
* $link is array with keys:
* - URL template of the url
* - CHECKFLDS array of rows => values which have to fit to link
if (debug) echoDebug(__FILE__
,"<p><b>DBMS_FORM::p_getListRowLink(...)</b> (".
get_class($this).
")</p>",1);
if ($debug) {echo
"<pre>";print_r($row);echo
"\n\n";print_r($val['CHECKFLDS']);echo
"</pre>";}
foreach($link['CHECKFLDS'] as $checkKey =>
$checkVal) {
if ($row[$checkKey]!=
$checkVal) {
$linkParams=
"ROWNR=".
$rowNr;
if ($fObj->dbDesc['PRIMARY_KEY']) {
$linkParams.=
"&".
$fObj->myName.
"=".
$row[$fObj->myName];
if (stristr($link['URL'],"javascript")) {
* echos a html table row <tr> ... </tr> for a row
* NOTE: sets the global $FORMS_LISTROW
* only use this global var in function called within
* this function it is used in field objects
* to access values of other fields with global ${$arrName}
* link array creates a <a ></a> HTML code with
* the folowing attributes (if array links[attrib] ! empty)
* - ATAGADD additional tags added as is
* - URL used in p_getListRowLink {@link DBMS_FORM::p_getListRowLink}
* - CHECKFLDS used in p_getListRowLink {@link DBMS_FORM::p_getListRowLink}
* - IMG a button img (tag or only source) both are handeled
* if (stristr($val['IMG'],"src=")) {
* echo "<img ".$val['IMG'].">"; // new style by gaisi
* echo "<img src=\"".$val['IMG']."\" alt=\"".$val['TEXT']."\" border=\"0\">";
* - TEXT text to show if no IMG or alt of the image
* if $links['EDIT'] isset each data colum is link to the url
* @param array $row array of row falues wiht col names as index
* @param int $rowNr Counter for the row (added to links)
* @param array $links array of link arrays to add in the button
* @param array $fields $this->getFieldArr(TRUE) to not call the function for every row
* @param string $trTag HTML-Code to append in <tr ...> tag
* @param array $tdDesc array with tag options in <td ...> tag
* @param boolean $debug show debug info
* @globals array $FORMS_LISTROW is set at the beginning and unset at the end
* @version pk-05-07-05 $this->lstShowRowNr
* @version pk-05-07-08 $val->lstTDAdd added
* @deprecated since pk-07-01-10
function writeListRow($row,$rowNr,$links,$fields=
NULL,$trTag=
"",$tdDesc=
"",$debug=
FALSE) {
if (!isset
($tdDesc[$val->myName]['COLTAG'])) $tdDesc[$val->myName]['COLTAG']=
"";
require_once $GLOBALS['PHPINCPATH'].
"common/pcf_templates.phpinc";
if ((!empty($links['EDIT']['URL'])) ||
(!empty($links['EDIT']['URLTMPL']))) {
if (!empty($links['EDIT']['URLTMPL'])) {
$colLink_start=
"<a href=\"".
$alink.
"\"";
if (!empty($links['EDIT']['TARGET'])) $colLink_start.=
" target=\"".
$links['EDIT']['TARGET'].
"\"";
if (!empty($links['EDIT']['ACLASS'])) $colLink_start.=
" class=\"".
$links['EDIT']['ACLASS'].
"\"";
if (!empty($links['EDIT']['ASTYLE'])) $colLink_start.=
" style=\"".
$links['EDIT']['ASTYLE'].
"\"";
if (!empty($links['EDIT']['ATAGADD']))
$colLink_start.=
" ".
pcf_tmpl_parse($links['EDIT']['ATAGADD'],$row,$debug); // <pk-04-09-02 />
if ($this->lstShowRowNr) echo
"<td align=\"right\">".
($rowNr+
1).
"</td>\n"; // <pk-05-07-05 />
while(list
($key,$val)=
each($fields)) {
//echo "\t<td>".$row[$val->myName]."</td>\n";
echo
"\t<td ".
$tdDesc[$val->myName]['COLTAG'];
if ($val->lstColSpan >
1) echo
" colspan=\"".
$val->lstColSpan.
"\" ";
echo
">".
$tdDesc[$val->myName]['PREPAND'];
$fldLinkStart=
$val->getListLink($row[$val->myName],"FORMS_LISTROW");
if ($fldLinkStart==
"[EDIT]") { // <pk-06-10-20>
$fldLinkEnd =
$colLink_end;
} else if (!empty($fldLinkStart)) {
if (stristr($fldLinkStart,"<a") &&
!(stristr($fldLinkStart,"</a>"))) {
echo
$tdDesc[$val->myName]['APPAND'].
"</td>\n";
if ($debug) {echo
"<!--\n";print_r($links);echo
"\n-->\n";}
while(list
($key,$val)=
each($links)) {
if (!empty($val['WIDTH'])) echo
" width=\"".
$val['WIDTH'].
"\"";
if (!empty($val['CLASS'])) echo
" class=\"".
$val['CLASS'].
"\"";
if (!empty($val['STYLE'])) echo
" style=\"".
$val['STYLE'].
"\"";
if (!empty($val['URLTMPL'])) {
echo
"><a href=\"".
$alink.
"\"";
if (!empty($val['TARGET'])) echo
" target=\"".
$val['TARGET'].
"\"";
if (!empty($val['ACLASS'])) echo
" class=\"".
$val['ACLASS'].
"\"";
if (!empty($val['ASTYLE'])) echo
" style=\"".
$val['ASTYLE'].
"\"";
if (!empty($val['ATAGADD'])) echo
" ".
pcf_tmpl_parse($val['ATAGADD'],$row,$debug);
if ($debug) {echo
"<!--\n";print_r($val);echo
"\n-->\n";}
if (!empty($val['IMG'])) {
echo
"<img ".
$val['IMG'].
">"; // new style by gaisi
echo
"<img src=\"".
$val['IMG'].
"\" alt=\"".
$val['TEXT'].
"\" border=\"0\">";
* returns an object value for a row
* @param DBMS_FIELD $fldObj
if ($debug) echo
"<p><b>DBMS_FORM::getRowObjValue(...)</b> (".
get_class($this).
")</p>\n";
$s_table=
str_replace("OBJVALS_","",$fldObj->getTable());
while(empty($s_keyFld) &&
(list
($i_idx,$a_keyData)=
each($this->frmKeys))) {
if ($a_keyData['TABLE']==
$s_table) {
$s_keyFld=
$a_keyData['NAME'];
$s_query=
"SELECT OV_VALUE FROM ".
$s_table.
"_OV WHERE ".
$s_keyFld.
"=".
$OCSP_OBJ['USRDB']->qs_getSlashedValue($row[$s_keyFld]);
$s_query.=
" AND OV_NAME=".
$OCSP_OBJ['USRDB']->qs_getSlashedValue($fldObj->getName());
if ($debug) echo
"<p>Query: $s_query</p>";
if ($s_ret=
$OCSP_OBJ['USRDB']->quickQuery($s_query,0)) {
if ($debug) echo
"<p>FOUND</p>";
if ($debug) echo
"<p>NOT FOUND</p>";
* returns the htmlCode for a list row
* - FRMLST_TRADD (<tr $this->FRMLST_TRADD[($rowNr % 2)] >)
* - FRMLST_TDADD (<td $this->FRMLST_TDADD >)
* - FRMLST_TDFLDADD (<td $this->FRMLST_TDADD $this->FRMLST_TDFLDADD[FLDNAME] >)
* links array creates links at the end of the row
* $links[colname|linkname]
* -[A] => link templdate parsed with $row
* -[TEXT] => the html code for the link button
* -[SHOWQUERY] => if str_replace(";","%","SELECT ".pcf_tmpl_parse($lArr['SHOWQUERY'],$row)) is TRUE the link is show otherwise not
* -[GROUPID] => overrules [SHOWQUERY]
* if $links['EDIT'] isset each data colum is link to the url
* if the link key == fldname the link is added to the field
* @version pk-05-04-13 anchor added
* @version pk-05-07-05 $this->lstShowRowNr
* @version pk-05-10-06 object values added
* @version pk-05-11-15 button cols width 20 added
* @version pk-06-03-02 [GROUPID] added
* @version pk-06-09-08 $rowNr call by reference
* @version pk-06-10-20 linking of the column
* @todo check edit link && check column links
function getListRow($row,&$rowNr,$links=
NULL,$debug=
FALSE) {
echo
"<p><b>DBMS_FORM::getListRow(...)</b> (".
get_class($this).
")</p><blockquote>";
echo
"<p style=\"font-weight: 75%\">VALUES:</p><pre style=\"font-weight: 75%\">".
print_r($row,TRUE).
"</pre>";
if ($debug) echo
"<p>ERROR \$row is not an array</p></blockquote>";
if (!is_array($links)) $links=
array(); // to avoid errors
$arrName =
$this->getName().
"_FRMLSTROW";
if (!empty($links['EDIT']['A'])) $editLink=
"<a ".
pcf_tmpl_parse($links['EDIT']['A'],$row).
" >";
if ($this->lstShowRowNr) $s_ret.=
"\t\t<td ".
$this->FRMLST_TDADD.
" align=\"right\">".
($rowNr+
1).
"</td>\n"; // <pk-05-07-05 />
$anchorSet=
FALSE;$anchor=
""; /* <pk-05-04-13 /> */
foreach($fields as $key =>
&$fldObj) {
$fldObj->setDataArrName($arrName); // <pk-06-08-18 /> use method instead of direct object access
$arr_fldDesc=
$fldObj->getdbDesc();
$arr_fldLink=
$fldObj->getListLinkArr();
if (isset
($arr_fldDesc['AUTO_INCREMENT']) &&
($arr_fldDesc['AUTO_INCREMENT']) && isset
($row[$fldObj->getName()])) { // <pk-05-04-13 /> <pk-06-07-24 /><pk-07-01-10 /> E_ALL
$anchor=
"<a name=\"".
$fldObj->getName().
"_".
$row[$fldObj->getName()].
"\"></a>";
if ($fldObj->isToShow(FRM_MODE_LIST,NULL,$debug)) { // <pk-07-01-10 />
if ((intval($fldObj->getLstColSpan()))) { // <pk-06-09-12>
$s_ret.=
"\t\t<!-- ____________".
$fldObj->getName().
"__________ -->\n";
if ($fldObj->getLstColSpan() >
1) $s_ret.=
" colspan=\"".
$fldObj->getLstColSpan().
"\" ";
$s_ret.=
" ".
pcf_tmpl_parse($fldObj->get_lstTDAdd(),$row); // <pk-05-07-08 />
if ((!$anchorSet) &&
(!empty($anchor))) { /* <pk-05-04-13 /> */
$b_linked=
FALSE; // <pk-06-11-07 />
if (isset
($links[$fldObj->getName()]['A']) &&
!empty($links[$fldObj->getName()]['A'])) {
// link set from outside alway rules hope developers know what they are doing
} else if (isset
($row[$fldObj->getName()])) { // <pk-07-02-08 /> E_ALL
if ($s_fldLnk==
"[EDIT]") {
// use the edit link if is set
if (!empty($links['EDIT']['A'])) {
} else if (!empty($s_fldLnk)) {
$b_linked=
((!stristr($s_fldLnk,"</a>")) ?
TRUE :
FALSE);
if (!empty($arr_fldLink['TEXT'])) {
$links[$fldObj->getName()]=
$arr_fldLink;
if (!isset
($row[$fldObj->getName()])) {
if (substr($fldObj->getTable(),0,8)==
"OBJVALS_") {
if ($b_linked) $s_ret.=
"</a>";
} else if (!empty($arr_fldLink['TEXT'])) {
$links[$fldObj->getName()]=
$arr_fldLink; // <pk-06-09-12 /> to ensure it is in the button list
echo
"showInList: ".
$fldObj->showInList().
"\n";
if ($debug) echo
"</pre>";
foreach($links as $name =>
$lArr) {
$s_ret.=
"\n\t\t<!-- ____ LINKS________ -->\n";
if (!empty($lArr['TEXT'])) {
$s_ret.=
"\t\t<td ".
$this->FRMLST_TDADD.
" width=\"20\" align=\"center\">"; // <pk-05-11-15 />
if (!empty($lArr['SHOWQUERY'])) { // <pk-05-11-07>
$b_showLink=
(intval($GLOBALS['USRDB']->quickQuery($s_showQuery,0)) ?
TRUE :
FALSE);
if (isset
($lArr['GROUPID']) &&
(intval($lArr['GROUPID']))) { // <pk-06-03-02>
if ($b_showLink &&
(isset
($lArr['A']))) { // <pk-06-07-28 /> E_ALL
$s_ret.=
"\n\t\t<!-- ____ END LINKS ___ -->\n";
if ($debug) echo
"</blockquote>";
* returns the SQL-Fieldlist for Lists
* @version pk-05-02-22 add primary keys
* @version pk-06-05-15 bugfix; debugging
if ($debug) echo
"<p><b>DBMS_FORM::getList_SQLFieldLst()</b> (".
get_class($this).
")</p>";
foreach($fields as &$fldObj) {
$arr_dbDesc=
$fldObj->getdbDesc();
if ($debug) echo
"<pre>".
print_r($fldObj->dbDesc,TRUE).
"</pre>";
if ((!$fldObj->isHidden()) &&
($fldObj->showInList())) {
if ($cName=
$fldObj->getDBColName()) {
} else if ($arr_dbDesc['PRIMARY_KEY']) { /* <pk-05-02-22 >*/
if ($debug) echo
"<p>checking PRIMARY_KEY: ".
$fldObj->getName().
"</p>";
if (!strstr($ret,".".
$fldObj->getName())) { // <pk-06-05-15 bugfix />
if ($cName=
$fldObj->getDBColName()) {
if (empty($ret)) return "*";
* echos the list header Row
* class = "lstHeader" is added to <a> html tag
* $this->FRMLST_THADD is added to <th>
* @param int $noCols number of columns
* @param array $links Linkicons to count colspan of the last row
* @param string $sortLink links the col title
* @version pk-05-04-15 $fldObj->lstLink added
* @version pk-05-07-05 $this->lstShowRowNr
* @version pk-05-11-07 links SHOWQUERY added
* @version pk-05-11-30 add ? or & to $sortLnk
* @version pk-06-01-19 lstLabel added in fields
* @version pk-06-02-23 check dbDesc['COLNAME'] in sortLink
* @version pk-06-09-12 use $fldObj->lstColSpan
* @version pk-07-01-10 use $fldObj->isToShow() instead of direct access
* @todo check query for SHOWQUERY
if ($debug) echo
"<p><b>DBMS_FORM::getListHeaderRow(...)</b> (".
get_class($this).
")</p><blockquote>";
if ((substr($sortLnk,-
1) !=
"?") &&
(substr($sortLnk,-
1) !=
"&")) {
if (!strstr($sortLnk,"?")) $sortLnk.=
"?"; else $sortLnk.=
"&";
foreach($fields as $fldObj) {
if ($fldObj->isToShow(FRM_MODE_LIST,NULL,$debug)) { // pk-07-01-10 />
if (intval($fldObj->getLstColSpan())) {// <pk-06-09-12 />
$arr_fldDesc=
$fldObj->getdbDesc();
if ((!empty($sortLnk)) &&
(!empty($arr_fldDesc['COLNAME']))) { // <pk-06-02-23>
$ret.=
"<a class=\"lstHeader\" href=\"".
$sortLnk.
"SORTCOL=".
$arr_fldDesc['COLNAME'].
"\">";
$ret.=
$fldObj->getLstLabel(); // <pk-06-01-19 />
if ((!empty($sortLnk)) &&
(!empty($arr_fldDesc['COLNAME']))) {
$noCols+=
intval($fldObj->getLstColSpan()); // <pk-06-09-12 />
if ($fldObj->getListLinkArr()) {
if (!isset
($links[$fldObj->getName()])) {
$links[$fldObj->getName()]=
$fldObj->getListLinkArr();
} else if ($fldObj->getListLinkArr()) {
if (!isset
($links[$fldObj->getName()])) {
$links[$fldObj->getName()]=
$fldObj->getListLinkArr();
$ret.=
"<a href=\"".
$GLOBALS['PROJECT']['ADMINURL'].
"dbms/editframe.php?FRM_ID=".
$this->getId().
"\" target=\"_blank\" title=\"Formular bearbeiten\">";
$ret.=
"<img src=\"".
$GLOBALS['PROJECT']['SYSIMGURL'].
"/icons-22x22/editConstruct.gif\" border=\"0\" alt=\"Formular bearbeiten\" class=\"button\"></a>\n";
$ret.=
"</th>\n"; //<pk-05-11-15 /> <pk-06-05-17 />
$noCols=
$noCols+
sizeof($links);
if ($debug) echo
"</blockquote>";
* returns an array with key=column name and value = label of the form
// @var DBMS_FIELD $o_fld
if ($debug) echo
"<p><b>DBMS_FORM::getListColLabelArr()</b></p>";
foreach($a_fields as $o_fld) {
if ((!$o_fld->isHidden) &&
($o_fld->showInList)) {
$a_ret[$o_fld->getName()]=
$o_fld->label;
* returns the html code for list from a database cursor object
* $cursor->fetchArrayFld() is called to get the row
* NOTE: use getList_SQLFieldLst() in the select statement if
* you have a LEFT JOIN to get the right fields and
* - FRMLST_TABLEADD (<table $this$this->FRMLST_TABLEADD>)
* - FRMLST_TRADD (<tr $this->FRMLST_TRADD[($rowNr % 2)] >)
* - FRMLST_TDADD (<td $this->FRMLST_TDADD >)
* @param DBCURSOR $cursor
if ($debug) echo
"<p><b>DBMS_FORM::getHTMLLstFromCursor(...)</b> (".
get_class($this).
")</p><blockquote>";
if ($debug) echo
"<p>\$cursor IS NO OBJECT</p></blockquote>";
$ret=
"\n<!-- ______ LISTTable ".
$this->getName().
" ________________ -->";
while ($row=
$cursor->fetchArrayFld()) {
$ret.=
$this->getListRow($row,$nofRows,$links,$debug);
$ret.=
"\n<!-- ______ END LISTTable ".
$this->getName().
" ____________ -->";
if ($debug) echo
"</blockquote><p>END getHTMLLstFromCursor(...)</p>";
* returns the html code for list from a query
* if $query is empty it is generated with:
* $query="SELECT ".$this->getList_SQLFieldLst().$this->getFromStmt();
* NOTE: use getList_SQLFieldLst() in the select statement if
* you have a LEFT JOIN to get the right fields and
* - FRMLST_TABLEADD (<table $this->FRMLST_TABLEADD>)
* - FRMLST_TRADD (<tr $this->FRMLST_TRADD[($rowNr % 2)] >)
* - FRMLST_TDADD (<td $this->FRMLST_TDADD >)
* @param int $nofRows return the number of rows processed
* @param string $query if empty the query is generated
* @global array $OCSP_OBJ
* @todo only mysqlcode for limit
function getHTMLLstFromQuery(&$nofRows,$query=
"",$links=
NULL,$sortLnk=
NULL,$limit=
0,$offset=
0,$debug=
FALSE) {
if ($debug) echo
"<p><b>DBMS_FORM::getHTMLLstFromQuery(...)</b> (".
get_class($this).
")</p><blockquote>";
$query.=
" LIMIT ".
intval($offset).
",".
$limit;
if ($debug) echo
"<p>Query: $query</p>";
if ($cursor=
$OCSP_OBJ['USRDB']->query($query)) {
$ret=
$this->getHTMLLstFromCursor($cursor,$nofRows,$links,$sortLnk,$debug); // <pk-06-01-24 /> bugfix sortLink
if ($debug) echo
"<p>ERROR could not query </p>";
if ($debug) echo
"</blockquote>";
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* returns the csv header line (column names)
* @param char $fldSep field seperator
* @param char $txtSep string seperator
* @param boolean $allFields check exportCSV is set in the field
function getCSVHeadLine($row=
NULL,$fldSep=
';',$txtSep=
'"',$allFields=
FALSE,$debug=
FALSE) {
foreach($fields as $s_key =>
&$fldObj) {
if (isset
($row[$fldObj->getName()])) {
$s_ret.=
$txtSep.
$fldObj->getName().
$txtSep;
* @param char $fldSep field seperator
* @param char $txtSep string seperator
* @param boolean $allFields check exportCSV is set in the field
function getCSVLine($row,$fldSep=
';',$txtSep=
'"',$allFields=
FALSE,$debug=
FALSE) {
$arrName =
$this->getName().
"_CSVLSTROW";
foreach($fields as $s_key =>
&$fldObj) {
if (isset
($row[$fldObj->getName()])) {
// ################################
while(list
($key,$fld)=
each($fields)) {
if (!$fld->isHidden &&
$fld->isSearchable) {
echo
"\n<tr ".
$trTag.
">";
* generates a where statement for search
* @param boolean $alwaysRetWhere if true return WHERE 1=1 if no values found
* @version pk-06-01-25 $alwaysRetWhere added
* @version pk-07-01-09 skip filds with no db
if ($debug) echoDebug(__FILE__
,"<p><b>DBMS_FORM::getSearchWhere(...)</b> (".
get_class($this).
"</p>",0);
if ($debug) echo
"<blockquote>";
foreach($a_fields as $s_key =>
&$o_fld) {
if (isset
($postArr[$o_fld->getName()]['VALUE']) &&
(!$o_fld->isHidden()) &&
($o_fld->isSearchable()) &&
($o_fld->getTable() !=
DBMS_NO_DBFIELD)) {
if ($debug) echo
"<p>Checking Field: <b>".
$o_fld->getName().
"</b> Value: ".
$postArr[$o_fld->getName()]['VALUE'].
"</p>";
if (!empty($postArr[$o_fld->getName()]['VALUE']) ||
($postArr[$o_fld->getName()]['VALUE']===
"0")) { // <pk-06-02-13 /> do not ignore "0" as value
if ($debug) echo
"<blockquote>";
$s_where.=
" ".
$o_fld->searchWhere($postArr[$o_fld->myName],$debug);
if ($debug) echo
"</blockquote>";
if ($debug) echo
"</blockquote>";
if ((!$alwaysRetWhere) &&
($s_where==
"WHERE 1=1")) return NULL; // <pk-06-01-24>
* exports the form to an xml file
* @param boolean $echoXML
function xmlExport($xmlfile=
"",$base64=
TRUE,$debug=
FALSE,$echoXML=
TRUE) {
if ($debug) echo
"<hr /><p><b>DBMS_FORM::xmlExport($xmlfile,$debug)</b></p><blockquote>";
if (empty($xmlfile)) $xmlfile=
$GLOBALS['PROJECT']['DBEXPORT'].
$this->frmName.
".xml";
$domObj =
new domDocument();
$domObj->appendChild($domObj->createElement("DBMSFORMLST"));
$frmRoot =
$domObj->createElement("DBMSFORM");
$domObj->documentElement->appendChild($frmRoot);
$valRoot =
$domObj->createElement("FRM_VALUES");
$frmRoot->appendChild($valRoot);
$domElem=
$domObj->createElement($var,utf8_encode($val));
$valRoot->appendChild($domElem);
$arrRoot=
$domObj->createElement("FRM_TABLE_LST");
$frmRoot->appendChild($arrRoot);
$domElem =
$domObj->createElement("FRM_TABLE",utf8_encode($tbl));
$arrRoot->appendChild($domElem);
unset
($objArrs['frmTables']);
$arrRoot=
$domObj->createElement("DBMS_FLD_LST");
$frmRoot->appendChild($arrRoot);
$fldRoot =
$domObj->createElement("DBMS_FLD");
$arrRoot->appendChild($fldRoot);
$fldRoot->appendChild($domObj->createElement("FLD_IDXKEY",utf8_encode($key)));
unset
($objArrs['frmFields']);
$arrRoot=
$domObj->createElement("FRM_KEY_LST");
$frmRoot->appendChild($arrRoot);
$keyElem =
$domObj->createElement("FRM_KEY");
$arrRoot->appendChild($keyElem);
$keyElem->appendChild($domObj->createElement("TABLE",utf8_encode($key['TABLE'])));
$keyElem->appendChild($domObj->createElement("NAME",utf8_encode($key['NAME'])));
unset
($objArrs['frmKeys']);
$serValRoot=
$frmRoot->appendChild($domObj->createElement("FRM_SERVALUES"));
foreach($objArrs as $key) {
$serValRoot->appendChild($domObj->createElement($key,utf8_encode($val)));
foreach($objObjs as $key) {
if ($debug) echo
"</blockquote>";
header("Content-Type: text/xml");
* exports the form to an xml file
* @param DomElement $frmNode
if ($debug) echo
"<pre>".
$frmNode->nodeName.
": ".
$frmNode->childNodes->length.
"</pre>";
foreach($frmNode->childNodes as $node) {
if ($debug) echo
"<pre>".
$node->nodeName.
": ".
$node->childNodes->length.
"</pre>";
switch($node->nodeName) {
foreach($node->childNodes as $valNode) {
if ($debug) echo
"<blockquote><p><b>".
$valNode->nodeName.
"</b> ".
utf8_decode($valNode->nodeValue).
"</p>";
$this->{$valNode->nodeName}=
utf8_decode($valNode->nodeValue);
if ($debug) echo
"</blockquote>";
foreach($node->childNodes as $valNode) {
if ($debug) echo
"<blockquote><p><b>".
$valNode->nodeName.
"</b> ".
utf8_decode($valNode->nodeValue).
"</p>";
if ($debug) echo
"</blockquote>";
foreach($node->childNodes as $tblNode) {
if ($tblNode->nodeName ==
"FRM_TABLE") {
foreach($node->childNodes as $tblNode) {
if ($tblNode->nodeName ==
"FRM_KEY") {
foreach($tblNode->childNodes as $valNode) {
$kArr[$valNode->nodeName]=
utf8_decode($valNode->nodeValue);
foreach($node->childNodes as $fldNode) {
//echo "<p>DBMS_FLD NODE: ".$fldNode->nodeName."<br /><pre>".$fldNode->nodeValue."</pre></p>";
if ($fldNode->nodeName ==
"DBMS_FLD") {
if ($debug) echo
"<p>DBMS_FLD NODE: ".
$fldNode->nodeName.
"<br /><pre>".
$fldNode->nodeValue.
"</pre></p>";
foreach($fldNode->childNodes as $valNode) {
// we have no dtd yet -> $fldNode->getElementsByTagName() won't work
if ($debug) echo
"<pre>\t".
$valNode->nodeName.
":\n\t\t".
$valNode->nodeValue.
"</pre>";
switch($valNode->nodeName) {
if ($debug) echo
"<pre>\t".
$valNode->nodeName.
"</pre>";
if (!empty($nArr['FLD_CLASS']) &&
!empty($nArr['FLD_IDXKEY'])) {
$cmd =
"\$this->frmFields['".
$nArr['FLD_IDXKEY'].
"']= new ".
$nArr['FLD_CLASS'];
$cmd.=
"(".
str_replace(".",",",$nArr['FLD_IDXKEY']).
",array());";
echo
"<p>NODE: ".
$fldNode->nodeName.
"</p>";
echo
"<pre>";print_r($nArr);echo
"</pre>";
echo
"<p>UNKNOWN NODE: ".
$fldNode->nodeName.
"</p>";
echo
"<p>NODE: ".
$node->nodeName.
"</p>";
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
* creates an AJAX_FORM for the form
* @param AJAX_FORM $aAjaxFrmObj
Documentation generated on Thu, 08 Jan 2009 17:43:36 +0100 by phpDocumentor 1.4.0a2