1: <?php
2: 3: 4: 5: 6: 7: 8: 9:
10:
11: if (!defined('XOOPS_ROOT_PATH')) exit();
12:
13: require_once XOOPS_MODULE_PATH . "/legacy/class/AbstractListAction.class.php";
14: require_once XOOPS_MODULE_PATH . "/legacy/admin/forms/BlockFilterForm.class.php";
15: require_once XOOPS_MODULE_PATH . "/legacy/admin/forms/BlockListForm.class.php";
16:
17: class Legacy_BlockListAction extends Legacy_AbstractListAction
18: {
19: var $mBlockObjects = array();
20: var $mActionForm = null;
21: var $mpageArr = array(5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 60, 70, 80, 90, 100, 0);
22:
23: function prepare(&$controller, &$xoopsUser)
24: {
25: $this->mActionForm =new Legacy_BlockListForm();
26: $this->mActionForm->prepare();
27: }
28:
29: function &_getHandler()
30: {
31: $handler =& xoops_getmodulehandler('newblocks');
32: return $handler;
33: }
34:
35: function &_getFilterForm()
36: {
37: $filter =new Legacy_BlockFilterForm($this->_getPageNavi(), $this->_getHandler());
38: return $filter;
39: }
40:
41: function &_getPageNavi()
42: {
43: $navi =new XCube_PageNavigator($this->_getBaseUrl(), XCUBE_PAGENAVI_START | XCUBE_PAGENAVI_PERPAGE);
44:
45: $root =& XCube_Root::getSingleton();
46: $perpage = $root->mContext->mRequest->getRequest($navi->mPrefix.'perpage');
47:
48: if (isset($perpage) && intval($perpage) == 0) {
49: $navi->setPerpage(0);
50: }
51: return $navi;
52: }
53:
54: function _getBaseUrl()
55: {
56: return "./index.php?action=BlockList";
57: }
58:
59: function executeViewIndex(&$controller, &$xoopsUser, &$render)
60: {
61: $render->setTemplateName("block_list.html");
62: foreach (array_keys($this->mObjects) as $key) {
63: $this->mObjects[$key]->loadModule();
64: $this->mObjects[$key]->loadColumn();
65: $this->mObjects[$key]->loadCachetime();
66: }
67:
68: $render->setAttribute("objects", $this->mObjects);
69: $render->setAttribute("pageNavi", $this->mFilter->mNavi);
70:
71: $render->setAttribute('modules', $controller->mActiveModules);
72: $render->setAttribute('filterForm', $this->mFilter);
73: $render->setAttribute('pageArr', $this->mpageArr);
74:
75:
76:
77: $handler =& xoops_gethandler('cachetime');
78: $cachetimeArr =& $handler->getObjects();
79: $render->setAttribute('cachetimeArr', $cachetimeArr);
80: $render->setAttribute('actionForm', $this->mActionForm);
81:
82: $handler =& xoops_getmodulehandler('columnside');
83: $columnSideArr =& $handler->getObjects();
84: $render->setAttribute('columnSideArr', $columnSideArr);
85:
86: $block_handler =& $this->_getHandler();
87: $block_total = $block_handler->getCount();
88: $inactive_block_total = $block_handler->getCount(new Criteria('isactive', 0));
89: $active_block_total = $block_total-$inactive_block_total;
90: $render->setAttribute('BlockTotal', $block_total);
91: $render->setAttribute('ActiveBlockTotal', $active_block_total);
92: $render->setAttribute('InactiveBlockTotal', $inactive_block_total);
93:
94: $active_installed_criteria = new CriteriaCompo(new Criteria('visible', 1));
95: $active_installed_criteria->add(new Criteria('isactive', 1));
96: $active_installed_block_total = $block_handler->getCount($active_installed_criteria);
97: $render->setAttribute('ActiveInstalledBlockTotal', $active_installed_block_total);
98: $render->setAttribute('ActiveUninstalledBlockTotal', $active_block_total - $active_installed_block_total);
99:
100: $inactive_installed_criteria = new CriteriaCompo(new Criteria('visible', 1));
101: $inactive_installed_criteria->add(new Criteria('isactive', 0));
102: $inactive_installed_block_total = $block_handler->getCount($inactive_installed_criteria);
103: $render->setAttribute('InactiveInstalledBlockTotal', $inactive_installed_block_total);
104: $render->setAttribute('InactiveUninstalledBlockTotal', $inactive_block_total - $inactive_installed_block_total);
105: }
106:
107:
108: function execute(&$controller, &$xoopsUser)
109: {
110: $form_cancel = $controller->mRoot->mContext->mRequest->getRequest('_form_control_cancel');
111: if ($form_cancel != null) {
112: return LEGACY_FRAME_VIEW_CANCEL;
113: }
114:
115: $this->mActionForm->fetch();
116: $this->mActionForm->validate();
117:
118: if ($this->mActionForm->hasError()) {
119: return $this->_processConfirm($controller, $xoopsUser);
120: }
121: else {
122: return $this->_processSave($controller, $xoopsUser);
123: }
124: }
125:
126: function _processConfirm(&$controller,&$xoopsUser)
127: {
128: $titleArr = $this->mActionForm->get('title');
129: $blockHandler =& xoops_getmodulehandler('newblocks');
130:
131:
132:
133: foreach (array_keys($titleArr) as $bid) {
134: $block =& $blockHandler->get($bid);
135: if (is_object($block) && $block->get('isactive') == 1 && $block->get('visible') == 1) {
136: $this->mBlockObjects[$bid] =& $block;
137: $this->mBlockObjects[$bid]->loadColumn();
138: $this->mBlockObjects[$bid]->loadCachetime();
139: }
140: unset($block);
141: }
142:
143: return LEGACY_FRAME_VIEW_INPUT;
144: }
145:
146: function _processSave(&$controller, &$xoopsUser)
147: {
148: $titleArr = $this->mActionForm->get('title');
149: $blockHandler =& xoops_getmodulehandler('newblocks');
150:
151: foreach (array_keys($titleArr) as $bid) {
152: $block =& $blockHandler->get($bid);
153: if (is_object($block) && $block->get('isactive') == 1 && $block->get('visible') == 1) {
154: $olddata['title'] = $block->get('title');
155: $olddata['weight'] = $block->get('weight');
156: $olddata['side'] = $block->get('side');
157: $olddata['bcachetime'] = $block->get('bcachetime');
158: $newdata['title'] = $this->mActionForm->get('title', $bid);
159: $newdata['weight'] = $this->mActionForm->get('weight', $bid);
160: $newdata['side'] = $this->mActionForm->get('side', $bid);
161: $newdata['bcachetime'] = $this->mActionForm->get('bcachetime', $bid);
162: if ( count(array_diff_assoc($olddata, $newdata)) > 0 ) {
163: $block->set('title', $this->mActionForm->get('title', $bid));
164: $block->set('weight', $this->mActionForm->get('weight', $bid));
165: $block->set('side', $this->mActionForm->get('side', $bid));
166: $block->set('bcachetime', $this->mActionForm->get('bcachetime', $bid));
167: $block->set('last_modified', time());
168: if (!$blockHandler->insert($block)) {
169: return LEGACY_FRAME_VIEW_ERROR;
170: }
171: }
172: }
173: }
174:
175:
176: foreach(array_keys($titleArr) as $bid) {
177: if($this->mActionForm->get('uninstall', $bid) == 1) {
178: $block =& $blockHandler->get($bid);
179: if (is_object($block) && $block->get('isactive') == 1 && $block->get('visible') == 1) {
180: $block->set('visible', 0);
181: if( !$blockHandler->insert($block) ) {
182: return LEGACY_FRAME_VIEW_ERROR;
183: }
184: }
185: }
186: }
187:
188: return LEGACY_FRAME_VIEW_SUCCESS;
189: }
190:
191:
192: function executeViewInput(&$controller, &$xoopsUser, &$render)
193: {
194: $render->setTemplateName("block_list_confirm.html");
195: $render->setAttribute('blockObjects', $this->mBlockObjects);
196: $render->setAttribute('actionForm', $this->mActionForm);
197:
198: $t_arr = $this->mActionForm->get('title');
199: $render->setAttribute('bids', array_keys($t_arr));
200:
201: $handler =& xoops_getmodulehandler('columnside');
202: $columnSideArr =& $handler->getObjects($criteria = null, $id_as_key = true);
203: $render->setAttribute('columnSideArr', $columnSideArr);
204: $handler =& xoops_gethandler('cachetime');
205: $cachetimeArr =& $handler->getObjects($criteria = null, $id_as_key = true);
206: $render->setAttribute('cachetimeArr', $cachetimeArr);
207:
208: }
209:
210: function executeViewSuccess(&$controller, &$xoopsUser, &$render)
211: {
212: $controller->executeForward('./index.php?action=BlockList');
213: }
214:
215: function executeViewError(&$controller, &$xoopsUser, &$render)
216: {
217: $controller->executeRedirect("./index.php?action=BlockInstallList", 1, _MD_LEGACY_ERROR_DBUPDATE_FAILED);
218: }
219:
220: function executeViewCancel(&$controller,&$xoopsUser,&$renderer)
221: {
222: $controller->executeForward('./index.php?action=BlockList');
223: }
224:
225: }
226:
227: ?>
228: