1: <?php
2: 3: 4: 5: 6: 7: 8: 9:
10:
11: if (!defined('XOOPS_ROOT_PATH')) exit();
12:
13: require_once XOOPS_LEGACY_PATH."/admin/forms/ActionSearchForm.class.php";
14:
15: class Legacy_ActionSearchArgs
16: {
17: var $mKeywords;
18: var $mRecords;
19:
20: function Legacy_ActionSearchArgs($words)
21: {
22: $this->setKeywords($words);
23: }
24:
25: function setKeywords($words)
26: {
27: foreach (explode(" ", $words) as $word) {
28: if( strlen($word) > 0) {
29: $this->mKeywords[] = $word;
30: }
31: }
32: }
33:
34: function getKeywords()
35: {
36: return $this->mKeywords;
37: }
38:
39: function addRecord($moduleName, $url, $title, $desc = null)
40: {
41: $this->mRecords[] =new Legacy_ActionSearchRecord($moduleName, $url, $title, $desc);
42: }
43:
44: function &getRecords()
45: {
46: return $this->mRecords;
47: }
48:
49: 50: 51:
52: function hasRecord()
53: {
54: return count($this->mRecords) > 0;
55: }
56: }
57:
58: 59: 60: 61: 62:
63: class Legacy_ActionSearchRecord
64: {
65: var $mModuleName;
66: var $mActionUrl;
67: var $mTitle;
68: var $mDescription;
69:
70: function Legacy_ActionSearchRecord($moduleName, $url, $title, $desc=null)
71: {
72: $this->mModuleName = $moduleName;
73: $this->mActionUrl = $url;
74: $this->mTitle = $title;
75: $this->mDescription = $desc;
76: }
77: }
78:
79: 80: 81: 82: 83: 84: 85:
86: class Legacy_ActSearchAction extends Legacy_Action
87: {
88: var $mModules = array();
89: var $mModuleRecords = null;
90: var $mRecords = null;
91: var $mActionForm = null;
92:
93: var $mSearchAction = null;
94:
95: function Legacy_ActSearchAction($flag)
96: {
97: parent::Legacy_Action($flag);
98:
99: $this->mSearchAction =new XCube_Delegate();
100: $this->mSearchAction->add(array(&$this, 'defaultSearch'));
101: $this->mSearchAction->register('Legacy_ActSearchAction.SearchAction');
102: }
103:
104: function prepare(&$controller, &$xoopsUser)
105: {
106: parent::prepare($controller, $xoopsUser);
107:
108: $db=&$controller->getDB();
109:
110: $mod = $db->prefix("modules");
111: $perm = $db->prefix("group_permission");
112: $groups = implode(",", $xoopsUser->getGroups());
113:
114: $sql = "SELECT DISTINCT ${mod}.mid FROM ${mod},${perm} " .
115: "WHERE ${mod}.isactive=1 AND ${mod}.mid=${perm}.gperm_itemid AND ${perm}.gperm_name='module_admin' AND ${perm}.gperm_groupid IN (${groups}) " .
116: "ORDER BY ${mod}.weight, ${mod}.mid";
117:
118: $result=$db->query($sql);
119:
120: $handler =& xoops_gethandler('module');
121: while ($row = $db->fetchArray($result)) {
122: $module =& $handler->get($row['mid']);
123: $adapter =new Legacy_ModuleAdapter($module);
124:
125: $this->mModules[] =& $adapter;
126:
127: unset($module);
128: unset($adapter);
129: }
130: }
131:
132: function hasPermission(&$controller, &$xoopsUser)
133: {
134: $permHandler =& xoops_gethandler('groupperm');
135: return $permHandler->checkRight('module_admin', -1, $xoopsUser->getGroups());
136: }
137:
138: function getDefaultView(&$controller, &$xoopsUser)
139: {
140: $this->_processActionForm();
141:
142: $this->mActionForm->fetch();
143: $this->mActionForm->validate();
144:
145: if($this->mActionForm->hasError()) {
146: return LEGACY_FRAME_VIEW_INPUT;
147: }
148:
149: $searchArgs =new Legacy_ActionSearchArgs($this->mActionForm->get('keywords'));
150: $this->mSearchAction->call(new XCube_Ref($searchArgs));
151:
152: if ($searchArgs->hasRecord()) {
153: $this->mRecords =& $searchArgs->getRecords();
154: return LEGACY_FRAME_VIEW_SUCCESS;
155: }
156: else {
157: return LEGACY_FRAME_VIEW_ERROR;
158: }
159: }
160:
161: function defaultSearch(&$searchArgs)
162: {
163: foreach (array_keys($this->mModules) as $key) {
164: $this->mModules[$key]->doActionSearch($searchArgs);
165: }
166: }
167:
168: function execute(&$controller, &$xoopsUser)
169: {
170: return $this->getDefaultView($controller, $xoopsUser);
171: }
172:
173: function _processActionForm()
174: {
175: $this->mActionForm =new Legacy_ActionSearchForm();
176: $this->mActionForm->prepare();
177: }
178:
179: function executeViewSuccess(&$controller, &$xoopsUser, &$render)
180: {
181: $render->setTemplateName("legacy_admin_actionsearch_success.html");
182: $render->setAttribute("records", $this->mRecords);
183: $render->setAttribute("actionForm", $this->mActionForm);
184: }
185:
186: function executeViewInput(&$controller, &$xoopsUser, &$render)
187: {
188: $render->setTemplateName("legacy_admin_actionsearch_input.html");
189: $render->setAttribute("actionForm", $this->mActionForm);
190: }
191:
192: function executeViewError(&$controller, &$xoopsUser, &$render)
193: {
194: $render->setTemplateName("legacy_admin_actionsearch_error.html");
195: $render->setAttribute("actionForm", $this->mActionForm);
196: }
197: }
198:
199: ?>
200: