Code: Select all
// std table ( for 'lists'.php ) - requires a arraer containing arrays of Fiels/Values and Columns
// contains ( or will contain ) column adding, seletion, field adding, row buttons and 'Add New' row....
// list item MUST at leas have columns/propertie/fields - such as the template provided by fw_list_new();
// ['name'] also required in array
function ui_tablelist($title,$list,$headers_array = null,$row_buttons=array(),$show_add = true){
ui_panel_start(admin_label($title));
if(is_array($list)){
$valid = false;
if(isset($list[FW_LIST_ITEMS])){ $valid = true ; }
if(isset($list[FW_LIST_COLUMNS])){ $valid = true ; }
if($valid) { $valid = is_array($list[FW_LIST_ITEMS]); }
if($valid) { $valid = is_array($list[FW_LIST_COLUMNS]); }
// Items should match columns, but display based on columns currently availabl
// [items][[row]][column/p] = <value>
if(!$valid){
echo '<p>List is Empty</p>';
if(isset($list[FW_LIST_COLUMNS])){
?><table class=""><?php
_table_add($list[FW_LIST_COLUMNS]); // <-- the option to add a item to this empty list
?></table><?php
}
}else{
if(count($list[FW_LIST_ITEMS]) > 0 ){
?>
<div class="">
<?php
// header buttons if any
if ( is_array( $headers_array ) ) { foreach ( $headers_array as $name => $label ) {
?><input name="<?php echo $name ?>" type="submit" value="<?php echo admin_label($name) ?>" /><?php
}
}
?>
</div>
<table>
<!-- header start -->
<tr class="">
<?php
// headers
if(is_array($list[FW_LIST_COLUMNS])){ foreach($list[FW_LIST_COLUMNS] as $columnheader ) {
?><td class=""><?php echo admin_label($columnheader); ?></td><?php
} }
?>
</tr>
<!-- header end -->
<!-- rows start -->
<?php
if( is_array($list[FW_LIST_ITEMS] )){ foreach($list[FW_LIST_ITEMS ] as $rowID => $item_row) {
// $item row must be $p/column => $v
?>
<tr class="">
<!-- items -->
<?php
// checking by available columns, not by available peroperties in each row
foreach( $list[FW_LIST_COLUMNS] as $column ){
$value = "";
if(isset($item_row[$column])){
$value = $item_row[$column];
}
$str = '_list['.$list['name'].']['.$rowID.']['.$column.']';
?>
<td class="">
<input name="<?php echo $str ?>" type="text" value="<?php echo $value; ?>" />
</td>
<?php
}
?>
<!-- buttons -->
<?php
foreach($row_buttons as $name => $label){
$str = $name.'['.$list['name'].']['.$rowID.']';
?>
<td class="">
<input name="<?php echo $str; ?>" type="submit" value="<?php echo admin_label($label); ?>" />
</td>
<?php
}
?>
</tr>
<?php } ?>
<!-- rows end -->
<!-- Add new item to tabel : -->
<?php _table_add($list[FW_LIST_COLUMNS]); ?>
</table>
<?php
}else{ // count
echo '<p> No Lists Items Available </p>';
}
}
}
}
ui_panel_end();
}
Code: Select all
// a componenet of the above function
function _table_add($columns){
?>
<tr class="">
<!-- New Item -->
<?php foreach( $columns as $column ){ ?>
<td class="">
<input name="_newitem[<?php echo $column; ?>]" type="text" />
</td>
<?php } ?>
<td>
<input name="_addnewlistitem" type="submit" value="Save" />
</td>
</tr>
<?php
}
?>
// < different php file contains this>
// new list array structure
function fw_list_new($name){
return array(
FW_LIST_SUBITEM_KEY => FW_LIST_SUBITEM_KEY, // infinate depth - to identify lists inside lists
'name' => $name,
FW_LIST_ITEMS => array(),
FW_LIST_ITEMS_DELETED => array(), // sub items are moved here when deleted
FW_LIST_COLUMNS => array('name','description'), //default columns
//'min_level_view' => 900, // on Public Lists, weather only admins can view
//'min_level_edit' => 900, // admins can edit on public lists
//'deleted' => false, // <-- create this entry to hide it
//'creator' => USER_CURRENT_HASH, // who created this list
//'edited_by' => USER_CURRENT_HASH, // last edited by
//'public' => false, // user's list can be shared?
// Extra Propertied
//'properties' => array(),
FW_LIST_COMMENTS => array(), //<-- comments will be added as list items...
'date_created' => date(FW_DATEFORMAT),
'date_edited' => date(FW_DATEFORMAT),
);
}
The problem I have is that - when the lists are empty - it should display a table row containing empty fields under the available columns collected from FW LIST_COLUMNS....
The basic issue is - it simply displays nothing when FW_LIST_ITEMS array is empty... were I am expecting a table...
Might be hard to figure out just by looking at it - but I cant show more code than this publicly.
I'm posting in hope that the first set of code { ui_tablelist(); } has a really simple stupid mistake that I am overlooking somewere.