_cols = ($cols > 0) ? $cols : 2;
return $tbl;
}
public static function NewIndexed($id, $title, $attrs, $index, $helpkey=NULL, $defaultExtract=NULL)
{
$tbl = new DTbl($id, $title, $attrs, $helpkey);
$tbl->_holderIndex = $index;
$tbl->_cols = 2;
if ($defaultExtract != NULL)
$tbl->_defaultExtract = $defaultExtract;
return $tbl;
}
public static function NewTop($id, $title, $attrs, $index, $addTbl, $align=0, $helpkey=NULL, $icon=NULL, $hasNote=FALSE)
{
$tbl = new DTbl($id, $title, $attrs, $helpkey);
$cols = count($attrs);
$tbl->_holderIndex = $index;
$tbl->_addTbl = $addTbl;
$tbl->_align = $align;
$tbl->_isTop = true;
if ($icon != NULL) {
$tbl->_icon = $icon;
$cols ++;
}
if ($hasNote) {
$cols ++;
$tbl->_hasNote = $hasNote;
}
$tbl->_cols = $cols;
return $tbl;
}
public static function NewSel($id, $title, $attrs, $subtbls, $helpkey=NULL)
{
$tbl = new DTbl($id, $title, $attrs, $helpkey);
$tbl->_subTbls = $subtbls;
$tbl->_cols = 3;
return $tbl;
}
private function __construct($id, $title, $attrs, $helpKey=NULL)
{
$this->_id = $id;
$this->_title = $title;
$this->_dattrs = $attrs;
$this->_helpKey = $helpKey;
}
public function Dup($newId, $title=NULL)
{
$d = new DTbl($newId, (($title == NULL)? $this->_title : $title), $this->_dattrs, $this->_helpKey);
$d->_addTbl = $this->_addTbl;
$d->_align = $this->_align;
$d->_icon = $this->_icon;
$d->_width = $this->_width;
$d->_cols = $this->_cols;
$d->_hasNote = $this->_hasNote;
$d->_holderIndex = $this->_holderIndex;
$d->_subTbls = $this->_subTbls;
$d->_linkedTbls = $this->_linkedTbls;
$d->_defaultExtract = $this->_defaultExtract;
$d->_showParentRef = $this->_showParentRef;
return $d;
}
public function Get($field)
{
switch ($field) {
case self::FLD_ID: return $this->_id;
case self::FLD_LINKEDTBL: return $this->_linkedTbls;
case self::FLD_INDEX: return $this->_holderIndex;
case self::FLD_DATTRS: return $this->_dattrs;
case self::FLD_DEFAULTEXTRACT: return $this->_defaultExtract;
case self::FLD_SUBTBLS: return $this->_subTbls;
}
die("DTbl field $field not supported");
}
public function Set($field, $fieldval)
{
switch ($field) {
case self::FLD_SHOWPARENTREF: $this->_showParentRef = $fieldval;
break;
case self::FLD_LINKEDTBL: $this->_linkedTbls = $fieldval;
break;
case self::FLD_DEFAULTEXTRACT: $this->_defaultExtract = $fieldval;
break;
default: die("field $field not supported");
}
}
public function ResetAttrEntry($index, $newAttr)
{
$this->_dattrs[$index] = $newAttr;
}
public function GetSubTid($node)
{
if ($this->_subTbls == '')
return NULL;
$keynode = $node->GetChildren($this->_subTbls[0]);
if ($keynode == NULL)
return NULL;
$newkey = $keynode->Get(CNode::FLD_VAL);
if ( ($newkey == '0') || !isset($this->_subTbls[$newkey]) ) {
return $this->_subTbls[1]; // use default
}
else
return $this->_subTbls[$newkey];
}
public function PrintHtml($dlayer, $disp)
{
if ($this->_holderIndex != NULL && $dlayer != NULL) {
// populate missing index
if (is_array($dlayer)) {
foreach ($dlayer as $key => $nd) {
if ($nd->GetChildren($this->_holderIndex) == NULL) {
$nd->AddChild(new CNode($this->_holderIndex, $nd->Get(CNode::FLD_VAL)));
}
}
}
elseif ($dlayer->GetChildren($this->_holderIndex) == NULL) {
$dlayer->AddChild(new CNode($this->_holderIndex, $dlayer->Get(CNode::FLD_VAL)));
}
}
if ($disp->IsViewAction())
$this->print_view($dlayer, $disp);
else
$this->print_edit($dlayer, $disp);
}
private function get_print_header($disp, $actString, $isEdit=FALSE, $hasSort=FALSE)
{
$buf = ''. $title . '
' . $table_help . '';
if ($hasSort) {
$this->_sorted_tbl = FALSE;
$sortval = $disp->Get(DInfo::FLD_SORT);
if ($sortval != NULL) {
$pos = strpos($sortval, '`');
if ($this->_id == substr($sortval, 0, $pos)) {
$this->_sorted_tbl = TRUE;
$this->_sort_ascend = $sortval[$pos+1];
$this->_sort_key = substr($sortval, $pos+2);
}
}
}
$url = $disp->Get(DInfo::FLD_CtrlUrl);
if ( $disp->Get(DInfo::FLD_TID) != NULL )
$url .= '&t=' . $disp->Get(DInfo::FLD_TID);
if ( $disp->Get(DInfo::FLD_REF) != NULL )
$url .= '&r=' . $disp->Get(DInfo::FLD_REF);
if ($this->_icon != NULL)
$buf .= ' \n";
}
return $buf;
}
private function print_view($dlayer, $disp)
{
$buf = '';
foreach( $keys as $i )
{
$attr = $this->_dattrs[$i];
if ( $attr->IsFlagOn(DAttr::BM_HIDE) )
continue;
$buf .= ' _align[$i]) )
$buf .= ' align="'.$this->_align[$i] .'"';
$buf .= '>' . $attr->_label;
if ( $hasSort && $attr->_type != 'action' )
{
$buf .= ' ';
else
$buf .= '1' . $attr->GetKey() . '"> ';
}
else {
$buf .= '1' . $attr->GetKey() . '"> ';
}
$buf .= '';
}
if ( $attr->_type == 'ctxseq' ) {
$attr->_hrefLink = $url . $attr->_href;
}
$buf .= ' ';
}
$buf .= "