XCL Web Application Platform 2.5.0
The XoopsCube Legacy Project
Loading...
Searching...
No Matches
simplewizard.php
1<?php
11
12
14 public $_v;
15 public $_op;
16 public $_title;
17 public $_content;
18 public $_next = '';
19 public $_back = '';
20 public $_reload = '';
21 public $_template_path;
22 public $_base_template_name;
23 public $_custom_seq;
24
25 public function setTemplatePath( $name ) {
26 $this->_template_path = $name;
27 }
28
29 public function setBaseTemplate( $name ) {
30 $this->_base_template_name = $name;
31 }
32
33 public function assign( $name, $value ) {
34 $this->_v[ $name ] = $value;
35 }
36
37 public function setContent( $value ) {
38 $this->_content = $value;
39 }
40
41 public function setOp( $value ) {
42 $this->_op = $value;
43 }
44
45 public function setTitle( $value ) {
46 $this->_title = $value;
47 }
48
49 public function setNext( $value ) {
50 $this->_next = $value;
51 $this->_custom_seq = true;
52 }
53
54 public function setBack( $value ) {
55 $this->_back = $value;
56 $this->_custom_seq = true;
57 }
58
59 public function setReload( $value ) {
60 $this->_reload = $value;
61 $this->_custom_seq = true;
62 }
63
64 public function addArray( $name, $value ) {
65 if ( ! isset( $this->_v[ $name ] ) || ! is_array( $this->_v[ $name ] ) ) {
66 $this->_v[ $name ] = [];
67 }
68 $this->_v[ $name ][] = $value;
69 }
70
71 public function v( $name ) {
72 return ! empty( $this->_v[ $name ] ) ? $this->_v[ $name ] : false;
73 }
74
75 public function e() {
76 $args = func_get_args();
77 if ( func_num_args() > 0 ) {
78 if ( ! empty( $this->_v[ $args[0] ] ) ) {
79 $value = $this->_v[ $args[0] ];
80 if ( 2 === func_num_args() && is_array( $value ) ) {
81 $value = $value[ $args[1] ];
82 }
83 } else {
84 $value = '';
85 }
86 echo $value;
87 }
88 }
89
90 public function render( $fname = '' ) {
91 if ( $fname && file_exists( $this->_template_path . '/' . $fname ) ) {
92 ob_start();
93 include $this->_template_path . '/' . $fname;
94 $this->setContent( ob_get_clean() );
95 }
96 $content = $this->_content;
97 if ( ! empty( $this->_title ) ) {
98 $title = $this->_title;
99 } else {
100 $title = $GLOBALS['wizardSeq']->getTitle( $this->_op );
101 }
102 if ( ! empty( $this->_next ) ) {
103 $b_next = $this->_next;
104 } elseif ( ! $this->_custom_seq ) {
105 $b_next = $GLOBALS['wizardSeq']->getNext( $this->_op );
106 } else {
107 $b_next = '';
108 }
109 if ( ! empty( $this->_back ) ) {
110 $b_back = $this->_back;
111 } elseif ( ! $this->_custom_seq ) {
112 $b_back = $GLOBALS['wizardSeq']->getBack( $this->_op );
113 } else {
114 $b_back = '';
115 }
116 if ( ! empty( $this->_reload ) ) {
117 $b_reload = $this->_reload;
118 } elseif ( ! $this->_custom_seq ) {
119 $b_reload = $GLOBALS['wizardSeq']->getReload( $this->_op );
120 } else {
121 $b_reload = '';
122 }
123 include $this->_base_template_name;
124 }
125
126 public function error() {
127 $content = $this->_content;
128 if ( ! empty( $this->_title ) ) {
129 $title = $this->_title;
130 } else {
131 $title = $GLOBALS['wizardSeq']->getTitle( $this->_op );
132 }
133 if ( ! empty( $this->_next ) ) {
134 $b_next = $this->_next;
135 } else {
136 $b_next = '';
137 }
138 if ( ! empty( $this->_back ) ) {
139 $b_back = $this->_back;
140 } else {
141 $b_back = '';
142 }
143 if ( ! empty( $this->_reload ) ) {
144 $b_reload = $this->_reload;
145 } else {
146 $b_reload = '';
147 }
148 include $this->_base_template_name;
149 }
150}
151
153 public $_list;
154
155 public function add( $name, $title = '', $next = '', $next_btn = '', $back = '', $back_btn = '', $reload = '' ) {
156 $this->_list[ $name ]['title'] = $title;
157 $this->_list[ $name ]['next'] = $next;
158 $this->_list[ $name ]['next_btn'] = $next_btn;
159 $this->_list[ $name ]['back'] = $back;
160 $this->_list[ $name ]['back_btn'] = $back_btn;
161 $this->_list[ $name ]['reload'] = $reload;
162 }
163
164 public function insertAfter( $after, $name, $title = '', $back = '', $back_btn = '', $reload = '' ) {
165 if ( ! empty( $this->_list[ $after ] ) ) {
166 $this->_list[ $name ]['title'] = $title;
167 $this->_list[ $name ]['next'] = $this->_list[ $after ]['next'];
168 $this->_list[ $name ]['next_btn'] = $this->_list[ $after ]['next_btn'];
169 $this->_list[ $after ]['next'] = $name;
170 $this->_list[ $after ]['next_btn'] = $title;
171 $this->_list[ $name ]['back'] = $back;
172 $this->_list[ $name ]['back_btn'] = $back_btn;
173 $this->_list[ $name ]['reload'] = $reload;
174 }
175 }
176
177 // Add replaceAfter method from GIJOE's patch.
178 public function replaceAfter( $after, $name, $title = '', $next = '', $next_btn = '', $back = '', $back_btn = '', $reload = '' ) {
179 if ( ! empty( $this->_list[ $after ] ) ) {
180 $this->_list[ $name ]['title'] = $title;
181 $this->_list[ $name ]['next'] = $next;
182 $this->_list[ $name ]['next_btn'] = $next_btn;
183 $this->_list[ $after ]['next'] = $name;
184 $this->_list[ $after ]['next_btn'] = $title;
185 $this->_list[ $name ]['back'] = $back;
186 $this->_list[ $name ]['back_btn'] = $back_btn;
187 $this->_list[ $name ]['reload'] = $reload;
188 }
189 }
190
191 public function getTitle( $name ) {
192 return ! empty( $this->_list[ $name ]['title'] ) ? ( $this->_list[ $name ]['title'] ) : '';
193 }
194
195 public function getNext( $name ) {
196 return ! empty( $this->_list[ $name ]['next'] ) || ! empty( $this->_list[ $name ]['next_btn'] ) ? ( [
197 $this->_list[ $name ]['next'],
198 $this->_list[ $name ]['next_btn']
199 ] ) : '';
200 }
201
202 public function getBack( $name ) {
203 return ! empty( $this->_list[ $name ]['back'] ) || ! empty( $this->_list[ $name ]['back_btn'] ) ? ( [
204 $this->_list[ $name ]['back'],
205 $this->_list[ $name ]['back_btn']
206 ] ) : '';
207 }
208
209 public function getReload( $name ) {
210 return ! empty( $this->_list[ $name ]['reload'] ) ? ( $this->_list[ $name ]['reload'] ) : '';
211 }
212}