function tabler($rows, $list = TRUE, $edit = TRUE, $repopulate = FALSE) { $result = array(); $CI =& get_instance(); $rows[] = array("", array('type' => 'submit', 'name' => 'submit', 'class' => 'btn primary', 'id' => 'submit', 'value' => _('Save'))); $echo = ""; foreach ($rows as $rowk => $row) { foreach ($row as $colk => $column) { if ($colk == 0) { $result[$rowk][$colk]["form"] = $column; $result[$rowk][$colk]["table"] = $column; $result[$rowk][$colk]["field"] = isset($rows[$rowk][$colk + 1]['name']) ? $rows[$rowk][$colk + 1]['name'] : $rows[$rowk][$colk + 1]; } else { if (isset($column['list']) && is_array($column['list'])) { foreach ($column['list'] as $key => $item) { if (!isset($column['list'][$key]['value'])) { $column['list'][$key]['value'] = ""; } } } elseif (!isset($column['value']) && is_array($column)) { $column['value'] = ""; } if (is_array($column)) { $result[$rowk][$colk]["table"] = writize($column); if (isset($column['type'])) { $result[$rowk][$colk]["type"] = $column['type']; $result[$rowk][$colk]["form"] = formize($column, $repopulate); $result[$rowk][$colk]['value'] = isset($column['values']) ? $column['values'] : $column['value']; } } else { $result[$rowk][$colk]["form"] = $column; $result[$rowk][$colk]["table"] = writize($column); $result[$rowk][$colk]["value"] = $column; } } } } // echo '<pre>'; print_r($result); echo '</pre>'; if ($list && $edit) { $CI->buttoner[] = array('text' => _('Edit'), 'href' => '', 'onclick' => "slideToggle('.plain'); slideToggle('.edit'); return false;"); } if ($list && $edit) { $echo .= '<div class="plain"><fieldset>'; foreach ($result as $rowk => $row) { if (isset($row[1]['type']) && $row[1]['type'] == 'hidden') { //$echo .= $row[1]['form']; } else { if (!isset($row[1]) || $row[1]['table'] != _('Save') && $row[0]['table'] != 'id') { $echo .= '<div class="clearfix">'; foreach ($row as $colk => $column) { if ($colk == 0) { $echo .= '<label for="' . $column['field'] . '">' . $column['table'] . '</label>'; $echo .= '<div class="input">'; } else { $echo .= '<span class="uneditable-input">'; if (is_array($column['table'])) { foreach ($column['table'] as $mini) { $echo .= '' . $mini->name . ' '; } } else { if ($column['table'] == "") { $echo .= 'N/A'; } else { if ($column['type'] == 'dropdowner' || $column['type'] == 'checkbox') { $echo .= $column['value'][$column['table']]; } else { $echo .= $column['table']; } } } $echo .= '</span>'; } } $echo .= '</div></div>'; } } } $echo .= '</fieldset></div>'; } elseif ($list) { $echo .= '<div class="plain"><table class="zebra-striped" rules="rows">'; foreach ($result as $rowk => $row) { if (isset($row[1]['type']) && $row[1]['type'] == 'hidden') { //$echo .= $row[1]['form']; } else { if (!isset($row[1]) || $row[1]['table'] != _('Save') && $row[0]['table'] != 'id') { $echo .= '<tr>'; foreach ($row as $key => $column) { if ($key == 'action' && $key !== 0) { $echo .= '<td><div style="float: right">'; } else { $echo .= '<td>'; } if (is_array($column['table'])) { foreach ($column['table'] as $mini) { $echo .= '' . $mini->name . ' '; } } else { if ($column['table'] == "") { $echo .= 'N/A'; } else { $echo .= $column['table']; } } if ($key == 'action' && $key !== 0) { $echo .= '</div>'; } $echo .= '</td>'; } $echo .= '</tr>'; } } } $echo .= '</table></div>'; } if ($edit) { $echo .= '<div class="edit" ' . ($list && $edit ? 'style="display:none;"' : '') . '><fieldset>'; foreach ($result as $rowk => $row) { if (isset($row[1]['type']) && $row[1]['type'] == 'hidden') { $echo .= $row[1]['form']; } else { $echo .= '<div class="clearfix">'; foreach ($row as $colk => $column) { if ($colk == 0) { $echo .= '<label for="' . $column['field'] . '">' . $column['form'] . '</label>'; $echo .= '<div class="input">'; } else { $echo .= $column['form']; } } $echo .= '</div></div>'; } } $echo .= '</fieldset></div>'; } return $echo; }
function tabler($rows, $list = TRUE, $edit = TRUE, $repopulate = FALSE) { $result = array(); $CI = & get_instance(); $rows[] = array( "", array( 'type' => 'submit', 'name' => 'submit', 'id' => 'submit', 'value' => _('Save') ) ); $echo = ""; foreach ($rows as $rowk => $row) { foreach ($row as $colk => $column) { if ($colk == 0) { $result[$rowk][$colk]["table"] = $column; $result[$rowk][$colk]["form"] = $column; } else { if (!isset($column['value'])) $column['value'] = ""; if (is_array($column)) { $result[$rowk][$colk]["table"] = writize($column); if (isset($column['type'])) { $result[$rowk][$colk]["form"] = formize($column, $repopulate); $result[$rowk][$colk]["type"] = $column['type']; } } else { $result[$rowk][$colk]["table"] = writize($column); $result[$rowk][$colk]["form"] = $column; } } } } // echo '<pre>'; print_r($result); echo '</pre>'; if ($list && $edit) { $CI->buttoner[] = array( 'text' => _('Edit'), 'href' => '', 'onclick' => "slideToggle('.plain'); slideToggle('.edit'); return false;" ); } if ($list) { $echo .= '<div class="plain"><table class="form">'; foreach ($result as $rowk => $row) { if (isset($row[1]['type']) && $row[1]['type'] == 'hidden') { //$echo .= $row[1]['form']; } else { if (!isset($row[1]) || $row[1]['table'] != _('Save') && $row[0]['table'] != 'id') { $echo .= '<tr>'; foreach ($row as $column) { $echo .= '<td>'; if (is_array($column['table'])) { foreach ($column['table'] as $mini) { $echo .= '' . $mini->name . ' '; } } else if ($column['table'] == "") $echo .= 'N/A'; else $echo .= $column['table']; $echo .= '</td>'; } $echo .= '</tr>'; } } } $echo .= '</table></div>'; } if ($edit) { $echo .= '<div class="edit" ' . (($list && $edit) ? 'style="display:none;"' : '') . '><table class="form">'; foreach ($result as $rowk => $row) { if ($row[1]['type'] == 'hidden') { $echo .= $row[1]['form']; } else { $echo .= '<tr>'; foreach ($row as $column) { $echo .= '<td>'; $echo .= $column['form']; $echo .= '</td>'; } $echo .= '</tr>'; } } $echo .= '</table></div>'; } return $echo; }