* @brief TableWiz helper */ if(!check_function_exists("tablewiz_cut_str")) { function tablewiz_cut_str($str, $strlimit=0) { $plaintext = strip_tags($str); // if use html, do not cut text if($strlimit > 0 && $str != $plaintext) { $str = substr($str, 0, $strlimit); } return $str; } } if(!check_function_exists("tablewiz_create")) { function tablewiz_create($rows, $bind=array(), $domid="", $domclass="", $strlimit=0, $thead_html=array(), $tbody_html_list=array()) { $html = ""; if(count($rows) == 0) { return $html; } $dom_element_name = make_random_id(10); $domid = empty($domid) ? "tablewiz_id_" . $dom_element_name : $domid; $domclass = empty($domclass) ? "tablewiz_class_" . $dom_element_name : $domclass; $html_th_elms = ""; foreach($rows[0] as $k=>$v) { $html_th_text = array_key_empty($k, $bind) ? $k : $bind[$k]; $html_th_elms .= "" . tablewiz_cut_str($html_th_text, $strlimit) . ""; } // append contents in thead foreach($thead_html as $k=>$v) { $html_th_elms .= "" . tablewiz_cut_str($v, $strlimit) . ""; } $html_tr_elms = ""; foreach($rows as $idx=>$record) { $html_tr_elms .= ""; foreach($record as $k=>$v) { $html_tr_elms .= "" . tablewiz_cut_str($v, $strlimit) . ""; } $html_tr_elms .= ""; // append contents in tbody if(count($tbody_html_list) > $idx) { $tbody_html = $tbody_html_list[$idx]; if(is_array($tbody_html)) { foreach($tbody_html as $k=>$v) { $html_tr_elms .= "" . tablewiz_cut_str($v, $strlimit) . ""; } } } } $html .= << $html_th_elms $html_tr_elms EOF; return $html; } }