📄 table.class.inc
字号:
<?php/** * @copyright Intermesh 2005 * @author Merijn Schering <mschering@intermesh.nl> * @version $Revision: 1.41 $ $Date: 2006/03/29 11:23:46 $ * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. * @package Framework * @subpackage Controls *//** * Creates a table that uses tabs to show multiple screens * * @package Framework * @subpackage Controls * * @access public */ class table extends html_element{ var $rows = array(); var $headings = array(); function table($id='') { $this->tagname = 'table'; $this->set_linebreak("\n"); if($id != '') { $this->set_attribute('id', $id); } } function add_column($heading) { $this->headings[] = $heading; } function add_row($row) { if(isset($this->attributes['id'])) { $row->table_id=$this->attributes['id']; } $this->rows[] = $row; } function get_html() { $html = '<table'; foreach($this->attributes as $name=>$value) { $html .= ' '.$name.'="'.$value.'"'; } $html .= '><tbody>'.$this->lb; $html .= $this->get_headings(); $html .= $this->get_rows(); $html .= '</tbody></table>'.$this->lb; return $this->outerHTML.$html; } function get_headings() { global $GO_THEME; $headings = ''; if(count($this->headings) > 0) { foreach($this->headings as $key=>$heading) { $headings .= '<th'; foreach($heading->attributes as $name=>$value) { $headings .= ' '.$name.'="'.$value.'"'; } $headings .= '>'.$heading->name.'</th>'.$this->lb; } $headings = '<tr>'.$this->lb.$headings.'</tr>'.$this->lb; } return $headings; } function get_rows() { $rows = ''; foreach($this->rows as $row) { $rows .= $row->get_html(); } return $rows; }}class datatable extends table{ var $footer; var $form_name = 'forms[0]'; var $sort_index; var $sort_ascending = true; var $sql_sort_order='ASC'; var $sort_table = array(); var $start = 0; var $offset = 0; var $total_rows = 0; var $max_links=10; var $row_count = 0; var $autosort = false; var $task =''; var $selected = array(); var $hidden_selected = array(); var $remind_selected = false; var $multiselect = true; function datatable($id, $autosort=false, $form_name='0') { global $GO_CONFIG, $GO_SECURITY; $this->tagname = 'table'; $this->set_linebreak("\n"); $this->set_attribute('id', $id); $this->set_attribute('onselectstart', 'return false;'); $this->form_name = $form_name; $this->autosort = $autosort; $this->sort_index = $GO_CONFIG->get_setting('sort_index_'.$id, $GO_SECURITY->user_id); $this->sort_ascending = $GO_CONFIG->get_setting('sort_asc_'.$id, $GO_SECURITY->user_id); if(isset($_POST[$id]['sort_index']) && $_POST[$id]['sort_index'] != $this->sort_index) { $GO_CONFIG->save_setting( 'sort_index_'.$id, smart_addslashes($_POST[$id]['sort_index']), $GO_SECURITY->user_id); $this->sort_index = smart_stripslashes($_POST[$id]['sort_index']); } if(isset($_POST[$id]['sort_ascending']) && $_POST[$id]['sort_ascending'] != $this->sort_ascending) { $GO_CONFIG->save_setting( 'sort_asc_'.$id, smart_addslashes($_POST[$id]['sort_ascending']), $GO_SECURITY->user_id); $this->sort_ascending = smart_stripslashes($_POST[$id]['sort_ascending']); } $this->sql_sort_order = $this->sort_ascending ? 'ASC' : 'DESC'; $this->offset = isset($_POST[$this->attributes['id']]['offset']) ? $_POST[$this->attributes['id']]['offset'] : $_SESSION['GO_SESSION']['max_rows_list']; if(isset($_POST[$this->attributes['id']]['start'])) { $this->start = $_SESSION[$this->attributes['id']]['start'] = $_POST[$this->attributes['id']]['start']; }else { $this->start = isset($_SESSION[$this->attributes['id']]['start']) ? $_SESSION[$this->attributes['id']]['start'] : 0; } $this->task = isset($_POST[$this->attributes['id']]['task']) ? $_POST[$this->attributes['id']]['task'] : ''; $this->selected = isset($_POST[$this->attributes['id']]['selected']) ? $_POST[$this->attributes['id']]['selected'] : array(); } function enable_select() { $this->set_attribute('style','-moz-user-select:text'); $this->set_attribute('onselectstart',''); } function get_header() { global $GO_CONFIG; return '<script type="text/javascript" src="'.$GO_CONFIG->host.'javascript/datatable.js"></script>'; } function set_remind_selected($remind_selected) { $this->remind_selected = $remind_selected; } function set_multiselect($multiselect) { $this->multiselect=$multiselect; } function set_pagination($total_rows) { $this->total_rows = $total_rows; } function add_column($heading) { if(empty($this->sort_index)) { if($this->autosort) { $this->sort_index = 0; }else { if(!empty($heading->sort_name)) { $this->sort_index = $heading->sort_name; } } } $this->headings[] = $heading; } function unshift_column($heading) { if(empty($this->sort_index)) { if($this->autosort) { $this->sort_index = 0; }else { if(!empty($heading->sort_name)) { $this->sort_index = $heading->sort_name; } } } array_unshift($this->headings, $heading); } function add_footer($row) { $this->footer = $row; } function add_row($row) { $row->table= &$this; $this->rows[] = $row; if($this->autosort) { $this->sort_table[] = $row->cells[$this->sort_index]->sort_name; } } function sort($sort_index, $sort_ascending =true) { $this->sort_index = $sort_index; $this->sort_ascending = $sort_ascending ; } function get_count_selected_handler() { return "table_count_selected('".$this->form_name."','".$this->attributes['id']."');"; } function get_unlink_handler() { return "javascript:table_confirm_unlink('".$this->form_name."','".$this->attributes['id']."', '". htmlspecialchars(addslashes($GLOBALS['strNoItemSelected']))."', '". htmlspecialchars(addslashes($GLOBALS['strSelectedItem']))."', '". htmlspecialchars(addslashes($GLOBALS['strSelectedItems']))."', '". htmlspecialchars(addslashes($GLOBALS['strUnlinkPrefix']))."', '". htmlspecialchars(addslashes($GLOBALS['strUnlinkSuffix']))."');"; } function get_delete_handler($row_id=0) { if ($row_id > 0) { return "javascript:table_select_single('".$this->form_name."','".$this->attributes['id']."', '".$row_id."');". "table_confirm_delete('".$this->form_name."','".$this->attributes['id']."', '". htmlspecialchars(addslashes($GLOBALS['strNoItemSelected']))."', '". htmlspecialchars(addslashes($GLOBALS['strSelectedItem']))."', '". htmlspecialchars(addslashes($GLOBALS['strSelectedItems']))."', '". htmlspecialchars(addslashes($GLOBALS['strDeletePrefix']))."', '". htmlspecialchars(addslashes($GLOBALS['strDeleteSuffix']))."');"; }else { return "javascript:table_confirm_delete('".$this->form_name."','".$this->attributes['id']."', '". htmlspecialchars(addslashes($GLOBALS['strNoItemSelected']))."', '". htmlspecialchars(addslashes($GLOBALS['strSelectedItem']))."', '". htmlspecialchars(addslashes($GLOBALS['strSelectedItems']))."', '". htmlspecialchars(addslashes($GLOBALS['strDeletePrefix']))."', '". htmlspecialchars(addslashes($GLOBALS['strDeleteSuffix']))."');"; } } function set_page_one() { return 'document.forms["'.$this->form_name.'"].elements["'.$this->attributes['id'].'[start]"].value=0;'; } function get_task_var() { return 'document.forms["'.$this->form_name.'"].elements["'.$this->attributes['id'].'[task]"]'; } function get_html() { if($this->remind_selected) { $this->hidden_selected = array_map('smart_stripslashes',$this->selected); } $table = '<input type="hidden" name="'.$this->attributes['id'].'[sort_ascending]" value="'.$this->sort_ascending.'" />'.$this->lb; $table .= '<input type="hidden" name="'.$this->attributes['id'].'[sort_index]" value="'.$this->sort_index.'" />'.$this->lb; $table .= '<input type="hidden" name="'.$this->attributes['id'].'[offset]" value="'.$this->offset.'" />'.$this->lb; $table .= '<input type="hidden" name="'.$this->attributes['id'].'[start]" value="'.$this->start.'" />'.$this->lb; $table .= '<input type="hidden" name="'.$this->attributes['id'].'[task]" value="" />'.$this->lb; if(!isset($this->attributes['class'])) { $this->set_attribute('class','go_table'); } $table .= '<table'; foreach($this->attributes as $name=>$value) { $table .= ' '.$name.'="'.$value.'"'; } $table .= '>'.$this->lb; $table .= $this->get_headings(); $table .= $this->get_rows(); if(isset($this->footer)) { $table .= $this->footer->get_html();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -