1: <?php
2: 3: 4: 5: 6:
7:
8: if (!defined('XOOPS_ROOT_PATH')) exit();
9:
10: require_once XOOPS_MODULE_PATH . "/profile/class/AbstractAction.class.php";
11:
12: define('PROFILE_FRAME_PERFORM_SUCCESS', 1);
13: define('PROFILE_FRAME_PERFORM_FAIL', 2);
14: define('PROFILE_FRAME_INIT_SUCCESS', 3);
15:
16: define('PROFILE_FRAME_VIEW_NONE', "none");
17: define('PROFILE_FRAME_VIEW_SUCCESS', "success");
18: define('PROFILE_FRAME_VIEW_ERROR', "error");
19: define('PROFILE_FRAME_VIEW_INDEX', "index");
20: define('PROFILE_FRAME_VIEW_INPUT', "input");
21: define('PROFILE_FRAME_VIEW_PREVIEW', "preview");
22: define('PROFILE_FRAME_VIEW_CANCEL', "cancel");
23:
24: class Profile_Module extends Legacy_ModuleAdapter
25: {
26: var $mActionName = null;
27: var $mAction = null;
28: var $mAdminFlag = false;
29: var $mAssetManager = null;
30:
31: 32: 33:
34: function startup()
35: {
36: parent::startup();
37:
38: XCube_DelegateUtils::call('Module.profile.Event.GetAssetManager', new XCube_Ref($this->mAssetManager));
39:
40: $root =& XCube_Root::getSingleton();
41: $root->mController->mExecute->add(array(&$this, "execute"));
42:
43:
44:
45:
46: }
47:
48: 49: 50:
51: function setAdminMode($flag)
52: {
53: $this->mAdminFlag = $flag;
54: }
55:
56: 57: 58:
59: function setActionName($name)
60: {
61: $this->mActionName = $name;
62: }
63:
64: 65: 66:
67: function execute(&$controller)
68: {
69: if ($this->mActionName == null) {
70: $this->mActionName = xoops_getrequest('action');
71: if ($this->mActionName == null) {
72: $this->mActionName = "DataEdit";
73: }
74: }
75:
76: if (!preg_match("/^\w+$/", $this->mActionName)) {
77: $this->doActionNotFoundError();
78: die();
79: }
80:
81:
82:
83:
84: $fileName = ucfirst($this->mActionName) . "Action";
85: if ($this->mAdminFlag) {
86: $className = "Profile_Admin_" . ucfirst($this->mActionName) . "Action";
87: $fileName = XOOPS_MODULE_PATH . "/profile/admin/actions/${fileName}.class.php";
88: } else {
89: $className = "Profile_" . ucfirst($this->mActionName) . "Action";
90: $fileName = XOOPS_MODULE_PATH . "/profile/actions/${fileName}.class.php";
91: }
92:
93: if (!file_exists($fileName)) {
94: $this->doActionNotFoundError();
95: die();
96: }
97:
98: require_once $fileName;
99:
100: if (class_exists($className)) {
101: $this->mAction =new $className();
102: }
103:
104: if (!is_object($this->mAction)) {
105: $this->doActionNotFoundError();
106: die();
107: }
108:
109: if ($this->mAction->isMemberOnly() && !$controller->mRoot->mContext->mUser->isInRole('Site.RegisteredUser')) {
110: $this->doPermissionError();
111: die();
112: }
113:
114: if ($this->mAction->isAdminOnly() && !$controller->mRoot->mContext->mUser->isInRole('Module.profile.Admin')) {
115: $this->doPermissionError();
116: die();
117: }
118:
119: if ($this->mAction->prepare() === false) {
120: $this->doPreparationError();
121: die();
122: }
123:
124: if (!$this->mAction->hasPermission()) {
125: $this->doPermissionError();
126: die();
127: }
128:
129: if (xoops_getenv("REQUEST_METHOD") == "POST") {
130: $viewStatus = $this->mAction->execute();
131: } else {
132: $viewStatus = $this->mAction->getDefaultView();
133: }
134:
135: switch ($viewStatus) {
136: case PROFILE_FRAME_VIEW_SUCCESS:
137: $this->mAction->executeViewSuccess($controller,$controller->mRoot->mContext->mModule->getRenderTarget());
138: break;
139: case PROFILE_FRAME_VIEW_ERROR:
140: $this->mAction->executeViewError($controller->mRoot->mContext->mModule->getRenderTarget());
141: break;
142: case PROFILE_FRAME_VIEW_INDEX:
143: $this->mAction->executeViewIndex($controller->mRoot->mContext->mModule->getRenderTarget());
144: break;
145: case PROFILE_FRAME_VIEW_INPUT:
146: $this->mAction->executeViewInput($controller->mRoot->mContext->mModule->getRenderTarget());
147: break;
148: case PROFILE_FRAME_VIEW_PREVIEW:
149: $this->mAction->executeViewPreview($controller->mRoot->mContext->mModule->getRenderTarget());
150: break;
151: case PROFILE_FRAME_VIEW_CANCEL:
152: $this->mAction->executeViewCancel($controller->mRoot->mContext->mModule->getRenderTarget());
153: break;
154: }
155: }
156:
157: 158: 159:
160: function doPermissionError()
161: {
162: XCube_DelegateUtils::call("Module.Profile.Event.Exception.Permission");
163: $root =& XCube_Root::getSingleton();
164: $root->mController->executeForward(XOOPS_URL);
165: return;
166: }
167:
168: 169: 170:
171: function doActionNotFoundError()
172: {
173: XCube_DelegateUtils::call("Module.Profile.Event.Exception.ActionNotFound");
174: $root =& XCube_Root::getSingleton();
175: $root->mController->executeForward(XOOPS_URL);
176: return;
177: }
178:
179: 180: 181:
182: function doPreparationError()
183: {
184: XCube_DelegateUtils::call("Module.Profile.Event.Exception.Preparation");
185: $root =& XCube_Root::getSingleton();
186: $root->mController->executeForward(XOOPS_URL);
187: return;
188: }
189: }
190:
191: ?>
192: