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/ImagecategoryFilterForm.class.php";
15: require_once XOOPS_MODULE_PATH . "/legacy/admin/forms/ImagecategoryListForm.class.php";
16:
17: class Legacy_ImagecategoryListAction extends Legacy_AbstractListAction
18: {
19: var $mImagecategoryObjects = 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_ImagecategoryListForm();
26: $this->mActionForm->prepare();
27: }
28:
29: function &_getHandler()
30: {
31: $handler =& xoops_getmodulehandler('imagecategory');
32: return $handler;
33: }
34:
35: function &_getPageNavi()
36: {
37: $navi =new XCube_PageNavigator($this->_getBaseUrl(), XCUBE_PAGENAVI_START | XCUBE_PAGENAVI_PERPAGE);
38:
39: $root =& XCube_Root::getSingleton();
40: $perpage = $root->mContext->mRequest->getRequest($navi->mPrefix.'perpage');
41: if (isset($perpage) && intval($perpage) == 0) {
42: $navi->setPerpage(0);
43: }
44: return $navi;
45: }
46:
47: function &_getFilterForm()
48: {
49: $filter =new Legacy_ImagecategoryFilterForm($this->_getPageNavi(), $this->_getHandler());
50: return $filter;
51: }
52:
53: function _getBaseUrl()
54: {
55: return "./index.php?action=ImagecategoryList";
56: }
57:
58: function executeViewIndex(&$controller, &$xoopsUser, &$render)
59: {
60: $render->setTemplateName("imagecategory_list.html");
61: $render->setAttribute("objects", $this->mObjects);
62: $render->setAttribute("pageNavi", $this->mFilter->mNavi);
63: $render->setAttribute('actionForm', $this->mActionForm);
64: $render->setAttribute('pageArr', $this->mpageArr);
65: $render->setAttribute('filterForm', $this->mFilter);
66:
67: $imgcat_handler =& $this->_getHandler();
68: $imgcat_total = $imgcat_handler->getCount();
69: $file_imgcat_total = $imgcat_handler->getCount(new Criteria('imgcat_storetype', 'file'));
70: $render->setAttribute('ImgcatTotal', $imgcat_total);
71: $render->setAttribute('fileImgcatTotal', $file_imgcat_total);
72: $render->setAttribute('dbImgcatTotal', $imgcat_total - $file_imgcat_total);
73:
74: $image_handler =& xoops_getmodulehandler('image');
75: $image_total = $image_handler->getCount();
76: $display_image_total = $image_handler->getCount(new Criteria('image_display', 1));
77: $render->setAttribute('ImageTotal', $image_total);
78: $render->setAttribute('displayImageTotal', $display_image_total);
79: $render->setAttribute('notdisplayImageTotal', $image_total - $display_image_total);
80: }
81:
82: function execute(&$controller, &$xoopsUser)
83: {
84: $form_cancel = $controller->mRoot->mContext->mRequest->getRequest('_form_control_cancel');
85: if ($form_cancel != null) {
86: return LEGACY_FRAME_VIEW_CANCEL;
87: }
88:
89: $this->mActionForm->fetch();
90: $this->mActionForm->validate();
91:
92: if ($this->mActionForm->hasError()) {
93: return $this->_processConfirm($controller, $xoopsUser);
94: }
95: else {
96: return $this->_processSave($controller, $xoopsUser);
97: }
98: }
99:
100: function _processConfirm(&$controller,&$xoopsUser)
101: {
102: $nameArr = $this->mActionForm->get('name');
103: $imagecategoryHandler =& xoops_getmodulehandler('imagecategory');
104:
105:
106:
107: foreach (array_keys($nameArr) as $icid) {
108: $imagecategory =& $imagecategoryHandler->get($icid);
109: if (is_object($imagecategory)) {
110: $this->mImagecategoryObjects[$icid] =& $imagecategory;
111: }
112: unset($imagecategory);
113: }
114:
115:
116: return LEGACY_FRAME_VIEW_INPUT;
117: }
118:
119: function _processSave(&$controller, &$xoopsUser)
120: {
121: $nameArr = $this->mActionForm->get('name');
122: $imagecategoryHandler =& xoops_getmodulehandler('imagecategory');
123:
124: foreach(array_keys($nameArr) as $icid) {
125: $imagecategory =& $imagecategoryHandler->get($icid);
126: if (is_object($imagecategory)) {
127: $olddata['name'] = $imagecategory->get('imgcat_name');
128: $olddata['weight'] = $imagecategory->get('imgcat_weight');
129: $olddata['maxsize'] = $imagecategory->get('imgcat_maxsize');
130: $olddata['maxwidth'] = $imagecategory->get('imgcat_maxwidth');
131: $olddata['maxheight'] = $imagecategory->get('imgcat_maxheight');
132: $olddata['display'] = $imagecategory->get('imgcat_display');
133: $newdata['name'] = $this->mActionForm->get('name', $icid);
134: $newdata['weight'] = $this->mActionForm->get('weight', $icid);
135: $newdata['maxsize'] = $this->mActionForm->get('maxsize', $icid);
136: $newdata['maxwidth'] = $this->mActionForm->get('maxwidth', $icid);
137: $newdata['maxheight'] = $this->mActionForm->get('maxheight', $icid);
138: $newdata['display'] = $this->mActionForm->get('display', $icid);
139: if (count(array_diff_assoc($olddata, $newdata)) > 0 ) {
140: $imagecategory->set('imgcat_name', $this->mActionForm->get('name', $icid));
141: $imagecategory->set('imgcat_weight', $this->mActionForm->get('weight', $icid));
142: $imagecategory->set('imgcat_maxsize', $this->mActionForm->get('maxsize', $icid));
143: $imagecategory->set('imgcat_maxwidth', $this->mActionForm->get('maxwidth', $icid));
144: $imagecategory->set('imgcat_maxheight', $this->mActionForm->get('maxheight', $icid));
145: $imagecategory->set('imgcat_display', $this->mActionForm->get('display', $icid));
146: if (!$imagecategoryHandler->insert($imagecategory)) {
147: return LEGACY_FRAME_VIEW_ERROR;
148: }
149: }
150: }
151: }
152:
153: foreach(array_keys($nameArr) as $icid) {
154: if($this->mActionForm->get('delete', $icid) == 1) {
155: $imagecategory =& $imagecategoryHandler->get($icid);
156: if (is_object($imagecategory)) {
157: if( !$imagecategoryHandler->delete($imagecategory) ) {
158: return LEGACY_FRAME_VIEW_ERROR;
159: }
160: }
161: }
162: }
163: return LEGACY_FRAME_VIEW_SUCCESS;
164:
165: }
166:
167: 168: 169:
170: function executeViewInput(&$controller, &$xoopsUser, &$render)
171: {
172: $render->setTemplateName("imagecategory_list_confirm.html");
173: $render->setAttribute('imagecategoryObjects', $this->mImagecategoryObjects);
174: $render->setAttribute('actionForm', $this->mActionForm);
175:
176:
177:
178:
179: $t_arr = $this->mActionForm->get('name');
180: $render->setAttribute('icids', array_keys($t_arr));
181: }
182:
183:
184: function executeViewSuccess(&$controller,&$xoopsUser,&$renderer)
185: {
186: $controller->executeForward('./index.php?action=ImagecategoryList');
187: }
188:
189: function executeViewError(&$controller, &$xoopsUser, &$renderer)
190: {
191: $controller->executeRedirect('./index.php?action=ImagecategoryList', 1, _MD_LEGACY_ERROR_DBUPDATE_FAILED);
192: }
193:
194: function executeViewCancel(&$controller,&$xoopsUser,&$renderer)
195: {
196: $controller->executeForward('./index.php?action=ImagecategoryList');
197: }
198:
199: }
200:
201: ?>
202: