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