SHOW:
|
|
- or go back to the newest paste.
1 | - | <?php |
1 | + | <?php |
2 | - | |
2 | + | |
3 | - | class ACMS_GET_Admin_Form_Index extends ACMS_GET_Admin_Module |
3 | + | class ACMS_GET_Admin_Form_Index extends ACMS_GET_Admin_Module |
4 | - | { |
4 | + | { |
5 | - | function get() |
5 | + | function get() |
6 | - | { |
6 | + | { |
7 | - | if ( 'form_index' <> ADMIN && 'form2-edit' <> ADMIN ) return ''; |
7 | + | if ( 'form_index' <> ADMIN && 'form2-edit' <> ADMIN ) return ''; |
8 | - | if ( 0 |
8 | + | if ( 0 |
9 | - | || ( !roleAvailableUser() && !sessionWithAdministration() ) |
9 | + | || ( !roleAvailableUser() && !sessionWithAdministration() ) |
10 | - | || ( roleAvailableUser() && !roleAuthorization('form_view', BID) && !roleAuthorization('form_edit', BID) ) |
10 | + | || ( roleAvailableUser() && !roleAuthorization('form_view', BID) && !roleAuthorization('form_edit', BID) ) |
11 | - | ) { |
11 | + | ) { |
12 | - | return ''; |
12 | + | return ''; |
13 | - | } |
13 | + | } |
14 | - | |
14 | + | |
15 | - | $Tpl = new Template($this->tpl, new ACMS_Corrector()); |
15 | + | $Tpl = new Template($this->tpl, new ACMS_Corrector()); |
16 | - | $Vars = array(); |
16 | + | $Vars = array(); |
17 | - | |
17 | + | |
18 | - | //--------- |
18 | + | //--------- |
19 | - | // refresh |
19 | + | // refresh |
20 | - | if ( !$this->Post->isNull() ) { |
20 | + | if ( !$this->Post->isNull() ) { |
21 | - | $Tpl->add('refresh'); |
21 | + | $Tpl->add('refresh'); |
22 | - | $Vars['notice_mess'] = 'show'; |
22 | + | $Vars['notice_mess'] = 'show'; |
23 | - | } |
23 | + | } |
24 | - | |
24 | + | |
25 | - | //------- |
25 | + | //------- |
26 | - | // order |
26 | + | // order |
27 | - | $order = ORDER ? ORDER : 'id-asc'; |
27 | + | $order = ORDER ? ORDER : 'id-asc'; |
28 | - | $Vars['order:selected#'.$order] = config('attr_selected'); |
28 | + | $Vars['order:selected#'.$order] = config('attr_selected'); |
29 | - | |
29 | + | |
30 | - | //-------- |
30 | + | //-------- |
31 | - | // limit |
31 | + | // limit |
32 | - | $limits = configArray('admin_limit_option'); |
32 | + | $limits = configArray('admin_limit_option'); |
33 | - | $limit = $this->Q->get('limit', $limits[config('admin_limit_default')]); |
33 | + | $limit = $this->Q->get('limit', $limits[config('admin_limit_default')]); |
34 | - | foreach ( $limits as $val ) { |
34 | + | foreach ( $limits as $val ) { |
35 | - | $_vars = array('value' => $val); |
35 | + | $_vars = array('value' => $val); |
36 | - | if ( $limit == $val ) $_vars['selected'] = config('attr_selected'); |
36 | + | if ( $limit == $val ) $_vars['selected'] = config('attr_selected'); |
37 | - | $Tpl->add('limit:loop', $_vars); |
37 | + | $Tpl->add('limit:loop', $_vars); |
38 | - | } |
38 | + | } |
39 | - | |
39 | + | |
40 | - | $DB = DB::singleton(dsn()); |
40 | + | $DB = DB::singleton(dsn()); |
41 | - | |
41 | + | |
42 | - | $SQL = SQL::newSelect('form'); |
42 | + | $SQL = SQL::newSelect('form'); |
43 | - | $SQL->addSelect('log_form_datetime', 'log_form_datetime', null, 'MAX'); |
43 | + | $SQL->addSelect('log_form_datetime', 'log_form_datetime', null, 'MAX'); |
44 | - | $SQL->addSelect('log_form_form_id'); |
44 | + | $SQL->addSelect('log_form_form_id'); |
45 | - | $SQL->addLeftJoin('blog', 'blog_id', 'form_blog_id'); |
45 | + | $SQL->addLeftJoin('blog', 'blog_id', 'form_blog_id'); |
46 | - | ACMS_Filter::blogTree($SQL, BID, 'ancestor-or-self'); |
46 | + | ACMS_Filter::blogTree($SQL, BID, 'ancestor-or-self'); |
47 | - | |
47 | + | |
48 | - | $Where = SQL::newWhere(); |
48 | + | $Where = SQL::newWhere(); |
49 | - | $Where->addWhereOpr('form_blog_id', BID, '=', 'OR'); |
49 | + | $Where->addWhereOpr('form_blog_id', BID, '=', 'OR'); |
50 | - | $Where->addWhereOpr('form_scope', 'global', '=', 'OR'); |
50 | + | $Where->addWhereOpr('form_scope', 'global', '=', 'OR'); |
51 | - | $SQL->addWhere($Where); |
51 | + | $SQL->addWhere($Where); |
52 | - | |
52 | + | |
53 | - | $Amount = new SQL_Select($SQL); |
53 | + | $Amount = new SQL_Select($SQL); |
54 | - | $Amount->setSelect('*', 'form_amount', null, 'count'); |
54 | + | $Amount->setSelect('*', 'form_amount', null, 'count'); |
55 | - | if ( !$pageAmount = $DB->query($Amount->get(dsn()), 'one') ) { |
55 | + | if ( !$pageAmount = $DB->query($Amount->get(dsn()), 'one') ) { |
56 | - | $Tpl->add('index#notFound'); |
56 | + | $Tpl->add('index#notFound'); |
57 | - | $Vars['notice_mess'] = 'show'; |
57 | + | $Vars['notice_mess'] = 'show'; |
58 | - | $Tpl->add(null, $Vars); |
58 | + | $Tpl->add(null, $Vars); |
59 | - | return $Tpl->get(); |
59 | + | return $Tpl->get(); |
60 | - | } |
60 | + | } |
61 | - | $Vars += $this->buildPager(PAGE, $limit, $pageAmount |
61 | + | $Vars += $this->buildPager(PAGE, $limit, $pageAmount |
62 | - | , config('admin_pager_delta'), config('admin_pager_cur_attr'), $Tpl, array(), array('admin' => ADMIN) |
62 | + | , config('admin_pager_delta'), config('admin_pager_cur_attr'), $Tpl, array(), array('admin' => ADMIN) |
63 | - | ); |
63 | + | ); |
64 | - | |
64 | + | |
65 | - | $Log = SQL::newSelect('log_form'); |
65 | + | $Log = SQL::newSelect('log_form'); |
66 | - | $Log->setOrder('log_form_datetime', 'DESC'); |
66 | + | $Log->setOrder('log_form_datetime', 'DESC'); |
67 | - | $SQL->addLeftJoin($Log, 'log_form_form_id', 'form_id', 'log_form_ordered'); |
67 | + | $SQL->addLeftJoin($Log, 'log_form_form_id', 'form_id', 'log_form_ordered'); |
68 | - | $SQL->addSelect('form_id'); |
68 | + | $SQL->addSelect('form_id'); |
69 | - | $SQL->addSelect('form_code'); |
69 | + | $SQL->addSelect('form_code'); |
70 | - | $SQL->addSelect('form_name'); |
70 | + | $SQL->addSelect('form_name'); |
71 | - | $SQL->addSelect('form_scope'); |
71 | + | $SQL->addSelect('form_scope'); |
72 | - | $SQL->addSelect('form_blog_id'); |
72 | + | $SQL->addSelect('form_blog_id'); |
73 | - | $SQL->addSelect('log_form_datetime', 'form_log_amount', null, 'count'); |
73 | + | $SQL->addSelect('log_form_datetime', 'form_log_amount', null, 'count'); |
74 | - | $Case = SQL::newCase(); |
74 | + | $Case = SQL::newCase(); |
75 | - | $Case->add(SQL::newOpr('log_form_datetime'), '1000-01-01 00:00:00'); |
75 | + | $Case->add(SQL::newOpr('log_form_datetime'), '1000-01-01 00:00:00'); |
76 | - | $Case->setElse(SQL::newField('log_form_datetime')); |
76 | + | $Case->setElse(SQL::newField('log_form_datetime')); |
77 | - | $SQL->addSelect($Case, 'form_last_datetime'); |
77 | + | $SQL->addSelect($Case, 'form_last_datetime'); |
78 | - | |
78 | + | |
79 | - | //------- |
79 | + | //------- |
80 | - | // order |
80 | + | // order |
81 | - | $base_order = explode('-', $order); |
81 | + | $base_order = explode('-', $order); |
82 | - | $base = $base_order[0]; |
82 | + | $base = $base_order[0]; |
83 | - | $ord = $base_order[1]; |
83 | + | $ord = $base_order[1]; |
84 | - | $ord = ('asc' == $ord) ? 'ASC' : 'DESC'; |
84 | + | $ord = ('asc' == $ord) ? 'ASC' : 'DESC'; |
85 | - | if ( 'code' == $base ) { |
85 | + | if ( 'code' == $base ) { |
86 | - | $SQL->setOrder('form_code', $ord); |
86 | + | $SQL->setOrder('form_code', $ord); |
87 | - | } else if ( 'amount' == $base ) { |
87 | + | } else if ( 'amount' == $base ) { |
88 | - | $SQL->setOrder('form_log_amount', $ord); |
88 | + | $SQL->setOrder('form_log_amount', $ord); |
89 | - | } else if ( 'datetime' == $base ) { |
89 | + | } else if ( 'datetime' == $base ) { |
90 | - | $SQL->setOrder('form_last_datetime', $ord); |
90 | + | $SQL->setOrder('form_last_datetime', $ord); |
91 | - | } else { |
91 | + | } else { |
92 | - | $SQL->setOrder('form_id', $ord); |
92 | + | $SQL->setOrder('form_id', $ord); |
93 | - | } |
93 | + | } |
94 | - | |
94 | + | |
95 | - | $SQL->setGroup('form_id'); |
95 | + | $SQL->setGroup('form_id'); |
96 | - | $SQL->setLimit($limit, (PAGE - 1) * $limit); |
96 | + | $SQL->setLimit($limit, (PAGE - 1) * $limit); |
97 | - | |
97 | + | |
98 | - | $q = $SQL->get(dsn()); |
98 | + | $q = $SQL->get(dsn()); |
99 | - | $DB->query($q, 'fetch'); |
99 | + | $DB->query($q, 'fetch'); |
100 | - | |
100 | + | |
101 | - | $editAction = false; |
101 | + | $editAction = false; |
102 | - | $logAction = false; |
102 | + | $logAction = false; |
103 | - | |
103 | + | |
104 | - | while ( $row = $DB->fetch($q) ) { |
104 | + | while ( $row = $DB->fetch($q) ) { |
105 | - | $fmid = intval($row['form_id']); |
105 | + | $fmid = intval($row['form_id']); |
106 | - | $fmbid = intval($row['form_blog_id']); |
106 | + | $fmbid = intval($row['form_blog_id']); |
107 | - | |
107 | + | |
108 | - | if ( 0 |
108 | + | if ( 0 |
109 | - | || ( !roleAvailableUser() && sessionWithAdministration($fmbid) ) |
109 | + | || ( !roleAvailableUser() && sessionWithAdministration($fmbid) ) |
110 | - | || ( roleAvailableUser() && roleAuthorization('form_edit', $fmbid) ) |
110 | + | || ( roleAvailableUser() && roleAuthorization('form_edit', $fmbid) ) |
111 | - | ) { |
111 | + | ) { |
112 | - | $editAction = true; |
112 | + | $editAction = true; |
113 | - | } |
113 | + | } |
114 | - | if ( 0 |
114 | + | if ( 0 |
115 | - | || ( !roleAvailableUser() && sessionWithAdministration(BID) ) |
115 | + | || ( !roleAvailableUser() && sessionWithAdministration(BID) ) |
116 | - | || ( roleAvailableUser() && roleAuthorization('form_view', BID) ) |
116 | + | || ( roleAvailableUser() && roleAuthorization('form_view', BID) ) |
117 | - | ) { |
117 | + | ) { |
118 | - | $logAction = true; |
118 | + | $logAction = true; |
119 | - | } |
119 | + | } |
120 | - | |
120 | + | |
121 | - | if ( $editAction ) { |
121 | + | if ( $editAction ) { |
122 | - | $Tpl->add(array('editAction', 'form:loop'), array( |
122 | + | $Tpl->add(array('editAction', 'form:loop'), array( |
123 | - | 'itemUrl' => acmsLink(array( |
123 | + | 'itemUrl' => acmsLink(array( |
124 | - | 'bid' => $fmbid, |
124 | + | 'bid' => $fmbid, |
125 | - | 'admin' => 'form_edit', |
125 | + | 'admin' => 'form_edit', |
126 | - | 'query' => array( |
126 | + | 'query' => array( |
127 | - | 'fmid' => $fmid, |
127 | + | 'fmid' => $fmid, |
128 | - | ), |
128 | + | ), |
129 | - | )), |
129 | + | )), |
130 | - | )); |
130 | + | )); |
131 | - | } |
131 | + | } |
132 | - | if ( $logAction ) { |
132 | + | if ( $logAction ) { |
133 | - | $Tpl->add(array('logAction', 'form:loop'), array( |
133 | + | $Tpl->add(array('logAction', 'form:loop'), array( |
134 | - | 'logUrl' => acmsLink(array( |
134 | + | 'logUrl' => acmsLink(array( |
135 | - | 'bid' => BID, |
135 | + | 'bid' => BID, |
136 | - | 'admin' => 'form_log', |
136 | + | 'admin' => 'form_log', |
137 | - | 'query' => array( |
137 | + | 'query' => array( |
138 | - | 'fmid' => $fmid, |
138 | + | 'fmid' => $fmid, |
139 | - | ), |
139 | + | ), |
140 | - | )), |
140 | + | )), |
141 | - | )); |
141 | + | )); |
142 | - | } |
142 | + | } |
143 | - | $Tpl->add('form:loop', array( |
143 | + | $Tpl->add('form:loop', array( |
144 | - | 'code' => $row['form_code'], |
144 | + | 'code' => $row['form_code'], |
145 | - | 'name' => $row['form_name'], |
145 | + | 'name' => $row['form_name'], |
146 | - | 'datetime' => $row['form_last_datetime'], |
146 | + | 'datetime' => $row['form_last_datetime'], |
147 | - | 'amount' => $row['form_log_amount'], |
147 | + | 'amount' => $row['form_log_amount'], |
148 | - | 'scope' => $row['form_scope'], |
148 | + | 'scope' => $row['form_scope'], |
149 | - | )); |
149 | + | )); |
150 | - | } |
150 | + | } |
151 | - | |
151 | + | |
152 | - | $Tpl->add(null, $Vars); |
152 | + | $Tpl->add(null, $Vars); |
153 | - | return $Tpl->get(); |
153 | + | return $Tpl->get(); |
154 | - | } |
154 | + | } |
155 | } |