Source for file OCSP_FORM_BLOCK.phpclass
Documentation is available at OCSP_FORM_BLOCK.phpclass
* Class file OCSP_FORM_BLOCK.phpclass
* @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 __OCSP_PHPINCPATH__.
"common".
_OCSP_DIRSEP_.
"OCSP_OBJ.phpclass";
define('__OCSP_FRMBLK_VIEWINLINE__',0);
define('__OCSP_FRMBLK_VIEWTAB__',1);
define('__OCSP_FRMBLK_VIEWFIELDSET__',2);
define('__OCSP_FRMBLK_VIEWTABLE__',3);
* @project Open CSP-Management
* @author Peter Krebs (pk) <pitlinz@users.sourceforge.net>
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
/*** class constants --------------------------------------------- */
* @constant string CLASS_SRC_FILE
* @var boolean $fieldsLoaded
* @var array $myDBColumns
protected $myBlockDBColumns=
array('FRB_ID','FRM_ID','FRB_VIEWTYPE','FRB_ORIG_FRB_ID','FRB_ORIG_FRM_ID','FRB_SORTORDER','FRB_PARENT',
'FRB_SHOW_RO','FRB_SHOW_NEW','FRB_SHOW_EDIT','FRB_SHOW_DELETE','FRB_SHOW_LIST','FRB_SHOW_COPY','FRB_GROUP_SHOW','FRB_GROUP_NEW','FRB_GROUP_EDIT',
'FRB_CLASS','FRB_CLASSSRC','FRB_TABLES','FRB_LINKCOLS','FRB_NAME','FRB_OBJVALS',
'FRB_SHOW_FRMBUTTONS','FRB_CSS_CLASS','FRB_CSS_STYLE','FRB_DESC','FRB_EXTCONF');
// ------------------------------------
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* @param OCSP_FORM $aForm
* generates a new block form from a database row
* @param OCSP_FORM $aForm
* @return OCSP_FORM_BLOCK
* @todo OCSP_FORM_BLOCK::getBlockObjFromRow() load class if not loaded
if (isset
($row['FRB_CLASS']) &&
($row['FRB_CLASS'] !=
"OCSP_FORM_BLOCK"))
ocsp_logError(__FILE__
,__LINE__
,$row['FRB_CLASS'].
" does not exist");
$str_cmd=
"\$obj_ret=new ".
$row['FRB_CLASS'].
"(\$aForm);";
foreach($row as $str_col =>
$mix_val)
$obj_ret->setMyDBColValue($str_col,$mix_val);
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if (!isset
($this->FRB_VIEWTYPE) ||
intval($this->FRB_VIEWTYPE) <
1) return True;
if (isset
($this->FRB_VIEWTYPE)) return intval($this->FRB_VIEWTYPE);
if (isset
($this->FRB_SHOW_FRMBUTTONS) &&
intval($this->FRB_SHOW_FRMBUTTONS)) return True;
* @param OCSP_FORM $aForm
$this->FRM_ID=
$aForm->getId();
} else if (isset
($this->FRM_ID)) {
// database values ----------------------------------
if (isset
($this->FRB_ID))
* sets the block id to the object and the fields
* @param unknown_type $aId
if (isset
($this->FRB_NAME) &&
!empty($this->FRB_NAME))
* returns $this->FRB_NAME if intval($this->getId()
if (isset
($this->FRB_SORTORDER))
return intval($this->FRB_SORTORDER);
$this->FRB_SORTORDER=
$ordNr;
* returns an array with the show fields
if (isset
($this->{$col})) return $this->{$col};
return $this->FRB_CSS_CLASS;
return $this->FRB_CSS_STYLE;
* returns the extJS configuration options for the block
return $this->FRB_EXTCONF;
* returns if the block is linked from another form
if (isset
($this->FRB_ORIG_FRB_ID) &&
intval($this->FRB_ORIG_FRB_ID) &&
intval($this->FRB_ORIG_FRM_ID))
return intval($this->FRB_ORIG_FRM_ID);
return intval($this->FRB_ORIG_FRB_ID);
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* returns the db object from the form
* loads the block form the database
if ($arr_Data=
$this->getDBObj()->getArray("T_DBMS_FORMBLOCKS",array('FRM_ID' =>
intval($this->myForm->getId())),0,1,NULL,$debug))
* stores the block to the database
if (isset
($this->{$str_colName}))
$arr_dbRow[$str_colName]=
$this->{$str_colName};
$arr_dbRow[$str_colName]=
NULL;
if (empty($arr_dbRow['FRB_TABLES']))
$arr_dbRow['FRB_TABLES']=
"__NO-DBFIELD__";
$str_tbl=
$obj_field->getTable();
if (!empty($str_tbl) &&
(empty($arr_dbRow['FRB_TABLES']) ||
!strstr($arr_dbRow['FRB_TABLES'],$str_tbl)))
$arr_dbRow['FRB_TABLES'].=
" ".
$str_tbl;
if ($debug) echoDebugLine(__FILE__
,__LINE__
,"updating existing block");
if ($debug) echoDebugLine(__FILE__
,__LINE__
,"inserting new block");
unset
($arr_dbRow['FRB_ID']);
{ // to also have db default values loaded
foreach($arr_Data as $str_col =>
$mix_val)
$this->{$str_col}=
$mix_val;
ocsp_logError(__FILE__
,__LINE__
,"error reloading inserted formblock ID:".
$aId);
echoDebugLine(__FILE__
,__LINE__
,"\$this->getName() returned DEFAULT");
* writes the field data to T_DBMS_FORMFIELDS
* @param DBMS_FIELD $aFld
* @param foreceLinked (if false linked block fields are not stored. this should only be tree if a block is linked to hide existing fields)
function storeFldToDb($aFld,$debug=
False,$forceLinked=
False)
if ($debug) echoDebugLine(__FILE__
,__LINE__
,"Link Block no need to store fields to db");
if ($aFld->isMarkedDeleted())
'FRB_ID' =>
$this->getId(),
'FLD_KEY' =>
$aFld->getKey(),
'FLD_TABLE' =>
$aFld->getTable(),
'FRB_ID' =>
$this->getId(),
'FLD_KEY' =>
$aFld->getKey(),
'FLD_TABLE' =>
$aFld->getTable(),
'FRM_MODULE' =>
$aFld->getModuleKey(),
'FLD_IS_HIDDEN' =>
intval($aFld->isHidden()),
'FLD_SHOW_IN_LIST' =>
intval($aFld->showInList()),
'FLD_CLASS_SRC' =>
$aFld->getSourceFile(),
'FLD_LABEL' =>
$aFld->getLabel() // <pk-05-10-04 />
if ($debug) echoDebugLine(__FILE__
,__LINE__
,"<p style=\"font-size: 75%;padding-left:20px;\">FRM_ID: ".
$a_fldRow['FRM_ID'].
" FRB_ID: ".
$a_fldRow['FRB_ID'].
" FLD_KEY: ".
$a_fldRow['FLD_KEY'].
"</p>");
* sets the database row to the object
foreach($dbRow as $str_col =>
$str_val)
$this->{$str_col}=
$str_val;
* updates a block form $_POST[$arrName] values
if(!isset
($_POST[$arrName]) ||
(!is_array($_POST[$arrName]))) return False;
$this->getMyForm(); // ensure $this->myForm isset
$this->getDBObj(); // ensure $this->myDBObj isset
$this->getFields(-
1); // ensure all fields are loaded
$arr_Data=
$_POST[$arrName];
unset
($arr_Data['FRB_ID']); // avoid overwriting
$b_reloadForm=
False; // if true the whole form is reloaded after the updates have been made
$arr_Data['FRB_NAME']=
trim($arr_Data['FRB_NAME']);
if (isset
($arr_Data['FRB_NAME']) &&
!empty($arr_Data['FRB_NAME']) &&
($arr_Data['FRB_NAME'] !=
$this->getName()))
$this->getDBObj(); // ensure $this->myDBObj isset
$str_query =
"SELECT COUNT(*) FROM T_DBMS_FORMBLOCKS ";
$str_query.=
" WHERE FRM_ID=".
$this->getId();
$str_query.=
" AND UPPER(FRB_NAME)=".
$this->myDBObj->qs_getSlashedValue(strtoupper(trim($arr_Data['FRB_NAME'])));
$str_query.=
" AND FRB_ID <> ".
$this->getId();
ocsp_logError(__FILE__
,__LINE__
,"Name: ".
$arr_Data['FRB_NAME'].
" already in use",E_NOTICE);
$this->setName($arr_Data['FRB_NAME']);
if (isset
($arr_Data['FRB_SORTORDER']) &&
intval($arr_Data['FRB_SORTORDER']) &&
($this->getOrderNr() !=
intval($arr_Data['FRB_SORTORDER'])))
$str_cmd =
"UPDATE T_DBMS_FORMBLOCKS SET FRB_SORTORDER=FRB_SORTORDER+1 ";
$str_cmd.=
" WHERE FRM_ID=".
$this->getFrmId();
$str_cmd.=
" AND FRB_SORTORDER >= ".
intval($arr_Data['FRB_SORTORDER']);
$this->myDBObj->executeCmd($str_cmd);
$str_cmd =
"UPDATE T_DBMS_FORMBLOCKS SET FRB_SORTORDER=".
intval($arr_Data['FRB_SORTORDER']);
$str_cmd.=
" WHERE FRM_ID=".
$this->getFrmId();
$str_cmd.=
" AND FRB_ID=".
$this->getId();
$this->myDBObj->executeCmd($str_cmd);
foreach($arr_showCols as $col =>
$lab)
if (isset
($arr_Data[$col]))
if (!empty($arr_Data[$col]))
foreach($arr_Data as $col =>
$val)
foreach($colNames as $str_colName)
if ($debug) echo
"<p style=\"background-color: red\">$str_colName --".
substr($str_colName,0,2).
"--</p>";
if (substr($str_colName,0,2) !=
"-:")
ocsp_logError(__FILE__
,__LINE__
,"Field: ".
$str_colName.
" not found");
$this->storeToDb($debug);
$this->myForm->delCacheFiles();
$this->myForm->loadBlocksFromDb();
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* returns the form export string (php array)
$str_ret .=
"\t\t\t\t'_FIELDS' => array(\n";
$str_tabs =
"\t\t\t\t\t";
foreach($arr_fields as $obj_field)
if ($arr_fldData =
$obj_field->getObjectVars())
$str_ret .=
$str_tabs .
"'{$obj_field->getKey()}' =>
array(\n
";
$str_ret .=
$str_tabs .
"\t'class' => \"" .
get_class($obj_field) .
"\",\n";
foreach($arr_fldData as $str_valName =>
$mix_val)
$str_ret .=
$str_tabs.
"), // field {$obj_field->getKey()}\n
";
$str_ret .=
"\t\t\t\t) // _FIELDS\n";
$str_ret .=
"\t\t\t),// blockValues {$this->getId()}\n
";
* imports the form from an array
* NOTE: does not save the form
if (isset
($impArray['FRB_ID'])) unset
($impArray['FRB_ID']);
if (isset
($impArray['FRM_ID'])) unset
($impArray['FRM_ID']);
if (isset
($impArray[$str_colName]) &&
!empty($impArray[$str_colName]))
if (isset
($impArray['_FIELDS']) &&
is_array($impArray['_FIELDS']))
$arr_tables =
$this->myForm->getTables();
if ($debug) echoDebugLine(__FILE__
,__LINE__
,"importing " .
sizeof($impArray['_FIELDS']) .
" fields");
foreach($impArray['_FIELDS'] as $arr_fld)
$obj_fld =
new $arr_fld['class']();
unset
($arr_fld['class']);
unset
($arr_fld['classSrcFile']);
$arr_fldValues =
array();
foreach($arr_fld as $str_colName =>
$mix_value)
$obj_fld->setObjectVars($arr_fldValues);
if ($str_table =
$obj_fld->getTable())
if (substr($str_table,-
3) !=
"_OV")
$arr_tables[] =
$str_table;
$this->myForm->registerTable($str_table);
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// form block cache methods
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if (isset
($this->{$str_col})) {
$arr_dbRow[$str_col]=
$this->{$str_col};
fwrite($hFile,"'block".
$this->getId().
"'=>array($str_eol");
fwrite($hFile,"'fields'=>array($str_eol");
foreach ($arr_fields as &$obj_fld)
fwrite($hFile,"'".
$obj_fld->getKey().
"'=>unserialize(base64_decode(\"".
base64_encode(serialize($obj_fld->getObjectData($debug))).
"\")),$str_eol");
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* add all columns in a table to the block
* @param boolean $asHidden if true the columns are added as hidden fields
* requires OCSP_FORM_DBCONTROLL.phpclass
function addTable($aTable,$asHidden=
True,$debug=
False)
$this->getDBObj(); // ensure we have a valid db connection
if (!($arr_tblDesc=
$this->myDBObj->getDBTblDesc($aTable)))
ocsp_logError(__FILE__
,__LINE__
,'Error no tabledesc found for $aTable');
if (!($o_frmDBControll=
$this->myForm->getMyDBControll()))
$this->getFields(-
1); // ensure this my fields is loaded
foreach($arr_tblDesc as $str_colName =>
$arr_colDesc)
$this->myFields[$i_ordNr]=
$o_frmDBControll->generateField($arr_colDesc,$debug);
* loads the fields form the database
$dbObj=
$this->myForm->getDBObj(); // ensure we have a database connection
$arr_filter=
array('FRM_ID'=>
intval($this->FRB_ORIG_FRM_ID),'FRB_ID' =>
intval($this->FRB_ORIG_FRB_ID));
$arr_filter=
array('FRM_ID'=>
$this->getFrmId(),'FRB_ID' =>
$this->getId());
if ($arr_fields=
$dbObj->getArray('T_DBMS_FORMFIELDS',$arr_filter,0,0,'FLD_SORTORDER',False))
foreach($arr_fields as $arr_row)
// try to find the source file in the system
$arr_objData['OBJVAL']['classSrcFile']
foreach($arr_sources as $str_file)
if (!$b_loaded && isset
($arr_objData['OBJDESC']['SRCFILE']) &&
!empty($arr_objData['OBJDESC']['SRCFILE']))
$str_src=
pcf_tmpl_parse($arr_objData['OBJDESC']['SRCFILE'],$arr_objData['OBJVAL']);
ocsp_logError(__FILE__
,__LINE__
,"fieldclass ".
$arr_row['FLD_CLASS'].
" not loaded<br />row:<p>".
print_r($arr_row,True).
"</p>objData:<p>".
print_r($arr_objData,True).
"</p>");
eval
("\$this->myFields['".
$i_sort.
"']=new ".
$arr_row['FLD_CLASS'].
"();");
//echoDebugLine(__FILE__,__LINE__,"Object values:<pre>".print_r(unserialize(base64_decode($arr_row['FLD_B64OBJECT'])),True)."</pre>");
$this->myFields[$i_sort]->setObjectVars($arr_objData['OBJVAL']);
$this->myFields[$i_sort]->setMyBlock($this);
ocsp_logError(__FILE__
,__LINE__
,"fieldclass ".
$arr_row['FLD_CLASS'].
" not loaded <pre>" .
print_r($arr_row,True) .
"</pre>");
* returns the number of fields in the form
* @param int $mode (-1 all modes)
* @return array of DBMS_FIELDS
if (!$objFld->isHidden('list'))
if (!$objFld->isHidden('form'))
if (!$objFld->isHidden('search'))
* @param string $aFldName
* @param string $aTable (empty to search in all tables)
* @version pk-08-11-06 object values added to table (_OV)
function &getField($aFldName,$aTable=
"",$aFldKey=
"",$debug=
False)
if (!strstr($aFldKey,'.')) // no table field seperator ignore it
if (!empty($aFldKey) &&
($obj_fld->getKey() ==
$aFldKey)) // <pk-08-07-31>
} else if ((!empty($aTable) &&
($obj_fld->getTable() ==
$aTable)) ||
(empty($aTable))) {
if ($obj_fld->getName()==
$aFldName)
} else if ((!empty($aTable) &&
($obj_fld->getTable() ==
$aTable .
"_OV"))) { // <pk-08-11-06>
if ($obj_fld->getName()==
$aFldName)
* adds a field to $this->myFields and removes it from the original block
* @param DBMS_FIELD $aField
if ($obj_other =
$aField->getMyBlock())
$aField->setMyBlock($this,$debug);
$str_debug.=
$obj_fld->getKey().
", ";
echoDebugLine(__FILE__
,__LINE__
,"Fields: <p>".
$str_debug.
"</p>");
* removes the field from the block not from the database
* @param DBMS_FIELD $aField
foreach($this->myFields as $i_idx =>
&$obj_fld)
if ($obj_fld->getKey() !=
$aField->getKey())
if ($debug) echoDebugLine(__FILE__
,__LINE__
,$aField->getKey().
" removed from block ".
$this->getId());
* creates a new field and add it to the block
function &addNewField($colName,$colType,$table=
"__NO-DBFIELD__",$size=
0,$debug=
False)
require_once dirname(__FILE__
).
"/OCSP_FORM_DBCONTROLL.phpclass";
if ($arr_dbDesc=
$obj_dbControll->generateColDesc($str_dbColName,$colType,$table,$size,$debug))
if ($obj_field=
$obj_dbControll->generateField($arr_dbDesc,$debug))
if (substr($table,-
3) ==
"_OV")
$obj_field->setTblAlias('OBJVALS_' .
substr($table,0,-
3));
$obj_field->setLabel($colName);
$obj_field->setMyBlock($this);
* moves a field in the block
* @param mixed $field (DBMS_FIELD or field name)
* @param int $movedir (-1 = up,0=position,1=down)
function moveField(&$field,$movedir=
0,$newPos=
0,$debug=
False)
$obj_block=
$obj_field->getMyBlock();
} else if (!empty($field)) {
if (!($obj_field=
$this->getField($arr_fldName[1],$arr_fldName[0],$debug)))
ocsp_logError(__FILE__
,__LINE__
,"field {$arr_fldName[1]} table {$arr_fldName[0]} not found",E_WARNING);
} else if (!($obj_field=
$this->getField($field))) {
ocsp_logError(__FILE__
,__LINE__
,"field $field not found",E_WARNING);
ocsp_logError(__FILE__
,__LINE__
,"param \$field is empty",E_WARNING);
if ($debug) echoDebugLine(__FILE__
,__LINE__
,"new position: $i_newPos");
foreach($arr_fields as &$obj_blockFld)
if ($i_idx <
0 ) // first loop
if ($i_newPos <
$i_idx) $i_newPos=
$i_idx;
if ($debug) echoDebugLine(__FILE__
,__LINE__
,"first orderNr in block: $i_idx");
$arr_tmp[$i_idx]=
&$obj_field;
if ($debug) echoDebugLine(__FILE__
,__LINE__
,"setting moveField (".
$obj_field->getKey().
") sortOrder to $i_idx");
if ($obj_blockFld->getKey() !=
$obj_field->getKey())
if ($debug &&
($obj_blockFld->getOrderNr() !=
$i_idx)) echoDebugLine(__FILE__
,__LINE__
,"setting field (".
$obj_field->getKey().
") sortOrder to $i_idx");
$arr_tmp[$i_idx]=
&$obj_blockFld;
if ($debug) echoDebugLine(__FILE__
,__LINE__
,"index $i_idx not found in block");
$arr_tmp[$i_idx]=
&$obj_field;
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* checks if we have a field in $scope
if (!$obj_fld->isHidden($scope)) return True;
* returns if the block is to show in $mode
* checks $this->show.... and FRB_GROUP_...
$this->getFields(-
1,False); // to load $this->myFields
if (isset
($this->FRB_GROUP_NEW) &&
intval($this->FRB_GROUP_NEW))
if (isset
($this->FRB_GROUP_NEW) &&
intval($this->FRB_GROUP_NEW))
if ($debug) echoDebugLine(__FILE__
,__LINE__
,"GROUP_EDIT: ".
$this->FRB_GROUP_EDIT.
" return <strong>False</strong>");
if ($debug) echoDebugLine(__FILE__
,__LINE__
,"hasFieldInScope: return <strong>".
($b_ret ?
"True" :
"False").
"</strong>");
if ($debug) echoDebugLine(__FILE__
,__LINE__
,"hasFieldInScope: return <strong>".
($b_ret ?
"True" :
"False").
"</strong>");
ocsp_logError(__FILE__
,__LINE__
,"mode $mode not implemented in isToShow()");
} // end of OCSP_FORM_BLOCK
Documentation generated on Thu, 08 Jan 2009 17:46:01 +0100 by phpDocumentor 1.4.0a2