-
Notifications
You must be signed in to change notification settings - Fork 3
/
csort.inc.php
96 lines (82 loc) · 2.42 KB
/
csort.inc.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?
//==================================================================
// Column sort class
//==================================================================
class column_sort_db
{
protected $url; // default url
protected $cols_n; // name
protected $cols_t; // title
protected $def_col; // default column
protected $def_dir; // default direction
function __construct()
{
$this->cols_n = array();
$this->cols_t = array();
$this->url = '';
$this->def_col = 0;
$this->def_dir = 1;
}
public function add_column($name,$title)
{
$this->cols_n[] = $name;
$this->cols_t[] = $title;
}
public function set_url($url,$params = false)
{
if($params)
$this->url = $url.'&csd=';
else
$this->url = $url.'?csd=';
}
public function set_default_sort($column,$direction)
{
$this->def_col = $column;
$this->def_dir = ($direction > 0 && $direction < 3) ? $direction : 1;
}
public function get_all_content()
{
$text = 'sort :';
for($ii=0; $ii< count ($this->cols_n); $ii++)
{
$text .= ' ';
$text .= $this->get_col_content($ii,true);
}
return $text;
}
public function get_col_content($col,$show_title = false)
{
$text = '';
if($col >= 0 && $col < count ($this->cols_n))
{
$v_up = (($col+1) << 4)+1;
$v_dn = (($col+1) << 4)+2;
if($show_title)
$text .= $this->cols_t[$col].' [';
$text .= '<A HREF="'.$this->url.$v_up.'"><IMG src="imgs/up'.(($this->def_col == $col && $this->def_dir == 1) ? '1' : '0' ).'.gif" border="0" width="8" height="8" alt="A->Z"></A>';
$text .= ' ';
$text .= '<A HREF="'.$this->url.$v_dn.'"><IMG src="imgs/dn'.(($this->def_col == $col && $this->def_dir == 2) ? '1' : '0' ).'.gif" border="0" width="8" height="8" alt="Z->A"></A>';
if($show_title)
$text .= ']';
}
return $text;
}
public function get_sql_string()
{
global $csd;
$csd = (IsSet($csd) && is_numeric($csd)) ? $csd : 0;
$col = $csd >> 4;
$dir = $csd - ($col << 4);
$col--;
$col = ($col >= 0 && $col < count ($this->cols_n)) ? $col : 0;
$dir = ($dir > 0 && $dir < 3) ? $dir : 1;
$this->set_default_sort($col,$dir);
// $query = 'res = '.$csd;
// $query .= ', col = '.$col.', dir = '.$dir;
$query = ' ORDER BY `'.$this->cols_n[$col].'` ';
$query.= ($dir == 2) ? 'DESC' : 'ASC';
return $query;
}
}
//==================================================================
?>