PageRenderTime 26ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/html/install/class/simplewizard.php

http://xoopscube-modules.googlecode.com/
PHP | 224 lines | 193 code | 22 blank | 9 comment | 43 complexity | 6e786dcf280982105d0d4d205d3a2ef7 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, AGPL-1.0
  1. <?php
  2. /**
  3. *
  4. * @package Legacy
  5. * @version $Id: simplewizard.php,v 1.4 2008/09/25 15:12:47 kilica Exp $
  6. * @copyright Copyright 2005-2007 XOOPS Cube Project <http://xoopscube.sourceforge.net/>
  7. * @license http://xoopscube.sourceforge.net/license/GPL_V2.txt GNU GENERAL PUBLIC LICENSE Version 2
  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. function setTemplatePath($name) {
  22. $this->_template_path = $name;
  23. }
  24. function setBaseTemplate($name) {
  25. $this->_base_template_name = $name;
  26. }
  27. function assign($name, $value) {
  28. $this->_v[$name] = $value;
  29. }
  30. function setContent($value) {
  31. $this->_content = $value;
  32. }
  33. function setOp($value) {
  34. $this->_op = $value;
  35. }
  36. function setTitle($value) {
  37. $this->_title = $value;
  38. }
  39. function setNext($value) {
  40. $this->_next = $value;
  41. $this->_custom_seq = true;
  42. }
  43. function setBack($value) {
  44. $this->_back = $value;
  45. $this->_custom_seq = true;
  46. }
  47. function setReload($value) {
  48. $this->_reload = $value;
  49. $this->_custom_seq = true;
  50. }
  51. function addArray($name, $value) {
  52. if (!isset($this->_v[$name]) || !is_array($this->_v[$name])) {
  53. $this->_v[$name] = array();
  54. }
  55. $this->_v[$name][] = $value;
  56. }
  57. function v($name) {
  58. if (!empty($this->_v[$name])) {
  59. return $this->_v[$name];
  60. } else {
  61. return false;
  62. }
  63. }
  64. function e() {
  65. $args = func_get_args();
  66. if (func_num_args() >0) {
  67. if (!empty($this->_v[$args[0]])) {
  68. $value = $this->_v[$args[0]];
  69. if ((func_num_args() ==2) && is_array($value)) {
  70. $value = $value[$args[1]];
  71. }
  72. } else {
  73. $value = '';
  74. }
  75. echo $value;
  76. }
  77. }
  78. function render($fname='') {
  79. if ($fname && file_exists($this->_template_path.'/'.$fname)) {
  80. ob_start();
  81. include $this->_template_path.'/'.$fname;
  82. $this->setContent(ob_get_contents());
  83. ob_end_clean();
  84. }
  85. $content = $this->_content;
  86. if (!empty($this->_title)) {
  87. $title = $this->_title;
  88. } else {
  89. $title = $GLOBALS['wizardSeq']->getTitle($this->_op);
  90. }
  91. if (!empty($this->_next)) {
  92. $b_next = $this->_next;
  93. } else if (!$this->_custom_seq) {
  94. $b_next = $GLOBALS['wizardSeq']->getNext($this->_op);
  95. } else {
  96. $b_next = '';
  97. }
  98. if (!empty($this->_back)) {
  99. $b_back = $this->_back;
  100. } else if (!$this->_custom_seq) {
  101. $b_back = $GLOBALS['wizardSeq']->getBack($this->_op);
  102. } else {
  103. $b_back = '';
  104. }
  105. if (!empty($this->_reload)) {
  106. $b_reload = $this->_reload;
  107. } else if (!$this->_custom_seq) {
  108. $b_reload = $GLOBALS['wizardSeq']->getReload($this->_op);
  109. } else {
  110. $b_reload = '';
  111. }
  112. include $this->_base_template_name;
  113. }
  114. function error() {
  115. $content = $this->_content;
  116. if (!empty($this->_title)) {
  117. $title = $this->_title;
  118. } else {
  119. $title = $GLOBALS['wizardSeq']->getTitle($this->_op);
  120. }
  121. if (!empty($this->_next)) {
  122. $b_next = $this->_next;
  123. } else {
  124. $b_next = '';
  125. }
  126. if (!empty($this->_back)) {
  127. $b_back = $this->_back;
  128. } else {
  129. $b_back = '';
  130. }
  131. if (!empty($this->_reload)) {
  132. $b_reload = $this->_reload;
  133. } else {
  134. $b_reload = '';
  135. }
  136. include $this->_base_template_name;
  137. }
  138. }
  139. class SimpleWizardSequence {
  140. var $_list;
  141. function add($name, $title='', $next='', $next_btn='', $back='', $back_btn='', $reload='') {
  142. $this->_list[$name]['title'] = $title;
  143. $this->_list[$name]['next'] = $next;
  144. $this->_list[$name]['next_btn'] = $next_btn;
  145. $this->_list[$name]['back'] = $back;
  146. $this->_list[$name]['back_btn'] = $back_btn;
  147. $this->_list[$name]['reload'] = $reload;
  148. }
  149. function insertAfter($after, $name, $title='', $back='', $back_btn='', $reload='') {
  150. if (!empty($this->_list[$after])) {
  151. $this->_list[$name]['title'] = $title;
  152. $this->_list[$name]['next'] = $this->_list[$after]['next'];
  153. $this->_list[$name]['next_btn'] = $this->_list[$after]['next_btn'];
  154. $this->_list[$after]['next'] = $name;
  155. $this->_list[$after]['next_btn'] = $title;
  156. $this->_list[$name]['back'] = $back;
  157. $this->_list[$name]['back_btn'] = $back_btn;
  158. $this->_list[$name]['reload'] = $reload;
  159. }
  160. }
  161. // Add replaceAfter method from GIJOE's patch.
  162. function replaceAfter($after, $name, $title='', $next='', $next_btn='', $back='', $back_btn='', $reload='') {
  163. if (!empty($this->_list[$after])) {
  164. $this->_list[$name]['title'] = $title;
  165. $this->_list[$name]['next'] = $next;
  166. $this->_list[$name]['next_btn'] = $next_btn;
  167. $this->_list[$after]['next'] = $name;
  168. $this->_list[$after]['next_btn'] = $title;
  169. $this->_list[$name]['back'] = $back;
  170. $this->_list[$name]['back_btn'] = $back_btn;
  171. $this->_list[$name]['reload'] = $reload;
  172. }
  173. }
  174. function getTitle($name) {
  175. if (!empty($this->_list[$name]['title'])) {
  176. return($this->_list[$name]['title']);
  177. } else {
  178. return '';
  179. }
  180. }
  181. function getNext($name) {
  182. if (!empty($this->_list[$name]['next'])||!empty($this->_list[$name]['next_btn'])) {
  183. return(array($this->_list[$name]['next'],$this->_list[$name]['next_btn']));
  184. } else {
  185. return '';
  186. }
  187. }
  188. function getBack($name) {
  189. if (!empty($this->_list[$name]['back'])||!empty($this->_list[$name]['back_btn'])) {
  190. return(array($this->_list[$name]['back'],$this->_list[$name]['back_btn']));
  191. } else {
  192. return '';
  193. }
  194. }
  195. function getReload($name) {
  196. if (!empty($this->_list[$name]['reload'])) {
  197. return($this->_list[$name]['reload']);
  198. } else {
  199. return '';
  200. }
  201. }
  202. }